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