@entro314labs/iso-engine 0.0.0-stage → 0.5.1

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +165 -2
  3. package/THIRD_PARTY_NOTICES.md +39 -0
  4. package/dist/engine/anim.js +225 -0
  5. package/dist/engine/behaviors.js +105 -0
  6. package/dist/engine/diagram.js +80 -0
  7. package/dist/engine/draw.js +117 -0
  8. package/dist/engine/export.js +81 -0
  9. package/dist/engine/figure.js +35 -0
  10. package/dist/engine/global.js +4 -0
  11. package/dist/engine/index.d.ts +278 -0
  12. package/dist/engine/index.js +164 -0
  13. package/dist/engine/math.js +190 -0
  14. package/dist/engine/node.js +290 -0
  15. package/dist/engine/paths.js +76 -0
  16. package/dist/engine/prefabs/architecture.js +136 -0
  17. package/dist/engine/prefabs/basics.js +131 -0
  18. package/dist/engine/prefabs/devices.js +295 -0
  19. package/dist/engine/prefabs/icons.js +49 -0
  20. package/dist/engine/prefabs/index.js +12 -0
  21. package/dist/engine/prefabs/logistics.js +156 -0
  22. package/dist/engine/scene.js +466 -0
  23. package/dist/engine/shapes.js +781 -0
  24. package/dist/engine/sort.js +153 -0
  25. package/dist/engine/spec.js +81 -0
  26. package/dist/engine/style.js +87 -0
  27. package/dist/engine.css +1 -0
  28. package/dist/figure.css +93 -0
  29. package/dist/figure.d.ts +22 -0
  30. package/dist/figure.js +73 -0
  31. package/dist/filters.d.ts +9 -0
  32. package/dist/filters.js +22 -0
  33. package/dist/index.d.ts +9 -0
  34. package/dist/index.js +8 -0
  35. package/dist/iso.global.js +7990 -0
  36. package/dist/kernel.d.ts +102 -0
  37. package/dist/kernel.js +172 -0
  38. package/dist/loops.d.ts +49 -0
  39. package/dist/loops.js +64 -0
  40. package/dist/patterns.d.ts +44 -0
  41. package/dist/patterns.js +97 -0
  42. package/dist/theme.css +19 -0
  43. package/dist/types.d.ts +86 -0
  44. package/dist/types.js +1 -0
  45. package/package.json +50 -4
  46. package/skills/iso-engine/SKILL.md +143 -0
  47. package/skills/iso-engine/examples/engine.html +42 -0
  48. package/skills/iso-engine/examples/figure.html +51 -0
  49. package/skills/iso-engine/examples/loop.html +68 -0
  50. package/skills/iso-engine/examples/loop.js +36 -0
  51. package/skills/iso-engine/examples/matcher.js +134 -0
  52. package/skills/iso-engine/examples/spec.html +42 -0
  53. package/skills/iso-engine/references/animation.md +116 -0
  54. package/skills/iso-engine/references/api.md +207 -0
  55. package/skills/iso-engine/references/composition.md +66 -0
  56. package/skills/iso-engine/references/diagrams.md +68 -0
  57. package/skills/iso-engine/references/figures.md +359 -0
  58. package/skills/iso-engine/references/loops.md +126 -0
  59. package/skills/iso-engine/references/prefabs.md +103 -0
  60. package/skills/iso-engine/references/spec.md +66 -0
  61. package/skills/iso-engine/references/style.md +76 -0
  62. package/skills/iso-engine/references/troubleshooting.md +49 -0
  63. package/skills/iso-engine/scripts/build.mjs +35 -0
