libpetri 1.8.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/dist/{chunk-B2D5DMTO.js → chunk-B2CV5M3L.js} +228 -9
- package/dist/chunk-B2CV5M3L.js.map +1 -0
- package/dist/chunk-H62Z76FY.js +1346 -0
- package/dist/chunk-H62Z76FY.js.map +1 -0
- package/dist/chunk-RNWTYK5B.js +419 -0
- package/dist/chunk-RNWTYK5B.js.map +1 -0
- package/dist/chunk-SXK2Z45Z.js +50 -0
- package/dist/chunk-SXK2Z45Z.js.map +1 -0
- package/dist/debug/index.d.ts +50 -3
- package/dist/debug/index.js +64 -6
- package/dist/debug/index.js.map +1 -1
- package/dist/doclet/index.d.ts +152 -31
- package/dist/doclet/index.js +458 -57
- package/dist/doclet/index.js.map +1 -1
- package/dist/doclet/resources/petrinet-diagrams.css +640 -7
- package/dist/doclet/resources/petrinet-diagrams.js +7238 -114
- package/dist/dot-exporter-WJMCJEFK.js +8 -0
- package/dist/{event-store-BnyHh3TF.d.ts → event-store-2zkXeQkd.d.ts} +1 -1
- package/dist/export/index.d.ts +18 -4
- package/dist/export/index.js +1 -1
- package/dist/index.d.ts +41 -5
- package/dist/index.js +1221 -35
- package/dist/index.js.map +1 -1
- package/dist/petri-net-BDrj4XZE.d.ts +1461 -0
- package/dist/render-QK57X4TP.js +73 -0
- package/dist/render-QK57X4TP.js.map +1 -0
- package/dist/verification/index.d.ts +3 -144
- package/dist/verification/index.js +30 -1214
- package/dist/verification/index.js.map +1 -1
- package/dist/viewer/index.d.ts +227 -0
- package/dist/viewer/index.js +877 -0
- package/dist/viewer/index.js.map +1 -0
- package/dist/viewer/layout/index.d.ts +200 -0
- package/dist/viewer/layout/index.js +15 -0
- package/dist/viewer/layout/index.js.map +1 -0
- package/dist/viewer/viewer-static.iife.js +3 -0
- package/dist/viewer/viewer.css +759 -0
- package/dist/viewer/viewer.iife.js +7243 -0
- package/package.json +28 -8
- package/dist/chunk-B2D5DMTO.js.map +0 -1
- package/dist/chunk-VQ4XMJTD.js +0 -107
- package/dist/chunk-VQ4XMJTD.js.map +0 -1
- package/dist/dot-exporter-3CVCH6J4.js +0 -8
- package/dist/petri-net-D-GN9g_D.d.ts +0 -570
- /package/dist/{dot-exporter-3CVCH6J4.js.map → dot-exporter-WJMCJEFK.js.map} +0 -0
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
// src/viewer/pan-zoom.ts
|
|
2
|
+
import panzoom from "panzoom";
|
|
3
|
+
var DEFAULT_PANZOOM_OPTS = {
|
|
4
|
+
smoothScroll: false,
|
|
5
|
+
zoomDoubleClickSpeed: 1,
|
|
6
|
+
maxZoom: 1e3,
|
|
7
|
+
minZoom: 0.02
|
|
8
|
+
};
|
|
9
|
+
function attachPanzoom(svg, options, previous) {
|
|
10
|
+
if (previous) {
|
|
11
|
+
try {
|
|
12
|
+
previous.dispose();
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const opts = { ...DEFAULT_PANZOOM_OPTS, ...options };
|
|
17
|
+
return panzoom(svg, opts);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/viewer/cluster-overlay.ts
|
|
21
|
+
function discoverClusters(svg) {
|
|
22
|
+
const out = /* @__PURE__ */ new Map();
|
|
23
|
+
const clusterGroups = svg.querySelectorAll("g.cluster");
|
|
24
|
+
if (!clusterGroups.length) return out;
|
|
25
|
+
const allNodes = Array.from(svg.querySelectorAll("g.node"));
|
|
26
|
+
for (const g of Array.from(clusterGroups)) {
|
|
27
|
+
const titleEl = directChild(g, "title");
|
|
28
|
+
if (!titleEl) continue;
|
|
29
|
+
const raw = titleEl.textContent ?? "";
|
|
30
|
+
if (!raw.startsWith("cluster_")) continue;
|
|
31
|
+
const prefix = raw.slice("cluster_".length);
|
|
32
|
+
if (out.has(prefix)) continue;
|
|
33
|
+
let nodeCount = 0;
|
|
34
|
+
for (const node of allNodes) {
|
|
35
|
+
if (node.getAttribute("data-instance")) continue;
|
|
36
|
+
const nodeTitle = directChild(node, "title");
|
|
37
|
+
if (!nodeTitle) continue;
|
|
38
|
+
const id = (nodeTitle.textContent ?? "").trim();
|
|
39
|
+
if (nodeBelongsToPrefix(id, prefix)) {
|
|
40
|
+
node.setAttribute("data-instance", prefix);
|
|
41
|
+
nodeCount++;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
out.set(prefix, {
|
|
45
|
+
prefix,
|
|
46
|
+
group: g,
|
|
47
|
+
nodeCount,
|
|
48
|
+
color: colorForPrefix(prefix)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
function nodeBelongsToPrefix(nodeId, prefix) {
|
|
54
|
+
return nodeId === prefix || nodeId.startsWith(`${prefix}/`) || nodeId.startsWith(`p_${prefix}_`) || nodeId.startsWith(`t_${prefix}_`) || nodeId.startsWith(`j_${prefix}_`);
|
|
55
|
+
}
|
|
56
|
+
function colorForPrefix(prefix) {
|
|
57
|
+
let h = 2166136261;
|
|
58
|
+
for (let i = 0; i < prefix.length; i++) {
|
|
59
|
+
h ^= prefix.charCodeAt(i);
|
|
60
|
+
h = h * 16777619 >>> 0;
|
|
61
|
+
}
|
|
62
|
+
let hue = Math.floor((h / 4294967296 * 360 + h % 360 * 0.61803) % 360);
|
|
63
|
+
if (hue < 0) hue += 360;
|
|
64
|
+
return `hsl(${hue}, 60%, 45%)`;
|
|
65
|
+
}
|
|
66
|
+
function paintClusterBorders(clusters) {
|
|
67
|
+
for (const c of clusters.values()) {
|
|
68
|
+
const border = directChild(c.group, "polygon") ?? directChild(c.group, "path");
|
|
69
|
+
if (border) {
|
|
70
|
+
border.setAttribute("stroke", c.color);
|
|
71
|
+
border.setAttribute("stroke-width", "2.2");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function setClusterCollapsed(cluster, collapsed) {
|
|
76
|
+
const g = cluster.group;
|
|
77
|
+
const isCollapsed = g.classList.contains("cluster-collapsed");
|
|
78
|
+
const root = g.ownerSVGElement;
|
|
79
|
+
if (!root) return;
|
|
80
|
+
if (collapsed && !isCollapsed) {
|
|
81
|
+
g.classList.add("cluster-collapsed");
|
|
82
|
+
const hidden = [];
|
|
83
|
+
root.querySelectorAll(`g.node[data-instance="${cssEscape(cluster.prefix)}"]`).forEach((node) => {
|
|
84
|
+
node.classList.add("petri-collapsed-inside");
|
|
85
|
+
hidden.push(node);
|
|
86
|
+
});
|
|
87
|
+
root.querySelectorAll("g.edge").forEach((edge) => {
|
|
88
|
+
const titleEl = directChild(edge, "title");
|
|
89
|
+
if (!titleEl) return;
|
|
90
|
+
const t = (titleEl.textContent ?? "").trim();
|
|
91
|
+
const arrow = t.indexOf("->");
|
|
92
|
+
if (arrow < 0) return;
|
|
93
|
+
const from = t.slice(0, arrow);
|
|
94
|
+
const to = t.slice(arrow + 2);
|
|
95
|
+
if (nodeBelongsToPrefix(from, cluster.prefix) && nodeBelongsToPrefix(to, cluster.prefix)) {
|
|
96
|
+
edge.classList.add("petri-collapsed-inside");
|
|
97
|
+
hidden.push(edge);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
g._petriHiddenSiblings = hidden;
|
|
101
|
+
if (!g._petriCollapsedBadge) {
|
|
102
|
+
const label = directChild(g, "text");
|
|
103
|
+
if (label) {
|
|
104
|
+
const badge = document.createElementNS("http://www.w3.org/2000/svg", "text");
|
|
105
|
+
badge.setAttribute("x", label.getAttribute("x") ?? "0");
|
|
106
|
+
const labelY = parseFloat(label.getAttribute("y") ?? "0");
|
|
107
|
+
badge.setAttribute("y", String(labelY + 16));
|
|
108
|
+
badge.setAttribute("text-anchor", label.getAttribute("text-anchor") ?? "middle");
|
|
109
|
+
badge.setAttribute("font-size", "11");
|
|
110
|
+
badge.setAttribute("fill", "#9ca3af");
|
|
111
|
+
badge.setAttribute("class", "cluster-collapsed-badge");
|
|
112
|
+
badge.textContent = `(${cluster.nodeCount} internal node${cluster.nodeCount === 1 ? "" : "s"})`;
|
|
113
|
+
g.appendChild(badge);
|
|
114
|
+
g._petriCollapsedBadge = badge;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} else if (!collapsed && isCollapsed) {
|
|
118
|
+
g.classList.remove("cluster-collapsed");
|
|
119
|
+
if (g._petriHiddenSiblings) {
|
|
120
|
+
g._petriHiddenSiblings.forEach((el) => el.classList.remove("petri-collapsed-inside"));
|
|
121
|
+
g._petriHiddenSiblings = void 0;
|
|
122
|
+
}
|
|
123
|
+
if (g._petriCollapsedBadge && g._petriCollapsedBadge.parentNode === g) {
|
|
124
|
+
g.removeChild(g._petriCollapsedBadge);
|
|
125
|
+
g._petriCollapsedBadge = null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function applyFilter(svg, prefix) {
|
|
130
|
+
if (prefix == null) {
|
|
131
|
+
svg.removeAttribute("data-active-filter");
|
|
132
|
+
svg.classList.remove("has-active-filter");
|
|
133
|
+
svg.querySelectorAll("g.node, g.edge").forEach((el) => el.classList.remove("petri-dimmed"));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
svg.setAttribute("data-active-filter", prefix);
|
|
137
|
+
svg.classList.add("has-active-filter");
|
|
138
|
+
svg.querySelectorAll("g.node").forEach((node) => {
|
|
139
|
+
const di = node.getAttribute("data-instance");
|
|
140
|
+
const match = !!di && (di === prefix || di.indexOf(prefix + "_") === 0 || di.indexOf(prefix + "/") === 0);
|
|
141
|
+
if (match) node.classList.remove("petri-dimmed");
|
|
142
|
+
else node.classList.add("petri-dimmed");
|
|
143
|
+
});
|
|
144
|
+
svg.querySelectorAll("g.edge").forEach((edge) => {
|
|
145
|
+
const titleEl = directChild(edge, "title");
|
|
146
|
+
if (!titleEl) return;
|
|
147
|
+
const titleText = titleEl.textContent ?? "";
|
|
148
|
+
const arrow = titleText.indexOf("->");
|
|
149
|
+
if (arrow < 0) {
|
|
150
|
+
edge.classList.remove("petri-dimmed");
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const from = titleText.slice(0, arrow);
|
|
154
|
+
const to = titleText.slice(arrow + 2);
|
|
155
|
+
const matches = (name) => name.indexOf(prefix + "/") >= 0 || name.indexOf(prefix + "_") >= 0 || name === prefix;
|
|
156
|
+
if (matches(from) || matches(to)) edge.classList.remove("petri-dimmed");
|
|
157
|
+
else edge.classList.add("petri-dimmed");
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function isInsideCollapsedCluster(svg, clusters, collapsedPrefixes, graphId) {
|
|
161
|
+
if (collapsedPrefixes.size === 0) return false;
|
|
162
|
+
if (!svg) return false;
|
|
163
|
+
for (const prefix of collapsedPrefixes) {
|
|
164
|
+
if (!clusters.has(prefix)) continue;
|
|
165
|
+
if (nodeBelongsToPrefix(graphId, prefix)) return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
function cssEscape(s) {
|
|
170
|
+
if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(s);
|
|
171
|
+
return s.replace(/[^a-zA-Z0-9_-]/g, (c) => `\\${c}`);
|
|
172
|
+
}
|
|
173
|
+
function directChild(parent, tagName) {
|
|
174
|
+
const lc = tagName.toLowerCase();
|
|
175
|
+
for (const child of Array.from(parent.children)) {
|
|
176
|
+
if (child.tagName.toLowerCase() === lc) return child;
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/viewer/c0-annotations.ts
|
|
182
|
+
function ownTitle(g) {
|
|
183
|
+
for (const child of Array.from(g.children)) {
|
|
184
|
+
if (child.tagName === "title") return child.textContent ?? "";
|
|
185
|
+
}
|
|
186
|
+
return "";
|
|
187
|
+
}
|
|
188
|
+
function enclosingClusterShortName(node) {
|
|
189
|
+
const cluster = node.parentElement?.closest("g.cluster");
|
|
190
|
+
if (!cluster) return "";
|
|
191
|
+
return ownTitle(cluster).replace(/^cluster_/, "");
|
|
192
|
+
}
|
|
193
|
+
function annotateSvgForC0(svg) {
|
|
194
|
+
const nodes = Array.from(svg.querySelectorAll("g.node"));
|
|
195
|
+
for (const node of nodes) {
|
|
196
|
+
const id = ownTitle(node);
|
|
197
|
+
if (!id) continue;
|
|
198
|
+
node.setAttribute("data-id", id);
|
|
199
|
+
const replicaM = /__rep__([A-Za-z0-9_]+)$/.exec(id);
|
|
200
|
+
if (replicaM) {
|
|
201
|
+
node.setAttribute("data-instance", replicaM[1]);
|
|
202
|
+
} else if (!node.hasAttribute("data-instance")) {
|
|
203
|
+
const inst = enclosingClusterShortName(node);
|
|
204
|
+
if (inst) node.setAttribute("data-instance", inst);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const nodeIndex = /* @__PURE__ */ new Map();
|
|
208
|
+
for (const n of nodes) {
|
|
209
|
+
const id = n.getAttribute("data-id");
|
|
210
|
+
if (id) nodeIndex.set(id, n);
|
|
211
|
+
}
|
|
212
|
+
for (const edge of Array.from(svg.querySelectorAll("g.edge"))) {
|
|
213
|
+
const title = ownTitle(edge);
|
|
214
|
+
const arrow = title.indexOf("->");
|
|
215
|
+
if (arrow <= 0) continue;
|
|
216
|
+
const src = title.slice(0, arrow).trim();
|
|
217
|
+
const dst = title.slice(arrow + 2).trim();
|
|
218
|
+
edge.setAttribute("data-src", src);
|
|
219
|
+
edge.setAttribute("data-dst", dst);
|
|
220
|
+
const srcInst = nodeIndex.get(src)?.getAttribute("data-instance") ?? "";
|
|
221
|
+
const dstInst = nodeIndex.get(dst)?.getAttribute("data-instance") ?? "";
|
|
222
|
+
edge.setAttribute("data-src-cluster", srcInst);
|
|
223
|
+
edge.setAttribute("data-dst-cluster", dstInst);
|
|
224
|
+
edge.classList.remove("intra-cluster", "cross-cluster");
|
|
225
|
+
if (srcInst !== "" && srcInst === dstInst) {
|
|
226
|
+
edge.classList.add("intra-cluster");
|
|
227
|
+
edge.setAttribute("data-cluster", srcInst);
|
|
228
|
+
} else {
|
|
229
|
+
edge.classList.add("cross-cluster");
|
|
230
|
+
edge.removeAttribute("data-cluster");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/viewer/chrome/sidebar.ts
|
|
236
|
+
var SIDEBAR_CLASS = "libpetri-sidebar";
|
|
237
|
+
var CHIP_CLASS = "libpetri-sidebar-chip";
|
|
238
|
+
var CHIP_OFF_CLASS = "is-off";
|
|
239
|
+
function mountSidebar(container, clusters, callbacks) {
|
|
240
|
+
const visibleClusters = /* @__PURE__ */ new Set();
|
|
241
|
+
for (const prefix of clusters.keys()) visibleClusters.add(prefix);
|
|
242
|
+
let includeSharedPlaces = true;
|
|
243
|
+
let highlightMode = true;
|
|
244
|
+
const emit = () => {
|
|
245
|
+
callbacks.onVisibilityChange({
|
|
246
|
+
visibleClusters: new Set(visibleClusters),
|
|
247
|
+
includeSharedPlaces
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
const root = document.createElement("aside");
|
|
251
|
+
root.className = SIDEBAR_CLASS;
|
|
252
|
+
const title = document.createElement("h4");
|
|
253
|
+
title.className = "libpetri-sidebar-title";
|
|
254
|
+
title.textContent = `Subnets (${clusters.size})`;
|
|
255
|
+
root.appendChild(title);
|
|
256
|
+
const actions = document.createElement("div");
|
|
257
|
+
actions.className = "libpetri-sidebar-actions";
|
|
258
|
+
const showAll = document.createElement("button");
|
|
259
|
+
showAll.type = "button";
|
|
260
|
+
showAll.textContent = "show all";
|
|
261
|
+
const hideAll = document.createElement("button");
|
|
262
|
+
hideAll.type = "button";
|
|
263
|
+
hideAll.textContent = "hide all";
|
|
264
|
+
actions.appendChild(showAll);
|
|
265
|
+
actions.appendChild(hideAll);
|
|
266
|
+
root.appendChild(actions);
|
|
267
|
+
const sharedLabel = document.createElement("label");
|
|
268
|
+
sharedLabel.className = "libpetri-sidebar-checkbox";
|
|
269
|
+
const sharedCb = document.createElement("input");
|
|
270
|
+
sharedCb.type = "checkbox";
|
|
271
|
+
sharedCb.checked = includeSharedPlaces;
|
|
272
|
+
sharedLabel.appendChild(sharedCb);
|
|
273
|
+
sharedLabel.appendChild(document.createTextNode(" Shared places"));
|
|
274
|
+
sharedCb.addEventListener("change", () => {
|
|
275
|
+
includeSharedPlaces = sharedCb.checked;
|
|
276
|
+
emit();
|
|
277
|
+
});
|
|
278
|
+
root.appendChild(sharedLabel);
|
|
279
|
+
const hlLabel = document.createElement("label");
|
|
280
|
+
hlLabel.className = "libpetri-sidebar-checkbox";
|
|
281
|
+
const hlCb = document.createElement("input");
|
|
282
|
+
hlCb.type = "checkbox";
|
|
283
|
+
hlCb.checked = highlightMode;
|
|
284
|
+
hlLabel.appendChild(hlCb);
|
|
285
|
+
hlLabel.appendChild(document.createTextNode(" Click node \u2192 highlight"));
|
|
286
|
+
hlCb.addEventListener("change", () => {
|
|
287
|
+
highlightMode = hlCb.checked;
|
|
288
|
+
callbacks.onHighlightModeChange(highlightMode);
|
|
289
|
+
});
|
|
290
|
+
root.appendChild(hlLabel);
|
|
291
|
+
const hint = document.createElement("div");
|
|
292
|
+
hint.className = "libpetri-sidebar-hint";
|
|
293
|
+
hint.innerHTML = "Click chip: toggle.<br>Shift-click: isolate.<br>Cmd/Ctrl-click: multi-select.<br>Click empty: clear highlight.";
|
|
294
|
+
root.appendChild(hint);
|
|
295
|
+
const chipList = document.createElement("ul");
|
|
296
|
+
chipList.className = "libpetri-sidebar-chips";
|
|
297
|
+
const chipMap = /* @__PURE__ */ new Map();
|
|
298
|
+
for (const cluster of clusters.values()) {
|
|
299
|
+
const li = document.createElement("li");
|
|
300
|
+
li.className = CHIP_CLASS;
|
|
301
|
+
li.style.borderLeftColor = cluster.color;
|
|
302
|
+
li.dataset.prefix = cluster.prefix;
|
|
303
|
+
const dot = document.createElement("span");
|
|
304
|
+
dot.className = "libpetri-sidebar-chip-dot";
|
|
305
|
+
dot.style.background = cluster.color;
|
|
306
|
+
const name = document.createElement("span");
|
|
307
|
+
name.className = "libpetri-sidebar-chip-name";
|
|
308
|
+
name.textContent = cluster.prefix;
|
|
309
|
+
const count = document.createElement("span");
|
|
310
|
+
count.className = "libpetri-sidebar-chip-count";
|
|
311
|
+
count.textContent = String(cluster.nodeCount);
|
|
312
|
+
li.appendChild(dot);
|
|
313
|
+
li.appendChild(name);
|
|
314
|
+
li.appendChild(count);
|
|
315
|
+
li.addEventListener("click", (ev) => {
|
|
316
|
+
const prefix = cluster.prefix;
|
|
317
|
+
if (ev.shiftKey) {
|
|
318
|
+
const allOff = [...clusters.keys()].every(
|
|
319
|
+
(k) => k === prefix ? visibleClusters.has(k) : !visibleClusters.has(k)
|
|
320
|
+
);
|
|
321
|
+
visibleClusters.clear();
|
|
322
|
+
if (allOff) for (const k of clusters.keys()) visibleClusters.add(k);
|
|
323
|
+
else visibleClusters.add(prefix);
|
|
324
|
+
} else if (ev.ctrlKey || ev.metaKey) {
|
|
325
|
+
const anyHidden = [...clusters.keys()].some((k) => !visibleClusters.has(k));
|
|
326
|
+
if (!anyHidden) {
|
|
327
|
+
visibleClusters.clear();
|
|
328
|
+
visibleClusters.add(prefix);
|
|
329
|
+
} else if (visibleClusters.has(prefix)) {
|
|
330
|
+
visibleClusters.delete(prefix);
|
|
331
|
+
} else {
|
|
332
|
+
visibleClusters.add(prefix);
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
if (visibleClusters.has(prefix)) visibleClusters.delete(prefix);
|
|
336
|
+
else visibleClusters.add(prefix);
|
|
337
|
+
}
|
|
338
|
+
refreshChips();
|
|
339
|
+
emit();
|
|
340
|
+
});
|
|
341
|
+
chipList.appendChild(li);
|
|
342
|
+
chipMap.set(cluster.prefix, li);
|
|
343
|
+
}
|
|
344
|
+
root.appendChild(chipList);
|
|
345
|
+
function refreshChips() {
|
|
346
|
+
for (const [prefix, li] of chipMap) {
|
|
347
|
+
li.classList.toggle(CHIP_OFF_CLASS, !visibleClusters.has(prefix));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
showAll.addEventListener("click", () => {
|
|
351
|
+
visibleClusters.clear();
|
|
352
|
+
for (const k of clusters.keys()) visibleClusters.add(k);
|
|
353
|
+
includeSharedPlaces = true;
|
|
354
|
+
sharedCb.checked = true;
|
|
355
|
+
refreshChips();
|
|
356
|
+
emit();
|
|
357
|
+
});
|
|
358
|
+
hideAll.addEventListener("click", () => {
|
|
359
|
+
visibleClusters.clear();
|
|
360
|
+
includeSharedPlaces = false;
|
|
361
|
+
sharedCb.checked = false;
|
|
362
|
+
refreshChips();
|
|
363
|
+
emit();
|
|
364
|
+
});
|
|
365
|
+
container.appendChild(root);
|
|
366
|
+
emit();
|
|
367
|
+
return {
|
|
368
|
+
root,
|
|
369
|
+
dispose() {
|
|
370
|
+
if (root.parentNode === container) container.removeChild(root);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/viewer/highlight.ts
|
|
376
|
+
var HIGHLIGHT_CLASSES = ["is-highlight", "is-neighbor", "is-faded"];
|
|
377
|
+
function clearHighlightClasses(svg) {
|
|
378
|
+
for (const cls of HIGHLIGHT_CLASSES) {
|
|
379
|
+
for (const el of Array.from(svg.querySelectorAll("." + cls))) {
|
|
380
|
+
el.classList.remove(cls);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function findAllCopies(svg, focusId) {
|
|
385
|
+
const focus = svg.querySelector(`g.node[data-id="${cssEscape2(focusId)}"]`);
|
|
386
|
+
if (!focus) return /* @__PURE__ */ new Set([focusId]);
|
|
387
|
+
const copies = /* @__PURE__ */ new Set([focusId]);
|
|
388
|
+
const origLabel = focus.getAttribute("data-replica-of") ?? (focusId.startsWith("p_") ? focusId.slice(2) : null);
|
|
389
|
+
if (origLabel) {
|
|
390
|
+
const orig = svg.querySelector(`g.node[data-id="${cssEscape2("p_" + origLabel)}"]`);
|
|
391
|
+
if (orig) {
|
|
392
|
+
const id = orig.getAttribute("data-id");
|
|
393
|
+
if (id) copies.add(id);
|
|
394
|
+
}
|
|
395
|
+
for (const sibling of Array.from(
|
|
396
|
+
svg.querySelectorAll(`g.node[data-replica-of="${cssEscape2(origLabel)}"]`)
|
|
397
|
+
)) {
|
|
398
|
+
const id = sibling.getAttribute("data-id");
|
|
399
|
+
if (id) copies.add(id);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return copies;
|
|
403
|
+
}
|
|
404
|
+
function applyHighlight(svg, focusId) {
|
|
405
|
+
clearHighlightClasses(svg);
|
|
406
|
+
if (focusId === null) return;
|
|
407
|
+
const copies = findAllCopies(svg, focusId);
|
|
408
|
+
for (const id of copies) {
|
|
409
|
+
const n = svg.querySelector(`g.node[data-id="${cssEscape2(id)}"]`);
|
|
410
|
+
if (n && !n.classList.contains("is-hidden")) n.classList.add("is-highlight");
|
|
411
|
+
}
|
|
412
|
+
const neighbors = /* @__PURE__ */ new Set();
|
|
413
|
+
const pathJunctions = /* @__PURE__ */ new Set();
|
|
414
|
+
const pathEdges = [];
|
|
415
|
+
const queue = Array.from(copies);
|
|
416
|
+
const visited = new Set(copies);
|
|
417
|
+
const allEdges = Array.from(svg.querySelectorAll("g.edge"));
|
|
418
|
+
while (queue.length > 0) {
|
|
419
|
+
const nodeId = queue.shift();
|
|
420
|
+
for (const e of allEdges) {
|
|
421
|
+
if (e.classList.contains("is-hidden")) continue;
|
|
422
|
+
const s = e.getAttribute("data-src");
|
|
423
|
+
const d = e.getAttribute("data-dst");
|
|
424
|
+
if (s !== nodeId && d !== nodeId) continue;
|
|
425
|
+
const otherId = s === nodeId ? d : s;
|
|
426
|
+
if (!otherId) continue;
|
|
427
|
+
pathEdges.push(e);
|
|
428
|
+
if (visited.has(otherId)) continue;
|
|
429
|
+
visited.add(otherId);
|
|
430
|
+
if (otherId.startsWith("j_")) {
|
|
431
|
+
pathJunctions.add(otherId);
|
|
432
|
+
queue.push(otherId);
|
|
433
|
+
} else {
|
|
434
|
+
neighbors.add(otherId);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
for (const e of pathEdges) e.classList.add("is-highlight");
|
|
439
|
+
for (const e of allEdges) {
|
|
440
|
+
if (e.classList.contains("is-hidden") || e.classList.contains("is-highlight")) continue;
|
|
441
|
+
e.classList.add("is-faded");
|
|
442
|
+
}
|
|
443
|
+
for (const n of Array.from(svg.querySelectorAll("g.node"))) {
|
|
444
|
+
if (n.classList.contains("is-hidden")) continue;
|
|
445
|
+
const id = n.getAttribute("data-id") ?? "";
|
|
446
|
+
if (copies.has(id)) continue;
|
|
447
|
+
if (neighbors.has(id)) n.classList.add("is-neighbor");
|
|
448
|
+
else if (pathJunctions.has(id)) continue;
|
|
449
|
+
else n.classList.add("is-faded");
|
|
450
|
+
}
|
|
451
|
+
for (const c of Array.from(
|
|
452
|
+
svg.querySelectorAll("g.cluster:not(.cluster-orchestrator)")
|
|
453
|
+
)) {
|
|
454
|
+
if (c.classList.contains("is-hidden")) continue;
|
|
455
|
+
c.classList.add("is-faded");
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function cssEscape2(value) {
|
|
459
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/viewer/replica-tagging.ts
|
|
463
|
+
var REPLICA_RE = /^(p_[A-Za-z0-9_]+)__rep__/;
|
|
464
|
+
function semanticName(placeId) {
|
|
465
|
+
return placeId.replace(/^p_/, "");
|
|
466
|
+
}
|
|
467
|
+
function tagReplicas(svg) {
|
|
468
|
+
const originalsWithCopies = /* @__PURE__ */ new Set();
|
|
469
|
+
const allNodes = Array.from(svg.querySelectorAll("g.node"));
|
|
470
|
+
for (const g of allNodes) {
|
|
471
|
+
const title = g.querySelector("title")?.textContent ?? "";
|
|
472
|
+
const m = REPLICA_RE.exec(title);
|
|
473
|
+
if (m) originalsWithCopies.add(m[1]);
|
|
474
|
+
}
|
|
475
|
+
for (const g of allNodes) {
|
|
476
|
+
const title = g.querySelector("title")?.textContent ?? "";
|
|
477
|
+
const replicaMatch = REPLICA_RE.exec(title);
|
|
478
|
+
let semantic = null;
|
|
479
|
+
if (replicaMatch) {
|
|
480
|
+
semantic = semanticName(replicaMatch[1]);
|
|
481
|
+
} else if (originalsWithCopies.has(title)) {
|
|
482
|
+
semantic = semanticName(title);
|
|
483
|
+
}
|
|
484
|
+
if (semantic === null) continue;
|
|
485
|
+
g.classList.add("petri-replica");
|
|
486
|
+
g.setAttribute("data-replica-of", semantic);
|
|
487
|
+
appendSharedGlyph(g);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
491
|
+
var GLYPH_CLASS = "libpetri-replica-glyph";
|
|
492
|
+
function appendSharedGlyph(g) {
|
|
493
|
+
if (g.querySelector(`text.${GLYPH_CLASS}`)) return;
|
|
494
|
+
const shape = g.querySelector("ellipse, circle");
|
|
495
|
+
if (!shape) return;
|
|
496
|
+
let cx = 0, cy = 0, rx = 0, ry = 0;
|
|
497
|
+
if (shape.tagName === "ellipse") {
|
|
498
|
+
cx = parseFloat(shape.getAttribute("cx") ?? "0");
|
|
499
|
+
cy = parseFloat(shape.getAttribute("cy") ?? "0");
|
|
500
|
+
rx = parseFloat(shape.getAttribute("rx") ?? "0");
|
|
501
|
+
ry = parseFloat(shape.getAttribute("ry") ?? "0");
|
|
502
|
+
} else {
|
|
503
|
+
cx = parseFloat(shape.getAttribute("cx") ?? "0");
|
|
504
|
+
cy = parseFloat(shape.getAttribute("cy") ?? "0");
|
|
505
|
+
rx = parseFloat(shape.getAttribute("r") ?? "0");
|
|
506
|
+
ry = rx;
|
|
507
|
+
}
|
|
508
|
+
const text = document.createElementNS(SVG_NS, "text");
|
|
509
|
+
text.setAttribute("class", GLYPH_CLASS);
|
|
510
|
+
text.setAttribute("x", (cx + rx + 2).toFixed(2));
|
|
511
|
+
text.setAttribute("y", (cy - ry + 2).toFixed(2));
|
|
512
|
+
text.setAttribute("text-anchor", "start");
|
|
513
|
+
text.setAttribute("font-size", "9");
|
|
514
|
+
text.textContent = "\u21C4";
|
|
515
|
+
g.appendChild(text);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// src/viewer/visibility.ts
|
|
519
|
+
function computeVisibleOrphans(svg, visibleClusters) {
|
|
520
|
+
if (visibleClusters.size === 0) return /* @__PURE__ */ new Set();
|
|
521
|
+
const orphanNodes = Array.from(
|
|
522
|
+
svg.querySelectorAll("g.node:not([data-instance])")
|
|
523
|
+
);
|
|
524
|
+
const orphanIds = /* @__PURE__ */ new Set();
|
|
525
|
+
for (const n of orphanNodes) {
|
|
526
|
+
const id = n.getAttribute("data-id");
|
|
527
|
+
if (id) orphanIds.add(id);
|
|
528
|
+
}
|
|
529
|
+
const fwdAdj = /* @__PURE__ */ new Map();
|
|
530
|
+
const bwdAdj = /* @__PURE__ */ new Map();
|
|
531
|
+
const link = (m, k, v) => {
|
|
532
|
+
let s = m.get(k);
|
|
533
|
+
if (!s) {
|
|
534
|
+
s = /* @__PURE__ */ new Set();
|
|
535
|
+
m.set(k, s);
|
|
536
|
+
}
|
|
537
|
+
s.add(v);
|
|
538
|
+
};
|
|
539
|
+
for (const e of Array.from(svg.querySelectorAll("g.edge"))) {
|
|
540
|
+
const s = e.getAttribute("data-src") ?? "";
|
|
541
|
+
const d = e.getAttribute("data-dst") ?? "";
|
|
542
|
+
if (orphanIds.has(s) && orphanIds.has(d)) {
|
|
543
|
+
link(fwdAdj, s, d);
|
|
544
|
+
link(bwdAdj, d, s);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const seedUpstream = /* @__PURE__ */ new Set();
|
|
548
|
+
const seedDownstream = /* @__PURE__ */ new Set();
|
|
549
|
+
for (const e of Array.from(
|
|
550
|
+
svg.querySelectorAll("g.edge.cross-cluster")
|
|
551
|
+
)) {
|
|
552
|
+
const s = e.getAttribute("data-src") ?? "";
|
|
553
|
+
const d = e.getAttribute("data-dst") ?? "";
|
|
554
|
+
const sCl = e.getAttribute("data-src-cluster") ?? "";
|
|
555
|
+
const dCl = e.getAttribute("data-dst-cluster") ?? "";
|
|
556
|
+
if (orphanIds.has(s) && visibleClusters.has(dCl)) seedUpstream.add(s);
|
|
557
|
+
if (orphanIds.has(d) && visibleClusters.has(sCl)) seedDownstream.add(d);
|
|
558
|
+
}
|
|
559
|
+
const visible = /* @__PURE__ */ new Set();
|
|
560
|
+
const bfs = (seeds, adj) => {
|
|
561
|
+
const q = [];
|
|
562
|
+
for (const s of seeds) {
|
|
563
|
+
visible.add(s);
|
|
564
|
+
q.push(s);
|
|
565
|
+
}
|
|
566
|
+
while (q.length) {
|
|
567
|
+
const cur = q.shift();
|
|
568
|
+
const next = adj.get(cur);
|
|
569
|
+
if (!next) continue;
|
|
570
|
+
for (const x of next) {
|
|
571
|
+
if (!visible.has(x)) {
|
|
572
|
+
visible.add(x);
|
|
573
|
+
q.push(x);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
bfs(seedUpstream, bwdAdj);
|
|
579
|
+
bfs(seedDownstream, fwdAdj);
|
|
580
|
+
return visible;
|
|
581
|
+
}
|
|
582
|
+
function applyVisibility(svg, state) {
|
|
583
|
+
annotateSvgForC0(svg);
|
|
584
|
+
const { visibleClusters, includeSharedPlaces } = state;
|
|
585
|
+
for (const c of Array.from(
|
|
586
|
+
svg.querySelectorAll("g.cluster:not(.cluster-orchestrator)")
|
|
587
|
+
)) {
|
|
588
|
+
const titleEl = c.querySelector(":scope > title");
|
|
589
|
+
const shortName = (titleEl?.textContent ?? "").replace(/^cluster_/, "");
|
|
590
|
+
c.classList.toggle("is-hidden", !visibleClusters.has(shortName));
|
|
591
|
+
}
|
|
592
|
+
for (const n of Array.from(svg.querySelectorAll("g.node[data-instance]"))) {
|
|
593
|
+
const inst = n.getAttribute("data-instance") ?? "";
|
|
594
|
+
n.classList.toggle("is-hidden", !visibleClusters.has(inst));
|
|
595
|
+
}
|
|
596
|
+
const visOrphans = computeVisibleOrphans(svg, visibleClusters);
|
|
597
|
+
for (const n of Array.from(
|
|
598
|
+
svg.querySelectorAll("g.node:not([data-instance])")
|
|
599
|
+
)) {
|
|
600
|
+
const id = n.getAttribute("data-id") ?? "";
|
|
601
|
+
n.classList.toggle("is-hidden", !visOrphans.has(id));
|
|
602
|
+
}
|
|
603
|
+
if (!includeSharedPlaces) {
|
|
604
|
+
for (const n of Array.from(svg.querySelectorAll("g.node.petri-replica"))) {
|
|
605
|
+
n.classList.add("is-hidden");
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const nodeById = /* @__PURE__ */ new Map();
|
|
609
|
+
for (const n of Array.from(svg.querySelectorAll("g.node"))) {
|
|
610
|
+
const id = n.getAttribute("data-id");
|
|
611
|
+
if (id) nodeById.set(id, n);
|
|
612
|
+
}
|
|
613
|
+
for (const e of Array.from(svg.querySelectorAll("g.edge"))) {
|
|
614
|
+
const s = e.getAttribute("data-src") ?? "";
|
|
615
|
+
const d = e.getAttribute("data-dst") ?? "";
|
|
616
|
+
const sHidden = nodeById.get(s)?.classList.contains("is-hidden") ?? false;
|
|
617
|
+
const dHidden = nodeById.get(d)?.classList.contains("is-hidden") ?? false;
|
|
618
|
+
e.classList.toggle("is-hidden", sHidden || dHidden);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// src/viewer/styles.ts
|
|
623
|
+
var VIEWER_CSS_VARIABLES = [
|
|
624
|
+
"--lpv-bg",
|
|
625
|
+
"--lpv-header-bg",
|
|
626
|
+
"--lpv-border",
|
|
627
|
+
"--lpv-text",
|
|
628
|
+
"--lpv-muted",
|
|
629
|
+
"--lpv-cluster-bg",
|
|
630
|
+
"--lpv-cluster-bg-collapsed",
|
|
631
|
+
"--lpv-cluster-stroke-width",
|
|
632
|
+
"--lpv-cluster-stroke-dash",
|
|
633
|
+
"--lpv-cluster-fill-tint",
|
|
634
|
+
"--lpv-dim-opacity",
|
|
635
|
+
"--lpv-active-filter-outline",
|
|
636
|
+
"--lpv-legend-bg",
|
|
637
|
+
"--lpv-chip-bg",
|
|
638
|
+
"--lpv-chip-active-bg",
|
|
639
|
+
// C0 sidebar + replica + highlight (Stage 5)
|
|
640
|
+
"--lpv-sidebar-bg",
|
|
641
|
+
"--lpv-sidebar-border",
|
|
642
|
+
"--lpv-sidebar-text",
|
|
643
|
+
"--lpv-sidebar-muted",
|
|
644
|
+
"--lpv-sidebar-chip-bg",
|
|
645
|
+
"--lpv-sidebar-chip-hover-bg",
|
|
646
|
+
"--lpv-sidebar-chip-off-opacity",
|
|
647
|
+
"--lpv-shared-glyph-color",
|
|
648
|
+
"--lpv-replica-fill",
|
|
649
|
+
"--lpv-replica-stroke",
|
|
650
|
+
"--lpv-highlight-stroke",
|
|
651
|
+
"--lpv-highlight-glow",
|
|
652
|
+
"--lpv-neighbor-stroke",
|
|
653
|
+
"--lpv-faded-node-opacity",
|
|
654
|
+
"--lpv-faded-edge-opacity",
|
|
655
|
+
"--lpv-faded-cluster-opacity"
|
|
656
|
+
];
|
|
657
|
+
|
|
658
|
+
// src/viewer/index.ts
|
|
659
|
+
async function mount(dotSource, container, opts = {}) {
|
|
660
|
+
const previousHandle = opts.previousHandle ?? null;
|
|
661
|
+
const preservedCollapsed = previousHandle ? new Set(previousHandle.collapsedPrefixes) : /* @__PURE__ */ new Set();
|
|
662
|
+
const preservedFilter = previousHandle?.activeFilter ?? null;
|
|
663
|
+
if (previousHandle) {
|
|
664
|
+
previousHandle.dispose();
|
|
665
|
+
}
|
|
666
|
+
let svg;
|
|
667
|
+
const existing = container.querySelector(":scope > svg");
|
|
668
|
+
if (dotSource == null) {
|
|
669
|
+
if (!(existing instanceof SVGSVGElement)) {
|
|
670
|
+
throw new Error("mount: no DOT source and no pre-rendered SVG");
|
|
671
|
+
}
|
|
672
|
+
svg = existing;
|
|
673
|
+
} else {
|
|
674
|
+
const renderModule = await import("../render-QK57X4TP.js");
|
|
675
|
+
const useElk = (opts.layout ?? "elk") === "elk";
|
|
676
|
+
svg = useElk ? await renderModule.renderDotToSvgWithElkLayout(dotSource) : await renderModule.renderDotToSvg(dotSource);
|
|
677
|
+
container.innerHTML = "";
|
|
678
|
+
container.appendChild(svg);
|
|
679
|
+
}
|
|
680
|
+
container.classList.add("libpetri-viewer");
|
|
681
|
+
const panzoomInstance = attachPanzoom(svg, opts.panzoom);
|
|
682
|
+
const clusters = discoverClusters(svg);
|
|
683
|
+
paintClusterBorders(clusters);
|
|
684
|
+
const layoutMode = opts.layout ?? "elk";
|
|
685
|
+
if (layoutMode === "elk") {
|
|
686
|
+
tagReplicas(svg);
|
|
687
|
+
annotateSvgForC0(svg);
|
|
688
|
+
}
|
|
689
|
+
const collapsedPrefixes = /* @__PURE__ */ new Set();
|
|
690
|
+
let activeFilter = null;
|
|
691
|
+
let highlightedNodeId = null;
|
|
692
|
+
let disposed = false;
|
|
693
|
+
let chromeRoot = null;
|
|
694
|
+
let sidebarHandle = null;
|
|
695
|
+
let highlightModeEnabled = true;
|
|
696
|
+
function ensureChrome() {
|
|
697
|
+
if (!opts.chrome) return;
|
|
698
|
+
if (chromeRoot && chromeRoot.parentNode === container) return;
|
|
699
|
+
chromeRoot = document.createElement("div");
|
|
700
|
+
chromeRoot.className = "libpetri-viewer-chrome";
|
|
701
|
+
chromeRoot.style.position = "absolute";
|
|
702
|
+
chromeRoot.style.inset = "0";
|
|
703
|
+
chromeRoot.style.pointerEvents = "none";
|
|
704
|
+
const controls = document.createElement("div");
|
|
705
|
+
controls.className = "diagram-controls";
|
|
706
|
+
controls.style.pointerEvents = "auto";
|
|
707
|
+
const resetBtn = document.createElement("button");
|
|
708
|
+
resetBtn.type = "button";
|
|
709
|
+
resetBtn.className = "diagram-btn btn-reset";
|
|
710
|
+
resetBtn.title = "Reset view";
|
|
711
|
+
resetBtn.textContent = "Reset";
|
|
712
|
+
resetBtn.addEventListener("click", () => handle.fit());
|
|
713
|
+
const fsBtn = document.createElement("button");
|
|
714
|
+
fsBtn.type = "button";
|
|
715
|
+
fsBtn.className = "diagram-btn btn-fullscreen";
|
|
716
|
+
fsBtn.title = "Toggle fullscreen";
|
|
717
|
+
fsBtn.textContent = "Fullscreen";
|
|
718
|
+
fsBtn.addEventListener("click", () => toggleFullscreen(container, fsBtn));
|
|
719
|
+
controls.appendChild(resetBtn);
|
|
720
|
+
controls.appendChild(fsBtn);
|
|
721
|
+
chromeRoot.appendChild(controls);
|
|
722
|
+
if (getComputedStyle(container).position === "static") {
|
|
723
|
+
container.style.position = "relative";
|
|
724
|
+
}
|
|
725
|
+
container.appendChild(chromeRoot);
|
|
726
|
+
if (layoutMode === "elk" && clusters.size > 0) {
|
|
727
|
+
sidebarHandle = mountSidebar(container, clusters, {
|
|
728
|
+
onVisibilityChange: (state) => handle.setVisibility(state),
|
|
729
|
+
onHighlightModeChange: (enabled) => {
|
|
730
|
+
highlightModeEnabled = enabled;
|
|
731
|
+
if (!enabled) handle.highlight(null);
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function toggleFullscreen(host, btn) {
|
|
737
|
+
const isFs = host.classList.toggle("diagram-fullscreen");
|
|
738
|
+
btn.textContent = isFs ? "Exit fullscreen" : "Fullscreen";
|
|
739
|
+
requestAnimationFrame(() => handle.fit());
|
|
740
|
+
}
|
|
741
|
+
const handle = {
|
|
742
|
+
svg,
|
|
743
|
+
panzoom: panzoomInstance,
|
|
744
|
+
clusters,
|
|
745
|
+
get collapsedPrefixes() {
|
|
746
|
+
return collapsedPrefixes;
|
|
747
|
+
},
|
|
748
|
+
get activeFilter() {
|
|
749
|
+
return activeFilter;
|
|
750
|
+
},
|
|
751
|
+
collapse(prefix) {
|
|
752
|
+
if (disposed) return;
|
|
753
|
+
const cluster = clusters.get(prefix);
|
|
754
|
+
if (!cluster) return;
|
|
755
|
+
if (!collapsedPrefixes.has(prefix)) {
|
|
756
|
+
setClusterCollapsed(cluster, true);
|
|
757
|
+
collapsedPrefixes.add(prefix);
|
|
758
|
+
opts.onClusterCollapse?.(prefix, true);
|
|
759
|
+
}
|
|
760
|
+
},
|
|
761
|
+
expand(prefix) {
|
|
762
|
+
if (disposed) return;
|
|
763
|
+
const cluster = clusters.get(prefix);
|
|
764
|
+
if (!cluster) return;
|
|
765
|
+
if (collapsedPrefixes.has(prefix)) {
|
|
766
|
+
setClusterCollapsed(cluster, false);
|
|
767
|
+
collapsedPrefixes.delete(prefix);
|
|
768
|
+
opts.onClusterCollapse?.(prefix, false);
|
|
769
|
+
}
|
|
770
|
+
},
|
|
771
|
+
collapseAll() {
|
|
772
|
+
if (disposed) return;
|
|
773
|
+
for (const cluster of clusters.values()) {
|
|
774
|
+
if (!collapsedPrefixes.has(cluster.prefix)) {
|
|
775
|
+
setClusterCollapsed(cluster, true);
|
|
776
|
+
collapsedPrefixes.add(cluster.prefix);
|
|
777
|
+
opts.onClusterCollapse?.(cluster.prefix, true);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
},
|
|
781
|
+
expandAll() {
|
|
782
|
+
if (disposed) return;
|
|
783
|
+
for (const prefix of Array.from(collapsedPrefixes)) {
|
|
784
|
+
const cluster = clusters.get(prefix);
|
|
785
|
+
if (!cluster) continue;
|
|
786
|
+
setClusterCollapsed(cluster, false);
|
|
787
|
+
collapsedPrefixes.delete(prefix);
|
|
788
|
+
opts.onClusterCollapse?.(prefix, false);
|
|
789
|
+
}
|
|
790
|
+
},
|
|
791
|
+
filter(prefix) {
|
|
792
|
+
if (disposed) return;
|
|
793
|
+
activeFilter = prefix;
|
|
794
|
+
applyFilter(svg, prefix);
|
|
795
|
+
opts.onClusterFilter?.(prefix);
|
|
796
|
+
},
|
|
797
|
+
resetZoom() {
|
|
798
|
+
if (disposed) return;
|
|
799
|
+
try {
|
|
800
|
+
panzoomInstance.moveTo(0, 0);
|
|
801
|
+
panzoomInstance.zoomAbs(0, 0, 1);
|
|
802
|
+
} catch {
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
fit() {
|
|
806
|
+
if (disposed) return;
|
|
807
|
+
try {
|
|
808
|
+
panzoomInstance.zoomAbs(0, 0, 1);
|
|
809
|
+
panzoomInstance.moveTo(0, 0);
|
|
810
|
+
} catch {
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
isInsideCollapsedCluster(graphId) {
|
|
814
|
+
return isInsideCollapsedCluster(svg, clusters, collapsedPrefixes, graphId);
|
|
815
|
+
},
|
|
816
|
+
get highlightedNodeId() {
|
|
817
|
+
return highlightedNodeId;
|
|
818
|
+
},
|
|
819
|
+
highlight(nodeId) {
|
|
820
|
+
if (disposed) return;
|
|
821
|
+
if (layoutMode !== "elk") return;
|
|
822
|
+
highlightedNodeId = nodeId;
|
|
823
|
+
applyHighlight(svg, nodeId);
|
|
824
|
+
},
|
|
825
|
+
setVisibility(state) {
|
|
826
|
+
if (disposed) return;
|
|
827
|
+
if (layoutMode !== "elk") return;
|
|
828
|
+
applyVisibility(svg, state);
|
|
829
|
+
},
|
|
830
|
+
dispose() {
|
|
831
|
+
if (disposed) return;
|
|
832
|
+
disposed = true;
|
|
833
|
+
try {
|
|
834
|
+
panzoomInstance.dispose();
|
|
835
|
+
} catch {
|
|
836
|
+
}
|
|
837
|
+
sidebarHandle?.dispose();
|
|
838
|
+
sidebarHandle = null;
|
|
839
|
+
if (chromeRoot && chromeRoot.parentNode === container) {
|
|
840
|
+
container.removeChild(chromeRoot);
|
|
841
|
+
}
|
|
842
|
+
chromeRoot = null;
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
for (const prefix of preservedCollapsed) {
|
|
846
|
+
handle.collapse(prefix);
|
|
847
|
+
}
|
|
848
|
+
if (preservedFilter !== null) {
|
|
849
|
+
handle.filter(preservedFilter);
|
|
850
|
+
}
|
|
851
|
+
if (layoutMode === "elk") {
|
|
852
|
+
svg.addEventListener("click", (ev) => {
|
|
853
|
+
if (!highlightModeEnabled) return;
|
|
854
|
+
const target = ev.target;
|
|
855
|
+
if (!(target instanceof Element)) return;
|
|
856
|
+
const nodeG = target.closest("g.node");
|
|
857
|
+
if (!nodeG) {
|
|
858
|
+
handle.highlight(null);
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const id = nodeG.getAttribute("data-id");
|
|
862
|
+
if (!id) return;
|
|
863
|
+
handle.highlight(id === highlightedNodeId ? null : id);
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
ensureChrome();
|
|
867
|
+
requestAnimationFrame(() => handle.fit());
|
|
868
|
+
return handle;
|
|
869
|
+
}
|
|
870
|
+
export {
|
|
871
|
+
DEFAULT_PANZOOM_OPTS,
|
|
872
|
+
VIEWER_CSS_VARIABLES,
|
|
873
|
+
colorForPrefix,
|
|
874
|
+
discoverClusters,
|
|
875
|
+
mount
|
|
876
|
+
};
|
|
877
|
+
//# sourceMappingURL=index.js.map
|