react-beauti-graph 0.0.0-stage → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,887 @@
1
+ "use client";
2
+ import { useEffect as e, useId as t, useRef as n, useState as r } from "react";
3
+ import i from "cytoscape";
4
+ import a from "cytoscape-svg";
5
+ import { jsx as o, jsxs as s } from "react/jsx-runtime";
6
+ // src/default_setting.ts
7
+ var c = "#e91e63", l = "#2e7d32", u = "#7b1fa2", d = "#efeb00", f = "#8b4513", p = "rgb(239, 108, 0)", m = "22px", h = "18px", g = "#0066cc", _ = "#fff", v = "#f0f8ff";
8
+ // src/graphFactory.tsx
9
+ i.use(a);
10
+ function y(e) {
11
+ let t = e.svg({
12
+ full: !0,
13
+ scale: 1
14
+ }), n = URL.createObjectURL(new Blob([t], { type: "image/svg+xml" })), r = document.createElement("a");
15
+ r.href = n, r.download = "graph.svg", r.click(), URL.revokeObjectURL(n);
16
+ }
17
+ var b = 2, x = -8, S = 16, C = 16, w = 14, T = [
18
+ ["top", "Font Top Panel"],
19
+ ["right", "Font Right Panel"],
20
+ ["graph", "Font Graph Panel"]
21
+ ], E = "Helvetica Neue, Helvetica, Arial, sans-serif", D = 1.2, O = .6, k = "macromolecule", A = "compartment", j = `node[class = "${k}"]`, M;
22
+ function N(e, t) {
23
+ if (M === void 0) try {
24
+ M = document.createElement("canvas").getContext("2d");
25
+ } catch {
26
+ M = null;
27
+ }
28
+ return M ? (M.font = `${t}px ${E}`, M.measureText(e).width) : e.length * t * O;
29
+ }
30
+ function ee(e, t = C) {
31
+ return {
32
+ width: Math.ceil(N(e ?? "", t)) + 8,
33
+ height: Math.ceil(t * D) + 8
34
+ };
35
+ }
36
+ function P(e, t) {
37
+ return e.localeCompare(t, void 0, {
38
+ numeric: !0,
39
+ sensitivity: "base"
40
+ });
41
+ }
42
+ function F(e = []) {
43
+ let t = /* @__PURE__ */ new Map();
44
+ return e.map((e) => e.map((e) => {
45
+ let n = t.get(e) ?? 0;
46
+ if (t.set(e, n + 1), n === 0) return e;
47
+ let r = `${e}(${n})`;
48
+ return console.warn(`layout: duplicate id "${e}" — renamed to "${r}"`), r;
49
+ }));
50
+ }
51
+ function te(e, t, n = {}) {
52
+ let { startX: r = 0, startY: i = 0, offsetX: a = 200, offsetY: o = 200, base: s = 1 } = n, c = /* @__PURE__ */ new Set();
53
+ t.forEach((t, n) => {
54
+ t.forEach((t, l) => {
55
+ let u = t, d = e.getElementById(u);
56
+ if (d.empty()) {
57
+ let n = /^(.+)\((\d+)\)$/.exec(t)?.[1];
58
+ n !== void 0 && e.getElementById(n).nonempty() && (u = n, d = e.getElementById(u), console.warn(`applyLayout: "${t}" not found — using "${u}" instead`));
59
+ }
60
+ d.empty() ? console.warn(`applyLayout: node "${t}" not found`) : c.has(u) ? console.warn(`applyLayout: duplicate layout entry for node "${u}" (from "${t}") — keeping the first position`) : (c.add(u), d.position({
61
+ x: r + (l + s) * a,
62
+ y: i + (n + s) * o
63
+ }));
64
+ });
65
+ });
66
+ }
67
+ function I(e, t) {
68
+ let n = e, r = 2;
69
+ for (; t.has(n);) n = `${e}_${r++}`;
70
+ return t.add(n), n;
71
+ }
72
+ function ne(e, t = 10) {
73
+ let n = Math.max(1, Math.floor(t) || 1), r = e.filter((e) => e.data.class === k), i = e.filter((e) => e.data.class === A).map((e) => r.filter((t) => t.data.parent === e.data.id));
74
+ i.push(r.filter((e) => !e.data.parent));
75
+ let a = [];
76
+ for (let e of i) for (let t = 0; t < e.length; t += n) a.push(e.slice(t, t + n).map((e) => e.data.id));
77
+ return a;
78
+ }
79
+ function L(e = {}, t = [], n = []) {
80
+ let r = [], i = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set([...t.flat(), ...n]);
81
+ for (let t of Object.values(e)) for (let e of t) i.add(e);
82
+ for (let e of a) i.add(e);
83
+ let o = (e) => {
84
+ let t = e.replace(/\s+/g, "");
85
+ return t ? t.charAt(0).toLowerCase() + t.slice(1) : "folder";
86
+ }, s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
87
+ for (let [t, n] of Object.entries(e)) {
88
+ let e = I(o(t), i);
89
+ c.set(t, e), r.push({ data: {
90
+ id: e,
91
+ class: A,
92
+ label: t
93
+ } });
94
+ for (let e of n) {
95
+ let n = s.get(e) ?? [], r = e;
96
+ if (n.length > 0) {
97
+ let t = n.length;
98
+ for (r = `${e}(${t})`; i.has(r);) r = `${e}(${++t})`;
99
+ i.add(r);
100
+ }
101
+ n.push({
102
+ actualId: r,
103
+ folderLabel: t
104
+ }), s.set(e, n);
105
+ }
106
+ }
107
+ let l = [];
108
+ for (let [e, t] of s) for (let { actualId: n, folderLabel: r } of t) l.push({
109
+ actualId: n,
110
+ originalId: e,
111
+ folderLabel: r
112
+ });
113
+ for (let e of a) s.has(e) || l.push({
114
+ actualId: e,
115
+ originalId: e,
116
+ folderLabel: null
117
+ });
118
+ for (let { actualId: e, originalId: t, folderLabel: n } of l) {
119
+ let i = {
120
+ id: e,
121
+ class: k,
122
+ rawLabel: t,
123
+ displayLabel: n ? `${t} (${n})` : t,
124
+ group: n
125
+ };
126
+ n && (i.parent = c.get(n)), r.push({ data: i });
127
+ }
128
+ let u = (e) => s.get(e)?.[0]?.actualId ?? e, d = (e, t) => `${e}->${t}`, f = /* @__PURE__ */ new Map();
129
+ return t.forEach(([e, t], n) => {
130
+ let a = u(e), o = u(t);
131
+ if (f.has(d(a, o))) return;
132
+ let s = f.get(d(o, a));
133
+ if (s) {
134
+ s.classes = "bidirectional";
135
+ return;
136
+ }
137
+ let c = { data: {
138
+ id: I(`e${n + 1}`, i),
139
+ source: a,
140
+ target: o
141
+ } };
142
+ f.set(d(a, o), c), r.push(c);
143
+ }), r;
144
+ }
145
+ function re(e, t, n) {
146
+ return e.filter((e) => t || e.data.class !== A).map((e) => {
147
+ if (e.data.class !== k) return {
148
+ ...e,
149
+ data: { ...e.data }
150
+ };
151
+ let t = n ? e.data.displayLabel : e.data.rawLabel;
152
+ return {
153
+ ...e,
154
+ data: {
155
+ ...e.data,
156
+ graphLabel: t
157
+ }
158
+ };
159
+ });
160
+ }
161
+ function R(e, t = !1) {
162
+ let n = (e) => ({
163
+ id: e.id(),
164
+ name: e.data("rawLabel") ?? e.id(),
165
+ group: e.data("group") ?? null
166
+ }), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
167
+ if (e.connectedEdges().forEach((t) => {
168
+ let a = t.hasClass("bidirectional");
169
+ t.target().same(e) && (r.set(t.source().id(), n(t.source())), a && i.set(t.source().id(), n(t.source()))), t.source().same(e) && (i.set(t.target().id(), n(t.target())), a && r.set(t.target().id(), n(t.target())));
170
+ }), t) {
171
+ let t = [[r, "parents"], [i, "children"]];
172
+ for (let [r, i] of t) r.clear(), z(e, i).nodes().forEach((t) => {
173
+ t.same(e) || r.set(t.id(), n(t));
174
+ });
175
+ }
176
+ let a = (e, t) => P(e.name, t.name);
177
+ return {
178
+ ...n(e),
179
+ parents: [...r.values()].sort(a),
180
+ children: [...i.values()].sort(a)
181
+ };
182
+ }
183
+ function z(e, t) {
184
+ let n = t === "parents", r = e.cy().collection(), i = /* @__PURE__ */ new Set([e.id()]), a = [e];
185
+ for (let e = a.shift(); e !== void 0; e = a.shift()) {
186
+ let t = e;
187
+ t.connectedEdges().forEach((e) => {
188
+ let o = e.hasClass("bidirectional"), s = null;
189
+ e.target().same(t) && (n || o) && (s = e.source()), e.source().same(t) && (!n || o) && (s = e.target()), s && (r = r.union(e), i.has(s.id()) || (i.add(s.id()), a.push(s)));
190
+ });
191
+ }
192
+ return r.union(e.cy().nodes().filter((e) => i.has(e.id())));
193
+ }
194
+ function ie(e) {
195
+ return [["Parent Nodes", e.parents], ["Child Nodes", e.children]].filter(([, e]) => e.length > 0);
196
+ }
197
+ function ae(e, t) {
198
+ let n = e.nodes(j).filter((e) => t.has(e.id())), r = e.nodes(":parent").filter((e) => e.children().every((e) => n.has(e)));
199
+ return n.union(r);
200
+ }
201
+ function B(e) {
202
+ let t = (e) => e.group ? `${e.name} (${e.group})` : e.name, n = [`Node: ${e.name}`];
203
+ e.group && n.push(`Group: ${e.group}`);
204
+ for (let [r, i] of ie(e)) n.push("", `${r} (${i.length}):`, ...i.map(t));
205
+ return n.join("\n");
206
+ }
207
+ function oe(e) {
208
+ let t = /^#([0-9a-f]{6})$/i.exec(e)?.[1];
209
+ if (t !== void 0) return parseInt(t, 16);
210
+ let n = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i.exec(e);
211
+ if (n === null) return null;
212
+ let [r = 0, i = 0, a = 0] = n.slice(1).map((e) => Math.min(Number(e), 255));
213
+ return r << 16 | i << 8 | a;
214
+ }
215
+ function V(e, t = .88) {
216
+ let n = oe(e);
217
+ return n === null ? "#ffffff" : `#${[
218
+ 16,
219
+ 8,
220
+ 0
221
+ ].map((e) => {
222
+ let r = n >> e & 255;
223
+ return Math.round(r + (255 - r) * t).toString(16).padStart(2, "0");
224
+ }).join("")}`;
225
+ }
226
+ function se(e, t, n = p) {
227
+ let r = ["track", "track2"], i = r.flatMap((e) => [
228
+ `${e}-parents`,
229
+ `${e}-children`,
230
+ `${e}-root`
231
+ ]).concat("faded", "track-mixed").join(" ");
232
+ e.batch(() => {
233
+ e.elements().removeClass(i).removeData("trackMixColor trackMixFill");
234
+ let a = t.map(({ id: t, direction: n }, i) => {
235
+ if (!t) return null;
236
+ let a = e.getElementById(t);
237
+ if (a.empty()) return null;
238
+ let o = z(a, n), s = r[i] ?? "track";
239
+ return o.addClass(`${s}-${n}`), a.addClass(`${s}-root`), o;
240
+ }), o = a.filter((e) => e !== null);
241
+ if (o.length === 0) return;
242
+ let [s, c] = a;
243
+ s && c && s.intersection(c).forEach((e) => {
244
+ e.data({
245
+ trackMixColor: n,
246
+ trackMixFill: V(n)
247
+ }), e.addClass("track-mixed");
248
+ });
249
+ let l = o.reduce((e, t) => e.union(t));
250
+ e.elements().not(l).not("node:parent").addClass("faded");
251
+ });
252
+ }
253
+ function H({ selectedColor: e = c, parentsColor: t = l, childrenColor: n = u, track2ParentsColor: r = d, track2ChildrenColor: i = f } = {}) {
254
+ return [
255
+ {
256
+ selector: "node",
257
+ style: {
258
+ "background-color": _,
259
+ label: "data(graphLabel)",
260
+ shape: "rectangle",
261
+ "font-family": E,
262
+ "font-size": C,
263
+ color: g,
264
+ "border-width": 2,
265
+ "border-color": g,
266
+ "text-valign": "center",
267
+ "text-halign": "center"
268
+ }
269
+ },
270
+ {
271
+ selector: "node:parent",
272
+ style: {
273
+ "background-color": v,
274
+ "background-opacity": .5,
275
+ "border-style": "dashed",
276
+ label: "data(label)",
277
+ "text-valign": "top",
278
+ "font-size": w,
279
+ "font-weight": "bold",
280
+ padding: "18px"
281
+ }
282
+ },
283
+ {
284
+ selector: ".selected",
285
+ style: {
286
+ "overlay-color": e,
287
+ "overlay-opacity": .35,
288
+ "overlay-padding": 8
289
+ }
290
+ },
291
+ {
292
+ selector: "edge",
293
+ style: {
294
+ "line-color": g,
295
+ width: 2,
296
+ "curve-style": "bezier",
297
+ "target-arrow-shape": "vee",
298
+ "target-arrow-color": g,
299
+ "target-arrow-fill": "filled",
300
+ "arrow-scale": 2
301
+ }
302
+ },
303
+ {
304
+ selector: "edge:loop",
305
+ style: {
306
+ "loop-direction": "0deg",
307
+ "loop-sweep": "-50deg",
308
+ "control-point-step-size": 70
309
+ }
310
+ },
311
+ {
312
+ selector: "edge.bidirectional",
313
+ style: {
314
+ "source-arrow-shape": "vee",
315
+ "source-arrow-color": g,
316
+ "source-arrow-fill": "filled"
317
+ }
318
+ },
319
+ {
320
+ selector: ".faded",
321
+ style: { opacity: .15 }
322
+ },
323
+ ...[
324
+ [
325
+ "track-parents",
326
+ "track-root",
327
+ t
328
+ ],
329
+ [
330
+ "track-children",
331
+ "track-root",
332
+ n
333
+ ],
334
+ [
335
+ "track2-parents",
336
+ "track2-root",
337
+ r
338
+ ],
339
+ [
340
+ "track2-children",
341
+ "track2-root",
342
+ i
343
+ ]
344
+ ].flatMap(([e, t, n]) => [
345
+ {
346
+ selector: `edge.${e}`,
347
+ style: {
348
+ "line-color": n,
349
+ "target-arrow-color": n,
350
+ "source-arrow-color": n,
351
+ width: 4
352
+ }
353
+ },
354
+ {
355
+ selector: `node.${e}`,
356
+ style: {
357
+ "border-color": n,
358
+ "border-width": 3
359
+ }
360
+ },
361
+ {
362
+ selector: `node.${e}.${t}`,
363
+ style: {
364
+ "border-width": 5,
365
+ "background-color": V(n)
366
+ }
367
+ }
368
+ ]),
369
+ {
370
+ selector: "edge.track-mixed",
371
+ style: {
372
+ "line-color": "data(trackMixColor)",
373
+ "target-arrow-color": "data(trackMixColor)",
374
+ "source-arrow-color": "data(trackMixColor)",
375
+ width: 5
376
+ }
377
+ },
378
+ {
379
+ selector: "node.track-mixed",
380
+ style: {
381
+ "border-color": "data(trackMixColor)",
382
+ "border-width": 4
383
+ }
384
+ },
385
+ {
386
+ selector: "node.track-mixed.track-root, node.track-mixed.track2-root",
387
+ style: {
388
+ "border-width": 6,
389
+ "background-color": "data(trackMixFill)"
390
+ }
391
+ },
392
+ {
393
+ selector: ".hidden",
394
+ style: { display: "none" }
395
+ }
396
+ ];
397
+ }
398
+ var U = "ALL";
399
+ function W({ id: t, options: i, selectedId: a, onSelect: c, noneLabel: l = U, hiddenIds: u, onToggleVisible: d }) {
400
+ let [f, p] = r(""), [m, h] = r(""), [g, _] = r(!1), [v, y] = r(0), b = n(null), x = n(null), S = i.find((e) => e.id === a)?.label ?? "", [C, w] = r(null);
401
+ C !== S && (w(S), p(S));
402
+ let T = m.trim().toLowerCase(), E = T ? i.filter((e) => e.label.toLowerCase().includes(T)) : i, D = {
403
+ id: "",
404
+ label: l
405
+ }, O = !T || l.toLowerCase().includes(T) ? [D, ...E] : E, k = () => {
406
+ h(""), y(0), _(!0);
407
+ }, A = () => {
408
+ _(!1), h(""), p(S);
409
+ }, j = (e) => {
410
+ c(e.id), p(e.id ? e.label : ""), h(""), _(!1);
411
+ };
412
+ return e(() => {
413
+ if (!g) return;
414
+ let e = (e) => {
415
+ b.current?.contains(e.target) || A();
416
+ };
417
+ return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
418
+ }), e(() => {
419
+ x.current?.children[v]?.scrollIntoView({ block: "nearest" });
420
+ }, [v, g]), /* @__PURE__ */ s("div", {
421
+ className: "node-search",
422
+ ref: b,
423
+ children: [
424
+ /* @__PURE__ */ o("input", {
425
+ id: t,
426
+ type: "text",
427
+ value: f,
428
+ placeholder: "-- type to search --",
429
+ autoComplete: "off",
430
+ onChange: (e) => {
431
+ p(e.target.value), h(e.target.value), y(0), _(!0);
432
+ },
433
+ onFocus: (e) => {
434
+ e.target.select(), k();
435
+ },
436
+ onClick: () => {
437
+ g || k();
438
+ },
439
+ onKeyDown: (e) => {
440
+ if (e.key === "ArrowDown") e.preventDefault(), g || _(!0), y((e) => Math.min(e + 1, O.length - 1));
441
+ else if (e.key === "ArrowUp") e.preventDefault(), y((e) => Math.max(e - 1, 0));
442
+ else if (e.key === "Enter" && g) {
443
+ let t = O[v];
444
+ t && (e.preventDefault(), j(t));
445
+ } else e.key === "Escape" && A();
446
+ }
447
+ }),
448
+ f && /* @__PURE__ */ o("button", {
449
+ type: "button",
450
+ className: "node-search-clear",
451
+ "aria-label": "Clear",
452
+ onClick: () => {
453
+ c(""), p(""), h("");
454
+ },
455
+ children: "×"
456
+ }),
457
+ g && /* @__PURE__ */ o("ul", {
458
+ className: "node-search-list",
459
+ ref: x,
460
+ role: "listbox",
461
+ children: O.length === 0 ? /* @__PURE__ */ o("li", {
462
+ className: "node-search-empty",
463
+ role: "option",
464
+ "aria-selected": "false",
465
+ "aria-disabled": "true",
466
+ children: "no match"
467
+ }) : O.map((e, t) => /* @__PURE__ */ s("li", {
468
+ role: "option",
469
+ "aria-selected": t === v,
470
+ className: [t === v && "active", u?.has(e.id) && "off"].filter(Boolean).join(" ") || void 0,
471
+ onMouseDown: (t) => {
472
+ t.preventDefault(), j(e);
473
+ },
474
+ onMouseEnter: () => y(t),
475
+ children: [d && e.id && /* @__PURE__ */ o("input", {
476
+ type: "checkbox",
477
+ checked: !u?.has(e.id),
478
+ "aria-label": `Show ${e.label}`,
479
+ onMouseDown: (e) => {
480
+ e.preventDefault(), e.stopPropagation();
481
+ },
482
+ onClick: (e) => e.stopPropagation(),
483
+ onChange: () => d(e.id)
484
+ }), e.label]
485
+ }, e.id || "__none__"))
486
+ })
487
+ ]
488
+ });
489
+ }
490
+ function G(a = {}, g = [], _ = null, v = {}) {
491
+ let E = Array.isArray(_) ? _ : null, D = _ !== null && !Array.isArray(_) ? _ : v, O = E !== null && E.length > 0, { selectedColor: k = c, parentsColor: A = l, childrenColor: M = u, track2ParentsColor: N = d, track2ChildrenColor: I = f, commonColor: z = p, topControlsFontSize: oe = m, rightDisplayFontSize: V = h, layoutColumns: U = 10 } = D, G = H({
492
+ selectedColor: k,
493
+ parentsColor: A,
494
+ childrenColor: M,
495
+ track2ParentsColor: N,
496
+ track2ChildrenColor: I
497
+ }), ce = {
498
+ "--rbg-parents-color": A,
499
+ "--rbg-children-color": M
500
+ }, le = {
501
+ "--rbg-parents-color": N,
502
+ "--rbg-children-color": I
503
+ }, K = L(a, g, E !== null && O ? E.flat() : []), ue = E !== null && O ? F(E) : ne(K, U);
504
+ function q() {
505
+ let a = n(null), c = n(null), l = t(), [u, d] = r([]), [f, p] = r(""), [m, h] = r(0), [g, _] = r(""), [v, E] = r("parents"), [O, k] = r(""), [A, M] = r("parents"), [N, F] = r(!0), [I, ne] = r(!0), [L, H] = r(null), [U, q] = r(null), [J, de] = r("top"), [Y, fe] = r({
506
+ top: 0,
507
+ right: 0,
508
+ graph: 0
509
+ }), [X, pe] = r(!1), Z = n(!1);
510
+ e(() => {
511
+ Z.current = X;
512
+ }, [X]);
513
+ let [Q, me] = r(() => /* @__PURE__ */ new Set());
514
+ e(() => {
515
+ let e = a.current;
516
+ if (!e) return;
517
+ let t = i({
518
+ container: e,
519
+ elements: re(K, N, I),
520
+ style: G,
521
+ layout: {
522
+ name: "preset",
523
+ fit: !1
524
+ }
525
+ });
526
+ t.on("cxttap", j, (e) => {
527
+ let t = B(R(e.target, Z.current)), { clientX: n, clientY: r } = e.originalEvent;
528
+ H({
529
+ x: n,
530
+ y: r,
531
+ copyText: t
532
+ });
533
+ }), t.on("dbltap", j, (e) => {
534
+ q(R(e.target, Z.current));
535
+ }), t.on("tap cxttap", (e) => {
536
+ e.target === t && H(null);
537
+ }), t.on("tap", "node", () => H(null)), t.on("viewport", () => H(null));
538
+ let n = (e) => e.preventDefault();
539
+ return e.addEventListener("contextmenu", n), te(t, ue, D), requestAnimationFrame(() => t.resize()), d(t.nodes(j).map((e) => ({
540
+ id: e.id(),
541
+ label: e.data("displayLabel")
542
+ })).sort((e, t) => P(e.label, t.label))), c.current = t, () => {
543
+ e.removeEventListener("contextmenu", n), H(null), t.destroy(), c.current = null;
544
+ };
545
+ }, [N, I]), e(() => {
546
+ let e = c.current;
547
+ if (!e) return;
548
+ let t = Y.graph;
549
+ e.batch(() => {
550
+ e.nodes(j).forEach((e) => {
551
+ let n = C + t, { width: r, height: i } = ee(e.data("graphLabel"), n);
552
+ e.style({
553
+ "font-size": n,
554
+ width: r,
555
+ height: i
556
+ });
557
+ }), e.nodes(":parent").style("font-size", w + t);
558
+ });
559
+ }, [
560
+ Y.graph,
561
+ N,
562
+ I
563
+ ]), e(() => {
564
+ if (!L) return;
565
+ let e = (e) => {
566
+ e.target.closest(".node-context-menu") || H(null);
567
+ }, t = (e) => {
568
+ e.key === "Escape" && H(null);
569
+ };
570
+ return document.addEventListener("mousedown", e), document.addEventListener("keydown", t), () => {
571
+ document.removeEventListener("mousedown", e), document.removeEventListener("keydown", t);
572
+ };
573
+ }, [L]);
574
+ let he = () => {
575
+ if (L === null) return;
576
+ let { copyText: e } = L;
577
+ H(null), navigator.clipboard.writeText(e).catch((e) => {
578
+ console.error("Failed to copy:", e);
579
+ });
580
+ }, ge = () => {
581
+ c.current && y(c.current);
582
+ }, $ = (e) => {
583
+ me((t) => {
584
+ let n = new Set(t);
585
+ return n.has(e) ? n.delete(e) : n.add(e), n;
586
+ });
587
+ }, _e = (e) => {
588
+ let t = c.current?.getElementById(e);
589
+ t && !t.empty() && (Q.has(e) && $(e), p(e), q(R(t, X)));
590
+ }, ve = () => {
591
+ p(""), q(null), h((e) => e + 1);
592
+ };
593
+ e(() => {
594
+ let e = c.current;
595
+ e && e.batch(() => {
596
+ e.elements().removeClass("hidden"), ae(e, Q).addClass("hidden");
597
+ });
598
+ }, [
599
+ Q,
600
+ N,
601
+ I
602
+ ]), e(() => {
603
+ let e = c.current;
604
+ m && e && (e.stop(), e.resize(), e.animate({ fit: {
605
+ eles: e.elements().not(".hidden"),
606
+ padding: 30
607
+ } }, { duration: 400 }));
608
+ }, [m]), e(() => {
609
+ let e = c.current;
610
+ if (!e || (e.nodes().removeClass("selected"), !f)) return;
611
+ let t = e.getElementById(f);
612
+ t.nonempty() && (t.addClass("selected"), e.animate({
613
+ center: { eles: t },
614
+ zoom: 1.8
615
+ }, { duration: 400 }));
616
+ }, [
617
+ f,
618
+ N,
619
+ I
620
+ ]), e(() => {
621
+ let e = c.current;
622
+ e && se(e, [{
623
+ id: g,
624
+ direction: v
625
+ }, {
626
+ id: O,
627
+ direction: A
628
+ }], z);
629
+ }, [
630
+ g,
631
+ v,
632
+ O,
633
+ A,
634
+ N,
635
+ I
636
+ ]), e(() => {
637
+ c.current?.resize();
638
+ }, [U !== null]), e(() => {
639
+ let e = () => c.current?.resize();
640
+ return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
641
+ }, []);
642
+ let ye = [{
643
+ n: 1,
644
+ id: g,
645
+ setId: _,
646
+ direction: v,
647
+ setDirection: E,
648
+ style: void 0
649
+ }, {
650
+ n: 2,
651
+ id: O,
652
+ setId: k,
653
+ direction: A,
654
+ setDirection: M,
655
+ style: le
656
+ }], be = [{
657
+ label: "Smaller text",
658
+ symbol: "−",
659
+ step: -2,
660
+ atLimit: Y[J] <= x
661
+ }, {
662
+ label: "Larger text",
663
+ symbol: "+",
664
+ step: b,
665
+ atLimit: Y[J] >= S
666
+ }];
667
+ return /* @__PURE__ */ s("div", {
668
+ className: "rbg-graph",
669
+ style: {
670
+ ...ce,
671
+ "--rbg-top-controls-font-size": `calc(${oe} + ${Y.top}px)`,
672
+ "--rbg-right-display-font-size": `calc(${V} + ${Y.right}px)`
673
+ },
674
+ children: [
675
+ /* @__PURE__ */ s("div", {
676
+ className: "controls",
677
+ children: [
678
+ /* @__PURE__ */ s("span", {
679
+ className: "control-group",
680
+ children: [/* @__PURE__ */ o("label", {
681
+ htmlFor: `${l}-search`,
682
+ children: "Node to Display:"
683
+ }), /* @__PURE__ */ o(W, {
684
+ id: `${l}-search`,
685
+ options: u,
686
+ selectedId: f,
687
+ onSelect: (e) => e ? _e(e) : ve(),
688
+ hiddenIds: Q,
689
+ onToggleVisible: $
690
+ })]
691
+ }),
692
+ /* @__PURE__ */ s("label", { children: [/* @__PURE__ */ o("input", {
693
+ type: "checkbox",
694
+ checked: N,
695
+ onChange: (e) => F(e.target.checked)
696
+ }), "Show Groups"] }),
697
+ /* @__PURE__ */ s("label", { children: [/* @__PURE__ */ o("input", {
698
+ type: "checkbox",
699
+ checked: I,
700
+ onChange: (e) => ne(e.target.checked)
701
+ }), "Add Group to Node Name"] }),
702
+ ye.map(({ n: e, id: t, setId: n, direction: r, setDirection: i, style: a }) => /* @__PURE__ */ s("span", {
703
+ className: "control-group",
704
+ style: a,
705
+ children: [
706
+ /* @__PURE__ */ s("label", {
707
+ htmlFor: `${l}-track${e}`,
708
+ children: [
709
+ "Show Dependency ",
710
+ e,
711
+ ":"
712
+ ]
713
+ }),
714
+ /* @__PURE__ */ o(W, {
715
+ id: `${l}-track${e}`,
716
+ options: u,
717
+ selectedId: t,
718
+ onSelect: n,
719
+ noneLabel: "Show Nothing"
720
+ }),
721
+ /* @__PURE__ */ s("span", {
722
+ className: t ? "track-switch" : "track-switch disabled",
723
+ children: [
724
+ /* @__PURE__ */ o("span", {
725
+ className: r === "parents" ? "parents on" : "parents",
726
+ children: "Parents"
727
+ }),
728
+ /* @__PURE__ */ o("button", {
729
+ type: "button",
730
+ role: "switch",
731
+ "aria-checked": r === "children",
732
+ "aria-label": `Show Dependency ${e}: track children instead of parents`,
733
+ className: "switch",
734
+ disabled: !t,
735
+ onClick: () => i((e) => e === "parents" ? "children" : "parents"),
736
+ children: /* @__PURE__ */ o("span", { className: "switch-knob" })
737
+ }),
738
+ /* @__PURE__ */ o("span", {
739
+ className: r === "children" ? "children on" : "children",
740
+ children: "Children"
741
+ })
742
+ ]
743
+ })
744
+ ]
745
+ }, e)),
746
+ /* @__PURE__ */ s("span", {
747
+ className: "help",
748
+ children: [/* @__PURE__ */ o("button", {
749
+ type: "button",
750
+ className: "help-icon",
751
+ "aria-label": "Help",
752
+ "aria-describedby": `${l}-help`,
753
+ children: "?"
754
+ }), /* @__PURE__ */ s("span", {
755
+ id: `${l}-help`,
756
+ role: "tooltip",
757
+ className: "help-tooltip",
758
+ children: [
759
+ /* @__PURE__ */ o("strong", { children: "Double click" }),
760
+ " on a node to see its information, parents and children.",
761
+ /* @__PURE__ */ o("br", {}),
762
+ /* @__PURE__ */ o("strong", { children: "Right click" }),
763
+ " on a node to save the same information to the clipboard."
764
+ ]
765
+ })]
766
+ }),
767
+ /* @__PURE__ */ s("span", {
768
+ className: "font-size-buttons",
769
+ children: [/* @__PURE__ */ o("select", {
770
+ "aria-label": "Area whose text size the + and - buttons change",
771
+ value: J,
772
+ onChange: (e) => de(e.target.value),
773
+ children: T.map(([e, t]) => /* @__PURE__ */ o("option", {
774
+ value: e,
775
+ children: t
776
+ }, e))
777
+ }), be.map(({ label: e, symbol: t, step: n, atLimit: r }) => /* @__PURE__ */ o("button", {
778
+ type: "button",
779
+ className: "help-icon",
780
+ "aria-label": e,
781
+ disabled: r,
782
+ onClick: () => fe((e) => ({
783
+ ...e,
784
+ [J]: e[J] + n
785
+ })),
786
+ children: t
787
+ }, e))]
788
+ }),
789
+ /* @__PURE__ */ o("button", {
790
+ type: "button",
791
+ className: "export-svg",
792
+ onClick: ge,
793
+ children: "Export SVG"
794
+ })
795
+ ]
796
+ }),
797
+ /* @__PURE__ */ s("div", {
798
+ className: "graph-area",
799
+ children: [/* @__PURE__ */ o("div", {
800
+ ref: a,
801
+ className: "cy-container"
802
+ }), U && /* @__PURE__ */ s("aside", {
803
+ className: "node-info-panel",
804
+ children: [
805
+ /* @__PURE__ */ s("div", {
806
+ className: "node-info-header",
807
+ children: [/* @__PURE__ */ s("h2", { children: [
808
+ /* @__PURE__ */ o("strong", { children: "Node:" }),
809
+ " ",
810
+ U.name
811
+ ] }), /* @__PURE__ */ o("button", {
812
+ type: "button",
813
+ onClick: () => q(null),
814
+ "aria-label": "Close",
815
+ children: "×"
816
+ })]
817
+ }),
818
+ U.group && /* @__PURE__ */ s("p", { children: [
819
+ /* @__PURE__ */ o("strong", { children: "Group:" }),
820
+ " ",
821
+ U.group
822
+ ] }),
823
+ /* @__PURE__ */ s("div", {
824
+ className: "track-switch level-switch",
825
+ children: [
826
+ /* @__PURE__ */ o("span", {
827
+ className: X ? "" : "parents on",
828
+ children: "One level"
829
+ }),
830
+ /* @__PURE__ */ o("button", {
831
+ type: "button",
832
+ role: "switch",
833
+ "aria-checked": X,
834
+ "aria-label": "Show all levels of parents and children",
835
+ className: "switch",
836
+ onClick: () => {
837
+ let e = !X;
838
+ pe(e);
839
+ let t = c.current?.getElementById(U.id);
840
+ t && !t.empty() && q(R(t, e));
841
+ },
842
+ children: /* @__PURE__ */ o("span", { className: "switch-knob" })
843
+ }),
844
+ /* @__PURE__ */ o("span", {
845
+ className: X ? "children on" : "",
846
+ children: "All levels"
847
+ })
848
+ ]
849
+ }),
850
+ ie(U).map(([e, t]) => /* @__PURE__ */ s("section", { children: [/* @__PURE__ */ s("h3", { children: [
851
+ e,
852
+ " (",
853
+ t.length,
854
+ "):"
855
+ ] }), /* @__PURE__ */ o("ul", { children: t.map((e) => /* @__PURE__ */ o("li", { children: /* @__PURE__ */ s("button", {
856
+ type: "button",
857
+ onClick: () => _e(e.id),
858
+ children: [e.name, e.group && /* @__PURE__ */ s("span", { children: [
859
+ " (",
860
+ e.group,
861
+ ")"
862
+ ] })]
863
+ }) }, e.id)) })] }, e))
864
+ ]
865
+ })]
866
+ }),
867
+ L && /* @__PURE__ */ o("div", {
868
+ className: "node-context-menu",
869
+ style: {
870
+ left: L.x,
871
+ top: L.y
872
+ },
873
+ onContextMenu: (e) => e.preventDefault(),
874
+ children: /* @__PURE__ */ o("button", {
875
+ type: "button",
876
+ onClick: he,
877
+ children: "Save to clipboard"
878
+ })
879
+ })
880
+ ]
881
+ });
882
+ }
883
+ return q.displayName = "CytoscapeGraph", q;
884
+ }
885
+ export { W as NodeSearch, G as create_graph, y as downloadSvg, B as formatNodeInfo, R as getNodeInfo };
886
+
887
+ //# sourceMappingURL=index.js.map