@pixerate/editor 0.57.0 → 0.58.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.
@@ -17,7 +17,7 @@ import {
17
17
  vectorDocumentToSvg,
18
18
  vectorNodeBounds,
19
19
  vectorPathWorldBezier
20
- } from "../chunk-NONDTTH7.js";
20
+ } from "../chunk-PYMV7HLI.js";
21
21
  import {
22
22
  bezierPathLength,
23
23
  bezierPathPointAtLength,
@@ -27,6 +27,10 @@ import {
27
27
  import {
28
28
  HistoryManager
29
29
  } from "../chunk-QVZZGT4X.js";
30
+ import {
31
+ behaviorProgress,
32
+ motionSeedFromId
33
+ } from "../chunk-3NYXDBBW.js";
30
34
  import {
31
35
  AnimationPlayer
32
36
  } from "../chunk-SHOVAHUB.js";
@@ -59,11 +63,17 @@ var MOTION_COMMAND_TYPES = [
59
63
  "follow",
60
64
  "pulse",
61
65
  "shake",
66
+ "teeter",
67
+ "wave",
68
+ "wiggle",
69
+ "color-pulse",
62
70
  "effect",
63
71
  "wait"
64
72
  ];
65
- var MOTION_ENTER_STYLES = ["fade", "pop", "grow", "slide", "draw"];
66
- var MOTION_EXIT_STYLES = ["fade", "shrink", "slide", "undraw"];
73
+ var MOTION_ENTER_STYLES = ["fade", "pop", "grow", "slide", "draw", "zoom", "rise", "wipe", "iris", "split"];
74
+ var MOTION_EXIT_STYLES = ["fade", "shrink", "slide", "undraw", "wipe"];
75
+ var MOTION_IRIS_SHAPES = ["circle", "box"];
76
+ var MOTION_SPLIT_ORIENTATIONS = ["horizontal", "vertical"];
67
77
  var MOTION_DIRECTIONS = ["up", "down", "left", "right"];
68
78
  var MOTION_DEFAULT_DURATIONS = {
69
79
  enter: 600,
@@ -77,12 +87,37 @@ var MOTION_DEFAULT_DURATIONS = {
77
87
  follow: 1400,
78
88
  pulse: 600,
79
89
  shake: 500,
90
+ teeter: 600,
91
+ wave: 1e3,
92
+ wiggle: 1500,
93
+ "color-pulse": 600,
80
94
  effect: 900
81
95
  };
82
96
  var MOTION_DEFAULT_HOLD = 600;
83
97
  var MOTION_CAMERA_MS = 1e3;
84
98
  var MOTION_DRAW_MS_PER_UNIT = 1.5;
85
99
  var MOTION_DRAW_RANGE = [500, 2500];
100
+ function motionFlairPrimitive(command2) {
101
+ switch (command2.type) {
102
+ case "enter":
103
+ return `entrance.${command2.style ?? "fade"}`;
104
+ case "exit":
105
+ return `exit.${command2.style ?? "fade"}`;
106
+ case "pulse":
107
+ case "shake":
108
+ case "teeter":
109
+ case "wave":
110
+ case "wiggle":
111
+ case "color-pulse":
112
+ return `emphasis.${command2.type}`;
113
+ case "rotate":
114
+ return command2.by !== void 0 ? "emphasis.spin" : void 0;
115
+ case "follow":
116
+ return "path.follow";
117
+ default:
118
+ return void 0;
119
+ }
120
+ }
86
121
 
87
122
  // src/animation-editor/issues.ts
88
123
  var MOTION_ISSUE_CODES = {
@@ -91,13 +126,14 @@ var MOTION_ISSUE_CODES = {
91
126
  "unknown-target": { severity: "error", wording: "A command names a node the artwork does not have." },
92
127
  "unknown-path": { severity: "error", wording: "A follow command names a path the artwork does not have." },
93
128
  "not-a-path": { severity: "error", wording: "A follow path must be a path node, not a group." },
129
+ "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." },
94
130
  "unknown-shape": { severity: "error", wording: "A morph names a shape the artwork does not have." },
95
131
  "unknown-effect": { severity: "error", wording: "An effect command names an effect the node does not have." },
96
132
  "unknown-effect-param": { severity: "error", wording: "An effect command names a parameter that is not a number of that effect." },
97
133
  "unknown-frame": { severity: "error", wording: "A camera frames a node the artwork does not have." },
98
134
  "invalid-camera": { severity: "error", wording: "A camera rectangle has no area." },
99
135
  "invalid-color": { severity: "error", wording: "A colour cannot be read." },
100
- "paint-not-color": { severity: "warning", wording: "A style command recolours a gradient or empty paint, which only switches at the end." },
136
+ "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." },
101
137
  "overlap": { severity: "warning", wording: "Two commands change the same property of a node at the same time; the later one wins." },
102
138
  "enter-visible": { severity: "warning", wording: "A node enters while it is already showing, so it blinks out first." },
103
139
  "exit-hidden": { severity: "warning", wording: "A node exits or animates while it is hidden." },
@@ -165,7 +201,7 @@ var SHOT_KEYS = ["id", "label", "camera", "run", "hold"];
165
201
  var CAMERA_KEYS = ["x", "y", "width", "height", "frame", "padding", "ease", "ms"];
166
202
  var BASE_KEYS = ["type", "targets", "duration", "delay", "stagger", "with", "ease", "note"];
167
203
  var COMMAND_KEYS = {
168
- enter: [...BASE_KEYS, "style", "direction", "distance"],
204
+ enter: [...BASE_KEYS, "style", "direction", "distance", "scale", "shape", "orientation"],
169
205
  exit: [...BASE_KEYS, "style", "direction", "distance"],
170
206
  draw: [...BASE_KEYS, "from", "to"],
171
207
  move: [...BASE_KEYS, "by", "to"],
@@ -176,7 +212,11 @@ var COMMAND_KEYS = {
176
212
  morph: [...BASE_KEYS, "into"],
177
213
  follow: [...BASE_KEYS, "path", "rotate", "from", "to"],
178
214
  pulse: [...BASE_KEYS, "amount", "count"],
179
- shake: [...BASE_KEYS, "amount", "count"],
215
+ shake: [...BASE_KEYS, "amount", "count", "axis"],
216
+ teeter: [...BASE_KEYS, "angle", "count"],
217
+ wave: [...BASE_KEYS, "amount", "count"],
218
+ wiggle: [...BASE_KEYS, "amount", "frequency", "octaves", "rotate", "seed"],
219
+ "color-pulse": [...BASE_KEYS, "color", "paint", "count"],
180
220
  effect: [...BASE_KEYS, "effect", "param", "to"],
181
221
  wait: ["type", "duration", "with", "note"]
182
222
  };
@@ -223,6 +263,9 @@ function commandShapeProblems(command2, where) {
223
263
  p(`"style" must be one of ${styles.join(", ")}${typeof command2.style === "string" ? ` (got ${namedWithSuggestion(command2.style, styles)})` : ""}.`);
224
264
  if (command2.direction !== void 0 && !MOTION_DIRECTIONS.includes(command2.direction)) p(`"direction" must be one of ${MOTION_DIRECTIONS.join(", ")}.`);
225
265
  optionalNumber("distance");
266
+ if (command2.scale !== void 0 && !(isNum(command2.scale) && command2.scale >= 0)) p(`"scale" must be a number \u2265 0 (the starting scale for pop and zoom).`);
267
+ if (command2.shape !== void 0 && !MOTION_IRIS_SHAPES.includes(command2.shape)) p(`"shape" must be one of ${MOTION_IRIS_SHAPES.join(", ")} (the opening of an iris).`);
268
+ if (command2.orientation !== void 0 && !MOTION_SPLIT_ORIENTATIONS.includes(command2.orientation)) p(`"orientation" must be one of ${MOTION_SPLIT_ORIENTATIONS.join(", ")} (the line a split opens from).`);
226
269
  break;
227
270
  }
228
271
  case "draw":
@@ -264,8 +307,22 @@ function commandShapeProblems(command2, where) {
264
307
  break;
265
308
  case "pulse":
266
309
  case "shake":
310
+ case "teeter":
311
+ case "wave":
312
+ case "color-pulse":
267
313
  optionalNumber("amount");
314
+ optionalNumber("angle");
268
315
  if (command2.count !== void 0 && !(Number.isInteger(command2.count) && command2.count >= 1)) p(`"count" must be a whole number \u2265 1.`);
316
+ if (command2.axis !== void 0 && command2.axis !== "horizontal" && command2.axis !== "vertical") p(`"axis" must be "horizontal" or "vertical".`);
317
+ if (command2.color !== void 0 && typeof command2.color !== "string") p(`"color" must be a CSS colour.`);
318
+ if (command2.paint !== void 0 && command2.paint !== "fill" && command2.paint !== "stroke") p(`"paint" must be "fill" or "stroke".`);
319
+ break;
320
+ case "wiggle":
321
+ optionalNumber("amount");
322
+ optionalNumber("rotate");
323
+ if (command2.frequency !== void 0 && !(isNum(command2.frequency) && command2.frequency > 0)) p(`"frequency" must be a number of Hz > 0.`);
324
+ if (command2.octaves !== void 0 && !(Number.isInteger(command2.octaves) && command2.octaves >= 1 && command2.octaves <= 8)) p(`"octaves" must be a whole number from 1 to 8.`);
325
+ if (command2.seed !== void 0 && !(Number.isInteger(command2.seed) && command2.seed >= 0)) p(`"seed" must be a whole number \u2265 0.`);
269
326
  break;
270
327
  case "effect":
271
328
  if (typeof command2.effect !== "string" || !command2.effect) p(`"effect" must be the id of one of the node's effects.`);
@@ -358,7 +415,7 @@ function indexMotionNodes(nodes) {
358
415
  const local = vectorNodeBounds(node);
359
416
  const bounds = vectorNodeBounds(node, parentWorld);
360
417
  const center = local ? { x: local.x + local.width / 2, y: local.y + local.height / 2 } : { x: 0, y: 0 };
361
- if (!out.has(node.id)) out.set(node.id, { node, ancestors, parentWorld, center, bounds });
418
+ if (!out.has(node.id)) out.set(node.id, { node, ancestors, parentWorld, center, bounds, box: local });
362
419
  if (node.type === "group") walk(node.children, multiplyMatrices(nodeMatrix(node), parentWorld), [...ancestors, node.id]);
363
420
  }
364
421
  };
@@ -375,6 +432,56 @@ function firstPaint(node, key) {
375
432
  }
376
433
  return void 0;
377
434
  }
435
+ function strokeReach(node) {
436
+ let reach = 0;
437
+ for (const p of node.type === "path" ? [node] : collectPathNodes(node)) {
438
+ if (p.stroke == null || p.stroke === "none") continue;
439
+ const width = p.strokeWidth ?? 1;
440
+ reach = Math.max(reach, p.strokeAlign === "outside" ? width : p.strokeAlign === "inside" ? 0 : width / 2);
441
+ }
442
+ return reach;
443
+ }
444
+ function motionRevealPadding(entry) {
445
+ const box = entry.box;
446
+ if (!box || !(box.width > 0) || !(box.height > 0)) return null;
447
+ const s = strokeReach(entry.node);
448
+ return [Math.min(1, s / box.width + 0.02), Math.min(1, s / box.height + 0.02)];
449
+ }
450
+ var clipRound = (n) => Math.round(n * 1e4) / 1e4 || 0;
451
+ function revealFull(property, [px, py]) {
452
+ return (property === "clipRect" ? [-px, -py, 1 + 2 * px, 1 + 2 * py] : [0.5, 0.5, Math.hypot(0.5 + px, 0.5 + py)]).map(clipRound);
453
+ }
454
+ var OPPOSITE = { up: "down", down: "up", left: "right", right: "left" };
455
+ function motionRevealClip(entry, reveal) {
456
+ const pad = motionRevealPadding(entry);
457
+ if (!pad) return null;
458
+ const [px, py] = pad;
459
+ const [w, h] = [1 + 2 * px, 1 + 2 * py];
460
+ const rect = (from, to) => ({ property: "clipRect", from: from.map(clipRound), to: to.map(clipRound) });
461
+ if (reveal.style === "iris") {
462
+ if (reveal.shape === "box") return rect([0.5, 0.5, 0, 0], [-px, -py, w, h]);
463
+ return { property: "clipCircle", from: [0.5, 0.5, 0], to: revealFull("clipCircle", pad) };
464
+ }
465
+ if (reveal.style === "split") {
466
+ if (reveal.orientation === "vertical") return rect([0.5, -py, 0, h], [-px, -py, w, h]);
467
+ return rect([-px, 0.5, w, 0], [-px, -py, w, h]);
468
+ }
469
+ const direction = reveal.direction ?? "right";
470
+ if (reveal.hide) {
471
+ const shown = motionRevealClip(entry, { style: "wipe", direction: OPPOSITE[direction] });
472
+ return { ...shown, from: shown.to, to: shown.from };
473
+ }
474
+ switch (direction) {
475
+ case "right":
476
+ return rect([-px, -py, 0, h], [-px, -py, w, h]);
477
+ case "left":
478
+ return rect([1 + px, -py, 0, h], [-px, -py, w, h]);
479
+ case "down":
480
+ return rect([-px, -py, w, 0], [-px, -py, w, h]);
481
+ case "up":
482
+ return rect([-px, 1 + py, w, 0], [-px, -py, w, h]);
483
+ }
484
+ }
378
485
  function motionRestValue(entry, property, artwork) {
379
486
  const node = entry?.node;
380
487
  switch (property) {
@@ -402,6 +509,11 @@ function motionRestValue(entry, property, artwork) {
402
509
  }
403
510
  case "shape":
404
511
  return node?.id ?? "";
512
+ case "clipRect":
513
+ case "clipCircle": {
514
+ const pad = entry && motionRevealPadding(entry);
515
+ return pad ? revealFull(property, pad) : [];
516
+ }
405
517
  case "camera":
406
518
  return [0, 0, artwork.width, artwork.height];
407
519
  }
@@ -424,15 +536,13 @@ function interpolateMotionValue(from, to, u) {
424
536
  function segmentProgress(segment, time) {
425
537
  const span = segment.end - segment.start;
426
538
  const u = span <= 0 ? 1 : Math.min(1, Math.max(0, (time - segment.start) / span));
427
- return { u, eased: segment.wave ? u : evaluateEasing(segment.ease, u, span) };
539
+ return { u, eased: evaluateEasing(segment.ease, u, span) };
428
540
  }
429
- function segmentValue(segment, time) {
430
- const { u, eased } = segmentProgress(segment, time);
431
- const v = interpolateMotionValue(segment.from, segment.to, eased);
432
- if (!segment.wave || typeof v !== "number") return v;
433
- const { kind, amount, count } = segment.wave;
434
- if (kind === "pulse") return v * (1 + amount * Math.sin(Math.PI * u * count) ** 2);
435
- return v + amount * Math.sin(2 * Math.PI * u * count) * (1 - u);
541
+ function segmentValue(segment, time, raw = false) {
542
+ const { eased } = segmentProgress(segment, time);
543
+ if (!segment.behavior || raw) return interpolateMotionValue(segment.from, segment.to, eased);
544
+ const p = behaviorProgress(segment.behavior, eased, segment.index ?? 0, segment.end - segment.start);
545
+ return typeof segment.from === "string" ? interpolateMotionValue(segment.from, segment.to, Math.min(1, Math.max(0, p))) : interpolateMotionValue(segment.from, segment.to, p);
436
546
  }
437
547
  function activeSegment(track, time) {
438
548
  if (!track?.length) return void 0;
@@ -440,10 +550,10 @@ function activeSegment(track, time) {
440
550
  for (const s of track) if (s.start <= time && (!found || s.start >= found.start)) found = s;
441
551
  return found;
442
552
  }
443
- function trackValue(track, time) {
553
+ function trackValue(track, time, raw = false) {
444
554
  if (!track?.length) return void 0;
445
555
  const s = activeSegment(track, time);
446
- if (s) return segmentValue(s, time);
556
+ if (s) return segmentValue(s, time, raw);
447
557
  let first = track[0];
448
558
  for (const t of track) if (t.start < first.start) first = t;
449
559
  return first.from;
@@ -582,15 +692,27 @@ function compileMotionScene(scene) {
582
692
  case "enter": {
583
693
  const style = command2.style ?? "fade";
584
694
  const opacity = rest("opacity");
695
+ const reveal = style === "wipe" ? motionRevealClip(entry, { style, direction: command2.direction }) : style === "iris" ? motionRevealClip(entry, { style, shape: command2.shape }) : style === "split" ? motionRevealClip(entry, { style, orientation: command2.orientation }) : null;
696
+ for (const p of ["clipRect", "clipCircle"]) if (p !== reveal?.property && tracks.has(motionTrackKey(node, p))) seg(p, rest(p), "linear", start, start);
697
+ if (reveal) {
698
+ seg("opacity", opacity, "linear", start, start);
699
+ seg(reveal.property, reveal.to, ease ?? MOTION_EASE_OUT, start, end, { from: reveal.from });
700
+ break;
701
+ }
585
702
  if (style === "draw") {
586
703
  seg("drawEnd", 1, ease ?? MOTION_EASE_IN_OUT, start, start + duration2 * 0.75, { from: 0 });
587
704
  seg("fillOpacity", 1, MOTION_EASE_OUT, start + duration2 * 0.6, end, { from: 0 });
588
705
  break;
589
706
  }
590
- if (style === "pop") {
591
- seg("opacity", opacity, MOTION_EASE_OUT, start, start + duration2 * 0.4, { from: 0 });
592
- seg("scaleX", 1, ease ?? "ease-out-back", start, end, { from: 0.5 });
593
- seg("scaleY", 1, ease ?? "ease-out-back", start, end, { from: 0.5 });
707
+ if (style === "pop" || style === "zoom") {
708
+ const from = command2.scale ?? (style === "pop" ? 0.5 : 1.6);
709
+ seg("opacity", opacity, MOTION_EASE_OUT, start, start + duration2 * (style === "pop" ? 0.4 : 0.5), { from: 0 });
710
+ seg("scaleX", 1, ease ?? (style === "pop" ? "ease-out-back" : MOTION_EASE_OUT), start, end, { from });
711
+ seg("scaleY", 1, ease ?? (style === "pop" ? "ease-out-back" : MOTION_EASE_OUT), start, end, { from });
712
+ } else if (style === "rise") {
713
+ const y = num("y");
714
+ seg("opacity", opacity, MOTION_EASE_OUT, start, start + duration2 * 0.5, { from: 0 });
715
+ seg("y", y, ease ?? "ease-out-back", start, end, { from: y + (command2.distance ?? 20) });
594
716
  } else if (style === "grow") {
595
717
  seg("opacity", opacity, MOTION_EASE_OUT, start, start + duration2 * 0.3, { from: 0 });
596
718
  seg("scaleX", 1, ease ?? MOTION_EASE_OUT, start, end, { from: 0 });
@@ -608,7 +730,9 @@ function compileMotionScene(scene) {
608
730
  }
609
731
  case "exit": {
610
732
  const style = command2.style ?? "fade";
611
- if (style === "undraw") {
733
+ const wipe = style === "wipe" ? motionRevealClip(entry, { style, direction: command2.direction, hide: true }) : null;
734
+ if (wipe) seg(wipe.property, wipe.to, ease ?? "ease-in", start, end, { from: wipe.from });
735
+ else if (style === "undraw") {
612
736
  seg("fillOpacity", 0, "ease-in", start, start + duration2 * 0.4);
613
737
  seg("drawEnd", 0, ease ?? MOTION_EASE_IN_OUT);
614
738
  } else if (style === "shrink") {
@@ -624,13 +748,11 @@ function compileMotionScene(scene) {
624
748
  } else seg("opacity", 0, ease ?? "ease-in");
625
749
  break;
626
750
  }
627
- case "draw":
628
- {
629
- const drawn = tracks.has(motionTrackKey(node, "drawEnd"));
630
- seg("drawEnd", command2.to ?? 1, ease ?? MOTION_EASE_IN_OUT, start, end, command2.from !== void 0 ? { from: command2.from } : drawn ? {} : { from: 0 });
631
- break;
632
- }
751
+ case "draw": {
752
+ const drawn = tracks.has(motionTrackKey(node, "drawEnd"));
753
+ seg("drawEnd", command2.to ?? 1, ease ?? MOTION_EASE_IN_OUT, start, end, command2.from !== void 0 ? { from: command2.from } : drawn ? {} : { from: 0 });
633
754
  break;
755
+ }
634
756
  case "move": {
635
757
  const e = ease ?? MOTION_EASE_IN_OUT;
636
758
  let dx = command2.by?.x ?? 0;
@@ -668,14 +790,35 @@ function compileMotionScene(scene) {
668
790
  case "follow":
669
791
  seg("follow", command2.to ?? 1, ease ?? MOTION_EASE_IN_OUT, start, end, { from: command2.from ?? 0, path: command2.path, rotate: command2.rotate ?? false });
670
792
  break;
793
+ // Emphasis: a change toward a peak that a behaviour swings round (as Flair's primitives do).
671
794
  case "pulse": {
672
- const wave = { kind: "pulse", amount: command2.amount ?? 0.15, count: command2.count ?? 1 };
673
- seg("scaleX", num("scaleX"), "linear", start, end, { wave });
674
- seg("scaleY", num("scaleY"), "linear", start, end, { wave });
795
+ const behavior = { type: "pulse", count: command2.count ?? 1 };
796
+ const k = 1 + (command2.amount ?? 0.15);
797
+ seg("scaleX", num("scaleX") * k, ease ?? "linear", start, end, { behavior });
798
+ seg("scaleY", num("scaleY") * k, ease ?? "linear", start, end, { behavior });
675
799
  break;
676
800
  }
677
- case "shake":
678
- seg("x", num("x"), "linear", start, end, { wave: { kind: "shake", amount: command2.amount ?? 8, count: command2.count ?? 3 } });
801
+ case "shake": {
802
+ const p = command2.axis === "vertical" ? "y" : "x";
803
+ seg(p, num(p) + (command2.amount ?? 8), ease ?? "linear", start, end, { behavior: { type: "oscillate", count: command2.count ?? 3, decay: 1 } });
804
+ break;
805
+ }
806
+ case "teeter":
807
+ seg("rotation", num("rotation") + (command2.angle ?? 8), ease ?? "linear", start, end, { behavior: { type: "oscillate", count: command2.count ?? 3, decay: 1 } });
808
+ break;
809
+ case "wave":
810
+ seg("y", num("y") - (command2.amount ?? 6), ease ?? "linear", start, end, { behavior: { type: "oscillate", count: command2.count ?? 2 } });
811
+ break;
812
+ case "wiggle": {
813
+ const behavior = { type: "wriggle", frequency: command2.frequency ?? 3, octaves: command2.octaves ?? 2, seed: command2.seed || motionSeedFromId(node) };
814
+ const amount = command2.amount ?? 6;
815
+ seg("x", num("x") + amount, ease ?? "linear", start, end, { behavior, index: 0 });
816
+ seg("y", num("y") + amount, ease ?? "linear", start, end, { behavior, index: 1 });
817
+ if (command2.rotate) seg("rotation", num("rotation") + command2.rotate, ease ?? "linear", start, end, { behavior, index: 2 });
818
+ break;
819
+ }
820
+ case "color-pulse":
821
+ seg(command2.paint ?? "fill", command2.color ?? "#f59e0b", ease ?? "linear", start, end, { behavior: { type: "pulse", count: command2.count ?? 1 } });
679
822
  break;
680
823
  case "effect":
681
824
  seg(`effect:${command2.effect}:${command2.param}`, command2.to, ease ?? MOTION_EASE_IN_OUT);
@@ -757,44 +900,53 @@ function shapeAt(entry, timeline, nodes, time) {
757
900
  if (u >= 1) return b === entry ? null : shapeIn(entry, b);
758
901
  return morphBetween(shapeIn(entry, a), shapeIn(entry, b)).at(u);
759
902
  }
903
+ function motionFollowRoute(entry, path) {
904
+ if (!path || path.node.type !== "path") return null;
905
+ try {
906
+ return transformBezierPath(vectorPathWorldBezier(path.node, path.parentWorld, { effects: false }), invertMatrix(entry.parentWorld));
907
+ } catch {
908
+ return null;
909
+ }
910
+ }
760
911
  function followAt(entry, timeline, nodes, time) {
761
912
  const track = timeline.tracks.get(motionTrackKey(entry.node.id, "follow"));
762
913
  const s = activeSegment(track, time) ?? track?.[0];
763
914
  if (!s?.path) return null;
764
- const path = nodes.get(s.path);
765
- if (!path || path.node.type !== "path") return null;
915
+ const route = motionFollowRoute(entry, nodes.get(s.path));
766
916
  const progress = Number(trackValue(track, time));
767
- if (!(progress >= 0)) return null;
917
+ if (!route || !(progress >= 0)) return null;
768
918
  try {
769
- const bezier = vectorPathWorldBezier(path.node, path.parentWorld, { effects: false });
770
- const at = bezierPathPointAtLength(bezier, Math.min(1, Math.max(0, progress)) * bezierPathLength(bezier));
919
+ const at = bezierPathPointAtLength(route, Math.min(1, Math.max(0, progress)) * bezierPathLength(route));
771
920
  if (!at) return null;
772
- const p = applyMatrix(invertMatrix(entry.parentWorld), { x: at.point[0], y: at.point[1] });
773
- return { x: p.x, y: p.y, angle: s.rotate ? at.angle * 180 / Math.PI : 0 };
921
+ return { x: at.point[0], y: at.point[1], angle: s.rotate ? at.angle * 180 / Math.PI : 0 };
774
922
  } catch {
775
923
  return null;
776
924
  }
777
925
  }
778
- function motionNodeOffset(entry, timeline, time, nodes = indexMotionNodes([entry.node])) {
926
+ function motionNodeOffset(entry, timeline, time, nodes = indexMotionNodes([entry.node]), raw = false, follow = true) {
779
927
  const read = (p, rest) => {
780
- const v = trackValue(timeline.tracks.get(motionTrackKey(entry.node.id, p)), time);
928
+ const v = trackValue(timeline.tracks.get(motionTrackKey(entry.node.id, p)), time, raw);
781
929
  return typeof v === "number" ? v : rest;
782
930
  };
783
- if (!TRANSFORM_PROPS.some((p) => timeline.tracks.has(motionTrackKey(entry.node.id, p)))) return null;
784
- let dx = read("x", 0);
785
- let dy = read("y", 0);
786
- let rotation = read("rotation", 0);
931
+ if (!TRANSFORM_PROPS.some((p) => (follow || p !== "follow") && timeline.tracks.has(motionTrackKey(entry.node.id, p)))) return null;
932
+ const dx = read("x", 0);
933
+ const dy = read("y", 0);
934
+ const rotation = read("rotation", 0);
787
935
  const scaleX = read("scaleX", 1);
788
936
  const scaleY = read("scaleY", 1);
789
- const follow = followAt(entry, timeline, nodes, time);
790
- if (follow) {
791
- dx += follow.x - entry.center.x;
792
- dy += follow.y - entry.center.y;
793
- rotation += follow.angle;
794
- }
795
937
  const c = entry.center;
796
- const matrix = multiplyMatrices(multiplyMatrices(scaleMatrix(scaleX, scaleY, c), rotateMatrix(rotation, c)), translateMatrix(dx, dy));
797
- return { matrix, dx, dy, rotation, scaleX, scaleY };
938
+ let matrix = multiplyMatrices(multiplyMatrices(scaleMatrix(scaleX, scaleY, c), rotateMatrix(rotation, c)), translateMatrix(dx, dy));
939
+ const along = follow ? followAt(entry, timeline, nodes, time) : null;
940
+ if (along) matrix = multiplyMatrices(matrix, multiplyMatrices(multiplyMatrices(translateMatrix(-c.x, -c.y), rotateMatrix(along.angle)), translateMatrix(along.x, along.y)));
941
+ return { matrix, dx, dy, rotation, scaleX, scaleY, follow: along };
942
+ }
943
+ function motionNodeClips(id, timeline, time) {
944
+ const out = [];
945
+ const rect = trackValue(timeline.tracks.get(motionTrackKey(id, "clipRect")), time);
946
+ if (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])) });
947
+ const circle = trackValue(timeline.tracks.get(motionTrackKey(id, "clipCircle")), time);
948
+ if (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])) });
949
+ return out;
798
950
  }
799
951
  function motionFrameAt(scene, time, options = {}) {
800
952
  const s = applyMotionControlValues(scene, options.values);
@@ -803,12 +955,15 @@ function motionFrameAt(scene, time, options = {}) {
803
955
  const drawOn = options.draw !== false;
804
956
  const value = (id, p) => trackValue(timeline.tracks.get(motionTrackKey(id, p)), time);
805
957
  const animated = new Set(timeline.segments.map((seg) => seg.node));
958
+ const clips = {};
806
959
  const visit = (node) => {
807
960
  let out = node.type === "group" ? { ...node, children: node.children.map(visit) } : node;
808
961
  if (!animated.has(node.id)) return out;
809
962
  const entry = nodes.get(node.id);
810
963
  if (!entry) return out;
811
964
  const id = node.id;
965
+ const clip = motionNodeClips(id, timeline, time);
966
+ if (clip.length) clips[id] = clip;
812
967
  const shape = shapeAt(entry, timeline, nodes, time);
813
968
  if (shape) {
814
969
  const { name, visible, opacity: opacity2, locked } = node;
@@ -872,11 +1027,19 @@ function motionFrameAt(scene, time, options = {}) {
872
1027
  const document = { ...s.artwork, nodes: s.artwork.nodes.map(visit) };
873
1028
  const cam = trackValue(timeline.tracks.get(motionTrackKey("", "camera")), time);
874
1029
  const box = Array.isArray(cam) ? cam : [0, 0, s.artwork.width, s.artwork.height];
875
- return { time, document, camera: { x: tidy(box[0]), y: tidy(box[1]), width: tidy(box[2]), height: tidy(box[3]) } };
1030
+ return { time, document, camera: { x: tidy(box[0]), y: tidy(box[1]), width: tidy(box[2]), height: tidy(box[3]) }, clips };
1031
+ }
1032
+ function motionClipAttrs(clip) {
1033
+ const { shape: _shape, ...attrs } = clip;
1034
+ return attrs;
876
1035
  }
877
1036
  function motionFrameToSvg(scene, time, options = {}) {
878
1037
  const frame = motionFrameAt(scene, time, options);
879
- return withViewBox(vectorDocumentToSvg(frame.document, options), frame.camera);
1038
+ const prefix = options.idPrefix ?? "vg-";
1039
+ const wrap = { ...options.wrap };
1040
+ for (const [id, clips] of Object.entries(frame.clips))
1041
+ wrap[id] = [...wrap[id] ?? [], ...clips.map((clip, i) => ({ clip: { id: `${prefix}reveal-${id}-${i}`, shape: clip.shape, attrs: motionClipAttrs(clip) } }))];
1042
+ return withViewBox(vectorDocumentToSvg(frame.document, { ...options, wrap }), frame.camera);
880
1043
  }
881
1044
  function withViewBox(svg, box) {
882
1045
  const f = (n) => String(Math.round(n * 1e3) / 1e3);
@@ -911,6 +1074,11 @@ function visibleAt(timeline, id, time, node) {
911
1074
  if (node.visible === false) return false;
912
1075
  if (num("opacity", node.opacity ?? 1) <= 0.01) return false;
913
1076
  if (Math.abs(num("scaleX", 1) * num("scaleY", 1)) <= 1e-4) return false;
1077
+ const clip = (p) => trackValue(timeline.tracks.get(motionTrackKey(id, p)), time);
1078
+ const rect = clip("clipRect");
1079
+ if (Array.isArray(rect) && (rect[2] <= 1e-4 || rect[3] <= 1e-4)) return false;
1080
+ const circle = clip("clipCircle");
1081
+ if (Array.isArray(circle) && circle[2] <= 1e-4) return false;
914
1082
  const hasFill = node.type === "path" ? !!node.fill && node.fill !== "none" : collectPathNodes(node).some((p) => p.fill && p.fill !== "none");
915
1083
  return num("drawEnd", 1) > 0.01 || hasFill && num("fillOpacity", 1) > 0.01;
916
1084
  }
@@ -950,6 +1118,12 @@ function checkMotionScene(scene) {
950
1118
  if (command2.type === "follow" && known(command2.path, "unknown-path", "path", where) && nodes.get(command2.path).node.type !== "path")
951
1119
  issues.push(motionIssue("not-a-path", `"${command2.path}" is a group; follow a single path node.`, { ...where, ids: [command2.path] }));
952
1120
  if (command2.type === "morph") known(command2.into, "unknown-shape", "shape", where);
1121
+ const style = command2.type === "enter" || command2.type === "exit" ? command2.style : void 0;
1122
+ if (style === "wipe" || style === "iris" || style === "split") {
1123
+ for (const id of targets)
1124
+ if (!motionRevealPadding(nodes.get(id)))
1125
+ issues.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 "${command2.type === "enter" ? "draw" : "undraw"}" for a line.`, { ...where, ids: [id] }));
1126
+ }
953
1127
  if (command2.type === "style") {
954
1128
  for (const key of ["fill", "stroke"]) {
955
1129
  const color = command2[key];
@@ -966,6 +1140,18 @@ function checkMotionScene(scene) {
966
1140
  }
967
1141
  }
968
1142
  }
1143
+ if (command2.type === "color-pulse") {
1144
+ const key = command2.paint ?? "fill";
1145
+ const color = command2.color ?? "#f59e0b";
1146
+ if (normalizeTokenColor(color) === null) issues.push(motionIssue("invalid-color", `color "${color}" is not a colour this editor reads; use hex ("#0ea5e9"), rgb() or rgba().`, where));
1147
+ else
1148
+ for (const id of targets) {
1149
+ const node = nodes.get(id).node;
1150
+ const paths = node.type === "path" ? [node] : collectPathNodes(node);
1151
+ if (paths.some((p) => typeof p[key] !== "string"))
1152
+ issues.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] }));
1153
+ }
1154
+ }
969
1155
  if (command2.type === "effect") {
970
1156
  for (const id of targets) {
971
1157
  const node = nodes.get(id).node;
@@ -1250,6 +1436,8 @@ function toFlairSvgMotion(scene, options = {}) {
1250
1436
  const fps = options.fps ?? scene.fps ?? 30;
1251
1437
  const precision = options.precision ?? 3;
1252
1438
  const curves = options.curves ?? true;
1439
+ const behaviors = options.behaviors ?? true;
1440
+ const plays = (s) => !s.behavior || behaviors;
1253
1441
  const round2 = (n) => Math.round(n * 10 ** precision) / 10 ** precision;
1254
1442
  const f = (n) => String(round2(n));
1255
1443
  const timeline = compileMotionScene(scene);
@@ -1264,26 +1452,72 @@ function toFlairSvgMotion(scene, options = {}) {
1264
1452
  };
1265
1453
  const animatedNodes = new Set(timeline.segments.map((s) => s.node).filter(Boolean));
1266
1454
  const pathsSeen = /* @__PURE__ */ new Set();
1455
+ const wrap = {};
1456
+ const routes = [];
1457
+ const follows = [];
1458
+ const usedIds = new Set(nodes.keys());
1459
+ const freshId = (base) => {
1460
+ let id = base;
1461
+ for (let n = 2; usedIds.has(id); n++) id = `${base}-${n}`;
1462
+ usedIds.add(id);
1463
+ return id;
1464
+ };
1267
1465
  for (const id of animatedNodes) {
1268
1466
  const entry = nodes.get(id);
1269
1467
  const node = entry.node;
1468
+ const drawn = [...entry.ancestors.map((a) => nodes.get(a).node), node].every((n) => n.visible !== false);
1469
+ for (const [p, name] of [["clipRect", "reveal"], ["clipCircle", "iris"]]) {
1470
+ if (!drawn || !timeline.tracks.has(motionTrackKey(id, p))) continue;
1471
+ const wrapper = freshId(`${id}--${name}`);
1472
+ const clipId = freshId(`${wrapper}-clip`);
1473
+ const shapeId = freshId(`${wrapper}-clip-shape`);
1474
+ const clipAt = (t) => motionNodeClips(id, timeline, t).find((c) => c.shape === (p === "clipRect" ? "rect" : "circle"));
1475
+ const rest = clipAt(0);
1476
+ (wrap[id] ??= []).push({ id: wrapper, clip: { id: clipId, shapeId, shape: rest.shape, attrs: motionClipAttrs(rest) } });
1477
+ channels.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) });
1478
+ }
1479
+ const followSegments = track(id, "follow");
1480
+ if (drawn && followSegments.length) {
1481
+ const ids = /* @__PURE__ */ new Map();
1482
+ for (const seg of followSegments) {
1483
+ if (!seg.path || ids.has(seg.path)) continue;
1484
+ const route = motionFollowRoute(entry, nodes.get(seg.path));
1485
+ if (!route) continue;
1486
+ const routeId = freshId(`${id}--follow-route`);
1487
+ ids.set(seg.path, routeId);
1488
+ routes.push(`<path id="${routeId}" d="${bezierPathToSvg(route, { precision })}" fill="none"/>`);
1489
+ }
1490
+ if (ids.size) {
1491
+ const wrapper = freshId(`${id}--follow`);
1492
+ const centre = freshId(`${id}--follow-centre`);
1493
+ const c = entry.center;
1494
+ const at = motionNodeOffset(entry, timeline, 0, nodes)?.follow;
1495
+ const placed = at ? `translate(${f(at.x)} ${f(at.y)})${at.angle ? ` rotate(${f(at.angle)})` : ""}` : void 0;
1496
+ (wrap[id] ??= []).push({ id: wrapper, ...placed ? { transform: placed } : {} }, { id: centre, transform: `translate(${f(-c.x)} ${f(-c.y)})` });
1497
+ follows.push({ id, wrapper, routes: ids, segments: followSegments.filter((seg) => seg.path && ids.has(seg.path)) });
1498
+ }
1499
+ }
1270
1500
  if (timeline.tracks.has(motionTrackKey(id, "opacity")))
1271
- channels.push({ id, kind: "attr", attr: "opacity", segments: [...track(id, "opacity")], exact: (s) => !s.wave, value: (t) => round2(Math.min(1, Math.max(0, Number(trackValue(track(id, "opacity"), t))))) });
1272
- const transformSegments = TRANSFORM_PROPS2.flatMap((p) => track(id, p));
1501
+ channels.push({ id, kind: "attr", attr: "opacity", segments: [...track(id, "opacity")], exact: plays, value: (t) => round2(Math.min(1, Math.max(0, Number(trackValue(track(id, "opacity"), t))))) });
1502
+ const followed = follows.some((x) => x.id === id);
1503
+ const transformSegments = TRANSFORM_PROPS2.flatMap((p) => followed && p === "follow" ? [] : track(id, p));
1273
1504
  if (transformSegments.length) {
1274
1505
  const base = node.transform ? ` matrix(${node.transform.map(f).join(" ")})` : "";
1275
1506
  const c = entry.center;
1507
+ const transformAt = (t, raw) => {
1508
+ const o = motionNodeOffset(entry, timeline, t, nodes, raw, !followed);
1509
+ return `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}`;
1510
+ };
1276
1511
  channels.push({
1277
1512
  id,
1278
1513
  kind: "attr",
1279
1514
  attr: "transform",
1280
1515
  segments: transformSegments,
1281
- exact: (s) => LINEAR_TRANSFORM.has(s.property) && !s.wave,
1516
+ exact: (s) => LINEAR_TRANSFORM.has(s.property) && plays(s),
1282
1517
  overshoot: true,
1283
- value: (t) => {
1284
- const o = motionNodeOffset(entry, timeline, t, nodes);
1285
- return `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}`;
1286
- }
1518
+ // x, y and the angle are the transform's numbers 0, 1 and 2 (`MotionSegment.index`).
1519
+ value: (t) => transformAt(t, false),
1520
+ raw: (t) => transformAt(t, true)
1287
1521
  });
1288
1522
  }
1289
1523
  const paths = node.type === "path" ? [node] : collectPathNodes(node);
@@ -1292,7 +1526,7 @@ function toFlairSvgMotion(scene, options = {}) {
1292
1526
  pathsSeen.add(path.id);
1293
1527
  const paint = (p, attr) => {
1294
1528
  const from = owner(path, p);
1295
- if (from) channels.push({ id: path.id, kind: "attr", attr, segments: [...track(from, p)], exact: () => true, value: (t) => hex6(trackValue(track(from, p), t)) });
1529
+ if (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)) });
1296
1530
  };
1297
1531
  paint("fill", "fill");
1298
1532
  paint("stroke", "stroke");
@@ -1331,15 +1565,22 @@ function toFlairSvgMotion(scene, options = {}) {
1331
1565
  const animate = [];
1332
1566
  let sampled = 0;
1333
1567
  const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
1334
- const emit = (channel, delay, ms, from, to, ease) => {
1335
- const base = { ...channel.id ? { id: channel.id } : {}, ...delay > 0 ? { delay: round2(delay) } : {}, ms: round2(ms), ease: typeof ease === "string" ? ease : ease.map(round2) };
1568
+ const emit = (channel, delay, ms, from, to, ease, behavior) => {
1569
+ const base = { ...channel.id ? { id: channel.id } : {}, ...delay > 0 ? { delay: round2(delay) } : {}, ms: round2(ms), ease: typeof ease === "string" ? ease : ease.map(round2), ...behavior ? { behavior } : {} };
1336
1570
  if (channel.kind === "view") animate.push({ ...base, view: to });
1337
1571
  else if (channel.kind === "draw") animate.push({ ...base, draw: [from, to] });
1338
- else animate.push({ ...base, attrs: { [channel.attr]: [from, to] } });
1572
+ else if (channel.kind === "attrs") {
1573
+ const [a, b] = [from, to];
1574
+ const attrs = Object.fromEntries(channel.attrs.flatMap((name, k) => a[k] !== b[k] ? [[name, [a[k], b[k]]]] : []));
1575
+ animate.push({ ...base, attrs });
1576
+ } else animate.push({ ...base, attrs: { [channel.attr]: [from, to] } });
1339
1577
  };
1340
1578
  for (const channel of channels) {
1341
1579
  const cuts = channel.segments.filter((s) => s.end <= s.start);
1342
- for (const cut of cuts) emit(channel, cut.start, 0, channel.value(Math.max(0, cut.start - 1e-3)), channel.value(cut.start), "linear");
1580
+ for (const cut of cuts) {
1581
+ const [from, to] = [channel.value(Math.max(0, cut.start - 1e-3)), channel.value(cut.start)];
1582
+ if (cut.start <= 0 || !same(from, to) || channel.kind === "view") emit(channel, cut.start, 0, from, to, "linear");
1583
+ }
1343
1584
  const times = [...new Set(channel.segments.flatMap((s) => [s.start, s.end]))].sort((a, b) => a - b);
1344
1585
  for (let i = 0; i + 1 < times.length; i++) {
1345
1586
  const a = times[i];
@@ -1347,13 +1588,15 @@ function toFlairSvgMotion(scene, options = {}) {
1347
1588
  const active = channel.segments.filter((s) => s.start < b && s.end > a);
1348
1589
  if (!active.length) continue;
1349
1590
  const first = active[0];
1350
- const together = active.every((x) => x.start === a && x.end === b && channel.exact(x) && JSON.stringify(x.ease) === JSON.stringify(first.ease));
1591
+ const together = active.every(
1592
+ (x) => x.start === a && x.end === b && channel.exact(x) && JSON.stringify(x.ease) === JSON.stringify(first.ease) && JSON.stringify(x.behavior) === JSON.stringify(first.behavior)
1593
+ );
1351
1594
  const curve = together ? flairCurveFor(first.ease, curves) : void 0;
1352
1595
  const ease = curve && (!overshoots(curve) || channel.overshoot) ? curve : void 0;
1353
1596
  if (ease) {
1354
1597
  const from = channel.value(a);
1355
- const to = channel.value(b);
1356
- if (!same(from, to) || channel.kind === "view") emit(channel, a, b - a, from, to, ease);
1598
+ const to = first.behavior ? (channel.raw ?? channel.value)(b) : channel.value(b);
1599
+ if (!same(from, to) || channel.kind === "view") emit(channel, a, b - a, from, to, ease, first.behavior);
1357
1600
  continue;
1358
1601
  }
1359
1602
  const n = Math.max(1, Math.ceil((b - a) * fps / 1e3));
@@ -1370,8 +1613,29 @@ function toFlairSvgMotion(scene, options = {}) {
1370
1613
  }
1371
1614
  }
1372
1615
  }
1616
+ for (const follow of follows) {
1617
+ const starts = follow.segments.map((seg) => seg.start);
1618
+ for (const seg of follow.segments) {
1619
+ const along = { id: follow.wrapper, along: follow.routes.get(seg.path), ...seg.rotate ? { orient: true } : {} };
1620
+ const progress = (t) => round2(Math.min(1, Math.max(0, Number(segmentValue(seg, t)))));
1621
+ const curve = seg.end > seg.start ? flairCurveFor(seg.ease, curves) : "linear";
1622
+ if (curve && !(overshoots(curve) && seg.rotate)) {
1623
+ animate.push({ ...along, ...seg.start > 0 ? { delay: round2(seg.start) } : {}, ms: round2(seg.end - seg.start), ease: typeof curve === "string" ? curve : curve.map(round2), at: [round2(Number(seg.from)), round2(Number(seg.to))] });
1624
+ continue;
1625
+ }
1626
+ const until = Math.min(seg.end, ...starts.filter((t) => t > seg.start));
1627
+ const n = Math.max(1, Math.ceil((until - seg.start) * fps / 1e3));
1628
+ for (let k = 1; k <= n; k++) {
1629
+ const t0 = seg.start + (until - seg.start) * (k - 1) / n;
1630
+ const t1 = seg.start + (until - seg.start) * k / n;
1631
+ animate.push({ ...along, ...t0 > 0 ? { delay: round2(t0) } : {}, ms: round2(t1 - t0), ease: "linear", at: [progress(t0), progress(t1)] });
1632
+ sampled++;
1633
+ }
1634
+ }
1635
+ }
1373
1636
  animate.sort((x, y) => (x.delay ?? 0) - (y.delay ?? 0));
1374
- let svg = vectorDocumentToSvg({ ...scene.artwork, nodes: expandVectorAppearances(scene.artwork.nodes) }, { pretty: false, precision });
1637
+ let svg = vectorDocumentToSvg({ ...scene.artwork, nodes: expandVectorAppearances(scene.artwork.nodes) }, { pretty: false, precision, wrap });
1638
+ if (routes.length) svg = svg.replace(/^(<svg[^>]*>)/, `$1<defs>${routes.join("")}</defs>`);
1375
1639
  const lastChange = animate.reduce((m, a) => Math.max(m, (a.delay ?? 0) + (a.ms ?? 0)), 0);
1376
1640
  let motion = { svg, animate };
1377
1641
  if (scene.controls?.length) {
@@ -1680,13 +1944,20 @@ var MOTION_COMMAND_SCHEMA = {
1680
1944
  description: `A command (one of ${MOTION_COMMAND_TYPES.join(", ")}). Commands in a shot play one after another unless "with": "previous".`,
1681
1945
  oneOf: [
1682
1946
  command("enter", "Brings hidden targets in; they are hidden before this shot.", {
1683
- style: { type: "string", enum: [...MOTION_ENTER_STYLES], description: "fade (default), pop, grow, slide, or draw (outline drawn on, then the fill fades in)." },
1684
- direction: { type: "string", enum: [...MOTION_DIRECTIONS], description: "For slide: direction of travel (default up)." },
1685
- distance: { type: "number", description: "For slide: document units (default 40)." }
1947
+ style: {
1948
+ type: "string",
1949
+ enum: [...MOTION_ENTER_STYLES],
1950
+ description: "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)."
1951
+ },
1952
+ direction: { 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)." },
1953
+ distance: { type: "number", description: "For slide (default 40) and rise (default 20): document units." },
1954
+ scale: { type: "number", minimum: 0, description: "For pop (default 0.5) and zoom (default 1.6): the starting scale (1 = rest size)." },
1955
+ shape: { 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." },
1956
+ orientation: { 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." }
1686
1957
  }),
1687
1958
  command("exit", "Takes targets out.", {
1688
- style: { type: "string", enum: [...MOTION_EXIT_STYLES], description: "fade (default), shrink, slide or undraw." },
1689
- direction: { type: "string", enum: [...MOTION_DIRECTIONS], description: "For slide: direction of travel (default down)." },
1959
+ style: { 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)." },
1960
+ direction: { 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)." },
1690
1961
  distance: { type: "number", description: "For slide: document units (default 40)." }
1691
1962
  }),
1692
1963
  command("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).") }),
@@ -1702,12 +1973,30 @@ var MOTION_COMMAND_SCHEMA = {
1702
1973
  command("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"]),
1703
1974
  command("follow", "Moves targets along a path node, centre on the path.", {
1704
1975
  path: { type: "string", minLength: 1, description: "Id of a path node (it can be hidden)." },
1705
- rotate: { type: "boolean", description: "Turn with the path (default false)." },
1976
+ rotate: { type: "boolean", description: "Turn with the path (default false); moves and shakes made meanwhile turn with it too." },
1706
1977
  from: FRACTION("Where to start along the path (default 0)."),
1707
1978
  to: FRACTION("Where to end along the path (default 1).")
1708
1979
  }, ["path"]),
1709
1980
  command("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)." } }),
1710
- command("shake", "Shakes side to side, settling.", { amount: { type: "number", description: "Document units (default 8)." }, count: { type: "integer", minimum: 1, description: "Shakes (default 3)." } }),
1981
+ command("shake", "Shakes side to side (or up and down), settling.", {
1982
+ amount: { type: "number", description: "Document units (default 8)." },
1983
+ count: { type: "integer", minimum: 1, description: "Shakes (default 3)." },
1984
+ axis: { type: "string", enum: ["horizontal", "vertical"], description: "Default horizontal." }
1985
+ }),
1986
+ command("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)." } }),
1987
+ command("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)." } }),
1988
+ command("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.", {
1989
+ amount: { type: "number", description: "Up to about this far, in document units (default 6)." },
1990
+ frequency: { type: "number", exclusiveMinimum: 0, description: "Wanders per second, in Hz (default 3)." },
1991
+ octaves: { type: "integer", minimum: 1, maximum: 8, description: "Layers of finer detail (default 2)." },
1992
+ rotate: { type: "number", description: "Also turns about the centre by up to about this many degrees (default 0)." },
1993
+ seed: { type: "integer", minimum: 0, description: "Default: one picked from the target id, so each target wanders its own way." }
1994
+ }),
1995
+ command("color-pulse", "Tints solid paint toward a colour and back (mixed in OKLab). On a group it tints every path in it.", {
1996
+ color: { type: "string", description: 'The tint, a CSS colour (default "#f59e0b").' },
1997
+ paint: { type: "string", enum: ["fill", "stroke"], description: "Which paint (default fill)." },
1998
+ count: { type: "integer", minimum: 1, description: "Pulses (default 1)." }
1999
+ }),
1711
2000
  command("effect", "Tweens a numeric parameter of a live path effect on the targets (twist angle, wiggle time, zig zag size, trim offset\u2026).", {
1712
2001
  effect: { type: "string", minLength: 1, description: `Effect id from get_animation's element "effects".` },
1713
2002
  param: { type: "string", minLength: 1, description: "A numeric parameter of that effect (listed with it)." },
@@ -1804,7 +2093,8 @@ function describeMotionShots(scene) {
1804
2093
  ...shot.hold !== void 0 ? { hold: shot.hold } : {},
1805
2094
  commands: shot.run.map((c, index) => {
1806
2095
  const ct = timeline.commands.find((x) => x.shotIndex === i && x.command === index);
1807
- return { index, ...c, start: ct.start, end: ct.end };
2096
+ const primitive = motionFlairPrimitive(c);
2097
+ return { index, ...c, start: ct.start, end: ct.end, ...primitive ? { flairPrimitive: primitive } : {} };
1808
2098
  })
1809
2099
  };
1810
2100
  });
@@ -1840,7 +2130,7 @@ function createAnimationEditorToolProvider(controller, options = {}) {
1840
2130
  const getAnimation = {
1841
2131
  name: "get_animation",
1842
2132
  title: "Read the animation",
1843
- description: "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.",
2133
+ description: `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.`,
1844
2134
  inputSchema: object({ includeElements: { type: "boolean", description: "Include the artwork's elements (default true)." } }),
1845
2135
  annotations: { title: "Read the animation", ...READ },
1846
2136
  handler: ({ includeElements = true }) => {
@@ -1927,16 +2217,18 @@ function createAnimationEditorToolProvider(controller, options = {}) {
1927
2217
  }
1928
2218
  };
1929
2219
  const CURVES_DESCRIPTION = "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.";
2220
+ const BEHAVIORS_DESCRIPTION = "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.";
1930
2221
  const exportFlairMotion = {
1931
2222
  name: "export_flair_motion",
1932
2223
  title: "Export as Flair vector motion",
1933
2224
  description: "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.",
1934
2225
  inputSchema: object({
1935
2226
  fps: { type: "number", minimum: 1, maximum: 120, description: "Sampling rate for changes Flair cannot express exactly (default: the scene's fps, else 30)." },
1936
- curves: { type: "boolean", description: CURVES_DESCRIPTION }
2227
+ curves: { type: "boolean", description: CURVES_DESCRIPTION },
2228
+ behaviors: { type: "boolean", description: BEHAVIORS_DESCRIPTION }
1937
2229
  }),
1938
2230
  annotations: { title: "Export as Flair vector motion", ...READ },
1939
- handler: ({ fps, curves }) => controller.toFlairMotion({ ...fps ? { fps } : {}, ...curves === void 0 ? {} : { curves } })
2231
+ handler: ({ fps, curves, behaviors }) => controller.toFlairMotion({ ...fps ? { fps } : {}, ...curves === void 0 ? {} : { curves }, ...behaviors === void 0 ? {} : { behaviors } })
1940
2232
  };
1941
2233
  const exportFlairEffect = {
1942
2234
  name: "export_flair_effect",
@@ -1948,7 +2240,8 @@ function createAnimationEditorToolProvider(controller, options = {}) {
1948
2240
  description: { type: "string", description: "One sentence (default: the scene's description)." },
1949
2241
  category: { type: "string", minLength: 1, description: "Flair catalog category, e.g. icon, loader, ui, data, text, morph (default icon)." },
1950
2242
  tags: { type: "array", items: { type: "string" }, description: "Search tags (default none)." },
1951
- curves: { type: "boolean", description: CURVES_DESCRIPTION }
2243
+ curves: { type: "boolean", description: CURVES_DESCRIPTION },
2244
+ behaviors: { type: "boolean", description: BEHAVIORS_DESCRIPTION }
1952
2245
  }),
1953
2246
  annotations: { title: "Export as a Flair effect", ...READ },
1954
2247
  handler: (args) => controller.toFlairEffect(args)
@@ -2160,8 +2453,12 @@ How it plays
2160
2453
 
2161
2454
  Commands
2162
2455
  - enter (fade, pop, grow, slide, draw) and exit (fade, shrink, slide, undraw) bring things in and out.
2456
+ - 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.
2163
2457
  - 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.
2164
- - 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.
2458
+ - enter also has zoom (settles from larger) and rise (rises a short way, overshooting a touch); pop and zoom take a starting "scale".
2459
+ - 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).
2460
+ - 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).
2461
+ - 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.
2165
2462
  - effect tweens a numeric parameter of a live path effect already on the node (twist angle, wiggle time, zig zag size).
2166
2463
 
2167
2464
  Working method
@@ -2189,8 +2486,10 @@ export {
2189
2486
  MOTION_EDIT_OPS,
2190
2487
  MOTION_ENTER_STYLES,
2191
2488
  MOTION_EXIT_STYLES,
2489
+ MOTION_IRIS_SHAPES,
2192
2490
  MOTION_ISSUE_CODES,
2193
2491
  MOTION_MIN_CHANGE_MS,
2492
+ MOTION_SPLIT_ORIENTATIONS,
2194
2493
  MotionSceneFormatError,
2195
2494
  activeSegment,
2196
2495
  applyMotionControlValues,
@@ -2210,15 +2509,21 @@ export {
2210
2509
  interpolateMotionValue,
2211
2510
  isMotionCommand,
2212
2511
  isMotionShot,
2512
+ motionClipAttrs,
2213
2513
  motionCommandDuration,
2514
+ motionFlairPrimitive,
2515
+ motionFollowRoute,
2214
2516
  motionFrameAt,
2215
2517
  motionFrameToSvg,
2216
2518
  motionIssue,
2217
2519
  motionIssueKey,
2218
2520
  motionIssueLine,
2521
+ motionNodeClips,
2219
2522
  motionNodeOffset,
2220
2523
  motionPathLength,
2221
2524
  motionRestValue,
2525
+ motionRevealClip,
2526
+ motionRevealPadding,
2222
2527
  motionSceneShapeProblems,
2223
2528
  motionSceneToJson,
2224
2529
  motionShotAt,