@phun-ky/arclace 0.2.0 → 0.3.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/CHANGELOG.md +42 -0
- package/README.md +66 -45
- package/dist/arclace.d.ts +88 -43
- package/dist/arclace.js +497 -298
- package/dist/arclace.js.map +1 -1
- package/dist/arclace.umd.cjs +1 -1
- package/dist/arclace.umd.cjs.map +1 -1
- package/package.json +4 -1
- package/src/Arclace.ts +145 -55
- package/src/Connection.ts +98 -50
- package/src/errors.ts +25 -0
- package/src/index.ts +2 -2
- package/src/types.ts +6 -6
- package/src/utils/geometry.ts +16 -13
- package/src/utils/paths.ts +71 -36
- package/src/utils/resolve-element.ts +26 -9
- package/src/utils/sides.ts +8 -8
- package/src/utils/validate.ts +253 -0
package/dist/arclace.js
CHANGED
|
@@ -1,72 +1,178 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var _t = Object.defineProperty;
|
|
2
|
+
var mt = (e) => {
|
|
3
3
|
throw TypeError(e);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
5
|
+
var Rt = (e, t, n) => t in e ? _t(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
6
|
+
var z = (e, t, n) => Rt(e, typeof t != "symbol" ? t + "" : t, n), et = (e, t, n) => t.has(e) || mt("Cannot " + n);
|
|
7
|
+
var r = (e, t, n) => (et(e, t, "read from private field"), n ? n.call(e) : t.get(e)), p = (e, t, n) => t.has(e) ? mt("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), l = (e, t, n, s) => (et(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), y = (e, t, n) => (et(e, t, "access private method"), n);
|
|
8
|
+
class N extends Error {
|
|
9
|
+
constructor(n, s) {
|
|
10
|
+
super(`arclace: ${n}`, s);
|
|
11
|
+
z(this, "name", "ArclaceError");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const B = Object.freeze({
|
|
15
|
+
top: Object.freeze({ x: 0, y: -1 }),
|
|
16
|
+
right: Object.freeze({ x: 1, y: 0 }),
|
|
17
|
+
bottom: Object.freeze({ x: 0, y: 1 }),
|
|
18
|
+
left: Object.freeze({ x: -1, y: 0 })
|
|
19
|
+
}), At = Object.freeze({
|
|
14
20
|
top: "bottom",
|
|
15
21
|
right: "left",
|
|
16
22
|
bottom: "top",
|
|
17
23
|
left: "right"
|
|
18
|
-
},
|
|
24
|
+
}), it = (e) => e === "left" || e === "right", J = (e) => ({
|
|
19
25
|
x: e.left + e.width / 2,
|
|
20
26
|
y: e.top + e.height / 2
|
|
21
|
-
}),
|
|
22
|
-
|
|
27
|
+
}), q = (e, t, n = 1) => ({ x: e.x + t.x * n, y: e.y + t.y * n }), I = (e, t) => Math.hypot(t.x - e.x, t.y - e.y), bt = (e) => Math.round(e * 100) / 100, O = (e) => `${bt(e.x)} ${bt(e.y)}`, jt = () => "_" + Math.random().toString(36).substring(2, 11), ct = Object.freeze([
|
|
28
|
+
"top",
|
|
29
|
+
"right",
|
|
30
|
+
"bottom",
|
|
31
|
+
"left"
|
|
32
|
+
]), xt = Object.freeze([
|
|
33
|
+
...ct,
|
|
34
|
+
"auto"
|
|
35
|
+
]), Lt = Object.freeze([
|
|
36
|
+
"bezier",
|
|
37
|
+
"straight",
|
|
38
|
+
"orthogonal"
|
|
39
|
+
]), It = Object.freeze([
|
|
40
|
+
"none",
|
|
41
|
+
"start",
|
|
42
|
+
"end",
|
|
43
|
+
"both"
|
|
44
|
+
]), C = (e) => typeof e == "string" ? JSON.stringify(e) : e == null || typeof e == "number" || typeof e == "boolean" ? String(e) : Array.isArray(e) ? "an array" : typeof e == "object" ? "an object" : `a ${typeof e}`, Z = (e, t) => {
|
|
45
|
+
if (typeof e != "object" || e === null || Array.isArray(e))
|
|
46
|
+
throw new TypeError(
|
|
47
|
+
`arclace: ${t} must be an object, not ${C(e)}`
|
|
48
|
+
);
|
|
49
|
+
}, F = (e, t, n) => {
|
|
50
|
+
const s = t.map((o) => `"${o}"`).join(", ");
|
|
51
|
+
if (typeof e != "string")
|
|
52
|
+
throw new TypeError(
|
|
53
|
+
`arclace: ${n} must be one of ${s}, not ${C(e)}`
|
|
54
|
+
);
|
|
55
|
+
if (!t.includes(e))
|
|
56
|
+
throw new RangeError(
|
|
57
|
+
`arclace: ${n} must be one of ${s}, not ${C(e)}`
|
|
58
|
+
);
|
|
59
|
+
return e;
|
|
60
|
+
}, A = (e, t, n) => {
|
|
61
|
+
if (typeof e != "number" || !Number.isFinite(e))
|
|
62
|
+
throw new TypeError(
|
|
63
|
+
`arclace: ${t} must be a finite number, not ${C(e)}`
|
|
64
|
+
);
|
|
65
|
+
if (n !== void 0 && e < n)
|
|
66
|
+
throw new RangeError(
|
|
67
|
+
`arclace: ${t} must be ${n} or more, not ${C(e)}`
|
|
68
|
+
);
|
|
69
|
+
return e;
|
|
70
|
+
}, G = (e, t) => {
|
|
71
|
+
if (typeof e != "boolean")
|
|
72
|
+
throw new TypeError(
|
|
73
|
+
`arclace: ${t} must be true or false, not ${C(e)}`
|
|
74
|
+
);
|
|
75
|
+
return e;
|
|
76
|
+
}, Y = (e, t, n = !1) => {
|
|
77
|
+
if (typeof e != "string" || n && e === "")
|
|
78
|
+
throw new TypeError(
|
|
79
|
+
`arclace: ${t} must be a ${n ? "non-empty " : ""}string, not ${C(e)}`
|
|
80
|
+
);
|
|
81
|
+
return e;
|
|
82
|
+
}, K = (e, t) => {
|
|
83
|
+
Z(e, t);
|
|
84
|
+
const { x: n, y: s } = e;
|
|
85
|
+
return A(n, `${t}.x`), A(s, `${t}.y`), e;
|
|
86
|
+
}, Ft = Object.freeze({
|
|
87
|
+
id: (e, t) => Y(e, t, !0),
|
|
88
|
+
type: (e, t) => F(e, Lt, t),
|
|
89
|
+
startSide: (e, t) => F(e, xt, t),
|
|
90
|
+
endSide: (e, t) => F(e, xt, t),
|
|
91
|
+
arrow: (e, t) => F(e, It, t),
|
|
92
|
+
label: Y,
|
|
93
|
+
color: Y,
|
|
94
|
+
className: Y,
|
|
95
|
+
strokeWidth: (e, t) => A(e, t, 0),
|
|
96
|
+
dashed: G,
|
|
97
|
+
animated: G,
|
|
98
|
+
anchors: G,
|
|
99
|
+
gap: (e, t) => A(e, t),
|
|
100
|
+
spread: G,
|
|
101
|
+
spacing: (e, t) => A(e, t, 0),
|
|
102
|
+
curvature: (e, t) => A(e, t),
|
|
103
|
+
radius: (e, t) => A(e, t, 0),
|
|
104
|
+
offset: (e, t) => A(e, t, 0)
|
|
105
|
+
}), dt = (e, t = "options") => {
|
|
106
|
+
Z(e, t);
|
|
107
|
+
for (const [n, s] of Object.entries(Ft)) {
|
|
108
|
+
const o = Object.hasOwn(e, n) ? e[n] : void 0;
|
|
109
|
+
o !== void 0 && s(o, `${t}.${n}`);
|
|
110
|
+
}
|
|
111
|
+
return e;
|
|
112
|
+
}, Wt = (e) => {
|
|
113
|
+
Z(e, "options");
|
|
114
|
+
const { autoUpdate: t, className: n, defaults: s } = e;
|
|
115
|
+
if (t !== void 0 && typeof t != "boolean" && t !== "frame")
|
|
116
|
+
throw new RangeError(
|
|
117
|
+
`arclace: options.autoUpdate must be true, false or "frame", not ${C(t)}`
|
|
118
|
+
);
|
|
119
|
+
if (n !== void 0 && Y(n, "options.className"), s !== void 0 && (dt(s, "options.defaults"), s.id !== void 0))
|
|
120
|
+
throw new TypeError(
|
|
121
|
+
"arclace: options.defaults cannot set an id; ids belong to single connections"
|
|
122
|
+
);
|
|
123
|
+
return e;
|
|
124
|
+
}, Dt = (e, t = 1e3) => Math.min(e / t, 1), Ut = (e, t, n) => t + (n - t) * e, Bt = (e, t = 1.1, n = 3.5, s = 1e3) => Ut(Dt(e, s), t, n), St = (e, t, n, s) => {
|
|
125
|
+
K(e, "start"), F(t, ct, "startSide"), K(n, "end"), F(s, ct, "endSide");
|
|
126
|
+
}, qt = (e, t) => (K(e, "start"), K(t, "end"), {
|
|
127
|
+
d: `M ${O(e)} L ${O(t)}`,
|
|
23
128
|
labelPoint: { x: (e.x + t.x) / 2, y: (e.y + t.y) / 2 }
|
|
24
|
-
}),
|
|
25
|
-
|
|
129
|
+
}), Yt = (e, t, n, s, o = 1) => {
|
|
130
|
+
St(e, t, n, s), A(o, "curvature");
|
|
131
|
+
const i = I(e, n), c = i / Bt(i) * o, a = q(e, B[t], c), h = q(n, B[s], c);
|
|
26
132
|
return {
|
|
27
|
-
d: `M ${
|
|
133
|
+
d: `M ${O(e)} C ${O(a)}, ${O(h)}, ${O(n)}`,
|
|
28
134
|
// Point on the curve at t = 0.5
|
|
29
135
|
labelPoint: {
|
|
30
|
-
x: (e.x + 3 *
|
|
31
|
-
y: (e.y + 3 *
|
|
136
|
+
x: (e.x + 3 * a.x + 3 * h.x + n.x) / 8,
|
|
137
|
+
y: (e.y + 3 * a.y + 3 * h.y + n.y) / 8
|
|
32
138
|
}
|
|
33
139
|
};
|
|
34
|
-
},
|
|
140
|
+
}, Xt = (e) => {
|
|
35
141
|
const t = e.filter(
|
|
36
|
-
(n, s) => s === 0 ||
|
|
142
|
+
(n, s) => s === 0 || I(n, e[s - 1]) > 0.01
|
|
37
143
|
);
|
|
38
144
|
return t.filter((n, s) => {
|
|
39
145
|
if (s === 0 || s === t.length - 1) return !0;
|
|
40
|
-
const o = t[s - 1],
|
|
146
|
+
const o = t[s - 1], i = t[s + 1], c = (n.x - o.x) * (i.y - o.y) - (n.y - o.y) * (i.x - o.x);
|
|
41
147
|
return Math.abs(c) > 0.01;
|
|
42
148
|
});
|
|
43
|
-
},
|
|
149
|
+
}, Ht = (e, t) => {
|
|
44
150
|
if (e.length === 0) return "";
|
|
45
|
-
const n = (o,
|
|
46
|
-
const
|
|
151
|
+
const n = (o, i, c) => {
|
|
152
|
+
const a = I(o, i);
|
|
47
153
|
return {
|
|
48
|
-
x: o.x + (
|
|
49
|
-
y: o.y + (
|
|
154
|
+
x: o.x + (i.x - o.x) / a * c,
|
|
155
|
+
y: o.y + (i.y - o.y) / a * c
|
|
50
156
|
};
|
|
51
|
-
}, s = [`M ${
|
|
157
|
+
}, s = [`M ${O(e[0])}`];
|
|
52
158
|
for (let o = 1; o < e.length - 1; o++) {
|
|
53
|
-
const
|
|
159
|
+
const i = e[o - 1], c = e[o], a = e[o + 1], h = Math.min(
|
|
54
160
|
t,
|
|
55
|
-
|
|
56
|
-
|
|
161
|
+
I(i, c) / 2,
|
|
162
|
+
I(c, a) / 2
|
|
57
163
|
);
|
|
58
|
-
if (
|
|
59
|
-
s.push(`L ${
|
|
164
|
+
if (h <= 0) {
|
|
165
|
+
s.push(`L ${O(c)}`);
|
|
60
166
|
continue;
|
|
61
167
|
}
|
|
62
168
|
s.push(
|
|
63
|
-
`L ${
|
|
64
|
-
`Q ${
|
|
169
|
+
`L ${O(n(c, i, h))}`,
|
|
170
|
+
`Q ${O(c)}, ${O(n(c, a, h))}`
|
|
65
171
|
);
|
|
66
172
|
}
|
|
67
|
-
return e.length > 1 && s.push(`L ${
|
|
68
|
-
},
|
|
69
|
-
const t = e.slice(1).map((s, o) =>
|
|
173
|
+
return e.length > 1 && s.push(`L ${O(e[e.length - 1])}`), s.join(" ");
|
|
174
|
+
}, Gt = (e) => {
|
|
175
|
+
const t = e.slice(1).map((s, o) => I(e[o], s));
|
|
70
176
|
let n = t.reduce((s, o) => s + o, 0) / 2;
|
|
71
177
|
for (let s = 0; s < t.length; s++) {
|
|
72
178
|
if (n <= t[s] && t[s] > 0) {
|
|
@@ -79,56 +185,57 @@ const q = {
|
|
|
79
185
|
n -= t[s];
|
|
80
186
|
}
|
|
81
187
|
return { ...e[0] };
|
|
82
|
-
},
|
|
188
|
+
}, gt = Object.freeze({
|
|
83
189
|
top: "left",
|
|
84
190
|
bottom: "right",
|
|
85
191
|
left: "top",
|
|
86
192
|
right: "bottom"
|
|
87
|
-
},
|
|
193
|
+
}), nt = (e) => ({
|
|
88
194
|
x: e.y,
|
|
89
195
|
y: e.x
|
|
90
|
-
}),
|
|
91
|
-
if (!
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
196
|
+
}), kt = (e, t, n, s, o = 20) => {
|
|
197
|
+
if (!it(t))
|
|
198
|
+
return kt(
|
|
199
|
+
nt(e),
|
|
200
|
+
gt[t],
|
|
201
|
+
nt(n),
|
|
202
|
+
gt[s],
|
|
97
203
|
o
|
|
98
|
-
).map(
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
if (s ===
|
|
102
|
-
if ((
|
|
103
|
-
const
|
|
104
|
-
return [e, { x:
|
|
204
|
+
).map(nt);
|
|
205
|
+
const i = B[t], c = B[s], a = q(e, i, o), h = q(n, c, o);
|
|
206
|
+
if (it(s)) {
|
|
207
|
+
if (s === At[t]) {
|
|
208
|
+
if ((h.x - a.x) * i.x >= 0) {
|
|
209
|
+
const k = (e.x + n.x) / 2;
|
|
210
|
+
return [e, { x: k, y: e.y }, { x: k, y: n.y }, n];
|
|
105
211
|
}
|
|
106
|
-
const
|
|
107
|
-
return [e,
|
|
212
|
+
const u = (a.y + h.y) / 2;
|
|
213
|
+
return [e, a, { x: a.x, y: u }, { x: h.x, y: u }, h, n];
|
|
108
214
|
}
|
|
109
|
-
const d =
|
|
215
|
+
const d = i.x > 0 ? Math.max(a.x, h.x) : Math.min(a.x, h.x);
|
|
110
216
|
return [e, { x: d, y: e.y }, { x: d, y: n.y }, n];
|
|
111
217
|
}
|
|
112
|
-
const
|
|
113
|
-
return (
|
|
114
|
-
},
|
|
115
|
-
|
|
116
|
-
|
|
218
|
+
const f = { x: n.x, y: e.y };
|
|
219
|
+
return (f.x - e.x) * i.x > 0 && (f.y - n.y) * c.y > 0 ? [e, f, n] : [e, a, { x: a.x, y: h.y }, h, n];
|
|
220
|
+
}, Vt = (e, t, n, s, { radius: o = 8, offset: i = 20 } = {}) => {
|
|
221
|
+
St(e, t, n, s), A(o, "radius", 0), A(i, "offset", 0);
|
|
222
|
+
const c = Xt(
|
|
223
|
+
kt(e, t, n, s, i)
|
|
117
224
|
);
|
|
118
225
|
return {
|
|
119
|
-
d:
|
|
120
|
-
labelPoint:
|
|
226
|
+
d: Ht(c, o),
|
|
227
|
+
labelPoint: Gt(c)
|
|
121
228
|
};
|
|
122
|
-
},
|
|
123
|
-
const n = document.createElementNS(
|
|
124
|
-
return
|
|
125
|
-
},
|
|
229
|
+
}, Jt = "http://www.w3.org/2000/svg", M = (e, t = {}) => {
|
|
230
|
+
const n = document.createElementNS(Jt, e);
|
|
231
|
+
return $(n, t), n;
|
|
232
|
+
}, $ = (e, t) => {
|
|
126
233
|
for (const [n, s] of Object.entries(t))
|
|
127
234
|
s == null ? e.removeAttribute(n) : e.setAttribute(n, String(s));
|
|
128
|
-
},
|
|
235
|
+
}, Kt = Object.freeze({
|
|
129
236
|
type: "bezier",
|
|
130
237
|
startSide: "auto",
|
|
131
|
-
|
|
238
|
+
endSide: "auto",
|
|
132
239
|
arrow: "none",
|
|
133
240
|
strokeWidth: 2,
|
|
134
241
|
dashed: !1,
|
|
@@ -140,55 +247,69 @@ const q = {
|
|
|
140
247
|
curvature: 1,
|
|
141
248
|
radius: 8,
|
|
142
249
|
offset: 20
|
|
143
|
-
},
|
|
144
|
-
|
|
145
|
-
|
|
250
|
+
}), wt = (e) => Object.fromEntries(
|
|
251
|
+
Object.entries(e).filter(([, t]) => t !== void 0)
|
|
252
|
+
), st = 4;
|
|
253
|
+
var P, X, _, R, H, j, w, E, m, zt, at, ht, Mt, Pt, Tt;
|
|
254
|
+
const pt = class pt {
|
|
146
255
|
constructor(t) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
256
|
+
p(this, m);
|
|
257
|
+
z(this, "id");
|
|
258
|
+
z(this, "startElement");
|
|
259
|
+
z(this, "endElement");
|
|
151
260
|
/**
|
|
152
261
|
* The `<g>` element holding everything this connection draws.
|
|
153
262
|
*/
|
|
154
|
-
|
|
263
|
+
z(this, "element");
|
|
155
264
|
/**
|
|
156
265
|
* The `<path>` element of the line.
|
|
157
266
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
m(this, k, null);
|
|
168
|
-
m(this, b, null);
|
|
169
|
-
m(this, v, null);
|
|
267
|
+
z(this, "path");
|
|
268
|
+
p(this, P, null);
|
|
269
|
+
p(this, X, !1);
|
|
270
|
+
p(this, _);
|
|
271
|
+
p(this, R);
|
|
272
|
+
p(this, H);
|
|
273
|
+
p(this, j, null);
|
|
274
|
+
p(this, w, null);
|
|
275
|
+
p(this, E, null);
|
|
170
276
|
const {
|
|
171
277
|
id: n,
|
|
172
278
|
startElement: s,
|
|
173
|
-
|
|
174
|
-
options:
|
|
279
|
+
endElement: o,
|
|
280
|
+
options: i,
|
|
175
281
|
defaults: c = {},
|
|
176
|
-
owner:
|
|
282
|
+
owner: a
|
|
177
283
|
} = t;
|
|
178
|
-
this.id = n, this.startElement = s, this.
|
|
284
|
+
this.id = n, this.startElement = s, this.endElement = o, l(this, _, a), l(this, R, { ...i }), l(this, H, c), this.element = M("g", { "data-arc-id": n }), this.path = M("path", {
|
|
179
285
|
class: "arc-path",
|
|
180
286
|
fill: "none",
|
|
181
287
|
stroke: "currentColor"
|
|
182
|
-
}), this.element.appendChild(this.path),
|
|
288
|
+
}), this.element.appendChild(this.path), y(this, m, ht).call(this);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Creates a connection for its owner. Options must already be validated.
|
|
292
|
+
*
|
|
293
|
+
* @internal
|
|
294
|
+
*/
|
|
295
|
+
static _create(t) {
|
|
296
|
+
return new pt(t);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The geometry from the last update, or `null` when the connection is
|
|
300
|
+
* hidden because one of its elements is not rendered.
|
|
301
|
+
*/
|
|
302
|
+
get geometry() {
|
|
303
|
+
return r(this, P);
|
|
183
304
|
}
|
|
184
305
|
/**
|
|
185
306
|
* The connection's options merged with the instance defaults.
|
|
186
307
|
*/
|
|
187
308
|
get options() {
|
|
188
309
|
return {
|
|
189
|
-
...
|
|
190
|
-
...
|
|
191
|
-
...
|
|
310
|
+
...Kt,
|
|
311
|
+
...wt(r(this, H)),
|
|
312
|
+
...wt(r(this, R)),
|
|
192
313
|
id: this.id
|
|
193
314
|
};
|
|
194
315
|
}
|
|
@@ -199,21 +320,28 @@ class it {
|
|
|
199
320
|
* ```ts
|
|
200
321
|
* connection.setOptions({ type: 'orthogonal', arrow: 'end' });
|
|
201
322
|
* ```
|
|
323
|
+
* @throws {TypeError} When an option has the wrong type, or `id` is set.
|
|
324
|
+
* @throws {RangeError} When an option is out of range.
|
|
325
|
+
* @throws {ArclaceError} When the connection has been removed.
|
|
202
326
|
*/
|
|
203
327
|
setOptions(t) {
|
|
204
|
-
|
|
328
|
+
if (r(this, X))
|
|
329
|
+
throw new N(`connection "${this.id}" has been removed`);
|
|
330
|
+
if (dt(t), t.id !== void 0)
|
|
331
|
+
throw new TypeError("arclace: setOptions() cannot change the id");
|
|
332
|
+
return l(this, R, { ...r(this, R), ...t }), y(this, m, ht).call(this), r(this, _).update(), this;
|
|
205
333
|
}
|
|
206
334
|
/**
|
|
207
335
|
* Redraws every connection of the owning instance.
|
|
208
336
|
*/
|
|
209
337
|
update() {
|
|
210
|
-
|
|
338
|
+
r(this, _).update();
|
|
211
339
|
}
|
|
212
340
|
/**
|
|
213
341
|
* Removes this connection.
|
|
214
342
|
*/
|
|
215
343
|
remove() {
|
|
216
|
-
|
|
344
|
+
r(this, _).disconnect(this);
|
|
217
345
|
}
|
|
218
346
|
/**
|
|
219
347
|
* Draws the connection between two attachment points.
|
|
@@ -221,11 +349,18 @@ class it {
|
|
|
221
349
|
* @internal
|
|
222
350
|
*/
|
|
223
351
|
_draw(t, n, s, o) {
|
|
224
|
-
const { arrow:
|
|
225
|
-
this
|
|
352
|
+
const { arrow: i, strokeWidth: c } = this.options, a = st * c, h = i === "start" || i === "both" ? y(this, m, at).call(this, t, n, s, a) : t, f = i === "end" || i === "both" ? y(this, m, at).call(this, s, o, t, a) : s, { d, labelPoint: u } = y(this, m, zt).call(this, h, n, f, o);
|
|
353
|
+
l(this, P, Object.freeze({
|
|
354
|
+
start: t,
|
|
355
|
+
end: s,
|
|
356
|
+
startSide: n,
|
|
357
|
+
endSide: o,
|
|
358
|
+
labelPoint: u,
|
|
359
|
+
d
|
|
360
|
+
})), this.element.removeAttribute("display"), $(this.element, {
|
|
226
361
|
"data-start-side": n,
|
|
227
|
-
"data-
|
|
228
|
-
}), this.path.setAttribute("d", d),
|
|
362
|
+
"data-end-side": o
|
|
363
|
+
}), this.path.setAttribute("d", d), r(this, w) && $(r(this, w), { ...u }), r(this, E) && ($(r(this, E)[0], { cx: t.x, cy: t.y }), $(r(this, E)[1], { cx: s.x, cy: s.y }));
|
|
229
364
|
}
|
|
230
365
|
/**
|
|
231
366
|
* Hides the connection.
|
|
@@ -233,7 +368,7 @@ class it {
|
|
|
233
368
|
* @internal
|
|
234
369
|
*/
|
|
235
370
|
_hide() {
|
|
236
|
-
this
|
|
371
|
+
l(this, P, null), this.element.setAttribute("display", "none");
|
|
237
372
|
}
|
|
238
373
|
/**
|
|
239
374
|
* Removes the connection's elements from the overlay.
|
|
@@ -241,93 +376,94 @@ class it {
|
|
|
241
376
|
* @internal
|
|
242
377
|
*/
|
|
243
378
|
_dispose() {
|
|
244
|
-
this.element.remove();
|
|
379
|
+
l(this, X, !0), this.element.remove();
|
|
245
380
|
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const { type:
|
|
249
|
-
return
|
|
250
|
-
radius:
|
|
251
|
-
offset:
|
|
252
|
-
}) :
|
|
253
|
-
},
|
|
254
|
-
const
|
|
255
|
-
return this.options.type !== "straight" ?
|
|
256
|
-
x: t.x + (s.x - t.x) /
|
|
257
|
-
y: t.y + (s.y - t.y) /
|
|
381
|
+
};
|
|
382
|
+
P = new WeakMap(), X = new WeakMap(), _ = new WeakMap(), R = new WeakMap(), H = new WeakMap(), j = new WeakMap(), w = new WeakMap(), E = new WeakMap(), m = new WeakSet(), zt = function(t, n, s, o) {
|
|
383
|
+
const { type: i, curvature: c, radius: a, offset: h } = this.options;
|
|
384
|
+
return i === "straight" ? qt(t, s) : i === "orthogonal" ? Vt(t, n, s, o, {
|
|
385
|
+
radius: a,
|
|
386
|
+
offset: h
|
|
387
|
+
}) : Yt(t, n, s, o, c);
|
|
388
|
+
}, at = function(t, n, s, o) {
|
|
389
|
+
const i = I(t, s), c = Math.min(o, i / 3);
|
|
390
|
+
return this.options.type !== "straight" ? q(t, B[n], c) : i === 0 ? t : {
|
|
391
|
+
x: t.x + (s.x - t.x) / i * c,
|
|
392
|
+
y: t.y + (s.y - t.y) / i * c
|
|
258
393
|
};
|
|
259
|
-
},
|
|
394
|
+
}, ht = function() {
|
|
260
395
|
const {
|
|
261
396
|
type: t,
|
|
262
397
|
arrow: n,
|
|
263
398
|
label: s,
|
|
264
399
|
color: o,
|
|
265
|
-
strokeWidth:
|
|
400
|
+
strokeWidth: i,
|
|
266
401
|
dashed: c,
|
|
267
|
-
animated:
|
|
268
|
-
anchors:
|
|
269
|
-
className:
|
|
402
|
+
animated: a,
|
|
403
|
+
anchors: h,
|
|
404
|
+
className: f
|
|
270
405
|
} = this.options, d = ["arc-connection", `arc-${t}`];
|
|
271
|
-
(c ||
|
|
406
|
+
(c || a) && d.push("arc-dashed"), a && d.push("arc-animated"), f && d.push(...f.split(/\s+/).filter(Boolean)), $(this.element, {
|
|
272
407
|
class: d.join(" "),
|
|
273
408
|
"data-type": t
|
|
274
|
-
}), this.element.style.color = o ?? "",
|
|
275
|
-
"stroke-width":
|
|
276
|
-
"stroke-dasharray": c ||
|
|
277
|
-
}),
|
|
278
|
-
},
|
|
409
|
+
}), this.element.style.color = o ?? "", $(this.path, {
|
|
410
|
+
"stroke-width": i,
|
|
411
|
+
"stroke-dasharray": c || a ? "6 6" : null
|
|
412
|
+
}), y(this, m, Mt).call(this, n), y(this, m, Pt).call(this, s), y(this, m, Tt).call(this, h, i);
|
|
413
|
+
}, Mt = function(t) {
|
|
279
414
|
var s;
|
|
280
415
|
if (t === "none") {
|
|
281
|
-
(s =
|
|
416
|
+
(s = r(this, j)) == null || s.remove(), l(this, j, null), $(this.path, { "marker-start": null, "marker-end": null });
|
|
282
417
|
return;
|
|
283
418
|
}
|
|
284
|
-
|
|
285
|
-
id: `arc-arrow-${
|
|
419
|
+
r(this, j) || (l(this, j, M("marker", {
|
|
420
|
+
id: `arc-arrow-${jt()}`,
|
|
286
421
|
class: "arc-marker",
|
|
287
422
|
viewBox: "0 0 10 10",
|
|
288
423
|
refX: 0,
|
|
289
424
|
refY: 5,
|
|
290
|
-
markerWidth:
|
|
291
|
-
markerHeight:
|
|
425
|
+
markerWidth: st,
|
|
426
|
+
markerHeight: st,
|
|
292
427
|
markerUnits: "strokeWidth",
|
|
293
428
|
orient: "auto-start-reverse"
|
|
294
|
-
})),
|
|
295
|
-
|
|
429
|
+
})), r(this, j).appendChild(
|
|
430
|
+
M("path", {
|
|
296
431
|
d: "M 0 0 L 10 5 L 0 10 z",
|
|
297
432
|
fill: "currentColor"
|
|
298
433
|
})
|
|
299
|
-
), this.element.insertBefore(
|
|
300
|
-
const n = `url(#${
|
|
301
|
-
|
|
434
|
+
), this.element.insertBefore(r(this, j), this.path));
|
|
435
|
+
const n = `url(#${r(this, j).id})`;
|
|
436
|
+
$(this.path, {
|
|
302
437
|
"marker-start": t === "start" || t === "both" ? n : null,
|
|
303
438
|
"marker-end": t === "end" || t === "both" ? n : null
|
|
304
439
|
});
|
|
305
|
-
},
|
|
440
|
+
}, Pt = function(t) {
|
|
306
441
|
var n;
|
|
307
442
|
if (!t) {
|
|
308
|
-
(n =
|
|
443
|
+
(n = r(this, w)) == null || n.remove(), l(this, w, null);
|
|
309
444
|
return;
|
|
310
445
|
}
|
|
311
|
-
|
|
446
|
+
r(this, w) || (l(this, w, M("text", {
|
|
312
447
|
class: "arc-label",
|
|
313
448
|
fill: "currentColor",
|
|
314
449
|
"text-anchor": "middle",
|
|
315
450
|
"dominant-baseline": "central"
|
|
316
|
-
})), this.path.after(
|
|
317
|
-
},
|
|
451
|
+
})), this.path.after(r(this, w)), r(this, P) && $(r(this, w), { ...r(this, P).labelPoint })), r(this, w).textContent = t;
|
|
452
|
+
}, Tt = function(t, n) {
|
|
318
453
|
var s;
|
|
319
454
|
if (!t) {
|
|
320
|
-
(s =
|
|
455
|
+
(s = r(this, E)) == null || s.forEach((o) => o.remove()), l(this, E, null);
|
|
321
456
|
return;
|
|
322
457
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
]), this.element.append(...
|
|
327
|
-
(o) =>
|
|
458
|
+
r(this, E) || (l(this, E, [
|
|
459
|
+
M("circle", { class: "arc-anchor arc-anchor-start" }),
|
|
460
|
+
M("circle", { class: "arc-anchor arc-anchor-end" })
|
|
461
|
+
]), this.element.append(...r(this, E))), r(this, E).forEach(
|
|
462
|
+
(o) => $(o, { r: n + 2, fill: "currentColor" })
|
|
328
463
|
);
|
|
329
464
|
};
|
|
330
|
-
|
|
465
|
+
let Q = pt;
|
|
466
|
+
const Qt = (e) => {
|
|
331
467
|
const t = e.getBoundingClientRect(), { clientWidth: n, clientHeight: s } = e;
|
|
332
468
|
return {
|
|
333
469
|
left: t.left,
|
|
@@ -335,85 +471,101 @@ const Pt = (e) => {
|
|
|
335
471
|
scaleX: n > 0 && t.width > 0 ? t.width / n : 1,
|
|
336
472
|
scaleY: s > 0 && t.height > 0 ? t.height / s : 1
|
|
337
473
|
};
|
|
338
|
-
},
|
|
339
|
-
const n = e.getBoundingClientRect(), s = (n.left - t.left) / t.scaleX, o = (n.top - t.top) / t.scaleY,
|
|
474
|
+
}, Et = (e, t) => {
|
|
475
|
+
const n = e.getBoundingClientRect(), s = (n.left - t.left) / t.scaleX, o = (n.top - t.top) / t.scaleY, i = n.width / t.scaleX, c = n.height / t.scaleY;
|
|
340
476
|
return {
|
|
341
477
|
left: s,
|
|
342
478
|
top: o,
|
|
343
|
-
width:
|
|
479
|
+
width: i,
|
|
344
480
|
height: c,
|
|
345
|
-
right: s +
|
|
481
|
+
right: s + i,
|
|
346
482
|
bottom: o + c
|
|
347
483
|
};
|
|
348
|
-
},
|
|
484
|
+
}, Ot = (e) => e.isConnected && e.getClientRects().length > 0, Ct = (e, t = "element") => {
|
|
485
|
+
try {
|
|
486
|
+
return document.querySelector(e);
|
|
487
|
+
} catch (n) {
|
|
488
|
+
throw new N(`${t} "${e}" is not a valid selector`, {
|
|
489
|
+
cause: n
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}, V = (e, t = "element") => {
|
|
349
493
|
if (typeof e == "string") {
|
|
350
|
-
const n =
|
|
351
|
-
if (!n) throw
|
|
494
|
+
const n = Ct(e, t);
|
|
495
|
+
if (!n) throw new N(`no ${t} matches "${e}"`);
|
|
352
496
|
return n;
|
|
353
497
|
}
|
|
354
498
|
if (!(e instanceof Element))
|
|
355
|
-
throw
|
|
499
|
+
throw new TypeError(
|
|
500
|
+
`arclace: ${t} must be an Element or a selector string`
|
|
501
|
+
);
|
|
356
502
|
return e;
|
|
357
|
-
},
|
|
358
|
-
const n =
|
|
359
|
-
return (c ===
|
|
360
|
-
},
|
|
361
|
-
startSide: n === "auto" ?
|
|
362
|
-
|
|
363
|
-
}),
|
|
503
|
+
}, $t = (e, t) => {
|
|
504
|
+
const n = J(e), s = J(t), o = s.x - n.x, i = s.y - n.y, c = Math.max(t.left - e.right, e.left - t.right), a = Math.max(t.top - e.bottom, e.top - t.bottom);
|
|
505
|
+
return (c === a ? Math.abs(o) >= Math.abs(i) : c > a) ? o >= 0 ? "right" : "left" : i >= 0 ? "bottom" : "top";
|
|
506
|
+
}, Zt = (e, t, n = "auto", s = "auto") => ({
|
|
507
|
+
startSide: n === "auto" ? $t(e, t) : n,
|
|
508
|
+
endSide: s === "auto" ? At[$t(e, t)] : s
|
|
509
|
+
}), vt = (e, t, {
|
|
364
510
|
index: n = 0,
|
|
365
511
|
count: s = 1,
|
|
366
512
|
spacing: o = 16,
|
|
367
|
-
gap:
|
|
513
|
+
gap: i = 0
|
|
368
514
|
} = {}) => {
|
|
369
|
-
const c = t === "top" || t === "bottom" ? e.width : e.height,
|
|
370
|
-
let
|
|
515
|
+
const c = t === "top" || t === "bottom" ? e.width : e.height, a = s > 1 ? Math.min(o, c / s) : 0, h = (n - (s - 1) / 2) * a, { x: f, y: d } = J(e);
|
|
516
|
+
let u;
|
|
371
517
|
switch (t) {
|
|
372
518
|
case "top":
|
|
373
|
-
|
|
519
|
+
u = { x: f + h, y: e.top };
|
|
374
520
|
break;
|
|
375
521
|
case "bottom":
|
|
376
|
-
|
|
522
|
+
u = { x: f + h, y: e.bottom };
|
|
377
523
|
break;
|
|
378
524
|
case "left":
|
|
379
|
-
|
|
525
|
+
u = { x: e.left, y: d + h };
|
|
380
526
|
break;
|
|
381
527
|
case "right":
|
|
382
|
-
|
|
528
|
+
u = { x: e.right, y: d + h };
|
|
383
529
|
break;
|
|
384
530
|
}
|
|
385
|
-
return
|
|
386
|
-
},
|
|
531
|
+
return q(u, B[t], i);
|
|
532
|
+
}, ot = (e) => typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : setTimeout(e, 16), rt = (e) => {
|
|
387
533
|
typeof cancelAnimationFrame == "function" ? cancelAnimationFrame(e) : clearTimeout(e);
|
|
388
534
|
};
|
|
389
|
-
var
|
|
390
|
-
class
|
|
535
|
+
var W, b, v, L, T, x, D, U, g, lt, ut, ft, S, Nt;
|
|
536
|
+
class te {
|
|
537
|
+
/**
|
|
538
|
+
* @throws {TypeError} When an option has the wrong type.
|
|
539
|
+
* @throws {RangeError} When an option is out of range.
|
|
540
|
+
* @throws {ArclaceError} When there is no DOM, or the container can't be
|
|
541
|
+
* found.
|
|
542
|
+
*/
|
|
391
543
|
constructor(t = {}) {
|
|
392
|
-
|
|
544
|
+
p(this, g);
|
|
393
545
|
/**
|
|
394
546
|
* The element the overlay was added to.
|
|
395
547
|
*/
|
|
396
|
-
|
|
548
|
+
z(this, "container");
|
|
397
549
|
/**
|
|
398
550
|
* The SVG overlay all lines are drawn in.
|
|
399
551
|
*/
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
552
|
+
z(this, "svg");
|
|
553
|
+
p(this, W);
|
|
554
|
+
p(this, b, /* @__PURE__ */ new Map());
|
|
555
|
+
p(this, v, 0);
|
|
556
|
+
p(this, L, 0);
|
|
557
|
+
p(this, T, !1);
|
|
558
|
+
p(this, x, null);
|
|
559
|
+
p(this, D, null);
|
|
560
|
+
p(this, U, null);
|
|
561
|
+
p(this, S, () => {
|
|
562
|
+
r(this, v) || r(this, T) || l(this, v, ot(() => {
|
|
563
|
+
l(this, v, 0), this.update();
|
|
412
564
|
}));
|
|
413
565
|
});
|
|
414
566
|
if (typeof document > "u")
|
|
415
|
-
throw
|
|
416
|
-
|
|
567
|
+
throw new N("a DOM is required");
|
|
568
|
+
l(this, W, Wt(t)), this.container = t.container ? V(t.container, "container") : document.body, this.container !== document.body && getComputedStyle(this.container).position === "static" && (l(this, U, this.container.style.position), this.container.style.position = "relative"), this.svg = M("svg", {
|
|
417
569
|
class: ["arc-svg", t.className].filter(Boolean).join(" "),
|
|
418
570
|
"aria-hidden": "true"
|
|
419
571
|
}), Object.assign(this.svg.style, {
|
|
@@ -424,68 +576,95 @@ class _t {
|
|
|
424
576
|
height: "100%",
|
|
425
577
|
overflow: "visible",
|
|
426
578
|
pointerEvents: "none"
|
|
427
|
-
}), this.container.prepend(this.svg),
|
|
579
|
+
}), this.container.prepend(this.svg), y(this, g, Nt).call(this);
|
|
428
580
|
}
|
|
429
581
|
/**
|
|
430
582
|
* All current connections, in the order they were made.
|
|
431
583
|
*/
|
|
432
584
|
get connections() {
|
|
433
|
-
return [...
|
|
585
|
+
return [...r(this, b).values()];
|
|
434
586
|
}
|
|
435
587
|
/**
|
|
436
588
|
* Connects two elements and draws the line right away.
|
|
437
589
|
*
|
|
438
590
|
* @param startElement - The element (or selector) the line starts at.
|
|
439
|
-
* @param
|
|
591
|
+
* @param endElement - The element (or selector) the line ends at.
|
|
440
592
|
* @param options - Options for this connection, merged over the instance defaults.
|
|
441
|
-
* @throws {
|
|
593
|
+
* @throws {TypeError} When an element or an option has the wrong type.
|
|
594
|
+
* @throws {RangeError} When an option is out of range.
|
|
595
|
+
* @throws {ArclaceError} When an element can't be found, the id is taken
|
|
596
|
+
* or the instance has been destroyed. Nothing is added.
|
|
442
597
|
* @example
|
|
443
598
|
* ```ts
|
|
444
599
|
* const connection = arclace.connect(a, b, { type: 'orthogonal', arrow: 'end' });
|
|
445
600
|
* ```
|
|
446
601
|
*/
|
|
447
602
|
connect(t, n, s = {}) {
|
|
448
|
-
const o =
|
|
603
|
+
const o = y(this, g, ut).call(this, y(this, g, lt).call(this, t, n, s, "options"));
|
|
449
604
|
return this.update(), o;
|
|
450
605
|
}
|
|
451
606
|
/**
|
|
452
|
-
* Connects many pairs of elements and draws them in one go.
|
|
607
|
+
* Connects many pairs of elements and draws them in one go. Every
|
|
608
|
+
* definition is checked first, so either all of them are added or none.
|
|
453
609
|
*
|
|
610
|
+
* @throws {TypeError} When `definitions` isn't an array, or an element or
|
|
611
|
+
* an option has the wrong type.
|
|
612
|
+
* @throws {RangeError} When an option is out of range.
|
|
613
|
+
* @throws {ArclaceError} When an element can't be found, an id is taken or
|
|
614
|
+
* repeated, or the instance has been destroyed.
|
|
454
615
|
* @example
|
|
455
616
|
* ```ts
|
|
456
617
|
* arclace.connectAll([
|
|
457
|
-
* { startElement: '#a',
|
|
458
|
-
* { startElement: '#a',
|
|
618
|
+
* { startElement: '#a', endElement: '#b' },
|
|
619
|
+
* { startElement: '#a', endElement: '#c', dashed: true }
|
|
459
620
|
* ]);
|
|
460
621
|
* ```
|
|
461
622
|
*/
|
|
462
623
|
connectAll(t) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
624
|
+
if (!Array.isArray(t))
|
|
625
|
+
throw new TypeError(
|
|
626
|
+
"arclace: connectAll() needs an array of definitions"
|
|
627
|
+
);
|
|
628
|
+
const n = /* @__PURE__ */ new Set(), o = t.map((i, c) => {
|
|
629
|
+
const a = `definitions[${c}]`;
|
|
630
|
+
Z(i, a);
|
|
631
|
+
const { startElement: h, endElement: f, ...d } = i, u = y(this, g, lt).call(this, h, f, d, a);
|
|
632
|
+
if (n.has(u.id))
|
|
633
|
+
throw new N(
|
|
634
|
+
`${a}.id "${u.id}" is used more than once`
|
|
635
|
+
);
|
|
636
|
+
return n.add(u.id), u;
|
|
637
|
+
}).map((i) => y(this, g, ut).call(this, i));
|
|
638
|
+
return this.update(), o;
|
|
467
639
|
}
|
|
468
640
|
/**
|
|
469
641
|
* Returns the connection with the given id.
|
|
470
642
|
*/
|
|
471
643
|
get(t) {
|
|
472
|
-
return
|
|
644
|
+
return r(this, b).get(t);
|
|
473
645
|
}
|
|
474
646
|
/**
|
|
475
|
-
* Returns every connection that starts or
|
|
647
|
+
* Returns every connection that starts or ends at an element. A selector
|
|
648
|
+
* that matches nothing returns an empty array.
|
|
649
|
+
*
|
|
650
|
+
* @throws {TypeError} When the target is neither an element nor a string.
|
|
651
|
+
* @throws {ArclaceError} When the selector is invalid.
|
|
476
652
|
*/
|
|
477
653
|
find(t) {
|
|
478
|
-
const n =
|
|
479
|
-
return this.connections.filter(
|
|
480
|
-
(s) => s.startElement === n || s.
|
|
481
|
-
);
|
|
654
|
+
const n = typeof t == "string" ? Ct(t) : V(t);
|
|
655
|
+
return n ? this.connections.filter(
|
|
656
|
+
(s) => s.startElement === n || s.endElement === n
|
|
657
|
+
) : [];
|
|
482
658
|
}
|
|
483
659
|
/**
|
|
484
660
|
* Removes connections.
|
|
485
661
|
*
|
|
486
662
|
* @param target - A connection, a connection id, or an element (or
|
|
487
663
|
* selector) whose connections should all be removed. Targets that match
|
|
488
|
-
* nothing are ignored.
|
|
664
|
+
* nothing, and `null` or `undefined`, are ignored.
|
|
665
|
+
* @throws {TypeError} When the target is another kind of value.
|
|
666
|
+
* @throws {ArclaceError} When a string is neither an id nor a valid
|
|
667
|
+
* selector.
|
|
489
668
|
* @example
|
|
490
669
|
* ```ts
|
|
491
670
|
* arclace.disconnect(connection);
|
|
@@ -494,29 +673,31 @@ class _t {
|
|
|
494
673
|
* ```
|
|
495
674
|
*/
|
|
496
675
|
disconnect(t) {
|
|
497
|
-
let n
|
|
498
|
-
if (t
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
676
|
+
let n;
|
|
677
|
+
if (t != null) {
|
|
678
|
+
if (t instanceof Q)
|
|
679
|
+
n = [t];
|
|
680
|
+
else if (typeof t == "string" && r(this, b).has(t))
|
|
681
|
+
n = [r(this, b).get(t)];
|
|
682
|
+
else if (typeof t == "string" || t instanceof Element)
|
|
683
|
+
n = this.find(t);
|
|
684
|
+
else
|
|
685
|
+
throw new TypeError(
|
|
686
|
+
"arclace: disconnect() needs a connection, an id, an element or a selector"
|
|
687
|
+
);
|
|
688
|
+
for (const s of n)
|
|
689
|
+
r(this, b).get(s.id) === s && (r(this, b).delete(s.id), s._dispose(), y(this, g, ft).call(this, s.startElement), y(this, g, ft).call(this, s.endElement));
|
|
690
|
+
n.length > 0 && this.update();
|
|
507
691
|
}
|
|
508
|
-
for (const s of n)
|
|
509
|
-
i(this, x).get(s.id) === s && (i(this, x).delete(s.id), s._dispose(), p(this, $, K).call(this, s.startElement), p(this, $, K).call(this, s.stopElement));
|
|
510
|
-
n.length > 0 && this.update();
|
|
511
692
|
}
|
|
512
693
|
/**
|
|
513
694
|
* Removes every connection.
|
|
514
695
|
*/
|
|
515
696
|
clear() {
|
|
516
697
|
var t;
|
|
517
|
-
for (const n of
|
|
698
|
+
for (const n of r(this, b).values())
|
|
518
699
|
n._dispose();
|
|
519
|
-
|
|
700
|
+
r(this, b).clear(), (t = r(this, x)) == null || t.disconnect(), r(this, x) && r(this, x).observe(this.container);
|
|
520
701
|
}
|
|
521
702
|
/**
|
|
522
703
|
* Remeasures every element and redraws every connection. Called
|
|
@@ -524,46 +705,46 @@ class _t {
|
|
|
524
705
|
* elements in ways the page can't observe.
|
|
525
706
|
*/
|
|
526
707
|
update() {
|
|
527
|
-
if (
|
|
528
|
-
|
|
529
|
-
const t =
|
|
530
|
-
const
|
|
531
|
-
return s.has(
|
|
532
|
-
slot:
|
|
533
|
-
key:
|
|
534
|
-
}),
|
|
708
|
+
if (r(this, T)) return;
|
|
709
|
+
r(this, v) && (rt(r(this, v)), l(this, v, 0));
|
|
710
|
+
const t = Qt(this.svg), n = [], s = /* @__PURE__ */ new Map(), o = (i, c, a) => {
|
|
711
|
+
const h = { index: 0, count: 1 }, f = J(a);
|
|
712
|
+
return s.has(i) || s.set(i, { top: [], right: [], bottom: [], left: [] }), s.get(i)[c].push({
|
|
713
|
+
slot: h,
|
|
714
|
+
key: it(c) ? f.y : f.x
|
|
715
|
+
}), h;
|
|
535
716
|
};
|
|
536
|
-
for (const
|
|
537
|
-
const { startElement: c,
|
|
538
|
-
if (!
|
|
539
|
-
|
|
717
|
+
for (const i of r(this, b).values()) {
|
|
718
|
+
const { startElement: c, endElement: a } = i;
|
|
719
|
+
if (!Ot(c) || !Ot(a)) {
|
|
720
|
+
i._hide();
|
|
540
721
|
continue;
|
|
541
722
|
}
|
|
542
|
-
const { spread:
|
|
723
|
+
const { spread: h, startSide: f, endSide: d } = i.options, u = Et(c, t), k = Et(a, t), tt = Zt(u, k, f, d), yt = { index: 0, count: 1 };
|
|
543
724
|
n.push({
|
|
544
|
-
connection:
|
|
545
|
-
startRect:
|
|
546
|
-
|
|
547
|
-
...
|
|
548
|
-
startSlot:
|
|
549
|
-
|
|
725
|
+
connection: i,
|
|
726
|
+
startRect: u,
|
|
727
|
+
endRect: k,
|
|
728
|
+
...tt,
|
|
729
|
+
startSlot: h ? o(c, tt.startSide, k) : yt,
|
|
730
|
+
endSlot: h ? o(a, tt.endSide, u) : { ...yt }
|
|
550
731
|
});
|
|
551
732
|
}
|
|
552
|
-
for (const
|
|
553
|
-
for (const c of Object.values(
|
|
554
|
-
c.sort((
|
|
555
|
-
|
|
733
|
+
for (const i of s.values())
|
|
734
|
+
for (const c of Object.values(i))
|
|
735
|
+
c.sort((a, h) => a.key - h.key).forEach((a, h) => {
|
|
736
|
+
a.slot.index = h, a.slot.count = c.length;
|
|
556
737
|
});
|
|
557
|
-
for (const
|
|
558
|
-
const { connection: c, startRect:
|
|
738
|
+
for (const i of n) {
|
|
739
|
+
const { connection: c, startRect: a, endRect: h, startSide: f, endSide: d } = i, { spacing: u, gap: k } = c.options;
|
|
559
740
|
c._draw(
|
|
560
|
-
|
|
561
|
-
...
|
|
562
|
-
spacing:
|
|
563
|
-
gap:
|
|
741
|
+
vt(a, f, {
|
|
742
|
+
...i.startSlot,
|
|
743
|
+
spacing: u,
|
|
744
|
+
gap: k
|
|
564
745
|
}),
|
|
565
|
-
|
|
566
|
-
|
|
746
|
+
f,
|
|
747
|
+
vt(h, d, { ...i.endSlot, spacing: u, gap: k }),
|
|
567
748
|
d
|
|
568
749
|
);
|
|
569
750
|
}
|
|
@@ -574,67 +755,85 @@ class _t {
|
|
|
574
755
|
*/
|
|
575
756
|
destroy() {
|
|
576
757
|
var t, n;
|
|
577
|
-
|
|
758
|
+
r(this, T) || (this.clear(), l(this, T, !0), r(this, v) && rt(r(this, v)), r(this, L) && rt(r(this, L)), window.removeEventListener("resize", r(this, S)), document.removeEventListener("scroll", r(this, S), {
|
|
578
759
|
capture: !0
|
|
579
|
-
}), (t =
|
|
760
|
+
}), (t = r(this, x)) == null || t.disconnect(), (n = r(this, D)) == null || n.disconnect(), this.svg.remove(), r(this, U) !== null && (this.container.style.position = r(this, U)));
|
|
580
761
|
}
|
|
581
762
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
if (
|
|
588
|
-
throw
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
763
|
+
W = new WeakMap(), b = new WeakMap(), v = new WeakMap(), L = new WeakMap(), T = new WeakMap(), x = new WeakMap(), D = new WeakMap(), U = new WeakMap(), g = new WeakSet(), /**
|
|
764
|
+
* Checks a connection without adding anything, so a bad option can't leave
|
|
765
|
+
* a connection behind that breaks every later update.
|
|
766
|
+
*/
|
|
767
|
+
lt = function(t, n, s, o) {
|
|
768
|
+
if (r(this, T))
|
|
769
|
+
throw new N("this instance has been destroyed");
|
|
770
|
+
dt(s, o);
|
|
771
|
+
const i = V(t, "startElement"), c = V(n, "endElement"), a = s, h = a.id ?? `arc-${jt()}`;
|
|
772
|
+
if (r(this, b).has(h))
|
|
773
|
+
throw new N(`a connection with id "${h}" exists`);
|
|
774
|
+
return { id: h, startElement: i, endElement: c, options: a };
|
|
775
|
+
}, ut = function({
|
|
776
|
+
id: t,
|
|
777
|
+
startElement: n,
|
|
778
|
+
endElement: s,
|
|
779
|
+
options: o
|
|
780
|
+
}) {
|
|
781
|
+
var c, a;
|
|
782
|
+
const i = Q._create({
|
|
783
|
+
id: t,
|
|
784
|
+
startElement: n,
|
|
785
|
+
endElement: s,
|
|
786
|
+
options: o,
|
|
787
|
+
defaults: r(this, W).defaults,
|
|
595
788
|
owner: this
|
|
596
789
|
});
|
|
597
|
-
return
|
|
598
|
-
},
|
|
599
|
-
if (!
|
|
790
|
+
return r(this, b).set(t, i), this.svg.appendChild(i.element), (c = r(this, x)) == null || c.observe(n), (a = r(this, x)) == null || a.observe(s), i;
|
|
791
|
+
}, ft = function(t) {
|
|
792
|
+
if (!r(this, x) || t === this.container) return;
|
|
600
793
|
this.connections.some(
|
|
601
|
-
(s) => s.startElement === t || s.
|
|
602
|
-
) ||
|
|
603
|
-
},
|
|
794
|
+
(s) => s.startElement === t || s.endElement === t
|
|
795
|
+
) || r(this, x).unobserve(t);
|
|
796
|
+
}, S = new WeakMap(), Nt = function() {
|
|
604
797
|
var n;
|
|
605
|
-
const { autoUpdate: t = !0 } =
|
|
798
|
+
const { autoUpdate: t = !0 } = r(this, W);
|
|
606
799
|
if (t !== !1) {
|
|
607
800
|
if (t === "frame") {
|
|
608
801
|
const s = () => {
|
|
609
|
-
this.update(),
|
|
802
|
+
this.update(), l(this, L, ot(s));
|
|
610
803
|
};
|
|
611
|
-
|
|
804
|
+
l(this, L, ot(s));
|
|
612
805
|
return;
|
|
613
806
|
}
|
|
614
|
-
window.addEventListener("resize",
|
|
807
|
+
window.addEventListener("resize", r(this, S)), document.addEventListener("scroll", r(this, S), {
|
|
615
808
|
capture: !0,
|
|
616
809
|
passive: !0
|
|
617
|
-
}), typeof ResizeObserver < "u" && (
|
|
618
|
-
s.some((o) => !this.svg.contains(o.target)) &&
|
|
619
|
-
})),
|
|
810
|
+
}), typeof ResizeObserver < "u" && (l(this, x, new ResizeObserver(r(this, S))), r(this, x).observe(this.container)), typeof MutationObserver < "u" && (l(this, D, new MutationObserver((s) => {
|
|
811
|
+
s.some((o) => !this.svg.contains(o.target)) && r(this, S).call(this);
|
|
812
|
+
})), r(this, D).observe(this.container, {
|
|
620
813
|
subtree: !0,
|
|
621
814
|
childList: !0,
|
|
622
815
|
attributes: !0,
|
|
623
816
|
attributeFilter: ["style", "class", "hidden"]
|
|
624
|
-
})), (n = document.fonts) == null || n.ready.then(
|
|
817
|
+
})), (n = document.fonts) == null || n.ready.then(r(this, S));
|
|
625
818
|
}
|
|
626
819
|
};
|
|
627
|
-
const
|
|
628
|
-
const n = new
|
|
629
|
-
|
|
820
|
+
const ne = (e, t) => {
|
|
821
|
+
const n = new te(t);
|
|
822
|
+
try {
|
|
823
|
+
n.connectAll(e);
|
|
824
|
+
} catch (s) {
|
|
825
|
+
throw n.destroy(), s;
|
|
826
|
+
}
|
|
827
|
+
return n;
|
|
630
828
|
};
|
|
631
829
|
export {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
830
|
+
te as Arclace,
|
|
831
|
+
N as ArclaceError,
|
|
832
|
+
Q as Connection,
|
|
833
|
+
Kt as DEFAULT_CONNECTION_OPTIONS,
|
|
834
|
+
Yt as bezierPath,
|
|
835
|
+
ne as createConnections,
|
|
836
|
+
Vt as orthogonalPath,
|
|
837
|
+
qt as straightPath
|
|
639
838
|
};
|
|
640
839
|
//# sourceMappingURL=arclace.js.map
|