cornfield 0.50.0 → 0.51.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 (67) hide show
  1. package/explorer/camera-frame.js +82 -0
  2. package/explorer/camera.js +7 -73
  3. package/explorer/check-model.js +3 -44
  4. package/explorer/cloud-model.js +2 -101
  5. package/explorer/cloud-panel.js +107 -0
  6. package/explorer/css/review.css +2 -0
  7. package/explorer/engine/connection.js +4 -1
  8. package/explorer/engine/map-rect.js +97 -0
  9. package/explorer/engine/player.js +2 -1
  10. package/explorer/engine/proposal.js +28 -7
  11. package/explorer/engine/server-load.js +64 -0
  12. package/explorer/engine/sheets.js +4 -86
  13. package/explorer/engine/source-address.js +58 -0
  14. package/explorer/engine/source.js +16 -45
  15. package/explorer/engine/theme-sheet.js +23 -1
  16. package/explorer/engine/topology.js +1 -1
  17. package/explorer/focus-room.js +1 -7
  18. package/explorer/focusables.js +1 -1
  19. package/explorer/forge-panel.js +36 -2630
  20. package/explorer/index.html +15 -147
  21. package/explorer/instance-state.js +0 -7
  22. package/explorer/instance.js +19 -2
  23. package/explorer/layer-model.js +1 -1
  24. package/explorer/outage-model.js +6 -76
  25. package/explorer/outage-scenario.js +83 -0
  26. package/explorer/page-pieces.js +21 -2
  27. package/explorer/page.js +3 -3
  28. package/explorer/panels.js +1 -5
  29. package/explorer/pieces/layers.js +1 -0
  30. package/explorer/pieces/node-panel.js +19 -8
  31. package/explorer/pieces/proposal.js +9 -0
  32. package/explorer/pieces/review-source.js +84 -0
  33. package/explorer/pieces/review.js +145 -12
  34. package/explorer/pieces/scope.js +23 -54
  35. package/explorer/pieces/status.js +5 -1
  36. package/explorer/pieces/work-agent.js +211 -0
  37. package/explorer/pieces/work-common.js +88 -0
  38. package/explorer/pieces/work-confirm.js +169 -0
  39. package/explorer/pieces/work-data.js +178 -0
  40. package/explorer/pieces/work-deploys.js +104 -0
  41. package/explorer/pieces/work-events.js +285 -0
  42. package/explorer/pieces/work-issues.js +43 -0
  43. package/explorer/pieces/work-markup.js +155 -0
  44. package/explorer/pieces/work-notes.js +177 -0
  45. package/explorer/pieces/work-paint.js +312 -0
  46. package/explorer/pieces/work-prs.js +253 -0
  47. package/explorer/pieces/work-runs.js +387 -0
  48. package/explorer/pieces/work-specs.js +71 -0
  49. package/explorer/pieces/work-threads.js +309 -0
  50. package/explorer/pieces/work.js +285 -0
  51. package/explorer/proposal-marks.js +220 -0
  52. package/explorer/proposal-model.js +23 -211
  53. package/explorer/proposal.js +1 -2
  54. package/explorer/runs-map.js +108 -103
  55. package/explorer/runs-view.js +8 -6
  56. package/explorer/scenario.js +2 -1
  57. package/explorer/scene.js +2 -2
  58. package/explorer/selection-model.js +2 -42
  59. package/explorer/selection-view.js +1 -1
  60. package/explorer/selection-words.js +52 -0
  61. package/explorer/strings.js +1 -1
  62. package/explorer/verdict-paint.js +51 -0
  63. package/explorer/waiting-model.js +12 -12
  64. package/explorer/waiting-view.js +6 -6
  65. package/package.json +1 -1
  66. package/explorer/feedback.js +0 -15
  67. package/explorer/waiting-line.js +0 -14
@@ -16,88 +16,23 @@
16
16
  * after the map as it would be: what the proposal removes is hidden, no marks
17
17
  *
18
18
  * Switching the view never moves a node: all three draw the same positions.
19
+ *
20
+ * What a map draws with (the views, the marks, where an added node sits) is proposal-marks.js's, re-exported here: a map alone imports that
21
+ * module and does not carry the bar's, the panel's and the list's words below.
19
22
  */
20
23
 
21
24
  import { escapeHtml as escHtml } from '../core/text.js';
22
25
  import { markStateAttr, stateIconHtml } from './corn-state.js';
23
26
  import { specStateOf, specStateWords, SPEC_STATE_WORDS, SPEC_STATE_CORN } from './waiting-model.js';
27
+ import { hasMark, kindOfMark, showsNode, showsEdge, markIn, beforeOf, touchedIds, placeAddedNodes, orderAddedLast, pinLanes } from './proposal-marks.js';
28
+
29
+ export { kindOfMark, showsNode, showsEdge, markIn, beforeOf, touchedIds, placeAddedNodes, orderAddedLast, pinLanes };
24
30
 
