GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Kuiper, cosmos and drawing engines / galaxies-wafers / iterations/30-journey

Iterations — 30 Journey and 2 more files

A JavaScript module in Galaxies Wafers that draws lines meta, families, crossname and substations, using SHA-256. Served with the page at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.

617 lines of JavaScript and CSS and HTML from galaxies-wafers, in 3 files. Topic: Kuiper, cosmos and drawing engines. Section 1202 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Iterations — 30 Journey render · galaxies-wafers / iterations/30-journey/app.mjs lines 701–1165
  2. Iterations — 30 Journey Page render · galaxies-wafers / iterations/30-journey/index.html lines 1–61
  3. Iterations — 30 Journey Style Sheet render · galaxies-wafers / iterations/30-journey/style.css lines 1–91

Iterations — 30 Journey

A JavaScript module in Galaxies Wafers that draws lines meta, families, crossname and substations, using SHA-256. Served with the page at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.

rendergalaxies-wafers / iterations/30-journey/app.mjs · lines 701–1165 of 1165 (continued from section 1201) · Entry point · pattern visibleBand (shared by 2 files)

What it does
It draws lines meta, families, crossname and substations. Defines 60 functions or classes, including levelOf, $, enqueue, pump, fetchWithTimeout. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage sub33kv_design (voltage levels 11kV (all 33kV or below)): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: substations, 11kV. README: "The page (`index.html`, `app.mjs`, `lib.mjs`) is inherited unchanged from testcode/202609151339."
Inputs & outputs
In: JSON file index.json; JSON file all-lines.meta.json; JSON file families.json; JSON file crossname.json. Out: canvas drawing. Voltage levels named: 11kV.
Downstream impact
Used directly by 1 file: Iterations — 30 Journey Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/). It is itself an entry point, published at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.
What it achieves
It fetches timeout (`fetchWithTimeout`), fetches JSON (`fetchJSON`) and fetches bin (`fetchBin`). Journey: the Line Wafer read by level of detail, and by following one thread. Its code works with 11 kV. It responds to pointerdown, pointermove and pointerup events.
Why it matters
Loaded by the page of the same name at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.
Application
galaxies-wafers · iterations/30-journey · JavaScript module
Uses
Galaxies Wafers — Lib (import)
Used by
loaded by Iterations — 30 Journey Page (script src)
Produces
levelOf, $, enqueue, pump, fetchWithTimeout, fetchJSON, fetchBin, tilesToggle, wantTiles, paintTileRow, loadModule, scheduleHubs
Defines here
familyThread, copyChains, find, wakeNamed, follow, leave, stopCross, goStop, radiusBand, elementMatch, threadPatterns, questionsOpen, paintStop, sizeStrip, paintStrip, X, keyCard, dotCard, tapAt, paintPageQuestions, gestures, up, writeURL, openThread
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
galaxies-wafers@5814793812add74605660fa821e6a39b8de80588 iterations/30-journey/app.mjs:701-1165 · blob de1694499db2cbdbb106f480f7c683231b67c0bd · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: unknown
}

function familyThread(moduleId, family) {
  const row = MOD.get(moduleId), r = row.data.routes.find(x => x.family === family);
  const n = r.keys.length;
  const stops = Array.from(r.keys, (k, j) => ({ key: k, fn: r.fn, title: `${r.fn} · line ${j + 1} of ${n}`, family, lines: r.lines, xy: r.xy, routeKeys: r.keys }));
  return { kind: 'family', id: `${moduleId}~${family}`, module: moduleId, label: `${r.fn} in ${row.label}`, colour: row.colour, stops,
           order: 'stops are the function\'s own lines in the order the layer file routes them' };
}

let chainCache = null, chainPromise = null;
function copyChains() {
  if (chainPromise) return chainPromise;
  $('chains').textContent = 'LOAD…';
  chainPromise = fetchJSON('../../layers/crossname.json').then(fc => {
    const parent = new Map(), info = new Map(), edges = [];
    const find = a => { while (parent.get(a) !== a) { parent.set(a, parent.get(parent.get(a))); a = parent.get(a); } return a; };
    for (const f of fc.features) {
      const p = f.properties, [ka, kb] = f.geometry.keys;
      for (const [fam, k] of [[p.a, ka], [p.b, kb]]) {
        if (!parent.has(fam.family)) { parent.set(fam.family, fam.family); info.set(fam.family, { key: k, name: fam.name, category: fam.category }); }
      }
      parent.set(find(p.a.family), find(p.b.family));
      edges.push([p.a.family, p.b.family, p.overlap, p.shared]);
    }
    const comps = new Map();
    for (const fam of parent.keys()) { const root = find(fam); if (!comps.has(root)) comps.set(root, []); comps.get(root).push(fam); }
    const edgeOf = new Map();
    for (const [a, b, ov, sh] of edges) { edgeOf.set(a + ':' + b, [ov, sh]); edgeOf.set(b + ':' + a, [ov, sh]); }
    chainCache = [...comps.values()].filter(cc => cc.length >= 3).sort((a, b) => b.length - a.length).map((fams, ci) => {
      const stops = fams.map(f => ({ key: info.get(f).key, fn: info.get(f).name, title: info.get(f).name, family: f, category: info.get(f).category }))
        .sort((a, b) => a.key - b.key);
      stops.forEach((s, j) => { if (j + 1 < stops.length) s.link = edgeOf.get(s.family + ':' + stops[j + 1].family) || null; });
      return { kind: 'copy', id: `copy~${ci}`, module: null, label: `copy chain ${ci + 1}: ${stops[0].title} and ${fmt(stops.length - 1)} more`, colour: '#ff00ff', stops,
               order: 'stops are the chain\'s functions, at their first lines, in numbering order' };
    });
    const sel = $('thread'), g = document.createElement('optgroup');
    g.label = `COPY CHAINS · ${fmt(chainCache.length)} of three or more functions, from ${fmt(fc.features.length)} copied pairs`;
    chainCache.forEach(t => { const o = document.createElement('option'); o.value = t.id; o.textContent = t.label; g.appendChild(o); });
    sel.insertBefore(g, sel.children[1]);
    $('chains').textContent = `${fmt(chainCache.length)} CHAINS`;
    return chainCache;
  }).catch(e => { $('chains').textContent = 'FAIL'; chainPromise = null; throw e; });
  return chainPromise;
}

