@popcorn245/cornfield 0.40.0 → 0.41.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.
@@ -1,19 +1,20 @@
1
1
  /**
2
2
  * @module core/map-tokens
3
3
  *
4
- * The map's non-colour tokens, as `cornfield validate` reads them: `--corn-map-font`, `--corn-map-edge-width` and `--corn-map-glow`. The
4
+ * The map's non-colour tokens, as `cornfield validate` reads them: `--corn-map-font`, `--corn-map-edge-width`, `--corn-map-glow` and `--corn-map-label-min`. The
5
5
  * map reads each with the same parser (explorer/map-style.js `readMapTokens`), and one it cannot read is drawn as if it were `auto`; this
6
6
  * says so before the theme ships, as a warning naming the token, the theme, the level and what it may hold (docs/theming.md, The map).
7
7
  */
8
8
 
9
9
  import { declaredProps, expand, projectGroupOf, resolveProps, themesToCheck } from './contrast.js';
10
10
  import { iconKeyShape, parseKindToken } from './layers.js';
11
- import { EDGE_WIDTH_TOKEN, FONT_TOKEN, GLOW_TOKEN, MAX_EDGE_WIDTH, MAX_GLOW, readMapTokens } from '../explorer/map-style.js';
11
+ import { EDGE_WIDTH_TOKEN, FONT_TOKEN, GLOW_TOKEN, LABEL_MIN_TOKEN, MAX_EDGE_WIDTH, MAX_GLOW, MAX_LABEL_MIN, readMapTokens } from '../explorer/map-style.js';
12
12
 
13
13
  const WANTS = {
14
14
  [FONT_TOKEN]: ['font', 'a list of font families (quoted names or plain words, at most 8; no url(), and no punctuation but commas and quotes)'],
15
15
  [EDGE_WIDTH_TOKEN]: ['edgeWidth', `a width in px over 0 and at most ${MAX_EDGE_WIDTH}`],
16
16
  [GLOW_TOKEN]: ['glow', `a factor from 0 (no glow) to ${MAX_GLOW}`],
17
+ [LABEL_MIN_TOKEN]: ['labelMin', `a size in px from 9 to ${MAX_LABEL_MIN} (11px is the default and the least it draws at; under 9px is ignored)`],
17
18
  };
18
19
 
19
20
  /**
@@ -64,7 +64,7 @@ export function pinchCamera(start, dist, mid, min = ZOOM_MIN) {
64
64
  // Framing: put these nodes in the part of the map nothing covers
65
65
  // ---------------------------------------------------------------------------
66
66
 
67
- /** The zoom at which a node's label is about 11px on screen (labels are 11px in world units from LABEL_ZOOM up, scene.js): where a step or a picked change is shown */
67
+ /** The zoom at which a node's label is about 11px on screen (a label is never drawn under 11px, labels.js): where a step or a picked change is shown */
68
68
  export const READ_ZOOM = 1.0;
69
69
  /**
70
70
  * The lowest zoom a change is framed at when it opens (proposal.js `fitToChange`): below it node discs and marks run together, so a change
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @module explorer/cluster
3
+ *
4
+ * A cluster is a hub and what hangs under it (spec 0008 D1): an app and its pages, a store and its tables. A click or tap on a cluster's title
5
+ * (its hub's label) frames the cluster: the camera fits to all of it. Pure: nodes and edges in, ids out.
6
+ */
7
+
8
+ /**
9
+ * The ids of a hub and everything under it, by ownership edges (no kind, not dashed).
10
+ * @param {string} hubId
11
+ * @param {{from: string, to: string, kind?: string, dashed?: boolean}[]} edges
12
+ * @returns {Set<string>}
13
+ */
14
+ export function clusterIds(hubId, edges) {
15
+ const kids = new Map();
16
+ for (const e of edges) {
17
+ if (e.kind || e.dashed || !e.from || !e.to) continue;
18
+ (kids.get(e.from) || kids.set(e.from, []).get(e.from)).push(e.to);
19
+ }
20
+ const out = new Set([hubId]);
21
+ const todo = [hubId];
22
+ while (todo.length) {
23
+ for (const k of kids.get(todo.pop()) || []) if (!out.has(k)) { out.add(k); todo.push(k); }
24
+ }
25
+ return out;
26
+ }
@@ -177,7 +177,11 @@ h1, h2, h3, p { margin: 0; }
177
177
  .hx-brand { min-width: 0; min-height: 0; }
