glassbrain 0.2.0-alpha.6 → 0.2.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +6 -7
  2. package/dist/chunks/{chunk-LMYD4QHC.js → chunk-3CNHFYHG.js} +1329 -1610
  3. package/dist/chunks/chunk-7PWRJEZT.js +35 -0
  4. package/dist/chunks/chunk-CHOCJIOD.js +1340 -0
  5. package/dist/chunks/chunk-DHYIMBHU.js +960 -0
  6. package/dist/chunks/{chunk-3SAL4526.js → chunk-NDUF3CBQ.js} +349 -989
  7. package/dist/cli/glassbrain.js +441 -230
  8. package/dist/cli/viewer.js +228 -194
  9. package/dist/core.d.ts +2 -0
  10. package/dist/core.js +54 -26
  11. package/dist/diff.d.ts +9 -1
  12. package/dist/edit.d.ts +10 -0
  13. package/dist/index.js +63 -35
  14. package/dist/internal.d.ts +1 -0
  15. package/dist/internal.js +103 -73
  16. package/dist/kinds.d.ts +23 -0
  17. package/dist/layers.d.ts +3 -1
  18. package/dist/lint-report.d.ts +70 -0
  19. package/dist/profile.d.ts +15 -3
  20. package/dist/react/DetailPanel.d.ts +31 -1
  21. package/dist/react/DetailPanel.js +8 -4
  22. package/dist/react/EdgeMark.d.ts +22 -0
  23. package/dist/react/EditPanel.d.ts +6 -6
  24. package/dist/react/GraphCanvas.d.ts +18 -5
  25. package/dist/react/GraphCanvas.js +4 -4
  26. package/dist/react/Inspector.d.ts +72 -0
  27. package/dist/react/ObjectRef.d.ts +12 -0
  28. package/dist/react/Toolbar.d.ts +10 -3
  29. package/dist/react/ZoomBoundary.d.ts +4 -0
  30. package/dist/react/camera.d.ts +7 -0
  31. package/dist/react/i18n.d.ts +2 -2
  32. package/dist/react/icons.d.ts +7 -1
  33. package/dist/react/input.d.ts +5 -3
  34. package/dist/react/useSubgraph.d.ts +15 -0
  35. package/dist/shell.d.ts +1 -0
  36. package/dist/strings.d.ts +24 -3
  37. package/dist/style.d.ts +2 -0
  38. package/dist/subgraph.d.ts +13 -0
  39. package/dist/tree.d.ts +1 -0
  40. package/dist/view.d.ts +3 -1
  41. package/package.json +1 -1
  42. package/schema/profile.schema.json +2 -2
  43. package/dist/chunks/chunk-3P34XHQ2.js +0 -244
  44. package/dist/chunks/chunk-5DEN6HXJ.js +0 -99
  45. package/dist/chunks/chunk-M3MAM2VD.js +0 -67
@@ -1,69 +1,86 @@
1
1
  import {
2
- DIFF_COLORS,
3
- DIFF_INK,
4
- EDGE_W,
5
2
  FADE_BASE,
6
3
  FADE_NAMES,
7
4
  FULL_VIEW,
5
+ SKIN_SIZE_PROPS,
6
+ anchorOf,
7
+ defaultProfile,
8
+ deriveLayers,
9
+ diffSkinStyle,
10
+ edgeFade,
11
+ edgeTraffic,
12
+ isFiltering,
13
+ kindTable,
14
+ layerView,
15
+ planSkins,
16
+ planTransition,
17
+ planeView,
18
+ projectSubgraph,
19
+ queryMarker,
20
+ resolveSpec,
21
+ resolveView,
22
+ sampleSkinStyle,
23
+ sampleTransition,
24
+ searchNodes,
25
+ solveDiffLayout,
26
+ subgraphFloors,
27
+ validateModelBySource
28
+ } from "./chunk-DHYIMBHU.js";
29
+ import {
30
+ EdgeMark,
31
+ EdgeMarks,
32
+ I,
33
+ Icon,
34
+ Inspector,
35
+ InspectorField,
36
+ NodeDot,
37
+ NodeRef,
38
+ NodeRelations,
39
+ ObjectDetails,
40
+ ObjectRef,
41
+ StringsContext,
42
+ ZoomBoundary,
43
+ childrenOf,
44
+ edgeKindHidden,
45
+ edgeMarksFor,
46
+ inspect,
47
+ installPainter,
48
+ renderMarkdown,
49
+ shapeOf,
50
+ useStrings
51
+ } from "./chunk-CHOCJIOD.js";
52
+ import {
53
+ DIFF_COLORS,
54
+ DIFF_INK,
55
+ EN,
8
56
  GK_CSS,
9
57
  LABEL_MAX_EM,
10
58
  LIGHT_THEME,
11
- NODE_BASE,
12
59
  PAST_KINDS,
13
60
  PLANE_HUES,
14
- SKIN_SIZE_PROPS,
15
61
  STEP_FLAG,
16
62
  VIRTUAL_ROOT,
17
- anchorOf,
18
63
  buildElements,
19
64
  checkEdit,
20
65
  chromeStyle,
21
66
  cls,
22
67
  defaultNodeColor,
23
- defaultProfile,
24
68
  diffModels,
25
- diffSkinStyle,
26
- edgeFade,
27
- edgeKindClass,
28
- edgeTraffic,
69
+ edgeKey,
29
70
  edgesOf,
30
71
  graphStyle,
31
72
  indexModel,
32
- isFiltering,
33
- isNarrowing,
34
73
  mixHex,
35
74
  nodeWeight,
36
- originView,
37
75
  originsOf,
38
- planSkins,
39
- planTransition,
40
- planeView,
41
76
  plateColors,
42
- queryMarker,
43
- resolveSpec,
44
- resolveView,
45
- sampleSkinStyle,
46
- sampleTransition,
47
- searchNodes,
48
- shareT,
77
+ sameEdge,
49
78
  skeletonColor,
50
- solveDiffLayout,
51
79
  stepUnion,
52
80
  themeColor,
53
81
  unionSides,
54
- untheme,
55
- validateModel
56
- } from "./chunk-3SAL4526.js";
57
- import {
58
- DetailPanel,
59
- I,
60
- Icon,
61
- StringsContext,
62
- useStrings
63
- } from "./chunk-3P34XHQ2.js";
64
- import {
65
- EN
66
- } from "./chunk-5DEN6HXJ.js";
82
+ untheme
83
+ } from "./chunk-NDUF3CBQ.js";
67
84
  import {
68
85
  LAYOUTS,
69
86
  inlinePool
@@ -75,698 +92,6 @@ import {
75
92
  // src/react/GraphCanvas.tsx
76
93
  import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo5, useRef as useRef4, useState as useState5 } from "react";
77
94
 
78
- // src/paint.ts
79
- var MIN_DOT = 2;
80
- var MIN_LINE = 1;
81
- var HOLD_LEAF = 4;
82
- var NODE_SLACK = 4;
83
- var SKEL_FLOOR = 4;
84
- var SKEL_CURVE = 1.2;
85
- var SEM_W = 1;
86
- var SEM_INK = 0.05;
87
- var SEM_BOOST = 2;
88
- var FOCUS_INK = 16;
89
- var focusAlphaOf = (n, ink = FOCUS_INK) => Math.min(1, Math.sqrt(ink / Math.max(1, n)));
90
- var DETAIL_LEAF = 6;
91
- var GAP = [3, 9];
92
- var GAP_MAX = 1.5;
93
- var HAZE_R = 1.4;
94
- var HAZE_MAX = 0.32;
95
- var HOVER_DIM = 0.4;
96
- var HOVER_FADE_MS = 160;
97
- var MUTE_FADE_MS = 240;
98
- var clamp01 = (v) => Math.max(0, Math.min(1, v));
99
- var ramp = (v, [a, b]) => clamp01((v - a) / (b - a));
100
- var dotOf = (d, z, w = 0, leafPx = Infinity, hold = HOLD_LEAF) => {
101
- const s = d * z * Math.max(1, w * hold / leafPx);
102
- return s >= MIN_DOT ? [s, 1] : [MIN_DOT, (s / MIN_DOT) ** 2];
103
- };
104
- var gapOf = (px) => GAP_MAX * ramp(px, GAP);
105
- var skeletonLineOf = (w, z, t) => {
106
- const s = Math.max(w * z, SKEL_FLOOR * t ** SKEL_CURVE);
107
- return s >= MIN_LINE ? [s, 1] : [MIN_LINE, s / MIN_LINE];
108
- };
109
- var semanticAlphaOf = (opacity, cover) => Math.min(1, opacity * Math.min(SEM_BOOST, Math.sqrt(SEM_INK / Math.max(cover, 1e-9))));
110
- var clippedLength = (ax, ay, bx, by, W, H) => {
111
- let t0 = 0, t1 = 1;
112
- const dx = bx - ax, dy = by - ay;
113
- for (const [p, q2] of [[-dx, ax], [dx, W - ax], [-dy, ay], [dy, H - ay]]) {
114
- if (p === 0) {
115
- if (q2 < 0) return 0;
116
- continue;
117
- }
118
- const r = q2 / p;
119
- if (p < 0) {
120
- if (r > t1) return 0;
121
- if (r > t0) t0 = r;
122
- } else {
123
- if (r < t0) return 0;
124
- if (r < t1) t1 = r;
125
- }
126
- }
127
- return Math.hypot(dx, dy) * (t1 - t0);
128
- };
129
- var hazeOf = (leafPx) => HAZE_MAX * (1 - ramp(leafPx, GAP));
130
- var EDGE_REACH = 0.5;
131
- var reachOf = (vis, lineW, touch = false, base = EDGE_REACH) => (base * (touch ? 2.4 : 1) + lineW / 2) * vis;
132
- var hittable = (reach) => reach * 2 >= 1;
133
- var detailed = (leafPx) => leafPx >= DETAIL_LEAF;
134
- var edgeKindHidden = (skeleton, kind, hidden) => !skeleton && hidden.has(kind);
135
- var shapeOf = (name) => /hexagon|octagon|pentagon|heptagon/.test(name) ? "hexagon" : /diamond/.test(name) ? "diamond" : /rectangle|square|barrel|tag/.test(name) ? "rect" : "circle";
136
- var arrowOf = (name) => name === "none" ? "none" : name === "tee" ? "tee" : "triangle";
137
- function installPainter(cy, opts) {
138
- const r = cy.renderer();
139
- const baseRender = r.render;
140
- const baseFind = r.findNearestElements;
141
- let nodes = [], parents = [], edges = [];
142
- let byId = /* @__PURE__ */ new Map();
143
- let stale = true;
144
- const dirty = /* @__PURE__ */ new Set();
145
- let needs = true;
146
- const readNode = (rec) => {
147
- const e = rec.ele;
148
- rec.vis = e.visible();
149
- rec.op = e.effectiveOpacity();
150
- rec.fill = e.pstyle("background-color").strValue;
151
- rec.border = e.pstyle("border-color").strValue;
152
- rec.bw = e.pstyle("border-width").pfValue;
153
- rec.d = rec.parent ? 0 : e.width();
154
- rec.shape = rec.parent ? "rect" : shapeOf(e.pstyle("shape").value);
155
- rec.bgOp = e.pstyle("background-opacity").value;
156
- rec.events = e.pstyle("events").value !== "no";
157
- };
158
- const readEdge = (rec) => {
159
- const e = rec.ele;
160
- rec.vis = e.pstyle("display").value !== "none" && e.pstyle("visibility").value === "visible";
161
- rec.op = e.effectiveOpacity() * e.pstyle("line-opacity").value;
162
- rec.color = e.pstyle("line-color").strValue;
163
- rec.w = e.pstyle("width").pfValue;
164
- rec.dash = e.pstyle("line-style").value;
165
- rec.head = arrowOf(e.pstyle("target-arrow-shape").value);
166
- rec.tail = arrowOf(e.pstyle("source-arrow-shape").value);
167
- rec.z = e.pstyle("z-index").value;
168
- const curve = e.pstyle("curve-style").value;
169
- rec.bend = curve === "unbundled-bezier" ? e.pstyle("control-point-distances").pfValue?.[0] ?? 0 : 0;
170
- rec.events = e.pstyle("events").value !== "no";
171
- };
172
- const rebuild = () => {
173
- nodes = [];
174
- parents = [];
175
- edges = [];
176
- byId = /* @__PURE__ */ new Map();
177
- cy.nodes().forEach((ele) => {
178
- const rec = {
179
- ele,
180
- id: ele.id(),
181
- parent: ele.isParent(),
182
- t: shareT(ele.data("share") ?? 0),
183
- w: nodeWeight(ele.data("leaves") ?? 0),
184
- depth: ele.ancestors().length,
185
- x: 0,
186
- y: 0,
187
- s: 0,
188
- a: 1
189
- };
190
- readNode(rec);
191
- (rec.parent ? parents : nodes).push(rec);
192
- byId.set(rec.id, rec);
193
- });
194
- parents.sort((a, b) => a.depth - b.depth);
195
- cy.edges().forEach((ele) => {
196
- const src = byId.get(ele.source().id()), tgt = byId.get(ele.target().id());
197
- if (!src || !tgt) return;
198
- const rec = { ele, id: ele.id(), src, tgt, skeleton: ele.hasClass("contains"), t: shareT(ele.data("share") ?? 0) };
199
- readEdge(rec);
200
- edges.push(rec);
201
- byId.set(rec.id, rec);
202
- });
203
- edges = byZ(edges);
204
- stale = false;
205
- dirty.clear();
206
- remute();
207
- repin();
208
- };
209
- const refresh = () => {
210
- if (stale) {
211
- rebuild();
212
- return;
213
- }
214
- if (!dirty.size) return;
215
- let reorder = false;
216
- for (const ele of dirty) {
217
- if (ele.removed()) continue;
218
- const rec = byId.get(ele.id());
219
- if (!rec) {
220
- stale = true;
221
- break;
222
- }
223
- if ("src" in rec) {
224
- const z = rec.z;
225
- readEdge(rec);
226
- if (rec.z !== z) reorder = true;
227
- } else readNode(rec);
228
- }
229
- dirty.clear();
230
- if (stale) rebuild();
231
- else if (reorder) edges = byZ(edges);
232
- };
233
- const onStyle = (e) => {
234
- const t = e.target;
235
- dirty.add(t);
236
- if (t.isNode() && t.isParent()) t.descendants().forEach((d) => dirty.add(d));
237
- needs = true;
238
- };
239
- const onStructure = () => {
240
- stale = true;
241
- needs = true;
242
- };
243
- const onMove = () => {
244
- needs = true;
245
- };
246
- cy.on("style", onStyle);
247
- cy.on("add remove data move", onStructure);
248
- cy.on("position viewport", onMove);
249
- let focusIds = /* @__PURE__ */ new Set();
250
- let lifted = /* @__PURE__ */ new Set();
251
- let semCover = 0;
252
- let hovered = null;
253
- let hoverT = 0, hoverFrom = 0, hoverTo = 0;
254
- let target = null;
255
- let spot = null;
256
- let muteKinds = { nodes: /* @__PURE__ */ new Set(), edges: /* @__PURE__ */ new Set() };
257
- let mutedIds = /* @__PURE__ */ new Set();
258
- let pinned = /* @__PURE__ */ new Set();
259
- let mutedFrom = /* @__PURE__ */ new Set();
260
- let muteT = 1, muteStart = 0;
261
- const mutedNow = () => {
262
- const out = /* @__PURE__ */ new Set();
263
- if (!muteKinds.nodes.size && !muteKinds.edges.size) return out;
264
- for (const n of [...nodes, ...parents]) if (muteKinds.nodes.has(n.ele.data("kind"))) out.add(n.id);
265
- for (const e of edges) {
266
- if (edgeKindHidden(e.skeleton, e.ele.data("kind"), muteKinds.edges) || out.has(e.src.id) || out.has(e.tgt.id)) out.add(e.id);
267
- }
268
- return out;
269
- };
270
- const remute = () => {
271
- mutedIds = mutedFrom = mutedNow();
272
- muteT = 1;
273
- };
274
- const repin = () => {
275
- const sel = cy.$(":selected");
276
- pinned = new Set(sel.nonempty() ? sel.closedNeighborhood().map((x) => x.id()) : []);
277
- };
278
- const shownIn2 = (set, id) => !set.has(id) || pinned.has(id) ? 1 : focusIds.has(id) ? smooth(hoverT) : 0;
279
- const muteOf = (id) => {
280
- const to = shownIn2(mutedIds, id);
281
- if (muteT >= 1) return to;
282
- const from = shownIn2(mutedFrom, id);
283
- return from + (to - from) * smooth(muteT);
284
- };
285
- const settleFocus = (instant) => {
286
- const live = target && !target.removed() ? target : spot?.size ? cy.collection([...spot].map((id) => cy.$id(id)).filter((x) => x.nonempty())) : null;
287
- if (live && live.nonempty()) {
288
- const one = live === target;
289
- const focus = !one ? live : target.isNode() ? target.closedNeighborhood() : target.union(target.connectedNodes());
290
- focusIds = new Set(focus.map((x) => x.id()));
291
- lifted = /* @__PURE__ */ new Set([...focusIds, ...focus.nodes().ancestors().map((x) => x.id())]);
292
- hovered = one ? target.id() : null;
293
- if (hoverTo !== 1) {
294
- hoverFrom = performance.now() - hoverT * HOVER_FADE_MS;
295
- hoverTo = 1;
296
- }
297
- } else {
298
- if (instant) {
299
- hoverT = 0;
300
- focusIds = /* @__PURE__ */ new Set();
301
- lifted = /* @__PURE__ */ new Set();
302
- hovered = null;
303
- }
304
- if (hoverTo !== 0) {
305
- hoverFrom = performance.now() - (1 - hoverT) * HOVER_FADE_MS;
306
- hoverTo = 0;
307
- }
308
- }
309
- needs = true;
310
- r.redraw();
311
- };
312
- const hover = (t, instant = false) => {
313
- target = t;
314
- settleFocus(instant);
315
- };
316
- const mute = (nodeKinds, edgeKinds) => {
317
- const same = (a, b) => a.size === b.length && b.every((k) => a.has(k));
318
- if (same(muteKinds.nodes, nodeKinds) && same(muteKinds.edges, edgeKinds)) return;
319
- muteKinds = { nodes: new Set(nodeKinds), edges: new Set(edgeKinds) };
320
- if (!stale) {
321
- const next = mutedNow();
322
- const back = muteT < 1 && next.size === mutedFrom.size && [...next].every((id) => mutedFrom.has(id));
323
- const t = back ? 1 - muteT : 0;
324
- mutedFrom = mutedIds;
325
- mutedIds = next;
326
- muteT = t;
327
- muteStart = performance.now() - t * MUTE_FADE_MS;
328
- }
329
- needs = true;
330
- r.redraw();
331
- };
332
- const onSelect = () => {
333
- repin();
334
- needs = true;
335
- r.redraw();
336
- };
337
- cy.on("select unselect", onSelect);
338
- const spotlight = (ids2) => {
339
- spot = ids2?.size ? ids2 : null;
340
- settleFocus(false);
341
- };
342
- const stepHover = (now) => {
343
- if (hoverT === hoverTo) return false;
344
- const k = Math.min(1, (now - hoverFrom) / HOVER_FADE_MS);
345
- hoverT = hoverTo ? k : 1 - k;
346
- if (k >= 1) {
347
- hoverT = hoverTo;
348
- if (!hoverTo) {
349
- focusIds = /* @__PURE__ */ new Set();
350
- lifted = /* @__PURE__ */ new Set();
351
- hovered = null;
352
- }
353
- }
354
- return true;
355
- };
356
- const stepMute = (now) => {
357
- if (muteT >= 1) return false;
358
- muteT = Math.min(1, (now - muteStart) / MUTE_FADE_MS);
359
- if (muteT >= 1) mutedFrom = mutedIds;
360
- return true;
361
- };
362
- const dimNow = () => 1 - (1 - HOVER_DIM) * smooth(hoverT);
363
- let wasActive = false;
364
- let lastSize = "";
365
- const ids = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()];
366
- const idOf = (m) => (c) => m.get(c) ?? m.set(c, m.size).get(c);
367
- const fillId = idOf(ids[0]), borderId = idOf(ids[1]), lineId = idOf(ids[2]);
368
- const paint = () => {
369
- const pr = r.getPixelRatio();
370
- if (r.prevPxRatio !== pr) {
371
- r.invalidateContainerClientCoordsCache();
372
- r.matchCanvasSize(r.container);
373
- }
374
- r.prevPxRatio = pr;
375
- const size = `${r.canvasWidth}x${r.canvasHeight}`;
376
- const now = performance.now();
377
- const hovering = stepHover(now), muting = stepMute(now);
378
- const animating = hovering || muting;
379
- if (r.hoverData?.selecting || r.touchData?.selecting) needs = true;
380
- if (!needs && !animating && size === lastSize) return;
381
- needs = false;
382
- lastSize = size;
383
- refresh();
384
- for (const m of ids) m.clear();
385
- const ctx = r.data.contexts[r.NODE];
386
- for (const c of r.data.contexts) {
387
- c.setTransform(1, 0, 0, 1, 0, 0);
388
- c.clearRect(0, 0, r.canvasWidth, r.canvasHeight);
389
- }
390
- ctx.setTransform(pr, 0, 0, pr, 0, 0);
391
- const W = r.canvasWidth / pr, H = r.canvasHeight / pr;
392
- const z = cy.zoom(), pan = cy.pan();
393
- const leafPx = NODE_BASE * opts.nodeScale() * z;
394
- const dim = dimNow();
395
- const mulOf = (id) => (hoverT > 0 && !lifted.has(id) ? dim : 1) * muteOf(id);
396
- const PAD3 = 40;
397
- const onScreen = (x, y, rad) => x + rad > -PAD3 && x - rad < W + PAD3 && y + rad > -PAD3 && y - rad < H + PAD3;
398
- const hold = HOLD_LEAF;
399
- for (const n of nodes) {
400
- if (!n.vis) continue;
401
- const p = n.ele.position();
402
- n.x = p.x * z + pan.x;
403
- n.y = p.y * z + pan.y;
404
- [n.s, n.a] = dotOf(n.d, z, n.w, leafPx, hold);
405
- }
406
- for (const n of parents) {
407
- if (!n.vis) continue;
408
- const bb = n.ele.boundingBox({ includeLabels: false, includeOverlays: false, includeUnderlays: false });
409
- n.box = [bb.x1 * z + pan.x, bb.y1 * z + pan.y, bb.w * z, bb.h * z];
410
- n.x = n.box[0] + n.box[2] / 2;
411
- n.y = n.box[1] + n.box[3] / 2;
412
- n.s = 0;
413
- n.a = 1;
414
- }
415
- ctx.lineJoin = "round";
416
- drawBoxes(ctx, z, mulOf);
417
- const haze = hazeOf(leafPx);
418
- if (haze > 5e-3) drawHaze(ctx, z, haze, mulOf, onScreen);
419
- let ink = 0;
420
- for (const e of edges) {
421
- if (e.skeleton || !e.vis || !e.src.vis || !e.tgt.vis) continue;
422
- ink += clippedLength(e.src.x, e.src.y, e.tgt.x, e.tgt.y, W, H) * (SEM_W * e.w / EDGE_W) * e.op;
423
- }
424
- semCover = ink / (W * H);
425
- drawEdges(ctx, edges, z, leafPx, mulOf, W, H, false);
426
- drawNodes(ctx, nodes, mulOf, onScreen);
427
- if (hoverT > 0 && focusIds.size) {
428
- drawEdges(ctx, edges.filter((e) => focusIds.has(e.id)), z, leafPx, () => 1, W, H, true);
429
- drawNodes(ctx, nodes.filter((n) => focusIds.has(n.id)), () => 1, onScreen);
430
- const h = hovered ? byId.get(hovered) : null;
431
- if (h && !("src" in h) && !h.parent && h.vis) {
432
- ctx.globalAlpha = 0.5 * smooth(hoverT);
433
- ctx.strokeStyle = opts.theme().halo;
434
- ctx.lineWidth = 2;
435
- ctx.beginPath();
436
- ctx.arc(h.x, h.y, h.s / 2 + gapOf(h.s) + 3, 0, Math.PI * 2);
437
- ctx.stroke();
438
- }
439
- }
440
- drawSelectionBox(ctx, z, pan);
441
- ctx.globalAlpha = 1;
442
- if (animating) queueMicrotask(() => r.redraw());
443
- };
444
- const drawBoxes = (ctx, z, mulOf) => {
445
- for (const n of parents) {
446
- if (!n.vis || !n.box) continue;
447
- const m = n.op * mulOf(n.id);
448
- if (m < 0.01) continue;
449
- const [x, y, w, h] = n.box;
450
- const rad = Math.min(10, w / 4, h / 4);
451
- ctx.beginPath();
452
- ctx.roundRect(x, y, w, h, rad);
453
- ctx.globalAlpha = n.bgOp * m;
454
- ctx.fillStyle = n.fill;
455
- ctx.fill();
456
- const [lw, la] = skeletonLineOf(n.bw, z, n.t);
457
- ctx.globalAlpha = la * m;
458
- ctx.strokeStyle = n.border;
459
- ctx.lineWidth = lw;
460
- ctx.stroke();
461
- }
462
- };
463
- const drawHaze = (ctx, z, haze, mulOf, onScreen) => {
464
- const groups = /* @__PURE__ */ new Map();
465
- for (const n of nodes) {
466
- if (!n.vis) continue;
467
- const rad = n.d * HAZE_R * z;
468
- if (!onScreen(n.x, n.y, rad)) continue;
469
- const a = q(haze * n.op * mulOf(n.id), 0.02);
470
- if (a < 0.01) continue;
471
- const key = fillId(n.fill) * 64 + Math.round(a * 50);
472
- let g = groups.get(key);
473
- if (!g) groups.set(key, g = { c: n.fill, a, list: [] });
474
- g.list.push(n);
475
- }
476
- for (const g of groups.values()) {
477
- ctx.globalAlpha = g.a;
478
- ctx.fillStyle = g.c;
479
- ctx.beginPath();
480
- for (const n of g.list) {
481
- const rad = n.d * HAZE_R * z;
482
- ctx.moveTo(n.x + rad, n.y);
483
- ctx.arc(n.x, n.y, rad, 0, Math.PI * 2);
484
- }
485
- ctx.fill();
486
- }
487
- };
488
- const drawEdges = (ctx, list, z, leafPx, mulOf, W, H, focus) => {
489
- const near = detailed(leafPx);
490
- const semA = semanticAlphaOf(opts.semanticOpacity(), semCover);
491
- const focusA = focus ? focusAlphaOf(list.reduce((k, e) => k + (e.skeleton ? 0 : 1), 0)) : 0;
492
- let layer = null;
493
- let groups = /* @__PURE__ */ new Map();
494
- const flush = () => {
495
- for (const g of groups.values()) strokeGroup(ctx, g, z, near);
496
- groups = /* @__PURE__ */ new Map();
497
- };
498
- for (const e of list) {
499
- if (!e.vis || !e.src.vis || !e.tgt.vis) continue;
500
- const a = e.src, b = e.tgt;
501
- if (Math.max(a.x, b.x) < -40 || Math.min(a.x, b.x) > W + 40 || Math.max(a.y, b.y) < -40 || Math.min(a.y, b.y) > H + 40) continue;
502
- if (e.z !== layer) {
503
- flush();
504
- layer = e.z;
505
- }
506
- let w, al;
507
- if (e.skeleton) [w, al] = skeletonLineOf(e.w, z, e.t);
508
- else [w, al] = [SEM_W * e.w / EDGE_W, focus ? focusA : semA];
509
- al *= e.op * mulOf(e.id);
510
- if (al < 0.01) continue;
511
- const wq = q(w, 0.25) || 0.25, aq = q(al, 0.05) || 0.05;
512
- const dash = e.dash === "solid" || !near ? 0 : e.dash === "dashed" ? 1 : 2;
513
- const key = ((lineId(e.color) * 4096 + Math.round(wq * 4)) * 32 + Math.round(aq * 20)) * 3 + dash;
514
- let g = groups.get(key);
515
- if (!g) groups.set(key, g = { c: e.color, w: wq, a: aq, dash, list: [] });
516
- g.list.push(e);
517
- }
518
- flush();
519
- ctx.setLineDash([]);
520
- };
521
- const drawNodes = (ctx, list, mulOf, onScreen) => {
522
- const groups = /* @__PURE__ */ new Map();
523
- const marked = [];
524
- for (const n of list) {
525
- if (!n.vis || !onScreen(n.x, n.y, n.s)) continue;
526
- const a = q(n.a * n.op * mulOf(n.id), 0.05);
527
- if (a < 0.01) continue;
528
- const gap = q(gapOf(n.s), 0.25);
529
- const shapeK = n.shape === "circle" ? 0 : n.shape === "hexagon" ? 1 : n.shape === "diamond" ? 2 : 3;
530
- const key = (((fillId(n.fill) * 65536 + borderId(n.border)) * 32 + Math.round(a * 20)) * 8 + gap * 4) * 4 + shapeK;
531
- let g = groups.get(key);
532
- if (!g) groups.set(key, g = { c: n.fill, border: n.border, a, gap, shape: n.shape, list: [] });
533
- g.list.push(n);
534
- if (n.bw > 1.5) marked.push(n);
535
- }
536
- for (const g of groups.values()) {
537
- ctx.globalAlpha = g.a;
538
- ctx.beginPath();
539
- for (const n of g.list) tracePoint(ctx, g.shape, n.x, n.y, n.s / 2);
540
- if (g.gap > 0) {
541
- ctx.strokeStyle = g.border;
542
- ctx.lineWidth = g.gap * 2;
543
- ctx.stroke();
544
- }
545
- ctx.fillStyle = g.c;
546
- ctx.fill();
547
- }
548
- for (const n of marked) {
549
- ctx.globalAlpha = n.op * mulOf(n.id);
550
- ctx.strokeStyle = n.border;
551
- ctx.lineWidth = 2;
552
- ctx.beginPath();
553
- tracePoint(ctx, n.shape, n.x, n.y, n.s / 2 + gapOf(n.s) + 1.5);
554
- ctx.stroke();
555
- }
556
- };
557
- const drawSelectionBox = (ctx, z, pan) => {
558
- const sel = r.selection;
559
- if (!sel || sel[4] !== 1 || !(r.hoverData?.selecting || r.touchData?.selecting)) return;
560
- const t = opts.theme();
561
- const x = sel[0] * z + pan.x, y = sel[1] * z + pan.y, w = (sel[2] - sel[0]) * z, h = (sel[3] - sel[1]) * z;
562
- ctx.globalAlpha = 0.15;
563
- ctx.fillStyle = t.selected;
564
- ctx.fillRect(x, y, w, h);
565
- ctx.globalAlpha = 0.6;
566
- ctx.strokeStyle = t.selected;
567
- ctx.lineWidth = 1;
568
- ctx.strokeRect(x, y, w, h);
569
- };
570
- const find = (mx, my, interactiveOnly, isTouch) => {
571
- refresh();
572
- const z = cy.zoom(), pan = cy.pan();
573
- const sx = mx * z + pan.x, sy = my * z + pan.y;
574
- const slack = isTouch ? 10 : NODE_SLACK;
575
- const leafPx = NODE_BASE * opts.nodeScale() * z;
576
- const usable = (x) => x.vis && x.op > 0.05 && (!interactiveOnly || x.events) && muteOf(x.id) > 0.5;
577
- let best = null, bestD = Infinity;
578
- for (const n of nodes) {
579
- if (!usable(n)) continue;
580
- const p = n.ele.position();
581
- const x = p.x * z + pan.x, y = p.y * z + pan.y;
582
- const rad = dotOf(n.d, z, n.w, leafPx)[0] / 2 + slack;
583
- const d = Math.hypot(sx - x, sy - y);
584
- if (d <= rad && d - rad < bestD) {
585
- best = n.ele;
586
- bestD = d - rad;
587
- }
588
- }
589
- if (best) return [best];
590
- const semReach = reachOf(semanticAlphaOf(1, semCover), SEM_W, isTouch);
591
- for (const e of edges) {
592
- if (!usable(e) || !e.src.vis || !e.tgt.vis) continue;
593
- let reach = semReach * Math.max(1, e.w / EDGE_W);
594
- if (e.skeleton) {
595
- const [lw, la] = skeletonLineOf(e.w, z, e.t);
596
- reach = reachOf(la, lw, isTouch);
597
- }
598
- const a = e.src.ele.position(), b = e.tgt.ele.position();
599
- const d = distToEdge(sx, sy, a.x * z + pan.x, a.y * z + pan.y, b.x * z + pan.x, b.y * z + pan.y, e.bend * z);
600
- if (hittable(reach) && d <= reach && d - reach < bestD) {
601
- best = e.ele;
602
- bestD = d - reach;
603
- }
604
- }
605
- if (best) return [best];
606
- for (let i = parents.length - 1; i >= 0; i--) {
607
- const n = parents[i];
608
- if (!usable(n)) continue;
609
- const bb = n.ele.boundingBox({ includeLabels: false, includeOverlays: false, includeUnderlays: false });
610
- if (mx >= bb.x1 && mx <= bb.x2 && my >= bb.y1 && my <= bb.y2) return [n.ele];
611
- }
612
- return [];
613
- };
614
- r.render = function render(options) {
615
- const active = opts.active() && !options?.forcedContext;
616
- if (active !== wasActive) {
617
- wasActive = active;
618
- needs = true;
619
- if (!active) {
620
- r.redrawHint("eles", true);
621
- r.redrawHint("drag", true);
622
- }
623
- }
624
- if (!active) return baseRender.call(r, options);
625
- paint();
626
- cy.emit("render");
627
- };
628
- r.findNearestElements = function findNearestElements(x, y, interactiveOnly, isTouch) {
629
- if (!opts.active()) return baseFind.call(r, x, y, interactiveOnly, isTouch);
630
- return find(x, y, interactiveOnly, isTouch);
631
- };
632
- r.redraw();
633
- return {
634
- hover,
635
- spotlight,
636
- focused: (id) => hoverTo === 1 && focusIds.has(id),
637
- hoveredId: () => hoverTo === 1 ? hovered : null,
638
- dimOf: (id) => (hoverT > 0 && !lifted.has(id) ? dimNow() : 1) * muteOf(id),
639
- mute,
640
- // Reads the hover **target**, not how far the fade has gone: when hover changes, the text layer must lay out the brought-out set at once.
641
- hidden: (id) => mutedIds.has(id) && !pinned.has(id) && !(hoverTo === 1 && focusIds.has(id)),
642
- radiusOf: (id) => {
643
- if (!opts.active()) return null;
644
- refresh();
645
- const n = byId.get(id);
646
- if (!n || "src" in n || n.parent) return null;
647
- const z = cy.zoom();
648
- return dotOf(n.d, z, n.w, NODE_BASE * opts.nodeScale() * z)[0] / 2;
649
- },
650
- repaint: () => {
651
- needs = true;
652
- r.redraw();
653
- },
654
- dispose: () => {
655
- cy.off("style", onStyle);
656
- cy.off("add remove data move", onStructure);
657
- cy.off("position viewport", onMove);
658
- cy.off("select unselect", onSelect);
659
- if (!cy.destroyed()) {
660
- r.render = baseRender;
661
- r.findNearestElements = baseFind;
662
- }
663
- }
664
- };
665
- }
666
- var q = (v, step) => Math.round(v / step) * step;
667
- var byZ = (list) => list.map((e, i) => [e, i]).sort((a, b) => a[0].z - b[0].z || a[1] - b[1]).map(([e]) => e);
668
- var smooth = (x) => x * x * (3 - 2 * x);
669
- var controlOf = (ax, ay, bx, by, bend) => {
670
- const dx = bx - ax, dy = by - ay, L = Math.hypot(dx, dy) || 1;
671
- return [(ax + bx) / 2 - dy / L * bend, (ay + by) / 2 + dx / L * bend];
672
- };
673
- function strokeGroup(ctx, g, z, near) {
674
- ctx.globalAlpha = Math.min(1, g.a);
675
- ctx.strokeStyle = g.c;
676
- ctx.lineWidth = g.w;
677
- ctx.lineCap = "round";
678
- ctx.setLineDash(g.dash === 1 ? [4, 3] : g.dash === 2 ? [1, 3] : []);
679
- ctx.beginPath();
680
- const heads = [];
681
- for (const e of g.list) {
682
- const ax = e.src.x, ay = e.src.y, bx = e.tgt.x, by = e.tgt.y;
683
- ctx.moveTo(ax, ay);
684
- let hx = bx - ax, hy = by - ay, tx = ax - bx, ty = ay - by;
685
- if (e.bend) {
686
- const [cx, cy] = controlOf(ax, ay, bx, by, e.bend * z);
687
- ctx.quadraticCurveTo(cx, cy, bx, by);
688
- hx = bx - cx;
689
- hy = by - cy;
690
- tx = ax - cx;
691
- ty = ay - cy;
692
- } else ctx.lineTo(bx, by);
693
- const show = e.skeleton ? g.w >= 1.5 : near && Math.hypot(bx - ax, by - ay) > 40;
694
- if (!show) continue;
695
- if (e.head !== "none") heads.push([e, bx, by, hx, hy, true]);
696
- if (e.tail !== "none") heads.push([e, ax, ay, tx, ty, false]);
697
- }
698
- ctx.stroke();
699
- if (!heads.length) return;
700
- ctx.setLineDash([]);
701
- ctx.fillStyle = g.c;
702
- ctx.beginPath();
703
- const tees = [];
704
- for (const [e, px, py, ux0, uy0, atHead] of heads) {
705
- const L = Math.hypot(ux0, uy0) || 1, ux = ux0 / L, uy = uy0 / L;
706
- const n = atHead ? e.tgt : e.src;
707
- const rad = n.parent ? 0 : n.s / 2 + gapOf(n.s);
708
- const tipX = px - ux * rad, tipY = py - uy * rad;
709
- const len = e.skeleton ? g.w * 2.6 : 3 + g.w * 2.5, half = len * 0.55;
710
- if ((atHead ? e.head : e.tail) === "tee") {
711
- tees.push([tipX, tipY, ux, uy, half]);
712
- continue;
713
- }
714
- ctx.moveTo(tipX, tipY);
715
- ctx.lineTo(tipX - ux * len - uy * half, tipY - uy * len + ux * half);
716
- ctx.lineTo(tipX - ux * len + uy * half, tipY - uy * len - ux * half);
717
- ctx.closePath();
718
- }
719
- ctx.fill();
720
- if (tees.length) {
721
- ctx.beginPath();
722
- for (const [x, y, ux, uy, half] of tees) {
723
- const cx = x - ux * 2, cy = y - uy * 2;
724
- ctx.moveTo(cx - uy * half, cy + ux * half);
725
- ctx.lineTo(cx + uy * half, cy - ux * half);
726
- }
727
- ctx.lineWidth = Math.max(1.5, g.w);
728
- ctx.stroke();
729
- }
730
- }
731
- function tracePoint(ctx, shape, x, y, rad) {
732
- if (shape === "circle") {
733
- ctx.moveTo(x + rad, y);
734
- ctx.arc(x, y, rad, 0, Math.PI * 2);
735
- return;
736
- }
737
- if (shape === "rect") {
738
- ctx.rect(x - rad, y - rad, rad * 2, rad * 2);
739
- return;
740
- }
741
- const n = shape === "hexagon" ? 6 : 4;
742
- const off = shape === "diamond" ? -Math.PI / 2 : 0;
743
- for (let i = 0; i < n; i++) {
744
- const t = off + i * 2 * Math.PI / n;
745
- const px = x + rad * Math.cos(t), py = y + rad * Math.sin(t);
746
- if (i === 0) ctx.moveTo(px, py);
747
- else ctx.lineTo(px, py);
748
- }
749
- ctx.closePath();
750
- }
751
- function distToEdge(px, py, ax, ay, bx, by, bend) {
752
- if (!bend) return distToSeg(px, py, ax, ay, bx, by);
753
- const [cx, cy] = controlOf(ax, ay, bx, by, bend);
754
- let best = Infinity, lx = ax, ly = ay;
755
- for (let i = 1; i <= 8; i++) {
756
- const t = i / 8, u = 1 - t;
757
- const x = u * u * ax + 2 * u * t * cx + t * t * bx, y = u * u * ay + 2 * u * t * cy + t * t * by;
758
- best = Math.min(best, distToSeg(px, py, lx, ly, x, y));
759
- lx = x;
760
- ly = y;
761
- }
762
- return best;
763
- }
764
- function distToSeg(px, py, ax, ay, bx, by) {
765
- const dx = bx - ax, dy = by - ay, L2 = dx * dx + dy * dy;
766
- const t = L2 ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / L2)) : 0;
767
- return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
768
- }
769
-
770
95
  // src/layout/divide.ts