/* The named module groups wake together; the long "OTHER" group only on its own request. */
const OTHER = 'MODULES · OTHER';
function wakeNamed() { for (const r of MODS) if (r.group !== OTHER) loadModule(r.id).catch(() => {}); }

async function follow(thread, i = 0) {
  F.thread = thread;
  F.keySet = new Set();
  for (const s of thread.stops) { F.keySet.add(s.key); if (s.routeKeys) for (const k of s.routeKeys) F.keySet.add(k); }
  $('follow').hidden = false; document.body.classList.add('following');
  sizeStrip();
  wakeNamed();
  tier2();
  await goStop(i);
}

function leave() {
  F.thread = null; F.keySet = null; F.cross = null; flight++;
  $('follow').hidden = true; $('card').hidden = true; document.body.classList.remove('following');
  $('thread').value = '';
  writeURL();
  draw();
}

function stopCross(key) {
  const m = keyMods.get(key);
  return m ? [...m.keys()].filter(id => id !== F.thread?.module) : [];
}

async function goStop(i) {
  const T = F.thread; if (!T) return;
  F.i = Math.max(0, Math.min(i, T.stops.length - 1));
  const s = T.stops[F.i], nx = T.stops[F.i + 1] || T.stops[F.i - 1] || s;
  F.cross = new Set(stopCross(s.key));
  paintStop(); paintStrip(); writeURL();
  const [x, y] = place(s.key), [x2, y2] = place(nx.key);
  /* arrive at PLANET so the stop's own lines exist; frame the next stop too when it is close enough */
  const span = Math.max(Math.hypot(x2 - x, y2 - y), 6);
  const z = Math.max(LEVELS[2].go, Math.min(120, Math.min(view.w, view.h * 0.45) / (span * 2.4)));
  stats.stopsVisited++;
  await flyTo(x, y, z);
}

/* ── the stop card ───────────────────────────────────────────────────────── */

function radiusBand(key) { return Math.min(BANDS - 1, Math.floor(S * Math.sqrt(key) / U.maxR * BANDS)); }

/* Q1 is answered by name match only: which drawing element, if any, the
   function's own name or its block's label names. It is marked as inference
   and the matched text is printed, so a false match can be seen. */
const ELEMENTS = [
  [/busbar/i, 'busbar'], [/feeder/i, 'feeder'], [/transformer/i, 'transformer'],
  [/cable|trench|conductor|overhead/i, 'cable route'], [/route/i, 'route (cable route or path)'],
  [/protect|fault|relay|breaker/i, 'protection'], [/earthing|earthed/i, 'earthing'],
  [/substation/i, 'substation'], [/voltage|rating|kv\b/i, 'rating or voltage annotation'],
  [/single.?line|\bsld\b/i, 'single-line diagram']
];
function elementMatch(...texts) {
  for (const t of texts) {
    if (!t) continue;
    for (const [re, el] of ELEMENTS) { const m = String(t).match(re); if (m) return { el, text: t, hit: m[0] }; }
  }
  return null;
}

function threadPatterns(T) {
  const st = T.stops, bands = new Set();
  let longest = 0, la = st[0].key, lb = st[0].key, dist = 0, junctions = 0, inner = 0, legs = 0;
  const innerR = U.maxR / BANDS;
  st.forEach((s, j) => {
    bands.add(radiusBand(s.key));
    if (stopCross(s.key).length) junctions++;
    if (j + 1 < st.length) {
      const hop = Math.abs(st[j + 1].key - s.key);
      if (hop > longest) { longest = hop; la = s.key; lb = st[j + 1].key; }
      const [ax, ay] = place(s.key), [bx, by] = place(st[j + 1].key);
      dist += Math.hypot(bx - ax, by - ay);
    }
  });
  const seenRoute = new Set();
  for (const s of st) {
    if (!s.xy || seenRoute.has(s.xy)) continue; seenRoute.add(s.xy);
    for (let j = 0; j + 1 < s.xy.length / 2; j++) {
      legs++;
      const ax = s.xy[j * 2], ay = s.xy[j * 2 + 1], dx = s.xy[j * 2 + 2] - ax, dy = s.xy[j * 2 + 3] - ay;
      const t = Math.max(0, Math.min(1, -(ax * dx + ay * dy) / (dx * dx + dy * dy || 1)));
      if (Math.hypot(ax + dx * t, ay + dy * t) < innerR) inner++;
    }
  }
  let minB = BANDS, maxB = -1;
  for (const b of bands) { minB = Math.min(minB, b); maxB = Math.max(maxB, b); }
  return { bands: bands.size, minB, maxB, longest, la, lb, meanHop: st.length > 1 ? dist / (st.length - 1) : 0, junctions, inner, legs };
}

const questionsOpen = () => window.innerWidth >= 760;

