GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Kuiper, cosmos and drawing engines / galaxies-wafers / iterations/09-deeplink-receiver

Iterations — 09 Deeplink Receiver and 4 more files

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

601 lines of JavaScript and HTML and CSS from galaxies-wafers, in 5 files. Topic: Kuiper, cosmos and drawing engines. Section 1187 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 — 09 Deeplink Receiver render · galaxies-wafers / iterations/09-deeplink-receiver/app.mjs lines 439–700
  2. Iterations — 09 Deeplink Receiver Page render · galaxies-wafers / iterations/09-deeplink-receiver/index.html lines 1–66
  3. Questions render · galaxies-wafers / iterations/09-deeplink-receiver/questions.css lines 1–15
  4. Questions render · galaxies-wafers / iterations/09-deeplink-receiver/questions.mjs lines 1–127
  5. Receiver interaction · galaxies-wafers / iterations/09-deeplink-receiver/receiver.mjs lines 1–131

Iterations — 09 Deeplink Receiver

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

rendergalaxies-wafers / iterations/09-deeplink-receiver/app.mjs · lines 439–700 of 700 (continued from section 1186) · Entry point · pattern visibleRange (shared by 3 files)

What it does
It draws lines meta and families. Defines 39 functions or classes, including $, snapshot, motion, indexOfKey, bin. Side effects: changes the web page (DOM); makes network requests.
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: JSON file all-lines.meta.json; JSON file families.json. Out: WebGL/WebGPU drawing.
Downstream impact
Used directly by 1 file: Iterations — 09 Deeplink Receiver Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/). Reached from 1 other entry point, including Iterations — 45 Deeplink Round Trip Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/45-deeplink-round-trip/). It is itself an entry point, published at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.
What it achieves
It indexes key (`indexOfKey`), builds gl (`buildGL`) and draws marks (`drawMarks`). The Line Wafer. 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/09-deeplink-receiver/.
Application
galaxies-wafers · iterations/09-deeplink-receiver · JavaScript module
Uses
Galaxies Wafers — Lib (import), Receiver (import)
Used by
loaded by Iterations — 09 Deeplink Receiver Page (script src)
Produces
$, snapshot, motion, indexOfKey, bin, tier1, tier2, compile, initGL, fallback2d, buildGL, put
Defines here
flyTo, nearestKeyAt, famsOf, paintPanel, family, connect, famLine, s, gestures, up, readURL, refuse, writeURL
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/09-deeplink-receiver/app.mjs:439-700 · blob 467d8e1299b1df05aaf085b45bb48cb32d835f27 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: unknown · users: none · canonical: unknown
function flyTo(key, zoom) {
  const [x, y] = placeOne(key);
  const z0 = view.zoom, x0 = view.x, y0 = view.y;
  const z1 = zoom ?? Math.max(view.zoom, 9);
  const t0 = performance.now(), ms = 620;
  (function step(t) {
    const u = Math.min(1, (t - t0) / ms);
    const e = u < .5 ? 4 * u * u * u : 1 - Math.pow(-2 * u + 2, 3) / 2;
    view.x = x0 + (x - x0) * e; view.y = y0 + (y - y0) * e;
    view.zoom = Math.exp(Math.log(z0) + (Math.log(z1) - Math.log(z0)) * e);
    motion(); render();
    if (u < 1) requestAnimationFrame(step);
  })(t0);
}

function nearestKeyAt(cx, cy) {
  const wx = (cx - view.w / 2) / view.zoom + view.x;
  const wy = (view.h / 2 - cy) / view.zoom + view.y;
  const reach = 22 / view.zoom;
  let best = -1, bestD = reach * reach;
  for (let i = 0; i < U.n; i++) {
    const dx = U.pos[i * 2] - wx, dy = U.pos[i * 2 + 1] - wy;
    const d = dx * dx + dy * dy;
    if (d < bestD) { bestD = d; best = i; }
  }
  return best < 0 ? -1 : U.keys[best];
}

/* ── the panel: what the beam found ──────────────────────────────────────── */

function famsOf(key) {
  if (!U.ownerOf) return null;
  return U.ownerOf.get(key) || [];
}