25
31
  export const PROPOSAL_VIEWS = ['before', 'diff', 'after'];
26
32
 
27
33
  /** The marks a proposal puts on the map, in the order the counts chip and the legend list them */
28
34
  export const MARKS = ['added', 'changed', 'removed'];
29
35
 
30
- const hasMark = (item) => !!item && !!item.mark && item.mark !== 'none';
31
-
32
- /**
33
- * What a marked item IS, under the mark it is drawn with: a what-if `edit` (whatif-model.js) is drawn in violet
34
- * but is still an addition or a removal (`editOp`), and the views and the layout treat it as one.
35
- * @returns {'none'|'added'|'changed'|'removed'}
36
- */
37
- export const kindOfMark = (item) => (item.mark === 'edit' ? item.editOp || 'none' : item.mark || 'none');
38
-
39
- // ---------------------------------------------------------------------------
40
- // What each view shows
41
- // ---------------------------------------------------------------------------
42
-
43
- /** Is this node drawn in `view`? (`view` null = no proposal is open: everything is) */
44
- export function showsNode(view, node) {
45
- if (view === 'before') return kindOfMark(node) !== 'added';
46
- if (view === 'after') return kindOfMark(node) !== 'removed';
47
- return true;
48
- }
49
-
50
- /** Is this edge drawn in `view`? The same rule: Before hides what is added, After what is removed */
51
- export function showsEdge(view, edge) {
52
- return showsNode(view, edge);
53
- }
54
-
55
- /**
56
- * The mark a scene carries in `view`: the proposal's own in Diff and none in Before and After; a
57
- * what-if `edit` is the maintainer's own and shows in all three.
58
- * @returns {'none'|'added'|'changed'|'removed'|'edit'}
59
- */
60
- export function markIn(view, item) {
61
- const mark = item.mark || 'none';
62
- if (mark === 'edit') return 'edit';
63
- return view === 'diff' ? mark : 'none';
64
- }
65
-
66
- /**
67
- * A changed node or edge as it was before the proposal: each field in `before` is put back
68
- * (`null` there means the item did not have it, so it is dropped). Anything else comes back as it is.
69
- */
70
- export function beforeOf(item) {
71
- if (item.mark !== 'changed' || !item.before) return item;
72
- const out = { ...item };
73
- for (const [field, value] of Object.entries(item.before)) {
74
- if (value === null) delete out[field];
75
- else out[field] = value;
76
- }
77
- return out;
78
- }
79
-
80
- /**
81
- * Which nodes a proposal touches, for dimming and for fitting the camera.
82
- * - `touched`: nodes with a mark, and both ends of a marked edge: what Diff keeps bright
83
- * - `near`: `touched` and what they connect to, except the children a touched node owns (a touched
84
- * app would otherwise bring all its hundreds of pages): what the camera fits
85
- * @param {{id:string, mark?:string}[]} nodes
86
- * @param {{from:string, to:string, kind?:string, dashed?:boolean, mark?:string}[]} edges
87
- */
88
- export function touchedIds(nodes, edges) {
89
- const touched = new Set();
90
- for (const n of nodes) if (hasMark(n)) touched.add(n.id);
91
- for (const e of edges) if (hasMark(e)) { touched.add(e.from); touched.add(e.to); }
92
- const near = new Set(touched);
93
- for (const e of edges) {
94
- const owns = !e.kind && !e.dashed;
95
- if (touched.has(e.from) && !(owns && !touched.has(e.to))) near.add(e.to);
96
- if (touched.has(e.to)) near.add(e.from);
97
- }
98
- return { touched, near };
99
- }
100
-
101
36
  // ---------------------------------------------------------------------------
102
37
  // The counts chip, the legend, the address
103
38
  // ---------------------------------------------------------------------------
@@ -149,6 +84,22 @@ export const openedWords = (title, counts, view) => `Proposal ${title}: ${barCou
149
84
  export const jumpWords = (markWord, name) => `${name}, ${String(markWord).toLowerCase()}. The map is on it.`;
150
85
 
151
86
  const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
87
+ /** The longest name the server takes for a proposal (server/submit-review.js) */
88
+ const MAX_NAME = 200;
89
+
90
+ /**
91
+ * Whether `name` can be a proposal's name: a file name in the proposals folder (what the server's routes take), so it is one path segment and never
92
+ * `.` or `..`: it starts with a letter or a digit and holds only letters, digits, `.`, `_` and `-`. A name that is not one is never asked for.
93
+ * @param {unknown} name
94
+ */
95
+ export const isProposalName = (name) => typeof name === 'string' && name.length <= MAX_NAME && SLUG.test(name);
96
+
97
+ /** What to say of a value that was given as a proposal's name and is not one; shown as text, cut to 60 characters */
98
+ export function notANameWords(raw) {
99
+ const text = String(raw ?? '');
100
+ const shown = text.length > 60 ? `${text.slice(0, 59)}\u2026` : text;
101
+ return shown.trim() ? `\u201c${shown}\u201d is not a proposal's name.` : 'That is not a proposal\'s name.';
102
+ }
152
103
 