function paintStop() {
  const T = F.thread; if (!T) return;
  const s = T.stops[F.i], next = T.stops[F.i + 1], prev = T.stops[F.i - 1];
  const idx = indexOfKey(U.keys, s.key);
  const cross = stopCross(s.key);
  const nW = woken().length;
  const P = threadPatterns(T);
  const fam = U.famCount && idx >= 0 ? U.famCount[idx] : null;
  const row = T.module ? MOD.get(T.module) : null;
  const st = row?.data?.stats || {};
  const keep = $('cardbody').querySelector('details.qs');
  const open = keep ? keep.open : questionsOpen();

  const match = elementMatch(s.fn, row?.label);
  const drawnAs = cross.length
    ? `a substation symbol carrying the count ${fmt(cross.length)} in the strip, because ${fmt(cross.length)} other woken ${cross.length === 1 ? 'route passes' : 'routes pass'} through line ${fmt(s.key)}`
    : `a busbar in the strip: no other woken route passes through line ${fmt(s.key)}`;
  const q1 = `On this page the stop is drawn as ${drawnAs} (paintStrip reads keyMods). In a power-system drawing: ` + (match
    ? `<b>${esc(match.el)}</b>, by name-match inference: "${esc(match.hit)}" in "${esc(match.text)}". The layer file carries the function name (properties.function) and the block label, not the element, so this is a reading of the name, not a record.`
    : `<b>none yet</b>: neither the function name "${esc(s.fn)}"${row ? ` nor the block label "${esc(row.label)}"` : ''} names a busbar, feeder, transformer, cable route, protection, earthing or substation.`);

  let q2;
  if (T.kind === 'copy') {
    q2 = `Function <span class="fam">${esc(s.fn)}</span>, family #${fmt(s.family)}, category ${esc(s.category ?? 'not recorded')}, from layers/crossname.json. It shares six or more usable lines with a differently named function in this chain. No block, file or commit is recorded for it in that layer. Callers: not established; this page holds line numbers and names, not call sites.`;
  } else {
    const files = (st.files || []).slice(0, 3);
    q2 = `Block <b>${esc(row.label)}</b> (${esc(row.group)}), function <span class="fam">${esc(s.fn)}</span>, family #${fmt(s.family)}, ${fmt(s.lines)} lines. `
      + `Register evidence: ${esc(row.evidence || 'none recorded')}. `
      + (files.length ? `Files named for the block: ${files.map(f => esc(f)).join(' · ')}${(st.files || []).length > 3 ? ` and ${fmt(st.files.length - 3)} more` : ''}. ` : 'No files are named in the layer file. ')
      + (st.commit ? `Commit ${esc(String(st.commit).slice(0, 12))}. ` : 'No commit recorded. ')
      + `Callers: not established; the layer holds line numbers, not call sites. Shared text is not a call.`;
  }

  let q3 = next
    ? `Next stop line ${fmt(next.key)}, <span class="fam">${esc(next.title)}</span>, ${fmt(Math.abs(next.key - s.key))} keys on${s.link ? `; a copied pair sharing ${fmt(s.link[1])} lines` : ''}.`
    : `No next stop: this is the last of ${fmt(T.stops.length)}.`;
  q3 += cross.length
    ? ` ${fmt(cross.length)} other ${cross.length === 1 ? 'route crosses' : 'routes cross'} here (counted over ${fmt(nW)} of ${fmt(MODS.length)} woken): ${cross.slice(0, 5).map(id => esc(MOD.get(id).label)).join(' · ')}${cross.length > 5 ? ' …' : ''}.`
    : ` No other route crosses here, counted over ${fmt(nW)} of ${fmt(MODS.length)} woken.`;
  q3 += ` Families carrying this line: ${fam == null ? 'not yet known, the family index is ' + esc(U.tier2) : fmt(fam)}.`;

  const machine = `inputs: key ${fmt(s.key)} (permanent line number, integer, 1 to ${fmt(U.meta.max)}), stop index ${fmt(F.i + 1)} of ${fmt(T.stops.length)}; `
    + `outputs: position r = ${(S * Math.sqrt(s.key)).toFixed(2)} wafer units, θ = key × golden angle (lib.mjs place), radius band ${fmt(radiusBand(s.key) + 1)} of ${BANDS}, `
    + `characters ${idx < 0 ? 'never issued' : U.lens[idx] === 65535 ? '≥ 65,535' : fmt(U.lens[idx])}, crossings ${fmt(cross.length)}; `
    + `refusals: EMPTY when a thread has no first-line points, "never issued" for a skipped number, FAIL with the HTTP status; `
    + `source: ${row ? `${esc(row.file)}${st.commit ? ' at commit ' + esc(String(st.commit).slice(0, 12)) : ''}` : 'layers/crossname.json'}, pack ${esc(U.meta.source.sha256.slice(0, 12))}.`;

  let h = `<h2>Stop <span class="n">${fmt(F.i + 1)}</span> of ${fmt(T.stops.length)} · line <span class="n">${fmt(s.key)}</span></h2>
    <p><span class="fam">${esc(s.title)}</span> <span class="dim">· ${esc(T.label)}</span></p>
    <p class="dim">${esc(T.order)}${prev ? ` · came from line ${fmt(prev.key)}` : ''}</p>
    <details class="qs"${open ? ' open' : ''}><summary>Questions</summary>
      <ol class="q3">
        <li><span class="dim">How does this help draw a system or a single-line diagram?</span> ${q1}</li>
        <li><span class="dim">What is this code used for?</span> ${q2}</li>
        <li><span class="dim">Where does it lead next?</span> ${q3}</li>
      </ol>
      <p class="machine"><b>Machine detail</b> · ${machine}</p>
    </details>`;
  if (T.kind === 'module' && s.xy) h += `<p><button type="button" class="act" data-walk="${esc(T.module)}~${s.family}">WALK THIS FUNCTION LINE BY LINE</button></p>`;
  if (T.kind === 'family') h += `<p><button type="button" class="act" data-back="${esc(T.module)}">BACK TO THE WHOLE BLOCK</button></p>`;
  h += `<h3>Pattern questions</h3><ul class="q">
    <li><span class="dim">What shape is this thread?</span> Its ${fmt(T.stops.length)} stops span ${fmt(P.bands)} of ${BANDS} radius bands (band ${fmt(P.minB + 1)} to ${fmt(P.maxB + 1)}).</li>
    <li><span class="dim">How far does one hop go?</span> The longest hop is ${fmt(P.longest)} keys, from line ${fmt(P.la)} to ${fmt(P.lb)}; a hop averages ${P.meanHop.toFixed(1)} units across the wafer.</li>
    <li><span class="dim">Where do threads meet?</span> ${fmt(P.junctions)} of ${fmt(T.stops.length)} stops are lines another woken route also passes through.</li>
    <li><span class="dim">Where would it tangle?</span> ${fmt(P.inner)} of ${fmt(P.legs)} route legs drawn for this thread cross the inner tenth of the wafer, where the most shared lines sit.</li>
  </ul>`;
  $('cardbody').innerHTML = h;
  $('card').hidden = false;
}