function paintPanel(key) {
  const i = indexOfKey(key);
  const p = $('panelbody');
  if (i < 0) {
    p.innerHTML =
      `<h2>Line <span class="n">${fmt(key)}</span></h2>
       <p class="refuse">This number was never issued. The numbering runs 1 to ${fmt(U.meta.max)} and
       ${fmt(U.meta.max - U.n)} of those numbers were skipped, so a gap is a real answer rather than a
       missing record. The surface still has a place for it, and the beam is pointing at it.</p>`;
    $('panel').hidden = false; return;
  }
  const chars = U.lens[i], carried = U.inFam[i] === 1;
  const fams = famsOf(key);
  let body =
    `<h2>Line <span class="n">${fmt(key)}</span></h2>
     <dl>
       <dt>characters</dt><dd>${chars === 65535
          ? 'at least 65,535 — the pack stores this in sixteen bits and this line reaches the ceiling, so its true length is not known here'
          : fmt(chars) + (chars === 0 ? ' (an empty line)' : '')}</dd>
       <dt>permanent</dt><dd>this number is never reused, so it means this line for ever</dd>
       <dt>carried by</dt><dd>${carried ? 'at least one function family' : 'no function family'}</dd>
     </dl>`;
  if (!carried) {
    body += `<p class="refuse">Nothing can be connected to this line. It is numbered and it exists, but no
      function family in the estate carries it, so it has no partner to join it to.</p>`;
  } else if (fams === null) {
    body += `<p class="dim">The family index is still loading; the families carrying this line will appear here.</p>`;
  } else if (fams.length === 0) {
    body += `<p class="refuse">The pack marks this line as carried, but no family range in this build
      contains it. That disagreement is shown rather than smoothed over.</p>`;
  } else {
    const show = fams.slice(0, 12);
    body += `<p>Carried by <span class="fam">${fmt(fams.length)}</span> ${fams.length === 1 ? 'family' : 'families'}${fams.length > 12 ? ', first twelve' : ''}:</p><ul>` +
      show.map(f => {
        const fa = U.families[f];
        const cat = fa.category ?? 'no category recorded';
        return `<li><span class="fam">${esc(fa.name)}</span> <span class="dim">#${fmt(fa.n)} · ${esc(fa.kind)} · ${esc(cat)} · ${fmt(fa.lineCount)} lines</span></li>`;
      }).join('') + `</ul>`;
    if (fams.length > 60) {
      body += `<p class="dim">A line carried by this many families is almost certainly trivial: a brace, a
        blank, an import. Its connection count is drawn here rather than hidden, so you can see that for
        yourself.</p>`;
    }
  }
  p.innerHTML = body;
  $('panel').hidden = false;
}

function connect(ka, kb) {
  view.link = [ka, kb];
  const p = $('panelbody');
  const head = `<h2>Connect <span class="n">${fmt(ka)}</span> to <span class="n">${fmt(kb)}</span></h2>`;

  /* The index is the only thing that can be missing; everything else is decided
     by lib.mjs so the page cannot disagree with the proofs. */
  if (!U.ownerOf) {
    p.innerHTML = head + `<p class="dim">The family index is still loading. The answer will appear here
      without another tap.</p>`;
    $('panel').hidden = false; draw(); return;
  }

  const a = connectAnswer(ka, kb, { keys: U.keys, owner: U.ownerOf });
  const famLine = f => {
    const fa = U.families[f];
    return `<li><span class="fam">${esc(fa.name)}</span> <span class="dim">#${fmt(fa.n)} · ${esc(fa.category ?? 'no category recorded')}</span></li>`;
  };
  let body = head;

  if (a.verdict === 'absent') {
    body += `<p class="refuse">${a.absent.map(fmt).join(' and ')} ${a.absent.length > 1 ? 'were' : 'was'}
      never issued in this numbering, so there is nothing at that address to connect.</p>`;

  } else if (a.verdict === 'same-line') {
    body += `<p class="refuse">Those are the same line. A line is not connected to itself, and reporting
      that it is would be the page agreeing with you rather than answering you.</p>` +
      (a.both.length
        ? `<p>Line ${fmt(ka)} is carried by ${fmt(a.both.length)} ${a.both.length === 1 ? 'family' : 'families'}.</p>`
        : `<p>No family carries line ${fmt(ka)}.</p>`);

  } else if (a.verdict === 'no-family') {
    body += `<p class="refuse">${a.without.map(fmt).join(' and ')} ${a.without.length > 1 ? 'are' : 'is'}
      carried by no function family at all, so ${a.without.length > 1 ? 'they have' : 'it has'} nothing to be
      joined through.</p>`;

  } else if (a.verdict === 'joined') {
    body += `<p>Joined by <span class="fam">${fmt(a.both.length)}</span>
      ${a.both.length === 1 ? 'family that carries' : 'families that carry'} both lines${a.both.length > 12 ? ', first twelve' : ''}:</p>
      <ul>${a.both.slice(0, 12).map(famLine).join('')}</ul>
      <p class="dim">This is co-membership: two different lines sitting in one function. It is not the same
      text in two places, and it is not a dependency. Either line may be carried by only that one family and
      still connect perfectly well through it.</p>`;

  } else {
    body += `<p class="refuse">No family carries both lines, so these two are not joined.</p>
      <dl><dt>${fmt(ka)}</dt><dd>${a.A.length ? fmt(a.A.length) + ' ' + (a.A.length === 1 ? 'family' : 'families') : 'no family'}</dd>
          <dt>${fmt(kb)}</dt><dd>${a.B.length ? fmt(a.B.length) + ' ' + (a.B.length === 1 ? 'family' : 'families') : 'no family'}</dd></dl>
      <p class="dim">An unjoined pair is the ordinary case: most lines of the estate sit in unrelated
      functions. This is not about fanout. ${fmt(U.fanout)} of the ${fmt(U.n)} numbered lines appear in more
      than one family, which is duplication; joining two numbers asks the different question of whether one
      family holds them both.</p>`;
  }

  p.innerHTML = body;
  $('panel').hidden = false;

  /* Frame both ends. */
  const [ax, ay] = placeOne(ka), [bx, by] = placeOne(kb);
  view.x = (ax + bx) / 2; view.y = (ay + by) / 2;
  const span = Math.max(Math.hypot(bx - ax, by - ay), 4);
  view.zoom = Math.min(view.w, view.h) / (span * 1.8);
  if (linkZoom !== undefined) view.zoom = linkZoom;
  draw();
}

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

