@johnoscott/isometric-engine 0.14.1 → 0.15.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 (54) hide show
  1. package/README.md +1 -1
  2. package/iso-editor.js +199 -190
  3. package/iso-render.js +157 -148
  4. package/iso-systems.js +170 -159
  5. package/js/iso-objects/ants.js +36 -0
  6. package/js/iso-objects/index.js +47 -1
  7. package/js/iso-objects/looks.js +25 -0
  8. package/js/iso-objects/motion-builder.js +130 -0
  9. package/js/iso-objects/motion-doc.js +500 -0
  10. package/js/iso-objects/motion-entry.js +32 -0
  11. package/js/iso-objects/motion.js +635 -0
  12. package/js/iso-objects/resolve.js +238 -0
  13. package/js/iso-objects/scene.js +15 -13
  14. package/js/iso-objects/timeline.js +553 -0
  15. package/js/iso-systems/compile.js +59 -1
  16. package/js/iso-systems/index.js +4 -1
  17. package/js/iso-systems/render.js +20 -0
  18. package/js/iso-systems/schema.json +39 -0
  19. package/js/iso-viewer/page.js +2 -1
  20. package/js/iso-viewer/player.js +23 -34
  21. package/package.json +46 -1
  22. package/src/iso-objects/ants.ts +53 -0
  23. package/src/iso-objects/compile.ts +4 -1
  24. package/src/iso-objects/index.ts +14 -1
  25. package/src/iso-objects/looks.ts +21 -0
  26. package/src/iso-objects/motion-builder.ts +79 -0
  27. package/src/iso-objects/motion-doc.ts +361 -0
  28. package/src/iso-objects/motion-entry.ts +12 -0
  29. package/src/iso-objects/motion.ts +616 -0
  30. package/src/iso-objects/resolve.ts +196 -0
  31. package/src/iso-objects/scene.ts +29 -13
  32. package/src/iso-objects/timeline.ts +443 -0
  33. package/src/iso-objects/types.ts +20 -2
  34. package/src/iso-systems/compile.ts +58 -3
  35. package/src/iso-systems/index.ts +4 -1
  36. package/src/iso-systems/render.ts +41 -0
  37. package/src/iso-systems/schema.json +39 -0
  38. package/src/iso-viewer/page.ts +2 -1
  39. package/src/iso-viewer/player.ts +24 -41
  40. package/types/iso-objects/ants.d.ts +33 -0
  41. package/types/iso-objects/compile.d.ts +3 -0
  42. package/types/iso-objects/index.d.ts +14 -1
  43. package/types/iso-objects/looks.d.ts +4 -0
  44. package/types/iso-objects/motion-builder.d.ts +105 -0
  45. package/types/iso-objects/motion-doc.d.ts +787 -0
  46. package/types/iso-objects/motion-entry.d.ts +10 -0
  47. package/types/iso-objects/motion.d.ts +200 -0
  48. package/types/iso-objects/resolve.d.ts +20 -0
  49. package/types/iso-objects/scene.d.ts +11 -0
  50. package/types/iso-objects/timeline.d.ts +46 -0
  51. package/types/iso-objects/types.d.ts +32 -0
  52. package/types/iso-systems/compile.d.ts +20 -3
  53. package/types/iso-systems/index.d.ts +4 -1
  54. package/types/iso-systems/render.d.ts +21 -0
@@ -29,6 +29,29 @@
29
29
  "scenes": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/scene" } }
30
30
  },
31
31
  "$defs": {
32
+ "motion": {
33
+ "type": "object", "additionalProperties": false, "minProperties": 1,
34
+ "description": "how this piece (a region: its contents too) moves when the drawing assembles or disassembles",
35
+ "properties": {
36
+ "style": { "enum": ["edge", "drop", "rise", "fly", "pop", "scatter", "build", "fade"], "description": "how it arrives" },
37
+ "out": { "enum": ["explode", "lift-off", "sink", "scatter", "fly-out", "collapse", "fade", "reverse"], "description": "how it leaves" },
38
+ "easing": { "enum": ["linear", "ease", "ease-in", "ease-out", "settle", "spring", "bounce"] },
39
+ "from": { "enum": ["left", "right", "top", "bottom"], "description": "fly: the side it comes from" },
40
+ "delay": { "type": "number", "minimum": 0, "description": "ms after its turn" },
41
+ "duration": { "type": "number", "exclusiveMinimum": 0, "description": "ms its own move takes" }
42
+ }
43
+ },
44
+ "variants": {
45
+ "type": "object", "minProperties": 1, "propertyNames": { "$ref": "#/$defs/id" },
46
+ "description": "other looks of it, by name, for a motion to switch to (its box stays as it is)",
47
+ "additionalProperties": {
48
+ "type": "object", "additionalProperties": false, "minProperties": 1,
49
+ "properties": {
50
+ "role": { "type": "string" }, "ghost": { "type": "boolean" }, "label": { "type": "string" }, "sub": { "type": "string" },
51
+ "face": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" }, "deco": { "type": "array", "items": { "$ref": "#/$defs/deco" } }
52
+ }
53
+ }
54
+ },
32
55
  "id": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]*$" },
