@johnoscott/isometric-engine 0.15.0 → 0.17.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 (78) hide show
  1. package/README.md +3 -1
  2. package/iso-editor.js +230 -193
  3. package/iso-remotion.js +353 -0
  4. package/iso-render.js +184 -147
  5. package/iso-systems.js +183 -146
  6. package/isometric-diagram.js +389 -0
  7. package/js/iso-core/arimo.js +5 -0
  8. package/js/iso-core/arimo.json +1 -0
  9. package/js/iso-core/index.js +8 -2
  10. package/js/iso-core/kernel.js +13 -2
  11. package/js/iso-core/mono.js +242 -0
  12. package/js/iso-editor/ui/canvas.js +23 -1
  13. package/js/iso-objects/ants.js +1 -1
  14. package/js/iso-objects/index.js +10 -2
  15. package/js/iso-objects/mono-paint.js +96 -0
  16. package/js/iso-objects/motion-doc.js +0 -79
  17. package/js/iso-objects/motion-entry.js +4 -2
  18. package/js/iso-objects/motion-schema.js +83 -0
  19. package/js/iso-objects/motion.js +9 -4
  20. package/js/iso-objects/timeline.js +60 -16
  21. package/js/iso-systems/compile.js +34 -3
  22. package/js/iso-systems/render.js +1 -1
  23. package/js/iso-systems/schema.json +1 -0
  24. package/js/iso-viewer/index.js +6 -0
  25. package/js/iso-viewer/page.js +40 -17
  26. package/js/iso-viewer/play.js +340 -0
  27. package/js/iso-viewer/player.js +147 -162
  28. package/js/iso-viewer/transport.js +289 -0
  29. package/package.json +61 -2
  30. package/src/iso-core/arimo.json +1 -0
  31. package/src/iso-core/arimo.ts +6 -0
  32. package/src/iso-core/index.ts +2 -1
  33. package/src/iso-core/kernel.ts +11 -1
  34. package/src/iso-core/mono.ts +306 -0
  35. package/src/iso-core/theme.ts +2 -1
  36. package/src/iso-editor/ui/canvas.ts +14 -1
  37. package/src/iso-objects/ants.ts +2 -2
  38. package/src/iso-objects/index.ts +5 -3
  39. package/src/iso-objects/mono-paint.ts +97 -0
  40. package/src/iso-objects/motion-doc.ts +0 -52
  41. package/src/iso-objects/motion-entry.ts +4 -3
  42. package/src/iso-objects/motion-schema.ts +55 -0
  43. package/src/iso-objects/motion.ts +6 -5
  44. package/src/iso-objects/scene.ts +3 -0
  45. package/src/iso-objects/timeline.ts +71 -15
  46. package/src/iso-objects/types.ts +2 -0
  47. package/src/iso-systems/compile.ts +37 -4
  48. package/src/iso-systems/render.ts +5 -1
  49. package/src/iso-systems/schema.json +1 -0
  50. package/src/iso-viewer/index.ts +4 -0
  51. package/src/iso-viewer/page.ts +28 -12
  52. package/src/iso-viewer/play.ts +280 -0
  53. package/src/iso-viewer/player.ts +133 -134
  54. package/src/iso-viewer/transport.ts +272 -0
  55. package/types/iso-core/arimo.d.ts +2 -0
  56. package/types/iso-core/index.d.ts +2 -1
  57. package/types/iso-core/kernel.d.ts +9 -0
  58. package/types/iso-core/mono.d.ts +61 -0
  59. package/types/iso-core/theme.d.ts +2 -0
  60. package/types/iso-objects/ants.d.ts +1 -0
  61. package/types/iso-objects/index.d.ts +5 -3
  62. package/types/iso-objects/mono-paint.d.ts +20 -0
  63. package/types/iso-objects/motion-doc.d.ts +0 -594
  64. package/types/iso-objects/motion-entry.d.ts +4 -3
  65. package/types/iso-objects/motion-schema.d.ts +594 -0
  66. package/types/iso-objects/motion.d.ts +4 -2
  67. package/types/iso-objects/scene.d.ts +3 -0
  68. package/types/iso-objects/timeline.d.ts +26 -3
  69. package/types/iso-objects/types.d.ts +2 -0
  70. package/types/iso-systems/compile.d.ts +8 -0
  71. package/types/iso-systems/render.d.ts +4 -0
  72. package/types/iso-viewer/index.d.ts +4 -0
  73. package/types/iso-viewer/play.d.ts +37 -0
  74. package/types/iso-viewer/transport.d.ts +73 -0
  75. package/types/player/isometric-diagram.d.ts +24 -0
  76. package/types/remotion/entry.d.ts +2 -0
  77. package/types/remotion/frames.d.ts +70 -0
  78. package/types/remotion/index.d.ts +39 -0
@@ -1,7 +1,8 @@
1
1
  export * from "./motion.js";
