@anvpx/motion-cli 0.1.52 → 0.1.54

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.
Files changed (57) hide show
  1. package/dist/.out/smoke/boot.js +90 -0
  2. package/dist/.out/smoke/runtime/compose.js +43 -0
  3. package/dist/.out/smoke/runtime/easing.js +45 -0
  4. package/dist/.out/smoke/runtime/mount.js +153 -0
  5. package/dist/.out/smoke/runtime/timeline.js +199 -0
  6. package/dist/.out/smoke/scenes/count/scene.js +6 -0
  7. package/dist/.out/smoke/scenes/intro/scene.js +6 -0
  8. package/dist/.out/smoke/scenes/outro/scene.js +6 -0
  9. package/dist/.out/smoke/scenes/path/scene.js +6 -0
  10. package/dist/.out/smoke/scenes/signals/scene.js +6 -0
  11. package/dist/.out/smoke/shared/format.js +59 -0
  12. package/dist/.out/smoke/shared/motion.js +117 -0
  13. package/dist/.out/template-flow/out/project/boot.js +88 -0
  14. package/dist/.out/template-flow/out/project/runtime/compose.js +43 -0
  15. package/dist/.out/template-flow/out/project/runtime/easing.js +45 -0
  16. package/dist/.out/template-flow/out/project/runtime/mount.js +153 -0
  17. package/dist/.out/template-flow/out/project/runtime/timeline.js +199 -0
  18. package/dist/.out/template-flow/out/project/scenes/diagram/scene.js +6 -0
  19. package/dist/.out/template-flow/out/project/scenes/end/scene.js +6 -0
  20. package/dist/.out/template-flow/out/project/scenes/intro/scene.js +6 -0
  21. package/dist/.out/template-flow/out/project/shared/format.js +59 -0
  22. package/dist/.out/template-flow/out/project/shared/motion.js +117 -0
  23. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/boot.js +88 -0
  24. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/runtime/compose.js +43 -0
  25. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/runtime/easing.js +45 -0
  26. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/runtime/mount.js +153 -0
  27. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/runtime/timeline.js +199 -0
  28. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/scenes/diagram/scene.js +6 -0
  29. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/scenes/end/scene.js +6 -0
  30. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/scenes/intro/scene.js +6 -0
  31. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/shared/format.js +59 -0
  32. package/dist/.out/template-flow/out/storyboard.preview-work/clip/project/shared/motion.js +117 -0
  33. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/boot.js +88 -0
  34. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/runtime/compose.js +43 -0
  35. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/runtime/easing.js +45 -0
  36. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/runtime/mount.js +153 -0
  37. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/runtime/timeline.js +199 -0
  38. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/scenes/diagram/scene.js +6 -0
  39. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/scenes/end/scene.js +6 -0
  40. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/scenes/intro/scene.js +6 -0
  41. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/shared/format.js +59 -0
  42. package/dist/.out/template-flow/out/storyboard.preview-work/light/project/shared/motion.js +117 -0
  43. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/boot.js +88 -0
  44. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/runtime/compose.js +43 -0
  45. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/runtime/easing.js +45 -0
  46. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/runtime/mount.js +153 -0
  47. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/runtime/timeline.js +199 -0
  48. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/scenes/diagram/scene.js +6 -0
  49. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/scenes/end/scene.js +6 -0
  50. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/scenes/intro/scene.js +6 -0
  51. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/shared/format.js +59 -0
  52. package/dist/.out/template-flow/out/storyboard.preview-work/paired/project/shared/motion.js +117 -0
  53. package/dist/contact/argv.js +2 -2
  54. package/dist/main.js +0 -0
  55. package/dist/plugin/install.d.ts +3 -3
  56. package/dist/plugin/install.js +2 -2
  57. package/package.json +8 -9
