@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/dist/arclace.js CHANGED
@@ -1,72 +1,178 @@
1
- var xt = Object.defineProperty;
2
- var et = (e) => {
1
+ var _t = Object.defineProperty;
2
+ var mt = (e) => {
3
3
  throw TypeError(e);
4
4
  };
5
- var gt = (e, t, n) => t in e ? xt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
6
- var S = (e, t, n) => gt(e, typeof t != "symbol" ? t + "" : t, n), I = (e, t, n) => t.has(e) || et("Cannot " + n);
7
- var i = (e, t, n) => (I(e, t, "read from private field"), n ? n.call(e) : t.get(e)), m = (e, t, n) => t.has(e) ? et("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, n), u = (e, t, n, s) => (I(e, t, "write to private field"), s ? s.call(e, n) : t.set(e, n), n), p = (e, t, n) => (I(e, t, "access private method"), n);
8
- const q = {
9
- top: { x: 0, y: -1 },
10
- right: { x: 1, y: 0 },
11
- bottom: { x: 0, y: 1 },
12
- left: { x: -1, y: 0 }
13
- }, at = {
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
- }, V = (e) => e === "left" || e === "right", U = (e) => ({
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
- }), B = (e, t, n = 1) => ({ x: e.x + t.x * n, y: e.y + t.y * n }), R = (e, t) => Math.hypot(t.x - e.x, t.y - e.y), nt = (e) => Math.round(e * 100) / 100, E = (e) => `${nt(e.x)} ${nt(e.y)}`, lt = () => "_" + Math.random().toString(36).substring(2, 11), bt = (e, t = 1e3) => Math.min(e / t, 1), vt = (e, t, n) => t + (n - t) * e, Et = (e, t = 1.1, n = 3.5, s = 1e3) => vt(bt(e, s), t, n), wt = (e, t) => ({
22
- d: `M ${E(e)} L ${E(t)}`,
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
- }), Mt = (e, t, n, s, o = 1) => {
25
- const r = R(e, n), c = r / Et(r) * o, h = B(e, q[t], c), a = B(n, q[s], c);
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 ${E(e)} C ${E(h)}, ${E(a)}, ${E(n)}`,
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 * h.x + 3 * a.x + n.x) / 8,
31
- y: (e.y + 3 * h.y + 3 * a.y + n.y) / 8
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
- }, kt = (e) => {
140
+ }, Xt = (e) => {
35
141
  const t = e.filter(
36
- (n, s) => s === 0 || R(n, e[s - 1]) > 0.01
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], r = t[s + 1], c = (n.x - o.x) * (r.y - o.y) - (n.y - o.y) * (r.x - o.x);
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
- }, Ot = (e, t) => {
149
+ }, Ht = (e, t) => {
44
150
  if (e.length === 0) return "";
45
- const n = (o, r, c) => {
46
- const h = R(o, r);
151
+ const n = (o, i, c) => {
152
+ const a = I(o, i);
47
153
  return {
48
- x: o.x + (r.x - o.x) / h * c,
49
- y: o.y + (r.y - o.y) / h * c
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 ${E(e[0])}`];
157
+ }, s = [`M ${O(e[0])}`];
52
158
  for (let o = 1; o < e.length - 1; o++) {
53
- const r = e[o - 1], c = e[o], h = e[o + 1], a = Math.min(
159
+ const i = e[o - 1], c = e[o], a = e[o + 1], h = Math.min(
54
160
  t,
55
- R(r, c) / 2,
56
- R(c, h) / 2
161
+ I(i, c) / 2,
162
+ I(c, a) / 2
57
163
  );
58
- if (a <= 0) {
59
- s.push(`L ${E(c)}`);
164
+ if (h <= 0) {
165
+ s.push(`L ${O(c)}`);
60
166
  continue;
61
167
  }
62
168
  s.push(
63
- `L ${E(n(c, r, a))}`,
64
- `Q ${E(c)}, ${E(n(c, h, a))}`
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 ${E(e[e.length - 1])}`), s.join(" ");
68
- }, $t = (e) => {
69
- const t = e.slice(1).map((s, o) => R(e[o], s));
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
- }, st = {
188
+ }, gt = Object.freeze({
83
189
  top: "left",
84
190
  bottom: "right",
85
191
  left: "top",
86
192
  right: "bottom"
87
- }, X = (e) => ({
193
+ }), nt = (e) => ({
88
194
  x: e.y,
89
195
  y: e.x
90
- }), ut = (e, t, n, s, o = 20) => {
91
- if (!V(t))
92
- return ut(
93
- X(e),
94
- st[t],
95
- X(n),
96
- st[s],
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(X);
99
- const r = q[t], c = q[s], h = B(e, r, o), a = B(n, c, o);
100
- if (V(s)) {
101
- if (s === at[t]) {
102
- if ((a.x - h.x) * r.x >= 0) {
103
- const A = (e.x + n.x) / 2;
104
- return [e, { x: A, y: e.y }, { x: A, y: n.y }, n];
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 f = (h.y + a.y) / 2;
107
- return [e, h, { x: h.x, y: f }, { x: a.x, y: f }, a, n];
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 = r.x > 0 ? Math.max(h.x, a.x) : Math.min(h.x, a.x);
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 l = { x: n.x, y: e.y };
113
- return (l.x - e.x) * r.x > 0 && (l.y - n.y) * c.y > 0 ? [e, l, n] : [e, h, { x: h.x, y: a.y }, a, n];
114
- }, At = (e, t, n, s, { radius: o = 8, offset: r = 20 } = {}) => {
115
- const c = kt(
116
- ut(e, t, n, s, r)
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: Ot(c, o),
120
- labelPoint: $t(c)
226
+ d: Ht(c, o),
227
+ labelPoint: Gt(c)
121
228
  };
122
- }, St = "http://www.w3.org/2000/svg", C = (e, t = {}) => {
123
- const n = document.createElementNS(St, e);
124
- return w(n, t), n;
125
- }, w = (e, t) => {
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
- }, Ct = {
235
+ }, Kt = Object.freeze({
129
236
  type: "bezier",
130
237
  startSide: "auto",
131
- stopSide: "auto",
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
- }, Y = 4;
144
- var L, _, D, k, b, v, y, dt, Q, Z, ft, mt, yt;
145
- class it {
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
- m(this, y);
148
- S(this, "id");
149
- S(this, "startElement");
150
- S(this, "stopElement");
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
- S(this, "element");
263
+ z(this, "element");
155
264
  /**
156
265
  * The `<path>` element of the line.
157
266
  */
158
- S(this, "path");
159
- /**
160
- * The geometry from the last update, or `null` when the connection is
161
- * hidden because one of its elements is not rendered.
162
- */
163
- S(this, "geometry", null);
164
- m(this, L);
165
- m(this, _);
166
- m(this, D);
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
- stopElement: o,
174
- options: r,
279
+ endElement: o,
280
+ options: i,
175
281
  defaults: c = {},
176
- owner: h
282
+ owner: a
177
283
  } = t;
178
- this.id = n, this.startElement = s, this.stopElement = o, u(this, L, h), u(this, _, { ...r }), u(this, D, c), this.element = C("g", { "data-arc-id": n }), this.path = C("path", {
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), p(this, y, Z).call(this);
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
- ...Ct,
190
- ...i(this, D),
191
- ...i(this, _),
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
- return u(this, _, { ...i(this, _), ...t }), p(this, y, Z).call(this), i(this, L).update(), this;
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
- i(this, L).update();
338
+ r(this, _).update();
211
339
  }
212
340
  /**
213
341
  * Removes this connection.
214
342
  */
215
343
  remove() {
216
- i(this, L).disconnect(this);
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: r, strokeWidth: c } = this.options, h = Y * c, a = r === "start" || r === "both" ? p(this, y, Q).call(this, t, n, s, h) : t, l = r === "end" || r === "both" ? p(this, y, Q).call(this, s, o, t, h) : s, { d, labelPoint: f } = p(this, y, dt).call(this, a, n, l, o);
225
- this.geometry = { start: t, stop: s, startSide: n, stopSide: o, labelPoint: f, d }, this.element.removeAttribute("display"), w(this.element, {
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-stop-side": o
228
- }), this.path.setAttribute("d", d), i(this, b) && w(i(this, b), { ...f }), i(this, v) && (w(i(this, v)[0], { cx: t.x, cy: t.y }), w(i(this, v)[1], { cx: s.x, cy: s.y }));
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.geometry = null, this.element.setAttribute("display", "none");
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
- L = new WeakMap(), _ = new WeakMap(), D = new WeakMap(), k = new WeakMap(), b = new WeakMap(), v = new WeakMap(), y = new WeakSet(), dt = function(t, n, s, o) {
248
- const { type: r, curvature: c, radius: h, offset: a } = this.options;
249
- return r === "straight" ? wt(t, s) : r === "orthogonal" ? At(t, n, s, o, {
250
- radius: h,
251
- offset: a
252
- }) : Mt(t, n, s, o, c);
253
- }, Q = function(t, n, s, o) {
254
- const r = R(t, s), c = Math.min(o, r / 3);
255
- return this.options.type !== "straight" ? B(t, q[n], c) : r === 0 ? t : {
256
- x: t.x + (s.x - t.x) / r * c,
257
- y: t.y + (s.y - t.y) / r * c
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
- }, Z = function() {
394
+ }, ht = function() {
260
395
  const {
261
396
  type: t,
262
397
  arrow: n,
263
398
  label: s,
264
399
  color: o,
265
- strokeWidth: r,
400
+ strokeWidth: i,
266
401
  dashed: c,
267
- animated: h,
268
- anchors: a,
269
- className: l
402
+ animated: a,
403
+ anchors: h,
404
+ className: f
270
405
  } = this.options, d = ["arc-connection", `arc-${t}`];
271
- (c || h) && d.push("arc-dashed"), h && d.push("arc-animated"), l && d.push(...l.split(/\s+/).filter(Boolean)), w(this.element, {
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 ?? "", w(this.path, {
275
- "stroke-width": r,
276
- "stroke-dasharray": c || h ? "6 6" : null
277
- }), p(this, y, ft).call(this, n), p(this, y, mt).call(this, s), p(this, y, yt).call(this, a, r);
278
- }, ft = function(t) {
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 = i(this, k)) == null || s.remove(), u(this, k, null), w(this.path, { "marker-start": null, "marker-end": null });
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
- i(this, k) || (u(this, k, C("marker", {
285
- id: `arc-arrow-${lt()}`,
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: Y,
291
- markerHeight: Y,
425
+ markerWidth: st,
426
+ markerHeight: st,
292
427
  markerUnits: "strokeWidth",
293
428
  orient: "auto-start-reverse"
294
- })), i(this, k).appendChild(
295
- C("path", {
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(i(this, k), this.path));
300
- const n = `url(#${i(this, k).id})`;
301
- w(this.path, {
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
- }, mt = function(t) {
440
+ }, Pt = function(t) {
306
441
  var n;
307
442
  if (!t) {
308
- (n = i(this, b)) == null || n.remove(), u(this, b, null);
443
+ (n = r(this, w)) == null || n.remove(), l(this, w, null);
309
444
  return;
310
445
  }
311
- i(this, b) || (u(this, b, C("text", {
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(i(this, b)), this.geometry && w(i(this, b), { ...this.geometry.labelPoint })), i(this, b).textContent = t;
317
- }, yt = function(t, n) {
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 = i(this, v)) == null || s.forEach((o) => o.remove()), u(this, v, null);
455
+ (s = r(this, E)) == null || s.forEach((o) => o.remove()), l(this, E, null);
321
456
  return;
322
457
  }
323
- i(this, v) || (u(this, v, [
324
- C("circle", { class: "arc-anchor arc-anchor-start" }),
325
- C("circle", { class: "arc-anchor arc-anchor-stop" })
326
- ]), this.element.append(...i(this, v))), i(this, v).forEach(
327
- (o) => w(o, { r: n + 2, fill: "currentColor" })
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
- const Pt = (e) => {
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
- }, ot = (e, t) => {
339
- const n = e.getBoundingClientRect(), s = (n.left - t.left) / t.scaleX, o = (n.top - t.top) / t.scaleY, r = n.width / t.scaleX, c = n.height / 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: r,
479
+ width: i,
344
480
  height: c,
345
- right: s + r,
481
+ right: s + i,
346
482
  bottom: o + c
347
483
  };
348
- }, rt = (e) => e.isConnected && e.getClientRects().length > 0, T = (e, t = "element") => {
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 = document.querySelector(e);
351
- if (!n) throw Error(`arclace: no ${t} matches "${e}"`);
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 Error(`arclace: ${t} must be an Element or a selector string`);
499
+ throw new TypeError(
500
+ `arclace: ${t} must be an Element or a selector string`
501
+ );
356
502
  return e;
357
- }, ct = (e, t) => {
358
- const n = U(e), s = U(t), o = s.x - n.x, r = s.y - n.y, c = Math.max(t.left - e.right, e.left - t.right), h = Math.max(t.top - e.bottom, e.top - t.bottom);
359
- return (c === h ? Math.abs(o) >= Math.abs(r) : c > h) ? o >= 0 ? "right" : "left" : r >= 0 ? "bottom" : "top";
360
- }, Lt = (e, t, n = "auto", s = "auto") => ({
361
- startSide: n === "auto" ? ct(e, t) : n,
362
- stopSide: s === "auto" ? at[ct(e, t)] : s
363
- }), ht = (e, t, {
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: r = 0
513
+ gap: i = 0
368
514
  } = {}) => {
369
- const c = t === "top" || t === "bottom" ? e.width : e.height, h = s > 1 ? Math.min(o, c / s) : 0, a = (n - (s - 1) / 2) * h, { x: l, y: d } = U(e);
370
- let f;
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
- f = { x: l + a, y: e.top };
519
+ u = { x: f + h, y: e.top };
374
520
  break;
375
521
  case "bottom":
376
- f = { x: l + a, y: e.bottom };
522
+ u = { x: f + h, y: e.bottom };
377
523
  break;
378
524
  case "left":
379
- f = { x: e.left, y: d + a };
525
+ u = { x: e.left, y: d + h };
380
526
  break;
381
527
  case "right":
382
- f = { x: e.right, y: d + a };
528
+ u = { x: e.right, y: d + h };
383
529
  break;
384
530
  }
385
- return B(f, q[t], r);
386
- }, H = (e) => typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : setTimeout(e, 16), G = (e) => {
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 F, x, M, z, P, g, N, W, $, J, K, O, pt;
390
- class _t {
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
- m(this, $);
544
+ p(this, g);
393
545
  /**
394
546
  * The element the overlay was added to.
395
547
  */
396
- S(this, "container");
548
+ z(this, "container");
397
549
  /**
398
550
  * The SVG overlay all lines are drawn in.
399
551
  */
400
- S(this, "svg");
401
- m(this, F);
402
- m(this, x, /* @__PURE__ */ new Map());
403
- m(this, M, 0);
404
- m(this, z, 0);
405
- m(this, P, !1);
406
- m(this, g, null);
407
- m(this, N, null);
408
- m(this, W, null);
409
- m(this, O, () => {
410
- i(this, M) || i(this, P) || u(this, M, H(() => {
411
- u(this, M, 0), this.update();
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 Error("arclace: a DOM is required");
416
- u(this, F, t), this.container = t.container ? T(t.container, "container") : document.body, this.container !== document.body && getComputedStyle(this.container).position === "static" && (u(this, W, this.container.style.position), this.container.style.position = "relative"), this.svg = C("svg", {
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), p(this, $, pt).call(this);
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 [...i(this, x).values()];
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 stopElement - The element (or selector) the line stops at.
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 {Error} When an element can't be found or the id is taken.
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 = p(this, $, J).call(this, t, n, s);
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', stopElement: '#b' },
458
- * { startElement: '#a', stopElement: '#c', dashed: true }
618
+ * { startElement: '#a', endElement: '#b' },
619
+ * { startElement: '#a', endElement: '#c', dashed: true }
459
620
  * ]);
460
621
  * ```
461
622
  */
462
623
  connectAll(t) {
463
- const n = t.map(
464
- ({ startElement: s, stopElement: o, ...r }) => p(this, $, J).call(this, s, o, r)
465
- );
466
- return this.update(), n;
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 i(this, x).get(t);
644
+ return r(this, b).get(t);
473
645
  }
474
646
  /**
475
- * Returns every connection that starts or stops at an element.
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 = T(t);
479
- return this.connections.filter(
480
- (s) => s.startElement === n || s.stopElement === n
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 instanceof it)
499
- n = [t];
500
- else if (typeof t == "string" && i(this, x).has(t))
501
- n = [i(this, x).get(t)];
502
- else if (t instanceof Element)
503
- n = this.find(t);
504
- else {
505
- const s = document.querySelector(t);
506
- s && (n = this.find(s));
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 i(this, x).values())
698
+ for (const n of r(this, b).values())
518
699
  n._dispose();
519
- i(this, x).clear(), (t = i(this, g)) == null || t.disconnect(), i(this, g) && i(this, g).observe(this.container);
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 (i(this, P)) return;
528
- i(this, M) && (G(i(this, M)), u(this, M, 0));
529
- const t = Pt(this.svg), n = [], s = /* @__PURE__ */ new Map(), o = (r, c, h) => {
530
- const a = { index: 0, count: 1 }, l = U(h);
531
- return s.has(r) || s.set(r, { top: [], right: [], bottom: [], left: [] }), s.get(r)[c].push({
532
- slot: a,
533
- key: V(c) ? l.y : l.x
534
- }), a;
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 r of i(this, x).values()) {
537
- const { startElement: c, stopElement: h } = r;
538
- if (!rt(c) || !rt(h)) {
539
- r._hide();
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: a, startSide: l, stopSide: d } = r.options, f = ot(c, t), A = ot(h, t), j = Lt(f, A, l, d), tt = { index: 0, count: 1 };
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: r,
545
- startRect: f,
546
- stopRect: A,
547
- ...j,
548
- startSlot: a ? o(c, j.startSide, A) : tt,
549
- stopSlot: a ? o(h, j.stopSide, f) : { ...tt }
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 r of s.values())
553
- for (const c of Object.values(r))
554
- c.sort((h, a) => h.key - a.key).forEach((h, a) => {
555
- h.slot.index = a, h.slot.count = c.length;
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 r of n) {
558
- const { connection: c, startRect: h, stopRect: a, startSide: l, stopSide: d } = r, { spacing: f, gap: A } = c.options;
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
- ht(h, l, {
561
- ...r.startSlot,
562
- spacing: f,
563
- gap: A
741
+ vt(a, f, {
742
+ ...i.startSlot,
743
+ spacing: u,
744
+ gap: k
564
745
  }),
565
- l,
566
- ht(a, d, { ...r.stopSlot, spacing: f, gap: A }),
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
- i(this, P) || (this.clear(), u(this, P, !0), i(this, M) && G(i(this, M)), i(this, z) && G(i(this, z)), window.removeEventListener("resize", i(this, O)), document.removeEventListener("scroll", i(this, O), {
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 = i(this, g)) == null || t.disconnect(), (n = i(this, N)) == null || n.disconnect(), this.svg.remove(), i(this, W) !== null && (this.container.style.position = i(this, W)));
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
- F = new WeakMap(), x = new WeakMap(), M = new WeakMap(), z = new WeakMap(), P = new WeakMap(), g = new WeakMap(), N = new WeakMap(), W = new WeakMap(), $ = new WeakSet(), J = function(t, n, s) {
583
- var a, l;
584
- if (i(this, P))
585
- throw Error("arclace: this instance has been destroyed");
586
- const o = T(t, "startElement"), r = T(n, "stopElement"), c = s.id ?? `arc-${lt()}`;
587
- if (i(this, x).has(c))
588
- throw Error(`arclace: a connection with id "${c}" exists`);
589
- const h = new it({
590
- id: c,
591
- startElement: o,
592
- stopElement: r,
593
- options: s,
594
- defaults: i(this, F).defaults,
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 i(this, x).set(c, h), this.svg.appendChild(h.element), (a = i(this, g)) == null || a.observe(o), (l = i(this, g)) == null || l.observe(r), h;
598
- }, K = function(t) {
599
- if (!i(this, g) || t === this.container) return;
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.stopElement === t
602
- ) || i(this, g).unobserve(t);
603
- }, O = new WeakMap(), pt = function() {
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 } = i(this, F);
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(), u(this, z, H(s));
802
+ this.update(), l(this, L, ot(s));
610
803
  };
611
- u(this, z, H(s));
804
+ l(this, L, ot(s));
612
805
  return;
613
806
  }
614
- window.addEventListener("resize", i(this, O)), document.addEventListener("scroll", i(this, O), {
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" && (u(this, g, new ResizeObserver(i(this, O))), i(this, g).observe(this.container)), typeof MutationObserver < "u" && (u(this, N, new MutationObserver((s) => {
618
- s.some((o) => !this.svg.contains(o.target)) && i(this, O).call(this);
619
- })), i(this, N).observe(this.container, {
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(i(this, O));
817
+ })), (n = document.fonts) == null || n.ready.then(r(this, S));
625
818
  }
626
819
  };
627
- const Rt = (e, t) => {
628
- const n = new _t(t);
629
- return n.connectAll(e), n;
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
- _t as Arclace,
633
- it as Connection,
634
- Ct as DEFAULT_CONNECTION_OPTIONS,
635
- Mt as bezierPath,
636
- Rt as createConnections,
637
- At as orthogonalPath,
638
- wt as straightPath
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