/* ── the strip: the same thread as one straight line ─────────────────────── */

const sld = $('sld'), sc = sld.getContext('2d');
const STEP = 58;
function sizeStrip() {
  const r = sld.getBoundingClientRect();
  sld.width = Math.max(1, Math.round(r.width * view.dpr)); sld.height = Math.max(1, Math.round(r.height * view.dpr));
  if (F.thread) paintStrip();
}
function paintStrip() {
  const T = F.thread; if (!T) return;
  const w = sld.width / view.dpr, h = sld.height / view.dpr, mid = h * 0.52;
  sc.setTransform(view.dpr, 0, 0, view.dpr, 0, 0);
  sc.fillStyle = '#070a10'; sc.fillRect(0, 0, w, h);
  const cx = w / 2, reach = Math.ceil(cx / STEP) + 1;
  const first = Math.max(0, F.i - reach), last = Math.min(T.stops.length - 1, F.i + reach);
  const X = j => cx + (j - F.i) * STEP;
  sc.strokeStyle = T.colour; sc.lineWidth = 2.2;
  sc.beginPath(); sc.moveTo(Math.max(0, X(0)), mid); sc.lineTo(Math.min(w, X(T.stops.length - 1)), mid); sc.stroke();
  sc.font = '9px ui-monospace,Menlo,Consolas,monospace'; sc.textAlign = 'center';
  for (let j = first; j <= last; j++) {
    const s = T.stops[j], x = X(j), cur = j === F.i, near = Math.abs(j - F.i) === 1;
    const n = stopCross(s.key).length;
    if (j + 1 <= last) { sc.fillStyle = '#6f7890'; const d = T.stops[j + 1].key - s.key; sc.fillText((d >= 0 ? '+' : '−') + fmt(Math.abs(d)), x + STEP / 2, mid - 5); }
    if (n) {
      sc.fillStyle = '#05070b'; sc.strokeStyle = cur ? '#ffd54a' : '#ffffff'; sc.lineWidth = 1.4;
      sc.fillRect(x - 8, mid - 8, 16, 16); sc.strokeRect(x - 8, mid - 8, 16, 16);
      sc.beginPath(); sc.moveTo(x - 5, mid - 3); sc.lineTo(x + 5, mid - 3); sc.moveTo(x - 5, mid + 3); sc.lineTo(x + 5, mid + 3); sc.stroke();
      sc.fillStyle = cur ? '#ffd54a' : '#e6e9ef'; sc.fillText(fmt(n), x, mid - 12);
    } else {
      sc.strokeStyle = cur ? '#ffd54a' : near ? '#ffffff' : '#8b93a7'; sc.lineWidth = cur ? 4 : 3;
      sc.beginPath(); sc.moveTo(x, mid - 11); sc.lineTo(x, mid + 11); sc.stroke();
    }
    sc.fillStyle = cur ? '#ffd54a' : '#8b93a7';
    sc.fillText(fmt(s.key), x, mid + 22);
    if (cur) { sc.fillStyle = '#d8dee9'; const t = s.title.length > 24 ? s.title.slice(0, 23) + '…' : s.title; sc.fillText(t, x, 11); }
  }
  sc.textAlign = 'left';
}

/* ── cards without a thread: the SYSTEM dot and the SURFACE line ─────────── */

