@bigplay/tree-view-core 0.3.0 → 0.4.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,52 +1,53 @@
1
- const U = {
1
+ const H = {
2
2
  nodeWidth: 180,
3
3
  nodeHeight: 64,
4
4
  levelGap: 60,
5
5
  siblingGap: 16,
6
6
  direction: "top-to-bottom",
7
- linkStyle: "elbow"
7
+ linkStyle: "elbow",
8
+ levelLayout: "tree"
8
9
  };
9
- function Y(e) {
10
- return { ...U, ...e };
10
+ function G(e) {
11
+ return { ...H, ...e };
11
12
  }
12
- function X(e) {
13
+ function U(e) {
13
14
  return e?.children;
14
15
  }
15
- function z(e) {
16
+ function R(e) {
16
17
  return e?.id;
17
18
  }
18
- function lt(e, t = {}) {
19
+ function ut(e, t = {}) {
19
20
  if (e == null) return [];
20
21
  const n = Array.isArray(e) ? e : [e];
21
- return n.length === 0 ? [] : t.getParentId ? N(n, t) : G(n, t);
22
- }
23
- function G(e, t) {
24
- const n = t.getId ?? z, i = t.getChildren ?? X, o = /* @__PURE__ */ new Set();
25
- function s(r, c, h, l) {
26
- const d = W(n(r), l);
27
- A(d, o);
28
- const p = (i(r) ?? []).map((a, f) => s(a, c + 1, d, `${l}.${f}`));
29
- return { id: d, data: r, depth: c, parentId: h, children: p, hasChildren: p.length > 0, collapsed: !1 };
22
+ return n.length === 0 ? [] : t.getParentId ? X(n, t) : Y(n, t);
23
+ }
24
+ function Y(e, t) {
25
+ const n = t.getId ?? R, i = t.getChildren ?? U, o = /* @__PURE__ */ new Set();
26
+ function s(r, h, c, l) {
27
+ const a = A(n(r), l);
28
+ W(a, o);
29
+ const u = (i(r) ?? []).map((f, p) => s(f, h + 1, a, `${l}.${p}`));
30
+ return { id: a, data: r, depth: h, parentId: c, children: u, hasChildren: u.length > 0, collapsed: !1 };
30
31
  }
31
- return e.map((r, c) => s(r, 0, null, String(c)));
32
- }
33
- function N(e, t) {
34
- const n = t.getId ?? z, i = /* @__PURE__ */ new Set(), o = e.map((h, l) => {
35
- const d = W(n(h), String(l));
36
- return A(d, i), { id: d, data: h, depth: 0, parentId: null, children: [], hasChildren: !1, collapsed: !1 };
37
- }), s = new Map(o.map((h) => [h.id, h])), r = [];
38
- if (o.forEach((h, l) => {
39
- const d = t.getParentId(e[l]), u = d == null ? void 0 : s.get(String(d));
40
- if (!u) {
41
- r.push(h);
32
+ return e.map((r, h) => s(r, 0, null, String(h)));
33
+ }
34
+ function X(e, t) {
35
+ const n = t.getId ?? R, i = /* @__PURE__ */ new Set(), o = e.map((c, l) => {
36
+ const a = A(n(c), String(l));
37
+ return W(a, i), { id: a, data: c, depth: 0, parentId: null, children: [], hasChildren: !1, collapsed: !1 };
38
+ }), s = new Map(o.map((c) => [c.id, c])), r = [];
39
+ if (o.forEach((c, l) => {
40
+ const a = t.getParentId(e[l]), d = a == null ? void 0 : s.get(String(a));
41
+ if (!d) {
42
+ r.push(c);
42
43
  return;
43
44
  }
44
- h.parentId = u.id, u.children.push(h), u.hasChildren = !0;
45
- }), V(r) !== o.length)
45
+ c.parentId = d.id, d.children.push(c), d.hasChildren = !0;
46
+ }), N(r) !== o.length)
46
47
  throw new Error("[tree-view] В данных есть цикл: часть узлов ссылается друг на друга по кругу.");
47
48
  return r;
48
49
  }
49
- function V(e) {
50
+ function N(e) {
50
51
  const t = [...e];
51
52
  for (let n = 0; n < t.length; n += 1) {
52
53
  const i = t[n];
@@ -55,21 +56,21 @@ function V(e) {
55
56
  }
56
57
  return t.length;
57
58
  }
58
- function W(e, t) {
59
+ function A(e, t) {
59
60
  return e == null || e === "" ? t : String(e);
60
61
  }
61
- function A(e, t) {
62
+ function W(e, t) {
62
63
  if (t.has(e))
63
64
  throw new Error(`[tree-view] Повторяющийся id узла: "${e}". Идентификаторы должны быть уникальными.`);
64
65
  t.add(e);
65
66
  }
66
- function at(e, t = {}) {
67
+ function ft(e, t = {}) {
67
68
  const n = e.filter((s) => s.length > 0);
68
69
  if (n.length === 0) return [];
69
70
  const i = n.length - 1, o = n.map(
70
- (s, r) => s.map((c, h) => ({
71
- id: F(c, r, h, t.getId),
72
- data: c,
71
+ (s, r) => s.map((h, c) => ({
72
+ id: F(h, r, c, t.getId),
73
+ data: h,
73
74
  // Финал — корень, поэтому глубина считается от последнего уровня.
74
75
  depth: i - r,
75
76
  parentId: null,
@@ -79,10 +80,10 @@ function at(e, t = {}) {
79
80
  }))
80
81
  );
81
82
  for (let s = 0; s < i; s += 1) {
82
- const r = o[s], c = o[s + 1], h = Math.ceil(r.length / c.length);
83
- r.forEach((l, d) => {
84
- const u = c[Math.min(Math.floor(d / h), c.length - 1)];
85
- l.parentId = u.id, u.children.push(l), u.hasChildren = !0;
83
+ const r = o[s], h = o[s + 1], c = Math.ceil(r.length / h.length);
84
+ r.forEach((l, a) => {
85
+ const d = h[Math.min(Math.floor(a / c), h.length - 1)];
86
+ l.parentId = d.id, d.children.push(l), d.hasChildren = !0;
86
87
  });
87
88
  }
88
89
  return o[i];
@@ -91,7 +92,7 @@ function F(e, t, n, i) {
91
92
  const o = i ? i(e, t, n) : e?.id;
92
93
  return o == null || o === "" ? `${t}.${n}` : String(o);
93
94
  }
94
- function dt(e, t) {
95
+ function pt(e, t) {
95
96
  if (t.size === 0) return e;
96
97
  function n(i) {
97
98
  const o = t.has(i.id);
@@ -103,22 +104,22 @@ function dt(e, t) {
103
104
  }
104
105
  return e.map(n);
105
106
  }
106
- function ut(e, t) {
107
+ function gt(e, t) {
107
108
  const n = new Set(e);
108
109
  return n.delete(t) || n.add(t), n;
109
110
  }
110
- const _ = 2, Z = 40;
111
- function ft(e, t = {}) {
112
- const n = e?.teams ?? [], i = Math.max(t.rows ?? _, n.length), o = t.techDefeatLabel ?? "ТП", s = n.map((r, c) => {
113
- const h = r.isTechDefeat === !0, l = r.isWinner === !0;
111
+ const z = 2, V = 40;
112
+ function mt(e, t = {}) {
113
+ const n = e?.teams ?? [], i = Math.max(t.rows ?? z, n.length), o = t.techDefeatLabel ?? "ТП", s = n.map((r, h) => {
114
+ const c = r.isTechDefeat === !0, l = r.isWinner === !0;
114
115
  return {
115
- key: String(r.id ?? `team-${c}`),
116
+ key: String(r.id ?? `team-${h}`),
116
117
  team: r,
117
- score: h ? o : String(r.score ?? ""),
118
+ score: c ? o : String(r.score ?? ""),
118
119
  isWinner: l,
119
120
  isLoser: !l,
120
121
  isMyTeam: r.isMyTeam === !0,
121
- isTechDefeat: h,
122
+ isTechDefeat: c,
122
123
  isEmpty: !1
123
124
  };
124
125
  });
@@ -135,48 +136,61 @@ function ft(e, t = {}) {
135
136
  });
136
137
  return { rows: s, hasMyTeam: n.some((r) => r.isMyTeam === !0) };
137
138
  }
138
- function pt(e, t = {}) {
139
+ function wt(e, t = {}) {
139
140
  const n = e?.teams ?? [];
140
- return Math.max(t.rows ?? _, n.length) * (t.rowHeight ?? Z);
141
+ return Math.max(t.rows ?? z, n.length) * (t.rowHeight ?? V);
141
142
  }
142
- const $ = { min: 0.2, max: 3 }, C = { x: 0, y: 0, scale: 1 };
143
- function v(e, t, n) {
143
+ const I = { min: 0.2, max: 3 }, S = { x: 0, y: 0, scale: 1 };
144
+ function L(e, t, n) {
144
145
  return Math.min(Math.max(e, t), n);
145
146
  }
146
- function q(e, t, n = 24, i = $) {
147
+ function Z(e, t, n = 24, i = I) {
147
148
  if (e.width <= 0 || e.height <= 0 || t.width <= 0 || t.height <= 0)
148
- return { ...C };
149
- const o = Math.max(t.width - n * 2, 1), s = Math.max(t.height - n * 2, 1), r = Math.min(o / e.width, s / e.height, 1), c = v(r, i.min, i.max);
149
+ return { ...S };
150
+ const o = Math.max(t.width - n * 2, 1), s = Math.max(t.height - n * 2, 1), r = Math.min(o / e.width, s / e.height, 1), h = L(r, i.min, i.max);
150
151
  return {
151
- scale: c,
152
- x: (t.width - e.width * c) / 2,
153
- y: (t.height - e.height * c) / 2
152
+ scale: h,
153
+ x: (t.width - e.width * h) / 2,
154
+ y: (t.height - e.height * h) / 2
154
155
  };
155
156
  }
156
- function K(e, t, n) {
157
+ function q(e, t, n) {
157
158
  return { ...e, x: e.x + t, y: e.y + n };
158
159
  }
159
- function M(e, t, n, i = $) {
160
- const o = v(e.scale * t, i.min, i.max);
160
+ function $(e, t, n, i = I) {
161
+ const o = L(e.scale * t, i.min, i.max);
161
162
  if (o === e.scale) return e;
162
163
  const s = (n.x - e.x) / e.scale, r = (n.y - e.y) / e.scale;
163
164
  return { scale: o, x: n.x - s * o, y: n.y - r * o };
164
165
  }
165
- function mt(e) {
166
+ function yt(e) {
166
167
  return `translate(${e.x}px, ${e.y}px) scale(${e.scale})`;
167
168
  }
168
- function gt(e, t) {
169
+ function xt(e, t) {
169
170
  const n = t.nodeWidth + t.levelGap, i = (e ?? []).map((o, s) => {
170
171
  const r = o.id ?? s;
171
172
  return { key: String(r), id: r, name: o.name, index: s, width: n };
172
173
  });
173
174
  return { columns: i, width: n * i.length, offset: t.levelGap / 2 };
174
175
  }
175
- function wt(e) {
176
+ function Et(e) {
176
177
  const t = e.left + e.width / 2 - e.viewport / 2;
177
- return v(t, 0, Math.max(0, e.scrollWidth - e.viewport));
178
+ return L(t, 0, Math.max(0, e.scrollWidth - e.viewport));
178
179
  }
179
- function yt(e) {
180
+ function Mt(e, t) {
181
+ return Math.max(0, e - t);
182
+ }
183
+ function Lt(e, t, n) {
184
+ return t <= 0 || n <= 0 ? 0 : L(Math.round(e / t), 0, n - 1);
185
+ }
186
+ function vt(e, t, n) {
187
+ return n ? t - 1 - e : e;
188
+ }
189
+ const K = 4;
190
+ function Ct(e, t) {
191
+ return t * L(e, 1, K);
192
+ }
193
+ function bt(e) {
180
194
  if (typeof window > "u") return null;
181
195
  let t = e?.parentElement ?? null;
182
196
  for (; t; ) {
@@ -186,41 +200,62 @@ function yt(e) {
186
200
  }
187
201
  return null;
188
202
  }
189
- function xt(e, t) {
203
+ function $t(e, t) {
190
204
  if (typeof e.scrollTo == "function") {
191
205
  e.scrollTo({ left: t, behavior: "smooth" });
192
206
  return;
193
207
  }
194
208
  e.scrollLeft = t;
195
209
  }
196
- function Et(e, t) {
210
+ function j(e, t) {
197
211
  return e.getBoundingClientRect().left - t.getBoundingClientRect().left + t.scrollLeft;
198
212
  }
199
- const j = ".tree-view__node";
200
- function Lt(e, t, n, i) {
213
+ const Q = ".tree-view__node";
214
+ function St(e, t, n, i) {
201
215
  const o = e.getBoundingClientRect().left + i;
202
- return Array.from(e.querySelectorAll(j)).filter((r) => {
203
- const c = r.getBoundingClientRect();
204
- return Math.floor((c.left + c.width / 2 - o) / n) === t;
216
+ return Array.from(e.querySelectorAll(Q)).filter((r) => {
217
+ const h = r.getBoundingClientRect();
218
+ return Math.floor((h.left + h.width / 2 - o) / n) === t;
205
219
  });
206
220
  }
207
- function Mt(e) {
208
- return typeof e.scrollIntoView != "function" ? !1 : (e.scrollIntoView({ behavior: "smooth", block: "center", inline: "center" }), !0);
221
+ function It(e, t) {
222
+ return { left: j(e, t), width: e.getBoundingClientRect().width };
209
223
  }
210
- const Ct = "(max-width: 768px)";
211
- function $t(e, t) {
224
+ const J = "tv-hidden";
225
+ function Pt(e, t, n) {
226
+ e.querySelectorAll("[data-depth]").forEach((i) => {
227
+ const o = Number(i.getAttribute("data-depth"));
228
+ i.classList.toggle(J, n(o) < t);
229
+ });
230
+ }
231
+ const Tt = "(max-width: 768px)";
232
+ function Dt(e, t) {
212
233
  if (typeof window > "u" || typeof window.matchMedia != "function") return () => {
213
234
  };
214
235
  const n = window.matchMedia(e), i = () => t(n.matches);
215
236
  return i(), typeof n.addEventListener == "function" ? (n.addEventListener("change", i), () => n.removeEventListener("change", i)) : (n.addListener(i), () => n.removeListener(i));
216
237
  }
217
- function m(e) {
238
+ function Rt(e, t) {
239
+ if (!e) return () => {
240
+ };
241
+ if (t(e.clientWidth), typeof ResizeObserver > "u") return () => {
242
+ };
243
+ const n = new ResizeObserver(() => t(e.clientWidth));
244
+ return n.observe(e), () => n.disconnect();
245
+ }
246
+ function At(e, t) {
247
+ if (!e || typeof MutationObserver > "u") return () => {
248
+ };
249
+ const n = new MutationObserver(t);
250
+ return n.observe(e, { childList: !0, subtree: !0 }), () => n.disconnect();
251
+ }
252
+ function E(e) {
218
253
  return Math.round(e * 100) / 100;
219
254
  }
220
- function Q(e) {
255
+ function tt(e) {
221
256
  return e === "top-to-bottom" || e === "bottom-to-top";
222
257
  }
223
- function J(e, t, n) {
258
+ function et(e, t, n) {
224
259
  const i = e.x + e.width / 2, o = e.y + e.height / 2, s = t.x + t.width / 2, r = t.y + t.height / 2;
225
260
  switch (n) {
226
261
  case "top-to-bottom":
@@ -233,102 +268,138 @@ function J(e, t, n) {
233
268
  return { from: { x: e.x, y: o }, to: { x: t.x + t.width, y: r } };
234
269
  }
235
270
  }
236
- function tt(e, t, n, i) {
237
- const o = m(e.x), s = m(e.y), r = m(t.x), c = m(t.y);
271
+ function nt(e, t, n, i) {
272
+ const o = E(e.x), s = E(e.y), r = E(t.x), h = E(t.y);
238
273
  if (n === "straight")
239
- return `M ${o} ${s} L ${r} ${c}`;
240
- const h = Q(i), l = m((o + r) / 2), d = m((s + c) / 2);
241
- return n === "elbow" ? h ? `M ${o} ${s} L ${o} ${d} L ${r} ${d} L ${r} ${c}` : `M ${o} ${s} L ${l} ${s} L ${l} ${c} L ${r} ${c}` : h ? `M ${o} ${s} C ${o} ${d} ${r} ${d} ${r} ${c}` : `M ${o} ${s} C ${l} ${s} ${l} ${c} ${r} ${c}`;
274
+ return `M ${o} ${s} L ${r} ${h}`;
275
+ const c = tt(i), l = E((o + r) / 2), a = E((s + h) / 2);
276
+ return n === "elbow" ? c ? `M ${o} ${s} L ${o} ${a} L ${r} ${a} L ${r} ${h}` : `M ${o} ${s} L ${l} ${s} L ${l} ${h} L ${r} ${h}` : c ? `M ${o} ${s} C ${o} ${a} ${r} ${a} ${r} ${h}` : `M ${o} ${s} C ${l} ${s} ${l} ${h} ${r} ${h}`;
242
277
  }
243
- function et(e, t) {
278
+ function it(e, t) {
244
279
  const n = new Map(e.map((o) => [o.id, o])), i = [];
245
280
  for (const o of e) {
246
281
  const s = o.parentId == null ? void 0 : n.get(o.parentId);
247
282
  if (!s) continue;
248
- const { from: r, to: c } = J(s, o, t.direction);
283
+ const { from: r, to: h } = et(s, o, t.direction);
249
284
  i.push({
250
285
  id: `${s.id}->${o.id}`,
251
286
  source: s,
252
287
  target: o,
253
- path: tt(r, c, t.linkStyle, t.direction)
288
+ path: nt(r, h, t.linkStyle, t.direction)
254
289
  });
255
290
  }
256
291
  return i;
257
292
  }
258
- function R(e, t) {
293
+ function C(e, t) {
259
294
  return typeof e == "function" ? e(t) : e;
260
295
  }
261
- function nt(e, t) {
262
- const n = t.direction === "top-to-bottom" || t.direction === "bottom-to-top", i = /* @__PURE__ */ new Map(), o = [];
296
+ function O(e, t, n) {
297
+ return typeof e == "function" ? e(t, n) : e;
298
+ }
299
+ function ot(e) {
300
+ const t = [];
301
+ for (const n of P(e)) t[n.depth] = (t[n.depth] ?? 0) + 1;
302
+ return t;
303
+ }
304
+ function k(e, t, n) {
305
+ const i = [];
306
+ let o = 0;
307
+ for (let c = 0; c < t.length; c += 1)
308
+ i[c] = o, o += (t[c] ?? 0) + n;
263
309
  let s = 0;
264
- const r = [];
265
- function c(a) {
266
- const f = R(t.nodeWidth, a), I = R(t.nodeHeight, a), S = n ? I : f, y = n ? f : I;
267
- r[a.depth] = Math.max(r[a.depth] ?? 0, S);
268
- const T = s, O = o.length;
269
- let g = s;
270
- if (a.children.length > 0) {
271
- const E = a.children.map(c), b = E[0], P = E[E.length - 1], B = b.across + b.acrossSize / 2, H = P.across + P.acrossSize / 2;
272
- g = (B + H) / 2 - y / 2;
273
- const D = T - g;
274
- if (D > 0) {
275
- for (let L = O; L < o.length; L += 1) o[L].across += D;
276
- g = T;
277
- }
278
- }
279
- const x = { depth: a.depth, along: 0, across: g, alongSize: S, acrossSize: y };
280
- return i.set(a.id, x), o.push(x), s = Math.max(s, g + y + t.siblingGap), x;
310
+ for (const c of e) {
311
+ const l = t[c.depth] ?? c.alongSize;
312
+ c.along = i[c.depth] + (l - c.alongSize) / 2, s = Math.max(s, c.across + c.acrossSize);
281
313
  }
282
- e.forEach(c);
314
+ const r = t.length - 1;
315
+ return { alongExtent: r < 0 ? 0 : i[r] + t[r], acrossExtent: s };
316
+ }
317
+ function rt(e, t) {
318
+ const n = t.direction === "top-to-bottom" || t.direction === "bottom-to-top", i = /* @__PURE__ */ new Map(), o = [], s = [], r = [];
319
+ for (const a of P(e)) (r[a.depth] ??= []).push(a);
320
+ const h = [], c = [];
321
+ r.forEach((a, d) => {
322
+ const u = [];
323
+ let f = 0;
324
+ for (const m of a) {
325
+ const g = C(t.nodeWidth, m), w = C(t.nodeHeight, m), y = n ? w : g, M = n ? g : w;
326
+ s[d] = Math.max(s[d] ?? 0, y);
327
+ const x = { depth: d, along: 0, across: f, alongSize: y, acrossSize: M };
328
+ i.set(m.id, x), u.push(x), o.push(x), f += M + O(t.siblingGap, m, a.length);
329
+ }
330
+ const p = u[u.length - 1];
331
+ h[d] = u, c[d] = p ? p.across + p.acrossSize : 0;
332
+ });
333
+ const l = Math.max(0, ...c);
334
+ return h.forEach((a, d) => {
335
+ const u = (l - (c[d] ?? 0)) / 2;
336
+ if (u > 0) for (const f of a) f.across += u;
337
+ }), { byId: i, ...k(o, s, t.levelGap) };
338
+ }
339
+ function st(e, t) {
340
+ if (t.levelLayout === "stack") return rt(e, t);
341
+ const n = t.direction === "top-to-bottom" || t.direction === "bottom-to-top", i = ot(e), o = /* @__PURE__ */ new Map(), s = [];
342
+ let r = 0;
283
343
  const h = [];
284
- let l = 0;
285
- for (let a = 0; a < r.length; a += 1)
286
- h[a] = l, l += (r[a] ?? 0) + t.levelGap;
287
- let d = 0;
288
- for (const a of o) {
289
- const f = r[a.depth] ?? a.alongSize;
290
- a.along = h[a.depth] + (f - a.alongSize) / 2, d = Math.max(d, a.across + a.acrossSize);
344
+ function c(l) {
345
+ const a = C(t.nodeWidth, l), d = C(t.nodeHeight, l), u = n ? d : a, f = n ? a : d;
346
+ h[l.depth] = Math.max(h[l.depth] ?? 0, u);
347
+ const p = r, m = s.length;
348
+ let g = r;
349
+ if (l.children.length > 0) {
350
+ const y = l.children.map(c), M = y[0], x = y[y.length - 1], _ = M.across + M.acrossSize / 2, B = x.across + x.acrossSize / 2;
351
+ g = (_ + B) / 2 - f / 2;
352
+ const T = p - g;
353
+ if (T > 0) {
354
+ for (let b = m; b < s.length; b += 1) s[b].across += T;
355
+ g = p;
356
+ }
357
+ }
358
+ const w = { depth: l.depth, along: 0, across: g, alongSize: u, acrossSize: f };
359
+ return o.set(l.id, w), s.push(w), r = Math.max(
360
+ r,
361
+ g + f + O(t.siblingGap, l, i[l.depth] ?? 1)
362
+ ), w;
291
363
  }
292
- const u = r.length - 1, p = u < 0 ? 0 : h[u] + r[u];
293
- return { byId: i, alongExtent: p, acrossExtent: d };
364
+ return e.forEach(c), { byId: o, ...k(s, h, t.levelGap) };
294
365
  }
295
- function it(e) {
366
+ function P(e) {
296
367
  const t = [];
297
368
  function n(i) {
298
369
  t.push(i), i.children.forEach(n);
299
370
  }
300
371
  return e.forEach(n), t;
301
372
  }
302
- function vt(e, t) {
303
- const n = Y(t);
373
+ function Wt(e, t) {
374
+ const n = G(t);
304
375
  if (e.length === 0)
305
376
  return { nodes: [], links: [], width: 0, height: 0 };
306
- const i = n.direction === "top-to-bottom" || n.direction === "bottom-to-top", { byId: o, alongExtent: s, acrossExtent: r } = nt(e, n), c = n.direction === "bottom-to-top" || n.direction === "right-to-left", h = it(e).map((l) => {
307
- const { along: d, across: u, alongSize: p, acrossSize: a } = o.get(l.id), f = c ? s - p - d : d;
377
+ const i = n.direction === "top-to-bottom" || n.direction === "bottom-to-top", { byId: o, alongExtent: s, acrossExtent: r } = st(e, n), h = n.direction === "bottom-to-top" || n.direction === "right-to-left", c = P(e).map((l) => {
378
+ const { along: a, across: d, alongSize: u, acrossSize: f } = o.get(l.id), p = h ? s - u - a : a;
308
379
  return {
309
380
  id: l.id,
310
381
  data: l.data,
311
382
  depth: l.depth,
312
383
  parentId: l.parentId,
313
- x: i ? u : f,
314
- y: i ? f : u,
315
- width: i ? a : p,
316
- height: i ? p : a,
384
+ x: i ? d : p,
385
+ y: i ? p : d,
386
+ width: i ? f : u,
387
+ height: i ? u : f,
317
388
  hasChildren: l.hasChildren,
318
389
  collapsed: l.collapsed
319
390
  };
320
391
  });
321
392
  return {
322
- nodes: h,
323
- links: et(h, n),
393
+ nodes: c,
394
+ links: it(c, n),
324
395
  width: i ? r : s,
325
396
  height: i ? s : r
326
397
  };
327
398
  }
328
- const w = 1.2;
329
- class It {
399
+ const v = 1.2;
400
+ class zt {
330
401
  constructor(t) {
331
- this.params = t, this.transform = { ...C }, this.element = null, this.pointers = /* @__PURE__ */ new Map(), this.lastPinchDistance = 0, this.onPointerDown = (n) => {
402
+ this.params = t, this.transform = { ...S }, this.element = null, this.pointers = /* @__PURE__ */ new Map(), this.lastPinchDistance = 0, this.onPointerDown = (n) => {
332
403
  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)));
333
404
  }, this.onPointerMove = (n) => {
334
405
  const i = this.pointers.get(n.pointerId);
@@ -337,15 +408,15 @@ class It {
337
408
  this.pinch();
338
409
  return;
339
410
  }
340
- this.set(K(this.transform, n.clientX - i.x, n.clientY - i.y));
411
+ this.set(q(this.transform, n.clientX - i.x, n.clientY - i.y));
341
412
  }
342
413
  }, this.onPointerUp = (n) => {
343
414
  this.pointers.delete(n.pointerId), this.pointers.size < 2 && (this.lastPinchDistance = 0);
344
415
  }, this.onWheel = (n) => {
345
416
  if (!this.isZoomable()) return;
346
417
  n.preventDefault();
347
- const i = n.deltaY < 0 ? w : 1 / w;
348
- this.set(M(this.transform, i, this.toLocalPoint(n), this.limits));
418
+ const i = n.deltaY < 0 ? v : 1 / v;
419
+ this.set($(this.transform, i, this.toLocalPoint(n), this.limits));
349
420
  };
350
421
  }
351
422
  /** Подписывается на события элемента. Повторный вызов сначала отписывается. */
@@ -361,7 +432,7 @@ class It {
361
432
  fit(t, n = 24) {
362
433
  const i = this.element;
363
434
  i && this.set(
364
- q(
435
+ Z(
365
436
  t,
366
437
  { width: i.clientWidth, height: i.clientHeight },
367
438
  n,
@@ -370,20 +441,20 @@ class It {
370
441
  );
371
442
  }
372
443
  zoomIn() {
373
- this.zoomToCenter(w);
444
+ this.zoomToCenter(v);
374
445
  }
375
446
  zoomOut() {
376
- this.zoomToCenter(1 / w);
447
+ this.zoomToCenter(1 / v);
377
448
  }
378
449
  reset() {
379
- this.set({ ...C });
450
+ this.set({ ...S });
380
451
  }
381
452
  /** Устанавливает состояние напрямую (например, восстановление после перезагрузки). */
382
453
  set(t) {
383
454
  this.transform = { ...t }, this.params.onChange(this.transform);
384
455
  }
385
456
  get limits() {
386
- return this.params.limits?.() ?? $;
457
+ return this.params.limits?.() ?? I;
387
458
  }
388
459
  isPannable() {
389
460
  return this.params.pannable?.() ?? !0;
@@ -398,7 +469,7 @@ class It {
398
469
  }
399
470
  zoomToCenter(t) {
400
471
  const n = this.element, i = { x: (n?.clientWidth ?? 0) / 2, y: (n?.clientHeight ?? 0) / 2 };
401
- this.set(M(this.transform, t, i, this.limits));
472
+ this.set($(this.transform, t, i, this.limits));
402
473
  }
403
474
  /** Два пальца: масштабируем вокруг точки ровно между ними. */
404
475
  pinch() {
@@ -411,21 +482,21 @@ class It {
411
482
  clientX: (t.x + n.x) / 2,
412
483
  clientY: (t.y + n.y) / 2
413
484
  });
414
- this.set(M(this.transform, i / this.lastPinchDistance, o, this.limits));
485
+ this.set($(this.transform, i / this.lastPinchDistance, o, this.limits));
415
486
  }
416
487
  this.lastPinchDistance = i;
417
488
  }
418
489
  }
419
- function St(e, t = "tree-view-styles") {
490
+ function Ot(e, t = "tree-view-styles") {
420
491
  if (typeof document > "u" || document.getElementById(t)) return;
421
492
  const n = document.createElement("style");
422
493
  n.id = t, n.textContent = e, document.head.appendChild(n);
423
494
  }
424
- const ot = 400, rt = 150;
425
- function k(e, t) {
495
+ const ct = 400, ht = 150;
496
+ function D(e, t) {
426
497
  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;
427
498
  }
428
- function st(e) {
499
+ function lt(e) {
429
500
  const { source: t, target: n } = e, i = Math.min(t.x, n.x), o = Math.min(t.y, n.y);
430
501
  return {
431
502
  x: i,
@@ -434,24 +505,24 @@ function st(e) {
434
505
  height: Math.max(t.y + t.height, n.y + n.height) - o
435
506
  };
436
507
  }
437
- function ct(e, t) {
508
+ function at(e, t) {
438
509
  return { x: e.x - t, y: e.y - t, width: e.width + t * 2, height: e.height + t * 2 };
439
510
  }
440
- function Tt(e, t, n = ot) {
441
- if (!t || e.nodes.length < rt) return e;
511
+ function kt(e, t, n = ct) {
512
+ if (!t || e.nodes.length < ht) return e;
442
513
  if (t.width <= 0 || t.height <= 0)
443
514
  return { nodes: [], links: [], width: e.width, height: e.height };
444
- const i = ct(t, n), o = [], s = [];
515
+ const i = at(t, n), o = [], s = [];
445
516
  for (const r of e.nodes)
446
- k(i, r) && o.push(r);
517
+ D(i, r) && o.push(r);
447
518
  for (const r of e.links)
448
- k(i, st(r)) && s.push(r);
519
+ D(i, lt(r)) && s.push(r);
449
520
  return { nodes: o, links: s, width: e.width, height: e.height };
450
521
  }
451
- function bt() {
522
+ function _t() {
452
523
  return typeof window > "u" ? null : { x: 0, y: 0, width: window.innerWidth, height: window.innerHeight };
453
524
  }
454
- function Pt(e, t) {
525
+ function Bt(e, t) {
455
526
  if (!e || typeof window > "u" || t <= 0) return null;
456
527
  const n = e.getBoundingClientRect(), i = Math.max(n.left, 0), o = Math.max(n.top, 0), s = Math.min(n.right, window.innerWidth), r = Math.min(n.bottom, window.innerHeight);
457
528
  return s <= i || r <= o ? { x: 0, y: 0, width: 0, height: 0 } : {
@@ -462,47 +533,56 @@ function Pt(e, t) {
462
533
  };
463
534
  }
464
535
  export {
465
- _ as DEFAULT_BRACKET_ROWS,
466
- Z as DEFAULT_BRACKET_ROW_HEIGHT,
467
- U as DEFAULT_OPTIONS,
468
- ot as DEFAULT_OVERSCAN,
469
- $ as DEFAULT_SCALE_LIMITS,
470
- C as IDENTITY_TRANSFORM,
471
- Ct as MOBILE_MEDIA_QUERY,
472
- It as PanZoomController,
473
- j as TREE_NODE_SELECTOR,
474
- rt as VIRTUALIZE_THRESHOLD,
475
- w as ZOOM_STEP,
476
- dt as applyCollapsed,
477
- pt as bracketCardHeight,
478
- ft as buildBracketCard,
479
- gt as buildBracketRounds,
480
- et as buildLinks,
481
- tt as buildPath,
482
- v as clamp,
483
- bt as estimateVisibleRect,
484
- ct as expandRect,
485
- yt as findScrollParent,
486
- q as fitToViewport,
487
- it as flatten,
488
- at as fromLevels,
489
- J as getAnchors,
490
- St as injectStyles,
491
- vt as layoutTree,
492
- Pt as measureVisibleRect,
493
- Lt as nodesInColumn,
494
- Et as offsetWithin,
495
- K as panBy,
496
- nt as placeNodes,
497
- Y as resolveOptions,
498
- wt as roundScrollLeft,
499
- Mt as scrollToNode,
500
- xt as smoothScrollLeft,
501
- mt as toCssTransform,
502
- lt as toTree,
503
- ut as toggleCollapsed,
504
- Tt as visibleLayout,
505
- $t as watchMedia,
506
- M as zoomAtPoint
536
+ z as DEFAULT_BRACKET_ROWS,
537
+ V as DEFAULT_BRACKET_ROW_HEIGHT,
538
+ H as DEFAULT_OPTIONS,
539
+ ct as DEFAULT_OVERSCAN,
540
+ I as DEFAULT_SCALE_LIMITS,
541
+ J as HIDDEN_CLASS,
542
+ S as IDENTITY_TRANSFORM,
543
+ K as MAX_GAP_STEPS,
544
+ Tt as MOBILE_MEDIA_QUERY,
545
+ zt as PanZoomController,
546
+ Q as TREE_NODE_SELECTOR,
547
+ ht as VIRTUALIZE_THRESHOLD,
548
+ v as ZOOM_STEP,
549
+ pt as applyCollapsed,
550
+ wt as bracketCardHeight,
551
+ mt as buildBracketCard,
552
+ xt as buildBracketRounds,
553
+ it as buildLinks,
554
+ nt as buildPath,
555
+ L as clamp,
556
+ _t as estimateVisibleRect,
557
+ at as expandRect,
558
+ bt as findScrollParent,
559
+ Z as fitToViewport,
560
+ P as flatten,
561
+ ft as fromLevels,
562
+ et as getAnchors,
563
+ Pt as hideRoundsBefore,
564
+ It as horizontalBox,
565
+ Ot as injectStyles,
566
+ Wt as layoutTree,
567
+ Mt as levelGapForWidth,
568
+ Bt as measureVisibleRect,
569
+ St as nodesInColumn,
570
+ j as offsetWithin,
571
+ q as panBy,
572
+ st as placeNodes,
573
+ G as resolveOptions,
574
+ Lt as roundAtScroll,
575
+ vt as roundOfDepth,
576
+ Et as roundScrollLeft,
577
+ Ct as roundSiblingGap,
578
+ $t as smoothScrollLeft,
579
+ yt as toCssTransform,
580
+ ut as toTree,
581
+ gt as toggleCollapsed,
582
+ kt as visibleLayout,
583
+ At as watchChildren,
584
+ Dt as watchMedia,
585
+ Rt as watchWidth,
586
+ $ as zoomAtPoint
507
587
  };
508
588
  //# sourceMappingURL=index.js.map