cornfield 0.34.1 → 0.34.3

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.
@@ -28,7 +28,7 @@ import { expandSheet, isPhone } from './sheets.js';
28
28
  import { hooks } from './proposal.js';
29
29
  import { refreshMockups } from './mockups.js';
30
30
  import { getEdits, clearEdits } from './whatif.js';
31
- import { reviewWords, sendBackProblem, reviewBody, editsHint, isReviewable, NOT_ON_A_PR } from './review-model.js';
31
+ import { reviewParts, sendBackProblem, reviewBody, editsHint, isReviewable, NOT_ON_A_PR } from './review-model.js';
32
32
  import { t } from './strings.js';
33
33
 
34
34
  const $ = (id) => document.getElementById(id);
@@ -69,7 +69,7 @@ function mount() {
69
69
  root.className = 'hx-review';
70
70
  root.dataset.corn = 'review-bar';
71
71
  root.innerHTML = `
72
- <p class="hx-review-status" data-review-status role="status" hidden></p>
72
+ <p class="hx-review-status" data-review-status hidden><span data-review-verdict role="status"></span><span data-review-when></span></p>
73
73
  <div class="hx-review-form" id="review-form" data-review-form hidden>
74
74
  <label class="hx-review-label" for="review-note"></label>
75
75
  <textarea id="review-note" class="hx-review-note" rows="2" maxlength="20000"></textarea>
@@ -78,7 +78,7 @@ function mount() {
78
78
  </div>
79
79
  </div>
80
80
  <p class="hx-review-msg" data-review-msg role="alert" hidden></p>
81
- <p class="hx-review-line" data-review-hint role="status" hidden></p>
81
+ <p class="hx-review-line" id="review-hint" data-review-hint role="status" hidden></p>
82
82
  `;
83
83
  // The words are set as text and attributes, never parsed as HTML (a brand's `strings`, explorer/strings.js)
84
84
  q('.hx-review-label').textContent = t('reviewNoteLabel');
@@ -96,10 +96,20 @@ function mount() {
96
96
  /** Everything the review shows, from `ui` */
97
97
  function paint() {
98
98
  if (!root) return;
99
+ // Only the verdict is a live region, written when it changes: the time beside it ticks every TICK_MS and is never said again
99
100
  const status = q('[data-review-status]');
100
- status.textContent = reviewWords(ui.review, now());
101
- status.hidden = !status.textContent;
102
- for (const btn of document.querySelectorAll('#proposal-bar [data-review]')) btn.disabled = ui.busy || !ui.reviewable;
101
+ const { verdict, when } = reviewParts(ui.review, now());
102
+ const said = q('[data-review-verdict]');
103
+ if (said.textContent !== verdict) said.textContent = verdict;
104
+ q('[data-review-when]').textContent = when ? ` ${when}` : '';
105
+ status.hidden = !verdict;
106
+ // Off for good (not a spec PR's copy) is `disabled`, and the reason is the line next to it, which the buttons point at. While a review is being posted the button
107
+ // only says it is busy (`aria-disabled`): a `disabled` button drops the focus to the page.
108
+ for (const btn of document.querySelectorAll('#proposal-bar [data-review]')) {
109
+ btn.disabled = !ui.reviewable;
110
+ if (ui.busy) btn.setAttribute('aria-disabled', 'true'); else btn.removeAttribute('aria-disabled');
111
+ if (!ui.reviewable && ui.key) btn.setAttribute('aria-describedby', 'review-hint'); else btn.removeAttribute('aria-describedby');
112
+ }
103
113
  const approve = button('approved');
104
114
  if (approve) approve.textContent = t('approve');
105
115
  const sendBack = button('notes');
@@ -125,6 +135,9 @@ function openNote() {
125
135
  paint();
126
136
  if (isPhone()) expandSheet('proposal');
127
137
  q('#review-note').focus();
138
+ // On a phone the keyboard is about to take half the screen: the note and the button that sends it stay in view above it
139
+ const send = button('notes');
140
+ if (isPhone() && send && typeof send.scrollIntoView === 'function') send.scrollIntoView({ block: 'nearest' });
128
141
  }
129
142
 
130
143
  /** Cancel: the field closes, what was typed goes, and focus goes back to Send back */
@@ -223,7 +236,11 @@ export async function sendReview(verdict) {
223
236
  const wasNoting = ui.noting;
224
237
  ui.noting = false;
225
238
  paint();
226
- if (wasNoting && verdict === 'notes') { const sendBack = button('notes'); if (sendBack) sendBack.focus(); }
239
+ // The buttons were busy while it posted, not `disabled`, so the focus stayed where it was. Approve keeps it (the status line, a live region,
240
+ // says "Approved" once; moving the focus onto it would say it twice); when it was lost it goes back to Approve. Send back: the button that opened the note.
241
+ const lost = !document.activeElement || document.activeElement === document.body || !document.activeElement.isConnected;
242
+ if (verdict === 'approved') { if (lost) button('approved')?.focus(); }
243
+ else if (wasNoting || lost) button('notes')?.focus();
227
244
  refreshMockups(); // an approval covers the screens as they are now; a send back leaves them not reviewed
228
245
  if (verdict === 'notes') clearEdits(); // the edits went with the note; an approval keeps them, they are in the review
229
246
  return true;
@@ -24,14 +24,15 @@
24
24
  */
25
25
 
26
26
  import { state, touchScene, onSceneTouch } from './state.js';
27
- import { render, ensureFlowLoop, addFrameClient, isNodeVisible } from './render.js';
27
+ import { render, ensureFlowLoop, addFrameClient, isNodeVisible, getMinZoom } from './render.js';
28
28
  import { flowReduceMotion } from './flows.js';
29
- import { registerSheet, unregisterSheet, collapseAllSheets, measureCovered, onCoveredChange } from './sheets.js';
29
+ import { registerSheet, unregisterSheet, collapseAllSheets, visibleMapRect, onCoveredChange } from './sheets.js';
30
30
  import { createPlayer, cameraFor, parseSpeed, SPEED_CHOICES, SPEED_KEY } from './scenario.js';
31
31
  import { edgeKey } from '../core/proposal.js';
32
32
  import { checksVersion, closeChecks, decorateSnapshot, openChecks, paintChecks } from './check.js';
33
33
  import { blastRadius, outageLayers, outageScenario } from './outage-model.js';
34
34
  import { toggleLayer } from './layers.js';
35
+ import { announce } from './keyboard.js';
35
36
 
36
37
  /** A frame that arrives later than this (a tab that was hidden) counts as this long */
37
38
  const MAX_FRAME_MS = 250;
@@ -58,7 +59,10 @@ const $stage = () => (state.canvas ? state.canvas.parentElement : null);
58
59
  * @returns {ReturnType<typeof createPlayer>} the player, for a caller that wants to drive it
59
60
  */
60
61
  export function playScenario(scenario, opts = {}) {
62
+ const opener = openerOf();
63
+ const takeFocus = isKeyboardish(); // checked now: the list row that was pressed goes with the list
61
64
  clearScenario();
65
+ returnTo = opener;
62
66
  const speed = opts.stepMs ?? readSpeed();
63
67
  player = createPlayer(scenario, { stepMs: speed, maxFrameMs: MAX_FRAME_MS });
64
68
  showBar(speed);
@@ -68,9 +72,43 @@ export function playScenario(scenario, opts = {}) {
68
72
  sync(true);
69
73
  render();
70
74
  ensureFlowLoop();
75
+ // Whatever started it (a row of the list, which goes) is gone: focus goes to the player's play and pause button, the first control of what opened
76
+ if (opts.focus !== false && bar && takeFocus) {
77
+ const toggle = bar.querySelector('[data-action=scenario-toggle]');
78
+ if (toggle && !toggle.disabled) toggle.focus(); else bar.querySelector('[data-action=scenario-next]')?.focus();
79
+ }
71
80
  return player;
72
81
  }
73
82
 
83
+ /** What had the focus when a scenario started, to give it back when the scenario closes: the toolbar's Play button when the start came from it or its list */
84
+ let returnTo = null;
85
+ function openerOf() {
86
+ const active = document.activeElement;
87
+ const play = document.getElementById('proposal-play');
88
+ if (active && active !== document.body && (active === play || active.closest?.('#proposal-scenarios'))) return play;
89
+ if (active && active !== document.body && !active.closest?.('.hx-player') && active !== state.canvas) return active;
90
+ return null;
91
+ }
92
+
93
+ /** Whether the focus is on the page's controls (not on nothing, and not in a field): a scenario started by a script from outside takes none */
94
+ function isKeyboardish() {
95
+ const active = document.activeElement;
96
+ return !!active && active !== document.body && !typingIn(active);
97
+ }
98
+
99
+ /** Closing the player by the viewer's own act: the focus goes back to what started it (Play), else to Play, else to the map (on a phone Play is folded away in the peek) */
100
+ function giveFocusBack() {
101
+ const to = returnTo;
102
+ returnTo = null;
103
+ const took = (el) => {
104
+ if (!el || !el.isConnected || el.hidden || el.disabled || el.closest('[hidden]')) return false;
105
+ el.focus();
106
+ return document.activeElement === el; // a control the stylesheet hides takes no focus
107
+ };
108
+ if (took(to) || took(document.getElementById('proposal-play'))) return;
109
+ took(state.canvas);
110
+ }
111
+
74
112
  /**
75
113
  * An outage scenario (spec 0031 section 8) turns on the layers its blast radius is drawn on (containers and
76
114
  * machines start off), as a scenario that names a persona turns the People layer on (check.js).
@@ -105,9 +143,12 @@ export function clearScenario() {
105
143
  /** Ends the scenario and redraws the map without it */
106
144
  export function stopScenario() {
107
145
  if (!player && !state.scenario) return;
146
+ const hadFocus = !!bar && bar.contains(document.activeElement);
108
147
  clearScenario();
109
148
  touchScene();
110
149
  render();
150
+ if (hadFocus || document.activeElement === document.body) giveFocusBack(); // focus was in the player, which is gone
151
+ else returnTo = null;
111
152
  }
112
153
 
113
154
  /** Brings `state.scenario` up to date with the player; when a step, the play state or the step start moved, rebuilds the scene and follows the step with the camera */
@@ -133,13 +174,11 @@ function sync(force = false) {
133
174
  function followStep(snap) {
134
175
  const visible = new Map();
135
176
  state.nodes.forEach((n) => { if (isNodeVisible(n)) visible.set(n.id, n); });
136
- // The bar covers the bottom of the map: a step behind it is as good as off screen. On a phone the sheets
137
- // (the dock) cover it; the rest of the time it is the bar alone.
138
- const sheets = measureCovered();
139
- const covered = sheets > 0 ? sheets + 16 : bar ? bar.offsetHeight + 24 : 0;
140
- const target = cameraFor({ node: snap.current.node, edge: snap.current.edge, at: snap.current.at, text: snap.current.text }, state.camera, { width: state.width, height: Math.max(120, state.height - covered) }, visible);
177
+ // The step must be in the part of the map nothing covers: not under the proposal bar, the node panel, the player or (on a phone) the sheets
178
+ const rect = visibleMapRect();
179
+ const target = cameraFor({ node: snap.current.node, edge: snap.current.edge, at: snap.current.at, text: snap.current.text }, state.camera, rect, visible, 60, getMinZoom());
141
180
  if (!target) return;
142
- if (flowReduceMotion) { Object.assign(state.camera, target); glide = null; return; }
181
+ if (flowReduceMotion) { Object.assign(state.camera, target); glide = null; render(); return; } // reduced motion: jump, do not fly
143
182
  glide = { to: target, last: null };
144
183
  ensureFlowLoop();
145
184
  }
@@ -191,9 +230,9 @@ function showBar(speed) {
191
230
  </div>
192
231
  <p class="hx-player-text" aria-live="polite"><span class="hx-player-count"></span> · <span class="hx-player-step"></span></p>
193
232
  <div class="hx-player-controls">
194
- <button type="button" class="hx-btn" data-action="scenario-prev">◀ Previous</button>
195
- <button type="button" class="hx-btn hx-btn--active" data-action="scenario-toggle" data-corn-kind="primary"></button>
196
- <button type="button" class="hx-btn" data-action="scenario-next">Next ▶</button>
233
+ <button type="button" class="hx-btn" data-action="scenario-prev" data-peek-ok>◀ Previous</button>
234
+ <button type="button" class="hx-btn hx-btn--active" data-action="scenario-toggle" data-peek-ok data-corn-kind="primary"></button>
235
+ <button type="button" class="hx-btn" data-action="scenario-next" data-peek-ok>Next ▶</button>
197
236
  </div>
198
237
  <div class="hx-player-track" aria-hidden="true"><span class="hx-player-fill"></span></div>`;
199
238
  bar.addEventListener('click', (e) => {
@@ -234,6 +273,7 @@ function act(action) {
234
273
  if (action === 'scenario-toggle') {
235
274
  const s = player.snapshot();
236
275
  if (s.playing) player.pause(); else player.play();
276
+ announce(s.playing ? 'Paused' : s.done ? 'Playing again' : s.index > 0 || s.progress > 0 ? 'Resumed' : 'Playing');
237
277
  } else if (action === 'scenario-prev') player.prev();
238
278
  else if (action === 'scenario-next') player.next();
239
279
  else return;
@@ -246,9 +286,11 @@ let lastFill = -1;
246
286
  function updateBar(snap) {
247
287
  if (!bar) return;
248
288
  const q = (cls) => bar.querySelector(cls);
249
- q('.hx-player-title').textContent = snap.title;
250
- q('.hx-player-count').textContent = `${Math.min(snap.index + 1, Math.max(snap.total, 1))} of ${snap.total}`;
251
- q('.hx-player-step').textContent = snap.current.text;
289
+ // this runs every frame: a live region is written only when its words change, so a step is said once, not once a frame
290
+ const put = (cls, text) => { const el = q(cls); if (el.textContent !== text) el.textContent = text; };
291
+ put('.hx-player-title', snap.title);
292
+ put('.hx-player-count', `${Math.min(snap.index + 1, Math.max(snap.total, 1))} of ${snap.total}`);
293
+ put('.hx-player-step', snap.current.text);
252
294
  const toggle = q('[data-action=scenario-toggle]');
253
295
  toggle.textContent = snap.playing ? 'Pause' : snap.done ? 'Play again' : 'Play';
254
296
  toggle.disabled = snap.total === 0 || snap.manual;
@@ -270,6 +312,10 @@ function typingIn(target) {
270
312
  }
271
313
 
272
314
  function onKeydown(e) {
315
+ if (e.key === 'Escape' && !e.defaultPrevented && !e.ctrlKey && !e.metaKey && !e.altKey) {
316
+ if (player && !typingIn(e.target) && !otherPopupOpen()) { e.preventDefault(); stopScenario(); return; } // Escape closes the scenario; focus goes back to Play
317
+ if (!player && list && !list.hidden && list.contains(document.activeElement)) { e.preventDefault(); closeList(true); return; }
318
+ }
273
319
  if (!player || e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || typingIn(e.target)) return;
274
320
  const action = e.key === ' ' || e.code === 'Space' ? 'scenario-toggle' : e.key === 'ArrowLeft' ? 'scenario-prev' : e.key === 'ArrowRight' ? 'scenario-next' : null;
275
321
  if (!action) return;
@@ -277,6 +323,11 @@ function onKeydown(e) {
277
323
  act(action);
278
324
  }
279
325
 
326
+ /** A menu or dialog that has its own Escape: the layers menu, the toolbar's ⋯ menu, a dialog */
327
+ function otherPopupOpen() {
328
+ return !!document.querySelector('#legend-dropdown:not([hidden]), #proposal-more-menu:not([hidden]), [data-corn="dialog-scrim"]:not([hidden]), .hx-mockup-dialog');
329
+ }
330
+
280
331
  /** Some browsers press a focused button on the key's release, so a space the player took must not reach it */
281
332
  function onKeyup(e) {
282
333
  if (player && (e.key === ' ' || e.code === 'Space') && !typingIn(e.target)) e.preventDefault();
@@ -322,10 +373,22 @@ function paintPlay(show) {
322
373
  btn.addEventListener('click', () => {
323
374
  const scenarios = proposalScenarios();
324
375
  if (scenarios.length === 1) playScenario(scenarios[0]);
325
- else if (list) { list.hidden = !list.hidden; btn.setAttribute('aria-expanded', String(!list.hidden)); }
376
+ else if (list) {
377
+ if (list.hidden) { list.hidden = false; btn.setAttribute('aria-expanded', 'true'); list.querySelector('button')?.focus(); } // the first row of what opened
378
+ else closeList(false);
379
+ }
326
380
  });
327
381
  }
328
382
 
383
+ /** Folds the scenario list back onto Play; `refocus` gives Play the focus (Escape from inside the list) */
384
+ function closeList(refocus) {
385
+ if (list) list.hidden = true;
386
+ const btn = document.getElementById('proposal-play');
387
+ if (!btn) return;
388
+ btn.setAttribute('aria-expanded', 'false');
389
+ if (refocus) btn.focus();
390
+ }
391
+
329
392
  /** Shows or hides the Play button and its list to match the open proposal's scenarios (and hides them while one plays: the player is the control then) */
330
393
  export function refreshList() {
331
394
  const stage = $stage();
@@ -52,6 +52,7 @@
52
52
  */
53
53
 
54
54
  import { edgeKey } from '../core/proposal.js';
55
+ import { frameNodes, allInside, READ_ZOOM, ZOOM_MIN } from './camera.js';
55
56
 
56
57
  export const DEFAULT_STEP_MS = 5000;
57
58
  /** Where the viewer's speed is kept (localStorage); scenario-ui.js reads and writes it */
@@ -70,8 +71,6 @@ export function parseSpeed(raw) {
70
71
  if (!choice) return DEFAULT_STEP_MS;
71
72
  return choice.value === 'manual' ? 'manual' : Number(choice.value);
72
73
  }
73
- /** The zoom fit-to-screen never goes below (render.js `fitGraphToViewport`) */
74
- export const MIN_FIT_ZOOM = 0.18;
75
74
 
76
75
  /** How long a step plays: its own `ms` when that is a positive number, else `fallback` */
77
76
  export function stepDuration(step, fallback = DEFAULT_STEP_MS) {
@@ -223,39 +222,32 @@ export function createPlayer(scenario, opts = {}) {
223
222
  }
224
223
 
225
224
  /**
226
- * Where the camera should go so a step is on screen, or null when it already is (or the step points
227
- * at something that is not in the map). A node off screen is centred at the same zoom; an edge is
228
- * centred and, if its two ends do not fit, zoomed out to fit (never below MIN_FIT_ZOOM, never in).
229
- * A step's `at` is kept in view with it when it is on the map, and ignored when it is not (a live id with no live layer).
225
+ * Where the camera should go so a step is on screen and readable, or null when it already is (or the step points at something that
226
+ * is not in the map). The step's node, or both ends of its edge, must be inside `viewport` (the part of the map nothing covers) at a zoom
227
+ * where the label reads (READ_ZOOM, about 11px): a node step zooms in to it, an edge step fits both ends (and no closer than READ_ZOOM).
228
+ * It never goes under `minZoom` (the map's floor, render.js `getMinZoom()`), so an edge too long even for that is shown as close as it allows.
229
+ * A step already shown well enough is left alone, so a walk does not wobble. A step's `at` is kept in view with it when it is on the map,
230
+ * and ignored when it is not (a live id with no live layer).
230
231
  * @param {Step} step
231
232
  * @param {{ x: number, y: number, zoom: number }} camera
232
- * @param {{ width: number, height: number }} viewport CSS px
233
+ * @param {{ width: number, height: number, x?: number, y?: number }} viewport CSS px (the free rect: `x` and `y` default to 0)
233
234
  * @param {Map<string, { x: number, y: number, r?: number }>} nodes by id
234
- * @param {number} [margin] px kept clear at the screen's edge
235
+ * @param {number} [margin] px kept clear at the viewport's edge
236
+ * @param {number} [minZoom] the lowest zoom it may go to
235
237
  * @returns {{ x: number, y: number, zoom: number } | null}
236
238
  */
237
- export function cameraFor(step, camera, viewport, nodes, margin = 60) {
239
+ export function cameraFor(step, camera, viewport, nodes, margin = 60, minZoom = ZOOM_MIN) {
238
240
  if (!viewport.width || !viewport.height) return null;
239
241
  const ids = step.node !== undefined ? [step.node] : step.edge ? [step.edge.from, step.edge.to] : [];
240
242
  const ends = ids.map((id) => nodes.get(id));
241
243
  if (ends.length === 0 || ends.some((n) => !n)) return null;
242
244
  if (step.at !== undefined && nodes.has(step.at) && !ids.includes(step.at)) ends.push(nodes.get(step.at));
243
245
 
244
- const onScreen = ends.every((n) => {
245
- const sx = camera.x + n.x * camera.zoom;
246
- const sy = camera.y + n.y * camera.zoom;
247
- return sx >= margin && sx <= viewport.width - margin && sy >= margin && sy <= viewport.height - margin;
248
- });
249
- if (onScreen) return null;
250
-
251
- const r = (n) => n.r || 18;
252
- const minX = Math.min(...ends.map((n) => n.x - r(n)));
253
- const maxX = Math.max(...ends.map((n) => n.x + r(n)));
254
- const minY = Math.min(...ends.map((n) => n.y - r(n)));
255
- const maxY = Math.max(...ends.map((n) => n.y + r(n)));
256
- const fit = Math.min((viewport.width - margin * 2) / (maxX - minX), (viewport.height - margin * 2) / (maxY - minY));
257
- const zoom = Math.max(MIN_FIT_ZOOM, Math.min(camera.zoom, fit));
258
- return { x: viewport.width / 2 - ((minX + maxX) / 2) * zoom, y: viewport.height / 2 - ((minY + maxY) / 2) * zoom, zoom };
246
+ const rect = { x: viewport.x || 0, y: viewport.y || 0, width: viewport.width, height: viewport.height };
247
+ const target = frameNodes(ends, rect, { padding: margin, maxZoom: Math.max(READ_ZOOM, camera.zoom), minZoom });
248
+ const edge = Math.min(margin, rect.width / 4, rect.height / 4);
249
+ if (allInside(ends, camera, rect, edge) && camera.zoom >= target.zoom - 0.001) return null;
250
+ return target;
259
251
  }
260
252
 
261
253
  /**
package/explorer/scene.js CHANGED
@@ -166,6 +166,7 @@ import { externalLayer, whenDash } from './cloud-model.js';
166
166
  import { outageFor, paintOutage } from './outage-model.js';
167
167
  import { paintForge } from './forge-panel-model.js';
168
168
  import { lightColor, lightenScene, parseColor } from './theme-model.js';
169
+ import { DIFF_MARK_COLORS, DIFF_LABEL_ALPHA, EDGE_MIN_ALPHA, MARK_SHAPES, REMOVED_ALPHA } from './diff-marks.js';
169
170
 
170
171
  // ---------------------------------------------------------------------------
171
172
  // Constants every renderer shares, so the looks cannot drift apart
@@ -200,10 +201,10 @@ const PACKET = { color: '#ffffff', radius: 3.5, glow: 10, cycleMs: 2600 };
200
201
  * `alpha` fades a removed node and its edge; `strike` strikes its label through (`labelStrike`).
201
202
  */
202
203
  export const MARK = {
203
- added: { color: '#2dd4bf', ringR: 9, ringWidth: 2, ringDash: [5, 4], edgeDash: [7, 5], edgeWidth: 2.2, alpha: 1, strike: false },
204
- changed: { color: '#fbbf24', ringR: 9, ringWidth: 2.5, ringDash: null, edgeDash: null, edgeWidth: 2.4, alpha: 1, strike: false },
205
- removed: { color: '#f87171', ringR: 9, ringWidth: 2, ringDash: null, edgeDash: [3, 4], edgeWidth: 2, alpha: 0.55, strike: true },
206
- edit: { color: '#a78bfa', ringR: 9, ringWidth: 2.5, ringDash: null, edgeDash: null, edgeWidth: 2.4, alpha: 1, strike: false },
204
+ added: { ...MARK_SHAPES.added, color: DIFF_MARK_COLORS.dark.added, ringR: 9, ringWidth: 2, edgeWidth: 2.2, alpha: 1 },
205
+ changed: { ...MARK_SHAPES.changed, color: DIFF_MARK_COLORS.dark.changed, ringR: 9, ringWidth: 2.5, edgeWidth: 2.4, alpha: 1 },
206
+ removed: { ...MARK_SHAPES.removed, color: DIFF_MARK_COLORS.dark.removed, ringR: 9, ringWidth: 2, edgeWidth: 2, alpha: REMOVED_ALPHA },
207
+ edit: { ...MARK_SHAPES.edit, color: DIFF_MARK_COLORS.dark.edit, ringR: 9, ringWidth: 3, edgeWidth: 2.4, alpha: 1 }, // dotted: not the same ring as a change
207
208
  };
208
209
  /**
209
210
  * The looks a renderer draws itself, per theme (MAP-01): the halos, the mark rings, the core dot and the
@@ -224,7 +225,7 @@ const lightLook = (look) => {
224
225
  const DARK_LOOKS = Object.freeze({ halo: HALO, mark: MARK, core: CORE_COLOR, labelOutline: LABEL_OUTLINE });
225
226
  const LIGHT_LOOKS = Object.freeze({
226
227
  halo: Object.fromEntries(Object.entries(HALO).map(([k, v]) => [k, lightLook(v)])),
227
- mark: Object.fromEntries(Object.entries(MARK).map(([k, v]) => [k, lightLook(v)])),
228
+ mark: Object.fromEntries(Object.entries(MARK).map(([k, v]) => [k, { ...v, color: DIFF_MARK_COLORS.light[k] }])), // chosen to be 3:1 over the light ground and its glow (diff-marks.js)
228
229
  core: CORE_COLOR, // the white dot stays white: it sits on the node's own (deepened) colour, not on the ground
229
230
  labelOutline: { node: { color: 'rgba(244, 246, 250, 0.9)', width: 3.5 }, edge: { color: 'rgba(244, 246, 250, 0.92)', width: 3 } },
230
231
  });
@@ -467,7 +468,7 @@ function styleForProposal(edge, mark, view, gone = false) {
467
468
  edge.color = look.color;
468
469
  edge.dash = gone ? MARK.removed.edgeDash : look.edgeDash; // an edge a what-if edit removes: violet, but dotted and faded like any removal
469
470
  edge.width = Math.max(edge.width, look.edgeWidth);
470
- if (edge.alpha >= 0.1) edge.alpha = Math.max(edge.alpha, 0.9) * (gone ? MARK.removed.alpha : look.alpha); // not under the selection's deep dimming
471
+ if (edge.alpha >= 0.1) edge.alpha = Math.max(edge.alpha, EDGE_MIN_ALPHA) * (gone ? MARK.removed.alpha : look.alpha); // not under the selection's deep dimming
471
472
  if (edge.glow) edge.glowColor = look.color;
472
473
  }
473
474
 
@@ -578,7 +579,7 @@ function buildNodes(state, subgraph) {
578
579
  label: shown.label,
579
580
  labelSize: big ? 12 : 11,
580
581
  labelBold: big,
581
- labelAlpha: alpha,
582
+ labelAlpha: focus && !focus.touched.has(node.id) && !(subgraph && !connected) ? Math.max(alpha, DIFF_LABEL_ALPHA) : alpha, // a label the diff dims stays 3:1
582
583
  labelColor: connected ? '#f8fafc' : 'rgba(255, 255, 255, 0.3)',
583
584
  labelKeep: LANDMARK_TYPES.includes(shown.type) || selected || match || mark !== 'none' || !!(subgraph && connected),
584
585
  labelStrike: !!look && (look.strike || gone),
@@ -15,6 +15,7 @@
15
15
 
16
16
  import { state } from './state.js';
17
17
  import { createSheetModel } from './sheet-model.js';
18
+ import { freeRect } from './camera.js';
18
19
 
19
20
  /** The width below which the sheets apply (matches the CSS) */
20
21
  export const PHONE_QUERY = '(max-width: 767px)';
@@ -92,6 +93,31 @@ export function measureCovered() {
92
93
  return covered;
93
94
  }
94
95
 
96
+ /**
97
+ * The part of the map nothing covers, in the canvas's own CSS px: what the camera should frame a node into.
98
+ * On a phone the dock's sheets cover the bottom; from 768px the proposal bar covers the top (and the change list it grows to hold),
99
+ * the node panel the right, the Work panel the left and the scenario player the bottom. Without a layout (no page) it is the whole canvas.
100
+ * @returns {{ x: number, y: number, width: number, height: number }}
101
+ */
102
+ export function visibleMapRect() {
103
+ const covers = { top: 0, bottom: 0, left: 0, right: 0 };
104
+ const canvas = state.canvas;
105
+ const shown = (el) => !!el && !el.hidden && el.isConnected;
106
+ if (isPhone()) covers.bottom = measureCovered() + 8;
107
+ else if (canvas && typeof canvas.getBoundingClientRect === 'function') {
108
+ const c = canvas.getBoundingClientRect();
109
+ const bar = $('proposal-bar');
110
+ if (shown(bar)) covers.top = Math.max(0, bar.getBoundingClientRect().bottom - c.top) + 8;
111
+ const drawer = $('spec-drawer');
112
+ if (shown(drawer) && drawer.classList.contains('drawer-open')) covers.right = drawer.offsetWidth; // its width, not its box: it slides in
113
+ const forge = $('forge-panel');
114
+ if (shown(forge) && forge.classList.contains('forge-open')) covers.left = forge.offsetWidth;
115
+ const player = document.querySelector('.hx-player');
116
+ if (shown(player)) covers.bottom = Math.max(0, c.bottom - player.getBoundingClientRect().top) + 8;
117
+ }
118
+ return freeRect(state.width || 0, state.height || 0, covers);
119
+ }
120
+
95
121
  // ---------------------------------------------------------------------------
96
122
  // Registering and changing sheets
97
123
  // ---------------------------------------------------------------------------
@@ -28,6 +28,7 @@
28
28
  */
29
29
 
30
30
  import { parseColor, luminance, ratio, contrast } from '../core/color.js';
31
+ import { DIFF_MARK_COLORS } from './diff-marks.js';
31
32
 
32
33
  export const THEME_CHOICES = ['system', 'light', 'dark'];
33
34
  /** Where the choice is kept in the browser (theme.js); `?theme=` in the address wins over it, without being kept */
@@ -186,12 +187,18 @@ export function lightenScene(scene) {
186
187
  n.labelColor = lightColor(n.labelColor, 'text');
187
188
  }
188
189
  for (const e of scene.edges) {
189
- // A thin dark line on a light ground reads weaker than a thin light one on a dark ground at the same
190
- // alpha (the contrast ratio is lower): a faded or translucent line gets LINE_GAIN more, capped at opaque
191
- if (e.alpha < 1) e.alpha = Math.min(1, e.alpha * LINE_GAIN);
192
- e.color = lightColor(e.color);
193
- const [r, g, b, a] = parseColor(e.color);
194
- if (a > 0 && a < 1) e.color = css([r, g, b], Math.min(1, a * LINE_GAIN));
190
+ if (e.mark && e.mark !== 'none') {
191
+ // A proposal's mark keeps the light colour chosen for it (diff-marks.js) and the opacity scene.js gave it, with no gain:
192
+ // those were chosen together to be 3:1 at that opacity, and the contrast check (markOpacity) measures exactly that
193
+ e.color = DIFF_MARK_COLORS.dark[e.mark] === e.color ? DIFF_MARK_COLORS.light[e.mark] : lightColor(e.color);
194
+ } else {
195
+ // A thin dark line on a light ground reads weaker than a thin light one on a dark ground at the same
196
+ // alpha (the contrast ratio is lower): a faded or translucent line gets LINE_GAIN more, capped at opaque
197
+ if (e.alpha < 1) e.alpha = Math.min(1, e.alpha * LINE_GAIN);
198
+ e.color = lightColor(e.color);
199
+ const [r, g, b, a] = parseColor(e.color);
200
+ if (a > 0 && a < 1) e.color = css([r, g, b], Math.min(1, a * LINE_GAIN));
201
+ }
195
202
  if (e.glowColor) e.glowColor = lightColor(e.glowColor);
196
203
  if (e.label) e.label = { ...e.label, color: lightColor(e.label.color, 'text') };
197
204
  if (e.packet) e.packet = { ...e.packet, color: lightColor(e.packet.color), glowColor: lightColor(e.packet.glowColor) };
@@ -54,8 +54,8 @@
54
54
  /* Diff: what a proposal adds, changes, removes and edits (the map draws the same four) */
55
55
  --corn-added: #2dd4bf;
56
56
  --corn-changed: #fbbf24;
57
- --corn-removed: #f87171;
58
- --corn-edit: #a78bfa;
57
+ --corn-removed: #fa9292;
58
+ --corn-edit: #b49cfb;
59
59
  /* The same as text: mixed toward the text colour, so it reads on either ground */
60
60
  --corn-added-text: color-mix(in srgb, var(--corn-added) 60%, var(--corn-text));
61
61
  --corn-edit-text: color-mix(in srgb, var(--corn-edit) 60%, var(--corn-text));
@@ -212,10 +212,10 @@
212
212
  --corn-bad: #b91c1c;
213
213
  --corn-info: #03679e;
214
214
 
215
- --corn-added: #209a8b;
216
- --corn-changed: #b28103;
217
- --corn-removed: #f64c4c;
218
- --corn-edit: #9472f9;
215
+ --corn-added: #197c6f;
216
+ --corn-changed: #8f6703;
217
+ --corn-removed: #e20b0b;
218
+ --corn-edit: #6839f6;
219
219
 
220
220
  --corn-hue-orange: #c2410c;
221
221
  --corn-hue-fuchsia: #a21caf;
@@ -261,10 +261,10 @@
261
261
  --corn-bad: #b91c1c;
262
262
  --corn-info: #03679e;
263
263
 
264
- --corn-added: #209a8b;
265
- --corn-changed: #b28103;
266
- --corn-removed: #f64c4c;
267
- --corn-edit: #9472f9;
264
+ --corn-added: #197c6f;
265
+ --corn-changed: #8f6703;
266
+ --corn-removed: #e20b0b;
267
+ --corn-edit: #6839f6;
268
268
 
269
269
  --corn-hue-orange: #c2410c;
270
270
  --corn-hue-fuchsia: #a21caf;
@@ -25,6 +25,7 @@ import { render, isNodeVisible } from './render.js';
25
25
  import { hooks, rebuildProposalMap, closeProposal } from './proposal.js';
26
26
  import { getPlayer, playScenario, stopScenario, tickScenario } from './scenario-ui.js';
27
27
  import { kindOfMark } from './proposal-model.js';
28
+ import { announce } from './keyboard.js';
28
29
  import { edgeKey } from '../core/proposal.js';
29
30
  import * as M from './whatif-model.js';
30
31
 
@@ -197,15 +198,21 @@ function doIntent(intent, where) {
197
198
 
198
199
  export function undoEdit() {
199
200
  if (!state.proposal || !M.canUndo(state.whatIf)) return false;
200
- return step(M.undo(state.whatIf));
201
+ const edit = state.whatIf.edits[state.whatIf.edits.length - 1];
202
+ return step(M.undo(state.whatIf), edit, 'Undid');
201
203
  }
202
204
  export function redoEdit() {
203
205
  if (!state.proposal || !M.canRedo(state.whatIf)) return false;
204
- return step(M.redo(state.whatIf));
206
+ const edit = state.whatIf.undone[state.whatIf.undone.length - 1];
207
+ return step(M.redo(state.whatIf), edit, 'Redid');
205
208
  }
206
- function step(whatIf) {
209
+ /** Applies an undo or a redo, and says which edit it was ("Undid: Added the service “X”"); names are read where the node exists (before for an add, after for a remove) */
210
+ function step(whatIf, edit, verb) {
207
211
  clearMessages();
212
+ const words = () => M.describeEdit(edit, { nameOf, scenarioTitle: (id) => (scenariosOf(state.effectiveProposal || state.proposal).find((s) => s.id === id) || { title: id }).title });
213
+ const before = words();
208
214
  apply({ whatIf, effective: M.evaluate(base(), state.proposal, whatIf.edits).effective });
215
+ announce(`${verb}: ${/^remove/.test(edit.op) ? words() : before}`);
209
216
  return true;
210
217
  }
211
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cornfield",
3
- "version": "0.34.1",
3
+ "version": "0.34.3",
4
4
  "description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
5
5
  "license": "MIT",
6
6
  "author": "popcorn245 (https://github.com/popcorn245)",
@@ -168,7 +168,7 @@ function describeProposal(slug, source, proposal, topology) {
168
168
  summary: object ? text(proposal.summary) : '',
169
169
  spec: object && typeof proposal.spec === 'string' ? proposal.spec : null,
170
170
  source,
171
- counts: summarize(proposal),
171
+ counts: summarize(proposal), // the totals, and `nodes` and `edges` apart, so the list can say what it counts
172
172
  errors: topology ? proposalProblems(topology, proposal).errors.length : null,
173
173
  };
174
174
  }