diff --git a/sdk/cloud/image/Cut.tsx b/sdk/cloud/image/Cut.tsx
index 297f7674..b00233ea 100644
--- a/sdk/cloud/image/Cut.tsx
+++ b/sdk/cloud/image/Cut.tsx
@@ -15,10 +15,10 @@
//
// A moment lasts its take's span (endAt - startFrom), or `frames` when it has no take. `said` is the cut's words in its
// own frames, as `raea cut` gives them for these spans in this order.
-import { Audio, Sequence, useCurrentFrame } from "raea";
+import { Audio, Sequence, useCurrentFrame, useVideoConfig } from "raea";
import EndCard from "./EndCard";
import Said from "./Said";
-import Shot, { type Layout } from "./Shot";
+import Shot, { facesOn, type Layout } from "./Shot";
import Title from "./Title";
type Who = number | string;
@@ -166,6 +166,11 @@ export default function Cut({ moments, said, keys, emoji, hook, hookFrames, bed
const firstEnd = said?.find((w) => /[.?!]$/.test(w.text))?.to;
const hookLen = hookFrames ?? Math.min(60, firstEnd ?? 60);
const showHook = !!hook && f < hookLen;
+ // the hook keeps off the faces of the shots under it (framed as one speaker: a split or a stack's faces aren't these)
+ const { width: W, height: H, fps } = useVideoConfig();
+ const hookFaces = showHook
+ ? moments.flatMap((m, i) => (sp[i].from < hookLen && m.src && (m.show === "speaker" || m.show === "wide" || m.show === "product") ? facesOn(m.src, m.startFrom, m.endAt, m.who, W, H, fps) : []))
+ : [];
return (
<>
{moments.map((m, i) => (
@@ -181,7 +186,7 @@ export default function Cut({ moments, said, keys, emoji, hook, hookFrames, bed
))}
{bed ? : null}
- {showHook ?
{hook} : null}
+ {showHook ? {hook} : null}
{said?.length ? : null}
>
);
diff --git a/sdk/cloud/image/Shot.tsx b/sdk/cloud/image/Shot.tsx
index 0cb80567..8181ef3c 100644
--- a/sdk/cloud/image/Shot.tsx
+++ b/sdk/cloud/image/Shot.tsx
@@ -103,6 +103,18 @@ export function clearSpot(W: number, H: number, faces: [number, number, number,
return best;
}
+/** the faces on screen in a take's span (px boxes [x, y, w, h]), framed as a speaker shot frames it: what a title over
+ * the shot keeps clear of (Cut's hook) */
+export function facesOn(src: string, startFrom: number | undefined, endAt: number | undefined, who: ShotProps["who"], W: number, H: number, fps: number): [number, number, number, number][] {
+ const take = TRACKS[nameOf(src)];
+ if (!take) return [];
+ const a = (startFrom ?? 0) / fps;
+ const ps = people(take, a, endAt !== undefined ? endAt / fps : a + 600);
+ const on = pick(ps, who);
+ const win = windowOn(take, W, H, on, ps.filter((q) => q !== on), false);
+ return ps.map((q) => onScreen(q, win, 0, 0, W, H));
+}
+
export default function Shot(p: ShotProps) {
const { width: W, height: H, fps } = useVideoConfig();
const frame = useCurrentFrame();
diff --git a/sdk/cloud/image/Title.tsx b/sdk/cloud/image/Title.tsx
index 345cca8a..05ab95ac 100644
--- a/sdk/cloud/image/Title.tsx
+++ b/sdk/cloud/image/Title.tsx
@@ -4,6 +4,7 @@
// run. Change the look freely; never give it a top or left.
import type React from "react";
import { Region, useRegion, useVideoConfig } from "raea";
+import { zones } from "./brand";
type Props = {
children: React.ReactNode;
@@ -13,8 +14,25 @@ type Props = {
size?: number;
/** merged over the title's own style (colour, font, a backing box); not its place */
style?: React.CSSProperties;
+ /** the faces on screen under it (px boxes, Shot's facesOn): a top title stays at the top when the room above the
+ * highest face holds it, else under the lowest, over the body. Without them places it, clear of the faces only
+ * where raea cut recorded them (perception.json) */
+ faces?: [number, number, number, number][];
};
+/** the top of a top title `need` px tall, clear of `faces` (each padded by a third of its height: hair, chin): at the
+ * top when the room under the app's top zone and over the highest face holds it, else under the lowest, kept above the caption band (the bottom
+ * 16%); null without faces. 12-05: hooks drew across faces in every street cut whose agent skipped raea cut */
+export function clearTop(W: number, H: number, faces: [number, number, number, number][], need: number): number | null {
+ if (!faces.length) return null;
+ const z = zones(W, H);
+ const m = 0.02 * H;
+ const top = Math.min(...faces.map((f) => f[1] - f[3] / 3));
+ const bottom = Math.max(...faces.map((f) => f[1] + (f[3] * 4) / 3));
+ if (top - m - z.top >= need) return z.top;
+ return Math.min(bottom + m, H - z.bottom - 0.16 * H - need);
+}
+
/** how tall the title's lines are in a box `w` px wide: about 0.56 em a letter in a bold face, its line height and the
* backing box's padding (`pad`, px top and bottom together) */
export function heightIn(text: string, w: number, size: number, pad = 0): number {
@@ -45,9 +63,9 @@ function Fit({ need, seen, children, when }: { need: number; seen: { top?: boole
return seen.top ? null : <>{children}>;
}
-export default function Title({ children, region = "top", size = 64, style }: Props) {
+export default function Title({ children, region = "top", size = 64, style, faces }: Props) {
const align = (r: string) => (r === "bottom" ? "flex-end" : r === "center" ? "center" : "flex-start");
- const { width } = useVideoConfig();
+ const { width, height } = useVideoConfig();
const px = size * (width / 1080);
const pad = 2 * (typeof style?.padding === "string" ? parseFloat(style.padding) || 0 : typeof style?.padding === "number" ? style.padding : 0);
// a hook at the top when the band over the face holds it; else in the middle, over the body and never the face
@@ -66,7 +84,11 @@ export default function Title({ children, region = "top", size = 64, style }: Pr
fontSize: size,
lineHeight: 1.1,
color: "var(--brand-text, #fff)",
- textShadow: "0 4px 24px rgba(0,0,0,0.55)",
+ // a dark plate, as raea's captions have: a hook over a beige coat or a sky read under 3:1 with a shadow alone
+ background: "rgba(0,0,0,0.6)",
+ padding: `${Math.round(px * 0.08)}px ${Math.round(px * 0.3)}px`,
+ borderRadius: Math.round(px * 0.18),
+ textShadow: "0 0 2px rgba(0,0,0,0.9)",
...style,
position: undefined,
top: undefined,
@@ -76,6 +98,13 @@ export default function Title({ children, region = "top", size = 64, style }: Pr
{children}
);
+ if (region === "top" && faces?.length) {
+ const z = zones(width, height);
+ const w = width - z.left - z.right;
+ const y = clearTop(width, height, faces, heightIn(text, w, px, pad));
+ if (y !== null)
+ return
{el}
;
+ }
if (region !== "top")
return (
diff --git a/sdk/cloud/image/brand.ts b/sdk/cloud/image/brand.ts
index aed16892..8e0207b2 100644
--- a/sdk/cloud/image/brand.ts
+++ b/sdk/cloud/image/brand.ts
@@ -15,14 +15,39 @@ type Kit = {
};
const kit = (KIT ?? {}) as Kit;
+/** a CSS colour's 0-255 channels (#rgb, #rrggbb, rgb(...), rgba(...)); null for anything else (a var(), a name) */
+export function rgbOf(c: string): [number, number, number] | null {
+ const h = c.trim().match(/^#([0-9a-f]{3}|[0-9a-f]{6})(?:[0-9a-f]{2})?$/i)?.[1];
+ if (h) return (h.length === 3 ? [...h].map((x) => parseInt(x + x, 16)) : [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16))) as [number, number, number];
+ const m = c.match(/^rgba?\(\s*(\d+)[ ,]+(\d+)[ ,]+(\d+)/i);
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
+}
+
+const lum = (c: [number, number, number]) => {
+ const [r, g, b] = c.map((v) => (v / 255 <= 0.04045 ? v / 255 / 12.92 : ((v / 255 + 0.055) / 1.055) ** 2.4));
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
+};
+/** WCAG contrast of two colours */
+export const contrast = (a: [number, number, number], b: [number, number, number]) => (Math.max(lum(a), lum(b)) + 0.05) / (Math.min(lum(a), lum(b)) + 0.05);
+
+/** text on `bg` that reads: `fg` where it's 4.5:1 or better, else white or black, whichever reads better. A colour
+ * either can't be read as (a var()) leaves `fg` as it is. 12-05: Elfster's CTA, in its kit's button colours, was 2.5:1 */
+export function readable(bg: string, fg: string): string {
+ const b = rgbOf(bg);
+ if (!b) return fg;
+ const f = rgbOf(fg);
+ if (f && contrast(b, f) >= 4.5) return fg;
+ return contrast(b, [255, 255, 255]) >= contrast(b, [0, 0, 0]) ? "#ffffff" : "#000000";
+}
+
/** the brand's colours, as CSS: the kit's, else brand.css's variables, else neutral */
export const COLORS = {
surface: kit.palette?.surface ?? "var(--brand-background, #101010)",
text: kit.palette?.text_on_surface ?? "var(--brand-text, #ffffff)",
accent: kit.palette?.accent ?? "var(--brand-accent, #ffd23f)",
- onAccent: kit.palette?.text_on_accent ?? "var(--brand-background, #101010)",
+ onAccent: readable(kit.palette?.accent ?? "", kit.palette?.text_on_accent ?? "var(--brand-background, #101010)"),
button: kit.button?.bg ?? kit.palette?.accent ?? "var(--brand-accent, #ffd23f)",
- buttonText: kit.button?.color ?? kit.palette?.text_on_accent ?? "var(--brand-background, #101010)",
+ buttonText: readable(kit.button?.bg ?? kit.palette?.accent ?? "", kit.button?.color ?? kit.palette?.text_on_accent ?? "var(--brand-background, #101010)"),
};
export const FONTS = {
heading: "var(--brand-font-heading, var(--brand-font, inherit))",
diff --git a/sdk/video/src/captions.tsx b/sdk/video/src/captions.tsx
index eec9fda5..d4bfae69 100644
--- a/sdk/video/src/captions.tsx
+++ b/sdk/video/src/captions.tsx
@@ -116,9 +116,9 @@ function CaptionLine({ g, saying, px, accent, style, className, children }: { g:
color: "var(--brand-text, #fff)",
// a dark plate under the line: the words hold 3:1 over a white wall, a sky or a lit window. A shadow alone
// darkened only the letters' edges, and 12-05's street cuts read 2.4-2.9:1 over bright walls. The brand's
- // --brand-caption-plate restyles it (its colour, or a darker one); 60% black keeps white 5.7:1 and the
- // accent yellow 4:1 over pure white
- background: "var(--brand-caption-plate, rgba(0,0,0,0.6))",
+ // `style` restyles it (its colour, or a darker one); 60% black keeps white 5.7:1 and the accent yellow 4:1
+ // over pure white. A colour, not var(--x, fallback): 12-05's renders drew no plate from the var
+ background: "rgba(0,0,0,0.6)",
padding: `${Math.round(px * 0.06)}px ${Math.round(px * 0.28)}px`,
borderRadius: Math.round(px * 0.16),
textShadow: "0 0 2px rgba(0,0,0,0.95), 0 0 6px rgba(0,0,0,0.8)",