@html-graph/html-graph 0.0.50 → 0.0.51

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,8 +1,8 @@
1
- var j = Object.defineProperty;
2
- var R = (r, t, e) => t in r ? j(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var n = (r, t, e) => R(r, typeof t != "symbol" ? t + "" : t, e);
4
- class W {
5
- constructor(t, e, s, o, a) {
1
+ var W = Object.defineProperty;
2
+ var j = (r, t, e) => t in r ? W(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var n = (r, t, e) => j(r, typeof t != "symbol" ? t + "" : t, e);
4
+ class R {
5
+ constructor(t, e, s, o, i) {
6
6
  n(this, "canvasWrapper", null);
7
7
  n(this, "host");
8
8
  n(this, "nodesContainer");
@@ -58,11 +58,11 @@ class W {
58
58
  }
59
59
  }
60
60
  });
61
- this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer = s, this.layersMode = o, this.backgroundDrawingFn = a, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.edgesContainer = this.createEdgesContainer();
62
- const c = this.canvas.getContext("2d");
63
- if (c === null)
61
+ this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer = s, this.layersMode = o, this.backgroundDrawingFn = i, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.edgesContainer = this.createEdgesContainer();
62
+ const h = this.canvas.getContext("2d");
63
+ if (h === null)
64
64
  throw new Error("unable to get canvas context");
65
- this.canvasCtx = c, this.host.appendChild(this.canvas), this.layers[this.layersMode].create(), this.hostResizeObserver = this.createHostResizeObserver(), this.hostResizeObserver.observe(this.host), this.nodesResizeObserver = this.createNodesResizeObserver();
65
+ this.canvasCtx = h, this.host.appendChild(this.canvas), this.layers[this.layersMode].create(), this.hostResizeObserver = this.createHostResizeObserver(), this.hostResizeObserver.observe(this.host), this.nodesResizeObserver = this.createNodesResizeObserver();
66
66
  }
67
67
  clear() {
68
68
  Array.from(this.edgeIdToElementMap.keys()).forEach((t) => {
@@ -145,9 +145,9 @@ class W {
145
145
  createNodesResizeObserver() {
146
146
  return new ResizeObserver((t) => {
147
147
  t.forEach((e) => {
148
- const s = e.target, o = this.nodeWrapperElementToIdMap.get(s), a = this.graphStore.getNode(o);
149
- this.updateNodeCoords(o, a.x, a.y), this.graphStore.getNodeAdjacentEdges(o).forEach((h) => {
150
- this.updateEdgeCoords(h);
148
+ const s = e.target, o = this.nodeWrapperElementToIdMap.get(s), i = this.graphStore.getNode(o);
149
+ this.updateNodeCoords(o, i.x, i.y), this.graphStore.getNodeAdjacentEdges(o).forEach((a) => {
150
+ this.updateEdgeCoords(a);
151
151
  });
152
152
  });
153
153
  });
@@ -157,24 +157,24 @@ class W {
157
157
  this.canvas.width = t, this.canvas.height = e;
158
158
  }
159
159
  updateNodeCoords(t, e, s) {
160
- const o = this.nodeIdToWrapperElementMap.get(t), { width: a, height: c } = o.getBoundingClientRect(), h = this.viewportTransformer.getAbsScale(), i = this.graphStore.getNode(t), [d, g] = i.centerFn(a, c);
161
- o.style.transform = `matrix(1, 0, 0, 1, ${e - h * d}, ${s - h * g})`;
160
+ const o = this.nodeIdToWrapperElementMap.get(t), { width: i, height: h } = o.getBoundingClientRect(), a = this.viewportTransformer.getAbsScale(), c = this.graphStore.getNode(t), [l, d] = c.centerFn(i, h);
161
+ o.style.transform = `matrix(1, 0, 0, 1, ${e - a * l}, ${s - a * d})`;
162
162
  }
163
163
  updateEdgeCoords(t) {
164
- const e = this.graphStore.getEdge(t), s = this.graphStore.getPort(e.from), o = this.graphStore.getPort(e.to), a = s.element.getBoundingClientRect(), c = o.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), [i, d] = this.viewportTransformer.getAbsCoords(
165
- a.left - h.left,
166
- a.top - h.top
167
- ), [g, l] = this.viewportTransformer.getAbsCoords(
168
- c.left - h.left,
169
- c.top - h.top
170
- ), u = this.viewportTransformer.getAbsScale(), [v, m] = s.centerFn(
171
- a.width * u,
172
- a.height * u
173
- ), [w, f] = o.centerFn(
174
- c.width * u,
175
- c.height * u
176
- ), C = v + i, E = m + d, b = w + g, $ = f + l, y = Math.min(C, b), T = Math.min(E, $), S = Math.abs(b - C), N = Math.abs($ - E);
177
- e.controller.update(y, T, S, N, s, o);
164
+ const e = this.graphStore.getEdge(t), s = this.graphStore.getPort(e.from), o = this.graphStore.getPort(e.to), i = s.element.getBoundingClientRect(), h = o.element.getBoundingClientRect(), a = this.host.getBoundingClientRect(), [c, l] = this.viewportTransformer.getAbsCoords(
165
+ i.left - a.left,
166
+ i.top - a.top
167
+ ), [d, u] = this.viewportTransformer.getAbsCoords(
168
+ h.left - a.left,
169
+ h.top - a.top
170
+ ), g = this.viewportTransformer.getAbsScale(), [w, m] = s.centerFn(
171
+ i.width * g,
172
+ i.height * g
173
+ ), [f, p] = o.centerFn(
174
+ h.width * g,
175
+ h.height * g
176
+ ), C = w + c, v = m + l, E = f + d, A = p + u, y = Math.min(C, E), x = Math.min(v, A), P = Math.abs(E - C), M = Math.abs(A - v);
177
+ e.controller.update(y, x, P, M, s, o);
178
178
  }
179
179
  }
180
180
  class B {
@@ -211,7 +211,7 @@ class B {
211
211
  };
212
212
  }
213
213
  }
214
- class z {
214
+ class Y {
215
215
  constructor(t) {
216
216
  this.transformer = t;
217
217
  }
@@ -244,7 +244,7 @@ class z {
244
244
  return this.transformer.getAbsScale();
245
245
  }
246
246
  }
247
- class Y {
247
+ class X {
248
248
  constructor() {
249
249
  n(this, "nodes", /* @__PURE__ */ Object.create(null));
250
250
  n(this, "ports", /* @__PURE__ */ Object.create(null));
@@ -255,8 +255,8 @@ class Y {
255
255
  n(this, "outcommingEdges", /* @__PURE__ */ Object.create(null));
256
256
  n(this, "cycleEdges", /* @__PURE__ */ Object.create(null));
257
257
  }
258
- addNode(t, e, s, o, a) {
259
- this.nodes[t] = { element: e, x: s, y: o, centerFn: a }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
258
+ addNode(t, e, s, o, i) {
259
+ this.nodes[t] = { element: e, x: s, y: o, centerFn: i }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
260
260
  }
261
261
  hasNode(t) {
262
262
  return this.nodes[t] !== void 0;
@@ -279,10 +279,10 @@ class Y {
279
279
  delete this.portNodeId[o];
280
280
  }), delete this.nodePorts[t];
281
281
  }
282
- addPort(t, e, s, o, a) {
283
- this.ports[t] = { element: e, centerFn: o, direction: a }, this.cycleEdges[t] = {}, this.incommingEdges[t] = {}, this.outcommingEdges[t] = {}, this.portNodeId[t] = s;
284
- const c = this.nodePorts[s];
285
- c !== void 0 && (c[t] = e);
282
+ addPort(t, e, s, o, i) {
283
+ this.ports[t] = { element: e, centerFn: o, direction: i }, this.cycleEdges[t] = {}, this.incommingEdges[t] = {}, this.outcommingEdges[t] = {}, this.portNodeId[t] = s;
284
+ const h = this.nodePorts[s];
285
+ h !== void 0 && (h[t] = e);
286
286
  }
287
287
  getPort(t) {
288
288
  return this.ports[t];
@@ -371,71 +371,52 @@ class Y {
371
371
  }), s;
372
372
  }
373
373
  }
374
- class p {
375
- static getPortCenter(t) {
376
- const { top: e, left: s, width: o, height: a } = t.element.getBoundingClientRect(), c = t.centerFn(o, a);
377
- return [s + c[0], e + c[1]];
378
- }
379
- static rotate(t, e, s) {
380
- return [
381
- e[0] * t[0] - e[1] * t[1] + ((1 - e[0]) * s[0] + e[1] * s[1]),
382
- e[1] * t[0] + e[0] * t[1] + ((1 - e[0]) * s[1] - e[1] * s[0])
383
- ];
384
- }
385
- static getDirectionVector(t, e, s) {
386
- return [e * Math.cos(t ?? 0), s * Math.sin(t ?? 0)];
387
- }
388
- static getArrowPath(t, e, s, o, a) {
389
- const h = [
390
- [0, 0],
391
- [o, a],
392
- [o, -a]
393
- ].map((l) => this.rotate(l, t, [0, 0])).map((l) => [l[0] + e, l[1] + s]), i = `M ${h[0][0]} ${h[0][1]}`, d = `L ${h[1][0]} ${h[1][1]}`, g = `L ${h[2][0]} ${h[2][1]}`;
394
- return `${i} ${d} ${g}`;
395
- }
396
- static getArrowOffsetPath(t, e, s, o, a) {
397
- const h = [
398
- [o, 0],
399
- [o + a, 0]
400
- ].map((i) => this.rotate(i, t, [0, 0])).map((i) => [i[0] + e, i[1] + s]);
401
- return `M ${h[0][0]} ${h[0][1]} L ${h[1][0]} ${h[1][1]}`;
402
- }
403
- static createStraightPath(t) {
404
- return t.map((e, s) => `${s === 0 ? "M" : "L"} ${e[0]} ${e[1]}`).join(" ");
405
- }
406
- }
407
- class G {
408
- constructor(t, e, s, o, a, c, h) {
374
+ const $ = (r) => {
375
+ const { top: t, left: e, width: s, height: o } = r.element.getBoundingClientRect(), i = r.centerFn(s, o);
376
+ return [e + i[0], t + i[1]];
377
+ }, b = (r, t, e) => [
378
+ t[0] * r[0] - t[1] * r[1] + ((1 - t[0]) * e[0] + t[1] * e[1]),
379
+ t[1] * r[0] + t[0] * r[1] + ((1 - t[0]) * e[1] - t[1] * e[0])
380
+ ], N = (r, t, e) => [t * Math.cos(r), e * Math.sin(r)], S = (r, t, e, s, o) => {
381
+ const h = [
382
+ [0, 0],
383
+ [s, o],
384
+ [s, -o]
385
+ ].map((d) => b(d, r, [0, 0])).map((d) => [d[0] + t, d[1] + e]), a = `M ${h[0][0]} ${h[0][1]}`, c = `L ${h[1][0]} ${h[1][1]}`, l = `L ${h[2][0]} ${h[2][1]}`;
386
+ return `${a} ${c} ${l}`;
387
+ };
388
+ class z {
389
+ constructor(t, e, s, o, i, h, a) {
409
390
  n(this, "svg");
410
391
  n(this, "group");
411
392
  n(this, "line");
412
393
  n(this, "sourceArrow", null);
413
394
  n(this, "targetArrow", null);
414
- this.color = t, this.width = e, this.curvature = s, this.arrowLength = o, this.arrowWidth = a, 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%", c && (this.sourceArrow = document.createElementNS(
395
+ this.color = t, this.width = e, 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%", h && (this.sourceArrow = document.createElementNS(
415
396
  "http://www.w3.org/2000/svg",
416
397
  "path"
417
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = document.createElementNS(
398
+ ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = document.createElementNS(
418
399
  "http://www.w3.org/2000/svg",
419
400
  "path"
420
401
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
421
402
  }
422
- update(t, e, s, o, a, c) {
403
+ update(t, e, s, o, i, h) {
423
404
  this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`;
424
- const h = p.getPortCenter(a), i = p.getPortCenter(c), d = h[0] <= i[0] ? 1 : -1, g = h[1] <= i[1] ? 1 : -1;
425
- this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${d}, ${g})`;
426
- const l = p.getDirectionVector(a.direction, d, g), u = p.getDirectionVector(c.direction, d, g), v = p.rotate([this.arrowLength, 0], l, [0, 0]), m = p.rotate([s - this.arrowLength, o], u, [
405
+ const a = $(i), c = $(h), l = a[0] <= c[0] ? 1 : -1, d = a[1] <= c[1] ? 1 : -1;
406
+ this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${d})`;
407
+ const u = N(i.direction, l, d), g = N(h.direction, l, d), w = b([this.arrowLength, 0], u, [0, 0]), m = b([s - this.arrowLength, o], g, [
427
408
  s,
428
409
  o
429
- ]), w = [
430
- v[0] + l[0] * this.curvature,
431
- v[1] + l[1] * this.curvature
432
- ], f = [
433
- m[0] - u[0] * this.curvature,
434
- m[1] - u[1] * this.curvature
435
- ], C = `M ${v[0]} ${v[1]} C ${w[0]} ${w[1]}, ${f[0]} ${f[1]}, ${m[0]} ${m[1]}`, E = this.sourceArrow ? "" : `M 0 0 L ${v[0]} ${v[1]} `, b = this.targetArrow ? "" : ` M ${m[0]} ${m[1]} L ${s} ${o}`, $ = `${E}${C}${b}`;
436
- if (this.line.setAttribute("d", $), this.sourceArrow) {
437
- const y = p.getArrowPath(
438
- l,
410
+ ]), f = [
411
+ w[0] + u[0] * this.curvature,
412
+ w[1] + u[1] * this.curvature
413
+ ], p = [
414
+ m[0] - g[0] * this.curvature,
415
+ m[1] - g[1] * this.curvature
416
+ ], C = `M ${w[0]} ${w[1]} C ${f[0]} ${f[1]}, ${p[0]} ${p[1]}, ${m[0]} ${m[1]}`, v = this.sourceArrow ? "" : `M 0 0 L ${w[0]} ${w[1]} `, E = this.targetArrow ? "" : ` M ${m[0]} ${m[1]} L ${s} ${o}`, A = `${v}${C}${E}`;
417
+ if (this.line.setAttribute("d", A), this.sourceArrow) {
418
+ const y = S(
419
+ u,
439
420
  0,
440
421
  0,
441
422
  this.arrowLength,
@@ -444,8 +425,8 @@ class G {
444
425
  this.sourceArrow.setAttribute("d", y);
445
426
  }
446
427
  if (this.targetArrow) {
447
- const y = p.getArrowPath(
448
- u,
428
+ const y = S(
429
+ g,
449
430
  s,
450
431
  o,
451
432
  -this.arrowLength,
@@ -455,159 +436,267 @@ class G {
455
436
  }
456
437
  }
457
438
  }
458
- class X {
459
- constructor(t, e, s, o, a, c, h, i) {
439
+ const V = (r, t) => {
440
+ const e = [];
441
+ if (r.length > 0 && e.push(`M ${r[0][0]} ${r[0][1]}`), r.length === 2 && e.push(`L ${r[1][0]} ${r[1][1]}`), r.length > 2) {
442
+ const s = r.length - 1;
443
+ let o = 0, i = 0, h = 0;
444
+ r.forEach((a, c) => {
445
+ let l = 0, d = 0, u = 0;
446
+ const g = c > 0, w = c < s, m = g && w;
447
+ if (g && (l = -o, d = -i, u = h), w) {
448
+ const y = r[c + 1];
449
+ o = y[0] - a[0], i = y[1] - a[1], h = Math.sqrt(o * o + i * i);
450
+ }
451
+ const p = Math.min((m ? t : 0) / h, c < s - 1 ? 0.5 : 1), C = m ? [a[0] + o * p, a[1] + i * p] : a, E = Math.min((m ? t : 0) / u, c > 1 ? 0.5 : 1), A = m ? [a[0] + l * E, a[1] + d * E] : a;
452
+ c > 0 && e.push(`L ${A[0]} ${A[1]}`), m && e.push(
453
+ `C ${a[0]} ${a[1]} ${a[0]} ${a[1]} ${C[0]} ${C[1]}`
454
+ );
455
+ });
456
+ }
457
+ return e.join(" ");
458
+ };
459
+ class G {
460
+ constructor(t, e, s, o, i, h, a, c) {
460
461
  n(this, "svg");
461
462
  n(this, "group");
462
463
  n(this, "line");
463
464
  n(this, "sourceArrow", null);
464
465
  n(this, "targetArrow", null);
465
- n(this, "roundness");
466
- this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = a, this.roundness = Math.min(this.arrowOffset, 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%", c && (this.sourceArrow = document.createElementNS(
466
+ this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = 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%", h && (this.sourceArrow = document.createElementNS(
467
467
  "http://www.w3.org/2000/svg",
468
468
  "path"
469
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = document.createElementNS(
469
+ ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = document.createElementNS(
470
470
  "http://www.w3.org/2000/svg",
471
471
  "path"
472
472
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
473
473
  }
474
- update(t, e, s, o, a, c) {
474
+ update(t, e, s, o, i, h) {
475
475
  this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`;
476
- const h = p.getPortCenter(a), i = p.getPortCenter(c), d = h[0] <= i[0] ? 1 : -1, g = h[1] <= i[1] ? 1 : -1;
477
- this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${d}, ${g})`;
478
- const l = p.getDirectionVector(a.direction, d, g), u = p.getDirectionVector(c.direction, d, g), v = this.sourceArrow ? p.rotate([this.arrowLength, 0], l, [0, 0]) : [0, 0], m = this.targetArrow ? p.rotate([s - this.arrowLength, o], u, [
476
+ const a = $(i), c = $(h), l = a[0] <= c[0] ? 1 : -1, d = a[1] <= c[1] ? 1 : -1;
477
+ this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${d})`;
478
+ const u = N(i.direction, l, d), g = N(h.direction, l, d), w = this.sourceArrow ? b([this.arrowLength, 0], u, [0, 0]) : [0, 0], m = this.targetArrow ? b([s - this.arrowLength, o], g, [
479
479
  s,
480
480
  o
481
- ]) : [s, o], w = this.arrowLength + this.arrowOffset, f = w - this.roundness, C = s - w * 2 * d, E = Math.sqrt(C * C + o * o) / 2, b = Math.min(this.roundness, E), $ = p.rotate([f, 0], l, [0, 0]), y = p.rotate([s - f, o], u, [
481
+ ]) : [s, o], f = this.arrowLength + this.arrowOffset, p = b([f, 0], u, [0, 0]), C = b([s - f, o], g, [
482
482
  s,
483
483
  o
484
- ]), T = p.rotate([w, 0], l, [0, 0]), S = p.rotate([s - w, o], u, [
485
- s,
486
- o
487
- ]), N = (S[0] - T[0]) / 2, L = (S[1] - T[1]) / 2, A = b / E, O = [T[0] + N * A, T[1] + L * A], V = [S[0] - N * A, S[1] - L * A], k = [
488
- `M ${v[0]} ${v[1]}`,
489
- `L ${$[0]} ${$[1]}`,
490
- `C ${T[0]} ${T[1]} ${T[0]} ${T[1]} ${O[0]} ${O[1]}`,
491
- `L ${V[0]} ${V[1]}`,
492
- `C ${S[0]} ${S[1]} ${S[0]} ${S[1]} ${y[0]} ${y[1]}`,
493
- `L ${m[0]} ${m[1]}`
494
- ].join(" ");
495
- if (this.line.setAttribute("d", k), this.sourceArrow) {
496
- const P = p.getArrowPath(
497
- l,
484
+ ]), v = V([w, p, C, m], this.roundness);
485
+ if (this.line.setAttribute("d", v), this.sourceArrow) {
486
+ const E = S(
487
+ u,
498
488
  0,
499
489
  0,
500
490
  this.arrowLength,
501
491
  this.arrowWidth
502
492
  );
503
- this.sourceArrow.setAttribute("d", P);
493
+ this.sourceArrow.setAttribute("d", E);
504
494
  }
505
495
  if (this.targetArrow) {
506
- const P = p.getArrowPath(
507
- u,
496
+ const E = S(
497
+ g,
508
498
  s,
509
499
  o,
510
500
  -this.arrowLength,
511
501
  this.arrowWidth
512
502
  );
513
- this.targetArrow.setAttribute("d", P);
503
+ this.targetArrow.setAttribute("d", E);
514
504
  }
515
505
  }
516
506
  }
517
507
  class Z {
518
- constructor(t, e, s, o, a, c, h) {
508
+ constructor(t, e, s, o, i, h, a) {
519
509
  n(this, "svg");
520
510
  n(this, "group");
521
511
  n(this, "line");
522
512
  n(this, "arrow", null);
523
- this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.radius = c, this.smallRadius = 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.arrow = document.createElementNS(
513
+ this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.radius = h, this.smallRadius = a, 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(
524
514
  "http://www.w3.org/2000/svg",
525
515
  "path"
526
516
  ), 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";
527
517
  }
528
- update(t, e, s, o, a) {
518
+ update(t, e, s, o, i) {
529
519
  this.svg.style.transform = `translate(${t}px, ${e}px)`;
530
- const c = p.getDirectionVector(a.direction, 1, 1), h = this.smallRadius, i = this.radius, d = Math.sqrt(h * h + i * i), g = h + i, l = this.arrowLength + d * (1 - i / g), u = h * i / g, m = [
520
+ const h = N(i.direction, 1, 1), a = this.smallRadius, c = this.radius, l = Math.sqrt(a * a + c * c), d = a + c, u = this.arrowLength + l * (1 - c / d), g = a * c / d, m = [
531
521
  [this.arrowLength, 0],
532
- [l, u],
533
- [l, -u]
534
- ].map((E) => p.rotate(E, c, [0, 0])), w = [
522
+ [u, g],
523
+ [u, -g]
524
+ ].map((v) => b(v, h, [0, 0])), f = [
535
525
  `M ${m[0][0]} ${m[0][1]}`,
536
- `A ${h} ${h} 0 0 1 ${m[1][0]} ${m[1][1]}`,
537
- `A ${i} ${i} 0 1 0 ${m[2][0]} ${m[2][1]}`,
538
- `A ${h} ${h} 0 0 1 ${m[0][0]} ${m[0][1]}`
539
- ].join(" "), f = `M 0 0 L ${m[0][0]} ${m[0][1]} `, C = `${this.arrow !== null ? "" : f}${w}`;
526
+ `A ${a} ${a} 0 0 1 ${m[1][0]} ${m[1][1]}`,
527
+ `A ${c} ${c} 0 1 0 ${m[2][0]} ${m[2][1]}`,
528
+ `A ${a} ${a} 0 0 1 ${m[0][0]} ${m[0][1]}`
529
+ ].join(" "), p = `M 0 0 L ${m[0][0]} ${m[0][1]} `, C = `${this.arrow !== null ? "" : p}${f}`;
540
530
  if (this.line.setAttribute("d", C), this.arrow) {
541
- const E = p.getArrowPath(
542
- c,
531
+ const v = S(
532
+ h,
543
533
  0,
544
534
  0,
545
535
  this.arrowLength,
546
536
  this.arrowWidth
547
537
  );
548
- this.arrow.setAttribute("d", E);
538
+ this.arrow.setAttribute("d", v);
549
539
  }
550
540
  }
551
541
  }
552
542
  class U {
553
- constructor(t, e, s, o, a, c, h, i) {
543
+ constructor(t, e, s, o, i, h, a, c) {
554
544
  n(this, "svg");
555
545
  n(this, "group");
556
546
  n(this, "line");
557
547
  n(this, "arrow", null);
558
548
  n(this, "roundness");
559
- n(this, "points");
560
- this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.side = c, this.minPortOffset = h, this.roundness = Math.min(i, 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%", a && (this.arrow = document.createElementNS(
549
+ n(this, "linePoints");
550
+ this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.side = h, this.minPortOffset = a, this.roundness = Math.min(c, 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(
561
551
  "http://www.w3.org/2000/svg",
562
552
  "path"
563
553
  ), 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";
564
- const d = this.minPortOffset, g = this.side, l = this.arrowLength + d, u = this.roundness, v = l - u, m = l + u, w = g - u, f = l + 2 * g, C = f - u;
565
- console.log(u), this.points = [
554
+ const l = this.minPortOffset, d = this.side, u = this.arrowLength + l, g = this.roundness, w = u + 2 * d;
555
+ console.log(g), this.linePoints = [
566
556
  [this.arrowLength, 0],
567
- [v, 0],
568
- [l, u],
569
- [l, w],
570
- [m, g],
571
- [C, g],
572
- [f, w],
573
- [f, -w],
574
- [C, -g],
575
- [m, -g],
576
- [l, -w],
577
- [l, -u]
557
+ [u, 0],
558
+ [u, this.side],
559
+ [w, this.side],
560
+ [w, -this.side],
561
+ [u, -this.side],
562
+ [u, 0],
563
+ [this.arrowLength, 0]
578
564
  ];
579
565
  }
580
- update(t, e, s, o, a) {
566
+ update(t, e, s, o, i) {
581
567
  this.svg.style.transform = `translate(${t}px, ${e}px)`;
582
- const c = p.getDirectionVector(a.direction, 1, 1), h = this.roundness, i = this.points.map((u) => p.rotate(u, c, [0, 0])), d = [
583
- `M ${i[0][0]} ${i[0][1]}`,
584
- `L ${i[1][0]} ${i[1][1]}`,
585
- `A ${h} ${h} 0 0 1 ${i[2][0]} ${i[2][1]}`,
586
- `L ${i[3][0]} ${i[3][1]}`,
587
- `A ${h} ${h} 0 0 0 ${i[4][0]} ${i[4][1]}`,
588
- `L ${i[5][0]} ${i[5][1]}`,
589
- `A ${h} ${h} 0 0 0 ${i[6][0]} ${i[6][1]}`,
590
- `L ${i[7][0]} ${i[7][1]}`,
591
- `A ${h} ${h} 0 0 0 ${i[8][0]} ${i[8][1]}`,
592
- `L ${i[9][0]} ${i[9][1]}`,
593
- `A ${h} ${h} 0 0 0 ${i[10][0]} ${i[10][1]}`,
594
- `L ${i[11][0]} ${i[11][1]}`,
595
- `A ${h} ${h} 0 0 1 ${i[1][0]} ${i[1][1]}`
596
- ].join(" "), g = `M 0 0 L ${i[0][0]} ${i[0][1]} `, l = `${this.arrow ? "" : g}${d}`;
568
+ const h = N(i.direction, 1, 1), a = this.linePoints.map(
569
+ (d) => b(d, h, [0, 0])
570
+ ), c = `M 0 0 L ${a[0][0]} ${a[0][1]} `, l = `${this.arrow ? "" : c}${V(a, this.roundness)}`;
597
571
  if (this.line.setAttribute("d", l), this.arrow) {
598
- const u = p.getArrowPath(
599
- c,
572
+ const d = S(
573
+ h,
574
+ 0,
575
+ 0,
576
+ this.arrowLength,
577
+ this.arrowWidth
578
+ );
579
+ this.arrow.setAttribute("d", d);
580
+ }
581
+ }
582
+ }
583
+ class H {
584
+ constructor(t, e, s, o, i, h, a, c, l, d) {
585
+ n(this, "svg");
586
+ n(this, "group");
587
+ n(this, "line");
588
+ n(this, "sourceArrow", null);
589
+ n(this, "targetArrow", null);
590
+ n(this, "detourX");
591
+ n(this, "detourY");
592
+ this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = c, this.detourX = Math.cos(d) * l, this.detourY = Math.sin(d) * l, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", h && (this.sourceArrow = document.createElementNS(
593
+ "http://www.w3.org/2000/svg",
594
+ "path"
595
+ ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = document.createElementNS(
596
+ "http://www.w3.org/2000/svg",
597
+ "path"
598
+ ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
599
+ }
600
+ update(t, e, s, o, i, h) {
601
+ this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`;
602
+ const a = $(i), c = $(h), l = a[0] <= c[0] ? 1 : -1, d = a[1] <= c[1] ? 1 : -1;
603
+ this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${d})`;
604
+ const u = N(i.direction, l, d), g = N(h.direction, l, d), w = this.sourceArrow ? b([this.arrowLength, 0], u, [0, 0]) : [0, 0], m = this.targetArrow ? b([s - this.arrowLength, o], g, [
605
+ s,
606
+ o
607
+ ]) : [s, o], f = this.arrowLength + this.arrowOffset, p = b([f, 0], u, [0, 0]), C = [p[0] + this.detourX, p[1] + this.detourY], v = b([s - f, o], g, [
608
+ s,
609
+ o
610
+ ]), E = [v[0] + this.detourX, v[1] + this.detourY], A = V(
611
+ [w, p, C, E, v, m],
612
+ this.roundness
613
+ );
614
+ if (this.line.setAttribute("d", A), this.sourceArrow) {
615
+ const y = S(
616
+ u,
617
+ 0,
618
+ 0,
619
+ this.arrowLength,
620
+ this.arrowWidth
621
+ );
622
+ this.sourceArrow.setAttribute("d", y);
623
+ }
624
+ if (this.targetArrow) {
625
+ const y = S(
626
+ g,
627
+ s,
628
+ o,
629
+ -this.arrowLength,
630
+ this.arrowWidth
631
+ );
632
+ this.targetArrow.setAttribute("d", y);
633
+ }
634
+ }
635
+ }
636
+ var T = /* @__PURE__ */ ((r) => (r.Regular = "regular", r.PortCycle = "port-cycle", r.NodeCycle = "node-cycle", r))(T || {});
637
+ class q {
638
+ constructor(t, e, s, o, i, h, a, c, l) {
639
+ n(this, "svg");
640
+ n(this, "group");
641
+ n(this, "line");
642
+ n(this, "sourceArrow", null);
643
+ n(this, "targetArrow", null);
644
+ n(this, "detourX");
645
+ n(this, "detourY");
646
+ this.color = t, this.width = e, this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.detourX = Math.cos(l) * c, this.detourY = Math.sin(l) * 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%", h && (this.sourceArrow = document.createElementNS(
647
+ "http://www.w3.org/2000/svg",
648
+ "path"
649
+ ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = document.createElementNS(
650
+ "http://www.w3.org/2000/svg",
651
+ "path"
652
+ ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
653
+ }
654
+ update(t, e, s, o, i, h) {
655
+ this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`;
656
+ const a = $(i), c = $(h), l = a[0] <= c[0] ? 1 : -1, d = a[1] <= c[1] ? 1 : -1;
657
+ this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${d})`;
658
+ const u = N(i.direction, l, d), g = N(h.direction, l, d), w = this.sourceArrow ? b([this.arrowLength, 0], u, [0, 0]) : [0, 0], m = this.targetArrow ? b([s - this.arrowLength, o], g, [
659
+ s,
660
+ o
661
+ ]) : [s, o], f = this.arrowLength, p = b([f, 0], u, [0, 0]), C = [p[0] + this.detourX, p[1] + this.detourY], v = b([s - f, o], g, [
662
+ s,
663
+ o
664
+ ]), E = [v[0] + this.detourX, v[1] + this.detourY], A = [(C[0] + E[0]) / 2, (C[1] + E[1]) / 2], y = [
665
+ p[0] - this.curvature * Math.cos(i.direction),
666
+ p[1] - this.curvature * Math.sin(i.direction)
667
+ ], x = [
668
+ v[0] + this.curvature * Math.cos(h.direction),
669
+ v[1] + this.curvature * Math.sin(h.direction)
670
+ ], P = [p[0] + this.detourX, p[1] + this.detourY], M = [v[0] + this.detourX, v[1] + this.detourY], k = [
671
+ `M ${w[0]} ${w[1]}`,
672
+ `L ${p[0]} ${p[1]}`,
673
+ `C ${y[0]} ${y[1]} ${P[0]} ${P[1]} ${A[0]} ${A[1]}`,
674
+ `C ${M[0]} ${M[1]} ${x[0]} ${x[1]} ${v[0]} ${v[1]}`,
675
+ `L ${m[0]} ${m[1]}`
676
+ ].join(" ");
677
+ if (this.line.setAttribute("d", k), this.sourceArrow) {
678
+ const O = S(
679
+ u,
600
680
  0,
601
681
  0,
602
682
  this.arrowLength,
603
683
  this.arrowWidth
604
684
  );
605
- this.arrow.setAttribute("d", u);
685
+ this.sourceArrow.setAttribute("d", O);
686
+ }
687
+ if (this.targetArrow) {
688
+ const O = S(
689
+ g,
690
+ s,
691
+ o,
692
+ -this.arrowLength,
693
+ this.arrowWidth
694
+ );
695
+ this.targetArrow.setAttribute("d", O);
606
696
  }
607
697
  }
608
698
  }
609
- var M = /* @__PURE__ */ ((r) => (r.Regular = "regular", r.Cycle = "cycle", r))(M || {});
610
- const H = (r) => (t) => t === "cycle" ? new Z(
699
+ const _ = (r) => (t) => t === T.PortCycle ? new Z(
611
700
  r.color,
612
701
  r.width,
613
702
  r.arrowLength,
@@ -615,7 +704,17 @@ const H = (r) => (t) => t === "cycle" ? new Z(
615
704
  r.hasSourceArrow || r.hasTargetArrow,
616
705
  r.cycleRadius,
617
706
  r.smallCycleRadius
618
- ) : new G(
707
+ ) : t === T.NodeCycle ? new q(
708
+ r.color,
709
+ r.width,
710
+ r.curvature,
711
+ r.arrowLength,
712
+ r.arrowWidth,
713
+ r.hasSourceArrow,
714
+ r.hasTargetArrow,
715
+ r.detourDistance,
716
+ r.detourDirection
717
+ ) : new z(
619
718
  r.color,
620
719
  r.width,
621
720
  r.curvature,
@@ -623,7 +722,7 @@ const H = (r) => (t) => t === "cycle" ? new Z(
623
722
  r.arrowWidth,
624
723
  r.hasSourceArrow,
625
724
  r.hasTargetArrow
626
- ), q = (r) => (t) => t === M.Cycle && t === "cycle" ? new U(
725
+ ), J = (r) => (t) => t === T.PortCycle ? new U(
627
726
  r.color,
628
727
  r.width,
629
728
  r.arrowLength,
@@ -632,7 +731,18 @@ const H = (r) => (t) => t === "cycle" ? new Z(
632
731
  r.cycleSquareSide,
633
732
  r.arrowOffset,
634
733
  r.roundness
635
- ) : new X(
734
+ ) : t === T.NodeCycle ? new H(
735
+ r.color,
736
+ r.width,
737
+ r.arrowLength,
738
+ r.arrowWidth,
739
+ r.arrowOffset,
740
+ r.hasSourceArrow,
741
+ r.hasTargetArrow,
742
+ r.roundness,
743
+ r.detourDistance,
744
+ r.detourDirection
745
+ ) : new G(
636
746
  r.color,
637
747
  r.width,
638
748
  r.arrowLength,
@@ -642,7 +752,7 @@ const H = (r) => (t) => t === "cycle" ? new Z(
642
752
  r.hasTargetArrow,
643
753
  r.roundness
644
754
  );
645
- class x {
755
+ class L {
646
756
  constructor() {
647
757
  n(this, "counter", 0);
648
758
  }
@@ -654,19 +764,19 @@ class x {
654
764
  this.counter = 0;
655
765
  }
656
766
  }
657
- class _ {
658
- constructor(t, e, s, o, a) {
659
- n(this, "nodeIdGenerator", new x());
660
- n(this, "portIdGenerator", new x());
661
- n(this, "edgeIdGenerator", new x());
662
- this.graphStore = t, this.htmlController = e, this.viewportTransformer = s, this.nodesCenterFn = o, this.portsCenterFn = a;
767
+ class K {
768
+ constructor(t, e, s, o, i, h) {
769
+ n(this, "nodeIdGenerator", new L());
770
+ n(this, "portIdGenerator", new L());
771
+ n(this, "edgeIdGenerator", new L());
772
+ this.graphStore = t, this.htmlController = e, this.viewportTransformer = s, this.nodesCenterFn = o, this.portsCenterFn = i, this.portsDirection = h;
663
773
  }
664
774
  moveNodeOnTop(t) {
665
775
  if (!this.graphStore.hasNode(t))
666
776
  throw new Error("failed to move on top nonexisting node");
667
777
  this.htmlController.moveNodeOnTop(t);
668
778
  }
669
- addNode(t, e, s, o, a, c) {
779
+ addNode(t, e, s, o, i, h) {
670
780
  if (t === void 0)
671
781
  do
672
782
  t = this.nodeIdGenerator.next();
@@ -678,18 +788,24 @@ class _ {
678
788
  e,
679
789
  s,
680
790
  o,
681
- c ?? this.nodesCenterFn
682
- ), this.htmlController.attachNode(t), a !== void 0 && Object.entries(a).forEach(([h, i]) => {
683
- i instanceof HTMLElement ? this.markPort(h, i, t, this.portsCenterFn, null) : this.markPort(
684
- h,
685
- i.element,
791
+ h ?? this.nodesCenterFn
792
+ ), this.htmlController.attachNode(t), i !== void 0 && Object.entries(i).forEach(([a, c]) => {
793
+ c instanceof HTMLElement ? this.markPort(
794
+ a,
795
+ c,
796
+ t,
797
+ this.portsCenterFn,
798
+ this.portsDirection
799
+ ) : this.markPort(
800
+ a,
801
+ c.element,
686
802
  t,
687
- i.centerFn ?? this.portsCenterFn,
688
- i.direction ?? null
803
+ c.centerFn ?? this.portsCenterFn,
804
+ c.direction ?? this.portsDirection
689
805
  );
690
806
  });
691
807
  }
692
- markPort(t, e, s, o, a) {
808
+ markPort(t, e, s, o, i) {
693
809
  if (t === void 0)
694
810
  do
695
811
  t = this.portIdGenerator.next();
@@ -703,7 +819,7 @@ class _ {
703
819
  e,
704
820
  s,
705
821
  o ?? this.portsCenterFn,
706
- a ?? null
822
+ i ?? 0
707
823
  );
708
824
  }
709
825
  updatePortEdges(t) {
@@ -727,12 +843,13 @@ class _ {
727
843
  throw new Error("failed to add edge from nonexisting port");
728
844
  if (!this.graphStore.hasPort(s))
729
845
  throw new Error("failed to add edge to nonexisting port");
730
- let a = M.Regular;
731
- e === s && (a = M.Cycle), this.graphStore.addEdge(
846
+ let i = T.Regular;
847
+ const h = this.graphStore.getPortNode(e), a = this.graphStore.getPortNode(s);
848
+ e === s ? i = T.PortCycle : h === a && (i = T.NodeCycle), this.graphStore.addEdge(
732
849
  t,
733
850
  e,
734
851
  s,
735
- o(a)
852
+ o(i)
736
853
  ), this.htmlController.attachEdge(t);
737
854
  }
738
855
  removeEdge(t) {
@@ -751,14 +868,14 @@ class _ {
751
868
  moveToNodes(t) {
752
869
  if (t.length === 0)
753
870
  return;
754
- const e = t.map((u) => this.graphStore.getNode(u)).filter((u) => u !== void 0);
871
+ const e = t.map((g) => this.graphStore.getNode(g)).filter((g) => g !== void 0);
755
872
  if (e.length < t.length)
756
873
  throw new Error("failed to move to nonexisting node");
757
874
  const [s, o] = e.reduce(
758
- (u, v) => [u[0] + v.x, u[1] + v.y],
875
+ (g, w) => [g[0] + w.x, g[1] + w.y],
759
876
  [0, 0]
760
- ), a = s / e.length, c = o / e.length, [h, i] = this.htmlController.getViewportDimensions(), d = this.viewportTransformer.getAbsScale(), g = a - d * h / 2, l = c - d * i / 2;
761
- this.patchViewportState(null, g, l);
877
+ ), i = s / e.length, h = o / e.length, [a, c] = this.htmlController.getViewportDimensions(), l = this.viewportTransformer.getAbsScale(), d = i - l * a / 2, u = h - l * c / 2;
878
+ this.patchViewportState(null, d, u);
762
879
  }
763
880
  updateNodeCoordinates(t, e, s) {
764
881
  if (!this.graphStore.hasNode(t))
@@ -783,81 +900,82 @@ class _ {
783
900
  this.htmlController.destroy();
784
901
  }
785
902
  }
786
- class J {
787
- constructor(t, e, s, o) {
903
+ class Q {
904
+ constructor(t, e, s, o, i) {
788
905
  n(this, "publicViewportTransformer");
789
906
  n(this, "canvasController");
790
- const a = new B(), c = new Y();
791
- this.publicViewportTransformer = new z(
792
- a
907
+ const h = new B(), a = new X();
908
+ this.publicViewportTransformer = new Y(
909
+ h
793
910
  );
794
- const h = new W(
795
- c,
911
+ const c = new R(
796
912
  a,
913
+ h,
797
914
  this.publicViewportTransformer,
798
915
  t,
799
916
  e
800
917
  );
801
- this.canvasController = new _(
918
+ this.canvasController = new K(
919
+ a,
802
920
  c,
803
921
  h,
804
- a,
805
922
  s,
806
- o
923
+ o,
924
+ i
807
925
  );
808
926
  }
809
927
  }
810
928
  const D = (r, t) => [
811
929
  r / 2,
812
930
  t / 2
813
- ], K = () => () => {
814
- }, Q = (r, t, e, s, o, a) => {
815
- r.clearRect(0, 0, r.canvas.width, r.canvas.height), r.fillStyle = a, r.fillRect(0, 0, r.canvas.width, r.canvas.height);
816
- const c = t.getViewCoords(0, 0), h = t.getViewScale(), i = s * h;
817
- let d = 0, g = 0, l = i / 2;
931
+ ], I = () => () => {
932
+ }, tt = (r, t, e, s, o, i) => {
933
+ r.clearRect(0, 0, r.canvas.width, r.canvas.height), r.fillStyle = i, r.fillRect(0, 0, r.canvas.width, r.canvas.height);
934
+ const h = t.getViewCoords(0, 0), a = t.getViewScale(), c = s * a;
935
+ let l = 0, d = 0, u = c / 2;
818
936
  do
819
- l *= 2, d = r.canvas.width / l, g = r.canvas.height / l;
820
- while (d * g > 1e4);
821
- const u = c[0] - Math.floor(c[0] / l) * l, v = c[1] - Math.floor(c[1] / l) * l, m = o * h, w = 2 * Math.PI, f = u - l, C = v - l, E = r.canvas.width + u, b = r.canvas.height + v;
937
+ u *= 2, l = r.canvas.width / u, d = r.canvas.height / u;
938
+ while (l * d > 1e4);
939
+ const g = h[0] - Math.floor(h[0] / u) * u, w = h[1] - Math.floor(h[1] / u) * u, m = o * a, f = 2 * Math.PI, p = g - u, C = w - u, v = r.canvas.width + g, E = r.canvas.height + w;
822
940
  r.fillStyle = e;
823
- for (let $ = f; $ <= E; $ += l)
824
- for (let y = C; y <= b; y += l)
825
- r.beginPath(), r.arc($, y, m, 0, w), r.closePath(), r.fill();
826
- }, I = (r, t, e, s) => (o, a) => {
827
- Q(
941
+ for (let A = p; A <= v; A += u)
942
+ for (let y = C; y <= E; y += u)
943
+ r.beginPath(), r.arc(A, y, m, 0, f), r.closePath(), r.fill();
944
+ }, et = (r, t, e, s) => (o, i) => {
945
+ tt(
828
946
  o,
829
- a,
947
+ i,
830
948
  r,
831
949
  t,
832
950
  e,
833
951
  s
834
952
  );
835
- }, tt = (r, t) => {
953
+ }, st = (r, t) => {
836
954
  r.fillStyle = t, r.fillRect(0, 0, r.canvas.width, r.canvas.height);
837
- }, et = (r) => (t) => {
838
- tt(t, r);
839
- }, st = (r) => {
955
+ }, rt = (r) => (t) => {
956
+ st(t, r);
957
+ }, ot = (r) => {
840
958
  switch (r == null ? void 0 : r.type) {
841
959
  case "custom":
842
960
  return r.drawingFn;
843
961
  case "dots":
844
- return I(
962
+ return et(
845
963
  r.dotColor ?? "#d8d8d8",
846
964
  r.dotGap ?? 25,
847
965
  r.dotRadius ?? 1.5,
848
966
  r.color ?? "#ffffff"
849
967
  );
850
968
  case "color":
851
- return et(r.color ?? "#ffffff");
969
+ return rt(r.color ?? "#ffffff");
852
970
  default:
853
- return K();
971
+ return I();
854
972
  }
855
973
  }, F = (r) => {
856
974
  switch (r == null ? void 0 : r.type) {
857
975
  case "custom":
858
976
  return r.controllerFactory;
859
977
  case "straight":
860
- return q({
978
+ return J({
861
979
  color: r.color ?? "#5c5c5c",
862
980
  width: r.width ?? 1,
863
981
  arrowLength: r.arrowLength ?? 15,
@@ -866,10 +984,12 @@ const D = (r, t) => [
866
984
  hasSourceArrow: r.hasSourceArrow ?? !1,
867
985
  hasTargetArrow: r.hasTargetArrow ?? !1,
868
986
  cycleSquareSide: r.cycleSquareSide ?? 30,
869
- roundness: r.roundness ?? 5
987
+ roundness: r.roundness ?? 10,
988
+ detourDistance: r.detourDistance ?? 100,
989
+ detourDirection: r.detourDirection ?? -Math.PI / 2
870
990
  });
871
991
  default:
872
- return H({
992
+ return _({
873
993
  color: r.color ?? "#5c5c5c",
874
994
  width: r.width ?? 1,
875
995
  curvature: r.curvature ?? 90,
@@ -878,14 +998,16 @@ const D = (r, t) => [
878
998
  hasSourceArrow: r.hasSourceArrow ?? !1,
879
999
  hasTargetArrow: r.hasTargetArrow ?? !1,
880
1000
  cycleRadius: r.cycleRadius ?? 30,
881
- smallCycleRadius: r.smallCycleRadius ?? 15
1001
+ smallCycleRadius: r.smallCycleRadius ?? 15,
1002
+ detourDistance: r.detourDistance ?? 100,
1003
+ detourDirection: r.detourDirection ?? -Math.PI / 2
882
1004
  });
883
1005
  }
884
- }, rt = (r) => {
885
- var t, e, s;
1006
+ }, nt = (r) => {
1007
+ var t, e, s, o;
886
1008
  return {
887
1009
  background: {
888
- drawingFn: st(
1010
+ drawingFn: ot(
889
1011
  r.background ?? { type: "none" }
890
1012
  )
891
1013
  },
@@ -893,28 +1015,30 @@ const D = (r, t) => [
893
1015
  centerFn: ((t = r.nodes) == null ? void 0 : t.centerFn) ?? D
894
1016
  },
895
1017
  ports: {
896
- centerFn: ((e = r.ports) == null ? void 0 : e.centerFn) ?? D
1018
+ centerFn: ((e = r.ports) == null ? void 0 : e.centerFn) ?? D,
1019
+ direction: ((s = r.ports) == null ? void 0 : s.direction) ?? 0
897
1020
  },
898
1021
  edges: {
899
1022
  controllerFactory: F(r.edges ?? {})
900
1023
  },
901
1024
  layers: {
902
- mode: ((s = r.layers) == null ? void 0 : s.mode) ?? "edges-follow-node"
1025
+ mode: ((o = r.layers) == null ? void 0 : o.mode) ?? "edges-follow-node"
903
1026
  }
904
1027
  };
905
1028
  };
906
- class ot {
1029
+ class it {
907
1030
  constructor(t) {
908
1031
  n(this, "transformation");
909
1032
  n(this, "di");
910
1033
  n(this, "edgeControllerFactory");
911
1034
  this.apiOptions = t;
912
- const e = rt(this.apiOptions ?? {});
913
- this.di = new J(
1035
+ const e = nt(this.apiOptions ?? {});
1036
+ this.di = new Q(
914
1037
  e.layers.mode,
915
1038
  e.background.drawingFn,
916
1039
  e.nodes.centerFn,
917
- e.ports.centerFn
1040
+ e.ports.centerFn,
1041
+ e.ports.direction
918
1042
  ), this.transformation = this.di.publicViewportTransformer, this.edgeControllerFactory = e.edges.controllerFactory;
919
1043
  }
920
1044
  addNode(t) {
@@ -989,14 +1113,14 @@ class ot {
989
1113
  this.di.canvasController.destroy();
990
1114
  }
991
1115
  }
992
- class nt {
1116
+ class ht {
993
1117
  constructor(t, e) {
994
1118
  n(this, "transformation");
995
1119
  n(this, "nodes", /* @__PURE__ */ new Map());
996
1120
  n(this, "grabbedNodeId", null);
997
1121
  n(this, "onNodeDrag");
998
1122
  n(this, "onBeforeNodeDrag");
999
- n(this, "nodeIdGenerator", new x());
1123
+ n(this, "nodeIdGenerator", new L());
1000
1124
  n(this, "element", null);
1001
1125
  n(this, "onCanvasMouseUp", () => {
1002
1126
  this.setCursor(null), this.grabbedNodeId = null;
@@ -1030,13 +1154,13 @@ class nt {
1030
1154
  ] : (this.previousTouchCoords = null, this.grabbedNodeId = null);
1031
1155
  });
1032
1156
  n(this, "previousTouchCoords", null);
1033
- var a, c;
1157
+ var i, h;
1034
1158
  this.canvas = t, this.transformation = this.canvas.transformation;
1035
1159
  const s = () => {
1036
1160
  };
1037
- this.onNodeDrag = ((a = e == null ? void 0 : e.events) == null ? void 0 : a.onNodeDrag) ?? s;
1161
+ this.onNodeDrag = ((i = e == null ? void 0 : e.events) == null ? void 0 : i.onNodeDrag) ?? s;
1038
1162
  const o = () => !0;
1039
- this.onBeforeNodeDrag = ((c = e == null ? void 0 : e.events) == null ? void 0 : c.onBeforeNodeDrag) ?? o;
1163
+ this.onBeforeNodeDrag = ((h = e == null ? void 0 : e.events) == null ? void 0 : h.onBeforeNodeDrag) ?? o;
1040
1164
  }
1041
1165
  addNode(t) {
1042
1166
  let e = t.id;
@@ -1045,20 +1169,20 @@ class nt {
1045
1169
  e = this.nodeIdGenerator.next();
1046
1170
  while (this.nodes.has(e));
1047
1171
  this.canvas.addNode(t);
1048
- const s = (a) => {
1172
+ const s = (i) => {
1049
1173
  this.onBeforeNodeDrag({
1050
1174
  nodeId: e,
1051
1175
  element: t.element,
1052
1176
  x: t.x,
1053
1177
  y: t.y
1054
- }) && (a.stopImmediatePropagation(), this.grabbedNodeId = e, this.setCursor("grab"), this.canvas.moveNodeOnTop(e));
1055
- }, o = (a) => {
1178
+ }) && (i.stopImmediatePropagation(), this.grabbedNodeId = e, this.setCursor("grab"), this.canvas.moveNodeOnTop(e));
1179
+ }, o = (i) => {
1056
1180
  this.onBeforeNodeDrag({
1057
1181
  nodeId: e,
1058
1182
  element: t.element,
1059
1183
  x: t.x,
1060
1184
  y: t.y
1061
- }) && a.touches.length === 1 && (this.grabbedNodeId = e, this.canvas.moveNodeOnTop(e));
1185
+ }) && i.touches.length === 1 && (this.grabbedNodeId = e, this.canvas.moveNodeOnTop(e));
1062
1186
  };
1063
1187
  return this.nodes.set(e, {
1064
1188
  element: t.element,
@@ -1125,8 +1249,8 @@ class nt {
1125
1249
  const o = this.nodes.get(t);
1126
1250
  if (o === void 0)
1127
1251
  throw new Error("failed to drag nonexisting node");
1128
- const [a, c] = this.transformation.getViewCoords(o.x, o.y), h = a + e, i = c + s, [d, g] = this.transformation.getAbsCoords(h, i);
1129
- o.x = d, o.y = g, this.canvas.updateNodeCoordinates(t, d, g), this.onNodeDrag({
1252
+ const [i, h] = this.transformation.getViewCoords(o.x, o.y), a = i + e, c = h + s, [l, d] = this.transformation.getAbsCoords(a, c);
1253
+ o.x = l, o.y = d, this.canvas.updateNodeCoordinates(t, l, d), this.onNodeDrag({
1130
1254
  nodeId: t,
1131
1255
  element: o.element,
1132
1256
  x: o.x,
@@ -1134,7 +1258,7 @@ class nt {
1134
1258
  });
1135
1259
  }
1136
1260
  }
1137
- class it {
1261
+ class at {
1138
1262
  constructor(t, e) {
1139
1263
  n(this, "transformation");
1140
1264
  n(this, "element", null);
@@ -1163,8 +1287,8 @@ class it {
1163
1287
  if (this.element === null || this.isScalable === !1)
1164
1288
  return;
1165
1289
  t.preventDefault();
1166
- const { left: e, top: s } = this.element.getBoundingClientRect(), o = t.clientX - e, a = t.clientY - s, h = 1 / (t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
1167
- this.scaleViewport(h, o, a);
1290
+ const { left: e, top: s } = this.element.getBoundingClientRect(), o = t.clientX - e, i = t.clientY - s, a = 1 / (t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
1291
+ this.scaleViewport(a, o, i);
1168
1292
  });
1169
1293
  n(this, "onTouchStart", (t) => {
1170
1294
  this.prevTouches = this.getAverageTouch(t);
@@ -1177,25 +1301,25 @@ class it {
1177
1301
  -(e.x - this.prevTouches.x),
1178
1302
  -(e.y - this.prevTouches.y)
1179
1303
  ), e.touchesCnt === 2 && this.isScalable) {
1180
- const { left: s, top: o } = this.element.getBoundingClientRect(), a = this.prevTouches.x - s, c = this.prevTouches.y - o, i = 1 / (e.scale / this.prevTouches.scale);
1181
- this.scaleViewport(i, a, c);
1304
+ const { left: s, top: o } = this.element.getBoundingClientRect(), i = this.prevTouches.x - s, h = this.prevTouches.y - o, c = 1 / (e.scale / this.prevTouches.scale);
1305
+ this.scaleViewport(c, i, h);
1182
1306
  }
1183
1307
  this.prevTouches = e, t.preventDefault();
1184
1308
  });
1185
1309
  n(this, "onTouchEnd", (t) => {
1186
1310
  t.touches.length > 0 ? this.prevTouches = this.getAverageTouch(t) : this.prevTouches = null;
1187
1311
  });
1188
- var i, d, g, l, u, v, m, w, f, C, E, b;
1312
+ var c, l, d, u, g, w, m, f, p, C, v, E;
1189
1313
  this.canvas = t, this.options = e, this.transformation = this.canvas.transformation;
1190
- const s = ((d = (i = this.options) == null ? void 0 : i.scale) == null ? void 0 : d.min) ?? null, o = ((l = (g = this.options) == null ? void 0 : g.scale) == null ? void 0 : l.max) ?? null;
1191
- this.isScalable = ((v = (u = this.options) == null ? void 0 : u.scale) == null ? void 0 : v.enabled) !== !1, this.minViewScale = o !== null ? 1 / o : null, this.maxViewScale = s !== null ? 1 / s : null, this.isShiftable = ((w = (m = this.options) == null ? void 0 : m.shift) == null ? void 0 : w.enabled) !== !1;
1192
- const a = (C = (f = this.options) == null ? void 0 : f.scale) == null ? void 0 : C.wheelSensitivity;
1193
- this.wheelSensitivity = a !== void 0 ? a : 1.2;
1194
- const c = () => {
1314
+ const s = ((l = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : l.min) ?? null, o = ((u = (d = this.options) == null ? void 0 : d.scale) == null ? void 0 : u.max) ?? null;
1315
+ this.isScalable = ((w = (g = this.options) == null ? void 0 : g.scale) == null ? void 0 : w.enabled) !== !1, this.minViewScale = o !== null ? 1 / o : null, this.maxViewScale = s !== null ? 1 / s : null, this.isShiftable = ((f = (m = this.options) == null ? void 0 : m.shift) == null ? void 0 : f.enabled) !== !1;
1316
+ const i = (C = (p = this.options) == null ? void 0 : p.scale) == null ? void 0 : C.wheelSensitivity;
1317
+ this.wheelSensitivity = i !== void 0 ? i : 1.2;
1318
+ const h = () => {
1195
1319
  };
1196
- this.onTransform = ((E = e == null ? void 0 : e.events) == null ? void 0 : E.onTransform) ?? c;
1197
- const h = () => !0;
1198
- this.onBeforeTransform = ((b = e == null ? void 0 : e.events) == null ? void 0 : b.onBeforeTransform) ?? h;
1320
+ this.onTransform = ((v = e == null ? void 0 : e.events) == null ? void 0 : v.onTransform) ?? h;
1321
+ const a = () => !0;
1322
+ this.onBeforeTransform = ((E = e == null ? void 0 : e.events) == null ? void 0 : E.onBeforeTransform) ?? a;
1199
1323
  }
1200
1324
  addNode(t) {
1201
1325
  return this.canvas.addNode(t), this;
@@ -1247,37 +1371,37 @@ class it {
1247
1371
  }
1248
1372
  getAverageTouch(t) {
1249
1373
  const e = [], s = t.touches.length;
1250
- for (let i = 0; i < s; i++)
1251
- e.push([t.touches[i].clientX, t.touches[i].clientY]);
1374
+ for (let c = 0; c < s; c++)
1375
+ e.push([t.touches[c].clientX, t.touches[c].clientY]);
1252
1376
  const o = e.reduce(
1253
- (i, d) => [i[0] + d[0], i[1] + d[1]],
1377
+ (c, l) => [c[0] + l[0], c[1] + l[1]],
1254
1378
  [0, 0]
1255
- ), a = [o[0] / s, o[1] / s], h = e.map((i) => [i[0] - a[0], i[1] - a[1]]).reduce(
1256
- (i, d) => i + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
1379
+ ), i = [o[0] / s, o[1] / s], a = e.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1380
+ (c, l) => c + Math.sqrt(l[0] * l[0] + l[1] * l[1]),
1257
1381
  0
1258
1382
  );
1259
- return { x: a[0], y: a[1], scale: h / s, touchesCnt: s };
1383
+ return { x: i[0], y: i[1], scale: a / s, touchesCnt: s };
1260
1384
  }
1261
1385
  setCursor(t) {
1262
1386
  this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1263
1387
  }
1264
1388
  moveViewport(t, e) {
1265
- const [s, o] = this.transformation.getAbsCoords(0, 0), a = this.canvas.transformation.getAbsScale(), c = {
1266
- scale: a,
1267
- x: s + a * t,
1268
- y: o + a * e
1389
+ const [s, o] = this.transformation.getAbsCoords(0, 0), i = this.canvas.transformation.getAbsScale(), h = {
1390
+ scale: i,
1391
+ x: s + i * t,
1392
+ y: o + i * e
1269
1393
  };
1270
- this.onBeforeTransform({ ...c }) && (this.canvas.patchViewportState(c), this.onTransform(c));
1394
+ this.onBeforeTransform({ ...h }) && (this.canvas.patchViewportState(h), this.onTransform(h));
1271
1395
  }
1272
1396
  scaleViewport(t, e, s) {
1273
- const [o, a] = this.canvas.transformation.getAbsCoords(0, 0), c = this.canvas.transformation.getAbsScale(), h = c * t, i = c * (1 - t) * e + o, d = c * (1 - t) * s + a;
1274
- if (this.maxViewScale !== null && h > this.maxViewScale && h > c || this.minViewScale !== null && h < this.minViewScale && h < c)
1397
+ const [o, i] = this.canvas.transformation.getAbsCoords(0, 0), h = this.canvas.transformation.getAbsScale(), a = h * t, c = h * (1 - t) * e + o, l = h * (1 - t) * s + i;
1398
+ if (this.maxViewScale !== null && a > this.maxViewScale && a > h || this.minViewScale !== null && a < this.minViewScale && a < h)
1275
1399
  return;
1276
- const g = { scale: h, x: i, y: d };
1277
- this.onBeforeTransform({ ...g }) && (this.canvas.patchViewportState(g), this.onTransform(g));
1400
+ const d = { scale: a, x: c, y: l };
1401
+ this.onBeforeTransform({ ...d }) && (this.canvas.patchViewportState(d), this.onTransform(d));
1278
1402
  }
1279
1403
  }
1280
- class ht {
1404
+ class lt {
1281
1405
  constructor() {
1282
1406
  n(this, "coreOptions");
1283
1407
  n(this, "dragOptions");
@@ -1295,21 +1419,21 @@ class ht {
1295
1419
  return this.isTransformable = !0, this.transformOptions = t, this;
1296
1420
  }
1297
1421
  build() {
1298
- let t = new ot(this.coreOptions);
1299
- return this.isDraggable && (t = new nt(t, this.dragOptions)), this.isTransformable && (t = new it(t, this.transformOptions)), t;
1422
+ let t = new it(this.coreOptions);
1423
+ return this.isDraggable && (t = new ht(t, this.dragOptions)), this.isTransformable && (t = new at(t, this.transformOptions)), t;
1300
1424
  }
1301
1425
  }
1302
1426
  export {
1303
- G as BezierEdgeController,
1304
- ot as CanvasCore,
1427
+ z as BezierEdgeController,
1428
+ it as CanvasCore,
1305
1429
  Z as CycleCircleEdgeController,
1306
1430
  U as CycleSquareEdgeController,
1307
- M as EdgeType,
1308
- p as EdgeUtils,
1309
- ht as HtmlGraphBuilder,
1310
- X as StraightEdgeController,
1311
- nt as UserDraggableNodesCanvas,
1312
- it as UserTransformableCanvas,
1313
- H as createBezierEdgeControllerFactory,
1314
- q as createStraightEdgeControllerFactory
1431
+ H as DetourStraightEdgeController,
1432
+ T as EdgeType,
1433
+ lt as HtmlGraphBuilder,
1434
+ G as StraightEdgeController,
1435
+ ht as UserDraggableNodesCanvas,
1436
+ at as UserTransformableCanvas,
1437
+ _ as createBezierEdgeControllerFactory,
1438
+ J as createStraightEdgeControllerFactory
1315
1439
  };