iso-explainer 0.0.0-stage → 1.1.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 (48) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +119 -2
  3. package/README.pt-BR.md +89 -0
  4. package/bin/iso-explainer.mjs +75 -0
  5. package/package.json +37 -4
  6. package/skills/iso-explainer/SKILL.md +99 -0
  7. package/skills/iso-explainer/assets/figure/figure.mjs +93 -0
  8. package/skills/iso-explainer/assets/fonts/OFL.txt +93 -0
  9. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-400-normal.woff2 +0 -0
  10. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-500-normal.woff2 +0 -0
  11. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-600-normal.woff2 +0 -0
  12. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-700-normal.woff2 +0 -0
  13. package/skills/iso-explainer/assets/fonts/jetbrains-mono-latin-800-normal.woff2 +0 -0
  14. package/skills/iso-explainer/assets/runtime/ANATOMY-LICENSE.txt +21 -0
  15. package/skills/iso-explainer/assets/runtime/LUCIDE-LICENSE.txt +43 -0
  16. package/skills/iso-explainer/assets/runtime/app.js +727 -0
  17. package/skills/iso-explainer/assets/runtime/engine.js +1224 -0
  18. package/skills/iso-explainer/assets/runtime/icons.js +205 -0
  19. package/skills/iso-explainer/assets/runtime/kit.js +676 -0
  20. package/skills/iso-explainer/assets/runtime/looks-core.js +162 -0
  21. package/skills/iso-explainer/assets/runtime/looks.js +508 -0
  22. package/skills/iso-explainer/assets/runtime/styles.css +461 -0
  23. package/skills/iso-explainer/assets/runtime/template.html +29 -0
  24. package/skills/iso-explainer/assets/templates/starter.course.json +134 -0
  25. package/skills/iso-explainer/examples/arquitetura-pedidos.docs.json +1745 -0
  26. package/skills/iso-explainer/examples/catalogo-looks.course.json +599 -0
  27. package/skills/iso-explainer/examples/engenharia-na-pratica.course.json +2079 -0
  28. package/skills/iso-explainer/examples/figures/token-bucket.build.mjs +111 -0
  29. package/skills/iso-explainer/examples/figures/token-bucket.html +962 -0
  30. package/skills/iso-explainer/examples/historia-pedidos.story.json +1874 -0
  31. package/skills/iso-explainer/references/architecture-mode.md +82 -0
  32. package/skills/iso-explainer/references/design-system.md +58 -0
  33. package/skills/iso-explainer/references/engine.md +64 -0
  34. package/skills/iso-explainer/references/entities.md +72 -0
  35. package/skills/iso-explainer/references/figure-craft.md +62 -0
  36. package/skills/iso-explainer/references/flows.md +67 -0
  37. package/skills/iso-explainer/references/inside.md +74 -0
  38. package/skills/iso-explainer/references/layout.md +134 -0
  39. package/skills/iso-explainer/references/looks.md +60 -0
  40. package/skills/iso-explainer/references/schema.md +157 -0
  41. package/skills/iso-explainer/references/story-mode.md +72 -0
  42. package/skills/iso-explainer/references/storytelling.md +56 -0
  43. package/skills/iso-explainer/scripts/build.mjs +82 -0
  44. package/skills/iso-explainer/scripts/harvest.mjs +240 -0
  45. package/skills/iso-explainer/scripts/lib/layout.mjs +111 -0
  46. package/skills/iso-explainer/scripts/lib/resolve.mjs +269 -0
  47. package/skills/iso-explainer/scripts/snapshot.mjs +159 -0
  48. package/skills/iso-explainer/scripts/validate.mjs +58 -0
