Open source CapCut alternative.
TypeScript
feat(site): drop a title's letters in any order, from any height, solid and streaked [rebuild]
David Le7aa0ba51042f
diff --git a/evals/cut-perf.latest-report.json b/evals/cut-perf.latest-report.jsonindex 50eea740..cdbdb186 100644--- a/evals/cut-perf.latest-report.json+++ b/evals/cut-perf.latest-report.json@@ -51,10 +51,10 @@},"frameMs": 16.7,"scrub": {- "p50": 15.5,- "p95": 32.4,- "mean": 18.14,- "max": 32.7,+ "p50": 15.8,+ "p95": 31.6,+ "mean": 18.41,+ "max": 31.8,"n": 41},"longTasks": {@@ -64,7 +64,7 @@"max": 0,"n": 0},- "liveSamples": 50,+ "liveSamples": 56,"machine": "desktop"},{@@ -74,17 +74,17 @@"notes": [],"late": {"p50": 0,- "p95": 0,- "mean": 0,- "max": 0,+ "p95": 1,+ "mean": 0.12,+ "max": 1,"n": 41},"frameMs": 16.7,"scrub": {- "p50": 13.8,- "p95": 16,- "mean": 12.29,- "max": 52.9,+ "p50": 15.4,+ "p95": 31.9,+ "mean": 17.07,+ "max": 47.3,"n": 41},"longTasks": {@@ -94,7 +94,7 @@"max": 0,"n": 0},- "liveSamples": 64,+ "liveSamples": 74,"machine": "desktop"},{@@ -111,10 +111,10 @@},"frameMs": 16.7,"scrub": {- "p50": 15.7,- "p95": 16.4,- "mean": 15.62,- "max": 32.3,+ "p50": 15.4,+ "p95": 16.3,+ "mean": 15.33,+ "max": 32.2,"n": 41},"longTasks": {@@ -124,7 +124,7 @@"max": 0,"n": 0},- "liveSamples": 89,+ "liveSamples": 91,"machine": "desktop"},{@@ -141,10 +141,10 @@},"frameMs": 16.7,"scrub": {- "p50": 15.4,+ "p50": 15.1,"p95": 16.4,- "mean": 15.65,- "max": 34,+ "mean": 14.9,+ "max": 31.9,"n": 81},"longTasks": {@@ -165,16 +165,16 @@"late": {"p50": 0,"p95": 1,- "mean": 0.2,+ "mean": 0.17,"max": 2,"n": 41},"frameMs": 16.7,"scrub": {- "p50": 15.6,- "p95": 32.6,- "mean": 18.4,- "max": 48.4,+ "p50": 15.5,+ "p95": 32.2,+ "mean": 17.71,+ "max": 48.9,"n": 41},"longTasks": {@@ -184,7 +184,7 @@"max": 0,"n": 0},- "liveSamples": 55,+ "liveSamples": 65,"machine": "desktop"},{@@ -201,10 +201,10 @@},"frameMs": 16.7,"scrub": {- "p50": 15.7,+ "p50": 15.6,"p95": 32.3,- "mean": 18.27,- "max": 47.2,+ "mean": 18.17,+ "max": 49.3,"n": 41},"longTasks": {@@ -214,7 +214,7 @@"max": 0,"n": 0},- "liveSamples": 59,+ "liveSamples": 66,"machine": "desktop"},{@@ -225,16 +225,16 @@"late": {"p50": 1,"p95": 1,- "mean": 0.88,+ "mean": 0.93,"max": 1,"n": 41},"frameMs": 16.7,"scrub": {- "p50": 31.4,- "p95": 32.4,- "mean": 28.79,- "max": 32.8,+ "p50": 31.9,+ "p95": 32.7,+ "mean": 30.66,+ "max": 33.1,"n": 41},"longTasks": {@@ -303,8 +303,8 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {"p50": 0,@@ -326,13 +326,13 @@"pass": true,"notes": [],"drops": 0,- "presented": 3240,+ "presented": 3243,"lag": {"p50": 0.02,"p95": 0.03,"mean": 0.02,"max": 0.03,- "n": 3240+ "n": 3243},"stallShare": 0,"decay": {@@ -340,8 +340,8 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {"p50": 0,@@ -363,13 +363,13 @@"pass": true,"notes": [],"drops": 0,- "presented": 222,+ "presented": 223,"lag": {"p50": 0.02,"p95": 0.03,"mean": 0.02,"max": 0.03,- "n": 222+ "n": 223},"stallShare": 0,"decay": {@@ -377,8 +377,8 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {"p50": 0,@@ -414,8 +414,8 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {"p50": 0,@@ -451,8 +451,8 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {"p50": 0,@@ -488,15 +488,15 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {- "p50": 56,- "p95": 56,- "mean": 56,- "max": 56,- "n": 1+ "p50": 0,+ "p95": 0,+ "mean": 0,+ "max": 0,+ "n": 0},"liveSamples": 10,"liveSources": 1,@@ -511,13 +511,13 @@"pass": true,"notes": [],"drops": 0,- "presented": 3443,+ "presented": 3437,"lag": {"p50": 0.02,"p95": 0.03,"mean": 0.01,"max": 0.03,- "n": 3443+ "n": 3437},"stallShare": 0,"decay": {@@ -525,14 +525,14 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {- "p50": 67,- "p95": 67,- "mean": 67,- "max": 67,+ "p50": 73,+ "p95": 73,+ "mean": 73,+ "max": 73,"n": 1},"liveSamples": 10,@@ -562,8 +562,8 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {"p50": 0,@@ -585,13 +585,13 @@"pass": true,"notes": [],"drops": 0,- "presented": 3431,+ "presented": 3439,"lag": {"p50": 0.02,"p95": 0.03,"mean": 0.02,"max": 0.03,- "n": 3431+ "n": 3439},"stallShare": 0,"decay": {@@ -599,14 +599,14 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {- "p50": 186,- "p95": 186,- "mean": 186,- "max": 186,+ "p50": 100,+ "p95": 100,+ "mean": 100,+ "max": 100,"n": 1},"liveSamples": 10,@@ -636,8 +636,8 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {"p50": 0,@@ -695,7 +695,7 @@"presented": 1095,"lag": {"p50": 0.02,- "p95": 0.03,+ "p95": 0.02,"mean": 0.01,"max": 0.03,"n": 1092@@ -706,14 +706,14 @@"last": 0},"clock": {- "lead": 0.22,- "reported": 0.22+ "lead": 0.04,+ "reported": 0.04},"longTasks": {- "p50": 178,- "p95": 178,- "mean": 125,- "max": 178,+ "p50": 196,+ "p95": 196,+ "mean": 134,+ "max": 196,"n": 2},"liveSamples": 10,diff --git a/site/packages/effects-kit/src/anim.ts b/site/packages/effects-kit/src/anim.tsindex c6d10aa0..638e4fca 100644--- a/site/packages/effects-kit/src/anim.ts+++ b/site/packages/effects-kit/src/anim.ts@@ -29,6 +29,8 @@ import type { OverlayFontCycle } from "./fontCycle";import type { MotionPose, MotionPreset } from "./motion/types";import type { OverlayWords } from "./words";import { splitScale } from "./stretch";+import { capStreak } from "./camera";+import { EASE_BEZIER, type EaseId } from "./ease";export type OverlayAnimStyle =| "fade"@@ -120,7 +122,31 @@ export interface OverlayEdge {* passing the motion from the first letter to the last (0 = every letter* together, near 1 = one at a time). Absent = the style's own. */stagger?: number;-}+ /** The order a per-letter style deals the letters their turns: "shuffle"+ * plays them in a fixed scattered order (After Effects' Randomize Order);+ * a list names the characters by index (the glyph count: spaces and line+ * breaks included) in the order they go, an order read off a reference.+ * Absent = the style's own, reading order for most. */+ order?: EdgeOrder | number[];+ /** How far the style travels from rest at its far end, design px (1080+ * short side): a drop from high above the frame, a long slide. Absent =+ * the style's own reach. */+ distance?: number;+ /** The curve the move travels on, over the style's own: a letter falling+ * at a steady pace is linear, one that brakes into place an ease out. */+ ease?: EaseId;+ /** false: no fade — the element (each letter) stays solid the whole way+ * in or out, as a letter falling in from beyond the frame does. Absent =+ * the style's own. */+ fade?: boolean;+}++export type EdgeOrder = "reading" | "shuffle";+export const EDGE_ORDERS: readonly EdgeOrder[] = ["reading", "shuffle"];+/** The farthest an edge's distance may send it, design px: past any frame. */+export const EDGE_DISTANCE_MAX = 4000;+/** Seeds the shuffled order, so the same title always scatters the same way. */+const EDGE_SHUFFLE_SEED = 5;/*** The bar at the end of the typed text. It holds solid while the entrance@@ -198,8 +224,98 @@ export interface OverlayAnim {/** The motion a slot plays: the one it carries, or the catalog entry it* names. Everything downstream reads the preset, never the id. */-export const edgeMotion = (slot: OverlayEdge | undefined): MotionPreset | undefined =>- slot ? (slot.preset ?? edgePreset(slot.style)) : undefined;+export const edgeMotion = (slot: OverlayEdge | undefined): MotionPreset | undefined => {+ if (!slot) return undefined;+ const base = slot.preset ?? edgePreset(slot.style);+ if (!base || (slot.order === undefined && !(slot.distance! > 0) && !slot.ease && slot.fade !== false)) return base;+ let made = shaped.get(slot);+ if (!made) {+ made = shapeEdge(base, slot);+ shaped.set(slot, made);+ }+ return made;+};++/** How far a preset's motion travels from rest, design px: the reach an+ * edge's `distance` replaces. 0 for a style that never moves. */+export function presetReach(preset: MotionPreset): number {+ const reach = (props: MotionPreset["animate"] | undefined) =>+ Math.max(0, ...(props?.position ?? []).map((k) => Math.max(Math.abs(k.v[0]), Math.abs(k.v[1]))));+ return Math.max(reach(preset.animate), reach(preset.animateOut));+}++/** The style's own reach under a slot, before its distance: what the slot+ * plays with no distance set. */+export const edgeOwnReach = (slot: OverlayEdge | undefined): number => {+ const base = slot ? (slot.preset ?? edgePreset(slot.style)) : undefined;+ return base ? presetReach(base) : 0;+};++/** Glyph indices for letters counted the way a person reads them: `letters`+ * numbers the text's characters from 0, skipping spaces and line breaks;+ * the glyph count the renderers walk includes both. Out-of-range numbers+ * drop out. */+export function letterSequence(text: string, letters: number[]): number[] {+ const at: number[] = [];+ let gi = 0;+ for (const line of text.split("\n")) {+ for (const ch of line) {+ if (!/\s/.test(ch)) at.push(gi);+ gi++;+ }+ gi++; // the line break takes a turn too+ }+ const seen = new Set<number>();+ return letters.filter((k) => Number.isInteger(k) && k >= 0 && k < at.length && !seen.has(k) && seen.add(k)).map((k) => at[k]);+}++/** Slots are replaced, never edited, so a shaped preset stays good for as+ * long as its slot lives. */+const shaped = new WeakMap<OverlayEdge, MotionPreset>();++/** The slot's own order and reach written into its preset, so every reader —+ * the glyph evaluator, the crop padding, both renderers — plays them. */+function shapeEdge(base: MotionPreset, slot: OverlayEdge): MotionPreset {+ let preset = base;+ if (Array.isArray(slot.order) && base.selector) {+ preset = { ...preset, selector: { ...base.selector, randomize: false, sequence: slot.order } };+ } else if (slot.order && base.selector) {+ const randomize = slot.order === "shuffle";+ preset = {+ ...preset,+ selector: { ...base.selector, randomize, ...(randomize ? { seed: base.selector.seed ?? EDGE_SHUFFLE_SEED } : {}) },+ };+ }+ const own = presetReach(base);+ if (slot.distance! > 0 && own > 0) {+ const k = Math.min(EDGE_DISTANCE_MAX, slot.distance!) / own;+ const scaled = (props: MotionPreset["animate"]): MotionPreset["animate"] =>+ props.position+ ? { ...props, position: props.position.map((key) => ({ ...key, v: [key.v[0] * k, key.v[1] * k] as [number, number] })) }+ : props;+ preset = {+ ...preset,+ animate: scaled(preset.animate),+ ...(preset.animateOut ? { animateOut: scaled(preset.animateOut) } : {}),+ };+ }+ if (slot.ease || slot.fade === false) {+ const curve = slot.ease ? EASE_BEZIER[slot.ease] : undefined;+ const reshaped = (props: MotionPreset["animate"]): MotionPreset["animate"] => {+ const next = { ...props };+ if (curve && next.position)+ next.position = next.position.map((key, k, all) => (k < all.length - 1 ? { ...key, ease: curve } : key));+ if (slot.fade === false) delete next.opacity;+ return next;+ };+ preset = {+ ...preset,+ animate: reshaped(preset.animate),+ ...(preset.animateOut ? { animateOut: reshaped(preset.animateOut) } : {}),+ };+ }+ return preset;+}export const loopMotion = (slot: OverlayLoop | undefined): MotionPreset | undefined =>slot ? (slot.preset ?? loopPreset(slot.style)) : undefined;@@ -279,10 +395,16 @@ export const LOOP_PERIODS = Object.fromEntries(export const OVERLAY_ANIM_MIN_SECONDS = 0.1;export const OVERLAY_ANIM_MAX_SECONDS = 2;export const OVERLAY_ANIM_DEFAULT_SECONDS = 0.5;--/** The longest ramp a style may run: its own cap, else the shared one. */-export const edgeMaxSeconds = (style: string | undefined): number =>- (style ? edgePreset(style)?.maxSeconds : undefined) ?? OVERLAY_ANIM_MAX_SECONDS;+/** A per-letter ramp hands its motion along a whole line, so it may run+ * longer: a long title landing a letter at a time takes a few seconds. */+export const OVERLAY_GLYPH_ANIM_MAX_SECONDS = 4;++/** The longest ramp a style may run: its own cap, else the per-letter one,+ * else the shared one. */+export const edgeMaxSeconds = (style: string | undefined): number => {+ const preset = style ? edgePreset(style) : undefined;+ return preset?.maxSeconds ?? (preset?.selector ? OVERLAY_GLYPH_ANIM_MAX_SECONDS : OVERLAY_ANIM_MAX_SECONDS);+};/** The most of a ramp the letter hand-off may take: at 1 each letter would* get no time of its own to move. */@@ -356,6 +478,13 @@ export interface GlyphPhase {exiting: boolean;/** The slot's own hand-off, over the style's (see `OverlayEdge.stagger`). */stagger?: number;+ /** The ramp's length, seconds. */+ seconds?: number;+ /** The share of the ramp the shutter stays open, when the element wears+ * motion blur: each letter then streaks along its own move. */+ exposure?: number;+ /** The element's shutter, frames (caps the streak's length). */+ shutter?: number;}/** Where a per-glyph loop stands: one number, 0 to 1 around the cycle. Each@@ -423,6 +552,9 @@ export interface GlyphAnimState {/** How far a red and a cyan copy pull apart either side, design px; absent* = one copy. */split?: number;+ /** The motion blur streak: how far the letter travels while the shutter+ * is open, design px, centered on this moment. Absent = sharp. */+ streak?: { x: number; y: number };}const IDLE: OverlayAnimState = { dx: 0, dy: 0, scale: 1, rotate: 0, alpha: 1 };@@ -462,7 +594,20 @@ export function glyphAnimAt(phase: GlyphPhase, index: number, count: number): Gl// whole-element style leaves its glyphs where they are.if (!preset?.selector) return GLYPH_IDLE;const n = Math.max(1, count);- return asGlyph(evalPreset(preset, p, index, n, exiting, 0, phase.stagger), index, n);+ const at = (q: number) => asGlyph(evalPreset(preset, q, index, n, exiting, 0, phase.stagger), index, n);+ const g = at(p);+ const e = phase.exposure ?? 0;+ if (!(e > 0)) return g;+ // The letter's travel over the part of the exposure inside the ramp,+ // scaled to the whole exposure, the way an element's own streak is.+ const p0 = Math.max(0, p - e / 2);+ const p1 = Math.min(1, p + e / 2);+ if (p1 - p0 < 1e-6) return g;+ const a = at(p0);+ const b = at(p1);+ const k = e / (p1 - p0);+ const streak = capStreak((b.dx - a.dx) * k, (b.dy - a.dy) * k, phase.shutter ?? 1);+ return streak ? { ...g, streak } : g;}/** Where character `index` of `count` sits with everything applied — the edge@@ -492,6 +637,7 @@ export function glyphStateAt(...(roll ? { roll } : {}),...(blur ? { blur } : {}),...(split ? { split } : {}),+ ...(ramp.streak ? { streak: ramp.streak } : {}),};}@@ -511,7 +657,8 @@ function edgeState(slot: OverlayEdge,p: number,exiting: boolean,- isText: boolean+ isText: boolean,+ seconds: number): OverlayAnimState {const preset = edgeMotion(slot);if (!preset) return { ...IDLE };@@ -519,7 +666,14 @@ function edgeState(if (preset.selector && isText)return {...IDLE,- glyphs: { style: slot.style, preset: slot.preset, p: clamped, exiting, ...(slot.stagger !== undefined ? { stagger: slot.stagger } : {}) },+ glyphs: {+ style: slot.style,+ preset,+ p: clamped,+ exiting,+ seconds,+ ...(slot.stagger !== undefined ? { stagger: slot.stagger } : {}),+ },};// Anything with no characters to hand the motion to plays it once over the// whole box.@@ -583,9 +737,9 @@ export function evalOverlayAnim(const outSecs = anim.out ? Math.min(anim.out.seconds, Math.max(0, dur - inSecs)) : 0;if (anim.in && tLocal < inSecs) {- state = edgeState(anim.in, tLocal / inSecs, false, isText);+ state = edgeState(anim.in, tLocal / inSecs, false, isText, inSecs);} else if (anim.out && tLocal > dur - outSecs) {- state = edgeState(anim.out, (dur - tLocal) / outSecs, true, isText);+ state = edgeState(anim.out, (dur - tLocal) / outSecs, true, isText, outSecs);}if (anim.loop) {diff --git a/site/packages/effects-kit/src/ease.ts b/site/packages/effects-kit/src/ease.tsindex 4857f3b3..fcc25ad1 100644--- a/site/packages/effects-kit/src/ease.ts+++ b/site/packages/effects-kit/src/ease.ts@@ -37,6 +37,21 @@ export const EASE_LABELS: Record<EaseId, string> = {"power3.inOut": "Power3 in-out",};+/** Each ease as cubic bezier handles, for keyframe tracks that time+ * themselves with handles rather than by name (motion presets). */+export const EASE_BEZIER: Record<EaseId, [number, number, number, number]> = {+ linear: [0, 0, 1, 1],+ "sine.in": [0.12, 0, 0.39, 0],+ "sine.out": [0.61, 1, 0.88, 1],+ "sine.inOut": [0.37, 0, 0.63, 1],+ "power2.in": [0.11, 0, 0.5, 0],+ "power2.out": [0.5, 1, 0.89, 1],+ "power2.inOut": [0.45, 0, 0.55, 1],+ "power3.in": [0.32, 0, 0.67, 0],+ "power3.out": [0.33, 1, 0.68, 1],+ "power3.inOut": [0.65, 0, 0.35, 1],+};+export const isEaseId = (v: unknown): v is EaseId => EASE_IDS.includes(v as EaseId);/** Progress `p` (0..1) through the named curve. Every curve starts at 0 anddiff --git a/site/packages/effects-kit/src/edgeShape.test.ts b/site/packages/effects-kit/src/edgeShape.test.tsnew file mode 100644index 00000000..f14f6f63--- /dev/null+++ b/site/packages/effects-kit/src/edgeShape.test.ts@@ -0,0 +1,199 @@+import { describe, expect, test } from "bun:test";+import { Canvas } from "skia-canvas";+import { paintElement, type RenderEnv } from "./render";+import type { TextOverlay } from "./types";+import { edgeMaxSeconds, edgeMotion, evalOverlayAnim, glyphStateAt, OVERLAY_ANIM_MAX_SECONDS, type OverlayEdge } from "./anim";+import { evalOverlayFrame } from "./keys";+import { presetExtent } from "./motion/evaluate";++// "YOUR LOCATION" dropping in over 2.4s, its letters falling from high above.+const TEXT = "YOUR LOCATION";+const N = [...TEXT].length;++/** The moment letter `i` first shows, in seconds. */+function firstShow(edge: OverlayEdge, i: number): number {+ for (let t = 0; t <= edge.seconds; t += 1 / 120) {+ const g = glyphStateAt(evalOverlayAnim({ in: edge }, t, 6, true), i, N);+ if (g.alpha > 0.001) return t;+ }+ return Infinity;+}++describe("an edge's letter order", () => {+ test("shuffle deals the letters their turns out of reading order", () => {+ const edge: OverlayEdge = { style: "drop", seconds: 2.4, stagger: 0.8, order: "shuffle" };+ const starts = [...Array(N).keys()].map((i) => firstShow(edge, i));+ const ranked = [...starts.keys()].sort((a, b) => starts[a] - starts[b]);+ expect(ranked).not.toEqual([...Array(N).keys()]);+ // Still one at a time, evenly spaced across the hand-off.+ const sorted = [...starts].sort((a, b) => a - b);+ for (let i = 1; i < N; i++) expect(sorted[i] - sorted[i - 1]).toBeGreaterThan(0.1);+ });++ test("absent, the letters go in reading order", () => {+ const edge: OverlayEdge = { style: "drop", seconds: 2.4, stagger: 0.8 };+ const starts = [...Array(N).keys()].map((i) => firstShow(edge, i));+ for (let i = 1; i < N; i++) expect(starts[i]).toBeGreaterThan(starts[i - 1]);+ });+});++describe("an edge's distance", () => {+ test("a letter starts that far from rest, and the crop pads for it", () => {+ const edge: OverlayEdge = { style: "drop", seconds: 2, distance: 500 };+ const g = glyphStateAt(evalOverlayAnim({ in: edge }, 0, 6, true), 0, N);+ expect(g.dy).toBeCloseTo(-500, 0);+ expect(presetExtent(edgeMotion(edge)!).travel).toBeGreaterThanOrEqual(500);+ // Absent, the style's own reach.+ const own = glyphStateAt(evalOverlayAnim({ in: { style: "drop", seconds: 2 } }, 0, 6, true), 0, N);+ expect(own.dy).toBeCloseTo(-46, 0);+ });+});++describe("a per-letter ramp's length", () => {+ test("runs past the shared cap, so a long title can land letter by letter", () => {+ expect(edgeMaxSeconds("drop")).toBeGreaterThan(OVERLAY_ANIM_MAX_SECONDS);+ expect(edgeMaxSeconds("fade")).toBe(OVERLAY_ANIM_MAX_SECONDS);+ });+});++describe("a falling letter's motion blur", () => {+ const title = {+ kind: "text" as const,+ text: TEXT,+ start: 0,+ end: 6,+ x: 0.5,+ y: 0.5,+ anim: { in: { style: "drop" as const, seconds: 2, stagger: 0.5, distance: 500 } },+ };++ test("with the element's motion blur on, a moving letter streaks along its own fall", () => {+ const st = evalOverlayFrame({ ...title, motionBlur: 1 } as never, 0.3, 16 / 9);+ const moving = [...Array(N).keys()].map((i) => glyphStateAt(st, i, N)).find((g) => g.alpha > 0.1 && g.dy < -20);+ expect(moving?.streak).toBeDefined();+ expect(Math.abs(moving!.streak!.y)).toBeGreaterThan(5);+ expect(Math.abs(moving!.streak!.x)).toBeLessThan(1);+ // The element itself never moves, so it carries no streak of its own.+ expect(st.streak).toBeUndefined();+ });++ test("a letter at rest, or a title without motion blur, draws sharp", () => {+ const off = evalOverlayFrame(title as never, 0.3, 16 / 9);+ for (let i = 0; i < N; i++) expect(glyphStateAt(off, i, N).streak).toBeUndefined();+ const landed = evalOverlayFrame({ ...title, motionBlur: 1 } as never, 4, 16 / 9);+ for (let i = 0; i < N; i++) expect(glyphStateAt(landed, i, N).streak).toBeUndefined();+ });+});++describe("the export's frame slices", () => {+ test("carry the slot's order, reach and per-letter streak, as the preview plays them", async () => {+ const { planAnimatedLayers } = await import("./render");+ const o = {+ id: "t",+ kind: "text",+ text: TEXT,+ start: 0,+ end: 6,+ x: 0.5,+ y: 0.5,+ size: 200,+ color: "#ff0000",+ font: "bebas",+ motionBlur: 1,+ anim: { in: { style: "drop", seconds: 2, stagger: 0.8, order: "shuffle", distance: 500 } },+ };+ const layers = planAnimatedLayers(o as never, 6);+ const mid = layers.find((l) => l.phase?.glyphs && l.start >= 0.5)!;+ const live = evalOverlayFrame(o as never, mid.start, 16 / 9);+ for (let i = 0; i < N; i++) {+ const baked = glyphStateAt(mid.phase!, i, N);+ const shown = glyphStateAt(live, i, N);+ expect(baked.dy).toBeCloseTo(shown.dy, 3);+ expect(baked.streak?.y ?? 0).toBeCloseTo(shown.streak?.y ?? 0, 3);+ }+ expect([...Array(N).keys()].some((i) => glyphStateAt(mid.phase!, i, N).streak)).toBe(true);+ });+});++const env: RenderEnv = {+ fontStack: () => "Arial",+ createCanvas: (w, h) => new Canvas(w, h) as unknown as HTMLCanvasElement,+ canvasToPngBlob: async (c) => new Blob([new Uint8Array(await (c as unknown as Canvas).toBuffer("png"))]),+};++describe("a falling letter on canvas", () => {+ test("smears along its fall under motion blur, and keeps its ink", async () => {+ const o: TextOverlay = { id: "t", text: "I", start: 0, end: 4, x: 0.5, y: 0.5, size: 200, font: "sf", weight: 700, color: "#ff0000", plate: false, shadow: false, anim: { in: { style: "drop", seconds: 1, distance: 400 } } };+ const paint = async (motionBlur?: number) => {+ const el = { ...o, ...(motionBlur ? { motionBlur } : {}) };+ const st = evalOverlayFrame(el as never, 0.2, 1);+ const c = new Canvas(1080, 1080);+ const ctx = c.getContext("2d") as unknown as CanvasRenderingContext2D;+ await paintElement(ctx, el, { width: 1080, height: 1080, scale: 1, phase: { glyphs: st.glyphs } }, env);+ const d = ctx.getImageData(0, 0, 1080, 1080).data;+ // The ink's rows, and its total coverage.+ let top = 1080;+ let bottom = 0;+ let ink = 0;+ for (let y = 0; y < 1080; y++)+ for (let x = 500; x < 580; x++) {+ const a = d[(y * 1080 + x) * 4 + 3];+ ink += a;+ if (a > 8) {+ top = Math.min(top, y);+ bottom = Math.max(bottom, y);+ }+ }+ return { h: bottom - top, ink };+ };+ const sharp = await paint();+ const blurred = await paint(1);+ expect(blurred.h).toBeGreaterThan(sharp.h + 10);+ // Averaged, not stacked: the smear spreads the same ink.+ expect(blurred.ink / sharp.ink).toBeGreaterThan(0.9);+ expect(blurred.ink / sharp.ink).toBeLessThan(1.1);+ });+});++describe("an order read off a reference", () => {+ test("letters land in the sequence named, spaces skipped, the last as the ramp ends", () => {+ const { letterSequence } = require("./anim") as typeof import("./anim");+ // O (of LOCATION) first, then L, C, A, T, … Y and N last.+ const letters = [5, 4, 6, 7, 8, 2, 9, 3, 10, 1, 0, 11];+ const order = letterSequence(TEXT, letters);+ expect(order[0]).toBe(6); // the space before LOCATION takes index 4+ const edge: OverlayEdge = { style: "drop", seconds: 2.4, stagger: 0.7, order };+ const starts = order.map((i) => firstShow(edge, i));+ for (let k = 1; k < starts.length; k++) expect(starts[k]).toBeGreaterThan(starts[k - 1]);+ // The last named letter starts its own move at the hand-off's end.+ expect(starts[starts.length - 1]).toBeCloseTo(0.7 * 2.4, 1);+ // An exit sweeps them out in the order they came in, as reading order does.+ const out = (i: number) => {+ for (let t = 0; t <= 2.4; t += 1 / 120) {+ const g = glyphStateAt(evalOverlayAnim({ out: edge }, 6 - 2.4 + t, 6, true), i, N);+ if (g.alpha < 0.999) return t;+ }+ return Infinity;+ };+ expect(out(order[0])).toBeLessThan(out(order[1]));+ expect(out(order[1])).toBeLessThan(out(order[order.length - 1]));+ });+});++describe("an edge's ease and fade", () => {+ const at = (edge: OverlayEdge, t: number) => glyphStateAt(evalOverlayAnim({ in: edge }, t, 6, true), 0, 1);++ test("a named ease replaces the style's own curve on its move", () => {+ const edge: OverlayEdge = { style: "drop", seconds: 1, stagger: 0, distance: 600, ease: "linear" };+ // Halfway through a linear fall, halfway down.+ expect(at(edge, 0.5).dy).toBeCloseTo(-300, 0);+ // The style's own curve is well past halfway by then.+ expect(at({ ...edge, ease: undefined }, 0.5).dy).toBeGreaterThan(-200);+ });++ test("fade off keeps a letter solid the whole way in", () => {+ const edge: OverlayEdge = { style: "drop", seconds: 1, stagger: 0, distance: 600, fade: false };+ expect(at(edge, 0.05).alpha).toBe(1);+ expect(at({ ...edge, fade: undefined }, 0.05).alpha).toBeLessThan(0.2);+ });+});diff --git a/site/packages/effects-kit/src/keys.ts b/site/packages/effects-kit/src/keys.tsindex 19d3d61a..b2848b9f 100644--- a/site/packages/effects-kit/src/keys.ts+++ b/site/packages/effects-kit/src/keys.ts@@ -359,12 +359,18 @@ export function evalOverlayFrame(o: Posable, tLocal: number, aspect?: number): Oif (!aspect || !Number.isFinite(aspect)) {throw new Error("A camera or motion blur needs the frame's aspect to evaluate.");}- const placed = cam ? composeCamera(own, cameraAt(cam, tLocal), aspect) : own;+ let placed = cam ? composeCamera(own, cameraAt(cam, tLocal), aspect) : own;if (!shutter) return placed;// The element's own motion blur streaks its whole move on screen; the// camera's streaks only what the camera does, with the element held still.const whole = !!o.motionBlur;const exposure = shutter * MOTION_BLUR_FRAME;+ // Letters on a per-letter ramp carry their own moves, so each one streaks+ // along its own: the glyph evaluator reads the shutter as a share of the+ // ramp.+ const ramp = placed.glyphs;+ if (whole && ramp?.seconds)+ placed = { ...placed, glyphs: { ...ramp, exposure: exposure / ramp.seconds, shutter } };const dur = Math.max(0.1, o.end - o.start);const t0 = Math.max(0, tLocal - exposure / 2);const t1 = Math.min(dur, tLocal + exposure / 2);diff --git a/site/packages/effects-kit/src/motion/evaluate.ts b/site/packages/effects-kit/src/motion/evaluate.tsindex 4f574cd0..3607ba84 100644--- a/site/packages/effects-kit/src/motion/evaluate.ts+++ b/site/packages/effects-kit/src/motion/evaluate.ts@@ -161,6 +161,12 @@ function flickered(pose: MotionPose, q: number, index: number): MotionPose {/** Where unit `i` sits in the hand-off order, 0 at the front. */function orderOf(sel: RangeSelector, i: number, n: number): number {if (n <= 1) return 0;+ if (sel.sequence?.length) {+ const at = sel.sequence.indexOf(i);+ if (at >= 0) return at;+ // The rest follow in reading order.+ return sel.sequence.length + [...Array(i).keys()].filter((j) => !sel.sequence!.includes(j)).length;+ }if (sel.randomize) {// Rank by the unit's own draw: a stable shuffle that needs no array.const mine = draw(sel.seed ?? 1, i);@@ -183,9 +189,18 @@ function orderOf(sel: RangeSelector, i: number, n: number): number {/** The share of the window unit `i` starts at. `square` gives every unit its* own slot with no overlap; the ramps and curves overlap by `spread`. */-function startShare(sel: RangeSelector, i: number, n: number, share = sel.spread): number {+function startShare(sel: RangeSelector, i: number, n: number, share = sel.spread, reverse = false): number {if (n <= 1) return 0;- const o = orderOf(sel, i, n);+ let o = orderOf(sel, i, n);+ if (sel.sequence?.length) {+ // A sequence hands the motion along the units it names, so the last of+ // them lands as the ramp ends; any it leaves out (a space) go with the+ // last. An exit sweeps them out in the order they came in, the way a+ // reading-order exit does.+ n = Math.max(2, sel.sequence.length);+ o = Math.min(o, n - 1);+ if (reverse) o = n - 1 - o;+ }const spread = clamp01(share);if (sel.shape === "square") return o / n;const u = o / (n - 1);@@ -216,9 +231,11 @@ export function selectorProgress(): number {const n = Math.max(1, count);// An exit sweeps out the way it came in, so the order reverses.- const i = exiting ? n - 1 - index : index;- const from = startShare(sel, i, n, spread);- const window = sel.shape === "square" ? 1 / n : Math.max(1e-6, 1 - clamp01(spread));+ const listed = !!sel.sequence?.length;+ const i = exiting && !listed ? n - 1 - index : index;+ const from = startShare(sel, i, n, spread, exiting && listed);+ const slots = listed ? Math.max(2, sel.sequence!.length) : n;+ const window = sel.shape === "square" ? 1 / slots : Math.max(1e-6, 1 - clamp01(spread));let q = clamp01((clamp01(p) - from) / window);if (sel.easeHigh) q = lerp(q, bezierEase([0.42, 0, 1, 1], q), clamp01(sel.easeHigh));if (sel.easeLow) q = lerp(q, bezierEase([0, 0, 0.58, 1], q), clamp01(sel.easeLow));diff --git a/site/packages/effects-kit/src/motion/types.ts b/site/packages/effects-kit/src/motion/types.tsindex 0574b5a3..b33a9c89 100644--- a/site/packages/effects-kit/src/motion/types.ts+++ b/site/packages/effects-kit/src/motion/types.ts@@ -110,6 +110,9 @@ export interface RangeSelector {* order — After Effects' Randomize Order. */randomize?: boolean;seed?: number;+ /** The units in the order they take their turns, by index: an order read+ * off a reference. Units it leaves out go after it, in reading order. */+ sequence?: number[];}/**diff --git a/site/packages/effects-kit/src/render.ts b/site/packages/effects-kit/src/render.tsindex b559b26c..c4a966ef 100644--- a/site/packages/effects-kit/src/render.ts+++ b/site/packages/effects-kit/src/render.ts@@ -32,8 +32,8 @@ import { cutAtFaces, cycleFaceTag, fontCycleCuts, fontCycleVariants, withFontCycimport { evalWhole, presetExtent } from "./motion/evaluate";import { countStep, countText } from "./count";import { evalOverlayFrame, hasOverlayKeys, poseAt, poseExtent, sortedKeys, type OverlayFrameState } from "./keys";-import { ELEMENT_BLUR_MAX, hasCameraKeys, streakCap } from "./camera";-import { ElementFx, elementLook } from "./elementFx";+import { ELEMENT_BLUR_MAX, hasCameraKeys, MOTION_BLUR_FRAME, streakCap, streakTaps } from "./camera";+import { drawStreak, ElementFx, elementLook } from "./elementFx";import { applyMaskToCanvas, isMaskAnimated } from "./mask";import { tracePolyShape } from "./shapePath";import { paintPattern } from "./pattern";@@ -761,30 +761,32 @@ async function paintText(// Outline behind the fill: stroke first, then fill over it — the same order// the DOM pair (-webkit-text-stroke + paint-order: stroke fill) paints.const strokeW = (overlay.stroke?.width ?? 0) * fpx;- const drawText = (text: string, x: number, y: number, fill: string = overlay.color) => {+ // `on` is where the type lands: the frame, or a streaking letter's own+ // picture.+ const drawText = (text: string, x: number, y: number, fill: string = overlay.color, on = ctx) => {if (overlay.stroke && strokeW > 0) {- ctx.lineJoin = "round";+ on.lineJoin = "round";// In em of whatever size is set, so a resized word wears the same// outline weight as the words beside it.- ctx.lineWidth = (strokeW / fpx) * drawSize * 2; // half of a centered stroke shows behind the fill- ctx.strokeStyle = overlay.stroke.color;- ctx.strokeText(text, x, y);+ on.lineWidth = (strokeW / fpx) * drawSize * 2; // half of a centered stroke shows behind the fill+ on.strokeStyle = overlay.stroke.color;+ on.strokeText(text, x, y);}- ctx.fillStyle = fill;- ctx.fillText(text, x, y);+ on.fillStyle = fill;+ on.fillText(text, x, y);};// A glitching letter's channel copies: the same outline and fill in one// tint, so a hollow title tears into hollow copies.- const drawTinted = (text: string, x: number, y: number, tint: string) => {+ const drawTinted = (text: string, x: number, y: number, tint: string, on = ctx) => {if (overlay.stroke && strokeW > 0) {- ctx.lineJoin = "round";- ctx.lineWidth = (strokeW / fpx) * drawSize * 2;- ctx.strokeStyle = tint;- ctx.strokeText(text, x, y);+ on.lineJoin = "round";+ on.lineWidth = (strokeW / fpx) * drawSize * 2;+ on.strokeStyle = tint;+ on.strokeText(text, x, y);}if (!isInkless(overlay.color)) {- ctx.fillStyle = tint;- ctx.fillText(text, x, y);+ on.fillStyle = tint;+ on.fillText(text, x, y);}};@@ -840,6 +842,72 @@ async function paintText(ctx.fillRect(right + CARET_GAP_EM * fpx, y + off - h / 2, Math.max(2 * scale, CARET_WIDTH_EM * fpx), h);ctx.restore();};+ // A streaking letter's two scratches: its picture, and the smear the taps+ // add up in. Made on the first streak and reused for every letter after.+ let glyphPic: HTMLCanvasElement | null = null;+ let glyphSmear: HTMLCanvasElement | null = null;+ const smearGlyph = (+ streak: { x: number; y: number },+ placed: DOMMatrix,+ w: number,+ paint: (on: CanvasRenderingContext2D) => void+ ) => {+ // The streak in the target's own pixels.+ const sx = (placed.a * streak.x + placed.c * streak.y) * scale;+ const sy = (placed.b * streak.x + placed.d * streak.y) * scale;+ // Room for the letter at any turn or stretch it is drawn at, its outline+ // and its shadow.+ const shadowPad = shadow ? (shadow.blur + Math.abs(shadow.offsetY)) * scale : 0;+ const zoom = Math.max(Math.hypot(placed.a, placed.b), Math.hypot(placed.c, placed.d));+ const half = Math.ceil((Math.max(w, lineH) * 1.5 + strokeW + shadowPad + 4) * zoom);+ const pw = 2 * half;+ const mw = pw + Math.ceil(Math.abs(sx));+ const mh = pw + Math.ceil(Math.abs(sy));+ glyphPic ??= newCanvas(env, pw, pw);+ glyphSmear ??= newCanvas(env, mw, mh);+ if (glyphPic.width !== pw || glyphPic.height !== pw) {+ glyphPic.width = pw;+ glyphPic.height = pw;+ }+ if (glyphSmear.width < mw || glyphSmear.height < mh) {+ glyphSmear.width = Math.max(glyphSmear.width, mw);+ glyphSmear.height = Math.max(glyphSmear.height, mh);+ }+ // The letter, posed as the frame would pose it, at the picture's middle.+ const pic = glyphPic.getContext("2d")!;+ pic.setTransform(1, 0, 0, 1, 0, 0);+ pic.clearRect(0, 0, pw, pw);+ pic.font = ctx.font;+ if ("letterSpacing" in pic) pic.letterSpacing = (ctx as CanvasRenderingContext2D & { letterSpacing: string }).letterSpacing;+ pic.textAlign = ctx.textAlign;+ pic.textBaseline = ctx.textBaseline;+ pic.filter = ctx.filter;+ pic.shadowColor = ctx.shadowColor;+ pic.shadowBlur = ctx.shadowBlur;+ pic.shadowOffsetY = ctx.shadowOffsetY;+ const m = ctx.getTransform();+ // Turn and stretch carry over; the frame's own placement does not.+ pic.setTransform(m.a, m.b, m.c, m.d, half, half);+ paint(pic);+ // The taps add up into the smear, so the streak averages the letter's+ // positions the way the element's own streak does.+ const smear = glyphSmear.getContext("2d")!;+ smear.setTransform(1, 0, 0, 1, 0, 0);+ smear.clearRect(0, 0, glyphSmear.width, glyphSmear.height);+ drawStreak(smear, glyphPic, (mw - pw) / 2, (mh - pw) / 2, {+ streakX: sx,+ streakY: sy,+ taps: streakTaps(Math.hypot(streak.x, streak.y)),+ });+ // Back at the letter's place, untransformed: the picture already wears+ // its turn and stretch.+ ctx.save();+ ctx.setTransform(1, 0, 0, 1, 0, 0);+ ctx.filter = "none";+ ctx.shadowColor = "transparent";+ ctx.drawImage(glyphSmear, 0, 0, mw, mh, placed.e - mw / 2, placed.f - mh / 2, mw, mh);+ ctx.restore();+ };if ((phase && hasGlyphMotion(phase)) || (texture && !draws)) {// A per-glyph ramp or loop draws character by character, each at its own// place in the motion. The index counts through the whole element, line@@ -875,6 +943,9 @@ async function paintText(ctx.save();ctx.globalAlpha = alpha0 * Math.min(1, Math.max(0, g.alpha));ctx.translate(x + w / 2 + g.dx * scale, y + g.dy * scale);+ // Where the letter sits before its own turn and stretch: its streak+ // runs in this space, since the move is an offset, not a turn.+ const placed = g.streak ? ctx.getTransform() : null;if (g.rotate) ctx.rotate((g.rotate * Math.PI) / 180);ctx.scale(g.sx, g.sy);if (g.blur && "filter" in ctx) {@@ -882,6 +953,21 @@ async function paintText(const own = ctx.filter && ctx.filter !== "none" ? `${ctx.filter} ` : "";ctx.filter = `${own}blur(${(g.blur * scale).toFixed(2)}px)`;}+ if (placed && g.streak && !g.roll) {+ // A letter in flight under motion blur: painted once into its own+ // picture, smeared along its streak, then laid down whole.+ smearGlyph(g.streak, placed, w, (on) => {+ if (g.split) {+ const off = g.split * scale;+ drawTinted(ch, -off, drop, SPLIT_RED, on);+ drawTinted(ch, off, drop, SPLIT_CYAN, on);+ }+ drawText(ch, 0, drop, overlay.color, on);+ });+ ctx.restore();+ x += w;+ return;+ }if (g.split) {const off = g.split * scale;drawTinted(ch, -off, drop, SPLIT_RED);@@ -1741,10 +1827,14 @@ export function planAnimatedLayers(o: Overlay, end: number): AnimatedLayer[] {push(o, at, to, rest, lit({glyphs: {style: edge.style,- preset: edge.preset,+ // The slot's own order and reach, as the preview plays them.+ preset,p,exiting: slot === "out",+ seconds: secs,...(edge.stagger !== undefined ? { stagger: edge.stagger } : {}),+ // Under motion blur each letter streaks along its own move.+ ...(o.motionBlur ? { exposure: (o.motionBlur * MOTION_BLUR_FRAME) / secs, shutter: o.motionBlur } : {}),},}, at, to));} else if (preset?.animate.erode) {diff --git a/site/src/cut/components/AnimationTiles.tools.ts b/site/src/cut/components/AnimationTiles.tools.tsindex c0516422..a11cba71 100644--- a/site/src/cut/components/AnimationTiles.tools.ts+++ b/site/src/cut/components/AnimationTiles.tools.ts@@ -27,6 +27,9 @@ import {OVERLAY_HIT_STYLE_IDS,OVERLAY_ANIM_DEFAULT_SECONDS,OVERLAY_ANIM_MAX_SECONDS,+ OVERLAY_GLYPH_ANIM_MAX_SECONDS,+ EDGE_DISTANCE_MAX,+ EDGE_ORDERS,edgeMaxSeconds,OVERLAY_ANIM_MIN_SECONDS,GLYPH_ANIM_STYLE_IDS,@@ -53,9 +56,12 @@ import {} from "@/cut/lib/textMotion";// Styles that may run past the shared cap say how far, e.g. "; count up to 10".-const LONG_RAMPS = OVERLAY_ANIM_STYLE_IDS.filter((id) => edgeMaxSeconds(id) !== OVERLAY_ANIM_MAX_SECONDS)- .map((id) => `; ${id} up to ${edgeMaxSeconds(id)}`)- .join("");+const LONG_RAMPS =+ OVERLAY_ANIM_STYLE_IDS.filter(+ (id) => edgeMaxSeconds(id) !== OVERLAY_ANIM_MAX_SECONDS && edgeMaxSeconds(id) !== OVERLAY_GLYPH_ANIM_MAX_SECONDS+ )+ .map((id) => `; ${id} up to ${edgeMaxSeconds(id)}`)+ .join("") + `; the per-letter styles up to ${OVERLAY_GLYPH_ANIM_MAX_SECONDS}`;const RAMP_SECONDS = `${OVERLAY_ANIM_MIN_SECONDS}..${OVERLAY_ANIM_MAX_SECONDS} (default ${OVERLAY_ANIM_DEFAULT_SECONDS}${LONG_RAMPS})`;/** The loop rate multiplier's range: at the top a spin turns twice a second,@@ -70,7 +76,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; ${TEXT_ONLY_ANIM_STYLE_IDS.join(", ")} animate titles only; ${GLYPH_ANIM_STYLE_IDS.join(", ")} move a title's letters one at a time, and move any other kind as one piece; in_stagger/out_stagger set how much of their ramp the hand-off from the first letter to the last takes, so a 1.6s drop at stagger 0.8 lands a letter every ~0.27s, each moving for ~0.3s. ${edgeNotes()} ${DIVE_ANIM_STYLE_IDS.join(", ")} as the exit is the zoom-through-a-letter transition: the shot after the element shows once the ink has filled the frame, so it needs no freeze frames, image stills or per-letter keyframes. 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; set_overlay_keyframes is the precise way to move an element and the default reach, so name a move when it is exactly what you mean — the two compose together. Word effects — words_style, titles only — play the line word by word, timed against the cut's transcript when there is one and spread across the element's own span when there is not: an emphasis travels along a line that is fully up, and a build assembles the line as it is spoken. It is the slot for "make each word pop as I say it" and for "have the words appear one by one". A typewriter entrance on a title can carry a caret: a thin bar at the end of the typed text, solid while it types, then blinking every ${CARET_BLINK_SECONDS}s — the typed comment or search box of a call-to-action card. A hit plays one motion once at a moment inside the element (hit_at seconds from its start), between its entrance and exit: ${hitNotes()}. Use press for a button being pressed, a tap on a UI element, a like or post button; pair it with a click from stock_search kind "sound" placed at the same moment when the tap should be heard. A font cycle flickers a title through typefaces — a new face font_cycle_rate times a second, from font_cycle_at for font_cycle_seconds — and then the title settles back into its own face: the typeface-shuffle beat of a teaser title. Give each face a scale (and tracking) so it fills about the room the title's own face does; a wide tracked title cycling through condensed or hand-drawn faces wants tracking 0 and a scale above 1 on them. A face keeps the title's own line breaks: where its scale makes a line wider than the room the title wraps in, that face is set smaller to fit rather than broken onto another line. Time the faces to the music with font_cycle_beats — a new face on each beat of that clip's detect_beats grid, font_cycle_beat_step 2 for every other beat or 0.5 for half beats — or to a reference's own face changes with font_cycle_switches, the timeline seconds you read them at; either sets every hold and repeats the faces in order to fill the run. A face's own hold times one face by hand; faces repeat in the list to revisit a typeface.`,+ `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; ${TEXT_ONLY_ANIM_STYLE_IDS.join(", ")} animate titles only; ${GLYPH_ANIM_STYLE_IDS.join(", ")} move a title's letters one at a time, and move any other kind as one piece; in_stagger/out_stagger set how much of their ramp the hand-off from the first letter to the last takes, so a 1.6s drop at stagger 0.8 lands a letter every ~0.27s, each moving for ~0.3s. in_order/out_order "shuffle" deals the letters their turns in a scattered order instead of left to right — letters landing at random; in_sequence names the exact order when it is read off a reference. in_ease sets the curve the move travels on and in_fade false keeps letters solid while they fall, both read off how a letter in flight looks. A ramp's timing comes from two reads: how long ONE letter takes from first showing to settling (its own move: track_element match ink within a tall strip over that letter's column), and the span from the first letter's start to the last one's — in_seconds is that span plus one letter's move, and in_stagger is the span over in_seconds. in_distance/out_distance set how far the motion travels from rest, design px: a letter falling from above the frame drops the distance from where track_element first sees it to where it lands. A per-letter ramp on an element with update_overlay motion_blur streaks each letter along its own move, the smear a fast fall wears. ${edgeNotes()} ${DIVE_ANIM_STYLE_IDS.join(", ")} as the exit is the zoom-through-a-letter transition: the shot after the element shows once the ink has filled the frame, so it needs no freeze frames, image stills or per-letter keyframes. 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; set_overlay_keyframes is the precise way to move an element and the default reach, so name a move when it is exactly what you mean — the two compose together. Word effects — words_style, titles only — play the line word by word, timed against the cut's transcript when there is one and spread across the element's own span when there is not: an emphasis travels along a line that is fully up, and a build assembles the line as it is spoken. It is the slot for "make each word pop as I say it" and for "have the words appear one by one". A typewriter entrance on a title can carry a caret: a thin bar at the end of the typed text, solid while it types, then blinking every ${CARET_BLINK_SECONDS}s — the typed comment or search box of a call-to-action card. A hit plays one motion once at a moment inside the element (hit_at seconds from its start), between its entrance and exit: ${hitNotes()}. Use press for a button being pressed, a tap on a UI element, a like or post button; pair it with a click from stock_search kind "sound" placed at the same moment when the tap should be heard. A font cycle flickers a title through typefaces — a new face font_cycle_rate times a second, from font_cycle_at for font_cycle_seconds — and then the title settles back into its own face: the typeface-shuffle beat of a teaser title. Give each face a scale (and tracking) so it fills about the room the title's own face does; a wide tracked title cycling through condensed or hand-drawn faces wants tracking 0 and a scale above 1 on them. A face keeps the title's own line breaks: where its scale makes a line wider than the room the title wraps in, that face is set smaller to fit rather than broken onto another line. Time the faces to the music with font_cycle_beats — a new face on each beat of that clip's detect_beats grid, font_cycle_beat_step 2 for every other beat or 0.5 for half beats — or to a reference's own face changes with font_cycle_switches, the timeline seconds you read them at; either sets every hold and repeats the faces in order to fill the run. A face's own hold times one face by hand; faces repeat in the list to revisit a typeface.`,inputSchema: obj({id: str("Overlay element id"),move: {@@ -95,6 +101,29 @@ export const OVERLAY_ANIMATION_TOOLS = [out_seconds: num(`Exit ramp seconds ${RAMP_SECONDS}`),in_stagger: num(`Per-letter entrance: share of the ramp spent handing the motion from the first letter to the last, 0..${EDGE_STAGGER_MAX} (0 = every letter together, higher = one after another, each moving for less of the ramp); a negative restores the style's own`),out_stagger: num(`Per-letter exit: the same hand-off share for the exit ramp, 0..${EDGE_STAGGER_MAX}; a negative restores the style's own`),+ in_order: {+ type: "string",+ enum: [...EDGE_ORDERS],+ description: 'Per-letter entrance: the order the letters take their turns — "reading" (left to right) or "shuffle" (a fixed scattered order)',+ },+ out_order: { type: "string", enum: [...EDGE_ORDERS], description: "Per-letter exit: the same order for the exit ramp" },+ in_sequence: {+ type: "array",+ items: { type: "integer" },+ description:+ "Per-letter entrance in an order read off a reference: the letters' numbers in the order they arrive, counting the title's letters from 0 and skipping spaces (YOUR LOCATION: Y=0 … R=3, L=4 … N=11). Overrides in_order; [] clears it",+ },+ out_sequence: { type: "array", items: { type: "integer" }, description: "Per-letter exit: the letters' numbers in the order they leave; [] clears it" },+ in_ease: {+ type: "string",+ enum: [...EASE_IDS, "style"],+ description: `Entrance: the curve the move travels on — the ease track_element reads for the reference's move (linear for a steady fall, an .out ease for one that brakes into place); "style" restores the style's own`,+ },+ out_ease: { type: "string", enum: [...EASE_IDS, "style"], description: 'Exit: the same curve for the exit ramp; "style" restores the style\'s own' },+ in_fade: bool("Entrance: false keeps the element (each letter) solid the whole way in instead of fading up as it moves — a letter falling in from beyond the frame is solid; true restores the style's fade"),+ out_fade: bool("Exit: false keeps it solid the whole way out; true restores the style's fade"),+ in_distance: num(`Entrance: how far the motion travels from rest at its far end, design px at 1080, 1..${EDGE_DISTANCE_MAX}; 0 restores the style's own reach`),+ out_distance: num(`Exit: the same reach for the exit ramp, design px; 0 restores the style's own`),loop_style: {type: "string",enum: [...OVERLAY_LOOP_STYLE_IDS, "none"],diff --git a/site/src/cut/components/Inspector.tools.ts b/site/src/cut/components/Inspector.tools.tsindex 3645d884..1fed479e 100644--- a/site/src/cut/components/Inspector.tools.ts+++ b/site/src/cut/components/Inspector.tools.ts@@ -371,7 +371,7 @@ export const INSPECTOR_TOOLS = [{name: "detach_audio",description:- "Detach Audio: lift a clip's sound onto the soundtrack track (mutes the clip) so it can be edited independently. Select the clip first or pass its id. Pass assetId instead to put a source's whole track on the soundtrack with none of its picture placed — how a cut blocked out as empty shots carries the reference's sound.",+ "Detach Audio: lift a clip's sound onto the soundtrack track (mutes the clip) so it can be edited independently. Select the clip first or pass its id. Pass assetId instead to put a source's whole track on the soundtrack with none of its picture placed; the clip still plays that source, so a reference that came from a link brings its sound in as its own file instead (import_url audio_only), and the reference stays off the timeline.",inputSchema: obj({clipId: str("Video clip id (optional if one is selected)"),assetId: str("Project asset id — its whole audio track lands on the soundtrack, no clip placed"),diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex d6a311c1..59923de5 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -54,6 +54,13 @@ import {edgeMotion,edgeStagger,EDGE_STAGGER_MAX,+ EDGE_DISTANCE_MAX,+ EASE_IDS,+ EASE_LABELS,+ type EaseId,+ edgeOwnReach,+ edgePreset,+ type OverlayEdge,keepCaret,OVERLAY_HIT_DEFAULT_SECONDS,OVERLAY_HIT_MAX_SECONDS,@@ -3618,6 +3625,20 @@ function AnimationToolbar({ overlay: o, slot, peers }: { overlay: Overlay; slot:ck.begin();writeOverlayAnim(o, anim, { [slot]: { ...edge, stagger: v } }, peers);};+ // The order the letters take their turns, and how far the motion reaches.+ const edgeSequence = Array.isArray(edge?.order) ? edge.order : null;+ const edgeOrder = edgeSequence ? "sequence" : (edge?.order ?? (edgeMotion(edge)?.selector?.randomize ? "shuffle" : "reading"));+ const ownReach = edgeOwnReach(edge);+ const edgeDistance = edge?.distance ?? ownReach;+ const edgeEase = edge?.ease ?? "style";+ // A style that fades as it moves can be told to stay solid.+ const edgeFades = !!(edge && (edge.preset ?? edgePreset(edge.style))?.animate.opacity);+ const edgeFade = edge?.fade !== false;+ const writeEdge = (patch: Partial<OverlayEdge>) => {+ if (!edge) return;+ ck.begin();+ writeOverlayAnim(o, anim, { [slot]: { ...edge, ...patch } }, peers);+ };return bar(<><Row label="Duration">@@ -3661,11 +3682,98 @@ function AnimationToolbar({ overlay: o, slot, peers }: { overlay: Overlay; slot:/></Row>)}+ {stagger !== undefined && (+ <Row label="Shuffle">+ <Switch+ checked={edgeOrder !== "reading"}+ onCheckedChange={(v) => {+ writeEdge({ order: v ? "shuffle" : "reading" });+ ck.end();+ }}+ />+ </Row>+ )}+ {ownReach > 0 && (+ // The curve the move travels on, over the style's own.+ <Row label="Ease">+ <Select+ value={edgeEase}+ items={EDGE_EASE_ITEMS}+ onValueChange={(id) => {+ const rest = { ...edge! };+ delete rest.ease;+ ck.begin();+ writeOverlayAnim(o, anim, { [slot]: id === "style" ? rest : { ...rest, ease: id as EaseId } }, peers);+ ck.end();+ }}+ >+ <SelectTrigger className="h-8 w-36 text-[12px]">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ {Object.entries(EDGE_EASE_ITEMS).map(([id, label]) => (+ <SelectItem key={id} value={id} className="text-[12px]">+ {label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </Row>+ )}+ {edgeFades && (+ <Row label="Fade">+ <Switch+ checked={edgeFade}+ onCheckedChange={(v) => {+ const rest = { ...edge! };+ delete rest.fade;+ ck.begin();+ writeOverlayAnim(o, anim, { [slot]: v ? rest : { ...rest, fade: false } }, peers);+ ck.end();+ }}+ />+ </Row>+ )}+ {edgeSequence && isTextOverlay(o) && (+ // An order read off a reference: the letters as they arrive.+ <Row label="Order">+ <span className="truncate text-xs text-muted-foreground" title="Letters in the order they move">+ {edgeSequence.map((i) => [...o.text][i] ?? "").join(" ")}+ </span>+ </Row>+ )}+ {ownReach > 0 && (+ <Row label="Distance">+ <ValueSlider+ label="Distance"+ sliderClassName="data-horizontal:w-24"+ valueClassName="w-9 text-muted-foreground"+ value={edgeDistance}+ min={1}+ max={EDGE_DISTANCE_MAX}+ step={1}+ snap={[ownReach]}+ format={(v) => String(Math.round(v))}+ parse={(t) => Number(t)}+ onDraft={(v) => writeEdge({ distance: v })}+ onCommit={(v) => {+ writeEdge({ distance: v });+ ck.end();+ }}+ />+ </Row>+ )}{types && <CaretSettings overlay={o} peers={peers} />}</>);}+/** An edge's curve: the style's own, or any ease by name. */+const EDGE_EASE_ITEMS: Record<string, string> = {+ style: "Style's own",+ ...Object.fromEntries(EASE_IDS.map((id) => [id, EASE_LABELS[id]])),+};+/** Rotation and opacity, shared by every overlay kind. Neutral values store* as absence so untouched elements carry nothing. *//** The element twin of the clip panels' Hidden row: parked on the timeline,diff --git a/site/src/cut/components/OverlayLayer.tsx b/site/src/cut/components/OverlayLayer.tsxindex 1c5e1cca..49858f27 100644--- a/site/src/cut/components/OverlayLayer.tsx+++ b/site/src/cut/components/OverlayLayer.tsx@@ -1557,6 +1557,21 @@ const MASK_CSS_FPS = 15;/** The mask canvas's size cap; the CSS mask stretches it over the box, so a* big element pays a small encode. */const MASK_CSS_MAX = 512;+/** A streaking letter's taps, in its span's own px: the on-screen streak+ * turned back through the letter's turn and stretch, and the share of the+ * streak each copy sits at. */+function glyphStreak(g: ReturnType<typeof glyphStateAt>, scale: number): { x: number; y: number; taps: number[] } | null {+ const s = g.streak!;+ const n = streakTaps(Math.hypot(s.x, s.y));+ if (n < 2) return null;+ const r = (-g.rotate * Math.PI) / 180;+ const x = s.x * scale;+ const y = s.y * scale;+ const ux = (x * Math.cos(r) - y * Math.sin(r)) / (g.sx || 1);+ const uy = (x * Math.sin(r) + y * Math.cos(r)) / (g.sy || 1);+ return { x: ux, y: uy, taps: [...Array(n).keys()].map((i) => i / (n - 1) - 0.5) };+}+/** Empty coverage: hides the element while a computed matte has no person. */const NO_COVERAGE_MASK = "linear-gradient(transparent, transparent)";@@ -1610,6 +1625,9 @@ function GlyphText({const blur = g.blur ? (g.blur * scale) / zoom : 0;// A splitting letter shows a red and a cyan copy either side.const split = g.split && ch !== " " ? g.split * scale : 0;+ // A letter streaking under motion blur: its streak in the span's+ // own space, under the letter's turn and stretch.+ const streak = g.streak && ch !== " " && !reel ? glyphStreak(g, scale) : null;const copy = (tint: string, dx: number) => (<spanaria-hidden@@ -1662,6 +1680,36 @@ function GlyphText({</span>))}</>+ ) : streak ? (+ // A letter in flight under motion blur: copies along its+ // streak that add up into one average, as the painter smears.+ <span style={{ position: "relative", display: "inline-block", isolation: "isolate" }}>+ <span style={{ visibility: "hidden" }}>{ch}</span>+ {streak.taps.map((f, k) => (+ <span+ key={k}+ aria-hidden+ style={{+ position: "absolute",+ left: 0,+ top: 0,+ opacity: 1 / streak.taps.length,+ mixBlendMode: "plus-lighter",+ transform: `translate(${(streak.x * f).toFixed(2)}px, ${(streak.y * f).toFixed(2)}px)`,+ }}+ >+ {split ? (+ <>+ {copy(SPLIT_RED, -split)}+ {copy(SPLIT_CYAN, split)}+ <span style={{ position: "relative" }}>{ch}</span>+ </>+ ) : (+ ch+ )}+ </span>+ ))}+ </span>) : split ? (<>{copy(SPLIT_RED, -split)}diff --git a/site/src/cut/components/inspectorToolFields.test.ts b/site/src/cut/components/inspectorToolFields.test.tsindex 0a7a4480..38945688 100644--- a/site/src/cut/components/inspectorToolFields.test.ts+++ b/site/src/cut/components/inspectorToolFields.test.ts@@ -106,6 +106,16 @@ const PANEL_NAME: Record<string, string> = {out_seconds: "seconds",in_stagger: "edgeStagger",out_stagger: "edgeStagger",+ in_order: "edgeOrder",+ out_order: "edgeOrder",+ in_sequence: "edgeSequence",+ out_sequence: "edgeSequence",+ in_ease: "edgeEase",+ out_ease: "edgeEase",+ in_fade: "edgeFade",+ out_fade: "edgeFade",+ in_distance: "edgeDistance",+ out_distance: "edgeDistance",loop_speed: "speed",words_style: "words",words_color: "words",diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex 29c3ea4a..c1a7b1ed 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -64,6 +64,12 @@ import {OVERLAY_ANIM_DEFAULT_SECONDS,EDGE_STAGGER_MAX,edgeMaxSeconds,+ EDGE_DISTANCE_MAX,+ EDGE_ORDERS,+ EASE_IDS,+ type EaseId,+ type EdgeOrder,+ letterSequence,OVERLAY_ANIM_MIN_SECONDS,OVERLAY_ANIM_STYLE_IDS,TEXT_ONLY_ANIM_STYLE_IDS,@@ -1028,6 +1034,46 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {delete rest.stagger;anim[slot] = stagger < 0 ? rest : { ...rest, stagger: clamp(stagger, 0, EDGE_STAGGER_MAX) };}+ // The order and the reach ride the slot too; "reading" and 0 hand+ // them back to the style's own.+ const order = input[`${slot}_order`];+ if (typeof order === "string" && anim[slot]) {+ if (!(EDGE_ORDERS as readonly string[]).includes(order))+ throw new ToolError(`Unknown ${slot}_order: ${order}. Use one of: ${EDGE_ORDERS.join(", ")}.`);+ const rest = { ...anim[slot]! };+ delete rest.order;+ anim[slot] = order === "reading" ? rest : { ...rest, order: order as EdgeOrder };+ }+ const sequence = input[`${slot}_sequence`];+ if (Array.isArray(sequence) && anim[slot]) {+ const rest = { ...anim[slot]! };+ if (Array.isArray(rest.order)) delete rest.order;+ const text = (o.kind ?? "text") === "text" ? ((o as { text?: string }).text ?? "") : "";+ const order = letterSequence(text, sequence as number[]);+ if (sequence.length > 0 && order.length === 0)+ throw new ToolError(`${slot}_sequence names no letter of "${text}": count its letters from 0, skipping spaces.`);+ anim[slot] = order.length > 0 ? { ...rest, order } : rest;+ }+ const ease = input[`${slot}_ease`];+ if (typeof ease === "string" && anim[slot]) {+ if (ease !== "style" && !isEaseId(ease))+ throw new ToolError(`Unknown ${slot}_ease: ${ease}. Use one of: ${EASE_IDS.join(", ")}, or "style".`);+ const rest = { ...anim[slot]! };+ delete rest.ease;+ anim[slot] = ease === "style" ? rest : { ...rest, ease: ease as EaseId };+ }+ const fade = input[`${slot}_fade`];+ if (typeof fade === "boolean" && anim[slot]) {+ const rest = { ...anim[slot]! };+ delete rest.fade;+ anim[slot] = fade ? rest : { ...rest, fade: false };+ }+ const distance = input[`${slot}_distance`];+ if (isNum(distance) && anim[slot]) {+ const rest = { ...anim[slot]! };+ delete rest.distance;+ anim[slot] = distance <= 0 ? rest : { ...rest, distance: clamp(distance, 1, EDGE_DISTANCE_MAX) };+ }};edge("in", "in_style", "in_seconds");edge("out", "out_style", "out_seconds");@@ -7082,8 +7128,8 @@ function silenceNote(s: Editor, asset: MediaAsset): string {return "";}return sound === "yes"- ? `The cut plays no sound and "${asset.name}" has a soundtrack: detach_audio with its assetId lays that track on the soundtrack from 0, lined up with its picture, and its picture stays off every timeline. `- : `The cut plays no sound. listen_audio on "${asset.name}" says whether it has a soundtrack to lay down with detach_audio. `;+ ? `The cut plays no sound and "${asset.name}" has a soundtrack: import_url with audio_only on the link it came from brings that track in as an audio file of its own, and add_clip at 0 lines it up with the picture while the reference stays off every timeline (detach_audio with its assetId when it came without a link). `+ : `The cut plays no sound. listen_audio on "${asset.name}" says whether it has a soundtrack to lay down. `;}/** How every source-reading tool names the source it read. `type` and `sound`diff --git a/site/src/cut/lib/compareToSource.test.ts b/site/src/cut/lib/compareToSource.test.tsindex 770237f4..0459cf0c 100644--- a/site/src/cut/lib/compareToSource.test.ts+++ b/site/src/cut/lib/compareToSource.test.ts@@ -404,9 +404,10 @@ test("a silent cut held up to a reference with sound says so", async () => {useEditor.getState().updateAsset("ref", { watch: { heard: [{ from: 0, to: 33 }] } as never });const out = (await runAiTool("compare_to_source", { asset_id: "ref", mode: "sweep", from: 0, to: 1, step: 0.5 })) as { note: string };expect(out.note).toContain("plays no sound");- expect(out.note).toContain("detach_audio");- // A reference kept off the timelines still lends its sound.- expect(out.note).toContain("its picture stays off every timeline");+ // A reference kept off the timelines still lends its sound, as a file of+ // its own, so the reference can go once the build is done.+ expect(out.note).toContain("audio_only");+ expect(out.note).toContain("the reference stays off every timeline");const look = (await runAiTool("compare_to_source", { asset_id: "ref", times: [1] })) as { note: string };expect(look.note).toContain("plays no sound");diff --git a/site/src/cut/lib/edgeShapeTool.test.ts b/site/src/cut/lib/edgeShapeTool.test.tsnew file mode 100644index 00000000..8fda2822--- /dev/null+++ b/site/src/cut/lib/edgeShapeTool.test.ts@@ -0,0 +1,71 @@+import { beforeEach, describe, expect, test } from "bun:test";+import { runAiTool } from "./aiTools";+import { useEditor } from "./store";+import { emptySubtitles, isTextOverlay } from "./types";++/**+ * A letter-by-letter drop read off a reference through set_overlay_animation:+ * its order, its reach, and a ramp long enough for a whole title.+ */++const reset = () =>+ useEditor.setState({+ projectId: "p1",+ aspect: "16:9",+ assets: [],+ clips: [],+ overlays: [],+ subtitles: emptySubtitles(),+ background: "#000000",+ });++const title = async () => {+ await runAiTool("add_text_sequence", {+ look: "serif-mood",+ lines: [{ text: "YOUR LOCATION", start: 0, end: 6 }],+ });+ return useEditor.getState().overlays.filter(isTextOverlay)[0];+};+const edgeOf = (id: string) => useEditor.getState().overlays.find((o) => o.id === id)!.anim?.in;++describe("set_overlay_animation letter order and reach", () => {+ beforeEach(reset);++ test("a sequence of letters lands as glyph indices, spaces skipped", async () => {+ const t = await title();+ await runAiTool("set_overlay_animation", { id: t.id, in_style: "drop", in_seconds: 2.6, in_sequence: [5, 4, 0] });+ // L is letter 4 but glyph 5: the space before it takes a turn.+ expect(edgeOf(t.id)?.order).toEqual([6, 5, 0]);+ expect(edgeOf(t.id)?.seconds).toBe(2.6);+ await runAiTool("set_overlay_animation", { id: t.id, in_sequence: [] });+ expect(edgeOf(t.id)?.order).toBeUndefined();+ });++ test("shuffle and reading set the order, a distance the reach, 0 hands it back", async () => {+ const t = await title();+ await runAiTool("set_overlay_animation", { id: t.id, in_style: "drop", in_order: "shuffle", in_distance: 600 });+ expect(edgeOf(t.id)).toMatchObject({ order: "shuffle", distance: 600 });+ await runAiTool("set_overlay_animation", { id: t.id, in_order: "reading", in_distance: 0 });+ expect(edgeOf(t.id)?.order).toBeUndefined();+ expect(edgeOf(t.id)?.distance).toBeUndefined();+ });++ test("a sequence that names no letter is refused", async () => {+ const t = await title();+ await runAiTool("set_overlay_animation", { id: t.id, in_style: "drop" });+ await expect(runAiTool("set_overlay_animation", { id: t.id, in_sequence: [40] })).rejects.toThrow("names no letter");+ });+});++describe("set_overlay_animation ease and fade", () => {+ beforeEach(reset);++ test("a named ease and fade off ride the slot; style and true hand them back", async () => {+ const t = await title();+ await runAiTool("set_overlay_animation", { id: t.id, in_style: "drop", in_ease: "linear", in_fade: false });+ expect(edgeOf(t.id)).toMatchObject({ ease: "linear", fade: false });+ await runAiTool("set_overlay_animation", { id: t.id, in_ease: "style", in_fade: true });+ expect(edgeOf(t.id)?.ease).toBeUndefined();+ expect(edgeOf(t.id)?.fade).toBeUndefined();+ });+});diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex e0af2dd2..2927d185 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -356,13 +356,13 @@ Someone points at a video — a file they imported, a link you brought in, a cli**Measure it.** A contact sheet tells you what happens; the numbers come from the source's pixels. A reference recorded off a screen — a phone filming an editing app, a letterboxed film — has its picture inside a bigger frame: find_picture finds that box and keeps it on the source (detect_cuts does on its first read), every measuring tool and compare_to_source then reads inside it, and their x, y, w, h are fractions of it, so they land on the cut's frame as they are; set_aspect to its \`aspect\`. detect_cuts reads every frame: each cut on its frame, the \`shots\` between them, and the \`changes\` inside a shot — a word landing, a word swapping fill for outline, a shape popping in. Run it over the whole source before the read passes, which then land a frame in every shot and change, and time each title from them. Its times are to the millisecond, and every tool lands such a time on the frame it names: write them back as read. sample_color reads the hex of any region at any second. track_element gives an element's box frame by frame and the ease of each move; with match ink it gives a title's ink box. track_camera gives a shot's camera move frame by frame — zoom, shift, turn — and says when the picture under it is one frozen frame. Run it over every shot before you describe how it moves: a beat zoom on a frozen frame, a shake or a slow push reads on a contact sheet as a held shot with exposure flicker, and detect_cuts lists its pulses as whole-frame \`changes\` — a run of those inside one shot is a camera move until track_camera says otherwise. A cut whose \`change\` sits far below a new shot's, or a few frames that open just before a real cut, is rarely a shot of its own: it is usually the next shot's subject laid over this one, a cutout flashed in. Look at those frames one at a time, and build every one you find; it is part of the edit's look, not a glitch to skip.-**Lay down the sound, then block out the cuts.** Cuts timed to a reference are timed to its sound: detach_audio with the reference's \`assetId\` puts its whole track on the soundtrack and none of its picture. add_clip with \`blocks\` lays the skeleton from \`shots\` in one call — one block per shot on track 0, each its shot's \`from\` and \`to\` as read so every cut lands on its frame, flash cuts included, \`color\` what sample_color reads behind it and \`label\` naming what the person drops there. The label rides the timeline chip; the frame shows the colour alone. Footage dropped on a block, or replace_item, takes its place and its length, so everything built on top keeps its timing. When the ask is the reference's own picture playing, add_clip \`spans\` lays its shots down instead, one span per shot at those same times.+**Lay down the sound, then block out the cuts.** Cuts timed to a reference are timed to its sound, and its music is the cut's soundtrack: bring that track in as an audio file of its own — import_url with \`audio_only\` on the link the reference came from — and add_clip it at 0, where it lines up with the picture. The reference itself stays off every timeline, its sound included, so it can be cleared out once the build is done while the music plays on. A reference with no link (a file the person imported) is the one case for detach_audio with its \`assetId\`, which plays the track straight off the reference. add_clip with \`blocks\` lays the skeleton from \`shots\` in one call — one block per shot on track 0, each its shot's \`from\` and \`to\` as read so every cut lands on its frame, flash cuts included, \`color\` what sample_color reads behind it and \`label\` naming what the person drops there. The label rides the timeline chip; the frame shows the colour alone. Footage dropped on a block, or replace_item, takes its place and its length, so everything built on top keeps its timing. When the ask is the reference's own picture playing, add_clip \`spans\` lays its shots down instead, one span per shot at those same times.**Fill the shots from Pexels, when asked.** The reference's own frames never go in the cut; Pexels' free footage does. Search it with WebFetch — the one web tool you have, and it reaches only Pexels: https://www.pexels.com/search/videos/<words>/?orientation=landscape (portrait for a 9:16 cut), asking for every result's link, id and title. Search per shot by what it shows — the subject and what they wear, the action, the angle, the light, the time of day — and look again with other words when a page has nothing close; one creator's series often covers a whole template, so a good hit's neighbours are worth a search of their own. import_url \`urls\` takes the video page links (pexels.com/video/<slug>-<id>/) and brings each down as its 1080p file, the Pexels id in its name. Watch the candidates beside the reference shot and keep the one that matches subject, angle and motion — a candidate is footage to judge, not a source to replicate: one scan pass over the stretch you would use settles it, and the whole-watch and word-for-word reading above are the reference's alone; replace_item puts it on that shot's block, trim_clip sets its in so the motion lands where the reference's does, set_framing zooms and pans to the reference's framing, and match_color_grade with ref_asset_id the reference and ref_at a moment inside the shot grades it to the reference's frame. Pexels files carry their own sound: when the reference's music is the soundtrack, set_clip_muted with \`ids\` mutes every footage clip in one call, so only the music plays. A shot whose camera moves — a push, a punch-in on the beat, a shake, a tilt — is measured with track_camera over that shot of the reference and keyed on its clip with set_clip_keyframes from the \`path\` and \`moves\` it returns. When it says \`still\`, the reference froze a frame and moved it: freeze_frame at a timeline second inside the shot's clip, for the shot's length, at that clip's index, delete_item the moving clip, and key the moves on the still. An overlay that shows the next shot's subject over the current one is that shot's clip again on a track above, its subject extracted with set_removal. Such a cutout is usually flashed in on its own picture, a frame at a time: a solid white silhouette, then the subject, then blown out, then the subject. Read those frames one by one, split the cutout a clip per frame, and give each its set_clip_effects flash: fade \"from\" at amount 1 for the silhouette, a pop at 0.6-0.9 for a blown-out frame, none for a plain one. A cutout that flickers between the subject and its negative every frame — detect_cuts marks such a run \`flicker\` — is one clip with a negative effect strobing at half the timeline's frame rate, which flips it each frame. Name every Pexels id you used when you close.**Rebuild the text as elements.** One title per card, a stretch of cards per add_title call — the words exactly as they read, size in px at 1080 wide, and x/y where suggest_font sets it on that card — a title is set from the middle of its line, so the centre of its ink box (track_element, match ink, the text's colour) sits off it by the face's own offset. A run of lines timed one after another is add_text_sequence in one call. Match the case the reference uses, and its colour from sample_color. The face comes off the frame: suggest_font with the card's moment, a region close around its words and the words themselves ranks every face Donkey has and hands back the font, weight, size, tracking and x/y to set. Call it on each card: cards in one face share its weight, size and tracking, but each sits its own way in its space, so its x/y comes from its own read, never from a neighbour's place. A title that cycles through typefaces is one call per face it shows. A no_match verdict means the reference uses a face Donkey does not bundle: say so, and set the closest one it named. Without a suggestion, size comes off the ink: capitals stand about 0.7 of the size tall, so size is the ink height in px at 1080 wide ÷ 0.7 (h × 1920 ÷ 0.7 on 9:16). A cycle whose faces change on the music's beats times itself with set_overlay_animation font_cycle_beats on the soundtrack clip after detect_beats; one whose changes follow the reference's own rhythm takes font_cycle_switches, the timeline seconds detect_cuts reads each change at.-**Then the motion.** set_overlay_keyframes gives each card its own pose track — where it sits, at what scale, at what second. track_element over a move hands you the keys: each move's from/to, start/end and ease, with scale as w over the resting w. set_overlay_animation composes on top for the entrance, the exit, a loop, and what a line does while it holds; 0.3-0.6s reads as an entrance, and a per-letter style is what makes a card read as typed. add_shape, a stretch per call, is the rest of the graphics: bars, cards, rules, a block of color behind a line.+**Then the motion.** set_overlay_keyframes gives each card its own pose track — where it sits, at what scale, at what second. track_element over a move hands you the keys: each move's from/to, start/end and ease, with scale as w over the resting w. set_overlay_animation composes on top for the entrance, the exit, a loop, and what a line does while it holds; 0.3-0.6s reads as an entrance, and a per-letter style is what makes a card read as typed. A line whose letters land one at a time is a per-letter entrance read off detect_cuts' \`changes\`: its timing from two reads — one letter's own move, from first showing to settling (track_element with match ink, \`within\` a tall strip over that one letter's column from the top of the frame to its line, from before it shows until it stops), and the span from the first letter's start to the last one's: in_seconds is the span plus one move, in_stagger the span over in_seconds — in_sequence the order they arrive in (in_order shuffle only when no order can be read), in_distance from where track_element first sees a letter to where it settles — a drop from above the frame travels hundreds of px — in_ease the curve that same track reads for its fall (linear when it drops at a steady pace), in_fade false when a letter is already solid as it comes in over the frame's edge, and motion_blur on the element (update_overlay) when a letter in flight smears along its fall. add_shape, a stretch per call, is the rest of the graphics: bars, cards, rules, a block of color behind a line.**Look at what you made.** A build that reads right from your own notes is still a guess until you measure it. compare_to_source does: mode sweep scores every frame of the cut against the source — 0 is the same picture, under ${SWEEP_TARGET} reads as one — and names the worst stretches with a grid of where each differs; mode moments shows those peaks beside the source's frames. Sweep as you build, since an error in the first card is in every card after it: look at the worst stretches, fix what differs, sweep again, and stop when the median is under ${SWEEP_TARGET} and no stretch stands out. A \`shift\` means the right thing lands early or late by that much. Read each picture for colour, the words and their face, where a thing sits, its size, and how far along a move is; a title the same colour as the block behind it reads as correct in the document and shows up here. A block keeps its footage's difference, so judge a shot by the cells over what you built.