function gestures() {
  let down = null, moved = 0, pinch = null, wasPinch = false;   /* 09b: a finger lifting after a pinch is not a tap */
  const pts = new Map();
  stage.addEventListener('pointerdown', e => {
    stage.setPointerCapture(e.pointerId);
    pts.set(e.pointerId, [e.clientX, e.clientY]);
    if (pts.size === 1) { down = [e.clientX, e.clientY]; moved = 0; }
    if (pts.size >= 2) wasPinch = true;
    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()];
      const 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)));
      motion(); 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;
      motion(); draw();
    }
  });
  const up = e => {
    if (pts.size === 1 && down && moved < 7 && !wasPinch) {
      const key = nearestKeyAt(e.clientX, e.clientY);
      if (key >= 0) { view.focus = key; paintPanel(key); view.link = null; draw(); }
    }
    pts.delete(e.pointerId);
    if (pts.size < 2) pinch = null;
    if (pts.size === 0) { down = null; wasPinch = false; }
  };
  stage.addEventListener('pointerup', up);
  stage.addEventListener('pointercancel', e => { pts.delete(e.pointerId); pinch = null; down = null; if (pts.size === 0) wasPinch = false; });
  stage.addEventListener('wheel', e => {
    e.preventDefault();
    const f = Math.exp(-e.deltaY * 0.0016);
    view.zoom = Math.max(0.02, Math.min(4000, view.zoom * f));
    motion(); draw();
  }, { passive: false });
  stage.addEventListener('dblclick', () => { view.focus = -1; view.link = null; $('panel').hidden = true; home(); });
}

/* ── URL state: the whole of it, in permanent numbers ────────────────────── */

/* The receiver. Everything comes from LINK, which is parseDeepLink(location.href).
   On ok:false the refusal card (receiver.mjs) quotes the engine's reason and
   the wafer stays at home; nothing is guessed. */
function readURL() {
  if (!LINK.ok) return;
  $('a').value = String(LINK.line);
  if (LINK.to !== undefined) { $('b').value = String(LINK.to); connect(LINK.line, LINK.to); }
  else { view.focus = LINK.line; paintPanel(LINK.line); flyTo(LINK.line, linkZoom); }
}

/* One refusal path, so a bad number is always visible rather than ignored. */
function refuse(sentence) {
  $('panelbody').replaceChildren();
  const h = document.createElement('h2'); h.textContent = 'Refused';
  const p2 = document.createElement('p'); p2.className = 'refuse'; p2.textContent = sentence;
  $('panelbody').append(h, p2);
  $('panel').hidden = false;
}
function writeURL(a, b) {
  const q = new URLSearchParams();
  if (a) q.set('line', String(a));
  if (b) q.set('to', String(b));
  history.replaceState(null, '', q.toString() ? '?' + q : location.pathname);
}

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

(async function start() {
  try {
    await tier1();
  } catch (e) {
    $('count').textContent = 'Could not load the numbered database: ' + e.message
      + '. Check the internet connection and reload.';
    return;
  }
  resize();
  try { initGL(); } catch (e) {
    ctx2d = stage.getContext('2d');
    $('hint').textContent = 'GPU not available: drawn without animation';
  }
  home();
  gestures();
  window.addEventListener('resize', () => { resize(); draw(); });

  $('beam').addEventListener('submit', e => {
    e.preventDefault();
    linkZoom = undefined;
    const pa = parseKey($('a').value), pb = parseKey($('b').value);
    if (!pa.ok) { refuse(`That is not a line number: ${pa.why}.`); return; }
    if ($('b').value.trim() && !pb.ok) { refuse(`Second number: ${pb.why}.`); return; }
    if (pb.ok) { view.focus = -1; connect(pa.key, pb.key); writeURL(pa.key, pb.key); }
    else { view.focus = pa.key; view.link = null; paintPanel(pa.key); flyTo(pa.key); writeURL(pa.key, null); }
    document.activeElement?.blur();
  });
  $('close').addEventListener('click', () => { $('panel').hidden = true; view.focus = -1; view.link = null; draw(); });

  readURL();
  tier2().catch(e => { $('prov').textContent = 'family index unavailable: ' + e.message; });
})();

Iterations — 09 Deeplink Receiver Page

A web page in Galaxies Wafers that reads inputs for emit line, emit to and emit layers. Published at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.