@@ -0,0 +1,508 @@
1
+ // iso-explainer · looks.js
2
+ // "Looks": a block can be drawn as a small physical object whose working IS what the component
3
+ // does (a boom gate for a gateway, a conveyor for a queue, a press for a worker…), in the style of
4
+ // the anatomy skill: many small precise solids, four-tone faces, painter's order, lines that end on
5
+ // something, one lit part, calm motion driven by the scene (packets, cpu, failures).
6
+ //
7
+ // A look is { build(e, P, pal) → { env, layers }, state(), ping(s, kind, failed), tick(s, dt, e) }.
8
+ // layers: SVG strings in painter's order, or { live, draw(s, e) } parts the engine redraws when
9
+ // tick() returns { [live]: true }. env: { hx, hy, top } in world units (for the outline).
10
+ // Shared camera/painters are in looks-core.js; geometry comes from the vendored anatomy kit.
11
+ import { slabOf, cylinder, insetPlan, planOutline, lineOnTop, onTop, segment, pathOf, sideRing, pointsAt, radialTicks, ring, knurl, dotGrid } from './kit.js';
12
+ import { W, NEUTRAL, toneOf, solidTone, solid, line, stroke, glass, fillPath, dots, screw, add, mul, beam, plinth, env, rig, planeX, planeY, gear, circle2 } from './looks-core.js';
13
+
14
+ /* ───────────────────────── catalogue ───────────────────────── */
15
+
16
+ // GATEWAY: a boom barrier with a cabinet and a two-lens lamp. Each request lifts the boom;
17
+ // a failure (429/401) flashes the lamp red.
18
+ const gateway = {
19
+ build(e, P, pal) {
20
+ const hx = (e.d ?? e.s) * W / 2, hy = (e.w ?? e.s) * W / 2, u = Math.min(hx, hy) / 40, z0 = 6 * u;
21
+ const at = (x, y, z) => [x * u, y * u, z0 + z * u];
22
+ const pl = (x, y, w, d, r) => ({ x: x * u, y: y * u, w: w * u, d: d * u, r: r * u });
23
+ const out = [plinth(P, hx, hy, z0, toneOf(pal))];
24
+ // lane: two edge lines and chevrons pointing along +x
25
+ out.push(line(lineOnTop([-34 * u, -8 * u], [34 * u, -8 * u], z0, P), 'lo') + line(lineOnTop([-34 * u, 24 * u], [34 * u, 24 * u], z0, P), 'lo'));
26
+ for (const cx of [8, 20]) out.push(line(onTop([[cx * u - 3 * u, 4 * u], [cx * u + 2 * u, 8 * u], [cx * u - 3 * u, 12 * u]], z0, P), 'mid', 0.9));
27
+ // bollards at the lane mouth (back, then front)
28
+ const bollard = (x, y) => solid(cylinder(x * u, y * u, 3 * u, z0, 13 * u, P, 20), NEUTRAL) +
29
+ solid(cylinder(x * u, y * u, 3.05 * u, z0 + 7 * u, 2.6 * u, P, 20), solidTone('#efb041'), { line: 'mid', crease: 'faint' });
30
+ out.push(bollard(-33, -12));
31
+ // cabinet with cap, door, vents and the lamp head
32
+ const cab = pl(-32, -36, 26, 24, 3);
33
+ const door = pointsAt([at(-28, -12, 6), at(-12, -12, 6), at(-12, -12, 34), at(-28, -12, 34)], P);
34
+ const vents = [0, 1, 2, 3].map((i) => segment(at(-6, -32 + i * 4, 30), at(-6, -29.4 + i * 4, 30), P) + segment(at(-6, -32 + i * 4, 25), at(-6, -29.4 + i * 4, 25), P)).join('');
35
+ out.push(solid(slabOf(cab, z0, 42 * u, P, 6, 0.8), toneOf(pal), {
36
+ inner: line(pathOf(door, true), 'mid') + dots(pointsAt([at(-14.5, -12, 20)], P), 1.1) + line(vents, 'mid'),
37
+ }));
38
+ out.push(solid(slabOf(pl(-34, -38, 30, 28, 3.5), z0 + 42 * u, 3.5 * u, P, 6, 0.6), NEUTRAL, { crease: 'lo' }));
39
+ out.push(solid(slabOf(pl(-28, -32, 11, 11, 2.5), z0 + 45.5 * u, 12 * u, P, 6, 0.5), solidTone('#3B3530'), { crease: 'mid' }));
40
+ // axle boss on the cabinet's +x face
41
+ out.push(fillPath(sideRing(at(-6, -22, 30), 4.2 * u, 'x', P, 18), '#ebe3d7') + dots(pointsAt([at(-6, -22, 30)], P), 1.3));
42
+ // fork post the boom rests on (front)
43
+ const fork = solid(slabOf(pl(-6.5, 30, 9, 7, 1.5), z0, 26 * u, P, 4, 0.6), toneOf(pal)) +
44
+ solid(slabOf(pl(-6.5, 30, 2.2, 7, 0.6), z0 + 26 * u, 5 * u, P, 3), NEUTRAL) +
45
+ solid(slabOf(pl(0.3, 30, 2.2, 7, 0.6), z0 + 26 * u, 5 * u, P, 3), NEUTRAL);
46
+ const bollard2 = bollard(33, 28);
47
+ // live: lamp lenses (green / red), then the boom in front of the cabinet, then the fork and front bollard
48
+ const lens = (z, fill) => fillPath(sideRing(at(-22.5, -21, z), 2.4 * u, 'y', P, 16), fill, 'hi');
49
+ const lamp = (s) => `<g opacity="${(1 - s.red).toFixed(2)}">${lens(53.5, '#7fc278')}</g><g opacity="${s.red.toFixed(2)}">${lens(53.5, '#e5534b')}</g>${lens(48.5, '#8a8076')}`;
50
+ const boom = (s) => {
51
+ const a = (s.angle * Math.PI) / 180, piv = at(-2, -22, 30), dir = [0, Math.cos(a), Math.sin(a)];
52
+ const p = (t) => add(piv, mul(dir, t * u)), side = [1, 0, 0];
53
+ let svg = beam(p(-8), p(-2), side, 5.4 * u, 5.4 * u, P, solidTone('#5F574E'), { line: 'hi' }); // counterweight
54
+ const seg = 9.6;
55
+ for (let i = 0; i < 6; i++) svg += beam(p(-2 + i * seg), p(-2 + (i + 1) * seg), side, 3.8 * u, 3.6 * u, P, i % 2 ? solidTone('#e5534b') : NEUTRAL, { line: 'hi' });
56
+ return svg + dots(pointsAt([at(-2, -22, 30)], P), 1.3);
57
+ };
58
+ return {
59
+ env: env(hx, hy, z0 + 58 * u),
60
+ layers: [...out, { live: 'lamp', draw: lamp }, { live: 'boom', draw: boom }, fork, bollard2],
61
+ };
62
+ },
63
+ state: () => ({ angle: 0, open: 0, red: 0 }),
64
+ ping(s, kind, failed) { if (failed || kind === 'kill') s.red = 1; else s.open = 0.3; },
65
+ tick(s, dt) {
66
+ s.open = Math.max(0, s.open - dt);
67
+ const target = s.open > 0 ? 62 : 0, k = target > s.angle ? 9 : 4.5;
68
+ const prev = { angle: s.angle, red: s.red };
69
+ s.angle += (target - s.angle) * (1 - Math.exp(-k * dt));
70
+ s.red = Math.max(0, s.red - dt * 1.4);
71
+ return { boom: Math.abs(s.angle - prev.angle) > 0.05, lamp: s.red > 0 || prev.red > 0 };
72
+ },
73
+ };
74
+
75
+ // QUEUE: a belt conveyor on legs; trays ride the belt from the intake hopper to the far end.
76
+ // The belt runs while messages are in the scene; `items` sets how many trays are queued.
77
+ const queue = {
78
+ build(e, P, pal) {
79
+ const hx = (e.d ?? e.s) * W / 2, hy = (e.w ?? e.s) * W / 2, u = Math.min(hx, hy) / 40, z0 = 6 * u;
80
+ const L = Math.min(hx - 4 * u, 46 * u); // half belt length (uses the long side when the block is long)
81
+ const zb = z0 + 22 * u; // belt surface
82
+ const pl = (x, y, w, d, r = 1) => ({ x, y, w, d, r });
83
+ const at = (x, y, z) => [x, y, z];
84
+ const out = [plinth(P, hx, hy, z0, toneOf(pal))];
85
+ const leg = (x, y) => solid(slabOf(pl(x - 2 * u, y - 2 * u, 4 * u, 4 * u, 0.8 * u), z0, 16 * u, P, 3, 0.4), NEUTRAL);
86
+ const foot = (x, y) => solid(slabOf(pl(x - 2.6 * u, y - 2.6 * u, 5.2 * u, 5.2 * u, 1 * u), z0, 1.2 * u, P, 3), NEUTRAL, { line: 'mid' });
87
+ const ys = [-15 * u, 15 * u], xs = [-L + 5 * u, L - 5 * u];
88
+ // back legs, back rail
89
+ out.push(foot(xs[0], ys[0]) + foot(xs[1], ys[0]) + leg(xs[0], ys[0]) + leg(xs[1], ys[0]));
90
+ const rail = (y) => solid(slabOf(pl(-L, y - 2.6 * u, L * 2, 5.2 * u, 1.4 * u), zb - 8 * u, 11 * u, P, 4, 0.5), toneOf(pal), { crease: 'lo' })
91
+ + line(segment([-L + 4 * u, y + 2.6 * u, zb - 3 * u], [L - 4 * u, y + 2.6 * u, zb - 3 * u], P), 'mid');
92
+ out.push(rail(-15 * u));
93
+ // belt: dark rubber slab, then live cleats and trays
94
+ const belt = pl(-L + 1 * u, -12.8 * u, L * 2 - 2 * u, 25.6 * u, 3 * u);
95
+ out.push(solid(slabOf(belt, zb - 2.5 * u, 2.5 * u, P, 6), solidTone('#4A433C'), { line: 'hi', crease: 'mid' }));
96
+ // intake hopper over the back end
97
+ const hop = pl(-L - 2 * u, -12 * u, 14 * u, 24 * u, 2 * u);
98
+ const hopper = solid(slabOf(hop, zb + 1 * u, 11 * u, P, 4, 0.6), NEUTRAL, { inner: fillPath(planOutline(insetPlan(hop, 2.5 * u), zb + 12 * u, P), '#4A433C', 'mid') });
99
+ const items = Math.max(0, Math.min(6, e.items ?? 3));
100
+ const span = L * 2 - 12 * u, gap = span / Math.max(3, items + 1);
101
+ const cleats = (s) => {
102
+ const step = 7 * u, off = (s.t * 9 * u) % step; let d = '';
103
+ for (let x = -L + 3 * u + off; x < L - 2 * u; x += step) d += lineOnTop([x, -12 * u], [x, 12 * u], zb, P);
104
+ return line(d, 'lo', 0.7);
105
+ };
106
+ const trays = (s) => {
107
+ let out2 = '';
108
+ const list = [];
109
+ for (let i = 0; i < items; i++) list.push(-L + 12 * u + ((i * gap + s.t * 9 * u) % span));
110
+ list.sort((a, b) => a - b); // far (small x) first
111
+ for (const x of list) {
112
+ const edge = Math.min(x - (-L + 9 * u), L - 2 * u - x) / (6 * u);
113
+ const o = Math.max(0, Math.min(1, edge));
114
+ const t = pl(x - 6.5 * u, -8 * u, 13 * u, 16 * u, 1.2 * u);
115
+ const flap = onTop([[x - 6.5 * u, -8 * u], [x, 0], [x - 6.5 * u, 8 * u]], zb + 7 * u, P);
116
+ out2 += `<g opacity="${o.toFixed(2)}">${solid(slabOf(t, zb, 7 * u, P, 4, 0.4), { top: '#fbe5bd', shade: ['#e9b85f', '#efc477', '#f4d18f', '#f8dca6'] }, { inner: line(flap, 'mid') })}</g>`;
117
+ }
118
+ return out2;
119
+ };
120
+ // front legs, front rail with drum caps, end tray
121
+ const caps = [-L + 4 * u, L - 4 * u].map((x) => fillPath(sideRing(at(x, 17.7 * u, zb - 3 * u), 3 * u, 'y', P, 16), '#ebe3d7', 'hi') + dots(pointsAt([at(x, 17.7 * u, zb - 3 * u)], P), 1)).join('');
122
+ const front = foot(xs[0], ys[1]) + foot(xs[1], ys[1]) + leg(xs[0], ys[1]) + leg(xs[1], ys[1]) + rail(15 * u) + caps;
123
+ return {
124
+ env: env(hx, hy, zb + 12 * u),
125
+ layers: [...out, { live: 'cleats', draw: cleats }, { live: 'trays', draw: trays }, hopper, front],
126
+ };
127
+ },
128
+ state: () => ({ t: 0, speed: 0.35 }),
129
+ ping(s) { s.speed = 1; },
130
+ tick(s, dt) { s.speed += (0.35 - s.speed) * (1 - Math.exp(-0.8 * dt)); s.t += dt * s.speed; return { cleats: true, trays: true }; },
131
+ };
132
+
133
+
134
+ // SERVER (API, service): an open rack of blade servers between four posts. Drive-bay LEDs blink
135
+ // faster as `cpu` rises; heat glows through the engine's overlay.
136
+ const server = {
137
+ build(e, P, pal) {
138
+ const { u, z0, at, pl, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
139
+ const out = [base, solid(slabOf(pl(-24, -22, 48, 44, 2), z0, 3 * u, P, 4), solidTone('#5F574E'), { crease: 'mid' })];
140
+ const H = 50, zb = 3;
141
+ const post = (x, y) => solid(slabOf(pl(x, y, 4, 4, 0.8), Z(zb), H * u, P, 3, 0.4), toneOf(pal));
142
+ out.push(post(-22, -20));
143
+ const levels = [0, 1, 2, 3].map((i) => zb + 1.5 + i * 12);
144
+ for (const zl of levels) {
145
+ const bays = [-14, -8, -2, 4].map((y) => planeX(18 * u, [[y * u, Z(zl + 2)], [(y + 4.6) * u, Z(zl + 2)], [(y + 4.6) * u, Z(zl + 8)], [y * u, Z(zl + 8)]], P)).join('');
146
+ const vent = [-14, -9, -4, 1, 6, 11].map((x) => segment(at(x, 16, zl + 3), at(x + 3, 16, zl + 3), P) + segment(at(x, 16, zl + 6.5), at(x + 3, 16, zl + 6.5), P)).join('');
147
+ out.push(solid(slabOf(pl(-20, -16, 38, 32, 1), Z(zl), 10 * u, P, 3, 0.4), NEUTRAL, {
148
+ inner: line(bays, 'lo') + line(vent, 'lo') + line(segment(at(18, 9, zl + 5), at(18, 14, zl + 5), P), 'hi', 1.4),
149
+ }));
150
+ }
151
+ const front = post(-22, 16) + post(16, -20) + post(16, 16) +
152
+ solid(slabOf(pl(-24, -22, 44, 42, 2), Z(zb + H), 3 * u, P, 4, 0.6), toneOf(pal), { crease: 'lo' }) +
153
+ [[-20, -18], [-20, 14], [14, -18], [14, 14]].map(([x, y]) => screw(P, (x + 2) * u, (y + 2) * u, Z(zb + H + 3))).join('');
154
+ const leds = (s) => levels.map((zl, i) => {
155
+ const on = (k) => ((s.t * (0.9 + i * 0.23) + k * 0.37 + i * 0.61) % 1) < 0.55;
156
+ return [0, 1].map((k) => { const [[x, y]] = pointsAt([at(18, -14 + k * 6 + 2.3, zl + 5)], P); return `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${(1.25 * u + 0.4).toFixed(2)}" fill="${on(k) ? (s.hot ? '#efb041' : '#7fc278') : '#b8ad9f'}" stroke="#211e1b" stroke-width=".5"/>`; }).join('');
157
+ }).join('');
158
+ return { env: env(hx, hy, Z(zb + H + 3)), layers: [...out, front, { live: 'leds', draw: leds }] };
159
+ },
160
+ state: () => ({ t: 0, key: '', hot: false }),
161
+ ping(s) { s.t += 0.13; },
162
+ tick(s, dt, e) {
163
+ const cpu = e?.cpu >= 0 ? e.cpu : 0.3;
164
+ s.t += dt * (0.6 + cpu * 3.4); s.hot = cpu >= 0.85;
165
+ const key = `${Math.floor(s.t * 8)}|${s.hot}`;
166
+ if (key === s.key) return null;
167
+ s.key = key; return { leds: true };
168
+ },
169
+ };
170
+
171
+ // BALANCER: a turntable distributor. Requests come in at the back; a lit pointer turns to the
172
+ // outlet the next request will take (round robin by default).
173
+ const PORTS = [-55, 0, 55];
174
+ const balancer = {
175
+ build(e, P, pal) {
176
+ const { u, z0, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
177
+ const rad = (a) => (a * Math.PI) / 180, polar = (a, r, z) => [Math.cos(rad(a)) * r * u, Math.sin(rad(a)) * r * u, Z(z)];
178
+ const port = (a) => beam(polar(a, 22, 6), polar(a, 33, 6), [0, 0, 1], 9 * u, 10 * u, P, NEUTRAL) +
179
+ beam(polar(a, 33, 6), polar(a, 35, 6), [0, 0, 1], 11 * u, 12 * u, P, toneOf(pal));
180
+ const out = [base, solid(slabOf({ x: -38 * u, y: -5 * u, w: 16 * u, d: 10 * u, r: 2 * u }, Z(2), 9 * u, P, 4, 0.5), NEUTRAL), port(PORTS[0])];
181
+ const tk = radialTicks(0, 0, 22 * u, 24, 4, Z(10), [1.6 * u, 3.4 * u], P);
182
+ out.push(solid(cylinder(0, 0, 25 * u, z0, 10 * u, P, 40, 0.8), toneOf(pal), { crease: 'lo' }) + line(ring(0, 0, 17 * u, Z(10), P), 'lo') + line(tk.minor, 'lo') + line(tk.major, 'mid'));
183
+ const front = port(PORTS[1]) + port(PORTS[2]);
184
+ const arm = (s) => {
185
+ const a = rad(s.ang), tip = [Math.cos(a) * 21 * u, Math.sin(a) * 21 * u, Z(13)];
186
+ return beam([0, 0, Z(13)], tip, [0, 0, 1], 3 * u, 4.4 * u, P, solidTone('#e5534b')) +
187
+ solid(cylinder(0, 0, 7 * u, Z(10), 5 * u, P, 24, 0.5), NEUTRAL, { inner: line(knurl(0, 0, 7 * u, Z(10), Z(15), 28, P), 'lo') }) +
188
+ dots(pointsAt([[0, 0, Z(15)]], P), 1.3);
189
+ };
190
+ return { env: env(hx, hy, Z(17)), layers: [...out, front, { live: 'arm', draw: arm }] };
191
+ },
192
+ state: () => ({ ang: PORTS[0], idx: 0 }),
193
+ ping(s) { s.idx = (s.idx + 1) % PORTS.length; },
194
+ tick(s, dt) {
195
+ const target = PORTS[s.idx], prev = s.ang;
196
+ s.ang += (target - s.ang) * (1 - Math.exp(-7 * dt));
197
+ return Math.abs(s.ang - prev) > 0.05 ? { arm: true } : null;
198
+ },
199
+ };
200
+
201
+ // WORKER: a bench press. Each job that arrives brings the ram down on the workpiece; the drive
202
+ // gears on the head turn faster as `cpu` rises.
203
+ const worker = {
204
+ build(e, P, pal) {
205
+ const { u, z0, at, pl, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
206
+ const out = [base];
207
+ out.push(solid(slabOf(pl(-30, -24, 60, 48, 3), z0, 14 * u, P, 6, 0.8), toneOf(pal), {
208
+ crease: 'lo', inner: line(segment(at(30, -18, 4), at(30, 18, 4), P) + segment(at(-24, 24, 4), at(24, 24, 4), P), 'mid'),
209
+ }));
210
+ for (const [x, y] of [[-26, -20], [-26, 20], [26, -20], [26, 20]]) out.push(screw(P, x * u, y * u, Z(14)));
211
+ out.push(solid(slabOf(pl(-30, -12, 12, 24, 2), Z(14), 30 * u, P, 4, 0.6), NEUTRAL, { inner: line(segment(at(-18, 12, 20), at(-18, 12, 38), P), 'lo') }));
212
+ out.push(solid(slabOf(pl(-1, -9, 18, 18, 1), Z(14), 3 * u, P, 4, 0.4), solidTone('#8a8076'), { crease: 'mid' }));
213
+ out.push(solid(slabOf(pl(3, -5, 10, 10, 1), Z(17), 2.5 * u, P, 4), { top: '#fbe5bd', shade: ['#e9b85f', '#efc477', '#f4d18f', '#f8dca6'] }, { line: 'hi' }));
214
+ const ram = (s) => {
215
+ const bottom = 26 - s.press * 6.4;
216
+ return solid(slabOf(pl(2, -6, 12, 12, 1.5), Z(bottom), (44 - bottom) * u, P, 4, 0.4), solidTone('#5F574E'), { crease: 'mid', inner: line(segment(at(14, 0, bottom + 2), at(14, 0, 42), P), 'mid') });
217
+ };
218
+ const head = solid(slabOf(pl(-30, -10, 46, 20, 2), Z(44), 12 * u, P, 4, 0.6), toneOf(pal), { crease: 'lo' });
219
+ const gears = (s) => {
220
+ const big = planeY(10 * u, gear(-20 * u, Z(50), 5.2 * u, 10, s.rot), P), small = planeY(10 * u, gear(-10.6 * u, Z(50), 3.6 * u, 7, -s.rot * 1.44 + 0.2), P);
221
+ return fillPath(big, '#ebe3d7') + fillPath(small, '#d6cabb') + dots(pointsAt([at(-20, 10, 50), at(-10.6, 10, 50)], P), 1) +
222
+ fillPath(planeY(10 * u, circle2(-20 * u, Z(50), 1.6 * u, 12), P), '#e5534b');
223
+ };
224
+ const panel = solid(slabOf(pl(14, 16, 12, 8, 1), Z(14), 7 * u, P, 3, 0.4), NEUTRAL) +
225
+ dots(pointsAt([at(17, 24, 18)], P), 1.3, '#7fc278') + dots(pointsAt([at(22, 24, 18)], P), 1.3, '#e5534b');
226
+ return { env: env(hx, hy, Z(56)), layers: [...out, { live: 'ram', draw: ram }, head, { live: 'gears', draw: gears }, panel] };
227
+ },
228
+ state: () => ({ rot: 0, press: 0, hit: 0 }),
229
+ ping(s) { s.hit = 1; },
230
+ tick(s, dt, e) {
231
+ const cpu = e?.cpu >= 0 ? e.cpu : 0.35, prev = s.press;
232
+ s.rot += dt * (0.5 + cpu * 3.2);
233
+ s.hit = Math.max(0, s.hit - dt * 2.6);
234
+ const target = s.hit > 0.55 ? 1 : 0;
235
+ s.press += (target - s.press) * (1 - Math.exp(-(target ? 16 : 5) * dt));
236
+ return { gears: true, ram: Math.abs(s.press - prev) > 0.002 };
237
+ },
238
+ };
239
+
240
+ // DATABASE: a stack of platters on a spindle with a read/write arm; the top platter's index marks
241
+ // turn when writes land. A glass gauge beside it shows `cpu` as the fill level (if set).
242
+ const database = {
243
+ build(e, P, pal) {
244
+ const { u, z0, at, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
245
+ const out = [base, solid(cylinder(20 * u, -22 * u, 2.6 * u, z0, 44 * u, P, 16), NEUTRAL)];
246
+ out.push(solid(cylinder(0, 0, 25 * u, z0, 4 * u, P, 40, 0.6), solidTone('#5F574E'), { crease: 'mid' }));
247
+ const tone = toneOf(pal);
248
+ for (let i = 0; i < 4; i++) {
249
+ const z = 4 + i * 9.5;
250
+ out.push(solid(cylinder(0, 0, 3.4 * u, Z(z - 3.5), 3.5 * u, P, 16), NEUTRAL, { line: 'mid' }));
251
+ out.push(solid(cylinder(0, 0, 22 * u, Z(z), 6 * u, P, 48, 0.6), tone, { crease: 'lo', inner: line(ring(0, 0, 16 * u, Z(z + 6), P), 'faint') }));
252
+ }
253
+ const top = 4 + 3 * 9.5 + 6;
254
+ const marks = (s) => {
255
+ let d = '';
256
+ for (let i = 0; i < 8; i++) { const a = s.rot + (i / 8) * Math.PI * 2; d += lineOnTop([Math.cos(a) * 9 * u, Math.sin(a) * 9 * u], [Math.cos(a) * 14 * u, Math.sin(a) * 14 * u], Z(top), P); }
257
+ return line(d, 'mid') + solid(cylinder(0, 0, 5.5 * u, Z(top), 3 * u, P, 20, 0.4), NEUTRAL, { inner: line(knurl(0, 0, 5.5 * u, Z(top), Z(top + 3), 22, P), 'lo') });
258
+ };
259
+ const arm = (s) => {
260
+ const a = 1.95 + s.sweep * 0.45, piv = [20 * u, -22 * u, Z(top + 2)]; // points over the platters, sweeps toward the hub on a write
261
+ return beam(piv, [piv[0] + Math.cos(a) * 24 * u, piv[1] + Math.sin(a) * 24 * u, piv[2]], [0, 0, 1], 2 * u, 3 * u, P, solidTone('#e5534b')) +
262
+ solid(cylinder(20 * u, -22 * u, 3.4 * u, Z(top), 4 * u, P, 16), NEUTRAL);
263
+ };
264
+ const gauge = (s, cur) => {
265
+ const lv = cur?.cpu >= 0 ? Math.max(0, Math.min(1, cur.cpu)) : -1;
266
+ if (lv < 0) return '';
267
+ const fill = lv < 0.6 ? solidTone('#9fd08f') : lv < 0.85 ? solidTone('#f2c063') : solidTone('#ec7a6f');
268
+ return solid(cylinder(-22 * u, 24 * u, 4.6 * u, z0, 2 * u, P, 20), NEUTRAL) +
269
+ (lv > 0.01 ? solid(cylinder(-22 * u, 24 * u, 3.2 * u, Z(2), 38 * lv * u, P, 20), fill, { line: 'mid' }) : '') +
270
+ glass(cylinder(-22 * u, 24 * u, 3.6 * u, Z(2), 38 * u, P, 20)) +
271
+ solid(cylinder(-22 * u, 24 * u, 4.6 * u, Z(40), 2 * u, P, 20), NEUTRAL);
272
+ };
273
+ return { env: env(hx, hy, Z(top + 6)), layers: [...out, { live: 'marks', draw: marks }, { live: 'arm', draw: arm }, { live: 'gauge', draw: gauge }] };
274
+ },
275
+ state: () => ({ rot: 0, spin: 0.15, sweep: 0, w: 0, lv: null }),
276
+ ping(s) { s.spin = 2.4; s.w = 1; },
277
+ tick(s, dt, e) {
278
+ s.spin += (0.15 - s.spin) * (1 - Math.exp(-1.6 * dt)); s.rot += dt * s.spin;
279
+ s.w = Math.max(0, s.w - dt * 1.8); const prev = s.sweep; s.sweep += ((s.w > 0 ? 1 : 0) - s.sweep) * (1 - Math.exp(-6 * dt));
280
+ const lv = e?.cpu ?? null, lvDirty = lv !== s.lv; s.lv = lv;
281
+ return { marks: true, arm: Math.abs(s.sweep - prev) > 0.002, gauge: lvDirty };
282
+ },
283
+ };
284
+
285
+ // CACHE: a card-index cabinet. On a hit one drawer slides out with the card raised; the next hit
286
+ // opens the next drawer.
287
+ const cache = {
288
+ build(e, P, pal) {
289
+ const { u, z0, at, pl, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
290
+ const cols = [[-21, -2.5], [2.5, 21]], rows = [[4, 14], [17, 27], [30, 40]];
291
+ const front = (y0, y1, z0r, z1r) => planeX(12 * u, [[y0 * u, Z(z0r)], [y1 * u, Z(z0r)], [y1 * u, Z(z1r)], [y0 * u, Z(z1r)]], P);
292
+ let faces = '';
293
+ for (const [y0, y1] of cols) for (const [za, zb] of rows) {
294
+ const m = (y0 + y1) / 2;
295
+ faces += line(front(y0, y1, za, zb), 'mid') + line(planeX(12 * u, [[(m - 3) * u, Z(zb - 3)], [(m + 3) * u, Z(zb - 3)], [(m + 3) * u, Z(zb - 1.5)], [(m - 3) * u, Z(zb - 1.5)]], P), 'lo') +
296
+ line(segment(at(12, m - 3.5, za + 3.5), at(12, m + 3.5, za + 3.5), P), 'hi', 1.6);
297
+ }
298
+ const out = [base, solid(slabOf(pl(-22, -24, 34, 48, 2), z0, 43 * u, P, 6, 0.8), toneOf(pal), { crease: 'lo', inner: faces })];
299
+ out.push(solid(slabOf(pl(-18, -14, 18, 20, 1.5), Z(43), 4 * u, P, 4, 0.4), NEUTRAL));
300
+ for (let i = 0; i < 4; i++) out.push(solid(slabOf(pl(-15 + i * 3.6, -12, 0.9, 16, 0.2), Z(45), 6 * u, P, 2), i === 2 ? solidTone('#fbe5bd') : solidTone('#fbf7f0'), { line: 'mid', crease: 'faint' }));
301
+ const drawer = (s) => {
302
+ if (s.out < 0.02) return '';
303
+ const [y0, y1] = cols[s.idx % 2], [za, zb] = rows[Math.floor(s.idx / 2) % 3], dx = s.out * 12;
304
+ const hole = fillPath(front(y0, y1, za, zb), '#4A433C', 'mid');
305
+ const box = solid(slabOf(pl(12 - 1, y0 + 0.4, dx + 1, y1 - y0 - 0.8, 0.6), Z(za + 0.4), (zb - za - 0.8) * u, P, 3), toneOf(pal), { crease: 'lo' });
306
+ const card = solid(slabOf(pl(12 + dx * 0.45, (y0 + y1) / 2 - 5, 0.9, 10, 0.2), Z(zb - 2), 6 * s.out * u, P, 2), solidTone('#fbe5bd'), { line: 'hi' });
307
+ return hole + box + card;
308
+ };
309
+ return { env: env(hx, hy, Z(51)), layers: [...out, { live: 'drawer', draw: drawer }] };
310
+ },
311
+ state: () => ({ out: 0, open: 0, idx: 0 }),
312
+ ping(s, kind, failed) { if (failed) return; if (s.open <= 0) s.idx = (s.idx + 1) % 6; s.open = 0.7; },
313
+ tick(s, dt) {
314
+ s.open = Math.max(0, s.open - dt); const prev = s.out;
315
+ s.out += ((s.open > 0 ? 1 : 0) - s.out) * (1 - Math.exp(-(s.open > 0 ? 10 : 6) * dt));
316
+ return Math.abs(s.out - prev) > 0.002 ? { drawer: true } : null;
317
+ },
318
+ };
319
+
320
+ // EXTERNAL (PSP, bank, third-party API): a payment terminal on a counter. Each call pushes the
321
+ // card into the slot; the status lamp answers green (ok) or red (failed).
322
+ const external = {
323
+ build(e, P, pal) {
324
+ const { u, z0, at, pl, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
325
+ const out = [base, solid(slabOf(pl(-30, -28, 56, 52, 3), z0, 14 * u, P, 6, 0.8), NEUTRAL, {
326
+ crease: 'lo', inner: line(segment(at(26, -22, 7), at(26, 20, 7), P), 'lo'),
327
+ })];
328
+ out.push(solid(slabOf(pl(-12, -14, 28, 28, 3), Z(14), 6 * u, P, 6, 0.6), toneOf(pal), { crease: 'lo' }));
329
+ const screen = fillPath(onTop([[-9 * u, -10 * u], [1 * u, -10 * u], [1 * u, 10 * u], [-9 * u, 10 * u]], Z(26), P, true), '#2F2B27', 'hi') +
330
+ stroke(lineOnTop([-6.5 * u, -7 * u], [-6.5 * u, 4 * u], Z(26), P) + lineOnTop([-3.5 * u, -7 * u], [-3.5 * u, 1 * u], Z(26), P) + lineOnTop([-0.5 * u, -7 * u], [-0.5 * u, 6 * u], Z(26), P), '#9fd08f', 1.3);
331
+ const keys = dots(dotGrid(5 * u, -7 * u, 3, 4, 4.4 * u, Z(26), P).filter((_, i) => i < 12), 1.25 * u + 0.25, '#6f6559');
332
+ out.push(solid(slabOf(pl(-10, -12, 24, 24, 3), Z(20), 6 * u, P, 6, 0.6), NEUTRAL, { crease: 'faint', inner: screen + keys }));
333
+ const card = (s) => {
334
+ const z = 26 + 1 + (1 - s.ins) * 12;
335
+ return solid(slabOf(pl(-11.4, -7, 1.2, 14, 0.3), Z(z - 10), 10 * u, P, 2), solidTone('#a9c5e8'), { line: 'hi' }) +
336
+ line(segment(at(-10.2, -7, z - 2.5), at(-10.2, 7, z - 2.5), P), 'hi', 1.6);
337
+ };
338
+ const slot = line(lineOnTop([-11 * u, -8 * u], [-11 * u, 8 * u], Z(26), P), 'hi', 1.8);
339
+ const lamp = (s) => { const [[x, y]] = pointsAt([at(12, 10, 26)], P); const c = s.red > 0 ? '#e5534b' : s.ok > 0 ? '#7fc278' : '#b8ad9f'; return `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="${(2 * u + 0.5).toFixed(2)}" fill="${c}" stroke="#211e1b" stroke-width=".7"/>`; };
340
+ return { env: env(hx, hy, Z(40)), layers: [...out, slot, { live: 'card', draw: card }, { live: 'lamp', draw: lamp }] };
341
+ },
342
+ state: () => ({ ins: 0, push: 0, ok: 0, red: 0 }),
343
+ ping(s, kind, failed) { s.push = 0.45; if (failed) s.red = 1; else s.ok = 1; },
344
+ tick(s, dt) {
345
+ s.push = Math.max(0, s.push - dt); const prev = s.ins, pr = [s.ok > 0, s.red > 0];
346
+ s.ins += ((s.push > 0 ? 1 : 0) - s.ins) * (1 - Math.exp(-9 * dt));
347
+ s.ok = Math.max(0, s.ok - dt * 1.2); s.red = Math.max(0, s.red - dt * 0.9);
348
+ const lamp = pr[0] !== (s.ok > 0) || pr[1] !== (s.red > 0);
349
+ return Math.abs(s.ins - prev) > 0.002 || lamp ? { card: true, lamp } : null;
350
+ },
351
+ };
352
+
353
+ // DLQ: a wheeled bin with its lid thrown back; dead letters drop in from above and stay there.
354
+ const dlq = {
355
+ build(e, P, pal) {
356
+ const { u, z0, at, pl, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
357
+ const wheel = (x, y) => solid(cylinder(x * u, y * u, 3.4 * u, z0, 4 * u, P, 16), solidTone('#4A433C'), { crease: 'mid' });
358
+ const ribs = [-14, -4, 6].map((x) => segment(at(x, 22, 8), at(x, 22, 28), P)).join('') + [-12, 0, 12].map((y) => segment(at(22, y, 8), at(22, y, 28), P)).join('');
359
+ const out = [base, wheel(-20, -16), wheel(-20, 16), wheel(18, -16)];
360
+ out.push(beam([-28 * u, -22 * u, Z(34)], [(-28 - 14) * u, -22 * u, Z(34 + 24)], [0, 1, 0], 44 * u, 2.2 * u, P, solidTone('#5F574E')));
361
+ out.push(solid(slabOf(pl(-26, -22, 48, 44, 3), Z(4), 27 * u, P, 6, 0.8), toneOf(pal), { crease: 'lo', inner: line(ribs, 'mid') }));
362
+ const inside = insetPlan(pl(-28, -24, 52, 48, 3), 3 * u);
363
+ out.push(solid(slabOf(pl(-28, -24, 52, 48, 3), Z(31), 3 * u, P, 6, 0.5), solidTone('#5F574E'), { crease: 'mid', inner: fillPath(planOutline(inside, Z(34), P), '#2F2B27', 'mid') }));
364
+ const n = Math.max(1, Math.min(5, e.items ?? 3));
365
+ for (let i = 0; i < n; i++) {
366
+ const x = -14 + (i * 13) % 30, y = -10 + ((i * 17) % 22);
367
+ out.push(beam([x * u, y * u, Z(33.5)], [(x + 10) * u, (y + 2) * u, Z(35 + (i % 2) * 2)], [-0.2, 1, 0], 12 * u, 1.2 * u, P, solidTone('#f6cd82')));
368
+ }
369
+ const drop = (s) => {
370
+ if (s.fall < 0) return '';
371
+ const z = 70 - s.fall * 36, o = Math.min(1, (z - 34) / 6);
372
+ return o <= 0 ? '' : `<g opacity="${o.toFixed(2)}">${beam([-4 * u, -4 * u, Z(z)], [6 * u, 0, Z(z + 2)], [-0.3, 1, 0.2], 12 * u, 1.2 * u, P, solidTone('#ec7a6f'))}</g>`;
373
+ };
374
+ const front = wheel(18, 16);
375
+ return { env: env(hx, hy, Z(58)), layers: [...out, { live: 'drop', draw: drop }, front] };
376
+ },
377
+ state: () => ({ fall: -1 }),
378
+ ping(s) { if (s.fall < 0 || s.fall > 0.9) s.fall = 0; },
379
+ tick(s, dt) {
380
+ if (s.fall < 0) return null;
381
+ s.fall += dt * 1.6; if (s.fall > 1.05) s.fall = -1;
382
+ return { drop: true };
383
+ },
384
+ };
385
+
386
+ // SCHEDULER (cron, timers, delayed jobs): a twin-bell alarm clock. The hands sweep; when a job
387
+ // fires, the hammer rings the bells.
388
+ const scheduler = {
389
+ build(e, P, pal) {
390
+ const { u, z0, at, pl, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
391
+ const cz = 27, R = 15;
392
+ const out = [base];
393
+ for (const y of [-14, 14]) out.push(solid(slabOf(pl(-7, y - 3, 8, 6, 1.5), z0, 5 * u, P, 3), solidTone('#5F574E'), { crease: 'mid' }));
394
+ const ticks = Array.from({ length: 12 }, (_, i) => { const a = (i / 12) * Math.PI * 2, r0 = i % 3 ? R - 2.2 : R - 4; return segment([5.2 * u, -Math.sin(a) * r0 * u, Z(cz + Math.cos(a) * r0)], [5.2 * u, -Math.sin(a) * (R - 0.6) * u, Z(cz + Math.cos(a) * (R - 0.6))], P); }).join('');
395
+ const face = fillPath(planeX(5.2 * u, circle2(0, Z(cz), R * u, 36), P), '#fbf7f0', 'mid') + line(ticks, 'hi', 1.1);
396
+ out.push(solid(slabOf(pl(-8, -21, 13, 42, 6), Z(5), 42 * u, P, 6, 0.8), toneOf(pal), { crease: 'lo', inner: fillPath(planeX(5 * u, circle2(0, Z(cz), (R + 2.2) * u, 36), P), '#ebe3d7', 'hi') + face }));
397
+ const bell = (y) => solid(cylinder(-1.5 * u, y * u, 6 * u, Z(47), 3 * u, P, 24, 0.6), solidTone('#d6cabb'), { crease: 'mid' }) + solid(cylinder(-1.5 * u, y * u, 4 * u, Z(50), 2.2 * u, P, 20), solidTone('#ebe3d7'));
398
+ out.push(solid(cylinder(-1.5 * u, 0, 1.4 * u, Z(47), 4 * u, P, 12), NEUTRAL, { line: 'mid' }));
399
+ const hands = (s) => {
400
+ const hand = (a, L, w) => line(segment([5.4 * u, 0, Z(cz)], [5.4 * u, -Math.sin(a) * L * u, Z(cz + Math.cos(a) * L)], P), 'hi', w);
401
+ return hand(s.t * 0.07, 8, 2.2) + hand(s.t * 0.8, 12, 1.5) + stroke(segment([5.5 * u, 0, Z(cz)], [5.5 * u, Math.sin(s.t * 6) * -3 * u, Z(cz + Math.cos(s.t * 6) * -3)], P), '#e5534b', 0.8) + dots(pointsAt([[5.5 * u, 0, Z(cz)]], P), 1.5);
402
+ };
403
+ const bells = (s) => {
404
+ const k = Math.sin(s.t * 40) * s.ring * 1.6;
405
+ return `<g transform="translate(${k.toFixed(2)} 0)">${bell(-12) + bell(12)}</g>` + solid(slabOf(pl(-3.5 + k * 0.2, -1.5 + k, 4, 3, 0.6), Z(49), 6 * u, P, 3), solidTone('#5F574E'));
406
+ };
407
+ return { env: env(hx, hy, Z(56)), layers: [...out, { live: 'bells', draw: bells }, { live: 'hands', draw: hands }] };
408
+ },
409
+ state: () => ({ t: 0, ring: 0 }),
410
+ ping(s) { s.ring = 1; },
411
+ tick(s, dt) { s.t += dt; s.ring = Math.max(0, s.ring - dt * 1.5); return { hands: true, bells: s.ring > 0 }; },
412
+ };
413
+
414
+ // LLM / AI model: a processor on its board. The die's cells light up while it is thinking; every
415
+ // request sends a wave across them.
416
+ const llm = {
417
+ build(e, P, pal) {
418
+ const { u, z0, at, pl, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
419
+ const out = [base];
420
+ let traces = '';
421
+ const vias = [];
422
+ for (let i = -3; i <= 3; i++) {
423
+ const y = i * 5; traces += lineOnTop([26 * u, y * u], [33 * u, (y + Math.sign(i) * 2) * u], z0, P); vias.push(at(33, y + Math.sign(i) * 2, 0));
424
+ const x = i * 5; traces += lineOnTop([x * u, 26 * u], [(x + Math.sign(i) * 2) * u, 33 * u], z0, P); vias.push(at(x + Math.sign(i) * 2, 33, 0));
425
+ }
426
+ out.push(line(traces, 'mid') + pointsAt(vias, P).map(([x, y]) => `<circle cx="${x.toFixed(1)}" cy="${y.toFixed(1)}" r="1.2" fill="#ebe3d7" stroke="#6f6559" stroke-width=".6"/>`).join(''));
427
+ const pin = (x, y, w, d) => solid(slabOf(pl(x, y, w, d, 0.3), z0, 2.4 * u, P, 2), solidTone('#d6cabb'), { line: 'mid', crease: 'none' });
428
+ for (let i = -3; i <= 3; i++) { out.push(pin(-26, i * 5 - 1, 4, 2) + pin(i * 5 - 1, -26, 2, 4)); }
429
+ out.push(solid(slabOf(pl(-23, -23, 46, 46, 2.5), z0, 7 * u, P, 6, 0.8), solidTone('#3B3530'), { crease: 'mid', inner: dots(pointsAt([at(-19, 19, 7)], P), 1.4, '#9a8f81') }));
430
+ for (let i = -3; i <= 3; i++) { out.push(pin(22, i * 5 - 1, 4, 2) + pin(i * 5 - 1, 22, 2, 4)); }
431
+ out.push(solid(slabOf(pl(-15, -15, 30, 30, 2), Z(7), 3 * u, P, 6, 0.6), solidTone('#d6cabb'), { crease: 'mid', inner: line(planOutline(pl(-12.5, -12.5, 25, 25, 1), Z(10), P), 'lo') }));
432
+ const cells = (s) => {
433
+ let svg = '';
434
+ for (let i = 0; i < 4; i++) for (let j = 0; j < 4; j++) {
435
+ const x = -10 + i * 5.2, y = -10 + j * 5.2, k = i * 4 + j;
436
+ const v = 0.5 + 0.5 * Math.sin(s.t * (2 + (k % 5) * 0.7) + k * 1.9) + s.wave * Math.max(0, 1 - Math.abs((i + j) / 6 - s.front) * 3);
437
+ svg += `<path d="${onTop([[x * u, y * u], [(x + 4.2) * u, y * u], [(x + 4.2) * u, (y + 4.2) * u], [x * u, (y + 4.2) * u]], Z(10), P, true)}" fill="${v > 0.75 ? '#f6cd82' : v > 0.45 ? '#e3c590' : '#bfb3a3'}" stroke="#6f6559" stroke-width=".45"/>`;
438
+ }
439
+ return svg;
440
+ };
441
+ return { env: env(hx, hy, Z(11)), layers: [...out, { live: 'cells', draw: cells }] };
442
+ },
443
+ state: () => ({ t: 0, wave: 0, front: 0, key: '' }),
444
+ ping(s) { s.wave = 1; s.front = 0; },
445
+ tick(s, dt) {
446
+ s.t += dt; s.front += dt * 1.4; s.wave = Math.max(0, s.wave - dt * 0.8);
447
+ const key = Math.floor(s.t * 10);
448
+ if (key === s.key) return null;
449
+ s.key = key; return { cells: true };
450
+ },
451
+ };
452
+
453
+ // WEBHOOK (endpoint, notifier, outbox): a mailbox on a post. A delivery drops a letter through the
454
+ // slot and raises the red flag.
455
+ const webhook = {
456
+ build(e, P, pal) {
457
+ const { u, z0, at, pl, base, hx, hy } = rig(e, P, pal), Z = (z) => z0 + z * u;
458
+ const out = [base, solid(cylinder(0, 0, 8 * u, z0, 2 * u, P, 24, 0.4), solidTone('#5F574E'), { crease: 'mid' })];
459
+ out.push(solid(slabOf(pl(-3, -3, 6, 6, 1), Z(2), 26 * u, P, 3, 0.4), NEUTRAL));
460
+ const door = planeX(16 * u, [[-8 * u, Z(30)], [8 * u, Z(30)], [8 * u, Z(41)], [6 * u, Z(44)], [0, Z(45.5)], [-6 * u, Z(44)], [-8 * u, Z(41)]], P);
461
+ out.push(solid(slabOf(pl(-16, -10, 32, 20, 3), Z(28), 14 * u, P, 6, 0.8), toneOf(pal), { crease: 'lo' }));
462
+ out.push(solid(slabOf(pl(-16, -8, 32, 16, 4), Z(42), 3 * u, P, 6, 0.6), toneOf(pal), { crease: 'lo' }));
463
+ out.push(solid(slabOf(pl(-16, -5, 32, 10, 3.5), Z(45), 2 * u, P, 6, 0.6), toneOf(pal), { crease: 'lo', inner: line(lineOnTop([-6 * u, -2.5 * u], [6 * u, -2.5 * u], Z(47), P), 'hi', 1.8) }));
464
+ out.push(line(door, 'hi', 1.1) + dots(pointsAt([at(16, 5.5, 36)], P), 1.3));
465
+ const letter = (s) => {
466
+ if (s.drop < 0) return '';
467
+ const z = 62 - s.drop * 16;
468
+ return z < 47 ? '' : solid(slabOf(pl(-6, -3.1, 12, 1.2, 0.3), Z(z - 9), 9 * u, P, 2), solidTone('#fbe5bd'), { line: 'hi' });
469
+ };
470
+ const flag = (s) => {
471
+ const a = (s.up * Math.PI) / 2, piv = at(6, 10.6, 34), dir = [-Math.cos(a), 0, Math.sin(a)];
472
+ const p = (t) => add(piv, mul(dir, t * u));
473
+ return beam(p(0), p(13), [0, 1, 0], 1.4 * u, 1.8 * u, P, solidTone('#e5534b')) + beam(p(8), p(13), [0, 1, 0], 1.4 * u, 6 * u, P, solidTone('#e5534b')) + dots(pointsAt([piv], P), 1.2);
474
+ };
475
+ return { env: env(hx, hy, Z(50)), layers: [...out, { live: 'letter', draw: letter }, { live: 'flag', draw: flag }] };
476
+ },
477
+ state: () => ({ up: 0, hold: 0, drop: -1 }),
478
+ ping(s) { s.hold = 2.5; if (s.drop < 0) s.drop = 0; },
479
+ tick(s, dt) {
480
+ s.hold = Math.max(0, s.hold - dt); const prev = s.up;
481
+ s.up += ((s.hold > 0 ? 1 : 0) - s.up) * (1 - Math.exp(-(s.hold > 0 ? 7 : 2) * dt));
482
+ if (s.drop >= 0) { s.drop += dt * 1.8; if (s.drop > 1) s.drop = -1; }
483
+ return { flag: Math.abs(s.up - prev) > 0.002, letter: s.drop >= 0 || prev !== s.up };
484
+ },
485
+ };
486
+
487
+ export const LOOKS = { gateway, queue, server, balancer, worker, database, cache, external, dlq, scheduler, llm, webhook };
488
+
489
+ // The look a block gets when it doesn't name one, inferred from its glyph. Only glyphs that clearly
490
+ // name a component are here (zap/check/clock-as-state stay plain boxes); `look: "box"` opts out.
491
+ export const GLYPH_LOOK = {
492
+ shield: 'gateway', 'shield-check': 'gateway', 'key-round': 'gateway', lock: 'gateway',
493
+ inbox: 'queue', mail: 'queue', 'list-ordered': 'queue',
494
+ server: 'server', container: 'server',
495
+ balancer: 'balancer', split: 'balancer', network: 'balancer',
496
+ bot: 'worker', cpu: 'worker', cog: 'worker',
497
+ 'credit-card': 'external', landmark: 'external', 'message-circle': 'external', globe: 'external',
498
+ archive: 'dlq', trash: 'dlq', 'trash-2': 'dlq',
499
+ 'alarm-clock': 'scheduler', timer: 'scheduler', 'calendar-clock': 'scheduler',
500
+ brain: 'llm', sparkles: 'llm',
501
+ webhook: 'webhook', bell: 'webhook', send: 'webhook',
502
+ 'hard-drive': 'cache',
503
+ };
504
+ export const lookOf = (e) => {
505
+ if (e.type !== 'block' && e.type !== 'db') return null;
506
+ const name = e.look ?? (e.type === 'db' ? 'database' : GLYPH_LOOK[e.glyph]);
507
+ return name && name !== 'box' && LOOKS[name] ? name : null;
508
+ };