@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.
- package/.claude-plugin/marketplace.json +13 -0
- package/.claude-plugin/plugin.json +9 -0
- package/LICENSE +21 -0
- package/README.md +119 -2
- package/adapters/astro/AnimatedDiagram.astro +55 -0
- package/adapters/page/README.md +22 -0
- package/adapters/slidev/AnimatedDiagram.vue +137 -0
- package/brand/logo.scene.mjs +115 -0
- package/cli/motion-kit.mjs +239 -0
- package/docs/spec/technique.md +447 -0
- package/examples/agent-loop.json +18 -0
- package/examples/custom-pulse.scene.mjs +141 -0
- package/examples/integrations.json +20 -0
- package/examples/order-flow.json +17 -0
- package/examples/release-pipeline.json +17 -0
- package/examples/smart-home.json +17 -0
- package/lib/build.mjs +62 -0
- package/lib/bundle.mjs +68 -0
- package/lib/check.mjs +86 -0
- package/lib/export.mjs +113 -0
- package/lib/icon.mjs +41 -0
- package/lib/load.mjs +53 -0
- package/lib/raster.mjs +69 -0
- package/lib/video.mjs +77 -0
- package/package.json +69 -5
- package/runtime/bake.mjs +61 -0
- package/runtime/motion.mjs +154 -0
- package/runtime/parts.mjs +123 -0
- package/runtime/player.mjs +207 -0
- package/runtime/scene.mjs +101 -0
- package/runtime/style.mjs +142 -0
- package/runtime/svg.mjs +165 -0
- package/runtime/types/hub-spoke.mjs +215 -0
- package/runtime/types/index.mjs +25 -0
- package/runtime/types/sequence.mjs +201 -0
- package/runtime/wrap.mjs +44 -0
- package/skills/animated-diagram/SKILL.md +90 -0
- package/skills/animated-diagram/references/custom-scenes.md +56 -0
- package/skills/animated-diagram/references/ecosystem.md +28 -0
- package/skills/animated-diagram/references/interactivity.md +38 -0
- package/skills/animated-diagram/references/motion-vocabulary.md +70 -0
- package/skills/animated-diagram/references/qc.md +41 -0
- package/skills/animated-diagram/references/scene-types.md +59 -0
- package/skills/animated-diagram/references/styles.md +55 -0
- package/skills/animated-diagram/references/targets.md +27 -0
- package/skills/animated-diagram/references/technique.md +148 -0
- package/skills/motion-render/SKILL.md +68 -0
- package/skills/motion-render/references/formats.md +18 -0
- package/skills/motion-render/references/slides.md +18 -0
- package/skills/motion-render/references/video.md +61 -0
- package/skills/project-logo/SKILL.md +72 -0
- package/skills/project-logo/references/design.md +22 -0
- package/skills/project-logo/references/discovery.md +15 -0
- package/skills/project-logo/references/external-prompt.md +23 -0
- package/styles/neutral.json +26 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* motion-kit CLI.
|
|
4
|
+
*
|
|
5
|
+
* motion-kit check <scene...> [--format F] [--locale L] gate (all formats/locales by default)
|
|
6
|
+
* motion-kit build <scene> --out x.html [--format F] [--locale L] [--style S] [--no-scrubber] [--no-heading]
|
|
7
|
+
* motion-kit export <scene> --out dir [--format F] [--locale L] [--style S] [--theme light|dark] [--png] [--scale 2] [--qc] [--background]
|
|
8
|
+
* motion-kit bake <scene> --out x.svg [--fps 15] [--theme ...] [--style S]
|
|
9
|
+
* motion-kit video <scene> --out x.mp4|.gif|.webm [--fps 30] [--scale 2] [--hold 1.5] [--sheet sheet.png]
|
|
10
|
+
* motion-kit icon <scene> --out <repo> [--size 512] [--style S] [--no-png] project icon set (assets/, .idea/)
|
|
11
|
+
* motion-kit vendor <dir> [--adapter page|slidev|astro]
|
|
12
|
+
* motion-kit formats | types
|
|
13
|
+
*
|
|
14
|
+
* <scene> is a spec (.json, any registered type) or a custom module (.mjs).
|
|
15
|
+
*/
|
|
16
|
+
import { cpSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { dirname, join, resolve } from "node:path";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { parseArgs } from "node:util";
|
|
20
|
+
import { bake, bakeStats } from "../runtime/bake.mjs";
|
|
21
|
+
import { FORMATS } from "../runtime/scene.mjs";
|
|
22
|
+
import { checkContrast } from "../runtime/style.mjs";
|
|
23
|
+
import { SCENE_TYPES } from "../runtime/types/index.mjs";
|
|
24
|
+
import { checkScene } from "../lib/check.mjs";
|
|
25
|
+
import { buildHtml } from "../lib/build.mjs";
|
|
26
|
+
import { writeIconSet } from "../lib/icon.mjs";
|
|
27
|
+
import { exportSteps } from "../lib/export.mjs";
|
|
28
|
+
import { loadScene, loadStyle } from "../lib/load.mjs";
|
|
29
|
+
import { rasterizer } from "../lib/raster.mjs";
|
|
30
|
+
import { probe, renderVideo, videoContactSheet } from "../lib/video.mjs";
|
|
31
|
+
|
|
32
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
33
|
+
const VERSION = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8")).version;
|
|
34
|
+
|
|
35
|
+
const { values: a, positionals } = parseArgs({
|
|
36
|
+
allowPositionals: true,
|
|
37
|
+
options: {
|
|
38
|
+
out: { type: "string", short: "o" },
|
|
39
|
+
format: { type: "string", short: "f" },
|
|
40
|
+
locale: { type: "string", short: "l" },
|
|
41
|
+
style: { type: "string", short: "s" },
|
|
42
|
+
theme: { type: "string", default: "light" },
|
|
43
|
+
png: { type: "boolean", default: false },
|
|
44
|
+
scale: { type: "string", default: "2" },
|
|
45
|
+
qc: { type: "boolean", default: false },
|
|
46
|
+
background: { type: "boolean", default: false },
|
|
47
|
+
fps: { type: "string" },
|
|
48
|
+
hold: { type: "string", default: "1.5" },
|
|
49
|
+
sheet: { type: "string" },
|
|
50
|
+
adapter: { type: "string", default: "page" },
|
|
51
|
+
size: { type: "string", default: "512" },
|
|
52
|
+
"no-png": { type: "boolean", default: false },
|
|
53
|
+
"no-scrubber": { type: "boolean", default: false },
|
|
54
|
+
"no-heading": { type: "boolean", default: false },
|
|
55
|
+
help: { type: "boolean", short: "h" },
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
const [cmd, ...args] = positionals;
|
|
59
|
+
|
|
60
|
+
function fail(msg) {
|
|
61
|
+
console.error(`motion-kit: ${msg}`);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
function need(v, what) {
|
|
65
|
+
if (!v) fail(`${cmd}: ${what} is required`);
|
|
66
|
+
return v;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function main() {
|
|
70
|
+
if (!cmd || a.help) {
|
|
71
|
+
const src = readFileSync(fileURLToPath(import.meta.url), "utf8");
|
|
72
|
+
console.log(src.slice(src.indexOf("/**") + 3, src.indexOf("*/")).replace(/^ \* ?/gm, ""));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const style = loadStyle(a.style);
|
|
76
|
+
const opts = { format: a.format ?? "16:9", locale: a.locale ?? "en" };
|
|
77
|
+
|
|
78
|
+
switch (cmd) {
|
|
79
|
+
case "formats":
|
|
80
|
+
for (const [k, v] of Object.entries(FORMATS)) console.log(`${k.padEnd(6)} ${v.width}×${v.height || "auto"}`);
|
|
81
|
+
return;
|
|
82
|
+
case "types":
|
|
83
|
+
console.log(Object.keys(SCENE_TYPES).join("\n"));
|
|
84
|
+
return;
|
|
85
|
+
case "check": {
|
|
86
|
+
if (!args.length) fail("check: give at least one scene file");
|
|
87
|
+
const styleProblems = checkContrast(style);
|
|
88
|
+
for (const p of styleProblems) console.error(`✗ style: ${p}`);
|
|
89
|
+
let bad = styleProblems.length;
|
|
90
|
+
for (const file of args) {
|
|
91
|
+
const formats = a.format ? [a.format] : Object.keys(FORMATS);
|
|
92
|
+
const raw = file.endsWith(".json") ? JSON.parse(readFileSync(file, "utf8")) : null;
|
|
93
|
+
const locales = a.locale ? [a.locale] : raw ? detectLocales(raw) : ["en"];
|
|
94
|
+
for (const format of formats) {
|
|
95
|
+
for (const locale of locales) {
|
|
96
|
+
try {
|
|
97
|
+
const { scene } = await loadScene(file, { format, locale });
|
|
98
|
+
const r = checkScene(scene);
|
|
99
|
+
if (r.ok) console.log(`✓ ${file} · ${format} · ${locale} · ${scene.duration.toFixed(2)} s · ${scene.steps.length} steps`);
|
|
100
|
+
else {
|
|
101
|
+
bad++;
|
|
102
|
+
console.error(`✗ ${file} · ${format} · ${locale}\n - ${r.problems.join("\n - ")}`);
|
|
103
|
+
}
|
|
104
|
+
} catch (e) {
|
|
105
|
+
bad++;
|
|
106
|
+
console.error(`✗ ${file} · ${format} · ${locale}: ${e instanceof Error ? e.message : e}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (bad) process.exit(1);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
case "build": {
|
|
115
|
+
const loaded = await loadScene(need(args[0], "<scene>"), opts);
|
|
116
|
+
const r = checkScene(loaded.scene);
|
|
117
|
+
if (!r.ok) fail(`scene fails the gate:\n - ${r.problems.join("\n - ")}`);
|
|
118
|
+
const html = buildHtml(loaded, { style, ...opts, scrubber: !a["no-scrubber"], heading: !a["no-heading"] });
|
|
119
|
+
if (/<\/script/i.test(html.slice(html.indexOf("<script>") + 8, html.lastIndexOf("</script>")))) fail("bundled code contains </script>");
|
|
120
|
+
const out = need(a.out, "--out");
|
|
121
|
+
mkdirSync(dirname(resolve(out)), { recursive: true });
|
|
122
|
+
writeFileSync(out, html);
|
|
123
|
+
console.log(`wrote ${out} (${(html.length / 1024).toFixed(1)} KB, self-contained)`);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
case "export": {
|
|
127
|
+
const file = need(args[0], "<scene>");
|
|
128
|
+
const { scene } = await loadScene(file, opts);
|
|
129
|
+
const r = checkScene(scene);
|
|
130
|
+
if (!r.ok) fail(`scene fails the gate:\n - ${r.problems.join("\n - ")}`);
|
|
131
|
+
if (a.png && !(await rasterizer())) fail("--png needs @resvg/resvg-js or Chrome");
|
|
132
|
+
const m = await exportSteps(scene, { out: need(a.out, "--out"), style, theme: a.theme, png: a.png, scale: Number(a.scale), qc: a.qc, background: a.background, sourceFile: resolve(file), version: VERSION });
|
|
133
|
+
console.log(`wrote ${m.files.length} frames + index.html + manifest.json to ${a.out}`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
case "bake": {
|
|
137
|
+
const { scene } = await loadScene(need(args[0], "<scene>"), opts);
|
|
138
|
+
const svg = bake(scene, { fps: Number(a.fps ?? 15), style, theme: a.theme, background: a.background });
|
|
139
|
+
const out = need(a.out, "--out");
|
|
140
|
+
writeFileSync(out, svg);
|
|
141
|
+
const s = bakeStats(svg);
|
|
142
|
+
console.log(`wrote ${out} (${s.frames} frames, ${(s.bytes / 1024).toFixed(0)} KB, zero JS)`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
case "video": {
|
|
146
|
+
const { scene } = await loadScene(need(args[0], "<scene>"), opts);
|
|
147
|
+
const out = need(a.out, "--out");
|
|
148
|
+
const r = await renderVideo(scene, {
|
|
149
|
+
out,
|
|
150
|
+
fps: Number(a.fps ?? 30),
|
|
151
|
+
scale: Number(a.scale),
|
|
152
|
+
hold: Number(a.hold),
|
|
153
|
+
style,
|
|
154
|
+
theme: a.theme,
|
|
155
|
+
onProgress: (f, n) => process.stderr.write(`\rframe ${f}/${n}`),
|
|
156
|
+
});
|
|
157
|
+
process.stderr.write("\n");
|
|
158
|
+
const p = probe(out);
|
|
159
|
+
console.log(`wrote ${out}: ${p.width}×${p.height}, ${p.duration.toFixed(2)} s, ${p.fps} fps (${r.frames} frames)`);
|
|
160
|
+
if (a.sheet) console.log(`contact sheet: ${videoContactSheet(out, a.sheet)}`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
case "icon": {
|
|
164
|
+
const { scene } = await loadScene(need(args[0], "<scene>"), { ...opts, format: a.format ?? "1:1" });
|
|
165
|
+
const r = checkScene(scene);
|
|
166
|
+
if (!r.ok) fail(`scene fails the gate:\n - ${r.problems.join("\n - ")}`);
|
|
167
|
+
const png = !a["no-png"];
|
|
168
|
+
if (png && !(await rasterizer())) fail("icon PNG needs @resvg/resvg-js or Chrome (or pass --no-png)");
|
|
169
|
+
const root = resolve(need(a.out, "--out"));
|
|
170
|
+
const files = await writeIconSet(scene, { root, style, size: Number(a.size), png });
|
|
171
|
+
console.log(`wrote to ${root}:\n ${files.join("\n ")}`);
|
|
172
|
+
if (files.includes(".idea/icon.svg")) console.log("note: if .idea/ is git-ignored, add !.idea/icon*.svg after it to commit the IDE icon");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
case "vendor": {
|
|
176
|
+
const dir = resolve(need(args[0], "<dir>"));
|
|
177
|
+
mkdirSync(dir, { recursive: true });
|
|
178
|
+
cpSync(join(ROOT, "LICENSE"), join(dir, "LICENSE"));
|
|
179
|
+
cpSync(join(ROOT, "runtime"), join(dir, "runtime"), { recursive: true });
|
|
180
|
+
const adapter = join(ROOT, "adapters", a.adapter);
|
|
181
|
+
cpSync(adapter, join(dir, "adapter"), { recursive: true });
|
|
182
|
+
mkdirSync(join(dir, "lib"), { recursive: true });
|
|
183
|
+
cpSync(join(ROOT, "lib", "check.mjs"), join(dir, "lib", "check.mjs"));
|
|
184
|
+
writeFileSync(join(dir, "check.mjs"), VENDOR_CHECK);
|
|
185
|
+
writeFileSync(join(dir, "MOTION_KIT_VERSION"), `motion-kit ${VERSION}\nadapter ${a.adapter}\nvendored from liqweed/motion-kit; do not edit here, re-vendor instead.\n`);
|
|
186
|
+
console.log(`vendored runtime + ${a.adapter} adapter (motion-kit ${VERSION}) into ${dir}`);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
default:
|
|
190
|
+
fail(`unknown command "${cmd}" (try --help)`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const VENDOR_CHECK = `#!/usr/bin/env node
|
|
195
|
+
// motion-kit gate for vendored copies: node check.mjs <spec.json...> [--format F]
|
|
196
|
+
// Checks every listed spec in every format (or --format) and every locale it contains.
|
|
197
|
+
import { readFileSync } from "node:fs";
|
|
198
|
+
import { checkScene } from "./lib/check.mjs";
|
|
199
|
+
import { FORMATS } from "./runtime/scene.mjs";
|
|
200
|
+
import { createScene } from "./runtime/types/index.mjs";
|
|
201
|
+
|
|
202
|
+
const args = process.argv.slice(2);
|
|
203
|
+
const fi = args.indexOf("--format");
|
|
204
|
+
const formats = fi >= 0 ? [args.splice(fi, 2)[1]] : Object.keys(FORMATS);
|
|
205
|
+
let bad = 0;
|
|
206
|
+
for (const file of args) {
|
|
207
|
+
const spec = JSON.parse(readFileSync(file, "utf8"));
|
|
208
|
+
const locales = new Set();
|
|
209
|
+
JSON.stringify(spec, (k, v) => {
|
|
210
|
+
if (v && typeof v === "object" && !Array.isArray(v) && Object.keys(v).length && Object.keys(v).every((x) => /^[a-z]{2}$/.test(x))) Object.keys(v).forEach((l) => locales.add(l));
|
|
211
|
+
return v;
|
|
212
|
+
});
|
|
213
|
+
for (const format of formats) {
|
|
214
|
+
for (const locale of locales.size ? locales : ["en"]) {
|
|
215
|
+
try {
|
|
216
|
+
const r = checkScene(createScene(spec, { format, locale }));
|
|
217
|
+
if (r.ok) console.log(\`✓ \${file} · \${format} · \${locale}\`);
|
|
218
|
+
else { bad++; console.error(\`✗ \${file} · \${format} · \${locale}\\n - \${r.problems.join("\\n - ")}\`); }
|
|
219
|
+
} catch (e) { bad++; console.error(\`✗ \${file} · \${format} · \${locale}: \${e.message}\`); }
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
process.exit(bad ? 1 : 0);
|
|
224
|
+
`;
|
|
225
|
+
|
|
226
|
+
function detectLocales(spec) {
|
|
227
|
+
const found = new Set();
|
|
228
|
+
const walk = (v) => {
|
|
229
|
+
if (v && typeof v === "object" && !Array.isArray(v)) {
|
|
230
|
+
const keys = Object.keys(v);
|
|
231
|
+
if (keys.length && keys.every((k) => /^[a-z]{2}(-[A-Z]{2})?$/.test(k) && typeof v[k] === "string")) keys.forEach((k) => found.add(k));
|
|
232
|
+
else Object.values(v).forEach(walk);
|
|
233
|
+
} else if (Array.isArray(v)) v.forEach(walk);
|
|
234
|
+
};
|
|
235
|
+
walk(spec);
|
|
236
|
+
return found.size ? [...found] : ["en"];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
main().catch((e) => fail(e.stack ?? e.message));
|