@idle-screens/savers-classic 3.1.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.
@@ -21,6 +21,7 @@ var PARAM_SPACE = {
21
21
  var dvdManifest = {
22
22
  id: "dvd",
23
23
  label: "Bouncing Logo",
24
+ timeModel: "closed-form",
24
25
  passthrough: false,
25
26
  minBackend: "canvas2d",
26
27
  costTier: "low",
@@ -365,6 +366,7 @@ var PARAM_SPACE2 = {
365
366
  var warpManifest = {
366
367
  id: "warp",
367
368
  label: "Warp",
369
+ timeModel: "closed-form",
368
370
  passthrough: false,
369
371
  minBackend: "canvas2d",
370
372
  costTier: "low",
@@ -603,6 +605,7 @@ var warpDemoTrack = {
603
605
  var hardRainManifest = {
604
606
  id: "hard-rain",
605
607
  label: "Hard Rain",
608
+ timeModel: "closed-form",
606
609
  passthrough: false,
607
610
  minBackend: "canvas2d",
608
611
  costTier: "low",
@@ -894,6 +897,7 @@ var hardRain = {
894
897
  var rainstormManifest = {
895
898
  id: "rainstorm",
896
899
  label: "Rainstorm",
900
+ timeModel: "closed-form",
897
901
  passthrough: false,
898
902
  minBackend: "canvas2d",
899
903
  costTier: "low",
@@ -1104,6 +1108,7 @@ var PARAM_SPACE3 = {
1104
1108
  var globeManifest = {
1105
1109
  id: "globe",
1106
1110
  label: "Globe",
1111
+ timeModel: "closed-form",
1107
1112
  passthrough: false,
1108
1113
  minBackend: "canvas2d",
1109
1114
  costTier: "low",
@@ -1411,6 +1416,7 @@ var globeDemoTrack = {
1411
1416
  var spotlightManifest = {
1412
1417
  id: "spotlight",
1413
1418
  label: "Spotlight",
1419
+ timeModel: "closed-form",
1414
1420
  passthrough: true,
1415
1421
  minBackend: "canvas2d",
1416
1422
  costTier: "low",
@@ -1547,14 +1553,33 @@ var spotlight = {
1547
1553
  };
1548
1554
 
1549
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
+ };
1550
1573
  var mystifyManifest = {
1551
1574
  id: "mystify",
1552
1575
  label: "Mystify",
1576
+ timeModel: "closed-form",
1553
1577
  passthrough: false,
1554
1578
  minBackend: "canvas2d",
1555
1579
  costTier: "low",
1556
1580
  motionIntensity: "moderate",
1557
1581
  reducedMotionFallback: "static",
1582
+ paramSpace: PARAM_SPACE4,
1558
1583
  attribution: {
1559
1584
  source: 'Windows "Mystify" \u2014 concept only; clean-room reimplementation',
1560
1585
  license: "MIT (original code)"
@@ -1562,18 +1587,39 @@ var mystifyManifest = {
1562
1587
  a11y: { flashSafe: true, notes: "Slow-fade polygon trails on black; no strobing." },
1563
1588
  workerReady: true
1564
1589
  };
1565
- var SHAPE_COUNT = 3;
1566
- var TRAIL_ALPHA = 0.12;
1567
- 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 {
1568
1599
  ctxSaver;
1569
1600
  canvas;
1570
1601
  ctx;
1571
1602
  w = 0;
1572
1603
  h = 0;
1573
- 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 = [];
1574
1610
  frameId = null;
1575
- last = 0;
1576
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;
1577
1623
  constructor(ctx) {
1578
1624
  this.ctxSaver = ctx;
1579
1625
  let canvas;
@@ -1593,31 +1639,28 @@ var MystifyInstance = class {
1593
1639
  this.w = ctx.width;
1594
1640
  this.h = ctx.height;
1595
1641
  this.sizeCanvas();
1596
- this.shapes = this.buildShapes(ctx.rng);
1597
- this.clearFull();
1642
+ this.shapes = _MystifyInstance.buildShapes(ctx.rng);
1598
1643
  this.paused = ctx.reducedMotion;
1599
1644
  if (this.paused) this.renderStill();
1600
1645
  else this.start();
1601
1646
  }
1602
- buildShapes(rng) {
1647
+ /** The full identity pool, one fork per slot — count-independent. */
1648
+ static buildShapes(rng) {
1603
1649
  const out = [];
1604
- for (let s = 0; s < SHAPE_COUNT; s++) {
1605
- const vertCount = rng.int(3, 5);
1606
- const hue = rng.int(0, 359);
1607
- 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: [] };
1608
1655
  for (let v = 0; v < vertCount; v++) {
1609
- const x = rng.range(this.w * 0.15, this.w * 0.85);
1610
- const y = rng.range(this.h * 0.15, this.h * 0.85);
1611
- const dir = rng.range(0, Math.PI * 2);
1612
- const speed = rng.range(70, 150);
1613
- verts.push({
1614
- x,
1615
- y,
1616
- vx: Math.cos(dir) * speed,
1617
- vy: Math.sin(dir) * speed
1618
- });
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);
1619
1662
  }
1620
- out.push({ hue, verts });
1663
+ out.push(id);
1621
1664
  }
1622
1665
  return out;
1623
1666
  }
@@ -1627,13 +1670,40 @@ var MystifyInstance = class {
1627
1670
  this.canvas.height = Math.max(1, Math.round(this.h * dpr));
1628
1671
  this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1629
1672
  }
1630
- clearFull() {
1631
- this.ctx.fillStyle = "#000";
1632
- 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;
1633
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 ----
1634
1704
  start() {
1635
1705
  if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
1636
- this.last = 0;
1706
+ this.startT = 0;
1637
1707
  this.frameId = requestAnimationFrame((now) => this.loop(now));
1638
1708
  }
1639
1709
  stop() {
@@ -1644,66 +1714,58 @@ var MystifyInstance = class {
1644
1714
  }
1645
1715
  loop(now) {
1646
1716
  this.frameId = requestAnimationFrame((n) => this.loop(n));
1647
- if (this.last === 0) this.last = now;
1648
- const dt = Math.min(0.05, (now - this.last) / 1e3);
1649
- this.last = now;
1650
- this.update(dt);
1651
- this.render();
1717
+ if (this.startT === 0) this.startT = now;
1718
+ this.renderFrame(now - this.startT + this.resumeFrom, this.ctxSaver.seed);
1652
1719
  }
1653
- update(dt) {
1654
- for (const shape of this.shapes) {
1655
- for (const v of shape.verts) {
1656
- v.x += v.vx * dt;
1657
- v.y += v.vy * dt;
1658
- if (v.x <= 0) {
1659
- v.x = 0;
1660
- v.vx = Math.abs(v.vx);
1661
- } else if (v.x >= this.w) {
1662
- v.x = this.w;
1663
- v.vx = -Math.abs(v.vx);
1664
- }
1665
- if (v.y <= 0) {
1666
- v.y = 0;
1667
- v.vy = Math.abs(v.vy);
1668
- } else if (v.y >= this.h) {
1669
- v.y = this.h;
1670
- v.vy = -Math.abs(v.vy);
1671
- }
1672
- }
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);
1673
1737
  }
1738
+ ctx.closePath();
1739
+ ctx.stroke();
1674
1740
  }
1675
- 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);
1676
1746
  const ctx = this.ctx;
1747
+ ctx.fillStyle = "#000";
1748
+ ctx.fillRect(0, 0, this.w, this.h);
1677
1749
  ctx.lineCap = "round";
1678
1750
  ctx.lineJoin = "round";
1679
- for (const shape of this.shapes) {
1680
- const { verts } = shape;
1681
- if (verts.length < 2) continue;
1682
- ctx.strokeStyle = `hsla(${shape.hue}, 90%, 62%, 0.92)`;
1683
- ctx.lineWidth = 2;
1684
- ctx.beginPath();
1685
- ctx.moveTo(verts[0].x, verts[0].y);
1686
- for (let i = 1; i < verts.length; i++) ctx.lineTo(verts[i].x, verts[i].y);
1687
- ctx.closePath();
1688
- 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);
1689
1760
  }
1690
1761
  }
1691
- render() {
1692
- this.ctx.fillStyle = `rgba(0,0,0,${TRAIL_ALPHA})`;
1693
- this.ctx.fillRect(0, 0, this.w, this.h);
1694
- this.drawShapes();
1695
- }
1696
- renderStill() {
1697
- this.clearFull();
1698
- this.drawShapes();
1699
- }
1700
1762
  setPaused(paused) {
1701
1763
  this.paused = paused;
1702
1764
  if (paused) {
1703
1765
  this.stop();
1704
1766
  this.renderStill();
1705
1767
  } else {
1706
- this.clearFull();
1768
+ this.resumeFrom = this.t;
1707
1769
  this.start();
1708
1770
  }
1709
1771
  }
@@ -1712,14 +1774,13 @@ var MystifyInstance = class {
1712
1774
  this.h = height;
1713
1775
  if (dpr !== void 0) this.ctxSaver.dpr = dpr;
1714
1776
  this.sizeCanvas();
1715
- for (const shape of this.shapes) {
1716
- for (const v of shape.verts) {
1717
- v.x = Math.min(Math.max(v.x, 0), this.w);
1718
- v.y = Math.min(Math.max(v.y, 0), this.h);
1719
- }
1720
- }
1721
1777
  if (this.paused) this.renderStill();
1722
- else this.clearFull();
1778
+ }
1779
+ applyTrack(track) {
1780
+ this.track = track;
1781
+ this.phiPrefix = [0];
1782
+ this.phiSpeeds = [];
1783
+ if (this.paused) this.renderStill();
1723
1784
  }
1724
1785
  dispose() {
1725
1786
  this.stop();
@@ -1732,23 +1793,61 @@ var mystify = {
1732
1793
  manifest: mystifyManifest,
1733
1794
  mount: (ctx) => new MystifyInstance(ctx)
1734
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
+ };
1735
1815
 
1736
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
+ };
1737
1836
  var pipesManifest = {
1738
1837
  id: "pipes",
1739
1838
  label: "Pipes",
1839
+ timeModel: "closed-form",
1740
1840
  passthrough: false,
1741
1841
  minBackend: "canvas2d",
1742
1842
  costTier: "low",
1743
1843
  motionIntensity: "moderate",
1744
1844
  reducedMotionFallback: "static",
1845
+ paramSpace: PARAM_SPACE5,
1745
1846
  a11y: { flashSafe: true },
1746
1847
  workerReady: true
1747
1848
  };
1748
- var CELL = 20;
1749
- var PIPE_WIDTH = 8;
1750
- var STEPS_PER_FRAME = 3;
1751
- var FILL_THRESHOLD = 0.65;
1849
+ var STEP_MS = 1e3 / 180;
1850
+ var PLAN_CACHE = 4;
1752
1851
  var PALETTE = ["#c0392b", "#2980b9", "#27ae60", "#f39c12", "#8e44ad", "#d4a259", "#7f8c8d"];
1753
1852
  var DX = { 0: 1, 1: 0, 2: -1, 3: 0 };
1754
1853
  var DY = { 0: 0, 1: 1, 2: 0, 3: -1 };
@@ -1758,17 +1857,31 @@ var PipesInstance = class {
1758
1857
  ctx;
1759
1858
  w = 0;
1760
1859
  h = 0;
1761
- cols = 0;
1762
- rows = 0;
1763
- grid = [];
1764
- filled = 0;
1765
- pipe = null;
1766
- 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;
1767
1870
  frameId = null;
1768
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;
1769
1883
  constructor(ctx) {
1770
1884
  this.ctxSaver = ctx;
1771
- this.rng = ctx.rng;
1772
1885
  let canvas;
1773
1886
  if (ctx.surface) {
1774
1887
  canvas = ctx.surface;
@@ -1798,121 +1911,171 @@ var PipesInstance = class {
1798
1911
  this.ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
1799
1912
  }
1800
1913
  rebuild() {
1801
- this.cols = Math.max(2, Math.floor(this.w / CELL));
1802
- this.rows = Math.max(2, Math.floor(this.h / CELL));
1803
- this.grid = new Array(this.cols * this.rows).fill(false);
1804
- this.filled = 0;
1805
- this.pipe = null;
1914
+ this.epochStarts = [];
1915
+ this.epochSteps = [];
1916
+ this.plans.clear();
1917
+ this.paintedEpoch = -1;
1918
+ this.paintedSteps = 0;
1806
1919
  this.paintBackground();
1807
1920
  }
1808
1921
  paintBackground() {
1809
1922
  this.ctx.fillStyle = "#111";
1810
1923
  this.ctx.fillRect(0, 0, this.w, this.h);
1811
1924
  }
1812
- idx(col, row) {
1813
- return row * this.cols + col;
1814
- }
1815
- inBounds(col, row) {
1816
- return col >= 0 && col < this.cols && row >= 0 && row < this.rows;
1817
- }
1818
- spawnPipe() {
1819
- const empty = [];
1820
- for (let i = 0; i < this.grid.length; i++) {
1821
- if (!this.grid[i]) empty.push(i);
1822
- }
1823
- if (empty.length === 0) {
1824
- this.clearGrid();
1825
- return;
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;
1826
1934
  }
1827
- const cell = this.rng.pick(empty);
1828
- const col = cell % this.cols;
1829
- const row = Math.floor(cell / this.cols);
1830
- this.pipe = {
1831
- col,
1832
- row,
1833
- dir: this.rng.int(0, 3),
1834
- color: this.rng.pick(PALETTE)
1835
- };
1836
- this.grid[cell] = true;
1837
- this.filled++;
1838
- this.drawJoint(col, row, this.pipe.color);
1839
- }
1840
- clearGrid() {
1841
- this.grid.fill(false);
1842
- this.filled = 0;
1843
- this.pipe = null;
1844
- this.paintBackground();
1935
+ return out;
1845
1936
  }
1846
- growStep() {
1847
- if (this.filled / this.grid.length > FILL_THRESHOLD) {
1848
- this.clearGrid();
1849
- return;
1850
- }
1851
- if (!this.pipe) {
1852
- this.spawnPipe();
1853
- return;
1854
- }
1855
- const candidates = this.getCandidates(this.pipe);
1856
- if (candidates.length === 0) {
1857
- this.pipe = null;
1858
- return;
1859
- }
1860
- const oldCol = this.pipe.col;
1861
- const oldRow = this.pipe.row;
1862
- const oldDir = this.pipe.dir;
1863
- const newDir = this.rng.pick(candidates);
1864
- this.pipe.dir = newDir;
1865
- const nc = oldCol + DX[newDir];
1866
- const nr = oldRow + DY[newDir];
1867
- this.drawSegment(oldCol, oldRow, nc, nr, this.pipe.color);
1868
- if (newDir !== oldDir) {
1869
- this.drawJoint(oldCol, oldRow, this.pipe.color);
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++;
1870
1994
  }
1871
- this.pipe.col = nc;
1872
- this.pipe.row = nr;
1873
- this.grid[this.idx(nc, nr)] = true;
1874
- this.filled++;
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
2002
+ };
1875
2003
  }
1876
- getCandidates(pipe) {
1877
- const out = [];
1878
- for (let d = 0; d < 4; d++) {
1879
- const nc = pipe.col + DX[d];
1880
- const nr = pipe.row + DY[d];
1881
- if (this.inBounds(nc, nr) && !this.grid[this.idx(nc, nr)]) {
1882
- 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);
1883
2021
  }
1884
2022
  }
1885
- if (out.includes(pipe.dir) && this.rng.next() < 0.65) {
1886
- 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++;
1887
2040
  }
1888
- return out;
1889
- }
1890
- cellCenter(col, row) {
1891
- return [col * CELL + CELL / 2, row * CELL + CELL / 2];
1892
2041
  }
1893
- drawSegment(c1, r1, c2, r2, color) {
1894
- const [x1, y1] = this.cellCenter(c1, r1);
1895
- 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;
1896
2046
  const ctx = this.ctx;
1897
2047
  ctx.strokeStyle = color;
1898
- ctx.lineWidth = PIPE_WIDTH;
2048
+ ctx.lineWidth = plan.thickness;
1899
2049
  ctx.lineCap = "round";
1900
2050
  ctx.beginPath();
1901
- ctx.moveTo(x1, y1);
1902
- 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);
1903
2053
  ctx.stroke();
1904
2054
  }
1905
- drawJoint(col, row, color) {
1906
- const [x, y] = this.cellCenter(col, row);
2055
+ drawJoint(plan, col, row, color) {
2056
+ const half = plan.cell / 2;
1907
2057
  const ctx = this.ctx;
1908
2058
  ctx.fillStyle = color;
1909
2059
  ctx.beginPath();
1910
- 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);
1911
2061
  ctx.fill();
1912
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 ----
1913
2075
  start() {
1914
2076
  if (this.frameId !== null || typeof requestAnimationFrame === "undefined") return;
1915
- this.loop();
2077
+ this.startT = 0;
2078
+ this.frameId = requestAnimationFrame((now) => this.loop(now));
1916
2079
  }
1917
2080
  stop() {
1918
2081
  if (this.frameId !== null) {
@@ -1920,22 +2083,53 @@ var PipesInstance = class {
1920
2083
  this.frameId = null;
1921
2084
  }
1922
2085
  }
1923
- loop() {
1924
- this.frameId = requestAnimationFrame(() => this.loop());
1925
- 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);
1926
2090
  }
1927
2091
  renderStill() {
1928
- this.rebuild();
1929
- 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;
1930
2112
  }
1931
2113
  setPaused(paused) {
1932
2114
  this.paused = paused;
1933
2115
  if (paused) {
1934
2116
  this.stop();
2117
+ this.renderStill();
1935
2118
  } else {
2119
+ this.resumeFrom = this.t;
1936
2120
  this.start();
1937
2121
  }
1938
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
+ }
1939
2133
  resize(width, height, dpr) {
1940
2134
  this.w = width;
1941
2135
  this.h = height;
@@ -1953,11 +2147,25 @@ var pipes = {
1953
2147
  manifest: pipesManifest,
1954
2148
  mount: (ctx) => new PipesInstance(ctx)
1955
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
+ };
1956
2164
 
1957
2165
  // src/flurry.ts
1958
2166
  import {
1959
- sampleTrack as sampleTrack4,
1960
- defaultParams as defaultParams4
2167
+ sampleTrack as sampleTrack6,
2168
+ defaultParams as defaultParams6
1961
2169
  } from "@idle-screens/core";
1962
2170
  var STREAM_COUNT = 5;
1963
2171
  var PARTICLES_PER_ARM = 56;
@@ -1967,7 +2175,7 @@ var TRAIL_FRAC_MIN = 0.12;
1967
2175
  var TRAIL_FRAC_MAX = 0.42;
1968
2176
  var TAIL_SIZE_FLOOR = 0.45;
1969
2177
  var TAIL_ALPHA_POWER = 1.4;
1970
- var PARAM_SPACE4 = {
2178
+ var PARAM_SPACE6 = {
1971
2179
  /** Arm count. Build-time: rebuilt (deterministically, from the same seeded
1972
2180
  * RNG forks) whenever this changes rather than smoothly animated — more
1973
2181
  * arms means re-deriving the whole cast, not interpolating between two. */
@@ -1986,12 +2194,13 @@ var PARAM_SPACE4 = {
1986
2194
  var flurryManifest = {
1987
2195
  id: "flurry",
1988
2196
  label: "Flurry",
2197
+ timeModel: "closed-form",
1989
2198
  passthrough: false,
1990
2199
  minBackend: "canvas2d",
1991
2200
  costTier: "low",
1992
2201
  motionIntensity: "calm",
1993
2202
  reducedMotionFallback: "static",
1994
- paramSpace: PARAM_SPACE4,
2203
+ paramSpace: PARAM_SPACE6,
1995
2204
  a11y: {
1996
2205
  flashSafe: true,
1997
2206
  notes: "Softly glowing arms drifting on black. The spectrum palette rotates hue over ~20s; no flashing."
@@ -2053,7 +2262,7 @@ var FlurryInstance = class {
2053
2262
  resumeFrom = 0;
2054
2263
  t = STILL_T;
2055
2264
  // anchor frame until the loop (or a seek) moves it
2056
- params = defaultParams4(PARAM_SPACE4);
2265
+ params = defaultParams6(PARAM_SPACE6);
2057
2266
  track = null;
2058
2267
  constructor(ctx) {
2059
2268
  this.ctxSaver = ctx;
@@ -2082,8 +2291,8 @@ var FlurryInstance = class {
2082
2291
  }
2083
2292
  }
2084
2293
  applyParams(t) {
2085
- const p = this.track ? sampleTrack4(PARAM_SPACE4, this.track, t) : this.params;
2086
- for (const k of Object.keys(PARAM_SPACE4)) {
2294
+ const p = this.track ? sampleTrack6(PARAM_SPACE6, this.track, t) : this.params;
2295
+ for (const k of Object.keys(PARAM_SPACE6)) {
2087
2296
  const v = p[k];
2088
2297
  if (v !== void 0) this.params[k] = v;
2089
2298
  }
@@ -2998,6 +3207,7 @@ function gpuMainThreadEligible(ctx) {
2998
3207
  var fluidManifest = {
2999
3208
  id: "fluid",
3000
3209
  label: "Fluid",
3210
+ timeModel: "simulated",
3001
3211
  passthrough: false,
3002
3212
  minBackend: "canvas2d",
3003
3213
  costTier: "low",
@@ -3754,6 +3964,7 @@ var ReactionDiffusionGPU = class {
3754
3964
  var reactionDiffusionManifest = {
3755
3965
  id: "reaction-diffusion",
3756
3966
  label: "Reaction Diffusion",
3967
+ timeModel: "simulated",
3757
3968
  passthrough: false,
3758
3969
  minBackend: "canvas2d",
3759
3970
  costTier: "low",
@@ -3926,8 +4137,8 @@ var reactionDiffusion = {
3926
4137
 
3927
4138
  // src/messages.ts
3928
4139
  import {
3929
- sampleTrack as sampleTrack5,
3930
- defaultParams as defaultParams5
4140
+ sampleTrack as sampleTrack7,
4141
+ defaultParams as defaultParams7
3931
4142
  } from "@idle-screens/core";
3932
4143
  var PHRASES = {
3933
4144
  "out-to-lunch": "OUT TO LUNCH",
@@ -3936,7 +4147,7 @@ var PHRASES = {
3936
4147
  "gone-idle": "gone idle \u2014 leave a message",
3937
4148
  "ship-it": "SHIP IT IN THE MORNING"
3938
4149
  };
3939
- var PARAM_SPACE5 = {
4150
+ var PARAM_SPACE7 = {
3940
4151
  /** Which line the screen mutters. */
3941
4152
  phrase: { type: "enum", default: "out-to-lunch", options: Object.keys(PHRASES) },
3942
4153
  /** 'marquee' = the Out-to-Lunch crawl (steps down the page);
@@ -3954,12 +4165,13 @@ var PARAM_SPACE5 = {
3954
4165
  var messagesManifest = {
3955
4166
  id: "messages",
3956
4167
  label: "Messages",
4168
+ timeModel: "closed-form",
3957
4169
  passthrough: false,
3958
4170
  minBackend: "canvas2d",
3959
4171
  costTier: "low",
3960
4172
  motionIntensity: "calm",
3961
4173
  reducedMotionFallback: "static",
3962
- paramSpace: PARAM_SPACE5,
4174
+ paramSpace: PARAM_SPACE7,
3963
4175
  attribution: {
3964
4176
  source: 'After Dark "Messages" \u2014 concepts by Berkeley Systems',
3965
4177
  license: "MIT port; reference CSS MIT (Bryan Braun)",
@@ -3982,7 +4194,7 @@ var MessagesInstance = class {
3982
4194
  paused = false;
3983
4195
  startT = 0;
3984
4196
  t = 0;
3985
- params = defaultParams5(PARAM_SPACE5);
4197
+ params = defaultParams7(PARAM_SPACE7);
3986
4198
  track = null;
3987
4199
  constructor(ctx) {
3988
4200
  this.ctxSaver = ctx;
@@ -4005,8 +4217,8 @@ var MessagesInstance = class {
4005
4217
  else this.start();
4006
4218
  }
4007
4219
  applyParams(t) {
4008
- const p = this.track ? sampleTrack5(PARAM_SPACE5, this.track, t) : this.params;
4009
- for (const k of Object.keys(PARAM_SPACE5)) {
4220
+ const p = this.track ? sampleTrack7(PARAM_SPACE7, this.track, t) : this.params;
4221
+ for (const k of Object.keys(PARAM_SPACE7)) {
4010
4222
  const v = p[k];
4011
4223
  if (v !== void 0) this.params[k] = v;
4012
4224
  }
@@ -4153,7 +4365,9 @@ export {
4153
4365
  globeDemoTrack,
4154
4366
  spotlight,
4155
4367
  mystify,
4368
+ mystifyDemoTrack,
4156
4369
  pipes,
4370
+ pipesDemoTrack,
4157
4371
  flurry,
4158
4372
  flurryDemoTrack,
4159
4373
  fluid,
@@ -4161,4 +4375,4 @@ export {
4161
4375
  messages,
4162
4376
  messagesDemoTrack
4163
4377
  };
4164
- //# sourceMappingURL=chunk-PU6BQ5S3.js.map
4378
+ //# sourceMappingURL=chunk-GVD3Q4LE.js.map