@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
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@entro314labs/iso-engine",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.1",
4
+ "description": "Interactive isometric figures and autoplaying isometric animations in plain SVG: a projection kernel, interaction patterns, a glow kit and the Iso animation engine. No framework, no canvas, zero dependencies.",
5
+ "license": "MIT",
6
+ "author": "Dominikos Pritis",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/entro314-labs/iso-figures.git",
10
+ "directory": "packages/iso-engine"
11
+ },
12
+ "homepage": "https://github.com/entro314-labs/iso-figures/tree/main/packages/iso-engine#readme",
13
+ "bugs": "https://github.com/entro314-labs/iso-figures/issues",
14
+ "keywords": ["isometric", "svg", "illustration", "animation", "diagram", "figure", "explorable"],
15
+ "type": "module",
16
+ "sideEffects": ["*.css", "**/engine/**", "**/iso.global.js"],
17
+ "exports": {
18
+ ".": "./src/index.ts",
19
+ "./engine": "./src/engine/index.js",
20
+ "./loops": "./src/loops.ts",
21
+ "./theme.css": "./src/theme.css",
22
+ "./figure.css": "./src/figure.css",
23
+ "./package.json": "./package.json"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "exports": {
28
+ ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
29
+ "./engine": { "types": "./dist/engine/index.d.ts", "default": "./dist/engine/index.js" },
30
+ "./loops": { "types": "./dist/loops.d.ts", "default": "./dist/loops.js" },
31
+ "./theme.css": "./dist/theme.css",
32
+ "./figure.css": "./dist/figure.css",
33
+ "./engine.css": "./dist/engine.css",
34
+ "./package.json": "./package.json"
35
+ }
36
+ },
37
+ "unpkg": "./dist/iso.global.js",
38
+ "jsdelivr": "./dist/iso.global.js",
39
+ "files": ["dist", "skills", "THIRD_PARTY_NOTICES.md"],
40
+ "scripts": {
41
+ "build": "node scripts/build.mjs",
42
+ "typecheck": "tsc --noEmit",
43
+ "test": "vitest run",
44
+ "prepack": "node scripts/build.mjs"
45
+ },
46
+ "devDependencies": {
47
+ "happy-dom": "^21.0.1",
48
+ "typescript": "^7.0.2",
49
+ "vite": "^8.3.4",
50
+ "vitest": "^5.0.4"
51
+ }
52
+ }
@@ -0,0 +1,143 @@
1
+ ---
2
+ name: iso-engine
3
+ description: Make isometric line-art illustrations, interactive figures, diagrams and autoplaying animations in plain SVG with the @entro314labs/iso-engine package — a projection kernel for pressable figures, the Iso engine (depth sorting, timelines, diagrams, 35 prefabs such as devices, servers, buildings and trucks) and loop helpers for animations that narrate their beats. Use it whenever someone wants an isometric drawing, a 3D-looking technical illustration, an isometric architecture or system diagram, an interactive product figure, or an animated hero or explainer for a site, even if they never say the word isometric.
4
+ compatibility: Runs in any modern browser. Apps import the @entro314labs/iso-engine npm package (ES modules with types); pages without a bundler load dist/iso.global.js (the engine as window.Iso) or the ES modules through an import map. No other dependencies.
5
+ ---
6
+
7
+ # Isometric figures and animations
8
+
9
+ Calm technical line drawings in true isometric: 1px hairlines, fills a hair off the background, legible in dark and
10
+ light, and one accent that glows on whatever is live. Everything is plain SVG, with no canvas and no framework. This
11
+ skill ships inside the `@entro314labs/iso-engine` package, so its references match the installed version.
12
+
13
+ ## Pick the form
14
+
15
+ | Make | When | Build with | Read |
16
+ |---|---|---|---|
17
+ | **Interactive figure** | The viewer explores an object: presses parts, picks layers, walks a route, and gets real output | the kernel (`createKernel`) + `mountFigure`, or the engine inside the same contract | `references/figures.md`, `examples/matcher.js` |
18
+ | **Illustration or diorama** | A drawing of a place, product or system; motion is optional | the engine: `Iso.scene`, prefabs, primitives | `references/api.md`, `prefabs.md`, `composition.md`, `examples/engine.html` |
19
+ | **Diagram** | Nodes, edges, zones, packets: an architecture, a pipeline, a workflow | the engine's `diagram` builder, or a JSON spec | `references/diagrams.md`, `spec.md`, `examples/spec.html` |
20
+ | **Autoplaying loop** | It plays by itself: a feature working, a process step by step, a hero or explainer | the engine + `@entro314labs/iso-engine/loops` | `references/loops.md`, `animation.md`, `examples/loop.js` |
21
+
22
+ Build what was asked, and the number of pieces that was asked. Read `references/style.md` before your first drawing.
23
+
24
+ ## Set up
25
+
26
+ In an app (any framework; mount from client code, the imports are safe during server-side rendering):
27
+
28
+ ```sh
29
+ npm i @entro314labs/iso-engine
30
+ ```
31
+
32
+ ```ts
33
+ import '@entro314labs/iso-engine/theme.css'; // colour tokens, light and dark (or define them yourself)
34
+ import '@entro314labs/iso-engine/figure.css'; // figure classes, the glow kit, the engine's accent mapping
35
+ import { createKernel, mountFigure } from '@entro314labs/iso-engine'; // figures
36
+ import Iso from '@entro314labs/iso-engine/engine'; // scenes, prefabs, timelines, diagrams, export
37
+ import { loopScene, beats, narrate } from '@entro314labs/iso-engine/loops'; // autoplaying loops
38
+ ```
39
+
40
+ Without a bundler:
41
+
42
+ - **Engine pages** load the engine as a classic script, which defines `window.Iso` and works from `file://`:
43
+ `<script src="node_modules/@entro314labs/iso-engine/dist/iso.global.js"></script>` (or the same path on a CDN such as jsDelivr).
44
+ `node scripts/build.mjs page.html` inlines it into one self-contained file for sharing, an artifact or an email.
45
+ - **Kernel figures and loops** are ES modules: map `@entro314labs/iso-engine` (and `@entro314labs/iso-engine/loops`) to `dist/index.js` (and
46
+ `dist/loops.js`) with an import map and serve the page over http. `examples/figure.html` and `examples/loop.html` do
47
+ exactly this. The global script contains only the engine, not the kernel.
48
+
49
+ Colours come from CSS custom properties (`theme.css` lists them). Set `--accent` / `--accent-hi` on any ancestor to
50
+ recolour one figure, e.g. to a brand's accent. Under a strict CSP, link `dist/engine.css` with `id="iso-engine-css"`
51
+ (the engine then skips injecting its own styles) and keep figure css in your own stylesheet.
52
+
53
+ ## Before you draw
54
+
55
+ 1. **Know the subject.** For a product, read its README, landing page and code first. Write one line: what it is, who
56
+ it is for, its core job, its standout. Use its own nouns as part names. Draw what it literally is (its
57
+ architecture, its device, its app, its standout feature), not an invented metaphor, unless the brand's own visuals
58
+ already use one. Someone who knows the product should recognise it without a caption.
59
+ 2. **Real values.** Take thresholds, limits, states and timings from the code. Where only example data exists, label it
60
+ as example. Where copy and code disagree, follow the code, leave the claim out, and tell the owner.
61
+ 3. **A reference list.** Write down 15-25 things the real object has (a mainboard: VRM heatsink fins, capacitor rows,
62
+ DIMM latches, SATA block, CMOS cell, standoff holes, silkscreen…). Draw from the list; no generic filler.
63
+ 4. **Name the output** (figures) or **write the beats** (loops). A figure where pressing a part produces text, a number,
64
+ a sound or a changed display is the point; motion explains a change, it is never the payoff. A loop is 3-7 beats,
65
+ each a real state change with a caption.
66
+ 5. **Plan in world units.** Sketch the plan view; list each object with its position and size; pick the one lit moment.
67
+ Axes everywhere: +x runs down-right, +y down-left, +z up; larger x + y is nearer the viewer.
68
+
69
+ ## The bar
70
+
71
+ - **One dominant object fills ~70 % of the frame** on a tight platform, with 15-25 % empty space. A small object on a
72
+ big platform reads as unfinished however detailed it is.
73
+ - **Ground it**: the object stands on a plinth that shows its world (a street with kerb and markings for a building, a
74
+ tray with standoffs for a board, a desk edge with a cable for a device).
75
+ - **Three tiers on every part**: the silhouette; secondary form (bevels, insets, bezels, seams, lips); marks (screws,
76
+ labels, vents, latches, grilles). A box with only the first tier is unfinished. Texture comes from repetition (bays,
77
+ vents, rails, windows), not from many unique small objects.
78
+ - **Fewer, bigger parts and readable labels**: 1-3 words on the object, mono, uppercase, tracked, at least 10 px when
79
+ rendered. Captions carry the sentences. Every label fits its surface.
80
+ - **Point the detail at the viewer**: only the top and the two front faces show.
81
+ - **Density**: a full figure is roughly 600-1500 SVG elements; a card a third of a page wide 250-700.
82
+
83
+ ## The look
84
+
85
+ - Grey hairlines (structure and detail) on near-background fills, in dark and light. No gradients, no drop shadows.
86
+ - **One accent hue, and only what is live glows**: lit glass, an active LED, a wire carrying signal, a packet in flight,
87
+ the slab being explained. Nothing else gets the accent.
88
+ - **Make the lit state unmistakable** at thumbnail size: at least one large lit element. Small lit things are solid
89
+ accent; a large lit surface stays glass with a bloom behind it, never a flat accent slab.
90
+ - Small radii and chamfers for a machined look; captions in mono (`Fig 1` · name · hint · live state).
91
+ - Dim with stroke colour, never with opacity on solid faces: occlusion depends on opaque fills.
92
+
93
+ ## Motion and access
94
+
95
+ - One entrance, at most two ambient loops, and motion that says something (data moving, a device responding).
96
+ Transitions 0.2-1 s, eased; loops of 2 s or more. Under `prefers-reduced-motion` everything jumps to its end state or
97
+ rest pose (the engine, `createTween` and `createSequence` handle this; keep it true for your own code).
98
+ - Ambient motion and loops pause when off screen or when the page is hidden; anything moving longer than 5 s has a
99
+ pause control.
100
+ - The svg has `role="img"`, `tabindex="0"` and an `aria-label` saying what it is and how to operate it (`mountFigure`
101
+ sets these from `aria`; scenes take `label`). Every interactive part works with the keyboard. Don't carry meaning in
102
+ the lit/unlit difference alone: say it in the readout or caption too.
103
+
104
+ ## Verify
105
+
106
+ Render it in a real browser and look at it; don't report a drawing you haven't seen.
107
+
108
+ - [ ] No console errors.
109
+ - [ ] Nothing floats, sinks or pokes through what is in front of it; nothing is clipped by the frame.
110
+ - [ ] Every interaction works with the mouse and with the keyboard alone, and changes the readout.
111
+ - [ ] Moving or lifted things checked at their end states and mid-move (screenshots, or `scene.seek(t)` for engine
112
+ scenes): they pass in front of and behind things correctly.
113
+ - [ ] Labels fit their surfaces and are readable at the delivered size; check a 2× crop of the busiest area.
114
+ - [ ] Reduced motion shows a complete, meaningful frame.
115
+ - [ ] The recognition test: would someone who knows the subject recognise it without the caption?
116
+
117
+ If you couldn't render it, say so plainly.
118
+
119
+ ## Don'ts
120
+
121
+ - No third-party logos, product silhouettes or trademarked marks; generic part names. Brand marks only when the owner
122
+ supplies them. No people at laptops, no emoji, no rainbow palettes, no perspective.
123
+ - No hand-typed skewed polygons for faces: draw flat in a plane (`TOP`/`FRONT`/`SIDE`, face drawers).
124
+ - No claims the product's code contradicts, and no placeholder numbers presented as real.
125
+ - No CSS `transform` on a `<g>` that also has a `transform` attribute (the CSS one replaces it); no re-framing during an
126
+ animation; no timers that rebuild pressable shapes.
127
+
128
+ ## Files
129
+
130
+ | Path | What |
131
+ |---|---|
132
+ | `references/figures.md` | Kernel figures: the contract, the kernel, the glow kit, procedure, input, painter's order, layers & links (units, selection, connections, sequences, exploded layers, cutaway, zoom, callouts, camera tilt), engine figures, frameworks |
133
+ | `references/loops.md` | Autoplaying loops: story, contract and helpers, hosting, timing |
134
+ | `references/api.md` · `prefabs.md` | The engine: scenes, nodes, primitives, face drawers, materials, timelines, export · the prefab catalogue |
135
+ | `references/animation.md` · `diagrams.md` · `spec.md` | Motion recipes · the diagram builder · JSON scenes |
136
+ | `references/composition.md` · `style.md` · `troubleshooting.md` | Layout and scale · the visual language · when something looks wrong |
137
+ | `examples/figure.html` + `matcher.js` | A kernel figure mounted with `mountFigure` (six switches rank six flatshares) |
138
+ | `examples/loop.html` + `loop.js` | A loop hosted politely: poster, visibility, pause |
139
+ | `examples/engine.html` · `spec.html` | An engine scene in JS · the same kind of scene as JSON |
140
+ | `scripts/build.mjs` | Inline the engine (and other local classic scripts) into one self-contained HTML file |
141
+
142
+ The examples load the package's own `dist/` by relative path; copying one elsewhere, point those paths at
143
+ `node_modules/@entro314labs/iso-engine/dist/` or a CDN.
@@ -0,0 +1,42 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>Laptop and server</title>
7
+ <style>
8
+ html,body{margin:0;background:#0b0c0d}
9
+ main{max-width:960px;margin:0 auto;padding:24px 16px}
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <main id="app"></main>
14
+ <!-- the engine as a classic script (window.Iso), from this package's dist/. Copying this page elsewhere: point
15
+ src at wherever iso.global.js is served (node_modules/@entro314labs/iso-engine/dist/, or a CDN such as jsDelivr). -->
16
+ <script src="../../../dist/iso.global.js"></script>
17
+ <script>
18
+ /* Laptop and server — world units: x → right-down, y → left-down, z → up. The platform top is z = 0. */
19
+ const s = Iso.scene('#app', {
20
+ figure: { index: 'Fig. 1', title: 'Laptop and server', hint: 'Hover the rack', status: 'ready' },
21
+ label: 'A laptop and a server rack on a platform, with a lit card floating between them.', // what a screen reader hears
22
+ theme: 'dark', // dark · light · paper · blueprint · terminal
23
+ });
24
+
25
+ /* 1. ground */
26
+ s.platform({ size: [240, 180] });
27
+
28
+ /* 2. objects (prefabs first; primitives for custom shapes) */
29
+ s.laptop({ at: [-30, -10, 0] });
30
+ s.server({ id: 'rack', at: [60, -40, 0] });
31
+ s.hoverLift('rack', { z: 5 });
32
+
33
+ /* 3. one lit moment */
34
+ s.card({ id: 'card', at: [40, 40, 0] });
35
+
36
+ /* 4. motion: an entrance + at most two ambient loops */
37
+ s.assemble();
38
+ s.float('card', { amp: 4, period: 2.6 });
39
+ s.blink('.led', { period: 1.2, stagger: 0.3 });
40
+ </script>
41
+ </body>
42
+ </html>
@@ -0,0 +1,51 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>Flatshare matcher</title>
7
+ <!-- Paths point into this package's dist/. Serve the folder over http (ES modules don't load from file://), e.g.
8
+ `npx serve node_modules/@entro314labs/iso-engine` and open /skills/iso-engine/examples/figure.html. Copying this page
9
+ elsewhere: point the stylesheets and the import map at node_modules/@entro314labs/iso-engine/dist/ or a CDN (jsDelivr). -->
10
+ <link rel="stylesheet" href="../../../dist/theme.css">
11
+ <link rel="stylesheet" href="../../../dist/figure.css">
12
+ <script type="importmap">{ "imports": { "@entro314labs/iso-engine": "../../../dist/index.js" } }</script>
13
+ <style>
14
+ body { margin:0; background:var(--page); color:var(--ink); font:13px/1.4 var(--mono); }
15
+ main { max-width:960px; margin:0 auto; padding:32px 16px; }
16
+ .plate { margin:0; background:var(--panel); border:1px solid var(--edge); border-radius:18px; padding:18px 20px;
17
+ display:flex; flex-direction:column; gap:6px; }
18
+ .cap { display:flex; flex-wrap:wrap; justify-content:space-between; gap:4px 16px; letter-spacing:.14em;
19
+ text-transform:uppercase; }
20
+ .cap .fn, .cap .readout { text-transform:none; }
21
+ .readout { color:var(--live); font-variant-numeric:tabular-nums; }
22
+ .host { height:min(70vh, 560px); } /* the stage fills its host, so the host needs a size */
23
+ </style>
24
+ </head>
25
+ <body>
26
+ <main>
27
+ <figure class="plate">
28
+ <div class="cap"><span class="fn">Fig 1</span><span class="name"></span></div>
29
+ <div class="host"></div>
30
+ <div class="cap"><span class="hint"></span><span class="readout" aria-live="polite"></span></div>
31
+ </figure>
32
+ </main>
33
+ <script type="module">
34
+ import { mountFigure } from '@entro314labs/iso-engine';
35
+ import matcher from './matcher.js';
36
+
37
+ const $ = sel => document.querySelector(sel);
38
+ $('.name').textContent = matcher.name;
39
+ $('.hint').textContent = matcher.hint;
40
+ const fig = mountFigure($('.host'), matcher, {
41
+ readout: t => { $('.readout').textContent = t; },
42
+ demo: new URLSearchParams(location.search).has('demo'), // ?demo opens it already alive
43
+ });
44
+ // page-level keys go to the figure; arrows and Escape belong on stage listeners inside it
45
+ addEventListener('keydown', e => {
46
+ if (e.metaKey || e.ctrlKey || e.altKey) return;
47
+ if (fig.handle.key?.(e)) e.preventDefault();
48
+ });
49
+ </script>
50
+ </body>
51
+ </html>
@@ -0,0 +1,68 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>Card lift</title>
7
+ <!-- Serve over http (ES modules don't load from file://). Copying this page elsewhere: point the stylesheets and the
8
+ import map at node_modules/@entro314labs/iso-engine/dist/ or a CDN (jsDelivr). -->
9
+ <link rel="stylesheet" href="../../../dist/theme.css">
10
+ <link rel="stylesheet" href="../../../dist/figure.css">
11
+ <script type="importmap">{ "imports": {
12
+ "@entro314labs/iso-engine": "../../../dist/index.js",
13
+ "@entro314labs/iso-engine/loops": "../../../dist/loops.js",
14
+ "@entro314labs/iso-engine/engine": "../../../dist/engine/index.js"
15
+ } }</script>
16
+ <style>
17
+ body { margin:0; background:var(--page); color:var(--ink); font:13px/1.4 var(--mono); }
18
+ main { max-width:520px; margin:0 auto; padding:32px 16px; }
19
+ .card { margin:0; background:var(--panel); border:1px solid var(--edge); border-radius:18px; padding:16px 18px;
20
+ display:flex; flex-direction:column; gap:6px; }
21
+ .cap { display:flex; flex-wrap:wrap; justify-content:space-between; gap:4px 16px; letter-spacing:.14em; text-transform:uppercase; }
22
+ .cap .say { text-transform:none; color:var(--live); }
23
+ .host { aspect-ratio:4 / 3; cursor:pointer; }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <main>
28
+ <figure class="card">
29
+ <div class="cap"><span class="kind"></span><span class="name"></span></div>
30
+ <div class="host" tabindex="0" role="button" aria-pressed="false"></div>
31
+ <div class="cap"><span class="counter"></span><span class="say" aria-live="off"></span></div>
32
+ </figure>
33
+ </main>
34
+ <script type="module">
35
+ import loop from './loop.js';
36
+
37
+ const $ = sel => document.querySelector(sel);
38
+ const host = $('.host');
39
+ $('.kind').textContent = loop.kind;
40
+ $('.name').textContent = loop.name;
41
+ host.dataset.loop = loop.id; // scope for the loop's css, and the accent mapping in figure.css
42
+ host.setAttribute('aria-label', `${loop.aria} Press to pause or play.`);
43
+
44
+ let last = '', inView = false, userPaused = false;
45
+ const { scene, posterTime } = loop.mount(host, {
46
+ say: t => { last = t; if (!userPaused) $('.say').textContent = t; },
47
+ beat: (i, n, name) => { $('.counter').textContent = `${String(i + 1).padStart(2, '0')} / ${String(n).padStart(2, '0')} · ${name}`; },
48
+ });
49
+ scene.pause();
50
+ scene.seek(posterTime);
51
+
52
+ // play only while a quarter of it is visible and the page is in front; click, Space or Enter pauses
53
+ const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
54
+ const sync = () => (inView && !userPaused && !reduced && !document.hidden ? scene.play() : scene.pause());
55
+ new IntersectionObserver(([e]) => { inView = !!e && e.intersectionRatio >= 0.25; sync(); }, { threshold: [0, 0.25] }).observe(host);
56
+ document.addEventListener('visibilitychange', sync);
57
+ const toggle = () => {
58
+ if (reduced) return;
59
+ userPaused = !userPaused;
60
+ host.setAttribute('aria-pressed', String(userPaused));
61
+ $('.say').textContent = userPaused ? 'paused · press to play' : last;
62
+ sync();
63
+ };
64
+ host.addEventListener('click', toggle);
65
+ host.addEventListener('keydown', e => { if (e.key === ' ' || e.key === 'Enter') { e.preventDefault(); toggle(); } });
66
+ </script>
67
+ </body>
68
+ </html>
@@ -0,0 +1,36 @@
1
+ // @ts-check
2
+ /*
3
+ * A loop: a card lifts off its dock, lights up, and lands again. Shows the loop contract (mount → { scene,
4
+ * posterTime }), beats laid end to end, captions narrated from the timeline, one lit moment with a halo behind it.
5
+ * loop.html hosts it: paused on its poster, playing only while visible, click to pause.
6
+ */
7
+ import { beats, halo, loopScene, narrate } from '@entro314labs/iso-engine/loops';
8
+
9
+ const ARIA = 'A card lifts off its dock, lights up, and lands again.';
10
+
11
+ /** @type {import('@entro314labs/iso-engine/loops').Loop} */
12
+ const loop = {
13
+ id: 'card-lift',
14
+ project: 'Example',
15
+ kind: 'flow',
16
+ name: 'Card lift',
17
+ aria: ARIA,
18
+ mount(host, ctx) {
19
+ const { list, cycle } = beats([['lift', 1.8], ['lit', 1.8], ['land', 1.8]]);
20
+ const s = loopScene(host, ARIA, 2.4);
21
+ s.add('platform', { size: [110, 84] });
22
+ s.add('box', { id: 'dock', center: [0, 0, 0], size: [52, 38, 4], r: 4, chamfer: 1 });
23
+ halo(s, 'glow', [-21, -14, 4.2], [42, 28], 6);
24
+ s.add('box', { id: 'card', center: [0, 0, 4], size: [34, 22, 2], r: 2, chamfer: 0.6 });
25
+ const tl = s.timeline({ repeat: -1 });
26
+ tl.to('card', { z: 30 }, { duration: 1 }, 0)
27
+ .set('card', { material: 'lit', glow: true }, 1.8).to('glow', { opacity: 1 }, { duration: 0.4 }, 1.8)
28
+ .set('card', { material: undefined, glow: false }, 3.6).to('glow', { opacity: 0 }, { duration: 0.4 }, 3.6)
29
+ .to('card', { z: 0 }, { duration: 1 }, 3.6)
30
+ .wait(cycle - 4.6);
31
+ narrate(tl, ctx, list, ['lift · the card leaves its dock', 'lit · it carries the signal', 'land · back on the dock']);
32
+ return { scene: s, posterTime: 2.4 };
33
+ },
34
+ };
35
+
36
+ export default loop;
@@ -0,0 +1,134 @@
1
+ // @ts-check
2
+ /*
3
+ * A kernel figure: a flatshare matcher. Six switches set your habits; the screen ranks six flatshares by how well
4
+ * the people living there match, and lights the rows at or above 75 %. Every press changes the screen and the readout.
5
+ *
6
+ * Shows the figure contract (mount → { key, destroy, demo }), the kernel (box, FRONT/SIDE/TOP planes, flat detail,
7
+ * frame), the glow kit (lit glass with a halo behind it, latched switches, lit bars) and CSS scoped to the figure.
8
+ * figure.html mounts it with mountFigure; in an app, import it the same way.
9
+ */
10
+ import { createKernel, frame, ln, rep, tx } from '@entro314labs/iso-engine';
11
+
12
+ /** Habits you set. `w` is how much a mismatch matters when sharing a flat. */
13
+ const TRAITS = [
14
+ { label: 'EARLY', name: 'early bird', w: 1.5 },
15
+ { label: 'TIDY', name: 'tidy', w: 2 },
16
+ { label: 'GUESTS', name: 'guests over', w: 1 },
17
+ { label: 'PETS', name: 'pets', w: 2 },
18
+ { label: 'SMOKES', name: 'smokes', w: 3 },
19
+ { label: 'REMOTE', name: 'works from home', w: 1 },
20
+ ];
21
+ /** Example flatshares with a free room, and the habits of the people already living there. */
22
+ const HOMES = [
23
+ { flat: '1A', name: 'eleni', t: [0, 1, 1, 0, 0, 1] },
24
+ { flat: '2A', name: 'theo', t: [0, 0, 0, 0, 0, 1] },
25
+ { flat: '2C', name: 'nikos', t: [1, 1, 0, 0, 0, 1] },
26
+ { flat: '3B', name: 'maria', t: [1, 0, 1, 1, 0, 0] },
27
+ { flat: '3C', name: 'jonas', t: [0, 0, 1, 0, 1, 1] },
28
+ { flat: '4A', name: 'aiko', t: [1, 1, 0, 1, 0, 0] },
29
+ ];
30
+ const LIT = 75; // match % at which a row lights
31
+ const W = TRAITS.reduce((s, t) => s + t.w, 0);
32
+ /**
33
+ * Weighted agreement: the share of total trait weight where your answer equals the household's, as a whole percent.
34
+ * @param {number[]} me @param {{ t: number[] }} home
35
+ */
36
+ const score = (me, home) => Math.round((100 * TRAITS.reduce((s, t, i) => s + (me[i] === home.t[i] ? t.w : 0), 0)) / W);
37
+
38
+ const BX = 360, BD = 220, BH = 30; // base slab
39
+ const PITCH = 52, SW = 36, SX0 = (BX - (5 * PITCH + SW)) / 2;
40
+ const SCR = { x: 12, y: 12, w: 296, h: 126 }; // the glass, in the housing's FRONT plane
41
+
42
+ /** @type {import('@entro314labs/iso-engine').Figure} */
43
+ const matcher = {
44
+ id: 'matcher',
45
+ name: 'Flatshare matcher',
46
+ hint: 'Press 1–6 or tap a switch',
47
+ aria: 'A flatshare matcher. Six switches set your habits and the screen ranks six flatshares by how well they match. Press keys 1 to 6 or tap a switch.',
48
+ css: `
49
+ [data-fig="matcher"] .switch.latched { transform:translateY(2px); }
50
+ [data-fig="matcher"] .switch.latched.down { transform:translateY(4px); }
51
+ [data-fig="matcher"] svg.stage .switch.latched text { fill:var(--body); }`,
52
+
53
+ mount({ stage, readout, flash, after }) {
54
+ const k = createKernel();
55
+ const { box, FRONT, SIDE, TOP } = k;
56
+ const state = /** @type {{ me: number[], last: number | null }} */ ({ me: [0, 1, 0, 0, 0, 1], last: null });
57
+
58
+ // scene, back to front: base, its detail, the screen housing, the deck print, bezels, then the switch caps
59
+ let svg = box(0, 0, 0, BX, BD, BH, 10);
60
+ svg += `<g transform="${SIDE(BX, BD, BH)}">${rep(18, i => ln(20 + i * 10, 9, 20 + i * 10, 21))}</g>`;
61
+ svg += `<g transform="${FRONT(0, BD, BH)}">${tx(16, 19, 'MATCHER · M-6', 8)}</g>`;
62
+ svg += box(20, 10, BH, 320, 40, 150, 8);
63
+ svg += `<g transform="${SIDE(340, 50, BH + 150)}">${rep(16, i => ln(9, 22 + i * 7, 31, 22 + i * 7))}</g>`;
64
+ svg += `<g transform="${FRONT(20, 50, BH + 150)}">
65
+ <rect class="glow-halo" filter="url(#fx-bloom)" x="${SCR.x - 6}" y="${SCR.y - 6}" width="${SCR.w + 12}" height="${SCR.h + 12}" rx="12"/>
66
+ <rect class="face glass" x="${SCR.x}" y="${SCR.y}" width="${SCR.w}" height="${SCR.h}" rx="8"/>
67
+ ${tx(24, 30, 'MATCHES', 8, 'start', 'lcd')}
68
+ ${tx(296, 30, `≥${LIT}% LIT`, 8, 'end', 'lcd dim')}
69
+ ${ln(24, 36, 296, 36)}
70
+ <g class="rows"></g></g>`;
71
+ svg += `<g transform="${TOP(0, 0, BH)}">
72
+ ${tx(SX0, 80, 'YOUR HABITS · KEYS 1–6', 7)}
73
+ ${TRAITS.map((t, i) => tx(SX0 + i * PITCH + SW / 2, 168, t.label, 6.5, 'middle', '', PITCH - 4)).join('')}
74
+ ${tx(BX - SX0, 200, `WEIGHTED · ${W} PTS`, 7, 'end')}</g>`;
75
+ TRAITS.forEach((_, i) => { svg += `<g class="deco">${box(SX0 + i * PITCH - 3, 97, BH, SW + 6, 52, 3, 3)}</g>`; });
76
+ TRAITS.forEach((_, i) => {
77
+ const x = SX0 + i * PITCH + 3;
78
+ // the press group carries no transform attribute: CSS moves it, the plane matrix sits on a nested group
79
+ svg += `<g class="press switch" data-i="${i}">${box(x, 103, BH + 3, SW - 6, 40, 9, 3)}
80
+ <g transform="${TOP(x, 103, BH + 12)}">${tx((SW - 6) / 2, 25, String(i + 1), 12, 'middle')}</g></g>`;
81
+ });
82
+ stage.innerHTML = svg;
83
+ frame(stage, k.pts);
84
+
85
+ const switches = [...stage.querySelectorAll('.switch')];
86
+ const rows = /** @type {SVGGElement} */ (stage.querySelector('.rows'));
87
+ const glass = stage.querySelector('.glass'), halo = stage.querySelector('.glow-halo');
88
+
89
+ // render touches classes and the screen's text only, never the pressable shapes
90
+ const render = () => {
91
+ switches.forEach((el, i) => el.classList.toggle('latched', !!state.me[i]));
92
+ const ranked = HOMES.map(h => ({ ...h, pct: score(state.me, h) }))
93
+ .sort((a, b) => b.pct - a.pct || a.flat.localeCompare(b.flat));
94
+ rows.innerHTML = ranked.map((h, j) => {
95
+ const y = 52 + j * 15, on = h.pct >= LIT, dim = on ? '' : ' dim';
96
+ return tx(24, y, h.flat, 8.5, 'start', `lcd${dim}`) + tx(46, y, h.name, 8.5, 'start', `lcd${dim}`, 54) +
97
+ `<rect class="detail" x="104" y="${y - 6}" width="130" height="6" rx="1"/>` +
98
+ `<rect class="led${on ? ' hot' : ''}" x="104" y="${y - 6}" width="${1.3 * h.pct}" height="6" rx="1"/>` +
99
+ tx(296, y, `${h.pct}%`, 8.5, 'end', `lcd${dim}`);
100
+ }).join('');
101
+ const lit = ranked.filter(h => h.pct >= LIT).length, best = ranked[0];
102
+ glass?.classList.toggle('hot', lit > 0);
103
+ halo?.classList.toggle('hot', lit > 0);
104
+ const parts = [`${state.me.filter(Boolean).length} on`, `${lit} lit`];
105
+ if (best) parts.push(`best ${best.name} ${best.pct}%`);
106
+ if (state.last !== null) parts.unshift(`${TRAITS[state.last]?.name} ${state.me[state.last] ? 'on' : 'off'}`);
107
+ readout(parts.join(' · '));
108
+ };
109
+
110
+ /** @param {number} i */
111
+ const press = i => {
112
+ const el = switches[i];
113
+ if (!el) return false;
114
+ state.me[i] = state.me[i] ? 0 : 1;
115
+ state.last = i;
116
+ flash(el);
117
+ render();
118
+ return true;
119
+ };
120
+
121
+ stage.addEventListener('click', e => {
122
+ const sw = /** @type {Element} */ (e.target).closest('.switch');
123
+ if (sw instanceof SVGElement) press(Number(sw.dataset.i));
124
+ });
125
+ render();
126
+
127
+ return {
128
+ key: e => !e.repeat && /^[1-6]$/.test(e.key) && press(Number(e.key) - 1),
129
+ demo() { [0, 3, 4, 4].forEach((i, j) => after(500 + j * 700, () => press(i))); },
130
+ };
131
+ },
132
+ };
133
+
134
+ export default matcher;
@@ -0,0 +1,42 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>Request path</title>
7
+ <style>
8
+ html,body{margin:0;background:#0b0c0d}
9
+ main{max-width:960px;margin:0 auto;padding:24px 16px}
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <main id="app"></main>
14
+ <!-- the engine as a classic script (window.Iso), from this package's dist/. Copying this page elsewhere: point
15
+ src at wherever iso.global.js is served (node_modules/@entro314labs/iso-engine/dist/, or a CDN such as jsDelivr). -->
16
+ <script src="../../../dist/iso.global.js"></script>
17
+ <script type="application/json" id="spec">
18
+ {
19
+ "theme": "dark",
20
+ "figure": { "index": "Fig. 1", "title": "Request path", "hint": "Hover a block", "status": "ready" },
21
+ "label": "A client sending requests to an API, as an isometric diagram.",
22
+ "objects": [
23
+ { "type": "platform", "size": [300, 180] },
24
+ { "type": "diagram", "grid": 130, "origin": [-65, 0],
25
+ "nodes": [
26
+ { "id": "a", "cell": [0, 0], "icon": "user", "label": "Client" },
27
+ { "id": "b", "cell": [1, 0], "icon": "server", "label": "API", "material": "lit", "glow": true }
28
+ ],
29
+ "edges": [ { "from": "a", "to": "b", "packets": 1, "label": "https" } ]
30
+ }
31
+ ],
32
+ "animations": [
33
+ { "type": "assemble", "stagger": 0.1 }
34
+ ],
35
+ "interactions": [
36
+ { "target": ["a", "b"], "hover": "lift", "z": 5 }
37
+ ]
38
+ }
39
+ </script>
40
+ <script>Iso.render(JSON.parse(document.getElementById('spec').textContent), '#app');</script>
41
+ </body>
42
+ </html>