@popcorn245/cornfield 0.33.1 → 0.34.1

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.
@@ -83,6 +83,68 @@ function ringPack(items, { first = 110, gap = 76, spacing = 90 } = {}) {
83
83
  return { offsets, radii };
84
84
  }
85
85
 
86
+ /**
87
+ * A cluster's whole pack: `children` in rings around the centre, and a child that has children of its own (a store
88
+ * owning 46 outside services) gets its own rings, placed on an outer ring of this cluster with room for them.
89
+ * `kidsOf(node)` says who hangs under a node. Returns `{ children, offsets, radii, subs, extent }`: `subs[i]` is the
90
+ * child i's own pack (or null), `extent` how far the whole thing reaches from the centre.
91
+ */
92
+ function packTree(children, kidsOf, spacingOf, byOrder, seen = new Set()) {
93
+ const withSub = [];
94
+ const plain = [];
95
+ children.forEach((c) => {
96
+ const kids = seen.has(c.id) ? [] : kidsOf(c);
97
+ if (!kids.length) { plain.push(c); return; }
98
+ seen.add(c.id);
99
+ const sub = packTree(kids.sort(byOrder), kidsOf, spacingOf, byOrder, seen);
100
+ withSub.push({ c, sub, fp: sub.extent });
101
+ });
102
+ withSub.sort((a, b) => b.fp - a.fp);
103
+ const pack = ringPack(plain, { spacing: spacingOf(children) });
104
+ const out = {
105
+ children: [...plain], offsets: [...pack.offsets], radii: pack.radii, subs: plain.map(() => null),
106
+ extent: pack.radii.length ? pack.radii[pack.radii.length - 1] + 40 : 0,
107
+ };
108
+ if (withSub.length) {
109
+ const lastR = pack.radii.length ? pack.radii[pack.radii.length - 1] : 0;
110
+ const fpMax = withSub[0].fp;
111
+ const arc = withSub.reduce((sum, w) => sum + 2 * w.fp + 30, 0);
112
+ // Each takes arc in proportion to its size; two of them are a chord apart, not an arc, so the ring is as wide as
113
+ // the closest pair needs (for three or more large ones, more than the arc says)
114
+ const mids = [];
115
+ let a = -Math.PI / 2;
116
+ withSub.forEach((w) => { const share = ((2 * w.fp + 30) / arc) * Math.PI * 2; mids.push(a + share / 2); a += share; });
117
+ let r = Math.max(110, lastR + fpMax + 40, arc / (2 * Math.PI));
118
+ for (let i = 0; i < withSub.length; i++) {
119
+ for (let j = i + 1; j < withSub.length; j++) {
120
+ const half = Math.sin(Math.abs(mids[j] - mids[i]) / 2);
121
+ if (half > 1e-6) r = Math.max(r, (withSub[i].fp + withSub[j].fp + 30) / (2 * half));
122
+ }
123
+ }
124
+ withSub.forEach((w, i) => {
125
+ out.children.push(w.c);
126
+ out.offsets.push({ x: Math.cos(mids[i]) * r, y: Math.sin(mids[i]) * r });
127
+ out.subs.push(w.sub);
128
+ });
129
+ out.bigRadius = r;
130
+ out.extent = Math.max(out.extent, r + fpMax);
131
+ }
132
+ return out;
133
+ }
134
+
135
+ /** Puts a pack's children (and theirs) around (ox, oy); a child's own rings are added to `clusters` */
136
+ function placePack(pack, ox, oy, clusters) {
137
+ pack.children.forEach((c, i) => {
138
+ c.x = ox + pack.offsets[i].x;
139
+ c.y = oy + pack.offsets[i].y;
140
+ const sub = pack.subs[i];
141
+ if (sub) {
142
+ clusters.push({ x: c.x, y: c.y, radii: sub.radii });
143
+ placePack(sub, c.x, c.y, clusters);
144
+ }
145
+ });
146
+ }
147
+
86
148
  export function computeOrbitalLayout() {
87
149
  touchScene(); // positions and rings change
88
150
  const { nodes, edges } = state;
@@ -90,9 +152,19 @@ export function computeOrbitalLayout() {
90
152
  state.rings = { rings: [], clusters: [] };
91
153
  const LAYOUT = state.rings;
92
154
 
155
+ const ids = new Set(nodes.map((n) => n.id));
93
156
  const parentMap = {};
94
157
  edges.forEach((e) => {
95
- if (!e.dashed && !e.kind && e.from && e.to && !parentMap[e.to]) parentMap[e.to] = e.from;
158
+ // A parent that is not on the map (an edge a proposal left behind) is no parent: the node would sit on the centre
159
+ if (!e.dashed && !e.kind && e.from && e.to && ids.has(e.from) && e.from !== e.to && !parentMap[e.to]) parentMap[e.to] = e.from;
160
+ });
161
+ // Nor is a parent that is its own ancestor: the first node of a loop loses its parent, so the loop hangs from it
162
+ nodes.forEach((n) => {
163
+ const path = new Set([n.id]);
164
+ for (let p = parentMap[n.id]; p; p = parentMap[p]) {
165
+ if (path.has(p)) { delete parentMap[p]; break; }
166
+ path.add(p);
167
+ }
96
168
  });
97
169
 
98
170
  // topology.json stores no positions; a node the passes below do not place starts at the centre
@@ -102,11 +174,18 @@ export function computeOrbitalLayout() {
102
174
 
103
175
  const isData = (n) => DATA_TYPES.includes(n.type);
104
176
  const hasChildren = new Set(Object.values(parentMap));
105
- // A data store with tables of its own is a cluster like an app; other data rings the root
177
+ const parentsOfNonData = new Set(nodes.filter((k) => parentMap[k.id] && !isData(k)).map((k) => parentMap[k.id]));
178
+ // A data store with children of its own (tables, outside services) is a cluster like an app; other data rings the root
179
+ // and so is any node with no parent but children of its own (its children need somewhere to go)
106
180
  const isHub = (n) => n.id !== 'root' && (isData(n)
107
- ? n.type === 'store' && hasChildren.has(n.id) && !parentMap[n.id]
108
- : parentMap[n.id] === 'root' || (!parentMap[n.id] && ['app', 'pkg', 'tool', 'external', 'stack'].includes(n.type)));
109
- const hubs = nodes.filter(isHub);
181
+ ? hasChildren.has(n.id) && (!parentMap[n.id] || parentMap[n.id] === 'root')
182
+ && (n.type === 'store' || parentsOfNonData.has(n.id))
183
+ : parentMap[n.id] === 'root' || (!parentMap[n.id] && (hasChildren.has(n.id) || ['app', 'pkg', 'tool', 'external', 'stack'].includes(n.type))));
184
+ const firstHubs = new Set(nodes.filter(isHub).map((h) => h.id));
185
+ // A data node that would ring the root (its parent is no hub) but has other nodes under it is a cluster too: the
186
+ // data ring has no room for them
187
+ const hubs = nodes.filter((n) => firstHubs.has(n.id)
188
+ || (n.id !== 'root' && isData(n) && parentsOfNonData.has(n.id) && !firstHubs.has(parentMap[n.id])));
110
189
  const hubIds = new Set(hubs.map((h) => h.id));
111
190
  const typeRank = (n) => { const i = CHILD_TYPE_ORDER.indexOf(n.type); return i < 0 ? 99 : i; };
112
191
  const byTypeThenLabel = (a, b) => typeRank(a) - typeRank(b) || String(a.label).localeCompare(String(b.label));
@@ -124,15 +203,15 @@ export function computeOrbitalLayout() {
124
203
  const coreExtent = data.length ? dataR + 50 : 60;
125
204
  if (data.length) LAYOUT.rings.push({ x: 0, y: 0, r: dataR });
126
205
 
127
- // 2. Pack each hub's children (relative to the hub)
206
+ // 2. Pack each hub's children (relative to the hub). A child with children of its own (a store that owns the
207
+ // outside services) gets rings of its own, and they count in the cluster's extent.
208
+ const kidsOf = (n) => (n.id === 'root' ? [] : nodes.filter((k) => parentMap[k.id] === n.id && !hubIds.has(k.id) && !isData(k) && k.id !== 'root'));
209
+ const spacingOf = (list) => Math.min(170, Math.max(84, ...list.map((c) => labelWidth(c) * 0.8 + 26)));
128
210
  const packs = new Map();
129
211
  hubs.forEach((hub) => {
130
212
  const children = nodes.filter((n) => parentMap[n.id] === hub.id && !hubIds.has(n.id)).sort(byTypeThenLabel);
131
213
  if (!children.length) return;
132
- const spacing = Math.min(170, Math.max(84, ...children.map((c) => labelWidth(c) * 0.8 + 26)));
133
- const pack = ringPack(children, { spacing });
134
- const extent = pack.radii[pack.radii.length - 1] + 40;
135
- packs.set(hub.id, { children, ...pack, extent });
214
+ packs.set(hub.id, packTree(children, kidsOf, spacingOf, byTypeThenLabel, new Set([hub.id])));
136
215
  });
137
216
 
138
217
  // 3. Hubs with children around the core, arc proportional to cluster size
@@ -143,19 +222,21 @@ export function computeOrbitalLayout() {
143
222
  const hubR = Math.max(coreExtent + maxExtent + GAP, need / (2 * Math.PI));
144
223
  let angle = -Math.PI / 2;
145
224
  big.forEach((hub) => {
146
- const { extent, children, offsets, radii } = packs.get(hub.id);
147
- const share = ((2 * extent + GAP) / need) * Math.PI * 2;
225
+ const pack = packs.get(hub.id);
226
+ const share = ((2 * pack.extent + GAP) / need) * Math.PI * 2;
148
227
  const a = angle + share / 2;
149
228
  hub.x = Math.cos(a) * hubR;
150
229
  hub.y = Math.sin(a) * hubR;
151
- children.forEach((c, i) => { c.x = hub.x + offsets[i].x; c.y = hub.y + offsets[i].y; });
152
- LAYOUT.clusters.push({ x: hub.x, y: hub.y, radii });
230
+ LAYOUT.clusters.push({ x: hub.x, y: hub.y, radii: pack.radii });
231
+ placePack(pack, hub.x, hub.y, LAYOUT.clusters);
153
232
  angle += share;
154
233
  });
155
234
  if (big.length) LAYOUT.rings.push({ x: 0, y: 0, r: hubR });
156
235
 
157
- // 4. Childless hubs on an outer ring
158
- const leaves = hubs.filter((h) => !packs.has(h.id)).sort(byTypeThenLabel);
236
+ // 4. Childless hubs on an outer ring, and with them any node that has no parent and is none of the above
237
+ // (it would otherwise sit on the centre, under whatever else is there)
238
+ const homeless = nodes.filter((n) => n.id !== 'root' && !parentMap[n.id] && !isData(n) && !hubIds.has(n.id));
239
+ const leaves = [...hubs.filter((h) => !packs.has(h.id)), ...homeless].sort(byTypeThenLabel);
159
240
  const leafSpacing = Math.max(120, ...leaves.map((n) => labelWidth(n) + 30));
160
241
  const leafR = Math.max(hubR + maxExtent + 90, (leaves.length * leafSpacing) / (2 * Math.PI));
161
242
  leaves.forEach((n, i) => {
@@ -165,13 +246,23 @@ export function computeOrbitalLayout() {
165
246
  });
166
247
  if (leaves.length) LAYOUT.rings.push({ x: 0, y: 0, r: leafR });
167
248
 
168
- // Anything left (a child of a non-hub) sits just outside its parent
249
+ // Anything still on the centre is a child of a node the passes above did not pack (a child of a data node on the
250
+ // core ring, say): it goes in rings around its parent, with its own children in rings around it, never on one point
251
+ const placedAt = (n) => n.id === 'root' || n.x !== 0 || n.y !== 0;
252
+ const stuckUnder = new Map();
169
253
  nodes.forEach((n) => {
170
- const p = parentMap[n.id] && nodes.find((x) => x.id === parentMap[n.id]);
171
- if (!p || hubIds.has(p.id) || p.id === 'root' || isData(n) || hubIds.has(n.id)) return;
172
- const d = Math.hypot(p.x, p.y) || 1;
173
- n.x = p.x + (p.x / d) * 70;
174
- n.y = p.y + (p.y / d) * 70;
254
+ const pid = parentMap[n.id];
255
+ if (placedAt(n) || !pid) return;
256
+ (stuckUnder.get(pid) || stuckUnder.set(pid, []).get(pid)).push(n);
257
+ });
258
+ const byId = new Map(nodes.map((n) => [n.id, n]));
259
+ stuckUnder.forEach((list, pid) => {
260
+ const p = byId.get(pid);
261
+ if (!p || !placedAt(p)) return; // its parent is stuck too: it is placed with it, in the parent's pack
262
+ if (list.every(placedAt)) return; // placed already, in a pack higher up
263
+ const pack = packTree(list.sort(byTypeThenLabel), kidsOf, spacingOf, byTypeThenLabel, new Set([pid]));
264
+ LAYOUT.clusters.push({ x: p.x, y: p.y, radii: pack.radii });
265
+ placePack(pack, p.x, p.y, LAYOUT.clusters);
175
266
  });
176
267
  }
177
268
 
package/explorer/main.js CHANGED
@@ -24,6 +24,7 @@
24
24
  */
25
25
 
26
26
  import { state, nodeById, touchScene } from './state.js';
27
+ import { updateSearchStatus } from './search-status.js';
27
28
  import { render, resize, fitGraphToViewport, fitPadding, isNodeVisible, setRenderer, getRenderer, ensureFlowLoop, renderNow, holdFrames } from './render.js';
28
29
  import { createRenderer } from './renderer.js';
29
30
  import { clearFreeformPositions, layoutOrbit, loadFreeformPositions } from './layout.js';
@@ -95,6 +96,9 @@ function handleSearch(value) {
95
96
  state.camera.x = state.width / 2 - found.x * state.camera.zoom;
96
97
  state.camera.y = state.height / 2 - found.y * state.camera.zoom;
97
98
  }
99
+ updateSearchStatus(state.searchQuery, !!found);
100
+ } else {
101
+ updateSearchStatus('', false);
98
102
  }
99
103
  render();
100
104
  }
@@ -12,7 +12,8 @@ import { flowSummary } from './flows.js';
12
12
  import { clearScenario } from './scenario-ui.js';
13
13
  import { kindOfMark, fieldRows, MARK_WORDS } from './proposal-model.js';
14
14
  import { nodeMockupsHtml } from './mockups-model.js';
15
- import { collapseSheet } from './sheets.js';
15
+ import { collapseSheet, isPhone, measureCovered, onCoveredChange } from './sheets.js';
16
+ import { panIntoView } from './camera.js';
16
17
  import { liveSection, hydrateLivePhotos } from './live.js';
17
18
  import { cloudPanelHtml } from './cloud-model.js';
18
19
  import { t } from './strings.js';
@@ -94,7 +95,9 @@ function dataSummary(node) {
94
95
  }
95
96
  if (node.type === 'service') {
96
97
  const row = (e, side) => `${nm(e[side])}${e.label && e.label !== 'imports' ? ` · ${escHtml(e.label)}` : ''}`;
97
- return section('Kind:', [line(`${code(node.kind)}${node.summary ? `<div class="hx-faint">${escHtml(node.summary)}</div>` : ''}`)])
98
+ // The summary is the first sentence of the description above: shown again only when the description does not hold it
99
+ const again = node.summary && !String(node.desc || '').includes(node.summary);
100
+ return section('Kind:', [line(`${code(node.kind)}${again ? `<div class="hx-faint">${escHtml(node.summary)}</div>` : ''}`)])
98
101
  + section('Started by:', [...(node.triggers || []).map((t) => line(escHtml(t))), ...edgesOf('triggers', 'to', node.id).map((e) => line(row(e, 'from')))])
99
102
  + section('Jobs:', (node.jobs || []).map((j) => line(`${code(j.name)} · cron ${code(j.cron)}`)))
100
103
  + section('Runs:', edgesOf('triggers', 'from', node.id).map((e) => line(row(e, 'to'))))
@@ -272,8 +275,24 @@ export async function selectNode(node) {
272
275
  $('spec-drawer').classList.add('drawer-open');
273
276
  $('spec-drawer').inert = false; // closed, it waits off screen: inert, so Tab never reaches its buttons (MAP-02)
274
277
  $('drawer-backdrop').hidden = false;
278
+ keepSelectedInView();
275
279
  }
276
280
 
281
+ /**
282
+ * On a phone the node's sheet covers the bottom of the map (sheets.js): when the selected node is under it, or
283
+ * gets covered as the sheet expands, pan the map (never zoom it) so the node is in the part still showing (F32)
284
+ */
285
+ export function keepSelectedInView() {
286
+ const node = state.selectedNode;
287
+ if (!node || !state.width || !isPhone()) return;
288
+ const covered = measureCovered();
289
+ const next = panIntoView(state.camera, node, { left: 0, top: 0, right: state.width, bottom: state.height - covered }, node.r * state.camera.zoom + 16);
290
+ if (!next) return;
291
+ Object.assign(state.camera, next);
292
+ render();
293
+ }
294
+ onCoveredChange(() => keepSelectedInView());
295
+
277
296
  /** Start a run: the Start dialog of the Work panel, on the proposal that is open */
278
297
  export function startRun() {
279
298
  if (state.proposalSlug) openProposalStart(state.proposalSlug, '#drawer-run-btn');
@@ -15,6 +15,7 @@ import { createSpatialCache } from './spatial.js';
15
15
  import { createFrameScheduler, packetsOnScreen } from './frame.js';
16
16
  import { createLabelLayer } from './labels.js';
17
17
  import { measureCovered } from './sheets.js';
18
+ import { ZOOM_MIN, ZOOM_FLOOR } from './camera.js';
18
19
 
19
20
  // ---------------------------------------------------------------------------
20
21
  // Visibility and focus (decided in scene.js, kept here under their old names)
@@ -93,15 +94,15 @@ export function resize() {
93
94
  render();
94
95
  }
95
96
 
96
- /** Zoom and pan so every visible node (and its label) is on screen; `only` (a Set of ids) narrows it to those, when any are visible */
97
- export function fitGraphToViewport(padding = 40, only = null) {
98
- const { nodes, width, height, camera } = state;
97
+ /** The box the fit shows (world px) and the zoom that makes it fill the screen, before any limit; null with nothing to show */
98
+ function fitTarget(padding, only = null) {
99
+ const { nodes, width, height } = state;
99
100
  let visible = nodes.filter(isNodeVisible);
100
101
  if (only) {
101
102
  const part = visible.filter((n) => only.has(n.id));
102
103
  if (part.length) visible = part;
103
104
  }
104
- if (visible.length === 0) return;
105
+ if (visible.length === 0) return null;
105
106
  // The phone's sheets hide the bottom of the map (sheets.js): fit into the part they leave
106
107
  const mapHeight = Math.max(160, height - measureCovered());
107
108
 
@@ -118,7 +119,34 @@ export function fitGraphToViewport(padding = 40, only = null) {
118
119
 
119
120
  const availWidth = Math.max(160, width - padding * 2);
120
121
  const availHeight = Math.max(160, mapHeight - padding * 2);
121
- const targetZoom = Math.min(1.0, Math.max(0.18, Math.min(availWidth / (maxX - minX), availHeight / (maxY - minY))));
122
+ const raw = Math.min(availWidth / (maxX - minX), availHeight / (maxY - minY));
123
+ return { minX, maxX, minY, maxY, mapHeight, raw };
124
+ }
125
+
126
+ let minZoomKey = '';
127
+ let minZoomValue = ZOOM_MIN;
128
+
129
+ /**
130
+ * The lowest zoom for this map on this screen: low enough that Fit shows all of it (at most the default floor, so a small
131
+ * map keeps its limit). Hand zoom (wheel, pinch, keys) and Fit share it.
132
+ */
133
+ export function getMinZoom() {
134
+ const key = `${state.sceneVersion}|${state.width}|${state.height}|${state.view}|${measureCovered()}`;
135
+ if (key !== minZoomKey) {
136
+ minZoomKey = key;
137
+ const t = fitTarget(fitPadding());
138
+ minZoomValue = t && t.raw > 0 && Number.isFinite(t.raw) ? Math.max(ZOOM_FLOOR, Math.min(ZOOM_MIN, t.raw)) : ZOOM_MIN;
139
+ }
140
+ return minZoomValue;
141
+ }
142
+
143
+ /** Zoom and pan so every visible node (and its label) is on screen; `only` (a Set of ids) narrows it to those, when any are visible */
144
+ export function fitGraphToViewport(padding = 40, only = null) {
145
+ const { width, camera } = state;
146
+ const t = fitTarget(padding, only);
147
+ if (!t) return;
148
+ const { minX, maxX, minY, maxY, mapHeight } = t;
149
+ const targetZoom = Math.min(1.0, Math.max(ZOOM_FLOOR, t.raw));
122
150
 
123
151
  camera.zoom = targetZoom;
124
152
  camera.x = width / 2 - ((minX + maxX) / 2) * targetZoom;
@@ -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
  }
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
+ }
@@ -50,9 +50,6 @@
50
50
  --corn-bad: #fca5a5;
51
51
  --corn-info: #7dd3fc;
52
52
  --corn-ok-soft: color-mix(in srgb, var(--corn-ok) 15%, transparent);
53
- --corn-warn-soft: color-mix(in srgb, var(--corn-warn) 14%, transparent);
54
- --corn-bad-soft: color-mix(in srgb, var(--corn-bad) 12%, transparent);
55
- --corn-info-soft: color-mix(in srgb, var(--corn-info) 15%, transparent);
56
53
 
57
54
  /* Diff: what a proposal adds, changes, removes and edits (the map draws the same four) */
58
55
  --corn-added: #2dd4bf;