@jossuealcala/madre 1.1.2 → 1.1.3

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 (101) hide show
  1. package/CHANGELOG.en.md +21 -1
  2. package/CHANGELOG.md +21 -1
  3. package/README.en.md +3 -3
  4. package/README.md +3 -3
  5. package/SECURITY.md +11 -6
  6. package/bin/madre.mjs +74 -11
  7. package/docs/REFERENCE.md +13 -7
  8. package/docs/SDK.md +8 -8
  9. package/docs/en/REFERENCE.md +10 -6
  10. package/docs/en/SDK.md +8 -8
  11. package/docs/en/training/README.md +1 -1
  12. package/docs/sdk/connector-module.mjs +1 -1
  13. package/docs/sdk/hello-module.mjs +1 -1
  14. package/docs/training/README.md +1 -1
  15. package/docs/training/train.sh +3 -0
  16. package/package.json +4 -2
  17. package/public/activity.js +9 -0
  18. package/public/app.js +988 -171
  19. package/public/attribution.js +9 -0
  20. package/public/brands.js +27 -13
  21. package/public/en.js +1 -2
  22. package/public/es.js +834 -257
  23. package/public/index.html +3 -0
  24. package/public/macroverso.js +24 -5
  25. package/public/manual-content.js +32 -2
  26. package/public/market-view.js +116 -9
  27. package/public/market.js +15 -0
  28. package/public/news-scenes.js +185 -0
  29. package/public/notices.js +66 -0
  30. package/public/power.js +1 -1
  31. package/public/resay.js +3 -0
  32. package/public/salas-mac.css +229 -26
  33. package/public/salas-mac.html +3 -0
  34. package/public/salas-mac.js +454 -37
  35. package/public/styles.css +393 -17
  36. package/public/tips.js +124 -0
  37. package/public/tour-chapters.js +75 -75
  38. package/public/tour.js +36 -8
  39. package/public/troubleshooting.js +215 -22
  40. package/public/welcome-scene.js +358 -0
  41. package/public/welcome.js +514 -273
  42. package/src/adapters/gemini-rest.mjs +236 -0
  43. package/src/adapters/gemini.mjs +9 -7
  44. package/src/adapters/grok.mjs +288 -0
  45. package/src/adapters/process.mjs +14 -3
  46. package/src/auth-probe.mjs +32 -0
  47. package/src/bridge/policy.mjs +1 -1
  48. package/src/capabilities.mjs +30 -0
  49. package/src/checkpoint.mjs +115 -1
  50. package/src/codex-route.mjs +113 -0
  51. package/src/credentials.mjs +46 -8
  52. package/src/dataset.mjs +18 -7
  53. package/src/event-store.mjs +10 -2
  54. package/src/ficha.mjs +142 -0
  55. package/src/files.mjs +36 -2
  56. package/src/lease.mjs +5 -0
  57. package/src/market-check.mjs +1 -1
  58. package/src/market-remote.mjs +135 -1
  59. package/src/mcp/image-server.mjs +1 -1
  60. package/src/mcp/memory-server.mjs +10 -0
  61. package/src/memory-tools.mjs +3 -0
  62. package/src/memory.mjs +29 -4
  63. package/src/models.mjs +21 -3
  64. package/src/modules/ahp.mjs +8 -3
  65. package/src/modules/bishop-exam.mjs +41 -12
  66. package/src/modules/bishop.mjs +2 -2
  67. package/src/modules/choices.mjs +12 -10
  68. package/src/modules/fetch-alone.mjs +7 -0
  69. package/src/modules/helpers.mjs +23 -5
  70. package/src/modules/image-studio.mjs +13 -27
  71. package/src/modules/index.mjs +54 -11
  72. package/src/modules/isolated.mjs +160 -0
  73. package/src/modules/ollama.mjs +35 -6
  74. package/src/modules/playwright.mjs +46 -17
  75. package/src/modules/run-alone.mjs +122 -0
  76. package/src/modules/runs.mjs +11 -8
  77. package/src/modules/sdk.mjs +4 -2
  78. package/src/notices-key.mjs +8 -0
  79. package/src/notices.mjs +185 -0
  80. package/src/ollama.mjs +57 -15
  81. package/src/outbound.mjs +45 -8
  82. package/src/room/archivist.mjs +30 -5
  83. package/src/room/busy.mjs +16 -0
  84. package/src/room/control.mjs +36 -6
  85. package/src/room/guard.mjs +32 -2
  86. package/src/room/prompt.mjs +32 -5
  87. package/src/room/vectors.mjs +7 -1
  88. package/src/room.mjs +94 -28
  89. package/src/router.mjs +1 -1
  90. package/src/runs.mjs +39 -0
  91. package/src/runtime-detection.mjs +46 -6
  92. package/src/salas.mjs +151 -15
  93. package/src/server.mjs +577 -80
  94. package/src/service.mjs +116 -0
  95. package/src/setup-trouble.mjs +20 -1
  96. package/src/skill-check.mjs +269 -0
  97. package/src/skills-import.mjs +128 -0
  98. package/src/skills.mjs +492 -0
  99. package/src/tour.mjs +14 -3
  100. package/src/whats-new.mjs +48 -0
  101. package/src/rumbo.mjs +0 -337
