@idle-screens/savers-classic 3.0.0 → 3.2.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.
@@ -1,17 +1,402 @@
1
+ // src/dvd.ts
2
+ import {
3
+ sampleTrack,
4
+ defaultParams
5
+ } from "@idle-screens/core";
6
+ var MARKS = ["dvd", "idle-screens", "diamond", "ring"];
7
+ var PARAM_SPACE = {
8
+ /** Which shape bounces. 'dvd' = the classic wordmark-in-a-pill. */
9
+ mark: { type: "enum", default: "dvd", options: [...MARKS] },
10
+ /** Multiplies both axis speeds (and therefore the wall-hit rate). */
11
+ speed: { type: "number", default: 1, min: 0.25, max: 3, ease: "smooth" },
12
+ /** Multiplies the mark's box size. */
13
+ scale: { type: "number", default: 1, min: 0.5, max: 2, ease: "smooth" },
14
+ /** Base hue (0-360); each wall hit steps it deterministically from here. */
15
+ hue: { type: "number", default: 110, min: 0, max: 360, ease: "smooth" },
16
+ /** Phosphor glow around the mark. */
17
+ glow: { type: "number", default: 0.25, min: 0, max: 1, ease: "smooth" },
18
+ /** Burst intensity when both axes hit a wall at once (a corner hit). */
19
+ cornerParty: { type: "number", default: 0.6, min: 0, max: 1, ease: "smooth" }
20
+ };
21
+ var dvdManifest = {
22
+ id: "dvd",
23
+ label: "Bouncing Logo",
24
+ timeModel: "closed-form",
25
+ passthrough: false,
26
+ minBackend: "canvas2d",
27
+ costTier: "low",
28
+ motionIntensity: "calm",
29
+ reducedMotionFallback: "static",
30
+ paramSpace: PARAM_SPACE,
31
+ a11y: {
32
+ flashSafe: true,
33
+ notes: "Hue steps once per wall hit and a brief corner burst on exact corner hits; no strobing."
34
+ },
35
+ attribution: {
36
+ source: "DVD player idle screen + After Dark logo bounce \u2014 concepts. The DVD-Video logo is a trademark of DVD FLLC",
37
+ license: "MIT, original implementation; logo drawn from scratch as nostalgic homage (the bouncing-DVD meme) \u2014 no third-party assets"
38
+ },
39
+ workerReady: true
40
+ };
41
+ var BASE_SPEED_X = 144;
42
+ var BASE_SPEED_Y = 120;
43
+ var BASE_MARK_W = 200;
44
+ var BASE_MARK_H = 84;
45
+ var HUE_STEP_DEG = 47;
46
+ var CORNER_BURST_MS = 220;
47
+ var clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, v));
48
+ function tri(t, p) {
49
+ const cycle = p * 2;
50
+ const k = (t % cycle + cycle) % cycle;
51
+ return k < p ? k / p : 2 - k / p;
52
+ }
53
+ function hitCount(t, p) {
54
+ return Math.floor(Math.max(0, t) / p);
55
+ }
56
+ function distToNearestHit(t, p) {
57
+ const r = (t % p + p) % p;
58
+ return Math.min(r, p - r);
59
+ }
60
+ var DvdInstance = class {
61
+ ctxSaver;
62
+ canvas;
63
+ c2d;
64
+ w = 0;
65
+ h = 0;
66
+ frameId = null;
67
+ paused = false;
68
+ startT = 0;
69
+ /** Logical time the next rAF origin resumes from.
70
+ *
71
+ * `start()` re-anchors `startT` to the next frame's timestamp, so on its own
72
+ * `now - startT` always begins at zero. Mount wants that; resuming from a
73
+ * pause does not — without carrying the frozen `t` forward, every
74
+ * pause/resume (and every reduced-motion toggle) snaps the scene back to its
75
+ * opening frame and restarts any applied control track. Set only in
76
+ * `setPaused(false)`, so first mount still starts at 0. */
77
+ resumeFrom = 0;
78
+ t = 0;
79
+ params = defaultParams(PARAM_SPACE);
80
+ track = null;
81
+ constructor(ctx) {
82
+ this.ctxSaver = ctx;
83
+ if (ctx.surface) {
84
+ this.canvas = ctx.surface;
85
+ } else {
86
+ const el = document.createElement("canvas");
87
+ el.style.cssText = "display:block;width:100%;height:100%;background:#04050a";
88
+ ctx.host.appendChild(el);
89
+ this.canvas = el;
90
+ }
91
+ const c2d = this.canvas.getContext("2d", { alpha: false });
92
+ if (!c2d) throw new Error("dvd: no 2d context");
93
+ this.c2d = c2d;
94
+ this.w = ctx.width;
95
+ this.h = ctx.height;
96
+ this.sizeCanvas();
97
+ this.paused = ctx.reducedMotion;
98
+ if (this.paused) this.renderStill();
99
+ else this.start();
100
+ }
101
+ // ---- params ----
102
+ applyParams(t) {
103
+ const p = this.track ? sampleTrack(PARAM_SPACE, this.track, t) : this.params;
104
+ for (const k of Object.keys(PARAM_SPACE)) {
105
+ const v = p[k];
106
+ if (v !== void 0) this.params[k] = v;
107
+ }
108
+ }
109
+ sizeCanvas() {
110
+ const dpr = Math.min(this.ctxSaver.dpr, 2);
111
+ this.canvas.width = Math.max(1, Math.round(this.w * dpr));
112
+ this.canvas.height = Math.max(1, Math.round(this.h * dpr));
113
+ this.c2d.setTransform(dpr, 0, 0, dpr, 0, 0);
114
+ }
115
+ // ---- closed-form geometry ----
116
+ markSize() {
117
+ const s = this.params.scale;
118
+ return {
119
+ markW: clamp(BASE_MARK_W * s, 60, this.w * 0.7),
120
+ markH: clamp(BASE_MARK_H * s, 26, this.h * 0.7)
121
+ };
122
+ }
123
+ /** One-way traversal periods (ms) for each axis at the current box size
124
+ * and speed. Pure function of (w, h, markW, markH, speed). */
125
+ periods(markW, markH) {
126
+ const distX = Math.max(1, this.w - markW);
127
+ const distY = Math.max(1, this.h - markH);
128
+ const speedX = BASE_SPEED_X * Math.max(0.05, this.params.speed);
129
+ const speedY = BASE_SPEED_Y * Math.max(0.05, this.params.speed);
130
+ return { px: distX / speedX * 1e3, py: distY / speedY * 1e3 };
131
+ }
132
+ // ---- loop ----
133
+ start() {
134
+ if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
135
+ this.startT = 0;
136
+ this.frameId = requestAnimationFrame((now) => this.loop(now));
137
+ }
138
+ stop() {
139
+ if (this.frameId !== null) {
140
+ cancelAnimationFrame(this.frameId);
141
+ this.frameId = null;
142
+ }
143
+ }
144
+ loop(now) {
145
+ this.frameId = requestAnimationFrame((n) => this.loop(n));
146
+ if (this.startT === 0) this.startT = now;
147
+ this.renderFrame(now - this.startT + this.resumeFrom, this.ctxSaver.seed);
148
+ }
149
+ renderStill() {
150
+ this.renderFrame(this.t, this.ctxSaver.seed);
151
+ }
152
+ // ---- draw ----
153
+ /** Rounded-rect path built from `arc` + `lineTo` only (no `quadraticCurveTo`/
154
+ * `roundRect`, to stay inside the minimal Canvas2D surface classic savers
155
+ * rely on). */
156
+ roundRectPath(c, x, y, w, h, r) {
157
+ const rr = Math.max(0, Math.min(r, w / 2, h / 2));
158
+ c.beginPath();
159
+ c.moveTo(x + rr, y);
160
+ c.lineTo(x + w - rr, y);
161
+ c.arc(x + w - rr, y + rr, rr, -Math.PI / 2, 0);
162
+ c.lineTo(x + w, y + h - rr);
163
+ c.arc(x + w - rr, y + h - rr, rr, 0, Math.PI / 2);
164
+ c.lineTo(x + rr, y + h);
165
+ c.arc(x + rr, y + h - rr, rr, Math.PI / 2, Math.PI);
166
+ c.lineTo(x, y + rr);
167
+ c.arc(x + rr, y + rr, rr, Math.PI, Math.PI * 1.5);
168
+ c.closePath();
169
+ }
170
+ /** The classic mark, as the meme remembers it: heavy italic "DVD" letters
171
+ * over the wide disc ellipse with its centre hole. Drawn entirely from
172
+ * text + ellipse paths — no imported asset. The DVD-Video logo shape is a
173
+ * trademark of the DVD Format/Logo Licensing Corp; it appears here as the
174
+ * nostalgic bouncing-logo homage (see CREDITS.md). */
175
+ drawDvd(c, x, y, w, h, color) {
176
+ c.save();
177
+ c.fillStyle = color;
178
+ c.font = `italic 900 ${Math.round(h * 0.66)}px "Arial Black", Arial, sans-serif`;
179
+ c.textAlign = "center";
180
+ c.textBaseline = "middle";
181
+ c.fillText("DVD", x + w / 2, y + h * 0.32);
182
+ c.restore();
183
+ const cx = x + w / 2;
184
+ const cy = y + h * 0.8;
185
+ c.fillStyle = color;
186
+ c.beginPath();
187
+ c.ellipse(cx, cy, w * 0.5, h * 0.155, 0, 0, Math.PI * 2);
188
+ c.fill();
189
+ c.fillStyle = "#04050a";
190
+ c.beginPath();
191
+ c.ellipse(cx, cy, w * 0.115, h * 0.052, 0, 0, Math.PI * 2);
192
+ c.fill();
193
+ }
194
+ drawWordmark(c, x, y, w, h, color) {
195
+ c.fillStyle = color;
196
+ c.textAlign = "center";
197
+ c.textBaseline = "middle";
198
+ c.font = `700 ${Math.round(h * 0.32)}px ui-rounded, "Avenir Next", system-ui, sans-serif`;
199
+ c.fillText("idle-screens", x + w / 2, y + h / 2);
200
+ }
201
+ drawDiamond(c, x, y, w, h, color) {
202
+ const cx = x + w / 2;
203
+ const cy = y + h / 2;
204
+ const s = Math.min(w, h) * 0.62;
205
+ c.save();
206
+ c.translate(cx, cy);
207
+ c.rotate(Math.PI / 4);
208
+ c.fillStyle = color;
209
+ c.fillRect(-s / 2, -s / 2, s, s);
210
+ c.restore();
211
+ }
212
+ drawRing(c, x, y, w, h, color) {
213
+ const cx = x + w / 2;
214
+ const cy = y + h / 2;
215
+ const r = Math.min(w, h) * 0.4;
216
+ c.beginPath();
217
+ c.arc(cx, cy, r, 0, Math.PI * 2);
218
+ c.strokeStyle = color;
219
+ c.lineWidth = Math.max(4, r * 0.34);
220
+ c.stroke();
221
+ }
222
+ drawMark(mark, c, x, y, w, h, color) {
223
+ switch (mark) {
224
+ case "idle-screens":
225
+ this.drawWordmark(c, x, y, w, h, color);
226
+ break;
227
+ case "diamond":
228
+ this.drawDiamond(c, x, y, w, h, color);
229
+ break;
230
+ case "ring":
231
+ this.drawRing(c, x, y, w, h, color);
232
+ break;
233
+ case "dvd":
234
+ default:
235
+ this.drawDvd(c, x, y, w, h, color);
236
+ break;
237
+ }
238
+ }
239
+ /** A tiny sparkle burst — the "corner party" — purely a function of how
240
+ * close both axes are to hitting simultaneously right now. */
241
+ drawBurst(c, cx, cy, intensity, hue) {
242
+ const rays = 8;
243
+ const radius = 10 + 46 * intensity;
244
+ c.save();
245
+ c.globalCompositeOperation = "lighter";
246
+ for (let i = 0; i < rays; i++) {
247
+ const a = i / rays * Math.PI * 2;
248
+ c.strokeStyle = `hsla(${hue.toFixed(1)}, 92%, 72%, ${(0.85 * intensity).toFixed(3)})`;
249
+ c.lineWidth = 1.5 + 3 * intensity;
250
+ c.beginPath();
251
+ c.moveTo(cx, cy);
252
+ c.lineTo(cx + Math.cos(a) * radius, cy + Math.sin(a) * radius);
253
+ c.stroke();
254
+ }
255
+ c.restore();
256
+ }
257
+ /** Pure render at logical time `t` for `seed`: everything below is a closed
258
+ * -form function of (t, seed, this.w, this.h, this.params) — nothing is
259
+ * read from or written to accumulated instance state. */
260
+ render(t, seed) {
261
+ const c = this.c2d;
262
+ c.fillStyle = "#04050a";
263
+ c.fillRect(0, 0, this.w, this.h);
264
+ const { markW, markH } = this.markSize();
265
+ const { px, py } = this.periods(markW, markH);
266
+ const shifted = t + Math.abs(seed) * 233 % 5e3;
267
+ const x = tri(shifted, px) * Math.max(0, this.w - markW);
268
+ const y = tri(shifted, py) * Math.max(0, this.h - markH);
269
+ const hits = hitCount(shifted, px) + hitCount(shifted, py);
270
+ const hue = ((this.params.hue + hits * HUE_STEP_DEG) % 360 + 360) % 360;
271
+ const color = `hsl(${hue.toFixed(1)}, 78%, 56%)`;
272
+ if (this.params.glow > 0.02) {
273
+ c.shadowColor = color;
274
+ c.shadowBlur = 26 * this.params.glow;
275
+ } else {
276
+ c.shadowBlur = 0;
277
+ }
278
+ this.drawMark(this.params.mark, c, x, y, markW, markH, color);
279
+ c.shadowBlur = 0;
280
+ const ax = Math.max(0, 1 - distToNearestHit(shifted, px) / CORNER_BURST_MS);
281
+ const ay = Math.max(0, 1 - distToNearestHit(shifted, py) / CORNER_BURST_MS);
282
+ const cornerIntensity = this.params.cornerParty * ax * ax * ay * ay;
283
+ if (cornerIntensity > 2e-3) {
284
+ this.drawBurst(c, x + markW / 2, y + markH / 2, cornerIntensity, hue);
285
+ }
286
+ }
287
+ // ---- SaverInstance ----
288
+ setPaused(paused) {
289
+ this.paused = paused;
290
+ if (paused) {
291
+ this.stop();
292
+ this.renderStill();
293
+ } else {
294
+ this.resumeFrom = this.t;
295
+ this.start();
296
+ }
297
+ }
298
+ resize(width, height, dpr) {
299
+ this.w = width;
300
+ this.h = height;
301
+ if (dpr !== void 0) this.ctxSaver.dpr = dpr;
302
+ this.sizeCanvas();
303
+ if (this.paused) this.renderStill();
304
+ }
305
+ applyTrack(track) {
306
+ this.track = track;
307
+ if (this.paused) this.renderStill();
308
+ }
309
+ /** Pure, frame-addressable render: draw the state at logical time `t` for `seed`. */
310
+ renderFrame(t, seed) {
311
+ this.t = t;
312
+ this.applyParams(t);
313
+ this.render(t, seed);
314
+ }
315
+ dispose() {
316
+ this.stop();
317
+ if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) {
318
+ this.canvas.remove();
319
+ }
320
+ }
321
+ };
322
+ var dvd = {
323
+ manifest: dvdManifest,
324
+ mount: (ctx) => new DvdInstance(ctx)
325
+ };
326
+ var dvdDemoTrack = {
327
+ program: "dvd",
328
+ seed: 7,
329
+ duration: 16e3,
330
+ loop: true,
331
+ deltas: [
332
+ // The DVD logo IS the act; the other marks get a quick tour at the end.
333
+ { t: 0, path: "mark", value: "dvd" },
334
+ { t: 1e4, path: "mark", value: "diamond" },
335
+ { t: 12e3, path: "mark", value: "ring" },
336
+ { t: 14e3, path: "mark", value: "idle-screens" },
337
+ { t: 0, path: "hue", value: 110 },
338
+ { t: 8e3, path: "hue", value: 280, ease: "smooth" },
339
+ { t: 16e3, path: "hue", value: 110, ease: "smooth" },
340
+ { t: 0, path: "speed", value: 0.8 },
341
+ { t: 8e3, path: "speed", value: 1.7, ease: "smooth" },
342
+ { t: 16e3, path: "speed", value: 0.8, ease: "smooth" }
343
+ ]
344
+ };
345
+
1
346
  // src/warp.ts