153
104
  /**
154
105
  * What `/?proposal=<slug>&source=<where>&proposalView=<view>` asks for, or null when it does not
@@ -385,8 +336,7 @@ export function malformedLinkWords(search) {
385
336
  if (!params.has('proposal')) return null;
386
337
  const raw = params.get('proposal') || '';
387
338
  if (SLUG.test(raw)) return null;
388
- const shown = raw.length > 60 ? `${raw.slice(0, 59)}\u2026` : raw;
389
- return shown.trim() ? `This link does not name a proposal: \u201c${shown}\u201d is not a proposal's name.` : 'This link does not name a proposal.';
339
+ return raw.trim() ? `This link does not name a proposal: ${notANameWords(raw)}` : 'This link does not name a proposal.';
390
340
  }
391
341
 
392
342
  /**
@@ -404,144 +354,6 @@ export function otherCopies(listing, slug, source) {
404
354
  .map((e) => ({ slug: e.slug, source: e.source, label: pullNumberOf(e.source) ? `Open the copy in PR #${pullNumberOf(e.source)}${e.pull && e.pull.draft ? ' (draft)' : ''}` : `Open the copy ${e.source === 'checkout' ? 'in the checkout' : `in worktree ${e.source}`}` }));
405
355
  }
406
356
 
407
- // ---------------------------------------------------------------------------
408
- // Where an added node sits
409
- // ---------------------------------------------------------------------------
410
-
411
- /** An ownership edge: a solid line with no kind (the parent → child link) */
412
- const isOwnership = (e) => !e.kind && !e.dashed;
413
-
414
- /**
415
- * Gives every node marked `added` a position, next to the node it hangs off: its parent when it has
416
- * one, else something it connects to, else a spot on a ring around the centre. Existing nodes never
417
- * move: the base layout is pinned, which is why the Before view and the Diff view show the same
418
- * picture. The spot is the first free one on widening rings around the anchor, starting on the side
419
- * facing away from the centre, where the map has room. Writes `x` and `y`; touches nothing else.
420
- * @param {{id:string, x:number, y:number, mark?:string}[]} nodes the applied nodes; the existing ones already have x and y
421
- * @param {{from:string, to:string, kind?:string, dashed?:boolean}[]} edges
422
- * @param {{gap?: number}} [opts] `gap`: the closest two nodes may sit (world units)
423
- */
424
- export function placeAddedNodes(nodes, edges, { gap = 74 } = {}) {
425
- const byId = new Map(nodes.map((n) => [n.id, n]));
426
- const placed = nodes.filter((n) => kindOfMark(n) !== 'added');
427
- const added = nodes.filter((n) => kindOfMark(n) === 'added');
428
- if (!added.length) return;
429
- const done = new Set(placed.map((n) => n.id));
430
-
431
- const anchorOf = (n) => {
432
- const own = edges.find((e) => isOwnership(e) && e.to === n.id && byId.has(e.from));
433
- if (own) return own.from;
434
- const other = edges.find((e) => (e.from === n.id && byId.has(e.to)) || (e.to === n.id && byId.has(e.from)));
435
- return other ? (other.from === n.id ? other.to : other.from) : null;
436
- };
437
-
438
- const free = (x, y) => placed.every((p) => Math.hypot(p.x - x, p.y - y) >= gap);
439
- const put = (n, ax, ay) => {
440
- const out = Math.atan2(ay, ax) || -Math.PI / 2; // away from the centre
441
- const base = ax === 0 && ay === 0 ? -Math.PI / 2 : out;
442
- let fallback = null;
443
- for (let r = 96; r <= 96 + 40 * 12; r += 40) {
444
- const steps = Math.max(8, Math.round((2 * Math.PI * r) / gap));
445
- for (let k = 0; k < steps; k++) {
446
- // 0, +1, -1, +2, -2 ... steps either side of the outward direction
447
- const turn = Math.ceil(k / 2) * (k % 2 ? 1 : -1) * ((2 * Math.PI) / steps);
448
- const x = ax + Math.cos(base + turn) * r;
449
- const y = ay + Math.sin(base + turn) * r;
450
- if (!fallback) fallback = { x, y };
451
- if (free(x, y)) { n.x = x; n.y = y; return; }
452
- }
453
- }
454
- n.x = fallback.x; n.y = fallback.y;
455
- };
456
-
457
- // Parents first: an added node can hang off another added node, in any order in the file
458
- let pending = added.slice();
459
- for (let pass = 0; pass <= added.length && pending.length; pass++) {
460
- const next = [];
461
- for (const n of pending) {
462
- const anchor = byId.get(anchorOf(n));
463
- if (anchor && done.has(anchor.id)) {
464
- put(n, anchor.x, anchor.y);
465
- placed.push(n);
466
- done.add(n.id);
467
- } else {
468
- next.push(n); // its anchor is another added node not placed yet, or it has none (settled below)
469
- }
470
- }
471
- if (next.length === pending.length) break;
472
- pending = next;
473
- }
474
- // No anchor, or an anchor that never got a place: a spot beside the centre
475
- for (const n of pending) {
476
- put(n, 0, 0);
477
- placed.push(n);
478
- }
479
- }
480
-
481
- /**
482
- * The data-flow lanes fill a column in order; an added node goes last in its column, so the nodes
483
- * that were there keep their rows. Reorders each tier's `nodes` in place, stably.
484
- * @param {{tiers: {nodes: {mark?:string}[]}[]}|null} flow `buildDataFlow` result
485
- */
486
- export function orderAddedLast(flow) {
487
- if (!flow) return;
488
- for (const tier of flow.tiers) {
489
- tier.nodes = [...tier.nodes.filter((n) => kindOfMark(n) !== 'added'), ...tier.nodes.filter((n) => kindOfMark(n) === 'added')];
490
- }
491
- }
492
-
493
- /** The distance between two rows of a lane (layout.js `LANE_ROW`) */
494
- const LANE_ROW = 50;
495
-
496
- /**
497
- * The data-flow lanes while a proposal is open: the base map's lane layout is pinned and the added
498
- * nodes take free cells of their lane, so no node that was there moves (laying the lanes out again
499
- * would re-flow a whole lane when one node more tips it into another row). An added node goes in the
500
- * free cells at the foot of its lane's last column, then in new rows below it; `flow.top` moves up
501
- * so the lane bands still cover them.
502
- *
503
- * Writes `x`, `y`, `r` of each existing node from `baseFlow`'s node of the same id, `x` and `y` of each
504
- * added one, and `flow.headers` / `flow.top`. `flow` is the applied map's flow (`buildDataFlow` over
505
- * the applied nodes, added nodes last in their tier), `baseFlow` the base map's, already laid out.
506
- * @param {{tiers: {key:string, nodes: object[]}[], headers?: object[], top?: number}} flow
507
- * @param {{tiers: {key:string, nodes: object[]}[], headers: object[], top: number}} baseFlow
508
- * @returns {boolean} false when the lanes cannot be pinned (a tier has nodes now that had none, so it has no column
509
- * to join): the caller lays the lanes out afresh
510
- */
511
- export function pinLanes(flow, baseFlow) {
512
- const baseTier = new Map(baseFlow.tiers.map((t) => [t.key, t]));
513
- if (flow.tiers.some((t) => t.nodes.length && !baseTier.get(t.key)?.nodes.length)) return false;
514
-
515
- // `headers` has one entry per tier that has nodes, in tier order
516
- const headerOf = new Map(baseFlow.tiers.filter((t) => t.nodes.length).map((t, i) => [t.key, baseFlow.headers[i]]));
517
- const was = new Map(baseFlow.tiers.flatMap((t) => t.nodes).map((n) => [n.id, n]));
518
- flow.headers = baseFlow.headers.map((h) => ({ ...h }));
519
- let top = baseFlow.top;
520
-
521
- for (const tier of flow.tiers) {
522
- if (!tier.nodes.length) continue;
523
- const kept = tier.nodes.filter((n) => was.has(n.id));
524
- const added = tier.nodes.filter((n) => !was.has(n.id));
525
- for (const n of kept) { const b = was.get(n.id); n.x = b.x; n.y = b.y; n.r = b.r; }
526
- if (!added.length) continue;
527
-
528
- const rows = headerOf.get(tier.key).rows;
529
- const lastX = Math.max(...kept.map((n) => n.x));
530
- const rowY = (k) => (k - (rows - 1) / 2) * LANE_ROW;
531
- const taken = new Set(kept.filter((n) => n.x === lastX).map((n) => Math.round(n.y)));
532
- let k = 0;
533
- for (const n of added) {
534
- while (taken.has(Math.round(rowY(k)))) k++;
535
- n.x = lastX;
536
- n.y = rowY(k);
537
- taken.add(Math.round(n.y));
538
- top = Math.min(top, -(n.y + 40)); // the bands run from `top` down to `-top + 40`
539
- }
540
- }
541
- flow.top = top;
542
- return true;
543
- }
544
-
545
357
  /**
546
358
  * The reviewer's own what-if edits, counted apart from the proposal's (spec 0007 D5): "yours: +1 node, 1 step changed". Never added to the proposal's
547
359
  * numbers, so the reviewer can still tell what the agent proposed. Empty for no edits.
@@ -9,7 +9,7 @@
9
9
  * as a listener of the instance (one registration per hook: assigning again takes the last one back), so a chain that wraps `hooks.bar` still works:
10
10
  *
11
11
  * hooks.effective -> ask proposal:effective hooks.mark -> event proposal:mark hooks.beforeClose -> ask proposal:before-close
12
- * hooks.closed -> event proposal {closed} hooks.bar -> event proposal:bar hooks.openSpecs -> ask work:open-specs
12
+ * hooks.closed -> event proposal {closed} hooks.bar -> event proposal:bar
13
13
  * hooks.reviewed -> event decision
14
14
  */
