@salilvnair/dui 1.0.2 → 1.0.4

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 It, r as At } from "./chunks/vis-runtime-DkpA8K_T.js";
2
- import { jsxs as Rt, jsx as ht } from "react/jsx-runtime";
3
- import { useRef as p, useEffect as pt } from "react";
4
- import { DataSet as St } from "vis-data/peer";
5
- import { Network as Tt } from "vis-network/peer";
6
- const ot = [
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 = [
7
7
  "#4E79A7",
8
8
  "#F28E2B",
9
9
  "#E15759",
@@ -14,7 +14,7 @@ const ot = [
14
14
  "#FF9DA7",
15
15
  "#9C755F",
16
16
  "#BAB0AC"
17
- ], nt = 0.12, Pt = 300, Lt = 0.45, Mt = {
17
+ ], at = 0.12, Vt = 300, Zt = 0.45, Tt = 220, qt = 120, lt = 96, kt = {
18
18
  dark: {
19
19
  text: "#d4d4d4",
20
20
  chipBg: "rgba(37, 37, 38, 0.85)",
@@ -32,112 +32,153 @@ const ot = [
32
32
  viewportStroke: "#1f2328"
33
33
  }
34
34
  };
35
- function Et(r) {
36
- return r.color ? r.color : r.communityId != null ? ot[r.communityId % ot.length] : "#6B7280";
35
+ function Wt(e) {
36
+ return e.color ? e.color : e.communityId != null ? ut[e.communityId % ut.length] : "#6B7280";
37
37
  }
38
- function Dt(r, v, h) {
39
- const i = document.createElement("div");
40
- return i.textContent = v, i.style.position = "absolute", i.style.padding = h.padding, i.style.borderRadius = "9999px", i.style.fontSize = `${h.fontSize}px`, i.style.fontWeight = String(h.fontWeight), i.style.letterSpacing = "0.01em", i.style.whiteSpace = "nowrap", i.style.pointerEvents = "none", i.style.background = h.bg, i.style.border = `1px solid ${h.border}`, i.style.color = h.color, r == null || r.appendChild(i), i;
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));
43
+ };
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;
53
+ return;
54
+ }
55
+ }
56
+ }), c;
57
+ },
58
+ insert(i) {
59
+ f(i, (c) => {
60
+ const m = e.get(c);
61
+ m ? m.push(i) : e.set(c, [i]);
62
+ });
63
+ }
64
+ };
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;
41
69
  }
42
- function $t(r) {
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);
78
+ }
79
+ function ee(e) {
43
80
  return {
44
- color: r,
45
- bg: `color-mix(in srgb, ${r} 16%, transparent)`,
46
- border: `color-mix(in srgb, ${r} 40%, transparent)`,
81
+ color: e,
82
+ bg: `color-mix(in srgb, ${e} 16%, transparent)`,
83
+ border: `color-mix(in srgb, ${e} 40%, transparent)`,
47
84
  fontSize: 12,
48
85
  fontWeight: 600,
49
86
  padding: "3px 9px"
50
87
  };
51
88
  }