rendergalaxies-wafers / iterations/09-deeplink-receiver/index.html · lines 1–66 of 66 · 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
Used directly by 1 file: Iterations — 45 Deeplink Round Trip Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/45-deeplink-round-trip/). It is itself an entry point, published at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.
What it achieves
The Line Wafer — iteration 09, the deep-link receiver.
Why it matters
Loaded by the 45 Deeplink Round Trip page at https://ventusltd.github.io/galaxies-wafers/iterations/45-deeplink-round-trip/.
Application
galaxies-wafers · iterations/09-deeplink-receiver · page
Uses
Iterations — 09 Deeplink Receiver Style Sheet (stylesheet), Questions (stylesheet), Galaxies Wafers — Proof Page (link), Receiver (script src), Iterations — 09 Deeplink Receiver (script src), Layers Panel (script src), Questions (script src)
Used by
linked from Iterations — 45 Deeplink Round Trip Page (link)
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/09-deeplink-receiver/index.html:1-66 · blob 91324b910732db4bf33fa18a531314b150056a64 · 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>The Line Wafer — iteration 09, the deep-link receiver</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="questions.css">
</head>
<body>

<canvas id="stage" aria-label="Every permanently numbered line of code in the estate, placed by its own number."></canvas>

<header id="bar">
  <span id="wordmark">THE LINE WAFER · RECEIVER</span>
  <span id="count" class="dim">loading the numbered database…</span>
</header>

<form id="beam" autocomplete="off">
  <input id="a" inputmode="numeric" pattern="[0-9]*" placeholder="line number" aria-label="line number to fly to">
  <input id="b" inputmode="numeric" pattern="[0-9]*" placeholder="connect to…" aria-label="second line number to connect to">
  <button id="go" type="submit">FLY</button>
</form>

<div id="leftcol">
<aside id="linkcard" hidden aria-live="polite"></aside>

<section id="emit" hidden>
  <button id="emitToggle" type="button">EMIT</button>
  <div id="emitBody" hidden>
    <div class="egroup">BUILD A LINK · buildDeepLink</div>
    <div class="erow">
      <input id="emitLine" inputmode="numeric" placeholder="line" aria-label="line for the emitted link">
      <input id="emitTo" inputmode="numeric" placeholder="to" aria-label="second line for the emitted link">
    </div>
    <select id="emitLayers" multiple size="5" aria-label="layers to carry in the emitted link"></select>
    <div class="egroup">galaxies-wafers <button id="emitCopy" type="button">COPY</button></div>
    <div id="emitA" class="eurl"></div>
    <div class="egroup">line-wafer-202609151339 · carries no layers</div>
    <div id="emitB" class="eurl"></div>
    <div id="emitReceivers" class="estat">checking engine/receivers.json…</div>
  </div>
</section>
<details id="questions"><summary>Questions</summary><dl id="qlist"></dl><p id="machine" class="dim"></p></details>
</div>

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

<footer id="foot">
  <span id="prov" class="dim">provenance loading</span>
  <span id="hint" class="dim">drag to steer · pinch or scroll to focus the beam · tap a line</span>
  <a id="proofs" href="../../proof/">check every claim on this page</a>
</footer>

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

<script type="module" src="receiver.mjs"></script>
<script type="module" src="app.mjs"></script>
<script type="module" src="layers-panel.mjs"></script>
<script type="module" src="questions.mjs"></script>
</body>
</html>

Questions

A style sheet in the iterations folder of Galaxies Wafers. Served with the page at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.

rendergalaxies-wafers / iterations/09-deeplink-receiver/questions.css · lines 1–15 of 15 · Entry point

What it does
Side effects: changes the web page (DOM).
Downstream impact
Used directly by 1 file: Iterations — 09 Deeplink Receiver Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/). Reached from 1 other entry point, including Iterations — 45 Deeplink Round Trip Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/45-deeplink-round-trip/). It is itself an entry point, published at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.
What it achieves
The Questions panel, collapsed by default.
Why it matters
Loaded by the 09 Deeplink Receiver page at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.
Application
galaxies-wafers · iterations/09-deeplink-receiver · style sheet
Uses
none found
Used by
loaded by Iterations — 09 Deeplink Receiver 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/09-deeplink-receiver/questions.css:1-15 · blob c506718688653d8528c05458e0f3d64e46a9a258 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: unknown · users: none · canonical: unknown
/* The Questions panel, collapsed by default. Markup and look from
   iterations/22-fast-zoom (index.html #questions, style.css). It sits last in the
   top bar and stops short of the LAYERS button on the right. */
