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