@bigplay/tree-view-core 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const I = {
1
+ const Y = {
2
2
  nodeWidth: 180,
3
3
  nodeHeight: 64,
4
4
  levelGap: 60,
@@ -6,71 +6,69 @@ const I = {
6
6
  direction: "top-to-bottom",
7
7
  linkStyle: "elbow"
8
8
  };
9
- function L(e) {
10
- return { ...I, ...e };
9
+ function X(e) {
10
+ return { ...Y, ...e };
11
11
  }
12
- function S(e) {
12
+ function B(e) {
13
13
  return e?.children;
14
14
  }
15
- function w(e) {
15
+ function k(e) {
16
16
  return e?.id;
17
17
  }
18
- function H(e, t = {}) {
18
+ function ct(e, t = {}) {
19
19
  if (e == null) return [];
20
20
  const n = Array.isArray(e) ? e : [e];
21
- return n.length === 0 ? [] : t.getParentId ? E(n, t) : b(n, t);
22
- }
23
- function b(e, t) {
24
- const n = t.getId ?? w, i = t.getChildren ?? S, r = /* @__PURE__ */ new Set();
25
- function o(s, h, l, d) {
26
- const c = P(n(s), d);
27
- v(c, r);
28
- const p = (i(s) ?? []).map((f, m) => o(f, h + 1, c, `${d}.${m}`));
29
- return { id: c, data: s, depth: h, parentId: l, children: p, hasChildren: p.length > 0, collapsed: !1 };
21
+ return n.length === 0 ? [] : t.getParentId ? G(n, t) : F(n, t);
22
+ }
23
+ function F(e, t) {
24
+ const n = t.getId ?? k, i = t.getChildren ?? B, o = /* @__PURE__ */ new Set();
25
+ function r(s, h, c, l) {
26
+ const d = A(n(s), l);
27
+ R(d, o);
28
+ const p = (i(s) ?? []).map((a, f) => r(a, h + 1, d, `${l}.${f}`));
29
+ return { id: d, data: s, depth: h, parentId: c, children: p, hasChildren: p.length > 0, collapsed: !1 };
30
30
  }
31
- return e.map((s, h) => o(s, 0, null, String(h)));
32
- }
33
- function E(e, t) {
34
- const n = t.getId ?? w, i = /* @__PURE__ */ new Set(), r = e.map((l, d) => {
35
- const c = P(n(l), String(d));
36
- return v(c, i), { id: c, data: l, depth: 0, parentId: null, children: [], hasChildren: !1, collapsed: !1 };
37
- }), o = new Map(r.map((l) => [l.id, l])), s = [];
38
- if (r.forEach((l, d) => {
39
- const c = t.getParentId(e[d]), a = c == null ? void 0 : o.get(String(c));
40
- if (!a) {
41
- s.push(l);
31
+ return e.map((s, h) => r(s, 0, null, String(h)));
32
+ }
33
+ function G(e, t) {
34
+ const n = t.getId ?? k, i = /* @__PURE__ */ new Set(), o = e.map((c, l) => {
35
+ const d = A(n(c), String(l));
36
+ return R(d, i), { id: d, data: c, depth: 0, parentId: null, children: [], hasChildren: !1, collapsed: !1 };
37
+ }), r = new Map(o.map((c) => [c.id, c])), s = [];
38
+ if (o.forEach((c, l) => {
39
+ const d = t.getParentId(e[l]), u = d == null ? void 0 : r.get(String(d));
40
+ if (!u) {
41
+ s.push(c);
42
42
  return;
43
43
  }
44
- l.parentId = a.id, a.children.push(l), a.hasChildren = !0;
45
- }), M(s) !== r.length)
44
+ c.parentId = u.id, u.children.push(c), u.hasChildren = !0;
45
+ }), N(s) !== o.length)
46
46
  throw new Error("[tree-view] В данных есть цикл: часть узлов ссылается друг на друга по кругу.");
47
47
  return s;
48
48
  }
49
- function M(e) {
49
+ function N(e) {
50
50
  const t = [...e];
51
- let n = 0;
52
- for (; t.length > 0; ) {
53
- const i = t.shift();
54
- n += 1;
55
- for (const r of i.children)
56
- r.depth = i.depth + 1, t.push(r);
51
+ for (let n = 0; n < t.length; n += 1) {
52
+ const i = t[n];
53
+ for (const o of i.children)
54
+ o.depth = i.depth + 1, t.push(o);
57
55
  }
58
- return n;
56
+ return t.length;
59
57
  }
60
- function P(e, t) {
58
+ function A(e, t) {
61
59
  return e == null || e === "" ? t : String(e);
62
60
  }
63
- function v(e, t) {
61
+ function R(e, t) {
64
62
  if (t.has(e))
65
63
  throw new Error(`[tree-view] Повторяющийся id узла: "${e}". Идентификаторы должны быть уникальными.`);
66
64
  t.add(e);
67
65
  }
68
- function G(e, t = {}) {
69
- const n = e.filter((o) => o.length > 0);
66
+ function lt(e, t = {}) {
67
+ const n = e.filter((r) => r.length > 0);
70
68
  if (n.length === 0) return [];
71
- const i = n.length - 1, r = n.map(
72
- (o, s) => o.map((h, l) => ({
73
- id: D(h, s, l, t.getId),
69
+ const i = n.length - 1, o = n.map(
70
+ (r, s) => r.map((h, c) => ({
71
+ id: V(h, s, c, t.getId),
74
72
  data: h,
75
73
  // Финал — корень, поэтому глубина считается от последнего уровня.
76
74
  depth: i - s,
@@ -80,162 +78,208 @@ function G(e, t = {}) {
80
78
  collapsed: !1
81
79
  }))
82
80
  );
83
- for (let o = 0; o < i; o += 1) {
84
- const s = r[o], h = r[o + 1], l = Math.ceil(s.length / h.length);
85
- s.forEach((d, c) => {
86
- const a = h[Math.min(Math.floor(c / l), h.length - 1)];
87
- d.parentId = a.id, a.children.push(d), a.hasChildren = !0;
81
+ for (let r = 0; r < i; r += 1) {
82
+ const s = o[r], h = o[r + 1], c = Math.ceil(s.length / h.length);
83
+ s.forEach((l, d) => {
84
+ const u = h[Math.min(Math.floor(d / c), h.length - 1)];
85
+ l.parentId = u.id, u.children.push(l), u.hasChildren = !0;
88
86
  });
89
87
  }
90
- return r[i];
88
+ return o[i];
91
89
  }
92
- function D(e, t, n, i) {
93
- const r = i ? i(e, t, n) : e?.id;
94
- return r == null || r === "" ? `${t}.${n}` : String(r);
90
+ function V(e, t, n, i) {
91
+ const o = i ? i(e, t, n) : e?.id;
92
+ return o == null || o === "" ? `${t}.${n}` : String(o);
95
93
  }
96
- function Z(e, t) {
94
+ function at(e, t) {
97
95
  if (t.size === 0) return e;
98
96
  function n(i) {
99
- const r = t.has(i.id);
97
+ const o = t.has(i.id);
100
98
  return {
101
99
  ...i,
102
- collapsed: r,
103
- children: r ? [] : i.children.map(n)
100
+ collapsed: o,
101
+ children: o ? [] : i.children.map(n)
104
102
  };
105
103
  }
106
104
  return e.map(n);
107
105
  }
108
- function _(e, t) {
106
+ function dt(e, t) {
109
107
  const n = new Set(e);
110
108
  return n.delete(t) || n.add(t), n;
111
109
  }
112
- function u(e) {
110
+ const W = 2, Z = 40;
111
+ function ut(e, t = {}) {
112
+ const n = e?.teams ?? [], i = Math.max(t.rows ?? W, n.length), o = t.techDefeatLabel ?? "ТП", r = n.map((s, h) => {
113
+ const c = s.isTechDefeat === !0, l = s.isWinner === !0;
114
+ return {
115
+ key: String(s.id ?? `team-${h}`),
116
+ team: s,
117
+ score: c ? o : String(s.score ?? ""),
118
+ isWinner: l,
119
+ isLoser: !l,
120
+ isMyTeam: s.isMyTeam === !0,
121
+ isTechDefeat: c,
122
+ isEmpty: !1
123
+ };
124
+ });
125
+ for (let s = n.length; s < i; s += 1)
126
+ r.push({
127
+ key: `empty-${s}`,
128
+ team: null,
129
+ score: "",
130
+ isWinner: !1,
131
+ isLoser: !1,
132
+ isMyTeam: !1,
133
+ isTechDefeat: !1,
134
+ isEmpty: !0
135
+ });
136
+ return { rows: r, hasMyTeam: n.some((s) => s.isMyTeam === !0) };
137
+ }
138
+ function ft(e, t = {}) {
139
+ const n = e?.teams ?? [];
140
+ return Math.max(t.rows ?? W, n.length) * (t.rowHeight ?? Z);
141
+ }
142
+ function m(e) {
113
143
  return Math.round(e * 100) / 100;
114
144
  }
115
- function z(e) {
145
+ function q(e) {
116
146
  return e === "top-to-bottom" || e === "bottom-to-top";
117
147
  }
118
- function T(e, t, n) {
119
- const i = e.x + e.width / 2, r = e.y + e.height / 2, o = t.x + t.width / 2, s = t.y + t.height / 2;
148
+ function K(e, t, n) {
149
+ const i = e.x + e.width / 2, o = e.y + e.height / 2, r = t.x + t.width / 2, s = t.y + t.height / 2;
120
150
  switch (n) {
121
151
  case "top-to-bottom":
122
- return { from: { x: i, y: e.y + e.height }, to: { x: o, y: t.y } };
152
+ return { from: { x: i, y: e.y + e.height }, to: { x: r, y: t.y } };
123
153
  case "bottom-to-top":
124
- return { from: { x: i, y: e.y }, to: { x: o, y: t.y + t.height } };
154
+ return { from: { x: i, y: e.y }, to: { x: r, y: t.y + t.height } };
125
155
  case "left-to-right":
126
- return { from: { x: e.x + e.width, y: r }, to: { x: t.x, y: s } };
156
+ return { from: { x: e.x + e.width, y: o }, to: { x: t.x, y: s } };
127
157
  case "right-to-left":
128
- return { from: { x: e.x, y: r }, to: { x: t.x + t.width, y: s } };
158
+ return { from: { x: e.x, y: o }, to: { x: t.x + t.width, y: s } };
129
159
  }
130
160
  }
131
- function O(e, t, n, i) {
132
- const r = u(e.x), o = u(e.y), s = u(t.x), h = u(t.y);
161
+ function j(e, t, n, i) {
162
+ const o = m(e.x), r = m(e.y), s = m(t.x), h = m(t.y);
133
163
  if (n === "straight")
134
- return `M ${r} ${o} L ${s} ${h}`;
135
- const l = z(i), d = u((r + s) / 2), c = u((o + h) / 2);
136
- return n === "elbow" ? l ? `M ${r} ${o} L ${r} ${c} L ${s} ${c} L ${s} ${h}` : `M ${r} ${o} L ${d} ${o} L ${d} ${h} L ${s} ${h}` : l ? `M ${r} ${o} C ${r} ${c} ${s} ${c} ${s} ${h}` : `M ${r} ${o} C ${d} ${o} ${d} ${h} ${s} ${h}`;
137
- }
138
- function Y(e, t) {
139
- const n = new Map(e.map((r) => [r.id, r])), i = [];
140
- for (const r of e) {
141
- const o = r.parentId == null ? void 0 : n.get(r.parentId);
142
- if (!o) continue;
143
- const { from: s, to: h } = T(o, r, t.direction);
164
+ return `M ${o} ${r} L ${s} ${h}`;
165
+ const c = q(i), l = m((o + s) / 2), d = m((r + h) / 2);
166
+ return n === "elbow" ? c ? `M ${o} ${r} L ${o} ${d} L ${s} ${d} L ${s} ${h}` : `M ${o} ${r} L ${l} ${r} L ${l} ${h} L ${s} ${h}` : c ? `M ${o} ${r} C ${o} ${d} ${s} ${d} ${s} ${h}` : `M ${o} ${r} C ${l} ${r} ${l} ${h} ${s} ${h}`;
167
+ }
168
+ function J(e, t) {
169
+ const n = new Map(e.map((o) => [o.id, o])), i = [];
170
+ for (const o of e) {
171
+ const r = o.parentId == null ? void 0 : n.get(o.parentId);
172
+ if (!r) continue;
173
+ const { from: s, to: h } = K(r, o, t.direction);
144
174
  i.push({
145
- id: `${o.id}->${r.id}`,
146
- source: o,
147
- target: r,
148
- path: O(s, h, t.linkStyle, t.direction)
175
+ id: `${r.id}->${o.id}`,
176
+ source: r,
177
+ target: o,
178
+ path: j(s, h, t.linkStyle, t.direction)
149
179
  });
150
180
  }
151
181
  return i;
152
182
  }
153
- function W(e) {
154
- const t = e.direction === "top-to-bottom" || e.direction === "bottom-to-top", n = t ? e.nodeHeight : e.nodeWidth, i = t ? e.nodeWidth : e.nodeHeight;
155
- return {
156
- vertical: t,
157
- alongSize: n,
158
- acrossSize: i,
159
- alongStep: n + e.levelGap,
160
- acrossStep: i + e.siblingGap
161
- };
183
+ function D(e, t) {
184
+ return typeof e == "function" ? e(t) : e;
162
185
  }
163
- function A(e) {
164
- const t = /* @__PURE__ */ new Map();
165
- let n = 0, i = 0;
166
- function r(o) {
167
- if (o.depth > i && (i = o.depth), o.children.length === 0) {
168
- const l = n;
169
- return n += 1, t.set(o.id, l), l;
186
+ function Q(e, t) {
187
+ const n = t.direction === "top-to-bottom" || t.direction === "bottom-to-top", i = /* @__PURE__ */ new Map(), o = [];
188
+ let r = 0;
189
+ const s = [];
190
+ function h(a) {
191
+ const f = D(t.nodeWidth, a), I = D(t.nodeHeight, a), b = n ? I : f, w = n ? f : I;
192
+ s[a.depth] = Math.max(s[a.depth] ?? 0, b);
193
+ const P = r, O = o.length;
194
+ let g = r;
195
+ if (a.children.length > 0) {
196
+ const $ = a.children.map(h), S = $[0], T = $[$.length - 1], U = S.across + S.acrossSize / 2, _ = T.across + T.acrossSize / 2;
197
+ g = (U + _) / 2 - w / 2;
198
+ const v = P - g;
199
+ if (v > 0) {
200
+ for (let M = O; M < o.length; M += 1) o[M].across += v;
201
+ g = P;
202
+ }
170
203
  }
171
- const s = o.children.map(r), h = (s[0] + s[s.length - 1]) / 2;
172
- return t.set(o.id, h), h;
204
+ const y = { depth: a.depth, along: 0, across: g, alongSize: b, acrossSize: w };
205
+ return i.set(a.id, y), o.push(y), r = Math.max(r, g + w + t.siblingGap), y;
206
+ }
207
+ e.forEach(h);
208
+ const c = [];
209
+ let l = 0;
210
+ for (let a = 0; a < s.length; a += 1)
211
+ c[a] = l, l += (s[a] ?? 0) + t.levelGap;
212
+ let d = 0;
213
+ for (const a of o) {
214
+ const f = s[a.depth] ?? a.alongSize;
215
+ a.along = c[a.depth] + (f - a.alongSize) / 2, d = Math.max(d, a.across + a.acrossSize);
173
216
  }
174
- return e.forEach(r), { orders: t, maxOrder: Math.max(0, n - 1), maxDepth: i };
217
+ const u = s.length - 1, p = u < 0 ? 0 : c[u] + s[u];
218
+ return { byId: i, alongExtent: p, acrossExtent: d };
175
219
  }
176
- function X(e) {
220
+ function tt(e) {
177
221
  const t = [];
178
222
  function n(i) {
179
223
  t.push(i), i.children.forEach(n);
180
224
  }
181
225
  return e.forEach(n), t;
182
226
  }
183
- function F(e, t) {
184
- const n = L(t), i = W(n);
227
+ function pt(e, t) {
228
+ const n = X(t);
185
229
  if (e.length === 0)
186
230
  return { nodes: [], links: [], width: 0, height: 0 };
187
- const { orders: r, maxOrder: o, maxDepth: s } = A(e), h = s * i.alongStep + i.alongSize, l = o * i.acrossStep + i.acrossSize, d = n.direction === "bottom-to-top" || n.direction === "right-to-left", c = X(e).map((a) => {
188
- const p = a.depth * i.alongStep, f = r.get(a.id) * i.acrossStep, m = d ? h - i.alongSize - p : p;
231
+ const i = n.direction === "top-to-bottom" || n.direction === "bottom-to-top", { byId: o, alongExtent: r, acrossExtent: s } = Q(e, n), h = n.direction === "bottom-to-top" || n.direction === "right-to-left", c = tt(e).map((l) => {
232
+ const { along: d, across: u, alongSize: p, acrossSize: a } = o.get(l.id), f = h ? r - p - d : d;
189
233
  return {
190
- id: a.id,
191
- data: a.data,
192
- depth: a.depth,
193
- parentId: a.parentId,
194
- x: i.vertical ? f : m,
195
- y: i.vertical ? m : f,
196
- width: n.nodeWidth,
197
- height: n.nodeHeight,
198
- hasChildren: a.hasChildren,
199
- collapsed: a.collapsed
234
+ id: l.id,
235
+ data: l.data,
236
+ depth: l.depth,
237
+ parentId: l.parentId,
238
+ x: i ? u : f,
239
+ y: i ? f : u,
240
+ width: i ? a : p,
241
+ height: i ? p : a,
242
+ hasChildren: l.hasChildren,
243
+ collapsed: l.collapsed
200
244
  };
201
245
  });
202
246
  return {
203
247
  nodes: c,
204
- links: Y(c, n),
205
- width: i.vertical ? l : h,
206
- height: i.vertical ? h : l
248
+ links: J(c, n),
249
+ width: i ? s : r,
250
+ height: i ? r : s
207
251
  };
208
252
  }
209
- const $ = { min: 0.2, max: 3 }, y = { x: 0, y: 0, scale: 1 };
210
- function C(e, t, n) {
253
+ const L = { min: 0.2, max: 3 }, E = { x: 0, y: 0, scale: 1 };
254
+ function H(e, t, n) {
211
255
  return Math.min(Math.max(e, t), n);
212
256
  }
213
- function k(e, t, n = 24, i = $) {
257
+ function et(e, t, n = 24, i = L) {
214
258
  if (e.width <= 0 || e.height <= 0 || t.width <= 0 || t.height <= 0)
215
- return { ...y };
216
- const r = Math.max(t.width - n * 2, 1), o = Math.max(t.height - n * 2, 1), s = Math.min(r / e.width, o / e.height, 1), h = C(s, i.min, i.max);
259
+ return { ...E };
260
+ const o = Math.max(t.width - n * 2, 1), r = Math.max(t.height - n * 2, 1), s = Math.min(o / e.width, r / e.height, 1), h = H(s, i.min, i.max);
217
261
  return {
218
262
  scale: h,
219
263
  x: (t.width - e.width * h) / 2,
220
264
  y: (t.height - e.height * h) / 2
221
265
  };
222
266
  }
223
- function U(e, t, n) {
267
+ function nt(e, t, n) {
224
268
  return { ...e, x: e.x + t, y: e.y + n };
225
269
  }
226
- function x(e, t, n, i = $) {
227
- const r = C(e.scale * t, i.min, i.max);
228
- if (r === e.scale) return e;
229
- const o = (n.x - e.x) / e.scale, s = (n.y - e.y) / e.scale;
230
- return { scale: r, x: n.x - o * r, y: n.y - s * r };
270
+ function C(e, t, n, i = L) {
271
+ const o = H(e.scale * t, i.min, i.max);
272
+ if (o === e.scale) return e;
273
+ const r = (n.x - e.x) / e.scale, s = (n.y - e.y) / e.scale;
274
+ return { scale: o, x: n.x - r * o, y: n.y - s * o };
231
275
  }
232
- function N(e) {
276
+ function mt(e) {
233
277
  return `translate(${e.x}px, ${e.y}px) scale(${e.scale})`;
234
278
  }
235
- const g = 1.2;
236
- class B {
279
+ const x = 1.2;
280
+ class gt {
237
281
  constructor(t) {
238
- this.params = t, this.transform = { ...y }, this.element = null, this.pointers = /* @__PURE__ */ new Map(), this.lastPinchDistance = 0, this.onPointerDown = (n) => {
282
+ this.params = t, this.transform = { ...E }, this.element = null, this.pointers = /* @__PURE__ */ new Map(), this.lastPinchDistance = 0, this.onPointerDown = (n) => {
239
283
  this.isPannable() && (n.target?.closest?.("[data-tv-no-pan]") || (this.pointers.set(n.pointerId, { x: n.clientX, y: n.clientY }), this.element?.setPointerCapture?.(n.pointerId)));
240
284
  }, this.onPointerMove = (n) => {
241
285
  const i = this.pointers.get(n.pointerId);
@@ -244,15 +288,15 @@ class B {
244
288
  this.pinch();
245
289
  return;
246
290
  }
247
- this.set(U(this.transform, n.clientX - i.x, n.clientY - i.y));
291
+ this.set(nt(this.transform, n.clientX - i.x, n.clientY - i.y));
248
292
  }
249
293
  }, this.onPointerUp = (n) => {
250
294
  this.pointers.delete(n.pointerId), this.pointers.size < 2 && (this.lastPinchDistance = 0);
251
295
  }, this.onWheel = (n) => {
252
296
  if (!this.isZoomable()) return;
253
297
  n.preventDefault();
254
- const i = n.deltaY < 0 ? g : 1 / g;
255
- this.set(x(this.transform, i, this.toLocalPoint(n), this.limits));
298
+ const i = n.deltaY < 0 ? x : 1 / x;
299
+ this.set(C(this.transform, i, this.toLocalPoint(n), this.limits));
256
300
  };
257
301
  }
258
302
  /** Подписывается на события элемента. Повторный вызов сначала отписывается. */
@@ -268,7 +312,7 @@ class B {
268
312
  fit(t, n = 24) {
269
313
  const i = this.element;
270
314
  i && this.set(
271
- k(
315
+ et(
272
316
  t,
273
317
  { width: i.clientWidth, height: i.clientHeight },
274
318
  n,
@@ -277,20 +321,20 @@ class B {
277
321
  );
278
322
  }
279
323
  zoomIn() {
280
- this.zoomToCenter(g);
324
+ this.zoomToCenter(x);
281
325
  }
282
326
  zoomOut() {
283
- this.zoomToCenter(1 / g);
327
+ this.zoomToCenter(1 / x);
284
328
  }
285
329
  reset() {
286
- this.set({ ...y });
330
+ this.set({ ...E });
287
331
  }
288
332
  /** Устанавливает состояние напрямую (например, восстановление после перезагрузки). */
289
333
  set(t) {
290
334
  this.transform = { ...t }, this.params.onChange(this.transform);
291
335
  }
292
336
  get limits() {
293
- return this.params.limits?.() ?? $;
337
+ return this.params.limits?.() ?? L;
294
338
  }
295
339
  isPannable() {
296
340
  return this.params.pannable?.() ?? !0;
@@ -305,7 +349,7 @@ class B {
305
349
  }
306
350
  zoomToCenter(t) {
307
351
  const n = this.element, i = { x: (n?.clientWidth ?? 0) / 2, y: (n?.clientHeight ?? 0) / 2 };
308
- this.set(x(this.transform, t, i, this.limits));
352
+ this.set(C(this.transform, t, i, this.limits));
309
353
  }
310
354
  /** Два пальца: масштабируем вокруг точки ровно между ними. */
311
355
  pinch() {
@@ -314,42 +358,92 @@ class B {
314
358
  if (!t || !n) return;
315
359
  const i = Math.hypot(t.x - n.x, t.y - n.y);
316
360
  if (this.lastPinchDistance > 0 && i > 0) {
317
- const r = this.toLocalPoint({
361
+ const o = this.toLocalPoint({
318
362
  clientX: (t.x + n.x) / 2,
319
363
  clientY: (t.y + n.y) / 2
320
364
  });
321
- this.set(x(this.transform, i / this.lastPinchDistance, r, this.limits));
365
+ this.set(C(this.transform, i / this.lastPinchDistance, o, this.limits));
322
366
  }
323
367
  this.lastPinchDistance = i;
324
368
  }
325
369
  }
326
- function R(e, t = "tree-view-styles") {
370
+ function xt(e, t = "tree-view-styles") {
327
371
  if (typeof document > "u" || document.getElementById(t)) return;
328
372
  const n = document.createElement("style");
329
373
  n.id = t, n.textContent = e, document.head.appendChild(n);
330
374
  }
375
+ const it = 400, ot = 150;
376
+ function z(e, t) {
377
+ return e.x <= t.x + t.width && e.x + e.width >= t.x && e.y <= t.y + t.height && e.y + e.height >= t.y;
378
+ }
379
+ function st(e) {
380
+ const { source: t, target: n } = e, i = Math.min(t.x, n.x), o = Math.min(t.y, n.y);
381
+ return {
382
+ x: i,
383
+ y: o,
384
+ width: Math.max(t.x + t.width, n.x + n.width) - i,
385
+ height: Math.max(t.y + t.height, n.y + n.height) - o
386
+ };
387
+ }
388
+ function rt(e, t) {
389
+ return { x: e.x - t, y: e.y - t, width: e.width + t * 2, height: e.height + t * 2 };
390
+ }
391
+ function wt(e, t, n = it) {
392
+ if (!t || e.nodes.length < ot) return e;
393
+ if (t.width <= 0 || t.height <= 0)
394
+ return { nodes: [], links: [], width: e.width, height: e.height };
395
+ const i = rt(t, n), o = [], r = [];
396
+ for (const s of e.nodes)
397
+ z(i, s) && o.push(s);
398
+ for (const s of e.links)
399
+ z(i, st(s)) && r.push(s);
400
+ return { nodes: o, links: r, width: e.width, height: e.height };
401
+ }
402
+ function yt() {
403
+ return typeof window > "u" ? null : { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight };
404
+ }
405
+ function $t(e, t) {
406
+ if (!e || typeof window > "u" || t <= 0) return null;
407
+ const n = e.getBoundingClientRect(), i = Math.max(n.left, 0), o = Math.max(n.top, 0), r = Math.min(n.right, window.innerWidth), s = Math.min(n.bottom, window.innerHeight);
408
+ return r <= i || s <= o ? { x: 0, y: 0, width: 0, height: 0 } : {
409
+ x: (i - n.left) / t,
410
+ y: (o - n.top) / t,
411
+ width: (r - i) / t,
412
+ height: (s - o) / t
413
+ };
414
+ }
331
415
  export {
332
- I as DEFAULT_OPTIONS,
333
- $ as DEFAULT_SCALE_LIMITS,
334
- y as IDENTITY_TRANSFORM,
335
- B as PanZoomController,
336
- g as ZOOM_STEP,
337
- Z as applyCollapsed,
338
- A as assignOrders,
339
- Y as buildLinks,
340
- O as buildPath,
341
- C as clamp,
342
- k as fitToViewport,
343
- X as flatten,
344
- G as fromLevels,
345
- T as getAnchors,
346
- R as injectStyles,
347
- F as layoutTree,
348
- U as panBy,
349
- L as resolveOptions,
350
- N as toCssTransform,
351
- H as toTree,
352
- _ as toggleCollapsed,
353
- x as zoomAtPoint
416
+ W as DEFAULT_BRACKET_ROWS,
417
+ Z as DEFAULT_BRACKET_ROW_HEIGHT,
418
+ Y as DEFAULT_OPTIONS,
419
+ it as DEFAULT_OVERSCAN,
420
+ L as DEFAULT_SCALE_LIMITS,
421
+ E as IDENTITY_TRANSFORM,
422
+ gt as PanZoomController,
423
+ ot as VIRTUALIZE_THRESHOLD,
424
+ x as ZOOM_STEP,
425
+ at as applyCollapsed,
426
+ ft as bracketCardHeight,
427
+ ut as buildBracketCard,
428
+ J as buildLinks,
429
+ j as buildPath,
430
+ H as clamp,
431
+ yt as estimateVisibleRect,
432
+ rt as expandRect,
433
+ et as fitToViewport,
434
+ tt as flatten,
435
+ lt as fromLevels,
436
+ K as getAnchors,
437
+ xt as injectStyles,
438
+ pt as layoutTree,
439
+ $t as measureVisibleRect,
440
+ nt as panBy,
441
+ Q as placeNodes,
442
+ X as resolveOptions,
443
+ mt as toCssTransform,
444
+ ct as toTree,
445
+ dt as toggleCollapsed,
446
+ wt as visibleLayout,
447
+ C as zoomAtPoint
354
448
  };
355
449
  //# sourceMappingURL=index.js.map