Open source CapCut alternative.
TypeScript
feat(site): a title lights each word as it is said [rebuild]
David Le11137a28bf37
diff --git a/site/src/cut/components/AnimationTiles.tools.ts b/site/src/cut/components/AnimationTiles.tools.tsindex 0a783dda..28f2801b 100644--- a/site/src/cut/components/AnimationTiles.tools.ts+++ b/site/src/cut/components/AnimationTiles.tools.ts@@ -16,6 +16,11 @@ import {GLYPH_LOOP_STYLE_IDS,OVERLAY_ANIM_STYLE_IDS,OVERLAY_LOOP_STYLE_IDS,+ WORD_ACCENT_MODE_IDS,+ WORD_ACCENT_NOTES,+ WORD_POP_SCALE,+ WORD_SWELL_MAX,+ WORD_SWELL_MIN,} from "@donkeycut/effects-kit";import { num, obj, str, type AiToolDef } from "@/cut/lib/aiToolDef";import {@@ -31,7 +36,7 @@ export const OVERLAY_ANIMATION_TOOLS = [{name: "set_overlay_animation",description:- `Animate an overlay element (title, shape, or sticker): preset In/Out ramps, a Loop that runs its whole duration, and a Move that says what the element does WHILE it holds. Omitted slots keep their setting; pass "none" to clear one. In/Out styles: ${OVERLAY_ANIM_STYLE_IDS.join(", ")} — slide names are the motion direction; typewriter animates titles only; ${GLYPH_ANIM_STYLE_IDS.join(", ")} move a title's letters one at a time, and move any other kind as one piece. Loop styles: ${OVERLAY_LOOP_STYLE_IDS.join(", ")} — ${GLYPH_LOOP_STYLE_IDS.join(", ")} carry a title's letters on their own delays, and carry any other kind as one piece. A move is a slot like the others and never touches the element's keyframe track; use set_overlay_keyframes when no named move fits, and both compose together.`,+ `Animate an overlay element (title, shape, or sticker): preset In/Out ramps, a Loop that runs its whole duration, and a Move that says what the element does WHILE it holds. Omitted slots keep their setting; pass "none" to clear one. In/Out styles: ${OVERLAY_ANIM_STYLE_IDS.join(", ")} — slide names are the motion direction; typewriter animates titles only; ${GLYPH_ANIM_STYLE_IDS.join(", ")} move a title's letters one at a time, and move any other kind as one piece. Loop styles: ${OVERLAY_LOOP_STYLE_IDS.join(", ")} — ${GLYPH_LOOP_STYLE_IDS.join(", ")} carry a title's letters on their own delays, and carry any other kind as one piece. A move is a slot like the others and never touches the element's keyframe track; use set_overlay_keyframes when no named move fits, and both compose together. Word emphasis — words_style, titles only — keeps the whole line on screen and lights each word as it is said, timed against the cut's transcript when there is one and spread across the element's own span when there is not; it is the slot for "make each word pop as I say it".`,inputSchema: obj({id: str("Overlay element id"),move: {@@ -60,6 +65,15 @@ export const OVERLAY_ANIMATION_TOOLS = [description: 'Loop style, or "none" to clear',},loop_speed: num("Loop rate multiplier 0.25..4 (default 1)"),+ words_style: {+ type: "string",+ enum: [...WORD_ACCENT_MODE_IDS, "none"],+ description: `How each word is emphasized as it is said, or "none" to clear — ${WORD_ACCENT_MODE_IDS.map((id) => `${id}: ${WORD_ACCENT_NOTES[id]}`).join("; ")}`,+ },+ words_color: str("Word emphasis accent color (hex)"),+ words_scale: num(+ `How far the emphasized word swells, ${WORD_SWELL_MIN}..${WORD_SWELL_MAX} (pop defaults to ${WORD_POP_SCALE}, the others to 1). The swollen word takes its new width in the line, so its neighbours move aside and settle back as the emphasis travels on.`+ ),}, ["id"]),},{diff --git a/site/src/cut/components/AnimationTiles.tsx b/site/src/cut/components/AnimationTiles.tsxindex 2a672fa8..f9afb19f 100644--- a/site/src/cut/components/AnimationTiles.tsx+++ b/site/src/cut/components/AnimationTiles.tsx@@ -16,10 +16,17 @@ import {OVERLAY_ANIM_STYLE_LABELS,OVERLAY_LOOP_STYLE_IDS,OVERLAY_LOOP_STYLE_LABELS,+ contrastText,+ wordAccent,+ WORD_ACCENT_DEFAULT,+ WORD_ACCENT_LABELS,+ WORD_ACCENT_MODE_IDS,type OverlayAnimStyle,type OverlayLoopStyle,+ type WordAccentMode,} from "@donkeycut/effects-kit";import { Tile } from "@/cut/components/PanelTile";+import { wordAccentCss } from "@/cut/lib/textRender";import { fontStack } from "@/cut/lib/types";/**@@ -83,18 +90,20 @@ const referencePx = (slot: Slot, style: string) =>? LOOP_REFERENCE_PX: DEMO_REFERENCE_PX;-type Slot = "in" | "out" | "loop" | "move";+type Slot = "in" | "out" | "loop" | "move" | "words";/** A move runs the element's whole span, so the tile gives it one of its own* to play in — long enough to read a push, short enough to come round again. */const MOVE_DEMO_SECONDS = 2.4;const labelOf = (slot: Slot, style: string) =>- slot === "move"- ? (MOTION.holds[style]?.label ?? style)- : slot === "loop"- ? (OVERLAY_LOOP_STYLE_LABELS[style as OverlayLoopStyle] ?? style)- : (OVERLAY_ANIM_STYLE_LABELS[style as OverlayAnimStyle] ?? style);+ slot === "words"+ ? (WORD_ACCENT_LABELS[style as WordAccentMode] ?? style)+ : slot === "move"+ ? (MOTION.holds[style]?.label ?? style)+ : slot === "loop"+ ? (OVERLAY_LOOP_STYLE_LABELS[style as OverlayLoopStyle] ?? style)+ : (OVERLAY_ANIM_STYLE_LABELS[style as OverlayAnimStyle] ?? style);function demoStateAt(slot: Slot,@@ -282,10 +291,95 @@ function LiveName({);}+/** One turn of a word-emphasis demo, and the share of it the accent holds —+ * long enough to read the treatment arriving and leaving again. */+const WORD_DEMO_SECONDS = 1.7;+const WORD_DEMO_ON = 0.5;+/** The accent reads on a light panel the way it reads over footage: with the+ * same shadow the caption previews give a bright caption color. */+const WORD_DEMO_SHADOW = "0 0 2px rgba(0, 0, 0, 0.6)";++/** A word-emphasis name: the label sits plain, then takes the accent the way+ * it will when that word is said. Written straight to the element, like every+ * other demo here. */+function WordName({+ style,+ textColor,+ accentColor,+ scale,+ index = 0,+}: {+ style: string;+ /** The element's own text color — what a swell keeps. */+ textColor: string;+ /** The accent it was given, if any. */+ accentColor?: string;+ /** The element's own swell, so a tile shows the size it will apply. */+ scale?: number;+ index?: number;+}) {+ const ref = useRef<HTMLSpanElement>(null);+ const phase = index * PHASE_STEP * WORD_DEMO_SECONDS;+ useEffect(() => {+ const el = ref.current;+ if (!el) return;+ const mode = style as WordAccentMode;+ const color = wordAccent({ style: mode, color: accentColor }, textColor);+ const css = wordAccentCss({+ mode,+ color,+ text: contrastText(color),+ scale,+ // The tile's name sits on one line of its own; the stage gives it room.+ lineHeight: 1,+ });+ const props = el.style as unknown as Record<string, string>;+ const rest = () => {+ for (const k of Object.keys(css)) props[k] = "";+ el.style.textShadow = "";+ };+ const accent = () => {+ Object.assign(el.style, css);+ if (mode !== "box") el.style.textShadow = WORD_DEMO_SHADOW;+ };+ if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {+ accent();+ return rest;+ }+ let start = 0;+ let raf = 0;+ let on: boolean | null = null;+ const tick = (now: number) => {+ if (!start) start = now;+ const p = (((now - start) / 1000 + phase) % WORD_DEMO_SECONDS) / WORD_DEMO_SECONDS;+ const next = p < WORD_DEMO_ON;+ if (next !== on) {+ on = next;+ if (next) accent();+ else rest();+ }+ raf = requestAnimationFrame(tick);+ };+ raf = requestAnimationFrame(tick);+ return () => {+ cancelAnimationFrame(raf);+ rest();+ };+ }, [style, textColor, accentColor, scale, phase]);+ return (+ <span ref={ref} className={`${WORD} text-foreground`} style={wordStyle()}>+ {labelOf("words", style)}+ </span>+ );+}+/** The name in its tile: the motion itself while the tile is playing, the* plain name when it is not. */function AnimName({playing,+ textColor,+ accentColor,+ accentScale,...rest}: {slot: Slot;@@ -295,12 +389,25 @@ function AnimName({speed: number;playing: boolean;index?: number;+ /** The element's own text color, for the words tiles. */+ textColor?: string;+ /** The accent it was given, if any. */+ accentColor?: string;+ /** Its swell, so the tiles show the size the pick will apply. */+ accentScale?: number;}) {- return playing ? (- <LiveName {...rest} />- ) : (- <FrozenName slot={rest.slot} style={rest.style} />- );+ if (!playing) return <FrozenName slot={rest.slot} style={rest.style} />;+ if (rest.slot === "words")+ return (+ <WordName+ style={rest.style}+ textColor={textColor ?? WORD_ACCENT_DEFAULT}+ accentColor={accentColor}+ scale={accentScale}+ index={rest.index}+ />+ );+ return <LiveName {...rest} />;}/** Whether the element is on screen. A tile off the scroll's edge keeps its@@ -327,6 +434,9 @@ function AnimTile({speed,index,selected,+ textColor,+ accentColor,+ accentScale,onPick,}: {slot: Slot;@@ -337,6 +447,12 @@ function AnimTile({/** Place in the grid, which sets this tile's beat in the cascade. */index: number;selected: boolean;+ /** The element's own text color, for the words tiles. */+ textColor?: string;+ /** The accent it was given, if any. */+ accentColor?: string;+ /** Its swell, so a words tile shows the size the pick will apply. */+ accentScale?: number;onPick: () => void;}) {const ref = useRef<HTMLButtonElement>(null);@@ -357,6 +473,9 @@ function AnimTile({seconds={seconds}speed={speed}index={index}+ textColor={textColor}+ accentColor={accentColor}+ accentScale={accentScale}playing={onScreen}/></span>@@ -376,6 +495,9 @@ export function AnimationCard({seconds,speed,index = 0,+ textColor,+ accentColor,+ accentScale,onOpen,onClear,}: {@@ -386,6 +508,12 @@ export function AnimationCard({speed: number;/** Place in the row, which sets where in its cycle this card starts. */index?: number;+ /** The element's own text color, for a words card. */+ textColor?: string;+ /** The accent it was given, if any. */+ accentColor?: string;+ /** Its swell, so the card shows the size the element is wearing. */+ accentScale?: number;onOpen: () => void;onClear: () => void;}) {@@ -408,6 +536,9 @@ export function AnimationCard({seconds={seconds}speed={speed}index={index}+ textColor={textColor}+ accentColor={accentColor}+ accentScale={accentScale}playing={onScreen}/></span>@@ -435,6 +566,9 @@ export function AnimationTiles({isText,seconds,speed,+ textColor,+ accentColor,+ accentScale,onPick,}: {slot: Slot;@@ -449,14 +583,23 @@ export function AnimationTiles({seconds: number;/** The loop speed the panel has set — the hover demo's cycle rate. */speed: number;+ /** The element's own text color, so the words tiles demo the color each+ * treatment will actually wear. */+ textColor?: string;+ /** The accent it was given, if any. */+ accentColor?: string;+ /** Its swell, so the tiles show the size a pick will apply. */+ accentScale?: number;onPick: (style: string | null) => void;}) {const ids: string[] =- slot === "move"- ? HOLD_IDS- : slot === "loop"- ? OVERLAY_LOOP_STYLE_IDS- : OVERLAY_ANIM_STYLE_IDS.filter((s) => s !== "typewriter" || isText);+ slot === "words"+ ? WORD_ACCENT_MODE_IDS+ : slot === "move"+ ? HOLD_IDS+ : slot === "loop"+ ? OVERLAY_LOOP_STYLE_IDS+ : OVERLAY_ANIM_STYLE_IDS.filter((s) => s !== "typewriter" || isText);return (<div className="grid grid-cols-2 gap-[9px]">@@ -476,6 +619,9 @@ export function AnimationTiles({seconds={seconds}speed={speed}index={i}+ textColor={textColor}+ accentColor={accentColor}+ accentScale={accentScale}selected={value === id}onPick={() => onPick(id)}/>diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex b1a3bd04..76e70b87 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -17,6 +17,7 @@ import { Textarea } from "@/components/ui/textarea";import {EFFECT_LABELS,hasMaskKeys,+ hasOverlayAnim,hasOverlayKeys,KEY_EPSILON,keyIndexAt,@@ -33,15 +34,23 @@ import {ZOOM_LEVELS,ZOOM_RAMP_MAX,zoomRampOf,+ wordAccent,+ WORD_ACCENT_DEFAULT,+ WORD_POP_SCALE,+ WORD_SWELL_MAX,+ WORD_SWELL_MIN,+ wordSwell,type OverlayAnim,type OverlayAnimStyle,type OverlayLoopStyle,+ type WordAccentMode,} from "@donkeycut/effects-kit";import { clipWindow, useEditor, type EditorState } from "@/cut/lib/store";import { usePreviewTime } from "@/cut/lib/playhead";import { CLIP_MAX_ZOOM, clipKeyed, clipPoseAt, clipZoom, contentRect } from "@/cut/lib/types";import { AnimationCard, AnimationTiles } from "@/cut/components/AnimationTiles";import { ColorField } from "@/cut/components/ColorField";+import { wordTimesFor } from "@/cut/lib/textWords";import { NumberField } from "@/cut/components/NumberField";import { playAnimPreview, stopAnimPreview } from "@/cut/lib/animPreview";import { GenerateSubtitlesAudio } from "@/cut/components/VoicePicker";@@ -1464,11 +1473,27 @@ function writeOverlayAnim(o: Overlay, anim: OverlayAnim, patch: Partial<OverlayAif (!next.out) delete next.out;if (!next.loop) delete next.loop;if (!next.move) delete next.move;- const value = next.in || next.out || next.loop || next.move ? next : undefined;+ if (!next.words) delete next.words;+ const value = hasOverlayAnim(next) ? next : undefined;const st = useEditor.getState();const peers = o.groupId ? st.overlays.filter((x) => x.groupId === o.groupId) : [];- const ids = peers.length > 1 ? peers.map((p) => p.id) : [o.id];- st.updateOverlaysTransient(ids.map((id) => ({ id, patch: { anim: value } })));+ const targets = peers.length > 1 ? peers : [o];+ st.updateOverlaysTransient(+ targets.map((el) => {+ if (!value?.words || !isTextOverlay(el)) return { id: el.id, patch: { anim: value } };+ // Word times are the element's own — each one's words are said at its+ // own moment — so a grouped write times every member against the cut+ // rather than copying one member's clock onto the rest. Times already+ // measured ride through: the alignment runs when a slot is first filled,+ // never on every frame of a slider drag.+ const carried = el.id === o.id ? value.words.times : el.anim?.words?.times;+ const times = carried ?? wordTimesFor(el, st.subtitles.cues);+ return {+ id: el.id,+ patch: { anim: { ...value, words: { ...value.words, ...(times ? { times } : {}) } } },+ };+ })+ );}/** The set slot's Length (In/Out) or Speed (Loop) slider. */@@ -1556,8 +1581,8 @@ function AnimationSection({if (reveal) ref.current?.scrollIntoView({ block: "nearest" });}, [reveal]);const anim = o.anim ?? {};- const slots = (["in", "out", "loop"] as const).filter((s) => anim[s]);- const clear = (slot: "in" | "out" | "loop") => {+ const slots = (["in", "out", "loop", "words"] as const).filter((s) => anim[s]);+ const clear = (slot: "in" | "out" | "loop" | "words") => {stopAnimPreview();useEditor.getState().pushHistory();writeOverlayAnim(o, anim, { [slot]: undefined });@@ -1584,10 +1609,15 @@ function AnimationSection({key={slot}slot={slot}index={i}- style={slot === "loop" ? anim.loop!.style : anim[slot]!.style}+ style={anim[slot]!.style}isText={isTextOverlay(o)}- seconds={slot === "loop" ? OVERLAY_ANIM_DEFAULT_SECONDS : anim[slot]!.seconds}+ seconds={+ slot === "in" || slot === "out" ? anim[slot]!.seconds : OVERLAY_ANIM_DEFAULT_SECONDS+ }speed={anim.loop?.speed ?? 1}+ textColor={isTextOverlay(o) ? o.color : WORD_ACCENT_DEFAULT}+ accentColor={anim.words?.color}+ accentScale={anim.words?.scale}onOpen={onOpen}onClear={() => clear(slot)}/>@@ -1598,6 +1628,7 @@ function AnimationSection({<AnimSlotSlider overlay={o} slot="out" label="Out duration" /><AnimSlotSlider overlay={o} slot="loop" label="Loop speed" /><MoveStrengthRow overlay={o} />+ <WordSizeRow overlay={o} /></Section></div>);@@ -1647,18 +1678,84 @@ function MoveStrengthRow({ overlay: o }: { overlay: Overlay }) {return <MoveStrengthSlider overlay={o} label="Move strength" />;}-/** The animation subview an overlay panel pushes into: In / Out / Loop tabs- * over the tile grid, the active slot's length or speed under it. The three- * slots pick from the same grid, one at a time — the tiles are big enough to- * read the motion, which three stacked grids would not be. */+/** How far the emphasized word swells, in the collapsed section — there only+ * once the words slot is filled. */+function WordSizeRow({ overlay: o }: { overlay: Overlay }) {+ const ck = useSliderCheckpoint();+ const anim = o.anim ?? {};+ const words = anim.words;+ if (!words) return null;+ const write = (v: number) => {+ ck.begin();+ writeOverlayAnim(o, anim, { words: { ...words, scale: v } });+ };+ return (+ <Row label="Word size">+ <ValueSlider+ label="Word size"+ sliderClassName="data-horizontal:w-24"+ valueClassName="w-9 text-muted-foreground"+ value={wordSwell(words)}+ min={WORD_SWELL_MIN}+ max={WORD_SWELL_MAX}+ step={0.02}+ snap={[1, WORD_POP_SCALE]}+ format={(v) => `${v.toFixed(2)}×`}+ parse={parseSpeedInput}+ onDraft={write}+ onCommit={(v) => {+ write(v);+ ck.end();+ }}+ />+ </Row>+ );+}++/** The slots the picker fills, in tab order. */+type AnimSlot = "in" | "out" | "loop" | "move" | "words";++/** The animation subview an overlay panel pushes into: a tab per slot over+ * the tile grid, the active slot's own control under it. The slots pick from+ * the same grid, one at a time — the tiles are big enough to read the motion,+ * which a stack of grids would not be. */function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () => void }) {const anim = o.anim ?? {};- const [slot, setSlot] = useState<"in" | "out" | "loop" | "move">("in");- const active = slot === "move" ? undefined : anim[slot];- const seconds =- slot === "loop" || slot === "move" ? undefined : (anim[slot] as OverlayAnim["in"])?.seconds;+ const [picked, setSlot] = useState<AnimSlot>("in");+ // Word emphasis is a title's slot; a shape or a sticker has no words, so+ // selecting one hands the picker back to the entrance.+ const tabs: AnimSlot[] = isTextOverlay(o)+ ? ["in", "out", "loop", "move", "words"]+ : ["in", "out", "loop", "move"];+ const slot = tabs.includes(picked) ? picked : "in";+ const active = slot === "move" || slot === "words" ? undefined : anim[slot];+ const seconds = slot === "in" || slot === "out" ? anim[slot]?.seconds : undefined;const activeMove = anim.move;const pick = (style: string | null) => {+ if (slot === "words") {+ if (!style && !anim.words) return;+ useEditor.getState().pushHistory();+ // The transcript is the clock: the times land at apply, measured+ // against whatever the cut has been transcribed to say. Nothing to+ // measure against leaves them out, and the words share the element's+ // span instead.+ const patch: Partial<OverlayAnim> = {+ words: style+ ? {+ style: style as WordAccentMode,+ ...(anim.words?.color ? { color: anim.words.color } : {}),+ ...(anim.words?.scale !== undefined ? { scale: anim.words.scale } : {}),+ }+ : undefined,+ };+ writeOverlayAnim(o, anim, patch);+ // The pick sweeps itself along the line, the same as any other slot.+ if (style) {+ const el = useEditor.getState().overlays.find((x) => x.id === o.id) ?? o;+ playAnimPreview(el, "words");+ } else stopAnimPreview();+ return;+ }if (slot === "move") {if (!style && !activeMove) return;useEditor.getState().pushHistory();@@ -1714,7 +1811,7 @@ function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () =Animation</div><div className="mx-3.5 flex shrink-0 rounded-lg bg-muted p-0.5 text-[11.5px] font-medium">- {(["in", "out", "loop", "move"] as const).map((id) => (+ {tabs.map((id) => (<buttonkey={id}type="button"@@ -1748,11 +1845,22 @@ function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () =// A slot carrying its own preset is playing something no tile here// names, so the grid shows nothing selected rather than the catalog// entry the id happens to hold.- value={active?.preset ? undefined : slot === "move" ? activeMove?.style : active?.style}+ value={+ active?.preset+ ? undefined+ : slot === "move"+ ? activeMove?.style+ : slot === "words"+ ? anim.words?.style+ : active?.style+ }custom={!!active?.preset}isText={isTextOverlay(o)}seconds={seconds ?? OVERLAY_ANIM_DEFAULT_SECONDS}speed={anim.loop?.speed ?? 1}+ textColor={isTextOverlay(o) ? o.color : WORD_ACCENT_DEFAULT}+ accentColor={anim.words?.color}+ accentScale={anim.words?.scale}onPick={pick}/></ScrollArea>@@ -1767,13 +1875,7 @@ function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () =* pushes — so the bar shows the tab's own control and nothing else. It stays* put with the slot unset, greyed rather than gone, because a bar that comes* and goes moves the grid under the pointer. */-function AnimationToolbar({- overlay: o,- slot,-}: {- overlay: Overlay;- slot: "in" | "out" | "loop" | "move";-}) {+function AnimationToolbar({ overlay: o, slot }: { overlay: Overlay; slot: AnimSlot }) {const ck = useSliderCheckpoint();const anim = o.anim ?? {};const dur = Math.max(0.2, o.end - o.start);@@ -1785,6 +1887,50 @@ function AnimationToolbar({if (slot === "move") return bar(<MoveStrengthSlider overlay={o} label="Strength" />);+ if (slot === "words") {+ // The words tab's two settings: how far the word swells while it is said,+ // and the accent it wears.+ const words = anim.words;+ const size = (v: number) => {+ if (!words) return;+ ck.begin();+ writeOverlayAnim(o, anim, { words: { ...words, scale: v } });+ };+ return bar(+ <>+ <Row label="Word size">+ <ValueSlider+ label="Word size"+ sliderClassName="data-horizontal:w-24"+ valueClassName="w-9 text-muted-foreground"+ value={wordSwell(words)}+ min={WORD_SWELL_MIN}+ max={WORD_SWELL_MAX}+ step={0.02}+ snap={[1, WORD_POP_SCALE]}+ format={(v) => `${v.toFixed(2)}×`}+ parse={parseSpeedInput}+ disabled={!words}+ onDraft={size}+ onCommit={(v) => {+ size(v);+ ck.end();+ }}+ />+ </Row>+ <Row label="Word color">+ <ColorField+ value={wordAccent(words, isTextOverlay(o) ? o.color : WORD_ACCENT_DEFAULT)}+ label="Word color"+ onBegin={() => useEditor.getState().pushHistory()}+ onLive={(c) => words && writeOverlayAnim(o, anim, { words: { ...words, color: c } })}+ onCommit={(c) => words && writeOverlayAnim(o, anim, { words: { ...words, color: c } })}+ />+ </Row>+ </>+ );+ }+if (slot === "loop") {const write = (speed: number) => {if (!anim.loop) return;diff --git a/site/src/cut/components/OverlayLayer.tsx b/site/src/cut/components/OverlayLayer.tsxindex a8f1a752..7d2c2313 100644--- a/site/src/cut/components/OverlayLayer.tsx+++ b/site/src/cut/components/OverlayLayer.tsx@@ -17,7 +17,7 @@ import {subtitleLaneCount,trackPos,} from "@/cut/lib/subtitles";-import { evalOverlayFrame, glyphStateAt, hasGlyphMotion, hasMaskKeys, hasOverlayKeys, isOverlayAnimated, lineLikeShape, maskFrameAt, paintMaskCoverage, resolveShadow, shapeMetrics, shapePathD, textStretch, type LottieHandle, type Mask, type MaskKey, type OverlayFrameState } from "@donkeycut/effects-kit";+import { contrastText, evalOverlayFrame, glyphStateAt, hasGlyphMotion, hasMaskKeys, hasOverlayKeys, isOverlayAnimated, lineLikeShape, maskFrameAt, overlayWords, paintMaskCoverage, resolveShadow, shapeMetrics, shapePathD, textStretch, WORD_ACCENT_DEFAULT, wordAccent, wordAccentIndex, type LottieHandle, type Mask, type MaskKey, type OverlayFrameState } from "@donkeycut/effects-kit";import {LINE_HEIGHT,PLATE_PAD_X,@@ -25,6 +25,7 @@ import {PLATE_RADIUS,plateFill,SHADOW,+ wordAccentCss,} from "@/cut/lib/textRender";import {behindSubjectOverlay,@@ -347,6 +348,34 @@ export function OverlayLayer({);}+/** Text with one word emphasized. The words are walked exactly the way the+ * canvas painter walks them — line by line, single-spaced — so the index the+ * preview lights is the index the burn-in lights. */+function AccentedText({ text, index, css }: { text: string; index: number; css: CSSProperties }) {+ let k = 0;+ return (+ <>+ {text.split("\n").map((line, li) => (+ <span key={li} className="block">+ {line+ .split(" ")+ .filter(Boolean)+ .map((w, wi) => {+ const active = k === index;+ k++;+ return (+ <span key={wi}>+ {wi > 0 && " "}+ <span style={active ? css : undefined}>{w}</span>+ </span>+ );+ })}+ </span>+ ))}+ </>+ );+}+/** Every subtitle track's active cue, one caption per language. */function SubtitleCaptions(props: {stageWidth: number;@@ -410,27 +439,12 @@ function SubtitleCaption({const wordIndex = subtitles.wordHighlight? cueWordWindows(cue).findIndex((w) => t >= w.start && t < w.end): -1;- // The spoken word's treatment follows the style (with user overrides): an- // accent box (drawn with box-shadow spread so the line never reflows), the- // accent color alone, or accent color + underline.+ // The spoken word's treatment follows the style (with user overrides): a+ // swell in the accent color, an accent box (drawn with box-shadow spread so+ // the line never reflows), the accent color alone, or accent color ++ // underline. The swell is a transform, so it too leaves the line alone.const look = karaokeLook(style, subtitles);- const activeStyle: CSSProperties =- look.mode === "box"- ? {- color: look.text,- background: look.color,- boxShadow: `0 0 0 0.12em ${look.color}`,- borderRadius: "0.18em",- textShadow: "none",- }- : look.mode === "color"- ? { color: look.color }- : {- color: look.color,- textDecoration: "underline",- textDecorationThickness: "0.07em",- textUnderlineOffset: "0.14em",- };+ const activeStyle = wordAccentCss(look);const scale = stageWidth / frame.w;return (<div@@ -470,25 +484,11 @@ function SubtitleCaption({borderRadius: ov.plate ? PLATE_RADIUS_EM : undefined,}}>- {wordIndex < 0- ? ov.text- : (() => {- let k = 0;- return ov.text.split("\n").map((line, li) => (- <span key={li} className="block">- {line.split(" ").map((w, wi) => {- const active = k === wordIndex;- k++;- return (- <span key={wi}>- {wi > 0 && " "}- <span style={active ? activeStyle : undefined}>{w}</span>- </span>- );- })}- </span>- ));- })()}+ {wordIndex < 0 ? (+ ov.text+ ) : (+ <AccentedText text={ov.text} index={wordIndex} css={activeStyle} />+ )}</div>);}@@ -584,6 +584,26 @@ function OverlayItem({// box from its left edge. Neither runs while the box is being edited.const glyphs = isText && !editing && live && hasGlyphMotion(live) ? live : null;const reveal = !editing ? live?.reveal : undefined;+ // Word emphasis: the word being said wears the accent while the rest of the+ // line stays as it is. Off while editing — the box is plain text then — and+ // a per-glyph ramp takes the frame for itself while it runs.+ const words = isText && !editing ? overlayWords(o) : undefined;+ // A rehearsal from the inspector sweeps the emphasis along the line on its+ // own clock; otherwise it follows the playhead, like everything else here.+ const wordLocal = running ? running.tLocal : Math.max(0, t - o.start);+ const wordIndex =+ words && !glyphs ? wordAccentIndex(o, wordLocal, Math.max(0.1, o.end - o.start)) : -1;+ const wordColor = wordAccent(words, isTextOverlay(o) ? o.color : WORD_ACCENT_DEFAULT);+ const wordCss =+ words && wordIndex >= 0+ ? wordAccentCss({+ mode: words.style,+ color: wordColor,+ text: contrastText(wordColor),+ scale: words.scale,+ lineHeight: (isTextOverlay(o) ? o.lineHeight : undefined) ?? LINE_HEIGHT,+ })+ : null;// Typewriter: the visible slice of the text (display only, never while// the box is being edited).const shownText =@@ -1033,6 +1053,8 @@ function OverlayItem({</div>) : glyphs ? (<GlyphText text={shownText} phase={glyphs} scale={scale} />+ ) : wordCss ? (+ <AccentedText text={shownText} index={wordIndex} css={wordCss} />) : (<span>{shownText}</span>)diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex f150e86f..9eb50fef 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -22,6 +22,10 @@ import {OVERLAY_ANIM_MIN_SECONDS,OVERLAY_ANIM_STYLE_IDS,OVERLAY_LOOP_STYLE_IDS,+ hasOverlayAnim,+ WORD_ACCENT_MODE_IDS,+ WORD_SWELL_MAX,+ WORD_SWELL_MIN,type OverlayAnim,type OverlayAnimStyle,type OverlayLoopStyle,@@ -91,10 +95,11 @@ import { renderStageFrame, storeStageStill } from "./stageFrame";import { createRasterCanvas, decodeRasterImageUrl, rasterCanvasToDataUrl } from "./raster";import { buildAiContext } from "./aiContext";import { sampleClipFrameData } from "./previewCanvas";-import { CAPTION_STYLES, laneCues, subtitleLaneCount } from "./subtitles";+import { CAPTION_STYLES, laneCues, subtitleLaneCount, WORD_ACCENT_MODES } from "./subtitles";import { fuseTimeline, renderFusedTimeline } from "./watch/fuse";import { mergeWatch, mergeWatchNotes, uncoveredSeconds, unnotedSpans } from "./watch/merge";-import { syncLines, type TimedWord } from "./lyricSync";+import { syncLines } from "./lyricSync";+import { transcriptWords as cueWords, wordTimesFor } from "./textWords";import {composeTextRun,TEXT_LAYOUT_IDS,@@ -146,6 +151,7 @@ import {type AnimStyle,type AssetWatch,type CaptionStyleId,+ type WordAccentMode,type AudioClip,type ClipShadow,type ColorGrade,@@ -462,9 +468,39 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {} else if (speed !== undefined && anim.loop) {anim.loop = { ...anim.loop, speed };}- s.updateOverlay(o.id, {- anim: anim.in || anim.out || anim.loop || anim.move ? anim : undefined,- });+ const rawWords = input.words_style;+ const wordColor = typeof input.words_color === "string" ? input.words_color : undefined;+ const wordScale = isNum(input.words_scale)+ ? clamp(input.words_scale, WORD_SWELL_MIN, WORD_SWELL_MAX)+ : undefined;+ if (typeof rawWords === "string") {+ if (rawWords === "none") delete anim.words;+ else if (!(WORD_ACCENT_MODE_IDS as string[]).includes(rawWords))+ throw new ToolError(`Unknown word emphasis: ${rawWords}`);+ else if ((o.kind ?? "text") !== "text")+ throw new ToolError("Word emphasis lights up a title's words; it needs a title.");+ else {+ const color = wordColor ?? anim.words?.color;+ const scale = wordScale ?? anim.words?.scale;+ // The transcript is the clock the emphasis follows. It is read now,+ // against whatever the cut has been transcribed to say; with nothing+ // to read, the words share the element's own span.+ const times = isTextOverlay(o) ? wordTimesFor(o, s.subtitles.cues) : undefined;+ anim.words = {+ style: rawWords as WordAccentMode,+ ...(color ? { color } : {}),+ ...(scale !== undefined ? { scale } : {}),+ ...(times ? { times } : {}),+ };+ }+ } else if ((wordColor || wordScale !== undefined) && anim.words) {+ anim.words = {+ ...anim.words,+ ...(wordColor ? { color: wordColor } : {}),+ ...(wordScale !== undefined ? { scale: wordScale } : {}),+ };+ }+ s.updateOverlay(o.id, { anim: hasOverlayAnim(anim) ? anim : undefined });const next = useEditor.getState().overlays.find((x) => x.id === o.id)!;return { id: next.id, anim: next.anim ?? null };},@@ -1592,8 +1628,13 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {patch.font = input.font;if (typeof input.word_highlight === "boolean") patch.wordHighlight = input.word_highlight;if (typeof input.accent_color === "string") patch.accentColor = input.accent_color;- if (input.accent_mode === "color" || input.accent_mode === "underline" || input.accent_mode === "box")- patch.accentMode = input.accent_mode;+ if (WORD_ACCENT_MODES.some((m) => m.id === input.accent_mode)) {+ patch.accentMode = input.accent_mode as WordAccentMode;+ // Naming a treatment is asking for the emphasis, so it comes on with+ // the mode unless this same call turned it off.+ if (patch.wordHighlight === undefined && !s.subtitles.wordHighlight)+ patch.wordHighlight = true;+ }if (isNum(input.y)) patch.y = clamp(input.y, 0.02, 0.98);if (isNum(input.x)) patch.x = clamp(input.x, 0.02, 0.98);if (Object.keys(patch).length === 0) throw new ToolError("Nothing to change.");@@ -3348,19 +3389,7 @@ async function synthesizeVoiceover(/** The words a caption track carries, on the timeline clock: the* transcriber's own word times where it left them, and an even split of each* cue's span where it did not. */-function cueWords(cues: { start: number; end: number; text: string; words?: TimedWord[] }[]): TimedWord[] {- const out: TimedWord[] = [];- for (const c of cues) {- if (c.words && c.words.length > 0) {- out.push(...c.words);- continue;- }- const parts = c.text.split(/\s+/).filter((w) => w.length > 0);- const step = parts.length > 0 ? (c.end - c.start) / parts.length : 0;- parts.forEach((w, i) => out.push({ w, t0: c.start + step * i, t1: c.start + step * (i + 1) }));- }- return out;-}+/** An alignment pass as the model reads it. The audio declining to testify is* a result of its own, never a silent success: a caller told "0 moved" withoutdiff --git a/site/src/cut/lib/animPreview.ts b/site/src/cut/lib/animPreview.tsindex d806dd68..158c72e3 100644--- a/site/src/cut/lib/animPreview.ts+++ b/site/src/cut/lib/animPreview.ts@@ -72,21 +72,22 @@ export function releaseAnimRest(id: string): void {notify();}-/** The longest a move rehearsal takes. A move runs the element's whole span,- * which can be half a minute; anything past this sweeps the same motion- * through in this long instead, so the shape reads without the wait. */-const MOVE_REHEARSAL_MAX = 2.4;+/** The longest a whole-span rehearsal takes. A move and word emphasis both+ * run the element's whole span, which can be half a minute; anything past+ * this sweeps through in this long instead, so the shape reads without the+ * wait. */+const SPAN_REHEARSAL_MAX = 2.4;/*** Play `slot` on `o` from its own starting point: In sweeps the head of the- * element, Out its tail, a loop runs one cycle, and a move runs the element's- * whole span. The run carries that slot alone, so rehearsing one animation- * never drags the element's others into the picture. Nothing plays when the- * slot is empty.+ * element, Out its tail, a loop runs one cycle, and a move or a run of word+ * emphasis runs the element's whole span. The run carries that slot alone, so+ * rehearsing one animation never drags the element's others into the picture.+ * Nothing plays when the slot is empty.*/export function playAnimPreview(o: { id: string; start: number; end: number; anim?: OverlayAnim },- slot: "in" | "out" | "loop" | "move"+ slot: "in" | "out" | "loop" | "move" | "words"): void {stopAnimPreview();const anim: OverlayAnim =@@ -96,19 +97,23 @@ export function playAnimPreview(? { out: o.anim?.out }: slot === "loop"? { loop: o.anim?.loop }- : { move: o.anim?.move };+ : slot === "move"+ ? { move: o.anim?.move }+ : { words: o.anim?.words };+ const wholeSpan = slot === "move" || slot === "words";if (slot === "move" && !anim.move) return;+ if (slot === "words" && !anim.words) return;const dur = Math.max(0.1, o.end - o.start);- const span =- slot === "move"- ? dur- : slot === "loop"- ? (loopPeriod(anim) ?? 0)- : Math.min((slot === "in" ? anim.in?.seconds : anim.out?.seconds) ?? 0, dur);+ const span = wholeSpan+ ? dur+ : slot === "loop"+ ? (loopPeriod(anim) ?? 0)+ : Math.min((slot === "in" ? anim.in?.seconds : anim.out?.seconds) ?? 0, dur);if (span <= 0) return;- // How long the rehearsal takes on the wall clock. Every slot but a move- // plays at its own speed; a long move is compressed into the cap.- const window = slot === "move" ? Math.min(span, MOVE_REHEARSAL_MAX) : span;+ // How long the rehearsal takes on the wall clock. A slot that plays at its+ // own speed keeps it; one that runs the whole span is compressed into the+ // cap.+ const window = wholeSpan ? Math.min(span, SPAN_REHEARSAL_MAX) : span;// Where the slot lives inside the element: In, a loop and a move start at// its head, Out ends at its tail.const from = slot === "out" ? dur - span : 0;diff --git a/site/src/cut/lib/behindPass.ts b/site/src/cut/lib/behindPass.tsindex 0b430b3b..af6750f6 100644--- a/site/src/cut/lib/behindPass.ts+++ b/site/src/cut/lib/behindPass.ts@@ -9,7 +9,16 @@* behind effect degrades to the plain picture.*/-import { evalOverlayFrame, glyphStateAt, hasGlyphMotion, maskComposite } from "@donkeycut/effects-kit";+import {+ applyWordAccent,+ evalOverlayFrame,+ glyphStateAt,+ hasGlyphMotion,+ maskComposite,+ overlayWords,+ wordAccentIndex,+ wordWindows,+} from "@donkeycut/effects-kit";import { personSegmenter, segmentSubjectAlpha } from "./cutout";import { createRasterCanvas } from "./raster";import { renderElementPng } from "./textRender";@@ -25,6 +34,18 @@ import {type Segmenter = import("@mediapipe/tasks-vision").ImageSegmenter;+/** An element's own length, the span its word emphasis is timed across. */+const spanOf = (o: Overlay): number => Math.max(0.1, o.end - o.start);++/** The word indices an element needs a picture for: one per word while it+ * lights them as they are said, and the plain picture (-1) otherwise. */+function rasterWords(o: Overlay): number[] {+ const words = overlayWords(o);+ if (!words || !isTextOverlay(o)) return [-1];+ const n = wordWindows(o.text, spanOf(o), words.times).length;+ return n > 0 ? Array.from({ length: n }, (_, i) => i) : [-1];+}+/** Segmentation input width — small on purpose; this runs per frame. */const SEG_WIDTH = 256;@@ -81,8 +102,11 @@ export class SubjectMaskCompositor {private segmenter: Segmenter | null = null;private segKicked = false;- private rasters = new WeakMap<Overlay, ImageBitmap>();- private pending = new WeakSet<Overlay>();+ // One picture per element, and one per emphasized word when the element+ // lights its words as they are said — keyed by the element object, so an+ // edit hands back a fresh picture rather than a stale one.+ private rasters = new WeakMap<Overlay, Map<number, ImageBitmap>>();+ private pending = new WeakMap<Overlay, Set<number>>();private person: HTMLCanvasElement | null = null;private small: HTMLCanvasElement | null = null;private mask: { at: number; alpha: HTMLCanvasElement | null } = { at: -1e9, alpha: null };@@ -100,21 +124,47 @@ export class SubjectMaskCompositor {});}- private rasterFor(o: Overlay, w: number, h: number, assets: MediaAsset[]): ImageBitmap | null {- const hit = this.rasters.get(o);+ private rasterFor(+ o: Overlay,+ w: number,+ h: number,+ assets: MediaAsset[],+ word: number+ ): ImageBitmap | null {+ const hit = this.rasters.get(o)?.get(word);if (hit) return hit;- if (!this.pending.has(o)) {- this.pending.add(o);+ const inFlight = this.pending.get(o) ?? new Set<number>();+ if (!inFlight.has(word)) {+ inFlight.add(word);+ this.pending.set(o, inFlight);// Neutral picture: position aside, the per-frame pose owns rotation and// opacity, so baking them here would apply each of them twice.- void renderElementPng({ ...o, rotation: undefined, opacity: undefined }, w, h, assets)- .then((png) => createImageBitmap(png))- .then((bmp) => this.rasters.set(o, bmp))- .catch(() => {});+ void this.drawRaster(o, w, h, assets, word).catch(() => {});}return null;}+ /** One element picture, with the word it emphasizes at this moment baked+ * in, kept under the element it came from. */+ private async drawRaster(+ o: Overlay,+ w: number,+ h: number,+ assets: MediaAsset[],+ word: number+ ): Promise<void> {+ const png = await renderElementPng(+ applyWordAccent({ ...o, rotation: undefined, opacity: undefined }, word),+ w,+ h,+ assets+ );+ const bmp = await createImageBitmap(png);+ const byWord = this.rasters.get(o) ?? new Map<number, ImageBitmap>();+ byWord.set(word, bmp);+ this.rasters.set(o, byWord);+ }+/** Export path: everything resident before the first frame draws. */async prepare(overlays: Overlay[], w: number, h: number, assets: MediaAsset[]): Promise<void> {this.ensureSegmenter();@@ -123,20 +173,18 @@ export class SubjectMaskCompositor {});const behind = overlays.filter((o) => behindSubjectOverlay(o) && drawable(o));await Promise.all(- behind.map(async (o) => {- if (this.rasters.get(o)) return;- try {- const png = await renderElementPng(- { ...o, rotation: undefined, opacity: undefined },- w,- h,- assets- );- this.rasters.set(o, await createImageBitmap(png));- } catch {- // The overlay just draws in front when its raster is missing.- }- })+ behind.flatMap((o) =>+ // An element that lights its words needs one picture per word, all of+ // them resident before the first frame draws.+ rasterWords(o).map(async (word) => {+ if (this.rasters.get(o)?.has(word)) return;+ try {+ await this.drawRaster(o, w, h, assets, word);+ } catch {+ // The overlay just draws in front when its raster is missing.+ }+ })+ ));}@@ -304,9 +352,10 @@ export class SubjectMaskCompositor {// export's stamped layers.const scale = Math.min(W, H) / 1080;for (const o of active) {- const bmp = this.rasterFor(o, W, H, assets);+ const tLocal = Math.max(0, t - o.start);+ const bmp = this.rasterFor(o, W, H, assets, wordAccentIndex(o, tLocal, spanOf(o)));if (!bmp) continue;- const ev = evalOverlayFrame(o, Math.max(0, t - o.start));+ const ev = evalOverlayFrame(o, tLocal);// One cached picture per element here, so a per-glyph ramp or loop runs// its motion over the whole box as a single letter would.const g = hasGlyphMotion(ev) ? glyphStateAt(ev, 0, 1) : null;diff --git a/site/src/cut/lib/textRender.ts b/site/src/cut/lib/textRender.tsindex 0e628e47..4184f441 100644--- a/site/src/cut/lib/textRender.ts+++ b/site/src/cut/lib/textRender.ts@@ -3,13 +3,16 @@import {renderElementPng as kitRenderElementPng,renderOverlayFrames as kitRenderOverlayFrames,+ LINE_HEIGHT,+ wordSwell,type OverlayFrameSet,type PaintPhase,type RenderEnv,type StickerImage,} from "@donkeycut/effects-kit";+import type { CSSProperties } from "react";import { createRasterCanvas, decodeRasterImage, rasterCanvasToPng } from "./raster";-import { fontStack, type MediaAsset, type Overlay } from "./types";+import { fontStack, type MediaAsset, type Overlay, type WordAccentMode } from "./types";// The shared text metrics and painters live in the effects kit; these// re-exports keep the app's preview components on the same constants.@@ -23,8 +26,51 @@ export {PLATE_RADIUS,plateFill,SHADOW,+ WORD_ACCENT_DEFAULT,+ WORD_ACCENT_LABELS,+ WORD_ACCENT_MODE_IDS,+ WORD_POP_SCALE,} from "@donkeycut/effects-kit";+/** The css one emphasized word wears — the DOM twin of what the canvas+ * painter draws for `highlightMode`. A swell is real type size, so the line+ * reflows around it: the words beside it move out of its way and settle back+ * as the emphasis travels on, which is what the burn-in lays out too. The+ * word keeps the line's own leading, so a bigger word never opens the line+ * box up. A box is box-shadow spread, which stays clear of the layout. */+export function wordAccentCss(look: {+ mode: WordAccentMode;+ color: string;+ text: string;+ /** How far the word swells; absent = the mode's default. */+ scale?: number;+ /** The block's line height, so the swollen word can hold it. */+ lineHeight?: number;+}): CSSProperties {+ const swell = wordSwell({ style: look.mode, scale: look.scale });+ const lh = look.lineHeight ?? LINE_HEIGHT;+ const size: CSSProperties =+ swell === 1 ? {} : { fontSize: `${swell}em`, lineHeight: lh / swell };+ const treatment: CSSProperties =+ look.mode === "box"+ ? {+ color: look.text,+ background: look.color,+ boxShadow: `0 0 0 0.12em ${look.color}`,+ borderRadius: "0.18em",+ textShadow: "none",+ }+ : look.mode === "color" || look.mode === "pop"+ ? { color: look.color }+ : {+ color: look.color,+ textDecoration: "underline",+ textDecorationThickness: "0.07em",+ textUnderlineOffset: "0.14em",+ };+ return { ...treatment, ...size };+}+/** Decoded sticker images by asset id, shared across one page's renders. An* <img> decode handles SVG too (createImageBitmap on an SVG blob does not). */const stickerCache = new Map<string, Promise<StickerImage | null>>();diff --git a/site/src/cut/lib/textWords.ts b/site/src/cut/lib/textWords.tsnew file mode 100644index 00000000..2370dfe3--- /dev/null+++ b/site/src/cut/lib/textWords.ts@@ -0,0 +1,63 @@+/**+ * When each word of a piece of on-screen text is actually said.+ *+ * The transcript is the cut's clock: it knows when every recognized word was+ * spoken. A title the user placed carries their exact wording, so the two are+ * aligned word for word — the text stays verbatim and only the times come+ * from the transcript, the same bargain a lyric sync makes. Nothing to align+ * against (no captions yet, a title over silence) hands back nothing, and the+ * emphasis falls back to an even share of the element's own span.+ */++import { displayWords } from "@donkeycut/effects-kit";+import { syncLines, type TimedWord } from "./lyricSync";+import type { SubtitleCue } from "./types";++/** The transcript an element is timed against: the first subtitle track. The+ * others are translations of it, and aligning English words to a Korean+ * translation would anchor nothing. */+const primaryCues = (cues: SubtitleCue[]): SubtitleCue[] => cues.filter((c) => (c.lane ?? 0) === 0);++/** Every transcript word the cut carries, in order. A cue with no word times+ * of its own contributes an even split of its line, so a hand-typed caption+ * still lends a usable clock. */+export function transcriptWords(+ cues: { start: number; end: number; text: string; words?: TimedWord[] }[]+): TimedWord[] {+ const out: TimedWord[] = [];+ for (const c of cues) {+ if (c.words && c.words.length > 0) {+ out.push(...c.words);+ continue;+ }+ const parts = c.text.split(/\s+/).filter((w) => w.length > 0);+ const step = parts.length > 0 ? (c.end - c.start) / parts.length : 0;+ parts.forEach((w, i) => out.push({ w, t0: c.start + step * i, t1: c.start + step * (i + 1) }));+ }+ return out;+}++/**+ * Word onsets for one text element, seconds from its own start — what the+ * word-emphasis slot follows. Undefined when the transcript says nothing+ * about this stretch of the cut.+ */+export function wordTimesFor(+ o: { text: string; start: number; end: number },+ cues: SubtitleCue[]+): number[] | undefined {+ const count = displayWords(o.text).length;+ if (count === 0) return undefined;+ const heard = transcriptWords(primaryCues(cues)).filter((w) => w.t1 > o.start && w.t0 < o.end);+ if (heard.length === 0) return undefined;+ const line = syncLines([o.text], heard, { from: o.start, to: o.end })[0];+ if (!line?.words || line.words.length !== count) return undefined;+ const dur = Math.max(0, o.end - o.start);+ const times: number[] = [];+ let floor = 0;+ for (const w of line.words) {+ floor = Math.min(Math.max(w.t0 - o.start, floor), dur);+ times.push(Math.round(floor * 1000) / 1000);+ }+ return times;+}diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex 2058541d..fa2543bc 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -12,6 +12,8 @@import { AI_PANEL_TOOLS } from "@/cut/components/AiPanel.tools";import { TEXT_LAYOUT_IDS, TEXT_LAYOUT_NOTES } from "@/cut/lib/textCompose";import { textLookCatalog } from "@/cut/lib/textLooks";+import { CAPTION_STYLES, WORD_ACCENT_MODES } from "@/cut/lib/subtitles";+import { WORD_ACCENT_MODE_IDS } from "@donkeycut/effects-kit";import { textMoveCatalog } from "@/cut/lib/textMotion";import { OVERLAY_ANIMATION_TOOLS } from "@/cut/components/AnimationTiles.tools";import { AUDIO_TOOLS } from "@/cut/components/AudioPanel.tools";@@ -174,7 +176,7 @@ Stickers (add_sticker): a project image asset (generated cutouts in the ElementsCustom stickers (create_sticker): one call generates the image, removes the background, adds the die-cut outline, and places it — use it when the user asks for a sticker of something they don't have (it spends credits like image generation).Effects (add_effect): time-ranged treatments over the finished cut. Three families, one list: the picture treatments (${EFFECT_TREATMENTS.join(", ")}), the graded looks (${LOOK_EFFECTS.join(", ")}), and the audio treatments (${AUDIO_EFFECT_IDS.join(", ")}). A picture effect treats the footage and everything laid over it; an audio effect treats everything audible under its window at once — clip sound, upper-track sound and the soundtrack — so "make this bit sound like a phone call", "put an echo on that line", or "muffle the music here" is an effect element over that stretch, and a per-clip volume, fade or duck is the audio tools instead. A handover on the sound at a cut belongs to the transition on that cut — the audiocross style — not here. Placed like any element and tuned with \`amount\` (update_overlay), and trims like anything else: a picture effect dropped over a clip opens covering that clip, while an audio effect opens at the standard length wherever it was placed — a treatment on the sound is aimed at a moment, so give it the window you mean. One effect at a time reads best, amounts under ~0.5. Effects are stylized post treatments on a stretch of timeline; pure color — exposure, warmth, a cinematic or film palette on one clip — is the per-clip grading tools instead (color-grading skill), whose preset catalog is separate from the look effects.Advanced text (update_overlay): italic, align (multi-line), letter_spacing (em), line_height, stretch_x/stretch_y (glyph stretch multipliers, the side grips' axis-only resize), stroke_color/stroke_width (em outline behind the fill), and richer shadows. Bundled Google families join the system set — ${GOOGLE_FONT_IDS.join(", ")} — and so do the user's own: a .ttf/.otf/.woff/.woff2 file dropped on the Library is offered in every project under a font id like "font:<id>". Editor_state lists the ones this account has under \`fonts\` — use an id from there instead of guessing at a family name, and when someone asks for a typeface that is not in the list, tell them the Library takes font files.-Animation (set_overlay_animation): every element takes preset In/Out ramps (${OVERLAY_ANIM_STYLE_IDS.join(", ")} — typewriter for titles only; the per-letter styles sweep a title character by character), a Loop (${OVERLAY_LOOP_STYLE_IDS.join(", ")}) that runs its whole duration, and a Move that says what it does WHILE it holds. Entrances 0.3–0.6s read well; one loop per scene, sparingly; a move on the lines that matter. All four are slots on the element, applied internally; the keyframe track (set_overlay_keyframes) is the separate power tier for motion the names do not cover, and slots compose over it.+Animation (set_overlay_animation): every element takes preset In/Out ramps (${OVERLAY_ANIM_STYLE_IDS.join(", ")} — typewriter for titles only; the per-letter styles sweep a title character by character), a Loop (${OVERLAY_LOOP_STYLE_IDS.join(", ")}) that runs its whole duration, and a Move that says what it does WHILE it holds. A title takes one more: Words (${WORD_ACCENT_MODE_IDS.join(", ")}), which holds the whole line on screen and lights each word as it is said. Entrances 0.3–0.6s read well; one loop per scene, sparingly; a move on the lines that matter. All of them are slots on the element, applied internally; the keyframe track (set_overlay_keyframes) is the separate power tier for motion the names do not cover, and slots compose over it.Keyframes (set_overlay_keyframes): for motion no preset covers — a path across the frame, a slow push in, a drift that holds first. A key is a whole pose (position, scale, rotation, opacity) at a time in seconds from the element's start; the pose moves linearly between keys and holds outside them, and presets still compose on top. Two or three keys carry almost everything; reach for a preset first and keyframes when the user describes a specific path or timing. In the UI the diamond in the inspector adds a key at the playhead, and dragging the element then records into it. set_clip_keyframes is the same track on a video clip (any track): pans, push-ins, picture-in-picture flights, spins, and fades on the footage itself.Masks (set_mask): trim any element or video clip to a shape — rect, square, circle, linear, mirror — with feather, invert, and its own keyframe track for reveals and wipes. The subject kind trims by the person in the shot (on-device segmentation; preview and export match): inverted sits the item behind the speaker, plain keeps it only on the speaker. Behind-speaker reads well when the speaker is clearly separated from the background; with no detectable person it degrades to the plain picture. Groups: the user can group elements (select several, Group in the inspector) — selecting one selects all, and moves/resize/rotate/timing ride together.Composite builds: these primitives compose. Stacked overlay video copies, masks and their keys, pose keyframes, staggered starts, and shapes construct effects beyond any preset list. Given a reference (a screenshot or clip of an effect the user wants), reverse-engineer it:@@ -193,7 +195,7 @@ A video whose picture is words. Three pieces: the frame behind them (set_backgro**Design is something the user asks for.** "Add the text", "put what he says on screen", "add text from the audio" is a plain job: get the words and their times — the cues already in editor_state, a source's transcript, listen_audio, or subtitles_generate when the user wants a caption track — then place them with add_text_sequence and no \`look\`. That lays one readable face at one spot with a short fade, no cards, no moves, no tilts, and no repaint of the frame. Then align_to_audio: the times you placed came from a transcript, and that pass measures them against the mix's own waveform and moves each edge onto the speech. Reach for a look, cards, moves, or a variation only when the ask carries a design in it: a lyric video, kinetic type, a named style or vibe, "make it fun", a reference to match. A cut that comes back restyled when the user asked for words on screen is the failure this default exists to prevent.-**Two ways to carry the words.** A caption track is one styled row of text that follows a voice — it holds word timings, so karaoke (each word lighting as it is sung) is only possible here, and one call restyles every line. Elements are separate titles and cards on the timeline — per-line face, per-line placement, per-glyph motion, a color card behind each line — which is what kinetic typography and lyric cards are made of. Captions for a song you want to sing along to; elements when each line is its own picture. Both burn into the export.+**Two ways to carry the words.** A caption track is one styled row of text that follows a voice — it holds word timings, and one call restyles every line. Elements are separate titles and cards on the timeline — per-line face, per-line placement, per-glyph motion, a color card behind each line — which is what kinetic typography and lyric cards are made of. Captions for a song you want to sing along to; elements when each line is its own picture. Both burn into the export, and both light each word as it is said: word_highlight on the caption track, the words slot of set_overlay_animation on a title.**The looks.** A look is opt-in, and it is not one line's styling — it is the design of a whole run. It sets the frame color, the cards it cycles, the type, the entrance, the caption equivalent, AND the ensemble the run walks across its length: the faces it rotates through, the entrances, where successive lines land, and what each line does while it holds. So one add_text_sequence call already produces a composed, varied run:${textLookCatalog()}@@ -210,7 +212,7 @@ Never lay a run at variation "none" and then repair it with a hundred update_ove**A lyric video, from an audio track and the words.** The user has the song and the lyrics.1. The song is in the cut (a soundtrack clip). \`get_state\` confirms it and gives the duration.2. sync_lyrics with the lyrics text, one line per screen. It transcribes the cut, aligns the user's words to what it recognized, and writes the user's text — verbatim — onto a caption track with per-word times. Singing defeats recognizers; that is why the wording comes from the user and only the clock comes from the transcript.-3. Dress it: set_caption_look with a look id (karaoke-glow for words lighting up, neon-club, serif-mood…), or add_text_sequence from_captions to turn the same timed lines into full-frame cards. Going the element route, re-send the lines yourself with emphasis and section on them rather than from_captions — from_captions carries the timing but knows nothing about which line is the hook.+3. Dress it: set_caption_look with a look id (karaoke-glow for words lighting up, neon-club, serif-mood…), or accent_mode on its own to pick how the sung word is emphasized — pop swells it, box puts a card behind it, or add_text_sequence from_captions to turn the same timed lines into full-frame cards. Going the element route, re-send the lines yourself with emphasis and section on them rather than from_captions — from_captions carries the timing but knows nothing about which line is the hook.4. Check it: sync_lyrics already snaps its lines to the mix, and align_to_audio re-runs that pass any time (on the caption track, or on the elements of a run with target elements). Then seek + capture_frame at three or four lines that landed on DIFFERENT rota steps, and listen_audio across one of them. A single line still sitting early or late retimes with update_cue.With no lyrics text, transcribe with subtitles_generate and work from the cues it wrote.@@ -311,7 +313,7 @@ Generating: subtitles_generate transcribes the cut's audio on-device (Apple speecaptions_generate rewrites a track's cues into punchy social captions (emoji, curiosity-hook opener) in a style (clean/hook/punchy), keeping timings — use it when the ask is social/TikTok captions rather than a plain transcript.Editing: update_cue (text or retime), delete_cue, merge_cue (joins into the previous cue on the same track). In the panel, Return splits a caption at the cursor onto real word timings; hand-edited text drops its word timings.subtitles_set_view: showOnVideo (preview + export burn-in), showOnTimeline (amber cue rows).-Caption look: the Subtitles panel offers 10 visual presets (clean, hook, punchy, minimal, editorial, typewriter, block, highlight, bubble, neon), a per-word karaoke highlight with accent overrides, and each track's caption drags to a new spot in the preview. No tool sets the look — direct the user to the panel. captions_generate's clean/hook/punchy choice shapes the caption text it writes; the visual preset is separate.`,+Caption look: set_caption_look carries the whole look — the visual presets (${Object.keys(CAPTION_STYLES).join(", ")}), size, font, and the karaoke emphasis with its accent overrides; the Subtitles panel offers the same, and each track's caption drags to a new spot in the preview. The emphasis keeps the whole line readable and lights the word being said: ${WORD_ACCENT_MODES.map((m) => `${m.id} (${m.hint})`).join(", ")}. captions_generate's clean/hook/punchy choice shapes the caption text it writes; the visual preset is separate.`,"ai-generation": `# Stock media & AI generationThree ways to get footage the user doesn't have: bundled stock (local, free), a URL they point at (import_url downloads TikTok / YouTube / Instagram / direct links, free), and hosted generation (signed in, spends credits). Prefer stock when it genuinely fits; generate when the shot needs to be specific.