@liqweed/motion-kit 0.0.0-stage → 0.2.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.
Files changed (55) hide show
  1. package/.claude-plugin/marketplace.json +13 -0
  2. package/.claude-plugin/plugin.json +9 -0
  3. package/LICENSE +21 -0
  4. package/README.md +119 -2
  5. package/adapters/astro/AnimatedDiagram.astro +55 -0
  6. package/adapters/page/README.md +22 -0
  7. package/adapters/slidev/AnimatedDiagram.vue +137 -0
  8. package/brand/logo.scene.mjs +115 -0
  9. package/cli/motion-kit.mjs +239 -0
  10. package/docs/spec/technique.md +447 -0
  11. package/examples/agent-loop.json +18 -0
  12. package/examples/custom-pulse.scene.mjs +141 -0
  13. package/examples/integrations.json +20 -0
  14. package/examples/order-flow.json +17 -0
  15. package/examples/release-pipeline.json +17 -0
  16. package/examples/smart-home.json +17 -0
  17. package/lib/build.mjs +62 -0
  18. package/lib/bundle.mjs +68 -0
  19. package/lib/check.mjs +86 -0
  20. package/lib/export.mjs +113 -0
  21. package/lib/icon.mjs +41 -0
  22. package/lib/load.mjs +53 -0
  23. package/lib/raster.mjs +69 -0
  24. package/lib/video.mjs +77 -0
  25. package/package.json +69 -5
  26. package/runtime/bake.mjs +61 -0
  27. package/runtime/motion.mjs +154 -0
  28. package/runtime/parts.mjs +123 -0
  29. package/runtime/player.mjs +207 -0
  30. package/runtime/scene.mjs +101 -0
  31. package/runtime/style.mjs +142 -0
  32. package/runtime/svg.mjs +165 -0
  33. package/runtime/types/hub-spoke.mjs +215 -0
  34. package/runtime/types/index.mjs +25 -0
  35. package/runtime/types/sequence.mjs +201 -0
  36. package/runtime/wrap.mjs +44 -0
  37. package/skills/animated-diagram/SKILL.md +90 -0
  38. package/skills/animated-diagram/references/custom-scenes.md +56 -0
  39. package/skills/animated-diagram/references/ecosystem.md +28 -0
  40. package/skills/animated-diagram/references/interactivity.md +38 -0
  41. package/skills/animated-diagram/references/motion-vocabulary.md +70 -0
  42. package/skills/animated-diagram/references/qc.md +41 -0
  43. package/skills/animated-diagram/references/scene-types.md +59 -0
  44. package/skills/animated-diagram/references/styles.md +55 -0
  45. package/skills/animated-diagram/references/targets.md +27 -0
  46. package/skills/animated-diagram/references/technique.md +148 -0
  47. package/skills/motion-render/SKILL.md +68 -0
  48. package/skills/motion-render/references/formats.md +18 -0
  49. package/skills/motion-render/references/slides.md +18 -0
  50. package/skills/motion-render/references/video.md +61 -0
  51. package/skills/project-logo/SKILL.md +72 -0
  52. package/skills/project-logo/references/design.md +22 -0
  53. package/skills/project-logo/references/discovery.md +15 -0
  54. package/skills/project-logo/references/external-prompt.md +23 -0
  55. package/styles/neutral.json +26 -0
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "motion-kit",
3
+ "owner": { "name": "Ophir Radnitz" },
4
+ "metadata": { "description": "motion-kit: animated diagram skills" },
5
+ "plugins": [
6
+ {
7
+ "name": "motion-kit",
8
+ "source": "./",
9
+ "description": "animated-diagram, motion-render and project-logo skills and the motion-kit runtime/CLI",
10
+ "version": "0.2.0"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "motion-kit",
3
+ "version": "0.2.0",
4
+ "description": "Deterministic animated diagrams: scenes as pure functions of time for live pages, Slidev, slide frames, baked SVG and video; plus project logos/icons.",
5
+ "author": { "name": "Ophir Radnitz" },
6
+ "repository": "https://github.com/liqweed/motion-kit",
7
+ "license": "MIT",
8
+ "keywords": ["animation", "diagrams", "svg", "slides", "video", "explainer"]
9
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ophir Radnitz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ <p align="center"><img src="assets/icon-animated.svg" width="112" alt="motion-kit logo"></p>
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # motion-kit
4
+
5
+ Deterministic animated diagrams. A scene is a **pure function of time**,
6
+ `frame(t) → SVG`. The same scene serves:
7
+
8
+ - a live, interactive player (web pages, Craft Pages, Astro islands),
9
+ - Slidev decks (one build step per click),
10
+ - slide-ready step frames (SVG/PNG, light/dark, any format),
11
+ - a zero-JS baked animated SVG (READMEs, notes, chat previews),
12
+ - MP4 / WebM / GIF video in 16:9, 4:3, 1:1 and 9:16.
13
+
14
+ Open source under the [MIT licence](LICENSE). Consumers vendor the runtime (see below).
15
+
16
+ ## Examples
17
+
18
+ Baked with `motion-kit bake`: zero-JS animated SVGs that play once in this
19
+ README and follow your GitHub theme. Regenerate with `npm run media`.
20
+
21
+ <picture>
22
+ <source media="(prefers-color-scheme: dark)" srcset="docs/media/order-flow-dark.svg">
23
+ <img src="docs/media/order-flow-light.svg" alt="order-flow: a sequence scene" width="720">
24
+ </picture>
25
+
26
+ <picture>
27
+ <source media="(prefers-color-scheme: dark)" srcset="docs/media/smart-home-dark.svg">
28
+ <img src="docs/media/smart-home-light.svg" alt="smart-home: a hub-and-spoke scene" width="720">
29
+ </picture>
30
+
31
+ The interactive player (scrubber, steps, captions) needs scripts, which
32
+ GitHub does not run: `node cli/motion-kit.mjs build examples/order-flow.json -o out/order.html`
33
+ and open the file.
34
+
35
+ ## Quick start
36
+
37
+ ```bash
38
+ npx @liqweed/motion-kit --help # or: npm i -g @liqweed/motion-kit (installs `motion-kit`)
39
+ npm install # optional: @resvg/resvg-js for PNG/video
40
+ node cli/motion-kit.mjs check examples/order-flow.json
41
+ node cli/motion-kit.mjs build examples/order-flow.json -o out/order.html -f wide -l nl
42
+ node cli/motion-kit.mjs export examples/smart-home.json -o out/slides --png --qc
43
+ node cli/motion-kit.mjs bake examples/order-flow.json -o out/order.svg -f wide
44
+ node cli/motion-kit.mjs video examples/smart-home.json -f 9:16 -o out/reel.mp4 --sheet out/sheet.png
45
+ node cli/motion-kit.mjs icon brand/logo.scene.mjs -o . # project icon set: assets/ + .idea/
46
+ npm test
47
+ npm run gate # typecheck, versions, tests, scene gate, media freshness
48
+ ```
49
+
50
+ Requirements: Node ≥ 22. PNG and video: `@resvg/resvg-js` (optional
51
+ dependency) or Chrome; video: `ffmpeg`.
52
+
53
+ ## Layout
54
+
55
+ ```
56
+ runtime/ dependency-free ES modules (browser + Node)
57
+ motion.mjs easing (exact cubic-bezier), progress, critically damped spring, retarget, split edges
58
+ svg.mjs escaping, rounding, el/text/fade, polyline + Bézier arc-length, drawOn
59
+ wrap.mjs label wrapping with hard budgets
60
+ style.mjs tokens, neutral style, contrast checks, token resolution
61
+ scene.mjs scene contract, formats, renderSvg
62
+ parts.mjs shared node/label drawing
63
+ types/ spec-driven scene types: sequence, hub-spoke
64
+ bake.mjs zero-JS animated SVG
65
+ player.mjs live player (controls, a11y, reduced motion, capture hook)
66
+ lib/ Node-side: check (gate), export, build (HTML inliner), raster, video, icon
67
+ adapters/ slidev (Vue), astro, page (README)
68
+ skills/ animated-diagram, motion-render, project-logo (Claude Code / Craft skills)
69
+ examples/ order-flow (sequence), smart-home (hub-spoke), custom-pulse (custom module)
70
+ brand/ logo scene (built with motion-kit); renders go to assets/ + .idea/ (npm run media)
71
+ assets/ generated project icon: icon.svg, icon.png, icon-animated.svg
72
+ docs/media/ baked README animations (generated: npm run media)
73
+ docs/ prd.md, roadmap.md, spec/technique.md
74
+ styles/ neutral.json (the only style shipped; brands live in their repos)
75
+ ```
76
+
77
+ ## Install the skills
78
+
79
+ - **Claude Code** (all projects):
80
+ `claude plugin marketplace add liqweed/motion-kit` →
81
+ `claude plugin install motion-kit@motion-kit`
82
+ - **Craft Agent:** symlink `~/.agents/skills/animated-diagram`,
83
+ `~/.agents/skills/motion-render` and `~/.agents/skills/project-logo` to
84
+ `skills/*` in this clone.
85
+
86
+ The skills look for this clone at `~/workspace/motion-kit` first (it has
87
+ `node_modules`), then fall back to the plugin copy.
88
+
89
+ ## Use in another repo (vendor)
90
+
91
+ ```bash
92
+ node cli/motion-kit.mjs vendor <repo>/components/motion-kit --adapter slidev # or astro / page
93
+ ```
94
+
95
+ Copies `runtime/`, the adapter, `lib/check.mjs` and `LICENSE`; writes a gate
96
+ script and `MOTION_KIT_VERSION`. Don't edit vendored files; change motion-kit
97
+ and re-vendor. Vendoring keeps consumer CI
98
+ self-contained (no install step, no network).
99
+
100
+ ## Rules (the gate enforces them)
101
+
102
+ Deterministic bytes · settled step frames · rounded numbers · token-only colours ·
103
+ escaped labels · labels fit their budget in every locale · holds the final frame ·
104
+ ≤ ~8–10 s · no clock or randomness in scenes. See
105
+ `skills/animated-diagram/references/technique.md`.
106
+
107
+ ## Licence and credits
108
+
109
+ MIT, see [LICENSE](LICENSE). Keep the copied `LICENSE` file and the SPDX
110
+ headers when redistributing vendored files.
111
+
112
+ Ideas borrowed with thanks: the contact-sheet self-check and hover-linking
113
+ from [visual-explainer](https://github.com/nicobailon/visual-explainer), and
114
+ in-SVG pause and reduced-motion handling from Dashmotion. See
115
+ [`skills/animated-diagram/references/ecosystem.md`](skills/animated-diagram/references/ecosystem.md)
116
+ for related tools and when to use them instead.
117
+
118
+ Pull requests here are reviewed with the help of
119
+ [CodeRabbit](https://coderabbit.ai), which supports open source projects for
120
+ free. Thank you, CodeRabbit, for the support.
@@ -0,0 +1,55 @@
1
+ ---
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) 2026 Ophir Radnitz
4
+ /**
5
+ * motion-kit · Astro adapter (reference).
6
+ *
7
+ * Server-renders the FINAL frame (no-JS visitors, crawlers and reduced-motion
8
+ * users get the complete diagram), then the client script mounts the live
9
+ * player, which replays once when the diagram scrolls into view.
10
+ *
11
+ * import AnimatedDiagram from "../motion-kit/adapter/AnimatedDiagram.astro";
12
+ * import spec from "../diagrams/order-flow.json";
13
+ * <AnimatedDiagram spec={spec} format="wide" locale="nl" class="hidden lg:block" />
14
+ * <AnimatedDiagram spec={spec} format="tall" locale="nl" class="lg:hidden" />
15
+ *
16
+ * Mount a wide and a tall instance and switch with CSS: display:none also
17
+ * removes the hidden one from the accessibility tree and its autoplay observer.
18
+ * Pass only serializable props (a spec, not a scene object).
19
+ */
20
+ import { renderSvg } from "../runtime/scene.mjs";
21
+ import { createScene } from "../runtime/types/index.mjs";
22
+
23
+ interface Props {
24
+ spec: Record<string, unknown>;
25
+ format?: string;
26
+ locale?: string;
27
+ class?: string;
28
+ scrubber?: boolean;
29
+ labels?: Record<string, string>;
30
+ }
31
+ const { spec, format = "16:9", locale = "en", class: className, scrubber = false, labels } = Astro.props;
32
+ const scene = createScene(spec, { format, locale });
33
+ const fallback = renderSvg(scene, scene.duration, { live: true, idPrefix: `${scene.id}-ssr` });
34
+ ---
35
+
36
+ <div
37
+ class:list={["mk-astro", className]}
38
+ data-mk-spec={JSON.stringify(spec)}
39
+ data-mk-opts={JSON.stringify({ format, locale, scrubber, labels })}
40
+ set:html={fallback}
41
+ />
42
+
43
+ <script>
44
+ import { mountPlayer } from "../runtime/player.mjs";
45
+ import { createScene } from "../runtime/types/index.mjs";
46
+
47
+ for (const el of document.querySelectorAll<HTMLElement>("[data-mk-spec]")) {
48
+ if (el.dataset.mkMounted) continue;
49
+ el.dataset.mkMounted = "1";
50
+ const spec = JSON.parse(el.dataset.mkSpec ?? "{}");
51
+ const opts = JSON.parse(el.dataset.mkOpts ?? "{}");
52
+ const scene = createScene(spec, { format: opts.format, locale: opts.locale });
53
+ mountPlayer(el, scene, { scrubber: opts.scrubber, labels: opts.labels, id: `${scene.id}-${Math.random().toString(36).slice(2, 7)}` });
54
+ }
55
+ </script>
@@ -0,0 +1,22 @@
1
+ # Page adapter (self-contained HTML)
2
+
3
+ No component to copy: `motion-kit build` inlines the runtime and the player
4
+ into one HTML document with no network requests.
5
+
6
+ ```bash
7
+ motion-kit build diagram.json --out diagram.html [--format wide] [--locale nl] [--style brand.json]
8
+ ```
9
+
10
+ - **Craft Pages:** pass the file's content to `create_page` / `update_page`.
11
+ Pages block all network egress (`connect-src 'none'`), and this output makes
12
+ no requests.
13
+ - **Craft in-chat `html-preview`:** scripts are blocked there. Use
14
+ `motion-kit bake` (zero-JS animated SVG) or step PNGs via `image-preview`.
15
+ - **Static hosting / file://:** works as is.
16
+
17
+ The final frame is pre-rendered into the markup, so the diagram is complete
18
+ before JS runs. The player replays once on scroll-into-view, shows pause/play,
19
+ step buttons, a scrubber and captions, and respects `prefers-reduced-motion`
20
+ and `prefers-color-scheme`.
21
+
22
+ Capture hook for renderers: `window.__motionKit[sceneId].seek(t)`.
@@ -0,0 +1,137 @@
1
+ <!--
2
+ SPDX-License-Identifier: MIT
3
+ Copyright (c) 2026 Ophir Radnitz
4
+
5
+ motion-kit · Slidev adapter (verified against Slidev 53).
6
+
7
+ Each slide click advances one build step. The component registers its own
8
+ clicks with the slide (the same API Slidev's ShikiMagicMove uses), so no
9
+ `clicks:` frontmatter is needed and it composes with v-click elements.
10
+
11
+ - Step 1 shows on arrival (its entrance plays once); clicks 1…N−1 advance.
12
+ - Forward by one click: animates from the previous step's time to the next.
13
+ Back or jump: seeks with no animation.
14
+ - Overview, presenter next-preview, print/PDF/PNG export (`isPrintMode`) and
15
+ prefers-reduced-motion: always the settled step frame, so
16
+ `slidev export --with-clicks` writes one clean frame per click.
17
+ - Light/dark follows Slidev's dark mode unless `theme` is set.
18
+
19
+ Usage in a slide:
20
+
21
+ <script setup>
22
+ import spec from './diagrams/order-flow.json'
23
+ </script>
24
+
25
+ <AnimatedDiagram :spec="spec" format="16:9" locale="en" />
26
+
27
+ Props:
28
+ spec scene spec (JSON) for a registered scene type, or
29
+ scene a ready scene object (custom scene module output)
30
+ format "16:9" | "4:3" | "1:1" | "9:16" | "wide" | "tall" (default "16:9")
31
+ locale string (default "en")
32
+ at Slidev click position of the first advance (default "+1")
33
+ intro play the entrance up to step 1 when the slide opens (default true)
34
+ theme "light" | "dark" (default: follow Slidev dark mode)
35
+ styleSpec style object (tokens); default neutral
36
+ maxHeight CSS length; default "380px" fits under a slide title on Slidev's
37
+ 980×552 canvas. Use "100%" (with a full-height parent) for
38
+ full-bleed diagram slides.
39
+ -->
40
+ <script setup>
41
+ import { useDarkMode, useNav, useSlideContext } from "@slidev/client";
42
+ import { computed, onMounted, onUnmounted, ref, unref, watch } from "vue";
43
+ import { renderSvg } from "../runtime/scene.mjs";
44
+ import { cssVars, normalizeStyle } from "../runtime/style.mjs";
45
+ import { createScene } from "../runtime/types/index.mjs";
46
+
47
+ const props = defineProps({
48
+ spec: { type: Object, default: null },
49
+ scene: { type: Object, default: null },
50
+ format: { type: String, default: "16:9" },
51
+ locale: { type: String, default: "en" },
52
+ at: { type: [String, Number], default: "+1" },
53
+ intro: { type: Boolean, default: true },
54
+ theme: { type: String, default: undefined },
55
+ styleSpec: { type: Object, default: null },
56
+ maxHeight: { type: String, default: "380px" },
57
+ });
58
+
59
+ const { $clicksContext: clicks, $renderContext } = useSlideContext();
60
+ const { isPrintMode } = useNav();
61
+ const { isDark } = useDarkMode();
62
+
63
+ const scene = computed(() => props.scene ?? createScene(props.spec, { format: props.format, locale: props.locale }));
64
+ const style = computed(() => normalizeStyle(props.styleSpec ?? "neutral"));
65
+ const n = scene.value.steps.length;
66
+ const id = `mk-${scene.value.id}-${Math.random().toString(36).slice(2, 8)}`;
67
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
68
+ const animated = computed(() => ["slide", "presenter"].includes(unref($renderContext)) && !isPrintMode.value && !reduced);
69
+
70
+ // Register N−1 clicks (step 1 is shown on arrival).
71
+ const info = clicks && n > 1 ? clicks.calculateSince(props.at, n - 1) : null;
72
+ const stepIndex = computed(() => {
73
+ if (!info || !clicks) return n - 1;
74
+ return Math.min(Math.max(clicks.current - info.start + 1, 0), n - 1);
75
+ });
76
+
77
+ const t = ref(scene.value.steps[stepIndex.value].at);
78
+ let raf = 0;
79
+
80
+ function animate(from, to) {
81
+ cancelAnimationFrame(raf);
82
+ if (!animated.value || to <= from) {
83
+ t.value = to;
84
+ return;
85
+ }
86
+ const start = performance.now();
87
+ const tick = (now) => {
88
+ const v = Math.min(from + (now - start) / 1000, to);
89
+ t.value = v;
90
+ if (v < to) raf = requestAnimationFrame(tick);
91
+ };
92
+ t.value = from;
93
+ raf = requestAnimationFrame(tick);
94
+ }
95
+
96
+ watch(stepIndex, (next, prev) => {
97
+ const steps = scene.value.steps;
98
+ if (next === prev + 1) animate(steps[prev].at, steps[next].at);
99
+ else {
100
+ cancelAnimationFrame(raf);
101
+ t.value = steps[next].at;
102
+ }
103
+ });
104
+
105
+ onMounted(() => {
106
+ if (info) clicks.register(id, info);
107
+ if (animated.value && props.intro && stepIndex.value === 0) animate(0, scene.value.steps[0].at);
108
+ });
109
+ onUnmounted(() => {
110
+ cancelAnimationFrame(raf);
111
+ clicks?.unregister(id);
112
+ });
113
+
114
+ const dark = computed(() => (props.theme ? props.theme === "dark" : isDark.value));
115
+ const markup = computed(() => renderSvg(scene.value, t.value, { style: style.value, live: true, idPrefix: id }));
116
+ const vars = computed(() => `${cssVars(style.value, dark.value ? "dark" : "light")};--mk-max-h:${props.maxHeight}`);
117
+ </script>
118
+
119
+ <template>
120
+ <figure class="mk-slidev" :style="vars" :data-mk-step="stepIndex + 1">
121
+ <div class="mk-slidev-stage" v-html="markup" />
122
+ </figure>
123
+ </template>
124
+
125
+ <style scoped>
126
+ .mk-slidev {
127
+ margin: 0;
128
+ width: 100%;
129
+ }
130
+ .mk-slidev-stage :deep(svg) {
131
+ display: block;
132
+ width: 100%;
133
+ height: auto;
134
+ max-height: var(--mk-max-h, 380px);
135
+ margin: 0 auto;
136
+ }
137
+ </style>
@@ -0,0 +1,115 @@
1
+ /**
2
+ * motion-kit logo: the standard easing curve, cubic-bezier(0.4, 0, 0.2, 1),
3
+ * drawn as a design tool shows it — two keyframes, their handles, and the path
4
+ * between them — on a rounded accent tile. It animates as motion-kit animates
5
+ * anything: the tile settles, the handles appear, the curve draws on, a packet
6
+ * runs the curve and the end keyframe lands.
7
+ *
8
+ * The final frame is the static mark. Square and readable down to ~32 px.
9
+ *
10
+ * node cli/motion-kit.mjs icon brand/logo.scene.mjs -o . (or: npm run media)
11
+ *
12
+ * Also the template the project-logo skill starts from for other projects:
13
+ * it takes the runtime from `kit` (passed by motion-kit's CLI) instead of
14
+ * importing it, so a copy works from any repository without vendoring.
15
+ */
16
+
17
+ const S = 720; // square viewBox; every format renders the same square mark
18
+ const TILE = { inset: 40, radius: 168 };
19
+ // Curve box: keyframe A bottom-left, keyframe B top-right (y grows downward).
20
+ const BOX = { x0: 196, y0: 524, x1: 524, y1: 196 };
21
+ const map = (u, v) => ({ x: BOX.x0 + u * (BOX.x1 - BOX.x0), y: BOX.y0 + v * (BOX.y1 - BOX.y0) });
22
+ const A = map(0, 0);
23
+ const B = map(1, 1);
24
+ const H1 = map(0.4, 0); // handle out of A (x1, y1)
25
+ const H2 = map(0.2, 1); // handle into B (x2, y2)
26
+
27
+ const STROKE = 30;
28
+ const DOT = 40;
29
+ const HANDLE = 9;
30
+ const KNOB = 26;
31
+
32
+ const T_TILE = 0;
33
+ const T_HANDLES = 0.35;
34
+ const T_DRAW = 0.6;
35
+ const DRAW = 0.9;
36
+ const T_PACKET = T_DRAW + DRAW + 0.05;
37
+ const TRAVEL = 0.8;
38
+ const LAG = 0.12;
39
+ const T_LAND = T_PACKET + TRAVEL + LAG;
40
+ const OMEGA = 16; // settles in 9.24 / 16 ≈ 0.58 s
41
+ const DURATION = T_LAND + 0.65;
42
+
43
+ /** @param {{kit: any}} opts */
44
+ export default function make({ kit }) {
45
+ const { easeOut, easeStandard, progress, splitEdge, springTo, tok, cubic, drawOn, el, fade, num, scaleAbout } = kit;
46
+ const CURVE = cubic(A, H1, H2, B);
47
+
48
+ function frame(t) {
49
+ const out = [];
50
+ // Tile: springs from 0.86 to full size while fading in.
51
+ const grow = springTo(t, 0.86, [{ at: T_TILE, to: 1 }], OMEGA);
52
+ const tileIn = progress(t, T_TILE, 0.3, easeOut);
53
+ out.push(
54
+ fade(
55
+ tileIn,
56
+ { transform: grow < 0.9995 ? scaleAbout(grow, S / 2, S / 2) : undefined },
57
+ el("rect", {
58
+ x: TILE.inset,
59
+ y: TILE.inset,
60
+ width: S - 2 * TILE.inset,
61
+ height: S - 2 * TILE.inset,
62
+ rx: TILE.radius,
63
+ fill: tok("accent"),
64
+ }),
65
+ ),
66
+ );
67
+
68
+ // Bézier handles: thin lines with square knobs.
69
+ const handles = progress(t, T_HANDLES, 0.35, easeOut);
70
+ const handle = (from, to) =>
71
+ el(
72
+ "g",
73
+ {},
74
+ el("line", { x1: num(from.x), y1: num(from.y), x2: num(to.x), y2: num(to.y), stroke: tok("onAccent"), "stroke-width": HANDLE, "stroke-linecap": "round" }),
75
+ el("rect", { x: num(to.x - KNOB / 2), y: num(to.y - KNOB / 2), width: KNOB, height: KNOB, rx: 5, fill: tok("onAccent") }),
76
+ );
77
+ out.push(fade(handles * 0.55, {}, handle(A, H1), handle(B, H2)));
78
+
79
+ // The curve draws on.
80
+ const dash = drawOn(CURVE.length, progress(t, T_DRAW, DRAW, easeStandard));
81
+ if (dash) out.push(el("path", { d: CURVE.d, fill: "none", stroke: tok("onAccent"), "stroke-width": STROKE, "stroke-linecap": "round", ...dash }));
82
+
83
+ // Start keyframe: a ring that appears with the handles.
84
+ out.push(
85
+ fade(handles, {}, el("circle", { cx: A.x, cy: A.y, r: DOT, fill: tok("accent"), stroke: tok("onAccent"), "stroke-width": 14 })),
86
+ );
87
+
88
+ // Packet: a capsule that stretches as it runs the curve (split edges).
89
+ const { lead, trail } = splitEdge(t, T_PACKET, TRAVEL, LAG);
90
+ if (lead > 0 && trail < 1) {
91
+ const a = CURVE.at(trail);
92
+ const b = CURVE.at(lead);
93
+ out.push(el("line", { x1: num(a.x), y1: num(a.y), x2: num(b.x), y2: num(b.y), stroke: tok("emphasis"), "stroke-width": STROKE + 6, "stroke-linecap": "round" }));
94
+ }
95
+
96
+ // End keyframe lands in the emphasis colour with a spring pop.
97
+ if (t >= T_LAND) {
98
+ const pop = springTo(t, 0.4, [{ at: T_LAND, to: 1 }], OMEGA);
99
+ out.push(el("circle", { cx: B.x, cy: B.y, r: num(DOT * pop), fill: tok("emphasis"), stroke: tok("onAccent"), "stroke-width": 14 }));
100
+ }
101
+ return out.join("");
102
+ }
103
+
104
+ return {
105
+ id: "motion-kit-logo",
106
+ width: S,
107
+ height: S,
108
+ duration: DURATION,
109
+ title: "motion-kit",
110
+ description: "An easing curve between two keyframes on a blue tile: the motion-kit logo.",
111
+ stepLabelsInFrame: false,
112
+ steps: [{ at: DURATION, label: "Logo" }],
113
+ frame,
114
+ };
115
+ }