@pixerate/editor 0.57.0 → 0.59.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/index.cjs +23 -3
- package/dist/animation/index.cjs.map +1 -1
- package/dist/animation/index.d.cts +3 -2
- package/dist/animation/index.d.ts +3 -2
- package/dist/animation/index.js +23 -3
- package/dist/animation-editor/index.cjs +836 -158
- package/dist/animation-editor/index.cjs.map +1 -1
- package/dist/animation-editor/index.d.cts +454 -40
- package/dist/animation-editor/index.d.ts +454 -40
- package/dist/animation-editor/index.js +790 -112
- package/dist/animation-editor/index.js.map +1 -1
- package/dist/behavior-Ymbld6jL.d.cts +60 -0
- package/dist/behavior-Ymbld6jL.d.ts +60 -0
- package/dist/canvas/index.cjs +35 -29
- package/dist/canvas/index.cjs.map +1 -1
- package/dist/canvas/index.d.cts +4 -4
- package/dist/canvas/index.d.ts +4 -4
- package/dist/canvas/index.js +9 -3
- package/dist/canvas/index.js.map +1 -1
- package/dist/{chunk-O4ONBPZW.cjs → chunk-2FGRTYJN.cjs} +4 -4
- package/dist/{chunk-O4ONBPZW.cjs.map → chunk-2FGRTYJN.cjs.map} +1 -1
- package/dist/{chunk-XZ4L3R4K.cjs → chunk-2FHLHZAL.cjs} +39 -3
- package/dist/chunk-2FHLHZAL.cjs.map +1 -0
- package/dist/chunk-3NYXDBBW.js +122 -0
- package/dist/chunk-3NYXDBBW.js.map +1 -0
- package/dist/{chunk-NONDTTH7.js → chunk-3TLL5OID.js} +17 -2
- package/dist/{chunk-NONDTTH7.js.map → chunk-3TLL5OID.js.map} +1 -1
- package/dist/{chunk-UB2OY7FD.js → chunk-AGR4P4UZ.js} +38 -2
- package/dist/chunk-AGR4P4UZ.js.map +1 -0
- package/dist/{chunk-SHOVAHUB.js → chunk-JK6M6V7G.js} +2 -2
- package/dist/{chunk-XCXQDPID.cjs → chunk-YJLCBA7V.cjs} +25 -10
- package/dist/chunk-YJLCBA7V.cjs.map +1 -0
- package/dist/chunk-ZCNLBRT6.cjs +122 -0
- package/dist/chunk-ZCNLBRT6.cjs.map +1 -0
- package/dist/{easing-CNGk-W6d.d.ts → easing-lM0Xo9Ni.d.cts} +14 -2
- package/dist/{easing-CNGk-W6d.d.cts → easing-lM0Xo9Ni.d.ts} +14 -2
- package/dist/parameters/index.cjs +2 -2
- package/dist/parameters/index.d.cts +1 -1
- package/dist/parameters/index.d.ts +1 -1
- package/dist/parameters/index.js +1 -1
- package/dist/{player-W-5DX3Go.d.ts → player-DV4Jujdq.d.ts} +1 -1
- package/dist/{player-Dg0FT0UI.d.cts → player-DrcP2xqj.d.cts} +1 -1
- package/dist/{svg-CPK82TtU.d.ts → svg-Dh17jCyA.d.ts} +22 -1
- package/dist/{svg-CLg2zqZA.d.cts → svg-ymShkNtu.d.cts} +22 -1
- package/dist/vector/index.cjs +472 -472
- package/dist/vector/index.d.cts +3 -3
- package/dist/vector/index.d.ts +3 -3
- package/dist/vector/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-UB2OY7FD.js.map +0 -1
- package/dist/chunk-XCXQDPID.cjs.map +0 -1
- package/dist/chunk-XZ4L3R4K.cjs.map +0 -1
- /package/dist/{chunk-SHOVAHUB.js.map → chunk-JK6M6V7G.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/animation-editor/types.ts","../../src/animation-editor/issues.ts","../../src/animation-editor/parse.ts","../../src/animation-editor/compile.ts","../../src/animation-editor/evaluate.ts","../../src/animation-editor/check.ts","../../src/animation-editor/edit.ts","../../src/animation-editor/flair.ts","../../src/animation-editor/controller.ts","../../src/animation-editor/tools.ts","../../src/animation-editor/instructions.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/** Frame rate used to sample motion that a target format cannot express exactly (default 30). */\n\tfps?: number;\n\t/** Wanted length in seconds `[min, max]`; `check` warns outside it. */\n\ttarget?: [number, number];\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/** 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};\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/** 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}\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 (each type has a default; `draw` follows the path length). */\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\tease?: AnimationEasing;\n\t/** Why this command is here (for people and agents reading the scene). */\n\tnote?: string;\n}\n\nexport type MotionEnterStyle = 'fade' | 'pop' | 'grow' | 'slide' | 'draw';\nexport type MotionExitStyle = 'fade' | 'shrink' | 'slide' | 'undraw';\nexport type MotionDirection = 'up' | 'down' | 'left' | 'right';\n\n/** Brings hidden targets in. Targets entered in a shot are hidden before it. */\nexport interface MotionEnterCommand extends MotionCommandBase {\n\ttype: 'enter';\n\t/** Default `fade`. `draw` draws the outline on, then fades the fill in. */\n\tstyle?: MotionEnterStyle;\n\t/** For `slide`: the direction of travel (default `up`). */\n\tdirection?: MotionDirection;\n\t/** For `slide`: how far in document units (default 40). */\n\tdistance?: number;\n}\n\n/** Takes targets out. */\nexport interface MotionExitCommand extends MotionCommandBase {\n\ttype: 'exit';\n\t/** Default `fade`. */\n\tstyle?: MotionExitStyle;\n\tdirection?: MotionDirection;\n\tdistance?: number;\n}\n\n/** Draws a stroke on (or off) between two fractions of its length. */\nexport interface MotionDrawCommand extends MotionCommandBase {\n\ttype: 'draw';\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\ttype: 'move';\n\tby?: { x: number; y: number };\n\tto?: { x: number; y: number };\n}\n\n/** Turns targets about their centre, by or to an angle in degrees (clockwise). */\nexport interface MotionRotateCommand extends MotionCommandBase {\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\ttype: 'scale';\n\tto: number | { x: number; y: number };\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/** 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/** Turn with the path's direction (default false). */\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\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, settling. */\nexport interface MotionShakeCommand extends MotionCommandBase {\n\ttype: 'shake';\n\t/** Distance in document units (default 8). */\n\tamount?: number;\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| MotionFollowCommand\n\t| MotionPulseCommand\n\t| MotionShakeCommand\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'follow',\n\t'pulse',\n\t'shake',\n\t'effect',\n\t'wait'\n];\nexport const MOTION_ENTER_STYLES: readonly MotionEnterStyle[] = ['fade', 'pop', 'grow', 'slide', 'draw'];\nexport const MOTION_EXIT_STYLES: readonly MotionExitStyle[] = ['fade', 'shrink', 'slide', 'undraw'];\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\tfollow: 1400,\n\tpulse: 600,\n\tshake: 500,\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 * 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'unknown-shape': { severity: 'error', wording: 'A morph names a shape the artwork does not have.' },\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.' },\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'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, 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', 'loop', 'fps', 'target', 'controls', 'presets'];\nconst SHOT_KEYS = ['id', 'label', 'camera', 'run', 'hold'];\nconst CAMERA_KEYS = ['x', 'y', 'width', 'height', 'frame', 'padding', 'ease', 'ms'];\nconst BASE_KEYS = ['type', 'targets', 'duration', 'delay', 'stagger', 'with', 'ease', 'note'];\nconst COMMAND_KEYS: Record<string, string[]> = {\n\tenter: [...BASE_KEYS, 'style', 'direction', 'distance'],\n\texit: [...BASE_KEYS, 'style', 'direction', 'distance'],\n\tdraw: [...BASE_KEYS, 'from', 'to'],\n\tmove: [...BASE_KEYS, 'by', 'to'],\n\trotate: [...BASE_KEYS, 'by', 'to'],\n\tscale: [...BASE_KEYS, 'to'],\n\tfade: [...BASE_KEYS, 'to'],\n\tstyle: [...BASE_KEYS, 'fill', 'stroke', 'strokeWidth'],\n\tmorph: [...BASE_KEYS, 'into'],\n\tfollow: [...BASE_KEYS, 'path', 'rotate', 'from', 'to'],\n\tpulse: [...BASE_KEYS, 'amount', 'count'],\n\tshake: [...BASE_KEYS, 'amount', '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 (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 { \"type\": \"cubic-bezier\", … }.`);\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\tbreak;\n\t\t}\n\t\tcase 'draw':\n\t\t\tfraction('from');\n\t\t\tfraction('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\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\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 'morph':\n\t\t\tif (typeof command.into !== 'string' || !command.into) p(`\"into\" must be the id of a 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\t\toptionalNumber('amount');\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\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 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.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}\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.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.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","import { mixColorsOklab } from '../animation/color.js';\nimport { evaluateEasing, 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\ttype MotionCamera,\n\ttype MotionCommand,\n\ttype MotionDirection,\n\ttype MotionRect,\n\ttype MotionScene\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]`.\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| 'camera'\n\t| `effect:${string}:${string}`;\n\nexport type MotionValue = number | string | readonly number[];\n\n/** An oscillation laid over a segment (`pulse`: scale up and back; `shake`: side to side, settling). */\nexport interface MotionWave {\n\tkind: 'pulse' | 'shake';\n\tamount: number;\n\tcount: number;\n}\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\twave?: MotionWave;\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}\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}\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 });\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/** 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 '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`. */\nexport function segmentProgress(segment: MotionSegment, time: number): { u: number; eased: number } {\n\tconst span = segment.end - segment.start;\n\tconst u = span <= 0 ? 1 : Math.min(1, Math.max(0, (time - segment.start) / span));\n\treturn { u, eased: segment.wave ? u : evaluateEasing(segment.ease, u, span) };\n}\n\n/** A segment's value at `time`. */\nexport function segmentValue(segment: MotionSegment, time: number): MotionValue {\n\tconst { u, eased } = segmentProgress(segment, time);\n\tconst v = interpolateMotionValue(segment.from, segment.to, eased);\n\tif (!segment.wave || typeof v !== 'number') return v;\n\tconst { kind, amount, count } = segment.wave;\n\tif (kind === 'pulse') return v * (1 + amount * Math.sin(Math.PI * u * count) ** 2);\n\treturn v + amount * Math.sin(2 * Math.PI * u * count) * (1 - u);\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. */\nexport function trackValue(track: readonly MotionSegment[] | undefined, time: number): MotionValue | undefined {\n\tif (!track?.length) return undefined;\n\tconst s = activeSegment(track, time);\n\tif (s) return segmentValue(s, time);\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/** 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 long one target of a command takes (ms). */\nexport function motionCommandDuration(command: MotionCommand, scene: MotionScene, target?: string): number {\n\tif (command.type === 'wait') return command.duration;\n\tif (command.duration !== undefined) return command.duration;\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\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 }[] = [];\n\tlet t = 0;\n\tscene.shots.forEach((shot, index) => {\n\t\tconst start = t;\n\t\tlet cursor = start;\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);\n\t\t\t\tcameraMoves.push({ shot: shot.id, start, end: start + ms, to: rect, ease: shot.camera.ease ?? MOTION_EASE_IN_OUT });\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));\n\t\t\tconst targets = command.type === 'wait' ? [] : command.targets;\n\t\t\tconst durations = command.type === 'wait' ? [command.duration] : targets.map((id) => motionCommandDuration(command, scene, id));\n\t\t\tconst stagger = command.type === 'wait' ? 0 : (command.stagger ?? 0);\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);\n\t\tshots.push({ id: shot.id, index, ...(shot.label ? { label: shot.label } : {}), start, commandsStart, commandsEnd: runEnd, end });\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 = 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 })\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\tcommand.targets.forEach((target, k) => {\n\t\t\tconst entry = nodes.get(target);\n\t\t\tif (!entry) return;\n\t\t\tconst start = timing.start + k * (command.stagger ?? 0);\n\t\t\tconst duration = motionCommandDuration(command, scene, target);\n\t\t\tjobs.push({ start, order: order++, run: () => compileCommand(command, target, entry, start, duration, 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\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\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\tif (style === 'draw') {\n\t\t\t\t\tseg('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') {\n\t\t\t\t\tseg('opacity', opacity, MOTION_EASE_OUT, start, start + duration * 0.4, { from: 0 });\n\t\t\t\t\tseg('scaleX', 1, ease ?? 'ease-out-back', start, end, { from: 0.5 });\n\t\t\t\t\tseg('scaleY', 1, ease ?? 'ease-out-back', start, end, { from: 0.5 });\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 });\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\tif (style === 'undraw') {\n\t\t\t\t\tseg('fillOpacity', 0, 'ease-in', start, start + duration * 0.4);\n\t\t\t\t\tseg('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');\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 drawn = tracks.has(motionTrackKey(node, 'drawEnd'));\n\t\t\t\tseg('drawEnd', command.to ?? 1, ease ?? MOTION_EASE_IN_OUT, start, end, command.from !== undefined ? { from: command.from } : drawn ? {} : { from: 0 });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\tbreak;\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\tseg('x', num('x') + dx, e);\n\t\t\t\tseg('y', num('y') + dy, e);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'rotate':\n\t\t\t\tseg('rotation', command.to ?? num('rotation') + (command.by ?? 0), ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\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\tseg('scaleX', to.x, ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tseg('scaleY', to.y, ease ?? MOTION_EASE_IN_OUT);\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 '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\tcase 'pulse': {\n\t\t\t\tconst wave: MotionWave = { kind: 'pulse', amount: command.amount ?? 0.15, count: command.count ?? 1 };\n\t\t\t\tseg('scaleX', num('scaleX'), 'linear', start, end, { wave });\n\t\t\t\tseg('scaleY', num('scaleY'), 'linear', start, end, { wave });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'shake':\n\t\t\t\tseg('x', num('x'), 'linear', start, end, { wave: { kind: 'shake', amount: command.amount ?? 8, count: command.count ?? 3 } });\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 } from '../canvas/pathops/bezier.js';\nimport { createVectorEffect } from '../vector/appearance.js';\nimport { applyMatrix, invertMatrix, multiplyMatrices, nodeMatrix, rotateMatrix, scaleMatrix, translateMatrix, vectorPathWorldBezier, isIdentityMatrix, type AffineMatrix } from '../vector/geometry.js';\nimport { vectorDocumentToSvg, type VectorSvgExportOptions } from '../vector/svg.js';\nimport type { VectorDocument, VectorEffect, VectorGradient, VectorNode, VectorPaint, VectorPathNode } from '../vector/types.js';\nimport { activeSegment, compileMotionScene, indexMotionNodes, motionTrackKey, segmentProgress, trackValue, type MotionNodeEntry, type MotionProperty, type MotionTimeline } from './compile.js';\nimport type { MotionRect, MotionScene } from './types.js';\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}\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/** Where a follow puts the node's centre (parent space), and the path's angle 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 path = nodes.get(s.path);\n\tif (!path || path.node.type !== 'path') return null;\n\tconst progress = Number(trackValue(track, time));\n\tif (!(progress >= 0)) return null;\n\ttry {\n\t\tconst bezier = vectorPathWorldBezier(path.node, path.parentWorld, { effects: false });\n\t\tconst at = bezierPathPointAtLength(bezier, Math.min(1, Math.max(0, progress)) * bezierPathLength(bezier));\n\t\tif (!at) return null;\n\t\tconst p = applyMatrix(invertMatrix(entry.parentWorld), { x: at.point[0], y: at.point[1] });\n\t\treturn { x: p.x, y: p.y, angle: s.rotate ? (at.angle * 180) / Math.PI : 0 };\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** The transform a node's offsets, turn, scale and follow add (parent space), or null when none. */\nexport function motionNodeOffset(entry: MotionNodeEntry, timeline: MotionTimeline, time: number, nodes = indexMotionNodes([entry.node])): { matrix: AffineMatrix; dx: number; dy: number; rotation: number; scaleX: number; scaleY: number } | null {\n\tconst read = (p: MotionProperty, rest: number) => {\n\t\tconst v = trackValue(timeline.tracks.get(motionTrackKey(entry.node.id, p)), time);\n\t\treturn typeof v === 'number' ? v : rest;\n\t};\n\tif (!TRANSFORM_PROPS.some((p) => timeline.tracks.has(motionTrackKey(entry.node.id, p)))) return null;\n\tlet dx = read('x', 0);\n\tlet dy = read('y', 0);\n\tlet rotation = read('rotation', 0);\n\tconst scaleX = read('scaleX', 1);\n\tconst scaleY = read('scaleY', 1);\n\tconst follow = followAt(entry, timeline, nodes, time);\n\tif (follow) {\n\t\tdx += follow.x - entry.center.x;\n\t\tdy += follow.y - entry.center.y;\n\t\trotation += follow.angle;\n\t}\n\tconst c = entry.center;\n\tconst matrix = multiplyMatrices(multiplyMatrices(scaleMatrix(scaleX, scaleY, c), rotateMatrix(rotation, c)), translateMatrix(dx, dy));\n\treturn { matrix, dx, dy, rotation, scaleX, scaleY };\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\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\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]) } };\n}\n\nexport interface MotionSvgOptions extends MotionFrameOptions, VectorSvgExportOptions {}\n\n/** The scene at `time` as a standalone SVG (the camera becomes the `viewBox`). */\nexport function motionFrameToSvg(scene: MotionScene, time: number, options: MotionSvgOptions = {}): string {\n\tconst frame = motionFrameAt(scene, time, options);\n\treturn withViewBox(vectorDocumentToSvg(frame.document, options), 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 { normalizeTokenColor } from '../tokens/color.js';\nimport { collectPathNodes } from '../vector/geometry.js';\nimport type { VectorNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionTrackKey, trackValue, type MotionTimeline } from './compile.js';\nimport { motionFrameAt } from './evaluate.js';\nimport { motionIssue, namedWithSuggestion, type MotionIssue } from './issues.js';\nimport type { MotionCommand, 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\tconst hasFill = node.type === 'path' ? !!node.fill && node.fill !== 'none' : collectPathNodes(node).some((p) => p.fill && p.fill !== 'none');\n\treturn num('drawEnd', 1) > 0.01 || (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.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 === '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 === '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// Two segments changing the same property of a node at the same time.\n\tfor (const [key, track] of timeline.tracks) {\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.`, { 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 or add shots.`, { 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 { commandShapeProblems, motionSceneShapeProblems, shotShapeProblems } from './parse.js';\nimport type { 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']; fps?: number; 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')[] }\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: 'set_artwork'; artwork: VectorDocument }\n\t| { op: 'set_controls'; controls: MotionControl[]; presets?: MotionPreset[] }\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'set_artwork',\n\t'set_controls',\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.fps !== undefined) next.fps = edit.fps;\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 '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 '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/** 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","import { evaluateEasing, resolveEasing, 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 } from '../vector/svg.js';\nimport type { VectorNode, VectorPathNode } from '../vector/types.js';\nimport { compileMotionScene, indexMotionNodes, motionTrackKey, trackValue, type MotionProperty, type MotionSegment } from './compile.js';\nimport { motionFrameAt, motionNodeOffset } from './evaluate.js';\nimport type { MotionScene } 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`, pulses and shakes, follows, morphs and live-effect tweens) is sampled at the\n * scene's `fps` into short linear changes, which Flair plays the same way.\n */\n\n/** Flair's easing names. */\nexport type FlairEaseName = 'linear' | 'in-out' | 'out';\n\n/** A Flair easing: a name, or (Flair 0.36 and later) a CSS cubic-bezier `[x1, y1, x2, y2]`. */\nexport type FlairEase = FlairEaseName | readonly [number, number, number, number];\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\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\tpresets?: { name: string; values: Record<string, string> }[];\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}\n\nexport interface FlairExportOptions {\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}\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), so its values pass `from` or `to`. */\nconst overshoots = (ease: FlairEase) => typeof ease !== 'string' && (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\tkind: 'attr' | 'draw' | 'view';\n\tattr?: 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}\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 curves = options.curves ?? true;\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\tfor (const id of animatedNodes) {\n\t\tconst entry = nodes.get(id)!;\n\t\tconst node = entry.node;\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: (s) => !s.wave, value: (t) => round(Math.min(1, Math.max(0, Number(trackValue(track(id, 'opacity'), t))))) });\n\n\t\tconst transformSegments = TRANSFORM_PROPS.flatMap((p) => track(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\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) && !s.wave,\n\t\t\t\tovershoot: true,\n\t\t\t\tvalue: (t) => {\n\t\t\t\t\tconst o = motionNodeOffset(entry, timeline, t, nodes)!;\n\t\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\t}\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: () => true, value: (t) => hex6(trackValue(track(from, p), t)) });\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) => {\n\t\tconst base = { ...(channel.id ? { id: channel.id } : {}), ...(delay > 0 ? { delay: round(delay) } : {}), ms: round(ms), ease: typeof ease === 'string' ? ease : (ease.map(round) as unknown as FlairEase) };\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 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) emit(channel, cut.start, 0, channel.value(Math.max(0, cut.start - 1e-3)), channel.value(cut.start), 'linear');\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\tconst together = active.every((x) => x.start === a && x.end === b && channel.exact(x) && JSON.stringify(x.ease) === JSON.stringify(first.ease));\n\t\t\tconst curve = together ? flairCurveFor(first.ease, curves) : 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 = channel.value(b);\n\t\t\t\tif (!same(from, to) || channel.kind === 'view') emit(channel, a, b - a, from, to, ease);\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\tanimate.sort((x, y) => (x.delay ?? 0) - (y.delay ?? 0));\n\n\t// The SVG: the artwork at rest, live effects drawn as plain paths so shapes can be tweened.\n\tlet svg = vectorDocumentToSvg({ ...scene.artwork, nodes: expandVectorAppearances(scene.artwork.nodes) }, { pretty: false, precision });\n\tconst lastChange = animate.reduce((m, a) => Math.max(m, (a.delay ?? 0) + (a.ms ?? 0)), 0);\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)] };\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\ttrigger?: FlairVectorEffect['trigger'];\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...(options.trigger ? { trigger: options.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\tloop: (scene.loop ?? 'none') !== 'none',\n\t\tpresets: scene.presets ?? []\n\t};\n}\n","import 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 = {}): string {\n\t\treturn motionFrameToSvg(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 } from './compile.js';\nimport type { AnimationEditorController } from './controller.js';\nimport { MOTION_EDIT_OPS, type MotionEdit, type MotionEditResult } from './edit.js';\nimport { motionIssueLine, type MotionIssue } from './issues.js';\nimport { MOTION_COMMAND_TYPES, MOTION_DIRECTIONS, MOTION_ENTER_STYLES, MOTION_EXIT_STYLES, 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(', ')}) or { \"type\": \"cubic-bezier\", \"x1\", \"y1\", \"x2\", \"y2\" }. 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]\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};\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.', {\n\t\t\tstyle: { type: 'string', enum: [...MOTION_ENTER_STYLES], description: 'fade (default), pop, grow, slide, or draw (outline drawn on, then the fill fades in).' },\n\t\t\tdirection: { type: 'string', enum: [...MOTION_DIRECTIONS], description: 'For slide: direction of travel (default up).' },\n\t\t\tdistance: { type: 'number', description: 'For slide: document units (default 40).' }\n\t\t}),\n\t\tcommand('exit', 'Takes targets out.', {\n\t\t\tstyle: { type: 'string', enum: [...MOTION_EXIT_STYLES], description: 'fade (default), shrink, slide or undraw.' },\n\t\t\tdirection: { type: 'string', enum: [...MOTION_DIRECTIONS], description: 'For slide: direction of travel (default down).' },\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.', { 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.', { 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).', { 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).', { to: { description: 'A factor, or { x, y } factors.', anyOf: [{ type: 'number' }, POINT('Factors per axis.')] } }, ['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\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).' },\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.', { 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, settling.', { amount: { type: 'number', description: 'Document units (default 8).' }, count: { type: 'integer', minimum: 1, description: 'Shakes (default 3).' } }),\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 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') }, ['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') }, ['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};\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\tfps: { type: 'number', minimum: 1, maximum: 120, description: 'Sampling rate for exports (default 30).' },\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'] }, 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: { type: 'integer', minimum: 0, description: 'Index in the shot\\'s run.' }, 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: 'delete_commands', description: 'Like delete_commands.' }, shot: SHOT_ID, commands: { type: 'array', items: { type: 'integer', minimum: 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\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\treturn { index, ...c, start: ct.start, end: ct.end };\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, 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.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.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 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}),\n\t\tannotations: { title: 'Render a frame', ...READ },\n\t\thandler: async ({ time, shot, at = 'end', format = 'svg' }) => {\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\tconst svg = controller.toSvg(t, { pretty: false });\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\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}),\n\t\tannotations: { title: 'Export as Flair vector motion', ...READ },\n\t\thandler: ({ fps, curves }) => controller.toFlairMotion({ ...(fps ? { fps } : {}), ...(curves === undefined ? {} : { curves }) })\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}),\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 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'] }, 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 setSettings: AgentTool = {\n\t\tname: 'set_animation_settings',\n\t\ttitle: 'Change animation settings',\n\t\tdescription: 'Sets the name, description, loop mode, export frame rate 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): …\"). With dry_run it only reports the timing and issues the edits would give.',\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\tconst result = controller.apply(ops, 'Edit animation', { dryRun: dry_run });\n\t\t\treturn outcome(result, 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, checkAnimation, renderFrame, exportFlairMotion, exportFlairEffect, seekAnimation];\n\tconst writes = [setArtworkSvg, insertShots, updateShot, deleteShots, moveShot, addCommands, updateCommand, deleteCommands, 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- 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- morph turns a shape into another node's shape (keep the target hidden); follow moves along a path node; pulse and shake draw the eye.\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).\n2. Plan a few shots, each one idea. Add them with insert_shots, or edit_animation to make several edits as one step (dry_run first when unsure).\n3. check_animation and fix every error and warning; render_animation_frame (shot + \"end\") to look at the result.\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2NO,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;AACD;AACO,IAAM,sBAAmD,CAAC,QAAQ,OAAO,QAAQ,SAAS,MAAM;AAChG,IAAM,qBAAiD,CAAC,QAAQ,UAAU,SAAS,QAAQ;AAC3F,IAAM,oBAAgD,CAAC,MAAM,QAAQ,QAAQ,OAAO;AAqBpF,IAAM,2BAAkG;AAAA,EAC9G,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AAAA,EACP,QAAQ;AACT;AAGO,IAAM,sBAAsB;AAE5B,IAAM,mBAAmB;AAEzB,IAAM,0BAA0B;AAChC,IAAM,oBAA+C,CAAC,KAAK,IAAI;;;AC7Q/D,IAAM,qBAAqB;AAAA,EACjC,YAAY,EAAE,UAAU,QAAQ,SAAS,8BAA8B;AAAA,EACvE,qBAAqB,EAAE,UAAU,SAAS,SAAS,yBAAyB;AAAA,EAC5E,kBAAkB,EAAE,UAAU,SAAS,SAAS,oDAAoD;AAAA,EACpG,gBAAgB,EAAE,UAAU,SAAS,SAAS,2DAA2D;AAAA,EACzG,cAAc,EAAE,UAAU,SAAS,SAAS,kDAAkD;AAAA,EAC9F,iBAAiB,EAAE,UAAU,SAAS,SAAS,mDAAmD;AAAA,EAClG,kBAAkB,EAAE,UAAU,SAAS,SAAS,4DAA4D;AAAA,EAC5G,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M,SAAS,WAAW,KAAK;AAC/B,aAAO,EAAE,QAAQ,GAAI,SAAS,EAAE,MAAM,IAAI,CAAC,EAAG;AAAA,IAC/C;AAAA,EACD;AAEA,QAAM,OAAkB;AAAA,IACvB,MAAM;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA,IACb,aAAa,OAAO,CAAC,CAAC;AAAA,IACtB,aAAa,EAAE,OAAO,0BAA0B,GAAG,MAAM;AAAA,IACzD,SAAS,MAAM;AACd,YAAM,QAAQ,WAAW,SAAS,EAAE;AACpC,YAAM,SAAS,WAAW,KAAK;AAC/B,aAAO,EAAE,QAAQ,GAAI,SAAS,EAAE,MAAM,IAAI,CAAC,EAAG;AAAA,IAC/C;AAAA,EACD;AAEA,QAAM,QAAQ,CAAC,cAAc,SAAS,cAAc,gBAAgB,aAAa,mBAAmB,mBAAmB,aAAa;AACpI,QAAM,SAAS,CAAC,eAAe,aAAa,YAAY,aAAa,UAAU,aAAa,eAAe,gBAAgB,aAAa,aAAa,eAAe,gBAAgB,MAAM,IAAI;AAE9L,SAAO;AAAA,IACN,IAAI,QAAQ,MAAM;AAAA,IAClB,WAAW,QAAQ;AAAA,IACnB,OAAO,MAAO,eAAe,IAAI,QAAQ,CAAC,GAAG,OAAO,GAAG,MAAM;AAAA,IAC7D,WAAW,CAAC,WAAW;AACtB,UAAI,OAAO,eAAe;AAC1B,aAAO,WAAW,UAAU,MAAM;AACjC,cAAM,MAAM,eAAe;AAC3B,YAAI,QAAQ,MAAM;AACjB,iBAAO;AACP,iBAAO;AAAA,QACR;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD;AACD;;;ACvkBO,IAAM,sCAAsC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":["command","command","end","duration","ease","opacity","shotIndex","command","command","TRANSFORM_PROPS","round","command","command"]}
|
|
1
|
+
{"version":3,"sources":["../../src/animation-editor/types.ts","../../src/animation-editor/issues.ts","../../src/animation-editor/parse.ts","../../src/animation-editor/compile.ts","../../src/animation-editor/evaluate.ts","../../src/animation-editor/check.ts","../../src/animation-editor/edit.ts","../../src/animation-editor/flair.ts","../../src/animation-editor/flair-import.ts","../../src/animation-editor/controller.ts","../../src/animation-editor/tools.ts","../../src/animation-editor/instructions.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/** 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/** Wanted length in seconds `[min, max]`; `check` warns outside it. */\n\ttarget?: [number, number];\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/** 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/** 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/** 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}\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 {\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 {\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/** Draws a stroke on (or off) between two fractions of its length. */\nexport interface MotionDrawCommand extends MotionCommandBase {\n\ttype: 'draw';\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\ttype: 'move';\n\tby?: { x: number; y: number };\n\tto?: { x: number; y: number };\n}\n\n/** Turns targets about their centre, by or to an angle in degrees (clockwise). */\nexport interface MotionRotateCommand extends MotionCommandBase {\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\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/** 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\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\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\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\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\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| 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'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_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\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-shape': { severity: 'error', wording: 'A morph names a shape the artwork does not have.' },\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'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_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', 'loop', 'fps', 'steps', 'target', 'controls', 'presets'];\nconst SHOT_KEYS = ['id', 'label', 'camera', 'run', 'hold'];\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 COMMAND_KEYS: Record<string, string[]> = {\n\tenter: [...BASE_KEYS, 'style', 'direction', 'distance', 'scale', 'shape', 'orientation'],\n\texit: [...BASE_KEYS, 'style', 'direction', 'distance'],\n\tdraw: [...BASE_KEYS, 'from', 'to'],\n\tmove: [...BASE_KEYS, 'by', 'to'],\n\trotate: [...BASE_KEYS, 'by', 'to'],\n\tscale: [...BASE_KEYS, 'to', 'geometric'],\n\tfade: [...BASE_KEYS, 'to'],\n\tstyle: [...BASE_KEYS, 'fill', 'stroke', 'strokeWidth'],\n\tmorph: [...BASE_KEYS, 'into'],\n\tfollow: [...BASE_KEYS, 'path', 'rotate', 'from', 'to'],\n\tpulse: [...BASE_KEYS, 'amount', 'count'],\n\tshake: [...BASE_KEYS, 'amount', 'count', 'axis'],\n\tteeter: [...BASE_KEYS, 'angle', 'count'],\n\twave: [...BASE_KEYS, 'amount', 'count'],\n\twiggle: [...BASE_KEYS, 'amount', 'frequency', 'octaves', 'rotate', 'seed'],\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 (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.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\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\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 'morph':\n\t\t\tif (typeof command.into !== 'string' || !command.into) p(`\"into\" must be the id of a 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 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.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.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.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","import { mixColorsOklab } from '../animation/color.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\ttype MotionCamera,\n\ttype MotionCommand,\n\ttype MotionDirection,\n\ttype MotionIrisShape,\n\ttype MotionRect,\n\ttype MotionSplitOrientation,\n\ttype MotionScene\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/** 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}\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/** 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 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/** 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.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\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\tconst start = t;\n\t\tlet cursor = start;\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);\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));\n\t\t\tconst targets = command.type === 'wait' ? [] : command.targets;\n\t\t\tconst durations = command.type === 'wait' ? [command.duration] : targets.map((id) => motionCommandDuration(command, scene, id));\n\t\t\tconst stagger = command.type === 'wait' ? 0 : (command.stagger ?? 0);\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);\n\t\tshots.push({ id: shot.id, index, ...(shot.label ? { label: shot.label } : {}), start, commandsStart, commandsEnd: runEnd, end });\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 = 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\tcommand.targets.forEach((target, k) => {\n\t\t\tconst entry = nodes.get(target);\n\t\t\tif (!entry) return;\n\t\t\tconst start = timing.start + k * (command.stagger ?? 0);\n\t\t\tconst cycle = motionCycleDuration(command, scene, target);\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\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\tseg('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\tseg('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 drawn = tracks.has(motionTrackKey(node, 'drawEnd'));\n\t\t\t\tseg('drawEnd', command.to ?? 1, ease ?? MOTION_EASE_IN_OUT, start, end, command.from !== undefined ? { from: command.from } : drawn ? {} : { from: 0 });\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\tseg('x', num('x') + dx, e);\n\t\t\t\tseg('y', num('y') + dy, e);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'rotate':\n\t\t\t\tseg('rotation', command.to ?? num('rotation') + (command.by ?? 0), ease ?? MOTION_EASE_IN_OUT);\n\t\t\t\tbreak;\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 geometric = command.geometric ? { geometric: true } : {};\n\t\t\t\tseg('scaleX', to.x, ease ?? MOTION_EASE_IN_OUT, start, end, geometric);\n\t\t\t\tseg('scaleY', to.y, ease ?? MOTION_EASE_IN_OUT, start, end, geometric);\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 '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\t\tconst behavior: MotionBehavior = { type: 'pulse', count: command.count ?? 1 };\n\t\t\t\tconst k = 1 + (command.amount ?? 0.15);\n\t\t\t\tseg('scaleX', num('scaleX') * k, ease ?? 'linear', start, end, { behavior });\n\t\t\t\tseg('scaleY', num('scaleY') * k, ease ?? 'linear', start, end, { behavior });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'shake': {\n\t\t\t\tconst p = command.axis === 'vertical' ? 'y' : 'x';\n\t\t\t\tseg(p, num(p) + (command.amount ?? 8), ease ?? 'linear', start, end, { behavior: { type: 'oscillate', count: command.count ?? 3, decay: 1 } });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'teeter':\n\t\t\t\tseg('rotation', num('rotation') + (command.angle ?? 8), ease ?? 'linear', start, end, { behavior: { type: 'oscillate', count: command.count ?? 3, decay: 1 } });\n\t\t\t\tbreak;\n\t\t\tcase 'wave':\n\t\t\t\tseg('y', num('y') - (command.amount ?? 6), ease ?? 'linear', start, end, { behavior: { type: 'oscillate', count: command.count ?? 2 } });\n\t\t\t\tbreak;\n\t\t\tcase 'wiggle': {\n\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\tconst amount = command.amount ?? 6;\n\t\t\t\tseg('x', num('x') + amount, ease ?? 'linear', start, end, { behavior, index: 0 });\n\t\t\t\tseg('y', num('y') + amount, ease ?? 'linear', start, end, { behavior, index: 1 });\n\t\t\t\tif (command.rotate) seg('rotation', num('rotation') + command.rotate, ease ?? 'linear', start, end, { behavior, index: 2 });\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, motionTrackKey, 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\tconst read = (p: MotionProperty, rest: number) => {\n\t\tconst v = trackValue(timeline.tracks.get(motionTrackKey(entry.node.id, p)), time, raw);\n\t\treturn typeof v === 'number' ? v : rest;\n\t};\n\tif (!TRANSFORM_PROPS.some((p) => (follow || p !== 'follow') && timeline.tracks.has(motionTrackKey(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 { resolveEasing, springSettleMs } from '../animation/easing.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 type { MotionCommand, 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\treturn num('drawEnd', 1) > 0.01 || (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\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// Two segments changing the same property of a node at the same time.\n\tfor (const [key, track] of timeline.tracks) {\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.`, { 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 or add shots.`, { 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 { commandShapeProblems, motionSceneShapeProblems, shotShapeProblems } from './parse.js';\nimport type { 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']; fps?: number; steps?: number | 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')[] }\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: 'set_artwork'; artwork: VectorDocument }\n\t| { op: 'set_controls'; controls: MotionControl[]; presets?: MotionPreset[] }\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'set_artwork',\n\t'set_controls',\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.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\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 '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 '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/** 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","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, motionTrackKey, segmentValue, trackValue, type MotionProperty, type MotionSegment } from './compile.js';\nimport { motionClipAttrs, motionFollowRoute, motionFrameAt, motionNodeClips, motionNodeOffset } from './evaluate.js';\nimport type { MotionScene } 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\tpresets?: { name: string; values: Record<string, string> }[];\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}\n\nexport interface FlairExportOptions {\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\tconst transformSegments = TRANSFORM_PROPS.flatMap((p) => (followed && p === 'follow' ? [] : track(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\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\tconst lastChange = animate.reduce((m, a) => Math.max(m, (a.delay ?? 0) + (a.ms ?? 0)), 0);\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)] };\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\ttrigger?: FlairVectorEffect['trigger'];\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...(options.trigger ? { trigger: options.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\tloop: (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}\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 step = Math.max(0, Math.floor(anim.step ?? 0));\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 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 });\n\tconst names = new Set((result.scene.controls ?? []).map((c) => c.name));\n\tconst presets = (effect.presets ?? []).map((p) => ({ name: p.name, values: Object.fromEntries(Object.entries(p.values).filter(([k]) => names.has(k))) })).filter((p) => Object.keys(p.values).length);\n\tconst scene: MotionScene = { ...result.scene, ...(effect.description ? { description: effect.description } : {}), ...(presets.length ? { presets } : {}) };\n\tconst notes = [...result.notes];\n\tif (effect.trigger) notes.push(`The effect plays on ${effect.trigger}; scenes play through, so the trigger is not kept (pass it back to toFlairVectorEffect).`);\n\treturn { scene, notes, issues: checkMotionScene(scene) };\n}\n","import 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 = {}): string {\n\t\treturn motionFrameToSvg(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 } from './compile.js';\nimport { fromFlairSvgMotion, fromFlairVectorEffect, type FlairImportResult } from './flair-import.js';\nimport type { AnimationEditorController } from './controller.js';\nimport { MOTION_EDIT_OPS, type MotionEdit, type MotionEditResult } from './edit.js';\nimport { motionIssueLine, type MotionIssue } from './issues.js';\nimport { MOTION_COMMAND_TYPES, MOTION_DIRECTIONS, MOTION_ENTER_STYLES, MOTION_EXIT_STYLES, MOTION_IRIS_SHAPES, MOTION_REPEAT_MODES, MOTION_SPLIT_ORIENTATIONS, motionFlairPrimitive, 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 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.', {\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.', {\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.', { 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.', { 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).', { 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).', { 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\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.', { 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.', {\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.', { 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).', { 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.', {\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};\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\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\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'] }, 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: { type: 'integer', minimum: 0, description: 'Index in the shot\\'s run.' }, 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: 'delete_commands', description: 'Like delete_commands.' }, shot: SHOT_ID, commands: { type: 'array', items: { type: 'integer', minimum: 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\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.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.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 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}),\n\t\tannotations: { title: 'Render a frame', ...READ },\n\t\thandler: async ({ time, shot, at = 'end', format = 'svg' }) => {\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\tconst svg = controller.toSvg(t, { pretty: false });\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 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 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 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'] }, 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 setSettings: AgentTool = {\n\t\tname: 'set_animation_settings',\n\t\ttitle: 'Change animation settings',\n\t\tdescription: 'Sets the name, description, loop mode, export frame rate, stepped time 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): …\"). With dry_run it only reports the timing and issues the edits would give.',\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\tconst result = controller.apply(ops, 'Edit animation', { dryRun: dry_run });\n\t\t\treturn outcome(result, 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, checkAnimation, renderFrame, exportFlairMotion, exportFlairEffect, seekAnimation];\n\tconst writes = [setArtworkSvg, importFlairEffect, insertShots, updateShot, deleteShots, moveShot, addCommands, updateCommand, deleteCommands, 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- 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); 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- 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- \"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, or edit_animation to make several edits as one step (dry_run first when unsure).\n3. check_animation and fix every error and warning; render_animation_frame (shot + \"end\") to look at the result.\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+TO,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;AACD;AACO,IAAM,sBAAmD,CAAC,QAAQ,OAAO,QAAQ,SA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AAAA;AAAA;","names":["command","command","command","end","duration","ease","opacity","shotIndex","command","command","TRANSFORM_PROPS","round","command","command","command"]}
|