15
15
 
@@ -30,7 +30,6 @@ const ADAPT = {
30
30
  beforeClose: (fn) => ['proposal:before-close', () => fn()],
31
31
  closed: (fn) => ['proposal', ({ change }) => { if (change === 'closed') fn(); }],
32
32
  bar: (fn) => ['proposal:bar', ({ open }) => { fn(open); }],
33
- openSpecs: (fn) => ['work:open-specs', () => { fn(); return true; }],
34
33
  reviewed: (fn) => ['decision', ({ open }) => { if (open !== false) fn(); }], // as before: not when another proposal was opened while it was sent
35
34
  };
36
35
  const kept = {};
@@ -13,11 +13,8 @@
13
13
  * state or a collision changes. The positions come from the scene the map just drew, so they follow every view, zoom and pan.
14
14
  */
15
15
 
16
- import { state } from './state.js';
17
16
  import { layerOn } from './layer-model.js';
18
- import { render, onPaint } from './render.js';
19
17
  import { overlayOf } from './runs-model.js';
20
- import { flowReduceMotion } from './flows.js';
21
18
 
22
19
  /** The most marks drawn at once: past this the Runs view still lists them all */
23
20
  export const MAX_MARKS = 80;
@@ -25,113 +22,121 @@ export const MAX_MARKS = 80;
25
22
  /** The key of the layer in the Layers menu and `state.activeLayers` */
