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