@pixerate/editor 0.71.0 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation-editor/index.cjs +285 -73
- package/dist/animation-editor/index.cjs.map +1 -1
- package/dist/animation-editor/index.d.cts +88 -2
- package/dist/animation-editor/index.d.ts +88 -2
- package/dist/animation-editor/index.js +233 -21
- package/dist/animation-editor/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/animation-editor/types.ts","../../src/animation-editor/issues.ts","../../src/animation-editor/parse.ts","../../src/animation-editor/match.ts","../../src/animation-editor/smooth.ts","../../src/animation-editor/compile.ts","../../src/animation-editor/evaluate.ts","../../src/animation-editor/onion.ts","../../src/animation-editor/check.ts","../../src/animation-editor/edit.ts","../../src/animation-editor/fit.ts","../../src/animation-editor/flair.ts","../../src/animation-editor/flair-import.ts","../../src/animation-editor/lottie.ts","../../src/animation-editor/controller.ts","../../src/animation-editor/tools.ts","../../src/animation-editor/instructions.ts","../../src/animation-editor/form.ts"],"sourcesContent":["import type { AnimationEasing } from '../animation/easing.js';\nimport type { AnimationLoopMode } from '../animation/evaluate.js';\nimport type { VectorDocument } from '../vector/types.js';\n\n/**\n * A vector animation as plain JSON: a piece of vector artwork (the editor's `VectorDocument`,\n * as the vector editor draws it) and the shots that bring it to life.\n *\n * Shots, not timelines: a shot frames the camera, plays its commands and holds. Timing comes\n * from the content (each command has a sensible default length, and drawing a line takes as\n * long as the line is long), so there are no keyframes to manage. The same scene plays the\n * same frames every time: every frame is a pure function of time.\n */\nexport interface MotionScene {\n\t/** Format version (always 1). */\n\tversion: 1;\n\t/** A short name, e.g. `logo-reveal`. */\n\tname: string;\n\tdescription?: string;\n\t/** The artwork in its resting state. Commands target its node ids. */\n\tartwork: VectorDocument;\n\tshots: MotionShot[];\n\t/** Playback past the end: stop (`none`, default), `loop` or `ping-pong`. */\n\tloop?: AnimationLoopMode;\n\t/**\n\t * Plays in answer to the viewer instead of on its own (exported to Flair's player):\n\t * - `click`: nothing plays until the viewer clicks; each click plays the next shot, and after the\n\t * last one a click plays the first again, so a last shot that puts things back makes a toggle.\n\t * - `hover` / `press`: plays forward while the pointer is over (or down on) it, and back when it leaves.\n\t * - `scroll`: scrubs through the scene as it scrolls through the viewport.\n\t * The editor previews it played through; `loop` does not apply.\n\t */\n\ttrigger?: MotionTrigger;\n\t/** Frame rate used to sample motion that a target format cannot express exactly (default 30). */\n\tfps?: number;\n\t/**\n\t * Stepped time for every command that gives none: changes hold on a grid of this many frames\n\t * per second (\"on twos\" at 12), for a hand-drawn look. Default: smooth.\n\t */\n\tsteps?: number;\n\t/** A beat grid to cue shots to (`MotionShot.at.beat`): music or a voiceover's rhythm. */\n\tbeat?: MotionBeatGrid;\n\t/** A voiceover's words with their times, to cue shots to (`MotionShot.at.word`). */\n\tnarration?: MotionNarration;\n\t/** Wanted length in seconds `[min, max]`; `check` warns outside it. */\n\ttarget?: [number, number];\n\t/**\n\t * Reusable motion: named command lists written against the target `\"$\"`, played on any\n\t * node with a `play` command (a \"pop and settle\" or \"attention\" you use many times).\n\t */\n\tclips?: Record<string, MotionClip>;\n\t/** Parameters a Flair effect made from this scene exposes (see `toFlairVectorEffect`). */\n\tcontrols?: MotionControl[];\n\t/** Named sets of control values. */\n\tpresets?: MotionPreset[];\n}\n\n/** What the viewer does to play a triggered scene (see `MotionScene.trigger`). */\nexport type MotionTrigger = 'click' | 'hover' | 'press' | 'scroll';\nexport const MOTION_TRIGGERS: readonly MotionTrigger[] = ['click', 'hover', 'press', 'scroll'];\n\n/** A rectangle of the artwork, in document units. */\nexport interface MotionRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Where the camera looks: a rectangle, or the id of a node to frame (with `padding` around\n * its bounds, default 24). The camera eases there over `ms` (default 1000; the first shot cuts).\n */\nexport type MotionCamera = (MotionRect | { frame: string; padding?: number }) & {\n\tease?: AnimationEasing;\n\tms?: number;\n\t/** Zoom at a steady rate (the size changes by the same factor each moment) instead of linearly. */\n\tgeometric?: boolean;\n};\n\n/** A steady beat: `bpm` beats a minute, the first at `offset` ms, `meter` beats a bar. */\nexport interface MotionBeatGrid {\n\tbpm: number;\n\t/** When beat 0 falls, ms (default 0). */\n\toffset?: number;\n\t/** Beats in a bar (default 4), for reading beats as bar and beat. */\n\tmeter?: number;\n}\n\n/** A voiceover: its words in order, each with when it is said (ms), from a TTS or speech-to-text word timing. */\nexport interface MotionNarration {\n\twords: { text: string; start: number; end?: number }[];\n}\n\n/** When a shot is cued to start: on a beat, on a narration word, or at a time. */\nexport interface MotionCue {\n\t/** Beat number on the scene's beat grid, from 0 (fractions for off-beats: 2.5 is the \"and\" of beat 3). */\n\tbeat?: number;\n\t/** Index of a word in the scene's narration, from 0. */\n\tword?: number;\n\t/** A time in ms. */\n\tms?: number;\n}\n\n/** One beat of the animation. */\nexport interface MotionShot {\n\t/** Stable id (unique in the scene), e.g. `intro`. */\n\tid: string;\n\t/** What happens in this shot, in a few words (shown on the timeline). */\n\tlabel?: string;\n\t/** Omit to keep the current framing. */\n\tcamera?: MotionCamera;\n\t/**\n\t * Start on a cue: a beat, a narration word or a time. The shot before holds until then; a\n\t * cue that comes before the shot before has ended is missed (`check` says by how much).\n\t * Give one of `beat`, `word` or `ms`.\n\t */\n\tat?: MotionCue;\n\t/** Commands, played one after another (unless a command says `with: \"previous\"`). */\n\trun: MotionCommand[];\n\t/** Milliseconds to hold after the commands finish (default 600). */\n\thold?: number;\n\t/**\n\t * Plays the whole shot this many times as fast (default 1): its camera move, delays,\n\t * durations, staggers and hold all scale by 1 / speed. `fit_animation` sets it to fit a length.\n\t */\n\tspeed?: number;\n}\n\n/** Fields every command takes. */\nexport interface MotionCommandBase {\n\t/** Node ids from the artwork (groups animate as one). */\n\ttargets: string[];\n\t/** Length in ms for each target, one cycle when repeating (each type has a default; `draw` follows the path length; a spring `ease` lasts until it settles). */\n\tduration?: number;\n\t/** Wait this many ms before starting (default 0). */\n\tdelay?: number;\n\t/** Start each further target this many ms after the one before (default 0). */\n\tstagger?: number;\n\t/** `after` (default) starts when the commands before it finish; `previous` starts with the command before. */\n\twith?: 'after' | 'previous';\n\t/** An easing; a spring with no `duration` lasts until it settles. */\n\tease?: AnimationEasing;\n\t/** Why this command is here (for people and agents reading the scene). */\n\tnote?: string;\n\t/**\n\t * Play the change this many times (a whole number, default 1); `duration` is one cycle. Not\n\t * for `enter`, `exit` or `wait`.\n\t */\n\trepeat?: number;\n\t/**\n\t * How repeats follow each other: `loop` (default) starts each cycle afresh, `mirror` plays\n\t * every other one backwards, `offset` carries on from where the last ended (rotate by 90,\n\t * repeat 4: a full turn). Colours and shapes offset like `loop`.\n\t */\n\trepeatMode?: 'loop' | 'mirror' | 'offset';\n\t/** Stepped time: hold the change on a grid of this many frames per second (default: the scene's `steps`, else smooth). */\n\tsteps?: number;\n}\n\nexport type MotionEnterStyle = 'fade' | 'pop' | 'grow' | 'slide' | 'draw' | 'zoom' | 'rise' | 'wipe' | 'iris' | 'split';\nexport type MotionExitStyle = 'fade' | 'shrink' | 'slide' | 'undraw' | 'wipe';\nexport type MotionDirection = 'up' | 'down' | 'left' | 'right';\n/** The opening an `iris` reveals through. */\nexport type MotionIrisShape = 'circle' | 'box';\n/** The line a `split` opens from. */\nexport type MotionSplitOrientation = 'horizontal' | 'vertical';\n\n/**\n * Brings hidden targets in. Targets entered in a shot are hidden before it. Each style is a\n * Flair motion primitive (`entrance.<style>`) with the same defaults.\n */\nexport interface MotionEnterCommand extends MotionCommandBase, MotionDrawOrder {\n\ttype: 'enter';\n\t/**\n\t * Default `fade`. `draw` draws the outline on, then fades the fill in. `pop` scales up past\n\t * full size and settles; `zoom` settles from larger; `rise` rises a short way with a little\n\t * overshoot. `wipe`, `iris` and `split` reveal the target through a clip over its box (see\n\t * `MotionFrame.clips`), reaching past it far enough to show its whole stroke.\n\t */\n\tstyle?: MotionEnterStyle;\n\t/**\n\t * For `slide`: the direction of travel (default `up`). For `wipe`: the way the edge travels\n\t * (default `right`, which reveals from the left).\n\t */\n\tdirection?: MotionDirection;\n\t/** For `slide` (default 40) and `rise` (default 20): how far in document units. */\n\tdistance?: number;\n\t/** For `pop` (default 0.5) and `zoom` (default 1.6): the starting scale. */\n\tscale?: number;\n\t/** For `iris`: open through a `circle` (default; an ellipse on a box that is not square) or a `box`. */\n\tshape?: MotionIrisShape;\n\t/** For `split`: open up and down from a `horizontal` line through the middle (default), or left and right from a `vertical` one. */\n\torientation?: MotionSplitOrientation;\n}\n\n/** Takes targets out. */\nexport interface MotionExitCommand extends MotionCommandBase, MotionDrawOrder {\n\ttype: 'exit';\n\t/** Default `fade`. `wipe` hides the target behind an edge travelling `direction` (a wipe in, reversed). */\n\tstyle?: MotionExitStyle;\n\t/** For `slide`: the direction of travel (default `down`). For `wipe`: the way the edge travels (default `right`, which hides from the left). */\n\tdirection?: MotionDirection;\n\tdistance?: number;\n}\n\n/**\n * How the strokes of a group (or several paths) draw on or off together. Default: all at once,\n * each over the whole time.\n */\nexport interface MotionDrawOrder {\n\t/** `together` (default) or `sequence`: one stroke after another, each for a time in proportion to its length. */\n\torder?: 'together' | 'sequence';\n\t/** With `together`: `time` (default) gives every stroke the whole time; `speed` draws them all at one speed, so short ones take less. */\n\tpace?: 'time' | 'speed';\n\t/** With `pace: \"speed\"`: `start` (default) starts them together, `end` finishes them together. */\n\talign?: 'start' | 'end';\n\t/** With `sequence`: `document` (default, stacking order) or `distance` from `origin` (a radial reveal). */\n\tsortBy?: 'document' | 'distance';\n\t/** With `sortBy: \"distance\"`: the point (document units) strokes are drawn out from (default the target's centre). */\n\torigin?: { x: number; y: number };\n}\n\n/** Draws a stroke on (or off) between two fractions of its length. */\nexport interface MotionDrawCommand extends MotionCommandBase, MotionDrawOrder {\n\ttype: 'draw';\n\t/**\n\t * A travelling stroke this fraction of the length long (0–1): it runs along the path and off\n\t * the end, instead of drawing it on and leaving it.\n\t */\n\tcomet?: number;\n\t/** Fraction drawn at the end (default 1). */\n\tto?: number;\n\t/** Fraction drawn at the start (default: what is drawn now). */\n\tfrom?: number;\n}\n\n/** Moves targets by an offset, or to a point (their centre lands there). */\nexport interface MotionMoveCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'move';\n\tby?: { x: number; y: number };\n\tto?: { x: number; y: number };\n\t/**\n\t * Points (document units) the centre passes through on the way, in order. The path is\n\t * smooth (velocity carries through each point) and never overshoots a point.\n\t */\n\tvia?: { x: number; y: number }[];\n\t/** With `via`: `even` (default) keeps the speed steady along the path, `equal` gives each leg the same time. */\n\tpacing?: 'even' | 'equal';\n}\n\n/** Turns targets about their centre, by or to an angle in degrees (clockwise). */\nexport interface MotionRotateCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'rotate';\n\tby?: number;\n\tto?: number;\n}\n\n/** Scales targets about their centre (1 = rest size). */\nexport interface MotionScaleCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'scale';\n\tto: number | { x: number; y: number };\n\t/** Grow at a steady rate (the same factor each moment), which reads as an even zoom. */\n\tgeometric?: boolean;\n}\n\n/** Changes opacity (0–1). */\nexport interface MotionFadeCommand extends MotionCommandBase {\n\ttype: 'fade';\n\tto: number;\n}\n\n/** Changes solid paints and stroke width. Colours mix in OKLab. */\nexport interface MotionStyleCommand extends MotionCommandBase {\n\ttype: 'style';\n\tfill?: string;\n\tstroke?: string;\n\tstrokeWidth?: number;\n}\n\n/** Morphs each target into the shape of another node (`into`), which usually stays hidden. */\nexport interface MotionMorphCommand extends MotionCommandBase {\n\ttype: 'morph';\n\tinto: string;\n}\n\n/**\n * Smart Animate: tweens a group into another group (`into`, usually hidden), part by part. Each\n * part of the target takes the shape, paint and place of its partner in `into`, paired by name,\n * then by id (`card-a-title` ↔ `card-b-title`), then by kind in order. Parts with no partner fade\n * out; parts of `into` with no partner do not appear (`check` lists them).\n */\nexport interface MotionMatchCommand extends MotionCommandBase {\n\ttype: 'match';\n\t/** Id of the group (or node) to become. */\n\tinto: string;\n}\n\n/** A reusable piece of motion: commands that target `\"$\"` (whatever `play` names), timed as in a shot. */\nexport interface MotionClip {\n\tdescription?: string;\n\t/** Commands, timed as in a shot; `\"$\"` in `targets` stands for the node played on. Clips cannot play clips. */\n\trun: MotionCommand[];\n}\n\n/** The placeholder target in a clip's commands. */\nexport const MOTION_CLIP_TARGET = '$';\n\n/** Plays a clip (`scene.clips`) on the targets: its commands, with `\"$\"` standing for each target. */\nexport interface MotionPlayCommand extends MotionCommandBase {\n\ttype: 'play';\n\t/** The clip's name. */\n\tclip: string;\n\t/** Play it this many times as fast (default 1). */\n\tspeed?: number;\n}\n\n/** Moves targets along a path node, centre on the path. */\nexport interface MotionFollowCommand extends MotionCommandBase {\n\ttype: 'follow';\n\t/** Id of a path node in the artwork (it can be hidden). */\n\tpath: string;\n\t/**\n\t * Turn with the path's direction (default false). Moves, shakes and wiggles made during the\n\t * follow then turn with it too: they are offsets from the target's place on the path.\n\t */\n\trotate?: boolean;\n\t/** Fractions of the path's length to travel between (default 0 → 1). */\n\tfrom?: number;\n\tto?: number;\n}\n\n/** Scales up and back, `count` times (draws the eye). */\nexport interface MotionPulseCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'pulse';\n\t/** Extra scale at the peak (default 0.15). */\n\tamount?: number;\n\tcount?: number;\n}\n\n/** Shakes side to side (or up and down), settling. */\nexport interface MotionShakeCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'shake';\n\t/** Distance in document units (default 8). */\n\tamount?: number;\n\tcount?: number;\n\t/** Default `horizontal`. */\n\taxis?: 'horizontal' | 'vertical';\n}\n\n/** Rocks about the centre by `angle` either way, settling (Flair's `emphasis.teeter`). */\nexport interface MotionTeeterCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'teeter';\n\t/** Degrees either way (default 8). */\n\tangle?: number;\n\t/** Rocks (default 3). */\n\tcount?: number;\n}\n\n/** Bobs up and down without settling, like something floating (Flair's `emphasis.wave`). */\nexport interface MotionWaveCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'wave';\n\t/** Height in document units (default 6). */\n\tamount?: number;\n\t/** Bobs (default 2). */\n\tcount?: number;\n}\n\n/**\n * Wanders about its place as smooth seeded noise, easing out of and back to rest (Flair's\n * `emphasis.wiggle`). The same seed always wanders the same way.\n */\nexport interface MotionWiggleCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'wiggle';\n\t/** Up to about this far, in document units (default 6). */\n\tamount?: number;\n\t/** Wanders per second, in Hz (default 3). */\n\tfrequency?: number;\n\t/** Layers of finer detail (default 2). */\n\toctaves?: number;\n\t/** Also turns about the centre by up to about this many degrees (default 0). */\n\trotate?: number;\n\t/** A whole number; default: one picked from the target's id, so each target wanders its own way. */\n\tseed?: number;\n}\n\n/** Tints solid paint toward a colour and back, `count` times (Flair's `emphasis.color-pulse`). */\nexport interface MotionColorPulseCommand extends MotionCommandBase {\n\ttype: 'color-pulse';\n\t/** The tint (default `#f59e0b`). Mixes in OKLab. */\n\tcolor?: string;\n\t/** Which paint (default `fill`). On a group it tints every path in it. */\n\tpaint?: 'fill' | 'stroke';\n\tcount?: number;\n}\n\n/** Tweens a numeric parameter of a live path effect on the target (twist angle, wiggle time, zig zag size…). */\nexport interface MotionEffectCommand extends MotionCommandBase {\n\ttype: 'effect';\n\t/** Id of an effect in the target node's `effects`. */\n\teffect: string;\n\t/** A numeric parameter of that effect, e.g. `angle`. */\n\tparam: string;\n\tto: number;\n}\n\n/** Does nothing for `duration` ms. */\nexport interface MotionWaitCommand {\n\ttype: 'wait';\n\tduration: number;\n\twith?: 'after' | 'previous';\n\tnote?: string;\n}\n\nexport type MotionCommand =\n\t| MotionEnterCommand\n\t| MotionExitCommand\n\t| MotionDrawCommand\n\t| MotionMoveCommand\n\t| MotionRotateCommand\n\t| MotionScaleCommand\n\t| MotionFadeCommand\n\t| MotionStyleCommand\n\t| MotionMorphCommand\n\t| MotionMatchCommand\n\t| MotionPlayCommand\n\t| MotionFollowCommand\n\t| MotionPulseCommand\n\t| MotionShakeCommand\n\t| MotionTeeterCommand\n\t| MotionWaveCommand\n\t| MotionWiggleCommand\n\t| MotionColorPulseCommand\n\t| MotionEffectCommand\n\t| MotionWaitCommand;\n\nexport type MotionCommandType = MotionCommand['type'];\n\nexport const MOTION_COMMAND_TYPES: readonly MotionCommandType[] = [\n\t'enter',\n\t'exit',\n\t'draw',\n\t'move',\n\t'rotate',\n\t'scale',\n\t'fade',\n\t'style',\n\t'morph',\n\t'match',\n\t'play',\n\t'follow',\n\t'pulse',\n\t'shake',\n\t'teeter',\n\t'wave',\n\t'wiggle',\n\t'color-pulse',\n\t'effect',\n\t'wait'\n];\nexport const MOTION_ENTER_STYLES: readonly MotionEnterStyle[] = ['fade', 'pop', 'grow', 'slide', 'draw', 'zoom', 'rise', 'wipe', 'iris', 'split'];\nexport const MOTION_BLENDS = ['replace', 'add'] as const;\nexport const MOTION_REPEAT_MODES = ['loop', 'mirror', 'offset'] as const;\nexport const MOTION_EXIT_STYLES: readonly MotionExitStyle[] = ['fade', 'shrink', 'slide', 'undraw', 'wipe'];\nexport const MOTION_IRIS_SHAPES: readonly MotionIrisShape[] = ['circle', 'box'];\nexport const MOTION_SPLIT_ORIENTATIONS: readonly MotionSplitOrientation[] = ['horizontal', 'vertical'];\nexport const MOTION_DIRECTIONS: readonly MotionDirection[] = ['up', 'down', 'left', 'right'];\n\n/**\n * A colour parameter of the effect made from the scene: it stands for every use of its\n * `default` colour in the artwork and the commands, so recolouring it recolours them all.\n */\nexport interface MotionControl {\n\t/** Identifier, e.g. `accent`. */\n\tname: string;\n\ttype: 'color';\n\t/** A `#rrggbb` colour used in the scene. */\n\tdefault: string;\n\tlabel?: string;\n}\n\nexport interface MotionPreset {\n\tname: string;\n\tvalues: Record<string, string>;\n}\n\n/** Default lengths (ms) of commands that give none. */\nexport const MOTION_DEFAULT_DURATIONS: Readonly<Record<Exclude<MotionCommandType, 'wait' | 'draw'>, number>> = {\n\tenter: 600,\n\texit: 450,\n\tmove: 700,\n\trotate: 700,\n\tscale: 500,\n\tfade: 400,\n\tstyle: 500,\n\tmorph: 900,\n\tmatch: 900,\n\t/** A clip's length comes from its commands (this is only a fallback). */\n\tplay: 600,\n\tfollow: 1400,\n\tpulse: 600,\n\tshake: 500,\n\tteeter: 600,\n\twave: 1000,\n\twiggle: 1500,\n\t'color-pulse': 600,\n\teffect: 900\n};\n\n/** Default hold after a shot's commands (ms). */\nexport const MOTION_DEFAULT_HOLD = 600;\n/** Default camera move (ms). */\nexport const MOTION_CAMERA_MS = 1000;\n/** `draw` lasts `length × MOTION_DRAW_MS_PER_UNIT`, clamped to `MOTION_DRAW_RANGE`. */\nexport const MOTION_DRAW_MS_PER_UNIT = 1.5;\nexport const MOTION_DRAW_RANGE: readonly [number, number] = [500, 2500];\n\n/**\n * The Flair motion primitive (`@pixerate/flair/motion`) a command plays, or undefined when\n * Flair has none (`move`, `scale`, `fade`, `style`, `morph`, `effect`, `wait` are the editor's\n * own). Commands and primitives of the same name take the same parameters and defaults.\n */\nexport function motionFlairPrimitive(command: MotionCommand): string | undefined {\n\tswitch (command.type) {\n\t\tcase 'enter':\n\t\t\treturn `entrance.${command.style ?? 'fade'}`;\n\t\tcase 'exit':\n\t\t\treturn `exit.${command.style ?? 'fade'}`;\n\t\tcase 'pulse':\n\t\tcase 'shake':\n\t\tcase 'teeter':\n\t\tcase 'wave':\n\t\tcase 'wiggle':\n\t\tcase 'color-pulse':\n\t\t\treturn `emphasis.${command.type}`;\n\t\tcase 'rotate':\n\t\t\treturn command.by !== undefined ? 'emphasis.spin' : undefined;\n\t\tcase 'follow':\n\t\t\treturn 'path.follow';\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n","/**\n * Problems with a scene, as data: every issue has a stable `code`, a severity, the shot and\n * command it is in and the ids it is about, beside its prose `message`, so an agent (or a UI)\n * can act on it without parsing sentences.\n */\n\n/** `error`: the scene does not play as written. `warning`: it plays, but probably not as meant. `note`: may well be intended. */\nexport type MotionIssueSeverity = 'error' | 'warning' | 'note';\n\n/** Every issue code with its severity and what it means. */\nexport const MOTION_ISSUE_CODES = {\n\t'no-shots': { severity: 'note', wording: 'The scene has no shots yet.' },\n\t'duplicate-shot-id': { severity: 'error', wording: 'Two shots share an id.' },\n\t'unknown-target': { severity: 'error', wording: 'A command names a node the artwork does not have.' },\n\t'unknown-path': { severity: 'error', wording: 'A follow command names a path the artwork does not have.' },\n\t'not-a-path': { severity: 'error', wording: 'A follow path must be a path node, not a group.' },\n\t'reveal-no-box': { severity: 'warning', wording: 'A wipe, iris or split cannot clip a node with no width or height (a lone straight line), so it fades instead.' },\n\t'unknown-clip': { severity: 'error', wording: 'A play command names a clip the scene does not have.' },\n\t'unknown-shape': { severity: 'error', wording: 'A morph names a shape the artwork does not have.' },\n\t'match-self': { severity: 'error', wording: 'A match turns a group into itself or into a group it holds (or that holds it).' },\n\t'match-unpaired': { severity: 'note', wording: 'Parts of a match\\'s \"into\" group have no partner in the target, so they do not appear.' },\n\t'unknown-effect': { severity: 'error', wording: 'An effect command names an effect the node does not have.' },\n\t'unknown-effect-param': { severity: 'error', wording: 'An effect command names a parameter that is not a number of that effect.' },\n\t'unknown-frame': { severity: 'error', wording: 'A camera frames a node the artwork does not have.' },\n\t'invalid-camera': { severity: 'error', wording: 'A camera rectangle has no area.' },\n\t'invalid-color': { severity: 'error', wording: 'A colour cannot be read.' },\n\t'paint-not-color': { severity: 'warning', wording: 'A style command recolours a gradient or empty paint, which only switches at the end, or a colour pulse has no solid paint to tint.' },\n\t'overlap': { severity: 'warning', wording: 'Two commands change the same property of a node at the same time; the later one wins.' },\n\t'enter-visible': { severity: 'warning', wording: 'A node enters while it is already showing, so it blinks out first.' },\n\t'exit-hidden': { severity: 'warning', wording: 'A node exits or animates while it is hidden.' },\n\t'out-of-frame': { severity: 'warning', wording: 'A node a command animates ends up outside the camera.' },\n\t'too-fast': { severity: 'warning', wording: 'A change is too quick to follow.' },\n\t'spring-cut-short': { severity: 'warning', wording: 'A spring is given a duration shorter than it takes to settle, so it jumps to its end.' },\n\t'unknown-cue': { severity: 'error', wording: 'A shot is cued to a beat with no beat grid, or to a word the narration does not have.' },\n\t'cue-missed': { severity: 'warning', wording: 'A shot starts after its cue, because the shot before runs past it.' },\n\t'trigger-loop': { severity: 'note', wording: 'A scene that plays on a trigger ignores its loop.' },\n\t'click-cue': { severity: 'warning', wording: 'A shot of a click-triggered scene is cued, but clicks decide when its shots start.' },\n\t'click-one-shot': { severity: 'note', wording: 'A click-triggered scene has one shot, so every click replays it.' },\n\t'scene-too-long': { severity: 'warning', wording: 'The scene runs past its target length.' },\n\t'scene-too-short': { severity: 'warning', wording: 'The scene ends before its target length.' },\n\t'unknown-control-color': { severity: 'warning', wording: 'A control stands for a colour the scene never uses.' },\n\t'empty-shot': { severity: 'note', wording: 'A shot neither moves the camera nor runs a command.' },\n\t'camera-aspect': { severity: 'note', wording: 'A camera rectangle has a different shape from the artwork, so it is letterboxed.' }\n} as const satisfies Record<string, { severity: MotionIssueSeverity; wording: string }>;\n\nexport type MotionIssueCode = keyof typeof MOTION_ISSUE_CODES;\n\nexport interface MotionIssue {\n\tcode: MotionIssueCode;\n\tseverity: MotionIssueSeverity;\n\tmessage: string;\n\t/** Id of the shot it is in, when it is in one. */\n\tshot?: string;\n\t/** Index of the command in that shot's `run`. */\n\tcommand?: number;\n\t/** Node ids it is about. */\n\tids?: string[];\n\t/** What was measured, what was needed and in what unit (e.g. 80 vs 120 ms). */\n\tmeasured?: number;\n\tneeded?: number;\n\tunit?: 'ms' | 's' | 'units';\n}\n\nexport function motionIssue(code: MotionIssueCode, message: string, extra: Omit<MotionIssue, 'code' | 'severity' | 'message'> = {}): MotionIssue {\n\treturn { code, severity: MOTION_ISSUE_CODES[code].severity, message, ...extra };\n}\n\n/** A stable key for an issue (code and ids, else code and place), to compare two checks. */\nexport function motionIssueKey(issue: MotionIssue): string {\n\tif (issue.ids?.length) return `${issue.code}:${[...issue.ids].sort().join(',')}`;\n\treturn `${issue.code}@${issue.shot ?? ''}#${issue.command ?? ''}`;\n}\n\n/** One line: `Shot \"intro\", command 2: …`. */\nexport function motionIssueLine(issue: MotionIssue): string {\n\tconst where = issue.shot !== undefined ? `Shot \"${issue.shot}\"${issue.command !== undefined ? `, command ${issue.command + 1}` : ''}: ` : '';\n\treturn `${where}${issue.message}`;\n}\n\n/** Optimal string alignment (Damerau–Levenshtein) distance. */\nfunction editDistance(a: string, b: string): number {\n\tconst d: number[][] = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);\n\tfor (let j = 1; j <= b.length; j++) d[0][j] = j;\n\tfor (let i = 1; i <= a.length; i++) {\n\t\tfor (let j = 1; j <= b.length; j++) {\n\t\t\tconst cost = a[i - 1] === b[j - 1] ? 0 : 1;\n\t\t\td[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);\n\t\t\tif (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);\n\t\t}\n\t}\n\treturn d[a.length][b.length];\n}\n\n/** The candidate closest to `word` (case-insensitive), if it is within a third of its length. */\nexport function suggestName(word: string, candidates: Iterable<string>): string | undefined {\n\tconst w = word.toLowerCase();\n\tlet best: string | undefined;\n\tlet bestDistance = Infinity;\n\tfor (const c of candidates) {\n\t\tconst distance = editDistance(w, c.toLowerCase());\n\t\tif (distance < bestDistance) {\n\t\t\tbest = c;\n\t\t\tbestDistance = distance;\n\t\t}\n\t}\n\treturn best !== undefined && bestDistance <= Math.max(1, Math.floor(word.length / 3)) ? best : undefined;\n}\n\n/** `\"sunn\" (did you mean \"sun\"?)`, or just `\"sunn\"`. */\nexport function namedWithSuggestion(word: string, candidates: Iterable<string>): string {\n\tconst s = suggestName(word, candidates);\n\treturn s !== undefined && s !== word ? `\"${word}\" (did you mean \"${s}\"?)` : `\"${word}\"`;\n}\n","import { isAnimationEasing } from '../animation/easing.js';\nimport { namedWithSuggestion } from './issues.js';\nimport { MOTION_COMMAND_TYPES, MOTION_DIRECTIONS, MOTION_ENTER_STYLES, MOTION_EXIT_STYLES, MOTION_REPEAT_MODES, MOTION_TRIGGERS, MOTION_BLENDS, MOTION_IRIS_SHAPES, MOTION_SPLIT_ORIENTATIONS, type MotionCommand, type MotionScene, type MotionShot } from './types.js';\n\n/**\n * Shape checking: whether a value is a well-formed scene, listing every problem at once.\n * Meaning (do the ids exist, does the timing work) is `checkMotionScene`'s job.\n */\n\nexport class MotionSceneFormatError extends Error {\n\treadonly problems: string[];\n\tconstructor(problems: string[]) {\n\t\tsuper(`The scene is not well formed:\\n${problems.map((p) => `- ${p}`).join('\\n')}`);\n\t\tthis.name = 'MotionSceneFormatError';\n\t\tthis.problems = problems;\n\t}\n}\n\nconst SCENE_KEYS = ['version', 'name', 'description', 'artwork', 'shots', 'clips', 'loop', 'trigger', 'fps', 'steps', 'beat', 'narration', 'target', 'controls', 'presets'];\nconst SHOT_KEYS = ['id', 'label', 'camera', 'at', 'run', 'hold', 'speed'];\nconst CAMERA_KEYS = ['x', 'y', 'width', 'height', 'frame', 'padding', 'ease', 'ms', 'geometric'];\nconst BASE_KEYS = ['type', 'targets', 'duration', 'delay', 'stagger', 'with', 'ease', 'note', 'repeat', 'repeatMode', 'steps'];\nconst DRAW_ORDER_KEYS = ['order', 'pace', 'align', 'sortBy', 'origin'];\nconst COMMAND_KEYS: Record<string, string[]> = {\n\tenter: [...BASE_KEYS, ...DRAW_ORDER_KEYS, 'style', 'direction', 'distance', 'scale', 'shape', 'orientation'],\n\texit: [...BASE_KEYS, ...DRAW_ORDER_KEYS, 'style', 'direction', 'distance'],\n\tdraw: [...BASE_KEYS, ...DRAW_ORDER_KEYS, 'from', 'to', 'comet'],\n\tmove: [...BASE_KEYS, 'by', 'to', 'via', 'pacing', 'blend'],\n\trotate: [...BASE_KEYS, 'by', 'to', 'blend'],\n\tscale: [...BASE_KEYS, 'to', 'geometric', 'blend'],\n\tfade: [...BASE_KEYS, 'to'],\n\tstyle: [...BASE_KEYS, 'fill', 'stroke', 'strokeWidth'],\n\tmorph: [...BASE_KEYS, 'into'],\n\tmatch: [...BASE_KEYS, 'into'],\n\tplay: ['type', 'targets', 'delay', 'stagger', 'with', 'note', 'clip', 'speed'],\n\tfollow: [...BASE_KEYS, 'path', 'rotate', 'from', 'to'],\n\tpulse: [...BASE_KEYS, 'amount', 'count', 'blend'],\n\tshake: [...BASE_KEYS, 'amount', 'count', 'axis', 'blend'],\n\tteeter: [...BASE_KEYS, 'angle', 'count', 'blend'],\n\twave: [...BASE_KEYS, 'amount', 'count', 'blend'],\n\twiggle: [...BASE_KEYS, 'amount', 'frequency', 'octaves', 'rotate', 'seed', 'blend'],\n\t'color-pulse': [...BASE_KEYS, 'color', 'paint', 'count'],\n\teffect: [...BASE_KEYS, 'effect', 'param', 'to'],\n\twait: ['type', 'duration', 'with', 'note']\n};\n\nconst isObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\nconst isNum = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);\nconst isPoint = (v: unknown) => isObject(v) && isNum(v.x) && isNum(v.y);\n\nfunction unknownKeys(value: Record<string, unknown>, known: readonly string[], where: string, problems: string[]) {\n\tfor (const key of Object.keys(value)) if (!known.includes(key)) problems.push(`${where}: unknown field ${namedWithSuggestion(key, known)}.`);\n}\n\n/** Problems with one command's shape (empty when well formed). `where` prefixes each. */\nexport function commandShapeProblems(command: unknown, where: string): string[] {\n\tconst problems: string[] = [];\n\tif (!isObject(command)) return [`${where} must be an object.`];\n\tconst type = command.type;\n\tif (typeof type !== 'string' || !(MOTION_COMMAND_TYPES as readonly string[]).includes(type)) {\n\t\treturn [`${where}: unknown type ${typeof type === 'string' ? namedWithSuggestion(type, MOTION_COMMAND_TYPES) : String(type)}; use one of ${MOTION_COMMAND_TYPES.join(', ')}.`];\n\t}\n\tunknownKeys(command, COMMAND_KEYS[type], `${where} (${type})`, problems);\n\tconst p = (msg: string) => problems.push(`${where} (${type}): ${msg}`);\n\tconst nonNegative = (key: string) => {\n\t\tif (command[key] !== undefined && !(isNum(command[key]) && (command[key] as number) >= 0)) p(`\"${key}\" must be a number of milliseconds ≥ 0.`);\n\t};\n\tconst fraction = (key: string) => {\n\t\tif (command[key] !== undefined && !(isNum(command[key]) && (command[key] as number) >= 0 && (command[key] as number) <= 1)) p(`\"${key}\" must be a fraction from 0 to 1.`);\n\t};\n\tconst optionalNumber = (key: string) => {\n\t\tif (command[key] !== undefined && !isNum(command[key])) p(`\"${key}\" must be a number.`);\n\t};\n\tif (command.with !== undefined && command.with !== 'after' && command.with !== 'previous') p(`\"with\" must be \"after\" or \"previous\".`);\n\tif (DRAW_ORDER_KEYS.some((k) => command[k] !== undefined)) {\n\t\tif ((type === 'enter' && command.style !== 'draw') || (type === 'exit' && command.style !== 'undraw')) p(`\"order\", \"pace\", \"align\", \"sortBy\" and \"origin\" go with drawing: style \"${type === 'enter' ? 'draw' : 'undraw'}\".`);\n\t\tif (command.order !== undefined && command.order !== 'together' && command.order !== 'sequence') p(`\"order\" must be \"together\" or \"sequence\" (one stroke after another).`);\n\t\tif (command.pace !== undefined && command.pace !== 'time' && command.pace !== 'speed') p(`\"pace\" must be \"time\" (each stroke takes the whole time) or \"speed\" (all at one speed).`);\n\t\tif (command.align !== undefined && command.align !== 'start' && command.align !== 'end') p(`\"align\" must be \"start\" or \"end\".`);\n\t\tif (command.sortBy !== undefined && command.sortBy !== 'document' && command.sortBy !== 'distance') p(`\"sortBy\" must be \"document\" or \"distance\".`);\n\t\tif (command.origin !== undefined && !isPoint(command.origin)) p(`\"origin\" must be { \"x\": number, \"y\": number } (document units).`);\n\t}\n\tif (command.note !== undefined && typeof command.note !== 'string') p(`\"note\" must be a string.`);\n\tif (type === 'wait') {\n\t\tif (!isNum(command.duration) || command.duration < 0) p(`\"duration\" must be a number of milliseconds ≥ 0.`);\n\t\treturn problems;\n\t}\n\tif (!Array.isArray(command.targets) || command.targets.length === 0 || !command.targets.every((t) => typeof t === 'string' && t.length > 0)) p(`\"targets\" must be a non-empty list of node ids.`);\n\tnonNegative('duration');\n\tnonNegative('delay');\n\tnonNegative('stagger');\n\tif (command.ease !== undefined && !isAnimationEasing(command.ease)) p(`\"ease\" is not an easing; use a preset such as \"ease-in-out\" or \"spring-bouncy\", or { \"type\": \"cubic-bezier\", … } or { \"type\": \"spring\", … }.`);\n\tif (command.repeat !== undefined) {\n\t\tif (type === 'enter' || type === 'exit') p(`\"repeat\" is not for ${type} (it brings things in or out once); repeat an emphasis or a move instead.`);\n\t\telse if (!(Number.isInteger(command.repeat) && (command.repeat as number) >= 1 && (command.repeat as number) <= 1000)) p(`\"repeat\" must be a whole number from 1 to 1000.`);\n\t}\n\tif (command.blend !== undefined && !(MOTION_BLENDS as readonly unknown[]).includes(command.blend)) p(`\"blend\" must be \"replace\" (the change takes over) or \"add\" (a layer on top).`);\n\tif (command.repeatMode !== undefined && !(MOTION_REPEAT_MODES as readonly unknown[]).includes(command.repeatMode)) p(`\"repeatMode\" must be one of ${MOTION_REPEAT_MODES.join(', ')}.`);\n\tif (command.steps !== undefined && !(isNum(command.steps) && command.steps > 0 && command.steps <= 120)) p(`\"steps\" must be frames per second from above 0 to 120 (12 holds each pose for two frames at 24 fps).`);\n\tswitch (type) {\n\t\tcase 'enter':\n\t\tcase 'exit': {\n\t\t\tconst styles = type === 'enter' ? MOTION_ENTER_STYLES : MOTION_EXIT_STYLES;\n\t\t\tif (command.style !== undefined && !(typeof command.style === 'string' && (styles as readonly string[]).includes(command.style)))\n\t\t\t\tp(`\"style\" must be one of ${styles.join(', ')}${typeof command.style === 'string' ? ` (got ${namedWithSuggestion(command.style, styles)})` : ''}.`);\n\t\t\tif (command.direction !== undefined && !(MOTION_DIRECTIONS as readonly unknown[]).includes(command.direction)) p(`\"direction\" must be one of ${MOTION_DIRECTIONS.join(', ')}.`);\n\t\t\toptionalNumber('distance');\n\t\t\tif (command.scale !== undefined && !(isNum(command.scale) && command.scale >= 0)) p(`\"scale\" must be a number ≥ 0 (the starting scale for pop and zoom).`);\n\t\t\tif (command.shape !== undefined && !(MOTION_IRIS_SHAPES as readonly unknown[]).includes(command.shape)) p(`\"shape\" must be one of ${MOTION_IRIS_SHAPES.join(', ')} (the opening of an iris).`);\n\t\t\tif (command.orientation !== undefined && !(MOTION_SPLIT_ORIENTATIONS as readonly unknown[]).includes(command.orientation)) p(`\"orientation\" must be one of ${MOTION_SPLIT_ORIENTATIONS.join(', ')} (the line a split opens from).`);\n\t\t\tbreak;\n\t\t}\n\t\tcase 'draw':\n\t\t\tfraction('from');\n\t\t\tfraction('to');\n\t\t\tfraction('comet');\n\t\t\tif (command.comet !== undefined && (command.from !== undefined || command.to !== undefined)) p(`\"comet\" runs the whole path; leave out \"from\" and \"to\".`);\n\t\t\tbreak;\n\t\tcase 'move':\n\t\t\tif (command.by === undefined && command.to === undefined) p(`give \"by\" (an offset) or \"to\" (a point).`);\n\t\t\tif (command.by !== undefined && command.to !== undefined) p(`give \"by\" or \"to\", not both.`);\n\t\t\tif (command.by !== undefined && !isPoint(command.by)) p(`\"by\" must be { \"x\": number, \"y\": number }.`);\n\t\t\tif (command.to !== undefined && !isPoint(command.to)) p(`\"to\" must be { \"x\": number, \"y\": number }.`);\n\t\t\tif (command.via !== undefined && !(Array.isArray(command.via) && command.via.length > 0 && command.via.length <= 64 && command.via.every(isPoint))) p(`\"via\" must be a list of 1 to 64 points { \"x\": number, \"y\": number } (document units).`);\n\t\t\tif (command.pacing !== undefined && command.pacing !== 'even' && command.pacing !== 'equal') p(`\"pacing\" must be \"even\" (steady speed) or \"equal\" (each leg the same time).`);\n\t\t\tif (command.pacing !== undefined && command.via === undefined) p(`\"pacing\" goes with \"via\".`);\n\t\t\tbreak;\n\t\tcase 'rotate':\n\t\t\tif (command.by === undefined && command.to === undefined) p(`give \"by\" or \"to\" (degrees).`);\n\t\t\tif (command.by !== undefined && command.to !== undefined) p(`give \"by\" or \"to\", not both.`);\n\t\t\toptionalNumber('by');\n\t\t\toptionalNumber('to');\n\t\t\tbreak;\n\t\tcase 'scale':\n\t\t\tif (!(isNum(command.to) || isPoint(command.to))) p(`\"to\" must be a number or { \"x\": number, \"y\": number }.`);\n\t\t\tif (command.geometric !== undefined && typeof command.geometric !== 'boolean') p(`\"geometric\" must be true or false.`);\n\t\t\tbreak;\n\t\tcase 'fade':\n\t\t\tif (!(isNum(command.to) && command.to >= 0 && command.to <= 1)) p(`\"to\" must be an opacity from 0 to 1.`);\n\t\t\tbreak;\n\t\tcase 'style':\n\t\t\tif (command.fill === undefined && command.stroke === undefined && command.strokeWidth === undefined) p(`give at least one of \"fill\", \"stroke\" or \"strokeWidth\".`);\n\t\t\tif (command.fill !== undefined && typeof command.fill !== 'string') p(`\"fill\" must be a CSS colour.`);\n\t\t\tif (command.stroke !== undefined && typeof command.stroke !== 'string') p(`\"stroke\" must be a CSS colour.`);\n\t\t\tif (command.strokeWidth !== undefined && !(isNum(command.strokeWidth) && command.strokeWidth >= 0)) p(`\"strokeWidth\" must be a number ≥ 0.`);\n\t\t\tbreak;\n\t\tcase 'play':\n\t\t\tif (typeof command.clip !== 'string' || !command.clip) p(`\"clip\" must be the name of one of the scene's clips.`);\n\t\t\tif (command.speed !== undefined && !(isNum(command.speed) && command.speed >= 0.05 && command.speed <= 20)) p(`\"speed\" must be a number from 0.05 to 20 (2 plays the clip twice as fast).`);\n\t\t\tbreak;\n\t\tcase 'morph':\n\t\tcase 'match':\n\t\t\tif (typeof command.into !== 'string' || !command.into) p(`\"into\" must be the id of a ${type === 'match' ? 'group to become' : 'node whose shape to take'}.`);\n\t\t\tbreak;\n\t\tcase 'follow':\n\t\t\tif (typeof command.path !== 'string' || !command.path) p(`\"path\" must be the id of a path node.`);\n\t\t\tif (command.rotate !== undefined && typeof command.rotate !== 'boolean') p(`\"rotate\" must be true or false.`);\n\t\t\tfraction('from');\n\t\t\tfraction('to');\n\t\t\tbreak;\n\t\tcase 'pulse':\n\t\tcase 'shake':\n\t\tcase 'teeter':\n\t\tcase 'wave':\n\t\tcase 'color-pulse':\n\t\t\toptionalNumber('amount');\n\t\t\toptionalNumber('angle');\n\t\t\tif (command.count !== undefined && !(Number.isInteger(command.count) && (command.count as number) >= 1)) p(`\"count\" must be a whole number ≥ 1.`);\n\t\t\tif (command.axis !== undefined && command.axis !== 'horizontal' && command.axis !== 'vertical') p(`\"axis\" must be \"horizontal\" or \"vertical\".`);\n\t\t\tif (command.color !== undefined && typeof command.color !== 'string') p(`\"color\" must be a CSS colour.`);\n\t\t\tif (command.paint !== undefined && command.paint !== 'fill' && command.paint !== 'stroke') p(`\"paint\" must be \"fill\" or \"stroke\".`);\n\t\t\tbreak;\n\t\tcase 'wiggle':\n\t\t\toptionalNumber('amount');\n\t\t\toptionalNumber('rotate');\n\t\t\tif (command.frequency !== undefined && !(isNum(command.frequency) && command.frequency > 0)) p(`\"frequency\" must be a number of Hz > 0.`);\n\t\t\tif (command.octaves !== undefined && !(Number.isInteger(command.octaves) && (command.octaves as number) >= 1 && (command.octaves as number) <= 8)) p(`\"octaves\" must be a whole number from 1 to 8.`);\n\t\t\tif (command.seed !== undefined && !(Number.isInteger(command.seed) && (command.seed as number) >= 0)) p(`\"seed\" must be a whole number ≥ 0.`);\n\t\t\tbreak;\n\t\tcase 'effect':\n\t\t\tif (typeof command.effect !== 'string' || !command.effect) p(`\"effect\" must be the id of one of the node's effects.`);\n\t\t\tif (typeof command.param !== 'string' || !command.param) p(`\"param\" must name a numeric parameter of the effect.`);\n\t\t\tif (!isNum(command.to)) p(`\"to\" must be a number.`);\n\t\t\tbreak;\n\t}\n\treturn problems;\n}\n\n/** Problems with a scene's `clips`: names, and each clip's commands (which may target `\"$\"` but not play clips). */\nexport function clipsShapeProblems(clips: unknown): string[] {\n\tif (!isObject(clips)) return ['Scene: \"clips\" must be an object of named clips { \"pop\": { \"run\": [ … ] } }.'];\n\tconst problems: string[] = [];\n\tfor (const [name, clip] of Object.entries(clips)) {\n\t\tconst where = `Clip \"${name}\"`;\n\t\tif (!/^[A-Za-z_][\\w-]*$/.test(name)) problems.push(`${where}: a clip name is letters, digits, \"_\" or \"-\" (e.g. \"pop-in\").`);\n\t\tif (!isObject(clip) || !Array.isArray(clip.run)) {\n\t\t\tproblems.push(`${where} must be { \"description\"?, \"run\": [commands] }.`);\n\t\t\tcontinue;\n\t\t}\n\t\tunknownKeys(clip, ['description', 'run'], where, problems);\n\t\tif (clip.description !== undefined && typeof clip.description !== 'string') problems.push(`${where}: \"description\" must be a string.`);\n\t\tclip.run.forEach((command, i) => {\n\t\t\tif (isObject(command) && command.type === 'play') problems.push(`${where}, command ${i + 1}: a clip cannot play another clip; copy its commands in instead.`);\n\t\t\telse problems.push(...commandShapeProblems(command, `${where}, command ${i + 1}`));\n\t\t});\n\t}\n\treturn problems;\n}\n\n/** Problems with one shot's shape. */\nexport function shotShapeProblems(shot: unknown, where: string): string[] {\n\tif (!isObject(shot)) return [`${where} must be an object.`];\n\tconst problems: string[] = [];\n\tunknownKeys(shot, SHOT_KEYS, where, problems);\n\tif (typeof shot.id !== 'string' || !/^[A-Za-z0-9_][\\w.-]*$/.test(shot.id)) problems.push(`${where}: \"id\" must be letters, digits, \"_\", \"-\" or \".\" (e.g. \"intro\").`);\n\tconst name = typeof shot.id === 'string' ? `Shot \"${shot.id}\"` : where;\n\tif (shot.label !== undefined && typeof shot.label !== 'string') problems.push(`${name}: \"label\" must be a string.`);\n\tif (shot.hold !== undefined && !(isNum(shot.hold) && shot.hold >= 0)) problems.push(`${name}: \"hold\" must be a number of milliseconds ≥ 0.`);\n\tif (shot.speed !== undefined && !(isNum(shot.speed) && shot.speed >= 0.05 && shot.speed <= 20)) problems.push(`${name}: \"speed\" must be a number from 0.05 to 20 (2 plays it twice as fast).`);\n\tif (shot.at !== undefined) {\n\t\tconst at = shot.at;\n\t\tconst given = isObject(at) ? (['beat', 'word', 'ms'] as const).filter((k) => at[k] !== undefined) : [];\n\t\tif (!isObject(at) || given.length !== 1) problems.push(`${name}: \"at\" must give one of { \"beat\": number }, { \"word\": index } or { \"ms\": number }.`);\n\t\telse {\n\t\t\tunknownKeys(at, ['beat', 'word', 'ms'], `${name} at`, problems);\n\t\t\tconst k = given[0];\n\t\t\tif (!isNum(at[k]) || (at[k] as number) < 0 || (k === 'word' && !Number.isInteger(at[k]))) problems.push(`${name}: \"at.${k}\" must be ${k === 'word' ? 'a word index ≥ 0' : 'a number ≥ 0'}.`);\n\t\t}\n\t}\n\tif (shot.camera !== undefined) {\n\t\tconst c = shot.camera;\n\t\tif (!isObject(c)) problems.push(`${name}: \"camera\" must be an object.`);\n\t\telse {\n\t\t\tunknownKeys(c, CAMERA_KEYS, `${name} camera`, problems);\n\t\t\tconst isRect = ['x', 'y', 'width', 'height'].every((k) => isNum(c[k]));\n\t\t\tif (typeof c.frame === 'string') {\n\t\t\t\tif (c.padding !== undefined && !isNum(c.padding)) problems.push(`${name} camera: \"padding\" must be a number.`);\n\t\t\t} else if (!isRect) problems.push(`${name} camera: give { x, y, width, height } or { frame: \"<node id>\" }.`);\n\t\t\tif (c.ease !== undefined && !isAnimationEasing(c.ease)) problems.push(`${name} camera: \"ease\" is not an easing.`);\n\t\t\tif (c.ms !== undefined && !(isNum(c.ms) && c.ms >= 0)) problems.push(`${name} camera: \"ms\" must be a number ≥ 0.`);\n\t\t\tif (c.geometric !== undefined && typeof c.geometric !== 'boolean') problems.push(`${name} camera: \"geometric\" must be true or false.`);\n\t\t}\n\t}\n\tif (!Array.isArray(shot.run)) problems.push(`${name}: \"run\" must be a list of commands (it may be empty).`);\n\telse shot.run.forEach((command, i) => problems.push(...commandShapeProblems(command, `${name}, command ${i + 1}`)));\n\treturn problems;\n}\n\n/** Problems with a scene's shape (empty when well formed). */\nexport function motionSceneShapeProblems(input: unknown): string[] {\n\tif (!isObject(input)) return ['The scene must be an object.'];\n\tconst problems: string[] = [];\n\tunknownKeys(input, SCENE_KEYS, 'Scene', problems);\n\tif (input.version !== 1) problems.push('Scene: \"version\" must be 1.');\n\tif (typeof input.name !== 'string' || !input.name) problems.push('Scene: \"name\" must be a non-empty string.');\n\tif (input.description !== undefined && typeof input.description !== 'string') problems.push('Scene: \"description\" must be a string.');\n\tconst art = input.artwork;\n\tif (!isObject(art) || !isNum(art.width) || !isNum(art.height) || !(art.width > 0) || !(art.height > 0) || !Array.isArray(art.nodes))\n\t\tproblems.push('Scene: \"artwork\" must be a vector document { width, height, nodes }.');\n\tif (input.clips !== undefined) problems.push(...clipsShapeProblems(input.clips));\n\tif (input.trigger !== undefined && !(MOTION_TRIGGERS as readonly unknown[]).includes(input.trigger)) problems.push(`Scene: \"trigger\" must be one of ${MOTION_TRIGGERS.join(', ')}.`);\n\tif (input.loop !== undefined && !['none', 'loop', 'ping-pong'].includes(input.loop as string)) problems.push('Scene: \"loop\" must be \"none\", \"loop\" or \"ping-pong\".');\n\tif (input.fps !== undefined && !(isNum(input.fps) && input.fps > 0 && input.fps <= 120)) problems.push('Scene: \"fps\" must be a number from 1 to 120.');\n\tif (input.beat !== undefined) {\n\t\tconst b = input.beat;\n\t\tif (!isObject(b) || !(isNum(b.bpm) && b.bpm >= 1 && b.bpm <= 1000) || (b.offset !== undefined && !isNum(b.offset)) || (b.meter !== undefined && !(Number.isInteger(b.meter) && (b.meter as number) >= 1)))\n\t\t\tproblems.push('Scene: \"beat\" must be { \"bpm\": 1–1000, \"offset\"?: ms, \"meter\"?: beats a bar }.');\n\t}\n\tif (input.narration !== undefined) {\n\t\tconst n = input.narration;\n\t\tif (!isObject(n) || !Array.isArray(n.words) || !n.words.every((w, i, all) => isObject(w) && typeof w.text === 'string' && isNum(w.start) && w.start >= 0 && (w.end === undefined || (isNum(w.end) && w.end >= w.start)) && (i === 0 || w.start >= ((all[i - 1] as Record<string, number>).start ?? 0))))\n\t\t\tproblems.push('Scene: \"narration\" must be { \"words\": [{ \"text\", \"start\": ms, \"end\"?: ms }, …] } in time order.');\n\t}\n\tif (input.steps !== undefined && !(isNum(input.steps) && input.steps > 0 && input.steps <= 120)) problems.push('Scene: \"steps\" must be frames per second from above 0 to 120.');\n\tif (input.target !== undefined && !(Array.isArray(input.target) && input.target.length === 2 && input.target.every(isNum) && input.target[0] <= input.target[1]))\n\t\tproblems.push('Scene: \"target\" must be [min, max] seconds.');\n\tif (input.controls !== undefined) {\n\t\tif (!Array.isArray(input.controls)) problems.push('Scene: \"controls\" must be a list.');\n\t\telse\n\t\t\tinput.controls.forEach((c, i) => {\n\t\t\t\tif (!isObject(c) || typeof c.name !== 'string' || !/^[A-Za-z_]\\w*$/.test(c.name) || c.type !== 'color' || typeof c.default !== 'string' || !/^#[0-9a-fA-F]{6}$/.test(c.default))\n\t\t\t\t\tproblems.push(`Scene: control ${i + 1} must be { name (an identifier), type: \"color\", default: \"#rrggbb\", label? }.`);\n\t\t\t});\n\t}\n\tif (input.presets !== undefined && !(Array.isArray(input.presets) && input.presets.every((p) => isObject(p) && typeof p.name === 'string' && isObject(p.values))))\n\t\tproblems.push('Scene: \"presets\" must be a list of { name, values }.');\n\tif (!Array.isArray(input.shots)) problems.push('Scene: \"shots\" must be a list.');\n\telse input.shots.forEach((shot, i) => problems.push(...shotShapeProblems(shot, `Shot ${i + 1}`)));\n\treturn problems;\n}\n\n/** Reads a scene from JSON (a string or a parsed value). Throws `MotionSceneFormatError` listing every problem. */\nexport function parseMotionScene(input: unknown): MotionScene {\n\tlet value = input;\n\tif (typeof input === 'string') {\n\t\ttry {\n\t\t\tvalue = JSON.parse(input);\n\t\t} catch (error) {\n\t\t\tthrow new MotionSceneFormatError([`The scene is not valid JSON: ${(error as Error).message}`]);\n\t\t}\n\t}\n\tconst problems = motionSceneShapeProblems(value);\n\tif (problems.length) throw new MotionSceneFormatError(problems);\n\treturn value as MotionScene;\n}\n\n/** Writes a scene as JSON. */\nexport function motionSceneToJson(scene: MotionScene, space: number | string = 2): string {\n\treturn JSON.stringify(scene, null, space);\n}\n\n/** Whether `shot` is a well-formed shot. */\nexport const isMotionShot = (shot: unknown): shot is MotionShot => shotShapeProblems(shot, 'Shot').length === 0;\n/** Whether `command` is a well-formed command. */\nexport const isMotionCommand = (command: unknown): command is MotionCommand => commandShapeProblems(command, 'Command').length === 0;\n","// Pairing passes adapted from deckcraft-main/crates/anim/src/morph.rs (`morph_pairs`) and figcraft-main/crates/ui-egui/src/present.rs (`match_layers`), MIT OR Apache-2.0, © ArtCraft Team and contributors.\nimport type { VectorNode } from '../vector/types.js';\n\n/** How the parts of one node pair with the parts of another for a `match` (Smart Animate). */\nexport interface MotionMatch {\n\t/** `[from id, into id]`: each part of the target and the part of `into` it becomes. */\n\tpairs: [string, string][];\n\t/** Parts of the target with no partner (they fade out). */\n\tunpairedFrom: string[];\n\t/** Parts of `into` with no partner (they cannot appear). */\n\tunpairedInto: string[];\n}\n\nconst SEPARATOR = /[-_/.:]/;\n\n/** An id with the group's own id (or its last word) taken out, so `card-a-title` and `card-b-title` both read `title`. */\nfunction localId(id: string, groupId: string): string {\n\tif (groupId && id.includes(groupId)) return id.split(groupId).join('').replace(/^[-_/.:]+|[-_/.:]+$/g, '');\n\tconst parts = id.split(SEPARATOR);\n\treturn parts[parts.length - 1] ?? id;\n}\n\n/**\n * Pairs the parts of `from` with the parts of `into`, each part used once, in passes: the same\n * `name`, then the same id once each group's own id is taken out, then the same kind in order.\n * Paired groups pair their own parts the same way, so a part pairs with a part, never a group\n * with a path. Two paths (or a path and a group with no children) pair whole.\n */\nexport function matchMotionNodes(from: VectorNode, into: VectorNode): MotionMatch {\n\tconst out: MotionMatch = { pairs: [], unpairedFrom: [], unpairedInto: [] };\n\tconst visit = (a: VectorNode, b: VectorNode) => {\n\t\tconst aKids = a.type === 'group' ? a.children : [];\n\t\tconst bKids = b.type === 'group' ? b.children : [];\n\t\tif (!aKids.length || !bKids.length) {\n\t\t\tout.pairs.push([a.id, b.id]);\n\t\t\treturn;\n\t\t}\n\t\tconst left = new Set(aKids);\n\t\tconst right = new Set(bKids);\n\t\tconst pair = (key: (n: VectorNode, group: VectorNode) => string | undefined) => {\n\t\t\tfor (const x of [...left]) {\n\t\t\t\tconst k = key(x, a);\n\t\t\t\tif (!k) continue;\n\t\t\t\tconst y = [...right].find((n) => key(n, b) === k);\n\t\t\t\tif (!y) continue;\n\t\t\t\tleft.delete(x);\n\t\t\t\tright.delete(y);\n\t\t\t\tif (x.type === 'group' && y.type === 'group') visit(x, y);\n\t\t\t\telse out.pairs.push([x.id, y.id]);\n\t\t\t}\n\t\t};\n\t\tpair((n) => n.name?.trim() || undefined);\n\t\tpair((n, g) => localId(n.id, g.id) || undefined);\n\t\t// Then the same kind, in stacking order.\n\t\tfor (const x of [...left]) {\n\t\t\tconst y = [...right].find((n) => n.type === x.type);\n\t\t\tif (!y) continue;\n\t\t\tleft.delete(x);\n\t\t\tright.delete(y);\n\t\t\tif (x.type === 'group' && y.type === 'group') visit(x, y);\n\t\t\telse out.pairs.push([x.id, y.id]);\n\t\t}\n\t\tout.unpairedFrom.push(...[...left].map((n) => n.id));\n\t\tout.unpairedInto.push(...[...right].map((n) => n.id));\n\t};\n\tvisit(from, into);\n\treturn out;\n}\n","// Clamped tangents after Blender's auto-clamped handles (ideas only) and Fritsch–Carlson monotone cubic interpolation.\nimport type { AnimationEasing } from '../animation/easing.js';\n\n/** One leg of a smooth path on one axis: from → to over [start, end] (ms), eased so velocity carries across legs. */\nexport interface MotionSmoothLeg {\n\tstart: number;\n\tend: number;\n\tfrom: number;\n\tto: number;\n\tease: AnimationEasing;\n}\n\n/**\n * A value passing through `values` at `times` (ms) with continuous velocity and no overshoot:\n * a monotone cubic (Fritsch–Carlson) whose slopes are zero at the ends, at turning points and on\n * flat stretches, so it never goes past a waypoint. Each leg is one cubic-bezier ease per axis;\n * x and y ease differently, so exports to Flair or Lottie (one ease per transform) sample them.\n */\nexport function smoothMotionLegs(times: readonly number[], values: readonly number[]): MotionSmoothLeg[] {\n\tconst n = values.length;\n\tconst slope: number[] = new Array(n).fill(0);\n\tconst secant = (i: number) => (values[i + 1] - values[i]) / Math.max(1e-9, times[i + 1] - times[i]);\n\tfor (let i = 1; i < n - 1; i++) {\n\t\tconst a = secant(i - 1);\n\t\tconst b = secant(i);\n\t\t// A turning point or a flat stretch stays put (Blender's clamped handles); otherwise the harmonic-weighted mean.\n\t\tif (a * b <= 0) continue;\n\t\tconst ha = times[i] - times[i - 1];\n\t\tconst hb = times[i + 1] - times[i];\n\t\tslope[i] = (3 * (ha + hb)) / ((2 * hb + ha) / a + (hb + 2 * ha) / b);\n\t}\n\tconst legs: MotionSmoothLeg[] = [];\n\tfor (let i = 0; i + 1 < n; i++) {\n\t\tconst dt = times[i + 1] - times[i];\n\t\tconst dv = values[i + 1] - values[i];\n\t\tif (Math.abs(dv) < 1e-9) {\n\t\t\tlegs.push({ start: times[i], end: times[i + 1], from: values[i], to: values[i + 1], ease: 'linear' });\n\t\t\tcontinue;\n\t\t}\n\t\t// The Hermite leg as a cubic-bezier ease: handles at thirds of the time, heights from the slopes.\n\t\tconst y1 = (slope[i] * dt) / (3 * dv);\n\t\tconst y2 = 1 - (slope[i + 1] * dt) / (3 * dv);\n\t\tlegs.push({ start: times[i], end: times[i + 1], from: values[i], to: values[i + 1], ease: { type: 'cubic-bezier', x1: 1 / 3, y1, x2: 2 / 3, y2 } });\n\t}\n\treturn legs;\n}\n\n/** When each point of a path is reached over `duration` (ms): in proportion to distance (`even`) or a leg each (`equal`). */\nexport function smoothMotionTimes(points: readonly { x: number; y: number }[], start: number, duration: number, pacing: 'even' | 'equal' = 'even'): number[] {\n\tconst legs = points.slice(1).map((p, i) => (pacing === 'equal' ? 1 : Math.hypot(p.x - points[i].x, p.y - points[i].y)));\n\tconst total = legs.reduce((a, b) => a + b, 0) || legs.length || 1;\n\tconst times = [start];\n\tlet acc = 0;\n\tfor (const l of legs) {\n\t\tacc += total > 0 ? l : 1;\n\t\ttimes.push(start + (duration * acc) / total);\n\t}\n\treturn times;\n}\n","import { mixColorsOklab } from '../animation/color.js';\nimport { matchMotionNodes } from './match.js';\nimport { smoothMotionLegs, smoothMotionTimes } from './smooth.js';\nimport { behaviorProgress, motionSeedFromId, type MotionBehavior } from '../animation/behavior.js';\nimport { evaluateEasing, resolveEasing, springSettleMs, type AnimationEasing } from '../animation/easing.js';\nimport { bezierPathLength } from '../canvas/pathops/bezier.js';\nimport {\n\tIDENTITY_MATRIX,\n\tapplyMatrix,\n\tcollectPathNodes,\n\tinvertMatrix,\n\tmultiplyMatrices,\n\tnodeMatrix,\n\tvectorNodeBounds,\n\tvectorPathWorldBezier,\n\ttype AffineMatrix\n} from '../vector/geometry.js';\nimport type { VectorBounds, VectorNode, VectorPaint } from '../vector/types.js';\nimport {\n\tMOTION_CAMERA_MS,\n\tMOTION_DEFAULT_DURATIONS,\n\tMOTION_DEFAULT_HOLD,\n\tMOTION_DRAW_MS_PER_UNIT,\n\tMOTION_DRAW_RANGE,\n\tMOTION_CLIP_TARGET,\n\ttype MotionBeatGrid,\n\ttype MotionCamera,\n\ttype MotionCommand,\n\ttype MotionCue,\n\ttype MotionDirection,\n\ttype MotionDrawOrder,\n\ttype MotionIrisShape,\n\ttype MotionRect,\n\ttype MotionSplitOrientation,\n\ttype MotionScene,\n\ttype MotionShot\n} from './types.js';\n\n/**\n * Compiling a scene: shots and commands become timed segments, one per (node, property)\n * change. A property's value at a time is that of the latest segment to have started (its\n * `from` before the first one), so a node that enters later is hidden until then. This is\n * also how Flair's vector motion combines changes, which keeps the Flair export exact.\n */\n\n/**\n * Properties a segment can change. Offsets (`x`, `y`, `rotation`) are relative to the rest\n * pose, scales multiply it, and turns and scales are about the node's centre at rest.\n * `effect:<effectId>:<param>` tweens a live path effect's parameter. `camera` (node `\"\"`) is\n * the view box `[x, y, width, height]`. `clipRect` (`[x, y, width, height]`) and `clipCircle`\n * (`[cx, cy, r]`) are the reveal clips of `wipe`, `iris` and `split`, in the units of the\n * node's own box (0–1 across it, SVG's `objectBoundingBox`), as Flair's clip reveals are.\n */\nexport type MotionProperty =\n\t| 'opacity'\n\t| 'x'\n\t| 'y'\n\t| 'rotation'\n\t| 'scaleX'\n\t| 'scaleY'\n\t| 'fill'\n\t| 'stroke'\n\t| 'strokeWidth'\n\t| 'fillOpacity'\n\t| 'drawStart'\n\t| 'drawEnd'\n\t| 'shape'\n\t| 'follow'\n\t| 'clipRect'\n\t| 'clipCircle'\n\t| 'camera'\n\t| `effect:${string}:${string}`;\n\nexport type MotionValue = number | string | readonly number[];\n\nexport interface MotionSegment {\n\t/** Node id (`\"\"` for the camera). */\n\tnode: string;\n\tproperty: MotionProperty;\n\tstart: number;\n\tend: number;\n\tfrom: MotionValue;\n\tto: MotionValue;\n\tease: AnimationEasing;\n\t/** The shot and command (index in `run`) it comes from. */\n\tshot: string;\n\tcommand: number;\n\t/**\n\t * How the change gets from `from` to `to` when not straight along its ease (a pulse there and\n\t * back, a settling oscillation, a wriggle): Flair's `behavior`, exported as is.\n\t */\n\tbehavior?: MotionBehavior;\n\t/**\n\t * Which number of the node's exported value this is (x 0, y 1, rotation 2, matching the\n\t * transform Flair is given), so a wriggle wanders each on the channel Flair uses. Default 0.\n\t */\n\tindex?: number;\n\t/** Played backwards in time (a mirrored repeat): progress runs 1 → 0 through the ease. */\n\treverse?: boolean;\n\t/** Stepped time: progress holds on a grid of this many frames per second from the start. */\n\tsteps?: number;\n\t/** Numbers change by a steady factor (`from·(to/from)^u`); a camera zooms at a steady rate. */\n\tgeometric?: boolean;\n\t/**\n\t * `add`: the segment is a layer over the node's pose rather than a change to it. It lives on\n\t * its own track (`motionAddTrackKey`), runs from 0 (offsets, turns) or 1 (scales), and what\n\t * it adds stays once it ends, on top of whatever the pose does.\n\t */\n\tblend?: 'add';\n\t/** For `follow`: the path node id, and whether to turn with it. */\n\tpath?: string;\n\trotate?: boolean;\n}\n\nexport interface MotionShotTiming {\n\tid: string;\n\tindex: number;\n\tlabel?: string;\n\tstart: number;\n\t/** When the camera move ends and the commands begin. */\n\tcommandsStart: number;\n\t/** When the last command ends (the hold follows). */\n\tcommandsEnd: number;\n\tend: number;\n\t/** The time the shot is cued to start (`at`), when it has a cue that resolves. */\n\tcue?: number;\n\t/** How late the shot starts after its cue (ms), when the shot before ran past it. */\n\tmissedBy?: number;\n}\n\nexport interface MotionCommandTiming {\n\tshot: string;\n\tshotIndex: number;\n\tcommand: number;\n\ttype: MotionCommand['type'];\n\tstart: number;\n\tend: number;\n\t/** Length per target (ms). */\n\tduration: number;\n}\n\nexport interface MotionTimeline {\n\t/** Total length in ms. */\n\tduration: number;\n\tshots: MotionShotTiming[];\n\tcommands: MotionCommandTiming[];\n\tsegments: MotionSegment[];\n\t/** Segments per `node\\u0000property`, in start order. */\n\ttracks: ReadonlyMap<string, readonly MotionSegment[]>;\n}\n\n/** Where a node sits in the artwork. */\nexport interface MotionNodeEntry {\n\tnode: VectorNode;\n\t/** Ids from the root down to the node's parent. */\n\tancestors: string[];\n\t/** Parent space → document space. */\n\tparentWorld: AffineMatrix;\n\t/** Centre of the node's bounds at rest, in its parent's space. */\n\tcenter: { x: number; y: number };\n\t/** Bounds at rest in document space. */\n\tbounds: VectorBounds | null;\n\t/** Bounds at rest in its parent's space (what a reveal clip's box is). */\n\tbox: VectorBounds | null;\n}\n\nconst indexCache = new WeakMap<object, Map<string, MotionNodeEntry>>();\n\n/** Every node of the artwork by id (cached per node list). */\nexport function indexMotionNodes(nodes: readonly VectorNode[]): Map<string, MotionNodeEntry> {\n\tconst hit = indexCache.get(nodes);\n\tif (hit) return hit;\n\tconst out = new Map<string, MotionNodeEntry>();\n\tconst walk = (list: readonly VectorNode[], parentWorld: AffineMatrix, ancestors: string[]) => {\n\t\tfor (const node of list) {\n\t\t\tconst local = vectorNodeBounds(node);\n\t\t\tconst bounds = vectorNodeBounds(node, parentWorld);\n\t\t\tconst center = local ? { x: local.x + local.width / 2, y: local.y + local.height / 2 } : { x: 0, y: 0 };\n\t\t\tif (!out.has(node.id)) out.set(node.id, { node, ancestors, parentWorld, center, bounds, box: local });\n\t\t\tif (node.type === 'group') walk(node.children, multiplyMatrices(nodeMatrix(node), parentWorld), [...ancestors, node.id]);\n\t\t}\n\t};\n\twalk(nodes, IDENTITY_MATRIX, []);\n\tindexCache.set(nodes, out);\n\treturn out;\n}\n\nconst solid = (paint: VectorPaint | undefined): string | undefined => (typeof paint === 'string' && paint !== 'none' ? paint : undefined);\n\n/** The first solid paint of a node (a group's first path with one). */\nfunction firstPaint(node: VectorNode, key: 'fill' | 'stroke'): string | undefined {\n\tif (node.type === 'path') return solid(node[key]);\n\tfor (const p of collectPathNodes(node)) {\n\t\tconst s = solid(p[key]);\n\t\tif (s) return s;\n\t}\n\treturn undefined;\n}\n\n/** How far a stroke reaches past the outline: half its width (all of it outside, none inside). */\nfunction strokeReach(node: VectorNode): number {\n\tlet reach = 0;\n\tfor (const p of node.type === 'path' ? [node] : collectPathNodes(node)) {\n\t\tif (p.stroke == null || p.stroke === 'none') continue;\n\t\tconst width = p.strokeWidth ?? 1;\n\t\treach = Math.max(reach, p.strokeAlign === 'outside' ? width : p.strokeAlign === 'inside' ? 0 : width / 2);\n\t}\n\treturn reach;\n}\n\n/**\n * How far past its box (as a share of its width and height) a reveal clip reaches, so it shows\n * the whole stroke: the stroke's reach over the box plus 0.02, at most 1 (Flair's padding). Null\n * when the box has no width or height (a lone straight line), which a clip cannot reveal.\n */\nexport function motionRevealPadding(entry: MotionNodeEntry): readonly [number, number] | null {\n\tconst box = entry.box;\n\tif (!box || !(box.width > 0) || !(box.height > 0)) return null;\n\tconst s = strokeReach(entry.node);\n\treturn [Math.min(1, s / box.width + 0.02), Math.min(1, s / box.height + 0.02)];\n}\n\n/** Clip numbers as Flair writes them (4 decimals). */\nconst clipRound = (n: number) => Math.round(n * 1e4) / 1e4 || 0;\n\n/** A reveal clip that shows the whole node (padded past its box), in its box's units. */\nfunction revealFull(property: 'clipRect' | 'clipCircle', [px, py]: readonly [number, number]): number[] {\n\treturn (property === 'clipRect' ? [-px, -py, 1 + 2 * px, 1 + 2 * py] : [0.5, 0.5, Math.hypot(0.5 + px, 0.5 + py)]).map(clipRound);\n}\n\nconst OPPOSITE: Record<MotionDirection, MotionDirection> = { up: 'down', down: 'up', left: 'right', right: 'left' };\n\n/** What a reveal clip animates: a wipe (in, or out with `hide`), an iris or a split. */\nexport type MotionReveal = { style: 'wipe'; direction?: MotionDirection; hide?: boolean } | { style: 'iris'; shape?: MotionIrisShape } | { style: 'split'; orientation?: MotionSplitOrientation };\n\n/**\n * The reveal clip a `wipe`, `iris` or `split` animates, from and to (Flair's `entrance.wipe`,\n * `entrance.iris`, `entrance.split` and `exit.wipe`), or null when the node's box has no width\n * or height. An exit wipe is the enter wipe the other way, reversed in time.\n */\nexport function motionRevealClip(entry: MotionNodeEntry, reveal: MotionReveal): { property: 'clipRect' | 'clipCircle'; from: number[]; to: number[] } | null {\n\tconst pad = motionRevealPadding(entry);\n\tif (!pad) return null;\n\tconst [px, py] = pad;\n\tconst [w, h] = [1 + 2 * px, 1 + 2 * py];\n\tconst rect = (from: number[], to: number[]) => ({ property: 'clipRect' as const, from: from.map(clipRound), to: to.map(clipRound) });\n\tif (reveal.style === 'iris') {\n\t\tif (reveal.shape === 'box') return rect([0.5, 0.5, 0, 0], [-px, -py, w, h]);\n\t\treturn { property: 'clipCircle', from: [0.5, 0.5, 0], to: revealFull('clipCircle', pad) };\n\t}\n\tif (reveal.style === 'split') {\n\t\tif (reveal.orientation === 'vertical') return rect([0.5, -py, 0, h], [-px, -py, w, h]);\n\t\treturn rect([-px, 0.5, w, 0], [-px, -py, w, h]);\n\t}\n\tconst direction = reveal.direction ?? 'right';\n\tif (reveal.hide) {\n\t\tconst shown = motionRevealClip(entry, { style: 'wipe', direction: OPPOSITE[direction] })!;\n\t\treturn { ...shown, from: shown.to, to: shown.from };\n\t}\n\tswitch (direction) {\n\t\tcase 'right':\n\t\t\treturn rect([-px, -py, 0, h], [-px, -py, w, h]);\n\t\tcase 'left':\n\t\t\treturn rect([1 + px, -py, 0, h], [-px, -py, w, h]);\n\t\tcase 'down':\n\t\t\treturn rect([-px, -py, w, 0], [-px, -py, w, h]);\n\t\tcase 'up':\n\t\t\treturn rect([-px, 1 + py, w, 0], [-px, -py, w, h]);\n\t}\n}\n\n/** A property's value with no animation. */\nexport function motionRestValue(entry: MotionNodeEntry | undefined, property: MotionProperty, artwork: { width: number; height: number }): MotionValue {\n\tconst node = entry?.node;\n\tswitch (property) {\n\t\tcase 'opacity':\n\t\t\treturn node?.opacity ?? 1;\n\t\tcase 'x':\n\t\tcase 'y':\n\t\tcase 'rotation':\n\t\t\treturn 0;\n\t\tcase 'scaleX':\n\t\tcase 'scaleY':\n\t\tcase 'fillOpacity':\n\t\tcase 'drawEnd':\n\t\t\treturn 1;\n\t\tcase 'drawStart':\n\t\t\treturn 0;\n\t\tcase 'follow':\n\t\t\treturn -1;\n\t\tcase 'fill':\n\t\tcase 'stroke':\n\t\t\treturn (node && firstPaint(node, property)) ?? 'transparent';\n\t\tcase 'strokeWidth': {\n\t\t\tconst path = node?.type === 'path' ? node : node ? collectPathNodes(node)[0] : undefined;\n\t\t\treturn path?.strokeWidth ?? 1;\n\t\t}\n\t\tcase 'shape':\n\t\t\treturn node?.id ?? '';\n\t\tcase 'clipRect':\n\t\tcase 'clipCircle': {\n\t\t\tconst pad = entry && motionRevealPadding(entry);\n\t\t\treturn pad ? revealFull(property, pad) : [];\n\t\t}\n\t\tcase 'camera':\n\t\t\treturn [0, 0, artwork.width, artwork.height];\n\t}\n\tconst [, effectId, param] = property.split(':');\n\tconst effect = node?.effects?.find((e) => e.id === effectId);\n\tconst v = effect ? (effect.params as unknown as Record<string, unknown>)[param] : undefined;\n\treturn typeof v === 'number' ? v : 0;\n}\n\n/** `from` → `to` at eased progress `u` (numbers extrapolate, colours mix in OKLab, others switch at the end). */\nexport function interpolateMotionValue(from: MotionValue, to: MotionValue, u: number): MotionValue {\n\tif (typeof from === 'number' && typeof to === 'number') return from + (to - from) * u;\n\tif (Array.isArray(from) && Array.isArray(to) && from.length === to.length) return from.map((f, i) => f + ((to[i] as number) - f) * u);\n\tif (u <= 0) return from;\n\tif (u >= 1) return to;\n\tif (typeof from === 'string' && typeof to === 'string') {\n\t\tconst mixed = mixColorsOklab(from, to, u);\n\t\tif (mixed !== null) return mixed;\n\t}\n\treturn u < 1 ? from : to;\n}\n\n/** Progress (0–1, unclamped by the easing) of a segment at `time`: stepped, reversed and eased as the segment says. */\nexport function segmentProgress(segment: MotionSegment, time: number): { u: number; eased: number } {\n\tconst span = segment.end - segment.start;\n\tlet elapsed = time - segment.start;\n\tif (segment.steps && segment.steps > 0 && elapsed < span) elapsed = (Math.floor((elapsed * segment.steps) / 1000 + 1e-9) / segment.steps) * 1000;\n\tconst u = span <= 0 ? 1 : Math.min(1, Math.max(0, elapsed / span));\n\t// A reversed segment plays its forward run backwards: at u it shows what it showed at 1 − u.\n\treturn { u, eased: evaluateEasing(segment.ease, segment.reverse ? 1 - u : u, span) };\n}\n\n/** `from` → `to` by a steady factor: numbers above 0 grow geometrically; a camera box zooms at a steady rate, its centre keeping pace. */\nfunction geometricValue(from: MotionValue, to: MotionValue, e: number): MotionValue | undefined {\n\tconst grow = (a: number, b: number) => (a > 0 && b > 0 ? a * (b / a) ** e : undefined);\n\tif (typeof from === 'number' && typeof to === 'number') return grow(from, to);\n\tif (Array.isArray(from) && Array.isArray(to) && from.length === 4 && to.length === 4) {\n\t\tconst [x0, y0, w0, h0] = from as number[];\n\t\tconst [x1, y1, w1, h1] = to as number[];\n\t\tconst w = grow(w0, w1);\n\t\tconst h = grow(h0, h1);\n\t\tif (w === undefined || h === undefined) return undefined;\n\t\t// The centre moves the same share of the way as the size has changed.\n\t\tconst f = Math.abs(w1 - w0) > 1e-9 ? (w - w0) / (w1 - w0) : e;\n\t\tconst cx = x0 + w0 / 2 + (x1 + w1 / 2 - x0 - w0 / 2) * f;\n\t\tconst cy = y0 + h0 / 2 + (y1 + h1 / 2 - y0 - h0 / 2) * f;\n\t\treturn [cx - w / 2, cy - h / 2, w, h];\n\t}\n\treturn undefined;\n}\n\n/**\n * A segment's value at `time`: along its ease, through its behaviour when it has one. `raw`\n * ignores the behaviour (the value it swings towards), as Flair is given it.\n */\nexport function segmentValue(segment: MotionSegment, time: number, raw = false): MotionValue {\n\tconst { eased } = segmentProgress(segment, time);\n\tif (segment.geometric && !segment.behavior) {\n\t\tconst g = geometricValue(segment.from, segment.to, eased);\n\t\tif (g !== undefined) return g;\n\t}\n\tif (!segment.behavior || raw) return interpolateMotionValue(segment.from, segment.to, eased);\n\tconst p = behaviorProgress(segment.behavior, eased, segment.index ?? 0, segment.end - segment.start);\n\t// Colours (a colour pulse) mix only between their ends; numbers swing past them.\n\treturn typeof segment.from === 'string' ? interpolateMotionValue(segment.from, segment.to, Math.min(1, Math.max(0, p))) : interpolateMotionValue(segment.from, segment.to, p);\n}\n\n/** The segment in effect at `time` (the latest to have started), if any. */\nexport function activeSegment(track: readonly MotionSegment[] | undefined, time: number): MotionSegment | undefined {\n\tif (!track?.length) return undefined;\n\tlet found: MotionSegment | undefined;\n\tfor (const s of track) if (s.start <= time && (!found || s.start >= found.start)) found = s;\n\treturn found;\n}\n\n/** A track's value at `time`, or `undefined` when nothing animates it. `raw` ignores behaviours (see `segmentValue`). */\nexport function trackValue(track: readonly MotionSegment[] | undefined, time: number, raw = false): MotionValue | undefined {\n\tif (!track?.length) return undefined;\n\tconst s = activeSegment(track, time);\n\tif (s) return segmentValue(s, time, raw);\n\tlet first = track[0];\n\tfor (const t of track) if (t.start < first.start) first = t;\n\treturn first.from;\n}\n\nexport const motionTrackKey = (node: string, property: MotionProperty) => `${node}\\u0000${property}`;\n\n/** The track of a node property's additive layers (segments with `blend: 'add'`). */\nexport const motionAddTrackKey = (node: string, property: MotionProperty) => `${node}\\u0000${property}\\u0000add`;\n\n/** Properties that take additive layers: offsets and turns add, scales multiply. */\nexport const MOTION_ADDITIVE_PROPERTIES: readonly MotionProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY'];\n\n/**\n * A property's value with its additive layers on top of `base` (its pose): every layer that has\n * started adds its value (offsets, turns) or multiplies by it (scales). `raw` ignores behaviours.\n */\nexport function withMotionLayers(timeline: Pick<MotionTimeline, 'tracks'>, node: string, property: MotionProperty, base: number, time: number, raw = false): number {\n\tconst layers = timeline.tracks.get(motionAddTrackKey(node, property));\n\tif (!layers) return base;\n\tconst scale = property === 'scaleX' || property === 'scaleY';\n\tlet v = base;\n\tfor (const layer of layers) {\n\t\tif (layer.start > time) continue;\n\t\tconst x = Number(segmentValue(layer, time, raw));\n\t\tif (Number.isFinite(x)) v = scale ? v * x : v + x;\n\t}\n\treturn v;\n}\n\n/** Grows a rectangle to the artwork's aspect ratio (about its centre). */\nexport function fitMotionRect(rect: MotionRect, aspect: number): MotionRect {\n\tconst cx = rect.x + rect.width / 2;\n\tconst cy = rect.y + rect.height / 2;\n\tlet { width, height } = rect;\n\tif (width / height < aspect) width = height * aspect;\n\telse height = width / aspect;\n\treturn { x: cx - width / 2, y: cy - height / 2, width, height };\n}\n\n/** The rectangle a camera looks at, or `null` when it frames an unknown node. */\nexport function resolveMotionCamera(camera: MotionCamera, scene: MotionScene): MotionRect | null {\n\tif ('frame' in camera && typeof camera.frame === 'string') {\n\t\tconst entry = indexMotionNodes(scene.artwork.nodes).get(camera.frame);\n\t\tif (!entry?.bounds) return null;\n\t\tconst pad = camera.padding ?? 24;\n\t\tconst b = entry.bounds;\n\t\tconst rect = { x: b.x - pad, y: b.y - pad, width: Math.max(1, b.width + pad * 2), height: Math.max(1, b.height + pad * 2) };\n\t\treturn fitMotionRect(rect, scene.artwork.width / scene.artwork.height);\n\t}\n\tconst r = camera as MotionRect;\n\treturn { x: r.x, y: r.y, width: r.width, height: r.height };\n}\n\n/** Length of a node's outline (its longest path for a group), in document units. */\nexport function motionPathLength(node: VectorNode, parentWorld: AffineMatrix = IDENTITY_MATRIX): number {\n\tlet longest = 0;\n\tconst paths = node.type === 'path' ? [node] : collectPathNodes(node);\n\tfor (const p of paths) {\n\t\ttry {\n\t\t\tlongest = Math.max(longest, bezierPathLength(vectorPathWorldBezier(p, parentWorld, { effects: false })));\n\t\t} catch {\n\t\t\t/* unmeasurable: keep the default */\n\t\t}\n\t}\n\treturn longest;\n}\n\n/** How much a shot's `speed` stretches its time (1 / speed; 1 when unset or not above 0). */\nexport function motionShotTimeScale(shot: MotionShot): number {\n\treturn typeof shot.speed === 'number' && shot.speed > 0 && Number.isFinite(shot.speed) ? 1 / shot.speed : 1;\n}\n\n// Beat grid adapted from soundcraft-main/crates/time/src/{tempo,grid}.rs (MIT OR Apache-2.0, © ArtCraft Team and contributors).\n/** When beat `beat` falls on a grid, ms: `offset + beat · 60000 / bpm`. */\nexport function motionBeatTime(grid: MotionBeatGrid, beat: number): number {\n\treturn (grid.offset ?? 0) + (beat * 60000) / grid.bpm;\n}\n\n/** The beat (fractional) at `ms` on a grid, and its bar and beat in the bar (both from 1). */\nexport function motionBeatAt(grid: MotionBeatGrid, ms: number): { beat: number; bar: number; beatInBar: number } {\n\tconst beat = ((ms - (grid.offset ?? 0)) * grid.bpm) / 60000;\n\tconst meter = Math.max(1, Math.round(grid.meter ?? 4));\n\tconst whole = Math.floor(beat + 1e-9);\n\treturn { beat, bar: Math.floor(whole / meter) + 1, beatInBar: (((whole % meter) + meter) % meter) + 1 };\n}\n\n/** The time a cue names, ms, or undefined when it names a beat with no grid or a word the narration lacks. */\nexport function motionCueTime(scene: Pick<MotionScene, 'beat' | 'narration'>, cue: MotionCue): number | undefined {\n\tif (typeof cue.ms === 'number') return Math.max(0, cue.ms);\n\tif (typeof cue.beat === 'number') return scene.beat && scene.beat.bpm > 0 ? Math.max(0, motionBeatTime(scene.beat, cue.beat)) : undefined;\n\tif (typeof cue.word === 'number') return scene.narration?.words[cue.word]?.start;\n\treturn undefined;\n}\n\n/** How many times a command plays (1 for `enter`, `exit` and `wait`, which do not repeat). */\nexport function motionCommandRepeat(command: MotionCommand): number {\n\tif (command.type === 'wait' || command.type === 'enter' || command.type === 'exit') return 1;\n\tconst n = command.repeat ?? 1;\n\treturn Number.isInteger(n) && n >= 1 ? n : 1;\n}\n\n/** How long one target of a command takes (ms), every repeat included. */\nexport function motionCommandDuration(command: MotionCommand, scene: MotionScene, target?: string): number {\n\treturn motionCycleDuration(command, scene, target) * motionCommandRepeat(command);\n}\n\n/** One command of a clip played on a target: when it starts (ms from the play's start), its target and one cycle's length. */\nexport interface MotionClipItem {\n\tcommand: Exclude<MotionCommand, { type: 'wait' }>;\n\ttarget: string;\n\tstart: number;\n\tcycle: number;\n}\n\n/** A clip's commands for `target` (`\"$\"` replaced), timed as in a shot from 0 at `speed`; unknown clips give nothing. */\nexport function motionClipLayout(scene: MotionScene, clip: string, target: string, speed = 1): { items: MotionClipItem[]; length: number } {\n\tconst run = scene.clips?.[clip]?.run;\n\tif (!run) return { items: [], length: 0 };\n\tconst f = speed > 0 && Number.isFinite(speed) ? 1 / speed : 1;\n\tconst items: MotionClipItem[] = [];\n\tlet runEnd = 0;\n\tlet prevStart = 0;\n\trun.forEach((raw, i) => {\n\t\tconst base = raw.with === 'previous' && i > 0 ? prevStart : runEnd;\n\t\tif (raw.type === 'wait') {\n\t\t\tprevStart = base;\n\t\t\trunEnd = Math.max(runEnd, base + raw.duration * f);\n\t\t\treturn;\n\t\t}\n\t\tif (raw.type === 'play') return;\n\t\tconst command = { ...raw, targets: raw.targets.map((t) => (t === MOTION_CLIP_TARGET ? target : t)) } as Exclude<MotionCommand, { type: 'wait' }>;\n\t\tconst begin = base + (command.delay ?? 0) * f;\n\t\tlet end = begin;\n\t\tcommand.targets.forEach((t, k) => {\n\t\t\tconst cycle = motionCycleDuration(command, scene, t) * f;\n\t\t\tconst s = begin + k * (command.stagger ?? 0) * f;\n\t\t\titems.push({ command, target: t, start: s, cycle });\n\t\t\tend = Math.max(end, s + cycle * motionCommandRepeat(command));\n\t\t});\n\t\tprevStart = begin;\n\t\trunEnd = Math.max(runEnd, end);\n\t});\n\treturn { items, length: runEnd };\n}\n\n/** How long one cycle of a command takes for one target (ms): its `duration`, a spring's settle time, the line's length for a draw, or the type's default. */\nexport function motionCycleDuration(command: MotionCommand, scene: MotionScene, target?: string): number {\n\tif (command.type === 'wait') return command.duration;\n\tif (command.type === 'play') return motionClipLayout(scene, command.clip, target ?? MOTION_CLIP_TARGET, command.speed).length;\n\tif (command.duration !== undefined) return command.duration;\n\tif (command.ease !== undefined) {\n\t\tconst ease = resolveEasing(command.ease);\n\t\tif (ease !== 'hold' && ease.type === 'spring') return springSettleMs(ease);\n\t}\n\tif (command.type === 'draw' || (command.type === 'enter' && command.style === 'draw') || (command.type === 'exit' && command.style === 'undraw')) {\n\t\tconst entry = target ? indexMotionNodes(scene.artwork.nodes).get(target) : undefined;\n\t\tconst length = entry ? motionPathLength(entry.node) : 0;\n\t\tconst ms = length * MOTION_DRAW_MS_PER_UNIT;\n\t\treturn Math.round(Math.min(MOTION_DRAW_RANGE[1], Math.max(MOTION_DRAW_RANGE[0], ms)));\n\t}\n\t// A move through waypoints takes longer the more stretches it has.\n\tif (command.type === 'move' && command.via?.length) return MOTION_DEFAULT_DURATIONS.move + 400 * command.via.length;\n\treturn MOTION_DEFAULT_DURATIONS[command.type];\n}\n\n/** Cubic ease-out, `1 − (1 − t)³` exactly (Flair's `out`): the default for things arriving. */\nexport const MOTION_EASE_OUT: AnimationEasing = { type: 'cubic-bezier', x1: 1 / 3, y1: 1, x2: 2 / 3, y2: 1 };\n/** Cubic ease-in-out (close to Flair's `in-out`): the default for moves. */\nexport const MOTION_EASE_IN_OUT: AnimationEasing = { type: 'cubic-bezier', x1: 0.65, y1: 0, x2: 0.35, y2: 1 };\n\nconst DIRECTION: Record<MotionDirection, { x: number; y: number }> = { up: { x: 0, y: -1 }, down: { x: 0, y: 1 }, left: { x: -1, y: 0 }, right: { x: 1, y: 0 } };\n\nconst timelineCache = new WeakMap<MotionScene, MotionTimeline>();\n\n/**\n * Times every shot and command and turns them into segments. Pure and cached per scene object\n * (treat scenes as immutable). Commands naming unknown nodes are timed but change nothing;\n * `checkMotionScene` reports them.\n */\nexport function compileMotionScene(scene: MotionScene): MotionTimeline {\n\tconst hit = timelineCache.get(scene);\n\tif (hit) return hit;\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst artwork = scene.artwork;\n\n\t// Pass 1: timing.\n\tconst shots: MotionShotTiming[] = [];\n\tconst commands: MotionCommandTiming[] = [];\n\tconst cameraMoves: { shot: string; start: number; end: number; to: MotionRect; ease: AnimationEasing; geometric: boolean }[] = [];\n\tlet t = 0;\n\tscene.shots.forEach((shot, index) => {\n\t\t// A cue holds the shot before until it comes (or, for the first shot, waits from 0).\n\t\tconst cue = shot.at ? motionCueTime(scene, shot.at) : undefined;\n\t\tif (cue !== undefined && cue > t) {\n\t\t\tif (shots.length) shots[shots.length - 1].end = cue;\n\t\t\tt = cue;\n\t\t}\n\t\tconst missedBy = cue !== undefined && t - cue > 0.5 ? t - cue : undefined;\n\t\tconst start = t;\n\t\tlet cursor = start;\n\t\t// A shot's speed scales all of its time: camera move, delays, durations, staggers and hold.\n\t\tconst f = motionShotTimeScale(shot);\n\t\tif (shot.camera) {\n\t\t\tconst rect = resolveMotionCamera(shot.camera, scene);\n\t\t\tif (rect && rect.width > 0 && rect.height > 0) {\n\t\t\t\tconst ms = index === 0 ? 0 : (shot.camera.ms ?? MOTION_CAMERA_MS) * f;\n\t\t\t\tcameraMoves.push({ shot: shot.id, start, end: start + ms, to: rect, ease: shot.camera.ease ?? MOTION_EASE_IN_OUT, geometric: shot.camera.geometric === true });\n\t\t\t\tcursor = start + ms;\n\t\t\t}\n\t\t}\n\t\tconst commandsStart = cursor;\n\t\tlet runEnd = cursor;\n\t\tlet prevStart = cursor;\n\t\tshot.run.forEach((command, i) => {\n\t\t\tconst base = command.with === 'previous' && i > 0 ? prevStart : runEnd;\n\t\t\tconst begin = base + (command.type === 'wait' ? 0 : (command.delay ?? 0) * f);\n\t\t\tconst targets = command.type === 'wait' ? [] : command.targets;\n\t\t\tconst durations = command.type === 'wait' ? [command.duration * f] : targets.map((id) => motionCommandDuration(command, scene, id) * f);\n\t\t\tconst stagger = command.type === 'wait' ? 0 : (command.stagger ?? 0) * f;\n\t\t\tconst end = durations.reduce((m, d, k) => Math.max(m, begin + k * stagger + d), begin);\n\t\t\tcommands.push({ shot: shot.id, shotIndex: index, command: i, type: command.type, start: begin, end, duration: durations[0] ?? 0 });\n\t\t\tprevStart = begin;\n\t\t\trunEnd = Math.max(runEnd, end);\n\t\t});\n\t\tconst end = runEnd + (shot.hold ?? MOTION_DEFAULT_HOLD) * f;\n\t\tshots.push({ id: shot.id, index, ...(shot.label ? { label: shot.label } : {}), start, commandsStart, commandsEnd: runEnd, end, ...(cue !== undefined ? { cue } : {}), ...(missedBy !== undefined ? { missedBy } : {}) });\n\t\tt = end;\n\t});\n\n\t// Pass 2: segments, in start order so each `from` is the value its segment starts at.\n\tconst tracks = new Map<string, MotionSegment[]>();\n\tconst segments: MotionSegment[] = [];\n\tconst valueAt = (node: string, property: MotionProperty, time: number): MotionValue => {\n\t\tconst v = trackValue(tracks.get(motionTrackKey(node, property)), time);\n\t\treturn v ?? motionRestValue(nodes.get(node), property, artwork);\n\t};\n\tconst push = (segment: MotionSegment) => {\n\t\tconst key = segment.blend === 'add' ? motionAddTrackKey(segment.node, segment.property) : motionTrackKey(segment.node, segment.property);\n\t\tlet track = tracks.get(key);\n\t\tif (!track) tracks.set(key, (track = []));\n\t\ttrack.push(segment);\n\t\tsegments.push(segment);\n\t};\n\n\ttype Job = { start: number; order: number; run: () => void };\n\tconst jobs: Job[] = [];\n\tlet order = 0;\n\tfor (const move of cameraMoves) {\n\t\tjobs.push({\n\t\t\tstart: move.start,\n\t\t\torder: order++,\n\t\t\trun: () => push({ node: '', property: 'camera', start: move.start, end: move.end, from: valueAt('', 'camera', move.start), to: [move.to.x, move.to.y, move.to.width, move.to.height], ease: move.ease, shot: move.shot, command: -1, ...(move.geometric ? { geometric: true } : {}) })\n\t\t});\n\t}\n\tfor (const timing of commands) {\n\t\tconst shot = scene.shots[timing.shotIndex];\n\t\tconst command = shot.run[timing.command];\n\t\tif (command.type === 'wait') continue;\n\t\tif (command.type === 'play') {\n\t\t\t// A clip: each of its commands becomes its own job, at its time in the clip.\n\t\t\tconst f = motionShotTimeScale(shot);\n\t\t\tcommand.targets.forEach((target, k) => {\n\t\t\t\tif (!nodes.has(target)) return;\n\t\t\t\tconst at = timing.start + k * (command.stagger ?? 0) * f;\n\t\t\t\tfor (const item of motionClipLayout(scene, command.clip, target, (command.speed ?? 1) / f).items) {\n\t\t\t\t\tconst entry = nodes.get(item.target);\n\t\t\t\t\tif (!entry) continue;\n\t\t\t\t\tjobs.push({ start: at + item.start, order: order++, run: () => compileRepeated(item.command, item.target, entry, at + item.start, item.cycle, timing) });\n\t\t\t\t}\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tcommand.targets.forEach((target, k) => {\n\t\t\tconst entry = nodes.get(target);\n\t\t\tif (!entry) return;\n\t\t\tconst f = motionShotTimeScale(shot);\n\t\t\tconst start = timing.start + k * (command.stagger ?? 0) * f;\n\t\t\tconst cycle = motionCycleDuration(command, scene, target) * f;\n\t\t\tjobs.push({ start, order: order++, run: () => compileRepeated(command, target, entry, start, cycle, timing) });\n\t\t});\n\t}\n\tjobs.sort((a, b) => a.start - b.start || a.order - b.order).forEach((job) => job.run());\n\n\t/**\n\t * Compiles one cycle, then lays further cycles after it: `loop` restarts each from the first\n\t * cycle's start, `mirror` plays every other one backwards, `offset` carries numbers on from\n\t * where the last ended. Stepped time goes on every segment the command makes.\n\t */\n\tfunction compileRepeated(command: Exclude<MotionCommand, { type: 'wait' }>, node: string, entry: MotionNodeEntry, start: number, cycle: number, timing: MotionCommandTiming) {\n\t\tconst first = segments.length;\n\t\tcompileCommand(command, node, entry, start, cycle, timing);\n\t\tconst made = segments.slice(first);\n\t\tconst steps = command.steps ?? scene.steps;\n\t\tif (steps && steps > 0) for (const s of made) s.steps = steps;\n\t\tconst n = motionCommandRepeat(command);\n\t\tconst mode = command.repeatMode ?? 'loop';\n\t\tconst shift = (v: MotionValue, by: MotionValue, k: number): MotionValue => {\n\t\t\tif (typeof v === 'number' && typeof by === 'number') return v + by * k;\n\t\t\tif (Array.isArray(v) && Array.isArray(by) && v.length === by.length) return v.map((x, i) => x + (by[i] as number) * k);\n\t\t\treturn v;\n\t\t};\n\t\tfor (let k = 1; k < n; k++) {\n\t\t\tconst at = start + k * cycle;\n\t\t\tfor (const s of made) {\n\t\t\t\tif (mode === 'mirror' && k % 2 === 1) {\n\t\t\t\t\tpush({ ...s, start: at + (start + cycle - s.end), end: at + (start + cycle - s.start), reverse: !s.reverse });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst delta: MotionValue = typeof s.from === 'number' && typeof s.to === 'number' ? s.to - s.from : Array.isArray(s.from) && Array.isArray(s.to) && s.from.length === s.to.length ? s.to.map((x, i) => (x as number) - (s.from as number[])[i]) : 0;\n\t\t\t\tconst by = mode === 'offset' ? delta : 0;\n\t\t\t\tpush({ ...s, start: at + (s.start - start), end: at + (s.end - start), from: shift(s.from, by, k), to: shift(s.to, by, k) });\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction compileCommand(command: Exclude<MotionCommand, { type: 'wait' }>, node: string, entry: MotionNodeEntry, start: number, duration: number, timing: MotionCommandTiming) {\n\t\tconst end = start + duration;\n\t\tconst where = { shot: timing.shot, command: timing.command };\n\t\tconst seg = (property: MotionProperty, to: MotionValue, ease: AnimationEasing, s = start, e = end, extra: Partial<MotionSegment> = {}) =>\n\t\t\tpush({ node, property, start: s, end: e, from: extra.from ?? valueAt(node, property, s), to, ease, ...where, ...extra });\n\t\tconst rest = (p: MotionProperty) => motionRestValue(entry, p, artwork);\n\t\tconst num = (p: MotionProperty, time = start) => {\n\t\t\tconst v = valueAt(node, p, time);\n\t\t\treturn typeof v === 'number' ? v : 0;\n\t\t};\n\t\tconst ease = command.ease;\n\t\t/**\n\t\t * When each stroke of the target draws, for an order other than all at once over the whole\n\t\t * time (null then): one after another by length, or all at one speed.\n\t\t */\n\t\tconst drawWindows = (s: number, e: number, o: MotionDrawOrder): { id: string; start: number; end: number }[] | null => {\n\t\t\tconst order = o.order ?? 'together';\n\t\t\tconst pace = o.pace ?? 'time';\n\t\t\tif (order === 'together' && pace === 'time') return null;\n\t\t\tconst paths = entry.node.type === 'path' ? [entry.node] : collectPathNodes(entry.node);\n\t\t\tlet list = paths.map((p) => {\n\t\t\t\tconst at = nodes.get(p.id);\n\t\t\t\tlet first = { x: 0, y: 0 };\n\t\t\t\ttry {\n\t\t\t\t\tconst m = vectorPathWorldBezier(p, at?.parentWorld ?? IDENTITY_MATRIX, { effects: false })[0];\n\t\t\t\t\tif (m && m.type === 'M') first = { x: m.x, y: m.y };\n\t\t\t\t} catch {\n\t\t\t\t\t/* unmeasurable: sorts first */\n\t\t\t\t}\n\t\t\t\treturn { id: p.id, len: Math.max(1e-6, motionPathLength(p, at?.parentWorld)), first };\n\t\t\t});\n\t\t\tif (!list.length) return null;\n\t\t\tconst span = Math.max(0, e - s);\n\t\t\tif (order === 'sequence') {\n\t\t\t\tif (o.sortBy === 'distance') {\n\t\t\t\t\tconst b = entry.bounds;\n\t\t\t\t\tconst origin = o.origin ?? (b ? { x: b.x + b.width / 2, y: b.y + b.height / 2 } : { x: 0, y: 0 });\n\t\t\t\t\tlist = [...list].sort((a, c) => Math.hypot(a.first.x - origin.x, a.first.y - origin.y) - Math.hypot(c.first.x - origin.x, c.first.y - origin.y));\n\t\t\t\t}\n\t\t\t\tconst total = list.reduce((sum, p) => sum + p.len, 0);\n\t\t\t\tlet at = s;\n\t\t\t\treturn list.map((p) => {\n\t\t\t\t\tconst w = { id: p.id, start: at, end: at + (span * p.len) / total };\n\t\t\t\t\tat = w.end;\n\t\t\t\t\treturn w;\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst longest = Math.max(...list.map((p) => p.len));\n\t\t\treturn list.map((p) => {\n\t\t\t\tconst d = (span * p.len) / longest;\n\t\t\t\treturn o.align === 'end' ? { id: p.id, start: e - d, end: e } : { id: p.id, start: s, end: s + d };\n\t\t\t});\n\t\t};\n\t\tswitch (command.type) {\n\t\t\tcase 'enter': {\n\t\t\t\tconst style = command.style ?? 'fade';\n\t\t\t\tconst opacity = rest('opacity');\n\t\t\t\tconst reveal =\n\t\t\t\t\tstyle === 'wipe' ? motionRevealClip(entry, { style, direction: command.direction }) : style === 'iris' ? motionRevealClip(entry, { style, shape: command.shape }) : style === 'split' ? motionRevealClip(entry, { style, orientation: command.orientation }) : null;\n\t\t\t\t// An earlier reveal or wipe out leaves its clip; entering opens it again, at once.\n\t\t\t\tfor (const p of ['clipRect', 'clipCircle'] as const) if (p !== reveal?.property && tracks.has(motionTrackKey(node, p))) seg(p, rest(p), 'linear', start, start);\n\t\t\t\tif (reveal) {\n\t\t\t\t\t// The clip reveals. Opacity is set at once too, so a node faded out before shows again,\n\t\t\t\t\t// and a later fade in (whose start would hold back to time 0) leaves this one alone.\n\t\t\t\t\tseg('opacity', opacity, 'linear', start, start);\n\t\t\t\t\tseg(reveal.property, reveal.to, ease ?? MOTION_EASE_OUT, start, end, { from: reveal.from });\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (style === 'draw') {\n\t\t\t\t\tconst windows = drawWindows(start, start + duration * 0.75, command);\n\t\t\t\t\tif (windows) for (const w of windows) push({ node: w.id, property: 'drawEnd', start: w.start, end: w.end, from: 0, to: 1, ease: ease ?? MOTION_EASE_IN_OUT, ...where });\n\t\t\t\t\telse seg('drawEnd', 1, ease ?? MOTION_EASE_IN_OUT, start, start + duration * 0.75, { from: 0 });\n\t\t\t\t\tseg('fillOpacity', 1, MOTION_EASE_OUT, start + duration * 0.6, end, { from: 0 });\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (style === 'pop' || style === 'zoom') {\n\t\t\t\t\tconst from = command.scale ?? (style === 'pop' ? 0.5 : 1.6);\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, start + duration * (style === 'pop' ? 0.4 : 0.5), { from: 0 });\n\t\t\t\t\tseg('scaleX', 1, ease ?? (style === 'pop' ? 'ease-out-back' : MOTION_EASE_OUT), start, end, { from });\n\t\t\t\t\tseg('scaleY', 1, ease ?? (style === 'pop' ? 'ease-out-back' : MOTION_EASE_OUT), start, end, { from });\n\t\t\t\t} else if (style === 'rise') {\n\t\t\t\t\tconst y = num('y');\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, start + duration * 0.5, { from: 0 });\n\t\t\t\t\tseg('y', y, ease ?? 'ease-out-back', start, end, { from: y + (command.distance ?? 20) });\n\t\t\t\t} else if (style === 'grow') {\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, start + duration * 0.3, { from: 0 });\n\t\t\t\t\tseg('scaleX', 1, ease ?? MOTION_EASE_OUT, start, end, { from: 0 });\n\t\t\t\t\tseg('scaleY', 1, ease ?? MOTION_EASE_OUT, start, end, { from: 0 });\n\t\t\t\t} else if (style === 'slide') {\n\t\t\t\t\tconst dir = DIRECTION[command.direction ?? 'up'];\n\t\t\t\t\tconst distance = command.distance ?? 40;\n\t\t\t\t\tconst x = num('x');\n\t\t\t\t\tconst y = num('y');\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, end, { from: 0 });\n\t\t\t\t\tseg('x', x, ease ?? MOTION_EASE_OUT, start, end, { from: x - dir.x * distance });\n\t\t\t\t\tseg('y', y, ease ?? MOTION_EASE_OUT, start, end, { from: y - dir.y * distance });\n\t\t\t\t} else seg('opacity', opacity, ease ?? MOTION_EASE_OUT, start, end, { from: 0 }); // fade, and a reveal of a node with no box\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'exit': {\n\t\t\t\tconst style = command.style ?? 'fade';\n\t\t\t\tconst wipe = style === 'wipe' ? motionRevealClip(entry, { style, direction: command.direction, hide: true }) : null;\n\t\t\t\tif (wipe) seg(wipe.property, wipe.to, ease ?? 'ease-in', start, end, { from: wipe.from });\n\t\t\t\telse if (style === 'undraw') {\n\t\t\t\t\tseg('fillOpacity', 0, 'ease-in', start, start + duration * 0.4);\n\t\t\t\t\tconst windows = drawWindows(start, end, command);\n\t\t\t\t\tif (windows) for (const w of windows) push({ node: w.id, property: 'drawEnd', start: w.start, end: w.end, from: valueAt(w.id, 'drawEnd', w.start), to: 0, ease: ease ?? MOTION_EASE_IN_OUT, ...where });\n\t\t\t\t\telse seg('drawEnd', 0, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\t} else if (style === 'shrink') {\n\t\t\t\t\tseg('scaleX', 0, ease ?? 'ease-in');\n\t\t\t\t\tseg('scaleY', 0, ease ?? 'ease-in');\n\t\t\t\t\tseg('opacity', 0, 'ease-in', start + duration * 0.6, end);\n\t\t\t\t} else if (style === 'slide') {\n\t\t\t\t\tconst dir = DIRECTION[command.direction ?? 'down'];\n\t\t\t\t\tconst distance = command.distance ?? 40;\n\t\t\t\t\tseg('x', num('x') + dir.x * distance, ease ?? 'ease-in');\n\t\t\t\t\tseg('y', num('y') + dir.y * distance, ease ?? 'ease-in');\n\t\t\t\t\tseg('opacity', 0, ease ?? 'ease-in');\n\t\t\t\t} else seg('opacity', 0, ease ?? 'ease-in'); // fade, and a wipe of a node with no box\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'draw': {\n\t\t\t\t// A stroke not drawn before draws on from nothing (and is hidden until then).\n\t\t\t\tconst e = ease ?? MOTION_EASE_IN_OUT;\n\t\t\t\tconst comet = command.comet !== undefined ? Math.min(1, Math.max(0, command.comet)) : undefined;\n\t\t\t\tconst windows = drawWindows(start, end, command) ?? [{ id: node, start, end }];\n\t\t\t\tfor (const w of windows) {\n\t\t\t\t\tif (comet !== undefined) {\n\t\t\t\t\t\t// A travelling stroke: the head runs 0 → 1 + comet and the tail comet behind it, both clamped, so it leaves the path empty.\n\t\t\t\t\t\tpush({ node: w.id, property: 'drawEnd', start: w.start, end: w.end, from: 0, to: 1 + comet, ease: e, ...where });\n\t\t\t\t\t\tpush({ node: w.id, property: 'drawStart', start: w.start, end: w.end, from: -comet, to: 1, ease: e, ...where });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst drawn = tracks.has(motionTrackKey(w.id, 'drawEnd'));\n\t\t\t\t\tpush({ node: w.id, property: 'drawEnd', start: w.start, end: w.end, from: command.from ?? (drawn ? valueAt(w.id, 'drawEnd', w.start) : 0), to: command.to ?? 1, ease: e, ...where });\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'move': {\n\t\t\t\tconst e = ease ?? MOTION_EASE_IN_OUT;\n\t\t\t\tlet dx = command.by?.x ?? 0;\n\t\t\t\tlet dy = command.by?.y ?? 0;\n\t\t\t\tif (command.to) {\n\t\t\t\t\t// The centre lands on `to` (document space): convert the remaining offset to the parent's space.\n\t\t\t\t\tconst inv = invertMatrix(entry.parentWorld);\n\t\t\t\t\tconst target = applyMatrix(inv, command.to);\n\t\t\t\t\tdx = target.x - (entry.center.x + num('x'));\n\t\t\t\t\tdy = target.y - (entry.center.y + num('y'));\n\t\t\t\t}\n\t\t\t\tif (command.via?.length) {\n\t\t\t\t\t// Through waypoints: offsets per axis as monotone cubics, one eased leg per stretch.\n\t\t\t\t\tconst inv = invertMatrix(entry.parentWorld);\n\t\t\t\t\tconst x0 = num('x');\n\t\t\t\t\tconst y0 = num('y');\n\t\t\t\t\tconst add = command.blend === 'add';\n\t\t\t\t\tconst offsets = [{ x: 0, y: 0 }, ...command.via.map((p) => applyMatrix(inv, p)).map((p) => ({ x: p.x - entry.center.x - x0, y: p.y - entry.center.y - y0 })), { x: dx, y: dy }];\n\t\t\t\t\tconst times = smoothMotionTimes(offsets, start, end - start, command.pacing ?? 'even');\n\t\t\t\t\tfor (const axis of ['x', 'y'] as const) {\n\t\t\t\t\t\tconst base = add ? 0 : axis === 'x' ? x0 : y0;\n\t\t\t\t\t\tfor (const leg of smoothMotionLegs(times, offsets.map((o) => o[axis])))\n\t\t\t\t\t\t\tseg(axis, base + leg.to, leg.ease, leg.start, leg.end, { from: base + leg.from, ...(add ? { blend: 'add' as const } : {}) });\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (command.blend === 'add') {\n\t\t\t\t\tseg('x', dx, e, start, end, { from: 0, blend: 'add' });\n\t\t\t\t\tseg('y', dy, e, start, end, { from: 0, blend: 'add' });\n\t\t\t\t} else {\n\t\t\t\t\tseg('x', num('x') + dx, e);\n\t\t\t\t\tseg('y', num('y') + dy, e);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'rotate': {\n\t\t\t\tconst e = ease ?? MOTION_EASE_IN_OUT;\n\t\t\t\tif (command.blend === 'add') seg('rotation', command.to !== undefined ? command.to - num('rotation') : (command.by ?? 0), e, start, end, { from: 0, blend: 'add' });\n\t\t\t\telse seg('rotation', command.to ?? num('rotation') + (command.by ?? 0), e);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'scale': {\n\t\t\t\tconst to = typeof command.to === 'number' ? { x: command.to, y: command.to } : command.to;\n\t\t\t\tconst extra = { ...(command.geometric ? { geometric: true } : {}), ...(command.blend === 'add' ? { from: 1, blend: 'add' as const } : {}) };\n\t\t\t\tseg('scaleX', to.x, ease ?? MOTION_EASE_IN_OUT, start, end, extra);\n\t\t\t\tseg('scaleY', to.y, ease ?? MOTION_EASE_IN_OUT, start, end, extra);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'fade':\n\t\t\t\tseg('opacity', command.to, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\n\t\t\tcase 'style':\n\t\t\t\tif (command.fill !== undefined) seg('fill', command.fill, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tif (command.stroke !== undefined) seg('stroke', command.stroke, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tif (command.strokeWidth !== undefined) seg('strokeWidth', command.strokeWidth, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\n\t\t\tcase 'morph':\n\t\t\t\tseg('shape', command.into, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\n\t\t\tcase 'match': {\n\t\t\t\t// Smart Animate: each part morphs into its partner in `into`; parts with no partner fade out.\n\t\t\t\tconst into = nodes.get(command.into);\n\t\t\t\tif (!into || command.into === node) break;\n\t\t\t\tconst match = matchMotionNodes(entry.node, into.node);\n\t\t\t\tconst e = ease ?? MOTION_EASE_IN_OUT;\n\t\t\t\tfor (const [a, b] of match.pairs) push({ node: a, property: 'shape', start, end, from: valueAt(a, 'shape', start), to: b, ease: e, ...where });\n\t\t\t\tfor (const a of match.unpairedFrom) push({ node: a, property: 'opacity', start, end, from: valueAt(a, 'opacity', start), to: 0, ease: e, ...where });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'follow':\n\t\t\t\tseg('follow', command.to ?? 1, ease ?? MOTION_EASE_IN_OUT, start, end, { from: command.from ?? 0, path: command.path, rotate: command.rotate ?? false });\n\t\t\t\tbreak;\n\t\t\t// Emphasis: a change toward a peak that a behaviour swings round (as Flair's primitives do).\n\t\t\tcase 'pulse':\n\t\t\tcase 'shake':\n\t\t\tcase 'teeter':\n\t\t\tcase 'wave':\n\t\t\tcase 'wiggle': {\n\t\t\t\t// Emphasis is a layer over the pose by default (blend \"add\"), so it rides on a move or turn under way.\n\t\t\t\tconst add = (command.blend ?? 'add') === 'add';\n\t\t\t\t// A change of `by` (offsets, turns) or by a factor (scales), as a layer or on the pose.\n\t\t\t\tconst swing = (p: MotionProperty, by: number, extra: Partial<MotionSegment>) => {\n\t\t\t\t\tconst scale = p === 'scaleX' || p === 'scaleY';\n\t\t\t\t\tif (add) seg(p, by, ease ?? 'linear', start, end, { from: scale ? 1 : 0, blend: 'add', ...extra });\n\t\t\t\t\telse seg(p, scale ? num(p) * by : num(p) + by, ease ?? 'linear', start, end, extra);\n\t\t\t\t};\n\t\t\t\tif (command.type === 'pulse') {\n\t\t\t\t\tconst behavior: MotionBehavior = { type: 'pulse', count: command.count ?? 1 };\n\t\t\t\t\tswing('scaleX', 1 + (command.amount ?? 0.15), { behavior });\n\t\t\t\t\tswing('scaleY', 1 + (command.amount ?? 0.15), { behavior });\n\t\t\t\t} else if (command.type === 'shake') swing(command.axis === 'vertical' ? 'y' : 'x', command.amount ?? 8, { behavior: { type: 'oscillate', count: command.count ?? 3, decay: 1 } });\n\t\t\t\telse if (command.type === 'teeter') swing('rotation', command.angle ?? 8, { behavior: { type: 'oscillate', count: command.count ?? 3, decay: 1 } });\n\t\t\t\telse if (command.type === 'wave') swing('y', -(command.amount ?? 6), { behavior: { type: 'oscillate', count: command.count ?? 2 } });\n\t\t\t\telse {\n\t\t\t\t\tconst behavior: MotionBehavior = { type: 'wriggle', frequency: command.frequency ?? 3, octaves: command.octaves ?? 2, seed: command.seed || motionSeedFromId(node) };\n\t\t\t\t\tconst amount = command.amount ?? 6;\n\t\t\t\t\tswing('x', amount, { behavior, index: 0 });\n\t\t\t\t\tswing('y', amount, { behavior, index: 1 });\n\t\t\t\t\tif (command.rotate) swing('rotation', command.rotate, { behavior, index: 2 });\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'color-pulse':\n\t\t\t\tseg(command.paint ?? 'fill', command.color ?? '#f59e0b', ease ?? 'linear', start, end, { behavior: { type: 'pulse', count: command.count ?? 1 } });\n\t\t\t\tbreak;\n\t\t\tcase 'effect':\n\t\t\t\tseg(`effect:${command.effect}:${command.param}`, command.to, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (const track of tracks.values()) track.sort((a, b) => a.start - b.start);\n\tsegments.sort((a, b) => a.start - b.start);\n\tconst duration = shots.length ? shots[shots.length - 1].end : 0;\n\tconst timeline: MotionTimeline = { duration, shots, commands, segments, tracks };\n\ttimelineCache.set(scene, timeline);\n\treturn timeline;\n}\n\n/** The shot playing at `time` (the last one at the end). */\nexport function motionShotAt(timeline: MotionTimeline, time: number): MotionShotTiming | undefined {\n\treturn timeline.shots.find((s) => time < s.end) ?? timeline.shots[timeline.shots.length - 1];\n}\n","import { normalizeTokenColor, hexToRgba, rgbaToHex } from '../tokens/color.js';\nimport { createVectorMorph, type VectorMorph } from '../vector/blend.js';\nimport { bezierPathLength, bezierPathPointAtLength, transformBezierPath, type BezierPath } from '../canvas/pathops/bezier.js';\nimport { createVectorEffect } from '../vector/appearance.js';\nimport { invertMatrix, multiplyMatrices, nodeMatrix, rotateMatrix, scaleMatrix, translateMatrix, vectorPathWorldBezier, isIdentityMatrix, type AffineMatrix } from '../vector/geometry.js';\nimport { vectorDocumentToSvg, type VectorSvgExportOptions, type VectorSvgWrapper } from '../vector/svg.js';\nimport type { VectorDocument, VectorEffect, VectorGradient, VectorNode, VectorPaint, VectorPathNode } from '../vector/types.js';\nimport { activeSegment, compileMotionScene, indexMotionNodes, motionAddTrackKey, motionTrackKey, withMotionLayers, segmentProgress, trackValue, type MotionNodeEntry, type MotionProperty, type MotionTimeline } from './compile.js';\nimport type { MotionRect, MotionScene } from './types.js';\n\n/**\n * A reveal clip (`wipe`, `iris`, `split`) in the units of the node's own box: 0–1 across it,\n * as SVG's `clipPathUnits=\"objectBoundingBox\"` and Flair's clip reveals are.\n */\nexport type MotionClipShape = { shape: 'rect'; x: number; y: number; width: number; height: number } | { shape: 'circle'; cx: number; cy: number; r: number };\n\n/** The artwork as it stands at one time, and where the camera looks. */\nexport interface MotionFrame {\n\ttime: number;\n\tdocument: VectorDocument;\n\tcamera: MotionRect;\n\t/**\n\t * Reveal clips by node id, outermost first: draw each of those nodes inside a group clipped\n\t * to each shape (`motionFrameToSvg` does). The vector model has no clips, so they ride here.\n\t */\n\tclips: Record<string, MotionClipShape[]>;\n}\n\nexport interface MotionFrameOptions {\n\t/** Control values (`{ accent: \"#0ea5e9\" }`): each recolours its control's default colour. */\n\tvalues?: Record<string, string>;\n\t/** Draw-on as a Trim Paths effect (default true). Off leaves strokes whole. */\n\tdraw?: boolean;\n\t/** Apply moves, turns, scales and follows (default true). Off leaves nodes where they rest. */\n\toffsets?: boolean;\n}\n\n/** Id of the trim effect that draws strokes on. */\nexport const MOTION_DRAW_EFFECT_ID = '~draw';\n\nconst TRANSFORM_PROPS: MotionProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'follow'];\nconst tidy = (v: number) => Math.round(v * 1e6) / 1e6 || 0;\n\n/** A copy of the scene with each control's default colour replaced by its value (exact, case-insensitive matches). */\nexport function applyMotionControlValues(scene: MotionScene, values: Record<string, string> | undefined): MotionScene {\n\tif (!values || !scene.controls?.length) return scene;\n\tconst map = new Map<string, string>();\n\tfor (const control of scene.controls) {\n\t\tconst value = values[control.name];\n\t\tif (typeof value === 'string' && normalizeTokenColor(value) !== null) map.set(control.default.toLowerCase(), value);\n\t}\n\tif (!map.size) return scene;\n\tconst walk = (v: unknown): unknown => {\n\t\tif (typeof v === 'string') return map.get(v.toLowerCase()) ?? v;\n\t\tif (Array.isArray(v)) return v.map(walk);\n\t\tif (v && typeof v === 'object') return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]));\n\t\treturn v;\n\t};\n\treturn { ...scene, artwork: walk(scene.artwork) as VectorDocument, shots: walk(scene.shots) as MotionScene['shots'] };\n}\n\n/** `color` with its alpha multiplied by `alpha` (as `#rrggbbaa`), or `color` when unreadable. */\nfunction fadeColor(color: string, alpha: number): string {\n\tconst hex = normalizeTokenColor(color);\n\tif (hex === null) return color;\n\tconst c = hexToRgba(hex)!;\n\treturn rgbaToHex(c.r, c.g, c.b, c.a * alpha);\n}\n\nfunction fadePaint(paint: VectorPaint | undefined, alpha: number): VectorPaint | undefined {\n\tif (alpha >= 1 || paint == null || paint === 'none') return paint;\n\tif (typeof paint === 'string') return fadeColor(paint, alpha);\n\tif ('stops' in paint && Array.isArray(paint.stops)) return { ...(paint as VectorGradient), stops: paint.stops.map((s) => ({ ...s, opacity: (s.opacity ?? 1) * alpha })) } as VectorGradient;\n\treturn paint;\n}\n\n/** Applies `fn` to the node if it is a path, else to every path inside it. */\nfunction mapPaths(node: VectorNode, fn: (path: VectorPathNode) => VectorPathNode): VectorNode {\n\tif (node.type === 'path') return fn(node);\n\treturn { ...node, children: node.children.map((c) => mapPaths(c, fn)) };\n}\n\nconst morphCache = new WeakMap<VectorNode, WeakMap<VectorNode, VectorMorph>>();\nfunction morphBetween(a: VectorNode, b: VectorNode): VectorMorph {\n\tlet inner = morphCache.get(a);\n\tif (!inner) morphCache.set(a, (inner = new WeakMap()));\n\tlet morph = inner.get(b);\n\tif (!morph) inner.set(b, (morph = createVectorMorph(a, b, { id: a.id })));\n\treturn morph;\n}\n\n/** A shape node by id as it rests in its own parent, mapped into `entry`'s parent space. */\nfunction shapeIn(entry: MotionNodeEntry, shape: MotionNodeEntry): VectorNode {\n\tif (shape === entry) return entry.node;\n\tconst m = multiplyMatrices(multiplyMatrices(nodeMatrix(shape.node), shape.parentWorld), invertMatrix(entry.parentWorld));\n\treturn { ...shape.node, ...(isIdentityMatrix(m) ? { transform: undefined } : { transform: m as VectorNode['transform'] }) } as VectorNode;\n}\n\n/** The node's own shape at `time` (a morph in progress, or the shape it last became). */\nfunction shapeAt(entry: MotionNodeEntry, timeline: MotionTimeline, nodes: Map<string, MotionNodeEntry>, time: number): VectorNode | null {\n\tconst track = timeline.tracks.get(motionTrackKey(entry.node.id, 'shape'));\n\tif (!track?.length) return null;\n\tconst s = activeSegment(track, time);\n\tconst fromId = String(s ? s.from : track[0].from);\n\tif (!s) return fromId === entry.node.id ? null : (nodes.get(fromId) ? shapeIn(entry, nodes.get(fromId)!) : null);\n\tconst a = nodes.get(fromId);\n\tconst b = nodes.get(String(s.to));\n\tif (!a || !b) return null;\n\tconst { eased } = segmentProgress(s, time);\n\tconst u = Math.min(1, Math.max(0, eased));\n\tif (u <= 0) return a === entry ? null : shapeIn(entry, a);\n\tif (u >= 1) return b === entry ? null : shapeIn(entry, b);\n\treturn morphBetween(shapeIn(entry, a), shapeIn(entry, b)).at(u);\n}\n\n/**\n * The path a node follows, in the node's parent's space (live effects left off), or null when\n * `path` is not a path or cannot be measured. Lengths and turns along it are measured there.\n */\nexport function motionFollowRoute(entry: MotionNodeEntry, path: MotionNodeEntry | undefined): BezierPath | null {\n\tif (!path || path.node.type !== 'path') return null;\n\ttry {\n\t\treturn transformBezierPath(vectorPathWorldBezier(path.node, path.parentWorld, { effects: false }), invertMatrix(entry.parentWorld));\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** Where a follow puts the node's centre (parent space), and the path's angle there in degrees. */\nfunction followAt(entry: MotionNodeEntry, timeline: MotionTimeline, nodes: Map<string, MotionNodeEntry>, time: number): { x: number; y: number; angle: number } | null {\n\tconst track = timeline.tracks.get(motionTrackKey(entry.node.id, 'follow'));\n\tconst s = activeSegment(track, time) ?? track?.[0];\n\tif (!s?.path) return null;\n\tconst route = motionFollowRoute(entry, nodes.get(s.path));\n\tconst progress = Number(trackValue(track, time));\n\tif (!route || !(progress >= 0)) return null;\n\ttry {\n\t\tconst at = bezierPathPointAtLength(route, Math.min(1, Math.max(0, progress)) * bezierPathLength(route));\n\t\tif (!at) return null;\n\t\treturn { x: at.point[0], y: at.point[1], angle: s.rotate ? (at.angle * 180) / Math.PI : 0 };\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * The transform a node's offsets, turn, scale and follow add (parent space), or null when none:\n * scaled and turned about its centre, offset by `dx`, `dy`, then (following a path) its centre\n * carried to the point on the path and turned with it, as Flair's `along` carries a wrapper.\n * `raw` ignores behaviours (the pose a pulse or shake swings towards, as Flair is given it);\n * `follow: false` leaves the follow out (`dx` … `scaleY` never include it).\n */\nexport function motionNodeOffset(\n\tentry: MotionNodeEntry,\n\ttimeline: MotionTimeline,\n\ttime: number,\n\tnodes = indexMotionNodes([entry.node]),\n\traw = false,\n\tfollow = true\n): { matrix: AffineMatrix; dx: number; dy: number; rotation: number; scaleX: number; scaleY: number; follow: { x: number; y: number; angle: number } | null } | null {\n\t// The pose, with any additive layers (emphasis, blend \"add\") on top.\n\tconst read = (p: MotionProperty, rest: number) => {\n\t\tconst v = trackValue(timeline.tracks.get(motionTrackKey(entry.node.id, p)), time, raw);\n\t\treturn withMotionLayers(timeline, entry.node.id, p, typeof v === 'number' ? v : rest, time, raw);\n\t};\n\tif (!TRANSFORM_PROPS.some((p) => (follow || p !== 'follow') && (timeline.tracks.has(motionTrackKey(entry.node.id, p)) || timeline.tracks.has(motionAddTrackKey(entry.node.id, p))))) return null;\n\tconst dx = read('x', 0);\n\tconst dy = read('y', 0);\n\tconst rotation = read('rotation', 0);\n\tconst scaleX = read('scaleX', 1);\n\tconst scaleY = read('scaleY', 1);\n\tconst c = entry.center;\n\tlet matrix = multiplyMatrices(multiplyMatrices(scaleMatrix(scaleX, scaleY, c), rotateMatrix(rotation, c)), translateMatrix(dx, dy));\n\tconst along = follow ? followAt(entry, timeline, nodes, time) : null;\n\tif (along) matrix = multiplyMatrices(matrix, multiplyMatrices(multiplyMatrices(translateMatrix(-c.x, -c.y), rotateMatrix(along.angle)), translateMatrix(along.x, along.y)));\n\treturn { matrix, dx, dy, rotation, scaleX, scaleY, follow: along };\n}\n\n/** A node's reveal clips at `time`, outermost first (rect, then circle), with sizes kept ≥ 0. */\nexport function motionNodeClips(id: string, timeline: MotionTimeline, time: number): MotionClipShape[] {\n\tconst out: MotionClipShape[] = [];\n\tconst rect = trackValue(timeline.tracks.get(motionTrackKey(id, 'clipRect')), time);\n\tif (Array.isArray(rect) && rect.length === 4) out.push({ shape: 'rect', x: tidy(rect[0]), y: tidy(rect[1]), width: Math.max(0, tidy(rect[2])), height: Math.max(0, tidy(rect[3])) });\n\tconst circle = trackValue(timeline.tracks.get(motionTrackKey(id, 'clipCircle')), time);\n\tif (Array.isArray(circle) && circle.length === 3) out.push({ shape: 'circle', cx: tidy(circle[0]), cy: tidy(circle[1]), r: Math.max(0, tidy(circle[2])) });\n\treturn out;\n}\n\n/**\n * The scene at `time` (ms): the artwork with every change applied, and the camera. A pure\n * function of time, so frames can be drawn in any order (and the same frames come out every time).\n */\nexport function motionFrameAt(scene: MotionScene, time: number, options: MotionFrameOptions = {}): MotionFrame {\n\tconst s = applyMotionControlValues(scene, options.values);\n\tconst timeline = compileMotionScene(s);\n\tconst nodes = indexMotionNodes(s.artwork.nodes);\n\tconst drawOn = options.draw !== false;\n\tconst value = (id: string, p: MotionProperty) => trackValue(timeline.tracks.get(motionTrackKey(id, p)), time);\n\tconst animated = new Set(timeline.segments.map((seg) => seg.node));\n\tconst clips: Record<string, MotionClipShape[]> = {};\n\n\tconst visit = (node: VectorNode): VectorNode => {\n\t\tlet out: VectorNode = node.type === 'group' ? { ...node, children: node.children.map(visit) } : node;\n\t\tif (!animated.has(node.id)) return out;\n\t\tconst entry = nodes.get(node.id);\n\t\tif (!entry) return out;\n\t\tconst id = node.id;\n\t\tconst clip = motionNodeClips(id, timeline, time);\n\t\tif (clip.length) clips[id] = clip;\n\n\t\tconst shape = shapeAt(entry, timeline, nodes, time);\n\t\tif (shape) {\n\t\t\tconst { name, visible, opacity, locked } = node;\n\t\t\tout = { ...shape, id, ...(name ? { name } : {}), ...(locked ? { locked } : {}), visible, ...(opacity !== undefined ? { opacity } : {}) } as VectorNode;\n\t\t\tif (out.visible === undefined) delete out.visible;\n\t\t}\n\n\t\t// Live path effect parameters.\n\t\tconst effectTracks = [...timeline.tracks.keys()].filter((k) => k.startsWith(`${id}\\u0000effect:`));\n\t\tif (effectTracks.length && out.effects?.length) {\n\t\t\tout = {\n\t\t\t\t...out,\n\t\t\t\teffects: out.effects.map((effect) => {\n\t\t\t\t\tlet params = effect.params as unknown as Record<string, unknown>;\n\t\t\t\t\tfor (const key of effectTracks) {\n\t\t\t\t\t\tconst [, effectId, param] = key.split('\\u0000')[1].split(':');\n\t\t\t\t\t\tif (effectId !== effect.id) continue;\n\t\t\t\t\t\tconst v = trackValue(timeline.tracks.get(key), time);\n\t\t\t\t\t\tif (typeof v === 'number') params = { ...params, [param]: v };\n\t\t\t\t\t}\n\t\t\t\t\treturn params === (effect.params as unknown) ? effect : ({ ...effect, params } as VectorEffect);\n\t\t\t\t})\n\t\t\t};\n\t\t}\n\n\t\tconst fill = value(id, 'fill');\n\t\tconst stroke = value(id, 'stroke');\n\t\tconst strokeWidth = value(id, 'strokeWidth');\n\t\tconst fillOpacity = value(id, 'fillOpacity');\n\t\tconst drawStart = value(id, 'drawStart');\n\t\tconst drawEnd = value(id, 'drawEnd');\n\t\tconst draw = drawOn && (drawStart !== undefined || drawEnd !== undefined);\n\t\tif (fill !== undefined || stroke !== undefined || strokeWidth !== undefined || fillOpacity !== undefined || draw) {\n\t\t\tout = mapPaths(out, (path) => {\n\t\t\t\tlet p: VectorPathNode = path;\n\t\t\t\tif (typeof fill === 'string') p = { ...p, fill };\n\t\t\t\tif (typeof stroke === 'string') p = { ...p, stroke };\n\t\t\t\tif (typeof strokeWidth === 'number') p = { ...p, strokeWidth: Math.max(0, tidy(strokeWidth)) };\n\t\t\t\tif (typeof fillOpacity === 'number' && fillOpacity < 1) p = { ...p, fill: fadePaint(p.fill, Math.max(0, fillOpacity)) };\n\t\t\t\tif (draw) {\n\t\t\t\t\tconst start = Math.min(1, Math.max(0, typeof drawStart === 'number' ? drawStart : 0));\n\t\t\t\t\tconst end = Math.min(1, Math.max(0, typeof drawEnd === 'number' ? drawEnd : 1));\n\t\t\t\t\tif (start > 0 || end < 1) {\n\t\t\t\t\t\tconst trim = createVectorEffect('trim', MOTION_DRAW_EFFECT_ID, { start: tidy(start * 100), end: tidy(end * 100) })!;\n\t\t\t\t\t\tp = { ...p, effects: [trim, ...(p.effects ?? []).filter((e) => e.id !== MOTION_DRAW_EFFECT_ID)] };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn p;\n\t\t\t});\n\t\t}\n\n\t\tconst opacity = value(id, 'opacity');\n\t\tif (typeof opacity === 'number') {\n\t\t\tconst o = Math.min(1, Math.max(0, tidy(opacity)));\n\t\t\tout = { ...out, opacity: o };\n\t\t\tif (o >= 1) delete out.opacity;\n\t\t}\n\n\t\tconst offset = options.offsets === false ? null : motionNodeOffset(entry, timeline, time, nodes);\n\t\tif (offset && !isIdentityMatrix(offset.matrix)) {\n\t\t\tconst m = multiplyMatrices(nodeMatrix(out), offset.matrix).map(tidy) as unknown as VectorNode['transform'];\n\t\t\tout = { ...out, transform: m };\n\t\t}\n\t\treturn out;\n\t};\n\n\tconst document: VectorDocument = { ...s.artwork, nodes: s.artwork.nodes.map(visit) };\n\tconst cam = trackValue(timeline.tracks.get(motionTrackKey('', 'camera')), time);\n\tconst box = Array.isArray(cam) ? cam : [0, 0, s.artwork.width, s.artwork.height];\n\treturn { time, document, camera: { x: tidy(box[0]), y: tidy(box[1]), width: tidy(box[2]), height: tidy(box[3]) }, clips };\n}\n\nexport interface MotionSvgOptions extends MotionFrameOptions, VectorSvgExportOptions {}\n\n/** A clip shape's SVG attributes. */\nexport function motionClipAttrs(clip: MotionClipShape): Record<string, number> {\n\tconst { shape: _shape, ...attrs } = clip;\n\treturn attrs;\n}\n\n/** The scene at `time` as a standalone SVG (the camera becomes the `viewBox`, reveal clips wrap their nodes). */\nexport function motionFrameToSvg(scene: MotionScene, time: number, options: MotionSvgOptions = {}): string {\n\tconst frame = motionFrameAt(scene, time, options);\n\tconst prefix = options.idPrefix ?? 'vg-';\n\tconst wrap: Record<string, readonly VectorSvgWrapper[]> = { ...options.wrap };\n\tfor (const [id, clips] of Object.entries(frame.clips))\n\t\twrap[id] = [...(wrap[id] ?? []), ...clips.map((clip, i) => ({ clip: { id: `${prefix}reveal-${id}-${i}`, shape: clip.shape, attrs: motionClipAttrs(clip) } }))];\n\treturn withViewBox(vectorDocumentToSvg(frame.document, { ...options, wrap }), frame.camera);\n}\n\n/** Replaces the root `viewBox` of an SVG string. */\nexport function withViewBox(svg: string, box: MotionRect): string {\n\tconst f = (n: number) => String(Math.round(n * 1000) / 1000);\n\treturn svg.replace(/viewBox=\"[^\"]*\"/, `viewBox=\"${f(box.x)} ${f(box.y)} ${f(box.width)} ${f(box.height)}\"`);\n}\n","import { compileMotionScene, indexMotionNodes, type MotionProperty } from './compile.js';\nimport { motionFrameAt, motionFrameToSvg, type MotionSvgOptions } from './evaluate.js';\nimport type { MotionRect, MotionScene } from './types.js';\n\n/**\n * Seeing motion on a still: onion skin (faded frames either side of the playhead) and motion\n * paths (where each node's centre travels). Frames are pure functions of time, so both are just\n * more frames: no state, and the same picture every time.\n */\n\nexport interface MotionOnionSkin {\n\t/** Ghost frames before the playhead (default 2). */\n\tbefore?: number;\n\t/** Ghost frames after the playhead (default 0). */\n\tafter?: number;\n\t/**\n\t * Time between ghosts: ms (default 1000 / 12, every other frame at 24 fps), or `commands` to\n\t * ghost the moments commands start and end around the playhead.\n\t */\n\tspacing?: number | 'commands';\n\t/** Opacity of the nearest ghost (default 0.35); further ones fade as 1 / distance. */\n\topacity?: number;\n}\n\nexport interface MotionGhost {\n\ttime: number;\n\t/** Negative before the playhead, positive after: 1 is the nearest. */\n\toffset: number;\n\topacity: number;\n}\n\n/** The ghost frames for a playhead at `time`, nearest first on each side. */\nexport function motionGhosts(scene: MotionScene, time: number, onion: MotionOnionSkin = {}): MotionGhost[] {\n\tconst before = Math.max(0, Math.floor(onion.before ?? 2));\n\tconst after = Math.max(0, Math.floor(onion.after ?? 0));\n\tconst base = Math.min(1, Math.max(0, onion.opacity ?? 0.35));\n\tconst timeline = compileMotionScene(scene);\n\tconst ghosts: MotionGhost[] = [];\n\tconst push = (t: number, offset: number) => ghosts.push({ time: t, offset, opacity: Math.round((base / Math.abs(offset)) * 1000) / 1000 });\n\tif (onion.spacing === 'commands') {\n\t\tconst marks = [...new Set(timeline.commands.flatMap((c) => [c.start, c.end]))].sort((a, b) => a - b);\n\t\tmarks.filter((t) => t < time - 1e-6).reverse().slice(0, before).forEach((t, i) => push(t, -(i + 1)));\n\t\tmarks.filter((t) => t > time + 1e-6).slice(0, after).forEach((t, i) => push(t, i + 1));\n\t\treturn ghosts;\n\t}\n\tconst spacing = typeof onion.spacing === 'number' && onion.spacing > 0 ? onion.spacing : 1000 / 12;\n\tfor (let i = 1; i <= before && time - i * spacing >= 0; i++) push(time - i * spacing, -i);\n\tfor (let i = 1; i <= after && time + i * spacing <= timeline.duration; i++) push(time + i * spacing, i);\n\treturn ghosts;\n}\n\nexport interface MotionPathOptions {\n\t/** From this time, ms (default 0). */\n\tfrom?: number;\n\t/** To this time, ms (default the end). */\n\tto?: number;\n\t/** Time between samples, ms (default 1000 / 30; at most 400 samples). */\n\tstep?: number;\n}\n\nexport interface MotionPath {\n\tid: string;\n\t/** Where the node's centre is, in document units, sample by sample. */\n\tpoints: { t: number; x: number; y: number }[];\n\t/** Where it is when a change that moves it (or a group it is in) starts or ends. */\n\tkeys: { t: number; x: number; y: number }[];\n}\n\nconst MOVING: MotionProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'follow', 'shape'];\n\n/** Ids of the nodes whose place changes (they or a group they are in move, turn, scale, follow or morph). */\nexport function motionMovingIds(scene: MotionScene): string[] {\n\tconst timeline = compileMotionScene(scene);\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst moving = new Set(timeline.segments.filter((s) => s.node && MOVING.includes(s.property)).map((s) => s.node));\n\treturn [...nodes.values()].filter((e) => e.node.visible !== false && (moving.has(e.node.id) || e.ancestors.some((a) => moving.has(a)))).map((e) => e.node.id);\n}\n\n/** Where a node's centre travels over time (its bounds as drawn, in document units). */\nexport function motionPath(scene: MotionScene, id: string, options: MotionPathOptions = {}): MotionPath {\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst entry = nodes.get(id);\n\tif (!entry) throw new Error(`There is no element \"${id}\" in the artwork.`);\n\tconst timeline = compileMotionScene(scene);\n\tconst from = Math.max(0, options.from ?? 0);\n\tconst to = Math.min(timeline.duration, options.to ?? timeline.duration);\n\tlet step = options.step && options.step > 0 ? options.step : 1000 / 30;\n\tif ((to - from) / step > 400) step = (to - from) / 400;\n\tconst r = (n: number) => Math.round(n * 100) / 100;\n\tconst centreAt = (t: number) => {\n\t\tconst node = indexMotionNodes(motionFrameAtCache(scene, t)).get(id);\n\t\tconst b = node?.bounds;\n\t\treturn b ? { t: r(t), x: r(b.x + b.width / 2), y: r(b.y + b.height / 2) } : null;\n\t};\n\tconst points: MotionPath['points'] = [];\n\tfor (let t = from; t <= to + 1e-6; t += step) {\n\t\tconst p = centreAt(Math.min(t, to));\n\t\tif (p) points.push(p);\n\t}\n\tconst owners = new Set([id, ...entry.ancestors]);\n\tconst times = [...new Set(timeline.segments.filter((s) => owners.has(s.node) && MOVING.includes(s.property)).flatMap((s) => [s.start, s.end]))].filter((t) => t >= from && t <= to).sort((a, b) => a - b);\n\tconst keys = times.map(centreAt).filter((p): p is NonNullable<typeof p> => p !== null);\n\treturn { id, points, keys };\n}\n\nfunction motionFrameAtCache(scene: MotionScene, t: number) {\n\treturn motionFrameAt(scene, t).document.nodes;\n}\n\n/** Motion paths as an SVG overlay: a line per node and a dot where each change starts or ends. Stroke widths follow the camera so they read the same at any zoom. */\nexport function motionPathsSvg(paths: readonly MotionPath[], camera: MotionRect, color = '#f43f5e'): string {\n\tconst w = Math.max(camera.width, camera.height) / 400;\n\tconst f = (n: number) => String(Math.round(n * 100) / 100);\n\treturn paths\n\t\t.filter((p) => p.points.length > 1)\n\t\t.map(\n\t\t\t(p) =>\n\t\t\t\t`<g data-motion-path=\"${p.id.replace(/\"/g, '"')}\" fill=\"none\" stroke=\"${color}\" stroke-width=\"${f(w)}\" stroke-linecap=\"round\" stroke-linejoin=\"round\" opacity=\"0.8\"><polyline points=\"${p.points.map((q) => `${f(q.x)},${f(q.y)}`).join(' ')}\" stroke-dasharray=\"${f(w * 3)} ${f(w * 2)}\"/>${p.keys.map((k) => `<circle cx=\"${f(k.x)}\" cy=\"${f(k.y)}\" r=\"${f(w * 2.5)}\" fill=\"${color}\" stroke=\"none\"/>`).join('')}</g>`\n\t\t)\n\t\t.join('');\n}\n\n/** What the stage can draw over a frame. */\nexport interface MotionOverlayOptions {\n\t/** Faded frames either side of the playhead. */\n\tonionSkin?: MotionOnionSkin;\n\t/** Draw where nodes travel: true for every node whose place changes, or a list of ids. */\n\tmotionPaths?: boolean | readonly string[];\n\t/** Colour of motion paths (default `#f43f5e`). */\n\tmotionPathColor?: string;\n}\n\n/** The inside of a standalone SVG (between its root tags). */\nconst innerSvg = (svg: string) => svg.slice(svg.indexOf('>') + 1, svg.lastIndexOf('</svg>'));\n\n/**\n * The frame at `time` as SVG with overlays: ghost frames under it (each with its own id prefix,\n * element ids dropped so they never clash) and motion paths over it. Without overlays it is\n * `motionFrameToSvg`.\n */\nexport function motionStageSvg(scene: MotionScene, time: number, options: MotionSvgOptions & MotionOverlayOptions = {}): string {\n\tconst { onionSkin, motionPaths, motionPathColor, ...svgOptions } = options;\n\tconst current = motionFrameToSvg(scene, time, svgOptions);\n\tif (!onionSkin && !motionPaths) return current;\n\tconst prefix = svgOptions.idPrefix ?? 'vg-';\n\tconst ghosts = onionSkin\n\t\t? motionGhosts(scene, time, onionSkin).map((g, i) => {\n\t\t\t\tconst own = `${prefix}ghost${i}-`;\n\t\t\t\tconst inner = innerSvg(motionFrameToSvg(scene, g.time, { ...svgOptions, idPrefix: own, background: false })).replace(new RegExp(` id=\"(?!${own.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')})[^\"]*\"`, 'g'), '');\n\t\t\t\treturn `<g data-onion=\"${g.offset < 0 ? 'before' : 'after'}\" opacity=\"${g.opacity}\">${inner}</g>`;\n\t\t\t})\n\t\t: [];\n\tconst camera = motionFrameAt(scene, time).camera;\n\tconst ids = motionPaths === true ? motionMovingIds(scene) : motionPaths ? [...motionPaths] : [];\n\tconst paths = ids.length ? motionPathsSvg(ids.map((id) => motionPath(scene, id)), camera, motionPathColor) : '';\n\t// Ghosts go under everything but the background, paths over everything.\n\tconst open = current.indexOf('>') + 1;\n\tconst close = current.lastIndexOf('</svg>');\n\tconst body = current.slice(open, close);\n\tconst bg = svgOptions.background !== false && scene.artwork.background ? /^\\s*<rect[^>]*\\/>/.exec(body)?.[0] ?? '' : '';\n\treturn `${current.slice(0, open)}${bg}${ghosts.join('')}${body.slice(bg.length)}${paths}</svg>`;\n}\n\nexport interface MotionContactSheetOptions extends MotionSvgOptions, MotionOverlayOptions {\n\t/** Frames a row (default: about square). */\n\tcolumns?: number;\n\t/** Write each frame's time (and shot) under it (default true). */\n\tlabels?: boolean;\n}\n\n/**\n * Several moments of the scene in one SVG, in a grid with each frame's time and shot under it:\n * a contact sheet, to see a whole animation (or an agent's change to it) at a glance.\n */\nexport function motionContactSheetSvg(scene: MotionScene, times: readonly number[], options: MotionContactSheetOptions = {}): string {\n\tconst { columns, labels = true, ...frameOptions } = options;\n\tconst n = Math.max(1, times.length);\n\tconst cols = Math.max(1, Math.min(n, Math.floor(columns ?? Math.ceil(Math.sqrt(n)))));\n\tconst rows = Math.ceil(n / cols);\n\tconst { width: w, height: h } = scene.artwork;\n\tconst gap = Math.round(Math.max(w, h) * 0.04);\n\tconst label = labels ? Math.round(Math.max(12, h * 0.08)) : 0;\n\tconst timeline = compileMotionScene(scene);\n\tconst W = cols * w + (cols + 1) * gap;\n\tconst H = rows * (h + label) + (rows + 1) * gap;\n\tconst prefix = frameOptions.idPrefix ?? 'vg-';\n\tconst cells = times.map((t, i) => {\n\t\tconst x = gap + (i % cols) * (w + gap);\n\t\tconst y = gap + Math.floor(i / cols) * (h + label + gap);\n\t\tconst frame = motionStageSvg(scene, t, { ...frameOptions, idPrefix: `${prefix}f${i}-` });\n\t\tconst view = /viewBox=\"([^\"]*)\"/.exec(frame)?.[1] ?? `0 0 ${w} ${h}`;\n\t\t// Each frame keeps its own ids under its prefix; element ids are dropped so frames never clash.\n\t\tconst inner = innerSvg(frame).replace(new RegExp(` id=\"(?!${`${prefix}f${i}-`.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')})[^\"]*\"`, 'g'), '');\n\t\tconst shot = timeline.shots.find((s) => t >= s.start && t < s.end) ?? timeline.shots[timeline.shots.length - 1];\n\t\tconst caption = labels ? `<text x=\"${x + w / 2}\" y=\"${y + h + label * 0.8}\" font-family=\"system-ui, sans-serif\" font-size=\"${Math.round(label * 0.7)}\" text-anchor=\"middle\" fill=\"#64748b\">${(t / 1000).toFixed(2)} s${shot ? ` · ${shot.id.replace(/[<&]/g, '')}` : ''}</text>` : '';\n\t\treturn `<svg x=\"${x}\" y=\"${y}\" width=\"${w}\" height=\"${h}\" viewBox=\"${view}\" overflow=\"hidden\">${inner}</svg><rect x=\"${x}\" y=\"${y}\" width=\"${w}\" height=\"${h}\" fill=\"none\" stroke=\"#cbd5e1\"/>${caption}`;\n\t});\n\treturn `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ${W} ${H}\" width=\"${W}\" height=\"${H}\"><rect width=\"${W}\" height=\"${H}\" fill=\"#f8fafc\"/>${cells.join('')}</svg>`;\n}\n","import { resolveEasing, springSettleMs } from '../animation/easing.js';\nimport { matchMotionNodes } from './match.js';\nimport { normalizeTokenColor } from '../tokens/color.js';\nimport { collectPathNodes } from '../vector/geometry.js';\nimport type { VectorNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionRevealPadding, motionTrackKey, trackValue, type MotionTimeline } from './compile.js';\nimport { motionFrameAt } from './evaluate.js';\nimport { motionIssue, namedWithSuggestion, type MotionIssue } from './issues.js';\nimport { MOTION_CLIP_TARGET, type MotionCommand, type MotionScene } from './types.js';\n\n/** Changes shorter than this (ms) are too quick to follow. */\nexport const MOTION_MIN_CHANGE_MS = 120;\n\nconst NUMERIC_PARAMS = (node: VectorNode, effectId: string): string[] | null => {\n\tconst effect = node.effects?.find((e) => e.id === effectId);\n\tif (!effect) return null;\n\treturn Object.entries(effect.params as unknown as Record<string, unknown>)\n\t\t.filter(([, v]) => typeof v === 'number')\n\t\t.map(([k]) => k);\n};\n\nfunction usesColor(scene: MotionScene, color: string): boolean {\n\tconst target = color.toLowerCase();\n\tlet found = false;\n\tconst walk = (v: unknown) => {\n\t\tif (found) return;\n\t\tif (typeof v === 'string') found = v.toLowerCase() === target;\n\t\telse if (Array.isArray(v)) v.forEach(walk);\n\t\telse if (v && typeof v === 'object') Object.values(v).forEach(walk);\n\t};\n\twalk(scene.artwork);\n\twalk(scene.shots);\n\treturn found;\n}\n\nfunction visibleAt(timeline: MotionTimeline, id: string, time: number, node: VectorNode): boolean {\n\tconst num = (p: Parameters<typeof motionTrackKey>[1], rest: number) => {\n\t\tconst v = trackValue(timeline.tracks.get(motionTrackKey(id, p)), time);\n\t\treturn typeof v === 'number' ? v : rest;\n\t};\n\tif (node.visible === false) return false;\n\tif (num('opacity', node.opacity ?? 1) <= 0.01) return false;\n\tif (Math.abs(num('scaleX', 1) * num('scaleY', 1)) <= 1e-4) return false;\n\t// A reveal clip with no area (before a wipe in, after a wipe out).\n\tconst clip = (p: 'clipRect' | 'clipCircle') => trackValue(timeline.tracks.get(motionTrackKey(id, p)), time);\n\tconst rect = clip('clipRect');\n\tif (Array.isArray(rect) && (rect[2] <= 1e-4 || rect[3] <= 1e-4)) return false;\n\tconst circle = clip('clipCircle');\n\tif (Array.isArray(circle) && circle[2] <= 1e-4) return false;\n\tconst hasFill = node.type === 'path' ? !!node.fill && node.fill !== 'none' : collectPathNodes(node).some((p) => p.fill && p.fill !== 'none');\n\t// A group's strokes may each draw on in turn (draw order): drawn when any of them is.\n\tconst drawn =\n\t\tnum('drawEnd', 1) > 0.01 &&\n\t\t(node.type === 'path' ||\n\t\t\tcollectPathNodes(node).length === 0 ||\n\t\t\tcollectPathNodes(node).some((p) => {\n\t\t\t\tconst v = trackValue(timeline.tracks.get(motionTrackKey(p.id, 'drawEnd')), time);\n\t\t\t\treturn typeof v !== 'number' || v > 0.01;\n\t\t\t}));\n\treturn drawn || (hasFill && num('fillOpacity', 1) > 0.01);\n}\n\n/**\n * What is wrong with a scene's meaning: unknown ids (with a \"did you mean\"), timing that\n * fights itself, things animated while hidden or off camera, and lengths outside the target.\n * The scene must be well formed (see `parseMotionScene`).\n */\nexport function checkMotionScene(scene: MotionScene): MotionIssue[] {\n\tconst issues: MotionIssue[] = [];\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst ids = [...nodes.keys()];\n\tconst timeline = compileMotionScene(scene);\n\tconst artAspect = scene.artwork.width / scene.artwork.height;\n\n\tif (!scene.shots.length) issues.push(motionIssue('no-shots', 'The scene has no shots yet; add one with a list of commands.'));\n\tconst seen = new Set<string>();\n\tfor (const shot of scene.shots) {\n\t\tif (seen.has(shot.id)) issues.push(motionIssue('duplicate-shot-id', `Shot id \"${shot.id}\" is used twice; give each shot its own id.`, { shot: shot.id }));\n\t\tseen.add(shot.id);\n\t}\n\n\tconst known = (id: string, code: 'unknown-target' | 'unknown-path' | 'unknown-shape' | 'unknown-frame', what: string, where: { shot: string; command?: number }) => {\n\t\tif (nodes.has(id)) return true;\n\t\tissues.push(motionIssue(code, `There is no ${what} ${namedWithSuggestion(id, ids)} in the artwork${ids.length ? '' : ' (it has no nodes yet)'}.`, { ...where, ids: [id] }));\n\t\treturn false;\n\t};\n\n\tscene.shots.forEach((shot, shotIndex) => {\n\t\tif (shot.camera && 'frame' in shot.camera && typeof shot.camera.frame === 'string') known(shot.camera.frame, 'unknown-frame', 'node to frame', { shot: shot.id });\n\t\telse if (shot.camera) {\n\t\t\tconst c = shot.camera as { width: number; height: number };\n\t\t\tif (!(c.width > 0 && c.height > 0)) issues.push(motionIssue('invalid-camera', `The camera needs a positive width and height (got ${c.width} × ${c.height}).`, { shot: shot.id }));\n\t\t\telse if (Math.abs(c.width / c.height / artAspect - 1) > 0.02)\n\t\t\t\tissues.push(motionIssue('camera-aspect', `The camera is ${c.width} × ${c.height}, a different shape from the ${scene.artwork.width} × ${scene.artwork.height} artwork, so it shows bands at the sides; frame a node instead to match.`, { shot: shot.id }));\n\t\t}\n\t\tif (!shot.run.length && !shot.camera && shotIndex > 0) issues.push(motionIssue('empty-shot', 'This shot only holds; add commands or a camera move, or remove it.', { shot: shot.id }));\n\n\t\tshot.run.forEach((command: MotionCommand, i) => {\n\t\t\tconst where = { shot: shot.id, command: i };\n\t\t\tif (command.type === 'wait') return;\n\t\t\tconst targets = command.targets.filter((id) => known(id, 'unknown-target', 'node', where));\n\t\t\tconst timing = timeline.commands.find((c) => c.shot === shot.id && c.command === i);\n\t\t\tif (timing && timing.duration > 0 && timing.duration < MOTION_MIN_CHANGE_MS)\n\t\t\t\tissues.push(motionIssue('too-fast', `This ${command.type} lasts ${timing.duration} ms, too quick to follow; make it at least ${MOTION_MIN_CHANGE_MS} ms.`, { ...where, measured: timing.duration, needed: MOTION_MIN_CHANGE_MS, unit: 'ms', ids: targets }));\n\t\t\tif (command.duration !== undefined && command.ease !== undefined) {\n\t\t\t\tconst ease = resolveEasing(command.ease);\n\t\t\t\tif (ease !== 'hold' && ease.type === 'spring') {\n\t\t\t\t\tconst settle = springSettleMs(ease);\n\t\t\t\t\tif (command.duration < settle * 0.9)\n\t\t\t\t\t\tissues.push(motionIssue('spring-cut-short', `This ${command.type}'s spring takes ${settle} ms to settle but lasts ${command.duration} ms, so it jumps to its end; leave \"duration\" out (the spring sets it) or make it at least ${settle} ms.`, { ...where, measured: command.duration, needed: settle, unit: 'ms', ids: targets }));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (command.type === 'follow' && known(command.path, 'unknown-path', 'path', where) && nodes.get(command.path)!.node.type !== 'path')\n\t\t\t\tissues.push(motionIssue('not-a-path', `\"${command.path}\" is a group; follow a single path node.`, { ...where, ids: [command.path] }));\n\t\t\tif (command.type === 'morph') known(command.into, 'unknown-shape', 'shape', where);\n\t\t\tif (command.type === 'play' && !scene.clips?.[command.clip])\n\t\t\t\tissues.push(motionIssue('unknown-clip', `There is no clip ${namedWithSuggestion(command.clip, Object.keys(scene.clips ?? {}))}; define it with set_animation_clip.`, where));\n\t\t\tif (command.type === 'match' && known(command.into, 'unknown-shape', 'group', where)) {\n\t\t\t\tconst into = nodes.get(command.into)!;\n\t\t\t\tfor (const id of targets) {\n\t\t\t\t\tconst entry = nodes.get(id)!;\n\t\t\t\t\tif (id === command.into || into.ancestors.includes(id) || entry.ancestors.includes(command.into)) {\n\t\t\t\t\t\tissues.push(motionIssue('match-self', `\"${id}\" cannot match \"${command.into}\": one is the other or holds it. Match two separate groups (the second usually hidden).`, { ...where, ids: [id, command.into] }));\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst m = matchMotionNodes(entry.node, into.node);\n\t\t\t\t\tif (m.unpairedInto.length)\n\t\t\t\t\t\tissues.push(motionIssue('match-unpaired', `${m.unpairedInto.map((x) => `\"${x}\"`).join(', ')} in \"${command.into}\" ${m.unpairedInto.length > 1 ? 'have' : 'has'} no partner in \"${id}\", so ${m.unpairedInto.length > 1 ? 'they do' : 'it does'} not appear; add a part with the same name or id to \"${id}\" (it can start hidden or tiny).`, { ...where, ids: m.unpairedInto }));\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst style = command.type === 'enter' || command.type === 'exit' ? command.style : undefined;\n\t\t\tif (style === 'wipe' || style === 'iris' || style === 'split')\n\t\t\t\tfor (const id of targets)\n\t\t\t\t\tif (!motionRevealPadding(nodes.get(id)!))\n\t\t\t\t\t\tissues.push(motionIssue('reveal-no-box', `\"${id}\" has no width or height (a straight line), so a ${style} cannot clip it and it fades instead; use style \"${command.type === 'enter' ? 'draw' : 'undraw'}\" for a line.`, { ...where, ids: [id] }));\n\t\t\tif (command.type === 'style') {\n\t\t\t\tfor (const key of ['fill', 'stroke'] as const) {\n\t\t\t\t\tconst color = command[key];\n\t\t\t\t\tif (color === undefined) continue;\n\t\t\t\t\tif (normalizeTokenColor(color) === null) {\n\t\t\t\t\t\tissues.push(motionIssue('invalid-color', `${key} \"${color}\" is not a colour this editor reads; use hex (\"#0ea5e9\"), rgb() or rgba().`, where));\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tfor (const id of targets) {\n\t\t\t\t\t\tconst node = nodes.get(id)!.node;\n\t\t\t\t\t\tconst paths = node.type === 'path' ? [node] : collectPathNodes(node);\n\t\t\t\t\t\tif (paths.some((p) => p[key] !== undefined && p[key] !== null && typeof p[key] !== 'string'))\n\t\t\t\t\t\t\tissues.push(motionIssue('paint-not-color', `\"${id}\" has a gradient ${key}; it switches to ${color} at the end instead of blending.`, { ...where, ids: [id] }));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (command.type === 'color-pulse') {\n\t\t\t\tconst key = command.paint ?? 'fill';\n\t\t\t\tconst color = command.color ?? '#f59e0b';\n\t\t\t\tif (normalizeTokenColor(color) === null) issues.push(motionIssue('invalid-color', `color \"${color}\" is not a colour this editor reads; use hex (\"#0ea5e9\"), rgb() or rgba().`, where));\n\t\t\t\telse\n\t\t\t\t\tfor (const id of targets) {\n\t\t\t\t\t\tconst node = nodes.get(id)!.node;\n\t\t\t\t\t\tconst paths = node.type === 'path' ? [node] : collectPathNodes(node);\n\t\t\t\t\t\tif (paths.some((p) => typeof p[key] !== 'string'))\n\t\t\t\t\t\t\tissues.push(motionIssue('paint-not-color', `\"${id}\" has a gradient or no ${key}, so a colour pulse cannot tint it; give it a solid ${key} or pulse the ${key === 'fill' ? 'stroke' : 'fill'}.`, { ...where, ids: [id] }));\n\t\t\t\t\t}\n\t\t\t}\n\t\t\tif (command.type === 'effect') {\n\t\t\t\tfor (const id of targets) {\n\t\t\t\t\tconst node = nodes.get(id)!.node;\n\t\t\t\t\tconst params = NUMERIC_PARAMS(node, command.effect);\n\t\t\t\t\tconst effects = (node.effects ?? []).map((e) => e.id);\n\t\t\t\t\tif (!params)\n\t\t\t\t\t\tissues.push(motionIssue('unknown-effect', `\"${id}\" has no effect ${namedWithSuggestion(command.effect, effects)}${effects.length ? `; its effects are ${effects.map((e) => `\"${e}\"`).join(', ')}` : '; it has no live effects'}.`, { ...where, ids: [id] }));\n\t\t\t\t\telse if (!params.includes(command.param))\n\t\t\t\t\t\tissues.push(motionIssue('unknown-effect-param', `Effect \"${command.effect}\" has no numeric parameter ${namedWithSuggestion(command.param, params)}; use one of ${params.join(', ')}.`, { ...where, ids: [id] }));\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Visibility at the start of the command.\n\t\t\tif (timing) {\n\t\t\t\tfor (const id of targets) {\n\t\t\t\t\tconst node = nodes.get(id)!.node;\n\t\t\t\t\tconst before = Math.max(0, timing.start - 0.5);\n\t\t\t\t\tconst visible = timing.start > 0 ? visibleAt(timeline, id, before, node) : node.visible !== false;\n\t\t\t\t\tif (command.type === 'enter' && visible && timing.start > 0)\n\t\t\t\t\t\tissues.push(motionIssue('enter-visible', `\"${id}\" is already showing when it enters, so it blinks out first; remove the enter or exit it earlier.`, { ...where, ids: [id] }));\n\t\t\t\t\tconst probe = command.type === 'exit' ? timing.start + 0.5 : (timing.start + timing.end) / 2;\n\t\t\t\t\tif (command.type !== 'enter' && command.type !== 'draw' && !visibleAt(timeline, id, probe, node))\n\t\t\t\t\t\tissues.push(motionIssue('exit-hidden', `\"${id}\" is hidden when this ${command.type} starts, so it is not seen; enter it first.`, { ...where, ids: [id] }));\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t});\n\n\t// Clips: the nodes they name besides \"$\" must exist.\n\tfor (const [name, clip] of Object.entries(scene.clips ?? {}))\n\t\tfor (const command of clip.run)\n\t\t\tif (command.type !== 'wait')\n\t\t\t\tfor (const id of command.targets)\n\t\t\t\t\tif (id !== MOTION_CLIP_TARGET && !nodes.has(id)) issues.push(motionIssue('unknown-target', `Clip \"${name}\" names ${namedWithSuggestion(id, [...nodes.keys()])}, which the artwork does not have; use \"$\" for the node the clip is played on.`, { ids: [id] }));\n\n\t// Triggers: what Flair's player does with a scene played in answer to the viewer.\n\tif (scene.trigger) {\n\t\tif ((scene.loop ?? 'none') !== 'none') issues.push(motionIssue('trigger-loop', `The scene plays on ${scene.trigger}, so its \"${scene.loop}\" loop does not apply; set loop to \"none\" or remove the trigger.`, {}));\n\t\tif (scene.trigger === 'click') {\n\t\t\tif (scene.shots.length === 1) issues.push(motionIssue('click-one-shot', 'The scene plays on click but has one shot, so every click replays it from the start; split it into shots (each click plays the next one).', { shot: scene.shots[0].id }));\n\t\t\tscene.shots.forEach((shot, i) => {\n\t\t\t\tif (i > 0 && shot.at) issues.push(motionIssue('click-cue', `Shot \"${shot.id}\" is cued, but on click a shot starts when it is clicked to; remove its \"at\" or the trigger.`, { shot: shot.id }));\n\t\t\t});\n\t\t}\n\t}\n\n\t// Cues: they must resolve, and the shot before must have ended by then.\n\tscene.shots.forEach((shot, i) => {\n\t\tif (!shot.at) return;\n\t\tconst timing = timeline.shots[i];\n\t\tif (timing.cue === undefined) {\n\t\t\tconst what = shot.at.beat !== undefined ? `beat ${shot.at.beat}, but the scene has no beat grid; set one with set_animation_settings ({ \"beat\": { \"bpm\": … } })` : `word ${shot.at.word}, but the narration has ${scene.narration?.words.length ?? 0} words (indexes from 0)`;\n\t\t\tissues.push(motionIssue('unknown-cue', `Shot \"${shot.id}\" is cued to ${what}.`, { shot: shot.id }));\n\t\t} else if (timing.missedBy !== undefined) {\n\t\t\tconst late = Math.round(timing.missedBy);\n\t\t\tissues.push(motionIssue('cue-missed', `Shot \"${shot.id}\" is cued at ${Math.round(timing.cue)} ms but starts ${late} ms late, because the shot before runs until ${Math.round(timing.start)} ms; shorten that shot (its hold, durations or speed) or cue this one later.`, { shot: shot.id, measured: late, needed: 0, unit: 'ms' }));\n\t\t}\n\t});\n\n\t// Two segments changing the same property of a node at the same time.\n\tfor (const [key, track] of timeline.tracks) {\n\t\t// Additive layers stack by design.\n\t\tif (key.endsWith('\\u0000add')) continue;\n\t\tfor (let i = 1; i < track.length; i++) {\n\t\t\tconst a = track[i - 1];\n\t\t\tconst b = track[i];\n\t\t\tif (b.start < a.end - 1 && (a.shot !== b.shot || a.command !== b.command)) {\n\t\t\t\tconst property = key.split('\\u0000')[1];\n\t\t\t\tif (!a.node) continue;\n\t\t\t\tissues.push(\n\t\t\t\t\tmotionIssue('overlap', `\"${a.node}\" ${property} is changed by two commands at once (shot \"${a.shot}\" command ${a.command + 1} and shot \"${b.shot}\" command ${b.command + 1}); the later one takes over. Start it after the first ends, or use with: \"after\".`, {\n\t\t\t\t\t\tshot: b.shot,\n\t\t\t\t\t\tcommand: b.command,\n\t\t\t\t\t\tids: [a.node]\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Animated nodes that end their command outside the camera.\n\tconst reported = new Set<string>();\n\tfor (const timing of timeline.commands) {\n\t\tconst command = scene.shots[timing.shotIndex].run[timing.command];\n\t\tif (command.type === 'wait' || command.type === 'exit') continue;\n\t\tconst frame = motionFrameAt(scene, timing.end);\n\t\tconst cam = frame.camera;\n\t\tconst docIndex = indexMotionNodes(frame.document.nodes);\n\t\tfor (const id of command.targets) {\n\t\t\tconst b = docIndex.get(id)?.bounds;\n\t\t\tif (!b || reported.has(id) || !visibleAt(timeline, id, timing.end, nodes.get(id)!.node)) continue;\n\t\t\tconst outside = b.x + b.width < cam.x || b.y + b.height < cam.y || b.x > cam.x + cam.width || b.y > cam.y + cam.height;\n\t\t\tif (outside) {\n\t\t\t\treported.add(id);\n\t\t\t\tissues.push(motionIssue('out-of-frame', `\"${id}\" is outside the camera when this ${command.type} ends, so it is not seen; move it into frame or move the camera.`, { shot: timing.shot, command: timing.command, ids: [id] }));\n\t\t\t}\n\t\t}\n\t}\n\n\tif (scene.controls) {\n\t\tfor (const control of scene.controls) {\n\t\t\tif (!usesColor(scene, control.default))\n\t\t\t\tissues.push(motionIssue('unknown-control-color', `Control \"${control.name}\" stands for ${control.default}, which the scene never uses; set its default to a colour in the artwork.`));\n\t\t}\n\t}\n\n\tif (scene.target && scene.shots.length) {\n\t\tconst seconds = Math.round(timeline.duration / 100) / 10;\n\t\tconst [min, max] = scene.target;\n\t\tif (seconds > max) issues.push(motionIssue('scene-too-long', `The scene runs ${seconds} s, past its ${max} s target; shorten holds or durations, or fit it (fit_animation).`, { measured: seconds, needed: max, unit: 's' }));\n\t\tif (seconds < min) issues.push(motionIssue('scene-too-short', `The scene runs ${seconds} s, under its ${min} s target; hold longer, add shots, or fit it (fit_animation).`, { measured: seconds, needed: min, unit: 's' }));\n\t}\n\treturn issues;\n}\n","import type { VectorDocument } from '../vector/types.js';\nimport { checkMotionScene } from './check.js';\nimport { motionIssueKey, motionIssueLine, namedWithSuggestion, type MotionIssue } from './issues.js';\nimport { clipsShapeProblems, commandShapeProblems, motionSceneShapeProblems, shotShapeProblems } from './parse.js';\nimport type { MotionClip, MotionCommand, MotionControl, MotionPreset, MotionScene, MotionShot } from './types.js';\n\n/**\n * Edits as data: each is a pure function of the scene, all or nothing. An edit that leaves the\n * scene malformed, or adds an error the scene did not have (an unknown id, say), changes\n * nothing and says why; existing errors do not block unrelated edits, so a broken scene can be\n * fixed a step at a time.\n */\nexport type MotionEdit =\n\t| { op: 'set_settings'; name?: string; description?: string | null; loop?: MotionScene['loop']; trigger?: MotionScene['trigger'] | null; fps?: number; steps?: number | null; beat?: MotionScene['beat'] | null; narration?: MotionScene['narration'] | null; target?: [number, number] | null }\n\t| { op: 'insert_shots'; shots: MotionShot[]; at?: number }\n\t| { op: 'update_shot'; shot: string; set?: Partial<MotionShot>; remove?: ('label' | 'camera' | 'hold' | 'speed' | 'at')[] }\n\t| { op: 'delete_shots'; shots: string[] }\n\t| { op: 'move_shot'; shot: string; to: number }\n\t| { op: 'add_commands'; shot: string; commands: MotionCommand[]; at?: number }\n\t| { op: 'update_command'; shot: string; command: number; set?: Record<string, unknown>; remove?: string[] }\n\t| { op: 'delete_commands'; shot: string; commands: number[] }\n\t| { op: 'move_command'; shot: string; command: number; to: number }\n\t| { op: 'set_artwork'; artwork: VectorDocument }\n\t| { op: 'set_controls'; controls: MotionControl[]; presets?: MotionPreset[] }\n\t| { op: 'set_clip'; name: string; clip: MotionClip | null }\n\t| { op: 'replace_scene'; scene: MotionScene };\n\nexport type MotionEditOp = MotionEdit['op'];\n\nexport const MOTION_EDIT_OPS: readonly MotionEditOp[] = [\n\t'set_settings',\n\t'insert_shots',\n\t'update_shot',\n\t'delete_shots',\n\t'move_shot',\n\t'add_commands',\n\t'update_command',\n\t'delete_commands',\n\t'move_command',\n\t'set_artwork',\n\t'set_controls',\n\t'set_clip',\n\t'replace_scene'\n];\n\nexport type MotionEditResult =\n\t| {\n\t\t\tok: true;\n\t\t\tscene: MotionScene;\n\t\t\t/** Every issue the edited scene has. */\n\t\t\tissues: MotionIssue[];\n\t\t\t/** Edits that work but may surprise (a later command undoes this one, say). */\n\t\t\thints: string[];\n\t }\n\t| { ok: false; error: string };\n\nclass EditError extends Error {}\nconst fail = (message: string): never => {\n\tthrow new EditError(message);\n};\n\nfunction shotIndex(scene: MotionScene, id: string): number {\n\tconst i = scene.shots.findIndex((s) => s.id === id);\n\tif (i < 0) fail(`There is no shot ${namedWithSuggestion(id, scene.shots.map((s) => s.id))}; the shots are ${scene.shots.map((s) => `\"${s.id}\"`).join(', ') || 'none yet'}.`);\n\treturn i;\n}\n\nfunction position(at: number | undefined, length: number, what: string): number {\n\tif (at === undefined) return length;\n\tif (!Number.isInteger(at) || at < 0 || at > length) fail(`${what} must be a whole number from 0 to ${length} (got ${at}).`);\n\treturn at;\n}\n\nconst replaceShot = (scene: MotionScene, index: number, shot: MotionShot): MotionScene => ({ ...scene, shots: scene.shots.map((s, i) => (i === index ? shot : s)) });\n\n/** A free shot id: `base`, then `base-2`, `base-3`… */\nexport function freshShotId(scene: MotionScene, base = 'shot'): string {\n\tconst used = new Set(scene.shots.map((s) => s.id));\n\tif (!used.has(base)) return base;\n\tlet n = 2;\n\twhile (used.has(`${base}-${n}`)) n++;\n\treturn `${base}-${n}`;\n}\n\nfunction applyOne(scene: MotionScene, edit: MotionEdit): MotionScene {\n\tswitch (edit.op) {\n\t\tcase 'set_settings': {\n\t\t\tconst next: MotionScene = { ...scene };\n\t\t\tif (edit.name !== undefined) next.name = edit.name;\n\t\t\tif (edit.description === null) delete next.description;\n\t\t\telse if (edit.description !== undefined) next.description = edit.description;\n\t\t\tif (edit.loop !== undefined) next.loop = edit.loop;\n\t\t\tif (edit.trigger === null) delete next.trigger;\n\t\t\telse if (edit.trigger !== undefined) {\n\t\t\t\tif (!['click', 'hover', 'press', 'scroll'].includes(edit.trigger)) fail('\"trigger\" must be click, hover, press or scroll, or null to play on its own.');\n\t\t\t\tnext.trigger = edit.trigger;\n\t\t\t}\n\t\t\tif (edit.fps !== undefined) next.fps = edit.fps;\n\t\t\tif (edit.steps === null) delete next.steps;\n\t\t\telse if (edit.steps !== undefined) {\n\t\t\t\tif (!(typeof edit.steps === 'number' && edit.steps > 0 && edit.steps <= 120)) fail('\"steps\" must be frames per second from above 0 to 120 (12 is \"on twos\" at 24 fps), or null for smooth.');\n\t\t\t\tnext.steps = edit.steps;\n\t\t\t}\n\t\t\tfor (const key of ['beat', 'narration'] as const) {\n\t\t\t\tif (edit[key] === null) delete next[key];\n\t\t\t\telse if (edit[key] !== undefined) (next as unknown as Record<string, unknown>)[key] = edit[key];\n\t\t\t}\n\t\t\t{\n\t\t\t\tconst problems = motionSceneShapeProblems(next).filter((p) => /\"beat\"|\"narration\"/.test(p));\n\t\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\t}\n\t\t\tif (edit.target === null) delete next.target;\n\t\t\telse if (edit.target !== undefined) next.target = edit.target;\n\t\t\treturn next;\n\t\t}\n\t\tcase 'set_clip': {\n\t\t\tif (typeof edit.name !== 'string' || !edit.name) fail('Give the clip a \"name\".');\n\t\t\tconst clips = { ...(scene.clips ?? {}) };\n\t\t\tif (edit.clip === null) {\n\t\t\t\tif (!clips[edit.name]) fail(`There is no clip ${namedWithSuggestion(edit.name, Object.keys(clips))} to delete.`);\n\t\t\t\tconst playing = scene.shots.filter((s) => s.run.some((c) => c.type === 'play' && c.clip === edit.name)).map((s) => `\"${s.id}\"`);\n\t\t\t\tif (playing.length) fail(`Clip \"${edit.name}\" is played in shot${playing.length > 1 ? 's' : ''} ${playing.join(', ')}; remove those play commands first.`);\n\t\t\t\tdelete clips[edit.name];\n\t\t\t} else {\n\t\t\t\tconst problems = clipsShapeProblems({ [edit.name]: edit.clip });\n\t\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\t\tclips[edit.name] = edit.clip;\n\t\t\t}\n\t\t\tconst next: MotionScene = { ...scene, clips };\n\t\t\tif (!Object.keys(clips).length) delete next.clips;\n\t\t\treturn next;\n\t\t}\n\t\tcase 'insert_shots': {\n\t\t\tif (!edit.shots.length) fail('Give at least one shot.');\n\t\t\tedit.shots.forEach((shot, i) => {\n\t\t\t\tconst problems = shotShapeProblems(shot, `Shot ${i + 1}`);\n\t\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\t});\n\t\t\tconst ids = new Set(scene.shots.map((s) => s.id));\n\t\t\tfor (const shot of edit.shots) {\n\t\t\t\tif (ids.has(shot.id)) fail(`Shot id \"${shot.id}\" is already used; choose another (e.g. \"${freshShotId(scene, shot.id)}\").`);\n\t\t\t\tids.add(shot.id);\n\t\t\t}\n\t\t\tconst at = position(edit.at, scene.shots.length, '\"at\"');\n\t\t\treturn { ...scene, shots: [...scene.shots.slice(0, at), ...edit.shots, ...scene.shots.slice(at)] };\n\t\t}\n\t\tcase 'update_shot': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst shot: MotionShot = { ...scene.shots[i], ...(edit.set ?? {}) };\n\t\t\tfor (const key of edit.remove ?? []) delete shot[key];\n\t\t\tif (shot.id !== edit.shot && scene.shots.some((s) => s.id === shot.id)) fail(`Shot id \"${shot.id}\" is already used; choose another.`);\n\t\t\tconst problems = shotShapeProblems(shot, `Shot \"${edit.shot}\"`);\n\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\treturn replaceShot(scene, i, shot);\n\t\t}\n\t\tcase 'delete_shots': {\n\t\t\tif (!edit.shots.length) fail('Give at least one shot id.');\n\t\t\tedit.shots.forEach((id) => shotIndex(scene, id));\n\t\t\tconst drop = new Set(edit.shots);\n\t\t\treturn { ...scene, shots: scene.shots.filter((s) => !drop.has(s.id)) };\n\t\t}\n\t\tcase 'move_shot': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst to = position(edit.to, scene.shots.length - 1, '\"to\"');\n\t\t\tconst shots = [...scene.shots];\n\t\t\tconst [shot] = shots.splice(i, 1);\n\t\t\tshots.splice(to, 0, shot);\n\t\t\treturn { ...scene, shots };\n\t\t}\n\t\tcase 'add_commands': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tif (!edit.commands.length) fail('Give at least one command.');\n\t\t\tedit.commands.forEach((command, k) => {\n\t\t\t\tconst problems = commandShapeProblems(command, `Command ${k + 1}`);\n\t\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\t});\n\t\t\tconst run = scene.shots[i].run;\n\t\t\tconst at = position(edit.at, run.length, '\"at\"');\n\t\t\treturn replaceShot(scene, i, { ...scene.shots[i], run: [...run.slice(0, at), ...edit.commands, ...run.slice(at)] });\n\t\t}\n\t\tcase 'update_command': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst run = scene.shots[i].run;\n\t\t\tif (!Number.isInteger(edit.command) || edit.command < 0 || edit.command >= run.length)\n\t\t\t\tfail(`Shot \"${edit.shot}\" has ${run.length} command${run.length === 1 ? '' : 's'}; \"command\" must be an index from 0 to ${run.length - 1} (got ${edit.command}).`);\n\t\t\tconst command = { ...run[edit.command], ...(edit.set ?? {}) } as Record<string, unknown>;\n\t\t\tfor (const key of edit.remove ?? []) {\n\t\t\t\tif (key === 'type') fail('\"type\" cannot be removed; replace the command instead.');\n\t\t\t\tdelete command[key];\n\t\t\t}\n\t\t\tconst problems = commandShapeProblems(command, `Command ${edit.command}`);\n\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\treturn replaceShot(scene, i, { ...scene.shots[i], run: run.map((c, k) => (k === edit.command ? (command as unknown as MotionCommand) : c)) });\n\t\t}\n\t\tcase 'delete_commands': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst run = scene.shots[i].run;\n\t\t\tif (!edit.commands.length) fail('Give at least one command index.');\n\t\t\tfor (const k of edit.commands)\n\t\t\t\tif (!Number.isInteger(k) || k < 0 || k >= run.length) fail(`Shot \"${edit.shot}\" has no command ${k}; indexes run from 0 to ${run.length - 1}.`);\n\t\t\tconst drop = new Set(edit.commands);\n\t\t\treturn replaceShot(scene, i, { ...scene.shots[i], run: run.filter((_, k) => !drop.has(k)) });\n\t\t}\n\t\tcase 'move_command': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst run = [...scene.shots[i].run];\n\t\t\tif (!Number.isInteger(edit.command) || edit.command < 0 || edit.command >= run.length)\n\t\t\t\tfail(`Shot \"${edit.shot}\" has ${run.length} command${run.length === 1 ? '' : 's'}; \"command\" must be an index from 0 to ${run.length - 1} (got ${edit.command}).`);\n\t\t\tconst to = position(edit.to, run.length - 1, '\"to\"');\n\t\t\tconst [moved] = run.splice(edit.command, 1);\n\t\t\trun.splice(to, 0, moved);\n\t\t\treturn replaceShot(scene, i, { ...scene.shots[i], run });\n\t\t}\n\t\tcase 'set_artwork':\n\t\t\treturn { ...scene, artwork: edit.artwork };\n\t\tcase 'set_controls': {\n\t\t\tconst next: MotionScene = { ...scene, controls: edit.controls };\n\t\t\tif (!edit.controls.length) delete next.controls;\n\t\t\tif (edit.presets !== undefined) {\n\t\t\t\tif (edit.presets.length) next.presets = edit.presets;\n\t\t\t\telse delete next.presets;\n\t\t\t}\n\t\t\tconst names = new Set(edit.controls.map((c) => c.name));\n\t\t\tfor (const preset of next.presets ?? [])\n\t\t\t\tfor (const key of Object.keys(preset.values))\n\t\t\t\t\tif (!names.has(key)) fail(`Preset \"${preset.name}\" sets ${namedWithSuggestion(key, names)}, which is not a control.`);\n\t\t\treturn next;\n\t\t}\n\t\tcase 'replace_scene':\n\t\t\treturn edit.scene;\n\t}\n}\n\nfunction errorKeys(issues: readonly MotionIssue[]): Set<string> {\n\treturn new Set(issues.filter((i) => i.severity === 'error').map(motionIssueKey));\n}\n\n/** Hints: commands whose change a later command takes over. */\nfunction editHints(before: MotionIssue[], after: MotionIssue[]): string[] {\n\tconst old = new Set(before.map(motionIssueKey));\n\treturn after.filter((i) => i.code === 'overlap' && !old.has(motionIssueKey(i))).map(motionIssueLine);\n}\n\n/** Applies edits in order, as one change. Fails without changing anything when one fails. */\nexport function applyMotionEdits(scene: MotionScene, edits: MotionEdit | readonly MotionEdit[]): MotionEditResult {\n\tconst list = Array.isArray(edits) ? edits : [edits as MotionEdit];\n\tconst before = checkMotionScene(scene);\n\tlet next = scene;\n\tfor (let i = 0; i < list.length; i++) {\n\t\tconst edit = list[i];\n\t\tconst prefix = list.length > 1 ? `op ${i + 1} (${edit?.op}): ` : '';\n\t\tif (!edit || !(MOTION_EDIT_OPS as readonly string[]).includes(edit.op))\n\t\t\treturn { ok: false, error: `${prefix}Unknown op ${namedWithSuggestion(String(edit?.op), MOTION_EDIT_OPS)}. Nothing was changed.` };\n\t\ttry {\n\t\t\tnext = applyOne(next, edit);\n\t\t} catch (error) {\n\t\t\tif (error instanceof EditError) return { ok: false, error: `${prefix}${error.message} Nothing was changed.` };\n\t\t\tthrow error;\n\t\t}\n\t\tconst problems = motionSceneShapeProblems(next);\n\t\tif (problems.length) return { ok: false, error: `${prefix}Nothing was changed: ${problems.join(' ')}` };\n\t}\n\tconst issues = checkMotionScene(next);\n\tconst had = errorKeys(before);\n\tconst added = issues.filter((i) => i.severity === 'error' && !had.has(motionIssueKey(i)));\n\tif (added.length) return { ok: false, error: `Nothing was changed: ${added.map(motionIssueLine).join(' ')}` };\n\treturn { ok: true, scene: next, issues, hints: editHints(before, issues) };\n}\n\n/** What one edit made, for later edits in a batch to refer to (`\"$0.indexes[0]\"`). */\nexport interface MotionEditOutcome {\n\top: string;\n\t/** The shot it changed or added to. */\n\tshot?: string;\n\t/** Shots it added. */\n\tshots?: string[];\n\t/** Indexes of the commands it added (or where it moved one). */\n\tindexes?: number[];\n\t/** The clip it set. */\n\tclip?: string;\n}\n\nconst REF = /^\\$(\\d+|last)((?:\\.[A-Za-z_]\\w*|\\[\\d+\\])+)$/;\n\n/**\n * Resolves references to earlier edits' outcomes in a batch: a string `\"$N.path\"` (`$last` for the\n * one before) is replaced by that value, e.g. `\"$0.indexes[0]\"` for the index of the first command\n * edit 0 added; `\"$$...\"` is a literal `$`. Returns the resolved edits with what each made, or why\n * a reference does not resolve. Nothing is applied.\n */\nexport function resolveMotionEditRefs(scene: MotionScene, edits: readonly MotionEdit[]): { ok: true; edits: MotionEdit[]; outcomes: MotionEditOutcome[] } | { ok: false; error: string } {\n\tconst outcomes: MotionEditOutcome[] = [];\n\tconst resolved: MotionEdit[] = [];\n\tlet next = scene;\n\tfor (let i = 0; i < edits.length; i++) {\n\t\tconst where = `op ${i + 1} (${edits[i]?.op})`;\n\t\tlet problem: string | null = null;\n\t\tconst walk = (v: unknown): unknown => {\n\t\t\tif (typeof v === 'string') {\n\t\t\t\tif (v.startsWith('$$')) return v.slice(1);\n\t\t\t\tconst m = REF.exec(v);\n\t\t\t\tif (!m) return v;\n\t\t\t\tconst n = m[1] === 'last' ? i - 1 : Number(m[1]);\n\t\t\t\tif (!(n >= 0 && n < i)) {\n\t\t\t\t\tproblem = `${where}: \"${v}\" refers to op ${n + 1}, but only ops before this one (1 to ${i}) can be referred to.`;\n\t\t\t\t\treturn v;\n\t\t\t\t}\n\t\t\t\tlet value: unknown = outcomes[n];\n\t\t\t\tfor (const part of m[2].match(/\\.[A-Za-z_]\\w*|\\[\\d+\\]/g) ?? []) value = value == null ? undefined : (value as Record<string, unknown>)[part.startsWith('.') ? part.slice(1) : part.slice(1, -1)];\n\t\t\t\tif (value === undefined) problem = `${where}: \"${v}\" has no value; op ${n + 1} made ${JSON.stringify(outcomes[n])}.`;\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tif (Array.isArray(v)) return v.map(walk);\n\t\t\tif (v && typeof v === 'object') return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]));\n\t\t\treturn v;\n\t\t};\n\t\tconst edit = walk(edits[i]) as MotionEdit;\n\t\tif (problem) return { ok: false, error: `${problem} Nothing was changed.` };\n\t\tconst before = next;\n\t\ttry {\n\t\t\tnext = applyOne(next, edit);\n\t\t} catch (error) {\n\t\t\tif (error instanceof EditError) return { ok: false, error: `${where}: ${error.message} Nothing was changed.` };\n\t\t\tthrow error;\n\t\t}\n\t\tresolved.push(edit);\n\t\tconst out: MotionEditOutcome = { op: edit.op };\n\t\tif (edit.op === 'insert_shots') out.shots = edit.shots.map((s) => s.id);\n\t\tif ('shot' in edit && typeof edit.shot === 'string') out.shot = edit.op === 'update_shot' && edit.set?.id ? edit.set.id : edit.shot;\n\t\tif (edit.op === 'add_commands') {\n\t\t\tconst at = edit.at ?? before.shots.find((s) => s.id === edit.shot)?.run.length ?? 0;\n\t\t\tout.indexes = edit.commands.map((_, k) => at + k);\n\t\t}\n\t\tif (edit.op === 'move_command') out.indexes = [edit.to];\n\t\tif (edit.op === 'set_clip') out.clip = edit.name;\n\t\toutcomes.push(out);\n\t}\n\treturn { ok: true, edits: resolved, outcomes };\n}\n\n/** An empty scene over `artwork`. */\nexport function createMotionScene(artwork: VectorDocument, init: Partial<Omit<MotionScene, 'artwork' | 'version'>> = {}): MotionScene {\n\treturn { version: 1, name: init.name ?? 'animation', ...init, artwork, shots: init.shots ?? [] };\n}\n","// Protected regions adapted from effectcraft-main/crates/render/src/eval.rs (`responsive_source_time`), MIT OR Apache-2.0, © ArtCraft Team and contributors.\nimport { compileMotionScene } from './compile.js';\nimport { namedWithSuggestion } from './issues.js';\nimport type { MotionScene } from './types.js';\n\nexport interface MotionFitOptions {\n\t/** Shot ids that keep their pace (a logo hold, a line of narration); the others absorb the change. */\n\tkeep?: readonly string[];\n}\n\nexport interface MotionFit {\n\tscene: MotionScene;\n\t/** The length after fitting, ms (within a few ms of the target: speeds are rounded). */\n\tduration: number;\n\t/** The new `speed` of every shot that changed. */\n\tspeeds: Record<string, number>;\n}\n\n/** Speeds are kept within this range. */\nexport const MOTION_SPEED_RANGE: readonly [number, number] = [0.05, 20];\n\n/**\n * Fits a scene to `ms` by setting its shots' `speed`: the shots in `keep` play as they are and\n * the rest stretch or squeeze by the same factor, so their timing keeps its proportions (the\n * responsive time of After Effects' protected regions). Throws, changing nothing, when the\n * kept shots alone outlast the target or a speed would leave `MOTION_SPEED_RANGE`.\n */\nexport function fitMotionScene(scene: MotionScene, ms: number, options: MotionFitOptions = {}): MotionFit {\n\tif (!(Number.isFinite(ms) && ms > 0)) throw new Error('Give the length to fit as a number of milliseconds above 0.');\n\tconst ids = scene.shots.map((s) => s.id);\n\tconst keep = new Set(options.keep ?? []);\n\tfor (const id of keep) if (!ids.includes(id)) throw new Error(`There is no shot ${namedWithSuggestion(id, ids)} to keep.`);\n\tconst timeline = compileMotionScene(scene);\n\tlet kept = 0;\n\tlet rest = 0;\n\ttimeline.shots.forEach((t) => (keep.has(t.id) ? (kept += t.end - t.start) : (rest += t.end - t.start)));\n\tif (rest <= 0) throw new Error(keep.size ? 'Every shot is kept, so nothing can change pace; keep fewer shots.' : 'The scene has no length to fit; add shots first.');\n\tif (ms <= kept) throw new Error(`The kept shots alone last ${Math.round(kept)} ms, so the scene cannot fit ${Math.round(ms)} ms; keep fewer shots or give at least ${Math.ceil(kept) + 1} ms.`);\n\tconst k = (ms - kept) / rest;\n\tconst speeds: Record<string, number> = {};\n\tconst shots = scene.shots.map((shot) => {\n\t\tif (keep.has(shot.id)) return shot;\n\t\tconst speed = Math.round(((shot.speed ?? 1) / k) * 10000) / 10000;\n\t\tif (speed < MOTION_SPEED_RANGE[0] || speed > MOTION_SPEED_RANGE[1])\n\t\t\tthrow new Error(`Fitting ${Math.round(ms)} ms would play shot \"${shot.id}\" at ${speed}× (speeds run ${MOTION_SPEED_RANGE[0]}–${MOTION_SPEED_RANGE[1]}); aim nearer the current ${Math.round(timeline.duration)} ms.`);\n\t\tspeeds[shot.id] = speed;\n\t\tconst { speed: _old, ...rest } = shot;\n\t\treturn speed === 1 ? rest : { ...rest, speed };\n\t});\n\tconst fitted: MotionScene = { ...scene, shots };\n\treturn { scene: fitted, duration: compileMotionScene(fitted).duration, speeds };\n}\n","import type { MotionBehavior } from '../animation/behavior.js';\nimport { evaluateEasing, resolveEasing, reverseCubicBezier, type AnimationEasing } from '../animation/easing.js';\nimport { bezierPathToSvg, transformBezierPath } from '../canvas/pathops/bezier.js';\nimport { normalizeTokenColor } from '../tokens/color.js';\nimport { expandVectorAppearance, expandVectorAppearances } from '../vector/appearance.js';\nimport { IDENTITY_MATRIX, collectPathNodes, invertMatrix, nodeMatrix, vectorPathWorldBezier } from '../vector/geometry.js';\nimport { vectorDocumentToSvg, type VectorSvgWrapper } from '../vector/svg.js';\nimport type { VectorNode, VectorPathNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionAddTrackKey, motionTrackKey, segmentValue, trackValue, type MotionProperty, type MotionSegment } from './compile.js';\nimport { motionClipAttrs, motionFollowRoute, motionFrameAt, motionNodeClips, motionNodeOffset } from './evaluate.js';\nimport type { MotionScene, MotionTrigger } from './types.js';\n\n/**\n * Export to Flair (`@pixerate/flair`): a scene becomes an `SvgMotion` (one SVG plus a list of\n * from → to changes on its elements), a catalog `VectorEffect`, or an `EffectDocument` for\n * Flair's effect editor. The types are mirrored here so this package does not depend on Flair.\n *\n * Changes are exact where Flair can express them: a change with a linear, cubic-out or\n * cubic-in-out curve (the editor's defaults) is one change, and so (Flair 0.36 and later) is\n * one with any cubic-bezier curve, written as `[x1, y1, x2, y2]`. Anything else (springs,\n * elastic, `hold`, morphs and live-effect tweens) is sampled at the\n * scene's `fps` into short linear changes, which Flair plays the same way. Pulses, shakes,\n * teeters, waves, wiggles and colour pulses are one change with a `behavior` (Flair 0.38).\n *\n * Reveals (`wipe`, `iris`, `split`) wrap their node in a group clipped through a rect or circle\n * in the group's own box units (`clipPathUnits=\"objectBoundingBox\"`), as Flair's\n * `entrance.wipe` does, and animate the shape's attributes. A follow wraps its node in a group\n * that Flair's `along` carries along a copy of the path in the node's parent's units (written\n * in `<defs>`, so the path may be hidden or anywhere), turning with it for `orient`, as\n * Flair's `path.follow` does.\n */\n\n/** Flair's easing names. */\nexport type FlairEaseName = 'linear' | 'in-out' | 'out';\n\n/** Flair's spring ease (Flair 0.39 and later): the editor's spring, number for number. */\nexport interface FlairSpringEase {\n\tspring: { mass?: number; stiffness?: number; damping?: number; velocity?: number };\n}\n\n/** A Flair easing: a name, (Flair 0.36 and later) a CSS cubic-bezier `[x1, y1, x2, y2]`, or (0.39) a spring. */\nexport type FlairEase = FlairEaseName | readonly [number, number, number, number] | FlairSpringEase;\n\n/** Flair's curves, for matching. */\nexport const FLAIR_EASES: Readonly<Record<FlairEaseName, (t: number) => number>> = {\n\tlinear: (t) => t,\n\t'in-out': (t) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2),\n\tout: (t) => 1 - (1 - t) ** 3\n};\n\n/** One change of a Flair `SvgMotion` (mirrors `SvgAnimation` in `@pixerate/flair/vector`). */\nexport interface FlairSvgAnimation {\n\tid?: string;\n\tstep?: number;\n\tdelay?: number;\n\tms?: number;\n\tease?: FlairEase;\n\tattrs?: Record<string, readonly [string | number, string | number]>;\n\tdraw?: boolean | readonly [number, number];\n\t/** Moves the element along a path (by id), from and to the fractions of its length in `at`. */\n\talong?: string;\n\tat?: readonly [number, number];\n\t/** With `along`: turns the element with the path's direction. */\n\torient?: boolean;\n\t/** Flair 0.38 and later: how the change swings from → to (see `MotionBehavior`). */\n\tbehavior?: MotionBehavior;\n\t/** Flair 0.39 and later: stepped time, held on a grid of this many frames per second. */\n\tstrobe?: number;\n\t/** Flair 0.39 and later: whole cycles to play (default 1); with `alternate`, every other one backwards. */\n\trepeat?: number;\n\talternate?: boolean;\n\t/** Flair features scenes do not have (imports skip them with a note). */\n\tcount?: readonly [number, number];\n\twrite?: string;\n\tscramble?: string;\n\tsolo?: number;\n\tview?: readonly [number, number, number, number] | string;\n}\n\n/** Mirrors `SvgMotion` in `@pixerate/flair/vector`. */\nexport interface FlairSvgMotion {\n\tsvg: string;\n\tanimate?: FlairSvgAnimation[];\n}\n\n/** Mirrors Flair's catalog `VectorEffect` (`@pixerate/flair/catalog`). */\nexport interface FlairVectorEffect {\n\tkind: 'vector';\n\tid: string;\n\tname: string;\n\tdescription: string;\n\tcategory: string;\n\ttags: string[];\n\tmotion: FlairSvgMotion;\n\t/** Values are `#rrggbb` strings, or `[r, g, b]` channels from 0 to 1 (Flair's catalog writes both); imports turn them into hex. */\n\tpresets?: { name: string; values: Record<string, string | readonly number[]> }[];\n\t/** Ms on the last frame before looping. */\n\thold?: number;\n\ttrigger?: 'hover' | 'press' | 'click' | 'scroll';\n}\n\n/** Mirrors Flair's `EffectDocument` (`@pixerate/flair/editor`) for a vector effect. */\nexport interface FlairEffectDocument {\n\tversion: 1;\n\tname: string;\n\teffect: { kind: 'vector'; motion: FlairSvgMotion; hold?: number };\n\tvalues: Record<string, string>;\n\ttracks: Record<string, never>;\n\tduration: number;\n\tloop: boolean;\n\tpresets: { name: string; values: Record<string, string> }[];\n}\n\nexport interface FlairMotionExport {\n\tmotion: FlairSvgMotion;\n\t/** The scene's length (ms). */\n\tduration: number;\n\t/** Ms after the last change (Flair's `hold`). */\n\thold: number;\n\t/** Changes sampled into linear steps. */\n\tsampled: number;\n\t/** What could not be carried over, in sentences. */\n\tnotes: string[];\n\t/** How the viewer plays it: pass to Flair's `SvgPlayer` as `{ trigger }` (from the scene's `trigger`). */\n\ttrigger?: MotionTrigger;\n}\n\nexport interface FlairExportOptions {\n\t/**\n\t * Play in answer to the viewer (default: the scene's `trigger`; null for none). With `click`\n\t * shot n is Flair step n + 1: nothing plays until the first click, and each click plays the next shot.\n\t */\n\ttrigger?: MotionTrigger | null;\n\t/** Sampling rate for changes Flair cannot express exactly (default: the scene's `fps`, else 30). */\n\tfps?: number;\n\t/** Decimal places (default 3). */\n\tprecision?: number;\n\t/**\n\t * Write cubic-bezier easings (the `ease`, `ease-in`, `ease-out`, `ease-in-out`, `ease-in-back`\n\t * and `ease-out-back` presets, and `{ type: 'cubic-bezier' }` curves) as one change with\n\t * `ease: [x1, y1, x2, y2]` (default true). Needs Flair 0.36 or later; set false for older\n\t * Flair, and they are sampled into linear steps.\n\t */\n\tcurves?: boolean;\n\t/**\n\t * Write pulses, shakes, teeters, waves, wiggles and colour pulses as one change with a Flair\n\t * `behavior` (default true), so they play exactly. Needs Flair 0.38 or later; set false for\n\t * older Flair, and they are sampled into linear steps.\n\t */\n\tbehaviors?: boolean;\n\t/**\n\t * The Flair version the export is for (default `0.39`): it decides what is written exactly\n\t * and what is sampled. 0.36 adds cubic-bezier curves, 0.38 behaviours, 0.39 springs and\n\t * stepped time (`strobe`). `curves` and `behaviors` override it.\n\t */\n\tflair?: string;\n}\n\n/** The Flair version exports target by default. */\nexport const FLAIR_EXPORT_VERSION = '0.39';\n\n/** Whether Flair `version` is at least `min` (dotted numbers). */\nexport function flairAtLeast(version: string, min: string): boolean {\n\tconst a = version.split('.').map((n) => parseInt(n, 10) || 0);\n\tconst b = min.split('.').map((n) => parseInt(n, 10) || 0);\n\tfor (let i = 0; i < Math.max(a.length, b.length); i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);\n\treturn true;\n}\n\n/** The Flair easing that matches `ease` (within 1% everywhere), if any. */\nexport function flairEaseFor(ease: AnimationEasing): FlairEaseName | undefined {\n\tfor (const name of ['linear', 'out', 'in-out'] as const) {\n\t\tlet worst = 0;\n\t\tfor (let i = 1; i < 40; i++) {\n\t\t\tconst t = i / 40;\n\t\t\tworst = Math.max(worst, Math.abs(evaluateEasing(ease, t, 1000) - FLAIR_EASES[name](t)));\n\t\t}\n\t\tif (worst < 0.01) return name;\n\t}\n\treturn undefined;\n}\n\n/**\n * The Flair easing for `ease`: a Flair name when one matches within 1%, else (with `curves`,\n * the default) the curve's `[x1, y1, x2, y2]` when it is a cubic-bezier. Undefined for curves\n * Flair cannot play (springs, elastic, `hold`), which are sampled.\n */\nexport function flairCurveFor(ease: AnimationEasing, curves = true): FlairEase | undefined {\n\tconst name = flairEaseFor(ease);\n\tif (name || !curves) return name;\n\tconst resolved = resolveEasing(ease);\n\tif (resolved === 'hold' || resolved.type !== 'cubic-bezier') return undefined;\n\treturn [resolved.x1, resolved.y1, resolved.x2, resolved.y2];\n}\n\n/** Whether a curve leaves 0–1 (a back ease or a spring), so its values pass `from` or `to`. */\nconst overshoots = (ease: FlairEase) => typeof ease !== 'string' && ('spring' in ease || ease[1] < 0 || ease[1] > 1 || ease[3] < 0 || ease[3] > 1);\n\ntype ChannelValue = number | string | readonly number[];\n\ninterface Channel {\n\tid: string;\n\t/** `attrs`: several number attributes changing together (`attrs` names them, `value` gives them in order). */\n\tkind: 'attr' | 'attrs' | 'draw' | 'view';\n\tattr?: string;\n\tattrs?: readonly string[];\n\tsegments: MotionSegment[];\n\texact: (segment: MotionSegment) => boolean;\n\t/**\n\t * Whether a value past `from` → `to` plays the same in Flair as in the editor. Transforms and\n\t * the camera extrapolate; colours would leave 0–255 and opacity and draw-on are clamped here.\n\t */\n\tovershoot?: boolean;\n\tvalue: (time: number) => ChannelValue;\n\t/** The value with behaviours ignored: what a behaviour swings towards (default `value`). */\n\traw?: (time: number) => ChannelValue;\n}\n\nconst TRANSFORM_PROPS: MotionProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'follow'];\nconst LINEAR_TRANSFORM = new Set<MotionProperty>(['x', 'y', 'rotation', 'scaleX', 'scaleY']);\n\nfunction hex6(color: unknown): string {\n\tconst hex = normalizeTokenColor(color);\n\treturn hex ? hex.slice(0, 7) : '#000000';\n}\n\n/** A scene as a Flair `SvgMotion`. */\nexport function toFlairSvgMotion(scene: MotionScene, options: FlairExportOptions = {}): FlairMotionExport {\n\tconst fps = options.fps ?? scene.fps ?? 30;\n\tconst precision = options.precision ?? 3;\n\tconst flair = options.flair ?? FLAIR_EXPORT_VERSION;\n\tconst curves = options.curves ?? flairAtLeast(flair, '0.36');\n\tconst behaviors = options.behaviors ?? flairAtLeast(flair, '0.38');\n\tconst springs = flairAtLeast(flair, '0.39');\n\tconst strobes = flairAtLeast(flair, '0.39');\n\tconst writeEase = (ease: FlairEase): FlairEase => (typeof ease === 'string' || 'spring' in ease ? ease : (ease.map(round) as unknown as FlairEase));\n\t// The ease Flair is given for a segment: its curve (run backwards for a mirrored repeat) or its spring, if Flair can take it.\n\tconst easeOf = (segment: MotionSegment): FlairEase | undefined => {\n\t\tconst resolved = resolveEasing(segment.ease);\n\t\tif (resolved !== 'hold' && resolved.type === 'spring') {\n\t\t\tif (!springs || segment.reverse) return undefined;\n\t\t\tconst { mass, stiffness, damping, velocity } = resolved;\n\t\t\treturn { spring: { mass, stiffness, damping, velocity } };\n\t\t}\n\t\tif (!segment.reverse) return flairCurveFor(segment.ease, curves);\n\t\tconst back = reverseCubicBezier(segment.ease);\n\t\treturn back && curves ? flairCurveFor(back, curves) : undefined;\n\t};\n\t// A segment with a behaviour plays exactly when Flair can be given the behaviour.\n\tconst plays = (s: MotionSegment) => (!s.behavior || behaviors) && (!s.steps || strobes) && !s.geometric;\n\tconst round = (n: number) => Math.round(n * 10 ** precision) / 10 ** precision;\n\tconst f = (n: number) => String(round(n));\n\tconst timeline = compileMotionScene(scene);\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst notes: string[] = [];\n\tconst channels: Channel[] = [];\n\tconst track = (id: string, p: MotionProperty) => timeline.tracks.get(motionTrackKey(id, p)) ?? [];\n\n\t// The outermost node (of a path and its groups) whose track sets `p` for that path.\n\tconst owner = (path: VectorPathNode, p: MotionProperty): string | undefined => {\n\t\tconst entry = nodes.get(path.id);\n\t\tif (!entry) return undefined;\n\t\treturn [...entry.ancestors, path.id].find((id) => timeline.tracks.has(motionTrackKey(id, p)));\n\t};\n\n\tconst animatedNodes = new Set(timeline.segments.map((s) => s.node).filter(Boolean));\n\tconst pathsSeen = new Set<string>();\n\t// Groups written round nodes (outermost first), routes for `along`, and the ids they take.\n\tconst wrap: Record<string, VectorSvgWrapper[]> = {};\n\tconst routes: string[] = [];\n\tconst follows: { id: string; wrapper: string; routes: Map<string, string>; segments: MotionSegment[] }[] = [];\n\tconst usedIds = new Set(nodes.keys());\n\tconst freshId = (base: string) => {\n\t\tlet id = base;\n\t\tfor (let n = 2; usedIds.has(id); n++) id = `${base}-${n}`;\n\t\tusedIds.add(id);\n\t\treturn id;\n\t};\n\tfor (const id of animatedNodes) {\n\t\tconst entry = nodes.get(id)!;\n\t\tconst node = entry.node;\n\t\t// Wrappers only go round nodes that are drawn (a hidden node is left out of the SVG).\n\t\tconst drawn = [...entry.ancestors.map((a) => nodes.get(a)!.node), node].every((n) => n.visible !== false);\n\n\t\t// Reveal clips: a group clipped through a shape whose attributes change (outermost: it clips what the follow carries).\n\t\tfor (const [p, name] of [['clipRect', 'reveal'], ['clipCircle', 'iris']] as const) {\n\t\t\tif (!drawn || !timeline.tracks.has(motionTrackKey(id, p))) continue;\n\t\t\tconst wrapper = freshId(`${id}--${name}`);\n\t\t\tconst clipId = freshId(`${wrapper}-clip`);\n\t\t\tconst shapeId = freshId(`${wrapper}-clip-shape`);\n\t\t\tconst clipAt = (t: number) => motionNodeClips(id, timeline, t).find((c) => c.shape === (p === 'clipRect' ? 'rect' : 'circle'))!;\n\t\t\tconst rest = clipAt(0);\n\t\t\t(wrap[id] ??= []).push({ id: wrapper, clip: { id: clipId, shapeId, shape: rest.shape, attrs: motionClipAttrs(rest) } });\n\t\t\tchannels.push({ id: shapeId, kind: 'attrs', attrs: Object.keys(motionClipAttrs(rest)), segments: [...track(id, p)], exact: () => true, value: (t) => Object.values(motionClipAttrs(clipAt(t))).map((v) => Math.round(v * 1e4) / 1e4) });\n\t\t}\n\n\t\t// A follow: Flair's `along` carries a wrapper, and an inner one puts the node's centre on it.\n\t\tconst followSegments = track(id, 'follow');\n\t\tif (drawn && followSegments.length) {\n\t\t\tconst ids = new Map<string, string>();\n\t\t\tfor (const seg of followSegments) {\n\t\t\t\tif (!seg.path || ids.has(seg.path)) continue;\n\t\t\t\tconst route = motionFollowRoute(entry, nodes.get(seg.path));\n\t\t\t\tif (!route) continue;\n\t\t\t\tconst routeId = freshId(`${id}--follow-route`);\n\t\t\t\tids.set(seg.path, routeId);\n\t\t\t\troutes.push(`<path id=\"${routeId}\" d=\"${bezierPathToSvg(route, { precision })}\" fill=\"none\"/>`);\n\t\t\t}\n\t\t\tif (ids.size) {\n\t\t\t\tconst wrapper = freshId(`${id}--follow`);\n\t\t\t\tconst centre = freshId(`${id}--follow-centre`);\n\t\t\t\tconst c = entry.center;\n\t\t\t\t// Where the follow puts it at the start, for players that draw a still frame without `along`.\n\t\t\t\tconst at = motionNodeOffset(entry, timeline, 0, nodes)?.follow;\n\t\t\t\tconst placed = at ? `translate(${f(at.x)} ${f(at.y)})${at.angle ? ` rotate(${f(at.angle)})` : ''}` : undefined;\n\t\t\t\t(wrap[id] ??= []).push({ id: wrapper, ...(placed ? { transform: placed } : {}) }, { id: centre, transform: `translate(${f(-c.x)} ${f(-c.y)})` });\n\t\t\t\tfollows.push({ id, wrapper, routes: ids, segments: followSegments.filter((seg) => seg.path && ids.has(seg.path)) });\n\t\t\t}\n\t\t}\n\n\t\tif (timeline.tracks.has(motionTrackKey(id, 'opacity')))\n\t\t\tchannels.push({ id, kind: 'attr', attr: 'opacity', segments: [...track(id, 'opacity')], exact: plays, value: (t) => round(Math.min(1, Math.max(0, Number(trackValue(track(id, 'opacity'), t))))) });\n\n\t\t// The node's own moves, turns and scales (a follow is carried by its wrappers).\n\t\tconst followed = follows.some((x) => x.id === id);\n\t\t// Additive layers share the transform: alone in a stretch they are one change, overlapping the pose they are sampled.\n\t\tconst transformSegments = TRANSFORM_PROPS.flatMap((p) => (followed && p === 'follow' ? [] : [...track(id, p), ...(timeline.tracks.get(motionAddTrackKey(id, p)) ?? [])]));\n\t\tif (transformSegments.length) {\n\t\t\tconst base = node.transform ? ` matrix(${node.transform.map(f).join(' ')})` : '';\n\t\t\tconst c = entry.center;\n\t\t\tconst transformAt = (t: number, raw: boolean) => {\n\t\t\t\tconst o = motionNodeOffset(entry, timeline, t, nodes, raw, !followed)!;\n\t\t\t\treturn `translate(${f(o.dx)} ${f(o.dy)}) rotate(${f(o.rotation)} ${f(c.x)} ${f(c.y)}) translate(${f(c.x)} ${f(c.y)}) scale(${f(o.scaleX)} ${f(o.scaleY)}) translate(${f(-c.x)} ${f(-c.y)})${base}`;\n\t\t\t};\n\t\t\tchannels.push({\n\t\t\t\tid,\n\t\t\t\tkind: 'attr',\n\t\t\t\tattr: 'transform',\n\t\t\t\tsegments: transformSegments,\n\t\t\t\texact: (s) => LINEAR_TRANSFORM.has(s.property) && plays(s),\n\t\t\t\tovershoot: true,\n\t\t\t\t// x, y and the angle are the transform's numbers 0, 1 and 2 (`MotionSegment.index`).\n\t\t\t\tvalue: (t) => transformAt(t, false),\n\t\t\t\traw: (t) => transformAt(t, true)\n\t\t\t});\n\t\t}\n\n\t\t// Paint, width, fill fade and draw-on live on paths: a group's change goes to each path in it.\n\t\tconst paths = node.type === 'path' ? [node] : collectPathNodes(node);\n\t\tfor (const path of paths) {\n\t\t\tif (pathsSeen.has(path.id)) continue;\n\t\t\tpathsSeen.add(path.id);\n\t\t\tconst paint = (p: 'fill' | 'stroke', attr: string) => {\n\t\t\t\tconst from = owner(path, p);\n\t\t\t\tif (from) channels.push({ id: path.id, kind: 'attr', attr, segments: [...track(from, p)], exact: plays, value: (t) => hex6(trackValue(track(from, p), t)), raw: (t) => hex6(trackValue(track(from, p), t, true)) });\n\t\t\t};\n\t\t\tpaint('fill', 'fill');\n\t\t\tpaint('stroke', 'stroke');\n\t\t\tconst width = owner(path, 'strokeWidth');\n\t\t\tif (width) channels.push({ id: path.id, kind: 'attr', attr: 'stroke-width', segments: [...track(width, 'strokeWidth')], exact: () => true, value: (t) => round(Number(trackValue(track(width, 'strokeWidth'), t))) });\n\t\t\tconst fade = owner(path, 'fillOpacity');\n\t\t\tif (fade) channels.push({ id: path.id, kind: 'attr', attr: 'fill-opacity', segments: [...track(fade, 'fillOpacity')], exact: () => true, value: (t) => round(Number(trackValue(track(fade, 'fillOpacity'), t))) });\n\t\t\tconst draw = owner(path, 'drawEnd');\n\t\t\tif (draw) channels.push({ id: path.id, kind: 'draw', segments: [...track(draw, 'drawEnd')], exact: () => true, value: (t) => round(Math.min(1, Math.max(0, Number(trackValue(track(draw, 'drawEnd'), t))))) });\n\t\t\tif (owner(path, 'drawStart')) notes.push(`\"${path.id}\": drawing from a start other than 0 is not exported; Flair draws from the start of the path.`);\n\t\t}\n\n\t\t// Shape changes (morphs, live effect tweens) are sampled as the path's `d`.\n\t\tconst shapeSegments = [...timeline.tracks.entries()].filter(([k]) => k.startsWith(`${id}\\u0000`) && (k.endsWith('\\u0000shape') || k.includes('\\u0000effect:'))).flatMap(([, v]) => v);\n\t\tif (shapeSegments.length) {\n\t\t\tif (node.type !== 'path') notes.push(`\"${id}\" is a group: its morph or effect animation is not exported (Flair tweens one path's \"d\").`);\n\t\t\telse {\n\t\t\t\tconst inverse = invertMatrix(nodeMatrix(node));\n\t\t\t\tchannels.push({\n\t\t\t\t\tid,\n\t\t\t\t\tkind: 'attr',\n\t\t\t\t\tattr: 'd',\n\t\t\t\t\tsegments: shapeSegments,\n\t\t\t\t\texact: () => false,\n\t\t\t\t\tvalue: (t) => {\n\t\t\t\t\t\tconst frame = motionFrameAt(scene, t, { draw: false, offsets: false });\n\t\t\t\t\t\tconst now = expandVectorAppearance(indexMotionNodes(frame.document.nodes).get(id)?.node as VectorNode);\n\t\t\t\t\t\tif (!now || now.type !== 'path') return '';\n\t\t\t\t\t\tconst bezier = transformBezierPath(vectorPathWorldBezier(now, IDENTITY_MATRIX, { effects: false }), inverse);\n\t\t\t\t\t\treturn bezierPathToSvg(bezier, { precision: Math.min(precision, 2) });\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tconst camera = track('', 'camera');\n\tif (camera.length) channels.push({ id: '', kind: 'view', segments: [...camera], exact: () => true, overshoot: true, value: (t) => (trackValue(camera, t) as number[]).map(round) });\n\n\tconst animate: FlairSvgAnimation[] = [];\n\tlet sampled = 0;\n\tconst same = (a: ChannelValue, b: ChannelValue) => JSON.stringify(a) === JSON.stringify(b);\n\tconst emit = (channel: Channel, delay: number, ms: number, from: ChannelValue, to: ChannelValue, ease: FlairEase, segment?: MotionSegment) => {\n\t\tconst written = writeEase(ease);\n\t\tconst base = {\n\t\t\t...(channel.id ? { id: channel.id } : {}),\n\t\t\t...(delay > 0 ? { delay: round(delay) } : {}),\n\t\t\tms: round(ms),\n\t\t\tease: written,\n\t\t\t...(segment?.behavior ? { behavior: segment.behavior } : {}),\n\t\t\t...(segment?.steps ? { strobe: segment.steps } : {})\n\t\t};\n\t\tif (channel.kind === 'view') animate.push({ ...base, view: to as unknown as [number, number, number, number] });\n\t\telse if (channel.kind === 'draw') animate.push({ ...base, draw: [from as number, to as number] });\n\t\telse if (channel.kind === 'attrs') {\n\t\t\t// Only the numbers that change (as Flair's clip reveals write them).\n\t\t\tconst [a, b] = [from as readonly number[], to as readonly number[]];\n\t\t\tconst attrs = Object.fromEntries(channel.attrs!.flatMap((name, k) => (a[k] !== b[k] ? [[name, [a[k], b[k]] as const]] : [])));\n\t\t\tanimate.push({ ...base, attrs });\n\t\t}\n\t\telse animate.push({ ...base, attrs: { [channel.attr!]: [from as string | number, to as string | number] } });\n\t};\n\n\tfor (const channel of channels) {\n\t\tconst cuts = channel.segments.filter((s) => s.end <= s.start);\n\t\tfor (const cut of cuts) {\n\t\t\tconst [from, to] = [channel.value(Math.max(0, cut.start - 1e-3)), channel.value(cut.start)];\n\t\t\t// A cut to where the value already is changes nothing (at 0 it sets the start, so it stays).\n\t\t\tif (cut.start <= 0 || !same(from, to) || channel.kind === 'view') emit(channel, cut.start, 0, from, to, 'linear');\n\t\t}\n\t\tconst times = [...new Set(channel.segments.flatMap((s) => [s.start, s.end]))].sort((a, b) => a - b);\n\t\tfor (let i = 0; i + 1 < times.length; i++) {\n\t\t\tconst a = times[i];\n\t\t\tconst b = times[i + 1];\n\t\t\tconst active = channel.segments.filter((s) => s.start < b && s.end > a);\n\t\t\tif (!active.length) continue;\n\t\t\t// One change when every active segment spans exactly this interval with one exact curve (a move's x and y, say).\n\t\t\tconst first = active[0];\n\t\t\t// A behaviour (pulse, shake, wriggle…) is one change toward the value it swings round, when every active segment shares it.\n\t\t\tconst key = (x: MotionSegment) => JSON.stringify([x.ease, x.behavior, x.reverse ?? false, x.steps ?? 0]);\n\t\t\tconst together = active.every((x) => x.start === a && x.end === b && channel.exact(x) && key(x) === key(first));\n\t\t\tconst curve = together ? easeOf(first) : undefined;\n\t\t\tconst ease = curve && (!overshoots(curve) || channel.overshoot) ? curve : undefined;\n\t\t\tif (ease) {\n\t\t\t\tconst from = channel.value(a);\n\t\t\t\tconst to = first.behavior ? (channel.raw ?? channel.value)(b) : channel.value(b);\n\t\t\t\tif (!same(from, to) || channel.kind === 'view') emit(channel, a, b - a, from, to, ease, first);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst n = Math.max(1, Math.ceil(((b - a) * fps) / 1000));\n\t\t\tlet prev = channel.value(a);\n\t\t\tfor (let k = 1; k <= n; k++) {\n\t\t\t\tconst t0 = a + ((b - a) * (k - 1)) / n;\n\t\t\t\tconst t1 = a + ((b - a) * k) / n;\n\t\t\t\tconst next = channel.value(t1);\n\t\t\t\tif (!same(prev, next)) {\n\t\t\t\t\temit(channel, t0, t1 - t0, prev, next, 'linear');\n\t\t\t\t\tsampled++;\n\t\t\t\t}\n\t\t\t\tprev = next;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Follows: one `along` per follow, sampled into linear steps only for curves Flair cannot play.\n\tfor (const follow of follows) {\n\t\tconst starts = follow.segments.map((seg) => seg.start);\n\t\tfor (const seg of follow.segments) {\n\t\t\tconst along = { id: follow.wrapper, along: follow.routes.get(seg.path!)!, ...(seg.rotate ? { orient: true } : {}) };\n\t\t\tconst progress = (t: number) => round(Math.min(1, Math.max(0, Number(segmentValue(seg, t)))));\n\t\t\tconst curve = seg.end > seg.start ? (plays(seg) ? easeOf(seg) : undefined) : 'linear';\n\t\t\t// Past the ends, Flair stops turning (its direction is measured either side of the point), so overshoots are sampled.\n\t\t\tif (curve && !(overshoots(curve) && seg.rotate)) {\n\t\t\t\tconst ends = seg.reverse ? [Number(seg.to), Number(seg.from)] : [Number(seg.from), Number(seg.to)];\n\t\t\t\tanimate.push({ ...along, ...(seg.start > 0 ? { delay: round(seg.start) } : {}), ms: round(seg.end - seg.start), ease: writeEase(curve), ...(seg.steps ? { strobe: seg.steps } : {}), at: [round(ends[0]), round(ends[1])] });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Sampled up to the next follow's start, which takes over there.\n\t\t\tconst until = Math.min(seg.end, ...starts.filter((t) => t > seg.start));\n\t\t\tconst n = Math.max(1, Math.ceil(((until - seg.start) * fps) / 1000));\n\t\t\tfor (let k = 1; k <= n; k++) {\n\t\t\t\tconst t0 = seg.start + ((until - seg.start) * (k - 1)) / n;\n\t\t\t\tconst t1 = seg.start + ((until - seg.start) * k) / n;\n\t\t\t\tanimate.push({ ...along, ...(t0 > 0 ? { delay: round(t0) } : {}), ms: round(t1 - t0), ease: 'linear', at: [progress(t0), progress(t1)] });\n\t\t\t\tsampled++;\n\t\t\t}\n\t\t}\n\t}\n\tanimate.sort((x, y) => (x.delay ?? 0) - (y.delay ?? 0));\n\tconst lastChange = animate.reduce((m, a) => Math.max(m, (a.delay ?? 0) + (a.ms ?? 0)), 0);\n\n\t// A click trigger plays shot by shot. Flair's player shows step 0 until the first click and then\n\t// plays it with step 1, so shot n goes on step n + 1: each click plays one shot, from the start.\n\tconst trigger = options.trigger === null ? undefined : (options.trigger ?? scene.trigger);\n\tif (trigger === 'click' && timeline.shots.length) {\n\t\tfor (const a of animate) {\n\t\t\tconst at = a.delay ?? 0;\n\t\t\tlet step = 0;\n\t\t\ttimeline.shots.forEach((shot, i) => {\n\t\t\t\tif (shot.start <= at + 1e-6) step = i;\n\t\t\t});\n\t\t\tconst delay = round(at - timeline.shots[step].start);\n\t\t\tdelete a.delay;\n\t\t\tif (delay > 0) a.delay = delay;\n\t\t\ta.step = step + 1;\n\t\t}\n\t\tanimate.sort((x, y) => (x.step ?? 0) - (y.step ?? 0) || (x.delay ?? 0) - (y.delay ?? 0));\n\t}\n\tif (trigger && (scene.loop ?? 'none') !== 'none') notes.push(`The scene plays on ${trigger}, so its loop does not apply in Flair.`);\n\n\t// The SVG: the artwork at rest, live effects drawn as plain paths so shapes can be tweened,\n\t// with the wrappers that reveals and follows animate, and the routes follows take.\n\tlet svg = vectorDocumentToSvg({ ...scene.artwork, nodes: expandVectorAppearances(scene.artwork.nodes) }, { pretty: false, precision, wrap });\n\tif (routes.length) svg = svg.replace(/^(<svg[^>]*>)/, `$1<defs>${routes.join('')}</defs>`);\n\n\t// Controls: each stands for its default colour wherever it appears.\n\tlet motion: FlairSvgMotion = { svg, animate };\n\tif (scene.controls?.length) {\n\t\tconst declarations = scene.controls.map((c) => `{{${c.name}: color default=${c.default.toUpperCase()}${c.label ? ` label='${c.label.replace(/'/g, '’')}'` : ''}}}`).join(' ');\n\t\tconst swap = (text: string) => scene.controls!.reduce((s, c) => s.replace(new RegExp(`${c.default}(?![0-9a-fA-F])`, 'gi'), `{{${c.name}}}`), text);\n\t\tsvg = svg.replace(/^(<svg[^>]*>)/, `$1<!-- ${declarations} -->`);\n\t\tconst header = svg.indexOf('-->') + 3;\n\t\tsvg = svg.slice(0, header) + swap(svg.slice(header));\n\t\tmotion = { svg, animate: animate.map((a) => (a.attrs ? { ...a, attrs: Object.fromEntries(Object.entries(a.attrs).map(([k, [x, y]]) => [k, [typeof x === 'string' ? swap(x) : x, typeof y === 'string' ? swap(y) : y] as const])) } : a)) };\n\t}\n\treturn { motion, duration: timeline.duration, hold: Math.max(0, round(timeline.duration - lastChange)), sampled, notes: [...new Set(notes)], ...(trigger ? { trigger } : {}) };\n}\n\nexport interface FlairEffectOptions extends FlairExportOptions {\n\t/** Kebab-case id (default: the scene's name). */\n\tid?: string;\n\tname?: string;\n\tdescription?: string;\n\t/** Flair catalog category (default `icon`). */\n\tcategory?: string;\n\ttags?: string[];\n}\n\nconst kebab = (text: string) =>\n\ttext\n\t\t.trim()\n\t\t.replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n\t\t.replace(/[^A-Za-z0-9]+/g, '-')\n\t\t.replace(/^-+|-+$/g, '')\n\t\t.toLowerCase() || 'animation';\n\n/** A scene as a Flair catalog vector effect, with its colour controls and presets. */\nexport function toFlairVectorEffect(scene: MotionScene, options: FlairEffectOptions = {}): FlairVectorEffect {\n\tconst out = toFlairSvgMotion(scene, options);\n\treturn {\n\t\tkind: 'vector',\n\t\tid: options.id ?? kebab(scene.name),\n\t\tname: options.name ?? scene.name,\n\t\tdescription: options.description ?? scene.description ?? '',\n\t\tcategory: options.category ?? 'icon',\n\t\ttags: options.tags ?? [],\n\t\tmotion: out.motion,\n\t\thold: out.hold,\n\t\t...(scene.presets?.length ? { presets: scene.presets } : {}),\n\t\t...(out.trigger ? { trigger: out.trigger } : {})\n\t};\n}\n\n/** A scene as a document for Flair's `EffectEditor` (`replaceDocument`). */\nexport function toFlairEffectDocument(scene: MotionScene, options: FlairExportOptions = {}): FlairEffectDocument {\n\tconst out = toFlairSvgMotion(scene, options);\n\treturn {\n\t\tversion: 1,\n\t\tname: scene.name,\n\t\teffect: { kind: 'vector', motion: out.motion, hold: out.hold },\n\t\tvalues: Object.fromEntries((scene.controls ?? []).map((c) => [c.name, c.default])),\n\t\ttracks: {},\n\t\tduration: out.duration,\n\t\t// Flair's editor documents have no trigger: a click scene keeps its steps, and plays through there.\n\t\tloop: !out.trigger && (scene.loop ?? 'none') !== 'none',\n\t\tpresets: scene.presets ?? []\n\t};\n}\n","import type { MotionBehavior } from '../animation/behavior.js';\nimport type { AnimationEasing } from '../animation/easing.js';\nimport { applyMatrix, invertMatrix, multiplyMatrices, nodeMatrix, type AffineMatrix } from '../vector/geometry.js';\nimport { parseSvgTransform, parseVectorSvg } from '../vector/svg.js';\nimport { checkMotionScene } from './check.js';\nimport { indexMotionNodes, MOTION_EASE_IN_OUT, MOTION_EASE_OUT, type MotionNodeEntry } from './compile.js';\nimport type { FlairEase, FlairSvgAnimation, FlairSvgMotion, FlairVectorEffect } from './flair.js';\nimport type { MotionIssue } from './issues.js';\nimport { motionSceneShapeProblems } from './parse.js';\nimport type { MotionCamera, MotionCommand, MotionControl, MotionScene, MotionShot } from './types.js';\n\n/**\n * Import from Flair: a Flair `SvgMotion` (or a catalog `VectorEffect`) becomes a scene, so an\n * effect made in Flair, or taken from its catalog, can be opened and edited here. The reverse\n * of `toFlairSvgMotion`, as far as the scene model goes:\n *\n * - The SVG becomes the artwork (`parseVectorSvg`); `{{name: color …}}` placeholders become\n * colour controls (other placeholders take their defaults).\n * - Each Flair step becomes a shot, its changes commands timed by their `delay`, all together.\n * - Opacity, paint, stroke width, transforms (as move, rotate and scale), drawing on, following\n * a path, camera views and behaviours (pulse, shake, teeter, wave, wiggle, colour pulse) carry\n * over. Counting, writing text, solo containers and anything else are listed in `notes`.\n */\n\nexport interface FlairImportResult {\n\tscene: MotionScene;\n\t/** What could not be carried over exactly, in sentences. */\n\tnotes: string[];\n\t/** `checkMotionScene` of the result. */\n\tissues: MotionIssue[];\n}\n\nexport interface FlairImportOptions {\n\t/** The scene's name (default: the effect's, else `from-flair`). */\n\tname?: string;\n\t/** Hold after the last shot, ms (default: the effect's `hold`, else 600). */\n\thold?: number;\n\t/**\n\t * The motion plays on click: Flair plays step 0 together with step 1 on the first click, so\n\t * both become the first shot (as `toFlairSvgMotion` writes them).\n\t */\n\tclickSteps?: boolean;\n}\n\n/** A `{{name}}` placeholder or `{{name: type attributes}}` declaration, as Flair writes them. */\nconst PLACEHOLDER = /\\{\\{\\s*([A-Za-z_]\\w*)\\s*(?::\\s*([A-Za-z0-9]*)([^}]*))?\\}\\}/g;\n\nfunction attributeOf(attrs: string, name: string): string | undefined {\n\tconst m = new RegExp(`(?:^|\\\\s)${name}=(?:'([^']*)'|(\\\\S+))`).exec(attrs);\n\treturn m ? (m[1] ?? m[2]) : undefined;\n}\n\n/** Placeholders replaced by their defaults; colour declarations become controls. */\nfunction resolvePlaceholders(motion: FlairSvgMotion, notes: string[]): { motion: FlairSvgMotion; controls: MotionControl[] } {\n\tconst text = JSON.stringify(motion);\n\tconst declared = new Map<string, { type: string; value: string; label?: string }>();\n\tfor (const m of text.matchAll(PLACEHOLDER)) {\n\t\tif (!m[2] || declared.has(m[1])) continue;\n\t\tconst attrs = m[3] ?? '';\n\t\tconst value = attributeOf(attrs, 'default');\n\t\tconst fallback = m[2] === 'color' ? '#000000' : '0';\n\t\tdeclared.set(m[1], { type: m[2], value: m[2] === 'color' ? (value ?? fallback).toLowerCase() : (value ?? fallback), ...(attributeOf(attrs, 'label') ? { label: attributeOf(attrs, 'label') } : {}) });\n\t}\n\tconst controls: MotionControl[] = [];\n\tfor (const [name, d] of declared) {\n\t\tif (d.type === 'color' && /^#[0-9a-fA-F]{6}$/.test(d.value)) controls.push({ name, type: 'color', default: d.value.toLowerCase(), ...(d.label ? { label: d.label } : {}) });\n\t\telse notes.push(`Control \"${name}\" (${d.type}) is fixed at its default ${d.value}: scenes take colour controls only.`);\n\t}\n\tconst unknown = new Set<string>();\n\tconst filled = text.replace(PLACEHOLDER, (_, name: string) => {\n\t\tconst d = declared.get(name);\n\t\tif (!d) unknown.add(name);\n\t\treturn (d?.value ?? '').replace(/\"/g, '\\\\\"');\n\t});\n\tfor (const name of unknown) notes.push(`Placeholder \"{{${name}}}\" has no declaration, so it was left empty.`);\n\t// SVG comments (where Flair declares controls) are dropped with the markup's comments.\n\treturn { motion: JSON.parse(filled) as FlairSvgMotion, controls };\n}\n\n/** A Flair ease as an editor easing. Flair's `in-out` is a cubic polynomial, close to the editor's ease-in-out curve. */\nfunction easingOf(ease: FlairEase | undefined, fallback: AnimationEasing): AnimationEasing {\n\tif (ease === undefined) return fallback;\n\tif (ease === 'linear') return 'linear';\n\tif (ease === 'out') return MOTION_EASE_OUT;\n\tif (ease === 'in-out') return MOTION_EASE_IN_OUT;\n\tif (Array.isArray(ease)) return { type: 'cubic-bezier', x1: ease[0], y1: ease[1], x2: ease[2], y2: ease[3] };\n\tif (typeof ease === 'object' && 'spring' in ease) return { type: 'spring', ...ease.spring };\n\treturn fallback;\n}\n\ninterface Pose {\n\tdx: number;\n\tdy: number;\n\trotation: number;\n\tsx: number;\n\tsy: number;\n}\n\n/** A Flair transform value as the editor's offset from the node's rest (move, turn and scale about its centre), or null when it skews. */\nfunction poseOf(value: string | number, entry: MotionNodeEntry): Pose | null {\n\tconst t = parseSvgTransform(String(value));\n\tconst o: AffineMatrix = multiplyMatrices(invertMatrix(nodeMatrix(entry.node)) ?? [1, 0, 0, 1, 0, 0], t);\n\tconst sx = Math.hypot(o[0], o[1]);\n\tif (!(sx > 1e-9)) return null;\n\tconst sy = (o[0] * o[3] - o[1] * o[2]) / sx;\n\t// No skew: the second column is the first turned a quarter, times sy.\n\tif (Math.abs(o[2] + (o[1] / sx) * sy) > 1e-6 || Math.abs(o[3] - (o[0] / sx) * sy) > 1e-6) return null;\n\tconst c = entry.center;\n\tconst moved = applyMatrix(o, c);\n\treturn { dx: moved.x - c.x, dy: moved.y - c.y, rotation: (Math.atan2(o[1], o[0]) * 180) / Math.PI, sx, sy };\n}\n\nconst near = (a: number, b: number, eps = 1e-6) => Math.abs(a - b) < eps;\nconst r3 = (n: number) => Math.round(n * 1000) / 1000;\n\n/** One Flair change as commands (all starting together), or a note on why it is skipped. */\nfunction commandsFor(anim: FlairSvgAnimation, nodes: Map<string, MotionNodeEntry>, entered: Set<string>, notes: string[]): MotionCommand[] {\n\tconst id = anim.id!;\n\tconst entry = nodes.get(id);\n\tconst where = `\"${id}\"`;\n\tif (!entry) {\n\t\tnotes.push(`A change to ${where} was skipped: the artwork has no element with that id.`);\n\t\treturn [];\n\t}\n\tconst targets = [id];\n\tconst duration = anim.ms ?? 800;\n\tconst timing = {\n\t\tduration,\n\t\t...(anim.strobe ? { steps: anim.strobe } : {}),\n\t\t...(anim.repeat && anim.repeat > 1 ? { repeat: anim.repeat, ...(anim.alternate ? { repeatMode: 'mirror' as const } : {}) } : {})\n\t};\n\tconst ease = (fallback: AnimationEasing) => ({ ease: easingOf(anim.ease, fallback) });\n\tconst out: MotionCommand[] = [];\n\tconst behavior: MotionBehavior | undefined = anim.behavior;\n\tconst unsupported = (['count', 'write', 'scramble', 'solo'] as const).filter((k) => (anim as Record<string, unknown>)[k] !== undefined);\n\tif (unsupported.length) notes.push(`${where}: ${unsupported.join(', ')} ${unsupported.length > 1 ? 'are' : 'is'} not part of scenes and was skipped.`);\n\n\tif (anim.draw !== undefined && anim.draw !== false) {\n\t\tconst [from, to] = anim.draw === true ? [0, 1] : anim.draw;\n\t\tout.push({ type: 'draw', targets, from, to, ...timing, ...ease(MOTION_EASE_IN_OUT) });\n\t}\n\tif (anim.along) {\n\t\tconst path = nodes.get(anim.along);\n\t\tif (!path || path.node.type !== 'path') notes.push(`${where} follows \"${anim.along}\", which is not a path in the artwork; the follow was skipped.`);\n\t\telse out.push({ type: 'follow', targets, path: anim.along, from: anim.at?.[0] ?? 0, to: anim.at?.[1] ?? 1, ...(anim.orient ? { rotate: true } : {}), ...timing, ...ease(MOTION_EASE_IN_OUT) });\n\t}\n\tfor (const [attr, [a, b]] of Object.entries(anim.attrs ?? {})) {\n\t\tif (attr === 'opacity') {\n\t\t\tconst [from, to] = [Number(a), Number(b)];\n\t\t\tif (behavior) notes.push(`${where}: an opacity ${behavior.type} became a plain fade.`);\n\t\t\tif (from === 0 && to > 0 && !entered.has(id)) {\n\t\t\t\tentered.add(id);\n\t\t\t\tout.push({ type: 'enter', targets, style: 'fade', ...timing, ...ease(MOTION_EASE_OUT) });\n\t\t\t} else out.push({ type: 'fade', targets, to: Math.min(1, Math.max(0, to)), ...timing, ...ease(MOTION_EASE_IN_OUT) });\n\t\t} else if (attr === 'fill' || attr === 'stroke') {\n\t\t\tif (behavior?.type === 'pulse') out.push({ type: 'color-pulse', targets, color: String(b), paint: attr, count: behavior.count ?? 1, ...timing, ...ease('linear') });\n\t\t\telse {\n\t\t\t\tif (behavior) notes.push(`${where}: a ${attr} ${behavior.type} became a plain colour change.`);\n\t\t\t\tout.push({ type: 'style', targets, [attr]: String(b), ...timing, ...ease(MOTION_EASE_IN_OUT) } as MotionCommand);\n\t\t\t}\n\t\t} else if (attr === 'stroke-width') {\n\t\t\tout.push({ type: 'style', targets, strokeWidth: Number(b), ...timing, ...ease(MOTION_EASE_IN_OUT) });\n\t\t} else if (attr === 'transform') {\n\t\t\tconst p0 = poseOf(a, entry);\n\t\t\tconst p1 = poseOf(b, entry);\n\t\t\tif (!p0 || !p1) {\n\t\t\t\tnotes.push(`${where}: a transform that skews was skipped (scenes move, turn and scale).`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst d = { x: r3(p1.dx - p0.dx), y: r3(p1.dy - p0.dy), r: r3(p1.rotation - p0.rotation), sx: p1.sx / p0.sx, sy: p1.sy / p0.sy };\n\t\t\tif (behavior) {\n\t\t\t\tconst linear = ease('linear');\n\t\t\t\tconst moves = d.x !== 0 || d.y !== 0;\n\t\t\t\tconst turns = d.r !== 0;\n\t\t\t\tconst scales = !near(d.sx, 1) || !near(d.sy, 1);\n\t\t\t\tif (behavior.type === 'pulse' && scales && !moves && !turns) out.push({ type: 'pulse', targets, amount: r3(d.sx - 1), count: behavior.count ?? 1, ...timing, ...linear });\n\t\t\t\telse if (behavior.type === 'oscillate' && (behavior.decay ?? 0) > 0 && turns && !moves && !scales) out.push({ type: 'teeter', targets, angle: d.r, count: behavior.count ?? 1, ...timing, ...linear });\n\t\t\t\telse if (behavior.type === 'oscillate' && (behavior.decay ?? 0) > 0 && moves && !turns && !scales && (d.x === 0 || d.y === 0))\n\t\t\t\t\tout.push({ type: 'shake', targets, amount: d.x || d.y, count: behavior.count ?? 1, ...(d.x === 0 ? { axis: 'vertical' as const } : {}), ...timing, ...linear });\n\t\t\t\telse if (behavior.type === 'oscillate' && !behavior.decay && d.x === 0 && d.y !== 0 && !turns && !scales) out.push({ type: 'wave', targets, amount: -d.y, count: behavior.count ?? 1, ...timing, ...linear });\n\t\t\t\telse if (behavior.type === 'wriggle' && !scales)\n\t\t\t\t\tout.push({ type: 'wiggle', targets, amount: Math.max(Math.abs(d.x), Math.abs(d.y)), ...(turns ? { rotate: Math.abs(d.r) } : {}), frequency: behavior.frequency ?? 2, octaves: behavior.octaves ?? 2, seed: behavior.seed ?? 42, ...timing, ...linear });\n\t\t\t\telse notes.push(`${where}: a transform ${behavior.type} that is not a pulse, shake, teeter, wave or wiggle was skipped.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst e = ease(MOTION_EASE_IN_OUT);\n\t\t\tif (d.x !== 0 || d.y !== 0) out.push({ type: 'move', targets, by: { x: d.x, y: d.y }, ...timing, ...e });\n\t\t\tif (d.r !== 0) out.push({ type: 'rotate', targets, to: r3(p1.rotation), ...timing, ...e });\n\t\t\tif (!near(d.sx, 1) || !near(d.sy, 1)) out.push({ type: 'scale', targets, to: near(p1.sx, p1.sy) ? r3(p1.sx) : { x: r3(p1.sx), y: r3(p1.sy) }, ...timing, ...e });\n\t\t} else notes.push(`${where}: changing \"${attr}\" is not part of scenes and was skipped.`);\n\t}\n\treturn out;\n}\n\n/** A Flair `SvgMotion` as a scene (see the module notes for what carries over). */\nexport function fromFlairSvgMotion(input: FlairSvgMotion, options: FlairImportOptions = {}): FlairImportResult {\n\tconst notes: string[] = [];\n\tif (!input || typeof input.svg !== 'string') throw new Error('Give a Flair SvgMotion: { svg: \"<svg …>\", animate: [ … ] }.');\n\tconst { motion, controls } = resolvePlaceholders(input, notes);\n\tconst artwork = parseVectorSvg(motion.svg);\n\tconst nodes = indexMotionNodes(artwork.nodes);\n\tconst byStep = new Map<number, FlairSvgAnimation[]>();\n\tfor (const anim of motion.animate ?? []) {\n\t\tconst raw = Math.max(0, Math.floor(anim.step ?? 0));\n\t\tconst step = options.clickSteps ? Math.max(1, raw) : raw;\n\t\tif (!byStep.has(step)) byStep.set(step, []);\n\t\tbyStep.get(step)!.push(anim);\n\t}\n\tconst steps = [...byStep.keys()].sort((a, b) => a - b);\n\tif (steps.length > 1) notes.push('Each Flair step became a shot played after the one before (Flair steps wait for clicks or set times).');\n\tconst entered = new Set<string>();\n\tconst shots: MotionShot[] = steps.map((step, index) => {\n\t\tconst anims = [...byStep.get(step)!].sort((a, b) => (a.delay ?? 0) - (b.delay ?? 0));\n\t\tlet camera: MotionCamera | undefined;\n\t\tlet cameraMs = 0;\n\t\tconst run: MotionCommand[] = [];\n\t\tlet last = 0;\n\t\tfor (const anim of anims) {\n\t\t\tif (anim.view !== undefined) {\n\t\t\t\tif (camera || (anim.delay ?? 0) > 0) {\n\t\t\t\t\tnotes.push(`Step ${step}: a camera move ${camera ? 'after the first' : `${anim.delay} ms in`} was dropped; a shot frames the camera once, at its start.`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst ms = anim.ms ?? 800;\n\t\t\t\tconst ease = easingOf(anim.ease, MOTION_EASE_IN_OUT);\n\t\t\t\tcamera = typeof anim.view === 'string' ? { frame: anim.view, padding: 0, ms, ease } : { x: anim.view[0], y: anim.view[1], width: anim.view[2], height: anim.view[3], ms, ease };\n\t\t\t\tcameraMs = index === 0 ? 0 : ms;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!anim.id) continue;\n\t\t\t// A shot's commands start after its camera move: earlier changes are pushed back to it.\n\t\t\tconst at = Math.max(0, (anim.delay ?? 0) - cameraMs);\n\t\t\tif (cameraMs && (anim.delay ?? 0) < cameraMs) notes.push(`Step ${step}: a change to \"${anim.id}\" during the camera move now starts after it.`);\n\t\t\tfor (const command of commandsFor(anim, nodes, entered, notes)) {\n\t\t\t\tconst first = run.length === 0;\n\t\t\t\trun.push({ ...command, ...(first ? {} : { with: 'previous' as const }), ...(at - last > 0 || first ? { delay: first ? at : at - last } : {}) } as MotionCommand);\n\t\t\t\tif (first && at === 0) delete (run[run.length - 1] as { delay?: number }).delay;\n\t\t\t\tlast = at;\n\t\t\t}\n\t\t}\n\t\treturn { id: `step-${step}`, ...(camera ? { camera } : {}), run, ...(index === steps.length - 1 ? { hold: options.hold ?? 600 } : {}) };\n\t});\n\tconst scene: MotionScene = { version: 1, name: options.name ?? 'from-flair', artwork, shots, ...(controls.length ? { controls } : {}) };\n\tconst problems = motionSceneShapeProblems(scene);\n\tif (problems.length) throw new Error(`The imported scene is not well formed:\\n${problems.join('\\n')}`);\n\treturn { scene, notes: [...new Set(notes)], issues: checkMotionScene(scene) };\n}\n\n/** A preset colour as `#rrggbb`: Flair writes them as hex strings or as `[r, g, b]` arrays of 0–1 channels (as its `rgbToHex` reads them). */\nfunction presetColor(value: unknown): string | undefined {\n\tif (typeof value === 'string') return /^#[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : value;\n\tif (Array.isArray(value) && value.length >= 3 && value.slice(0, 3).every((n) => typeof n === 'number' && Number.isFinite(n)))\n\t\treturn `#${value\n\t\t\t.slice(0, 3)\n\t\t\t.map((n: number) => Math.round(Math.min(1, Math.max(0, n)) * 255).toString(16).padStart(2, '0'))\n\t\t\t.join('')}`;\n\treturn undefined;\n}\n\n/** A Flair catalog `VectorEffect` as a scene: its motion, name, description, colour controls and presets. */\nexport function fromFlairVectorEffect(effect: FlairVectorEffect, options: FlairImportOptions = {}): FlairImportResult {\n\tif (!effect || effect.kind !== 'vector' || !effect.motion) throw new Error('Give a Flair vector effect: { kind: \"vector\", id, name, motion: { svg, animate } }.');\n\tconst result = fromFlairSvgMotion(effect.motion, { name: options.name ?? effect.id ?? effect.name, hold: options.hold ?? effect.hold, ...(effect.trigger === 'click' ? { clickSteps: true } : {}) });\n\tconst names = new Set((result.scene.controls ?? []).map((c) => c.name));\n\tconst presets = (effect.presets ?? [])\n\t\t.map((p) => ({ name: p.name, values: Object.fromEntries(Object.entries(p.values).flatMap(([k, v]) => (names.has(k) && presetColor(v) ? [[k, presetColor(v)!]] : []))) }))\n\t\t.filter((p) => Object.keys(p.values).length);\n\t// Flair's steps became shots, so a click trigger plays them shot by shot again on export.\n\tconst scene: MotionScene = { ...result.scene, ...(effect.description ? { description: effect.description } : {}), ...(presets.length ? { presets } : {}), ...(effect.trigger ? { trigger: effect.trigger } : {}) };\n\tconst notes = [...result.notes];\n\treturn { scene, notes, issues: checkMotionScene(scene) };\n}\n","// Export mapping adapted from effectcraft-main/crates/lottie/src/{anim,shapes,export}.rs (MIT OR Apache-2.0, © ArtCraft Team and contributors).\nimport { resolveEasing, reverseCubicBezier } from '../animation/easing.js';\nimport { toBezierPath, type BezierPath } from '../canvas/pathops/bezier.js';\nimport { normalizeTokenColor } from '../tokens/color.js';\nimport { expandVectorAppearances } from '../vector/appearance.js';\nimport { IDENTITY_MATRIX, nodeMatrix, vectorPathWorldBezier, type AffineMatrix } from '../vector/geometry.js';\nimport type { VectorNode, VectorPaint, VectorPathNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionTrackKey, trackValue, type MotionNodeEntry, type MotionProperty, type MotionSegment } from './compile.js';\nimport { motionFrameAt, motionNodeOffset } from './evaluate.js';\nimport type { MotionScene } from './types.js';\n\n/**\n * Export to Lottie (Bodymovin JSON, v5): the scene as one shape layer whose groups mirror the\n * artwork. Lottie players (lottie-web, rlottie, the iOS and Android libraries) then play it.\n *\n * - Each node is an outer group carrying its animated pose (anchor at its centre, position,\n * scale, rotation, opacity) around an inner group carrying its own transform. Paths keep their\n * own transform in their points.\n * - Paths become `sh` shapes with solid fills (`fl`) and strokes (`st`). Drawing on becomes trim\n * paths (`tm`), and colours, stroke width and fill opacity animate on the fill and stroke.\n * - The camera becomes the transform of a root group.\n * - A change is written as keyframes with Lottie's bezier easing when a cubic-bezier ease (run\n * backwards for a mirrored repeat) is all that drives that property over that stretch.\n * Everything else is sampled at `fps` into linear keyframes: springs, elastic, behaviours,\n * stepped time, geometric zooms, additive layers, follows and camera moves.\n *\n * Gradients, dashes, reveal clips and skews of groups are not carried over; `notes` says so.\n */\n\n/** A Lottie property: static (`a: 0`) or keyframed (`a: 1`). */\nexport type LottieValue = { a: 0; k: number | number[] } | { a: 1; k: LottieKeyframe[] };\n\nexport interface LottieKeyframe {\n\t/** Frame. */\n\tt: number;\n\t/** Value from this key on. */\n\ts: number[];\n\t/** Out tangent of the ease to the next key (`x1`, `y1`). */\n\to?: { x: number[]; y: number[] };\n\t/** In tangent of the ease to the next key (`x2`, `y2`). */\n\ti?: { x: number[]; y: number[] };\n\t/** Hold until the next key. */\n\th?: 1;\n}\n\n/** A Lottie shape item (group, path, fill, stroke, trim, transform): plain JSON. */\nexport type LottieShape = { ty: string; nm?: string; [key: string]: unknown };\n\n/** A Lottie animation: plain Bodymovin JSON. */\nexport interface LottieAnimation {\n\tv: string;\n\tfr: number;\n\tip: number;\n\top: number;\n\tw: number;\n\th: number;\n\tnm: string;\n\tddd: 0;\n\tassets: [];\n\tlayers: Record<string, unknown>[];\n\t/** One marker per shot (`cm` its label, else its id). */\n\tmarkers: { tm: number; cm: string; dr: number }[];\n}\n\nexport interface LottieExportOptions {\n\t/** Frame rate and sampling rate (default: the scene's `fps`, else 30). */\n\tfps?: number;\n\t/** Decimal places (default 3). */\n\tprecision?: number;\n}\n\nexport interface LottieExport {\n\tlottie: LottieAnimation;\n\t/** Keyframes that sample changes Lottie cannot ease the same way. */\n\tsampled: number;\n\t/** What could not be carried over, in sentences. */\n\tnotes: string[];\n}\n\ntype Vec = number[];\ntype Bezier4 = [number, number, number, number];\n\nconst STATIC_TR = (): LottieShape => ({\n\tty: 'tr',\n\tp: { a: 0, k: [0, 0] },\n\ta: { a: 0, k: [0, 0] },\n\ts: { a: 0, k: [100, 100] },\n\tr: { a: 0, k: 0 },\n\to: { a: 0, k: 100 },\n\tsk: { a: 0, k: 0 },\n\tsa: { a: 0, k: 0 }\n});\n\n/** `#rrggbb` (or anything `normalizeTokenColor` reads) as Lottie's 0–1 RGBA. */\nfunction rgba(color: unknown): Vec | null {\n\tconst hex = typeof color === 'string' ? normalizeTokenColor(color) : null;\n\tif (!hex) return null;\n\tconst n = (i: number) => parseInt(hex.slice(i, i + 2), 16) / 255;\n\treturn [n(1), n(3), n(5), hex.length >= 9 ? parseInt(hex.slice(7, 9), 16) / 255 : 1];\n}\n\n/** A path as Lottie shape data per contour: vertices with in / out tangents relative to them. */\nfunction lottieContours(path: BezierPath, round: (n: number) => number): { c: boolean; v: Vec[]; i: Vec[]; o: Vec[] }[] {\n\tconst out: { c: boolean; v: Vec[]; i: Vec[]; o: Vec[] }[] = [];\n\tlet cur: { c: boolean; v: Vec[]; i: Vec[]; o: Vec[] } | null = null;\n\tlet px = 0;\n\tlet py = 0;\n\tconst add = (x: number, y: number, inX: number, inY: number) => {\n\t\tcur!.v.push([x, y]);\n\t\tcur!.i.push([inX - x, inY - y]);\n\t\tcur!.o.push([0, 0]);\n\t\tpx = x;\n\t\tpy = y;\n\t};\n\tfor (const cmd of path) {\n\t\tif (cmd.type === 'M') {\n\t\t\tif (cur) out.push(cur);\n\t\t\tcur = { c: false, v: [], i: [], o: [] };\n\t\t\tadd(cmd.x, cmd.y, cmd.x, cmd.y);\n\t\t} else if (!cur) continue;\n\t\telse if (cmd.type === 'L') add(cmd.x, cmd.y, cmd.x, cmd.y);\n\t\telse if (cmd.type === 'Q') {\n\t\t\tconst c1 = [px + (2 / 3) * (cmd.x1 - px), py + (2 / 3) * (cmd.y1 - py)];\n\t\t\tconst c2 = [cmd.x + (2 / 3) * (cmd.x1 - cmd.x), cmd.y + (2 / 3) * (cmd.y1 - cmd.y)];\n\t\t\tcur.o[cur.o.length - 1] = [c1[0] - px, c1[1] - py];\n\t\t\tadd(cmd.x, cmd.y, c2[0], c2[1]);\n\t\t} else if (cmd.type === 'C') {\n\t\t\tcur.o[cur.o.length - 1] = [cmd.x1 - px, cmd.y1 - py];\n\t\t\tadd(cmd.x, cmd.y, cmd.x2, cmd.y2);\n\t\t} else if (cmd.type === 'Z') {\n\t\t\tcur.c = true;\n\t\t\t// A closing segment that ends on the first vertex folds into it.\n\t\t\tconst n = cur.v.length;\n\t\t\tif (n > 1 && Math.abs(cur.v[n - 1][0] - cur.v[0][0]) < 1e-9 && Math.abs(cur.v[n - 1][1] - cur.v[0][1]) < 1e-9) {\n\t\t\t\tcur.i[0] = cur.i[n - 1];\n\t\t\t\tcur.v.pop();\n\t\t\t\tcur.i.pop();\n\t\t\t\tcur.o.pop();\n\t\t\t}\n\t\t\tout.push(cur);\n\t\t\tcur = null;\n\t\t}\n\t}\n\tif (cur) out.push(cur);\n\treturn out.map((c) => ({ c: c.c, v: c.v.map((p) => p.map(round)), i: c.i.map((p) => p.map(round)), o: c.o.map((p) => p.map(round)) }));\n}\n\n/** The node's own matrix as Lottie transform parts (no skew), or null when it skews. */\nfunction staticParts(m: AffineMatrix): { p: Vec; s: Vec; r: number } | null {\n\tconst sx = Math.hypot(m[0], m[1]);\n\tif (!(sx > 1e-12)) return null;\n\tconst sy = (m[0] * m[3] - m[1] * m[2]) / sx;\n\tif (Math.abs(m[2] + (m[1] / sx) * sy) > 1e-6 || Math.abs(m[3] - (m[0] / sx) * sy) > 1e-6) return null;\n\treturn { p: [m[4], m[5]], s: [sx * 100, sy * 100], r: (Math.atan2(m[1], m[0]) * 180) / Math.PI };\n}\n\n/** A scene as a Lottie animation. */\nexport function toLottie(scene: MotionScene, options: LottieExportOptions = {}): LottieExport {\n\tconst fps = options.fps ?? scene.fps ?? 30;\n\tconst precision = options.precision ?? 3;\n\tconst round = (n: number) => Math.round(n * 10 ** precision) / 10 ** precision;\n\tconst frame = (ms: number) => round((ms * fps) / 1000);\n\tconst timeline = compileMotionScene(scene);\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst notes: string[] = [];\n\tif (scene.trigger) notes.push(`The scene plays on ${scene.trigger}; Lottie has no trigger, so it plays through (markers show where each shot starts, for a player to stop at).`);\n\tlet sampled = 0;\n\tconst track = (id: string, p: MotionProperty) => timeline.tracks.get(motionTrackKey(id, p)) ?? [];\n\t// Additive layers (blend \"add\"), on their own tracks when the editor has them.\n\tconst layers = (id: string, p: MotionProperty) => timeline.tracks.get(`${motionTrackKey(id, p)}\\u0000add`) ?? [];\n\tconst end = timeline.duration;\n\n\t/** The Lottie bezier for a segment's ease, if its change can be one eased keyframe. */\n\tconst curveOf = (s: MotionSegment): Bezier4 | undefined => {\n\t\tif (s.behavior || s.steps || s.geometric) return undefined;\n\t\tconst e = s.reverse ? reverseCubicBezier(s.ease) : resolveEasing(s.ease);\n\t\tif (!e || e === 'hold' || e.type !== 'cubic-bezier') return undefined;\n\t\treturn [e.x1, e.y1, e.x2, e.y2];\n\t};\n\n\t/**\n\t * A property's keyframes: one eased key per stretch where every active segment shares that\n\t * stretch and one cubic-bezier ease, linear keys at `fps` elsewhere.\n\t */\n\tconst animate = (segments: readonly MotionSegment[], value: (t: number) => Vec, exact = true): LottieValue => {\n\t\tconst rest = value(0).map(round);\n\t\tif (!segments.length) return { a: 0, k: rest.length === 1 ? rest[0] : rest };\n\t\tconst keys: LottieKeyframe[] = [];\n\t\tconst key = (t: number, v: Vec, ease?: Bezier4 | 'linear' | 'hold') => {\n\t\t\tconst k: LottieKeyframe = { t: frame(t), s: v.map(round) };\n\t\t\tif (ease === 'hold') k.h = 1;\n\t\t\telse {\n\t\t\t\tconst [x1, y1, x2, y2] = ease === 'linear' || !ease ? [0, 0, 1, 1] : ease;\n\t\t\t\tk.o = { x: [round(x1)], y: [round(y1)] };\n\t\t\t\tk.i = { x: [round(x2)], y: [round(y2)] };\n\t\t\t}\n\t\t\tif (keys.length && keys[keys.length - 1].t === k.t) keys[keys.length - 1] = k;\n\t\t\telse keys.push(k);\n\t\t};\n\t\tconst times = [...new Set([0, ...segments.flatMap((s) => [s.start, s.end]), end])].filter((t) => t >= 0 && t <= end).sort((a, b) => a - b);\n\t\tfor (let n = 0; n + 1 < times.length; n++) {\n\t\t\tconst a = times[n];\n\t\t\tconst b = times[n + 1];\n\t\t\tconst active = segments.filter((s) => s.start < b && s.end > a);\n\t\t\tif (!active.length) {\n\t\t\t\tkey(a, value(a), 'hold');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst first = active[0];\n\t\t\tconst curve = exact && active.every((s) => s.start === a && s.end === b && JSON.stringify(curveOf(s)) === JSON.stringify(curveOf(first))) ? curveOf(first) : undefined;\n\t\t\tif (curve) {\n\t\t\t\tkey(a, value(a), curve);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst count = Math.max(1, Math.ceil(((b - a) * fps) / 1000));\n\t\t\tfor (let k = 0; k < count; k++) {\n\t\t\t\tconst t = a + ((b - a) * k) / count;\n\t\t\t\tkey(t, value(t), 'linear');\n\t\t\t\tsampled++;\n\t\t\t}\n\t\t}\n\t\t// Changes that cut (no length) land on their frame.\n\t\tfor (const s of segments) if (s.end <= s.start) key(s.start, value(s.start), 'hold');\n\t\tkeys.sort((x, y) => x.t - y.t);\n\t\tkey(end, value(end), 'hold');\n\t\tconst last = keys[keys.length - 1];\n\t\tdelete last.o;\n\t\tdelete last.i;\n\t\tdelete last.h;\n\t\treturn { a: 1, k: keys };\n\t};\n\n\t/** The node's offset as Lottie transform parts at `t` (anchor at its centre). */\n\tconst poseAt = (entry: MotionNodeEntry, t: number) => {\n\t\tconst o = motionNodeOffset(entry, timeline, t, nodes);\n\t\tif (!o) return { p: [entry.center.x, entry.center.y], s: [100, 100], r: 0 };\n\t\tconst m = o.matrix;\n\t\tconst sx = Math.hypot(m[0], m[1]);\n\t\tconst sy = sx > 1e-12 ? (m[0] * m[3] - m[1] * m[2]) / sx : 0;\n\t\tconst c = entry.center;\n\t\treturn { p: [m[0] * c.x + m[2] * c.y + m[4], m[1] * c.x + m[3] * c.y + m[5]], s: [sx * 100, sy * 100], r: (Math.atan2(m[1], m[0]) * 180) / Math.PI };\n\t};\n\n\t/** The outer group's transform: the node's animated pose and opacity. */\n\tconst poseTransform = (entry: MotionNodeEntry): LottieShape => {\n\t\tconst id = entry.node.id;\n\t\tconst tr = STATIC_TR();\n\t\tconst c = [entry.center.x, entry.center.y].map(round);\n\t\tconst own = (p: MotionProperty) => track(id, p);\n\t\tconst layered = (['x', 'y', 'rotation', 'scaleX', 'scaleY'] as MotionProperty[]).some((p) => layers(id, p).length);\n\t\tconst moving = (['x', 'y', 'rotation', 'scaleX', 'scaleY', 'follow'] as MotionProperty[]).some((p) => own(p).length) || layered;\n\t\tif (moving) {\n\t\t\t// Position, rotation and scale are separate in Lottie, so each is exact on its own; follows and layers mix them and are sampled.\n\t\t\tconst mixed = own('follow').length > 0 || layered;\n\t\t\ttr.a = { a: 0, k: c };\n\t\t\ttr.p = animate(mixed ? [...own('x'), ...own('y'), ...own('follow'), ...layers(id, 'x'), ...layers(id, 'y')] : [...own('x'), ...own('y')], (t) => poseAt(entry, t).p, !mixed);\n\t\t\ttr.r = animate(mixed ? [...own('rotation'), ...own('follow'), ...layers(id, 'rotation')] : own('rotation'), (t) => [poseAt(entry, t).r], !mixed);\n\t\t\ttr.s = animate(mixed ? [...own('scaleX'), ...own('scaleY'), ...layers(id, 'scaleX'), ...layers(id, 'scaleY')] : [...own('scaleX'), ...own('scaleY')], (t) => poseAt(entry, t).s, !mixed);\n\t\t\t// Lottie needs the position where the anchor is when nothing moves it.\n\t\t\tif ((tr.p as LottieValue).a === 0) tr.p = { a: 0, k: poseAt(entry, 0).p.map(round) };\n\t\t}\n\t\tconst opacity = own('opacity');\n\t\tconst rest = entry.node.opacity ?? 1;\n\t\ttr.o = opacity.length ? animate(opacity, (t) => [Math.min(1, Math.max(0, Number(trackValue(opacity, t) ?? rest))) * 100]) : { a: 0, k: round(rest * 100) };\n\t\treturn tr;\n\t};\n\n\t/** The outermost of a path and its groups whose track sets `p` (a group's paint goes to each path in it). */\n\tconst owner = (path: VectorPathNode, p: MotionProperty): string | undefined => {\n\t\tconst entry = nodes.get(path.id);\n\t\tif (!entry) return undefined;\n\t\treturn [...entry.ancestors, path.id].find((id) => timeline.tracks.has(motionTrackKey(id, p)));\n\t};\n\n\tconst paintOf = (paint: VectorPaint | undefined, what: string, id: string): Vec | null => {\n\t\tif (paint === undefined || paint === null || paint === 'none') return null;\n\t\tconst c = rgba(paint);\n\t\tif (!c) notes.push(`\"${id}\": its ${what} is a gradient, which is not exported; it is left unpainted.`);\n\t\treturn c;\n\t};\n\n\tconst pathShapes = (path: VectorPathNode): LottieShape[] => {\n\t\tconst items: LottieShape[] = [];\n\t\tconst shapeSegments = [...timeline.tracks.entries()].filter(([k]) => k.startsWith(`${path.id}\\u0000`) && (k.endsWith('\\u0000shape') || k.includes('\\u0000effect:'))).flatMap(([, v]) => v);\n\t\tconst geometryAt = (t: number): BezierPath => {\n\t\t\tif (!shapeSegments.length) return vectorPathWorldBezier(path);\n\t\t\tconst now = indexMotionNodes(motionFrameAt(scene, t, { draw: false, offsets: false }).document.nodes).get(path.id)?.node;\n\t\t\treturn now && now.type === 'path' ? vectorPathWorldBezier(expandVectorAppearances([now])[0] as VectorPathNode) : vectorPathWorldBezier(path);\n\t\t};\n\t\tconst rest = lottieContours(toBezierPath(geometryAt(0)), round);\n\t\trest.forEach((contour, n) => {\n\t\t\tlet ks: LottieValue | { a: 0; k: unknown } = { a: 0, k: contour };\n\t\t\tif (shapeSegments.length) {\n\t\t\t\t// Lottie tweens shapes vertex by vertex: only a morph that keeps every contour's vertex count can be keyed.\n\t\t\t\tconst keys: LottieKeyframe[] = [];\n\t\t\t\tlet fits = true;\n\t\t\t\tconst count = Math.max(1, Math.ceil((end * fps) / 1000));\n\t\t\t\tfor (let k = 0; k <= count && fits; k++) {\n\t\t\t\t\tconst t = (end * k) / count;\n\t\t\t\t\tconst c = lottieContours(toBezierPath(geometryAt(t)), round)[n];\n\t\t\t\t\tif (!c || c.v.length !== contour.v.length || c.c !== contour.c) fits = false;\n\t\t\t\t\telse keys.push({ t: frame(t), s: [c as unknown as number], ...(k < count ? { o: { x: [0], y: [0] }, i: { x: [1], y: [1] } } : {}) } as LottieKeyframe);\n\t\t\t\t}\n\t\t\t\tif (fits) {\n\t\t\t\t\tks = { a: 1, k: keys };\n\t\t\t\t\tsampled += keys.length;\n\t\t\t\t} else notes.push(`\"${path.id}\": its morph changes how many points the outline has, which Lottie cannot tween; it shows its starting shape.`);\n\t\t\t}\n\t\t\titems.push({ ty: 'sh', nm: `${path.id} ${n + 1}`, ks });\n\t\t});\n\t\tconst fillFrom = owner(path, 'fill');\n\t\tconst strokeFrom = owner(path, 'stroke');\n\t\tconst widthFrom = owner(path, 'strokeWidth');\n\t\tconst fadeFrom = owner(path, 'fillOpacity');\n\t\tconst drawFrom = owner(path, 'drawEnd');\n\t\tconst tailFrom = owner(path, 'drawStart');\n\t\tif (drawFrom || tailFrom) {\n\t\t\t// Trim paths: the end draws on; the start follows it for a travelling stroke (draw with comet).\n\t\t\tconst pct = (track: readonly MotionSegment[], fallback: number) => (t: number) => [Math.min(1, Math.max(0, Number(trackValue(track, t) ?? fallback))) * 100];\n\t\t\tconst head = drawFrom ? track(drawFrom, 'drawEnd') : [];\n\t\t\tconst tail = tailFrom ? track(tailFrom, 'drawStart') : [];\n\t\t\titems.push({ ty: 'tm', nm: 'Draw on', s: tail.length ? animate(tail, pct(tail, 0)) : { a: 0, k: 0 }, e: head.length ? animate(head, pct(head, 1)) : { a: 0, k: 100 }, o: { a: 0, k: 0 }, m: 1 });\n\t\t}\n\n\t\tconst stroke = paintOf(path.stroke, 'stroke', path.id);\n\t\tif (stroke || strokeFrom) {\n\t\t\tconst colour = strokeFrom ? track(strokeFrom, 'stroke') : [];\n\t\t\titems.push({\n\t\t\t\tty: 'st',\n\t\t\t\tnm: 'Stroke',\n\t\t\t\tc: colour.length ? animate(colour, (t) => rgba(trackValue(colour, t)) ?? stroke ?? [0, 0, 0, 1]) : { a: 0, k: (stroke ?? [0, 0, 0, 1]).map(round) },\n\t\t\t\to: { a: 0, k: 100 },\n\t\t\t\tw: widthFrom ? animate(track(widthFrom, 'strokeWidth'), (t) => [Math.max(0, Number(trackValue(track(widthFrom, 'strokeWidth'), t) ?? path.strokeWidth ?? 1))]) : { a: 0, k: round(path.strokeWidth ?? 1) },\n\t\t\t\tlc: path.strokeLinecap === 'round' ? 2 : path.strokeLinecap === 'square' ? 3 : 1,\n\t\t\t\tlj: path.strokeLinejoin === 'round' ? 2 : path.strokeLinejoin === 'bevel' ? 3 : 1,\n\t\t\t\tml: 4\n\t\t\t});\n\t\t\tif (path.strokeDasharray?.length) notes.push(`\"${path.id}\": its dashes are not exported; the stroke is solid.`);\n\t\t\tif (path.strokeAlign && path.strokeAlign !== 'center') notes.push(`\"${path.id}\": its stroke is drawn centred (Lottie has no inside or outside strokes).`);\n\t\t}\n\t\tconst fill = paintOf(path.fill, 'fill', path.id);\n\t\tif (fill || fillFrom) {\n\t\t\tconst colour = fillFrom ? track(fillFrom, 'fill') : [];\n\t\t\tconst fade = fadeFrom ? track(fadeFrom, 'fillOpacity') : [];\n\t\t\titems.push({\n\t\t\t\tty: 'fl',\n\t\t\t\tnm: 'Fill',\n\t\t\t\tc: colour.length ? animate(colour, (t) => rgba(trackValue(colour, t)) ?? fill ?? [0, 0, 0, 1]) : { a: 0, k: (fill ?? [0, 0, 0, 1]).map(round) },\n\t\t\t\to: fade.length ? animate(fade, (t) => [Math.min(1, Math.max(0, Number(trackValue(fade, t) ?? 1))) * 100]) : { a: 0, k: 100 },\n\t\t\t\tr: path.fillRule === 'evenodd' ? 2 : 1\n\t\t\t});\n\t\t}\n\t\treturn items;\n\t};\n\n\t// Hidden nodes are never drawn (the stage gives them display=\"none\"), so they are left out. Marking\n\t// their group `hd: true` is not enough: lottie-web honours `hd` on paths, fills and strokes but not on\n\t// groups. Follow routes and morph targets are sampled into keyframes, so nothing in the file needs them.\n\tconst shown = (list: readonly VectorNode[]) => list.filter((n) => n.visible !== false);\n\n\tconst nodeGroup = (node: VectorNode): LottieShape => {\n\t\tconst entry = nodes.get(node.id)!;\n\t\tif (timeline.tracks.has(motionTrackKey(node.id, 'clipRect')) || timeline.tracks.has(motionTrackKey(node.id, 'clipCircle')))\n\t\t\tnotes.push(`\"${node.id}\": its wipe, iris or split reveal is not exported (Lottie masks belong to layers); it fades with its opacity only.`);\n\t\tlet inner: LottieShape[];\n\t\tconst innerTr = STATIC_TR();\n\t\tif (node.type === 'path') inner = [...pathShapes(node)];\n\t\telse {\n\t\t\t// Later children draw on top: Lottie lists the top item first.\n\t\t\tinner = shown(node.children).reverse().map(nodeGroup);\n\t\t\tconst m = nodeMatrix(node);\n\t\t\tif (m !== IDENTITY_MATRIX) {\n\t\t\t\tconst parts = staticParts(m);\n\t\t\t\tif (!parts) notes.push(`\"${node.id}\": its transform skews, which is not exported; it is drawn without the skew.`);\n\t\t\t\telse {\n\t\t\t\t\tinnerTr.p = { a: 0, k: parts.p.map(round) };\n\t\t\t\t\tinnerTr.s = { a: 0, k: parts.s.map(round) };\n\t\t\t\t\tinnerTr.r = { a: 0, k: round(parts.r) };\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst body: LottieShape = { ty: 'gr', nm: `${node.id} (own)`, it: [...inner, innerTr] };\n\t\treturn { ty: 'gr', nm: node.name ?? node.id, it: [body, poseTransform(entry)] };\n\t};\n\n\tconst artwork = { ...scene.artwork, nodes: expandVectorAppearances(scene.artwork.nodes) };\n\tconst content = shown(artwork.nodes).reverse().map(nodeGroup);\n\tif (artwork.background && rgba(artwork.background))\n\t\tcontent.push({ ty: 'gr', nm: 'Background', it: [{ ty: 'rc', nm: 'Background', p: { a: 0, k: [artwork.width / 2, artwork.height / 2] }, s: { a: 0, k: [artwork.width, artwork.height] }, r: { a: 0, k: 0 } }, { ty: 'fl', c: { a: 0, k: rgba(artwork.background)!.map(round) }, o: { a: 0, k: 100 }, r: 1 }, STATIC_TR()] });\n\n\t// The camera: a root transform that maps its box onto the canvas.\n\tconst camera = track('', 'camera');\n\tconst root = STATIC_TR();\n\tif (camera.length) {\n\t\tconst box = (t: number) => (trackValue(camera, t) as number[] | undefined) ?? [0, 0, artwork.width, artwork.height];\n\t\troot.a = animate(camera, (t) => box(t).slice(0, 2), false);\n\t\troot.s = animate(camera, (t) => [(artwork.width / box(t)[2]) * 100, (artwork.height / box(t)[3]) * 100], false);\n\t}\n\n\tconst op = Math.max(1, Math.ceil((end * fps) / 1000));\n\tconst lottie: LottieAnimation = {\n\t\tv: '5.7.4',\n\t\tfr: fps,\n\t\tip: 0,\n\t\top,\n\t\tw: artwork.width,\n\t\th: artwork.height,\n\t\tnm: scene.name,\n\t\tddd: 0,\n\t\tassets: [],\n\t\tlayers: [\n\t\t\t{\n\t\t\t\tddd: 0,\n\t\t\t\tind: 1,\n\t\t\t\tty: 4,\n\t\t\t\tnm: scene.name,\n\t\t\t\tsr: 1,\n\t\t\t\tks: { o: { a: 0, k: 100 }, r: { a: 0, k: 0 }, p: { a: 0, k: [0, 0, 0] }, a: { a: 0, k: [0, 0, 0] }, s: { a: 0, k: [100, 100, 100] } },\n\t\t\t\tao: 0,\n\t\t\t\tshapes: [{ ty: 'gr', nm: 'Camera', it: [...content, root] }],\n\t\t\t\tip: 0,\n\t\t\t\top,\n\t\t\t\tst: 0,\n\t\t\t\tbm: 0\n\t\t\t}\n\t\t],\n\t\tmarkers: timeline.shots.map((s) => ({ tm: frame(s.start), cm: s.label ?? s.id, dr: frame(s.end - s.start) }))\n\t};\n\treturn { lottie, sampled, notes: [...new Set(notes)] };\n}\n","import { motionStageSvg, type MotionOverlayOptions } from './onion.js';\nimport type { Clock } from '../animation/clock.js';\nimport type { AnimationLoopMode } from '../animation/evaluate.js';\nimport { AnimationPlayer } from '../animation/player.js';\nimport { HistoryManager } from '../history/HistoryManager.js';\nimport type { Command } from '../history/types.js';\nimport type { VectorDocument } from '../vector/types.js';\nimport { checkMotionScene } from './check.js';\nimport { compileMotionScene, motionShotAt, type MotionShotTiming } from './compile.js';\nimport { applyMotionEdits, createMotionScene, type MotionEdit, type MotionEditResult } from './edit.js';\nimport { motionFrameAt, motionFrameToSvg, type MotionFrame, type MotionFrameOptions, type MotionSvgOptions } from './evaluate.js';\nimport { toFlairEffectDocument, toFlairSvgMotion, toFlairVectorEffect, type FlairEffectOptions, type FlairExportOptions } from './flair.js';\nimport type { MotionIssue } from './issues.js';\nimport { parseMotionScene } from './parse.js';\nimport type { MotionScene } from './types.js';\n\nexport interface AnimationEditorOptions {\n\t/** The scene to open (default: an empty one over a blank 800 × 450 artwork). */\n\tscene?: MotionScene;\n\t/** Shared undo history (default: a new one). */\n\thistory?: HistoryManager;\n\t/** Time source for playback (default: requestAnimationFrame). Pass a `ManualClock` to step frames. */\n\tclock?: Clock;\n\treadOnly?: boolean;\n\t/** Called after every change to the scene (not on playback or selection). */\n\tonChange?: (scene: MotionScene) => void;\n}\n\n/** What is selected on the timeline: a shot, and optionally one of its commands. */\nexport interface AnimationEditorSelection {\n\tshot: string;\n\tcommand?: number;\n}\n\n/** A snapshot of the editor. The same object is returned until something changes. */\nexport interface AnimationEditorState {\n\tscene: MotionScene;\n\t/** Total length (ms). */\n\tduration: number;\n\t/** Each shot's timing. */\n\tshots: readonly MotionShotTiming[];\n\t/** The scene's problems (see `checkMotionScene`). */\n\tissues: readonly MotionIssue[];\n\t/** Playhead (ms). */\n\ttime: number;\n\tplaying: boolean;\n\tloop: AnimationLoopMode;\n\t/** Id of the shot under the playhead. */\n\tcurrentShot: string | null;\n\tselection: AnimationEditorSelection | null;\n\treadOnly: boolean;\n\t/** Why the last edit was refused, if it was. */\n\terror: string | null;\n\tcanUndo: boolean;\n\tcanRedo: boolean;\n\tundoLabel: string;\n\tredoLabel: string;\n\t/** Bumped on every change. */\n\trevision: number;\n}\n\nconst BLANK: VectorDocument = { width: 800, height: 450, background: '#ffffff', nodes: [] };\n\n/**\n * Headless editor for a vector animation (a `MotionScene`): undoable, all-or-nothing edits,\n * playback on an injectable clock, a timeline selection and frames at any time. UI-agnostic:\n * React and Svelte bind it with `useAnimationEditor` / `createAnimationEditor`, and agents\n * drive it through `createAnimationEditorToolProvider`. `getState()` returns the same object\n * until something changes, so it works with `useSyncExternalStore` and Svelte runes.\n */\nexport class AnimationEditorController {\n\treadonly history: HistoryManager;\n\treadonly player: AnimationPlayer;\n\tprivate scene: MotionScene;\n\tprivate issues: MotionIssue[];\n\tprivate selection: AnimationEditorSelection | null = null;\n\tprivate readOnly: boolean;\n\tprivate error: string | null = null;\n\tprivate revision = 0;\n\tprivate applying = false;\n\tprivate readonly onChange?: (scene: MotionScene) => void;\n\tprivate readonly listeners = new Set<(state: AnimationEditorState) => void>();\n\tprivate readonly unsubscribers: (() => void)[] = [];\n\tprivate state!: AnimationEditorState;\n\n\tconstructor(options: AnimationEditorOptions = {}) {\n\t\tthis.history = options.history ?? new HistoryManager();\n\t\tthis.scene = options.scene ? parseMotionScene(options.scene) : createMotionScene(BLANK);\n\t\tthis.issues = checkMotionScene(this.scene);\n\t\tthis.readOnly = options.readOnly ?? false;\n\t\tthis.onChange = options.onChange;\n\t\tthis.player = new AnimationPlayer({ clock: options.clock, duration: () => compileMotionScene(this.scene).duration, loop: this.scene.loop ?? 'none' });\n\t\tthis.state = this.computeState();\n\t\tthis.connect();\n\t}\n\n\tprivate connect() {\n\t\tif (this.unsubscribers.length) return;\n\t\tthis.unsubscribers.push(\n\t\t\tthis.player.subscribe(() => this.notify()),\n\t\t\tthis.history.subscribe(() => {\n\t\t\t\tif (!this.applying) this.notify();\n\t\t\t})\n\t\t);\n\t}\n\n\t/**\n\t * Pauses and stops listening to the player and history. Subscribing again reconnects, so a\n\t * controller survives React StrictMode's unmount / remount.\n\t */\n\tdestroy(): void {\n\t\tthis.player.pause();\n\t\tthis.unsubscribers.splice(0).forEach((u) => u());\n\t}\n\n\tgetState = (): AnimationEditorState => this.state;\n\n\tsubscribe = (listener: (state: AnimationEditorState) => void): (() => void) => {\n\t\tthis.connect();\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t};\n\n\t/** The current scene (immutable; edit through the controller). */\n\tgetScene(): MotionScene {\n\t\treturn this.scene;\n\t}\n\n\tprivate computeState(): AnimationEditorState {\n\t\tconst timeline = compileMotionScene(this.scene);\n\t\tconst p = this.player.getState();\n\t\tconst h = this.history.getState();\n\t\treturn {\n\t\t\tscene: this.scene,\n\t\t\tduration: timeline.duration,\n\t\t\tshots: timeline.shots,\n\t\t\tissues: this.issues,\n\t\t\ttime: p.time,\n\t\t\tplaying: p.playing,\n\t\t\tloop: p.loop,\n\t\t\tcurrentShot: motionShotAt(timeline, p.time)?.id ?? null,\n\t\t\tselection: this.selection,\n\t\t\treadOnly: this.readOnly,\n\t\t\terror: this.error,\n\t\t\tcanUndo: h.canUndo,\n\t\t\tcanRedo: h.canRedo,\n\t\t\tundoLabel: h.undoName,\n\t\t\tredoLabel: h.redoName,\n\t\t\trevision: this.revision\n\t\t};\n\t}\n\n\tprivate notify() {\n\t\tthis.revision++;\n\t\tthis.state = this.computeState();\n\t\tconst state = this.state;\n\t\tthis.listeners.forEach((listener) => {\n\t\t\ttry {\n\t\t\t\tlistener(state);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('[AnimationEditorController] Error in state listener:', error);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate setScene(scene: MotionScene) {\n\t\tthis.applying = true;\n\t\ttry {\n\t\t\tthis.scene = scene;\n\t\t\tthis.issues = checkMotionScene(scene);\n\t\t\tif (this.selection) {\n\t\t\t\tconst shot = scene.shots.find((s) => s.id === this.selection!.shot);\n\t\t\t\tif (!shot) this.selection = null;\n\t\t\t\telse if (this.selection.command !== undefined && this.selection.command >= shot.run.length) this.selection = { shot: shot.id };\n\t\t\t}\n\t\t\tthis.player.setLoop(scene.loop ?? 'none');\n\t\t\tthis.player.setDuration(() => compileMotionScene(this.scene).duration);\n\t\t} finally {\n\t\t\tthis.applying = false;\n\t\t}\n\t\tthis.notify();\n\t\tthis.onChange?.(scene);\n\t}\n\n\tprivate commit(label: string, next: MotionScene) {\n\t\tconst before = this.scene;\n\t\tthis.error = null;\n\t\tif (next === before) {\n\t\t\tthis.notify();\n\t\t\treturn;\n\t\t}\n\t\tconst command: Command = {\n\t\t\tname: label,\n\t\t\ttag: 'animation-editor',\n\t\t\texecute: () => this.setScene(next),\n\t\t\tundo: () => this.setScene(before),\n\t\t\tredo: () => this.setScene(next)\n\t\t};\n\t\tthis.history.execute(command);\n\t}\n\n\tprivate refuse(message: string): MotionEditResult {\n\t\tthis.error = message;\n\t\tthis.notify();\n\t\treturn { ok: false, error: message };\n\t}\n\n\t/** Why edits are refused now, or `null` when they are allowed. */\n\treadOnlyReason(): string | null {\n\t\treturn this.readOnly ? 'The animation is read-only.' : null;\n\t}\n\n\t/**\n\t * Applies edits as one undo step, all or nothing (see `applyMotionEdits`). With\n\t * `dryRun` it reports what would happen and changes nothing.\n\t */\n\tapply(edits: MotionEdit | readonly MotionEdit[], label = 'Edit animation', options: { dryRun?: boolean } = {}): MotionEditResult {\n\t\tconst reason = this.readOnlyReason();\n\t\tif (reason) return this.refuse(reason);\n\t\tconst result = applyMotionEdits(this.scene, edits);\n\t\tif (!result.ok) return options.dryRun ? result : this.refuse(result.error);\n\t\tif (!options.dryRun) this.commit(label, result.scene);\n\t\treturn result;\n\t}\n\n\t/** Replaces the artwork (e.g. from a vector editor's `onChange`), as one undo step. */\n\tsetArtwork(artwork: VectorDocument, label = 'Change artwork'): MotionEditResult {\n\t\treturn this.apply({ op: 'set_artwork', artwork }, label);\n\t}\n\n\t/** Opens a scene (JSON or object). `clearHistory` drops the undo stack (opening a file); otherwise it is one undo step. */\n\tload(scene: MotionScene | string, options: { clearHistory?: boolean } = {}): MotionEditResult {\n\t\tlet parsed: MotionScene;\n\t\ttry {\n\t\t\tparsed = parseMotionScene(scene);\n\t\t} catch (error) {\n\t\t\treturn this.refuse((error as Error).message);\n\t\t}\n\t\tif (options.clearHistory) {\n\t\t\tthis.history.clear();\n\t\t\tthis.error = null;\n\t\t\tthis.selection = null;\n\t\t\tthis.setScene(parsed);\n\t\t\tthis.player.seek(0);\n\t\t\treturn { ok: true, scene: parsed, issues: this.issues, hints: [] };\n\t\t}\n\t\treturn this.apply({ op: 'replace_scene', scene: parsed }, 'Replace animation');\n\t}\n\n\tsetReadOnly(readOnly: boolean): void {\n\t\tif (this.readOnly === readOnly) return;\n\t\tthis.readOnly = readOnly;\n\t\tthis.notify();\n\t}\n\n\t/** Selects a shot (and optionally a command in it); `null` clears. Unknown shots clear. */\n\tselect(selection: AnimationEditorSelection | null): void {\n\t\tconst shot = selection && this.scene.shots.find((s) => s.id === selection.shot);\n\t\tconst next = shot ? { shot: shot.id, ...(selection!.command !== undefined && selection!.command < shot.run.length ? { command: selection!.command } : {}) } : null;\n\t\tif (JSON.stringify(next) === JSON.stringify(this.selection)) return;\n\t\tthis.selection = next;\n\t\tthis.notify();\n\t}\n\n\tplay(): void {\n\t\tthis.player.play();\n\t}\n\n\tpause(): void {\n\t\tthis.player.pause();\n\t}\n\n\ttoggle(): void {\n\t\tthis.player.toggle();\n\t}\n\n\t/** Moves the playhead (ms). */\n\tseek(time: number): void {\n\t\tthis.player.seek(time);\n\t}\n\n\t/** Moves the playhead to the start or end of a shot. Returns false for an unknown shot. */\n\tseekShot(id: string, at: 'start' | 'end' = 'start'): boolean {\n\t\tconst shot = compileMotionScene(this.scene).shots.find((s) => s.id === id);\n\t\tif (!shot) return false;\n\t\tthis.player.seek(at === 'start' ? shot.start : shot.end);\n\t\treturn true;\n\t}\n\n\tundo(): boolean {\n\t\treturn this.history.undo();\n\t}\n\n\tredo(): boolean {\n\t\treturn this.history.redo();\n\t}\n\n\t/** The scene at `time` (default: the playhead). */\n\tframe(time = this.player.currentTime, options: MotionFrameOptions = {}): MotionFrame {\n\t\treturn motionFrameAt(this.scene, time, options);\n\t}\n\n\t/** The scene at `time` (default: the playhead) as SVG. */\n\ttoSvg(time = this.player.currentTime, options: MotionSvgOptions & MotionOverlayOptions = {}): string {\n\t\treturn motionStageSvg(this.scene, time, options);\n\t}\n\n\t/** The scene as a Flair `SvgMotion`. */\n\ttoFlairMotion(options: FlairExportOptions = {}) {\n\t\treturn toFlairSvgMotion(this.scene, options);\n\t}\n\n\t/** The scene as a Flair catalog vector effect. */\n\ttoFlairEffect(options: FlairEffectOptions = {}) {\n\t\treturn toFlairVectorEffect(this.scene, options);\n\t}\n\n\t/** The scene as a Flair `EffectDocument`. */\n\ttoFlairDocument(options: FlairExportOptions = {}) {\n\t\treturn toFlairEffectDocument(this.scene, options);\n\t}\n}\n","import { ANIMATION_EASING_PRESETS } from '../animation/easing.js';\nimport type { AgentTool, AgentToolProvider } from '../tools/registry.js';\nimport type { JsonSchema } from '../tools/schema.js';\nimport { parseVectorSvg } from '../vector/svg.js';\nimport type { VectorNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionClipLayout, motionBeatAt, motionBeatTime } from './compile.js';\nimport { fitMotionScene } from './fit.js';\nimport { toLottie } from './lottie.js';\nimport { motionContactSheetSvg, motionPath } from './onion.js';\nimport { fromFlairSvgMotion, fromFlairVectorEffect, type FlairImportResult } from './flair-import.js';\nimport type { AnimationEditorController } from './controller.js';\nimport { MOTION_EDIT_OPS, resolveMotionEditRefs, type MotionEdit, type MotionEditResult } from './edit.js';\nimport { motionIssueLine, namedWithSuggestion, type MotionIssue } from './issues.js';\nimport { MOTION_COMMAND_TYPES, MOTION_DIRECTIONS, MOTION_ENTER_STYLES, MOTION_EXIT_STYLES, MOTION_IRIS_SHAPES, MOTION_REPEAT_MODES, MOTION_BLENDS, MOTION_SPLIT_ORIENTATIONS, motionFlairPrimitive, type MotionCommand, type MotionScene } from './types.js';\n\nexport interface AnimationEditorToolProviderOptions {\n\t/** Provider id (unique per registry). Default `animation`. */\n\tid?: string;\n\t/** Always prefix tool names with `<namespace>__`. */\n\tnamespace?: string;\n\t/** The animation cannot be edited: write tools are hidden and `get_animation` says why. A string is the reason. */\n\treadOnly?: boolean | string | (() => boolean | string);\n\t/** Turns SVG into PNG (e.g. `rasterizeSvg`), so `render_animation_frame` can return an image. */\n\trasterize?: (svg: string, size: { width: number; height: number }) => Promise<{ data: string; mimeType: string }> | { data: string; mimeType: string };\n}\n\nconst READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\nconst WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false } as const;\nconst WRITE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\nconst DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false } as const;\n\nconst object = (properties: Record<string, JsonSchema>, required: string[] = [], description?: string): JsonSchema & { type: 'object' } => ({\n\ttype: 'object' as const,\n\t...(description ? { description } : {}),\n\tproperties,\n\t...(required.length ? { required } : {}),\n\tadditionalProperties: false\n});\n\nconst SHOT_ID = { type: 'string', minLength: 1, description: 'A shot id from get_animation (e.g. \"intro\").' } as const;\nconst NODE_IDS = { type: 'array', items: { type: 'string', minLength: 1 }, minItems: 1, description: 'Node ids from get_animation\\'s \"elements\" (a group animates as one).' } as const;\nconst MS = (what: string) => ({ type: 'number', minimum: 0, description: `${what} in milliseconds.` }) as const;\nconst FRACTION = (what: string) => ({ type: 'number', minimum: 0, maximum: 1, description: what }) as const;\nconst POINT = (what: string) => object({ x: { type: 'number', description: 'Document units.' }, y: { type: 'number', description: 'Document units.' } }, ['x', 'y'], what);\nconst EASE: JsonSchema = {\n\tdescription: `Easing: a preset (${ANIMATION_EASING_PRESETS.join(', ')}), { \"type\": \"cubic-bezier\", \"x1\", \"y1\", \"x2\", \"y2\" }, { \"type\": \"spring\", … } or { \"type\": \"elastic\", … }. The spring presets are Figma's: gentle, quick, bouncy, slow. A command with a spring and no \"duration\" lasts until the spring settles. Default: a cubic ease-out for entrances, cubic ease-in-out for moves.`,\n\tanyOf: [\n\t\t{ type: 'string', enum: [...ANIMATION_EASING_PRESETS] },\n\t\tobject({ type: { const: 'cubic-bezier', description: 'Curve kind.' }, x1: { type: 'number', description: 'Out handle x (0–1).' }, y1: { type: 'number', description: 'Out handle y.' }, x2: { type: 'number', description: 'In handle x (0–1).' }, y2: { type: 'number', description: 'In handle y.' } }, ['type', 'x1', 'y1', 'x2', 'y2']),\n\t\tobject(\n\t\t\t{\n\t\t\t\ttype: { const: 'spring', description: 'A damped spring (may overshoot).' },\n\t\t\t\tstiffness: { type: 'number', exclusiveMinimum: 0, description: 'Stiffness (default 170; quick 300, bouncy 600).' },\n\t\t\t\tdamping: { type: 'number', minimum: 0, description: 'Damping (default 26; lower bounces more).' },\n\t\t\t\tmass: { type: 'number', exclusiveMinimum: 0, description: 'Mass (default 1).' },\n\t\t\t\tvelocity: { type: 'number', description: 'Starting speed, in changes per second (default 0).' }\n\t\t\t},\n\t\t\t['type']\n\t\t),\n\t\tobject(\n\t\t\t{\n\t\t\t\ttype: { const: 'elastic', description: 'A decaying wobble.' },\n\t\t\t\tamplitude: { type: 'number', minimum: 0, description: 'Overshoot factor (default 1).' },\n\t\t\t\tperiod: { type: 'number', exclusiveMinimum: 0, description: 'Wobble period as a fraction of the length (default 0.3).' },\n\t\t\t\tmode: { type: 'string', enum: ['out', 'in', 'in-out'], description: 'Where it wobbles (default out).' }\n\t\t\t},\n\t\t\t['type']\n\t\t)\n\t]\n};\n\nconst BASE: Record<string, JsonSchema> = {\n\ttargets: NODE_IDS,\n\tduration: MS('Length for each target (each type has a default; draw follows the path length)'),\n\tdelay: MS('Wait before starting (default 0)'),\n\tstagger: MS('Start each further target this much later (default 0)'),\n\twith: { type: 'string', enum: ['after', 'previous'], description: '\"after\" (default) starts when the commands before it finish; \"previous\" starts together with the command before.' },\n\tease: EASE,\n\tnote: { type: 'string', description: 'Why this command is here, in a few words.' },\n\trepeat: { type: 'integer', minimum: 1, maximum: 1000, description: 'Play it this many times (default 1); \"duration\" is one cycle. Not for enter or exit.' },\n\trepeatMode: { type: 'string', enum: [...MOTION_REPEAT_MODES], description: 'loop (default) restarts each cycle, mirror plays every other one backwards, offset carries on from where the last ended (rotate by 90 with repeat 4 makes a full turn).' },\n\tsteps: { type: 'number', exclusiveMinimum: 0, maximum: 120, description: 'Stepped time: hold on a grid of this many frames per second (12 = \"on twos\"). Default: the scene\\'s steps, else smooth.' }\n};\nconst BLEND = (fallback: 'replace' | 'add'): JsonSchema => ({\n\ttype: 'string',\n\tenum: [...MOTION_BLENDS],\n\tdescription: `\"add\" makes it a layer over the pose that stacks with other changes (a shake on a slide); \"replace\" makes it a change the next one takes over from (default ${fallback}).`\n});\nconst DRAW_ORDER: Record<string, JsonSchema> = {\n\torder: { type: 'string', enum: ['together', 'sequence'], description: 'For drawing a group or several paths: together (default) or sequence (one stroke after another, each for a time in proportion to its length).' },\n\tpace: { type: 'string', enum: ['time', 'speed'], description: 'With together: time (default, every stroke takes the whole time) or speed (all at one speed, so short strokes take less).' },\n\talign: { type: 'string', enum: ['start', 'end'], description: 'With pace speed: start them together (default) or finish them together.' },\n\tsortBy: { type: 'string', enum: ['document', 'distance'], description: 'With sequence: stacking order (default) or distance from origin (a radial reveal).' },\n\torigin: object({ x: { type: 'number', description: 'Document units.' }, y: { type: 'number', description: 'Document units.' } }, ['x', 'y'], 'With sortBy distance: where strokes are drawn out from (default the target\\'s centre).')\n};\nconst command = (type: string, description: string, extra: Record<string, JsonSchema> = {}, required: string[] = []): JsonSchema =>\n\tobject({ type: { const: type, description }, ...BASE, ...extra }, ['type', 'targets', ...required], description);\n\n/** JSON Schema of one command (each type its own strict branch). */\nexport const MOTION_COMMAND_SCHEMA: JsonSchema = {\n\tdescription: `A command (one of ${MOTION_COMMAND_TYPES.join(', ')}). Commands in a shot play one after another unless \"with\": \"previous\".`,\n\toneOf: [\n\t\tcommand('enter', 'Brings hidden targets in; they are hidden before this shot.', { ...DRAW_ORDER,\n\t\t\tstyle: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: [...MOTION_ENTER_STYLES],\n\t\t\t\tdescription:\n\t\t\t\t\t'fade (default), pop (scales up past full size and settles), grow (from nothing), slide, draw (outline drawn on, then the fill fades in), zoom (settles from larger), rise (rises a short way, overshooting a touch), or a reveal through a clip over the target\\'s box: wipe (behind a travelling edge), iris (from the centre outwards) or split (from a line through the middle). Reveals need a box with a width and a height (not a lone straight line).'\n\t\t\t},\n\t\t\tdirection: { type: 'string', enum: [...MOTION_DIRECTIONS], description: 'For slide: direction of travel (default up). For wipe: the way the edge travels (default right, revealing from the left).' },\n\t\t\tdistance: { type: 'number', description: 'For slide (default 40) and rise (default 20): document units.' },\n\t\t\tscale: { type: 'number', minimum: 0, description: 'For pop (default 0.5) and zoom (default 1.6): the starting scale (1 = rest size).' },\n\t\t\tshape: { type: 'string', enum: [...MOTION_IRIS_SHAPES], description: 'For iris: open through a circle (default; an ellipse on a box that is not square) or a box.' },\n\t\t\torientation: { type: 'string', enum: [...MOTION_SPLIT_ORIENTATIONS], description: 'For split: horizontal (default) opens up and down from a horizontal line through the middle; vertical opens left and right.' }\n\t\t}),\n\t\tcommand('exit', 'Takes targets out.', { ...DRAW_ORDER,\n\t\t\tstyle: { type: 'string', enum: [...MOTION_EXIT_STYLES], description: 'fade (default), shrink, slide, undraw, or wipe (hides behind a travelling edge through a clip over the target\\'s box: a wipe in, reversed).' },\n\t\t\tdirection: { type: 'string', enum: [...MOTION_DIRECTIONS], description: 'For slide: direction of travel (default down). For wipe: the way the edge travels (default right, hiding from the left).' },\n\t\t\tdistance: { type: 'number', description: 'For slide: document units (default 40).' }\n\t\t}),\n\t\tcommand('draw', 'Draws strokes on (or off) to a fraction of their length.', { ...DRAW_ORDER, comet: FRACTION('A travelling stroke this fraction of the length long: it runs along the path and off the end (leave out from and to).'), to: FRACTION('Fraction drawn at the end (default 1).'), from: FRACTION('Fraction drawn at the start (default: what is drawn now).') }),\n\t\tcommand('move', 'Moves targets by an offset or so their centre lands on a point.', { via: { type: 'array', items: POINT('A point the centre passes through.'), minItems: 1, maxItems: 64, description: 'Waypoints (document units) the centre passes through on the way to \"to\" or \"by\", smoothly (velocity carries through each) and without overshooting any. Default length 700 ms + 400 per waypoint.' }, pacing: { type: 'string', enum: ['even', 'equal'], description: 'With via: even (default) keeps the speed steady along the path; equal gives each stretch the same time.' }, blend: BLEND('replace'), by: POINT('Offset in document units.'), to: POINT('Point (document coordinates) for the centre.') }),\n\t\tcommand('rotate', 'Turns targets about their centre (degrees, clockwise).', { blend: BLEND('replace'), by: { type: 'number', description: 'Degrees to turn by.' }, to: { type: 'number', description: 'Angle to turn to, in degrees from rest.' } }),\n\t\tcommand('scale', 'Scales targets about their centre (1 = rest size).', { blend: BLEND('replace'), to: { description: 'A factor, or { x, y } factors.', anyOf: [{ type: 'number' }, POINT('Factors per axis.')] }, geometric: { type: 'boolean', description: 'Grow by a steady factor, which reads as an even zoom (default false).' } }, ['to']),\n\t\tcommand('fade', 'Changes opacity.', { to: FRACTION('Opacity at the end (0–1).') }, ['to']),\n\t\tcommand('style', 'Blends solid fill / stroke colours (in OKLab) and stroke width. On a group it changes every path in it.', {\n\t\t\tfill: { type: 'string', description: 'CSS colour (hex, rgb(), rgba()).' },\n\t\t\tstroke: { type: 'string', description: 'CSS colour (hex, rgb(), rgba()).' },\n\t\t\tstrokeWidth: { type: 'number', minimum: 0, description: 'Document units.' }\n\t\t}),\n\t\tobject(\n\t\t\t{\n\t\t\t\ttype: { const: 'play', description: 'Plays a clip (set_animation_clip) on the targets: its commands, with \"$\" standing for each target, timed as in a shot.' },\n\t\t\t\ttargets: NODE_IDS,\n\t\t\t\tclip: { type: 'string', minLength: 1, description: 'The clip\\'s name (get_animation lists them).' },\n\t\t\t\tspeed: { type: 'number', minimum: 0.05, maximum: 20, description: 'Play it this many times as fast (default 1).' },\n\t\t\t\tdelay: BASE.delay,\n\t\t\t\tstagger: BASE.stagger,\n\t\t\t\twith: BASE.with,\n\t\t\t\tnote: BASE.note\n\t\t\t},\n\t\t\t['type', 'targets', 'clip'],\n\t\t\t'Plays a clip on the targets.'\n\t\t),\n\t\tcommand('match', 'Smart Animate: tweens a group into another group (usually hidden), part by part. Parts pair by name, then by id with the group ids taken out (card-a-title ↔ card-b-title), then by kind in order; each takes its partner\\'s shape, paint and place. Unpaired parts fade out; parts of \"into\" with no partner do not appear (check_animation lists them).', { into: { type: 'string', minLength: 1, description: 'Id of the group to become.' } }, ['into']),\n\t\tcommand('morph', 'Morphs each target into the shape (and paint) of another node, which usually stays hidden.', { into: { type: 'string', minLength: 1, description: 'Id of the node whose shape to take.' } }, ['into']),\n\t\tcommand('follow', 'Moves targets along a path node, centre on the path.', {\n\t\t\tpath: { type: 'string', minLength: 1, description: 'Id of a path node (it can be hidden).' },\n\t\t\trotate: { type: 'boolean', description: 'Turn with the path (default false); moves and shakes made meanwhile turn with it too.' },\n\t\t\tfrom: FRACTION('Where to start along the path (default 0).'),\n\t\t\tto: FRACTION('Where to end along the path (default 1).')\n\t\t}, ['path']),\n\t\tcommand('pulse', 'Scales up and back to draw the eye.', { blend: BLEND('add'), amount: { type: 'number', description: 'Extra scale at the peak (default 0.15).' }, count: { type: 'integer', minimum: 1, description: 'Pulses (default 1).' } }),\n\t\tcommand('shake', 'Shakes side to side (or up and down), settling.', { blend: BLEND('add'),\n\t\t\tamount: { type: 'number', description: 'Document units (default 8).' },\n\t\t\tcount: { type: 'integer', minimum: 1, description: 'Shakes (default 3).' },\n\t\t\taxis: { type: 'string', enum: ['horizontal', 'vertical'], description: 'Default horizontal.' }\n\t\t}),\n\t\tcommand('teeter', 'Rocks about the centre either way, settling.', { blend: BLEND('add'), angle: { type: 'number', description: 'Degrees either way (default 8).' }, count: { type: 'integer', minimum: 1, description: 'Rocks (default 3).' } }),\n\t\tcommand('wave', 'Bobs up and down without settling, like something floating (default 1000 ms).', { blend: BLEND('add'), amount: { type: 'number', description: 'Height in document units (default 6).' }, count: { type: 'integer', minimum: 1, description: 'Bobs (default 2).' } }),\n\t\tcommand('wiggle', 'Wanders about its place as smooth seeded noise, easing out of and back to rest (default 1500 ms). The same seed always wanders the same way.', { blend: BLEND('add'),\n\t\t\tamount: { type: 'number', description: 'Up to about this far, in document units (default 6).' },\n\t\t\tfrequency: { type: 'number', exclusiveMinimum: 0, description: 'Wanders per second, in Hz (default 3).' },\n\t\t\toctaves: { type: 'integer', minimum: 1, maximum: 8, description: 'Layers of finer detail (default 2).' },\n\t\t\trotate: { type: 'number', description: 'Also turns about the centre by up to about this many degrees (default 0).' },\n\t\t\tseed: { type: 'integer', minimum: 0, description: 'Default: one picked from the target id, so each target wanders its own way.' }\n\t\t}),\n\t\tcommand('color-pulse', 'Tints solid paint toward a colour and back (mixed in OKLab). On a group it tints every path in it.', {\n\t\t\tcolor: { type: 'string', description: 'The tint, a CSS colour (default \"#f59e0b\").' },\n\t\t\tpaint: { type: 'string', enum: ['fill', 'stroke'], description: 'Which paint (default fill).' },\n\t\t\tcount: { type: 'integer', minimum: 1, description: 'Pulses (default 1).' }\n\t\t}),\n\t\tcommand('effect', 'Tweens a numeric parameter of a live path effect on the targets (twist angle, wiggle time, zig zag size, trim offset…).', {\n\t\t\teffect: { type: 'string', minLength: 1, description: 'Effect id from get_animation\\'s element \"effects\".' },\n\t\t\tparam: { type: 'string', minLength: 1, description: 'A numeric parameter of that effect (listed with it).' },\n\t\t\tto: { type: 'number', description: 'Value at the end.' }\n\t\t}, ['effect', 'param', 'to']),\n\t\tobject(\n\t\t\t{ type: { const: 'wait', description: 'Waits.' }, duration: MS('How long'), with: BASE.with, note: BASE.note },\n\t\t\t['type', 'duration'],\n\t\t\t'Waits before the next command.'\n\t\t)\n\t]\n};\n\nconst GEOMETRIC_CAMERA: JsonSchema = { type: 'boolean', description: 'Zoom at a steady rate, so a big zoom does not rush at the start (default false).' };\nconst CAMERA: JsonSchema = {\n\tdescription: 'Where the camera looks: a rectangle { x, y, width, height } in document units, or { frame: \"<node id>\", padding } to frame a node (fitted to the artwork\\'s shape). It eases there over \"ms\" (default 1000); the first shot cuts.',\n\tanyOf: [\n\t\tobject({ x: { type: 'number', description: 'Left.' }, y: { type: 'number', description: 'Top.' }, width: { type: 'number', exclusiveMinimum: 0, description: 'Width.' }, height: { type: 'number', exclusiveMinimum: 0, description: 'Height.' }, ease: EASE, ms: MS('Camera move length'), geometric: GEOMETRIC_CAMERA }, ['x', 'y', 'width', 'height']),\n\t\tobject({ frame: { type: 'string', minLength: 1, description: 'Node id to frame.' }, padding: { type: 'number', description: 'Margin around it (default 24).' }, ease: EASE, ms: MS('Camera move length'), geometric: GEOMETRIC_CAMERA }, ['frame'])\n\t]\n};\n\nconst SHOT_FIELDS: Record<string, JsonSchema> = {\n\tlabel: { type: 'string', description: 'What happens, in a few words.' },\n\tcamera: CAMERA,\n\trun: { type: 'array', items: MOTION_COMMAND_SCHEMA, description: 'Commands, in order.' },\n\thold: MS('Hold after the commands (default 600)'),\n\tspeed: { type: 'number', minimum: 0.05, maximum: 20, description: 'Play the whole shot this many times as fast (default 1; 0.5 is half speed). fit_animation sets it.' },\n\tat: object(\n\t\t{ beat: { type: 'number', minimum: 0, description: 'Beat number on the scene\\'s beat grid, from 0 (2.5 is the \"and\" of beat 3).' }, word: { type: 'integer', minimum: 0, description: 'Index of a narration word, from 0.' }, ms: { type: 'number', minimum: 0, description: 'A time in ms.' } },\n\t\t[],\n\t\t'Start this shot on a cue (give one of beat, word or ms); the shot before holds until then. get_timing_grid lists beats and words.'\n\t)\n};\nconst SHOT: JsonSchema = object({ id: { type: 'string', pattern: '^[A-Za-z0-9_][\\\\w.-]*$', description: 'Unique shot id, e.g. \"intro\".' }, ...SHOT_FIELDS }, ['id', 'run'], 'A shot.');\nconst CONTROL: JsonSchema = object(\n\t{\n\t\tname: { type: 'string', pattern: '^[A-Za-z_]\\\\w*$', description: 'Identifier, e.g. \"accent\".' },\n\t\ttype: { const: 'color', description: 'Controls are colours.' },\n\t\tdefault: { type: 'string', pattern: '^#[0-9a-fA-F]{6}$', description: 'A #rrggbb colour the scene uses; the control stands for every use of it.' },\n\t\tlabel: { type: 'string', description: 'Label in a controls panel.' }\n\t},\n\t['name', 'type', 'default'],\n\t'A colour parameter of the Flair effect made from the scene.'\n);\nconst PRESET: JsonSchema = object({ name: { type: 'string', minLength: 1, description: 'Preset name.' }, values: { type: 'object', additionalProperties: { type: 'string' }, description: 'Control name → colour.' } }, ['name', 'values'], 'Named control values.');\n\nconst SETTINGS: Record<string, JsonSchema> = {\n\tname: { type: 'string', minLength: 1, description: 'Short name, e.g. \"logo-reveal\".' },\n\tdescription: { type: ['string', 'null'], description: 'What it shows; null clears.' },\n\tloop: { type: 'string', enum: ['none', 'loop', 'ping-pong'], description: 'Playback past the end (default none).' },\n\ttrigger: {\n\t\tanyOf: [{ type: 'string', enum: ['click', 'hover', 'press', 'scroll'] }, { type: 'null' }],\n\t\tdescription: 'Play in answer to the viewer when exported to Flair: click (nothing plays until a click; each click plays the next shot, then the first again), hover or press (plays while the pointer is over or down, rewinds when it leaves), scroll (scrubs as it scrolls past). null plays on its own (default). The editor previews it played through.'\n\t},\n\tfps: { type: 'number', minimum: 1, maximum: 120, description: 'Sampling rate for exports (default 30).' },\n\tsteps: { anyOf: [{ type: 'number', exclusiveMinimum: 0, maximum: 120 }, { type: 'null' }], description: 'Stepped time for every command without its own: changes hold on a grid of this many frames per second (12 = \"on twos\" at 24 fps) for a hand-drawn look; null makes it smooth again (default).' },\n\tbeat: {\n\t\tanyOf: [\n\t\t\tobject({ bpm: { type: 'number', minimum: 1, maximum: 1000, description: 'Beats a minute.' }, offset: { type: 'number', description: 'When beat 0 falls, ms (default 0).' }, meter: { type: 'integer', minimum: 1, description: 'Beats a bar (default 4).' } }, ['bpm']),\n\t\t\t{ type: 'null' }\n\t\t],\n\t\tdescription: 'A beat grid (music or a voiceover\\'s rhythm) that shots can be cued to with \"at\": { \"beat\": n }; null clears.'\n\t},\n\tnarration: {\n\t\tanyOf: [\n\t\t\tobject({ words: { type: 'array', items: object({ text: { type: 'string', description: 'The word.' }, start: { type: 'number', minimum: 0, description: 'When it is said, ms.' }, end: { type: 'number', minimum: 0, description: 'When it ends, ms.' } }, ['text', 'start']), description: 'Words in time order, from a TTS or speech-to-text word timing.' } }, ['words']),\n\t\t\t{ type: 'null' }\n\t\t],\n\t\tdescription: 'A voiceover\\'s word timings that shots can be cued to with \"at\": { \"word\": index }; null clears.'\n\t},\n\ttarget: { anyOf: [{ type: 'array', items: { type: 'number', minimum: 0 }, minItems: 2, maxItems: 2 }, { type: 'null' }], description: 'Wanted length [min, max] in seconds; null clears.' }\n};\n\n/** JSON Schema of one `edit_animation` op. */\nconst EDIT_OP: JsonSchema = {\n\tdescription: `One edit (${MOTION_EDIT_OPS.filter((o) => o !== 'replace_scene' && o !== 'set_artwork').join(', ')}), shaped like the tool of the same name with an \"op\" field.`,\n\toneOf: [\n\t\tobject({ op: { const: 'set_settings', description: 'Like set_animation_settings.' }, ...SETTINGS }, ['op']),\n\t\tobject({ op: { const: 'insert_shots', description: 'Like insert_shots.' }, shots: { type: 'array', items: SHOT, minItems: 1, description: 'Shots to add.' }, at: { type: 'integer', minimum: 0, description: 'Position (default: the end).' } }, ['op', 'shots']),\n\t\tobject({ op: { const: 'update_shot', description: 'Like update_shot.' }, shot: SHOT_ID, set: object({ id: SHOT.properties!.id, ...SHOT_FIELDS }, [], 'Fields to replace.'), remove: { type: 'array', items: { type: 'string', enum: ['label', 'camera', 'hold', 'speed', 'at'] }, description: 'Fields to clear.' } }, ['op', 'shot']),\n\t\tobject({ op: { const: 'delete_shots', description: 'Like delete_shots.' }, shots: { type: 'array', items: SHOT_ID, minItems: 1, description: 'Shot ids.' } }, ['op', 'shots']),\n\t\tobject({ op: { const: 'move_shot', description: 'Like move_shot.' }, shot: SHOT_ID, to: { type: 'integer', minimum: 0, description: 'New position (0 = first).' } }, ['op', 'shot', 'to']),\n\t\tobject({ op: { const: 'add_commands', description: 'Like add_commands.' }, shot: SHOT_ID, commands: { type: 'array', items: MOTION_COMMAND_SCHEMA, minItems: 1, description: 'Commands to add.' }, at: { type: 'integer', minimum: 0, description: 'Index in the shot\\'s run (default: the end).' } }, ['op', 'shot', 'commands']),\n\t\tobject({ op: { const: 'update_command', description: 'Like update_command.' }, shot: SHOT_ID, command: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'string', pattern: '^\\\\$(\\\\d+|last)[.\\\\[]' }], description: 'Index in the shot\\'s run, or a reference to an earlier op\\'s outcome such as \"$0.indexes[0]\".' }, set: { type: 'object', description: 'Command fields to replace.' }, remove: { type: 'array', items: { type: 'string' }, description: 'Command fields to clear.' } }, ['op', 'shot', 'command']),\n\t\tobject({ op: { const: 'move_command', description: 'Like move_command.' }, shot: SHOT_ID, command: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'string', pattern: '^\\\\$(\\\\d+|last)[.\\\\[]' }], description: 'Index in the shot\\'s run, or a reference to an earlier op\\'s outcome such as \"$0.indexes[0]\".' }, to: { type: 'integer', minimum: 0, description: 'New index in the run (0 = first).' } }, ['op', 'shot', 'command', 'to']),\n\t\tobject({ op: { const: 'delete_commands', description: 'Like delete_commands.' }, shot: SHOT_ID, commands: { type: 'array', items: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'string', pattern: '^\\\\$(\\\\d+|last)[.\\\\[]' }], description: 'An index, or a reference to an earlier op\\'s outcome such as \"$0.indexes[0]\".' }, minItems: 1, description: 'Indexes in the shot\\'s run.' } }, ['op', 'shot', 'commands']),\n\t\tobject({ op: { const: 'set_controls', description: 'Like set_controls.' }, controls: { type: 'array', items: CONTROL, description: 'Controls (empty clears).' }, presets: { type: 'array', items: PRESET, description: 'Presets (empty clears).' } }, ['op', 'controls'])\n\t]\n};\n\nfunction describeElement(node: VectorNode, ancestors: string[]) {\n\tconst effects = (node.effects ?? []).map((e) => ({\n\t\tid: e.id,\n\t\ttype: e.type,\n\t\tnumericParams: Object.fromEntries(Object.entries(e.params as unknown as Record<string, unknown>).filter(([, v]) => typeof v === 'number'))\n\t}));\n\treturn {\n\t\tid: node.id,\n\t\ttype: node.type,\n\t\t...(node.name ? { name: node.name } : {}),\n\t\t...(ancestors.length ? { parent: ancestors[ancestors.length - 1] } : {}),\n\t\t...(node.visible === false ? { hidden: true } : {}),\n\t\t...(node.type === 'path' && typeof node.fill === 'string' ? { fill: node.fill } : {}),\n\t\t...(node.type === 'path' && typeof node.stroke === 'string' ? { stroke: node.stroke } : {}),\n\t\t...(node.type === 'group' ? { children: node.children.map((c) => c.id) } : {}),\n\t\t...(effects.length ? { effects } : {})\n\t};\n}\n\nconst round = (n: number) => Math.round(n * 10) / 10;\n\n/** The elements of a scene's artwork, as agents see them. */\nexport function describeMotionElements(scene: MotionScene) {\n\treturn [...indexMotionNodes(scene.artwork.nodes).values()].map((e) => ({\n\t\t...describeElement(e.node, e.ancestors),\n\t\t...(e.bounds ? { bounds: { x: round(e.bounds.x), y: round(e.bounds.y), width: round(e.bounds.width), height: round(e.bounds.height) } } : {})\n\t}));\n}\n\n/** A scene's shots with their timing, as agents see them. */\nexport function describeMotionShots(scene: MotionScene) {\n\tconst timeline = compileMotionScene(scene);\n\treturn scene.shots.map((shot, i) => {\n\t\tconst t = timeline.shots[i];\n\t\treturn {\n\t\t\tid: shot.id,\n\t\t\t...(shot.label ? { label: shot.label } : {}),\n\t\t\tstart: t.start,\n\t\t\tend: t.end,\n\t\t\t...(shot.camera ? { camera: shot.camera } : {}),\n\t\t\t...(shot.hold !== undefined ? { hold: shot.hold } : {}),\n\t\t\t...(t.cue !== undefined ? { cue: Math.round(t.cue) } : {}),\n\t\t\t...(t.missedBy !== undefined ? { missedBy: Math.round(t.missedBy) } : {}),\n\t\t\tcommands: shot.run.map((c, index) => {\n\t\t\t\tconst ct = timeline.commands.find((x) => x.shotIndex === i && x.command === index)!;\n\t\t\t\tconst primitive = motionFlairPrimitive(c);\n\t\t\t\treturn { index, ...c, start: ct.start, end: ct.end, ...(primitive ? { flairPrimitive: primitive } : {}) };\n\t\t\t})\n\t\t};\n\t});\n}\n\nconst issueSummary = (issues: readonly MotionIssue[]) => ({\n\terrors: issues.filter((i) => i.severity === 'error').length,\n\twarnings: issues.filter((i) => i.severity === 'warning').length,\n\tnotes: issues.filter((i) => i.severity === 'note').length,\n\tlines: issues.map((i) => `${i.severity}: ${motionIssueLine(i)}`)\n});\n\n/**\n * Agent tools for an `AnimationEditorController`: read the scene (artwork elements, shots with\n * their timing, issues), render a frame, export to Flair, and change it a step at a time. Every\n * write is checked first (unknown ids with \"did you mean\", malformed commands), applies as one\n * undo step, and returns the resulting timing and any new issues. Write tools are hidden while\n * the animation is read-only.\n */\nexport function createAnimationEditorToolProvider(controller: AnimationEditorController, options: AnimationEditorToolProviderOptions = {}): AgentToolProvider {\n\tconst readOnlyReason = (): string | null => {\n\t\tconst r = typeof options.readOnly === 'function' ? options.readOnly() : options.readOnly;\n\t\tif (r) return typeof r === 'string' ? r : 'This animation is read-only.';\n\t\treturn controller.readOnlyReason();\n\t};\n\tconst scene = () => controller.getScene();\n\tconst outcome = (result: MotionEditResult, extra: Record<string, unknown> = {}) => {\n\t\tif (!result.ok) throw new Error(result.error);\n\t\tconst timeline = compileMotionScene(result.scene);\n\t\treturn {\n\t\t\t...extra,\n\t\t\tduration: timeline.duration,\n\t\t\tshots: timeline.shots.map((s) => ({ id: s.id, start: s.start, end: s.end })),\n\t\t\tissues: issueSummary(result.issues),\n\t\t\t...(result.hints.length ? { hints: result.hints } : {})\n\t\t};\n\t};\n\tconst apply = (edits: MotionEdit | MotionEdit[], label: string, extra?: (s: MotionScene) => Record<string, unknown>) => {\n\t\tconst result = controller.apply(edits, label);\n\t\treturn outcome(result, result.ok && extra ? extra(result.scene) : {});\n\t};\n\n\tconst getAnimation: AgentTool = {\n\t\tname: 'get_animation',\n\t\ttitle: 'Read the animation',\n\t\tdescription:\n\t\t\t'Returns the vector animation: its name, artwork size, length (ms), loop mode, the artwork\\'s elements (id, type, name, parent, bounds, solid paints, live effects with their numeric parameters), every shot with its commands and their start/end times (and, where Flair has one, the Flair motion primitive a command plays as \"flairPrimitive\", e.g. \"entrance.pop\"), Flair controls, and a summary of issues. Use the ids it returns with the write tools.',\n\t\tinputSchema: object({ includeElements: { type: 'boolean', description: 'Include the artwork\\'s elements (default true).' } }),\n\t\tannotations: { title: 'Read the animation', ...READ },\n\t\thandler: ({ includeElements = true }) => {\n\t\t\tconst s = scene();\n\t\t\tconst reason = readOnlyReason();\n\t\t\treturn {\n\t\t\t\tname: s.name,\n\t\t\t\t...(s.description ? { description: s.description } : {}),\n\t\t\t\tartwork: { width: s.artwork.width, height: s.artwork.height },\n\t\t\t\tduration: compileMotionScene(s).duration,\n\t\t\t\tloop: s.loop ?? 'none',\n\t\t\t\t...(s.trigger ? { trigger: s.trigger } : {}),\n\t\t\t\t...(s.target ? { target: s.target } : {}),\n\t\t\t\t...(includeElements ? { elements: describeMotionElements(s) } : {}),\n\t\t\t\tshots: describeMotionShots(s),\n\t\t\t\t...(s.clips ? { clips: Object.fromEntries(Object.entries(s.clips).map(([name, c]) => [name, { ...(c.description ? { description: c.description } : {}), commands: c.run.length, length: Math.round(motionClipLayout(s, name, '$').length) }])) } : {}),\n\t\t\t\t...(s.controls ? { controls: s.controls } : {}),\n\t\t\t\t...(s.presets ? { presets: s.presets } : {}),\n\t\t\t\tissues: issueSummary(controller.getState().issues),\n\t\t\t\t...(reason ? { readOnly: reason } : {})\n\t\t\t};\n\t\t}\n\t};\n\n\tconst getShot: AgentTool = {\n\t\tname: 'get_shot',\n\t\ttitle: 'Read one shot',\n\t\tdescription: 'Returns one shot as stored (id, label, camera, run, hold) with its start/end and each command\\'s start/end in ms.',\n\t\tinputSchema: object({ shot: SHOT_ID }, ['shot']),\n\t\tannotations: { title: 'Read one shot', ...READ },\n\t\thandler: ({ shot }) => {\n\t\t\tconst found = describeMotionShots(scene()).find((s) => s.id === shot);\n\t\t\tif (!found) throw new Error(`There is no shot \"${shot}\"; the shots are ${scene().shots.map((s) => `\"${s.id}\"`).join(', ') || 'none yet'}.`);\n\t\t\treturn found;\n\t\t}\n\t};\n\n\tconst findElements: AgentTool = {\n\t\tname: 'find_animation_elements',\n\t\ttitle: 'Find artwork elements',\n\t\tdescription: 'Finds artwork elements whose id or name contains the text (case-insensitive). Returns their id, type, name, parent, bounds, paints and live effects.',\n\t\tinputSchema: object({ query: { type: 'string', minLength: 1, description: 'Text to look for in ids and names.' }, limit: { type: 'integer', minimum: 1, maximum: 200, description: 'Most results (default 20).' } }, ['query']),\n\t\tannotations: { title: 'Find artwork elements', ...READ },\n\t\thandler: ({ query, limit = 20 }) => {\n\t\t\tconst q = String(query).toLowerCase();\n\t\t\tconst all = describeMotionElements(scene());\n\t\t\tconst elements = all.filter((e) => e.id.toLowerCase().includes(q) || ('name' in e && String(e.name).toLowerCase().includes(q)));\n\t\t\treturn { elements: elements.slice(0, limit), total: elements.length };\n\t\t}\n\t};\n\n\tconst checkAnimation: AgentTool = {\n\t\tname: 'check_animation',\n\t\ttitle: 'Check the animation',\n\t\tdescription:\n\t\t\t'Lists the animation\\'s problems: each with a stable code (unknown-target, overlap, out-of-frame, too-fast, enter-visible…), severity (error / warning / note), the shot and command index it is in, the node ids it is about, measured vs needed values, and a message saying how to fix it.',\n\t\tinputSchema: object({}),\n\t\tannotations: { title: 'Check the animation', ...READ },\n\t\thandler: () => {\n\t\t\tconst issues = controller.getState().issues;\n\t\t\treturn { ...issueSummary(issues), issues };\n\t\t}\n\t};\n\n\tconst renderFrame: AgentTool = {\n\t\tname: 'render_animation_frame',\n\t\ttitle: 'Render a frame',\n\t\tdescription:\n\t\t\t'Draws the animation at one moment (or, with times, several moments as one labelled contact sheet) without changing it, to check it: standalone SVG by default, or a PNG image (format \"png\") when the host can rasterize. Give a time in ms, or a shot and where in it.',\n\t\tinputSchema: object({\n\t\t\ttime: MS('Time from the start'),\n\t\t\tshot: { ...SHOT_ID, description: 'Render a moment of this shot instead of \"time\".' },\n\t\t\tat: { type: 'string', enum: ['start', 'middle', 'end'], description: 'With shot: which moment (default end: everything drawn, before the next shot).' },\n\t\t\tformat: { type: 'string', enum: ['svg', 'png'], description: 'svg (default) or png (only when the host supports it).' },\n\t\t\tonion_skin: object(\n\t\t\t\t{\n\t\t\t\t\tbefore: { type: 'integer', minimum: 0, maximum: 12, description: 'Ghost frames before the moment (default 2).' },\n\t\t\t\t\tafter: { type: 'integer', minimum: 0, maximum: 12, description: 'Ghost frames after it (default 0).' },\n\t\t\t\t\tspacing: { anyOf: [{ type: 'number', exclusiveMinimum: 0 }, { type: 'string', enum: ['commands'] }], description: 'Ms between ghosts (default 83, every other frame at 24 fps), or \"commands\" for the moments commands start and end.' }\n\t\t\t\t},\n\t\t\t\t[],\n\t\t\t\t'Draw faded frames either side of the moment, to see motion in one picture.'\n\t\t\t),\n\t\t\ttimes: { type: 'array', items: { type: 'number', minimum: 0 }, minItems: 2, maxItems: 16, description: 'Several moments (ms) to draw as one contact sheet, each labelled with its time and shot, instead of one frame. Overrides time and shot.' },\n\t\t\tcolumns: { type: 'integer', minimum: 1, maximum: 8, description: 'With times: frames a row (default about square).' },\n\t\t\tmotion_paths: { anyOf: [{ type: 'boolean' }, { type: 'array', items: { type: 'string', minLength: 1 } }], description: 'Draw where nodes travel (dashed, with a dot where each change starts or ends): true for every node whose place changes, or a list of ids.' }\n\t\t}),\n\t\tannotations: { title: 'Render a frame', ...READ },\n\t\thandler: async ({ time, shot, at = 'end', format = 'svg', onion_skin, motion_paths, times, columns }) => {\n\t\t\tconst s = scene();\n\t\t\tlet t = time ?? controller.getState().time;\n\t\t\tif (shot !== undefined) {\n\t\t\t\tconst timing = compileMotionScene(s).shots.find((x) => x.id === shot);\n\t\t\t\tif (!timing) throw new Error(`There is no shot \"${shot}\"; the shots are ${s.shots.map((x) => `\"${x.id}\"`).join(', ') || 'none yet'}.`);\n\t\t\t\tt = at === 'start' ? timing.start : at === 'middle' ? (timing.commandsStart + timing.commandsEnd) / 2 : Math.max(timing.start, timing.end - 1);\n\t\t\t}\n\t\t\tif (Array.isArray(motion_paths)) {\n\t\t\t\tconst known = new Set(describeMotionElements(s).map((e) => e.id));\n\t\t\t\tfor (const id of motion_paths) if (!known.has(id)) throw new Error(`There is no element ${namedWithSuggestion(id, known)} to draw a motion path for.`);\n\t\t\t}\n\t\t\tconst overlays = { ...(onion_skin ? { onionSkin: onion_skin } : {}), ...(motion_paths ? { motionPaths: motion_paths } : {}) };\n\t\t\tif (times) {\n\t\t\t\tconst sheet = motionContactSheetSvg(s, times, { pretty: false, ...overlays, ...(columns ? { columns } : {}) });\n\t\t\t\tif (format === 'png') {\n\t\t\t\t\tif (!options.rasterize) throw new Error('This host cannot make PNG images; call render_animation_frame with format \"svg\".');\n\t\t\t\t\tconst size = /width=\"(\\d+)\" height=\"(\\d+)\"/.exec(sheet)!;\n\t\t\t\t\tconst image = await options.rasterize(sheet, { width: Number(size[1]), height: Number(size[2]) });\n\t\t\t\t\treturn { content: [{ type: 'image', data: image.data, mimeType: image.mimeType }] };\n\t\t\t\t}\n\t\t\t\treturn { times, svg: sheet };\n\t\t\t}\n\t\t\tconst svg = controller.toSvg(t, { pretty: false, ...overlays });\n\t\t\tif (format === 'png') {\n\t\t\t\tif (!options.rasterize) throw new Error('This host cannot make PNG images; call render_animation_frame with format \"svg\".');\n\t\t\t\tconst image = await options.rasterize(svg, { width: s.artwork.width, height: s.artwork.height });\n\t\t\t\treturn { content: [{ type: 'image', data: image.data, mimeType: image.mimeType }] };\n\t\t\t}\n\t\t\treturn { time: t, svg };\n\t\t}\n\t};\n\n\tconst CURVES_DESCRIPTION =\n\t\t'Write cubic-bezier easings (ease, ease-in, ease-out, ease-in-out, back eases, custom curves) as one change with ease: [x1, y1, x2, y2] (default true). Needs Flair 0.36 or later; false samples them into linear steps for older Flair.';\n\tconst FLAIR_DESCRIPTION =\n\t\t'The Flair version to export for (default 0.39): springs and stepped time need 0.39, behaviours 0.38, cubic-bezier curves 0.36; older versions get those sampled into linear steps.';\n\tconst BEHAVIORS_DESCRIPTION =\n\t\t'Write pulses, shakes, teeters, waves, wiggles and colour pulses as one change with a Flair behavior, so they play exactly (default true; needs Flair 0.38 or later). False samples them into linear steps for older Flair.';\n\n\tconst getTimingGrid: AgentTool = {\n\t\tname: 'get_timing_grid',\n\t\ttitle: 'Read the beat grid and narration',\n\t\tdescription:\n\t\t\t'Returns the beats (number, time in ms, bar and beat in the bar) and narration words (index, text, start, end) between two times, to cue shots to with \"at\". Also says which shot plays at each. Without a beat grid or narration, that part is empty and says how to add one.',\n\t\tinputSchema: object({\n\t\t\tfrom: { type: 'number', minimum: 0, description: 'From this time, ms (default 0).' },\n\t\t\tto: { type: 'number', minimum: 0, description: 'Up to this time, ms (default: the end of the animation, or of the narration if later).' },\n\t\t\tlimit: { type: 'integer', minimum: 1, maximum: 1000, description: 'At most this many beats and words each (default 200).' }\n\t\t}),\n\t\tannotations: { title: 'Read the beat grid and narration', ...READ },\n\t\thandler: ({ from = 0, to, limit = 200 }) => {\n\t\t\tconst s = scene();\n\t\t\tconst timeline = compileMotionScene(s);\n\t\t\tconst words = s.narration?.words ?? [];\n\t\t\tconst end = to ?? Math.max(timeline.duration, words.length ? (words[words.length - 1].end ?? words[words.length - 1].start) : 0);\n\t\t\tconst shotAt = (ms: number) => timeline.shots.find((x) => ms >= x.start && ms < x.end)?.id;\n\t\t\tconst beats: { beat: number; ms: number; bar: number; beatInBar: number; shot?: string }[] = [];\n\t\t\tif (s.beat && s.beat.bpm > 0) {\n\t\t\t\tconst first = Math.max(0, Math.ceil(motionBeatAt(s.beat, from).beat - 1e-9));\n\t\t\t\tfor (let b = first; beats.length < limit; b++) {\n\t\t\t\t\tconst ms = motionBeatTime(s.beat, b);\n\t\t\t\t\tif (ms > end) break;\n\t\t\t\t\tconst at = motionBeatAt(s.beat, ms);\n\t\t\t\t\tconst shot = shotAt(ms);\n\t\t\t\t\tbeats.push({ beat: b, ms: Math.round(ms), bar: at.bar, beatInBar: at.beatInBar, ...(shot ? { shot } : {}) });\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst listed = words\n\t\t\t\t.map((w, index) => ({ index, text: w.text, start: w.start, ...(w.end !== undefined ? { end: w.end } : {}), ...(shotAt(w.start) ? { shot: shotAt(w.start) } : {}) }))\n\t\t\t\t.filter((w) => w.start >= from && w.start <= end)\n\t\t\t\t.slice(0, limit);\n\t\t\treturn {\n\t\t\t\tfrom,\n\t\t\t\tto: Math.round(end),\n\t\t\t\t...(s.beat ? { grid: s.beat, beats } : { beats: [], hint: 'No beat grid: set_animation_settings with { \"beat\": { \"bpm\": 120 } }.' }),\n\t\t\t\t...(words.length ? { words: listed } : { words: [], narrationHint: 'No narration: set_animation_settings with { \"narration\": { \"words\": [{ \"text\", \"start\" }, …] } }.' })\n\t\t\t};\n\t\t}\n\t};\n\n\tconst getMotionPath: AgentTool = {\n\t\tname: 'get_motion_path',\n\t\ttitle: 'Read where a node travels',\n\t\tdescription:\n\t\t\t'Returns where a node\\'s centre is over time, in document units (sampled), and where it is each time a change that moves it starts or ends. Use it to check a path, spacing or arc without reading pictures; render_animation_frame with motion_paths draws it.',\n\t\tinputSchema: object({\n\t\t\tnode: { type: 'string', minLength: 1, description: 'Element id from get_animation.' },\n\t\t\tfrom: { type: 'number', minimum: 0, description: 'From this time, ms (default 0).' },\n\t\t\tto: { type: 'number', minimum: 0, description: 'To this time, ms (default the end).' },\n\t\t\tstep: { type: 'number', exclusiveMinimum: 0, description: 'Ms between samples (default 33; at most 400 samples).' }\n\t\t}, ['node']),\n\t\tannotations: { title: 'Read where a node travels', ...READ },\n\t\thandler: ({ node, from, to, step }) => {\n\t\t\tconst s = scene();\n\t\t\tconst ids = describeMotionElements(s).map((e) => e.id);\n\t\t\tif (!ids.includes(node)) throw new Error(`There is no element ${namedWithSuggestion(node, ids)}.`);\n\t\t\treturn motionPath(s, node, { from, to, step });\n\t\t}\n\t};\n\n\tconst exportFlairMotion: AgentTool = {\n\t\tname: 'export_flair_motion',\n\t\ttitle: 'Export as Flair vector motion',\n\t\tdescription:\n\t\t\t'Returns the animation as a Flair SvgMotion ({ svg, animate }) that Flair\\'s SvgPlayer plays, plus its hold, how many changes were sampled into linear steps, and notes on anything not carried over.',\n\t\tinputSchema: object({\n\t\t\tfps: { type: 'number', minimum: 1, maximum: 120, description: 'Sampling rate for changes Flair cannot express exactly (default: the scene\\'s fps, else 30).' },\n\t\t\tcurves: { type: 'boolean', description: CURVES_DESCRIPTION },\n\t\t\tbehaviors: { type: 'boolean', description: BEHAVIORS_DESCRIPTION },\n\t\t\tflair: { type: 'string', pattern: '^\\\\d+\\\\.\\\\d+(\\\\.\\\\d+)?$', description: FLAIR_DESCRIPTION }\n\t\t}),\n\t\tannotations: { title: 'Export as Flair vector motion', ...READ },\n\t\thandler: ({ fps, curves, behaviors, flair }) => controller.toFlairMotion({ ...(fps ? { fps } : {}), ...(curves === undefined ? {} : { curves }), ...(behaviors === undefined ? {} : { behaviors }), ...(flair ? { flair } : {}) })\n\t};\n\n\tconst exportLottie: AgentTool = {\n\t\tname: 'export_lottie',\n\t\ttitle: 'Export as Lottie',\n\t\tdescription:\n\t\t\t'Returns the animation as Lottie (Bodymovin JSON, v5) for lottie-web and the mobile Lottie players: one shape layer whose groups mirror the artwork, a marker per shot, eased changes as keyframes with bezier easing and the rest sampled. Also returns how many keyframes were sampled and notes on anything not carried over (gradients, dashes, reveal clips, morphs that change point counts).',\n\t\tinputSchema: object({ fps: { type: 'number', minimum: 1, maximum: 120, description: 'Frame rate (default: the scene\\'s fps, else 30).' } }),\n\t\tannotations: { title: 'Export as Lottie', ...READ },\n\t\thandler: ({ fps }) => toLottie(scene(), fps ? { fps } : {})\n\t};\n\n\tconst exportFlairEffect: AgentTool = {\n\t\tname: 'export_flair_effect',\n\t\ttitle: 'Export as a Flair effect',\n\t\tdescription:\n\t\t\t'Returns the animation as a Flair catalog vector effect: { kind: \"vector\", id, name, description, category, tags, motion, hold, presets }, with each colour control declared as a {{name: color}} placeholder. Add it to a Flair catalog or load it in Flair\\'s effect editor.',\n\t\tinputSchema: object({\n\t\t\tid: { type: 'string', pattern: '^[a-z0-9]+(-[a-z0-9]+)*$', description: 'Kebab-case id (default: from the scene\\'s name).' },\n\t\t\tname: { type: 'string', minLength: 1, description: 'Display name (default: the scene\\'s name).' },\n\t\t\tdescription: { type: 'string', description: 'One sentence (default: the scene\\'s description).' },\n\t\t\tcategory: { type: 'string', minLength: 1, description: 'Flair catalog category, e.g. icon, loader, ui, data, text, morph (default icon).' },\n\t\t\ttags: { type: 'array', items: { type: 'string' }, description: 'Search tags (default none).' },\n\t\t\tcurves: { type: 'boolean', description: CURVES_DESCRIPTION },\n\t\t\tbehaviors: { type: 'boolean', description: BEHAVIORS_DESCRIPTION },\n\t\t\tflair: { type: 'string', pattern: '^\\\\d+\\\\.\\\\d+(\\\\.\\\\d+)?$', description: FLAIR_DESCRIPTION }\n\t\t}),\n\t\tannotations: { title: 'Export as a Flair effect', ...READ },\n\t\thandler: (args) => controller.toFlairEffect(args)\n\t};\n\n\tconst setArtworkSvg: AgentTool = {\n\t\tname: 'set_animation_artwork_svg',\n\t\ttitle: 'Replace the artwork with SVG',\n\t\tdescription:\n\t\t\t'Replaces the artwork with an SVG (paths, shapes, groups, gradients; one undo step). Give every element you will animate an id: commands target ids. Shots that name ids the new artwork lacks are refused. Returns the elements.',\n\t\tinputSchema: object({ svg: { type: 'string', minLength: 1, description: 'A standalone <svg> with a viewBox.' } }, ['svg']),\n\t\tannotations: { title: 'Replace the artwork with SVG', ...DESTRUCTIVE },\n\t\thandler: ({ svg }) => {\n\t\t\tlet artwork;\n\t\t\ttry {\n\t\t\t\tartwork = parseVectorSvg(svg);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(`The SVG could not be read: ${(error as Error).message}. Nothing was changed.`);\n\t\t\t}\n\t\t\treturn apply({ op: 'set_artwork', artwork }, 'Replace artwork', (s) => ({ elements: describeMotionElements(s) }));\n\t\t}\n\t};\n\n\tconst importFlairEffect: AgentTool = {\n\t\tname: 'import_flair_effect',\n\t\ttitle: 'Import a Flair effect',\n\t\tdescription:\n\t\t\t'Replaces the whole animation with a Flair vector effect or SvgMotion (one undo step): its SVG becomes the artwork, {{name: color}} placeholders become colour controls, and each Flair step becomes a shot of commands (fade, enter, style, move, rotate, scale, draw, follow, pulse, shake, teeter, wave, wiggle, color-pulse). Returns the shots, the elements, notes on anything not carried over and the issues. With dry_run it only reports what the import would give.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\teffect: { type: 'object', description: 'A Flair catalog vector effect { kind: \"vector\", id, name, motion: { svg, animate }, hold?, presets? }. Give this or \"motion\".' },\n\t\t\t\tmotion: { type: 'object', description: 'A Flair SvgMotion { svg, animate }. Give this or \"effect\".' },\n\t\t\t\tname: { type: 'string', minLength: 1, description: 'Name for the scene (default: the effect\\'s id, else \"from-flair\").' },\n\t\t\t\tdry_run: { type: 'boolean', description: 'Report without replacing anything (default false).' }\n\t\t\t},\n\t\t\t[]\n\t\t),\n\t\tannotations: { title: 'Import a Flair effect', ...DESTRUCTIVE },\n\t\thandler: ({ effect, motion, name, dry_run = false }) => {\n\t\t\tif ((effect === undefined) === (motion === undefined)) throw new Error('Give exactly one of \"effect\" (a Flair vector effect) or \"motion\" (a Flair SvgMotion). Nothing was changed.');\n\t\t\tlet result: FlairImportResult;\n\t\t\ttry {\n\t\t\t\tresult = effect !== undefined ? fromFlairVectorEffect(effect, name ? { name } : {}) : fromFlairSvgMotion(motion, name ? { name } : {});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(`The Flair effect could not be imported: ${(error as Error).message} Nothing was changed.`);\n\t\t\t}\n\t\t\tconst report = { notes: result.notes, issues: issueSummary(result.issues), shots: describeMotionShots(result.scene).map(({ id, start, end, commands }) => ({ id, start, end, commands: commands.length })) };\n\t\t\tif (dry_run) return { dry_run: true, ...report, hint: 'Nothing was replaced; call again without dry_run to import.' };\n\t\t\tconst applied = controller.apply({ op: 'replace_scene', scene: result.scene }, 'Import Flair effect');\n\t\t\treturn outcome(applied, applied.ok ? { ...report, elements: describeMotionElements(result.scene) } : {});\n\t\t}\n\t};\n\n\tconst fitAnimation: AgentTool = {\n\t\tname: 'fit_animation',\n\t\ttitle: 'Fit the animation to a length',\n\t\tdescription:\n\t\t\t'Makes the animation last a given time by setting its shots\\' speed (one undo step): shots in \"keep\" play as they are and the others stretch or squeeze together, keeping their proportions. Returns the new length, each changed shot\\'s speed and the timing. With dry_run it only reports them.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tseconds: { type: 'number', exclusiveMinimum: 0, description: 'The length to fit, in seconds.' },\n\t\t\t\tkeep: { type: 'array', items: SHOT_ID, description: 'Shots that keep their pace, e.g. a logo hold (default none).' },\n\t\t\t\tdry_run: { type: 'boolean', description: 'Report without changing anything (default false).' }\n\t\t\t},\n\t\t\t['seconds']\n\t\t),\n\t\tannotations: { title: 'Fit the animation to a length', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ seconds, keep, dry_run = false }) => {\n\t\t\tconst fit = fitMotionScene(controller.getState().scene, seconds * 1000, { keep: keep ?? [] });\n\t\t\tconst report = { duration: fit.duration, speeds: fit.speeds };\n\t\t\tif (dry_run) return { dry_run: true, ...report, hint: 'Nothing was changed; call again without dry_run to fit.' };\n\t\t\tconst edits = Object.entries(fit.speeds).map(([shot, speed]) => (speed === 1 ? { op: 'update_shot' as const, shot, remove: ['speed' as const] } : { op: 'update_shot' as const, shot, set: { speed } }));\n\t\t\treturn apply(edits, 'Fit to length', () => report);\n\t\t}\n\t};\n\n\tconst setClip: AgentTool = {\n\t\tname: 'set_animation_clip',\n\t\ttitle: 'Define a reusable clip',\n\t\tdescription:\n\t\t\t'Defines, replaces or (with clip null) deletes a named clip: commands written against the target \"$\" that a play command plays on any node, e.g. a \"pop-settle\" or \"attention\" used many times. One undo step. Returns the clip\\'s length and the timing.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tname: { type: 'string', pattern: '^[A-Za-z_][\\\\w-]*$', description: 'Clip name, e.g. \"pop-settle\".' },\n\t\t\t\tclip: {\n\t\t\t\t\tanyOf: [object({ description: { type: 'string', description: 'What it does, in a few words.' }, run: { type: 'array', items: MOTION_COMMAND_SCHEMA, minItems: 1, description: 'Commands, timed as in a shot; target \"$\" for the node it is played on. Clips cannot play clips.' } }, ['run']), { type: 'null' }],\n\t\t\t\t\tdescription: 'The clip, or null to delete it (refused while a play command uses it).'\n\t\t\t\t}\n\t\t\t},\n\t\t\t['name', 'clip']\n\t\t),\n\t\tannotations: { title: 'Define a reusable clip', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ name, clip }) => apply({ op: 'set_clip', name, clip }, clip === null ? 'Delete clip' : 'Set clip', (s) => (clip === null ? { deleted: name } : { clip: name, length: Math.round(motionClipLayout(s, name, '$').length) }))\n\t};\n\n\tconst copyAnimation: AgentTool = {\n\t\tname: 'copy_animation',\n\t\ttitle: 'Copy one node\\'s animation to others',\n\t\tdescription:\n\t\t\t'Copies every command that animates \"from\" (in all shots, or the ones given) so it also animates \"to\": each copy goes right after its original and starts with it. One undo step. Returns how many commands were copied per shot. For motion you will reuse often, a clip (set_animation_clip + play) is tidier.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tfrom: { type: 'string', minLength: 1, description: 'Element id whose commands to copy.' },\n\t\t\t\tto: { type: 'array', items: { type: 'string', minLength: 1 }, minItems: 1, description: 'Element ids to give the same motion.' },\n\t\t\t\tshots: { type: 'array', items: SHOT_ID, description: 'Only these shots (default all).' },\n\t\t\t\tstagger: MS('Start each copy this much after the one before (default 0)')\n\t\t\t},\n\t\t\t['from', 'to']\n\t\t),\n\t\tannotations: { title: 'Copy one node\\'s animation to others', ...WRITE },\n\t\thandler: ({ from, to, shots, stagger }) => {\n\t\t\tconst s = scene();\n\t\t\tconst ids = describeMotionElements(s).map((e) => e.id);\n\t\t\tfor (const id of [from, ...to]) if (!ids.includes(id)) throw new Error(`There is no element ${namedWithSuggestion(id, ids)}. Nothing was changed.`);\n\t\t\tif (to.includes(from)) throw new Error(`\"to\" includes \"${from}\" itself; give other elements. Nothing was changed.`);\n\t\t\tconst only = shots ? new Set<string>(shots) : null;\n\t\t\tif (only) for (const id of only) if (!s.shots.some((x) => x.id === id)) throw new Error(`There is no shot ${namedWithSuggestion(id, s.shots.map((x) => x.id))}. Nothing was changed.`);\n\t\t\tconst copied: Record<string, number> = {};\n\t\t\tconst edits: MotionEdit[] = [];\n\t\t\tfor (const shot of s.shots) {\n\t\t\t\tif (only && !only.has(shot.id)) continue;\n\t\t\t\tconst run: MotionCommand[] = [];\n\t\t\t\tlet n = 0;\n\t\t\t\tfor (const c of shot.run) {\n\t\t\t\t\trun.push(c);\n\t\t\t\t\tif (c.type === 'wait' || !c.targets.includes(from)) continue;\n\t\t\t\t\tconst { delay: _delay, ...rest } = c;\n\t\t\t\t\trun.push({ ...rest, targets: to, with: 'previous', ...(stagger ? { stagger } : {}) } as MotionCommand);\n\t\t\t\t\tn++;\n\t\t\t\t}\n\t\t\t\tif (n) {\n\t\t\t\t\tcopied[shot.id] = n;\n\t\t\t\t\tedits.push({ op: 'update_shot', shot: shot.id, set: { run } });\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!edits.length) throw new Error(`No command animates \"${from}\"${only ? ' in those shots' : ''}; nothing to copy.`);\n\t\t\treturn apply(edits, 'Copy animation', () => ({ copied }));\n\t\t}\n\t};\n\n\tconst insertShots: AgentTool = {\n\t\tname: 'insert_shots',\n\t\ttitle: 'Add shots',\n\t\tdescription: 'Adds shots (one undo step) at a position (default: the end). Returns every shot\\'s new timing and any issues.',\n\t\tinputSchema: object({ shots: { type: 'array', items: SHOT, minItems: 1, description: 'Shots to add.' }, at: { type: 'integer', minimum: 0, description: 'Position, 0 = first (default: the end).' } }, ['shots']),\n\t\tannotations: { title: 'Add shots', ...WRITE },\n\t\thandler: ({ shots, at }) => apply({ op: 'insert_shots', shots, at }, 'Add shots', () => ({ added: shots.map((s: { id: string }) => s.id) }))\n\t};\n\n\tconst updateShot: AgentTool = {\n\t\tname: 'update_shot',\n\t\ttitle: 'Change a shot',\n\t\tdescription: 'Replaces the fields of one shot given in \"set\" (label, camera, run, hold, id) and clears those in \"remove\". Returns the new timing and issues.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tshot: SHOT_ID,\n\t\t\t\tset: object({ id: SHOT.properties!.id, ...SHOT_FIELDS }, [], 'Fields to replace.'),\n\t\t\t\tremove: { type: 'array', items: { type: 'string', enum: ['label', 'camera', 'hold', 'speed', 'at'] }, description: 'Fields to clear.' }\n\t\t\t},\n\t\t\t['shot']\n\t\t),\n\t\tannotations: { title: 'Change a shot', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ shot, set, remove }) => apply({ op: 'update_shot', shot, set, remove }, 'Change shot')\n\t};\n\n\tconst deleteShots: AgentTool = {\n\t\tname: 'delete_shots',\n\t\ttitle: 'Delete shots',\n\t\tdescription: 'Removes shots by id (one undo step). Returns the remaining timing.',\n\t\tinputSchema: object({ shots: { type: 'array', items: SHOT_ID, minItems: 1, description: 'Shot ids.' } }, ['shots']),\n\t\tannotations: { title: 'Delete shots', ...DESTRUCTIVE },\n\t\thandler: ({ shots }) => apply({ op: 'delete_shots', shots }, 'Delete shots')\n\t};\n\n\tconst moveShot: AgentTool = {\n\t\tname: 'move_shot',\n\t\ttitle: 'Reorder a shot',\n\t\tdescription: 'Moves a shot to a new position (0 = first). Returns the new timing.',\n\t\tinputSchema: object({ shot: SHOT_ID, to: { type: 'integer', minimum: 0, description: 'New position, 0 = first.' } }, ['shot', 'to']),\n\t\tannotations: { title: 'Reorder a shot', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ shot, to }) => apply({ op: 'move_shot', shot, to }, 'Move shot')\n\t};\n\n\tconst addCommands: AgentTool = {\n\t\tname: 'add_commands',\n\t\ttitle: 'Add commands to a shot',\n\t\tdescription: 'Adds commands to a shot\\'s run (one undo step), at an index (default: the end). Returns the indexes they got, their timing and any issues.',\n\t\tinputSchema: object({ shot: SHOT_ID, commands: { type: 'array', items: MOTION_COMMAND_SCHEMA, minItems: 1, description: 'Commands to add.' }, at: { type: 'integer', minimum: 0, description: 'Index in the run (default: the end).' } }, ['shot', 'commands']),\n\t\tannotations: { title: 'Add commands to a shot', ...WRITE },\n\t\thandler: ({ shot, commands, at }) => {\n\t\t\tconst before = scene().shots.find((s) => s.id === shot)?.run.length ?? 0;\n\t\t\tconst first = at ?? before;\n\t\t\treturn apply({ op: 'add_commands', shot, commands, at }, 'Add commands', (s) => {\n\t\t\t\tconst shots = describeMotionShots(s);\n\t\t\t\tconst added = shots.find((x) => x.id === shot)!.commands.slice(first, first + commands.length);\n\t\t\t\treturn { added: added.map((c) => ({ index: c.index, type: c.type, start: c.start, end: c.end })) };\n\t\t\t});\n\t\t}\n\t};\n\n\tconst updateCommand: AgentTool = {\n\t\tname: 'update_command',\n\t\ttitle: 'Change a command',\n\t\tdescription: 'Replaces fields of one command (by shot and index) given in \"set\" and clears those in \"remove\". Returns the command as it now stands with its timing.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tshot: SHOT_ID,\n\t\t\t\tcommand: { type: 'integer', minimum: 0, description: 'Index in the shot\\'s run (from get_animation).' },\n\t\t\t\tset: { type: 'object', description: 'Command fields to replace (see add_commands for each type\\'s fields).' },\n\t\t\t\tremove: { type: 'array', items: { type: 'string' }, description: 'Optional fields to clear (e.g. \"delay\").' }\n\t\t\t},\n\t\t\t['shot', 'command']\n\t\t),\n\t\tannotations: { title: 'Change a command', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ shot, command, set, remove }) =>\n\t\t\tapply({ op: 'update_command', shot, command, set, remove }, 'Change command', (s) => ({ command: describeMotionShots(s).find((x) => x.id === shot)!.commands[command] }))\n\t};\n\n\tconst deleteCommands: AgentTool = {\n\t\tname: 'delete_commands',\n\t\ttitle: 'Delete commands',\n\t\tdescription: 'Removes commands from a shot by index (one undo step). Later commands move up. Returns the new timing.',\n\t\tinputSchema: object({ shot: SHOT_ID, commands: { type: 'array', items: { type: 'integer', minimum: 0 }, minItems: 1, description: 'Indexes in the shot\\'s run.' } }, ['shot', 'commands']),\n\t\tannotations: { title: 'Delete commands', ...DESTRUCTIVE },\n\t\thandler: ({ shot, commands }) => apply({ op: 'delete_commands', shot, commands }, 'Delete commands')\n\t};\n\n\tconst moveCommand: AgentTool = {\n\t\tname: 'move_command',\n\t\ttitle: 'Reorder a command',\n\t\tdescription:\n\t\t\t'Moves one command to a new index in its shot\\'s run (0 = first), as one undo step; the others close up around it. A command with \"with\": \"previous\" then starts with its new neighbour. Returns the command\\'s new index, its old one and the shot\\'s timing.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tshot: SHOT_ID,\n\t\t\t\tcommand: { type: 'integer', minimum: 0, description: 'Index of the command in the shot\\'s run (from get_animation).' },\n\t\t\t\tto: { type: 'integer', minimum: 0, description: 'Its new index, 0 = first (at most the last index).' }\n\t\t\t},\n\t\t\t['shot', 'command', 'to']\n\t\t),\n\t\tannotations: { title: 'Reorder a command', ...WRITE },\n\t\thandler: ({ shot, command, to }) =>\n\t\t\tapply({ op: 'move_command', shot, command, to }, 'Move command', (s) => ({ shot, command: to, from: command, commands: describeMotionShots(s).find((x) => x.id === shot)!.commands.map((c) => ({ index: c.index, type: c.type, start: c.start, end: c.end })) }))\n\t};\n\n\tconst setSettings: AgentTool = {\n\t\tname: 'set_animation_settings',\n\t\ttitle: 'Change animation settings',\n\t\tdescription: 'Sets the name, description, loop mode, trigger (click, hover, press or scroll), export frame rate, stepped time, beat grid, narration word timings or target length. Returns the timing.',\n\t\tinputSchema: object(SETTINGS),\n\t\tannotations: { title: 'Change animation settings', ...WRITE_IDEMPOTENT },\n\t\thandler: (args) => apply({ op: 'set_settings', ...args }, 'Change settings')\n\t};\n\n\tconst setControls: AgentTool = {\n\t\tname: 'set_animation_controls',\n\t\ttitle: 'Set Flair controls',\n\t\tdescription:\n\t\t\t'Sets the colour controls (and presets) a Flair effect made from this animation exposes: each control stands for every use of its default colour. Replaces the existing controls; an empty list clears them. Returns the issues.',\n\t\tinputSchema: object({ controls: { type: 'array', items: CONTROL, description: 'Controls (empty clears).' }, presets: { type: 'array', items: PRESET, description: 'Presets (empty clears; omit to keep).' } }, ['controls']),\n\t\tannotations: { title: 'Set Flair controls', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ controls, presets }) => apply({ op: 'set_controls', controls, presets }, 'Set controls')\n\t};\n\n\tconst editAnimation: AgentTool = {\n\t\tname: 'edit_animation',\n\t\ttitle: 'Make several edits at once',\n\t\tdescription:\n\t\t\t'Applies several edits in order as one undo step, all or nothing: if one fails, nothing changes and the error names the op (\"op 2 (add_commands): …\"). A later op can use what an earlier one made: \"$0.indexes[0]\" is the index of the first command op 1 added, \"$last.shot\" the shot the op before changed. Returns each op\\'s outcome (shot, shots, indexes, clip), the timing and issues. With dry_run it only reports them.',\n\t\tinputSchema: object({ ops: { type: 'array', items: EDIT_OP, minItems: 1, description: 'Edits, applied in order.' }, dry_run: { type: 'boolean', description: 'Check without applying (default false).' } }, ['ops']),\n\t\tannotations: { title: 'Make several edits at once', ...WRITE },\n\t\thandler: ({ ops, dry_run = false }) => {\n\t\t\t// Later ops may refer to what earlier ones made (\"$0.indexes[0]\").\n\t\t\tconst refs = resolveMotionEditRefs(controller.getScene(), ops);\n\t\t\tif (!refs.ok) throw new Error(refs.error);\n\t\t\tconst result = controller.apply(refs.edits, 'Edit animation', { dryRun: dry_run });\n\t\t\treturn outcome(result, { outcomes: refs.outcomes, ...(dry_run ? { dry_run: true, hint: 'Nothing was applied; call again without dry_run to apply.' } : {}) });\n\t\t}\n\t};\n\n\tconst writeAnimation: AgentTool = {\n\t\tname: 'write_animation',\n\t\ttitle: 'Replace the animation\\'s shots',\n\t\tdescription:\n\t\t\t'Replaces every shot (and optionally the settings and controls), keeping the artwork, as one undo step. For small changes prefer the per-operation tools. Returns the timing and issues.',\n\t\tinputSchema: object({ shots: { type: 'array', items: SHOT, description: 'All shots, in order.' }, ...SETTINGS, controls: { type: 'array', items: CONTROL, description: 'Colour controls.' }, presets: { type: 'array', items: PRESET, description: 'Presets.' } }, ['shots']),\n\t\tannotations: { title: 'Replace the animation\\'s shots', ...DESTRUCTIVE },\n\t\thandler: ({ shots, controls, presets, ...settings }) => {\n\t\t\tconst current = scene();\n\t\t\tconst next: MotionScene = { ...current, shots };\n\t\t\tconst edits: MotionEdit[] = [{ op: 'replace_scene', scene: next }];\n\t\t\tif (Object.keys(settings).length) edits.push({ op: 'set_settings', ...settings });\n\t\t\tif (controls) edits.push({ op: 'set_controls', controls, presets });\n\t\t\treturn apply(edits, 'Replace animation');\n\t\t}\n\t};\n\n\tconst seekAnimation: AgentTool = {\n\t\tname: 'seek_animation',\n\t\ttitle: 'Show a moment',\n\t\tdescription: 'Moves the playhead the person sees to a time or the start of a shot, and plays or pauses. Does not change the animation. Returns the playhead time and shot.',\n\t\tinputSchema: object({ time: MS('Time from the start'), shot: { ...SHOT_ID, description: 'Go to the start of this shot instead of \"time\".' }, play: { type: 'boolean', description: 'true plays from there, false pauses (default: leave as is).' } }),\n\t\tannotations: { title: 'Show a moment', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ time, shot, play }) => {\n\t\t\tif (shot !== undefined && !controller.seekShot(shot)) throw new Error(`There is no shot \"${shot}\"; the shots are ${scene().shots.map((s) => `\"${s.id}\"`).join(', ') || 'none yet'}.`);\n\t\t\tif (shot === undefined && time !== undefined) controller.seek(time);\n\t\t\tif (play === true) controller.play();\n\t\t\tif (play === false) controller.pause();\n\t\t\tconst state = controller.getState();\n\t\t\treturn { time: state.time, shot: state.currentShot, playing: state.playing };\n\t\t}\n\t};\n\n\tconst undo: AgentTool = {\n\t\tname: 'undo_animation',\n\t\ttitle: 'Undo an animation edit',\n\t\tdescription: 'Undoes the last edit. Returns whether something was undone and its label.',\n\t\tinputSchema: object({}),\n\t\tannotations: { title: 'Undo an animation edit', ...WRITE },\n\t\thandler: () => {\n\t\t\tconst label = controller.getState().undoLabel;\n\t\t\tconst undone = controller.undo();\n\t\t\treturn { undone, ...(undone ? { label } : {}) };\n\t\t}\n\t};\n\n\tconst redo: AgentTool = {\n\t\tname: 'redo_animation',\n\t\ttitle: 'Redo an animation edit',\n\t\tdescription: 'Redoes the last undone edit. Returns whether something was redone and its label.',\n\t\tinputSchema: object({}),\n\t\tannotations: { title: 'Redo an animation edit', ...WRITE },\n\t\thandler: () => {\n\t\t\tconst label = controller.getState().redoLabel;\n\t\t\tconst redone = controller.redo();\n\t\t\treturn { redone, ...(redone ? { label } : {}) };\n\t\t}\n\t};\n\n\tconst reads = [getAnimation, getShot, findElements, getMotionPath, getTimingGrid, checkAnimation, renderFrame, exportFlairMotion, exportFlairEffect, exportLottie, seekAnimation];\n\tconst writes = [setArtworkSvg, setClip, copyAnimation, fitAnimation, importFlairEffect, insertShots, updateShot, deleteShots, moveShot, addCommands, updateCommand, deleteCommands, moveCommand, setSettings, setControls, editAnimation, writeAnimation, undo, redo];\n\n\treturn {\n\t\tid: options.id ?? 'animation',\n\t\tnamespace: options.namespace,\n\t\ttools: () => (readOnlyReason() ? reads : [...reads, ...writes]),\n\t\tsubscribe: (notify) => {\n\t\t\tlet last = readOnlyReason();\n\t\t\treturn controller.subscribe(() => {\n\t\t\t\tconst now = readOnlyReason();\n\t\t\t\tif (now !== last) {\n\t\t\t\t\tlast = now;\n\t\t\t\t\tnotify();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t};\n}\n","/**\n * A short authoring guide for a model writing vector animations with the animation editor's\n * tools. Static, so it caches well as part of a system prompt.\n */\nexport const ANIMATION_EDITOR_AGENT_INSTRUCTIONS = `You animate vector artwork. A scene is artwork (vector paths and groups, each with an id) plus shots.\n\nHow it plays\n- Shots play in order. A shot optionally moves the camera, plays its commands, then holds (default 600 ms).\n- Commands in a shot play one after another; give \"with\": \"previous\" to start one together with the command before, \"delay\" to wait, \"stagger\" to offset several targets.\n- Timing comes from the content: each command has a default length (enter 600 ms, move 700 ms, draw follows the path length). Only set \"duration\" to change the pace.\n- Anything that enters later is hidden until it enters. Things that never enter are visible from the start.\n- Every frame is a pure function of time: the same scene always plays the same frames.\n\nCommands\n- enter (fade, pop, grow, slide, draw) and exit (fade, shrink, slide, undraw) bring things in and out.\n- enter also reveals through a clip over the target's box: wipe (behind an edge travelling \"direction\", default right), iris (from the centre; \"shape\": circle or box) and split (from a line through the middle; \"orientation\": horizontal or vertical). exit wipe hides the same way. Reveals need a width and a height: use draw / undraw for a straight line.\n- draw draws strokes on to a fraction; move, rotate, scale and fade change the pose (about the centre); style blends solid colours and stroke width.\n- Drawing a group of strokes: \"order\": \"sequence\" draws them one after another (a signature, a diagram), \"sortBy\": \"distance\" from \"origin\" reveals outward, \"pace\": \"speed\" keeps one speed; draw with \"comet\": 0.2 sends a short stroke along a path and off the end.\n- Reuse motion: set_animation_clip defines a clip (commands targeting \"$\"), and { \"type\": \"play\", \"clip\": name, \"targets\": [...] } plays it on any nodes (with stagger and speed). copy_animation gives other nodes one node's motion.\n- move takes \"via\" waypoints for a curved, smooth path that passes exactly through each point (steady speed by default); use it instead of chaining moves, which stop at each point.\n- enter also has zoom (settles from larger) and rise (rises a short way, overshooting a touch); pop and zoom take a starting \"scale\".\n- morph turns a shape into another node's shape (keep the target hidden); match does the same for a whole group, part by part (Smart Animate: draw the end state as a second, hidden group whose parts share names with the first); follow moves along a path node (with \"rotate\", moves made meanwhile turn with the path).\n- Emphasis draws the eye and returns to rest: pulse (swell), shake (side to side, or \"axis\": \"vertical\"), teeter (rock), wave (bob, no settling), wiggle (seeded wander; the same seed wanders the same way) and color-pulse (tint and back).\n- Emphasis stacks on other motion: a shake during a slide shakes as it slides. Give move, rotate or scale \"blend\": \"add\" to stack them too (what they add stays); \"blend\": \"replace\" makes a change take over instead.\n- Any command but enter and exit can \"repeat\" (loop, mirror back and forth, or offset to carry on: rotate by 90, repeat 4 is a full turn); \"duration\" is one cycle.\n- Springs (\"spring-gentle\", \"spring-quick\", \"spring-bouncy\", \"spring-slow\" or { \"type\": \"spring\", … }) feel physical; leave \"duration\" out and the spring sets it.\n- To time shots to music or a voiceover: set a \"beat\" grid or \"narration\" word timings with set_animation_settings, read them with get_timing_grid, and give a shot \"at\": { \"beat\": n } or { \"word\": i }. The shot before holds until the cue; check_animation warns when a cue is missed.\n- \"steps\": 12 (on a command, or for the whole scene with set_animation_settings) holds poses \"on twos\" for a hand-drawn look. \"geometric\": true on scale or a camera zooms at an even rate.\n- Commands share their names and defaults with Flair's motion primitives (get_animation shows each one's \"flairPrimitive\"), and emphasis, reveals and follows export to Flair exactly.\n- effect tweens a numeric parameter of a live path effect already on the node (twist angle, wiggle time, zig zag size).\n\nWorking method\n1. get_animation to learn the element ids (set_animation_artwork_svg first if there is no artwork: give every element you will animate an id; or import_flair_effect to start from a Flair effect and edit it).\n2. Plan a few shots, each one idea. Add them with insert_shots (add_commands, update_command, move_command and delete_commands refine a shot), or edit_animation to make several edits as one step (dry_run first when unsure).\n- In edit_animation, a later op can use what an earlier one made: \"$0.indexes[0]\" (the first command op 1 added), \"$last.shot\".\n3. To hit a length, fit_animation (keep the shots whose pace matters). check_animation and fix every error and warning; render_animation_frame (shot + \"end\") to look at the result, or with \"times\" for a contact sheet of several moments; add onion_skin or motion_paths to see the motion in one picture, or get_motion_path for the numbers.\n- For something the viewer plays (a button, a toggle, a step-by-step explainer), set \"trigger\" with set_animation_settings: click plays the next shot on each click and then starts over (make the last shot put things back for a toggle), hover or press plays and rewinds, scroll scrubs.\n4. To make a reusable Flair effect, set_animation_controls (colour controls stand for every use of their default colour) and export_flair_effect.\n\nKeep motion purposeful: one thing moving at a time reads best, ease-out for arrivals, ease-in for exits, and hold long enough to see each result.`;\n","import { ANIMATION_EASING_LABELS, ANIMATION_EASING_PRESETS, evaluateEasing, resolveEasing, springSettleMs, type AnimationEasing } from '../animation/easing.js';\nimport type { JsonSchema } from '../tools/schema.js';\nimport { compileMotionScene, indexMotionNodes, motionBeatAt, motionBeatTime, motionCueTime } from './compile.js';\nimport type { MotionEdit } from './edit.js';\nimport { fitMotionScene, type MotionFitOptions } from './fit.js';\nimport { MOTION_COMMAND_SCHEMA } from './tools.js';\nimport { motionFlairPrimitive, type MotionCommand, type MotionCommandType, type MotionCue, type MotionNarration, type MotionScene } from './types.js';\n\n/**\n * Helpers for hand-editing UIs (React's and Svelte's command inspector, ease picker, cue picker,\n * scrubber and stage picking). They hold the logic both bindings share, so the components stay\n * thin and alike. The command form is generated from `MOTION_COMMAND_SCHEMA`, the same schema\n * the agent tools take, so people and agents see the same fields, limits and descriptions.\n */\n\n/** How a command field is edited. */\nexport type MotionFieldKind = 'targets' | 'node' | 'enum' | 'number' | 'integer' | 'boolean' | 'text' | 'color' | 'point' | 'scale' | 'ease';\n\nexport interface MotionFieldSpec {\n\tname: string;\n\tkind: MotionFieldKind;\n\tlabel: string;\n\tdescription: string;\n\trequired: boolean;\n\t/** For `enum`. */\n\toptions?: readonly string[];\n\tmin?: number;\n\tmax?: number;\n\t/** Unit shown next to a number: `ms`, `units`, `°`, `Hz`, `fps`, `×` or `0–1`. */\n\tunit?: string;\n\t/** `main` (what it does) or `timing` (when and how fast). */\n\tgroup: 'main' | 'timing';\n}\n\nconst TIMING = new Set(['duration', 'delay', 'stagger', 'with', 'ease', 'repeat', 'repeatMode', 'steps', 'note']);\nconst COLORS = new Set(['fill', 'stroke', 'color']);\nconst NODES = new Set(['into', 'path']);\n\nfunction branch(type: MotionCommandType): JsonSchema | undefined {\n\treturn (MOTION_COMMAND_SCHEMA.oneOf ?? []).find((b) => (b.properties?.type as JsonSchema | undefined)?.const === type);\n}\n\nfunction unitOf(type: MotionCommandType, name: string): string | undefined {\n\tif (name === 'duration' || name === 'delay' || name === 'stagger') return 'ms';\n\tif (name === 'steps') return 'fps';\n\tif (name === 'frequency') return 'Hz';\n\tif (name === 'repeat' || name === 'count') return '×';\n\tif (name === 'distance' || name === 'strokeWidth') return 'units';\n\tif (name === 'angle') return '°';\n\tif (name === 'amount') return type === 'pulse' ? '×' : 'units';\n\tif (name === 'rotate' && type === 'wiggle') return '°';\n\tif ((name === 'by' || name === 'to') && type === 'rotate') return '°';\n\tif (name === 'scale' || (name === 'to' && type === 'scale')) return '×';\n\tif ((name === 'from' || name === 'to') && (type === 'draw' || type === 'fade' || type === 'follow')) return '0–1';\n\treturn undefined;\n}\n\n/** `repeatMode` → `Repeat mode`. */\nexport function motionFieldLabel(name: string): string {\n\tconst words = name.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase();\n\treturn words.charAt(0).toUpperCase() + words.slice(1);\n}\n\nfunction kindOf(name: string, schema: JsonSchema): MotionFieldKind {\n\tif (name === 'targets') return 'targets';\n\tif (name === 'ease') return 'ease';\n\tif (schema.enum) return 'enum';\n\tif (schema.anyOf) return 'scale';\n\tif (schema.type === 'object') return 'point';\n\tif (schema.type === 'boolean') return 'boolean';\n\tif (schema.type === 'integer') return 'integer';\n\tif (schema.type === 'number') return 'number';\n\tif (COLORS.has(name)) return 'color';\n\tif (NODES.has(name)) return 'node';\n\treturn 'text';\n}\n\n/**\n * The fields a command type takes, in schema order (main fields first, then timing), each with\n * how to edit it, its limits and unit. Generated from `MOTION_COMMAND_SCHEMA`.\n */\nexport function motionCommandFields(type: MotionCommandType): MotionFieldSpec[] {\n\tconst schema = branch(type);\n\tif (!schema?.properties) return [];\n\tconst required = new Set(schema.required ?? []);\n\tconst fields = Object.entries(schema.properties)\n\t\t.filter(([name]) => name !== 'type')\n\t\t.map(([name, s]): MotionFieldSpec => {\n\t\t\tconst kind = kindOf(name, s);\n\t\t\tconst min = typeof s.minimum === 'number' ? s.minimum : typeof s.exclusiveMinimum === 'number' ? s.exclusiveMinimum : undefined;\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\tkind,\n\t\t\t\tlabel: motionFieldLabel(name),\n\t\t\t\tdescription: s.description ?? '',\n\t\t\t\trequired: required.has(name),\n\t\t\t\t...(s.enum ? { options: s.enum.map(String) } : {}),\n\t\t\t\t...(min !== undefined ? { min } : {}),\n\t\t\t\t...(typeof s.maximum === 'number' ? { max: s.maximum } : {}),\n\t\t\t\t...(unitOf(type, name) ? { unit: unitOf(type, name) } : {}),\n\t\t\t\tgroup: TIMING.has(name) ? 'timing' : 'main'\n\t\t\t};\n\t\t});\n\treturn [...fields.filter((f) => f.group === 'main'), ...fields.filter((f) => f.group === 'timing')];\n}\n\nexport type MotionFieldInput = { set: unknown } | { remove: true } | { error: string };\n\n/**\n * Turns what a person typed into a field into a value to `set`, a field to `remove` (an empty\n * optional field) or an `error` to show. Numbers are checked against the field's limits.\n */\nexport function parseMotionFieldInput(field: MotionFieldSpec, raw: string | boolean | readonly string[] | { x: string; y: string }): MotionFieldInput {\n\tif (field.kind === 'boolean') return raw === true ? { set: true } : { remove: true };\n\tif (field.kind === 'targets') {\n\t\tconst ids = (Array.isArray(raw) ? raw : String(raw).split(',')).map((s) => String(s).trim()).filter(Boolean);\n\t\treturn ids.length ? { set: ids } : { error: 'Pick at least one target.' };\n\t}\n\tif (field.kind === 'point' || (field.kind === 'scale' && typeof raw === 'object' && !Array.isArray(raw))) {\n\t\tconst p = raw as { x: string; y: string };\n\t\tif (p.x.trim() === '' && p.y.trim() === '') return field.required ? { error: `${field.label} is required.` } : { remove: true };\n\t\tconst x = Number(p.x);\n\t\tconst y = Number(p.y);\n\t\tif (!Number.isFinite(x) || !Number.isFinite(y)) return { error: `${field.label} needs a number for x and for y.` };\n\t\treturn { set: { x, y } };\n\t}\n\tconst text = String(raw).trim();\n\tif (text === '') return field.required ? { error: `${field.label} is required.` } : { remove: true };\n\tif (field.kind === 'number' || field.kind === 'integer' || field.kind === 'scale') {\n\t\tconst n = Number(text);\n\t\tif (!Number.isFinite(n)) return { error: `${field.label} must be a number${field.unit ? ` (${field.unit})` : ''}.` };\n\t\tif (field.kind === 'integer' && !Number.isInteger(n)) return { error: `${field.label} must be a whole number.` };\n\t\tif (field.min !== undefined && n < field.min) return { error: `${field.label} must be at least ${field.min}.` };\n\t\tif (field.max !== undefined && n > field.max) return { error: `${field.label} must be at most ${field.max}.` };\n\t\treturn { set: n };\n\t}\n\tif (field.kind === 'enum' && field.options && !field.options.includes(text)) return { error: `${field.label} must be one of ${field.options.join(', ')}.` };\n\treturn { set: text };\n}\n\n/** The `update_command` edit for one field input, or the error to show. */\nexport function motionFieldEdit(shot: string, command: number, field: MotionFieldSpec, raw: Parameters<typeof parseMotionFieldInput>[1]): MotionEdit | { error: string } {\n\tconst input = parseMotionFieldInput(field, raw);\n\tif ('error' in input) return input;\n\tif ('remove' in input) return { op: 'update_command', shot, command, remove: [field.name] };\n\treturn { op: 'update_command', shot, command, set: { [field.name]: input.set } };\n}\n\n/**\n * A new command of `type` on `targets`, with its required fields filled from the artwork (the\n * first hidden shape to morph into, the first path to follow, the first effect parameter to\n * tween). Returns an error when the artwork has nothing to fill one with.\n */\nexport function defaultMotionCommand(type: MotionCommandType, targets: readonly string[], scene: MotionScene): MotionCommand | { error: string } {\n\tif (type === 'wait') return { type: 'wait', duration: 500 };\n\tif (!targets.length) return { error: 'Pick a target first: click an element on the stage.' };\n\tconst nodes = [...indexMotionNodes(scene.artwork.nodes).values()];\n\tconst other = (pred: (e: (typeof nodes)[number]) => boolean) => nodes.find((e) => !targets.includes(e.node.id) && pred(e))?.node.id;\n\tconst base = { targets: [...targets] };\n\tswitch (type) {\n\t\tcase 'scale':\n\t\t\treturn { type, ...base, to: 1.2 };\n\t\tcase 'fade':\n\t\t\treturn { type, ...base, to: 0.5 };\n\t\tcase 'move':\n\t\t\treturn { type, ...base, by: { x: 40, y: 0 } };\n\t\tcase 'rotate':\n\t\t\treturn { type, ...base, by: 90 };\n\t\tcase 'style':\n\t\t\treturn { type, ...base, fill: '#f59e0b' };\n\t\tcase 'morph': {\n\t\t\tconst into = other((e) => e.node.type === 'path' && e.node.visible === false) ?? other((e) => e.node.type === 'path');\n\t\t\treturn into ? { type, ...base, into } : { error: 'Morph needs another shape to become; draw one (it can stay hidden).' };\n\t\t}\n\t\tcase 'match': {\n\t\t\tconst into = other((e) => e.node.type === 'group' && e.node.visible === false) ?? other((e) => e.node.type === 'group');\n\t\t\treturn into ? ({ type, ...base, into } as MotionCommand) : { error: 'Match needs another group to become; group the end state (it can stay hidden).' };\n\t\t}\n\t\tcase 'play': {\n\t\t\tconst clip = Object.keys(scene.clips ?? {})[0];\n\t\t\treturn clip ? { type, ...base, clip } : { error: 'Play needs a clip; define one first (set_animation_clip), with \"$\" as its target.' };\n\t\t}\n\t\tcase 'follow': {\n\t\t\tconst path = other((e) => e.node.type === 'path' && e.node.visible === false) ?? other((e) => e.node.type === 'path');\n\t\t\treturn path ? { type, ...base, path } : { error: 'Follow needs a path to travel along; draw one (it can stay hidden).' };\n\t\t}\n\t\tcase 'effect': {\n\t\t\tfor (const id of targets) {\n\t\t\t\tconst node = nodes.find((e) => e.node.id === id)?.node;\n\t\t\t\tfor (const effect of node?.effects ?? []) {\n\t\t\t\t\tconst param = Object.entries(effect.params as unknown as Record<string, unknown>).find(([, v]) => typeof v === 'number');\n\t\t\t\t\tif (param) return { type, ...base, effect: effect.id, param: param[0], to: (param[1] as number) + 1 };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { error: 'Effect needs a target with a live path effect (wiggle, twist, zig zag…).' };\n\t\t}\n\t\tdefault:\n\t\t\treturn { type, ...base } as MotionCommand;\n\t}\n}\n\n/** A short line for a command in a list: `enter pop · ring, badge`. */\nexport function motionCommandSummary(command: MotionCommand): string {\n\tconst c = command as unknown as Record<string, unknown>;\n\tconst what = [command.type, typeof c.style === 'string' ? c.style : ''].filter(Boolean).join(' ');\n\tif (command.type === 'wait') return `wait ${command.duration} ms`;\n\tconst extra = typeof c.into === 'string' ? ` → ${c.into}` : typeof c.path === 'string' ? ` along ${c.path}` : '';\n\treturn `${what} · ${(command.targets ?? []).join(', ')}${extra}`;\n}\n\n/** The commands of a shot as a list UI shows them. */\nexport function motionCommandRows(scene: MotionScene, shotId: string) {\n\tconst index = scene.shots.findIndex((s) => s.id === shotId);\n\tif (index < 0) return [];\n\tconst timeline = compileMotionScene(scene);\n\treturn scene.shots[index].run.map((command, i) => {\n\t\tconst t = timeline.commands.find((c) => c.shotIndex === index && c.command === i);\n\t\tconst primitive = motionFlairPrimitive(command);\n\t\treturn { index: i, command, summary: motionCommandSummary(command), start: t?.start ?? 0, end: t?.end ?? 0, ...(primitive ? { flairPrimitive: primitive } : {}) };\n\t});\n}\n\n/** Edits that put a copy of a command right after it. */\nexport function duplicateMotionCommandEdit(scene: MotionScene, shot: string, command: number): MotionEdit {\n\tconst run = scene.shots.find((s) => s.id === shot)?.run ?? [];\n\treturn { op: 'add_commands', shot, commands: run[command] ? [structuredClone(run[command])] : [], at: command + 1 };\n}\n\n// ---------------------------------------------------------------------------------------------\n// Easing\n\n/** The ease picker's choices: `default` (the command type's own), every preset, then `custom`. */\nexport const MOTION_EASE_CHOICES: readonly { value: string; label: string }[] = [\n\t{ value: '', label: 'Default' },\n\t...ANIMATION_EASING_PRESETS.map((p) => ({ value: p, label: ANIMATION_EASING_LABELS[p] }))\n];\n\n/** The picker value for an easing: `''` for none, the preset name, else `custom`. */\nexport function motionEaseKey(ease: AnimationEasing | undefined | null): string {\n\tif (ease === undefined || ease === null) return '';\n\treturn typeof ease === 'string' ? ease : 'custom';\n}\n\nexport interface MotionEasingCurve {\n\t/** Samples of the eased value from u = 0 to 1. */\n\tpoints: { u: number; v: number }[];\n\t/** The lowest and highest eased value (below 0 or above 1 when the curve overshoots). */\n\tmin: number;\n\tmax: number;\n\t/** The length the curve was sampled over: a spring's settle time, else `durationMs`. */\n\tdurationMs: number;\n}\n\n/** Samples an easing (`evaluateEasing`) for a preview; springs are sampled until they settle. */\nexport function motionEasingCurve(ease: AnimationEasing | string | undefined | null, samples = 48, durationMs = 1000): MotionEasingCurve {\n\tconst resolved = resolveEasing(ease);\n\tconst ms = resolved !== 'hold' && resolved.type === 'spring' ? springSettleMs(resolved) : durationMs;\n\tconst n = Math.max(2, Math.floor(samples));\n\tconst points: { u: number; v: number }[] = [];\n\tfor (let i = 0; i <= n; i++) {\n\t\tconst u = i / n;\n\t\tpoints.push({ u, v: resolved === 'hold' ? (i === n ? 1 : 0) : evaluateEasing(ease, u, ms) });\n\t}\n\tconst values = points.map((p) => p.v);\n\treturn { points, min: Math.min(0, ...values), max: Math.max(1, ...values), durationMs: ms };\n}\n\n/** An SVG path (`d`) of an easing curve in a `width` × `height` box, overshoot included. */\nexport function motionEasingPath(curve: MotionEasingCurve, width: number, height: number, pad = 4): string {\n\tconst span = curve.max - curve.min || 1;\n\tconst f = (n: number) => String(Math.round(n * 100) / 100);\n\treturn curve.points\n\t\t.map((p, i) => `${i ? 'L' : 'M'}${f(pad + p.u * (width - 2 * pad))} ${f(pad + (1 - (p.v - curve.min) / span) * (height - 2 * pad))}`)\n\t\t.join(' ');\n}\n\n/** Where 0 and 1 fall on a curve preview's y axis (for guide lines). */\nexport function motionEasingGuides(curve: MotionEasingCurve, height: number, pad = 4): { zero: number; one: number } {\n\tconst span = curve.max - curve.min || 1;\n\tconst y = (v: number) => pad + (1 - (v - curve.min) / span) * (height - 2 * pad);\n\treturn { zero: y(0), one: y(1) };\n}\n\n// ---------------------------------------------------------------------------------------------\n// Stage picking\n\ninterface ElementLike {\n\tgetAttribute(name: string): string | null;\n\tparentElement: ElementLike | null;\n}\n\n/**\n * The artwork node a click landed on: the nearest element (from `target` up to `root`) whose\n * id is a node of the scene. Onion-skin ghosts and motion-path overlays carry no node ids, so\n * clicks on them pick nothing.\n */\nexport function motionNodeAtElement(scene: MotionScene, target: ElementLike | null, root?: ElementLike | null): string | null {\n\tconst ids = indexMotionNodes(scene.artwork.nodes);\n\tfor (let el = target; el && el !== root; el = el.parentElement) {\n\t\tconst id = el.getAttribute('id');\n\t\tif (id && ids.has(id)) return id;\n\t}\n\treturn null;\n}\n\nconst escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Marks the nodes `ids` in stage SVG with `data-picked` and outlines them. */\nexport function highlightMotionSvg(svg: string, ids: readonly string[], color = '#f43f5e'): string {\n\tif (!ids.length) return svg;\n\tlet out = svg;\n\tfor (const id of ids) {\n\t\tconst escaped = id.replace(/&/g, '&').replace(/\"/g, '"');\n\t\tout = out.replace(new RegExp(` id=\"${escapeRegExp(escaped)}\"`), ` id=\"${escaped}\" data-picked=\"\"`);\n\t}\n\treturn out.replace(/(<svg\\b[^>]*>)/, `$1<style>[data-picked]{filter:drop-shadow(0 0 1px #fff) drop-shadow(0 0 3px ${color}) drop-shadow(0 0 3px ${color})}</style>`);\n}\n\n// ---------------------------------------------------------------------------------------------\n// Time ruler, fit, cues and narration\n\n/** Ticks for a time ruler `width` px wide: a step that leaves at least `minGap` px between labels. */\nexport function motionRulerTicks(duration: number, width: number, minGap = 56): { time: number; label: string; major: boolean }[] {\n\tconst span = Math.max(1, duration);\n\tconst steps = [100, 250, 500, 1000, 2000, 5000, 10000, 30000, 60000];\n\tconst step = steps.find((s) => (s / span) * Math.max(1, width) >= minGap) ?? steps[steps.length - 1];\n\tconst ticks: { time: number; label: string; major: boolean }[] = [];\n\tfor (let t = 0; t <= span + 1e-6; t += step / 2) {\n\t\tconst major = Math.round(t / (step / 2)) % 2 === 0;\n\t\tticks.push({ time: t, major, label: major ? `${step < 1000 ? (t / 1000).toFixed(step < 500 ? 2 : 1) : String(Math.round(t / 1000))}s` : '' });\n\t}\n\treturn ticks;\n}\n\n/**\n * The edits that fit a scene to `ms` (`fitMotionScene`): one `update_shot` per shot whose speed\n * changes, so applied together they are one undo step. Throws with the reason when it can't fit.\n */\nexport function fitMotionSceneEdits(scene: MotionScene, ms: number, options: MotionFitOptions = {}): MotionEdit[] {\n\tconst fit = fitMotionScene(scene, ms, options);\n\treturn fit.scene.shots.flatMap((shot, i): MotionEdit[] => {\n\t\tconst before = scene.shots[i].speed;\n\t\tif (before === shot.speed) return [];\n\t\treturn shot.speed === undefined ? [{ op: 'update_shot', shot: shot.id, remove: ['speed'] }] : [{ op: 'update_shot', shot: shot.id, set: { speed: shot.speed } }];\n\t});\n}\n\n/** A cue picker's value for a cue: `beat:4`, `word:2`, `ms:1200` or `''` for none. */\nexport function motionCueKey(cue: MotionCue | undefined): string {\n\tif (!cue) return '';\n\tif (typeof cue.beat === 'number') return `beat:${cue.beat}`;\n\tif (typeof cue.word === 'number') return `word:${cue.word}`;\n\tif (typeof cue.ms === 'number') return `ms:${cue.ms}`;\n\treturn '';\n}\n\n/** The cue a picker value names, or undefined for none. */\nexport function motionCueFromKey(key: string): MotionCue | undefined {\n\tconst m = /^(beat|word|ms):(-?\\d+(?:\\.\\d+)?)$/.exec(key);\n\tif (!m) return undefined;\n\treturn { [m[1]]: Number(m[2]) } as MotionCue;\n}\n\n/**\n * The cues a shot can start on: every beat of the scene's grid up to a little past the end, and\n * every narration word, each labelled with its time.\n */\nexport function motionCueChoices(scene: MotionScene, limit = 256): { value: string; label: string; time: number }[] {\n\tconst choices: { value: string; label: string; time: number }[] = [];\n\tconst s = (ms: number) => `${(ms / 1000).toFixed(2)} s`;\n\tconst end = Math.max(compileMotionScene(scene).duration, ...(scene.narration?.words.map((w) => w.end ?? w.start) ?? [0])) + 2000;\n\tif (scene.beat && scene.beat.bpm > 0) {\n\t\tfor (let beat = 0; choices.length < limit; beat++) {\n\t\t\tconst time = motionBeatTime(scene.beat, beat);\n\t\t\tif (time > end) break;\n\t\t\tif (time < 0) continue;\n\t\t\tconst at = motionBeatAt(scene.beat, time);\n\t\t\tchoices.push({ value: `beat:${beat}`, label: `Beat ${beat} (bar ${at.bar}.${at.beatInBar}) · ${s(time)}`, time });\n\t\t}\n\t}\n\tscene.narration?.words.forEach((w, i) => {\n\t\tif (choices.length < limit * 2) choices.push({ value: `word:${i}`, label: `Word ${i} “${w.text}” · ${s(w.start)}`, time: w.start });\n\t});\n\treturn choices;\n}\n\n/** When a shot's cue falls (ms), or undefined. */\nexport function motionShotCueTime(scene: MotionScene, cue: MotionCue | undefined): number | undefined {\n\treturn cue ? motionCueTime(scene, cue) : undefined;\n}\n\n/** Narration as text, a word a line: `<start ms> <word>`. */\nexport function formatMotionNarration(narration: MotionNarration | undefined): string {\n\treturn (narration?.words ?? []).map((w) => `${w.start} ${w.text}`).join('\\n');\n}\n\n/** Reads narration typed a word a line (`<start ms> <word>`); empty text clears it. */\nexport function parseMotionNarration(text: string): { narration: MotionNarration | null } | { error: string } {\n\tconst lines = text.split('\\n').map((l) => l.trim()).filter(Boolean);\n\tif (!lines.length) return { narration: null };\n\tconst words: MotionNarration['words'] = [];\n\tfor (const [i, line] of lines.entries()) {\n\t\tconst m = /^(\\d+(?:\\.\\d+)?)\\s+(.+)$/.exec(line);\n\t\tif (!m) return { error: `Line ${i + 1} (\"${line}\") should be a start time in ms and a word, e.g. \"1200 hello\".` };\n\t\tconst start = Number(m[1]);\n\t\tif (words.length && start < words[words.length - 1].start) return { error: `Line ${i + 1} starts before the word above it; keep the words in time order.` };\n\t\twords.push({ text: m[2], start });\n\t}\n\treturn { narration: { words } };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DO,IAAM,kBAA4C,CAAC,SAAS,SAAS,SAAS,QAAQ;AA4QtF,IAAM,qBAAqB;AAuK3B,IAAM,uBAAqD;AAAA,EACjE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AACO,IAAM,sBAAmD,CAAC,QAAQ,OAAO,QAAQ,SAAS,QAAQ,QAAQ,QAAQ,QAAQ,QAAQ,OAAO;AACzI,IAAM,gBAAgB,CAAC,WAAW,KAAK;AACvC,IAAM,sBAAsB,CAAC,QAAQ,UAAU,QAAQ;AACvD,IAAM,qBAAiD,CAAC,QAAQ,UAAU,SAAS,UAAU,MAAM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Q,CAAC,UAAK,EAAE,IAAI,eAAO,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,EAAE,MAAM,CAAC;AAAA,EACnI,CAAC;AACD,SAAO;AACR;AAGO,SAAS,kBAAkB,OAAoB,KAAgD;AACrG,SAAO,MAAM,cAAc,OAAO,GAAG,IAAI;AAC1C;AAGO,SAAS,sBAAsB,WAAgD;AACrF,UAAQ,WAAW,SAAS,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,EAAE,KAAK,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,IAAI;AAC7E;AAGO,SAAS,qBAAqB,MAAyE;AAC7G,QAAM,QAAQ,KAAK,MAAM,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,OAAO;AAClE,MAAI,CAAC,MAAM,OAAQ,QAAO,EAAE,WAAW,KAAK;AAC5C,QAAM,QAAkC,CAAC;AACzC,aAAW,CAAC,GAAG,IAAI,KAAK,MAAM,QAAQ,GAAG;AACxC,UAAM,IAAI,2BAA2B,KAAK,IAAI;AAC9C,QAAI,CAAC,EAAG,QAAO,EAAE,OAAO,QAAQ,IAAI,CAAC,MAAM,IAAI,iEAAiE;AAChH,UAAM,QAAQ,OAAO,EAAE,CAAC,CAAC;AACzB,QAAI,MAAM,UAAU,QAAQ,MAAM,MAAM,SAAS,CAAC,EAAE,MAAO,QAAO,EAAE,OAAO,QAAQ,IAAI,CAAC,kEAAkE;AAC1J,UAAM,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CAAC;AAAA,EACjC;AACA,SAAO,EAAE,WAAW,EAAE,MAAM,EAAE;AAC/B;","names":["command","command","command","end","duration","ease","order","opacity","shotIndex","command","command","rest","TRANSFORM_PROPS","round","command","round","track","command","command","command"]}
|
|
1
|
+
{"version":3,"sources":["../../src/animation-editor/types.ts","../../src/animation-editor/issues.ts","../../src/animation-editor/parse.ts","../../src/animation-editor/match.ts","../../src/animation-editor/smooth.ts","../../src/animation-editor/compile.ts","../../src/animation-editor/evaluate.ts","../../src/animation-editor/onion.ts","../../src/animation-editor/check.ts","../../src/animation-editor/edit.ts","../../src/animation-editor/fit.ts","../../src/animation-editor/flair.ts","../../src/animation-editor/flair-import.ts","../../src/animation-editor/lottie.ts","../../src/animation-editor/controller.ts","../../src/animation-editor/tools.ts","../../src/animation-editor/instructions.ts","../../src/animation-editor/form.ts"],"sourcesContent":["import type { AnimationEasing } from '../animation/easing.js';\nimport type { AnimationLoopMode } from '../animation/evaluate.js';\nimport type { VectorDocument } from '../vector/types.js';\n\n/**\n * A vector animation as plain JSON: a piece of vector artwork (the editor's `VectorDocument`,\n * as the vector editor draws it) and the shots that bring it to life.\n *\n * Shots, not timelines: a shot frames the camera, plays its commands and holds. Timing comes\n * from the content (each command has a sensible default length, and drawing a line takes as\n * long as the line is long), so there are no keyframes to manage. The same scene plays the\n * same frames every time: every frame is a pure function of time.\n */\nexport interface MotionScene {\n\t/** Format version (always 1). */\n\tversion: 1;\n\t/** A short name, e.g. `logo-reveal`. */\n\tname: string;\n\tdescription?: string;\n\t/** The artwork in its resting state. Commands target its node ids. */\n\tartwork: VectorDocument;\n\tshots: MotionShot[];\n\t/** Playback past the end: stop (`none`, default), `loop` or `ping-pong`. */\n\tloop?: AnimationLoopMode;\n\t/**\n\t * Plays in answer to the viewer instead of on its own (exported to Flair's player):\n\t * - `click`: nothing plays until the viewer clicks; each click plays the next shot, and after the\n\t * last one a click plays the first again, so a last shot that puts things back makes a toggle.\n\t * - `hover` / `press`: plays forward while the pointer is over (or down on) it, and back when it leaves.\n\t * - `scroll`: scrubs through the scene as it scrolls through the viewport.\n\t * The editor previews it played through; `loop` does not apply.\n\t */\n\ttrigger?: MotionTrigger;\n\t/** Frame rate used to sample motion that a target format cannot express exactly (default 30). */\n\tfps?: number;\n\t/**\n\t * Stepped time for every command that gives none: changes hold on a grid of this many frames\n\t * per second (\"on twos\" at 12), for a hand-drawn look. Default: smooth.\n\t */\n\tsteps?: number;\n\t/** A beat grid to cue shots to (`MotionShot.at.beat`): music or a voiceover's rhythm. */\n\tbeat?: MotionBeatGrid;\n\t/** A voiceover's words with their times, to cue shots to (`MotionShot.at.word`). */\n\tnarration?: MotionNarration;\n\t/** Wanted length in seconds `[min, max]`; `check` warns outside it. */\n\ttarget?: [number, number];\n\t/**\n\t * Reusable motion: named command lists written against the target `\"$\"`, played on any\n\t * node with a `play` command (a \"pop and settle\" or \"attention\" you use many times).\n\t */\n\tclips?: Record<string, MotionClip>;\n\t/**\n\t * Properties that follow other properties: a background moving at half the speed of the\n\t * foreground (parallax), a wheel turning as it rolls. Each adds to what its target's commands do.\n\t */\n\tdrivers?: MotionDriver[];\n\t/**\n\t * Motion blur on the stage and in rendered frames (not in exports): each frame averages a few\n\t * moments across the shutter, more for faster motion.\n\t */\n\tmotionBlur?: MotionBlur;\n\t/** Parameters a Flair effect made from this scene exposes (see `toFlairVectorEffect`). */\n\tcontrols?: MotionControl[];\n\t/** Named sets of control values. */\n\tpresets?: MotionPreset[];\n}\n\n/** What the viewer does to play a triggered scene (see `MotionScene.trigger`). */\nexport type MotionTrigger = 'click' | 'hover' | 'press' | 'scroll';\nexport const MOTION_TRIGGERS: readonly MotionTrigger[] = ['click', 'hover', 'press', 'scroll'];\n\n/** A rectangle of the artwork, in document units. */\nexport interface MotionRect {\n\tx: number;\n\ty: number;\n\twidth: number;\n\theight: number;\n}\n\n/**\n * Where the camera looks: a rectangle, or the id of a node to frame (with `padding` around\n * its bounds, default 24). The camera eases there over `ms` (default 1000; the first shot cuts).\n */\nexport type MotionCamera = (MotionRect | { frame: string; padding?: number }) & {\n\tease?: AnimationEasing;\n\tms?: number;\n\t/** Zoom at a steady rate (the size changes by the same factor each moment) instead of linearly. */\n\tgeometric?: boolean;\n};\n\n/** A steady beat: `bpm` beats a minute, the first at `offset` ms, `meter` beats a bar. */\nexport interface MotionBeatGrid {\n\tbpm: number;\n\t/** When beat 0 falls, ms (default 0). */\n\toffset?: number;\n\t/** Beats in a bar (default 4), for reading beats as bar and beat. */\n\tmeter?: number;\n}\n\n/** A voiceover: its words in order, each with when it is said (ms), from a TTS or speech-to-text word timing. */\nexport interface MotionNarration {\n\twords: { text: string; start: number; end?: number }[];\n}\n\n/** When a shot is cued to start: on a beat, on a narration word, or at a time. */\nexport interface MotionCue {\n\t/** Beat number on the scene's beat grid, from 0 (fractions for off-beats: 2.5 is the \"and\" of beat 3). */\n\tbeat?: number;\n\t/** Index of a word in the scene's narration, from 0. */\n\tword?: number;\n\t/** A time in ms. */\n\tms?: number;\n}\n\n/** One beat of the animation. */\nexport interface MotionShot {\n\t/** Stable id (unique in the scene), e.g. `intro`. */\n\tid: string;\n\t/** What happens in this shot, in a few words (shown on the timeline). */\n\tlabel?: string;\n\t/** Omit to keep the current framing. */\n\tcamera?: MotionCamera;\n\t/**\n\t * Start on a cue: a beat, a narration word or a time. The shot before holds until then; a\n\t * cue that comes before the shot before has ended is missed (`check` says by how much).\n\t * Give one of `beat`, `word` or `ms`.\n\t */\n\tat?: MotionCue;\n\t/** Commands, played one after another (unless a command says `with: \"previous\"`). */\n\trun: MotionCommand[];\n\t/** Milliseconds to hold after the commands finish (default 600). */\n\thold?: number;\n\t/**\n\t * Plays the whole shot this many times as fast (default 1): its camera move, delays,\n\t * durations, staggers and hold all scale by 1 / speed. `fit_animation` sets it to fit a length.\n\t */\n\tspeed?: number;\n}\n\n/** Fields every command takes. */\nexport interface MotionCommandBase {\n\t/** Node ids from the artwork (groups animate as one). */\n\ttargets: string[];\n\t/** Length in ms for each target, one cycle when repeating (each type has a default; `draw` follows the path length; a spring `ease` lasts until it settles). */\n\tduration?: number;\n\t/** Wait this many ms before starting (default 0). */\n\tdelay?: number;\n\t/** Start each further target this many ms after the one before (default 0). */\n\tstagger?: number;\n\t/** `after` (default) starts when the commands before it finish; `previous` starts with the command before. */\n\twith?: 'after' | 'previous';\n\t/** An easing; a spring with no `duration` lasts until it settles. */\n\tease?: AnimationEasing;\n\t/** Why this command is here (for people and agents reading the scene). */\n\tnote?: string;\n\t/**\n\t * Play the change this many times (a whole number, default 1); `duration` is one cycle. Not\n\t * for `enter`, `exit` or `wait`.\n\t */\n\trepeat?: number;\n\t/**\n\t * How repeats follow each other: `loop` (default) starts each cycle afresh, `mirror` plays\n\t * every other one backwards, `offset` carries on from where the last ended (rotate by 90,\n\t * repeat 4: a full turn). Colours and shapes offset like `loop`.\n\t */\n\trepeatMode?: 'loop' | 'mirror' | 'offset';\n\t/** Stepped time: hold the change on a grid of this many frames per second (default: the scene's `steps`, else smooth). */\n\tsteps?: number;\n}\n\nexport type MotionEnterStyle = 'fade' | 'pop' | 'grow' | 'slide' | 'draw' | 'zoom' | 'rise' | 'wipe' | 'iris' | 'split';\nexport type MotionExitStyle = 'fade' | 'shrink' | 'slide' | 'undraw' | 'wipe';\nexport type MotionDirection = 'up' | 'down' | 'left' | 'right';\n/** The opening an `iris` reveals through. */\nexport type MotionIrisShape = 'circle' | 'box';\n/** The line a `split` opens from. */\nexport type MotionSplitOrientation = 'horizontal' | 'vertical';\n\n/**\n * Brings hidden targets in. Targets entered in a shot are hidden before it. Each style is a\n * Flair motion primitive (`entrance.<style>`) with the same defaults.\n */\nexport interface MotionEnterCommand extends MotionCommandBase, MotionDrawOrder {\n\ttype: 'enter';\n\t/**\n\t * Default `fade`. `draw` draws the outline on, then fades the fill in. `pop` scales up past\n\t * full size and settles; `zoom` settles from larger; `rise` rises a short way with a little\n\t * overshoot. `wipe`, `iris` and `split` reveal the target through a clip over its box (see\n\t * `MotionFrame.clips`), reaching past it far enough to show its whole stroke.\n\t */\n\tstyle?: MotionEnterStyle;\n\t/**\n\t * For `slide`: the direction of travel (default `up`). For `wipe`: the way the edge travels\n\t * (default `right`, which reveals from the left).\n\t */\n\tdirection?: MotionDirection;\n\t/** For `slide` (default 40) and `rise` (default 20): how far in document units. */\n\tdistance?: number;\n\t/** For `pop` (default 0.5) and `zoom` (default 1.6): the starting scale. */\n\tscale?: number;\n\t/** For `iris`: open through a `circle` (default; an ellipse on a box that is not square) or a `box`. */\n\tshape?: MotionIrisShape;\n\t/** For `split`: open up and down from a `horizontal` line through the middle (default), or left and right from a `vertical` one. */\n\torientation?: MotionSplitOrientation;\n}\n\n/** Takes targets out. */\nexport interface MotionExitCommand extends MotionCommandBase, MotionDrawOrder {\n\ttype: 'exit';\n\t/** Default `fade`. `wipe` hides the target behind an edge travelling `direction` (a wipe in, reversed). */\n\tstyle?: MotionExitStyle;\n\t/** For `slide`: the direction of travel (default `down`). For `wipe`: the way the edge travels (default `right`, which hides from the left). */\n\tdirection?: MotionDirection;\n\tdistance?: number;\n}\n\n/**\n * How the strokes of a group (or several paths) draw on or off together. Default: all at once,\n * each over the whole time.\n */\nexport interface MotionDrawOrder {\n\t/** `together` (default) or `sequence`: one stroke after another, each for a time in proportion to its length. */\n\torder?: 'together' | 'sequence';\n\t/** With `together`: `time` (default) gives every stroke the whole time; `speed` draws them all at one speed, so short ones take less. */\n\tpace?: 'time' | 'speed';\n\t/** With `pace: \"speed\"`: `start` (default) starts them together, `end` finishes them together. */\n\talign?: 'start' | 'end';\n\t/** With `sequence`: `document` (default, stacking order) or `distance` from `origin` (a radial reveal). */\n\tsortBy?: 'document' | 'distance';\n\t/** With `sortBy: \"distance\"`: the point (document units) strokes are drawn out from (default the target's centre). */\n\torigin?: { x: number; y: number };\n}\n\n/** Draws a stroke on (or off) between two fractions of its length. */\nexport interface MotionDrawCommand extends MotionCommandBase, MotionDrawOrder {\n\ttype: 'draw';\n\t/**\n\t * A travelling stroke this fraction of the length long (0–1): it runs along the path and off\n\t * the end, instead of drawing it on and leaving it.\n\t */\n\tcomet?: number;\n\t/** Fraction drawn at the end (default 1). */\n\tto?: number;\n\t/** Fraction drawn at the start (default: what is drawn now). */\n\tfrom?: number;\n}\n\n/** Moves targets by an offset, or to a point (their centre lands there). */\nexport interface MotionMoveCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'move';\n\tby?: { x: number; y: number };\n\tto?: { x: number; y: number };\n\t/**\n\t * Points (document units) the centre passes through on the way, in order. The path is\n\t * smooth (velocity carries through each point) and never overshoots a point.\n\t */\n\tvia?: { x: number; y: number }[];\n\t/** With `via`: `even` (default) keeps the speed steady along the path, `equal` gives each leg the same time. */\n\tpacing?: 'even' | 'equal';\n}\n\n/** Turns targets about their centre, by or to an angle in degrees (clockwise). */\nexport interface MotionRotateCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'rotate';\n\tby?: number;\n\tto?: number;\n}\n\n/** Scales targets about their centre (1 = rest size). */\nexport interface MotionScaleCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'scale';\n\tto: number | { x: number; y: number };\n\t/** Grow at a steady rate (the same factor each moment), which reads as an even zoom. */\n\tgeometric?: boolean;\n}\n\n/** Changes opacity (0–1). */\nexport interface MotionFadeCommand extends MotionCommandBase {\n\ttype: 'fade';\n\tto: number;\n}\n\n/** Changes solid paints and stroke width. Colours mix in OKLab. */\nexport interface MotionStyleCommand extends MotionCommandBase {\n\ttype: 'style';\n\tfill?: string;\n\tstroke?: string;\n\tstrokeWidth?: number;\n}\n\n/** Morphs each target into the shape of another node (`into`), which usually stays hidden. */\nexport interface MotionMorphCommand extends MotionCommandBase {\n\ttype: 'morph';\n\tinto: string;\n}\n\n/**\n * Smart Animate: tweens a group into another group (`into`, usually hidden), part by part. Each\n * part of the target takes the shape, paint and place of its partner in `into`, paired by name,\n * then by id (`card-a-title` ↔ `card-b-title`), then by kind in order. Parts with no partner fade\n * out; parts of `into` with no partner do not appear (`check` lists them).\n */\nexport interface MotionMatchCommand extends MotionCommandBase {\n\ttype: 'match';\n\t/** Id of the group (or node) to become. */\n\tinto: string;\n}\n\n/** A reusable piece of motion: commands that target `\"$\"` (whatever `play` names), timed as in a shot. */\nexport interface MotionClip {\n\tdescription?: string;\n\t/** Commands, timed as in a shot; `\"$\"` in `targets` stands for the node played on. Clips cannot play clips. */\n\trun: MotionCommand[];\n}\n\n/** Motion blur: how long the shutter is open and how many moments a frame averages at most. */\nexport interface MotionBlur {\n\t/** Shutter angle in degrees of a frame at the scene's fps (default 180: half a frame; 360 is a whole frame). */\n\tshutter?: number;\n\t/** Most moments a frame averages (default 8, at most 32); fewer for slower motion. */\n\tsamples?: number;\n}\n\n/** Properties a driver reads and drives: offsets (document units), turn (degrees), scales and opacity. */\nexport type MotionDrivenProperty = 'x' | 'y' | 'rotation' | 'scaleX' | 'scaleY' | 'opacity';\nexport const MOTION_DRIVEN_PROPERTIES: readonly MotionDrivenProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'opacity'];\n\n/**\n * One property following another. Both are read as a change from rest (offsets and turns from\n * 0, scales and opacity from 1): the target's property changes by `source change · factor + offset`,\n * clamped to `clamp`, on top of its own commands (added to offsets and turns, multiplied into\n * scales and opacity as 1 + change).\n */\nexport interface MotionDriver {\n\t/** The node that follows. */\n\ttarget: string;\n\tproperty: MotionDrivenProperty;\n\t/** The node and property it follows. */\n\tsource: { node: string; property: MotionDrivenProperty };\n\t/** Default 1 (0.5 moves at half the speed; 360 / (2π·radius) turns a wheel by how far it rolls). */\n\tfactor?: number;\n\t/** Added to the change (default 0). */\n\toffset?: number;\n\t/** Limits the change to `[min, max]`. */\n\tclamp?: [number, number];\n}\n\n/** The placeholder target in a clip's commands. */\nexport const MOTION_CLIP_TARGET = '$';\n\n/** Plays a clip (`scene.clips`) on the targets: its commands, with `\"$\"` standing for each target. */\nexport interface MotionPlayCommand extends MotionCommandBase {\n\ttype: 'play';\n\t/** The clip's name. */\n\tclip: string;\n\t/** Play it this many times as fast (default 1). */\n\tspeed?: number;\n}\n\n/** Moves targets along a path node, centre on the path. */\nexport interface MotionFollowCommand extends MotionCommandBase {\n\ttype: 'follow';\n\t/** Id of a path node in the artwork (it can be hidden). */\n\tpath: string;\n\t/**\n\t * Turn with the path's direction (default false). Moves, shakes and wiggles made during the\n\t * follow then turn with it too: they are offsets from the target's place on the path.\n\t */\n\trotate?: boolean;\n\t/** Fractions of the path's length to travel between (default 0 → 1). */\n\tfrom?: number;\n\tto?: number;\n}\n\n/** Scales up and back, `count` times (draws the eye). */\nexport interface MotionPulseCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'pulse';\n\t/** Extra scale at the peak (default 0.15). */\n\tamount?: number;\n\tcount?: number;\n}\n\n/** Shakes side to side (or up and down), settling. */\nexport interface MotionShakeCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'shake';\n\t/** Distance in document units (default 8). */\n\tamount?: number;\n\tcount?: number;\n\t/** Default `horizontal`. */\n\taxis?: 'horizontal' | 'vertical';\n}\n\n/** Rocks about the centre by `angle` either way, settling (Flair's `emphasis.teeter`). */\nexport interface MotionTeeterCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'teeter';\n\t/** Degrees either way (default 8). */\n\tangle?: number;\n\t/** Rocks (default 3). */\n\tcount?: number;\n}\n\n/** Bobs up and down without settling, like something floating (Flair's `emphasis.wave`). */\nexport interface MotionWaveCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'wave';\n\t/** Height in document units (default 6). */\n\tamount?: number;\n\t/** Bobs (default 2). */\n\tcount?: number;\n}\n\n/**\n * Wanders about its place as smooth seeded noise, easing out of and back to rest (Flair's\n * `emphasis.wiggle`). The same seed always wanders the same way.\n */\nexport interface MotionWiggleCommand extends MotionCommandBase {\n\t/**\n\t * `add` makes the change a layer over the pose instead of a change to it: it stacks on\n\t * whatever else moves the target (a shake on a slide), and what it adds stays once it ends.\n\t * Default `replace` for move, rotate and scale (the later change takes over), `add` for\n\t * pulse, shake, teeter, wave and wiggle.\n\t */\n\tblend?: 'replace' | 'add';\n\ttype: 'wiggle';\n\t/** Up to about this far, in document units (default 6). */\n\tamount?: number;\n\t/** Wanders per second, in Hz (default 3). */\n\tfrequency?: number;\n\t/** Layers of finer detail (default 2). */\n\toctaves?: number;\n\t/** Also turns about the centre by up to about this many degrees (default 0). */\n\trotate?: number;\n\t/** A whole number; default: one picked from the target's id, so each target wanders its own way. */\n\tseed?: number;\n}\n\n/** Tints solid paint toward a colour and back, `count` times (Flair's `emphasis.color-pulse`). */\nexport interface MotionColorPulseCommand extends MotionCommandBase {\n\ttype: 'color-pulse';\n\t/** The tint (default `#f59e0b`). Mixes in OKLab. */\n\tcolor?: string;\n\t/** Which paint (default `fill`). On a group it tints every path in it. */\n\tpaint?: 'fill' | 'stroke';\n\tcount?: number;\n}\n\n/** Tweens a numeric parameter of a live path effect on the target (twist angle, wiggle time, zig zag size…). */\nexport interface MotionEffectCommand extends MotionCommandBase {\n\ttype: 'effect';\n\t/** Id of an effect in the target node's `effects`. */\n\teffect: string;\n\t/** A numeric parameter of that effect, e.g. `angle`. */\n\tparam: string;\n\tto: number;\n}\n\n/** Does nothing for `duration` ms. */\nexport interface MotionWaitCommand {\n\ttype: 'wait';\n\tduration: number;\n\twith?: 'after' | 'previous';\n\tnote?: string;\n}\n\nexport type MotionCommand =\n\t| MotionEnterCommand\n\t| MotionExitCommand\n\t| MotionDrawCommand\n\t| MotionMoveCommand\n\t| MotionRotateCommand\n\t| MotionScaleCommand\n\t| MotionFadeCommand\n\t| MotionStyleCommand\n\t| MotionMorphCommand\n\t| MotionMatchCommand\n\t| MotionPlayCommand\n\t| MotionFollowCommand\n\t| MotionPulseCommand\n\t| MotionShakeCommand\n\t| MotionTeeterCommand\n\t| MotionWaveCommand\n\t| MotionWiggleCommand\n\t| MotionColorPulseCommand\n\t| MotionEffectCommand\n\t| MotionWaitCommand;\n\nexport type MotionCommandType = MotionCommand['type'];\n\nexport const MOTION_COMMAND_TYPES: readonly MotionCommandType[] = [\n\t'enter',\n\t'exit',\n\t'draw',\n\t'move',\n\t'rotate',\n\t'scale',\n\t'fade',\n\t'style',\n\t'morph',\n\t'match',\n\t'play',\n\t'follow',\n\t'pulse',\n\t'shake',\n\t'teeter',\n\t'wave',\n\t'wiggle',\n\t'color-pulse',\n\t'effect',\n\t'wait'\n];\nexport const MOTION_ENTER_STYLES: readonly MotionEnterStyle[] = ['fade', 'pop', 'grow', 'slide', 'draw', 'zoom', 'rise', 'wipe', 'iris', 'split'];\nexport const MOTION_BLENDS = ['replace', 'add'] as const;\nexport const MOTION_REPEAT_MODES = ['loop', 'mirror', 'offset'] as const;\nexport const MOTION_EXIT_STYLES: readonly MotionExitStyle[] = ['fade', 'shrink', 'slide', 'undraw', 'wipe'];\nexport const MOTION_IRIS_SHAPES: readonly MotionIrisShape[] = ['circle', 'box'];\nexport const MOTION_SPLIT_ORIENTATIONS: readonly MotionSplitOrientation[] = ['horizontal', 'vertical'];\nexport const MOTION_DIRECTIONS: readonly MotionDirection[] = ['up', 'down', 'left', 'right'];\n\n/**\n * A colour parameter of the effect made from the scene: it stands for every use of its\n * `default` colour in the artwork and the commands, so recolouring it recolours them all.\n */\nexport interface MotionControl {\n\t/** Identifier, e.g. `accent`. */\n\tname: string;\n\ttype: 'color';\n\t/** A `#rrggbb` colour used in the scene. */\n\tdefault: string;\n\tlabel?: string;\n}\n\nexport interface MotionPreset {\n\tname: string;\n\tvalues: Record<string, string>;\n}\n\n/** Default lengths (ms) of commands that give none. */\nexport const MOTION_DEFAULT_DURATIONS: Readonly<Record<Exclude<MotionCommandType, 'wait' | 'draw'>, number>> = {\n\tenter: 600,\n\texit: 450,\n\tmove: 700,\n\trotate: 700,\n\tscale: 500,\n\tfade: 400,\n\tstyle: 500,\n\tmorph: 900,\n\tmatch: 900,\n\t/** A clip's length comes from its commands (this is only a fallback). */\n\tplay: 600,\n\tfollow: 1400,\n\tpulse: 600,\n\tshake: 500,\n\tteeter: 600,\n\twave: 1000,\n\twiggle: 1500,\n\t'color-pulse': 600,\n\teffect: 900\n};\n\n/** Default hold after a shot's commands (ms). */\nexport const MOTION_DEFAULT_HOLD = 600;\n/** Default camera move (ms). */\nexport const MOTION_CAMERA_MS = 1000;\n/** `draw` lasts `length × MOTION_DRAW_MS_PER_UNIT`, clamped to `MOTION_DRAW_RANGE`. */\nexport const MOTION_DRAW_MS_PER_UNIT = 1.5;\nexport const MOTION_DRAW_RANGE: readonly [number, number] = [500, 2500];\n\n/**\n * The Flair motion primitive (`@pixerate/flair/motion`) a command plays, or undefined when\n * Flair has none (`move`, `scale`, `fade`, `style`, `morph`, `effect`, `wait` are the editor's\n * own). Commands and primitives of the same name take the same parameters and defaults.\n */\nexport function motionFlairPrimitive(command: MotionCommand): string | undefined {\n\tswitch (command.type) {\n\t\tcase 'enter':\n\t\t\treturn `entrance.${command.style ?? 'fade'}`;\n\t\tcase 'exit':\n\t\t\treturn `exit.${command.style ?? 'fade'}`;\n\t\tcase 'pulse':\n\t\tcase 'shake':\n\t\tcase 'teeter':\n\t\tcase 'wave':\n\t\tcase 'wiggle':\n\t\tcase 'color-pulse':\n\t\t\treturn `emphasis.${command.type}`;\n\t\tcase 'rotate':\n\t\t\treturn command.by !== undefined ? 'emphasis.spin' : undefined;\n\t\tcase 'follow':\n\t\t\treturn 'path.follow';\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n","/**\n * Problems with a scene, as data: every issue has a stable `code`, a severity, the shot and\n * command it is in and the ids it is about, beside its prose `message`, so an agent (or a UI)\n * can act on it without parsing sentences.\n */\n\n/** `error`: the scene does not play as written. `warning`: it plays, but probably not as meant. `note`: may well be intended. */\nexport type MotionIssueSeverity = 'error' | 'warning' | 'note';\n\n/** Every issue code with its severity and what it means. */\nexport const MOTION_ISSUE_CODES = {\n\t'no-shots': { severity: 'note', wording: 'The scene has no shots yet.' },\n\t'duplicate-shot-id': { severity: 'error', wording: 'Two shots share an id.' },\n\t'unknown-target': { severity: 'error', wording: 'A command names a node the artwork does not have.' },\n\t'unknown-path': { severity: 'error', wording: 'A follow command names a path the artwork does not have.' },\n\t'not-a-path': { severity: 'error', wording: 'A follow path must be a path node, not a group.' },\n\t'reveal-no-box': { severity: 'warning', wording: 'A wipe, iris or split cannot clip a node with no width or height (a lone straight line), so it fades instead.' },\n\t'driver-cycle': { severity: 'error', wording: 'Drivers follow each other in a loop, so none of them has a value.' },\n\t'unknown-clip': { severity: 'error', wording: 'A play command names a clip the scene does not have.' },\n\t'unknown-shape': { severity: 'error', wording: 'A morph names a shape the artwork does not have.' },\n\t'match-self': { severity: 'error', wording: 'A match turns a group into itself or into a group it holds (or that holds it).' },\n\t'match-unpaired': { severity: 'note', wording: 'Parts of a match\\'s \"into\" group have no partner in the target, so they do not appear.' },\n\t'unknown-effect': { severity: 'error', wording: 'An effect command names an effect the node does not have.' },\n\t'unknown-effect-param': { severity: 'error', wording: 'An effect command names a parameter that is not a number of that effect.' },\n\t'unknown-frame': { severity: 'error', wording: 'A camera frames a node the artwork does not have.' },\n\t'invalid-camera': { severity: 'error', wording: 'A camera rectangle has no area.' },\n\t'invalid-color': { severity: 'error', wording: 'A colour cannot be read.' },\n\t'paint-not-color': { severity: 'warning', wording: 'A style command recolours a gradient or empty paint, which only switches at the end, or a colour pulse has no solid paint to tint.' },\n\t'overlap': { severity: 'warning', wording: 'Two commands change the same property of a node at the same time; the later one wins.' },\n\t'enter-visible': { severity: 'warning', wording: 'A node enters while it is already showing, so it blinks out first.' },\n\t'exit-hidden': { severity: 'warning', wording: 'A node exits or animates while it is hidden.' },\n\t'out-of-frame': { severity: 'warning', wording: 'A node a command animates ends up outside the camera.' },\n\t'too-fast': { severity: 'warning', wording: 'A change is too quick to follow.' },\n\t'spring-cut-short': { severity: 'warning', wording: 'A spring is given a duration shorter than it takes to settle, so it jumps to its end.' },\n\t'unknown-cue': { severity: 'error', wording: 'A shot is cued to a beat with no beat grid, or to a word the narration does not have.' },\n\t'cue-missed': { severity: 'warning', wording: 'A shot starts after its cue, because the shot before runs past it.' },\n\t'trigger-loop': { severity: 'note', wording: 'A scene that plays on a trigger ignores its loop.' },\n\t'click-cue': { severity: 'warning', wording: 'A shot of a click-triggered scene is cued, but clicks decide when its shots start.' },\n\t'click-one-shot': { severity: 'note', wording: 'A click-triggered scene has one shot, so every click replays it.' },\n\t'scene-too-long': { severity: 'warning', wording: 'The scene runs past its target length.' },\n\t'scene-too-short': { severity: 'warning', wording: 'The scene ends before its target length.' },\n\t'unknown-control-color': { severity: 'warning', wording: 'A control stands for a colour the scene never uses.' },\n\t'empty-shot': { severity: 'note', wording: 'A shot neither moves the camera nor runs a command.' },\n\t'camera-aspect': { severity: 'note', wording: 'A camera rectangle has a different shape from the artwork, so it is letterboxed.' }\n} as const satisfies Record<string, { severity: MotionIssueSeverity; wording: string }>;\n\nexport type MotionIssueCode = keyof typeof MOTION_ISSUE_CODES;\n\nexport interface MotionIssue {\n\tcode: MotionIssueCode;\n\tseverity: MotionIssueSeverity;\n\tmessage: string;\n\t/** Id of the shot it is in, when it is in one. */\n\tshot?: string;\n\t/** Index of the command in that shot's `run`. */\n\tcommand?: number;\n\t/** Node ids it is about. */\n\tids?: string[];\n\t/** What was measured, what was needed and in what unit (e.g. 80 vs 120 ms). */\n\tmeasured?: number;\n\tneeded?: number;\n\tunit?: 'ms' | 's' | 'units';\n}\n\nexport function motionIssue(code: MotionIssueCode, message: string, extra: Omit<MotionIssue, 'code' | 'severity' | 'message'> = {}): MotionIssue {\n\treturn { code, severity: MOTION_ISSUE_CODES[code].severity, message, ...extra };\n}\n\n/** A stable key for an issue (code and ids, else code and place), to compare two checks. */\nexport function motionIssueKey(issue: MotionIssue): string {\n\tif (issue.ids?.length) return `${issue.code}:${[...issue.ids].sort().join(',')}`;\n\treturn `${issue.code}@${issue.shot ?? ''}#${issue.command ?? ''}`;\n}\n\n/** One line: `Shot \"intro\", command 2: …`. */\nexport function motionIssueLine(issue: MotionIssue): string {\n\tconst where = issue.shot !== undefined ? `Shot \"${issue.shot}\"${issue.command !== undefined ? `, command ${issue.command + 1}` : ''}: ` : '';\n\treturn `${where}${issue.message}`;\n}\n\n/** Optimal string alignment (Damerau–Levenshtein) distance. */\nfunction editDistance(a: string, b: string): number {\n\tconst d: number[][] = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);\n\tfor (let j = 1; j <= b.length; j++) d[0][j] = j;\n\tfor (let i = 1; i <= a.length; i++) {\n\t\tfor (let j = 1; j <= b.length; j++) {\n\t\t\tconst cost = a[i - 1] === b[j - 1] ? 0 : 1;\n\t\t\td[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);\n\t\t\tif (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);\n\t\t}\n\t}\n\treturn d[a.length][b.length];\n}\n\n/** The candidate closest to `word` (case-insensitive), if it is within a third of its length. */\nexport function suggestName(word: string, candidates: Iterable<string>): string | undefined {\n\tconst w = word.toLowerCase();\n\tlet best: string | undefined;\n\tlet bestDistance = Infinity;\n\tfor (const c of candidates) {\n\t\tconst distance = editDistance(w, c.toLowerCase());\n\t\tif (distance < bestDistance) {\n\t\t\tbest = c;\n\t\t\tbestDistance = distance;\n\t\t}\n\t}\n\treturn best !== undefined && bestDistance <= Math.max(1, Math.floor(word.length / 3)) ? best : undefined;\n}\n\n/** `\"sunn\" (did you mean \"sun\"?)`, or just `\"sunn\"`. */\nexport function namedWithSuggestion(word: string, candidates: Iterable<string>): string {\n\tconst s = suggestName(word, candidates);\n\treturn s !== undefined && s !== word ? `\"${word}\" (did you mean \"${s}\"?)` : `\"${word}\"`;\n}\n","import { isAnimationEasing } from '../animation/easing.js';\nimport { namedWithSuggestion } from './issues.js';\nimport { MOTION_COMMAND_TYPES, MOTION_DIRECTIONS, MOTION_ENTER_STYLES, MOTION_EXIT_STYLES, MOTION_REPEAT_MODES, MOTION_TRIGGERS, MOTION_DRIVEN_PROPERTIES, MOTION_BLENDS, MOTION_IRIS_SHAPES, MOTION_SPLIT_ORIENTATIONS, type MotionCommand, type MotionScene, type MotionShot } from './types.js';\n\n/**\n * Shape checking: whether a value is a well-formed scene, listing every problem at once.\n * Meaning (do the ids exist, does the timing work) is `checkMotionScene`'s job.\n */\n\nexport class MotionSceneFormatError extends Error {\n\treadonly problems: string[];\n\tconstructor(problems: string[]) {\n\t\tsuper(`The scene is not well formed:\\n${problems.map((p) => `- ${p}`).join('\\n')}`);\n\t\tthis.name = 'MotionSceneFormatError';\n\t\tthis.problems = problems;\n\t}\n}\n\nconst SCENE_KEYS = ['version', 'name', 'description', 'artwork', 'shots', 'clips', 'drivers', 'motionBlur', 'loop', 'trigger', 'fps', 'steps', 'beat', 'narration', 'target', 'controls', 'presets'];\nconst SHOT_KEYS = ['id', 'label', 'camera', 'at', 'run', 'hold', 'speed'];\nconst CAMERA_KEYS = ['x', 'y', 'width', 'height', 'frame', 'padding', 'ease', 'ms', 'geometric'];\nconst BASE_KEYS = ['type', 'targets', 'duration', 'delay', 'stagger', 'with', 'ease', 'note', 'repeat', 'repeatMode', 'steps'];\nconst DRAW_ORDER_KEYS = ['order', 'pace', 'align', 'sortBy', 'origin'];\nconst COMMAND_KEYS: Record<string, string[]> = {\n\tenter: [...BASE_KEYS, ...DRAW_ORDER_KEYS, 'style', 'direction', 'distance', 'scale', 'shape', 'orientation'],\n\texit: [...BASE_KEYS, ...DRAW_ORDER_KEYS, 'style', 'direction', 'distance'],\n\tdraw: [...BASE_KEYS, ...DRAW_ORDER_KEYS, 'from', 'to', 'comet'],\n\tmove: [...BASE_KEYS, 'by', 'to', 'via', 'pacing', 'blend'],\n\trotate: [...BASE_KEYS, 'by', 'to', 'blend'],\n\tscale: [...BASE_KEYS, 'to', 'geometric', 'blend'],\n\tfade: [...BASE_KEYS, 'to'],\n\tstyle: [...BASE_KEYS, 'fill', 'stroke', 'strokeWidth'],\n\tmorph: [...BASE_KEYS, 'into'],\n\tmatch: [...BASE_KEYS, 'into'],\n\tplay: ['type', 'targets', 'delay', 'stagger', 'with', 'note', 'clip', 'speed'],\n\tfollow: [...BASE_KEYS, 'path', 'rotate', 'from', 'to'],\n\tpulse: [...BASE_KEYS, 'amount', 'count', 'blend'],\n\tshake: [...BASE_KEYS, 'amount', 'count', 'axis', 'blend'],\n\tteeter: [...BASE_KEYS, 'angle', 'count', 'blend'],\n\twave: [...BASE_KEYS, 'amount', 'count', 'blend'],\n\twiggle: [...BASE_KEYS, 'amount', 'frequency', 'octaves', 'rotate', 'seed', 'blend'],\n\t'color-pulse': [...BASE_KEYS, 'color', 'paint', 'count'],\n\teffect: [...BASE_KEYS, 'effect', 'param', 'to'],\n\twait: ['type', 'duration', 'with', 'note']\n};\n\nconst isObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);\nconst isNum = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v);\nconst isPoint = (v: unknown) => isObject(v) && isNum(v.x) && isNum(v.y);\n\nfunction unknownKeys(value: Record<string, unknown>, known: readonly string[], where: string, problems: string[]) {\n\tfor (const key of Object.keys(value)) if (!known.includes(key)) problems.push(`${where}: unknown field ${namedWithSuggestion(key, known)}.`);\n}\n\n/** Problems with one command's shape (empty when well formed). `where` prefixes each. */\nexport function commandShapeProblems(command: unknown, where: string): string[] {\n\tconst problems: string[] = [];\n\tif (!isObject(command)) return [`${where} must be an object.`];\n\tconst type = command.type;\n\tif (typeof type !== 'string' || !(MOTION_COMMAND_TYPES as readonly string[]).includes(type)) {\n\t\treturn [`${where}: unknown type ${typeof type === 'string' ? namedWithSuggestion(type, MOTION_COMMAND_TYPES) : String(type)}; use one of ${MOTION_COMMAND_TYPES.join(', ')}.`];\n\t}\n\tunknownKeys(command, COMMAND_KEYS[type], `${where} (${type})`, problems);\n\tconst p = (msg: string) => problems.push(`${where} (${type}): ${msg}`);\n\tconst nonNegative = (key: string) => {\n\t\tif (command[key] !== undefined && !(isNum(command[key]) && (command[key] as number) >= 0)) p(`\"${key}\" must be a number of milliseconds ≥ 0.`);\n\t};\n\tconst fraction = (key: string) => {\n\t\tif (command[key] !== undefined && !(isNum(command[key]) && (command[key] as number) >= 0 && (command[key] as number) <= 1)) p(`\"${key}\" must be a fraction from 0 to 1.`);\n\t};\n\tconst optionalNumber = (key: string) => {\n\t\tif (command[key] !== undefined && !isNum(command[key])) p(`\"${key}\" must be a number.`);\n\t};\n\tif (command.with !== undefined && command.with !== 'after' && command.with !== 'previous') p(`\"with\" must be \"after\" or \"previous\".`);\n\tif (DRAW_ORDER_KEYS.some((k) => command[k] !== undefined)) {\n\t\tif ((type === 'enter' && command.style !== 'draw') || (type === 'exit' && command.style !== 'undraw')) p(`\"order\", \"pace\", \"align\", \"sortBy\" and \"origin\" go with drawing: style \"${type === 'enter' ? 'draw' : 'undraw'}\".`);\n\t\tif (command.order !== undefined && command.order !== 'together' && command.order !== 'sequence') p(`\"order\" must be \"together\" or \"sequence\" (one stroke after another).`);\n\t\tif (command.pace !== undefined && command.pace !== 'time' && command.pace !== 'speed') p(`\"pace\" must be \"time\" (each stroke takes the whole time) or \"speed\" (all at one speed).`);\n\t\tif (command.align !== undefined && command.align !== 'start' && command.align !== 'end') p(`\"align\" must be \"start\" or \"end\".`);\n\t\tif (command.sortBy !== undefined && command.sortBy !== 'document' && command.sortBy !== 'distance') p(`\"sortBy\" must be \"document\" or \"distance\".`);\n\t\tif (command.origin !== undefined && !isPoint(command.origin)) p(`\"origin\" must be { \"x\": number, \"y\": number } (document units).`);\n\t}\n\tif (command.note !== undefined && typeof command.note !== 'string') p(`\"note\" must be a string.`);\n\tif (type === 'wait') {\n\t\tif (!isNum(command.duration) || command.duration < 0) p(`\"duration\" must be a number of milliseconds ≥ 0.`);\n\t\treturn problems;\n\t}\n\tif (!Array.isArray(command.targets) || command.targets.length === 0 || !command.targets.every((t) => typeof t === 'string' && t.length > 0)) p(`\"targets\" must be a non-empty list of node ids.`);\n\tnonNegative('duration');\n\tnonNegative('delay');\n\tnonNegative('stagger');\n\tif (command.ease !== undefined && !isAnimationEasing(command.ease)) p(`\"ease\" is not an easing; use a preset such as \"ease-in-out\" or \"spring-bouncy\", or { \"type\": \"cubic-bezier\", … } or { \"type\": \"spring\", … }.`);\n\tif (command.repeat !== undefined) {\n\t\tif (type === 'enter' || type === 'exit') p(`\"repeat\" is not for ${type} (it brings things in or out once); repeat an emphasis or a move instead.`);\n\t\telse if (!(Number.isInteger(command.repeat) && (command.repeat as number) >= 1 && (command.repeat as number) <= 1000)) p(`\"repeat\" must be a whole number from 1 to 1000.`);\n\t}\n\tif (command.blend !== undefined && !(MOTION_BLENDS as readonly unknown[]).includes(command.blend)) p(`\"blend\" must be \"replace\" (the change takes over) or \"add\" (a layer on top).`);\n\tif (command.repeatMode !== undefined && !(MOTION_REPEAT_MODES as readonly unknown[]).includes(command.repeatMode)) p(`\"repeatMode\" must be one of ${MOTION_REPEAT_MODES.join(', ')}.`);\n\tif (command.steps !== undefined && !(isNum(command.steps) && command.steps > 0 && command.steps <= 120)) p(`\"steps\" must be frames per second from above 0 to 120 (12 holds each pose for two frames at 24 fps).`);\n\tswitch (type) {\n\t\tcase 'enter':\n\t\tcase 'exit': {\n\t\t\tconst styles = type === 'enter' ? MOTION_ENTER_STYLES : MOTION_EXIT_STYLES;\n\t\t\tif (command.style !== undefined && !(typeof command.style === 'string' && (styles as readonly string[]).includes(command.style)))\n\t\t\t\tp(`\"style\" must be one of ${styles.join(', ')}${typeof command.style === 'string' ? ` (got ${namedWithSuggestion(command.style, styles)})` : ''}.`);\n\t\t\tif (command.direction !== undefined && !(MOTION_DIRECTIONS as readonly unknown[]).includes(command.direction)) p(`\"direction\" must be one of ${MOTION_DIRECTIONS.join(', ')}.`);\n\t\t\toptionalNumber('distance');\n\t\t\tif (command.scale !== undefined && !(isNum(command.scale) && command.scale >= 0)) p(`\"scale\" must be a number ≥ 0 (the starting scale for pop and zoom).`);\n\t\t\tif (command.shape !== undefined && !(MOTION_IRIS_SHAPES as readonly unknown[]).includes(command.shape)) p(`\"shape\" must be one of ${MOTION_IRIS_SHAPES.join(', ')} (the opening of an iris).`);\n\t\t\tif (command.orientation !== undefined && !(MOTION_SPLIT_ORIENTATIONS as readonly unknown[]).includes(command.orientation)) p(`\"orientation\" must be one of ${MOTION_SPLIT_ORIENTATIONS.join(', ')} (the line a split opens from).`);\n\t\t\tbreak;\n\t\t}\n\t\tcase 'draw':\n\t\t\tfraction('from');\n\t\t\tfraction('to');\n\t\t\tfraction('comet');\n\t\t\tif (command.comet !== undefined && (command.from !== undefined || command.to !== undefined)) p(`\"comet\" runs the whole path; leave out \"from\" and \"to\".`);\n\t\t\tbreak;\n\t\tcase 'move':\n\t\t\tif (command.by === undefined && command.to === undefined) p(`give \"by\" (an offset) or \"to\" (a point).`);\n\t\t\tif (command.by !== undefined && command.to !== undefined) p(`give \"by\" or \"to\", not both.`);\n\t\t\tif (command.by !== undefined && !isPoint(command.by)) p(`\"by\" must be { \"x\": number, \"y\": number }.`);\n\t\t\tif (command.to !== undefined && !isPoint(command.to)) p(`\"to\" must be { \"x\": number, \"y\": number }.`);\n\t\t\tif (command.via !== undefined && !(Array.isArray(command.via) && command.via.length > 0 && command.via.length <= 64 && command.via.every(isPoint))) p(`\"via\" must be a list of 1 to 64 points { \"x\": number, \"y\": number } (document units).`);\n\t\t\tif (command.pacing !== undefined && command.pacing !== 'even' && command.pacing !== 'equal') p(`\"pacing\" must be \"even\" (steady speed) or \"equal\" (each leg the same time).`);\n\t\t\tif (command.pacing !== undefined && command.via === undefined) p(`\"pacing\" goes with \"via\".`);\n\t\t\tbreak;\n\t\tcase 'rotate':\n\t\t\tif (command.by === undefined && command.to === undefined) p(`give \"by\" or \"to\" (degrees).`);\n\t\t\tif (command.by !== undefined && command.to !== undefined) p(`give \"by\" or \"to\", not both.`);\n\t\t\toptionalNumber('by');\n\t\t\toptionalNumber('to');\n\t\t\tbreak;\n\t\tcase 'scale':\n\t\t\tif (!(isNum(command.to) || isPoint(command.to))) p(`\"to\" must be a number or { \"x\": number, \"y\": number }.`);\n\t\t\tif (command.geometric !== undefined && typeof command.geometric !== 'boolean') p(`\"geometric\" must be true or false.`);\n\t\t\tbreak;\n\t\tcase 'fade':\n\t\t\tif (!(isNum(command.to) && command.to >= 0 && command.to <= 1)) p(`\"to\" must be an opacity from 0 to 1.`);\n\t\t\tbreak;\n\t\tcase 'style':\n\t\t\tif (command.fill === undefined && command.stroke === undefined && command.strokeWidth === undefined) p(`give at least one of \"fill\", \"stroke\" or \"strokeWidth\".`);\n\t\t\tif (command.fill !== undefined && typeof command.fill !== 'string') p(`\"fill\" must be a CSS colour.`);\n\t\t\tif (command.stroke !== undefined && typeof command.stroke !== 'string') p(`\"stroke\" must be a CSS colour.`);\n\t\t\tif (command.strokeWidth !== undefined && !(isNum(command.strokeWidth) && command.strokeWidth >= 0)) p(`\"strokeWidth\" must be a number ≥ 0.`);\n\t\t\tbreak;\n\t\tcase 'play':\n\t\t\tif (typeof command.clip !== 'string' || !command.clip) p(`\"clip\" must be the name of one of the scene's clips.`);\n\t\t\tif (command.speed !== undefined && !(isNum(command.speed) && command.speed >= 0.05 && command.speed <= 20)) p(`\"speed\" must be a number from 0.05 to 20 (2 plays the clip twice as fast).`);\n\t\t\tbreak;\n\t\tcase 'morph':\n\t\tcase 'match':\n\t\t\tif (typeof command.into !== 'string' || !command.into) p(`\"into\" must be the id of a ${type === 'match' ? 'group to become' : 'node whose shape to take'}.`);\n\t\t\tbreak;\n\t\tcase 'follow':\n\t\t\tif (typeof command.path !== 'string' || !command.path) p(`\"path\" must be the id of a path node.`);\n\t\t\tif (command.rotate !== undefined && typeof command.rotate !== 'boolean') p(`\"rotate\" must be true or false.`);\n\t\t\tfraction('from');\n\t\t\tfraction('to');\n\t\t\tbreak;\n\t\tcase 'pulse':\n\t\tcase 'shake':\n\t\tcase 'teeter':\n\t\tcase 'wave':\n\t\tcase 'color-pulse':\n\t\t\toptionalNumber('amount');\n\t\t\toptionalNumber('angle');\n\t\t\tif (command.count !== undefined && !(Number.isInteger(command.count) && (command.count as number) >= 1)) p(`\"count\" must be a whole number ≥ 1.`);\n\t\t\tif (command.axis !== undefined && command.axis !== 'horizontal' && command.axis !== 'vertical') p(`\"axis\" must be \"horizontal\" or \"vertical\".`);\n\t\t\tif (command.color !== undefined && typeof command.color !== 'string') p(`\"color\" must be a CSS colour.`);\n\t\t\tif (command.paint !== undefined && command.paint !== 'fill' && command.paint !== 'stroke') p(`\"paint\" must be \"fill\" or \"stroke\".`);\n\t\t\tbreak;\n\t\tcase 'wiggle':\n\t\t\toptionalNumber('amount');\n\t\t\toptionalNumber('rotate');\n\t\t\tif (command.frequency !== undefined && !(isNum(command.frequency) && command.frequency > 0)) p(`\"frequency\" must be a number of Hz > 0.`);\n\t\t\tif (command.octaves !== undefined && !(Number.isInteger(command.octaves) && (command.octaves as number) >= 1 && (command.octaves as number) <= 8)) p(`\"octaves\" must be a whole number from 1 to 8.`);\n\t\t\tif (command.seed !== undefined && !(Number.isInteger(command.seed) && (command.seed as number) >= 0)) p(`\"seed\" must be a whole number ≥ 0.`);\n\t\t\tbreak;\n\t\tcase 'effect':\n\t\t\tif (typeof command.effect !== 'string' || !command.effect) p(`\"effect\" must be the id of one of the node's effects.`);\n\t\t\tif (typeof command.param !== 'string' || !command.param) p(`\"param\" must name a numeric parameter of the effect.`);\n\t\t\tif (!isNum(command.to)) p(`\"to\" must be a number.`);\n\t\t\tbreak;\n\t}\n\treturn problems;\n}\n\n/** Problems with a scene's `clips`: names, and each clip's commands (which may target `\"$\"` but not play clips). */\nexport function clipsShapeProblems(clips: unknown): string[] {\n\tif (!isObject(clips)) return ['Scene: \"clips\" must be an object of named clips { \"pop\": { \"run\": [ … ] } }.'];\n\tconst problems: string[] = [];\n\tfor (const [name, clip] of Object.entries(clips)) {\n\t\tconst where = `Clip \"${name}\"`;\n\t\tif (!/^[A-Za-z_][\\w-]*$/.test(name)) problems.push(`${where}: a clip name is letters, digits, \"_\" or \"-\" (e.g. \"pop-in\").`);\n\t\tif (!isObject(clip) || !Array.isArray(clip.run)) {\n\t\t\tproblems.push(`${where} must be { \"description\"?, \"run\": [commands] }.`);\n\t\t\tcontinue;\n\t\t}\n\t\tunknownKeys(clip, ['description', 'run'], where, problems);\n\t\tif (clip.description !== undefined && typeof clip.description !== 'string') problems.push(`${where}: \"description\" must be a string.`);\n\t\tclip.run.forEach((command, i) => {\n\t\t\tif (isObject(command) && command.type === 'play') problems.push(`${where}, command ${i + 1}: a clip cannot play another clip; copy its commands in instead.`);\n\t\t\telse problems.push(...commandShapeProblems(command, `${where}, command ${i + 1}`));\n\t\t});\n\t}\n\treturn problems;\n}\n\n/** Problems with a scene's `drivers`. */\nexport function driversShapeProblems(drivers: unknown): string[] {\n\tif (!Array.isArray(drivers)) return ['Scene: \"drivers\" must be a list of { target, property, source: { node, property }, factor?, offset?, clamp? }.'];\n\tconst problems: string[] = [];\n\tconst props = MOTION_DRIVEN_PROPERTIES as readonly unknown[];\n\tdrivers.forEach((d, i) => {\n\t\tconst where = `Driver ${i + 1}`;\n\t\tif (!isObject(d)) return void problems.push(`${where} must be an object.`);\n\t\tunknownKeys(d, ['target', 'property', 'source', 'factor', 'offset', 'clamp'], where, problems);\n\t\tif (typeof d.target !== 'string' || !d.target) problems.push(`${where}: \"target\" must be the id of the node that follows.`);\n\t\tif (!props.includes(d.property)) problems.push(`${where}: \"property\" must be one of ${MOTION_DRIVEN_PROPERTIES.join(', ')}.`);\n\t\tif (!isObject(d.source) || typeof d.source.node !== 'string' || !d.source.node || !props.includes(d.source.property)) problems.push(`${where}: \"source\" must be { \"node\": id, \"property\": one of ${MOTION_DRIVEN_PROPERTIES.join(', ')} }.`);\n\t\tif (d.factor !== undefined && !isNum(d.factor)) problems.push(`${where}: \"factor\" must be a number.`);\n\t\tif (d.offset !== undefined && !isNum(d.offset)) problems.push(`${where}: \"offset\" must be a number.`);\n\t\tif (d.clamp !== undefined && !(Array.isArray(d.clamp) && d.clamp.length === 2 && d.clamp.every(isNum) && d.clamp[0] <= d.clamp[1])) problems.push(`${where}: \"clamp\" must be [min, max].`);\n\t});\n\treturn problems;\n}\n\n/** Problems with one shot's shape. */\nexport function shotShapeProblems(shot: unknown, where: string): string[] {\n\tif (!isObject(shot)) return [`${where} must be an object.`];\n\tconst problems: string[] = [];\n\tunknownKeys(shot, SHOT_KEYS, where, problems);\n\tif (typeof shot.id !== 'string' || !/^[A-Za-z0-9_][\\w.-]*$/.test(shot.id)) problems.push(`${where}: \"id\" must be letters, digits, \"_\", \"-\" or \".\" (e.g. \"intro\").`);\n\tconst name = typeof shot.id === 'string' ? `Shot \"${shot.id}\"` : where;\n\tif (shot.label !== undefined && typeof shot.label !== 'string') problems.push(`${name}: \"label\" must be a string.`);\n\tif (shot.hold !== undefined && !(isNum(shot.hold) && shot.hold >= 0)) problems.push(`${name}: \"hold\" must be a number of milliseconds ≥ 0.`);\n\tif (shot.speed !== undefined && !(isNum(shot.speed) && shot.speed >= 0.05 && shot.speed <= 20)) problems.push(`${name}: \"speed\" must be a number from 0.05 to 20 (2 plays it twice as fast).`);\n\tif (shot.at !== undefined) {\n\t\tconst at = shot.at;\n\t\tconst given = isObject(at) ? (['beat', 'word', 'ms'] as const).filter((k) => at[k] !== undefined) : [];\n\t\tif (!isObject(at) || given.length !== 1) problems.push(`${name}: \"at\" must give one of { \"beat\": number }, { \"word\": index } or { \"ms\": number }.`);\n\t\telse {\n\t\t\tunknownKeys(at, ['beat', 'word', 'ms'], `${name} at`, problems);\n\t\t\tconst k = given[0];\n\t\t\tif (!isNum(at[k]) || (at[k] as number) < 0 || (k === 'word' && !Number.isInteger(at[k]))) problems.push(`${name}: \"at.${k}\" must be ${k === 'word' ? 'a word index ≥ 0' : 'a number ≥ 0'}.`);\n\t\t}\n\t}\n\tif (shot.camera !== undefined) {\n\t\tconst c = shot.camera;\n\t\tif (!isObject(c)) problems.push(`${name}: \"camera\" must be an object.`);\n\t\telse {\n\t\t\tunknownKeys(c, CAMERA_KEYS, `${name} camera`, problems);\n\t\t\tconst isRect = ['x', 'y', 'width', 'height'].every((k) => isNum(c[k]));\n\t\t\tif (typeof c.frame === 'string') {\n\t\t\t\tif (c.padding !== undefined && !isNum(c.padding)) problems.push(`${name} camera: \"padding\" must be a number.`);\n\t\t\t} else if (!isRect) problems.push(`${name} camera: give { x, y, width, height } or { frame: \"<node id>\" }.`);\n\t\t\tif (c.ease !== undefined && !isAnimationEasing(c.ease)) problems.push(`${name} camera: \"ease\" is not an easing.`);\n\t\t\tif (c.ms !== undefined && !(isNum(c.ms) && c.ms >= 0)) problems.push(`${name} camera: \"ms\" must be a number ≥ 0.`);\n\t\t\tif (c.geometric !== undefined && typeof c.geometric !== 'boolean') problems.push(`${name} camera: \"geometric\" must be true or false.`);\n\t\t}\n\t}\n\tif (!Array.isArray(shot.run)) problems.push(`${name}: \"run\" must be a list of commands (it may be empty).`);\n\telse shot.run.forEach((command, i) => problems.push(...commandShapeProblems(command, `${name}, command ${i + 1}`)));\n\treturn problems;\n}\n\n/** Problems with a scene's shape (empty when well formed). */\nexport function motionSceneShapeProblems(input: unknown): string[] {\n\tif (!isObject(input)) return ['The scene must be an object.'];\n\tconst problems: string[] = [];\n\tunknownKeys(input, SCENE_KEYS, 'Scene', problems);\n\tif (input.version !== 1) problems.push('Scene: \"version\" must be 1.');\n\tif (typeof input.name !== 'string' || !input.name) problems.push('Scene: \"name\" must be a non-empty string.');\n\tif (input.description !== undefined && typeof input.description !== 'string') problems.push('Scene: \"description\" must be a string.');\n\tconst art = input.artwork;\n\tif (!isObject(art) || !isNum(art.width) || !isNum(art.height) || !(art.width > 0) || !(art.height > 0) || !Array.isArray(art.nodes))\n\t\tproblems.push('Scene: \"artwork\" must be a vector document { width, height, nodes }.');\n\tif (input.clips !== undefined) problems.push(...clipsShapeProblems(input.clips));\n\tif (input.drivers !== undefined) problems.push(...driversShapeProblems(input.drivers));\n\tif (input.motionBlur !== undefined) {\n\t\tconst b = input.motionBlur;\n\t\tif (!isObject(b) || Object.keys(b).some((k) => k !== 'shutter' && k !== 'samples') || (b.shutter !== undefined && !(isNum(b.shutter) && b.shutter > 0 && b.shutter <= 720)) || (b.samples !== undefined && !(Number.isInteger(b.samples) && (b.samples as number) >= 2 && (b.samples as number) <= 32)))\n\t\t\tproblems.push('Scene: \"motionBlur\" must be { \"shutter\"?: degrees above 0 up to 720 (default 180), \"samples\"?: 2 to 32 (default 8) }.');\n\t}\n\tif (input.trigger !== undefined && !(MOTION_TRIGGERS as readonly unknown[]).includes(input.trigger)) problems.push(`Scene: \"trigger\" must be one of ${MOTION_TRIGGERS.join(', ')}.`);\n\tif (input.loop !== undefined && !['none', 'loop', 'ping-pong'].includes(input.loop as string)) problems.push('Scene: \"loop\" must be \"none\", \"loop\" or \"ping-pong\".');\n\tif (input.fps !== undefined && !(isNum(input.fps) && input.fps > 0 && input.fps <= 120)) problems.push('Scene: \"fps\" must be a number from 1 to 120.');\n\tif (input.beat !== undefined) {\n\t\tconst b = input.beat;\n\t\tif (!isObject(b) || !(isNum(b.bpm) && b.bpm >= 1 && b.bpm <= 1000) || (b.offset !== undefined && !isNum(b.offset)) || (b.meter !== undefined && !(Number.isInteger(b.meter) && (b.meter as number) >= 1)))\n\t\t\tproblems.push('Scene: \"beat\" must be { \"bpm\": 1–1000, \"offset\"?: ms, \"meter\"?: beats a bar }.');\n\t}\n\tif (input.narration !== undefined) {\n\t\tconst n = input.narration;\n\t\tif (!isObject(n) || !Array.isArray(n.words) || !n.words.every((w, i, all) => isObject(w) && typeof w.text === 'string' && isNum(w.start) && w.start >= 0 && (w.end === undefined || (isNum(w.end) && w.end >= w.start)) && (i === 0 || w.start >= ((all[i - 1] as Record<string, number>).start ?? 0))))\n\t\t\tproblems.push('Scene: \"narration\" must be { \"words\": [{ \"text\", \"start\": ms, \"end\"?: ms }, …] } in time order.');\n\t}\n\tif (input.steps !== undefined && !(isNum(input.steps) && input.steps > 0 && input.steps <= 120)) problems.push('Scene: \"steps\" must be frames per second from above 0 to 120.');\n\tif (input.target !== undefined && !(Array.isArray(input.target) && input.target.length === 2 && input.target.every(isNum) && input.target[0] <= input.target[1]))\n\t\tproblems.push('Scene: \"target\" must be [min, max] seconds.');\n\tif (input.controls !== undefined) {\n\t\tif (!Array.isArray(input.controls)) problems.push('Scene: \"controls\" must be a list.');\n\t\telse\n\t\t\tinput.controls.forEach((c, i) => {\n\t\t\t\tif (!isObject(c) || typeof c.name !== 'string' || !/^[A-Za-z_]\\w*$/.test(c.name) || c.type !== 'color' || typeof c.default !== 'string' || !/^#[0-9a-fA-F]{6}$/.test(c.default))\n\t\t\t\t\tproblems.push(`Scene: control ${i + 1} must be { name (an identifier), type: \"color\", default: \"#rrggbb\", label? }.`);\n\t\t\t});\n\t}\n\tif (input.presets !== undefined && !(Array.isArray(input.presets) && input.presets.every((p) => isObject(p) && typeof p.name === 'string' && isObject(p.values))))\n\t\tproblems.push('Scene: \"presets\" must be a list of { name, values }.');\n\tif (!Array.isArray(input.shots)) problems.push('Scene: \"shots\" must be a list.');\n\telse input.shots.forEach((shot, i) => problems.push(...shotShapeProblems(shot, `Shot ${i + 1}`)));\n\treturn problems;\n}\n\n/** Reads a scene from JSON (a string or a parsed value). Throws `MotionSceneFormatError` listing every problem. */\nexport function parseMotionScene(input: unknown): MotionScene {\n\tlet value = input;\n\tif (typeof input === 'string') {\n\t\ttry {\n\t\t\tvalue = JSON.parse(input);\n\t\t} catch (error) {\n\t\t\tthrow new MotionSceneFormatError([`The scene is not valid JSON: ${(error as Error).message}`]);\n\t\t}\n\t}\n\tconst problems = motionSceneShapeProblems(value);\n\tif (problems.length) throw new MotionSceneFormatError(problems);\n\treturn value as MotionScene;\n}\n\n/** Writes a scene as JSON. */\nexport function motionSceneToJson(scene: MotionScene, space: number | string = 2): string {\n\treturn JSON.stringify(scene, null, space);\n}\n\n/** Whether `shot` is a well-formed shot. */\nexport const isMotionShot = (shot: unknown): shot is MotionShot => shotShapeProblems(shot, 'Shot').length === 0;\n/** Whether `command` is a well-formed command. */\nexport const isMotionCommand = (command: unknown): command is MotionCommand => commandShapeProblems(command, 'Command').length === 0;\n","// Pairing passes adapted from deckcraft-main/crates/anim/src/morph.rs (`morph_pairs`) and figcraft-main/crates/ui-egui/src/present.rs (`match_layers`), MIT OR Apache-2.0, © ArtCraft Team and contributors.\nimport type { VectorNode } from '../vector/types.js';\n\n/** How the parts of one node pair with the parts of another for a `match` (Smart Animate). */\nexport interface MotionMatch {\n\t/** `[from id, into id]`: each part of the target and the part of `into` it becomes. */\n\tpairs: [string, string][];\n\t/** Parts of the target with no partner (they fade out). */\n\tunpairedFrom: string[];\n\t/** Parts of `into` with no partner (they cannot appear). */\n\tunpairedInto: string[];\n}\n\nconst SEPARATOR = /[-_/.:]/;\n\n/** An id with the group's own id (or its last word) taken out, so `card-a-title` and `card-b-title` both read `title`. */\nfunction localId(id: string, groupId: string): string {\n\tif (groupId && id.includes(groupId)) return id.split(groupId).join('').replace(/^[-_/.:]+|[-_/.:]+$/g, '');\n\tconst parts = id.split(SEPARATOR);\n\treturn parts[parts.length - 1] ?? id;\n}\n\n/**\n * Pairs the parts of `from` with the parts of `into`, each part used once, in passes: the same\n * `name`, then the same id once each group's own id is taken out, then the same kind in order.\n * Paired groups pair their own parts the same way, so a part pairs with a part, never a group\n * with a path. Two paths (or a path and a group with no children) pair whole.\n */\nexport function matchMotionNodes(from: VectorNode, into: VectorNode): MotionMatch {\n\tconst out: MotionMatch = { pairs: [], unpairedFrom: [], unpairedInto: [] };\n\tconst visit = (a: VectorNode, b: VectorNode) => {\n\t\tconst aKids = a.type === 'group' ? a.children : [];\n\t\tconst bKids = b.type === 'group' ? b.children : [];\n\t\tif (!aKids.length || !bKids.length) {\n\t\t\tout.pairs.push([a.id, b.id]);\n\t\t\treturn;\n\t\t}\n\t\tconst left = new Set(aKids);\n\t\tconst right = new Set(bKids);\n\t\tconst pair = (key: (n: VectorNode, group: VectorNode) => string | undefined) => {\n\t\t\tfor (const x of [...left]) {\n\t\t\t\tconst k = key(x, a);\n\t\t\t\tif (!k) continue;\n\t\t\t\tconst y = [...right].find((n) => key(n, b) === k);\n\t\t\t\tif (!y) continue;\n\t\t\t\tleft.delete(x);\n\t\t\t\tright.delete(y);\n\t\t\t\tif (x.type === 'group' && y.type === 'group') visit(x, y);\n\t\t\t\telse out.pairs.push([x.id, y.id]);\n\t\t\t}\n\t\t};\n\t\tpair((n) => n.name?.trim() || undefined);\n\t\tpair((n, g) => localId(n.id, g.id) || undefined);\n\t\t// Then the same kind, in stacking order.\n\t\tfor (const x of [...left]) {\n\t\t\tconst y = [...right].find((n) => n.type === x.type);\n\t\t\tif (!y) continue;\n\t\t\tleft.delete(x);\n\t\t\tright.delete(y);\n\t\t\tif (x.type === 'group' && y.type === 'group') visit(x, y);\n\t\t\telse out.pairs.push([x.id, y.id]);\n\t\t}\n\t\tout.unpairedFrom.push(...[...left].map((n) => n.id));\n\t\tout.unpairedInto.push(...[...right].map((n) => n.id));\n\t};\n\tvisit(from, into);\n\treturn out;\n}\n","// Clamped tangents after Blender's auto-clamped handles (ideas only) and Fritsch–Carlson monotone cubic interpolation.\nimport type { AnimationEasing } from '../animation/easing.js';\n\n/** One leg of a smooth path on one axis: from → to over [start, end] (ms), eased so velocity carries across legs. */\nexport interface MotionSmoothLeg {\n\tstart: number;\n\tend: number;\n\tfrom: number;\n\tto: number;\n\tease: AnimationEasing;\n}\n\n/**\n * A value passing through `values` at `times` (ms) with continuous velocity and no overshoot:\n * a monotone cubic (Fritsch–Carlson) whose slopes are zero at the ends, at turning points and on\n * flat stretches, so it never goes past a waypoint. Each leg is one cubic-bezier ease per axis;\n * x and y ease differently, so exports to Flair or Lottie (one ease per transform) sample them.\n */\nexport function smoothMotionLegs(times: readonly number[], values: readonly number[]): MotionSmoothLeg[] {\n\tconst n = values.length;\n\tconst slope: number[] = new Array(n).fill(0);\n\tconst secant = (i: number) => (values[i + 1] - values[i]) / Math.max(1e-9, times[i + 1] - times[i]);\n\tfor (let i = 1; i < n - 1; i++) {\n\t\tconst a = secant(i - 1);\n\t\tconst b = secant(i);\n\t\t// A turning point or a flat stretch stays put (Blender's clamped handles); otherwise the harmonic-weighted mean.\n\t\tif (a * b <= 0) continue;\n\t\tconst ha = times[i] - times[i - 1];\n\t\tconst hb = times[i + 1] - times[i];\n\t\tslope[i] = (3 * (ha + hb)) / ((2 * hb + ha) / a + (hb + 2 * ha) / b);\n\t}\n\tconst legs: MotionSmoothLeg[] = [];\n\tfor (let i = 0; i + 1 < n; i++) {\n\t\tconst dt = times[i + 1] - times[i];\n\t\tconst dv = values[i + 1] - values[i];\n\t\tif (Math.abs(dv) < 1e-9) {\n\t\t\tlegs.push({ start: times[i], end: times[i + 1], from: values[i], to: values[i + 1], ease: 'linear' });\n\t\t\tcontinue;\n\t\t}\n\t\t// The Hermite leg as a cubic-bezier ease: handles at thirds of the time, heights from the slopes.\n\t\tconst y1 = (slope[i] * dt) / (3 * dv);\n\t\tconst y2 = 1 - (slope[i + 1] * dt) / (3 * dv);\n\t\tlegs.push({ start: times[i], end: times[i + 1], from: values[i], to: values[i + 1], ease: { type: 'cubic-bezier', x1: 1 / 3, y1, x2: 2 / 3, y2 } });\n\t}\n\treturn legs;\n}\n\n/** When each point of a path is reached over `duration` (ms): in proportion to distance (`even`) or a leg each (`equal`). */\nexport function smoothMotionTimes(points: readonly { x: number; y: number }[], start: number, duration: number, pacing: 'even' | 'equal' = 'even'): number[] {\n\tconst legs = points.slice(1).map((p, i) => (pacing === 'equal' ? 1 : Math.hypot(p.x - points[i].x, p.y - points[i].y)));\n\tconst total = legs.reduce((a, b) => a + b, 0) || legs.length || 1;\n\tconst times = [start];\n\tlet acc = 0;\n\tfor (const l of legs) {\n\t\tacc += total > 0 ? l : 1;\n\t\ttimes.push(start + (duration * acc) / total);\n\t}\n\treturn times;\n}\n","import { mixColorsOklab } from '../animation/color.js';\nimport { matchMotionNodes } from './match.js';\nimport { smoothMotionLegs, smoothMotionTimes } from './smooth.js';\nimport { behaviorProgress, motionSeedFromId, type MotionBehavior } from '../animation/behavior.js';\nimport { evaluateEasing, resolveEasing, springSettleMs, type AnimationEasing } from '../animation/easing.js';\nimport { bezierPathLength } from '../canvas/pathops/bezier.js';\nimport {\n\tIDENTITY_MATRIX,\n\tapplyMatrix,\n\tcollectPathNodes,\n\tinvertMatrix,\n\tmultiplyMatrices,\n\tnodeMatrix,\n\tvectorNodeBounds,\n\tvectorPathWorldBezier,\n\ttype AffineMatrix\n} from '../vector/geometry.js';\nimport type { VectorBounds, VectorNode, VectorPaint } from '../vector/types.js';\nimport {\n\tMOTION_CAMERA_MS,\n\tMOTION_DEFAULT_DURATIONS,\n\tMOTION_DEFAULT_HOLD,\n\tMOTION_DRAW_MS_PER_UNIT,\n\tMOTION_DRAW_RANGE,\n\tMOTION_CLIP_TARGET,\n\ttype MotionBeatGrid,\n\ttype MotionCamera,\n\ttype MotionCommand,\n\ttype MotionCue,\n\ttype MotionDirection,\n\ttype MotionDriver,\n\ttype MotionDrivenProperty,\n\ttype MotionDrawOrder,\n\ttype MotionIrisShape,\n\ttype MotionRect,\n\ttype MotionSplitOrientation,\n\ttype MotionScene,\n\ttype MotionShot\n} from './types.js';\n\n/**\n * Compiling a scene: shots and commands become timed segments, one per (node, property)\n * change. A property's value at a time is that of the latest segment to have started (its\n * `from` before the first one), so a node that enters later is hidden until then. This is\n * also how Flair's vector motion combines changes, which keeps the Flair export exact.\n */\n\n/**\n * Properties a segment can change. Offsets (`x`, `y`, `rotation`) are relative to the rest\n * pose, scales multiply it, and turns and scales are about the node's centre at rest.\n * `effect:<effectId>:<param>` tweens a live path effect's parameter. `camera` (node `\"\"`) is\n * the view box `[x, y, width, height]`. `clipRect` (`[x, y, width, height]`) and `clipCircle`\n * (`[cx, cy, r]`) are the reveal clips of `wipe`, `iris` and `split`, in the units of the\n * node's own box (0–1 across it, SVG's `objectBoundingBox`), as Flair's clip reveals are.\n */\nexport type MotionProperty =\n\t| 'opacity'\n\t| 'x'\n\t| 'y'\n\t| 'rotation'\n\t| 'scaleX'\n\t| 'scaleY'\n\t| 'fill'\n\t| 'stroke'\n\t| 'strokeWidth'\n\t| 'fillOpacity'\n\t| 'drawStart'\n\t| 'drawEnd'\n\t| 'shape'\n\t| 'follow'\n\t| 'clipRect'\n\t| 'clipCircle'\n\t| 'camera'\n\t| `effect:${string}:${string}`;\n\nexport type MotionValue = number | string | readonly number[];\n\nexport interface MotionSegment {\n\t/** Node id (`\"\"` for the camera). */\n\tnode: string;\n\tproperty: MotionProperty;\n\tstart: number;\n\tend: number;\n\tfrom: MotionValue;\n\tto: MotionValue;\n\tease: AnimationEasing;\n\t/** The shot and command (index in `run`) it comes from. */\n\tshot: string;\n\tcommand: number;\n\t/**\n\t * How the change gets from `from` to `to` when not straight along its ease (a pulse there and\n\t * back, a settling oscillation, a wriggle): Flair's `behavior`, exported as is.\n\t */\n\tbehavior?: MotionBehavior;\n\t/**\n\t * Which number of the node's exported value this is (x 0, y 1, rotation 2, matching the\n\t * transform Flair is given), so a wriggle wanders each on the channel Flair uses. Default 0.\n\t */\n\tindex?: number;\n\t/** Played backwards in time (a mirrored repeat): progress runs 1 → 0 through the ease. */\n\treverse?: boolean;\n\t/** Stepped time: progress holds on a grid of this many frames per second from the start. */\n\tsteps?: number;\n\t/** Numbers change by a steady factor (`from·(to/from)^u`); a camera zooms at a steady rate. */\n\tgeometric?: boolean;\n\t/**\n\t * `add`: the segment is a layer over the node's pose rather than a change to it. It lives on\n\t * its own track (`motionAddTrackKey`), runs from 0 (offsets, turns) or 1 (scales), and what\n\t * it adds stays once it ends, on top of whatever the pose does.\n\t */\n\tblend?: 'add';\n\t/** For `follow`: the path node id, and whether to turn with it. */\n\tpath?: string;\n\trotate?: boolean;\n}\n\nexport interface MotionShotTiming {\n\tid: string;\n\tindex: number;\n\tlabel?: string;\n\tstart: number;\n\t/** When the camera move ends and the commands begin. */\n\tcommandsStart: number;\n\t/** When the last command ends (the hold follows). */\n\tcommandsEnd: number;\n\tend: number;\n\t/** The time the shot is cued to start (`at`), when it has a cue that resolves. */\n\tcue?: number;\n\t/** How late the shot starts after its cue (ms), when the shot before ran past it. */\n\tmissedBy?: number;\n}\n\nexport interface MotionCommandTiming {\n\tshot: string;\n\tshotIndex: number;\n\tcommand: number;\n\ttype: MotionCommand['type'];\n\tstart: number;\n\tend: number;\n\t/** Length per target (ms). */\n\tduration: number;\n}\n\nexport interface MotionTimeline {\n\t/** Total length in ms. */\n\tduration: number;\n\tshots: MotionShotTiming[];\n\tcommands: MotionCommandTiming[];\n\tsegments: MotionSegment[];\n\t/** Segments per `node\\u0000property`, in start order. */\n\ttracks: ReadonlyMap<string, readonly MotionSegment[]>;\n\t/** The scene's drivers (properties that follow other properties). */\n\tdrivers?: readonly MotionDriver[];\n\t/** Rest opacity per node, for drivers that read opacity. */\n\trestOpacity?: ReadonlyMap<string, number>;\n}\n\n/** Where a node sits in the artwork. */\nexport interface MotionNodeEntry {\n\tnode: VectorNode;\n\t/** Ids from the root down to the node's parent. */\n\tancestors: string[];\n\t/** Parent space → document space. */\n\tparentWorld: AffineMatrix;\n\t/** Centre of the node's bounds at rest, in its parent's space. */\n\tcenter: { x: number; y: number };\n\t/** Bounds at rest in document space. */\n\tbounds: VectorBounds | null;\n\t/** Bounds at rest in its parent's space (what a reveal clip's box is). */\n\tbox: VectorBounds | null;\n}\n\nconst indexCache = new WeakMap<object, Map<string, MotionNodeEntry>>();\n\n/** Every node of the artwork by id (cached per node list). */\nexport function indexMotionNodes(nodes: readonly VectorNode[]): Map<string, MotionNodeEntry> {\n\tconst hit = indexCache.get(nodes);\n\tif (hit) return hit;\n\tconst out = new Map<string, MotionNodeEntry>();\n\tconst walk = (list: readonly VectorNode[], parentWorld: AffineMatrix, ancestors: string[]) => {\n\t\tfor (const node of list) {\n\t\t\tconst local = vectorNodeBounds(node);\n\t\t\tconst bounds = vectorNodeBounds(node, parentWorld);\n\t\t\tconst center = local ? { x: local.x + local.width / 2, y: local.y + local.height / 2 } : { x: 0, y: 0 };\n\t\t\tif (!out.has(node.id)) out.set(node.id, { node, ancestors, parentWorld, center, bounds, box: local });\n\t\t\tif (node.type === 'group') walk(node.children, multiplyMatrices(nodeMatrix(node), parentWorld), [...ancestors, node.id]);\n\t\t}\n\t};\n\twalk(nodes, IDENTITY_MATRIX, []);\n\tindexCache.set(nodes, out);\n\treturn out;\n}\n\nconst solid = (paint: VectorPaint | undefined): string | undefined => (typeof paint === 'string' && paint !== 'none' ? paint : undefined);\n\n/** The first solid paint of a node (a group's first path with one). */\nfunction firstPaint(node: VectorNode, key: 'fill' | 'stroke'): string | undefined {\n\tif (node.type === 'path') return solid(node[key]);\n\tfor (const p of collectPathNodes(node)) {\n\t\tconst s = solid(p[key]);\n\t\tif (s) return s;\n\t}\n\treturn undefined;\n}\n\n/** How far a stroke reaches past the outline: half its width (all of it outside, none inside). */\nfunction strokeReach(node: VectorNode): number {\n\tlet reach = 0;\n\tfor (const p of node.type === 'path' ? [node] : collectPathNodes(node)) {\n\t\tif (p.stroke == null || p.stroke === 'none') continue;\n\t\tconst width = p.strokeWidth ?? 1;\n\t\treach = Math.max(reach, p.strokeAlign === 'outside' ? width : p.strokeAlign === 'inside' ? 0 : width / 2);\n\t}\n\treturn reach;\n}\n\n/**\n * How far past its box (as a share of its width and height) a reveal clip reaches, so it shows\n * the whole stroke: the stroke's reach over the box plus 0.02, at most 1 (Flair's padding). Null\n * when the box has no width or height (a lone straight line), which a clip cannot reveal.\n */\nexport function motionRevealPadding(entry: MotionNodeEntry): readonly [number, number] | null {\n\tconst box = entry.box;\n\tif (!box || !(box.width > 0) || !(box.height > 0)) return null;\n\tconst s = strokeReach(entry.node);\n\treturn [Math.min(1, s / box.width + 0.02), Math.min(1, s / box.height + 0.02)];\n}\n\n/** Clip numbers as Flair writes them (4 decimals). */\nconst clipRound = (n: number) => Math.round(n * 1e4) / 1e4 || 0;\n\n/** A reveal clip that shows the whole node (padded past its box), in its box's units. */\nfunction revealFull(property: 'clipRect' | 'clipCircle', [px, py]: readonly [number, number]): number[] {\n\treturn (property === 'clipRect' ? [-px, -py, 1 + 2 * px, 1 + 2 * py] : [0.5, 0.5, Math.hypot(0.5 + px, 0.5 + py)]).map(clipRound);\n}\n\nconst OPPOSITE: Record<MotionDirection, MotionDirection> = { up: 'down', down: 'up', left: 'right', right: 'left' };\n\n/** What a reveal clip animates: a wipe (in, or out with `hide`), an iris or a split. */\nexport type MotionReveal = { style: 'wipe'; direction?: MotionDirection; hide?: boolean } | { style: 'iris'; shape?: MotionIrisShape } | { style: 'split'; orientation?: MotionSplitOrientation };\n\n/**\n * The reveal clip a `wipe`, `iris` or `split` animates, from and to (Flair's `entrance.wipe`,\n * `entrance.iris`, `entrance.split` and `exit.wipe`), or null when the node's box has no width\n * or height. An exit wipe is the enter wipe the other way, reversed in time.\n */\nexport function motionRevealClip(entry: MotionNodeEntry, reveal: MotionReveal): { property: 'clipRect' | 'clipCircle'; from: number[]; to: number[] } | null {\n\tconst pad = motionRevealPadding(entry);\n\tif (!pad) return null;\n\tconst [px, py] = pad;\n\tconst [w, h] = [1 + 2 * px, 1 + 2 * py];\n\tconst rect = (from: number[], to: number[]) => ({ property: 'clipRect' as const, from: from.map(clipRound), to: to.map(clipRound) });\n\tif (reveal.style === 'iris') {\n\t\tif (reveal.shape === 'box') return rect([0.5, 0.5, 0, 0], [-px, -py, w, h]);\n\t\treturn { property: 'clipCircle', from: [0.5, 0.5, 0], to: revealFull('clipCircle', pad) };\n\t}\n\tif (reveal.style === 'split') {\n\t\tif (reveal.orientation === 'vertical') return rect([0.5, -py, 0, h], [-px, -py, w, h]);\n\t\treturn rect([-px, 0.5, w, 0], [-px, -py, w, h]);\n\t}\n\tconst direction = reveal.direction ?? 'right';\n\tif (reveal.hide) {\n\t\tconst shown = motionRevealClip(entry, { style: 'wipe', direction: OPPOSITE[direction] })!;\n\t\treturn { ...shown, from: shown.to, to: shown.from };\n\t}\n\tswitch (direction) {\n\t\tcase 'right':\n\t\t\treturn rect([-px, -py, 0, h], [-px, -py, w, h]);\n\t\tcase 'left':\n\t\t\treturn rect([1 + px, -py, 0, h], [-px, -py, w, h]);\n\t\tcase 'down':\n\t\t\treturn rect([-px, -py, w, 0], [-px, -py, w, h]);\n\t\tcase 'up':\n\t\t\treturn rect([-px, 1 + py, w, 0], [-px, -py, w, h]);\n\t}\n}\n\n/** A property's value with no animation. */\nexport function motionRestValue(entry: MotionNodeEntry | undefined, property: MotionProperty, artwork: { width: number; height: number }): MotionValue {\n\tconst node = entry?.node;\n\tswitch (property) {\n\t\tcase 'opacity':\n\t\t\treturn node?.opacity ?? 1;\n\t\tcase 'x':\n\t\tcase 'y':\n\t\tcase 'rotation':\n\t\t\treturn 0;\n\t\tcase 'scaleX':\n\t\tcase 'scaleY':\n\t\tcase 'fillOpacity':\n\t\tcase 'drawEnd':\n\t\t\treturn 1;\n\t\tcase 'drawStart':\n\t\t\treturn 0;\n\t\tcase 'follow':\n\t\t\treturn -1;\n\t\tcase 'fill':\n\t\tcase 'stroke':\n\t\t\treturn (node && firstPaint(node, property)) ?? 'transparent';\n\t\tcase 'strokeWidth': {\n\t\t\tconst path = node?.type === 'path' ? node : node ? collectPathNodes(node)[0] : undefined;\n\t\t\treturn path?.strokeWidth ?? 1;\n\t\t}\n\t\tcase 'shape':\n\t\t\treturn node?.id ?? '';\n\t\tcase 'clipRect':\n\t\tcase 'clipCircle': {\n\t\t\tconst pad = entry && motionRevealPadding(entry);\n\t\t\treturn pad ? revealFull(property, pad) : [];\n\t\t}\n\t\tcase 'camera':\n\t\t\treturn [0, 0, artwork.width, artwork.height];\n\t}\n\tconst [, effectId, param] = property.split(':');\n\tconst effect = node?.effects?.find((e) => e.id === effectId);\n\tconst v = effect ? (effect.params as unknown as Record<string, unknown>)[param] : undefined;\n\treturn typeof v === 'number' ? v : 0;\n}\n\n/** `from` → `to` at eased progress `u` (numbers extrapolate, colours mix in OKLab, others switch at the end). */\nexport function interpolateMotionValue(from: MotionValue, to: MotionValue, u: number): MotionValue {\n\tif (typeof from === 'number' && typeof to === 'number') return from + (to - from) * u;\n\tif (Array.isArray(from) && Array.isArray(to) && from.length === to.length) return from.map((f, i) => f + ((to[i] as number) - f) * u);\n\tif (u <= 0) return from;\n\tif (u >= 1) return to;\n\tif (typeof from === 'string' && typeof to === 'string') {\n\t\tconst mixed = mixColorsOklab(from, to, u);\n\t\tif (mixed !== null) return mixed;\n\t}\n\treturn u < 1 ? from : to;\n}\n\n/** Progress (0–1, unclamped by the easing) of a segment at `time`: stepped, reversed and eased as the segment says. */\nexport function segmentProgress(segment: MotionSegment, time: number): { u: number; eased: number } {\n\tconst span = segment.end - segment.start;\n\tlet elapsed = time - segment.start;\n\tif (segment.steps && segment.steps > 0 && elapsed < span) elapsed = (Math.floor((elapsed * segment.steps) / 1000 + 1e-9) / segment.steps) * 1000;\n\tconst u = span <= 0 ? 1 : Math.min(1, Math.max(0, elapsed / span));\n\t// A reversed segment plays its forward run backwards: at u it shows what it showed at 1 − u.\n\treturn { u, eased: evaluateEasing(segment.ease, segment.reverse ? 1 - u : u, span) };\n}\n\n/** `from` → `to` by a steady factor: numbers above 0 grow geometrically; a camera box zooms at a steady rate, its centre keeping pace. */\nfunction geometricValue(from: MotionValue, to: MotionValue, e: number): MotionValue | undefined {\n\tconst grow = (a: number, b: number) => (a > 0 && b > 0 ? a * (b / a) ** e : undefined);\n\tif (typeof from === 'number' && typeof to === 'number') return grow(from, to);\n\tif (Array.isArray(from) && Array.isArray(to) && from.length === 4 && to.length === 4) {\n\t\tconst [x0, y0, w0, h0] = from as number[];\n\t\tconst [x1, y1, w1, h1] = to as number[];\n\t\tconst w = grow(w0, w1);\n\t\tconst h = grow(h0, h1);\n\t\tif (w === undefined || h === undefined) return undefined;\n\t\t// The centre moves the same share of the way as the size has changed.\n\t\tconst f = Math.abs(w1 - w0) > 1e-9 ? (w - w0) / (w1 - w0) : e;\n\t\tconst cx = x0 + w0 / 2 + (x1 + w1 / 2 - x0 - w0 / 2) * f;\n\t\tconst cy = y0 + h0 / 2 + (y1 + h1 / 2 - y0 - h0 / 2) * f;\n\t\treturn [cx - w / 2, cy - h / 2, w, h];\n\t}\n\treturn undefined;\n}\n\n/**\n * A segment's value at `time`: along its ease, through its behaviour when it has one. `raw`\n * ignores the behaviour (the value it swings towards), as Flair is given it.\n */\nexport function segmentValue(segment: MotionSegment, time: number, raw = false): MotionValue {\n\tconst { eased } = segmentProgress(segment, time);\n\tif (segment.geometric && !segment.behavior) {\n\t\tconst g = geometricValue(segment.from, segment.to, eased);\n\t\tif (g !== undefined) return g;\n\t}\n\tif (!segment.behavior || raw) return interpolateMotionValue(segment.from, segment.to, eased);\n\tconst p = behaviorProgress(segment.behavior, eased, segment.index ?? 0, segment.end - segment.start);\n\t// Colours (a colour pulse) mix only between their ends; numbers swing past them.\n\treturn typeof segment.from === 'string' ? interpolateMotionValue(segment.from, segment.to, Math.min(1, Math.max(0, p))) : interpolateMotionValue(segment.from, segment.to, p);\n}\n\n/** The segment in effect at `time` (the latest to have started), if any. */\nexport function activeSegment(track: readonly MotionSegment[] | undefined, time: number): MotionSegment | undefined {\n\tif (!track?.length) return undefined;\n\tlet found: MotionSegment | undefined;\n\tfor (const s of track) if (s.start <= time && (!found || s.start >= found.start)) found = s;\n\treturn found;\n}\n\n/** A track's value at `time`, or `undefined` when nothing animates it. `raw` ignores behaviours (see `segmentValue`). */\nexport function trackValue(track: readonly MotionSegment[] | undefined, time: number, raw = false): MotionValue | undefined {\n\tif (!track?.length) return undefined;\n\tconst s = activeSegment(track, time);\n\tif (s) return segmentValue(s, time, raw);\n\tlet first = track[0];\n\tfor (const t of track) if (t.start < first.start) first = t;\n\treturn first.from;\n}\n\nexport const motionTrackKey = (node: string, property: MotionProperty) => `${node}\\u0000${property}`;\n\n/** The track of a node property's additive layers (segments with `blend: 'add'`). */\nexport const motionAddTrackKey = (node: string, property: MotionProperty) => `${node}\\u0000${property}\\u0000add`;\n\n/** Properties that take additive layers: offsets and turns add, scales multiply. */\nexport const MOTION_ADDITIVE_PROPERTIES: readonly MotionProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY'];\n\n/**\n * A property's value with its additive layers on top of `base` (its pose): every layer that has\n * started adds its value (offsets, turns) or multiplies by it (scales). `raw` ignores behaviours.\n */\nexport function withMotionLayers(timeline: Pick<MotionTimeline, 'tracks'>, node: string, property: MotionProperty, base: number, time: number, raw = false): number {\n\tconst layers = timeline.tracks.get(motionAddTrackKey(node, property));\n\tif (!layers) return base;\n\tconst scale = property === 'scaleX' || property === 'scaleY';\n\tlet v = base;\n\tfor (const layer of layers) {\n\t\tif (layer.start > time) continue;\n\t\tconst x = Number(segmentValue(layer, time, raw));\n\t\tif (Number.isFinite(x)) v = scale ? v * x : v + x;\n\t}\n\treturn v;\n}\n\n/** Grows a rectangle to the artwork's aspect ratio (about its centre). */\nexport function fitMotionRect(rect: MotionRect, aspect: number): MotionRect {\n\tconst cx = rect.x + rect.width / 2;\n\tconst cy = rect.y + rect.height / 2;\n\tlet { width, height } = rect;\n\tif (width / height < aspect) width = height * aspect;\n\telse height = width / aspect;\n\treturn { x: cx - width / 2, y: cy - height / 2, width, height };\n}\n\n/** The rectangle a camera looks at, or `null` when it frames an unknown node. */\nexport function resolveMotionCamera(camera: MotionCamera, scene: MotionScene): MotionRect | null {\n\tif ('frame' in camera && typeof camera.frame === 'string') {\n\t\tconst entry = indexMotionNodes(scene.artwork.nodes).get(camera.frame);\n\t\tif (!entry?.bounds) return null;\n\t\tconst pad = camera.padding ?? 24;\n\t\tconst b = entry.bounds;\n\t\tconst rect = { x: b.x - pad, y: b.y - pad, width: Math.max(1, b.width + pad * 2), height: Math.max(1, b.height + pad * 2) };\n\t\treturn fitMotionRect(rect, scene.artwork.width / scene.artwork.height);\n\t}\n\tconst r = camera as MotionRect;\n\treturn { x: r.x, y: r.y, width: r.width, height: r.height };\n}\n\n/** Length of a node's outline (its longest path for a group), in document units. */\nexport function motionPathLength(node: VectorNode, parentWorld: AffineMatrix = IDENTITY_MATRIX): number {\n\tlet longest = 0;\n\tconst paths = node.type === 'path' ? [node] : collectPathNodes(node);\n\tfor (const p of paths) {\n\t\ttry {\n\t\t\tlongest = Math.max(longest, bezierPathLength(vectorPathWorldBezier(p, parentWorld, { effects: false })));\n\t\t} catch {\n\t\t\t/* unmeasurable: keep the default */\n\t\t}\n\t}\n\treturn longest;\n}\n\n/** How much a shot's `speed` stretches its time (1 / speed; 1 when unset or not above 0). */\nexport function motionShotTimeScale(shot: MotionShot): number {\n\treturn typeof shot.speed === 'number' && shot.speed > 0 && Number.isFinite(shot.speed) ? 1 / shot.speed : 1;\n}\n\n// Beat grid adapted from soundcraft-main/crates/time/src/{tempo,grid}.rs (MIT OR Apache-2.0, © ArtCraft Team and contributors).\n/** When beat `beat` falls on a grid, ms: `offset + beat · 60000 / bpm`. */\nexport function motionBeatTime(grid: MotionBeatGrid, beat: number): number {\n\treturn (grid.offset ?? 0) + (beat * 60000) / grid.bpm;\n}\n\n/** The beat (fractional) at `ms` on a grid, and its bar and beat in the bar (both from 1). */\nexport function motionBeatAt(grid: MotionBeatGrid, ms: number): { beat: number; bar: number; beatInBar: number } {\n\tconst beat = ((ms - (grid.offset ?? 0)) * grid.bpm) / 60000;\n\tconst meter = Math.max(1, Math.round(grid.meter ?? 4));\n\tconst whole = Math.floor(beat + 1e-9);\n\treturn { beat, bar: Math.floor(whole / meter) + 1, beatInBar: (((whole % meter) + meter) % meter) + 1 };\n}\n\n/** The time a cue names, ms, or undefined when it names a beat with no grid or a word the narration lacks. */\nexport function motionCueTime(scene: Pick<MotionScene, 'beat' | 'narration'>, cue: MotionCue): number | undefined {\n\tif (typeof cue.ms === 'number') return Math.max(0, cue.ms);\n\tif (typeof cue.beat === 'number') return scene.beat && scene.beat.bpm > 0 ? Math.max(0, motionBeatTime(scene.beat, cue.beat)) : undefined;\n\tif (typeof cue.word === 'number') return scene.narration?.words[cue.word]?.start;\n\treturn undefined;\n}\n\nconst SCALE_LIKE = new Set<MotionProperty>(['scaleX', 'scaleY', 'opacity']);\n\n/**\n * A node property's value at `time` with its commands, additive layers and drivers: offsets and\n * turns from 0, scales from 1, opacity from the node's own. `raw` ignores behaviours.\n */\nexport function motionPropertyValue(timeline: MotionTimeline, node: string, property: MotionDrivenProperty, time: number, raw = false, depth = 0): number {\n\tconst rest = property === 'opacity' ? (timeline.restOpacity?.get(node) ?? 1) : SCALE_LIKE.has(property) ? 1 : 0;\n\tconst v = trackValue(timeline.tracks.get(motionTrackKey(node, property)), time, raw);\n\tconst base = property === 'opacity' ? (typeof v === 'number' ? v : rest) : withMotionLayers(timeline, node, property, typeof v === 'number' ? v : rest, time, raw);\n\treturn applyMotionDrivers(timeline, node, property, base, time, raw, depth);\n}\n\n/** `value` with the drivers of `node`'s `property` applied (a no-op without drivers). Chains of drivers are followed up to 8 deep; `check` reports cycles. */\nexport function applyMotionDrivers(timeline: MotionTimeline, node: string, property: MotionDrivenProperty, value: number, time: number, raw = false, depth = 0): number {\n\tif (!timeline.drivers || depth > 8) return value;\n\tlet v = value;\n\tfor (const d of timeline.drivers) {\n\t\tif (d.target !== node || d.property !== property) continue;\n\t\tconst src = motionPropertyValue(timeline, d.source.node, d.source.property, time, raw, depth + 1);\n\t\tconst srcRest = d.source.property === 'opacity' ? (timeline.restOpacity?.get(d.source.node) ?? 1) : SCALE_LIKE.has(d.source.property) ? 1 : 0;\n\t\tlet change = (src - srcRest) * (d.factor ?? 1) + (d.offset ?? 0);\n\t\tif (d.clamp) change = Math.min(d.clamp[1], Math.max(d.clamp[0], change));\n\t\tv = SCALE_LIKE.has(property) ? v * (1 + change) : v + change;\n\t}\n\treturn property === 'opacity' ? Math.min(1, Math.max(0, v)) : v;\n}\n\n/** Nodes driven by a driver (directly). */\nexport function motionDrivenNodes(timeline: MotionTimeline): Set<string> {\n\treturn new Set((timeline.drivers ?? []).map((d) => d.target));\n}\n\n/**\n * The segments a node's drivers depend on (its sources', followed down chains), for exporters that\n * must sample a driven property wherever its sources change.\n */\nexport function motionDriverSources(timeline: MotionTimeline, node: string, properties: readonly MotionDrivenProperty[], seen = new Set<string>()): MotionSegment[] {\n\tconst out: MotionSegment[] = [];\n\tfor (const d of timeline.drivers ?? []) {\n\t\tif (d.target !== node || !properties.includes(d.property)) continue;\n\t\tconst key = `${d.source.node}\\u0000${d.source.property}`;\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tout.push(...(timeline.tracks.get(motionTrackKey(d.source.node, d.source.property)) ?? []), ...(timeline.tracks.get(`${motionTrackKey(d.source.node, d.source.property)}\\u0000add`) ?? []));\n\t\tout.push(...motionDriverSources(timeline, d.source.node, [d.source.property], seen));\n\t}\n\treturn out;\n}\n\n/** How many times a command plays (1 for `enter`, `exit` and `wait`, which do not repeat). */\nexport function motionCommandRepeat(command: MotionCommand): number {\n\tif (command.type === 'wait' || command.type === 'enter' || command.type === 'exit') return 1;\n\tconst n = command.repeat ?? 1;\n\treturn Number.isInteger(n) && n >= 1 ? n : 1;\n}\n\n/** How long one target of a command takes (ms), every repeat included. */\nexport function motionCommandDuration(command: MotionCommand, scene: MotionScene, target?: string): number {\n\treturn motionCycleDuration(command, scene, target) * motionCommandRepeat(command);\n}\n\n/** One command of a clip played on a target: when it starts (ms from the play's start), its target and one cycle's length. */\nexport interface MotionClipItem {\n\tcommand: Exclude<MotionCommand, { type: 'wait' }>;\n\ttarget: string;\n\tstart: number;\n\tcycle: number;\n}\n\n/** A clip's commands for `target` (`\"$\"` replaced), timed as in a shot from 0 at `speed`; unknown clips give nothing. */\nexport function motionClipLayout(scene: MotionScene, clip: string, target: string, speed = 1): { items: MotionClipItem[]; length: number } {\n\tconst run = scene.clips?.[clip]?.run;\n\tif (!run) return { items: [], length: 0 };\n\tconst f = speed > 0 && Number.isFinite(speed) ? 1 / speed : 1;\n\tconst items: MotionClipItem[] = [];\n\tlet runEnd = 0;\n\tlet prevStart = 0;\n\trun.forEach((raw, i) => {\n\t\tconst base = raw.with === 'previous' && i > 0 ? prevStart : runEnd;\n\t\tif (raw.type === 'wait') {\n\t\t\tprevStart = base;\n\t\t\trunEnd = Math.max(runEnd, base + raw.duration * f);\n\t\t\treturn;\n\t\t}\n\t\tif (raw.type === 'play') return;\n\t\tconst command = { ...raw, targets: raw.targets.map((t) => (t === MOTION_CLIP_TARGET ? target : t)) } as Exclude<MotionCommand, { type: 'wait' }>;\n\t\tconst begin = base + (command.delay ?? 0) * f;\n\t\tlet end = begin;\n\t\tcommand.targets.forEach((t, k) => {\n\t\t\tconst cycle = motionCycleDuration(command, scene, t) * f;\n\t\t\tconst s = begin + k * (command.stagger ?? 0) * f;\n\t\t\titems.push({ command, target: t, start: s, cycle });\n\t\t\tend = Math.max(end, s + cycle * motionCommandRepeat(command));\n\t\t});\n\t\tprevStart = begin;\n\t\trunEnd = Math.max(runEnd, end);\n\t});\n\treturn { items, length: runEnd };\n}\n\n/** How long one cycle of a command takes for one target (ms): its `duration`, a spring's settle time, the line's length for a draw, or the type's default. */\nexport function motionCycleDuration(command: MotionCommand, scene: MotionScene, target?: string): number {\n\tif (command.type === 'wait') return command.duration;\n\tif (command.type === 'play') return motionClipLayout(scene, command.clip, target ?? MOTION_CLIP_TARGET, command.speed).length;\n\tif (command.duration !== undefined) return command.duration;\n\tif (command.ease !== undefined) {\n\t\tconst ease = resolveEasing(command.ease);\n\t\tif (ease !== 'hold' && ease.type === 'spring') return springSettleMs(ease);\n\t}\n\tif (command.type === 'draw' || (command.type === 'enter' && command.style === 'draw') || (command.type === 'exit' && command.style === 'undraw')) {\n\t\tconst entry = target ? indexMotionNodes(scene.artwork.nodes).get(target) : undefined;\n\t\tconst length = entry ? motionPathLength(entry.node) : 0;\n\t\tconst ms = length * MOTION_DRAW_MS_PER_UNIT;\n\t\treturn Math.round(Math.min(MOTION_DRAW_RANGE[1], Math.max(MOTION_DRAW_RANGE[0], ms)));\n\t}\n\t// A move through waypoints takes longer the more stretches it has.\n\tif (command.type === 'move' && command.via?.length) return MOTION_DEFAULT_DURATIONS.move + 400 * command.via.length;\n\treturn MOTION_DEFAULT_DURATIONS[command.type];\n}\n\n/** Cubic ease-out, `1 − (1 − t)³` exactly (Flair's `out`): the default for things arriving. */\nexport const MOTION_EASE_OUT: AnimationEasing = { type: 'cubic-bezier', x1: 1 / 3, y1: 1, x2: 2 / 3, y2: 1 };\n/** Cubic ease-in-out (close to Flair's `in-out`): the default for moves. */\nexport const MOTION_EASE_IN_OUT: AnimationEasing = { type: 'cubic-bezier', x1: 0.65, y1: 0, x2: 0.35, y2: 1 };\n\nconst DIRECTION: Record<MotionDirection, { x: number; y: number }> = { up: { x: 0, y: -1 }, down: { x: 0, y: 1 }, left: { x: -1, y: 0 }, right: { x: 1, y: 0 } };\n\nconst timelineCache = new WeakMap<MotionScene, MotionTimeline>();\n\n/**\n * Times every shot and command and turns them into segments. Pure and cached per scene object\n * (treat scenes as immutable). Commands naming unknown nodes are timed but change nothing;\n * `checkMotionScene` reports them.\n */\nexport function compileMotionScene(scene: MotionScene): MotionTimeline {\n\tconst hit = timelineCache.get(scene);\n\tif (hit) return hit;\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst artwork = scene.artwork;\n\n\t// Pass 1: timing.\n\tconst shots: MotionShotTiming[] = [];\n\tconst commands: MotionCommandTiming[] = [];\n\tconst cameraMoves: { shot: string; start: number; end: number; to: MotionRect; ease: AnimationEasing; geometric: boolean }[] = [];\n\tlet t = 0;\n\tscene.shots.forEach((shot, index) => {\n\t\t// A cue holds the shot before until it comes (or, for the first shot, waits from 0).\n\t\tconst cue = shot.at ? motionCueTime(scene, shot.at) : undefined;\n\t\tif (cue !== undefined && cue > t) {\n\t\t\tif (shots.length) shots[shots.length - 1].end = cue;\n\t\t\tt = cue;\n\t\t}\n\t\tconst missedBy = cue !== undefined && t - cue > 0.5 ? t - cue : undefined;\n\t\tconst start = t;\n\t\tlet cursor = start;\n\t\t// A shot's speed scales all of its time: camera move, delays, durations, staggers and hold.\n\t\tconst f = motionShotTimeScale(shot);\n\t\tif (shot.camera) {\n\t\t\tconst rect = resolveMotionCamera(shot.camera, scene);\n\t\t\tif (rect && rect.width > 0 && rect.height > 0) {\n\t\t\t\tconst ms = index === 0 ? 0 : (shot.camera.ms ?? MOTION_CAMERA_MS) * f;\n\t\t\t\tcameraMoves.push({ shot: shot.id, start, end: start + ms, to: rect, ease: shot.camera.ease ?? MOTION_EASE_IN_OUT, geometric: shot.camera.geometric === true });\n\t\t\t\tcursor = start + ms;\n\t\t\t}\n\t\t}\n\t\tconst commandsStart = cursor;\n\t\tlet runEnd = cursor;\n\t\tlet prevStart = cursor;\n\t\tshot.run.forEach((command, i) => {\n\t\t\tconst base = command.with === 'previous' && i > 0 ? prevStart : runEnd;\n\t\t\tconst begin = base + (command.type === 'wait' ? 0 : (command.delay ?? 0) * f);\n\t\t\tconst targets = command.type === 'wait' ? [] : command.targets;\n\t\t\tconst durations = command.type === 'wait' ? [command.duration * f] : targets.map((id) => motionCommandDuration(command, scene, id) * f);\n\t\t\tconst stagger = command.type === 'wait' ? 0 : (command.stagger ?? 0) * f;\n\t\t\tconst end = durations.reduce((m, d, k) => Math.max(m, begin + k * stagger + d), begin);\n\t\t\tcommands.push({ shot: shot.id, shotIndex: index, command: i, type: command.type, start: begin, end, duration: durations[0] ?? 0 });\n\t\t\tprevStart = begin;\n\t\t\trunEnd = Math.max(runEnd, end);\n\t\t});\n\t\tconst end = runEnd + (shot.hold ?? MOTION_DEFAULT_HOLD) * f;\n\t\tshots.push({ id: shot.id, index, ...(shot.label ? { label: shot.label } : {}), start, commandsStart, commandsEnd: runEnd, end, ...(cue !== undefined ? { cue } : {}), ...(missedBy !== undefined ? { missedBy } : {}) });\n\t\tt = end;\n\t});\n\n\t// Pass 2: segments, in start order so each `from` is the value its segment starts at.\n\tconst tracks = new Map<string, MotionSegment[]>();\n\tconst segments: MotionSegment[] = [];\n\tconst valueAt = (node: string, property: MotionProperty, time: number): MotionValue => {\n\t\tconst v = trackValue(tracks.get(motionTrackKey(node, property)), time);\n\t\treturn v ?? motionRestValue(nodes.get(node), property, artwork);\n\t};\n\tconst push = (segment: MotionSegment) => {\n\t\tconst key = segment.blend === 'add' ? motionAddTrackKey(segment.node, segment.property) : motionTrackKey(segment.node, segment.property);\n\t\tlet track = tracks.get(key);\n\t\tif (!track) tracks.set(key, (track = []));\n\t\ttrack.push(segment);\n\t\tsegments.push(segment);\n\t};\n\n\ttype Job = { start: number; order: number; run: () => void };\n\tconst jobs: Job[] = [];\n\tlet order = 0;\n\tfor (const move of cameraMoves) {\n\t\tjobs.push({\n\t\t\tstart: move.start,\n\t\t\torder: order++,\n\t\t\trun: () => push({ node: '', property: 'camera', start: move.start, end: move.end, from: valueAt('', 'camera', move.start), to: [move.to.x, move.to.y, move.to.width, move.to.height], ease: move.ease, shot: move.shot, command: -1, ...(move.geometric ? { geometric: true } : {}) })\n\t\t});\n\t}\n\tfor (const timing of commands) {\n\t\tconst shot = scene.shots[timing.shotIndex];\n\t\tconst command = shot.run[timing.command];\n\t\tif (command.type === 'wait') continue;\n\t\tif (command.type === 'play') {\n\t\t\t// A clip: each of its commands becomes its own job, at its time in the clip.\n\t\t\tconst f = motionShotTimeScale(shot);\n\t\t\tcommand.targets.forEach((target, k) => {\n\t\t\t\tif (!nodes.has(target)) return;\n\t\t\t\tconst at = timing.start + k * (command.stagger ?? 0) * f;\n\t\t\t\tfor (const item of motionClipLayout(scene, command.clip, target, (command.speed ?? 1) / f).items) {\n\t\t\t\t\tconst entry = nodes.get(item.target);\n\t\t\t\t\tif (!entry) continue;\n\t\t\t\t\tjobs.push({ start: at + item.start, order: order++, run: () => compileRepeated(item.command, item.target, entry, at + item.start, item.cycle, timing) });\n\t\t\t\t}\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tcommand.targets.forEach((target, k) => {\n\t\t\tconst entry = nodes.get(target);\n\t\t\tif (!entry) return;\n\t\t\tconst f = motionShotTimeScale(shot);\n\t\t\tconst start = timing.start + k * (command.stagger ?? 0) * f;\n\t\t\tconst cycle = motionCycleDuration(command, scene, target) * f;\n\t\t\tjobs.push({ start, order: order++, run: () => compileRepeated(command, target, entry, start, cycle, timing) });\n\t\t});\n\t}\n\tjobs.sort((a, b) => a.start - b.start || a.order - b.order).forEach((job) => job.run());\n\n\t/**\n\t * Compiles one cycle, then lays further cycles after it: `loop` restarts each from the first\n\t * cycle's start, `mirror` plays every other one backwards, `offset` carries numbers on from\n\t * where the last ended. Stepped time goes on every segment the command makes.\n\t */\n\tfunction compileRepeated(command: Exclude<MotionCommand, { type: 'wait' }>, node: string, entry: MotionNodeEntry, start: number, cycle: number, timing: MotionCommandTiming) {\n\t\tconst first = segments.length;\n\t\tcompileCommand(command, node, entry, start, cycle, timing);\n\t\tconst made = segments.slice(first);\n\t\tconst steps = command.steps ?? scene.steps;\n\t\tif (steps && steps > 0) for (const s of made) s.steps = steps;\n\t\tconst n = motionCommandRepeat(command);\n\t\tconst mode = command.repeatMode ?? 'loop';\n\t\tconst shift = (v: MotionValue, by: MotionValue, k: number): MotionValue => {\n\t\t\tif (typeof v === 'number' && typeof by === 'number') return v + by * k;\n\t\t\tif (Array.isArray(v) && Array.isArray(by) && v.length === by.length) return v.map((x, i) => x + (by[i] as number) * k);\n\t\t\treturn v;\n\t\t};\n\t\tfor (let k = 1; k < n; k++) {\n\t\t\tconst at = start + k * cycle;\n\t\t\tfor (const s of made) {\n\t\t\t\tif (mode === 'mirror' && k % 2 === 1) {\n\t\t\t\t\tpush({ ...s, start: at + (start + cycle - s.end), end: at + (start + cycle - s.start), reverse: !s.reverse });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst delta: MotionValue = typeof s.from === 'number' && typeof s.to === 'number' ? s.to - s.from : Array.isArray(s.from) && Array.isArray(s.to) && s.from.length === s.to.length ? s.to.map((x, i) => (x as number) - (s.from as number[])[i]) : 0;\n\t\t\t\tconst by = mode === 'offset' ? delta : 0;\n\t\t\t\tpush({ ...s, start: at + (s.start - start), end: at + (s.end - start), from: shift(s.from, by, k), to: shift(s.to, by, k) });\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction compileCommand(command: Exclude<MotionCommand, { type: 'wait' }>, node: string, entry: MotionNodeEntry, start: number, duration: number, timing: MotionCommandTiming) {\n\t\tconst end = start + duration;\n\t\tconst where = { shot: timing.shot, command: timing.command };\n\t\tconst seg = (property: MotionProperty, to: MotionValue, ease: AnimationEasing, s = start, e = end, extra: Partial<MotionSegment> = {}) =>\n\t\t\tpush({ node, property, start: s, end: e, from: extra.from ?? valueAt(node, property, s), to, ease, ...where, ...extra });\n\t\tconst rest = (p: MotionProperty) => motionRestValue(entry, p, artwork);\n\t\tconst num = (p: MotionProperty, time = start) => {\n\t\t\tconst v = valueAt(node, p, time);\n\t\t\treturn typeof v === 'number' ? v : 0;\n\t\t};\n\t\tconst ease = command.ease;\n\t\t/**\n\t\t * When each stroke of the target draws, for an order other than all at once over the whole\n\t\t * time (null then): one after another by length, or all at one speed.\n\t\t */\n\t\tconst drawWindows = (s: number, e: number, o: MotionDrawOrder): { id: string; start: number; end: number }[] | null => {\n\t\t\tconst order = o.order ?? 'together';\n\t\t\tconst pace = o.pace ?? 'time';\n\t\t\tif (order === 'together' && pace === 'time') return null;\n\t\t\tconst paths = entry.node.type === 'path' ? [entry.node] : collectPathNodes(entry.node);\n\t\t\tlet list = paths.map((p) => {\n\t\t\t\tconst at = nodes.get(p.id);\n\t\t\t\tlet first = { x: 0, y: 0 };\n\t\t\t\ttry {\n\t\t\t\t\tconst m = vectorPathWorldBezier(p, at?.parentWorld ?? IDENTITY_MATRIX, { effects: false })[0];\n\t\t\t\t\tif (m && m.type === 'M') first = { x: m.x, y: m.y };\n\t\t\t\t} catch {\n\t\t\t\t\t/* unmeasurable: sorts first */\n\t\t\t\t}\n\t\t\t\treturn { id: p.id, len: Math.max(1e-6, motionPathLength(p, at?.parentWorld)), first };\n\t\t\t});\n\t\t\tif (!list.length) return null;\n\t\t\tconst span = Math.max(0, e - s);\n\t\t\tif (order === 'sequence') {\n\t\t\t\tif (o.sortBy === 'distance') {\n\t\t\t\t\tconst b = entry.bounds;\n\t\t\t\t\tconst origin = o.origin ?? (b ? { x: b.x + b.width / 2, y: b.y + b.height / 2 } : { x: 0, y: 0 });\n\t\t\t\t\tlist = [...list].sort((a, c) => Math.hypot(a.first.x - origin.x, a.first.y - origin.y) - Math.hypot(c.first.x - origin.x, c.first.y - origin.y));\n\t\t\t\t}\n\t\t\t\tconst total = list.reduce((sum, p) => sum + p.len, 0);\n\t\t\t\tlet at = s;\n\t\t\t\treturn list.map((p) => {\n\t\t\t\t\tconst w = { id: p.id, start: at, end: at + (span * p.len) / total };\n\t\t\t\t\tat = w.end;\n\t\t\t\t\treturn w;\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst longest = Math.max(...list.map((p) => p.len));\n\t\t\treturn list.map((p) => {\n\t\t\t\tconst d = (span * p.len) / longest;\n\t\t\t\treturn o.align === 'end' ? { id: p.id, start: e - d, end: e } : { id: p.id, start: s, end: s + d };\n\t\t\t});\n\t\t};\n\t\tswitch (command.type) {\n\t\t\tcase 'enter': {\n\t\t\t\tconst style = command.style ?? 'fade';\n\t\t\t\tconst opacity = rest('opacity');\n\t\t\t\tconst reveal =\n\t\t\t\t\tstyle === 'wipe' ? motionRevealClip(entry, { style, direction: command.direction }) : style === 'iris' ? motionRevealClip(entry, { style, shape: command.shape }) : style === 'split' ? motionRevealClip(entry, { style, orientation: command.orientation }) : null;\n\t\t\t\t// An earlier reveal or wipe out leaves its clip; entering opens it again, at once.\n\t\t\t\tfor (const p of ['clipRect', 'clipCircle'] as const) if (p !== reveal?.property && tracks.has(motionTrackKey(node, p))) seg(p, rest(p), 'linear', start, start);\n\t\t\t\tif (reveal) {\n\t\t\t\t\t// The clip reveals. Opacity is set at once too, so a node faded out before shows again,\n\t\t\t\t\t// and a later fade in (whose start would hold back to time 0) leaves this one alone.\n\t\t\t\t\tseg('opacity', opacity, 'linear', start, start);\n\t\t\t\t\tseg(reveal.property, reveal.to, ease ?? MOTION_EASE_OUT, start, end, { from: reveal.from });\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (style === 'draw') {\n\t\t\t\t\tconst windows = drawWindows(start, start + duration * 0.75, command);\n\t\t\t\t\tif (windows) for (const w of windows) push({ node: w.id, property: 'drawEnd', start: w.start, end: w.end, from: 0, to: 1, ease: ease ?? MOTION_EASE_IN_OUT, ...where });\n\t\t\t\t\telse seg('drawEnd', 1, ease ?? MOTION_EASE_IN_OUT, start, start + duration * 0.75, { from: 0 });\n\t\t\t\t\tseg('fillOpacity', 1, MOTION_EASE_OUT, start + duration * 0.6, end, { from: 0 });\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (style === 'pop' || style === 'zoom') {\n\t\t\t\t\tconst from = command.scale ?? (style === 'pop' ? 0.5 : 1.6);\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, start + duration * (style === 'pop' ? 0.4 : 0.5), { from: 0 });\n\t\t\t\t\tseg('scaleX', 1, ease ?? (style === 'pop' ? 'ease-out-back' : MOTION_EASE_OUT), start, end, { from });\n\t\t\t\t\tseg('scaleY', 1, ease ?? (style === 'pop' ? 'ease-out-back' : MOTION_EASE_OUT), start, end, { from });\n\t\t\t\t} else if (style === 'rise') {\n\t\t\t\t\tconst y = num('y');\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, start + duration * 0.5, { from: 0 });\n\t\t\t\t\tseg('y', y, ease ?? 'ease-out-back', start, end, { from: y + (command.distance ?? 20) });\n\t\t\t\t} else if (style === 'grow') {\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, start + duration * 0.3, { from: 0 });\n\t\t\t\t\tseg('scaleX', 1, ease ?? MOTION_EASE_OUT, start, end, { from: 0 });\n\t\t\t\t\tseg('scaleY', 1, ease ?? MOTION_EASE_OUT, start, end, { from: 0 });\n\t\t\t\t} else if (style === 'slide') {\n\t\t\t\t\tconst dir = DIRECTION[command.direction ?? 'up'];\n\t\t\t\t\tconst distance = command.distance ?? 40;\n\t\t\t\t\tconst x = num('x');\n\t\t\t\t\tconst y = num('y');\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, end, { from: 0 });\n\t\t\t\t\tseg('x', x, ease ?? MOTION_EASE_OUT, start, end, { from: x - dir.x * distance });\n\t\t\t\t\tseg('y', y, ease ?? MOTION_EASE_OUT, start, end, { from: y - dir.y * distance });\n\t\t\t\t} else seg('opacity', opacity, ease ?? MOTION_EASE_OUT, start, end, { from: 0 }); // fade, and a reveal of a node with no box\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'exit': {\n\t\t\t\tconst style = command.style ?? 'fade';\n\t\t\t\tconst wipe = style === 'wipe' ? motionRevealClip(entry, { style, direction: command.direction, hide: true }) : null;\n\t\t\t\tif (wipe) seg(wipe.property, wipe.to, ease ?? 'ease-in', start, end, { from: wipe.from });\n\t\t\t\telse if (style === 'undraw') {\n\t\t\t\t\tseg('fillOpacity', 0, 'ease-in', start, start + duration * 0.4);\n\t\t\t\t\tconst windows = drawWindows(start, end, command);\n\t\t\t\t\tif (windows) for (const w of windows) push({ node: w.id, property: 'drawEnd', start: w.start, end: w.end, from: valueAt(w.id, 'drawEnd', w.start), to: 0, ease: ease ?? MOTION_EASE_IN_OUT, ...where });\n\t\t\t\t\telse seg('drawEnd', 0, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\t} else if (style === 'shrink') {\n\t\t\t\t\tseg('scaleX', 0, ease ?? 'ease-in');\n\t\t\t\t\tseg('scaleY', 0, ease ?? 'ease-in');\n\t\t\t\t\tseg('opacity', 0, 'ease-in', start + duration * 0.6, end);\n\t\t\t\t} else if (style === 'slide') {\n\t\t\t\t\tconst dir = DIRECTION[command.direction ?? 'down'];\n\t\t\t\t\tconst distance = command.distance ?? 40;\n\t\t\t\t\tseg('x', num('x') + dir.x * distance, ease ?? 'ease-in');\n\t\t\t\t\tseg('y', num('y') + dir.y * distance, ease ?? 'ease-in');\n\t\t\t\t\tseg('opacity', 0, ease ?? 'ease-in');\n\t\t\t\t} else seg('opacity', 0, ease ?? 'ease-in'); // fade, and a wipe of a node with no box\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'draw': {\n\t\t\t\t// A stroke not drawn before draws on from nothing (and is hidden until then).\n\t\t\t\tconst e = ease ?? MOTION_EASE_IN_OUT;\n\t\t\t\tconst comet = command.comet !== undefined ? Math.min(1, Math.max(0, command.comet)) : undefined;\n\t\t\t\tconst windows = drawWindows(start, end, command) ?? [{ id: node, start, end }];\n\t\t\t\tfor (const w of windows) {\n\t\t\t\t\tif (comet !== undefined) {\n\t\t\t\t\t\t// A travelling stroke: the head runs 0 → 1 + comet and the tail comet behind it, both clamped, so it leaves the path empty.\n\t\t\t\t\t\tpush({ node: w.id, property: 'drawEnd', start: w.start, end: w.end, from: 0, to: 1 + comet, ease: e, ...where });\n\t\t\t\t\t\tpush({ node: w.id, property: 'drawStart', start: w.start, end: w.end, from: -comet, to: 1, ease: e, ...where });\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst drawn = tracks.has(motionTrackKey(w.id, 'drawEnd'));\n\t\t\t\t\tpush({ node: w.id, property: 'drawEnd', start: w.start, end: w.end, from: command.from ?? (drawn ? valueAt(w.id, 'drawEnd', w.start) : 0), to: command.to ?? 1, ease: e, ...where });\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'move': {\n\t\t\t\tconst e = ease ?? MOTION_EASE_IN_OUT;\n\t\t\t\tlet dx = command.by?.x ?? 0;\n\t\t\t\tlet dy = command.by?.y ?? 0;\n\t\t\t\tif (command.to) {\n\t\t\t\t\t// The centre lands on `to` (document space): convert the remaining offset to the parent's space.\n\t\t\t\t\tconst inv = invertMatrix(entry.parentWorld);\n\t\t\t\t\tconst target = applyMatrix(inv, command.to);\n\t\t\t\t\tdx = target.x - (entry.center.x + num('x'));\n\t\t\t\t\tdy = target.y - (entry.center.y + num('y'));\n\t\t\t\t}\n\t\t\t\tif (command.via?.length) {\n\t\t\t\t\t// Through waypoints: offsets per axis as monotone cubics, one eased leg per stretch.\n\t\t\t\t\tconst inv = invertMatrix(entry.parentWorld);\n\t\t\t\t\tconst x0 = num('x');\n\t\t\t\t\tconst y0 = num('y');\n\t\t\t\t\tconst add = command.blend === 'add';\n\t\t\t\t\tconst offsets = [{ x: 0, y: 0 }, ...command.via.map((p) => applyMatrix(inv, p)).map((p) => ({ x: p.x - entry.center.x - x0, y: p.y - entry.center.y - y0 })), { x: dx, y: dy }];\n\t\t\t\t\tconst times = smoothMotionTimes(offsets, start, end - start, command.pacing ?? 'even');\n\t\t\t\t\tfor (const axis of ['x', 'y'] as const) {\n\t\t\t\t\t\tconst base = add ? 0 : axis === 'x' ? x0 : y0;\n\t\t\t\t\t\tfor (const leg of smoothMotionLegs(times, offsets.map((o) => o[axis])))\n\t\t\t\t\t\t\tseg(axis, base + leg.to, leg.ease, leg.start, leg.end, { from: base + leg.from, ...(add ? { blend: 'add' as const } : {}) });\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (command.blend === 'add') {\n\t\t\t\t\tseg('x', dx, e, start, end, { from: 0, blend: 'add' });\n\t\t\t\t\tseg('y', dy, e, start, end, { from: 0, blend: 'add' });\n\t\t\t\t} else {\n\t\t\t\t\tseg('x', num('x') + dx, e);\n\t\t\t\t\tseg('y', num('y') + dy, e);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'rotate': {\n\t\t\t\tconst e = ease ?? MOTION_EASE_IN_OUT;\n\t\t\t\tif (command.blend === 'add') seg('rotation', command.to !== undefined ? command.to - num('rotation') : (command.by ?? 0), e, start, end, { from: 0, blend: 'add' });\n\t\t\t\telse seg('rotation', command.to ?? num('rotation') + (command.by ?? 0), e);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'scale': {\n\t\t\t\tconst to = typeof command.to === 'number' ? { x: command.to, y: command.to } : command.to;\n\t\t\t\tconst extra = { ...(command.geometric ? { geometric: true } : {}), ...(command.blend === 'add' ? { from: 1, blend: 'add' as const } : {}) };\n\t\t\t\tseg('scaleX', to.x, ease ?? MOTION_EASE_IN_OUT, start, end, extra);\n\t\t\t\tseg('scaleY', to.y, ease ?? MOTION_EASE_IN_OUT, start, end, extra);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'fade':\n\t\t\t\tseg('opacity', command.to, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\n\t\t\tcase 'style':\n\t\t\t\tif (command.fill !== undefined) seg('fill', command.fill, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tif (command.stroke !== undefined) seg('stroke', command.stroke, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tif (command.strokeWidth !== undefined) seg('strokeWidth', command.strokeWidth, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\n\t\t\tcase 'morph':\n\t\t\t\tseg('shape', command.into, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\n\t\t\tcase 'match': {\n\t\t\t\t// Smart Animate: each part morphs into its partner in `into`; parts with no partner fade out.\n\t\t\t\tconst into = nodes.get(command.into);\n\t\t\t\tif (!into || command.into === node) break;\n\t\t\t\tconst match = matchMotionNodes(entry.node, into.node);\n\t\t\t\tconst e = ease ?? MOTION_EASE_IN_OUT;\n\t\t\t\tfor (const [a, b] of match.pairs) push({ node: a, property: 'shape', start, end, from: valueAt(a, 'shape', start), to: b, ease: e, ...where });\n\t\t\t\tfor (const a of match.unpairedFrom) push({ node: a, property: 'opacity', start, end, from: valueAt(a, 'opacity', start), to: 0, ease: e, ...where });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'follow':\n\t\t\t\tseg('follow', command.to ?? 1, ease ?? MOTION_EASE_IN_OUT, start, end, { from: command.from ?? 0, path: command.path, rotate: command.rotate ?? false });\n\t\t\t\tbreak;\n\t\t\t// Emphasis: a change toward a peak that a behaviour swings round (as Flair's primitives do).\n\t\t\tcase 'pulse':\n\t\t\tcase 'shake':\n\t\t\tcase 'teeter':\n\t\t\tcase 'wave':\n\t\t\tcase 'wiggle': {\n\t\t\t\t// Emphasis is a layer over the pose by default (blend \"add\"), so it rides on a move or turn under way.\n\t\t\t\tconst add = (command.blend ?? 'add') === 'add';\n\t\t\t\t// A change of `by` (offsets, turns) or by a factor (scales), as a layer or on the pose.\n\t\t\t\tconst swing = (p: MotionProperty, by: number, extra: Partial<MotionSegment>) => {\n\t\t\t\t\tconst scale = p === 'scaleX' || p === 'scaleY';\n\t\t\t\t\tif (add) seg(p, by, ease ?? 'linear', start, end, { from: scale ? 1 : 0, blend: 'add', ...extra });\n\t\t\t\t\telse seg(p, scale ? num(p) * by : num(p) + by, ease ?? 'linear', start, end, extra);\n\t\t\t\t};\n\t\t\t\tif (command.type === 'pulse') {\n\t\t\t\t\tconst behavior: MotionBehavior = { type: 'pulse', count: command.count ?? 1 };\n\t\t\t\t\tswing('scaleX', 1 + (command.amount ?? 0.15), { behavior });\n\t\t\t\t\tswing('scaleY', 1 + (command.amount ?? 0.15), { behavior });\n\t\t\t\t} else if (command.type === 'shake') swing(command.axis === 'vertical' ? 'y' : 'x', command.amount ?? 8, { behavior: { type: 'oscillate', count: command.count ?? 3, decay: 1 } });\n\t\t\t\telse if (command.type === 'teeter') swing('rotation', command.angle ?? 8, { behavior: { type: 'oscillate', count: command.count ?? 3, decay: 1 } });\n\t\t\t\telse if (command.type === 'wave') swing('y', -(command.amount ?? 6), { behavior: { type: 'oscillate', count: command.count ?? 2 } });\n\t\t\t\telse {\n\t\t\t\t\tconst behavior: MotionBehavior = { type: 'wriggle', frequency: command.frequency ?? 3, octaves: command.octaves ?? 2, seed: command.seed || motionSeedFromId(node) };\n\t\t\t\t\tconst amount = command.amount ?? 6;\n\t\t\t\t\tswing('x', amount, { behavior, index: 0 });\n\t\t\t\t\tswing('y', amount, { behavior, index: 1 });\n\t\t\t\t\tif (command.rotate) swing('rotation', command.rotate, { behavior, index: 2 });\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'color-pulse':\n\t\t\t\tseg(command.paint ?? 'fill', command.color ?? '#f59e0b', ease ?? 'linear', start, end, { behavior: { type: 'pulse', count: command.count ?? 1 } });\n\t\t\t\tbreak;\n\t\t\tcase 'effect':\n\t\t\t\tseg(`effect:${command.effect}:${command.param}`, command.to, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (const track of tracks.values()) track.sort((a, b) => a.start - b.start);\n\tsegments.sort((a, b) => a.start - b.start);\n\tconst duration = shots.length ? shots[shots.length - 1].end : 0;\n\tconst timeline: MotionTimeline = { duration, shots, commands, segments, tracks, ...(scene.drivers?.length ? { drivers: scene.drivers, restOpacity: new Map([...nodes].map(([id, e]) => [id, e.node.opacity ?? 1])) } : {}) };\n\ttimelineCache.set(scene, timeline);\n\treturn timeline;\n}\n\n/** The shot playing at `time` (the last one at the end). */\nexport function motionShotAt(timeline: MotionTimeline, time: number): MotionShotTiming | undefined {\n\treturn timeline.shots.find((s) => time < s.end) ?? timeline.shots[timeline.shots.length - 1];\n}\n","import { normalizeTokenColor, hexToRgba, rgbaToHex } from '../tokens/color.js';\nimport { createVectorMorph, type VectorMorph } from '../vector/blend.js';\nimport { bezierPathLength, bezierPathPointAtLength, transformBezierPath, type BezierPath } from '../canvas/pathops/bezier.js';\nimport { createVectorEffect } from '../vector/appearance.js';\nimport { invertMatrix, multiplyMatrices, nodeMatrix, rotateMatrix, scaleMatrix, translateMatrix, vectorPathWorldBezier, isIdentityMatrix, type AffineMatrix } from '../vector/geometry.js';\nimport { vectorDocumentToSvg, type VectorSvgExportOptions, type VectorSvgWrapper } from '../vector/svg.js';\nimport type { VectorDocument, VectorEffect, VectorGradient, VectorNode, VectorPaint, VectorPathNode } from '../vector/types.js';\nimport { activeSegment, compileMotionScene, indexMotionNodes, motionAddTrackKey, motionTrackKey, withMotionLayers, segmentProgress, trackValue, type MotionNodeEntry, type MotionProperty, type MotionTimeline, applyMotionDrivers, motionDrivenNodes, motionPropertyValue } from './compile.js';\nimport type { MotionDrivenProperty, MotionRect, MotionScene } from './types.js';\n\n/**\n * A reveal clip (`wipe`, `iris`, `split`) in the units of the node's own box: 0–1 across it,\n * as SVG's `clipPathUnits=\"objectBoundingBox\"` and Flair's clip reveals are.\n */\nexport type MotionClipShape = { shape: 'rect'; x: number; y: number; width: number; height: number } | { shape: 'circle'; cx: number; cy: number; r: number };\n\n/** The artwork as it stands at one time, and where the camera looks. */\nexport interface MotionFrame {\n\ttime: number;\n\tdocument: VectorDocument;\n\tcamera: MotionRect;\n\t/**\n\t * Reveal clips by node id, outermost first: draw each of those nodes inside a group clipped\n\t * to each shape (`motionFrameToSvg` does). The vector model has no clips, so they ride here.\n\t */\n\tclips: Record<string, MotionClipShape[]>;\n}\n\nexport interface MotionFrameOptions {\n\t/** Control values (`{ accent: \"#0ea5e9\" }`): each recolours its control's default colour. */\n\tvalues?: Record<string, string>;\n\t/** Draw-on as a Trim Paths effect (default true). Off leaves strokes whole. */\n\tdraw?: boolean;\n\t/** Apply moves, turns, scales and follows (default true). Off leaves nodes where they rest. */\n\toffsets?: boolean;\n}\n\n/** Id of the trim effect that draws strokes on. */\nexport const MOTION_DRAW_EFFECT_ID = '~draw';\n\nconst TRANSFORM_PROPS: MotionProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'follow'];\nconst tidy = (v: number) => Math.round(v * 1e6) / 1e6 || 0;\n\n/** A copy of the scene with each control's default colour replaced by its value (exact, case-insensitive matches). */\nexport function applyMotionControlValues(scene: MotionScene, values: Record<string, string> | undefined): MotionScene {\n\tif (!values || !scene.controls?.length) return scene;\n\tconst map = new Map<string, string>();\n\tfor (const control of scene.controls) {\n\t\tconst value = values[control.name];\n\t\tif (typeof value === 'string' && normalizeTokenColor(value) !== null) map.set(control.default.toLowerCase(), value);\n\t}\n\tif (!map.size) return scene;\n\tconst walk = (v: unknown): unknown => {\n\t\tif (typeof v === 'string') return map.get(v.toLowerCase()) ?? v;\n\t\tif (Array.isArray(v)) return v.map(walk);\n\t\tif (v && typeof v === 'object') return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]));\n\t\treturn v;\n\t};\n\treturn { ...scene, artwork: walk(scene.artwork) as VectorDocument, shots: walk(scene.shots) as MotionScene['shots'] };\n}\n\n/** `color` with its alpha multiplied by `alpha` (as `#rrggbbaa`), or `color` when unreadable. */\nfunction fadeColor(color: string, alpha: number): string {\n\tconst hex = normalizeTokenColor(color);\n\tif (hex === null) return color;\n\tconst c = hexToRgba(hex)!;\n\treturn rgbaToHex(c.r, c.g, c.b, c.a * alpha);\n}\n\nfunction fadePaint(paint: VectorPaint | undefined, alpha: number): VectorPaint | undefined {\n\tif (alpha >= 1 || paint == null || paint === 'none') return paint;\n\tif (typeof paint === 'string') return fadeColor(paint, alpha);\n\tif ('stops' in paint && Array.isArray(paint.stops)) return { ...(paint as VectorGradient), stops: paint.stops.map((s) => ({ ...s, opacity: (s.opacity ?? 1) * alpha })) } as VectorGradient;\n\treturn paint;\n}\n\n/** Applies `fn` to the node if it is a path, else to every path inside it. */\nfunction mapPaths(node: VectorNode, fn: (path: VectorPathNode) => VectorPathNode): VectorNode {\n\tif (node.type === 'path') return fn(node);\n\treturn { ...node, children: node.children.map((c) => mapPaths(c, fn)) };\n}\n\nconst morphCache = new WeakMap<VectorNode, WeakMap<VectorNode, VectorMorph>>();\nfunction morphBetween(a: VectorNode, b: VectorNode): VectorMorph {\n\tlet inner = morphCache.get(a);\n\tif (!inner) morphCache.set(a, (inner = new WeakMap()));\n\tlet morph = inner.get(b);\n\tif (!morph) inner.set(b, (morph = createVectorMorph(a, b, { id: a.id })));\n\treturn morph;\n}\n\n/** A shape node by id as it rests in its own parent, mapped into `entry`'s parent space. */\nfunction shapeIn(entry: MotionNodeEntry, shape: MotionNodeEntry): VectorNode {\n\tif (shape === entry) return entry.node;\n\tconst m = multiplyMatrices(multiplyMatrices(nodeMatrix(shape.node), shape.parentWorld), invertMatrix(entry.parentWorld));\n\treturn { ...shape.node, ...(isIdentityMatrix(m) ? { transform: undefined } : { transform: m as VectorNode['transform'] }) } as VectorNode;\n}\n\n/** The node's own shape at `time` (a morph in progress, or the shape it last became). */\nfunction shapeAt(entry: MotionNodeEntry, timeline: MotionTimeline, nodes: Map<string, MotionNodeEntry>, time: number): VectorNode | null {\n\tconst track = timeline.tracks.get(motionTrackKey(entry.node.id, 'shape'));\n\tif (!track?.length) return null;\n\tconst s = activeSegment(track, time);\n\tconst fromId = String(s ? s.from : track[0].from);\n\tif (!s) return fromId === entry.node.id ? null : (nodes.get(fromId) ? shapeIn(entry, nodes.get(fromId)!) : null);\n\tconst a = nodes.get(fromId);\n\tconst b = nodes.get(String(s.to));\n\tif (!a || !b) return null;\n\tconst { eased } = segmentProgress(s, time);\n\tconst u = Math.min(1, Math.max(0, eased));\n\tif (u <= 0) return a === entry ? null : shapeIn(entry, a);\n\tif (u >= 1) return b === entry ? null : shapeIn(entry, b);\n\treturn morphBetween(shapeIn(entry, a), shapeIn(entry, b)).at(u);\n}\n\n/**\n * The path a node follows, in the node's parent's space (live effects left off), or null when\n * `path` is not a path or cannot be measured. Lengths and turns along it are measured there.\n */\nexport function motionFollowRoute(entry: MotionNodeEntry, path: MotionNodeEntry | undefined): BezierPath | null {\n\tif (!path || path.node.type !== 'path') return null;\n\ttry {\n\t\treturn transformBezierPath(vectorPathWorldBezier(path.node, path.parentWorld, { effects: false }), invertMatrix(entry.parentWorld));\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** Where a follow puts the node's centre (parent space), and the path's angle there in degrees. */\nfunction followAt(entry: MotionNodeEntry, timeline: MotionTimeline, nodes: Map<string, MotionNodeEntry>, time: number): { x: number; y: number; angle: number } | null {\n\tconst track = timeline.tracks.get(motionTrackKey(entry.node.id, 'follow'));\n\tconst s = activeSegment(track, time) ?? track?.[0];\n\tif (!s?.path) return null;\n\tconst route = motionFollowRoute(entry, nodes.get(s.path));\n\tconst progress = Number(trackValue(track, time));\n\tif (!route || !(progress >= 0)) return null;\n\ttry {\n\t\tconst at = bezierPathPointAtLength(route, Math.min(1, Math.max(0, progress)) * bezierPathLength(route));\n\t\tif (!at) return null;\n\t\treturn { x: at.point[0], y: at.point[1], angle: s.rotate ? (at.angle * 180) / Math.PI : 0 };\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * The transform a node's offsets, turn, scale and follow add (parent space), or null when none:\n * scaled and turned about its centre, offset by `dx`, `dy`, then (following a path) its centre\n * carried to the point on the path and turned with it, as Flair's `along` carries a wrapper.\n * `raw` ignores behaviours (the pose a pulse or shake swings towards, as Flair is given it);\n * `follow: false` leaves the follow out (`dx` … `scaleY` never include it).\n */\nexport function motionNodeOffset(\n\tentry: MotionNodeEntry,\n\ttimeline: MotionTimeline,\n\ttime: number,\n\tnodes = indexMotionNodes([entry.node]),\n\traw = false,\n\tfollow = true\n): { matrix: AffineMatrix; dx: number; dy: number; rotation: number; scaleX: number; scaleY: number; follow: { x: number; y: number; angle: number } | null } | null {\n\t// The pose, with any additive layers (emphasis, blend \"add\") on top.\n\tconst read = (p: MotionProperty, rest: number) => {\n\t\tconst v = trackValue(timeline.tracks.get(motionTrackKey(entry.node.id, p)), time, raw);\n\t\tconst layered = withMotionLayers(timeline, entry.node.id, p, typeof v === 'number' ? v : rest, time, raw);\n\t\t// Drivers: properties that follow other nodes' properties.\n\t\treturn p === 'follow' ? layered : applyMotionDrivers(timeline, entry.node.id, p as MotionDrivenProperty, layered, time, raw);\n\t};\n\tconst driven = timeline.drivers?.some((d) => d.target === entry.node.id && d.property !== 'opacity');\n\tif (!driven && !TRANSFORM_PROPS.some((p) => (follow || p !== 'follow') && (timeline.tracks.has(motionTrackKey(entry.node.id, p)) || timeline.tracks.has(motionAddTrackKey(entry.node.id, p))))) return null;\n\tconst dx = read('x', 0);\n\tconst dy = read('y', 0);\n\tconst rotation = read('rotation', 0);\n\tconst scaleX = read('scaleX', 1);\n\tconst scaleY = read('scaleY', 1);\n\tconst c = entry.center;\n\tlet matrix = multiplyMatrices(multiplyMatrices(scaleMatrix(scaleX, scaleY, c), rotateMatrix(rotation, c)), translateMatrix(dx, dy));\n\tconst along = follow ? followAt(entry, timeline, nodes, time) : null;\n\tif (along) matrix = multiplyMatrices(matrix, multiplyMatrices(multiplyMatrices(translateMatrix(-c.x, -c.y), rotateMatrix(along.angle)), translateMatrix(along.x, along.y)));\n\treturn { matrix, dx, dy, rotation, scaleX, scaleY, follow: along };\n}\n\n/** A node's reveal clips at `time`, outermost first (rect, then circle), with sizes kept ≥ 0. */\nexport function motionNodeClips(id: string, timeline: MotionTimeline, time: number): MotionClipShape[] {\n\tconst out: MotionClipShape[] = [];\n\tconst rect = trackValue(timeline.tracks.get(motionTrackKey(id, 'clipRect')), time);\n\tif (Array.isArray(rect) && rect.length === 4) out.push({ shape: 'rect', x: tidy(rect[0]), y: tidy(rect[1]), width: Math.max(0, tidy(rect[2])), height: Math.max(0, tidy(rect[3])) });\n\tconst circle = trackValue(timeline.tracks.get(motionTrackKey(id, 'clipCircle')), time);\n\tif (Array.isArray(circle) && circle.length === 3) out.push({ shape: 'circle', cx: tidy(circle[0]), cy: tidy(circle[1]), r: Math.max(0, tidy(circle[2])) });\n\treturn out;\n}\n\n/**\n * The scene at `time` (ms): the artwork with every change applied, and the camera. A pure\n * function of time, so frames can be drawn in any order (and the same frames come out every time).\n */\nexport function motionFrameAt(scene: MotionScene, time: number, options: MotionFrameOptions = {}): MotionFrame {\n\tconst s = applyMotionControlValues(scene, options.values);\n\tconst timeline = compileMotionScene(s);\n\tconst nodes = indexMotionNodes(s.artwork.nodes);\n\tconst drawOn = options.draw !== false;\n\tconst value = (id: string, p: MotionProperty) => trackValue(timeline.tracks.get(motionTrackKey(id, p)), time);\n\tconst animated = new Set([...timeline.segments.map((seg) => seg.node), ...motionDrivenNodes(timeline)]);\n\tconst clips: Record<string, MotionClipShape[]> = {};\n\n\tconst visit = (node: VectorNode): VectorNode => {\n\t\tlet out: VectorNode = node.type === 'group' ? { ...node, children: node.children.map(visit) } : node;\n\t\tif (!animated.has(node.id)) return out;\n\t\tconst entry = nodes.get(node.id);\n\t\tif (!entry) return out;\n\t\tconst id = node.id;\n\t\tconst clip = motionNodeClips(id, timeline, time);\n\t\tif (clip.length) clips[id] = clip;\n\n\t\tconst shape = shapeAt(entry, timeline, nodes, time);\n\t\tif (shape) {\n\t\t\tconst { name, visible, opacity, locked } = node;\n\t\t\tout = { ...shape, id, ...(name ? { name } : {}), ...(locked ? { locked } : {}), visible, ...(opacity !== undefined ? { opacity } : {}) } as VectorNode;\n\t\t\tif (out.visible === undefined) delete out.visible;\n\t\t}\n\n\t\t// Live path effect parameters.\n\t\tconst effectTracks = [...timeline.tracks.keys()].filter((k) => k.startsWith(`${id}\\u0000effect:`));\n\t\tif (effectTracks.length && out.effects?.length) {\n\t\t\tout = {\n\t\t\t\t...out,\n\t\t\t\teffects: out.effects.map((effect) => {\n\t\t\t\t\tlet params = effect.params as unknown as Record<string, unknown>;\n\t\t\t\t\tfor (const key of effectTracks) {\n\t\t\t\t\t\tconst [, effectId, param] = key.split('\\u0000')[1].split(':');\n\t\t\t\t\t\tif (effectId !== effect.id) continue;\n\t\t\t\t\t\tconst v = trackValue(timeline.tracks.get(key), time);\n\t\t\t\t\t\tif (typeof v === 'number') params = { ...params, [param]: v };\n\t\t\t\t\t}\n\t\t\t\t\treturn params === (effect.params as unknown) ? effect : ({ ...effect, params } as VectorEffect);\n\t\t\t\t})\n\t\t\t};\n\t\t}\n\n\t\tconst fill = value(id, 'fill');\n\t\tconst stroke = value(id, 'stroke');\n\t\tconst strokeWidth = value(id, 'strokeWidth');\n\t\tconst fillOpacity = value(id, 'fillOpacity');\n\t\tconst drawStart = value(id, 'drawStart');\n\t\tconst drawEnd = value(id, 'drawEnd');\n\t\tconst draw = drawOn && (drawStart !== undefined || drawEnd !== undefined);\n\t\tif (fill !== undefined || stroke !== undefined || strokeWidth !== undefined || fillOpacity !== undefined || draw) {\n\t\t\tout = mapPaths(out, (path) => {\n\t\t\t\tlet p: VectorPathNode = path;\n\t\t\t\tif (typeof fill === 'string') p = { ...p, fill };\n\t\t\t\tif (typeof stroke === 'string') p = { ...p, stroke };\n\t\t\t\tif (typeof strokeWidth === 'number') p = { ...p, strokeWidth: Math.max(0, tidy(strokeWidth)) };\n\t\t\t\tif (typeof fillOpacity === 'number' && fillOpacity < 1) p = { ...p, fill: fadePaint(p.fill, Math.max(0, fillOpacity)) };\n\t\t\t\tif (draw) {\n\t\t\t\t\tconst start = Math.min(1, Math.max(0, typeof drawStart === 'number' ? drawStart : 0));\n\t\t\t\t\tconst end = Math.min(1, Math.max(0, typeof drawEnd === 'number' ? drawEnd : 1));\n\t\t\t\t\tif (start > 0 || end < 1) {\n\t\t\t\t\t\tconst trim = createVectorEffect('trim', MOTION_DRAW_EFFECT_ID, { start: tidy(start * 100), end: tidy(end * 100) })!;\n\t\t\t\t\t\tp = { ...p, effects: [trim, ...(p.effects ?? []).filter((e) => e.id !== MOTION_DRAW_EFFECT_ID)] };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn p;\n\t\t\t});\n\t\t}\n\n\t\tconst opacity = timeline.drivers?.some((d) => d.target === id && d.property === 'opacity') ? motionPropertyValue(timeline, id, 'opacity', time) : value(id, 'opacity');\n\t\tif (typeof opacity === 'number') {\n\t\t\tconst o = Math.min(1, Math.max(0, tidy(opacity)));\n\t\t\tout = { ...out, opacity: o };\n\t\t\tif (o >= 1) delete out.opacity;\n\t\t}\n\n\t\tconst offset = options.offsets === false ? null : motionNodeOffset(entry, timeline, time, nodes);\n\t\tif (offset && !isIdentityMatrix(offset.matrix)) {\n\t\t\tconst m = multiplyMatrices(nodeMatrix(out), offset.matrix).map(tidy) as unknown as VectorNode['transform'];\n\t\t\tout = { ...out, transform: m };\n\t\t}\n\t\treturn out;\n\t};\n\n\tconst document: VectorDocument = { ...s.artwork, nodes: s.artwork.nodes.map(visit) };\n\tconst cam = trackValue(timeline.tracks.get(motionTrackKey('', 'camera')), time);\n\tconst box = Array.isArray(cam) ? cam : [0, 0, s.artwork.width, s.artwork.height];\n\treturn { time, document, camera: { x: tidy(box[0]), y: tidy(box[1]), width: tidy(box[2]), height: tidy(box[3]) }, clips };\n}\n\nexport interface MotionSvgOptions extends MotionFrameOptions, VectorSvgExportOptions {}\n\n/** A clip shape's SVG attributes. */\nexport function motionClipAttrs(clip: MotionClipShape): Record<string, number> {\n\tconst { shape: _shape, ...attrs } = clip;\n\treturn attrs;\n}\n\n/** The scene at `time` as a standalone SVG (the camera becomes the `viewBox`, reveal clips wrap their nodes). */\nexport function motionFrameToSvg(scene: MotionScene, time: number, options: MotionSvgOptions = {}): string {\n\tconst frame = motionFrameAt(scene, time, options);\n\tconst prefix = options.idPrefix ?? 'vg-';\n\tconst wrap: Record<string, readonly VectorSvgWrapper[]> = { ...options.wrap };\n\tfor (const [id, clips] of Object.entries(frame.clips))\n\t\twrap[id] = [...(wrap[id] ?? []), ...clips.map((clip, i) => ({ clip: { id: `${prefix}reveal-${id}-${i}`, shape: clip.shape, attrs: motionClipAttrs(clip) } }))];\n\treturn withViewBox(vectorDocumentToSvg(frame.document, { ...options, wrap }), frame.camera);\n}\n\n/** Replaces the root `viewBox` of an SVG string. */\nexport function withViewBox(svg: string, box: MotionRect): string {\n\tconst f = (n: number) => String(Math.round(n * 1000) / 1000);\n\treturn svg.replace(/viewBox=\"[^\"]*\"/, `viewBox=\"${f(box.x)} ${f(box.y)} ${f(box.width)} ${f(box.height)}\"`);\n}\n","import { compileMotionScene, indexMotionNodes, type MotionProperty } from './compile.js';\nimport { motionFrameAt, motionFrameToSvg, type MotionSvgOptions } from './evaluate.js';\nimport type { MotionBlur, MotionRect, MotionScene } from './types.js';\n\n/**\n * Seeing motion on a still: onion skin (faded frames either side of the playhead) and motion\n * paths (where each node's centre travels). Frames are pure functions of time, so both are just\n * more frames: no state, and the same picture every time.\n */\n\nexport interface MotionOnionSkin {\n\t/** Ghost frames before the playhead (default 2). */\n\tbefore?: number;\n\t/** Ghost frames after the playhead (default 0). */\n\tafter?: number;\n\t/**\n\t * Time between ghosts: ms (default 1000 / 12, every other frame at 24 fps), or `commands` to\n\t * ghost the moments commands start and end around the playhead.\n\t */\n\tspacing?: number | 'commands';\n\t/** Opacity of the nearest ghost (default 0.35); further ones fade as 1 / distance. */\n\topacity?: number;\n}\n\nexport interface MotionGhost {\n\ttime: number;\n\t/** Negative before the playhead, positive after: 1 is the nearest. */\n\toffset: number;\n\topacity: number;\n}\n\n/** The ghost frames for a playhead at `time`, nearest first on each side. */\nexport function motionGhosts(scene: MotionScene, time: number, onion: MotionOnionSkin = {}): MotionGhost[] {\n\tconst before = Math.max(0, Math.floor(onion.before ?? 2));\n\tconst after = Math.max(0, Math.floor(onion.after ?? 0));\n\tconst base = Math.min(1, Math.max(0, onion.opacity ?? 0.35));\n\tconst timeline = compileMotionScene(scene);\n\tconst ghosts: MotionGhost[] = [];\n\tconst push = (t: number, offset: number) => ghosts.push({ time: t, offset, opacity: Math.round((base / Math.abs(offset)) * 1000) / 1000 });\n\tif (onion.spacing === 'commands') {\n\t\tconst marks = [...new Set(timeline.commands.flatMap((c) => [c.start, c.end]))].sort((a, b) => a - b);\n\t\tmarks.filter((t) => t < time - 1e-6).reverse().slice(0, before).forEach((t, i) => push(t, -(i + 1)));\n\t\tmarks.filter((t) => t > time + 1e-6).slice(0, after).forEach((t, i) => push(t, i + 1));\n\t\treturn ghosts;\n\t}\n\tconst spacing = typeof onion.spacing === 'number' && onion.spacing > 0 ? onion.spacing : 1000 / 12;\n\tfor (let i = 1; i <= before && time - i * spacing >= 0; i++) push(time - i * spacing, -i);\n\tfor (let i = 1; i <= after && time + i * spacing <= timeline.duration; i++) push(time + i * spacing, i);\n\treturn ghosts;\n}\n\nexport interface MotionPathOptions {\n\t/** From this time, ms (default 0). */\n\tfrom?: number;\n\t/** To this time, ms (default the end). */\n\tto?: number;\n\t/** Time between samples, ms (default 1000 / 30; at most 400 samples). */\n\tstep?: number;\n}\n\nexport interface MotionPath {\n\tid: string;\n\t/** Where the node's centre is, in document units, sample by sample. */\n\tpoints: { t: number; x: number; y: number }[];\n\t/** Where it is when a change that moves it (or a group it is in) starts or ends. */\n\tkeys: { t: number; x: number; y: number }[];\n}\n\nconst MOVING: MotionProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'follow', 'shape'];\n\n/** Ids of the nodes whose place changes (they or a group they are in move, turn, scale, follow or morph). */\nexport function motionMovingIds(scene: MotionScene): string[] {\n\tconst timeline = compileMotionScene(scene);\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst moving = new Set(timeline.segments.filter((s) => s.node && MOVING.includes(s.property)).map((s) => s.node));\n\treturn [...nodes.values()].filter((e) => e.node.visible !== false && (moving.has(e.node.id) || e.ancestors.some((a) => moving.has(a)))).map((e) => e.node.id);\n}\n\n/** Where a node's centre travels over time (its bounds as drawn, in document units). */\nexport function motionPath(scene: MotionScene, id: string, options: MotionPathOptions = {}): MotionPath {\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst entry = nodes.get(id);\n\tif (!entry) throw new Error(`There is no element \"${id}\" in the artwork.`);\n\tconst timeline = compileMotionScene(scene);\n\tconst from = Math.max(0, options.from ?? 0);\n\tconst to = Math.min(timeline.duration, options.to ?? timeline.duration);\n\tlet step = options.step && options.step > 0 ? options.step : 1000 / 30;\n\tif ((to - from) / step > 400) step = (to - from) / 400;\n\tconst r = (n: number) => Math.round(n * 100) / 100;\n\tconst centreAt = (t: number) => {\n\t\tconst node = indexMotionNodes(motionFrameAtCache(scene, t)).get(id);\n\t\tconst b = node?.bounds;\n\t\treturn b ? { t: r(t), x: r(b.x + b.width / 2), y: r(b.y + b.height / 2) } : null;\n\t};\n\tconst points: MotionPath['points'] = [];\n\tfor (let t = from; t <= to + 1e-6; t += step) {\n\t\tconst p = centreAt(Math.min(t, to));\n\t\tif (p) points.push(p);\n\t}\n\tconst owners = new Set([id, ...entry.ancestors]);\n\tconst times = [...new Set(timeline.segments.filter((s) => owners.has(s.node) && MOVING.includes(s.property)).flatMap((s) => [s.start, s.end]))].filter((t) => t >= from && t <= to).sort((a, b) => a - b);\n\tconst keys = times.map(centreAt).filter((p): p is NonNullable<typeof p> => p !== null);\n\treturn { id, points, keys };\n}\n\nfunction motionFrameAtCache(scene: MotionScene, t: number) {\n\treturn motionFrameAt(scene, t).document.nodes;\n}\n\n/** Motion paths as an SVG overlay: a line per node and a dot where each change starts or ends. Stroke widths follow the camera so they read the same at any zoom. */\nexport function motionPathsSvg(paths: readonly MotionPath[], camera: MotionRect, color = '#f43f5e'): string {\n\tconst w = Math.max(camera.width, camera.height) / 400;\n\tconst f = (n: number) => String(Math.round(n * 100) / 100);\n\treturn paths\n\t\t.filter((p) => p.points.length > 1)\n\t\t.map(\n\t\t\t(p) =>\n\t\t\t\t`<g data-motion-path=\"${p.id.replace(/\"/g, '"')}\" fill=\"none\" stroke=\"${color}\" stroke-width=\"${f(w)}\" stroke-linecap=\"round\" stroke-linejoin=\"round\" opacity=\"0.8\"><polyline points=\"${p.points.map((q) => `${f(q.x)},${f(q.y)}`).join(' ')}\" stroke-dasharray=\"${f(w * 3)} ${f(w * 2)}\"/>${p.keys.map((k) => `<circle cx=\"${f(k.x)}\" cy=\"${f(k.y)}\" r=\"${f(w * 2.5)}\" fill=\"${color}\" stroke=\"none\"/>`).join('')}</g>`\n\t\t)\n\t\t.join('');\n}\n\n/** What the stage can draw over a frame. */\nexport interface MotionOverlayOptions {\n\t/** Faded frames either side of the playhead. */\n\tonionSkin?: MotionOnionSkin;\n\t/** Draw where nodes travel: true for every node whose place changes, or a list of ids. */\n\tmotionPaths?: boolean | readonly string[];\n\t/** Colour of motion paths (default `#f43f5e`). */\n\tmotionPathColor?: string;\n\t/** Motion blur (default: the scene's `motionBlur`; false for none). */\n\tmotionBlur?: MotionBlur | false;\n}\n\n/**\n * The moments a frame at `time` averages for motion blur: spread across the shutter (centred on\n * `time`), as many as the fastest moving node needs to look smooth (about one per 1.5 document\n * units it travels), and just `[time]` when nothing moves.\n */\nexport function motionBlurTimes(scene: MotionScene, time: number, blur: MotionBlur = {}): number[] {\n\tconst shutter = Math.min(720, Math.max(0, blur.shutter ?? 180));\n\tconst most = Math.max(1, Math.min(32, Math.floor(blur.samples ?? 8)));\n\tconst span = ((1000 / (scene.fps ?? 30)) * shutter) / 360;\n\tif (span <= 0 || most <= 1) return [time];\n\tconst ids = motionMovingIds(scene);\n\tif (!ids.length) return [time];\n\tconst a = indexMotionNodes(motionFrameAt(scene, time - span / 2).document.nodes);\n\tconst b = indexMotionNodes(motionFrameAt(scene, time + span / 2).document.nodes);\n\tlet travel = 0;\n\tfor (const id of ids) {\n\t\tconst p = a.get(id)?.bounds;\n\t\tconst q = b.get(id)?.bounds;\n\t\tif (p && q) travel = Math.max(travel, Math.abs(p.x - q.x), Math.abs(p.y - q.y), Math.abs(p.x + p.width - q.x - q.width), Math.abs(p.y + p.height - q.y - q.height));\n\t}\n\tconst n = Math.min(most, Math.ceil(travel / 1.5));\n\tif (n <= 1) return [time];\n\treturn Array.from({ length: n }, (_, k) => time - span / 2 + (span * (k + 0.5)) / n);\n}\n\n/** Moments averaged into one picture: added (plus-lighter) at 1/n each in an isolated group, an exact average, transparency included. */\nfunction averagedFrames(scene: MotionScene, times: readonly number[], options: MotionSvgOptions, prefix: string): string {\n\tconst n = times.length;\n\treturn `<g data-motion-blur=\"${n}\" style=\"isolation:isolate\">${times\n\t\t.map((t, k) => {\n\t\t\tconst own = `${prefix}blur${k}-`;\n\t\t\tconst frame = motionFrameToSvg(scene, t, { ...options, idPrefix: own, background: false });\n\t\t\tconst view = /viewBox=\"([^\"]*)\"/.exec(frame)?.[1] ?? '';\n\t\t\t// Element ids stay on the last moment only, so the picture has each once.\n\t\t\tconst inner = k === n - 1 ? innerSvg(frame) : innerSvg(frame).replace(new RegExp(` id=\"(?!${own.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')})[^\"]*\"`, 'g'), '');\n\t\t\treturn `<svg viewBox=\"${view}\" preserveAspectRatio=\"none\" style=\"mix-blend-mode:plus-lighter\" opacity=\"${Math.round(10000 / n) / 10000}\">${inner}</svg>`;\n\t\t})\n\t\t.join('')}</g>`;\n}\n\n/** The inside of a standalone SVG (between its root tags). */\nconst innerSvg = (svg: string) => svg.slice(svg.indexOf('>') + 1, svg.lastIndexOf('</svg>'));\n\n/**\n * The frame at `time` as SVG with overlays: ghost frames under it (each with its own id prefix,\n * element ids dropped so they never clash) and motion paths over it. Without overlays it is\n * `motionFrameToSvg`.\n */\nexport function motionStageSvg(scene: MotionScene, time: number, options: MotionSvgOptions & MotionOverlayOptions = {}): string {\n\tconst { onionSkin, motionPaths, motionPathColor, motionBlur, ...svgOptions } = options;\n\tconst prefix = svgOptions.idPrefix ?? 'vg-';\n\tlet current = motionFrameToSvg(scene, time, svgOptions);\n\tconst blur = motionBlur === false ? undefined : (motionBlur ?? scene.motionBlur);\n\tconst blurTimes = blur ? motionBlurTimes(scene, time, blur) : [time];\n\tif (blurTimes.length > 1) {\n\t\t// The background once, then the moments averaged over it (compositing is linear, so this is the average of whole frames).\n\t\tconst open = current.indexOf('>') + 1;\n\t\tconst body = current.slice(open, current.lastIndexOf('</svg>'));\n\t\tconst bg = svgOptions.background !== false && scene.artwork.background ? (/^\\s*<rect[^>]*\\/>/.exec(body)?.[0] ?? '') : '';\n\t\tcurrent = `${current.slice(0, open)}${bg}${averagedFrames(scene, blurTimes, svgOptions, prefix)}</svg>`;\n\t}\n\tif (!onionSkin && !motionPaths) return current;\n\tconst ghosts = onionSkin\n\t\t? motionGhosts(scene, time, onionSkin).map((g, i) => {\n\t\t\t\tconst own = `${prefix}ghost${i}-`;\n\t\t\t\tconst inner = innerSvg(motionFrameToSvg(scene, g.time, { ...svgOptions, idPrefix: own, background: false })).replace(new RegExp(` id=\"(?!${own.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')})[^\"]*\"`, 'g'), '');\n\t\t\t\treturn `<g data-onion=\"${g.offset < 0 ? 'before' : 'after'}\" opacity=\"${g.opacity}\">${inner}</g>`;\n\t\t\t})\n\t\t: [];\n\tconst camera = motionFrameAt(scene, time).camera;\n\tconst ids = motionPaths === true ? motionMovingIds(scene) : motionPaths ? [...motionPaths] : [];\n\tconst paths = ids.length ? motionPathsSvg(ids.map((id) => motionPath(scene, id)), camera, motionPathColor) : '';\n\t// Ghosts go under everything but the background, paths over everything.\n\tconst open = current.indexOf('>') + 1;\n\tconst close = current.lastIndexOf('</svg>');\n\tconst body = current.slice(open, close);\n\tconst bg = svgOptions.background !== false && scene.artwork.background ? /^\\s*<rect[^>]*\\/>/.exec(body)?.[0] ?? '' : '';\n\treturn `${current.slice(0, open)}${bg}${ghosts.join('')}${body.slice(bg.length)}${paths}</svg>`;\n}\n\nexport interface MotionContactSheetOptions extends MotionSvgOptions, MotionOverlayOptions {\n\t/** Frames a row (default: about square). */\n\tcolumns?: number;\n\t/** Write each frame's time (and shot) under it (default true). */\n\tlabels?: boolean;\n}\n\n/**\n * Several moments of the scene in one SVG, in a grid with each frame's time and shot under it:\n * a contact sheet, to see a whole animation (or an agent's change to it) at a glance.\n */\nexport function motionContactSheetSvg(scene: MotionScene, times: readonly number[], options: MotionContactSheetOptions = {}): string {\n\tconst { columns, labels = true, ...frameOptions } = options;\n\tconst n = Math.max(1, times.length);\n\tconst cols = Math.max(1, Math.min(n, Math.floor(columns ?? Math.ceil(Math.sqrt(n)))));\n\tconst rows = Math.ceil(n / cols);\n\tconst { width: w, height: h } = scene.artwork;\n\tconst gap = Math.round(Math.max(w, h) * 0.04);\n\tconst label = labels ? Math.round(Math.max(12, h * 0.08)) : 0;\n\tconst timeline = compileMotionScene(scene);\n\tconst W = cols * w + (cols + 1) * gap;\n\tconst H = rows * (h + label) + (rows + 1) * gap;\n\tconst prefix = frameOptions.idPrefix ?? 'vg-';\n\tconst cells = times.map((t, i) => {\n\t\tconst x = gap + (i % cols) * (w + gap);\n\t\tconst y = gap + Math.floor(i / cols) * (h + label + gap);\n\t\tconst frame = motionStageSvg(scene, t, { ...frameOptions, idPrefix: `${prefix}f${i}-` });\n\t\tconst view = /viewBox=\"([^\"]*)\"/.exec(frame)?.[1] ?? `0 0 ${w} ${h}`;\n\t\t// Each frame keeps its own ids under its prefix; element ids are dropped so frames never clash.\n\t\tconst inner = innerSvg(frame).replace(new RegExp(` id=\"(?!${`${prefix}f${i}-`.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')})[^\"]*\"`, 'g'), '');\n\t\tconst shot = timeline.shots.find((s) => t >= s.start && t < s.end) ?? timeline.shots[timeline.shots.length - 1];\n\t\tconst caption = labels ? `<text x=\"${x + w / 2}\" y=\"${y + h + label * 0.8}\" font-family=\"system-ui, sans-serif\" font-size=\"${Math.round(label * 0.7)}\" text-anchor=\"middle\" fill=\"#64748b\">${(t / 1000).toFixed(2)} s${shot ? ` · ${shot.id.replace(/[<&]/g, '')}` : ''}</text>` : '';\n\t\treturn `<svg x=\"${x}\" y=\"${y}\" width=\"${w}\" height=\"${h}\" viewBox=\"${view}\" overflow=\"hidden\">${inner}</svg><rect x=\"${x}\" y=\"${y}\" width=\"${w}\" height=\"${h}\" fill=\"none\" stroke=\"#cbd5e1\"/>${caption}`;\n\t});\n\treturn `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 ${W} ${H}\" width=\"${W}\" height=\"${H}\"><rect width=\"${W}\" height=\"${H}\" fill=\"#f8fafc\"/>${cells.join('')}</svg>`;\n}\n","import { resolveEasing, springSettleMs } from '../animation/easing.js';\nimport { matchMotionNodes } from './match.js';\nimport { normalizeTokenColor } from '../tokens/color.js';\nimport { collectPathNodes } from '../vector/geometry.js';\nimport type { VectorNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionRevealPadding, motionTrackKey, trackValue, type MotionTimeline } from './compile.js';\nimport { motionFrameAt } from './evaluate.js';\nimport { motionIssue, namedWithSuggestion, type MotionIssue } from './issues.js';\nimport { MOTION_CLIP_TARGET, type MotionCommand, type MotionScene } from './types.js';\n\n/** Changes shorter than this (ms) are too quick to follow. */\nexport const MOTION_MIN_CHANGE_MS = 120;\n\nconst NUMERIC_PARAMS = (node: VectorNode, effectId: string): string[] | null => {\n\tconst effect = node.effects?.find((e) => e.id === effectId);\n\tif (!effect) return null;\n\treturn Object.entries(effect.params as unknown as Record<string, unknown>)\n\t\t.filter(([, v]) => typeof v === 'number')\n\t\t.map(([k]) => k);\n};\n\nfunction usesColor(scene: MotionScene, color: string): boolean {\n\tconst target = color.toLowerCase();\n\tlet found = false;\n\tconst walk = (v: unknown) => {\n\t\tif (found) return;\n\t\tif (typeof v === 'string') found = v.toLowerCase() === target;\n\t\telse if (Array.isArray(v)) v.forEach(walk);\n\t\telse if (v && typeof v === 'object') Object.values(v).forEach(walk);\n\t};\n\twalk(scene.artwork);\n\twalk(scene.shots);\n\treturn found;\n}\n\nfunction visibleAt(timeline: MotionTimeline, id: string, time: number, node: VectorNode): boolean {\n\tconst num = (p: Parameters<typeof motionTrackKey>[1], rest: number) => {\n\t\tconst v = trackValue(timeline.tracks.get(motionTrackKey(id, p)), time);\n\t\treturn typeof v === 'number' ? v : rest;\n\t};\n\tif (node.visible === false) return false;\n\tif (num('opacity', node.opacity ?? 1) <= 0.01) return false;\n\tif (Math.abs(num('scaleX', 1) * num('scaleY', 1)) <= 1e-4) return false;\n\t// A reveal clip with no area (before a wipe in, after a wipe out).\n\tconst clip = (p: 'clipRect' | 'clipCircle') => trackValue(timeline.tracks.get(motionTrackKey(id, p)), time);\n\tconst rect = clip('clipRect');\n\tif (Array.isArray(rect) && (rect[2] <= 1e-4 || rect[3] <= 1e-4)) return false;\n\tconst circle = clip('clipCircle');\n\tif (Array.isArray(circle) && circle[2] <= 1e-4) return false;\n\tconst hasFill = node.type === 'path' ? !!node.fill && node.fill !== 'none' : collectPathNodes(node).some((p) => p.fill && p.fill !== 'none');\n\t// A group's strokes may each draw on in turn (draw order): drawn when any of them is.\n\tconst drawn =\n\t\tnum('drawEnd', 1) > 0.01 &&\n\t\t(node.type === 'path' ||\n\t\t\tcollectPathNodes(node).length === 0 ||\n\t\t\tcollectPathNodes(node).some((p) => {\n\t\t\t\tconst v = trackValue(timeline.tracks.get(motionTrackKey(p.id, 'drawEnd')), time);\n\t\t\t\treturn typeof v !== 'number' || v > 0.01;\n\t\t\t}));\n\treturn drawn || (hasFill && num('fillOpacity', 1) > 0.01);\n}\n\n/**\n * What is wrong with a scene's meaning: unknown ids (with a \"did you mean\"), timing that\n * fights itself, things animated while hidden or off camera, and lengths outside the target.\n * The scene must be well formed (see `parseMotionScene`).\n */\nexport function checkMotionScene(scene: MotionScene): MotionIssue[] {\n\tconst issues: MotionIssue[] = [];\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst ids = [...nodes.keys()];\n\tconst timeline = compileMotionScene(scene);\n\tconst artAspect = scene.artwork.width / scene.artwork.height;\n\n\tif (!scene.shots.length) issues.push(motionIssue('no-shots', 'The scene has no shots yet; add one with a list of commands.'));\n\tconst seen = new Set<string>();\n\tfor (const shot of scene.shots) {\n\t\tif (seen.has(shot.id)) issues.push(motionIssue('duplicate-shot-id', `Shot id \"${shot.id}\" is used twice; give each shot its own id.`, { shot: shot.id }));\n\t\tseen.add(shot.id);\n\t}\n\n\tconst known = (id: string, code: 'unknown-target' | 'unknown-path' | 'unknown-shape' | 'unknown-frame', what: string, where: { shot: string; command?: number }) => {\n\t\tif (nodes.has(id)) return true;\n\t\tissues.push(motionIssue(code, `There is no ${what} ${namedWithSuggestion(id, ids)} in the artwork${ids.length ? '' : ' (it has no nodes yet)'}.`, { ...where, ids: [id] }));\n\t\treturn false;\n\t};\n\n\tscene.shots.forEach((shot, shotIndex) => {\n\t\tif (shot.camera && 'frame' in shot.camera && typeof shot.camera.frame === 'string') known(shot.camera.frame, 'unknown-frame', 'node to frame', { shot: shot.id });\n\t\telse if (shot.camera) {\n\t\t\tconst c = shot.camera as { width: number; height: number };\n\t\t\tif (!(c.width > 0 && c.height > 0)) issues.push(motionIssue('invalid-camera', `The camera needs a positive width and height (got ${c.width} × ${c.height}).`, { shot: shot.id }));\n\t\t\telse if (Math.abs(c.width / c.height / artAspect - 1) > 0.02)\n\t\t\t\tissues.push(motionIssue('camera-aspect', `The camera is ${c.width} × ${c.height}, a different shape from the ${scene.artwork.width} × ${scene.artwork.height} artwork, so it shows bands at the sides; frame a node instead to match.`, { shot: shot.id }));\n\t\t}\n\t\tif (!shot.run.length && !shot.camera && shotIndex > 0) issues.push(motionIssue('empty-shot', 'This shot only holds; add commands or a camera move, or remove it.', { shot: shot.id }));\n\n\t\tshot.run.forEach((command: MotionCommand, i) => {\n\t\t\tconst where = { shot: shot.id, command: i };\n\t\t\tif (command.type === 'wait') return;\n\t\t\tconst targets = command.targets.filter((id) => known(id, 'unknown-target', 'node', where));\n\t\t\tconst timing = timeline.commands.find((c) => c.shot === shot.id && c.command === i);\n\t\t\tif (timing && timing.duration > 0 && timing.duration < MOTION_MIN_CHANGE_MS)\n\t\t\t\tissues.push(motionIssue('too-fast', `This ${command.type} lasts ${timing.duration} ms, too quick to follow; make it at least ${MOTION_MIN_CHANGE_MS} ms.`, { ...where, measured: timing.duration, needed: MOTION_MIN_CHANGE_MS, unit: 'ms', ids: targets }));\n\t\t\tif (command.duration !== undefined && command.ease !== undefined) {\n\t\t\t\tconst ease = resolveEasing(command.ease);\n\t\t\t\tif (ease !== 'hold' && ease.type === 'spring') {\n\t\t\t\t\tconst settle = springSettleMs(ease);\n\t\t\t\t\tif (command.duration < settle * 0.9)\n\t\t\t\t\t\tissues.push(motionIssue('spring-cut-short', `This ${command.type}'s spring takes ${settle} ms to settle but lasts ${command.duration} ms, so it jumps to its end; leave \"duration\" out (the spring sets it) or make it at least ${settle} ms.`, { ...where, measured: command.duration, needed: settle, unit: 'ms', ids: targets }));\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (command.type === 'follow' && known(command.path, 'unknown-path', 'path', where) && nodes.get(command.path)!.node.type !== 'path')\n\t\t\t\tissues.push(motionIssue('not-a-path', `\"${command.path}\" is a group; follow a single path node.`, { ...where, ids: [command.path] }));\n\t\t\tif (command.type === 'morph') known(command.into, 'unknown-shape', 'shape', where);\n\t\t\tif (command.type === 'play' && !scene.clips?.[command.clip])\n\t\t\t\tissues.push(motionIssue('unknown-clip', `There is no clip ${namedWithSuggestion(command.clip, Object.keys(scene.clips ?? {}))}; define it with set_animation_clip.`, where));\n\t\t\tif (command.type === 'match' && known(command.into, 'unknown-shape', 'group', where)) {\n\t\t\t\tconst into = nodes.get(command.into)!;\n\t\t\t\tfor (const id of targets) {\n\t\t\t\t\tconst entry = nodes.get(id)!;\n\t\t\t\t\tif (id === command.into || into.ancestors.includes(id) || entry.ancestors.includes(command.into)) {\n\t\t\t\t\t\tissues.push(motionIssue('match-self', `\"${id}\" cannot match \"${command.into}\": one is the other or holds it. Match two separate groups (the second usually hidden).`, { ...where, ids: [id, command.into] }));\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst m = matchMotionNodes(entry.node, into.node);\n\t\t\t\t\tif (m.unpairedInto.length)\n\t\t\t\t\t\tissues.push(motionIssue('match-unpaired', `${m.unpairedInto.map((x) => `\"${x}\"`).join(', ')} in \"${command.into}\" ${m.unpairedInto.length > 1 ? 'have' : 'has'} no partner in \"${id}\", so ${m.unpairedInto.length > 1 ? 'they do' : 'it does'} not appear; add a part with the same name or id to \"${id}\" (it can start hidden or tiny).`, { ...where, ids: m.unpairedInto }));\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst style = command.type === 'enter' || command.type === 'exit' ? command.style : undefined;\n\t\t\tif (style === 'wipe' || style === 'iris' || style === 'split')\n\t\t\t\tfor (const id of targets)\n\t\t\t\t\tif (!motionRevealPadding(nodes.get(id)!))\n\t\t\t\t\t\tissues.push(motionIssue('reveal-no-box', `\"${id}\" has no width or height (a straight line), so a ${style} cannot clip it and it fades instead; use style \"${command.type === 'enter' ? 'draw' : 'undraw'}\" for a line.`, { ...where, ids: [id] }));\n\t\t\tif (command.type === 'style') {\n\t\t\t\tfor (const key of ['fill', 'stroke'] as const) {\n\t\t\t\t\tconst color = command[key];\n\t\t\t\t\tif (color === undefined) continue;\n\t\t\t\t\tif (normalizeTokenColor(color) === null) {\n\t\t\t\t\t\tissues.push(motionIssue('invalid-color', `${key} \"${color}\" is not a colour this editor reads; use hex (\"#0ea5e9\"), rgb() or rgba().`, where));\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tfor (const id of targets) {\n\t\t\t\t\t\tconst node = nodes.get(id)!.node;\n\t\t\t\t\t\tconst paths = node.type === 'path' ? [node] : collectPathNodes(node);\n\t\t\t\t\t\tif (paths.some((p) => p[key] !== undefined && p[key] !== null && typeof p[key] !== 'string'))\n\t\t\t\t\t\t\tissues.push(motionIssue('paint-not-color', `\"${id}\" has a gradient ${key}; it switches to ${color} at the end instead of blending.`, { ...where, ids: [id] }));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (command.type === 'color-pulse') {\n\t\t\t\tconst key = command.paint ?? 'fill';\n\t\t\t\tconst color = command.color ?? '#f59e0b';\n\t\t\t\tif (normalizeTokenColor(color) === null) issues.push(motionIssue('invalid-color', `color \"${color}\" is not a colour this editor reads; use hex (\"#0ea5e9\"), rgb() or rgba().`, where));\n\t\t\t\telse\n\t\t\t\t\tfor (const id of targets) {\n\t\t\t\t\t\tconst node = nodes.get(id)!.node;\n\t\t\t\t\t\tconst paths = node.type === 'path' ? [node] : collectPathNodes(node);\n\t\t\t\t\t\tif (paths.some((p) => typeof p[key] !== 'string'))\n\t\t\t\t\t\t\tissues.push(motionIssue('paint-not-color', `\"${id}\" has a gradient or no ${key}, so a colour pulse cannot tint it; give it a solid ${key} or pulse the ${key === 'fill' ? 'stroke' : 'fill'}.`, { ...where, ids: [id] }));\n\t\t\t\t\t}\n\t\t\t}\n\t\t\tif (command.type === 'effect') {\n\t\t\t\tfor (const id of targets) {\n\t\t\t\t\tconst node = nodes.get(id)!.node;\n\t\t\t\t\tconst params = NUMERIC_PARAMS(node, command.effect);\n\t\t\t\t\tconst effects = (node.effects ?? []).map((e) => e.id);\n\t\t\t\t\tif (!params)\n\t\t\t\t\t\tissues.push(motionIssue('unknown-effect', `\"${id}\" has no effect ${namedWithSuggestion(command.effect, effects)}${effects.length ? `; its effects are ${effects.map((e) => `\"${e}\"`).join(', ')}` : '; it has no live effects'}.`, { ...where, ids: [id] }));\n\t\t\t\t\telse if (!params.includes(command.param))\n\t\t\t\t\t\tissues.push(motionIssue('unknown-effect-param', `Effect \"${command.effect}\" has no numeric parameter ${namedWithSuggestion(command.param, params)}; use one of ${params.join(', ')}.`, { ...where, ids: [id] }));\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Visibility at the start of the command.\n\t\t\tif (timing) {\n\t\t\t\tfor (const id of targets) {\n\t\t\t\t\tconst node = nodes.get(id)!.node;\n\t\t\t\t\tconst before = Math.max(0, timing.start - 0.5);\n\t\t\t\t\tconst visible = timing.start > 0 ? visibleAt(timeline, id, before, node) : node.visible !== false;\n\t\t\t\t\tif (command.type === 'enter' && visible && timing.start > 0)\n\t\t\t\t\t\tissues.push(motionIssue('enter-visible', `\"${id}\" is already showing when it enters, so it blinks out first; remove the enter or exit it earlier.`, { ...where, ids: [id] }));\n\t\t\t\t\tconst probe = command.type === 'exit' ? timing.start + 0.5 : (timing.start + timing.end) / 2;\n\t\t\t\t\tif (command.type !== 'enter' && command.type !== 'draw' && !visibleAt(timeline, id, probe, node))\n\t\t\t\t\t\tissues.push(motionIssue('exit-hidden', `\"${id}\" is hidden when this ${command.type} starts, so it is not seen; enter it first.`, { ...where, ids: [id] }));\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t});\n\n\t// Drivers: their nodes must exist, and they must not follow each other round in a loop.\n\tconst drivers = scene.drivers ?? [];\n\tdrivers.forEach((d, i) => {\n\t\tfor (const id of [d.target, d.source.node])\n\t\t\tif (!nodes.has(id)) issues.push(motionIssue('unknown-target', `Driver ${i + 1} names ${namedWithSuggestion(id, [...nodes.keys()])}, which the artwork does not have.`, { ids: [id] }));\n\t});\n\t{\n\t\tconst key = (n: string, p: string) => `${n}.${p}`;\n\t\tconst edges = new Map<string, string[]>();\n\t\tfor (const d of drivers) edges.set(key(d.target, d.property), [...(edges.get(key(d.target, d.property)) ?? []), key(d.source.node, d.source.property)]);\n\t\tconst state = new Map<string, 1 | 2>();\n\t\tconst loop: string[] = [];\n\t\tconst visit = (k: string, trail: string[]): boolean => {\n\t\t\tif (state.get(k) === 2) return false;\n\t\t\tif (state.get(k) === 1) return loop.push(...trail.slice(trail.indexOf(k)), k), true;\n\t\t\tstate.set(k, 1);\n\t\t\tfor (const n of edges.get(k) ?? []) if (visit(n, [...trail, k])) return true;\n\t\t\tstate.set(k, 2);\n\t\t\treturn false;\n\t\t};\n\t\tfor (const k of edges.keys()) if (visit(k, [])) break;\n\t\tif (loop.length) issues.push(motionIssue('driver-cycle', `Drivers follow each other round in a loop (${loop.join(' ← ')}); remove one of them.`, { ids: [...new Set(loop.map((k) => k.split('.')[0]))] }));\n\t}\n\n\t// Clips: the nodes they name besides \"$\" must exist.\n\tfor (const [name, clip] of Object.entries(scene.clips ?? {}))\n\t\tfor (const command of clip.run)\n\t\t\tif (command.type !== 'wait')\n\t\t\t\tfor (const id of command.targets)\n\t\t\t\t\tif (id !== MOTION_CLIP_TARGET && !nodes.has(id)) issues.push(motionIssue('unknown-target', `Clip \"${name}\" names ${namedWithSuggestion(id, [...nodes.keys()])}, which the artwork does not have; use \"$\" for the node the clip is played on.`, { ids: [id] }));\n\n\t// Triggers: what Flair's player does with a scene played in answer to the viewer.\n\tif (scene.trigger) {\n\t\tif ((scene.loop ?? 'none') !== 'none') issues.push(motionIssue('trigger-loop', `The scene plays on ${scene.trigger}, so its \"${scene.loop}\" loop does not apply; set loop to \"none\" or remove the trigger.`, {}));\n\t\tif (scene.trigger === 'click') {\n\t\t\tif (scene.shots.length === 1) issues.push(motionIssue('click-one-shot', 'The scene plays on click but has one shot, so every click replays it from the start; split it into shots (each click plays the next one).', { shot: scene.shots[0].id }));\n\t\t\tscene.shots.forEach((shot, i) => {\n\t\t\t\tif (i > 0 && shot.at) issues.push(motionIssue('click-cue', `Shot \"${shot.id}\" is cued, but on click a shot starts when it is clicked to; remove its \"at\" or the trigger.`, { shot: shot.id }));\n\t\t\t});\n\t\t}\n\t}\n\n\t// Cues: they must resolve, and the shot before must have ended by then.\n\tscene.shots.forEach((shot, i) => {\n\t\tif (!shot.at) return;\n\t\tconst timing = timeline.shots[i];\n\t\tif (timing.cue === undefined) {\n\t\t\tconst what = shot.at.beat !== undefined ? `beat ${shot.at.beat}, but the scene has no beat grid; set one with set_animation_settings ({ \"beat\": { \"bpm\": … } })` : `word ${shot.at.word}, but the narration has ${scene.narration?.words.length ?? 0} words (indexes from 0)`;\n\t\t\tissues.push(motionIssue('unknown-cue', `Shot \"${shot.id}\" is cued to ${what}.`, { shot: shot.id }));\n\t\t} else if (timing.missedBy !== undefined) {\n\t\t\tconst late = Math.round(timing.missedBy);\n\t\t\tissues.push(motionIssue('cue-missed', `Shot \"${shot.id}\" is cued at ${Math.round(timing.cue)} ms but starts ${late} ms late, because the shot before runs until ${Math.round(timing.start)} ms; shorten that shot (its hold, durations or speed) or cue this one later.`, { shot: shot.id, measured: late, needed: 0, unit: 'ms' }));\n\t\t}\n\t});\n\n\t// Two segments changing the same property of a node at the same time.\n\tfor (const [key, track] of timeline.tracks) {\n\t\t// Additive layers stack by design.\n\t\tif (key.endsWith('\\u0000add')) continue;\n\t\tfor (let i = 1; i < track.length; i++) {\n\t\t\tconst a = track[i - 1];\n\t\t\tconst b = track[i];\n\t\t\tif (b.start < a.end - 1 && (a.shot !== b.shot || a.command !== b.command)) {\n\t\t\t\tconst property = key.split('\\u0000')[1];\n\t\t\t\tif (!a.node) continue;\n\t\t\t\tissues.push(\n\t\t\t\t\tmotionIssue('overlap', `\"${a.node}\" ${property} is changed by two commands at once (shot \"${a.shot}\" command ${a.command + 1} and shot \"${b.shot}\" command ${b.command + 1}); the later one takes over. Start it after the first ends, or use with: \"after\".`, {\n\t\t\t\t\t\tshot: b.shot,\n\t\t\t\t\t\tcommand: b.command,\n\t\t\t\t\t\tids: [a.node]\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Animated nodes that end their command outside the camera.\n\tconst reported = new Set<string>();\n\tfor (const timing of timeline.commands) {\n\t\tconst command = scene.shots[timing.shotIndex].run[timing.command];\n\t\tif (command.type === 'wait' || command.type === 'exit') continue;\n\t\tconst frame = motionFrameAt(scene, timing.end);\n\t\tconst cam = frame.camera;\n\t\tconst docIndex = indexMotionNodes(frame.document.nodes);\n\t\tfor (const id of command.targets) {\n\t\t\tconst b = docIndex.get(id)?.bounds;\n\t\t\tif (!b || reported.has(id) || !visibleAt(timeline, id, timing.end, nodes.get(id)!.node)) continue;\n\t\t\tconst outside = b.x + b.width < cam.x || b.y + b.height < cam.y || b.x > cam.x + cam.width || b.y > cam.y + cam.height;\n\t\t\tif (outside) {\n\t\t\t\treported.add(id);\n\t\t\t\tissues.push(motionIssue('out-of-frame', `\"${id}\" is outside the camera when this ${command.type} ends, so it is not seen; move it into frame or move the camera.`, { shot: timing.shot, command: timing.command, ids: [id] }));\n\t\t\t}\n\t\t}\n\t}\n\n\tif (scene.controls) {\n\t\tfor (const control of scene.controls) {\n\t\t\tif (!usesColor(scene, control.default))\n\t\t\t\tissues.push(motionIssue('unknown-control-color', `Control \"${control.name}\" stands for ${control.default}, which the scene never uses; set its default to a colour in the artwork.`));\n\t\t}\n\t}\n\n\tif (scene.target && scene.shots.length) {\n\t\tconst seconds = Math.round(timeline.duration / 100) / 10;\n\t\tconst [min, max] = scene.target;\n\t\tif (seconds > max) issues.push(motionIssue('scene-too-long', `The scene runs ${seconds} s, past its ${max} s target; shorten holds or durations, or fit it (fit_animation).`, { measured: seconds, needed: max, unit: 's' }));\n\t\tif (seconds < min) issues.push(motionIssue('scene-too-short', `The scene runs ${seconds} s, under its ${min} s target; hold longer, add shots, or fit it (fit_animation).`, { measured: seconds, needed: min, unit: 's' }));\n\t}\n\treturn issues;\n}\n","import type { VectorDocument } from '../vector/types.js';\nimport { checkMotionScene } from './check.js';\nimport { motionIssueKey, motionIssueLine, namedWithSuggestion, type MotionIssue } from './issues.js';\nimport { clipsShapeProblems, driversShapeProblems, commandShapeProblems, motionSceneShapeProblems, shotShapeProblems } from './parse.js';\nimport type { MotionClip, MotionDriver, MotionCommand, MotionControl, MotionPreset, MotionScene, MotionShot } from './types.js';\n\n/**\n * Edits as data: each is a pure function of the scene, all or nothing. An edit that leaves the\n * scene malformed, or adds an error the scene did not have (an unknown id, say), changes\n * nothing and says why; existing errors do not block unrelated edits, so a broken scene can be\n * fixed a step at a time.\n */\nexport type MotionEdit =\n\t| { op: 'set_settings'; name?: string; description?: string | null; loop?: MotionScene['loop']; trigger?: MotionScene['trigger'] | null; fps?: number; steps?: number | null; beat?: MotionScene['beat'] | null; motionBlur?: MotionScene['motionBlur'] | null; narration?: MotionScene['narration'] | null; target?: [number, number] | null }\n\t| { op: 'insert_shots'; shots: MotionShot[]; at?: number }\n\t| { op: 'update_shot'; shot: string; set?: Partial<MotionShot>; remove?: ('label' | 'camera' | 'hold' | 'speed' | 'at')[] }\n\t| { op: 'delete_shots'; shots: string[] }\n\t| { op: 'move_shot'; shot: string; to: number }\n\t| { op: 'add_commands'; shot: string; commands: MotionCommand[]; at?: number }\n\t| { op: 'update_command'; shot: string; command: number; set?: Record<string, unknown>; remove?: string[] }\n\t| { op: 'delete_commands'; shot: string; commands: number[] }\n\t| { op: 'move_command'; shot: string; command: number; to: number }\n\t| { op: 'set_artwork'; artwork: VectorDocument }\n\t| { op: 'set_controls'; controls: MotionControl[]; presets?: MotionPreset[] }\n\t| { op: 'set_clip'; name: string; clip: MotionClip | null }\n\t| { op: 'set_drivers'; drivers: MotionDriver[] }\n\t| { op: 'replace_scene'; scene: MotionScene };\n\nexport type MotionEditOp = MotionEdit['op'];\n\nexport const MOTION_EDIT_OPS: readonly MotionEditOp[] = [\n\t'set_settings',\n\t'insert_shots',\n\t'update_shot',\n\t'delete_shots',\n\t'move_shot',\n\t'add_commands',\n\t'update_command',\n\t'delete_commands',\n\t'move_command',\n\t'set_artwork',\n\t'set_controls',\n\t'set_clip',\n\t'set_drivers',\n\t'replace_scene'\n];\n\nexport type MotionEditResult =\n\t| {\n\t\t\tok: true;\n\t\t\tscene: MotionScene;\n\t\t\t/** Every issue the edited scene has. */\n\t\t\tissues: MotionIssue[];\n\t\t\t/** Edits that work but may surprise (a later command undoes this one, say). */\n\t\t\thints: string[];\n\t }\n\t| { ok: false; error: string };\n\nclass EditError extends Error {}\nconst fail = (message: string): never => {\n\tthrow new EditError(message);\n};\n\nfunction shotIndex(scene: MotionScene, id: string): number {\n\tconst i = scene.shots.findIndex((s) => s.id === id);\n\tif (i < 0) fail(`There is no shot ${namedWithSuggestion(id, scene.shots.map((s) => s.id))}; the shots are ${scene.shots.map((s) => `\"${s.id}\"`).join(', ') || 'none yet'}.`);\n\treturn i;\n}\n\nfunction position(at: number | undefined, length: number, what: string): number {\n\tif (at === undefined) return length;\n\tif (!Number.isInteger(at) || at < 0 || at > length) fail(`${what} must be a whole number from 0 to ${length} (got ${at}).`);\n\treturn at;\n}\n\nconst replaceShot = (scene: MotionScene, index: number, shot: MotionShot): MotionScene => ({ ...scene, shots: scene.shots.map((s, i) => (i === index ? shot : s)) });\n\n/** A free shot id: `base`, then `base-2`, `base-3`… */\nexport function freshShotId(scene: MotionScene, base = 'shot'): string {\n\tconst used = new Set(scene.shots.map((s) => s.id));\n\tif (!used.has(base)) return base;\n\tlet n = 2;\n\twhile (used.has(`${base}-${n}`)) n++;\n\treturn `${base}-${n}`;\n}\n\nfunction applyOne(scene: MotionScene, edit: MotionEdit): MotionScene {\n\tswitch (edit.op) {\n\t\tcase 'set_settings': {\n\t\t\tconst next: MotionScene = { ...scene };\n\t\t\tif (edit.name !== undefined) next.name = edit.name;\n\t\t\tif (edit.description === null) delete next.description;\n\t\t\telse if (edit.description !== undefined) next.description = edit.description;\n\t\t\tif (edit.loop !== undefined) next.loop = edit.loop;\n\t\t\tif (edit.trigger === null) delete next.trigger;\n\t\t\telse if (edit.trigger !== undefined) {\n\t\t\t\tif (!['click', 'hover', 'press', 'scroll'].includes(edit.trigger)) fail('\"trigger\" must be click, hover, press or scroll, or null to play on its own.');\n\t\t\t\tnext.trigger = edit.trigger;\n\t\t\t}\n\t\t\tif (edit.fps !== undefined) next.fps = edit.fps;\n\t\t\tif (edit.steps === null) delete next.steps;\n\t\t\telse if (edit.steps !== undefined) {\n\t\t\t\tif (!(typeof edit.steps === 'number' && edit.steps > 0 && edit.steps <= 120)) fail('\"steps\" must be frames per second from above 0 to 120 (12 is \"on twos\" at 24 fps), or null for smooth.');\n\t\t\t\tnext.steps = edit.steps;\n\t\t\t}\n\t\t\tfor (const key of ['beat', 'narration', 'motionBlur'] as const) {\n\t\t\t\tif (edit[key] === null) delete next[key];\n\t\t\t\telse if (edit[key] !== undefined) (next as unknown as Record<string, unknown>)[key] = edit[key];\n\t\t\t}\n\t\t\t{\n\t\t\t\tconst problems = motionSceneShapeProblems(next).filter((p) => /\"beat\"|\"narration\"|\"motionBlur\"/.test(p));\n\t\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\t}\n\t\t\tif (edit.target === null) delete next.target;\n\t\t\telse if (edit.target !== undefined) next.target = edit.target;\n\t\t\treturn next;\n\t\t}\n\t\tcase 'set_drivers': {\n\t\t\tconst problems = driversShapeProblems(edit.drivers);\n\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\tconst next: MotionScene = { ...scene, drivers: edit.drivers };\n\t\t\tif (!edit.drivers.length) delete next.drivers;\n\t\t\treturn next;\n\t\t}\n\t\tcase 'set_clip': {\n\t\t\tif (typeof edit.name !== 'string' || !edit.name) fail('Give the clip a \"name\".');\n\t\t\tconst clips = { ...(scene.clips ?? {}) };\n\t\t\tif (edit.clip === null) {\n\t\t\t\tif (!clips[edit.name]) fail(`There is no clip ${namedWithSuggestion(edit.name, Object.keys(clips))} to delete.`);\n\t\t\t\tconst playing = scene.shots.filter((s) => s.run.some((c) => c.type === 'play' && c.clip === edit.name)).map((s) => `\"${s.id}\"`);\n\t\t\t\tif (playing.length) fail(`Clip \"${edit.name}\" is played in shot${playing.length > 1 ? 's' : ''} ${playing.join(', ')}; remove those play commands first.`);\n\t\t\t\tdelete clips[edit.name];\n\t\t\t} else {\n\t\t\t\tconst problems = clipsShapeProblems({ [edit.name]: edit.clip });\n\t\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\t\tclips[edit.name] = edit.clip;\n\t\t\t}\n\t\t\tconst next: MotionScene = { ...scene, clips };\n\t\t\tif (!Object.keys(clips).length) delete next.clips;\n\t\t\treturn next;\n\t\t}\n\t\tcase 'insert_shots': {\n\t\t\tif (!edit.shots.length) fail('Give at least one shot.');\n\t\t\tedit.shots.forEach((shot, i) => {\n\t\t\t\tconst problems = shotShapeProblems(shot, `Shot ${i + 1}`);\n\t\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\t});\n\t\t\tconst ids = new Set(scene.shots.map((s) => s.id));\n\t\t\tfor (const shot of edit.shots) {\n\t\t\t\tif (ids.has(shot.id)) fail(`Shot id \"${shot.id}\" is already used; choose another (e.g. \"${freshShotId(scene, shot.id)}\").`);\n\t\t\t\tids.add(shot.id);\n\t\t\t}\n\t\t\tconst at = position(edit.at, scene.shots.length, '\"at\"');\n\t\t\treturn { ...scene, shots: [...scene.shots.slice(0, at), ...edit.shots, ...scene.shots.slice(at)] };\n\t\t}\n\t\tcase 'update_shot': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst shot: MotionShot = { ...scene.shots[i], ...(edit.set ?? {}) };\n\t\t\tfor (const key of edit.remove ?? []) delete shot[key];\n\t\t\tif (shot.id !== edit.shot && scene.shots.some((s) => s.id === shot.id)) fail(`Shot id \"${shot.id}\" is already used; choose another.`);\n\t\t\tconst problems = shotShapeProblems(shot, `Shot \"${edit.shot}\"`);\n\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\treturn replaceShot(scene, i, shot);\n\t\t}\n\t\tcase 'delete_shots': {\n\t\t\tif (!edit.shots.length) fail('Give at least one shot id.');\n\t\t\tedit.shots.forEach((id) => shotIndex(scene, id));\n\t\t\tconst drop = new Set(edit.shots);\n\t\t\treturn { ...scene, shots: scene.shots.filter((s) => !drop.has(s.id)) };\n\t\t}\n\t\tcase 'move_shot': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst to = position(edit.to, scene.shots.length - 1, '\"to\"');\n\t\t\tconst shots = [...scene.shots];\n\t\t\tconst [shot] = shots.splice(i, 1);\n\t\t\tshots.splice(to, 0, shot);\n\t\t\treturn { ...scene, shots };\n\t\t}\n\t\tcase 'add_commands': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tif (!edit.commands.length) fail('Give at least one command.');\n\t\t\tedit.commands.forEach((command, k) => {\n\t\t\t\tconst problems = commandShapeProblems(command, `Command ${k + 1}`);\n\t\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\t});\n\t\t\tconst run = scene.shots[i].run;\n\t\t\tconst at = position(edit.at, run.length, '\"at\"');\n\t\t\treturn replaceShot(scene, i, { ...scene.shots[i], run: [...run.slice(0, at), ...edit.commands, ...run.slice(at)] });\n\t\t}\n\t\tcase 'update_command': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst run = scene.shots[i].run;\n\t\t\tif (!Number.isInteger(edit.command) || edit.command < 0 || edit.command >= run.length)\n\t\t\t\tfail(`Shot \"${edit.shot}\" has ${run.length} command${run.length === 1 ? '' : 's'}; \"command\" must be an index from 0 to ${run.length - 1} (got ${edit.command}).`);\n\t\t\tconst command = { ...run[edit.command], ...(edit.set ?? {}) } as Record<string, unknown>;\n\t\t\tfor (const key of edit.remove ?? []) {\n\t\t\t\tif (key === 'type') fail('\"type\" cannot be removed; replace the command instead.');\n\t\t\t\tdelete command[key];\n\t\t\t}\n\t\t\tconst problems = commandShapeProblems(command, `Command ${edit.command}`);\n\t\t\tif (problems.length) fail(problems.join(' '));\n\t\t\treturn replaceShot(scene, i, { ...scene.shots[i], run: run.map((c, k) => (k === edit.command ? (command as unknown as MotionCommand) : c)) });\n\t\t}\n\t\tcase 'delete_commands': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst run = scene.shots[i].run;\n\t\t\tif (!edit.commands.length) fail('Give at least one command index.');\n\t\t\tfor (const k of edit.commands)\n\t\t\t\tif (!Number.isInteger(k) || k < 0 || k >= run.length) fail(`Shot \"${edit.shot}\" has no command ${k}; indexes run from 0 to ${run.length - 1}.`);\n\t\t\tconst drop = new Set(edit.commands);\n\t\t\treturn replaceShot(scene, i, { ...scene.shots[i], run: run.filter((_, k) => !drop.has(k)) });\n\t\t}\n\t\tcase 'move_command': {\n\t\t\tconst i = shotIndex(scene, edit.shot);\n\t\t\tconst run = [...scene.shots[i].run];\n\t\t\tif (!Number.isInteger(edit.command) || edit.command < 0 || edit.command >= run.length)\n\t\t\t\tfail(`Shot \"${edit.shot}\" has ${run.length} command${run.length === 1 ? '' : 's'}; \"command\" must be an index from 0 to ${run.length - 1} (got ${edit.command}).`);\n\t\t\tconst to = position(edit.to, run.length - 1, '\"to\"');\n\t\t\tconst [moved] = run.splice(edit.command, 1);\n\t\t\trun.splice(to, 0, moved);\n\t\t\treturn replaceShot(scene, i, { ...scene.shots[i], run });\n\t\t}\n\t\tcase 'set_artwork':\n\t\t\treturn { ...scene, artwork: edit.artwork };\n\t\tcase 'set_controls': {\n\t\t\tconst next: MotionScene = { ...scene, controls: edit.controls };\n\t\t\tif (!edit.controls.length) delete next.controls;\n\t\t\tif (edit.presets !== undefined) {\n\t\t\t\tif (edit.presets.length) next.presets = edit.presets;\n\t\t\t\telse delete next.presets;\n\t\t\t}\n\t\t\tconst names = new Set(edit.controls.map((c) => c.name));\n\t\t\tfor (const preset of next.presets ?? [])\n\t\t\t\tfor (const key of Object.keys(preset.values))\n\t\t\t\t\tif (!names.has(key)) fail(`Preset \"${preset.name}\" sets ${namedWithSuggestion(key, names)}, which is not a control.`);\n\t\t\treturn next;\n\t\t}\n\t\tcase 'replace_scene':\n\t\t\treturn edit.scene;\n\t}\n}\n\nfunction errorKeys(issues: readonly MotionIssue[]): Set<string> {\n\treturn new Set(issues.filter((i) => i.severity === 'error').map(motionIssueKey));\n}\n\n/** Hints: commands whose change a later command takes over. */\nfunction editHints(before: MotionIssue[], after: MotionIssue[]): string[] {\n\tconst old = new Set(before.map(motionIssueKey));\n\treturn after.filter((i) => i.code === 'overlap' && !old.has(motionIssueKey(i))).map(motionIssueLine);\n}\n\n/** Applies edits in order, as one change. Fails without changing anything when one fails. */\nexport function applyMotionEdits(scene: MotionScene, edits: MotionEdit | readonly MotionEdit[]): MotionEditResult {\n\tconst list = Array.isArray(edits) ? edits : [edits as MotionEdit];\n\tconst before = checkMotionScene(scene);\n\tlet next = scene;\n\tfor (let i = 0; i < list.length; i++) {\n\t\tconst edit = list[i];\n\t\tconst prefix = list.length > 1 ? `op ${i + 1} (${edit?.op}): ` : '';\n\t\tif (!edit || !(MOTION_EDIT_OPS as readonly string[]).includes(edit.op))\n\t\t\treturn { ok: false, error: `${prefix}Unknown op ${namedWithSuggestion(String(edit?.op), MOTION_EDIT_OPS)}. Nothing was changed.` };\n\t\ttry {\n\t\t\tnext = applyOne(next, edit);\n\t\t} catch (error) {\n\t\t\tif (error instanceof EditError) return { ok: false, error: `${prefix}${error.message} Nothing was changed.` };\n\t\t\tthrow error;\n\t\t}\n\t\tconst problems = motionSceneShapeProblems(next);\n\t\tif (problems.length) return { ok: false, error: `${prefix}Nothing was changed: ${problems.join(' ')}` };\n\t}\n\tconst issues = checkMotionScene(next);\n\tconst had = errorKeys(before);\n\tconst added = issues.filter((i) => i.severity === 'error' && !had.has(motionIssueKey(i)));\n\tif (added.length) return { ok: false, error: `Nothing was changed: ${added.map(motionIssueLine).join(' ')}` };\n\treturn { ok: true, scene: next, issues, hints: editHints(before, issues) };\n}\n\n/** What one edit made, for later edits in a batch to refer to (`\"$0.indexes[0]\"`). */\nexport interface MotionEditOutcome {\n\top: string;\n\t/** The shot it changed or added to. */\n\tshot?: string;\n\t/** Shots it added. */\n\tshots?: string[];\n\t/** Indexes of the commands it added (or where it moved one). */\n\tindexes?: number[];\n\t/** The clip it set. */\n\tclip?: string;\n}\n\nconst REF = /^\\$(\\d+|last)((?:\\.[A-Za-z_]\\w*|\\[\\d+\\])+)$/;\n\n/**\n * Resolves references to earlier edits' outcomes in a batch: a string `\"$N.path\"` (`$last` for the\n * one before) is replaced by that value, e.g. `\"$0.indexes[0]\"` for the index of the first command\n * edit 0 added; `\"$$...\"` is a literal `$`. Returns the resolved edits with what each made, or why\n * a reference does not resolve. Nothing is applied.\n */\nexport function resolveMotionEditRefs(scene: MotionScene, edits: readonly MotionEdit[]): { ok: true; edits: MotionEdit[]; outcomes: MotionEditOutcome[] } | { ok: false; error: string } {\n\tconst outcomes: MotionEditOutcome[] = [];\n\tconst resolved: MotionEdit[] = [];\n\tlet next = scene;\n\tfor (let i = 0; i < edits.length; i++) {\n\t\tconst where = `op ${i + 1} (${edits[i]?.op})`;\n\t\tlet problem: string | null = null;\n\t\tconst walk = (v: unknown): unknown => {\n\t\t\tif (typeof v === 'string') {\n\t\t\t\tif (v.startsWith('$$')) return v.slice(1);\n\t\t\t\tconst m = REF.exec(v);\n\t\t\t\tif (!m) return v;\n\t\t\t\tconst n = m[1] === 'last' ? i - 1 : Number(m[1]);\n\t\t\t\tif (!(n >= 0 && n < i)) {\n\t\t\t\t\tproblem = `${where}: \"${v}\" refers to op ${n + 1}, but only ops before this one (1 to ${i}) can be referred to.`;\n\t\t\t\t\treturn v;\n\t\t\t\t}\n\t\t\t\tlet value: unknown = outcomes[n];\n\t\t\t\tfor (const part of m[2].match(/\\.[A-Za-z_]\\w*|\\[\\d+\\]/g) ?? []) value = value == null ? undefined : (value as Record<string, unknown>)[part.startsWith('.') ? part.slice(1) : part.slice(1, -1)];\n\t\t\t\tif (value === undefined) problem = `${where}: \"${v}\" has no value; op ${n + 1} made ${JSON.stringify(outcomes[n])}.`;\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tif (Array.isArray(v)) return v.map(walk);\n\t\t\tif (v && typeof v === 'object') return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, walk(x)]));\n\t\t\treturn v;\n\t\t};\n\t\tconst edit = walk(edits[i]) as MotionEdit;\n\t\tif (problem) return { ok: false, error: `${problem} Nothing was changed.` };\n\t\tconst before = next;\n\t\ttry {\n\t\t\tnext = applyOne(next, edit);\n\t\t} catch (error) {\n\t\t\tif (error instanceof EditError) return { ok: false, error: `${where}: ${error.message} Nothing was changed.` };\n\t\t\tthrow error;\n\t\t}\n\t\tresolved.push(edit);\n\t\tconst out: MotionEditOutcome = { op: edit.op };\n\t\tif (edit.op === 'insert_shots') out.shots = edit.shots.map((s) => s.id);\n\t\tif ('shot' in edit && typeof edit.shot === 'string') out.shot = edit.op === 'update_shot' && edit.set?.id ? edit.set.id : edit.shot;\n\t\tif (edit.op === 'add_commands') {\n\t\t\tconst at = edit.at ?? before.shots.find((s) => s.id === edit.shot)?.run.length ?? 0;\n\t\t\tout.indexes = edit.commands.map((_, k) => at + k);\n\t\t}\n\t\tif (edit.op === 'move_command') out.indexes = [edit.to];\n\t\tif (edit.op === 'set_clip') out.clip = edit.name;\n\t\toutcomes.push(out);\n\t}\n\treturn { ok: true, edits: resolved, outcomes };\n}\n\n/** An empty scene over `artwork`. */\nexport function createMotionScene(artwork: VectorDocument, init: Partial<Omit<MotionScene, 'artwork' | 'version'>> = {}): MotionScene {\n\treturn { version: 1, name: init.name ?? 'animation', ...init, artwork, shots: init.shots ?? [] };\n}\n","// Protected regions adapted from effectcraft-main/crates/render/src/eval.rs (`responsive_source_time`), MIT OR Apache-2.0, © ArtCraft Team and contributors.\nimport { compileMotionScene } from './compile.js';\nimport { namedWithSuggestion } from './issues.js';\nimport type { MotionScene } from './types.js';\n\nexport interface MotionFitOptions {\n\t/** Shot ids that keep their pace (a logo hold, a line of narration); the others absorb the change. */\n\tkeep?: readonly string[];\n}\n\nexport interface MotionFit {\n\tscene: MotionScene;\n\t/** The length after fitting, ms (within a few ms of the target: speeds are rounded). */\n\tduration: number;\n\t/** The new `speed` of every shot that changed. */\n\tspeeds: Record<string, number>;\n}\n\n/** Speeds are kept within this range. */\nexport const MOTION_SPEED_RANGE: readonly [number, number] = [0.05, 20];\n\n/**\n * Fits a scene to `ms` by setting its shots' `speed`: the shots in `keep` play as they are and\n * the rest stretch or squeeze by the same factor, so their timing keeps its proportions (the\n * responsive time of After Effects' protected regions). Throws, changing nothing, when the\n * kept shots alone outlast the target or a speed would leave `MOTION_SPEED_RANGE`.\n */\nexport function fitMotionScene(scene: MotionScene, ms: number, options: MotionFitOptions = {}): MotionFit {\n\tif (!(Number.isFinite(ms) && ms > 0)) throw new Error('Give the length to fit as a number of milliseconds above 0.');\n\tconst ids = scene.shots.map((s) => s.id);\n\tconst keep = new Set(options.keep ?? []);\n\tfor (const id of keep) if (!ids.includes(id)) throw new Error(`There is no shot ${namedWithSuggestion(id, ids)} to keep.`);\n\tconst timeline = compileMotionScene(scene);\n\tlet kept = 0;\n\tlet rest = 0;\n\ttimeline.shots.forEach((t) => (keep.has(t.id) ? (kept += t.end - t.start) : (rest += t.end - t.start)));\n\tif (rest <= 0) throw new Error(keep.size ? 'Every shot is kept, so nothing can change pace; keep fewer shots.' : 'The scene has no length to fit; add shots first.');\n\tif (ms <= kept) throw new Error(`The kept shots alone last ${Math.round(kept)} ms, so the scene cannot fit ${Math.round(ms)} ms; keep fewer shots or give at least ${Math.ceil(kept) + 1} ms.`);\n\tconst k = (ms - kept) / rest;\n\tconst speeds: Record<string, number> = {};\n\tconst shots = scene.shots.map((shot) => {\n\t\tif (keep.has(shot.id)) return shot;\n\t\tconst speed = Math.round(((shot.speed ?? 1) / k) * 10000) / 10000;\n\t\tif (speed < MOTION_SPEED_RANGE[0] || speed > MOTION_SPEED_RANGE[1])\n\t\t\tthrow new Error(`Fitting ${Math.round(ms)} ms would play shot \"${shot.id}\" at ${speed}× (speeds run ${MOTION_SPEED_RANGE[0]}–${MOTION_SPEED_RANGE[1]}); aim nearer the current ${Math.round(timeline.duration)} ms.`);\n\t\tspeeds[shot.id] = speed;\n\t\tconst { speed: _old, ...rest } = shot;\n\t\treturn speed === 1 ? rest : { ...rest, speed };\n\t});\n\tconst fitted: MotionScene = { ...scene, shots };\n\treturn { scene: fitted, duration: compileMotionScene(fitted).duration, speeds };\n}\n","import type { MotionBehavior } from '../animation/behavior.js';\nimport { evaluateEasing, resolveEasing, reverseCubicBezier, type AnimationEasing } from '../animation/easing.js';\nimport { bezierPathToSvg, transformBezierPath } from '../canvas/pathops/bezier.js';\nimport { normalizeTokenColor } from '../tokens/color.js';\nimport { expandVectorAppearance, expandVectorAppearances } from '../vector/appearance.js';\nimport { IDENTITY_MATRIX, collectPathNodes, invertMatrix, nodeMatrix, vectorPathWorldBezier } from '../vector/geometry.js';\nimport { vectorDocumentToSvg, type VectorSvgWrapper } from '../vector/svg.js';\nimport type { VectorNode, VectorPathNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionAddTrackKey, motionTrackKey, segmentValue, trackValue, type MotionProperty, type MotionSegment, motionDrivenNodes, motionDriverSources, motionPropertyValue } from './compile.js';\nimport { motionClipAttrs, motionFollowRoute, motionFrameAt, motionNodeClips, motionNodeOffset } from './evaluate.js';\nimport type { MotionDrivenProperty, MotionScene, MotionTrigger } from './types.js';\n\n/**\n * Export to Flair (`@pixerate/flair`): a scene becomes an `SvgMotion` (one SVG plus a list of\n * from → to changes on its elements), a catalog `VectorEffect`, or an `EffectDocument` for\n * Flair's effect editor. The types are mirrored here so this package does not depend on Flair.\n *\n * Changes are exact where Flair can express them: a change with a linear, cubic-out or\n * cubic-in-out curve (the editor's defaults) is one change, and so (Flair 0.36 and later) is\n * one with any cubic-bezier curve, written as `[x1, y1, x2, y2]`. Anything else (springs,\n * elastic, `hold`, morphs and live-effect tweens) is sampled at the\n * scene's `fps` into short linear changes, which Flair plays the same way. Pulses, shakes,\n * teeters, waves, wiggles and colour pulses are one change with a `behavior` (Flair 0.38).\n *\n * Reveals (`wipe`, `iris`, `split`) wrap their node in a group clipped through a rect or circle\n * in the group's own box units (`clipPathUnits=\"objectBoundingBox\"`), as Flair's\n * `entrance.wipe` does, and animate the shape's attributes. A follow wraps its node in a group\n * that Flair's `along` carries along a copy of the path in the node's parent's units (written\n * in `<defs>`, so the path may be hidden or anywhere), turning with it for `orient`, as\n * Flair's `path.follow` does.\n */\n\n/** Flair's easing names. */\nexport type FlairEaseName = 'linear' | 'in-out' | 'out';\n\n/** Flair's spring ease (Flair 0.39 and later): the editor's spring, number for number. */\nexport interface FlairSpringEase {\n\tspring: { mass?: number; stiffness?: number; damping?: number; velocity?: number };\n}\n\n/** A Flair easing: a name, (Flair 0.36 and later) a CSS cubic-bezier `[x1, y1, x2, y2]`, or (0.39) a spring. */\nexport type FlairEase = FlairEaseName | readonly [number, number, number, number] | FlairSpringEase;\n\n/** Flair's curves, for matching. */\nexport const FLAIR_EASES: Readonly<Record<FlairEaseName, (t: number) => number>> = {\n\tlinear: (t) => t,\n\t'in-out': (t) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2),\n\tout: (t) => 1 - (1 - t) ** 3\n};\n\n/** One change of a Flair `SvgMotion` (mirrors `SvgAnimation` in `@pixerate/flair/vector`). */\nexport interface FlairSvgAnimation {\n\tid?: string;\n\tstep?: number;\n\tdelay?: number;\n\tms?: number;\n\tease?: FlairEase;\n\tattrs?: Record<string, readonly [string | number, string | number]>;\n\tdraw?: boolean | readonly [number, number];\n\t/** Moves the element along a path (by id), from and to the fractions of its length in `at`. */\n\talong?: string;\n\tat?: readonly [number, number];\n\t/** With `along`: turns the element with the path's direction. */\n\torient?: boolean;\n\t/** Flair 0.38 and later: how the change swings from → to (see `MotionBehavior`). */\n\tbehavior?: MotionBehavior;\n\t/** Flair 0.39 and later: stepped time, held on a grid of this many frames per second. */\n\tstrobe?: number;\n\t/** Flair 0.39 and later: whole cycles to play (default 1); with `alternate`, every other one backwards. */\n\trepeat?: number;\n\talternate?: boolean;\n\t/** Flair features scenes do not have (imports skip them with a note). */\n\tcount?: readonly [number, number];\n\twrite?: string;\n\tscramble?: string;\n\tsolo?: number;\n\tview?: readonly [number, number, number, number] | string;\n}\n\n/** Mirrors `SvgMotion` in `@pixerate/flair/vector`. */\nexport interface FlairSvgMotion {\n\tsvg: string;\n\tanimate?: FlairSvgAnimation[];\n}\n\n/** Mirrors Flair's catalog `VectorEffect` (`@pixerate/flair/catalog`). */\nexport interface FlairVectorEffect {\n\tkind: 'vector';\n\tid: string;\n\tname: string;\n\tdescription: string;\n\tcategory: string;\n\ttags: string[];\n\tmotion: FlairSvgMotion;\n\t/** Values are `#rrggbb` strings, or `[r, g, b]` channels from 0 to 1 (Flair's catalog writes both); imports turn them into hex. */\n\tpresets?: { name: string; values: Record<string, string | readonly number[]> }[];\n\t/** Ms on the last frame before looping. */\n\thold?: number;\n\ttrigger?: 'hover' | 'press' | 'click' | 'scroll';\n}\n\n/** Mirrors Flair's `EffectDocument` (`@pixerate/flair/editor`) for a vector effect. */\nexport interface FlairEffectDocument {\n\tversion: 1;\n\tname: string;\n\teffect: { kind: 'vector'; motion: FlairSvgMotion; hold?: number };\n\tvalues: Record<string, string>;\n\ttracks: Record<string, never>;\n\tduration: number;\n\tloop: boolean;\n\tpresets: { name: string; values: Record<string, string> }[];\n}\n\nexport interface FlairMotionExport {\n\tmotion: FlairSvgMotion;\n\t/** The scene's length (ms). */\n\tduration: number;\n\t/** Ms after the last change (Flair's `hold`). */\n\thold: number;\n\t/** Changes sampled into linear steps. */\n\tsampled: number;\n\t/** What could not be carried over, in sentences. */\n\tnotes: string[];\n\t/** How the viewer plays it: pass to Flair's `SvgPlayer` as `{ trigger }` (from the scene's `trigger`). */\n\ttrigger?: MotionTrigger;\n}\n\nexport interface FlairExportOptions {\n\t/**\n\t * Play in answer to the viewer (default: the scene's `trigger`; null for none). With `click`\n\t * shot n is Flair step n + 1: nothing plays until the first click, and each click plays the next shot.\n\t */\n\ttrigger?: MotionTrigger | null;\n\t/** Sampling rate for changes Flair cannot express exactly (default: the scene's `fps`, else 30). */\n\tfps?: number;\n\t/** Decimal places (default 3). */\n\tprecision?: number;\n\t/**\n\t * Write cubic-bezier easings (the `ease`, `ease-in`, `ease-out`, `ease-in-out`, `ease-in-back`\n\t * and `ease-out-back` presets, and `{ type: 'cubic-bezier' }` curves) as one change with\n\t * `ease: [x1, y1, x2, y2]` (default true). Needs Flair 0.36 or later; set false for older\n\t * Flair, and they are sampled into linear steps.\n\t */\n\tcurves?: boolean;\n\t/**\n\t * Write pulses, shakes, teeters, waves, wiggles and colour pulses as one change with a Flair\n\t * `behavior` (default true), so they play exactly. Needs Flair 0.38 or later; set false for\n\t * older Flair, and they are sampled into linear steps.\n\t */\n\tbehaviors?: boolean;\n\t/**\n\t * The Flair version the export is for (default `0.39`): it decides what is written exactly\n\t * and what is sampled. 0.36 adds cubic-bezier curves, 0.38 behaviours, 0.39 springs and\n\t * stepped time (`strobe`). `curves` and `behaviors` override it.\n\t */\n\tflair?: string;\n}\n\n/** The Flair version exports target by default. */\nexport const FLAIR_EXPORT_VERSION = '0.39';\n\n/** Whether Flair `version` is at least `min` (dotted numbers). */\nexport function flairAtLeast(version: string, min: string): boolean {\n\tconst a = version.split('.').map((n) => parseInt(n, 10) || 0);\n\tconst b = min.split('.').map((n) => parseInt(n, 10) || 0);\n\tfor (let i = 0; i < Math.max(a.length, b.length); i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);\n\treturn true;\n}\n\n/** The Flair easing that matches `ease` (within 1% everywhere), if any. */\nexport function flairEaseFor(ease: AnimationEasing): FlairEaseName | undefined {\n\tfor (const name of ['linear', 'out', 'in-out'] as const) {\n\t\tlet worst = 0;\n\t\tfor (let i = 1; i < 40; i++) {\n\t\t\tconst t = i / 40;\n\t\t\tworst = Math.max(worst, Math.abs(evaluateEasing(ease, t, 1000) - FLAIR_EASES[name](t)));\n\t\t}\n\t\tif (worst < 0.01) return name;\n\t}\n\treturn undefined;\n}\n\n/**\n * The Flair easing for `ease`: a Flair name when one matches within 1%, else (with `curves`,\n * the default) the curve's `[x1, y1, x2, y2]` when it is a cubic-bezier. Undefined for curves\n * Flair cannot play (springs, elastic, `hold`), which are sampled.\n */\nexport function flairCurveFor(ease: AnimationEasing, curves = true): FlairEase | undefined {\n\tconst name = flairEaseFor(ease);\n\tif (name || !curves) return name;\n\tconst resolved = resolveEasing(ease);\n\tif (resolved === 'hold' || resolved.type !== 'cubic-bezier') return undefined;\n\treturn [resolved.x1, resolved.y1, resolved.x2, resolved.y2];\n}\n\n/** Whether a curve leaves 0–1 (a back ease or a spring), so its values pass `from` or `to`. */\nconst overshoots = (ease: FlairEase) => typeof ease !== 'string' && ('spring' in ease || ease[1] < 0 || ease[1] > 1 || ease[3] < 0 || ease[3] > 1);\n\ntype ChannelValue = number | string | readonly number[];\n\ninterface Channel {\n\tid: string;\n\t/** `attrs`: several number attributes changing together (`attrs` names them, `value` gives them in order). */\n\tkind: 'attr' | 'attrs' | 'draw' | 'view';\n\tattr?: string;\n\tattrs?: readonly string[];\n\tsegments: MotionSegment[];\n\texact: (segment: MotionSegment) => boolean;\n\t/**\n\t * Whether a value past `from` → `to` plays the same in Flair as in the editor. Transforms and\n\t * the camera extrapolate; colours would leave 0–255 and opacity and draw-on are clamped here.\n\t */\n\tovershoot?: boolean;\n\tvalue: (time: number) => ChannelValue;\n\t/** The value with behaviours ignored: what a behaviour swings towards (default `value`). */\n\traw?: (time: number) => ChannelValue;\n}\n\nconst TRANSFORM_PROPS: MotionProperty[] = ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'follow'];\nconst LINEAR_TRANSFORM = new Set<MotionProperty>(['x', 'y', 'rotation', 'scaleX', 'scaleY']);\n\nfunction hex6(color: unknown): string {\n\tconst hex = normalizeTokenColor(color);\n\treturn hex ? hex.slice(0, 7) : '#000000';\n}\n\n/** A scene as a Flair `SvgMotion`. */\nexport function toFlairSvgMotion(scene: MotionScene, options: FlairExportOptions = {}): FlairMotionExport {\n\tconst fps = options.fps ?? scene.fps ?? 30;\n\tconst precision = options.precision ?? 3;\n\tconst flair = options.flair ?? FLAIR_EXPORT_VERSION;\n\tconst curves = options.curves ?? flairAtLeast(flair, '0.36');\n\tconst behaviors = options.behaviors ?? flairAtLeast(flair, '0.38');\n\tconst springs = flairAtLeast(flair, '0.39');\n\tconst strobes = flairAtLeast(flair, '0.39');\n\tconst writeEase = (ease: FlairEase): FlairEase => (typeof ease === 'string' || 'spring' in ease ? ease : (ease.map(round) as unknown as FlairEase));\n\t// The ease Flair is given for a segment: its curve (run backwards for a mirrored repeat) or its spring, if Flair can take it.\n\tconst easeOf = (segment: MotionSegment): FlairEase | undefined => {\n\t\tconst resolved = resolveEasing(segment.ease);\n\t\tif (resolved !== 'hold' && resolved.type === 'spring') {\n\t\t\tif (!springs || segment.reverse) return undefined;\n\t\t\tconst { mass, stiffness, damping, velocity } = resolved;\n\t\t\treturn { spring: { mass, stiffness, damping, velocity } };\n\t\t}\n\t\tif (!segment.reverse) return flairCurveFor(segment.ease, curves);\n\t\tconst back = reverseCubicBezier(segment.ease);\n\t\treturn back && curves ? flairCurveFor(back, curves) : undefined;\n\t};\n\t// A segment with a behaviour plays exactly when Flair can be given the behaviour.\n\tconst plays = (s: MotionSegment) => (!s.behavior || behaviors) && (!s.steps || strobes) && !s.geometric;\n\tconst round = (n: number) => Math.round(n * 10 ** precision) / 10 ** precision;\n\tconst f = (n: number) => String(round(n));\n\tconst timeline = compileMotionScene(scene);\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst notes: string[] = [];\n\tconst channels: Channel[] = [];\n\tconst track = (id: string, p: MotionProperty) => timeline.tracks.get(motionTrackKey(id, p)) ?? [];\n\n\t// The outermost node (of a path and its groups) whose track sets `p` for that path.\n\tconst owner = (path: VectorPathNode, p: MotionProperty): string | undefined => {\n\t\tconst entry = nodes.get(path.id);\n\t\tif (!entry) return undefined;\n\t\treturn [...entry.ancestors, path.id].find((id) => timeline.tracks.has(motionTrackKey(id, p)));\n\t};\n\n\tconst animatedNodes = new Set([...timeline.segments.map((s) => s.node).filter(Boolean), ...motionDrivenNodes(timeline)]);\n\t// What drivers depend on: a driven property is sampled wherever its sources change.\n\tconst drivenBy = new WeakSet<MotionSegment>();\n\tconst sourcesOf = (id: string, props: MotionDrivenProperty[]) => motionDriverSources(timeline, id, props).map((s) => {\n\t\tconst copy = { ...s };\n\t\tdrivenBy.add(copy);\n\t\treturn copy;\n\t});\n\tconst pathsSeen = new Set<string>();\n\t// Groups written round nodes (outermost first), routes for `along`, and the ids they take.\n\tconst wrap: Record<string, VectorSvgWrapper[]> = {};\n\tconst routes: string[] = [];\n\tconst follows: { id: string; wrapper: string; routes: Map<string, string>; segments: MotionSegment[] }[] = [];\n\tconst usedIds = new Set(nodes.keys());\n\tconst freshId = (base: string) => {\n\t\tlet id = base;\n\t\tfor (let n = 2; usedIds.has(id); n++) id = `${base}-${n}`;\n\t\tusedIds.add(id);\n\t\treturn id;\n\t};\n\tfor (const id of animatedNodes) {\n\t\tconst entry = nodes.get(id)!;\n\t\tconst node = entry.node;\n\t\t// Wrappers only go round nodes that are drawn (a hidden node is left out of the SVG).\n\t\tconst drawn = [...entry.ancestors.map((a) => nodes.get(a)!.node), node].every((n) => n.visible !== false);\n\n\t\t// Reveal clips: a group clipped through a shape whose attributes change (outermost: it clips what the follow carries).\n\t\tfor (const [p, name] of [['clipRect', 'reveal'], ['clipCircle', 'iris']] as const) {\n\t\t\tif (!drawn || !timeline.tracks.has(motionTrackKey(id, p))) continue;\n\t\t\tconst wrapper = freshId(`${id}--${name}`);\n\t\t\tconst clipId = freshId(`${wrapper}-clip`);\n\t\t\tconst shapeId = freshId(`${wrapper}-clip-shape`);\n\t\t\tconst clipAt = (t: number) => motionNodeClips(id, timeline, t).find((c) => c.shape === (p === 'clipRect' ? 'rect' : 'circle'))!;\n\t\t\tconst rest = clipAt(0);\n\t\t\t(wrap[id] ??= []).push({ id: wrapper, clip: { id: clipId, shapeId, shape: rest.shape, attrs: motionClipAttrs(rest) } });\n\t\t\tchannels.push({ id: shapeId, kind: 'attrs', attrs: Object.keys(motionClipAttrs(rest)), segments: [...track(id, p)], exact: () => true, value: (t) => Object.values(motionClipAttrs(clipAt(t))).map((v) => Math.round(v * 1e4) / 1e4) });\n\t\t}\n\n\t\t// A follow: Flair's `along` carries a wrapper, and an inner one puts the node's centre on it.\n\t\tconst followSegments = track(id, 'follow');\n\t\tif (drawn && followSegments.length) {\n\t\t\tconst ids = new Map<string, string>();\n\t\t\tfor (const seg of followSegments) {\n\t\t\t\tif (!seg.path || ids.has(seg.path)) continue;\n\t\t\t\tconst route = motionFollowRoute(entry, nodes.get(seg.path));\n\t\t\t\tif (!route) continue;\n\t\t\t\tconst routeId = freshId(`${id}--follow-route`);\n\t\t\t\tids.set(seg.path, routeId);\n\t\t\t\troutes.push(`<path id=\"${routeId}\" d=\"${bezierPathToSvg(route, { precision })}\" fill=\"none\"/>`);\n\t\t\t}\n\t\t\tif (ids.size) {\n\t\t\t\tconst wrapper = freshId(`${id}--follow`);\n\t\t\t\tconst centre = freshId(`${id}--follow-centre`);\n\t\t\t\tconst c = entry.center;\n\t\t\t\t// Where the follow puts it at the start, for players that draw a still frame without `along`.\n\t\t\t\tconst at = motionNodeOffset(entry, timeline, 0, nodes)?.follow;\n\t\t\t\tconst placed = at ? `translate(${f(at.x)} ${f(at.y)})${at.angle ? ` rotate(${f(at.angle)})` : ''}` : undefined;\n\t\t\t\t(wrap[id] ??= []).push({ id: wrapper, ...(placed ? { transform: placed } : {}) }, { id: centre, transform: `translate(${f(-c.x)} ${f(-c.y)})` });\n\t\t\t\tfollows.push({ id, wrapper, routes: ids, segments: followSegments.filter((seg) => seg.path && ids.has(seg.path)) });\n\t\t\t}\n\t\t}\n\n\t\tconst opacitySources = sourcesOf(id, ['opacity']);\n\t\tif (timeline.tracks.has(motionTrackKey(id, 'opacity')) || opacitySources.length)\n\t\t\tchannels.push({ id, kind: 'attr', attr: 'opacity', segments: [...track(id, 'opacity'), ...opacitySources], exact: (s) => plays(s) && !drivenBy.has(s), value: (t) => round(motionPropertyValue(timeline, id, 'opacity', t)) });\n\n\t\t// The node's own moves, turns and scales (a follow is carried by its wrappers).\n\t\tconst followed = follows.some((x) => x.id === id);\n\t\t// Additive layers share the transform: alone in a stretch they are one change, overlapping the pose they are sampled.\n\t\tconst transformSegments = [...TRANSFORM_PROPS.flatMap((p) => (followed && p === 'follow' ? [] : [...track(id, p), ...(timeline.tracks.get(motionAddTrackKey(id, p)) ?? [])])), ...sourcesOf(id, ['x', 'y', 'rotation', 'scaleX', 'scaleY'])];\n\t\tif (transformSegments.length) {\n\t\t\tconst base = node.transform ? ` matrix(${node.transform.map(f).join(' ')})` : '';\n\t\t\tconst c = entry.center;\n\t\t\tconst transformAt = (t: number, raw: boolean) => {\n\t\t\t\tconst o = motionNodeOffset(entry, timeline, t, nodes, raw, !followed)!;\n\t\t\t\treturn `translate(${f(o.dx)} ${f(o.dy)}) rotate(${f(o.rotation)} ${f(c.x)} ${f(c.y)}) translate(${f(c.x)} ${f(c.y)}) scale(${f(o.scaleX)} ${f(o.scaleY)}) translate(${f(-c.x)} ${f(-c.y)})${base}`;\n\t\t\t};\n\t\t\tchannels.push({\n\t\t\t\tid,\n\t\t\t\tkind: 'attr',\n\t\t\t\tattr: 'transform',\n\t\t\t\tsegments: transformSegments,\n\t\t\t\texact: (s) => LINEAR_TRANSFORM.has(s.property) && plays(s) && !drivenBy.has(s),\n\t\t\t\tovershoot: true,\n\t\t\t\t// x, y and the angle are the transform's numbers 0, 1 and 2 (`MotionSegment.index`).\n\t\t\t\tvalue: (t) => transformAt(t, false),\n\t\t\t\traw: (t) => transformAt(t, true)\n\t\t\t});\n\t\t}\n\n\t\t// Paint, width, fill fade and draw-on live on paths: a group's change goes to each path in it.\n\t\tconst paths = node.type === 'path' ? [node] : collectPathNodes(node);\n\t\tfor (const path of paths) {\n\t\t\tif (pathsSeen.has(path.id)) continue;\n\t\t\tpathsSeen.add(path.id);\n\t\t\tconst paint = (p: 'fill' | 'stroke', attr: string) => {\n\t\t\t\tconst from = owner(path, p);\n\t\t\t\tif (from) channels.push({ id: path.id, kind: 'attr', attr, segments: [...track(from, p)], exact: plays, value: (t) => hex6(trackValue(track(from, p), t)), raw: (t) => hex6(trackValue(track(from, p), t, true)) });\n\t\t\t};\n\t\t\tpaint('fill', 'fill');\n\t\t\tpaint('stroke', 'stroke');\n\t\t\tconst width = owner(path, 'strokeWidth');\n\t\t\tif (width) channels.push({ id: path.id, kind: 'attr', attr: 'stroke-width', segments: [...track(width, 'strokeWidth')], exact: () => true, value: (t) => round(Number(trackValue(track(width, 'strokeWidth'), t))) });\n\t\t\tconst fade = owner(path, 'fillOpacity');\n\t\t\tif (fade) channels.push({ id: path.id, kind: 'attr', attr: 'fill-opacity', segments: [...track(fade, 'fillOpacity')], exact: () => true, value: (t) => round(Number(trackValue(track(fade, 'fillOpacity'), t))) });\n\t\t\tconst draw = owner(path, 'drawEnd');\n\t\t\tif (draw) channels.push({ id: path.id, kind: 'draw', segments: [...track(draw, 'drawEnd')], exact: () => true, value: (t) => round(Math.min(1, Math.max(0, Number(trackValue(track(draw, 'drawEnd'), t))))) });\n\t\t\tif (owner(path, 'drawStart')) notes.push(`\"${path.id}\": drawing from a start other than 0 is not exported; Flair draws from the start of the path.`);\n\t\t}\n\n\t\t// Shape changes (morphs, live effect tweens) are sampled as the path's `d`.\n\t\tconst shapeSegments = [...timeline.tracks.entries()].filter(([k]) => k.startsWith(`${id}\\u0000`) && (k.endsWith('\\u0000shape') || k.includes('\\u0000effect:'))).flatMap(([, v]) => v);\n\t\tif (shapeSegments.length) {\n\t\t\tif (node.type !== 'path') notes.push(`\"${id}\" is a group: its morph or effect animation is not exported (Flair tweens one path's \"d\").`);\n\t\t\telse {\n\t\t\t\tconst inverse = invertMatrix(nodeMatrix(node));\n\t\t\t\tchannels.push({\n\t\t\t\t\tid,\n\t\t\t\t\tkind: 'attr',\n\t\t\t\t\tattr: 'd',\n\t\t\t\t\tsegments: shapeSegments,\n\t\t\t\t\texact: () => false,\n\t\t\t\t\tvalue: (t) => {\n\t\t\t\t\t\tconst frame = motionFrameAt(scene, t, { draw: false, offsets: false });\n\t\t\t\t\t\tconst now = expandVectorAppearance(indexMotionNodes(frame.document.nodes).get(id)?.node as VectorNode);\n\t\t\t\t\t\tif (!now || now.type !== 'path') return '';\n\t\t\t\t\t\tconst bezier = transformBezierPath(vectorPathWorldBezier(now, IDENTITY_MATRIX, { effects: false }), inverse);\n\t\t\t\t\t\treturn bezierPathToSvg(bezier, { precision: Math.min(precision, 2) });\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tconst camera = track('', 'camera');\n\tif (camera.length) channels.push({ id: '', kind: 'view', segments: [...camera], exact: () => true, overshoot: true, value: (t) => (trackValue(camera, t) as number[]).map(round) });\n\n\tconst animate: FlairSvgAnimation[] = [];\n\tlet sampled = 0;\n\tconst same = (a: ChannelValue, b: ChannelValue) => JSON.stringify(a) === JSON.stringify(b);\n\tconst emit = (channel: Channel, delay: number, ms: number, from: ChannelValue, to: ChannelValue, ease: FlairEase, segment?: MotionSegment) => {\n\t\tconst written = writeEase(ease);\n\t\tconst base = {\n\t\t\t...(channel.id ? { id: channel.id } : {}),\n\t\t\t...(delay > 0 ? { delay: round(delay) } : {}),\n\t\t\tms: round(ms),\n\t\t\tease: written,\n\t\t\t...(segment?.behavior ? { behavior: segment.behavior } : {}),\n\t\t\t...(segment?.steps ? { strobe: segment.steps } : {})\n\t\t};\n\t\tif (channel.kind === 'view') animate.push({ ...base, view: to as unknown as [number, number, number, number] });\n\t\telse if (channel.kind === 'draw') animate.push({ ...base, draw: [from as number, to as number] });\n\t\telse if (channel.kind === 'attrs') {\n\t\t\t// Only the numbers that change (as Flair's clip reveals write them).\n\t\t\tconst [a, b] = [from as readonly number[], to as readonly number[]];\n\t\t\tconst attrs = Object.fromEntries(channel.attrs!.flatMap((name, k) => (a[k] !== b[k] ? [[name, [a[k], b[k]] as const]] : [])));\n\t\t\tanimate.push({ ...base, attrs });\n\t\t}\n\t\telse animate.push({ ...base, attrs: { [channel.attr!]: [from as string | number, to as string | number] } });\n\t};\n\n\tfor (const channel of channels) {\n\t\tconst cuts = channel.segments.filter((s) => s.end <= s.start);\n\t\tfor (const cut of cuts) {\n\t\t\tconst [from, to] = [channel.value(Math.max(0, cut.start - 1e-3)), channel.value(cut.start)];\n\t\t\t// A cut to where the value already is changes nothing (at 0 it sets the start, so it stays).\n\t\t\tif (cut.start <= 0 || !same(from, to) || channel.kind === 'view') emit(channel, cut.start, 0, from, to, 'linear');\n\t\t}\n\t\tconst times = [...new Set(channel.segments.flatMap((s) => [s.start, s.end]))].sort((a, b) => a - b);\n\t\tfor (let i = 0; i + 1 < times.length; i++) {\n\t\t\tconst a = times[i];\n\t\t\tconst b = times[i + 1];\n\t\t\tconst active = channel.segments.filter((s) => s.start < b && s.end > a);\n\t\t\tif (!active.length) continue;\n\t\t\t// One change when every active segment spans exactly this interval with one exact curve (a move's x and y, say).\n\t\t\tconst first = active[0];\n\t\t\t// A behaviour (pulse, shake, wriggle…) is one change toward the value it swings round, when every active segment shares it.\n\t\t\tconst key = (x: MotionSegment) => JSON.stringify([x.ease, x.behavior, x.reverse ?? false, x.steps ?? 0]);\n\t\t\tconst together = active.every((x) => x.start === a && x.end === b && channel.exact(x) && key(x) === key(first));\n\t\t\tconst curve = together ? easeOf(first) : undefined;\n\t\t\tconst ease = curve && (!overshoots(curve) || channel.overshoot) ? curve : undefined;\n\t\t\tif (ease) {\n\t\t\t\tconst from = channel.value(a);\n\t\t\t\tconst to = first.behavior ? (channel.raw ?? channel.value)(b) : channel.value(b);\n\t\t\t\tif (!same(from, to) || channel.kind === 'view') emit(channel, a, b - a, from, to, ease, first);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst n = Math.max(1, Math.ceil(((b - a) * fps) / 1000));\n\t\t\tlet prev = channel.value(a);\n\t\t\tfor (let k = 1; k <= n; k++) {\n\t\t\t\tconst t0 = a + ((b - a) * (k - 1)) / n;\n\t\t\t\tconst t1 = a + ((b - a) * k) / n;\n\t\t\t\tconst next = channel.value(t1);\n\t\t\t\tif (!same(prev, next)) {\n\t\t\t\t\temit(channel, t0, t1 - t0, prev, next, 'linear');\n\t\t\t\t\tsampled++;\n\t\t\t\t}\n\t\t\t\tprev = next;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Follows: one `along` per follow, sampled into linear steps only for curves Flair cannot play.\n\tfor (const follow of follows) {\n\t\tconst starts = follow.segments.map((seg) => seg.start);\n\t\tfor (const seg of follow.segments) {\n\t\t\tconst along = { id: follow.wrapper, along: follow.routes.get(seg.path!)!, ...(seg.rotate ? { orient: true } : {}) };\n\t\t\tconst progress = (t: number) => round(Math.min(1, Math.max(0, Number(segmentValue(seg, t)))));\n\t\t\tconst curve = seg.end > seg.start ? (plays(seg) ? easeOf(seg) : undefined) : 'linear';\n\t\t\t// Past the ends, Flair stops turning (its direction is measured either side of the point), so overshoots are sampled.\n\t\t\tif (curve && !(overshoots(curve) && seg.rotate)) {\n\t\t\t\tconst ends = seg.reverse ? [Number(seg.to), Number(seg.from)] : [Number(seg.from), Number(seg.to)];\n\t\t\t\tanimate.push({ ...along, ...(seg.start > 0 ? { delay: round(seg.start) } : {}), ms: round(seg.end - seg.start), ease: writeEase(curve), ...(seg.steps ? { strobe: seg.steps } : {}), at: [round(ends[0]), round(ends[1])] });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Sampled up to the next follow's start, which takes over there.\n\t\t\tconst until = Math.min(seg.end, ...starts.filter((t) => t > seg.start));\n\t\t\tconst n = Math.max(1, Math.ceil(((until - seg.start) * fps) / 1000));\n\t\t\tfor (let k = 1; k <= n; k++) {\n\t\t\t\tconst t0 = seg.start + ((until - seg.start) * (k - 1)) / n;\n\t\t\t\tconst t1 = seg.start + ((until - seg.start) * k) / n;\n\t\t\t\tanimate.push({ ...along, ...(t0 > 0 ? { delay: round(t0) } : {}), ms: round(t1 - t0), ease: 'linear', at: [progress(t0), progress(t1)] });\n\t\t\t\tsampled++;\n\t\t\t}\n\t\t}\n\t}\n\tanimate.sort((x, y) => (x.delay ?? 0) - (y.delay ?? 0));\n\tconst lastChange = animate.reduce((m, a) => Math.max(m, (a.delay ?? 0) + (a.ms ?? 0)), 0);\n\n\t// A click trigger plays shot by shot. Flair's player shows step 0 until the first click and then\n\t// plays it with step 1, so shot n goes on step n + 1: each click plays one shot, from the start.\n\tconst trigger = options.trigger === null ? undefined : (options.trigger ?? scene.trigger);\n\tif (trigger === 'click' && timeline.shots.length) {\n\t\tfor (const a of animate) {\n\t\t\tconst at = a.delay ?? 0;\n\t\t\tlet step = 0;\n\t\t\ttimeline.shots.forEach((shot, i) => {\n\t\t\t\tif (shot.start <= at + 1e-6) step = i;\n\t\t\t});\n\t\t\tconst delay = round(at - timeline.shots[step].start);\n\t\t\tdelete a.delay;\n\t\t\tif (delay > 0) a.delay = delay;\n\t\t\ta.step = step + 1;\n\t\t}\n\t\tanimate.sort((x, y) => (x.step ?? 0) - (y.step ?? 0) || (x.delay ?? 0) - (y.delay ?? 0));\n\t}\n\tif (scene.motionBlur) notes.push('Motion blur is drawn on the stage only; Flair plays the scene sharp.');\n\tif (trigger && (scene.loop ?? 'none') !== 'none') notes.push(`The scene plays on ${trigger}, so its loop does not apply in Flair.`);\n\n\t// The SVG: the artwork at rest, live effects drawn as plain paths so shapes can be tweened,\n\t// with the wrappers that reveals and follows animate, and the routes follows take.\n\tlet svg = vectorDocumentToSvg({ ...scene.artwork, nodes: expandVectorAppearances(scene.artwork.nodes) }, { pretty: false, precision, wrap });\n\tif (routes.length) svg = svg.replace(/^(<svg[^>]*>)/, `$1<defs>${routes.join('')}</defs>`);\n\n\t// Controls: each stands for its default colour wherever it appears.\n\tlet motion: FlairSvgMotion = { svg, animate };\n\tif (scene.controls?.length) {\n\t\tconst declarations = scene.controls.map((c) => `{{${c.name}: color default=${c.default.toUpperCase()}${c.label ? ` label='${c.label.replace(/'/g, '’')}'` : ''}}}`).join(' ');\n\t\tconst swap = (text: string) => scene.controls!.reduce((s, c) => s.replace(new RegExp(`${c.default}(?![0-9a-fA-F])`, 'gi'), `{{${c.name}}}`), text);\n\t\tsvg = svg.replace(/^(<svg[^>]*>)/, `$1<!-- ${declarations} -->`);\n\t\tconst header = svg.indexOf('-->') + 3;\n\t\tsvg = svg.slice(0, header) + swap(svg.slice(header));\n\t\tmotion = { svg, animate: animate.map((a) => (a.attrs ? { ...a, attrs: Object.fromEntries(Object.entries(a.attrs).map(([k, [x, y]]) => [k, [typeof x === 'string' ? swap(x) : x, typeof y === 'string' ? swap(y) : y] as const])) } : a)) };\n\t}\n\treturn { motion, duration: timeline.duration, hold: Math.max(0, round(timeline.duration - lastChange)), sampled, notes: [...new Set(notes)], ...(trigger ? { trigger } : {}) };\n}\n\nexport interface FlairEffectOptions extends FlairExportOptions {\n\t/** Kebab-case id (default: the scene's name). */\n\tid?: string;\n\tname?: string;\n\tdescription?: string;\n\t/** Flair catalog category (default `icon`). */\n\tcategory?: string;\n\ttags?: string[];\n}\n\nconst kebab = (text: string) =>\n\ttext\n\t\t.trim()\n\t\t.replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n\t\t.replace(/[^A-Za-z0-9]+/g, '-')\n\t\t.replace(/^-+|-+$/g, '')\n\t\t.toLowerCase() || 'animation';\n\n/** A scene as a Flair catalog vector effect, with its colour controls and presets. */\nexport function toFlairVectorEffect(scene: MotionScene, options: FlairEffectOptions = {}): FlairVectorEffect {\n\tconst out = toFlairSvgMotion(scene, options);\n\treturn {\n\t\tkind: 'vector',\n\t\tid: options.id ?? kebab(scene.name),\n\t\tname: options.name ?? scene.name,\n\t\tdescription: options.description ?? scene.description ?? '',\n\t\tcategory: options.category ?? 'icon',\n\t\ttags: options.tags ?? [],\n\t\tmotion: out.motion,\n\t\thold: out.hold,\n\t\t...(scene.presets?.length ? { presets: scene.presets } : {}),\n\t\t...(out.trigger ? { trigger: out.trigger } : {})\n\t};\n}\n\n/** A scene as a document for Flair's `EffectEditor` (`replaceDocument`). */\nexport function toFlairEffectDocument(scene: MotionScene, options: FlairExportOptions = {}): FlairEffectDocument {\n\tconst out = toFlairSvgMotion(scene, options);\n\treturn {\n\t\tversion: 1,\n\t\tname: scene.name,\n\t\teffect: { kind: 'vector', motion: out.motion, hold: out.hold },\n\t\tvalues: Object.fromEntries((scene.controls ?? []).map((c) => [c.name, c.default])),\n\t\ttracks: {},\n\t\tduration: out.duration,\n\t\t// Flair's editor documents have no trigger: a click scene keeps its steps, and plays through there.\n\t\tloop: !out.trigger && (scene.loop ?? 'none') !== 'none',\n\t\tpresets: scene.presets ?? []\n\t};\n}\n","import type { MotionBehavior } from '../animation/behavior.js';\nimport type { AnimationEasing } from '../animation/easing.js';\nimport { applyMatrix, invertMatrix, multiplyMatrices, nodeMatrix, type AffineMatrix } from '../vector/geometry.js';\nimport { parseSvgTransform, parseVectorSvg } from '../vector/svg.js';\nimport { checkMotionScene } from './check.js';\nimport { indexMotionNodes, MOTION_EASE_IN_OUT, MOTION_EASE_OUT, type MotionNodeEntry } from './compile.js';\nimport type { FlairEase, FlairSvgAnimation, FlairSvgMotion, FlairVectorEffect } from './flair.js';\nimport type { MotionIssue } from './issues.js';\nimport { motionSceneShapeProblems } from './parse.js';\nimport type { MotionCamera, MotionCommand, MotionControl, MotionScene, MotionShot } from './types.js';\n\n/**\n * Import from Flair: a Flair `SvgMotion` (or a catalog `VectorEffect`) becomes a scene, so an\n * effect made in Flair, or taken from its catalog, can be opened and edited here. The reverse\n * of `toFlairSvgMotion`, as far as the scene model goes:\n *\n * - The SVG becomes the artwork (`parseVectorSvg`); `{{name: color …}}` placeholders become\n * colour controls (other placeholders take their defaults).\n * - Each Flair step becomes a shot, its changes commands timed by their `delay`, all together.\n * - Opacity, paint, stroke width, transforms (as move, rotate and scale), drawing on, following\n * a path, camera views and behaviours (pulse, shake, teeter, wave, wiggle, colour pulse) carry\n * over. Counting, writing text, solo containers and anything else are listed in `notes`.\n */\n\nexport interface FlairImportResult {\n\tscene: MotionScene;\n\t/** What could not be carried over exactly, in sentences. */\n\tnotes: string[];\n\t/** `checkMotionScene` of the result. */\n\tissues: MotionIssue[];\n}\n\nexport interface FlairImportOptions {\n\t/** The scene's name (default: the effect's, else `from-flair`). */\n\tname?: string;\n\t/** Hold after the last shot, ms (default: the effect's `hold`, else 600). */\n\thold?: number;\n\t/**\n\t * The motion plays on click: Flair plays step 0 together with step 1 on the first click, so\n\t * both become the first shot (as `toFlairSvgMotion` writes them).\n\t */\n\tclickSteps?: boolean;\n}\n\n/** A `{{name}}` placeholder or `{{name: type attributes}}` declaration, as Flair writes them. */\nconst PLACEHOLDER = /\\{\\{\\s*([A-Za-z_]\\w*)\\s*(?::\\s*([A-Za-z0-9]*)([^}]*))?\\}\\}/g;\n\nfunction attributeOf(attrs: string, name: string): string | undefined {\n\tconst m = new RegExp(`(?:^|\\\\s)${name}=(?:'([^']*)'|(\\\\S+))`).exec(attrs);\n\treturn m ? (m[1] ?? m[2]) : undefined;\n}\n\n/** Placeholders replaced by their defaults; colour declarations become controls. */\nfunction resolvePlaceholders(motion: FlairSvgMotion, notes: string[]): { motion: FlairSvgMotion; controls: MotionControl[] } {\n\tconst text = JSON.stringify(motion);\n\tconst declared = new Map<string, { type: string; value: string; label?: string }>();\n\tfor (const m of text.matchAll(PLACEHOLDER)) {\n\t\tif (!m[2] || declared.has(m[1])) continue;\n\t\tconst attrs = m[3] ?? '';\n\t\tconst value = attributeOf(attrs, 'default');\n\t\tconst fallback = m[2] === 'color' ? '#000000' : '0';\n\t\tdeclared.set(m[1], { type: m[2], value: m[2] === 'color' ? (value ?? fallback).toLowerCase() : (value ?? fallback), ...(attributeOf(attrs, 'label') ? { label: attributeOf(attrs, 'label') } : {}) });\n\t}\n\tconst controls: MotionControl[] = [];\n\tfor (const [name, d] of declared) {\n\t\tif (d.type === 'color' && /^#[0-9a-fA-F]{6}$/.test(d.value)) controls.push({ name, type: 'color', default: d.value.toLowerCase(), ...(d.label ? { label: d.label } : {}) });\n\t\telse notes.push(`Control \"${name}\" (${d.type}) is fixed at its default ${d.value}: scenes take colour controls only.`);\n\t}\n\tconst unknown = new Set<string>();\n\tconst filled = text.replace(PLACEHOLDER, (_, name: string) => {\n\t\tconst d = declared.get(name);\n\t\tif (!d) unknown.add(name);\n\t\treturn (d?.value ?? '').replace(/\"/g, '\\\\\"');\n\t});\n\tfor (const name of unknown) notes.push(`Placeholder \"{{${name}}}\" has no declaration, so it was left empty.`);\n\t// SVG comments (where Flair declares controls) are dropped with the markup's comments.\n\treturn { motion: JSON.parse(filled) as FlairSvgMotion, controls };\n}\n\n/** A Flair ease as an editor easing. Flair's `in-out` is a cubic polynomial, close to the editor's ease-in-out curve. */\nfunction easingOf(ease: FlairEase | undefined, fallback: AnimationEasing): AnimationEasing {\n\tif (ease === undefined) return fallback;\n\tif (ease === 'linear') return 'linear';\n\tif (ease === 'out') return MOTION_EASE_OUT;\n\tif (ease === 'in-out') return MOTION_EASE_IN_OUT;\n\tif (Array.isArray(ease)) return { type: 'cubic-bezier', x1: ease[0], y1: ease[1], x2: ease[2], y2: ease[3] };\n\tif (typeof ease === 'object' && 'spring' in ease) return { type: 'spring', ...ease.spring };\n\treturn fallback;\n}\n\ninterface Pose {\n\tdx: number;\n\tdy: number;\n\trotation: number;\n\tsx: number;\n\tsy: number;\n}\n\n/** A Flair transform value as the editor's offset from the node's rest (move, turn and scale about its centre), or null when it skews. */\nfunction poseOf(value: string | number, entry: MotionNodeEntry): Pose | null {\n\tconst t = parseSvgTransform(String(value));\n\tconst o: AffineMatrix = multiplyMatrices(invertMatrix(nodeMatrix(entry.node)) ?? [1, 0, 0, 1, 0, 0], t);\n\tconst sx = Math.hypot(o[0], o[1]);\n\tif (!(sx > 1e-9)) return null;\n\tconst sy = (o[0] * o[3] - o[1] * o[2]) / sx;\n\t// No skew: the second column is the first turned a quarter, times sy.\n\tif (Math.abs(o[2] + (o[1] / sx) * sy) > 1e-6 || Math.abs(o[3] - (o[0] / sx) * sy) > 1e-6) return null;\n\tconst c = entry.center;\n\tconst moved = applyMatrix(o, c);\n\treturn { dx: moved.x - c.x, dy: moved.y - c.y, rotation: (Math.atan2(o[1], o[0]) * 180) / Math.PI, sx, sy };\n}\n\nconst near = (a: number, b: number, eps = 1e-6) => Math.abs(a - b) < eps;\nconst r3 = (n: number) => Math.round(n * 1000) / 1000;\n\n/** One Flair change as commands (all starting together), or a note on why it is skipped. */\nfunction commandsFor(anim: FlairSvgAnimation, nodes: Map<string, MotionNodeEntry>, entered: Set<string>, notes: string[]): MotionCommand[] {\n\tconst id = anim.id!;\n\tconst entry = nodes.get(id);\n\tconst where = `\"${id}\"`;\n\tif (!entry) {\n\t\tnotes.push(`A change to ${where} was skipped: the artwork has no element with that id.`);\n\t\treturn [];\n\t}\n\tconst targets = [id];\n\tconst duration = anim.ms ?? 800;\n\tconst timing = {\n\t\tduration,\n\t\t...(anim.strobe ? { steps: anim.strobe } : {}),\n\t\t...(anim.repeat && anim.repeat > 1 ? { repeat: anim.repeat, ...(anim.alternate ? { repeatMode: 'mirror' as const } : {}) } : {})\n\t};\n\tconst ease = (fallback: AnimationEasing) => ({ ease: easingOf(anim.ease, fallback) });\n\tconst out: MotionCommand[] = [];\n\tconst behavior: MotionBehavior | undefined = anim.behavior;\n\tconst unsupported = (['count', 'write', 'scramble', 'solo'] as const).filter((k) => (anim as Record<string, unknown>)[k] !== undefined);\n\tif (unsupported.length) notes.push(`${where}: ${unsupported.join(', ')} ${unsupported.length > 1 ? 'are' : 'is'} not part of scenes and was skipped.`);\n\n\tif (anim.draw !== undefined && anim.draw !== false) {\n\t\tconst [from, to] = anim.draw === true ? [0, 1] : anim.draw;\n\t\tout.push({ type: 'draw', targets, from, to, ...timing, ...ease(MOTION_EASE_IN_OUT) });\n\t}\n\tif (anim.along) {\n\t\tconst path = nodes.get(anim.along);\n\t\tif (!path || path.node.type !== 'path') notes.push(`${where} follows \"${anim.along}\", which is not a path in the artwork; the follow was skipped.`);\n\t\telse out.push({ type: 'follow', targets, path: anim.along, from: anim.at?.[0] ?? 0, to: anim.at?.[1] ?? 1, ...(anim.orient ? { rotate: true } : {}), ...timing, ...ease(MOTION_EASE_IN_OUT) });\n\t}\n\tfor (const [attr, [a, b]] of Object.entries(anim.attrs ?? {})) {\n\t\tif (attr === 'opacity') {\n\t\t\tconst [from, to] = [Number(a), Number(b)];\n\t\t\tif (behavior) notes.push(`${where}: an opacity ${behavior.type} became a plain fade.`);\n\t\t\tif (from === 0 && to > 0 && !entered.has(id)) {\n\t\t\t\tentered.add(id);\n\t\t\t\tout.push({ type: 'enter', targets, style: 'fade', ...timing, ...ease(MOTION_EASE_OUT) });\n\t\t\t} else out.push({ type: 'fade', targets, to: Math.min(1, Math.max(0, to)), ...timing, ...ease(MOTION_EASE_IN_OUT) });\n\t\t} else if (attr === 'fill' || attr === 'stroke') {\n\t\t\tif (behavior?.type === 'pulse') out.push({ type: 'color-pulse', targets, color: String(b), paint: attr, count: behavior.count ?? 1, ...timing, ...ease('linear') });\n\t\t\telse {\n\t\t\t\tif (behavior) notes.push(`${where}: a ${attr} ${behavior.type} became a plain colour change.`);\n\t\t\t\tout.push({ type: 'style', targets, [attr]: String(b), ...timing, ...ease(MOTION_EASE_IN_OUT) } as MotionCommand);\n\t\t\t}\n\t\t} else if (attr === 'stroke-width') {\n\t\t\tout.push({ type: 'style', targets, strokeWidth: Number(b), ...timing, ...ease(MOTION_EASE_IN_OUT) });\n\t\t} else if (attr === 'transform') {\n\t\t\tconst p0 = poseOf(a, entry);\n\t\t\tconst p1 = poseOf(b, entry);\n\t\t\tif (!p0 || !p1) {\n\t\t\t\tnotes.push(`${where}: a transform that skews was skipped (scenes move, turn and scale).`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst d = { x: r3(p1.dx - p0.dx), y: r3(p1.dy - p0.dy), r: r3(p1.rotation - p0.rotation), sx: p1.sx / p0.sx, sy: p1.sy / p0.sy };\n\t\t\tif (behavior) {\n\t\t\t\tconst linear = ease('linear');\n\t\t\t\tconst moves = d.x !== 0 || d.y !== 0;\n\t\t\t\tconst turns = d.r !== 0;\n\t\t\t\tconst scales = !near(d.sx, 1) || !near(d.sy, 1);\n\t\t\t\tif (behavior.type === 'pulse' && scales && !moves && !turns) out.push({ type: 'pulse', targets, amount: r3(d.sx - 1), count: behavior.count ?? 1, ...timing, ...linear });\n\t\t\t\telse if (behavior.type === 'oscillate' && (behavior.decay ?? 0) > 0 && turns && !moves && !scales) out.push({ type: 'teeter', targets, angle: d.r, count: behavior.count ?? 1, ...timing, ...linear });\n\t\t\t\telse if (behavior.type === 'oscillate' && (behavior.decay ?? 0) > 0 && moves && !turns && !scales && (d.x === 0 || d.y === 0))\n\t\t\t\t\tout.push({ type: 'shake', targets, amount: d.x || d.y, count: behavior.count ?? 1, ...(d.x === 0 ? { axis: 'vertical' as const } : {}), ...timing, ...linear });\n\t\t\t\telse if (behavior.type === 'oscillate' && !behavior.decay && d.x === 0 && d.y !== 0 && !turns && !scales) out.push({ type: 'wave', targets, amount: -d.y, count: behavior.count ?? 1, ...timing, ...linear });\n\t\t\t\telse if (behavior.type === 'wriggle' && !scales)\n\t\t\t\t\tout.push({ type: 'wiggle', targets, amount: Math.max(Math.abs(d.x), Math.abs(d.y)), ...(turns ? { rotate: Math.abs(d.r) } : {}), frequency: behavior.frequency ?? 2, octaves: behavior.octaves ?? 2, seed: behavior.seed ?? 42, ...timing, ...linear });\n\t\t\t\telse notes.push(`${where}: a transform ${behavior.type} that is not a pulse, shake, teeter, wave or wiggle was skipped.`);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst e = ease(MOTION_EASE_IN_OUT);\n\t\t\tif (d.x !== 0 || d.y !== 0) out.push({ type: 'move', targets, by: { x: d.x, y: d.y }, ...timing, ...e });\n\t\t\tif (d.r !== 0) out.push({ type: 'rotate', targets, to: r3(p1.rotation), ...timing, ...e });\n\t\t\tif (!near(d.sx, 1) || !near(d.sy, 1)) out.push({ type: 'scale', targets, to: near(p1.sx, p1.sy) ? r3(p1.sx) : { x: r3(p1.sx), y: r3(p1.sy) }, ...timing, ...e });\n\t\t} else notes.push(`${where}: changing \"${attr}\" is not part of scenes and was skipped.`);\n\t}\n\treturn out;\n}\n\n/** A Flair `SvgMotion` as a scene (see the module notes for what carries over). */\nexport function fromFlairSvgMotion(input: FlairSvgMotion, options: FlairImportOptions = {}): FlairImportResult {\n\tconst notes: string[] = [];\n\tif (!input || typeof input.svg !== 'string') throw new Error('Give a Flair SvgMotion: { svg: \"<svg …>\", animate: [ … ] }.');\n\tconst { motion, controls } = resolvePlaceholders(input, notes);\n\tconst artwork = parseVectorSvg(motion.svg);\n\tconst nodes = indexMotionNodes(artwork.nodes);\n\tconst byStep = new Map<number, FlairSvgAnimation[]>();\n\tfor (const anim of motion.animate ?? []) {\n\t\tconst raw = Math.max(0, Math.floor(anim.step ?? 0));\n\t\tconst step = options.clickSteps ? Math.max(1, raw) : raw;\n\t\tif (!byStep.has(step)) byStep.set(step, []);\n\t\tbyStep.get(step)!.push(anim);\n\t}\n\tconst steps = [...byStep.keys()].sort((a, b) => a - b);\n\tif (steps.length > 1) notes.push('Each Flair step became a shot played after the one before (Flair steps wait for clicks or set times).');\n\tconst entered = new Set<string>();\n\tconst shots: MotionShot[] = steps.map((step, index) => {\n\t\tconst anims = [...byStep.get(step)!].sort((a, b) => (a.delay ?? 0) - (b.delay ?? 0));\n\t\tlet camera: MotionCamera | undefined;\n\t\tlet cameraMs = 0;\n\t\tconst run: MotionCommand[] = [];\n\t\tlet last = 0;\n\t\tfor (const anim of anims) {\n\t\t\tif (anim.view !== undefined) {\n\t\t\t\tif (camera || (anim.delay ?? 0) > 0) {\n\t\t\t\t\tnotes.push(`Step ${step}: a camera move ${camera ? 'after the first' : `${anim.delay} ms in`} was dropped; a shot frames the camera once, at its start.`);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst ms = anim.ms ?? 800;\n\t\t\t\tconst ease = easingOf(anim.ease, MOTION_EASE_IN_OUT);\n\t\t\t\tcamera = typeof anim.view === 'string' ? { frame: anim.view, padding: 0, ms, ease } : { x: anim.view[0], y: anim.view[1], width: anim.view[2], height: anim.view[3], ms, ease };\n\t\t\t\tcameraMs = index === 0 ? 0 : ms;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!anim.id) continue;\n\t\t\t// A shot's commands start after its camera move: earlier changes are pushed back to it.\n\t\t\tconst at = Math.max(0, (anim.delay ?? 0) - cameraMs);\n\t\t\tif (cameraMs && (anim.delay ?? 0) < cameraMs) notes.push(`Step ${step}: a change to \"${anim.id}\" during the camera move now starts after it.`);\n\t\t\tfor (const command of commandsFor(anim, nodes, entered, notes)) {\n\t\t\t\tconst first = run.length === 0;\n\t\t\t\trun.push({ ...command, ...(first ? {} : { with: 'previous' as const }), ...(at - last > 0 || first ? { delay: first ? at : at - last } : {}) } as MotionCommand);\n\t\t\t\tif (first && at === 0) delete (run[run.length - 1] as { delay?: number }).delay;\n\t\t\t\tlast = at;\n\t\t\t}\n\t\t}\n\t\treturn { id: `step-${step}`, ...(camera ? { camera } : {}), run, ...(index === steps.length - 1 ? { hold: options.hold ?? 600 } : {}) };\n\t});\n\tconst scene: MotionScene = { version: 1, name: options.name ?? 'from-flair', artwork, shots, ...(controls.length ? { controls } : {}) };\n\tconst problems = motionSceneShapeProblems(scene);\n\tif (problems.length) throw new Error(`The imported scene is not well formed:\\n${problems.join('\\n')}`);\n\treturn { scene, notes: [...new Set(notes)], issues: checkMotionScene(scene) };\n}\n\n/** A preset colour as `#rrggbb`: Flair writes them as hex strings or as `[r, g, b]` arrays of 0–1 channels (as its `rgbToHex` reads them). */\nfunction presetColor(value: unknown): string | undefined {\n\tif (typeof value === 'string') return /^#[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : value;\n\tif (Array.isArray(value) && value.length >= 3 && value.slice(0, 3).every((n) => typeof n === 'number' && Number.isFinite(n)))\n\t\treturn `#${value\n\t\t\t.slice(0, 3)\n\t\t\t.map((n: number) => Math.round(Math.min(1, Math.max(0, n)) * 255).toString(16).padStart(2, '0'))\n\t\t\t.join('')}`;\n\treturn undefined;\n}\n\n/** A Flair catalog `VectorEffect` as a scene: its motion, name, description, colour controls and presets. */\nexport function fromFlairVectorEffect(effect: FlairVectorEffect, options: FlairImportOptions = {}): FlairImportResult {\n\tif (!effect || effect.kind !== 'vector' || !effect.motion) throw new Error('Give a Flair vector effect: { kind: \"vector\", id, name, motion: { svg, animate } }.');\n\tconst result = fromFlairSvgMotion(effect.motion, { name: options.name ?? effect.id ?? effect.name, hold: options.hold ?? effect.hold, ...(effect.trigger === 'click' ? { clickSteps: true } : {}) });\n\tconst names = new Set((result.scene.controls ?? []).map((c) => c.name));\n\tconst presets = (effect.presets ?? [])\n\t\t.map((p) => ({ name: p.name, values: Object.fromEntries(Object.entries(p.values).flatMap(([k, v]) => (names.has(k) && presetColor(v) ? [[k, presetColor(v)!]] : []))) }))\n\t\t.filter((p) => Object.keys(p.values).length);\n\t// Flair's steps became shots, so a click trigger plays them shot by shot again on export.\n\tconst scene: MotionScene = { ...result.scene, ...(effect.description ? { description: effect.description } : {}), ...(presets.length ? { presets } : {}), ...(effect.trigger ? { trigger: effect.trigger } : {}) };\n\tconst notes = [...result.notes];\n\treturn { scene, notes, issues: checkMotionScene(scene) };\n}\n","// Export mapping adapted from effectcraft-main/crates/lottie/src/{anim,shapes,export}.rs (MIT OR Apache-2.0, © ArtCraft Team and contributors).\nimport { resolveEasing, reverseCubicBezier } from '../animation/easing.js';\nimport { toBezierPath, type BezierPath } from '../canvas/pathops/bezier.js';\nimport { normalizeTokenColor } from '../tokens/color.js';\nimport { expandVectorAppearances } from '../vector/appearance.js';\nimport { IDENTITY_MATRIX, nodeMatrix, vectorPathWorldBezier, type AffineMatrix } from '../vector/geometry.js';\nimport type { VectorNode, VectorPaint, VectorPathNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionTrackKey, trackValue, type MotionNodeEntry, type MotionProperty, type MotionSegment, motionDriverSources, motionPropertyValue } from './compile.js';\nimport { motionFrameAt, motionNodeOffset } from './evaluate.js';\nimport type { MotionScene } from './types.js';\n\n/**\n * Export to Lottie (Bodymovin JSON, v5): the scene as one shape layer whose groups mirror the\n * artwork. Lottie players (lottie-web, rlottie, the iOS and Android libraries) then play it.\n *\n * - Each node is an outer group carrying its animated pose (anchor at its centre, position,\n * scale, rotation, opacity) around an inner group carrying its own transform. Paths keep their\n * own transform in their points.\n * - Paths become `sh` shapes with solid fills (`fl`) and strokes (`st`). Drawing on becomes trim\n * paths (`tm`), and colours, stroke width and fill opacity animate on the fill and stroke.\n * - The camera becomes the transform of a root group.\n * - A change is written as keyframes with Lottie's bezier easing when a cubic-bezier ease (run\n * backwards for a mirrored repeat) is all that drives that property over that stretch.\n * Everything else is sampled at `fps` into linear keyframes: springs, elastic, behaviours,\n * stepped time, geometric zooms, additive layers, follows and camera moves.\n *\n * Gradients, dashes, reveal clips and skews of groups are not carried over; `notes` says so.\n */\n\n/** A Lottie property: static (`a: 0`) or keyframed (`a: 1`). */\nexport type LottieValue = { a: 0; k: number | number[] } | { a: 1; k: LottieKeyframe[] };\n\nexport interface LottieKeyframe {\n\t/** Frame. */\n\tt: number;\n\t/** Value from this key on. */\n\ts: number[];\n\t/** Out tangent of the ease to the next key (`x1`, `y1`). */\n\to?: { x: number[]; y: number[] };\n\t/** In tangent of the ease to the next key (`x2`, `y2`). */\n\ti?: { x: number[]; y: number[] };\n\t/** Hold until the next key. */\n\th?: 1;\n}\n\n/** A Lottie shape item (group, path, fill, stroke, trim, transform): plain JSON. */\nexport type LottieShape = { ty: string; nm?: string; [key: string]: unknown };\n\n/** A Lottie animation: plain Bodymovin JSON. */\nexport interface LottieAnimation {\n\tv: string;\n\tfr: number;\n\tip: number;\n\top: number;\n\tw: number;\n\th: number;\n\tnm: string;\n\tddd: 0;\n\tassets: [];\n\tlayers: Record<string, unknown>[];\n\t/** One marker per shot (`cm` its label, else its id). */\n\tmarkers: { tm: number; cm: string; dr: number }[];\n}\n\nexport interface LottieExportOptions {\n\t/** Frame rate and sampling rate (default: the scene's `fps`, else 30). */\n\tfps?: number;\n\t/** Decimal places (default 3). */\n\tprecision?: number;\n}\n\nexport interface LottieExport {\n\tlottie: LottieAnimation;\n\t/** Keyframes that sample changes Lottie cannot ease the same way. */\n\tsampled: number;\n\t/** What could not be carried over, in sentences. */\n\tnotes: string[];\n}\n\ntype Vec = number[];\ntype Bezier4 = [number, number, number, number];\n\nconst STATIC_TR = (): LottieShape => ({\n\tty: 'tr',\n\tp: { a: 0, k: [0, 0] },\n\ta: { a: 0, k: [0, 0] },\n\ts: { a: 0, k: [100, 100] },\n\tr: { a: 0, k: 0 },\n\to: { a: 0, k: 100 },\n\tsk: { a: 0, k: 0 },\n\tsa: { a: 0, k: 0 }\n});\n\n/** `#rrggbb` (or anything `normalizeTokenColor` reads) as Lottie's 0–1 RGBA. */\nfunction rgba(color: unknown): Vec | null {\n\tconst hex = typeof color === 'string' ? normalizeTokenColor(color) : null;\n\tif (!hex) return null;\n\tconst n = (i: number) => parseInt(hex.slice(i, i + 2), 16) / 255;\n\treturn [n(1), n(3), n(5), hex.length >= 9 ? parseInt(hex.slice(7, 9), 16) / 255 : 1];\n}\n\n/** A path as Lottie shape data per contour: vertices with in / out tangents relative to them. */\nfunction lottieContours(path: BezierPath, round: (n: number) => number): { c: boolean; v: Vec[]; i: Vec[]; o: Vec[] }[] {\n\tconst out: { c: boolean; v: Vec[]; i: Vec[]; o: Vec[] }[] = [];\n\tlet cur: { c: boolean; v: Vec[]; i: Vec[]; o: Vec[] } | null = null;\n\tlet px = 0;\n\tlet py = 0;\n\tconst add = (x: number, y: number, inX: number, inY: number) => {\n\t\tcur!.v.push([x, y]);\n\t\tcur!.i.push([inX - x, inY - y]);\n\t\tcur!.o.push([0, 0]);\n\t\tpx = x;\n\t\tpy = y;\n\t};\n\tfor (const cmd of path) {\n\t\tif (cmd.type === 'M') {\n\t\t\tif (cur) out.push(cur);\n\t\t\tcur = { c: false, v: [], i: [], o: [] };\n\t\t\tadd(cmd.x, cmd.y, cmd.x, cmd.y);\n\t\t} else if (!cur) continue;\n\t\telse if (cmd.type === 'L') add(cmd.x, cmd.y, cmd.x, cmd.y);\n\t\telse if (cmd.type === 'Q') {\n\t\t\tconst c1 = [px + (2 / 3) * (cmd.x1 - px), py + (2 / 3) * (cmd.y1 - py)];\n\t\t\tconst c2 = [cmd.x + (2 / 3) * (cmd.x1 - cmd.x), cmd.y + (2 / 3) * (cmd.y1 - cmd.y)];\n\t\t\tcur.o[cur.o.length - 1] = [c1[0] - px, c1[1] - py];\n\t\t\tadd(cmd.x, cmd.y, c2[0], c2[1]);\n\t\t} else if (cmd.type === 'C') {\n\t\t\tcur.o[cur.o.length - 1] = [cmd.x1 - px, cmd.y1 - py];\n\t\t\tadd(cmd.x, cmd.y, cmd.x2, cmd.y2);\n\t\t} else if (cmd.type === 'Z') {\n\t\t\tcur.c = true;\n\t\t\t// A closing segment that ends on the first vertex folds into it.\n\t\t\tconst n = cur.v.length;\n\t\t\tif (n > 1 && Math.abs(cur.v[n - 1][0] - cur.v[0][0]) < 1e-9 && Math.abs(cur.v[n - 1][1] - cur.v[0][1]) < 1e-9) {\n\t\t\t\tcur.i[0] = cur.i[n - 1];\n\t\t\t\tcur.v.pop();\n\t\t\t\tcur.i.pop();\n\t\t\t\tcur.o.pop();\n\t\t\t}\n\t\t\tout.push(cur);\n\t\t\tcur = null;\n\t\t}\n\t}\n\tif (cur) out.push(cur);\n\treturn out.map((c) => ({ c: c.c, v: c.v.map((p) => p.map(round)), i: c.i.map((p) => p.map(round)), o: c.o.map((p) => p.map(round)) }));\n}\n\n/** The node's own matrix as Lottie transform parts (no skew), or null when it skews. */\nfunction staticParts(m: AffineMatrix): { p: Vec; s: Vec; r: number } | null {\n\tconst sx = Math.hypot(m[0], m[1]);\n\tif (!(sx > 1e-12)) return null;\n\tconst sy = (m[0] * m[3] - m[1] * m[2]) / sx;\n\tif (Math.abs(m[2] + (m[1] / sx) * sy) > 1e-6 || Math.abs(m[3] - (m[0] / sx) * sy) > 1e-6) return null;\n\treturn { p: [m[4], m[5]], s: [sx * 100, sy * 100], r: (Math.atan2(m[1], m[0]) * 180) / Math.PI };\n}\n\n/** A scene as a Lottie animation. */\nexport function toLottie(scene: MotionScene, options: LottieExportOptions = {}): LottieExport {\n\tconst fps = options.fps ?? scene.fps ?? 30;\n\tconst precision = options.precision ?? 3;\n\tconst round = (n: number) => Math.round(n * 10 ** precision) / 10 ** precision;\n\tconst frame = (ms: number) => round((ms * fps) / 1000);\n\tconst timeline = compileMotionScene(scene);\n\tconst nodes = indexMotionNodes(scene.artwork.nodes);\n\tconst notes: string[] = [];\n\tif (scene.motionBlur) notes.push('Motion blur is drawn on the stage only; the Lottie plays sharp.');\n\tif (scene.trigger) notes.push(`The scene plays on ${scene.trigger}; Lottie has no trigger, so it plays through (markers show where each shot starts, for a player to stop at).`);\n\tlet sampled = 0;\n\tconst track = (id: string, p: MotionProperty) => timeline.tracks.get(motionTrackKey(id, p)) ?? [];\n\t// Additive layers (blend \"add\"), on their own tracks when the editor has them.\n\tconst layers = (id: string, p: MotionProperty) => timeline.tracks.get(`${motionTrackKey(id, p)}\\u0000add`) ?? [];\n\tconst end = timeline.duration;\n\n\t/** The Lottie bezier for a segment's ease, if its change can be one eased keyframe. */\n\tconst curveOf = (s: MotionSegment): Bezier4 | undefined => {\n\t\tif (s.behavior || s.steps || s.geometric) return undefined;\n\t\tconst e = s.reverse ? reverseCubicBezier(s.ease) : resolveEasing(s.ease);\n\t\tif (!e || e === 'hold' || e.type !== 'cubic-bezier') return undefined;\n\t\treturn [e.x1, e.y1, e.x2, e.y2];\n\t};\n\n\t/**\n\t * A property's keyframes: one eased key per stretch where every active segment shares that\n\t * stretch and one cubic-bezier ease, linear keys at `fps` elsewhere.\n\t */\n\tconst animate = (segments: readonly MotionSegment[], value: (t: number) => Vec, exact = true): LottieValue => {\n\t\tconst rest = value(0).map(round);\n\t\tif (!segments.length) return { a: 0, k: rest.length === 1 ? rest[0] : rest };\n\t\tconst keys: LottieKeyframe[] = [];\n\t\tconst key = (t: number, v: Vec, ease?: Bezier4 | 'linear' | 'hold') => {\n\t\t\tconst k: LottieKeyframe = { t: frame(t), s: v.map(round) };\n\t\t\tif (ease === 'hold') k.h = 1;\n\t\t\telse {\n\t\t\t\tconst [x1, y1, x2, y2] = ease === 'linear' || !ease ? [0, 0, 1, 1] : ease;\n\t\t\t\tk.o = { x: [round(x1)], y: [round(y1)] };\n\t\t\t\tk.i = { x: [round(x2)], y: [round(y2)] };\n\t\t\t}\n\t\t\tif (keys.length && keys[keys.length - 1].t === k.t) keys[keys.length - 1] = k;\n\t\t\telse keys.push(k);\n\t\t};\n\t\tconst times = [...new Set([0, ...segments.flatMap((s) => [s.start, s.end]), end])].filter((t) => t >= 0 && t <= end).sort((a, b) => a - b);\n\t\tfor (let n = 0; n + 1 < times.length; n++) {\n\t\t\tconst a = times[n];\n\t\t\tconst b = times[n + 1];\n\t\t\tconst active = segments.filter((s) => s.start < b && s.end > a);\n\t\t\tif (!active.length) {\n\t\t\t\tkey(a, value(a), 'hold');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst first = active[0];\n\t\t\tconst curve = exact && active.every((s) => s.start === a && s.end === b && JSON.stringify(curveOf(s)) === JSON.stringify(curveOf(first))) ? curveOf(first) : undefined;\n\t\t\tif (curve) {\n\t\t\t\tkey(a, value(a), curve);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst count = Math.max(1, Math.ceil(((b - a) * fps) / 1000));\n\t\t\tfor (let k = 0; k < count; k++) {\n\t\t\t\tconst t = a + ((b - a) * k) / count;\n\t\t\t\tkey(t, value(t), 'linear');\n\t\t\t\tsampled++;\n\t\t\t}\n\t\t}\n\t\t// Changes that cut (no length) land on their frame.\n\t\tfor (const s of segments) if (s.end <= s.start) key(s.start, value(s.start), 'hold');\n\t\tkeys.sort((x, y) => x.t - y.t);\n\t\tkey(end, value(end), 'hold');\n\t\tconst last = keys[keys.length - 1];\n\t\tdelete last.o;\n\t\tdelete last.i;\n\t\tdelete last.h;\n\t\treturn { a: 1, k: keys };\n\t};\n\n\t/** The node's offset as Lottie transform parts at `t` (anchor at its centre). */\n\tconst poseAt = (entry: MotionNodeEntry, t: number) => {\n\t\tconst o = motionNodeOffset(entry, timeline, t, nodes);\n\t\tif (!o) return { p: [entry.center.x, entry.center.y], s: [100, 100], r: 0 };\n\t\tconst m = o.matrix;\n\t\tconst sx = Math.hypot(m[0], m[1]);\n\t\tconst sy = sx > 1e-12 ? (m[0] * m[3] - m[1] * m[2]) / sx : 0;\n\t\tconst c = entry.center;\n\t\treturn { p: [m[0] * c.x + m[2] * c.y + m[4], m[1] * c.x + m[3] * c.y + m[5]], s: [sx * 100, sy * 100], r: (Math.atan2(m[1], m[0]) * 180) / Math.PI };\n\t};\n\n\t/** The outer group's transform: the node's animated pose and opacity. */\n\tconst poseTransform = (entry: MotionNodeEntry): LottieShape => {\n\t\tconst id = entry.node.id;\n\t\tconst tr = STATIC_TR();\n\t\tconst c = [entry.center.x, entry.center.y].map(round);\n\t\tconst own = (p: MotionProperty) => track(id, p);\n\t\t// Drivers' sources count as layers: the driven pose is sampled wherever they change.\n\t\tconst sources = motionDriverSources(timeline, id, ['x', 'y', 'rotation', 'scaleX', 'scaleY']);\n\t\tconst layered = (['x', 'y', 'rotation', 'scaleX', 'scaleY'] as MotionProperty[]).some((p) => layers(id, p).length) || sources.length > 0;\n\t\tconst moving = (['x', 'y', 'rotation', 'scaleX', 'scaleY', 'follow'] as MotionProperty[]).some((p) => own(p).length) || layered;\n\t\tif (moving) {\n\t\t\t// Position, rotation and scale are separate in Lottie, so each is exact on its own; follows and layers mix them and are sampled.\n\t\t\tconst mixed = own('follow').length > 0 || layered;\n\t\t\ttr.a = { a: 0, k: c };\n\t\t\ttr.p = animate(mixed ? [...own('x'), ...own('y'), ...own('follow'), ...layers(id, 'x'), ...layers(id, 'y'), ...sources] : [...own('x'), ...own('y')], (t) => poseAt(entry, t).p, !mixed);\n\t\t\ttr.r = animate(mixed ? [...own('rotation'), ...own('follow'), ...layers(id, 'rotation'), ...sources] : own('rotation'), (t) => [poseAt(entry, t).r], !mixed);\n\t\t\ttr.s = animate(mixed ? [...own('scaleX'), ...own('scaleY'), ...layers(id, 'scaleX'), ...layers(id, 'scaleY'), ...sources] : [...own('scaleX'), ...own('scaleY')], (t) => poseAt(entry, t).s, !mixed);\n\t\t\t// Lottie needs the position where the anchor is when nothing moves it.\n\t\t\tif ((tr.p as LottieValue).a === 0) tr.p = { a: 0, k: poseAt(entry, 0).p.map(round) };\n\t\t}\n\t\tconst opacitySources = motionDriverSources(timeline, id, ['opacity']);\n\t\tif (opacitySources.length) {\n\t\t\ttr.o = animate([...own('opacity'), ...opacitySources], (t) => [motionPropertyValue(timeline, id, 'opacity', t) * 100], false);\n\t\t\treturn tr;\n\t\t}\n\t\tconst opacity = own('opacity');\n\t\tconst rest = entry.node.opacity ?? 1;\n\t\ttr.o = opacity.length ? animate(opacity, (t) => [Math.min(1, Math.max(0, Number(trackValue(opacity, t) ?? rest))) * 100]) : { a: 0, k: round(rest * 100) };\n\t\treturn tr;\n\t};\n\n\t/** The outermost of a path and its groups whose track sets `p` (a group's paint goes to each path in it). */\n\tconst owner = (path: VectorPathNode, p: MotionProperty): string | undefined => {\n\t\tconst entry = nodes.get(path.id);\n\t\tif (!entry) return undefined;\n\t\treturn [...entry.ancestors, path.id].find((id) => timeline.tracks.has(motionTrackKey(id, p)));\n\t};\n\n\tconst paintOf = (paint: VectorPaint | undefined, what: string, id: string): Vec | null => {\n\t\tif (paint === undefined || paint === null || paint === 'none') return null;\n\t\tconst c = rgba(paint);\n\t\tif (!c) notes.push(`\"${id}\": its ${what} is a gradient, which is not exported; it is left unpainted.`);\n\t\treturn c;\n\t};\n\n\tconst pathShapes = (path: VectorPathNode): LottieShape[] => {\n\t\tconst items: LottieShape[] = [];\n\t\tconst shapeSegments = [...timeline.tracks.entries()].filter(([k]) => k.startsWith(`${path.id}\\u0000`) && (k.endsWith('\\u0000shape') || k.includes('\\u0000effect:'))).flatMap(([, v]) => v);\n\t\tconst geometryAt = (t: number): BezierPath => {\n\t\t\tif (!shapeSegments.length) return vectorPathWorldBezier(path);\n\t\t\tconst now = indexMotionNodes(motionFrameAt(scene, t, { draw: false, offsets: false }).document.nodes).get(path.id)?.node;\n\t\t\treturn now && now.type === 'path' ? vectorPathWorldBezier(expandVectorAppearances([now])[0] as VectorPathNode) : vectorPathWorldBezier(path);\n\t\t};\n\t\tconst rest = lottieContours(toBezierPath(geometryAt(0)), round);\n\t\trest.forEach((contour, n) => {\n\t\t\tlet ks: LottieValue | { a: 0; k: unknown } = { a: 0, k: contour };\n\t\t\tif (shapeSegments.length) {\n\t\t\t\t// Lottie tweens shapes vertex by vertex: only a morph that keeps every contour's vertex count can be keyed.\n\t\t\t\tconst keys: LottieKeyframe[] = [];\n\t\t\t\tlet fits = true;\n\t\t\t\tconst count = Math.max(1, Math.ceil((end * fps) / 1000));\n\t\t\t\tfor (let k = 0; k <= count && fits; k++) {\n\t\t\t\t\tconst t = (end * k) / count;\n\t\t\t\t\tconst c = lottieContours(toBezierPath(geometryAt(t)), round)[n];\n\t\t\t\t\tif (!c || c.v.length !== contour.v.length || c.c !== contour.c) fits = false;\n\t\t\t\t\telse keys.push({ t: frame(t), s: [c as unknown as number], ...(k < count ? { o: { x: [0], y: [0] }, i: { x: [1], y: [1] } } : {}) } as LottieKeyframe);\n\t\t\t\t}\n\t\t\t\tif (fits) {\n\t\t\t\t\tks = { a: 1, k: keys };\n\t\t\t\t\tsampled += keys.length;\n\t\t\t\t} else notes.push(`\"${path.id}\": its morph changes how many points the outline has, which Lottie cannot tween; it shows its starting shape.`);\n\t\t\t}\n\t\t\titems.push({ ty: 'sh', nm: `${path.id} ${n + 1}`, ks });\n\t\t});\n\t\tconst fillFrom = owner(path, 'fill');\n\t\tconst strokeFrom = owner(path, 'stroke');\n\t\tconst widthFrom = owner(path, 'strokeWidth');\n\t\tconst fadeFrom = owner(path, 'fillOpacity');\n\t\tconst drawFrom = owner(path, 'drawEnd');\n\t\tconst tailFrom = owner(path, 'drawStart');\n\t\tif (drawFrom || tailFrom) {\n\t\t\t// Trim paths: the end draws on; the start follows it for a travelling stroke (draw with comet).\n\t\t\tconst pct = (track: readonly MotionSegment[], fallback: number) => (t: number) => [Math.min(1, Math.max(0, Number(trackValue(track, t) ?? fallback))) * 100];\n\t\t\tconst head = drawFrom ? track(drawFrom, 'drawEnd') : [];\n\t\t\tconst tail = tailFrom ? track(tailFrom, 'drawStart') : [];\n\t\t\titems.push({ ty: 'tm', nm: 'Draw on', s: tail.length ? animate(tail, pct(tail, 0)) : { a: 0, k: 0 }, e: head.length ? animate(head, pct(head, 1)) : { a: 0, k: 100 }, o: { a: 0, k: 0 }, m: 1 });\n\t\t}\n\n\t\tconst stroke = paintOf(path.stroke, 'stroke', path.id);\n\t\tif (stroke || strokeFrom) {\n\t\t\tconst colour = strokeFrom ? track(strokeFrom, 'stroke') : [];\n\t\t\titems.push({\n\t\t\t\tty: 'st',\n\t\t\t\tnm: 'Stroke',\n\t\t\t\tc: colour.length ? animate(colour, (t) => rgba(trackValue(colour, t)) ?? stroke ?? [0, 0, 0, 1]) : { a: 0, k: (stroke ?? [0, 0, 0, 1]).map(round) },\n\t\t\t\to: { a: 0, k: 100 },\n\t\t\t\tw: widthFrom ? animate(track(widthFrom, 'strokeWidth'), (t) => [Math.max(0, Number(trackValue(track(widthFrom, 'strokeWidth'), t) ?? path.strokeWidth ?? 1))]) : { a: 0, k: round(path.strokeWidth ?? 1) },\n\t\t\t\tlc: path.strokeLinecap === 'round' ? 2 : path.strokeLinecap === 'square' ? 3 : 1,\n\t\t\t\tlj: path.strokeLinejoin === 'round' ? 2 : path.strokeLinejoin === 'bevel' ? 3 : 1,\n\t\t\t\tml: 4\n\t\t\t});\n\t\t\tif (path.strokeDasharray?.length) notes.push(`\"${path.id}\": its dashes are not exported; the stroke is solid.`);\n\t\t\tif (path.strokeAlign && path.strokeAlign !== 'center') notes.push(`\"${path.id}\": its stroke is drawn centred (Lottie has no inside or outside strokes).`);\n\t\t}\n\t\tconst fill = paintOf(path.fill, 'fill', path.id);\n\t\tif (fill || fillFrom) {\n\t\t\tconst colour = fillFrom ? track(fillFrom, 'fill') : [];\n\t\t\tconst fade = fadeFrom ? track(fadeFrom, 'fillOpacity') : [];\n\t\t\titems.push({\n\t\t\t\tty: 'fl',\n\t\t\t\tnm: 'Fill',\n\t\t\t\tc: colour.length ? animate(colour, (t) => rgba(trackValue(colour, t)) ?? fill ?? [0, 0, 0, 1]) : { a: 0, k: (fill ?? [0, 0, 0, 1]).map(round) },\n\t\t\t\to: fade.length ? animate(fade, (t) => [Math.min(1, Math.max(0, Number(trackValue(fade, t) ?? 1))) * 100]) : { a: 0, k: 100 },\n\t\t\t\tr: path.fillRule === 'evenodd' ? 2 : 1\n\t\t\t});\n\t\t}\n\t\treturn items;\n\t};\n\n\t// Hidden nodes are never drawn (the stage gives them display=\"none\"), so they are left out. Marking\n\t// their group `hd: true` is not enough: lottie-web honours `hd` on paths, fills and strokes but not on\n\t// groups. Follow routes and morph targets are sampled into keyframes, so nothing in the file needs them.\n\tconst shown = (list: readonly VectorNode[]) => list.filter((n) => n.visible !== false);\n\n\tconst nodeGroup = (node: VectorNode): LottieShape => {\n\t\tconst entry = nodes.get(node.id)!;\n\t\tif (timeline.tracks.has(motionTrackKey(node.id, 'clipRect')) || timeline.tracks.has(motionTrackKey(node.id, 'clipCircle')))\n\t\t\tnotes.push(`\"${node.id}\": its wipe, iris or split reveal is not exported (Lottie masks belong to layers); it fades with its opacity only.`);\n\t\tlet inner: LottieShape[];\n\t\tconst innerTr = STATIC_TR();\n\t\tif (node.type === 'path') inner = [...pathShapes(node)];\n\t\telse {\n\t\t\t// Later children draw on top: Lottie lists the top item first.\n\t\t\tinner = shown(node.children).reverse().map(nodeGroup);\n\t\t\tconst m = nodeMatrix(node);\n\t\t\tif (m !== IDENTITY_MATRIX) {\n\t\t\t\tconst parts = staticParts(m);\n\t\t\t\tif (!parts) notes.push(`\"${node.id}\": its transform skews, which is not exported; it is drawn without the skew.`);\n\t\t\t\telse {\n\t\t\t\t\tinnerTr.p = { a: 0, k: parts.p.map(round) };\n\t\t\t\t\tinnerTr.s = { a: 0, k: parts.s.map(round) };\n\t\t\t\t\tinnerTr.r = { a: 0, k: round(parts.r) };\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst body: LottieShape = { ty: 'gr', nm: `${node.id} (own)`, it: [...inner, innerTr] };\n\t\treturn { ty: 'gr', nm: node.name ?? node.id, it: [body, poseTransform(entry)] };\n\t};\n\n\tconst artwork = { ...scene.artwork, nodes: expandVectorAppearances(scene.artwork.nodes) };\n\tconst content = shown(artwork.nodes).reverse().map(nodeGroup);\n\tif (artwork.background && rgba(artwork.background))\n\t\tcontent.push({ ty: 'gr', nm: 'Background', it: [{ ty: 'rc', nm: 'Background', p: { a: 0, k: [artwork.width / 2, artwork.height / 2] }, s: { a: 0, k: [artwork.width, artwork.height] }, r: { a: 0, k: 0 } }, { ty: 'fl', c: { a: 0, k: rgba(artwork.background)!.map(round) }, o: { a: 0, k: 100 }, r: 1 }, STATIC_TR()] });\n\n\t// The camera: a root transform that maps its box onto the canvas.\n\tconst camera = track('', 'camera');\n\tconst root = STATIC_TR();\n\tif (camera.length) {\n\t\tconst box = (t: number) => (trackValue(camera, t) as number[] | undefined) ?? [0, 0, artwork.width, artwork.height];\n\t\troot.a = animate(camera, (t) => box(t).slice(0, 2), false);\n\t\troot.s = animate(camera, (t) => [(artwork.width / box(t)[2]) * 100, (artwork.height / box(t)[3]) * 100], false);\n\t}\n\n\tconst op = Math.max(1, Math.ceil((end * fps) / 1000));\n\tconst lottie: LottieAnimation = {\n\t\tv: '5.7.4',\n\t\tfr: fps,\n\t\tip: 0,\n\t\top,\n\t\tw: artwork.width,\n\t\th: artwork.height,\n\t\tnm: scene.name,\n\t\tddd: 0,\n\t\tassets: [],\n\t\tlayers: [\n\t\t\t{\n\t\t\t\tddd: 0,\n\t\t\t\tind: 1,\n\t\t\t\tty: 4,\n\t\t\t\tnm: scene.name,\n\t\t\t\tsr: 1,\n\t\t\t\tks: { o: { a: 0, k: 100 }, r: { a: 0, k: 0 }, p: { a: 0, k: [0, 0, 0] }, a: { a: 0, k: [0, 0, 0] }, s: { a: 0, k: [100, 100, 100] } },\n\t\t\t\tao: 0,\n\t\t\t\tshapes: [{ ty: 'gr', nm: 'Camera', it: [...content, root] }],\n\t\t\t\tip: 0,\n\t\t\t\top,\n\t\t\t\tst: 0,\n\t\t\t\tbm: 0\n\t\t\t}\n\t\t],\n\t\tmarkers: timeline.shots.map((s) => ({ tm: frame(s.start), cm: s.label ?? s.id, dr: frame(s.end - s.start) }))\n\t};\n\treturn { lottie, sampled, notes: [...new Set(notes)] };\n}\n","import { motionStageSvg, type MotionOverlayOptions } from './onion.js';\nimport type { Clock } from '../animation/clock.js';\nimport type { AnimationLoopMode } from '../animation/evaluate.js';\nimport { AnimationPlayer } from '../animation/player.js';\nimport { HistoryManager } from '../history/HistoryManager.js';\nimport type { Command } from '../history/types.js';\nimport type { VectorDocument } from '../vector/types.js';\nimport { checkMotionScene } from './check.js';\nimport { compileMotionScene, motionShotAt, type MotionShotTiming } from './compile.js';\nimport { applyMotionEdits, createMotionScene, type MotionEdit, type MotionEditResult } from './edit.js';\nimport { motionFrameAt, motionFrameToSvg, type MotionFrame, type MotionFrameOptions, type MotionSvgOptions } from './evaluate.js';\nimport { toFlairEffectDocument, toFlairSvgMotion, toFlairVectorEffect, type FlairEffectOptions, type FlairExportOptions } from './flair.js';\nimport type { MotionIssue } from './issues.js';\nimport { parseMotionScene } from './parse.js';\nimport type { MotionScene } from './types.js';\n\nexport interface AnimationEditorOptions {\n\t/** The scene to open (default: an empty one over a blank 800 × 450 artwork). */\n\tscene?: MotionScene;\n\t/** Shared undo history (default: a new one). */\n\thistory?: HistoryManager;\n\t/** Time source for playback (default: requestAnimationFrame). Pass a `ManualClock` to step frames. */\n\tclock?: Clock;\n\treadOnly?: boolean;\n\t/** Called after every change to the scene (not on playback or selection). */\n\tonChange?: (scene: MotionScene) => void;\n}\n\n/** What is selected on the timeline: a shot, and optionally one of its commands. */\nexport interface AnimationEditorSelection {\n\tshot: string;\n\tcommand?: number;\n}\n\n/** A snapshot of the editor. The same object is returned until something changes. */\nexport interface AnimationEditorState {\n\tscene: MotionScene;\n\t/** Total length (ms). */\n\tduration: number;\n\t/** Each shot's timing. */\n\tshots: readonly MotionShotTiming[];\n\t/** The scene's problems (see `checkMotionScene`). */\n\tissues: readonly MotionIssue[];\n\t/** Playhead (ms). */\n\ttime: number;\n\tplaying: boolean;\n\tloop: AnimationLoopMode;\n\t/** Id of the shot under the playhead. */\n\tcurrentShot: string | null;\n\tselection: AnimationEditorSelection | null;\n\treadOnly: boolean;\n\t/** Why the last edit was refused, if it was. */\n\terror: string | null;\n\tcanUndo: boolean;\n\tcanRedo: boolean;\n\tundoLabel: string;\n\tredoLabel: string;\n\t/** Bumped on every change. */\n\trevision: number;\n}\n\nconst BLANK: VectorDocument = { width: 800, height: 450, background: '#ffffff', nodes: [] };\n\n/**\n * Headless editor for a vector animation (a `MotionScene`): undoable, all-or-nothing edits,\n * playback on an injectable clock, a timeline selection and frames at any time. UI-agnostic:\n * React and Svelte bind it with `useAnimationEditor` / `createAnimationEditor`, and agents\n * drive it through `createAnimationEditorToolProvider`. `getState()` returns the same object\n * until something changes, so it works with `useSyncExternalStore` and Svelte runes.\n */\nexport class AnimationEditorController {\n\treadonly history: HistoryManager;\n\treadonly player: AnimationPlayer;\n\tprivate scene: MotionScene;\n\tprivate issues: MotionIssue[];\n\tprivate selection: AnimationEditorSelection | null = null;\n\tprivate readOnly: boolean;\n\tprivate error: string | null = null;\n\tprivate revision = 0;\n\tprivate applying = false;\n\tprivate readonly onChange?: (scene: MotionScene) => void;\n\tprivate readonly listeners = new Set<(state: AnimationEditorState) => void>();\n\tprivate readonly unsubscribers: (() => void)[] = [];\n\tprivate state!: AnimationEditorState;\n\n\tconstructor(options: AnimationEditorOptions = {}) {\n\t\tthis.history = options.history ?? new HistoryManager();\n\t\tthis.scene = options.scene ? parseMotionScene(options.scene) : createMotionScene(BLANK);\n\t\tthis.issues = checkMotionScene(this.scene);\n\t\tthis.readOnly = options.readOnly ?? false;\n\t\tthis.onChange = options.onChange;\n\t\tthis.player = new AnimationPlayer({ clock: options.clock, duration: () => compileMotionScene(this.scene).duration, loop: this.scene.loop ?? 'none' });\n\t\tthis.state = this.computeState();\n\t\tthis.connect();\n\t}\n\n\tprivate connect() {\n\t\tif (this.unsubscribers.length) return;\n\t\tthis.unsubscribers.push(\n\t\t\tthis.player.subscribe(() => this.notify()),\n\t\t\tthis.history.subscribe(() => {\n\t\t\t\tif (!this.applying) this.notify();\n\t\t\t})\n\t\t);\n\t}\n\n\t/**\n\t * Pauses and stops listening to the player and history. Subscribing again reconnects, so a\n\t * controller survives React StrictMode's unmount / remount.\n\t */\n\tdestroy(): void {\n\t\tthis.player.pause();\n\t\tthis.unsubscribers.splice(0).forEach((u) => u());\n\t}\n\n\tgetState = (): AnimationEditorState => this.state;\n\n\tsubscribe = (listener: (state: AnimationEditorState) => void): (() => void) => {\n\t\tthis.connect();\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t};\n\n\t/** The current scene (immutable; edit through the controller). */\n\tgetScene(): MotionScene {\n\t\treturn this.scene;\n\t}\n\n\tprivate computeState(): AnimationEditorState {\n\t\tconst timeline = compileMotionScene(this.scene);\n\t\tconst p = this.player.getState();\n\t\tconst h = this.history.getState();\n\t\treturn {\n\t\t\tscene: this.scene,\n\t\t\tduration: timeline.duration,\n\t\t\tshots: timeline.shots,\n\t\t\tissues: this.issues,\n\t\t\ttime: p.time,\n\t\t\tplaying: p.playing,\n\t\t\tloop: p.loop,\n\t\t\tcurrentShot: motionShotAt(timeline, p.time)?.id ?? null,\n\t\t\tselection: this.selection,\n\t\t\treadOnly: this.readOnly,\n\t\t\terror: this.error,\n\t\t\tcanUndo: h.canUndo,\n\t\t\tcanRedo: h.canRedo,\n\t\t\tundoLabel: h.undoName,\n\t\t\tredoLabel: h.redoName,\n\t\t\trevision: this.revision\n\t\t};\n\t}\n\n\tprivate notify() {\n\t\tthis.revision++;\n\t\tthis.state = this.computeState();\n\t\tconst state = this.state;\n\t\tthis.listeners.forEach((listener) => {\n\t\t\ttry {\n\t\t\t\tlistener(state);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error('[AnimationEditorController] Error in state listener:', error);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate setScene(scene: MotionScene) {\n\t\tthis.applying = true;\n\t\ttry {\n\t\t\tthis.scene = scene;\n\t\t\tthis.issues = checkMotionScene(scene);\n\t\t\tif (this.selection) {\n\t\t\t\tconst shot = scene.shots.find((s) => s.id === this.selection!.shot);\n\t\t\t\tif (!shot) this.selection = null;\n\t\t\t\telse if (this.selection.command !== undefined && this.selection.command >= shot.run.length) this.selection = { shot: shot.id };\n\t\t\t}\n\t\t\tthis.player.setLoop(scene.loop ?? 'none');\n\t\t\tthis.player.setDuration(() => compileMotionScene(this.scene).duration);\n\t\t} finally {\n\t\t\tthis.applying = false;\n\t\t}\n\t\tthis.notify();\n\t\tthis.onChange?.(scene);\n\t}\n\n\tprivate commit(label: string, next: MotionScene) {\n\t\tconst before = this.scene;\n\t\tthis.error = null;\n\t\tif (next === before) {\n\t\t\tthis.notify();\n\t\t\treturn;\n\t\t}\n\t\tconst command: Command = {\n\t\t\tname: label,\n\t\t\ttag: 'animation-editor',\n\t\t\texecute: () => this.setScene(next),\n\t\t\tundo: () => this.setScene(before),\n\t\t\tredo: () => this.setScene(next)\n\t\t};\n\t\tthis.history.execute(command);\n\t}\n\n\tprivate refuse(message: string): MotionEditResult {\n\t\tthis.error = message;\n\t\tthis.notify();\n\t\treturn { ok: false, error: message };\n\t}\n\n\t/** Why edits are refused now, or `null` when they are allowed. */\n\treadOnlyReason(): string | null {\n\t\treturn this.readOnly ? 'The animation is read-only.' : null;\n\t}\n\n\t/**\n\t * Applies edits as one undo step, all or nothing (see `applyMotionEdits`). With\n\t * `dryRun` it reports what would happen and changes nothing.\n\t */\n\tapply(edits: MotionEdit | readonly MotionEdit[], label = 'Edit animation', options: { dryRun?: boolean } = {}): MotionEditResult {\n\t\tconst reason = this.readOnlyReason();\n\t\tif (reason) return this.refuse(reason);\n\t\tconst result = applyMotionEdits(this.scene, edits);\n\t\tif (!result.ok) return options.dryRun ? result : this.refuse(result.error);\n\t\tif (!options.dryRun) this.commit(label, result.scene);\n\t\treturn result;\n\t}\n\n\t/** Replaces the artwork (e.g. from a vector editor's `onChange`), as one undo step. */\n\tsetArtwork(artwork: VectorDocument, label = 'Change artwork'): MotionEditResult {\n\t\treturn this.apply({ op: 'set_artwork', artwork }, label);\n\t}\n\n\t/** Opens a scene (JSON or object). `clearHistory` drops the undo stack (opening a file); otherwise it is one undo step. */\n\tload(scene: MotionScene | string, options: { clearHistory?: boolean } = {}): MotionEditResult {\n\t\tlet parsed: MotionScene;\n\t\ttry {\n\t\t\tparsed = parseMotionScene(scene);\n\t\t} catch (error) {\n\t\t\treturn this.refuse((error as Error).message);\n\t\t}\n\t\tif (options.clearHistory) {\n\t\t\tthis.history.clear();\n\t\t\tthis.error = null;\n\t\t\tthis.selection = null;\n\t\t\tthis.setScene(parsed);\n\t\t\tthis.player.seek(0);\n\t\t\treturn { ok: true, scene: parsed, issues: this.issues, hints: [] };\n\t\t}\n\t\treturn this.apply({ op: 'replace_scene', scene: parsed }, 'Replace animation');\n\t}\n\n\tsetReadOnly(readOnly: boolean): void {\n\t\tif (this.readOnly === readOnly) return;\n\t\tthis.readOnly = readOnly;\n\t\tthis.notify();\n\t}\n\n\t/** Selects a shot (and optionally a command in it); `null` clears. Unknown shots clear. */\n\tselect(selection: AnimationEditorSelection | null): void {\n\t\tconst shot = selection && this.scene.shots.find((s) => s.id === selection.shot);\n\t\tconst next = shot ? { shot: shot.id, ...(selection!.command !== undefined && selection!.command < shot.run.length ? { command: selection!.command } : {}) } : null;\n\t\tif (JSON.stringify(next) === JSON.stringify(this.selection)) return;\n\t\tthis.selection = next;\n\t\tthis.notify();\n\t}\n\n\tplay(): void {\n\t\tthis.player.play();\n\t}\n\n\tpause(): void {\n\t\tthis.player.pause();\n\t}\n\n\ttoggle(): void {\n\t\tthis.player.toggle();\n\t}\n\n\t/** Moves the playhead (ms). */\n\tseek(time: number): void {\n\t\tthis.player.seek(time);\n\t}\n\n\t/** Moves the playhead to the start or end of a shot. Returns false for an unknown shot. */\n\tseekShot(id: string, at: 'start' | 'end' = 'start'): boolean {\n\t\tconst shot = compileMotionScene(this.scene).shots.find((s) => s.id === id);\n\t\tif (!shot) return false;\n\t\tthis.player.seek(at === 'start' ? shot.start : shot.end);\n\t\treturn true;\n\t}\n\n\tundo(): boolean {\n\t\treturn this.history.undo();\n\t}\n\n\tredo(): boolean {\n\t\treturn this.history.redo();\n\t}\n\n\t/** The scene at `time` (default: the playhead). */\n\tframe(time = this.player.currentTime, options: MotionFrameOptions = {}): MotionFrame {\n\t\treturn motionFrameAt(this.scene, time, options);\n\t}\n\n\t/** The scene at `time` (default: the playhead) as SVG. */\n\ttoSvg(time = this.player.currentTime, options: MotionSvgOptions & MotionOverlayOptions = {}): string {\n\t\treturn motionStageSvg(this.scene, time, options);\n\t}\n\n\t/** The scene as a Flair `SvgMotion`. */\n\ttoFlairMotion(options: FlairExportOptions = {}) {\n\t\treturn toFlairSvgMotion(this.scene, options);\n\t}\n\n\t/** The scene as a Flair catalog vector effect. */\n\ttoFlairEffect(options: FlairEffectOptions = {}) {\n\t\treturn toFlairVectorEffect(this.scene, options);\n\t}\n\n\t/** The scene as a Flair `EffectDocument`. */\n\ttoFlairDocument(options: FlairExportOptions = {}) {\n\t\treturn toFlairEffectDocument(this.scene, options);\n\t}\n}\n","import { ANIMATION_EASING_PRESETS } from '../animation/easing.js';\nimport type { AgentTool, AgentToolProvider } from '../tools/registry.js';\nimport type { JsonSchema } from '../tools/schema.js';\nimport { parseVectorSvg } from '../vector/svg.js';\nimport type { VectorNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionClipLayout, motionBeatAt, motionBeatTime } from './compile.js';\nimport { fitMotionScene } from './fit.js';\nimport { toLottie } from './lottie.js';\nimport { motionContactSheetSvg, motionPath } from './onion.js';\nimport { fromFlairSvgMotion, fromFlairVectorEffect, type FlairImportResult } from './flair-import.js';\nimport type { AnimationEditorController } from './controller.js';\nimport { MOTION_EDIT_OPS, resolveMotionEditRefs, type MotionEdit, type MotionEditResult } from './edit.js';\nimport { motionIssueLine, namedWithSuggestion, type MotionIssue } from './issues.js';\nimport { MOTION_COMMAND_TYPES, MOTION_DIRECTIONS, MOTION_ENTER_STYLES, MOTION_EXIT_STYLES, MOTION_IRIS_SHAPES, MOTION_REPEAT_MODES, MOTION_BLENDS, MOTION_SPLIT_ORIENTATIONS, motionFlairPrimitive, type MotionCommand, type MotionScene } from './types.js';\n\nexport interface AnimationEditorToolProviderOptions {\n\t/** Provider id (unique per registry). Default `animation`. */\n\tid?: string;\n\t/** Always prefix tool names with `<namespace>__`. */\n\tnamespace?: string;\n\t/** The animation cannot be edited: write tools are hidden and `get_animation` says why. A string is the reason. */\n\treadOnly?: boolean | string | (() => boolean | string);\n\t/** Turns SVG into PNG (e.g. `rasterizeSvg`), so `render_animation_frame` can return an image. */\n\trasterize?: (svg: string, size: { width: number; height: number }) => Promise<{ data: string; mimeType: string }> | { data: string; mimeType: string };\n}\n\nconst READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\nconst WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false } as const;\nconst WRITE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } as const;\nconst DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false } as const;\n\nconst object = (properties: Record<string, JsonSchema>, required: string[] = [], description?: string): JsonSchema & { type: 'object' } => ({\n\ttype: 'object' as const,\n\t...(description ? { description } : {}),\n\tproperties,\n\t...(required.length ? { required } : {}),\n\tadditionalProperties: false\n});\n\nconst SHOT_ID = { type: 'string', minLength: 1, description: 'A shot id from get_animation (e.g. \"intro\").' } as const;\nconst NODE_IDS = { type: 'array', items: { type: 'string', minLength: 1 }, minItems: 1, description: 'Node ids from get_animation\\'s \"elements\" (a group animates as one).' } as const;\nconst MS = (what: string) => ({ type: 'number', minimum: 0, description: `${what} in milliseconds.` }) as const;\nconst FRACTION = (what: string) => ({ type: 'number', minimum: 0, maximum: 1, description: what }) as const;\nconst POINT = (what: string) => object({ x: { type: 'number', description: 'Document units.' }, y: { type: 'number', description: 'Document units.' } }, ['x', 'y'], what);\nconst EASE: JsonSchema = {\n\tdescription: `Easing: a preset (${ANIMATION_EASING_PRESETS.join(', ')}), { \"type\": \"cubic-bezier\", \"x1\", \"y1\", \"x2\", \"y2\" }, { \"type\": \"spring\", … } or { \"type\": \"elastic\", … }. The spring presets are Figma's: gentle, quick, bouncy, slow. A command with a spring and no \"duration\" lasts until the spring settles. Default: a cubic ease-out for entrances, cubic ease-in-out for moves.`,\n\tanyOf: [\n\t\t{ type: 'string', enum: [...ANIMATION_EASING_PRESETS] },\n\t\tobject({ type: { const: 'cubic-bezier', description: 'Curve kind.' }, x1: { type: 'number', description: 'Out handle x (0–1).' }, y1: { type: 'number', description: 'Out handle y.' }, x2: { type: 'number', description: 'In handle x (0–1).' }, y2: { type: 'number', description: 'In handle y.' } }, ['type', 'x1', 'y1', 'x2', 'y2']),\n\t\tobject(\n\t\t\t{\n\t\t\t\ttype: { const: 'spring', description: 'A damped spring (may overshoot).' },\n\t\t\t\tstiffness: { type: 'number', exclusiveMinimum: 0, description: 'Stiffness (default 170; quick 300, bouncy 600).' },\n\t\t\t\tdamping: { type: 'number', minimum: 0, description: 'Damping (default 26; lower bounces more).' },\n\t\t\t\tmass: { type: 'number', exclusiveMinimum: 0, description: 'Mass (default 1).' },\n\t\t\t\tvelocity: { type: 'number', description: 'Starting speed, in changes per second (default 0).' }\n\t\t\t},\n\t\t\t['type']\n\t\t),\n\t\tobject(\n\t\t\t{\n\t\t\t\ttype: { const: 'elastic', description: 'A decaying wobble.' },\n\t\t\t\tamplitude: { type: 'number', minimum: 0, description: 'Overshoot factor (default 1).' },\n\t\t\t\tperiod: { type: 'number', exclusiveMinimum: 0, description: 'Wobble period as a fraction of the length (default 0.3).' },\n\t\t\t\tmode: { type: 'string', enum: ['out', 'in', 'in-out'], description: 'Where it wobbles (default out).' }\n\t\t\t},\n\t\t\t['type']\n\t\t)\n\t]\n};\n\nconst BASE: Record<string, JsonSchema> = {\n\ttargets: NODE_IDS,\n\tduration: MS('Length for each target (each type has a default; draw follows the path length)'),\n\tdelay: MS('Wait before starting (default 0)'),\n\tstagger: MS('Start each further target this much later (default 0)'),\n\twith: { type: 'string', enum: ['after', 'previous'], description: '\"after\" (default) starts when the commands before it finish; \"previous\" starts together with the command before.' },\n\tease: EASE,\n\tnote: { type: 'string', description: 'Why this command is here, in a few words.' },\n\trepeat: { type: 'integer', minimum: 1, maximum: 1000, description: 'Play it this many times (default 1); \"duration\" is one cycle. Not for enter or exit.' },\n\trepeatMode: { type: 'string', enum: [...MOTION_REPEAT_MODES], description: 'loop (default) restarts each cycle, mirror plays every other one backwards, offset carries on from where the last ended (rotate by 90 with repeat 4 makes a full turn).' },\n\tsteps: { type: 'number', exclusiveMinimum: 0, maximum: 120, description: 'Stepped time: hold on a grid of this many frames per second (12 = \"on twos\"). Default: the scene\\'s steps, else smooth.' }\n};\nconst BLEND = (fallback: 'replace' | 'add'): JsonSchema => ({\n\ttype: 'string',\n\tenum: [...MOTION_BLENDS],\n\tdescription: `\"add\" makes it a layer over the pose that stacks with other changes (a shake on a slide); \"replace\" makes it a change the next one takes over from (default ${fallback}).`\n});\nconst DRAW_ORDER: Record<string, JsonSchema> = {\n\torder: { type: 'string', enum: ['together', 'sequence'], description: 'For drawing a group or several paths: together (default) or sequence (one stroke after another, each for a time in proportion to its length).' },\n\tpace: { type: 'string', enum: ['time', 'speed'], description: 'With together: time (default, every stroke takes the whole time) or speed (all at one speed, so short strokes take less).' },\n\talign: { type: 'string', enum: ['start', 'end'], description: 'With pace speed: start them together (default) or finish them together.' },\n\tsortBy: { type: 'string', enum: ['document', 'distance'], description: 'With sequence: stacking order (default) or distance from origin (a radial reveal).' },\n\torigin: object({ x: { type: 'number', description: 'Document units.' }, y: { type: 'number', description: 'Document units.' } }, ['x', 'y'], 'With sortBy distance: where strokes are drawn out from (default the target\\'s centre).')\n};\nconst command = (type: string, description: string, extra: Record<string, JsonSchema> = {}, required: string[] = []): JsonSchema =>\n\tobject({ type: { const: type, description }, ...BASE, ...extra }, ['type', 'targets', ...required], description);\n\n/** JSON Schema of one command (each type its own strict branch). */\nexport const MOTION_COMMAND_SCHEMA: JsonSchema = {\n\tdescription: `A command (one of ${MOTION_COMMAND_TYPES.join(', ')}). Commands in a shot play one after another unless \"with\": \"previous\".`,\n\toneOf: [\n\t\tcommand('enter', 'Brings hidden targets in; they are hidden before this shot.', { ...DRAW_ORDER,\n\t\t\tstyle: {\n\t\t\t\ttype: 'string',\n\t\t\t\tenum: [...MOTION_ENTER_STYLES],\n\t\t\t\tdescription:\n\t\t\t\t\t'fade (default), pop (scales up past full size and settles), grow (from nothing), slide, draw (outline drawn on, then the fill fades in), zoom (settles from larger), rise (rises a short way, overshooting a touch), or a reveal through a clip over the target\\'s box: wipe (behind a travelling edge), iris (from the centre outwards) or split (from a line through the middle). Reveals need a box with a width and a height (not a lone straight line).'\n\t\t\t},\n\t\t\tdirection: { type: 'string', enum: [...MOTION_DIRECTIONS], description: 'For slide: direction of travel (default up). For wipe: the way the edge travels (default right, revealing from the left).' },\n\t\t\tdistance: { type: 'number', description: 'For slide (default 40) and rise (default 20): document units.' },\n\t\t\tscale: { type: 'number', minimum: 0, description: 'For pop (default 0.5) and zoom (default 1.6): the starting scale (1 = rest size).' },\n\t\t\tshape: { type: 'string', enum: [...MOTION_IRIS_SHAPES], description: 'For iris: open through a circle (default; an ellipse on a box that is not square) or a box.' },\n\t\t\torientation: { type: 'string', enum: [...MOTION_SPLIT_ORIENTATIONS], description: 'For split: horizontal (default) opens up and down from a horizontal line through the middle; vertical opens left and right.' }\n\t\t}),\n\t\tcommand('exit', 'Takes targets out.', { ...DRAW_ORDER,\n\t\t\tstyle: { type: 'string', enum: [...MOTION_EXIT_STYLES], description: 'fade (default), shrink, slide, undraw, or wipe (hides behind a travelling edge through a clip over the target\\'s box: a wipe in, reversed).' },\n\t\t\tdirection: { type: 'string', enum: [...MOTION_DIRECTIONS], description: 'For slide: direction of travel (default down). For wipe: the way the edge travels (default right, hiding from the left).' },\n\t\t\tdistance: { type: 'number', description: 'For slide: document units (default 40).' }\n\t\t}),\n\t\tcommand('draw', 'Draws strokes on (or off) to a fraction of their length.', { ...DRAW_ORDER, comet: FRACTION('A travelling stroke this fraction of the length long: it runs along the path and off the end (leave out from and to).'), to: FRACTION('Fraction drawn at the end (default 1).'), from: FRACTION('Fraction drawn at the start (default: what is drawn now).') }),\n\t\tcommand('move', 'Moves targets by an offset or so their centre lands on a point.', { via: { type: 'array', items: POINT('A point the centre passes through.'), minItems: 1, maxItems: 64, description: 'Waypoints (document units) the centre passes through on the way to \"to\" or \"by\", smoothly (velocity carries through each) and without overshooting any. Default length 700 ms + 400 per waypoint.' }, pacing: { type: 'string', enum: ['even', 'equal'], description: 'With via: even (default) keeps the speed steady along the path; equal gives each stretch the same time.' }, blend: BLEND('replace'), by: POINT('Offset in document units.'), to: POINT('Point (document coordinates) for the centre.') }),\n\t\tcommand('rotate', 'Turns targets about their centre (degrees, clockwise).', { blend: BLEND('replace'), by: { type: 'number', description: 'Degrees to turn by.' }, to: { type: 'number', description: 'Angle to turn to, in degrees from rest.' } }),\n\t\tcommand('scale', 'Scales targets about their centre (1 = rest size).', { blend: BLEND('replace'), to: { description: 'A factor, or { x, y } factors.', anyOf: [{ type: 'number' }, POINT('Factors per axis.')] }, geometric: { type: 'boolean', description: 'Grow by a steady factor, which reads as an even zoom (default false).' } }, ['to']),\n\t\tcommand('fade', 'Changes opacity.', { to: FRACTION('Opacity at the end (0–1).') }, ['to']),\n\t\tcommand('style', 'Blends solid fill / stroke colours (in OKLab) and stroke width. On a group it changes every path in it.', {\n\t\t\tfill: { type: 'string', description: 'CSS colour (hex, rgb(), rgba()).' },\n\t\t\tstroke: { type: 'string', description: 'CSS colour (hex, rgb(), rgba()).' },\n\t\t\tstrokeWidth: { type: 'number', minimum: 0, description: 'Document units.' }\n\t\t}),\n\t\tobject(\n\t\t\t{\n\t\t\t\ttype: { const: 'play', description: 'Plays a clip (set_animation_clip) on the targets: its commands, with \"$\" standing for each target, timed as in a shot.' },\n\t\t\t\ttargets: NODE_IDS,\n\t\t\t\tclip: { type: 'string', minLength: 1, description: 'The clip\\'s name (get_animation lists them).' },\n\t\t\t\tspeed: { type: 'number', minimum: 0.05, maximum: 20, description: 'Play it this many times as fast (default 1).' },\n\t\t\t\tdelay: BASE.delay,\n\t\t\t\tstagger: BASE.stagger,\n\t\t\t\twith: BASE.with,\n\t\t\t\tnote: BASE.note\n\t\t\t},\n\t\t\t['type', 'targets', 'clip'],\n\t\t\t'Plays a clip on the targets.'\n\t\t),\n\t\tcommand('match', 'Smart Animate: tweens a group into another group (usually hidden), part by part. Parts pair by name, then by id with the group ids taken out (card-a-title ↔ card-b-title), then by kind in order; each takes its partner\\'s shape, paint and place. Unpaired parts fade out; parts of \"into\" with no partner do not appear (check_animation lists them).', { into: { type: 'string', minLength: 1, description: 'Id of the group to become.' } }, ['into']),\n\t\tcommand('morph', 'Morphs each target into the shape (and paint) of another node, which usually stays hidden.', { into: { type: 'string', minLength: 1, description: 'Id of the node whose shape to take.' } }, ['into']),\n\t\tcommand('follow', 'Moves targets along a path node, centre on the path.', {\n\t\t\tpath: { type: 'string', minLength: 1, description: 'Id of a path node (it can be hidden).' },\n\t\t\trotate: { type: 'boolean', description: 'Turn with the path (default false); moves and shakes made meanwhile turn with it too.' },\n\t\t\tfrom: FRACTION('Where to start along the path (default 0).'),\n\t\t\tto: FRACTION('Where to end along the path (default 1).')\n\t\t}, ['path']),\n\t\tcommand('pulse', 'Scales up and back to draw the eye.', { blend: BLEND('add'), amount: { type: 'number', description: 'Extra scale at the peak (default 0.15).' }, count: { type: 'integer', minimum: 1, description: 'Pulses (default 1).' } }),\n\t\tcommand('shake', 'Shakes side to side (or up and down), settling.', { blend: BLEND('add'),\n\t\t\tamount: { type: 'number', description: 'Document units (default 8).' },\n\t\t\tcount: { type: 'integer', minimum: 1, description: 'Shakes (default 3).' },\n\t\t\taxis: { type: 'string', enum: ['horizontal', 'vertical'], description: 'Default horizontal.' }\n\t\t}),\n\t\tcommand('teeter', 'Rocks about the centre either way, settling.', { blend: BLEND('add'), angle: { type: 'number', description: 'Degrees either way (default 8).' }, count: { type: 'integer', minimum: 1, description: 'Rocks (default 3).' } }),\n\t\tcommand('wave', 'Bobs up and down without settling, like something floating (default 1000 ms).', { blend: BLEND('add'), amount: { type: 'number', description: 'Height in document units (default 6).' }, count: { type: 'integer', minimum: 1, description: 'Bobs (default 2).' } }),\n\t\tcommand('wiggle', 'Wanders about its place as smooth seeded noise, easing out of and back to rest (default 1500 ms). The same seed always wanders the same way.', { blend: BLEND('add'),\n\t\t\tamount: { type: 'number', description: 'Up to about this far, in document units (default 6).' },\n\t\t\tfrequency: { type: 'number', exclusiveMinimum: 0, description: 'Wanders per second, in Hz (default 3).' },\n\t\t\toctaves: { type: 'integer', minimum: 1, maximum: 8, description: 'Layers of finer detail (default 2).' },\n\t\t\trotate: { type: 'number', description: 'Also turns about the centre by up to about this many degrees (default 0).' },\n\t\t\tseed: { type: 'integer', minimum: 0, description: 'Default: one picked from the target id, so each target wanders its own way.' }\n\t\t}),\n\t\tcommand('color-pulse', 'Tints solid paint toward a colour and back (mixed in OKLab). On a group it tints every path in it.', {\n\t\t\tcolor: { type: 'string', description: 'The tint, a CSS colour (default \"#f59e0b\").' },\n\t\t\tpaint: { type: 'string', enum: ['fill', 'stroke'], description: 'Which paint (default fill).' },\n\t\t\tcount: { type: 'integer', minimum: 1, description: 'Pulses (default 1).' }\n\t\t}),\n\t\tcommand('effect', 'Tweens a numeric parameter of a live path effect on the targets (twist angle, wiggle time, zig zag size, trim offset…).', {\n\t\t\teffect: { type: 'string', minLength: 1, description: 'Effect id from get_animation\\'s element \"effects\".' },\n\t\t\tparam: { type: 'string', minLength: 1, description: 'A numeric parameter of that effect (listed with it).' },\n\t\t\tto: { type: 'number', description: 'Value at the end.' }\n\t\t}, ['effect', 'param', 'to']),\n\t\tobject(\n\t\t\t{ type: { const: 'wait', description: 'Waits.' }, duration: MS('How long'), with: BASE.with, note: BASE.note },\n\t\t\t['type', 'duration'],\n\t\t\t'Waits before the next command.'\n\t\t)\n\t]\n};\n\nconst GEOMETRIC_CAMERA: JsonSchema = { type: 'boolean', description: 'Zoom at a steady rate, so a big zoom does not rush at the start (default false).' };\nconst CAMERA: JsonSchema = {\n\tdescription: 'Where the camera looks: a rectangle { x, y, width, height } in document units, or { frame: \"<node id>\", padding } to frame a node (fitted to the artwork\\'s shape). It eases there over \"ms\" (default 1000); the first shot cuts.',\n\tanyOf: [\n\t\tobject({ x: { type: 'number', description: 'Left.' }, y: { type: 'number', description: 'Top.' }, width: { type: 'number', exclusiveMinimum: 0, description: 'Width.' }, height: { type: 'number', exclusiveMinimum: 0, description: 'Height.' }, ease: EASE, ms: MS('Camera move length'), geometric: GEOMETRIC_CAMERA }, ['x', 'y', 'width', 'height']),\n\t\tobject({ frame: { type: 'string', minLength: 1, description: 'Node id to frame.' }, padding: { type: 'number', description: 'Margin around it (default 24).' }, ease: EASE, ms: MS('Camera move length'), geometric: GEOMETRIC_CAMERA }, ['frame'])\n\t]\n};\n\nconst SHOT_FIELDS: Record<string, JsonSchema> = {\n\tlabel: { type: 'string', description: 'What happens, in a few words.' },\n\tcamera: CAMERA,\n\trun: { type: 'array', items: MOTION_COMMAND_SCHEMA, description: 'Commands, in order.' },\n\thold: MS('Hold after the commands (default 600)'),\n\tspeed: { type: 'number', minimum: 0.05, maximum: 20, description: 'Play the whole shot this many times as fast (default 1; 0.5 is half speed). fit_animation sets it.' },\n\tat: object(\n\t\t{ beat: { type: 'number', minimum: 0, description: 'Beat number on the scene\\'s beat grid, from 0 (2.5 is the \"and\" of beat 3).' }, word: { type: 'integer', minimum: 0, description: 'Index of a narration word, from 0.' }, ms: { type: 'number', minimum: 0, description: 'A time in ms.' } },\n\t\t[],\n\t\t'Start this shot on a cue (give one of beat, word or ms); the shot before holds until then. get_timing_grid lists beats and words.'\n\t)\n};\nconst SHOT: JsonSchema = object({ id: { type: 'string', pattern: '^[A-Za-z0-9_][\\\\w.-]*$', description: 'Unique shot id, e.g. \"intro\".' }, ...SHOT_FIELDS }, ['id', 'run'], 'A shot.');\nconst CONTROL: JsonSchema = object(\n\t{\n\t\tname: { type: 'string', pattern: '^[A-Za-z_]\\\\w*$', description: 'Identifier, e.g. \"accent\".' },\n\t\ttype: { const: 'color', description: 'Controls are colours.' },\n\t\tdefault: { type: 'string', pattern: '^#[0-9a-fA-F]{6}$', description: 'A #rrggbb colour the scene uses; the control stands for every use of it.' },\n\t\tlabel: { type: 'string', description: 'Label in a controls panel.' }\n\t},\n\t['name', 'type', 'default'],\n\t'A colour parameter of the Flair effect made from the scene.'\n);\nconst PRESET: JsonSchema = object({ name: { type: 'string', minLength: 1, description: 'Preset name.' }, values: { type: 'object', additionalProperties: { type: 'string' }, description: 'Control name → colour.' } }, ['name', 'values'], 'Named control values.');\n\nconst SETTINGS: Record<string, JsonSchema> = {\n\tname: { type: 'string', minLength: 1, description: 'Short name, e.g. \"logo-reveal\".' },\n\tdescription: { type: ['string', 'null'], description: 'What it shows; null clears.' },\n\tloop: { type: 'string', enum: ['none', 'loop', 'ping-pong'], description: 'Playback past the end (default none).' },\n\ttrigger: {\n\t\tanyOf: [{ type: 'string', enum: ['click', 'hover', 'press', 'scroll'] }, { type: 'null' }],\n\t\tdescription: 'Play in answer to the viewer when exported to Flair: click (nothing plays until a click; each click plays the next shot, then the first again), hover or press (plays while the pointer is over or down, rewinds when it leaves), scroll (scrubs as it scrolls past). null plays on its own (default). The editor previews it played through.'\n\t},\n\tfps: { type: 'number', minimum: 1, maximum: 120, description: 'Sampling rate for exports (default 30).' },\n\tsteps: { anyOf: [{ type: 'number', exclusiveMinimum: 0, maximum: 120 }, { type: 'null' }], description: 'Stepped time for every command without its own: changes hold on a grid of this many frames per second (12 = \"on twos\" at 24 fps) for a hand-drawn look; null makes it smooth again (default).' },\n\tmotionBlur: {\n\t\tanyOf: [object({ shutter: { type: 'number', exclusiveMinimum: 0, maximum: 720, description: 'Shutter angle in degrees of a frame (default 180; 360 is a whole frame, more blur).' }, samples: { type: 'integer', minimum: 2, maximum: 32, description: 'Most moments a frame averages (default 8).' } }), { type: 'null' }],\n\t\tdescription: 'Motion blur on the stage and in rendered frames (not exported to Flair or Lottie); null turns it off.'\n\t},\n\tbeat: {\n\t\tanyOf: [\n\t\t\tobject({ bpm: { type: 'number', minimum: 1, maximum: 1000, description: 'Beats a minute.' }, offset: { type: 'number', description: 'When beat 0 falls, ms (default 0).' }, meter: { type: 'integer', minimum: 1, description: 'Beats a bar (default 4).' } }, ['bpm']),\n\t\t\t{ type: 'null' }\n\t\t],\n\t\tdescription: 'A beat grid (music or a voiceover\\'s rhythm) that shots can be cued to with \"at\": { \"beat\": n }; null clears.'\n\t},\n\tnarration: {\n\t\tanyOf: [\n\t\t\tobject({ words: { type: 'array', items: object({ text: { type: 'string', description: 'The word.' }, start: { type: 'number', minimum: 0, description: 'When it is said, ms.' }, end: { type: 'number', minimum: 0, description: 'When it ends, ms.' } }, ['text', 'start']), description: 'Words in time order, from a TTS or speech-to-text word timing.' } }, ['words']),\n\t\t\t{ type: 'null' }\n\t\t],\n\t\tdescription: 'A voiceover\\'s word timings that shots can be cued to with \"at\": { \"word\": index }; null clears.'\n\t},\n\ttarget: { anyOf: [{ type: 'array', items: { type: 'number', minimum: 0 }, minItems: 2, maxItems: 2 }, { type: 'null' }], description: 'Wanted length [min, max] in seconds; null clears.' }\n};\n\n/** JSON Schema of one `edit_animation` op. */\nconst EDIT_OP: JsonSchema = {\n\tdescription: `One edit (${MOTION_EDIT_OPS.filter((o) => o !== 'replace_scene' && o !== 'set_artwork').join(', ')}), shaped like the tool of the same name with an \"op\" field.`,\n\toneOf: [\n\t\tobject({ op: { const: 'set_settings', description: 'Like set_animation_settings.' }, ...SETTINGS }, ['op']),\n\t\tobject({ op: { const: 'insert_shots', description: 'Like insert_shots.' }, shots: { type: 'array', items: SHOT, minItems: 1, description: 'Shots to add.' }, at: { type: 'integer', minimum: 0, description: 'Position (default: the end).' } }, ['op', 'shots']),\n\t\tobject({ op: { const: 'update_shot', description: 'Like update_shot.' }, shot: SHOT_ID, set: object({ id: SHOT.properties!.id, ...SHOT_FIELDS }, [], 'Fields to replace.'), remove: { type: 'array', items: { type: 'string', enum: ['label', 'camera', 'hold', 'speed', 'at'] }, description: 'Fields to clear.' } }, ['op', 'shot']),\n\t\tobject({ op: { const: 'delete_shots', description: 'Like delete_shots.' }, shots: { type: 'array', items: SHOT_ID, minItems: 1, description: 'Shot ids.' } }, ['op', 'shots']),\n\t\tobject({ op: { const: 'move_shot', description: 'Like move_shot.' }, shot: SHOT_ID, to: { type: 'integer', minimum: 0, description: 'New position (0 = first).' } }, ['op', 'shot', 'to']),\n\t\tobject({ op: { const: 'add_commands', description: 'Like add_commands.' }, shot: SHOT_ID, commands: { type: 'array', items: MOTION_COMMAND_SCHEMA, minItems: 1, description: 'Commands to add.' }, at: { type: 'integer', minimum: 0, description: 'Index in the shot\\'s run (default: the end).' } }, ['op', 'shot', 'commands']),\n\t\tobject({ op: { const: 'update_command', description: 'Like update_command.' }, shot: SHOT_ID, command: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'string', pattern: '^\\\\$(\\\\d+|last)[.\\\\[]' }], description: 'Index in the shot\\'s run, or a reference to an earlier op\\'s outcome such as \"$0.indexes[0]\".' }, set: { type: 'object', description: 'Command fields to replace.' }, remove: { type: 'array', items: { type: 'string' }, description: 'Command fields to clear.' } }, ['op', 'shot', 'command']),\n\t\tobject({ op: { const: 'move_command', description: 'Like move_command.' }, shot: SHOT_ID, command: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'string', pattern: '^\\\\$(\\\\d+|last)[.\\\\[]' }], description: 'Index in the shot\\'s run, or a reference to an earlier op\\'s outcome such as \"$0.indexes[0]\".' }, to: { type: 'integer', minimum: 0, description: 'New index in the run (0 = first).' } }, ['op', 'shot', 'command', 'to']),\n\t\tobject({ op: { const: 'delete_commands', description: 'Like delete_commands.' }, shot: SHOT_ID, commands: { type: 'array', items: { anyOf: [{ type: 'integer', minimum: 0 }, { type: 'string', pattern: '^\\\\$(\\\\d+|last)[.\\\\[]' }], description: 'An index, or a reference to an earlier op\\'s outcome such as \"$0.indexes[0]\".' }, minItems: 1, description: 'Indexes in the shot\\'s run.' } }, ['op', 'shot', 'commands']),\n\t\tobject({ op: { const: 'set_controls', description: 'Like set_controls.' }, controls: { type: 'array', items: CONTROL, description: 'Controls (empty clears).' }, presets: { type: 'array', items: PRESET, description: 'Presets (empty clears).' } }, ['op', 'controls'])\n\t]\n};\n\nfunction describeElement(node: VectorNode, ancestors: string[]) {\n\tconst effects = (node.effects ?? []).map((e) => ({\n\t\tid: e.id,\n\t\ttype: e.type,\n\t\tnumericParams: Object.fromEntries(Object.entries(e.params as unknown as Record<string, unknown>).filter(([, v]) => typeof v === 'number'))\n\t}));\n\treturn {\n\t\tid: node.id,\n\t\ttype: node.type,\n\t\t...(node.name ? { name: node.name } : {}),\n\t\t...(ancestors.length ? { parent: ancestors[ancestors.length - 1] } : {}),\n\t\t...(node.visible === false ? { hidden: true } : {}),\n\t\t...(node.type === 'path' && typeof node.fill === 'string' ? { fill: node.fill } : {}),\n\t\t...(node.type === 'path' && typeof node.stroke === 'string' ? { stroke: node.stroke } : {}),\n\t\t...(node.type === 'group' ? { children: node.children.map((c) => c.id) } : {}),\n\t\t...(effects.length ? { effects } : {})\n\t};\n}\n\nconst round = (n: number) => Math.round(n * 10) / 10;\n\n/** The elements of a scene's artwork, as agents see them. */\nexport function describeMotionElements(scene: MotionScene) {\n\treturn [...indexMotionNodes(scene.artwork.nodes).values()].map((e) => ({\n\t\t...describeElement(e.node, e.ancestors),\n\t\t...(e.bounds ? { bounds: { x: round(e.bounds.x), y: round(e.bounds.y), width: round(e.bounds.width), height: round(e.bounds.height) } } : {})\n\t}));\n}\n\n/** A scene's shots with their timing, as agents see them. */\nexport function describeMotionShots(scene: MotionScene) {\n\tconst timeline = compileMotionScene(scene);\n\treturn scene.shots.map((shot, i) => {\n\t\tconst t = timeline.shots[i];\n\t\treturn {\n\t\t\tid: shot.id,\n\t\t\t...(shot.label ? { label: shot.label } : {}),\n\t\t\tstart: t.start,\n\t\t\tend: t.end,\n\t\t\t...(shot.camera ? { camera: shot.camera } : {}),\n\t\t\t...(shot.hold !== undefined ? { hold: shot.hold } : {}),\n\t\t\t...(t.cue !== undefined ? { cue: Math.round(t.cue) } : {}),\n\t\t\t...(t.missedBy !== undefined ? { missedBy: Math.round(t.missedBy) } : {}),\n\t\t\tcommands: shot.run.map((c, index) => {\n\t\t\t\tconst ct = timeline.commands.find((x) => x.shotIndex === i && x.command === index)!;\n\t\t\t\tconst primitive = motionFlairPrimitive(c);\n\t\t\t\treturn { index, ...c, start: ct.start, end: ct.end, ...(primitive ? { flairPrimitive: primitive } : {}) };\n\t\t\t})\n\t\t};\n\t});\n}\n\nconst issueSummary = (issues: readonly MotionIssue[]) => ({\n\terrors: issues.filter((i) => i.severity === 'error').length,\n\twarnings: issues.filter((i) => i.severity === 'warning').length,\n\tnotes: issues.filter((i) => i.severity === 'note').length,\n\tlines: issues.map((i) => `${i.severity}: ${motionIssueLine(i)}`)\n});\n\n/**\n * Agent tools for an `AnimationEditorController`: read the scene (artwork elements, shots with\n * their timing, issues), render a frame, export to Flair, and change it a step at a time. Every\n * write is checked first (unknown ids with \"did you mean\", malformed commands), applies as one\n * undo step, and returns the resulting timing and any new issues. Write tools are hidden while\n * the animation is read-only.\n */\nexport function createAnimationEditorToolProvider(controller: AnimationEditorController, options: AnimationEditorToolProviderOptions = {}): AgentToolProvider {\n\tconst readOnlyReason = (): string | null => {\n\t\tconst r = typeof options.readOnly === 'function' ? options.readOnly() : options.readOnly;\n\t\tif (r) return typeof r === 'string' ? r : 'This animation is read-only.';\n\t\treturn controller.readOnlyReason();\n\t};\n\tconst scene = () => controller.getScene();\n\tconst outcome = (result: MotionEditResult, extra: Record<string, unknown> = {}) => {\n\t\tif (!result.ok) throw new Error(result.error);\n\t\tconst timeline = compileMotionScene(result.scene);\n\t\treturn {\n\t\t\t...extra,\n\t\t\tduration: timeline.duration,\n\t\t\tshots: timeline.shots.map((s) => ({ id: s.id, start: s.start, end: s.end })),\n\t\t\tissues: issueSummary(result.issues),\n\t\t\t...(result.hints.length ? { hints: result.hints } : {})\n\t\t};\n\t};\n\tconst apply = (edits: MotionEdit | MotionEdit[], label: string, extra?: (s: MotionScene) => Record<string, unknown>) => {\n\t\tconst result = controller.apply(edits, label);\n\t\treturn outcome(result, result.ok && extra ? extra(result.scene) : {});\n\t};\n\n\tconst getAnimation: AgentTool = {\n\t\tname: 'get_animation',\n\t\ttitle: 'Read the animation',\n\t\tdescription:\n\t\t\t'Returns the vector animation: its name, artwork size, length (ms), loop mode, the artwork\\'s elements (id, type, name, parent, bounds, solid paints, live effects with their numeric parameters), every shot with its commands and their start/end times (and, where Flair has one, the Flair motion primitive a command plays as \"flairPrimitive\", e.g. \"entrance.pop\"), Flair controls, and a summary of issues. Use the ids it returns with the write tools.',\n\t\tinputSchema: object({ includeElements: { type: 'boolean', description: 'Include the artwork\\'s elements (default true).' } }),\n\t\tannotations: { title: 'Read the animation', ...READ },\n\t\thandler: ({ includeElements = true }) => {\n\t\t\tconst s = scene();\n\t\t\tconst reason = readOnlyReason();\n\t\t\treturn {\n\t\t\t\tname: s.name,\n\t\t\t\t...(s.description ? { description: s.description } : {}),\n\t\t\t\tartwork: { width: s.artwork.width, height: s.artwork.height },\n\t\t\t\tduration: compileMotionScene(s).duration,\n\t\t\t\tloop: s.loop ?? 'none',\n\t\t\t\t...(s.trigger ? { trigger: s.trigger } : {}),\n\t\t\t\t...(s.target ? { target: s.target } : {}),\n\t\t\t\t...(includeElements ? { elements: describeMotionElements(s) } : {}),\n\t\t\t\tshots: describeMotionShots(s),\n\t\t\t\t...(s.clips ? { clips: Object.fromEntries(Object.entries(s.clips).map(([name, c]) => [name, { ...(c.description ? { description: c.description } : {}), commands: c.run.length, length: Math.round(motionClipLayout(s, name, '$').length) }])) } : {}),\n\t\t\t\t...(s.drivers ? { drivers: s.drivers } : {}),\n\t\t\t\t...(s.motionBlur ? { motionBlur: s.motionBlur } : {}),\n\t\t\t\t...(s.controls ? { controls: s.controls } : {}),\n\t\t\t\t...(s.presets ? { presets: s.presets } : {}),\n\t\t\t\tissues: issueSummary(controller.getState().issues),\n\t\t\t\t...(reason ? { readOnly: reason } : {})\n\t\t\t};\n\t\t}\n\t};\n\n\tconst getShot: AgentTool = {\n\t\tname: 'get_shot',\n\t\ttitle: 'Read one shot',\n\t\tdescription: 'Returns one shot as stored (id, label, camera, run, hold) with its start/end and each command\\'s start/end in ms.',\n\t\tinputSchema: object({ shot: SHOT_ID }, ['shot']),\n\t\tannotations: { title: 'Read one shot', ...READ },\n\t\thandler: ({ shot }) => {\n\t\t\tconst found = describeMotionShots(scene()).find((s) => s.id === shot);\n\t\t\tif (!found) throw new Error(`There is no shot \"${shot}\"; the shots are ${scene().shots.map((s) => `\"${s.id}\"`).join(', ') || 'none yet'}.`);\n\t\t\treturn found;\n\t\t}\n\t};\n\n\tconst findElements: AgentTool = {\n\t\tname: 'find_animation_elements',\n\t\ttitle: 'Find artwork elements',\n\t\tdescription: 'Finds artwork elements whose id or name contains the text (case-insensitive). Returns their id, type, name, parent, bounds, paints and live effects.',\n\t\tinputSchema: object({ query: { type: 'string', minLength: 1, description: 'Text to look for in ids and names.' }, limit: { type: 'integer', minimum: 1, maximum: 200, description: 'Most results (default 20).' } }, ['query']),\n\t\tannotations: { title: 'Find artwork elements', ...READ },\n\t\thandler: ({ query, limit = 20 }) => {\n\t\t\tconst q = String(query).toLowerCase();\n\t\t\tconst all = describeMotionElements(scene());\n\t\t\tconst elements = all.filter((e) => e.id.toLowerCase().includes(q) || ('name' in e && String(e.name).toLowerCase().includes(q)));\n\t\t\treturn { elements: elements.slice(0, limit), total: elements.length };\n\t\t}\n\t};\n\n\tconst checkAnimation: AgentTool = {\n\t\tname: 'check_animation',\n\t\ttitle: 'Check the animation',\n\t\tdescription:\n\t\t\t'Lists the animation\\'s problems: each with a stable code (unknown-target, overlap, out-of-frame, too-fast, enter-visible…), severity (error / warning / note), the shot and command index it is in, the node ids it is about, measured vs needed values, and a message saying how to fix it.',\n\t\tinputSchema: object({}),\n\t\tannotations: { title: 'Check the animation', ...READ },\n\t\thandler: () => {\n\t\t\tconst issues = controller.getState().issues;\n\t\t\treturn { ...issueSummary(issues), issues };\n\t\t}\n\t};\n\n\tconst renderFrame: AgentTool = {\n\t\tname: 'render_animation_frame',\n\t\ttitle: 'Render a frame',\n\t\tdescription:\n\t\t\t'Draws the animation at one moment (or, with times, several moments as one labelled contact sheet) without changing it, to check it: standalone SVG by default, or a PNG image (format \"png\") when the host can rasterize. Give a time in ms, or a shot and where in it.',\n\t\tinputSchema: object({\n\t\t\ttime: MS('Time from the start'),\n\t\t\tshot: { ...SHOT_ID, description: 'Render a moment of this shot instead of \"time\".' },\n\t\t\tat: { type: 'string', enum: ['start', 'middle', 'end'], description: 'With shot: which moment (default end: everything drawn, before the next shot).' },\n\t\t\tformat: { type: 'string', enum: ['svg', 'png'], description: 'svg (default) or png (only when the host supports it).' },\n\t\t\tonion_skin: object(\n\t\t\t\t{\n\t\t\t\t\tbefore: { type: 'integer', minimum: 0, maximum: 12, description: 'Ghost frames before the moment (default 2).' },\n\t\t\t\t\tafter: { type: 'integer', minimum: 0, maximum: 12, description: 'Ghost frames after it (default 0).' },\n\t\t\t\t\tspacing: { anyOf: [{ type: 'number', exclusiveMinimum: 0 }, { type: 'string', enum: ['commands'] }], description: 'Ms between ghosts (default 83, every other frame at 24 fps), or \"commands\" for the moments commands start and end.' }\n\t\t\t\t},\n\t\t\t\t[],\n\t\t\t\t'Draw faded frames either side of the moment, to see motion in one picture.'\n\t\t\t),\n\t\t\ttimes: { type: 'array', items: { type: 'number', minimum: 0 }, minItems: 2, maxItems: 16, description: 'Several moments (ms) to draw as one contact sheet, each labelled with its time and shot, instead of one frame. Overrides time and shot.' },\n\t\t\tcolumns: { type: 'integer', minimum: 1, maximum: 8, description: 'With times: frames a row (default about square).' },\n\t\t\tmotion_paths: { anyOf: [{ type: 'boolean' }, { type: 'array', items: { type: 'string', minLength: 1 } }], description: 'Draw where nodes travel (dashed, with a dot where each change starts or ends): true for every node whose place changes, or a list of ids.' }\n\t\t}),\n\t\tannotations: { title: 'Render a frame', ...READ },\n\t\thandler: async ({ time, shot, at = 'end', format = 'svg', onion_skin, motion_paths, times, columns }) => {\n\t\t\tconst s = scene();\n\t\t\tlet t = time ?? controller.getState().time;\n\t\t\tif (shot !== undefined) {\n\t\t\t\tconst timing = compileMotionScene(s).shots.find((x) => x.id === shot);\n\t\t\t\tif (!timing) throw new Error(`There is no shot \"${shot}\"; the shots are ${s.shots.map((x) => `\"${x.id}\"`).join(', ') || 'none yet'}.`);\n\t\t\t\tt = at === 'start' ? timing.start : at === 'middle' ? (timing.commandsStart + timing.commandsEnd) / 2 : Math.max(timing.start, timing.end - 1);\n\t\t\t}\n\t\t\tif (Array.isArray(motion_paths)) {\n\t\t\t\tconst known = new Set(describeMotionElements(s).map((e) => e.id));\n\t\t\t\tfor (const id of motion_paths) if (!known.has(id)) throw new Error(`There is no element ${namedWithSuggestion(id, known)} to draw a motion path for.`);\n\t\t\t}\n\t\t\tconst overlays = { ...(onion_skin ? { onionSkin: onion_skin } : {}), ...(motion_paths ? { motionPaths: motion_paths } : {}) };\n\t\t\tif (times) {\n\t\t\t\tconst sheet = motionContactSheetSvg(s, times, { pretty: false, ...overlays, ...(columns ? { columns } : {}) });\n\t\t\t\tif (format === 'png') {\n\t\t\t\t\tif (!options.rasterize) throw new Error('This host cannot make PNG images; call render_animation_frame with format \"svg\".');\n\t\t\t\t\tconst size = /width=\"(\\d+)\" height=\"(\\d+)\"/.exec(sheet)!;\n\t\t\t\t\tconst image = await options.rasterize(sheet, { width: Number(size[1]), height: Number(size[2]) });\n\t\t\t\t\treturn { content: [{ type: 'image', data: image.data, mimeType: image.mimeType }] };\n\t\t\t\t}\n\t\t\t\treturn { times, svg: sheet };\n\t\t\t}\n\t\t\tconst svg = controller.toSvg(t, { pretty: false, ...overlays });\n\t\t\tif (format === 'png') {\n\t\t\t\tif (!options.rasterize) throw new Error('This host cannot make PNG images; call render_animation_frame with format \"svg\".');\n\t\t\t\tconst image = await options.rasterize(svg, { width: s.artwork.width, height: s.artwork.height });\n\t\t\t\treturn { content: [{ type: 'image', data: image.data, mimeType: image.mimeType }] };\n\t\t\t}\n\t\t\treturn { time: t, svg };\n\t\t}\n\t};\n\n\tconst CURVES_DESCRIPTION =\n\t\t'Write cubic-bezier easings (ease, ease-in, ease-out, ease-in-out, back eases, custom curves) as one change with ease: [x1, y1, x2, y2] (default true). Needs Flair 0.36 or later; false samples them into linear steps for older Flair.';\n\tconst FLAIR_DESCRIPTION =\n\t\t'The Flair version to export for (default 0.39): springs and stepped time need 0.39, behaviours 0.38, cubic-bezier curves 0.36; older versions get those sampled into linear steps.';\n\tconst BEHAVIORS_DESCRIPTION =\n\t\t'Write pulses, shakes, teeters, waves, wiggles and colour pulses as one change with a Flair behavior, so they play exactly (default true; needs Flair 0.38 or later). False samples them into linear steps for older Flair.';\n\n\tconst getTimingGrid: AgentTool = {\n\t\tname: 'get_timing_grid',\n\t\ttitle: 'Read the beat grid and narration',\n\t\tdescription:\n\t\t\t'Returns the beats (number, time in ms, bar and beat in the bar) and narration words (index, text, start, end) between two times, to cue shots to with \"at\". Also says which shot plays at each. Without a beat grid or narration, that part is empty and says how to add one.',\n\t\tinputSchema: object({\n\t\t\tfrom: { type: 'number', minimum: 0, description: 'From this time, ms (default 0).' },\n\t\t\tto: { type: 'number', minimum: 0, description: 'Up to this time, ms (default: the end of the animation, or of the narration if later).' },\n\t\t\tlimit: { type: 'integer', minimum: 1, maximum: 1000, description: 'At most this many beats and words each (default 200).' }\n\t\t}),\n\t\tannotations: { title: 'Read the beat grid and narration', ...READ },\n\t\thandler: ({ from = 0, to, limit = 200 }) => {\n\t\t\tconst s = scene();\n\t\t\tconst timeline = compileMotionScene(s);\n\t\t\tconst words = s.narration?.words ?? [];\n\t\t\tconst end = to ?? Math.max(timeline.duration, words.length ? (words[words.length - 1].end ?? words[words.length - 1].start) : 0);\n\t\t\tconst shotAt = (ms: number) => timeline.shots.find((x) => ms >= x.start && ms < x.end)?.id;\n\t\t\tconst beats: { beat: number; ms: number; bar: number; beatInBar: number; shot?: string }[] = [];\n\t\t\tif (s.beat && s.beat.bpm > 0) {\n\t\t\t\tconst first = Math.max(0, Math.ceil(motionBeatAt(s.beat, from).beat - 1e-9));\n\t\t\t\tfor (let b = first; beats.length < limit; b++) {\n\t\t\t\t\tconst ms = motionBeatTime(s.beat, b);\n\t\t\t\t\tif (ms > end) break;\n\t\t\t\t\tconst at = motionBeatAt(s.beat, ms);\n\t\t\t\t\tconst shot = shotAt(ms);\n\t\t\t\t\tbeats.push({ beat: b, ms: Math.round(ms), bar: at.bar, beatInBar: at.beatInBar, ...(shot ? { shot } : {}) });\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst listed = words\n\t\t\t\t.map((w, index) => ({ index, text: w.text, start: w.start, ...(w.end !== undefined ? { end: w.end } : {}), ...(shotAt(w.start) ? { shot: shotAt(w.start) } : {}) }))\n\t\t\t\t.filter((w) => w.start >= from && w.start <= end)\n\t\t\t\t.slice(0, limit);\n\t\t\treturn {\n\t\t\t\tfrom,\n\t\t\t\tto: Math.round(end),\n\t\t\t\t...(s.beat ? { grid: s.beat, beats } : { beats: [], hint: 'No beat grid: set_animation_settings with { \"beat\": { \"bpm\": 120 } }.' }),\n\t\t\t\t...(words.length ? { words: listed } : { words: [], narrationHint: 'No narration: set_animation_settings with { \"narration\": { \"words\": [{ \"text\", \"start\" }, …] } }.' })\n\t\t\t};\n\t\t}\n\t};\n\n\tconst getMotionPath: AgentTool = {\n\t\tname: 'get_motion_path',\n\t\ttitle: 'Read where a node travels',\n\t\tdescription:\n\t\t\t'Returns where a node\\'s centre is over time, in document units (sampled), and where it is each time a change that moves it starts or ends. Use it to check a path, spacing or arc without reading pictures; render_animation_frame with motion_paths draws it.',\n\t\tinputSchema: object({\n\t\t\tnode: { type: 'string', minLength: 1, description: 'Element id from get_animation.' },\n\t\t\tfrom: { type: 'number', minimum: 0, description: 'From this time, ms (default 0).' },\n\t\t\tto: { type: 'number', minimum: 0, description: 'To this time, ms (default the end).' },\n\t\t\tstep: { type: 'number', exclusiveMinimum: 0, description: 'Ms between samples (default 33; at most 400 samples).' }\n\t\t}, ['node']),\n\t\tannotations: { title: 'Read where a node travels', ...READ },\n\t\thandler: ({ node, from, to, step }) => {\n\t\t\tconst s = scene();\n\t\t\tconst ids = describeMotionElements(s).map((e) => e.id);\n\t\t\tif (!ids.includes(node)) throw new Error(`There is no element ${namedWithSuggestion(node, ids)}.`);\n\t\t\treturn motionPath(s, node, { from, to, step });\n\t\t}\n\t};\n\n\tconst exportFlairMotion: AgentTool = {\n\t\tname: 'export_flair_motion',\n\t\ttitle: 'Export as Flair vector motion',\n\t\tdescription:\n\t\t\t'Returns the animation as a Flair SvgMotion ({ svg, animate }) that Flair\\'s SvgPlayer plays, plus its hold, how many changes were sampled into linear steps, and notes on anything not carried over.',\n\t\tinputSchema: object({\n\t\t\tfps: { type: 'number', minimum: 1, maximum: 120, description: 'Sampling rate for changes Flair cannot express exactly (default: the scene\\'s fps, else 30).' },\n\t\t\tcurves: { type: 'boolean', description: CURVES_DESCRIPTION },\n\t\t\tbehaviors: { type: 'boolean', description: BEHAVIORS_DESCRIPTION },\n\t\t\tflair: { type: 'string', pattern: '^\\\\d+\\\\.\\\\d+(\\\\.\\\\d+)?$', description: FLAIR_DESCRIPTION }\n\t\t}),\n\t\tannotations: { title: 'Export as Flair vector motion', ...READ },\n\t\thandler: ({ fps, curves, behaviors, flair }) => controller.toFlairMotion({ ...(fps ? { fps } : {}), ...(curves === undefined ? {} : { curves }), ...(behaviors === undefined ? {} : { behaviors }), ...(flair ? { flair } : {}) })\n\t};\n\n\tconst exportLottie: AgentTool = {\n\t\tname: 'export_lottie',\n\t\ttitle: 'Export as Lottie',\n\t\tdescription:\n\t\t\t'Returns the animation as Lottie (Bodymovin JSON, v5) for lottie-web and the mobile Lottie players: one shape layer whose groups mirror the artwork, a marker per shot, eased changes as keyframes with bezier easing and the rest sampled. Also returns how many keyframes were sampled and notes on anything not carried over (gradients, dashes, reveal clips, morphs that change point counts).',\n\t\tinputSchema: object({ fps: { type: 'number', minimum: 1, maximum: 120, description: 'Frame rate (default: the scene\\'s fps, else 30).' } }),\n\t\tannotations: { title: 'Export as Lottie', ...READ },\n\t\thandler: ({ fps }) => toLottie(scene(), fps ? { fps } : {})\n\t};\n\n\tconst exportFlairEffect: AgentTool = {\n\t\tname: 'export_flair_effect',\n\t\ttitle: 'Export as a Flair effect',\n\t\tdescription:\n\t\t\t'Returns the animation as a Flair catalog vector effect: { kind: \"vector\", id, name, description, category, tags, motion, hold, presets }, with each colour control declared as a {{name: color}} placeholder. Add it to a Flair catalog or load it in Flair\\'s effect editor.',\n\t\tinputSchema: object({\n\t\t\tid: { type: 'string', pattern: '^[a-z0-9]+(-[a-z0-9]+)*$', description: 'Kebab-case id (default: from the scene\\'s name).' },\n\t\t\tname: { type: 'string', minLength: 1, description: 'Display name (default: the scene\\'s name).' },\n\t\t\tdescription: { type: 'string', description: 'One sentence (default: the scene\\'s description).' },\n\t\t\tcategory: { type: 'string', minLength: 1, description: 'Flair catalog category, e.g. icon, loader, ui, data, text, morph (default icon).' },\n\t\t\ttags: { type: 'array', items: { type: 'string' }, description: 'Search tags (default none).' },\n\t\t\tcurves: { type: 'boolean', description: CURVES_DESCRIPTION },\n\t\t\tbehaviors: { type: 'boolean', description: BEHAVIORS_DESCRIPTION },\n\t\t\tflair: { type: 'string', pattern: '^\\\\d+\\\\.\\\\d+(\\\\.\\\\d+)?$', description: FLAIR_DESCRIPTION }\n\t\t}),\n\t\tannotations: { title: 'Export as a Flair effect', ...READ },\n\t\thandler: (args) => controller.toFlairEffect(args)\n\t};\n\n\tconst setArtworkSvg: AgentTool = {\n\t\tname: 'set_animation_artwork_svg',\n\t\ttitle: 'Replace the artwork with SVG',\n\t\tdescription:\n\t\t\t'Replaces the artwork with an SVG (paths, shapes, groups, gradients; one undo step). Give every element you will animate an id: commands target ids. Shots that name ids the new artwork lacks are refused. Returns the elements.',\n\t\tinputSchema: object({ svg: { type: 'string', minLength: 1, description: 'A standalone <svg> with a viewBox.' } }, ['svg']),\n\t\tannotations: { title: 'Replace the artwork with SVG', ...DESTRUCTIVE },\n\t\thandler: ({ svg }) => {\n\t\t\tlet artwork;\n\t\t\ttry {\n\t\t\t\tartwork = parseVectorSvg(svg);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(`The SVG could not be read: ${(error as Error).message}. Nothing was changed.`);\n\t\t\t}\n\t\t\treturn apply({ op: 'set_artwork', artwork }, 'Replace artwork', (s) => ({ elements: describeMotionElements(s) }));\n\t\t}\n\t};\n\n\tconst importFlairEffect: AgentTool = {\n\t\tname: 'import_flair_effect',\n\t\ttitle: 'Import a Flair effect',\n\t\tdescription:\n\t\t\t'Replaces the whole animation with a Flair vector effect or SvgMotion (one undo step): its SVG becomes the artwork, {{name: color}} placeholders become colour controls, and each Flair step becomes a shot of commands (fade, enter, style, move, rotate, scale, draw, follow, pulse, shake, teeter, wave, wiggle, color-pulse). Returns the shots, the elements, notes on anything not carried over and the issues. With dry_run it only reports what the import would give.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\teffect: { type: 'object', description: 'A Flair catalog vector effect { kind: \"vector\", id, name, motion: { svg, animate }, hold?, presets? }. Give this or \"motion\".' },\n\t\t\t\tmotion: { type: 'object', description: 'A Flair SvgMotion { svg, animate }. Give this or \"effect\".' },\n\t\t\t\tname: { type: 'string', minLength: 1, description: 'Name for the scene (default: the effect\\'s id, else \"from-flair\").' },\n\t\t\t\tdry_run: { type: 'boolean', description: 'Report without replacing anything (default false).' }\n\t\t\t},\n\t\t\t[]\n\t\t),\n\t\tannotations: { title: 'Import a Flair effect', ...DESTRUCTIVE },\n\t\thandler: ({ effect, motion, name, dry_run = false }) => {\n\t\t\tif ((effect === undefined) === (motion === undefined)) throw new Error('Give exactly one of \"effect\" (a Flair vector effect) or \"motion\" (a Flair SvgMotion). Nothing was changed.');\n\t\t\tlet result: FlairImportResult;\n\t\t\ttry {\n\t\t\t\tresult = effect !== undefined ? fromFlairVectorEffect(effect, name ? { name } : {}) : fromFlairSvgMotion(motion, name ? { name } : {});\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(`The Flair effect could not be imported: ${(error as Error).message} Nothing was changed.`);\n\t\t\t}\n\t\t\tconst report = { notes: result.notes, issues: issueSummary(result.issues), shots: describeMotionShots(result.scene).map(({ id, start, end, commands }) => ({ id, start, end, commands: commands.length })) };\n\t\t\tif (dry_run) return { dry_run: true, ...report, hint: 'Nothing was replaced; call again without dry_run to import.' };\n\t\t\tconst applied = controller.apply({ op: 'replace_scene', scene: result.scene }, 'Import Flair effect');\n\t\t\treturn outcome(applied, applied.ok ? { ...report, elements: describeMotionElements(result.scene) } : {});\n\t\t}\n\t};\n\n\tconst fitAnimation: AgentTool = {\n\t\tname: 'fit_animation',\n\t\ttitle: 'Fit the animation to a length',\n\t\tdescription:\n\t\t\t'Makes the animation last a given time by setting its shots\\' speed (one undo step): shots in \"keep\" play as they are and the others stretch or squeeze together, keeping their proportions. Returns the new length, each changed shot\\'s speed and the timing. With dry_run it only reports them.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tseconds: { type: 'number', exclusiveMinimum: 0, description: 'The length to fit, in seconds.' },\n\t\t\t\tkeep: { type: 'array', items: SHOT_ID, description: 'Shots that keep their pace, e.g. a logo hold (default none).' },\n\t\t\t\tdry_run: { type: 'boolean', description: 'Report without changing anything (default false).' }\n\t\t\t},\n\t\t\t['seconds']\n\t\t),\n\t\tannotations: { title: 'Fit the animation to a length', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ seconds, keep, dry_run = false }) => {\n\t\t\tconst fit = fitMotionScene(controller.getState().scene, seconds * 1000, { keep: keep ?? [] });\n\t\t\tconst report = { duration: fit.duration, speeds: fit.speeds };\n\t\t\tif (dry_run) return { dry_run: true, ...report, hint: 'Nothing was changed; call again without dry_run to fit.' };\n\t\t\tconst edits = Object.entries(fit.speeds).map(([shot, speed]) => (speed === 1 ? { op: 'update_shot' as const, shot, remove: ['speed' as const] } : { op: 'update_shot' as const, shot, set: { speed } }));\n\t\t\treturn apply(edits, 'Fit to length', () => report);\n\t\t}\n\t};\n\n\tconst PROP: JsonSchema = { type: 'string', enum: ['x', 'y', 'rotation', 'scaleX', 'scaleY', 'opacity'], description: 'x / y (offset, document units), rotation (degrees), scaleX / scaleY or opacity (1 = rest).' };\n\tconst setDrivers: AgentTool = {\n\t\tname: 'set_animation_drivers',\n\t\ttitle: 'Make properties follow others',\n\t\tdescription:\n\t\t\t'Replaces the drivers (empty clears them): each makes a target\\'s property follow a source node\\'s property, as a change from rest — target change = source change · factor + offset, clamped — added to offsets and turns, multiplied into scales and opacity, on top of the target\\'s own commands. For parallax (x follows x · 0.5), a wheel turning as it rolls (rotation follows x · 360 / (2π·radius)), a shadow fading as a ball rises (opacity follows y · 0.005). One undo step; loops between drivers are refused by check_animation. Returns the timing and issues.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tdrivers: {\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\tmaxItems: 64,\n\t\t\t\t\titems: object(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttarget: { type: 'string', minLength: 1, description: 'Element id that follows.' },\n\t\t\t\t\t\t\tproperty: PROP,\n\t\t\t\t\t\t\tsource: object({ node: { type: 'string', minLength: 1, description: 'Element id it follows.' }, property: PROP }, ['node', 'property'], 'What it follows.'),\n\t\t\t\t\t\t\tfactor: { type: 'number', description: 'Multiplies the source\\'s change (default 1).' },\n\t\t\t\t\t\t\toffset: { type: 'number', description: 'Added to the change (default 0).' },\n\t\t\t\t\t\t\tclamp: { type: 'array', items: { type: 'number' }, minItems: 2, maxItems: 2, description: 'Limits the change to [min, max].' }\n\t\t\t\t\t\t},\n\t\t\t\t\t\t['target', 'property', 'source'],\n\t\t\t\t\t\t'One property following another.'\n\t\t\t\t\t),\n\t\t\t\t\tdescription: 'Every driver (the list replaces the current one).'\n\t\t\t\t}\n\t\t\t},\n\t\t\t['drivers']\n\t\t),\n\t\tannotations: { title: 'Make properties follow others', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ drivers }) => apply({ op: 'set_drivers', drivers }, 'Set drivers')\n\t};\n\n\tconst setClip: AgentTool = {\n\t\tname: 'set_animation_clip',\n\t\ttitle: 'Define a reusable clip',\n\t\tdescription:\n\t\t\t'Defines, replaces or (with clip null) deletes a named clip: commands written against the target \"$\" that a play command plays on any node, e.g. a \"pop-settle\" or \"attention\" used many times. One undo step. Returns the clip\\'s length and the timing.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tname: { type: 'string', pattern: '^[A-Za-z_][\\\\w-]*$', description: 'Clip name, e.g. \"pop-settle\".' },\n\t\t\t\tclip: {\n\t\t\t\t\tanyOf: [object({ description: { type: 'string', description: 'What it does, in a few words.' }, run: { type: 'array', items: MOTION_COMMAND_SCHEMA, minItems: 1, description: 'Commands, timed as in a shot; target \"$\" for the node it is played on. Clips cannot play clips.' } }, ['run']), { type: 'null' }],\n\t\t\t\t\tdescription: 'The clip, or null to delete it (refused while a play command uses it).'\n\t\t\t\t}\n\t\t\t},\n\t\t\t['name', 'clip']\n\t\t),\n\t\tannotations: { title: 'Define a reusable clip', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ name, clip }) => apply({ op: 'set_clip', name, clip }, clip === null ? 'Delete clip' : 'Set clip', (s) => (clip === null ? { deleted: name } : { clip: name, length: Math.round(motionClipLayout(s, name, '$').length) }))\n\t};\n\n\tconst copyAnimation: AgentTool = {\n\t\tname: 'copy_animation',\n\t\ttitle: 'Copy one node\\'s animation to others',\n\t\tdescription:\n\t\t\t'Copies every command that animates \"from\" (in all shots, or the ones given) so it also animates \"to\": each copy goes right after its original and starts with it. One undo step. Returns how many commands were copied per shot. For motion you will reuse often, a clip (set_animation_clip + play) is tidier.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tfrom: { type: 'string', minLength: 1, description: 'Element id whose commands to copy.' },\n\t\t\t\tto: { type: 'array', items: { type: 'string', minLength: 1 }, minItems: 1, description: 'Element ids to give the same motion.' },\n\t\t\t\tshots: { type: 'array', items: SHOT_ID, description: 'Only these shots (default all).' },\n\t\t\t\tstagger: MS('Start each copy this much after the one before (default 0)')\n\t\t\t},\n\t\t\t['from', 'to']\n\t\t),\n\t\tannotations: { title: 'Copy one node\\'s animation to others', ...WRITE },\n\t\thandler: ({ from, to, shots, stagger }) => {\n\t\t\tconst s = scene();\n\t\t\tconst ids = describeMotionElements(s).map((e) => e.id);\n\t\t\tfor (const id of [from, ...to]) if (!ids.includes(id)) throw new Error(`There is no element ${namedWithSuggestion(id, ids)}. Nothing was changed.`);\n\t\t\tif (to.includes(from)) throw new Error(`\"to\" includes \"${from}\" itself; give other elements. Nothing was changed.`);\n\t\t\tconst only = shots ? new Set<string>(shots) : null;\n\t\t\tif (only) for (const id of only) if (!s.shots.some((x) => x.id === id)) throw new Error(`There is no shot ${namedWithSuggestion(id, s.shots.map((x) => x.id))}. Nothing was changed.`);\n\t\t\tconst copied: Record<string, number> = {};\n\t\t\tconst edits: MotionEdit[] = [];\n\t\t\tfor (const shot of s.shots) {\n\t\t\t\tif (only && !only.has(shot.id)) continue;\n\t\t\t\tconst run: MotionCommand[] = [];\n\t\t\t\tlet n = 0;\n\t\t\t\tfor (const c of shot.run) {\n\t\t\t\t\trun.push(c);\n\t\t\t\t\tif (c.type === 'wait' || !c.targets.includes(from)) continue;\n\t\t\t\t\tconst { delay: _delay, ...rest } = c;\n\t\t\t\t\trun.push({ ...rest, targets: to, with: 'previous', ...(stagger ? { stagger } : {}) } as MotionCommand);\n\t\t\t\t\tn++;\n\t\t\t\t}\n\t\t\t\tif (n) {\n\t\t\t\t\tcopied[shot.id] = n;\n\t\t\t\t\tedits.push({ op: 'update_shot', shot: shot.id, set: { run } });\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!edits.length) throw new Error(`No command animates \"${from}\"${only ? ' in those shots' : ''}; nothing to copy.`);\n\t\t\treturn apply(edits, 'Copy animation', () => ({ copied }));\n\t\t}\n\t};\n\n\tconst insertShots: AgentTool = {\n\t\tname: 'insert_shots',\n\t\ttitle: 'Add shots',\n\t\tdescription: 'Adds shots (one undo step) at a position (default: the end). Returns every shot\\'s new timing and any issues.',\n\t\tinputSchema: object({ shots: { type: 'array', items: SHOT, minItems: 1, description: 'Shots to add.' }, at: { type: 'integer', minimum: 0, description: 'Position, 0 = first (default: the end).' } }, ['shots']),\n\t\tannotations: { title: 'Add shots', ...WRITE },\n\t\thandler: ({ shots, at }) => apply({ op: 'insert_shots', shots, at }, 'Add shots', () => ({ added: shots.map((s: { id: string }) => s.id) }))\n\t};\n\n\tconst updateShot: AgentTool = {\n\t\tname: 'update_shot',\n\t\ttitle: 'Change a shot',\n\t\tdescription: 'Replaces the fields of one shot given in \"set\" (label, camera, run, hold, id) and clears those in \"remove\". Returns the new timing and issues.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tshot: SHOT_ID,\n\t\t\t\tset: object({ id: SHOT.properties!.id, ...SHOT_FIELDS }, [], 'Fields to replace.'),\n\t\t\t\tremove: { type: 'array', items: { type: 'string', enum: ['label', 'camera', 'hold', 'speed', 'at'] }, description: 'Fields to clear.' }\n\t\t\t},\n\t\t\t['shot']\n\t\t),\n\t\tannotations: { title: 'Change a shot', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ shot, set, remove }) => apply({ op: 'update_shot', shot, set, remove }, 'Change shot')\n\t};\n\n\tconst deleteShots: AgentTool = {\n\t\tname: 'delete_shots',\n\t\ttitle: 'Delete shots',\n\t\tdescription: 'Removes shots by id (one undo step). Returns the remaining timing.',\n\t\tinputSchema: object({ shots: { type: 'array', items: SHOT_ID, minItems: 1, description: 'Shot ids.' } }, ['shots']),\n\t\tannotations: { title: 'Delete shots', ...DESTRUCTIVE },\n\t\thandler: ({ shots }) => apply({ op: 'delete_shots', shots }, 'Delete shots')\n\t};\n\n\tconst moveShot: AgentTool = {\n\t\tname: 'move_shot',\n\t\ttitle: 'Reorder a shot',\n\t\tdescription: 'Moves a shot to a new position (0 = first). Returns the new timing.',\n\t\tinputSchema: object({ shot: SHOT_ID, to: { type: 'integer', minimum: 0, description: 'New position, 0 = first.' } }, ['shot', 'to']),\n\t\tannotations: { title: 'Reorder a shot', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ shot, to }) => apply({ op: 'move_shot', shot, to }, 'Move shot')\n\t};\n\n\tconst addCommands: AgentTool = {\n\t\tname: 'add_commands',\n\t\ttitle: 'Add commands to a shot',\n\t\tdescription: 'Adds commands to a shot\\'s run (one undo step), at an index (default: the end). Returns the indexes they got, their timing and any issues.',\n\t\tinputSchema: object({ shot: SHOT_ID, commands: { type: 'array', items: MOTION_COMMAND_SCHEMA, minItems: 1, description: 'Commands to add.' }, at: { type: 'integer', minimum: 0, description: 'Index in the run (default: the end).' } }, ['shot', 'commands']),\n\t\tannotations: { title: 'Add commands to a shot', ...WRITE },\n\t\thandler: ({ shot, commands, at }) => {\n\t\t\tconst before = scene().shots.find((s) => s.id === shot)?.run.length ?? 0;\n\t\t\tconst first = at ?? before;\n\t\t\treturn apply({ op: 'add_commands', shot, commands, at }, 'Add commands', (s) => {\n\t\t\t\tconst shots = describeMotionShots(s);\n\t\t\t\tconst added = shots.find((x) => x.id === shot)!.commands.slice(first, first + commands.length);\n\t\t\t\treturn { added: added.map((c) => ({ index: c.index, type: c.type, start: c.start, end: c.end })) };\n\t\t\t});\n\t\t}\n\t};\n\n\tconst updateCommand: AgentTool = {\n\t\tname: 'update_command',\n\t\ttitle: 'Change a command',\n\t\tdescription: 'Replaces fields of one command (by shot and index) given in \"set\" and clears those in \"remove\". Returns the command as it now stands with its timing.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tshot: SHOT_ID,\n\t\t\t\tcommand: { type: 'integer', minimum: 0, description: 'Index in the shot\\'s run (from get_animation).' },\n\t\t\t\tset: { type: 'object', description: 'Command fields to replace (see add_commands for each type\\'s fields).' },\n\t\t\t\tremove: { type: 'array', items: { type: 'string' }, description: 'Optional fields to clear (e.g. \"delay\").' }\n\t\t\t},\n\t\t\t['shot', 'command']\n\t\t),\n\t\tannotations: { title: 'Change a command', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ shot, command, set, remove }) =>\n\t\t\tapply({ op: 'update_command', shot, command, set, remove }, 'Change command', (s) => ({ command: describeMotionShots(s).find((x) => x.id === shot)!.commands[command] }))\n\t};\n\n\tconst deleteCommands: AgentTool = {\n\t\tname: 'delete_commands',\n\t\ttitle: 'Delete commands',\n\t\tdescription: 'Removes commands from a shot by index (one undo step). Later commands move up. Returns the new timing.',\n\t\tinputSchema: object({ shot: SHOT_ID, commands: { type: 'array', items: { type: 'integer', minimum: 0 }, minItems: 1, description: 'Indexes in the shot\\'s run.' } }, ['shot', 'commands']),\n\t\tannotations: { title: 'Delete commands', ...DESTRUCTIVE },\n\t\thandler: ({ shot, commands }) => apply({ op: 'delete_commands', shot, commands }, 'Delete commands')\n\t};\n\n\tconst moveCommand: AgentTool = {\n\t\tname: 'move_command',\n\t\ttitle: 'Reorder a command',\n\t\tdescription:\n\t\t\t'Moves one command to a new index in its shot\\'s run (0 = first), as one undo step; the others close up around it. A command with \"with\": \"previous\" then starts with its new neighbour. Returns the command\\'s new index, its old one and the shot\\'s timing.',\n\t\tinputSchema: object(\n\t\t\t{\n\t\t\t\tshot: SHOT_ID,\n\t\t\t\tcommand: { type: 'integer', minimum: 0, description: 'Index of the command in the shot\\'s run (from get_animation).' },\n\t\t\t\tto: { type: 'integer', minimum: 0, description: 'Its new index, 0 = first (at most the last index).' }\n\t\t\t},\n\t\t\t['shot', 'command', 'to']\n\t\t),\n\t\tannotations: { title: 'Reorder a command', ...WRITE },\n\t\thandler: ({ shot, command, to }) =>\n\t\t\tapply({ op: 'move_command', shot, command, to }, 'Move command', (s) => ({ shot, command: to, from: command, commands: describeMotionShots(s).find((x) => x.id === shot)!.commands.map((c) => ({ index: c.index, type: c.type, start: c.start, end: c.end })) }))\n\t};\n\n\tconst setSettings: AgentTool = {\n\t\tname: 'set_animation_settings',\n\t\ttitle: 'Change animation settings',\n\t\tdescription: 'Sets the name, description, loop mode, trigger (click, hover, press or scroll), export frame rate, stepped time, beat grid, narration word timings or target length. Returns the timing.',\n\t\tinputSchema: object(SETTINGS),\n\t\tannotations: { title: 'Change animation settings', ...WRITE_IDEMPOTENT },\n\t\thandler: (args) => apply({ op: 'set_settings', ...args }, 'Change settings')\n\t};\n\n\tconst setControls: AgentTool = {\n\t\tname: 'set_animation_controls',\n\t\ttitle: 'Set Flair controls',\n\t\tdescription:\n\t\t\t'Sets the colour controls (and presets) a Flair effect made from this animation exposes: each control stands for every use of its default colour. Replaces the existing controls; an empty list clears them. Returns the issues.',\n\t\tinputSchema: object({ controls: { type: 'array', items: CONTROL, description: 'Controls (empty clears).' }, presets: { type: 'array', items: PRESET, description: 'Presets (empty clears; omit to keep).' } }, ['controls']),\n\t\tannotations: { title: 'Set Flair controls', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ controls, presets }) => apply({ op: 'set_controls', controls, presets }, 'Set controls')\n\t};\n\n\tconst editAnimation: AgentTool = {\n\t\tname: 'edit_animation',\n\t\ttitle: 'Make several edits at once',\n\t\tdescription:\n\t\t\t'Applies several edits in order as one undo step, all or nothing: if one fails, nothing changes and the error names the op (\"op 2 (add_commands): …\"). A later op can use what an earlier one made: \"$0.indexes[0]\" is the index of the first command op 1 added, \"$last.shot\" the shot the op before changed. Returns each op\\'s outcome (shot, shots, indexes, clip), the timing and issues. With dry_run it only reports them.',\n\t\tinputSchema: object({ ops: { type: 'array', items: EDIT_OP, minItems: 1, description: 'Edits, applied in order.' }, dry_run: { type: 'boolean', description: 'Check without applying (default false).' } }, ['ops']),\n\t\tannotations: { title: 'Make several edits at once', ...WRITE },\n\t\thandler: ({ ops, dry_run = false }) => {\n\t\t\t// Later ops may refer to what earlier ones made (\"$0.indexes[0]\").\n\t\t\tconst refs = resolveMotionEditRefs(controller.getScene(), ops);\n\t\t\tif (!refs.ok) throw new Error(refs.error);\n\t\t\tconst result = controller.apply(refs.edits, 'Edit animation', { dryRun: dry_run });\n\t\t\treturn outcome(result, { outcomes: refs.outcomes, ...(dry_run ? { dry_run: true, hint: 'Nothing was applied; call again without dry_run to apply.' } : {}) });\n\t\t}\n\t};\n\n\tconst writeAnimation: AgentTool = {\n\t\tname: 'write_animation',\n\t\ttitle: 'Replace the animation\\'s shots',\n\t\tdescription:\n\t\t\t'Replaces every shot (and optionally the settings and controls), keeping the artwork, as one undo step. For small changes prefer the per-operation tools. Returns the timing and issues.',\n\t\tinputSchema: object({ shots: { type: 'array', items: SHOT, description: 'All shots, in order.' }, ...SETTINGS, controls: { type: 'array', items: CONTROL, description: 'Colour controls.' }, presets: { type: 'array', items: PRESET, description: 'Presets.' } }, ['shots']),\n\t\tannotations: { title: 'Replace the animation\\'s shots', ...DESTRUCTIVE },\n\t\thandler: ({ shots, controls, presets, ...settings }) => {\n\t\t\tconst current = scene();\n\t\t\tconst next: MotionScene = { ...current, shots };\n\t\t\tconst edits: MotionEdit[] = [{ op: 'replace_scene', scene: next }];\n\t\t\tif (Object.keys(settings).length) edits.push({ op: 'set_settings', ...settings });\n\t\t\tif (controls) edits.push({ op: 'set_controls', controls, presets });\n\t\t\treturn apply(edits, 'Replace animation');\n\t\t}\n\t};\n\n\tconst seekAnimation: AgentTool = {\n\t\tname: 'seek_animation',\n\t\ttitle: 'Show a moment',\n\t\tdescription: 'Moves the playhead the person sees to a time or the start of a shot, and plays or pauses. Does not change the animation. Returns the playhead time and shot.',\n\t\tinputSchema: object({ time: MS('Time from the start'), shot: { ...SHOT_ID, description: 'Go to the start of this shot instead of \"time\".' }, play: { type: 'boolean', description: 'true plays from there, false pauses (default: leave as is).' } }),\n\t\tannotations: { title: 'Show a moment', ...WRITE_IDEMPOTENT },\n\t\thandler: ({ time, shot, play }) => {\n\t\t\tif (shot !== undefined && !controller.seekShot(shot)) throw new Error(`There is no shot \"${shot}\"; the shots are ${scene().shots.map((s) => `\"${s.id}\"`).join(', ') || 'none yet'}.`);\n\t\t\tif (shot === undefined && time !== undefined) controller.seek(time);\n\t\t\tif (play === true) controller.play();\n\t\t\tif (play === false) controller.pause();\n\t\t\tconst state = controller.getState();\n\t\t\treturn { time: state.time, shot: state.currentShot, playing: state.playing };\n\t\t}\n\t};\n\n\tconst undo: AgentTool = {\n\t\tname: 'undo_animation',\n\t\ttitle: 'Undo an animation edit',\n\t\tdescription: 'Undoes the last edit. Returns whether something was undone and its label.',\n\t\tinputSchema: object({}),\n\t\tannotations: { title: 'Undo an animation edit', ...WRITE },\n\t\thandler: () => {\n\t\t\tconst label = controller.getState().undoLabel;\n\t\t\tconst undone = controller.undo();\n\t\t\treturn { undone, ...(undone ? { label } : {}) };\n\t\t}\n\t};\n\n\tconst redo: AgentTool = {\n\t\tname: 'redo_animation',\n\t\ttitle: 'Redo an animation edit',\n\t\tdescription: 'Redoes the last undone edit. Returns whether something was redone and its label.',\n\t\tinputSchema: object({}),\n\t\tannotations: { title: 'Redo an animation edit', ...WRITE },\n\t\thandler: () => {\n\t\t\tconst label = controller.getState().redoLabel;\n\t\t\tconst redone = controller.redo();\n\t\t\treturn { redone, ...(redone ? { label } : {}) };\n\t\t}\n\t};\n\n\tconst reads = [getAnimation, getShot, findElements, getMotionPath, getTimingGrid, checkAnimation, renderFrame, exportFlairMotion, exportFlairEffect, exportLottie, seekAnimation];\n\tconst writes = [setArtworkSvg, setDrivers, setClip, copyAnimation, fitAnimation, importFlairEffect, insertShots, updateShot, deleteShots, moveShot, addCommands, updateCommand, deleteCommands, moveCommand, setSettings, setControls, editAnimation, writeAnimation, undo, redo];\n\n\treturn {\n\t\tid: options.id ?? 'animation',\n\t\tnamespace: options.namespace,\n\t\ttools: () => (readOnlyReason() ? reads : [...reads, ...writes]),\n\t\tsubscribe: (notify) => {\n\t\t\tlet last = readOnlyReason();\n\t\t\treturn controller.subscribe(() => {\n\t\t\t\tconst now = readOnlyReason();\n\t\t\t\tif (now !== last) {\n\t\t\t\t\tlast = now;\n\t\t\t\t\tnotify();\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t};\n}\n","/**\n * A short authoring guide for a model writing vector animations with the animation editor's\n * tools. Static, so it caches well as part of a system prompt.\n */\nexport const ANIMATION_EDITOR_AGENT_INSTRUCTIONS = `You animate vector artwork. A scene is artwork (vector paths and groups, each with an id) plus shots.\n\nHow it plays\n- Shots play in order. A shot optionally moves the camera, plays its commands, then holds (default 600 ms).\n- Commands in a shot play one after another; give \"with\": \"previous\" to start one together with the command before, \"delay\" to wait, \"stagger\" to offset several targets.\n- Timing comes from the content: each command has a default length (enter 600 ms, move 700 ms, draw follows the path length). Only set \"duration\" to change the pace.\n- Anything that enters later is hidden until it enters. Things that never enter are visible from the start.\n- Every frame is a pure function of time: the same scene always plays the same frames.\n\nCommands\n- enter (fade, pop, grow, slide, draw) and exit (fade, shrink, slide, undraw) bring things in and out.\n- enter also reveals through a clip over the target's box: wipe (behind an edge travelling \"direction\", default right), iris (from the centre; \"shape\": circle or box) and split (from a line through the middle; \"orientation\": horizontal or vertical). exit wipe hides the same way. Reveals need a width and a height: use draw / undraw for a straight line.\n- draw draws strokes on to a fraction; move, rotate, scale and fade change the pose (about the centre); style blends solid colours and stroke width.\n- Drawing a group of strokes: \"order\": \"sequence\" draws them one after another (a signature, a diagram), \"sortBy\": \"distance\" from \"origin\" reveals outward, \"pace\": \"speed\" keeps one speed; draw with \"comet\": 0.2 sends a short stroke along a path and off the end.\n- Fast motion reads better with blur: set_animation_settings { \"motionBlur\": { \"shutter\": 180 } } (stage and rendered frames only).\n- Tie properties together with set_animation_drivers: parallax layers, a wheel that turns as it rolls, a shadow that fades as something rises. Drivers add to the target's own commands.\n- Reuse motion: set_animation_clip defines a clip (commands targeting \"$\"), and { \"type\": \"play\", \"clip\": name, \"targets\": [...] } plays it on any nodes (with stagger and speed). copy_animation gives other nodes one node's motion.\n- move takes \"via\" waypoints for a curved, smooth path that passes exactly through each point (steady speed by default); use it instead of chaining moves, which stop at each point.\n- enter also has zoom (settles from larger) and rise (rises a short way, overshooting a touch); pop and zoom take a starting \"scale\".\n- morph turns a shape into another node's shape (keep the target hidden); match does the same for a whole group, part by part (Smart Animate: draw the end state as a second, hidden group whose parts share names with the first); follow moves along a path node (with \"rotate\", moves made meanwhile turn with the path).\n- Emphasis draws the eye and returns to rest: pulse (swell), shake (side to side, or \"axis\": \"vertical\"), teeter (rock), wave (bob, no settling), wiggle (seeded wander; the same seed wanders the same way) and color-pulse (tint and back).\n- Emphasis stacks on other motion: a shake during a slide shakes as it slides. Give move, rotate or scale \"blend\": \"add\" to stack them too (what they add stays); \"blend\": \"replace\" makes a change take over instead.\n- Any command but enter and exit can \"repeat\" (loop, mirror back and forth, or offset to carry on: rotate by 90, repeat 4 is a full turn); \"duration\" is one cycle.\n- Springs (\"spring-gentle\", \"spring-quick\", \"spring-bouncy\", \"spring-slow\" or { \"type\": \"spring\", … }) feel physical; leave \"duration\" out and the spring sets it.\n- To time shots to music or a voiceover: set a \"beat\" grid or \"narration\" word timings with set_animation_settings, read them with get_timing_grid, and give a shot \"at\": { \"beat\": n } or { \"word\": i }. The shot before holds until the cue; check_animation warns when a cue is missed.\n- \"steps\": 12 (on a command, or for the whole scene with set_animation_settings) holds poses \"on twos\" for a hand-drawn look. \"geometric\": true on scale or a camera zooms at an even rate.\n- Commands share their names and defaults with Flair's motion primitives (get_animation shows each one's \"flairPrimitive\"), and emphasis, reveals and follows export to Flair exactly.\n- effect tweens a numeric parameter of a live path effect already on the node (twist angle, wiggle time, zig zag size).\n\nWorking method\n1. get_animation to learn the element ids (set_animation_artwork_svg first if there is no artwork: give every element you will animate an id; or import_flair_effect to start from a Flair effect and edit it).\n2. Plan a few shots, each one idea. Add them with insert_shots (add_commands, update_command, move_command and delete_commands refine a shot), or edit_animation to make several edits as one step (dry_run first when unsure).\n- In edit_animation, a later op can use what an earlier one made: \"$0.indexes[0]\" (the first command op 1 added), \"$last.shot\".\n3. To hit a length, fit_animation (keep the shots whose pace matters). check_animation and fix every error and warning; render_animation_frame (shot + \"end\") to look at the result, or with \"times\" for a contact sheet of several moments; add onion_skin or motion_paths to see the motion in one picture, or get_motion_path for the numbers.\n- For something the viewer plays (a button, a toggle, a step-by-step explainer), set \"trigger\" with set_animation_settings: click plays the next shot on each click and then starts over (make the last shot put things back for a toggle), hover or press plays and rewinds, scroll scrubs.\n4. To make a reusable Flair effect, set_animation_controls (colour controls stand for every use of their default colour) and export_flair_effect.\n\nKeep motion purposeful: one thing moving at a time reads best, ease-out for arrivals, ease-in for exits, and hold long enough to see each result.`;\n","import { ANIMATION_EASING_LABELS, ANIMATION_EASING_PRESETS, evaluateEasing, resolveEasing, springSettleMs, type AnimationEasing } from '../animation/easing.js';\nimport type { JsonSchema } from '../tools/schema.js';\nimport { compileMotionScene, indexMotionNodes, motionBeatAt, motionBeatTime, motionCueTime } from './compile.js';\nimport type { MotionEdit } from './edit.js';\nimport { fitMotionScene, type MotionFitOptions } from './fit.js';\nimport { MOTION_COMMAND_SCHEMA } from './tools.js';\nimport { MOTION_DRIVEN_PROPERTIES, motionFlairPrimitive, type MotionCommand, type MotionCommandType, type MotionCue, type MotionDrivenProperty, type MotionDriver, type MotionNarration, type MotionScene } from './types.js';\n\n/**\n * Helpers for hand-editing UIs (React's and Svelte's command inspector, ease picker, cue picker,\n * scrubber and stage picking). They hold the logic both bindings share, so the components stay\n * thin and alike. The command form is generated from `MOTION_COMMAND_SCHEMA`, the same schema\n * the agent tools take, so people and agents see the same fields, limits and descriptions.\n */\n\n/** How a command field is edited. */\nexport type MotionFieldKind = 'targets' | 'node' | 'enum' | 'number' | 'integer' | 'boolean' | 'text' | 'color' | 'point' | 'scale' | 'ease';\n\nexport interface MotionFieldSpec {\n\tname: string;\n\tkind: MotionFieldKind;\n\tlabel: string;\n\tdescription: string;\n\trequired: boolean;\n\t/** For `enum`. */\n\toptions?: readonly string[];\n\tmin?: number;\n\tmax?: number;\n\t/** Unit shown next to a number: `ms`, `units`, `°`, `Hz`, `fps`, `×` or `0–1`. */\n\tunit?: string;\n\t/** `main` (what it does) or `timing` (when and how fast). */\n\tgroup: 'main' | 'timing';\n}\n\nconst TIMING = new Set(['duration', 'delay', 'stagger', 'with', 'ease', 'repeat', 'repeatMode', 'steps', 'note']);\nconst COLORS = new Set(['fill', 'stroke', 'color']);\nconst NODES = new Set(['into', 'path']);\n\nfunction branch(type: MotionCommandType): JsonSchema | undefined {\n\treturn (MOTION_COMMAND_SCHEMA.oneOf ?? []).find((b) => (b.properties?.type as JsonSchema | undefined)?.const === type);\n}\n\nfunction unitOf(type: MotionCommandType, name: string): string | undefined {\n\tif (name === 'duration' || name === 'delay' || name === 'stagger') return 'ms';\n\tif (name === 'steps') return 'fps';\n\tif (name === 'frequency') return 'Hz';\n\tif (name === 'repeat' || name === 'count') return '×';\n\tif (name === 'distance' || name === 'strokeWidth') return 'units';\n\tif (name === 'angle') return '°';\n\tif (name === 'amount') return type === 'pulse' ? '×' : 'units';\n\tif (name === 'rotate' && type === 'wiggle') return '°';\n\tif ((name === 'by' || name === 'to') && type === 'rotate') return '°';\n\tif (name === 'scale' || (name === 'to' && type === 'scale')) return '×';\n\tif ((name === 'from' || name === 'to') && (type === 'draw' || type === 'fade' || type === 'follow')) return '0–1';\n\treturn undefined;\n}\n\n/** `repeatMode` → `Repeat mode`. */\nexport function motionFieldLabel(name: string): string {\n\tconst words = name.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase();\n\treturn words.charAt(0).toUpperCase() + words.slice(1);\n}\n\nfunction kindOf(name: string, schema: JsonSchema): MotionFieldKind {\n\tif (name === 'targets') return 'targets';\n\tif (name === 'ease') return 'ease';\n\tif (schema.enum) return 'enum';\n\tif (schema.anyOf) return 'scale';\n\tif (schema.type === 'object') return 'point';\n\tif (schema.type === 'boolean') return 'boolean';\n\tif (schema.type === 'integer') return 'integer';\n\tif (schema.type === 'number') return 'number';\n\tif (COLORS.has(name)) return 'color';\n\tif (NODES.has(name)) return 'node';\n\treturn 'text';\n}\n\n/**\n * The fields a command type takes, in schema order (main fields first, then timing), each with\n * how to edit it, its limits and unit. Generated from `MOTION_COMMAND_SCHEMA`.\n */\nexport function motionCommandFields(type: MotionCommandType): MotionFieldSpec[] {\n\tconst schema = branch(type);\n\tif (!schema?.properties) return [];\n\tconst required = new Set(schema.required ?? []);\n\tconst fields = Object.entries(schema.properties)\n\t\t.filter(([name]) => name !== 'type')\n\t\t.map(([name, s]): MotionFieldSpec => {\n\t\t\tconst kind = kindOf(name, s);\n\t\t\tconst min = typeof s.minimum === 'number' ? s.minimum : typeof s.exclusiveMinimum === 'number' ? s.exclusiveMinimum : undefined;\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\tkind,\n\t\t\t\tlabel: motionFieldLabel(name),\n\t\t\t\tdescription: s.description ?? '',\n\t\t\t\trequired: required.has(name),\n\t\t\t\t...(s.enum ? { options: s.enum.map(String) } : {}),\n\t\t\t\t...(min !== undefined ? { min } : {}),\n\t\t\t\t...(typeof s.maximum === 'number' ? { max: s.maximum } : {}),\n\t\t\t\t...(unitOf(type, name) ? { unit: unitOf(type, name) } : {}),\n\t\t\t\tgroup: TIMING.has(name) ? 'timing' : 'main'\n\t\t\t};\n\t\t});\n\treturn [...fields.filter((f) => f.group === 'main'), ...fields.filter((f) => f.group === 'timing')];\n}\n\nexport type MotionFieldInput = { set: unknown } | { remove: true } | { error: string };\n\n/**\n * Turns what a person typed into a field into a value to `set`, a field to `remove` (an empty\n * optional field) or an `error` to show. Numbers are checked against the field's limits.\n */\nexport function parseMotionFieldInput(field: MotionFieldSpec, raw: string | boolean | readonly string[] | { x: string; y: string }): MotionFieldInput {\n\tif (field.kind === 'boolean') return raw === true ? { set: true } : { remove: true };\n\tif (field.kind === 'targets') {\n\t\tconst ids = (Array.isArray(raw) ? raw : String(raw).split(',')).map((s) => String(s).trim()).filter(Boolean);\n\t\treturn ids.length ? { set: ids } : { error: 'Pick at least one target.' };\n\t}\n\tif (field.kind === 'point' || (field.kind === 'scale' && typeof raw === 'object' && !Array.isArray(raw))) {\n\t\tconst p = raw as { x: string; y: string };\n\t\tif (p.x.trim() === '' && p.y.trim() === '') return field.required ? { error: `${field.label} is required.` } : { remove: true };\n\t\tconst x = Number(p.x);\n\t\tconst y = Number(p.y);\n\t\tif (!Number.isFinite(x) || !Number.isFinite(y)) return { error: `${field.label} needs a number for x and for y.` };\n\t\treturn { set: { x, y } };\n\t}\n\tconst text = String(raw).trim();\n\tif (text === '') return field.required ? { error: `${field.label} is required.` } : { remove: true };\n\tif (field.kind === 'number' || field.kind === 'integer' || field.kind === 'scale') {\n\t\tconst n = Number(text);\n\t\tif (!Number.isFinite(n)) return { error: `${field.label} must be a number${field.unit ? ` (${field.unit})` : ''}.` };\n\t\tif (field.kind === 'integer' && !Number.isInteger(n)) return { error: `${field.label} must be a whole number.` };\n\t\tif (field.min !== undefined && n < field.min) return { error: `${field.label} must be at least ${field.min}.` };\n\t\tif (field.max !== undefined && n > field.max) return { error: `${field.label} must be at most ${field.max}.` };\n\t\treturn { set: n };\n\t}\n\tif (field.kind === 'enum' && field.options && !field.options.includes(text)) return { error: `${field.label} must be one of ${field.options.join(', ')}.` };\n\treturn { set: text };\n}\n\n/** The `update_command` edit for one field input, or the error to show. */\nexport function motionFieldEdit(shot: string, command: number, field: MotionFieldSpec, raw: Parameters<typeof parseMotionFieldInput>[1]): MotionEdit | { error: string } {\n\tconst input = parseMotionFieldInput(field, raw);\n\tif ('error' in input) return input;\n\tif ('remove' in input) return { op: 'update_command', shot, command, remove: [field.name] };\n\treturn { op: 'update_command', shot, command, set: { [field.name]: input.set } };\n}\n\n/**\n * A new command of `type` on `targets`, with its required fields filled from the artwork (the\n * first hidden shape to morph into, the first path to follow, the first effect parameter to\n * tween). Returns an error when the artwork has nothing to fill one with.\n */\nexport function defaultMotionCommand(type: MotionCommandType, targets: readonly string[], scene: MotionScene): MotionCommand | { error: string } {\n\tif (type === 'wait') return { type: 'wait', duration: 500 };\n\tif (!targets.length) return { error: 'Pick a target first: click an element on the stage.' };\n\tconst nodes = [...indexMotionNodes(scene.artwork.nodes).values()];\n\tconst other = (pred: (e: (typeof nodes)[number]) => boolean) => nodes.find((e) => !targets.includes(e.node.id) && pred(e))?.node.id;\n\tconst base = { targets: [...targets] };\n\tswitch (type) {\n\t\tcase 'scale':\n\t\t\treturn { type, ...base, to: 1.2 };\n\t\tcase 'fade':\n\t\t\treturn { type, ...base, to: 0.5 };\n\t\tcase 'move':\n\t\t\treturn { type, ...base, by: { x: 40, y: 0 } };\n\t\tcase 'rotate':\n\t\t\treturn { type, ...base, by: 90 };\n\t\tcase 'style':\n\t\t\treturn { type, ...base, fill: '#f59e0b' };\n\t\tcase 'morph': {\n\t\t\tconst into = other((e) => e.node.type === 'path' && e.node.visible === false) ?? other((e) => e.node.type === 'path');\n\t\t\treturn into ? { type, ...base, into } : { error: 'Morph needs another shape to become; draw one (it can stay hidden).' };\n\t\t}\n\t\tcase 'match': {\n\t\t\tconst into = other((e) => e.node.type === 'group' && e.node.visible === false) ?? other((e) => e.node.type === 'group');\n\t\t\treturn into ? ({ type, ...base, into } as MotionCommand) : { error: 'Match needs another group to become; group the end state (it can stay hidden).' };\n\t\t}\n\t\tcase 'play': {\n\t\t\tconst clip = Object.keys(scene.clips ?? {})[0];\n\t\t\treturn clip ? { type, ...base, clip } : { error: 'Play needs a clip; define one first (set_animation_clip), with \"$\" as its target.' };\n\t\t}\n\t\tcase 'follow': {\n\t\t\tconst path = other((e) => e.node.type === 'path' && e.node.visible === false) ?? other((e) => e.node.type === 'path');\n\t\t\treturn path ? { type, ...base, path } : { error: 'Follow needs a path to travel along; draw one (it can stay hidden).' };\n\t\t}\n\t\tcase 'effect': {\n\t\t\tfor (const id of targets) {\n\t\t\t\tconst node = nodes.find((e) => e.node.id === id)?.node;\n\t\t\t\tfor (const effect of node?.effects ?? []) {\n\t\t\t\t\tconst param = Object.entries(effect.params as unknown as Record<string, unknown>).find(([, v]) => typeof v === 'number');\n\t\t\t\t\tif (param) return { type, ...base, effect: effect.id, param: param[0], to: (param[1] as number) + 1 };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { error: 'Effect needs a target with a live path effect (wiggle, twist, zig zag…).' };\n\t\t}\n\t\tdefault:\n\t\t\treturn { type, ...base } as MotionCommand;\n\t}\n}\n\n/** A short line for a command in a list: `enter pop · ring, badge`. */\nexport function motionCommandSummary(command: MotionCommand): string {\n\tconst c = command as unknown as Record<string, unknown>;\n\tconst what = [command.type, typeof c.style === 'string' ? c.style : ''].filter(Boolean).join(' ');\n\tif (command.type === 'wait') return `wait ${command.duration} ms`;\n\tconst extra = typeof c.into === 'string' ? ` → ${c.into}` : typeof c.path === 'string' ? ` along ${c.path}` : '';\n\treturn `${what} · ${(command.targets ?? []).join(', ')}${extra}`;\n}\n\n/** The commands of a shot as a list UI shows them. */\nexport function motionCommandRows(scene: MotionScene, shotId: string) {\n\tconst index = scene.shots.findIndex((s) => s.id === shotId);\n\tif (index < 0) return [];\n\tconst timeline = compileMotionScene(scene);\n\treturn scene.shots[index].run.map((command, i) => {\n\t\tconst t = timeline.commands.find((c) => c.shotIndex === index && c.command === i);\n\t\tconst primitive = motionFlairPrimitive(command);\n\t\treturn { index: i, command, summary: motionCommandSummary(command), start: t?.start ?? 0, end: t?.end ?? 0, ...(primitive ? { flairPrimitive: primitive } : {}) };\n\t});\n}\n\n/** Edits that put a copy of a command right after it. */\nexport function duplicateMotionCommandEdit(scene: MotionScene, shot: string, command: number): MotionEdit {\n\tconst run = scene.shots.find((s) => s.id === shot)?.run ?? [];\n\treturn { op: 'add_commands', shot, commands: run[command] ? [structuredClone(run[command])] : [], at: command + 1 };\n}\n\n// ---------------------------------------------------------------------------------------------\n// Easing\n\n/** The ease picker's choices: `default` (the command type's own), every preset, then `custom`. */\nexport const MOTION_EASE_CHOICES: readonly { value: string; label: string }[] = [\n\t{ value: '', label: 'Default' },\n\t...ANIMATION_EASING_PRESETS.map((p) => ({ value: p, label: ANIMATION_EASING_LABELS[p] }))\n];\n\n/** The picker value for an easing: `''` for none, the preset name, else `custom`. */\nexport function motionEaseKey(ease: AnimationEasing | undefined | null): string {\n\tif (ease === undefined || ease === null) return '';\n\treturn typeof ease === 'string' ? ease : 'custom';\n}\n\nexport interface MotionEasingCurve {\n\t/** Samples of the eased value from u = 0 to 1. */\n\tpoints: { u: number; v: number }[];\n\t/** The lowest and highest eased value (below 0 or above 1 when the curve overshoots). */\n\tmin: number;\n\tmax: number;\n\t/** The length the curve was sampled over: a spring's settle time, else `durationMs`. */\n\tdurationMs: number;\n}\n\n/** Samples an easing (`evaluateEasing`) for a preview; springs are sampled until they settle. */\nexport function motionEasingCurve(ease: AnimationEasing | string | undefined | null, samples = 48, durationMs = 1000): MotionEasingCurve {\n\tconst resolved = resolveEasing(ease);\n\tconst ms = resolved !== 'hold' && resolved.type === 'spring' ? springSettleMs(resolved) : durationMs;\n\tconst n = Math.max(2, Math.floor(samples));\n\tconst points: { u: number; v: number }[] = [];\n\tfor (let i = 0; i <= n; i++) {\n\t\tconst u = i / n;\n\t\tpoints.push({ u, v: resolved === 'hold' ? (i === n ? 1 : 0) : evaluateEasing(ease, u, ms) });\n\t}\n\tconst values = points.map((p) => p.v);\n\treturn { points, min: Math.min(0, ...values), max: Math.max(1, ...values), durationMs: ms };\n}\n\n/** An SVG path (`d`) of an easing curve in a `width` × `height` box, overshoot included. */\nexport function motionEasingPath(curve: MotionEasingCurve, width: number, height: number, pad = 4): string {\n\tconst span = curve.max - curve.min || 1;\n\tconst f = (n: number) => String(Math.round(n * 100) / 100);\n\treturn curve.points\n\t\t.map((p, i) => `${i ? 'L' : 'M'}${f(pad + p.u * (width - 2 * pad))} ${f(pad + (1 - (p.v - curve.min) / span) * (height - 2 * pad))}`)\n\t\t.join(' ');\n}\n\n/** Where 0 and 1 fall on a curve preview's y axis (for guide lines). */\nexport function motionEasingGuides(curve: MotionEasingCurve, height: number, pad = 4): { zero: number; one: number } {\n\tconst span = curve.max - curve.min || 1;\n\tconst y = (v: number) => pad + (1 - (v - curve.min) / span) * (height - 2 * pad);\n\treturn { zero: y(0), one: y(1) };\n}\n\n// ---------------------------------------------------------------------------------------------\n// Stage picking\n\ninterface ElementLike {\n\tgetAttribute(name: string): string | null;\n\tparentElement: ElementLike | null;\n}\n\n/**\n * The artwork node a click landed on: the nearest element (from `target` up to `root`) whose\n * id is a node of the scene. Onion-skin ghosts and motion-path overlays carry no node ids, so\n * clicks on them pick nothing.\n */\nexport function motionNodeAtElement(scene: MotionScene, target: ElementLike | null, root?: ElementLike | null): string | null {\n\tconst ids = indexMotionNodes(scene.artwork.nodes);\n\tfor (let el = target; el && el !== root; el = el.parentElement) {\n\t\tconst id = el.getAttribute('id');\n\t\tif (id && ids.has(id)) return id;\n\t}\n\treturn null;\n}\n\nconst escapeRegExp = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n/** Marks the nodes `ids` in stage SVG with `data-picked` and outlines them. */\nexport function highlightMotionSvg(svg: string, ids: readonly string[], color = '#f43f5e'): string {\n\tif (!ids.length) return svg;\n\tlet out = svg;\n\tfor (const id of ids) {\n\t\tconst escaped = id.replace(/&/g, '&').replace(/\"/g, '"');\n\t\tout = out.replace(new RegExp(` id=\"${escapeRegExp(escaped)}\"`), ` id=\"${escaped}\" data-picked=\"\"`);\n\t}\n\treturn out.replace(/(<svg\\b[^>]*>)/, `$1<style>[data-picked]{filter:drop-shadow(0 0 1px #fff) drop-shadow(0 0 3px ${color}) drop-shadow(0 0 3px ${color})}</style>`);\n}\n\n// ---------------------------------------------------------------------------------------------\n// Time ruler, fit, cues and narration\n\n/** Ticks for a time ruler `width` px wide: a step that leaves at least `minGap` px between labels. */\nexport function motionRulerTicks(duration: number, width: number, minGap = 56): { time: number; label: string; major: boolean }[] {\n\tconst span = Math.max(1, duration);\n\tconst steps = [100, 250, 500, 1000, 2000, 5000, 10000, 30000, 60000];\n\tconst step = steps.find((s) => (s / span) * Math.max(1, width) >= minGap) ?? steps[steps.length - 1];\n\tconst ticks: { time: number; label: string; major: boolean }[] = [];\n\tfor (let t = 0; t <= span + 1e-6; t += step / 2) {\n\t\tconst major = Math.round(t / (step / 2)) % 2 === 0;\n\t\tticks.push({ time: t, major, label: major ? `${step < 1000 ? (t / 1000).toFixed(step < 500 ? 2 : 1) : String(Math.round(t / 1000))}s` : '' });\n\t}\n\treturn ticks;\n}\n\n/**\n * The edits that fit a scene to `ms` (`fitMotionScene`): one `update_shot` per shot whose speed\n * changes, so applied together they are one undo step. Throws with the reason when it can't fit.\n */\nexport function fitMotionSceneEdits(scene: MotionScene, ms: number, options: MotionFitOptions = {}): MotionEdit[] {\n\tconst fit = fitMotionScene(scene, ms, options);\n\treturn fit.scene.shots.flatMap((shot, i): MotionEdit[] => {\n\t\tconst before = scene.shots[i].speed;\n\t\tif (before === shot.speed) return [];\n\t\treturn shot.speed === undefined ? [{ op: 'update_shot', shot: shot.id, remove: ['speed'] }] : [{ op: 'update_shot', shot: shot.id, set: { speed: shot.speed } }];\n\t});\n}\n\n/** A cue picker's value for a cue: `beat:4`, `word:2`, `ms:1200` or `''` for none. */\nexport function motionCueKey(cue: MotionCue | undefined): string {\n\tif (!cue) return '';\n\tif (typeof cue.beat === 'number') return `beat:${cue.beat}`;\n\tif (typeof cue.word === 'number') return `word:${cue.word}`;\n\tif (typeof cue.ms === 'number') return `ms:${cue.ms}`;\n\treturn '';\n}\n\n/** The cue a picker value names, or undefined for none. */\nexport function motionCueFromKey(key: string): MotionCue | undefined {\n\tconst m = /^(beat|word|ms):(-?\\d+(?:\\.\\d+)?)$/.exec(key);\n\tif (!m) return undefined;\n\treturn { [m[1]]: Number(m[2]) } as MotionCue;\n}\n\n/**\n * The cues a shot can start on: every beat of the scene's grid up to a little past the end, and\n * every narration word, each labelled with its time.\n */\nexport function motionCueChoices(scene: MotionScene, limit = 256): { value: string; label: string; time: number }[] {\n\tconst choices: { value: string; label: string; time: number }[] = [];\n\tconst s = (ms: number) => `${(ms / 1000).toFixed(2)} s`;\n\tconst end = Math.max(compileMotionScene(scene).duration, ...(scene.narration?.words.map((w) => w.end ?? w.start) ?? [0])) + 2000;\n\tif (scene.beat && scene.beat.bpm > 0) {\n\t\tfor (let beat = 0; choices.length < limit; beat++) {\n\t\t\tconst time = motionBeatTime(scene.beat, beat);\n\t\t\tif (time > end) break;\n\t\t\tif (time < 0) continue;\n\t\t\tconst at = motionBeatAt(scene.beat, time);\n\t\t\tchoices.push({ value: `beat:${beat}`, label: `Beat ${beat} (bar ${at.bar}.${at.beatInBar}) · ${s(time)}`, time });\n\t\t}\n\t}\n\tscene.narration?.words.forEach((w, i) => {\n\t\tif (choices.length < limit * 2) choices.push({ value: `word:${i}`, label: `Word ${i} “${w.text}” · ${s(w.start)}`, time: w.start });\n\t});\n\treturn choices;\n}\n\n/** When a shot's cue falls (ms), or undefined. */\nexport function motionShotCueTime(scene: MotionScene, cue: MotionCue | undefined): number | undefined {\n\treturn cue ? motionCueTime(scene, cue) : undefined;\n}\n\n/** Narration as text, a word a line: `<start ms> <word>`. */\nexport function formatMotionNarration(narration: MotionNarration | undefined): string {\n\treturn (narration?.words ?? []).map((w) => `${w.start} ${w.text}`).join('\\n');\n}\n\n/** Reads narration typed a word a line (`<start ms> <word>`); empty text clears it. */\nexport function parseMotionNarration(text: string): { narration: MotionNarration | null } | { error: string } {\n\tconst lines = text.split('\\n').map((l) => l.trim()).filter(Boolean);\n\tif (!lines.length) return { narration: null };\n\tconst words: MotionNarration['words'] = [];\n\tfor (const [i, line] of lines.entries()) {\n\t\tconst m = /^(\\d+(?:\\.\\d+)?)\\s+(.+)$/.exec(line);\n\t\tif (!m) return { error: `Line ${i + 1} (\"${line}\") should be a start time in ms and a word, e.g. \"1200 hello\".` };\n\t\tconst start = Number(m[1]);\n\t\tif (words.length && start < words[words.length - 1].start) return { error: `Line ${i + 1} starts before the word above it; keep the words in time order.` };\n\t\twords.push({ text: m[2], start });\n\t}\n\treturn { narration: { words } };\n}\n\n/** Drivers as text, one a line: `dot.x <- box.x * 0.5 + 2 [-10, 10]` (factor, offset and clamp optional). */\nexport function formatMotionDrivers(drivers: readonly MotionDriver[] | undefined): string {\n\treturn (drivers ?? [])\n\t\t.map((d) => `${d.target}.${d.property} <- ${d.source.node}.${d.source.property}${d.factor !== undefined && d.factor !== 1 ? ` * ${d.factor}` : ''}${d.offset ? ` ${d.offset < 0 ? '-' : '+'} ${Math.abs(d.offset)}` : ''}${d.clamp ? ` [${d.clamp[0]}, ${d.clamp[1]}]` : ''}`)\n\t\t.join('\\n');\n}\n\n/** Reads drivers typed one a line (see `formatMotionDrivers`); empty text clears them. */\nexport function parseMotionDrivers(text: string): { drivers: MotionDriver[] } | { error: string } {\n\tconst props = MOTION_DRIVEN_PROPERTIES as readonly string[];\n\tconst drivers: MotionDriver[] = [];\n\tconst lines = text.split('\\n').map((l) => l.trim()).filter(Boolean);\n\tfor (const [i, line] of lines.entries()) {\n\t\tconst m = /^([\\w.-]+)\\.(\\w+)\\s*<-\\s*([\\w.-]+)\\.(\\w+)\\s*(?:\\*\\s*(-?[\\d.]+(?:e-?\\d+)?))?\\s*(?:([+-])\\s*([\\d.]+(?:e-?\\d+)?))?\\s*(?:\\[\\s*(-?[\\d.]+)\\s*,\\s*(-?[\\d.]+)\\s*\\])?$/.exec(line);\n\t\tif (!m) return { error: `Line ${i + 1} (\"${line}\") should read \"target.property <- source.property\", optionally \"* factor\", \"+ offset\" and \"[min, max]\", e.g. \"dot.x <- box.x * 0.5\".` };\n\t\tconst [, target, property, node, sourceProperty, factor, sign, offset, min, max] = m;\n\t\tfor (const p of [property, sourceProperty]) if (!props.includes(p)) return { error: `Line ${i + 1}: \"${p}\" is not a property drivers use; use ${MOTION_DRIVEN_PROPERTIES.join(', ')}.` };\n\t\tconst d: MotionDriver = { target, property: property as MotionDrivenProperty, source: { node, property: sourceProperty as MotionDrivenProperty } };\n\t\tif (factor !== undefined) d.factor = Number(factor);\n\t\tif (offset !== undefined) d.offset = (sign === '-' ? -1 : 1) * Number(offset);\n\t\tif (min !== undefined) d.clamp = [Number(min), Number(max)];\n\t\tif ([d.factor, d.offset, ...(d.clamp ?? [])].some((n) => n !== undefined && !Number.isFinite(n))) return { error: `Line ${i + 1} has a number that cannot be read.` };\n\t\tdrivers.push(d);\n\t}\n\treturn { drivers };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEO,IAAM,kBAA4C,CAAC,SAAS,SAAS,SAAS,QAAQ;AAqRtF,IAAM,2BAA4D,CAAC,KAAK,KAAK,YAAY,UAAU,UAAU,SAAS;AAuBtH,IAAM,qBAAqB;AAuK3B,IAAM,uBAAqD;AAAA,EACjE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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CAAqC;AACpK,YAAQ,KAAK,CAAC;AAAA,EACf;AACA,SAAO,EAAE,QAAQ;AAClB;","names":["command","command","command","end","duration","ease","order","opacity","open","body","bg","shotIndex","command","command","rest","TRANSFORM_PROPS","round","command","round","track","command","command","command"]}
|