let cardKey = -1;
function keyCard(key) {
  cardKey = key;
  const i = indexOfKey(U.keys, key);
  const m = keyMods.get(key);
  let h = `<h2>Line <span class="n">${fmt(key)}</span></h2><dl>
    <dt>characters</dt><dd>${i < 0 ? 'never issued' : U.lens[i] === 65535 ? 'at least 65,535' : fmt(U.lens[i])}</dd>
    <dt>carried</dt><dd>${i >= 0 && U.inFam[i] ? 'by at least one function family' : 'by no function family'}</dd>
    <dt>families</dt><dd>${U.famCount && i >= 0 ? fmt(U.famCount[i]) : 'not yet known: family index ' + esc(U.tier2)}</dd>
    <dt>radius band</dt><dd>${fmt(radiusBand(key) + 1)} of ${BANDS}</dd></dl>`;
  if (m && m.size) {
    h += `<h3>Blocks through this line</h3><ul>` + [...m].slice(0, 10).map(([id, fn]) =>
      `<li><span class="fam">${esc(fn)}</span> <span class="dim">${esc(MOD.get(id).label)}</span> <button type="button" class="act small" data-follow="${esc(id)}" data-at="">FOLLOW</button></li>`).join('') +
      (m.size > 10 ? `<li class="dim">and ${fmt(m.size - 10)} more</li>` : '') + `</ul>`;
  } else {
    h += `<p class="dim">No woken module route passes through this line (${fmt(woken().length)} of ${fmt(MODS.length)} woken).</p>`;
  }
  if (U.famCount && U.families && i >= 0 && U.famCount[i] && U.famCount[i] <= 40) {
    const names = [];
    for (let f = 0; f < U.families.length && names.length < 8; f++) {
      const o = U.families[f].lineOffset, c = U.families[f].lineCount;
      for (let j = o; j < o + c; j++) if (U.famLines[j] === key) { names.push(U.families[f]); break; }
    }
    h += `<h3>Families carrying it</h3><ul>` + names.map(fa => `<li><span class="fam">${esc(fa.name)}</span> <span class="dim">#${fmt(fa.n)} · ${esc(fa.category ?? 'no category recorded')}</span></li>`).join('') + `</ul>`;
  }
  $('cardbody').innerHTML = h; $('card').hidden = false;
}

function dotCard(row, s) {
  cardKey = -1;
  const m = keyMods.get(s.key);
  $('cardbody').innerHTML = `<h2><span class="fam">${esc(s.fn)}</span></h2><dl>
    <dt>block</dt><dd>${esc(row.label)}</dd>
    <dt>family</dt><dd>#${fmt(s.family)}</dd>
    <dt>first line</dt><dd>${fmt(s.key)}</dd>
    <dt>lines</dt><dd>${fmt(s.lines)}</dd>
    <dt>shared</dt><dd>${fmt(m ? m.size - 1 : 0)} other woken routes pass through its first line</dd></dl>
    <p class="dim">${esc(row.note || '')}</p>
    <p><button type="button" class="act" data-follow="${esc(row.id)}" data-at="${s.key}">FOLLOW THIS BLOCK FROM HERE</button></p>`;
  $('card').hidden = false;
}

function tapAt(cx, cy) {
  const L = levelOf(view.zoom);
  let best = null, bd = 18 * 18;
  if (L >= 1) {
    for (const row of woken()) for (const s of row.data.firsts) {
      const dx = sx(s.x) - cx, dy = sy(s.y) - cy, d = dx * dx + dy * dy;
      if (d < bd) { bd = d; best = [row, s]; }
    }
  }
  if (F.thread) return;
  if (L === 3) {
    let bi = -1, bdi = Math.min(bd, 16 * 16);
    for (let j = 0; j < drawnN; j++) {
      const i = drawnIdx[j], dx = sx(U.pos[i * 2]) - cx, dy = sy(U.pos[i * 2 + 1]) - cy, d = dx * dx + dy * dy;
      if (d < bdi) { bdi = d; bi = i; }
    }
    if (bi >= 0) { keyCard(U.keys[bi]); tier2(); return; }
  }
  if (best) dotCard(best[0], best[1]);
}

/* ── the page's own questions ────────────────────────────────────────────── */

