cornfield 0.41.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.
Files changed (45) hide show
  1. package/core/contrast.js +68 -2
  2. package/core/delta-e.js +66 -0
  3. package/core/schema.js +29 -7
  4. package/core/strings.js +11 -0
  5. package/explorer/capped.js +6 -5
  6. package/explorer/cloud-model.js +10 -7
  7. package/explorer/decision-model.js +231 -0
  8. package/explorer/diff-marks.js +3 -1
  9. package/explorer/edge-key.js +59 -0
  10. package/explorer/explorer.css +55 -9
  11. package/explorer/flows.js +0 -2
  12. package/explorer/forge-panel.js +30 -8
  13. package/explorer/glyphs.js +130 -0
  14. package/explorer/house-model.js +2 -2
  15. package/explorer/index.html +7 -18
  16. package/explorer/keyboard-model.js +4 -1
  17. package/explorer/keyboard.js +14 -2
  18. package/explorer/kind-letters.js +9 -5
  19. package/explorer/labels.js +33 -34
  20. package/explorer/layers.js +16 -5
  21. package/explorer/main.js +3 -2
  22. package/explorer/map-style.js +3 -0
  23. package/explorer/panels.js +92 -7
  24. package/explorer/proposal-model.js +24 -0
  25. package/explorer/proposal.js +13 -6
  26. package/explorer/render.js +2 -2
  27. package/explorer/renderer-canvas2d.js +169 -26
  28. package/explorer/renderer-webgl.js +51 -17
  29. package/explorer/review-column.js +22 -4
  30. package/explorer/review.js +413 -44
  31. package/explorer/runs-model.js +1 -1
  32. package/explorer/scene.js +58 -47
  33. package/explorer/selection-model.js +150 -0
  34. package/explorer/selection-view.js +36 -0
  35. package/explorer/shaders.js +76 -13
  36. package/explorer/spatial.js +7 -4
  37. package/explorer/state.js +8 -0
  38. package/explorer/tokens.css +1 -0
  39. package/explorer/whatif.js +84 -7
  40. package/package.json +1 -1
  41. package/server/decision.js +117 -0
  42. package/server/proposal-pulls.js +1 -1
  43. package/server/proposals.js +58 -9
  44. package/server/server.js +19 -2
  45. package/server/submit-review.js +52 -7
@@ -299,8 +299,6 @@ h1, h2, h3, p { margin: 0; }
299
299
  .hx-legend-label { display: flex; align-items: center; gap: var(--corn-space-3); font-weight: 500; }
300
300
  .hx-legend-swatch { width: 16px; flex: none; display: inline-flex; justify-content: center; }
301
301
  .hx-swatch-line { display: inline-block; width: 16px; height: 2px; border-radius: var(--corn-radius-xs); }
302
- .hx-swatch-solid { background: color-mix(in srgb, var(--corn-text) 55%, transparent); }
303
- .hx-swatch-dashed { height: 0; background: none; border-top: var(--corn-border-strong) dashed var(--corn-text-2); }
304
302
  .hx-swatch-indigo { border-top-color: var(--corn-accent-text); }
305
303
 
306
304
  /* ---- stage: canvas, hint, states --------------------------------------------------------- */