347
+ import {
348
+ sampleTrack as sampleTrack2,
349
+ defaultParams as defaultParams2
350
+ } from "@idle-screens/core";
351
+ var PARAM_SPACE2 = {
352
+ /** Star count basis. Read only at build time — rebuilding the field live
353
+ * would reshuffle star identity and break renderFrame purity, so steer
354
+ * the other knobs to change the feel while live; density only takes
355
+ * effect on (re)mount. */
356
+ density: { type: "number", default: 520, min: 120, max: 1400 },
357
+ speed: { type: "number", default: 1, min: 0.25, max: 3, ease: "smooth" },
358
+ /** Star color. '#ffffff' is the classic white starfield. */
359
+ tint: { type: "color", default: "#ffffff" },
360
+ /** Elongation of the per-star motion streak. */
361
+ streak: { type: "number", default: 0.4, min: 0, max: 1, ease: "smooth" },
362
+ /** Subtle per-star brightness shimmer. No strobe: each star's shimmer
363
+ * period is fixed at build (800-1800ms), well under any flash threshold. */
364
+ twinkle: { type: "number", default: 0.3, min: 0, max: 1, ease: "smooth" }
365
+ };
2
366
  var warpManifest = {
3
367
  id: "warp",
4
368
  label: "Warp",
369
+ timeModel: "closed-form",
5
370
  passthrough: false,
6
371
  minBackend: "canvas2d",
7
372
  costTier: "low",
8
373
  motionIntensity: "energetic",
9
374
  reducedMotionFallback: "static",
10
- a11y: { flashSafe: true },
375
+ paramSpace: PARAM_SPACE2,
376
+ a11y: { flashSafe: true, notes: "Streaming star field; brightness shimmer is subtle and >=800ms per cycle." },
11
377
  workerReady: true
12
378
  };
