Open source CapCut alternative.
TypeScript
feat(site): every animation is keyframe data in one format [rebuild]
David Le9157c794f56f
diff --git a/docs/guides/cut/README.md b/docs/guides/cut/README.mdindex 3a47979f..ca3e7b62 100644--- a/docs/guides/cut/README.md+++ b/docs/guides/cut/README.md@@ -32,6 +32,8 @@ The client probes the engine's health endpoint (dedicated port first, dev server**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.+**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.+## The previewThe preview decodes the cut itself. Every clip on screen owns a decoder reading its file directly — the container is parsed in the page and frames come off WebCodecs — and a small ring of already-decoded frames sits beside it. Drawing a frame is a question answered from that ring, never a wait: playing walks each file forward and keeps the ring ahead of the playhead, scrubbing asks for one moment and the newest ask wins, and if the exact frame has not landed the nearest one already decoded goes up and is replaced when the real one arrives. A held frame is worth more than a stall.diff --git a/site/packages/effects-kit/src/anim.ts b/site/packages/effects-kit/src/anim.tsindex 476af22e..8bfc5212 100644--- a/site/packages/effects-kit/src/anim.ts+++ b/site/packages/effects-kit/src/anim.ts@@ -3,8 +3,28 @@* function. The DOM preview applies the result as a per-frame CSS transform;* the export samples the same function into rasterized frames — a single* evaluator is what keeps the two in lockstep.+ *+ * None of the motion lives here. Every entrance, exit, loop and hold move is+ * keyframe data under motion/, written in the After Effects+ * text-animator shape (keyframed properties plus a range selector) that+ * Lottie serializes. This module is the adapter: it names the slots, holds+ * the ids saved in project docs, and folds the evaluator's per-unit poses+ * into the shapes the renderers already draw.*/+import {+ edgePreset,+ EDGE_IDS,+ holdPreset,+ loopPreset,+ LOOP_IDS,+ MOTION,+ PER_UNIT_EDGE_IDS,+ PER_UNIT_LOOP_IDS,+} from "./motion/catalog";+import { evalPreset, evalWhole, presetExtent, sampleProperties } from "./motion/evaluate";+import type { MotionPose, MotionPreset } from "./motion/types";+export type OverlayAnimStyle =| "fade"| "pop"@@ -16,7 +36,8 @@ export type OverlayAnimStyle =| "typewriter" // text only; other kinds render it as a fade| "wipe"// Per-glyph styles: on text each character runs the ramp on its own delay- // (see glyphAnimAt); on every other kind the whole element runs it once.+ // (the preset carries a range selector); on every other kind the whole+ // element runs it once.| "rise"| "drop"| "grow"@@ -38,9 +59,8 @@ export type OverlayLoopStyle =| "wiggle"| "shake"| "flicker"- // Per-glyph loops: on text each character runs the cycle on its own delay- // (see glyphLoopAt), so the motion travels along the line; on every other- // kind the whole element runs it as one piece.+ // Per-glyph loops: on text each character runs the cycle on its own delay;+ // on every other kind the whole element runs it as one piece.| "wave"| "bounce"| "flip"@@ -49,47 +69,8 @@ export type OverlayLoopStyle =/** The loops that move each character on its own delay. */export type GlyphLoopStyle = "wave" | "bounce" | "flip" | "flutter";-export const GLYPH_LOOP_STYLE_IDS: GlyphLoopStyle[] = ["wave", "bounce", "flip", "flutter"];--const GLYPH_LOOPS: Set<string> = new Set(GLYPH_LOOP_STYLE_IDS);--export function isGlyphLoopStyle(style: OverlayLoopStyle): style is GlyphLoopStyle {- return GLYPH_LOOPS.has(style);-}--export interface OverlayAnim {- in?: { style: OverlayAnimStyle; seconds: number };- out?: { style: OverlayAnimStyle; seconds: number };- /** Runs the element's whole duration; `speed` multiplies the base rate- * (1 = default, 2 = twice as fast). */- loop?: { style: OverlayLoopStyle; speed: number };-}--export const OVERLAY_ANIM_STYLE_IDS: OverlayAnimStyle[] = [- "fade",- "pop",- "zoom",- "slideleft",- "slideright",- "slideup",- "slidedown",- "typewriter",- "wipe",- "rise",- "drop",- "grow",- "flip",- "swivel",- "bounce",- "wave",- "converge",- "streak",- "tumble",- "scatter",-];--/** The styles that move each character on its own delay. Text plays them glyph- * by glyph; anything else plays the same motion as one piece. */+/** The styles that move each character on its own delay. Text plays them+ * glyph by glyph; anything else plays the same motion as one piece. */export type GlyphAnimStyle =| "rise"| "drop"@@ -103,163 +84,117 @@ export type GlyphAnimStyle =| "tumble"| "scatter";-export const GLYPH_ANIM_STYLE_IDS: GlyphAnimStyle[] = [- "rise",- "drop",- "grow",- "flip",- "swivel",- "bounce",- "wave",- "converge",- "streak",- "tumble",- "scatter",-];+/**+ * A ramp at one end of the element.+ *+ * `preset` is a composed animation the project carries itself, in the same+ * shape as a catalog entry — the evaluator cannot tell the two apart, so+ * anything a composer writes plays everywhere a catalog preset does. When it+ * is set it is what plays, and `style` stays the nearest catalog name so+ * menus, tools and prompts still have something to call it.+ */+export interface OverlayEdge {+ style: OverlayAnimStyle;+ seconds: number;+ preset?: MotionPreset;+}++/** The cycle an element runs for its whole duration; `speed` multiplies the+ * base rate (1 = default, 2 = twice as fast). Carries its own preset on the+ * same terms as an edge. */+export interface OverlayLoop {+ style: OverlayLoopStyle;+ speed: number;+ preset?: MotionPreset;+}++export interface OverlayAnim {+ in?: OverlayEdge;+ out?: OverlayEdge;+ loop?: OverlayLoop;+}++/** 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 loopMotion = (slot: OverlayLoop | undefined): MotionPreset | undefined =>+ slot ? (slot.preset ?? loopPreset(slot.style)) : undefined;++// ── the registries, read from the catalog ─────────────────────────────────+// A preset added to the motion catalog appears in every menu, tool enum and prompt+// without being named anywhere else. The unions above stay hand-written:+// they are the ids saved in project docs, and a test holds them to the data.++export const OVERLAY_ANIM_STYLE_IDS = EDGE_IDS as OverlayAnimStyle[];+export const OVERLAY_LOOP_STYLE_IDS = LOOP_IDS as OverlayLoopStyle[];+export const GLYPH_ANIM_STYLE_IDS = PER_UNIT_EDGE_IDS as GlyphAnimStyle[];+export const GLYPH_LOOP_STYLE_IDS = PER_UNIT_LOOP_IDS as GlyphLoopStyle[];const GLYPH_STYLES: Set<string> = new Set(GLYPH_ANIM_STYLE_IDS);+const GLYPH_LOOPS: Set<string> = new Set(GLYPH_LOOP_STYLE_IDS);export function isGlyphAnimStyle(style: OverlayAnimStyle): style is GlyphAnimStyle {return GLYPH_STYLES.has(style);}-/**- * Whether a style changes the element's pixels rather than moving them as one- * picture. A cached bitmap under a transform can't express these, so both- * renderers bake them frame by frame.- */-export function bakesPixels(style: OverlayAnimStyle, isText: boolean): boolean {- if (style === "wipe") return true;- return isText && (style === "typewriter" || isGlyphAnimStyle(style));+export function isGlyphLoopStyle(style: OverlayLoopStyle): style is GlyphLoopStyle {+ return GLYPH_LOOPS.has(style);}-export const OVERLAY_LOOP_STYLE_IDS: OverlayLoopStyle[] = [- "pulse",- "heartbeat",- "float",- "sway",- "spin",- "wiggle",- "shake",- "flicker",- "wave",- "bounce",- "flip",- "flutter",-];--export const OVERLAY_ANIM_STYLE_LABELS: Record<OverlayAnimStyle, string> = {- fade: "Fade",- pop: "Pop",- zoom: "Zoom",- slideleft: "Slide left",- slideright: "Slide right",- slideup: "Slide up",- slidedown: "Slide down",- typewriter: "Typewriter",- wipe: "Wipe",- rise: "Rise",- drop: "Drop",- grow: "Grow",- flip: "Flip",- swivel: "Swivel",- bounce: "Bounce",- wave: "Wave",- converge: "Converge",- streak: "Streak",- tumble: "Tumble",- scatter: "Scatter",-};--export const OVERLAY_LOOP_STYLE_LABELS: Record<OverlayLoopStyle, string> = {- pulse: "Pulse",- heartbeat: "Heartbeat",- float: "Float",- sway: "Sway",- spin: "Spin",- wiggle: "Wiggle",- shake: "Shake",- flicker: "Flicker",- wave: "Wave",- bounce: "Bounce",- flip: "Flip",- flutter: "Flutter",-};+export const OVERLAY_ANIM_STYLE_LABELS = Object.fromEntries(+ EDGE_IDS.map((id) => [id, MOTION.edges[id].label])+) as Record<OverlayAnimStyle, string>;++export const OVERLAY_LOOP_STYLE_LABELS = Object.fromEntries(+ LOOP_IDS.map((id) => [id, MOTION.loops[id].label])+) as Record<OverlayLoopStyle, string>;++/** Base loop periods in seconds at speed 1. */+export const LOOP_PERIODS = Object.fromEntries(+ LOOP_IDS.map((id) => [id, MOTION.loops[id].period ?? 1])+) as Record<OverlayLoopStyle, number>;/** Ramp length bounds, seconds (mirrors clip animations). */export const OVERLAY_ANIM_MIN_SECONDS = 0.1;export const OVERLAY_ANIM_MAX_SECONDS = 2;export const OVERLAY_ANIM_DEFAULT_SECONDS = 0.5;-/** How far slides travel, in design px at the 1080 short side. */-export const SLIDE_TRAVEL = 120;-/** Float bob amplitude, design px. */-export const FLOAT_TRAVEL = 12;-/** Loop amplitudes, design px. */-const SWAY_TRAVEL = 18;-const SHAKE_TRAVEL = 7;-const WAVE_LOOP_TRAVEL = 16;-const BOUNCE_LOOP_TRAVEL = 24;-const FLUTTER_TRAVEL = 5;-/** Per-glyph travel distances, design px. */-const RISE_TRAVEL = 46;-const WAVE_TRAVEL = 26;-const STREAK_TRAVEL = 110;-const CONVERGE_SPREAD = 90;-const SCATTER_TRAVEL = 70;-/** The farthest a glyph ever strays from its resting spot — what the frame- * sampler pads its crop region by. */-export const GLYPH_TRAVEL_MAX = 120;-/** Base loop periods in seconds at speed 1. */-export const LOOP_PERIODS: Record<OverlayLoopStyle, number> = {- pulse: 1.2,- heartbeat: 1.5,- float: 2.4,- sway: 2.8,- spin: 4,- wiggle: 0.9,- shake: 0.5,- flicker: 1.8,- wave: 1.6,- bounce: 1.6,- flip: 3.2,- flutter: 1.4,-};+/**+ * Whether a style changes the element's pixels rather than moving them as one+ * picture. A cached bitmap under a transform can't express these, so both+ * renderers bake them frame by frame.+ */+export function bakesPixels(slot: OverlayEdge | undefined, isText: boolean): boolean {+ const preset = edgeMotion(slot);+ if (!preset) return false;+ if (preset.animate.reveal) return true; // a wipe clips whatever it is over+ if (!isText) return false;+ // A typewriter types characters; a selector moves them one at a time.+ return !!preset.animate.typed || !!preset.selector;+}/*** How far a loop strays from rest, in design px, and whether it turns. The* frame sampler crops an element to the box it lives in, so a loop that* travels has to say so or the sampler clips the motion off.*/-export function loopExtent(style: OverlayLoopStyle | undefined): {+export function loopExtent(slot: OverlayLoop | undefined): {travel: number;rotates: boolean;} {- switch (style) {- case "float":- return { travel: FLOAT_TRAVEL, rotates: false };- case "sway":- return { travel: SWAY_TRAVEL, rotates: true };- case "shake":- return { travel: SHAKE_TRAVEL, rotates: false };- case "wave":- return { travel: WAVE_LOOP_TRAVEL, rotates: false };- case "bounce":- return { travel: BOUNCE_LOOP_TRAVEL, rotates: false };- case "flutter":- return { travel: FLUTTER_TRAVEL, rotates: true };- case "spin":- case "wiggle":- return { travel: 0, rotates: true };- default:- return { travel: 0, rotates: false };- }+ const preset = loopMotion(slot);+ return preset ? presetExtent(preset) : { travel: 0, rotates: false };}/** Where a per-glyph ramp stands. Renderers walk the element's characters and* ask `glyphAnimAt` where each one sits. */export interface GlyphPhase {style: OverlayAnimStyle;+ /** The slot's own preset, carried through so a composed animation reaches+ * the characters the same way a catalog one does. */+ preset?: MotionPreset;/** 0 at the far end of the ramp, 1 at rest. */p: number;exiting: boolean;@@ -269,6 +204,7 @@ export interface GlyphPhase {* character reads it at its own delay. */export interface GlyphLoopPhase {style: GlyphLoopStyle;+ preset?: MotionPreset;phase: number;}@@ -305,201 +241,38 @@ export interface GlyphAnimState {const IDLE: OverlayAnimState = { dx: 0, dy: 0, scale: 1, rotate: 0, alpha: 1 };const GLYPH_IDLE: GlyphAnimState = { dx: 0, dy: 0, sx: 1, sy: 1, rotate: 0, alpha: 1 };-const easeOutCubic = (p: number) => 1 - Math.pow(1 - p, 3);-const easeInCubic = (p: number) => p * p * p;-const easeOutBack = (p: number) => {- const c1 = 1.70158;- const c3 = c1 + 1;- return 1 + c3 * Math.pow(p - 1, 3) + c1 * Math.pow(p - 1, 2);-};--const easeOutBounce = (p: number) => {- const n1 = 7.5625;- const d1 = 2.75;- if (p < 1 / d1) return n1 * p * p;- if (p < 2 / d1) return n1 * (p -= 1.5 / d1) * p + 0.75;- if (p < 2.5 / d1) return n1 * (p -= 2.25 / d1) * p + 0.9375;- return n1 * (p -= 2.625 / d1) * p + 0.984375;-};--const clamp01 = (p: number) => Math.min(1, Math.max(0, p));+const wrap01 = (v: number) => v - Math.floor(v);-/**- * One glyph's motion at its own progress `q` (0 = the far end of the ramp,- * 1 = at rest). `index`/`count` place it in the run, which is what a spread or- * a scatter needs; a whole element playing the same style is glyph 0 of 1.- */-function glyphMotion(- style: OverlayAnimStyle,- q: number,- exiting: boolean,- index: number,- count: number-): GlyphAnimState {- const away = 1 - easeOutCubic(q);- const dir = exiting ? -1 : 1;- const fade = (mult: number) => Math.min(1, q * mult);- switch (style) {- case "rise":- return { ...GLYPH_IDLE, dy: away * RISE_TRAVEL * dir, alpha: q };- case "drop":- return { ...GLYPH_IDLE, dy: -away * RISE_TRAVEL * dir, alpha: q };- case "grow": {- const s = easeOutBack(q);- return { ...GLYPH_IDLE, sx: s, sy: s, alpha: fade(2) };- }- case "flip":- return { ...GLYPH_IDLE, sy: Math.cos((1 - q) * Math.PI), alpha: fade(4) };- case "swivel":- return { ...GLYPH_IDLE, sx: Math.cos((1 - q) * Math.PI), alpha: fade(4) };- case "bounce":- return {- ...GLYPH_IDLE,- dy: -(1 - easeOutBounce(q)) * RISE_TRAVEL * dir,- alpha: fade(4),- };- case "wave":- // Up from below with an arch past the resting line; run one after the- // other, the arch is what reads as the wave.- return {- ...GLYPH_IDLE,- dy: (away - Math.sin(q * Math.PI) * 0.6) * WAVE_TRAVEL,- alpha: fade(2.5),- };- case "converge": {- // Spread across the run, then pulled together into place.- const frac = count > 1 ? (index / (count - 1)) * 2 - 1 : 0;- return { ...GLYPH_IDLE, dx: frac * CONVERGE_SPREAD * away, alpha: fade(2) };- }- case "streak":- return {- ...GLYPH_IDLE,- dx: -away * STREAK_TRAVEL * dir,- sx: 1 + away * 0.5,- alpha: fade(2),- };- case "tumble":- return {- ...GLYPH_IDLE,- dy: -away * RISE_TRAVEL * 1.4 * dir,- rotate: -away * 35 * dir,- alpha: fade(2),- };- case "scatter": {- // The golden angle spreads the directions evenly however many glyphs- // there are, and the same index always flies the same way.- const a = index * 2.399963;- const reach = SCATTER_TRAVEL * (0.7 + 0.3 * (((index * 7919) % 13) / 13));- return {- ...GLYPH_IDLE,- dx: Math.cos(a) * reach * away,- dy: Math.sin(a) * reach * away,- rotate: away * 25 * (index % 2 ? -1 : 1),- alpha: q,- };- }- default:- return GLYPH_IDLE;- }-}+/** A unit's share of the line's spread: -1 at the head, +1 at the tail. This+ * is what turns the tracking property into a per-character offset. */+const trackShare = (index: number, count: number) =>+ count > 1 ? (index / (count - 1)) * 2 - 1 : 0;-/** Share of the ramp spent handing the motion from the first glyph to the- * last; what's left is how long any one glyph takes. */-const GLYPH_STAGGER = 0.6;-const GLYPH_STAGGER_BY_STYLE: Partial<Record<OverlayAnimStyle, number>> = {- converge: 0.25,- wave: 0.75,- flip: 0.7,- swivel: 0.7,-};+/** An evaluator pose as the per-glyph state the renderers draw. */+function asGlyph(pose: MotionPose, index: number, count: number): GlyphAnimState {+ return {+ dx: pose.dx + trackShare(index, count) * pose.tracking,+ dy: pose.dy,+ sx: pose.sx,+ sy: pose.sy,+ rotate: pose.rotate,+ alpha: pose.alpha,+ };+}/*** Where character `index` of `count` sits when its element's ramp stands at* `p`. Glyphs start in order and overlap, so the motion sweeps the line; an* exit sweeps out the way it came in.*/-export function glyphAnimAt(- style: OverlayAnimStyle,- p: number,- index: number,- count: number,- exiting: boolean-): GlyphAnimState {+export function glyphAnimAt(phase: GlyphPhase, index: number, count: number): GlyphAnimState {+ const { p, exiting } = phase;+ const preset = phase.preset ?? edgePreset(phase.style);+ // Only a preset with a selector has anything to say per character; a+ // whole-element style leaves its glyphs where they are.+ if (!preset?.selector) return GLYPH_IDLE;const n = Math.max(1, count);- const i = exiting ? n - 1 - index : index;- const stagger = GLYPH_STAGGER_BY_STYLE[style] ?? GLYPH_STAGGER;- const from = n > 1 ? (i / (n - 1)) * stagger : 0;- return glyphMotion(style, clamp01((clamp01(p) - from) / (1 - stagger)), exiting, index, n);-}--/** The whole-element stand-in for a per-glyph ramp: the same motion run once- * over the box, for renderers that only have one cached picture to move. */-export function glyphFallback(phase: GlyphPhase): GlyphAnimState {- return glyphMotion(phase.style, clamp01(phase.p), phase.exiting, 0, 1);-}--const TAU = Math.PI * 2;-const wrap01 = (v: number) => v - Math.floor(v);-/** Distance between two points on a cycle, either way round. */-const cyclicGap = (a: number, b: number) => {- const d = Math.abs(wrap01(a) - wrap01(b));- return Math.min(d, 1 - d);-};--/**- * One glyph's place in a loop at cycle position `phase`. Every loop is exactly- * periodic in `phase` — built from whole harmonics and wrapped offsets — which- * is what lets the frame sampler render one cycle of pictures and repeat them- * for as long as the element runs.- *- * `index`/`count` stagger the run: most of these hand the motion down the line- * one character at a time, and a whole element playing the same loop is glyph- * 0 of 1.- */-function glyphLoopMotion(- style: GlyphLoopStyle,- phase: number,- index: number,- count: number-): GlyphAnimState {- const n = Math.max(1, count);- // Each character starts its turn a little later than the one before it, so- // one cycle sweeps the whole line exactly once.- const u = wrap01(phase - index / n);- switch (style) {- case "wave":- return { ...GLYPH_IDLE, dy: -Math.sin(u * TAU) * WAVE_LOOP_TRAVEL };- case "bounce": {- // Up over the first half of the turn, a beat on the ground for the- // second. The character stretches as it rises and squashes as it sits,- // so the weight of the hop reads even at caption size.- const hop = Math.max(0, Math.sin(u * TAU));- const ground = Math.max(0, -Math.sin(u * TAU));- return {- ...GLYPH_IDLE,- dy: -hop * BOUNCE_LOOP_TRAVEL,- sx: 1 - 0.05 * hop + 0.08 * ground,- sy: 1 + 0.07 * hop - 0.1 * ground,- };- }- case "flip": {- // A split-flap turn: one full revolution inside the character's window,- // and it sits still for the rest of the cycle.- const window = 0.4;- return { ...GLYPH_IDLE, sy: Math.cos(TAU * Math.min(1, u / window)) };- }- case "flutter": {- // No hand-off here: the golden angle gives every character its own place- // in the cycle, so the line shimmers instead of sweeping.- const a = index * 2.399963;- return {- ...GLYPH_IDLE,- dx: Math.sin(TAU * phase + a) * FLUTTER_TRAVEL,- dy: Math.sin(TAU * phase + a * 1.7) * FLUTTER_TRAVEL,- rotate: Math.sin(2 * TAU * phase + a) * 5,- };- }- }+ return asGlyph(evalPreset(preset, p, index, n, exiting), index, n);}/** Where character `index` of `count` sits with everything applied — the edge@@ -510,11 +283,12 @@ export function glyphStateAt(index: number,count: number): GlyphAnimState {- const ramp = state.glyphs- ? glyphAnimAt(state.glyphs.style, state.glyphs.p, index, count, state.glyphs.exiting)- : GLYPH_IDLE;+ const ramp = state.glyphs ? glyphAnimAt(state.glyphs, index, count) : GLYPH_IDLE;if (!state.glyphLoop) return ramp;- const loop = glyphLoopMotion(state.glyphLoop.style, state.glyphLoop.phase, index, count);+ const preset = state.glyphLoop.preset ?? loopPreset(state.glyphLoop.style);+ if (!preset) return ramp;+ const n = Math.max(1, count);+ const loop = asGlyph(evalPreset(preset, state.glyphLoop.phase, index, n, false), index, n);return {dx: ramp.dx + loop.dx,dy: ramp.dy + loop.dy,@@ -533,122 +307,62 @@ export function hasGlyphMotion(state: {return !!state.glyphs || !!state.glyphLoop;}-/** The loop's contribution at `phase`, written onto the state the edge ramps- * left. A per-glyph loop hands the characters their own cycle; on any other- * kind it folds back into the one transform the element has. */-function applyLoop(- state: OverlayAnimState,- style: OverlayLoopStyle,- phase: number,- isText: boolean-): void {- if (isGlyphLoopStyle(style)) {- if (isText) {- state.glyphLoop = { style, phase };- return;- }- const g = glyphLoopMotion(style, phase, 0, 1);- state.dx += g.dx;- state.dy += g.dy;- state.rotate += g.rotate;- state.scale *= (g.sx + g.sy) / 2;- state.alpha *= g.alpha;- return;- }- const wave = Math.sin(phase * TAU);- switch (style) {- case "pulse":- state.scale *= 1 + 0.06 * wave;- break;- case "heartbeat": {- // Two thumps close together, then the rest of the cycle at rest — the- // gap is what separates it from a pulse.- const thump = (at: number, width: number) =>- Math.exp(-Math.pow(cyclicGap(phase, at) / width, 2));- state.scale *= 1 + 0.14 * thump(0.06, 0.045) + 0.09 * thump(0.2, 0.05);- break;- }- case "float":- state.dy += FLOAT_TRAVEL * wave;- break;- case "sway":- // The tilt follows the glide, so the element leans into the turn.- state.dx += SWAY_TRAVEL * wave;- state.rotate += 3 * wave;- break;- case "spin":- state.rotate += phase * 360;- break;- case "wiggle":- state.rotate += 4 * wave;- break;- case "shake":- // Stacked harmonics: erratic to watch, and still exactly periodic.- state.dx += SHAKE_TRAVEL * (wave * 0.65 + Math.sin(3 * phase * TAU) * 0.35);- state.dy +=- SHAKE_TRAVEL *- 0.7 *- (Math.sin(2 * phase * TAU) * 0.7 + Math.sin(5 * phase * TAU) * 0.3);- break;- case "flicker": {- // Lit most of the way round, with one stuttering dip.- const dip = Math.max(0, wave) * (0.6 + 0.4 * Math.sin(5 * phase * TAU));- state.alpha *= 1 - 0.55 * Math.max(0, dip);- break;- }- }-}-/** One edge ramp. `p` runs 0→1 over the window in play direction for "in";* for "out" the caller feeds remaining-share so the motion mirrors. Text hands* the per-glyph styles to the renderer as a phase; every other kind plays the* same motion as one piece. */function edgeState(- style: OverlayAnimStyle,+ slot: OverlayEdge,p: number,exiting: boolean,isText: boolean): OverlayAnimState {+ const preset = edgeMotion(slot);+ if (!preset) return { ...IDLE };const clamped = Math.min(1, Math.max(0, p));- if (isGlyphAnimStyle(style)) {- if (isText) return { ...IDLE, glyphs: { style, p: clamped, exiting } };- const g = glyphFallback({ style, p: clamped, exiting });+ if (preset.selector && isText)return {- dx: g.dx,- dy: g.dy,- scale: (g.sx + g.sy) / 2,- rotate: g.rotate,- alpha: g.alpha,+ ...IDLE,+ glyphs: { style: slot.style, preset: slot.preset, p: clamped, exiting },};+ // Anything with no characters to hand the motion to plays it once over the+ // whole box.+ const pose = evalWhole(preset, clamped, exiting);+ const state: OverlayAnimState = {+ dx: pose.dx,+ dy: pose.dy,+ scale: (pose.sx + pose.sy) / 2,+ rotate: pose.rotate,+ alpha: pose.alpha,+ };+ // A typewriter on anything but text has no characters to reveal, so the+ // element just holds — the same as it always did.+ if (pose.typed !== undefined) state.textProgress = pose.typed;+ if (pose.reveal !== undefined) state.reveal = pose.reveal;+ return state;+}++/** The loop's contribution at `phase`, written onto the state the edge ramps+ * left. A per-glyph loop hands the characters their own cycle; on any other+ * kind it folds back into the one transform the element has. */+function applyLoop(+ state: OverlayAnimState,+ slot: OverlayLoop,+ phase: number,+ isText: boolean+): void {+ const preset = loopMotion(slot);+ if (!preset) return;+ if (preset.selector && isText) {+ state.glyphLoop = { style: slot.style as GlyphLoopStyle, preset: slot.preset, phase };+ return;}- switch (style) {- case "wipe":- return { ...IDLE, reveal: clamped };- case "fade":- return { ...IDLE, alpha: clamped };- case "pop":- // Entering overshoots then settles; exiting shrinks away without the- // overshoot (a reverse overshoot reads as a stutter).- return {- ...IDLE,- scale: exiting ? easeInCubic(clamped) * 0.4 + 0.6 * clamped : easeOutBack(clamped),- alpha: Math.min(1, clamped * 2),- };- case "zoom":- return { ...IDLE, scale: 0.6 + 0.4 * easeOutCubic(clamped), alpha: clamped };- case "slideleft":- // The picture moves leftward: it enters from the right edge, or exits- // off the left one — the exit's offset runs negative.- return { ...IDLE, dx: (1 - easeOutCubic(clamped)) * SLIDE_TRAVEL * (exiting ? -1 : 1), alpha: clamped };- case "slideright":- return { ...IDLE, dx: (1 - easeOutCubic(clamped)) * SLIDE_TRAVEL * (exiting ? 1 : -1), alpha: clamped };- case "slideup":- return { ...IDLE, dy: (1 - easeOutCubic(clamped)) * SLIDE_TRAVEL * (exiting ? -1 : 1), alpha: clamped };- case "slidedown":- return { ...IDLE, dy: (1 - easeOutCubic(clamped)) * SLIDE_TRAVEL * (exiting ? 1 : -1), alpha: clamped };- case "typewriter":- return { ...IDLE, textProgress: clamped };- }+ const pose = evalPreset(preset, phase, 0, 1, false);+ state.dx += pose.dx;+ state.dy += pose.dy;+ state.rotate += pose.rotate;+ state.scale *= (pose.sx + pose.sy) / 2;+ state.alpha *= pose.alpha;}/**@@ -669,15 +383,14 @@ 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.style, tLocal / inSecs, false, isText);+ state = edgeState(anim.in, tLocal / inSecs, false, isText);} else if (anim.out && tLocal > dur - outSecs) {- state = edgeState(anim.out.style, (dur - tLocal) / outSecs, true, isText);+ state = edgeState(anim.out, (dur - tLocal) / outSecs, true, isText);}if (anim.loop) {- const speed = anim.loop.speed > 0 ? anim.loop.speed : 1;- const period = LOOP_PERIODS[anim.loop.style] / speed;- applyLoop(state, anim.loop.style, wrap01(tLocal / period), isText);+ const period = loopPeriod(anim) ?? 1;+ applyLoop(state, anim.loop, wrap01(tLocal / period), isText);}return state;}@@ -687,10 +400,94 @@ export function evalOverlayAnim(export function loopPeriod(anim: OverlayAnim | undefined): number | null {if (!anim?.loop) return null;const speed = anim.loop.speed > 0 ? anim.loop.speed : 1;- return LOOP_PERIODS[anim.loop.style] / speed;+ const base = loopMotion(anim.loop)?.period ?? LOOP_PERIODS[anim.loop.style] ?? 1;+ return base / speed;}/** Whether any slot is set (an element with an empty anim object is static). */export function hasOverlayAnim(anim: OverlayAnim | undefined): boolean {return !!anim && (!!anim.in || !!anim.out || !!anim.loop);}++/**+ * A hold move as the element's own pose track: absolute poses at seconds from+ * its start, ready to write onto `kf`. A move is the same keyframe data every+ * other animation is — sampled against the element's resting pose so a preset+ * entrance still composes over it.+ */+export function holdMoveKeys(+ id: string,+ rest: { x: number; y: number; rotation: number },+ dur: number,+ /** Multiplies every offset from rest. 1 is the move as written; below it+ * the same shape reads quieter, above it harder. The timing never changes,+ * so a move stays on the beat whatever it is scaled to. */+ strength = 1,+ frameShortSide = 1080+): { t: number; x: number; y: number; scale: number; rotation: number; opacity: number }[] | undefined {+ const preset = holdPreset(id);+ if (!preset || dur <= 0.15) return undefined;+ const pose = (t: number) => sampleProperties(preset.animate, t, dur);+ const seeds = new Set<number>([0, 1]);+ for (const track of Object.values(preset.animate))+ for (const k of track) seeds.add(k.tMax === undefined ? k.t : Math.min(k.t, k.tMax / dur));+ const times = [...seeds].sort((a, b) => a - b);+ // The preset's own keys are not enough by themselves: a pose track runs+ // straight between its keys, so an eased push would arrive at a constant+ // rate and a circling move would draw a polygon. Each gap is halved until+ // the straight line across it matches the curve, which leaves an even move+ // at its two keys and spends keys only where there is a bend.+ const track: number[] = [times[0]];+ const fill = (a: number, b: number, depth: number): void => {+ if (depth < SUBDIVIDE_MAX && bends(a, b, pose)) {+ const m = (a + b) / 2;+ fill(a, m, depth + 1);+ fill(m, b, depth + 1);+ } else track.push(b);+ };+ for (let i = 0; i < times.length - 1; i++) fill(times[i], times[i + 1], 0);+ const px = 1 / frameShortSide;+ const k = strength;+ const keys = track+ .map((t) => {+ const p = pose(t);+ return {+ t: Math.round(t * dur * 1000) / 1000,+ x: rest.x + p.dx * px * k,+ y: rest.y + p.dy * px * k,+ scale: 1 + ((p.sx + p.sy) / 2 - 1) * k,+ rotation: rest.rotation + p.rotate * k,+ opacity: 1 + (p.alpha - 1) * k,+ };+ })+ .filter((key, i, all) => i === 0 || key.t > all[i - 1].t + 1e-3);+ return keys.length > 1 ? keys : undefined;+}++/** How many times a gap may be halved before the curve across it is called+ * close enough. */+const SUBDIVIDE_MAX = 4;++/** Whether the motion across a gap leaves the straight line between its ends+ * by enough to see. Three points are checked rather than one, because the+ * ease most of these presets are written with is symmetric: it is exactly on+ * the line at the middle and furthest off it at the quarters. Tolerances are+ * design px of travel, degrees of turn, and shares of scale and opacity. */+function bends(a: number, b: number, pose: (t: number) => MotionPose): boolean {+ const pa = pose(a);+ const pb = pose(b);+ for (const f of [0.25, 0.5, 0.75]) {+ const p = pose(a + (b - a) * f);+ const off = (u: number, w: number, v: number) => Math.abs(u + (w - u) * f - v);+ if (+ off(pa.dx, pb.dx, p.dx) > 1.5 ||+ off(pa.dy, pb.dy, p.dy) > 1.5 ||+ off(pa.rotate, pb.rotate, p.rotate) > 0.5 ||+ off(pa.sx, pb.sx, p.sx) > 0.006 ||+ off(pa.sy, pb.sy, p.sy) > 0.006 ||+ off(pa.alpha, pb.alpha, p.alpha) > 0.015+ )+ return true;+ }+ return false;+}diff --git a/site/packages/effects-kit/src/index.ts b/site/packages/effects-kit/src/index.tsindex 6174655e..c6c8dc1a 100644--- a/site/packages/effects-kit/src/index.ts+++ b/site/packages/effects-kit/src/index.ts@@ -1,5 +1,8 @@export * from "./types";export * from "./anim";+export * from "./motion/types";+export * from "./motion/evaluate";+export * from "./motion/catalog";export * from "./keys";export * from "./mask";export * from "./render";diff --git a/site/packages/effects-kit/src/motion/catalog.ts b/site/packages/effects-kit/src/motion/catalog.tsnew file mode 100644index 00000000..ecb1b669--- /dev/null+++ b/site/packages/effects-kit/src/motion/catalog.ts@@ -0,0 +1,44 @@+/**+ * The motion catalog: every animation in the app, as data.+ *+ * The three JSON files beside this one hold them in the After Effects+ * text-animator shape — keyframed properties plus a range selector — which is+ * what Lottie serializes and what GSAP and Motion reimplement as split-text+ * stagger. They are split the way they are used: edges are the entrances and+ * exits, loops run for as long as the element does, holds are the moves a+ * pose track is written from. Adding one means adding an entry to its file;+ * no code lists them.+ */++import edges from "./edges.json";+import loops from "./loops.json";+import holds from "./holds.json";+import type { MotionCatalog, MotionPreset, MotionSlot } from "./types";++export const MOTION: MotionCatalog = {+ version: 1,+ edges,+ loops,+ holds,+} as unknown as MotionCatalog;++export const edgePreset = (id: string): MotionPreset | undefined => MOTION.edges[id];+export const loopPreset = (id: string): MotionPreset | undefined => MOTION.loops[id];+export const holdPreset = (id: string): MotionPreset | undefined => MOTION.holds[id];++export const EDGE_IDS = Object.keys(MOTION.edges);+export const LOOP_IDS = Object.keys(MOTION.loops);+export const HOLD_IDS = Object.keys(MOTION.holds);++/** The entrances and exits that move a title character by character. */+export const PER_UNIT_EDGE_IDS = EDGE_IDS.filter((id) => !!MOTION.edges[id].selector);+/** The loops that carry a title's characters on their own delays. */+export const PER_UNIT_LOOP_IDS = LOOP_IDS.filter((id) => !!MOTION.loops[id].selector);++/** Every preset that may fill a slot, for menus and tool enums. */+export function presetsFor(slot: MotionSlot): { id: string; preset: MotionPreset }[] {+ const group = slot === "loop" ? MOTION.loops : slot === "hold" ? MOTION.holds : MOTION.edges;+ return Object.entries(group)+ .filter(([, p]) => p.slots.includes(slot))+ .map(([id, preset]) => ({ id, preset }));+}diff --git a/site/packages/effects-kit/src/motion/edges.json b/site/packages/effects-kit/src/motion/edges.jsonnew file mode 100644index 00000000..57ebaf56--- /dev/null+++ b/site/packages/effects-kit/src/motion/edges.json@@ -0,0 +1,1764 @@+{+ "fade": {+ "label": "Fade",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "pop": {+ "label": "Pop",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.395,+ 0.99,+ 0.795,+ 0.99+ ]+ },+ {+ "t": 0.5813,+ "v": [+ 1.1,+ 1.1+ ],+ "ease": [+ 0.34,+ 0.015,+ 0.67,+ 1.005+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.33,+ 0.33,+ 0.65,+ 0.65+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "scale": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.44,+ 0.255,+ 0.715,+ 0.49+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.33,+ 0.33,+ 0.65,+ 0.65+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "zoom": {+ "label": "Zoom",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 0.6,+ 0.6+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "slideleft": {+ "label": "Slide left",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 120,+ 0+ ],+ "ease": [+ 0.485,+ 0.77,+ 0.96,+ 0.975+ ]+ },+ {+ "t": 0.4219,+ "v": [+ 23.1871,+ 0+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ -120,+ 0+ ],+ "ease": [+ 0.485,+ 0.77,+ 0.96,+ 0.975+ ]+ },+ {+ "t": 0.4219,+ "v": [+ -23.1871,+ 0+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "slideright": {+ "label": "Slide right",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ -120,+ 0+ ],+ "ease": [+ 0.485,+ 0.77,+ 0.96,+ 0.975+ ]+ },+ {+ "t": 0.4219,+ "v": [+ -23.1871,+ 0+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ 120,+ 0+ ],+ "ease": [+ 0.485,+ 0.77,+ 0.96,+ 0.975+ ]+ },+ {+ "t": 0.4219,+ "v": [+ 23.1871,+ 0+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "slideup": {+ "label": "Slide up",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 120+ ],+ "ease": [+ 0.485,+ 0.77,+ 0.96,+ 0.975+ ]+ },+ {+ "t": 0.4219,+ "v": [+ 0,+ 23.1871+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -120+ ],+ "ease": [+ 0.485,+ 0.77,+ 0.96,+ 0.975+ ]+ },+ {+ "t": 0.4219,+ "v": [+ 0,+ -23.1871+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "slidedown": {+ "label": "Slide down",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -120+ ],+ "ease": [+ 0.485,+ 0.77,+ 0.96,+ 0.975+ ]+ },+ {+ "t": 0.4219,+ "v": [+ 0,+ -23.1871+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 120+ ],+ "ease": [+ 0.485,+ 0.77,+ 0.96,+ 0.975+ ]+ },+ {+ "t": 0.4219,+ "v": [+ 0,+ 23.1871+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "typewriter": {+ "label": "Typewriter",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "typed": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "wipe": {+ "label": "Wipe",+ "slots": [+ "in",+ "out"+ ],+ "animate": {+ "reveal": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "rise": {+ "label": "Rise",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.6+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 46+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -46+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "drop": {+ "label": "Drop",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.6+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -46+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 46+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "grow": {+ "label": "Grow",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.6+ },+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.395,+ 0.99,+ 0.795,+ 0.99+ ]+ },+ {+ "t": 0.5813,+ "v": [+ 1.1,+ 1.1+ ],+ "ease": [+ 0.34,+ 0.015,+ 0.67,+ 1.005+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.33,+ 0.33,+ 0.65,+ 0.65+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "flip": {+ "label": "Flip",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.7+ },+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1,+ -1+ ],+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.35,+ 0.35,+ 0.6,+ 0.6+ ]+ },+ {+ "t": 0.25,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "swivel": {+ "label": "Swivel",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.7+ },+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ -1,+ 1+ ],+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.35,+ 0.35,+ 0.6,+ 0.6+ ]+ },+ {+ "t": 0.25,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "bounce": {+ "label": "Bounce",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.6+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -46+ ],+ "ease": [+ 0.17,+ 0,+ 0.535,+ 0.07+ ]+ },+ {+ "t": 0.1813,+ "v": [+ 0,+ -34.5718+ ],+ "ease": [+ 0.86,+ 0.66,+ 0.865,+ 0.93+ ]+ },+ {+ "t": 0.3656,+ "v": [+ 0,+ -0.2502+ ],+ "ease": [+ 0.145,+ 0.29,+ 0.525,+ 1.015+ ]+ },+ {+ "t": 0.5469,+ "v": [+ 0,+ -11.4993+ ],+ "ease": [+ 0.515,+ 0.04,+ 0.795,+ 0.665+ ]+ },+ {+ "t": 0.7281,+ "v": [+ 0,+ -0.0537+ ],+ "ease": [+ 0.125,+ 0.25,+ 0.51,+ 1.01+ ]+ },+ {+ "t": 0.8188,+ "v": [+ 0,+ -2.8749+ ],+ "ease": [+ 0.215,+ 0.03,+ 0.5,+ 0.06+ ]+ },+ {+ "t": 0.9094,+ "v": [+ 0,+ -0.009+ ],+ "ease": [+ 0.365,+ 0.705,+ 0.7,+ 0.985+ ]+ },+ {+ "t": 0.9531,+ "v": [+ 0,+ -0.718+ ],+ "ease": [+ 0.41,+ -0.025,+ 0.75,+ 0.485+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.35,+ 0.35,+ 0.6,+ 0.6+ ]+ },+ {+ "t": 0.25,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 46+ ],+ "ease": [+ 0.17,+ 0,+ 0.535,+ 0.07+ ]+ },+ {+ "t": 0.1813,+ "v": [+ 0,+ 34.5718+ ],+ "ease": [+ 0.86,+ 0.66,+ 0.865,+ 0.93+ ]+ },+ {+ "t": 0.3656,+ "v": [+ 0,+ 0.2502+ ],+ "ease": [+ 0.145,+ 0.29,+ 0.525,+ 1.015+ ]+ },+ {+ "t": 0.5469,+ "v": [+ 0,+ 11.4993+ ],+ "ease": [+ 0.515,+ 0.04,+ 0.795,+ 0.665+ ]+ },+ {+ "t": 0.7281,+ "v": [+ 0,+ 0.0537+ ],+ "ease": [+ 0.125,+ 0.25,+ 0.51,+ 1.01+ ]+ },+ {+ "t": 0.8188,+ "v": [+ 0,+ 2.8749+ ],+ "ease": [+ 0.215,+ 0.03,+ 0.5,+ 0.06+ ]+ },+ {+ "t": 0.9094,+ "v": [+ 0,+ 0.009+ ],+ "ease": [+ 0.365,+ 0.705,+ 0.7,+ 0.985+ ]+ },+ {+ "t": 0.9531,+ "v": [+ 0,+ 0.718+ ],+ "ease": [+ 0.41,+ -0.025,+ 0.75,+ 0.485+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.35,+ 0.35,+ 0.6,+ 0.6+ ]+ },+ {+ "t": 0.25,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "wave": {+ "label": "Wave",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.75+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 26+ ],+ "ease": [+ 0.475,+ 0.915,+ 0.805,+ 1+ ]+ },+ {+ "t": 0.5875,+ "v": [+ 0,+ -13.1894+ ],+ "ease": [+ 0.24,+ 0.01,+ 0.47,+ 0.165+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.38,+ 0.38,+ 0.585,+ 0.585+ ]+ },+ {+ "t": 0.4,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "converge": {+ "label": "Converge",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.25+ },+ "animate": {+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.33,+ 0.33,+ 0.65,+ 0.65+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ],+ "tracking": [+ {+ "t": 0,+ "v": 90,+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": 0+ }+ ]+ }+ },+ "streak": {+ "label": "Streak",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.6+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ -110,+ 0+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "scale": [+ {+ "t": 0,+ "v": [+ 1.5,+ 1+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.33,+ 0.33,+ 0.65,+ 0.65+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ 110,+ 0+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "scale": [+ {+ "t": 0,+ "v": [+ 1.5,+ 1+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.33,+ 0.33,+ 0.65,+ 0.65+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "tumble": {+ "label": "Tumble",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.6+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -64.4+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "rotation": [+ {+ "t": 0,+ "v": -35,+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": 0+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.33,+ 0.33,+ 0.65,+ 0.65+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ },+ "animateOut": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 64.4+ ],+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "rotation": [+ {+ "t": 0,+ "v": 35,+ "ease": [+ 0.21,+ 0.595,+ 0.415,+ 1.04+ ]+ },+ {+ "t": 1,+ "v": 0+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.33,+ 0.33,+ 0.65,+ 0.65+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "scatter": {+ "label": "Scatter",+ "slots": [+ "in",+ "out"+ ],+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 0.6+ },+ "wiggly": {+ "position": [+ 70,+ 70+ ],+ "rotation": 25,+ "seed": 11+ },+ "animate": {+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ }+}diff --git a/site/packages/effects-kit/src/motion/evaluate.ts b/site/packages/effects-kit/src/motion/evaluate.tsnew file mode 100644index 00000000..3e884786--- /dev/null+++ b/site/packages/effects-kit/src/motion/evaluate.ts@@ -0,0 +1,293 @@+/**+ * The one motion evaluator.+ *+ * Everything that moves in the app — entrances, exits, loops, hold moves and+ * the per-character sweeps — comes through here: sample a property's+ * keyframes at a normalized time, after a range selector has decided what+ * that time is for the unit being drawn. Nothing else computes motion.+ */++import {+ REST_POSE,+ type Easing,+ type MotionPose,+ type MotionPreset,+ type MotionProperties,+ type PropertyKey,+ type RangeSelector,+ type WigglySelector,+} from "./types";++const clamp01 = (v: number) => (v < 0 ? 0 : v > 1 ? 1 : v);+const lerp = (a: number, b: number, p: number) => a + (b - a) * p;++/** A cubic bezier timing function, solved by bisection on x. Curves run+ * [0,0] to [1,1], the same handles Lottie writes and CSS reads. */+export function bezierEase(e: Easing, x: number): number {+ const [x1, y1, x2, y2] = e;+ const at = (a: number, b: number, t: number) =>+ 3 * (1 - t) * (1 - t) * t * a + 3 * (1 - t) * t * t * b + t * t * t;+ let lo = 0;+ let hi = 1;+ for (let i = 0; i < 30; i++) {+ const mid = (lo + hi) / 2;+ if (at(x1, x2, mid) < x) lo = mid;+ else hi = mid;+ }+ return at(y1, y2, (lo + hi) / 2);+}++/** One property's value at normalized time `q`: held before its first key and+ * after its last, eased between. */+export function sampleTrack<V extends number | [number, number]>(+ keys: PropertyKey<V>[] | undefined,+ q: number,+ rest: V+): V {+ if (!keys || keys.length === 0) return rest;+ const t = clamp01(q);+ if (t <= keys[0].t) return keys[0].v;+ const last = keys[keys.length - 1];+ if (t >= last.t) return last.v;+ let i = 0;+ while (i + 1 < keys.length && keys[i + 1].t <= t) i++;+ const a = keys[i];+ const b = keys[i + 1];+ if (a.hold) return a.v;+ const span = b.t - a.t;+ const raw = span > 0 ? (t - a.t) / span : 1;+ const p = a.ease ? bezierEase(a.ease, clamp01(raw)) : clamp01(raw);+ if (typeof a.v === "number") return lerp(a.v as number, b.v as number, p) as V;+ const av = a.v as [number, number];+ const bv = b.v as [number, number];+ return [lerp(av[0], bv[0], p), lerp(av[1], bv[1], p)] as V;+}++/** A track with its `tMax` caps resolved against a known duration. Keys stay+ * in order: a capped key drags the ones after it no earlier than itself. */+function capped<V extends number | [number, number]>(+ keys: PropertyKey<V>[] | undefined,+ dur: number+): PropertyKey<V>[] | undefined {+ if (!keys || dur <= 0 || !keys.some((k) => k.tMax !== undefined)) return keys;+ let floor = 0;+ return keys.map((k) => {+ const t = Math.max(floor, k.tMax === undefined ? k.t : Math.min(k.t, k.tMax / dur));+ floor = t;+ return { ...k, t };+ });+}++/** Every property of a preset sampled at one moment. `dur` resolves any+ * `tMax` caps; omit it and normalized time is used as written. */+export function sampleProperties(props: MotionProperties, q: number, dur = 0): MotionPose {+ if (dur > 0)+ props = {+ position: capped(props.position, dur),+ scale: capped(props.scale, dur),+ rotation: capped(props.rotation, dur),+ opacity: capped(props.opacity, dur),+ tracking: capped(props.tracking, dur),+ reveal: capped(props.reveal, dur),+ typed: capped(props.typed, dur),+ };+ return samplePropertiesRaw(props, q);+}++function samplePropertiesRaw(props: MotionProperties, q: number): MotionPose {+ const pos = sampleTrack(props.position, q, [0, 0] as [number, number]);+ const scale = sampleTrack(props.scale, q, [1, 1] as [number, number]);+ return {+ dx: pos[0],+ dy: pos[1],+ sx: scale[0],+ sy: scale[1],+ rotate: sampleTrack(props.rotation, q, 0),+ alpha: sampleTrack(props.opacity, q, 1),+ tracking: sampleTrack(props.tracking, q, 0),+ ...(props.reveal ? { reveal: sampleTrack(props.reveal, q, 1) } : {}),+ ...(props.typed ? { typed: sampleTrack(props.typed, q, 1) } : {}),+ };+}++/** A deterministic 0..1 draw for unit `i` of a seeded selector. */+function draw(seed: number, i: number, salt = 0): number {+ let h = (Math.imul(seed, 374761393) + Math.imul(i, 668265263) + Math.imul(salt, 2246822519)) >>> 0;+ h = (h ^ (h >>> 13)) >>> 0;+ h = Math.imul(h, 1274126177) >>> 0;+ return ((h ^ (h >>> 16)) >>> 0) / 4294967296;+}++/** 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.randomize) {+ // Rank by the unit's own draw: a stable shuffle that needs no array.+ const mine = draw(sel.seed ?? 1, i);+ let rank = 0;+ for (let j = 0; j < n; j++) if (j !== i && draw(sel.seed ?? 1, j) < mine) rank++;+ return rank;+ }+ switch (sel.shape) {+ case "rampDown":+ return n - 1 - i;+ case "triangle": {+ // Both ends move first, meeting in the middle.+ const mid = (n - 1) / 2;+ return Math.round(mid - Math.abs(i - mid));+ }+ default:+ return i;+ }+}++/** 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): number {+ if (n <= 1) return 0;+ const o = orderOf(sel, i, n);+ const spread = clamp01(sel.spread);+ if (sel.shape === "square") return o / n;+ const u = o / (n - 1);+ switch (sel.shape) {+ case "round":+ // Slow at the ends, quick through the middle.+ return (0.5 - Math.cos(u * Math.PI) / 2) * spread;+ case "smooth":+ return u * u * (3 - 2 * u) * spread;+ default:+ return u * spread;+ }+}++/**+ * Unit `i` of `n`'s own progress when its element's window stands at `p`.+ * This is the whole of what a range selector does: turn one clock into a+ * clock per character.+ */+export function selectorProgress(+ sel: RangeSelector,+ p: number,+ index: number,+ count: number,+ exiting = false+): 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);+ const window = sel.shape === "square" ? 1 / n : Math.max(1e-6, 1 - clamp01(sel.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));+ return q;+}++/**+ * A looping selector hands each unit the same cycle at its own phase, so one+ * turn sweeps the whole line exactly once and the motion stays exactly+ * periodic — which is what lets a frame sequence render one cycle and repeat+ * it for as long as the element runs.+ */+export function loopProgress(+ sel: RangeSelector,+ p: number,+ index: number,+ count: number+): number {+ const n = Math.max(1, count);+ // The order — shuffled when the selector randomizes — is the phase offset,+ // so a run of one always sits at phase 0 and a whole element with no+ // characters plays the cycle exactly as written.+ const q = (p - (orderOf(sel, index, n) / n) * clamp01(sel.spread)) % 1;+ return q < 0 ? q + 1 : q;+}++/** The wiggly selector's fixed draw for one unit, applied on top of the pose.+ * `away` is how far from rest the unit still is, so the stray collapses to+ * nothing as the motion settles. */+function applyWiggly(pose: MotionPose, w: WigglySelector, index: number, away: number): MotionPose {+ const seed = w.seed ?? 7;+ const signed = (salt: number) => draw(seed, index, salt) * 2 - 1;+ const out = { ...pose };+ if (w.position) {+ out.dx += signed(1) * w.position[0] * away;+ out.dy += signed(2) * w.position[1] * away;+ }+ if (w.rotation) out.rotate += signed(3) * w.rotation * away;+ if (w.scale) {+ out.sx *= 1 + signed(4) * (w.scale[0] - 1) * away;+ out.sy *= 1 + signed(5) * (w.scale[1] - 1) * away;+ }+ return out;+}++/**+ * A preset's pose for one unit at window position `p`.+ *+ * `index`/`count` place the unit in its run; an element moving as one piece is+ * unit 0 of 1. `exiting` picks the exit track and reverses the sweep.+ */+export function evalPreset(+ preset: MotionPreset,+ p: number,+ index = 0,+ count = 1,+ exiting = false,+ dur = 0+): MotionPose {+ const props = exiting && preset.animateOut ? preset.animateOut : preset.animate;+ const q = !preset.selector+ ? clamp01(p)+ : preset.period !== undefined+ ? loopProgress(preset.selector, p, index, count)+ : selectorProgress(preset.selector, p, index, count, exiting);+ const pose = sampleProperties(props, q, dur);+ return preset.wiggly ? applyWiggly(pose, preset.wiggly, index, 1 - q) : pose;+}++/**+ * A preset's pose for the element as ONE piece, ignoring any selector: the+ * whole box plays the motion once over the window. This is what a renderer+ * with a single cached picture draws, and what every non-text kind gets from+ * a per-character style.+ */+export function evalWhole(+ preset: MotionPreset,+ p: number,+ exiting = false,+ dur = 0+): MotionPose {+ const props = exiting && preset.animateOut ? preset.animateOut : preset.animate;+ const q = clamp01(p);+ const pose = sampleProperties(props, q, dur);+ // A wiggly preset keeps its stray here too — it is the whole motion of a+ // scatter, and dropping it would leave the element with only its fade.+ return preset.wiggly ? applyWiggly(pose, preset.wiggly, 0, 1 - q) : pose;+}++/** How far a preset ever strays from rest, in design px, and whether it turns.+ * Read from the data, so a new preset never has to be registered anywhere for+ * the frame sampler to pad its crop correctly. */+export function presetExtent(preset: MotionPreset): { travel: number; rotates: boolean } {+ let travel = 0;+ let rotates = false;+ for (const props of [preset.animate, preset.animateOut]) {+ if (!props) continue;+ // A unit carries both: the whole line's offset, plus its own share of the+ // spread, so the one that gets farthest gets the sum of the two.+ let offset = 0;+ let spread = 0;+ for (const k of props.position ?? [])+ offset = Math.max(offset, Math.abs(k.v[0]), Math.abs(k.v[1]));+ for (const k of props.tracking ?? []) spread = Math.max(spread, Math.abs(k.v));+ travel = Math.max(travel, offset + spread);+ if ((props.rotation ?? []).some((k) => k.v !== 0)) rotates = true;+ }+ if (preset.wiggly?.position)+ travel += Math.max(preset.wiggly.position[0], preset.wiggly.position[1]);+ if (preset.wiggly?.rotation) rotates = true;+ return { travel, rotates };+}++export { REST_POSE };diff --git a/site/packages/effects-kit/src/motion/holds.json b/site/packages/effects-kit/src/motion/holds.jsonnew file mode 100644index 00000000..5c7a508e--- /dev/null+++ b/site/packages/effects-kit/src/motion/holds.json@@ -0,0 +1,895 @@+{+ "push": {+ "label": "Push in",+ "note": "A slow zoom in across the whole hold \u2014 the workhorse for a line that has to feel urgent.",+ "slots": [+ "hold"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 1.16,+ 1.16+ ]+ }+ ]+ }+ },+ "pull": {+ "label": "Pull out",+ "note": "A slow zoom out, the frame opening up. Endings, reveals, the last line of a verse.",+ "slots": [+ "hold"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1.16,+ 1.16+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ]+ }+ },+ "settle": {+ "label": "Settle",+ "note": "Lands oversized and leaning, eases to rest in the first third, then creeps. Hero lines.",+ "slots": [+ "hold"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1.14,+ 1.14+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.35,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ],+ "tMax": 0.55+ },+ {+ "t": 1,+ "v": [+ 1.03,+ 1.03+ ]+ }+ ],+ "rotation": [+ {+ "t": 0,+ "v": -4,+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.35,+ "v": 0,+ "tMax": 0.55+ }+ ]+ }+ },+ "swing": {+ "label": "Swing",+ "note": "Overshoots past its resting angle and swings back. Playful, hand-drawn.",+ "slots": [+ "hold"+ ],+ "animate": {+ "rotation": [+ {+ "t": 0,+ "v": -14,+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.35,+ "v": 7,+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.62,+ "v": -3,+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": 0+ }+ ],+ "scale": [+ {+ "t": 0,+ "v": [+ 0.94,+ 0.94+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.35,+ "v": [+ 1,+ 1+ ]+ }+ ]+ }+ },+ "punch": {+ "label": "Punch",+ "note": "Snaps big, snaps back, then creeps. A hit on the beat.",+ "slots": [+ "hold"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1.3,+ 1.3+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.2,+ "v": [+ 0.97,+ 0.97+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ],+ "tMax": 0.18+ },+ {+ "t": 0.35,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ],+ "tMax": 0.32+ },+ {+ "t": 1,+ "v": [+ 1.06,+ 1.06+ ]+ }+ ]+ }+ },+ "float": {+ "label": "Float",+ "note": "Rises a little the whole time it is up. Dreamy, weightless.",+ "slots": [+ "hold"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 43+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ -43+ ]+ }+ ]+ }+ },+ "sink": {+ "label": "Sink",+ "note": "Drifts down. Regret, endings, a line that gives up.",+ "slots": [+ "hold"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -43+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 54+ ]+ }+ ]+ }+ },+ "driftleft": {+ "label": "Drift left",+ "note": "Slides steadily left across the hold \u2014 a parallax bed under other lines.",+ "slots": [+ "hold"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 115,+ 0+ ]+ },+ {+ "t": 1,+ "v": [+ -115,+ 0+ ]+ }+ ]+ }+ },+ "driftright": {+ "label": "Drift right",+ "note": "Slides steadily right.",+ "slots": [+ "hold"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ -115,+ 0+ ]+ },+ {+ "t": 1,+ "v": [+ 115,+ 0+ ]+ }+ ]+ }+ },+ "sway": {+ "label": "Sway",+ "note": "Leans one way, then the other, and back to level. Drunk, loose, swung.",+ "slots": [+ "hold"+ ],+ "animate": {+ "rotation": [+ {+ "t": 0,+ "v": -5,+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.5,+ "v": 5,+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": -2+ }+ ]+ }+ },+ "arc": {+ "label": "Arc",+ "note": "Travels along a shallow curve rather than a straight line.",+ "slots": [+ "hold"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ -150,+ 32+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.5,+ "v": [+ 0,+ -54+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 150,+ 32+ ]+ }+ ]+ }+ },+ "tiltsettle": {+ "label": "Tilt settle",+ "note": "Arrives rotated a quarter turn out and unwinds to level.",+ "slots": [+ "hold"+ ],+ "animate": {+ "rotation": [+ {+ "t": 0,+ "v": -25,+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.45,+ "v": 0,+ "tMax": 0.6+ }+ ],+ "scale": [+ {+ "t": 0,+ "v": [+ 0.9,+ 0.9+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.45,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 1.04,+ 1.04+ ]+ }+ ]+ }+ },+ "breathe": {+ "label": "Breathe",+ "note": "Grows and shrinks a few percent, twice. Living, patient.",+ "slots": [+ "hold"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.25,+ "v": [+ 1.05,+ 1.05+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.5,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": [+ 1.05,+ 1.05+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ]+ }+ },+ "creep": {+ "label": "Creep",+ "note": "A scale rise so slow you only notice it in the cut. Dread, tension.",+ "slots": [+ "hold"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 0.98,+ 0.98+ ]+ },+ {+ "t": 1,+ "v": [+ 1.06,+ 1.06+ ]+ }+ ]+ }+ },+ "slam": {+ "label": "Slam",+ "note": "Enormous for two frames, then hard down to rest. Impact.",+ "slots": [+ "hold"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1.9,+ 1.9+ ],+ "ease": [+ 0.55,+ 0.055,+ 0.675,+ 0.19+ ]+ },+ {+ "t": 0.12,+ "v": [+ 0.94,+ 0.94+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ],+ "tMax": 0.1+ },+ {+ "t": 0.22,+ "v": [+ 1,+ 1+ ],+ "tMax": 0.2+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0.6,+ "ease": [+ 0.55,+ 0.055,+ 0.675,+ 0.19+ ]+ },+ {+ "t": 0.12,+ "v": 1,+ "tMax": 0.1+ }+ ]+ }+ },+ "orbit": {+ "label": "Orbit",+ "note": "Circles its own resting point once. Playful chaos.",+ "slots": [+ "hold"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.25,+ "v": [+ 54,+ -43+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.5,+ "v": [+ 0,+ -76+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": [+ -54,+ -43+ ],+ "ease": [+ 0.645,+ 0.045,+ 0.355,+ 1+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ]+ }+ },+ "spring": {+ "label": "Spring",+ "note": "Overshoots the size and bounces once past it before resting.",+ "slots": [+ "hold"+ ],+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 0.6,+ 0.6+ ],+ "ease": [+ 0.34,+ 1.56,+ 0.64,+ 1+ ]+ },+ {+ "t": 0.3,+ "v": [+ 1.18,+ 1.18+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ],+ "tMax": 0.22+ },+ {+ "t": 0.48,+ "v": [+ 0.96,+ 0.96+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ],+ "tMax": 0.38+ },+ {+ "t": 0.62,+ "v": [+ 1,+ 1+ ],+ "tMax": 0.5+ }+ ]+ }+ },+ "fall": {+ "label": "Fall",+ "note": "Drops in from above resting position and stops dead. Weight.",+ "slots": [+ "hold"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -237+ ],+ "ease": [+ 0.55,+ 0.055,+ 0.675,+ 0.19+ ]+ },+ {+ "t": 0.3,+ "v": [+ 0,+ 0+ ],+ "tMax": 0.28+ }+ ],+ "scale": [+ {+ "t": 0,+ "v": [+ 1.1,+ 1.1+ ],+ "ease": [+ 0.55,+ 0.055,+ 0.675,+ 0.19+ ]+ },+ {+ "t": 0.3,+ "v": [+ 1,+ 1+ ]+ }+ ]+ }+ },+ "reveal": {+ "label": "Reveal",+ "note": "Starts offset up at zero opacity and eases down into place.",+ "slots": [+ "hold"+ ],+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ -65+ ],+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.3,+ "v": [+ 0,+ 0+ ],+ "tMax": 0.4+ }+ ],+ "opacity": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.215,+ 0.61,+ 0.355,+ 1+ ]+ },+ {+ "t": 0.3,+ "v": 1,+ "tMax": 0.4+ }+ ]+ }+ }+}diff --git a/site/packages/effects-kit/src/motion/loops.json b/site/packages/effects-kit/src/motion/loops.jsonnew file mode 100644index 00000000..a451f1f0--- /dev/null+++ b/site/packages/effects-kit/src/motion/loops.json@@ -0,0 +1,1028 @@+{+ "pulse": {+ "label": "Pulse",+ "slots": [+ "loop"+ ],+ "period": 1.2,+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": [+ 1.06,+ 1.06+ ],+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": [+ 0.94,+ 0.94+ ],+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ]+ }+ },+ "heartbeat": {+ "label": "Heartbeat",+ "slots": [+ "loop"+ ],+ "period": 1.5,+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1.0237,+ 1.0237+ ],+ "ease": [+ 0.41,+ 0.285,+ 0.67,+ 0.985+ ]+ },+ {+ "t": 0.0594,+ "v": [+ 1.14,+ 1.14+ ],+ "ease": [+ 0.335,+ -0.015,+ 0.565,+ 0.99+ ]+ },+ {+ "t": 0.1313,+ "v": [+ 1.025,+ 1.025+ ],+ "ease": [+ 0.365,+ -0.02,+ 0.65,+ 1.01+ ]+ },+ {+ "t": 0.2,+ "v": [+ 1.09,+ 1.09+ ],+ "ease": [+ 0.315,+ 0.04,+ 0.4,+ 0.99+ ]+ },+ {+ "t": 0.3063,+ "v": [+ 1.001,+ 1.001+ ],+ "ease": [+ 0.94,+ -0.11,+ 0.975,+ -0.48+ ]+ },+ {+ "t": 1,+ "v": [+ 1.0237,+ 1.0237+ ]+ }+ ]+ }+ },+ "float": {+ "label": "Float",+ "slots": [+ "loop"+ ],+ "period": 2.4,+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": [+ 0,+ 12+ ],+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": [+ 0,+ -12+ ],+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ]+ }+ },+ "sway": {+ "label": "Sway",+ "slots": [+ "loop"+ ],+ "period": 2.8,+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": [+ 18,+ 0+ ],+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": [+ -18,+ 0+ ],+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "rotation": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": 3,+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": -3,+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": 0+ }+ ]+ }+ },+ "spin": {+ "label": "Spin",+ "slots": [+ "loop"+ ],+ "period": 4,+ "animate": {+ "rotation": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.335,+ 0.335,+ 0.665,+ 0.665+ ]+ },+ {+ "t": 1,+ "v": 360+ }+ ]+ }+ },+ "wiggle": {+ "label": "Wiggle",+ "slots": [+ "loop"+ ],+ "period": 0.9,+ "animate": {+ "rotation": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": 4,+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": -4,+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": 0+ }+ ]+ }+ },+ "shake": {+ "label": "Shake",+ "slots": [+ "loop"+ ],+ "period": 0.5,+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.485,+ 0.805,+ 0.715,+ 0.985+ ]+ },+ {+ "t": 0.0688,+ "v": [+ 4.2629,+ 3.8305+ ],+ "ease": [+ 0.32,+ -0.04,+ 0.585,+ 1.02+ ]+ },+ {+ "t": 0.1094,+ "v": [+ 5.0472,+ 2.9374+ ],+ "ease": [+ 0.405,+ 0.06,+ 0.565,+ 0.945+ ]+ },+ {+ "t": 0.1656,+ "v": [+ 3.9735,+ 1.6962+ ],+ "ease": [+ 0.385,+ 0.06,+ 0.645,+ 1.035+ ]+ },+ {+ "t": 0.2188,+ "v": [+ 2.4255,+ 2.1293+ ],+ "ease": [+ 0.425,+ 0,+ 0.64,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": [+ 2.1,+ 1.47+ ],+ "ease": [+ 0.435,+ 0.055,+ 0.595,+ 0.94+ ]+ },+ {+ "t": 0.3563,+ "v": [+ 4.5989,+ -4.777+ ],+ "ease": [+ 0.385,+ 0.06,+ 0.49,+ 0.99+ ]+ },+ {+ "t": 0.3906,+ "v": [+ 5.0472,+ -3.7908+ ],+ "ease": [+ 0.385,+ 0,+ 0.615,+ 1+ ]+ },+ {+ "t": 0.4875,+ "v": [+ 0.9289,+ 0.026+ ],+ "ease": [+ 0.34,+ 0.015,+ 0.66,+ 0.985+ ]+ },+ {+ "t": 0.5125,+ "v": [+ -0.9289,+ -0.026+ ],+ "ease": [+ 0.51,+ 0.01,+ 0.615,+ 0.94+ ]+ },+ {+ "t": 0.6094,+ "v": [+ -5.0472,+ 3.7908+ ],+ "ease": [+ 0.405,+ 0.06,+ 0.565,+ 0.945+ ]+ },+ {+ "t": 0.6438,+ "v": [+ -4.5989,+ 4.777+ ],+ "ease": [+ 0.36,+ 0.02,+ 0.575,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": [+ -2.1,+ -1.47+ ],+ "ease": [+ 0.435,+ 0.055,+ 0.595,+ 0.94+ ]+ },+ {+ "t": 0.7813,+ "v": [+ -2.4255,+ -2.1293+ ],+ "ease": [+ 0.355,+ -0.035,+ 0.615,+ 0.94+ ]+ },+ {+ "t": 0.8344,+ "v": [+ -3.9735,+ -1.6962+ ],+ "ease": [+ 0.415,+ -0.02,+ 0.68,+ 1.04+ ]+ },+ {+ "t": 0.8906,+ "v": [+ -5.0472,+ -2.9374+ ],+ "ease": [+ 0.285,+ 0.015,+ 0.515,+ 0.195+ ]+ },+ {+ "t": 0.9313,+ "v": [+ -4.2629,+ -3.8305+ ],+ "ease": [+ 0.185,+ 0.025,+ 0.41,+ 0.02+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ]+ }+ },+ "flicker": {+ "label": "Flicker",+ "slots": [+ "loop"+ ],+ "period": 1.8,+ "animate": {+ "opacity": [+ {+ "t": 0,+ "v": 1,+ "ease": [+ 0.53,+ 0.46,+ 0.58,+ 0.925+ ]+ },+ {+ "t": 0.0781,+ "v": 0.7786,+ "ease": [+ 0.375,+ -0.015,+ 0.665,+ 0.98+ ]+ },+ {+ "t": 0.1469,+ "v": 0.9115,+ "ease": [+ 0.445,+ 0.02,+ 0.59,+ 0.94+ ]+ },+ {+ "t": 0.25,+ "v": 0.45,+ "ease": [+ 0.41,+ 0.06,+ 0.555,+ 0.98+ ]+ },+ {+ "t": 0.3531,+ "v": 0.9115,+ "ease": [+ 0.335,+ 0.02,+ 0.625,+ 1.015+ ]+ },+ {+ "t": 0.4219,+ "v": 0.7786,+ "ease": [+ 0.42,+ 0.075,+ 0.47,+ 0.54+ ]+ },+ {+ "t": 0.5,+ "v": 1+ },+ {+ "t": 1,+ "v": 1+ }+ ]+ }+ },+ "wave": {+ "label": "Wave",+ "slots": [+ "loop"+ ],+ "period": 1.6,+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 1+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": [+ 0,+ -16+ ],+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": [+ 0,+ 16+ ],+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ]+ }+ },+ "bounce": {+ "label": "Bounce",+ "slots": [+ "loop"+ ],+ "period": 1.6,+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 1+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": [+ 0,+ -24+ ],+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 0.5,+ "v": [+ 0,+ 0+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "scale": [+ {+ "t": 0,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": [+ 0.95,+ 1.07+ ],+ "ease": [+ 0.6,+ 0.125,+ 0.635,+ 0.995+ ]+ },+ {+ "t": 0.75,+ "v": [+ 1.08,+ 0.9+ ],+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ]+ }+ },+ "flip": {+ "label": "Flip",+ "slots": [+ "loop"+ ],+ "period": 3.2,+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 1+ },+ "animate": {+ "scale": [+ {+ "t": 0,+ "v": [+ 1,+ 1+ ],+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.2,+ "v": [+ 1,+ -1+ ],+ "ease": [+ 0.36,+ -0.005,+ 0.64,+ 0.915+ ]+ },+ {+ "t": 0.3906,+ "v": [+ 1,+ 0.9892+ ],+ "ease": [+ 0,+ 1.93,+ 0.03,+ 0.71+ ]+ },+ {+ "t": 1,+ "v": [+ 1,+ 1+ ]+ }+ ]+ }+ },+ "flutter": {+ "label": "Flutter",+ "slots": [+ "loop"+ ],+ "period": 1.4,+ "selector": {+ "basedOn": "characters",+ "shape": "rampUp",+ "spread": 1,+ "randomize": true,+ "seed": 3+ },+ "animate": {+ "position": [+ {+ "t": 0,+ "v": [+ 0,+ 0+ ],+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.25,+ "v": [+ 5,+ 5+ ],+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.75,+ "v": [+ -5,+ -5+ ],+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": [+ 0,+ 0+ ]+ }+ ],+ "rotation": [+ {+ "t": 0,+ "v": 0,+ "ease": [+ 0.58,+ 0.94,+ 0.79,+ 0.98+ ]+ },+ {+ "t": 0.125,+ "v": 5,+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.375,+ "v": -5,+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.625,+ "v": 5,+ "ease": [+ 0.365,+ 0,+ 0.635,+ 1+ ]+ },+ {+ "t": 0.875,+ "v": -5,+ "ease": [+ 0.21,+ 0.02,+ 0.42,+ 0.06+ ]+ },+ {+ "t": 1,+ "v": 0+ }+ ]+ }+ }+}diff --git a/site/packages/effects-kit/src/motion/motion.test.ts b/site/packages/effects-kit/src/motion/motion.test.tsnew file mode 100644index 00000000..19ca6136--- /dev/null+++ b/site/packages/effects-kit/src/motion/motion.test.ts@@ -0,0 +1,271 @@+import { describe, expect, test } from "bun:test";+import {+ GLYPH_ANIM_STYLE_IDS,+ GLYPH_LOOP_STYLE_IDS,+ OVERLAY_ANIM_STYLE_IDS,+ OVERLAY_LOOP_STYLE_IDS,+ bakesPixels,+ evalOverlayAnim,+ glyphAnimAt,+ glyphStateAt,+ loopExtent,+ loopPeriod,+} from "../anim";+import { MOTION, presetsFor } from "./catalog";+import { evalPreset, sampleProperties, sampleTrack } from "./evaluate";+import type { MotionPreset, PropertyKey } from "./types";++/**+ * The catalog is the whole animation library, so what it has to satisfy is+ * structural: keys in order inside the window, loops that close, and ids the+ * saved-doc unions still name.+ */++const everyPreset = (): [string, MotionPreset][] => [+ ...Object.entries(MOTION.edges),+ ...Object.entries(MOTION.loops),+ ...Object.entries(MOTION.holds),+];++const tracks = (p: MotionPreset): PropertyKey<never>[][] =>+ [p.animate, p.animateOut].flatMap((props) =>+ props ? (Object.values(props) as PropertyKey<never>[][]) : []+ );++describe("the motion catalog", () => {+ test("every preset keys inside its window, in order", () => {+ for (const [, preset] of everyPreset()) {+ expect(preset.label.length).toBeGreaterThan(0);+ expect(preset.slots.length).toBeGreaterThan(0);+ expect(tracks(preset).length).toBeGreaterThan(0);+ for (const track of tracks(preset)) {+ expect(track.length).toBeGreaterThan(0);+ for (let i = 0; i < track.length; i++) {+ expect(track[i].t).toBeGreaterThanOrEqual(0);+ expect(track[i].t).toBeLessThanOrEqual(1);+ if (i > 0) expect(track[i].t).toBeGreaterThan(track[i - 1].t);+ if (track[i].ease)+ expect(track[i].ease!.length).toBe(4);+ }+ }+ }+ });++ test("a loop closes on itself, so one rendered cycle can repeat forever", () => {+ for (const [id, preset] of Object.entries(MOTION.loops)) {+ expect(preset.period).toBeGreaterThan(0);+ const start = evalPreset(preset, 0);+ const end = evalPreset(preset, 1);+ // Spin is the exception every rotation system has: a full turn lands+ // back where it started, 360 degrees on.+ const turn = id === "spin" ? 360 : 0;+ expect(Math.abs(end.dx - start.dx)).toBeLessThan(0.5);+ expect(Math.abs(end.dy - start.dy)).toBeLessThan(0.5);+ expect(Math.abs(end.sx - start.sx)).toBeLessThan(0.01);+ expect(Math.abs(end.rotate - start.rotate - turn)).toBeLessThan(0.5);+ expect(Math.abs(end.alpha - start.alpha)).toBeLessThan(0.02);+ }+ });++ test("a ramp starts away from rest and lands on it", () => {+ for (const [, preset] of Object.entries(MOTION.edges)) {+ const end = evalPreset(preset, 1);+ expect(Math.abs(end.dx)).toBeLessThan(0.5);+ expect(Math.abs(end.dy)).toBeLessThan(0.5);+ expect(Math.abs(end.sx - 1)).toBeLessThan(0.01);+ expect(Math.abs(end.rotate)).toBeLessThan(0.5);+ expect(Math.abs(end.alpha - 1)).toBeLessThan(0.01);+ expect(Math.abs(end.tracking)).toBeLessThan(0.5);+ }+ });++ test("the saved-doc ids and the data name the same presets", () => {+ expect([...OVERLAY_ANIM_STYLE_IDS].sort()).toEqual(Object.keys(MOTION.edges).sort());+ expect([...OVERLAY_LOOP_STYLE_IDS].sort()).toEqual(Object.keys(MOTION.loops).sort());+ for (const id of GLYPH_ANIM_STYLE_IDS) expect(!!MOTION.edges[id].selector).toBe(true);+ for (const id of GLYPH_LOOP_STYLE_IDS) expect(!!MOTION.loops[id].selector).toBe(true);+ for (const slot of ["in", "out", "loop", "hold"] as const)+ expect(presetsFor(slot).length).toBeGreaterThan(0);+ });++ test("a hold move says what it is for", () => {+ for (const [, preset] of Object.entries(MOTION.holds))+ expect(preset.note?.length ?? 0).toBeGreaterThan(0);+ });+});++describe("the evaluator", () => {+ test("a track holds before its first key and after its last", () => {+ const keys: PropertyKey<number>[] = [+ { t: 0.25, v: 10 },+ { t: 0.75, v: 20 },+ ];+ expect(sampleTrack(keys, 0, 0)).toBe(10);+ expect(sampleTrack(keys, 0.5, 0)).toBeCloseTo(15, 5);+ expect(sampleTrack(keys, 1, 0)).toBe(20);+ expect(sampleTrack(undefined, 0.5, 3)).toBe(3);+ });++ test("a hold key steps instead of ramping", () => {+ const keys: PropertyKey<number>[] = [+ { t: 0, v: 0, hold: true },+ { t: 1, v: 1 },+ ];+ expect(sampleTrack(keys, 0.99, 0)).toBe(0);+ });++ test("easing bends the ramp without moving its ends", () => {+ const eased: PropertyKey<number>[] = [+ { t: 0, v: 0, ease: [0.9, 0, 1, 0.1] },+ { t: 1, v: 1 },+ ];+ expect(sampleTrack(eased, 0, 0)).toBe(0);+ expect(sampleTrack(eased, 1, 0)).toBe(1);+ expect(sampleTrack(eased, 0.5, 0)).toBeLessThan(0.4);+ });++ test("a tMax cap keeps a hit short however long the element runs", () => {+ const props = { scale: [{ t: 0, v: [2, 2] as [number, number] }, { t: 0.5, v: [1, 1] as [number, number], tMax: 0.2 }] };+ // Over six seconds the second key lands at 0.2s, not at three seconds.+ expect(sampleProperties(props, 0.2 / 6, 6).sx).toBeCloseTo(1, 2);+ // Over half a second the cap is not binding and normalized time stands.+ expect(sampleProperties(props, 0.5, 0.5).sx).toBeCloseTo(1, 2);+ });++ test("a selector hands the motion down the line", () => {+ // Early in a rise, the first character has moved further than the last.+ const first = glyphAnimAt({ style: "rise", p: 0.3, exiting: false }, 0, 8);+ const last = glyphAnimAt({ style: "rise", p: 0.3, exiting: false }, 7, 8);+ expect(Math.abs(first.dy)).toBeLessThan(Math.abs(last.dy));+ });++ test("a wiggly entrance still strays on an element with no characters", () => {+ // A scatter's whole motion is its per-unit stray; a shape or a sticker+ // has no characters to hand it to and plays it as one piece.+ const st = evalOverlayAnim({ in: { style: "scatter", seconds: 1 } }, 0.2, 3, false);+ expect(Math.hypot(st.dx, st.dy)).toBeGreaterThan(1);+ });++ test("every style evaluates over its whole window without going wild", () => {+ for (const style of OVERLAY_ANIM_STYLE_IDS) {+ for (const isText of [false, true]) {+ for (let i = 0; i <= 20; i++) {+ const st = evalOverlayAnim(+ { in: { style, seconds: 1 }, out: { style, seconds: 1 } },+ (i / 20) * 3,+ 3,+ isText+ );+ expect(Number.isFinite(st.dx)).toBe(true);+ expect(Number.isFinite(st.scale)).toBe(true);+ expect(st.alpha).toBeGreaterThanOrEqual(0);+ expect(st.alpha).toBeLessThanOrEqual(1.001);+ }+ }+ }+ });++ test("loop speed divides the period", () => {+ for (const style of OVERLAY_LOOP_STYLE_IDS) {+ const base = loopPeriod({ loop: { style, speed: 1 } })!;+ expect(loopPeriod({ loop: { style, speed: 2 } })).toBeCloseTo(base / 2, 5);+ }+ });+});++describe("presets are data, not code", () => {+ test("a preset invented at runtime evaluates like any other", () => {+ const invented: MotionPreset = {+ label: "Test",+ slots: ["in"],+ selector: { basedOn: "characters", shape: "rampDown", spread: 0.5 },+ animate: {+ position: [+ { t: 0, v: [0, 200] },+ { t: 1, v: [0, 0] },+ ],+ },+ };+ // rampDown deals the last character first, so it is the one already on+ // its way home while the first has not started.+ expect(Math.abs(evalPreset(invented, 0.2, 0, 4).dy)).toBeGreaterThan(+ Math.abs(evalPreset(invented, 0.2, 3, 4).dy)+ );+ expect(evalPreset(invented, 1, 0, 4).dy).toBeCloseTo(0, 5);+ });+});++/**+ * A composed animation is a preset the project carries instead of naming, so+ * what has to hold is that nothing downstream can tell the two apart: the+ * evaluator, the per-character path, the crop padding and the bake decision+ * all read the preset, never the id.+ */+describe("a slot's own preset", () => {+ const DIVE: MotionPreset = {+ label: "Dive",+ slots: ["in"],+ animate: {+ position: [+ { t: 0, v: [0, -300] },+ { t: 1, v: [0, 0] },+ ],+ opacity: [+ { t: 0, v: 0 },+ { t: 0.4, v: 1 },+ ],+ },+ };+ const SWEEP: MotionPreset = {+ ...DIVE,+ label: "Sweep",+ selector: { basedOn: "characters", shape: "rampUp", spread: 0.6 },+ };++ test("plays instead of the style it is filed under", () => {+ const at = (anim: Parameters<typeof evalOverlayAnim>[0]) => evalOverlayAnim(anim, 0.25, 2);+ const named = at({ in: { style: "fade", seconds: 1 } });+ const composed = at({ in: { style: "fade", seconds: 1, preset: DIVE } });+ expect(named.dy).toBe(0);+ expect(composed.dy).toBeLessThan(-100);+ // It lands where any ramp lands: at rest by the end of its window.+ const done = evalOverlayAnim({ in: { style: "fade", seconds: 1, preset: DIVE } }, 1, 2);+ expect(done.dy).toBeCloseTo(0, 5);+ });++ test("reaches the characters when it carries a selector", () => {+ const st = evalOverlayAnim({ in: { style: "fade", seconds: 1, preset: SWEEP } }, 0.3, 2, true);+ expect(!!st.glyphs).toBe(true);+ const first = glyphStateAt(st, 0, 8);+ const last = glyphStateAt(st, 7, 8);+ // rampUp deals the first character first, so it is nearer home.+ expect(Math.abs(first.dy)).toBeLessThan(Math.abs(last.dy));+ });++ test("a loop of its own sets the period and the extent", () => {+ const spin: MotionPreset = {+ label: "Turn",+ slots: ["loop"],+ period: 3,+ animate: {+ position: [+ { t: 0, v: [0, 0] },+ { t: 0.5, v: [80, 0] },+ { t: 1, v: [0, 0] },+ ],+ },+ };+ expect(loopPeriod({ loop: { style: "float", speed: 2, preset: spin } })).toBeCloseTo(1.5, 5);+ expect(loopExtent({ style: "float", speed: 1, preset: spin }).travel).toBe(80);+ });++ test("decides its own bake from its channels", () => {+ expect(bakesPixels({ style: "fade", seconds: 1, preset: DIVE }, true)).toBe(false);+ expect(bakesPixels({ style: "fade", seconds: 1, preset: SWEEP }, true)).toBe(true);+ const wipe: MotionPreset = {+ ...DIVE,+ animate: { reveal: [{ t: 0, v: 0 }, { t: 1, v: 1 }] },+ };+ expect(bakesPixels({ style: "fade", seconds: 1, preset: wipe }, false)).toBe(true);+ });+});diff --git a/site/packages/effects-kit/src/motion/types.ts b/site/packages/effects-kit/src/motion/types.tsnew file mode 100644index 00000000..cb5dd75f--- /dev/null+++ b/site/packages/effects-kit/src/motion/types.ts@@ -0,0 +1,153 @@+/**+ * The motion preset format: keyframes plus a range selector.+ *+ * This is After Effects' text-animator model, which Lottie serializes and+ * which GSAP and Motion reimplement as "split text + stagger". An animation+ * is a keyframed pose, and a selector decides how that pose is handed from+ * one character to the next. Every entrance, exit, loop and hold move in the+ * app is one entry in that format, stored as data beside this file — there is+ * no second way to describe motion here.+ *+ * Times are normalized: `t` runs 0..1 across the window the preset is playing+ * in (an entrance ramp, an exit ramp, one loop cycle, or the element's whole+ * hold). Offsets are design px at the 1080 short side; scales multiply;+ * rotation is degrees clockwise; opacity multiplies the element's own.+ */++/** Cubic bezier timing handles, [x1, y1, x2, y2], the curve running [0,0] to+ * [1,1] — the same shape Lottie's `o`/`i` handles and CSS cubic-bezier take.+ * Absent = linear. */+export type Easing = [number, number, number, number];++/**+ * One keyframe of one property. `ease` is the curve OUT of this key and into+ * the next; `hold` steps instead of interpolating. Easing is per property,+ * not per moment — position and opacity on the same preset routinely want+ * different curves, which is why Lottie keys each property separately and so+ * does this.+ */+export interface PropertyKey<V> {+ t: number;+ v: V;+ ease?: Easing;+ hold?: boolean;+ /** Seconds this key may never fall later than. Normalized time stretches+ * with the element, which is right for a ramp and wrong for a hit: a punch+ * lands in a fifth of a second whether the line holds for one beat or six.+ * Only read when the caller knows the element's duration. */+ tMax?: number;+}++/**+ * The animated properties of a preset. Every one is optional; an absent+ * property simply does not move. Offsets are design px at the 1080 short+ * side, scales multiply, rotation is degrees clockwise, opacity multiplies+ * the element's own.+ */+export interface MotionProperties {+ /** Offset from the element's resting position. */+ position?: PropertyKey<[number, number]>[];+ /** Per-axis scale. A flip runs one axis through zero. */+ scale?: PropertyKey<[number, number]>[];+ rotation?: PropertyKey<number>[];+ opacity?: PropertyKey<number>[];+ /** How far the line spreads about its center — After Effects' tracking.+ * Each unit offsets by its own share, so the ends travel and the middle+ * holds. */+ tracking?: PropertyKey<number>[];+ /** Share of the box uncovered from its leading edge, 0..1 (wipes). */+ reveal?: PropertyKey<number>[];+ /** Share of the characters drawn, 0..1 (typewriter). */+ typed?: PropertyKey<number>[];+}++/** What the selector counts as one unit. */+export type SelectorBasis = "characters" | "charactersExcludingSpaces" | "words" | "lines";++/** How the hand-off is distributed across the units — After Effects' Shape. */+export type SelectorShape = "square" | "rampUp" | "rampDown" | "triangle" | "round" | "smooth";++/**+ * Which units are playing, and how far through, at a given moment. Present on+ * a preset = the motion runs unit by unit; absent = the element moves as one+ * piece.+ */+export interface RangeSelector {+ basedOn: SelectorBasis;+ shape: SelectorShape;+ /** Share of the window spent handing the motion from the first unit to the+ * last. 0 = every unit together; 1 = strictly one at a time. */+ spread: number;+ /** Eases the unit's own progress as it enters (`easeHigh`) and leaves+ * (`easeLow`) the selection, 0..1 — After Effects' Ease High / Ease Low. */+ easeHigh?: number;+ easeLow?: number;+ /** Deal the units their turn in a shuffled order rather than in reading+ * order — After Effects' Randomize Order. */+ randomize?: boolean;+ seed?: number;+}++/**+ * Per-unit random amplitude — After Effects' Wiggly Selector. The named+ * amounts are the maximum stray; each unit gets its own fixed draw from the+ * seed, so the same text always scatters the same way.+ */+export interface WigglySelector {+ position?: [number, number];+ rotation?: number;+ scale?: [number, number];+ seed?: number;+}++export type MotionSlot = "in" | "out" | "loop" | "hold";++export interface MotionPreset {+ label: string;+ /** What the move is for, in one line — the text the tool schemas and the+ * assistant's skills are written from. */+ note?: string;+ /** Where this preset may be used. */+ slots: MotionSlot[];+ /** Loops only: one cycle in seconds at speed 1. */+ period?: number;+ selector?: RangeSelector;+ wiggly?: WigglySelector;+ animate: MotionProperties;+ /** An exit that is not simply the entry played backwards. */+ animateOut?: MotionProperties;+}++export interface MotionCatalog {+ version: number;+ /** Entrances and exits, keyed by the id saved on an element. */+ edges: Record<string, MotionPreset>;+ /** Loops that run an element's whole duration. */+ loops: Record<string, MotionPreset>;+ /** Moves an element holds for its whole span, baked onto its own pose+ * track rather than played as a preset. */+ holds: Record<string, MotionPreset>;+}++/** A resolved pose for one unit at one moment. */+export interface MotionPose {+ dx: number;+ dy: number;+ sx: number;+ sy: number;+ rotate: number;+ alpha: number;+ tracking: number;+ reveal?: number;+ typed?: number;+}++export const REST_POSE: MotionPose = {+ dx: 0,+ dy: 0,+ sx: 1,+ sy: 1,+ rotate: 0,+ alpha: 1,+ tracking: 0,+};diff --git a/site/packages/effects-kit/src/render.ts b/site/packages/effects-kit/src/render.tsindex 4e68fa01..ab3e4356 100644--- a/site/packages/effects-kit/src/render.ts+++ b/site/packages/effects-kit/src/render.ts@@ -7,18 +7,16 @@import {bakesPixels,+ edgeMotion,glyphStateAt,- GLYPH_TRAVEL_MAX,hasGlyphMotion,- isGlyphAnimStyle,loopExtent,loopPeriod,- SLIDE_TRAVEL,type GlyphLoopPhase,type GlyphPhase,type OverlayAnim,- type OverlayAnimStyle,} from "./anim";+import { presetExtent } from "./motion/evaluate";import { evalOverlayFrame, hasOverlayKeys, poseAt, poseExtent, sortedKeys } from "./keys";import { applyMaskToCanvas, isMaskAnimated } from "./mask";import type { LottieHandle } from "./lottie";@@ -674,10 +672,7 @@ export function planAnimatedLayers(o: Overlay, end: number): AnimatedLayer[] {const anim: OverlayAnim = o.anim ?? {};const dur = Math.max(0.1, o.end - o.start);const isText = (o.kind ?? "text") === "text";- const baked = (slot: "in" | "out") => {- const style = anim[slot]?.style;- return !!style && bakesPixels(style, isText);- };+ const baked = (slot: "in" | "out") => bakesPixels(anim[slot], isText);const inS = anim.in ? Math.min(anim.in.seconds, dur) : 0;const outS = anim.out ? Math.min(anim.out.seconds, Math.max(0, dur - inS)) : 0;const out: AnimatedLayer[] = [];@@ -702,9 +697,14 @@ export function planAnimatedLayers(o: Overlay, end: number): AnimatedLayer[] {/** One window per slice, each drawn at the ramp's position mid-window. The* slot leaves the window's anim: its motion is in the picture already. */const slices = (from: number, secs: number, slot: "in" | "out") => {- const style = anim[slot]!.style;+ const edge = anim[slot]!;+ // Which of the three bakes this is comes from the preset's own channels,+ // so a composed animation is sliced by what it does.+ const preset = edgeMotion(edge);+ const types = !!preset?.animate.typed;+ const perGlyph = !!preset?.selector;const text = isText ? (o as TextOverlay).text : "";- const cap = style === "typewriter" ? Math.max(1, text.length) : Infinity;+ const cap = types ? Math.max(1, text.length) : Infinity;const n = Math.max(1, Math.min(cap, Math.ceil(secs * TYPE_SLICE_FPS)));const rest: OverlayAnim = { ...anim, [slot]: undefined };for (let i = 0; i < n; i++) {@@ -712,11 +712,13 @@ export function planAnimatedLayers(o: Overlay, end: number): AnimatedLayer[] {const p = slot === "out" ? 1 - mid : mid;const at = from + (i / n) * secs;const to = from + ((i + 1) / n) * secs;- if (style === "typewriter") {+ if (types) {const chars = Math.max(1, Math.ceil(p * text.length));push({ ...o, text: text.slice(0, chars) } as Overlay, at, to, rest);- } else if (isGlyphAnimStyle(style)) {- push(o, at, to, rest, { glyphs: { style, p, exiting: slot === "out" } });+ } else if (perGlyph) {+ push(o, at, to, rest, {+ glyphs: { style: edge.style, preset: edge.preset, p, exiting: slot === "out" },+ });} else {push(o, at, to, rest, { reveal: p });}@@ -782,18 +784,16 @@ export async function renderOverlayFrames(// The crop region: the resting box, grown for travel, scale overshoot,// shadow spill, and — when anything rotates — the circumscribed square.const base = await measureElementBounds(overlay, frame, env);- const styles: OverlayAnimStyle[] = [anim?.in?.style, anim?.out?.style].filter(- (s): s is OverlayAnimStyle => !!s- );- const slides = styles.some((s) => s.startsWith("slide"));- // Glyphs stray from the resting box on their own; pad by the farthest any- // of them travels.- const glyphs = styles.some(isGlyphAnimStyle);- const loop = loopExtent(anim?.loop?.style);- const travel =- (slides ? SLIDE_TRAVEL : 0) * scale +- (glyphs ? GLYPH_TRAVEL_MAX : 0) * scale +- loop.travel * scale;+ // Read from the presets themselves, so a composed animation pads its crop+ // by what it actually travels rather than by what its name suggests.+ const edges = [anim?.in, anim?.out]+ .map(edgeMotion)+ .filter((p): p is NonNullable<typeof p> => !!p);+ const edgeTravel = edges.reduce((max, p) => Math.max(max, presetExtent(p).travel), 0);+ // A per-glyph ramp hands each character its share of the same tracks, so+ // the preset's own reach already covers where the glyphs get to.+ const loop = loopExtent(anim?.loop);+ const travel = (edgeTravel + loop.travel) * scale;// A keyframed element carries its own travel and its own zoom: the region// spans every pose the track visits, at the largest scale it reaches.const keyed = hasOverlayKeys(overlay);diff --git a/site/src/cut/components/AnimationTiles.tools.ts b/site/src/cut/components/AnimationTiles.tools.tsindex 693fd63c..5f1deb5d 100644--- a/site/src/cut/components/AnimationTiles.tools.ts+++ b/site/src/cut/components/AnimationTiles.tools.ts@@ -18,6 +18,12 @@ import {OVERLAY_LOOP_STYLE_IDS,} from "@donkeycut/effects-kit";import { num, obj, str, type AiToolDef } from "@/cut/lib/aiToolDef";+import {+ MOVE_STRENGTH_MAX,+ MOVE_STRENGTH_MIN,+ TEXT_MOVE_IDS,+ TEXT_MOVE_NOTES,+} from "@/cut/lib/textMotion";const RAMP_SECONDS = `${OVERLAY_ANIM_MIN_SECONDS}..${OVERLAY_ANIM_MAX_SECONDS} (default ${OVERLAY_ANIM_DEFAULT_SECONDS})`;@@ -25,9 +31,17 @@ export const OVERLAY_ANIMATION_TOOLS = [{name: "set_overlay_animation",description:- `Animate an overlay element (title, shape, or sticker): preset In/Out ramps plus a Loop that runs its whole duration. Omitted slots keep their setting; pass "none" to clear one. In/Out styles: ${OVERLAY_ANIM_STYLE_IDS.join(", ")} — slide names are the motion direction; typewriter animates titles only; ${GLYPH_ANIM_STYLE_IDS.join(", ")} move a title's letters one at a time, and move any other kind as one piece. Loop styles: ${OVERLAY_LOOP_STYLE_IDS.join(", ")} — ${GLYPH_LOOP_STYLE_IDS.join(", ")} carry a title's letters on their own delays, and carry any other kind as one piece.`,+ `Animate an overlay element (title, shape, or sticker): preset In/Out ramps, a Loop that runs its whole duration, and a Move that says what the element does WHILE it holds. Omitted slots keep their setting; pass "none" to clear one. In/Out styles: ${OVERLAY_ANIM_STYLE_IDS.join(", ")} — slide names are the motion direction; typewriter animates titles only; ${GLYPH_ANIM_STYLE_IDS.join(", ")} move a title's letters one at a time, and move any other kind as one piece. Loop styles: ${OVERLAY_LOOP_STYLE_IDS.join(", ")} — ${GLYPH_LOOP_STYLE_IDS.join(", ")} carry a title's letters on their own delays, and carry any other kind as one piece. A move writes the element's own keyframe pose track, so it lands as ordinary keys the user can then drag; set_overlay_keyframes replaces it when no named move fits.`,inputSchema: obj({id: str("Overlay element id"),+ move: {+ type: "string",+ enum: [...TEXT_MOVE_IDS],+ description: `What the element does while it holds, written onto its pose track. ${TEXT_MOVE_IDS.filter((m) => m !== "none").map((m) => `${m}: ${TEXT_MOVE_NOTES[m]}`).join(" ")}`,+ },+ move_strength: num(+ `How hard the move pushes, ${MOVE_STRENGTH_MIN}..${MOVE_STRENGTH_MAX} (1 = as written). Scales every offset from rest and leaves the timing alone, so the move stays on the beat.`+ ),in_style: {type: "string",enum: [...OVERLAY_ANIM_STYLE_IDS, "none"],@@ -51,7 +65,7 @@ export const OVERLAY_ANIMATION_TOOLS = [{name: "set_overlay_keyframes",description:- "Give an overlay element a keyframed pose track, for motion the presets cannot express (a path across the frame, a slow push in, a hold-then-drift). Each key is a whole pose at a time measured in seconds from the element's own start; the pose moves linearly between keys and holds outside them. Omitted fields on a key take the element's current value. Pass an empty list to clear the track and return the element to its resting pose. Preset In/Out/Loop animation still composes on top, so a keyframed title can also fade in.",+ "Give an overlay element a keyframed pose track, for motion no named move covers (a specific path across the frame, a timing tied to the footage). Each key is a whole pose at a time measured in seconds from the element's own start; the pose moves linearly between keys and holds outside them. Omitted fields on a key take the element's current value. Pass an empty list to clear the track and return the element to its resting pose. Preset In/Out/Loop animation still composes on top, so a keyframed title can also fade in.",inputSchema: obj({id: str("Overlay element id"),diff --git a/site/src/cut/components/AnimationTiles.tsx b/site/src/cut/components/AnimationTiles.tsxindex 424a96de..ed4e31b0 100644--- a/site/src/cut/components/AnimationTiles.tsx+++ b/site/src/cut/components/AnimationTiles.tsx@@ -8,6 +8,10 @@ import {hasGlyphMotion,isGlyphAnimStyle,isGlyphLoopStyle,+ HOLD_IDS,+ MOTION,+ presetExtent,+ sampleProperties,OVERLAY_ANIM_STYLE_IDS,OVERLAY_ANIM_STYLE_LABELS,OVERLAY_LOOP_STYLE_IDS,@@ -57,14 +61,40 @@ const DEMO_REFERENCE_PX = 190;* it maps against a shorter reference and stays visible at tile size. */const LOOP_REFERENCE_PX = 64;-const referencePx = (slot: Slot) => (slot === "loop" ? LOOP_REFERENCE_PX : DEMO_REFERENCE_PX);+/** The share of the tile the widest part of a move is drawn at. Small enough+ * that the name is still inside the card at the far end of the travel. */+const MOVE_REACH = 0.15;-type Slot = "in" | "out" | "loop";+/** A move is mapped against its own reach: the holds run from a breath that+ * never leaves the spot to a fall the depth of the frame, and one fixed+ * mapping either loses the small ones or throws the big ones clean off the+ * tile. Every move then reads at the same amplitude, and what tells them+ * apart in the grid is the shape of the motion. */+const moveReferencePx = (style: string) => {+ const preset = MOTION.holds[style];+ const travel = preset ? presetExtent(preset).travel : 0;+ return Math.max(LOOP_REFERENCE_PX, travel / MOVE_REACH);+};++const referencePx = (slot: Slot, style: string) =>+ slot === "move"+ ? moveReferencePx(style)+ : slot === "loop"+ ? LOOP_REFERENCE_PX+ : DEMO_REFERENCE_PX;++type Slot = "in" | "out" | "loop" | "move";++/** A move runs the element's whole span, so the tile gives it one of its own+ * to play in — long enough to read a push, short enough to come round again. */+const MOVE_DEMO_SECONDS = 2.4;const labelOf = (slot: Slot, style: string) =>- slot === "loop"- ? (OVERLAY_LOOP_STYLE_LABELS[style as OverlayLoopStyle] ?? style)- : (OVERLAY_ANIM_STYLE_LABELS[style as OverlayAnimStyle] ?? style);+ slot === "move"+ ? (MOTION.holds[style]?.label ?? style)+ : slot === "loop"+ ? (OVERLAY_LOOP_STYLE_LABELS[style as OverlayLoopStyle] ?? style)+ : (OVERLAY_ANIM_STYLE_LABELS[style as OverlayAnimStyle] ?? style);function demoStateAt(slot: Slot,@@ -74,6 +104,24 @@ function demoStateAt(ramp: number,speed: number) {+ if (slot === "move") {+ // A move is a pose track, not a preset slot: sample it straight and hand+ // back the same shape the ramps produce, so the tile draws it the same way.+ const preset = MOTION.holds[style];+ if (!preset) return { dx: 0, dy: 0, scale: 1, rotate: 0, alpha: 1 };+ const pose = sampleProperties(+ preset.animate,+ (t % MOVE_DEMO_SECONDS) / MOVE_DEMO_SECONDS,+ MOVE_DEMO_SECONDS+ );+ return {+ dx: pose.dx,+ dy: pose.dy,+ scale: (pose.sx + pose.sy) / 2,+ rotate: pose.rotate,+ alpha: pose.alpha,+ };+ }if (slot === "loop") {return evalOverlayAnim({ loop: { style: style as OverlayLoopStyle, speed } }, t, 60, isText);}@@ -98,12 +146,21 @@ const WORD = "text-[13px] whitespace-nowrap";* mid-slide, open enough that a name fits the tile at 13px. */const wordStyle = () => ({ fontFamily: fontStack("montserrat"), fontWeight: 700, lineHeight: 1 });+/** Whether the demo types its name out rather than moving it. A typed demo+ * rewrites the element's text every frame, so React must render it with no+ * children at all — a text node React still tracks would be destroyed under+ * it, and the crash lands later, when the tile unmounts. */+const typesItsName = (slot: Slot, style: string) =>+ slot === "in" || slot === "out" ? !!MOTION.edges[style]?.animate.typed : false;+/** Whether the demo has to lay the name out letter by letter: the per-glyph* ramps and the per-glyph loops both move each character on its own delay. */const splitsGlyphs = (slot: Slot, style: string) =>- slot === "loop"- ? isGlyphLoopStyle(style as OverlayLoopStyle)- : isGlyphAnimStyle(style as OverlayAnimStyle);+ slot === "move"+ ? false+ : slot === "loop"+ ? isGlyphLoopStyle(style as OverlayLoopStyle)+ : isGlyphAnimStyle(style as OverlayAnimStyle);/** The name standing still: what a card wears until the pointer reaches it,* and what every tile falls back to when the reader asks for less motion. */@@ -137,12 +194,16 @@ function LiveName({}) {const ref = useRef<HTMLSpanElement>(null);const label = labelOf(slot, style);+ const typed = typesItsName(slot, style);// Golden-ratio steps around the cycle: neighbouring tiles land far apart in// it, and no run of them ever bunches up mid-motion together.const phase = index * (slot === "loop" ? LOOP_SPREAD : demoCycle(seconds)) * PHASE_STEP;useEffect(() => {const el = ref.current;if (!el) return;+ // A typed demo's element comes from React empty; its content is this+ // effect's to write, starting with the whole name.+ if (el.dataset.word) el.textContent = el.dataset.word;const letters = () => Array.from(el.children) as HTMLElement[];const rest = () => {el.style.transform = "";@@ -164,7 +225,7 @@ function LiveName({const tick = (now: number) => {if (!start) start = now;const st = demoStateAt(slot, style, (now - start) / 1000 + phase, isText, seconds, speed);- const px = (v: number) => (v * el.clientWidth) / referencePx(slot);+ const px = (v: number) => (v * el.clientWidth) / referencePx(slot, style);if (hasGlyphMotion(st)) {// The letters carry the motion; the word itself stays put.const kids = letters();@@ -204,17 +265,19 @@ function LiveName({return (<spanref={ref}- data-word={style === "typewriter" ? label : undefined}+ data-word={typed ? label : undefined}className={`${WORD} text-foreground`}style={{ willChange: "transform", ...wordStyle() }}>- {isText && splitsGlyphs(slot, style)- ? [...label].map((ch, i) => (- <span key={i} className="inline-block">- {ch}- </span>- ))- : label}+ {typed+ ? null+ : isText && splitsGlyphs(slot, style)+ ? [...label].map((ch, i) => (+ <span key={i} className="inline-block">+ {ch}+ </span>+ ))+ : label}</span>);}@@ -368,6 +431,7 @@ export function AnimationCard({export function AnimationTiles({slot,value,+ custom,isText,seconds,speed,@@ -376,6 +440,9 @@ export function AnimationTiles({slot: Slot;/** The style in use, or undefined for none. */value?: string;+ /** The slot plays an animation the project carries itself, so none of these+ * tiles is what is running — including None. */+ custom?: boolean;/** Typewriter is offered on titles only. */isText: boolean;/** The In/Out length the panel has set — the hover demo's ramp. */@@ -385,13 +452,15 @@ export function AnimationTiles({onPick: (style: string | null) => void;}) {const ids: string[] =- slot === "loop"- ? OVERLAY_LOOP_STYLE_IDS- : OVERLAY_ANIM_STYLE_IDS.filter((s) => s !== "typewriter" || isText);+ slot === "move"+ ? HOLD_IDS+ : slot === "loop"+ ? OVERLAY_LOOP_STYLE_IDS+ : OVERLAY_ANIM_STYLE_IDS.filter((s) => s !== "typewriter" || isText);return (<div className="grid grid-cols-2 gap-[9px]">- <Tile selected={!value} onClick={() => onPick(null)} title="None" className="p-1">+ <Tile selected={!value && !custom} onClick={() => onPick(null)} title="None" className="p-1"><span className={STAGE}><span className={`${WORD} text-muted-foreground/70`} style={wordStyle()}>Nonediff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex 6d55ab49..334b7edc 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -1,6 +1,6 @@"use client";-import { useCallback, useEffect, useMemo, useRef, useState } from "react";+import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";import { AlignCenter, AlignHorizontalSpaceAround, AlignLeft, AlignRight, AlignVerticalSpaceAround, Bold, ChevronLeft, ChevronRight, Diamond, Info, Italic, RotateCcw, SlidersHorizontal, Smile, Trash2, Type, Wand2 } from "lucide-react";import { Button } from "@/components/ui/button";import { EmojiPicker } from "@/cut/components/EmojiPicker";@@ -99,6 +99,13 @@ import {type VideoClip,} from "@/cut/lib/types";import { autoGradeFromImageData, isNeutralGrade, normalizeGrade } from "@donkeycut/effects-kit";+import {+ matchTextMove,+ MOVE_STRENGTH_MAX,+ MOVE_STRENGTH_MIN,+ MOVE_STRENGTH_STEP,+ textMoveKeys,+} from "@/cut/lib/textMotion";import { getPreviewCanvas, sampleClipFrameData } from "@/cut/lib/previewCanvas";import { cn } from "@/lib/utils";import { ScrollArea } from "@/components/ui/scroll-area";@@ -122,6 +129,18 @@ function useSliderCheckpoint() {};}+/** Where the animation panel is, for the panel that offers the way in. It is+ * held by the Inspector rather than by each panel because the animation panel+ * replaces the whole column, scroller included: it lays out its own bands, and+ * a band that must not move cannot sit inside something that scrolls. */+type AnimNav = { view: "closed" | "open" | "returned"; open: () => void; back: () => void };+const AnimNavContext = createContext<AnimNav>({+ view: "closed",+ open: () => {},+ back: () => {},+});+const useAnimNav = () => useContext(AnimNavContext);+export function Inspector() {const selection = useEditor((s) => s.selection);const clip = useEditor((s) =>@@ -135,26 +154,64 @@ export function Inspector() {);return (- <ScrollArea- render={<aside data-field-panel="" />}- className="flex min-h-0 flex-col border-l border-border bg-card"- >- {clip ? (- <ClipPanel key={clip.id} clip={clip} />- ) : audio ? (- <AudioPanel key={audio.id} clip={audio} />- ) : overlay ? (- isTextOverlay(overlay) ? (- <TextPanel key={overlay.id} overlay={overlay} />- ) : isShapeOverlay(overlay) ? (- <ShapePanel key={overlay.id} overlay={overlay} />- ) : isEffectOverlay(overlay) ? (- <EffectPanel key={overlay.id} overlay={overlay} />- ) : (- <StickerPanel key={overlay.id} overlay={overlay} />- )- ) : null}- </ScrollArea>+ <aside data-field-panel="" className="flex min-h-0 flex-col border-l border-border bg-card">+ {/* Keyed on what is selected: picking something else builds a fresh+ column, so it opens on that thing's own fields. */}+ <InspectorColumn+ key={selection?.id ?? "none"}+ clip={clip}+ audio={audio}+ overlay={overlay}+ />+ </aside>+ );+}++function InspectorColumn({+ clip,+ audio,+ overlay,+}: {+ clip?: VideoClip;+ audio?: AudioClip;+ overlay?: Overlay;+}) {+ const [animView, setAnimView] = useState<"closed" | "open" | "returned">("closed");+ const nav = useMemo<AnimNav>(+ () => ({+ view: animView,+ open: () => setAnimView("open"),+ back: () => setAnimView("returned"),+ }),+ [animView]+ );++ if (overlay && animView === "open")+ return (+ <AnimNavContext.Provider value={nav}>+ <AnimationPanel overlay={overlay} onBack={nav.back} />+ </AnimNavContext.Provider>+ );+ return (+ <AnimNavContext.Provider value={nav}>+ <ScrollArea className="min-h-0 flex-1">+ {clip ? (+ <ClipPanel clip={clip} />+ ) : audio ? (+ <AudioPanel clip={audio} />+ ) : overlay ? (+ isTextOverlay(overlay) ? (+ <TextPanel overlay={overlay} />+ ) : isShapeOverlay(overlay) ? (+ <ShapePanel overlay={overlay} />+ ) : isEffectOverlay(overlay) ? (+ <EffectPanel overlay={overlay} />+ ) : (+ <StickerPanel overlay={overlay} />+ )+ ) : null}+ </ScrollArea>+ </AnimNavContext.Provider>);}@@ -1004,7 +1061,7 @@ const LETTER_SPACINGS = [-2, 0, 2, 5, 10, 20];function TextPanel({ overlay: o }: { overlay: TextOverlay }) {const update = useEditor((s) => s.updateOverlay);- const [animView, setAnimView] = useState<"closed" | "open" | "returned">("closed");+ const nav = useAnimNav();const sizeCk = useSliderCheckpoint();const radiusCk = useSliderCheckpoint();const opacityCk = useSliderCheckpoint();@@ -1053,8 +1110,6 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {requestAnimationFrame(() => ta?.setSelectionRange(start + emoji.length, start + emoji.length));};- if (animView === "open")- return <AnimationPanel overlay={o} onBack={() => setAnimView("returned")} />;return (<><PanelTitle>Text</PanelTitle>@@ -1391,8 +1446,8 @@ function TextPanel({ overlay: o }: { overlay: TextOverlay }) {<GroupRow overlay={o} /><AnimationSectionoverlay={o}- onOpen={() => setAnimView("open")}- reveal={animView === "returned"}+ onOpen={nav.open}+ reveal={nav.view === "returned"}/></div></>@@ -1585,11 +1640,9 @@ function AnimSlotSlider({snap={[OVERLAY_ANIM_DEFAULT_SECONDS]}format={(v) => `${v.toFixed(2)}s`}parse={parseSecondsInput}- onDraft={(v) =>- drag({ [slot]: { style: active.style as OverlayAnimStyle, seconds: v } })- }+ onDraft={(v) => drag({ [slot]: { ...active, seconds: v } })}onCommit={(v) => {- drag({ [slot]: { style: active.style as OverlayAnimStyle, seconds: v } });+ drag({ [slot]: { ...active, seconds: v } });ck.end();}}/>@@ -1657,22 +1710,113 @@ function AnimationSection({<AnimSlotSlider overlay={o} slot="in" label="In duration" /><AnimSlotSlider overlay={o} slot="out" label="Out duration" /><AnimSlotSlider overlay={o} slot="loop" label="Loop speed" />+ <MoveStrengthRow overlay={o} /></Section></div>);}+/** The move's strength: how hard the hold pushes, rewritten into the pose+ * track on every step. The slider sits in two places — the collapsed+ * section, and the animation panel's Move tab — so it is one component. */+function MoveStrengthSlider({+ overlay: o,+ move,+ label,+}: {+ overlay: Overlay;+ move?: { id: string; strength: number };+ label: string;+}) {+ const ck = useSliderCheckpoint();+ const write = (strength: number) => {+ if (!move) return;+ ck.begin();+ const keys = textMoveKeys(+ move.id,+ { x: o.x, y: o.y, rotation: o.rotation ?? 0 },+ o.end - o.start,+ strength+ );+ useEditor.getState().updateOverlay(o.id, { kf: keys ?? [] });+ };+ return (+ <Row label={label}>+ <ValueSlider+ label={label}+ sliderClassName="data-horizontal:w-24"+ valueClassName="w-9 text-muted-foreground"+ value={move?.strength ?? 1}+ min={MOVE_STRENGTH_MIN}+ max={MOVE_STRENGTH_MAX}+ step={MOVE_STRENGTH_STEP}+ snap={[1]}+ format={(v) => `${Math.round(v * 100)}%`}+ parse={parsePercentInput}+ disabled={!move}+ onDraft={write}+ onCommit={(v) => {+ write(v);+ ck.end();+ }}+ />+ </Row>+ );+}++/** The strength row in the collapsed section, there only once a move is on+ * the element — a move lives on the pose track rather than in an animation+ * slot, so there is no card above it to explain an empty slider. */+function MoveStrengthRow({ overlay: o }: { overlay: Overlay }) {+ const move = useMemo(+ () => matchTextMove(o.kf, { x: o.x, y: o.y, rotation: o.rotation ?? 0 }, o.end - o.start),+ [o.kf, o.x, o.y, o.rotation, o.start, o.end]+ );+ if (!move) return null;+ return <MoveStrengthSlider overlay={o} move={move} label="Move strength" />;+}+/** The animation subview an overlay panel pushes into: In / Out / Loop tabs* over the tile grid, the active slot's length or speed under it. The three* slots pick from the same grid, one at a time — the tiles are big enough to* read the motion, which three stacked grids would not be. */function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () => void }) {const anim = o.anim ?? {};- const [slot, setSlot] = useState<"in" | "out" | "loop">("in");- const active = anim[slot];+ const [slot, setSlot] = useState<"in" | "out" | "loop" | "move">("in");+ const active = slot === "move" ? undefined : anim[slot];const seconds =- slot === "loop" ? undefined : (anim[slot] as OverlayAnim["in"])?.seconds;+ slot === "loop" || slot === "move" ? undefined : (anim[slot] as OverlayAnim["in"])?.seconds;+ // Which move wrote the element's keys, and how hard. Nothing is stored on+ // the element: the match is recomputed, so keys the user has since dragged+ // stop matching and the tab simply shows none selected.+ const activeMove = useMemo(+ () => matchTextMove(o.kf, { x: o.x, y: o.y, rotation: o.rotation ?? 0 }, o.end - o.start),+ [o.kf, o.x, o.y, o.rotation, o.start, o.end]+ );const pick = (style: string | null) => {+ if (slot === "move") {+ // Nothing here wrote this track — the user keyed it by hand — so "None"+ // has no move to take off and those keys stay put.+ if (!style && !activeMove) return;+ useEditor.getState().pushHistory();+ // A move is not a fourth animation slot: it writes the same pose track+ // the keyframe diamond writes, so the keys stay the user's to drag.+ // A newly picked move starts at full strength; switching moves keeps+ // whatever strength the last one was set to.+ const keys = style+ ? textMoveKeys(+ style,+ { x: o.x, y: o.y, rotation: o.rotation ?? 0 },+ o.end - o.start,+ activeMove?.strength ?? 1+ )+ : undefined;+ useEditor.getState().updateOverlay(o.id, { kf: keys ?? [] });+ // The pick plays itself on the stage, the same as any other slot.+ if (keys) playAnimPreview(o, "move");+ else stopAnimPreview();+ return;+ }if (!style) {stopAnimPreview();useEditor.getState().pushHistory();@@ -1697,11 +1841,11 @@ function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () =useEffect(() => stopAnimPreview, []);return (- <>- {/* The title and the slot tabs ride the top of the scroll: the grid is- longer than the panel, and which slot a tile lands in is the one- thing a reader cannot afford to lose track of. */}- <div className="sticky top-0 z-10 bg-card pb-2">+ // Three bands: the tabs, the grid, the bar. Only the middle one scrolls —+ // it owns the scroller, so the two edges are outside it and stay still+ // even while the grid rubber-bands at its ends.+ <div className="flex min-h-0 flex-1 flex-col">+ <div className="shrink-0 bg-card pb-2"><div className="flex h-10 shrink-0 items-center gap-1 px-2.5 text-sm font-semibold tracking-tight"><buttontype="button"@@ -1714,7 +1858,7 @@ function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () =Animation</div><div className="mx-3.5 flex shrink-0 rounded-lg bg-muted p-0.5 text-[11.5px] font-medium">- {(["in", "out", "loop"] as const).map((id) => (+ {(["in", "out", "loop", "move"] as const).map((id) => (<buttonkey={id}type="button"@@ -1725,7 +1869,7 @@ function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () =: "text-muted-foreground hover:text-foreground",// A slot that is already set reads darker, so switching tabs is// not the only way to see what an element is doing.- anim[id] && slot !== id && "text-foreground"+ (id === "move" ? !!activeMove : !!anim[id]) && slot !== id && "text-foreground")}onClick={() => setSlot(id)}>@@ -1734,19 +1878,116 @@ function AnimationPanel({ overlay: o, onBack }: { overlay: Overlay; onBack: () =))}</div></div>- {/* pt-1 clears the selected tile's ring, which draws outside its box and- would otherwise sit under the sticky header. */}- <div className="flex flex-col gap-1 px-3.5 pt-1 pb-4">+ {/* pt-1 clears the selected tile's ring, which draws outside its box.+ The bounce stops here rather than travelling to the panel behind. */}+ <ScrollArea+ // Keyed on the tab: a new list of tiles starts at its own top.+ key={slot}+ className="min-h-0 flex-1"+ viewportClassName="overscroll-contain"+ contentClassName="flex flex-col gap-1 px-3.5 pt-1 pb-2"+ ><AnimationTilesslot={slot}- value={active?.style}+ // A slot carrying its own preset is playing something no tile here+ // names, so the grid shows nothing selected rather than the catalog+ // entry the id happens to hold.+ value={active?.preset ? undefined : slot === "move" ? activeMove?.id : active?.style}+ custom={!!active?.preset}isText={isTextOverlay(o)}seconds={seconds ?? OVERLAY_ANIM_DEFAULT_SECONDS}speed={anim.loop?.speed ?? 1}onPick={pick}/>- </div>- </>+ </ScrollArea>+ <AnimationToolbar overlay={o} slot={slot} move={activeMove} />+ </div>+ );+}++/** The bar on the panel floor: the one number the active tab has, kept in+ * reach while the reader is still scrolling the grid. Each slot measures+ * something different — a ramp in seconds, a loop's rate, how hard a move+ * pushes — so the bar shows the tab's own control and nothing else. It stays+ * put with the slot unset, greyed rather than gone, because a bar that comes+ * and goes moves the grid under the pointer. */+function AnimationToolbar({+ overlay: o,+ slot,+ move,+}: {+ overlay: Overlay;+ slot: "in" | "out" | "loop" | "move";+ move?: { id: string; strength: number };+}) {+ const ck = useSliderCheckpoint();+ const anim = o.anim ?? {};+ const dur = Math.max(0.2, o.end - o.start);+ const edge = slot === "in" || slot === "out" ? anim[slot] : undefined;++ const bar = (children: React.ReactNode) => (+ <div className="shrink-0 border-t border-border bg-card px-3.5 py-0.5">{children}</div>+ );++ if (slot === "move")+ return bar(<MoveStrengthSlider overlay={o} move={move} label="Strength" />);++ if (slot === "loop") {+ const write = (speed: number) => {+ if (!anim.loop) return;+ ck.begin();+ writeOverlayAnim(o, anim, { loop: { ...anim.loop, speed } });+ };+ return bar(+ <Row label="Speed">+ <ValueSlider+ label="Speed"+ sliderClassName="data-horizontal:w-24"+ valueClassName="w-9 text-muted-foreground"+ value={anim.loop?.speed ?? 1}+ min={0.25}+ max={4}+ step={0.25}+ snap={[1]}+ format={(v) => `${v.toFixed(2)}×`}+ parse={parseSpeedInput}+ disabled={!anim.loop}+ onDraft={write}+ onCommit={(v) => {+ write(v);+ ck.end();+ }}+ />+ </Row>+ );+ }++ const write = (secs: number) => {+ if (!edge) return;+ ck.begin();+ writeOverlayAnim(o, anim, { [slot]: { ...edge, seconds: secs } });+ };+ return bar(+ <Row label="Duration">+ <ValueSlider+ label="Duration"+ sliderClassName="data-horizontal:w-24"+ valueClassName="w-9 text-muted-foreground"+ value={edge?.seconds ?? OVERLAY_ANIM_DEFAULT_SECONDS}+ min={OVERLAY_ANIM_MIN_SECONDS}+ max={Math.min(OVERLAY_ANIM_MAX_SECONDS, dur)}+ step={0.05}+ snap={[OVERLAY_ANIM_DEFAULT_SECONDS]}+ format={(v) => `${v.toFixed(2)}s`}+ parse={parseSecondsInput}+ disabled={!edge}+ onDraft={write}+ onCommit={(v) => {+ write(v);+ ck.end();+ }}+ />+ </Row>);}@@ -2557,10 +2798,8 @@ function ShapePanel({ overlay: o }: { overlay: ShapeOverlay }) {const fillCk = useSliderCheckpoint();const radiusCk = useSliderCheckpoint();const strokeCk = useSliderCheckpoint();- const [animView, setAnimView] = useState<"closed" | "open" | "returned">("closed");+ const nav = useAnimNav();const boxShape = !lineLikeShape(o.shape);- if (animView === "open")- return <AnimationPanel overlay={o} onBack={() => setAnimView("returned")} />;return (<><PanelTitle>{SHAPE_LABELS[o.shape]}</PanelTitle>@@ -2684,8 +2923,8 @@ function ShapePanel({ overlay: o }: { overlay: ShapeOverlay }) {<GroupRow overlay={o} /><AnimationSectionoverlay={o}- onOpen={() => setAnimView("open")}- reveal={animView === "returned"}+ onOpen={nav.open}+ reveal={nav.view === "returned"}/></div></>@@ -2873,9 +3112,7 @@ function StickerPanel({ overlay: o }: { overlay: StickerOverlay }) {const asset = useEditor((s) =>o.assetId ? s.assets.find((a) => a.id === o.assetId) : undefined);- const [animView, setAnimView] = useState<"closed" | "open" | "returned">("closed");- if (animView === "open")- return <AnimationPanel overlay={o} onBack={() => setAnimView("returned")} />;+ const nav = useAnimNav();return (<><PanelTitle>Sticker</PanelTitle>@@ -2912,8 +3149,8 @@ function StickerPanel({ overlay: o }: { overlay: StickerOverlay }) {<GroupRow overlay={o} /><AnimationSectionoverlay={o}- onOpen={() => setAnimView("open")}- reveal={animView === "returned"}+ onOpen={nav.open}+ reveal={nav.view === "returned"}/></div></>diff --git a/site/src/cut/components/ScrubValue.tsx b/site/src/cut/components/ScrubValue.tsxindex 6a5239dd..7799b740 100644--- a/site/src/cut/components/ScrubValue.tsx+++ b/site/src/cut/components/ScrubValue.tsx@@ -26,6 +26,7 @@ export function ScrubValue({parse,onScrub,onCommit,+ disabled,className,label,}: {@@ -41,6 +42,9 @@ export function ScrubValue({parse: (raw: string) => number | null;onScrub?: (v: number) => void;onCommit: (v: number) => void;+ /** Nothing to write: the readout still shows the value and takes no drag,+ * no keystroke and no click. */+ disabled?: boolean;className?: string;label: string;}) {@@ -146,10 +150,14 @@ export function ScrubValue({<buttonref={buttonRef}type="button"+ disabled={disabled}aria-label={label}- title="Drag to adjust · click to type"+ title={disabled ? undefined : "Drag to adjust · click to type"}className={cn(- "cursor-ew-resize touch-none select-none text-right font-mono text-[11.5px] tabular-nums underline decoration-transparent decoration-dotted underline-offset-3 transition-colors hover:text-foreground hover:decoration-current",+ "touch-none select-none text-right font-mono text-[11.5px] tabular-nums underline decoration-transparent decoration-dotted underline-offset-3 transition-colors",+ disabled+ ? "cursor-default opacity-50"+ : "cursor-ew-resize hover:text-foreground hover:decoration-current",className)}onPointerDown={(e) => {diff --git a/site/src/cut/components/ValueSlider.tsx b/site/src/cut/components/ValueSlider.tsxindex 40395979..2a1c2dbd 100644--- a/site/src/cut/components/ValueSlider.tsx+++ b/site/src/cut/components/ValueSlider.tsx@@ -91,6 +91,7 @@ export function ValueSlider({snap={snap}format={format}parse={parse}+ disabled={disabled}onScrub={onDraft}onCommit={onCommit}/>diff --git a/site/src/cut/lib/animPreview.ts b/site/src/cut/lib/animPreview.tsindex 36d864f3..290c38bb 100644--- a/site/src/cut/lib/animPreview.ts+++ b/site/src/cut/lib/animPreview.ts@@ -72,32 +72,47 @@ export function releaseAnimRest(id: string): void {notify();}+/** The longest a move rehearsal takes. A move runs the element's whole span,+ * which can be half a minute; anything past this sweeps the same motion+ * through in this long instead, so the shape reads without the wait. */+const MOVE_REHEARSAL_MAX = 2.4;+/*** Play `slot` on `o` from its own starting point: In sweeps the head of the- * element, Out its tail, and a loop runs one cycle. The run carries that slot- * alone, so rehearsing one animation never drags the element's other two into- * the picture. Nothing plays when the slot is empty.+ * element, Out its tail, a loop runs one cycle, and a move runs the element's+ * whole span. The run carries that slot alone, so rehearsing one animation+ * never drags the element's others into the picture. Nothing plays when the+ * slot is empty.*/export function playAnimPreview(o: { id: string; start: number; end: number; anim?: OverlayAnim },- slot: "in" | "out" | "loop"+ slot: "in" | "out" | "loop" | "move"): void {stopAnimPreview();+ // A move is not an anim slot: it is written into the element's own pose+ // track, so its run carries no anim at all and the track alone draws it.const anim: OverlayAnim =slot === "in"? { in: o.anim?.in }: slot === "out"? { out: o.anim?.out }- : { loop: o.anim?.loop };+ : slot === "loop"+ ? { loop: o.anim?.loop }+ : {};const dur = Math.max(0.1, o.end - o.start);- const window =- slot === "loop"- ? (loopPeriod(anim) ?? 0)- : Math.min((slot === "in" ? anim.in?.seconds : anim.out?.seconds) ?? 0, dur);- if (window <= 0) return;- // Where the slot lives inside the element: In and a loop start at its head,- // Out ends at its tail.- const from = slot === "out" ? dur - window : 0;+ const span =+ slot === "move"+ ? dur+ : slot === "loop"+ ? (loopPeriod(anim) ?? 0)+ : Math.min((slot === "in" ? anim.in?.seconds : anim.out?.seconds) ?? 0, dur);+ if (span <= 0) return;+ // How long the rehearsal takes on the wall clock. Every slot but a move+ // plays at its own speed; a long move is compressed into the cap.+ const window = slot === "move" ? Math.min(span, MOVE_REHEARSAL_MAX) : span;+ // Where the slot lives inside the element: In, a loop and a move start at+ // its head, Out ends at its tail.+ const from = slot === "out" ? dur - span : 0;const t0 = performance.now();const step = () => {const elapsed = (performance.now() - t0) / 1000;@@ -107,7 +122,7 @@ export function playAnimPreview(notify();return;}- run = { id: o.id, tLocal: from + elapsed, anim };+ run = { id: o.id, tLocal: from + (elapsed / window) * span, anim };notify();frame = requestAnimationFrame(step);};diff --git a/site/src/cut/lib/textMotion.ts b/site/src/cut/lib/textMotion.tsnew file mode 100644index 00000000..1f723321--- /dev/null+++ b/site/src/cut/lib/textMotion.ts@@ -0,0 +1,101 @@+import { holdMoveKeys, HOLD_IDS, MOTION } from "@donkeycut/effects-kit";+import type { OverlayKey } from "@donkeycut/effects-kit";++/**+ * Named keyframe moves for text.+ *+ * Preset In/Out ramps decide how a line ARRIVES. These decide what it does+ * while it holds — the push-in that never stops, the drift across the frame,+ * the swing that overshoots and settles. That is the difference between text+ * that appears and text that is alive.+ *+ * A move is not a special mechanism: it is an entry in the same motion+ * catalog every entrance and loop lives in, sampled against the element's+ * resting pose into the ordinary `kf` track a user could have keyed by hand.+ */++export type TextMoveId = string;++export const TEXT_MOVE_IDS: TextMoveId[] = ["none", ...HOLD_IDS];++export const TEXT_MOVE_NOTES: Record<string, string> = {+ none: "Holds its resting pose.",+ ...Object.fromEntries(HOLD_IDS.map((id) => [id, MOTION.holds[id].note ?? MOTION.holds[id].label])),+};++/** How far a move may be scaled from the shape it is written at. */+export const MOVE_STRENGTH_MIN = 0.25;+export const MOVE_STRENGTH_MAX = 2;+export const MOVE_STRENGTH_STEP = 0.05;++/** The strengths the panel's slider can land on — what a saved track is+ * matched against when the panel works out which move wrote it. */+export const MOVE_STRENGTHS: number[] = Array.from(+ { length: Math.round((MOVE_STRENGTH_MAX - MOVE_STRENGTH_MIN) / MOVE_STRENGTH_STEP) + 1 },+ (_, i) => Math.round((MOVE_STRENGTH_MIN + i * MOVE_STRENGTH_STEP) * 100) / 100+);++/** The pose track for a named move on an element resting at `rest` for+ * `dur` seconds, scaled by `strength`. An unknown id, "none", or a duration+ * too short to read gives back no track at all. */+export function textMoveKeys(+ id: string | undefined,+ rest: { x: number; y: number; rotation: number },+ dur: number,+ strength = 1+): OverlayKey[] | undefined {+ if (!id || id === "none") return undefined;+ return holdMoveKeys(id, rest, dur, strength);+}++/** Which move wrote a pose track, and at what strength. Nothing is stored on+ * the element: the answer is found by regenerating each move and seeing which+ * one matches, so keys the user has since dragged simply stop matching. */+export function matchTextMove(+ kf: OverlayKey[] | undefined,+ rest: { x: number; y: number; rotation: number },+ dur: number+): { id: string; strength: number } | undefined {+ if (!kf || kf.length === 0) return undefined;+ // Gentle moves — a float, a breath — travel so little that several+ // neighbouring strengths all sit inside any usable tolerance, so the answer+ // is the closest candidate rather than the first one that fits.+ const cost = (a: OverlayKey, b: OverlayKey) =>+ Math.abs(a.t - b.t) / 0.01 ++ Math.abs(a.x - b.x) / 0.002 ++ Math.abs(a.y - b.y) / 0.002 ++ Math.abs(a.scale - b.scale) / 0.005 ++ Math.abs(a.rotation - b.rotation) / 0.25 ++ Math.abs(a.opacity - b.opacity) / 0.005;+ // Strength scales every offset from rest and leaves the times alone, so+ // each move is generated once and the candidates are read off that one+ // track rather than built again per strength.+ const at = (u: OverlayKey, k: number): OverlayKey => ({+ t: u.t,+ x: rest.x + (u.x - rest.x) * k,+ y: rest.y + (u.y - rest.y) * k,+ scale: 1 + (u.scale - 1) * k,+ rotation: rest.rotation + (u.rotation - rest.rotation) * k,+ opacity: 1 + (u.opacity - 1) * k,+ });+ let best: { id: string; strength: number } | undefined;+ let bestCost = 1; // one tolerance unit, summed across every key and channel+ for (const id of HOLD_IDS) {+ const unit = textMoveKeys(id, rest, dur, 1);+ if (unit?.length !== kf.length) continue;+ for (const strength of MOVE_STRENGTHS) {+ let total = 0;+ for (let i = 0; i < unit.length && total < bestCost; i++)+ total += cost(at(unit[i], strength), kf[i]);+ if (total < bestCost) {+ bestCost = total;+ best = { id, strength };+ }+ }+ }+ return best;+}++/** The moves as prompt text: one line per id. */+export const textMoveCatalog = (): string =>+ HOLD_IDS.map((id) => `- ${id}: ${TEXT_MOVE_NOTES[id]}`).join("\n");