@@ -642,7 +640,7 @@ h2.hx-proposal-name { margin: 0; }
642
640
  .hx-proposal-bar[data-sheet-state="peek"] > :not(.hx-sheet-handle):not(#proposal-message):not(#proposal-ways):not(#proposal-body),
643
641
  .hx-proposal-bar[data-sheet-state="peek"] #proposal-body > :not(.hx-proposal-head),
644
642
  .hx-proposal-bar[data-sheet-state="peek"] .hx-proposal-head > :is(.hx-proposal-tools, .hx-proposal-more, .hx-proposal-more-menu) { display: none; }
645
- .hx-proposal-bar[data-sheet-state="peek"] .hx-review > :not([data-review-hint]):not([data-review-msg]) { display: none; } /* the peek keeps the reason Approve is off, and a refusal */
643
+ .hx-proposal-bar[data-sheet-state="peek"] .hx-review > :not([data-review-hint]):not([data-review-msg]):not([data-review-line]):not([data-review-ask]):not([data-review-hold]):not([data-review-hold-live]):not([data-review-landing]) { display: none; } /* the peek keeps the line Approve points at, the question, the hold, a landing that waits, and a refusal */
646
644
  .hx-proposal-bar[data-sheet-state="expanded"] .hx-whatif-panel { max-height: none; overflow: visible; }
647
645
 
648
646
  /* The scenario player: one row (Previous, Pause, Next, the counter and Close) in the peek; the text, the speed and the checks when it is open */
@@ -714,12 +712,6 @@ h2.hx-proposal-name { margin: 0; }
714
712
  .hx-player-as[hidden], .hx-player-verdict[hidden], .hx-player-check[hidden] { display: none; }
715
713
 
716
714
  /* ---- cloud nodes (spec 0031, CLOUD-06): the panel's badges, plan and Used by; the `when` line styles -- */
717
- /* The `when` swatches mirror cloud-model.js WHEN_STYLES (run solid, deploy dashed, renew dotted; red, amber, violet) */
718
- .hx-swatch-when { width: 18px; height: 2px; border-radius: 0; color: var(--corn-text-2); background: currentColor; }
719
- .hx-swatch-when--run { color: var(--corn-removed); }
720
- .hx-swatch-when--deploy { color: var(--corn-changed); background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px); }
721
- .hx-swatch-when--renew { color: var(--corn-edit); background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 5px); }
722
- .hx-swatch-when--plain { color: var(--corn-text-2); } /* the legend: the map draws every call in the calls colour, so only the pattern is the key */
723
715
  .hx-cloud-browser { color: var(--corn-text-3); font-size: var(--corn-text-sm); }
724
716
 
