In this section
- Gl render · globalgrid2050 / testcode/202609142225/gl.js lines 1–227
- Chord render · globalgrid2050 / testcode/202609142225/lenses/chord.js lines 1–60
- Column render · globalgrid2050 / testcode/202609142225/lenses/column.js lines 1–75
- Ring transform · globalgrid2050 / testcode/202609142225/lenses/ring.js lines 1–62
- River transform · globalgrid2050 / testcode/202609142225/lenses/river.js lines 1–60
- Table render · globalgrid2050 / testcode/202609142225/lenses/table.js lines 1–82
Gl
A JavaScript module in the testcode folder of GlobalGrid2050 that syncs pos tex (`syncPosTex`) and meta tex (`syncMetaTex`) and draws on a canvas.
renderglobalgrid2050 / testcode/202609142225/gl.js · lines 1–227 of 227 · version 2026-09-14 22:25 · Not reached from any entry point (candidate for review) · pattern upload (shared by 3 files)
- What it does
- It draws its content. Defines 11 functions or classes, including hex, ease, compile, mk, createGL. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. README: "A read-only lab page: `index.html` + `style.css` + `core.js` + `gl.js` + `ui.js` + `lenses/*.js` (ES modules, WebGL2, no CDN, no framework, no build step)."
- Inputs & outputs
- Out: WebGL/WebGPU drawing.
- Downstream impact
- Used directly by 1 file: UI (globalgrid2050).
- What it achieves
- It syncs pos tex (`syncPosTex`) and syncs meta tex (`syncMetaTex`). Star Generator — `gl.js` (GRAMMAR §1.5).
- Why it matters
- Imported by UI.
- Application
- globalgrid2050 · testcode/202609142225 · JavaScript module
- Uses
- GlobalGrid2050 — Testcode (import)
- Used by
- imported by UI (import)
- Produces
- SEG_STRIDE, createGL, draw2D
- Defines here
- hex, ease, compile, mk, createGL, buf, inst, syncPosTex, syncMetaTex, upload, draw2D
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609142225/gl.js:1-227 · blob 593f24e84bd9b1206426197e8b3603c2f0f46941 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: experimental · users: none · canonical: unreached_review
/* Star Generator — gl.js (GRAMMAR §1.5). One WebGL2 context, buffers uploaded once; only lit, positions and the
* per-focus edge/geometry instance lists are re-uploaded. Two lens programs (points, segments) shared by every lens —
* a lens cannot add one — plus one shell-owned program (lines) that keeps all 664,940 numbered-line instances
* resident on the GPU once and draws them around their families. 2D-canvas fallback when WebGL2 is absent.
*/
import { PAL, REL, REL_WORDS } from './core.js';
const hex = h => { const n = parseInt(h.slice(1), 16); return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255]; };
const ease = t => t < .5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
const VS_POINTS = `#version 300 es
precision highp float;
bool nanf(float x){ uint b = floatBitsToUint(x); return (b & 0x7f800000u) == 0x7f800000u && (b & 0x007fffffu) != 0u; } // NaN by its bit pattern: on D3D11 through ANGLE a float compared with itself, and the isnan builtin, both fold to false, so the sentinel test must not be a float comparison
layout(location=0) in vec2 a_quad; layout(location=1) in vec2 a_posA; layout(location=2) in vec2 a_posB;
layout(location=3) in uvec4 a_meta; layout(location=4) in float a_mass; layout(location=5) in vec2 a_orb;
uniform mat3 u_view; uniform vec2 u_res; uniform float u_mix, u_time, u_dpr, u_orbit; uniform float u_base[5]; uniform float u_gain[5];
out vec2 v_uv; flat out uint v_cat; flat out uint v_cls; flat out uint v_lit; out float v_light;
float lightOf(uint lit){ float l = 0.35; if((lit&8u)!=0u) l = max(l,0.7); if((lit&1u)!=0u) l = max(l,0.8); if((lit&4u)!=0u) l = max(l,0.9); if((lit&2u)!=0u) l = 1.0; if((lit&32u)!=0u) l *= 0.4; return l; }
void main(){
float t = u_mix; t = t < .5 ? 4.*t*t*t : 1. - pow(-2.*t + 2., 3.)/2.;
vec2 A = a_posA, B = a_posB; bool na = nanf(A.x), nb = nanf(B.x);
vec2 p = na && nb ? vec2(0.) : na ? B : nb ? A : mix(A, B, t);
float fade = (na && nb) ? 0. : na ? t : nb ? (1. - t) : 1.;
if (u_orbit > 0.5 && a_orb.x >= 0.0) { float ring = a_orb.x; float ang = a_orb.y + u_time * 0.25 / (ring + 1.0); p += vec2(cos(ang), sin(ang)) * (16.0 + ring * 18.0); }
uint cls = a_meta.y; v_lit = a_meta.z; float light = lightOf(a_meta.z);
float size = clamp(u_base[cls] + u_gain[cls] * sqrt(a_mass), 2.0, 14.0);
if ((a_meta.z & 2u) != 0u) size *= 1.5; else if (light >= 0.8) size *= 1.3;
vec3 s = u_view * vec3(p, 1.0);
vec2 css = s.xy + a_quad * size * 0.5;
vec2 clip = (css / u_res * 2.0 - 1.0) * vec2(1.0, -1.0);
gl_Position = fade <= 0.0 ? vec4(2.0, 2.0, 2.0, 1.0) : vec4(clip, 0.0, 1.0);
v_uv = a_quad; v_cat = a_meta.x; v_cls = cls; v_light = light * fade;
}`;
const FS_POINTS = `#version 300 es
precision highp float;
in vec2 v_uv; flat in uint v_cat; flat in uint v_cls; flat in uint v_lit; in float v_light;
uniform vec3 u_catColour[21]; uniform vec3 u_ring; uniform float u_dpr;
out vec4 o;
void main(){
float d = v_cls == 4u ? max(abs(v_uv.x), abs(v_uv.y)) : length(v_uv);
float edge = fwidth(d) * 1.2;
float a = 1.0 - smoothstep(0.85 - edge, 0.85 + edge, d);
vec3 c = u_catColour[min(v_cat, 12u)];
float alpha = (0.18 + 0.82 * v_light) * a;
if ((v_lit & 4u) != 0u) { float r = smoothstep(0.75 - edge, 0.75, d) * (1.0 - smoothstep(0.95, 0.95 + edge, d)); c = mix(c, u_ring, r); alpha = max(alpha, r * 0.95); }
if ((v_lit & 8u) != 0u && (v_lit & 4u) == 0u) { float ang = atan(v_uv.y, v_uv.x); float dot_ = step(0.5, fract(ang / 6.2832 * 8.0)); float r = smoothstep(0.78 - edge, 0.78, d) * (1.0 - smoothstep(0.95, 0.95 + edge, d)) * dot_; c = mix(c, u_ring, r); alpha = max(alpha, r * 0.9); }
if (alpha <= 0.003) discard;
o = vec4(c, alpha);
}`;
const VS_SEG = `#version 300 es
precision highp float;
bool nanf(float x){ uint b = floatBitsToUint(x); return (b & 0x7f800000u) == 0x7f800000u && (b & 0x007fffffu) != 0u; } // NaN by its bit pattern: on D3D11 through ANGLE a float compared with itself, and the isnan builtin, both fold to false, so the sentinel test must not be a float comparison
layout(location=0) in vec2 a_a0; layout(location=1) in vec2 a_a1; layout(location=2) in vec2 a_ac;
layout(location=3) in vec2 a_b0; layout(location=4) in vec2 a_b1; layout(location=5) in vec2 a_bc;
layout(location=6) in vec4 a_style; layout(location=7) in float a_flags;
uniform mat3 u_view; uniform vec2 u_res; uniform float u_mix, u_dpr, u_zoom;
out float v_t; flat out float v_kind; flat out float v_cls; flat out float v_light; flat out float v_flags;
void main(){
float m = u_mix; m = m < .5 ? 4.*m*m*m : 1. - pow(-2.*m + 2., 3.)/2.;
int i = gl_VertexID / 2; float side = float(gl_VertexID % 2) * 2.0 - 1.0; float t = float(i) / 16.0;
int flags = int(a_flags); bool arrow = (flags & 2) != 0; bool rev = (flags & 4) != 0;
if (rev) t = 1.0 - t;
vec2 p0 = mix(a_a0, a_b0, m), p1 = mix(a_a1, a_b1, m), pc = mix(a_ac, a_bc, m);
bool bad = nanf(p0.x) || nanf(p1.x) || nanf(pc.x);
vec2 P = (1.-t)*(1.-t)*p0 + 2.*(1.-t)*t*pc + t*t*p1;
vec2 T = 2.*(1.-t)*(pc - p0) + 2.*t*(p1 - pc); if (length(T) < 1e-4) T = p1 - p0; vec2 Ts = normalize((u_view * vec3(T, 0.0)).xy); vec2 Nn = vec2(-Ts.y, Ts.x); // the normal in screen space, so rotation and zoom keep widths in CSS px
float w = a_style.x;
if (arrow) { int j = rev ? 16 - i : i; if (j == 15) w = max(w * 3.0, 5.0); else if (j == 16) w = 0.05; } // arrowhead = the last two vertices widened
vec3 s = u_view * vec3(P, 1.0);
vec2 css = s.xy + Nn * side * w * 0.5;
vec2 clip = (css / u_res * 2.0 - 1.0) * vec2(1.0, -1.0);
gl_Position = bad ? vec4(2.,2.,2.,1.) : vec4(clip, 0.0, 1.0);
v_t = t; v_kind = a_style.y; v_cls = a_style.w; v_light = a_style.z; v_flags = a_flags;
}`;
const FS_SEG = `#version 300 es
precision highp float;
in float v_t; flat in float v_kind; flat in float v_cls; flat in float v_light; flat in float v_flags;
uniform vec3 u_catColour[21]; uniform vec3 u_relColour[8]; uniform float u_kindsOn[8]; uniform float u_faint; uniform float u_geomFade;
out vec4 o;
void main(){
int flags = int(v_flags); bool geom = (flags & 1) != 0; int k = int(v_kind);
vec3 c; float alpha;
if (geom) { c = u_catColour[min(k, 20)]; alpha = (v_cls < 1.5 ? 0.3 : 0.9 * v_light) * u_geomFade; }
else { if (u_kindsOn[k] < 0.5) discard; c = u_relColour[k]; alpha = v_cls < 1.5 ? u_faint : 0.9 * v_light; }
if (k == 5 && !geom) { if (fract(v_t * 40.0) > 0.45) discard; }
if (k == 6 && !geom) { if (fract(v_t * 20.0) > 0.6) discard; }
if (k == 7 && !geom) { if (fract(v_t * 24.0) > 0.5) discard; alpha = 0.6; }
if ((flags & 8) != 0) { if (fract(v_t * 20.0) > 0.6) discard; }
o = vec4(c, alpha);
}`;
const VS_LINES = `#version 300 es
precision highp float;
bool nanf(float x){ uint b = floatBitsToUint(x); return (b & 0x7f800000u) == 0x7f800000u && (b & 0x007fffffu) != 0u; } // NaN by its bit pattern: on D3D11 through ANGLE a float compared with itself, and the isnan builtin, both fold to false, so the sentinel test must not be a float comparison
layout(location=0) in uint a_fam; layout(location=1) in float a_ord; layout(location=2) in float a_shared;
uniform sampler2D u_pos; uniform sampler2D u_meta; uniform mat3 u_view; uniform vec2 u_res; uniform float u_mix, u_dpr, u_zoom;
flat out uint v_cat; out float v_light; flat out float v_shared;
void main(){
float m = u_mix; m = m < .5 ? 4.*m*m*m : 1. - pow(-2.*m + 2., 3.)/2.;
if (a_fam == 0xffffffffu) { gl_Position = vec4(2.,2.,2.,1.); gl_PointSize = 1.0; return; }
int f = int(a_fam); ivec2 tc = ivec2(f % 256, f / 256);
vec4 ab = texelFetch(u_pos, tc, 0); vec4 meta = texelFetch(u_meta, tc, 0);
vec2 A = ab.xy, B = ab.zw; bool na = nanf(A.x), nb = nanf(B.x);
if (na && nb) { gl_Position = vec4(2.,2.,2.,1.); gl_PointSize = 1.0; return; }
vec2 p = na ? B : nb ? A : mix(A, B, m); float fade = na ? m : nb ? 1. - m : 1.;
float r = 5.0 + 1.3 * sqrt(a_ord); float ang = a_ord * 2.39996;
p += vec2(cos(ang), sin(ang)) * r / max(u_zoom, 0.5);
uint lit = uint(meta.z * 255.0 + 0.5); float light = 0.35; if((lit&8u)!=0u) light=0.7; if((lit&1u)!=0u) light=0.8; if((lit&4u)!=0u) light=0.9; if((lit&2u)!=0u) light=1.0; if((lit&32u)!=0u) light*=0.4;
vec3 s = u_view * vec3(p, 1.0); vec2 clip = (s.xy / u_res * 2.0 - 1.0) * vec2(1.0, -1.0);
gl_Position = vec4(clip, 0.0, 1.0); gl_PointSize = 1.5 * u_dpr;
v_cat = uint(meta.x * 255.0 + 0.5); v_light = light * fade; v_shared = a_shared;
}`;
const FS_LINES = `#version 300 es
precision highp float;
flat in uint v_cat; in float v_light; flat in float v_shared;
uniform vec3 u_catColour[21]; uniform vec3 u_shared;
out vec4 o;
void main(){ vec3 c = v_shared > 0.5 ? u_shared : u_catColour[min(v_cat, 12u)]; float a = (0.18 + 0.82 * v_light) * 0.55; if (a < 0.01) discard; o = vec4(c, a); }`;
function compile(gl, vs, fs) {
const mk = (t, s) => { const sh = gl.createShader(t); gl.shaderSource(sh, s); gl.compileShader(sh); if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) throw new Error('shader: ' + gl.getShaderInfoLog(sh)); return sh; };
const p = gl.createProgram(); gl.attachShader(p, mk(gl.VERTEX_SHADER, vs)); gl.attachShader(p, mk(gl.FRAGMENT_SHADER, fs)); gl.linkProgram(p);
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) throw new Error('link: ' + gl.getProgramInfoLog(p));
const u = {}; const n = gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); for (let i = 0; i < n; i++) { const inf = gl.getActiveUniform(p, i); u[inf.name.replace(/\[0\]$/, '')] = gl.getUniformLocation(p, inf.name); }
return { p, u };
}
/** SEG layout: 17 floats per instance = a0(2) a1(2) ac(2) b0(2) b1(2) bc(2) style(width, kindOrCat, light, cls) flags */
export const SEG_STRIDE = 17;
export function createGL(canvas, core) {
const gl = canvas.getContext('webgl2', { antialias: true, alpha: false, premultipliedAlpha: false });
const N = core.N;
const G = { gl, N, ok: !!gl, mix: 1, tweenStart: 0, tweenMs: 600, time0: performance.now(), orbit: 0, geomFade: 1, faint: 0.12, kindsOn: 0x7f, view: { pan: [0, 0], zoom: 1, rotate: 0 }, w: 1, h: 1, dpr: 1, posA: new Float32Array(2 * N).fill(NaN), posB: new Float32Array(2 * N).fill(NaN), orb: new Float32Array(2 * N).fill(-1), meta: new Uint8Array(4 * N), edgeCount: 0, geomCount: 0, journeyCount: … [line shortened here: 455 characters; full line on GitHub]
for (let i = 0; i < N; i++) { G.meta[4 * i] = core.cat[i] === 255 ? 12 : core.cat[i]; G.meta[4 * i + 1] = core.cls[i]; }
const catColours = new Float32Array(21 * 3); core.U.cats.forEach((c, i) => catColours.set(hex(c.colour || PAL.muted), i * 3)); catColours.set(hex(PAL.muted), 36); REL_WORDS.forEach((w, i) => catColours.set(hex(REL[w]), (13 + i) * 3)); catColours.set(hex(PAL.busbar), 60);
const relColours = new Float32Array(8 * 3); REL_WORDS.forEach((w, i) => relColours.set(hex(REL[w]), i * 3)); relColours.set(hex(PAL.accent), 21);
G.catColours = catColours; G.relColours = relColours;
if (!gl) { G.ctx2d = canvas.getContext('2d'); return G; }
const P = compile(gl, VS_POINTS, FS_POINTS), S = compile(gl, VS_SEG, FS_SEG), L = compile(gl, VS_LINES, FS_LINES);
const buf = (data, usage = gl.STATIC_DRAW) => { const b = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, b); gl.bufferData(gl.ARRAY_BUFFER, data, usage); return b; };
const quad = buf(new Float32Array([-1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1]));
const bPosA = buf(G.posA, gl.DYNAMIC_DRAW), bPosB = buf(G.posB, gl.DYNAMIC_DRAW), bMeta = buf(G.meta, gl.DYNAMIC_DRAW), bMass = buf(core.mass, gl.DYNAMIC_DRAW), bOrb = buf(G.orb, gl.DYNAMIC_DRAW);
// points VAO
const vaoP = gl.createVertexArray(); gl.bindVertexArray(vaoP);
gl.bindBuffer(gl.ARRAY_BUFFER, quad); gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
const inst = (loc, b, size, type, isInt) => { gl.bindBuffer(gl.ARRAY_BUFFER, b); gl.enableVertexAttribArray(loc); if (isInt) gl.vertexAttribIPointer(loc, size, type, 0, 0); else gl.vertexAttribPointer(loc, size, type, false, 0, 0); gl.vertexAttribDivisor(loc, 1); };
inst(1, bPosA, 2, gl.FLOAT); inst(2, bPosB, 2, gl.FLOAT); inst(3, bMeta, 4, gl.UNSIGNED_BYTE, true); inst(4, bMass, 1, gl.FLOAT); inst(5, bOrb, 2, gl.FLOAT);
// segments VAO (edges, geometry, journey share one layout; three dynamic buffers)
const mkSeg = () => { const b = gl.createBuffer(); const vao = gl.createVertexArray(); gl.bindVertexArray(vao); gl.bindBuffer(gl.ARRAY_BUFFER, b); const st = SEG_STRIDE * 4; const offs = [0, 2, 4, 6, 8, 10]; offs.forEach((o, i) => { gl.enableVertexAttribArray(i); gl.vertexAttribPointer(i, 2, gl.FLOAT, false, st, o * 4); gl.vertexAttribDivisor(i, 1); }); gl.enableVertexAttribArray(6); gl.vertexAt … [line shortened here: 617 characters; full line on GitHub]
const segEdges = mkSeg(), segGeom = mkSeg(), segJourney = mkSeg();
// textures for the lines program: family positions (RGBA32F: ax ay bx by) and meta (RGBA8)
const TH = Math.ceil(N / 256);
const tex = (internal, fmt, type, data) => { const t = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, t); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); gl.texImage2D … [line shortened here: 471 characters; full line on GitHub]
const posTex4 = new Float32Array(256 * TH * 4).fill(NaN), metaTex = new Uint8Array(256 * TH * 4);
const tPos = tex(gl.RGBA32F, gl.RGBA, gl.FLOAT, posTex4), tMeta = tex(gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, metaTex);
let vaoL = null, bLinesFam = null;
gl.enable(gl.BLEND); gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); gl.disable(gl.DEPTH_TEST);
const bg = hex(PAL.body); gl.clearColor(bg[0], bg[1], bg[2], 1);
const syncPosTex = () => { for (let i = 0; i < N; i++) { posTex4[4 * i] = G.posA[2 * i]; posTex4[4 * i + 1] = G.posA[2 * i + 1]; posTex4[4 * i + 2] = G.posB[2 * i]; posTex4[4 * i + 3] = G.posB[2 * i + 1]; } gl.bindTexture(gl.TEXTURE_2D, tPos); gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 256, TH, gl.RGBA, gl.FLOAT, posTex4); };
const syncMetaTex = () => { metaTex.set(G.meta); gl.bindTexture(gl.TEXTURE_2D, tMeta); gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 256, TH, gl.RGBA, gl.UNSIGNED_BYTE, metaTex); };
/** begin a tween: current interpolated positions become A, `target` becomes B */
G.setPositions = function (target) {
const t = ease(Math.min(1, G.mix));
for (let i = 0; i < 2 * N; i++) { const a = G.posA[i], b = G.posB[i]; G.posA[i] = (a !== a) ? b : (b !== b) ? a : a + (b - a) * t; }
G.posB.set(target);
gl.bindBuffer(gl.ARRAY_BUFFER, bPosA); gl.bufferSubData(gl.ARRAY_BUFFER, 0, G.posA); gl.bindBuffer(gl.ARRAY_BUFFER, bPosB); gl.bufferSubData(gl.ARRAY_BUFFER, 0, G.posB);
syncPosTex(); G.mix = 0; G.tweenStart = performance.now();
};
G.setLit = function (lit) { for (let i = 0; i < N; i++) G.meta[4 * i + 2] = lit[i]; gl.bindBuffer(gl.ARRAY_BUFFER, bMeta); gl.bufferSubData(gl.ARRAY_BUFFER, 0, G.meta); syncMetaTex(); };
G.setMass = function () { gl.bindBuffer(gl.ARRAY_BUFFER, bMass); gl.bufferSubData(gl.ARRAY_BUFFER, 0, core.mass); };
G.setOrbit = function (orb, on) { G.orb.set(orb); G.orbit = on ? 1 : 0; gl.bindBuffer(gl.ARRAY_BUFFER, bOrb); gl.bufferSubData(gl.ARRAY_BUFFER, 0, G.orb); };
const upload = (seg, data, count) => { gl.bindBuffer(gl.ARRAY_BUFFER, seg.b); gl.bufferData(gl.ARRAY_BUFFER, data.subarray(0, count * SEG_STRIDE), gl.DYNAMIC_DRAW); seg.n = count; };
G.setEdges = (data, n) => { upload(segEdges, data, n); G.edgeCount = n; };
G.setGeometry = (data, n) => { upload(segGeom, data, n); G.geomCount = n; };
G.setJourney = (data, n) => { upload(segJourney, data, n); G.journeyCount = n; };
/** all line instances resident once: fam index (uint32), ordinal within family (float32), shared flag (uint8) */
G.setLines = function (lineFam, lineOrd, lineShared) {
vaoL = gl.createVertexArray(); gl.bindVertexArray(vaoL);
bLinesFam = buf(lineFam); gl.enableVertexAttribArray(0); gl.vertexAttribIPointer(0, 1, gl.UNSIGNED_INT, 0, 0);
buf(lineOrd); gl.enableVertexAttribArray(1); gl.vertexAttribPointer(1, 1, gl.FLOAT, false, 0, 0);
buf(lineShared); gl.enableVertexAttribArray(2); gl.vertexAttribPointer(2, 1, gl.UNSIGNED_BYTE, false, 0, 0);
G.linesCount = lineFam.length; G.linesBytes = lineFam.byteLength + lineOrd.byteLength + lineShared.byteLength;
};
G.resize = function (w, h, dpr) { G.w = w; G.h = h; G.dpr = dpr; canvas.width = Math.round(w * dpr); canvas.height = Math.round(h * dpr); gl.viewport(0, 0, canvas.width, canvas.height); };
G.viewMatrix = function () { const { pan, zoom, rotate } = G.view, cx = G.w / 2, cy = G.h / 2, c = Math.cos(rotate) * zoom, s = Math.sin(rotate) * zoom; return new Float32Array([c, s, 0, -s, c, 0, cx + pan[0] - c * cx + s * cy, cy + pan[1] - s * cx - c * cy, 1]); };
G.toScreen = function (x, y) { const m = G.viewMatrix(); return [m[0] * x + m[3] * y + m[6], m[1] * x + m[4] * y + m[7]]; };
G.toLayout = function (sx, sy) { const m = G.viewMatrix(); const det = m[0] * m[4] - m[3] * m[1]; const dx = sx - m[6], dy = sy - m[7]; return [(m[4] * dx - m[3] * dy) / det, (-m[1] * dx + m[0] * dy) / det]; };
G.curPos = function (i) { const t = ease(Math.min(1, G.mix)); const ax = G.posA[2 * i], ay = G.posA[2 * i + 1], bx = G.posB[2 * i], by = G.posB[2 * i + 1]; if (bx !== bx) return ax !== ax ? null : [ax, ay]; if (ax !== ax) return [bx, by]; return [ax + (bx - ax) * t, ay + (by - ay) * t]; };
const base = new Float32Array([5, 4, 3.2, 2.5, 3]), gain = new Float32Array([0.6, 0.6, 0.35, 0.3, 0.12]);
G.frame = function () {
const now = performance.now(); const t0 = now;
if (G.mix < 1) G.mix = Math.min(1, (now - G.tweenStart) / G.tweenMs);
const time = (now - G.time0) / 1000, view = G.viewMatrix();
gl.clear(gl.COLOR_BUFFER_BIT);
const kinds = new Float32Array(8); for (let k = 0; k < 7; k++) kinds[k] = (G.kindsOn >> k) & 1; kinds[7] = 1;
// segments: geometry first, then edges, then the journey on top
gl.useProgram(S.p); gl.uniformMatrix3fv(S.u.u_view, false, view); gl.uniform2f(S.u.u_res, G.w, G.h); gl.uniform1f(S.u.u_mix, G.mix); gl.uniform1f(S.u.u_dpr, G.dpr); gl.uniform1f(S.u.u_zoom, G.view.zoom);
gl.uniform3fv(S.u.u_catColour, catColours); gl.uniform3fv(S.u.u_relColour, relColours); gl.uniform1fv(S.u.u_kindsOn, kinds); gl.uniform1f(S.u.u_faint, G.litOnly ? 0 : G.faint); gl.uniform1f(S.u.u_geomFade, G.geomFade);
for (const seg of [segGeom, segEdges]) if (seg.n) { gl.bindVertexArray(seg.vao); gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 34, seg.n); }
// lines (the sea around each positioned family)
if (vaoL && G.linesCount) { gl.useProgram(L.p); gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, tPos); gl.uniform1i(L.u.u_pos, 0); gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, tMeta); gl.uniform1i(L.u.u_meta, 1); gl.uniformMatrix3fv(L.u.u_view, false, view); gl.uniform2f(L.u.u_res, G.w, G.h); gl.uniform1f(L.u.u_mix, G.mix); gl.uniform1f(L.u.u_dpr, G.dpr); gl.unifor … [line shortened here: 598 characters; full line on GitHub]
// points
gl.useProgram(P.p); gl.uniformMatrix3fv(P.u.u_view, false, view); gl.uniform2f(P.u.u_res, G.w, G.h); gl.uniform1f(P.u.u_mix, G.mix); gl.uniform1f(P.u.u_time, time); gl.uniform1f(P.u.u_dpr, G.dpr); gl.uniform1f(P.u.u_orbit, G.orbit);
gl.uniform1fv(P.u.u_base, base); gl.uniform1fv(P.u.u_gain, gain); gl.uniform3fv(P.u.u_catColour, catColours); gl.uniform3fv(P.u.u_ring, hex(PAL.text));
gl.bindVertexArray(vaoP); gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, N);
if (segJourney.n) { gl.useProgram(S.p); gl.bindVertexArray(segJourney.vao); gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 34, segJourney.n); }
gl.bindVertexArray(null);
// frame-time guard (§8): 30 consecutive frames > 24 ms drops faint edges first
const dt = performance.now() - t0; G.frames++; if (dt > 24) { if (++G.slow >= 30 && !G.litOnly) { G.litOnly = true; G.onLitOnly && G.onLitOnly(); } } else G.slow = 0;
return time;
};
return G;
}
/** 2D fallback: the same layout() output on a 2D canvas, no tween */
export function draw2D(G, core, edges, edgeN) {
const c = G.ctx2d, dpr = G.dpr; c.setTransform(dpr, 0, 0, dpr, 0, 0); c.fillStyle = PAL.body; c.fillRect(0, 0, G.w, G.h);
const m = G.viewMatrix(); c.setTransform(m[0] * dpr, m[1] * dpr, m[3] * dpr, m[4] * dpr, m[6] * dpr, m[7] * dpr);
for (let e = 0; e < edgeN; e++) { const o = e * SEG_STRIDE; const k = edges[o + 13] | 0, geom = (edges[o + 16] | 0) & 1; c.strokeStyle = geom ? core.colour(k < 12 ? core.range.cat[0] + k : -1) : REL[REL_WORDS[k]] || PAL.accent; c.globalAlpha = edges[o + 15] < 1.5 ? 0.12 : 0.9 * edges[o + 14]; c.lineWidth = edges[o + 12]; c.beginPath(); c.moveTo(edges[o + 6], edges[o + 7]); c.quadraticCurveTo(edg … [line shortened here: 469 characters; full line on GitHub]
c.globalAlpha = 1;
for (let i = 0; i < G.N; i++) { const x = G.posB[2 * i], y = G.posB[2 * i + 1]; if (x !== x) continue; const lit = G.meta[4 * i + 2]; const light = lit & 2 ? 1 : lit & 4 ? .9 : lit & 1 ? .8 : lit & 8 ? .7 : .35; c.globalAlpha = 0.18 + 0.82 * light; c.fillStyle = core.colour(i); const s = Math.min(14, Math.max(2, 3 + 0.3 * Math.sqrt(core.mass[i]))) * (lit & 2 ? 1.5 : 1); if (core.cls[i] === 4) c. … [line shortened here: 504 characters; full line on GitHub]
c.globalAlpha = 1;
}Chord
A JavaScript module in the lenses folder of GlobalGrid2050 that calculates planar distances. It is built from the put step (`put`).
renderglobalgrid2050 / testcode/202609142225/lenses/chord.js · lines 1–60 of 60 · version 2026-09-14 22:25 · Not reached from any entry point (candidate for review)
- What it does
- It draws its content. Defines pt, put. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Downstream impact
- Used directly by 1 file: UI (globalgrid2050).
- What it achieves
- Lens chord — from v05-chord-dependencies (GRAMMAR §7 chord). It responds to click events.
- Why it matters
- Imported by UI.
- Application
- globalgrid2050 · testcode/202609142225/lenses · JavaScript module
- Uses
- none found
- Used by
- imported by UI (import)
- Produces
- pt, put
- Defines here
- pt, put
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609142225/lenses/chord.js:1-60 · blob 935cd7c0c5779dc91d1c664d658dde28e18a36d7 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: experimental · users: none · canonical: unreached_review
/* lens chord — from v05-chord-dependencies (GRAMMAR §7 chord). 210 arcs as geometry; depends-on chords through the centre. */
const TAU = Math.PI * 2, GAP = 0.004;
const pt = (cx, cy, r, a) => [cx + r * Math.cos(a - Math.PI / 2), cy + r * Math.sin(a - Math.PI / 2)];
let geo = null; // last layout's arc table for hit()
export default {
id: 'chord',
from: 'v05-chord-dependencies',
wants: ['block', 'family', 'category'],
always: ['block', 'category'],
draws: ['depends on', 'uses', 'used by'],
curve: { mode: 'centre' },
hint(core, view) { return `${core.dependsOnCount} depends-on chords between blocks on the table.`; },
simplify(width) { return width <= 600 ? { thick: 18, strip: true } : { thick: 14, strip: false }; },
camera() { return { pan: false, zoom: [0.5, 6], rotate: true }; },
layout(core, view, out) {
const { w, h } = view, S = Math.min(w, h), cx = w / 2, cy = h / 2, R = 0.40 * S, [b0, b1] = core.range.block, n = b1 - b0, step = TAU / n;
const put = (i, p) => { out[2 * i] = p[0]; out[2 * i + 1] = p[1]; };
geo = { cx, cy, R, step, n, b0, thick: view.params.thick || 14 };
let rotate = 0;
for (let i = b0; i < b1; i++) { const a = (i - b0 + 0.5) * step; put(i, pt(cx, cy, 0.98 * R, a)); if (i === view.open) rotate = -a; }
const first = new Map(), last = new Map(); for (let i = b0; i < b1; i++) { const c = core.cat[i]; if (!first.has(c)) first.set(c, i - b0); last.set(c, i - b0); }
for (let c = core.range.cat[0]; c < core.range.cat[1]; c++) { const ci = c - core.range.cat[0]; if (first.has(ci)) put(c, pt(cx, cy, 1.08 * R, ((first.get(ci) + last.get(ci)) / 2 + 0.5) * step)); }
if (view.focus >= 0 && core.cls[view.focus] === 4 && view.open >= 0 && core.cls[view.open] === 2) put(view.focus, pt(cx, cy, 0.9 * R, (view.open - b0 + 0.5) * step));
return { bounds: [cx - 1.1 * R, cy - 1.1 * R, cx + 1.1 * R, cy + 1.1 * R], home: { pan: [0, 0], zoom: 1, rotate } };
},
edges(core, view) {
const a = [], b = [], kind = [], cls = [], w = [], o = view.open, f = view.focus;
if (o >= 0 && core.cls[o] === 2) {
for (const t of core.edgesOf(o, 1, 'out')) { a.push(o); b.push(t); kind.push(1); cls.push(2); w.push(1); }
for (const s of core.edgesOf(o, 1, 'in')) { a.push(s); b.push(o); kind.push(3); cls.push(2); w.push(1); }
}
if (f >= 0 && core.cls[f] === 4 && o >= 0) {
const seen = new Set();
for (const t of core.edgesOf(f, 2, 'out')) { const p = core.parent[t]; if (p >= 0 && p !== o && core.cls[p] === 2 && !seen.has('u' + p)) { seen.add('u' + p); a.push(f); b.push(p); kind.push(2); cls.push(2); w.push(1); } }
for (const s of core.edgesOf(f, 2, 'in')) { const p = core.parent[s]; if (p >= 0 && p !== o && core.cls[p] === 2 && !seen.has('b' + p)) { seen.add('b' + p); a.push(p); b.push(f); kind.push(3); cls.push(2); w.push(1); } }
}
for (const r of view.recipe) if (core.cls[r] === 2) for (const t of core.edgesOf(r, 1, 'out')) if (view.recipe.includes(t)) { a.push(r); b.push(t); kind.push(1); cls.push(2); w.push(1); }
return { a: Uint32Array.from(a), b: Uint32Array.from(b), kind: Uint8Array.from(kind), cls: Uint8Array.from(cls), w: Float32Array.from(w) };
},
geometry(core, view) {
if (!geo) return null; const { cx, cy, R, step, n, b0, thick } = geo, g = [];
for (let k = 0; k < n; k++) { const i = b0 + k, a0 = k * step + GAP / 2, a1 = (k + 1) * step - GAP / 2, am = (a0 + a1) / 2, rc = R / Math.cos((a1 - a0) / 2); const p0 = pt(cx, cy, R, a0), p1 = pt(cx, cy, R, a1), c = pt(cx, cy, rc, am); const lit = view.lit[i] & 15; g.push(p0[0], p0[1], c[0], c[1], p1[0], p1[1], thick, core.cat[i] === 255 ? core.GEOM.muted : core.cat[i], lit ? 2 : 1); }
// every depends-on chord between table blocks, faint, in the depending block's category colour when idle
if ((view.kindsOn >> 1) & 1) { const E = core.edges; for (let e = 0; e < E.n; e++) { if (E.kind[e] !== 1) continue; const s = E.a[e], t = E.b[e]; if (core.cls[s] !== 2 || core.cls[t] !== 2) continue; if (view.open >= 0 && (s === view.open || t === view.open)) continue; const ps = pt(cx, cy, 0.98 * R, (s - b0 + 0.5) * step), pt2 = pt(cx, cy, 0.98 * R, (t - b0 + 0.5) * step); g.push(ps[0], ps[1] … [line shortened here: 489 characters; full line on GitHub]
return Float32Array.from(g);
},
hit(core, view, x, y) {
if (!geo) return -1; const { cx, cy, R, step, n, b0, thick } = geo; const d = Math.hypot(x - cx, y - cy); if (Math.abs(d - R) > thick) return -1;
let a = Math.atan2(y - cy, x - cx) + Math.PI / 2; if (a < 0) a += TAU; const k = Math.floor(a / step); return k >= 0 && k < n ? b0 + k : -1;
},
labels(core, view, max) { const out = []; for (let i = 0; i < core.N && out.length < max; i++) if ((view.lit[i] & 15) && core.cls[i] !== 1 && core.cls[i] !== 3) out.push(i); if (view.open < 0) for (let c = core.range.cat[0]; c < core.range.cat[1] && out.length < max; c++) out.push(c); return Uint32Array.from(out); },
overlay(core, view, host, shell) {
host.innerHTML = ''; host.style.pointerEvents = 'none'; if (!view.params.strip) return;
const strip = document.createElement('div'); strip.style.cssText = 'position:absolute;left:0;right:0;bottom:0;height:44px;overflow-x:auto;overflow-y:hidden;white-space:nowrap;pointer-events:auto;padding:4px 6px;';
for (let i = core.range.block[0]; i < core.range.block[1]; i++) { const b = document.createElement('button'); b.textContent = core.rec[i].symbol; b.style.cssText = `display:inline-block;min-width:36px;height:36px;margin-right:2px;border-radius:6px;border:1px solid ${core.colour(i)};background:${i === view.open ? core.colour(i) : 'transparent'};color:${i === view.open ? core.PAL.body : core.col … [line shortened here: 606 characters; full line on GitHub]
host.append(strip);
},
leave() { geo = null; },
};Column
A JavaScript module in the lenses folder of GlobalGrid2050. It is built from the card step (`card`) and the fan step (`fan`).
renderglobalgrid2050 / testcode/202609142225/lenses/column.js · lines 1–75 of 75 · version 2026-09-14 22:25 · Not reached from any entry point (candidate for review)
- What it does
- It draws its content. Defines card, H, fan. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Downstream impact
- Used directly by 1 file: UI (globalgrid2050).
- What it achieves
- Lens column — from ventus-grid-engine column view + v10 single-line diagram (GRAMMAR §7 column). It responds to click events.
- Why it matters
- Imported by UI.
- Application
- globalgrid2050 · testcode/202609142225/lenses · JavaScript module
- Uses
- Table (import)
- Used by
- imported by UI (import)
- Produces
- card, H, fan
- Defines here
- card, H, fan
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609142225/lenses/column.js:1-75 · blob 6d45ef5ac1f0fbdcdd4c1ac45a24d43081143f8e · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: experimental · users: none · canonical: unreached_review
/* lens column — from ventus-grid-engine column view + v10 single-line diagram (GRAMMAR §7 column).
* A native single column of cards on a busbar; on desktop a spider toggle fans the same cards out from the same positions. */
import { swipeable } from './table.js'; // the same tap / long-press / swipe-right gesture on a card as on a tile
let host = null, cards = new Map(), show = 'both', spider = false, sections = [];
function card(core, i, view, shell, kindWord, focus) {
const c = document.createElement('div'); c.className = 'card' + (focus ? ' focus' : '') + (view.recipe.includes(i) ? ' recipe' : '') + (view.recipeDerived && view.recipeDerived.includes(i) ? ' derived' : '');
const colour = kindWord ? core.REL[kindWord] : core.PAL.border; c.style.borderLeftColor = colour; c.style.background = `linear-gradient(90deg, ${core.colour(i)}14, transparent 40%)`;
const t = document.createElement('div'); t.textContent = core.label(i); c.append(t);
const w = document.createElement('div'); w.className = 'cw'; w.textContent = core.CLS_WORD[core.cls[i]] + (kindWord ? ` · ${kindWord}` : ''); c.append(w);
if (focus) { const cnt = document.createElement('div'); cnt.className = 'cw'; const parts = []; if (core.cls[i] === 2 || core.cls[i] === 3) { parts.push(`depends on ${core.edgesOf(i, 1, 'out').length}`, `used by ${core.edgesOf(i, 1, 'in').length}`, `contains ${core.familiesOf(i).length}`, `found in ${core.edgesOf(i, 0, 'in').filter(x => core.cls[x] === 1).length}`); } else if (core.cls[i] === 4) … [line shortened here: 677 characters; full line on GitHub]
swipeable(c, i, shell, () => { if (focus) shell.measure(i); else shell.navigate(i); });
cards.set(i, { el: c, kind: kindWord }); return c;
}
export default {
id: 'column',
from: 'ventus-grid-engine column view + v10 single-line diagram',
wants: ['block', 'group', 'family', 'category', 'repo'],
always: [], // every card depends on the focus; with no focus the 210 blocks are the column
draws: ['contains', 'depends on', 'uses', 'used by', 'shared line'],
curve: { mode: 'straight' },
hint(core, view) { return spider ? 'The same cards fanned out: outgoing to the right, incoming to the left.' : 'One column on a busbar: what the key depends on above it, what uses it below it.'; },
simplify(width) { return width <= 600 ? { cardH: 64, spider: false } : { cardH: 64, spider: true }; },
camera() { return spider ? { pan: true, zoom: [0.5, 4], rotate: false } : { pan: false, zoom: null, rotate: false }; },
overlay(core, view, h, shell) {
host = h; h.innerHTML = ''; cards.clear(); sections = []; h.style.pointerEvents = spider ? 'none' : 'auto';
const col = document.createElement('div'); col.className = 'col'; const R = core.range, f = view.focus;
const seg = document.createElement('div'); seg.className = 'seg'; seg.style.pointerEvents = 'auto';
// show / spider are lens parameters: they redraw the lens and never move the focus, the trail or history
for (const s of ['both', 'depends on', 'used by']) { const b = document.createElement('button'); b.className = 'u-chip' + (show === s ? ' on' : ''); b.textContent = `show: ${s}`; b.addEventListener('click', () => { show = s; shell.relayout(false); }); seg.append(b); }
if (view.params.spider) { const b = document.createElement('button'); b.className = 'u-chip' + (spider ? ' on' : ''); b.textContent = spider ? 'column' : 'spider'; b.addEventListener('click', () => { spider = !spider; shell.relayout(true); }); seg.append(b); }
col.append(seg);
const H = (t) => { const e = document.createElement('h4'); e.textContent = t; col.append(e); };
if (f < 0) { H('blocks on the table, in table order'); for (let i = R.block[0]; i < R.block[1]; i++) col.append(card(core, i, view, shell, null, false)); h.append(col); return; }
const cls = core.cls[f]; const isFam = cls === 4;
if (core.parent[f] >= 0) { H('◂ contained in'); col.append(card(core, core.parent[f], view, shell, 'contains', false)); }
const outK = isFam ? 2 : 1, outWord = isFam ? 'uses' : 'depends on'; const outs = [...core.edgesOf(f, outK, 'out')], ins = [...core.edgesOf(f, outK, 'in')];
if (show !== 'used by' && (cls === 2 || cls === 3 || isFam)) { H(`→ ${outWord} (${outs.length})`); for (const t of outs) col.append(card(core, t, view, shell, outWord, false)); }
col.append(card(core, f, view, shell, null, true));
if (show !== 'depends on' && (cls === 2 || cls === 3 || isFam)) { H(`← used by (${ins.length})`); for (const t of ins) col.append(card(core, t, view, shell, 'used by', false)); }
if (view.lineKey != null) { const fs = [...(core.familiesOfLine(view.lineKey) || [])].filter(x => x !== f); H(`families carrying line ${view.lineKey.toLocaleString('en-GB')} (${fs.length})`); for (const t of fs.slice(0, 40)) col.append(card(core, t, view, shell, 'shared line', false)); }
if (isFam) { const sh = core.edgesOf(f, 4, 'both'); if (sh.length) { H(`≡ shared line (${sh.length})`); for (const t of [...sh].slice(0, 40)) col.append(card(core, t, view, shell, 'shared line', false)); } }
if (cls === 0 || cls === 1) { const m = [...core.edgesOf(f, 0, 'out')]; H(`contains (${m.length})`); for (const t of m.slice(0, 60)) col.append(card(core, t, view, shell, 'contains', false)); }
if (cls === 2 || cls === 3) { const m = [...core.familiesOf(f)]; H(`contains (${m.length} families)`); for (const t of m.slice(0, 40)) col.append(card(core, t, view, shell, 'contains', false)); }
const repos = cls === 2 ? core.edgesOf(f, 0, 'in').filter(x => core.cls[x] === 1) : [];
if (repos.length) { H(`▸ found in (${repos.length})`); for (const t of repos) col.append(card(core, t, view, shell, 'contains', false)); }
h.append(col);
},
layout(core, view, out) {
if (!host) return { bounds: [0, 0, view.w, view.h], home: { pan: [0, 0], zoom: 1, rotate: 0 } };
const hr = host.getBoundingClientRect(), st = host.scrollTop; let maxY = 0;
if (!spider) { for (const [i, c] of cards) { const r = c.el.getBoundingClientRect(); out[2 * i] = r.left - hr.left; out[2 * i + 1] = r.top - hr.top + st + r.height / 2; if (out[2 * i + 1] > maxY) maxY = out[2 * i + 1]; } return { bounds: [0, 0, view.w, maxY], home: { pan: [0, -st], zoom: 1, rotate: 0 } }; }
const { w, h } = view, cx = w / 2, cy = h / 2; const groups = { focus: [], out: [], in: [], up: [], down: [] };
for (const [i, c] of cards) { if (i === view.focus) groups.focus.push(i); else if (c.kind === 'depends on' || c.kind === 'uses') groups.out.push(i); else if (c.kind === 'used by') groups.in.push(i); else if (c.kind === 'contains' && core.cls[i] === 1) groups.down.push(i); else if (c.kind === 'contains' && (core.cls[i] === 0 || core.cls[i] === 2 || core.cls[i] === 3)) groups.up.push(i); else gr … [line shortened here: 420 characters; full line on GitHub]
const fan = (list, x, y0, y1) => list.forEach((i, k) => { out[2 * i] = x; out[2 * i + 1] = y0 + (y1 - y0) * (k + 0.5) / list.length; });
fan(groups.focus, cx, cy, cy); fan(groups.out, 0.8 * w, 40, h - 40); fan(groups.in, 0.2 * w, 40, h - 40); fan(groups.up, cx, 30, 30); fan(groups.down, cx, h - 30, h - 30);
return { bounds: [0, 0, w, h], home: { pan: [0, 0], zoom: 1, rotate: 0 } };
},
edges(core, view) {
const a = [], b = [], kind = [], cls = [], w = [], f = view.focus; if (f < 0) return { a: new Uint32Array(0), b: new Uint32Array(0), kind: new Uint8Array(0), cls: new Uint8Array(0), w: new Float32Array(0) };
if (!spider) return { a: new Uint32Array(0), b: new Uint32Array(0), kind: new Uint8Array(0), cls: new Uint8Array(0), w: new Float32Array(0) }; // in the column the busbar geometry is the wiring
for (const [i, c] of cards) { if (i === f) continue; const k = c.kind === 'depends on' ? 1 : c.kind === 'uses' ? 2 : c.kind === 'used by' ? 3 : c.kind === 'shared line' ? 4 : 0; if (c.kind === 'used by' || (c.kind === 'contains' && i === core.parent[f])) { a.push(i); b.push(f); } else { a.push(f); b.push(i); } kind.push(k); cls.push(2); w.push(1); }
return { a: Uint32Array.from(a), b: Uint32Array.from(b), kind: Uint8Array.from(kind), cls: Uint8Array.from(cls), w: Float32Array.from(w) };
},
geometry(core, view) {
if (spider || !view.pos) return null; const P = view.pos, g = []; let y0 = Infinity, y1 = -Infinity;
for (const [i, c] of cards) { const x = P[2 * i], y = P[2 * i + 1]; if (x !== x) continue; y0 = Math.min(y0, y); y1 = Math.max(y1, y); const k = c.kind ? core.KIND[c.kind] : -1; const col = k >= 0 ? core.GEOM.rel + k : core.GEOM.busbar; g.push(20, y, 32, y, x - 5, y, 2, col, 2); g.push(x - 5, y - 5, x + 5, y - 5, x + 5, y + 5, 1, core.GEOM.busbar, 2); g.push(x + 5, y + 5, x - 5, y + 5, x - 5, … [line shortened here: 433 characters; full line on GitHub]
if (isFinite(y0)) g.push(20, y0 - 20, 20, (y0 + y1) / 2, 20, y1 + 20, 4, core.GEOM.busbar, 2);
return Float32Array.from(g);
},
labels(core, view, max) { if (!spider) return new Uint32Array(0); const out = []; for (const i of cards.keys()) if (out.length < max) out.push(i); return Uint32Array.from(out); },
scrollTo(idx, visibleH) { const c = cards.get(idx); if (c && host && !spider) { const band = visibleH || host.clientHeight; host.scrollTop = Math.max(0, c.el.offsetTop - Math.max(0, band / 2 - c.el.offsetHeight / 2)); } },
leave() { cards.clear(); host = null; },
};Ring
A JavaScript module in the lenses folder of GlobalGrid2050. It is built from the put step (`put`).
transformglobalgrid2050 / testcode/202609142225/lenses/ring.js · lines 1–62 of 62 · version 2026-09-14 22:25 · Not reached from any entry point (candidate for review)
- What it does
- It calculates its inputs. Defines pt, put.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Downstream impact
- Used directly by 1 file: UI (globalgrid2050).
- What it achieves
- Lens ring — from v08-ring-journey (GRAMMAR §7 ring).
- Why it matters
- Imported by UI.
- Application
- globalgrid2050 · testcode/202609142225/lenses · JavaScript module
- Uses
- none found
- Used by
- imported by UI (import)
- Produces
- pt, put
- Defines here
- pt, put
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609142225/lenses/ring.js:1-62 · blob 9002992a4dcfff30cb22985e44fac5e8728a23c7 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: unreached_review
/* lens ring — from v08-ring-journey (GRAMMAR §7 ring). Positions only; the shell draws, picks and acts. */
const TAU = Math.PI * 2;
const pt = (cx, cy, r, a) => [cx + r * Math.cos(a - Math.PI / 2), cy + r * Math.sin(a - Math.PI / 2)];
export default {
id: 'ring',
from: 'v08-ring-journey',
wants: ['block', 'group', 'family', 'category'],
always: ['block', 'group', 'category'],
draws: ['contains', 'depends on', 'uses', 'used by', 'shared line', 'random link', 'entangled'],
curve: { mode: 'centre' },
hint(core, view) { return view.open >= 0 ? 'Blocks on the outer ring; families of the open block on the inner ring. Drag to rotate.' : 'Blocks on the outer ring, in table order; tap one to open its families on the inner ring.'; },
simplify(width) { return width <= 600 ? { innerCap: 60, labelCap: 12 } : { innerCap: Infinity, labelCap: 60 }; },
camera() { return { pan: false, zoom: [0.5, 6], rotate: true }; },
layout(core, view, out) {
const { w, h } = view, S = Math.min(w, h), cx = w / 2, cy = h / 2, RB = 0.42 * S, RF = 0.27 * S, RC = 0.48 * S, RG = 0.47 * S;
const [b0, b1] = core.range.block, nB = b1 - b0, step = TAU / nB;
const put = (i, p) => { out[2 * i] = p[0]; out[2 * i + 1] = p[1]; };
let rotate = 0;
for (let i = b0; i < b1; i++) { const a = (i - b0 + 0.5) * step; put(i, pt(cx, cy, RB, a)); if (i === view.open) rotate = -a; }
// categories at their sector mid-angles (blocks are contiguous per category in ordinal order)
const first = new Map(), last = new Map(); for (let i = b0; i < b1; i++) { const c = core.cat[i]; if (!first.has(c)) first.set(c, i - b0); last.set(c, i - b0); }
for (let c = core.range.cat[0]; c < core.range.cat[1]; c++) { const ci = c - core.range.cat[0]; if (!first.has(ci)) continue; put(c, pt(cx, cy, RC, ((first.get(ci) + last.get(ci)) / 2 + 0.5) * step)); }
const [g0, g1] = core.range.group, gs = TAU / (g1 - g0); for (let i = g0; i < g1; i++) put(i, pt(cx, cy, RG, (i - g0 + 0.5) * gs));
if (view.open >= 0) {
const fams = core.familiesOf(view.open), cap = Math.min(fams.length, view.params.innerCap || Infinity), fs = TAU / Math.max(cap, 1);
let k = 0; for (const f of fams) { if (k >= cap && f !== view.focus) continue; put(f, pt(cx, cy, RF, (k + 0.5) * fs)); k++; }
if (view.focus >= 0 && core.cls[view.focus] === 4 && out[2 * view.focus] !== out[2 * view.focus]) put(view.focus, pt(cx, cy, RF, 0.5 * fs));
}
return { bounds: [cx - RC, cy - RC, cx + RC, cy + RC], home: { pan: [0, 0], zoom: 1, rotate } };
},
edges(core, view) {
const a = [], b = [], kind = [], cls = [], w = [], has = i => i >= 0 && view.lit !== undefined;
const f = view.focus, o = view.open;
if (o >= 0) {
for (const t of core.edgesOf(o, 1, 'out')) { a.push(o); b.push(t); kind.push(1); cls.push(2); w.push(1); }
for (const s of core.edgesOf(o, 1, 'in')) { a.push(s); b.push(o); kind.push(3); cls.push(2); w.push(1); }
for (const t of core.familiesOf(o)) { a.push(o); b.push(t); kind.push(0); cls.push(1); w.push(1); }
}
if (f >= 0 && core.cls[f] === 4) {
for (const t of core.edgesOf(f, 2, 'out')) { a.push(f); b.push(t); kind.push(2); cls.push(2); w.push(1); }
for (const s of core.edgesOf(f, 2, 'in')) { a.push(s); b.push(f); kind.push(3); cls.push(2); w.push(1); }
for (const e of core.edgeIds(f, 4, 'both')) { const E = core.edges; a.push(E.a[e]); b.push(E.b[e]); kind.push(4); cls.push(2); w.push(E.w[e]); }
for (const e of core.edgeIds(f, 5, 'both')) { const E = core.edges; a.push(E.a[e]); b.push(E.b[e]); kind.push(5); cls.push(2); w.push(E.w[e]); }
}
// the recipe's own wiring
for (const r of view.recipe) if (core.cls[r] === 2) for (const t of core.edgesOf(r, 1, 'out')) if (view.recipe.includes(t)) { a.push(r); b.push(t); kind.push(1); cls.push(2); w.push(1); }
return { a: Uint32Array.from(a), b: Uint32Array.from(b), kind: Uint8Array.from(kind), cls: Uint8Array.from(cls), w: Float32Array.from(w) };
},
geometry(core, view) {
// the core disc r = 0.15·S as 24 quadratic arcs (muted), and the faint group band at 0.47·S
const { w, h } = view, S = Math.min(w, h), cx = w / 2, cy = h / 2, g = [];
for (const [r, wd] of [[0.15 * S, 1], [0.47 * S, 0.5]]) for (let k = 0; k < 24; k++) { const a0 = k / 24 * TAU, a1 = (k + 1) / 24 * TAU, am = (a0 + a1) / 2, rc = r / Math.cos((a1 - a0) / 2); const p0 = pt(cx, cy, r, a0), p1 = pt(cx, cy, r, a1), c = pt(cx, cy, rc, am); g.push(p0[0], p0[1], c[0], c[1], p1[0], p1[1], wd, core.GEOM.muted, 1); }
return Float32Array.from(g);
},
labels(core, view, max) {
const out = []; const cap = Math.min(max, view.params.labelCap || max);
for (let i = 0; i < core.N && out.length < cap; i++) if ((view.lit[i] & 15) && core.cls[i] !== 1) out.push(i);
if (view.open < 0) for (let c = core.range.cat[0]; c < core.range.cat[1] && out.length < cap; c++) out.push(c);
return Uint32Array.from(out);
},
};River
A JavaScript module in the lenses folder of GlobalGrid2050. It is built from the spread step (`spread`) and the touched step (`touched`).
transformglobalgrid2050 / testcode/202609142225/lenses/river.js · lines 1–60 of 60 · version 2026-09-14 22:25 · Not reached from any entry point (candidate for review) · pattern spread (shared by 2 files)
- What it does
- It calculates its inputs. Defines spread, S, touched.
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Downstream impact
- Used directly by 1 file: UI (globalgrid2050).
- What it achieves
- Lens river — from v07-flow-repos with the ribbon idea of v09-line-river (GRAMMAR §7 river).
- Why it matters
- Imported by UI.
- Application
- globalgrid2050 · testcode/202609142225/lenses · JavaScript module
- Uses
- none found
- Used by
- imported by UI (import)
- Produces
- spread, S, touched
- Defines here
- spread, S, touched
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609142225/lenses/river.js:1-60 · blob 4a6eb0b2869b39cb78d5ffd525e120388dacac0d · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: experimental · users: none · canonical: unreached_review
/* lens river — from v07-flow-repos with the ribbon idea of v09-line-river (GRAMMAR §7 river).
* Repositories → categories → blocks as bands (two stacked quadratics with horizontal / vertical tangents). */
let bands = null; // last layout's band table for hit()
function spread(out, list, fixed, lo, hi, vertical) { const n = list.length; list.forEach((i, k) => { const v = lo + (hi - lo) * (k + 0.5) / Math.max(n, 1); out[2 * i] = vertical ? fixed : v; out[2 * i + 1] = vertical ? v : fixed; }); }
export default {
id: 'river',
from: 'v07-flow-repos',
wants: ['repo', 'category', 'block', 'group', 'family'],
always: ['repo', 'category', 'block', 'group'],
draws: ['contains', 'depends on', 'shared line'],
curve: { mode: 'bow', bow: 0.15 },
hint(core, view) { return view.mobile ? 'Repositories flow down through categories into blocks; drag sideways along the block row.' : 'Repositories flow right through categories into blocks; drag up and down along the block column.'; },
simplify(width) { return width <= 600 ? { vertical: true, nameCap: 14 } : { vertical: false, nameCap: 40 }; },
camera(view) { return { pan: view.params.vertical ? 'x' : 'y', zoom: [0.5, 3], rotate: false }; },
layout(core, view, out) {
const { w, h } = view, V = !!view.params.vertical, R = core.range, repos = [], cats = [], blocks = [], groups = [];
for (let i = R.repo[0]; i < R.repo[1]; i++) repos.push(i); for (let i = R.cat[0]; i < R.cat[1]; i++) cats.push(i); for (let i = R.block[0]; i < R.block[1]; i++) blocks.push(i); for (let i = R.group[0]; i < R.group[1]; i++) groups.push(i);
const L = Math.max(V ? w : h, blocks.length * 14 + 40); // the flow axis is long: page-scrolled by the camera
if (!V) { spread(out, repos, 0.15 * w, 20, h - 20, true); spread(out, cats, 0.50 * w, 20, h - 20, true); spread(out, blocks, 0.71 * w, 20, L - 20, true); spread(out, groups, 0.90 * w, 20, L - 20, true); }
else { spread(out, repos, 0.12 * h, 10, w - 10, false); spread(out, cats, 0.50 * h, 10, w - 10, false); spread(out, blocks, 0.85 * h, 20, L - 20, false); spread(out, groups, 0.97 * h, 20, L - 20, false); }
if (view.open >= 0) { const fams = [...core.familiesOf(view.open)]; const bx = out[2 * view.open], by = out[2 * view.open + 1]; if (!V) spread(out, fams, 0.86 * w, by - 60, by + 60, true); else spread(out, fams, 0.95 * h, bx - 80, bx + 80, false); }
// recipe families of other blocks get a place beside their block too, so every recipe member can be named on the river
const perBlock = new Map(); for (const f of view.recipe) { if (core.cls[f] !== 4 || out[2 * f] === out[2 * f]) continue; const p = core.parent[f]; if (p < 0 || out[2 * p] !== out[2 * p]) continue; const k = perBlock.get(p) || 0; perBlock.set(p, k + 1); if (!V) { out[2 * f] = 0.86 * w; out[2 * f + 1] = out[2 * p + 1] + k * 12; } else { out[2 * f] = out[2 * p] + k * 12; out[2 * f + 1] = 0.95 * h … [line shortened here: 405 characters; full line on GitHub]
bands = { V, w, h, L };
// the camera follows the open block along the flow axis (the row is blocks·14+40 px long), so the key and its families are on screen
let pan = [0, 0]; if (view.open >= 0 && out[2 * view.open] === out[2 * view.open]) { const c = V ? out[2 * view.open] : out[2 * view.open + 1], span = V ? w : h; const off = Math.max(span - L, Math.min(0, span / 2 - c)); pan = V ? [off, 0] : [0, off]; }
return { bounds: V ? [0, 0, L, h] : [0, 0, w, L], home: { pan, zoom: 1, rotate: 0 }, follow: true };
},
edges(core, view) {
const a = [], b = [], kind = [], cls = [], w = [], o = view.open, f = view.focus;
if (o >= 0 && core.cls[o] === 2) { for (const t of core.edgesOf(o, 1, 'out')) { a.push(o); b.push(t); kind.push(1); cls.push(2); w.push(1); } for (const s of core.edgesOf(o, 1, 'in')) { a.push(s); b.push(o); kind.push(3); cls.push(2); w.push(1); } }
if (f >= 0 && core.cls[f] === 4) for (const e of core.edgeIds(f, 4, 'both')) { const E = core.edges; a.push(E.a[e]); b.push(E.b[e]); kind.push(4); cls.push(2); w.push(E.w[e]); }
return { a: Uint32Array.from(a), b: Uint32Array.from(b), kind: Uint8Array.from(kind), cls: Uint8Array.from(cls), w: Float32Array.from(w) };
},
/** bands need the positions the shell just laid out; the shell passes them back through view.pos (set by layout in the shell) */
geometry(core, view) {
if (!bands || !view.pos) return null; const P = view.pos, { V } = bands, g = [], R = core.range, lit = view.lit;
const S = (x0, y0, x1, y1, width, cat, cls) => { const mx = (x0 + x1) / 2, my = (y0 + y1) / 2; if (!V) g.push(x0, y0, mx, y0, mx, my, width, cat, cls, mx, my, mx, y1, x1, y1, width, cat, cls); else g.push(x0, y0, x0, my, mx, my, width, cat, cls, mx, my, x1, my, x1, y1, width, cat, cls); };
const touched = i => (lit[i] & 3) > 0;
for (let r = R.repo[0]; r < R.repo[1]; r++) { const perCat = new Map(); for (const bl of core.edgesOf(r, 0, 'out')) { const c = core.cat[bl]; if (c === 255) continue; perCat.set(c, (perCat.get(c) || 0) + 1); } for (const [c, n] of perCat) { const ci = R.cat[0] + c; S(P[2 * r], P[2 * r + 1], P[2 * ci], P[2 * ci + 1], Math.sqrt(n) * 2.2, c, touched(r) || touched(ci) ? 2 : 1); } }
for (let bl = R.block[0]; bl < R.block[1]; bl++) { const c = core.cat[bl]; if (c === 255) continue; const ci = R.cat[0] + c; if (view.cat >= 0 && view.cat !== c) continue; S(P[2 * ci], P[2 * ci + 1], P[2 * bl], P[2 * bl + 1], 1.4, c, touched(bl) ? 2 : 1); }
if (view.open >= 0) for (const fm of core.familiesOf(view.open)) S(P[2 * view.open], P[2 * view.open + 1], P[2 * fm], P[2 * fm + 1], 1, core.cat[fm] === 255 ? core.GEOM.muted : core.cat[fm], touched(fm) ? 2 : 1);
for (const fm of view.recipe) { const p = core.parent[fm]; if (core.cls[fm] !== 4 || p === view.open || p < 0 || P[2 * fm] !== P[2 * fm] || P[2 * p] !== P[2 * p]) continue; S(P[2 * p], P[2 * p + 1], P[2 * fm], P[2 * fm + 1], 1, core.cat[fm] === 255 ? core.GEOM.muted : core.cat[fm], 2); }
// the ribbon: a focus family's numbered lines as ticks in key order (green where shared, grey otherwise)
const f = view.focus; const pk = f >= 0 && core.famPack ? core.famPack[f] : null;
if (pk && P[2 * f] === P[2 * f]) { const keys = []; for (let i = pk.lineOffset; i < pk.lineOffset + pk.lineCount; i++) keys.push([core.lineKey[i], core.lineShared[i]]); keys.sort((p, q) => p[0] - q[0]); const n = Math.min(keys.length, 400), x = P[2 * f], y = P[2 * f + 1]; keys.slice(0, n).forEach(([k, sh], j) => { const t = (j + 0.5) / n; if (!V) { const yy = y + 14 + t * 0; const xx = x + 12 … [line shortened here: 635 characters; full line on GitHub]
return Float32Array.from(g);
},
labels(core, view, max) {
const out = []; const R = core.range;
for (const i of view.recipe) if (out.length < max && !out.includes(i)) out.push(i); // every recipe member is named on the river, not only the focus
for (let i = 0; i < core.N && out.length < max; i++) if ((view.lit[i] & 15) && core.cls[i] !== 3 && (core.cls[i] !== 4 || i === view.focus) && !out.includes(i)) out.push(i);
for (let c = R.cat[0]; c < R.cat[1] && out.length < max; c++) if (!out.includes(c)) out.push(c);
for (let r = R.repo[0]; r < R.repo[1] && out.length < max; r++) if (!out.includes(r)) out.push(r);
return Uint32Array.from(out);
},
leave() { bands = null; },
};Table
A JavaScript module in the lenses folder of GlobalGrid2050. It is built from the parent of helper (`parentOf`), the tile step (`tile`) and the swipeable step (`swipeable`).
renderglobalgrid2050 / testcode/202609142225/lenses/table.js · lines 1–82 of 82 · version 2026-09-14 22:25 · Not reached from any entry point (candidate for review)
- What it does
- It draws its content. Defines parentOf, tile, swipeable. Side effects: changes the web page (DOM).
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow.
- Downstream impact
- Used directly by 2 files: Column (globalgrid2050); UI (globalgrid2050).
- What it achieves
- Lens table — from `stars/table.html` + v04-periodic-arrows (GRAMMAR §7 table). It responds to pointerdown, pointermove and pointerup events.
- Why it matters
- Imported by Column and UI.
- Application
- globalgrid2050 · testcode/202609142225/lenses · JavaScript module
- Uses
- none found
- Used by
- imported by Column (import), imported by UI (import)
- Produces
- swipeable
- Defines here
- parentOf, tile, swipeable
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609142225/lenses/table.js:1-82 · blob e1791da35ee4bd37c229039c114eaf281872dfd8 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: experimental · users: none · canonical: unreached_review
/* lens table — from stars/table.html + v04-periodic-arrows (GRAMMAR §7 table). A DOM overlay of tiles; layout() reads the tile centres. */
let host = null, tiles = new Map(), shellRef = null, scrollKeep = 0, groupPage = 40, coreRef = null;
const parentOf = idx => (coreRef && idx >= 0 ? coreRef.parent[idx] : -1);
function tile(core, i, view, shell) {
const r = core.rec[i], isBlock = core.cls[i] === 2;
const t = document.createElement('div'); t.className = 'tile' + (i === view.focus || i === view.open ? ' focus' : '') + (view.recipe.includes(i) ? ' recipe' : '') + (view.recipeDerived && view.recipeDerived.includes(i) ? ' derived' : '') + ((view.lit[i] & 1) ? ' lit' : '') + (view.cat >= 0 && core.cat[i] !== view.cat && core.cat[i] !== 255 ? ' dim' : '');
if (view.recipeDerived && view.recipeDerived.includes(i)) t.title = 'will travel: a family of this block is in the recipe';
t.style.borderTopColor = core.colour(i);
const n = document.createElement('span'); n.textContent = isBlock ? String(r.number) : 'group'; t.append(n);
const s = document.createElement('b'); s.textContent = isBlock ? r.symbol : r; t.append(s);
const tt = document.createElement('span'); tt.className = 't'; tt.textContent = isBlock ? r.title : '(not yet named)'; t.append(tt);
const f = document.createElement('span'); f.textContent = isBlock ? (r.functions ? `${r.functions} functions` : 'data only') + (r.state === 'UNSETTLED' ? ' · not agreed' : '') : `${core.familiesOf(i).length} families`; t.append(f);
swipeable(t, i, shell, () => shell.navigate(i));
tiles.set(i, t); return t;
}
/** tap = navigate (or measure), long-press = measure, swipe-right ≥ 60 px = compose. touch-action: pan-y (style.css) keeps horizontal
* pointer moves with the tile, so the swipe completes on pointermove instead of ending in the browser's pointercancel. */
export function swipeable(node, i, shell, onTap) {
let x0 = 0, y0 = 0, t0 = 0, press = null, done = false;
node.addEventListener('pointerdown', e => { x0 = e.clientX; y0 = e.clientY; t0 = performance.now(); done = false; clearTimeout(press); press = setTimeout(() => { press = null; done = true; shell.measure(i); }, 450); });
node.addEventListener('pointermove', e => { if (done || !press) return; const dx = e.clientX - x0, dy = e.clientY - y0; if (Math.abs(dy) > 24) { clearTimeout(press); press = null; return; } if (dx > 60) { clearTimeout(press); press = null; done = true; shell.compose(i); } });
node.addEventListener('pointerup', e => { if (done || !press) return; clearTimeout(press); press = null; const dx = e.clientX - x0; if (dx > 60) shell.compose(i); else if (performance.now() - t0 < 350 && Math.abs(dx) <= 6 && Math.abs(e.clientY - y0) <= 6) onTap(); });
for (const ev of ['pointerleave', 'pointercancel']) node.addEventListener(ev, () => { clearTimeout(press); press = null; });
node.addEventListener('contextmenu', e => e.preventDefault());
}
export default {
id: 'table',
from: 'stars/table.html + v04-periodic-arrows',
wants: ['block', 'group', 'category', 'repo', 'family'],
always: ['block', 'group', 'category', 'repo'],
draws: ['depends on', 'used by'],
curve: { mode: 'bow', bow: 0.3 },
hint(core, view) { return 'Tiles in table order, one section per category; found-automatically blocks with fewer than 8 functions fold away.'; },
simplify(width) { return width <= 600 ? { perRow: 4 } : {}; },
camera() { return { pan: false, zoom: null, rotate: false }; },
overlay(core, view, h, shell) {
host = h; shellRef = shell; coreRef = core; scrollKeep = h.scrollTop; h.innerHTML = ''; h.style.pointerEvents = 'auto'; tiles.clear();
const R = core.range, strip = document.createElement('div'); strip.className = 'tb-repos';
for (let r = R.repo[0]; r < R.repo[1]; r++) { const c = document.createElement('button'); c.className = 'u-chip' + (view.focus === r ? ' on' : ''); c.textContent = core.rec[r]; c.style.borderColor = (view.lit[r] & 3) ? core.PAL.accent : ''; c.addEventListener('click', () => shell.navigate(r)); tiles.set(r, c); strip.append(c); }
if (view.mobile) { const d = document.createElement('details'); d.className = 'tb-cat'; const s = document.createElement('summary'); s.textContent = `repositories (${R.repo[1] - R.repo[0]})`; d.append(s, strip); d.open = view.focus >= R.repo[0] && view.focus < R.repo[1]; h.append(d); } // 31 chips are taller than the stage at 430: folded until wanted, so the tiles start at the top
else h.append(strip);
for (let c = R.cat[0]; c < R.cat[1]; c++) {
const sec = document.createElement('section'); sec.className = 'tb-cat'; const hd = document.createElement('h3'); hd.textContent = core.rec[c].title; hd.style.color = core.colour(c); hd.style.borderColor = core.colour(c); hd.style.cursor = 'pointer'; hd.addEventListener('click', () => shell.navigate(c)); tiles.set(c, hd); sec.append(hd);
const grid = document.createElement('div'); grid.className = 'tb-grid'; const fold = [];
for (let i = R.block[0]; i < R.block[1]; i++) { if (core.cat[i] !== c - R.cat[0]) continue; const b = core.rec[i]; if (b.kind === 'auto' && (b.functions || 0) < 8 && i !== view.open && !view.recipe.includes(i) && !(view.lit[i] & 15)) fold.push(i); else grid.append(tile(core, i, view, shell)); }
sec.append(grid);
if (fold.length) { const d = document.createElement('details'); const s = document.createElement('summary'); s.textContent = `found automatically (${fold.length})`; d.append(s); const g2 = document.createElement('div'); g2.className = 'tb-grid'; for (const i of fold) g2.append(tile(core, i, view, shell)); d.append(g2); sec.append(d); }
h.append(sec);
}
const gs = document.createElement('section'); gs.className = 'tb-cat'; const gh = document.createElement('h3'); gh.textContent = `groups off the table (${R.group[1] - R.group[0]})`; gh.style.color = core.PAL.muted; gh.style.borderColor = core.PAL.border; gs.append(gh);
const gg = document.createElement('div'); gg.className = 'tb-grid'; const want = Math.max(groupPage, view.open >= R.group[0] && view.open < R.group[1] ? view.open - R.group[0] + 1 : 0);
for (let i = R.group[0]; i < Math.min(R.group[1], R.group[0] + want); i++) gg.append(tile(core, i, view, shell));
gs.append(gg); if (R.group[0] + want < R.group[1]) { const more = document.createElement('button'); more.className = 'u-chip u-more'; more.textContent = `show 40 more (${R.group[1] - R.group[0] - want} left)`; more.addEventListener('click', () => { groupPage = want + 40; scrollKeep = h.scrollTop; shell.relayout(false); }); gs.append(more); } // paging: the lens redraws; focus, trail and hist … [line shortened here: 415 characters; full line on GitHub]
h.append(gs);
h.scrollTop = scrollKeep;
},
layout(core, view, out) {
if (!host) return { bounds: [0, 0, view.w, view.h], home: { pan: [0, 0], zoom: 1, rotate: 0 } };
const hr = host.getBoundingClientRect(), st = host.scrollTop; let maxY = 0;
for (const [i, t] of tiles) { const r = t.getBoundingClientRect(); const x = r.left - hr.left + r.width / 2, y = r.top - hr.top + st + r.height / 2; out[2 * i] = x; out[2 * i + 1] = y; if (y > maxY) maxY = y; }
if (view.open >= 0 && out[2 * view.open] === out[2 * view.open]) for (const f of core.familiesOf(view.open)) if (f === view.focus) { out[2 * f] = out[2 * view.open]; out[2 * f + 1] = out[2 * view.open + 1]; }
return { bounds: [0, 0, view.w, maxY], home: { pan: [0, -st], zoom: 1, rotate: 0 } };
},
edges(core, view) {
const a = [], b = [], kind = [], cls = [], w = [], o = view.open; let k = 0;
if (o >= 0 && core.cls[o] === 2) { for (const t of core.edgesOf(o, 1, 'out')) { if (k++ >= 30) break; a.push(o); b.push(t); kind.push(1); cls.push(2); w.push(1); } for (const s of core.edgesOf(o, 1, 'in')) { if (k++ >= 30) break; a.push(s); b.push(o); kind.push(3); cls.push(2); w.push(1); } }
for (const r of view.recipe) if (core.cls[r] === 2) for (const t of core.edgesOf(r, 1, 'out')) if (view.recipe.includes(t)) { a.push(r); b.push(t); kind.push(1); cls.push(2); w.push(1); }
return { a: Uint32Array.from(a), b: Uint32Array.from(b), kind: Uint8Array.from(kind), cls: Uint8Array.from(cls), w: Float32Array.from(w) };
},
labels() { return new Uint32Array(0); }, // the tiles carry their own text
/** scroll the overlay so the key's tile sits in the band a person can see (visibleH px from the stage top, above the phone sheet);
* a family resolves to its block or group tile, a category to its heading */
scrollTo(idx, visibleH) {
if (!host) return;
let t = tiles.get(idx); if (!t) { const p = parentOf(idx); t = p >= 0 ? tiles.get(p) : null; }
if (!t) return; const d = t.closest('details'); if (d) d.open = true;
const band = visibleH || host.clientHeight; host.scrollTop = Math.max(0, t.offsetTop - Math.max(0, band / 2 - t.offsetHeight / 2));
},
leave() { tiles.clear(); host = null; },
};