26
23
  export const RUNS_LAYER = 'runs';
27
24
 
28
- /** @type {Map<string, HTMLElement>} the marks on the page by `<kind>:<node id>`, kept so a pulse is not restarted by every pan */
29
- const marks = new Map();
30
- let wired = false;
31
- /** What the marks were last placed for: a paint with the same scene, camera, runs, layer and motion moves nothing (packet frames) */
32
- let placed = '';
33
- let placedFor = null;
34
- let placedScene = null;
35
- let placedLayer = null;
36
- let reduce = null;
37
-
38
- /** Whether motion is reduced: the page's setting, or a test's */
39
- const reducedMotion = () => (reduce === null ? flowReduceMotion : reduce);
40
- /** For tests: force reduced motion on or off (null: follow the page's setting) */
41
- export function setReducedMotionForTests(on) { reduce = on; }
42
-
43
- /** Whether the layer is on */
44
- export const runsLayerOn = () => layerOn(state, RUNS_LAYER); // the viewer's layer, or the review's (layer-model.js)
45
-
46
- /** Hands the map the runs the API listed: what pulses and what collides is worked out here, and the map is drawn again */
47
- export function setRunsOnMap(runs) {
48
- state.runsMap = Array.isArray(runs) && runs.length ? { ...overlayOf(runs), runs } : null;
49
- wire();
50
- paintLegend();
51
- render();
52
- }
53
-
54
- /** Takes the marks off (the panel is reset, or there is no forge) */
55
- export function clearRunsOnMap() {
56
- state.runsMap = null;
57
- clearMarks();
58
- paintLegend();
59
- }
60
-
61
- function wire() {
62
- if (wired) return;
63
- wired = true;
64
- onPaint((scene, camera) => syncRunOverlay(scene, camera));
65
- }
66
-
67
- function clearMarks() {
68
- for (const el of marks.values()) el.remove();
69
- marks.clear();
70
- placed = '';
71
- }
72
-
73
25
  /** The words on a collision mark */
74
26
  export const collisionTag = (n) => `Collision · ${n} runs`;
75
27
 
76
28
  /**
77
- * Puts the marks on the nodes the scene drew, at the camera. Marks are kept between frames (only their place changes), so a pan does not
78
- * restart the pulse.
79
- * @param {{ nodes: { id: string, x: number, y: number, r: number, alpha: number }[] }} scene
80
- * @param {{ x: number, y: number, zoom: number }} camera
29
+ * The runs' marks for one instance (spec 0011 D3): what the Work piece hands the map. Nothing here is shared with another instance.
30
+ * @param {ReturnType<import('./instance.js').createInstance>} inst
81
31
  */