178
178
  .hx-only-wide { display: inline; }
179
179
  .hx-only-mobile { display: none; }
180
- .hx-search { display: flex; }
180
+ .hx-search { display: flex; flex: 0 1 260px; width: auto; }
181
+ /* A narrow desktop (768 to about 900 px, signed in): the search gives up width before it runs over the Layers chip; the left group
182
+ keeps its own (the right group shrinks, the search down to its min-width) */
183
+ .hx-header-left { flex: none; }
184
+ .hx-header-right { flex: 0 1 auto; min-width: 0; }
181
185
  }
182
186
  /* Not for a desktop: the brand keeps its logo and shows its wordmark; with no wordmark the logo stands alone (the button keeps its name) */
183
187
  @media (max-width: 767px) {
@@ -1094,11 +1098,10 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
1094
1098
  .hx-drawer[data-sheet-state="peek"] .hx-drawer-title { overflow: visible; text-overflow: clip; white-space: normal; }
1095
1099
  }
1096
1100
 
1097
- /* Search with no match (F24): one line under the field, a polite live region. Empty it takes no room. */
1101
+ /* Search status (F24, spec 0008): the polite live region by each search field. The count and the list say it on the screen (below), so
1102
+ the region itself is only for a screen reader: it stays in the page, out of sight. */
1098
1103
  .hx-search { position: relative; }
