cornfield 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,8 +25,9 @@
25
25
  */
26
26
 
27
27
  import { ARROW, CORE_RATIO, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, parseColor } from './scene.js';
28
+ import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
28
29
  import {
29
- CURVE_SEGMENTS, EDGE_FRAG, GRID_FRAG, GRID_VERT, LANE_FRAG, LANE_VERT, NODE_FRAG, NODE_VERT, PACKET_FRAG, PACKET_VERT,
30
+ CURVE_SEGMENTS, EDGE_FRAG, GRID_FRAG, GRID_VERT, ICON_FRAG, ICON_VERT, LANE_FRAG, LANE_VERT, NODE_FRAG, NODE_VERT, PACKET_FRAG, PACKET_VERT,
30
31
  RING_FRAG, RING_VERT, TIP_FRAG, TIP_VERT, edgeVert,
31
32
  } from './shaders.js';
32
33
 
@@ -45,6 +46,8 @@ export const GRID_STRIDE = 8;
45
46
 
46
47
  /** Floats per edge: x1, y1, x2, y2 | control x, y, width, glow blur | rgba | glow rgb, glow strength | dash on, off | marked (0 or 1) */
47
48
  export const EDGE_STRIDE = 19;
49
+ /** Floats per icon: x, y, side, alpha */
50
+ export const ICON_STRIDE = 4;
48
51
  /** Floats per tip: x, y, direction x, y | rgba | kind (TIP_CODE) */
49
52
  export const TIP_STRIDE = 9;
50
53
  /** Floats per packet: x1, y1, x2, y2 | control x, y, speed, phase | rgba | glow rgb, glow strength | radius, glow blur */