#questions{order:9; flex-basis:100%; max-width:min(26rem,calc(100% - 5.5rem)); pointer-events:auto; font-size:10.5px; line-height:1.45}
#questions summary{cursor:pointer; color:var(--beam,#5ec8f2); letter-spacing:.08em; width:max-content}
#questions[open]{background:#0e121bf2; border:1px solid var(--edge,#1b2030); border-radius:8px; padding:.4rem .55rem; max-height:45vh; overflow:auto; -webkit-overflow-scrolling:touch; overscroll-behavior:contain}
#questions dl{margin:.35rem 0 0}
#questions dt{color:var(--ink,#d8dee9); margin-top:.35rem}
#questions dd{margin:.1rem 0 0; color:var(--dim,#8b93a7); overflow-wrap:anywhere}
#questions a{color:var(--beam,#5ec8f2)}
#questions #machine{margin:.45rem 0 0; overflow-wrap:anywhere}
/* Iteration 09: the arrival card (#leftcol, z-index 6) sits over the top bar on a
   phone, so here the panel is the last item of #leftcol, under EMIT. Nothing above
   it moves; opened, it grows downward over the wafer only. */
#leftcol #questions{order:0; flex-basis:auto; max-width:100%; font-size:10.5px}

Questions

A JavaScript module in the iterations folder of Galaxies Wafers that works with layer tags (`layerTags`) and single-line diagram (SLD) sentence (`sldSentence`). Served with the page at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.

rendergalaxies-wafers / iterations/09-deeplink-receiver/questions.mjs · lines 1–127 of 127 · Entry point · pattern sldSentence (shared by 8 files)

What it does
It draws its content. Defines 11 functions or classes, including $, fmt, answer, fill, readJSON. Side effects: changes the web page (DOM); makes network requests.
Downstream impact
Used directly by 1 file: Iterations — 09 Deeplink Receiver Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/). Reached from 1 other entry point, including Iterations — 45 Deeplink Round Trip Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/45-deeplink-round-trip/). It is itself an entry point, published at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.
What it achieves
It reads JSON (`readJSON`) and is built from the fmt step (`fmt`) and the answer step (`answer`). Iteration 09, the Deep-Link Receiver: the owner's three questions and the machine detail line. It reads `../../layers/manifest.json`. It responds to resize and toggle events.
Why it matters
Loaded by the 09 Deeplink Receiver page at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.
Application
galaxies-wafers · iterations/09-deeplink-receiver · JavaScript module
Uses
Receiver (import), Code Galaxy Engine (import)
Used by
loaded by Iterations — 09 Deeplink Receiver Page (script src)
Produces
$, fmt, answer, fill, readJSON, layerTags, sldSentence, text, mount, fit, paint
Defines here
$, fmt, answer, fill, readJSON, layerTags, sldSentence, text, mount, fit, paint
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/09-deeplink-receiver/questions.mjs:1-127 · blob 7309fadfe600e5ddacde87f2ef8f613d2ac3769b · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: unknown · users: none · canonical: unknown
/* questions.mjs — iteration 09, the Deep-Link Receiver: the owner's three
 * questions and the machine detail line. The parsed link and the receiver list
 * are read at run time from the same module instances the page uses
 * (receiver.mjs LINK, engine/code-galaxy-engine.mjs PARAMS and RECEIVERS); layer
 * counts from layers/manifest.json; functions are cited to file and line.
 */
import { LINK } from './receiver.mjs';
import { PARAMS, RECEIVERS, LIFTED_FROM } from '../../engine/code-galaxy-engine.mjs';

const $ = id => document.getElementById(id);
const fmt = n => Number(n).toLocaleString('en-GB');
const DATA_PIN = 'https://globalgrid2050.com/testcode/202609142202/data/';
const SEARCH = 'repository search at ee082ea';   /* the commit the "who else" searches were run on */

/* One question and its answer. Parts are strings or [text, href] links; text only, never HTML. */
function answer(dl, q, parts) {
  const dt = document.createElement('dt'); dt.textContent = q;
  const dd = document.createElement('dd');
  const fill = ps => {
    dd.replaceChildren();
    for (const p of [].concat(ps)) {
      if (Array.isArray(p)) { const a = document.createElement('a'); a.textContent = p[0]; a.href = p[1]; dd.append(a); }
      else dd.append(String(p));
    }
  };
  fill(parts);
  dl.append(dt, dd);
  return fill;
}

/* One fetch, 15 s timeout, only when the reader opens the panel. */
async function readJSON(url) {
  const c = new AbortController();
  const t = setTimeout(() => c.abort(), 15000);
  try {
    const r = await fetch(url, { cache: 'default', signal: c.signal });
    if (!r.ok) throw new Error(url + ' returned HTTP ' + r.status);
    return await r.json();
  } finally { clearTimeout(t); }
}

/* The layer rows' tags as the layers panel shows them now, counted from its own DOM. */
function layerTags() {
  const c = new Map();
  for (const t of document.querySelectorAll('#layersList .ltag')) {
    const s = (t.textContent.match(/[A-Z]+/) || ['?'])[0];
    c.set(s, (c.get(s) || 0) + 1);
  }
  return c.size ? [...c].map(([s, n]) => `${fmt(n)} ${s}`).join(', ') : 'layer rows not built yet';
}