1099
- .hx-search-status { position: absolute; top: calc(100% + var(--corn-space-2)); left: 0; right: 0; z-index: 40; padding: var(--corn-space-2) var(--corn-space-3); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: var(--corn-surface-2); color: var(--corn-text); font-size: var(--corn-text-sm); overflow-wrap: anywhere; }
1100
- .hx-search-status:empty { display: none; }
1101
- .hx-mobile-search .hx-search-status { top: calc(100% - var(--corn-space-1)); left: var(--corn-space-3); right: var(--corn-space-3); }
1104
+ .hx-search-status { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
1102
1105
 
1103
1106
  /* The node panel's facts break at word boundaries only (F60): "hook" is never "hoo / k". A long path or name still wraps, at its slashes and dashes, and only as a last resort anywhere. */
1104
1107
  .hx-fact-v { overflow-wrap: break-word; word-break: normal; }
@@ -1175,6 +1178,51 @@ a.hx-proposal-source:focus-visible { outline: var(--corn-focus-width) solid var(
1175
1178
  .hx-offline[hidden] { display: none; }
1176
1179
  .hx-offline[data-corn-state="success"] { border-color: var(--corn-ok); }
1177
1180
 
1181
+ /* ---------------------------------------------------------------------------
1182
+ Search: the count, the step buttons and the list of what was found (spec 0008 D4)
1183
+ --------------------------------------------------------------------------- */
1184
+ .hx-search-steps { display: flex; align-items: center; flex: none; gap: var(--corn-space-1); }
1185
+ .hx-search-steps[hidden] { display: none; }
1186
+ .hx-search-count { padding: 0 var(--corn-space-2); font-size: var(--corn-text-2xs); color: var(--corn-text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
1187
+ .hx-search-count[data-empty="true"] { color: var(--corn-text); font-weight: 600; }
1188
+ .hx-search-btn { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: var(--corn-radius-xs); background: none; color: var(--corn-text-3); }
1189
+ .hx-search-btn:hover { background: var(--corn-surface-3); color: var(--corn-text); }
1190
+ .hx-search-btn:focus-visible, .hx-search-row:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: calc(var(--corn-focus-offset) * -1); }
1191
+ .hx-search:has(.hx-search-steps:not([hidden])) { flex-basis: 340px; }
1192
+ /* A narrow desktop leaves the field too little room for the count and three buttons: Previous and Next go (Enter and Shift+Enter, N and P
1193
+ and the list's rows still step), the count and Clear stay */
1194
+ @media (min-width: 768px) and (max-width: 959px) {
1195
+ .hx-search [data-action="search-prev"], .hx-search [data-action="search-next"] { display: none; }
1196
+ }
1197
+ .hx-search-results { position: absolute; top: calc(100% + var(--corn-space-2)); right: 0; z-index: 40; width: min(440px, 92vw); max-height: min(60vh, 560px); overflow-y: auto; padding: var(--corn-space-1) 0; border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: var(--corn-ground); box-shadow: var(--corn-shadow); color: var(--corn-text); font-size: var(--corn-text-sm); } /* the ground itself, not a surface: a surface is see-through, and the panel under the list would show in it */
1198
+ .hx-search-results[hidden] { display: none; }
1199
+ /* The list is part of the header, which sits under the node panel (40): while the list is open the header is over it, so a row is never half under the panel */
1200
+ .hx-header:has(.hx-search-results:not([hidden])) { z-index: 46; }
1201
+ /* On a phone the list is in the search bar, under the sheets (the dock, 45): while it is open the bar is over them, so a proposal's or the
1202
+ Work sheet never covers rows of it. Without :has() the list stays under the sheets, as the bar always was */
1203
+ .hx-mobile-search:has(.hx-search-results:not([hidden])) { z-index: 46; }
1204
+ .hx-search-group-title { position: sticky; top: 0; display: flex; justify-content: space-between; gap: var(--corn-space-3); padding: var(--corn-space-2) var(--corn-space-3) var(--corn-space-1); background: var(--corn-ground); color: var(--corn-text-3); font-size: var(--corn-text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
1205
+ .hx-search-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--corn-space-3); width: 100%; min-height: 28px; padding: var(--corn-space-1) var(--corn-space-3); border: 0; border-left: var(--corn-border-strong) solid transparent; background: none; color: var(--corn-text); font: inherit; text-align: left; cursor: pointer; }
1206
+ .hx-search-row:hover, .hx-search-row:focus-visible { background: var(--corn-surface-3); }
1207
+ .hx-search-row[aria-current="true"] { border-left-color: var(--corn-accent); background: var(--corn-accent-soft); }
1208
+ .hx-search-row-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1209
+ .hx-search-row-parent { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--corn-text-3); font-size: var(--corn-text-xs); }
1210
+ .hx-search-frame { font-weight: 600; color: var(--corn-text); }
1211
+ .hx-search-empty, .hx-search-more { margin: 0; padding: var(--corn-space-2) var(--corn-space-3); color: var(--corn-text-2); overflow-wrap: anywhere; }
1212
+ .hx-mobile-search { flex-wrap: wrap; }
1213
+ .hx-mobile-search .hx-input { flex: 1 1 0; min-width: 0; }
1214
+ .hx-mobile-search::before { top: calc(var(--corn-space-3) + 22px); } /* the magnifier stays by the field when the bar wraps to a second row of steps */
1215
+ .hx-mobile-search .hx-search-steps { flex: 1 0 100%; justify-content: flex-end; gap: var(--corn-space-1); }
1216
+ .hx-mobile-search .hx-search-count { margin-right: auto; font-size: var(--corn-text-xs); }
1217
+ .hx-mobile-search .hx-search-results { top: 100%; left: 0; right: 0; width: auto; max-height: 50vh; border-radius: 0; border-left: 0; border-right: 0; }
1218
+ @media (max-width: 767px), (pointer: coarse) {
1219
+ .hx-search-btn { min-width: 44px; min-height: 44px; }
1220
+ .hx-search-row { min-height: 44px; }
1221
+ }
1222
+ @media (forced-colors: active) {
1223
+ .hx-search-row[aria-current="true"] { border-left-color: Highlight; }
1224
+ }
1225
+
1178
1226
  /* ==== the review column (spec 0006, review-column.js): the changes, and the personas with the scenarios that apply to them ==============
1179
1227
  From 768px it is docked on the left of the map under the proposal bar (the free map is what it leaves: sheets.js visibleMapRect);
1180
1228
  on a phone it is the expanded proposal sheet's body, a two-part switch at its top, its foot (the decision) always in view. */
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module explorer/fly
3
+ *
4
+ * The camera flying to a place: a short glide to `{ x, y, zoom }`, as the scenario player's steps do, so a match chosen in a search
5
+ * is not a jump the eye has to find again. Under reduced motion the camera jumps. A new flight replaces the one in the air, and a
6
+ * hand on the map (a pan, a wheel) is not fought: `stopFlight()` ends it (input.js calls it when the pointer takes the camera).
7
+ * It is a frame client of render.js's loop, so it asks for frames only while it flies.
8
+ */
9
+
10
+ import { state } from './state.js';
11
+ import { render, ensureFlowLoop, addFrameClient } from './render.js';
12
+ import { flowReduceMotion } from './flows.js';
13
+
14
+ /** How quickly the camera closes on the target: the time constant of the glide (ms) */
15
+ export const FLY_MS = 120;
16
+ let glide = null; // { to: {x, y, zoom}, last: nowMs|null }
17
+
18
+ /** Flies the camera to `target` (jumps there when motion is reduced) */
19
+ export function flyTo(target) {
20
+ if (!target) return;
21
+ if (flowReduceMotion || !state.width) { Object.assign(state.camera, target); glide = null; render(); return; }
22
+ glide = { to: { ...target }, last: null };
23
+ ensureFlowLoop();
24
+ }
25
+
26
+ /** Ends a flight where it is */
27
+ export function stopFlight() { glide = null; }
28
+
29
+ /** Whether the camera is in the air */
30
+ export const flying = () => !!glide;
31
+
32
+ /** One frame of the glide (exported so a test can be the loop) */
33
+ export function tickFlight(now) {
34
+ if (!glide) return;
35
+ const dt = glide.last === null ? 16 : Math.min(now - glide.last, 100);
36
+ glide.last = now;
37
+ const k = 1 - Math.exp(-dt / FLY_MS);
38
+ const cam = state.camera;
39
+ cam.x += (glide.to.x - cam.x) * k;
40
+ cam.y += (glide.to.y - cam.y) * k;
41
+ cam.zoom += (glide.to.zoom - cam.zoom) * k;
42
+ if (Math.abs(glide.to.x - cam.x) < 0.5 && Math.abs(glide.to.y - cam.y) < 0.5 && Math.abs(glide.to.zoom - cam.zoom) < 0.002) {
43
+ Object.assign(cam, glide.to);
44
+ glide = null;
45
+ }
46
+ }
47
+
48
+ addFrameClient({ wants: flying, tick: tickFlight });
@@ -118,7 +118,14 @@
118
118
  <svg class="hx-search-icon" viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false"><circle cx="7" cy="7" r="4.5" /><path d="M10.5 10.5L14 14" /></svg>
119
119
  <input type="text" id="node-search" class="hx-search-input" placeholder="Search..." data-corn-string-placeholder="searchPlaceholder" aria-label="Search nodes" aria-keyshortcuts="/" data-corn="search-input" />
120
120
  <kbd class="hx-kbd" data-corn="search-key" aria-hidden="true">/</kbd>
121
+ <span id="search-steps" class="hx-search-steps" data-corn="search-steps" hidden>
122
+ <span id="search-count" class="hx-search-count" data-corn="search-count" aria-hidden="true"></span>
123
+ <button type="button" class="hx-search-btn" data-action="search-prev" aria-label="Previous match" title="Previous match (Shift+Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 10.5L8 6l4.5 4.5" /></svg></button>
124
+ <button type="button" class="hx-search-btn" data-action="search-next" aria-label="Next match" title="Next match (Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 5.5L8 10l4.5-4.5" /></svg></button>
125
+ <button type="button" class="hx-search-btn" data-action="clear-search" aria-label="Clear search" title="Clear search (Escape)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8" /></svg></button>
126
+ </span>
121
127
  <div id="search-status" class="hx-search-status" role="status" aria-live="polite" data-corn="search-status"></div>
128
+ <div id="search-results" class="hx-search-results" data-corn="search-results" hidden></div>
122
129
  </div>
123
130
 
124
131
  <!-- The Work toggle (explorer/forge-panel.js): opens the Work panel; shown only when the config names a forge -->
@@ -177,9 +184,15 @@
177
184
  <!-- Mobile search bar -->
178
185
  <div id="mobile-search-bar" class="hx-mobile-search glass-header" role="search" hidden data-corn="mobile-search">
179
186
  <input type="text" id="mobile-node-search" class="hx-input hx-input--wide" placeholder="Search nodes, apps, components..." aria-label="Search nodes" data-corn="search-input" />
180
- <button type="button" class="hx-textbtn" data-action="clear-search" aria-label="Clear search" data-corn-kind="quiet">✕</button>
181
187
  <button type="button" class="hx-textbtn" data-action="close-mobile-search" data-corn-kind="quiet">Cancel</button>
188
+ <span id="mobile-search-steps" class="hx-search-steps" data-corn="search-steps" hidden>
189
+ <span id="mobile-search-count" class="hx-search-count" data-corn="search-count" aria-hidden="true"></span>
190
+ <button type="button" class="hx-search-btn" data-action="search-prev" aria-label="Previous match" title="Previous match (Shift+Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 10.5L8 6l4.5 4.5" /></svg></button>
191
+ <button type="button" class="hx-search-btn" data-action="search-next" aria-label="Next match" title="Next match (Enter)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3.5 5.5L8 10l4.5-4.5" /></svg></button>
192
+ <button type="button" class="hx-search-btn" data-action="clear-search" aria-label="Clear search" title="Clear search (Escape)" data-corn-kind="icon"><svg viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="M4 4l8 8M12 4l-8 8" /></svg></button>
193
+ </span>
182
194
  <div id="mobile-search-status" class="hx-search-status" role="status" aria-live="polite" data-corn="search-status"></div>
195
+ <div id="mobile-search-results" class="hx-search-results" data-corn="search-results" hidden></div>
183
196
  </div>
184
197
 
185
198
  <!-- The map -->
package/explorer/input.js CHANGED
@@ -13,11 +13,14 @@
13
13
  */
14
14
 
15
15
  import { state, touchScene } from './state.js';
16
- import { render, getSpatialIndex, queueFrameWork, screenToWorld, getMinZoom } from './render.js';
16
+ import { render, getSpatialIndex, queueFrameWork, screenToWorld, getMinZoom, setHoverNode, labelNodeAt, fitGraphToViewport, fitPadding } from './render.js';
17
+ import { clusterIds } from './cluster.js';
18
+ import { LANDMARK_TYPES } from './scene.js';
17
19
  import { saveFreeformPositions } from './layout.js';
18
20
  import { selectNode, closeDrawer } from './panels.js';
19
21
  import { hitTestScreen } from './spatial.js';
20
22
  import { zoomAbout, pinchStart, pinchCamera } from './camera.js';
23
+ import { stopFlight } from './fly.js';
21
24
 
22
25
  let isDragging = false;
23
26
  let dragNode = null;
@@ -71,6 +74,8 @@ function touchMid(e) {
71
74
 
72
75
  function onPointerDown(e) {
73
76
  downOnCanvas = true;
77
+ stopFlight(); // the hand takes the camera: a flight to a match ends where it is
78
+ setHoverNode(null); // a press starts a tap or a drag: the chip that named a node under the pointer goes
74
79
  if (e.touches && e.touches.length === 2) {
75
80
  pinch = pinchStart(state.camera, touchDistance(e), touchMid(e));
76
81
  pendingPos = null;
@@ -124,7 +129,9 @@ function applyHover() {
124
129
  const p = pendingHover;
125
130
  pendingHover = null;
126
131
  if (!p || isDragging || dragNode) return;
127
- setHover(!!findNodeAt(p.x, p.y, false));
132
+ const over = findNodeAt(p.x, p.y, false);
133
+ setHover(!!over);
134
+ setHoverNode(over ? over.id : null); // a node with no label is named by a chip (labels.js)
128
135
  }
129
136
 
130
137
  function setHover(over) {
@@ -183,8 +190,11 @@ function onPointerUp(e) {
183
190
  }
184
191
  }
185
192
  }
186
- } else if (state.selectedNode) {
187
- closeDrawer(); // the background was clicked: back to the normal view
193
+ } else {
194
+ // A cluster's title (its hub's label) is not a node to select: a click on it frames the cluster (spec 0008 D1)
195
+ const titled = topologyNode(labelNodeAt(p.x, p.y));
196
+ if (titled && LANDMARK_TYPES.includes(titled.type) && titled.id !== 'root') fitGraphToViewport(fitPadding(), clusterIds(titled.id, state.edges));
197
+ else if (state.selectedNode) closeDrawer(); // the background was clicked: back to the normal view
188
198
  }
189
199
  }
190
200
  isDragging = false;
@@ -199,7 +209,7 @@ export function bindCanvasInput() {
199
209
  const { canvas } = state;
200
210
  canvas.addEventListener('mousedown', onPointerDown);
201
211
  canvas.addEventListener('mousemove', onPointerMove);
202
- canvas.addEventListener('mouseleave', () => { pendingHover = null; setHover(false); });
212
+ canvas.addEventListener('mouseleave', () => { pendingHover = null; setHover(false); setHoverNode(null); });
203
213
  window.addEventListener('mouseup', onPointerUp);
204
214
 
205
215
  canvas.addEventListener('touchstart', onPointerDown, { passive: false });
@@ -209,6 +219,7 @@ export function bindCanvasInput() {
209
219
 
210
220
  canvas.addEventListener('wheel', (e) => {
211
221
  e.preventDefault();
222
+ stopFlight();
212
223
  const p = getPointerPos(e);
213
224
  Object.assign(state.camera, zoomAbout(state.camera, e.deltaY < 0 ? 1.12 : 0.88, p.x, p.y, getMinZoom()));
214
225
  render(); // a camera change is cheap; the draw is one per frame however many wheel events arrive
@@ -10,7 +10,7 @@
10
10
  * Escape closes it, and in Freeform Alt+arrow moves the selected node;
11
11
  * - `#map-announcer` (a polite live region) says where the keyboard landed: the node, its type, its
12
12
  * connections, its place; the zoom; a search's hit;
13
- * - Enter in the search box selects the first visible match;
13
+ * - Enter in the search box selects the best match and goes on to the next (search.js); with a search on, N and P step through its matches;
14
14
  * - the panel: Escape inside it closes it and gives the focus back to the map; it is `inert` while closed
15
15
  * (panels.js), so its buttons are never tabbed to off screen;
16
16
  * - the Layers menu says whether it is open (`aria-expanded`), and Escape closes it, back on its button;
@@ -24,6 +24,7 @@ import { selectNode, closeDrawer } from './panels.js';
24
24
  import { saveFreeformPositions } from './layout.js';
25
25
  import { closeLegendMenu } from './layers.js';
26
26
  import * as K from './keyboard-model.js';
27
+ import { searchActive, stepMatch } from './search.js';
27
28
 
28
29
  const $ = (id) => document.getElementById(id);
29
30
  let wired = false;
@@ -42,17 +43,21 @@ export function announce(text) {
42
43
  /** The visible nodes, in the order the keys step through them */
43
44
  const stepOrder = () => K.readingOrder(state.nodes.filter((n) => isNodeVisible(n)));
44
45
 
45
- /** Moves the camera so `node` is in the middle of the part of the map not under the panels or a phone's sheets */
46
- export function centreOn(node) {
47
- const { camera, width, height } = state;
46
+ /** The camera that puts `node` in the middle of the part of the map not under the panels or a phone's sheets, at `zoom` (the current one by default) */
47
+ export function centreTarget(node, zoom = state.camera.zoom) {
48
+ const { width, height } = state;
48
49
  const visibleHeight = Math.max(160, height - (state.coveredBottom || 0));
49
50
  const panel = $('spec-drawer');
50
51
  const visibleWidth = width >= 768 && panel && panel.classList.contains('drawer-open') ? Math.max(160, width - (panel.offsetWidth || 480)) : width;
51
52
  // The issues and PRs panel slides in from the left (forge-panel.js)
52
53
  const forge = $('forge-panel');
53
54
  const left = width >= 768 && forge && forge.classList.contains('forge-open') ? Math.min(forge.offsetWidth || 400, visibleWidth - 160) : 0;
54
- camera.x = left + (visibleWidth - left) / 2 - node.x * camera.zoom;
55
- camera.y = visibleHeight / 2 - node.y * camera.zoom;
55
+ return { x: left + (visibleWidth - left) / 2 - node.x * zoom, y: visibleHeight / 2 - node.y * zoom, zoom };
56
+ }
57
+
58
+ /** Moves the camera so `node` is in the middle of the part of the map not under the panels or a phone's sheets */
59
+ export function centreOn(node) {
60
+ Object.assign(state.camera, centreTarget(node));
56
61
  render();
57
62
  }
58
63
 
@@ -108,6 +113,7 @@ function onMapKey(e) {
108
113
  announce(`The whole map. ${K.zoomWords(camera.zoom)}`);
109
114
  break;
110
115
  case 'step': {
116
+ if (searchActive() && stepMatch(action.by)) break; // with a search on, N and P walk its matches (search.js)
111
117
  const order = stepOrder();
112
118
  land(K.stepFrom(order, state.selectedNode && state.selectedNode.id, action.by), order);
113
119
  break;
@@ -147,18 +153,6 @@ function onPanelClick(e) {
147
153
  if (close && state.canvas) setTimeout(() => state.canvas.focus(), 0);
148
154
  }
149
155
 
150
- /** Enter in a search box: the first visible node it matches is selected, like a click on it */
151
- function onSearchKey(e) {
152
- if (e.key !== 'Enter') return;
153
- const q = e.target.value.trim().toLowerCase();
154
- if (!q) return;
155
- e.preventDefault();
156
- const order = stepOrder();
157
- const hit = order.find((n) => n.label.toLowerCase().includes(q));
158
- if (!hit) { announce(`No node matches ${e.target.value.trim()}`); return; }
159
- land(hit, order);
160
- }
161
-
162
156
  /** Whether the key went to something that takes typing */
163
157
  const typing = (el) => !!el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName));
164
158
 
@@ -198,10 +192,6 @@ export function initKeyboard() {
198
192
  drawer.addEventListener('keydown', onPanelKey);
199
193
  drawer.addEventListener('click', onPanelClick);
200
194
  }
201
- for (const id of ['node-search', 'mobile-node-search']) {
202
- const input = $(id);
203
- if (input) input.addEventListener('keydown', onSearchKey);
204
- }
205
195
  document.addEventListener('keydown', onDocumentKey);
206
196
  }
207
197