@html-graph/html-graph 0.0.55 → 0.0.57

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/main.js CHANGED
@@ -1,136 +1,19 @@
1
- var j = Object.defineProperty;
2
- var H = (e, t, r) => t in e ? j(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var a = (e, t, r) => H(e, typeof t != "symbol" ? t + "" : t, r);
4
- const U = () => {
5
- const e = document.createElement("div");
6
- return e.style.width = "100%", e.style.height = "100%", e.style.position = "relative", e.style.overflow = "hidden", e;
7
- }, _ = () => {
8
- const e = document.createElement("canvas");
9
- return e.style.position = "absolute", e.style.inset = "0", e;
10
- }, J = () => {
11
- const e = document.createElement("div");
12
- return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.width = "0", e.style.height = "0", e;
13
- };
14
- class K {
15
- constructor(t, r, s, o) {
16
- a(this, "canvasWrapper", null);
17
- a(this, "host", U());
18
- a(this, "canvas", _());
19
- a(this, "container", J());
20
- a(this, "canvasCtx");
21
- a(this, "hostResizeObserver");
22
- a(this, "nodesResizeObserver");
23
- a(this, "nodeElementToIdMap", /* @__PURE__ */ new Map());
24
- a(this, "nodeWrapperElementToIdMap", /* @__PURE__ */ new Map());
25
- a(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
26
- a(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
27
- this.graphStore = t, this.viewportTransformer = r, this.publicViewportTransformer = s, this.backgroundDrawingFn = o;
28
- const i = this.canvas.getContext("2d");
29
- if (i === null)
30
- throw new Error("unable to get canvas context");
31
- this.canvasCtx = i, this.host.appendChild(this.canvas), this.host.appendChild(this.container), this.hostResizeObserver = this.createHostResizeObserver(), this.hostResizeObserver.observe(this.host), this.nodesResizeObserver = this.createNodesResizeObserver();
32
- }
33
- clear() {
34
- Array.from(this.edgeIdToElementMap.keys()).forEach((t) => {
35
- this.detachEdge(t);
36
- }), Array.from(this.nodeElementToIdMap.values()).forEach((t) => {
37
- this.detachNode(t);
38
- });
39
- }
40
- attach(t) {
41
- this.detach(), this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
42
- }
43
- detach() {
44
- this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
45
- }
46
- destroy() {
47
- this.hostResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.container), this.detach();
48
- }
49
- applyTransform() {
50
- this.backgroundDrawingFn(this.canvasCtx, this.publicViewportTransformer);
51
- const t = this.viewportTransformer.getContentMatrix();
52
- this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.dx}, ${t.dy})`;
53
- }
54
- attachNode(t) {
55
- const r = this.graphStore.getNode(t), s = document.createElement("div");
56
- s.appendChild(r.element), s.style.position = "absolute", s.style.top = "0", s.style.left = "0", s.style.visibility = "hidden", this.container.appendChild(s), this.nodeElementToIdMap.set(r.element, t), this.nodeWrapperElementToIdMap.set(s, t), this.nodeIdToWrapperElementMap.set(t, s), this.updateNodeCoords(t), this.updateNodePriority(t), this.nodesResizeObserver.observe(s), s.style.visibility = "visible";
57
- }
58
- detachNode(t) {
59
- const r = this.graphStore.getNode(t);
60
- this.nodesResizeObserver.unobserve(r.element);
61
- const s = this.nodeIdToWrapperElementMap.get(t);
62
- s.removeChild(r.element), this.container.removeChild(s), this.nodeElementToIdMap.delete(r.element), this.nodeWrapperElementToIdMap.delete(s), this.nodeIdToWrapperElementMap.delete(t);
63
- }
64
- attachEdge(t) {
65
- const s = this.graphStore.getEdge(t).shape.svg;
66
- s.style.position = "absolute", s.style.top = "0", s.style.left = "0", this.edgeIdToElementMap.set(t, s), this.updateEdgeCoords(t), this.updateEdgePriority(t), this.container.appendChild(s);
67
- }
68
- detachEdge(t) {
69
- const r = this.edgeIdToElementMap.get(t);
70
- this.edgeIdToElementMap.delete(t), this.container.removeChild(r);
71
- }
72
- updateNodePriority(t) {
73
- const r = this.graphStore.getNode(t), s = this.nodeIdToWrapperElementMap.get(t);
74
- s.style.zIndex = `${r.priority}`;
75
- }
76
- updateEdgePriority(t) {
77
- const r = this.graphStore.getEdge(t);
78
- this.edgeIdToElementMap.get(t).style.zIndex = `${r.priority}`;
79
- }
80
- updateNodeCoordinates(t) {
81
- const r = this.graphStore.getNodeAdjacentEdges(t);
82
- this.updateNodeCoords(t), r.forEach((s) => {
83
- this.updateEdgeCoords(s);
84
- });
85
- }
86
- updatePortEdges(t) {
87
- this.graphStore.getPortAdjacentEdges(t).forEach((s) => {
88
- this.updateEdgeCoords(s);
89
- });
90
- }
91
- createHostResizeObserver() {
92
- return new ResizeObserver(() => {
93
- this.updateCanvasDimensions(), this.applyTransform();
94
- });
95
- }
96
- createNodesResizeObserver() {
97
- return new ResizeObserver((t) => {
98
- t.forEach((r) => {
99
- const s = r.target, o = this.nodeWrapperElementToIdMap.get(s);
100
- this.updateNodeCoords(o), this.graphStore.getNodeAdjacentEdges(o).forEach((n) => {
101
- this.updateEdgeCoords(n);
102
- });
103
- });
104
- });
105
- }
106
- updateCanvasDimensions() {
107
- const { width: t, height: r } = this.host.getBoundingClientRect();
108
- this.canvas.width = t, this.canvas.height = r;
109
- }
110
- updateNodeCoords(t) {
111
- const r = this.nodeIdToWrapperElementMap.get(t), { width: s, height: o } = r.getBoundingClientRect(), i = this.viewportTransformer.getViewportMatrix().scale, n = this.graphStore.getNode(t), { x: c, y: h } = n.centerFn(s, o), l = n.x - i * c, d = n.y - i * h;
112
- r.style.transform = `matrix(1, 0, 0, 1, ${l}, ${d})`;
113
- }
114
- updateEdgeCoords(t) {
115
- const r = this.graphStore.getEdge(t), s = this.graphStore.getPort(r.from), o = this.graphStore.getPort(r.to), i = s.element.getBoundingClientRect(), n = o.element.getBoundingClientRect(), c = this.host.getBoundingClientRect(), h = this.viewportTransformer.getViewportMatrix(), l = h.scale * (i.left - c.left) + h.dx, d = h.scale * (i.top - c.top) + h.dy, u = h.scale * (n.left - c.left) + h.dx, g = h.scale * (n.top - c.top) + h.dy, { x: y, y: w } = s.centerFn(
116
- i.width * h.scale,
117
- i.height * h.scale
118
- ), { x: v, y: m } = o.centerFn(
119
- n.width * h.scale,
120
- n.height * h.scale
121
- ), f = y + l, p = w + d, x = v + u, A = m + g, C = Math.min(f, x), P = Math.min(p, A), T = Math.abs(x - f), L = Math.abs(A - p);
122
- r.shape.update(C, P, T, L, s, o);
123
- }
124
- }
125
- const Y = {
1
+ var tt = Object.defineProperty;
2
+ var et = (e, t, r) => t in e ? tt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var n = (e, t, r) => et(e, typeof t != "symbol" ? t + "" : t, r);
4
+ const K = (e) => ({
5
+ scale: 1 / e.scale,
6
+ dx: -e.dx / e.scale,
7
+ dy: -e.dy / e.scale
8
+ }), J = {
126
9
  scale: 1,
127
10
  dx: 0,
128
11
  dy: 0
129
12
  };
130
- class Q {
13
+ class rt {
131
14
  constructor() {
132
- a(this, "viewportMatrix", Y);
133
- a(this, "contentMatrix", Y);
15
+ n(this, "viewportMatrix", J);
16
+ n(this, "contentMatrix", J);
134
17
  }
135
18
  getViewportMatrix() {
136
19
  return this.viewportMatrix;
@@ -143,24 +26,17 @@ class Q {
143
26
  scale: t ?? this.viewportMatrix.scale,
144
27
  dx: r ?? this.viewportMatrix.dx,
145
28
  dy: s ?? this.viewportMatrix.dy
146
- }, this.contentMatrix = this.calculateReverseMatrix(this.viewportMatrix);
29
+ }, this.contentMatrix = K(this.viewportMatrix);
147
30
  }
148
31
  patchContentMatrix(t, r, s) {
149
32
  this.contentMatrix = {
150
33
  scale: t ?? this.contentMatrix.scale,
151
34
  dx: r ?? this.contentMatrix.dx,
152
35
  dy: s ?? this.contentMatrix.dy
153
- }, this.viewportMatrix = this.calculateReverseMatrix(this.contentMatrix);
154
- }
155
- calculateReverseMatrix(t) {
156
- return {
157
- scale: 1 / t.scale,
158
- dx: -t.dx / t.scale,
159
- dy: -t.dy / t.scale
160
- };
36
+ }, this.viewportMatrix = K(this.contentMatrix);
161
37
  }
162
38
  }
163
- class Z {
39
+ class st {
164
40
  constructor(t) {
165
41
  this.transformer = t;
166
42
  }
@@ -171,58 +47,47 @@ class Z {
171
47
  return { ...this.transformer.getContentMatrix() };
172
48
  }
173
49
  }
174
- class q {
50
+ class ot {
175
51
  constructor() {
176
- a(this, "nodes", /* @__PURE__ */ new Map());
177
- a(this, "ports", /* @__PURE__ */ new Map());
178
- a(this, "nodePorts", /* @__PURE__ */ new Map());
179
- a(this, "portNodeId", /* @__PURE__ */ new Map());
180
- a(this, "edges", /* @__PURE__ */ new Map());
181
- a(this, "incommingEdges", /* @__PURE__ */ new Map());
182
- a(this, "outcommingEdges", /* @__PURE__ */ new Map());
183
- a(this, "cycleEdges", /* @__PURE__ */ new Map());
184
- }
185
- addNode(t, r, s, o, i, n) {
186
- this.nodes.set(t, { element: r, x: s, y: o, centerFn: i, priority: n }), this.nodePorts.set(t, /* @__PURE__ */ new Map());
187
- }
188
- getAllNodes() {
52
+ n(this, "nodes", /* @__PURE__ */ new Map());
53
+ n(this, "ports", /* @__PURE__ */ new Map());
54
+ n(this, "nodePorts", /* @__PURE__ */ new Map());
55
+ n(this, "portNodeId", /* @__PURE__ */ new Map());
56
+ n(this, "edges", /* @__PURE__ */ new Map());
57
+ n(this, "incommingEdges", /* @__PURE__ */ new Map());
58
+ n(this, "outcommingEdges", /* @__PURE__ */ new Map());
59
+ n(this, "cycleEdges", /* @__PURE__ */ new Map());
60
+ }
61
+ addNode(t, r, s, o, i, h) {
62
+ this.nodes.set(t, { element: r, x: s, y: o, centerFn: i, priority: h }), this.nodePorts.set(t, /* @__PURE__ */ new Map());
63
+ }
64
+ getAllNodeIds() {
189
65
  return Array.from(this.nodes.keys());
190
66
  }
191
67
  getNode(t) {
192
68
  return this.nodes.get(t);
193
69
  }
194
- getNodePorts(t) {
195
- const r = this.nodePorts.get(t);
196
- if (r !== void 0)
197
- return Array.from(r.keys());
198
- }
199
70
  removeNode(t) {
200
- this.getNodeAdjacentEdges(t).forEach((o) => {
201
- this.removeEdge(o);
202
- }), this.nodes.delete(t), this.nodePorts.get(t).forEach((o, i) => {
203
- this.portNodeId.delete(i);
204
- }), this.nodePorts.delete(t);
71
+ this.nodes.delete(t), this.nodePorts.delete(t);
205
72
  }
206
73
  addPort(t, r, s, o, i) {
207
74
  this.ports.set(t, { element: r, centerFn: o, direction: i }), this.cycleEdges.set(t, /* @__PURE__ */ new Set()), this.incommingEdges.set(t, /* @__PURE__ */ new Set()), this.outcommingEdges.set(t, /* @__PURE__ */ new Set()), this.portNodeId.set(t, s), this.nodePorts.get(s).set(t, r);
208
75
  }
209
- getAllPorts() {
210
- return Array.from(this.ports.keys());
211
- }
212
76
  getPort(t) {
213
77
  return this.ports.get(t);
214
78
  }
215
- getPortNode(t) {
79
+ getAllPortIds() {
80
+ return Array.from(this.ports.keys());
81
+ }
82
+ getNodePortIds(t) {
83
+ const r = this.nodePorts.get(t);
84
+ if (r !== void 0)
85
+ return Array.from(r.keys());
86
+ }
87
+ getPortNodeId(t) {
216
88
  return this.portNodeId.get(t);
217
89
  }
218
90
  removePort(t) {
219
- this.cycleEdges.get(t).forEach((s) => {
220
- this.removeEdge(s);
221
- }), this.cycleEdges.delete(t), this.incommingEdges.get(t).forEach((s) => {
222
- this.removeEdge(s);
223
- }), this.incommingEdges.delete(t), this.outcommingEdges.get(t).forEach((s) => {
224
- this.removeEdge(s);
225
- }), this.outcommingEdges.get(t);
226
91
  const r = this.portNodeId.get(t);
227
92
  this.portNodeId.delete(t), this.nodePorts.get(r).delete(t), this.ports.delete(t);
228
93
  }
@@ -234,7 +99,7 @@ class q {
234
99
  priority: i
235
100
  }), r !== s ? (this.outcommingEdges.get(r).add(t), this.incommingEdges.get(s).add(t)) : this.cycleEdges.get(r).add(t);
236
101
  }
237
- getAllEdges() {
102
+ getAllEdgeIds() {
238
103
  return Array.from(this.edges.keys());
239
104
  }
240
105
  getEdge(t) {
@@ -244,63 +109,63 @@ class q {
244
109
  const r = this.edges.get(t), s = r.from, o = r.to;
245
110
  this.cycleEdges.get(s).delete(t), this.cycleEdges.get(o).delete(t), this.incommingEdges.get(s).delete(t), this.incommingEdges.get(o).delete(t), this.outcommingEdges.get(s).delete(t), this.outcommingEdges.get(o).delete(t), this.edges.delete(t);
246
111
  }
247
- getPortAdjacentEdges(t) {
248
- return [
249
- ...this.getPortIncomingEdges(t),
250
- ...this.getPortOutcomingEdges(t),
251
- ...this.getPortCycleEdges(t)
252
- ];
253
- }
254
- getNodeAdjacentEdges(t) {
255
- return [
256
- ...this.getNodeIncomingEdges(t),
257
- ...this.getNodeOutcomingEdges(t),
258
- ...this.getNodeCycleEdges(t)
259
- ];
260
- }
261
112
  clear() {
262
113
  this.nodes.clear(), this.ports.clear(), this.nodePorts.clear(), this.portNodeId.clear(), this.edges.clear(), this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear();
263
114
  }
264
- getPortIncomingEdges(t) {
115
+ getPortIncomingEdgeIds(t) {
265
116
  return Array.from(this.incommingEdges.get(t));
266
117
  }
267
- getPortOutcomingEdges(t) {
118
+ getPortOutcomingEdgeIds(t) {
268
119
  return Array.from(this.outcommingEdges.get(t));
269
120
  }
270
- getPortCycleEdges(t) {
121
+ getPortCycleEdgeIds(t) {
271
122
  return Array.from(this.cycleEdges.get(t));
272
123
  }
273
- getNodeIncomingEdges(t) {
124
+ getPortAdjacentEdgeIds(t) {
125
+ return [
126
+ ...this.getPortIncomingEdgeIds(t),
127
+ ...this.getPortOutcomingEdgeIds(t),
128
+ ...this.getPortCycleEdgeIds(t)
129
+ ];
130
+ }
131
+ getNodeIncomingEdgeIds(t) {
274
132
  const r = Array.from(this.nodePorts.get(t).keys());
275
133
  let s = [];
276
134
  return r.forEach((o) => {
277
- s = [...s, ...this.getPortIncomingEdges(o)];
135
+ s = [...s, ...this.getPortIncomingEdgeIds(o)];
278
136
  }), s;
279
137
  }
280
- getNodeOutcomingEdges(t) {
138
+ getNodeOutcomingEdgeIds(t) {
281
139
  const r = Array.from(this.nodePorts.get(t).keys());
282
140
  let s = [];
283
141
  return r.forEach((o) => {
284
- s = [...s, ...this.getPortOutcomingEdges(o)];
142
+ s = [...s, ...this.getPortOutcomingEdgeIds(o)];
285
143
  }), s;
286
144
  }
287
- getNodeCycleEdges(t) {
145
+ getNodeCycleEdgeIds(t) {
288
146
  const r = Array.from(this.nodePorts.get(t).keys());
289
147
  let s = [];
290
148
  return r.forEach((o) => {
291
- s = [...s, ...this.getPortCycleEdges(o)];
149
+ s = [...s, ...this.getPortCycleEdgeIds(o)];
292
150
  }), s;
293
151
  }
152
+ getNodeAdjacentEdgeIds(t) {
153
+ return [
154
+ ...this.getNodeIncomingEdgeIds(t),
155
+ ...this.getNodeOutcomingEdgeIds(t),
156
+ ...this.getNodeCycleEdgeIds(t)
157
+ ];
158
+ }
294
159
  }
295
- class I {
160
+ class it {
296
161
  constructor(t) {
297
162
  this.graphStore = t;
298
163
  }
299
- getAllNodes() {
300
- return this.graphStore.getAllNodes();
164
+ getAllNodeIds() {
165
+ return this.graphStore.getAllNodeIds();
301
166
  }
302
- getAllPorts() {
303
- return this.graphStore.getAllPorts();
167
+ getAllPortIds() {
168
+ return this.graphStore.getAllPortIds();
304
169
  }
305
170
  getNode(t) {
306
171
  const r = this.graphStore.getNode(t);
@@ -312,8 +177,8 @@ class I {
312
177
  priority: r.priority
313
178
  };
314
179
  }
315
- getNodePorts(t) {
316
- return this.graphStore.getNodePorts(t);
180
+ getNodePortIds(t) {
181
+ return this.graphStore.getNodePortIds(t);
317
182
  }
318
183
  getPort(t) {
319
184
  const r = this.graphStore.getPort(t);
@@ -323,217 +188,210 @@ class I {
323
188
  direction: r.direction
324
189
  };
325
190
  }
326
- getPortNode(t) {
327
- return this.graphStore.getPortNode(t) ?? null;
191
+ getPortNodeId(t) {
192
+ return this.graphStore.getPortNodeId(t) ?? null;
328
193
  }
329
- getAllEdges() {
330
- return this.graphStore.getAllEdges();
194
+ getAllEdgeIds() {
195
+ return this.graphStore.getAllEdgeIds();
331
196
  }
332
197
  getEdge(t) {
333
198
  const r = this.graphStore.getEdge(t);
334
199
  return r === void 0 ? null : { from: r.from, to: r.to, priority: r.priority };
335
200
  }
336
- getPortAdjacentEdges(t) {
337
- return this.graphStore.getPortAdjacentEdges(t);
201
+ getPortAdjacentEdgeIds(t) {
202
+ return this.graphStore.getPortAdjacentEdgeIds(t);
338
203
  }
339
- getNodeAdjacentEdges(t) {
340
- return this.graphStore.getNodeAdjacentEdges(t);
204
+ getNodeAdjacentEdgeIds(t) {
205
+ return this.graphStore.getNodeAdjacentEdgeIds(t);
341
206
  }
342
- getPortIncomingEdges(t) {
343
- return this.graphStore.getPortIncomingEdges(t);
207
+ getPortIncomingEdgeIds(t) {
208
+ return this.graphStore.getPortIncomingEdgeIds(t);
344
209
  }
345
- getPortOutcomingEdges(t) {
346
- return this.graphStore.getPortOutcomingEdges(t);
210
+ getPortOutcomingEdgeIds(t) {
211
+ return this.graphStore.getPortOutcomingEdgeIds(t);
347
212
  }
348
- getPortCycleEdges(t) {
349
- return this.graphStore.getPortCycleEdges(t);
213
+ getPortCycleEdgeIds(t) {
214
+ return this.graphStore.getPortCycleEdgeIds(t);
350
215
  }
351
- getNodeIncomingEdges(t) {
352
- return this.graphStore.getNodeIncomingEdges(t);
216
+ getNodeIncomingEdgeIds(t) {
217
+ return this.graphStore.getNodeIncomingEdgeIds(t);
353
218
  }
354
- getNodeOutcomingEdges(t) {
355
- return this.graphStore.getNodeOutcomingEdges(t);
219
+ getNodeOutcomingEdgeIds(t) {
220
+ return this.graphStore.getNodeOutcomingEdgeIds(t);
356
221
  }
357
- getNodeCycleEdges(t) {
358
- return this.graphStore.getNodeCycleEdges(t);
222
+ getNodeCycleEdgeIds(t) {
223
+ return this.graphStore.getNodeCycleEdgeIds(t);
359
224
  }
360
225
  }
361
- const M = (e) => {
226
+ const L = (e) => {
362
227
  const { top: t, left: r, width: s, height: o } = e.element.getBoundingClientRect(), i = e.centerFn(s, o);
363
228
  return { x: r + i.x, y: t + i.y };
364
229
  }, E = (e, t, r) => ({
365
230
  x: t.x * e.x - t.y * e.y + ((1 - t.x) * r.x + t.y * r.y),
366
231
  y: t.y * e.x + t.x * e.y + ((1 - t.x) * r.y - t.y * r.x)
367
- }), S = (e, t, r) => ({ x: t * Math.cos(e), y: r * Math.sin(e) }), N = (e, t, r, s, o) => {
368
- const n = [
232
+ }), P = (e, t, r) => ({ x: t * Math.cos(e), y: r * Math.sin(e) }), N = (e, t, r, s, o) => {
233
+ const h = [
369
234
  { x: 0, y: 0 },
370
235
  { x: s, y: o },
371
236
  { x: s, y: -o }
372
- ].map((d) => E(d, e, { x: 0, y: 0 })).map((d) => ({ x: d.x + t, y: d.y + r })), c = `M ${n[0].x} ${n[0].y}`, h = `L ${n[1].x} ${n[1].y}`, l = `L ${n[2].x} ${n[2].y}`;
373
- return `${c} ${h} ${l}`;
237
+ ].map((l) => E(l, e, { x: 0, y: 0 })).map((l) => ({ x: l.x + t, y: l.y + r })), c = `M ${h[0].x} ${h[0].y}`, a = `L ${h[1].x} ${h[1].y}`, d = `L ${h[2].x} ${h[2].y}`;
238
+ return `${c} ${a} ${d}`;
239
+ }, k = (e, t) => {
240
+ const r = [];
241
+ if (e.length > 0 && r.push(`M ${e[0].x} ${e[0].y}`), e.length === 2 && r.push(`L ${e[1].x} ${e[1].y}`), e.length > 2) {
242
+ const s = e.length - 1;
243
+ let o = 0, i = 0, h = 0;
244
+ e.forEach((c, a) => {
245
+ let d = 0, l = 0, u = 0;
246
+ const w = a > 0, v = a < s, p = w && v;
247
+ if (w && (d = -o, l = -i, u = h), v) {
248
+ const M = e[a + 1];
249
+ o = M.x - c.x, i = M.y - c.y, h = Math.sqrt(o * o + i * i);
250
+ }
251
+ const m = Math.min((p ? t : 0) / h, a < s - 1 ? 0.5 : 1), x = p ? { x: c.x + o * m, y: c.y + i * m } : c, C = Math.min((p ? t : 0) / u, a > 1 ? 0.5 : 1), A = p ? { x: c.x + d * C, y: c.y + l * C } : c;
252
+ a > 0 && r.push(`L ${A.x} ${A.y}`), p && r.push(
253
+ `C ${c.x} ${c.y} ${c.x} ${c.y} ${x.x} ${x.y}`
254
+ );
255
+ });
256
+ }
257
+ return r.join(" ");
258
+ }, V = () => {
259
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "svg");
260
+ return e.style.pointerEvents = "none", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.overflow = "visible", e;
261
+ }, O = () => {
262
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "g");
263
+ return e.style.transformOrigin = "50% 50%", e;
264
+ }, R = (e, t) => {
265
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
266
+ return r.setAttribute("stroke", e), r.setAttribute("stroke-width", `${t}`), r.setAttribute("fill", "none"), r;
267
+ }, b = (e) => {
268
+ const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
269
+ return t.setAttribute("fill", e), t;
374
270
  };
375
- class tt {
376
- constructor(t, r, s, o, i, n, c) {
377
- a(this, "svg");
378
- a(this, "group");
379
- a(this, "line");
380
- a(this, "sourceArrow", null);
381
- a(this, "targetArrow", null);
382
- this.color = t, this.width = r, this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", n && (this.sourceArrow = document.createElementNS(
383
- "http://www.w3.org/2000/svg",
384
- "path"
385
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = document.createElementNS(
386
- "http://www.w3.org/2000/svg",
387
- "path"
388
- ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
389
- }
390
- update(t, r, s, o, i, n) {
271
+ class nt {
272
+ constructor(t, r, s, o, i, h, c) {
273
+ n(this, "svg", V());
274
+ n(this, "group", O());
275
+ n(this, "line");
276
+ n(this, "sourceArrow", null);
277
+ n(this, "targetArrow", null);
278
+ this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.svg.appendChild(this.group), this.line = R(t, r), this.group.appendChild(this.line), h && (this.sourceArrow = b(t), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = b(t), this.group.appendChild(this.targetArrow));
279
+ }
280
+ update(t, r, s, o, i, h) {
391
281
  this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`, this.svg.style.transform = `translate(${t}px, ${r}px)`;
392
- const c = M(i), h = M(n), l = c.x <= h.x ? 1 : -1, d = c.y <= h.y ? 1 : -1;
393
- this.group.style.transform = `scale(${l}, ${d})`;
394
- const u = S(i.direction, l, d), g = S(n.direction, l, d), y = E({ x: this.arrowLength, y: 0 }, u, {
282
+ const c = L(i), a = L(h), d = c.x <= a.x ? 1 : -1, l = c.y <= a.y ? 1 : -1;
283
+ this.group.style.transform = `scale(${d}, ${l})`;
284
+ const u = P(i.direction, d, l), w = P(h.direction, d, l), v = E({ x: this.arrowLength, y: 0 }, u, {
395
285
  x: 0,
396
286
  y: 0
397
- }), w = E(
287
+ }), p = E(
398
288
  { x: s - this.arrowLength, y: o },
399
- g,
289
+ w,
400
290
  {
401
291
  x: s,
402
292
  y: o
403
293
  }
404
- ), v = {
405
- x: y.x + u.x * this.curvature,
406
- y: y.y + u.y * this.curvature
294
+ ), f = {
295
+ x: v.x + u.x * this.curvature,
296
+ y: v.y + u.y * this.curvature
407
297
  }, m = {
408
- x: w.x - g.x * this.curvature,
409
- y: w.y - g.y * this.curvature
410
- }, f = `M ${y.x} ${y.y} C ${v.x} ${v.y}, ${m.x} ${m.y}, ${w.x} ${w.y}`, p = this.sourceArrow ? "" : `M 0 0 L ${y.x} ${y.y} `, x = this.targetArrow ? "" : ` M ${w.x} ${w.y} L ${s} ${o}`, A = `${p}${f}${x}`;
298
+ x: p.x - w.x * this.curvature,
299
+ y: p.y - w.y * this.curvature
300
+ }, x = `M ${v.x} ${v.y} C ${f.x} ${f.y}, ${m.x} ${m.y}, ${p.x} ${p.y}`, y = this.sourceArrow ? "" : `M 0 0 L ${v.x} ${v.y} `, C = this.targetArrow ? "" : ` M ${p.x} ${p.y} L ${s} ${o}`, A = `${y}${x}${C}`;
411
301
  if (this.line.setAttribute("d", A), this.sourceArrow) {
412
- const C = N(
302
+ const M = N(
413
303
  u,
414
304
  0,
415
305
  0,
416
306
  this.arrowLength,
417
307
  this.arrowWidth
418
308
  );
419
- this.sourceArrow.setAttribute("d", C);
309
+ this.sourceArrow.setAttribute("d", M);
420
310
  }
421
311
  if (this.targetArrow) {
422
- const C = N(
423
- g,
312
+ const M = N(
313
+ w,
424
314
  s,
425
315
  o,
426
316
  -this.arrowLength,
427
317
  this.arrowWidth
428
318
  );
429
- this.targetArrow.setAttribute("d", C);
319
+ this.targetArrow.setAttribute("d", M);
430
320
  }
431
321
  }
432
322
  }
433
- const F = (e, t) => {
434
- const r = [];
435
- if (e.length > 0 && r.push(`M ${e[0].x} ${e[0].y}`), e.length === 2 && r.push(`L ${e[1].x} ${e[1].y}`), e.length > 2) {
436
- const s = e.length - 1;
437
- let o = 0, i = 0, n = 0;
438
- e.forEach((c, h) => {
439
- let l = 0, d = 0, u = 0;
440
- const g = h > 0, y = h < s, w = g && y;
441
- if (g && (l = -o, d = -i, u = n), y) {
442
- const C = e[h + 1];
443
- o = C.x - c.x, i = C.y - c.y, n = Math.sqrt(o * o + i * i);
444
- }
445
- const m = Math.min((w ? t : 0) / n, h < s - 1 ? 0.5 : 1), f = w ? { x: c.x + o * m, y: c.y + i * m } : c, x = Math.min((w ? t : 0) / u, h > 1 ? 0.5 : 1), A = w ? { x: c.x + l * x, y: c.y + d * x } : c;
446
- h > 0 && r.push(`L ${A.x} ${A.y}`), w && r.push(
447
- `C ${c.x} ${c.y} ${c.x} ${c.y} ${f.x} ${f.y}`
448
- );
449
- });
450
- }
451
- return r.join(" ");
452
- };
453
- class et {
454
- constructor(t, r, s, o, i, n, c, h) {
455
- a(this, "svg");
456
- a(this, "group");
457
- a(this, "line");
458
- a(this, "sourceArrow", null);
459
- a(this, "targetArrow", null);
460
- this.color = t, this.width = r, this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = h, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", n && (this.sourceArrow = document.createElementNS(
461
- "http://www.w3.org/2000/svg",
462
- "path"
463
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = document.createElementNS(
464
- "http://www.w3.org/2000/svg",
465
- "path"
466
- ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
467
- }
468
- update(t, r, s, o, i, n) {
323
+ class at {
324
+ constructor(t, r, s, o, i, h, c, a) {
325
+ n(this, "svg", V());
326
+ n(this, "group", O());
327
+ n(this, "line");
328
+ n(this, "sourceArrow", null);
329
+ n(this, "targetArrow", null);
330
+ this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = a, this.svg.appendChild(this.group), this.line = R(t, r), this.group.appendChild(this.line), h && (this.sourceArrow = b(t), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = b(t), this.group.appendChild(this.targetArrow));
331
+ }
332
+ update(t, r, s, o, i, h) {
469
333
  this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`, this.svg.style.transform = `translate(${t}px, ${r}px)`;
470
- const c = M(i), h = M(n), l = c.x <= h.x ? 1 : -1, d = c.y <= h.y ? 1 : -1;
471
- this.group.style.transform = `scale(${l}, ${d})`;
472
- const u = S(i.direction, l, d), g = S(n.direction, l, d), y = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
334
+ const c = L(i), a = L(h), d = c.x <= a.x ? 1 : -1, l = c.y <= a.y ? 1 : -1;
335
+ this.group.style.transform = `scale(${d}, ${l})`;
336
+ const u = P(i.direction, d, l), w = P(h.direction, d, l), v = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
473
337
  x: 0,
474
338
  y: 0
475
- }) : { x: 0, y: 0 }, w = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, g, {
339
+ }) : { x: 0, y: 0 }, p = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, w, {
476
340
  x: s,
477
341
  y: o
478
- }) : { x: s, y: o }, v = this.arrowLength + this.arrowOffset, m = E({ x: v, y: 0 }, u, { x: 0, y: 0 }), f = E({ x: s - v, y: o }, g, {
342
+ }) : { x: s, y: o }, f = this.arrowLength + this.arrowOffset, m = E({ x: f, y: 0 }, u, { x: 0, y: 0 }), x = E({ x: s - f, y: o }, w, {
479
343
  x: s,
480
344
  y: o
481
- }), p = F([y, m, f, w], this.roundness);
482
- if (this.line.setAttribute("d", p), this.sourceArrow) {
483
- const x = N(
345
+ }), y = k([v, m, x, p], this.roundness);
346
+ if (this.line.setAttribute("d", y), this.sourceArrow) {
347
+ const C = N(
484
348
  u,
485
349
  0,
486
350
  0,
487
351
  this.arrowLength,
488
352
  this.arrowWidth
489
353
  );
490
- this.sourceArrow.setAttribute("d", x);
354
+ this.sourceArrow.setAttribute("d", C);
491
355
  }
492
356
  if (this.targetArrow) {
493
- const x = N(
494
- g,
357
+ const C = N(
358
+ w,
495
359
  s,
496
360
  o,
497
361
  -this.arrowLength,
498
362
  this.arrowWidth
499
363
  );
500
- this.targetArrow.setAttribute("d", x);
364
+ this.targetArrow.setAttribute("d", C);
501
365
  }
502
366
  }
503
367
  }
504
- class rt {
505
- constructor(t, r, s, o, i, n, c, h) {
506
- a(this, "svg");
507
- a(this, "group");
508
- a(this, "line");
509
- a(this, "sourceArrow", null);
510
- a(this, "targetArrow", null);
511
- this.color = t, this.width = r, this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = h, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", n && (this.sourceArrow = document.createElementNS(
512
- "http://www.w3.org/2000/svg",
513
- "path"
514
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = document.createElementNS(
515
- "http://www.w3.org/2000/svg",
516
- "path"
517
- ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
518
- }
519
- update(t, r, s, o, i, n) {
368
+ class ht {
369
+ constructor(t, r, s, o, i, h, c, a) {
370
+ n(this, "svg", V());
371
+ n(this, "group", O());
372
+ n(this, "line");
373
+ n(this, "sourceArrow", null);
374
+ n(this, "targetArrow", null);
375
+ this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = a, this.svg.appendChild(this.group), this.line = R(t, r), this.group.appendChild(this.line), h && (this.sourceArrow = b(t), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = b(t), this.group.appendChild(this.targetArrow));
376
+ }
377
+ update(t, r, s, o, i, h) {
520
378
  this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`, this.svg.style.transform = `translate(${t}px, ${r}px)`;
521
- const c = M(i), h = M(n), l = c.x <= h.x ? 1 : -1, d = c.y <= h.y ? 1 : -1;
522
- this.group.style.transform = `scale(${l}, ${d})`;
523
- const u = S(i.direction, l, d), g = S(n.direction, l, d), y = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
379
+ const c = L(i), a = L(h), d = c.x <= a.x ? 1 : -1, l = c.y <= a.y ? 1 : -1;
380
+ this.group.style.transform = `scale(${d}, ${l})`;
381
+ const u = P(i.direction, d, l), w = P(h.direction, d, l), v = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
524
382
  x: 0,
525
383
  y: 0
526
- }) : { x: 0, y: 0 }, w = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, g, {
384
+ }) : { x: 0, y: 0 }, p = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, w, {
527
385
  x: s,
528
386
  y: o
529
- }) : { x: s, y: o }, v = this.arrowLength + this.arrowOffset, m = E({ x: v, y: 0 }, u, { x: 0, y: 0 }), f = E({ x: s - v, y: o }, g, {
387
+ }) : { x: s, y: o }, f = this.arrowLength + this.arrowOffset, m = f - this.roundness, x = E({ x: m, y: 0 }, u, { x: 0, y: 0 }), y = E({ x: s - m, y: o }, w, {
530
388
  x: s,
531
389
  y: o
532
- }), p = Math.max((m.x + f.x) / 2, v), x = o / 2, A = { x: l > 0 ? p : -v, y: m.y }, C = { x: A.x, y: x }, P = { x: l > 0 ? s - p : s + v, y: f.y }, T = { x: P.x, y: x }, L = F(
533
- [y, m, A, C, T, P, f, w],
390
+ }), C = Math.max((x.x + y.x) / 2, f), A = o / 2, M = { x: d > 0 ? C : -f, y: x.y }, F = { x: M.x, y: A }, D = { x: d > 0 ? s - C : s + f, y: y.y }, W = { x: D.x, y: A }, Y = k(
391
+ [v, x, M, F, W, D, y, p],
534
392
  this.roundness
535
393
  );
536
- if (this.line.setAttribute("d", L), this.sourceArrow) {
394
+ if (this.line.setAttribute("d", Y), this.sourceArrow) {
537
395
  const $ = N(
538
396
  u,
539
397
  0,
@@ -545,7 +403,7 @@ class rt {
545
403
  }
546
404
  if (this.targetArrow) {
547
405
  const $ = N(
548
- g,
406
+ w,
549
407
  s,
550
408
  o,
551
409
  -this.arrowLength,
@@ -555,42 +413,36 @@ class rt {
555
413
  }
556
414
  }
557
415
  }
558
- class st {
559
- constructor(t, r, s, o, i, n, c, h) {
560
- a(this, "svg");
561
- a(this, "group");
562
- a(this, "line");
563
- a(this, "sourceArrow", null);
564
- a(this, "targetArrow", null);
565
- this.color = t, this.width = r, this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = h, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", n && (this.sourceArrow = document.createElementNS(
566
- "http://www.w3.org/2000/svg",
567
- "path"
568
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = document.createElementNS(
569
- "http://www.w3.org/2000/svg",
570
- "path"
571
- ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
572
- }
573
- update(t, r, s, o, i, n) {
416
+ class ct {
417
+ constructor(t, r, s, o, i, h, c, a) {
418
+ n(this, "svg", V());
419
+ n(this, "group", O());
420
+ n(this, "line");
421
+ n(this, "sourceArrow", null);
422
+ n(this, "targetArrow", null);
423
+ this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = a, this.svg.appendChild(this.group), this.line = R(t, r), this.group.appendChild(this.line), h && (this.sourceArrow = b(t), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = b(t), this.group.appendChild(this.targetArrow));
424
+ }
425
+ update(t, r, s, o, i, h) {
574
426
  this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`, this.svg.style.transform = `translate(${t}px, ${r}px)`;
575
- const c = M(i), h = M(n), l = c.x <= h.x ? 1 : -1, d = c.y <= h.y ? 1 : -1;
576
- this.group.style.transform = `scale(${l}, ${d})`;
577
- const u = S(i.direction, l, d), g = S(n.direction, l, d), y = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
427
+ const c = L(i), a = L(h), d = c.x <= a.x ? 1 : -1, l = c.y <= a.y ? 1 : -1;
428
+ this.group.style.transform = `scale(${d}, ${l})`;
429
+ const u = P(i.direction, d, l), w = P(h.direction, d, l), v = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
578
430
  x: 0,
579
431
  y: 0
580
- }) : { x: 0, y: 0 }, w = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, g, {
432
+ }) : { x: 0, y: 0 }, p = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, w, {
581
433
  x: s,
582
434
  y: o
583
- }) : { x: s, y: o }, v = this.arrowLength + this.arrowOffset, m = E({ x: v, y: 0 }, u, { x: 0, y: 0 }), f = E({ x: s - v, y: o }, g, {
435
+ }) : { x: s, y: o }, f = this.arrowLength + this.arrowOffset, m = f - this.roundness, x = E({ x: m, y: 0 }, u, { x: 0, y: 0 }), y = E({ x: s - m, y: o }, w, {
584
436
  x: s,
585
437
  y: o
586
- }), p = Math.max((m.y + f.y) / 2, v), x = s / 2, A = { x: m.x, y: d > 0 ? p : -v }, C = { x, y: A.y }, P = {
587
- x: f.x,
588
- y: d > 0 ? o - p : o + v
589
- }, T = { x, y: P.y }, L = F(
590
- [y, m, A, C, T, P, f, w],
438
+ }), C = Math.max((x.y + y.y) / 2, f), A = s / 2, M = { x: x.x, y: l > 0 ? C : -f }, F = { x: A, y: M.y }, D = {
439
+ x: y.x,
440
+ y: l > 0 ? o - C : o + f
441
+ }, W = { x: A, y: D.y }, Y = k(
442
+ [v, x, M, F, W, D, y, p],
591
443
  this.roundness
592
444
  );
593
- if (this.line.setAttribute("d", L), this.sourceArrow) {
445
+ if (this.line.setAttribute("d", Y), this.sourceArrow) {
594
446
  const $ = N(
595
447
  u,
596
448
  0,
@@ -602,7 +454,7 @@ class st {
602
454
  }
603
455
  if (this.targetArrow) {
604
456
  const $ = N(
605
- g,
457
+ w,
606
458
  s,
607
459
  o,
608
460
  -this.arrowLength,
@@ -612,62 +464,56 @@ class st {
612
464
  }
613
465
  }
614
466
  }
615
- class ot {
616
- constructor(t, r, s, o, i, n, c) {
617
- a(this, "svg");
618
- a(this, "group");
619
- a(this, "line");
620
- a(this, "arrow", null);
621
- this.color = t, this.width = r, this.arrowLength = s, this.arrowWidth = o, this.radius = n, this.smallRadius = c, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", i && (this.arrow = document.createElementNS(
622
- "http://www.w3.org/2000/svg",
623
- "path"
624
- ), this.arrow.setAttribute("fill", this.color), this.group.appendChild(this.arrow)), this.svg.style.overflow = "visible", this.svg.style.width = "0px", this.svg.style.height = "0px";
467
+ class dt {
468
+ constructor(t, r, s, o, i, h, c) {
469
+ n(this, "svg", V());
470
+ n(this, "group", O());
471
+ n(this, "line");
472
+ n(this, "arrow", null);
473
+ this.arrowLength = s, this.arrowWidth = o, this.radius = h, this.smallRadius = c, this.svg.appendChild(this.group), this.line = R(t, r), this.group.appendChild(this.line), i && (this.arrow = b(t), this.group.appendChild(this.arrow)), this.svg.style.width = "0px", this.svg.style.height = "0px";
625
474
  }
626
475
  update(t, r, s, o, i) {
627
476
  this.svg.style.transform = `translate(${t}px, ${r}px)`;
628
- const n = S(i.direction, 1, 1), c = this.smallRadius, h = this.radius, l = Math.sqrt(c * c + h * h), d = c + h, u = this.arrowLength + l * (1 - h / d), g = c * h / d, w = [
477
+ const h = P(i.direction, 1, 1), c = this.smallRadius, a = this.radius, d = Math.sqrt(c * c + a * a), l = c + a, u = this.arrowLength + d * (1 - a / l), w = c * a / l, p = [
629
478
  { x: this.arrowLength, y: 0 },
630
- { x: u, y: g },
631
- { x: u, y: -g }
479
+ { x: u, y: w },
480
+ { x: u, y: -w }
632
481
  ].map(
633
- (p) => E(p, n, { x: 0, y: 0 })
634
- ), v = [
635
- `M ${w[0].x} ${w[0].y}`,
636
- `A ${c} ${c} 0 0 1 ${w[1].x} ${w[1].y}`,
637
- `A ${h} ${h} 0 1 0 ${w[2].x} ${w[2].y}`,
638
- `A ${c} ${c} 0 0 1 ${w[0].x} ${w[0].y}`
639
- ].join(" "), m = `M 0 0 L ${w[0].x} ${w[0].y} `, f = `${this.arrow !== null ? "" : m}${v}`;
640
- if (this.line.setAttribute("d", f), this.arrow) {
641
- const p = N(
642
- n,
482
+ (y) => E(y, h, { x: 0, y: 0 })
483
+ ), f = [
484
+ `M ${p[0].x} ${p[0].y}`,
485
+ `A ${c} ${c} 0 0 1 ${p[1].x} ${p[1].y}`,
486
+ `A ${a} ${a} 0 1 0 ${p[2].x} ${p[2].y}`,
487
+ `A ${c} ${c} 0 0 1 ${p[0].x} ${p[0].y}`
488
+ ].join(" "), m = `M 0 0 L ${p[0].x} ${p[0].y} `, x = `${this.arrow !== null ? "" : m}${f}`;
489
+ if (this.line.setAttribute("d", x), this.arrow) {
490
+ const y = N(
491
+ h,
643
492
  0,
644
493
  0,
645
494
  this.arrowLength,
646
495
  this.arrowWidth
647
496
  );
648
- this.arrow.setAttribute("d", p);
497
+ this.arrow.setAttribute("d", y);
649
498
  }
650
499
  }
651
500
  }
652
- class k {
653
- constructor(t, r, s, o, i, n, c, h) {
654
- a(this, "svg");
655
- a(this, "group");
656
- a(this, "line");
657
- a(this, "arrow", null);
658
- a(this, "roundness");
659
- a(this, "linePoints");
660
- this.color = t, this.width = r, this.arrowLength = s, this.arrowWidth = o, this.side = n, this.minPortOffset = c, this.roundness = Math.min(h, this.minPortOffset, this.side / 2), this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", i && (this.arrow = document.createElementNS(
661
- "http://www.w3.org/2000/svg",
662
- "path"
663
- ), this.arrow.setAttribute("fill", this.color), this.group.appendChild(this.arrow)), this.svg.style.overflow = "visible", this.svg.style.width = "0px", this.svg.style.height = "0px";
664
- const l = this.minPortOffset, d = this.side, u = this.arrowLength + l, g = this.roundness, y = u + 2 * d;
665
- console.log(g), this.linePoints = [
501
+ class U {
502
+ constructor(t, r, s, o, i, h, c, a) {
503
+ n(this, "svg", V());
504
+ n(this, "group", O());
505
+ n(this, "line");
506
+ n(this, "arrow", null);
507
+ n(this, "roundness");
508
+ n(this, "linePoints");
509
+ this.arrowLength = s, this.arrowWidth = o, this.side = h, this.minPortOffset = c, this.roundness = Math.min(a, this.minPortOffset, this.side / 2), this.svg.appendChild(this.group), this.line = R(t, r), this.group.appendChild(this.line), i && (this.arrow = b(t), this.group.appendChild(this.arrow)), this.svg.style.width = "0px", this.svg.style.height = "0px";
510
+ const d = this.minPortOffset, l = this.side, u = this.arrowLength + d, w = this.roundness, v = u + 2 * l;
511
+ console.log(w), this.linePoints = [
666
512
  { x: this.arrowLength, y: 0 },
667
513
  { x: u, y: 0 },
668
514
  { x: u, y: this.side },
669
- { x: y, y: this.side },
670
- { x: y, y: -this.side },
515
+ { x: v, y: this.side },
516
+ { x: v, y: -this.side },
671
517
  { x: u, y: -this.side },
672
518
  { x: u, y: 0 },
673
519
  { x: this.arrowLength, y: 0 }
@@ -675,158 +521,146 @@ class k {
675
521
  }
676
522
  update(t, r, s, o, i) {
677
523
  this.svg.style.transform = `translate(${t}px, ${r}px)`;
678
- const n = S(i.direction, 1, 1), c = this.linePoints.map(
679
- (d) => E(d, n, { x: 0, y: 0 })
680
- ), h = `M 0 0 L ${c[0].x} ${c[0].y} `, l = `${this.arrow ? "" : h}${F(c, this.roundness)}`;
681
- if (this.line.setAttribute("d", l), this.arrow) {
682
- const d = N(
683
- n,
524
+ const h = P(i.direction, 1, 1), c = this.linePoints.map(
525
+ (l) => E(l, h, { x: 0, y: 0 })
526
+ ), a = `M 0 0 L ${c[0].x} ${c[0].y} `, d = `${this.arrow ? "" : a}${k(c, this.roundness)}`;
527
+ if (this.line.setAttribute("d", d), this.arrow) {
528
+ const l = N(
529
+ h,
684
530
  0,
685
531
  0,
686
532
  this.arrowLength,
687
533
  this.arrowWidth
688
534
  );
689
- this.arrow.setAttribute("d", d);
535
+ this.arrow.setAttribute("d", l);
690
536
  }
691
537
  }
692
538
  }
693
- class R {
694
- constructor(t, r, s, o, i, n, c, h, l, d) {
695
- a(this, "svg");
696
- a(this, "group");
697
- a(this, "line");
698
- a(this, "sourceArrow", null);
699
- a(this, "targetArrow", null);
700
- a(this, "detourX");
701
- a(this, "detourY");
702
- this.color = t, this.width = r, this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = h, this.detourX = Math.cos(d) * l, this.detourY = Math.sin(d) * l, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", n && (this.sourceArrow = document.createElementNS(
703
- "http://www.w3.org/2000/svg",
704
- "path"
705
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = document.createElementNS(
706
- "http://www.w3.org/2000/svg",
707
- "path"
708
- ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
709
- }
710
- update(t, r, s, o, i, n) {
539
+ class _ {
540
+ constructor(t, r, s, o, i, h, c, a, d, l) {
541
+ n(this, "svg", V());
542
+ n(this, "group", O());
543
+ n(this, "line");
544
+ n(this, "sourceArrow", null);
545
+ n(this, "targetArrow", null);
546
+ n(this, "detourX");
547
+ n(this, "detourY");
548
+ this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = a, this.detourX = Math.cos(l) * d, this.detourY = Math.sin(l) * d, this.svg.appendChild(this.group), this.line = R(t, r), this.group.appendChild(this.line), h && (this.sourceArrow = b(t), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = b(t), this.group.appendChild(this.targetArrow));
549
+ }
550
+ update(t, r, s, o, i, h) {
711
551
  this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`, this.svg.style.transform = `translate(${t}px, ${r}px)`;
712
- const c = M(i), h = M(n), l = c.x <= h.x ? 1 : -1, d = c.y <= h.y ? 1 : -1;
713
- this.group.style.transform = `scale(${l}, ${d})`;
714
- const u = S(i.direction, l, d), g = S(n.direction, l, d), y = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
552
+ const c = L(i), a = L(h), d = c.x <= a.x ? 1 : -1, l = c.y <= a.y ? 1 : -1;
553
+ this.group.style.transform = `scale(${d}, ${l})`;
554
+ const u = P(i.direction, d, l), w = P(h.direction, d, l), v = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
715
555
  x: 0,
716
556
  y: 0
717
- }) : { x: 0, y: 0 }, w = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, g, {
557
+ }) : { x: 0, y: 0 }, p = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, w, {
718
558
  x: s,
719
559
  y: o
720
- }) : { x: s, y: o }, v = this.arrowLength + this.arrowOffset, m = E({ x: v, y: 0 }, u, {
560
+ }) : { x: s, y: o }, f = this.arrowLength + this.arrowOffset, m = E({ x: f, y: 0 }, u, {
721
561
  x: 0,
722
562
  y: 0
723
- }), f = { x: m.x + this.detourX, y: m.y + this.detourY }, p = E(
724
- { x: s - v, y: o },
725
- g,
563
+ }), x = { x: m.x + this.detourX, y: m.y + this.detourY }, y = E(
564
+ { x: s - f, y: o },
565
+ w,
726
566
  {
727
567
  x: s,
728
568
  y: o
729
569
  }
730
- ), x = { x: p.x + this.detourX, y: p.y + this.detourY }, A = F(
731
- [y, m, f, x, p, w],
570
+ ), C = { x: y.x + this.detourX, y: y.y + this.detourY }, A = k(
571
+ [v, m, x, C, y, p],
732
572
  this.roundness
733
573
  );
734
574
  if (this.line.setAttribute("d", A), this.sourceArrow) {
735
- const C = N(
575
+ const M = N(
736
576
  u,
737
577
  0,
738
578
  0,
739
579
  this.arrowLength,
740
580
  this.arrowWidth
741
581
  );
742
- this.sourceArrow.setAttribute("d", C);
582
+ this.sourceArrow.setAttribute("d", M);
743
583
  }
744
584
  if (this.targetArrow) {
745
- const C = N(
746
- g,
585
+ const M = N(
586
+ w,
747
587
  s,
748
588
  o,
749
589
  -this.arrowLength,
750
590
  this.arrowWidth
751
591
  );
752
- this.targetArrow.setAttribute("d", C);
592
+ this.targetArrow.setAttribute("d", M);
753
593
  }
754
594
  }
755
595
  }
756
- var b = /* @__PURE__ */ ((e) => (e.Regular = "regular", e.PortCycle = "port-cycle", e.NodeCycle = "node-cycle", e))(b || {});
757
- class it {
758
- constructor(t, r, s, o, i, n, c, h, l) {
759
- a(this, "svg");
760
- a(this, "group");
761
- a(this, "line");
762
- a(this, "sourceArrow", null);
763
- a(this, "targetArrow", null);
764
- a(this, "detourX");
765
- a(this, "detourY");
766
- this.color = t, this.width = r, this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.detourX = Math.cos(l) * h, this.detourY = Math.sin(l) * h, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", n && (this.sourceArrow = document.createElementNS(
767
- "http://www.w3.org/2000/svg",
768
- "path"
769
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = document.createElementNS(
770
- "http://www.w3.org/2000/svg",
771
- "path"
772
- ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
773
- }
774
- update(t, r, s, o, i, n) {
596
+ var T = /* @__PURE__ */ ((e) => (e.Regular = "regular", e.PortCycle = "port-cycle", e.NodeCycle = "node-cycle", e))(T || {});
597
+ class lt {
598
+ constructor(t, r, s, o, i, h, c, a, d) {
599
+ n(this, "svg", V());
600
+ n(this, "group", O());
601
+ n(this, "line");
602
+ n(this, "sourceArrow", null);
603
+ n(this, "targetArrow", null);
604
+ n(this, "detourX");
605
+ n(this, "detourY");
606
+ this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.detourX = Math.cos(d) * a, this.detourY = Math.sin(d) * a, this.svg.appendChild(this.group), this.line = R(t, r), this.group.appendChild(this.line), h && (this.sourceArrow = b(t), this.group.appendChild(this.sourceArrow)), c && (this.targetArrow = b(t), this.group.appendChild(this.targetArrow));
607
+ }
608
+ update(t, r, s, o, i, h) {
775
609
  this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`, this.svg.style.transform = `translate(${t}px, ${r}px)`;
776
- const c = M(i), h = M(n), l = c.x <= h.x ? 1 : -1, d = c.y <= h.y ? 1 : -1;
777
- this.group.style.transform = `scale(${l}, ${d})`;
778
- const u = S(i.direction, l, d), g = S(n.direction, l, d), y = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
610
+ const c = L(i), a = L(h), d = c.x <= a.x ? 1 : -1, l = c.y <= a.y ? 1 : -1;
611
+ this.group.style.transform = `scale(${d}, ${l})`;
612
+ const u = P(i.direction, d, l), w = P(h.direction, d, l), v = this.sourceArrow ? E({ x: this.arrowLength, y: 0 }, u, {
779
613
  x: 0,
780
614
  y: 0
781
- }) : { x: 0, y: 0 }, w = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, g, {
615
+ }) : { x: 0, y: 0 }, p = this.targetArrow ? E({ x: s - this.arrowLength, y: o }, w, {
782
616
  x: s,
783
617
  y: o
784
- }) : { x: s, y: o }, v = this.arrowLength, m = E({ x: v, y: 0 }, u, {
618
+ }) : { x: s, y: o }, f = this.arrowLength, m = E({ x: f, y: 0 }, u, {
785
619
  x: 0,
786
620
  y: 0
787
- }), f = { x: m.x + this.detourX, y: m.y + this.detourY }, p = E(
788
- { x: s - v, y: o },
789
- g,
621
+ }), x = { x: m.x + this.detourX, y: m.y + this.detourY }, y = E(
622
+ { x: s - f, y: o },
623
+ w,
790
624
  {
791
625
  x: s,
792
626
  y: o
793
627
  }
794
- ), x = { x: p.x + this.detourX, y: p.y + this.detourY }, A = { x: (f.x + x.x) / 2, y: (f.y + x.y) / 2 }, C = {
628
+ ), C = { x: y.x + this.detourX, y: y.y + this.detourY }, A = { x: (x.x + C.x) / 2, y: (x.y + C.y) / 2 }, M = {
795
629
  x: m.x - this.curvature * Math.cos(i.direction),
796
630
  y: m.y - this.curvature * Math.sin(i.direction)
797
- }, P = {
798
- x: p.x + this.curvature * Math.cos(n.direction),
799
- y: p.y + this.curvature * Math.sin(n.direction)
800
- }, T = { x: m.x + this.detourX, y: m.y + this.detourY }, L = { x: p.x + this.detourX, y: p.y + this.detourY }, $ = [
801
- `M ${y.x} ${y.y}`,
631
+ }, F = {
632
+ x: y.x + this.curvature * Math.cos(h.direction),
633
+ y: y.y + this.curvature * Math.sin(h.direction)
634
+ }, D = { x: m.x + this.detourX, y: m.y + this.detourY }, W = { x: y.x + this.detourX, y: y.y + this.detourY }, Y = [
635
+ `M ${v.x} ${v.y}`,
802
636
  `L ${m.x} ${m.y}`,
803
- `C ${C.x} ${C.y} ${T.x} ${T.y} ${A.x} ${A.y}`,
804
- `C ${L.x} ${L.y} ${P.x} ${P.y} ${p.x} ${p.y}`,
805
- `L ${w.x} ${w.y}`
637
+ `C ${M.x} ${M.y} ${D.x} ${D.y} ${A.x} ${A.y}`,
638
+ `C ${W.x} ${W.y} ${F.x} ${F.y} ${y.x} ${y.y}`,
639
+ `L ${p.x} ${p.y}`
806
640
  ].join(" ");
807
- if (this.line.setAttribute("d", $), this.sourceArrow) {
808
- const V = N(
641
+ if (this.line.setAttribute("d", Y), this.sourceArrow) {
642
+ const $ = N(
809
643
  u,
810
644
  0,
811
645
  0,
812
646
  this.arrowLength,
813
647
  this.arrowWidth
814
648
  );
815
- this.sourceArrow.setAttribute("d", V);
649
+ this.sourceArrow.setAttribute("d", $);
816
650
  }
817
651
  if (this.targetArrow) {
818
- const V = N(
819
- g,
652
+ const $ = N(
653
+ w,
820
654
  s,
821
655
  o,
822
656
  -this.arrowLength,
823
657
  this.arrowWidth
824
658
  );
825
- this.targetArrow.setAttribute("d", V);
659
+ this.targetArrow.setAttribute("d", $);
826
660
  }
827
661
  }
828
662
  }
829
- const nt = (e) => (t) => t === b.PortCycle ? new ot(
663
+ const ut = (e) => (t) => t === T.PortCycle ? new dt(
830
664
  e.color,
831
665
  e.width,
832
666
  e.arrowLength,
@@ -834,7 +668,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
834
668
  e.hasSourceArrow || e.hasTargetArrow,
835
669
  e.cycleRadius,
836
670
  e.smallCycleRadius
837
- ) : t === b.NodeCycle ? new it(
671
+ ) : t === T.NodeCycle ? new lt(
838
672
  e.color,
839
673
  e.width,
840
674
  e.curvature,
@@ -844,7 +678,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
844
678
  e.hasTargetArrow,
845
679
  e.detourDistance,
846
680
  e.detourDirection
847
- ) : new tt(
681
+ ) : new nt(
848
682
  e.color,
849
683
  e.width,
850
684
  e.curvature,
@@ -852,7 +686,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
852
686
  e.arrowWidth,
853
687
  e.hasSourceArrow,
854
688
  e.hasTargetArrow
855
- ), at = (e) => (t) => t === b.PortCycle ? new k(
689
+ ), gt = (e) => (t) => t === T.PortCycle ? new U(
856
690
  e.color,
857
691
  e.width,
858
692
  e.arrowLength,
@@ -861,7 +695,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
861
695
  e.cycleSquareSide,
862
696
  e.arrowOffset,
863
697
  e.roundness
864
- ) : t === b.NodeCycle ? new R(
698
+ ) : t === T.NodeCycle ? new _(
865
699
  e.color,
866
700
  e.width,
867
701
  e.arrowLength,
@@ -872,7 +706,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
872
706
  e.roundness,
873
707
  e.detourDistance,
874
708
  e.detourDirection
875
- ) : new et(
709
+ ) : new at(
876
710
  e.color,
877
711
  e.width,
878
712
  e.arrowLength,
@@ -881,7 +715,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
881
715
  e.hasSourceArrow,
882
716
  e.hasTargetArrow,
883
717
  e.roundness
884
- ), ht = (e) => (t) => t === b.PortCycle ? new k(
718
+ ), wt = (e) => (t) => t === T.PortCycle ? new U(
885
719
  e.color,
886
720
  e.width,
887
721
  e.arrowLength,
@@ -890,7 +724,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
890
724
  e.cycleSquareSide,
891
725
  e.arrowOffset,
892
726
  e.roundness
893
- ) : t === b.NodeCycle ? new R(
727
+ ) : t === T.NodeCycle ? new _(
894
728
  e.color,
895
729
  e.width,
896
730
  e.arrowLength,
@@ -901,7 +735,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
901
735
  e.roundness,
902
736
  e.detourDistance,
903
737
  e.detourDirection
904
- ) : new rt(
738
+ ) : new ht(
905
739
  e.color,
906
740
  e.width,
907
741
  e.arrowLength,
@@ -910,7 +744,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
910
744
  e.hasSourceArrow,
911
745
  e.hasTargetArrow,
912
746
  e.roundness
913
- ), ct = (e) => (t) => t === b.PortCycle ? new k(
747
+ ), pt = (e) => (t) => t === T.PortCycle ? new U(
914
748
  e.color,
915
749
  e.width,
916
750
  e.arrowLength,
@@ -919,7 +753,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
919
753
  e.cycleSquareSide,
920
754
  e.arrowOffset,
921
755
  e.roundness
922
- ) : t === b.NodeCycle ? new R(
756
+ ) : t === T.NodeCycle ? new _(
923
757
  e.color,
924
758
  e.width,
925
759
  e.arrowLength,
@@ -930,7 +764,7 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
930
764
  e.roundness,
931
765
  e.detourDistance,
932
766
  e.detourDirection
933
- ) : new st(
767
+ ) : new ct(
934
768
  e.color,
935
769
  e.width,
936
770
  e.arrowLength,
@@ -940,128 +774,131 @@ const nt = (e) => (t) => t === b.PortCycle ? new ot(
940
774
  e.hasTargetArrow,
941
775
  e.roundness
942
776
  );
943
- class D {
944
- constructor() {
945
- a(this, "counter", 0);
777
+ class X {
778
+ constructor(t) {
779
+ n(this, "counter", 0);
780
+ this.checkExists = t;
946
781
  }
947
- create() {
948
- const t = this.counter;
949
- return this.counter++, t;
782
+ create(t) {
783
+ if (t !== void 0)
784
+ return t;
785
+ for (; this.checkExists(this.counter); )
786
+ this.counter++;
787
+ return this.counter;
950
788
  }
951
789
  reset() {
952
790
  this.counter = 0;
953
791
  }
954
792
  }
955
- class lt {
956
- constructor(t, r, s, o, i, n, c, h) {
957
- a(this, "nodeIdGenerator", new D());
958
- a(this, "portIdGenerator", new D());
959
- a(this, "edgeIdGenerator", new D());
960
- this.graphStore = t, this.htmlController = r, this.viewportTransformer = s, this.nodesCenterFn = o, this.portsCenterFn = i, this.portsDirection = n, this.nodesPriorityFn = c, this.edgesPriorityFn = h;
961
- }
962
- addNode(t, r, s, o, i, n, c) {
963
- if (t === void 0)
964
- do
965
- t = this.nodeIdGenerator.create();
966
- while (this.graphStore.getNode(t) !== void 0);
967
- if (this.graphStore.getNode(t) !== void 0)
968
- throw new Error("failed to add node with existing id");
793
+ class S extends Error {
794
+ constructor() {
795
+ super(...arguments);
796
+ n(this, "name", "HtmlGraphError");
797
+ }
798
+ }
799
+ class yt {
800
+ constructor(t, r, s, o, i, h, c, a) {
801
+ n(this, "nodeIdGenerator", new X(
802
+ (t) => this.graphStore.getNode(t) !== void 0
803
+ ));
804
+ n(this, "portIdGenerator", new X(
805
+ (t) => this.graphStore.getPort(t) !== void 0
806
+ ));
807
+ n(this, "edgeIdGenerator", new X(
808
+ (t) => this.graphStore.getEdge(t) !== void 0
809
+ ));
810
+ this.graphStore = t, this.htmlController = r, this.viewportTransformer = s, this.defaultNodesCenterFn = o, this.defaultPortsCenterFn = i, this.defaultPortsDirection = h, this.defaultNodesPriorityFn = c, this.defaultEdgesPriorityFn = a;
811
+ }
812
+ addNode(t, r, s, o, i, h, c) {
813
+ if (t = this.nodeIdGenerator.create(t), this.graphStore.getNode(t) !== void 0)
814
+ throw new S("failed to add node with existing id");
969
815
  this.graphStore.addNode(
970
816
  t,
971
817
  r,
972
818
  s,
973
819
  o,
974
- n ?? this.nodesCenterFn,
975
- c ?? this.nodesPriorityFn()
976
- ), this.htmlController.attachNode(t), new Map(i ?? []).forEach((l, d) => {
977
- l instanceof HTMLElement ? this.markPort(
978
- d,
979
- l,
980
- t,
981
- this.portsCenterFn,
982
- this.portsDirection
983
- ) : this.markPort(
984
- d,
985
- l.element,
820
+ h ?? this.defaultNodesCenterFn,
821
+ c ?? this.defaultNodesPriorityFn()
822
+ ), this.htmlController.attachNode(t), Array.from(i ?? []).forEach((a) => {
823
+ this.markPort(
824
+ a.id,
825
+ a.element,
986
826
  t,
987
- l.centerFn ?? this.portsCenterFn,
988
- l.direction ?? this.portsDirection
827
+ a.centerFn ?? this.defaultPortsCenterFn,
828
+ a.direction ?? this.defaultPortsDirection
989
829
  );
990
830
  });
991
831
  }
992
832
  updateNode(t, r, s, o, i) {
993
- const n = this.graphStore.getNode(t);
994
- if (n === void 0)
995
- throw new Error("failed to update nonexisting node");
996
- n.x = r ?? n.x, n.y = s ?? n.y, n.centerFn = i ?? n.centerFn, this.htmlController.updateNodeCoordinates(t), o !== void 0 && (n.priority = o, this.htmlController.updateNodePriority(t));
833
+ const h = this.graphStore.getNode(t);
834
+ if (h === void 0)
835
+ throw new S("failed to update nonexisting node");
836
+ h.x = r ?? h.x, h.y = s ?? h.y, h.centerFn = i ?? h.centerFn, this.htmlController.updateNodeCoordinates(t), o !== void 0 && (h.priority = o, this.htmlController.updateNodePriority(t));
837
+ }
838
+ removeNode(t) {
839
+ if (this.graphStore.getNode(t) === void 0)
840
+ throw new S("failed to remove nonexisting node");
841
+ (this.graphStore.getNodePortIds(t) ?? []).forEach((r) => {
842
+ this.unmarkPort(r);
843
+ }), this.htmlController.detachNode(t), this.graphStore.removeNode(t);
997
844
  }
998
845
  markPort(t, r, s, o, i) {
999
- if (t === void 0)
1000
- do
1001
- t = this.portIdGenerator.create();
1002
- while (this.graphStore.getPort(t) !== void 0);
1003
- if (this.graphStore.getNode(s) === void 0)
1004
- throw new Error("failed to set port on nonexisting node");
846
+ if (t = this.portIdGenerator.create(t), this.graphStore.getNode(s) === void 0)
847
+ throw new S("failed to set port on nonexisting node");
1005
848
  if (this.graphStore.getPort(t) !== void 0)
1006
- throw new Error("failed to add port with existing id");
849
+ throw new S("failed to add port with existing id");
1007
850
  this.graphStore.addPort(
1008
851
  t,
1009
852
  r,
1010
853
  s,
1011
- o ?? this.portsCenterFn,
1012
- i ?? 0
854
+ o ?? this.defaultPortsCenterFn,
855
+ i ?? this.defaultPortsDirection
1013
856
  );
1014
857
  }
1015
- updatePort(t, r) {
1016
- const s = this.graphStore.getPort(t);
1017
- if (s === void 0)
1018
- throw new Error("failed to unset nonexisting port");
1019
- s.direction = (r == null ? void 0 : r.direction) ?? s.direction, s.centerFn = (r == null ? void 0 : r.centerFn) ?? s.centerFn, this.htmlController.updatePortEdges(t);
858
+ updatePort(t, r, s) {
859
+ const o = this.graphStore.getPort(t);
860
+ if (o === void 0)
861
+ throw new S("failed to unset nonexisting port");
862
+ o.direction = r ?? o.direction, o.centerFn = s ?? o.centerFn, this.htmlController.updatePortEdges(t);
1020
863
  }
1021
864
  unmarkPort(t) {
1022
865
  if (this.graphStore.getPort(t) === void 0)
1023
- throw new Error("failed to unset nonexisting port");
1024
- this.graphStore.getPortAdjacentEdges(t).forEach((r) => {
866
+ throw new S("failed to unset nonexisting port");
867
+ this.graphStore.getPortAdjacentEdgeIds(t).forEach((r) => {
1025
868
  this.removeEdge(r);
1026
869
  }), this.graphStore.removePort(t);
1027
870
  }
1028
871
  addEdge(t, r, s, o, i) {
1029
- if (t === void 0)
1030
- do
1031
- t = this.edgeIdGenerator.create();
1032
- while (this.graphStore.getEdge(t) !== void 0);
1033
- if (this.graphStore.getPort(r) === void 0)
1034
- throw new Error("failed to add edge from nonexisting port");
872
+ if (t = this.edgeIdGenerator.create(t), this.graphStore.getPort(r) === void 0)
873
+ throw new S("failed to add edge from nonexisting port");
1035
874
  if (this.graphStore.getPort(s) === void 0)
1036
- throw new Error("failed to add edge to nonexisting port");
875
+ throw new S("failed to add edge to nonexisting port");
1037
876
  if (this.graphStore.getEdge(t) !== void 0)
1038
- throw new Error("failed to add edge with existing id");
1039
- let n = b.Regular;
1040
- const c = this.graphStore.getPortNode(r), h = this.graphStore.getPortNode(s);
1041
- r === s ? n = b.PortCycle : c === h && (n = b.NodeCycle), this.graphStore.addEdge(
877
+ throw new S("failed to add edge with existing id");
878
+ const h = this.resolveEdgeType(r, s);
879
+ this.graphStore.addEdge(
1042
880
  t,
1043
881
  r,
1044
882
  s,
1045
- o(n),
1046
- i ?? this.edgesPriorityFn()
883
+ o(h),
884
+ i ?? this.defaultEdgesPriorityFn()
1047
885
  ), this.htmlController.attachEdge(t);
1048
886
  }
1049
- updateEdge(t, r) {
1050
- const s = this.graphStore.getEdge(t);
1051
- if (s === void 0)
1052
- throw new Error("failed to update nonexisting edge");
1053
- r.controller !== void 0 && (this.htmlController.detachEdge(t), s.shape = r.controller, this.htmlController.attachEdge(t)), r.priority !== void 0 && (s.priority = r.priority, this.htmlController.updateEdgePriority(t));
887
+ updateEdge(t, r, s) {
888
+ const o = this.graphStore.getEdge(t);
889
+ if (o === void 0)
890
+ throw new S("failed to update nonexisting edge");
891
+ if (r !== void 0) {
892
+ const i = this.resolveEdgeType(o.from, o.to);
893
+ o.shape = r(i), this.htmlController.updateEdgeShape(t);
894
+ }
895
+ s !== void 0 && (o.priority = s, this.htmlController.updateEdgePriority(t));
1054
896
  }
1055
897
  removeEdge(t) {
1056
898
  if (this.graphStore.getEdge(t) === void 0)
1057
- throw new Error("failed to remove nonexisting edge");
899
+ throw new S("failed to remove nonexisting edge");
1058
900
  this.htmlController.detachEdge(t), this.graphStore.removeEdge(t);
1059
901
  }
1060
- removeNode(t) {
1061
- if (this.graphStore.getNode(t) === void 0)
1062
- throw new Error("failed to remove nonexisting node");
1063
- this.htmlController.detachNode(t), this.graphStore.removeNode(t);
1064
- }
1065
902
  patchViewportMatrix(t, r, s) {
1066
903
  this.viewportTransformer.patchViewportMatrix(t, r, s), this.htmlController.applyTransform();
1067
904
  }
@@ -1080,180 +917,358 @@ class lt {
1080
917
  destroy() {
1081
918
  this.htmlController.destroy();
1082
919
  }
920
+ resolveEdgeType(t, r) {
921
+ if (t === r)
922
+ return T.PortCycle;
923
+ const s = this.graphStore.getPortNodeId(t), o = this.graphStore.getPortNodeId(r);
924
+ return s === o ? T.NodeCycle : T.Regular;
925
+ }
1083
926
  }
1084
- class dt {
1085
- constructor(t, r, s, o, i, n) {
1086
- a(this, "publicViewportTransformer");
1087
- a(this, "publicGraphStore");
1088
- a(this, "canvasController");
1089
- const c = new Q(), h = new q();
1090
- this.publicGraphStore = new I(h), this.publicViewportTransformer = new Z(
927
+ const mt = () => {
928
+ const e = document.createElement("div");
929
+ return e.style.width = "100%", e.style.height = "100%", e.style.position = "relative", e.style.overflow = "hidden", e;
930
+ }, vt = () => {
931
+ const e = document.createElement("canvas");
932
+ return e.style.position = "absolute", e.style.inset = "0", e;
933
+ }, ft = () => {
934
+ const e = document.createElement("div");
935
+ return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.width = "0", e.style.height = "0", e;
936
+ }, xt = () => {
937
+ const e = document.createElement("div");
938
+ return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.visibility = "hidden", e;
939
+ };
940
+ class Ct {
941
+ constructor() {
942
+ n(this, "keyMap", /* @__PURE__ */ new Map());
943
+ n(this, "valueMap", /* @__PURE__ */ new Map());
944
+ }
945
+ set(t, r) {
946
+ this.keyMap.set(t, r), this.valueMap.set(r, t);
947
+ }
948
+ getByKey(t) {
949
+ return this.keyMap.get(t);
950
+ }
951
+ getByValue(t) {
952
+ return this.valueMap.get(t);
953
+ }
954
+ deleteByKey(t) {
955
+ const r = this.keyMap.get(t);
956
+ r !== void 0 && this.valueMap.delete(r), this.keyMap.delete(t);
957
+ }
958
+ deleteByValue(t) {
959
+ const r = this.valueMap.get(t);
960
+ r !== void 0 && this.keyMap.delete(r), this.valueMap.delete(t);
961
+ }
962
+ forEach(t) {
963
+ this.keyMap.forEach((r, s) => {
964
+ t(r, s);
965
+ });
966
+ }
967
+ clear() {
968
+ this.keyMap.clear(), this.valueMap.clear();
969
+ }
970
+ }
971
+ class Et {
972
+ constructor(t, r, s, o) {
973
+ n(this, "canvasWrapper", null);
974
+ n(this, "host", mt());
975
+ n(this, "canvas", vt());
976
+ n(this, "container", ft());
977
+ n(this, "canvasCtx");
978
+ n(this, "canvasResizeObserver");
979
+ n(this, "nodesResizeObserver");
980
+ n(this, "nodeElementToIdMap", /* @__PURE__ */ new Map());
981
+ n(this, "nodeIdToWrapperElementMap", new Ct());
982
+ n(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
983
+ this.graphStore = t, this.viewportTransformer = r, this.publicViewportTransformer = s, this.backgroundDrawingFn = o;
984
+ const i = this.canvas.getContext("2d");
985
+ if (i === null)
986
+ throw new S("unable to get canvas context");
987
+ this.canvasCtx = i, this.host.appendChild(this.canvas), this.host.appendChild(this.container), this.canvasResizeObserver = this.createHostResizeObserver(), this.nodesResizeObserver = this.createNodesResizeObserver();
988
+ }
989
+ clear() {
990
+ this.edgeIdToElementMap.forEach((t, r) => {
991
+ this.detachEdge(r);
992
+ }), this.nodeIdToWrapperElementMap.forEach((t, r) => {
993
+ this.detachNode(r);
994
+ });
995
+ }
996
+ attach(t) {
997
+ this.detach(), this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host), this.canvasResizeObserver.observe(this.canvasWrapper);
998
+ }
999
+ detach() {
1000
+ this.canvasWrapper !== null && (this.canvasResizeObserver.unobserve(this.canvasWrapper), this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
1001
+ }
1002
+ destroy() {
1003
+ this.canvasResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.container), this.clear(), this.detach();
1004
+ }
1005
+ applyTransform() {
1006
+ this.backgroundDrawingFn(this.canvasCtx, this.publicViewportTransformer);
1007
+ const t = this.viewportTransformer.getContentMatrix();
1008
+ this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.dx}, ${t.dy})`;
1009
+ }
1010
+ attachNode(t) {
1011
+ const r = this.graphStore.getNode(t), s = xt();
1012
+ s.appendChild(r.element), this.container.appendChild(s), this.nodeElementToIdMap.set(r.element, t), this.nodeIdToWrapperElementMap.set(t, s), this.updateNodeCoords(t), this.updateNodePriority(t), this.nodesResizeObserver.observe(s), s.style.visibility = "visible";
1013
+ }
1014
+ detachNode(t) {
1015
+ const r = this.graphStore.getNode(t), s = this.nodeIdToWrapperElementMap.getByKey(t);
1016
+ this.nodesResizeObserver.unobserve(s), s.removeChild(r.element), this.container.removeChild(s), this.nodeElementToIdMap.delete(r.element), this.nodeIdToWrapperElementMap.deleteByKey(t);
1017
+ }
1018
+ attachEdge(t) {
1019
+ const r = this.graphStore.getEdge(t);
1020
+ this.edgeIdToElementMap.set(t, r.shape.svg), this.container.appendChild(r.shape.svg), this.updateEdgeCoords(t), this.updateEdgePriority(t);
1021
+ }
1022
+ detachEdge(t) {
1023
+ const r = this.graphStore.getEdge(t);
1024
+ this.container.removeChild(r.shape.svg), this.edgeIdToElementMap.delete(t);
1025
+ }
1026
+ updateNodeCoordinates(t) {
1027
+ const r = this.graphStore.getNodeAdjacentEdgeIds(t);
1028
+ this.updateNodeCoords(t), r.forEach((s) => {
1029
+ this.updateEdgeCoords(s);
1030
+ });
1031
+ }
1032
+ updateNodePriority(t) {
1033
+ const r = this.graphStore.getNode(t), s = this.nodeIdToWrapperElementMap.getByKey(t);
1034
+ s.style.zIndex = `${r.priority}`;
1035
+ }
1036
+ updateEdgeShape(t) {
1037
+ const r = this.edgeIdToElementMap.get(t);
1038
+ this.container.removeChild(r);
1039
+ const s = this.graphStore.getEdge(t);
1040
+ this.edgeIdToElementMap.set(t, s.shape.svg), this.container.appendChild(s.shape.svg), this.updateEdgeCoords(t), this.updateEdgePriority(t);
1041
+ }
1042
+ updateEdgePriority(t) {
1043
+ const r = this.graphStore.getEdge(t);
1044
+ r.shape.svg.style.zIndex = `${r.priority}`;
1045
+ }
1046
+ updatePortEdges(t) {
1047
+ this.graphStore.getPortAdjacentEdgeIds(t).forEach((s) => {
1048
+ this.updateEdgeCoords(s);
1049
+ });
1050
+ }
1051
+ createHostResizeObserver() {
1052
+ return new ResizeObserver(() => {
1053
+ this.updateCanvasDimensions(), this.applyTransform();
1054
+ });
1055
+ }
1056
+ createNodesResizeObserver() {
1057
+ return new ResizeObserver((t) => {
1058
+ t.forEach((r) => {
1059
+ const s = r.target, o = this.nodeIdToWrapperElementMap.getByValue(s);
1060
+ this.updateNodeCoords(o), this.graphStore.getNodeAdjacentEdgeIds(o).forEach((h) => {
1061
+ this.updateEdgeCoords(h);
1062
+ });
1063
+ });
1064
+ });
1065
+ }
1066
+ updateCanvasDimensions() {
1067
+ const { width: t, height: r } = this.host.getBoundingClientRect();
1068
+ this.canvas.width = t, this.canvas.height = r;
1069
+ }
1070
+ updateNodeCoords(t) {
1071
+ const r = this.nodeIdToWrapperElementMap.getByKey(t), { width: s, height: o } = r.getBoundingClientRect(), i = this.viewportTransformer.getViewportMatrix().scale, h = this.graphStore.getNode(t), { x: c, y: a } = h.centerFn(s, o), d = h.x - i * c, l = h.y - i * a;
1072
+ r.style.transform = `matrix(1, 0, 0, 1, ${d}, ${l})`;
1073
+ }
1074
+ updateEdgeCoords(t) {
1075
+ const r = this.graphStore.getEdge(t), s = this.graphStore.getPort(r.from), o = this.graphStore.getPort(r.to), i = s.element.getBoundingClientRect(), h = o.element.getBoundingClientRect(), c = this.host.getBoundingClientRect(), a = this.viewportTransformer.getViewportMatrix(), d = a.scale * (i.left - c.left) + a.dx, l = a.scale * (i.top - c.top) + a.dy, u = a.scale * (h.left - c.left) + a.dx, w = a.scale * (h.top - c.top) + a.dy, { x: v, y: p } = s.centerFn(
1076
+ i.width * a.scale,
1077
+ i.height * a.scale
1078
+ ), { x: f, y: m } = o.centerFn(
1079
+ h.width * a.scale,
1080
+ h.height * a.scale
1081
+ ), x = v + d, y = p + l, C = f + u, A = m + w, M = Math.min(x, C), F = Math.min(y, A), D = Math.abs(C - x), W = Math.abs(A - y);
1082
+ r.shape.update(M, F, D, W, s, o);
1083
+ }
1084
+ }
1085
+ class At {
1086
+ constructor(t, r, s, o, i, h) {
1087
+ n(this, "publicViewportTransformer");
1088
+ n(this, "publicGraphStore");
1089
+ n(this, "canvasController");
1090
+ const c = new rt(), a = new ot();
1091
+ this.publicGraphStore = new it(a), this.publicViewportTransformer = new st(
1091
1092
  c
1092
1093
  );
1093
- const l = new K(
1094
- h,
1094
+ const d = new Et(
1095
+ a,
1095
1096
  c,
1096
1097
  this.publicViewportTransformer,
1097
1098
  t
1098
1099
  );
1099
- this.canvasController = new lt(
1100
- h,
1101
- l,
1100
+ this.canvasController = new yt(
1101
+ a,
1102
+ d,
1102
1103
  c,
1103
1104
  r,
1104
1105
  s,
1105
1106
  o,
1106
1107
  i,
1107
- n
1108
+ h
1108
1109
  );
1109
1110
  }
1110
1111
  }
1111
- const X = (e, t) => ({
1112
+ const Q = (e, t) => ({
1112
1113
  x: e / 2,
1113
1114
  y: t / 2
1114
- }), ut = () => () => {
1115
- }, gt = (e, t, r, s, o, i) => {
1115
+ }), Mt = () => () => {
1116
+ }, St = (e, t, r, s, o, i, h) => {
1116
1117
  e.clearRect(0, 0, e.canvas.width, e.canvas.height), e.fillStyle = i, e.fillRect(0, 0, e.canvas.width, e.canvas.height);
1117
- const n = t.getContentMatrix(), c = s * n.scale;
1118
- let h = 0, l = 0, d = c / 2;
1119
- do
1120
- d *= 2, h = e.canvas.width / d, l = e.canvas.height / d;
1121
- while (h * l > 1e4);
1122
- const u = n.dx - Math.floor(n.dx / d) * d, g = n.dy - Math.floor(n.dy / d) * d, y = o * n.scale, w = 2 * Math.PI, v = u - d, m = g - d, f = e.canvas.width + u, p = e.canvas.height + g;
1118
+ const c = t.getContentMatrix(), a = s * c.scale, d = e.canvas.width / a, l = e.canvas.height / a;
1119
+ if (d * l > h)
1120
+ return;
1121
+ const u = c.dx - Math.floor(c.dx / a) * a, w = c.dy - Math.floor(c.dy / a) * a, v = o * c.scale, p = 2 * Math.PI, f = u - a, m = w - a, x = e.canvas.width + u, y = e.canvas.height + w;
1123
1122
  e.fillStyle = r;
1124
- for (let x = v; x <= f; x += d)
1125
- for (let A = m; A <= p; A += d)
1126
- e.beginPath(), e.arc(x, A, y, 0, w), e.closePath(), e.fill();
1127
- }, wt = (e, t, r, s) => (o, i) => {
1128
- gt(
1129
- o,
1123
+ for (let C = f; C <= x; C += a)
1124
+ for (let A = m; A <= y; A += a)
1125
+ e.beginPath(), e.arc(C, A, v, 0, p), e.closePath(), e.fill();
1126
+ }, Pt = (e, t, r, s, o) => (i, h) => {
1127
+ St(
1130
1128
  i,
1129
+ h,
1131
1130
  e,
1132
1131
  t,
1133
1132
  r,
1134
- s
1133
+ s,
1134
+ o
1135
1135
  );
1136
- }, mt = (e) => {
1136
+ }, Nt = (e) => {
1137
1137
  switch (e == null ? void 0 : e.type) {
1138
1138
  case "custom":
1139
1139
  return e.drawingFn;
1140
1140
  case "dots":
1141
- return wt(
1141
+ return Pt(
1142
1142
  e.dotColor ?? "#d8d8d8",
1143
1143
  e.dotGap ?? 25,
1144
1144
  e.dotRadius ?? 1.5,
1145
- e.color ?? "#ffffff"
1145
+ e.color ?? "#ffffff",
1146
+ e.limit ?? 1e4
1146
1147
  );
1147
1148
  default:
1148
- return ut();
1149
- }
1150
- }, G = (e) => {
1149
+ return Mt();
1150
+ }
1151
+ }, g = {
1152
+ edgeColor: "#5c5c5c",
1153
+ edgeWidth: 1,
1154
+ edgeArrowLength: 15,
1155
+ edgeArrowWidth: 4,
1156
+ edgeArrowOffset: 15,
1157
+ hasSourceArrow: !1,
1158
+ hasTargetArrow: !1,
1159
+ cycleSize: 30,
1160
+ roundness: 10,
1161
+ detourDistance: 100,
1162
+ detourDirection: -Math.PI / 2,
1163
+ smallCycleSize: 15,
1164
+ curvature: 90
1165
+ }, j = (e) => {
1151
1166
  switch (e == null ? void 0 : e.type) {
1152
1167
  case "custom":
1153
- return e.controllerFactory;
1168
+ return e.factory;
1154
1169
  case "straight":
1155
- return at({
1156
- color: e.color ?? "#5c5c5c",
1157
- width: e.width ?? 1,
1158
- arrowLength: e.arrowLength ?? 15,
1159
- arrowWidth: e.arrowWidth ?? 4,
1160
- arrowOffset: e.arrowOffset ?? 15,
1161
- hasSourceArrow: e.hasSourceArrow ?? !1,
1162
- hasTargetArrow: e.hasTargetArrow ?? !1,
1163
- cycleSquareSide: e.cycleSquareSide ?? 30,
1164
- roundness: e.roundness ?? 10,
1165
- detourDistance: e.detourDistance ?? 100,
1166
- detourDirection: e.detourDirection ?? -Math.PI / 2
1170
+ return gt({
1171
+ color: e.color ?? g.edgeColor,
1172
+ width: e.width ?? g.edgeWidth,
1173
+ arrowLength: e.arrowLength ?? g.edgeArrowLength,
1174
+ arrowWidth: e.arrowWidth ?? g.edgeArrowWidth,
1175
+ arrowOffset: e.arrowOffset ?? g.edgeArrowOffset,
1176
+ hasSourceArrow: e.hasSourceArrow ?? g.hasSourceArrow,
1177
+ hasTargetArrow: e.hasTargetArrow ?? g.hasTargetArrow,
1178
+ cycleSquareSide: e.cycleSquareSide ?? g.cycleSize,
1179
+ roundness: e.roundness ?? g.roundness,
1180
+ detourDistance: e.detourDistance ?? g.detourDistance,
1181
+ detourDirection: e.detourDirection ?? g.detourDirection
1167
1182
  });
1168
1183
  case "horizontal":
1169
- return ht({
1170
- color: e.color ?? "#5c5c5c",
1171
- width: e.width ?? 1,
1172
- arrowLength: e.arrowLength ?? 15,
1173
- arrowWidth: e.arrowWidth ?? 4,
1174
- arrowOffset: e.arrowOffset ?? 15,
1175
- hasSourceArrow: e.hasSourceArrow ?? !1,
1176
- hasTargetArrow: e.hasTargetArrow ?? !1,
1177
- cycleSquareSide: e.cycleSquareSide ?? 30,
1178
- roundness: e.roundness ?? 10,
1179
- detourDistance: e.detourDistance ?? 100,
1180
- detourDirection: e.detourDirection ?? -Math.PI / 2
1184
+ return wt({
1185
+ color: e.color ?? g.edgeColor,
1186
+ width: e.width ?? g.edgeWidth,
1187
+ arrowLength: e.arrowLength ?? g.edgeArrowLength,
1188
+ arrowWidth: e.arrowWidth ?? g.edgeArrowWidth,
1189
+ arrowOffset: e.arrowOffset ?? g.edgeArrowOffset,
1190
+ hasSourceArrow: e.hasSourceArrow ?? g.hasSourceArrow,
1191
+ hasTargetArrow: e.hasTargetArrow ?? g.hasTargetArrow,
1192
+ cycleSquareSide: e.cycleSquareSide ?? g.cycleSize,
1193
+ roundness: e.roundness ?? g.roundness,
1194
+ detourDistance: e.detourDistance ?? g.detourDistance,
1195
+ detourDirection: e.detourDirection ?? g.detourDirection
1181
1196
  });
1182
1197
  case "vertical":
1183
- return ct({
1184
- color: e.color ?? "#5c5c5c",
1185
- width: e.width ?? 1,
1186
- arrowLength: e.arrowLength ?? 15,
1187
- arrowWidth: e.arrowWidth ?? 4,
1188
- arrowOffset: e.arrowOffset ?? 15,
1189
- hasSourceArrow: e.hasSourceArrow ?? !1,
1190
- hasTargetArrow: e.hasTargetArrow ?? !1,
1191
- cycleSquareSide: e.cycleSquareSide ?? 30,
1192
- roundness: e.roundness ?? 10,
1193
- detourDistance: e.detourDistance ?? 100,
1194
- detourDirection: e.detourDirection ?? -Math.PI / 2
1198
+ return pt({
1199
+ color: e.color ?? g.edgeColor,
1200
+ width: e.width ?? g.edgeWidth,
1201
+ arrowLength: e.arrowLength ?? g.edgeArrowLength,
1202
+ arrowWidth: e.arrowWidth ?? g.edgeArrowWidth,
1203
+ arrowOffset: e.arrowOffset ?? g.edgeArrowOffset,
1204
+ hasSourceArrow: e.hasSourceArrow ?? g.hasSourceArrow,
1205
+ hasTargetArrow: e.hasTargetArrow ?? g.hasTargetArrow,
1206
+ cycleSquareSide: e.cycleSquareSide ?? g.cycleSize,
1207
+ roundness: e.roundness ?? g.roundness,
1208
+ detourDistance: e.detourDistance ?? g.detourDistance,
1209
+ detourDirection: e.detourDirection ?? g.detourDirection
1195
1210
  });
1196
1211
  default:
1197
- return nt({
1198
- color: e.color ?? "#5c5c5c",
1199
- width: e.width ?? 1,
1200
- curvature: e.curvature ?? 90,
1201
- arrowLength: e.arrowLength ?? 15,
1202
- arrowWidth: e.arrowWidth ?? 4,
1203
- hasSourceArrow: e.hasSourceArrow ?? !1,
1204
- hasTargetArrow: e.hasTargetArrow ?? !1,
1205
- cycleRadius: e.cycleRadius ?? 30,
1206
- smallCycleRadius: e.smallCycleRadius ?? 15,
1207
- detourDistance: e.detourDistance ?? 100,
1208
- detourDirection: e.detourDirection ?? -Math.PI / 2
1212
+ return ut({
1213
+ color: e.color ?? g.edgeColor,
1214
+ width: e.width ?? g.edgeWidth,
1215
+ arrowLength: e.arrowLength ?? g.edgeArrowLength,
1216
+ arrowWidth: e.arrowWidth ?? g.edgeArrowWidth,
1217
+ hasSourceArrow: e.hasSourceArrow ?? g.hasSourceArrow,
1218
+ hasTargetArrow: e.hasTargetArrow ?? g.hasTargetArrow,
1219
+ cycleRadius: e.cycleRadius ?? g.cycleSize,
1220
+ detourDistance: e.detourDistance ?? g.detourDistance,
1221
+ detourDirection: e.detourDirection ?? g.detourDirection,
1222
+ smallCycleRadius: e.smallCycleRadius ?? g.smallCycleSize,
1223
+ curvature: e.curvature ?? g.curvature
1209
1224
  });
1210
1225
  }
1211
- }, O = (e) => () => e, z = O(0), W = () => {
1226
+ }, H = (e) => () => e, Z = H(0), G = () => {
1212
1227
  let e = 0;
1213
1228
  return () => e++;
1214
- }, pt = (e, t) => {
1229
+ }, bt = (e, t) => {
1215
1230
  const r = [
1216
- z,
1217
- z
1231
+ Z,
1232
+ Z
1218
1233
  ];
1219
- e === "incremental" && (r[0] = W()), t === "incremental" && (r[1] = W());
1220
- const s = W();
1221
- return e === "shared-incremental" && (r[0] = s), t === "shared-incremental" && (r[1] = s), typeof e == "number" && (r[0] = O(e)), typeof t == "number" && (r[1] = O(t)), typeof e == "function" && (r[0] = e), typeof t == "function" && (r[1] = t), r;
1222
- }, vt = (e) => {
1223
- var s, o, i, n, c, h;
1224
- const [t, r] = pt(
1234
+ e === "incremental" && (r[0] = G()), t === "incremental" && (r[1] = G());
1235
+ const s = G();
1236
+ return e === "shared-incremental" && (r[0] = s), t === "shared-incremental" && (r[1] = s), typeof e == "number" && (r[0] = H(e)), typeof t == "number" && (r[1] = H(t)), typeof e == "function" && (r[0] = e), typeof t == "function" && (r[1] = t), r;
1237
+ }, Tt = (e) => {
1238
+ var s, o, i, h, c, a;
1239
+ const [t, r] = bt(
1225
1240
  (s = e.nodes) == null ? void 0 : s.priority,
1226
1241
  (o = e.edges) == null ? void 0 : o.priority
1227
1242
  );
1228
1243
  return {
1229
1244
  background: {
1230
- drawingFn: mt(
1245
+ drawingFn: Nt(
1231
1246
  e.background ?? { type: "none" }
1232
1247
  )
1233
1248
  },
1234
1249
  nodes: {
1235
- centerFn: ((i = e.nodes) == null ? void 0 : i.centerFn) ?? X,
1250
+ centerFn: ((i = e.nodes) == null ? void 0 : i.centerFn) ?? Q,
1236
1251
  priorityFn: t
1237
1252
  },
1238
1253
  ports: {
1239
- centerFn: ((n = e.ports) == null ? void 0 : n.centerFn) ?? X,
1254
+ centerFn: ((h = e.ports) == null ? void 0 : h.centerFn) ?? Q,
1240
1255
  direction: ((c = e.ports) == null ? void 0 : c.direction) ?? 0
1241
1256
  },
1242
1257
  edges: {
1243
- shapeFactory: G(((h = e.edges) == null ? void 0 : h.shape) ?? {}),
1258
+ shapeFactory: j(((a = e.edges) == null ? void 0 : a.shape) ?? {}),
1244
1259
  priorityFn: r
1245
1260
  }
1246
1261
  };
1247
1262
  };
1248
- class yt {
1263
+ class Lt {
1249
1264
  constructor(t) {
1250
- a(this, "transformation");
1251
- a(this, "model");
1252
- a(this, "di");
1253
- a(this, "edgeShapeFactory");
1265
+ n(this, "transformation");
1266
+ n(this, "model");
1267
+ n(this, "di");
1268
+ n(this, "edgeShapeFactory");
1254
1269
  this.apiOptions = t;
1255
- const r = vt(this.apiOptions ?? {});
1256
- this.di = new dt(
1270
+ const r = Tt(this.apiOptions ?? {});
1271
+ this.di = new At(
1257
1272
  r.background.drawingFn,
1258
1273
  r.nodes.centerFn,
1259
1274
  r.ports.centerFn,
@@ -1295,13 +1310,17 @@ class yt {
1295
1310
  ), this;
1296
1311
  }
1297
1312
  updatePort(t, r) {
1298
- return this.di.canvasController.updatePort(t, r), this;
1313
+ return this.di.canvasController.updatePort(
1314
+ t,
1315
+ r.direction,
1316
+ r.centerFn
1317
+ ), this;
1299
1318
  }
1300
1319
  unmarkPort(t) {
1301
1320
  return this.di.canvasController.unmarkPort(t), this;
1302
1321
  }
1303
1322
  addEdge(t) {
1304
- const r = t.options !== void 0 ? G(t.options) : this.edgeShapeFactory;
1323
+ const r = t.shape !== void 0 ? j(t.shape) : this.edgeShapeFactory;
1305
1324
  return this.di.canvasController.addEdge(
1306
1325
  t.id,
1307
1326
  t.from,
@@ -1311,7 +1330,8 @@ class yt {
1311
1330
  ), this;
1312
1331
  }
1313
1332
  updateEdge(t, r) {
1314
- return this.di.canvasController.updateEdge(t, r), this;
1333
+ const s = r.shape !== void 0 ? j(r.shape) : void 0;
1334
+ return this.di.canvasController.updateEdge(t, s, r.priority), this;
1315
1335
  }
1316
1336
  removeEdge(t) {
1317
1337
  return this.di.canvasController.removeEdge(t), this;
@@ -1343,81 +1363,97 @@ class yt {
1343
1363
  this.di.canvasController.destroy();
1344
1364
  }
1345
1365
  }
1346
- class ft {
1366
+ const z = (e, t, r) => {
1367
+ const { x: s, y: o, width: i, height: h } = e.getBoundingClientRect();
1368
+ return t >= s && t < s + i && r >= o && r <= o + h;
1369
+ }, I = (e, t, r) => t >= 0 && t < e.innerWidth && r >= 0 && r <= e.innerHeight, B = (e, t) => {
1370
+ t !== null ? e.style.cursor = t : e.style.removeProperty("cursor");
1371
+ };
1372
+ class $t {
1347
1373
  constructor(t, r) {
1348
- a(this, "model");
1349
- a(this, "transformation");
1350
- a(this, "maxNodePriority", 0);
1351
- a(this, "nodes", /* @__PURE__ */ new Map());
1352
- a(this, "grabbedNodeId", null);
1353
- a(this, "onNodeDrag");
1354
- a(this, "onBeforeNodeDrag");
1355
- a(this, "nodeIdGenerator", new D());
1356
- a(this, "element", null);
1357
- a(this, "onCanvasMouseUp", () => {
1358
- this.setCursor(null), this.grabbedNodeId = null;
1374
+ n(this, "model");
1375
+ n(this, "transformation");
1376
+ n(this, "maxNodePriority", 0);
1377
+ n(this, "nodes", /* @__PURE__ */ new Map());
1378
+ n(this, "grabbedNodeId", null);
1379
+ n(this, "onNodeDrag");
1380
+ n(this, "onBeforeNodeDrag");
1381
+ n(this, "nodeIdGenerator", new X(
1382
+ (t) => this.nodes.has(t)
1383
+ ));
1384
+ n(this, "element", null);
1385
+ n(this, "onCanvasMouseUp", () => {
1386
+ this.cancelMouseDrag();
1359
1387
  });
1360
- a(this, "onCanvasMouseMove", (t) => {
1361
- this.grabbedNodeId !== null && (t.stopPropagation(), this.dragNode(this.grabbedNodeId, t.movementX, t.movementY));
1388
+ n(this, "onCanvasMouseMove", (t) => {
1389
+ if (this.element !== null && (!z(this.element, t.clientX, t.clientY) || !I(this.window, t.clientX, t.clientY))) {
1390
+ this.cancelMouseDrag();
1391
+ return;
1392
+ }
1393
+ this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, t.movementX, t.movementY);
1362
1394
  });
1363
- a(this, "onCanvasTouchStart", (t) => {
1395
+ n(this, "onCanvasTouchStart", (t) => {
1364
1396
  this.previousTouchCoords = [
1365
1397
  t.touches[0].clientX,
1366
1398
  t.touches[0].clientY
1367
1399
  ];
1368
1400
  });
1369
- a(this, "onCanvasTouchMove", (t) => {
1370
- if (this.grabbedNodeId === null || t.touches.length !== 1 || this.previousTouchCoords === null)
1371
- return;
1372
- t.stopImmediatePropagation();
1373
- const [r, s] = [
1374
- t.touches[0].clientX - this.previousTouchCoords[0],
1375
- t.touches[0].clientY - this.previousTouchCoords[1]
1376
- ];
1377
- this.dragNode(this.grabbedNodeId, r, s), this.previousTouchCoords = [
1378
- t.touches[0].clientX,
1379
- t.touches[0].clientY
1380
- ];
1401
+ n(this, "onCanvasTouchMove", (t) => {
1402
+ if (t.touches.length === 1) {
1403
+ const r = t.touches[0];
1404
+ if (this.element !== null && (!z(this.element, r.clientX, r.clientY) || !I(this.window, r.clientX, r.clientY))) {
1405
+ this.cancelTouchDrag();
1406
+ return;
1407
+ }
1408
+ if (this.grabbedNodeId !== null && this.previousTouchCoords !== null) {
1409
+ t.stopImmediatePropagation();
1410
+ const s = r.clientX - this.previousTouchCoords[0], o = r.clientY - this.previousTouchCoords[1];
1411
+ this.dragNode(this.grabbedNodeId, s, o), this.previousTouchCoords = [
1412
+ t.touches[0].clientX,
1413
+ t.touches[0].clientY
1414
+ ];
1415
+ }
1416
+ }
1381
1417
  });
1382
- a(this, "onCanvasTouchEnd", (t) => {
1418
+ n(this, "onCanvasTouchEnd", (t) => {
1383
1419
  t.touches.length > 0 ? this.previousTouchCoords = [
1384
1420
  t.touches[0].clientX,
1385
1421
  t.touches[0].clientY
1386
- ] : (this.previousTouchCoords = null, this.grabbedNodeId = null);
1422
+ ] : this.cancelTouchDrag();
1387
1423
  });
1388
- a(this, "previousTouchCoords", null);
1389
- a(this, "freezePriority");
1390
- var i, n;
1424
+ n(this, "previousTouchCoords", null);
1425
+ n(this, "freezePriority");
1426
+ n(this, "window", window);
1427
+ n(this, "dragCursor");
1428
+ var i, h;
1391
1429
  this.canvas = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1392
1430
  const s = () => {
1393
1431
  };
1394
1432
  this.onNodeDrag = ((i = r == null ? void 0 : r.events) == null ? void 0 : i.onNodeDrag) ?? s;
1395
1433
  const o = () => !0;
1396
- this.onBeforeNodeDrag = ((n = r == null ? void 0 : r.events) == null ? void 0 : n.onBeforeNodeDrag) ?? o, this.freezePriority = (r == null ? void 0 : r.grabPriorityStrategy) === "freeze";
1434
+ this.onBeforeNodeDrag = ((h = r == null ? void 0 : r.events) == null ? void 0 : h.onBeforeNodeDrag) ?? o, this.freezePriority = (r == null ? void 0 : r.grabPriorityStrategy) === "freeze", this.dragCursor = (r == null ? void 0 : r.dragCursor) !== void 0 ? r.dragCursor : "grab";
1397
1435
  }
1398
1436
  addNode(t) {
1399
- let r = t.id;
1400
- if (r === void 0)
1401
- do
1402
- r = this.nodeIdGenerator.create();
1403
- while (this.nodes.has(r));
1437
+ const r = this.nodeIdGenerator.create(t.id);
1404
1438
  this.canvas.addNode({ ...t, id: r }), this.updateMaxNodePriority(r);
1405
1439
  const s = (i) => {
1406
- const n = this.model.getNode(r);
1440
+ if (this.element === null)
1441
+ return;
1442
+ const h = this.model.getNode(r);
1407
1443
  this.onBeforeNodeDrag({
1408
1444
  nodeId: r,
1409
1445
  element: t.element,
1410
- x: n.x,
1411
- y: n.y
1412
- }) && (i.stopImmediatePropagation(), this.grabbedNodeId = r, this.setCursor("grab"), this.moveNodeOnTop(r));
1446
+ x: h.x,
1447
+ y: h.y
1448
+ }) && (i.stopImmediatePropagation(), this.grabbedNodeId = r, B(this.element, this.dragCursor), this.moveNodeOnTop(r), this.window.addEventListener("mouseup", this.onCanvasMouseUp), this.window.addEventListener("mousemove", this.onCanvasMouseMove));
1413
1449
  }, o = (i) => {
1414
- const n = this.model.getNode(r);
1450
+ const h = this.model.getNode(r);
1415
1451
  this.onBeforeNodeDrag({
1416
1452
  nodeId: r,
1417
1453
  element: t.element,
1418
- x: n.x,
1419
- y: n.y
1420
- }) && i.touches.length === 1 && (this.grabbedNodeId = r, this.moveNodeOnTop(r));
1454
+ x: h.x,
1455
+ y: h.y
1456
+ }) && i.touches.length === 1 && (this.grabbedNodeId = r, this.moveNodeOnTop(r), this.window.addEventListener("touchmove", this.onCanvasTouchMove), this.window.addEventListener("touchend", this.onCanvasTouchEnd), this.window.addEventListener("touchcancel", this.onCanvasTouchEnd));
1421
1457
  };
1422
1458
  return this.nodes.set(r, {
1423
1459
  element: t.element,
@@ -1462,25 +1498,22 @@ class ft {
1462
1498
  }), this.nodes.clear(), this.maxNodePriority = 0, this;
1463
1499
  }
1464
1500
  attach(t) {
1465
- return this.detach(), this.element = t, this.canvas.attach(this.element), this.element.addEventListener("mouseup", this.onCanvasMouseUp), this.element.addEventListener("mousemove", this.onCanvasMouseMove), this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.element.addEventListener("touchmove", this.onCanvasTouchMove), this.element.addEventListener("touchend", this.onCanvasTouchEnd), this.element.addEventListener("touchcancel", this.onCanvasTouchEnd), this;
1501
+ return this.detach(), this.element = t, this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.canvas.attach(this.element), this;
1466
1502
  }
1467
1503
  detach() {
1468
- return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mouseup", this.onCanvasMouseUp), this.element.removeEventListener("mousemove", this.onCanvasMouseMove), this.element.removeEventListener("touchstart", this.onCanvasTouchStart), this.element.removeEventListener("touchmove", this.onCanvasTouchMove), this.element.removeEventListener("touchend", this.onCanvasTouchEnd), this.element.removeEventListener("touchcancel", this.onCanvasTouchEnd), this.element = null), this;
1504
+ return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("touchstart", this.onCanvasTouchStart), this.element = null), this;
1469
1505
  }
1470
1506
  destroy() {
1471
- this.detach(), this.nodes.forEach((t) => {
1507
+ this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.nodes.forEach((t) => {
1472
1508
  t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart);
1473
1509
  }), this.nodes.clear(), this.canvas.destroy();
1474
1510
  }
1475
- setCursor(t) {
1476
- this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1477
- }
1478
1511
  dragNode(t, r, s) {
1479
1512
  const o = this.model.getNode(t);
1480
1513
  if (o === null)
1481
- throw new Error("failed to drag nonexisting node");
1482
- const i = this.canvas.transformation.getContentMatrix(), n = i.scale * o.x + i.dx, c = i.scale * o.y + i.dy, h = n + r, l = c + s, d = this.canvas.transformation.getViewportMatrix(), u = d.scale * h + d.dx, g = d.scale * l + d.dy;
1483
- this.canvas.updateNode(t, { x: u, y: g }), this.onNodeDrag({
1514
+ throw new S("failed to drag nonexisting node");
1515
+ const i = this.canvas.transformation.getContentMatrix(), h = i.scale * o.x + i.dx, c = i.scale * o.y + i.dy, a = h + r, d = c + s, l = this.canvas.transformation.getViewportMatrix(), u = l.scale * a + l.dx, w = l.scale * d + l.dy;
1516
+ this.canvas.updateNode(t, { x: u, y: w }), this.onNodeDrag({
1484
1517
  nodeId: t,
1485
1518
  element: o.element,
1486
1519
  x: o.x,
@@ -1496,31 +1529,43 @@ class ft {
1496
1529
  return;
1497
1530
  this.maxNodePriority += 2, this.updateNode(t, { priority: this.maxNodePriority });
1498
1531
  const r = this.maxNodePriority - 1;
1499
- this.model.getNodeAdjacentEdges(t).forEach((o) => {
1532
+ this.model.getNodeAdjacentEdgeIds(t).forEach((o) => {
1500
1533
  this.updateEdge(o, { priority: r });
1501
1534
  });
1502
1535
  }
1536
+ cancelMouseDrag() {
1537
+ this.grabbedNodeId = null, this.element !== null && B(this.element, null), this.removeMouseDragListeners();
1538
+ }
1539
+ removeMouseDragListeners() {
1540
+ this.window.removeEventListener("mouseup", this.onCanvasMouseUp), this.window.removeEventListener("mousemove", this.onCanvasMouseMove);
1541
+ }
1542
+ cancelTouchDrag() {
1543
+ this.previousTouchCoords = null, this.grabbedNodeId = null, this.removeTouchDragListeners();
1544
+ }
1545
+ removeTouchDragListeners() {
1546
+ this.window.removeEventListener("touchmove", this.onCanvasTouchMove), this.window.removeEventListener("touchend", this.onCanvasTouchEnd), this.window.removeEventListener("touchcancel", this.onCanvasTouchEnd);
1547
+ }
1503
1548
  }
1504
- const xt = () => {
1505
- }, Et = (e, t) => t, At = (e, t) => {
1549
+ const Dt = () => {
1550
+ }, Ft = (e, t) => t, Wt = (e, t) => {
1506
1551
  const r = t !== null ? 1 / t : null, s = e !== null ? 1 / e : null;
1507
1552
  return (o, i) => s !== null && i.scale > s && i.scale > o.scale || r !== null && i.scale < r && i.scale < o.scale ? o : i;
1508
- }, Ct = (e, t, r, s) => (o, i, n, c) => {
1509
- let h = i.dx, l = i.dy;
1510
- e !== null && h < e && h < o.dx && (h = o.dx);
1511
- const d = n * o.scale;
1512
- t !== null && h > t - d && h > o.dx && (h = o.dx), r !== null && l < r && l < o.dy && (l = o.dy);
1553
+ }, Vt = (e, t, r, s) => (o, i, h, c) => {
1554
+ let a = i.dx, d = i.dy;
1555
+ e !== null && a < e && a < o.dx && (a = o.dx);
1556
+ const l = h * o.scale;
1557
+ t !== null && a > t - l && a > o.dx && (a = o.dx), r !== null && d < r && d < o.dy && (d = o.dy);
1513
1558
  const u = c * o.scale;
1514
- return s !== null && l > s - u && l > o.dy && (l = o.dy), { scale: i.scale, dx: h, dy: l };
1515
- }, B = (e) => {
1559
+ return s !== null && d > s - u && d > o.dy && (d = o.dy), { scale: i.scale, dx: a, dy: d };
1560
+ }, q = (e) => {
1516
1561
  switch (e.type) {
1517
1562
  case "scale-limit":
1518
- return At(
1563
+ return Wt(
1519
1564
  e.minContentScale ?? null,
1520
1565
  e.maxContentScale ?? null
1521
1566
  );
1522
1567
  case "shift-limit":
1523
- return Ct(
1568
+ return Vt(
1524
1569
  e.minX ?? null,
1525
1570
  e.maxX ?? null,
1526
1571
  e.minY ?? null,
@@ -1529,61 +1574,71 @@ const xt = () => {
1529
1574
  default:
1530
1575
  return e.preprocessorFn;
1531
1576
  }
1532
- }, St = (e) => (t, r, s, o) => e.reduce(
1533
- (i, n) => n(t, i, s, o),
1577
+ }, Ot = (e) => (t, r, s, o) => e.reduce(
1578
+ (i, h) => h(t, i, s, o),
1534
1579
  r
1535
1580
  );
1536
- class Nt {
1581
+ class Rt {
1537
1582
  constructor(t, r) {
1538
- a(this, "model");
1539
- a(this, "transformation");
1540
- a(this, "element", null);
1541
- a(this, "isMoving", !1);
1542
- a(this, "prevTouches", null);
1543
- a(this, "onTransformFinished");
1544
- a(this, "transformPreprocessor");
1545
- a(this, "isScalable");
1546
- a(this, "isShiftable");
1547
- a(this, "wheelSensitivity");
1548
- a(this, "onMouseDown", () => {
1549
- this.setCursor("grab"), this.isMoving = !0;
1583
+ n(this, "model");
1584
+ n(this, "transformation");
1585
+ n(this, "element", null);
1586
+ n(this, "prevTouches", null);
1587
+ n(this, "onTransformFinished");
1588
+ n(this, "transformPreprocessor");
1589
+ n(this, "isScalable");
1590
+ n(this, "isShiftable");
1591
+ n(this, "wheelSensitivity");
1592
+ n(this, "window", window);
1593
+ n(this, "onMouseDown", () => {
1594
+ this.element !== null && (B(this.element, this.shiftCursor), this.window.addEventListener("mousemove", this.onMouseMove), this.window.addEventListener("mouseup", this.onMouseUp));
1550
1595
  });
1551
- a(this, "onMouseMove", (t) => {
1552
- if (!this.isMoving || !this.isShiftable)
1596
+ n(this, "onMouseMove", (t) => {
1597
+ if (!this.isShiftable || this.element === null)
1598
+ return;
1599
+ if (!z(this.element, t.clientX, t.clientY) || !I(this.window, t.clientX, t.clientY)) {
1600
+ this.stopMouseDrag();
1553
1601
  return;
1602
+ }
1554
1603
  const r = -t.movementX, s = -t.movementY;
1555
1604
  this.moveViewport(r, s);
1556
1605
  });
1557
- a(this, "onMouseUp", () => {
1558
- this.setCursor(null), this.isMoving = !1;
1606
+ n(this, "onMouseUp", () => {
1607
+ this.stopMouseDrag();
1559
1608
  });
1560
- a(this, "onWheelScroll", (t) => {
1609
+ n(this, "onWheelScroll", (t) => {
1561
1610
  if (this.element === null || this.isScalable === !1)
1562
1611
  return;
1563
1612
  t.preventDefault();
1564
1613
  const { left: r, top: s } = this.element.getBoundingClientRect(), o = t.clientX - r, i = t.clientY - s, c = 1 / (t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
1565
1614
  this.scaleViewport(c, o, i);
1566
1615
  });
1567
- a(this, "onTouchStart", (t) => {
1568
- this.prevTouches = this.getAverageTouch(t);
1616
+ n(this, "onTouchStart", (t) => {
1617
+ this.prevTouches = this.getAverageTouch(t), this.window.addEventListener("touchmove", this.onTouchMove), this.window.addEventListener("touchend", this.onTouchEnd), this.window.addEventListener("touchcancel", this.onTouchEnd);
1569
1618
  });
1570
- a(this, "onTouchMove", (t) => {
1571
- if (this.prevTouches === null || this.element === null || !this.isShiftable)
1619
+ n(this, "onTouchMove", (t) => {
1620
+ if (this.prevTouches === null || !this.isShiftable || this.element === null)
1572
1621
  return;
1573
1622
  const r = this.getAverageTouch(t);
1623
+ if (!r.touches.every(
1624
+ (o) => z(this.element, o[0], o[1]) && I(this.window, o[0], o[1])
1625
+ )) {
1626
+ this.stopTouchDrag();
1627
+ return;
1628
+ }
1574
1629
  if ((r.touchesCnt === 1 || r.touchesCnt === 2) && this.moveViewport(
1575
1630
  -(r.x - this.prevTouches.x),
1576
1631
  -(r.y - this.prevTouches.y)
1577
1632
  ), r.touchesCnt === 2 && this.isScalable) {
1578
- const { left: s, top: o } = this.element.getBoundingClientRect(), i = this.prevTouches.x - s, n = this.prevTouches.y - o, h = 1 / (r.scale / this.prevTouches.scale);
1579
- this.scaleViewport(h, i, n);
1633
+ const { left: o, top: i } = this.element.getBoundingClientRect(), h = this.prevTouches.x - o, c = this.prevTouches.y - i, d = 1 / (r.scale / this.prevTouches.scale);
1634
+ this.scaleViewport(d, h, c);
1580
1635
  }
1581
- this.prevTouches = r, t.preventDefault();
1636
+ this.prevTouches = r;
1582
1637
  });
1583
- a(this, "onTouchEnd", (t) => {
1584
- t.touches.length > 0 ? this.prevTouches = this.getAverageTouch(t) : this.prevTouches = null;
1638
+ n(this, "onTouchEnd", (t) => {
1639
+ t.touches.length > 0 ? this.prevTouches = this.getAverageTouch(t) : this.stopTouchDrag();
1585
1640
  });
1586
- a(this, "observer", new ResizeObserver(() => {
1641
+ n(this, "observer", new ResizeObserver(() => {
1587
1642
  if (this.element !== null) {
1588
1643
  const t = this.canvas.transformation.getViewportMatrix(), { width: r, height: s } = this.element.getBoundingClientRect(), o = this.transformPreprocessor(
1589
1644
  t,
@@ -1594,16 +1649,17 @@ class Nt {
1594
1649
  this.canvas.patchViewportMatrix(o), this.onTransformFinished(o);
1595
1650
  }
1596
1651
  }));
1597
- var i, n, c, h, l, d, u;
1598
- this.canvas = t, this.options = r, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((n = (i = this.options) == null ? void 0 : i.scale) == null ? void 0 : n.enabled) !== !1, this.isShiftable = ((h = (c = this.options) == null ? void 0 : c.shift) == null ? void 0 : h.enabled) !== !1;
1599
- const s = (d = (l = this.options) == null ? void 0 : l.scale) == null ? void 0 : d.wheelSensitivity;
1600
- this.wheelSensitivity = s !== void 0 ? s : 1.2, this.onTransformFinished = ((u = r == null ? void 0 : r.events) == null ? void 0 : u.onTransformFinished) ?? xt;
1652
+ n(this, "shiftCursor");
1653
+ var i, h, c, a, d, l, u, w;
1654
+ this.canvas = t, this.options = r, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((h = (i = this.options) == null ? void 0 : i.scale) == null ? void 0 : h.enabled) !== !1, this.isShiftable = ((a = (c = this.options) == null ? void 0 : c.shift) == null ? void 0 : a.enabled) !== !1;
1655
+ const s = (l = (d = this.options) == null ? void 0 : d.scale) == null ? void 0 : l.wheelSensitivity;
1656
+ this.wheelSensitivity = s !== void 0 ? s : 1.2, this.onTransformFinished = ((u = r == null ? void 0 : r.events) == null ? void 0 : u.onTransformFinished) ?? Dt;
1601
1657
  const o = r == null ? void 0 : r.transformPreprocessor;
1602
- o !== void 0 ? Array.isArray(o) ? this.transformPreprocessor = St(
1658
+ o !== void 0 ? Array.isArray(o) ? this.transformPreprocessor = Ot(
1603
1659
  o.map(
1604
- (g) => B(g)
1660
+ (v) => q(v)
1605
1661
  )
1606
- ) : this.transformPreprocessor = B(o) : this.transformPreprocessor = Et;
1662
+ ) : this.transformPreprocessor = q(o) : this.transformPreprocessor = Ft, this.shiftCursor = ((w = r == null ? void 0 : r.shift) == null ? void 0 : w.cursor) !== void 0 ? r.shift.cursor : "grab";
1607
1663
  }
1608
1664
  addNode(t) {
1609
1665
  return this.canvas.addNode(t), this;
@@ -1642,29 +1698,32 @@ class Nt {
1642
1698
  return this.canvas.clear(), this;
1643
1699
  }
1644
1700
  attach(t) {
1645
- return this.detach(), this.element = t, this.observer.observe(this.element), this.canvas.attach(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("mousemove", this.onMouseMove), this.element.addEventListener("mouseup", this.onMouseUp), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.element.addEventListener("touchmove", this.onTouchMove), this.element.addEventListener("touchend", this.onTouchEnd), this.element.addEventListener("touchcancel", this.onTouchEnd), this;
1701
+ return this.detach(), this.element = t, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.canvas.attach(this.element), this;
1646
1702
  }
1647
1703
  detach() {
1648
- return this.canvas.detach(), this.element !== null && (this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("mousemove", this.onMouseMove), this.element.removeEventListener("mouseup", this.onMouseUp), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("touchmove", this.onTouchMove), this.element.removeEventListener("touchend", this.onTouchEnd), this.element.removeEventListener("touchcancel", this.onTouchEnd), this.element = null), this;
1704
+ return this.canvas.detach(), this.element !== null && (this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element = null), this;
1649
1705
  }
1650
1706
  destroy() {
1651
- this.detach(), this.canvas.destroy();
1707
+ this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
1652
1708
  }
1653
1709
  getAverageTouch(t) {
1654
1710
  const r = [], s = t.touches.length;
1655
- for (let h = 0; h < s; h++)
1656
- r.push([t.touches[h].clientX, t.touches[h].clientY]);
1711
+ for (let a = 0; a < s; a++)
1712
+ r.push([t.touches[a].clientX, t.touches[a].clientY]);
1657
1713
  const o = r.reduce(
1658
- (h, l) => [h[0] + l[0], h[1] + l[1]],
1714
+ (a, d) => [a[0] + d[0], a[1] + d[1]],
1659
1715
  [0, 0]
1660
- ), i = [o[0] / s, o[1] / s], c = r.map((h) => [h[0] - i[0], h[1] - i[1]]).reduce(
1661
- (h, l) => h + Math.sqrt(l[0] * l[0] + l[1] * l[1]),
1716
+ ), i = [o[0] / s, o[1] / s], c = r.map((a) => [a[0] - i[0], a[1] - i[1]]).reduce(
1717
+ (a, d) => a + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
1662
1718
  0
1663
1719
  );
1664
- return { x: i[0], y: i[1], scale: c / s, touchesCnt: s };
1665
- }
1666
- setCursor(t) {
1667
- this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1720
+ return {
1721
+ x: i[0],
1722
+ y: i[1],
1723
+ scale: c / s,
1724
+ touchesCnt: s,
1725
+ touches: r
1726
+ };
1668
1727
  }
1669
1728
  moveViewport(t, r) {
1670
1729
  const s = this.transformation.getViewportMatrix(), o = {
@@ -1673,39 +1732,50 @@ class Nt {
1673
1732
  dy: s.dy + s.scale * r
1674
1733
  };
1675
1734
  if (this.element !== null) {
1676
- const { width: i, height: n } = this.element.getBoundingClientRect(), c = this.transformPreprocessor(
1735
+ const { width: i, height: h } = this.element.getBoundingClientRect(), c = this.transformPreprocessor(
1677
1736
  s,
1678
1737
  o,
1679
1738
  i,
1680
- n
1739
+ h
1681
1740
  );
1682
1741
  this.canvas.patchViewportMatrix(c), this.onTransformFinished(c);
1683
1742
  }
1684
1743
  }
1685
1744
  scaleViewport(t, r, s) {
1745
+ if (this.element === null)
1746
+ return;
1686
1747
  const o = this.canvas.transformation.getViewportMatrix(), i = {
1687
1748
  scale: o.scale * t,
1688
1749
  dx: o.scale * (1 - t) * r + o.dx,
1689
1750
  dy: o.scale * (1 - t) * s + o.dy
1690
- };
1691
- if (this.element !== null) {
1692
- const { width: n, height: c } = this.element.getBoundingClientRect(), h = this.transformPreprocessor(
1693
- o,
1694
- i,
1695
- n,
1696
- c
1697
- );
1698
- this.canvas.patchViewportMatrix(h), this.onTransformFinished(h);
1699
- }
1751
+ }, { width: h, height: c } = this.element.getBoundingClientRect(), a = this.transformPreprocessor(
1752
+ o,
1753
+ i,
1754
+ h,
1755
+ c
1756
+ );
1757
+ this.canvas.patchViewportMatrix(a), this.onTransformFinished(a);
1758
+ }
1759
+ stopMouseDrag() {
1760
+ this.element !== null && B(this.element, null), this.removeMouseDragListeners();
1761
+ }
1762
+ removeMouseDragListeners() {
1763
+ this.window.removeEventListener("mousemove", this.onMouseMove), this.window.removeEventListener("mouseup", this.onMouseUp);
1764
+ }
1765
+ stopTouchDrag() {
1766
+ this.prevTouches = null, this.removeTouchDragListeners();
1767
+ }
1768
+ removeTouchDragListeners() {
1769
+ this.window.removeEventListener("touchmove", this.onTouchMove), this.window.removeEventListener("touchend", this.onTouchEnd), this.window.removeEventListener("touchcancel", this.onTouchEnd);
1700
1770
  }
1701
1771
  }
1702
- class Mt {
1772
+ class kt {
1703
1773
  constructor() {
1704
- a(this, "coreOptions");
1705
- a(this, "dragOptions");
1706
- a(this, "transformOptions");
1707
- a(this, "isDraggable", !1);
1708
- a(this, "isTransformable", !1);
1774
+ n(this, "coreOptions");
1775
+ n(this, "dragOptions");
1776
+ n(this, "transformOptions");
1777
+ n(this, "isDraggable", !1);
1778
+ n(this, "isTransformable", !1);
1709
1779
  }
1710
1780
  setOptions(t) {
1711
1781
  return this.coreOptions = t, this;
@@ -1717,25 +1787,26 @@ class Mt {
1717
1787
  return this.isTransformable = !0, this.transformOptions = t, this;
1718
1788
  }
1719
1789
  build() {
1720
- let t = new yt(this.coreOptions);
1721
- return this.isDraggable && (t = new ft(t, this.dragOptions)), this.isTransformable && (t = new Nt(t, this.transformOptions)), t;
1790
+ let t = new Lt(this.coreOptions);
1791
+ return this.isDraggable && (t = new $t(t, this.dragOptions)), this.isTransformable && (t = new Rt(t, this.transformOptions)), t;
1722
1792
  }
1723
1793
  }
1724
1794
  export {
1725
- tt as BezierEdgeShape,
1726
- yt as CanvasCore,
1727
- ot as CycleCircleEdgeShape,
1728
- k as CycleSquareEdgeShape,
1729
- R as DetourStraightEdgeShape,
1730
- b as EdgeType,
1731
- rt as HorizontalEdgeShape,
1732
- Mt as HtmlGraphBuilder,
1733
- et as StraightEdgeShape,
1734
- ft as UserDraggableNodesCanvas,
1735
- Nt as UserTransformableCanvas,
1736
- st as VerticalEdgeShape,
1737
- nt as createBezierEdgeShapeFactory,
1738
- ht as createHorizontalEdgeShapeFactory,
1739
- at as createStraightEdgeShareFactory,
1740
- ct as createVerticalEdgeShapeFactory
1795
+ nt as BezierEdgeShape,
1796
+ Lt as CanvasCore,
1797
+ dt as CycleCircleEdgeShape,
1798
+ U as CycleSquareEdgeShape,
1799
+ _ as DetourStraightEdgeShape,
1800
+ T as EdgeType,
1801
+ ht as HorizontalEdgeShape,
1802
+ kt as HtmlGraphBuilder,
1803
+ S as HtmlGraphError,
1804
+ at as StraightEdgeShape,
1805
+ $t as UserDraggableNodesCanvas,
1806
+ Rt as UserTransformableCanvas,
1807
+ ct as VerticalEdgeShape,
1808
+ ut as createBezierEdgeShapeFactory,
1809
+ wt as createHorizontalEdgeShapeFactory,
1810
+ gt as createStraightEdgeShareFactory,
1811
+ pt as createVerticalEdgeShapeFactory
1741
1812
  };