cornfield 0.39.0 → 0.41.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.
@@ -15,6 +15,7 @@
15
15
  * --corn-map-collision the collision mark of two runs on one node (a DOM mark: explorer.css reads it)
16
16
  * --corn-map-font the font list of every label on the map (a list of families, `auto` for the map's own)
17
17
  * --corn-map-edge-width the width of an ordinary line, in map px (`auto` keeps each line's own; the focus's and the marks' keep their proportion)
18
+ * --corn-map-label-min the smallest a label is drawn on screen, in px (11 by default; below 9px it is ignored; a hub's title is 2 more)
18
19
  * --corn-map-glow the soft glow round nodes, lines and packets: a factor (`0` none, `1` as drawn, `auto` as drawn)
19
20
  *
20
21
  * `auto` (the default of every one of them but the width and the collision) means "keep what the map draws without a theme": the
@@ -34,7 +35,8 @@
34
35
 
35
36
  import { NODE_THEMES } from '../core/schema.js';
36
37
  import { parseColor } from './theme-model.js';
37
- import { looksFor } from './scene.js';
38
+ import { LABEL_MIN_FLOOR, looksFor } from './scene.js';
39
+ import { iconKeyShape, iconKeysFor, mapGroupToken, mapKindToken } from '../core/layers.js';
38
40
 
39
41
  /** The node kinds (topology types) and the groups (layers a node can belong to) the tokens exist for */
40
42
  export const MAP_KINDS = Object.freeze(Object.keys(NODE_THEMES));
@@ -52,6 +54,9 @@ export const COLLISION_TOKEN = '--corn-map-collision';
52
54
  export const FONT_TOKEN = '--corn-map-font';
53
55
  export const EDGE_WIDTH_TOKEN = '--corn-map-edge-width';
54
56
  export const GLOW_TOKEN = '--corn-map-glow';
57
+ export const LABEL_MIN_TOKEN = '--corn-map-label-min';
58
+ /** The largest label minimum a theme may ask for: bigger text would leave no room for another label */
59
+ export const MAX_LABEL_MIN = 24;
55
60
  /** The width an ordinary line has with no theme (scene.js `flowEdge`): the `--corn-map-edge-width` scales every line by its ratio to this */
56
61
  export const BASE_EDGE_WIDTH = 1.6;
57
62
  /** The most a font list may hold: the families, and the characters */
@@ -69,6 +74,8 @@ export const ICON_URL_PREFIX = '/cornfield/theme/assets/';
69
74
 
70
75
  export const nodeToken = (kind) => `--corn-map-node-${kind}`;
71
76
  export const groupToken = (group) => `--corn-map-group-${group}`;
77
+ /** The fill token of a finer kind: `--corn-map-kind-service-timer`, or null for a kind that cannot be a part of a name (core/layers.js) */
78
+ export const kindToken = (type, kind) => mapKindToken(type, kind);
72
79
  export const edgeToken = (kind) => `--corn-map-edge-${kind}`;
73
80
  export const stateToken = (name) => `--corn-map-${name}`;
74
81
 
@@ -84,7 +91,7 @@ export const MAP_COLOR_TOKENS = Object.freeze([
84
91
  ...MAP_STATES.map(stateToken),
85
92
  ]);
86
93
  /** Every map token */
87
- export const mapTokenNames = () => [...MAP_COLOR_TOKENS, STROKE_WIDTH_TOKEN, COLLISION_TOKEN, FONT_TOKEN, EDGE_WIDTH_TOKEN, GLOW_TOKEN];
94
+ export const mapTokenNames = () => [...MAP_COLOR_TOKENS, STROKE_WIDTH_TOKEN, COLLISION_TOKEN, FONT_TOKEN, EDGE_WIDTH_TOKEN, GLOW_TOKEN, LABEL_MIN_TOKEN];
88
95
 
89
96
  // ---------------------------------------------------------------------------
90
97
  // Reading a token
@@ -203,6 +210,12 @@ function pxOf(value, max) {
203
210
  return Number.isFinite(n) && n > 0 && n <= max ? n : null;
204
211
  }
205
212
 
213
+ /** The label minimum: a length in px from LABEL_MIN_FLOOR to MAX_LABEL_MIN, or null for `auto` and anything else (under the floor is ignored, so a theme cannot make labels unreadable) */
214
+ function labelMinOf(value) {
215
+ const n = pxOf(value, MAX_LABEL_MIN);
216
+ return n !== null && n >= LABEL_MIN_FLOOR ? n : null;
217
+ }
218
+
206
219
  /** The glow factor: a number (`0` for none, `1` as drawn, up to MAX_GLOW; `0px` reads as 0), or null for `auto` and anything else */
207
220
  function factorOf(value) {
208
221
  const m = /^\s*(\d*\.?\d+)(px)?\s*$/i.exec(String(value ?? ''));
@@ -215,12 +228,13 @@ function factorOf(value) {
215
228
  /**
216
229
  * The tokens as the page computes them.
217
230
  * @param {(name: string) => string} read the value of a custom property
218
- * @returns {{values: Record<string, string>, strokeWidth: number, font: string | null, edgeWidth: number | null, glow: number | null}}
219
- * `values` holds only the tokens that are a colour (not `auto`); `font`, `edgeWidth` and `glow` are null at `auto` or when the value is not one
231
+ * @param {string[]} [extra] more colour tokens to read: those of the finer kinds and project layers on the map (`setMapSubjects`)
232
+ * @returns {{values: Record<string, string>, strokeWidth: number, font: string | null, edgeWidth: number | null, glow: number | null, labelMin: number | null}}
233
+ * `values` holds only the tokens that are a colour (not `auto`); `font`, `edgeWidth`, `glow` and `labelMin` are null at `auto` or when the value is not one
220
234
  */
221
- export function readMapTokens(read) {
235
+ export function readMapTokens(read, extra = []) {
222
236
  const values = {};
223
- for (const name of MAP_COLOR_TOKENS) {
237
+ for (const name of [...MAP_COLOR_TOKENS, ...extra]) {
224
238
  const c = cssColor(read(name));
225
239
  if (c) values[name] = c;
226
240
  }
@@ -231,6 +245,7 @@ export function readMapTokens(read) {
231
245
  font: cssFontList(read(FONT_TOKEN)),
232
246
  edgeWidth: pxOf(read(EDGE_WIDTH_TOKEN), MAX_EDGE_WIDTH),
233
247
  glow: factorOf(read(GLOW_TOKEN)),
248
+ labelMin: labelMinOf(read(LABEL_MIN_TOKEN)),
234
249
  };
235
250
  }
236
251
 
@@ -266,7 +281,7 @@ export function createIconStore(urls, { load = loadImage, onChange = () => {}, w
266
281
  const entries = new Map();
267
282
  let ready = 0;
268
283
  for (const [kind, url] of Object.entries(urls || {})) {
269
- if (!MAP_KINDS.includes(kind) || typeof url !== 'string' || !url.startsWith(ICON_URL_PREFIX) || url.includes('..')) continue;
284
+ if (!iconKeyShape(kind) || typeof url !== 'string' || !url.startsWith(ICON_URL_PREFIX) || url.includes('..')) continue;
270
285
  const entry = { status: 'loading', image: null };
271
286
  entries.set(kind, entry);
272
287
  Promise.resolve().then(() => load(url)).then((image) => {
@@ -299,12 +314,13 @@ export function createIconStore(urls, { load = loadImage, onChange = () => {}, w
299
314
  * @property {string | null} font the label font list (`--corn-map-font`), null at `auto`
300
315
  * @property {number | null} edgeWidth an ordinary line's width in px (`--corn-map-edge-width`), null at `auto`
301
316
  * @property {number | null} glow the glow factor (`--corn-map-glow`), null at `auto`
317
+ * @property {number | null} labelMin the smallest label size in px (`--corn-map-label-min`), null at `auto` or under 9px
302
318
  * @property {ReturnType<typeof createIconStore> | null} icons
303
319
  * @property {boolean} pixelated sample icons without smoothing
304
320
  * @property {boolean} plain nothing to apply: no colour set, no icon loaded (the scene is drawn as it is)
305
321
  */
306
322
 
307
- const NO_TOKENS = { values: {}, strokeWidth: DEFAULT_STROKE_WIDTH, font: null, edgeWidth: null, glow: null };
323
+ const NO_TOKENS = { values: {}, strokeWidth: DEFAULT_STROKE_WIDTH, font: null, edgeWidth: null, glow: null, labelMin: null };
308
324
  let tokens = NO_TOKENS;
309
325
  let icons = null;
310
326
  let pixelated = false;
@@ -313,8 +329,8 @@ let current = compose();
313
329
  const listeners = new Set();
314
330
 
315
331
  function compose() {
316
- const plain = !Object.keys(tokens.values).length && !(icons && icons.anyReady()) && tokens.font === null && tokens.edgeWidth === null && tokens.glow === null;
317
- return Object.freeze({ version, values: tokens.values, strokeWidth: tokens.strokeWidth, font: tokens.font, edgeWidth: tokens.edgeWidth, glow: tokens.glow, icons, pixelated, plain });
332
+ const plain = !Object.keys(tokens.values).length && !(icons && icons.anyReady()) && tokens.font === null && tokens.edgeWidth === null && tokens.glow === null && tokens.labelMin === null;
333
+ return Object.freeze({ version, values: tokens.values, strokeWidth: tokens.strokeWidth, font: tokens.font, edgeWidth: tokens.edgeWidth, glow: tokens.glow, labelMin: tokens.labelMin, icons, pixelated, plain });
318
334
  }
319
335
 
320
336
  function changed() {
@@ -323,6 +339,22 @@ function changed() {
323
339
  listeners.forEach((fn) => fn(current));
324
340
  }
325
341
 
342
+ /** The tokens of the finer kinds and project layers on the map, read besides the fixed list (their names come from the map and the config, through core/layers.js, which refuses a name that is not a plain one) */
343
+ let subjectTokens = [];
344
+ const MAX_SUBJECT_TOKENS = 500;
345
+
346
+ /**
347
+ * Tells the style which finer kinds (`[type, kind]`) and project layers (keys) are on the map, so the tokens that colour them
348
+ * (`--corn-map-kind-<type>-<kind>`, `--corn-map-group-<key>`) are read. True when the set changed and a token differed.
349
+ * @param {{kinds?: [string, string][], layers?: string[]}} [subjects]
350
+ */
351
+ export function setMapSubjects({ kinds = [], layers = [] } = {}) {
352
+ const names = [...new Set([...kinds.map(([t, k]) => mapKindToken(t, k)), ...layers.map((l) => mapGroupToken(l))].filter(Boolean))].sort().slice(0, MAX_SUBJECT_TOKENS);
353
+ if (names.length === subjectTokens.length && names.every((n, i) => n === subjectTokens[i])) return false;
354
+ subjectTokens = names;
355
+ return refreshMapStyle();
356
+ }
357
+
326
358
  /** @returns {MapStyle} */
327
359
  export const getMapStyle = () => current;
328
360
 
@@ -338,8 +370,8 @@ export function onMapStyleChange(fn) {
338
370
  */
339
371
  export function refreshMapStyle(read = pageReader()) {
340
372
  if (!read) return false;
341
- const next = readMapTokens(read);
342
- const same = next.strokeWidth === tokens.strokeWidth && next.font === tokens.font && next.edgeWidth === tokens.edgeWidth && next.glow === tokens.glow
373
+ const next = readMapTokens(read, subjectTokens);
374
+ const same = next.strokeWidth === tokens.strokeWidth && next.font === tokens.font && next.edgeWidth === tokens.edgeWidth && next.glow === tokens.glow && next.labelMin === tokens.labelMin
343
375
  && Object.keys(next.values).length === Object.keys(tokens.values).length
344
376
  && Object.entries(next.values).every(([k, v]) => tokens.values[k] === v);
345
377
  if (same) return false;
@@ -379,6 +411,7 @@ export function resetMapStyle() {
379
411
  tokens = NO_TOKENS;
380
412
  icons = null;
381
413
  pixelated = false;
414
+ subjectTokens = [];
382
415
  changed();
383
416
  }
384
417
 
@@ -452,8 +485,9 @@ function compute(scene, style) {
452
485
  const stroke = values[STROKE_TOKEN];
453
486
  const painted = scene.painted || { nodes: new Set(), edges: new Set() };
454
487
  const nodes = scene.nodes.map((n) => {
455
- const fill = !painted.nodes.has(n.id) && firstOf(values, [nodeToken(n.type), groupToken(n.group || n.type)]);
456
- const icon = style.icons && style.icons.get(n.type) ? n.type : null;
488
+ // Which fill wins, most specific first (spec 0009 D6): the finer kind, the project layer, the type, the starting layer
489
+ const fill = !painted.nodes.has(n.id) && firstOf(values, [kindToken(n.type, n.kind), n.layer ? mapGroupToken(n.layer) : null, nodeToken(n.type), groupToken(n.group || n.type)].filter(Boolean));
490
+ const icon = style.icons ? iconKeysFor(n.type, n.kind, n.layer).find((k) => style.icons.get(k)) || null : null; // the same order: kind, layer, type
457
491
  const glows = style.glow != null && style.glow !== 1 && n.glow > 0;
458
492
  if (!fill && !label && !stroke && !icon && !glows) return n;
459
493
  const out = { ...n };
@@ -466,6 +500,7 @@ function compute(scene, style) {
466
500
  });
467
501
  const out = { ...scene, nodes, edges: scene.edges.map((e) => styleEdge(e, style, painted.edges)) };
468
502
  if (style.font) out.labelFont = style.font; // every label's font list (labels.js reads `scene.labelFont`)
503
+ if (style.labelMin != null) out.labelMin = style.labelMin; // the smallest label on screen (labels.js reads `scene.labelMin`)
469
504
  const halo = values[LABEL_HALO_TOKEN];
470
505
  if (halo) { // the outline under the labels, at the widths it has (labels.js reads `scene.labelOutline` before the ground's own)
471
506
  const { node, edge } = looksFor(scene.theme).labelOutline;
@@ -100,7 +100,8 @@ function dataSummary(node) {
100
100
  const row = (e, side) => `${nm(e[side])}${e.label && e.label !== 'imports' ? ` · ${escHtml(e.label)}` : ''}`;
101
101
  // The summary is the first sentence of the description above: shown again only when the description does not hold it
102
102
  const again = node.summary && !String(node.desc || '').includes(node.summary);
103
- return section('Kind:', [line(`${code(node.kind)}${again ? `<div class="hx-faint">${escHtml(node.summary)}</div>` : ''}`)])
103
+ // The kind is in the badge ("Service · timer", typeWords): it has no row of its own
104
+ return (again ? section('Summary:', [line(`<span class="hx-faint">${escHtml(node.summary)}</span>`)]) : '')
104
105
  + section('Started by:', [...(node.triggers || []).map((t) => line(escHtml(t))), ...edgesOf('triggers', 'to', node.id).map((e) => line(row(e, 'from')))])
105
106
  + section('Jobs:', (node.jobs || []).map((j) => line(`${code(j.name)} · cron ${code(j.cron)}`)))
106
107
  + section('Runs:', edgesOf('triggers', 'from', node.id).map((e) => line(row(e, 'to'))))
@@ -179,10 +180,11 @@ export function repaintThreads() {
179
180
  // The head: type · host, and what the open proposal does to the node
180
181
  // ---------------------------------------------------------------------------
181
182
 
182
- /** "Page", "Cloud", "Public web": the kind of node, in words */
183
+ /** "Page", "Cloud", "Public web", "Service · timer": the kind of node, in words, with its finer kind (spec 0009 D5) after a dot. A kind is text, shown as text */
183
184
  function typeWords(node) {
184
185
  if (node.type === 'external' && node.kind) return node.kind === 'web' ? 'Public web' : 'Cloud';
185
- return node.type.charAt(0).toUpperCase() + node.type.slice(1);
186
+ const type = node.type.charAt(0).toUpperCase() + node.type.slice(1);
187
+ return typeof node.kind === 'string' && node.kind ? `${type} · ${node.kind}` : type;
186
188
  }
187
189
 
188
190
  /** The host a node answers on, when it has one */
@@ -172,10 +172,28 @@ function paint() {
172
172
  getRenderer().draw(scene, state.camera, performance.now());
173
173
  // The labels repaint only when the camera, the scene or the size changed, never on a packet frame
174
174
  const labels = getLabelLayer();
175
- if (labels) labels.draw(scene, state.camera);
175
+ if (labels) labels.draw(scene, state.camera, { hover: state.hoverNodeId });
176
176
  paintHooks.forEach((fn) => fn(scene, state.camera));
177
177
  }
178
178
 
179
+ /** The node whose label is drawn under a screen point, or null (labels.js `hit`): a cluster's title frames the cluster */
180
+ export function labelNodeAt(x, y) {
181
+ const labels = getLabelLayer();
182
+ return labels ? labels.hit(x, y) : null;
183
+ }
184
+
185
+ /**
186
+ * The node the pointer is on (or null): a node with no label is named by a chip over the map while it is. Only the label layer
187
+ * draws again (the map has nothing new to show), so moving across the map costs one small redraw per node entered.
188
+ */
189
+ export function setHoverNode(id) {
190
+ const next = id || null;
191
+ if (state.hoverNodeId === next) return;
192
+ state.hoverNodeId = next;
193
+ const labels = getLabelLayer();
194
+ if (labels && state.canvas && state.width) labels.draw(getScene(), state.camera, { hover: next });
195
+ }
196
+
179
197
  /** Things drawn over the map by the page itself (the runs' marks, explorer/runs-map.js): called after each draw with the scene and the camera */
180
198
  const paintHooks = new Set();
181
199
  export function onPaint(fn) {
@@ -10,6 +10,7 @@
10
10
 
11
11
  import { CORE_RATIO, ARROW, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, packetPoint } from './scene.js';
12
12
  import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
13
+ import { LETTER_RATIO, letterImage, showsLetters } from './kind-letters.js';
13
14
 
14
15
  const TAU = Math.PI * 2;
15
16
  /** A glow thinner than this on screen (px) is not drawn: zoomed out it is a fraction of a pixel, and costs a stroke or fill per edge and node */
@@ -217,6 +218,14 @@ function drawNode(ctx, node, zoom, looks, style) {
217
218
  const side = node.r * ICON_RATIO;
218
219
  ctx.imageSmoothingEnabled = !style.pixelated;
219
220
  ctx.drawImage(image, node.x - side / 2, node.y - side / 2, side, side);
221
+ } else if (showsLetters(node, zoom)) {
222
+ // A finer kind's letters (spec 0009 D5), where a theme's icon would be: the shortest start of its name, once the node is wide enough
223
+ const letters = letterImage(node.letters);
224
+ if (letters) {
225
+ const side = node.r * LETTER_RATIO;
226
+ ctx.imageSmoothingEnabled = true;
227
+ ctx.drawImage(letters, node.x - side / 2, node.y - side / 2, side, side);
228
+ }
220
229
  }
221
230
  ctx.restore();
222
231
  }
@@ -26,6 +26,7 @@
26
26
 
27
27
  import { ARROW, CORE_RATIO, EDGE_STRIKE, MARK_MIN_PX, edgePoint, looksFor, parseColor } from './scene.js';
28
28
  import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
29
+ import { LETTER_MIN_PX, LETTER_RATIO, isLetterKey, letterImage, letterKey, lettersOfKey } from './kind-letters.js';
29
30
  import {
30
31
  CURVE_SEGMENTS, EDGE_FRAG, GRID_FRAG, GRID_VERT, ICON_FRAG, ICON_VERT, LANE_FRAG, LANE_VERT, NODE_FRAG, NODE_VERT, PACKET_FRAG, PACKET_VERT,
31
32
  RING_FRAG, RING_VERT, TIP_FRAG, TIP_VERT, edgeVert,
@@ -194,22 +195,29 @@ export function packStrokes(scene) {
194
195
  }
195
196
 
196
197
  /**
197
- * The icons of the nodes that have one, grouped by kind (one texture, one draw each), in scene order within a kind.
198
+ * The icons of the nodes that have one, grouped by kind (one texture, one draw each), in scene order within a kind. A node with no theme icon
199
+ * but a finer kind's letters (spec 0009 D5) goes in a group of its own letters (`letters:j`), drawn from the image in explorer/kind-letters.js;
200
+ * a group says its smallest node's radius (`minR`), for the zoom below which its letters are not drawn.
198
201
  * @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}[]}}
202
+ * @param {(kind: string) => boolean} has whether the kind's image has loaded (a letters key: whether its image could be made)
203
+ * @returns {{data: Float32Array, count: number, stride: number, groups: {kind: string, first: number, count: number, minR: number}[]}}
201
204
  */
202
205
  export function packIcons(scene, has) {
203
206
  const byKind = new Map();
204
207
  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
+ let kind = n.icon && has(n.icon) ? n.icon : null;
209
+ let side = n.r * ICON_RATIO;
210
+ if (!kind && !n.icon && n.letters && has(letterKey(n.letters))) { kind = letterKey(n.letters); side = n.r * LETTER_RATIO; }
211
+ if (!kind) return;
212
+ if (!byKind.has(kind)) byKind.set(kind, { rows: [], minR: Infinity });
213
+ const group = byKind.get(kind);
214
+ group.rows.push([n.x, n.y, side, n.alpha]);
215
+ group.minR = Math.min(group.minR, n.r);
208
216
  });
209
217
  const groups = [];
210
218
  const rows = [];
211
- for (const [kind, list] of byKind) {
212
- groups.push({ kind, first: rows.length, count: list.length });
219
+ for (const [kind, { rows: list, minR }] of byKind) {
220
+ groups.push({ kind, first: rows.length, count: list.length, minR });
213
221
  rows.push(...list);
214
222
  }
215
223
  const data = new Float32Array(rows.length * ICON_STRIDE);
@@ -492,7 +500,7 @@ export function createWebglRenderer(canvas, opts = {}) {
492
500
  gpu.iconStore = style.icons;
493
501
  }
494
502
  if (scene !== packedScene || scene.version !== packedVersion) {
495
- packed = { ...packScene(scene), strokes: packStrokes(scene), icons: packIcons(scene, (kind) => !!(style.icons && style.icons.get(kind))) };
503
+ packed = { ...packScene(scene), strokes: packStrokes(scene), icons: packIcons(scene, (kind) => (isLetterKey(kind) ? !!letterImage(lettersOfKey(kind)) : !!(style.icons && style.icons.get(kind)))) };
496
504
  packedScene = scene;
497
505
  packedVersion = scene.version;
498
506
  upload();
@@ -539,9 +547,11 @@ export function createWebglRenderer(canvas, opts = {}) {
539
547
  gl.bindVertexArray(icons.vao);
540
548
  gl.bindBuffer(gl.ARRAY_BUFFER, icons.buffer);
541
549
  for (const group of packed.icons.groups) {
542
- const image = style.icons && style.icons.get(group.kind);
550
+ const letters = isLetterKey(group.kind);
551
+ if (letters && group.minR * 2 * camera.zoom < LETTER_MIN_PX) continue; // too small on screen: the letters would be a smudge (kind-letters.js)
552
+ const image = letters ? letterImage(lettersOfKey(group.kind)) : style.icons && style.icons.get(group.kind);
543
553
  if (!image) continue;
544
- gl.bindTexture(gl.TEXTURE_2D, textureOf(group.kind, image, !!style.pixelated));
554
+ gl.bindTexture(gl.TEXTURE_2D, textureOf(group.kind, image, !!style.pixelated && !letters));
545
555
  gl.vertexAttribPointer(1, 4, gl.FLOAT, false, ICON_STRIDE * 4, group.first * ICON_STRIDE * 4); // this kind's rows
546
556
  gl.drawArraysInstanced(gl.TRIANGLE_STRIP, 0, 4, group.count);
547
557
  stats.draws++;
@@ -32,6 +32,7 @@ import { checksVersion, closeChecks, decorateSnapshot, openChecks, paintChecks }
32
32
  import { blastRadius, outageLayers, outageScenario } from './outage-model.js';
33
33
  import { toggleLayer, LAYER_DEFS } from './layers.js';
34
34
  import { externalLayer } from './cloud-model.js';
35
+ import { projectLayerKey, shownByProposal } from './layer-model.js';
35
36
  import { announce } from './keyboard.js';
36
37
  import { t } from './strings.js';
37
38
  import { currentStepSentence } from './scenario-list-model.js';
@@ -145,7 +146,9 @@ export function layersHiding(node) {
145
146
  if (!node || state.view === 'dataflow' || state.view === 'house') return [];
146
147
  const on = (key) => state.activeLayers[key] !== false;
147
148
  const t = node.type;
148
- if (t === 'root') return [];
149
+ if (t === 'root' || shownByProposal(state, node)) return []; // a proposal's own nodes are drawn whatever their layer says (spec 0009 D3)
150
+ const project = projectLayerKey(state, node); // a project layer that takes the node decides alone (spec 0009 D3), as scene.js layerShows has it
151
+ if (project) return on(project) ? [] : [project];
149
152
  if (t === 'core') return [...(on('core') ? [] : ['core']), ...(state.activeLayers.pkg || state.activeLayers.atom ? [] : ['pkg'])];
150
153
  if (t === 'store') return ['flow', 'store'].filter((k) => !on(k));
151
154
  if (t === 'rom') return ['rom', 'flow'].filter((k) => !on(k));
@@ -167,7 +170,7 @@ function showStepLayers(scenario) {
167
170
  for (const id of stepNodeIds(scenario)) for (const key of layersHiding(byId.get(id))) if (!keys.includes(key)) keys.push(key);
168
171
  if (!keys.length) return;
169
172
  for (const key of keys) { if (key === 'pkg') state.activeLayers.pkg = false; toggleLayer(key); }
170
- const names = keys.map((key) => (LAYER_DEFS.find((l) => l.key === key) || { label: key }).label);
173
+ const names = keys.map((key) => (LAYER_DEFS.find((l) => l.key === key) || (state.projectLayers || []).find((l) => l.key === key) || { label: key }).label);
171
174
  announce(`Turned on ${names.length > 1 ? `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}` : names[0]} to show this scenario's steps.`);
172
175
  }
173
176
 
package/explorer/scene.js CHANGED
@@ -17,9 +17,9 @@
17
17
  * What changes the scene (and so what must call `touchScene()` in state.js): the topology, the
18
18
  * layout, the layers, the selection, the search, the view, a playing scenario (the ROM simulation is one), a dragged node, a selected pull request.
19
19
  * What does NOT: the camera (pan, zoom, fit) and time (packets). So the scene is built once per
20
- * `state.sceneVersion` and drawn many times. The one camera-dependent decision, label level of
21
- * detail, is therefore not in the scene's nodes but in `labelAt(node, zoom, scene)`, which
22
- * every renderer or label layer calls with the current zoom.
20
+ * `state.sceneVersion` and drawn many times. The one camera-dependent decision, which labels fit
21
+ * and how big they are, is therefore not in the scene's nodes but in labels.js (`placeLabels(scene,
22
+ * zoom)`, which the label layer calls and caches by zoom).
23
23
  *
24
24
  * buildScene needs no text metrics (a label's size comes from rules, not from measuring it), so it
25
25
  * takes no `measure` function; the one place that measures text is layout.js `labelWidth`, which
@@ -55,14 +55,16 @@
55
55
  * @property {Halo} halo
56
56
  * @property {Mark} mark
57
57
  * @property {boolean} selected this is the selected node
58
- * @property {boolean} match the search query matches its label
58
+ * @property {boolean} match the search finds it (its label, id, file, type or kind: search-model.js)
59
+ * @property {boolean} current it is the search match the stepping is on (`state.searchCurrent`): its label is placed first of the matches
60
+ * @property {number} degree how many edges it has (the label placer's tie-break: more edges first)
59
61
  * @property {boolean} connected inside the focus subgraph (always true when nothing is focused)
60
- * @property {string} label the text, always set; whether it is drawn is `labelAt`'s decision
61
- * @property {number} labelSize px at zoom >= 0.6 (before the zoomed-out boost): 12 for `root`/`app`, else 11
62
+ * @property {string} label the text, always set; whether it is drawn is labels.js's decision (`placeLabels`)
63
+ * @property {number} labelSize px in world units: 12 for `root`/`app`, else 11. On screen a label is never under LABEL_MIN_PX (a hub's, 2 more)
62
64
  * @property {boolean} labelBold
63
65
  * @property {number} labelAlpha = alpha
64
66
  * @property {string} labelColor `#f8fafc`, or a dim white for a node outside the focus
65
- * @property {boolean} labelKeep keeps its label when zoomed out: a landmark type, the selection, a match, a marked node, or in the focus
67
+ * @property {boolean} labelKeep its label is asked for: a landmark type, the selection, a match, a marked node, or in the focus (and what a painter lights: an outage, a pull request)
66
68
  * @property {boolean} labelStrike the label is struck through (a node a proposal removes, in the Diff view)
67
69
  * @property {boolean} live the node came from the live layer (spec 0029: a floor, a room, a live device), not from topology.json
68
70
  * @property {{x:number, y:number, w:number, h:number}|null} box a live room's box in the 800 x 600 floor viewBox (for the House view), else null
@@ -139,7 +141,7 @@
139
141
  * @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
140
142
  * @property {SceneDecor} decor
141
143
  * @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`
142
- * @property {boolean} preset the data-flow view: every node is labelled and the label boost differs (see `labelAt`)
144
+ * @property {boolean} preset the data-flow view
143
145
  * @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
144
146
  * @property {number} version the `state.sceneVersion` it was built from
145
147
  *
@@ -163,9 +165,11 @@ import { beforeOf, markIn, showsEdge, showsNode, touchedIds } from './proposal-m
163
165
  import { decorateHouseScene, houseEdgeStyle, houseShowsNode, houseViewEdges } from './house-model.js';
164
166
  import { paintVerdict } from './check-model.js';
165
167
  import { externalLayer, whenDash } from './cloud-model.js';
168
+ import { lettersOf, projectLayerKey, shownByProposal } from './layer-model.js';
166
169
  import { outageFor, paintOutage } from './outage-model.js';
167
170
  import { paintForge } from './forge-panel-model.js';
168
171
  import { lightColor, lightenScene, parseColor } from './theme-model.js';
172
+ import { matchIds } from './search-model.js';
169
173
  import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, EDGE_MIN_ALPHA, MARK_SHAPES, REMOVED_ALPHA } from './diff-marks.js';
170
174
 
171
175
  // ---------------------------------------------------------------------------
@@ -174,8 +178,13 @@ import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, EDGE_MIN_ALPHA, MARK_SHAPES, REMOVE
174
178
  export const LANDMARK_TYPES = ['root', 'app', 'pkg', 'tool', 'store', 'rom', 'floor']; // a floor (spec 0029) names its cluster of rooms like an app names its pages
175
179
  export const FONT_NODE = '"Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif';
176
180
  export const FONT_EDGE = '"Segoe UI", -apple-system, sans-serif';
177
- /** Below this zoom (outside the data-flow view) only landmarks and the focus keep a label */
178
- export const LABEL_ZOOM = 0.6;
181
+ /**
182
+ * The smallest a label is ever drawn on screen (px), whatever the zoom (spec 0008 D2): a node's own, and a hub's (its cluster's title).
183
+ * A theme may raise the first with `--corn-map-label-min` (not below LABEL_MIN_FLOOR); a hub's is that plus 2.
184
+ */
185
+ export const LABEL_MIN_PX = 11;
186
+ export const LABEL_MIN_FLOOR = 9;
187
+ export const HUB_LABEL_EXTRA_PX = 2;
179
188
  /** The white dot in the middle of a node, as a fraction of its radius */
180
189
  export const CORE_RATIO = 0.32;
181
190
  export const CORE_COLOR = '#ffffff';
@@ -238,11 +247,18 @@ export const PROPOSAL_DIM_ALPHA = 0.28;
238
247
  // Visibility and focus (moved unchanged from render.js)
239
248
  // ---------------------------------------------------------------------------
240
249
  export function isNodeVisible(state, node) {
241
- const { activeLayers } = state;
242
250
  if (state.proposal && !showsNode(state.proposalView || 'diff', node)) return false; // Before hides what is added, After what is removed
243
251
  if (state.view === 'dataflow') return !!state.flow && state.flow.ids.has(node.id);
244
252
  if (state.view === 'house') return houseShowsNode(state, node); // the House view (spec 0029, PHY-11) draws its own set: house-model.js
245
253
  if (node.type === 'root') return true;
254
+ return layerShows(state, node) || shownByProposal(state, node); // a proposal's own nodes are drawn whatever their layer says (spec 0009 D3)
255
+ }
256
+
257
+ /** Whether the Layers menu has the node's layer on: a project layer that takes it decides alone, else its starting layer, with the rules each type has */
258
+ export function layerShows(state, node) {
259
+ const { activeLayers } = state;
260
+ const project = projectLayerKey(state, node);
261
+ if (project) return activeLayers[project] !== false;
246
262
  if (node.type === 'core') return (activeLayers.pkg || activeLayers.atom) && activeLayers.core !== false; // its own row in Layers, and Packages or Atoms
247
263
  if (node.type === 'store') return activeLayers.flow !== false && activeLayers.store !== false; // its own row, and Data Flow
248
264
  if (node.type === 'rom') return activeLayers.rom !== false && activeLayers.flow !== false;
@@ -361,27 +377,6 @@ export function packetPoint(edge, timeMs) {
361
377
  /** `#rgb`, `#rrggbb`, `rgb(...)` or `rgba(...)` → `[r, g, b, a]` (0..255, alpha 0..1); transparent for anything else (theme-model.js) */
362
378
  export { parseColor };
363
379
 
364
- // ---------------------------------------------------------------------------
365
- // Labels: the one decision that depends on the camera
366
- // ---------------------------------------------------------------------------
367
-
368
- /**
369
- * The label a node shows at `zoom`, or null. Zoomed out (below LABEL_ZOOM, outside the data-flow
370
- * view) only landmarks and the focus keep a label, drawn larger so it stays readable on screen;
371
- * the data-flow view is small enough to label everything, a little larger when zoomed out.
372
- * @param {SceneNode} node
373
- * @param {number} zoom
374
- * @param {{preset:boolean}} scene
375
- * @returns {{text:string, x:number, y:number, size:number, bold:boolean, color:string, alpha:number, strike:boolean}|null}
376
- */
377
- export function labelAt(node, zoom, scene) {
378
- const zoomedOut = !scene.preset && zoom < LABEL_ZOOM;
379
- if (zoomedOut && !node.labelKeep) return null;
380
- const boost = zoomedOut ? Math.min(2.2, 0.75 / zoom) : scene.preset ? Math.min(1.8, 0.8 / zoom) : 1;
381
- const size = Math.round(node.labelSize * Math.max(1, boost));
382
- return { text: node.label, x: node.x, y: node.y + node.r + size + 3, size, bold: node.labelBold, color: node.labelColor, alpha: node.labelAlpha, strike: node.labelStrike };
383
- }
384
-
385
380
  // ---------------------------------------------------------------------------
386
381
  // Edges
387
382
  // ---------------------------------------------------------------------------
@@ -542,11 +537,12 @@ function buildEdges(state, subgraph, reduceMotion) {
542
537
  // Nodes
543
538
  // ---------------------------------------------------------------------------
544
539
  /** 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) */
545
- const groupOf = (node) => (node.type === 'floor' || node.type === 'room' ? 'house' : node.type === 'external' ? externalLayer(node) : node.type);
540
+ export const groupOf = (node) => (node.type === 'floor' || node.type === 'room' ? 'house' : node.type === 'external' ? externalLayer(node) : node.type);
546
541
 
547
542
  function buildNodes(state, subgraph) {
548
543
  const { nodes, selectedNode, searchQuery } = state;
549
- const query = searchQuery.toLowerCase();
544
+ const found = searchQuery ? matchIds(nodes, searchQuery) : null; // what the search finds: label, id, file, type, kind (search-model.js)
545
+ const searching = !!found && nodes.some((n) => found.has(n.id) && isNodeVisible(state, n)); // with no match on the map nothing dims: it would only be a blank map
550
546
  const out = [];
551
547
  const view = proposalView(state);
552
548
  const focus = view === 'diff' ? touchedIds(nodes, viewEdgesOf(state)) : null;
@@ -555,7 +551,8 @@ function buildNodes(state, subgraph) {
555
551
  if (!isNodeVisible(state, node)) return;
556
552
 
557
553
  const shown = view === 'before' ? beforeOf(node) : node; // Before reads a changed node as it was
558
- const match = !!query && shown.label.toLowerCase().includes(query);
554
+ const match = !!found && found.has(node.id);
555
+ const current = match && state.searchCurrent === node.id;
559
556
  const selected = !!selectedNode && selectedNode.id === node.id;
560
557
  const connected = subgraph ? subgraph.connectedNodeIds.has(node.id) : true;
561
558
  const child = subgraph && subgraph.childIds ? subgraph.childIds.has(node.id) : false;
@@ -563,19 +560,28 @@ function buildNodes(state, subgraph) {
563
560
  const look = MARK[mark];
564
561
  const gone = mark === 'edit' && node.editOp === 'removed'; // a node a what-if edit removes: violet ring, faded, label struck through
565
562
  // deep dimming for what is not connected; a proposal's Diff view fades what it does not touch, less deeply, and a removed node is faded too
566
- let alpha = subgraph && !connected ? DIM_ALPHA : 1;
563
+ // A search's matches are what the reader asked for: a selection's focus does not dim them, so each keeps its label (spec 0008 D4)
564
+ let alpha = subgraph && !connected && !(searching && match) ? DIM_ALPHA : 1;
565
+ if (searching && !match && !selected && !(subgraph && connected)) alpha = DIM_ALPHA; // a search dims what it did not find, as a focus does
567
566
  if (focus && !focus.touched.has(node.id)) alpha = Math.min(alpha, PROPOSAL_DIM_ALPHA);
568
567
  if (look) alpha *= gone ? MARK.removed.alpha : look.alpha;
569
568
  const big = shown.type === 'root' || shown.type === 'app';
569
+ // A finer kind (spec 0009): its letters, drawn in the node's core by the renderers (kind-letters.js), and the project layer that takes the node
570
+ const letters = lettersOf(state, shown);
571
+ const layer = projectLayerKey(state, shown);
570
572
 
571
573
  out.push({
572
574
  id: node.id, type: shown.type, group: groupOf(shown),
575
+ ...(typeof shown.kind === 'string' && shown.kind ? { kind: shown.kind } : {}),
576
+ ...(letters ? { letters } : {}),
577
+ ...(layer ? { layer } : {}),
573
578
  x: node.x, y: node.y, r: shown.r, color: shown.color,
574
579
  alpha,
575
580
  glow: connected && alpha >= 0.5 ? (big ? 15 : 9) : 0,
576
581
  halo: match ? 'match' : selected ? 'selected' : child ? 'child' : 'none',
577
582
  mark,
578
- selected, match, connected,
583
+ selected, match, current, connected,
584
+ degree: node.degree || 0,
579
585
  label: shown.label,
580
586
  labelSize: big ? 12 : 11,
581
587
  labelBold: big,