@@ -0,0 +1,358 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
+ // THE WELCOME'S STAGE (1.1, 2026-11-08, docs/private/BIENVENIDA-1.1.md): one abstract picture above
4
+ // every step, so the welcome reads as one story and not as six forms. No words, no logos, no
5
+ // drawings of things: a field of points of light that takes a new shape at each step, and MADRE's
6
+ // DOT (the logo's, «MADRE is ready») at the centre of it all.
7
+ //
8
+ // The same points travel from one step to the next — they are never thrown away and made again —
9
+ // so every change of step is the field rearranging itself, not a cut:
10
+ //
11
+ // hello a cloud the computer is read through: a soft wave crosses it; once read, it settles
12
+ // into a calm halo round the dot
13
+ // use five nebulae round the dot; the ones the person marks grow, brighten and come closer
14
+ // agents one small constellation per AI, round the dot; a connected one sends light to it
15
+ // project threads from the edge, one per folder chosen, gathering into a ring round the dot
16
+ // ai the points fall in a slow spiral into a core while it downloads, a fine arc saying how
17
+ // much; once there, they settle in three quiet orbits
18
+ // ready the points draw the logo's pulse, flat, one beat, flat, and end in the dot
19
+ //
20
+ // MADRE's own style, from its brand book (madre-landing/brand-kit): the phosphor is the only colour
21
+ // and means something; nothing spins fast, bounces or glows like neon; changes take about 0.4 s and
22
+ // settle softly. It follows the look the person has on — light or dark, as their system or their
23
+ // Settings say (`data-scheme` on the page) — and changes with it. A person who asked for less
24
+ // motion gets each picture still, in its final shape.
25
+
26
+ const N = 220;
27
+ const RIPPLE = 2.6; // s between two heartbeats of the dot
28
+
29
+ const clamp01 = (x) => Math.max(0, Math.min(1, x));
30
+ const frac = (x) => x - Math.floor(x);
31
+ const easeInOut = (x) => { const v = clamp01(x); return v < 0.5 ? 4 * v * v * v : 1 - Math.pow(-2 * v + 2, 3) / 2; };
32
+ const hash = (n) => frac(Math.sin(n * 127.1 + 311.7) * 43758.5453);
33
+
34
+ // The logo's beat (madre-mark: …H20 L23.5 2 L28 18 L32 10 L35 10 L37 6 L39 10…): along 0…1, the height
35
+ // in units of the beat (negative is up). The `ready` picture draws it with points.
36
+ const BEAT = [[0, 0], [3.5, -1], [8, 1], [12, 0], [15, 0], [17, -0.5], [19, 0]];
37
+ function beatAt(u) {
38
+ if (u <= 0 || u >= 1) return 0;
39
+ const x = u * 19;
40
+ for (let i = 1; i < BEAT.length; i += 1) {
41
+ const [x0, y0] = BEAT[i - 1];
42
+ const [x1, y1] = BEAT[i];
43
+ if (x <= x1) return y0 + ((y1 - y0) * (x - x0)) / (x1 - x0);
44
+ }
45
+ return 0;
46
+ }
47
+ const bezier = (a, c, b, q) => (1 - q) * (1 - q) * a + 2 * (1 - q) * q * c + q * q * b;
48
+
49
+ // The two looks. In the dark the light adds up, as light does; in the light the points are ink.
50
+ const LOOKS = {
51
+ dark: { ground: [5, 6, 5], ink: [155, 255, 102], soft: [238, 241, 234], glow: 0.075, scan: 0.03, blend: 'lighter', halo: 0.34 },
52
+ light: { ground: [238, 240, 234], ink: [47, 138, 28], soft: [18, 21, 18], glow: 0.06, scan: 0, blend: 'source-over', halo: 0.18 },
53
+ };
54
+ const rgba = ([r, g, b], a) => `rgba(${r},${g},${b},${clamp01(a)})`;
55
+
56
+ // One point of light, drawn once and stamped: a solid core and a short soft halo, never a blur.
57
+ function spriteOf(ink, halo) {
58
+ const size = 64;
59
+ const canvas = document.createElement('canvas');
60
+ canvas.width = size;
61
+ canvas.height = size;
62
+ const ctx = canvas.getContext('2d');
63
+ if (!ctx) return canvas;
64
+ const g = ctx.createRadialGradient(size / 2, size / 2, 0, size / 2, size / 2, size / 2);
65
+ g.addColorStop(0, rgba(ink, 1));
66
+ g.addColorStop(0.18, rgba(ink, 1));
67
+ g.addColorStop(0.3, rgba(ink, halo));
68
+ g.addColorStop(1, rgba(ink, 0));
69
+ ctx.fillStyle = g;
70
+ ctx.fillRect(0, 0, size, size);
71
+ return canvas;
72
+ }
73
+
74
+ export function createScene({ still = globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false } = {}) {
75
+ const node = document.createElement('figure');
76
+ node.className = 'wl-scene';
77
+ node.setAttribute('aria-hidden', 'true');
78
+ const canvas = document.createElement('canvas');
79
+ const caption = document.createElement('figcaption');
80
+ caption.className = 'wl-scene-cap';
81
+ const words = document.createElement('span');
82
+ caption.append(words);
83
+ node.append(canvas, caption);
84
+ const ctx = canvas.getContext?.('2d') ?? null;
85
+
86
+ let w = 0;
87
+ let h = 0;
88
+ let dpr = 1;
89
+ let frame = 0;
90
+ let scene = { id: 'hello', data: () => ({}), since: 0 };
91
+ const dot = { a: 0, r: 4.5 }; // the dot, eased like the points
92
+ let look = null;
93
+ let ground = null; // the ground's colour now, eased between looks
94
+ let sprite = null;
95
+ const parts = Array.from({ length: N }, (_, i) => ({
96
+ i, seed: hash(i + 1), seed2: hash(i + 1000), z: 0.35 + 0.65 * hash(i + 2000),
97
+ x: 0, y: 0, vx: 0, vy: 0, a: 0, s: 1,
98
+ }));
99
+ let placed = false;
100
+
101
+ const readLook = () => {
102
+ const next = LOOKS[document.documentElement.dataset.scheme === 'light' ? 'light' : 'dark'];
103
+ if (next === look) return;
104
+ look = next;
105
+ ground ??= [...look.ground];
106
+ sprite = spriteOf(look.ink, look.halo);
107
+ };
108
+ readLook();
109
+ // The look changes when the person or their system changes it: the picture goes with it.
110
+ const watcher = typeof MutationObserver === 'function' ? new MutationObserver(() => { readLook(); redraw(); }) : null;
111
+ watcher?.observe(document.documentElement, { attributes: true, attributeFilter: ['data-scheme'] });
112
+
113
+ function fit() {
114
+ const box = node.getBoundingClientRect();
115
+ if (!box.width) return;
116
+ dpr = Math.min(2, globalThis.devicePixelRatio || 1);
117
+ w = box.width;
118
+ h = box.height;
119
+ canvas.width = Math.round(w * dpr);
120
+ canvas.height = Math.round(h * dpr);
121
+ if (!placed) {
122
+ for (const p of parts) { p.x = w / 2 + (p.seed - 0.5) * w * 0.9; p.y = h / 2 + (p.seed2 - 0.5) * h * 0.8; }
123
+ placed = true;
124
+ }
125
+ redraw();
126
+ }
127
+ const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(fit) : null;
128
+ observer?.observe(node);
129
+
130
+ // ---- Where each point wants to be in each picture: [x, y, brightness, size]. Every picture keeps
131
+ // the dot in the same place, a little above the middle, so the eye has one place to rest.
132
+ const centre = () => ({ cx: w * 0.5, cy: h * 0.44, R: Math.min(h * 0.32, w * 0.16) });
133
+ const drift = (p, t, k = 1) => [Math.sin(t * 0.5 + p.seed * 40) * 3 * k * p.z, Math.cos(t * 0.42 + p.seed2 * 40) * 2.4 * k * p.z];
134
+ const PICTURES = {
135
+ hello(p, t, data) {
136
+ const { cx, cy, R } = centre();
137
+ const [dx, dy] = drift(p, t);
138
+ if (!data.scanned) {
139
+ // A wide soft cloud, and a wave that crosses it, as if the computer were read line by line.
140
+ const ang = p.seed * Math.PI * 2;
141
+ const rad = Math.sqrt(p.seed2);
142
+ const x = cx + Math.cos(ang) * rad * w * 0.36;
143
+ const y = cy + Math.sin(ang) * rad * R * 1.25;
144
+ const sweep = w * (0.08 + 0.84 * frac(t * 0.24));
145
+ const near = Math.exp(-(((x - sweep) / 46) ** 2));
146
+ return [x + dx, y + dy - near * 7, 0.14 + 0.7 * near, 1 + near * 0.9];
147
+ }
148
+ // Read: the cloud gathers into a calm halo round the dot.
149
+ const ang = p.seed * Math.PI * 2 + t * 0.04;
150
+ const ring = R * (1.05 + (p.seed2 - 0.5) ** 2 * 2);
151
+ return [cx + Math.cos(ang) * ring * 1.9 + dx, cy + Math.sin(ang) * ring * 0.62 + dy, 0.22 + 0.45 * (1 - p.seed2), 1];
152
+ },
153
+ use(p, t, data) {
154
+ const { cx, cy, R } = centre();
155
+ const items = data.items ?? [];
156
+ const k = items.length ? p.i % items.length : 0;
157
+ const on = Boolean(items[k]?.on);
158
+ // Five nebulae on an ellipse round the dot; a marked one comes a third of the way in.
159
+ const ang = -Math.PI / 2 + ((k + 0.5) / Math.max(1, items.length)) * Math.PI * 2;
160
+ const pull = on ? 0.66 : 1;
161
+ const nx = cx + Math.cos(ang) * w * 0.34 * pull;
162
+ const ny = cy + Math.sin(ang) * R * 1.05 * pull;
163
+ // A few points of a marked nebula carry light to the dot.
164
+ if (on && p.seed < 0.16) {
165
+ const q = frac(t * 0.3 + p.seed2 * 3);
166
+ const bend = (p.seed2 - 0.5) * 40;
167
+ return [bezier(nx, (nx + cx) / 2 + bend, cx, easeInOut(q)), bezier(ny, (ny + cy) / 2 - bend, cy, easeInOut(q)), 0.9 * Math.sin(q * Math.PI), 1.1];
168
+ }
169
+ const [dx, dy] = drift(p, t, on ? 1.4 : 0.8);
170
+ const spread = (on ? 26 : 14) * Math.sqrt(p.seed2);
171
+ const a2 = p.seed2 * 40 + t * (on ? 0.12 : 0.05);
172
+ return [nx + Math.cos(a2) * spread * 1.3 + dx, ny + Math.sin(a2) * spread + dy, on ? 0.45 + 0.45 * (1 - p.seed2) : 0.13, on ? 1.15 : 0.85];
173
+ },
174
+ agents(p, t, data) {
175
+ const { cx, cy, R } = centre();
176
+ const items = data.items ?? [];
177
+ const n = Math.max(1, items.length);
178
+ const k = p.i % n;
179
+ const on = Boolean(items[k]?.on);
180
+ const ang = -Math.PI / 2 + ((k + 0.25) / n) * Math.PI * 2;
181
+ const nx = cx + Math.cos(ang) * w * 0.38;
182
+ const ny = cy + Math.sin(ang) * R * 1.1;
183
+ // A connected AI sends a stream of light along a gentle curve into the dot.
184
+ if (on && p.seed < 0.42) {
185
+ const q = frac(t * 0.26 + p.seed2 * 2);
186
+ const bend = Math.cos(ang) * 26;
187
+ return [bezier(nx, (nx + cx) / 2, cx, easeInOut(q)), bezier(ny, (ny + cy) / 2 + bend, cy, easeInOut(q)), 0.75 * Math.sin(q * Math.PI) ** 0.7, 0.95];
188
+ }
189
+ const [dx, dy] = drift(p, t, 0.7);
190
+ const spread = (on ? 13 : 8) * Math.sqrt(p.seed2);
191
+ const a2 = p.seed2 * 40 + t * 0.1;
192
+ return [nx + Math.cos(a2) * spread + dx, ny + Math.sin(a2) * spread * 0.8 + dy, on ? 0.6 + 0.3 * (1 - p.seed2) : 0.14, on ? 1.1 : 0.8];
193
+ },
194
+ project(p, t, data) {
195
+ const { cx, cy, R } = centre();
196
+ const n = Math.min(8, data.count ?? 0);
197
+ // The ring round the dot: fuller with every folder that comes.
198
+ const ringShare = 0.12 + 0.07 * n;
199
+ const ringAng = p.seed * Math.PI * 2 + t * 0.06;
200
+ const ringR = R * (0.9 + 0.22 * (p.seed2 - 0.5));
201
+ const ring = [cx + Math.cos(ringAng) * ringR * 1.75, cy + Math.sin(ringAng) * ringR * 0.55];
202
+ if (!n) { const [dx, dy] = drift(p, t); return [ring[0] + dx * 3, ring[1] + dy * 3, p.seed2 < 0.4 ? 0.14 : 0, 0.8]; }
203
+ if (p.seed2 < ringShare) return [ring[0], ring[1], 0.28 + 0.4 * p.z, 0.95];
204
+ // Threads: one from each folder chosen, coming in from the left edge, joining the ring.
205
+ const k = p.i % n;
206
+ const sy = h * (0.14 + (n === 1 ? 0.3 : (k / (n - 1)) * 0.6));
207
+ const q = frac(t * 0.17 + p.seed * 1.7);
208
+ const ex = cx - ringR * 1.75 * 0.98;
209
+ return [bezier(-10, w * 0.22, ex, easeInOut(q)), bezier(sy, sy, cy, easeInOut(q)), 0.62 * Math.sin(q * Math.PI) ** 0.6, 0.9];
210
+ },
211
+ ai(p, t, data) {
212
+ const { cx, cy, R } = centre();
213
+ const pct = clamp01((data.pct ?? 0) / 100);
214
+ if (data.state === 'ready') {
215
+ // Three quiet orbits, each a little more tilted, slower further out.
216
+ const shell = p.i % 3;
217
+ const r = R * (0.5 + shell * 0.26);
218
+ const ang = p.seed * Math.PI * 2 + t * (0.11 - shell * 0.025) * (shell === 1 ? -1 : 1);
219
+ const tilt = [0.32, 0.48, 0.62][shell];
220
+ return [cx + Math.cos(ang) * r * 1.6, cy + Math.sin(ang) * r * tilt, 0.25 + 0.5 * (0.5 + 0.5 * Math.sin(ang * 2 + t * 0.6)) * p.z, 0.95];
221
+ }
222
+ if (data.state === 'downloading') {
223
+ // Falling in, slowly, along a spiral: faster as more has arrived.
224
+ const q = frac(t * (0.12 + 0.18 * pct) + p.seed);
225
+ const r = R * (2.1 * (1 - q) + 0.28);
226
+ const ang = p.seed2 * Math.PI * 2 + q * 3.2;
227
+ return [cx + Math.cos(ang) * r * 1.5, cy + Math.sin(ang) * r * 0.6, 0.1 + 0.7 * q ** 1.4, 0.7 + 0.5 * q];
228
+ }
229
+ // Waiting, or left for later: a loose quiet disc.
230
+ const [dx, dy] = drift(p, t);
231
+ const ang = p.seed * Math.PI * 2;
232
+ const r = R * (0.6 + 1.3 * Math.sqrt(p.seed2));
233
+ return [cx + Math.cos(ang) * r * 1.6 + dx, cy + Math.sin(ang) * r * 0.55 + dy, data.state === 'skip' ? 0.07 : 0.15, 0.8];
234
+ },
235
+ ready(p, t, data, age) {
236
+ const { cy } = centre();
237
+ // The logo's pulse, drawn with points from the left, ending in the dot.
238
+ const x0 = w * 0.1;
239
+ const x1 = w * 0.5 - 14;
240
+ const u = p.i / (N - 1);
241
+ const drawn = still ? 1 : easeInOut(age / 1.6);
242
+ const amp = Math.min(30, h * 0.2);
243
+ const span = Math.min(0.32, 120 / Math.max(1, x1 - x0));
244
+ if (u > drawn) return [x0, cy, 0, 0.6];
245
+ const y = cy + beatAt((u - (0.62 - span / 2)) / span) * amp;
246
+ // A soft brightness runs along it, the way a heartbeat travels.
247
+ const runner = Math.exp(-(((u - frac(t * 0.22)) / 0.06) ** 2));
248
+ return [x0 + (x1 - x0) * u, y, 0.3 + 0.6 * runner, 0.75 + 0.4 * runner];
249
+ },
250
+ };
251
+ const dotOf = (id, data) => {
252
+ if (id === 'hello') return data.scanned ? 1 : 0;
253
+ if (id === 'use' || id === 'agents') return (data.items ?? []).some((one) => one.on) ? 1 : 0.45;
254
+ if (id === 'project') return data.count ? 1 : 0.45;
255
+ if (id === 'ai') return data.state === 'ready' ? 1 : data.state === 'downloading' ? 0.7 : data.state === 'skip' ? 0.3 : 0.5;
256
+ return 1;
257
+ };
258
+
259
+ // ---- Drawing.
260
+ function paintGround() {
261
+ ground = ground.map((v, i) => v + (look.ground[i] - v) * (still ? 1 : 0.12));
262
+ ctx.fillStyle = `rgb(${ground.map(Math.round).join(',')})`;
263
+ ctx.fillRect(0, 0, w, h);
264
+ const { cx, cy } = centre();
265
+ const glow = ctx.createRadialGradient(cx, cy, 0, cx, cy, Math.max(w, h) * 0.55);
266
+ glow.addColorStop(0, rgba(look.ink, look.glow));
267
+ glow.addColorStop(1, rgba(look.ink, 0));
268
+ ctx.fillStyle = glow;
269
+ ctx.fillRect(0, 0, w, h);
270
+ if (look.scan) { ctx.fillStyle = rgba(look.ink, look.scan); for (let y = 0; y < h; y += 4) ctx.fillRect(0, y, w, 1); }
271
+ }
272
+ function paintDot(t) {
273
+ if (dot.a < 0.01) return;
274
+ const { cx, cy } = centre();
275
+ // Its heartbeat: a fine ring that leaves it and fades, every few seconds.
276
+ if (!still) {
277
+ const beat = frac(t / RIPPLE);
278
+ ctx.strokeStyle = rgba(look.ink, dot.a * 0.45 * (1 - beat));
279
+ ctx.lineWidth = 1.2;
280
+ ctx.beginPath(); ctx.arc(cx, cy, dot.r + 4 + easeInOut(beat) * 26, 0, Math.PI * 2); ctx.stroke();
281
+ }
282
+ const r = dot.r * (1 + (still ? 0 : 0.16 * Math.exp(-(((frac(t / RIPPLE) * RIPPLE) / 0.25) ** 2))));
283
+ ctx.globalAlpha = dot.a;
284
+ ctx.drawImage(sprite, cx - r * 3.6, cy - r * 3.6, r * 7.2, r * 7.2);
285
+ ctx.globalAlpha = 1;
286
+ }
287
+ // The download's arc: a fine track round the core and how much of it is done.
288
+ function paintArc(data) {
289
+ if (scene.id !== 'ai' || data.state !== 'downloading') return;
290
+ const { cx, cy, R } = centre();
291
+ const r = R * 0.62;
292
+ ctx.lineWidth = 1.4;
293
+ ctx.lineCap = 'round';
294
+ ctx.strokeStyle = rgba(look.soft, 0.1);
295
+ ctx.beginPath(); ctx.arc(cx, cy, r, 0, Math.PI * 2); ctx.stroke();
296
+ ctx.strokeStyle = rgba(look.ink, 0.9);
297
+ ctx.beginPath(); ctx.arc(cx, cy, r, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * clamp01((data.pct ?? 0) / 100)); ctx.stroke();
298
+ }
299
+
300
+ function draw(nowMs) {
301
+ frame = 0;
302
+ if (!node.isConnected || !ctx) return;
303
+ if (!w) { fit(); if (!w) return; }
304
+ const now = nowMs / 1000;
305
+ const t = still ? 2 : now;
306
+ const age = still ? 99 : now - scene.since;
307
+ const data = scene.data() ?? {};
308
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
309
+ paintGround();
310
+ const want = PICTURES[scene.id] ?? PICTURES.hello;
311
+ ctx.globalCompositeOperation = look.blend;
312
+ for (const p of parts) {
313
+ const [tx, ty, ta, ts] = want(p, t, data, age);
314
+ if (still) { p.x = tx; p.y = ty; p.a = ta; p.s = ts; } else {
315
+ // A soft spring: the points arrive and settle, never snap or bounce.
316
+ p.vx = (p.vx + (tx - p.x) * 0.032) * 0.84;
317
+ p.vy = (p.vy + (ty - p.y) * 0.032) * 0.84;
318
+ p.x += p.vx;
319
+ p.y += p.vy;
320
+ p.a += (ta - p.a) * 0.07;
321
+ p.s += (ts - p.s) * 0.07;
322
+ }
323
+ const alpha = p.a * (0.45 + 0.55 * p.z);
324
+ if (alpha < 0.01) continue;
325
+ const r = (0.75 + 1.05 * p.z) * p.s;
326
+ ctx.globalAlpha = clamp01(alpha);
327
+ ctx.drawImage(sprite, p.x - r * 3.2, p.y - r * 3.2, r * 6.4, r * 6.4);
328
+ }
329
+ ctx.globalAlpha = 1;
330
+ ctx.globalCompositeOperation = 'source-over';
331
+ paintArc(data);
332
+ const target = dotOf(scene.id, data);
333
+ dot.a = still ? target : dot.a + (target - dot.a) * 0.06;
334
+ paintDot(t);
335
+ if (!still) frame = requestAnimationFrame(draw);
336
+ }
337
+ function redraw() { if (!frame) frame = requestAnimationFrame(draw); }
338
+
339
+ return {
340
+ node,
341
+ // A step's picture: its id and a function that says, each time it is drawn, what it shows now.
342
+ show(id, data = () => ({})) {
343
+ if (scene.id !== id) scene = { id, data, since: (globalThis.performance?.now() ?? Date.now()) / 1000 };
344
+ else scene.data = data;
345
+ redraw();
346
+ },
347
+ // The line under the picture: what is happening now, in a few words.
348
+ say(text) {
349
+ if (words.textContent === text) return;
350
+ words.textContent = text;
351
+ if (!still) { caption.classList.remove('new'); void caption.offsetWidth; caption.classList.add('new'); }
352
+ redraw();
353
+ },
354
+ // What it shows changed (a still picture is drawn again; a moving one already is).
355
+ redraw,
356
+ stop() { if (frame) cancelAnimationFrame(frame); frame = 0; observer?.disconnect(); watcher?.disconnect(); },
357
+ };
358
+ }