33
56
  "grid": {
34
57
  "type": "object",
@@ -88,6 +111,18 @@
88
111
  "properties": {
89
112
  "id": { "$ref": "#/$defs/id" },
90
113
  "title": { "type": "string" },
114
+ "ants": {
115
+ "description": "its connectors march, showing which way they flow: all that may, these, or with a speed (units a second) and a dash",
116
+ "anyOf": [
117
+ { "type": "boolean" },
118
+ { "type": "array", "items": { "type": "string" } },
119
+ { "type": "object", "additionalProperties": false, "properties": {
120
+ "ids": { "type": "array", "items": { "type": "string" } },
121
+ "speed": { "type": "number" },
122
+ "dash": { "type": "array", "items": { "type": "number", "exclusiveMinimum": 0 }, "minItems": 2, "maxItems": 2 } } }
123
+ ]
124
+ },
125
+ "motion": { "type": "object", "description": "the scene's motion document (isomotion/1; its `isomotion: 1` may be left out)" },
91
126
  "caption": { "type": "string" },
92
127
  "aria": { "type": "string" },
93
128
  "gap": { "type": "number", "exclusiveMinimum": 0 },
@@ -143,6 +178,8 @@
143
178
  },
144
179
  "around": { "type": "array", "items": { "$ref": "#/$defs/id" }, "description": "tunnel: routes it wraps" },
145
180
  "regions": { "type": "array", "items": { "$ref": "#/$defs/region" } },
181
+ "motion": { "$ref": "#/$defs/motion" },
182
+ "variants": { "$ref": "#/$defs/variants" },
146
183
  "nodes": { "type": "array", "items": { "$ref": "#/$defs/node" } }
147
184
  }
148
185
  },
@@ -188,6 +225,8 @@
188
225
  "dy": { "type": "number" }
189
226
  }
190
227
  },
228
+ "motion": { "$ref": "#/$defs/motion" },
229
+ "variants": { "$ref": "#/$defs/variants" },
191
230
  "nodes": { "type": "array", "items": { "$ref": "#/$defs/node" }, "description": "nodes standing on top of this one" }
192
231
  }
193
232
  },
@@ -1,3 +1,4 @@
1
+ import { motionModel } from "../iso-objects/motion.js";
1
2
  import { esc } from "../iso-core/kernel.js";
2
3
  import { themeCss } from "../iso-core/theme.js";
3
4
  import { baseCss, PLAYER_CSS } from "../iso-objects/css.js";
@@ -19,7 +20,7 @@ function stepData(c) {
19
20
  steps: s.steps.steps.map((st) => ({ ...st, caption: md(st.caption) })),
20
21
  assemble: s.assemble,
21
22
  grid: !!s.grid.show,
22
- assembly: s.rendered.assembly
23
+ motion: motionModel(s)
23
24
  }))
24
25
  });
25
26
  }
@@ -1,7 +1,7 @@
1
1
  import { focusView } from "../iso-objects/focus.js";
2
+ import { paint, planOf } from "../iso-objects/motion.js";
2
3
  const NS = "http://www.w3.org/2000/svg";
3
4
  const TRAVEL = 1150;