82
- export function syncRunOverlay(scene, camera) {
83
- const layer = typeof document !== 'undefined' ? document.getElementById('run-overlay') : null;
84
- if (!layer) return;
85
- const map = state.runsMap;
86
- if (!map || !runsLayerOn() || (!map.flight.size && !map.collide.size)) { if (marks.size) clearMarks(); layer.hidden = true; placed = ''; return; }
87
- // The map paints every frame while packets move; the marks only move with the scene or the camera
88
- const key = `${scene.version}|${camera.x}|${camera.y}|${camera.zoom}|${reducedMotion()}`;
89
- if (key === placed && placedFor === map && placedScene === scene && placedLayer === layer) return;
90
- placed = key;
91
- placedLayer = layer;
92
- placedFor = map;
93
- placedScene = scene;
94
- layer.hidden = false;
95
- layer.classList.toggle('is-static', reducedMotion());
96
- const seen = new Set();
97
- let n = 0;
98
- for (const node of scene.nodes) {
99
- if (n >= MAX_MARKS) break;
100
- const runs = map.collide.get(node.id) || map.flight.get(node.id);
101
- if (!runs || !(node.alpha > 0.2)) continue;
102
- const kind = map.collide.has(node.id) ? 'collision' : 'flight';
103
- const key = `${kind}:${node.id}`;
104
- n += 1;
105
- seen.add(key);
106
- let el = marks.get(key);
107
- if (!el) {
108
- el = document.createElement('span');
109
- el.className = `hx-run-mark hx-run-mark--${kind}`;
110
- el.dataset.node = node.id;
111
- el.dataset.kind = kind;
112
- el.dataset.corn = 'run-mark';
113
- el.innerHTML = `<span class="hx-run-ring"></span>${kind === 'collision' ? `<span class="hx-run-tag"><span class="hx-run-sign">⚠</span> ${collisionTag(runs.length)}</span>` : ''}`;
114
- layer.append(el);
115
- marks.set(key, el);
32
+ export function createRunsMap(inst) {
33
+ const { state } = inst;
34
+ /** @type {Map<string, HTMLElement>} the marks by `<kind>:<node id>`, kept so a pulse is not restarted by every pan */
35
+ const marks = new Map();
36
+ /** What the marks were last placed for: a paint with the same scene, camera, runs, layer and motion moves nothing (packet frames) */
37
+ let placed = '';
38
+ let placedFor = null;
39
+ let placedScene = null;
40
+ let placedLayer = null;
41
+ let reduce = null;
42
+ /** The map's paint hook while the marks follow it */
43
+ let offPaint = null;
44
+
45
+ /** Whether motion is reduced: the viewer's setting, or a test's */
46
+ const reducedMotion = () => (reduce === null ? inst.reducedMotion : reduce);
47
+ /** Whether the layer is on: the viewer's layer, or the review's (layer-model.js) */
48
+ const runsLayerOn = () => layerOn(state, RUNS_LAYER);
49
+
50
+ function clearMarks() {
51
+ for (const el of marks.values()) el.remove();
52
+ marks.clear();
53
+ placed = '';
54
+ }
55
+
56
+ /** Says whether any run is on the map: the Layers menu shows its legend while there is */
57
+ function paintLegend() {
58
+ inst.emit('runs:map', { active: !!(state.runsMap && (state.runsMap.flight.size || state.runsMap.collide.size)) });
59
+ }
60
+
61
+ /**
62
+ * Puts the marks on the nodes the scene drew, at the camera. Marks are kept between frames (only their place changes), so a pan does not
63
+ * restart the pulse.
64
+ * @param {{ nodes: { id: string, x: number, y: number, r: number, alpha: number }[], version?: number }} scene
65
+ * @param {{ x: number, y: number, zoom: number }} camera
66
+ */
67
+ function sync(scene, camera) {
68
+ const layer = inst.el('run-overlay');
69
+ if (!layer) return;
70
+ const map = state.runsMap;
71
+ if (!map || !runsLayerOn() || (!map.flight.size && !map.collide.size)) { if (marks.size) clearMarks(); layer.hidden = true; placed = ''; return; }
72
+ // The map paints every frame while packets move; the marks only move with the scene or the camera
73
+ const key = `${scene.version}|${camera.x}|${camera.y}|${camera.zoom}|${reducedMotion()}`;
74
+ if (key === placed && placedFor === map && placedScene === scene && placedLayer === layer) return;
75
+ placed = key;
76
+ placedLayer = layer;
77
+ placedFor = map;
78
+ placedScene = scene;
79
+ layer.hidden = false;
80
+ layer.classList.toggle('is-static', reducedMotion());
81
+ const seen = new Set();
82
+ let n = 0;
83
+ for (const node of scene.nodes) {
84
+ if (n >= MAX_MARKS) break;
85
+ const runs = map.collide.get(node.id) || map.flight.get(node.id);
86
+ if (!runs || !(node.alpha > 0.2)) continue;
87
+ const kind = map.collide.has(node.id) ? 'collision' : 'flight';
88
+ const key = `${kind}:${node.id}`;
89
+ n += 1;
90
+ seen.add(key);
91
+ let el = marks.get(key);
92
+ if (!el) {
93
+ el = inst.doc.createElement('span');
94
+ el.className = `hx-run-mark hx-run-mark--${kind}`;
95
+ el.dataset.node = node.id;
96
+ el.dataset.kind = kind;
97
+ el.dataset.corn = 'run-mark';
98
+ el.setAttribute('part', 'run-mark');
99
+ el.innerHTML = `<span class="hx-run-ring"></span>${kind === 'collision' ? `<span class="hx-run-tag"><span class="hx-run-sign">⚠</span> ${collisionTag(runs.length)}</span>` : ''}`;
100
+ layer.append(el);
101
+ marks.set(key, el);
102
+ }
103
+ const r = Math.max(10, (node.r + 9) * camera.zoom);
104
+ el.style.left = `${(node.x * camera.zoom + camera.x).toFixed(1)}px`;
105
+ el.style.top = `${(node.y * camera.zoom + camera.y).toFixed(1)}px`;
106
+ el.style.setProperty('--r', `${r.toFixed(1)}px`);
116
107
  }
117
- const r = Math.max(10, (node.r + 9) * camera.zoom);
118
- el.style.left = `${(node.x * camera.zoom + camera.x).toFixed(1)}px`;
119
- el.style.top = `${(node.y * camera.zoom + camera.y).toFixed(1)}px`;
120
- el.style.setProperty('--r', `${r.toFixed(1)}px`);
108
+ for (const [key, el] of marks) if (!seen.has(key)) { el.remove(); marks.delete(key); }
121
109
  }
122
- for (const [key, el] of marks) if (!seen.has(key)) { el.remove(); marks.delete(key); }
123
- }
124
110
 
125
- /** The legend in the Layers menu: shown while runs are on the map, saying in words what each mark is */
126
- export function paintLegend() {
127
- const el = typeof document !== 'undefined' ? document.getElementById('runs-legend') : null;
128
- if (!el) return;
129
- el.hidden = !(state.runsMap && (state.runsMap.flight.size || state.runsMap.collide.size));
130
- }
111
+ function clear() {
112
+ state.runsMap = null;
113
+ clearMarks();
114
+ paintLegend();
115
+ }
116
+
117
+ /** Follows the map's paints: once, while the instance has a map (a bare root has none, and no marks) */
118
+ function wire() {
119
+ if (offPaint || !inst.map) return;
120
+ offPaint = inst.own(inst.map.onPaint((scene, camera) => sync(scene, camera)));
121
+ }
131
122
 
132
- /** For tests: forget the page */
133
- export function resetRunsMapForTests() {
134
- clearMarks();
135
- state.runsMap = null;
136
- reduce = null;
123
+ return {
124
+ /** Hands the map the runs the API listed: what pulses and what collides is worked out here, and the map is drawn again */
125
+ set(runs) {
126
+ state.runsMap = Array.isArray(runs) && runs.length ? { ...overlayOf(runs), runs } : null;
127
+ wire();
128
+ paintLegend();
129
+ if (inst.map) inst.map.render();
130
+ },
131
+ /** Takes the marks off (the panel ends, or there is no forge) */
132
+ clear,
133
+ /** Takes the marks off and stops following the map's paints: the piece that made this ends before the instance (a second one may follow) */
134
+ destroy() {
135
+ if (offPaint) { offPaint(); inst.release(offPaint); offPaint = null; }
136
+ clear();
137
+ },
138
+ sync,
139
+ /** For tests: force reduced motion on or off (null: follow the viewer's setting) */
140
+ setReducedMotion(on) { reduce = on; },
141
+ };
137
142
  }
@@ -92,15 +92,16 @@ function resultHtml(ctx, run) {
92
92
 
93
93
  /** A waiting run: what was asked (the note and link are shown above) and the three answers, plain buttons and a reply field */
94
94
  function answerHtml(ctx, run) {
95
+ const say = ctx.t || t; // the words of the instance that draws it (the Work piece hands its own), else the page's
95
96
  const id = ctx.esc(run.runId);
96
97
  const name = ctx.esc(runName(run, ctx.now));
97
98
  const off = ctx.busy ? ' disabled' : '';
98
99
  const reply = ctx.replies && ctx.replies.get(run.runId) || '';
99
100
  return `${run.answer ? answeredHtml(ctx, run) : ''}<div class="hx-run-actions" data-corn="run-actions" role="group" aria-label="Answer: ${name}">
100
- <button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="${ctx.esc(t('continueRun'))}: ${name}"${off}>${ctx.esc(t('continueRun'))}</button>
101
- <button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="${ctx.esc(t('stop'))}: ${name}"${off} data-corn-kind="danger">${ctx.esc(t('stop'))}</button></div>
101
+ <button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-answer="continue" data-run-id="${id}" aria-label="${ctx.esc(say('continueRun'))}: ${name}"${off}>${ctx.esc(say('continueRun'))}</button>
102
+ <button type="button" class="hx-btn hx-forge-act" data-run-answer="stop" data-run-id="${id}" aria-label="${ctx.esc(say('stop'))}: ${name}"${off} data-corn-kind="danger">${ctx.esc(say('stop'))}</button></div>
102
103
  <label class="hx-forge-field" data-corn="field">Reply to ${ctx.esc(`${run.kind} on ${aboutWords(run.refs)}`)}<input data-corn="control" type="text" class="hx-forge-input" data-run-reply="${id}" value="${ctx.esc(reply)}" maxlength="4000" autocomplete="off" /></label>
103
- <div class="hx-run-actions" data-corn="run-actions"><button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-answer="reply" data-run-id="${id}" aria-label="${ctx.esc(t('reply'))}: ${name}"${off}>${ctx.esc(t('reply'))}</button></div>`;
104
+ <div class="hx-run-actions" data-corn="run-actions"><button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-run-answer="reply" data-run-id="${id}" aria-label="${ctx.esc(say('reply'))}: ${name}"${off}>${ctx.esc(say('reply'))}</button></div>`;
104
105
  }
105
106
 
106
107
  /**
@@ -141,6 +142,7 @@ export function loadingLinesHtml(n = 1) {
141
142
 
142
143
  /** One run */
143
144
  export function runHtml(ctx, run, all) {
145
+ const say = ctx.t || t;
144
146
  const lit = ctx.selected === run.runId;
145
147
  const open = ctx.timelines.has(run.runId);
146
148
  const why = statusWhy(run);
@@ -148,8 +150,8 @@ export function runHtml(ctx, run, all) {
148
150
  const note = run.report && run.report.note ? `<p class="hx-forge-meta">Runner: ${ctx.esc(run.report.note)}</p>` : '';
149
151
  const answering = canAnswer(run);
150
152
  const off = ctx.busy ? ' disabled' : '';
151
- const retry = canRetry(run) ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="${ctx.esc(t('startAgain'))}: ${name}"${off}>${ctx.esc(t('startAgain'))}</button>` : '';
152
- const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="${ctx.esc(t('stop'))}: ${name}"${off} data-corn-kind="danger">${ctx.esc(t('stop'))}</button>` : '';
153
+ const retry = canRetry(run) ? `<button data-corn-kind="secondary" type="button" class="hx-btn hx-forge-act" data-forge-retry="${ctx.esc(run.runId)}" aria-label="${ctx.esc(say('startAgain'))}: ${name}"${off}>${ctx.esc(say('startAgain'))}</button>` : '';
154
+ const stop = canStop(run) && !answering ? `<button type="button" class="hx-btn hx-forge-act" data-forge-stop="${ctx.esc(run.runId)}" aria-label="${ctx.esc(say('stop'))}: ${name}"${off} data-corn-kind="danger">${ctx.esc(say('stop'))}</button>` : '';
153
155
  const names = nodeLabels(run.nodes, ctx.nodes);
154
156
  const collision = collisionWords(run, all, ctx.nodes);
155
157
  const limits = limitRows(run);
@@ -182,7 +184,7 @@ export function runHtml(ctx, run, all) {
182
184
  * @param {object[]} runs
183
185
  */
184
186
  export function runsHtml(ctx, runs) {
185
- return runGroups(runs).map((group) => runGroupHeadingHtml(group) + group.items.map((g) => {
187
+ return runGroups(runs).map((group) => runGroupHeadingHtml(group, ctx.t) + group.items.map((g) => {
186
188
  if (g.kind === 'run') return runHtml(ctx, g.run, runs);
187
189
  const id = `cmp-${g.runs[0].runId}`;
188
190
  return `<li class="hx-run-group" data-key="${ctx.esc(id)}"><section class="hx-run-compare" aria-labelledby="${ctx.esc(id)}">
@@ -52,7 +52,8 @@
52
52
  */
53
53
 
54
54
  import { edgeKey } from '../core/proposal.js';
55
- import { frameNodes, allInside, READ_ZOOM, ZOOM_MIN } from './camera.js';
55
+ import { frameNodes, ZOOM_MIN } from './camera.js';
56
+ import { allInside, READ_ZOOM } from './camera-frame.js';
56
57
 
57
58
  export const DEFAULT_STEP_MS = 5000;
58
59
  /** Where the viewer's speed is kept (localStorage); scenario-ui.js reads and writes it */
package/explorer/scene.js CHANGED
@@ -168,9 +168,9 @@
168
168
  */
169
169
 
170
170
  import { flowStyleOf } from './flow-style.js';
171
- import { beforeOf, markIn, showsEdge, showsNode, touchedIds } from './proposal-model.js';
171
+ import { beforeOf, markIn, showsEdge, showsNode, touchedIds } from './proposal-marks.js';
172
172
  import { decorateHouseScene, houseEdgeStyle, houseShowsNode, houseViewEdges } from './house-model.js';
173
- import { paintVerdict } from './check-model.js';
173
+ import { paintVerdict } from './verdict-paint.js';
174
174
  import { externalLayer, whenTicks } from './cloud-model.js';
175
175
  import { greying, lettersOf, projectLayerKey, shownByProposal, layersOf } from './layer-model.js';
176
176
  import { NODE_THEMES, shapeOf } from '../core/schema.js';