Skip to content

Open source CapCut alternative.

TypeScript

feat(site): a text run composes itself across its whole length [rebuild]

David Lee55ea117c0ca
diff --git a/docs/guides/cut/README.md b/docs/guides/cut/README.md
index ca3e7b62..da5f2246 100644
--- a/docs/guides/cut/README.md
+++ b/docs/guides/cut/README.md
@@ -30,7 +30,7 @@ The client probes the engine's health endpoint (dedicated port first, dev server
**A cut needs no footage.** The frame starts as a color the project owns, and everything else — clips, titles, shapes, stickers — draws over it. So a video made entirely of text and graphics is an ordinary project: it plays, exports, shares, and renders on the worker like any other, and the same color letterboxes a fitted clip and fills a gap on track 0. Elements stack by row: two on one row slide clear of each other in time, so a title that sits over a card lives a row above it.
-**Words as the picture.** A lyric video, a kinetic-typography passage, a quote sequence: the assistant places a whole run of lines in one call, carrying a named look that decides the frame color, the card colors it cycles line to line, the type, and how each line arrives. The looks live in one registry the tools and the skill both read, so adding a look teaches the assistant a new style with no other change. Words ride one of two carriers — a caption track, which holds per-word timings and can light each word as it is sung, or elements, which give each line its own card, color and motion. Text the user already has (lyrics, a script) is timed by aligning it to a transcript of the audio: the recognizer supplies the clock and the user's wording is kept exactly, which is what makes it survive singing.
+**Words as the picture.** A lyric video, a kinetic-typography passage, a quote sequence: the assistant places a whole run of lines in one call, carrying a named look. A look is the design of the whole run rather than of one line — the frame color, the cards it cycles, and the ensemble the run walks across its length: the faces it rotates through, the entrances, where successive lines land in the frame, and what each line does while it holds. That is what stops a hundred lines coming out identical and dead center, which is the failure a text video actually has. The looks live in one registry the tools and the skills both read, so adding a look teaches the assistant a new style with no other change. Words ride one of two carriers — a caption track, which holds per-word timings and can light each word as it is sung, or elements, which give each line its own card, color and motion. Text the user already has (lyrics, a script) is timed by aligning it to a transcript of the audio: the recognizer supplies the clock and the user's wording is kept exactly, which is what makes it survive singing.
**Motion is data.** Every animation in the editor — an entrance, an exit, a loop, and the moves an element makes while it holds — is one format: a pose keyframed over a normalized window with cubic-bezier easing, plus a range selector that says how the motion is handed from one character to the next. That is the After Effects text-animator model, the one Lottie serializes, and picking it means a preset and a hand-keyed track are the same object at two levels of convenience: a named move writes the ordinary pose track the user can then drag, and anything no name covers is keyed directly. The library is a JSON asset in the effects kit rather than code, and the menus, tool enums, prompts, and the frame sampler's crop budget are all read from it, so adding an animation is adding an entry. One evaluator samples it, which is what keeps the preview, the export, and the headless worker showing the same motion. A slot may also carry a preset of its own rather than naming one from the library, in the same shape a library entry has — the evaluator cannot tell the two apart, so an animation composed inside a project plays wherever a shipped one does.
diff --git a/site/src/cut/components/Timeline.tools.ts b/site/src/cut/components/Timeline.tools.ts
index a1326cf1..76189a2c 100644
--- a/site/src/cut/components/Timeline.tools.ts
+++ b/site/src/cut/components/Timeline.tools.ts
@@ -7,6 +7,14 @@
*/
import { bool, num, obj, str, type AiToolDef } from "@/cut/lib/aiToolDef";
+import {
+ TEXT_EMPHASIS_IDS,
+ TEXT_LAYOUT_IDS,
+ TEXT_LAYOUT_NOTES,
+ TEXT_VARIATION_IDS,
+} from "@/cut/lib/textCompose";
+import { TEXT_MOVE_IDS, TEXT_MOVE_NOTES } from "@/cut/lib/textMotion";
+import { OVERLAY_ANIM_STYLE_IDS } from "@donkeycut/effects-kit";
export const TIMELINE_TOOLS = [
{
@@ -194,9 +202,20 @@ export const TIMELINE_TOOLS = [
{
name: "add_text_sequence",
description:
- "Place a run of text on the timeline in one call — a lyric video, a kinetic-typography passage, a quote sequence — styled by a named look. `look` carries the whole design: the frame color, the card colors it cycles line to line, the type, and how each line arrives (ids and what each is for are in the text-videos skill). Lines come from `lines` ({text, start, end} in timeline seconds, plus an optional color/size override per line), or from the caption track with from_captions when a sync already timed them. The words land on `lane` and each card on the row under them, so they stack instead of sliding apart. It sets the project background to the look's frame color unless background is false — words over the user's own footage want a look with no cards, and the footage keeps playing underneath.",
+ "Place a run of text on the timeline in one call — a lyric video, a kinetic-typography passage, a quote sequence — composed by a named look. `look` carries the design of one line (frame color, cards, type, entrance) AND the ensemble the run walks across its whole length: where successive lines land, which faces they rotate through, which entrances, and what each line does while it holds. So one call already produces a varied, composed run; it never lays a hundred identical lines at dead center. Lines come from `lines` ({text, start, end} in timeline seconds), or from the caption track with from_captions when a sync already timed them. Mark the loud lines with `emphasis: \"hero\"` and the quiet ones `\"whisper\"`, and label passages with `section` (\"verse\", \"chorus\") — a new section restarts the type and color rotas, so a chorus does not look like the verse before it. Anything you set per line (font, x/y, rotation, in_style, move, color, size) wins over the ensemble. The words land on `lane` and each card on the row under them. It sets the project background to the look's frame color unless background is false. Look ids, layouts and moves are in the text-videos and text-creativity skills.",
inputSchema: obj({
look: str("Look id from the text-videos skill (default lyric-card)"),
+ variation: {
+ type: "string",
+ enum: [...TEXT_VARIATION_IDS],
+ description:
+ "How far the run departs from one repeated design. bold (default) walks the look's whole ensemble — faces, tilts, palette, keyframe moves; subtle keeps one typeface and varies placement and entrance; none lays every line identical, for a run you intend to hand-compose.",
+ },
+ layout: {
+ type: "string",
+ enum: [...TEXT_LAYOUT_IDS],
+ description: `Where successive lines land, overriding the look's own. ${TEXT_LAYOUT_IDS.map((id) => `${id}: ${TEXT_LAYOUT_NOTES[id]}`).join(" ")}`,
+ },
lines: {
type: "array",
description: "The run, in order. Omit times on a line and it follows the one before it.",
@@ -205,8 +224,29 @@ export const TIMELINE_TOOLS = [
text: str("The line (\\n for a break inside it)"),
start: num("Timeline start s"),
end: num("Timeline end s"),
- color: str("Override the look's text color for this line — for an accent word or a section change"),
- size: num("Override the look's size for this line"),
+ emphasis: {
+ type: "string",
+ enum: [...TEXT_EMPHASIS_IDS],
+ description:
+ "How loud this line is: hero is markedly bigger and takes the look's hero move, whisper is small and quiet. Default normal.",
+ },
+ section: str('Passage label ("verse", "chorus", "bridge") — a new label restarts the type and color rotas'),
+ color: str("Override the run's color for this line"),
+ size: num("Override the composed size for this line"),
+ font: str("Override the face carrying this line"),
+ x: num("Frame-width fraction 0..1, overriding the layout"),
+ y: num("Frame-height fraction 0..1, overriding the layout"),
+ rotation: num("Tilt in degrees, -45..45"),
+ in_style: {
+ type: "string",
+ enum: [...OVERLAY_ANIM_STYLE_IDS],
+ description: "Entrance for this line, overriding the rota",
+ },
+ move: {
+ type: "string",
+ enum: [...TEXT_MOVE_IDS],
+ description: `What this line does WHILE it holds (a keyframe move; the entrance is separate). ${TEXT_MOVE_IDS.filter((m) => m !== "none").map((m) => `${m}: ${TEXT_MOVE_NOTES[m]}`).join(" ")}`,
+ },
},
["text"]
),
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index 0bf93610..d5605baa 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -82,7 +82,21 @@ import { CAPTION_STYLES, laneCues, subtitleLaneCount } from "./subtitles";
import { fuseTimeline, renderFusedTimeline } from "./watch/fuse";
import { mergeWatch, mergeWatchNotes, uncoveredSeconds, unnotedSpans } from "./watch/merge";
import { syncLines, type TimedWord } from "./lyricSync";
+import {
+ composeTextRun,
+ TEXT_LAYOUT_IDS,
+ type ComposeLine,
+ type TextLayout,
+ type TextVariation,
+} from "./textCompose";
import { requireTextLook } from "./textLooks";
+import {
+ MOVE_STRENGTH_MAX,
+ MOVE_STRENGTH_MIN,
+ TEXT_MOVE_IDS,
+ textMoveKeys,
+ type TextMoveId,
+} from "./textMotion";
import { queueWatchSweep, withSweepPaused } from "./watch/sweep";
import { synthesizeMusic } from "./audioGen";
import { composeMusicPrompt } from "./composeGen";
@@ -95,6 +109,7 @@ import {
ANIM_DEFAULT_SECONDS,
ANIM_STYLE_IDS,
DEFAULT_BACKGROUND,
+ clampOverlayPos,
frameOf,
IMAGE_CLIP_SECONDS,
isEffectOverlay,
@@ -347,6 +362,29 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
};
edge("in", "in_style", "in_seconds");
edge("out", "out_style", "out_seconds");
+ // A move is not a fourth slot on the element: it writes the pose track
+ // the inspector's diamond writes, so the user can drag the keys after.
+ if (typeof input.move === "string") {
+ if (input.move === "none") s.updateOverlay(o.id, { kf: [] });
+ else {
+ if (!TEXT_MOVE_IDS.includes(input.move))
+ throw new ToolError(`Unknown move: ${input.move}. Use one of: ${TEXT_MOVE_IDS.join(", ")}.`);
+ const strength = isNum(input.move_strength)
+ ? clamp(input.move_strength, MOVE_STRENGTH_MIN, MOVE_STRENGTH_MAX)
+ : 1;
+ const keys = textMoveKeys(
+ input.move,
+ { x: o.x, y: o.y, rotation: o.rotation ?? 0 },
+ o.end - o.start,
+ strength
+ );
+ if (!keys)
+ throw new ToolError(
+ `This element is too short for a move to read (${round2(o.end - o.start)}s).`
+ );
+ s.updateOverlay(o.id, { kf: keys });
+ }
+ }
const rawLoop = input.loop_style;
const speed = isNum(input.loop_speed) ? clamp(input.loop_speed, 0.25, 4) : undefined;
if (typeof rawLoop === "string") {
@@ -1335,13 +1373,26 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
throw new ToolError(
"Pass lines: [{text, start, end}], or from_captions: true to build the sequence from the caption track."
);
+ const variation: TextVariation =
+ input.variation === "none" || input.variation === "subtle" || input.variation === "bold"
+ ? input.variation
+ : "bold";
+ if (typeof input.layout === "string" && !TEXT_LAYOUT_IDS.includes(input.layout as TextLayout))
+ throw new ToolError(`Unknown layout. Use one of: ${TEXT_LAYOUT_IDS.join(", ")}.`);
+ const layout = typeof input.layout === "string" ? (input.layout as TextLayout) : undefined;
if (input.background !== false) s.setBackground(look.frame.background);
// Row 0 is the front of the element stack, so the words take the row the
// caller named and each card goes one row under them. Cards over words
// would paint the line out.
const cardLane = lane + 1;
+ const composed = composeTextRun(lines, look, {
+ variation,
+ layout,
+ frame: frameOf(s.aspect),
+ cards,
+ });
const made: { id: string; start: number; end: number; text: string }[] = [];
- lines.forEach((line, i) => {
+ composed.forEach((line, i) => {
const card = cards.length > 0 ? cards[i % cards.length] : null;
if (card) {
useEditor.getState().seek(line.start);
@@ -1362,20 +1413,18 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
useEditor.getState().addOverlay({ lane });
const sel = useEditor.getState().selection;
if (sel?.kind !== "overlay") return;
- const onCard =
- card && look.text.onCards ? look.text.onCards[i % look.text.onCards.length] : undefined;
- const fit = fitTextToFrame(line.text, look, frameOf(s.aspect), line.size ?? look.text.size);
applyOverlayPatchSettled(sel.id, {
start: line.start,
end: line.end,
- text: fit.text,
- x: look.text.x,
- y: look.text.y,
- size: fit.size,
- font: look.text.font,
- weight: look.text.weight,
- color: line.color ?? onCard ?? look.text.color,
- italic: look.text.italic,
+ text: line.text,
+ x: line.x,
+ y: line.y,
+ rotation: line.rotation,
+ size: line.size,
+ font: line.font,
+ weight: line.weight,
+ color: line.color,
+ italic: line.italic || look.text.italic,
letterSpacing: look.text.letterSpacing,
lineHeight: look.text.lineHeight,
stroke: look.text.stroke,
@@ -1385,29 +1434,29 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
shadow: look.text.shadow ?? false,
align: "center",
});
- if (look.motion.in || look.motion.out || look.motion.loop)
- useEditor.getState().updateOverlay(sel.id, {
- anim: {
- ...(look.motion.in ? { in: look.motion.in } : {}),
- ...(look.motion.out ? { out: look.motion.out } : {}),
- ...(look.motion.loop
- ? { loop: { style: look.motion.loop.style, speed: look.motion.loop.speed ?? 1 } }
- : {}),
- },
- });
+ useEditor.getState().updateOverlay(sel.id, {
+ anim: line.anim,
+ ...(line.kf ? { kf: line.kf } : {}),
+ });
const o = useEditor.getState().overlays.find((x) => x.id === sel.id);
if (o) made.push({ id: o.id, start: round2(o.start), end: round2(o.end), text: line.text });
});
+ const faces = [...new Set(composed.map((l) => l.font))];
+ const moves = [...new Set(composed.map((l) => l.move))].filter((m) => m !== "none");
return {
look: look.id,
+ variation,
+ layout: layout ?? (variation === "none" ? "center" : look.ensemble.layout),
count: made.length,
lanes: cards.length > 0 ? { cards: cardLane, text: lane } : { text: lane },
background: useEditor.getState().background,
+ faces,
+ moves,
items: made.slice(0, 40),
...(made.length > 40 ? { itemsTruncated: true } : {}),
note:
cards.length > 0
- ? `Words on row ${lane} with their cards on row ${cardLane} behind them, colors cycling ${look.frame.cards.join(" → ")}.`
+ ? `Words on row ${lane} with their cards on row ${cardLane} behind them, colors cycling ${look.frame.cards.join(" \u2192 ")}.`
: `Words on row ${lane} over the ${look.frame.background} frame.`,
};
},
@@ -2854,55 +2903,12 @@ function cueWords(cues: { start: number; end: number; text: string; words?: Time
return out;
}
-/** A line broken and sized to the frame it is going into. The look's size is
- * a ceiling written for a wide frame; a vertical cut, or a long line, gets
- * breaks at word boundaries first and a smaller size only when breaking is
- * not enough. Type the user hand-sized (a per-line `size`) is left alone
- * apart from the breaks. */
-function fitTextToFrame(
- text: string,
- look: { text: { size: number; widthRatio?: number; lineHeight?: number } },
- frame: { w: number; h: number },
- size: number
-): { text: string; size: number } {
- if (text.includes("\n")) return { text, size }; // the caller broke it themselves
- const ratio = look.text.widthRatio ?? 0.55;
- const usable = frame.w * 0.86;
- const words = text.split(/\s+/).filter((w) => w.length > 0);
- if (words.length === 0) return { text, size };
- const maxLines = 3;
- // The widest a line may run, in characters, at this size.
- const budget = Math.max(6, Math.floor(usable / (size * ratio)));
- const lines: string[] = [];
- let cur = "";
- for (const w of words) {
- const next = cur ? `${cur} ${w}` : w;
- if (next.length <= budget || cur === "") cur = next;
- else {
- lines.push(cur);
- cur = w;
- }
- }
- if (cur) lines.push(cur);
- const longest = lines.reduce((n, l) => Math.max(n, l.length), 0);
- // Still over the frame (one long word, or more rows than the look wants):
- // shrink until it sits inside.
- let fitted = size;
- if (longest > budget) fitted = Math.min(fitted, Math.floor(usable / (longest * ratio)));
- if (lines.length > maxLines) fitted = Math.min(fitted, Math.floor(size * (maxLines / lines.length)));
- const rows = lines.length;
- const lineH = look.text.lineHeight ?? 1.25;
- const tall = rows * fitted * lineH;
- if (tall > frame.h * 0.8) fitted = Math.floor((frame.h * 0.8) / (rows * lineH));
- return { text: lines.join("\n"), size: Math.max(16, Math.min(size, fitted)) };
-}
-
/** The lines a text sequence should place: the ones passed in, or the caption
* track read as a running order. */
function textSequenceLines(
s: ReturnType<typeof useEditor.getState>,
input: Record<string, unknown>
-): { text: string; start: number; end: number; color?: string; size?: number }[] {
+): ComposeLine[] {
if (input.from_captions === true || isNum(input.from_captions)) {
const lane = isNum(input.from_captions) ? Math.max(0, Math.round(input.from_captions)) : 0;
return laneCues(s.subtitles, lane).map((c) => ({
@@ -2920,6 +2926,18 @@ function textSequenceLines(
end: isNum(l.end) ? l.end : NaN,
...(typeof l.color === "string" ? { color: l.color } : {}),
...(isNum(l.size) ? { size: clamp(Math.round(l.size), 16, 320) } : {}),
+ ...(l.emphasis === "whisper" || l.emphasis === "hero" || l.emphasis === "normal"
+ ? { emphasis: l.emphasis }
+ : {}),
+ ...(typeof l.section === "string" && l.section ? { section: l.section } : {}),
+ ...(typeof l.font === "string" ? { font: l.font } : {}),
+ ...(isNum(l.x) ? { x: clampOverlayPos(l.x) } : {}),
+ ...(isNum(l.y) ? { y: clampOverlayPos(l.y) } : {}),
+ ...(isNum(l.rotation) ? { rotation: clamp(l.rotation, -45, 45) } : {}),
+ ...(typeof l.in_style === "string" ? { inStyle: l.in_style as OverlayAnimStyle } : {}),
+ ...(typeof l.move === "string" && TEXT_MOVE_IDS.includes(l.move as TextMoveId)
+ ? { move: l.move as TextMoveId }
+ : {}),
}))
.filter((l) => l.text.length > 0);
// A line with no times follows the one before it; the first starts at the
@@ -2934,7 +2952,7 @@ function textSequenceLines(
// decided — a following line that starts earlier cannot invert it.
const end = Math.max(Number.isNaN(l.end) ? fallbackEnd : l.end, start + 0.2);
cursor = end;
- return { ...l, start: round2(start), end: round2(end) };
+ return { ...l, start: round2(start), end: round2(end) } as ComposeLine;
});
}
diff --git a/site/src/cut/lib/textCompose.ts b/site/src/cut/lib/textCompose.ts
new file mode 100644
index 00000000..e0d046b7
--- /dev/null
+++ b/site/src/cut/lib/textCompose.ts
@@ -0,0 +1,404 @@
+import type { OverlayAnim, OverlayAnimStyle, OverlayKey } from "@donkeycut/effects-kit";
+import type { TextLook } from "./textLooks";
+import { type TextMoveId, textMoveKeys } from "./textMotion";
+import type { FontId } from "./types";
+
+/**
+ * How a run of text is composed across the frame and across its own length.
+ *
+ * A look says what one line looks like. This says what a hundred of them look
+ * like together: where each lands, which face carries it, how it arrives, and
+ * which lines are the loud ones. Without it every line of a lyric video comes
+ * out identical and dead center, and the only way to vary anything is to edit
+ * each element afterwards one call at a time.
+ *
+ * Everything here is deterministic — index in, pose out — so the same run
+ * composes the same way twice, and index 0 always reproduces the look's own
+ * settings exactly.
+ */
+
+/** How loud a line is. The model decides this per line from the meaning of
+ * the words; nothing here reads the text to guess. */
+export type TextEmphasis = "whisper" | "normal" | "hero";
+
+/** How far the run departs from a single repeated design.
+ * - `none`: every line identical — the look, nothing else.
+ * - `subtle`: lines move around the frame and change entrance; one typeface.
+ * - `bold`: the look's whole ensemble — faces, tilts, palette, hero accents. */
+export type TextVariation = "none" | "subtle" | "bold";
+
+/** Where successive lines land relative to the look's own anchor. */
+export type TextLayout =
+ | "center"
+ | "stack"
+ | "alternate"
+ | "corners"
+ | "drift"
+ | "scatter"
+ | "ladder";
+
+export const TEXT_LAYOUT_IDS: TextLayout[] = [
+ "center",
+ "stack",
+ "alternate",
+ "corners",
+ "drift",
+ "scatter",
+ "ladder",
+];
+
+export const TEXT_VARIATION_IDS: TextVariation[] = ["none", "subtle", "bold"];
+export const TEXT_EMPHASIS_IDS: TextEmphasis[] = ["whisper", "normal", "hero"];
+
+/** One-line descriptions, so the tool schema and the skill teach the same
+ * thing the composer does. */
+export const TEXT_LAYOUT_NOTES: Record<TextLayout, string> = {
+ center: "Every line on the look's anchor. Still, formal, karaoke.",
+ stack: "Lines step up and down the middle column, so a phrase builds vertically.",
+ alternate: "Lines swing left and right of center — call and response.",
+ corners: "Lines walk the four corners of the safe area. Busy, poster-like.",
+ drift: "A slow diagonal walk across the frame and back. Ballads, long holds.",
+ scatter: "A fixed scatter around the frame that never lands twice in a row. Chaotic energy.",
+ ladder: "Each line one rung lower than the last, then back to the top. Lists, countdowns, verses.",
+};
+
+/** The offsets a layout walks, in frame fractions from the look's anchor.
+ * Entry 0 is always zero: a single line, and the first line of any run, sits
+ * exactly where the look put it. */
+const LAYOUT_STEPS: Record<TextLayout, { dx: number; dy: number }[]> = {
+ center: [{ dx: 0, dy: 0 }],
+ stack: [
+ { dx: 0, dy: 0 },
+ { dx: 0, dy: -0.19 },
+ { dx: 0, dy: 0.19 },
+ { dx: 0, dy: -0.1 },
+ { dx: 0, dy: 0.1 },
+ ],
+ alternate: [
+ { dx: 0, dy: 0 },
+ { dx: -0.17, dy: -0.12 },
+ { dx: 0.17, dy: 0.12 },
+ { dx: -0.15, dy: 0.1 },
+ { dx: 0.15, dy: -0.1 },
+ ],
+ corners: [
+ { dx: 0, dy: 0 },
+ { dx: -0.21, dy: -0.17 },
+ { dx: 0.21, dy: -0.17 },
+ { dx: 0.21, dy: 0.17 },
+ { dx: -0.21, dy: 0.17 },
+ ],
+ drift: [
+ { dx: 0, dy: 0 },
+ { dx: 0.07, dy: 0.07 },
+ { dx: 0.14, dy: 0.14 },
+ { dx: 0.07, dy: 0.2 },
+ { dx: -0.07, dy: 0.14 },
+ { dx: -0.14, dy: 0.05 },
+ { dx: -0.08, dy: -0.06 },
+ ],
+ scatter: [
+ { dx: 0, dy: 0 },
+ { dx: 0.2, dy: -0.15 },
+ { dx: -0.18, dy: 0.14 },
+ { dx: 0.13, dy: 0.19 },
+ { dx: -0.21, dy: -0.12 },
+ { dx: 0.05, dy: -0.2 },
+ { dx: -0.09, dy: 0.21 },
+ { dx: 0.22, dy: 0.04 },
+ ],
+ ladder: [
+ { dx: 0, dy: 0 },
+ { dx: 0.05, dy: 0.11 },
+ { dx: 0.1, dy: 0.22 },
+ { dx: -0.05, dy: -0.11 },
+ { dx: -0.1, dy: -0.22 },
+ ],
+};
+
+/** Tilts a bold run walks. Entry 0 is upright, so the first line never leans. */
+const TILTS = [0, -6, 5, -4, 7, -3, 6, -7, 4, -5];
+
+/** How much bigger or smaller than the look's size each emphasis runs. */
+const EMPHASIS_SCALE: Record<TextEmphasis, number> = {
+ whisper: 0.68,
+ normal: 1,
+ hero: 1.34,
+};
+
+/** Average glyph width as a fraction of the type size, per face. A run that
+ * changes typeface has to re-break every line against the face carrying it —
+ * the same string in Bebas and Archivo Black are nowhere near the same width. */
+export const FACE_WIDTH_RATIO: Record<string, number> = {
+ sf: 0.52,
+ serif: 0.5,
+ rounded: 0.55,
+ mono: 0.6,
+ impact: 0.46,
+ inter: 0.53,
+ montserrat: 0.56,
+ poppins: 0.58,
+ oswald: 0.45,
+ "space-grotesk": 0.55,
+ playfair: 0.5,
+ caveat: 0.42,
+ bebas: 0.42,
+ anton: 0.44,
+ "archivo-black": 0.62,
+ bangers: 0.48,
+ lobster: 0.46,
+ pacifico: 0.52,
+ "permanent-marker": 0.5,
+ "dm-serif": 0.5,
+};
+
+export const faceWidth = (font: string): number => FACE_WIDTH_RATIO[font] ?? 0.55;
+
+/** One face in a look's ensemble. */
+export interface TextFace {
+ font: FontId;
+ weight: 400 | 700;
+ /** Size multiplier against the look's own size — a condensed face carries a
+ * bigger number than a wide one at the same optical weight. */
+ scale?: number;
+ italic?: boolean;
+}
+
+/** The rotas a look walks when a run asks for variation. Entry 0 of every
+ * rota is the look's own setting, so a one-line run and the first line of a
+ * long one are exactly what the look describes. */
+export interface TextEnsemble {
+ faces: TextFace[];
+ /** Entrances, walked one per line. */
+ motion: OverlayAnimStyle[];
+ layout: TextLayout;
+ /** Keyframe moves the run walks while each line HOLDS — see textMotion.ts.
+ * Entrances say how a line arrives; these say what it does after. */
+ moves: TextMoveId[];
+ /** The move a hero line takes regardless of where the rota is. */
+ heroMove?: TextMoveId;
+ /** Line colors for a run with no cards behind it. */
+ palette?: string[];
+}
+
+export interface ComposeLine {
+ text: string;
+ start: number;
+ end: number;
+ color?: string;
+ size?: number;
+ emphasis?: TextEmphasis;
+ /** Verse, chorus, bridge — any label. Lines sharing a label compose as one
+ * passage, and each new label starts the type and palette rotas somewhere
+ * else, so a chorus does not look like the verse before it. */
+ section?: string;
+ font?: FontId;
+ x?: number;
+ y?: number;
+ rotation?: number;
+ inStyle?: OverlayAnimStyle;
+ /** A named keyframe move for this line, overriding the look's rota. */
+ move?: TextMoveId;
+}
+
+export interface ComposedLine {
+ text: string;
+ start: number;
+ end: number;
+ x: number;
+ y: number;
+ rotation: number;
+ font: FontId;
+ weight: 400 | 700;
+ italic: boolean;
+ size: number;
+ color: string;
+ anim: OverlayAnim;
+ move: TextMoveId | string;
+ kf?: OverlayKey[];
+ /** Which of the look's cards sits behind this line. */
+ cardIndex: number;
+}
+
+const clampPos = (v: number) => Math.min(0.9, Math.max(0.1, v));
+const round2 = (n: number) => Math.round(n * 100) / 100;
+const step = <T,>(arr: readonly T[], n: number): T => arr[((n % arr.length) + arr.length) % arr.length];
+
+/** Comparison form of a line: letters and digits only. Two lines that read
+ * the same are the same hook however they are punctuated. */
+const normText = (t: string): string =>
+ t
+ .toLowerCase()
+ .normalize("NFKD")
+ .replace(/[^\p{L}\p{N}]/gu, "");
+
+/**
+ * A line broken and sized to the room it actually has. The look's size is a
+ * ceiling written for a wide frame at center; a vertical cut, a long line, a
+ * wider face, or a line placed off to one side all get breaks at word
+ * boundaries first and a smaller size only when breaking is not enough.
+ */
+export function fitTextToFrame(
+ text: string,
+ frame: { w: number; h: number },
+ size: number,
+ opts: { widthRatio: number; lineHeight?: number; x?: number; maxLines?: number } = {
+ widthRatio: 0.55,
+ }
+): { text: string; size: number } {
+ if (text.includes("\n")) return { text, size }; // the caller broke it themselves
+ const ratio = opts.widthRatio;
+ // An element centered off-axis only has the narrower half of the frame to
+ // spread into before it runs off the edge.
+ const x = opts.x ?? 0.5;
+ const room = Math.max(0.3, 2 * Math.min(x, 1 - x));
+ const usable = frame.w * 0.86 * room;
+ const words = text.split(/\s+/).filter((w) => w.length > 0);
+ if (words.length === 0) return { text, size };
+ const maxLines = opts.maxLines ?? 3;
+ const budget = Math.max(6, Math.floor(usable / (size * ratio)));
+ const lines: string[] = [];
+ let cur = "";
+ for (const w of words) {
+ const next = cur ? `${cur} ${w}` : w;
+ if (next.length <= budget || cur === "") cur = next;
+ else {
+ lines.push(cur);
+ cur = w;
+ }
+ }
+ if (cur) lines.push(cur);
+ const longest = lines.reduce((n, l) => Math.max(n, l.length), 0);
+ let fitted = size;
+ if (longest > budget) fitted = Math.floor(usable / (longest * ratio));
+ if (lines.length > maxLines) fitted = Math.min(fitted, Math.floor(size * (maxLines / lines.length)));
+ const rows = lines.length;
+ const lineH = opts.lineHeight ?? 1.25;
+ const tall = rows * fitted * lineH;
+ if (tall > frame.h * 0.8) fitted = Math.floor((frame.h * 0.8) / (rows * lineH));
+ return { text: lines.join("\n"), size: Math.max(16, Math.min(size, fitted)) };
+}
+
+/**
+ * Compose a run: every line's place in the frame, its face, its size, its
+ * tilt and how it arrives.
+ *
+ * The rotas are walked by index, so the design moves whether or not the
+ * caller said anything about a given line, and any field the caller did name
+ * wins outright.
+ */
+export function composeTextRun(
+ lines: ComposeLine[],
+ look: TextLook,
+ opts: {
+ variation: TextVariation;
+ layout?: TextLayout;
+ frame: { w: number; h: number };
+ /** The color cards the run is cycling; empty = the words sit on the
+ * frame and the palette is free to carry them. */
+ cards: string[];
+ }
+): ComposedLine[] {
+ const { variation, frame } = opts;
+ const cardCount = opts.cards.length;
+ const onCards = look.text.onCards ?? [];
+ const ens = look.ensemble;
+ const layout = opts.layout ?? (variation === "none" ? "center" : ens?.layout ?? "center");
+ const steps = LAYOUT_STEPS[layout] ?? LAYOUT_STEPS.center;
+ const faces: TextFace[] =
+ variation === "bold" && ens?.faces.length
+ ? ens.faces
+ : [{ font: look.text.font, weight: look.text.weight, italic: look.text.italic }];
+ const motions: OverlayAnimStyle[] =
+ variation === "none" || !ens?.motion.length
+ ? [look.motion.in?.style ?? "fade"]
+ : ens.motion;
+ const moves: TextMoveId[] =
+ variation === "none" || !ens?.moves.length ? ["none"] : ens.moves;
+ const palette =
+ variation === "bold" && cardCount === 0 && ens?.palette?.length
+ ? [look.text.color, ...ens.palette]
+ : [look.text.color];
+
+ // Sections in the order they first appear, so the rotas can start a new
+ // passage somewhere the last one did not sit.
+ const sectionOrder: string[] = [];
+ for (const l of lines) {
+ const s = l.section;
+ if (s && !sectionOrder.includes(s)) sectionOrder.push(s);
+ }
+
+ const seen = new Map<string, number>();
+
+ return lines.map((line, i) => {
+ const sec = line.section ? sectionOrder.indexOf(line.section) : 0;
+ const emphasis = line.emphasis ?? "normal";
+
+ // A hook that comes round again steps up rather than repeating flat.
+ const key = normText(line.text);
+ const repeats = key ? seen.get(key) ?? 0 : 0;
+ if (key) seen.set(key, repeats + 1);
+ const repeatBoost = variation === "none" ? 1 : 1 + Math.min(repeats, 3) * 0.09;
+
+ const place = variation === "none" ? { dx: 0, dy: 0 } : step(steps, i);
+ const x = line.x ?? clampPos(look.text.x + place.dx);
+ const y = line.y ?? clampPos(look.text.y + place.dy);
+
+ // Faces change per phrase pair; a new face every single line reads as
+ // noise even in a ransom-note look.
+ const face = step(faces, Math.floor(i / 2) + sec);
+ const font = line.font ?? face.font;
+ const tilt = line.rotation ?? (variation === "bold" ? step(TILTS, i + sec) : 0);
+
+ const base = (line.size ?? look.text.size) * (line.size ? 1 : face.scale ?? 1);
+ const wanted = Math.round(base * EMPHASIS_SCALE[emphasis] * repeatBoost);
+ // The look's own ratio is measured for its own face; the moment a line
+ // is carried by a different one, the line has to be broken against that
+ // face instead or it fits the frame on paper only.
+ const ownFace = font === look.text.font;
+ const fit = fitTextToFrame(line.text, frame, wanted, {
+ widthRatio: ownFace ? look.text.widthRatio ?? faceWidth(font) : faceWidth(font),
+ lineHeight: look.text.lineHeight,
+ x,
+ });
+
+ const inStyle = line.inStyle ?? step(motions, i + sec);
+ const inSeconds = Math.min(look.motion.in?.seconds ?? 0.35, Math.max(0.12, (line.end - line.start) * 0.4));
+ const anim: OverlayAnim = {
+ in: { style: inStyle, seconds: round2(inSeconds) },
+ ...(look.motion.out ? { out: look.motion.out } : {}),
+ ...(look.motion.loop
+ ? { loop: { style: look.motion.loop.style, speed: look.motion.loop.speed ?? 1 } }
+ : {}),
+ };
+
+ const cardIndex = cardCount > 0 ? i % cardCount : -1;
+ const onCard = cardIndex >= 0 && onCards.length > 0 ? step(onCards, cardIndex) : undefined;
+
+ // What the line does while it holds. A hero line takes the look's hero
+ // move; everything else walks the rota, so no two neighbours move alike.
+ const dur = line.end - line.start;
+ const moveId =
+ line.move ??
+ (emphasis === "hero" ? ens?.heroMove ?? step(moves, i + sec) : step(moves, i + sec));
+ const kf = textMoveKeys(moveId, { x, y, rotation: tilt }, dur);
+
+ return {
+ text: fit.text,
+ start: line.start,
+ end: line.end,
+ x,
+ y,
+ rotation: tilt,
+ font,
+ weight: face.weight,
+ italic: face.italic ?? false,
+ size: fit.size,
+ color: line.color ?? onCard ?? step(palette, i + sec),
+ anim,
+ move: moveId,
+ ...(kf ? { kf } : {}),
+ cardIndex,
+ };
+ });
+}
diff --git a/site/src/cut/lib/textLooks.ts b/site/src/cut/lib/textLooks.ts
index 00fb3c3c..bd728bf5 100644
--- a/site/src/cut/lib/textLooks.ts
+++ b/site/src/cut/lib/textLooks.ts
@@ -1,4 +1,5 @@
import type { OverlayAnimStyle, OverlayLoopStyle, WordAccentMode } from "@donkeycut/effects-kit";
+import type { TextEnsemble } from "./textCompose";
import type { CaptionStyleId, FontId } from "./types";
/**
@@ -55,6 +56,12 @@ export interface TextLook {
out?: { style: OverlayAnimStyle; seconds: number };
loop?: { style: OverlayLoopStyle; speed?: number };
};
+ /** What the look does across a whole run rather than on one line: where
+ * successive lines land, which faces the run rotates through, which
+ * entrances, and the colors a card-less run walks. Entry 0 of every rota
+ * repeats the look's own setting, so one line is always the look itself.
+ * See textCompose.ts. */
+ ensemble: TextEnsemble;
/** The same look on a caption track — what set_caption_look writes when it
* is handed this look id. */
captions: {
@@ -87,6 +94,19 @@ export const TEXT_LOOKS: Record<string, TextLook> = {
},
accent: "#FF5500",
motion: { in: { style: "pop", seconds: 0.35 } },
+ ensemble: {
+ faces: [
+ { font: "archivo-black", weight: 700 },
+ { font: "impact", weight: 400, scale: 1.14 },
+ { font: "space-grotesk", weight: 700, scale: 0.94 },
+ { font: "anton", weight: 400, scale: 1.18 },
+ ],
+ motion: ["pop", "rise", "grow", "bounce", "drop", "zoom"],
+ layout: "stack",
+ moves: ["none", "push", "settle", "none", "punch", "creep"],
+ heroMove: "punch",
+ palette: ["#FFE94A", "#FF5500", "#FFFFFF"],
+ },
captions: { style: "punchy", wordHighlight: true, accentColor: "#FF5500" },
},
@@ -108,6 +128,14 @@ export const TEXT_LOOKS: Record<string, TextLook> = {
},
accent: "#FFE94A",
motion: { in: { style: "fade", seconds: 0.25 }, out: { style: "fade", seconds: 0.25 } },
+ ensemble: {
+ faces: [{ font: "montserrat", weight: 700 }],
+ motion: ["fade"],
+ layout: "center",
+ moves: ["none", "push"],
+ heroMove: "push",
+ palette: ["#FFE94A"],
+ },
captions: { style: "highlight", wordHighlight: true, size: 84, accentColor: "#FFE94A" },
},
@@ -131,6 +159,18 @@ export const TEXT_LOOKS: Record<string, TextLook> = {
},
accent: "#F0ABFC",
motion: { in: { style: "streak", seconds: 0.4 }, loop: { style: "flicker", speed: 0.6 } },
+ ensemble: {
+ faces: [
+ { font: "bebas", weight: 400 },
+ { font: "oswald", weight: 700, scale: 0.9 },
+ { font: "anton", weight: 400, scale: 0.94 },
+ ],
+ motion: ["streak", "swivel", "flip", "wave", "tumble"],
+ layout: "alternate",
+ moves: ["push", "driftleft", "none", "sway", "driftright", "creep"],
+ heroMove: "slam",
+ palette: ["#22D3EE", "#F0ABFC", "#F5F5FF"],
+ },
captions: { style: "neon", wordHighlight: true, accentColor: "#F0ABFC" },
},
@@ -153,6 +193,17 @@ export const TEXT_LOOKS: Record<string, TextLook> = {
},
accent: "#FF5500",
motion: { in: { style: "typewriter", seconds: 0.5 } },
+ ensemble: {
+ faces: [
+ { font: "caveat", weight: 700 },
+ { font: "permanent-marker", weight: 400, scale: 0.82 },
+ ],
+ motion: ["typewriter", "wave", "rise", "grow"],
+ layout: "scatter",
+ moves: ["none", "sway", "float", "swing", "none"],
+ heroMove: "swing",
+ palette: ["#1B1B1B", "#FF5500", "#2563EB"],
+ },
captions: { style: "typewriter", wordHighlight: false, font: "caveat", accentColor: "#FF5500" },
},
@@ -175,6 +226,18 @@ export const TEXT_LOOKS: Record<string, TextLook> = {
},
accent: "#C9A227",
motion: { in: { style: "fade", seconds: 0.8 }, out: { style: "fade", seconds: 0.8 } },
+ ensemble: {
+ faces: [
+ { font: "dm-serif", weight: 400 },
+ { font: "playfair", weight: 700, scale: 0.96 },
+ { font: "dm-serif", weight: 400, italic: true, scale: 0.9 },
+ ],
+ motion: ["fade", "rise", "converge", "grow"],
+ layout: "drift",
+ moves: ["push", "float", "pull", "creep", "sink"],
+ heroMove: "pull",
+ palette: ["#F2EDE4", "#C9A227", "#B7B2A8"],
+ },
captions: { style: "minimal", wordHighlight: false, font: "dm-serif", accentColor: "#C9A227" },
},
@@ -197,6 +260,14 @@ export const TEXT_LOOKS: Record<string, TextLook> = {
},
accent: "#F2F2F2",
motion: { in: { style: "typewriter", seconds: 0.6 } },
+ ensemble: {
+ faces: [{ font: "mono", weight: 400 }, { font: "space-grotesk", weight: 400, scale: 0.96 }],
+ motion: ["typewriter", "wipe", "fade"],
+ layout: "ladder",
+ moves: ["none", "creep", "none", "push"],
+ heroMove: "push",
+ palette: ["#9BE29B", "#F2F2F2", "#7DD3FC"],
+ },
captions: { style: "typewriter", wordHighlight: false, font: "mono" },
},
@@ -219,6 +290,18 @@ export const TEXT_LOOKS: Record<string, TextLook> = {
},
accent: "#FFE94A",
motion: { in: { style: "rise", seconds: 0.35 }, out: { style: "fade", seconds: 0.2 } },
+ ensemble: {
+ faces: [
+ { font: "anton", weight: 400 },
+ { font: "impact", weight: 400, scale: 0.96 },
+ { font: "archivo-black", weight: 700, scale: 0.82 },
+ ],
+ motion: ["rise", "pop", "slideleft", "drop", "streak"],
+ layout: "alternate",
+ moves: ["push", "none", "float", "driftright", "settle"],
+ heroMove: "punch",
+ palette: ["#FFFFFF", "#FFE94A", "#FF5500"],
+ },
captions: { style: "hook", wordHighlight: true, accentColor: "#FFE94A" },
},
@@ -241,8 +324,125 @@ export const TEXT_LOOKS: Record<string, TextLook> = {
},
accent: "#FDE047",
motion: { in: { style: "scatter", seconds: 0.5 }, out: { style: "converge", seconds: 0.3 } },
+ ensemble: {
+ faces: [
+ { font: "poppins", weight: 700 },
+ { font: "bangers", weight: 400, scale: 1.18 },
+ { font: "montserrat", weight: 700, scale: 0.94 },
+ { font: "lobster", weight: 400, scale: 1.04 },
+ ],
+ motion: ["scatter", "tumble", "bounce", "swivel", "converge", "flip"],
+ layout: "scatter",
+ moves: ["spring", "swing", "orbit", "punch", "tiltsettle", "fall"],
+ heroMove: "slam",
+ palette: ["#FDE047", "#FFFFFF", "#38BDF8", "#FB7185"],
+ },
captions: { style: "bubble", wordHighlight: true, accentColor: "#FDE047" },
},
+
+ "ransom-note": {
+ id: "ransom-note",
+ label: "Ransom note",
+ when: "Every phrase in a different face, tilted, scattered across the frame. Chaotic, hand-cut, pop-punk — the look when the ask is \"make it wild\".",
+ frame: { background: "#F5F2EA", cards: [] },
+ text: {
+ font: "archivo-black",
+ size: 110,
+ weight: 700,
+ color: "#111111",
+ lineHeight: 1.05,
+ shadow: false,
+ x: 0.5,
+ y: 0.5,
+ widthRatio: 0.62,
+ },
+ accent: "#E11D48",
+ motion: { in: { style: "pop", seconds: 0.18 } },
+ ensemble: {
+ faces: [
+ { font: "archivo-black", weight: 700 },
+ { font: "bangers", weight: 400, scale: 1.22 },
+ { font: "permanent-marker", weight: 400, scale: 0.92 },
+ { font: "playfair", weight: 700, scale: 0.98 },
+ { font: "impact", weight: 400, scale: 1.1 },
+ { font: "lobster", weight: 400, scale: 1.06 },
+ ],
+ motion: ["pop", "tumble", "drop", "swivel", "scatter", "flip", "bounce"],
+ layout: "scatter",
+ moves: ["swing", "punch", "tiltsettle", "orbit", "fall", "spring", "slam"],
+ heroMove: "slam",
+ palette: ["#111111", "#E11D48", "#2563EB", "#F59E0B", "#111111"],
+ },
+ captions: { style: "punchy", wordHighlight: true, accentColor: "#E11D48" },
+ },
+
+ "stacked-caps": {
+ id: "stacked-caps",
+ label: "Stacked caps",
+ when: "Huge condensed caps climbing the frame, one phrase per rung. Rap verses, manifestos, title sequences that want weight.",
+ frame: { background: "#0A0A0A", cards: [] },
+ text: {
+ font: "anton",
+ size: 150,
+ weight: 400,
+ color: "#FFFFFF",
+ letterSpacing: -0.01,
+ lineHeight: 0.95,
+ shadow: false,
+ x: 0.5,
+ y: 0.5,
+ widthRatio: 0.44,
+ },
+ accent: "#FF3D00",
+ motion: { in: { style: "rise", seconds: 0.3 } },
+ ensemble: {
+ faces: [
+ { font: "anton", weight: 400 },
+ { font: "bebas", weight: 400, scale: 1.08 },
+ { font: "archivo-black", weight: 700, scale: 0.72 },
+ ],
+ motion: ["rise", "wipe", "drop", "grow", "streak"],
+ layout: "ladder",
+ moves: ["push", "none", "creep", "fall", "reveal"],
+ heroMove: "slam",
+ palette: ["#FFFFFF", "#FF3D00", "#FFFFFF", "#A3A3A3"],
+ },
+ captions: { style: "block", wordHighlight: true, accentColor: "#FF3D00" },
+ },
+
+ "pastel-pop": {
+ id: "pastel-pop",
+ label: "Pastel pop",
+ when: "Soft candy cards and a round friendly face, everything bouncing. Vlogs, cozy songs, anything sweet.",
+ frame: { background: "#FFF1F2", cards: ["#FFE4E6", "#DBEAFE", "#FEF9C3", "#DCFCE7"] },
+ text: {
+ font: "poppins",
+ size: 96,
+ weight: 700,
+ color: "#3F3F46",
+ onCards: ["#9F1239", "#1E40AF", "#854D0E", "#166534"],
+ lineHeight: 1.15,
+ shadow: false,
+ x: 0.5,
+ y: 0.5,
+ widthRatio: 0.58,
+ },
+ accent: "#FB7185",
+ motion: { in: { style: "bounce", seconds: 0.45 } },
+ ensemble: {
+ faces: [
+ { font: "poppins", weight: 700 },
+ { font: "rounded", weight: 700, scale: 1.02 },
+ { font: "pacifico", weight: 400, scale: 1.08 },
+ ],
+ motion: ["bounce", "pop", "grow", "wave", "flip"],
+ layout: "alternate",
+ moves: ["spring", "float", "breathe", "swing", "orbit"],
+ heroMove: "spring",
+ palette: ["#3F3F46", "#FB7185", "#60A5FA"],
+ },
+ captions: { style: "bubble", wordHighlight: true, accentColor: "#FB7185" },
+ },
};
export const TEXT_LOOK_IDS = Object.keys(TEXT_LOOKS);
diff --git a/site/src/cut/lib/textVideo.test.ts b/site/src/cut/lib/textVideo.test.ts
index 0b545624..3c1e1ef7 100644
--- a/site/src/cut/lib/textVideo.test.ts
+++ b/site/src/cut/lib/textVideo.test.ts
@@ -1,7 +1,9 @@
import { beforeEach, describe, expect, test } from "bun:test";
import { runAiTool } from "./aiTools";
import { useEditor } from "./store";
+import { composeTextRun, TEXT_LAYOUT_IDS, TEXT_LAYOUT_NOTES } from "./textCompose";
import { TEXT_LOOKS, textLookCatalog } from "./textLooks";
+import { matchTextMove, TEXT_MOVE_IDS, TEXT_MOVE_NOTES, textMoveKeys } from "./textMotion";
import { emptySubtitles, frameOf, isTextOverlay, isShapeOverlay, type SubtitleCue } from "./types";
/**
@@ -189,3 +191,306 @@ describe("the look registry", () => {
}
});
});
+
+describe("composing a run", () => {
+ beforeEach(reset);
+
+ const runOf = async (extra: Record<string, unknown> = {}) => {
+ await runAiTool("add_text_sequence", {
+ look: "kinetic-scatter",
+ lines: Array.from({ length: 8 }, (_, i) => ({
+ text: `line ${i}`,
+ start: i * 2,
+ end: i * 2 + 2,
+ })),
+ ...extra,
+ });
+ return overlays().filter(isTextOverlay);
+ };
+
+ test("lines land in different places instead of stacking on one anchor", async () => {
+ const words = await runOf();
+ const spots = new Set(words.map((w) => `${w.x},${w.y}`));
+ expect(spots.size).toBeGreaterThan(3);
+ });
+
+ test("the run walks faces, entrances and holds rather than repeating one", async () => {
+ const words = await runOf();
+ expect(new Set(words.map((w) => w.font)).size).toBeGreaterThan(1);
+ expect(new Set(words.map((w) => w.anim?.in?.style)).size).toBeGreaterThan(1);
+ expect(words.filter((w) => (w.kf?.length ?? 0) > 1).length).toBeGreaterThan(0);
+ });
+
+ test('variation "none" lays the run exactly as the look describes it', async () => {
+ const look = TEXT_LOOKS["kinetic-scatter"];
+ const words = await runOf({ variation: "none" });
+ expect(new Set(words.map((w) => `${w.x},${w.y}`)).size).toBe(1);
+ expect(new Set(words.map((w) => w.font))).toEqual(new Set([look.text.font]));
+ expect(words.every((w) => (w.kf?.length ?? 0) === 0)).toBe(true);
+ });
+
+ test("a named layout overrides the look's own", async () => {
+ const words = await runOf({ layout: "ladder" });
+ // The ladder walks down the frame and back; nothing sits left or right.
+ expect(new Set(words.map((w) => w.y)).size).toBeGreaterThan(2);
+ });
+
+ test("an unknown layout is refused", async () => {
+ let message = "";
+ try {
+ await runOf({ layout: "spiral" });
+ } catch (err) {
+ message = err instanceof Error ? err.message : String(err);
+ }
+ expect(message).toContain("layout");
+ });
+
+ test("hero lines come out bigger than whispers", async () => {
+ await runAiTool("add_text_sequence", {
+ look: "lyric-card",
+ lines: [
+ { text: "quiet", start: 0, end: 2, emphasis: "whisper" },
+ { text: "quiet", start: 2, end: 4, emphasis: "normal" },
+ { text: "LOUD", start: 4, end: 6, emphasis: "hero" },
+ ],
+ });
+ const [w, n, h] = overlays().filter(isTextOverlay);
+ expect(w.size).toBeLessThan(n.size);
+ expect(h.size).toBeGreaterThan(n.size);
+ });
+
+ test("a new section restarts the rotas so passages differ", async () => {
+ const look = TEXT_LOOKS["ransom-note"];
+ const lines = [
+ { text: "one", start: 0, end: 2, section: "verse" },
+ { text: "two", start: 2, end: 4, section: "verse" },
+ { text: "one", start: 4, end: 6, section: "chorus" },
+ { text: "two", start: 6, end: 8, section: "chorus" },
+ ];
+ const composed = composeTextRun(lines, look, {
+ variation: "bold",
+ frame: { w: 1920, h: 1080 },
+ cards: [],
+ });
+ expect(composed[0].font).not.toBe(composed[2].font);
+ });
+
+ test("per-line fields beat the ensemble", async () => {
+ await runAiTool("add_text_sequence", {
+ look: "neon-club",
+ lines: [
+ { text: "a", start: 0, end: 2 },
+ { text: "b", start: 2, end: 4, font: "caveat", x: 0.2, y: 0.8, rotation: 12, in_style: "wipe", move: "orbit" },
+ ],
+ });
+ const b = overlays().filter(isTextOverlay)[1];
+ expect(b.font).toBe("caveat");
+ expect(b.x).toBeCloseTo(0.2, 2);
+ expect(b.y).toBeCloseTo(0.8, 2);
+ expect(b.rotation).toBe(12);
+ expect(b.anim?.in?.style).toBe("wipe");
+ expect(b.kf!.length).toBeGreaterThan(2);
+ });
+
+ test("a line placed off-axis is broken to the room it actually has", async () => {
+ const composed = composeTextRun(
+ [{ text: "a long line that would fill the whole frame at center", start: 0, end: 2, x: 0.18 }],
+ TEXT_LOOKS["over-footage"],
+ { variation: "bold", frame: { w: 1920, h: 1080 }, cards: [] }
+ );
+ const widest = composed[0].text.split("\n").reduce((n, l) => Math.max(n, l.length), 0);
+ // Centered at x 0.18 there is only 36% of the frame to spread into.
+ expect(widest * composed[0].size * 0.5).toBeLessThanOrEqual(1920 * 0.4);
+ });
+
+ test("a repeated hook steps up rather than repeating flat", async () => {
+ const lines = Array.from({ length: 4 }, (_, i) => ({ text: "do", start: i, end: i + 1 }));
+ const composed = composeTextRun(lines, TEXT_LOOKS["lyric-card"], {
+ variation: "bold",
+ frame: { w: 1920, h: 1080 },
+ cards: [],
+ });
+ expect(composed[3].size).toBeGreaterThan(composed[0].size);
+ });
+});
+
+describe("keyframe moves", () => {
+ test("every id has a note and a track, and none outlives its element", () => {
+ for (const id of TEXT_MOVE_IDS) {
+ expect(TEXT_MOVE_NOTES[id].length).toBeGreaterThan(0);
+ const keys = textMoveKeys(id, { x: 0.5, y: 0.5, rotation: 0 }, 2);
+ if (id === "none") {
+ expect(keys).toBeUndefined();
+ continue;
+ }
+ expect(keys!.length).toBeGreaterThan(1);
+ for (const k of keys!) {
+ expect(k.t).toBeGreaterThanOrEqual(0);
+ expect(k.t).toBeLessThanOrEqual(2);
+ expect(k.opacity).toBeGreaterThanOrEqual(0);
+ }
+ // Keys arrive in play order with no duplicate times.
+ for (let i = 1; i < keys!.length; i++) expect(keys![i].t).toBeGreaterThan(keys![i - 1].t);
+ }
+ });
+
+ test("the track bends the way the preset does", () => {
+ // A pose track runs straight between its keys, so a move written on a
+ // curve has to be sampled off that curve: push's ease and orbit's circle
+ // both leave the straight line between the first key and the last.
+ const rest = { x: 0.5, y: 0.5, rotation: 0 };
+ const strayFrom = (id: string, read: (k: { scale: number; x: number; y: number }) => number) => {
+ const keys = textMoveKeys(id, rest, 3)!;
+ const first = keys[0];
+ const last = keys[keys.length - 1];
+ return Math.max(
+ ...keys.map((k) => {
+ const p = (k.t - first.t) / (last.t - first.t);
+ return Math.abs(read(k) - (read(first) + (read(last) - read(first)) * p));
+ })
+ );
+ };
+ expect(strayFrom("push", (k) => k.scale)).toBeGreaterThan(0.01);
+ expect(strayFrom("orbit", (k) => k.x)).toBeGreaterThan(0.01);
+ });
+
+ test("a line too short to read gets no track", () => {
+ expect(textMoveKeys("push", { x: 0.5, y: 0.5, rotation: 0 }, 0.1)).toBeUndefined();
+ });
+});
+
+describe("the ensemble registry", () => {
+ test("entry 0 of every rota is the look's own setting", () => {
+ for (const look of Object.values(TEXT_LOOKS)) {
+ expect(look.ensemble.faces[0].font).toBe(look.text.font);
+ expect(look.ensemble.faces[0].weight).toBe(look.text.weight);
+ expect(look.ensemble.faces[0].scale ?? 1).toBe(1);
+ expect(look.ensemble.motion[0]).toBe(look.motion.in?.style ?? "fade");
+ expect(TEXT_LAYOUT_IDS).toContain(look.ensemble.layout);
+ for (const m of look.ensemble.moves) expect(TEXT_MOVE_IDS).toContain(m);
+ if (look.ensemble.heroMove) expect(TEXT_MOVE_IDS).toContain(look.ensemble.heroMove);
+ }
+ });
+
+ test("every layout is described for the prompt", () => {
+ for (const id of TEXT_LAYOUT_IDS) expect(TEXT_LAYOUT_NOTES[id].length).toBeGreaterThan(0);
+ });
+});
+
+describe("moves on an existing element", () => {
+ beforeEach(reset);
+
+ const aTitle = async () => {
+ await runAiTool("add_text_sequence", {
+ look: "serif-mood",
+ lines: [{ text: "a line", start: 0, end: 3 }],
+ });
+ return overlays().filter(isTextOverlay)[0];
+ };
+
+ test("a named move writes the element's own pose track", async () => {
+ const o = await aTitle();
+ await runAiTool("set_overlay_animation", { id: o.id, move: "push" });
+ const after = overlays().filter(isTextOverlay)[0];
+ expect(after.kf!.length).toBeGreaterThan(1);
+ // A push grows across the hold and never leaves its resting spot.
+ expect(after.kf![after.kf!.length - 1].scale).toBeGreaterThan(after.kf![0].scale);
+ for (const key of after.kf!) {
+ expect(key.x).toBeCloseTo(after.x, 3);
+ expect(key.t).toBeGreaterThanOrEqual(0);
+ expect(key.t).toBeLessThanOrEqual(after.end - after.start + 1e-6);
+ }
+ });
+
+ test('move "none" clears the track', async () => {
+ const o = await aTitle();
+ await runAiTool("set_overlay_animation", { id: o.id, move: "swing" });
+ expect(overlays().filter(isTextOverlay)[0].kf!.length).toBeGreaterThan(1);
+ await runAiTool("set_overlay_animation", { id: o.id, move: "none" });
+ expect(overlays().filter(isTextOverlay)[0].kf ?? []).toHaveLength(0);
+ });
+
+ test("an unknown move is refused", async () => {
+ const o = await aTitle();
+ let message = "";
+ try {
+ await runAiTool("set_overlay_animation", { id: o.id, move: "wobble" });
+ } catch (err) {
+ message = err instanceof Error ? err.message : String(err);
+ }
+ expect(message).toContain("Unknown move");
+ });
+
+ test("a move and an entrance sit on the element together", async () => {
+ const o = await aTitle();
+ await runAiTool("set_overlay_animation", { id: o.id, in_style: "rise", move: "float" });
+ const after = overlays().filter(isTextOverlay)[0];
+ expect(after.anim?.in?.style).toBe("rise");
+ expect(after.kf!.length).toBeGreaterThan(1);
+ });
+});
+
+describe("every move is real motion", () => {
+ test("each id moves the element somewhere", () => {
+ for (const id of TEXT_MOVE_IDS) {
+ const keys = textMoveKeys(id, { x: 0.5, y: 0.5, rotation: 0 }, 2.5);
+ if (id === "none") {
+ expect(keys).toBeUndefined();
+ continue;
+ }
+ expect(keys!.length).toBeGreaterThan(1);
+ const moves = keys!.some(
+ (k) =>
+ Math.abs(k.x - keys![0].x) > 1e-4 ||
+ Math.abs(k.y - keys![0].y) > 1e-4 ||
+ Math.abs(k.scale - keys![0].scale) > 1e-3 ||
+ Math.abs(k.rotation - keys![0].rotation) > 1e-3 ||
+ Math.abs(k.opacity - keys![0].opacity) > 1e-3
+ );
+ expect(moves).toBe(true);
+ }
+ });
+});
+
+describe("move strength", () => {
+ const rest = { x: 0.5, y: 0.5, rotation: 0 };
+
+ test("scales every offset from rest and leaves the timing alone", () => {
+ const full = textMoveKeys("push", rest, 3, 1)!;
+ const half = textMoveKeys("push", rest, 3, 0.5)!;
+ expect(half.map((k) => k.t)).toEqual(full.map((k) => k.t));
+ for (let i = 0; i < full.length; i++)
+ expect(half[i].scale - 1).toBeCloseTo((full[i].scale - 1) / 2, 5);
+ });
+
+ test("a move at any strength is found again on the element", () => {
+ for (const id of TEXT_MOVE_IDS) {
+ if (id === "none") continue;
+ for (const strength of [0.25, 0.5, 1, 1.5, 2]) {
+ const keys = textMoveKeys(id, rest, 2.5, strength)!;
+ expect(matchTextMove(keys, rest, 2.5)).toEqual({ id, strength });
+ }
+ }
+ });
+
+ test("keys the user has dragged stop matching", () => {
+ const keys = textMoveKeys("swing", rest, 2.5, 1)!;
+ keys[1] = { ...keys[1], x: keys[1].x + 0.2 };
+ expect(matchTextMove(keys, rest, 2.5)).toBeUndefined();
+ expect(matchTextMove(undefined, rest, 2.5)).toBeUndefined();
+ });
+
+ test("the tool takes a strength and clamps it", async () => {
+ reset();
+ await runAiTool("add_text_sequence", {
+ look: "serif-mood",
+ lines: [{ text: "a line", start: 0, end: 3 }],
+ });
+ const o = overlays().filter(isTextOverlay)[0];
+ await runAiTool("set_overlay_animation", { id: o.id, move: "push", move_strength: 0.5 });
+ const after = overlays().filter(isTextOverlay)[0];
+ expect(
+ matchTextMove(after.kf, { x: after.x, y: after.y, rotation: after.rotation ?? 0 }, 3)
+ ).toEqual({ id: "push", strength: 0.5 });
+ });
+});
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index 34bfc44d..c86df172 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -10,7 +10,9 @@
*/
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 { textMoveCatalog } from "@/cut/lib/textMotion";
import { OVERLAY_ANIMATION_TOOLS } from "@/cut/components/AnimationTiles.tools";
import { AUDIO_TOOLS } from "@/cut/components/AudioPanel.tools";
import { EDITOR_TOOLS } from "@/cut/components/Editor.tools";
@@ -137,14 +139,14 @@ What the user sees on the transitions row: one badge per bar, and nothing else
The title lanes hold three overlay element kinds, all sharing timing (start/end), center position (x/y fractions 0..1), rotation (degrees), opacity, and a lane; \`overlays\` in editor_state lists them with their \`kind\`. All burn into the export exactly as previewed.
Rows are how elements stack (\`lane\`, 0 = the front row; a higher row draws further back). Two elements on ONE row never overlap in time — placing a title where a shape already sits slides it clear instead of laying it on top — so anything meant to sit over something else names a LOWER row: title on lane 0, the background shape behind it on lane 1. Every add tool and update_overlay take \`lane\`.
The frame's own color is set_background, not a full-frame rectangle: it fills the frame behind every clip and element, holds for the whole cut, letterboxes fitted footage, and shows through gaps on track 0. "Make the background white", a colored card behind a title sequence, a text-and-graphics video with no footage at all — all of them start with set_background. A rectangle element is for a panel or a band inside the frame, not for the frame itself.
-A whole run of text — a lyric video, a kinetic-typography passage, a quote sequence — is add_text_sequence, one call carrying a named look (frame color, card colors, type, motion): read the text-videos skill for the looks and the flow. A video needs no footage. Titles, shapes and stickers over a background color are a complete cut on their own: it plays, exports, and shares like any other. Build one by setting the background, then placing elements on the rows the stack needs — reach for footage only when the user asks for it.
+A whole run of text — a lyric video, a kinetic-typography passage, a quote sequence — is add_text_sequence, one call carrying a named look. A look is the design of the whole run, not one line: the frame color, the cards, and the ensemble the run walks across its length — faces, entrances, where successive lines land, and what each holds. Read the text-videos skill for the looks and the flow, and text-creativity for the fifty devices that keep a long run from reading flat. Never lay a run of identical centered lines and then repair it element by element. A video needs no footage. Titles, shapes and stickers over a background color are a complete cut on their own: it plays, exports, and shares like any other. Build one by setting the background, then placing elements on the rows the stack needs — reach for footage only when the user asks for it.
Titles (add_title / update_overlay): text, size (frame px; the design short side is 1080), font (${FONTS.map((f) => `${f.id}=${f.label}`).join(", ")}), weight (400/700), color, shadow, plate (translucent dark backdrop).
Shapes (add_shape): rect, ellipse, line, arrow. w/h are frame fractions; rect/ellipse take fill + fill_opacity, corner radius (rect), and an outline (stroke_color/stroke_width); line/arrow draw in \`fill\` with h as their thickness, and rotation gives them their direction (0° points right, 90° points down).
Stickers (add_sticker): a project image asset (generated cutouts in the Elements panel carry origin "sticker"); w is a frame-width fraction and height follows the source's aspect. Lottie JSON uploads become animated stickers that loop for the element's duration.
Custom 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 picture — the footage and everything laid over it. Two families, one list: the treatments (${EFFECT_TREATMENTS.join(", ")}) and the graded looks (${LOOK_EFFECTS.join(", ")}). Placed like any element and tuned with \`amount\` (update_overlay); an effect added over a clip opens covering that clip, and trims like anything else. One effect at a time reads best, amounts under ~0.5.
Advanced text (update_overlay): italic, align (multi-line), letter_spacing (em), line_height, 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) and a Loop (${OVERLAY_LOOP_STYLE_IDS.join(", ")}) that runs its whole duration. Entrances 0.3–0.6s read well; one loop per scene, sparingly.
+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. Every one of these is keyframe data — the same poses set_overlay_keyframes writes — so a named move lands as ordinary keys the user can drag, and anything the names do not cover is keyed directly.
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:
@@ -159,27 +161,108 @@ Tasteful graphics: shapes read best as accents (a highlight box behind a stat, a
In the UI: the timeline toolbar adds Text; the Elements side-panel tab browses stickers and shapes and creates sticker images, and the Effects tab holds the effects — a click in any panel picks a tile, and dragging one onto the timeline is what places it; dragging in the preview places an element, its corner handle resizes, the top handle rotates; the Inspector edits every field.`,
"text-videos": `# Text-driven videos: lyrics, kinetic type, quote cards
-A video whose picture is words. Three pieces: the frame behind them (set_background, or the user's footage), the words themselves, and the clock that says when each line lands.
+A video whose picture is words. Three pieces: the frame behind them (set_background, or the user's footage), the words themselves, and the clock that says when each line lands. For the device list — fifty ways to make a run of text worth watching — read the text-creativity skill.
-**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 color, 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, 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.
-**The looks.** Every look sets the frame color, the card colors it cycles, the type, the motion, and the caption equivalent, so a whole video comes from one id:
+**The looks.** A look 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()}
+**Composing a run (this is the part that decides whether it reads as creative).** add_text_sequence takes the whole run in one call and walks the look's rotas by index, so no two neighbouring lines land the same. Steer it:
+- \`variation\`: bold (default) walks faces, tilts, palette and keyframe moves; subtle keeps one face and varies placement and entrance; none lays every line identical — only for a run you are about to hand-compose yourself.
+- \`layout\` overrides where lines land: ${TEXT_LAYOUT_IDS.map((id) => `${id} — ${TEXT_LAYOUT_NOTES[id]}`).join(" ")}
+- \`emphasis\` per line: hero is markedly bigger and takes the look's hero move, whisper is small and quiet. Mark the hook, the title line, the punchline. Two or three heroes in a verse; a run where everything is a hero is a run where nothing is.
+- \`section\` per line ("verse", "chorus", "bridge"): a new label restarts the type and color rotas, so a chorus does not look like the verse before it. Label every line of a song — it is the cheapest way to make three passages read as three passages.
+- \`move\` per line: what it does WHILE it holds, separate from the entrance. The rota gives each line one already; name one when a specific line wants a specific move.
+- Anything you set per line — font, x, y, rotation, in_style, color, size — wins over the ensemble.
+Never lay a run at variation "none" and then repair it with a hundred update_overlay calls. Compose it in the call.
+
**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.
-4. Check it: seek + capture_frame at two or three lines, and listen_audio across one of them. A line that sits early or late retimes with update_cue — the recognizer's gaps are where drift comes from.
+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.
+4. Check it: seek + capture_frame at three or four lines that landed on DIFFERENT rota steps, and listen_audio across one of them. A line that sits early or late retimes with update_cue.
With no lyrics text, transcribe with subtitles_generate and work from the cues it wrote.
-**Words over the user's footage.** Same flow, with the over-footage look (or any look with \`cards: false\`) and \`background: false\` — the clips keep playing and the words ride above them. Aim them off the caption band when captions are also on.
+**Words over the user's footage.** Same flow, with the over-footage look (or any look with no cards) and \`background: false\` — the clips keep playing and the words ride above them. Aim them off the caption band when captions are also on, and prefer layouts that stay out of the middle of the shot.
**Words on plain color.** A cut with nothing on track 0 is a complete video: set the background, place the run, export. Cards are how the color changes line to line — the sequence paints one per line on its own row behind the words, so they stack instead of sliding apart.
**Timing.** One line per screen beats two. A line needs about 0.4s minimum to read; 1.5–2.5s is the normal beat for a spoken line, and a sung line takes whatever the vocal takes. Lines never overlap on a row — the sequence tool lays them end to end from the times you give it.
-**Making it yours.** Every look is a starting point: after add_text_sequence, update_overlay retimes or recolors any line, set_overlay_animation swaps a line's motion, and set_overlay_keyframes moves it on a path. A per-line \`color\` on the sequence call marks the word that matters without touching the rest.`,
+**Fixing a run.** update_overlay retimes or recolors any line, set_overlay_animation swaps its entrance, set_overlay_keyframes gives it a path. Reach for those to fix a handful of lines. When the whole run is wrong, delete it and re-compose with different look, layout, or variation — that is one call against a hundred.`,
+
+ "text-creativity": `# Text creativity: fifty devices
+Ways to make a run of words worth watching. Every one is buildable with the tools you already have — add_text_sequence composes most of them in a single call; the rest are update_overlay, set_overlay_keyframes, set_mask, add_shape and add_overlay_video on top.
+
+Read this before any text-heavy job the user calls flat, boring, samey, or "not creative". The failure mode is always the same: one design repeated a hundred times at dead center. Pick three or four devices from different groups and commit to them for the whole video — a run using twenty devices is noise, and a run using none is wallpaper.
+
+## Rhythm — what changes from line to line
+1. **Hero and whisper.** Mark the hook \`emphasis: hero\`, the throwaway line \`whisper\`. Size contrast is the single strongest signal that a video was designed.
+2. **Small to large.** March size up across a passage: whisper, normal, normal, hero. The build is the payoff.
+3. **Large to small.** The reverse, for a line that trails off or an admission.
+4. **Section palettes.** Label verse/chorus/bridge with \`section\` — the rotas restart and the passages stop looking alike.
+5. **Escalating repeat.** A repeated hook already steps up size each time it comes round. Push it further by naming the last one hero.
+6. **One word per screen.** Break a line into its words as separate lines on the beat. Fast, percussive, made for a drop.
+7. **Held line, moving words.** The opposite: one line up for four bars with a slow \`push\` move under it, while everything else is fast.
+8. **The rest.** Leave a beat with nothing on screen before the hook. Silence in the picture makes the next line land.
+9. **Off-beat entry.** Start a line a sixth of a second before its vocal rather than on it — text read early feels sung, text read late feels subtitled.
+10. **Anticipation card.** A whisper line holding a single word ("almost…") between two loud passages.
+
+## Type — the faces themselves
+11. **Two-face pairing.** A display face for the hook, a neutral one for the rest. The bold ensembles already do this; hold it steady rather than adding a third.
+12. **Mixed case on purpose.** Caps faces (anton, bebas, bangers, archivo-black) shout; sentence-case faces (montserrat, poppins, space-grotesk, playfair, dm-serif) speak. When a user says everything is shouting, the fix is a mixed-case face, not smaller type.
+13. **Handwriting for confession.** caveat and permanent-marker read as a person, not a title card.
+14. **Serif for weight.** playfair and dm-serif carry ballads, credits and anything that should feel written down.
+15. **Mono for machinery.** mono plus a typewriter entrance for anything that should read as a screen.
+16. **Tracking as tone.** letter_spacing 0.06–0.12em on a serif reads expensive; -0.01em on caps reads like a poster.
+17. **Line height as pace.** lineHeight under 1.0 on caps packs a block; 1.4 on a serif opens it out.
+18. **Stroke instead of shadow.** A heavy stroke (0.03–0.05em) over footage keeps type legible where a shadow goes muddy.
+19. **Word-level color.** A per-line \`color\` on the one line that matters marks it without touching the rest.
+20. **The mismatched word.** One word of a phrase on its own element, in another face, tilted, overlapping the rest. Two calls, enormous effect.
+
+## Composition — where words sit
+21. **Stop centering everything.** A hundred lines at 0.5/0.5 is the flattest thing text can do. Every layout except \`center\` fixes it in one parameter.
+22. **Stack.** Lines step up and down the middle column so a phrase builds vertically.
+23. **Call and response.** \`alternate\` swings left and right — perfect for question/answer or two voices.
+24. **Ladder.** Each line a rung lower, then back to the top: lists, countdowns, verses.
+25. **Drift.** A slow diagonal walk for long holds and ballads.
+26. **Scatter.** Scattered chaos for punk, comedy and anything frantic.
+27. **Corners.** Poster energy — words claiming the edges of the frame.
+28. **Left rail.** Pin a whole passage to x 0.22 with align left; the empty right half is the composition.
+29. **Overlap on purpose.** Two elements on DIFFERENT rows at the same time, one behind the other — a big pale word behind a small sharp one. Same row would slide them apart, so give the back word a higher lane.
+30. **Off-frame bleed.** A hero word sized past the frame edge so it is cropped. Set size well over the fit and let it bleed.
+31. **Rule of thirds.** Park the run at y 0.33 or 0.66 rather than 0.5 and leave the other two thirds empty.
+32. **Follow the subject.** Over footage, place words in the empty half of the shot and move them when the shot changes.
+
+## Motion — arrival and hold
+**Everything here is keyframes.** Entrances, exits, loops and moves are one format: a pose (position, scale, rotation, opacity, letter-spacing) keyed over a normalized window with cubic-bezier easing, plus a range selector that hands the motion from one character to the next — the After Effects text-animator model, the one Lottie serializes. So a named preset and a hand-keyed track are the same object at different levels of convenience. Reach for a name first; key it directly when no name says what you mean.
+
+33. **Arrival and hold are two decisions.** \`in_style\` is how it appears; \`move\` is what it does for the rest of its life. A line with only an entrance freezes the moment it lands.
+34. **The moves** — each writes the element's own pose track, so the keys are there to drag afterwards:
+${textMoveCatalog()}
+35. **Per-glyph entrances.** rise, drop, grow, flip, swivel, bounce, wave, converge, streak, tumble and scatter move a title's letters one at a time. They cost nothing extra and are the difference between a title and kinetic typography.
+36. **Typewriter for a reveal.** Slow it to two thirds of the line's hold so the text finishes typing just before it leaves.
+37. **Wipe for a band.** A wipe entrance on a line sitting in a shape band reads as a broadcast lower third.
+38. **Loops, sparingly.** flicker on neon, float on dreamy, wiggle on comedy — one loop per passage, never on every line.
+39. **Exit matters.** A run where every line simply cuts out feels cheap; a 0.2s fade or a converge out costs nothing.
+40. **Contrast the move to the entrance.** A violent entrance (slam, tumble) into a still hold; a soft entrance (fade) into a slow push. Both loud reads as noise.
+41. **Match the move to the beat.** punch and slam on hits, push and creep under sustained notes, float and breathe under held vocals.
+42. **Key it yourself when no name says it.** set_overlay_keyframes takes whole poses in seconds from the element's start — a path across the frame, a hold-then-drift, a beat that lands on a specific hit in the music. Two or three keys carry almost everything, and a preset entrance still composes over them.
+
+## Frame and color
+43. **Cards as punctuation.** A full-frame color card behind each line, cycling — the color change IS the edit. lyric-card and pastel-pop do it; \`cards: true\` adds it to any look that has them.
+44. **Invert on the hook.** One card in the cycle with the light/dark relationship flipped. The eye reads it as a cut.
+45. **Band, not plate.** A shape rectangle at fill_opacity 0.2–0.5 behind a line on a lower row, wider than the text, beats a plate for anything editorial.
+46. **Color as the section marker.** One accent per passage, changing at the chorus. Cheaper and clearer than changing everything.
+47. **Two colors only.** A frame color and one accent, everywhere. Restraint reads as design; six colors read as defaults.
+
+## Construction — beyond the presets
+48. **Masked reveal.** set_mask a linear mask on a title and keyframe it: the line wipes on from one side, no entrance preset involved.
+49. **Text behind the speaker.** A subject mask (inverted) on a title over footage sits the words behind the person in the shot. Nothing else in a text video looks as expensive.
+50. **Text in the footage.** add_overlay_video a copy of the shot, mask it to the text's shape region, and the picture plays inside the word. The graphics skill's composite-builds section has the geometry.
+
+**How to use this list.** Pick a look for the base design, one composition device, one rhythm device and one motion device, and hold them for the whole video. Then break the pattern exactly once, on the hook. That single break is what a viewer remembers.`,
"audio-and-subtitles": `# Audio, voiceover & subtitles
Lyrics and scripts the user already has: sync_lyrics times their exact words against the audio (transcribing first when needed) and writes them to a caption track with per-word timings; set_caption_look then dresses the track — preset, size, font, karaoke word highlight, accent color — from a text-videos look id or field by field. The text-videos skill has the whole flow, including turning the same timed lines into full-frame cards.