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.
- package/README.md +6 -7
- package/dist/chunks/{chunk-LMYD4QHC.js → chunk-3CNHFYHG.js} +1329 -1610
- package/dist/chunks/chunk-7PWRJEZT.js +35 -0
- package/dist/chunks/chunk-CHOCJIOD.js +1340 -0
- package/dist/chunks/chunk-DHYIMBHU.js +960 -0
- package/dist/chunks/{chunk-3SAL4526.js → chunk-NDUF3CBQ.js} +349 -989
- package/dist/cli/glassbrain.js +441 -230
- package/dist/cli/viewer.js +228 -194
- package/dist/core.d.ts +2 -0
- package/dist/core.js +54 -26
- package/dist/diff.d.ts +9 -1
- package/dist/edit.d.ts +10 -0
- package/dist/index.js +63 -35
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +103 -73
- package/dist/kinds.d.ts +23 -0
- package/dist/layers.d.ts +3 -1
- package/dist/lint-report.d.ts +70 -0
- package/dist/profile.d.ts +15 -3
- package/dist/react/DetailPanel.d.ts +31 -1
- package/dist/react/DetailPanel.js +8 -4
- package/dist/react/EdgeMark.d.ts +22 -0
- package/dist/react/EditPanel.d.ts +6 -6
- package/dist/react/GraphCanvas.d.ts +18 -5
- package/dist/react/GraphCanvas.js +4 -4
- package/dist/react/Inspector.d.ts +72 -0
- package/dist/react/ObjectRef.d.ts +12 -0
- package/dist/react/Toolbar.d.ts +10 -3
- package/dist/react/ZoomBoundary.d.ts +4 -0
- package/dist/react/camera.d.ts +7 -0
- package/dist/react/i18n.d.ts +2 -2
- package/dist/react/icons.d.ts +7 -1
- package/dist/react/input.d.ts +5 -3
- package/dist/react/useSubgraph.d.ts +15 -0
- package/dist/shell.d.ts +1 -0
- package/dist/strings.d.ts +24 -3
- package/dist/style.d.ts +2 -0
- package/dist/subgraph.d.ts +13 -0
- package/dist/tree.d.ts +1 -0
- package/dist/view.d.ts +3 -1
- package/package.json +1 -1
- package/schema/profile.schema.json +2 -2
- package/dist/chunks/chunk-3P34XHQ2.js +0 -244
- package/dist/chunks/chunk-5DEN6HXJ.js +0 -99
- package/dist/chunks/chunk-M3MAM2VD.js +0 -67
|
@@ -0,0 +1,1340 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EDGE_W,
|
|
3
|
+
EN,
|
|
4
|
+
HOVER_FADE_MS,
|
|
5
|
+
NODE_BASE,
|
|
6
|
+
buildModel,
|
|
7
|
+
edgeContent,
|
|
8
|
+
edgeContentChanged,
|
|
9
|
+
edgeKey,
|
|
10
|
+
edgeKindClass,
|
|
11
|
+
edgesOf,
|
|
12
|
+
nodeWeight,
|
|
13
|
+
sameEdge,
|
|
14
|
+
shareT,
|
|
15
|
+
stable,
|
|
16
|
+
themeColor
|
|
17
|
+
} from "./chunk-NDUF3CBQ.js";
|
|
18
|
+
|
|
19
|
+
// src/react/icons.tsx
|
|
20
|
+
import { jsx } from "react/jsx-runtime";
|
|
21
|
+
var Icon = ({ d, size = 16 }) => /* @__PURE__ */ jsx("svg", { className: "gb-ico", viewBox: "0 0 24 24", width: size, height: size, "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d }) });
|
|
22
|
+
var I = {
|
|
23
|
+
id: "M6.5 2.5h11a4 4 0 0 1 4 4v11a4 4 0 0 1-4 4h-11a4 4 0 0 1-4-4v-11a4 4 0 0 1 4-4ZM7.5 8v8M11.5 8h1.75a4 4 0 0 1 0 8H11.5Z",
|
|
24
|
+
enter: "M8 8V5a1 1 0 0 1 1-1h11v16H9a1 1 0 0 1-1-1v-3M3 12h12m-4-4 4 4-4 4",
|
|
25
|
+
exit: "M8 8V5a1 1 0 0 1 1-1h11v16H9a1 1 0 0 1-1-1v-3M15 12H3m4-4-4 4 4 4",
|
|
26
|
+
tree: "M5 3v13a2 2 0 0 0 2 2h5M5 7h7M13 4h7v6h-7zM13 15h7v6h-7z",
|
|
27
|
+
search: "M10.5 4a6.5 6.5 0 1 1 0 13 6.5 6.5 0 0 1 0-13Zm4.75 11.25L20 20",
|
|
28
|
+
x: "M6 6l12 12M18 6 6 18",
|
|
29
|
+
trash: "M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 10v7m4-7v7",
|
|
30
|
+
clear: "M21 12a9 9 0 1 1-18 0 9 9 0 1 1 18 0ZM9 9l6 6m0-6-6 6",
|
|
31
|
+
plus: "M12 5v14M5 12h14",
|
|
32
|
+
minus: "M5 12h14",
|
|
33
|
+
fit: "M4 9V5a1 1 0 0 1 1-1h4M15 4h4a1 1 0 0 1 1 1v4M20 15v4a1 1 0 0 1-1 1h-4M9 20H5a1 1 0 0 1-1-1v-4",
|
|
34
|
+
more: "M4 7h10M18 7h2M4 17h2M10 17h10M16 5v4M8 15v4",
|
|
35
|
+
checks: "M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18Zm0 5v5m0 3v.2",
|
|
36
|
+
arrow: "M5 12h13M13 7l5 5-5 5",
|
|
37
|
+
stack: "M12 4 3 8.5l9 4.5 9-4.5L12 4ZM3 12.5l9 4.5 9-4.5M3 16.5l9 4.5 9-4.5",
|
|
38
|
+
edit: "M4 20h4L19 9l-4-4L4 16v4Zm9-13 4 4",
|
|
39
|
+
legend: "M5 7h.01M9 7h10M5 12h.01M9 12h10M5 17h.01M9 17h10",
|
|
40
|
+
reset: "M4 12a8 8 0 1 0 2.3-5.6M4 4v4h4",
|
|
41
|
+
collapse: "M6 15l6-6 6 6",
|
|
42
|
+
file: "M7 3h7l5 5v12a1 1 0 0 1-1 1H7a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Zm7 0v5h5"
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/react/ObjectRef.tsx
|
|
46
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
47
|
+
function NodeDot({ color }) {
|
|
48
|
+
return /* @__PURE__ */ jsx2("i", { "aria-hidden": "true", className: "gb-dot", style: { background: color } });
|
|
49
|
+
}
|
|
50
|
+
function ObjectRef({ mark, name, sub, onPick, title }) {
|
|
51
|
+
const label = /* @__PURE__ */ jsx2("span", { className: "gb-ref-label", children: name });
|
|
52
|
+
const body = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
53
|
+
/* @__PURE__ */ jsx2("span", { className: "gb-ref-mark", "aria-hidden": "true", children: mark }),
|
|
54
|
+
sub ? /* @__PURE__ */ jsxs("span", { className: "gb-ref-main", children: [
|
|
55
|
+
label,
|
|
56
|
+
/* @__PURE__ */ jsx2("span", { className: "gb-ref-sub", children: sub })
|
|
57
|
+
] }) : label
|
|
58
|
+
] });
|
|
59
|
+
return onPick ? /* @__PURE__ */ jsx2("button", { type: "button", className: "gb-ref gb-ref-link", title, onClick: onPick, children: body }) : /* @__PURE__ */ jsx2("span", { className: "gb-ref gb-ref-static", children: body });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/react/i18n.ts
|
|
63
|
+
import { createContext, useContext } from "react";
|
|
64
|
+
var StringsContext = createContext(EN);
|
|
65
|
+
var useStrings = () => useContext(StringsContext);
|
|
66
|
+
|
|
67
|
+
// src/react/Inspector.tsx
|
|
68
|
+
import { useState } from "react";
|
|
69
|
+
|
|
70
|
+
// src/react/EdgeMark.tsx
|
|
71
|
+
import { createContext as createContext2, useContext as useContext2 } from "react";
|
|
72
|
+
|
|
73
|
+
// src/paint.ts
|
|
74
|
+
var MIN_DOT = 2;
|
|
75
|
+
var MIN_LINE = 1;
|
|
76
|
+
var HOLD_LEAF = 4;
|
|
77
|
+
var NODE_SLACK = 4;
|
|
78
|
+
var SKEL_FLOOR = 4;
|
|
79
|
+
var SKEL_CURVE = 1.2;
|
|
80
|
+
var SEM_W = 1;
|
|
81
|
+
var SEM_INK = 0.05;
|
|
82
|
+
var SEM_BOOST = 2;
|
|
83
|
+
var FOCUS_INK = 16;
|
|
84
|
+
var focusAlphaOf = (n, ink = FOCUS_INK) => Math.min(1, Math.sqrt(ink / Math.max(1, n)));
|
|
85
|
+
var DETAIL_LEAF = 6;
|
|
86
|
+
var GAP = [3, 9];
|
|
87
|
+
var GAP_MAX = 1.5;
|
|
88
|
+
var HAZE_R = 1.4;
|
|
89
|
+
var HAZE_MAX = 0.32;
|
|
90
|
+
var HOVER_DIM = 0.4;
|
|
91
|
+
var MUTE_FADE_MS = 240;
|
|
92
|
+
var clamp01 = (v) => Math.max(0, Math.min(1, v));
|
|
93
|
+
var ramp = (v, [a, b]) => clamp01((v - a) / (b - a));
|
|
94
|
+
var dotOf = (d, z, w = 0, leafPx = Infinity, hold = HOLD_LEAF) => {
|
|
95
|
+
const s = d * z * Math.max(1, w * hold / leafPx);
|
|
96
|
+
return s >= MIN_DOT ? [s, 1] : [MIN_DOT, (s / MIN_DOT) ** 2];
|
|
97
|
+
};
|
|
98
|
+
var gapOf = (px) => GAP_MAX * ramp(px, GAP);
|
|
99
|
+
var skeletonLineOf = (w, z, t) => {
|
|
100
|
+
const s = Math.max(w * z, SKEL_FLOOR * t ** SKEL_CURVE);
|
|
101
|
+
return s >= MIN_LINE ? [s, 1] : [MIN_LINE, s / MIN_LINE];
|
|
102
|
+
};
|
|
103
|
+
var semanticAlphaOf = (opacity, cover) => Math.min(1, opacity * Math.min(SEM_BOOST, Math.sqrt(SEM_INK / Math.max(cover, 1e-9))));
|
|
104
|
+
var clippedLength = (ax, ay, bx, by, W, H) => {
|
|
105
|
+
let t0 = 0, t1 = 1;
|
|
106
|
+
const dx = bx - ax, dy = by - ay;
|
|
107
|
+
for (const [p, q2] of [[-dx, ax], [dx, W - ax], [-dy, ay], [dy, H - ay]]) {
|
|
108
|
+
if (p === 0) {
|
|
109
|
+
if (q2 < 0) return 0;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const r = q2 / p;
|
|
113
|
+
if (p < 0) {
|
|
114
|
+
if (r > t1) return 0;
|
|
115
|
+
if (r > t0) t0 = r;
|
|
116
|
+
} else {
|
|
117
|
+
if (r < t0) return 0;
|
|
118
|
+
if (r < t1) t1 = r;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return Math.hypot(dx, dy) * (t1 - t0);
|
|
122
|
+
};
|
|
123
|
+
var hazeOf = (leafPx) => HAZE_MAX * (1 - ramp(leafPx, GAP));
|
|
124
|
+
var EDGE_REACH = 0.5;
|
|
125
|
+
var reachOf = (vis, lineW, touch = false, base = EDGE_REACH) => (base * (touch ? 2.4 : 1) + lineW / 2) * vis;
|
|
126
|
+
var hittable = (reach) => reach * 2 >= 1;
|
|
127
|
+
var detailed = (leafPx) => leafPx >= DETAIL_LEAF;
|
|
128
|
+
var edgeKindHidden = (skeleton, kind, hidden) => !skeleton && hidden.has(kind);
|
|
129
|
+
var shapeOf = (name) => /hexagon|octagon|pentagon|heptagon/.test(name) ? "hexagon" : /diamond/.test(name) ? "diamond" : /rectangle|square|barrel|tag/.test(name) ? "rect" : "circle";
|
|
130
|
+
var arrowOf = (name) => name === "none" ? "none" : name === "tee" ? "tee" : "triangle";
|
|
131
|
+
function installPainter(cy, opts) {
|
|
132
|
+
const r = cy.renderer();
|
|
133
|
+
const baseRender = r.render;
|
|
134
|
+
const baseFind = r.findNearestElements;
|
|
135
|
+
let nodes = [], parents = [], edges = [];
|
|
136
|
+
let byId = /* @__PURE__ */ new Map();
|
|
137
|
+
let stale = true;
|
|
138
|
+
const dirty = /* @__PURE__ */ new Set();
|
|
139
|
+
let needs = true;
|
|
140
|
+
const readNode = (rec) => {
|
|
141
|
+
const e = rec.ele;
|
|
142
|
+
rec.vis = e.visible();
|
|
143
|
+
rec.op = e.effectiveOpacity();
|
|
144
|
+
rec.fill = e.pstyle("background-color").strValue;
|
|
145
|
+
rec.border = e.pstyle("border-color").strValue;
|
|
146
|
+
rec.bw = e.pstyle("border-width").pfValue;
|
|
147
|
+
rec.d = rec.parent ? 0 : e.width();
|
|
148
|
+
rec.shape = rec.parent ? "rect" : shapeOf(e.pstyle("shape").value);
|
|
149
|
+
rec.bgOp = e.pstyle("background-opacity").value;
|
|
150
|
+
rec.events = e.pstyle("events").value !== "no";
|
|
151
|
+
};
|
|
152
|
+
const readEdge = (rec) => {
|
|
153
|
+
const e = rec.ele;
|
|
154
|
+
rec.vis = e.pstyle("display").value !== "none" && e.pstyle("visibility").value === "visible";
|
|
155
|
+
rec.op = e.effectiveOpacity() * e.pstyle("line-opacity").value;
|
|
156
|
+
rec.color = e.pstyle("line-color").strValue;
|
|
157
|
+
rec.w = e.pstyle("width").pfValue;
|
|
158
|
+
rec.dash = e.pstyle("line-style").value;
|
|
159
|
+
rec.head = arrowOf(e.pstyle("target-arrow-shape").value);
|
|
160
|
+
rec.tail = arrowOf(e.pstyle("source-arrow-shape").value);
|
|
161
|
+
rec.z = e.pstyle("z-index").value;
|
|
162
|
+
const curve = e.pstyle("curve-style").value;
|
|
163
|
+
rec.bend = curve === "unbundled-bezier" ? e.pstyle("control-point-distances").pfValue?.[0] ?? 0 : 0;
|
|
164
|
+
rec.events = e.pstyle("events").value !== "no";
|
|
165
|
+
};
|
|
166
|
+
const rebuild = () => {
|
|
167
|
+
nodes = [];
|
|
168
|
+
parents = [];
|
|
169
|
+
edges = [];
|
|
170
|
+
byId = /* @__PURE__ */ new Map();
|
|
171
|
+
cy.nodes().forEach((ele) => {
|
|
172
|
+
const rec = {
|
|
173
|
+
ele,
|
|
174
|
+
id: ele.id(),
|
|
175
|
+
parent: ele.isParent(),
|
|
176
|
+
t: shareT(ele.data("share") ?? 0),
|
|
177
|
+
w: nodeWeight(ele.data("leaves") ?? 0),
|
|
178
|
+
depth: ele.ancestors().length,
|
|
179
|
+
x: 0,
|
|
180
|
+
y: 0,
|
|
181
|
+
s: 0,
|
|
182
|
+
a: 1
|
|
183
|
+
};
|
|
184
|
+
readNode(rec);
|
|
185
|
+
(rec.parent ? parents : nodes).push(rec);
|
|
186
|
+
byId.set(rec.id, rec);
|
|
187
|
+
});
|
|
188
|
+
parents.sort((a, b) => a.depth - b.depth);
|
|
189
|
+
cy.edges().forEach((ele) => {
|
|
190
|
+
const src = byId.get(ele.source().id()), tgt = byId.get(ele.target().id());
|
|
191
|
+
if (!src || !tgt) return;
|
|
192
|
+
const rec = { ele, id: ele.id(), src, tgt, skeleton: ele.hasClass("contains"), t: shareT(ele.data("share") ?? 0) };
|
|
193
|
+
readEdge(rec);
|
|
194
|
+
edges.push(rec);
|
|
195
|
+
byId.set(rec.id, rec);
|
|
196
|
+
});
|
|
197
|
+
edges = byZ(edges);
|
|
198
|
+
stale = false;
|
|
199
|
+
dirty.clear();
|
|
200
|
+
remute();
|
|
201
|
+
repin();
|
|
202
|
+
};
|
|
203
|
+
const refresh = () => {
|
|
204
|
+
if (stale) {
|
|
205
|
+
rebuild();
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!dirty.size) return;
|
|
209
|
+
let reorder = false;
|
|
210
|
+
for (const ele of dirty) {
|
|
211
|
+
if (ele.removed()) continue;
|
|
212
|
+
const rec = byId.get(ele.id());
|
|
213
|
+
if (!rec) {
|
|
214
|
+
stale = true;
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if ("src" in rec) {
|
|
218
|
+
const z = rec.z;
|
|
219
|
+
readEdge(rec);
|
|
220
|
+
if (rec.z !== z) reorder = true;
|
|
221
|
+
} else readNode(rec);
|
|
222
|
+
}
|
|
223
|
+
dirty.clear();
|
|
224
|
+
if (stale) rebuild();
|
|
225
|
+
else if (reorder) edges = byZ(edges);
|
|
226
|
+
};
|
|
227
|
+
const onStyle = (e) => {
|
|
228
|
+
const t = e.target;
|
|
229
|
+
dirty.add(t);
|
|
230
|
+
if (t.isNode() && t.isParent()) t.descendants().forEach((d) => dirty.add(d));
|
|
231
|
+
needs = true;
|
|
232
|
+
};
|
|
233
|
+
const onStructure = () => {
|
|
234
|
+
stale = true;
|
|
235
|
+
needs = true;
|
|
236
|
+
};
|
|
237
|
+
const onMove = () => {
|
|
238
|
+
needs = true;
|
|
239
|
+
};
|
|
240
|
+
cy.on("style", onStyle);
|
|
241
|
+
cy.on("add remove data move", onStructure);
|
|
242
|
+
cy.on("position viewport", onMove);
|
|
243
|
+
let focusIds = /* @__PURE__ */ new Set();
|
|
244
|
+
let lifted = /* @__PURE__ */ new Set();
|
|
245
|
+
let semCover = 0;
|
|
246
|
+
let hovered = null;
|
|
247
|
+
let hoverT = 0, hoverFrom = 0, hoverTo = 0;
|
|
248
|
+
let target = null;
|
|
249
|
+
let spot = null;
|
|
250
|
+
let muteKinds = { nodes: /* @__PURE__ */ new Set(), edges: /* @__PURE__ */ new Set() };
|
|
251
|
+
let mutedIds = /* @__PURE__ */ new Set();
|
|
252
|
+
let pinned = /* @__PURE__ */ new Set();
|
|
253
|
+
let mutedFrom = /* @__PURE__ */ new Set();
|
|
254
|
+
let muteT = 1, muteStart = 0;
|
|
255
|
+
const mutedNow = () => {
|
|
256
|
+
const out = /* @__PURE__ */ new Set();
|
|
257
|
+
if (!muteKinds.nodes.size && !muteKinds.edges.size) return out;
|
|
258
|
+
for (const n of [...nodes, ...parents]) if (muteKinds.nodes.has(n.ele.data("kind"))) out.add(n.id);
|
|
259
|
+
for (const e of edges) {
|
|
260
|
+
if (edgeKindHidden(e.skeleton, e.ele.data("kind"), muteKinds.edges) || out.has(e.src.id) || out.has(e.tgt.id)) out.add(e.id);
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
};
|
|
264
|
+
const remute = () => {
|
|
265
|
+
mutedIds = mutedFrom = mutedNow();
|
|
266
|
+
muteT = 1;
|
|
267
|
+
};
|
|
268
|
+
const repin = () => {
|
|
269
|
+
const sel = cy.$(":selected");
|
|
270
|
+
pinned = new Set(sel.nonempty() ? sel.closedNeighborhood().map((x) => x.id()) : []);
|
|
271
|
+
};
|
|
272
|
+
const shownIn = (set, id) => !set.has(id) || pinned.has(id) ? 1 : focusIds.has(id) ? smooth(hoverT) : 0;
|
|
273
|
+
const muteOf = (id) => {
|
|
274
|
+
const to = shownIn(mutedIds, id);
|
|
275
|
+
if (muteT >= 1) return to;
|
|
276
|
+
const from = shownIn(mutedFrom, id);
|
|
277
|
+
return from + (to - from) * smooth(muteT);
|
|
278
|
+
};
|
|
279
|
+
const settleFocus = (instant) => {
|
|
280
|
+
const live = target && !target.removed() ? target : spot?.size ? cy.collection([...spot].map((id) => cy.$id(id)).filter((x) => x.nonempty())) : null;
|
|
281
|
+
if (live && live.nonempty()) {
|
|
282
|
+
const one = live === target;
|
|
283
|
+
const focus = !one ? live : target.isNode() ? target.closedNeighborhood() : target.union(target.connectedNodes());
|
|
284
|
+
focusIds = new Set(focus.map((x) => x.id()));
|
|
285
|
+
lifted = /* @__PURE__ */ new Set([...focusIds, ...focus.nodes().ancestors().map((x) => x.id())]);
|
|
286
|
+
hovered = one ? target.id() : null;
|
|
287
|
+
if (hoverTo !== 1) {
|
|
288
|
+
hoverFrom = performance.now() - hoverT * HOVER_FADE_MS;
|
|
289
|
+
hoverTo = 1;
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
if (instant) {
|
|
293
|
+
hoverT = 0;
|
|
294
|
+
focusIds = /* @__PURE__ */ new Set();
|
|
295
|
+
lifted = /* @__PURE__ */ new Set();
|
|
296
|
+
hovered = null;
|
|
297
|
+
}
|
|
298
|
+
if (hoverTo !== 0) {
|
|
299
|
+
hoverFrom = performance.now() - (1 - hoverT) * HOVER_FADE_MS;
|
|
300
|
+
hoverTo = 0;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
needs = true;
|
|
304
|
+
r.redraw();
|
|
305
|
+
};
|
|
306
|
+
const hover = (t, instant = false) => {
|
|
307
|
+
target = t;
|
|
308
|
+
settleFocus(instant);
|
|
309
|
+
};
|
|
310
|
+
const mute = (nodeKinds, edgeKinds) => {
|
|
311
|
+
const same = (a, b) => a.size === b.length && b.every((k) => a.has(k));
|
|
312
|
+
if (same(muteKinds.nodes, nodeKinds) && same(muteKinds.edges, edgeKinds)) return;
|
|
313
|
+
muteKinds = { nodes: new Set(nodeKinds), edges: new Set(edgeKinds) };
|
|
314
|
+
if (!stale) {
|
|
315
|
+
const next = mutedNow();
|
|
316
|
+
const back = muteT < 1 && next.size === mutedFrom.size && [...next].every((id) => mutedFrom.has(id));
|
|
317
|
+
const t = back ? 1 - muteT : 0;
|
|
318
|
+
mutedFrom = mutedIds;
|
|
319
|
+
mutedIds = next;
|
|
320
|
+
muteT = t;
|
|
321
|
+
muteStart = performance.now() - t * MUTE_FADE_MS;
|
|
322
|
+
}
|
|
323
|
+
needs = true;
|
|
324
|
+
r.redraw();
|
|
325
|
+
};
|
|
326
|
+
const onSelect = () => {
|
|
327
|
+
repin();
|
|
328
|
+
needs = true;
|
|
329
|
+
r.redraw();
|
|
330
|
+
};
|
|
331
|
+
cy.on("select unselect", onSelect);
|
|
332
|
+
const spotlight = (ids2) => {
|
|
333
|
+
spot = ids2?.size ? ids2 : null;
|
|
334
|
+
settleFocus(false);
|
|
335
|
+
};
|
|
336
|
+
const stepHover = (now) => {
|
|
337
|
+
if (hoverT === hoverTo) return false;
|
|
338
|
+
const k = Math.min(1, (now - hoverFrom) / HOVER_FADE_MS);
|
|
339
|
+
hoverT = hoverTo ? k : 1 - k;
|
|
340
|
+
if (k >= 1) {
|
|
341
|
+
hoverT = hoverTo;
|
|
342
|
+
if (!hoverTo) {
|
|
343
|
+
focusIds = /* @__PURE__ */ new Set();
|
|
344
|
+
lifted = /* @__PURE__ */ new Set();
|
|
345
|
+
hovered = null;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return true;
|
|
349
|
+
};
|
|
350
|
+
const stepMute = (now) => {
|
|
351
|
+
if (muteT >= 1) return false;
|
|
352
|
+
muteT = Math.min(1, (now - muteStart) / MUTE_FADE_MS);
|
|
353
|
+
if (muteT >= 1) mutedFrom = mutedIds;
|
|
354
|
+
return true;
|
|
355
|
+
};
|
|
356
|
+
const dimNow = () => 1 - (1 - HOVER_DIM) * smooth(hoverT);
|
|
357
|
+
let wasActive = false;
|
|
358
|
+
let lastSize = "";
|
|
359
|
+
const ids = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()];
|
|
360
|
+
const idOf = (m) => (c) => m.get(c) ?? m.set(c, m.size).get(c);
|
|
361
|
+
const fillId = idOf(ids[0]), borderId = idOf(ids[1]), lineId = idOf(ids[2]);
|
|
362
|
+
const paint = () => {
|
|
363
|
+
const pr = r.getPixelRatio();
|
|
364
|
+
if (r.prevPxRatio !== pr) {
|
|
365
|
+
r.invalidateContainerClientCoordsCache();
|
|
366
|
+
r.matchCanvasSize(r.container);
|
|
367
|
+
}
|
|
368
|
+
r.prevPxRatio = pr;
|
|
369
|
+
const size = `${r.canvasWidth}x${r.canvasHeight}`;
|
|
370
|
+
const now = performance.now();
|
|
371
|
+
const hovering = stepHover(now), muting = stepMute(now);
|
|
372
|
+
const animating = hovering || muting;
|
|
373
|
+
if (r.hoverData?.selecting || r.touchData?.selecting) needs = true;
|
|
374
|
+
if (!needs && !animating && size === lastSize) return;
|
|
375
|
+
needs = false;
|
|
376
|
+
lastSize = size;
|
|
377
|
+
refresh();
|
|
378
|
+
for (const m of ids) m.clear();
|
|
379
|
+
const ctx = r.data.contexts[r.NODE];
|
|
380
|
+
for (const c of r.data.contexts) {
|
|
381
|
+
c.setTransform(1, 0, 0, 1, 0, 0);
|
|
382
|
+
c.clearRect(0, 0, r.canvasWidth, r.canvasHeight);
|
|
383
|
+
}
|
|
384
|
+
ctx.setTransform(pr, 0, 0, pr, 0, 0);
|
|
385
|
+
const W = r.canvasWidth / pr, H = r.canvasHeight / pr;
|
|
386
|
+
const z = cy.zoom(), pan = cy.pan();
|
|
387
|
+
const leafPx = NODE_BASE * opts.nodeScale() * z;
|
|
388
|
+
const dim = dimNow();
|
|
389
|
+
const mulOf = (id) => (hoverT > 0 && !lifted.has(id) ? dim : 1) * muteOf(id);
|
|
390
|
+
const PAD = 40;
|
|
391
|
+
const onScreen = (x, y, rad) => x + rad > -PAD && x - rad < W + PAD && y + rad > -PAD && y - rad < H + PAD;
|
|
392
|
+
const hold = HOLD_LEAF;
|
|
393
|
+
for (const n of nodes) {
|
|
394
|
+
if (!n.vis) continue;
|
|
395
|
+
const p = n.ele.position();
|
|
396
|
+
n.x = p.x * z + pan.x;
|
|
397
|
+
n.y = p.y * z + pan.y;
|
|
398
|
+
[n.s, n.a] = dotOf(n.d, z, n.w, leafPx, hold);
|
|
399
|
+
}
|
|
400
|
+
for (const n of parents) {
|
|
401
|
+
if (!n.vis) continue;
|
|
402
|
+
const bb = n.ele.boundingBox({ includeLabels: false, includeOverlays: false, includeUnderlays: false });
|
|
403
|
+
n.box = [bb.x1 * z + pan.x, bb.y1 * z + pan.y, bb.w * z, bb.h * z];
|
|
404
|
+
n.x = n.box[0] + n.box[2] / 2;
|
|
405
|
+
n.y = n.box[1] + n.box[3] / 2;
|
|
406
|
+
n.s = 0;
|
|
407
|
+
n.a = 1;
|
|
408
|
+
}
|
|
409
|
+
ctx.lineJoin = "round";
|
|
410
|
+
drawBoxes(ctx, z, mulOf);
|
|
411
|
+
const haze = hazeOf(leafPx);
|
|
412
|
+
if (haze > 5e-3) drawHaze(ctx, z, haze, mulOf, onScreen);
|
|
413
|
+
let ink = 0;
|
|
414
|
+
for (const e of edges) {
|
|
415
|
+
if (e.skeleton || !e.vis || !e.src.vis || !e.tgt.vis) continue;
|
|
416
|
+
ink += clippedLength(e.src.x, e.src.y, e.tgt.x, e.tgt.y, W, H) * (SEM_W * e.w / EDGE_W) * e.op;
|
|
417
|
+
}
|
|
418
|
+
semCover = ink / (W * H);
|
|
419
|
+
drawEdges(ctx, edges, z, leafPx, mulOf, W, H, false);
|
|
420
|
+
drawNodes(ctx, nodes, mulOf, onScreen);
|
|
421
|
+
if (hoverT > 0 && focusIds.size) {
|
|
422
|
+
drawEdges(ctx, edges.filter((e) => focusIds.has(e.id)), z, leafPx, () => 1, W, H, true);
|
|
423
|
+
drawNodes(ctx, nodes.filter((n) => focusIds.has(n.id)), () => 1, onScreen);
|
|
424
|
+
const h = hovered ? byId.get(hovered) : null;
|
|
425
|
+
if (h && !("src" in h) && !h.parent && h.vis) {
|
|
426
|
+
ctx.globalAlpha = 0.5 * smooth(hoverT);
|
|
427
|
+
ctx.strokeStyle = opts.theme().halo;
|
|
428
|
+
ctx.lineWidth = 2;
|
|
429
|
+
ctx.beginPath();
|
|
430
|
+
ctx.arc(h.x, h.y, h.s / 2 + gapOf(h.s) + 3, 0, Math.PI * 2);
|
|
431
|
+
ctx.stroke();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
drawSelectionBox(ctx, z, pan);
|
|
435
|
+
ctx.globalAlpha = 1;
|
|
436
|
+
if (animating) queueMicrotask(() => r.redraw());
|
|
437
|
+
};
|
|
438
|
+
const drawBoxes = (ctx, z, mulOf) => {
|
|
439
|
+
for (const n of parents) {
|
|
440
|
+
if (!n.vis || !n.box) continue;
|
|
441
|
+
const m = n.op * mulOf(n.id);
|
|
442
|
+
if (m < 0.01) continue;
|
|
443
|
+
const [x, y, w, h] = n.box;
|
|
444
|
+
const rad = Math.min(10, w / 4, h / 4);
|
|
445
|
+
ctx.beginPath();
|
|
446
|
+
ctx.roundRect(x, y, w, h, rad);
|
|
447
|
+
ctx.globalAlpha = n.bgOp * m;
|
|
448
|
+
ctx.fillStyle = n.fill;
|
|
449
|
+
ctx.fill();
|
|
450
|
+
const [lw, la] = skeletonLineOf(n.bw, z, n.t);
|
|
451
|
+
ctx.globalAlpha = la * m;
|
|
452
|
+
ctx.strokeStyle = n.border;
|
|
453
|
+
ctx.lineWidth = lw;
|
|
454
|
+
ctx.stroke();
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
const drawHaze = (ctx, z, haze, mulOf, onScreen) => {
|
|
458
|
+
const groups = /* @__PURE__ */ new Map();
|
|
459
|
+
for (const n of nodes) {
|
|
460
|
+
if (!n.vis) continue;
|
|
461
|
+
const rad = n.d * HAZE_R * z;
|
|
462
|
+
if (!onScreen(n.x, n.y, rad)) continue;
|
|
463
|
+
const a = q(haze * n.op * mulOf(n.id), 0.02);
|
|
464
|
+
if (a < 0.01) continue;
|
|
465
|
+
const key = fillId(n.fill) * 64 + Math.round(a * 50);
|
|
466
|
+
let g = groups.get(key);
|
|
467
|
+
if (!g) groups.set(key, g = { c: n.fill, a, list: [] });
|
|
468
|
+
g.list.push(n);
|
|
469
|
+
}
|
|
470
|
+
for (const g of groups.values()) {
|
|
471
|
+
ctx.globalAlpha = g.a;
|
|
472
|
+
ctx.fillStyle = g.c;
|
|
473
|
+
ctx.beginPath();
|
|
474
|
+
for (const n of g.list) {
|
|
475
|
+
const rad = n.d * HAZE_R * z;
|
|
476
|
+
ctx.moveTo(n.x + rad, n.y);
|
|
477
|
+
ctx.arc(n.x, n.y, rad, 0, Math.PI * 2);
|
|
478
|
+
}
|
|
479
|
+
ctx.fill();
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
const drawEdges = (ctx, list, z, leafPx, mulOf, W, H, focus) => {
|
|
483
|
+
const near = detailed(leafPx);
|
|
484
|
+
const semA = semanticAlphaOf(opts.semanticOpacity(), semCover);
|
|
485
|
+
const focusA = focus ? focusAlphaOf(list.reduce((k, e) => k + (e.skeleton ? 0 : 1), 0)) : 0;
|
|
486
|
+
let layer = null;
|
|
487
|
+
let groups = /* @__PURE__ */ new Map();
|
|
488
|
+
const flush = () => {
|
|
489
|
+
for (const g of groups.values()) strokeGroup(ctx, g, z, near);
|
|
490
|
+
groups = /* @__PURE__ */ new Map();
|
|
491
|
+
};
|
|
492
|
+
for (const e of list) {
|
|
493
|
+
if (!e.vis || !e.src.vis || !e.tgt.vis) continue;
|
|
494
|
+
const a = e.src, b = e.tgt;
|
|
495
|
+
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;
|
|
496
|
+
if (e.z !== layer) {
|
|
497
|
+
flush();
|
|
498
|
+
layer = e.z;
|
|
499
|
+
}
|
|
500
|
+
let w, al;
|
|
501
|
+
if (e.skeleton) [w, al] = skeletonLineOf(e.w, z, e.t);
|
|
502
|
+
else [w, al] = [SEM_W * e.w / EDGE_W, focus ? focusA : semA];
|
|
503
|
+
al *= e.op * mulOf(e.id);
|
|
504
|
+
if (al < 0.01) continue;
|
|
505
|
+
const wq = q(w, 0.25) || 0.25, aq = q(al, 0.05) || 0.05;
|
|
506
|
+
const dash = e.dash === "solid" || !near ? 0 : e.dash === "dashed" ? 1 : 2;
|
|
507
|
+
const key = ((lineId(e.color) * 4096 + Math.round(wq * 4)) * 32 + Math.round(aq * 20)) * 3 + dash;
|
|
508
|
+
let g = groups.get(key);
|
|
509
|
+
if (!g) groups.set(key, g = { c: e.color, w: wq, a: aq, dash, list: [] });
|
|
510
|
+
g.list.push(e);
|
|
511
|
+
}
|
|
512
|
+
flush();
|
|
513
|
+
ctx.setLineDash([]);
|
|
514
|
+
};
|
|
515
|
+
const drawNodes = (ctx, list, mulOf, onScreen) => {
|
|
516
|
+
const groups = /* @__PURE__ */ new Map();
|
|
517
|
+
const marked = [];
|
|
518
|
+
for (const n of list) {
|
|
519
|
+
if (!n.vis || !onScreen(n.x, n.y, n.s)) continue;
|
|
520
|
+
const a = q(n.a * n.op * mulOf(n.id), 0.05);
|
|
521
|
+
if (a < 0.01) continue;
|
|
522
|
+
const gap = q(gapOf(n.s), 0.25);
|
|
523
|
+
const shapeK = n.shape === "circle" ? 0 : n.shape === "hexagon" ? 1 : n.shape === "diamond" ? 2 : 3;
|
|
524
|
+
const key = (((fillId(n.fill) * 65536 + borderId(n.border)) * 32 + Math.round(a * 20)) * 8 + gap * 4) * 4 + shapeK;
|
|
525
|
+
let g = groups.get(key);
|
|
526
|
+
if (!g) groups.set(key, g = { c: n.fill, border: n.border, a, gap, shape: n.shape, list: [] });
|
|
527
|
+
g.list.push(n);
|
|
528
|
+
if (n.bw > 1.5) marked.push(n);
|
|
529
|
+
}
|
|
530
|
+
for (const g of groups.values()) {
|
|
531
|
+
ctx.globalAlpha = g.a;
|
|
532
|
+
ctx.beginPath();
|
|
533
|
+
for (const n of g.list) tracePoint(ctx, g.shape, n.x, n.y, n.s / 2);
|
|
534
|
+
if (g.gap > 0) {
|
|
535
|
+
ctx.strokeStyle = g.border;
|
|
536
|
+
ctx.lineWidth = g.gap * 2;
|
|
537
|
+
ctx.stroke();
|
|
538
|
+
}
|
|
539
|
+
ctx.fillStyle = g.c;
|
|
540
|
+
ctx.fill();
|
|
541
|
+
}
|
|
542
|
+
for (const n of marked) {
|
|
543
|
+
ctx.globalAlpha = n.op * mulOf(n.id);
|
|
544
|
+
ctx.strokeStyle = n.border;
|
|
545
|
+
ctx.lineWidth = 2;
|
|
546
|
+
ctx.beginPath();
|
|
547
|
+
tracePoint(ctx, n.shape, n.x, n.y, n.s / 2 + gapOf(n.s) + 1.5);
|
|
548
|
+
ctx.stroke();
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
const drawSelectionBox = (ctx, z, pan) => {
|
|
552
|
+
const sel = r.selection;
|
|
553
|
+
if (!sel || sel[4] !== 1 || !(r.hoverData?.selecting || r.touchData?.selecting)) return;
|
|
554
|
+
const t = opts.theme();
|
|
555
|
+
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;
|
|
556
|
+
ctx.globalAlpha = 0.15;
|
|
557
|
+
ctx.fillStyle = t.selected;
|
|
558
|
+
ctx.fillRect(x, y, w, h);
|
|
559
|
+
ctx.globalAlpha = 0.6;
|
|
560
|
+
ctx.strokeStyle = t.selected;
|
|
561
|
+
ctx.lineWidth = 1;
|
|
562
|
+
ctx.strokeRect(x, y, w, h);
|
|
563
|
+
};
|
|
564
|
+
const find = (mx, my, interactiveOnly, isTouch) => {
|
|
565
|
+
refresh();
|
|
566
|
+
const z = cy.zoom(), pan = cy.pan();
|
|
567
|
+
const sx = mx * z + pan.x, sy = my * z + pan.y;
|
|
568
|
+
const slack = isTouch ? 10 : NODE_SLACK;
|
|
569
|
+
const leafPx = NODE_BASE * opts.nodeScale() * z;
|
|
570
|
+
const usable = (x) => x.vis && x.op > 0.05 && (!interactiveOnly || x.events) && muteOf(x.id) > 0.5;
|
|
571
|
+
let best = null, bestD = Infinity;
|
|
572
|
+
for (const n of nodes) {
|
|
573
|
+
if (!usable(n)) continue;
|
|
574
|
+
const p = n.ele.position();
|
|
575
|
+
const x = p.x * z + pan.x, y = p.y * z + pan.y;
|
|
576
|
+
const rad = dotOf(n.d, z, n.w, leafPx)[0] / 2 + slack;
|
|
577
|
+
const d = Math.hypot(sx - x, sy - y);
|
|
578
|
+
if (d <= rad && d - rad < bestD) {
|
|
579
|
+
best = n.ele;
|
|
580
|
+
bestD = d - rad;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
if (best) return [best];
|
|
584
|
+
const semReach = reachOf(semanticAlphaOf(1, semCover), SEM_W, isTouch);
|
|
585
|
+
for (const e of edges) {
|
|
586
|
+
if (!usable(e) || !e.src.vis || !e.tgt.vis) continue;
|
|
587
|
+
let reach = semReach * Math.max(1, e.w / EDGE_W);
|
|
588
|
+
if (e.skeleton) {
|
|
589
|
+
const [lw, la] = skeletonLineOf(e.w, z, e.t);
|
|
590
|
+
reach = reachOf(la, lw, isTouch);
|
|
591
|
+
}
|
|
592
|
+
const a = e.src.ele.position(), b = e.tgt.ele.position();
|
|
593
|
+
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);
|
|
594
|
+
if (hittable(reach) && d <= reach && d - reach < bestD) {
|
|
595
|
+
best = e.ele;
|
|
596
|
+
bestD = d - reach;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
if (best) return [best];
|
|
600
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
601
|
+
const n = parents[i];
|
|
602
|
+
if (!usable(n)) continue;
|
|
603
|
+
const bb = n.ele.boundingBox({ includeLabels: false, includeOverlays: false, includeUnderlays: false });
|
|
604
|
+
if (mx >= bb.x1 && mx <= bb.x2 && my >= bb.y1 && my <= bb.y2) return [n.ele];
|
|
605
|
+
}
|
|
606
|
+
return [];
|
|
607
|
+
};
|
|
608
|
+
r.render = function render(options) {
|
|
609
|
+
const active = opts.active() && !options?.forcedContext;
|
|
610
|
+
if (active !== wasActive) {
|
|
611
|
+
wasActive = active;
|
|
612
|
+
needs = true;
|
|
613
|
+
if (!active) {
|
|
614
|
+
r.redrawHint("eles", true);
|
|
615
|
+
r.redrawHint("drag", true);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
if (!active) return baseRender.call(r, options);
|
|
619
|
+
paint();
|
|
620
|
+
cy.emit("render");
|
|
621
|
+
};
|
|
622
|
+
r.findNearestElements = function findNearestElements(x, y, interactiveOnly, isTouch) {
|
|
623
|
+
if (!opts.active()) return baseFind.call(r, x, y, interactiveOnly, isTouch);
|
|
624
|
+
return find(x, y, interactiveOnly, isTouch);
|
|
625
|
+
};
|
|
626
|
+
r.redraw();
|
|
627
|
+
return {
|
|
628
|
+
hover,
|
|
629
|
+
spotlight,
|
|
630
|
+
focused: (id) => hoverTo === 1 && focusIds.has(id),
|
|
631
|
+
hoveredId: () => hoverTo === 1 ? hovered : null,
|
|
632
|
+
dimOf: (id) => (hoverT > 0 && !lifted.has(id) ? dimNow() : 1) * muteOf(id),
|
|
633
|
+
mute,
|
|
634
|
+
// 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.
|
|
635
|
+
hidden: (id) => mutedIds.has(id) && !pinned.has(id) && !(hoverTo === 1 && focusIds.has(id)),
|
|
636
|
+
radiusOf: (id) => {
|
|
637
|
+
if (!opts.active()) return null;
|
|
638
|
+
refresh();
|
|
639
|
+
const n = byId.get(id);
|
|
640
|
+
if (!n || "src" in n || n.parent) return null;
|
|
641
|
+
const z = cy.zoom();
|
|
642
|
+
return dotOf(n.d, z, n.w, NODE_BASE * opts.nodeScale() * z)[0] / 2;
|
|
643
|
+
},
|
|
644
|
+
repaint: () => {
|
|
645
|
+
needs = true;
|
|
646
|
+
r.redraw();
|
|
647
|
+
},
|
|
648
|
+
dispose: () => {
|
|
649
|
+
cy.off("style", onStyle);
|
|
650
|
+
cy.off("add remove data move", onStructure);
|
|
651
|
+
cy.off("position viewport", onMove);
|
|
652
|
+
cy.off("select unselect", onSelect);
|
|
653
|
+
if (!cy.destroyed()) {
|
|
654
|
+
r.render = baseRender;
|
|
655
|
+
r.findNearestElements = baseFind;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
var q = (v, step) => Math.round(v / step) * step;
|
|
661
|
+
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);
|
|
662
|
+
var smooth = (x) => x * x * (3 - 2 * x);
|
|
663
|
+
var controlOf = (ax, ay, bx, by, bend) => {
|
|
664
|
+
const dx = bx - ax, dy = by - ay, L = Math.hypot(dx, dy) || 1;
|
|
665
|
+
return [(ax + bx) / 2 - dy / L * bend, (ay + by) / 2 + dx / L * bend];
|
|
666
|
+
};
|
|
667
|
+
function strokeGroup(ctx, g, z, near) {
|
|
668
|
+
ctx.globalAlpha = Math.min(1, g.a);
|
|
669
|
+
ctx.strokeStyle = g.c;
|
|
670
|
+
ctx.lineWidth = g.w;
|
|
671
|
+
ctx.lineCap = "round";
|
|
672
|
+
ctx.setLineDash(g.dash === 1 ? [4, 3] : g.dash === 2 ? [1, 3] : []);
|
|
673
|
+
ctx.beginPath();
|
|
674
|
+
const heads = [];
|
|
675
|
+
for (const e of g.list) {
|
|
676
|
+
const ax = e.src.x, ay = e.src.y, bx = e.tgt.x, by = e.tgt.y;
|
|
677
|
+
ctx.moveTo(ax, ay);
|
|
678
|
+
let hx = bx - ax, hy = by - ay, tx = ax - bx, ty = ay - by;
|
|
679
|
+
if (e.bend) {
|
|
680
|
+
const [cx, cy] = controlOf(ax, ay, bx, by, e.bend * z);
|
|
681
|
+
ctx.quadraticCurveTo(cx, cy, bx, by);
|
|
682
|
+
hx = bx - cx;
|
|
683
|
+
hy = by - cy;
|
|
684
|
+
tx = ax - cx;
|
|
685
|
+
ty = ay - cy;
|
|
686
|
+
} else ctx.lineTo(bx, by);
|
|
687
|
+
const show = e.skeleton ? g.w >= 1.5 : near && Math.hypot(bx - ax, by - ay) > 40;
|
|
688
|
+
if (!show) continue;
|
|
689
|
+
if (e.head !== "none") heads.push([e, bx, by, hx, hy, true]);
|
|
690
|
+
if (e.tail !== "none") heads.push([e, ax, ay, tx, ty, false]);
|
|
691
|
+
}
|
|
692
|
+
ctx.stroke();
|
|
693
|
+
if (!heads.length) return;
|
|
694
|
+
ctx.setLineDash([]);
|
|
695
|
+
ctx.fillStyle = g.c;
|
|
696
|
+
ctx.beginPath();
|
|
697
|
+
const tees = [];
|
|
698
|
+
for (const [e, px, py, ux0, uy0, atHead] of heads) {
|
|
699
|
+
const L = Math.hypot(ux0, uy0) || 1, ux = ux0 / L, uy = uy0 / L;
|
|
700
|
+
const n = atHead ? e.tgt : e.src;
|
|
701
|
+
const rad = n.parent ? 0 : n.s / 2 + gapOf(n.s);
|
|
702
|
+
const tipX = px - ux * rad, tipY = py - uy * rad;
|
|
703
|
+
const len = e.skeleton ? g.w * 2.6 : 3 + g.w * 2.5, half = len * 0.55;
|
|
704
|
+
if ((atHead ? e.head : e.tail) === "tee") {
|
|
705
|
+
tees.push([tipX, tipY, ux, uy, half]);
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
708
|
+
ctx.moveTo(tipX, tipY);
|
|
709
|
+
ctx.lineTo(tipX - ux * len - uy * half, tipY - uy * len + ux * half);
|
|
710
|
+
ctx.lineTo(tipX - ux * len + uy * half, tipY - uy * len - ux * half);
|
|
711
|
+
ctx.closePath();
|
|
712
|
+
}
|
|
713
|
+
ctx.fill();
|
|
714
|
+
if (tees.length) {
|
|
715
|
+
ctx.beginPath();
|
|
716
|
+
for (const [x, y, ux, uy, half] of tees) {
|
|
717
|
+
const cx = x - ux * 2, cy = y - uy * 2;
|
|
718
|
+
ctx.moveTo(cx - uy * half, cy + ux * half);
|
|
719
|
+
ctx.lineTo(cx + uy * half, cy - ux * half);
|
|
720
|
+
}
|
|
721
|
+
ctx.lineWidth = Math.max(1.5, g.w);
|
|
722
|
+
ctx.stroke();
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
function tracePoint(ctx, shape, x, y, rad) {
|
|
726
|
+
if (shape === "circle") {
|
|
727
|
+
ctx.moveTo(x + rad, y);
|
|
728
|
+
ctx.arc(x, y, rad, 0, Math.PI * 2);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
if (shape === "rect") {
|
|
732
|
+
ctx.rect(x - rad, y - rad, rad * 2, rad * 2);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const n = shape === "hexagon" ? 6 : 4;
|
|
736
|
+
const off = shape === "diamond" ? -Math.PI / 2 : 0;
|
|
737
|
+
for (let i = 0; i < n; i++) {
|
|
738
|
+
const t = off + i * 2 * Math.PI / n;
|
|
739
|
+
const px = x + rad * Math.cos(t), py = y + rad * Math.sin(t);
|
|
740
|
+
if (i === 0) ctx.moveTo(px, py);
|
|
741
|
+
else ctx.lineTo(px, py);
|
|
742
|
+
}
|
|
743
|
+
ctx.closePath();
|
|
744
|
+
}
|
|
745
|
+
function distToEdge(px, py, ax, ay, bx, by, bend) {
|
|
746
|
+
if (!bend) return distToSeg(px, py, ax, ay, bx, by);
|
|
747
|
+
const [cx, cy] = controlOf(ax, ay, bx, by, bend);
|
|
748
|
+
let best = Infinity, lx = ax, ly = ay;
|
|
749
|
+
for (let i = 1; i <= 8; i++) {
|
|
750
|
+
const t = i / 8, u = 1 - t;
|
|
751
|
+
const x = u * u * ax + 2 * u * t * cx + t * t * bx, y = u * u * ay + 2 * u * t * cy + t * t * by;
|
|
752
|
+
best = Math.min(best, distToSeg(px, py, lx, ly, x, y));
|
|
753
|
+
lx = x;
|
|
754
|
+
ly = y;
|
|
755
|
+
}
|
|
756
|
+
return best;
|
|
757
|
+
}
|
|
758
|
+
function distToSeg(px, py, ax, ay, bx, by) {
|
|
759
|
+
const dx = bx - ax, dy = by - ay, L2 = dx * dx + dy * dy;
|
|
760
|
+
const t = L2 ? Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / L2)) : 0;
|
|
761
|
+
return Math.hypot(px - (ax + t * dx), py - (ay + t * dy));
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/react/EdgeMark.tsx
|
|
765
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
766
|
+
var plain = { dash: "solid", head: "none", tail: "none" };
|
|
767
|
+
var EdgeMarks = createContext2(() => ({ stroke: plain, color: "currentColor", scale: 1 }));
|
|
768
|
+
function edgeMarksFor(profile, theme, cy, mirror) {
|
|
769
|
+
const marks = /* @__PURE__ */ new Map();
|
|
770
|
+
return (kind = "") => {
|
|
771
|
+
const cached = marks.get(kind);
|
|
772
|
+
if (cached) return cached;
|
|
773
|
+
const selector = "." + edgeKindClass(kind || "plain");
|
|
774
|
+
const sample = (graph) => graph && !graph.destroyed() && graph.edges(selector)[0];
|
|
775
|
+
const edge = sample(cy) || sample(mirror());
|
|
776
|
+
const palette = profile.edgePalette[kind];
|
|
777
|
+
const mark = {
|
|
778
|
+
stroke: edge ? {
|
|
779
|
+
dash: edge.pstyle("line-style").value,
|
|
780
|
+
head: arrowOf(edge.pstyle("target-arrow-shape").value),
|
|
781
|
+
tail: arrowOf(edge.pstyle("source-arrow-shape").value)
|
|
782
|
+
} : plain,
|
|
783
|
+
color: palette ? themeColor(theme, palette) : theme.edge,
|
|
784
|
+
scale: profile.edgeWidth[kind] ?? 1
|
|
785
|
+
};
|
|
786
|
+
if (edge) marks.set(kind, mark);
|
|
787
|
+
return mark;
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
var DASH = { dashed: "4 2.5", dotted: "0.1 3" };
|
|
791
|
+
function EdgeMark({ kind, off, reverse }) {
|
|
792
|
+
const { color, stroke, scale } = useContext2(EdgeMarks)(kind);
|
|
793
|
+
const head = reverse ? stroke.tail : stroke.head, tail = reverse ? stroke.head : stroke.tail;
|
|
794
|
+
const sw = 1.8 * (1 + 0.3 * Math.log2(scale));
|
|
795
|
+
const x1 = tail === "triangle" ? 6 : 2, x2 = head === "triangle" ? 18 : 22;
|
|
796
|
+
return /* @__PURE__ */ jsxs2("svg", { "aria-hidden": "true", className: "gb-lg-mark", viewBox: "0 0 24 12", width: 24, height: 12, opacity: off ? 0.35 : 1, children: [
|
|
797
|
+
/* @__PURE__ */ jsx3(
|
|
798
|
+
"line",
|
|
799
|
+
{
|
|
800
|
+
x1,
|
|
801
|
+
y1: 6,
|
|
802
|
+
x2,
|
|
803
|
+
y2: 6,
|
|
804
|
+
stroke: color,
|
|
805
|
+
strokeWidth: sw,
|
|
806
|
+
strokeLinecap: stroke.dash === "dotted" ? "round" : void 0,
|
|
807
|
+
strokeDasharray: DASH[stroke.dash]
|
|
808
|
+
}
|
|
809
|
+
),
|
|
810
|
+
head === "triangle" && /* @__PURE__ */ jsx3("polygon", { points: "17,2.5 23,6 17,9.5", fill: color }),
|
|
811
|
+
tail === "triangle" && /* @__PURE__ */ jsx3("polygon", { points: "7,2.5 1,6 7,9.5", fill: color }),
|
|
812
|
+
head === "tee" && /* @__PURE__ */ jsx3("path", { d: "M22,2.5 V9.5", stroke: color, strokeWidth: 1.8 }),
|
|
813
|
+
tail === "tee" && /* @__PURE__ */ jsx3("path", { d: "M2,2.5 V9.5", stroke: color, strokeWidth: 1.8 })
|
|
814
|
+
] });
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// src/react/ZoomBoundary.tsx
|
|
818
|
+
import { useEffect, useRef } from "react";
|
|
819
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
820
|
+
function ZoomBoundary(props) {
|
|
821
|
+
const ref = useRef(null);
|
|
822
|
+
useEffect(() => {
|
|
823
|
+
const el = ref.current;
|
|
824
|
+
if (el.parentElement?.closest("[data-gb-zoom-boundary]")) return;
|
|
825
|
+
const controller = new AbortController();
|
|
826
|
+
const options = { passive: false, capture: true, signal: controller.signal };
|
|
827
|
+
const wheel = (e) => {
|
|
828
|
+
if (e.ctrlKey || e.metaKey) e.preventDefault();
|
|
829
|
+
};
|
|
830
|
+
const prevent = (e) => e.preventDefault();
|
|
831
|
+
el.addEventListener("wheel", wheel, options);
|
|
832
|
+
el.addEventListener("touchstart", (e) => {
|
|
833
|
+
if (e.touches.length > 1 && Array.from(e.touches).every((t) => el.contains(t.target))) e.preventDefault();
|
|
834
|
+
}, options);
|
|
835
|
+
el.addEventListener("gesturestart", prevent, options);
|
|
836
|
+
el.addEventListener("gesturechange", prevent, options);
|
|
837
|
+
return () => controller.abort();
|
|
838
|
+
}, []);
|
|
839
|
+
return /* @__PURE__ */ jsx4("div", { ...props, "data-gb-zoom-boundary": "", ref });
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// src/react/Inspector.tsx
|
|
843
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
844
|
+
function childrenOf(model, parent) {
|
|
845
|
+
return model.nodes.filter((n) => n.parent === (parent ?? void 0)).sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity));
|
|
846
|
+
}
|
|
847
|
+
function IdentityField({ mark, label, children }) {
|
|
848
|
+
return /* @__PURE__ */ jsxs3("div", { className: "gb-identity-field", title: label, "aria-label": label, children: [
|
|
849
|
+
/* @__PURE__ */ jsx5("span", { className: "gb-identity-mark", "aria-hidden": "true", children: mark }),
|
|
850
|
+
/* @__PURE__ */ jsx5("div", { children })
|
|
851
|
+
] });
|
|
852
|
+
}
|
|
853
|
+
function HeaderAction({ icon, label, hint = label, onClick }) {
|
|
854
|
+
return /* @__PURE__ */ jsxs3("button", { type: "button", className: "gb-ibtn gb-ibtn-text", title: hint, "aria-label": hint, onClick, children: [
|
|
855
|
+
/* @__PURE__ */ jsx5(Icon, { d: icon }),
|
|
856
|
+
/* @__PURE__ */ jsx5("span", { children: label })
|
|
857
|
+
] });
|
|
858
|
+
}
|
|
859
|
+
function Inspector({ title, kind, mark, status, objectId, onClose, onBack, onEdit, scopeAction, onSubmit, foot, error, children }) {
|
|
860
|
+
const t = useStrings();
|
|
861
|
+
const body = /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
862
|
+
/* @__PURE__ */ jsxs3("div", { className: "gb-dh", children: [
|
|
863
|
+
onBack && /* @__PURE__ */ jsx5("button", { type: "button", className: "gb-ibtn", "aria-label": t.back, onClick: onBack, children: "\u2039" }),
|
|
864
|
+
/* @__PURE__ */ jsxs3("div", { className: "gb-dh-title", children: [
|
|
865
|
+
kind && /* @__PURE__ */ jsxs3("div", { className: "gb-dh-meta", children: [
|
|
866
|
+
/* @__PURE__ */ jsx5(IdentityField, { mark, children: kind }),
|
|
867
|
+
objectId != null && /* @__PURE__ */ jsx5(IdentityField, { mark: /* @__PURE__ */ jsx5(Icon, { d: I.id, size: 15 }), label: t.id, children: objectId }),
|
|
868
|
+
status
|
|
869
|
+
] }),
|
|
870
|
+
/* @__PURE__ */ jsx5("div", { className: "gb-dt", children: title })
|
|
871
|
+
] }),
|
|
872
|
+
(scopeAction || onEdit) && /* @__PURE__ */ jsxs3("div", { className: "gb-dh-controls", children: [
|
|
873
|
+
scopeAction,
|
|
874
|
+
onEdit && /* @__PURE__ */ jsx5(HeaderAction, { icon: I.edit, label: t.edit, onClick: onEdit })
|
|
875
|
+
] }),
|
|
876
|
+
/* @__PURE__ */ jsx5("button", { type: "button", className: "gb-ibtn gb-dh-close", "aria-label": t.close, title: t.close, onClick: onClose, children: /* @__PURE__ */ jsx5(Icon, { d: I.x, size: 15 }) })
|
|
877
|
+
] }),
|
|
878
|
+
/* @__PURE__ */ jsx5("div", { className: "gb-db" + (onSubmit ? " gb-form" : ""), children }),
|
|
879
|
+
error && /* @__PURE__ */ jsx5("div", { className: "gb-edit-err", role: "alert", children: error }),
|
|
880
|
+
foot && /* @__PURE__ */ jsx5("div", { className: "gb-df", children: foot })
|
|
881
|
+
] });
|
|
882
|
+
return onSubmit ? /* @__PURE__ */ jsx5(
|
|
883
|
+
"form",
|
|
884
|
+
{
|
|
885
|
+
className: "gb-detail gb-edit",
|
|
886
|
+
onSubmit: (e) => {
|
|
887
|
+
e.preventDefault();
|
|
888
|
+
onSubmit();
|
|
889
|
+
},
|
|
890
|
+
onKeyDown: (e) => {
|
|
891
|
+
if (e.key === "Escape" && !e.defaultPrevented) onClose();
|
|
892
|
+
},
|
|
893
|
+
children: body
|
|
894
|
+
}
|
|
895
|
+
) : /* @__PURE__ */ jsx5(ZoomBoundary, { className: "gb-detail", children: body });
|
|
896
|
+
}
|
|
897
|
+
function NodeRef({ id, model, colorOf, sub, onPick }) {
|
|
898
|
+
const name = model?.index.get(id)?.label ?? id;
|
|
899
|
+
return /* @__PURE__ */ jsx5(
|
|
900
|
+
ObjectRef,
|
|
901
|
+
{
|
|
902
|
+
mark: /* @__PURE__ */ jsx5(NodeDot, { color: colorOf(id) }),
|
|
903
|
+
name,
|
|
904
|
+
sub,
|
|
905
|
+
title: name,
|
|
906
|
+
onPick: onPick && model?.index.has(id) ? () => onPick({ node: id }) : void 0
|
|
907
|
+
}
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
function edgeName(edge, labels, fallback) {
|
|
911
|
+
return edge.label || typeof edge.data?.name === "string" && edge.data.name || edge.kind && (labels?.[edge.kind] ?? edge.kind) || fallback;
|
|
912
|
+
}
|
|
913
|
+
function DiffValue({ old, now, block }) {
|
|
914
|
+
const t = useStrings();
|
|
915
|
+
return /* @__PURE__ */ jsxs3("div", { className: "gb-value-diff" + (block ? " is-block" : ""), children: [
|
|
916
|
+
old != null && /* @__PURE__ */ jsx5("del", { className: "gb-was", "aria-label": t.past, children: old }),
|
|
917
|
+
now != null && /* @__PURE__ */ jsx5("ins", { className: "gb-now", "aria-label": t.now, children: now })
|
|
918
|
+
] });
|
|
919
|
+
}
|
|
920
|
+
function InspectorField({ label, htmlFor, children }) {
|
|
921
|
+
return /* @__PURE__ */ jsxs3("div", { className: "gb-core-field", children: [
|
|
922
|
+
label && (htmlFor ? /* @__PURE__ */ jsx5("label", { className: "gb-k", htmlFor, children: label }) : /* @__PURE__ */ jsx5("span", { className: "gb-k", children: label })),
|
|
923
|
+
children
|
|
924
|
+
] });
|
|
925
|
+
}
|
|
926
|
+
function pairItems(before, after, key) {
|
|
927
|
+
const previous = new Map(before.map((item) => [key(item), item]));
|
|
928
|
+
const pairs = after.map((now) => {
|
|
929
|
+
const k = key(now), old = previous.get(k);
|
|
930
|
+
previous.delete(k);
|
|
931
|
+
return { key: k, old, now };
|
|
932
|
+
});
|
|
933
|
+
for (const [key2, old] of previous) pairs.push({ key: key2, old, now: void 0 });
|
|
934
|
+
return pairs;
|
|
935
|
+
}
|
|
936
|
+
function RelationList({ title, items, previous, keyOf, changed, render, columns, add }) {
|
|
937
|
+
const t = useStrings();
|
|
938
|
+
const [expanded, setExpanded] = useState(false);
|
|
939
|
+
let rows = pairItems(previous ?? [], items, keyOf);
|
|
940
|
+
if (!rows.length && !add) return null;
|
|
941
|
+
const limit = columns ? 4 : 2;
|
|
942
|
+
if (previous) {
|
|
943
|
+
const changes = [], rest = [];
|
|
944
|
+
for (const r of rows) (!r.old || !r.now || changed(r.old, r.now) ? changes : rest).push(r);
|
|
945
|
+
rows = changes.concat(rest);
|
|
946
|
+
}
|
|
947
|
+
return /* @__PURE__ */ jsxs3("section", { className: "gb-rel-section", "aria-label": title, children: [
|
|
948
|
+
/* @__PURE__ */ jsxs3("div", { className: "gb-list-head", children: [
|
|
949
|
+
/* @__PURE__ */ jsx5("span", { className: "gb-k", children: title }),
|
|
950
|
+
previous && previous.length !== items.length ? /* @__PURE__ */ jsx5(DiffValue, { old: previous.length, now: items.length }) : /* @__PURE__ */ jsx5("span", { children: items.length }),
|
|
951
|
+
add && /* @__PURE__ */ jsx5("button", { type: "button", className: "gb-ibtn gb-list-add", "aria-label": title + " +", onClick: add, children: /* @__PURE__ */ jsx5(Icon, { d: I.plus, size: 14 }) })
|
|
952
|
+
] }),
|
|
953
|
+
!!rows.length && /* @__PURE__ */ jsx5("ul", { className: "gb-rel" + (columns ? " gb-children" : ""), children: (expanded ? rows : rows.slice(0, limit)).map((r) => /* @__PURE__ */ jsx5("li", { children: render(r.old, r.now) }, r.key)) }),
|
|
954
|
+
rows.length > limit && /* @__PURE__ */ jsx5("button", { type: "button", className: "gb-link gb-more", "aria-expanded": expanded, onClick: () => setExpanded(!expanded), children: expanded ? t.showLess : t.moreItems(rows.length - limit) })
|
|
955
|
+
] });
|
|
956
|
+
}
|
|
957
|
+
function NodeRelations({ id, current, previous, kindLabels, movedChild, ignore = /* @__PURE__ */ new Set(), onAdd, onEditEdge }) {
|
|
958
|
+
const t = useStrings();
|
|
959
|
+
const ref = (side, id2) => /* @__PURE__ */ jsx5(NodeRef, { id: id2, ...side });
|
|
960
|
+
const name = (e) => edgeName(e, kindLabels, t.edge);
|
|
961
|
+
function cell(old, now, differs, body) {
|
|
962
|
+
if (previous && (!old || !now || differs)) return /* @__PURE__ */ jsx5(DiffValue, { old: old && body(previous, old), now: now && body(current, now) });
|
|
963
|
+
return body(current, now);
|
|
964
|
+
}
|
|
965
|
+
return /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
966
|
+
/* @__PURE__ */ jsx5(
|
|
967
|
+
RelationList,
|
|
968
|
+
{
|
|
969
|
+
title: t.legendContainsName,
|
|
970
|
+
columns: true,
|
|
971
|
+
items: current.children,
|
|
972
|
+
previous: previous?.children,
|
|
973
|
+
keyOf: (n) => n.id,
|
|
974
|
+
changed: (a, b) => a.label !== b.label || !!movedChild?.(b.id),
|
|
975
|
+
add: onAdd && (() => onAdd("child")),
|
|
976
|
+
render: (old, now) => /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
977
|
+
cell(old, now, old?.label !== now?.label, (side, n) => ref(side, n.id)),
|
|
978
|
+
old && now && movedChild?.(now.id) && /* @__PURE__ */ jsx5(DiffValue, { old: old.order, now: now.order })
|
|
979
|
+
] })
|
|
980
|
+
}
|
|
981
|
+
),
|
|
982
|
+
["in", "out"].map((direction) => {
|
|
983
|
+
const incoming = direction === "in";
|
|
984
|
+
const relation = ({ onPick }, edge) => /* @__PURE__ */ jsx5(ObjectRef, { mark: /* @__PURE__ */ jsx5(EdgeMark, { kind: edge.kind, reverse: incoming }), name: name(edge), onPick: onPick && (() => onPick({ edge })) });
|
|
985
|
+
const end = (e) => incoming ? e.source : e.target;
|
|
986
|
+
const belongs = (e) => (incoming ? e.target : e.source) === id;
|
|
987
|
+
const peer = (side, e) => side.model.index.get(end(e))?.label ?? end(e);
|
|
988
|
+
return /* @__PURE__ */ jsx5(
|
|
989
|
+
RelationList,
|
|
990
|
+
{
|
|
991
|
+
title: incoming ? t.inEdges : t.outEdges,
|
|
992
|
+
items: current.edges.filter(belongs),
|
|
993
|
+
previous: previous?.edges.filter(belongs),
|
|
994
|
+
keyOf: edgeKey,
|
|
995
|
+
changed: (a, b) => edgeContentChanged(a, b, ignore) || peer(previous, a) !== peer(current, b),
|
|
996
|
+
add: onAdd && (() => onAdd(direction)),
|
|
997
|
+
render: (old, now) => {
|
|
998
|
+
if (onEditEdge && now) return /* @__PURE__ */ jsxs3("button", { type: "button", className: "gb-input gb-edge-row", onClick: () => onEditEdge(now), children: [
|
|
999
|
+
relation(current, now),
|
|
1000
|
+
ref(current, end(now))
|
|
1001
|
+
] });
|
|
1002
|
+
return /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
1003
|
+
/* @__PURE__ */ jsxs3("div", { children: [
|
|
1004
|
+
cell(old, now, !!(old && now && name(old) !== name(now)), relation),
|
|
1005
|
+
old && now && name(old) === name(now) && edgeContentChanged(old, now, ignore) && /* @__PURE__ */ jsx5("small", { className: "gb-change", children: t.change.changed })
|
|
1006
|
+
] }),
|
|
1007
|
+
/* @__PURE__ */ jsx5("div", { className: "gb-peer", children: cell(old, now, !!(old && now && peer(previous, old) !== peer(current, now)), (side, e) => ref(side, end(e))) })
|
|
1008
|
+
] });
|
|
1009
|
+
}
|
|
1010
|
+
},
|
|
1011
|
+
direction
|
|
1012
|
+
);
|
|
1013
|
+
})
|
|
1014
|
+
] });
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// src/react/markdown.tsx
|
|
1018
|
+
import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1019
|
+
var ABS = /^(https?:|mailto:)/i;
|
|
1020
|
+
var SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
1021
|
+
function href(url, o) {
|
|
1022
|
+
const u = url.trim();
|
|
1023
|
+
if (u.startsWith("node:")) return { kind: "node", url: u.slice(5) };
|
|
1024
|
+
if (ABS.test(u)) return { kind: "ext", url: u };
|
|
1025
|
+
if (SCHEME.test(u) || u.startsWith("//")) return null;
|
|
1026
|
+
const r = o.resolveUrl?.(u);
|
|
1027
|
+
return r && ABS.test(r) ? { kind: "ext", url: r } : null;
|
|
1028
|
+
}
|
|
1029
|
+
var INLINE = /\\(?<escaped>[!-/:-@\[-`{-~])|!\[(?<alt>[^\]]*)\]\((?<image>[^)\s]+)(?:\s+"[^"]*")?\)|\[(?<label>[^\]]+)\]\((?<link>[^)\s]+)(?:\s+"[^"]*")?\)|(?<!`)(?<ticks>`+)(?!`)(?<code>[\s\S]*?)(?<!`)\k<ticks>(?!`)|\*\*(?<bold>(?:\\.|[^*\\])+)\*\*|__(?<strong>[^_]+)__|\*(?<italic>[^*\s][^*]*)\*|_(?<em>[^_\s][^_]*)_/g;
|
|
1030
|
+
function inline(text, o, key) {
|
|
1031
|
+
const out = [];
|
|
1032
|
+
let last = 0, i = 0;
|
|
1033
|
+
for (const m of text.matchAll(INLINE)) {
|
|
1034
|
+
if (m.index > last) out.push(text.slice(last, m.index));
|
|
1035
|
+
const k = `${key}.${i++}`;
|
|
1036
|
+
const token = m.groups;
|
|
1037
|
+
if (token.escaped !== void 0) out.push(token.escaped);
|
|
1038
|
+
else if (token.image !== void 0) {
|
|
1039
|
+
const h = href(token.image, o);
|
|
1040
|
+
if (h?.kind === "ext") {
|
|
1041
|
+
out.push(/* @__PURE__ */ jsx6(
|
|
1042
|
+
"img",
|
|
1043
|
+
{
|
|
1044
|
+
className: "gb-md-img",
|
|
1045
|
+
src: h.url,
|
|
1046
|
+
alt: token.alt,
|
|
1047
|
+
loading: "lazy",
|
|
1048
|
+
onError: (e) => {
|
|
1049
|
+
e.currentTarget.style.display = "none";
|
|
1050
|
+
}
|
|
1051
|
+
},
|
|
1052
|
+
k
|
|
1053
|
+
));
|
|
1054
|
+
} else if (token.alt) out.push(/* @__PURE__ */ jsx6("span", { className: "gb-md-alt", children: token.alt }, k));
|
|
1055
|
+
} else if (token.link !== void 0) {
|
|
1056
|
+
const h = href(token.link, o);
|
|
1057
|
+
const label = inline(token.label, o, k);
|
|
1058
|
+
if (h?.kind === "ext") out.push(/* @__PURE__ */ jsx6("a", { href: h.url, target: "_blank", rel: "noreferrer noopener", children: label }, k));
|
|
1059
|
+
else if (h?.kind === "node" && o.onNodeLink) {
|
|
1060
|
+
const id = h.url;
|
|
1061
|
+
out.push(/* @__PURE__ */ jsx6("a", { href: "#", className: "gb-md-node", onClick: (e) => {
|
|
1062
|
+
e.preventDefault();
|
|
1063
|
+
o.onNodeLink(id);
|
|
1064
|
+
}, children: label }, k));
|
|
1065
|
+
} else out.push(/* @__PURE__ */ jsx6("span", { children: label }, k));
|
|
1066
|
+
} else if (token.code !== void 0) {
|
|
1067
|
+
const value = token.code;
|
|
1068
|
+
out.push(/* @__PURE__ */ jsx6("code", { children: /^ .* $/.test(value) && /[^ ]/.test(value) ? value.slice(1, -1) : value }, k));
|
|
1069
|
+
} else if (token.bold !== void 0 || token.strong !== void 0) out.push(/* @__PURE__ */ jsx6("strong", { children: inline(token.bold ?? token.strong, o, k) }, k));
|
|
1070
|
+
else out.push(/* @__PURE__ */ jsx6("em", { children: inline(token.italic ?? token.em, o, k) }, k));
|
|
1071
|
+
last = m.index + m[0].length;
|
|
1072
|
+
}
|
|
1073
|
+
if (last < text.length) out.push(text.slice(last));
|
|
1074
|
+
return out;
|
|
1075
|
+
}
|
|
1076
|
+
function renderMarkdown(src, o = {}) {
|
|
1077
|
+
const lines = src.replace(/\r\n?/g, "\n").split("\n");
|
|
1078
|
+
return /* @__PURE__ */ jsx6("div", { className: "gb-md", children: renderBlocks(lines, o) });
|
|
1079
|
+
}
|
|
1080
|
+
function renderBlocks(lines, o) {
|
|
1081
|
+
const blocks = [];
|
|
1082
|
+
let para = [];
|
|
1083
|
+
let list = null;
|
|
1084
|
+
let n = 0;
|
|
1085
|
+
const flushPara = () => {
|
|
1086
|
+
if (para.length) blocks.push(/* @__PURE__ */ jsx6("p", { children: inline(para.join(" "), o, `p${n}`) }, n++));
|
|
1087
|
+
para = [];
|
|
1088
|
+
};
|
|
1089
|
+
const flushList = () => {
|
|
1090
|
+
if (!list) return;
|
|
1091
|
+
const items = list.items.map((it, j) => /* @__PURE__ */ jsxs4("li", { children: [
|
|
1092
|
+
inline(it.label, o, `l${n}.${j}`),
|
|
1093
|
+
renderBlocks(it.body, o)
|
|
1094
|
+
] }, j));
|
|
1095
|
+
blocks.push(list.ordered ? /* @__PURE__ */ jsx6("ol", { children: items }, n++) : /* @__PURE__ */ jsx6("ul", { children: items }, n++));
|
|
1096
|
+
list = null;
|
|
1097
|
+
};
|
|
1098
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1099
|
+
const line = lines[i];
|
|
1100
|
+
const t = line.trim();
|
|
1101
|
+
if (list && (!t || line.startsWith(" ".repeat(list.indent)))) {
|
|
1102
|
+
list.items[list.items.length - 1].body.push(line.slice(list.indent));
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
const fence = /^(`{3,})([^`]*)$/.exec(t);
|
|
1106
|
+
if (fence) {
|
|
1107
|
+
flushPara();
|
|
1108
|
+
flushList();
|
|
1109
|
+
const body = [];
|
|
1110
|
+
const closing = new RegExp("^\\s{0,3}`{" + fence[1].length + ",}\\s*$");
|
|
1111
|
+
for (i++; i < lines.length && !closing.test(lines[i]); i++) body.push(lines[i]);
|
|
1112
|
+
blocks.push(/* @__PURE__ */ jsx6("pre", { children: /* @__PURE__ */ jsx6("code", { children: body.join("\n") }) }, n++));
|
|
1113
|
+
continue;
|
|
1114
|
+
}
|
|
1115
|
+
if (!t) {
|
|
1116
|
+
flushPara();
|
|
1117
|
+
flushList();
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
const h = /^(#{1,6})\s+(.*)$/.exec(t);
|
|
1121
|
+
if (h) {
|
|
1122
|
+
flushPara();
|
|
1123
|
+
flushList();
|
|
1124
|
+
blocks.push(/* @__PURE__ */ jsx6("div", { role: "heading", "aria-level": h[1].length, className: `gb-md-h gb-md-h${Math.min(h[1].length, 3)}`, children: inline(h[2], o, `h${n}`) }, n++));
|
|
1125
|
+
continue;
|
|
1126
|
+
}
|
|
1127
|
+
const li = /^([-*+]|\d+[.)])\s+(.*)$/.exec(t);
|
|
1128
|
+
if (li) {
|
|
1129
|
+
flushPara();
|
|
1130
|
+
const ordered = /\d/.test(li[1]);
|
|
1131
|
+
if (list && list.ordered !== ordered) flushList();
|
|
1132
|
+
const indent = line.length - line.trimStart().length + li[0].length - li[2].length;
|
|
1133
|
+
if (!list) list = { ordered, indent, items: [] };
|
|
1134
|
+
else list.indent = indent;
|
|
1135
|
+
list.items.push({ label: li[2], body: [] });
|
|
1136
|
+
continue;
|
|
1137
|
+
}
|
|
1138
|
+
if (t.startsWith(">")) {
|
|
1139
|
+
flushPara();
|
|
1140
|
+
flushList();
|
|
1141
|
+
blocks.push(/* @__PURE__ */ jsx6("blockquote", { children: inline(t.replace(/^>\s?/, ""), o, `q${n}`) }, n++));
|
|
1142
|
+
continue;
|
|
1143
|
+
}
|
|
1144
|
+
flushList();
|
|
1145
|
+
para.push(t);
|
|
1146
|
+
}
|
|
1147
|
+
flushPara();
|
|
1148
|
+
flushList();
|
|
1149
|
+
return blocks;
|
|
1150
|
+
}
|
|
1151
|
+
function renderInline(src, o = {}) {
|
|
1152
|
+
return /* @__PURE__ */ jsx6(Fragment3, { children: inline(src, o, "i") });
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// src/react/DetailPanel.tsx
|
|
1156
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1157
|
+
function inspect(model, target, originalNode) {
|
|
1158
|
+
if (!target) return void 0;
|
|
1159
|
+
const node = "node" in target ? model.index.get(target.node) : void 0;
|
|
1160
|
+
const edge = "edge" in target ? model.edges.find((e) => sameEdge(e, target.edge)) : void 0;
|
|
1161
|
+
if (!node && !edge) return void 0;
|
|
1162
|
+
const children = node ? childrenOf(model, node.id) : [];
|
|
1163
|
+
return { model, node, originalNode: originalNode ?? node, edge, children, edges: node ? edgesOf(model, node.id) : [] };
|
|
1164
|
+
}
|
|
1165
|
+
function ObjectDetails({ before, after, delta, spec, kindLabels, onClose, onEdit, scope, membership, onBack, renderText, markdownFor, onPick, colorOf, nodeClass }) {
|
|
1166
|
+
const t = useStrings();
|
|
1167
|
+
const subject = after ?? before;
|
|
1168
|
+
if (!subject) return null;
|
|
1169
|
+
const { node, edge } = subject;
|
|
1170
|
+
const both = !!(before && after);
|
|
1171
|
+
const ignore = new Set(delta?.ignore);
|
|
1172
|
+
const change = node && delta?.byId.get(node.id);
|
|
1173
|
+
const links = (side) => ({
|
|
1174
|
+
model: side.model,
|
|
1175
|
+
colorOf: (id2) => colorOf(id2, side === before),
|
|
1176
|
+
onPick: onPick && ((item) => onPick({ ...item, past: side === before }))
|
|
1177
|
+
});
|
|
1178
|
+
const link = (side, id2) => /* @__PURE__ */ jsx7(NodeRef, { id: id2, ...links(side) });
|
|
1179
|
+
const fields = (side) => {
|
|
1180
|
+
if (!side) return [];
|
|
1181
|
+
const { node: n, edge: e, model } = side;
|
|
1182
|
+
const data = n?.data ?? (e ? edgeContent(e) : {});
|
|
1183
|
+
const rows = /* @__PURE__ */ new Map();
|
|
1184
|
+
let content = false;
|
|
1185
|
+
const add = (key, label, raw, body, block = false) => {
|
|
1186
|
+
if (raw === void 0) return;
|
|
1187
|
+
const fieldKey = content ? "data:" + key : key;
|
|
1188
|
+
rows.set(fieldKey, { key: fieldKey, label, raw, body: body ?? (raw === "" ? "\u201C\u201D" : typeof raw === "object" ? JSON.stringify(raw, null, 2) : String(raw)), block });
|
|
1189
|
+
};
|
|
1190
|
+
if (n) {
|
|
1191
|
+
add("@parent", t.parent, n.parent ?? null, n.parent ? link(side, n.parent) : t.noParent);
|
|
1192
|
+
if ((!n.parent || model.index.get(n.parent)?.data?.unordered !== true) && n.order != null) add("@position", t.position, n.order);
|
|
1193
|
+
}
|
|
1194
|
+
if (e) {
|
|
1195
|
+
add("@source", t.source, e.source, link(side, e.source));
|
|
1196
|
+
add("@target", t.target, e.target, link(side, e.target));
|
|
1197
|
+
}
|
|
1198
|
+
content = true;
|
|
1199
|
+
const md = markdownFor?.(side);
|
|
1200
|
+
const skip = /* @__PURE__ */ new Set(["id", "kind", "label", ...n ? ["parent", "order", "children", "layer", "flags"] : [], ...spec.skip ?? []]);
|
|
1201
|
+
if (data.name === n?.label || data.name === e?.label || e && !e.label) skip.add("name");
|
|
1202
|
+
for (const { key, label } of spec.line ?? []) {
|
|
1203
|
+
add(key, label, data[key]);
|
|
1204
|
+
skip.add(key);
|
|
1205
|
+
}
|
|
1206
|
+
if (typeof data.description === "string" && data.description) {
|
|
1207
|
+
add("description", "", data.description, renderText ? renderText(data.description) : renderMarkdown(data.description, md), true);
|
|
1208
|
+
skip.add("description");
|
|
1209
|
+
}
|
|
1210
|
+
for (const { key, label } of spec.list ?? []) {
|
|
1211
|
+
const list = data[key];
|
|
1212
|
+
if (Array.isArray(list) && list.length) add(key, label, list, /* @__PURE__ */ jsx7("ul", { children: list.map((v, i) => {
|
|
1213
|
+
const text = spec.linkify?.(key, String(v)) ?? String(v);
|
|
1214
|
+
return /* @__PURE__ */ jsx7("li", { children: renderText ? renderText(text) : renderInline(text, md) }, i);
|
|
1215
|
+
}) }), true);
|
|
1216
|
+
skip.add(key);
|
|
1217
|
+
}
|
|
1218
|
+
for (const [key, value] of Object.entries(data)) if (!skip.has(key)) add(key, key, value);
|
|
1219
|
+
if (side.originalNode && spec.flagNotes) {
|
|
1220
|
+
const flags = /* @__PURE__ */ new Set([...side.originalNode.flags ?? [], ...(nodeClass?.(side.originalNode) ?? "").split(/\s+/)]);
|
|
1221
|
+
for (const flag of flags) if (spec.flagNotes[flag]) add("@flag:" + flag, "", spec.flagNotes[flag]);
|
|
1222
|
+
}
|
|
1223
|
+
if (data.flags && !spec.skip?.includes("flags") && (!spec.flagNotes || Array.isArray(data.flags) && data.flags.some((f) => !spec.flagNotes?.[String(f)])))
|
|
1224
|
+
add("flags", "flags", data.flags);
|
|
1225
|
+
return [...rows.values()];
|
|
1226
|
+
};
|
|
1227
|
+
const name = (s) => s.node?.label ?? edgeName(s.edge, kindLabels, t.edge);
|
|
1228
|
+
const kind = (s) => {
|
|
1229
|
+
const k = s.node?.kind ?? s.edge?.kind;
|
|
1230
|
+
if (s.edge && (!k || name(s) === (kindLabels[k] ?? k))) return t.edge;
|
|
1231
|
+
return k && (kindLabels[k] ?? k) || (s.node ? t.node : t.edge);
|
|
1232
|
+
};
|
|
1233
|
+
const paired = pairItems(fields(before), fields(after), (f) => f.key);
|
|
1234
|
+
const movedChild = (id2) => delta?.byId.get(id2)?.fields?.includes("position") ?? false;
|
|
1235
|
+
const status = delta && (!before ? "added" : !after ? change?.kind ?? "removed" : change?.kind ?? (before.edge && after.edge && edgeContentChanged(before.edge, after.edge, ignore) ? "changed" : void 0));
|
|
1236
|
+
const renderField = ({ key, old, now }) => {
|
|
1237
|
+
const ignored = key.startsWith("data:") && ignore.has(key.slice(5));
|
|
1238
|
+
if (both && !now && ignored) return null;
|
|
1239
|
+
const field = now ?? old;
|
|
1240
|
+
const compare = both && !ignored && (key !== "@position" || change?.fields?.includes("position") || change?.kind === "moved");
|
|
1241
|
+
const changed = compare && (!old || !now || stable(old.raw, ignore) !== stable(now.raw, ignore));
|
|
1242
|
+
const body = changed ? /* @__PURE__ */ jsx7(DiffValue, { old: old?.body, now: now?.body, block: field.block }) : /* @__PURE__ */ jsx7("div", { className: "gb-value", children: field.body });
|
|
1243
|
+
return /* @__PURE__ */ jsx7(InspectorField, { label: field.label, children: body }, key);
|
|
1244
|
+
};
|
|
1245
|
+
const id = (s) => s?.originalNode?.id ?? s?.edge?.id;
|
|
1246
|
+
const objectId = both && !ignore.has("id") && id(before) !== id(after) ? /* @__PURE__ */ jsx7(DiffValue, { old: id(before), now: id(after) }) : id(subject);
|
|
1247
|
+
const atRoot = !!node && node.id === scope?.subtree;
|
|
1248
|
+
const scopeAction = scope && node && (atRoot || !!before?.children.length || !!after?.children.length) ? /* @__PURE__ */ jsx7(
|
|
1249
|
+
HeaderAction,
|
|
1250
|
+
{
|
|
1251
|
+
icon: atRoot ? I.exit : I.enter,
|
|
1252
|
+
label: atRoot ? t.exitScopeLabel : t.viewSubtree,
|
|
1253
|
+
hint: atRoot ? t.exitScope : t.viewSubtreeTip,
|
|
1254
|
+
onClick: () => scope.change(atRoot ? null : node.id)
|
|
1255
|
+
}
|
|
1256
|
+
) : void 0;
|
|
1257
|
+
return /* @__PURE__ */ jsxs5(
|
|
1258
|
+
Inspector,
|
|
1259
|
+
{
|
|
1260
|
+
...{ onClose, onEdit, scopeAction, onBack, objectId },
|
|
1261
|
+
title: before && after && name(before) !== name(after) ? /* @__PURE__ */ jsx7(DiffValue, { old: name(before), now: name(after) }) : name(subject),
|
|
1262
|
+
mark: node ? /* @__PURE__ */ jsx7(NodeDot, { color: colorOf(node.id, !after) }) : /* @__PURE__ */ jsx7(EdgeMark, { kind: edge?.kind }),
|
|
1263
|
+
kind: before && after && kind(before) !== kind(after) ? /* @__PURE__ */ jsx7(DiffValue, { old: kind(before), now: kind(after) }) : kind(subject),
|
|
1264
|
+
status: status && /* @__PURE__ */ jsx7("span", { className: "gb-change", children: membership ?? t.change[status] }),
|
|
1265
|
+
children: [
|
|
1266
|
+
/* @__PURE__ */ jsx7("div", { className: "gb-field-pair", children: paired.filter((p) => p.key.startsWith("@")).map(renderField) }),
|
|
1267
|
+
change?.kind === "merged" && change.pairId && /* @__PURE__ */ jsxs5("div", { className: "gb-line", children: [
|
|
1268
|
+
/* @__PURE__ */ jsx7("span", { className: "gb-k", children: t.change.merged }),
|
|
1269
|
+
/* @__PURE__ */ jsx7("button", { type: "button", className: "gb-link", onClick: () => onPick?.({ node: change.pairId }), children: delta?.after.index.get(change.pairId)?.label })
|
|
1270
|
+
] }),
|
|
1271
|
+
node && /* @__PURE__ */ jsx7(
|
|
1272
|
+
NodeRelations,
|
|
1273
|
+
{
|
|
1274
|
+
id: node.id,
|
|
1275
|
+
current: { ...subject, ...links(subject) },
|
|
1276
|
+
previous: both ? { ...before, ...links(before) } : void 0,
|
|
1277
|
+
...{ kindLabels, movedChild, ignore }
|
|
1278
|
+
}
|
|
1279
|
+
),
|
|
1280
|
+
paired.filter((p) => !p.key.startsWith("@")).map(renderField),
|
|
1281
|
+
!paired.some((p) => !p.key.startsWith("@")) && !subject.children.length && !subject.edges.length && !node?.parent && !edge && /* @__PURE__ */ jsx7("div", { className: "gb-dempty", children: t.noDetails })
|
|
1282
|
+
]
|
|
1283
|
+
}
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
function DetailPanel({ node, color, markdown, ...props }) {
|
|
1287
|
+
const n = { ...node, origin: node.origin ?? void 0, data: node.detail ?? void 0 };
|
|
1288
|
+
const model = buildModel([n], []);
|
|
1289
|
+
return /* @__PURE__ */ jsx7(ObjectDetails, { ...props, after: inspect(model, { node: n.id }), colorOf: () => color, markdownFor: () => markdown ?? {} });
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
export {
|
|
1293
|
+
MIN_DOT,
|
|
1294
|
+
MIN_LINE,
|
|
1295
|
+
HOLD_LEAF,
|
|
1296
|
+
NODE_SLACK,
|
|
1297
|
+
SKEL_FLOOR,
|
|
1298
|
+
SEM_W,
|
|
1299
|
+
SEM_INK,
|
|
1300
|
+
SEM_BOOST,
|
|
1301
|
+
FOCUS_INK,
|
|
1302
|
+
focusAlphaOf,
|
|
1303
|
+
DETAIL_LEAF,
|
|
1304
|
+
GAP,
|
|
1305
|
+
HOVER_DIM,
|
|
1306
|
+
dotOf,
|
|
1307
|
+
gapOf,
|
|
1308
|
+
skeletonLineOf,
|
|
1309
|
+
semanticAlphaOf,
|
|
1310
|
+
clippedLength,
|
|
1311
|
+
hazeOf,
|
|
1312
|
+
EDGE_REACH,
|
|
1313
|
+
reachOf,
|
|
1314
|
+
hittable,
|
|
1315
|
+
detailed,
|
|
1316
|
+
edgeKindHidden,
|
|
1317
|
+
shapeOf,
|
|
1318
|
+
arrowOf,
|
|
1319
|
+
installPainter,
|
|
1320
|
+
NodeDot,
|
|
1321
|
+
ObjectRef,
|
|
1322
|
+
renderMarkdown,
|
|
1323
|
+
renderInline,
|
|
1324
|
+
StringsContext,
|
|
1325
|
+
useStrings,
|
|
1326
|
+
Icon,
|
|
1327
|
+
I,
|
|
1328
|
+
ZoomBoundary,
|
|
1329
|
+
EdgeMarks,
|
|
1330
|
+
edgeMarksFor,
|
|
1331
|
+
EdgeMark,
|
|
1332
|
+
childrenOf,
|
|
1333
|
+
Inspector,
|
|
1334
|
+
NodeRef,
|
|
1335
|
+
InspectorField,
|
|
1336
|
+
NodeRelations,
|
|
1337
|
+
inspect,
|
|
1338
|
+
ObjectDetails,
|
|
1339
|
+
DetailPanel
|
|
1340
|
+
};
|