function paintPageQuestions() {
  const named = MODS.filter(r => r.group !== OTHER).length;
  const el = $('pageq');
  el.open = questionsOpen();
  el.querySelector('.body').innerHTML = `<ol class="q3">
    <li><span class="dim">How does this help draw a system or a single-line diagram?</span> It draws one thread as a <b>single-line strip</b>: a straight line with each stop as a <b>busbar</b>, and a line shared by other routes as a <b>substation</b> symbol with its count (paintStrip, from the keys in layers/modules/*.json). On the wafer it draws module routes as cased <b>routes</b>. None of it is  … [line shortened here: 428 characters; full line on GitHub]
    <li><span class="dim">What is this code used for?</span> Reading the ${fmt(MODS.length)} module routes in layers/manifest.json (${fmt(named)} in named groups, ${fmt(MODS.length - named)} in ${OTHER}) one level of detail and one thread at a time. It places keys with place and placeAll from lib.mjs and counts families from families.json and lines.bin. Callers: none in the estate; it is a page.</  … [line shortened here: 403 characters; full line on GitHub]
    <li><span class="dim">Where does it lead next?</span> Pick a thread: each stop names the next stop, the routes that cross there and, when a name says so, the drawing element it may feed.</li>
  </ol>
  <p class="machine"><b>Machine detail</b> · inputs: permanent keys (integers 1 to ${fmt(U.meta.max)}), zoom (screen px per wafer unit), thread id (layer id, layer~family, or copy~n); outputs: level (GALAXY below ${LEVELS[1].min}, SYSTEM below ${LEVELS[2].min}, PLANET below ${LEVELS[3].min}, SURFACE), visible key band [(r0/S)², (r1/S)²] with S = ${S}, keys drawn per frame (counted, ceiling ${fmt(D  … [line shortened here: 1,100 characters; full line on GitHub]
}

/* ── gestures ────────────────────────────────────────────────────────────── */

function gestures() {
  let down = null, moved = 0, pinch = null;
  const pts = new Map();
  stage.addEventListener('pointerdown', e => {
    stage.setPointerCapture(e.pointerId); flight++;
    pts.set(e.pointerId, [e.clientX, e.clientY]);
    if (pts.size === 1) { down = [e.clientX, e.clientY]; moved = 0; }
    if (pts.size === 2) { const [p, q] = [...pts.values()]; pinch = { d: Math.hypot(p[0] - q[0], p[1] - q[1]), z: view.zoom }; }
  });
  stage.addEventListener('pointermove', e => {
    if (!pts.has(e.pointerId)) return;
    const prev = pts.get(e.pointerId);
    pts.set(e.pointerId, [e.clientX, e.clientY]);
    if (pts.size === 2 && pinch) {
      const [p, q] = [...pts.values()], d = Math.hypot(p[0] - q[0], p[1] - q[1]);
      if (pinch.d > 0) view.zoom = Math.max(0.02, Math.min(4000, pinch.z * (d / pinch.d)));
      draw(); return;
    }
    if (pts.size === 1) {
      const dx = e.clientX - prev[0], dy = e.clientY - prev[1];
      moved += Math.abs(dx) + Math.abs(dy);
      view.x -= dx / view.zoom; view.y += dy / view.zoom; draw();
    }
  });
  const up = e => {
    if (pts.size === 1 && down && moved < 7) tapAt(e.clientX, e.clientY);
    pts.delete(e.pointerId);
    if (pts.size < 2) pinch = null;
    if (pts.size === 0) down = null;
  };
  stage.addEventListener('pointerup', up);
  stage.addEventListener('pointercancel', e => { pts.delete(e.pointerId); pinch = null; down = null; });
  stage.addEventListener('wheel', e => {
    e.preventDefault(); flight++;
    view.zoom = Math.max(0.02, Math.min(4000, view.zoom * Math.exp(-e.deltaY * 0.0016)));
    draw();
  }, { passive: false });

  /* the strip: swipe for the next stop, or tap a stop */
  let sdown = null;
  sld.addEventListener('pointerdown', e => { sdown = [e.clientX, e.clientY]; try { sld.setPointerCapture(e.pointerId); } catch (_) {} });
  sld.addEventListener('pointerup', e => {
    if (!sdown || !F.thread) return;
    const dx = e.clientX - sdown[0]; sdown = null;
    if (Math.abs(dx) > 36) { goStop(F.i + (dx < 0 ? 1 : -1)); return; }
    const r = sld.getBoundingClientRect(), j = F.i + Math.round((e.clientX - r.left - r.width / 2) / STEP);
    if (j !== F.i) goStop(j);
  });
}

/* ── URL: thread and stop ────────────────────────────────────────────────── */

function writeURL() {
  const q = new URLSearchParams();
  if (F.thread) { q.set('thread', F.thread.id); q.set('stop', String(F.i + 1)); }
  history.replaceState(null, '', q.toString() ? '?' + q.toString().replace(/%7E/gi, '~') : location.pathname);
}

async function openThread(id, at) {
  try {
    let T;
    if (id.startsWith('copy~')) {
      const chains = await copyChains(); T = chains[+id.slice(5)];
      if (!T) throw new Error(`EMPTY: there is no ${id}; ${fmt(chains.length)} chains exist`);
    } else if (id.includes('~')) {
      const [m, fam] = id.split('~'); await loadModule(m);
      if (!MOD.get(m).data.routes.some(x => x.family === +fam)) throw new Error(`EMPTY: ${m} routes no family #${fam}`);
      T = familyThread(m, +fam);
    } else T = await moduleThread(id);
    if ([...$('thread').options].some(o => o.value === T.id)) $('thread').value = T.id;
    let i = 0;
    if (at && at.key != null && at.key !== '') i = Math.max(0, T.stops.findIndex(s => s.key === +at.key));
    else if (at && at.index != null) i = at.index;
    await follow(T, i);
  } catch (e) {
    $('cardbody').innerHTML = `<h2>Refused</h2><p class="refuse"></p>`;
    $('cardbody').querySelector('.refuse').textContent = e.message;
    $('card').hidden = false;
  }
}

/* ── start ───────────────────────────────────────────────────────────────── */

(async function start() {
  try { await tier1(); }
  catch (e) { $('count').textContent = 'Could not load the numbered database: ' + e.message + '. Check the connection and reload.'; return; }
  resize();
  buildDensity();
  paintPageQuestions();
  home();
  gestures();
  window.addEventListener('resize', () => { resize(); draw(); });

  document.querySelectorAll('#levels button').forEach(b => b.addEventListener('click', () => {
    const L = +b.dataset.level;
    if (L === 0) flyTo(0, 0, homeZoom()); else flyTo(view.x, view.y, LEVELS[L].go);
  }));
  $('wake').addEventListener('click', () => {
    if ($('wake').dataset.stage === 'named') {
      for (const r of MODS) loadModule(r.id).catch(() => {});
      $('wake').textContent = 'ALL'; $('wake').disabled = true; return;
    }
    wakeNamed();
    $('wake').dataset.stage = 'named';
    $('wake').textContent = `+${fmt(MODS.filter(r => r.group === OTHER).length)}`;
  });
  $('copies').addEventListener('click', tilesToggle);
  $('chains').addEventListener('click', () => copyChains().catch(e => { $('loadrow').textContent = 'copy chains FAIL: ' + e.message; }));
  $('thread').addEventListener('change', e => { const v = e.target.value; if (v) openThread(v); else leave(); });
  $('prev').addEventListener('click', () => goStop(F.i - 1));
  $('next').addEventListener('click', () => goStop(F.i + 1));
  $('leave').addEventListener('click', leave);
  $('close').addEventListener('click', () => { $('card').hidden = true; cardKey = -1; });
  $('cardbody').addEventListener('click', e => {
    const b = e.target.closest('button'); if (!b) return;
    if (b.dataset.walk) openThread(b.dataset.walk);
    else if (b.dataset.back) openThread(b.dataset.back, { key: F.thread.stops[0].key });
    else if (b.dataset.follow) openThread(b.dataset.follow, { key: b.dataset.at });
  });
  window.addEventListener('keydown', e => {
    if (!F.thread || e.target.tagName === 'SELECT') return;
    if (e.key === 'ArrowRight') goStop(F.i + 1);
    if (e.key === 'ArrowLeft') goStop(F.i - 1);
  });

  const q = new URLSearchParams(location.search);
  if (q.get('thread')) openThread(q.get('thread'), { index: Math.max(0, (parseInt(q.get('stop'), 10) || 1) - 1) });
  window.__journey.ready = true;
  window.__journey.goStop = i => goStop(i);
  window.__journey.openThread = (id, at) => openThread(id, at);
  window.__journey.copyChains = () => copyChains();
  window.__journey.tiles = () => ({ on: TILES.on, bands: TILES.bands.size, held: TILES.held, cap: TILE_FEATURE_CAP, fetched: TILES.fetched, evicted: TILES.evicted, withheld: TILES.withheld, state: TILES.state });
})();