771
96
  var isEdge = (el) => !!el.data.source;
772
97
  var isAttached = (el) => el.data._struct === false;
@@ -940,12 +265,12 @@ function readOrder(elements) {
940
265
  }
941
266
  const orderedKids = /* @__PURE__ */ new Map();
942
267
  let any = false;
943
- for (const [parent, list] of kids) {
944
- if (list.length < 2 || list.some((k) => k.order === null)) continue;
945
- const sorted = [...list].sort((a, b) => a.order - b.order).map((k) => k.id);
268
+ for (const [parent, list2] of kids) {
269
+ if (list2.length < 2 || list2.some((k) => k.order === null)) continue;
270
+ const sorted = [...list2].sort((a, b) => a.order - b.order).map((k) => k.id);
946
271
  const seen = /* @__PURE__ */ new Set();
947
272
  let unique = true;
948
- for (const k of list) {
273
+ for (const k of list2) {
949
274
  if (seen.has(k.order)) {
950
275
  unique = false;
951
276
  break;
@@ -976,8 +301,8 @@ function orderSeed(elements, info, dims = {}, random = Math.random) {
976
301
  const gap = LAYOUTS["cose-bilkent"].opts.idealEdgeLength;
977
302
  const children = /* @__PURE__ */ new Map();
978
303
  for (const [id, parent] of info.parentOf) {
979
- const list = children.get(parent);
980
- list ? list.push(id) : children.set(parent, [id]);
304
+ const list2 = children.get(parent);
305
+ list2 ? list2.push(id) : children.set(parent, [id]);
981
306
  }
982
307
  const diameter = (id) => {
983
308
  const d = dims[id];
@@ -1000,10 +325,10 @@ function orderSeed(elements, info, dims = {}, random = Math.random) {
1000
325
  };
1001
326
  const out = {};
1002
327
  const placeChildren = (parent, ids, parentRadius, sector) => {
1003
- const list = info.orderedKids.get(parent ?? VIRTUAL_PARENT) ?? shuffled(ids, random);
1004
- if (!list.length) return;
1005
- const span = sector ? (sector.to - sector.from) / list.length : TAU / (list.length + 1);
1006
- list.forEach((id, i) => {
328
+ const list2 = info.orderedKids.get(parent ?? VIRTUAL_PARENT) ?? shuffled(ids, random);
329
+ if (!list2.length) return;
330
+ const span = sector ? (sector.to - sector.from) / list2.length : TAU / (list2.length + 1);
331
+ list2.forEach((id, i) => {
1007
332
  const middle2 = sector ? sector.from + (i + 0.5) * span : -Math.PI / 2 + (i + 1) * span;
1008
333
  const angle = middle2 + offset(span);
1009
334
  const clearance = gap + (diameter(parent ?? VIRTUAL_PARENT) + diameter(id)) / 2;
@@ -1155,7 +480,7 @@ async function runDivide(req, aborted) {
1155
480
  if (req.seed) {
1156
481
  const seed2 = req.seed;
1157
482
  const compByKey = new Map(comps.map((c) => [c.key, c]));
1158
- const mid = (pts) => pts.length ? { x: pts.reduce((s, q2) => s + q2.x, 0) / pts.length, y: pts.reduce((s, q2) => s + q2.y, 0) / pts.length } : void 0;
483
+ const mid = (pts) => pts.length ? { x: pts.reduce((s, q) => s + q.x, 0) / pts.length, y: pts.reduce((s, q) => s + q.y, 0) / pts.length } : void 0;
1159
484
  for (const el of coarseEls) {
1160
485
  if (el.data.source) continue;
1161
486
  const key = el.data.id;
@@ -1603,12 +928,254 @@ function idPhase(id) {
1603
928
  return (h >>> 0) % 6283 / 1e3;
1604
929
  }
1605
930
 
931
+ // src/react/useSubgraph.ts
932
+ import { useMemo } from "react";
933
+ function useSubgraph(props, view, force) {
934
+ const base = props.profile ?? defaultProfile;
935
+ const before = props.diff?.before ?? props.compareWith?.model;
936
+ const after = props.diff?.after ?? props.editModel ?? props.model;
937
+ const active = !!(view.subtree || view.origins?.length);
938
+ const priorRoot = useMemo(() => {
939
+ if (view.subtree && before && !before.index.has(view.subtree)) {
940
+ if (props.diff) {
941
+ for (const [old, now2] of props.diff.resolved) if (now2 === view.subtree) return old;
942
+ } else {
943
+ const key = props.compareWith?.options?.key;
944
+ const root = after.index.get(view.subtree);
945
+ if (key && root) {
946
+ const identity = key(root);
947
+ return before.nodes.find((n) => key(n) === identity)?.id ?? view.subtree;
948
+ }
949
+ }
950
+ }
951
+ return view.subtree;
952
+ }, [after, before, props.diff, props.compareWith, view.subtree]);
953
+ const current = useMemo(() => projectSubgraph(after, view), [after, view.subtree, view.origins]);
954
+ const previous = useMemo(
955
+ () => before && projectSubgraph(before, { subtree: priorRoot, origins: view.origins }),
956
+ [before, priorRoot, view.origins]
957
+ );
958
+ const colors = useMemo(() => base.layers.map((l) => l.color ?? ""), [base.layers]);
959
+ const localFloors = active && (base.structuralLayers ?? base.layers.length <= 1);
960
+ const now = useMemo(() => localFloors ? subgraphFloors(current, colors, force) : null, [current, localFloors, colors, force]);
961
+ const past = useMemo(() => localFloors && previous ? subgraphFloors(previous, colors, force) : null, [previous, localFloors, colors, force]);
962
+ const profile = useMemo(() => {
963
+ if (!now) return base;
964
+ const ids = new Set(now.layers.map((l) => l.id));
965
+ const layers = now.layers.concat((past?.layers ?? []).filter((l) => !ids.has(l.id)));
966
+ return { ...base, layers: layers.length ? layers : defaultProfile.layers };
967
+ }, [base, now, past]);
968
+ const delta = useMemo(() => {
969
+ if (!previous) return null;
970
+ if (!active && props.diff) return props.diff;
971
+ return diffModels(
972
+ past?.model ?? previous,
973
+ now?.model ?? current,
974
+ props.diff?.options ?? props.compareWith?.options ?? { labels: props.diff?.labels, ignore: props.diff?.ignore, key: props.matchKey }
975
+ );
976
+ }, [previous, active, props.diff, props.compareWith, props.matchKey, past, now, current]);
977
+ const model = useMemo(() => {
978
+ if (delta) return delta.model;
979
+ if (!now) return active ? current : props.model;
980
+ const { model: model2, anchor } = now;
981
+ return layerView(model2, view.planes === false ? void 0 : anchor);
982
+ }, [delta, props.model, active, current, now, view.planes]);
983
+ const canForce = useMemo(() => !!now && !now.layers.length && !force && deriveLayers(current, [], true).layers.length >= 2, [now, current, force]);
984
+ const origins = useMemo(() => [.../* @__PURE__ */ new Set([...props.sourceFiles ?? [], ...originsOf(after), ...before ? originsOf(before) : []])].sort(), [props.sourceFiles, after, before]);
985
+ return { active, before, after, current, model, delta, profile, origins, canForce };
986
+ }
987
+
1606
988
  // src/react/Toolbar.tsx
1607
- import { useEffect, useLayoutEffect as useLayoutEffect2, useMemo, useRef, useState as useState2 } from "react";
989
+ import { useId, useEffect, useLayoutEffect as useLayoutEffect2, useRef, useState as useState2 } from "react";
990
+
991
+ // src/shell.ts
992
+ var shellArg = (s) => "'" + s.replace(/'/g, `'"'"'`) + "'";
993
+
994
+ // src/lint-report.ts
995
+ var headings = {
996
+ "bad-structure": "Sibling subtrees differ in shape or node kind.",
997
+ "wide-node": "These parent nodes have many direct children.",
998
+ "duplicate-edge": "Multiple edge records have the same source ID, kind and target ID.",
999
+ "dangling-edge": "An edge references a missing node ID. Add the node or correct the endpoint.",
1000
+ "field-conflict": "Choose one value for the conflicting node field.",
1001
+ "children-conflict": "Use the same ordered child IDs in each declaration, with each child listed once.",
1002
+ "parent-error": "Repair the parent\u2013child placement.",
1003
+ "duplicate-id": "Resolve conflicting definitions of a node ID.",
1004
+ "schema": "Check the named fields against the graph or profile format.",
1005
+ "kind-note": "Review kind names. Merge synonyms and keep distinct meanings.",
1006
+ "uncolored-kind": "Assign a distinct color to each listed node kind.",
1007
+ "coverage-note": "These leaf nodes have no `description`. Add a sentence explaining each one.",
1008
+ "color-note": "These node kinds have similar colors. Make one lighter or darker."
1009
+ };
1010
+ function delimiter(text, minimum) {
1011
+ let length = minimum;
1012
+ for (const run of text.matchAll(/`+/g)) length = Math.max(length, run[0].length + 1);
1013
+ return "`".repeat(length);
1014
+ }
1015
+ function codeBlock(text, indent, language = "") {
1016
+ const fence = delimiter(text, 3);
1017
+ return [indent + fence + language, ...text.split("\n").map((line) => indent + line), indent + fence];
1018
+ }
1019
+ function literal(value) {
1020
+ const text = /[\u0000-\u001f]|^\s|\s$|^$/.test(value) ? JSON.stringify(value) : value;
1021
+ const fence = delimiter(text, 1);
1022
+ const pad = text.startsWith("`") || text.endsWith("`") ? " " : "";
1023
+ return fence + pad + text + pad + fence;
1024
+ }
1025
+ function plain(value) {
1026
+ return value.replace(/[\\`*_\[\]<>#&~!|]/g, "\\$&").replace(/[\r\n]+/g, " ");
1027
+ }
1028
+ var list = (values) => values.map(literal).join(", ");
1029
+ function groupBy(items, keyOf) {
1030
+ const groups = /* @__PURE__ */ new Map();
1031
+ for (const item of items) {
1032
+ const key = keyOf(item);
1033
+ const group = groups.get(key);
1034
+ if (group) group.push(item);
1035
+ else groups.set(key, [item]);
1036
+ }
1037
+ return groups;
1038
+ }
1039
+ function duplicateLines(edges) {
1040
+ const lines = [];
1041
+ const batches = [...groupBy(edges, (e) => JSON.stringify([e.differing, e.count, e.files])).values()];
1042
+ for (const group of batches.sort((a, b) => Number(b[0].differing) - Number(a[0].differing))) {
1043
+ const { differing, count, files } = group[0];
1044
+ const redundant = group.length * (count - 1);
1045
+ const action = differing ? "Attributes differ. Decide which values to retain before merging." : `Remove ${redundant} identical ${redundant === 1 ? "copy" : "copies"}, leaving one record per edge.`;
1046
+ lines.push(` - ${group.length} ${group.length === 1 ? "edge" : "edges"}, ${count} copies each${files.length ? (files.length === 1 ? " in " : " across ") + list(files) : ""}. ${action}`);
1047
+ for (const [source, outgoing] of groupBy(group, (e) => e.source)) {
1048
+ const targets = [...groupBy(outgoing, (e) => JSON.stringify(e.kind ?? null)).values()].map((sameKind) => {
1049
+ const kind = sameKind[0].kind;
1050
+ return `${kind === void 0 ? "(no kind)" : literal(kind)} \u2192 ${list(sameKind.map((e) => e.target))}`;
1051
+ });
1052
+ lines.push(` - From node ID ${literal(source)}: ${targets.join(" | ")}`);
1053
+ for (const edge of outgoing) for (const diff of edge.differences ?? []) {
1054
+ const values = diff.copies.map((c) => (c.value === void 0 ? "(absent)" : literal(c.value)) + (c.file ? " in " + literal(c.file) : ""));
1055
+ lines.push(` - ${edge.kind ? "Kind " + literal(edge.kind) + ", " : ""}target ID ${literal(edge.target)}, field ${literal(diff.field)}: ${values.join(" / ")}.`);
1056
+ }
1057
+ }
1058
+ }
1059
+ return lines;
1060
+ }
1061
+ function ruleLines(rows, input) {
1062
+ const lines = [];
1063
+ const duplicates = [];
1064
+ const uneven = [];
1065
+ for (const f of rows) {
1066
+ const d = f.facts;
1067
+ const place = f.where && f.scope !== "graph" ? literal(f.where) : "";
1068
+ const location = place ? " in " + (f.scope === "version" ? "version " : "") + place : "";
1069
+ switch (d?.type) {
1070
+ case "duplicate":
1071
+ duplicates.push(d);
1072
+ break;
1073
+ case "uneven":
1074
+ uneven.push(f);
1075
+ break;
1076
+ case "wide":
1077
+ lines.push(` - Node ID ${literal(f.node)}: ${d.count} direct children${d.layers ? " (floors; check that each is a major section)" : ""}.`);
1078
+ break;
1079
+ case "dangling":
1080
+ lines.push(` - Source ID ${literal(d.source)} \u2192 target ID ${literal(d.target)}${d.kind ? ", edge kind " + literal(d.kind) : ""}${location}. Missing: ${list(d.missing)}.`);
1081
+ break;
1082
+ case "misplaced":
1083
+ lines.push(` - On node ID ${literal(f.node)}${location}, move ${list(d.fields)} out of \`data\` and beside \`id\`.`);
1084
+ break;
1085
+ case "palette":
1086
+ case "colors": {
1087
+ const target = d.target ?? { file: "_profile.json", field: "nodePalette" };
1088
+ lines.push(` - In ${literal(target.file)}, edit ${literal(target.field)} for node kinds: ${list(d.kinds)}`);
1089
+ break;
1090
+ }
1091
+ case "coverage":
1092
+ lines.push(" - Leaf node IDs: " + list(d.leaves));
1093
+ break;
1094
+ case "vocabulary":
1095
+ lines.push(` - ${d.space === "node" ? "Node" : "Edge"} kinds (${d.kinds.length}): ${list(d.kinds)}`);
1096
+ break;
1097
+ default:
1098
+ lines.push(" - " + (place ? (f.scope === "version" ? "Version " : "File ") + place + ": " : "") + plain(f.message));
1099
+ if (f.fix) {
1100
+ const [action, ...example] = f.fix.split("\n");
1101
+ lines.push(" - " + plain(action));
1102
+ if (example.length) lines.push(...codeBlock(example.join("\n"), " "));
1103
+ }
1104
+ }
1105
+ }
1106
+ if (uneven.length) {
1107
+ const example = uneven[0];
1108
+ lines.push(" - Parent node IDs: " + list(uneven.map((f) => f.node)));
1109
+ if (example.facts?.type === "uneven" && example.facts.closest) {
1110
+ const { a, b } = example.facts.closest;
1111
+ lines.push(` - Example: Under the node with ID ${literal(example.node)}, child nodes ${literal(a)} and ${literal(b)} have the most similar subtrees.`);
1112
+ }
1113
+ const commands = [
1114
+ "glassbrain tree " + shellArg(input) + " --path " + shellArg(example.node),
1115
+ "glassbrain restructure " + shellArg(input) + " --dry-run"
1116
+ ].join("\n");
1117
+ lines.push(
1118
+ " - If two siblings share a subject, move both under a new group node. Inspect and preview:",
1119
+ ...codeBlock(commands, " ", "sh")
1120
+ );
1121
+ const pairs = uneven.slice(1).flatMap((f) => f.facts?.type === "uneven" && f.facts.closest ? [`${literal(f.node)} \u2192 ${list([f.facts.closest.a, f.facts.closest.b])}`] : []);
1122
+ if (pairs.length) {
1123
+ lines.push(" - Other pairs to inspect (parent node ID \u2192 two child node IDs):");
1124
+ for (const pair of pairs) lines.push(" - " + pair);
1125
+ }
1126
+ }
1127
+ if (rows.some((f) => f.facts?.type === "wide" && !f.facts.layers)) lines.push(" - Group children by subject where useful. Keep a natural collection together.");
1128
+ if (duplicates.length) {
1129
+ lines.push(" - Each source below lists edge kind \u2192 target node IDs.");
1130
+ for (const line of duplicateLines(duplicates)) lines.push(line);
1131
+ }
1132
+ return lines;
1133
+ }
1134
+ var severities = [["error", "Errors"], ["warn", "Warnings"], ["info", "Info"]];
1135
+ function reportText(found, input, versions = 1) {
1136
+ const lines = ["# Graph lint"];
1137
+ if (versions > 1) lines.push(`${versions} versions checked. Quality warnings apply to the latest version.`);
1138
+ for (const [level, heading] of severities) {
1139
+ const findings = found.filter((f) => f.level === level);
1140
+ const policy = { error: "Blocks export.", warn: "Fails lint with `--strict`.", info: "Advisory. Info alone passes lint, including with `--strict`." };
1141
+ lines.push(`## ${heading} (${findings.length})${findings.length ? " \u2014 " + policy[level] : ""}`);
1142
+ const groups = groupBy(findings, (f) => f.code);
1143
+ const codes = [...groups.keys()].sort((a, b) => Number(a === "duplicate-edge") - Number(b === "duplicate-edge"));
1144
+ for (const code of codes) {
1145
+ const rows = groups.get(code);
1146
+ lines.push(`- **${plain(code)}** (${rows.length})${Object.hasOwn(headings, code) ? " \u2014 " + headings[code] : ""}`);
1147
+ for (const line of ruleLines(rows, input)) lines.push(line);
1148
+ }
1149
+ }
1150
+ return lines.join("\n") + "\n";
1151
+ }
1152
+ function checksText({ lint, review }, lintReport) {
1153
+ const graphLint = lintReport ?? reportText(lint.map((i) => ({ ...i, code: i.kind, node: i.nodeId })), "graph.json");
1154
+ if (!review) return graphLint;
1155
+ const lines = [`# Data review (${review.length})`];
1156
+ for (const [level, heading] of severities) {
1157
+ const rows = review.filter((i) => i.level === level);
1158
+ if (!rows.length) continue;
1159
+ lines.push(`## ${heading} (${rows.length})`);
1160
+ for (const [kind, issues] of groupBy(rows, (i) => i.kind)) {
1161
+ const label = issues[0].group;
1162
+ lines.push(`- **${plain(kind)}** (${issues.length})` + (label && label !== kind ? " \u2014 " + plain(label) : ""));
1163
+ for (const issue of issues) {
1164
+ const location = [];
1165
+ if (issue.nodeId !== void 0) location.push("Node ID " + literal(issue.nodeId));
1166
+ if (issue.edge) location.push("Edge " + literal(issue.edge.source) + " \u2192 " + literal(issue.edge.target));
1167
+ if (issue.where) location.push(literal(issue.where));
1168
+ lines.push(" - " + (location.length ? location.join(", ") + " \u2014 " : "") + plain(issue.message));
1169
+ if (issue.fix) lines.push(" - " + plain(issue.fix));
1170
+ }
1171
+ }
1172
+ }
1173
+ return lines.join("\n") + "\n\n" + graphLint;
1174
+ }
1608
1175
 
1609
1176
  // src/react/placement.ts
1610
1177
  import { useLayoutEffect, useState } from "react";
1611
- var GAP2 = 6;
1178
+ var GAP = 6;
1612
1179
  var MARGIN = 8;
1613
1180
  function placePanel(anchor, panel, boundary, prefer) {
1614
1181
  const combos = [
@@ -1619,7 +1186,7 @@ function placePanel(anchor, panel, boundary, prefer) {
1619
1186
  ];
1620
1187
  const at = (c) => ({
1621
1188
  left: c.align === "start" ? anchor.left : anchor.right - panel.width,
1622
- top: c.side === "bottom" ? anchor.bottom + GAP2 : anchor.top - GAP2 - panel.height
1189
+ top: c.side === "bottom" ? anchor.bottom + GAP : anchor.top - GAP - panel.height
1623
1190
  });
1624
1191
  const fits = (c) => {
1625
1192
  const p2 = at(c);
@@ -1713,7 +1280,7 @@ function LayerPicker({ layers, view, setView, disabled, collapsed }) {
1713
1280
  const ro = new ResizeObserver(measure);
1714
1281
  ro.observe(root);
1715
1282
  return () => ro.disconnect();
1716
- }, [single, layers.length]);
1283
+ }, [single, layers.length, collapsed]);
1717
1284
  useLayoutEffect2(() => {
1718
1285
  const root = box.current;
1719
1286
  if (!root) return;
@@ -1739,7 +1306,7 @@ function LayerPicker({ layers, view, setView, disabled, collapsed }) {
1739
1306
  const next = layers.map((l) => l.id).filter((l) => l === id ? !on.has(l) : on.has(l));
1740
1307
  setView({ layers: next });
1741
1308
  };
1742
- return /* @__PURE__ */ jsxs("div", { className: `gb-segm gb-layers${stacked ? " is-multi" : ""}${collapsed ? " is-collapsed" : ""}`, role: stacked ? "group" : "radiogroup", children: [
1309
+ return /* @__PURE__ */ jsxs("div", { className: `gb-segm gb-glass gb-raised gb-round gb-layers${stacked ? " is-multi" : ""}${collapsed ? " is-collapsed" : ""}`, role: stacked ? "group" : "radiogroup", children: [
1743
1310
  /* @__PURE__ */ jsxs("div", { className: `gb-layer-track${edges.left ? " can-left" : ""}${edges.right ? " can-right" : ""}`, ref: box, "aria-hidden": collapsed, children: [
1744
1311
  thumb && /* @__PURE__ */ jsx("i", { className: "gb-thumb", style: { transform: `translateX(${thumb.x}px)`, width: thumb.w } }),
1745
1312
  layers.map((l) => {
@@ -1749,6 +1316,7 @@ function LayerPicker({ layers, view, setView, disabled, collapsed }) {
1749
1316
  {
1750
1317
  "data-v": l.id,
1751
1318
  disabled,
1319
+ tabIndex: collapsed ? -1 : void 0,
1752
1320
  className: lit ? "on" : "",
1753
1321
  ...stacked ? { "aria-pressed": lit } : { role: "radio", "aria-checked": lit },
1754
1322
  title: stacked ? t.stackLayer(l.label, lit) : t.viewLayer(l.label),
@@ -1781,7 +1349,7 @@ function LayerUnavailable(p) {
1781
1349
  /* @__PURE__ */ jsx(
1782
1350
  "button",
1783
1351
  {
1784
- className: "gb-icon-btn",
1352
+ className: "gb-icon-btn gb-glass gb-raised gb-round",
1785
1353
  style: { opacity: 0.45 },
1786
1354
  "aria-label": t.layersOff,
1787
1355
  title: t.layersOff,
@@ -1794,7 +1362,7 @@ function LayerUnavailable(p) {
1794
1362
  "div",
1795
1363
  {
1796
1364
  ref: pop.panelRef,
1797
- className: "gb-panel",
1365
+ className: "gb-panel gb-glass gb-raised gb-round",
1798
1366
  role: "dialog",
1799
1367
  "data-x": pop.placement?.align,
1800
1368
  "data-y": pop.placement?.side,
@@ -1888,11 +1456,11 @@ function SearchBox(p) {
1888
1456
  else e.target.blur();
1889
1457
  }
1890
1458
  };
1891
- const q2 = p.query.trim();
1892
- const marker = queryMarker(q2);
1459
+ const q = p.query.trim();
1460
+ const marker = queryMarker(q);
1893
1461
  return /* @__PURE__ */ jsxs("div", { className: `gb-search${focused ? " is-focus" : ""}${open ? " is-open" : ""}`, children: [
1894
- /* @__PURE__ */ jsxs("div", { className: "gb-field", children: [
1895
- /* @__PURE__ */ jsx(Icon, { d: I.search }),
1462
+ /* @__PURE__ */ jsxs("div", { className: "gb-field gb-glass gb-raised gb-round", children: [
1463
+ p.prefix ?? /* @__PURE__ */ jsx(Icon, { d: I.search }),
1896
1464
  /* @__PURE__ */ jsx(
1897
1465
  "input",
1898
1466
  {
@@ -1908,10 +1476,10 @@ function SearchBox(p) {
1908
1476
  onKeyDown: onKey
1909
1477
  }
1910
1478
  ),
1911
- p.query ? /* @__PURE__ */ jsx("button", { className: "gb-clear", "aria-label": t.clearSearch, onMouseDown: (e) => e.preventDefault(), onClick: () => p.setQuery(""), children: /* @__PURE__ */ jsx(Icon, { d: I.x, size: 14 }) }) : !focused && /* @__PURE__ */ jsx("kbd", { children: "/" })
1479
+ p.query ? /* @__PURE__ */ jsx("button", { className: "gb-clear", "aria-label": t.clearSearch, onMouseDown: (e) => e.preventDefault(), onClick: () => p.setQuery(""), children: /* @__PURE__ */ jsx(Icon, { d: I.clear, size: 14 }) }) : !focused && /* @__PURE__ */ jsx("kbd", { children: "/" })
1912
1480
  ] }),
1913
1481
  open && // Pressing the mouse in the list does not take focus: the dropdown closes as soon as the input blurs, and the click would miss.
1914
- /* @__PURE__ */ jsxs("div", { className: "gb-drop", onMouseDown: (e) => e.preventDefault(), children: [
1482
+ /* @__PURE__ */ jsxs("div", { className: "gb-drop gb-glass gb-raised gb-round", onMouseDown: (e) => e.preventDefault(), children: [
1915
1483
  results.length > 0 ? /* @__PURE__ */ jsx("ul", { role: "listbox", children: results.map((r, i) => /* @__PURE__ */ jsxs(
1916
1484
  "li",
1917
1485
  {
@@ -1925,16 +1493,12 @@ function SearchBox(p) {
1925
1493
  p.inputRef.current?.blur();
1926
1494
  },
1927
1495
  children: [
1928
- /* @__PURE__ */ jsx("i", { className: "gb-dot", style: { background: p.colorOf(r.id) } }),
1929
- /* @__PURE__ */ jsxs("span", { className: "gb-r-main", children: [
1930
- /* @__PURE__ */ jsx("span", { className: "gb-r-label", children: /* @__PURE__ */ jsx(Hl, { text: r.label, re: marker }) }),
1931
- r.path.length > 0 && /* @__PURE__ */ jsx("span", { className: "gb-r-path", children: r.path.join(" / ") })
1932
- ] }),
1496
+ /* @__PURE__ */ jsx(ObjectRef, { mark: /* @__PURE__ */ jsx(NodeDot, { color: p.colorOf(r.id) }), name: /* @__PURE__ */ jsx(Hl, { text: r.label, re: marker }), sub: r.path.join(" / ") }),
1933
1497
  r.kind && /* @__PURE__ */ jsx("span", { className: "gb-r-kind", children: r.kind })
1934
1498
  ]
1935
1499
  },
1936
1500
  r.id
1937
- )) }) : /* @__PURE__ */ jsx("div", { className: "gb-drop-empty", children: t.noMatch(q2, !!p.search?.elsewhere.length) }),
1501
+ )) }) : /* @__PURE__ */ jsx("div", { className: "gb-drop-empty", children: t.noMatch(q, !!p.search?.elsewhere.length) }),
1938
1502
  p.search && p.search.total > results.length || p.search?.elsewhere.length ? /* @__PURE__ */ jsxs("div", { className: "gb-drop-foot", children: [
1939
1503
  p.search && p.search.total > results.length && /* @__PURE__ */ jsx("span", { children: t.moreResults(p.search.total - results.length) }),
1940
1504
  p.search?.elsewhere.map((e) => /* @__PURE__ */ jsxs("button", { onClick: () => p.onLayer(e.layer), children: [
@@ -1967,7 +1531,7 @@ function ViewMenu(p) {
1967
1531
  /* @__PURE__ */ jsx(
1968
1532
  "button",
1969
1533
  {
1970
- className: `gb-icon-btn${pop.open ? " on" : ""}`,
1534
+ className: `gb-icon-btn gb-glass gb-raised gb-round${pop.open ? " on" : ""}`,
1971
1535
  "aria-label": t.more,
1972
1536
  "aria-expanded": pop.open,
1973
1537
  title: t.more,
@@ -1979,7 +1543,7 @@ function ViewMenu(p) {
1979
1543
  "div",
1980
1544
  {
1981
1545
  ref: pop.panelRef,
1982
- className: "gb-panel",
1546
+ className: "gb-panel gb-glass gb-raised gb-round",
1983
1547
  role: "dialog",
1984
1548
  "data-x": pop.placement?.align,
1985
1549
  "data-y": pop.placement?.side,
@@ -2001,16 +1565,22 @@ function ViewMenu(p) {
2001
1565
  function Toolbar(p) {
2002
1566
  const { view, setView, controls } = p;
2003
1567
  const t = useStrings();
2004
- const shortOrigin = (o) => o.split("/").pop() ?? o;
2005
1568
  const originPick = controls.origins && p.origins.length > 1;
1569
+ const token = p.scope.active && /* @__PURE__ */ jsxs("span", { className: "gb-token", title: p.scope.subtree ?? p.scope.origins?.join(", "), children: [
1570
+ /* @__PURE__ */ jsx(Icon, { d: p.scope.subtree ? I.tree : I.file, size: 13 }),
1571
+ /* @__PURE__ */ jsx("span", { children: p.scope.label }),
1572
+ /* @__PURE__ */ jsx("button", { type: "button", "aria-label": t.exitScope, title: t.exitScope, onClick: () => p.scope.change(null), children: /* @__PURE__ */ jsx(Icon, { d: I.x, size: 12 }) })
1573
+ ] });
2006
1574
  const multi = controls.layers && p.layers.length > 1;
2007
1575
  const showLayer = (l) => setView(view.planes ? { layers: [...view.layers ?? [], l] } : { layers: [l] });
2008
- return /* @__PURE__ */ jsxs("div", { className: `gb-bar${multi ? " has-layers" : ""}`, children: [
1576
+ return /* @__PURE__ */ jsxs("div", { className: `gb-bar${multi && view.planes ? " has-layers" : ""}`, children: [
1577
+ !controls.search && token,
2009
1578
  controls.search && /* @__PURE__ */ jsx(
2010
1579
  SearchBox,
2011
1580
  {
1581
+ prefix: token || void 0,
2012
1582
  query: view.query ?? "",
2013
- setQuery: (q2) => setView({ query: q2 }),
1583
+ setQuery: (q) => setView({ query: q }),
2014
1584
  search: p.search,
2015
1585
  colorOf: p.colorOf,
2016
1586
  onPreview: p.onPreview,
@@ -2021,12 +1591,6 @@ function Toolbar(p) {
2021
1591
  ),
2022
1592
  multi && /* @__PURE__ */ jsx(LayerPicker, { layers: p.layers, view, setView, disabled: p.busy, collapsed: !view.planes }),
2023
1593
  controls.layers && !multi && /* @__PURE__ */ jsx(LayerUnavailable, { reason: p.layerIssue ?? "", onForce: p.onForceLayers }),
2024
- originPick && view.origins?.length === 1 && /* Filtering by source: the state is in plain sight, and one × returns to everything. */
2025
- /* @__PURE__ */ jsxs("span", { className: "gb-chip", title: view.origins[0], children: [
2026
- /* @__PURE__ */ jsx(Icon, { d: I.file, size: 13 }),
2027
- /* @__PURE__ */ jsx("span", { children: shortOrigin(view.origins[0]) }),
2028
- /* @__PURE__ */ jsx("button", { "aria-label": t.allOrigins, title: t.allOrigins, onClick: () => setView({ origins: null }), children: /* @__PURE__ */ jsx(Icon, { d: I.x, size: 12 }) })
2029
- ] }),
2030
1594
  (originPick || p.onAdd || p.onRelayout || p.onRestructure) && /* @__PURE__ */ jsxs(ViewMenu, { foot: t.stats(p.stats.nodes, p.stats.edges), children: [
2031
1595
  originPick && /* @__PURE__ */ jsxs("div", { className: "gb-panel-sec", children: [
2032
1596
  /* @__PURE__ */ jsx("div", { className: "gb-panel-h", children: t.origins }),
@@ -2034,11 +1598,12 @@ function Toolbar(p) {
2034
1598
  "select",
2035
1599
  {
2036
1600
  className: "gb-select",
2037
- value: view.origins?.length === 1 ? view.origins[0] : "",
2038
- onChange: (e) => setView({ origins: e.target.value ? [e.target.value] : null }),
1601
+ "aria-label": t.origins,
1602
+ value: p.scope.origins?.length === 1 ? p.scope.origins[0] : "",
1603
+ onChange: (e) => p.scope.change(null, e.target.value ? [e.target.value] : void 0),
2039
1604
  children: [
2040
1605
  /* @__PURE__ */ jsx("option", { value: "", children: t.allOrigins }),
2041
- p.origins.map((o) => /* @__PURE__ */ jsx("option", { value: o, children: shortOrigin(o) }, o))
1606
+ p.origins.map((o) => /* @__PURE__ */ jsx("option", { value: o, children: o }, o))
2042
1607
  ]
2043
1608
  }
2044
1609
  )
@@ -2049,82 +1614,79 @@ function Toolbar(p) {
2049
1614
  ] }),
2050
1615
  (p.onRelayout || p.onRestructure) && /* @__PURE__ */ jsxs("div", { className: "gb-panel-sec gb-menu-list", children: [
2051
1616
  p.onRelayout && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: p.onRelayout, disabled: p.busy, children: t.relayout }),
2052
- p.onRestructure && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", "data-menu-keep-open": p.restructureContent ? true : void 0, onClick: p.onRestructure, disabled: p.busy, children: t.restructure }),
1617
+ p.onRestructure && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", "data-menu-keep-open": p.restructureContent ? true : void 0, onClick: p.onRestructure, disabled: p.busy, children: p.scope.active ? t.restructureFull : t.restructure }),
2053
1618
  p.restructureContent
2054
1619
  ] })
2055
1620
  ] })
2056
1621
  ] });
2057
1622
  }
2058
- var GROUP_CAP = 100;
2059
- function Issues({ issues, onPick }) {
1623
+ function MarkdownReport({ text }) {
1624
+ return /* @__PURE__ */ jsx("div", { onCopy: (event) => {
1625
+ const selection = event.currentTarget.ownerDocument.getSelection();
1626
+ if (!selection?.rangeCount || selection.isCollapsed) return;
1627
+ const range = selection.getRangeAt(0);
1628
+ if (!event.currentTarget.contains(range.commonAncestorContainer)) return;
1629
+ if (range.toString() === event.currentTarget.textContent) {
1630
+ event.clipboardData.setData("text/plain", text);
1631
+ event.preventDefault();
1632
+ }
1633
+ }, children: renderMarkdown(text) });
1634
+ }
1635
+ function Issues({ checks, report }) {
2060
1636
  const t = useStrings();
1637
+ const panelId = useId();
2061
1638
  const pop = usePopover(ISSUES_PLACE);
2062
- const groups = useMemo(() => {
2063
- const by = /* @__PURE__ */ new Map();
2064
- for (const it of issues) {
2065
- const name = it.group ?? it.kind;
2066
- const g = by.get(name) ?? by.set(name, { name, error: false, items: [] }).get(name);
2067
- g.items.push(it);
2068
- if (it.level === "error") g.error = true;
2069
- }
2070
- return [...by.values()].sort((a, b) => +b.error - +a.error || b.items.length - a.items.length);
2071
- }, [issues]);
1639
+ const countCategories = (rows) => new Set(rows.map((i) => i.level + ":" + i.kind)).size;
1640
+ const lintGroups = countCategories(checks.lint);
1641
+ const reviewGroups = checks.review && countCategories(checks.review);
1642
+ const groups = lintGroups + (reviewGroups ?? 0);
1643
+ const issues = checks.review ? checks.lint.concat(checks.review) : checks.lint;
2072
1644
  const errors = issues.filter((i) => i.level === "error").length;
2073
- const warns = issues.length - errors;
2074
- const target = (it) => it.nodeId ?? it.edge?.source;
1645
+ const warns = issues.filter((i) => i.level === "warn").length;
1646
+ const infos = issues.length - errors - warns;
1647
+ const summary = [t.issuesTitle(errors, warns, infos, groups), t.issuesTip(errors, warns, infos)].filter(Boolean).join(" \xB7 ");
1648
+ const title = reviewGroups === void 0 ? summary : summary + "\n" + t.issuesBySource(reviewGroups, lintGroups);
2075
1649
  return /* @__PURE__ */ jsxs("div", { className: "gb-menu", ref: pop.ref, children: [
2076
- /* @__PURE__ */ jsxs(
1650
+ /* @__PURE__ */ jsx(
2077
1651
  "button",
2078
1652
  {
2079
- className: `gb-pill ${errors ? "gb-err" : "gb-hint"}`,
1653
+ className: "gb-icon-btn gb-glass gb-raised gb-round gb-check-button",
2080
1654
  onClick: () => pop.setOpen(!pop.open),
2081
1655
  "aria-expanded": pop.open,
2082
- title: t.issuesTip(errors, warns),
2083
- children: [
2084
- /* @__PURE__ */ jsx(Icon, { d: I.warn, size: 14 }),
2085
- " ",
2086
- errors || warns
2087
- ]
1656
+ "aria-haspopup": "dialog",
1657
+ "aria-controls": pop.open ? panelId : void 0,
1658
+ title,
1659
+ "aria-label": title,
1660
+ children: /* @__PURE__ */ jsxs("span", { className: "gb-check-stack", "aria-hidden": "true", children: [
1661
+ /* @__PURE__ */ jsx(Icon, { d: I.checks, size: 18 }),
1662
+ groups > 0 && /* @__PURE__ */ jsx("span", { className: "gb-check-badge", children: groups > 99 ? "99+" : groups })
1663
+ ] })
2088
1664
  }
2089
1665
  ),
2090
- pop.open && /* @__PURE__ */ jsxs(
1666
+ pop.open && /* @__PURE__ */ jsx(
2091
1667
  "div",
2092
1668
  {
2093
1669
  ref: pop.panelRef,
2094
- className: "gb-panel gb-issues",
1670
+ id: panelId,
1671
+ className: "gb-panel gb-glass gb-raised gb-round gb-issues",
2095
1672
  role: "dialog",
1673
+ "aria-label": title,
2096
1674
  "data-x": pop.placement?.align,
2097
1675
  "data-y": pop.placement?.side,
2098
1676
  style: pop.placement ? { left: pop.placement.left, top: pop.placement.top, right: "auto", bottom: "auto" } : { visibility: "hidden" },
2099
- children: [
2100
- /* @__PURE__ */ jsx("div", { className: "gb-panel-h", children: t.issuesTitle(errors, warns) }),
2101
- groups.map((g) => /* @__PURE__ */ jsxs("details", { open: groups.length === 1, children: [
2102
- /* @__PURE__ */ jsxs("summary", { className: g.error ? "is-err" : "", children: [
2103
- /* @__PURE__ */ jsx("span", { children: g.name }),
2104
- /* @__PURE__ */ jsx("b", { children: g.items.length })
2105
- ] }),
2106
- /* @__PURE__ */ jsxs("ul", { children: [
2107
- g.items.slice(0, GROUP_CAP).map((it, i) => {
2108
- const id = target(it);
2109
- return /* @__PURE__ */ jsx("li", { className: id ? "is-link" : "", onClick: id ? () => {
2110
- onPick(id);
2111
- pop.setOpen(false);
2112
- } : void 0, children: it.message }, i);
2113
- }),
2114
- g.items.length > GROUP_CAP && /* @__PURE__ */ jsx("li", { className: "gb-more", children: t.moreItems(g.items.length - GROUP_CAP) })
2115
- ] })
2116
- ] }, g.name))
2117
- ]
1677
+ children: /* @__PURE__ */ jsx(MarkdownReport, { text: checksText(checks, report) })
2118
1678
  }
2119
1679
  )
2120
1680
  ] });
2121
1681
  }
2122
1682
  function ZoomDock(p) {
2123
1683
  const t = useStrings();
2124
- if (!p.zoom && !p.issues.length) return null;
1684
+ const checks = p.checks;
1685
+ const showChecks = checks && (checks.lint.length > 0 || checks.review !== void 0 || !!p.report);
1686
+ if (!p.zoom && !showChecks) return null;
2125
1687
  return /* @__PURE__ */ jsxs("div", { className: "gb-dock", children: [
2126
- p.issues.length > 0 && /* @__PURE__ */ jsx(Issues, { issues: p.issues, onPick: p.onPick }),
2127
- p.zoom && /* @__PURE__ */ jsxs("div", { className: "gb-group", title: t.cameraTip, children: [
1688
+ showChecks && /* @__PURE__ */ jsx(Issues, { checks, report: p.report }),
1689
+ p.zoom && /* @__PURE__ */ jsxs("div", { className: "gb-group gb-glass gb-raised gb-round", title: t.cameraTip, children: [
2128
1690
  /* @__PURE__ */ jsx("button", { "aria-label": t.zoomOut, title: t.zoomOut, onClick: () => p.onZoom(-1), children: /* @__PURE__ */ jsx(Icon, { d: I.minus }) }),
2129
1691
  /* @__PURE__ */ jsx("button", { "aria-label": t.zoomIn, title: t.zoomIn, onClick: () => p.onZoom(1), children: /* @__PURE__ */ jsx(Icon, { d: I.plus }) }),
2130
1692
  /* @__PURE__ */ jsx("button", { "aria-label": t.fit, title: t.fit, onClick: p.onFit, children: /* @__PURE__ */ jsx(Icon, { d: I.fit }) })
@@ -2144,7 +1706,12 @@ function touchGestures(actions) {
2144
1706
  let start = null;
2145
1707
  let startedAt = 0;
2146
1708
  let target = null;
2147
- let previewId = null;
1709
+ let current = null;
1710
+ let beforeGesture = null;
1711
+ const preview = (hit) => {
1712
+ current = hit;
1713
+ actions.preview(hit?.value ?? null);
1714
+ };
2148
1715
  let lastTap = null;
2149
1716
  let pinch = null;
2150
1717
  const anchor = () => {
@@ -2161,6 +1728,7 @@ function touchGestures(actions) {
2161
1728
  pinch = null;
2162
1729
  start = null;
2163
1730
  target = null;
1731
+ beforeGesture = null;
2164
1732
  navigation = moved = false;
2165
1733
  };
2166
1734
  return {
@@ -2168,9 +1736,9 @@ function touchGestures(actions) {
2168
1736
  actions.interact();
2169
1737
  fingers.set(id, point);
2170
1738
  if (fingers.size > 1 || navigation) {
1739
+ if (current?.id !== beforeGesture?.id) preview(beforeGesture);
2171
1740
  navigation = true;
2172
1741
  lastTap = null;
2173
- actions.preview(null);
2174
1742
  anchor();
2175
1743
  return;
2176
1744
  }
@@ -2178,8 +1746,8 @@ function touchGestures(actions) {
2178
1746
  startedAt = Date.now();
2179
1747
  moved = false;
2180
1748
  target = actions.hit(point);
2181
- previewId = target?.id ?? null;
2182
- actions.preview(target?.value ?? null);
1749
+ beforeGesture = current;
1750
+ if (target) preview(target);
2183
1751
  },
2184
1752
  move(id, point) {
2185
1753
  if (!fingers.has(id)) return;
@@ -2207,10 +1775,7 @@ function touchGestures(actions) {
2207
1775
  }
2208
1776
  if (moved) {
2209
1777
  const next = actions.hit(point);
2210
- if ((next?.id ?? null) !== previewId) {
2211
- previewId = next?.id ?? null;
2212
- actions.preview(next?.value ?? null);
2213
- }
1778
+ if (next && next.id !== current?.id) preview(next);
2214
1779
  }
2215
1780
  },
2216
1781
  up(id, point) {
@@ -2219,8 +1784,8 @@ function touchGestures(actions) {
2219
1784
  if (!navigation && !moved && start && Date.now() - startedAt < TAP_MS && distance(start, point) <= SLOP) {
2220
1785
  const hit = actions.hit(point);
2221
1786
  if ((hit?.id ?? null) === (target?.id ?? null)) {
2222
- actions.preview(hit?.value ?? null);
2223
1787
  if (!hit) {
1788
+ preview(null);
2224
1789
  actions.select(null);
2225
1790
  lastTap = null;
2226
1791
  } else if (hit.node) {
@@ -2238,7 +1803,7 @@ function touchGestures(actions) {
2238
1803
  cancel() {
2239
1804
  reset();
2240
1805
  lastTap = null;
2241
- actions.preview(null);
1806
+ preview(null);
2242
1807
  },
2243
1808
  dispose() {
2244
1809
  reset();
@@ -2253,20 +1818,43 @@ function installGraphInput(cy, el, actions) {
2253
1818
  actions.interact();
2254
1819
  actions.cancelFly();
2255
1820
  };
2256
- let hasTouchPreview = false;
2257
- const previewTouch = (target) => {
2258
- hasTouchPreview = target != null;
2259
- actions.preview(target);
1821
+ const pane = el.parentElement;
1822
+ const point = (e) => {
1823
+ const rect = pane.getBoundingClientRect();
1824
+ return { x: e.clientX - rect.left, y: e.clientY - rect.top };
1825
+ };
1826
+ const hit = (p, isTouch) => {
1827
+ let layerHit = null;
1828
+ if (pane.firstElementChild?.classList.contains("gb-planes")) {
1829
+ const rect = pane.getBoundingClientRect();
1830
+ const root = pane.getRootNode();
1831
+ const stack = root.elementsFromPoint(rect.left + p.x, rect.top + p.y);
1832
+ const shape = stack.find((item) => item.hasAttribute("data-gb-layer") && pane.contains(item));
1833
+ if (shape) {
1834
+ const layer = shape.getAttribute("data-gb-layer");
1835
+ layerHit = { id: "layer:" + layer, node: false, value: layer };
1836
+ if (shape.localName === "text") return layerHit;
1837
+ }
1838
+ }
1839
+ const z = cy.zoom(), pan = cy.pan();
1840
+ const element = cy.renderer().findNearestElements((p.x - pan.x) / z, (p.y - pan.y) / z, true, isTouch)[0];
1841
+ if (element && element.id() !== VIRTUAL_ROOT) {
1842
+ return { id: "graph:" + element.id(), node: element.isNode(), value: element };
1843
+ }
1844
+ return layerHit;
1845
+ };
1846
+ let mouseId;
1847
+ const mouseHover = (target) => {
1848
+ if (target?.id === mouseId) return;
1849
+ mouseId = target?.id;
1850
+ actions.interact();
1851
+ actions.hover?.(target?.value ?? null);
2260
1852
  };
2261
1853
  const touch = touchGestures({
2262
1854
  interact,
2263
- hit(p) {
2264
- const z = cy.zoom(), pan = cy.pan();
2265
- const hit = cy.renderer().findNearestElements((p.x - pan.x) / z, (p.y - pan.y) / z, true, true)[0];
2266
- return !hit || hit.id() === VIRTUAL_ROOT ? null : { id: hit.id(), node: hit.isNode(), value: hit };
2267
- },
2268
- preview: previewTouch,
2269
- select: actions.selectTouch,
1855
+ hit: (p) => hit(p, true),
1856
+ preview: actions.preview,
1857
+ select: actions.select,
2270
1858
  viewport: () => ({ zoom: cy.zoom(), pan: { ...cy.pan() } }),
2271
1859
  move: (view) => cy.viewport(view),
2272
1860
  limits: () => ({ min: cy.minZoom(), max: cy.maxZoom() })
@@ -2285,28 +1873,53 @@ function installGraphInput(cy, el, actions) {
2285
1873
  actions.select(id === VIRTUAL_ROOT ? null : e.target);
2286
1874
  if (id !== VIRTUAL_ROOT && lastTap.id === id && time - lastTap.time < 350) actions.focus?.(id);
2287
1875
  lastTap = { id, time };
2288
- }
1876
+ } else if (e.target.isEdge() && !e.target.hasClass("contains")) actions.select(e.target);
2289
1877
  });
2290
1878
  onCy("tapstart", actions.cancelFly);
2291
- if (actions.hover) {
2292
- onCy("mouseover", (e) => {
2293
- if (e.target !== cy) {
2294
- actions.interact();
2295
- actions.hover(e.target);
2296
- }
2297
- });
2298
- onCy("mouseout", (e) => {
2299
- if (e.target !== cy) actions.hover(null);
2300
- });
2301
- }
2302
1879
  const on = (name, fn, capture = false) => {
2303
- el.addEventListener(name, fn, { capture, passive: false });
2304
- bindings.push(() => el.removeEventListener(name, fn, capture));
1880
+ pane.addEventListener(name, fn, { capture, passive: false });
1881
+ bindings.push(() => pane.removeEventListener(name, fn, capture));
1882
+ };
1883
+ const captured = /* @__PURE__ */ new Set();
1884
+ let mixedTouch = false;
1885
+ const boundary = pane.closest("[data-gb-zoom-boundary]:not([data-gb-zoom-boundary] *)");
1886
+ const checkOrigins = (e) => {
1887
+ if (captured.size && !mixedTouch && Array.from(e.touches).some((t) => !pane.contains(t.target))) {
1888
+ mixedTouch = true;
1889
+ touch.cancel();
1890
+ }
1891
+ };
1892
+ boundary?.addEventListener("touchstart", checkOrigins, { capture: true, passive: true });
1893
+ let gestureZoom;
1894
+ const gestureStart = (e) => {
1895
+ e.preventDefault();
1896
+ if (!captured.size) {
1897
+ interact();
1898
+ gestureZoom = cy.zoom();
1899
+ }
1900
+ };
1901
+ const gestureChange = (e) => {
1902
+ e.preventDefault();
1903
+ if (gestureZoom === void 0 || captured.size) return;
1904
+ const { scale, clientX, clientY } = e;
1905
+ if (!Number.isFinite(scale) || scale <= 0) return;
1906
+ const rect = el.getBoundingClientRect();
1907
+ cy.zoom({ level: gestureZoom * scale, renderedPosition: {
1908
+ x: Number.isFinite(clientX) ? clientX - rect.left : rect.width / 2,
1909
+ y: Number.isFinite(clientY) ? clientY - rect.top : rect.height / 2
1910
+ } });
1911
+ };
1912
+ const gestureEnd = () => {
1913
+ gestureZoom = void 0;
2305
1914
  };
1915
+ pane.addEventListener("gesturestart", gestureStart, { passive: false });
1916
+ pane.addEventListener("gesturechange", gestureChange, { passive: false });
1917
+ pane.addEventListener("gestureend", gestureEnd);
2306
1918
  on("wheel", (e) => {
2307
1919
  e.preventDefault();
2308
1920
  interact();
2309
1921
  if (e.ctrlKey || e.metaKey) {
1922
+ if (gestureZoom !== void 0) return;
2310
1923
  const rect = el.getBoundingClientRect();
2311
1924
  cy.zoom({
2312
1925
  level: cy.zoom() * Math.exp(-e.deltaY * 0.01),
@@ -2314,11 +1927,15 @@ function installGraphInput(cy, el, actions) {
2314
1927
  });
2315
1928
  } else cy.panBy({ x: -e.deltaX, y: -e.deltaY });
2316
1929
  });
2317
- on("mouseleave", () => actions.hover?.(null));
2318
- const captured = /* @__PURE__ */ new Set();
2319
- const point = (e) => {
2320
- const rect = el.getBoundingClientRect();
2321
- return { x: e.clientX - rect.left, y: e.clientY - rect.top };
1930
+ on("pointerleave", (e) => {
1931
+ if (e.pointerType !== "touch") mouseHover(null);
1932
+ });
1933
+ let usingTouch = false;
1934
+ const useMouse = () => {
1935
+ if (usingTouch) {
1936
+ touch.cancel();
1937
+ usingTouch = false;
1938
+ }
2322
1939
  };
2323
1940
  const stop = (e) => {
2324
1941
  if (e.cancelable) e.preventDefault();
@@ -2326,17 +1943,23 @@ function installGraphInput(cy, el, actions) {
2326
1943
  };
2327
1944
  on("pointerdown", (e) => {
2328
1945
  if (e.pointerType !== "touch") {
2329
- if (hasTouchPreview) previewTouch(null);
1946
+ useMouse();
2330
1947
  return;
2331
1948
  }
1949
+ mouseHover(null);
1950
+ usingTouch = true;
2332
1951
  stop(e);
2333
1952
  lastTap = { id: "", time: 0 };
2334
1953
  captured.add(e.pointerId);
2335
- el.setPointerCapture(e.pointerId);
2336
- touch.down(e.pointerId, point(e));
1954
+ pane.setPointerCapture(e.pointerId);
1955
+ if (!mixedTouch) touch.down(e.pointerId, point(e));
2337
1956
  }, true);
2338
1957
  on("pointermove", (e) => {
2339
- if (e.pointerType !== "touch" && hasTouchPreview) previewTouch(null);
1958
+ if (e.pointerType !== "touch") {
1959
+ useMouse();
1960
+ if (actions.hover && !e.buttons) mouseHover(hit(point(e), false));
1961
+ return;
1962
+ }
2340
1963
  if (!captured.has(e.pointerId)) return;
2341
1964
  stop(e);
2342
1965
  touch.move(e.pointerId, point(e));
@@ -2345,13 +1968,16 @@ function installGraphInput(cy, el, actions) {
2345
1968
  if (!captured.delete(e.pointerId)) return;
2346
1969
  stop(e);
2347
1970
  touch.up(e.pointerId, point(e));
2348
- if (el.hasPointerCapture(e.pointerId)) el.releasePointerCapture(e.pointerId);
1971
+ if (!captured.size) mixedTouch = false;
1972
+ if (pane.hasPointerCapture(e.pointerId)) pane.releasePointerCapture(e.pointerId);
2349
1973
  }, true);
2350
1974
  const cancel = () => {
1975
+ gestureEnd();
1976
+ mixedTouch = false;
2351
1977
  touch.cancel();
2352
1978
  const ids = [...captured];
2353
1979
  captured.clear();
2354
- for (const id of ids) if (el.hasPointerCapture(id)) el.releasePointerCapture(id);
1980
+ for (const id of ids) if (pane.hasPointerCapture(id)) pane.releasePointerCapture(id);
2355
1981
  };
2356
1982
  on("pointercancel", (e) => {
2357
1983
  if (captured.has(e.pointerId)) {
@@ -2366,21 +1992,48 @@ function installGraphInput(cy, el, actions) {
2366
1992
  on("contextmenu", (e) => {
2367
1993
  if (captured.size || e.pointerType === "touch") stop(e);
2368
1994
  }, true);
2369
- const previousTouchAction = el.style.touchAction;
2370
- el.style.touchAction = "none";
1995
+ const previousTouchAction = pane.style.touchAction;
1996
+ pane.style.touchAction = "none";
2371
1997
  const win = el.ownerDocument.defaultView;
2372
1998
  win?.addEventListener("blur", cancel);
2373
1999
  return () => {
2374
2000
  touch.dispose();
2001
+ boundary?.removeEventListener("touchstart", checkOrigins, true);
2002
+ pane.removeEventListener("gesturestart", gestureStart);
2003
+ pane.removeEventListener("gesturechange", gestureChange);
2004
+ pane.removeEventListener("gestureend", gestureEnd);
2375
2005
  bindings.forEach((off) => off());
2376
2006
  win?.removeEventListener("blur", cancel);
2377
- for (const id of captured) if (el.hasPointerCapture(id)) el.releasePointerCapture(id);
2007
+ for (const id of captured) if (pane.hasPointerCapture(id)) pane.releasePointerCapture(id);
2378
2008
  captured.clear();
2379
- el.style.touchAction = previousTouchAction;
2009
+ pane.style.touchAction = previousTouchAction;
2380
2010
  };
2381
2011
  }
2382
2012
 
2383
2013
  // src/react/camera.ts
2014
+ function frameTranslation(before, after) {
2015
+ let x = 0, y = 0, count = 0;
2016
+ for (const [id, a2] of Object.entries(after)) {
2017
+ const b2 = before[id];
2018
+ if (!b2) continue;
2019
+ x += a2.x - b2.x;
2020
+ y += a2.y - b2.y;
2021
+ count++;
2022
+ }
2023
+ if (count) return { x: x / count, y: y / count };
2024
+ const center = (points) => {
2025
+ let x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
2026
+ for (const p of Object.values(points)) {
2027
+ x1 = Math.min(x1, p.x);
2028
+ y1 = Math.min(y1, p.y);
2029
+ x2 = Math.max(x2, p.x);
2030
+ y2 = Math.max(y2, p.y);
2031
+ }
2032
+ return x1 === Infinity ? null : { x: (x1 + x2) / 2, y: (y1 + y2) / 2 };
2033
+ };
2034
+ const a = center(after), b = center(before);
2035
+ return a && b ? { x: a.x - b.x, y: a.y - b.y } : { x: 0, y: 0 };
2036
+ }
2384
2037
  var toRect = (v, W, H) => ({
2385
2038
  cx: (W / 2 - v.pan.x) / v.zoom,
2386
2039
  cy: (H / 2 - v.pan.y) / v.zoom,
@@ -2421,30 +2074,20 @@ function zoomPath(a, b) {
2421
2074
  var easeInOut = (x) => x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
2422
2075
 
2423
2076
  // src/react/EditPanel.tsx
2424
- import { useEffect as useEffect2, useId, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
2077
+ import { useEffect as useEffect2, useId as useId2, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
2425
2078
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
2426
2079
  var PICK_MAX = 8;
2427
- function NodeRef({ id, model, colorOf, sub }) {
2428
- const n = model.index.get(id);
2429
- return /* @__PURE__ */ jsxs2(Fragment2, { children: [
2430
- /* @__PURE__ */ jsx2("i", { className: "gb-dot", style: { background: colorOf(id) } }),
2431
- /* @__PURE__ */ jsxs2("span", { className: "gb-ref-main", children: [
2432
- /* @__PURE__ */ jsx2("span", { className: "gb-ref-label", children: n?.label ?? id }),
2433
- sub && /* @__PURE__ */ jsx2("span", { className: "gb-ref-sub", children: sub })
2434
- ] })
2435
- ] });
2436
- }
2437
2080
  function NodePicker({ model, value, onChange, exclude, empty, autoFocus, label, colorOf, id: inputId }) {
2438
2081
  const t = useStrings();
2439
- const [q2, setQ] = useState3("");
2082
+ const [q, setQ] = useState3("");
2440
2083
  const [open, setOpen] = useState3(false);
2441
2084
  const [active, setActive] = useState3(0);
2442
2085
  const idx = useMemo2(() => indexModel(model), [model]);
2443
2086
  const hits = useMemo2(
2444
- () => q2.trim() ? searchNodes(model, q2).filter((id) => !exclude?.(id)).slice(0, PICK_MAX) : [],
2445
- [model, q2, exclude]
2087
+ () => q.trim() ? searchNodes(model, q).filter((id) => !exclude?.(id)).slice(0, PICK_MAX) : [],
2088
+ [model, q, exclude]
2446
2089
  );
2447
- useEffect2(() => setActive(0), [q2]);
2090
+ useEffect2(() => setActive(0), [q]);
2448
2091
  const curRef = useRef2(null);
2449
2092
  const refocus = useRef2(false);
2450
2093
  const choose = (id) => {
@@ -2462,37 +2105,47 @@ function NodePicker({ model, value, onChange, exclude, empty, autoFocus, label,
2462
2105
  });
2463
2106
  const pathOf = (id) => idx.ancestorsOf(id).slice(0, 2).reverse().map((a) => model.index.get(a)?.label).filter(Boolean).join(" / ");
2464
2107
  return /* @__PURE__ */ jsxs2("div", { className: `gb-pick${open ? " is-open" : ""}`, children: [
2465
- cur && !open ? /* @__PURE__ */ jsxs2(
2466
- "button",
2467
- {
2468
- ref: curRef,
2469
- type: "button",
2470
- id: inputId,
2471
- className: "gb-pick-cur",
2472
- "aria-label": `${label}: ${cur.label}`,
2473
- onClick: () => setOpen(true),
2474
- onKeyDown: (e) => {
2475
- if (e.key === "Backspace" || e.key === "Delete") {
2476
- e.preventDefault();
2477
- choose(null);
2478
- }
2479
- },
2480
- children: [
2481
- /* @__PURE__ */ jsx2(NodeRef, { id: cur.id, model, colorOf, sub: cur.id }),
2482
- /* @__PURE__ */ jsx2("i", { className: "gb-pick-x", "aria-hidden": true, onClick: (e) => {
2483
- e.stopPropagation();
2108
+ cur && !open ? /* @__PURE__ */ jsxs2("span", { className: "gb-input gb-pick-selected", children: [
2109
+ /* @__PURE__ */ jsx2(
2110
+ "button",
2111
+ {
2112
+ ref: curRef,
2113
+ type: "button",
2114
+ id: inputId,
2115
+ className: "gb-pick-cur",
2116
+ "aria-label": `${label}: ${cur.label}`,
2117
+ onClick: () => setOpen(true),
2118
+ onKeyDown: (e) => {
2119
+ if (e.key === "Backspace" || e.key === "Delete") {
2120
+ e.preventDefault();
2121
+ choose(null);
2122
+ setOpen(true);
2123
+ }
2124
+ },
2125
+ children: /* @__PURE__ */ jsx2(NodeRef, { id: cur.id, model, colorOf, sub: cur.id === cur.label ? void 0 : cur.id })
2126
+ }
2127
+ ),
2128
+ /* @__PURE__ */ jsx2(
2129
+ "button",
2130
+ {
2131
+ type: "button",
2132
+ className: "gb-ibtn gb-pick-x",
2133
+ "aria-label": t.clearField + " " + label,
2134
+ onClick: () => {
2484
2135
  choose(null);
2485
- }, children: /* @__PURE__ */ jsx2(Icon, { d: I.x, size: 12 }) })
2486
- ]
2487
- }
2488
- ) : /* @__PURE__ */ jsxs2("span", { className: "gb-input gb-pick-field", children: [
2136
+ setOpen(true);
2137
+ },
2138
+ children: /* @__PURE__ */ jsx2(Icon, { d: I.clear, size: 15 })
2139
+ }
2140
+ )
2141
+ ] }) : /* @__PURE__ */ jsxs2("span", { className: "gb-input gb-pick-field", children: [
2489
2142
  /* @__PURE__ */ jsx2(Icon, { d: I.search, size: 14 }),
2490
2143
  /* @__PURE__ */ jsx2(
2491
2144
  "input",
2492
2145
  {
2493
2146
  id: inputId,
2494
2147
  "aria-label": label,
2495
- value: q2,
2148
+ value: q,
2496
2149
  spellCheck: false,
2497
2150
  placeholder: value === null && empty ? empty : t.pick,
2498
2151
  autoFocus: autoFocus || open,
@@ -2521,7 +2174,7 @@ function NodePicker({ model, value, onChange, exclude, empty, autoFocus, label,
2521
2174
  }
2522
2175
  )
2523
2176
  ] }),
2524
- open && hits.length > 0 && /* @__PURE__ */ jsx2("ul", { className: "gb-pick-list", role: "listbox", onMouseDown: (e) => e.preventDefault(), children: hits.map((id, i) => /* @__PURE__ */ jsx2(
2177
+ open && hits.length > 0 && /* @__PURE__ */ jsx2("ul", { className: "gb-pick-list gb-glass gb-raised gb-round", role: "listbox", onMouseDown: (e) => e.preventDefault(), children: hits.map((id, i) => /* @__PURE__ */ jsx2(
2525
2178
  "li",
2526
2179
  {
2527
2180
  role: "option",
@@ -2552,32 +2205,7 @@ function readContent(text) {
2552
2205
  if (Object.keys(d).length) out.data = d;
2553
2206
  return out;
2554
2207
  }
2555
- function Shell({ title, onClose, onSubmit, foot, error, children }) {
2556
- const t = useStrings();
2557
- return /* @__PURE__ */ jsxs2(
2558
- "form",
2559
- {
2560
- className: "gb-detail gb-edit",
2561
- onSubmit: (e) => {
2562
- e.preventDefault();
2563
- onSubmit();
2564
- },
2565
- onKeyDown: (e) => {
2566
- if (e.key === "Escape" && !e.defaultPrevented) onClose();
2567
- },
2568
- children: [
2569
- /* @__PURE__ */ jsxs2("div", { className: "gb-dh", children: [
2570
- /* @__PURE__ */ jsx2("span", { className: "gb-dh-title", children: title }),
2571
- /* @__PURE__ */ jsx2("span", { className: "gb-dh-act", children: /* @__PURE__ */ jsx2("button", { type: "button", className: "gb-ibtn", onClick: onClose, "aria-label": t.close, title: t.close, children: /* @__PURE__ */ jsx2(Icon, { d: I.x, size: 15 }) }) })
2572
- ] }),
2573
- /* @__PURE__ */ jsx2("div", { className: "gb-db gb-form", children }),
2574
- error && /* @__PURE__ */ jsx2("div", { className: "gb-edit-err", role: "alert", children: error }),
2575
- /* @__PURE__ */ jsx2("div", { className: "gb-df", children: foot })
2576
- ]
2577
- }
2578
- );
2579
- }
2580
- function EditPanel({ target, model, onSubmit, onCancel, onRetarget, renderEditor, colorOf = () => void 0 }) {
2208
+ function EditPanel({ target, model, onSubmit, onCancel, kindLabels, renderEditor, colorOf = () => void 0 }) {
2581
2209
  return target.what === "node" ? /* @__PURE__ */ jsx2(
2582
2210
  NodeForm,
2583
2211
  {
@@ -2585,12 +2213,12 @@ function EditPanel({ target, model, onSubmit, onCancel, onRetarget, renderEditor
2585
2213
  model,
2586
2214
  onSubmit,
2587
2215
  onCancel,
2588
- onRetarget,
2216
+ kindLabels,
2589
2217
  renderEditor,
2590
2218
  colorOf
2591
2219
  },
2592
2220
  target.id ?? "+"
2593
- ) : /* @__PURE__ */ jsx2(EdgeForm, { source: target.source, model, onSubmit, onCancel, colorOf }, target.source ?? "+");
2221
+ ) : /* @__PURE__ */ jsx2(EdgeForm, { targetSpec: target, model, onSubmit, onCancel, colorOf }, target.edge ? edgeKey(target.edge) : "+");
2594
2222
  }
2595
2223
  function useSubmit(onSubmit) {
2596
2224
  const t = useStrings();
@@ -2602,9 +2230,16 @@ function useSubmit(onSubmit) {
2602
2230
  };
2603
2231
  return { error, setError, submit };
2604
2232
  }
2605
- function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor, colorOf }) {
2233
+ function SaveActions({ onCancel, label, disabled }) {
2606
2234
  const t = useStrings();
2607
- const uid = useId();
2235
+ return /* @__PURE__ */ jsxs2("span", { className: "gb-form-act", children: [
2236
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "gb-btn", onClick: onCancel, children: t.cancel }),
2237
+ /* @__PURE__ */ jsx2("button", { type: "submit", className: "gb-btn gb-primary", disabled, children: label })
2238
+ ] });
2239
+ }
2240
+ function NodeForm({ target, model, onSubmit, onCancel, kindLabels, renderEditor, colorOf }) {
2241
+ const t = useStrings();
2242
+ const uid = useId2();
2608
2243
  const { error, setError, submit } = useSubmit(onSubmit);
2609
2244
  const node = target.id ? model.index.get(target.id) : void 0;
2610
2245
  const creating = !node;
@@ -2616,27 +2251,19 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
2616
2251
  );
2617
2252
  const [text, setText] = useState3(initial);
2618
2253
  const initialBefore = useMemo2(() => {
2619
- const siblings = model.nodes.filter((n) => (n.parent ?? null) === (node?.parent ?? target.parent ?? null)).sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity));
2620
- return node ? siblings[siblings.findIndex((n) => n.id === node.id) + 1]?.id ?? null : null;
2254
+ const siblings2 = childrenOf(model, node?.parent ?? target.parent);
2255
+ return node ? siblings2[siblings2.findIndex((n) => n.id === node.id) + 1]?.id ?? null : null;
2621
2256
  }, [model, node, target.parent]);
2622
2257
  const [before, setBefore] = useState3(initialBefore);
2258
+ const [nested, setNested] = useState3(null);
2623
2259
  const [confirming, setConfirming] = useState3(false);
2624
2260
  const idErr = creating && id ? checkEdit(model, { op: "addNode", id, set: {} }) : null;
2625
2261
  const below = useMemo2(() => {
2626
2262
  if (!node) return null;
2627
- const out = /* @__PURE__ */ new Set([node.id]);
2628
- let grew = true;
2629
- while (grew) {
2630
- grew = false;
2631
- for (const n of model.nodes) if (n.parent && out.has(n.parent) && !out.has(n.id)) {
2632
- out.add(n.id);
2633
- grew = true;
2634
- }
2635
- }
2636
- return out;
2263
+ return indexModel(model).subtreeOf(node.id);
2637
2264
  }, [model, node]);
2638
2265
  const edges = node ? edgesOf(model, node.id) : [];
2639
- const childCount = node ? model.nodes.filter((n) => n.parent === node.id).length : 0;
2266
+ const children = node ? childrenOf(model, node.id) : [];
2640
2267
  const save = () => {
2641
2268
  const content = readContent(text);
2642
2269
  if (!content) {
@@ -2663,174 +2290,181 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
2663
2290
  /* @__PURE__ */ jsx2("span", { className: "gb-confirm", children: t.confirmRemove(edges.length) }),
2664
2291
  /* @__PURE__ */ jsxs2("span", { className: "gb-form-act", children: [
2665
2292
  /* @__PURE__ */ jsx2("button", { type: "button", className: "gb-btn", onClick: () => setConfirming(false), children: t.cancel }),
2666
- /* @__PURE__ */ jsx2("button", { type: "button", className: "gb-btn gb-danger", onClick: () => {
2293
+ /* @__PURE__ */ jsxs2("button", { type: "button", className: "gb-btn gb-danger", onClick: () => {
2667
2294
  if (submit({ op: "removeNode", id: node.id })) onCancel();
2668
- }, children: t.remove })
2295
+ }, children: [
2296
+ /* @__PURE__ */ jsx2(Icon, { d: I.trash, size: 15 }),
2297
+ t.remove
2298
+ ] })
2669
2299
  ] })
2670
2300
  ] }) : /* @__PURE__ */ jsxs2(Fragment2, { children: [
2671
- node ? /* @__PURE__ */ jsx2(
2301
+ node ? /* @__PURE__ */ jsxs2(
2672
2302
  "button",
2673
2303
  {
2674
2304
  type: "button",
2675
2305
  className: "gb-btn gb-danger-text",
2676
- disabled: childCount > 0,
2677
- title: childCount > 0 ? t.error["has-children"] : void 0,
2306
+ disabled: children.length > 0,
2307
+ title: children.length > 0 ? t.error["has-children"] : void 0,
2678
2308
  onClick: () => setConfirming(true),
2679
- children: t.remove
2309
+ children: [
2310
+ /* @__PURE__ */ jsx2(Icon, { d: I.trash, size: 15 }),
2311
+ t.remove
2312
+ ]
2680
2313
  }
2681
2314
  ) : /* @__PURE__ */ jsx2("span", {}),
2682
- /* @__PURE__ */ jsxs2("span", { className: "gb-form-act", children: [
2683
- /* @__PURE__ */ jsx2("button", { type: "button", className: "gb-btn", onClick: onCancel, children: t.cancel }),
2684
- /* @__PURE__ */ jsx2("button", { type: "submit", className: "gb-btn gb-primary", disabled: creating && (!id.trim() || !!idErr), children: creating ? t.create : t.save })
2685
- ] })
2315
+ /* @__PURE__ */ jsx2(SaveActions, { onCancel, label: creating ? t.create : t.save, disabled: creating && (!id.trim() || !!idErr) })
2686
2316
  ] });
2687
- return /* @__PURE__ */ jsxs2(Shell, { title: creating ? t.newNode : t.editNode, onClose: onCancel, onSubmit: save, foot, error, children: [
2688
- /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2689
- /* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-id`, children: t.id }),
2690
- creating ? /* @__PURE__ */ jsxs2(Fragment2, { children: [
2691
- /* @__PURE__ */ jsx2(
2692
- "input",
2693
- {
2694
- id: `${uid}-id`,
2695
- className: `gb-input${idErr ? " is-bad" : ""}`,
2696
- value: id,
2697
- autoFocus: true,
2698
- spellCheck: false,
2699
- onChange: (e) => setId(e.target.value)
2700
- }
2701
- ),
2702
- /* @__PURE__ */ jsx2("small", { className: idErr ? "is-bad" : "", children: idErr ? t.error[idErr] : t.idHint })
2703
- ] }) : /* @__PURE__ */ jsx2("code", { className: "gb-id", children: node.id })
2704
- ] }),
2705
- /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2706
- /* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-parent`, children: t.parent }),
2707
- /* @__PURE__ */ jsx2(
2708
- NodePicker,
2709
- {
2710
- id: `${uid}-parent`,
2711
- model,
2712
- value: parent,
2713
- onChange: (id2) => {
2714
- setParent(id2);
2715
- setBefore(null);
2716
- },
2717
- empty: t.noParent,
2718
- label: t.parent,
2719
- exclude: below ? (x) => below.has(x) : void 0,
2720
- colorOf
2721
- }
2722
- )
2723
- ] }),
2724
- /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2725
- /* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-before`, children: "Before" }),
2726
- /* @__PURE__ */ jsxs2("select", { id: `${uid}-before`, className: "gb-input", value: before ?? "", onChange: (e) => setBefore(e.target.value || null), children: [
2727
- /* @__PURE__ */ jsx2("option", { value: "", children: "Last" }),
2728
- model.nodes.filter((n) => n.id !== node?.id && (n.parent ?? null) === parent).sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity)).map((n) => /* @__PURE__ */ jsx2("option", { value: n.id, children: n.label }, n.id))
2729
- ] })
2730
- ] }),
2731
- /* @__PURE__ */ jsxs2("div", { className: "gb-fld gb-grow", children: [
2732
- /* @__PURE__ */ jsxs2("label", { className: "gb-k", htmlFor: `${uid}-json`, children: [
2733
- t.content,
2734
- " ",
2735
- /* @__PURE__ */ jsx2("em", { children: t.contentHint })
2736
- ] }),
2737
- renderEditor ? renderEditor({ value: text, onChange: setText }) : /* @__PURE__ */ jsx2(
2738
- "textarea",
2739
- {
2740
- id: `${uid}-json`,
2741
- className: "gb-input gb-json",
2742
- value: text,
2743
- spellCheck: false,
2744
- rows: 9,
2745
- onChange: (e) => setText(e.target.value)
2746
- }
2747
- )
2748
- ] }),
2749
- node && /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2750
- /* @__PURE__ */ jsxs2("span", { className: "gb-k", children: [
2751
- t.relations,
2752
- " ",
2753
- /* @__PURE__ */ jsx2("em", { children: edges.length || "" })
2754
- ] }),
2755
- /* @__PURE__ */ jsx2("ul", { className: "gb-rel", children: edges.map((e, i) => {
2756
- const out = e.source === node.id;
2757
- return /* @__PURE__ */ jsxs2("li", { children: [
2758
- /* @__PURE__ */ jsx2("span", { className: "gb-rel-dir", "aria-hidden": true, children: out ? "\u2192" : "\u2190" }),
2759
- /* @__PURE__ */ jsx2(NodeRef, { id: out ? e.target : e.source, model, colorOf }),
2760
- e.kind && /* @__PURE__ */ jsx2("span", { className: "gb-r-kind", children: e.kind }),
2317
+ if (nested) return /* @__PURE__ */ jsx2(EditPanel, { target: nested, ...{ model, onSubmit, renderEditor, colorOf, kindLabels }, onCancel: () => setNested(null) });
2318
+ const siblings = childrenOf(model, parent).filter((n) => n.id !== node?.id);
2319
+ const ordered = !parent || model.index.get(parent)?.data?.unordered !== true;
2320
+ return /* @__PURE__ */ jsxs2(
2321
+ Inspector,
2322
+ {
2323
+ title: node?.label ?? t.newNode,
2324
+ objectId: node?.id,
2325
+ mark: node && /* @__PURE__ */ jsx2(NodeDot, { color: colorOf(node.id) }),
2326
+ kind: node && (node.kind ? kindLabels?.[node.kind] ?? node.kind : t.node),
2327
+ onClose: onCancel,
2328
+ onSubmit: save,
2329
+ foot,
2330
+ error,
2331
+ children: [
2332
+ creating && /* @__PURE__ */ jsxs2(InspectorField, { label: t.id, htmlFor: `${uid}-id`, children: [
2761
2333
  /* @__PURE__ */ jsx2(
2762
- "button",
2334
+ "input",
2763
2335
  {
2764
- type: "button",
2765
- className: "gb-ibtn",
2766
- "aria-label": t.removeEdge,
2767
- title: t.removeEdge,
2768
- onClick: () => submit({ op: "removeEdge", edge: { source: e.source, target: e.target, kind: e.kind } }),
2769
- children: /* @__PURE__ */ jsx2(Icon, { d: I.x, size: 13 })
2336
+ id: `${uid}-id`,
2337
+ className: `gb-input${idErr ? " is-bad" : ""}`,
2338
+ value: id,
2339
+ autoFocus: true,
2340
+ spellCheck: false,
2341
+ onChange: (e) => setId(e.target.value)
2770
2342
  }
2771
- )
2772
- ] }, i);
2773
- }) }),
2774
- /* @__PURE__ */ jsxs2("button", { type: "button", className: "gb-add", onClick: () => onRetarget({ what: "edge", source: node.id }), children: [
2775
- /* @__PURE__ */ jsx2(Icon, { d: I.plus, size: 13 }),
2776
- t.addEdge
2777
- ] })
2778
- ] })
2779
- ] });
2343
+ ),
2344
+ /* @__PURE__ */ jsx2("small", { className: idErr ? "is-bad" : "", children: idErr ? t.error[idErr] : t.idHint })
2345
+ ] }),
2346
+ /* @__PURE__ */ jsxs2("div", { className: "gb-field-pair", children: [
2347
+ /* @__PURE__ */ jsx2(InspectorField, { label: t.parent, htmlFor: `${uid}-parent`, children: /* @__PURE__ */ jsx2(
2348
+ NodePicker,
2349
+ {
2350
+ id: `${uid}-parent`,
2351
+ model,
2352
+ value: parent,
2353
+ onChange: (id2) => {
2354
+ setParent(id2);
2355
+ setBefore(null);
2356
+ },
2357
+ empty: t.noParent,
2358
+ label: t.parent,
2359
+ exclude: below ? (x) => below.has(x) : void 0,
2360
+ colorOf
2361
+ }
2362
+ ) }),
2363
+ ordered && /* @__PURE__ */ jsx2(InspectorField, { label: t.position, htmlFor: `${uid}-before`, children: /* @__PURE__ */ jsxs2("select", { id: `${uid}-before`, className: "gb-input", value: before ?? "", onChange: (e) => setBefore(e.target.value || null), children: [
2364
+ siblings.map((n, i) => /* @__PURE__ */ jsx2("option", { value: n.id, children: i + 1 }, n.id)),
2365
+ /* @__PURE__ */ jsx2("option", { value: "", children: siblings.length + 1 })
2366
+ ] }) })
2367
+ ] }),
2368
+ node && /* @__PURE__ */ jsx2(
2369
+ NodeRelations,
2370
+ {
2371
+ id: node.id,
2372
+ current: { model, children, edges, colorOf },
2373
+ kindLabels,
2374
+ onAdd: (group) => setNested(group === "child" ? { what: "node", parent: node.id } : { what: "edge", ...group === "in" ? { target: node.id } : { source: node.id } }),
2375
+ onEditEdge: (edge) => setNested({ what: "edge", edge })
2376
+ }
2377
+ ),
2378
+ /* @__PURE__ */ jsx2(InspectorField, { htmlFor: `${uid}-json`, label: /* @__PURE__ */ jsxs2(Fragment2, { children: [
2379
+ t.content,
2380
+ " ",
2381
+ /* @__PURE__ */ jsx2("em", { children: t.contentHint })
2382
+ ] }), children: renderEditor ? renderEditor({ value: text, onChange: setText }) : /* @__PURE__ */ jsx2(
2383
+ "textarea",
2384
+ {
2385
+ id: `${uid}-json`,
2386
+ className: "gb-input gb-json",
2387
+ value: text,
2388
+ spellCheck: false,
2389
+ rows: 5,
2390
+ onChange: (e) => setText(e.target.value)
2391
+ }
2392
+ ) })
2393
+ ]
2394
+ }
2395
+ );
2780
2396
  }
2781
- function EdgeForm({ source: src, model, onSubmit, onCancel, colorOf }) {
2397
+ function EdgeForm({ targetSpec, model, onSubmit, onCancel, colorOf }) {
2782
2398
  const t = useStrings();
2783
- const uid = useId();
2399
+ const uid = useId2();
2784
2400
  const { error, submit } = useSubmit(onSubmit);
2785
- const [source, setSource] = useState3(src ?? null);
2786
- const [target, setTarget] = useState3(null);
2787
- const [kind, setKind] = useState3("");
2788
- const [label, setLabel] = useState3("");
2401
+ const original = targetSpec.edge && { source: targetSpec.edge.source, target: targetSpec.edge.target, kind: targetSpec.edge.kind };
2402
+ const existing = original && model.edges.find((e) => sameEdge(e, original));
2403
+ const [source, setSource] = useState3(original?.source ?? targetSpec.source ?? null);
2404
+ const [target, setTarget] = useState3(original?.target ?? targetSpec.target ?? null);
2405
+ const [kind, setKind] = useState3(existing?.kind ?? "");
2406
+ const [label, setLabel] = useState3(existing?.label ?? "");
2789
2407
  const kinds = useMemo2(() => [...new Set(model.edges.map((e) => e.kind).filter(Boolean))].sort(), [model]);
2790
2408
  const save = () => {
2791
- const op = {
2792
- op: "addEdge",
2793
- edge: { source: source ?? "", target: target ?? "", ...kind.trim() ? { kind: kind.trim() } : {}, ...label.trim() ? { label: label.trim() } : {} }
2794
- };
2795
- if (submit(op)) onCancel();
2409
+ if (!source || !target) return;
2410
+ if (original) {
2411
+ const set = {};
2412
+ if (source !== original.source) set.source = source;
2413
+ if (target !== original.target) set.target = target;
2414
+ if (kind !== (existing?.kind ?? "")) set.kind = kind.trim();
2415
+ if (label !== (existing?.label ?? "")) set.label = label.trim();
2416
+ if (existing && !Object.keys(set).length) {
2417
+ onCancel();
2418
+ return;
2419
+ }
2420
+ if (submit({ op: "updateEdge", edge: original, set })) onCancel();
2421
+ } else if (submit({ op: "addEdge", edge: { source, target, ...kind.trim() && { kind: kind.trim() }, ...label.trim() && { label: label.trim() } } })) {
2422
+ onCancel();
2423
+ }
2796
2424
  };
2797
2425
  const foot = /* @__PURE__ */ jsxs2(Fragment2, { children: [
2798
- /* @__PURE__ */ jsx2("span", {}),
2799
- /* @__PURE__ */ jsxs2("span", { className: "gb-form-act", children: [
2800
- /* @__PURE__ */ jsx2("button", { type: "button", className: "gb-btn", onClick: onCancel, children: t.cancel }),
2801
- /* @__PURE__ */ jsx2("button", { type: "submit", className: "gb-btn gb-primary", disabled: !source || !target, children: t.create })
2802
- ] })
2803
- ] });
2804
- return /* @__PURE__ */ jsxs2(Shell, { title: t.newEdge, onClose: onCancel, onSubmit: save, foot, error, children: [
2805
- /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2806
- /* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-s`, children: t.source }),
2807
- /* @__PURE__ */ jsx2(NodePicker, { id: `${uid}-s`, model, value: source, onChange: setSource, autoFocus: !src, label: t.source, colorOf })
2426
+ original && /* @__PURE__ */ jsxs2("button", { type: "button", className: "gb-btn gb-danger-text", onClick: () => {
2427
+ if (submit({ op: "removeEdge", edge: original })) onCancel();
2428
+ }, children: [
2429
+ /* @__PURE__ */ jsx2(Icon, { d: I.trash, size: 15 }),
2430
+ t.remove
2808
2431
  ] }),
2809
- /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2810
- /* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-t`, children: t.target }),
2811
- /* @__PURE__ */ jsx2(
2432
+ /* @__PURE__ */ jsx2(SaveActions, { onCancel, label: original ? t.save : t.create, disabled: !source || !target })
2433
+ ] });
2434
+ return /* @__PURE__ */ jsxs2(Inspector, { title: original ? t.editEdge : t.newEdge, onClose: onCancel, onSubmit: save, foot, error, children: [
2435
+ /* @__PURE__ */ jsxs2("div", { className: "gb-field-pair", children: [
2436
+ /* @__PURE__ */ jsx2(InspectorField, { label: t.source, htmlFor: `${uid}-s`, children: /* @__PURE__ */ jsx2(
2437
+ NodePicker,
2438
+ {
2439
+ id: `${uid}-s`,
2440
+ model,
2441
+ value: source,
2442
+ onChange: setSource,
2443
+ autoFocus: !original && !targetSpec.source,
2444
+ label: t.source,
2445
+ colorOf,
2446
+ exclude: target ? (x) => x === target : void 0
2447
+ }
2448
+ ) }),
2449
+ /* @__PURE__ */ jsx2(InspectorField, { label: t.target, htmlFor: `${uid}-t`, children: /* @__PURE__ */ jsx2(
2812
2450
  NodePicker,
2813
2451
  {
2814
2452
  id: `${uid}-t`,
2815
2453
  model,
2816
2454
  value: target,
2817
2455
  onChange: setTarget,
2818
- autoFocus: !!src,
2456
+ autoFocus: !original && !!targetSpec.source,
2819
2457
  label: t.target,
2820
2458
  colorOf,
2821
2459
  exclude: source ? (x) => x === source : void 0
2822
2460
  }
2823
- )
2461
+ ) })
2824
2462
  ] }),
2825
- /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2826
- /* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-k`, children: t.kind }),
2463
+ /* @__PURE__ */ jsxs2(InspectorField, { label: t.kind, htmlFor: `${uid}-k`, children: [
2827
2464
  /* @__PURE__ */ jsx2("input", { id: `${uid}-k`, className: "gb-input", value: kind, list: `${uid}-kinds`, spellCheck: false, onChange: (e) => setKind(e.target.value) }),
2828
2465
  /* @__PURE__ */ jsx2("datalist", { id: `${uid}-kinds`, children: kinds.map((k) => /* @__PURE__ */ jsx2("option", { value: k }, k)) })
2829
2466
  ] }),
2830
- /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2831
- /* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-l`, children: t.edgeLabel }),
2832
- /* @__PURE__ */ jsx2("input", { id: `${uid}-l`, className: "gb-input", value: label, spellCheck: false, onChange: (e) => setLabel(e.target.value) })
2833
- ] })
2467
+ /* @__PURE__ */ jsx2(InspectorField, { label: t.edgeLabel, htmlFor: `${uid}-l`, children: /* @__PURE__ */ jsx2("input", { id: `${uid}-l`, className: "gb-input", value: label, spellCheck: false, onChange: (e) => setLabel(e.target.value) }) })
2834
2468
  ] });
2835
2469
  }
2836
2470
 
@@ -2842,47 +2476,24 @@ function applyLook(profile, look) {
2842
2476
  if (!look || !(look.nodePalette || look.edgePalette || look.nodeSize || look.edgeWidth)) return profile;
2843
2477
  return {
2844
2478
  ...profile,
2845
- nodePalette: { ...profile.nodePalette, ...look.nodePalette },
2846
- edgePalette: { ...profile.edgePalette, ...look.edgePalette },
2847
- nodeSize: { ...profile.nodeSize, ...look.nodeSize },
2848
- edgeWidth: { ...profile.edgeWidth, ...look.edgeWidth }
2479
+ nodePalette: kindTable(profile.nodePalette, look.nodePalette),
2480
+ edgePalette: kindTable(profile.edgePalette, look.edgePalette),
2481
+ nodeSize: kindTable(profile.nodeSize, look.nodeSize),
2482
+ edgeWidth: kindTable(profile.edgeWidth, look.edgeWidth)
2849
2483
  };
2850
2484
  }
2851
2485
  var isEmptyLook = (l) => !l.skeleton && ![l.nodePalette, l.edgePalette, l.nodeSize, l.edgeWidth].some((m) => m && Object.keys(m).length);
2852
- function readMarks(c, cy, style, nodeKinds, edgeKinds) {
2853
- if (c.cy !== cy || c.style !== style) {
2854
- c.cy = cy;
2855
- c.style = style;
2856
- c.shapes.clear();
2857
- c.strokes.clear();
2858
- }
2859
- const live = cy && !cy.destroyed();
2860
- for (const k of nodeKinds) {
2861
- if (c.shapes.has(k) || !live) continue;
2862
- const n = cy.nodes(`.${cls(k)}`)[0];
2863
- if (n) c.shapes.set(k, shapeOf(n.pstyle("shape").value));
2864
- }
2865
- for (const k of edgeKinds) {
2866
- if (c.strokes.has(k) || !live) continue;
2867
- const e = cy.edges(`.${edgeKindClass(k)}`)[0];
2868
- if (e) c.strokes.set(k, { dash: e.pstyle("line-style").value, head: arrowOf(e.pstyle("target-arrow-shape").value), tail: arrowOf(e.pstyle("source-arrow-shape").value) });
2869
- }
2870
- return {
2871
- shape: (k) => c.shapes.get(k) ?? "circle",
2872
- stroke: (k) => c.strokes.get(k) ?? { dash: "solid", head: "none", tail: "none" }
2873
- };
2874
- }
2875
2486
  function tally(model, profile) {
2876
- const nodes = {};
2877
- const edges = {};
2878
- let plain = 0;
2487
+ const nodes = /* @__PURE__ */ Object.create(null);
2488
+ const edges = /* @__PURE__ */ Object.create(null);
2489
+ let plain2 = 0;
2879
2490
  for (const n of model.nodes) {
2880
2491
  const hollow = !!n.flags?.some((f) => profile.placeholderFlags.includes(f));
2881
2492
  if (!hollow && n.kind) nodes[n.kind] = (nodes[n.kind] ?? 0) + 1;
2882
- else plain++;
2493
+ else plain2++;
2883
2494
  }
2884
- for (const e of model.edges) if (e.kind && e.kind in profile.edgePalette) edges[e.kind] = (edges[e.kind] ?? 0) + 1;
2885
- return { nodes, edges, plain };
2495
+ for (const e of model.edges) if (e.kind && Object.hasOwn(profile.edgePalette, e.kind)) edges[e.kind] = (edges[e.kind] ?? 0) + 1;
2496
+ return { nodes, edges, plain: plain2 };
2886
2497
  }
2887
2498
  var SCALES = [0.5, 1, 2];
2888
2499
  var OPEN_DELAY_MS = 120;
@@ -2952,7 +2563,7 @@ function Item(p) {
2952
2563
  "div",
2953
2564
  {
2954
2565
  ref: panel,
2955
- className: "gb-lg-pop",
2566
+ className: "gb-lg-pop gb-glass gb-raised gb-round",
2956
2567
  role: "dialog",
2957
2568
  "aria-label": p.title,
2958
2569
  "data-side": placement?.side,
@@ -3040,30 +2651,6 @@ function NodeMark({ color, shape = "circle", ring, off, scale = 1 }) {
3040
2651
  const r = (off ? 4.8 : 5.5) * (1 + 0.2 * Math.log2(scale));
3041
2652
  return /* @__PURE__ */ jsx3("svg", { className: "gb-lg-mark", viewBox: "0 0 14 14", width: 14, height: 14, children: shape === "hexagon" ? /* @__PURE__ */ jsx3("polygon", { points: [0, 1, 2, 3, 4, 5].map((i) => `${7 + r * Math.sin(i * Math.PI / 3)},${7 - r * Math.cos(i * Math.PI / 3)}`).join(" "), ...paint }) : shape === "diamond" ? /* @__PURE__ */ jsx3("polygon", { points: `7,${7 - r} ${7 + r},7 7,${7 + r} ${7 - r},7`, ...paint }) : shape === "rect" ? /* @__PURE__ */ jsx3("rect", { x: 7 - r * 0.85, y: 7 - r * 0.85, width: r * 1.7, height: r * 1.7, rx: 1.5, ...paint }) : /* @__PURE__ */ jsx3("circle", { cx: 7, cy: 7, r, ...paint }) });
3042
2653
  }
3043
- var DASH = { dashed: "4 2.5", dotted: "0.1 3" };
3044
- function EdgeMark({ color, stroke, off, scale = 1 }) {
3045
- const sw = 1.8 * (1 + 0.3 * Math.log2(scale));
3046
- const x1 = stroke.tail === "triangle" ? 6 : 2, x2 = stroke.head === "triangle" ? 18 : 22;
3047
- return /* @__PURE__ */ jsxs3("svg", { className: "gb-lg-mark", viewBox: "0 0 24 12", width: 24, height: 12, opacity: off ? 0.35 : 1, children: [
3048
- /* @__PURE__ */ jsx3(
3049
- "line",
3050
- {
3051
- x1,
3052
- y1: 6,
3053
- x2,
3054
- y2: 6,
3055
- stroke: color,
3056
- strokeWidth: sw,
3057
- strokeLinecap: stroke.dash === "dotted" ? "round" : void 0,
3058
- strokeDasharray: DASH[stroke.dash]
3059
- }
3060
- ),
3061
- stroke.head === "triangle" && /* @__PURE__ */ jsx3("polygon", { points: "17,2.5 23,6 17,9.5", fill: color }),
3062
- stroke.tail === "triangle" && /* @__PURE__ */ jsx3("polygon", { points: "7,2.5 1,6 7,9.5", fill: color }),
3063
- stroke.head === "tee" && /* @__PURE__ */ jsx3("path", { d: "M22,2.5 V9.5", stroke: color, strokeWidth: 1.8 }),
3064
- stroke.tail === "tee" && /* @__PURE__ */ jsx3("path", { d: "M2,2.5 V9.5", stroke: color, strokeWidth: 1.8 })
3065
- ] });
3066
- }
3067
2654
  function SkeletonEdge({ theme }) {
3068
2655
  const id = useMemo3(() => `gb-lg-contain-${Math.random().toString(36).slice(2)}`, []);
3069
2656
  return /* @__PURE__ */ jsxs3("svg", { className: "gb-lg-mark", viewBox: "0 0 30 12", width: 30, height: 12, children: [
@@ -3085,7 +2672,7 @@ function LegendFrame({ collapsed, children }) {
3085
2672
  if (!before || before.width === after.width && before.height === after.height || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
3086
2673
  const body = el.firstElementChild;
3087
2674
  body.style.width = `${body.getBoundingClientRect().width}px`;
3088
- const timing = { duration: 220, easing: "cubic-bezier(.3,.7,.2,1)" };
2675
+ const timing = { duration: 220, easing: getComputedStyle(el).getPropertyValue("--gb-ease").trim() };
3089
2676
  const motion = el.animate([
3090
2677
  { width: `${before.width}px`, height: `${before.height}px`, overflow: "clip" },
3091
2678
  { width: `${after.width}px`, height: `${after.height}px`, overflow: "clip" }
@@ -3110,7 +2697,7 @@ function LegendFrame({ collapsed, children }) {
3110
2697
  ro.observe(el);
3111
2698
  return () => ro.disconnect();
3112
2699
  }, []);
3113
- return /* @__PURE__ */ jsx3("div", { className: "gb-legend", ref: root, children });
2700
+ return /* @__PURE__ */ jsx3("div", { className: "gb-legend gb-glass gb-raised gb-round", ref: root, children });
3114
2701
  }
3115
2702
  function Legend(p) {
3116
2703
  const t = useStrings();
@@ -3189,8 +2776,15 @@ function Legend(p) {
3189
2776
  const slot = (key) => ({ k: key, open: open === key, ctl });
3190
2777
  const nodeKinds = Object.keys(count.nodes).sort((a, b) => count.nodes[b] - count.nodes[a] || a.localeCompare(b));
3191
2778
  const edgeKinds = Object.keys(profile.edgePalette).filter((k) => count.edges[k]);
3192
- const markCache = useRef3({ cy: null, style: null, shapes: /* @__PURE__ */ new Map(), strokes: /* @__PURE__ */ new Map() });
3193
- const marks = readMarks(markCache.current, p.cy, profile.style, nodeKinds, edgeKinds);
2779
+ const shapes = useMemo3(() => /* @__PURE__ */ new Map(), [p.cy, profile.style]);
2780
+ const shape = (k) => {
2781
+ const cy = p.cy;
2782
+ if (!shapes.has(k) && cy && !cy.destroyed()) {
2783
+ const node = cy.nodes(`.${cls(k)}`)[0];
2784
+ if (node) shapes.set(k, shapeOf(node.pstyle("shape").value));
2785
+ }
2786
+ return shapes.get(k);
2787
+ };
3194
2788
  const spot = picking || p.collapsed ? null : open ?? focused;
3195
2789
  const onEmphasis = p.onEmphasis;
3196
2790
  useEffect3(() => {
@@ -3245,7 +2839,7 @@ function Legend(p) {
3245
2839
  scale,
3246
2840
  glyph: "dot",
3247
2841
  onScale: (s) => set("nodeSize", k, s),
3248
- mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(colorOfKind(k)), shape: marks.shape(k), ring: theme.canvas, off, scale }),
2842
+ mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(colorOfKind(k)), shape: shape(k), ring: theme.canvas, off, scale }),
3249
2843
  label: name(k),
3250
2844
  count: count.nodes[k]
3251
2845
  },
@@ -3280,7 +2874,7 @@ function Legend(p) {
3280
2874
  scale,
3281
2875
  glyph: "line",
3282
2876
  onScale: (s) => set("edgeWidth", k, s),
3283
- mark: /* @__PURE__ */ jsx3(EdgeMark, { color: shown(profile.edgePalette[k]), stroke: marks.stroke(k), off, scale }),
2877
+ mark: /* @__PURE__ */ jsx3(EdgeMark, { kind: k, off }),
3284
2878
  label: name(k),
3285
2879
  count: count.edges[k]
3286
2880
  },
@@ -3347,12 +2941,12 @@ function DiffOverlay(p) {
3347
2941
  const shown = (id) => (!only || only.has(id)) && (!visible || visible.has(id));
3348
2942
  const table = MARK[side];
3349
2943
  const rank = { merged: 0, moved: 1, removed: 2, added: 3, changed: 4 };
3350
- const list = [...delta.changes].filter((c) => table[c.kind] && shown(c.id)).sort((a, b) => rank[a.kind] - rank[b.kind]);
3351
- const truncated2 = Math.max(0, list.length - max);
2944
+ const list2 = [...delta.changes].filter((c) => table[c.kind] && shown(c.id)).sort((a, b) => rank[a.kind] - rank[b.kind]);
2945
+ const truncated2 = Math.max(0, list2.length - max);
3352
2946
  const nodeGlow2 = LEVEL.map(emptyBuckets);
3353
2947
  const edgeGlow2 = emptyBuckets();
3354
2948
  const wire = [];
3355
- for (const c of list.slice(0, max)) {
2949
+ for (const c of list2.slice(0, max)) {
3356
2950
  const box = geom.nodes[c.id];
3357
2951
  if (!box) continue;
3358
2952
  const ink = table[c.kind];
@@ -3399,15 +2993,12 @@ function DiffOverlay(p) {
3399
2993
  ] }, ink)),
3400
2994
  wireD && /* @__PURE__ */ jsx4("path", { className: "gb-pastwire", d: wireD, strokeWidth: 2 * inv, style: dash })
3401
2995
  ] }) }),
3402
- truncated > 0 && /* @__PURE__ */ jsx4("div", { className: "gb-diff-trunc", children: str.diffTruncated(truncated) })
2996
+ truncated > 0 && /* @__PURE__ */ jsx4("div", { className: "gb-diff-trunc gb-glass gb-raised gb-round", children: str.diffTruncated(truncated) })
3403
2997
  ] });
3404
2998
  }
3405
2999
 
3406
3000
  // src/react/GraphCanvas.tsx
3407
3001
  import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
3408
- var TIGHTEN_MAX = 400;
3409
- var NODE_PITCH = 150;
3410
- var SEED_MAX = 60;
3411
3002
  var PLANE_MS = 720;
3412
3003
  var FLY_ZOOM = 1;
3413
3004
  var FLY_MS_PER_S = 380;
@@ -3418,7 +3009,6 @@ var FIT_MAX_ZOOM = 1.5;
3418
3009
  var planeKey = (v) => `${v.planes ? 1 : 0}|${(v.layers ?? []).join(",")}`;
3419
3010
  var litPlates = (plates, alphaOf) => plates.map((p) => ({ ...p, alpha: alphaOf(p.layer) })).filter((p) => p.alpha > 1e-3);
3420
3011
  var shownIn = (v) => (layer) => !v.layers || v.layers.includes(layer) ? 1 : 0;
3421
- var sightKey = (v) => `${planeKey(v)}|${(v.origins ?? []).join(",")}`;
3422
3012
  var LABEL_FONT = { min: 12, max: 15 };
3423
3013
  var labelFontOf = (leaves) => LABEL_FONT.min + (LABEL_FONT.max - LABEL_FONT.min) * nodeWeight(leaves);
3424
3014
  var labelCss = (px, bold = false) => `${bold ? 600 : 400} ${px}px ui-sans-serif, system-ui, sans-serif`;
@@ -3443,7 +3033,7 @@ var BREATH_IDLE_MS = 4e3;
3443
3033
  var BREATH_INTERVAL_MS = 2600;
3444
3034
  var BREATH_AMPLITUDE = 0.08;
3445
3035
  var smoothstep = (x) => x * x * (3 - 2 * x);
3446
- var clamp012 = (x) => Math.min(1, Math.max(0, x));
3036
+ var clamp01 = (x) => Math.min(1, Math.max(0, x));
3447
3037
  var SPRITE_MAX = 1500;
3448
3038
  var sprites = /* @__PURE__ */ new Map();
3449
3039
  var tintOf = ([r, g, b]) => `rgb(${[r, g, b].map((v) => Math.round(v / 8) * 8).join(",")})`;
@@ -3532,8 +3122,8 @@ function samePositions(a, b) {
3532
3122
  const ka = Object.keys(a);
3533
3123
  if (ka.length !== Object.keys(b).length) return false;
3534
3124
  for (const k of ka) {
3535
- const p = a[k], q2 = b[k];
3536
- if (!q2 || p.x !== q2.x || p.y !== q2.y) return false;
3125
+ const p = a[k], q = b[k];
3126
+ if (!q || p.x !== q.x || p.y !== q.y) return false;
3537
3127
  }
3538
3128
  return true;
3539
3129
  }
@@ -3695,7 +3285,7 @@ function seatFromLastFrame(cy, prev, parentOf) {
3695
3285
  y: vals.reduce((s, p) => s + p.y, 0) / vals.length
3696
3286
  };
3697
3287
  const seat = (id) => {
3698
- const anc = anchorOf(id, (q2) => !!prev[q2], parentOf);
3288
+ const anc = anchorOf(id, (q) => !!prev[q], parentOf);
3699
3289
  return anc ? prev[anc] : mid;
3700
3290
  };
3701
3291
  cy.batch(() => {
@@ -3746,11 +3336,107 @@ function Drawer({ children }) {
3746
3336
  }, [open]);
3747
3337
  const content = children || (gone ? null : last.current);
3748
3338
  if (!content) return null;
3749
- return /* @__PURE__ */ jsx5("div", { className: `gb-drawer${open ? "" : " is-closing"}`, children: content });
3339
+ return /* @__PURE__ */ jsx5("div", { className: `gb-drawer gb-glass gb-raised gb-round${open ? "" : " is-closing"}`, children: content });
3750
3340
  }
3751
3341
  var DRAWER_MS = 200;
3342
+ function hasTarget(model, target) {
3343
+ return "node" in target ? model.index.has(target.node) : model.edges.some((e) => sameEdge(e, target.edge));
3344
+ }
3752
3345
  function GraphCanvas(props) {
3346
+ const [innerView, setInnerView] = useState5({ ...FULL_VIEW, ...props.defaultView });
3347
+ const rawView = props.view ?? innerView;
3348
+ const patchView = useCallback2((patch) => {
3349
+ const next = { ...props.view ?? innerView, ...patch };
3350
+ if (!props.view) setInnerView(next);
3351
+ props.onViewChange?.(next);
3352
+ }, [props.view, props.onViewChange, innerView]);
3353
+ const [forcedScope, setForcedScope] = useState5("");
3354
+ const scopeKey = JSON.stringify(rawView.subtree ? ["node", rawView.subtree] : rawView.origins?.length ? ["files", ...rawView.origins] : []);
3355
+ const scoped = useSubgraph(props, rawView, forcedScope === scopeKey);
3356
+ const cy = useRef4(null);
3357
+ const destination = useRef4(null);
3358
+ const returnCamera = useRef4(null);
3359
+ const fullLayers = useRef4({ layers: null, planes: void 0 });
3360
+ const change = (subtree, origins, target) => {
3361
+ destination.current = target ?? null;
3362
+ if (!scoped.active) {
3363
+ fullLayers.current = { layers: rawView.layers, planes: rawView.planes };
3364
+ returnCamera.current = null;
3365
+ const graph = cy.current;
3366
+ if (graph && !graph.destroyed()) {
3367
+ const center = { x: graph.width() / 2, y: graph.height() / 2 };
3368
+ let nearest = Infinity;
3369
+ graph.nodes(":visible").forEach((n) => {
3370
+ if (n.id() === VIRTUAL_ROOT) return;
3371
+ const pos = n.renderedPosition(), dx = pos.x - center.x, dy = pos.y - center.y;
3372
+ const distance2 = dx * dx + dy * dy;
3373
+ if (distance2 < nearest) {
3374
+ nearest = distance2;
3375
+ returnCamera.current = { id: n.id(), dx, dy, zoom: graph.zoom() };
3376
+ }
3377
+ });
3378
+ }
3379
+ }
3380
+ setForcedScope("");
3381
+ const layers = subtree || origins?.length || target ? { layers: null, planes: false } : fullLayers.current;
3382
+ patchView({ subtree, origins: origins ?? null, query: "", ...layers });
3383
+ };
3384
+ const strings = props.strings;
3385
+ const lastRoot = useRef4(null);
3386
+ const root = rawView.subtree && (scoped.after.index.get(rawView.subtree) ?? scoped.before?.index.get(rawView.subtree));
3387
+ if (root) lastRoot.current = root;
3388
+ const label = rawView.subtree ? lastRoot.current?.id === rawView.subtree ? lastRoot.current.label : rawView.subtree : (rawView.origins ?? []).join(", ");
3389
+ const scope = {
3390
+ active: scoped.active,
3391
+ subtree: rawView.subtree,
3392
+ origins: rawView.subtree ? null : rawView.origins,
3393
+ label,
3394
+ files: scoped.origins,
3395
+ change,
3396
+ before: scoped.before,
3397
+ after: scoped.after,
3398
+ local: scoped.current,
3399
+ leaveFor: (target) => change(null, void 0, target),
3400
+ missing: rawView.subtree ? strings?.absentNode ?? EN.absentNode : strings?.absentSource ?? EN.absentSource
3401
+ };
3402
+ const localView = useMemo5(() => ({ ...rawView, subtree: null, origins: null }), [rawView]);
3403
+ const caption = typeof props.note === "function" ? props.note(scoped.current, scoped.delta) : props.note ?? (scoped.active ? (strings?.stats ?? EN.stats)(scoped.current.nodes.length, scoped.current.edges.length) : void 0);
3404
+ return /* @__PURE__ */ jsx5(
3405
+ CanvasScene,
3406
+ {
3407
+ ...props,
3408
+ scopeKey,
3409
+ scope,
3410
+ sourceDiff: props.diff,
3411
+ world: props.profile ?? defaultProfile,
3412
+ restoreCamera: returnCamera,
3413
+ destination,
3414
+ note: caption,
3415
+ view: localView,
3416
+ setView: patchView,
3417
+ model: scoped.model,
3418
+ diff: scoped.delta,
3419
+ profile: scoped.profile,
3420
+ editModel: scoped.after,
3421
+ onReady: (instance) => {
3422
+ cy.current = instance;
3423
+ props.onReady?.(instance);
3424
+ },
3425
+ layout: scoped.active ? null : props.layout,
3426
+ onLayout: scoped.active ? void 0 : props.onLayout,
3427
+ layerIssue: scoped.active ? strings?.noLocalFloors ?? EN.noLocalFloors : props.layerIssue,
3428
+ onForceLayers: scoped.active ? scoped.canForce ? () => {
3429
+ setForcedScope(scopeKey);
3430
+ patchView({ planes: true });
3431
+ } : void 0 : props.onForceLayers
3432
+ }
3433
+ );
3434
+ }
3435
+ function CanvasScene(props) {
3753
3436
  const {
3437
+ scope,
3438
+ view: rawView,
3439
+ setView,
3754
3440
  model,
3755
3441
  profile: baseProfile = defaultProfile,
3756
3442
  theme: baseTheme = LIGHT_THEME,
@@ -3793,9 +3479,9 @@ function GraphCanvas(props) {
3793
3479
  } = props;
3794
3480
  const [innerLook, setInnerLook] = useState5(props.defaultLook ?? {});
3795
3481
  const look = props.look ?? innerLook;
3796
- const setLook = useCallback2((l) => {
3797
- if (!props.look) setInnerLook(l);
3798
- props.onLookChange?.(l);
3482
+ const setLook = useCallback2((next) => {
3483
+ if (!props.look) setInnerLook(next);
3484
+ props.onLookChange?.(next);
3799
3485
  }, [props.look, props.onLookChange]);
3800
3486
  const lookProfile = useMemo5(() => applyLook(baseProfile, look), [baseProfile, look]);
3801
3487
  const theme = useMemo5(() => look.skeleton ? { ...baseTheme, skeleton: look.skeleton } : baseTheme, [baseTheme, look.skeleton]);
@@ -3808,33 +3494,31 @@ function GraphCanvas(props) {
3808
3494
  if ((stageRef.current?.clientWidth ?? 1e3) < 640) setLegendCollapsed(true);
3809
3495
  }, []);
3810
3496
  const [liveCy, setLiveCy] = useState5(null);
3811
- const profile = useShapeOf(lookProfile);
3497
+ const requestedProfile = useShapeOf(lookProfile);
3498
+ const [profile, setProfile] = useState5(requestedProfile);
3812
3499
  const strings = useMemo5(() => ({ ...EN, ...props.strings, error: { ...EN.error, ...props.strings?.error } }), [props.strings]);
3813
- const [innerView, setInnerView] = useState5({ ...FULL_VIEW, ...props.defaultView });
3814
- const rawView = props.view ?? innerView;
3815
- const setView = useCallback2((patch) => {
3816
- const next = { ...props.view ?? innerView, ...patch };
3817
- if (!props.view) setInnerView(next);
3818
- props.onViewChange?.(next);
3819
- }, [props.view, props.onViewChange, innerView]);
3820
3500
  const containerRef = useRef4(null);
3821
3501
  const [layoutOwner] = useState5(() => ({}));
3822
3502
  const cyRef = useRef4(null);
3823
3503
  const mirrorRef = useRef4(null);
3504
+ const edgeMarks = useMemo5(() => edgeMarksFor(lookProfile, theme, liveCy, () => mirrorRef.current), [lookProfile, theme, liveCy]);
3824
3505
  const mirrorElRef = useRef4(null);
3825
3506
  const syncingRef = useRef4(false);
3826
3507
  const baseRef = useRef4({});
3827
- const tightenedRef = useRef4(false);
3828
3508
  const runRef = useRef4(0);
3829
3509
  const platesRef = useRef4([]);
3830
3510
  const dispRef = useRef4({});
3511
+ const visibleFrameRef = useRef4(/* @__PURE__ */ new Set());
3512
+ const framingRef = useRef4("");
3831
3513
  const [renderModel, setRenderModel] = useState5(model);
3832
3514
  const prevModelRef = useRef4(null);
3833
3515
  const prevProfileRef = useRef4(null);
3834
3516
  const [pastRenderModel, setPastRenderModel] = useState5(null);
3835
- const [renderWorld, setRenderWorld] = useState5(profile);
3836
- if (renderWorld !== profile) {
3837
- setRenderWorld(profile);
3517
+ const world = useShapeOf(props.world);
3518
+ const [renderWorld, setRenderWorld] = useState5(world);
3519
+ if (renderWorld !== world) {
3520
+ setRenderWorld(world);
3521
+ setProfile(requestedProfile);
3838
3522
  setRenderModel(model);
3839
3523
  setPastRenderModel(null);
3840
3524
  }
@@ -3852,7 +3536,7 @@ function GraphCanvas(props) {
3852
3536
  const dimsRef = useRef4({});
3853
3537
  const labelsRef = useRef4(/* @__PURE__ */ new Map());
3854
3538
  const labelRafRef = useRef4(null);
3855
- const hoverOutRef = useRef4(null);
3539
+ const hoverTimerRef = useRef4(null);
3856
3540
  const painterRef = useRef4(null);
3857
3541
  const ringsRef = useRef4(/* @__PURE__ */ new Map());
3858
3542
  const ringRafRef = useRef4(null);
@@ -3877,16 +3561,21 @@ function GraphCanvas(props) {
3877
3561
  const playPlanesRef = useRef4(null);
3878
3562
  const sightRef = useRef4("");
3879
3563
  const searchInputRef = useRef4(null);
3880
- const [selected, setSelected] = useState5(null);
3564
+ const [trail, setTrail] = useState5([]);
3565
+ const target = trail.at(-1);
3881
3566
  const [editing, setEditing] = useState5(null);
3567
+ const [inspectedScope, setInspectedScope] = useState5(props.scopeKey);
3568
+ if (inspectedScope !== props.scopeKey) {
3569
+ setInspectedScope(props.scopeKey);
3570
+ setTrail([]);
3571
+ setEditing(null);
3572
+ }
3882
3573
  const editingModel = props.editModel ?? model;
3883
- const modelRef = useRef4(model);
3884
- modelRef.current = model;
3885
3574
  const editable = !!onEdit && !diff;
3886
3575
  const onEditRef = useRef4(onEdit);
3887
3576
  onEditRef.current = onEdit;
3888
3577
  const pendingPickRef = useRef4(null);
3889
- const keepSelRef = useRef4(null);
3578
+ const keepSelRef = useRef4(void 0);
3890
3579
  const pickRef = useRef4(() => {
3891
3580
  });
3892
3581
  const [prog, setProg] = useState5(null);
@@ -3904,11 +3593,7 @@ function GraphCanvas(props) {
3904
3593
  const has = new Set(model.nodes.map((n) => n.layer ?? profile.layers[0].id));
3905
3594
  return profile.layers.filter((l) => has.has(l.id));
3906
3595
  }, [model, profile.layers]);
3907
- const origins = useMemo5(() => originsOf(model), [model]);
3908
- const view = useMemo5(
3909
- () => planeView(originView(rawView, origins), layersHere),
3910
- [rawView, origins, layersHere]
3911
- );
3596
+ const view = useMemo5(() => planeView(rawView, layersHere), [rawView, layersHere]);
3912
3597
  const resolved = useMemo5(() => resolveView(renderModel, built.elements, view), [renderModel, built, view]);
3913
3598
  const stats = useMemo5(() => {
3914
3599
  const hn = new Set(view.hiddenNodeKinds ?? []), he = new Set(view.hiddenEdgeKinds ?? []);
@@ -3922,11 +3607,48 @@ function GraphCanvas(props) {
3922
3607
  return { nodes, edges };
3923
3608
  }, [model, resolved, view.hiddenNodeKinds, view.hiddenEdgeKinds]);
3924
3609
  const diffSides = useMemo5(() => diff ? unionSides(diff) : null, [diff]);
3610
+ const oldIds = useMemo5(() => diff && new Map([...diff.resolved].map(([old, id]) => [id, old])), [diff]);
3611
+ const fullPast = useMemo5(() => {
3612
+ if (!scope.active || !scope.before) return diffSides?.before;
3613
+ const identity = props.sourceDiff ?? diff;
3614
+ if (!identity || ![...identity.resolved].some(([a, b]) => a !== b)) return scope.before;
3615
+ return unionSides({ ...identity, before: scope.before }).before;
3616
+ }, [scope.active, scope.before, diffSides, diff, props.sourceDiff]);
3617
+ const oldSubject = useMemo5(() => {
3618
+ if (!diff || !diffSides || !target || !fullPast) return void 0;
3619
+ const oldId = "node" in target && (oldIds?.get(target.node) ?? target.node);
3620
+ if (scope.active && !hasTarget(diffSides.before, target)) return void 0;
3621
+ return inspect(fullPast, target, oldId ? (scope.before ?? diff.before).index.get(oldId) : void 0);
3622
+ }, [diff, diffSides, fullPast, oldIds, target, scope.active, scope.before]);
3623
+ const currentSubject = useMemo5(() => {
3624
+ if (scope.active && target && !hasTarget(diff?.after ?? scope.local, target)) return void 0;
3625
+ return inspect(scope.active ? editingModel : diff?.after ?? editingModel, target);
3626
+ }, [scope.active, scope.local, diff, editingModel, target]);
3627
+ const selected = useMemo5(() => {
3628
+ const subject = target?.past ? oldSubject ?? currentSubject : currentSubject ?? oldSubject;
3629
+ const n = subject?.node;
3630
+ return n ? {
3631
+ id: n.id,
3632
+ label: n.label,
3633
+ kind: n.kind ?? "",
3634
+ layer: n.layer ?? profile.layers[0]?.id,
3635
+ parent: n.parent,
3636
+ order: n.order,
3637
+ origin: n.origin ?? null,
3638
+ container: !!subject.children.length,
3639
+ flags: [.../* @__PURE__ */ new Set([...n.flags ?? [], ...profile.nodeClass(subject.originalNode ?? n).split(/\s+/).filter(Boolean)])],
3640
+ detail: n.data ?? null
3641
+ } : null;
3642
+ }, [currentSubject, oldSubject, target, profile]);
3925
3643
  const pastBuilt = useMemo5(
3926
3644
  () => pastRenderModel ? buildElements(pastRenderModel, profile, { past: true }) : null,
3927
3645
  [pastRenderModel, profile]
3928
3646
  );
3929
- const issues = useMemo5(() => validateModel(model, profile), [model, profile]);
3647
+ const checks = useMemo5(() => {
3648
+ if (props.checks) return props.checks;
3649
+ return props.issues ? { lint: props.issues } : validateModelBySource(editingModel, profile);
3650
+ }, [props.checks, props.issues, editingModel, profile]);
3651
+ const issues = useMemo5(() => checks.review ? checks.lint.concat(checks.review) : checks.lint, [checks]);
3930
3652
  const onIssuesRef = useRef4(onIssues);
3931
3653
  onIssuesRef.current = onIssues;
3932
3654
  useEffect4(() => {
@@ -4004,6 +3726,7 @@ function GraphCanvas(props) {
4004
3726
  if (v) painterRef.current?.hover(null, true);
4005
3727
  onBusyRef.current?.(v);
4006
3728
  }, []);
3729
+ useEffect4(() => () => markBusy(false), [markBusy]);
4007
3730
  const carryLastFrame = useCallback2((resolved2) => {
4008
3731
  if (!resolved2.size) return;
4009
3732
  const carried = { ...dispRef.current };
@@ -4011,6 +3734,7 @@ function GraphCanvas(props) {
4011
3734
  for (const [oldId, unionId] of resolved2) {
4012
3735
  const p = dispRef.current[oldId];
4013
3736
  if (p && !carried[unionId]) carried[unionId] = p;
3737
+ if (visibleFrameRef.current.has(oldId)) visibleFrameRef.current.add(unionId);
4014
3738
  const s = book.get(oldId);
4015
3739
  if (s && !book.has(unionId)) book.set(unionId, { ...s });
4016
3740
  }
@@ -4022,10 +3746,11 @@ function GraphCanvas(props) {
4022
3746
  return;
4023
3747
  }
4024
3748
  missedRef.current = false;
3749
+ setProfile(requestedProfile);
4025
3750
  const prev = prevModelRef.current;
4026
3751
  prevModelRef.current = model;
4027
- const sameWorld = prevProfileRef.current === profileRef.current;
4028
- prevProfileRef.current = profileRef.current;
3752
+ const sameWorld = prevProfileRef.current === world;
3753
+ prevProfileRef.current = world;
4029
3754
  const spec = resolveSpec(animateRef.current);
4030
3755
  const sides = diffRef.current ? diffSidesRef.current ?? unionSides(diffRef.current) : null;
4031
3756
  const settleNow = () => {
@@ -4038,9 +3763,13 @@ function GraphCanvas(props) {
4038
3763
  prevPastRef.current = sides ? sides.before : null;
4039
3764
  setPastRenderModel(sides ? sides.before : null);
4040
3765
  };
4041
- if (!sameWorld) {
3766
+ if (!sameWorld || !model.nodes.length || !prev?.nodes.length) {
4042
3767
  dispRef.current = {};
3768
+ rawRef.current = {};
3769
+ visibleFrameRef.current.clear();
3770
+ framingRef.current = "";
4043
3771
  labelsRef.current = /* @__PURE__ */ new Map();
3772
+ prevViewportRef.current = null;
4044
3773
  }
4045
3774
  if (!spec || !prev || prev === model || !sameWorld || !model.nodes.length || !prev.nodes.length) {
4046
3775
  settleNow();
@@ -4060,7 +3789,7 @@ function GraphCanvas(props) {
4060
3789
  pendingRef.current = step;
4061
3790
  pendingPastRef.current = pastStep;
4062
3791
  marksRef.current = STEP_MARKS;
4063
- pendingSkinsRef.current = planSkins(step, prev, model, profileRef.current);
3792
+ pendingSkinsRef.current = planSkins(step, prev, model, requestedProfile);
4064
3793
  leftRef.current = /* @__PURE__ */ new Set();
4065
3794
  leftPastRef.current = /* @__PURE__ */ new Set();
4066
3795
  setDiffGeom(EMPTY_GEOM);
@@ -4080,11 +3809,11 @@ function GraphCanvas(props) {
4080
3809
  }
4081
3810
  carryLastFrame(delta.resolved);
4082
3811
  pendingRef.current = delta;
4083
- pendingSkinsRef.current = planSkins(delta, prev, model, profileRef.current);
3812
+ pendingSkinsRef.current = planSkins(delta, prev, model, requestedProfile);
4084
3813
  leftRef.current = /* @__PURE__ */ new Set();
4085
3814
  markBusy(true);
4086
3815
  setRenderModel(delta.model);
4087
- }, [model, resume]);
3816
+ }, [model, requestedProfile, world, resume]);
4088
3817
  const [diffGeom, setDiffGeom] = useState5(EMPTY_GEOM);
4089
3818
  const [pastGeom, setPastGeom] = useState5(EMPTY_GEOM);
4090
3819
  const visibleNodes = useCallback2((cy) => {
@@ -4092,17 +3821,19 @@ function GraphCanvas(props) {
4092
3821
  const left = leftRef.current;
4093
3822
  return cy.nodes().filter((n) => visible.has(n.id()) && !left.has(n.id()));
4094
3823
  }, []);
4095
- const fitAll = useCallback2((cy, coll, animate2 = false) => {
3824
+ const frameIds = useCallback2((visible) => {
3825
+ const ids = /* @__PURE__ */ new Set();
3826
+ const hidden = new Set(viewRef.current.hiddenNodeKinds);
3827
+ visible.forEach((n) => {
3828
+ if (n.id() !== VIRTUAL_ROOT && !n.isParent() && !hidden.has(n.data("kind")) && !(diffRef.current && (n.hasClass("gb-removed") || n.hasClass("gb-merged")))) ids.add(n.id());
3829
+ });
3830
+ return ids;
3831
+ }, []);
3832
+ const fitAll = useCallback2((cy, coll) => {
4096
3833
  const vis = coll ?? visibleNodes(cy);
4097
3834
  const go = (eles, padding) => {
4098
- const fit2 = () => {
4099
- cy.fit(eles, padding);
4100
- if (cy.zoom() > FIT_MAX_ZOOM) cy.zoom({ level: FIT_MAX_ZOOM, renderedPosition: { x: cy.width() / 2, y: cy.height() / 2 } });
4101
- };
4102
- if (animate2) requestAnimationFrame(() => {
4103
- if (!cy.destroyed()) fit2();
4104
- });
4105
- else fit2();
3835
+ cy.fit(eles, padding);
3836
+ if (cy.zoom() > FIT_MAX_ZOOM) cy.zoom({ level: FIT_MAX_ZOOM, renderedPosition: { x: cy.width() / 2, y: cy.height() / 2 } });
4106
3837
  };
4107
3838
  if (!viewRef.current.planes || platesRef.current.length === 0) {
4108
3839
  if (vis.length) go(vis, compactRef.current ? 24 : FIT_PAD);
@@ -4150,18 +3881,26 @@ function GraphCanvas(props) {
4150
3881
  const left = leftRef.current;
4151
3882
  painterRef.current?.spotlight(ids.size ? new Set([...ids].filter((id) => !left.has(id))) : null);
4152
3883
  }, []);
3884
+ const spotlightLayer = useCallback2((layer) => {
3885
+ if (hotLayerRef.current === layer) return;
3886
+ hotLayerRef.current = layer;
3887
+ setHotLayer(layer);
3888
+ respot();
3889
+ }, [respot]);
4153
3890
  const projectAt = useCallback2((raw, t) => {
4154
3891
  const layers = profileRef.current.layers;
4155
3892
  if (layers.length < 2) return { positions: { ...raw }, plates: [] };
4156
- const frame = isNarrowing(viewRef.current) ? resolvedRef.current.visible : null;
4157
- return projectPlanes(raw, layerOfRef.current, layers, {}, t, frame);
3893
+ return projectPlanes(raw, layerOfRef.current, layers, {}, t);
4158
3894
  }, []);
4159
3895
  const showPlates = useCallback2((plates2, alpha) => {
4160
3896
  platesRef.current = plates2;
4161
3897
  plateAlphaRef.current = alpha;
4162
3898
  setPlates(plates2);
4163
3899
  setPlateAlpha(alpha);
4164
- }, []);
3900
+ if (hotLayerRef.current && (alpha <= 0.01 || !plates2.some((p) => p.layer === hotLayerRef.current))) {
3901
+ spotlightLayer(null);
3902
+ }
3903
+ }, [spotlightLayer]);
4165
3904
  const applyView = useCallback2((opts) => {
4166
3905
  const cy = cyRef.current;
4167
3906
  if (!cy) return;
@@ -4190,55 +3929,9 @@ function GraphCanvas(props) {
4190
3929
  showPlates(litPlates(projectAt(rawRef.current, planeTRef.current).plates, shownIn(v)), plateAlphaRef.current);
4191
3930
  }
4192
3931
  const vis = visibleNodes(cy);
4193
- const visEdges = vis.edgesWith(vis);
4194
- const wantTighten = isNarrowing(v) && !v.planes && vis.length > 1 && vis.length <= TIGHTEN_MAX && !diffRef.current;
4195
- if (wantTighten) {
4196
- try {
4197
- const structureless = visEdges.length === 0 && vis.filter((n) => !n.isChildless()).length === 0;
4198
- const seed = vis.length <= SEED_MAX;
4199
- if (!structureless && seed) {
4200
- const bb = vis.boundingBox();
4201
- const want = Math.sqrt(vis.length) * NODE_PITCH;
4202
- const k = want / Math.max(1, bb.w, bb.h);
4203
- if (k < 1) {
4204
- const mx = bb.x1 + bb.w / 2, my = bb.y1 + bb.h / 2;
4205
- cy.batch(() => vis.forEach((n) => {
4206
- const p = n.position();
4207
- n.position({ x: mx + (p.x - mx) * k, y: my + (p.y - my) * k });
4208
- }));
4209
- }
4210
- }
4211
- vis.union(visEdges).layout(structureless ? { name: "grid", fit: false, animate: false, avoidOverlap: true, condense: true } : {
4212
- name: "fcose",
4213
- quality: "default",
4214
- randomize: !seed,
4215
- animate: false,
4216
- fit: false,
4217
- nodeSeparation: 45,
4218
- idealEdgeLength: 60,
4219
- nodeRepulsion: 8e3,
4220
- packComponents: true,
4221
- tile: true,
4222
- tilingPaddingVertical: 8,
4223
- tilingPaddingHorizontal: 8
4224
- }).run();
4225
- tightenedRef.current = true;
4226
- if (opts?.fit !== false) fitAll(cy, vis, true);
4227
- return;
4228
- } catch {
4229
- }
4230
- }
4231
- if (tightenedRef.current) {
4232
- cy.batch(() => {
4233
- cy.nodes(":childless").forEach((n) => {
4234
- const p = baseRef.current[n.id()];
4235
- if (p) n.position(p);
4236
- });
4237
- });
4238
- tightenedRef.current = false;
4239
- }
3932
+ if (!busyRef.current) visibleFrameRef.current = frameIds(vis);
4240
3933
  if (opts?.fit !== false) fitAll(cy, vis);
4241
- }, [fitAll, visibleNodes, respot, projectAt, showPlates]);
3934
+ }, [fitAll, visibleNodes, respot, projectAt, showPlates, frameIds]);
4242
3935
  const touchInteraction = useCallback2(() => {
4243
3936
  lastInteractionRef.current = Date.now();
4244
3937
  }, []);
@@ -4351,6 +4044,8 @@ function GraphCanvas(props) {
4351
4044
  ringRafRef.current = null;
4352
4045
  if (cy.destroyed()) return;
4353
4046
  drawLabels(cy);
4047
+ const mirror = mirrorRef.current;
4048
+ if (mirror && !mirror.destroyed()) drawLabels(mirror);
4354
4049
  const now = performance.now();
4355
4050
  if ([...ringsRef.current.values()].some((t0) => now - t0 < RING_IN_MS)) ringRafRef.current = requestAnimationFrame(step);
4356
4051
  };
@@ -4459,10 +4154,10 @@ function GraphCanvas(props) {
4459
4154
  if (cyRef.current === cy && !cy.destroyed()) scheduleReadability(cy);
4460
4155
  }, LABEL_SETTLE_MS);
4461
4156
  }, [scheduleReadability]);
4462
- const applyHover = useCallback2((cy, target, fade = true) => {
4157
+ const applyHover = useCallback2((cy, target2, fade = true) => {
4463
4158
  const painter = painterRef.current;
4464
4159
  if (cy.destroyed() || !painter) return;
4465
- painter.hover(diffRef.current ? null : target, !fade);
4160
+ painter.hover(diffRef.current ? null : target2, !fade);
4466
4161
  if (readableRef.current && !diffRef.current && !labelsFrozen()) replanLabels(cy);
4467
4162
  }, [labelsFrozen, replanLabels]);
4468
4163
  const emphasisKey = JSON.stringify(emphasis ?? null);
@@ -4472,50 +4167,40 @@ function GraphCanvas(props) {
4472
4167
  respot();
4473
4168
  if (readableRef.current && !labelsFrozen()) replanLabels(cy);
4474
4169
  }, [emphasisKey, respot, labelsFrozen, replanLabels]);
4475
- const setHover = useCallback2((cy, target) => {
4476
- if (hoverOutRef.current != null) {
4477
- clearTimeout(hoverOutRef.current);
4478
- hoverOutRef.current = null;
4479
- }
4480
- if (labelsFrozen()) {
4481
- applyHover(cy, null, false);
4482
- return;
4483
- }
4484
- if (target) {
4485
- if (painterRef.current?.hoveredId() != null) {
4486
- applyHover(cy, target);
4487
- return;
4488
- }
4489
- hoverOutRef.current = setTimeout(() => {
4490
- hoverOutRef.current = null;
4491
- applyHover(cy, target);
4492
- }, HOVER_IN_MS);
4493
- return;
4494
- }
4495
- hoverOutRef.current = setTimeout(() => {
4496
- hoverOutRef.current = null;
4497
- applyHover(cy, null);
4498
- }, HOVER_OUT_MS);
4499
- }, [labelsFrozen, applyHover]);
4500
- const previewTouch = useCallback2((cy, target) => {
4501
- if (hoverOutRef.current != null) {
4502
- clearTimeout(hoverOutRef.current);
4503
- hoverOutRef.current = null;
4504
- }
4505
- if (labelsFrozen()) target = null;
4506
- cy.batch(() => {
4507
- cy.$(".gb-preview, .gb-preview-hop").removeClass("gb-preview gb-preview-hop");
4508
- if (diffRef.current || !readableRef.current) {
4509
- target?.addClass("gb-preview");
4510
- if (target) (target.isNode() ? target.closedNeighborhood() : target.connectedNodes()).addClass("gb-preview-hop");
4170
+ const cancelHoverTimer = useCallback2(() => {
4171
+ if (hoverTimerRef.current != null) clearTimeout(hoverTimerRef.current);
4172
+ hoverTimerRef.current = null;
4173
+ }, []);
4174
+ const highlight = useCallback2((cy, target2, touch) => {
4175
+ cancelHoverTimer();
4176
+ const apply = () => {
4177
+ hoverTimerRef.current = null;
4178
+ if (cy.destroyed()) return;
4179
+ const frozen = labelsFrozen();
4180
+ const hit = frozen ? null : target2;
4181
+ const layer = typeof hit === "string" && plateAlphaRef.current > 0.01 && platesRef.current.some((p) => p.layer === hit) ? hit : null;
4182
+ spotlightLayer(layer);
4183
+ const element = hit && typeof hit !== "string" && !hit.removed() ? hit : null;
4184
+ if (touch) {
4185
+ cy.batch(() => {
4186
+ cy.$(".gb-preview, .gb-preview-hop").removeClass("gb-preview gb-preview-hop");
4187
+ if (element && (diffRef.current || !readableRef.current)) {
4188
+ element.addClass("gb-preview");
4189
+ (element.isNode() ? element.closedNeighborhood() : element.connectedNodes()).addClass("gb-preview-hop");
4190
+ }
4191
+ });
4192
+ if (diffRef.current || !readableRef.current) {
4193
+ replanLabels(cy);
4194
+ drawLabels(cy);
4195
+ return;
4196
+ }
4511
4197
  }
4512
- });
4513
- if (!diffRef.current && readableRef.current) applyHover(cy, target);
4514
- else {
4515
- replanLabels(cy);
4516
- drawLabels(cy);
4517
- }
4518
- }, [labelsFrozen, applyHover, replanLabels, drawLabels]);
4198
+ applyHover(cy, element, !frozen);
4199
+ };
4200
+ const focused = hotLayerRef.current != null || painterRef.current?.hoveredId() != null;
4201
+ if (touch || labelsFrozen() || target2 != null && focused) apply();
4202
+ else hoverTimerRef.current = setTimeout(apply, target2 == null ? HOVER_OUT_MS : HOVER_IN_MS);
4203
+ }, [cancelHoverTimer, labelsFrozen, spotlightLayer, applyHover, replanLabels, drawLabels]);
4519
4204
  const armBreath = useCallback2((cy) => {
4520
4205
  if (!readableRef.current || breathTimerRef.current != null) return;
4521
4206
  const tick = () => {
@@ -4613,30 +4298,28 @@ function GraphCanvas(props) {
4613
4298
  if (!busyRef.current) setPastGeom(measureDiffGeom(m, leftPastRef.current));
4614
4299
  }, []);
4615
4300
  const selectEle = useCallback2((el) => {
4616
- if (!el || el.empty?.()) return;
4617
- const d = el.data();
4618
- if (d.id === VIRTUAL_ROOT) return;
4619
- setSelected({
4620
- id: d.id,
4621
- label: d.label,
4622
- kind: d.kind,
4623
- layer: d.layer,
4624
- origin: d.origin,
4625
- container: builtRef.current.containers.has(d.id),
4626
- flags: el.classes().filter((c) => !["gb-node", "flat", "container", "gb-hit", "gb-preview", "gb-preview-hop", d.kind].includes(c)),
4627
- detail: d.detail ?? null,
4628
- parent: modelRef.current.index.get(d.id)?.parent,
4629
- order: modelRef.current.index.get(d.id)?.order
4301
+ if (!el || el.empty?.() || el.id() === VIRTUAL_ROOT) {
4302
+ setTrail([]);
4303
+ return;
4304
+ }
4305
+ const past = el.cy() === mirrorRef.current;
4306
+ if (el.isNode()) setTrail([{ node: el.id(), past }]);
4307
+ else if (!el.hasClass("contains")) setTrail([{ edge: { source: el.data("source"), target: el.data("target"), kind: el.data("kind") }, past }]);
4308
+ }, []);
4309
+ const syncSelection = useCallback2((cy, item) => {
4310
+ if (!cy || cy.destroyed()) return;
4311
+ const match = item && ("node" in item ? cy.$id(item.node) : cy.edges().filter((e) => !e.hasClass("contains") && sameEdge(e.data(), item.edge)));
4312
+ cy.batch(() => {
4313
+ cy.$(":selected").difference(match || cy.collection()).unselect();
4314
+ if (match?.length && match.visible()) match.select();
4630
4315
  });
4631
4316
  }, []);
4632
- const selectTouch = useCallback2((target) => {
4633
- for (const cy of [cyRef.current, mirrorRef.current]) {
4634
- if (cy && !cy.destroyed()) cy.$(":selected").unselect();
4635
- }
4636
- target?.select();
4637
- if (target) selectEle(target);
4638
- else setSelected(null);
4639
- }, [selectEle]);
4317
+ const targetRef = useRef4(target);
4318
+ targetRef.current = target;
4319
+ useEffect4(() => {
4320
+ syncSelection(cyRef.current, target);
4321
+ syncSelection(mirrorRef.current, target);
4322
+ }, [target, liveCy, syncSelection]);
4640
4323
  const cancelFrames = useCallback2(() => {
4641
4324
  const tw = tweenRef.current;
4642
4325
  if (tw) {
@@ -4685,12 +4368,12 @@ function GraphCanvas(props) {
4685
4368
  });
4686
4369
  if (settle && diffRef.current) setDiffGeom(measureDiffGeom(cy, leftRef.current));
4687
4370
  }, []);
4688
- const settleTo = useCallback2((cy, target, after) => {
4689
- dispRef.current = { ...target };
4690
- applyPositions(cy, target, true);
4371
+ const settleTo = useCallback2((cy, target2, after) => {
4372
+ dispRef.current = { ...target2 };
4373
+ applyPositions(cy, target2, true);
4691
4374
  after?.();
4692
4375
  }, [applyPositions]);
4693
- const playTransition = useCallback2((cy, union, after) => {
4376
+ const playTransition = useCallback2((cy, union, after, returnView) => {
4694
4377
  const spec = resolveSpec(animateRef.current);
4695
4378
  const delta = pendingRef.current;
4696
4379
  const pastDelta = pendingPastRef.current;
@@ -4729,10 +4412,12 @@ function GraphCanvas(props) {
4729
4412
  // or exits: the marks on the union are left over, and planning by them would replay the previous batch.
4730
4413
  presence: delta ? presenceOf(cy, marksRef.current) : void 0
4731
4414
  };
4415
+ const framing = [cy.width(), cy.height(), !!diffRef.current, planeKey(viewRef.current)].join("|");
4416
+ const sameFraming = framingRef.current === framing;
4417
+ framingRef.current = framing;
4732
4418
  const tooBig = !!spec && Object.keys(union).length > spec.maxNodes;
4733
- const filtering2 = isNarrowing(viewRef.current);
4734
4419
  const hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
4735
- if (!spec || tooBig || filtering2 || hidden) {
4420
+ if (!spec || tooBig || hidden) {
4736
4421
  onTransitionRef.current?.({
4737
4422
  ...planTransition(delta, dispRef.current, union, planOpts).report,
4738
4423
  layoutMs: layoutMsRef.current,
@@ -4741,7 +4426,10 @@ function GraphCanvas(props) {
4741
4426
  collectLeft();
4742
4427
  armed.disarm();
4743
4428
  disarmMirror();
4744
- settleTo(cy, union, () => after?.(false));
4429
+ settleTo(cy, union, () => {
4430
+ if (returnView) cy.viewport(returnView);
4431
+ after(!!returnView);
4432
+ });
4745
4433
  forgetLeft();
4746
4434
  return;
4747
4435
  }
@@ -4750,12 +4438,14 @@ function GraphCanvas(props) {
4750
4438
  setPastGeom(EMPTY_GEOM);
4751
4439
  };
4752
4440
  const t = planTransition(delta, dispRef.current, union, planOpts);
4753
- onTransitionRef.current?.({ ...t.report, layoutMs: layoutMsRef.current, animated: t.worth });
4754
- if (!t.worth) {
4441
+ const movingCamera = returnView && (Math.abs(returnView.zoom - cy.zoom()) > 1e-6 || Math.hypot(returnView.pan.x - cy.pan().x, returnView.pan.y - cy.pan().y) > 0.5);
4442
+ const animated = t.worth || !!movingCamera;
4443
+ onTransitionRef.current?.({ ...t.report, layoutMs: layoutMsRef.current, animated });
4444
+ if (!animated) {
4755
4445
  collectLeft();
4756
4446
  armed.disarm();
4757
4447
  disarmMirror();
4758
- settleTo(cy, union, () => after?.(false));
4448
+ settleTo(cy, union, () => after(sameFraming || !!returnView));
4759
4449
  forgetLeft();
4760
4450
  return;
4761
4451
  }
@@ -4768,10 +4458,13 @@ function GraphCanvas(props) {
4768
4458
  fitAll(cy);
4769
4459
  const vU = cam();
4770
4460
  leftRef.current = /* @__PURE__ */ new Set([...leftBefore, ...t.leaving]);
4771
- fitAll(cy);
4772
- const v1 = cam();
4461
+ if (!returnView) fitAll(cy);
4462
+ const v1 = returnView ?? cam();
4773
4463
  leftRef.current = leftBefore;
4774
- applyPositions(cy, sampleTransition(t, 0).pos, false);
4464
+ const startPositions = sampleTransition(t, 0).pos;
4465
+ applyPositions(cy, startPositions, false);
4466
+ const mirror = mirrorNow();
4467
+ if (mirror) applyPositions(mirror.m, startPositions, false);
4775
4468
  cy.viewport(v0);
4776
4469
  const W = cy.width() || 1, H = cy.height() || 1;
4777
4470
  const r0 = toRect(v0, W, H), r12 = toRect(v1, W, H);
@@ -4792,12 +4485,12 @@ function GraphCanvas(props) {
4792
4485
  disarmMirror();
4793
4486
  const settled = { ...union };
4794
4487
  for (const id of t.leaving) {
4795
- const q2 = dispRef.current[id];
4796
- if (q2) settled[id] = q2;
4488
+ const q = dispRef.current[id];
4489
+ if (q) settled[id] = q;
4797
4490
  }
4798
4491
  settleTo(cy, settled, () => {
4799
4492
  cy.viewport(v1);
4800
- after?.(true);
4493
+ after(true);
4801
4494
  });
4802
4495
  forgetLeft();
4803
4496
  };
@@ -4816,10 +4509,10 @@ function GraphCanvas(props) {
4816
4509
  Object.assign(dispRef.current, pos);
4817
4510
  cy.batch(() => {
4818
4511
  leaves.forEach((n) => {
4819
- const q2 = pos[n.id()];
4820
- if (q2) n.position(q2);
4512
+ const q = pos[n.id()];
4513
+ if (q) n.position(q);
4821
4514
  });
4822
- for (const n of FADE_NAMES) groups[n].style("opacity", clamp012(fade[n]));
4515
+ for (const n of FADE_NAMES) groups[n].style("opacity", clamp01(fade[n]));
4823
4516
  for (const g of skinGroups) g.eles.style(sampleSkinStyle(g.tween, fade.in));
4824
4517
  if (!present && fade.in > 0) {
4825
4518
  present = true;
@@ -4830,10 +4523,10 @@ function GraphCanvas(props) {
4830
4523
  if (mir) {
4831
4524
  mir.m.batch(() => {
4832
4525
  mir.leaves.forEach((n) => {
4833
- const q2 = pos[n.id()];
4834
- if (q2) n.position(q2);
4526
+ const q = pos[n.id()];
4527
+ if (q) n.position(q);
4835
4528
  });
4836
- if (mir.armed) for (const n of FADE_NAMES) mir.armed.groups[n].style("opacity", clamp012(fade[n]));
4529
+ if (mir.armed) for (const n of FADE_NAMES) mir.armed.groups[n].style("opacity", clamp01(fade[n]));
4837
4530
  });
4838
4531
  }
4839
4532
  cy.viewport(toView({
@@ -4873,7 +4566,10 @@ function GraphCanvas(props) {
4873
4566
  const dims = {};
4874
4567
  cy.nodes(":childless").forEach((n) => {
4875
4568
  const d = n.layoutDimensions({ nodeDimensionsIncludeLabels: true });
4876
- dims[n.id()] = { w: Math.round(d.w * 64) / 64, h: Math.round(d.h * 64) / 64 };
4569
+ const size = { w: Math.round(d.w * 64) / 64, h: Math.round(d.h * 64) / 64 };
4570
+ dims[n.id()] = size;
4571
+ const old = dimsRef.current[n.id()];
4572
+ if (!old || old.w !== size.w || old.h !== size.h) framingRef.current = "";
4877
4573
  });
4878
4574
  dimsRef.current = dims;
4879
4575
  if (scaled) cy.style(sheetFor(false));
@@ -4972,20 +4668,44 @@ function GraphCanvas(props) {
4972
4668
  layerOfRef.current = layerOf;
4973
4669
  const t = viewRef.current.planes ? 1 : 0;
4974
4670
  const placed = projectAt(positions, t);
4671
+ const previous = dispRef.current;
4672
+ const before = /* @__PURE__ */ Object.create(null), after = /* @__PURE__ */ Object.create(null);
4673
+ for (const id of visibleFrameRef.current) if (previous[id]) before[id] = previous[id];
4674
+ const target2 = diffSidesRef.current?.after ?? model;
4675
+ for (const id of frameIds(visibleNodes(cy))) {
4676
+ if (target2.index.has(id) && placed.positions[id]) after[id] = placed.positions[id];
4677
+ }
4678
+ const shift = frameTranslation(before, after);
4679
+ if (shift.x || shift.y) {
4680
+ for (const [id, p] of Object.entries(previous)) previous[id] = { x: p.x + shift.x, y: p.y + shift.y };
4681
+ cy.panBy({ x: -shift.x * cy.zoom(), y: -shift.y * cy.zoom() });
4682
+ }
4975
4683
  for (const id of stay) placed.positions[id] = dispRef.current[id];
4976
4684
  planeTRef.current = t;
4977
4685
  planeKeyRef.current = planeKey(viewRef.current);
4978
4686
  layerAlphaRef.current = /* @__PURE__ */ new Map();
4979
4687
  baseRef.current = placed.positions;
4980
- tightenedRef.current = false;
4981
4688
  showPlates(litPlates(placed.plates, shownIn(viewRef.current)), t);
4982
4689
  setProg(null);
4690
+ const bookmark = !scope.active && props.restoreCamera.current;
4691
+ const anchor = bookmark && after[bookmark.id];
4692
+ const returnView = anchor && bookmark ? { zoom: bookmark.zoom, pan: {
4693
+ x: cy.width() / 2 + bookmark.dx - anchor.x * bookmark.zoom,
4694
+ y: cy.height() / 2 + bookmark.dy - anchor.y * bookmark.zoom
4695
+ } } : null;
4696
+ if (bookmark) props.restoreCamera.current = null;
4983
4697
  playTransition(cy, placed.positions, (cameraPlaced) => {
4984
4698
  markBusy(false);
4985
4699
  if (missedRef.current) setResume((v) => v + 1);
4986
4700
  if (cyRef.current !== cy) return;
4987
4701
  applyView({ fit: !cameraPlaced });
4988
- sightRef.current = sightKey(viewRef.current);
4702
+ const destination = props.destination.current;
4703
+ if (destination && !scope.active) {
4704
+ props.destination.current = null;
4705
+ setTrail([destination]);
4706
+ if ("node" in destination) flyToRef.current(destination.node, false, true);
4707
+ }
4708
+ sightRef.current = planeKey(viewRef.current);
4989
4709
  if (plateAlphaRef.current > 0 || diffRef.current) setViewport({ zoom: cy.zoom(), pan: { ...cy.pan() } });
4990
4710
  syncMirror();
4991
4711
  if (!missedRef.current && owedLayoutRef.current) {
@@ -4999,7 +4719,7 @@ function GraphCanvas(props) {
4999
4719
  pendingPickRef.current = null;
5000
4720
  pickRef.current(want);
5001
4721
  }
5002
- });
4722
+ }, returnView);
5003
4723
  } catch (err) {
5004
4724
  pendingRef.current = null;
5005
4725
  markBusy(false);
@@ -5008,7 +4728,7 @@ function GraphCanvas(props) {
5008
4728
  } finally {
5009
4729
  if (runRef.current === run) setProg(null);
5010
4730
  }
5011
- }, [built, pool, profile, applyView, playTransition, markBusy, sheetFor, scheduleReadability, projectAt, showPlates]);
4731
+ }, [built, pool, profile, model, scope.active, applyView, playTransition, markBusy, sheetFor, scheduleReadability, projectAt, showPlates, frameIds, visibleNodes]);
5012
4732
  const playPlanes = useCallback2((cy) => {
5013
4733
  if (planeTweenRef.current != null) {
5014
4734
  cancelAnimationFrame(planeTweenRef.current);
@@ -5018,7 +4738,7 @@ function GraphCanvas(props) {
5018
4738
  const v = viewRef.current;
5019
4739
  const prevKey = planeKeyRef.current;
5020
4740
  planeKeyRef.current = planeKey(v);
5021
- sightRef.current = sightKey(v);
4741
+ sightRef.current = planeKey(v);
5022
4742
  const raw = rawRef.current;
5023
4743
  const t0 = planeTRef.current, t1 = v.planes ? 1 : 0;
5024
4744
  const end = projectAt(raw, t1);
@@ -5067,8 +4787,8 @@ ${lt}`;
5067
4787
  };
5068
4788
  const place = (pos) => {
5069
4789
  for (const g of groups) g.inst.batch(() => g.leaves.forEach((n) => {
5070
- const q2 = pos[n.id()];
5071
- if (q2) n.position(q2);
4790
+ const q = pos[n.id()];
4791
+ if (q) n.position(q);
5072
4792
  }));
5073
4793
  Object.assign(dispRef.current, pos);
5074
4794
  };
@@ -5090,7 +4810,7 @@ ${lt}`;
5090
4810
  };
5091
4811
  const spec = resolveSpec(animateRef.current);
5092
4812
  const hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
5093
- if (!spec || hidden || isNarrowing(v) || !Object.keys(raw).length) {
4813
+ if (!spec || hidden || !Object.keys(raw).length) {
5094
4814
  finish();
5095
4815
  applyView();
5096
4816
  syncMirror();
@@ -5102,16 +4822,16 @@ ${lt}`;
5102
4822
  const from = { ...dispRef.current };
5103
4823
  const platesBefore = platesRef.current;
5104
4824
  cy.batch(() => groups[0].leaves.forEach((n) => {
5105
- const q2 = end.positions[n.id()];
5106
- if (q2) n.position(q2);
4825
+ const q = end.positions[n.id()];
4826
+ if (q) n.position(q);
5107
4827
  }));
5108
4828
  platesRef.current = endPlates;
5109
4829
  fitAll(cy);
5110
4830
  const v1 = { zoom: cy.zoom(), pan: { ...cy.pan() } };
5111
4831
  platesRef.current = platesBefore;
5112
4832
  cy.batch(() => groups[0].leaves.forEach((n) => {
5113
- const q2 = from[n.id()];
5114
- if (q2) n.position(q2);
4833
+ const q = from[n.id()];
4834
+ if (q) n.position(q);
5115
4835
  }));
5116
4836
  cy.viewport(v0);
5117
4837
  const r0 = toRect(v0, W, H), r12 = toRect(v1, W, H);
@@ -5143,11 +4863,12 @@ ${lt}`;
5143
4863
  planeTweenRef.current = requestAnimationFrame(frame);
5144
4864
  }, [projectAt, showPlates, fitAll, applyView, syncMirror, scheduleReadability, cancelFly]);
5145
4865
  playPlanesRef.current = playPlanes;
5146
- const flyTo = useCallback2((id, around2 = false) => {
4866
+ const flyTo = useCallback2((id, around2 = false, allowPast = false) => {
5147
4867
  const cy = cyRef.current;
5148
4868
  if (!cy || cy.destroyed() || busyRef.current || planeTweenRef.current != null) return;
5149
- const n = cy.$id(id);
5150
- if (n.empty() || !n.visible()) return;
4869
+ const now = cy.$id(id);
4870
+ const n = allowPast && (!now.length || !now.visible()) ? mirrorRef.current?.$id(id) : now;
4871
+ if (!n || n.empty() || !n.visible()) return;
5151
4872
  cancelFly();
5152
4873
  const W = cy.width() || 1, H = cy.height() || 1;
5153
4874
  const p = n.position();
@@ -5171,10 +4892,10 @@ ${lt}`;
5171
4892
  const path = zoomPath(a, b);
5172
4893
  const dur = Math.min(FLY_MS.max, Math.max(FLY_MS.min, path.S * FLY_MS_PER_S));
5173
4894
  const start = performance.now();
5174
- const frame = (now) => {
4895
+ const frame = (now2) => {
5175
4896
  flyRef.current = null;
5176
4897
  if (cyRef.current !== cy || cy.destroyed()) return;
5177
- const k = Math.min(1, (now - start) / dur);
4898
+ const k = Math.min(1, (now2 - start) / dur);
5178
4899
  cy.viewport(toView(path.at(easeInOut(k)), cy.width() || W, cy.height() || H));
5179
4900
  if (k < 1) flyRef.current = requestAnimationFrame(frame);
5180
4901
  };
@@ -5189,14 +4910,8 @@ ${lt}`;
5189
4910
  let detach = null;
5190
4911
  let cancelled = false;
5191
4912
  (async () => {
5192
- const [{ default: cytoscape }, { default: fcose }, { default: coseBilkent }] = await Promise.all([
5193
- import("cytoscape"),
5194
- import("cytoscape-fcose"),
5195
- import("cytoscape-cose-bilkent")
5196
- ]);
4913
+ const { default: cytoscape } = await import("cytoscape");
5197
4914
  if (cancelled || !containerRef.current) return;
5198
- cytoscape.use(fcose);
5199
- cytoscape.use(coseBilkent);
5200
4915
  cy = cytoscape({
5201
4916
  container: containerRef.current,
5202
4917
  elements: built.elements,
@@ -5209,8 +4924,9 @@ ${lt}`;
5209
4924
  maxZoom: 4
5210
4925
  });
5211
4926
  const prevView = prevViewportRef.current;
4927
+ const restoringCamera = !scope.active && !!props.restoreCamera.current;
5212
4928
  if (prevView) cy.viewport(prevView);
5213
- seatFromLastFrame(cy, dispRef.current, (q2) => built.parentOf.get(q2));
4929
+ seatFromLastFrame(cy, dispRef.current, (q) => built.parentOf.get(q));
5214
4930
  armedRef.current = null;
5215
4931
  if (pendingRef.current && resolveSpec(animateRef.current)) armTransition(cy);
5216
4932
  painterRef.current = installPainter(cy, {
@@ -5236,7 +4952,7 @@ ${lt}`;
5236
4952
  const pan = cy.pan();
5237
4953
  cy.resize();
5238
4954
  if (first) {
5239
- fitAll(cy);
4955
+ if (!prevView && !restoringCamera && !busyRef.current) fitAll(cy);
5240
4956
  return;
5241
4957
  }
5242
4958
  const sel = cy.nodes(":selected").filter((n) => n.visible());
@@ -5260,10 +4976,9 @@ ${lt}`;
5260
4976
  detach = installGraphInput(cy, containerRef.current, {
5261
4977
  interact: touchInteraction,
5262
4978
  cancelFly,
5263
- selectTouch,
5264
- select: (target) => target ? selectEle(target) : setSelected(null),
5265
- hover: (target) => setHover(cy, target),
5266
- preview: (target) => previewTouch(cy, target),
4979
+ select: selectEle,
4980
+ hover: (target2) => highlight(cy, target2, false),
4981
+ preview: (target2) => highlight(cy, target2, true),
5267
4982
  // The first click opens the inspector: let its new width settle before framing.
5268
4983
  focus: (id) => requestAnimationFrame(() => requestAnimationFrame(() => {
5269
4984
  if (!cy.destroyed()) flyToRef.current(id, true);
@@ -5282,9 +4997,9 @@ ${lt}`;
5282
4997
  });
5283
4998
  cyRef.current = cy;
5284
4999
  const keep = keepSelRef.current;
5285
- keepSelRef.current = null;
5286
- if (keep && cy.$id(keep).nonempty()) cy.$id(keep).select();
5287
- else setSelected(null);
5000
+ keepSelRef.current = void 0;
5001
+ if (keep) syncSelection(cy, keep);
5002
+ else setTrail([]);
5288
5003
  setLiveCy(cy);
5289
5004
  onReady?.(cy);
5290
5005
  markBusy(true);
@@ -5307,10 +5022,7 @@ ${lt}`;
5307
5022
  clearTimeout(breathTimerRef.current);
5308
5023
  breathTimerRef.current = null;
5309
5024
  }
5310
- if (hoverOutRef.current != null) {
5311
- clearTimeout(hoverOutRef.current);
5312
- hoverOutRef.current = null;
5313
- }
5025
+ cancelHoverTimer();
5314
5026
  if (planeTweenRef.current != null) {
5315
5027
  cancelAnimationFrame(planeTweenRef.current);
5316
5028
  planeTweenRef.current = null;
@@ -5322,6 +5034,7 @@ ${lt}`;
5322
5034
  detach?.();
5323
5035
  cy?.destroy();
5324
5036
  cyRef.current = null;
5037
+ spotlightLayer(null);
5325
5038
  };
5326
5039
  }, [built, profile, !!diff]);
5327
5040
  useEffect4(() => {
@@ -5342,15 +5055,15 @@ ${lt}`;
5342
5055
  minZoom: 0.02,
5343
5056
  maxZoom: 4
5344
5057
  });
5345
- seatFromLastFrame(m, dispRef.current, (q2) => pastBuilt.parentOf.get(q2));
5058
+ seatFromLastFrame(m, dispRef.current, (q) => pastBuilt.parentOf.get(q));
5346
5059
  mirrorRef.current = m;
5060
+ syncSelection(m, targetRef.current);
5347
5061
  m.$id(VIRTUAL_ROOT).unselectify();
5348
5062
  detach = installGraphInput(m, mirrorElRef.current, {
5349
5063
  interact: touchInteraction,
5350
5064
  cancelFly,
5351
- selectTouch,
5352
- select: (target) => target ? selectEle(target) : setSelected(null),
5353
- preview: (target) => previewTouch(m, target)
5065
+ select: selectEle,
5066
+ preview: (target2) => highlight(m, target2, true)
5354
5067
  });
5355
5068
  m.on("viewport", () => {
5356
5069
  const cy2 = cyRef.current;
@@ -5392,7 +5105,7 @@ ${lt}`;
5392
5105
  if (!busyRef.current) playPlanes(cy);
5393
5106
  return;
5394
5107
  }
5395
- const sight = sightKey(view);
5108
+ const sight = planeKey(view);
5396
5109
  applyView({ fit: sight !== sightRef.current });
5397
5110
  sightRef.current = sight;
5398
5111
  if (cy && !cy.destroyed()) scheduleReadability(cy);
@@ -5483,32 +5196,31 @@ ${lt}`;
5483
5196
  const query = view.query?.trim() ?? "";
5484
5197
  const search = useMemo5(() => {
5485
5198
  if (!query) return null;
5486
- const idx = indexModel(renderModel);
5487
- const left = leftRef.current;
5488
- const hits = [...resolved.hits].filter((id) => !left.has(id));
5199
+ const idx = indexModel(model);
5200
+ const hits = [...resolved.hits].filter((id) => model.index.has(id));
5489
5201
  const results = hits.slice(0, SEARCH_LIST).map((id) => {
5490
- const n = renderModel.index.get(id);
5491
- const path = idx.ancestorsOf(id).slice(0, 2).reverse().map((a) => renderModel.index.get(a)?.label).filter((x) => !!x);
5202
+ const n = model.index.get(id);
5203
+ const path = idx.ancestorsOf(id).slice(0, 2).reverse().map((a) => model.index.get(a)?.label).filter((x) => !!x);
5492
5204
  return { id, label: n.label, path, kind: n.kind ? profile.kindLabels[n.kind] ?? n.kind : void 0 };
5493
5205
  });
5494
5206
  const elsewhere = [];
5495
5207
  if (layersHere.length > 1 && view.layers) {
5496
5208
  const here = new Set(view.layers ?? []);
5497
5209
  const count = /* @__PURE__ */ new Map();
5498
- for (const id of searchNodes(renderModel, query)) {
5499
- if (left.has(id)) continue;
5500
- const l = renderModel.index.get(id)?.layer ?? profile.layers[0].id;
5210
+ for (const id of searchNodes(model, query)) {
5211
+ const l = model.index.get(id)?.layer ?? profile.layers[0].id;
5501
5212
  if (!here.has(l)) count.set(l, (count.get(l) ?? 0) + 1);
5502
5213
  }
5503
5214
  for (const l of layersHere) if (count.get(l.id)) elsewhere.push({ layer: l.id, label: l.label, count: count.get(l.id) });
5504
5215
  }
5505
5216
  return { results, total: hits.length, elsewhere };
5506
- }, [query, resolved, renderModel, profile, layersHere, view.planes, view.layers]);
5507
- const colorOf = useCallback2((id) => {
5508
- const cy = cyRef.current;
5509
- if (!cy || cy.destroyed()) return void 0;
5510
- const n = cy.$id(id);
5511
- return n.nonempty() ? n.style("background-color") : void 0;
5217
+ }, [query, resolved, model, profile, layersHere, view.planes, view.layers]);
5218
+ const colorOf = useCallback2((id, past = false) => {
5219
+ for (const cy of past ? [mirrorRef.current, cyRef.current] : [cyRef.current, mirrorRef.current]) {
5220
+ if (!cy || cy.destroyed()) continue;
5221
+ const n = cy.$id(id);
5222
+ if (n.nonempty()) return n.style("background-color");
5223
+ }
5512
5224
  }, []);
5513
5225
  const preview = useCallback2((id) => {
5514
5226
  const cy = cyRef.current;
@@ -5517,63 +5229,58 @@ ${lt}`;
5517
5229
  applyHover(cy, n && n.nonempty() ? n : null);
5518
5230
  if (id) flyTo(id);
5519
5231
  }, [applyHover, flyTo]);
5520
- const hoverLayer = useCallback2((layer) => {
5521
- hotLayerRef.current = layer;
5522
- setHotLayer(layer);
5523
- const cy = cyRef.current;
5524
- if (!cy || cy.destroyed() || diffRef.current) return;
5525
- respot();
5526
- if (readableRef.current && !labelsFrozen()) replanLabels(cy);
5527
- }, [respot, labelsFrozen, replanLabels]);
5528
5232
  const pick = useCallback2((id) => {
5529
5233
  const cy = cyRef.current;
5530
5234
  if (!cy || cy.destroyed()) return;
5531
5235
  const n = cy.$id(id);
5532
5236
  if (n.empty()) return;
5533
5237
  applyHover(cy, null);
5534
- cy.$(":selected").unselect();
5535
- n.select();
5536
5238
  selectEle(n);
5537
5239
  flyTo(id);
5538
5240
  setView({ query: "" });
5539
5241
  }, [applyHover, flyTo, selectEle, setView]);
5540
5242
  pickRef.current = pick;
5243
+ const navigate = useCallback2((next, back = false) => {
5244
+ if (scope.active && !hasTarget(next.past && diffSides ? diffSides.before : scope.local, next)) {
5245
+ scope.leaveFor(next);
5246
+ return;
5247
+ }
5248
+ setTrail((path) => back ? path.slice(0, -1) : [...path, next]);
5249
+ if ("node" in next) flyTo(next.node, false, true);
5250
+ }, [flyTo, scope, diffSides]);
5541
5251
  useEffect4(() => {
5542
- if (diff) return;
5543
- setSelected((s) => {
5544
- const n = s && model.index.get(s.id);
5545
- if (!s || !n) return null;
5546
- return {
5547
- ...s,
5548
- parent: n.parent,
5549
- order: n.order,
5550
- label: n.label,
5551
- kind: n.kind ?? "",
5552
- layer: n.layer,
5553
- detail: n.data ?? null,
5554
- flags: n.flags ?? [],
5555
- container: model.nodes.some((x) => x.parent === n.id)
5556
- };
5557
- });
5558
- setEditing((e) => e?.what === "node" && e.id && !model.index.has(e.id) ? null : e);
5559
- }, [model]);
5252
+ setEditing((e) => e?.what === "node" && e.id && !editingModel.index.has(e.id) ? null : e);
5253
+ }, [editingModel]);
5560
5254
  useEffect4(() => {
5561
5255
  if (!editable) setEditing(null);
5562
5256
  }, [editable]);
5563
5257
  const submitEdit = useCallback2((input) => {
5564
- const only = view.origins?.length === 1 ? view.origins[0] : void 0;
5565
- const op = input.op === "addNode" && only && !input.origin ? { ...input, origin: only } : input;
5258
+ const only = scope.origins?.length === 1 ? scope.origins[0] : void 0;
5259
+ const op = (input.op === "addNode" || input.op === "addEdge") && only && !input.origin ? { ...input, origin: only } : input;
5566
5260
  const err = checkEdit(editingModel, op) ?? props.validateEdit?.(op);
5567
5261
  if (err) return err;
5568
- if (op.op === "addNode") pendingPickRef.current = op.id;
5569
- else if (op.op === "removeNode") setSelected(null);
5570
- else keepSelRef.current = selected?.id ?? null;
5262
+ let path = trail;
5263
+ if (op.op === "addNode" && !(editing?.what === "node" && editing.id)) {
5264
+ pendingPickRef.current = op.id;
5265
+ path = [];
5266
+ } else if (op.op === "removeNode") {
5267
+ path = [];
5268
+ } else if (op.op === "updateEdge" || op.op === "removeEdge") {
5269
+ path = trail.flatMap((item) => {
5270
+ if (!("edge" in item) || !sameEdge(item.edge, op.edge)) return [item];
5271
+ if (op.op === "removeEdge") return [];
5272
+ const { source, target: target2, kind } = { ...op.edge, ...op.set };
5273
+ return [{ ...item, edge: { source, target: target2, kind } }];
5274
+ });
5275
+ }
5276
+ keepSelRef.current = path.at(-1);
5277
+ if (path !== trail) setTrail(path);
5571
5278
  onEditRef.current?.(op);
5572
5279
  return null;
5573
- }, [editingModel, selected, view.origins, props.validateEdit]);
5280
+ }, [editing, editingModel, trail, scope.origins, props.validateEdit]);
5574
5281
  const startAdd = useCallback2((what) => {
5575
- setEditing(what === "node" ? { what, parent: selected?.id ?? null } : { what, source: selected?.id });
5576
- }, [selected]);
5282
+ setEditing(what === "node" ? { what, parent: selected?.id ?? scope.subtree ?? null } : { what, source: selected?.id });
5283
+ }, [selected, scope.subtree]);
5577
5284
  const editPanel = editing && /* @__PURE__ */ jsx5(
5578
5285
  EditPanel,
5579
5286
  {
@@ -5583,9 +5290,56 @@ ${lt}`;
5583
5290
  renderEditor,
5584
5291
  colorOf,
5585
5292
  onCancel: () => setEditing(null),
5586
- onRetarget: setEditing
5293
+ kindLabels: profile.kindLabels
5587
5294
  }
5588
5295
  );
5296
+ const details = useMemo5(() => detailPanel && (currentSubject || oldSubject) ? /* @__PURE__ */ jsx5(
5297
+ ObjectDetails,
5298
+ {
5299
+ before: oldSubject,
5300
+ after: currentSubject,
5301
+ delta: diff,
5302
+ nodeClass: profile.nodeClass,
5303
+ spec: profile.detail,
5304
+ kindLabels: profile.kindLabels,
5305
+ onClose: () => setTrail([]),
5306
+ onBack: trail.length > 1 ? () => navigate(trail[trail.length - 2], true) : void 0,
5307
+ scope: compact ? void 0 : scope,
5308
+ membership: scope.active && target && "node" in target && diff ? !currentSubject && scope.after.index.has(target.node) ? strings.leftScope : !oldSubject && fullPast?.index.has(target.node) ? strings.enteredScope : void 0 : void 0,
5309
+ onPick: navigate,
5310
+ renderText,
5311
+ colorOf,
5312
+ onEdit: editable && currentSubject && target ? () => setEditing("node" in target ? { what: "node", id: target.node } : { what: "edge", edge: target.edge }) : void 0,
5313
+ markdownFor: (side) => ({
5314
+ resolveUrl: resolveUrl && side.originalNode ? (u) => resolveUrl(u, side.originalNode) : void 0,
5315
+ onNodeLink: (id) => {
5316
+ const node = side === oldSubject ? diff?.resolved.get(id) ?? id : id;
5317
+ if (side.model.index.has(node)) navigate({ node, past: side === oldSubject });
5318
+ }
5319
+ })
5320
+ },
5321
+ target && ("node" in target ? "node:" + target.node : "edge:" + edgeKey(target.edge))
5322
+ ) : null, [
5323
+ detailPanel,
5324
+ currentSubject,
5325
+ oldSubject,
5326
+ target,
5327
+ diff,
5328
+ profile,
5329
+ trail,
5330
+ navigate,
5331
+ renderText,
5332
+ colorOf,
5333
+ editable,
5334
+ resolveUrl,
5335
+ lookProfile,
5336
+ theme,
5337
+ liveCy,
5338
+ compact,
5339
+ scope,
5340
+ strings,
5341
+ fullPast
5342
+ ]);
5589
5343
  useEffect4(() => {
5590
5344
  if (compact) return;
5591
5345
  const onKey = (e) => {
@@ -5611,8 +5365,8 @@ ${lt}`;
5611
5365
  window.addEventListener("keydown", onKey);
5612
5366
  return () => window.removeEventListener("keydown", onKey);
5613
5367
  }, [compact, zoomBy, fit]);
5614
- if (model.nodes.length === 0 && model.errors.length === 0) {
5615
- return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style: rootStyle, children: [
5368
+ if (!scope.active && model.nodes.length === 0 && model.errors.length === 0) {
5369
+ return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5(ZoomBoundary, { className: `gb-root ${className ?? ""}`, style: rootStyle, children: [
5616
5370
  /* @__PURE__ */ jsxs5("div", { className: "gb-empty", children: [
5617
5371
  /* @__PURE__ */ jsx5("div", { children: emptyMessage ?? strings.empty }),
5618
5372
  editable && !editing && /* @__PURE__ */ jsx5("button", { className: "gb-link", onClick: () => startAdd("node"), children: strings.addNode })
@@ -5623,97 +5377,104 @@ ${lt}`;
5623
5377
  const filtering = isFiltering(view);
5624
5378
  const panes = !!diff;
5625
5379
  const platesOn = !panes && plates.length > 0 && plateAlpha > 0.01;
5626
- return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style: rootStyle, children: [
5380
+ return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsx5(EdgeMarks.Provider, { value: edgeMarks, children: /* @__PURE__ */ jsxs5(ZoomBoundary, { className: `gb-root ${className ?? ""}`, style: rootStyle, children: [
5627
5381
  /* @__PURE__ */ jsxs5("div", { className: "gb-stage", ref: stageRef, style: { background: theme.canvas }, children: [
5628
- platesOn && /* @__PURE__ */ jsx5("svg", { className: "gb-planes", style: { opacity: plateAlpha }, children: /* @__PURE__ */ jsx5("g", { transform: `translate(${viewport.pan.x},${viewport.pan.y}) scale(${viewport.zoom})`, children: plates.map((p) => {
5629
- const c = plateColors(theme, p.color);
5630
- return /* @__PURE__ */ jsx5(
5631
- "polygon",
5382
+ /* @__PURE__ */ jsxs5("div", { className: "gb-scene", children: [
5383
+ platesOn && /* @__PURE__ */ jsx5("svg", { className: "gb-planes", style: { opacity: plateAlpha }, children: /* @__PURE__ */ jsx5("g", { transform: `translate(${viewport.pan.x},${viewport.pan.y}) scale(${viewport.zoom})`, children: plates.map((p) => {
5384
+ const c = plateColors(theme, p.color);
5385
+ return /* @__PURE__ */ jsx5("g", { opacity: p.alpha, children: /* @__PURE__ */ jsx5(
5386
+ "polygon",
5387
+ {
5388
+ "data-gb-layer": p.layer,
5389
+ pointerEvents: "visiblePainted",
5390
+ opacity: hotLayer && hotLayer !== p.layer ? 0.45 : 1,
5391
+ points: p.points.map(([x, y]) => `${x},${y}`).join(" "),
5392
+ fill: p.color,
5393
+ fillOpacity: hotLayer === p.layer ? 0.16 : 0.07,
5394
+ stroke: c.stroke,
5395
+ strokeWidth: hotLayer === p.layer ? 3 : 2,
5396
+ vectorEffect: "non-scaling-stroke"
5397
+ }
5398
+ ) }, p.layer);
5399
+ }) }) }),
5400
+ panes ? (
5401
+ /* Left = before, right = now, sharing one set of coordinates and one viewport: "unchanged things are the same
5402
+ screen pixel in both columns" is the whole value of two columns. */
5403
+ /* @__PURE__ */ jsxs5("div", { className: "gb-panes", children: [
5404
+ /* @__PURE__ */ jsxs5("div", { className: "gb-pane", children: [
5405
+ !prog && /* @__PURE__ */ jsx5(
5406
+ DiffOverlay,
5407
+ {
5408
+ delta: diff,
5409
+ geom: pastGeom,
5410
+ viewport,
5411
+ only: diffOnly,
5412
+ side: "past",
5413
+ visible: filtering ? resolved.visible : null
5414
+ }
5415
+ ),
5416
+ /* @__PURE__ */ jsx5("div", { ref: mirrorElRef, className: "gb-canvas" }),
5417
+ /* @__PURE__ */ jsx5("canvas", { ref: mirrorCanvasRef, className: "gb-labels" }),
5418
+ scope.active && !diff.before.nodes.length && /* @__PURE__ */ jsx5("div", { role: "status", className: "gb-absent", children: scope.missing }),
5419
+ /* @__PURE__ */ jsxs5("div", { className: "gb-pane-tag gb-glass gb-raised gb-round", children: [
5420
+ diff.labels.before,
5421
+ " \xB7 ",
5422
+ strings.past
5423
+ ] })
5424
+ ] }),
5425
+ /* @__PURE__ */ jsxs5("div", { className: "gb-pane", children: [
5426
+ !prog && /* @__PURE__ */ jsx5(
5427
+ DiffOverlay,
5428
+ {
5429
+ delta: diff,
5430
+ geom: diffGeom,
5431
+ viewport,
5432
+ only: diffOnly,
5433
+ side: "now",
5434
+ visible: filtering ? resolved.visible : null
5435
+ }
5436
+ ),
5437
+ /* @__PURE__ */ jsx5("div", { ref: containerRef, className: "gb-canvas" }),
5438
+ /* @__PURE__ */ jsx5("canvas", { ref: labelCanvasRef, className: "gb-labels" }),
5439
+ scope.active && !diff.after.nodes.length && /* @__PURE__ */ jsx5("div", { role: "status", className: "gb-absent", children: scope.missing }),
5440
+ /* @__PURE__ */ jsxs5("div", { className: "gb-pane-tag gb-glass gb-raised gb-round gb-pane-now", children: [
5441
+ diff.labels.after,
5442
+ " \xB7 ",
5443
+ strings.now
5444
+ ] })
5445
+ ] }),
5446
+ /* @__PURE__ */ jsx5("div", { className: "gb-flow", "aria-hidden": true, children: /* @__PURE__ */ jsx5("svg", { viewBox: "-32 -25 64 50", children: /* @__PURE__ */ jsx5("path", { d: "M-31.84,-12.16 H7.52 V-24.32 L31.84,0 L7.52,24.32 V12.16 H-31.84 Z", fill: theme.canvas }) }) })
5447
+ ] }, "panes")
5448
+ ) : /* @__PURE__ */ jsx5("div", { ref: containerRef, className: "gb-canvas" }, "solo"),
5449
+ !panes && scope.active && !model.nodes.length && /* @__PURE__ */ jsx5("div", { role: "status", className: "gb-absent", children: scope.missing }),
5450
+ !panes && /* @__PURE__ */ jsx5("canvas", { ref: labelCanvasRef, className: "gb-labels" }),
5451
+ platesOn && /* @__PURE__ */ jsx5("svg", { className: "gb-plane-labels", style: { opacity: plateAlpha }, children: /* @__PURE__ */ jsx5("g", { transform: `translate(${viewport.pan.x},${viewport.pan.y}) scale(${viewport.zoom})`, children: plates.map((p) => /* @__PURE__ */ jsx5(
5452
+ "text",
5632
5453
  {
5633
- opacity: (p.alpha ?? 1) * (hotLayer && hotLayer !== p.layer ? 0.45 : 1),
5634
- points: p.points.map(([x, y]) => `${x},${y}`).join(" "),
5635
- fill: p.color,
5636
- fillOpacity: hotLayer === p.layer ? 0.16 : 0.07,
5637
- stroke: c.stroke,
5638
- strokeWidth: (hotLayer === p.layer ? 3 : 2) / viewport.zoom
5454
+ "data-gb-layer": p.layer,
5455
+ opacity: p.alpha ?? 1,
5456
+ x: p.anchor[0],
5457
+ y: p.anchor[1],
5458
+ fontSize: 22 / viewport.zoom,
5459
+ fill: plateColors(theme, p.color).text,
5460
+ fontWeight: 700,
5461
+ stroke: theme.canvas,
5462
+ strokeWidth: 4 / viewport.zoom,
5463
+ paintOrder: "stroke",
5464
+ style: { userSelect: "none", pointerEvents: "auto", cursor: "default" },
5465
+ children: p.label
5639
5466
  },
5640
5467
  p.layer
5641
- );
5642
- }) }) }),
5643
- panes ? (
5644
- /* Left = before, right = now, sharing one set of coordinates and one viewport: "unchanged things are the same
5645
- screen pixel in both columns" is the whole value of two columns. */
5646
- /* @__PURE__ */ jsxs5("div", { className: "gb-panes", children: [
5647
- /* @__PURE__ */ jsxs5("div", { className: "gb-pane", children: [
5648
- !prog && /* @__PURE__ */ jsx5(
5649
- DiffOverlay,
5650
- {
5651
- delta: diff,
5652
- geom: pastGeom,
5653
- viewport,
5654
- only: diffOnly,
5655
- side: "past",
5656
- visible: filtering ? resolved.visible : null
5657
- }
5658
- ),
5659
- /* @__PURE__ */ jsx5("div", { ref: mirrorElRef, className: "gb-canvas" }),
5660
- /* @__PURE__ */ jsx5("canvas", { ref: mirrorCanvasRef, className: "gb-labels" }),
5661
- /* @__PURE__ */ jsxs5("div", { className: "gb-pane-tag", children: [
5662
- diff.labels.before,
5663
- " \xB7 ",
5664
- strings.past
5665
- ] })
5666
- ] }),
5667
- /* @__PURE__ */ jsxs5("div", { className: "gb-pane", children: [
5668
- !prog && /* @__PURE__ */ jsx5(
5669
- DiffOverlay,
5670
- {
5671
- delta: diff,
5672
- geom: diffGeom,
5673
- viewport,
5674
- only: diffOnly,
5675
- side: "now",
5676
- visible: filtering ? resolved.visible : null
5677
- }
5678
- ),
5679
- /* @__PURE__ */ jsx5("div", { ref: containerRef, className: "gb-canvas" }),
5680
- /* @__PURE__ */ jsx5("canvas", { ref: labelCanvasRef, className: "gb-labels" }),
5681
- /* @__PURE__ */ jsxs5("div", { className: "gb-pane-tag gb-pane-now", children: [
5682
- diff.labels.after,
5683
- " \xB7 ",
5684
- strings.now
5685
- ] })
5686
- ] }),
5687
- /* @__PURE__ */ jsx5("div", { className: "gb-flow", "aria-hidden": true, children: /* @__PURE__ */ jsx5("svg", { viewBox: "-32 -25 64 50", children: /* @__PURE__ */ jsx5("path", { d: "M-31.84,-12.16 H7.52 V-24.32 L31.84,0 L7.52,24.32 V12.16 H-31.84 Z", fill: theme.canvas }) }) })
5688
- ] }, "panes")
5689
- ) : /* @__PURE__ */ jsx5("div", { ref: containerRef, className: "gb-canvas" }, "solo"),
5690
- !panes && /* @__PURE__ */ jsx5("canvas", { ref: labelCanvasRef, className: "gb-labels" }),
5691
- platesOn && /* @__PURE__ */ jsx5("svg", { className: "gb-plane-labels", style: { opacity: plateAlpha }, children: /* @__PURE__ */ jsx5("g", { transform: `translate(${viewport.pan.x},${viewport.pan.y}) scale(${viewport.zoom})`, children: plates.map((p) => /* @__PURE__ */ jsx5(
5692
- "text",
5693
- {
5694
- opacity: p.alpha ?? 1,
5695
- x: p.anchor[0],
5696
- y: p.anchor[1],
5697
- fontSize: 22 / viewport.zoom,
5698
- fill: plateColors(theme, p.color).text,
5699
- fontWeight: 700,
5700
- stroke: theme.canvas,
5701
- strokeWidth: 4 / viewport.zoom,
5702
- paintOrder: "stroke",
5703
- style: { userSelect: "none", pointerEvents: "auto", cursor: "default" },
5704
- onMouseEnter: () => hoverLayer(p.layer),
5705
- onMouseLeave: () => hoverLayer(null),
5706
- children: p.label
5707
- },
5708
- p.layer
5709
- )) }) }),
5468
+ )) }) })
5469
+ ] }),
5710
5470
  !compact && /* @__PURE__ */ jsx5(
5711
5471
  Toolbar,
5712
5472
  {
5713
5473
  view,
5714
5474
  setView,
5715
5475
  layers: layersHere,
5716
- origins,
5476
+ origins: scope.files,
5477
+ scope,
5717
5478
  stats,
5718
5479
  busy: !!prog,
5719
5480
  controls,
@@ -5722,7 +5483,7 @@ ${lt}`;
5722
5483
  onPreview: preview,
5723
5484
  onPick: pick,
5724
5485
  inputRef: searchInputRef,
5725
- onAdd: editable ? startAdd : void 0,
5486
+ onAdd: editable && (!scope.active || model.nodes.length > 0) ? startAdd : void 0,
5726
5487
  onRelayout: controls.relayout && !diff ? relayout : void 0,
5727
5488
  onRestructure: controls.relayout && !diff ? onRestructure : void 0,
5728
5489
  restructureContent: controls.relayout && !diff ? restructureContent : void 0,
@@ -5730,78 +5491,61 @@ ${lt}`;
5730
5491
  onForceLayers
5731
5492
  }
5732
5493
  ),
5733
- (note || model.errors.length > 0 || legend && !compact) && /* Bottom left: the host's caption (if any) on top, the legend below. Top left is tools, bottom right is the camera. */
5734
- /* @__PURE__ */ jsxs5("div", { className: "gb-bl", children: [
5735
- (note && !(legend && !compact) || model.errors.length > 0) && /* @__PURE__ */ jsxs5("div", { className: "gb-note", children: [
5736
- !(legend && !compact) && note,
5737
- model.errors.length > 0 && // The names must appear on this line. Reporting only a number, "16 sources could not be parsed" sends people back to
5738
- // try the files one by one, while locating them only takes printing the origin. The full list is in title.
5739
- /* @__PURE__ */ jsx5("span", { className: "gb-warn", title: model.errors.map((e) => `${e.origin}: ${e.message}`).join("\n"), children: strings.parseErrors(
5740
- model.errors.length,
5741
- model.errors.slice(0, 2).map((e) => e.origin).join(", ") + (model.errors.length > 2 ? ", \u2026" : "")
5742
- ) })
5494
+ /* @__PURE__ */ jsxs5("div", { className: "gb-footer", children: [
5495
+ (note || model.errors.length > 0 || legend && !compact) && /* Bottom left: the host's caption (if any) on top, the legend below. Top left is tools, bottom right is the camera. */
5496
+ /* @__PURE__ */ jsxs5("div", { className: "gb-bl", children: [
5497
+ (note && !(legend && !compact) || model.errors.length > 0) && /* @__PURE__ */ jsxs5("div", { className: "gb-note gb-glass gb-raised gb-round", children: [
5498
+ !(legend && !compact) && note,
5499
+ model.errors.length > 0 && // The names must appear on this line. Reporting only a number, "16 sources could not be parsed" sends people back to
5500
+ // try the files one by one, while locating them only takes printing the origin. The full list is in title.
5501
+ /* @__PURE__ */ jsx5("span", { className: "gb-warn", title: model.errors.map((e) => `${e.origin}: ${e.message}`).join("\n"), children: strings.parseErrors(
5502
+ model.errors.length,
5503
+ model.errors.slice(0, 2).map((e) => e.origin).join(", ") + (model.errors.length > 2 ? ", \u2026" : "")
5504
+ ) })
5505
+ ] }),
5506
+ legend && !compact && /* @__PURE__ */ jsx5(
5507
+ Legend,
5508
+ {
5509
+ model,
5510
+ profile: lookProfile,
5511
+ theme,
5512
+ look,
5513
+ onLook: setLook,
5514
+ cy: liveCy,
5515
+ delta: diff,
5516
+ hidden: { nodes: view.hiddenNodeKinds ?? [], edges: view.hiddenEdgeKinds ?? [] },
5517
+ onToggle: (which, kind) => {
5518
+ const key = which === "nodes" ? "hiddenNodeKinds" : "hiddenEdgeKinds";
5519
+ const cur = view[key] ?? [];
5520
+ setView({ [key]: cur.includes(kind) ? cur.filter((x) => x !== kind) : [...cur, kind] });
5521
+ },
5522
+ onEmphasis: setLegendEmphasis,
5523
+ onShowAll: () => setView({ hiddenNodeKinds: [], hiddenEdgeKinds: [] }),
5524
+ collapsed: legendCollapsed,
5525
+ onCollapsed: setLegendCollapsed,
5526
+ caption: note
5527
+ }
5528
+ )
5743
5529
  ] }),
5744
- legend && !compact && /* @__PURE__ */ jsx5(
5745
- Legend,
5530
+ !compact && /* @__PURE__ */ jsx5(
5531
+ ZoomDock,
5746
5532
  {
5747
- model,
5748
- profile: lookProfile,
5749
- theme,
5750
- look,
5751
- onLook: setLook,
5752
- cy: liveCy,
5753
- delta: diff,
5754
- hidden: { nodes: view.hiddenNodeKinds ?? [], edges: view.hiddenEdgeKinds ?? [] },
5755
- onToggle: (which, kind) => {
5756
- const key = which === "nodes" ? "hiddenNodeKinds" : "hiddenEdgeKinds";
5757
- const cur = view[key] ?? [];
5758
- setView({ [key]: cur.includes(kind) ? cur.filter((x) => x !== kind) : [...cur, kind] });
5759
- },
5760
- onEmphasis: setLegendEmphasis,
5761
- onShowAll: () => setView({ hiddenNodeKinds: [], hiddenEdgeKinds: [] }),
5762
- collapsed: legendCollapsed,
5763
- onCollapsed: setLegendCollapsed,
5764
- caption: note
5533
+ zoom: controls.zoom,
5534
+ onZoom: zoomBy,
5535
+ onFit: fit,
5536
+ checks: showIssues ? checks : void 0,
5537
+ report: showIssues ? props.issueReport : void 0
5765
5538
  }
5766
5539
  )
5767
5540
  ] }),
5768
- !compact && /* @__PURE__ */ jsx5(
5769
- ZoomDock,
5770
- {
5771
- zoom: controls.zoom,
5772
- onZoom: zoomBy,
5773
- onFit: fit,
5774
- issues: showIssues ? issues : [],
5775
- onPick: pick
5776
- }
5777
- ),
5778
- prog && /* @__PURE__ */ jsx5("div", { className: "gb-mask", children: /* @__PURE__ */ jsxs5("div", { children: [
5541
+ prog && /* @__PURE__ */ jsx5("div", { className: "gb-mask", children: /* @__PURE__ */ jsxs5("div", { className: "gb-glass gb-raised gb-round gb-loading", children: [
5779
5542
  /* @__PURE__ */ jsx5("span", { className: "gb-spin" }),
5780
5543
  prog.total > 0 ? strings.layingOut(prog.done, prog.total) : strings.preparing
5781
5544
  ] }) }),
5782
5545
  compact && /* @__PURE__ */ jsx5("div", { style: { position: "absolute", bottom: 4, left: 8, fontSize: 10.5, opacity: 0.6, pointerEvents: "none" }, children: strings.stats(stats.nodes, stats.edges) })
5783
5546
  ] }),
5784
- /* @__PURE__ */ jsx5(Drawer, { children: editPanel || (detailPanel && selected ? /* @__PURE__ */ jsx5(
5785
- DetailPanel,
5786
- {
5787
- node: selected,
5788
- spec: profile.detail,
5789
- kindLabels: profile.kindLabels,
5790
- onClose: () => setSelected(null),
5791
- renderText,
5792
- onEdit: editable ? () => setEditing({ what: "node", id: selected.id }) : void 0,
5793
- color: colorOf(selected.id),
5794
- markdown: {
5795
- resolveUrl: resolveUrl ? (u) => {
5796
- const n = model.index.get(selected.id);
5797
- return n ? resolveUrl(u, n) : null;
5798
- } : void 0,
5799
- onNodeLink: pick
5800
- }
5801
- },
5802
- selected.id
5803
- ) : null) })
5804
- ] }) });
5547
+ /* @__PURE__ */ jsx5(Drawer, { children: editPanel || details }, props.scopeKey)
5548
+ ] }) }) });
5805
5549
  }
5806
5550
 
5807
5551
  export {
@@ -5809,32 +5553,6 @@ export {
5809
5553
  clearLayoutCache,
5810
5554
  DEFAULT_PLANES,
5811
5555
  projectPlanes,
5812
- MIN_DOT,
5813
- MIN_LINE,
5814
- HOLD_LEAF,
5815
- NODE_SLACK,
5816
- SKEL_FLOOR,
5817
- SEM_W,
5818
- SEM_INK,
5819
- SEM_BOOST,
5820
- FOCUS_INK,
5821
- focusAlphaOf,
5822
- DETAIL_LEAF,
5823
- GAP,
5824
- HOVER_DIM,
5825
- dotOf,
5826
- gapOf,
5827
- skeletonLineOf,
5828
- semanticAlphaOf,
5829
- clippedLength,
5830
- hazeOf,
5831
- EDGE_REACH,
5832
- reachOf,
5833
- hittable,
5834
- detailed,
5835
- edgeKindHidden,
5836
- shapeOf,
5837
- arrowOf,
5838
5556
  relaxOverlaps,
5839
5557
  relaxNodes,
5840
5558
  labelBox,
@@ -5843,6 +5561,7 @@ export {
5843
5561
  placePanel,
5844
5562
  ALL_CONTROLS,
5845
5563
  touchGestures,
5564
+ frameTranslation,
5846
5565
  applyLook,
5847
5566
  DiffOverlay,
5848
5567
  GraphCanvas