@html-graph/html-graph 0.0.54 → 0.0.56

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