@@ -0,0 +1,116 @@
1
+ # Motion recipes
2
+
3
+ All motion is a function of scene time, so any frame can be seeked and exported exactly and reduced-motion
4
+ users see a clean rest pose. Combine: one entrance + up to two loops + optional interactions.
5
+
6
+ ## Entrances
7
+
8
+ ```js
9
+ s.assemble(); // everything, back to front
10
+ s.assemble('.tree', { stagger: 0.006, drop: 24 }); // just the trees, fast
11
+ s.assemble(s.root.items().filter((n) => n.prefab !== 'platform'), { stagger: 0.02 });
12
+ s.drawOn(d.edges.map((e) => e.line), { delay: 0.9 }); // diagram edges draw themselves after nodes land
13
+ s.timeline({ delay: 1.8 }).from(['card-*'], { opacity: 0 }, { duration: 0.6 }); // late arrivals
14
+ ```
15
+
16
+ Exclude moving objects (cards, packets) from `assemble` and fade them in after it, otherwise they
17
+ travel over an empty platform during the entrance.
18
+
19
+ ## Loops
20
+
21
+ ```js
22
+ s.float('card', { amp: 4, period: 2.6 }); // hover in place
23
+ s.travel(cards, Iso.path.circle({ center: [0, 0, 22], r: 145 }), { duration: 16, orient: true, orientOffset: 90 });
24
+ s.travel(phones, belt.track(0.2), { duration: 9 }); // along a conveyor
25
+ s.orbit('satellite', { center: [0, 0, 60], r: 80, duration: 10 });
26
+ s.blink('.led', { period: 1.3, duty: 0.6, stagger: 0.37 }); // LEDs out of phase
27
+ s.pulse('.dock', { min: 0.8, max: 1, period: 3 }); // breathing light
28
+ s.spin('fan', { speed: 90 }); // small objects only
29
+ ```
30
+
31
+ `travel` with several nodes spreads them evenly along the path (`spread` = 1/n by default).
32
+
33
+ ## Coordinated loops (react to where things are)
34
+
35
+ Compute positions analytically in a `loop` — no physics, still deterministic:
36
+
37
+ ```js
38
+ const LAP = 16;
39
+ s.loop((t) => {
40
+ phones.forEach((p) => {
41
+ let b = 0;
42
+ for (let j = 0; j < 3; j++) { // three cards, spread by 1/3 of a lap
43
+ const ca = ((t / LAP + j / 3) * 360) % 360;
44
+ const d = Math.abs(((p.angle - ca + 540) % 360) - 180);
45
+ if (d < 14) b = Math.max(b, 0.5 + 0.5 * Math.cos((Math.PI * d) / 14));
46
+ }
47
+ p.set('z', b * 24); // rise as a card passes underneath
48
+ });
49
+ });
50
+ ```
51
+
52
+ ## Objects that change at stations
53
+
54
+ Derive each traveller's position along the path from time, then switch its state when it passes a
55
+ station. State switches are cheap (`hidden` toggles inside the prefab), so do it every frame:
56
+
57
+ ```js
58
+ const line = Iso.path.polyline([[150, -128, 16], [150, 81, 16], [-148, 81, 16]], { radius: 11 });
59
+ const N = 11, LAP = line.length / 21; // 21 units per second
60
+ const boxes = Array.from({ length: N }, (_, i) => s.parcel({ id: 'box-' + i, at: [150, -128, 16], open: true }));
61
+ s.travel(boxes, line, { duration: LAP, orient: true }); // travel spreads them by 1/N
62
+ const uAt = (pred) => { for (let u = 0; u <= 1; u += 0.0005) if (pred(line.at(u))) return u; return 1; };
63
+ const uTape = uAt((p) => p[1] >= -60), uScan = uAt((p) => p[0] <= -70);
64
+ s.loop((t) => boxes.forEach((b, i) => {
65
+ const u = (((t / LAP + i / N) % 1) + 1) % 1, at = u * line.length;
66
+ b.open(u < uTape); // taped after the tunnel
67
+ b.label(u > uScan); // labelled after the scanner
68
+ s.nudge(b, 'opacity', Math.max(0, Math.min(1, at / 10, (line.length - at) / 12))); // emerge and vanish
69
+ }));
70
+ ```
71
+
72
+ Use `s.nudge(node, 'opacity', k)` (multiplicative, per frame) rather than `set('opacity')` inside loops
73
+ so entrance fades from timelines still apply.
74
+
75
+ ## Scripted sequences (explainers)
76
+
77
+ ```js
78
+ const tl = s.timeline({ repeat: -1, repeatDelay: 1.2 });
79
+ tl.to('lid', { rot: 90 }, { duration: 0.8, ease: 'inOutCubic' })
80
+ .fromTo('chip', { z: 30, opacity: 0 }, { z: 0, opacity: 1 }, { duration: 0.6, ease: 'out' })
81
+ .set('chip', { material: 'lit', glow: true })
82
+ .call(() => s.status('installed'))
83
+ .wait(1.5)
84
+ .to('lid', { rot: 0 }, { duration: 0.6 })
85
+ .set('chip', { material: undefined, glow: false });
86
+ ```
87
+
88
+ ## Interaction
89
+
90
+ ```js
91
+ node.set({ interactive: true, label: 'Server rack. Press Enter for details.' });
92
+ node.on('click', () => { … }); // mouse, Enter and Space
93
+ node.on('hover', () => s.to(node, { z: 6 })); // reactive tweens start from current values
94
+ node.on('leave', () => s.to(node, { z: 0 }));
95
+ s.hoverLift('.rack', { z: 5 }); // shorthand
96
+ s.on('render', () => s.svg.addEventListener('click', () => s.toggle())); // click anywhere to pause
97
+ ```
98
+
99
+ Test every interaction in a browser with the mouse and with the keyboard alone (Tab to the node, then Enter).
100
+
101
+ ## Device behaviours
102
+
103
+ - `deskComputer`: `pc.power()` runs the CRT sequence (line → opening → glow → logo), `pc.type(key)`,
104
+ `pc.press(key, down)`; status via `onStatus`.
105
+ - `keyboard`: `kb.press('a', true)`.
106
+ - `conveyor`: `belt.track()` gives the path for `travel`.
107
+
108
+ ## Timing guide
109
+
110
+ | Motion | Duration |
111
+ |---|---|
112
+ | Hover / press feedback | 0.06–0.22 s |
113
+ | State change (switch on, open) | 0.3–1.1 s |
114
+ | Entrance per object | 0.6–0.8 s, stagger 0.005–0.1 s |
115
+ | Ambient loops | 2–16 s per cycle |
116
+ | Exported GIF/MP4 | one full cycle of the main loop (4–8 s) |
@@ -0,0 +1,207 @@
1
+ # Iso API reference
2
+
3
+ In an app, `import Iso from '@entro314labs/iso-engine/engine'`. Without a bundler, load the package's `dist/iso.global.js` with a
4
+ `<script>` tag; it defines `window.Iso`.
5
+ All lengths are world units (≈ px at the fitted size). Angles are degrees.
6
+
7
+ ## Coordinates and projection
8
+
9
+ - `x` → screen right-down, `y` → screen left-down, `z` → up. Larger x, y or z = closer to the viewer.
10
+ - True isometric (30°) by default; `angle: 26.565` gives the 2:1 "pixel" dimetric look.
11
+ - Visible faces of a solid: **top** (+z), **left** (+y, screen-left), **right** (+x, screen-right).
12
+ - Plan angles (circles, paths, `rot`) are measured from +x toward +y, which is **clockwise on screen**.
13
+ - The viewBox fits the drawing automatically (with `padding`), so you never compute screen offsets.
14
+
15
+ ## Iso namespace
16
+
17
+ | Member | Purpose |
18
+ |---|---|
19
+ | `Iso.scene(host, opts)` | Create a scene in a selector/element. Returns a `Scene`. |
20
+ | `Iso.render(spec, host?)` | Build a scene from a JSON spec (see `spec.md`). |
21
+ | `Iso.define(name, build, meta?)` | Register a prefab: `build(g, opts, Iso)` fills group `g` in local coords (origin = footprint centre, base). `meta`: `{ sort: 'auto' \| 'none', flat: bool }`. May return an object of methods merged into the group. |
22
+ | `Iso.make(type, opts)` | Create a detached node of any type (primitive, builder or prefab). |
23
+ | `Iso.prefabs`, `Iso.shapes` | Registries. `Object.keys(Iso.prefabs)` lists prefabs. |
24
+ | `Iso.path.*` | World paths: `line(a,b)`, `polyline(pts,{radius,closed})`, `circle({center,r,start,ccw})`, `arc({center,r,from,to})`, `bezier(p0,p1,p2,p3)`, `hop(a,b,height)`, `rect({at,size,r})`, `join(...)`. A path has `length`, `at(u)`, `tangent(u)`, `heading(u)`, `points`, `reverse()`, `offset(dx,dy,dz)`. |
25
+ | `Iso.ease` | Easing functions (see Animation). |
26
+ | `Iso.rng(seed)` | Seeded random: `r()`, `r.range(a,b)`, `r.int(a,b)`, `r.pick(arr)`, `r.chance(p)`. |
27
+ | `Iso.ICONS`, `Iso.icon(name, cls)`, `Iso.MARK` | Built-in 24-grid line icons; a 9×9 pixel mark (replace with your own). |
28
+ | `Iso.THEMES`, `Iso.MATERIALS` | Theme parameters and material definitions. |
29
+ | `Iso.manual = true`, `Iso.advance(dt)`, `Iso.scenes()` | Manual clock for export and tests: scenes only advance when you call `Iso.advance(dt)`. |
30
+ | `Iso.figure(host, opts)` | Just the caption frame, if you need it without a scene. |
31
+
32
+ ## Scene options
33
+
34
+ ```js
35
+ Iso.scene('#app', {
36
+ theme: 'dark', // dark | light | paper | blueprint | terminal | inherit (uses host --bg/--fg)
37
+ colors: { bg: '#0f1012', fg: '#f0efe9', accent: '#ff6a3d' }, // optional brand palette
38
+ figure: { index: 'Fig. 1', title: 'Name', hint: 'What to do', status: 'state', maxWidth: 900 },
39
+ label: 'Accessible description of the figure',
40
+ padding: 24, // fit padding (world units)
41
+ extend: [top, right, bottom, left], // extra room for things that move outside the rest pose
42
+ aspect: 16 / 9, // force the viewBox aspect
43
+ zoom: 1.2, // crop into the fitted view
44
+ view: [x, y, w, h], // explicit viewBox (disables fitting)
45
+ height: 480, // fixed CSS height
46
+ angle: 30, // projection angle
47
+ autoplay: true, // start the clock
48
+ reducedMotion: 'static',// 'static': show the rest pose when the user prefers reduced motion; 'ignore'
49
+ restTime: 2.5, // time shown under reduced motion (default: after finite timelines)
50
+ });
51
+ ```
52
+
53
+ ## Scene methods
54
+
55
+ | Method | |
56
+ |---|---|
57
+ | `s.<primitive>(opts)`, `s.<prefab>(opts)` | Add an object to the root; returns the node. |
58
+ | `s.group(opts, fn)` | Add a group; `fn(g)` fills it. `opts`: `at`, `rot`, `flat`, `sort`. |
59
+ | `s.add(node)` / `s.add('type', opts)` | Add a detached node, or by type name. |
60
+ | `s.get(id)`, `s.find(pred)`, `s.all(pred)` | Look nodes up. |
61
+ | `s.resolve(target)` | Targets everywhere accept: a node, an id, `'#id'`, `'.class'`, `'prefix*'`, an array, or a predicate. |
62
+ | `s.timeline(opts)` | New deterministic timeline (see Animation). |
63
+ | `s.to(target, props, opts)` | Reactive tween from current values (`duration` 0.3, `ease` 'out'). Returns a thenable. |
64
+ | `s.loop(fn)` | Per-frame `fn(time, dt, scene)`; returns `{ stop() }`. |
65
+ | `s.float / pulse / blink / spin / travel / orbit / assemble / drawOn / typewriter / hoverLift` | Motion presets (see Animation). |
66
+ | `s.play()`, `s.pause()`, `s.toggle()`, `s.seek(t)`, `s.reset()`, `s.time`, `s.timeScale` | Clock. |
67
+ | `s.status(text)` | Update the figure's state caption (scenes made with `figure`). |
68
+ | `s.setTheme(name)` | Switch theme live. |
69
+ | `s.project([x,y,z])` | World point → CSS px inside the SVG (for HTML overlays/tooltips). |
70
+ | `s.refit()` | Recompute the viewBox after big changes. |
71
+ | `s.toSVG(opts)` · `s.toPNG({scale})` · `s.download(name, 'svg'\|'png')` | Export (colours inlined). |
72
+ | `s.toString()` | SVG markup at rest (works without a DOM). |
73
+ | `s.on('render'\|'tick'\|'destroy', fn)`, `s.destroy()` | Lifecycle. |
74
+
75
+ ## Nodes
76
+
77
+ Every object accepts: `id`, `class` (space-separated; used by `'.class'` targets), `opacity` (initial), `material`,
78
+ `color` (tint), `glow`, `layer` (lower draws first when overlapping; labels use 1), `hidden`, `style`
79
+ (CSS custom properties object), `anchor` (`'bottom'|'center'|'top'` for scale), and for interaction
80
+ `interactive`, `label` (aria-label), `role`, `pressed`.
81
+
82
+ ```js
83
+ node.set('z', 10); node.set({ x: 4, opacity: 0.5 }); // x/y/z are world offsets from the rest pose
84
+ node.set('h', 40); // any geometry option re-draws the node
85
+ node.get('z');
86
+ node.to({ z: 6 }, { duration: 0.2 }); // reactive tween
87
+ node.on('click', fn); // also: press, hover, leave, focus, down, up. click/press make it focusable (Enter/Space).
88
+ node.remove();
89
+ group.add(node); group.find(pred); group.findAll(pred); group.items(); group.children;
90
+ ```
91
+
92
+ Animatable: `x`, `y`, `z`, `scale`, `opacity`, and any numeric option (`h`, `r`, `rot`, `reveal`, `chars`, `power`, …).
93
+ Arrays (e.g. `points`) can be set but not tweened.
94
+
95
+ ## Primitives
96
+
97
+ ### Solids
98
+
99
+ | Type | Options |
100
+ |---|---|
101
+ | `box` | `at` (min corner) or `center:[cx,cy,z]`; `size:[w,d,h]`; `r` plan corner radius; `chamfer` top bevel; `rot` around its own centre; `n` arc samples; `tone:{top,left,right,bevel}` fill classes; face drawers `top`, `left`, `right` = `(face, node) => …`; `faces: (get) => …` with `get('left'\|'right'\|'top'\|'back-left'\|'back-right')`. |
102
+ | `prism` | `points:[[x,y],…]` plan polygon (convex or concave), `at` offset, `z`, `h`, `chamfer` (convex only). |
103
+ | `cylinder` | `at` (base centre), `r`, `h`, `rTop` (frustum), `chamfer`, `bands:[z…]` rings on the side, `ribs:n` vertical lines (`ribFrom`, `ribTo`), `rings:[r…]` on the top, `top:false`, `topFace(face)`. |
104
+ | `cone` | Like `cylinder` with `rTop: 0`. Inverted cones: `r: 0.01, rTop: R`. |
105
+ | `tube` | Hollow cylinder split into angular `segments` (default 16) so things inside sort correctly: `at`, `r`, `ri`, `h`, `bands`, `ribs`, `innerBands`, `topRings`, `topRadials`. |
106
+ | `sphere` | `at` (centre), `r`, `equator`. |
107
+ | `panel` | Rounded slab standing on a plane — phones, screens, signs: `plane:'left'\|'right'\|'top'`, `at` = bottom-left of the front face (`top`: back-left of the top face), `w`, `h`, `t` thickness, `r`, `front(face)`. |
108
+ | `hull` | Convex polyhedron: `vertices:[[x,y,z]…]`, `faces:[[i,j,k,…]…]`, `crease` (deg, default 28: smaller angles render smooth). |
109
+ | `slab` | Parallelepiped: `origin`, edge vectors `u`, `v`, `w` (tilted lids, ramps). |
110
+ | `wedge` | `at` (min corner), `size:[w,d,h]`, `up:'x'\|'-x'\|'y'\|'-y'` (the high side). |
111
+ | `pyramid` | `at` (base centre), `size:[w,d]`, `h`. |
112
+ | `roof` | Gable: `at` (min corner), `size:[w,d,h]`, `axis:'x'\|'y'` (ridge direction). |
113
+
114
+ ### Flats, lines, text
115
+
116
+ | Type | Options |
117
+ |---|---|
118
+ | `rect` | On a horizontal plane: `at` (min corner, z = plane height), `size:[w,d]`, `r`, `rot`, `fill` (class or null), `line` (class or null), `dash`. |
119
+ | `circle` · `ring` · `poly` | `at` (centre / offset), `r`, `ri` (ring), `points` (poly); same fill/line/dash. |
120
+ | `grid` | `at`, `size:[w,d]`, `step`, `line`. |
121
+ | `ribbon` | A strip along `points`/`path`: `width`, `z`, `fill` (default `f-road`), `line`, `center` (dash string), `flow`. |
122
+ | `line` | `points:[[x,y,z]…]` or `path`; `line` class; `dash`; `flow` (dash speed, units/s); `width`; `arrow:'end'\|'start'\|'both'`; `arrowSize`; `dots` (end dot radius); `closed`; `reveal` (0–1, draw-on). |
123
+ | `connector` | Orthogonal route on a plane: `from:[x,y]`, `to:[x,y]`, `z`, `route:'auto'\|'x'\|'y'\|'xyx'\|'yxy'\|'straight'\|[[x,y]…]`, `radius`; plus `line` options. Arrow at the end by default. |
124
+ | `helix` | Coil between `a` and `b`: `r`, `turns`. |
125
+ | `text` | `text` (`\n` for lines), `at`, `plane:'screen'\|'top'\|'left'\|'right'\|'top-y'`, `size`, `anchor:'start'\|'middle'\|'end'`, `cls`, `weight`, `spacing`, `dx`/`dy` (screen only), `chars` (typewriter). |
126
+ | `label` | Screen-facing callout with a leader: `at`, `text`, `lift` (leader height, 28), `size`, `anchor`, `dot`. |
127
+ | `pane` | 2D content on a plane: `at` (top-left corner), `plane`, `w`, `h`, `r`, `fill` (default glass, or `false`), `line` (or `false`), custom axes `u`/`v`, `draw(face, node)`. |
128
+ | `custom` | Escape hatch: `draw(d, node)` with the Draw context; give `bounds:[x0,y0,z0,x1,y1,z1]` for sorting. |
129
+ | `diagram` | Grid of nodes + routed edges + zones + packets — see `diagrams.md`. |
130
+
131
+ ### Face drawers
132
+
133
+ Face callbacks receive a `Face` whose `(u, v)` origin is the face's top-left as seen on screen,
134
+ `u` → right, `v` → down, in world units; `face.w`, `face.h` are its size.
135
+
136
+ ```js
137
+ left: (f) => {
138
+ f.rect(6, 6, f.w - 12, 30, { r: 3, fill: 'f-screen', line: 'ln' }); // a screen
139
+ f.hlines(8, 44, 20, 10, 5); // vents (n lines)
140
+ f.vlines(u, v, w, h, n, cls);
141
+ f.grid(4, 4, f.w - 8, f.h - 8, cols, rows, { gap: 2, fill: 'f-screen', each: (i, j) => (i === j ? { fill: 'f-lit' } : null) });
142
+ f.circle(u, v, r, { fill, line });
143
+ f.line(u1, v1, u2, v2, 'ln-soft');
144
+ f.poly([[u, v], …], { fill, line, close });
145
+ f.text('LABEL', f.w / 2, f.h / 2, { size: 5, anchor: 'middle', cls: 'tx tx-label' });
146
+ f.svg('<path class="ln-strong" d="…"/>', { u: 4, v: 4, transform: 'scale(.5)' }); // any SVG in face units
147
+ f.sub(u, v, w, h); // a sub-face
148
+ }
149
+ ```
150
+
151
+ ## Materials and classes
152
+
153
+ Materials (`material: '…'`): `lit` (bright, pair with `glow: true`), `screen` (dark glass), `dark`,
154
+ `glass` (translucent), `wire` (no fill), `ghost` (faint lines), `solid` (ink), `paper` (lighter),
155
+ `accent` (uses `--iso-accent`), and `color: '#hex'` (tint).
156
+
157
+ Fill classes for face drawers and flats: `f-top f-left f-right f-bevel f-dark f-screen f-screen-on f-key
158
+ f-lit f-glass f-ink f-road f-bg f-accent f-soft`. Line classes: `ln` (edges), `ln-soft` (detail),
159
+ `ln-faint` (texture), `ln-strong`, `ln-bold`, `ln-lit`, `ln-accent`. Text classes: `tx`, `tx-label`
160
+ (mono uppercase, tracked), `tx-lit`, `tx-strong`, `tx-on-lit`, `tx-floor` (a caption lying on the floor).
161
+
162
+ Colour always comes from CSS custom properties, so themes and materials switch without re-drawing.
163
+ Override per scene with `colors`, per node with `style: { '--iso-accent': '#e05a2b' }`.
164
+
165
+ ## Animation
166
+
167
+ ### Timelines (deterministic, seekable)
168
+
169
+ ```js
170
+ const tl = s.timeline({ repeat: -1, yoyo: false, delay: 0.5, repeatDelay: 1 });
171
+ tl.to('card', { z: 12 }, { duration: 0.6, ease: 'out' })
172
+ .to('card', { x: 40 }, { duration: 1 }, '<') // same start as the previous step
173
+ .from('.tree', { opacity: 0, z: 20 }, { duration: 0.5, stagger: { each: 0.03, from: 'depth' } })
174
+ .fromTo('lid', { rot: 0 }, { rot: 90 }, { duration: 0.8 }, '+=0.2')
175
+ .set('led', { material: 'lit' }, 2) // instant change at t = 2
176
+ .call(() => s.status('done'))
177
+ .wait(1);
178
+ ```
179
+
180
+ Positions: a number (absolute), `'<'` (start of previous), `'>'` (end), `'+=0.2'`, `'-=0.2'`, `'<0.3'`.
181
+ Stagger: a number, or `{ each | amount, from: 'start'|'end'|'center'|'random'|'depth'|'front' }`.
182
+ Eases: `linear`, `in/out/inOut` + `Quad|Cubic|Quart|Expo|Sine|Back`, `outElastic`, `outBounce`,
183
+ `out` (0.16,1,0.3,1 — the default for entrances), `standard`, `smooth`, `Iso.ease.bezier(x1,y1,x2,y2)`,
184
+ `Iso.ease.steps(n)`, `Iso.ease.spring(k)`, or any `t => t` function.
185
+
186
+ ### Presets
187
+
188
+ | Preset | Options |
189
+ |---|---|
190
+ | `s.assemble(target?, o)` | Entrance: drop in and fade. Default target: every top-level item. `drop` 36, `duration` 0.8, `stagger` 0.05, `from` 'depth', `delay` 0.15, `filter`. |
191
+ | `s.float(target, o)` | Vertical bob (additive): `amp` 3, `period` 3, `phase`, `stagger` 0.17. |
192
+ | `s.travel(target, path, o)` | Move along a world path: `duration` or `speed`, `offset`, `spread` (between several nodes), `orient`, `orientOffset`, `yoyo`, `once`, `lift`, `ease`. The node's footprint centre rides the path. |
193
+ | `s.orbit(target, o)` | `travel` on a circle: `center`, `r`, `start`, `ccw`. |
194
+ | `s.pulse(target, o)` | Opacity breathing: `min` .35, `max` 1, `period` 2, `stagger`. |
195
+ | `s.blink(target, o)` | On/off: `period` 1, `duty` .5, `stagger`, `low` 0. |
196
+ | `s.spin(target, o)` | Rotate around z: `speed` (deg/s). Re-draws each frame: keep it to small objects. |
197
+ | `s.drawOn(target, o)` | Lines draw themselves: `duration`, `stagger`, `delay`. |
198
+ | `s.typewriter(target, o)` | Text appears letter by letter: `perChar` .05 or `duration`. |
199
+ | `s.hoverLift(target, o)` | Raise on hover: `z` 4. |
200
+
201
+ Moving objects are re-sorted every frame against everything they overlap, so they pass behind and
202
+ in front of other objects correctly. Under `prefers-reduced-motion` the scene shows its rest pose.
203
+
204
+ ## Export (browser)
205
+
206
+ `await s.toPNG({ scale: 2 })` → Blob · `s.toSVG()` → string with every colour inlined ·
207
+ `s.download('figure', 'png')`. For a still at a given moment, `s.pause(); s.seek(t)` first.
@@ -0,0 +1,66 @@
1
+ # Composing a figure
2
+
3
+ ## Think in world units on a grid
4
+
5
+ Sketch the plan view first (looking down): x to the right, y downward on your sketch. In the drawing,
6
+ +x runs toward the bottom-right and +y toward the bottom-left; the corner `(-x, -y)` is the back
7
+ (top of the screen), `(+x, +y)` is the front (bottom of the screen).
8
+
9
+ ```
10
+ back (-x,-y)
11
+ ◇
12
+ left ◇ ◇ right
13
+ (-x,+y) ◇ ◇ (+x,-y)
14
+ ◇
15
+ front (+x,+y)
16
+ ```
17
+
18
+ - Put the focal object near the centre or slightly toward the front.
19
+ - Tall objects belong toward the back (smaller x + y) so they do not hide others.
20
+ - Paths that should be visible (roads, conveyors, edges) run in front of tall things, not behind.
21
+
22
+ ## Scale
23
+
24
+ | Thing | Typical size |
25
+ |---|---|
26
+ | Platform for an object figure | 160–280 wide |
27
+ | Platform for a diorama | 400–640 wide |
28
+ | Diagram grid step | 80–100 between node centres, nodes 32–40 wide |
29
+ | Tree | r 5–7, h 18–24 |
30
+ | Phone / card | 13×27 / 16×10 |
31
+ | Laptop / monitor | 40×28 / 48×30 |
32
+ | Server rack | 28×34×64 |
33
+ | Building | 30–60 footprint, 10 per floor |
34
+
35
+ Mixing scales is fine in a diorama (oversized boxes on a factory floor read as "the subject"), but keep
36
+ each category consistent.
37
+
38
+ ## Layering a diorama
39
+
40
+ 1. `platform` (and decks/extensions as boxes at `z: -10`).
41
+ 2. Ground decals: roads (`ring`, `ribbon`), ponds (`circle` with `f-dark`), lots (`rect`), engraved
42
+ labels (`text` with `plane: 'top'`). All at `z: 0`.
43
+ 3. Structures: `tube` rings, `building`s, `tower`s, gates, conveyors.
44
+ 4. Props: devices, lamps, cars, benches, solar fields.
45
+ 5. Scatter: `forest` with `avoid(x, y)` to keep paths and structures clear.
46
+ 6. Movers: cards, packets, vehicles on paths — excluded from `assemble`, faded in after.
47
+
48
+ ## Objects on objects
49
+
50
+ - On a box of height `h`: `at: [x, y, h]`.
51
+ - On the ring roof of a `tube` of height `h`: `z = h`.
52
+ - On a desk: `z = desk.h`.
53
+ - Stacks: each part starts where the previous ends; leave no gap unless the gap is the point.
54
+
55
+ ## Framing
56
+
57
+ - The viewBox fits the drawing; adjust `padding` (18–40) for breathing room.
58
+ - Things that move above their rest pose (lifts, hops) may need `extend: [top, right, bottom, left]`.
59
+ - `aspect: 16/9` for heroes and videos; `zoom: 1.15` to crop a busy edge.
60
+ - The figure frame adds the captions; skip `figure` for a bare SVG (e.g. inside your own layout).
61
+
62
+ ## Accessibility
63
+
64
+ - `label` on the scene: one sentence describing what is shown.
65
+ - Interactive nodes need a `label` (aria-label) and respond to Enter/Space automatically.
66
+ - Do not encode meaning only in the lit/unlit difference — say it in a caption or label too.
@@ -0,0 +1,68 @@
1
+ # Isometric diagrams
2
+
3
+ Use the `diagram` builder for anything with nodes and edges: system architectures, data pipelines,
4
+ network maps, workflows. It places nodes on a grid, routes edges orthogonally on the floor, trims
5
+ them so arrowheads stay visible next to tall nodes, animates dashes and packets, and draws zones.
6
+
7
+ ```js
8
+ const d = s.diagram({
9
+ grid: 88, // distance between cell centres
10
+ origin: [-222, -88], // world position of cell [0, 0] (centre the diagram on the platform)
11
+ nodeSize: 34, // default block footprint
12
+ speed: 46, // packet speed (units/s), per edge override: speed | duration
13
+ route: 'auto', // default edge route: auto | x | y | xyx | yxy | straight
14
+ zones: [{ from: [2, 0], to: [5, 2], label: 'VPC · private subnets', pad: 34 }],
15
+ nodes: [
16
+ { id: 'clients', cell: [0, 1], icon: 'users', label: 'Clients' },
17
+ { id: 'api', cell: [2, 1], icon: 'server', label: 'API', size: [40, 40, 16], material: 'lit', glow: true },
18
+ { id: 'db', cell: [4.4, 0], type: 'database', r: 16 }, // any prefab via `type`; cells can be fractional
19
+ ],
20
+ edges: [
21
+ { from: 'clients', to: 'api', packets: 2, label: 'https' },
22
+ { from: 'api', to: 'db', route: 'y', packets: 1 },
23
+ ],
24
+ });
25
+ d.nodesById.get('api'); // the node objects
26
+ d.edges[0].line; d.edges[0].path; // the drawn line and its world path (for your own travellers)
27
+ ```
28
+
29
+ Node options: everything the node's prefab accepts (`block` by default: `icon`, `label`, `size`,
30
+ `material`, `color`, `glow`), plus `cell:[i,j]` or `at:[x,y,z]`.
31
+ Edge options: `route`, `packets` (count or true), `packet` (prefab, default `card`), `speed`/`duration`,
32
+ `offset`, `label`, `arrow` ('end' | 'start' | 'both' | null), `dash`, `flow` (dash speed, false = static),
33
+ `gap`, `radius`.
34
+
35
+ ## Layout rules
36
+
37
+ - Flow along **+x** (top-left → bottom-right on screen) for the main path; branch along ±y.
38
+ - Put sources at small x (back-left), sinks at large x (front-right). Readers scan the diagonal.
39
+ - Keep 1 cell between nodes that have labels on their front faces; use fractional cells to align
40
+ odd-sized nodes (`[4.4, 0]`).
41
+ - Route branches with `route: 'y'` (leave along y first) so they fan out from a node's side instead of
42
+ overlapping the main path.
43
+ - Zones: one or two, as dashed floors with a short uppercase label. Do not nest more than one level.
44
+ - One lit node: the service the diagram is about.
45
+ - Labels: 1–2 words on node faces; longer explanations go in the status caption on hover.
46
+
47
+ ## Interaction pattern
48
+
49
+ ```js
50
+ for (const [id, node] of d.nodesById) {
51
+ node.set('label', roles[id]); // aria-label
52
+ node.on('hover', () => { s.to(node, { z: 6 }, { duration: 0.22 }); s.status(roles[id]); });
53
+ node.on('leave', () => { s.to(node, { z: 0 }, { duration: 0.22 }); s.status('requests flowing'); });
54
+ }
55
+ s.assemble([...d.nodesById.values()], { stagger: 0.07, drop: 30 });
56
+ s.drawOn(d.edges.map((e) => e.line), { delay: 0.9, duration: 0.9, stagger: 0.08 });
57
+ ```
58
+
59
+ ## Without the builder
60
+
61
+ For freeform diagrams use `block` prefabs and `connector`s directly. Keep connector ends outside the
62
+ nodes' footprints, and remember a ground point within `h` behind a node of height `h` (on its −x or
63
+ −y side) is hidden by it: end the connector further away or approach from the front.
64
+
65
+ ## Stacks and layers
66
+
67
+ `stack` renders layered platforms (infrastructure → data → app) with callout labels; float a small
68
+ lit `card` above the top layer instead of lighting a whole layer.