Iterations — 30 Journey Page

A web page in Galaxies Wafers that reads inputs for thread. Published at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.

rendergalaxies-wafers / iterations/30-journey/index.html · lines 1–61 of 61 · Entry point

What it does
It draws its content. Side effects: changes the web page (DOM).
Why it exists in the grid workflow
README: "The page (`index.html`, `app.mjs`, `lib.mjs`) is inherited unchanged from testcode/202609151339."
Inputs & outputs
In: form fields (user input). Out: web page.
Downstream impact
It is itself an entry point, published at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.
What it achieves
Journey — follow one thread through the Line Wafer, level by level.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
galaxies-wafers · iterations/30-journey · page
Uses
Iterations — 30 Journey Style Sheet (stylesheet), Iterations — 30 Journey (script src)
Used by
none found
Produces
none declared
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
galaxies-wafers@5814793812add74605660fa821e6a39b8de80588 iterations/30-journey/index.html:1-61 · blob 84cf7ee7aabe48303cbed2bb65f3dae5f687d848 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: unknown · users: none · canonical: unknown
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover, maximum-scale=5">
<meta name="color-scheme" content="dark">
<title>Journey — follow one thread through the Line Wafer, level by level</title>
<link rel="icon" href="data:,">
<link rel="stylesheet" href="style.css">
</head>
<body>

<canvas id="stage" aria-label="The Line Wafer drawn by level of detail: only what the current level needs is drawn."></canvas>

<div id="top">
<header id="bar">
  <div class="row"><span id="wordmark">JOURNEY</span> <span id="count" class="dim">loading the numbered database…</span></div>
  <div class="row"><span id="lvl">LEVEL —</span> <span id="drawn" class="dim"></span></div>
</header>

<nav id="levels" aria-label="levels of detail">
  <button type="button" data-level="0">GALAXY</button>
  <button type="button" data-level="1">SYSTEM</button>
  <button type="button" data-level="2">PLANET</button>
  <button type="button" data-level="3">SURFACE</button>
</nav>

<section id="pick">
  <select id="thread" aria-label="thread to follow"><option value="">follow a thread…</option></select>
  <button id="wake" type="button">ROUTES</button>
  <button id="copies" type="button">COPIES</button>
  <button id="chains" type="button">CHAINS</button>
</section>
<div id="loadrow" class="dim">WAIT · module routes load when you wake them or pick a thread</div>
<div id="tilerow" class="dim"></div>
<details id="pageq"><summary>Questions</summary><div class="body dim">computed when the numbered database has loaded</div></details>

</div>

<section id="card" hidden>
  <button id="close" type="button" aria-label="close">✕</button>
  <div id="cardbody"></div>
</section>

<section id="follow" hidden>
  <button id="prev" type="button" aria-label="previous stop">◀</button>
  <canvas id="sld" aria-label="the followed thread drawn as a single straight line with its stops as busbars"></canvas>
  <button id="next" type="button" aria-label="next stop">▶</button>
  <button id="leave" type="button" aria-label="stop following">✕</button>
</section>

<footer id="foot">
  <span id="prov" class="dim">provenance loading</span>
  <span id="hint" class="dim">drag to pan · pinch or scroll to change level · tap a white dot or, at SURFACE, a line · swipe the strip for the next stop</span>
</footer>

<noscript><p class="dim" style="padding:1rem">This surface is drawn from the numbered database at run time, so it needs JavaScript.</p></noscript>

<script type="module" src="app.mjs"></script>
</body>
</html>

Iterations — 30 Journey Style Sheet

A style sheet in Galaxies Wafers. Served with the page at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.

rendergalaxies-wafers / iterations/30-journey/style.css · lines 1–91 of 91 · Entry point

What it does
Side effects: changes the web page (DOM).
Downstream impact
Used directly by 1 file: Iterations — 30 Journey Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/). It is itself an entry point, published at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.
What it achieves
Designed at 390 px first; the desktop is the same layout with more room.
Why it matters
Loaded by the 30 Journey page at https://ventusltd.github.io/galaxies-wafers/iterations/30-journey/.
Application
galaxies-wafers · iterations/30-journey · style sheet
Uses
none found
Used by
loaded by Iterations — 30 Journey Page (stylesheet)
Produces
none declared
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
galaxies-wafers@5814793812add74605660fa821e6a39b8de80588 iterations/30-journey/style.css:1-91 · blob d387cbd3b7cd14713638bcc15195a154b5f672f9 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: unknown · users: none · canonical: unknown
/* Journey. Designed at 390 px first; the desktop is the same layout with more room. */