4
- const EASE_IN = "cubic-bezier(.16,.84,.3,1)";
5
5
  function svgEl(tag, attrs, parent) {
6
6
  const e = document.createElementNS(NS, tag);
7
7
  for (const k in attrs) e.setAttribute(k, String(attrs[k]));
@@ -59,7 +59,7 @@ function init() {
59
59
  const flowPath = (id) => svg.querySelector(`[data-hl="${CSS.escape(id)}"] path.flow`);
60
60
  if (sd.dim === "all") svg.classList.add("dim-all");
61
61
  let cur = 0, playing = false, userPaused = false, active = false, timer = 0, raf = 0, groups = 0, t0 = 0;
62
- let assembling = false, assembled = false, animations = [];
62
+ let assembling = false, assembled = false, introTimer = 0, introDone;
63
63
  let tokens = [];
64
64
  const setGrid = (on) => {
65
65
  svg.classList.toggle("show-grid", on);
@@ -199,53 +199,42 @@ function init() {
199
199
  userPaused = true;
200
200
  stop();
201
201
  }
202
- const A = sd.assembly;
203
- const layer = (name) => svg.querySelector(`.g-${name}`);
202
+ const plan = planOf(sd.motion, "assemble");
204
203
  function finishAssemble() {
205
- if (!assembling) return;
206
- for (const a of animations) a.finish();
204
+ if (assembling) introDone?.();
207
205
  }
208
206
  function assemble(freezeAt) {
209
- for (const a of animations) a.cancel();
210
- animations = [];
207
+ clearTimeout(introTimer);
208
+ introDone = void 0;
211
209
  stop();
212
210
  if (N) show(cur);
213
211
  clearAnim();
214
212
  svg.classList.remove("focus", "pre-assemble", "all");
215
213
  assembling = true;
216
- const run = (el, frames, delay, dur, easing = EASE_IN) => animations.push(el.animate(frames, { delay, duration: dur, easing, fill: "backwards" }));
217
- const solid = ["base", "blocks", "air"].map(layer).filter(Boolean);
218
- for (const p of A.pieces) {
219
- const from = `translate(${p.dx}px, ${p.dy}px)`;
220
- for (const L of solid) L.querySelectorAll(`[data-id="${CSS.escape(p.id)}"]`).forEach((el) => run(el, [{ transform: from }, { transform: "translate(0px, 0px)" }], p.delay, p.dur));
221
- }
222
- for (const r of A.routes) {
223
- const g = layer("flows")?.querySelector(`[data-hl="${CSS.escape(r.id)}"]`);
224
- const path = g?.querySelector("path.flow");
225
- if (!g || !path) continue;
226
- const len = path.getTotalLength();
227
- run(g, [{ opacity: 0 }, { opacity: 1 }], r.delay, 80, "linear");
228
- run(path, [{ strokeDasharray: `${len} ${len}`, strokeDashoffset: len }, { strokeDasharray: `${len} ${len}`, strokeDashoffset: 0 }], r.delay, r.dur, "ease-out");
229
- }
230
- for (const name of ["floor", "labels", "badges"]) {
231
- const L = layer(name);
232
- if (L) run(L, [{ opacity: 0 }, { opacity: 1 }], A.labels.delay, A.labels.dur, "ease-out");
233
- }
234
214
  if (freezeAt !== void 0) {
235
- for (const a of animations) {
236
- a.pause();
237
- a.currentTime = freezeAt;
238
- }
215
+ paint(svg, plan.at(freezeAt));
239
216
  return;
240
217
  }
241
- Promise.all(animations.map((a) => a.finished)).then(() => {
218
+ const start = performance.now();
219
+ introDone = () => {
220
+ clearTimeout(introTimer);
221
+ introDone = void 0;
222
+ paint(svg, {});
242
223
  assembling = false;
243
224
  assembled = true;
244
- animations = [];
245
225
  if (N) show(cur);
246
226
  if (active && !userPaused) play();
247
- }, () => {
248
- });
227
+ };
228
+ const step = () => {
229
+ const t = performance.now() - start;
230
+ if (t >= plan.duration) {
231
+ introDone?.();
232
+ return;
233
+ }
234
+ paint(svg, plan.at(t));
235
+ introTimer = window.setTimeout(step, 16);
236
+ };
237
+ step();
249
238
  }
250
239
  asmBtn?.addEventListener("click", () => {
251
240
  userPaused = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnoscott/isometric-engine",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "description": "A generic isometric diagram engine: render (L0–L2) and editor (L0–L3), with a 2D view and a YAML diagram format.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -49,6 +49,11 @@
49
49
  "types": "./iso-systems.d.ts",
50
50
  "default": "./iso-systems.js"
51
51
  },
52
+ "./motion": {
53
+ "types": "./types/iso-objects/motion-entry.d.ts",
54
+ "source": "./src/iso-objects/motion-entry.ts",
55
+ "default": "./js/iso-objects/motion-entry.js"
56
+ },
52
57
  "./modules/iso-core/compile-schema": {
53
58
  "types": "./types/iso-core/compile-schema.d.ts",
54
59
  "source": "./src/iso-core/compile-schema.ts",
@@ -109,6 +114,11 @@
109
114
  "source": "./src/iso-core/vdom.ts",
110
115
  "default": "./js/iso-core/vdom.js"
111
116
  },
117
+ "./modules/iso-objects/ants": {
118
+ "types": "./types/iso-objects/ants.d.ts",
119
+ "source": "./src/iso-objects/ants.ts",
120
+ "default": "./js/iso-objects/ants.js"
121
+ },
112
122
  "./modules/iso-objects/assemble": {
113
123
  "types": "./types/iso-objects/assemble.d.ts",
114
124
  "source": "./src/iso-objects/assemble.ts",
@@ -164,11 +174,36 @@
164
174
  "source": "./src/iso-objects/labels.ts",
165
175
  "default": "./js/iso-objects/labels.js"
166
176
  },
177
+ "./modules/iso-objects/looks": {
178
+ "types": "./types/iso-objects/looks.d.ts",
179
+ "source": "./src/iso-objects/looks.ts",
180
+ "default": "./js/iso-objects/looks.js"
181
+ },
182
+ "./modules/iso-objects/motion-builder": {
183
+ "types": "./types/iso-objects/motion-builder.d.ts",
184
+ "source": "./src/iso-objects/motion-builder.ts",
185
+ "default": "./js/iso-objects/motion-builder.js"
186
+ },
187
+ "./modules/iso-objects/motion-doc": {
188
+ "types": "./types/iso-objects/motion-doc.d.ts",
189
+ "source": "./src/iso-objects/motion-doc.ts",
190
+ "default": "./js/iso-objects/motion-doc.js"
191
+ },
192
+ "./modules/iso-objects/motion": {
193
+ "types": "./types/iso-objects/motion.d.ts",
194
+ "source": "./src/iso-objects/motion.ts",
195
+ "default": "./js/iso-objects/motion.js"
196
+ },
167
197
  "./modules/iso-objects/place": {
168
198
  "types": "./types/iso-objects/place.d.ts",
169
199
  "source": "./src/iso-objects/place.ts",
170
200
  "default": "./js/iso-objects/place.js"
171
201
  },
202
+ "./modules/iso-objects/resolve": {
203
+ "types": "./types/iso-objects/resolve.d.ts",
204
+ "source": "./src/iso-objects/resolve.ts",
205
+ "default": "./js/iso-objects/resolve.js"
206
+ },
172
207
  "./modules/iso-objects/route": {
173
208
  "types": "./types/iso-objects/route.d.ts",
174
209
  "source": "./src/iso-objects/route.ts",
@@ -184,6 +219,11 @@
184
219
  "source": "./src/iso-objects/steps.ts",
185
220
  "default": "./js/iso-objects/steps.js"
186
221
  },
222
+ "./modules/iso-objects/timeline": {
223
+ "types": "./types/iso-objects/timeline.d.ts",
224
+ "source": "./src/iso-objects/timeline.ts",
225
+ "default": "./js/iso-objects/timeline.js"
226
+ },
187
227
  "./modules/iso-objects/types": {
188
228
  "types": "./types/iso-objects/types.d.ts",
189
229
  "source": "./src/iso-objects/types.ts",
@@ -502,6 +542,11 @@
502
542
  "source": "./src/iso-systems/nodes.ts",
503
543
  "default": "./js/iso-systems/nodes.js"
504
544
  },
545
+ "./modules/iso-systems/render": {
546
+ "types": "./types/iso-systems/render.d.ts",
547
+ "source": "./src/iso-systems/render.ts",
548
+ "default": "./js/iso-systems/render.js"
549
+ },
505
550
  "./modules/iso-systems/validate": {
506
551
  "types": "./types/iso-systems/validate.d.ts",
507
552
  "source": "./src/iso-systems/validate.ts",
@@ -0,0 +1,53 @@
1
+ // Marching dashes on a still drawing (docs/design/MOTION.md, 5a): a loop of the drawing's own, for a page or an image that plays
2
+ // nothing else. Two ways: 'css' (a class on each connector and ANTS_CSS once on the page, which a switch can stop) and 'smil' (an
3
+ // animation inside each connector, for an SVG that goes out alone, where a page's stylesheet doesn't reach). In motion (a
4
+ // timeline's `ants`) there is no loop: a frame has the offset of its moment.
5
+
6
+ import type { CompiledScene } from './compile.ts';
7
+
8
+ export const ANT_SPEED = 32 / 1.1;
9
+ export const ANT_DASH: Record<string, [number, number]> = { solid: [9, 7], dashed: [7, 6], dotted: [3, 6] };
10
+ export const ANT_STILL = ['blocked', 'planned'];
11
+ export interface AntsOptions {
12
+ /** how it moves (default: smil); 'none': the dashes, standing still */
13
+ by?: 'css' | 'smil' | 'none';
14
+ /** the connectors that march (default: every one that may) */
15
+ ids?: string[];
16
+ /** units a second, in the drawing's units (default: 32 in 1.1 s) */
17
+ speed?: number;
18
+ dash?: [number, number];
19
+ /** the connectors' dashes, by kind: the theme's `kinds` (a dashed kind marches with its own dash) */
20
+ kinds?: Record<string, { dash?: 'solid' | 'dashed' | 'dotted' }>;
21
+ /** kinds whose connectors stand still (default: blocked, planned) */
22
+ still?: string[];
23
+ }
24
+ /** for 'css': one rule and its keyframes. A page stops them, where they are, with --ants: paused. */
25
+ export const ANTS_CSS = `
26
+ .flow.iso-ants{stroke-dasharray:var(--ant-on) var(--ant-off);animation:iso-ants var(--ant-turn) linear infinite;animation-play-state:var(--ants,running)}
27
+ @keyframes iso-ants{to{stroke-dashoffset:var(--ant-to)}}
28
+ `;
29
+ /** the dash a connector marches with, or undefined when it stands still */
30
+ export function antDash(kind: string, o: Pick<AntsOptions, 'dash' | 'kinds' | 'still'> = {}): [number, number] | undefined {
31
+ return (o.still ?? ANT_STILL).includes(kind) ? undefined : o.dash ?? ANT_DASH[o.kinds?.[kind]?.dash ?? 'solid'];
32
+ }
33
+
34
+ /** what a scene's `ants:` in the file asks for, as options; undefined: none */
35
+ export function antsOf(raw: { ants?: boolean | string[] | { ids?: string[]; speed?: number; dash?: [number, number] } } | undefined): Pick<AntsOptions, 'ids' | 'speed' | 'dash'> | undefined {
36
+ const a = raw?.ants;
37
+ return !a ? undefined : a === true ? {} : Array.isArray(a) ? { ids: a } : a;
38
+ }
39
+
40
+ /** The scene's still, as SVG text, with its connectors marching. */
41
+ export function withAnts(scene: Pick<CompiledScene, 'rendered' | 'routes'>, o: AntsOptions = {}): string {
42
+ const kindOf = new Map(scene.routes.map(r => [r.id, r.kind])), wanted = o.ids && new Set(o.ids), speed = o.speed ?? ANT_SPEED;
43
+ const n = (v: number) => String(Number(v.toFixed(3)));
44
+ return scene.rendered.svg.replace(/(<g data-route="([^"]*)" data-part="line">(?:<g[^>]*>)*)<path ([^>]*?)\s*\/>/g, (m, before: string, id: string, attrs: string) => {
45
+ const route = id.replace(/&quot;/g, '"').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
46
+ const dash = wanted && !wanted.has(route) ? undefined : antDash(kindOf.get(route) ?? '', o);
47
+ if (!dash || !/class="flow\b/.test(attrs)) return m;
48
+ const period = dash[0] + dash[1], turn = n(period / Math.max(1e-6, Math.abs(speed)) ), to = n(speed < 0 ? period : -period);
49
+ if (o.by === 'css') return `${before}<path ${attrs.replace(/class="flow\b/, 'class="flow iso-ants')} style="--ant-on:${n(dash[0])};--ant-off:${n(dash[1])};--ant-to:${to};--ant-turn:${turn}s"/>`;
50
+ if (o.by === 'none') return `${before}<path ${attrs.replace(/ ?stroke-dasharray="[^"]*"/, '')} style="stroke-dasharray:${n(dash[0])} ${n(dash[1])}"/>`;
51
+ return `${before}<path ${attrs.replace(/ ?stroke-dasharray="[^"]*"/, '')} style="stroke-dasharray:${n(dash[0])} ${n(dash[1])}"><animate attributeName="stroke-dashoffset" from="0" to="${to}" dur="${turn}s" repeatCount="indefinite"/></path>`;
52
+ });
53
+ }
@@ -9,10 +9,13 @@ import { routeAll, type Routed } from './route.ts';
9
9
  import { resolveSteps, type Steps } from './steps.ts';
10
10
  import { extendTheme, loadTheme } from '../iso-core/theme.ts';
11
11
  import { type KindCatalog, nodeKindOr } from './kinds.ts';
12
+ import type { MotionDoc } from './motion-doc.ts';
12
13
  import type { GridDef, RawDiagram, RawNode, RawRegion, RawScene, Theme } from './types.ts';
13
14
  import { facePainter, iconPainter } from './assets.ts';
14
15
 
15
- export interface CompiledScene { id: string; raw: RawDiagram['scenes'][number]; layout: Layout; routes: Routed[]; steps: Steps; rendered: RenderedScene; grid: GridDef; assemble: boolean }
16
+ export interface CompiledScene { id: string; raw: RawDiagram['scenes'][number]; layout: Layout; routes: Routed[]; steps: Steps; rendered: RenderedScene; grid: GridDef; assemble: boolean;
17
+ /** the file's `motion:` on this scene, checked against the drawing (a file with errors in it has none) */
18
+ motion?: MotionDoc }
16
19
  export interface Compiled {
17
20
  ok: boolean;
18
21
  /** the parsed source: positions and spans of every value, for the proof sheet */
@@ -5,7 +5,7 @@
5
5
  // The layer's public API. Importers name the module a name comes from (with code splitting, a barrel puts every file
6
6
  // it reaches into each bundle that imports it); the Node tests may import this index.
7
7
 
8
- export type { Side, StepRef, RawPlacement, RawDeco, RawNode, RawGate, RawRegion, RawNote, RawScene, GridDef, RawDiagram, RegionKindName, Placed, RawRole, RawKind, Theme } from './types.ts';
8
+ export type { Side, StepRef, RawPlacement, RawDeco, RawNode, RawGate, RawRegion, RawNote, RawScene, GridDef, RawDiagram, RegionKindName, Placed, RawRole, RawKind, Theme, RawMotion, RawVariant } from './types.ts';
9
9
  export { regionKind, nodeKind, nodeKindOr, wallHeight, kindsCss } from './kinds.ts';
10
10
  export type { RegionShape, RegionKind, KindCatalog } from './kinds.ts';
11
11
  export { drawDecos, boxAsset, plate, cloudPath, drawCloud, defaultLabel, registerMarks, markCss, iconPainter, facePainter, placeholderIcon } from './assets.ts';
@@ -18,6 +18,19 @@ export { silhouette, polyBounds, polyRectArea, rectArea, lineRectArea, Obstacles
18
18
  export type { Rect, Poly, LabelText, PlacedLabel, CalloutSpot } from './labels.ts';
19
19
  export { offscreen, assembly } from './assemble.ts';
20
20
  export type { Edge, Piece, Assembly } from './assemble.ts';
21
+ export { ASSEMBLE_STYLES, DISASSEMBLE_STYLES, MOTION_ORDERS, MOTION_EASINGS, motionModel, motionOrder, planOf, assemble, disassemble, alongPath, svgAt, paint, introSvg } from './motion.ts';
22
+ export type { AssembleStyle, DisassembleStyle, MotionOrder, MotionEasing, Direction, PieceMotion, AssembleOptions, DisassembleOptions, PlanOptions, MotionPiece, MotionModel, MotionPlan, ScenePlan, SceneState, ItemState, LabelState, RouteState } from './motion.ts';
23
+ export { drawLooks } from './looks.ts';
24
+ export { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } from './ants.ts';
25
+ export type { AntsOptions } from './ants.ts';
26
+ export { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from './motion-builder.ts';
27
+ export type { SequenceOptions, Timing, CameraVerbs, Ids as MotionIds } from './motion-builder.ts';
28
+ export { bindMotion, motionOfSteps } from './timeline.ts';
29
+ export type { Timeline, BindOptions, BeatInfo, Cue } from './timeline.ts';
30
+ export { MOTION_SCHEMA, EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from './motion-doc.ts';
31
+ export type { MotionDoc, MotionNode, MotionTime, MotionEase, EasingName, Extrapolate, SpringConfig, Curve, Say as MotionSay, Focus, ReadTime, Sequence, SeriesItem, Transition, MotionDiag } from './motion-doc.ts';
32
+ export { resolveSvg, FONT_STACKS } from './resolve.ts';
33
+ export type { ResolveOptions, ThemeMode } from './resolve.ts';
21
34
  export { durationFor, resolveSteps, midpoint } from './steps.ts';
22
35
  export type { RawStep, Token, StepData, Say, Mark, Badge, Steps } from './steps.ts';
23
36
  export { focusView } from './focus.ts';
@@ -0,0 +1,21 @@
1
+ // The looks things declare (`variants:`): the same drawing with each thing's in it, for a motion to take that thing's parts from. A format
2
+ // that offers looks draws them after it compiles; one that doesn't bundles none of this.
3
+
4
+ import type { CompiledScene } from './compile.ts';
5
+ import { renderScene } from './scene.ts';
6
+ import type { Theme } from './types.ts';
7
+
8
+ /** Draw a scene's looks into its `rendered` (none declared: nothing). */
9
+ export function drawLooks(s: CompiledScene, theme: Theme): void {
10
+ const looks: Record<string, string[]> = {};
11
+ for (const p of s.layout.items) { const v = (p.region ?? p.node)?.variants; if (v) looks[p.id] = Object.keys(v); }
12
+ if (!Object.keys(looks).length) return;
13
+ s.rendered.looks = looks;
14
+ s.rendered.variants = Object.fromEntries([...new Set(Object.values(looks).flat())].map(name => [name, renderScene({
15
+ scene: s.raw, routes: s.routes, steps: s.steps, theme, id: s.raw.id, gridStep: s.grid.step ?? s.grid.snap ?? 1,
16
+ layout: { ...s.layout, items: s.layout.items.map(p => {
17
+ const v = (p.region ?? p.node)?.variants?.[name];
18
+ return !v ? p : p.region ? { ...p, region: { ...p.region, ...v, deco: undefined } as typeof p.region } : { ...p, node: { ...p.node!, ...v } };
19
+ }) },
20
+ }).svg]));
21
+ }
@@ -0,0 +1,79 @@
1
+ // The motion document, written in code: motion() and its methods make plain data (toJSON() is the document) and nothing else is
2
+ // kept. Every word here is one of the document's; `over` is its duration. What a document can't say has no method.
3
+
4
+ import type { Curve, Focus, MotionDoc, MotionEase, MotionNode, MotionTime, ReadTime, Say, Sequence, SeriesItem, Transition } from './motion-doc.ts';
5
+ import type { AssembleOptions, DisassembleOptions } from './motion.ts';
6
+
7
+ export interface Timing { from?: MotionTime; over?: MotionTime; easing?: MotionEase }
8
+ /** a sequence's own keys; `read`: as long as its words take (true, or how) */
9
+ export type SequenceOptions = Omit<Sequence, 'name' | 'children' | 'layers' | 'series' | 'duration'> & { duration?: MotionTime; read?: ReadTime['read'] };
10
+ export type Ids = string | string[];
11
+ const list = (v: Ids): string[] => (typeof v === 'string' ? [v] : [...v]);
12
+ /** what was given, as plain data of its own (no undefined, nothing shared with the caller) */
13
+ const plain = <T>(v: T): T => JSON.parse(JSON.stringify(v)) as T;
14
+ const timing = (o: Timing = {}) => ({ ...(o.from === undefined ? {} : { from: o.from }), ...(o.over === undefined ? {} : { duration: o.over }), ...(o.easing === undefined ? {} : { easing: o.easing }) });
15
+
16
+ export interface CameraVerbs<B> { focus(on: Ids | [number, number, number, number], o?: Timing & { zoom?: number; margin?: number }): B; fit(o?: Timing): B }
17
+ /** what is in a sequence (or in a document's layers), in the order it is said */
18
+ export class NodesBuilder {
19
+ /** @internal */
20
+ readonly nodes: MotionNode[] = [];
21
+ private add(n: MotionNode): this { this.nodes.push(plain(n)); return this; }
22
+ assemble(o: Omit<AssembleOptions, 'duration'> = {}, t: Timing = {}): this { return this.add({ assemble: o, ...timing(t) }); }
23
+ disassemble(o: Omit<DisassembleOptions, 'duration'> = {}, t: Timing = {}): this { return this.add({ disassemble: o, ...timing(t) } as MotionNode); }
24
+ /** tokens along connectors, one after another; a nested list at once; "id:kind" */
25
+ travel(routes: (string | string[])[], o: Timing & { each?: MotionTime; hold?: MotionTime; loop?: boolean } = {}): this { const { each, hold, loop } = o; return this.add({ travel: routes, ...timing(o), each, hold, loop }); }
26
+ pulse(ids: Ids, o: Timing & { loop?: boolean } = {}): this { return this.add({ pulse: list(ids), ...timing(o), loop: o.loop }); }
27
+ ants(ids: Ids | true = true, o: Timing & { speed?: number; dash?: [number, number] } = {}): this { return this.add({ ants: ids === true ? true : list(ids), ...timing(o), speed: o.speed, dash: o.dash }); }
28
+ draw(routes: Ids, o: Timing & { by?: 'stroke' | 'grow'; stagger?: MotionTime } = {}): this { return this.add({ draw: list(routes), ...timing(o), by: o.by, stagger: o.stagger }); }
29
+ type(ids: Ids, o: Timing = {}): this { return this.add({ type: list(ids), ...timing(o) }); }
30
+ move(id: string, o: { from?: MotionTime; x?: Curve; y?: Curve; scale?: Curve; opacity?: Curve }): this { return this.add({ move: id, ...o }); }
31
+ lift(ids: Ids, by: number, o: Timing & { stagger?: MotionTime; to?: 'up' | 'down'; opacity?: Curve } = {}): this { return this.add({ lift: list(ids), by, ...timing(o), stagger: o.stagger, to: o.to, opacity: o.opacity }); }
32
+ focus(lit: Ids, o: Timing & Omit<Focus, 'lit'> & { fade?: MotionTime } = {}): this { const { scope, level, always } = o; return this.add({ focus: { lit: list(lit), scope, level, always }, ...timing(o), fade: o.fade }); }
33
+ highlight(ids: Ids, o: Timing & { fade?: MotionTime } = {}): this { return this.add({ highlight: list(ids), ...timing(o), fade: o.fade }); }
34
+ /** the view: on a thing, some things or a box; or the whole drawing again */
35
+ get camera(): CameraVerbs<this> {
36
+ return {
37
+ focus: (on, o = {}) => this.add({ camera: { focus: on as string, zoom: o.zoom, margin: o.margin }, ...timing(o) }),
38
+ fit: (o = {}) => this.add({ camera: 'fit', ...timing(o) }),
39
+ };
40
+ }
41
+ /** a sequence in this one: a clock of its own, from `from` */
42
+ sequence(name: string | undefined, o: SequenceOptions = {}, fill?: (b: NodesBuilder) => unknown): this { return this.add({ sequence: sequenceOf(name, o, fill) }); }
43
+ /** sequences one after another */
44
+ series(fill: (s: SeriesBuilder) => unknown): this { const s = new SeriesBuilder(); fill(s); return this.add({ series: s.items }); }
45
+ /** nodes over one another */
46
+ layers(fill: (b: NodesBuilder) => unknown): this { const b = new NodesBuilder(); fill(b); return this.add({ layers: b.nodes }); }
47
+ }
48
+ function sequenceOf(name: string | undefined, o: SequenceOptions, fill?: (b: NodesBuilder) => unknown): Sequence {
49
+ const { read, duration, ...rest } = o, b = new NodesBuilder();
50
+ fill?.(b);
51
+ return plain({ ...(name === undefined ? {} : { name }), ...rest, ...(read !== undefined ? { duration: { read } } : duration !== undefined ? { duration } : {}), ...(b.nodes.length ? { children: b.nodes } : {}) });
52
+ }
53
+ export class SeriesBuilder {
54
+ /** @internal */
55
+ readonly items: SeriesItem[] = [];
56
+ sequence(name: string | undefined, o: SequenceOptions = {}, fill?: (b: NodesBuilder) => unknown): this { this.items.push({ sequence: sequenceOf(name, o, fill) }); return this; }
57
+ transition(t: Transition): this { this.items.push({ transition: plain(t) }); return this; }
58
+ }
59
+ export class MotionBuilder extends SeriesBuilder {
60
+ private over: MotionNode[] = [];
61
+ private marks: Record<string, MotionTime> = {};
62
+ private head: { fps?: number; seed?: number; ambient?: 'on' | 'off' };
63
+ constructor(head: { fps?: number; seed?: number; ambient?: 'on' | 'off' } = {}) { super(); this.head = head; }
64
+ /** a beat: a sequence with commentary */
65
+ beat(name: string, say: Say, o: SequenceOptions = {}, fill?: (b: NodesBuilder) => unknown): this { return this.sequence(name, { ...o, say }, fill); }
66
+ /** the whole drawing arrives (a sequence as long as that takes) */
67
+ assemble(o: Omit<AssembleOptions, 'duration'> = {}, t: Timing = {}): this { return this.sequence(undefined, {}, b => b.assemble(o, t)); }
68
+ /** the whole drawing leaves */
69
+ disassemble(o: Omit<DisassembleOptions, 'duration'> = {}, t: Timing = {}): this { return this.sequence(undefined, {}, b => b.disassemble(o, t)); }
70
+ /** a name for a moment: ms, or "beat+1200" */
71
+ mark(name: string, at: MotionTime): this { this.marks[name] = at; return this; }
72
+ /** nodes over the whole document, on its own clock */
73
+ layers(fill: (b: NodesBuilder) => unknown): this { const b = new NodesBuilder(); fill(b); this.over.push(...b.nodes); return this; }
74
+ toJSON(): MotionDoc {
75
+ return plain({ isomotion: 1 as const, ...this.head, ...(this.items.length ? { series: this.items } : {}), ...(this.over.length ? { layers: this.over } : {}), ...(Object.keys(this.marks).length ? { markers: this.marks } : {}) });
76
+ }
77
+ }
78
+ /** Start a motion document. */
79
+ export const motion = (head: { fps?: number; seed?: number; ambient?: 'on' | 'off' } = {}): MotionBuilder => new MotionBuilder(head);