725
717
  /* ---- a panel glyph (MAP-01) ----------------------------------------------------------------------
@@ -1420,3 +1412,57 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
1420
1412
  .hx-dock > .hx-proposal-bar[data-sheet-state="expanded"], .hx-dock > .hx-player[data-sheet-state="expanded"] { max-height: min(var(--hx-sheet-cap, 50dvh), 50dvh); }
1421
1413
  .hx-dock > .hx-drawer[data-sheet-state="expanded"], .hx-dock > .hx-forge[data-sheet-state="expanded"] { max-height: min(var(--hx-sheet-cap, 60dvh), 60dvh); }
1422
1414
  }
1415
+
1416
+ /* ---------------------------------------------------------------------------
1417
+ The node panel's lines (spec 0008 D5 and D6): the lit lines by kind, the switch, and Frame them
1418
+ --------------------------------------------------------------------------- */
1419
+ .hx-lines { display: flex; flex-direction: column; gap: var(--corn-space-2); }
1420
+ .hx-lines .hx-chips { padding-top: 0; }
1421
+ .hx-lines-kind { display: inline-flex; align-items: baseline; gap: var(--corn-space-1); min-height: 28px; padding: 0 var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); background: none; color: var(--corn-text-2); font: inherit; font-size: var(--corn-text-xs); font-weight: 600; cursor: pointer; }
1422
+ .hx-lines-kind:hover { background: var(--corn-surface-3); color: var(--corn-text); }
1423
+ .hx-lines-kind[aria-pressed="true"] { border-color: var(--corn-accent); background: var(--corn-accent-soft); color: var(--corn-accent-text); }
1424
+ .hx-lines-kind:focus-visible, .hx-lines-switch input:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: var(--corn-focus-offset); }
1425
+ .hx-lines-count { font-variant-numeric: tabular-nums; color: var(--corn-text-3); }
1426
+ .hx-lines-list { display: flex; flex-direction: column; align-items: flex-start; gap: calc(var(--corn-space-1) / 2); }
1427
+ .hx-lines-list .hx-linkbtn { margin-left: 0; text-align: left; overflow-wrap: anywhere; }
1428
+ .hx-lines-switch { display: flex; align-items: center; gap: var(--corn-space-2); min-height: 28px; font-size: var(--corn-text-sm); color: var(--corn-text-2); cursor: pointer; }
1429
+ .hx-lines-reach { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-3); font-size: var(--corn-text-sm); color: var(--corn-text-2); font-variant-numeric: tabular-nums; }
1430
+ @media (max-width: 767px), (pointer: coarse) {
1431
+ .hx-lines-kind, .hx-lines-switch, .hx-lines-list .hx-linkbtn, .hx-lines-reach .hx-btn { min-height: 44px; }
1432
+ .hx-lines-switch input { width: 24px; height: 24px; }
1433
+ }
1434
+
1435
+ /* ---------------------------------------------------------------------------
1436
+ The Key (spec 0008 D7, edge-key.js): each kind of line drawn with its real style and end mark. The map says the kind by line style
1437
+ and mark, never by colour alone, so the swatches are one ink; a `when` is told by ticks (cloud-model.js WHEN_STYLES)
1438
+ --------------------------------------------------------------------------- */
1439
+ .hx-legend-swatch--wide { width: 44px; justify-content: flex-start; color: var(--corn-text-2); }
1440
+ .hx-key-line { display: block; overflow: visible; }
1441
+ .hx-key-note { margin: var(--corn-space-1) 0 0; font-size: var(--corn-text-xs); }
1442
+
1443
+ /* ===== Spec 0007: the decision. The line above Approve, the question asked in place, the hold with Undo, a landing that waits, what a send back carried ===== */
1444
+ .hx-decision-line { margin: 0; color: var(--corn-text-2); font-size: var(--corn-text-sm); line-height: 1.45; }
1445
+ .hx-decision-line[hidden], .hx-review-ask[hidden], .hx-hold[hidden], .hx-review-landing[hidden], .hx-sent-edits[hidden] { display: none; }
1446
+ .hx-review-ask { margin: 0; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid color-mix(in srgb, var(--corn-warn) 55%, transparent); background: color-mix(in srgb, var(--corn-warn) 14%, transparent); color: var(--corn-text); line-height: 1.4; }
1447
+ .hx-review-landing { display: flex; align-items: center; justify-content: space-between; gap: var(--corn-space-3); padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); color: var(--corn-text-2); }
1448
+ .hx-review-landing p { margin: 0; line-height: 1.4; }
1449
+ .hx-sent-edits { color: var(--corn-text-2); }
1450
+ .hx-sent-edits summary { cursor: pointer; min-height: 24px; }
1451
+ .hx-hold { height: 3px; border-radius: var(--corn-radius-sm); background: color-mix(in srgb, var(--corn-accent) 22%, transparent); overflow: hidden; }
1452
+ .hx-hold-fill { display: block; height: 100%; width: 100%; background: var(--corn-accent); transform-origin: left center; animation-name: hx-hold-drain; animation-timing-function: linear; animation-fill-mode: forwards; }
1453
+ @keyframes hx-hold-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
1454
+ .hx-proposal-actions .hx-btn[aria-disabled="true"] { opacity: 0.55; cursor: default; }
1455
+ .hx-proposal-actions .hx-btn[data-holding="true"] { opacity: 1; font-variant-numeric: tabular-nums; }
1456
+ .hx-review-undo[hidden] { display: none; }
1457
+ @media (max-width: 767px) {
1458
+ .hx-review-undo { min-height: 44px; min-width: 44px; order: 1; grid-column: 1 / -1; } /* a row of its own under Send back and Approve: never where the finger that pressed is */
1459
+ .hx-review-landing .hx-btn { min-height: 44px; }
1460
+ .hx-proposal-bar:has(.hx-review-form:not([hidden])) .hx-decision-line { display: none; } /* the note's sheet shows the send back line under the note, not Approve's */
1461
+ }
1462
+ @media (prefers-reduced-motion: reduce) { .hx-hold { display: none; } .hx-hold-fill { animation: none; } } /* only the words count down */
1463
+ .hx-rc-sub { margin: var(--corn-space-2) 0 var(--corn-space-1); font-size: var(--corn-text-sm); font-weight: 600; color: var(--corn-text); }
1464
+ .hx-proposal-yours { display: inline-flex; align-items: center; gap: var(--corn-space-1); color: var(--corn-text-2); }
1465
+ .hx-proposal-tools [aria-pressed="false"] { opacity: 0.8; }
1466
+ .hx-whatif-row [aria-disabled="true"] { opacity: 0.55; cursor: default; }
1467
+ .hx-runner-dot { display: inline-block; width: 8px; height: 8px; margin-left: var(--corn-space-1); border-radius: 50%; background: var(--corn-warn); vertical-align: middle; }
1468
+ .hx-runner-dot[hidden] { display: none; }
package/explorer/flows.js CHANGED
@@ -142,8 +142,6 @@ export function renderFlowLegend() {
142
142
  <span>Data Flow</span>
143
143
  </div>
144
144
  ${Object.values(FLOW_STYLES).map((s) => row(`<span data-corn="swatch" class="hx-swatch-line" style="background:${themed(s.color, state.theme)}"></span>`, s.label)).join('')}
145
- ${row('<span data-corn="swatch" class="hx-swatch-line hx-swatch-solid"></span>', '<span class="hx-faint">Solid: live today</span>')}
146
- ${row('<span data-corn="swatch" class="hx-swatch-line hx-swatch-dashed"></span>', '<span class="hx-faint">Dashed: proposed</span>')}
147
145
  </div>`;
148
146
  }
149
147
 
@@ -69,7 +69,7 @@
69
69
  import { state, nodeById, escHtml, touchScene, onSceneTouch } from './state.js';
70
70
  import { render, isNodeVisible } from './render.js';
71
71
  import { selectNode, repaintThreads } from './panels.js';
72
- import { announce, centreOn } from './keyboard.js';
72
+ import { announce } from './keyboard.js';
73
73
  import { trapTab } from './focusables.js';
74
74
  import { isPhone, registerSheet, expandSheet, collapseSheet, showSheet, refreshStubs } from './sheets.js';
75
75
  import { relativeTime } from './review-model.js';
@@ -1538,13 +1538,32 @@ function graftAround(root, keep, twin) {
1538
1538
  }
1539
1539
  }
1540
1540
 
1541
- /** The one line on whether a runner is polling (pull transport only), in the Runs view and the Start dialog; hidden where it does not apply */
1541
+ /** Whether a run would wait for a runner that is not there (pull transport only; issue #183, spec 0007 D1) */
1542
+ function runnerAway() {
1543
+ const data = ui.runs && ui.runs.data;
1544
+ const state = data ? runnerState(data.runnerPresence, now()) : null;
1545
+ return state === 'offline' || state === 'none';
1546
+ }
1547
+
1548
+ /** The Start dialog's button: "Ask the runner", or "Queue it (no runner online)" while no runner polls, so the click says what it does */
1549
+ function askRunnerWords() {
1550
+ return runnerAway() ? `${t('queueIt')} (no runner online)` : t('askRunner');
1551
+ }
1552
+
1553
+ /**
1554
+ * The one line on whether a runner is polling (pull transport only), in the Runs view and the Start dialog; hidden where it does not apply.
1555
+ * While no runner is online it is a notice at the top of the view, not the faint line: a run asked for would wait (issue #183).
1556
+ */
1542
1557
  function paintRunner(id, data) {
1543
1558
  const el = $(id);
1544
1559
  if (!el) return;
1545
1560
  const words = data ? runnerWords(data.runnerPresence, now()) : '';
1546
1561
  el.hidden = !words;
1547
1562
  el.textContent = words;
1563
+ const state = data ? runnerState(data.runnerPresence, now()) : null;
1564
+ const away = state === 'offline' || state === 'none';
1565
+ el.className = away ? 'hx-forge-notice' : 'hx-forge-meta';
1566
+ if (away) { el.dataset.corn = 'notice'; el.dataset.cornState = 'waiting'; } else { delete el.dataset.corn; delete el.dataset.cornState; }
1548
1567
  }
1549
1568
 
1550
1569
  /** What the Runs view needs to know of the page */
@@ -1618,12 +1637,16 @@ function paintButton() {
1618
1637
  tag.textContent = ui.runSel ? 'run' : ui.thread !== null ? `thread #${ui.thread}` : ui.deployItem ? 'deploy' : lit ? `#${ui.selected}` : '';
1619
1638
  }
