@liqweed/motion-kit 0.11.0 → 0.13.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/lib/check.mjs CHANGED
@@ -9,7 +9,7 @@
9
9
  * Over files, formats and locales (the CLI and the vendored gate): lib/gate.mjs.
10
10
  */
11
11
  import { labelProblems } from "../runtime/iso.mjs";
12
- import { renderSvg, validateScene } from "../runtime/scene.mjs";
12
+ import { renderSvg, safeId, validateScene } from "../runtime/scene.mjs";
13
13
  import { contrastReport, normalizeStyle } from "../runtime/style.mjs";
14
14
 
15
15
  const SAMPLES = 120;
@@ -187,6 +187,9 @@ function underStubbedClock({ now, perf, random }, fn) {
187
187
  */
188
188
  export const SETTLE_AFTER = Object.freeze([0.001, 0.015, 0.03, 0.045]);
189
189
 
190
+ /** The most problems a scene reports before the gate stops looking. */
191
+ const MAX_PROBLEMS = 13;
192
+
190
193
  /**
191
194
  * Run the scene gate on one built scene.
192
195
  * @param {import("../runtime/scene.mjs").Scene} scene
@@ -220,7 +223,7 @@ export function checkScene(scene, { samples = SAMPLES, style } = {}) {
220
223
  if (wf) problems.push(`malformed at t=${t.toFixed(3)}: ${wf}`);
221
224
  const long = a.match(/-?\d+\.\d{5,}/);
222
225
  if (long) problems.push(`unrounded number ${long[0]} at t=${t.toFixed(3)} (use num())`);
223
- const frame = scene.frame(Math.min(t, scene.duration), { idPrefix: scene.id, style });
226
+ const frame = scene.frame(Math.min(t, scene.duration), { idPrefix: safeId(scene.id), style });
224
227
  const lit = findColourLiteral(frame);
225
228
  if (lit) problems.push(`colour literal ${lit} at t=${t.toFixed(3)} (use tok())`);
226
229
  if (/NaN|undefined|Infinity/.test(frame)) problems.push(`NaN/undefined/Infinity in frame at t=${t.toFixed(3)}`);
@@ -237,7 +240,7 @@ export function checkScene(scene, { samples = SAMPLES, style } = {}) {
237
240
  break;
238
241
  }
239
242
  }
240
- if (problems.length > 12) break;
243
+ if (problems.length >= MAX_PROBLEMS) break;
241
244
  }
242
245
 
243
246
  // 2. Settled steps: nothing moves at a step's time. The step's own motion
@@ -259,7 +262,7 @@ export function checkScene(scene, { samples = SAMPLES, style } = {}) {
259
262
  const lastFrame = render(scene.duration);
260
263
  if (first === lastFrame) problems.push("first and last frame are identical: nothing animates");
261
264
  if (scene.steps[scene.steps.length - 1].at > scene.duration) problems.push("last step is after duration");
262
- if (scene.frame(scene.duration + 5, { idPrefix: scene.id, style }) !== scene.frame(scene.duration, { idPrefix: scene.id, style })) problems.push("frames after the end differ from the final frame (must hold)");
265
+ if (scene.frame(scene.duration + 5, { idPrefix: safeId(scene.id), style }) !== scene.frame(scene.duration, { idPrefix: safeId(scene.id), style })) problems.push("frames after the end differ from the final frame (must hold)");
263
266
 
264
267
  // 4. Hard limit: 12 s. Authoring target: 8 s; these are distinct.
265
268
  if (scene.duration > 12) problems.push(`duration ${scene.duration.toFixed(1)}s exceeds the 12 s limit (aim for ≤ 8 s)`);
@@ -286,7 +289,10 @@ export function checkScene(scene, { samples = SAMPLES, style } = {}) {
286
289
  const second = ids("mk-gate-b");
287
290
  for (const id of ids("mk-gate-a")) if (second.has(id)) fixed.add(id);
288
291
  }
289
- for (const id of fixed) problems.push(`fixed id "${id}": build ids from frame(t, { idPrefix }), e.g. \`\${idPrefix}-${id}\``);
292
+ for (const id of fixed) {
293
+ if (problems.length >= MAX_PROBLEMS) break;
294
+ problems.push(`fixed id "${id}": build ids from frame(t, { idPrefix }), e.g. \`\${idPrefix}-${id}\``);
295
+ }
290
296
 
291
297
  // 8. (Contrast, G12: checked first, above, by contrastReport.)
292
298
 
@@ -297,6 +303,7 @@ export function checkScene(scene, { samples = SAMPLES, style } = {}) {
297
303
  const seen = new Set();
298
304
  const times = [...Array.from({ length: samples + 1 }, (_, i) => at(i)), ...scene.steps.map((s) => s.at)].sort((a, b) => a - b);
299
305
  for (const t of times) {
306
+ if (problems.length >= MAX_PROBLEMS) break; // the cap: nothing more is asked of labelBoxes()
300
307
  let boxes;
301
308
  try {
302
309
  boxes = scene.labelBoxes(Math.min(t, scene.duration));
@@ -308,17 +315,16 @@ export function checkScene(scene, { samples = SAMPLES, style } = {}) {
308
315
  problems.push("labelBoxes() must return an array of label boxes");
309
316
  break;
310
317
  }
311
- const bad = boxes.findIndex((b) => !b || typeof b !== "object" || typeof b.id !== "string" || !["x", "y", "width", "height"].every((k) => Number.isFinite(b[k])) || (b.opacity !== undefined && !Number.isFinite(b.opacity)) || (b.stem !== undefined && (!b.stem || typeof b.stem !== "object" || !["x1", "y1", "x2", "y2"].every((k) => Number.isFinite(b.stem[k])))));
318
+ const bad = boxes.findIndex((b) => !b || typeof b !== "object" || typeof b.id !== "string" || !["x", "y", "width", "height"].every((k) => Number.isFinite(b[k])) || b.width < 0 || b.height < 0 || (b.opacity !== undefined && !Number.isFinite(b.opacity)) || (b.stem !== undefined && (!b.stem || typeof b.stem !== "object" || !["x1", "y1", "x2", "y2"].every((k) => Number.isFinite(b.stem[k])))));
312
319
  if (bad >= 0) {
313
- problems.push(`labelBoxes() entry ${bad} must be { id, x, y, width, height } with finite numbers (and a stem, when given, { x1, y1, x2, y2 }), at t=${t.toFixed(3)}`);
320
+ problems.push(`labelBoxes() entry ${bad} must be { id, x, y, width, height } with finite numbers (width and height not negative; and a stem, when given, { x1, y1, x2, y2 }), at t=${t.toFixed(3)}`);
314
321
  break;
315
322
  }
316
- for (const p of labelProblems(boxes, { width: scene.width, height: scene.height })) {
317
- if (seen.has(p)) continue;
323
+ // The limit is what is left of the 13-problem cap (the loop entry guarantees some); problems already seen are skipped, not counted.
324
+ for (const p of labelProblems(boxes, { width: scene.width, height: scene.height, limit: MAX_PROBLEMS - problems.length, ignore: seen })) {
318
325
  seen.add(p);
319
326
  problems.push(`${p} at t=${t.toFixed(3)}`);
320
327
  }
321
- if (problems.length > 12) break;
322
328
  }
323
329
  }
324
330
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liqweed/motion-kit",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Deterministic animated diagrams: scenes as pure functions of time, for live pages, slides, baked SVG and video.",
5
5
  "keywords": [
6
6
  "animation",
@@ -47,7 +47,7 @@
47
47
  "prepare": "lefthook install || true",
48
48
  "test": "node --test test/*.test.mjs",
49
49
  "typecheck": "tsc -p .",
50
- "check": "node cli/motion-kit.mjs check examples/order-flow.json examples/smart-home.json examples/release-pipeline.json examples/agent-loop.json examples/integrations.json examples/incident.json examples/web-stack.json examples/custom-pulse.scene.mjs examples/isometric-swivel.scene.mjs examples/connectors.scene.mjs brand/logo.scene.mjs examples/player-states.json examples/checkout.json examples/connection.json examples/pull-request.json",
50
+ "check": "node cli/motion-kit.mjs check examples/order-flow.json examples/smart-home.json examples/release-pipeline.json examples/agent-loop.json examples/integrations.json examples/incident.json examples/web-stack.json examples/custom-pulse.scene.mjs examples/isometric-swivel.scene.mjs examples/connectors.scene.mjs examples/isometric-platform.scene.mjs examples/text-reveal.scene.mjs brand/logo.scene.mjs examples/player-states.json examples/checkout.json examples/connection.json examples/pull-request.json",
51
51
  "media": "scripts/render-media.sh",
52
52
  "media:check": "scripts/render-media.sh --check",
53
53
  "site": "npm run -w website build",