/* Layers whose id names an SLD, read from a manifest at run time (name-match inference). */
function sldSentence(m, file) {
  const hits = m.layers.filter(l => /sld/i.test(l.id));
  if (!hits.length) return `None of the ${fmt(m.layers.length)} layers in ${file} carries "sld" in its id.`;
  return `Of ${fmt(m.layers.length)} layers in ${file}, ${hits.length} carry "sld" in their id (name-match inference): ` +
    hits.map(l => `${l.id} (${fmt(l.features)} features, draws ${l.draws})`).join(', ') + '.';
}

const text = id => ($(id)?.textContent || '').trim();

/* Collapsed by default. Nothing is read or fetched until the reader opens it; the
   machine line repaints every 500 ms only while it is open. */
function mount(build, machine) {
  const box = $('questions'), dl = $('qlist'), out = $('machine');
  if (!box || !dl || !out) return;
  let built = false, timer = 0;
  /* Opened, the panel stops above whatever is drawn at the bottom (line panel, clock, strip, beam form), never over it. */
  const fit = () => {
    const top = box.getBoundingClientRect().top;
    let floor = innerHeight;
    for (const id of ['panel', 'clock', 'ptable', 'beam']) {
      const el = $(id);
      const r = el && !el.hidden ? el.getBoundingClientRect() : null;
      if (r && r.height > 0 && r.top > top) floor = Math.min(floor, r.top);
    }
    box.style.maxHeight = Math.max(96, Math.min(innerHeight * 0.45, floor - top - 8)) + 'px';
  };
  const paint = () => {
    fit();
    try { out.textContent = 'Machine detail · ' + machine(); }
    catch (e) { out.textContent = 'Machine detail · not established: ' + e.message; }
  };
  /* A bottom element that grows while the panel is open refits it at once, not at the next repaint. */
  if ('ResizeObserver' in window) {
    const ro = new ResizeObserver(() => { if (box.open) fit(); });
    for (const id of ['panel', 'clock', 'ptable', 'beam']) if ($(id)) ro.observe($(id));
  }
  addEventListener('resize', () => { if (box.open) fit(); });
  box.addEventListener('toggle', () => {
    clearInterval(timer);
    if (!box.open) return;
    if (!built) { built = true; build(dl); }
    paint();
    timer = setInterval(paint, 500);
  });
}

const COMMIT = '8ac6cd4';   /* the last commit to this page before the Questions panel */

mount(dl => {
  const q1 = answer(dl, '1 · How does this help draw a system or a single-line diagram?', 'reading layers/manifest.json…');
  answer(dl, '2 · What is this code used for?',
    'Arriving at a line from a link, and building links out. engine/code-galaxy-engine.mjs: parseDeepLink() line 78 reads a URL and never throws, buildDeepLink() line 55 writes one and throws on a bad field, RECEIVERS line 35 lists where links may point; ' +
    `it is lifted from ${LIFTED_FROM} (read now from LIFTED_FROM, line 24). receiver.mjs parses location.href once (LINK, line 22), paintCard() line 37 shows the arrival or refusal card, emitPanel() line 77 builds links, checkReceivers() line 114 compares engine/receivers.json with RECEIVERS. ` +
    'layers-panel.mjs requestedLayers() line 255 loads a layers-only link only after re-checking to and zoom with a placeholder line; app.mjs readURL() line 645 flies to LINK.line or connects LINK.line to LINK.to. ' +
    `Who else: engine/code-galaxy-engine.mjs is imported by this page's receiver.mjs and layers-panel.mjs and by proof/engine.check.mjs, and by no other file; engine/receivers.json is read only here (${SEARCH}).`);
  answer(dl, '3 · Where does it lead next?',
    'To the receivers its links point at, read now from RECEIVERS: ' +
    RECEIVERS.map(r => `${r.id} (${r.status}, ${r.carries_layers ? 'carries layers' : 'carries no layers'}) at ${r.url}`).join('; ') +
    '. The EMIT panel builds a link to each; the second refuses a layers field in the engine\'s own words.');
  readJSON('../../layers/manifest.json').then(m => {
    q1('It draws no electrical element; it carries a place on the wafer between pages. ' +
      `The link fields, read now from PARAMS (line 28), are ${Object.keys(PARAMS).join(', ')}; none is an electrical quantity. ` +
      'What that enables: a link can arrive with named layers ticked, an SLD layer included. ' + sldSentence(m, 'layers/manifest.json'));
  }).catch(e => q1(`Not established: layers/manifest.json could not be read (${e.message}). The page draws no electrical element.`));
}, () => {
  const card = $('linkcard');
  const link = LINK.ok
    ? `accepted: line ${LINK.line}${LINK.to !== undefined ? `, to ${LINK.to}` : ''}${LINK.zoom !== undefined ? `, zoom ${LINK.zoom}` : ''}${LINK.layers ? `, layers ${LINK.layers.join(',')}` : ''}`
    : `refused: ${LINK.why}`;
  return `inputs: ?line= (the identity, a positive safe integer), ?to= (a second line), ?layers= (ids from layers/manifest.json), ?zoom= (0.02 to 4000), each read only through parseDeepLink(); ` +
    `data: all-lines.meta.json, all-lines.bin, all-lines.len.bin, all-lines.family.bin, families.json and lines.bin from ${DATA_PIN} (app.mjs line 53), ${text('prov') || 'provenance not loaded yet'}; engine/receivers.json and layers/manifest.json from this repository · ` +
    `outputs: this link ${link}; card ${card && !card.hidden ? `shown, ${card.dataset.state || 'no state'}` : 'hidden'}; ${text('count') || 'count not loaded yet'}; layer rows now ${layerTags()}; receivers check ${text('emitReceivers') || 'not run'} · ` +
    'refusals: LINK REFUSED quoting parseDeepLink\'s reason, wafer drawn at home (receiver.mjs line 45); a layers-only link loads its layers only if to and zoom are valid (layers-panel.mjs line 262); unknown layer ids are not ticked and are named as dropped (line 274); receivers.json disagreeing with RECEIVERS reads FAIL (receiver.mjs line 121) · ' +
    `source: page commit ${COMMIT}; engine/code-galaxy-engine.mjs, lib.mjs and layers/ from this repository`;
});

