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