1620
1639
  const n = waitingNow().total;
1640
+ // A run would wait for a runner that is not there: a dot, and the name says so (issue #183); it sits beside the waiting badge, not on it
1641
+ const away = runnerAway();
1642
+ const dot = $('forge-btn-dot');
1643
+ if (dot) dot.hidden = !away;
1621
1644
  const badge = $('forge-btn-waiting');
1622
1645
  if (badge) {
1623
1646
  badge.hidden = n === 0;
1624
1647
  badge.textContent = n ? String(n) : '';
1625
1648
  }
1626
- btn.setAttribute('aria-label', `${workButtonName(t('issuesAndPrs'), n)}${ui.runSel ? ', a run lit on the map' : ui.thread !== null ? `, thread ${ui.thread} selected` : ui.deployItem ? ', a deploy selected' : lit ? `, pull request ${ui.selected} selected` : ''}`);
1649
+ btn.setAttribute('aria-label', `${workButtonName(t('issuesAndPrs'), n)}${away ? ', no runner online' : ''}${ui.runSel ? ', a run lit on the map' : ui.thread !== null ? `, thread ${ui.thread} selected` : ui.deployItem ? ', a deploy selected' : lit ? `, pull request ${ui.selected} selected` : ''}`);
1627
1650
  }
1628
1651
 
1629
1652
  // ---------------------------------------------------------------------------