:root{
  --ink:#d8dee9; --dim:#8b93a7; --ground:#030406; --edge:#1b2030;
  --lit:#ffd54a; --beam:#5ec8f2;
  --top:env(safe-area-inset-top,0px); --bot:env(safe-area-inset-bottom,0px);
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; background:var(--ground); color:var(--ink);
  font:12px/1.45 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  overflow:hidden; overscroll-behavior:none; -webkit-text-size-adjust:100%;
}
#stage{position:fixed; inset:0; width:100%; height:100%; display:block; touch-action:none}
.dim{color:var(--dim)}
[hidden]{display:none!important}

#top{
  position:fixed; left:0; right:0; top:0; z-index:3;
  display:flex; flex-direction:column; gap:.3rem;
  padding:calc(var(--top) + .4rem) .5rem .3rem;
  background:linear-gradient(#030406f2 70%,#03040600); pointer-events:none;
}
#top > *{pointer-events:auto}
#bar, #loadrow, #tilerow{pointer-events:none!important; padding:0 .25rem}
#bar .row{display:flex; gap:.6rem; align-items:baseline; flex-wrap:wrap}
#wordmark{letter-spacing:.14em; font-size:11px}
#lvl{color:var(--lit); letter-spacing:.06em}
#drawn{font-size:11px}
#levels{display:flex; gap:.3rem}
#levels button, #pick button, #pick select, .act, #follow button{
  font:inherit; font-size:11px; letter-spacing:.06em; color:var(--beam);
  background:#0c1018; border:1px solid var(--edge); border-radius:5px; padding:.4rem .45rem; cursor:pointer;
}
#levels button{flex:1 1 0}
#levels button.on{color:#030406; background:var(--lit); border-color:var(--lit)}
#pick{display:flex; gap:.3rem}
#pick select{flex:1 1 auto; min-width:0; color:var(--ink); font-size:16px; padding:.3rem}
#pick button:disabled{color:var(--dim)}
#pick button.on{color:#030406; background:#ff2bd6; border-color:#ff2bd6}
#loadrow{font-size:10.5px}
#tilerow{font-size:10.5px; color:#e59ad9}
#tilerow:empty{display:none}
#pageq{max-height:30vh; overflow:auto; background:#0a0d14e8; border:1px solid var(--edge); border-radius:6px; padding:.25rem .55rem}
#pageq summary, .qs summary{cursor:pointer; color:var(--lit); letter-spacing:.08em}
body.following #pageq{display:none}

#card{
  position:fixed; z-index:4; left:.5rem; right:.5rem;
  bottom:calc(var(--bot) + 8.6rem);
  max-height:34vh; overflow:auto; -webkit-overflow-scrolling:touch;
  background:#0a0d15f2; border:1px solid var(--edge); border-radius:8px;
  padding:.6rem .75rem .8rem;
}
#close{position:absolute; top:.3rem; right:.35rem; width:2rem; height:2rem; background:none; border:0; color:var(--dim); font:inherit; font-size:15px; cursor:pointer}
#card h2{margin:0 1.6rem .35rem 0; font-size:14px; font-weight:600}
#card h2 .n{color:var(--lit)}
#card h3{margin:.7rem 0 .2rem; font-size:11px; letter-spacing:.08em; color:var(--dim); font-weight:600; text-transform:uppercase}
#card dl{display:grid; grid-template-columns:auto 1fr; gap:.1rem .6rem; margin:.35rem 0}
#card dt{color:var(--dim)} #card dd{margin:0; overflow-wrap:anywhere}
#card p{margin:.35rem 0 0; overflow-wrap:anywhere}
#card ul, .q3{margin:.3rem 0 0; padding-left:1.1rem}
#card li, .q3 li{margin:.25rem 0; overflow-wrap:anywhere}
.machine{font-size:10.5px; color:#aab2c3; border-top:1px solid var(--edge); padding-top:.3rem; overflow-wrap:anywhere}
.fam{color:var(--beam)}
.refuse{color:var(--lit)}
.act.small{padding:.1rem .35rem; font-size:10px}

#follow{
  position:fixed; z-index:4; left:0; right:0; bottom:calc(var(--bot) + 2.4rem);
  display:flex; gap:.25rem; align-items:stretch; padding:0 .4rem; height:5.6rem;
}
#sld{flex:1 1 auto; min-width:0; height:100%; border:1px solid var(--edge); border-radius:6px; touch-action:none; background:#070a10}
#follow button{flex:0 0 2.4rem; font-size:14px; padding:0}

#foot{
  position:fixed; z-index:2; left:0; right:0; bottom:0;
  display:flex; gap:.1rem; flex-direction:column;
  padding:.25rem .75rem calc(var(--bot) + .3rem);
  background:linear-gradient(#03040600,#030406ee); pointer-events:none; font-size:10px;
}
body:not(.following) #card{bottom:calc(var(--bot) + 2.8rem)}

@media (min-width:760px){
  #top{left:auto; width:27rem; background:none}
  #card{left:1rem; right:auto; width:28rem; top:calc(var(--top) + 3.6rem); bottom:calc(var(--bot) + 8.6rem); max-height:none}
  body:not(.following) #card{bottom:auto; max-height:70vh}
  #follow{left:30rem; right:1rem}
  #foot{flex-direction:row; justify-content:space-between; font-size:11px}
}