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