@@ -1872,7 +1895,7 @@ async function openAgent(ref, opener, again = null, brief = null) {
1872
1895
  const go = $('agent-start-go');
1873
1896
  go.disabled = false;
1874
1897
  go.removeAttribute('aria-busy');
1875
- go.textContent = t('askRunner');
1898
+ go.textContent = askRunnerWords();
1876
1899
  document.addEventListener('focusin', keepFocusInAgent);
1877
1900
  agentEl().hidden = false;
1878
1901
  $('agent-kind').focus();
@@ -1962,7 +1985,7 @@ async function submitAgent(e) {
1962
1985
  ui.agent.posting = false;
1963
1986
  go.disabled = false;
1964
1987
  go.removeAttribute('aria-busy');
1965
- go.textContent = t('askRunner');
1988
+ go.textContent = askRunnerWords();
1966
1989
  const bad = $('agent-start-msg');
1967
1990
  bad.textContent = `A limit is a number above zero, or blank for the config's (${wrong.join(', ')}).`;
1968
1991
  bad.hidden = false;
@@ -1987,7 +2010,7 @@ async function submitAgent(e) {
1987
2010
  }
1988
2011
  go.disabled = false;
1989
2012
  go.removeAttribute('aria-busy');
1990
- go.textContent = t('askRunner');
2013
+ go.textContent = askRunnerWords();
1991
2014
  const msg = $('agent-start-msg');
1992
2015
  msg.textContent = text;
1993
2016
  msg.hidden = false;
@@ -2326,8 +2349,7 @@ function onClick(e) {
2326
2349
  if (nodeBtn) {
2327
2350
  const node = nodeById(nodeBtn.dataset.forgeNode);
2328
2351
  if (!node) return;
2329
- selectNode(node);
2330
- centreOn(node);
2352
+ selectNode(node, { frame: true });
2331
2353
  if (isPhone()) collapseSheet('forge'); // the map and the node's sheet are what is wanted now
2332
2354
  announce(`${node.label}, ${node.type}`);
2333
2355
  return;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @module explorer/glyphs
3
+ *
4
+ * The built-in glyph of each node type (spec 0008 D8): a small monochrome picture drawn in the middle of a node once it is 14 px across on screen,
5
+ * where the white core dot is. It tells types of one silhouette apart beyond their colour. Both renderers draw the same picture, made once here as
6
+ * a small transparent image (like kind-letters.js), and by the same rule:
7
+ *
8
+ * a theme's icon for the node (`theme.icons`) > a finer kind's letters (spec 0009, kind-letters.js) > the type's glyph > the white core dot
9
+ *
10
+ * Canvas 2D draws the image with `drawImage` where an icon would go; WebGL uploads it as a texture and draws it in the icon pass, grouped by
11
+ * `glyph:<type>|<ink>`. The glyphs are a fixed set (one per type in core/schema.js, nothing a map holds), in two inks at most per type
12
+ * (white or dark, whichever reads on the node's fill; or the theme's `--corn-map-glyph`), so the textures are few and bounded.
13
+ */
14
+
15
+ import { NODE_THEMES } from '../core/schema.js';
16
+ import { parseColor } from './theme-model.js';
17
+
18
+ /** A node is at least this many px across (on screen) before its glyph is drawn: smaller, no glyph reads and the silhouette does the work */
19
+ export const GLYPH_MIN_PX = 14;
20
+ /** The glyph's box, as a fraction of the node's radius across (a square centred on the node, like an icon) */
21
+ export const GLYPH_RATIO = 1.2;
22
+ const SIDE = 96;
23
+ const GRID = 24; // the glyphs are drawn on a 24 by 24 grid
24
+ const KEY_PREFIX = 'glyph:';
25
+ /** The two inks the glyph takes when the theme does not set `--corn-map-glyph`: white on a deep fill, dark on a pale one */
26
+ export const INK_LIGHT = '#ffffff';
27
+ export const INK_DARK = '#0b1220';
28
+ /** The most glyph images made: types times inks is far under it; a theme that sets many colours at once cannot grow it */
29
+ export const MAX_GLYPH_IMAGES = 64;
30
+
31
+ /** Types that have a glyph: the built-in ones. A type a project invents has none (it keeps the white core dot) */
32
+ export const GLYPH_TYPES = Object.freeze(Object.keys(NODE_THEMES));
33
+ export const hasGlyph = (type) => typeof type === 'string' && Object.hasOwn(NODE_THEMES, type);
34
+
35
+ /** The key a glyph goes under in the renderers' icon tables */
36
+ export const glyphKey = (type, ink) => `${KEY_PREFIX}${type}|${ink}`;
37
+ export const isGlyphKey = (key) => typeof key === 'string' && key.startsWith(KEY_PREFIX);
38
+ /** @returns {{type: string, ink: string}} */
39
+ export function glyphOfKey(key) {
40
+ const rest = key.slice(KEY_PREFIX.length);
41
+ const at = rest.indexOf('|');
42
+ return { type: rest.slice(0, at), ink: rest.slice(at + 1) };
43
+ }
44
+
45
+ const luminanceOf = ([r, g, b]) => {
46
+ const lin = (c) => { const v = c / 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; };
47
+ return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
48
+ };
49
+ const ratioOf = (a, b) => { const [hi, lo] = a > b ? [a, b] : [b, a]; return (hi + 0.05) / (lo + 0.05); };
50
+
51
+ /** The ink that reads on a fill: white or dark, whichever has the higher contrast (the glyph is at least 3:1 on every fill of the default palette: a test holds it) */
52
+ export function inkFor(fill) {
53
+ const lum = luminanceOf(parseColor(fill));
54
+ return ratioOf(1, lum) >= ratioOf(luminanceOf(parseColor(INK_DARK)), lum) ? INK_LIGHT : INK_DARK;
55
+ }
56
+
57
+ /** The ink a node's glyph is drawn in: the theme's (`--corn-map-glyph`, in the style's `values`), else the one that reads on its fill */
58
+ export const glyphInk = (node, style) => (style && style.values && style.values['--corn-map-glyph']) || inkFor(node.color);
59
+
60
+ /** Whether a node's glyph is drawn at this zoom: it has one, no icon or letters replace it, and it is wide enough on screen */
61
+ export const showsGlyph = (node, zoom) => !!node.glyph && !node.icon && !node.letters && node.r * 2 * zoom >= GLYPH_MIN_PX;
62
+
63
+ /** The glyph of each type: a function that adds its strokes and fills to a 24 by 24 grid (`ink` is already the fill and stroke style) */
64
+ const PATHS = {
65
+ root: (c) => { ring(c, 12, 12, 8); dot(c, 12, 12, 3.2); },
66
+ app: (c) => { c.beginPath(); c.rect(3.5, 5, 17, 14); c.stroke(); line(c, 3.5, 9.5, 20.5, 9.5); },
67
+ page: (c) => { c.beginPath(); c.rect(6, 3.5, 12, 17); c.stroke(); line(c, 9, 9, 15, 9); line(c, 9, 12.5, 15, 12.5); line(c, 9, 16, 13, 16); },
68
+ pkg: (c) => { c.beginPath(); c.rect(4, 7, 16, 13); c.stroke(); line(c, 4, 12, 20, 12); line(c, 12, 7, 12, 12); },
69
+ core: (c) => { ring(c, 12, 12, 8.2); dot(c, 12, 12, 4); },
70
+ token: (c) => { for (const [x, y] of [[5, 5], [13, 5], [5, 13], [13, 13]]) { c.fillRect(x, y, 6, 6); } },
71
+ atom: (c) => { c.beginPath(); c.ellipse(12, 12, 9.5, 4, -0.5, 0, Math.PI * 2); c.stroke(); dot(c, 12, 12, 3); },
72
+ molecule: (c) => { line(c, 7, 16, 17, 8); dot(c, 7, 16, 4); dot(c, 17, 8, 4); },
73
+ tool: (c) => { line(c, 12, 4, 12, 20); line(c, 4, 12, 20, 12); },
74
+ rom: (c) => { c.beginPath(); c.arc(12, 12, 7.5, 0.4, Math.PI * 1.6); c.stroke(); c.beginPath(); c.moveTo(14.5, 2.5); c.lineTo(20, 5.5); c.lineTo(14, 8.5); c.closePath(); c.fill(); },
75
+ service: (c) => { c.beginPath(); c.moveTo(13.5, 2.5); c.lineTo(6, 13.5); c.lineTo(11.5, 13.5); c.lineTo(10, 21.5); c.lineTo(18, 9.5); c.lineTo(12.5, 9.5); c.closePath(); c.fill(); },
76
+ store: (c) => { c.beginPath(); c.ellipse(12, 6.5, 7.5, 3, 0, 0, Math.PI * 2); c.stroke(); line(c, 4.5, 6.5, 4.5, 17.5); line(c, 19.5, 6.5, 19.5, 17.5); c.beginPath(); c.ellipse(12, 17.5, 7.5, 3, 0, 0, Math.PI); c.stroke(); },
77
+ table: (c) => { c.beginPath(); c.rect(4, 5, 16, 14); c.stroke(); line(c, 4, 10, 20, 10); line(c, 12, 10, 12, 19); },
78
+ external: (c) => { line(c, 7, 17, 17, 7); c.beginPath(); c.moveTo(9.5, 6.5); c.lineTo(17.5, 6.5); c.lineTo(17.5, 14.5); c.stroke(); },
79
+ stack: (c) => { for (const y of [4.5, 10.5, 16.5]) c.fillRect(4, y, 16, 3.5); },
80
+ machine: (c) => { c.beginPath(); c.rect(3.5, 4.5, 17, 11); c.stroke(); line(c, 12, 15.5, 12, 19.5); line(c, 7.5, 19.5, 16.5, 19.5); },
81
+ container: (c) => { c.beginPath(); c.rect(4, 4, 16, 16); c.stroke(); c.fillRect(8.5, 8.5, 7, 7); },
82
+ device: (c) => { c.beginPath(); c.rect(7.5, 3, 9, 18); c.stroke(); dot(c, 12, 17.5, 1.3); },
83
+ floor: (c) => { c.beginPath(); c.moveTo(3.5, 20.5); c.lineTo(3.5, 15.5); c.lineTo(9, 15.5); c.lineTo(9, 10.5); c.lineTo(14.5, 10.5); c.lineTo(14.5, 5.5); c.lineTo(20.5, 5.5); c.stroke(); },
84
+ room: (c) => { c.beginPath(); c.rect(6.5, 3.5, 11, 17); c.stroke(); dot(c, 14.5, 12.5, 1.4); },
85
+ persona: (c) => { dot(c, 12, 8, 3.8); c.beginPath(); c.arc(12, 21, 8, Math.PI * 1.15, Math.PI * 1.85); c.stroke(); },
86
+ };
87
+ function line(c, x1, y1, x2, y2) { c.beginPath(); c.moveTo(x1, y1); c.lineTo(x2, y2); c.stroke(); }
88
+ function ring(c, x, y, r) { c.beginPath(); c.arc(x, y, r, 0, Math.PI * 2); c.stroke(); }
89
+ function dot(c, x, y, r) { c.beginPath(); c.arc(x, y, r, 0, Math.PI * 2); c.fill(); }
90
+
91
+ /** Draws a glyph on a 2D context sized `side` px, in `ink` (the tone was chosen against the node's fill, so the glyph needs no halo; it sits over the white core dot) */
92
+ export function drawGlyph(ctx, type, side, ink) {
93
+ const draw = PATHS[type];
94
+ if (!draw) return;
95
+ const k = side / GRID;
96
+ ctx.save();
97
+ ctx.scale(k, k);
98
+ ctx.lineWidth = 2.4;
99
+ ctx.lineCap = 'round';
100
+ ctx.lineJoin = 'round';
101
+ ctx.strokeStyle = ink;
102
+ ctx.fillStyle = ink;
103
+ draw(ctx);
104
+ ctx.restore();
105
+ }
106
+
107
+ const images = new Map();
108
+ /** Lets the images go (a test starts afresh with it) */
109
+ export const forgetGlyphImages = () => images.clear();
110
+
111
+ /**
112
+ * The image of a type's glyph in an ink, made once (null where there is no canvas to draw one on, as in a test without a browser, and for a type with no glyph).
113
+ * @param {string} type
114
+ * @param {string} ink a CSS colour
115
+ * @returns {CanvasImageSource | null}
116
+ */
117
+ export function glyphImage(type, ink) {
118
+ if (!hasGlyph(type) || typeof ink !== 'string') return null;
119
+ const key = glyphKey(type, ink);
120
+ if (images.has(key)) return images.get(key);
121
+ if (images.size >= MAX_GLYPH_IMAGES) return null;
122
+ let image = null;
123
+ try {
124
+ const canvas = typeof OffscreenCanvas !== 'undefined' ? new OffscreenCanvas(SIDE, SIDE) : typeof document !== 'undefined' ? Object.assign(document.createElement('canvas'), { width: SIDE, height: SIDE }) : null;
125
+ const ctx = canvas && canvas.getContext && canvas.getContext('2d');
126
+ if (ctx && ctx.stroke) { drawGlyph(ctx, type, SIDE, ink); image = canvas; }
127
+ } catch { image = null; }
128
+ images.set(key, image);
129
+ return image;
130
+ }
@@ -778,8 +778,8 @@ export const CLOUD_LINE_ALPHA = { run: 0.9, deploy: 0.25, renew: 0.9 };
778
778
  /** A line an outage travels, as outage-model.js `paintOutage` draws a walked edge */
779
779
  const OUTAGE_LINE = { alpha: 0.9, width: 2.2 };
780
780
  const WHENS = Object.keys(WHEN_STYLES);
781
- /** The `when` a drawn call is for, read off its dash (scene.js draws it with `whenDash`) */
782
- const whenOfDrawn = (e) => WHENS.find((w) => String(WHEN_STYLES[w].dash) === String(e.dash)) || 'run';
781
+ /** The `when` a drawn call is for, read off its ticks (scene.js draws it with `whenTicks`) */
782
+ const whenOfDrawn = (e) => WHENS.find((w) => WHEN_STYLES[w].ticks === (e.ticks || 0)) || 'run';
783
783
 
784
784
  /**
785
785
  * The Cloud band's lines, after the scene is built: with nothing selected, `deploy` lines quiet and the rest at full;
@@ -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>
@@ -133,6 +119,7 @@
133
119
  <span data-corn-string="issuesAndPrs">Work</span>
134
120
  <span id="forge-btn-lit" class="hx-forge-lit" data-corn="count" hidden></span>
135
121
  <!-- What waits on you (explorer/waiting-model.js): specs to decide plus runs that need an answer; hidden at 0 and for anyone not signed in -->
122
+ <span id="forge-btn-dot" class="hx-runner-dot" aria-hidden="true" title="No runner online" hidden></span>
136
123
  <span id="forge-btn-waiting" class="hx-waiting-badge" data-corn="waiting-badge" aria-hidden="true" hidden></span>
137
124
  </button>
138
125
 
@@ -199,7 +186,7 @@
199
186
  <div class="hx-stage" role="main" data-corn="stage">
200
187
  <!-- The map takes the keyboard when it has the focus (keyboard.js): its keys are below, read out with its name -->
201
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>
202
- <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>
203
190
  <!-- What the keyboard landed on, said by a screen reader (keyboard.js) -->
204
191
  <p id="map-announcer" class="hx-sr-only" role="status" aria-live="polite"></p>
205
192
  <!-- Every label, drawn on its own transparent canvas over the map (explorer/labels.js); the map canvas still gets the pointer -->
@@ -228,6 +215,8 @@
228
215
  <button data-corn="compare-option" type="button" class="hx-seg-btn" data-action="proposal-view" data-view="after" aria-pressed="false" data-corn-string="after">After</button>
229
216
  </div>
230
217
  <div class="hx-proposal-tools">
218
+ <!-- Shown only while there are what-if edits: off, the map is the proposal as written; the edits are kept and still go with a review (whatif.js) -->
219
+ <button data-corn-kind="secondary" type="button" id="proposal-myedits" class="hx-btn" aria-pressed="true" data-peek-ok data-corn-string="myEdits" hidden>My edits</button>
231
220
  <button data-corn-kind="secondary" type="button" id="proposal-edit" class="hx-btn" aria-expanded="false" aria-controls="whatif" title="Try a change: add a node or an edge, reword a scenario">Edit</button>
232
221
  </div>
233
222
  <div class="hx-proposal-more">
@@ -325,8 +314,8 @@
325
314
  <!-- Agent runs (forge-panel.js, runs-model.js): shown on the Runs tab; each run's state, what it is about, links, and Stop -->
326
315
  <section id="forge-runs" class="hx-forge-runs" aria-labelledby="forge-runs-title" hidden>
327
316
  <h3 id="forge-runs-title" class="hx-forge-runs-title">Agent runs</h3>
328
- <p id="forge-runs-status" class="hx-forge-meta hx-faint"></p>
329
317
  <p id="forge-runs-runner" class="hx-forge-meta" hidden></p>
318
+ <p id="forge-runs-status" class="hx-forge-meta hx-faint"></p>
330
319
  <p id="forge-runs-note" class="hx-forge-notice" hidden data-corn="notice"></p>
331
320
  <p id="forge-runs-trigger" class="hx-forge-notice" hidden data-corn="notice"></p>
332
321
  <div id="forge-runs-totals" data-corn="run-totals" role="group" aria-label="Tokens and cost the runners reported" hidden></div>
@@ -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
  }