@@ -173,13 +176,55 @@ export function packEdges(scene) {
173
176
  /** Everything the GPU needs from a scene */
174
177
  export const packScene = (scene) => ({ ...packDecor(scene), nodes: packNodes(scene), ...packEdges(scene) });
175
178
 
179
+ /**
180
+ * The outlines the theme gives nodes (--corn-map-stroke), as rows of the rings pass (the same shader, drawn over the nodes): a ring
181
+ * just inside the circle's edge, in the node's alpha. Empty for a scene whose nodes have none.
182
+ * @param {import('./scene.js').Scene} scene a scene through `styledScene`
183
+ */
184
+ export function packStrokes(scene) {
185
+ const rows = [];
186
+ scene.nodes.forEach((n) => {
187
+ if (!n.stroke) return;
188
+ const [r, g, b, a] = rgba(n.stroke.color);
189
+ rows.push([n.x, n.y, Math.max(0, n.r - n.stroke.width / 2), n.stroke.width, r, g, b, a * n.alpha, 0, 0]);
190
+ });
191
+ const data = new Float32Array(rows.length * RING_STRIDE);
192
+ rows.forEach((row, i) => data.set(row, i * RING_STRIDE));
193
+ return { data, count: rows.length, stride: RING_STRIDE };
194
+ }
195
+
196
+ /**
197
+ * The icons of the nodes that have one, grouped by kind (one texture, one draw each), in scene order within a kind.
198
+ * @param {import('./scene.js').Scene} scene a scene through `styledScene`
199
+ * @param {(kind: string) => boolean} has whether the kind's image has loaded
200
+ * @returns {{data: Float32Array, count: number, stride: number, groups: {kind: string, first: number, count: number}[]}}
201
+ */
202
+ export function packIcons(scene, has) {
203
+ const byKind = new Map();
204
+ scene.nodes.forEach((n) => {
205
+ if (!n.icon || !has(n.icon)) return;
206
+ if (!byKind.has(n.icon)) byKind.set(n.icon, []);
207
+ byKind.get(n.icon).push([n.x, n.y, n.r * ICON_RATIO, n.alpha]);
208
+ });
209
+ const groups = [];
210
+ const rows = [];
211
+ for (const [kind, list] of byKind) {
212
+ groups.push({ kind, first: rows.length, count: list.length });
213
+ rows.push(...list);
214
+ }
215
+ const data = new Float32Array(rows.length * ICON_STRIDE);
216
+ rows.forEach((row, i) => data.set(row, i * ICON_STRIDE));
217
+ return { data, count: rows.length, stride: ICON_STRIDE, groups };
218
+ }
219
+
176
220
  /**
177
221
  * The looks of scene.js (halo, mark, core) as flat float arrays for uniforms, indexed by the codes
178
222
  * above, so the shaders hold no colour of their own and cannot drift from the Canvas 2D renderer.
179
- * `theme` picks `looksFor(theme)`: the renderer sets them again when a scene's theme differs from the last.
223
+ * `theme` picks `looksFor(theme)`: the renderer sets them again when a scene's theme differs from the last. `style` (map-style.js)
224
+ * puts the theme's colours for the halos and the diff marks over them.
180
225
  */
181
- export function styleTables(theme = 'dark') {
182
- const { halo: HALO, mark: MARK, core: CORE_COLOR } = looksFor(theme);
226
+ export function styleTables(theme = 'dark', style = null) {
227
+ const { halo: HALO, mark: MARK, core: CORE_COLOR } = style ? looksWith(looksFor(theme), style) : looksFor(theme);
183
228
  const haloFill = new Float32Array(16);
184
229
  const haloRing = new Float32Array(16);
185
230
  const haloGeom = new Float32Array(16);
@@ -287,52 +332,69 @@ function link(gl, vertSource, fragSource, label) {
287
332
  }
288
333
 
289
334
  /** Sets the one-time uniforms of every pass that has them, for `theme`'s looks */
290
- function setConstants(gl, gpu, theme) {
291
- const tables = styleTables(theme);
335
+ /** What of a style the constants depend on: 0 for the plain one, else its version */
336
+ const styleKey = (style) => (!style || style.plain ? 0 : style.version);
337
+
338
+ function setConstants(gl, gpu, theme, style = null) {
339
+ const tables = styleTables(theme, style);
292
340
  gpu.passes.forEach((pass) => {
293
341
  if (!pass.spec.constants) return;
294
342
  gl.useProgram(pass.program);
295
343
  CONSTANTS[pass.spec.constants](gl, pass.at, tables);
296
344
  });
297
345
  gpu.theme = theme;
346
+ gpu.styleKey = styleKey(style);
347
+ }
348
+
349
+ /** One pass's program, vertex array and buffer (a unit quad per instance, unless the spec has `verts`) */
350
+ function makePass(gl, spec, corners) {
351
+ const program = link(gl, spec.vert, spec.frag, spec.name);
352
+ const vao = gl.createVertexArray();
353
+ const buffer = gl.createBuffer();
354
+ gl.bindVertexArray(vao);
355
+ if (!spec.verts) {
356
+ gl.bindBuffer(gl.ARRAY_BUFFER, corners);
357
+ gl.enableVertexAttribArray(0);
358
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
359
+ gl.vertexAttribDivisor(0, 0);
360
+ }
361
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
362
+ spec.attribs.forEach(([location, size, offset]) => {
363
+ gl.enableVertexAttribArray(location);
364
+ gl.vertexAttribPointer(location, size, gl.FLOAT, false, spec.stride * 4, offset * 4);
365
+ gl.vertexAttribDivisor(location, 1);
366
+ });
367
+ gl.bindVertexArray(null);
368
+
369
+ const at = (name) => gl.getUniformLocation(program, name);
370
+ return { spec, program, vao, buffer, at, count: 0, uniforms: { viewport: at('u_viewport'), cam: at('u_cam'), dpr: at('u_dpr'), time: spec.time ? at('u_time') : null } };
298
371
  }
299
372
 
373
+ /**
374
+ * The passes only a theme asks for, built the first time one is needed so a map with no theme costs nothing: the node outlines (the rings
375
+ * shader, drawn over the nodes) and the icons (a textured square per node), after the nodes, in this order.
376
+ */
377
+ export const EXTRA_PASSES = {
378
+ strokes: { name: 'strokes', vert: RING_VERT, frag: RING_FRAG, stride: RING_STRIDE, attribs: [[1, 4, 0], [2, 4, 4], [3, 2, 8]] },
379
+ icons: { name: 'icons', vert: ICON_VERT, frag: ICON_FRAG, stride: ICON_STRIDE, attribs: [[1, 4, 0]] },
380
+ };
381
+
300
382
  /** Programs, vertex arrays and buffers for every pass, on this context, with `theme`'s looks. Throws when a shader fails. */
301
- function buildGpu(gl, theme = 'dark') {
383
+ function buildGpu(gl, theme = 'dark', style = null) {
302
384
  const corners = gl.createBuffer();
303
385
  gl.bindBuffer(gl.ARRAY_BUFFER, corners);
304
386
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
305
387
 
306
- const passes = PASSES.map((spec) => {
307
- const program = link(gl, spec.vert, spec.frag, spec.name);
308
- const vao = gl.createVertexArray();
309
- const buffer = gl.createBuffer();
310
- gl.bindVertexArray(vao);
311
- if (!spec.verts) {
312
- gl.bindBuffer(gl.ARRAY_BUFFER, corners);
313
- gl.enableVertexAttribArray(0);
314
- gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
315
- gl.vertexAttribDivisor(0, 0);
316
- }
317
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
318
- spec.attribs.forEach(([location, size, offset]) => {
319
- gl.enableVertexAttribArray(location);
320
- gl.vertexAttribPointer(location, size, gl.FLOAT, false, spec.stride * 4, offset * 4);
321
- gl.vertexAttribDivisor(location, 1);
322
- });
323
- gl.bindVertexArray(null);
324
-
325
- const at = (name) => gl.getUniformLocation(program, name);
326
- return { spec, program, vao, buffer, at, count: 0, uniforms: { viewport: at('u_viewport'), cam: at('u_cam'), dpr: at('u_dpr'), time: spec.time ? at('u_time') : null } };
327
- });
328
- const gpu = { corners, passes, theme };
329
- setConstants(gl, gpu, theme);
388
+ const passes = PASSES.map((spec) => makePass(gl, spec, corners));
389
+ const gpu = { corners, passes, theme, styleKey: 0, extras: { strokes: null, icons: null }, textures: new Map(), iconStore: null };
390
+ setConstants(gl, gpu, theme, style);
330
391
  return gpu;
331
392
  }
332
393
 
333
394
  function destroyGpu(gl, gpu) {
334
395
  gl.deleteBuffer(gpu.corners);
335
- gpu.passes.forEach((p) => {
396
+ gpu.textures.forEach(({ texture }) => gl.deleteTexture(texture));
397
+ [...gpu.passes, ...Object.values(gpu.extras).filter(Boolean)].forEach((p) => {
336
398
  gl.deleteProgram(p.program);
337
399
  gl.deleteVertexArray(p.vao);
338
400
  gl.deleteBuffer(p.buffer);
@@ -345,7 +407,8 @@ function destroyGpu(gl, gpu) {
345
407
 
346
408
  /**
347
409
  * @param {HTMLCanvasElement} canvas the canvas to draw on (it must not have given a 2d context)
348
- * @param {{gl?: WebGL2RenderingContext}} [opts] `gl`: a context already taken from the canvas
410
+ * @param {{gl?: WebGL2RenderingContext, mapStyle?: () => import('./map-style.js').MapStyle}} [opts] `gl`: a context already taken from the canvas.
411
+ * `mapStyle`: where the theme's map tokens and icons come from (default: the page's, map-style.js `getMapStyle`)
349
412
  * @returns {import('./scene.js').Renderer & {stats: {uploads: number, draws: number}}}
350
413
  * @throws {Error} when there is no WebGL2 context or a shader fails to compile or link
351
414
  */
@@ -353,6 +416,7 @@ export function createWebglRenderer(canvas, opts = {}) {
353
416
  const gl = opts.gl || canvas.getContext('webgl2', CONTEXT_ATTRS);
354
417
  if (!gl) throw new Error('WebGL2 is not available');
355
418
 
419
+ const styleOf = opts.mapStyle || getMapStyle;
356
420
  const stats = { uploads: 0, draws: 0 };
357
421
  let gpu = buildGpu(gl);
358
422
  let lost = false;
@@ -363,6 +427,12 @@ export function createWebglRenderer(canvas, opts = {}) {
363
427
  let packedVersion;
364
428
  let lastArgs = null;
365
429
 
430
+ /** A pass only a theme asks for (EXTRA_PASSES), built the first time it is wanted */
431
+ function extra(name) {
432
+ if (!gpu.extras[name]) gpu.extras[name] = makePass(gl, EXTRA_PASSES[name], gpu.corners);
433
+ return gpu.extras[name];
434
+ }
435
+
366
436
  /** Copies the packed arrays into the GPU buffers (only when the scene changed, or after a restore) */
367
437
  function upload() {
368
438
  gpu.passes.forEach((pass) => {
@@ -372,20 +442,63 @@ export function createWebglRenderer(canvas, opts = {}) {
372
442
  gl.bindBuffer(gl.ARRAY_BUFFER, pass.buffer);
373
443
  gl.bufferData(gl.ARRAY_BUFFER, rows.data, gl.DYNAMIC_DRAW);
374
444
  });
445
+ for (const name of Object.keys(EXTRA_PASSES)) {
446
+ const rows = packed[name];
447
+ if (!rows.count && !gpu.extras[name]) continue;
448
+ const pass = extra(name);
449
+ pass.count = rows.count;
450
+ if (!rows.count) continue;
451
+ gl.bindBuffer(gl.ARRAY_BUFFER, pass.buffer);
452
+ gl.bufferData(gl.ARRAY_BUFFER, rows.data, gl.DYNAMIC_DRAW);
453
+ }
375
454
  stats.uploads++;
376
455
  }
377
456
 
378
- function draw(scene, camera, timeMs) {
379
- lastArgs = [scene, camera, timeMs];
457
+ /** Nearest-neighbour sampling when the theme is pixelated (theme.pixelated), else smooth with mipmaps */
458
+ function sample(texture, pixelated) {
459
+ gl.bindTexture(gl.TEXTURE_2D, texture);
460
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, pixelated ? gl.NEAREST : gl.LINEAR_MIPMAP_LINEAR);
461
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, pixelated ? gl.NEAREST : gl.LINEAR);
462
+ }
463
+
464
+ /** The texture of a kind's icon: made when the image is first drawn, sampled as the style says */
465
+ function textureOf(kind, image, pixelated) {
466
+ let entry = gpu.textures.get(kind);
467
+ if (!entry || entry.image !== image) {
468
+ if (entry) gl.deleteTexture(entry.texture);
469
+ const texture = gl.createTexture();
470
+ gl.bindTexture(gl.TEXTURE_2D, texture);
471
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true); // the context blends premultiplied
472
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
473
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
474
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
475
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
476
+ gl.generateMipmap(gl.TEXTURE_2D);
477
+ entry = { image, texture, pixelated: null };
478
+ gpu.textures.set(kind, entry);
479
+ }
480
+ if (entry.pixelated !== pixelated) { sample(entry.texture, pixelated); entry.pixelated = pixelated; }
481
+ return entry.texture;
482
+ }
483
+
484
+ function draw(drawn, camera, timeMs) {
485
+ lastArgs = [drawn, camera, timeMs];
380
486
  if (lost || !gpu || !width || !height) return;
487
+ const style = styleOf();
488
+ const scene = styledScene(drawn, style); // the map in the theme's colours, outlines and icons (map-style.js); the scene itself when nothing is set
489
+ if (gpu.iconStore !== style.icons) { // a new set of icons (or none): the old ones' textures go now, not when the renderer does
490
+ gpu.textures.forEach(({ texture }) => gl.deleteTexture(texture));
491
+ gpu.textures.clear();
492
+ gpu.iconStore = style.icons;
493
+ }
381
494
  if (scene !== packedScene || scene.version !== packedVersion) {
382
- packed = packScene(scene);
495
+ packed = { ...packScene(scene), strokes: packStrokes(scene), icons: packIcons(scene, (kind) => !!(style.icons && style.icons.get(kind))) };
383
496
  packedScene = scene;
384
497
  packedVersion = scene.version;
385
498
  upload();
386
499
  }
387
500
  const theme = scene.theme || 'dark';
388
- if (gpu.theme !== theme) setConstants(gl, gpu, theme); // the halos, mark rings and core of the other ground
501
+ if (gpu.theme !== theme || gpu.styleKey !== styleKey(style)) setConstants(gl, gpu, theme, style); // the halos, mark rings and core of the other ground, in the theme's colours
389
502
 
390
503
  gl.viewport(0, 0, canvas.width, canvas.height);
391
504
  gl.clearColor(0, 0, 0, 0);
@@ -403,6 +516,37 @@ export function createWebglRenderer(canvas, opts = {}) {
403
516
  gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, pass.spec.verts || 4, pass.count);
404
517
  stats.draws++;
405
518
  });
519
+
520
+ // Over the nodes, only when the theme gave some an outline or an icon
521
+ const strokes = gpu.extras.strokes;
522
+ if (strokes && strokes.count) {
523
+ gl.useProgram(strokes.program);
524
+ gl.uniform2f(strokes.uniforms.viewport, width, height);
525
+ gl.uniform3f(strokes.uniforms.cam, camera.x, camera.y, camera.zoom);
526
+ gl.uniform1f(strokes.uniforms.dpr, canvas.width / width);
527
+ gl.bindVertexArray(strokes.vao);
528
+ gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 4, strokes.count);
529
+ stats.draws++;
530
+ }
531
+ const icons = gpu.extras.icons;
532
+ if (icons && icons.count) {
533
+ gl.useProgram(icons.program);
534
+ gl.uniform2f(icons.uniforms.viewport, width, height);
535
+ gl.uniform3f(icons.uniforms.cam, camera.x, camera.y, camera.zoom);
536
+ gl.uniform1f(icons.uniforms.dpr, canvas.width / width);
537
+ gl.uniform1i(icons.at('u_tex'), 0);
538
+ gl.activeTexture(gl.TEXTURE0);
539
+ gl.bindVertexArray(icons.vao);
540
+ gl.bindBuffer(gl.ARRAY_BUFFER, icons.buffer);
541
+ for (const group of packed.icons.groups) {
542
+ const image = style.icons && style.icons.get(group.kind);
543
+ if (!image) continue;
544
+ gl.bindTexture(gl.TEXTURE_2D, textureOf(group.kind, image, !!style.pixelated));
545
+ gl.vertexAttribPointer(1, 4, gl.FLOAT, false, ICON_STRIDE * 4, group.first * ICON_STRIDE * 4); // this kind's rows
546
+ gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 4, group.count);
547
+ stats.draws++;
548
+ }
549
+ }
406
550
  gl.bindVertexArray(null);
407
551
  }
408
552
 
@@ -413,7 +557,7 @@ export function createWebglRenderer(canvas, opts = {}) {
413
557
  };
414
558
  const onRestored = () => {
415
559
  try {
416
- gpu = buildGpu(gl, lastArgs ? lastArgs[0].theme || 'dark' : 'dark');
560
+ gpu = buildGpu(gl, lastArgs ? lastArgs[0].theme || 'dark' : 'dark', styleOf());
417
561
  lost = false;
418
562
  if (packed) upload();
419
563
  if (lastArgs) draw(...lastArgs);
package/explorer/scene.js CHANGED
@@ -44,7 +44,8 @@
44
44
  *
45
45
  * @typedef {object} SceneNode One visible node, in draw order (later is on top)
46
46
  * @property {string} id topology id
47
- * @property {string} type topology type (`app`, `page`, `table`, ...)
47
+ * @property {string} type topology type (`app`, `page`, `table`, ...): the node's kind for the map tokens (map-style.js)
48
+ * @property {string} group the node's layer in the Layers menu (`app`, `cloud`, `web`, `house`, ...): the node's group for the map tokens
48
49
  * @property {number} x world centre
49
50
  * @property {number} y
50
51
  * @property {number} r world radius of the filled circle
@@ -135,7 +136,9 @@
135
136
  * @typedef {object} Scene
136
137
  * @property {SceneNode[]} nodes
137
138
  * @property {SceneEdge[]} edges
139
+ * @property {{nodes: Set<string>, edges: Set<string>}} painted the ids of the nodes and the keys of the edges a painter (an outage, a check's verdict, a pull request) gave a colour of its own: map-style.js leaves those alone
138
140
  * @property {SceneDecor} decor
141
+ * @property {{node: {color: string, width: number}, edge: {color: string, width: number}}} [labelOutline] the outline under the labels when the theme sets one (map-style.js, `--corn-map-label-halo`); else `looksFor(theme).labelOutline`
139
142
  * @property {boolean} preset the data-flow view: every node is labelled and the label boost differs (see `labelAt`)
140
143
  * @property {'dark'|'light'} theme the ground it is drawn for (`state.theme`, theme.js): every colour in it already suits it; `looksFor(theme)` has the rest
141
144
  * @property {number} version the `state.sceneVersion` it was built from
@@ -537,6 +540,9 @@ function buildEdges(state, subgraph, reduceMotion) {
537
540
  // ---------------------------------------------------------------------------
538
541
  // Nodes
539
542
  // ---------------------------------------------------------------------------
543
+ /** A node's group: its layer in the Layers menu (layers.js), one per kind but for the rooms and floors (House) and the outside nodes (Cloud, or the Public web) */
544
+ const groupOf = (node) => (node.type === 'floor' || node.type === 'room' ? 'house' : node.type === 'external' ? externalLayer(node) : node.type);
545
+
540
546
  function buildNodes(state, subgraph) {
541
547
  const { nodes, selectedNode, searchQuery } = state;
542
548
  const query = searchQuery.toLowerCase();
@@ -562,7 +568,7 @@ function buildNodes(state, subgraph) {
562
568
  const big = shown.type === 'root' || shown.type === 'app';
563
569
 
564
570
  out.push({
565
- id: node.id, type: shown.type,
571
+ id: node.id, type: shown.type, group: groupOf(shown),
566
572
  x: node.x, y: node.y, r: shown.r, color: shown.color,
567
573
  alpha,
568
574
  glow: connected && alpha >= 0.5 ? (big ? 15 : 9) : 0,
@@ -694,15 +700,20 @@ export function buildScene(state, opts = {}) {
694
700
  nodes: buildNodes(state, subgraph),
695
701
  edges: buildEdges(state, subgraph, !!opts.reduceMotion),
696
702
  decor: { grid: { size: 48, color: 'rgba(255, 255, 255, 0.035)', width: 0.5, margin: 200 }, rings, lanes },
703
+ painted: { nodes: new Set(), edges: new Set() },
697
704
  preset,
698
705
  theme: 'dark',
699
706
  version: state.sceneVersion || 0,
700
707
  };
701
708
  if (state.view === 'house') decorateHouseScene(scene, state); // its bands and tray as lanes, rooms unlabelled (house-model.js)
702
709
  if (state.scenario) emphasiseScenario(scene, state.scenario, opts);
710
+ const colours = { nodes: scene.nodes.map((n) => n.color), edges: scene.edges.map((e) => e.color) };
703
711
  if (state.scenario) paintOutage(scene, outageFor(state.scenario, state.nodes, state.edges)); // CLOUD-07: red, amber, violet by when the outage bites
704
712
  if (state.scenario) paintVerdict(scene, state.scenario); // PHY-10: red, green or amber by the step's permission check
705
713
  if (state.forgeLit) paintForge(scene, state.forgeLit); // CF-07: the selected pull request's nodes, the rest faded
714
+ // The nodes and edges a painter above gave a colour: the map's own styling (map-style.js) leaves them to it
715
+ scene.nodes.forEach((n, i) => { if (colours.nodes.length === scene.nodes.length && n.color !== colours.nodes[i]) scene.painted.nodes.add(n.id); });
716
+ scene.edges.forEach((e, i) => { if (colours.edges.length === scene.edges.length && e.color !== colours.edges[i]) scene.painted.edges.add(e.key); });
706
717
  if (state.theme === 'light') lightenScene(scene); // MAP-01: last, so what every painter above set is themed with the rest (theme-model.js)
707
718
  return scene;
708
719
  }
@@ -533,3 +533,30 @@ void main() {
533
533
  outColor = acc;
534
534
  }
535
535
  `;
536
+
537
+ // ---------------------------------------------------------------------------
538
+ // Icons: one textured square per node that has the theme's icon for its kind (theme.icons), drawn over the nodes
539
+ // ---------------------------------------------------------------------------
540
+ export const ICON_VERT = `${HEAD}${TO_CLIP}
541
+ layout(location = 0) in vec2 a_corner;
542
+ layout(location = 1) in vec4 a_geom; // x, y, side (world), alpha
543
+ out vec2 v_uv;
544
+ flat out float v_alpha;
545
+ void main() {
546
+ vec2 centre = u_cam.xy + a_geom.xy * u_cam.z;
547
+ vec2 pos = centre + a_corner * (a_geom.z * 0.5 * u_cam.z);
548
+ v_uv = vec2(a_corner.x * 0.5 + 0.5, 0.5 - a_corner.y * 0.5);
549
+ v_alpha = a_geom.w;
550
+ gl_Position = toClip(pos);
551
+ }
552
+ `;
553
+
554
+ export const ICON_FRAG = `${HEAD}
555
+ uniform sampler2D u_tex;
556
+ in vec2 v_uv;
557
+ flat in float v_alpha;
558
+ out vec4 outColor;
559
+ void main() {
560
+ outColor = texture(u_tex, v_uv) * v_alpha; // the texture is uploaded premultiplied
561
+ }
562
+ `;
package/explorer/theme.js CHANGED
@@ -10,13 +10,15 @@
10
10
  * - the theme in force is `<html data-theme="light|dark">`: explorer.css swaps its tokens on it,
11
11
  * theme-boot.js sets it before the first paint (so a light page never flashes dark), and this module
12
12
  * keeps it right afterwards;
13
- * - the map: `state.theme`, then `touchScene()`, so the next scene is built for the new ground (scene.js);
13
+ * - the map: `state.theme`, then `touchScene()`, so the next scene is built for the new ground (scene.js), and the map's
14
+ * `--corn-map-*` tokens are read again for it (map-style.js; it also watches `data-theme-name` and `prefers-color-scheme` itself);
14
15
  * - whatever else draws in colour from script listens with `onThemeChange` (the Layers menu's dots, the
15
16
  * legend's mark colours).
16
17
  */
17
18
 
18
19
  import { state, touchScene } from './state.js';
19
20
  import { render } from './render.js';
21
+ import { refreshMapStyle } from './map-style.js';
20
22
  import { THEME_STORAGE_KEY, nextChoice, resolveTheme, themeChoiceFrom, themeWords } from './theme-model.js';
21
23
 
22
24
  const QUERY = '(prefers-color-scheme: light)';
@@ -63,6 +65,7 @@ function apply() {
63
65
  const root = document.documentElement;
64
66
  root.dataset.theme = theme;
65
67
  syncButton(theme);
68
+ refreshMapStyle(); // the map's tokens (--corn-map-*) differ by theme: read them for this one (map-style.js)
66
69
  if (state.theme === theme) return;
67
70
  state.theme = theme;
68
71
  touchScene();
@@ -110,6 +110,77 @@
110
110
  --corn-glyph-mix: 100%;
111
111
 
112
112
  color-scheme: dark;
113
+
114
+ /* The map (docs/theming.md, "The map"). explorer/map-style.js reads these from the computed style on load and on every theme change.
115
+ `auto` keeps what the map draws with no theme: the node's own colour from the topology (deepened on the light ground), and every
116
+ other colour as scene.js has it. A colour replaces it, as written, in both themes: set it again under :root[data-theme="light"] in a theme file
117
+ for the light ground. A kind's fill wins over its group's. */
118
+ --corn-map-stroke: auto;
119
+ --corn-map-stroke-width: 1.5px;
120
+ --corn-map-label: auto;
121
+ --corn-map-label-halo: auto;
122
+ --corn-map-collision: var(--corn-warn);
123
+ /* Diff, selection and focus */
124
+ --corn-map-added: auto;
125
+ --corn-map-changed: auto;
126
+ --corn-map-removed: auto;
127
+ --corn-map-edit: auto;
128
+ --corn-map-selected: auto;
129
+ --corn-map-match: auto;
130
+ --corn-map-lit: auto;
131
+ /* Edges by kind */
132
+ --corn-map-edge-ownership: auto;
133
+ --corn-map-edge-usage: auto;
134
+ --corn-map-edge-flow: auto;
135
+ --corn-map-edge-reads: auto;
136
+ --corn-map-edge-writes: auto;
137
+ --corn-map-edge-calls: auto;
138
+ --corn-map-edge-triggers: auto;
139
+ --corn-map-edge-delivers: auto;
140
+ --corn-map-edge-runs-on: auto;
141
+ --corn-map-edge-uses: auto;
142
+ --corn-map-edge-extends: auto;
143
+ /* Node fill by kind */
144
+ --corn-map-node-root: auto;
145
+ --corn-map-node-app: auto;
146
+ --corn-map-node-page: auto;
147
+ --corn-map-node-pkg: auto;
148
+ --corn-map-node-core: auto;
149
+ --corn-map-node-token: auto;
150
+ --corn-map-node-atom: auto;
151
+ --corn-map-node-molecule: auto;
152
+ --corn-map-node-tool: auto;
153
+ --corn-map-node-store: auto;
154
+ --corn-map-node-table: auto;
155
+ --corn-map-node-rom: auto;
156
+ --corn-map-node-service: auto;
157
+ --corn-map-node-external: auto;
158
+ --corn-map-node-stack: auto;
159
+ --corn-map-node-machine: auto;
160
+ --corn-map-node-container: auto;
161
+ --corn-map-node-persona: auto;
162
+ --corn-map-node-device: auto;
163
+ --corn-map-node-floor: auto;
164
+ --corn-map-node-room: auto;
165
+ /* Node fill by group */
166
+ --corn-map-group-app: auto;
167
+ --corn-map-group-pkg: auto;
168
+ --corn-map-group-page: auto;
169
+ --corn-map-group-atom: auto;
170
+ --corn-map-group-molecule: auto;
171
+ --corn-map-group-token: auto;
172
+ --corn-map-group-tool: auto;
173
+ --corn-map-group-table: auto;
174
+ --corn-map-group-rom: auto;
175
+ --corn-map-group-service: auto;
176
+ --corn-map-group-cloud: auto;
177
+ --corn-map-group-web: auto;
178
+ --corn-map-group-stack: auto;
179
+ --corn-map-group-machine: auto;
180
+ --corn-map-group-container: auto;
181
+ --corn-map-group-device: auto;
182
+ --corn-map-group-house: auto;
183
+ --corn-map-group-persona: auto;
113
184
  }
114
185
 
115
186
  /* Light: the same names, for the light ground */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cornfield",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
5
5
  "license": "MIT",
6
6
  "author": "popcorn245 (https://github.com/popcorn245)",