cornfield 0.42.0 → 0.43.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.
@@ -62,6 +62,7 @@
62
62
  <p id="layers-preset-note" class="hx-note" data-corn="notice" hidden>The data-flow view shows its own tiers and ignores these toggles. Switch it off to use them.</p>
63
63
  <div id="layer-toggles-container" class="hx-toggles"></div>
64
64
  <div id="flow-legend" hidden></div>
65
+ <div id="edge-key" class="hx-menu-section" data-corn="legend-key"></div>
65
66
  <div id="cloud-legend" class="hx-menu-section" data-corn="menu-section" hidden></div>
66
67
 
67
68
  <!-- What the marks of agent runs mean, while there are runs on the map (runs-map.js) -->
@@ -77,22 +78,7 @@
77
78
  <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--added" data-corn="mark-dot" data-corn-state="added"></span><span>Added: dashed ring</span></div>
78
79
  <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--changed" data-corn="mark-dot" data-corn-state="changed"></span><span>Changed: solid ring</span></div>
79
80
  <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--removed" data-corn="mark-dot" data-corn-state="removed"></span><span>Removed: faded ring, label struck through</span></div>
80
- <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit" data-corn="mark-dot" data-corn-state="edit"></span><span>Your edit: dotted ring</span></div>
81
- </div>
82
-
83
- <div class="hx-menu-section" data-corn="menu-section">
84
- <div class="hx-menu-title" data-corn="menu-title">
85
- <span>Connections</span>
86
- <span class="hx-faint hx-mono">Click node to focus</span>
87
- </div>
88
- <div class="hx-legend-row hx-legend-row--split">
89
- <span class="hx-legend-label"><span data-corn="swatch" class="hx-swatch-line hx-swatch-solid"></span>Solid</span>
90
- <span class="hx-faint hx-mono">Parent-Child / Hub</span>
91
- </div>
92
- <div class="hx-legend-row hx-legend-row--split">
93
- <span class="hx-legend-label"><span data-corn="swatch" class="hx-swatch-line hx-swatch-dashed hx-swatch-indigo"></span>Dotted</span>
94
- <span class="hx-faint hx-mono">Usage &amp; Dependency</span>
95
- </div>
81
+ <div class="hx-legend-row"><span class="hx-mark-dot hx-mark-dot--edit" data-corn="mark-dot" data-corn-state="edit"></span><span>Your edit: dotted ring, long-dashed line</span></div>
96
82
  </div>
97
83
  </div><!-- .hx-menu-body: the rows scroll, the title with All and None stays (spec 0009 D8) -->
98
84
  </div>
@@ -200,7 +186,7 @@
200
186
  <div class="hx-stage" role="main" data-corn="stage">
201
187
  <!-- The map takes the keyboard when it has the focus (keyboard.js): its keys are below, read out with its name -->
202
188
  <canvas id="graph-canvas" tabindex="0" role="application" aria-roledescription="map" aria-label="Topology map" aria-describedby="map-keys-help" data-corn="map-canvas"></canvas>
203
- <p id="map-keys-help" class="hx-sr-only">Arrow keys pan, plus and minus zoom, 0 fits the map. N and P select the next and the previous node, Home and End the first and the last. Enter goes to the selected node's panel, Escape closes it. In Freeform, Alt and an arrow moves the selected node.</p>
189
+ <p id="map-keys-help" class="hx-sr-only">Arrow keys pan, plus and minus zoom, 0 fits the map. N and P select the next and the previous node, Home and End the first and the last. F frames the selected node and what it lights. Enter goes to the selected node's panel, Escape closes it. In Freeform, Alt and an arrow moves the selected node.</p>
204
190
  <!-- What the keyboard landed on, said by a screen reader (keyboard.js) -->
205
191
  <p id="map-announcer" class="hx-sr-only" role="status" aria-live="polite"></p>
206
192
  <!-- Every label, drawn on its own transparent canvas over the map (explorer/labels.js); the map canvas still gets the pointer -->
@@ -13,6 +13,7 @@
13
13
  * The keys (on the focused map; a playing scenario keeps Left, Right and Space for itself):
14
14
  * Arrow keys pan (Shift: further) + / - zoom in / out 0 fit the map
