@salilvnair/dui 1.0.17 → 1.0.18

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/vis-setup.js CHANGED
@@ -1,9 +1,9 @@
1
- import { m as Xt, r as Yt } from "./chunks/vis-runtime-DkpA8K_T.js";
2
- import { jsxs as Ut, jsx as Mt } from "react/jsx-runtime";
3
- import { useRef as M, useEffect as Et } from "react";
4
- import { DataSet as Rt } from "vis-data/peer";
5
- import { Network as Kt } from "vis-network/peer";
6
- const ut = [
1
+ import { m as ne, r as oe } from "./chunks/vis-runtime-DkpA8K_T.js";
2
+ import { jsxs as re, jsx as At } from "react/jsx-runtime";
3
+ import { useRef as w, useMemo as It, useEffect as at } from "react";
4
+ import { DataSet as Yt } from "vis-data/peer";
5
+ import { Network as ie } from "vis-network/peer";
6
+ const bt = [
7
7
  "#4E79A7",
8
8
  "#F28E2B",
9
9
  "#E15759",
@@ -14,7 +14,7 @@ const ut = [
14
14
  "#FF9DA7",
15
15
  "#9C755F",
16
16
  "#BAB0AC"
17
- ], at = 0.12, Vt = 300, Zt = 0.45, Tt = 220, qt = 120, lt = 96, kt = {
17
+ ], mt = 0.12, se = 300, ce = 0.45, Kt = 220, ae = 120, yt = 96, Pt = {
18
18
  dark: {
19
19
  text: "#d4d4d4",
20
20
  chipBg: "rgba(37, 37, 38, 0.85)",
@@ -32,51 +32,51 @@ const ut = [
32
32
  viewportStroke: "#1f2328"
33
33
  }
34
34
  };
35
- function Wt(e) {
36
- return e.color ? e.color : e.communityId != null ? ut[e.communityId % ut.length] : "#6B7280";
35
+ function Lt(e) {
36
+ return e.color ? e.color : e.communityId != null ? bt[e.communityId % bt.length] : "#6B7280";
37
37
  }
38
- const Jt = (e, s) => e.left < s.right && e.right > s.left && e.top < s.bottom && e.bottom > s.top;
39
- function Qt() {
40
- const e = /* @__PURE__ */ new Map(), s = (i, c) => i * 73856093 ^ c * 19349663, f = (i, c) => {
41
- const m = Math.floor(i.left / lt), C = Math.floor(i.right / lt), O = Math.floor(i.top / lt), K = Math.floor(i.bottom / lt);
42
- for (let N = m; N <= C; N++) for (let x = O; x <= K; x++) c(s(N, x));
38
+ const le = (e, a) => e.left < a.right && e.right > a.left && e.top < a.bottom && e.bottom > a.top;
39
+ function ue() {
40
+ const e = /* @__PURE__ */ new Map(), a = (c, d) => c * 73856093 ^ d * 19349663, g = (c, d) => {
41
+ const E = Math.floor(c.left / yt), B = Math.floor(c.right / yt), I = Math.floor(c.top / yt), Q = Math.floor(c.bottom / yt);
42
+ for (let K = E; K <= B; K++) for (let S = I; S <= Q; S++) d(a(K, S));
43
43
  };
44
44
  return {
45
- collides(i) {
46
- let c = !1;
47
- return f(i, (m) => {
48
- if (c) return;
49
- const C = e.get(m);
50
- if (C) {
51
- for (let O = 0; O < C.length; O++) if (Jt(i, C[O])) {
52
- c = !0;
45
+ collides(c) {
46
+ let d = !1;
47
+ return g(c, (E) => {
48
+ if (d) return;
49
+ const B = e.get(E);
50
+ if (B) {
51
+ for (let I = 0; I < B.length; I++) if (le(c, B[I])) {
52
+ d = !0;
53
53
  return;
54
54
  }
55
55
  }
56
- }), c;
56
+ }), d;
57
57
  },
58
- insert(i) {
59
- f(i, (c) => {
60
- const m = e.get(c);
61
- m ? m.push(i) : e.set(c, [i]);
58
+ insert(c) {
59
+ g(c, (d) => {
60
+ const E = e.get(d);
61
+ E ? E.push(c) : e.set(d, [c]);
62
62
  });
63
63
  }
64
64
  };
65
65
  }
66
- function te(e) {
67
- const s = document.createElement("div");
68
- return s.style.position = "absolute", s.style.borderRadius = "9999px", s.style.letterSpacing = "0.01em", s.style.whiteSpace = "nowrap", s.style.pointerEvents = "none", s.style.display = "none", e == null || e.appendChild(s), s;
66
+ function de(e) {
67
+ const a = document.createElement("div");
68
+ return a.style.position = "absolute", a.style.borderRadius = "9999px", a.style.letterSpacing = "0.01em", a.style.whiteSpace = "nowrap", a.style.pointerEvents = "none", a.style.display = "none", e == null || e.appendChild(a), a;
69
69
  }
70
- function _t(e, s, f) {
71
- e.textContent !== s && (e.textContent = s), e.style.padding !== f.padding && (e.style.padding = f.padding);
72
- const i = `${f.fontSize}px`;
73
- e.style.fontSize !== i && (e.style.fontSize = i);
74
- const c = String(f.fontWeight);
75
- e.style.fontWeight !== c && (e.style.fontWeight = c), e.style.background !== f.bg && (e.style.background = f.bg);
76
- const m = `1px solid ${f.border}`;
77
- e.style.border !== m && (e.style.border = m), e.style.color !== f.color && (e.style.color = f.color);
70
+ function Vt(e, a, g) {
71
+ e.textContent !== a && (e.textContent = a), e.style.padding !== g.padding && (e.style.padding = g.padding);
72
+ const c = `${g.fontSize}px`;
73
+ e.style.fontSize !== c && (e.style.fontSize = c);
74
+ const d = String(g.fontWeight);
75
+ e.style.fontWeight !== d && (e.style.fontWeight = d), e.style.background !== g.bg && (e.style.background = g.bg);
76
+ const E = `1px solid ${g.border}`;
77
+ e.style.border !== E && (e.style.border = E), e.style.color !== g.color && (e.style.color = g.color);
78
78
  }
79
- function ee(e) {
79
+ function fe(e) {
80
80
  return {
81
81
  color: e,
82
82
  bg: `color-mix(in srgb, ${e} 16%, transparent)`,
@@ -86,7 +86,7 @@ function ee(e) {
86
86
  padding: "3px 9px"
87
87
  };
88
88
  }
89
- function ne(e) {
89
+ function he(e) {
90
90
  return {
91
91
  color: e.text,
92
92
  bg: e.chipBg,
@@ -96,72 +96,83 @@ function ne(e) {
96
96
  padding: "2px 7px"
97
97
  };
98
98
  }
99
- function $t(e, s, f) {
100
- const i = new Set(f.filter((x) => x.communityId === s).map((x) => x.id));
101
- if (i.size < 2) return;
102
- for (const x of i)
103
- if (!e.findNode(x).length || e.isCluster(x)) return;
104
- const c = ut[s % ut.length], m = `cluster:community:${s}`, C = `Community ${s} (${i.size})`, O = Math.min(20 + i.size * 2, 60), K = Math.max(11, Math.min(16, Math.round(O * 0.32))), N = -(O + K * 0.5);
99
+ function Zt(e, a, g) {
100
+ const c = new Set(g.filter((S) => S.communityId === a).map((S) => S.id));
101
+ if (c.size < 2) return;
102
+ for (const S of c)
103
+ if (!e.findNode(S).length || e.isCluster(S)) return;
104
+ const d = bt[a % bt.length], E = `cluster:community:${a}`, B = `Community ${a} (${c.size})`, I = Math.min(20 + c.size * 2, 60), Q = Math.max(11, Math.min(16, Math.round(I * 0.32))), K = -(I + Q * 0.5);
105
105
  e.cluster({
106
- joinCondition: (x) => i.has(x.id),
106
+ joinCondition: (S) => c.has(S.id),
107
107
  // vis-network genuinely accepts `id` in clusterNodeProperties at runtime
108
108
  // (it's how you address the cluster later via openCluster/isCluster) —
109
109
  // the shipped .d.ts's NodeOptions type just doesn't declare it.
110
110
  clusterNodeProperties: {
111
- id: m,
111
+ id: E,
112
112
  // Member count only — the full name is tooltip + legend-panel only
113
113
  // (see the doc comment above). Not empty string: vis-network defaults
114
114
  // `label` to the literal "cluster" when it's `undefined`, which would
115
115
  // otherwise draw a stray caption under every collapsed community.
116
- label: String(i.size),
117
- font: { color: "#ffffff", size: K, vadjust: N },
118
- title: C,
116
+ label: String(c.size),
117
+ font: { color: "#ffffff", size: Q, vadjust: K },
118
+ title: B,
119
119
  shape: "dot",
120
120
  // Larger + white-ringed so a collapsed community reads as a distinct
121
121
  // "group" at a glance, not just another same-sized leaf node.
122
- size: O,
122
+ size: I,
123
123
  borderWidth: 3,
124
- color: { background: c, border: "#ffffff", highlight: { background: c, border: "#ffffff" } },
124
+ color: { background: d, border: "#ffffff", highlight: { background: d, border: "#ffffff" } },
125
125
  // Soft colored glow (a hint of the community's own color) instead of a
126
126
  // flat plain circle — same "elevated card" depth language dui's own
127
127
  // panels use, just expressed on canvas.
128
- shadow: { enabled: !0, color: `${c}66`, size: 16, x: 0, y: 4 }
128
+ shadow: { enabled: !0, color: `${d}66`, size: 16, x: 0, y: 4 }
129
129
  }
130
130
  });
131
131
  }
132
- function oe({
132
+ function pe({
133
133
  nodes: e,
134
- edges: s,
135
- onNodeClick: f,
136
- selectedId: i,
137
- fitTrigger: c,
138
- onReady: m,
139
- colorBy: C,
140
- sizeBy: O,
141
- className: K = "",
142
- style: N,
143
- enableClustering: x = !1,
144
- enableHoverDim: St = !1,
145
- enableMinimap: q = !1,
146
- theme: ft = "dark"
134
+ edges: a,
135
+ onNodeClick: g,
136
+ selectedId: c,
137
+ fitTrigger: d,
138
+ onReady: E,
139
+ colorBy: B,
140
+ sizeBy: I,
141
+ className: Q = "",
142
+ style: K,
143
+ enableClustering: S = !1,
144
+ enableHoverDim: Rt = !1,
145
+ enableMinimap: tt = !1,
146
+ theme: lt = "dark",
147
+ hiddenNodeIds: Tt,
148
+ hiddenEdgeIds: kt
147
149
  }) {
148
- const V = M(null), dt = M(null), j = M(null), Dt = M(null), Bt = M(null), Z = M(/* @__PURE__ */ new Map()), Ct = M(/* @__PURE__ */ new Map()), Ot = M(/* @__PURE__ */ new Map()), zt = M(null), pt = M([]), ht = M([]), gt = M(/* @__PURE__ */ new Map()), k = M(i);
149
- k.current = i;
150
- const X = M(!1);
151
- Et(() => {
152
- if (!V.current) return;
153
- let u = null;
150
+ const et = w(null), wt = w(null), V = w(null), ut = w(null), xt = w(null), Z = w(/* @__PURE__ */ new Map()), Wt = w(/* @__PURE__ */ new Map()), _t = w(/* @__PURE__ */ new Map()), $t = w(null), vt = w([]), Et = w([]), Mt = w(/* @__PURE__ */ new Map()), $ = w(c);
151
+ $.current = c;
152
+ const q = w(!1), jt = It(() => {
153
+ const i = e.map((s) => s.id).join(""), l = a.map((s, h) => [s.id ?? h, s.source, s.target, s.type ?? ""].join("")).join("");
154
+ return i + "" + l;
155
+ }, [e, a]), dt = It(() => new Set(Tt ?? []), [Tt]), St = It(() => new Set(kt ?? []), [kt]), nt = w(dt);
156
+ nt.current = dt;
157
+ const Ft = w(St);
158
+ Ft.current = St;
159
+ const ot = w(/* @__PURE__ */ new Map()), H = w(null), Gt = (i, l) => Ft.current.has(l) || nt.current.has(i.source) || nt.current.has(i.target);
160
+ at(() => {
161
+ if (!et.current) return;
162
+ let i = null;
154
163
  Z.current = new Map(e.map((t) => [t.id, t]));
155
- const w = {}, y = /* @__PURE__ */ new Map(), z = /* @__PURE__ */ new Map();
156
- s.forEach((t, n) => {
157
- w[t.source] = (w[t.source] ?? 0) + 1, w[t.target] = (w[t.target] ?? 0) + 1, y.has(t.source) || y.set(t.source, /* @__PURE__ */ new Set()), y.has(t.target) || y.set(t.target, /* @__PURE__ */ new Set()), y.get(t.source).add(t.target), y.get(t.target).add(t.source);
164
+ const l = {}, s = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
165
+ a.forEach((t, n) => {
166
+ l[t.source] = (l[t.source] ?? 0) + 1, l[t.target] = (l[t.target] ?? 0) + 1, s.has(t.source) || s.set(t.source, /* @__PURE__ */ new Set()), s.has(t.target) || s.set(t.target, /* @__PURE__ */ new Set()), s.get(t.source).add(t.target), s.get(t.target).add(t.source);
158
167
  const r = t.id ?? n;
159
- z.has(t.source) || z.set(t.source, /* @__PURE__ */ new Set()), z.has(t.target) || z.set(t.target, /* @__PURE__ */ new Set()), z.get(t.source).add(r), z.get(t.target).add(r);
160
- }), Ct.current = y, Ot.current = z;
161
- const L = Math.max(1, ...Object.values(w)), R = kt[ft], J = /* @__PURE__ */ new Map(), bt = e.map((t) => {
162
- const n = C ? C(t) : Wt(t);
163
- J.set(t.id, n);
164
- const r = w[t.id] ?? 1, a = O ? O(t, r, L) : 10 + 30 * (r / L);
168
+ h.has(t.source) || h.set(t.source, /* @__PURE__ */ new Set()), h.has(t.target) || h.set(t.target, /* @__PURE__ */ new Set()), h.get(t.source).add(r), h.get(t.target).add(r);
169
+ }), Wt.current = s, _t.current = h;
170
+ const p = Math.max(1, ...Object.values(l)), x = Pt[lt], P = /* @__PURE__ */ new Map();
171
+ ot.current = P;
172
+ const N = e.map((t) => {
173
+ const n = B ? B(t) : Lt(t);
174
+ P.set(t.id, n);
175
+ const r = l[t.id] ?? 1, f = I ? I(t, r, p) : 10 + 30 * (r / p);
165
176
  return {
166
177
  id: t.id,
167
178
  title: t.label,
@@ -173,11 +184,12 @@ function oe({
173
184
  // border instead — the old highlight swapped the fill to the theme
174
185
  // text color, which read as a jarring near-black circle in light
175
186
  // mode (and near-white in dark).
176
- color: { background: n, border: n, highlight: { background: n, border: R.text } },
177
- size: Math.round(a * 10) / 10,
178
- shape: "dot"
187
+ color: { background: n, border: n, highlight: { background: n, border: x.text } },
188
+ size: Math.round(f * 10) / 10,
189
+ shape: "dot",
190
+ hidden: nt.current.has(t.id)
179
191
  };
180
- }), nt = s.map((t, n) => ({
192
+ }), U = a.map((t, n) => ({
181
193
  id: t.id ?? n,
182
194
  from: t.source,
183
195
  to: t.target,
@@ -186,10 +198,11 @@ function oe({
186
198
  // midpoint instead of a flat gray line — a vis-network-native
187
199
  // stand-in for the gradient edges ck8t's ReactFlow canvas uses.
188
200
  color: { inherit: "both", opacity: 0.55 },
189
- arrows: { to: { enabled: !0, scaleFactor: 0.6 } }
190
- })), F = new Rt(bt), W = new Rt(nt);
191
- Dt.current = F, Bt.current = W;
192
- const Q = e.length > Vt, wt = {
201
+ arrows: { to: { enabled: !0, scaleFactor: 0.6 } },
202
+ hidden: Gt(t, t.id ?? n)
203
+ })), R = new Yt(N), L = new Yt(U);
204
+ ut.current = R, xt.current = L;
205
+ const rt = e.length > se, Bt = {
193
206
  // vis-network defaults `layout.improvedLayout` to true, which runs a
194
207
  // Kamada-Kawai pre-positioning pass whenever the graph exceeds its
195
208
  // internal clusterThreshold (150 nodes). On graphs with many
@@ -239,249 +252,279 @@ function oe({
239
252
  shape: "dot",
240
253
  borderWidth: 1.5,
241
254
  borderWidthSelected: 3,
242
- shadow: { enabled: !Q, color: "rgba(0,0,0,0.35)", size: 8, x: 0, y: 3 }
255
+ shadow: { enabled: !rt, color: "rgba(0,0,0,0.35)", size: 8, x: 0, y: 3 }
243
256
  },
244
257
  edges: {
245
258
  // 'continuous' recomputes bezier control points per edge per draw —
246
259
  // the most expensive of vis-network's smooth types. Straight lines
247
260
  // above the threshold; edges are hidden during zoom either way.
248
- smooth: Q ? !1 : { enabled: !0, type: "continuous", roundness: 0.25 },
249
- shadow: { enabled: !Q, color: "rgba(0,0,0,0.12)", size: 3, x: 0, y: 1 }
261
+ smooth: rt ? !1 : { enabled: !0, type: "continuous", roundness: 0.25 },
262
+ shadow: { enabled: !rt, color: "rgba(0,0,0,0.12)", size: 3, x: 0, y: 1 }
250
263
  }
251
- }, o = new Kt(V.current, { nodes: F, edges: W }, wt);
252
- j.current = o;
253
- const G = () => {
254
- const t = dt.current;
255
- if (!t || !q) return;
264
+ }, o = new ie(et.current, { nodes: R, edges: L }, Bt);
265
+ V.current = o;
266
+ const j = () => {
267
+ const t = wt.current;
268
+ if (!t || !tt) return;
256
269
  const n = t.getContext("2d");
257
270
  if (!n) return;
258
- const r = o.getPositions(), a = Object.values(r).map((l) => l.x), d = Object.values(r).map((l) => l.y);
259
- if (a.length === 0) return;
260
- const S = Math.min(...a), D = Math.max(...a), p = Math.min(...d), et = Math.max(...d), U = t.width, H = t.height, it = Math.max(1, D - S), st = Math.max(1, et - p), h = (l, v) => [
261
- (l - S) / it * (U - 10) + 5,
262
- (v - p) / st * (H - 10) + 5
271
+ const r = o.getPositions(), f = Object.values(r).map((u) => u.x), m = Object.values(r).map((u) => u.y);
272
+ if (f.length === 0) return;
273
+ const z = Math.min(...f), O = Math.max(...f), y = Math.min(...m), ct = Math.max(...m), J = t.width, Y = t.height, ht = Math.max(1, O - z), pt = Math.max(1, ct - y), b = (u, C) => [
274
+ (u - z) / ht * (J - 10) + 5,
275
+ (C - y) / pt * (Y - 10) + 5
263
276
  ];
264
- n.clearRect(0, 0, U, H), n.fillStyle = R.minimapBg, n.fillRect(0, 0, U, H), Object.entries(r).forEach(([l, v]) => {
265
- const [B, b] = h(v.x, v.y), A = Z.current.get(l);
266
- n.fillStyle = A ? C ? C(A) : Wt(A) : "#6B7280", n.beginPath();
267
- const _ = w[l] ?? 0;
268
- n.arc(B, b, 1 + 1.5 * (_ / L), 0, Math.PI * 2), n.fill();
277
+ n.clearRect(0, 0, J, Y), n.fillStyle = x.minimapBg, n.fillRect(0, 0, J, Y), Object.entries(r).forEach(([u, C]) => {
278
+ if (nt.current.has(u)) return;
279
+ const [A, M] = b(C.x, C.y), k = Z.current.get(u);
280
+ n.fillStyle = ot.current.get(u) ?? (k ? B ? B(k) : Lt(k) : "#6B7280"), n.beginPath();
281
+ const F = l[u] ?? 0;
282
+ n.arc(A, M, 1 + 1.5 * (F / p), 0, Math.PI * 2), n.fill();
269
283
  });
270
- const g = o.getScale(), E = o.getViewPosition(), T = V.current;
271
- if (T && g > 0) {
272
- const l = T.clientWidth / g, v = T.clientHeight / g, [B, b] = h(E.x - l / 2, E.y - v / 2), [A, _] = h(E.x + l / 2, E.y + v / 2);
273
- n.strokeStyle = R.viewportStroke, n.lineWidth = 1, n.strokeRect(B, b, A - B, _ - b);
284
+ const v = o.getScale(), D = o.getViewPosition(), _ = et.current;
285
+ if (_ && v > 0) {
286
+ const u = _.clientWidth / v, C = _.clientHeight / v, [A, M] = b(D.x - u / 2, D.y - C / 2), [k, F] = b(D.x + u / 2, D.y + C / 2);
287
+ n.strokeStyle = x.viewportStroke, n.lineWidth = 1, n.strokeRect(A, M, k - A, F - M);
274
288
  }
275
289
  };
276
- let I = null;
277
- const ot = () => {
278
- I = null;
290
+ let T = null;
291
+ const it = () => {
292
+ T = null;
279
293
  };
280
- let xt = null, vt = null;
281
- const At = /* @__PURE__ */ new Map();
282
- s.forEach((t, n) => {
283
- t.type && At.set(t.id ?? n, t.type);
294
+ let zt = null, Ot = null;
295
+ const Nt = /* @__PURE__ */ new Map();
296
+ a.forEach((t, n) => {
297
+ t.type && Nt.set(t.id ?? n, t.type);
284
298
  });
285
- const Pt = (t, n) => {
299
+ const Ut = (t, n) => {
286
300
  let r = t[n];
287
- return r || (r = te(zt.current), t[n] = r), r;
288
- }, Lt = (t, n, r) => {
289
- const a = `${n}\0${r}`;
290
- let d = gt.current.get(a);
291
- return d || (d = { w: t.offsetWidth, h: t.offsetHeight }, gt.current.set(a, d)), d;
292
- }, rt = (t, n) => {
301
+ return r || (r = de($t.current), t[n] = r), r;
302
+ }, Xt = (t, n, r) => {
303
+ const f = `${n}\0${r}`;
304
+ let m = Mt.current.get(f);
305
+ return m || (m = { w: t.offsetWidth, h: t.offsetHeight }, Mt.current.set(f, m)), m;
306
+ }, ft = (t, n) => {
293
307
  for (let r = n; r < t.length; r++)
294
308
  t[r].style.display !== "none" && (t[r].style.display = "none");
295
- }, Y = () => {
296
- var it, st;
297
- const t = pt.current, n = ht.current, r = ((it = V.current) == null ? void 0 : it.clientWidth) ?? 0, a = ((st = V.current) == null ? void 0 : st.clientHeight) ?? 0;
298
- if (o.getScale() < Zt || !r || !a) {
299
- rt(t, 0), rt(n, 0);
309
+ }, X = () => {
310
+ var ht, pt;
311
+ const t = vt.current, n = Et.current, r = ((ht = et.current) == null ? void 0 : ht.clientWidth) ?? 0, f = ((pt = et.current) == null ? void 0 : pt.clientHeight) ?? 0;
312
+ if (o.getScale() < ce || !r || !f) {
313
+ ft(t, 0), ft(n, 0);
300
314
  return;
301
315
  }
302
- I || (I = o.getPositions());
303
- const d = o.DOMtoCanvas({ x: 0, y: 0 }), S = o.DOMtoCanvas({ x: r, y: a }), D = [];
304
- for (const h in I) {
305
- const g = I[h];
306
- g.x < d.x || g.x > S.x || g.y < d.y || g.y > S.y || Z.current.has(h) && D.push({ id: h, deg: w[h] ?? 0 });
316
+ T || (T = o.getPositions());
317
+ const m = o.DOMtoCanvas({ x: 0, y: 0 }), z = o.DOMtoCanvas({ x: r, y: f }), O = [];
318
+ for (const b in T) {
319
+ const v = T[b];
320
+ v.x < m.x || v.x > z.x || v.y < m.y || v.y > z.y || Z.current.has(b) && (nt.current.has(b) || O.push({ id: b, deg: l[b] ?? 0 }));
307
321
  }
308
- D.length > Tt && (D.sort((h, g) => g.deg - h.deg), D.length = Tt);
309
- const p = Qt(), et = 12;
310
- let U = 0;
311
- for (const h of D) {
312
- const g = Z.current.get(h.id);
313
- if (!(g != null && g.label) || o.findNode(h.id).length !== 1) continue;
314
- const E = o.getBoundingBox(h.id);
315
- if (!E) continue;
316
- const T = o.canvasToDOM({ x: (E.left + E.right) / 2, y: E.bottom }), l = Pt(t, U);
317
- _t(l, g.label, ee(J.get(h.id) ?? "#6B7280")), l.style.display !== "" && (l.style.display = "");
318
- const v = !xt || xt.has(h.id) ? "1" : String(at);
319
- l.style.opacity !== v && (l.style.opacity = v);
320
- const { w: B, h: b } = Lt(l, "n", g.label), A = T.x - B / 2, _ = T.y + 6;
321
- let $ = A, P = _;
322
- for (let ct = 0; ct < et; ct++) {
323
- const Nt = Math.floor(ct / 3), jt = ct % 3 - 1;
324
- if ($ = A + jt * (B + 6), P = _ + Nt * (b + 3), !p.collides({ left: $, top: P, right: $ + B, bottom: P + b })) break;
322
+ O.length > Kt && (O.sort((b, v) => v.deg - b.deg), O.length = Kt);
323
+ const y = ue(), ct = 12;
324
+ let J = 0;
325
+ for (const b of O) {
326
+ const v = Z.current.get(b.id);
327
+ if (!(v != null && v.label) || o.findNode(b.id).length !== 1) continue;
328
+ const D = o.getBoundingBox(b.id);
329
+ if (!D) continue;
330
+ const _ = o.canvasToDOM({ x: (D.left + D.right) / 2, y: D.bottom }), u = Ut(t, J);
331
+ Vt(u, v.label, fe(ot.current.get(b.id) ?? "#6B7280")), u.style.display !== "" && (u.style.display = "");
332
+ const C = !zt || zt.has(b.id) ? "1" : String(mt);
333
+ u.style.opacity !== C && (u.style.opacity = C);
334
+ const { w: A, h: M } = Xt(u, "n", v.label), k = _.x - A / 2, F = _.y + 6;
335
+ let G = k, W = F;
336
+ for (let gt = 0; gt < ct; gt++) {
337
+ const te = Math.floor(gt / 3), ee = gt % 3 - 1;
338
+ if (G = k + ee * (A + 6), W = F + te * (M + 3), !y.collides({ left: G, top: W, right: G + A, bottom: W + M })) break;
325
339
  }
326
- l.style.left = `${$}px`, l.style.top = `${P}px`, p.insert({ left: $, top: P, right: $ + B, bottom: P + b }), U++;
340
+ u.style.left = `${G}px`, u.style.top = `${W}px`, y.insert({ left: G, top: W, right: G + A, bottom: W + M }), J++;
327
341
  }
328
- rt(t, U);
329
- let H = 0;
330
- for (const [h, g] of At) {
331
- if (H >= qt) break;
332
- const E = W.get(h);
333
- if (!E) continue;
334
- const T = I[E.from], l = I[E.to];
335
- if (!T || !l) continue;
336
- const v = { x: (T.x + l.x) / 2, y: (T.y + l.y) / 2 };
337
- if (v.x < d.x || v.x > S.x || v.y < d.y || v.y > S.y || o.findNode(E.from).length !== 1 || o.findNode(E.to).length !== 1) continue;
338
- const B = o.canvasToDOM(v), b = Pt(n, H);
339
- _t(b, g, ne(R)), b.style.display !== "" && (b.style.display = "");
340
- const A = !vt || vt.has(h) ? "1" : String(at);
341
- b.style.opacity !== A && (b.style.opacity = A);
342
- const { w: _, h: $ } = Lt(b, "e", g), P = { left: B.x - _ / 2, top: B.y - $ / 2, right: B.x + _ / 2, bottom: B.y + $ / 2 };
343
- if (p.collides(P)) {
344
- b.style.display = "none";
342
+ ft(t, J);
343
+ let Y = 0;
344
+ for (const [b, v] of Nt) {
345
+ if (Y >= ae) break;
346
+ const D = L.get(b);
347
+ if (!D || D.hidden) continue;
348
+ const _ = T[D.from], u = T[D.to];
349
+ if (!_ || !u) continue;
350
+ const C = { x: (_.x + u.x) / 2, y: (_.y + u.y) / 2 };
351
+ if (C.x < m.x || C.x > z.x || C.y < m.y || C.y > z.y || o.findNode(D.from).length !== 1 || o.findNode(D.to).length !== 1) continue;
352
+ const A = o.canvasToDOM(C), M = Ut(n, Y);
353
+ Vt(M, v, he(x)), M.style.display !== "" && (M.style.display = "");
354
+ const k = !Ot || Ot.has(b) ? "1" : String(mt);
355
+ M.style.opacity !== k && (M.style.opacity = k);
356
+ const { w: F, h: G } = Xt(M, "e", v), W = { left: A.x - F / 2, top: A.y - G / 2, right: A.x + F / 2, bottom: A.y + G / 2 };
357
+ if (y.collides(W)) {
358
+ M.style.display = "none";
345
359
  continue;
346
360
  }
347
- b.style.left = `${P.left}px`, b.style.top = `${P.top}px`, p.insert(P), H++;
361
+ M.style.left = `${W.left}px`, M.style.top = `${W.top}px`, y.insert(W), Y++;
348
362
  }
349
- rt(n, H);
363
+ ft(n, Y);
364
+ };
365
+ H.current = () => {
366
+ it(), X(), tt && j();
350
367
  };
351
- let tt = null;
352
- const Ht = () => {
353
- X.current || tt === null && (tt = requestAnimationFrame(() => {
354
- tt = null, Y();
368
+ let st = null;
369
+ const Qt = () => {
370
+ q.current || st === null && (st = requestAnimationFrame(() => {
371
+ st = null, X();
355
372
  }));
356
373
  };
357
374
  if (o.once("stabilizationIterationsDone", () => {
358
375
  o.setOptions({ physics: { enabled: !1 } });
359
376
  let t = !1;
360
- if (x) {
361
- const r = new Set(e.map((a) => a.communityId).filter((a) => a != null));
362
- r.forEach((a) => $t(o, a, e)), r.size > 1 && (t = !0, o.once("stabilizationIterationsDone", () => {
363
- o.setOptions({ physics: { enabled: !1 } }), G(), ot(), Y(), k.current && o.findNode(k.current).length > 0 && (o.selectNodes([k.current]), o.focus(k.current, { scale: 1.4, animation: !0 }), X.current = !0), m == null || m();
377
+ if (S) {
378
+ const r = new Set(e.map((f) => f.communityId).filter((f) => f != null));
379
+ r.forEach((f) => Zt(o, f, e)), r.size > 1 && (t = !0, o.once("stabilizationIterationsDone", () => {
380
+ o.setOptions({ physics: { enabled: !1 } }), j(), it(), X(), $.current && o.findNode($.current).length > 0 && (o.selectNodes([$.current]), o.focus($.current, { scale: 1.4, animation: !0 }), q.current = !0), E == null || E();
364
381
  }), o.setOptions({
365
382
  physics: { enabled: !0, stabilization: { iterations: 80, fit: !1 } }
366
383
  }), o.stabilize(80));
367
384
  }
368
385
  const n = o.getScale();
369
- n > 0 && o.moveTo({ scale: n * 0.92 }), G(), ot(), Y(), t || (k.current && o.findNode(k.current).length > 0 && (o.selectNodes([k.current]), o.focus(k.current, { scale: 1.4, animation: !0 }), X.current = !0), m == null || m());
370
- }), o.on("afterDrawing", Ht), o.on("dragEnd", () => {
371
- ot(), Y();
386
+ n > 0 && o.moveTo({ scale: n * 0.92 }), j(), it(), X(), t || ($.current && o.findNode($.current).length > 0 && (o.selectNodes([$.current]), o.focus($.current, { scale: 1.4, animation: !0 }), q.current = !0), E == null || E());
387
+ }), o.on("afterDrawing", Qt), o.on("dragEnd", () => {
388
+ it(), X();
372
389
  }), o.on("animationFinished", () => {
373
- X.current = !1, Y(), q && G();
390
+ q.current = !1, X(), tt && j();
374
391
  }), o.on("click", (t) => {
375
392
  if (t.nodes.length === 0) return;
376
393
  const n = t.nodes[0], r = Z.current.get(n);
377
394
  if (r) {
378
- f == null || f(r);
395
+ g == null || g(r);
379
396
  return;
380
397
  }
381
- o.isCluster(n) && (f == null || f({ id: n, label: n }));
382
- }), x && o.on("doubleClick", (t) => {
398
+ o.isCluster(n) && (g == null || g({ id: n, label: n }));
399
+ }), S && o.on("doubleClick", (t) => {
383
400
  if (t.nodes.length !== 1) return;
384
401
  const n = t.nodes[0];
385
402
  if (o.isCluster(n))
386
403
  o.openCluster(n);
387
404
  else {
388
405
  const r = Z.current.get(n);
389
- (r == null ? void 0 : r.communityId) != null && $t(o, r.communityId, e);
406
+ (r == null ? void 0 : r.communityId) != null && Zt(o, r.communityId, e);
390
407
  }
391
- G(), ot(), Y();
392
- }), St) {
393
- let t = new Set(F.getIds()), n = new Set(W.getIds());
394
- const r = (a, d) => {
395
- const S = [];
396
- for (const p of a) t.has(p) || S.push({ id: p, opacity: 1 });
397
- for (const p of t) a.has(p) || S.push({ id: p, opacity: at });
398
- S.length && F.update(S);
399
- const D = [];
400
- for (const p of d)
401
- n.has(p) || D.push({ id: p, color: { inherit: "both", opacity: 0.9 } });
402
- for (const p of n)
403
- d.has(p) || D.push({ id: p, color: { inherit: "both", opacity: at } });
404
- D.length && W.update(D), xt = a, vt = d, Y(), t = a, n = d;
408
+ j(), it(), X();
409
+ }), Rt) {
410
+ let t = new Set(R.getIds()), n = new Set(L.getIds());
411
+ const r = (f, m) => {
412
+ const z = [];
413
+ for (const y of f) t.has(y) || z.push({ id: y, opacity: 1 });
414
+ for (const y of t) f.has(y) || z.push({ id: y, opacity: mt });
415
+ z.length && R.update(z);
416
+ const O = [];
417
+ for (const y of m)
418
+ n.has(y) || O.push({ id: y, color: { inherit: "both", opacity: 0.9 } });
419
+ for (const y of n)
420
+ m.has(y) || O.push({ id: y, color: { inherit: "both", opacity: mt } });
421
+ O.length && L.update(O), zt = f, Ot = m, X(), t = f, n = m;
405
422
  };
406
- o.on("hoverNode", (a) => {
407
- u !== null && (clearTimeout(u), u = null);
408
- const d = a.node, S = Ct.current.get(d) ?? /* @__PURE__ */ new Set(), D = new Set(
409
- [d, ...S].filter((et) => F.get(et) != null)
410
- ), p = Ot.current.get(d) ?? /* @__PURE__ */ new Set();
411
- r(D, p);
423
+ o.on("hoverNode", (f) => {
424
+ i !== null && (clearTimeout(i), i = null);
425
+ const m = f.node, z = Wt.current.get(m) ?? /* @__PURE__ */ new Set(), O = new Set(
426
+ [m, ...z].filter((ct) => R.get(ct) != null)
427
+ ), y = _t.current.get(m) ?? /* @__PURE__ */ new Set();
428
+ r(O, y);
412
429
  }), o.on("blurNode", () => {
413
- u = setTimeout(() => {
414
- u = null, r(new Set(F.getIds()), new Set(W.getIds()));
430
+ i = setTimeout(() => {
431
+ i = null, r(new Set(R.getIds()), new Set(L.getIds()));
415
432
  }, 80);
416
433
  });
417
434
  }
418
- if (q) {
419
- o.on("dragEnd", G);
435
+ if (tt) {
436
+ o.on("dragEnd", j);
420
437
  let t = 0;
421
438
  const n = () => {
422
- if (X.current) return;
439
+ if (q.current) return;
423
440
  const r = Date.now();
424
- r - t < 100 || (t = r, G());
441
+ r - t < 100 || (t = r, j());
425
442
  };
426
443
  o.on("zoom", n), o.on("afterDrawing", n);
427
444
  }
428
445
  return () => {
429
- u !== null && clearTimeout(u), tt !== null && cancelAnimationFrame(tt), o.destroy(), j.current = null, Dt.current = null, Bt.current = null;
430
- for (const t of pt.current) t.remove();
431
- pt.current = [];
432
- for (const t of ht.current) t.remove();
433
- ht.current = [], gt.current.clear();
446
+ i !== null && clearTimeout(i), st !== null && cancelAnimationFrame(st), o.destroy(), V.current = null, H.current = null, ut.current = null, xt.current = null;
447
+ for (const t of vt.current) t.remove();
448
+ vt.current = [];
449
+ for (const t of Et.current) t.remove();
450
+ Et.current = [], Mt.current.clear();
434
451
  };
435
- }, [e, s, x, St, q, ft]), Et(() => {
436
- const u = j.current;
437
- !u || !i || u.findNode(i).length > 0 && (u.selectNodes([i]), u.focus(i, { scale: 1.4, animation: !0 }), X.current = !0);
438
- }, [i, e]);
439
- const mt = M(c);
440
- Et(() => {
441
- const u = j.current;
442
- if (!u || c === void 0 || c === mt.current) {
443
- mt.current = c;
452
+ }, [jt, S, Rt, tt, lt]), at(() => {
453
+ var h;
454
+ const i = ut.current;
455
+ if (!i) return;
456
+ Z.current = new Map(e.map((p) => [p.id, p]));
457
+ const l = Pt[lt].text, s = [];
458
+ for (const p of e) {
459
+ const x = B ? B(p) : Lt(p);
460
+ ot.current.get(p.id) !== x && (ot.current.set(p.id, x), s.push({ id: p.id, color: { background: x, border: x, highlight: { background: x, border: l } } }));
461
+ }
462
+ s.length && (i.update(s), (h = H.current) == null || h.call(H));
463
+ }, [e, B]), at(() => {
464
+ var p, x;
465
+ const i = ut.current, l = xt.current;
466
+ if (!i || !l) return;
467
+ const s = [];
468
+ for (const P of e) {
469
+ const N = dt.has(P.id);
470
+ !!((p = i.get(P.id)) != null && p.hidden) !== N && s.push({ id: P.id, hidden: N });
471
+ }
472
+ const h = [];
473
+ a.forEach((P, N) => {
474
+ var L;
475
+ const U = P.id ?? N, R = Gt(P, U);
476
+ !!((L = l.get(U)) != null && L.hidden) !== R && h.push({ id: U, hidden: R });
477
+ }), s.length && i.update(s), h.length && l.update(h), (s.length || h.length) && ((x = H.current) == null || x.call(H));
478
+ }, [dt, St]), at(() => {
479
+ const i = V.current;
480
+ !i || !c || i.findNode(c).length > 0 && (i.selectNodes([c]), i.focus(c, { scale: 1.4, animation: !0 }), q.current = !0);
481
+ }, [c, jt]);
482
+ const Dt = w(d);
483
+ at(() => {
484
+ const i = V.current;
485
+ if (!i || d === void 0 || d === Dt.current) {
486
+ Dt.current = d;
444
487
  return;
445
488
  }
446
- mt.current = c, u.unselectAll(), u.fit({ animation: !0 }), X.current = !0;
447
- }, [c]);
448
- const It = (u) => {
449
- const w = j.current, y = dt.current;
450
- if (!w || !y) return null;
451
- const z = w.getPositions(), L = Object.values(z).map((I) => I.x), R = Object.values(z).map((I) => I.y);
452
- if (L.length === 0) return null;
453
- const J = Math.min(...L), bt = Math.max(...L), nt = Math.min(...R), F = Math.max(...R), W = y.getBoundingClientRect(), Q = u.clientX - W.left, wt = u.clientY - W.top, o = Math.max(1, bt - J), G = Math.max(1, F - nt);
489
+ Dt.current = d, i.unselectAll(), i.fit({ animation: !0 }), q.current = !0;
490
+ }, [d]);
491
+ const Ht = (i) => {
492
+ const l = V.current, s = wt.current;
493
+ if (!l || !s) return null;
494
+ const h = l.getPositions(), p = Object.values(h).map((T) => T.x), x = Object.values(h).map((T) => T.y);
495
+ if (p.length === 0) return null;
496
+ const P = Math.min(...p), N = Math.max(...p), U = Math.min(...x), R = Math.max(...x), L = s.getBoundingClientRect(), rt = i.clientX - L.left, Bt = i.clientY - L.top, o = Math.max(1, N - P), j = Math.max(1, R - U);
454
497
  return {
455
- x: (Q - 5) / (y.width - 10) * o + J,
456
- y: (wt - 5) / (y.height - 10) * G + nt
498
+ x: (rt - 5) / (s.width - 10) * o + P,
499
+ y: (Bt - 5) / (s.height - 10) * j + U
457
500
  };
458
- }, Ft = (u) => {
459
- var y;
460
- const w = It(u);
461
- w && ((y = j.current) == null || y.moveTo({ position: w, animation: !0 }));
462
- }, yt = M(!1), Gt = (u) => {
463
- yt.current = !0;
464
- const w = (z) => {
465
- var R;
466
- if (!yt.current) return;
467
- const L = It(z);
468
- L && ((R = j.current) == null || R.moveTo({ position: L }));
469
- }, y = () => {
470
- yt.current = !1, window.removeEventListener("mousemove", w), window.removeEventListener("mouseup", y);
501
+ }, qt = (i) => {
502
+ var s;
503
+ const l = Ht(i);
504
+ l && ((s = V.current) == null || s.moveTo({ position: l, animation: !0 }));
505
+ }, Ct = w(!1), Jt = (i) => {
506
+ Ct.current = !0;
507
+ const l = (h) => {
508
+ var x;
509
+ if (!Ct.current) return;
510
+ const p = Ht(h);
511
+ p && ((x = V.current) == null || x.moveTo({ position: p }));
512
+ }, s = () => {
513
+ Ct.current = !1, window.removeEventListener("mousemove", l), window.removeEventListener("mouseup", s);
471
514
  };
472
- window.addEventListener("mousemove", w), window.addEventListener("mouseup", y), u.preventDefault();
515
+ window.addEventListener("mousemove", l), window.addEventListener("mouseup", s), i.preventDefault();
473
516
  };
474
- return /* @__PURE__ */ Ut("div", { className: K, style: { width: "100%", height: "100%", position: "relative", ...N }, children: [
475
- /* @__PURE__ */ Mt("div", { ref: V, style: { width: "100%", height: "100%" } }),
476
- /* @__PURE__ */ Mt("div", { ref: zt, style: { position: "absolute", inset: 0, overflow: "hidden", pointerEvents: "none" } }),
477
- q && /* @__PURE__ */ Mt(
517
+ return /* @__PURE__ */ re("div", { className: Q, style: { width: "100%", height: "100%", position: "relative", ...K }, children: [
518
+ /* @__PURE__ */ At("div", { ref: et, style: { width: "100%", height: "100%" } }),
519
+ /* @__PURE__ */ At("div", { ref: $t, style: { position: "absolute", inset: 0, overflow: "hidden", pointerEvents: "none" } }),
520
+ tt && /* @__PURE__ */ At(
478
521
  "canvas",
479
522
  {
480
- ref: dt,
523
+ ref: wt,
481
524
  width: 140,
482
525
  height: 100,
483
- onClick: Ft,
484
- onMouseDown: Gt,
526
+ onClick: qt,
527
+ onMouseDown: Jt,
485
528
  style: {
486
529
  // bottom 72 (not 8): host apps commonly float a chat/action
487
530
  // orb in the bottom-right corner — leave that spot free.
@@ -489,13 +532,13 @@ function oe({
489
532
  bottom: 72,
490
533
  right: 8,
491
534
  borderRadius: 4,
492
- border: `1px solid ${kt[ft].minimapBorder}`,
535
+ border: `1px solid ${Pt[lt].minimapBorder}`,
493
536
  cursor: "grab"
494
537
  }
495
538
  }
496
539
  )
497
540
  ] });
498
541
  }
499
- Yt(oe);
500
- Xt();
542
+ oe(pe);
543
+ ne();
501
544
  //# sourceMappingURL=vis-setup.js.map