@@ -0,0 +1,59 @@
1
+ // @ts-check
2
+ // Locale-free, deterministic number formatting for tabular numerals (no Intl, no toLocaleString).
3
+ const MINUS = "−";
4
+ const TIERS = ["", "K", "M", "B", "T"];
5
+ /**
6
+ * @typedef {object} FmtOpts
7
+ * @property {string} [unit] "$", "€", "£", "¥" prefix; anything else is appended ("%", " km")
8
+ * @property {number} [decimals] fixed decimals (default 0; 1 when compact above 1000)
9
+ * @property {boolean} [sign] show "+" for positive values
10
+ * @property {boolean} [compact] K / M / B / T suffix
11
+ */
12
+ /** @param {string} digits */
13
+ const group = (digits) => digits.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
14
+ /**
15
+ * @param {number} abs
16
+ * @param {number} decimals
17
+ * @returns {string}
18
+ */
19
+ const fixed = (abs, decimals) => {
20
+ const [int = "0", frac] = abs.toFixed(decimals).split(".");
21
+ return frac === undefined ? group(int) : `${group(int)}.${frac}`;
22
+ };
23
+ /**
24
+ * @param {number} abs
25
+ * @param {number | undefined} decimals
26
+ * @returns {string}
27
+ */
28
+ const compactBody = (abs, decimals) => {
29
+ let tier = 0;
30
+ let scaled = abs;
31
+ while (scaled >= 1000 && tier < TIERS.length - 1) {
32
+ scaled /= 1000;
33
+ tier++;
34
+ }
35
+ const d = decimals ?? (tier === 0 ? 0 : 1);
36
+ // rounding can reach 1000 of this tier (999.95K -> 1000.0K): promote once
37
+ if (tier < TIERS.length - 1 && Number(scaled.toFixed(d)) >= 1000) {
38
+ scaled /= 1000;
39
+ tier++;
40
+ }
41
+ return `${fixed(scaled, d)}${TIERS[tier]}`;
42
+ };
43
+ /** @param {string} unit */
44
+ const isPrefix = (unit) => /^[$€£¥]/.test(unit);
45
+ /**
46
+ * @param {number} value
47
+ * @param {FmtOpts} [opts]
48
+ * @returns {string}
49
+ */
50
+ export const fmt = (value, opts = {}) => {
51
+ if (!Number.isFinite(value))
52
+ throw new RangeError(`fmt: value must be finite, got ${value}`);
53
+ const { unit = "", decimals, sign = false, compact = false } = opts;
54
+ const abs = Math.abs(value);
55
+ const body = compact ? compactBody(abs, decimals) : fixed(abs, decimals ?? 0);
56
+ const zero = Number(body.replace(/[^0-9.]/g, "")) === 0;
57
+ const mark = zero ? "" : value < 0 ? MINUS : sign ? "+" : "";
58
+ return isPrefix(unit) ? `${mark}${unit}${body}` : `${mark}${body}${unit}`;
59
+ };
@@ -0,0 +1,117 @@
1
+ // @ts-check
2
+ // Pure motion helpers shared by scenes. No DOM, no clock, no state: the same inputs always give
3
+ // the same outputs. One implementation serves emit time (TS) and the browser seek runtime.
4
+ import { clamp01, ease } from "../runtime/easing.js";
5
+ /** Smallest / largest fraction of an item's duration shared with the next item in a stagger. */
6
+ export const MIN_OVERLAP = 0.05;
7
+ export const MAX_OVERLAP = 0.9;
8
+ /**
9
+ * @param {number} v
10
+ * @param {number} lo
11
+ * @param {number} hi
12
+ * @returns {number}
13
+ */
14
+ export const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
15
+ /**
16
+ * @param {number} a
17
+ * @param {number} b
18
+ * @param {number} p
19
+ * @returns {number}
20
+ */
21
+ export const lerp = (a, b, p) => a + (b - a) * p;
22
+ /** Linear map of `v` from [inMin, inMax] to [outMin, outMax], clamped to the input range.
23
+ * @param {number} v
24
+ * @param {number} inMin
25
+ * @param {number} inMax
26
+ * @param {number} outMin
27
+ * @param {number} outMax
28
+ * @returns {number}
29
+ */
30
+ export const scale = (v, inMin, inMax, outMin, outMax) => lerp(outMin, outMax, inMax === inMin ? (v >= inMax ? 1 : 0) : clamp01((v - inMin) / (inMax - inMin)));
31
+ /** Monotone 0..1 progress of `t` through [start, end]; a zero-length window is a step.
32
+ * @param {number} t
33
+ * @param {number} start
34
+ * @param {number} end
35
+ * @returns {number}
36
+ */
37
+ export const progress = (t, start, end) => end > start ? clamp01((t - start) / (end - start)) : t >= start ? 1 : 0;
38
+ /**
39
+ * @param {number} n
40
+ * @param {number} span
41
+ * @returns {void}
42
+ */
43
+ const assertStagger = (n, span) => {
44
+ if (!Number.isInteger(n) || n < 1)
45
+ throw new RangeError(`stagger: n must be an integer >= 1, got ${n}`);
46
+ if (!(span > 0) || !Number.isFinite(span))
47
+ throw new RangeError(`stagger: span must be > 0, got ${span}`);
48
+ };
49
+ /** @param {number} overlap */
50
+ const overlapOf = (overlap) => clamp(Number.isFinite(overlap) ? overlap : 0, MIN_OVERLAP, MAX_OVERLAP);
51
+ /**
52
+ * Duration of each item when `n` items share `span` seconds and overlap by `overlap` (a fraction of
53
+ * the item duration, clamped to [0.05, 0.9]). The last item ends exactly at `span`.
54
+ * @param {number} n
55
+ * @param {number} span
56
+ * @param {number} overlap
57
+ * @returns {number}
58
+ */
59
+ export const staggerDuration = (n, span, overlap) => {
60
+ assertStagger(n, span);
61
+ return span / (1 + (n - 1) * (1 - overlapOf(overlap)));
62
+ };
63
+ /**
64
+ * Start time of item `i` (0-based). Offset between items is always smaller than an item's duration.
65
+ * @param {number} i
66
+ * @param {number} n
67
+ * @param {number} span
68
+ * @param {number} overlap
69
+ * @returns {number}
70
+ */
71
+ export const staggerStart = (i, n, span, overlap) => i * staggerDuration(n, span, overlap) * (1 - overlapOf(overlap));
72
+ /**
73
+ * Count from `from` (default 0) to `value`, easing out; exact at the end.
74
+ * @param {number} t
75
+ * @param {number} value
76
+ * @param {{ from?: number, start?: number, dur?: number }} [opts]
77
+ * @returns {number}
78
+ */
79
+ export const countUp = (t, value, opts = {}) => {
80
+ const { from = 0, start = 0, dur = 1 } = opts;
81
+ const p = progress(t, start, start + dur);
82
+ return p >= 1 ? value : lerp(from, value, ease("out", p));
83
+ };
84
+ /** Stroke-dashoffset that draws a path of length `len` on as `p` goes 0..1.
85
+ * @param {number} len
86
+ * @param {number} p
87
+ * @returns {number}
88
+ */
89
+ export const drawOn = (len, p) => len * (1 - clamp01(p));
90
+ /** Left-to-right clip-path reveal; `p` 0..1.
91
+ * @param {number} p
92
+ * @returns {string}
93
+ */
94
+ export const wipe = (p) => `inset(0 ${Math.round((1 - clamp01(p)) * 100000) / 1000}% 0 0)`;
95
+ /**
96
+ * Word-by-word timings: `n` words spread over `span` seconds with `overlap` between neighbours.
97
+ * @param {number} n
98
+ * @param {number} span
99
+ * @param {number} [overlap]
100
+ * @returns {{ start: number, end: number }[]}
101
+ */
102
+ export const revealTimings = (n, span, overlap = 0.5) => {
103
+ const dur = staggerDuration(n, span, overlap);
104
+ return Array.from({ length: n }, (_, i) => {
105
+ const start = staggerStart(i, n, span, overlap);
106
+ return { start, end: i === n - 1 ? span : start + dur };
107
+ });
108
+ };
109
+ /**
110
+ * Eased 0..1 progress of each of `n` words at time `t`.
111
+ * @param {number} n
112
+ * @param {number} t
113
+ * @param {number} span
114
+ * @param {number} [overlap]
115
+ * @returns {number[]}
116
+ */
117
+ export const revealProgress = (n, t, span, overlap = 0.5) => revealTimings(n, span, overlap).map(({ start, end }) => ease("out", progress(t, start, end)));
@@ -0,0 +1,88 @@
1
+ // Emitted boot glue: the only file that knows the renderer's `hf-seek` event.
2
+ import { createScene as scene0 } from "./scenes/intro/scene.js";
3
+ import { createScene as scene1 } from "./scenes/diagram/scene.js";
4
+ import { createScene as scene2 } from "./scenes/end/scene.js";
5
+ const FACTORIES = [scene0, scene1, scene2];
6
+ window.__timelines = window.__timelines || {};
7
+ const CONFIG = {"fps":30,"scenes":[{"clipId":"clip-intro","start":0,"duration":2,"overlap":0,"final":false,"config":{"ease":"out","move":"push-in"}},{"clipId":"clip-diagram","start":1.5,"duration":2,"overlap":0.5,"final":false,"config":{"ease":"out","move":"push-in"}},{"clipId":"clip-end","start":3,"duration":2,"overlap":0.5,"final":true,"config":{"ease":"out","move":"push-in"}}]};
8
+
9
+ const clamp = (value, low, high) => Math.min(high, Math.max(low, value));
10
+
11
+ const ease = (p) => 1 - (1 - p) ** 3;
12
+
13
+ /** Eased progress 0..1 of a scene entering over its predecessor (1 when no overlap transition). */
14
+ const transOf = (t, scene) =>
15
+ scene?.overlap > 0 && (scene.push || scene.wipe || scene.zoomThrough)
16
+ ? ease(clamp((t - scene.start) / scene.overlap, 0, 1))
17
+ : 1;
18
+
19
+ /** Push progress 0..1 of a scene entering over its predecessor (1 when it is not a push). */
20
+ const pushOf = (t, scene) => (scene?.push && scene.overlap > 0 ? transOf(t, scene) : 1);
21
+
22
+ /** Pure function of global time `t`: local scene time, visibility and fade opacity. */
23
+ const stateAt = (t, scene) => {
24
+ const end = scene.start + scene.duration;
25
+ const live = t >= scene.start && (t < end || (scene.final && t <= end));
26
+ const fade = scene.overlap > 0 ? clamp((t - scene.start) / scene.overlap, 0, 1) : 1;
27
+ return {
28
+ local: clamp(t - scene.start, 0, scene.duration),
29
+ visible: live,
30
+ opacity: live ? (scene.push || scene.wipe ? 1 : fade) : 0,
31
+ };
32
+ };
33
+
34
+ const mounts = CONFIG.scenes.map((scene, index) => {
35
+ const clip = document.getElementById(scene.clipId);
36
+ const ctx = { fps: CONFIG.fps, duration: scene.duration };
37
+ const runtime = FACTORIES[index](clip.firstElementChild, scene.config, ctx);
38
+ return { scene, clip, runtime };
39
+ });
40
+
41
+ const ready = Promise.all([document.fonts.ready, ...mounts.map((mount) => mount.runtime.ready)]);
42
+
43
+ /** Horizontal offset in percent: an entering push scene starts one frame to the right, the one it replaces leaves to the left. */
44
+ const offsetOf = (t, scene, next) => {
45
+ if (scene.push) return (1 - pushOf(t, scene)) * 100;
46
+ return next?.push ? -pushOf(t, next) * 100 : null;
47
+ };
48
+
49
+ /** Scale punch of a zoom-through: incoming shrinks 1.25 -> 1, outgoing grows 1 -> 1.12. */
50
+ const ZOOM_IN_FROM = 1.25;
51
+ const ZOOM_OUT_TO = 1.12;
52
+
53
+ const scaleOf = (t, scene, next) => {
54
+ if (scene.zoomThrough) return ZOOM_IN_FROM - (ZOOM_IN_FROM - 1) * transOf(t, scene);
55
+ if (next?.zoomThrough) return 1 + (ZOOM_OUT_TO - 1) * transOf(t, next);
56
+ return null;
57
+ };
58
+
59
+ /** Directional reveal of a wipe: incoming clip opens left -> right. */
60
+ const clipOf = (t, scene) => {
61
+ if (!scene.wipe) return null;
62
+ const p = transOf(t, scene);
63
+ if (p >= 1) return "";
64
+ return `inset(0 ${(1 - p) * 100}% 0 0)`;
65
+ };
66
+
67
+ const apply = (t) =>
68
+ mounts.map(({ scene, clip, runtime }, index) => {
69
+ const state = stateAt(t, scene);
70
+ clip.style.visibility = state.visible ? "visible" : "hidden";
71
+ clip.style.opacity = String(state.opacity);
72
+ const next = CONFIG.scenes[index + 1];
73
+ const offset = offsetOf(t, scene, next);
74
+ if (offset !== null) clip.style.transform = `translateX(${offset}%)`;
75
+ else {
76
+ const scale = scaleOf(t, scene, next);
77
+ if (scale !== null) clip.style.transform = `scale(${scale})`;
78
+ }
79
+ const clipPath = clipOf(t, scene);
80
+ if (clipPath !== null) clip.style.clipPath = clipPath;
81
+ return runtime.seek(state.local);
82
+ });
83
+
84
+ window.addEventListener("hf-seek", (event) => {
85
+ event.detail.waitUntil(Promise.all([ready, ...apply(event.detail.time)]));
86
+ });
87
+
88
+ apply(0);
@@ -0,0 +1,43 @@
1
+ // @ts-check
2
+ // Style-neutral authoring helpers. Every sample depends only on its inputs.
3
+ export { clamp01, ease } from "./easing.js";
4
+ /** @param {number[]} values */
5
+ const finite = (...values) => {
6
+ if (!values.every(Number.isFinite))
7
+ throw new RangeError("composition inputs must be finite");
8
+ };
9
+ /**
10
+ * Normalized interval in seconds. A zero duration is an instantaneous cut;
11
+ * negative durations are invalid. No prior samples or DOM state are read.
12
+ * @param {number} time
13
+ * @param {number} start
14
+ * @param {number} duration
15
+ */
16
+ export const progress = (time, start, duration) => {
17
+ finite(time, start, duration);
18
+ if (duration < 0)
19
+ throw new RangeError("duration must be non-negative");
20
+ if (duration === 0)
21
+ return time < start ? 0 : 1;
22
+ return Math.max(0, Math.min(1, (time - start) / duration));
23
+ };
24
+ /** Numeric interpolation; amount may overshoot for spring or anticipation.
25
+ * @param {number} from
26
+ * @param {number} to
27
+ * @param {number} amount
28
+ */
29
+ export const interpolate = (from, to, amount) => {
30
+ finite(from, to, amount);
31
+ return from + (to - from) * amount;
32
+ };
33
+ /** Start time for an item. A negative step expresses a reversed order.
34
+ * @param {number} index non-negative integer
35
+ * @param {number} step seconds between items
36
+ * @param {number} [start=0] first item's time
37
+ */
38
+ export const stagger = (index, step, start = 0) => {
39
+ if (!Number.isInteger(index) || index < 0)
40
+ throw new RangeError("index must be a non-negative integer");
41
+ finite(step, start);
42
+ return start + index * step;
43
+ };
@@ -0,0 +1,45 @@
1
+ // @ts-check
2
+ // Pure easing functions: no DOM, no clock, no state.
3
+ /** @typedef {(t: number) => number} EaseFn */
4
+ /** Clamp to [0, 1]; non-finite input maps to 0.
5
+ * @param {number} t
6
+ * @returns {number}
7
+ */
8
+ export const clamp01 = (t) => (t > 0 ? Math.min(t, 1) : 0);
9
+ /** Normalised settle time of the closed-form spring response. */
10
+ const SPRING_SPAN = 1;
11
+ /**
12
+ * Closed-form underdamped spring step response, rescaled so f(1) = 1 exactly.
13
+ * @param {number} damping damping ratio, 0 < damping < 1
14
+ * @param {number} omega natural frequency over the normalised span
15
+ * @returns {EaseFn}
16
+ */
17
+ const spring = (damping, omega) => {
18
+ const decay = damping * omega;
19
+ const damped = omega * Math.sqrt(1 - damping * damping);
20
+ /** @param {number} x */
21
+ const step = (x) => 1 - Math.exp(-decay * x) * (Math.cos(damped * x) + (decay / damped) * Math.sin(damped * x));
22
+ const settled = step(SPRING_SPAN);
23
+ return (t) => step(t * SPRING_SPAN) / settled;
24
+ };
25
+ /** @type {Readonly<Record<string, EaseFn>>} */
26
+ const EASINGS = {
27
+ linear: (t) => t,
28
+ in: (t) => t * t * t,
29
+ out: (t) => 1 - (1 - t) ** 3,
30
+ "in-out": (t) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2),
31
+ "spring-soft": spring(0.85, 9),
32
+ "spring-snappy": spring(0.6, 14),
33
+ };
34
+ export const EASE_NAMES = Object.keys(EASINGS);
35
+ /**
36
+ * @param {string} name one of EASE_NAMES
37
+ * @param {number} t progress, clamped to [0, 1]
38
+ * @returns {number}
39
+ */
40
+ export const ease = (name, t) => {
41
+ const fn = EASINGS[name];
42
+ if (!fn)
43
+ throw new Error(`unknown ease "${name}"; use one of: ${EASE_NAMES.join("|")}`);
44
+ return fn(clamp01(t));
45
+ };
@@ -0,0 +1,153 @@
1
+ // @ts-check
2
+ // Thin DOM layer: seek(t) writes styles as a pure function of t.
3
+ import { cameraScale, countScale, countText, countTrack, dimOpacity, driftOf, entranceState, entranceTrack, overlayEnvelope, sample, } from "./timeline.js";
4
+ /** @typedef {{ ease?: string, move?: string, focus?: string }} SceneConfig */
5
+ /** @typedef {{ fps?: number, duration?: number }} RuntimeContext */
6
+ /** @typedef {import("./timeline.js").Plan} Plan */
7
+ /** @typedef {{ seek(t: number): void, dispose(): void, ready: Promise<void> }} Runtime */
8
+ /** @typedef {(root: HTMLElement, config: SceneConfig, ctx: RuntimeContext) => Runtime} CreateScene */
9
+ /** @typedef {{ el: HTMLElement, text: string, track: import("./timeline.js").Track }} Counter */
10
+ /** @typedef {{ el: HTMLElement | SVGElement, kind: string, keys: string, track: import("./timeline.js").Track }} Item */
11
+ const DEFAULT_FPS = 30;
12
+ /**
13
+ * Config and ctx win over the data-* attributes the emitter put on the root.
14
+ * @param {HTMLElement} root
15
+ * @param {SceneConfig} config
16
+ * @param {RuntimeContext} ctx
17
+ */
18
+ const readSettings = (root, config, ctx) => ({
19
+ ease: config.ease ?? root.dataset.ease ?? "out",
20
+ move: config.move ?? root.dataset.move ?? "static",
21
+ focus: config.focus ?? root.dataset.focus ?? "",
22
+ fps: ctx.fps ?? Number(root.dataset.fps ?? DEFAULT_FPS),
23
+ duration: ctx.duration ?? Number(root.dataset.duration ?? 0),
24
+ });
25
+ /**
26
+ * @param {HTMLElement} root
27
+ * @param {ReturnType<typeof readSettings>} settings
28
+ * @param {Plan} plan
29
+ * @returns {Item[]}
30
+ */
31
+ const collectItems = (root, settings, plan) => Array.from(root.querySelectorAll("[data-anim]"), (node) => {
32
+ const el = /** @type {HTMLElement | SVGElement} */ (node);
33
+ const step = Number(el.dataset.step ?? 0);
34
+ return {
35
+ el,
36
+ kind: el.dataset.anim ?? "rise",
37
+ keys: el.dataset.focusKey ?? "",
38
+ track: entranceTrack(step, plan, settings.fps, settings.ease),
39
+ };
40
+ });
41
+ /**
42
+ * @param {Item} item
43
+ * @param {number} t
44
+ * @param {string} focus
45
+ * @param {number} rise
46
+ */
47
+ const applyItem = (item, t, focus, rise) => {
48
+ const state = entranceState(item.kind, sample(item.track, t), rise);
49
+ item.el.style.opacity = String(state.opacity * dimOpacity(focus, item.keys));
50
+ if (item.kind === "rise")
51
+ item.el.style.transform = `translateY(${state.y}px)`;
52
+ if (item.kind === "draw")
53
+ item.el.style.strokeDashoffset = String(state.dash);
54
+ if (item.kind === "grow")
55
+ item.el.style.transform = `scaleX(${state.scale})`;
56
+ };
57
+ /** @param {Item} item */
58
+ const clearItem = (item) => {
59
+ for (const name of ["opacity", "transform", "stroke-dashoffset"]) {
60
+ item.el.style.removeProperty(name);
61
+ }
62
+ };
63
+ /**
64
+ * Elements whose text counts up to the number they carry in data-count.
65
+ * @param {HTMLElement} root
66
+ * @param {ReturnType<typeof readSettings>} settings
67
+ * @param {Plan} plan
68
+ * @returns {Counter[]}
69
+ */
70
+ const collectCounters = (root, settings, plan) => Array.from(root.querySelectorAll("[data-count]"), (node) => {
71
+ const el = /** @type {HTMLElement} */ (node);
72
+ const step = Number(el.dataset.step ?? 0);
73
+ return {
74
+ el,
75
+ text: el.dataset.count ?? "",
76
+ track: countTrack(step, plan, settings.fps, settings.ease, settings.duration),
77
+ };
78
+ });
79
+ /**
80
+ * @param {Counter} counter
81
+ * @param {number} t
82
+ */
83
+ const applyCounter = (counter, t) => {
84
+ const progress = sample(counter.track, t);
85
+ counter.el.textContent = countText(counter.text, progress);
86
+ counter.el.style.transform = `scale(${countScale(progress)})`;
87
+ };
88
+ /**
89
+ * @param {HTMLElement} root
90
+ * @returns {Promise<void>}
91
+ */
92
+ const fontsReady = (root) => root.ownerDocument.fonts?.ready.then(() => undefined) ?? Promise.resolve();
93
+ /**
94
+ * Mounts every [data-anim] element of a scene fragment on one entrance timeline.
95
+ * @param {HTMLElement} root
96
+ * @param {SceneConfig} config
97
+ * @param {RuntimeContext} ctx
98
+ * @param {Plan} plan
99
+ * @returns {Runtime}
100
+ */
101
+ export const mountTimeline = (root, config, ctx, plan) => {
102
+ const settings = readSettings(root, config, ctx);
103
+ const items = collectItems(root, settings, plan);
104
+ const counters = collectCounters(root, settings, plan);
105
+ /** @param {number} t */
106
+ const seek = (t) => {
107
+ for (const item of items)
108
+ applyItem(item, t, settings.focus, plan.rise);
109
+ for (const counter of counters)
110
+ applyCounter(counter, t);
111
+ root.style.setProperty("--drift", String(driftOf(t)));
112
+ root.style.transform = `scale(${cameraScale(settings.move, t, settings.duration)})`;
113
+ };
114
+ const dispose = () => {
115
+ for (const item of items)
116
+ clearItem(item);
117
+ for (const counter of counters) {
118
+ counter.el.textContent = counter.text;
119
+ counter.el.style.removeProperty("transform");
120
+ }
121
+ root.style.removeProperty("transform");
122
+ root.style.removeProperty("--drift");
123
+ };
124
+ seek(0);
125
+ return { seek, dispose, ready: fontsReady(root) };
126
+ };
127
+ /**
128
+ * An overlay: the entrance timeline plus an eased fade of the whole layer in and out of its
129
+ * time span. `hooks.update(t)` draws scene-specific state; `hooks.reset()` undoes it on dispose.
130
+ * @param {HTMLElement} root
131
+ * @param {SceneConfig} config
132
+ * @param {RuntimeContext} ctx
133
+ * @param {Plan} plan
134
+ * @param {{ update?: (t: number) => void, reset?: () => void }} [hooks]
135
+ * @returns {Runtime}
136
+ */
137
+ export const mountOverlay = (root, config, ctx, plan, hooks = {}) => {
138
+ const settings = readSettings(root, config, ctx);
139
+ const inner = mountTimeline(root, config, ctx, plan);
140
+ /** @param {number} t */
141
+ const seek = (t) => {
142
+ inner.seek(t);
143
+ root.style.opacity = String(overlayEnvelope(t, settings.duration, settings.ease));
144
+ hooks.update?.(t);
145
+ };
146
+ const dispose = () => {
147
+ inner.dispose();
148
+ root.style.removeProperty("opacity");
149
+ hooks.reset?.();
150
+ };
151
+ seek(0);
152
+ return { seek, dispose, ready: inner.ready };
153
+ };