2
- import { bindMotion, motionOfSteps } from "./timeline.js";
2
+ import { bindMotion, motionOfSteps, motionSource } from "./timeline.js";
3
3
  import { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from "./motion-builder.js";
4
- import { MOTION_SCHEMA, EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from "./motion-doc.js";
4
+ import { MOTION_SCHEMA } from "./motion-schema.js";
5
+ import { EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from "./motion-doc.js";
5
6
  import { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } from "./ants.js";
6
7
  import { drawLooks } from "./looks.js";
7
8
  export {
@@ -25,6 +26,7 @@ export {
25
26
  easeOf,
26
27
  motion,
27
28
  motionOfSteps,
29
+ motionSource,
28
30
  msOf,
29
31
  readMs,
30
32
  springAt,
@@ -0,0 +1,83 @@
1
+ import { ASSEMBLE_STYLES, DISASSEMBLE_STYLES, MOTION_ORDERS } from "./motion.js";
2
+ import { EASING_NAMES, EXTRAPOLATE } from "./motion-doc.js";
3
+ const TIME = { anyOf: [{ type: "number" }, { type: "string", pattern: "^-?\\d+(\\.\\d+)?(ms|s|f)?$" }] };
4
+ const IDS = { type: "array", items: { type: "string" } };
5
+ const EASE = { anyOf: [{ enum: EASING_NAMES }, { type: "object", required: ["bezier"], additionalProperties: false, properties: { bezier: { type: "array", items: { type: "number" }, minItems: 4, maxItems: 4 } } }, { type: "object", required: ["spring"], additionalProperties: false, properties: { spring: { $ref: "#/$defs/spring" } } }] };
6
+ const timing = { from: { $ref: "#/$defs/time" }, duration: { $ref: "#/$defs/time" }, easing: { $ref: "#/$defs/ease" } };
7
+ const node = (key, value, more = {}, withTiming = true) => ({ type: "object", required: [key], additionalProperties: false, properties: { [key]: value, ...withTiming ? timing : {}, ...more } });
8
+ const MOTION_SCHEMA = {
9
+ $schema: "https://json-schema.org/draft/2020-12/schema",
10
+ title: "isomotion/1",
11
+ type: "object",
12
+ required: ["isomotion"],
13
+ additionalProperties: false,
14
+ properties: {
15
+ isomotion: { const: 1 },
16
+ fps: { type: "number", exclusiveMinimum: 0, description: 'Frames a second, for lengths written "30f".' },
17
+ seed: { type: "integer" },
18
+ ambient: { enum: ["on", "off"], description: "Off: the ants and the looping tokens and pulses stand still, each at its start." },
19
+ series: { $ref: "#/$defs/series" },
20
+ layers: { $ref: "#/$defs/nodes" },
21
+ markers: { type: "object", additionalProperties: { anyOf: [{ type: "number" }, { type: "string" }] } }
22
+ },
23
+ $defs: {
24
+ time: TIME,
25
+ ids: IDS,
26
+ ease: EASE,
27
+ spring: { type: "object", additionalProperties: false, properties: { mass: { type: "number", exclusiveMinimum: 0 }, damping: { type: "number", exclusiveMinimum: 0 }, stiffness: { type: "number", exclusiveMinimum: 0 }, overshootClamping: { type: "boolean" } } },
28
+ curve: { type: "object", required: ["times", "values"], additionalProperties: false, properties: { times: { type: "array", items: { $ref: "#/$defs/time" }, minItems: 1 }, values: { type: "array", items: { type: "number" }, minItems: 1 }, easing: { $ref: "#/$defs/ease" }, extrapolateLeft: { enum: EXTRAPOLATE }, extrapolateRight: { enum: EXTRAPOLATE } } },
29
+ say: { type: "object", additionalProperties: false, properties: { chapter: { type: "string" }, title: { type: "string" }, text: { type: "string" }, code: { type: "string" }, color: { type: "string" }, facts: { type: "array", items: { type: "array", items: { type: "string" }, minItems: 2, maxItems: 2 } } } },
30
+ focus: { type: "object", required: ["lit"], additionalProperties: false, properties: { lit: { $ref: "#/$defs/ids" }, scope: { enum: ["all", "links"] }, level: { type: "number", minimum: 0, maximum: 1 }, always: { $ref: "#/$defs/ids" } } },
31
+ sequence: {
32
+ type: "object",
33
+ additionalProperties: false,
34
+ properties: {
35
+ name: { type: "string", pattern: "^[A-Za-z][\\w-]*$" },
36
+ from: { $ref: "#/$defs/time" },
37
+ offset: { $ref: "#/$defs/time" },
38
+ trimBefore: { $ref: "#/$defs/time" },
39
+ duration: { anyOf: [{ $ref: "#/$defs/time" }, { type: "object", required: ["read"], additionalProperties: false, properties: { read: { anyOf: [{ const: true }, { type: "object", additionalProperties: false, properties: { base: { type: "number" }, perChar: { type: "number" }, min: { type: "number" }, max: { type: "number" } } }] } } }] },
40
+ loop: { anyOf: [{ type: "boolean" }, { type: "integer", minimum: 1 }] },
41
+ playbackRate: { type: "number", exclusiveMinimum: 0 },
42
+ say: { $ref: "#/$defs/say" },
43
+ show: { $ref: "#/$defs/ids" },
44
+ hide: { $ref: "#/$defs/ids" },
45
+ focus: { $ref: "#/$defs/focus" },
46
+ highlight: { $ref: "#/$defs/ids" },
47
+ levels: { type: "object", additionalProperties: { type: "number", minimum: 0, maximum: 1 } },
48
+ variants: { type: "object", additionalProperties: { type: "string" } },
49
+ enter: { type: "object", required: ["fade"], additionalProperties: false, properties: { fade: { $ref: "#/$defs/time" }, easing: { $ref: "#/$defs/ease" } } },
50
+ ants: { anyOf: [{ type: "boolean" }, { $ref: "#/$defs/ids" }] },
51
+ children: { $ref: "#/$defs/nodes" },
52
+ layers: { $ref: "#/$defs/nodes" },
53
+ series: { $ref: "#/$defs/series" }
54
+ }
55
+ },
56
+ series: { type: "array", items: { anyOf: [{ $ref: "#/$defs/seq" }, node("transition", { type: "object", required: ["presentation", "timing"], additionalProperties: false, properties: { presentation: { enum: ["fade", "none"] }, timing: { anyOf: [{ type: "object", required: ["linear"], additionalProperties: false, properties: { linear: { $ref: "#/$defs/time" } } }, { type: "object", required: ["spring"], additionalProperties: false, properties: { spring: { type: "object", additionalProperties: false, properties: { mass: { type: "number", exclusiveMinimum: 0 }, damping: { type: "number", exclusiveMinimum: 0 }, stiffness: { type: "number", exclusiveMinimum: 0 }, overshootClamping: { type: "boolean" }, duration: { $ref: "#/$defs/time" } } } } }] } } }, {}, false)] } },
57
+ seq: node("sequence", { $ref: "#/$defs/sequence" }, {}, false),
58
+ plan: { type: "object" },
59
+ nodes: {
60
+ type: "array",
61
+ items: { anyOf: [
62
+ { $ref: "#/$defs/seq" },
63
+ node("series", { $ref: "#/$defs/series" }, {}, false),
64
+ node("layers", { $ref: "#/$defs/nodes" }, {}, false),
65
+ node("assemble", { type: "object", properties: { style: { enum: ASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
66
+ node("disassemble", { type: "object", properties: { style: { enum: DISASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
67
+ node("travel", { type: "array", items: { anyOf: [{ type: "string" }, { $ref: "#/$defs/ids" }] }, minItems: 1 }, { each: { $ref: "#/$defs/time" }, hold: { $ref: "#/$defs/time" }, loop: { type: "boolean" } }),
68
+ node("pulse", { $ref: "#/$defs/ids" }, { loop: { type: "boolean" } }),
69
+ node("ants", { anyOf: [{ const: true }, { $ref: "#/$defs/ids" }] }, { speed: { type: "number" }, dash: { type: "array", items: { type: "number", exclusiveMinimum: 0 }, minItems: 2, maxItems: 2 } }),
70
+ node("draw", { $ref: "#/$defs/ids" }, { by: { enum: ["stroke", "grow"] }, stagger: { $ref: "#/$defs/time" } }),
71
+ node("type", { $ref: "#/$defs/ids" }),
72
+ { type: "object", required: ["move"], additionalProperties: false, properties: { move: { type: "string" }, from: { $ref: "#/$defs/time" }, x: { $ref: "#/$defs/curve" }, y: { $ref: "#/$defs/curve" }, scale: { $ref: "#/$defs/curve" }, opacity: { $ref: "#/$defs/curve" } } },
73
+ { type: "object", required: ["lift", "by"], additionalProperties: false, properties: { lift: { $ref: "#/$defs/ids" }, by: { type: "number" }, stagger: { $ref: "#/$defs/time" }, to: { enum: ["up", "down"] }, opacity: { $ref: "#/$defs/curve" }, ...timing } },
74
+ node("focus", { $ref: "#/$defs/focus" }, { fade: { $ref: "#/$defs/time" } }),
75
+ node("highlight", { $ref: "#/$defs/ids" }, { fade: { $ref: "#/$defs/time" } }),
76
+ node("camera", { anyOf: [{ const: "fit" }, { type: "object", required: ["focus"], additionalProperties: false, properties: { focus: { anyOf: [{ type: "string" }, { $ref: "#/$defs/ids" }, { type: "array", items: { type: "number" }, minItems: 4, maxItems: 4 }] }, zoom: { type: "number", exclusiveMinimum: 0 }, margin: { type: "number" } } }] })
77
+ ] }
78
+ }
79
+ }
80
+ };
81
+ export {
82
+ MOTION_SCHEMA
83
+ };
@@ -519,7 +519,7 @@ function svgAt(scene, S) {
519
519
  }
520
520
  const unescape = (s) => s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
521
521
  const keptOf = /* @__PURE__ */ new WeakMap();
522
- function paint(svg, S, rendered) {
522
+ function paint(svg, S, rendered, o = {}) {
523
523
  const was = keptOf.get(svg);
524
524
  if (was) {
525
525
  for (const [el, kids] of was.mixed) el.replaceChildren(...kids);
@@ -537,7 +537,7 @@ function paint(svg, S, rendered) {
537
537
  keptOf.set(svg, kept);
538
538
  const set = (el, k, v) => {
539
539
  const m = kept.attrs.get(el) ?? /* @__PURE__ */ new Map();
540
- if (!m.has(k)) m.set(k, el.getAttribute(k));
540
+ if (!m.has(k)) m.set(k, k === "style" ? el.getAttribute(k) || null : el.getAttribute(k));
541
541
  kept.attrs.set(el, m);
542
542
  if (v === null) el.removeAttribute(k);
543
543
  else el.setAttribute(k, v);
@@ -606,12 +606,17 @@ function paint(svg, S, rendered) {
606
606
  const path = w.path && el.querySelector("path.flow");
607
607
  if (path && w.path) {
608
608
  if (w.path.d !== void 0) set(path, "d", w.path.d);
609
- if (w.path.style !== void 0) set(path, "style", w.path.style);
609
+ if (w.path.style !== void 0) {
610
+ if (o.styles === "cssom") {
611
+ set(path, "style", null);
612
+ path.style.cssText = w.path.style;
613
+ } else set(path, "style", w.path.style);
614
+ }
610
615
  if (!w.path.head) set(path, "marker-end", null);
611
616
  }
612
617
  }
613
618
  const anim = layer("anim");
614
- if (anim) for (const [n, at] of overlay(S, pathOf)) make(n, at, anim);
619
+ if (anim) for (const [n, at] of overlay(S, pathOf, rendered?.inks)) make(n, at, anim);
615
620
  }
616
621
  const ofScene = (s, p) => ({ ...p, frame: (t) => svgAt(s, p.at(t)) });
617
622
  const assemble = (s, o = {}) => ofScene(s, planOf(motionModel(s), "assemble", o));
@@ -2,6 +2,7 @@ import { didYouMean } from "../iso-core/errors.js";
2
2
  import { ANT_SPEED, antDash, antsOf } from "./ants.js";
3
3
  import { silhouette } from "./labels.js";
4
4
  import { motionModel, planOf } from "./motion.js";
5
+ import { focusView } from "./focus.js";
5
6
  import { checkMotion, curveAt, easeOf, msOf, readMs, springAt } from "./motion-doc.js";
6
7
  const r2 = (v) => Math.round(v * 100) / 100 || 0;
7
8
  const r4 = (v) => Math.round(v * 1e4) / 1e4 || 0;
@@ -88,16 +89,29 @@ class Sum {
88
89
  return out;
89
90
  }
90
91
  }
91
- function bindMotion(scene, doc, opts = {}) {
92
- const diags = checkMotion(doc), m = motionModel(scene), fps = doc.fps, fileAnts = antsOf(scene.raw);
93
- const none = () => ({ ok: false, diags, duration: 0, beats: [], markers: {}, at: () => ({}), cues: () => void 0, beatAt: () => void 0, startOf: () => void 0 });
92
+ function motionSource(scene) {
93
+ const ants = antsOf(scene.raw), looks = scene.rendered.looks, model = motionModel(scene), free = Object.keys(model.notes).filter((n) => model.notes[n] === void 0);
94
+ return {
95
+ model,
96
+ kinds: Object.fromEntries(scene.routes.map((r) => [r.id, r.kind])),
97
+ outlines: Object.fromEntries(scene.layout.items.map((p) => [p.id, silhouette(p.box).map((q) => [r2(q[0]), r2(q[1])])])),
98
+ ...looks && Object.keys(looks).length ? { looks } : {},
99
+ ...ants ? { ants } : {},
100
+ ...free.length ? { free } : {}
101
+ };
102
+ }
103
+ function bindMotion(drawing, doc, opts = {}) {
104
+ const src = "model" in drawing ? drawing : motionSource(drawing);
105
+ const m = src.free ? { ...src.model, notes: { ...src.model.notes, ...Object.fromEntries(src.free.map((n) => [n, void 0])) } } : src.model;
106
+ const diags = checkMotion(doc), fps = doc.fps, fileAnts = src.ants;
107
+ const none = () => ({ ok: false, diags, duration: 0, beats: [], markers: {}, ambient: "on", loops: false, at: () => ({}), cues: () => void 0, beatAt: () => void 0, startOf: () => void 0 });
94
108
  if (diags.length) return none();
95
109
  const err = (path, message, hint) => {
96
110
  diags.push({ severity: "error", path, message, ...hint ? { hint } : {} });
97
111
  };
98
112
  const ms = (t, otherwise) => t === void 0 ? otherwise : msOf(t, fps);
99
113
  const pieces = new Map(m.pieces.map((p) => [p.id, p])), routes = new Set(m.routes.map((r) => r.id)), notes = new Set(Object.keys(m.notes));
100
- const kindOf = new Map(scene.routes.map((r) => [r.id, r.kind]));
114
+ const kindOf = new Map(Object.entries(src.kinds));
101
115
  const all = [...pieces.keys(), ...routes, ...notes];
102
116
  const known = new Set(all);
103
117
  const notesOn = /* @__PURE__ */ new Map();
@@ -111,7 +125,7 @@ function bindMotion(scene, doc, opts = {}) {
111
125
  }
112
126
  };
113
127
  const needAll = (v, path, kind = "any") => v?.forEach((id, i) => need(id, `${path}/${i}`, kind));
114
- const outline = new Map(scene.layout.items.map((p) => [p.id, silhouette(p.box).map((q) => [r2(q[0]), r2(q[1])])]));
128
+ const outline = new Map(Object.entries(src.outlines));
115
129
  const plans = /* @__PURE__ */ new Map();
116
130
  function nodeEnd(n, path) {
117
131
  const from = "from" in n ? ms(n.from, 0) : 0, dur = "duration" in n ? ms(n.duration, NaN) : NaN, given = Number.isFinite(dur);
@@ -161,7 +175,7 @@ function bindMotion(scene, doc, opts = {}) {
161
175
  items.forEach((it, i) => {
162
176
  if ("transition" in it) {
163
177
  const t = it.transition, g = t.timing;
164
- const length = t.presentation === "none" ? 0 : "linear" in g ? ms(g.linear, 0) : ms(g.spring.duration, settleMs(g.spring));
178
+ const length = t.presentation === "none" ? 0 : transitionMs(g, fps);
165
179
  into = { t, length };
166
180
  return;
167
181
  }
@@ -250,7 +264,7 @@ function bindMotion(scene, doc, opts = {}) {
250
264
  for (const id of Object.keys(s.levels ?? {})) if (id !== "*") need(id, `${path}/levels/${id}`);
251
265
  for (const [id, name] of Object.entries(s.variants ?? {})) {
252
266
  need(id, `${path}/variants/${id}`, "thing");
253
- const have = scene.rendered.looks?.[id] ?? [];
267
+ const have = src.looks?.[id] ?? [];
254
268
  if (pieces.has(id) && name !== "" && !have.includes(name)) {
255
269
  const d = didYouMean(name, have);
256
270
  err(`${path}/variants/${id}`, have.length ? `${id} has no look "${name}" (it has ${have.join(", ")})` : `${id} declares no looks (variants: in the diagram)`, d ? `did you mean "${d}"?` : void 0);
@@ -324,10 +338,7 @@ function bindMotion(scene, doc, opts = {}) {
324
338
  };
325
339
  const entered = (k, T) => {
326
340
  const p = top.list[k], lt = T - p.start;
327
- if (p.into && p.into.length > 0) {
328
- const g = p.into.t.timing;
329
- return "spring" in g ? lt >= p.into.length ? 1 : clamp(springAt(lt, { ...g.spring, overshootClamping: true }) / springAt(p.into.length, { ...g.spring, overshootClamping: true })) : clamp(lt / p.into.length);
330
- }
341
+ if (p.into && p.into.length > 0) return transitionAt(p.into.t.timing, lt, p.into.length);
331
342
  const e = p.s.enter;
332
343
  if (!e) return 1;
333
344
  const over = ms(e.fade, 0);
@@ -414,13 +425,14 @@ function bindMotion(scene, doc, opts = {}) {
414
425
  const one = ms(n.each, 1150), hold = ms(n.hold, n.loop ? 700 : 0), period = n.travel.length * one + hold;
415
426
  const q = n.loop ? turned(a - from, period, c) : lt, i = Math.floor(q / one);
416
427
  if (i >= n.travel.length) return;
417
- const f = easeOf(n.easing, one, "ease-in-out")((q - i * one) / one), group = n.travel[i];
428
+ const part = (q - i * one) / one, f = easeOf(n.easing, one, "ease-in-out")(part), group = n.travel[i];
418
429
  for (const x of Array.isArray(group) ? group : [group]) {
419
430
  const [id, kind] = x.split(":");
420
- if (c.shown(id)) c.sum.tokens.push({ route: id, at: r4(f), ...kind ? { kind } : {} });
431
+ if (c.shown(id)) c.sum.tokens.push({ route: id, at: r4((kind ?? kindOf.get(id)) === "blocked" ? stalled(part) : f), ...kind ? { kind } : {} });
421
432
  }
422
433
  }
423
434
  }
435
+ const stalled = (f) => f < 0.7 ? f / 0.7 : 1 - (f - 0.7) / 0.3 * 0.25;
424
436
  const turned = (x, period, c) => c.off ? 0 : (x % period + period) % period;
425
437
  const ring = (id, amount, sum) => {
426
438
  if (r4(amount) > 0 && outline.has(id)) sum.outlines.push({ id, points: outline.get(id), ...r4(amount) < 1 ? { opacity: r4(amount) } : {} });
@@ -502,6 +514,15 @@ function bindMotion(scene, doc, opts = {}) {
502
514
  const cam = view?.map(r2);
503
515
  return sum.state(cam && cam.some((v, i) => Math.abs(v - fit[i]) > 5e-3) ? cam : void 0);
504
516
  }
517
+ const moving = (n) => {
518
+ if (!n || typeof n !== "object") return false;
519
+ if (Array.isArray(n)) return n.some(moving);
520
+ const o = n;
521
+ if (o.ants !== void 0 && o.ants !== false) return true;
522
+ if (o.loop === true && ("travel" in o || "pulse" in o)) return true;
523
+ return Object.values(o).some(moving);
524
+ };
525
+ const loops = fileAnts !== void 0 || moving(doc.series) || moving(doc.layers);
505
526
  const beatAt = (t) => {
506
527
  const k = beatIndex(Math.max(0, Math.min(duration, t)));
507
528
  return k < 0 ? void 0 : beats[k];
@@ -512,6 +533,8 @@ function bindMotion(scene, doc, opts = {}) {
512
533
  duration,
513
534
  beats,
514
535
  markers,
536
+ ambient: doc.ambient ?? "on",
537
+ loops,
515
538
  at,
516
539
  beatAt,
517
540
  startOf: (n) => starts.get(n) ?? beats.find((b) => b.name === n)?.start,
@@ -523,12 +546,20 @@ function bindMotion(scene, doc, opts = {}) {
523
546
  }
524
547
  };
525
548
  }
549
+ const transitionMs = (g, fps) => "linear" in g ? msOf(g.linear, fps) ?? 0 : msOf(g.spring.duration, fps) ?? settleMs(g.spring);
550
+ function transitionAt(g, t, length) {
551
+ if (length <= 0 || t >= length) return 1;
552
+ return "spring" in g ? clamp(springAt(t, { ...g.spring, overshootClamping: true }) / springAt(length, { ...g.spring, overshootClamping: true })) : clamp(t / length);
553
+ }
526
554
  function settleMs(c) {
527
555
  const m = c.mass ?? 1, k = c.stiffness ?? 100, d = c.damping ?? 10, w0 = Math.sqrt(k / m), z = Math.min(1, d / (2 * Math.sqrt(k * m)));
528
556
  return Math.ceil(Math.log(200) / (z * w0) * 1e3 * (z >= 1 ? 1.6 : 1));
529
557
  }
530
558
  function motionOfSteps(scene) {
531
- const { steps, vis } = scene.steps;
559
+ const { steps, vis } = scene.steps, full = scene.rendered.viewBox;
560
+ let zoomed = false;
561
+ const m = motionModel(scene), ids = /* @__PURE__ */ new Set([...m.pieces.map((p) => p.id), ...m.routes.map((r) => r.id), ...Object.keys(m.notes)]), has = (id) => ids.has(id);
562
+ const free = Object.keys(m.notes).filter((n) => m.notes[n] === void 0);
532
563
  const series = steps.map((st, i) => {
533
564
  const show = [], hide = [];
534
565
  for (const [id, v] of Object.entries(vis)) {
@@ -536,12 +567,22 @@ function motionOfSteps(scene) {
536
567
  else if (i > 0 ? v[i] && !v[i - 1] : false) show.push(id);
537
568
  }
538
569
  const children = [];
539
- if (st.phases.length) children.push({ travel: st.phases.map((g) => g.length === 1 ? g[0].route : g.map((t) => t.route)), each: 1150, hold: 700, loop: true });
570
+ const token = (t) => `${t.route}:${t.kind}`;
571
+ if (st.phases.length) children.push({ travel: st.phases.map((g) => g.length === 1 ? token(g[0]) : g.map(token)), each: 1150, hold: 700, loop: true });
540
572
  const pulse = (scene.raw.steps ?? [])[i]?.pulse?.filter((id) => scene.layout.byId.has(id)) ?? [];
541
573
  if (pulse.length) children.push({ pulse, loop: true });
574
+ if (st.focus) {
575
+ const [x, y, w, h] = focusView(full, st.focus).map(r2);
576
+ children.push({ camera: { focus: [x, y, w, h] }, duration: 900, easing: "ease-in-out" });
577
+ zoomed = true;
578
+ } else if (zoomed) {
579
+ children.push({ camera: "fit", duration: 900, easing: "ease-in-out" });
580
+ zoomed = false;
581
+ }
542
582
  const s = { name: `step-${st.n}`, duration: st.duration, say: { title: st.heading, ...st.caption ? { text: st.caption } : {}, ...st.command ? { code: st.command } : {} } };
543
583
  if (show.length) s.show = show;
544
584
  if (hide.length) s.hide = hide;
585
+ s.focus = scene.raw.dim === "all" ? { lit: st.lit.filter(has), scope: "all", level: 0.14 } : { lit: st.lit.filter(has), scope: "links", level: 0.12, ...free.length ? { always: free } : {} };
545
586
  if (children.length) s.children = children;
546
587
  return { sequence: s };
547
588
  });
@@ -549,5 +590,8 @@ function motionOfSteps(scene) {
549
590
  }
550
591
  export {
551
592
  bindMotion,
552
- motionOfSteps
593
+ motionOfSteps,
594
+ motionSource,
595
+ transitionAt,
596
+ transitionMs
553
597
  };
@@ -3,7 +3,9 @@ import { validateSchema } from "./validate.js";
3
3
  import { place } from "../iso-objects/place.js";
4
4
  import { extendTheme, loadTheme } from "../iso-core/theme.js";
5
5
  import { compileRaw } from "../iso-objects/compile.js";
6
- import { resolveSvg } from "../iso-objects/resolve.js";
6
+ import { FONT_STACKS, resolveSvg } from "../iso-objects/resolve.js";
7
+ import { monoOfDrawing, paintMono } from "../iso-objects/mono-paint.js";
8
+ import { withFont } from "../iso-core/kernel.js";
7
9
  import { bindMotion } from "../iso-objects/timeline.js";
8
10
  import { antsOf } from "../iso-objects/ants.js";
9
11
  import { drawLooks } from "../iso-objects/looks.js";
@@ -18,12 +20,22 @@ class CompileError extends Error {
18
20
  }
19
21
  }
20
22
  function compile(source, themeText, opts = {}) {
21
- const c = compileAll(source, themeText, opts);
23
+ if (opts.font && !opts.resolveVars) throw new Error("font: a self-contained drawing's (resolveVars)");
24
+ const c = withFont(opts.font, () => compileAll(source, themeText, opts)), fonts = opts.font && { sans: opts.font.sans, mono: opts.font.mono ?? FONT_STACKS.mono };
22
25
  if (!c.ok && opts.strict === "throw") throw new CompileError(c.diags);
23
26
  if (!c.ok && opts.strict) c.scenes = [];
24
27
  if (opts.stepMs !== void 0) for (const s of c.scenes) for (const st of s.steps.steps) st.duration = opts.stepMs;
28
+ if (opts.treatment !== void 0 && opts.treatment !== "mono" && opts.treatment !== "none") throw new Error(`treatment: there is "mono" (and "none"), and no ${JSON.stringify(opts.treatment)}`);
29
+ const treatment = (opts.treatment ?? c.doc?.treatment) === "mono";
30
+ if (opts.treatment === "mono" && !opts.resolveVars) throw new Error("treatment: a self-contained drawing's (resolveVars)");
31
+ const theme = c.theme;
25
32
  if (opts.resolveVars) for (const s of c.scenes) {
26
- const o = { mode: opts.mode ?? "light", theme: c.theme, css: drawingCss(systems) + MARKS_CSS + GRID_CSS };
33
+ const mode = opts.mode ?? "light", css = drawingCss(systems) + MARKS_CSS + GRID_CSS;
34
+ if (treatment) {
35
+ toMono(s, theme, mode, css, opts.mono, fonts);
36
+ continue;
37
+ }
38
+ const o = { mode, theme: c.theme, css, fonts };
27
39
  s.rendered.svg = resolveSvg(s.rendered.svg, o);
28
40
  if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, resolveSvg(v, o)]));
29
41
  s.rendered.inks = {
@@ -32,8 +44,27 @@ function compile(source, themeText, opts = {}) {
32
44
  kinds: Object.fromEntries(Object.entries(c.theme.kinds).map(([k, v]) => [k, c.theme[o.mode][v.color] ?? v.color]))
33
45
  };
34
46
  }
47
+ if (opts.font) for (const s of c.scenes) {
48
+ const name = opts.font.name, mark = (svg) => svg.replace("<svg ", `<svg data-font="${name.replace(/[^\w-]/g, "")}" `);
49
+ s.rendered.svg = mark(s.rendered.svg);
50
+ if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, mark(v)]));
51
+ }
52
+ if (opts.resolveVars && treatment && theme) c.theme = { ...theme, kinds: Object.fromEntries(Object.entries(theme.kinds).map(([k, v]) => {
53
+ const d = c.scenes.map((s) => s.rendered.mono?.kinds[k]?.dash).find((x) => x && x.length > 1);
54
+ return [k, d ? { ...v, ants: [d[0], d[1]] } : v];
55
+ })) };
35
56
  return c;
36
57
  }
58
+ function toMono(s, theme, mode, css, own, fonts) {
59
+ const all = [s.rendered.svg, ...Object.values(s.rendered.variants ?? {})];
60
+ const m = monoOfDrawing(all.join(""), theme, mode, [...s.routes.map((r) => r.kind), ...s.steps.kindsUsed], own);
61
+ const draw = (svg) => paintMono(resolveSvg(svg, { mode, theme: m.theme, css: css + m.css, fonts }), m.look, s.id);
62
+ s.rendered.svg = draw(s.rendered.svg);
63
+ if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, draw(v)]));
64
+ s.rendered.inks = { surface: m.look.paper, control: m.look.ink, kinds: Object.fromEntries(Object.keys(theme.kinds).map((k) => [k, m.look.ink])) };
65
+ s.rendered.mono = m.look;
66
+ for (const w of m.look.warnings) s.rendered.warnings.push({ path: "", message: `black and white: ${w}` });
67
+ }
37
68
  function compileAll(source, themeText, opts) {
38
69
  const parsed = parse(source);
39
70
  const diags = [...parsed.diags];
@@ -3,7 +3,7 @@ import { svgAt } from "../iso-objects/motion.js";
3
3
  import { bindMotion } from "../iso-objects/timeline.js";
4
4
  import { compile } from "./compile.js";
5
5
  function renderSvg(source, o) {
6
- const c = compile(source, o.theme, { mode: o.mode ?? "light", resolveVars: true, strict: "throw" }), kinds = c.theme.kinds;
6
+ const c = compile(source, o.theme, { mode: o.mode ?? "light", resolveVars: true, strict: "throw", treatment: o.treatment, mono: o.mono }), kinds = c.theme.kinds;
7
7
  const s = o.scene === void 0 ? c.scenes[0] : typeof o.scene === "number" ? c.scenes[o.scene] : c.scenes.find((x) => x.id === o.scene);
8
8
  if (!s) throw new Error(`no scene ${JSON.stringify(o.scene)} (there ${c.scenes.length === 1 ? "is" : "are"} ${c.scenes.map((x) => x.id).join(", ")})`);
9
9
  const ants = o.ants === void 0 ? antsOf(s.raw) : o.ants === true ? antsOf(s.raw) ?? {} : o.ants || void 0;
@@ -26,6 +26,7 @@
26
26
  "grid": { "$ref": "#/$defs/grid" },
27
27
  "assemble": { "type": "boolean", "description": "draw each scene by flying its parts in from the nearest edge, then play" },
28
28
  "footer": { "type": "string" },
29
+ "treatment": { "enum": ["mono"], "description": "How a self-contained drawing (renderSvg, <isometric-diagram>) is painted: mono, black and white. A host may say otherwise. The page isodiag build writes is in colour." },
29
30
  "scenes": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/scene" } }
30
31
  },
31
32
  "$defs": {
@@ -5,6 +5,8 @@ import { n, node, rewrite, prune, cls, attr, extent, unite, fitWithOverlay } fro
5
5
  import { isoVars, scopeSelector, scope } from "./view-css.js";
6
6
  import { md, stepData, legend, renderPage } from "./page.js";
7
7
  import { playerScript } from "./bundle.js";
8
+ import { transport, pageClock } from "./transport.js";
9
+ import { mountPlayer, PLAY_CSS } from "./play.js";
8
10
  import { h } from "./dom.js";
9
11
  import { TIMELINE_VERSION, SEGMENT_NAME, SEVERITIES, BINS, BIN_MS, scopePattern } from "./timeline-contract.js";
10
12
  import { scopeRules, escapeName, formatScope, join, levelOf, prefixAt, parentOf, within, hasSegment, kindOf, nameOf, crumbs } from "./timeline-scope.js";
@@ -28,6 +30,7 @@ export {
28
30
  MAX_ZOOM,
29
31
  MIN_ZOOM,
30
32
  P3,
33
+ PLAY_CSS,
31
34
  SEGMENT_NAME,
32
35
  SEVERITIES,
33
36
  TIMELINE_VERSION,
@@ -66,12 +69,14 @@ export {
66
69
  memorySource,
67
70
  modeFor,
68
71
  morphSvgs,
72
+ mountPlayer,
69
73
  mountTimeline,
70
74
  n,
71
75
  nameOf,
72
76
  node,
73
77
  offsetAt,
74
78
  overlayPaint,
79
+ pageClock,
75
80
  parentOf,
76
81
  playerScript,
77
82
  prefixAt,
@@ -94,6 +99,7 @@ export {
94
99
  timeScale,
95
100
  toCSV,
96
101
  toJSON,
102
+ transport,
97
103
  unite,
98
104
  viewToggle,
99
105
  viewport,
@@ -1,4 +1,4 @@
1
- import { motionModel } from "../iso-objects/motion.js";
1
+ import { bindMotion, motionOfSteps, motionSource } from "../iso-objects/timeline.js";
2
2
  import { esc } from "../iso-core/kernel.js";
3
3
  import { themeCss } from "../iso-core/theme.js";
4
4
  import { baseCss, PLAYER_CSS } from "../iso-objects/css.js";
@@ -10,18 +10,41 @@ function md(s) {
10
10
  return esc(s).replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>").replace(/(^|[^*])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>").replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, t, u) => /^(https?:|#|\.{0,2}\/)/.test(u.replace(/&amp;/g, "&")) ? `<a href="${u}">${t}</a>` : t);
11
11
  }
12
12
  const paras = (s) => (s ?? "").split(/\n\s*\n/).filter(Boolean).map((p) => `<p class="sec-sub">${md(p.trim())}</p>`).join("");
13
+ const ownMotion = (c, s) => !!s.motion && bindMotion(s, s.motion, { kinds: c.theme.kinds }).ok;
14
+ function stepsOf(c, s) {
15
+ if (!ownMotion(c, s)) return s.steps.steps;
16
+ return bindMotion(s, s.motion, { kinds: c.theme.kinds }).beats.map((b) => ({
17
+ n: b.index + 1,
18
+ num: b.index + 1,
19
+ kind: "control",
20
+ color: b.say?.color ?? colorRef(c.theme, c.theme.kinds.control?.color ?? "control"),
21
+ heading: b.say?.title ?? b.name,
22
+ caption: b.say?.text ?? "",
23
+ command: b.say?.code ?? "",
24
+ phases: [],
25
+ pulses: [],
26
+ lit: [],
27
+ duration: b.end - b.start
28
+ }));
29
+ }
13
30
  function stepData(c) {
14
31
  return JSON.stringify({
15
- scenes: c.scenes.map((s) => ({
16
- id: s.id,
17
- loop: s.raw.loop ?? true,
18
- dim: s.raw.dim ?? "flows",
19
- vis: s.steps.vis,
20
- steps: s.steps.steps.map((st) => ({ ...st, caption: md(st.caption) })),
21
- assemble: s.assemble,
22
- grid: !!s.grid.show,
23
- motion: motionModel(s)
24
- }))
32
+ scenes: c.scenes.map((s) => {
33
+ const own = ownMotion(c, s), steps = stepsOf(c, s), doc = own ? s.motion : s.steps.steps.length ? motionOfSteps(s) : void 0;
34
+ return {
35
+ id: s.id,
36
+ loop: s.raw.loop ?? true,
37
+ dim: s.raw.dim ?? "flows",
38
+ vis: s.steps.vis,
39
+ // (where a step's view goes is its document's camera)
40
+ steps: steps.map(({ focus: _, ...st }) => ({ ...st, caption: md(st.caption) })),
41
+ assemble: s.assemble,
42
+ grid: !!s.grid.show,
43
+ source: motionSource(s),
44
+ ...doc ? { doc } : {},
45
+ ...own ? { own } : {}
46
+ };
47
+ })
25
48
  });
26
49
  }
27
50
  function legend(c, s) {
@@ -43,8 +66,8 @@ function legend(c, s) {
43
66
  }
44
67
  return items.join("");
45
68
  }
46
- function player(s) {
47
- const st = s.steps.steps;
69
+ function player(c, s) {
70
+ const st = stepsOf(c, s);
48
71
  const tools = `<div class="tools">
49
72
  <button class="pbtn small" type="button" data-a="grid" aria-pressed="${s.grid.show ? "true" : "false"}" title="Show the floor grid">Grid</button>
50
73
  <button class="pbtn small" type="button" data-a="assemble" title="Draw the diagram again, piece by piece">Assemble</button>
@@ -67,8 +90,8 @@ function player(s) {
67
90
  <div class="dots"></div>
68
91
  </div>`;
69
92
  }
70
- function stepList(s) {
71
- const st = s.steps.steps;
93
+ function stepList(c, s) {
94
+ const st = stepsOf(c, s);
72
95
  if (!st.length) return "";
73
96
  return `<details class="steps"><summary>All ${st.length} steps as text</summary><ol>${st.map((x) => `<li value="${x.num}"><b>${esc(x.heading)}.</b> ${md(x.caption)}${x.command ? `<br><code>${esc(x.command)}</code>` : ""}</li>`).join("")}</ol></details>`;
74
97
  }
@@ -81,10 +104,10 @@ function renderPage(c, opts = {}) {
81
104
  ${paras(s.raw.caption)}
82
105
  <div class="figure" tabindex="-1">
83
106
  <div class="scroller">${s.grid.show ? s.rendered.svg.replace("<svg ", '<svg class="show-grid" ') : s.rendered.svg}</div>
84
- ${player(s)}
107
+ ${player(c, s)}
85
108
  <div class="legend">${legend(c, s)}</div>
86
109
  </div>
87
- ${stepList(s)}
110
+ ${stepList(c, s)}
88
111
  ${s.raw.after ? `<div class="after">${paras(s.raw.after)}</div>` : ""}
89
112
  </section>`).join("\n");
90
113
  return `<!doctype html>