Receiver

A JavaScript module in the iterations folder of Galaxies Wafers that draws receivers. Served with the page at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/. It paints card (`paintCard`), emits panel (`emitPanel`) and checks receivers (`checkReceivers`).

interactiongalaxies-wafers / iterations/09-deeplink-receiver/receiver.mjs · lines 1–131 of 131 · Entry point · pattern paintCard (shared by 3 files)

What it does
It draws receivers. Defines 10 functions or classes, including $, node, paintCard, kv, reportLayers. Side effects: changes the web page (DOM); makes network requests.
Inputs & outputs
In: JSON file receivers.json.
Downstream impact
Used directly by 4 files: Layers Panel (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/); Iterations — 09 Deeplink Receiver (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/); Iterations — 09 Deeplink Receiver Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/); Questions (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/). Reached from 1 other entry point, including Iterations — 45 Deeplink Round Trip Page (galaxies-wafers, https://ventusltd.github.io/galaxies-wafers/iterations/45-deeplink-round-trip/). It is itself an entry point, published at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/.
What it achieves
Iteration 09: the page reads its own URL through the engine. It responds to click, input and change events.
Why it matters
Loaded by the 09 Deeplink Receiver page at https://ventusltd.github.io/galaxies-wafers/iterations/09-deeplink-receiver/. Also imported by Layers Panel, Iterations — 09 Deeplink Receiver and Questions.
Application
galaxies-wafers · iterations/09-deeplink-receiver · JavaScript module
Uses
Code Galaxy Engine (import)
Used by
imported by Layers Panel (import), imported by Iterations — 09 Deeplink Receiver (import), loaded by Iterations — 09 Deeplink Receiver Page (script src), imported by Questions (import)
Produces
ROOT, LINK, hasLink, reportLayers
Defines here
$, node, paintCard, kv, reportLayers, emitPanel, intOrUndef, show, update, checkReceivers
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/09-deeplink-receiver/receiver.mjs:1-131 · blob ae8f600ec85424fdd6ed6233730f0751bb1691ab · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: unknown · users: none · canonical: unknown
/* receiver.mjs — iteration 09: the page reads its own URL through the engine.
 *
 * The inherited page parsed `line` and `to` with its own readURL and `layers`
 * with its own reader, and nothing read `zoom`. Here the URL is parsed once,
 * by parseDeepLink from engine/code-galaxy-engine.mjs, and every other module
 * takes its orders from LINK. Like the Atlas's receiver (repd_ref, validated,
 * then centre and open a card), a link is never guessed at: a bad one is
 * refused in a card that quotes the engine's own reason, and the wafer is
 * drawn at home.
 *
 * The card also reports what the receiver did with the layers field: ids the
 * manifest names are ticked, ids it does not are listed as dropped.
 *
 * The emit panel is the other half of the contract: buildDeepLink, for the
 * layered receiver and for the layerless one, which refuses a layers field in
 * the engine's words. engine/receivers.json is fetched and compared with the
 * module's RECEIVERS; any disagreement is shown as FAIL.
 */
import { parseDeepLink, buildDeepLink, RECEIVERS, IDENTITY_PARAM } from '../../engine/code-galaxy-engine.mjs';

export const ROOT = '../../';
export const LINK = parseDeepLink(location.href);
export const hasLink = new URL(location.href).search.length > 0;

const $ = id => document.getElementById(id);
const node = (tag, text, cls) => {
  const n = document.createElement(tag);
  if (text != null) n.textContent = String(text);
  if (cls) n.className = cls;
  return n;
};

/* ── the arrival card ────────────────────────────────────────────────────── */

const card = { layers: null };

function paintCard() {
  const box = $('linkcard');
  if (!box) return;
  box.replaceChildren();
  if (!hasLink) { box.hidden = true; return; }
  const close = node('button', '✕', 'lcclose'); close.type = 'button'; close.setAttribute('aria-label', 'close');
  close.addEventListener('click', () => { box.hidden = true; });
  box.append(close);
  if (!LINK.ok) {
    box.dataset.state = 'refused';
    box.append(node('b', 'LINK REFUSED', 'lctitle'),
      node('div', LINK.why, 'lcwhy'),
      node('div', 'the engine\'s parseDeepLink returned ok:false; the wafer is drawn at home', 'lcdim'));
    box.hidden = false; return;
  }
  box.dataset.state = 'ok';
  box.append(node('b', `LINE ${LINK.line}`, 'lctitle'));
  const dl = node('dl');
  const kv = (k, v, cls) => dl.append(node('dt', k), node('dd', v, cls));
  kv(IDENTITY_PARAM, String(LINK.line));
  if (LINK.to !== undefined) kv('to', String(LINK.to));
  if (LINK.zoom !== undefined) kv('zoom', String(LINK.zoom));
  if (LINK.layers) {
    if (!card.layers) kv('layers', LINK.layers.join(', ') + ' (waiting for the manifest)', 'lcdim');
    else {
      kv('layers ticked', card.layers.ticked.length ? card.layers.ticked.join(', ') : 'none');
      if (card.layers.dropped.length) kv('dropped', card.layers.dropped.join(', ') + ' — not in layers/manifest.json', 'lcdrop');
      if (card.layers.failed) kv('layers', card.layers.failed, 'lcdrop');
    }
  }
  kv('receiver', LINK.receiver ?? 'this page (not a published receiver URL)', 'lcdim');
  box.append(dl);
  box.hidden = false;
}

/* layers-panel.mjs calls this once it knows the manifest. */
export function reportLayers(r) { card.layers = r; paintCard(); }

/* ── the emit panel ──────────────────────────────────────────────────────── */

function emitPanel(manifest) {
  const sec = $('emit');
  const body = $('emitBody');
  $('emitToggle').addEventListener('click', () => { body.hidden = !body.hidden; });
  const inLine = $('emitLine'), inTo = $('emitTo'), pick = $('emitLayers');
  if (LINK.ok) { inLine.value = String(LINK.line); if (LINK.to !== undefined) inTo.value = String(LINK.to); }
  for (const l of (manifest?.layers || [])) {
    const o = node('option', l.id); o.value = l.id;
    if (LINK.ok && LINK.layers?.includes(l.id)) o.selected = true;
    pick.append(o);
  }
  const intOrUndef = s => (s.trim() === '' ? undefined : (/^[0-9]+$/.test(s.trim()) ? Number(s.trim()) : s.trim()));
  const show = (id, fn) => {
    const out = $(id);
    try { out.textContent = fn(); out.className = 'eurl'; out.dataset.ok = '1'; }
    catch (e) { out.textContent = e.message; out.className = 'eurl eerr'; out.dataset.ok = ''; }
  };
  const update = () => {
    const line = intOrUndef(inLine.value), to = intOrUndef(inTo.value);
    const chosen = [...pick.selectedOptions].map(o => o.value);
    const layers = chosen.length ? chosen : undefined;
    show('emitA', () => buildDeepLink(RECEIVERS[0].id, { line, to, layers }));
    show('emitB', () => buildDeepLink('line-wafer-202609151339', { line, to, layers }));
  };
  for (const el of [inLine, inTo, pick]) el.addEventListener('input', update);
  pick.addEventListener('change', update);
  $('emitCopy').addEventListener('click', async () => {
    const t = $('emitA').dataset.ok ? $('emitA').textContent : '';
    if (!t) return;
    try { await navigator.clipboard.writeText(t); $('emitCopy').textContent = 'COPIED'; }
    catch { $('emitCopy').textContent = 'COPY BLOCKED'; }
    setTimeout(() => { $('emitCopy').textContent = 'COPY'; }, 1400);
  });
  update();
  sec.hidden = false;
}

async function checkReceivers() {
  const out = $('emitReceivers');
  try {
    const r = await fetch(ROOT + 'engine/receivers.json', { cache: 'no-cache' });
    if (!r.ok) throw new Error('engine/receivers.json returned HTTP ' + r.status);
    const doc = await r.json();
    const a = JSON.stringify(doc.receivers), b = JSON.stringify(RECEIVERS);
    if (a !== b) throw new Error('engine/receivers.json disagrees with RECEIVERS in the module');
    out.textContent = `receivers.json agrees with the module · ${RECEIVERS.map(x => x.id).join(', ')}`;
    out.className = 'estat OK';
  } catch (e) { out.textContent = 'FAIL · ' + e.message; out.className = 'estat FAIL'; }
}

paintCard();
checkReceivers();
fetch(ROOT + 'layers/manifest.json', { cache: 'no-cache' })
  .then(r => (r.ok ? r.json() : null)).catch(() => null)
  .then(m => emitPanel(m));