13
- var STAR_COUNT = 520;
14
- var SPEED = 0.012;
379
+ var BASE_RATE = 727e-6;
380
+ var frac = (x) => x - Math.floor(x);
381
+ function smoothstep01(x) {
382
+ const c = Math.max(0, Math.min(1, x));
383
+ return c * c * (3 - 2 * c);
384
+ }
385
+ var FADE_IN_END = 0.15;
386
+ var FADE_OUT_START = 0.94;
387
+ function fadeEnvelope(p) {
388
+ let e = 1;
389
+ if (p < FADE_IN_END) e *= smoothstep01(p / FADE_IN_END);
390
+ if (p > FADE_OUT_START) e *= smoothstep01((1 - p) / (1 - FADE_OUT_START));
391
+ return e;
392
+ }
393
+ function hexToRgb(hex) {
394
+ const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
395
+ if (!m) return [255, 255, 255];
396
+ const h = m[1].length === 3 ? m[1].split("").map((c) => c + c).join("") : m[1];
397
+ const n = parseInt(h, 16);
398
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
399
+ }
15
400
  var WarpInstance = class {
16
401
  ctxSaver;
17
402
  canvas;
@@ -21,6 +406,19 @@ var WarpInstance = class {
21
406
  stars = [];
22
407
  frameId = null;
23
408
  paused = false;
409
+ startT = 0;
410
+ /** Logical time the next rAF origin resumes from.
411
+ *
412
+ * `start()` re-anchors `startT` to the next frame's timestamp, so on its own
413
+ * `now - startT` always begins at zero. Mount wants that; resuming from a
414
+ * pause does not — without carrying the frozen `t` forward, every
415
+ * pause/resume (and every reduced-motion toggle) snaps the scene back to its
416
+ * opening frame and restarts any applied control track. Set only in
417
+ * `setPaused(false)`, so first mount still starts at 0. */
418
+ resumeFrom = 0;
419
+ t = 0;
420
+ params = defaultParams2(PARAM_SPACE2);
421
+ track = null;
24
422
  constructor(ctx) {
25
423
  this.ctxSaver = ctx;
26
424
  let canvas;
@@ -45,31 +443,43 @@ var WarpInstance = class {
45
443
  if (this.paused) this.renderStill();
46
444
  else this.start();
47
445
  }
446
+ // ---- params ----
447
+ applyParams(t) {
448
+ const p = this.track ? sampleTrack2(PARAM_SPACE2, this.track, t) : this.params;
449
+ for (const k of Object.keys(PARAM_SPACE2)) {
450
+ const v = p[k];
451
+ if (v !== void 0) this.params[k] = v;
452
+ }
453
+ }
48
454
  sizeCanvas() {
49
455
  const dpr = Math.min(this.ctxSaver.dpr, 2);
50
456
  this.canvas.width = Math.max(1, Math.round(this.w * dpr));
51
457
  this.canvas.height = Math.max(1, Math.round(this.h * dpr));
52
458
  this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
53
459
  }
460
+ /** Build the star field's fixed identity from forked streams. Deterministic
461
+ * regardless of how much of `ctx.rng` other code has consumed, and safe
462
+ * to call again (e.g. a future density change on remount) without
463
+ * reshuffling existing star identities. */
54
464
  buildStars() {
55
- const rng = this.ctxSaver.rng;
56
- this.stars = new Array(STAR_COUNT);
57
- for (let i = 0; i < STAR_COUNT; i++) {
58
- this.stars[i] = this.spawn(rng.range(0.01, 1));
465
+ const count = Math.max(1, Math.round(this.params.density));
466
+ this.stars = new Array(count);
467
+ for (let i = 0; i < count; i++) {
468
+ const r = this.ctxSaver.rng.fork(i);
469
+ this.stars[i] = {
470
+ x: r.range(-1, 1),
471
+ y: r.range(-1, 1),
472
+ phase: r.next(),
473
+ twinklePhase: r.range(0, Math.PI * 2),
474
+ twinklePeriod: r.range(800, 1800)
475
+ };
59
476
  }
60
477
  }
61
- spawn(z) {
62
- const rng = this.ctxSaver.rng;
63
- return {
64
- x: rng.range(-1, 1),
65
- y: rng.range(-1, 1),
66
- z,
67
- pz: z
68
- };
69
- }
478
+ // ---- loop ----
70
479
  start() {
71
480
  if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
72
- this.loop();
481
+ this.startT = 0;
482
+ this.frameId = requestAnimationFrame((now) => this.loop(now));
73
483
  }
74
484
  stop() {
75
485
  if (this.frameId !== null) {
@@ -77,44 +487,54 @@ var WarpInstance = class {
77
487
  this.frameId = null;
78
488
  }
79
489
  }
80
- loop() {
81
- this.frameId = requestAnimationFrame(() => this.loop());
82
- this.step();
83
- this.render();
490
+ loop(now) {
491
+ this.frameId = requestAnimationFrame((n) => this.loop(n));
492
+ if (this.startT === 0) this.startT = now;
493
+ this.renderFrame(now - this.startT + this.resumeFrom, this.ctxSaver.seed);
84
494
  }
85
- step() {
86
- for (const s of this.stars) {
87
- s.pz = s.z;
88
- s.z -= SPEED;
89
- if (s.z <= 0.01) {
90
- const respawned = this.spawn(1);
91
- s.x = respawned.x;
92
- s.y = respawned.y;
93
- s.z = 1;
94
- s.pz = 1;
95
- }
96
- }
495
+ renderStill() {
496
+ this.renderFrame(this.t, this.ctxSaver.seed);
97
497
  }
98
- render() {
498
+ // ---- closed-form travel + draw ----
499
+ /** A star's travel progress at time `t`: 0 = just spawned (near center,
500
+ * dim), approaches 1 as it nears the eye and is about to recycle. Pure
501
+ * function of `t` and the star's fixed phase — no accumulation. */
502
+ progress(star, t, rate) {
503
+ return frac(star.phase + t * rate);
504
+ }
505
+ render(t) {
99
506
  const ctx = this.ctx;
100
507
  const w = this.w;
101
508
  const h = this.h;
102
509
  const cx = w / 2;
103
510
  const cy = h / 2;
104
511
  const focal = Math.min(w, h) * 0.9;
512
+ const p = this.params;
513
+ const rate = BASE_RATE * p.speed;
514
+ const [tr, tg, tb] = hexToRgb(p.tint);
515
+ const streakDt = 16 * (1 + p.streak * 5);
105
516
  ctx.fillStyle = "rgba(17,17,17,0.45)";
106
517
  ctx.fillRect(0, 0, w, h);
107
518
  ctx.lineCap = "round";
108
519
  for (const s of this.stars) {
109
- const sx = cx + s.x / s.z * focal;
110
- const sy = cy + s.y / s.z * focal;
111
- const px = cx + s.x / s.pz * focal;
112
- const py = cy + s.y / s.pz * focal;
113
- if (sx < -50 || sx > w + 50 || sy < -50 || sy > h + 50) continue;
114
- const depth = 1 - s.z;
115
- const alpha = Math.min(1, 0.15 + depth * 1.1);
116
- const size = Math.max(0.4, depth * 2.6);
117
- ctx.strokeStyle = `rgba(220,235,255,${alpha.toFixed(3)})`;
520
+ const prog = this.progress(s, t, rate);
521
+ const z = 1 - prog * 0.99;
522
+ const sx = cx + s.x / z * focal;
523
+ const sy = cy + s.y / z * focal;
524
+ let progPrev = this.progress(s, t - streakDt, rate);
525
+ if (progPrev > prog) progPrev = prog;
526
+ const zPrev = 1 - progPrev * 0.99;
527
+ const px = cx + s.x / zPrev * focal;
528
+ const py = cy + s.y / zPrev * focal;
529
+ const headOut = sx < -50 || sx > w + 50 || sy < -50 || sy > h + 50;
530
+ const tailOut = px < -50 || px > w + 50 || py < -50 || py > h + 50;
531
+ if (headOut && tailOut) continue;
532
+ const envelope = fadeEnvelope(prog);
533
+ const shimmer = 1 + p.twinkle * 0.4 * Math.sin(2 * Math.PI * t / s.twinklePeriod + s.twinklePhase);
534
+ const alpha = Math.max(0, Math.min(1, (0.15 + prog * 1.1) * envelope * shimmer));
535
+ if (alpha <= 2e-3) continue;
536
+ const size = Math.max(0.4, prog * 2.6);
537
+ ctx.strokeStyle = `rgba(${tr},${tg},${tb},${alpha.toFixed(3)})`;
118
538
  ctx.lineWidth = size;
119
539
  ctx.beginPath();
120
540
  ctx.moveTo(px, py);
@@ -122,32 +542,14 @@ var WarpInstance = class {
122
542
  ctx.stroke();
123
543
  }
124
544
  }
125
- renderStill() {
126
- const ctx = this.ctx;
127
- ctx.fillStyle = "#111";
128
- ctx.fillRect(0, 0, this.w, this.h);
129
- const cx = this.w / 2;
130
- const cy = this.h / 2;
131
- const focal = Math.min(this.w, this.h) * 0.9;
132
- for (const s of this.stars) {
133
- const sx = cx + s.x / s.z * focal;
134
- const sy = cy + s.y / s.z * focal;
135
- if (sx < 0 || sx > this.w || sy < 0 || sy > this.h) continue;
136
- const depth = 1 - s.z;
137
- const alpha = Math.min(1, 0.15 + depth * 1.1);
138
- const size = Math.max(0.4, depth * 2.6);
139
- ctx.fillStyle = `rgba(220,235,255,${alpha.toFixed(3)})`;
140
- ctx.beginPath();
141
- ctx.arc(sx, sy, size, 0, Math.PI * 2);
142
- ctx.fill();
143
- }
144
- }
545
+ // ---- SaverInstance ----
145
546
  setPaused(paused) {
146
547
  this.paused = paused;
147
548
  if (paused) {
148
549
  this.stop();
149
550
  this.renderStill();
150
551
  } else {
552
+ this.resumeFrom = this.t;
151
553
  this.start();
152
554
  }
153
555
  }
@@ -158,6 +560,18 @@ var WarpInstance = class {
158
560
  this.sizeCanvas();
159
561
  if (this.paused) this.renderStill();
160
562
  }
563
+ applyTrack(track) {
564
+ this.track = track;
565
+ if (this.paused) this.renderStill();
566
+ }
567
+ /** Pure, frame-addressable render: draw the state at logical time `t` for
568
+ * `seed`. Identical (t, seed, applied track) always produces the same
569
+ * frame — safe to seek forward or backward. */
570
+ renderFrame(t, _seed) {
571
+ this.t = t;
572
+ this.applyParams(t);
573
+ this.render(t);
574
+ }
161
575
  dispose() {
162
576
  this.stop();
163
577
  if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
@@ -167,11 +581,31 @@ var warp = {
167
581
  manifest: warpManifest,
168
582
  mount: (ctx) => new WarpInstance(ctx)
169
583
  };
584
+ var warpDemoTrack = {
585
+ program: "warp",
586
+ seed: 7,
587
+ duration: 14e3,
588
+ loop: true,
589
+ deltas: [
590
+ { t: 0, path: "speed", value: 0.6 },
591
+ { t: 5e3, path: "speed", value: 2.4, ease: "smooth" },
592
+ { t: 9e3, path: "speed", value: 0.6, ease: "smooth" },
593
+ { t: 14e3, path: "speed", value: 0.6 },
594
+ { t: 0, path: "streak", value: 0.15 },
595
+ { t: 5e3, path: "streak", value: 0.9, ease: "smooth" },
596
+ { t: 9e3, path: "streak", value: 0.15, ease: "smooth" },
597
+ { t: 14e3, path: "streak", value: 0.15 },
598
+ { t: 0, path: "tint", value: "#ffffff" },
599
+ { t: 7e3, path: "tint", value: "#8fd8ff", ease: "smooth" },
600
+ { t: 14e3, path: "tint", value: "#ffffff", ease: "smooth" }
601
+ ]
602
+ };
170
603
 
171
604
  // src/hard-rain.ts
172
605
  var hardRainManifest = {
173
606
  id: "hard-rain",
174
607
  label: "Hard Rain",
608
+ timeModel: "closed-form",
175
609
  passthrough: false,
176
610
  minBackend: "canvas2d",
177
611
  costTier: "low",
@@ -326,7 +760,7 @@ var DROP_SPECS = [
326
760
  "t1 p5-4 s250 yellow",
327
761
  "t24 p5-5 s200 ltgray"
328
762
  ];
329
- function hexToRgb(hex) {
763
+ function hexToRgb2(hex) {
330
764
  const n = parseInt(hex.slice(1), 16);
331
765
  return `${n >> 16 & 255},${n >> 8 & 255},${n & 255}`;
332
766
  }
@@ -373,7 +807,7 @@ var HardRainInstance = class {
373
807
  fx: pos[0],
374
808
  fy: pos[1],
375
809
  maxR: SIZES[sCls] ?? 100,
376
- rgb: hexToRgb(COLOURS[cCls] ?? "#c2c2c2"),
810
+ rgb: hexToRgb2(COLOURS[cCls] ?? "#c2c2c2"),
377
811
  phase: timingPhase(tCls)
378
812
  };
379
813
  });
@@ -463,6 +897,7 @@ var hardRain = {
463
897
  var rainstormManifest = {
464
898
  id: "rainstorm",
465
899
  label: "Rainstorm",
900
+ timeModel: "closed-form",
466
901
  passthrough: false,
467
902
  minBackend: "canvas2d",
468
903
  costTier: "low",
@@ -641,45 +1076,97 @@ var rainstorm = {
641
1076
  };
642
1077
 
643
1078
  // src/globe.ts
1079
+ import {
1080
+ sampleTrack as sampleTrack3,
1081
+ defaultParams as defaultParams3
1082
+ } from "@idle-screens/core";
1083
+ var RADIUS = 120;
1084
+ var SPIN_BASE = 0.9;
1085
+ var BOUNCE_SPEED = 90;
1086
+ var SEG_LAT = 24;
1087
+ var SEG_LON = 48;
1088
+ var LINE_W_DEVICE = 0.85;
1089
+ var TAU = Math.PI * 2;
1090
+ var PARAM_SPACE3 = {
1091
+ /** Meridian count (longitude lines); parallel count is derived proportionally
1092
+ * (11 parallels : 21 meridians, the original's ratio). Read once at mount —
1093
+ * the lattice is built at construction time and does not respond to a
1094
+ * control-track delta, same convention as `bubbleCount` in saver-tide. */
1095
+ density: { type: "number", default: 21, min: 8, max: 42 },
1096
+ /** Rotation-rate multiplier on the preserved 0.9 rad/s base. */
1097
+ spin: { type: "number", default: 1, min: 0.25, max: 3, ease: "smooth" },
1098
+ /** DVD-bounce amplitude. 1 = the original's full corner-to-corner bounce;
1099
+ * 0 = the globe floats motionless at viewport center. */
1100
+ bounce: { type: "number", default: 1, min: 0, max: 1, ease: "smooth" },
1101
+ /** Wireframe stroke color. */
1102
+ wire: { type: "color", default: "#78c8ff" },
1103
+ /** Soft additive glow on the globe's limb. */
1104
+ glow: { type: "number", default: 0.35, min: 0, max: 1, ease: "smooth" },
1105
+ /** How much the far (back) hemisphere dims relative to the near hemisphere. */
1106
+ depthFade: { type: "number", default: 0.8, min: 0, max: 1, ease: "smooth" }
1107
+ };
644
1108
  var globeManifest = {
645
1109
  id: "globe",
646
1110
  label: "Globe",
1111
+ timeModel: "closed-form",
647
1112
  passthrough: false,
648
1113
  minBackend: "canvas2d",
649
1114
  costTier: "low",
650
1115
  motionIntensity: "calm",
651
1116
  reducedMotionFallback: "static",
1117
+ paramSpace: PARAM_SPACE3,
652
1118
  attribution: {
653
1119
  source: 'After Dark "Globe" \u2014 concept by Berkeley Systems',
654
1120
  license: "MIT port; reference CSS MIT (Bryan Braun)",
655
1121
  url: "https://github.com/bryanbraun/after-dark-css"
656
1122
  },
657
- a11y: { flashSafe: true, notes: "A slowly spinning dotted globe drifting on black; no flashing." },
1123
+ a11y: { flashSafe: true, notes: "A slowly spinning wireframe globe drifting on black; no flashing." },
658
1124
  workerReady: true
659
1125
  };
660
- var RADIUS = 120;
661
- var SPIN = 0.9;
662
- var LAT_LINES = 11;
663
- var LON_LINES = 21;
1126
+ function reflect(pos, size) {
1127
+ const period = size * 2;
1128
+ const k = (pos % period + period) % period;
1129
+ return k <= size ? k : period - k;
1130
+ }
1131
+ function lerp(a, b, p) {
1132
+ return a + (b - a) * p;
1133
+ }
1134
+ function parseHex(c) {
1135
+ const m = /^#?([0-9a-f]{6})$/i.exec(c.trim());
1136
+ if (!m) return [120, 200, 255];
1137
+ const n = parseInt(m[1], 16);
1138
+ return [n >> 16 & 255, n >> 8 & 255, n & 255];
1139
+ }
1140
+ var rgba = (r, g, b, a) => `rgba(${r.toFixed(0)},${g.toFixed(0)},${b.toFixed(0)},${Math.max(0, Math.min(1, a)).toFixed(3)})`;
1141
+ function depthAlpha(depth, depthFade) {
1142
+ const front = 0.82;
1143
+ const backMin = 0.04;
1144
+ const back = front - depthFade * (front - backMin);
1145
+ return back + (front - back) * depth;
1146
+ }
664
1147
  var GlobeInstance = class {
665
- ctx;
1148
+ ctxSaver;
666
1149
  canvas;
667
1150
  c2d;
668
1151
  w = 0;
669
1152
  h = 0;
670
- // globe centre + velocity (DVD bounce)
671
- cx = 0;
672
- cy = 0;
673
- vx = 0;
674
- vy = 0;
675
- spinPhase = 0;
676
- // precomputed unit-sphere lattice (spun about Y at render time)
677
- lattice = [];
1153
+ t = 0;
678
1154
  frameId = null;
679
1155
  paused = false;
680
- last = 0;
1156
+ startT = 0;
1157
+ params = defaultParams3(PARAM_SPACE3);
1158
+ track = null;
1159
+ // Seeded once at construction (never rebuilt on resize) — the exact analog
1160
+ // of saver-tide's `build()`. Determinism only requires the SAME instance to
1161
+ // reproduce a given t; these constants make the DVD-bounce path pure in t.
1162
+ x0Frac;
1163
+ y0Frac;
1164
+ dirAngle;
1165
+ // Lattice, built once from the manifest-default `density` (build-time param).
1166
+ meridians = [];
1167
+ parallels = [];
681
1168
  constructor(ctx) {
682
- this.ctx = ctx;
1169
+ this.ctxSaver = ctx;
683
1170
  let canvas;
684
1171
  if (ctx.surface) {
685
1172
  canvas = ctx.surface;
@@ -693,51 +1180,85 @@ var GlobeInstance = class {
693
1180
  const c2d = canvas.getContext("2d", { alpha: false });
694
1181
  if (!c2d) throw new Error("globe: no 2d context");
695
1182
  this.c2d = c2d;
696
- this.buildLattice();
1183
+ this.buildLattice(PARAM_SPACE3.density.default);
697
1184
  this.w = ctx.width;
698
1185
  this.h = ctx.height;
699
1186
  this.sizeCanvas();
700
1187
  const rng = ctx.rng;
701
- this.cx = rng.range(RADIUS, Math.max(RADIUS + 1, this.w - RADIUS));
702
- this.cy = rng.range(RADIUS, Math.max(RADIUS + 1, this.h - RADIUS));
703
- const dir = rng.range(0, Math.PI * 2);
704
- const speed = 90;
705
- this.vx = Math.cos(dir) * speed;
706
- this.vy = Math.sin(dir) * speed;
707
- this.setPaused(ctx.reducedMotion);
1188
+ this.x0Frac = rng.next();
1189
+ this.y0Frac = rng.next();
1190
+ this.dirAngle = rng.range(0, TAU);
1191
+ this.paused = ctx.reducedMotion;
708
1192
  if (this.paused) this.renderStill();
1193
+ else this.start();
709
1194
  }
710
- /** Dotted lat/long lattice on the unit sphere. */
711
- buildLattice() {
712
- for (let i = 1; i < LAT_LINES; i++) {
713
- const lat = -Math.PI / 2 + Math.PI * i / LAT_LINES;
714
- const ringR = Math.cos(lat);
715
- const y = Math.sin(lat);
716
- const dots = Math.max(6, Math.round(LON_LINES * ringR + 4));
717
- for (let j = 0; j < dots; j++) {
718
- const lon = Math.PI * 2 * j / dots;
719
- this.lattice.push({ x: ringR * Math.cos(lon), y, z: ringR * Math.sin(lon) });
1195
+ /** Meridian half-ellipses + parallel rings on the unit sphere. Pure geometry,
1196
+ * no randomness — `density` is read once, at build time, per the paramSpace
1197
+ * comment; a later control-track delta on `density` updates `params.density`
1198
+ * but does not re-tessellate the lattice. */
1199
+ buildLattice(density) {
1200
+ const meridianCount = Math.max(4, Math.round(density));
1201
+ const parallelCount = Math.max(3, Math.round(density * (11 / 21)));
1202
+ for (let m = 0; m < meridianCount; m++) {
1203
+ const lon = TAU * m / meridianCount;
1204
+ const line = [];
1205
+ for (let s = 0; s <= SEG_LAT; s++) {
1206
+ const lat = -Math.PI / 2 + Math.PI * s / SEG_LAT;
1207
+ const ringR = Math.cos(lat);
1208
+ line.push({ x: ringR * Math.cos(lon), y: Math.sin(lat), z: ringR * Math.sin(lon) });
720
1209
  }
1210
+ this.meridians.push(line);
721
1211
  }
722
- for (let m = 0; m < LON_LINES; m++) {
723
- const lon = Math.PI * 2 * m / LON_LINES;
724
- for (let s = 0; s <= 24; s++) {
725
- const lat = -Math.PI / 2 + Math.PI * s / 24;
726
- const ringR = Math.cos(lat);
727
- this.lattice.push({ x: ringR * Math.cos(lon), y: Math.sin(lat), z: ringR * Math.sin(lon) });
1212
+ for (let i = 1; i < parallelCount; i++) {
1213
+ const lat = -Math.PI / 2 + Math.PI * i / parallelCount;
1214
+ const ringR = Math.cos(lat);
1215
+ const y = Math.sin(lat);
1216
+ const line = [];
1217
+ for (let k = 0; k <= SEG_LON; k++) {
1218
+ const lon = TAU * k / SEG_LON;
1219
+ line.push({ x: ringR * Math.cos(lon), y, z: ringR * Math.sin(lon) });
728
1220
  }
1221
+ this.parallels.push(line);
729
1222
  }
730
1223
  }
731
1224
  sizeCanvas() {
732
- const dpr = Math.min(this.ctx.dpr, 2);
1225
+ const dpr = Math.min(this.ctxSaver.dpr, 2);
733
1226
  this.canvas.width = Math.max(1, Math.round(this.w * dpr));
734
1227
  this.canvas.height = Math.max(1, Math.round(this.h * dpr));
735
1228
  this.c2d.setTransform(dpr, 0, 0, dpr, 0, 0);
736
1229
  }
1230
+ applyParams(t) {
1231
+ const p = this.track ? sampleTrack3(PARAM_SPACE3, this.track, t) : this.params;
1232
+ for (const k of Object.keys(PARAM_SPACE3)) {
1233
+ const v = p[k];
1234
+ if (v !== void 0) this.params[k] = v;
1235
+ }
1236
+ }
1237
+ // ---- closed-form placement ----
1238
+ /** Globe center at time `t` (ms). `bounce` blends between the full
1239
+ * DVD-bounce path and a fixed viewport center. Pure in `t` given the
1240
+ * instance's current w/h and the seeded x0Frac/y0Frac/dirAngle. */
1241
+ center(t) {
1242
+ const p = this.params;
1243
+ const rangeX = Math.max(1, this.w - RADIUS * 2);
1244
+ const rangeY = Math.max(1, this.h - RADIUS * 2);
1245
+ const tSec = t / 1e3;
1246
+ const vx = Math.cos(this.dirAngle) * BOUNCE_SPEED;
1247
+ const vy = Math.sin(this.dirAngle) * BOUNCE_SPEED;
1248
+ const bx = RADIUS + reflect(this.x0Frac * rangeX + vx * tSec, rangeX);
1249
+ const by = RADIUS + reflect(this.y0Frac * rangeY + vy * tSec, rangeY);
1250
+ return [lerp(this.w / 2, bx, p.bounce), lerp(this.h / 2, by, p.bounce)];
1251
+ }
1252
+ /** Rotation angle at time `t` (ms). Pure: the instantaneous `spin` sample
1253
+ * times the preserved base rate, times elapsed seconds — same convention
1254
+ * as saver-tide's `waveSpeed * t` (no integration across changing spin). */
1255
+ angle(t) {
1256
+ return t / 1e3 * SPIN_BASE * this.params.spin;
1257
+ }
737
1258
  // ---- loop ----
738
1259
  start() {
739
1260
  if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
740
- this.last = 0;
1261
+ this.startT = 0;
741
1262
  this.frameId = requestAnimationFrame((now) => this.loop(now));
742
1263
  }
743
1264
  stop() {
@@ -748,76 +1269,90 @@ var GlobeInstance = class {
748
1269
  }
749
1270
  loop(now) {
750
1271
  this.frameId = requestAnimationFrame((n) => this.loop(n));
751
- if (this.last === 0) this.last = now;
752
- const dt = Math.min(0.05, (now - this.last) / 1e3);
753
- this.last = now;
754
- this.update(dt);
755
- this.render();
1272
+ if (this.startT === 0) this.startT = now;
1273
+ this.renderFrame(now - this.startT, this.ctxSaver.seed);
756
1274
  }
757
- update(dt) {
758
- this.spinPhase += SPIN * dt;
759
- this.cx += this.vx * dt;
760
- this.cy += this.vy * dt;
761
- const minX = RADIUS;
762
- const maxX = this.w - RADIUS;
763
- const minY = RADIUS;
764
- const maxY = this.h - RADIUS;
765
- if (this.cx < minX) {
766
- this.cx = minX;
767
- this.vx = Math.abs(this.vx);
768
- } else if (this.cx > maxX) {
769
- this.cx = maxX;
770
- this.vx = -Math.abs(this.vx);
771
- }
772
- if (this.cy < minY) {
773
- this.cy = minY;
774
- this.vy = Math.abs(this.vy);
775
- } else if (this.cy > maxY) {
776
- this.cy = maxY;
777
- this.vy = -Math.abs(this.vy);
1275
+ renderStill() {
1276
+ this.renderFrame(this.t, this.ctxSaver.seed);
1277
+ }
1278
+ /** Stroke one lattice polyline (a meridian or a parallel ring), rotated and
1279
+ * projected at render time. `ctx.strokeStyle` is set by the caller;
1280
+ * per-segment alpha/width vary with `depthFade`/`lineW` for a sense of
1281
+ * depth on the back hemisphere. */
1282
+ strokeLine(line, cx, cy, cosA, sinA, lineW, depthFade) {
1283
+ const ctx = this.c2d;
1284
+ let prevX = 0;
1285
+ let prevY = 0;
1286
+ let prevDepth = 0;
1287
+ for (let i = 0; i < line.length; i++) {
1288
+ const p = line[i];
1289
+ const rx = p.x * cosA + p.z * sinA;
1290
+ const rz = -p.x * sinA + p.z * cosA;
1291
+ const x = cx + rx * RADIUS;
1292
+ const y = cy + p.y * RADIUS;
1293
+ const depth = (rz + 1) / 2;
1294
+ if (i > 0) {
1295
+ const avgDepth = (prevDepth + depth) / 2;
1296
+ ctx.globalAlpha = depthAlpha(avgDepth, depthFade);
1297
+ ctx.lineWidth = lineW * (0.55 + 0.65 * avgDepth);
1298
+ ctx.beginPath();
1299
+ ctx.moveTo(prevX, prevY);
1300
+ ctx.lineTo(x, y);
1301
+ ctx.stroke();
1302
+ }
1303
+ prevX = x;
1304
+ prevY = y;
1305
+ prevDepth = depth;
778
1306
  }
1307
+ ctx.globalAlpha = 1;
779
1308
  }
780
- render() {
1309
+ render(t) {
781
1310
  const ctx = this.c2d;
1311
+ const p = this.params;
1312
+ const [cx, cy] = this.center(t);
1313
+ const a = this.angle(t);
1314
+ const cosA = Math.cos(a);
1315
+ const sinA = Math.sin(a);
1316
+ const dpr = Math.min(this.ctxSaver.dpr, 2);
1317
+ const lineW = LINE_W_DEVICE / dpr;
1318
+ const [wr, wg, wb] = parseHex(p.wire);
782
1319
  ctx.fillStyle = "#000";
783
1320
  ctx.fillRect(0, 0, this.w, this.h);
784
1321
  const body = ctx.createRadialGradient(
785
- this.cx - RADIUS * 0.35,
786
- this.cy - RADIUS * 0.35,
1322
+ cx - RADIUS * 0.35,
1323
+ cy - RADIUS * 0.35,
787
1324
  RADIUS * 0.1,
788
- this.cx,
789
- this.cy,
1325
+ cx,
1326
+ cy,
790
1327
  RADIUS
791
1328
  );
792
- body.addColorStop(0, "rgba(30,60,90,0.55)");
793
- body.addColorStop(1, "rgba(6,14,26,0.15)");
1329
+ body.addColorStop(0, rgba(wr * 0.35, wg * 0.4, wb * 0.5, 0.5));
1330
+ body.addColorStop(1, rgba(wr * 0.1, wg * 0.14, wb * 0.2, 0.15));
794
1331
  ctx.fillStyle = body;
795
1332
  ctx.beginPath();
796
- ctx.arc(this.cx, this.cy, RADIUS, 0, Math.PI * 2);
1333
+ ctx.arc(cx, cy, RADIUS, 0, TAU);
797
1334
  ctx.fill();
798
- const cos = Math.cos(this.spinPhase);
799
- const sin = Math.sin(this.spinPhase);
800
- for (const p of this.lattice) {
801
- const rx = p.x * cos + p.z * sin;
802
- const rz = -p.x * sin + p.z * cos;
803
- const x = this.cx + rx * RADIUS;
804
- const y = this.cy + p.y * RADIUS;
805
- const depth = (rz + 1) / 2;
806
- const alpha = 0.12 + depth * 0.7;
807
- const size = 0.7 + depth * 1.2;
808
- ctx.fillStyle = `rgba(120,200,255,${alpha.toFixed(3)})`;
1335
+ ctx.strokeStyle = rgba(wr, wg, wb, 1);
1336
+ for (const line of this.meridians) this.strokeLine(line, cx, cy, cosA, sinA, lineW, p.depthFade);
1337
+ for (const line of this.parallels) this.strokeLine(line, cx, cy, cosA, sinA, lineW, p.depthFade);
1338
+ ctx.globalAlpha = 1;
1339
+ ctx.strokeStyle = rgba(wr, wg, wb, 0.4);
1340
+ ctx.lineWidth = lineW;
1341
+ ctx.beginPath();
1342
+ ctx.arc(cx, cy, RADIUS, 0, TAU);
1343
+ ctx.stroke();
1344
+ if (p.glow > 0.01) {
1345
+ ctx.save();
1346
+ ctx.globalCompositeOperation = "lighter";
1347
+ const glow = ctx.createRadialGradient(cx, cy, RADIUS * 0.82, cx, cy, RADIUS * 1.4);
1348
+ glow.addColorStop(0, rgba(wr, wg, wb, 0.4 * p.glow));
1349
+ glow.addColorStop(1, rgba(wr, wg, wb, 0));
1350
+ ctx.fillStyle = glow;
809
1351
  ctx.beginPath();
810
- ctx.arc(x, y, size, 0, Math.PI * 2);
1352
+ ctx.arc(cx, cy, RADIUS * 1.4, 0, TAU);
811
1353
  ctx.fill();
1354
+ ctx.restore();
812
1355
  }
813
- ctx.strokeStyle = "rgba(120,200,255,0.35)";
814
- ctx.lineWidth = 1;
815
- ctx.beginPath();
816
- ctx.arc(this.cx, this.cy, RADIUS, 0, Math.PI * 2);
817
- ctx.stroke();
818
- }
819
- renderStill() {
820
- this.render();
821
1356
  }
822
1357
  // ---- SaverInstance ----
823
1358
  setPaused(paused) {
@@ -832,12 +1367,22 @@ var GlobeInstance = class {
832
1367
  resize(width, height, dpr) {
833
1368
  this.w = width;
834
1369
  this.h = height;
835
- if (dpr !== void 0) this.ctx.dpr = dpr;
1370
+ if (dpr !== void 0) this.ctxSaver.dpr = dpr;
836
1371
  this.sizeCanvas();
837
- this.cx = Math.min(Math.max(this.cx, RADIUS), Math.max(RADIUS, this.w - RADIUS));
838
- this.cy = Math.min(Math.max(this.cy, RADIUS), Math.max(RADIUS, this.h - RADIUS));
839
1372
  if (this.paused) this.renderStill();
840
1373
  }
1374
+ applyTrack(track) {
1375
+ this.track = track;
1376
+ if (this.paused) this.renderStill();
1377
+ }
1378
+ /** Pure, frame-addressable render at logical time `t` (ms). Position and
1379
+ * rotation are both closed-form in `t` — no accumulated state — so seeking
1380
+ * to any `t`, in any order, reproduces the same frame. */
1381
+ renderFrame(t, _seed) {
1382
+ this.t = t;
1383
+ this.applyParams(t);
1384
+ this.render(t);
1385
+ }
841
1386
  dispose() {
842
1387
  this.stop();
843
1388
  if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
@@ -847,11 +1392,31 @@ var globe = {
847
1392
  manifest: globeManifest,
848
1393
  mount: (ctx) => new GlobeInstance(ctx)
849
1394
  };
1395
+ var globeDemoTrack = {
1396
+ program: "globe",
1397
+ seed: 3,
1398
+ duration: 12e3,
1399
+ loop: true,
1400
+ deltas: [
1401
+ { t: 0, path: "spin", value: 0.6 },
1402
+ { t: 4e3, path: "spin", value: 2.2, ease: "smooth" },
1403
+ { t: 8e3, path: "spin", value: 0.6, ease: "smooth" },
1404
+ { t: 12e3, path: "spin", value: 0.6 },
1405
+ { t: 0, path: "bounce", value: 1 },
1406
+ { t: 5e3, path: "bounce", value: 0.1, ease: "smooth" },
1407
+ { t: 9e3, path: "bounce", value: 1, ease: "smooth" },
1408
+ { t: 12e3, path: "bounce", value: 1 },
1409
+ { t: 0, path: "glow", value: 0.25 },
1410
+ { t: 6e3, path: "glow", value: 0.9, ease: "smooth" },
1411
+ { t: 12e3, path: "glow", value: 0.25, ease: "smooth" }
1412
+ ]
1413
+ };
850
1414
 
851
1415
  // src/spotlight.ts
852
1416
  var spotlightManifest = {
853
1417
  id: "spotlight",
854
1418
  label: "Spotlight",
1419
+ timeModel: "closed-form",
855
1420
  passthrough: true,
856
1421
  minBackend: "canvas2d",
857
1422
  costTier: "low",
@@ -906,12 +1471,12 @@ var SpotlightInstance = class {
906
1471
  this.c2d.setTransform(dpr, 0, 0, dpr, 0, 0);
907
1472
  }
908
1473
  centre() {
909
- const tri2 = (t, period) => {
1474
+ const tri3 = (t, period) => {
910
1475
  const p = (t % (period * 2) + period * 2) % (period * 2);
911
1476
  return p < period ? p / period : 2 - p / period;
912
1477
  };
913
- const kx = tri2(this.clock, SPEED_X);
914
- const ky = tri2(this.clock, SPEED_Y);
1478
+ const kx = tri3(this.clock, SPEED_X);
1479
+ const ky = tri3(this.clock, SPEED_Y);
915
1480
  const x = HOLE_RADIUS + kx * (this.w - HOLE_RADIUS * 2);
916
1481
  const y = HOLE_RADIUS + ky * (this.h - HOLE_RADIUS * 2);
917
1482
  return [x, y];
@@ -988,14 +1553,33 @@ var spotlight = {
988
1553
  };
989
1554
 
990
1555
  // src/mystify.ts
1556
+ import {
1557
+ sampleTrack as sampleTrack4,
1558
+ defaultParams as defaultParams4
1559
+ } from "@idle-screens/core";
1560
+ var PARAM_SPACE4 = {
1561
+ /** How many polygons perform. Identities are stable per slot (seeded
1562
+ * forks), so steering the count never re-rolls the visible shapes. */
1563
+ shapes: { type: "number", default: 3, min: 1, max: 6 },
1564
+ /** Motion rate multiplier — integrated, so live changes never teleport. */
1565
+ speed: { type: "number", default: 1, min: 0.25, max: 2.5, ease: "smooth" },
1566
+ /** Trail persistence: 0 = crisp outline, 1 = long dreamy ribbons. */
1567
+ trail: { type: "number", default: 0.55, min: 0, max: 1, ease: "smooth" },
1568
+ /** Stroke width, px. */
1569
+ width: { type: "number", default: 2, min: 1, max: 5, ease: "smooth" },
1570
+ /** Additive hue rotation over each shape's seeded base hue, degrees. */
1571
+ hueShift: { type: "number", default: 0, min: 0, max: 360, ease: "smooth" }
1572
+ };
991
1573
  var mystifyManifest = {
992
1574
  id: "mystify",
993
1575
  label: "Mystify",
1576
+ timeModel: "closed-form",
994
1577
  passthrough: false,
995
1578
  minBackend: "canvas2d",
996
1579
  costTier: "low",
997
1580
  motionIntensity: "moderate",
998
1581
  reducedMotionFallback: "static",
1582
+ paramSpace: PARAM_SPACE4,
999
1583
  attribution: {
1000
1584
  source: 'Windows "Mystify" \u2014 concept only; clean-room reimplementation',
1001
1585
  license: "MIT (original code)"
@@ -1003,18 +1587,39 @@ var mystifyManifest = {
1003
1587
  a11y: { flashSafe: true, notes: "Slow-fade polygon trails on black; no strobing." },
1004
1588
  workerReady: true
1005
1589
  };
1006
- var SHAPE_COUNT = 3;
1007
- var TRAIL_ALPHA = 0.12;
1008
- var MystifyInstance = class {
1590
+ var MAX_SHAPES = 6;
1591
+ var GHOST_MS = 25;
1592
+ var PHASE_BUCKET_MS = 250;
1593
+ var fold = (p, span) => {
1594
+ const period = 2 * span;
1595
+ const m = (p % period + period) % period;
1596
+ return m <= span ? m : period - m;
1597
+ };
1598
+ var MystifyInstance = class _MystifyInstance {
1009
1599
  ctxSaver;
1010
1600
  canvas;
1011
1601
  ctx;
1012
1602
  w = 0;
1013
1603
  h = 0;
1014
- shapes = [];
1604
+ shapes;
1605
+ track = null;
1606
+ baseParams = defaultParams4(PARAM_SPACE4);
1607
+ /** Append-only speed-integral caches, one slot per PHASE_BUCKET_MS. */
1608
+ phiPrefix = [0];
1609
+ phiSpeeds = [];
1015
1610
  frameId = null;
1016
- last = 0;
1017
1611
  paused = false;
1612
+ startT = 0;
1613
+ /** Logical time the next rAF origin resumes from.
1614
+ *
1615
+ * `start()` re-anchors `startT` to the next frame's timestamp, so on its own
1616
+ * `now - startT` always begins at zero. Mount wants that; resuming from a
1617
+ * pause does not — without carrying the frozen `t` forward, every
1618
+ * pause/resume (and every reduced-motion toggle) snaps the scene back to its
1619
+ * opening frame and restarts any applied control track. Set only in
1620
+ * `setPaused(false)`, so first mount still starts at 0. */
1621
+ resumeFrom = 0;
1622
+ t = 0;
1018
1623
  constructor(ctx) {
1019
1624
  this.ctxSaver = ctx;
1020
1625
  let canvas;
@@ -1034,31 +1639,28 @@ var MystifyInstance = class {
1034
1639
  this.w = ctx.width;
1035
1640
  this.h = ctx.height;
1036
1641
  this.sizeCanvas();
1037
- this.shapes = this.buildShapes(ctx.rng);
1038
- this.clearFull();
1642
+ this.shapes = _MystifyInstance.buildShapes(ctx.rng);
1039
1643
  this.paused = ctx.reducedMotion;
1040
1644
  if (this.paused) this.renderStill();
1041
1645
  else this.start();
1042
1646
  }
1043
- buildShapes(rng) {
1647
+ /** The full identity pool, one fork per slot — count-independent. */
1648
+ static buildShapes(rng) {
1044
1649
  const out = [];
1045
- for (let s = 0; s < SHAPE_COUNT; s++) {
1046
- const vertCount = rng.int(3, 5);
1047
- const hue = rng.int(0, 359);
1048
- const verts = [];
1650
+ for (let s = 0; s < MAX_SHAPES; s++) {
1651
+ const f = rng.fork(61469 + s);
1652
+ const vertCount = f.int(3, 5);
1653
+ const hue = f.int(0, 359);
1654
+ const id = { hue, fx: [], fy: [], vx: [], vy: [] };
1049
1655
  for (let v = 0; v < vertCount; v++) {
1050
- const x = rng.range(this.w * 0.15, this.w * 0.85);
1051
- const y = rng.range(this.h * 0.15, this.h * 0.85);
1052
- const dir = rng.range(0, Math.PI * 2);
1053
- const speed = rng.range(70, 150);
1054
- verts.push({
1055
- x,
1056
- y,
1057
- vx: Math.cos(dir) * speed,
1058
- vy: Math.sin(dir) * speed
1059
- });
1656
+ id.fx.push(f.range(0.15, 0.85));
1657
+ id.fy.push(f.range(0.15, 0.85));
1658
+ const dir = f.range(0, Math.PI * 2);
1659
+ const speed = f.range(70, 150);
1660
+ id.vx.push(Math.cos(dir) * speed);
1661
+ id.vy.push(Math.sin(dir) * speed);
1060
1662
  }
1061
- out.push({ hue, verts });
1663
+ out.push(id);
1062
1664
  }
1063
1665
  return out;
1064
1666
  }
@@ -1068,13 +1670,40 @@ var MystifyInstance = class {
1068
1670
  this.canvas.height = Math.max(1, Math.round(this.h * dpr));
1069
1671
  this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1070
1672
  }
1071
- clearFull() {
1072
- this.ctx.fillStyle = "#000";
1073
- this.ctx.fillRect(0, 0, this.w, this.h);
1673
+ /** Params at `t` — track-driven when applied, defaults otherwise. */
1674
+ paramsAt(t) {
1675
+ if (!this.track) return this.baseParams;
1676
+ const p = sampleTrack4(PARAM_SPACE4, this.track, t);
1677
+ const out = { ...this.baseParams };
1678
+ for (const k of Object.keys(PARAM_SPACE4)) {
1679
+ const v = p[k];
1680
+ if (typeof v === "number") out[k] = v;
1681
+ }
1682
+ return out;
1074
1683
  }
1684
+ /** Speed the phase integral uses across one bucket (sampled at its centre). */
1685
+ bucketSpeed(b) {
1686
+ let s = this.phiSpeeds[b];
1687
+ if (s === void 0) {
1688
+ for (let k = this.phiSpeeds.length; k <= b; k++) {
1689
+ this.phiSpeeds[k] = this.paramsAt(k * PHASE_BUCKET_MS + PHASE_BUCKET_MS / 2).speed;
1690
+ this.phiPrefix[k + 1] = this.phiPrefix[k] + this.phiSpeeds[k] * (PHASE_BUCKET_MS / 1e3);
1691
+ }
1692
+ s = this.phiSpeeds[b];
1693
+ }
1694
+ return s;
1695
+ }
1696
+ /** ∫ speed dt in seconds — continuous in t, pure (prefix grounds at 0). */
1697
+ phaseAt(t) {
1698
+ if (t <= 0) return 0;
1699
+ const b = Math.floor(t / PHASE_BUCKET_MS);
1700
+ const s = this.bucketSpeed(b);
1701
+ return this.phiPrefix[b] + s * ((t - b * PHASE_BUCKET_MS) / 1e3);
1702
+ }
1703
+ // ---- loop ----
1075
1704
  start() {
1076
1705
  if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
1077
- this.last = 0;
1706
+ this.startT = 0;
1078
1707
  this.frameId = requestAnimationFrame((now) => this.loop(now));
1079
1708
  }
1080
1709
  stop() {
@@ -1085,66 +1714,58 @@ var MystifyInstance = class {
1085
1714
  }
1086
1715
  loop(now) {
1087
1716
  this.frameId = requestAnimationFrame((n) => this.loop(n));
1088
- if (this.last === 0) this.last = now;
1089
- const dt = Math.min(0.05, (now - this.last) / 1e3);
1090
- this.last = now;
1091
- this.update(dt);
1092
- this.render();
1717
+ if (this.startT === 0) this.startT = now;
1718
+ this.renderFrame(now - this.startT + this.resumeFrom, this.ctxSaver.seed);
1093
1719
  }
1094
- update(dt) {
1095
- for (const shape of this.shapes) {
1096
- for (const v of shape.verts) {
1097
- v.x += v.vx * dt;
1098
- v.y += v.vy * dt;
1099
- if (v.x <= 0) {
1100
- v.x = 0;
1101
- v.vx = Math.abs(v.vx);
1102
- } else if (v.x >= this.w) {
1103
- v.x = this.w;
1104
- v.vx = -Math.abs(v.vx);
1105
- }
1106
- if (v.y <= 0) {
1107
- v.y = 0;
1108
- v.vy = Math.abs(v.vy);
1109
- } else if (v.y >= this.h) {
1110
- v.y = this.h;
1111
- v.vy = -Math.abs(v.vy);
1112
- }
1113
- }
1720
+ renderStill() {
1721
+ const t = this.t === 0 ? 1200 : this.t;
1722
+ this.renderFrame(t, this.ctxSaver.seed);
1723
+ }
1724
+ // ---- draw ----
1725
+ strokeShape(id, phi, alpha, width, hueShift) {
1726
+ const ctx = this.ctx;
1727
+ const sw = Math.max(1, this.w);
1728
+ const sh = Math.max(1, this.h);
1729
+ ctx.strokeStyle = `hsla(${(id.hue + hueShift) % 360}, 90%, 62%, ${alpha.toFixed(3)})`;
1730
+ ctx.lineWidth = width;
1731
+ ctx.beginPath();
1732
+ for (let v = 0; v < id.fx.length; v++) {
1733
+ const x = fold(id.fx[v] * sw + id.vx[v] * phi, sw);
1734
+ const y = fold(id.fy[v] * sh + id.vy[v] * phi, sh);
1735
+ if (v === 0) ctx.moveTo(x, y);
1736
+ else ctx.lineTo(x, y);
1114
1737
  }
1738
+ ctx.closePath();
1739
+ ctx.stroke();
1115
1740
  }
1116
- drawShapes() {
1741
+ /** Pure, frame-addressable render: black field, ghost trail oldest-first,
1742
+ * live outline last. Everything derives from (t, seed, params-at-t). */
1743
+ renderFrame(t, _seed) {
1744
+ this.t = t;
1745
+ const p = this.paramsAt(t);
1117
1746
  const ctx = this.ctx;
1747
+ ctx.fillStyle = "#000";
1748
+ ctx.fillRect(0, 0, this.w, this.h);
1118
1749
  ctx.lineCap = "round";
1119
1750
  ctx.lineJoin = "round";
1120
- for (const shape of this.shapes) {
1121
- const { verts } = shape;
1122
- if (verts.length < 2) continue;
1123
- ctx.strokeStyle = `hsla(${shape.hue}, 90%, 62%, 0.92)`;
1124
- ctx.lineWidth = 2;
1125
- ctx.beginPath();
1126
- ctx.moveTo(verts[0].x, verts[0].y);
1127
- for (let i = 1; i < verts.length; i++) ctx.lineTo(verts[i].x, verts[i].y);
1128
- ctx.closePath();
1129
- ctx.stroke();
1751
+ const n = Math.max(1, Math.min(MAX_SHAPES, Math.round(p.shapes)));
1752
+ const decay = 0.68 + p.trail * 0.29;
1753
+ const ghosts = Math.min(48, Math.max(1, Math.ceil(Math.log(0.03 / 0.92) / Math.log(decay))));
1754
+ for (let k = ghosts - 1; k >= 0; k--) {
1755
+ const tk = t - k * GHOST_MS;
1756
+ if (tk < 0) continue;
1757
+ const phi = this.phaseAt(tk);
1758
+ const alpha = 0.92 * Math.pow(decay, k);
1759
+ for (let s = 0; s < n; s++) this.strokeShape(this.shapes[s], phi, alpha, p.width, p.hueShift);
1130
1760
  }
1131
1761
  }
1132
- render() {
1133
- this.ctx.fillStyle = `rgba(0,0,0,${TRAIL_ALPHA})`;
1134
- this.ctx.fillRect(0, 0, this.w, this.h);
1135
- this.drawShapes();
1136
- }
1137
- renderStill() {
1138
- this.clearFull();
1139
- this.drawShapes();
1140
- }
1141
1762
  setPaused(paused) {
1142
1763
  this.paused = paused;
1143
1764
  if (paused) {
1144
1765
  this.stop();
1145
1766
  this.renderStill();
1146
1767
  } else {
1147
- this.clearFull();
1768
+ this.resumeFrom = this.t;
1148
1769
  this.start();
1149
1770
  }
1150
1771
  }
@@ -1153,14 +1774,13 @@ var MystifyInstance = class {
1153
1774
  this.h = height;
1154
1775
  if (dpr !== void 0) this.ctxSaver.dpr = dpr;
1155
1776
  this.sizeCanvas();
1156
- for (const shape of this.shapes) {
1157
- for (const v of shape.verts) {
1158
- v.x = Math.min(Math.max(v.x, 0), this.w);
1159
- v.y = Math.min(Math.max(v.y, 0), this.h);
1160
- }
1161
- }
1162
1777
  if (this.paused) this.renderStill();
1163
- else this.clearFull();
1778
+ }
1779
+ applyTrack(track) {
1780
+ this.track = track;
1781
+ this.phiPrefix = [0];
1782
+ this.phiSpeeds = [];
1783
+ if (this.paused) this.renderStill();
1164
1784
  }
1165
1785
  dispose() {
1166
1786
  this.stop();
@@ -1173,23 +1793,61 @@ var mystify = {
1173
1793
  manifest: mystifyManifest,
1174
1794
  mount: (ctx) => new MystifyInstance(ctx)
1175
1795
  };
1796
+ var mystifyDemoTrack = {
1797
+ program: "mystify",
1798
+ seed: 5,
1799
+ duration: 24e3,
1800
+ loop: true,
1801
+ deltas: [
1802
+ { t: 0, path: "shapes", value: 3 },
1803
+ { t: 1e4, path: "shapes", value: 6 },
1804
+ { t: 2e4, path: "shapes", value: 3 },
1805
+ { t: 0, path: "speed", value: 0.8 },
1806
+ { t: 12e3, path: "speed", value: 2, ease: "smooth" },
1807
+ { t: 24e3, path: "speed", value: 0.8, ease: "smooth" },
1808
+ { t: 0, path: "trail", value: 0.45 },
1809
+ { t: 12e3, path: "trail", value: 0.85, ease: "smooth" },
1810
+ { t: 24e3, path: "trail", value: 0.45, ease: "smooth" },
1811
+ { t: 0, path: "hueShift", value: 0 },
1812
+ { t: 24e3, path: "hueShift", value: 300, ease: "smooth" }
1813
+ ]
1814
+ };
1176
1815
 
1177
1816
  // src/pipes.ts
1817
+ import {
1818
+ sampleTrack as sampleTrack5,
1819
+ defaultParams as defaultParams5
1820
+ } from "@idle-screens/core";
1821
+ var PARAM_SPACE5 = {
1822
+ /** Growth speed multiplier. Sampled at each epoch's start — a run keeps its
1823
+ * pace for its whole life, so the step clock stays a pure function of t. */
1824
+ tempo: { type: "number", default: 1, min: 0.3, max: 3, ease: "smooth" },
1825
+ /** Fraction of the grid a run fills before the screen clears. Sampled per
1826
+ * epoch, like every param here. */
1827
+ density: { type: "number", default: 0.65, min: 0.3, max: 0.9, ease: "smooth" },
1828
+ /** Grid pitch, px. Small cells read as circuitry; large ones as plumbing. */
1829
+ cell: { type: "number", default: 20, min: 10, max: 40, ease: "smooth" },
1830
+ /** Chance a pipe keeps its heading when it can — the classic bias is 0.65.
1831
+ * Low values grow twisty mazes; high values long straight runs. */
1832
+ straightness: { type: "number", default: 0.65, min: 0, max: 0.95, ease: "smooth" },
1833
+ /** Pipe stroke width, px. */
1834
+ thickness: { type: "number", default: 8, min: 3, max: 14, ease: "smooth" }
1835
+ };
1178
1836
  var pipesManifest = {
1179
1837
  id: "pipes",
1180
1838
  label: "Pipes",
1839
+ timeModel: "closed-form",
1181
1840
  passthrough: false,
1182
1841
  minBackend: "canvas2d",
1183
1842
  costTier: "low",
1184
1843
  motionIntensity: "moderate",
1185
1844
  reducedMotionFallback: "static",
1845
+ paramSpace: PARAM_SPACE5,
1186
1846
  a11y: { flashSafe: true },
1187
1847
  workerReady: true
1188
1848
  };
1189
- var CELL = 20;
1190
- var PIPE_WIDTH = 8;
1191
- var STEPS_PER_FRAME = 3;
1192
- var FILL_THRESHOLD = 0.65;
1849
+ var STEP_MS = 1e3 / 180;
1850
+ var PLAN_CACHE = 4;
1193
1851
  var PALETTE = ["#c0392b", "#2980b9", "#27ae60", "#f39c12", "#8e44ad", "#d4a259", "#7f8c8d"];
1194
1852
  var DX = { 0: 1, 1: 0, 2: -1, 3: 0 };
1195
1853
  var DY = { 0: 0, 1: 1, 2: 0, 3: -1 };
@@ -1199,17 +1857,31 @@ var PipesInstance = class {
1199
1857
  ctx;
1200
1858
  w = 0;
1201
1859
  h = 0;
1202
- cols = 0;
1203
- rows = 0;
1204
- grid = [];
1205
- filled = 0;
1206
- pipe = null;
1207
- rng;
1860
+ /** Prefix-sum of epoch start times (ms); index i = epoch i's start. */
1861
+ epochStarts = [];
1862
+ /** Step counts per compiled-at-least-once epoch (start + count = summary). */
1863
+ epochSteps = [];
1864
+ plans = /* @__PURE__ */ new Map();
1865
+ track = null;
1866
+ baseParams = defaultParams5(PARAM_SPACE5);
1867
+ /** What the canvas currently shows: epoch index + steps drawn. -1 = dirty. */
1868
+ paintedEpoch = -1;
1869
+ paintedSteps = 0;
1208
1870
  frameId = null;
1209
1871
  paused = false;
1872
+ startT = 0;
1873
+ /** Logical time the next rAF origin resumes from.
1874
+ *
1875
+ * `start()` re-anchors `startT` to the next frame's timestamp, so on its own
1876
+ * `now - startT` always begins at zero. Mount wants that; resuming from a
1877
+ * pause does not — without carrying the frozen `t` forward, every
1878
+ * pause/resume (and every reduced-motion toggle) snaps the scene back to its
1879
+ * opening frame and restarts any applied control track. Set only in
1880
+ * `setPaused(false)`, so first mount still starts at 0. */
1881
+ resumeFrom = 0;
1882
+ t = 0;
1210
1883
  constructor(ctx) {
1211
1884
  this.ctxSaver = ctx;
1212
- this.rng = ctx.rng;
1213
1885
  let canvas;
1214
1886
  if (ctx.surface) {
1215
1887
  canvas = ctx.surface;
@@ -1239,121 +1911,171 @@ var PipesInstance = class {
1239
1911
  this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1240
1912
  }
1241
1913
  rebuild() {
1242
- this.cols = Math.max(2, Math.floor(this.w / CELL));
1243
- this.rows = Math.max(2, Math.floor(this.h / CELL));
1244
- this.grid = new Array(this.cols * this.rows).fill(false);
1245
- this.filled = 0;
1246
- this.pipe = null;
1914
+ this.epochStarts = [];
1915
+ this.epochSteps = [];
1916
+ this.plans.clear();
1917
+ this.paintedEpoch = -1;
1918
+ this.paintedSteps = 0;
1247
1919
  this.paintBackground();
1248
1920
  }
1249
1921
  paintBackground() {
1250
1922
  this.ctx.fillStyle = "#111";
1251
1923
  this.ctx.fillRect(0, 0, this.w, this.h);
1252
1924
  }
1253
- idx(col, row) {
1254
- return row * this.cols + col;
1255
- }
1256
- inBounds(col, row) {
1257
- return col >= 0 && col < this.cols && row >= 0 && row < this.rows;
1258
- }
1259
- spawnPipe() {
1260
- const empty = [];
1261
- for (let i = 0; i < this.grid.length; i++) {
1262
- if (!this.grid[i]) empty.push(i);
1925
+ // ---- the compiled plan ----
1926
+ /** Params at `t` — track-driven when a track is applied, defaults otherwise. */
1927
+ paramsAt(t) {
1928
+ if (!this.track) return this.baseParams;
1929
+ const p = sampleTrack5(PARAM_SPACE5, this.track, t);
1930
+ const out = { ...this.baseParams };
1931
+ for (const k of Object.keys(PARAM_SPACE5)) {
1932
+ const v = p[k];
1933
+ if (typeof v === "number") out[k] = v;
1263
1934
  }
1264
- if (empty.length === 0) {
1265
- this.clearGrid();
1266
- return;
1935
+ return out;
1936
+ }
1937
+ /**
1938
+ * Compile one epoch's full growth history. Pure in (seed, epoch, cols,
1939
+ * rows, params-at-epoch-start): the rng is an epoch-keyed fork, and the
1940
+ * walk is exactly the old per-frame algorithm — spawn on an empty cell,
1941
+ * grow with a 0.65 bias to continue straight, die when boxed in, stop at
1942
+ * the fill threshold. tempo/density are sampled once at the epoch's start,
1943
+ * so a run keeps its pace and appetite for its whole life.
1944
+ */
1945
+ compileEpoch(epoch, start) {
1946
+ const p = this.paramsAt(start);
1947
+ const rng = this.ctxSaver.rng.fork(596453 + epoch * 7919);
1948
+ const cell = Math.max(6, p.cell);
1949
+ const cols = Math.max(2, Math.floor(this.w / cell));
1950
+ const rows = Math.max(2, Math.floor(this.h / cell));
1951
+ const size = cols * rows;
1952
+ const grid = new Uint8Array(size);
1953
+ let filled = 0;
1954
+ let pipe = null;
1955
+ const steps = [];
1956
+ while (filled / size <= p.density) {
1957
+ if (!pipe) {
1958
+ const empty = [];
1959
+ for (let i = 0; i < size; i++) if (!grid[i]) empty.push(i);
1960
+ if (empty.length === 0) break;
1961
+ const at = rng.pick(empty);
1962
+ const col = at % cols;
1963
+ const row = Math.floor(at / cols);
1964
+ pipe = { col, row, dir: rng.int(0, 3), color: PALETTE.indexOf(rng.pick(PALETTE)) };
1965
+ grid[at] = 1;
1966
+ filled++;
1967
+ steps.push({ kind: "spawn", col, row, c2: -1, r2: -1, turn: false, color: pipe.color });
1968
+ continue;
1969
+ }
1970
+ const candidates = [];
1971
+ for (let d = 0; d < 4; d++) {
1972
+ const nc2 = pipe.col + DX[d];
1973
+ const nr2 = pipe.row + DY[d];
1974
+ if (nc2 >= 0 && nc2 < cols && nr2 >= 0 && nr2 < rows && !grid[nr2 * cols + nc2]) {
1975
+ candidates.push(d);
1976
+ }
1977
+ }
1978
+ const pool = candidates.includes(pipe.dir) && rng.next() < p.straightness ? [pipe.dir] : candidates;
1979
+ if (pool.length === 0) {
1980
+ pipe = null;
1981
+ steps.push({ kind: "end", col: -1, row: -1, c2: -1, r2: -1, turn: false, color: -1 });
1982
+ continue;
1983
+ }
1984
+ const newDir = rng.pick(pool);
1985
+ const turn = newDir !== pipe.dir;
1986
+ const nc = pipe.col + DX[newDir];
1987
+ const nr = pipe.row + DY[newDir];
1988
+ steps.push({ kind: "seg", col: pipe.col, row: pipe.row, c2: nc, r2: nr, turn, color: pipe.color });
1989
+ pipe.col = nc;
1990
+ pipe.row = nr;
1991
+ pipe.dir = newDir;
1992
+ grid[nr * cols + nc] = 1;
1993
+ filled++;
1267
1994
  }
1268
- const cell = this.rng.pick(empty);
1269
- const col = cell % this.cols;
1270
- const row = Math.floor(cell / this.cols);
1271
- this.pipe = {
1272
- col,
1273
- row,
1274
- dir: this.rng.int(0, 3),
1275
- color: this.rng.pick(PALETTE)
1995
+ return {
1996
+ steps,
1997
+ stepMs: STEP_MS / Math.max(0.05, p.tempo),
1998
+ cell,
1999
+ thickness: Math.min(p.thickness, cell * 0.7),
2000
+ cols,
2001
+ rows
1276
2002
  };
1277
- this.grid[cell] = true;
1278
- this.filled++;
1279
- this.drawJoint(col, row, this.pipe.color);
1280
- }
1281
- clearGrid() {
1282
- this.grid.fill(false);
1283
- this.filled = 0;
1284
- this.pipe = null;
1285
- this.paintBackground();
1286
2003
  }
1287
- growStep() {
1288
- if (this.filled / this.grid.length > FILL_THRESHOLD) {
1289
- this.clearGrid();
1290
- return;
1291
- }
1292
- if (!this.pipe) {
1293
- this.spawnPipe();
1294
- return;
1295
- }
1296
- const candidates = this.getCandidates(this.pipe);
1297
- if (candidates.length === 0) {
1298
- this.pipe = null;
1299
- return;
1300
- }
1301
- const oldCol = this.pipe.col;
1302
- const oldRow = this.pipe.row;
1303
- const oldDir = this.pipe.dir;
1304
- const newDir = this.rng.pick(candidates);
1305
- this.pipe.dir = newDir;
1306
- const nc = oldCol + DX[newDir];
1307
- const nr = oldRow + DY[newDir];
1308
- this.drawSegment(oldCol, oldRow, nc, nr, this.pipe.color);
1309
- if (newDir !== oldDir) {
1310
- this.drawJoint(oldCol, oldRow, this.pipe.color);
1311
- }
1312
- this.pipe.col = nc;
1313
- this.pipe.row = nr;
1314
- this.grid[this.idx(nc, nr)] = true;
1315
- this.filled++;
1316
- }
1317
- getCandidates(pipe) {
1318
- const out = [];
1319
- for (let d = 0; d < 4; d++) {
1320
- const nc = pipe.col + DX[d];
1321
- const nr = pipe.row + DY[d];
1322
- if (this.inBounds(nc, nr) && !this.grid[this.idx(nc, nr)]) {
1323
- out.push(d);
2004
+ /** The plan for an epoch, via the small cache. Recompiles are bit-identical. */
2005
+ planFor(epoch, start) {
2006
+ let plan = this.plans.get(epoch);
2007
+ if (!plan) {
2008
+ plan = this.compileEpoch(epoch, start);
2009
+ this.plans.set(epoch, plan);
2010
+ if (this.plans.size > PLAN_CACHE) {
2011
+ let worst = epoch;
2012
+ let worstD = -1;
2013
+ for (const k of this.plans.keys()) {
2014
+ const d = Math.abs(k - epoch);
2015
+ if (d > worstD) {
2016
+ worstD = d;
2017
+ worst = k;
2018
+ }
2019
+ }
2020
+ this.plans.delete(worst);
1324
2021
  }
1325
2022
  }
1326
- if (out.includes(pipe.dir) && this.rng.next() < 0.65) {
1327
- return [pipe.dir];
2023
+ if (this.epochSteps.length === epoch) this.epochSteps.push(plan.steps.length);
2024
+ return plan;
2025
+ }
2026
+ /** Epoch containing `t`, extending the prefix sum as needed. */
2027
+ epochAt(t) {
2028
+ if (this.epochStarts.length === 0) this.epochStarts.push(0);
2029
+ let e = 0;
2030
+ for (e = this.epochStarts.length - 1; e > 0; e--) {
2031
+ if (t >= this.epochStarts[e]) break;
2032
+ }
2033
+ for (; ; ) {
2034
+ const start = this.epochStarts[e];
2035
+ const plan = this.planFor(e, start);
2036
+ const dur = Math.max(1, plan.steps.length) * plan.stepMs;
2037
+ if (t < start + dur) return { epoch: e, start, plan };
2038
+ if (this.epochStarts.length === e + 1) this.epochStarts.push(start + dur);
2039
+ e++;
1328
2040
  }
1329
- return out;
1330
- }
1331
- cellCenter(col, row) {
1332
- return [col * CELL + CELL / 2, row * CELL + CELL / 2];
1333
2041
  }
1334
- drawSegment(c1, r1, c2, r2, color) {
1335
- const [x1, y1] = this.cellCenter(c1, r1);
1336
- const [x2, y2] = this.cellCenter(c2, r2);
2042
+ // ---- drawing (identical marks to the accumulative version; geometry from
2043
+ // the epoch's own plan, since cell/thickness are epoch-sampled params) ----
2044
+ drawSegment(plan, c1, r1, c2, r2, color) {
2045
+ const half = plan.cell / 2;
1337
2046
  const ctx = this.ctx;
1338
2047
  ctx.strokeStyle = color;
1339
- ctx.lineWidth = PIPE_WIDTH;
2048
+ ctx.lineWidth = plan.thickness;
1340
2049
  ctx.lineCap = "round";
1341
2050
  ctx.beginPath();
1342
- ctx.moveTo(x1, y1);
1343
- ctx.lineTo(x2, y2);
2051
+ ctx.moveTo(c1 * plan.cell + half, r1 * plan.cell + half);
2052
+ ctx.lineTo(c2 * plan.cell + half, r2 * plan.cell + half);
1344
2053
  ctx.stroke();
1345
2054
  }
1346
- drawJoint(col, row, color) {
1347
- const [x, y] = this.cellCenter(col, row);
2055
+ drawJoint(plan, col, row, color) {
2056
+ const half = plan.cell / 2;
1348
2057
  const ctx = this.ctx;
1349
2058
  ctx.fillStyle = color;
1350
2059
  ctx.beginPath();
1351
- ctx.arc(x, y, PIPE_WIDTH * 0.65, 0, Math.PI * 2);
2060
+ ctx.arc(col * plan.cell + half, row * plan.cell + half, plan.thickness * 0.65, 0, Math.PI * 2);
1352
2061
  ctx.fill();
1353
2062
  }
2063
+ drawSteps(plan, from, to) {
2064
+ for (let i = from; i < to; i++) {
2065
+ const s = plan.steps[i];
2066
+ if (s.kind === "spawn") {
2067
+ this.drawJoint(plan, s.col, s.row, PALETTE[s.color]);
2068
+ } else if (s.kind === "seg") {
2069
+ this.drawSegment(plan, s.col, s.row, s.c2, s.r2, PALETTE[s.color]);
2070
+ if (s.turn) this.drawJoint(plan, s.col, s.row, PALETTE[s.color]);
2071
+ }
2072
+ }
2073
+ }
2074
+ // ---- loop ----
1354
2075
  start() {
1355
2076
  if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
1356
- this.loop();
2077
+ this.startT = 0;
2078
+ this.frameId = requestAnimationFrame((now) => this.loop(now));
1357
2079
  }
1358
2080
  stop() {
1359
2081
  if (this.frameId !== null) {
@@ -1361,22 +2083,53 @@ var PipesInstance = class {
1361
2083
  this.frameId = null;
1362
2084
  }
1363
2085
  }
1364
- loop() {
1365
- this.frameId = requestAnimationFrame(() => this.loop());
1366
- for (let i = 0; i < STEPS_PER_FRAME; i++) this.growStep();
2086
+ loop(now) {
2087
+ this.frameId = requestAnimationFrame((n) => this.loop(n));
2088
+ if (this.startT === 0) this.startT = now;
2089
+ this.renderFrame(now - this.startT + this.resumeFrom, this.ctxSaver.seed);
1367
2090
  }
1368
2091
  renderStill() {
1369
- this.rebuild();
1370
- for (let i = 0; i < 80; i++) this.growStep();
2092
+ const t = this.t === 0 ? 80 * STEP_MS : this.t;
2093
+ this.renderFrame(t, this.ctxSaver.seed);
2094
+ }
2095
+ /**
2096
+ * Pure, frame-addressable render: the canvas after this call is a function
2097
+ * of (t, seed, size) only. Forward motion within an epoch appends new
2098
+ * steps; anything else repaints and replays the prefix.
2099
+ */
2100
+ renderFrame(t, _seed) {
2101
+ this.t = t;
2102
+ const { epoch, start, plan } = this.epochAt(Math.max(0, t));
2103
+ const stepsDone = Math.min(plan.steps.length, Math.floor((t - start) / plan.stepMs));
2104
+ if (epoch === this.paintedEpoch && stepsDone >= this.paintedSteps) {
2105
+ this.drawSteps(plan, this.paintedSteps, stepsDone);
2106
+ } else {
2107
+ this.paintBackground();
2108
+ this.drawSteps(plan, 0, stepsDone);
2109
+ }
2110
+ this.paintedEpoch = epoch;
2111
+ this.paintedSteps = stepsDone;
1371
2112
  }
1372
2113
  setPaused(paused) {
1373
2114
  this.paused = paused;
1374
2115
  if (paused) {
1375
2116
  this.stop();
2117
+ this.renderStill();
1376
2118
  } else {
2119
+ this.resumeFrom = this.t;
1377
2120
  this.start();
1378
2121
  }
1379
2122
  }
2123
+ applyTrack(track) {
2124
+ this.track = track;
2125
+ this.epochStarts = [];
2126
+ this.epochSteps = [];
2127
+ this.plans.clear();
2128
+ this.paintedEpoch = -1;
2129
+ this.paintedSteps = 0;
2130
+ this.paintBackground();
2131
+ if (this.paused) this.renderStill();
2132
+ }
1380
2133
  resize(width, height, dpr) {
1381
2134
  this.w = width;
1382
2135
  this.h = height;
@@ -1394,34 +2147,123 @@ var pipes = {
1394
2147
  manifest: pipesManifest,
1395
2148
  mount: (ctx) => new PipesInstance(ctx)
1396
2149
  };
2150
+ var pipesDemoTrack = {
2151
+ program: "pipes",
2152
+ seed: 7,
2153
+ duration: 3e4,
2154
+ loop: true,
2155
+ deltas: [
2156
+ { t: 0, path: "tempo", value: 0.8 },
2157
+ { t: 15e3, path: "tempo", value: 2.4, ease: "smooth" },
2158
+ { t: 3e4, path: "tempo", value: 0.8, ease: "smooth" },
2159
+ { t: 0, path: "density", value: 0.55 },
2160
+ { t: 15e3, path: "density", value: 0.8, ease: "smooth" },
2161
+ { t: 3e4, path: "density", value: 0.55, ease: "smooth" }
2162
+ ]
2163
+ };
1397
2164
 
1398
2165
  // src/flurry.ts
2166
+ import {
2167
+ sampleTrack as sampleTrack6,
2168
+ defaultParams as defaultParams6
2169
+ } from "@idle-screens/core";
2170
+ var STREAM_COUNT = 5;
2171
+ var PARTICLES_PER_ARM = 56;
2172
+ var BASE_RADIUS = 6;
2173
+ var STILL_T = 6e3;
2174
+ var TRAIL_FRAC_MIN = 0.12;
2175
+ var TRAIL_FRAC_MAX = 0.42;
2176
+ var TAIL_SIZE_FLOOR = 0.45;
2177
+ var TAIL_ALPHA_POWER = 1.4;
2178
+ var PARAM_SPACE6 = {
2179
+ /** Arm count. Build-time: rebuilt (deterministically, from the same seeded
2180
+ * RNG forks) whenever this changes rather than smoothly animated — more
2181
+ * arms means re-deriving the whole cast, not interpolating between two. */
2182
+ arms: { type: "number", default: STREAM_COUNT, min: 3, max: 10, ease: "step" },
2183
+ speed: { type: "number", default: 1, min: 0.25, max: 3, ease: "smooth" },
2184
+ /** Additive glow strength: halo reach and brightness of each particle. */
2185
+ glow: { type: "number", default: 0.6, min: 0, max: 1.5, ease: "smooth" },
2186
+ /** How far back each arm's analytic trail reads, as a fraction of the
2187
+ * screen diagonal (0 = short stub, 1 = long flowing ribbon). */
2188
+ trail: { type: "number", default: 0.5, min: 0, max: 1, ease: "smooth" },
2189
+ /** Color scheme. 'spectrum' rotates hue continuously over ~20s — well
2190
+ * outside flash-safety limits, no strobing. */
2191
+ palette: { type: "enum", default: "aurora", options: ["aurora", "ember", "mono", "spectrum"] },
2192
+ size: { type: "number", default: 1, min: 0.5, max: 2, ease: "smooth" }
2193
+ };
1399
2194
  var flurryManifest = {
1400
2195
  id: "flurry",
1401
2196
  label: "Flurry",
2197
+ timeModel: "closed-form",
1402
2198
  passthrough: false,
1403
2199
  minBackend: "canvas2d",
1404
2200
  costTier: "low",
1405
2201
  motionIntensity: "calm",
1406
2202
  reducedMotionFallback: "static",
1407
- a11y: { flashSafe: true },
2203
+ paramSpace: PARAM_SPACE6,
2204
+ a11y: {
2205
+ flashSafe: true,
2206
+ notes: "Softly glowing arms drifting on black. The spectrum palette rotates hue over ~20s; no flashing."
2207
+ },
1408
2208
  workerReady: true
1409
2209
  };
1410
- var STREAM_COUNT = 5;
1411
- var PARTICLES_PER_STREAM = 12;
1412
- var TRAIL_ALPHA2 = 0.06;
1413
- var BASE_RADIUS = 6;
2210
+ function buildArm(rng) {
2211
+ return {
2212
+ freqX1: rng.range(0.3, 0.9),
2213
+ freqY1: rng.range(0.3, 0.9),
2214
+ freqX2: rng.range(0.1, 0.4),
2215
+ freqY2: rng.range(0.1, 0.4),
2216
+ freqX3: rng.range(0.04, 0.15),
2217
+ freqY3: rng.range(0.04, 0.15),
2218
+ phaseX: rng.range(0, Math.PI * 2),
2219
+ phaseY: rng.range(0, Math.PI * 2),
2220
+ ampX: rng.range(0.2, 0.4),
2221
+ ampY: rng.range(0.2, 0.4),
2222
+ armSpeed: rng.range(0.6, 1.2),
2223
+ hueJitter: rng.range(0, 1)
2224
+ };
2225
+ }
2226
+ function paletteHue(palette, arm, armIndex, armCount, t) {
2227
+ const spread = armCount > 0 ? armIndex / armCount : 0;
2228
+ switch (palette) {
2229
+ case "ember":
2230
+ return (8 + spread * 46 + arm.hueJitter * 10) % 360;
2231
+ // reds -> oranges -> yellows
2232
+ case "mono":
2233
+ return 201 + arm.hueJitter * 14;
2234
+ // narrow cool-blue band, 201-215
2235
+ case "spectrum": {
2236
+ const rotation = t / 2e4 * 360;
2237
+ return (arm.hueJitter * 360 + rotation) % 360;
2238
+ }
2239
+ case "aurora":
2240
+ default:
2241
+ return (150 + spread * 70 + arm.hueJitter * 20) % 360;
2242
+ }
2243
+ }
1414
2244
  var FlurryInstance = class {
1415
2245
  ctxSaver;
1416
2246
  canvas;
1417
- ctx;
2247
+ c2d;
1418
2248
  w = 0;
1419
2249
  h = 0;
1420
- streams;
2250
+ arms = [];
1421
2251
  frameId = null;
1422
- t = 0;
1423
- lastTime = 0;
1424
2252
  paused = false;
2253
+ startT = 0;
2254
+ /** Logical time the next rAF origin resumes from.
2255
+ *
2256
+ * `start()` re-anchors `startT` to the next frame's timestamp, so on its own
2257
+ * `now - startT` always begins at zero. Mount wants that; resuming from a
2258
+ * pause does not — without carrying the frozen `t` forward, every
2259
+ * pause/resume (and every reduced-motion toggle) snaps the scene back to its
2260
+ * opening frame and restarts any applied control track. Set only in
2261
+ * `setPaused(false)`, so first mount still starts at 0. */
2262
+ resumeFrom = 0;
2263
+ t = STILL_T;
2264
+ // anchor frame until the loop (or a seek) moves it
2265
+ params = defaultParams6(PARAM_SPACE6);
2266
+ track = null;
1425
2267
  constructor(ctx) {
1426
2268
  this.ctxSaver = ctx;
1427
2269
  this.w = ctx.width;
@@ -1439,10 +2281,8 @@ var FlurryInstance = class {
1439
2281
  this.canvas = canvas;
1440
2282
  const c2d = canvas.getContext("2d", { alpha: false });
1441
2283
  if (!c2d) throw new Error("flurry: no 2d context");
1442
- this.ctx = c2d;
1443
- this.streams = this.buildStreams(ctx.rng);
2284
+ this.c2d = c2d;
1444
2285
  this.sizeCanvas();
1445
- this.clearFull();
1446
2286
  this.paused = ctx.reducedMotion;
1447
2287
  if (this.paused) {
1448
2288
  this.renderStill();
@@ -1450,71 +2290,95 @@ var FlurryInstance = class {
1450
2290
  this.start();
1451
2291
  }
1452
2292
  }
1453
- buildStreams(rng) {
1454
- const out = [];
1455
- for (let i = 0; i < STREAM_COUNT; i++) {
1456
- out.push({
1457
- hue: (i * 360 / STREAM_COUNT + rng.range(0, 30)) % 360,
1458
- freqX1: rng.range(0.3, 0.9),
1459
- freqY1: rng.range(0.3, 0.9),
1460
- freqX2: rng.range(0.1, 0.4),
1461
- freqY2: rng.range(0.1, 0.4),
1462
- phaseX: rng.range(0, Math.PI * 2),
1463
- phaseY: rng.range(0, Math.PI * 2),
1464
- ampX: rng.range(0.2, 0.4),
1465
- ampY: rng.range(0.2, 0.4),
1466
- speed: rng.range(0.6, 1.2)
1467
- });
2293
+ applyParams(t) {
2294
+ const p = this.track ? sampleTrack6(PARAM_SPACE6, this.track, t) : this.params;
2295
+ for (const k of Object.keys(PARAM_SPACE6)) {
2296
+ const v = p[k];
2297
+ if (v !== void 0) this.params[k] = v;
1468
2298
  }
1469
- return out;
2299
+ }
2300
+ /** Rebuild the arm cast for a given count, deterministically, from the
2301
+ * saver's own seeded RNG. Pure w.r.t. (ctx.rng, count) — safe to call any
2302
+ * number of times, in any order, from any `t`. Keying off `arms.length`
2303
+ * alone is correct here (not a "rebuild every frame" bug): `ctx.rng`
2304
+ * never changes for this instance and `Rng.fork(salt)` is itself a pure
2305
+ * function of the salt, so a given count always yields the same cast. */
2306
+ ensureArms(count) {
2307
+ if (count === this.arms.length) return;
2308
+ const out = [];
2309
+ for (let i = 0; i < count; i++) out.push(buildArm(this.ctxSaver.rng.fork(i)));
2310
+ this.arms = out;
1470
2311
  }
1471
2312
  sizeCanvas() {
1472
2313
  const dpr = Math.min(this.ctxSaver.dpr, 2);
1473
2314
  this.canvas.width = Math.max(1, Math.round(this.w * dpr));
1474
2315
  this.canvas.height = Math.max(1, Math.round(this.h * dpr));
1475
- this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1476
- }
1477
- clearFull() {
1478
- this.ctx.fillStyle = "#000";
1479
- this.ctx.fillRect(0, 0, this.w, this.h);
2316
+ this.c2d.setTransform(dpr, 0, 0, dpr, 0, 0);
1480
2317
  }
1481
- streamPos(s, t) {
2318
+ /** Closed-form arm-tip position at arm-local time `s` (seconds). Pure. */
2319
+ armTip(arm, s) {
1482
2320
  const cx = this.w / 2;
1483
2321
  const cy = this.h / 2;
1484
- const x = cx + Math.sin(t * s.freqX1 + s.phaseX) * this.w * s.ampX + Math.sin(t * s.freqX2 + s.phaseX * 1.7) * this.w * s.ampX * 0.3;
1485
- const y = cy + Math.cos(t * s.freqY1 + s.phaseY) * this.h * s.ampY + Math.cos(t * s.freqY2 + s.phaseY * 2.1) * this.h * s.ampY * 0.3;
2322
+ const x = cx + Math.sin(s * arm.freqX1 + arm.phaseX) * this.w * arm.ampX + Math.sin(s * arm.freqX2 + arm.phaseX * 1.7) * this.w * arm.ampX * 0.3 + Math.sin(s * arm.freqX3 + arm.phaseX * 0.6) * this.w * arm.ampX * 0.12;
2323
+ const y = cy + Math.cos(s * arm.freqY1 + arm.phaseY) * this.h * arm.ampY + Math.cos(s * arm.freqY2 + arm.phaseY * 2.1) * this.h * arm.ampY * 0.3 + Math.cos(s * arm.freqY3 + arm.phaseY * 1.3) * this.h * arm.ampY * 0.12;
1486
2324
  return [x, y];
1487
2325
  }
1488
- drawFrame(_dt) {
1489
- const ctx = this.ctx;
1490
- ctx.globalCompositeOperation = "source-over";
1491
- ctx.fillStyle = `rgba(0,0,0,${TRAIL_ALPHA2})`;
1492
- ctx.fillRect(0, 0, this.w, this.h);
1493
- ctx.globalCompositeOperation = "lighter";
1494
- for (const s of this.streams) {
1495
- const st = this.t * s.speed;
1496
- for (let p = 0; p < PARTICLES_PER_STREAM; p++) {
1497
- const offset = p * 0.012;
1498
- const [x, y] = this.streamPos(s, st - offset);
1499
- const hue = (s.hue + this.t * 8 + p * 3) % 360;
1500
- const alpha = 0.15 + 0.1 * (1 - p / PARTICLES_PER_STREAM);
1501
- const r = BASE_RADIUS * (1 - p * 0.04);
1502
- const grad = ctx.createRadialGradient(x, y, 0, x, y, r * 3);
1503
- grad.addColorStop(0, `hsla(${hue},90%,60%,${alpha})`);
1504
- grad.addColorStop(0.4, `hsla(${hue},80%,50%,${alpha * 0.5})`);
1505
- grad.addColorStop(1, `hsla(${hue},70%,40%,0)`);
1506
- ctx.fillStyle = grad;
1507
- ctx.beginPath();
1508
- ctx.arc(x, y, r * 3, 0, Math.PI * 2);
1509
- ctx.fill();
2326
+ /** Pure render at logical time `t` (ms): background + every arm's analytic trail. */
2327
+ render(t) {
2328
+ const c2d = this.c2d;
2329
+ const p = this.params;
2330
+ c2d.fillStyle = "#000";
2331
+ c2d.fillRect(0, 0, this.w, this.h);
2332
+ const armCount = Math.max(3, Math.min(10, Math.round(p.arms)));
2333
+ this.ensureArms(armCount);
2334
+ c2d.globalCompositeOperation = "lighter";
2335
+ c2d.lineCap = "butt";
2336
+ c2d.lineJoin = "round";
2337
+ const globalS = t / 1e3 * p.speed;
2338
+ const glow = Math.max(0, Math.min(1.5, p.glow));
2339
+ const size = Math.max(0.5, Math.min(2, p.size));
2340
+ const glowReach = 3.6 + glow * 2.6;
2341
+ const headAlpha = 0.85 * (0.5 + glow * 0.6);
2342
+ const diag = Math.hypot(this.w, this.h);
2343
+ const trailFrac = TRAIL_FRAC_MIN + Math.max(0, Math.min(1, p.trail)) * (TRAIL_FRAC_MAX - TRAIL_FRAC_MIN);
2344
+ const targetArcPx = trailFrac * diag;
2345
+ const avgDim = (this.w + this.h) / 2;
2346
+ for (let i = 0; i < this.arms.length; i++) {
2347
+ const arm = this.arms[i];
2348
+ const armS = globalS * arm.armSpeed;
2349
+ const charRate = Math.max(0.02, (arm.freqX1 * arm.ampX + arm.freqY1 * arm.ampY) / 2);
2350
+ const spanS = targetArcPx / (charRate * avgDim);
2351
+ const stepS = spanS / (PARTICLES_PER_ARM - 1);
2352
+ const pts = new Array(PARTICLES_PER_ARM);
2353
+ for (let k = 0; k < PARTICLES_PER_ARM; k++) pts[k] = this.armTip(arm, armS - k * stepS);
2354
+ const hue = paletteHue(p.palette, arm, i, this.arms.length, t);
2355
+ for (let k = 0; k < PARTICLES_PER_ARM - 1; k++) {
2356
+ const kFrac = (k + 0.5) / (PARTICLES_PER_ARM - 1);
2357
+ const r = BASE_RADIUS * size * (1 - kFrac * (1 - TAIL_SIZE_FLOOR));
2358
+ const alpha = headAlpha * Math.pow(1 - kFrac, TAIL_ALPHA_POWER);
2359
+ const [x0, y0] = pts[k];
2360
+ const [x1, y1] = pts[k + 1];
2361
+ c2d.strokeStyle = `hsla(${hue},85%,58%,${alpha * 0.5})`;
2362
+ c2d.lineWidth = Math.max(0.5, r * glowReach);
2363
+ c2d.beginPath();
2364
+ c2d.moveTo(x0, y0);
2365
+ c2d.lineTo(x1, y1);
2366
+ c2d.stroke();
2367
+ c2d.strokeStyle = `hsla(${hue},95%,74%,${Math.min(1, alpha * 1.15)})`;
2368
+ c2d.lineWidth = Math.max(0.5, r * 1.15);
2369
+ c2d.beginPath();
2370
+ c2d.moveTo(x0, y0);
2371
+ c2d.lineTo(x1, y1);
2372
+ c2d.stroke();
1510
2373
  }
1511
2374
  }
1512
- ctx.globalCompositeOperation = "source-over";
2375
+ c2d.globalCompositeOperation = "source-over";
1513
2376
  }
2377
+ // ---- loop ----
1514
2378
  start() {
1515
2379
  if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
1516
- this.lastTime = 0;
1517
- this.loop(0);
2380
+ this.startT = 0;
2381
+ this.frameId = requestAnimationFrame((now) => this.loop(now));
1518
2382
  }
1519
2383
  stop() {
1520
2384
  if (this.frameId !== null) {
@@ -1524,23 +2388,23 @@ var FlurryInstance = class {
1524
2388
  }
1525
2389
  loop(now) {
1526
2390
  this.frameId = requestAnimationFrame((n) => this.loop(n));
1527
- const dt = this.lastTime ? (now - this.lastTime) / 1e3 : 1 / 60;
1528
- this.lastTime = now;
1529
- this.t += Math.min(dt, 0.1);
1530
- this.drawFrame(dt);
2391
+ if (this.startT === 0) this.startT = now;
2392
+ this.renderFrame(now - this.startT + this.resumeFrom, this.ctxSaver.seed);
1531
2393
  }
2394
+ /** Freeze on whatever frame we're actually at — not a fixed anchor — so
2395
+ * pausing mid-loop, resizing while paused, or steering a track while
2396
+ * paused all repaint the same instant instead of snapping elsewhere. */
1532
2397
  renderStill() {
1533
- this.clearFull();
1534
- for (let i = 0; i < 120; i++) {
1535
- this.t += 1 / 60;
1536
- this.drawFrame(1 / 60);
1537
- }
2398
+ this.renderFrame(this.t, this.ctxSaver.seed);
1538
2399
  }
2400
+ // ---- SaverInstance ----
1539
2401
  setPaused(paused) {
1540
2402
  this.paused = paused;
1541
2403
  if (paused) {
1542
2404
  this.stop();
2405
+ this.renderStill();
1543
2406
  } else {
2407
+ this.resumeFrom = this.t;
1544
2408
  this.start();
1545
2409
  }
1546
2410
  }
@@ -1549,9 +2413,19 @@ var FlurryInstance = class {
1549
2413
  this.h = height;
1550
2414
  if (dpr !== void 0) this.ctxSaver.dpr = dpr;
1551
2415
  this.sizeCanvas();
1552
- this.clearFull();
1553
2416
  if (this.paused) this.renderStill();
1554
2417
  }
2418
+ applyTrack(track) {
2419
+ this.track = track;
2420
+ if (this.paused) this.renderStill();
2421
+ }
2422
+ /** Pure, frame-addressable render at logical time `t` (ms) for `seed`.
2423
+ * Same (t, seed) always paints the same pixels — seek-back safe. */
2424
+ renderFrame(t, _seed) {
2425
+ this.t = t;
2426
+ this.applyParams(t);
2427
+ this.render(t);
2428
+ }
1555
2429
  dispose() {
1556
2430
  this.stop();
1557
2431
  if (typeof HTMLCanvasElement !== "undefined" && this.canvas instanceof HTMLCanvasElement) this.canvas.remove();
@@ -1561,6 +2435,24 @@ var flurry = {
1561
2435
  manifest: flurryManifest,
1562
2436
  mount: (ctx) => new FlurryInstance(ctx)
1563
2437
  };
2438
+ var flurryDemoTrack = {
2439
+ program: "flurry",
2440
+ seed: 3,
2441
+ duration: 16e3,
2442
+ loop: true,
2443
+ deltas: [
2444
+ { t: 0, path: "palette", value: "aurora" },
2445
+ { t: 8e3, path: "palette", value: "ember" },
2446
+ { t: 0, path: "speed", value: 0.6 },
2447
+ { t: 8e3, path: "speed", value: 1.8, ease: "smooth" },
2448
+ { t: 16e3, path: "speed", value: 0.6, ease: "smooth" },
2449
+ { t: 0, path: "glow", value: 0.3 },
2450
+ { t: 4e3, path: "glow", value: 0.9, ease: "smooth" },
2451
+ { t: 8e3, path: "glow", value: 0.3, ease: "smooth" },
2452
+ { t: 12e3, path: "glow", value: 0.9, ease: "smooth" },
2453
+ { t: 16e3, path: "glow", value: 0.3, ease: "smooth" }
2454
+ ]
2455
+ };
1564
2456
 
1565
2457
  // src/fluid-shared.ts
1566
2458
  var DT = 0.025;
@@ -2315,6 +3207,7 @@ function gpuMainThreadEligible(ctx) {
2315
3207
  var fluidManifest = {
2316
3208
  id: "fluid",
2317
3209
  label: "Fluid",
3210
+ timeModel: "simulated",
2318
3211
  passthrough: false,
2319
3212
  minBackend: "canvas2d",
2320
3213
  costTier: "low",
@@ -3071,6 +3964,7 @@ var ReactionDiffusionGPU = class {
3071
3964
  var reactionDiffusionManifest = {
3072
3965
  id: "reaction-diffusion",
3073
3966
  label: "Reaction Diffusion",
3967
+ timeModel: "simulated",
3074
3968
  passthrough: false,
3075
3969
  minBackend: "canvas2d",
3076
3970
  costTier: "low",
@@ -3243,8 +4137,8 @@ var reactionDiffusion = {
3243
4137
 
3244
4138
  // src/messages.ts
3245
4139
  import {
3246
- sampleTrack,
3247
- defaultParams
4140
+ sampleTrack as sampleTrack7,
4141
+ defaultParams as defaultParams7
3248
4142
  } from "@idle-screens/core";
3249
4143
  var PHRASES = {
3250
4144
  "out-to-lunch": "OUT TO LUNCH",
@@ -3253,7 +4147,7 @@ var PHRASES = {
3253
4147
  "gone-idle": "gone idle \u2014 leave a message",
3254
4148
  "ship-it": "SHIP IT IN THE MORNING"
3255
4149
  };
3256
- var PARAM_SPACE = {
4150
+ var PARAM_SPACE7 = {
3257
4151
  /** Which line the screen mutters. */
3258
4152
  phrase: { type: "enum", default: "out-to-lunch", options: Object.keys(PHRASES) },
3259
4153
  /** 'marquee' = the Out-to-Lunch crawl (steps down the page);
@@ -3271,12 +4165,13 @@ var PARAM_SPACE = {
3271
4165
  var messagesManifest = {
3272
4166
  id: "messages",
3273
4167
  label: "Messages",
4168
+ timeModel: "closed-form",
3274
4169
  passthrough: false,
3275
4170
  minBackend: "canvas2d",
3276
4171
  costTier: "low",
3277
4172
  motionIntensity: "calm",
3278
4173
  reducedMotionFallback: "static",
3279
- paramSpace: PARAM_SPACE,
4174
+ paramSpace: PARAM_SPACE7,
3280
4175
  attribution: {
3281
4176
  source: 'After Dark "Messages" \u2014 concepts by Berkeley Systems',
3282
4177
  license: "MIT port; reference CSS MIT (Bryan Braun)",
@@ -3285,7 +4180,7 @@ var messagesManifest = {
3285
4180
  a11y: { flashSafe: true, notes: "A single line of text moving smoothly; no flashing." },
3286
4181
  workerReady: true
3287
4182
  };
3288
- var tri = (t, p) => {
4183
+ var tri2 = (t, p) => {
3289
4184
  const k = (t % (p * 2) + p * 2) % (p * 2);
3290
4185
  return k < p ? k / p : 2 - k / p;
3291
4186
  };
@@ -3299,7 +4194,7 @@ var MessagesInstance = class {
3299
4194
  paused = false;
3300
4195
  startT = 0;
3301
4196
  t = 0;
3302
- params = defaultParams(PARAM_SPACE);
4197
+ params = defaultParams7(PARAM_SPACE7);
3303
4198
  track = null;
3304
4199
  constructor(ctx) {
3305
4200
  this.ctxSaver = ctx;
@@ -3322,8 +4217,8 @@ var MessagesInstance = class {
3322
4217
  else this.start();
3323
4218
  }
3324
4219
  applyParams(t) {
3325
- const p = this.track ? sampleTrack(PARAM_SPACE, this.track, t) : this.params;
3326
- for (const k of Object.keys(PARAM_SPACE)) {
4220
+ const p = this.track ? sampleTrack7(PARAM_SPACE7, this.track, t) : this.params;
4221
+ for (const k of Object.keys(PARAM_SPACE7)) {
3327
4222
  const v = p[k];
3328
4223
  if (v !== void 0) this.params[k] = v;
3329
4224
  }
@@ -3354,8 +4249,8 @@ var MessagesInstance = class {
3354
4249
  const y2 = this.h * 0.22 + row * this.h * 0.27 + fs * 0.5;
3355
4250
  return [x2, y2];
3356
4251
  }
3357
- const x = tri(t, 8e3 / p.speed) * Math.max(0, this.w - textW);
3358
- const y = fs + tri(t, 17300 / p.speed) * Math.max(0, this.h - fs * 1.6);
4252
+ const x = tri2(t, 8e3 / p.speed) * Math.max(0, this.w - textW);
4253
+ const y = fs + tri2(t, 17300 / p.speed) * Math.max(0, this.h - fs * 1.6);
3359
4254
  return [x, y];
3360
4255
  }
3361
4256
  // ---- loop ----
@@ -3460,17 +4355,24 @@ var messagesDemoTrack = {
3460
4355
  };
3461
4356
 
3462
4357
  export {
4358
+ dvd,
4359
+ dvdDemoTrack,
3463
4360
  warp,
4361
+ warpDemoTrack,
3464
4362
  hardRain,
3465
4363
  rainstorm,
3466
4364
  globe,
4365
+ globeDemoTrack,
3467
4366
  spotlight,
3468
4367
  mystify,
4368
+ mystifyDemoTrack,
3469
4369
  pipes,
4370
+ pipesDemoTrack,
3470
4371
  flurry,
4372
+ flurryDemoTrack,
3471
4373
  fluid,
3472
4374
  reactionDiffusion,
3473
4375
  messages,
3474
4376
  messagesDemoTrack
3475
4377
  };
3476
- //# sourceMappingURL=chunk-RMW74SYX.js.map
4378
+ //# sourceMappingURL=chunk-GVD3Q4LE.js.map