@phun-ky/arclace 0.0.0-stage → 0.2.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.
@@ -0,0 +1,640 @@
1
+ var xt = Object.defineProperty;
2
+ var et = (e) => {
3
+ throw TypeError(e);
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 = {
14
+ top: "bottom",
15
+ right: "left",
16
+ bottom: "top",
17
+ left: "right"
18
+ }, V = (e) => e === "left" || e === "right", U = (e) => ({
19
+ x: e.left + e.width / 2,
20
+ 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)}`,
23
+ 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);
26
+ return {
27
+ d: `M ${E(e)} C ${E(h)}, ${E(a)}, ${E(n)}`,
28
+ // Point on the curve at t = 0.5
29
+ 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
32
+ }
33
+ };
34
+ }, kt = (e) => {
35
+ const t = e.filter(
36
+ (n, s) => s === 0 || R(n, e[s - 1]) > 0.01
37
+ );
38
+ return t.filter((n, s) => {
39
+ 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);
41
+ return Math.abs(c) > 0.01;
42
+ });
43
+ }, Ot = (e, t) => {
44
+ if (e.length === 0) return "";
45
+ const n = (o, r, c) => {
46
+ const h = R(o, r);
47
+ return {
48
+ x: o.x + (r.x - o.x) / h * c,
49
+ y: o.y + (r.y - o.y) / h * c
50
+ };
51
+ }, s = [`M ${E(e[0])}`];
52
+ 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(
54
+ t,
55
+ R(r, c) / 2,
56
+ R(c, h) / 2
57
+ );
58
+ if (a <= 0) {
59
+ s.push(`L ${E(c)}`);
60
+ continue;
61
+ }
62
+ s.push(
63
+ `L ${E(n(c, r, a))}`,
64
+ `Q ${E(c)}, ${E(n(c, h, a))}`
65
+ );
66
+ }
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));
70
+ let n = t.reduce((s, o) => s + o, 0) / 2;
71
+ for (let s = 0; s < t.length; s++) {
72
+ if (n <= t[s] && t[s] > 0) {
73
+ const o = n / t[s];
74
+ return {
75
+ x: e[s].x + (e[s + 1].x - e[s].x) * o,
76
+ y: e[s].y + (e[s + 1].y - e[s].y) * o
77
+ };
78
+ }
79
+ n -= t[s];
80
+ }
81
+ return { ...e[0] };
82
+ }, st = {
83
+ top: "left",
84
+ bottom: "right",
85
+ left: "top",
86
+ right: "bottom"
87
+ }, X = (e) => ({
88
+ x: e.y,
89
+ 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],
97
+ 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];
105
+ }
106
+ const f = (h.y + a.y) / 2;
107
+ return [e, h, { x: h.x, y: f }, { x: a.x, y: f }, a, n];
108
+ }
109
+ const d = r.x > 0 ? Math.max(h.x, a.x) : Math.min(h.x, a.x);
110
+ return [e, { x: d, y: e.y }, { x: d, y: n.y }, n];
111
+ }
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)
117
+ );
118
+ return {
119
+ d: Ot(c, o),
120
+ labelPoint: $t(c)
121
+ };
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) => {
126
+ for (const [n, s] of Object.entries(t))
127
+ s == null ? e.removeAttribute(n) : e.setAttribute(n, String(s));
128
+ }, Ct = {
129
+ type: "bezier",
130
+ startSide: "auto",
131
+ stopSide: "auto",
132
+ arrow: "none",
133
+ strokeWidth: 2,
134
+ dashed: !1,
135
+ animated: !1,
136
+ anchors: !1,
137
+ gap: 0,
138
+ spread: !0,
139
+ spacing: 16,
140
+ curvature: 1,
141
+ radius: 8,
142
+ offset: 20
143
+ }, Y = 4;
144
+ var L, _, D, k, b, v, y, dt, Q, Z, ft, mt, yt;
145
+ class it {
146
+ constructor(t) {
147
+ m(this, y);
148
+ S(this, "id");
149
+ S(this, "startElement");
150
+ S(this, "stopElement");
151
+ /**
152
+ * The `<g>` element holding everything this connection draws.
153
+ */
154
+ S(this, "element");
155
+ /**
156
+ * The `<path>` element of the line.
157
+ */
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);
170
+ const {
171
+ id: n,
172
+ startElement: s,
173
+ stopElement: o,
174
+ options: r,
175
+ defaults: c = {},
176
+ owner: h
177
+ } = 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", {
179
+ class: "arc-path",
180
+ fill: "none",
181
+ stroke: "currentColor"
182
+ }), this.element.appendChild(this.path), p(this, y, Z).call(this);
183
+ }
184
+ /**
185
+ * The connection's options merged with the instance defaults.
186
+ */
187
+ get options() {
188
+ return {
189
+ ...Ct,
190
+ ...i(this, D),
191
+ ...i(this, _),
192
+ id: this.id
193
+ };
194
+ }
195
+ /**
196
+ * Changes options and redraws.
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * connection.setOptions({ type: 'orthogonal', arrow: 'end' });
201
+ * ```
202
+ */
203
+ setOptions(t) {
204
+ return u(this, _, { ...i(this, _), ...t }), p(this, y, Z).call(this), i(this, L).update(), this;
205
+ }
206
+ /**
207
+ * Redraws every connection of the owning instance.
208
+ */
209
+ update() {
210
+ i(this, L).update();
211
+ }
212
+ /**
213
+ * Removes this connection.
214
+ */
215
+ remove() {
216
+ i(this, L).disconnect(this);
217
+ }
218
+ /**
219
+ * Draws the connection between two attachment points.
220
+ *
221
+ * @internal
222
+ */
223
+ _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, {
226
+ "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 }));
229
+ }
230
+ /**
231
+ * Hides the connection.
232
+ *
233
+ * @internal
234
+ */
235
+ _hide() {
236
+ this.geometry = null, this.element.setAttribute("display", "none");
237
+ }
238
+ /**
239
+ * Removes the connection's elements from the overlay.
240
+ *
241
+ * @internal
242
+ */
243
+ _dispose() {
244
+ this.element.remove();
245
+ }
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
258
+ };
259
+ }, Z = function() {
260
+ const {
261
+ type: t,
262
+ arrow: n,
263
+ label: s,
264
+ color: o,
265
+ strokeWidth: r,
266
+ dashed: c,
267
+ animated: h,
268
+ anchors: a,
269
+ className: l
270
+ } = 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, {
272
+ class: d.join(" "),
273
+ "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) {
279
+ var s;
280
+ if (t === "none") {
281
+ (s = i(this, k)) == null || s.remove(), u(this, k, null), w(this.path, { "marker-start": null, "marker-end": null });
282
+ return;
283
+ }
284
+ i(this, k) || (u(this, k, C("marker", {
285
+ id: `arc-arrow-${lt()}`,
286
+ class: "arc-marker",
287
+ viewBox: "0 0 10 10",
288
+ refX: 0,
289
+ refY: 5,
290
+ markerWidth: Y,
291
+ markerHeight: Y,
292
+ markerUnits: "strokeWidth",
293
+ orient: "auto-start-reverse"
294
+ })), i(this, k).appendChild(
295
+ C("path", {
296
+ d: "M 0 0 L 10 5 L 0 10 z",
297
+ fill: "currentColor"
298
+ })
299
+ ), this.element.insertBefore(i(this, k), this.path));
300
+ const n = `url(#${i(this, k).id})`;
301
+ w(this.path, {
302
+ "marker-start": t === "start" || t === "both" ? n : null,
303
+ "marker-end": t === "end" || t === "both" ? n : null
304
+ });
305
+ }, mt = function(t) {
306
+ var n;
307
+ if (!t) {
308
+ (n = i(this, b)) == null || n.remove(), u(this, b, null);
309
+ return;
310
+ }
311
+ i(this, b) || (u(this, b, C("text", {
312
+ class: "arc-label",
313
+ fill: "currentColor",
314
+ "text-anchor": "middle",
315
+ "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) {
318
+ var s;
319
+ if (!t) {
320
+ (s = i(this, v)) == null || s.forEach((o) => o.remove()), u(this, v, null);
321
+ return;
322
+ }
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" })
328
+ );
329
+ };
330
+ const Pt = (e) => {
331
+ const t = e.getBoundingClientRect(), { clientWidth: n, clientHeight: s } = e;
332
+ return {
333
+ left: t.left,
334
+ top: t.top,
335
+ scaleX: n > 0 && t.width > 0 ? t.width / n : 1,
336
+ scaleY: s > 0 && t.height > 0 ? t.height / s : 1
337
+ };
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;
340
+ return {
341
+ left: s,
342
+ top: o,
343
+ width: r,
344
+ height: c,
345
+ right: s + r,
346
+ bottom: o + c
347
+ };
348
+ }, rt = (e) => e.isConnected && e.getClientRects().length > 0, T = (e, t = "element") => {
349
+ if (typeof e == "string") {
350
+ const n = document.querySelector(e);
351
+ if (!n) throw Error(`arclace: no ${t} matches "${e}"`);
352
+ return n;
353
+ }
354
+ if (!(e instanceof Element))
355
+ throw Error(`arclace: ${t} must be an Element or a selector string`);
356
+ 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, {
364
+ index: n = 0,
365
+ count: s = 1,
366
+ spacing: o = 16,
367
+ gap: r = 0
368
+ } = {}) => {
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;
371
+ switch (t) {
372
+ case "top":
373
+ f = { x: l + a, y: e.top };
374
+ break;
375
+ case "bottom":
376
+ f = { x: l + a, y: e.bottom };
377
+ break;
378
+ case "left":
379
+ f = { x: e.left, y: d + a };
380
+ break;
381
+ case "right":
382
+ f = { x: e.right, y: d + a };
383
+ break;
384
+ }
385
+ return B(f, q[t], r);
386
+ }, H = (e) => typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : setTimeout(e, 16), G = (e) => {
387
+ typeof cancelAnimationFrame == "function" ? cancelAnimationFrame(e) : clearTimeout(e);
388
+ };
389
+ var F, x, M, z, P, g, N, W, $, J, K, O, pt;
390
+ class _t {
391
+ constructor(t = {}) {
392
+ m(this, $);
393
+ /**
394
+ * The element the overlay was added to.
395
+ */
396
+ S(this, "container");
397
+ /**
398
+ * The SVG overlay all lines are drawn in.
399
+ */
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();
412
+ }));
413
+ });
414
+ 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", {
417
+ class: ["arc-svg", t.className].filter(Boolean).join(" "),
418
+ "aria-hidden": "true"
419
+ }), Object.assign(this.svg.style, {
420
+ position: "absolute",
421
+ top: "0",
422
+ left: "0",
423
+ width: "100%",
424
+ height: "100%",
425
+ overflow: "visible",
426
+ pointerEvents: "none"
427
+ }), this.container.prepend(this.svg), p(this, $, pt).call(this);
428
+ }
429
+ /**
430
+ * All current connections, in the order they were made.
431
+ */
432
+ get connections() {
433
+ return [...i(this, x).values()];
434
+ }
435
+ /**
436
+ * Connects two elements and draws the line right away.
437
+ *
438
+ * @param startElement - The element (or selector) the line starts at.
439
+ * @param stopElement - The element (or selector) the line stops at.
440
+ * @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.
442
+ * @example
443
+ * ```ts
444
+ * const connection = arclace.connect(a, b, { type: 'orthogonal', arrow: 'end' });
445
+ * ```
446
+ */
447
+ connect(t, n, s = {}) {
448
+ const o = p(this, $, J).call(this, t, n, s);
449
+ return this.update(), o;
450
+ }
451
+ /**
452
+ * Connects many pairs of elements and draws them in one go.
453
+ *
454
+ * @example
455
+ * ```ts
456
+ * arclace.connectAll([
457
+ * { startElement: '#a', stopElement: '#b' },
458
+ * { startElement: '#a', stopElement: '#c', dashed: true }
459
+ * ]);
460
+ * ```
461
+ */
462
+ 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;
467
+ }
468
+ /**
469
+ * Returns the connection with the given id.
470
+ */
471
+ get(t) {
472
+ return i(this, x).get(t);
473
+ }
474
+ /**
475
+ * Returns every connection that starts or stops at an element.
476
+ */
477
+ find(t) {
478
+ const n = T(t);
479
+ return this.connections.filter(
480
+ (s) => s.startElement === n || s.stopElement === n
481
+ );
482
+ }
483
+ /**
484
+ * Removes connections.
485
+ *
486
+ * @param target - A connection, a connection id, or an element (or
487
+ * selector) whose connections should all be removed. Targets that match
488
+ * nothing are ignored.
489
+ * @example
490
+ * ```ts
491
+ * arclace.disconnect(connection);
492
+ * arclace.disconnect('my-connection-id');
493
+ * arclace.disconnect(document.querySelector('#a'));
494
+ * ```
495
+ */
496
+ 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));
507
+ }
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
+ }
512
+ /**
513
+ * Removes every connection.
514
+ */
515
+ clear() {
516
+ var t;
517
+ for (const n of i(this, x).values())
518
+ n._dispose();
519
+ i(this, x).clear(), (t = i(this, g)) == null || t.disconnect(), i(this, g) && i(this, g).observe(this.container);
520
+ }
521
+ /**
522
+ * Remeasures every element and redraws every connection. Called
523
+ * automatically when `autoUpdate` is on; call it yourself after moving
524
+ * elements in ways the page can't observe.
525
+ */
526
+ 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;
535
+ };
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();
540
+ continue;
541
+ }
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 };
543
+ 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 }
550
+ });
551
+ }
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;
556
+ });
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;
559
+ c._draw(
560
+ ht(h, l, {
561
+ ...r.startSlot,
562
+ spacing: f,
563
+ gap: A
564
+ }),
565
+ l,
566
+ ht(a, d, { ...r.stopSlot, spacing: f, gap: A }),
567
+ d
568
+ );
569
+ }
570
+ }
571
+ /**
572
+ * Removes every connection and the overlay, and stops listening for
573
+ * changes. The instance can't be used afterwards.
574
+ */
575
+ destroy() {
576
+ 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), {
578
+ 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)));
580
+ }
581
+ }
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,
595
+ owner: this
596
+ });
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;
600
+ this.connections.some(
601
+ (s) => s.startElement === t || s.stopElement === t
602
+ ) || i(this, g).unobserve(t);
603
+ }, O = new WeakMap(), pt = function() {
604
+ var n;
605
+ const { autoUpdate: t = !0 } = i(this, F);
606
+ if (t !== !1) {
607
+ if (t === "frame") {
608
+ const s = () => {
609
+ this.update(), u(this, z, H(s));
610
+ };
611
+ u(this, z, H(s));
612
+ return;
613
+ }
614
+ window.addEventListener("resize", i(this, O)), document.addEventListener("scroll", i(this, O), {
615
+ capture: !0,
616
+ 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, {
620
+ subtree: !0,
621
+ childList: !0,
622
+ attributes: !0,
623
+ attributeFilter: ["style", "class", "hidden"]
624
+ })), (n = document.fonts) == null || n.ready.then(i(this, O));
625
+ }
626
+ };
627
+ const Rt = (e, t) => {
628
+ const n = new _t(t);
629
+ return n.connectAll(e), n;
630
+ };
631
+ 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
639
+ };
640
+ //# sourceMappingURL=arclace.js.map