52
- function Wt(r) {
89
+ function ne(e) {
53
90
  return {
54
- color: r.text,
55
- bg: r.chipBg,
56
- border: r.chipBorder,
91
+ color: e.text,
92
+ bg: e.chipBg,
93
+ border: e.chipBorder,
57
94
  fontSize: 10,
58
95
  fontWeight: 500,
59
96
  padding: "2px 7px"
60
97
  };
61
98
  }
62
- function Bt(r, v, h) {
63
- const i = new Set(h.filter((y) => y.communityId === v).map((y) => y.id));
99
+ function $t(e, s, f) {
100
+ const i = new Set(f.filter((x) => x.communityId === s).map((x) => x.id));
64
101
  if (i.size < 2) return;
65
- for (const y of i)
66
- if (!r.findNode(y).length || r.isCluster(y)) return;
67
- const D = ot[v % ot.length], R = `cluster:community:${v}`, H = `Community ${v} (${i.size})`, N = Math.min(20 + i.size * 2, 60), Z = Math.max(11, Math.min(16, Math.round(N * 0.32))), rt = -(N + Z * 0.5);
68
- r.cluster({
69
- joinCondition: (y) => i.has(y.id),
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);
105
+ e.cluster({
106
+ joinCondition: (x) => i.has(x.id),
70
107
  // vis-network genuinely accepts `id` in clusterNodeProperties at runtime
71
108
  // (it's how you address the cluster later via openCluster/isCluster) —
72
109
  // the shipped .d.ts's NodeOptions type just doesn't declare it.
73
110
  clusterNodeProperties: {
74
- id: R,
111
+ id: m,
75
112
  // Member count only — the full name is tooltip + legend-panel only
76
113
  // (see the doc comment above). Not empty string: vis-network defaults
77
114
  // `label` to the literal "cluster" when it's `undefined`, which would
78
115
  // otherwise draw a stray caption under every collapsed community.
79
116
  label: String(i.size),
80
- font: { color: "#ffffff", size: Z, vadjust: rt },
81
- title: H,
117
+ font: { color: "#ffffff", size: K, vadjust: N },
118
+ title: C,
82
119
  shape: "dot",
83
120
  // Larger + white-ringed so a collapsed community reads as a distinct
84
121
  // "group" at a glance, not just another same-sized leaf node.
85
- size: N,
122
+ size: O,
86
123
  borderWidth: 3,
87
- color: { background: D, border: "#ffffff", highlight: { background: D, border: "#ffffff" } },
124
+ color: { background: c, border: "#ffffff", highlight: { background: c, border: "#ffffff" } },
88
125
  // Soft colored glow (a hint of the community's own color) instead of a
89
126
  // flat plain circle — same "elevated card" depth language dui's own
90
127
  // panels use, just expressed on canvas.
91
- shadow: { enabled: !0, color: `${D}66`, size: 16, x: 0, y: 4 }
128
+ shadow: { enabled: !0, color: `${c}66`, size: 16, x: 0, y: 4 }
92
129
  }
93
130
  });
94
131
  }
95
- function jt({
96
- nodes: r,
97
- edges: v,
98
- onNodeClick: h,
132
+ function oe({
133
+ nodes: e,
134
+ edges: s,
135
+ onNodeClick: f,
99
136
  selectedId: i,
100
- fitTrigger: D,
101
- onReady: R,
102
- colorBy: H,
103
- sizeBy: N,
104
- className: Z = "",
105
- style: rt,
106
- enableClustering: y = !1,
107
- enableHoverDim: gt = !1,
108
- enableMinimap: G = !1,
109
- theme: st = "dark"
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"
110
147
  }) {
111
- const q = p(null), it = p(null), $ = p(null), mt = p(null), bt = p(null), J = p(/* @__PURE__ */ new Map()), yt = p(/* @__PURE__ */ new Map()), wt = p(/* @__PURE__ */ new Map()), ct = p(null), X = p(/* @__PURE__ */ new Map()), Y = p(/* @__PURE__ */ new Map()), z = p(i);
112
- z.current = i;
113
- const W = p(!1);
114
- pt(() => {
115
- if (!q.current) return;
116
- let l = null;
117
- J.current = new Map(r.map((t) => [t.id, t]));
118
- const d = {}, f = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map();
119
- v.forEach((t, e) => {
120
- d[t.source] = (d[t.source] ?? 0) + 1, d[t.target] = (d[t.target] ?? 0) + 1, f.has(t.source) || f.set(t.source, /* @__PURE__ */ new Set()), f.has(t.target) || f.set(t.target, /* @__PURE__ */ new Set()), f.get(t.source).add(t.target), f.get(t.target).add(t.source);
121
- const s = t.id ?? e;
122
- w.has(t.source) || w.set(t.source, /* @__PURE__ */ new Set()), w.has(t.target) || w.set(t.target, /* @__PURE__ */ new Set()), w.get(t.source).add(s), w.get(t.target).add(s);
123
- }), yt.current = f, wt.current = w;
124
- const B = Math.max(1, ...Object.values(d)), C = Mt[st], K = /* @__PURE__ */ new Map(), ut = r.map((t) => {
125
- const e = H ? H(t) : Et(t);
126
- K.set(t.id, e);
127
- const s = d[t.id] ?? 1, a = N ? N(t, s, B) : 10 + 30 * (s / B);
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;
154
+ 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);
158
+ 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);
128
165
  return {
129
166
  id: t.id,
130
167
  title: t.label,
168
+ // No `label` here on purpose: every label is a pooled DOM chip
169
+ // positioned by syncAllChipPositions. Collapsed community nodes are
170
+ // the one exception and set their own label natively — see
171
+ // clusterCommunity.
131
172
  // Selection keeps the node's own fill and flags it with a themed
132
173
  // border instead — the old highlight swapped the fill to the theme
133
174
  // text color, which read as a jarring near-black circle in light
134
175
  // mode (and near-white in dark).
135
- color: { background: e, border: e, highlight: { background: e, border: C.text } },
176
+ color: { background: n, border: n, highlight: { background: n, border: R.text } },
136
177
  size: Math.round(a * 10) / 10,
137
178
  shape: "dot"
138
179
  };
139
- }), Q = v.map((t, e) => ({
140
- id: t.id ?? e,
180
+ }), nt = s.map((t, n) => ({
181
+ id: t.id ?? n,
141
182
  from: t.source,
142
183
  to: t.target,
143
184
  title: t.type,
@@ -146,9 +187,22 @@ function jt({
146
187
  // stand-in for the gradient edges ck8t's ReactFlow canvas uses.
147
188
  color: { inherit: "both", opacity: 0.55 },
148
189
  arrows: { to: { enabled: !0, scaleFactor: 0.6 } }
149
- })), T = new St(ut), I = new St(Q);
150
- mt.current = T, bt.current = I;
151
- const U = r.length > Pt, ft = {
190
+ })), F = new Rt(bt), W = new Rt(nt);
191
+ Dt.current = F, Bt.current = W;
192
+ const Q = e.length > Vt, wt = {
193
+ // vis-network defaults `layout.improvedLayout` to true, which runs a
194
+ // Kamada-Kawai pre-positioning pass whenever the graph exceeds its
195
+ // internal clusterThreshold (150 nodes). On graphs with many
196
+ // uneven-sized communities that pass regularly fails to reduce the
197
+ // graph within its own iteration budget: it logs "This network could
198
+ // not be positioned by this version of the improved layout
199
+ // algorithm" and falls back to leaving most nodes near their default
200
+ // circular starting positions with a ±35px jitter — the stray ring of
201
+ // dots around the outside that physics then can't pull in within its
202
+ // stabilization budget. Skipping the pre-pass (vis's own documented
203
+ // suggestion, printed in that same message) lets forceAtlas2Based
204
+ // position everything from a clean random start instead.
205
+ layout: { improvedLayout: !1 },
152
206
  physics: {
153
207
  enabled: !0,
154
208
  solver: "forceAtlas2Based",
@@ -185,220 +239,249 @@ function jt({
185
239
  shape: "dot",
186
240
  borderWidth: 1.5,
187
241
  borderWidthSelected: 3,
188
- shadow: { enabled: !U, color: "rgba(0,0,0,0.35)", size: 8, x: 0, y: 3 }
242
+ shadow: { enabled: !Q, color: "rgba(0,0,0,0.35)", size: 8, x: 0, y: 3 }
189
243
  },
190
244
  edges: {
191
245
  // 'continuous' recomputes bezier control points per edge per draw —
192
246
  // the most expensive of vis-network's smooth types. Straight lines
193
247
  // above the threshold; edges are hidden during zoom either way.
194
- smooth: U ? !1 : { enabled: !0, type: "continuous", roundness: 0.25 },
195
- shadow: { enabled: !U, color: "rgba(0,0,0,0.12)", size: 3, x: 0, y: 1 }
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 }
196
250
  }
197
- }, n = new Tt(q.current, { nodes: T, edges: I }, ft);
198
- $.current = n;
199
- const P = () => {
200
- const t = it.current;
201
- if (!t || !G) return;
202
- const e = t.getContext("2d");
203
- if (!e) return;
204
- const s = n.getPositions(), a = Object.values(s).map((E) => E.x), c = Object.values(s).map((E) => E.y);
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;
256
+ const n = t.getContext("2d");
257
+ if (!n) return;
258
+ const r = o.getPositions(), a = Object.values(r).map((l) => l.x), d = Object.values(r).map((l) => l.y);
205
259
  if (a.length === 0) return;
206
- const u = Math.min(...a), g = Math.max(...a), o = Math.min(...c), m = Math.max(...c), A = t.width, O = t.height, x = Math.max(1, g - u), b = Math.max(1, m - o), S = (E, F) => [
207
- (E - u) / x * (A - 10) + 5,
208
- (F - o) / b * (O - 10) + 5
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
209
263
  ];
210
- e.clearRect(0, 0, A, O), e.fillStyle = C.minimapBg, e.fillRect(0, 0, A, O), Object.entries(s).forEach(([E, F]) => {
211
- const [tt, et] = S(F.x, F.y), V = J.current.get(E);
212
- e.fillStyle = V ? H ? H(V) : Et(V) : "#6B7280", e.beginPath();
213
- const dt = d[E] ?? 0;
214
- e.arc(tt, et, 1 + 1.5 * (dt / B), 0, Math.PI * 2), e.fill();
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();
215
269
  });
216
- const L = n.getScale(), M = n.getViewPosition(), j = q.current;
217
- if (j && L > 0) {
218
- const E = j.clientWidth / L, F = j.clientHeight / L, [tt, et] = S(M.x - E / 2, M.y - F / 2), [V, dt] = S(M.x + E / 2, M.y + F / 2);
219
- e.strokeStyle = C.viewportStroke, e.lineWidth = 1, e.strokeRect(tt, et, V - tt, dt - et);
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);
220
274
  }
221
275
  };
222
- for (const t of r)
223
- X.current.set(t.id, Dt(ct.current, t.label, $t(K.get(t.id) ?? "#6B7280")));
224
- v.forEach((t, e) => {
225
- if (!t.type) return;
226
- const s = t.id ?? e;
227
- Y.current.set(s, Dt(ct.current, t.type, Wt(C)));
276
+ let I = null;
277
+ const ot = () => {
278
+ I = null;
279
+ };
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);
228
284
  });
229
- const _ = (t, e) => t.left < e.right && t.right > e.left && t.top < e.bottom && t.bottom > e.top, k = () => {
230
- const t = n.getScale() < Lt, e = [], s = 12;
231
- for (const [a, c] of X.current) {
232
- if (t || n.findNode(a).length !== 1) {
233
- c.style.display = "none";
234
- continue;
235
- }
236
- const u = n.getBoundingBox(a), g = n.canvasToDOM({ x: (u.left + u.right) / 2, y: u.bottom });
237
- c.style.display = "";
238
- const o = c.offsetWidth, m = c.offsetHeight, A = g.x - o / 2, O = g.y + 6;
239
- let x = A, b = O;
240
- for (let S = 0; S < s; S++) {
241
- const L = Math.floor(S / 3), M = S % 3 - 1;
242
- if (x = A + M * (o + 6), b = O + L * (m + 3), !e.some((j) => _({ left: x, top: b, right: x + o, bottom: b + m }, j))) break;
243
- }
244
- c.style.left = `${x}px`, c.style.top = `${b}px`, e.push({ left: x, top: b, right: x + o, bottom: b + m });
285
+ const Pt = (t, n) => {
286
+ 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) => {
293
+ for (let r = n; r < t.length; r++)
294
+ 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);
300
+ return;
245
301
  }
246
- for (const [a, c] of Y.current) {
247
- const u = I.get(a), g = u ? n.findNode(u.from) : [], o = u ? n.findNode(u.to) : [], m = g.length === 1 && o.length === 1;
248
- if (t || !u || !m) {
249
- c.style.display = "none";
250
- continue;
251
- }
252
- const A = n.getPositions([u.from, u.to]), O = A[u.from], x = A[u.to];
253
- if (!O || !x) {
254
- c.style.display = "none";
255
- continue;
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 });
307
+ }
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;
256
325
  }
257
- const b = n.canvasToDOM({ x: (O.x + x.x) / 2, y: (O.y + x.y) / 2 }), S = c.offsetWidth, L = c.offsetHeight, M = { left: b.x - S / 2, top: b.y - L / 2, right: b.x + S / 2, bottom: b.y + L / 2 };
258
- if (e.some((j) => _(M, j))) {
259
- c.style.display = "none";
326
+ l.style.left = `${$}px`, l.style.top = `${P}px`, p.insert({ left: $, top: P, right: $ + B, bottom: P + b }), U++;
327
+ }
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";
260
345
  continue;
261
346
  }
262
- c.style.display = "", c.style.left = `${M.left}px`, c.style.top = `${M.top}px`, e.push(M);
347
+ b.style.left = `${P.left}px`, b.style.top = `${P.top}px`, p.insert(P), H++;
263
348
  }
349
+ rt(n, H);
264
350
  };
265
- let vt = 0;
266
- const zt = () => {
267
- if (W.current) return;
268
- const t = Date.now();
269
- t - vt < 100 || (vt = t, k());
351
+ let tt = null;
352
+ const Ht = () => {
353
+ X.current || tt === null && (tt = requestAnimationFrame(() => {
354
+ tt = null, Y();
355
+ }));
270
356
  };
271
- if (n.once("stabilizationIterationsDone", () => {
272
- n.setOptions({ physics: { enabled: !1 } });
357
+ if (o.once("stabilizationIterationsDone", () => {
358
+ o.setOptions({ physics: { enabled: !1 } });
273
359
  let t = !1;
274
- if (y) {
275
- const s = new Set(r.map((a) => a.communityId).filter((a) => a != null));
276
- s.forEach((a) => Bt(n, a, r)), s.size > 1 && (t = !0, n.once("stabilizationIterationsDone", () => {
277
- n.setOptions({ physics: { enabled: !1 } }), P(), k(), z.current && n.findNode(z.current).length > 0 && (n.selectNodes([z.current]), n.focus(z.current, { scale: 1.4, animation: !0 }), W.current = !0), R == null || R();
278
- }), n.setOptions({
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();
364
+ }), o.setOptions({
279
365
  physics: { enabled: !0, stabilization: { iterations: 80, fit: !1 } }
280
- }), n.stabilize(80));
366
+ }), o.stabilize(80));
281
367
  }
282
- const e = n.getScale();
283
- e > 0 && n.moveTo({ scale: e * 0.92 }), P(), k(), t || (z.current && n.findNode(z.current).length > 0 && (n.selectNodes([z.current]), n.focus(z.current, { scale: 1.4, animation: !0 }), W.current = !0), R == null || R());
284
- }), n.on("afterDrawing", zt), n.on("dragEnd", k), n.on("animationFinished", () => {
285
- W.current = !1, k(), G && P();
286
- }), n.on("click", (t) => {
368
+ 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();
372
+ }), o.on("animationFinished", () => {
373
+ X.current = !1, Y(), q && G();
374
+ }), o.on("click", (t) => {
287
375
  if (t.nodes.length === 0) return;
288
- const e = t.nodes[0], s = J.current.get(e);
289
- if (s) {
290
- h == null || h(s);
376
+ const n = t.nodes[0], r = Z.current.get(n);
377
+ if (r) {
378
+ f == null || f(r);
291
379
  return;
292
380
  }
293
- n.isCluster(e) && (h == null || h({ id: e, label: e }));
294
- }), y && n.on("doubleClick", (t) => {
381
+ o.isCluster(n) && (f == null || f({ id: n, label: n }));
382
+ }), x && o.on("doubleClick", (t) => {
295
383
  if (t.nodes.length !== 1) return;
296
- const e = t.nodes[0];
297
- if (n.isCluster(e))
298
- n.openCluster(e);
384
+ const n = t.nodes[0];
385
+ if (o.isCluster(n))
386
+ o.openCluster(n);
299
387
  else {
300
- const s = J.current.get(e);
301
- (s == null ? void 0 : s.communityId) != null && Bt(n, s.communityId, r);
388
+ const r = Z.current.get(n);
389
+ (r == null ? void 0 : r.communityId) != null && $t(o, r.communityId, e);
302
390
  }
303
- P(), k();
304
- }), gt) {
305
- let t = new Set(T.getIds()), e = new Set(I.getIds());
306
- const s = (a, c) => {
307
- const u = [];
308
- for (const o of a) t.has(o) || u.push({ id: o, opacity: 1 });
309
- for (const o of t) a.has(o) || u.push({ id: o, opacity: nt });
310
- u.length && T.update(u);
311
- const g = [];
312
- for (const o of c)
313
- e.has(o) || g.push({ id: o, color: { inherit: "both", opacity: 0.9 } });
314
- for (const o of e)
315
- c.has(o) || g.push({ id: o, color: { inherit: "both", opacity: nt } });
316
- g.length && I.update(g);
317
- for (const [o, m] of X.current)
318
- a.has(o) !== t.has(o) && (m.style.opacity = a.has(o) ? "1" : String(nt));
319
- for (const [o, m] of Y.current)
320
- c.has(o) !== e.has(o) && (m.style.opacity = c.has(o) ? "1" : String(nt));
321
- t = a, e = c;
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;
322
405
  };
323
- n.on("hoverNode", (a) => {
324
- l !== null && (clearTimeout(l), l = null);
325
- const c = a.node, u = yt.current.get(c) ?? /* @__PURE__ */ new Set(), g = new Set(
326
- [c, ...u].filter((m) => T.get(m) != null)
327
- ), o = wt.current.get(c) ?? /* @__PURE__ */ new Set();
328
- s(g, o);
329
- }), n.on("blurNode", () => {
330
- l = setTimeout(() => {
331
- l = null, s(new Set(T.getIds()), new Set(I.getIds()));
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);
412
+ }), o.on("blurNode", () => {
413
+ u = setTimeout(() => {
414
+ u = null, r(new Set(F.getIds()), new Set(W.getIds()));
332
415
  }, 80);
333
416
  });
334
417
  }
335
- if (G) {
336
- n.on("dragEnd", P);
418
+ if (q) {
419
+ o.on("dragEnd", G);
337
420
  let t = 0;
338
- const e = () => {
339
- if (W.current) return;
340
- const s = Date.now();
341
- s - t < 100 || (t = s, P());
421
+ const n = () => {
422
+ if (X.current) return;
423
+ const r = Date.now();
424
+ r - t < 100 || (t = r, G());
342
425
  };
343
- n.on("zoom", e), n.on("afterDrawing", e);
426
+ o.on("zoom", n), o.on("afterDrawing", n);
344
427
  }
345
428
  return () => {
346
- l !== null && clearTimeout(l), n.destroy(), $.current = null, mt.current = null, bt.current = null;
347
- for (const t of X.current.values()) t.remove();
348
- X.current.clear();
349
- for (const t of Y.current.values()) t.remove();
350
- Y.current.clear();
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();
351
434
  };
352
- }, [r, v, y, gt, G, st]), pt(() => {
353
- const l = $.current;
354
- !l || !i || l.findNode(i).length > 0 && (l.selectNodes([i]), l.focus(i, { scale: 1.4, animation: !0 }), W.current = !0);
355
- }, [i, r]);
356
- const at = p(D);
357
- pt(() => {
358
- const l = $.current;
359
- if (!l || D === void 0 || D === at.current) {
360
- at.current = D;
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;
361
444
  return;
362
445
  }
363
- at.current = D, l.unselectAll(), l.fit({ animation: !0 }), W.current = !0;
364
- }, [D]);
365
- const xt = (l) => {
366
- const d = $.current, f = it.current;
367
- if (!d || !f) return null;
368
- const w = d.getPositions(), B = Object.values(w).map((_) => _.x), C = Object.values(w).map((_) => _.y);
369
- if (B.length === 0) return null;
370
- const K = Math.min(...B), ut = Math.max(...B), Q = Math.min(...C), T = Math.max(...C), I = f.getBoundingClientRect(), U = l.clientX - I.left, ft = l.clientY - I.top, n = Math.max(1, ut - K), P = Math.max(1, T - Q);
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);
371
454
  return {
372
- x: (U - 5) / (f.width - 10) * n + K,
373
- y: (ft - 5) / (f.height - 10) * P + Q
455
+ x: (Q - 5) / (y.width - 10) * o + J,
456
+ y: (wt - 5) / (y.height - 10) * G + nt
374
457
  };
375
- }, Ct = (l) => {
376
- var f;
377
- const d = xt(l);
378
- d && ((f = $.current) == null || f.moveTo({ position: d, animation: !0 }));
379
- }, lt = p(!1), Ot = (l) => {
380
- lt.current = !0;
381
- const d = (w) => {
382
- var C;
383
- if (!lt.current) return;
384
- const B = xt(w);
385
- B && ((C = $.current) == null || C.moveTo({ position: B }));
386
- }, f = () => {
387
- lt.current = !1, window.removeEventListener("mousemove", d), window.removeEventListener("mouseup", f);
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);
388
471
  };
389
- window.addEventListener("mousemove", d), window.addEventListener("mouseup", f), l.preventDefault();
472
+ window.addEventListener("mousemove", w), window.addEventListener("mouseup", y), u.preventDefault();
390
473
  };
391
- return /* @__PURE__ */ Rt("div", { className: Z, style: { width: "100%", height: "100%", position: "relative", ...rt }, children: [
392
- /* @__PURE__ */ ht("div", { ref: q, style: { width: "100%", height: "100%" } }),
393
- /* @__PURE__ */ ht("div", { ref: ct, style: { position: "absolute", inset: 0, overflow: "hidden", pointerEvents: "none" } }),
394
- G && /* @__PURE__ */ ht(
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(
395
478
  "canvas",
396
479
  {
397
- ref: it,
480
+ ref: dt,
398
481
  width: 140,
399
482
  height: 100,
400
- onClick: Ct,
401
- onMouseDown: Ot,
483
+ onClick: Ft,
484
+ onMouseDown: Gt,
402
485
  style: {
403
486
  // bottom 72 (not 8): host apps commonly float a chat/action
404
487
  // orb in the bottom-right corner — leave that spot free.
@@ -406,13 +489,13 @@ function jt({
406
489
  bottom: 72,
407
490
  right: 8,
408
491
  borderRadius: 4,
409
- border: `1px solid ${Mt[st].minimapBorder}`,
492
+ border: `1px solid ${kt[ft].minimapBorder}`,
410
493
  cursor: "grab"
411
494
  }
412
495
  }
413
496
  )
414
497
  ] });
415
498
  }
416
- At(jt);
417
- It();
499
+ Yt(oe);
500
+ Xt();
418
501
  //# sourceMappingURL=vis-setup.js.map