cornfield 0.34.0 → 0.34.2

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.
@@ -12,6 +12,8 @@ import { CORE_RATIO, ARROW, MARK_MIN_PX, looksFor, packetPoint } from './scene.j
12
12
  import { ICON_RATIO, getMapStyle, looksWith, styledScene } from './map-style.js';
13
13
 
14
14
  const TAU = Math.PI * 2;
15
+ /** A glow thinner than this on screen (px) is not drawn: zoomed out it is a fraction of a pixel, and costs a stroke or fill per edge and node */
16
+ const GLOW_MIN_PX = 1.5;
15
17
  const circle = (ctx, x, y, r) => { ctx.beginPath(); ctx.arc(x, y, r, 0, TAU); };
16
18
 
17
19
  // ---------------------------------------------------------------------------
@@ -61,7 +63,7 @@ function drawLanes(ctx, lanes) {
61
63
  // ---------------------------------------------------------------------------
62
64
  // Edges
63
65
  // ---------------------------------------------------------------------------
64
- function drawEdge(ctx, edge, timeMs, zoom) {
66
+ function drawEdge(ctx, edge, timeMs, zoom, withPacket = true) {
65
67
  ctx.save();
66
68
  ctx.globalAlpha = edge.alpha;
67
69
 
@@ -72,12 +74,18 @@ function drawEdge(ctx, edge, timeMs, zoom) {
72
74
  ctx.strokeStyle = edge.color;
73
75
  ctx.lineWidth = edge.mark && edge.mark !== 'none' ? Math.max(edge.width, MARK_MIN_PX.edge / zoom) : edge.width; // a proposal's marks stay visible zoomed out
74
76
  ctx.setLineDash(edge.dash || []);
75
- if (edge.glow) {
76
- ctx.shadowColor = edge.glowColor;
77
- ctx.shadowBlur = edge.glow;
77
+ if (edge.glow && edge.glow * zoom >= GLOW_MIN_PX) {
78
+ // The glow is a wider, fainter stroke under the line, not `shadowBlur`: a blur per edge is a full-canvas blur
79
+ // pass each, and a selected hub lights ~900 edges (F30: 8 to 10 s a tap on a phone)
80
+ const line = ctx.lineWidth;
81
+ ctx.save();
82
+ ctx.globalAlpha = edge.alpha * 0.3;
83
+ ctx.strokeStyle = edge.glowColor || edge.color;
84
+ ctx.lineWidth = line + edge.glow * 0.6;
85
+ ctx.stroke();
86
+ ctx.restore();
78
87
  }
79
88
  ctx.stroke();
80
- ctx.shadowBlur = 0;
81
89
  ctx.setLineDash([]);
82
90
 
83
91
  // Arrowhead along the curve's end tangent
@@ -95,15 +103,33 @@ function drawEdge(ctx, edge, timeMs, zoom) {
95
103
 
96
104
  // The edge's label (selection only) is the label layer's, not drawn here
97
105
 
98
- if (edge.packet) {
99
- const p = packetPoint(edge, timeMs);
106
+ if (withPacket && edge.packet) drawPacketIn(ctx, edge, timeMs, zoom);
107
+ ctx.restore();
108
+ }
109
+
110
+ /** The packet's dot: a soft disc under it for the glow (no `shadowBlur`: see drawEdge), then the dot */
111
+ function drawPacketIn(ctx, edge, timeMs, zoom) {
112
+ const p = packetPoint(edge, timeMs);
113
+ const { packet } = edge;
114
+ if (packet.glow && packet.glow * zoom >= GLOW_MIN_PX) {
100
115
  ctx.beginPath();
101
- ctx.arc(p.x, p.y, edge.packet.radius, 0, TAU);
102
- ctx.fillStyle = edge.packet.color;
103
- ctx.shadowColor = edge.packet.glowColor;
104
- ctx.shadowBlur = edge.packet.glow;
116
+ ctx.arc(p.x, p.y, packet.radius + packet.glow * 0.5, 0, TAU);
117
+ ctx.globalAlpha = edge.alpha * 0.3;
118
+ ctx.fillStyle = packet.glowColor || packet.color;
105
119
  ctx.fill();
120
+ ctx.globalAlpha = edge.alpha;
106
121
  }
122
+ ctx.beginPath();
123
+ ctx.arc(p.x, p.y, packet.radius, 0, TAU);
124
+ ctx.fillStyle = packet.color;
125
+ ctx.fill();
126
+ }
127
+
128
+ /** A packet on its own (the layer cache below draws the edges' lines once and the packets every frame) */
129
+ function drawPacket(ctx, edge, timeMs, zoom) {
130
+ ctx.save();
131
+ ctx.globalAlpha = edge.alpha;
132
+ drawPacketIn(ctx, edge, timeMs, zoom);
107
133
  ctx.restore();
108
134
  }
109
135
 
@@ -143,13 +169,18 @@ function drawNode(ctx, node, zoom, looks, style) {
143
169
 
144
170
  // The node circle, glowing, with a white core dot
145
171
  circle(ctx, node.x, node.y, node.r);
146
- ctx.fillStyle = node.color;
147
- if (node.glow) {
148
- ctx.shadowColor = node.color;
149
- ctx.shadowBlur = node.glow;
172
+ if (node.glow && node.glow * zoom >= GLOW_MIN_PX) {
173
+ // A soft disc behind the node, not `shadowBlur` (see drawEdge): one cheap fill instead of a blur pass
174
+ ctx.save();
175
+ ctx.globalAlpha = node.alpha * 0.28;
176
+ circle(ctx, node.x, node.y, node.r + node.glow * 0.7);
177
+ ctx.fillStyle = node.color;
178
+ ctx.fill();
179
+ ctx.restore();
180
+ circle(ctx, node.x, node.y, node.r);
150
181
  }
182
+ ctx.fillStyle = node.color;
151
183
  ctx.fill();
152
- ctx.shadowBlur = 0;
153
184
  circle(ctx, node.x, node.y, node.r * CORE_RATIO);
154
185
  ctx.fillStyle = looks.core;
155
186
  ctx.fill();
@@ -186,6 +217,41 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
186
217
  const ctx = canvas.getContext('2d');
187
218
  let width = 0;
188
219
  let height = 0;
220
+ let ratio = 1;
221
+
222
+ // The still part of a frame (the background and every edge's line) is drawn once into `layer` and blitted while only
223
+ // the packets move: a hub's selection lights hundreds of packets, and redrawing thousands of lines on each frame is
224
+ // what made a tap take seconds on a phone (F30). Used only when the scene has packets and a canvas can be made.
225
+ let layer = null;
226
+ let layerCtx = null;
227
+ let layerFor = null; // what the layer shows: { scene, x, y, zoom, w, h }
228
+ const makeLayer = () => {
229
+ if (layer) return layer;
230
+ try {
231
+ layer = typeof OffscreenCanvas !== 'undefined' ? new OffscreenCanvas(canvas.width || 1, canvas.height || 1)
232
+ : typeof document !== 'undefined' ? document.createElement('canvas') : null;
233
+ layerCtx = layer && layer.getContext ? layer.getContext('2d') : null;
234
+ } catch { layerCtx = null; }
235
+ if (!layerCtx) layer = null;
236
+ return layer;
237
+ };
238
+ const hasPacket = new WeakMap();
239
+ const packetsIn = (scene) => {
240
+ if (!hasPacket.has(scene)) hasPacket.set(scene, scene.edges.some((e) => e.packet));
241
+ return hasPacket.get(scene);
242
+ };
243
+
244
+ function drawStill(c, scene, camera) {
245
+ c.save();
246
+ c.translate(camera.x, camera.y);
247
+ c.scale(camera.zoom, camera.zoom);
248
+ const { decor } = scene;
249
+ if (decor.grid) drawGrid(c, decor.grid, camera, width, height);
250
+ if (decor.lanes.length) drawLanes(c, decor.lanes);
251
+ if (decor.rings.length) drawRings(c, decor.rings);
252
+ scene.edges.forEach((edge) => drawEdge(c, edge, 0, camera.zoom, false));
253
+ c.restore();
254
+ }
189
255
 
190
256
  return {
191
257
  kind: 'canvas2d',
@@ -193,15 +259,42 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
193
259
  resize(w, h, dpr) {
194
260
  width = w;
195
261
  height = h;
262
+ ratio = dpr;
196
263
  canvas.width = w * dpr;
197
264
  canvas.height = h * dpr;
198
265
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
266
+ layerFor = null;
267
+ if (layer) { layer.width = canvas.width; layer.height = canvas.height; layerCtx.setTransform(dpr, 0, 0, dpr, 0, 0); }
199
268
  },
200
269
 
201
270
  draw(drawn, camera, timeMs) {
202
271
  const style = styleOf();
203
272
  const scene = styledScene(drawn, style); // the map in the theme's colours (map-style.js); the scene itself when nothing is set
204
273
  ctx.clearRect(0, 0, width, height);
274
+
275
+ const looks = looksWith(looksFor(scene.theme), style); // the halos, mark rings and core for the scene's ground, in the theme's colours
276
+ if (packetsIn(scene) && makeLayer()) {
277
+ const same = layerFor && layerFor.scene === scene && layerFor.x === camera.x && layerFor.y === camera.y && layerFor.zoom === camera.zoom && layerFor.w === canvas.width && layerFor.h === canvas.height;
278
+ if (!same) {
279
+ if (layer.width !== canvas.width || layer.height !== canvas.height) { layer.width = canvas.width; layer.height = canvas.height; }
280
+ layerCtx.setTransform(ratio, 0, 0, ratio, 0, 0);
281
+ layerCtx.clearRect(0, 0, width, height);
282
+ drawStill(layerCtx, scene, camera);
283
+ layerFor = { scene, x: camera.x, y: camera.y, zoom: camera.zoom, w: canvas.width, h: canvas.height };
284
+ }
285
+ ctx.save();
286
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
287
+ ctx.drawImage(layer, 0, 0);
288
+ ctx.restore();
289
+ ctx.save();
290
+ ctx.translate(camera.x, camera.y);
291
+ ctx.scale(camera.zoom, camera.zoom);
292
+ scene.edges.forEach((edge) => { if (edge.packet) drawPacket(ctx, edge, timeMs, camera.zoom); });
293
+ scene.nodes.forEach((node) => drawNode(ctx, node, camera.zoom, looks, style));
294
+ ctx.restore();
295
+ return;
296
+ }
297
+
205
298
  ctx.save();
206
299
  ctx.translate(camera.x, camera.y);
207
300
  ctx.scale(camera.zoom, camera.zoom);
@@ -212,13 +305,12 @@ export function createCanvas2dRenderer(canvas, opts = {}) {
212
305
  if (decor.rings.length) drawRings(ctx, decor.rings);
213
306
 
214
307
  scene.edges.forEach((edge) => drawEdge(ctx, edge, timeMs, camera.zoom));
215
- const looks = looksWith(looksFor(scene.theme), style); // the halos, mark rings and core for the scene's ground, in the theme's colours
216
308
  scene.nodes.forEach((node) => drawNode(ctx, node, camera.zoom, looks, style));
217
309
  // No text here: every label (and the strike through a removed one) is drawn by the label layer (labels.js) over this canvas
218
310
 
219
311
  ctx.restore();
220
312
  },
221
313
 
222
- destroy() { /* a 2d context holds nothing to release */ },
314
+ destroy() { layer = null; layerCtx = null; layerFor = null; },
223
315
  };
224
316
  }
@@ -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');
@@ -99,7 +99,13 @@ function paint() {
99
99
  const status = q('[data-review-status]');
100
100
  status.textContent = reviewWords(ui.review, now());
101
101
  status.hidden = !status.textContent;
102
- for (const btn of document.querySelectorAll('#proposal-bar [data-review]')) btn.disabled = ui.busy || !ui.reviewable;
102
+ // 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
103
+ // only says it is busy (`aria-disabled`): a `disabled` button drops the focus to the page.
104
+ for (const btn of document.querySelectorAll('#proposal-bar [data-review]')) {
105
+ btn.disabled = !ui.reviewable;
106
+ if (ui.busy) btn.setAttribute('aria-disabled', 'true'); else btn.removeAttribute('aria-disabled');
107
+ if (!ui.reviewable && ui.key) btn.setAttribute('aria-describedby', 'review-hint'); else btn.removeAttribute('aria-describedby');
108
+ }
103
109
  const approve = button('approved');
104
110
  if (approve) approve.textContent = t('approve');
105
111
  const sendBack = button('notes');
@@ -125,6 +131,9 @@ function openNote() {
125
131
  paint();
126
132
  if (isPhone()) expandSheet('proposal');
127
133
  q('#review-note').focus();
134
+ // 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
135
+ const send = button('notes');
136
+ if (isPhone() && send && typeof send.scrollIntoView === 'function') send.scrollIntoView({ block: 'nearest' });
128
137
  }
129
138
 
130
139
  /** Cancel: the field closes, what was typed goes, and focus goes back to Send back */
@@ -223,7 +232,11 @@ export async function sendReview(verdict) {
223
232
  const wasNoting = ui.noting;
224
233
  ui.noting = false;
225
234
  paint();
226
- if (wasNoting && verdict === 'notes') { const sendBack = button('notes'); if (sendBack) sendBack.focus(); }
235
+ // 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,
236
+ // 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.
237
+ const lost = !document.activeElement || document.activeElement === document.body || !document.activeElement.isConnected;
238
+ if (verdict === 'approved') { if (lost) button('approved')?.focus(); }
239
+ else if (wasNoting || lost) button('notes')?.focus();
227
240
  refreshMockups(); // an approval covers the screens as they are now; a send back leaves them not reviewed
228
241
  if (verdict === 'notes') clearEdits(); // the edits went with the note; an approval keeps them, they are in the review
229
242
  return true;
@@ -24,9 +24,9 @@
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';
@@ -58,7 +58,10 @@ const $stage = () => (state.canvas ? state.canvas.parentElement : null);
58
58
  * @returns {ReturnType<typeof createPlayer>} the player, for a caller that wants to drive it
59
59
  */
60
60
  export function playScenario(scenario, opts = {}) {
61
+ const opener = openerOf();
62
+ const takeFocus = isKeyboardish(); // checked now: the list row that was pressed goes with the list
61
63
  clearScenario();
64
+ returnTo = opener;
62
65
  const speed = opts.stepMs ?? readSpeed();
63
66
  player = createPlayer(scenario, { stepMs: speed, maxFrameMs: MAX_FRAME_MS });
64
67
  showBar(speed);
@@ -68,9 +71,43 @@ export function playScenario(scenario, opts = {}) {
68
71
  sync(true);
69
72
  render();
70
73
  ensureFlowLoop();
74
+ // 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
75
+ if (opts.focus !== false && bar && takeFocus) {
76
+ const toggle = bar.querySelector('[data-action=scenario-toggle]');
77
+ if (toggle && !toggle.disabled) toggle.focus(); else bar.querySelector('[data-action=scenario-next]')?.focus();
78
+ }
71
79
  return player;
72
80
  }
73
81
 
82
+ /** 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 */
83
+ let returnTo = null;
84
+ function openerOf() {
85
+ const active = document.activeElement;
86
+ const play = document.getElementById('proposal-play');
87
+ if (active && active !== document.body && (active === play || active.closest?.('#proposal-scenarios'))) return play;
88
+ if (active && active !== document.body && !active.closest?.('.hx-player') && active !== state.canvas) return active;
89
+ return null;
90
+ }
91
+
92
+ /** 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 */
93
+ function isKeyboardish() {
94
+ const active = document.activeElement;
95
+ return !!active && active !== document.body && !typingIn(active);
96
+ }
97
+
98
+ /** 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) */
99
+ function giveFocusBack() {
100
+ const to = returnTo;
101
+ returnTo = null;
102
+ const took = (el) => {
103
+ if (!el || !el.isConnected || el.hidden || el.disabled || el.closest('[hidden]')) return false;
104
+ el.focus();
105
+ return document.activeElement === el; // a control the stylesheet hides takes no focus
106
+ };
107
+ if (took(to) || took(document.getElementById('proposal-play'))) return;
108
+ took(state.canvas);
109
+ }
110
+
74
111
  /**
75
112
  * An outage scenario (spec 0031 section 8) turns on the layers its blast radius is drawn on (containers and
76
113
  * machines start off), as a scenario that names a persona turns the People layer on (check.js).
@@ -105,9 +142,12 @@ export function clearScenario() {
105
142
  /** Ends the scenario and redraws the map without it */
106
143
  export function stopScenario() {
107
144
  if (!player && !state.scenario) return;
145
+ const hadFocus = !!bar && bar.contains(document.activeElement);
108
146
  clearScenario();
109
147
  touchScene();
110
148
  render();
149
+ if (hadFocus || document.activeElement === document.body) giveFocusBack(); // focus was in the player, which is gone
150
+ else returnTo = null;
111
151
  }
112
152
 
113
153
  /** 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 +173,11 @@ function sync(force = false) {
133
173
  function followStep(snap) {
134
174
  const visible = new Map();
135
175
  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);
176
+ // 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
177
+ const rect = visibleMapRect();
178
+ 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
179
  if (!target) return;
142
- if (flowReduceMotion) { Object.assign(state.camera, target); glide = null; return; }
180
+ if (flowReduceMotion) { Object.assign(state.camera, target); glide = null; render(); return; } // reduced motion: jump, do not fly
143
181
  glide = { to: target, last: null };
144
182
  ensureFlowLoop();
145
183
  }
@@ -191,9 +229,9 @@ function showBar(speed) {
191
229
  </div>
192
230
  <p class="hx-player-text" aria-live="polite"><span class="hx-player-count"></span> · <span class="hx-player-step"></span></p>
193
231
  <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>
232
+ <button type="button" class="hx-btn" data-action="scenario-prev" data-peek-ok>◀ Previous</button>
233
+ <button type="button" class="hx-btn hx-btn--active" data-action="scenario-toggle" data-peek-ok data-corn-kind="primary"></button>
234
+ <button type="button" class="hx-btn" data-action="scenario-next" data-peek-ok>Next ▶</button>
197
235
  </div>
198
236
  <div class="hx-player-track" aria-hidden="true"><span class="hx-player-fill"></span></div>`;
199
237
  bar.addEventListener('click', (e) => {
@@ -270,6 +308,10 @@ function typingIn(target) {
270
308
  }
271
309
 
272
310
  function onKeydown(e) {
311
+ if (e.key === 'Escape' && !e.defaultPrevented && !e.ctrlKey && !e.metaKey && !e.altKey) {
312
+ if (player && !typingIn(e.target) && !otherPopupOpen()) { e.preventDefault(); stopScenario(); return; } // Escape closes the scenario; focus goes back to Play
313
+ if (!player && list && !list.hidden && list.contains(document.activeElement)) { e.preventDefault(); closeList(true); return; }
314
+ }
273
315
  if (!player || e.defaultPrevented || e.ctrlKey || e.metaKey || e.altKey || typingIn(e.target)) return;
274
316
  const action = e.key === ' ' || e.code === 'Space' ? 'scenario-toggle' : e.key === 'ArrowLeft' ? 'scenario-prev' : e.key === 'ArrowRight' ? 'scenario-next' : null;
275
317
  if (!action) return;
@@ -277,6 +319,11 @@ function onKeydown(e) {
277
319
  act(action);
278
320
  }
279
321
 
322
+ /** A menu or dialog that has its own Escape: the layers menu, the toolbar's ⋯ menu, a dialog */
323
+ function otherPopupOpen() {
324
+ return !!document.querySelector('#legend-dropdown:not([hidden]), #proposal-more-menu:not([hidden]), [data-corn="dialog-scrim"]:not([hidden]), .hx-mockup-dialog');
325
+ }
326
+
280
327
  /** Some browsers press a focused button on the key's release, so a space the player took must not reach it */
281
328
  function onKeyup(e) {
282
329
  if (player && (e.key === ' ' || e.code === 'Space') && !typingIn(e.target)) e.preventDefault();
@@ -322,10 +369,22 @@ function paintPlay(show) {
322
369
  btn.addEventListener('click', () => {
323
370
  const scenarios = proposalScenarios();
324
371
  if (scenarios.length === 1) playScenario(scenarios[0]);
325
- else if (list) { list.hidden = !list.hidden; btn.setAttribute('aria-expanded', String(!list.hidden)); }
372
+ else if (list) {
373
+ if (list.hidden) { list.hidden = false; btn.setAttribute('aria-expanded', 'true'); list.querySelector('button')?.focus(); } // the first row of what opened
374
+ else closeList(false);
375
+ }
326
376
  });
327
377
  }
328
378
 
379
+ /** Folds the scenario list back onto Play; `refocus` gives Play the focus (Escape from inside the list) */
380
+ function closeList(refocus) {
381
+ if (list) list.hidden = true;
382
+ const btn = document.getElementById('proposal-play');
383
+ if (!btn) return;
384
+ btn.setAttribute('aria-expanded', 'false');
385
+ if (refocus) btn.focus();
386
+ }
387
+
329
388
  /** 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
389
  export function refreshList() {
331
390
  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
@@ -242,8 +242,8 @@ export function isNodeVisible(state, node) {
242
242
  if (state.view === 'dataflow') return !!state.flow && state.flow.ids.has(node.id);
243
243
  if (state.view === 'house') return houseShowsNode(state, node); // the House view (spec 0029, PHY-11) draws its own set: house-model.js
244
244
  if (node.type === 'root') return true;
245
- if (node.type === 'core') return activeLayers.pkg || activeLayers.atom;
246
- if (node.type === 'store') return activeLayers.flow !== false;
245
+ if (node.type === 'core') return (activeLayers.pkg || activeLayers.atom) && activeLayers.core !== false; // its own row in Layers, and Packages or Atoms
246
+ if (node.type === 'store') return activeLayers.flow !== false && activeLayers.store !== false; // its own row, and Data Flow
247
247
  if (node.type === 'rom') return activeLayers.rom !== false && activeLayers.flow !== false;
248
248
  if (node.type === 'floor' || node.type === 'room') return activeLayers.house !== false; // the House layer (spec 0029)
249
249
  if (node.type === 'external') return activeLayers[externalLayer(node)] !== false; // the Cloud and Public web layers (spec 0031)
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @module explorer/search-status
3
+ *
4
+ * The line by the search field that says a search found nothing ("No match for “xyz”"), in a polite live region so a
5
+ * screen reader says it too (F24). Spec 0008 builds the results list; this is only the no-match message.
6
+ * The words are the `searchNoMatch` string; the query goes in as text, never as HTML.
7
+ */
8
+
9
+ import { t } from './strings.js';
10
+
11
+ /** The two fields' status lines: the desktop box and the phone's bar */
12
+ const IDS = ['search-status', 'mobile-search-status'];
13
+
14
+ /** "No match for “query”" */
15
+ export const noMatchText = (query) => `${t('searchNoMatch')} “${query}”`;
16
+
17
+ /** Shows `text` by the search field(s); '' clears it */
18
+ export function showSearchStatus(text) {
19
+ for (const id of IDS) {
20
+ const el = document.getElementById(id);
21
+ if (el) el.textContent = text;
22
+ }
23
+ }
24
+
25
+ /** How long the typing must pause before "No match" is shown: a live region that changed on every key would be read out on every key */
26
+ export const NO_MATCH_DELAY_MS = 400;
27
+ let pending = null;
28
+
29
+ /**
30
+ * Sets the status for a search: nothing for an empty query or a match (at once), "No match for …" when the query found
31
+ * no node, once the typing pauses, so a screen reader says it once and not for every letter.
32
+ * @param {string} query the trimmed query
33
+ * @param {boolean} found whether a shown node matched
34
+ */
35
+ export function updateSearchStatus(query, found) {
36
+ clearTimeout(pending);
37
+ pending = null;
38
+ if (!query || found) { showSearchStatus(''); return; }
39
+ const text = noMatchText(query);
40
+ pending = setTimeout(() => { pending = null; showSearchStatus(text); }, NO_MATCH_DELAY_MS);
41
+ }
@@ -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
  // ---------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cornfield",
3
- "version": "0.34.0",
3
+ "version": "0.34.2",
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)",