neon-activity-graph 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -495,6 +495,12 @@ function createNeon({ blocks, apply, done, sound, fps = NEON_FPS, wobbleFps = 40
495
495
  }
496
496
  areaPlans.set(k, { start, stutters, steady: at + 60 });
497
497
  });
498
+ const lead = Math.min(...[...areaPlans.values()].map((p) => p.start));
499
+ if (Number.isFinite(lead)) for (const p of areaPlans.values()) {
500
+ p.start -= lead;
501
+ p.steady -= lead;
502
+ for (const st of p.stutters) st.at -= lead;
503
+ }
498
504
  const plans = /* @__PURE__ */ new Map();
499
505
  blocks.forEach((_, i) => {
500
506
  const base = areaPlans.get(areaOf[i]);
@@ -1260,7 +1266,7 @@ function mountScene(el, opts, st) {
1260
1266
  const rgb = opts.rodColor({ layer: src, index: cell, date: layout.top.cells[cell].date, t });
1261
1267
  return rgb ? new THREE.Color(rgb[0], rgb[1], rgb[2]) : null;
1262
1268
  };
1263
- const groundLayers = (stack2, tones, dark) => {
1269
+ const groundLayers = (stack2, tones, dark, page) => {
1264
1270
  const cw = Math.ceil((width + GLOW_PAD * 2) * PX);
1265
1271
  const ch = Math.ceil((total + GLOW_PAD * 2) * PX);
1266
1272
  const lw = Math.ceil((width + GLOW_PAD * 2) * LPX);
@@ -1531,7 +1537,7 @@ void main() {
1531
1537
  const prevClear = renderer.getClearColor(new THREE.Color());
1532
1538
  const prevAlpha = renderer.getClearAlpha();
1533
1539
  renderer.setRenderTarget(bake);
1534
- renderer.setClearColor(pageColour(), 1);
1540
+ renderer.setClearColor(page, 1);
1535
1541
  renderer.clear();
1536
1542
  renderer.render(bakeScene, cam);
1537
1543
  renderer.setRenderTarget(prevTarget);
@@ -1560,7 +1566,6 @@ void main() {
1560
1566
  }
1561
1567
  if (dark && DARK_BACKDROP) {
1562
1568
  const uBackdrop = { value: 0 };
1563
- const page = pageColour();
1564
1569
  const proxyMat = new THREE.MeshBasicMaterial({ map: ground2.texture, toneMapped: false });
1565
1570
  proxyMat.onBeforeCompile = (shader) => {
1566
1571
  shader.uniforms.uBackdrop = uBackdrop;
@@ -1604,10 +1609,15 @@ void main() {
1604
1609
  })();
1605
1610
  let tallest = 1;
1606
1611
  const boxes = /* @__PURE__ */ new Map();
1612
+ const repeat = (count, ...v) => {
1613
+ const a = new Float32Array(count * v.length);
1614
+ for (let i = 0; i < a.length; i += v.length) for (let k = 0; k < v.length; k++) a[i + k] = v[k];
1615
+ return a;
1616
+ };
1607
1617
  const roundedBox = (w2, h2, d, seg, r) => {
1608
1618
  const key = `${w2.toFixed(4)}|${h2.toFixed(4)}|${d.toFixed(4)}|${seg}|${r.toFixed(4)}`;
1609
1619
  let g = boxes.get(key);
1610
- if (!g) boxes.set(key, g = new RoundedBoxGeometry(w2, h2, d, seg, r));
1620
+ if (!g) boxes.set(key, g = new THREE.BufferGeometry().copy(new RoundedBoxGeometry(w2, h2, d, seg, r)));
1611
1621
  return g.clone();
1612
1622
  };
1613
1623
  const stock = { top: true, bottom: true };
@@ -1624,7 +1634,7 @@ void main() {
1624
1634
  api.bounds = () => bounds;
1625
1635
  let picks = [];
1626
1636
  const LIFT = 0.04;
1627
- const build = (stack2, tones, dark) => {
1637
+ const build = function* (stack2, tones, dark) {
1628
1638
  const tb0 = performance.now();
1629
1639
  picks = [];
1630
1640
  let tileShape = null;
@@ -1647,7 +1657,9 @@ void main() {
1647
1657
  tallest = Math.max(tallest, y0 + h2);
1648
1658
  return y0 + h2;
1649
1659
  };
1650
- stack2.top.cells.forEach((g, i) => {
1660
+ for (let i = 0; i < stack2.top.cells.length; i++) {
1661
+ const g = stack2.top.cells[i];
1662
+ if (i % 48 === 47) yield;
1651
1663
  const w2 = stack2.bottom.cells[i];
1652
1664
  const { x, z } = at(g.week, g.day);
1653
1665
  if (w2.value <= 0 && g.value <= 0) {
@@ -1669,7 +1681,8 @@ void main() {
1669
1681
  c3.toArray(col, q * 3);
1670
1682
  }
1671
1683
  g2.setAttribute("color", new THREE.BufferAttribute(col, 3));
1672
- tileShape = g2;
1684
+ tileShape = new THREE.BufferGeometry().copy(g2);
1685
+ g2.dispose();
1673
1686
  const outer = roundedSquare.getPoints(lite ? 3 : 6);
1674
1687
  const ringShape = new THREE.Shape(outer.map((v) => v.clone().multiplyScalar(1.05)));
1675
1688
  ringShape.holes.push(new THREE.Path(outer.map((v) => v.clone().multiplyScalar(0.955)).reverse()));
@@ -1689,7 +1702,8 @@ void main() {
1689
1702
  c3.toArray(rc, q * 3);
1690
1703
  }
1691
1704
  ring.setAttribute("color", new THREE.BufferAttribute(rc, 3));
1692
- ringShape0 = ring;
1705
+ ringShape0 = new THREE.BufferGeometry().copy(ring);
1706
+ ring.dispose();
1693
1707
  }
1694
1708
  const tile = tileShape.clone();
1695
1709
  tile.translate(x, 0, z);
@@ -1699,12 +1713,12 @@ void main() {
1699
1713
  rims.push(rim);
1700
1714
  pitRims.push({ geom: rim, x, z });
1701
1715
  picks.push({ cell: i, x, z, y0: 0, y1: 0.04, pit: true });
1702
- return;
1716
+ continue;
1703
1717
  }
1704
1718
  let y = 0;
1705
1719
  if (w2.value > 0) y = layer(i, "bottom", x, z, 0, w2.t, tones.bottom) + LIFT;
1706
1720
  if (g.value > 0) layer(i, "top", x, z, y, g.t, tones.top);
1707
- });
1721
+ }
1708
1722
  let blockIndex = 0;
1709
1723
  neonNeighbours = [];
1710
1724
  const shades = dark ? glassShades(specs.map((q) => ({ x: q.x, z: q.z, y0: q.y0, h: q.h })), GLASS_ABSORB, GLASS_FLOOR) : [];
@@ -1734,7 +1748,9 @@ void main() {
1734
1748
  behindTint.set(q, new THREE.Color(1, 1, 1).lerp(mean, Math.min(1, cv) * LIGHT_BEHIND_TINT));
1735
1749
  });
1736
1750
  }
1751
+ let made = 0;
1737
1752
  for (const sp of specs) {
1753
+ if (++made % 24 === 0) yield;
1738
1754
  const { src, x, z, y0, h: h2, t, hue: hue0 } = sp;
1739
1755
  let hue = hue0;
1740
1756
  const inc = new THREE.Color(0, 0, 0);
@@ -1773,8 +1789,8 @@ void main() {
1773
1789
  return new THREE.Color(1, 1, 1).lerp(new THREE.Color(hue0.r / m, hue0.g / m, hue0.b / m), GLOW_TINT);
1774
1790
  })();
1775
1791
  const vcount = shell.getAttribute("position").count;
1776
- shell.setAttribute("aInc", new THREE.BufferAttribute(Float32Array.from({ length: vcount * 3 }, (_, k) => [inc.r, inc.g, inc.b][k % 3] * nbShare), 3));
1777
- shell.setAttribute("aTint", new THREE.BufferAttribute(Float32Array.from({ length: vcount * 3 }, (_, k) => [glowTint.r, glowTint.g, glowTint.b][k % 3]), 3));
1792
+ shell.setAttribute("aInc", new THREE.BufferAttribute(repeat(vcount, inc.r * nbShare, inc.g * nbShare, inc.b * nbShare), 3));
1793
+ shell.setAttribute("aTint", new THREE.BufferAttribute(repeat(vcount, glowTint.r, glowTint.g, glowTint.b), 3));
1778
1794
  const tier = tEff < 0.34 ? 0 : tEff < 0.67 ? 1 : 2;
1779
1795
  const key = `${src}${tier}`;
1780
1796
  (shellsBy.get(key) ?? shellsBy.set(key, []).get(key)).push(shell);
@@ -1795,18 +1811,20 @@ void main() {
1795
1811
  core.setAttribute("aInc", new THREE.BufferAttribute(incs, 3));
1796
1812
  }
1797
1813
  core.setAttribute("aBlock", new THREE.BufferAttribute(new Float32Array(core.getAttribute("position").count).fill(blockIndex++), 1));
1798
- core.setAttribute("aCtr", new THREE.BufferAttribute(Float32Array.from({ length: core.getAttribute("position").count * 2 }, (_, k) => k % 2 ? z : x), 2));
1814
+ core.setAttribute("aCtr", new THREE.BufferAttribute(repeat(core.getAttribute("position").count, x, z), 2));
1799
1815
  cores.push(core);
1800
1816
  }
1801
1817
  if (dark) {
1802
1818
  pitRims.forEach((pr, pi) => {
1803
1819
  pr.geom.setAttribute("aPit", new THREE.BufferAttribute(new Float32Array(pr.geom.getAttribute("position").count).fill(pi), 1));
1804
- const lamps = [];
1820
+ const near = [];
1805
1821
  specs.forEach((sp, si) => {
1806
- const d = Math.hypot(sp.x - pr.x, sp.z - pr.z);
1807
- if (d >= 0.5 && d <= 4) lamps.push({ si, w: emit(sp.t) * Math.exp(-(d * d) / (2 * 1.6 * 1.6)) });
1822
+ const dx = sp.x - pr.x;
1823
+ const dz = sp.z - pr.z;
1824
+ const dist = Math.hypot(dx, dz);
1825
+ if (dist >= 0.5 && dist <= 4) near.push({ si, dx, dz, dist, w: emit(sp.t) * Math.exp(-(dist * dist) / (2 * 1.6 * 1.6)) });
1808
1826
  });
1809
- pitLamps.push(lamps);
1827
+ pitLamps.push(near.map(({ si, w: w2 }) => ({ si, w: w2 })));
1810
1828
  const rp = pr.geom.getAttribute("position");
1811
1829
  const rc = pr.geom.getAttribute("color");
1812
1830
  for (let q = 0; q < rp.count; q++) {
@@ -1816,29 +1834,28 @@ void main() {
1816
1834
  let r = 0;
1817
1835
  let gg = 0;
1818
1836
  let bb = 0;
1819
- for (const sp of specs) {
1820
- const dx = sp.x - pr.x;
1821
- const dz = sp.z - pr.z;
1822
- const dist = Math.hypot(dx, dz);
1823
- if (dist < 0.5 || dist > 4) continue;
1837
+ for (const { si, dx, dz, dist, w: w2 } of near) {
1824
1838
  const facing = Math.max(0, (-(rx / rl) * dx - rz / rl * dz) / dist);
1825
1839
  if (facing <= 0) continue;
1826
- const k = emit(sp.t) * Math.exp(-(dist * dist) / (2 * 1.6 * 1.6)) * facing * facing * 0.018;
1827
- r += sp.hue.r * k;
1828
- gg += sp.hue.g * k;
1829
- bb += sp.hue.b * k;
1840
+ const k = w2 * facing * facing * 0.018;
1841
+ const hue = specs[si].hue;
1842
+ r += hue.r * k;
1843
+ gg += hue.g * k;
1844
+ bb += hue.b * k;
1830
1845
  }
1831
1846
  rc.setXYZ(q, page.r + Math.min(r, 0.1), page.g + Math.min(gg, 0.1), page.b + Math.min(bb, 0.1));
1832
1847
  }
1833
1848
  rc.needsUpdate = true;
1834
1849
  });
1835
1850
  }
1851
+ yield;
1836
1852
  const tb1 = performance.now();
1837
1853
  const group = new THREE.Group();
1838
- const groundGroup = groundLayers(stack2, tones, dark);
1854
+ const groundGroup = groundLayers(stack2, tones, dark, page);
1839
1855
  pitLight = groundGroup.userData.setLevels ?? null;
1840
1856
  group.add(groundGroup);
1841
1857
  const tb2 = performance.now();
1858
+ yield;
1842
1859
  rimLight = null;
1843
1860
  if (tiles.length) {
1844
1861
  const tile = new THREE.Mesh(mergeGeometries(tiles), tileUnlit);
@@ -1870,6 +1887,7 @@ void main() {
1870
1887
  }
1871
1888
  const materials = [];
1872
1889
  for (const [key, list] of shellsBy) {
1890
+ yield;
1873
1891
  const [src, tier] = shellTier.get(key);
1874
1892
  const mat = blockMaterial.clone();
1875
1893
  if (dbg.wireframe) {
@@ -1934,17 +1952,18 @@ void main() {
1934
1952
  const blocks = new THREE.Group();
1935
1953
  scene.add(blocks);
1936
1954
  const ground0 = () => ground.material.opacity = isDark() ? 0 : 0.05;
1937
- const buildBlocks = () => {
1938
- showMat.uniforms.bloom.value = isDark() ? customOn() ? 0.4 : 1 : 0;
1939
- showMat.uniforms.veil.value = customOn() ? 0.75 : 0;
1940
- scene.environmentIntensity = isDark() ? 0 : 0.9;
1941
- sun.intensity = isDark() ? 0 : 2.2;
1942
- ground0();
1943
- blocks.traverse((o) => {
1944
- o.geometry?.dispose();
1945
- o.userData.dispose?.();
1946
- });
1947
- blocks.clear();
1955
+ let buildToken = 0;
1956
+ let building = false;
1957
+ let fitted = false;
1958
+ const BUILD_SLICE = 12;
1959
+ const buildBlocks = (done) => {
1960
+ const token = ++buildToken;
1961
+ building = true;
1962
+ stopNeon();
1963
+ window.clearTimeout(focusTimer);
1964
+ window.clearTimeout(focusRaf);
1965
+ cancelAnimationFrame(raf);
1966
+ raf = 0;
1948
1967
  const dark = isDark();
1949
1968
  const pair = (layer) => {
1950
1969
  const [low, high] = colorOf(layer, dark);
@@ -1956,7 +1975,39 @@ void main() {
1956
1975
  }
1957
1976
  return [new THREE.Color(low), new THREE.Color(high)];
1958
1977
  };
1959
- blocks.add(build({ bottom: layout.bottom, top: layout.top }, { bottom: pair("bottom"), top: pair("top") }, dark));
1978
+ const steps = cm(() => build({ bottom: layout.bottom, top: layout.top }, { bottom: pair("bottom"), top: pair("top") }, dark));
1979
+ const step = () => {
1980
+ if (cancelled || token !== buildToken) return;
1981
+ const t = performance.now();
1982
+ let result;
1983
+ try {
1984
+ result = cm(() => {
1985
+ let r = steps.next();
1986
+ while (!r.done && performance.now() - t < BUILD_SLICE) r = steps.next();
1987
+ return r;
1988
+ });
1989
+ } catch (e) {
1990
+ building = false;
1991
+ throw e;
1992
+ }
1993
+ if (!result.done) return void window.setTimeout(step, 0);
1994
+ cm(() => {
1995
+ showMat.uniforms.bloom.value = dark ? customOn() ? 0.4 : 1 : 0;
1996
+ showMat.uniforms.veil.value = customOn() ? 0.75 : 0;
1997
+ scene.environmentIntensity = dark ? 0 : 0.9;
1998
+ sun.intensity = dark ? 0 : 2.2;
1999
+ ground0();
2000
+ blocks.traverse((o) => {
2001
+ o.geometry?.dispose();
2002
+ o.userData.dispose?.();
2003
+ });
2004
+ blocks.clear();
2005
+ blocks.add(result.value);
2006
+ building = false;
2007
+ done();
2008
+ });
2009
+ };
2010
+ step();
1960
2011
  };
1961
2012
  const floor = new THREE.Mesh(new THREE.PlaneGeometry(1200, 1200), new THREE.MeshBasicMaterial({ color: pageColour() }));
1962
2013
  floor.rotation.x = -Math.PI / 2;
@@ -2111,6 +2162,7 @@ void main(){
2111
2162
  return r;
2112
2163
  };
2113
2164
  const fit = () => {
2165
+ fitted = true;
2114
2166
  const size = renderSize({ cssWidth: el.clientWidth, cssHeight: el.clientHeight, devicePixelRatio: window.devicePixelRatio, lite, maxPixelRatio: opts.maxPixelRatio, maxPixels: opts.maxPixels, maxSize: renderer.capabilities.maxTextureSize });
2115
2167
  w = size.width;
2116
2168
  h = size.height;
@@ -2186,6 +2238,7 @@ void main(){
2186
2238
  let blendFloor = 0;
2187
2239
  let jitter = 0;
2188
2240
  const frameBody = (count = 1) => {
2241
+ if (building) return void (raf = 0);
2189
2242
  raf = 0;
2190
2243
  const f0 = performance.now();
2191
2244
  for (let c = 0; c < count; c++) {
@@ -2286,6 +2339,7 @@ void main(){
2286
2339
  let focusRaf = 0;
2287
2340
  let focusTimer = 0;
2288
2341
  const applyLevels = (levels) => {
2342
+ if (building) return;
2289
2343
  lastLevels = levels;
2290
2344
  const n2 = neonBlocks.length;
2291
2345
  if (effective.length !== n2) effective = new Float32Array(n2).fill(1);
@@ -2333,7 +2387,7 @@ void main(){
2333
2387
  const GHOST = 0.12;
2334
2388
  const focusOn = (cell, ghosts = []) => {
2335
2389
  window.clearTimeout(focusTimer);
2336
- if (!focusCtl) return;
2390
+ if (!focusCtl || building) return;
2337
2391
  focusTimer = window.setTimeout(() => {
2338
2392
  for (let i = 0; i < focusTo.length; i++) focusTo[i] = cell < 0 ? 1 : neonBlocks[i].cell === cell ? Math.min(FOCUS_MAX_GAIN, Math.max(FOCUS_ON, FOCUS_MIN_PEAK / Math.max(neonBlocks[i].peak, 1e-3))) : ghosts.includes(neonBlocks[i].cell) ? GHOST : FOCUS_OFF;
2339
2393
  window.clearTimeout(focusRaf);
@@ -2413,8 +2467,10 @@ void main(){
2413
2467
  ctl.update(half);
2414
2468
  }
2415
2469
  };
2416
- buildBlocks();
2417
- prepareNeon();
2470
+ buildBlocks(() => {
2471
+ prepareNeon();
2472
+ if (fitted) restart();
2473
+ });
2418
2474
  const dom = renderer.domElement;
2419
2475
  const ray = new THREE.Raycaster();
2420
2476
  const ndc = new THREE.Vector2();
@@ -2615,9 +2671,10 @@ void main(){
2615
2671
  void wantTemplates().then(() => !cancelled && rethink(recolour));
2616
2672
  return;
2617
2673
  }
2618
- buildBlocks();
2619
- prepareNeon(recolour);
2620
- restart();
2674
+ buildBlocks(() => {
2675
+ prepareNeon(recolour);
2676
+ restart();
2677
+ });
2621
2678
  };
2622
2679
  const onScheme = () => st.theme === "auto" && rethink(false);
2623
2680
  mq.addEventListener("change", onScheme);
@@ -2903,4 +2960,4 @@ export {
2903
2960
  createHoverOverlay,
2904
2961
  createActivityGraph
2905
2962
  };
2906
- //# sourceMappingURL=chunk-METLYI5N.js.map
2963
+ //# sourceMappingURL=chunk-UTH7N6HE.js.map