15
15
  * N / ] the next node, selected and centred P / [ the previous one Home / End the first / the last
16
+ * F frame the selected node and what it lights
16
17
  * Enter into the selected node's panel Escape close the panel
17
18
  * Alt+Arrow in Freeform, move the selected node (Shift: further)
18
19
  */
@@ -38,6 +39,7 @@ export const MAP_KEYS = [
38
39
  ['N or ]', 'select the next node'],
39
40
  ['P or [', 'select the previous node'],
40
41
  ['Home and End', 'select the first and the last node'],
42
+ ['F', 'frame the selected node and what it lights'],
41
43
  ['Enter', 'go to the selected node\'s panel'],
42
44
  ['Escape', 'close the panel'],
43
45
  ['Alt and an arrow', 'in Freeform, move the selected node'],
@@ -48,7 +50,7 @@ export const MAP_KEYS = [
48
50
  * @param {{shift?: boolean, alt?: boolean, ctrl?: boolean, meta?: boolean, scenario?: boolean, freeform?: boolean, selected?: boolean}} [opts]
49
51
  * `scenario`: a scenario is playing (its player owns Left, Right and Space); `freeform`: nodes can be moved; `selected`: a node is selected
50
52
  * @returns {null | {type: 'pan', dx: number, dy: number} | {type: 'zoom', factor: number} | {type: 'fit'} | {type: 'step', by: number}
51
- * | {type: 'first'} | {type: 'last'} | {type: 'open'} | {type: 'close'} | {type: 'move', dx: number, dy: number}}
53
+ * | {type: 'frame'} | {type: 'first'} | {type: 'last'} | {type: 'open'} | {type: 'close'} | {type: 'move', dx: number, dy: number}}
52
54
  */
53
55
  export function mapKeyAction(key, opts = {}) {
54
56
  const { shift = false, alt = false, ctrl = false, meta = false, scenario = false, freeform = false, selected = false } = opts;
@@ -68,6 +70,7 @@ export function mapKeyAction(key, opts = {}) {
68
70
  case '0': return { type: 'fit' };
69
71
  case 'n': case 'N': case ']': return { type: 'step', by: 1 };
70
72
  case 'p': case 'P': case '[': return { type: 'step', by: -1 };
73
+ case 'f': case 'F': return selected ? { type: 'frame' } : null;
71
74
  case 'Home': return { type: 'first' };
72
75
  case 'End': return { type: 'last' };
73
76
  case 'Enter': return selected ? { type: 'open' } : null;
@@ -25,6 +25,7 @@ import { saveFreeformPositions } from './layout.js';
25
25
  import { closeLegendMenu } from './layers.js';
26
26
  import * as K from './keyboard-model.js';
27
27
  import { searchActive, stepMatch } from './search.js';
28
+ import { frameSelection, litNodes } from './selection-view.js';
28
29
 
29
30
  const $ = (id) => document.getElementById(id);
30
31
  let wired = false;
@@ -63,11 +64,19 @@ export function centreOn(node) {
63
64
 
64
65
  function land(node, order) {
65
66
  if (!node) { announce('No nodes are shown. Turn a layer on in the Layers menu.'); return; }
66
- selectNode(node);
67
- centreOn(node);
67
+ selectNode(node, { frame: true }); // the keyboard's selection frames the node and what it lights (spec 0008 D6)
68
68
  announce(K.describeNode(node, order.length, order.indexOf(node)));
69
69
  }
70
70
 
71
+ /** "Frame them" and the `F` key: the camera goes to the selected node and what it lights, and a screen reader is told how many that is */
72
+ export function frameThem() {
73
+ if (!state.selectedNode) return;
74
+ const target = frameSelection();
75
+ if (!target) return;
76
+ const connected = Math.max(0, litNodes().length - 1);
77
+ announce(target.framed ? `Framed ${state.selectedNode.label} and ${connected} connected` : `${state.selectedNode.label} centred: ${connected} connected, too spread out to frame together`);
78
+ }
79
+
71
80
  /** Into the open panel: its title takes the focus, so a screen reader starts there and Tab goes on into it */
72
81
  function focusPanel() {
73
82
  const title = $('drawer-title');
@@ -123,6 +132,9 @@ function onMapKey(e) {
123
132
  land(action.type === 'first' ? order[0] : order[order.length - 1], order);
124
133
  break;
125
134
  }
135
+ case 'frame':
136
+ frameThem();
137
+ break;
126
138
  case 'open':
127
139
  focusPanel();
128
140
  break;
@@ -14,6 +14,7 @@
14
14
  */
15
15
 
16
16
  import { FONT_NODE } from './scene.js';
17
+ import { INK_DARK, INK_LIGHT, inkFor } from './glyphs.js';
17
18
 
18
19
  /** A node is at least this many px across (on screen) before its letters are drawn: smaller, they are a smudge */
19
20
  export const LETTER_MIN_PX = 14;
@@ -43,9 +44,10 @@ export const forgetLetterImages = () => images.clear();
43
44
  * @param {string} letters one or two characters
44
45
  * @returns {CanvasImageSource | null}
45
46
  */
46
- export function letterImage(letters) {
47
+ export function letterImage(letters, ink = null) {
47
48
  if (typeof letters !== 'string' || !letters) return null;
48
- if (images.has(letters)) return images.get(letters);
49
+ const cacheKey = `${typeof ink === 'string' ? ink : ''}|${letters}`;
50
+ if (images.has(cacheKey)) return images.get(cacheKey);
49
51
  if (images.size >= MAX_LETTER_IMAGES) return null;
50
52
  let image = null;
51
53
  try {
@@ -58,13 +60,15 @@ export function letterImage(letters) {
58
60
  ctx.textBaseline = 'middle';
59
61
  ctx.lineJoin = 'round';
60
62
  ctx.lineWidth = 10;
61
- ctx.strokeStyle = 'rgba(255, 255, 255, 0.92)';
63
+ // dark ink under a light outline by default; a theme's `--corn-map-glyph` is the ink, under the outline of the opposite tone
64
+ const fill = typeof ink === 'string' ? ink : INK_DARK;
65
+ ctx.strokeStyle = inkFor(fill) === INK_LIGHT ? 'rgba(11, 18, 32, 0.92)' : 'rgba(255, 255, 255, 0.92)';
62
66
  ctx.strokeText(letters, SIDE / 2, SIDE / 2 + 3);
63
- ctx.fillStyle = '#0b1220';
67
+ ctx.fillStyle = fill;
64
68
  ctx.fillText(letters, SIDE / 2, SIDE / 2 + 3);
65
69
  image = canvas;
66
70
  }
67
71
  } catch { image = null; }
68
- images.set(letters, image);
72
+ images.set(cacheKey, image);
69
73
  return image;
70
74
  }
@@ -18,7 +18,7 @@
18
18
  * A label is never drawn under 11 px (a hub's, 13 px, bold; a theme may raise the 11 with `--corn-map-label-min`): text that
19
19
  * would be smaller is not drawn smaller, it competes for room at 11 px. Zoomed in, it grows with the map.
20
20
  * A node left without a label is named by a chip over everything else while the pointer is on it (`hover`).
21
- * Lane titles, notes and arrows and the selection's edge labels are always included and take no part in the placing.
21
+ * Lane titles, notes and arrows are always included and take no part in the placing. The kind words on a selection's lit edges (spec 0008 D7) are placed last, after every node label: a word is drawn only where it touches no node label, no lit node's disc and no word before it.
22
22
  * The layer redraws only when the camera, the scene, the size or the hover changed, so a packet frame (the renderer
23
23
  * redrawing for animation) costs the labels nothing.
24
24
  *
@@ -26,7 +26,7 @@
26
26
  * never the explorer's state.
27
27
  *
28
28
  * @typedef {object} LabelItem One piece of text to draw
29
- * @property {'node'|'edge'|'lane'|'chip'} kind
29
+ * @property {'node'|'edge'|'lane'|'chip'} kind `edge`: a kind word on a lit edge, in screen space
30
30
  * @property {string} [id] the node, for `kind: 'node'` and `'chip'`
31
31
  * @property {string} text
32
32
  * @property {number} x world coordinates; the text is drawn on this baseline point
@@ -44,11 +44,13 @@
44
44
  * @property {boolean} [screen] a node's label at its minimum size: drawn in screen space at `px`, so the font stays one string while the zoom changes (a changing font string is the slow part of drawing text)
45
45
  */
46
46
 
47
- import { EDGE_LABEL_SIZE, FONT_EDGE, FONT_NODE, HUB_LABEL_EXTRA_PX, LABEL_MIN_FLOOR, LABEL_MIN_PX, LANDMARK_TYPES, looksFor } from './scene.js';
47
+ import { FONT_EDGE, FONT_NODE, HUB_LABEL_EXTRA_PX, LABEL_MIN_FLOOR, LABEL_MIN_PX, LANDMARK_TYPES, looksFor } from './scene.js';
48
48
  import { getMapStyle, styledScene } from './map-style.js';
49
49
 
50
50
  /** At most this many node labels in view at a time (lane text and selection edge labels are extra); the placing itself never needs it */
51
51
  export const MAX_LABELS = 400;
52
+ /** At most this many kind words on the lit edges in view (spec 0008 D7) */
53
+ export const MAX_EDGE_WORDS = 120;
52
54
  /** A label this many screen px past the viewport is still kept, so none pops in at the border */
53
55
  export const CULL_MARGIN = 32;
54
56
  /** A label whose box, this many px bigger on every side, touches a placed one is skipped: placed labels are at least this far apart */
@@ -162,7 +164,7 @@ export function placeLabels(scene, zoom, opts = {}) {
162
164
  * `max` node labels in view (default 400); `margin` px past the viewport (default 32); `measure` the width of a text at a font
163
165
  * size (default: an estimate from its length); `hover`: the node the pointer is on, named by a chip when it has no label;
164
166
  * `placed`: the placing for this scene at this zoom, when the caller has kept it (default: made here)
165
- * @returns {LabelItem[]} lane text, then edge labels, then node labels in scene order, then the chip
167
+ * @returns {LabelItem[]} lane text, then node labels in scene order, then the words on the lit edges, then the chip
166
168
  */
167
169
  export function chooseLabels(scene, camera, viewport, opts = {}) {
168
170
  const { max = MAX_LABELS, margin = CULL_MARGIN, measure = null, hover = null } = opts;
@@ -175,12 +177,6 @@ export function chooseLabels(scene, camera, viewport, opts = {}) {
175
177
  if (t) out.push({ kind: 'lane', text: t.text, x: t.x, y: t.y, size: t.size, bold: t.bold, italic: false, color: t.color, alpha: 1, outline: null, align: 'center', family: scene.labelFont || FONT_NODE });
176
178
  }
177
179
  }
178
- // ... and the labels on the selection's edges
179
- for (const edge of scene.edges) {
180
- const l = edge.label;
181
- if (l) out.push({ kind: 'edge', text: l.text, x: l.x, y: l.y, size: EDGE_LABEL_SIZE, bold: false, italic: !!l.italic, color: l.color, alpha: edge.alpha, outline: outline.edge, align: 'center', family: scene.labelFont || FONT_EDGE });
182
- }
183
-
184
180
  // Node labels: the placing for this zoom, then the boxes that reach the viewport
185
181
  const { zoom } = camera;
186
182
  const placed = opts.placed || placeLabels(scene, zoom, { measure });
@@ -196,6 +192,30 @@ export function chooseLabels(scene, camera, viewport, opts = {}) {
196
192
  out.push({ kind: 'node', id: p.id, text: p.node.label, x: p.x, y: p.y, size: p.size, bold: p.bold, italic: false, color: p.node.labelColor, alpha: p.node.labelAlpha, outline: outline.node ? { color: outline.node.color, width: outline.node.width * k } : null, align: 'center', family, strike: !!p.node.labelStrike, px: p.px, screen: p.screen });
197
193
  }
198
194
 
195
+ // The words on the lit edges ("reads", "calls": spec 0008 D7) go last, below every node label: one is placed only where it touches no node label, no lit
196
+ // node's disc and no word placed before it, so it never covers a name; at the label minimum size, in screen space
197
+ const px = labelMinOf(scene);
198
+ const taken = inView.map((p) => ({ l: camera.x + p.l, r: camera.x + p.r, t: camera.y + p.t, b: camera.y + p.b }));
199
+ for (const n of scene.nodes) {
200
+ if (n.alpha < 0.5) continue;
201
+ const cx = camera.x + n.x * zoom, cy = camera.y + n.y * zoom, rr = n.r * zoom;
202
+ if (cx + rr < 0 || cx - rr > viewport.width || cy + rr < 0 || cy - rr > viewport.height) continue;
203
+ taken.push({ l: cx - rr, r: cx + rr, t: cy - rr, b: cy + rr });
204
+ }
205
+ let words = 0;
206
+ for (const edge of scene.edges) {
207
+ const l = edge.label;
208
+ if (!l || words >= MAX_EDGE_WORDS) continue;
209
+ const sx = camera.x + l.x * zoom, sy = camera.y + l.y * zoom;
210
+ if (sx < 0 || sx > viewport.width || sy < 0 || sy > viewport.height) continue;
211
+ const w = (measure ? measure(l.text, px, false) : l.text.length * px * 0.55) / 2 + LABEL_PAD;
212
+ const box = { l: sx - w, r: sx + w, t: sy - px * 0.6 - LABEL_PAD, b: sy + px * 0.6 + LABEL_PAD };
213
+ if (taken.some((o) => box.l < o.r && box.r > o.l && box.t < o.b && box.b > o.t)) continue;
214
+ taken.push(box);
215
+ words++;
216
+ out.push({ kind: 'edge', text: l.text, x: l.x, y: l.y + (px * 0.35) / zoom, size: px / zoom, px, screen: true, bold: false, italic: !!l.italic, color: l.color, alpha: edge.alpha, outline: outline.edge, align: 'center', family: scene.labelFont || FONT_EDGE });
217
+ }
218
+
199
219
  // The chip: a node with no label, named while the pointer is on it
200
220
  if (hover) {
201
221
  const node = scene.nodes.find((n) => n.id === hover);
@@ -271,26 +291,6 @@ function drawItem(ctx, t, pen, v = WORLD) {
271
291
  }
272
292
  }
273
293
 
274
- /**
275
- * Erases every node circle from what is drawn so far. The map used to draw an edge's label before
276
- * the circles, so a node covered it; this layer is above the circles, so it cuts them out of the
277
- * lane and edge text instead (a dimmed node, which hides almost nothing, does not cut).
278
- */
279
- function coverWithNodes(ctx, nodes) {
280
- ctx.save();
281
- ctx.globalCompositeOperation = 'destination-out';
282
- ctx.globalAlpha = 1;
283
- ctx.fillStyle = '#000';
284
- ctx.beginPath();
285
- nodes.forEach((n) => {
286
- if (n.alpha < 0.5) return;
287
- ctx.moveTo(n.x + n.r, n.y);
288
- ctx.arc(n.x, n.y, n.r, 0, Math.PI * 2);
289
- });
290
- ctx.fill();
291
- ctx.restore();
292
- }
293
-
294
294
  /**
295
295
  * The placed label under a screen point, or null: the one drawn on top (the last in scene order) when two overlap their padding
296
296
  * @param {ReturnType<typeof placeLabels>} placed
@@ -375,11 +375,9 @@ export function createLabelLayer(canvas, opts = {}) {
375
375
  // The placing is for the whole map at this zoom: kept while the scene, the zoom and the style stay (a pan, a hover), made again when one changes
376
376
  if (!samePlacing) kept = placeLabels(scene, camera.zoom, { measure });
377
377
  const items = chooseLabels(scene, camera, { width, height }, { measure, hover, placed: kept });
378
- // The lane text and the selection's edge labels, then the circles cut out of them (only when there are edge labels), then the node labels
378
+ // The lane text (the words on the lit edges are placed below the node labels, and drawn with them in screen space, below)
379
379
  let pen = newPen();
380
- let edges = false;
381
- for (const t of items) { if (t.kind === 'lane' || t.kind === 'edge') { drawItem(ctx, t, pen); if (t.kind === 'edge') edges = true; } }
382
- if (edges) { coverWithNodes(ctx, scene.nodes); pen = newPen(); }
380
+ for (const t of items) if (t.kind === 'lane') drawItem(ctx, t, pen);
383
381
  for (const t of items) if (t.kind === 'node' && !t.screen) drawItem(ctx, t, pen); // a label that grows with the map: the camera's transform
384
382
  ctx.restore();
385
383
  // A label at its minimum size is drawn in screen space at a whole font size, whatever the zoom: the font string does not change as the
@@ -387,6 +385,7 @@ export function createLabelLayer(canvas, opts = {}) {
387
385
  const screen = { ox: camera.x, oy: camera.y, k: camera.zoom };
388
386
  pen = newPen();
389
387
  for (const t of items) if (t.kind === 'node' && t.screen) drawItem(ctx, t, pen, screen);
388
+ for (const t of items) if (t.kind === 'edge') drawItem(ctx, t, pen, screen); // the kind words: where no node label, disc or word is
390
389
  for (const t of items) if (t.kind === 'chip') drawItem(ctx, t, pen, screen);
391
390
  return true;
392
391
  },
@@ -10,19 +10,23 @@ import { state, touchScene, escHtml } from './state.js';
10
10
  import { render, ensureFlowLoop, isNodeVisible } from './render.js';
11
11
  import { renderFlowLegend } from './flows.js';
12
12
  import { WHEN_STYLES } from './cloud-model.js';
13
+ import { edgeKeyHtml, keySwatch } from './edge-key.js';
13
14
  import { themed } from './theme-model.js';
14
15
  import { onThemeChange } from './theme.js';
16
+ import { NODE_THEMES } from '../core/schema.js';
15
17
  import { STARTING_LAYERS, clientLayers, kindLetters, orderRows, startingLayerOf } from '../core/layers.js';
16
18
  import { rowKeyOf, shownByProposal } from './layer-model.js';
17
19
  import { layerShows } from './scene.js';
18
20
  import { getMapStyle, groupToken, setMapSubjects } from './map-style.js';
19
21
  import { t } from './strings.js';
20
22
 
21
- /** The dot of each starting row: the colour its nodes are drawn in (a project layer's dot is its nodes' own, or the theme's group token) */
23
+ /**
24
+ * The dot of each starting row: the colour its nodes are drawn in, read from the node types' own colours (core/schema.js), so the dots and
25
+ * the map cannot drift apart when the palette moves (a project layer's dot is its nodes' own, or the theme's group token)
26
+ */
22
27
  const COLORS = {
23
- app: '#6366f1', pkg: '#06b6d4', page: '#38bdf8', atom: '#10b981', molecule: '#a855f7', token: '#ec4899', tool: '#f43f5e', flow: '#fb923c',
24
- core: '#14b8a6', store: '#fb923c', table: '#fde047', rom: '#f0abfc', service: '#84cc16', cloud: '#94a3b8', web: '#94a3b8', stack: '#a8a29e',
25
- machine: '#78716c', container: '#d6d3d1', device: '#2dd4bf', house: '#a3e635', runs: '#5eead4', persona: '#fb7185',
28
+ ...Object.fromEntries(Object.entries(NODE_THEMES).map(([type, { color }]) => [type, color])),
29
+ flow: NODE_THEMES.store.color, cloud: NODE_THEMES.external.color, web: NODE_THEMES.external.color, house: NODE_THEMES.floor.color, runs: '#5eead4',
26
30
  };
27
31
  /** The starting layers that start off: the infra layer is its own view, and the physical world's are loaded when first turned on (spec 0029) */
28
32
  const STARTS_OFF = new Set(['stack', 'machine', 'container', 'device', 'house', 'persona']);
@@ -272,9 +276,16 @@ export function renderLayerToggles() {
272
276
  if (again && typeof again.focus === 'function') again.focus({ preventScroll: true });
273
277
  }
274
278
  renderFlowLegend();
279
+ renderEdgeKey();
275
280
  renderCloudLegend();
276
281
  }
277
282
 
283
+ /** The Key (spec 0008 D7): each kind of line as the map draws it (edge-key.js) */
284
+ export function renderEdgeKey() {
285
+ const el = document.getElementById('edge-key');
286
+ if (el) el.innerHTML = edgeKeyHtml();
287
+ }
288
+
278
289
  /** What a call into a cloud node looks like for its `when` (spec 0031 section 6), while the Cloud layer is on */
279
290
  export function renderCloudLegend() {
280
291
  const el = document.getElementById('cloud-legend');
@@ -283,7 +294,7 @@ export function renderCloudLegend() {
283
294
  el.hidden = false;
284
295
  el.innerHTML = `
285
296
  <div class="hx-menu-title" data-corn="menu-title"><span>Cloud: when an outage bites</span></div>
286
- ${Object.entries(WHEN_STYLES).map(([when, s]) => `<div class="hx-legend-row"><span class="hx-legend-swatch"><span data-corn="swatch" class="hx-swatch-line hx-swatch-when hx-swatch-when--${when} hx-swatch-when--plain"></span></span><span>${s.legend}</span></div>`).join('')}
297
+ ${Object.entries(WHEN_STYLES).map(([when, s]) => `<div class="hx-legend-row"><span class="hx-legend-swatch hx-legend-swatch--wide hx-swatch-when--${when}">${keySwatch({ end: 'triangle', ticks: s.ticks })}</span><span>${s.legend}</span></div>`).join('')}
287
298
  <div class="hx-legend-row"><span class="hx-legend-swatch"></span><span class="hx-faint"><span class="hx-cloud-browser">(browser)</span> the visitor's browser makes the call, not our server</span></div>`;
288
299
  }
289
300
 
package/explorer/main.js CHANGED
@@ -46,7 +46,7 @@ import { initLive } from './live.js';
46
46
  import { initHouse } from './house.js';
47
47
  import { houseOffered } from './house-model.js';
48
48
  import { initChecks } from './check.js';
49
- import { initKeyboard } from './keyboard.js';
49
+ import { frameThem, initKeyboard } from './keyboard.js';
50
50
  import { initForgePanel } from './forge-panel.js';
51
51
  import { initReviewTokens } from './review-tokens.js';
52
52
  import { loadClientConfig, loadSources, applyBranding } from './plugins.js';
@@ -128,7 +128,8 @@ const ACTIONS = {
128
128
  'close-drawer': () => closeDrawer(),
129
129
  'copy-spec': (el) => copySpec(el),
130
130
  'start-run': () => startRun(),
131
- 'select-node': (el) => selectNode(nodeById(el.dataset.id)),
131
+ 'select-node': (el) => selectNode(nodeById(el.dataset.id), { frame: true }), // a link or a list row: the camera follows (spec 0008 D6)
132
+ 'frame-selection': () => frameThem(),
132
133
  'play-outage': (el) => playOutage(el.dataset.id), // the cloud panel's Play button (spec 0031 section 8)
133
134
  'retry': () => loadTopology(),
134
135
  'set-theme': (el) => setThemeChoice(el.dataset.choice),
@@ -55,6 +55,8 @@ export const FONT_TOKEN = '--corn-map-font';
55
55
  export const EDGE_WIDTH_TOKEN = '--corn-map-edge-width';
56
56
  export const GLOW_TOKEN = '--corn-map-glow';
57
57
  export const LABEL_MIN_TOKEN = '--corn-map-label-min';
58
+ /** The ink of a node's glyph and of a finer kind's letters (spec 0008 D8); `auto` is the white or the dark that reads on the node's fill (glyphs.js) */
59
+ export const GLYPH_TOKEN = '--corn-map-glyph';
58
60
  /** The largest label minimum a theme may ask for: bigger text would leave no room for another label */
59
61
  export const MAX_LABEL_MIN = 24;
60
62
  /** 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 */
@@ -86,6 +88,7 @@ export const MAP_COLOR_TOKENS = Object.freeze([
86
88
  STROKE_TOKEN,
87
89
  LABEL_TOKEN,
88
90
  LABEL_HALO_TOKEN,
91
+ GLYPH_TOKEN,
89
92
  ...MAP_EDGE_KINDS.map(edgeToken),
90
93
  ...MAP_MARKS.map(stateToken),
91
94
  ...MAP_STATES.map(stateToken),
@@ -6,8 +6,8 @@
6
6
  * cloud node (spec 0031) its plan, what breaks if it is down and who uses it, by when (cloud-model.js).
7
7
  */
8
8
 
9
- import { state, nodeById, nameOf, escHtml, touchScene } from './state.js';
10
- import { render } from './render.js';
9
+ import { state, nodeById, nameOf, escHtml, touchScene, viewEdges } from './state.js';
10
+ import { render, onPaint } from './render.js';
11
11
  import { flowSummary } from './flows.js';
12
12
  import { clearScenario } from './scenario-ui.js';
13
13
  import { kindOfMark, fieldRows, MARK_WORDS } from './proposal-model.js';
@@ -23,6 +23,9 @@ import { capped, toggleCapped } from './capped.js';
23
23
  import { dismissHint } from './hint.js';
24
24
  import { canStartAgent, openProposalStart } from './forge-panel.js';
25
25
  import { sayResult, clearResult, showResultIn, RESULT_MS } from './feedback.js';
26
+ import { activeSubgraph, connectedLine, farEnds, kindPanelWord, linesByKind } from './selection-model.js';
27
+ import { frameSelection, reach } from './selection-view.js';
28
+ import { announce } from './keyboard.js';
26
29
 
27
30
  const $ = (id) => document.getElementById(id);
28
31
 
@@ -220,24 +223,105 @@ function diffSection(node) {
220
223
  return `<div class="hx-sec-block" data-proposal-mark="${escHtml(node.mark)}" data-corn="section"><h3 class="hx-sec-title">In this proposal</h3>${node.why ? `<p class="hx-why">${escHtml(node.why)}</p>` : ''}<div class="hx-diff hx-diff--${escHtml(kind)}" data-corn="diff-block"${markStateAttr(node.mark)}>${rows.join('')}</div></div>`;
221
224
  }
222
225
 
226
+ // ---------------------------------------------------------------------------
227
+ // What the selection lights: the lines by kind, the switch, Frame them (spec 0008 D5 and D6)
228
+ // ---------------------------------------------------------------------------
229
+
230
+ /** The most rows a kind's list shows before "and N more" */
231
+ export const LINES_CAP = 12;
232
+
233
+ /** The lit set the panel describes: the same rule the scene lights by (selection-model.js) */
234
+ const litNow = () => activeSubgraph(state.selectedNode, viewEdges(), { throughChildren: state.throughChildren, kind: state.selectedKind });
235
+
236
+ /** The panel's "Calls 12 · Reads 9" chips, the chosen kind's far ends, the switch, and the line that says how much is on screen, with Frame them */
237
+ function linesHtml(node) {
238
+ const sub = litNow();
239
+ if (!sub || !sub.kinds.size) return '';
240
+ const kinds = linesByKind(sub);
241
+ const chips = kinds.map(({ kind, count, word }) => `<button type="button" class="hx-lines-kind" data-corn="lines-kind" data-corn-kind="quiet" data-lines-kind="${escHtml(kind)}" data-focus-key="kind:${escHtml(kind)}" aria-pressed="${sub.kind === kind}">${escHtml(word)} <span class="hx-lines-count" data-corn="count">${count}</span></button>`).join('');
242
+ const open = sub.kind ? farEnds(sub, sub.kind).map((r) => `<button type="button" class="hx-linkbtn" data-corn="node-link" data-action="select-node" data-id="${escHtml(r.id)}"><span class="hx-sr-only">${r.out ? 'to ' : 'from '}</span><span aria-hidden="true">${r.out ? '→' : '←'}</span> ${escHtml(nameOf(r.id))}</button>`) : [];
243
+ const list = open.length ? `<div class="hx-lines-list">${capped(open, LINES_CAP)}</div>` : '';
244
+ const hasChildren = activeSubgraph(node, viewEdges(), { throughChildren: false }).childIds.size > 0;
245
+ const through = hasChildren ? `<label class="hx-lines-switch"><input type="checkbox" data-corn="lines-switch" data-lines-switch data-focus-key="switch"${state.throughChildren ? ' checked' : ''}> <span>${escHtml(t('throughChildren'))}</span></label>` : '';
246
+ const { connected, off } = reach();
247
+ return `<div class="hx-sec-block hx-lines" id="drawer-lines" data-corn="lines-by-kind"><h3 class="hx-sec-title">Lines</h3><div class="hx-chips" role="group" aria-label="Lit lines by kind">${chips}</div>${list}${through}<div class="hx-lines-reach"><span data-lines-reach>${escHtml(connectedLine(connected, off))}</span> <button type="button" data-corn="frame-button" data-corn-kind="secondary" class="hx-btn hx-btn--secondary" data-action="frame-selection" data-focus-key="frame">${escHtml(t('frame'))}</button></div></div>`;
248
+ }
249
+
250
+ /** Draws the lines block again after a switch or a kind was chosen; the focus stays on the control that was used */
251
+ function paintLines() {
252
+ const box = $('drawer-lines');
253
+ if (!box || !state.selectedNode) return;
254
+ const key = document.activeElement && box.contains(document.activeElement) ? document.activeElement.dataset.focusKey : '';
255
+ const html = linesHtml(state.selectedNode);
256
+ const holder = document.createElement('div');
257
+ holder.innerHTML = html;
258
+ const next = holder.firstElementChild;
259
+ if (next) box.replaceWith(next); else box.remove();
260
+ if (key) { const again = $('drawer-lines'); const el = again && [...again.querySelectorAll('[data-focus-key]')].find((x) => x.dataset.focusKey === key); if (el) el.focus(); }
261
+ }
262
+
263
+ /** One step through the panel's lines controls: a kind's chip lights that kind alone (the same chip again lights them all), the switch widens the set */
264
+ function onLinesClick(e) {
265
+ const chip = e.target.closest && e.target.closest('[data-lines-kind]');
266
+ if (!chip || !state.selectedNode) return false;
267
+ const kind = chip.dataset.linesKind;
268
+ state.selectedKind = state.selectedKind === kind ? null : kind;
269
+ touchScene();
270
+ render();
271
+ paintLines();
272
+ const sub = litNow();
273
+ announce(sub && sub.kind ? `Showing ${kindPanelWord(sub.kind).toLowerCase()} only: ${sub.edges.length} ${sub.edges.length === 1 ? 'line' : 'lines'}` : 'Showing every kind of line');
274
+ return true;
275
+ }
276
+ function onLinesChange(e) {
277
+ const box = e.target.closest && e.target.closest('[data-lines-switch]');
278
+ if (!box || !state.selectedNode) return;
279
+ state.throughChildren = !!box.checked;
280
+ state.selectedKind = null; // the set changed under the chosen kind: it may not be in it
281
+ touchScene();
282
+ render();
283
+ paintLines();
284
+ const sub = litNow();
285
+ announce(`${state.throughChildren ? 'Including' : 'Not including'} its children's lines: ${sub ? sub.connectedNodeIds.size - 1 : 0} connected`);
286
+ }
287
+
288
+ /** Keeps "9 connected · 3 off screen" true as the camera moves (after every draw, while a node is selected and its panel is open) */
289
+ onPaint(() => {
290
+ if (!state.selectedNode) return;
291
+ const el = document.querySelector('[data-lines-reach]');
292
+ if (!el) return;
293
+ const { connected, off } = reach();
294
+ const text = connectedLine(connected, off);
295
+ if (el.textContent !== text) el.textContent = text;
296
+ });
297
+
223
298
  // ---------------------------------------------------------------------------
224
299
  // The drawer
225
300
  // ---------------------------------------------------------------------------
226
301
  let selectToken = 0;
227
302
 
228
- /** Selects a node: highlights its neighbourhood on the map and fills the side panel */
229
- export async function selectNode(node) {
303
+ /**
304
+ * Selects a node: lights what is one edge from it on the map and fills the side panel. `frame` is for a selection that did not come
305
+ * from a click on the map (a search, a list, a link, the keyboard): the camera then flies to the node and what it lights (selection-model.js);
306
+ * a click leaves the camera where it is (spec 0008 D6).
307
+ */
308
+ export async function selectNode(node, { frame = false } = {}) {
230
309
  if (!node) return;
231
310
  const token = ++selectToken;
232
311
  clearScenario();
233
312
  dismissHint(); // a node has been picked: the hint's job is done for this session
313
+ if (!state.selectedNode || state.selectedNode.id !== node.id) state.selectedKind = null; // a kind chosen for one node means nothing for the next
234
314
  state.selectedNode = node;
235
315
  state.selectedEdge = null;
236
316
  touchScene();
237
317
  render();
238
318
 
239
319
  const metaList = $('drawer-meta-list');
240
- if (!metaList.dataset.moreBound) { metaList.dataset.moreBound = '1'; metaList.addEventListener('click', (e) => { toggleCapped(e.target); }); }
320
+ if (!metaList.dataset.moreBound) {
321
+ metaList.dataset.moreBound = '1';
322
+ metaList.addEventListener('click', (e) => { if (!onLinesClick(e)) toggleCapped(e.target); });
323
+ metaList.addEventListener('change', onLinesChange);
324
+ }
241
325
  const openBtn = $('drawer-open-btn');
242
326
  const title = $('drawer-title');
243
327
 
@@ -257,7 +341,7 @@ export async function selectNode(node) {
257
341
  if (token !== selectToken) return;
258
342
 
259
343
  const facts = `${node.file ? section('File', [code(node.file)]) : ''}${flowSummary(node)}${dataSummary(node)}`;
260
- metaList.innerHTML = `${facts ? `<div class="hx-facts">${facts}</div>` : ''}
344
+ metaList.innerHTML = `${linesHtml(node)}${facts ? `<div class="hx-facts">${facts}</div>` : ''}
261
345
  <div id="drawer-live">${liveSection(node)}</div>
262
346
  ${nodeMockupsHtml(node.id)}
263
347
  <div id="drawer-threads">${threadsSection(node)}</div>
@@ -285,7 +369,8 @@ export async function selectNode(node) {
285
369
  $('spec-drawer').inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
286
370
  $('drawer-backdrop').hidden = false;
287
371
  showSheet('drawer'); // on a phone it takes Work's place (the node sheet and Work take turns), and comes back from away when its node is tapped again
288
- keepSelectedInView();
372
+ if (frame) frameSelection(); // the panel is open now, so what it covers is known
373
+ else keepSelectedInView();
289
374
  }
290
375
 
291
376
  /**
@@ -22,8 +22,8 @@ import { ZOOM_MIN, ZOOM_FLOOR } from './camera.js';
22
22
  // ---------------------------------------------------------------------------
23
23
  export const isNodeVisible = (node) => nodeVisible(state, node);
24
24
 
25
- /** The focus subgraph: the selected node, its children and every path through them */
26
- export const getActiveSubgraph = (selected, edges = viewEdges()) => activeSubgraph(selected, edges);
25
+ /** The focus subgraph: the selected node and every node one edge away (selection-model.js); the switch and the kind come from the state */
26
+ export const getActiveSubgraph = (selected, edges = viewEdges(), opts = { throughChildren: !!state.throughChildren, kind: state.selectedKind || null }) => activeSubgraph(selected, edges, opts);
27
27
 
28
28
  // ---------------------------------------------------------------------------
29
29
  // Scene and renderer