@html-graph/html-graph 7.3.0 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -58,8 +58,17 @@ export declare interface AnimatedLayoutConfig {
58
58
  readonly edgeEquilibriumLength?: number;
59
59
  readonly edgeStiffness?: number;
60
60
  readonly seed?: string;
61
+ /**
62
+ * @deprecated
63
+ * use convergenceVelocity instead
64
+ */
61
65
  readonly effectiveDistance?: number;
66
+ /**
67
+ * @deprecated
68
+ * use convergenceVelocity instead
69
+ */
62
70
  readonly convergenceDelta?: number;
71
+ readonly convergenceVelocity?: number;
63
72
  readonly maxForce?: number;
64
73
  readonly nodeForceCoefficient?: number;
65
74
  readonly barnesHut?: {
@@ -747,11 +756,15 @@ declare type LayoutAlgorithmConfig = {
747
756
  readonly edgeStiffness?: number;
748
757
  /**
749
758
  * @deprecated
750
- * this parameter results in slow convergence
751
- * use convergenceDelta instead
759
+ * use convergenceVelocity instead
752
760
  */
753
761
  readonly effectiveDistance?: number;
762
+ /**
763
+ * @deprecated
764
+ * use convergenceVelocity instead
765
+ */
754
766
  readonly convergenceDelta?: number;
767
+ readonly convergenceVelocity?: number;
755
768
  readonly maxForce?: number;
756
769
  readonly nodeForceCoefficient?: number;
757
770
  readonly barnesHut?: {
@@ -1,7 +1,7 @@
1
1
  var ke = Object.defineProperty;
2
2
  var ze = (r, e, t) => e in r ? ke(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
3
  var i = (r, e, t) => ze(r, typeof e != "symbol" ? e + "" : e, t);
4
- const D = (r, e) => ({
4
+ const C = (r, e) => ({
5
5
  x: r.scale * e.x + r.x,
6
6
  y: r.scale * e.y + r.y
7
7
  });
@@ -90,7 +90,7 @@ class me {
90
90
  const n = {
91
91
  x: t.left - s.left,
92
92
  y: t.top - s.top
93
- }, a = D(o, n);
93
+ }, a = C(o, n);
94
94
  return {
95
95
  x: a.x,
96
96
  y: a.y,
@@ -825,10 +825,10 @@ class K {
825
825
  this.canvas.updateNode(t);
826
826
  }
827
827
  }
828
- const Je = (r, e, t) => {
828
+ const qe = (r, e, t) => {
829
829
  const { x: s, y: o, width: n, height: a } = r.getBoundingClientRect();
830
830
  return e >= s && e <= s + n && t >= o && t <= o + a;
831
- }, qe = (r, e, t) => e >= 0 && e <= r.innerWidth && t >= 0 && t <= r.innerHeight, F = (r, e, t, s) => Je(e, t, s) && qe(r, t, s), U = (r, e) => {
831
+ }, Je = (r, e, t) => e >= 0 && e <= r.innerWidth && t >= 0 && t <= r.innerHeight, V = (r, e, t, s) => qe(e, t, s) && Je(r, t, s), U = (r, e) => {
832
832
  e !== null ? r.style.cursor = e : r.style.removeProperty("cursor");
833
833
  }, B = (r) => {
834
834
  const e = document.createElement("div");
@@ -1007,10 +1007,10 @@ const Q = Object.freeze({
1007
1007
  }, O = () => {
1008
1008
  const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
1009
1009
  return r.setAttribute("fill", `var(${Q.edgeColor})`), r;
1010
- }, Ce = () => {
1010
+ }, De = () => {
1011
1011
  const r = document.createElementNS("http://www.w3.org/2000/svg", "g");
1012
1012
  return r.style.transformOrigin = "50% 50%", r;
1013
- }, De = (r, e) => {
1013
+ }, Ce = (r, e) => {
1014
1014
  r.style.transform = `translate(${e.x}px, ${e.y}px)`, r.style.width = `${Math.max(e.width, 1)}px`, r.style.height = `${Math.max(e.height, 1)}px`;
1015
1015
  }, L = (r, e) => {
1016
1016
  const t = [];
@@ -1021,8 +1021,8 @@ const Q = Object.freeze({
1021
1021
  let c = 0, g = 0, l = 0;
1022
1022
  const u = d > 0, w = d < s, y = u && w;
1023
1023
  if (u && (c = -o, g = -n, l = a), w) {
1024
- const V = r[d + 1];
1025
- o = V.x - h.x, n = V.y - h.y, a = Math.sqrt(o * o + n * n);
1024
+ const F = r[d + 1];
1025
+ o = F.x - h.x, n = F.y - h.y, a = Math.sqrt(o * o + n * n);
1026
1026
  }
1027
1027
  const A = a !== 0 ? Math.min((y ? e : 0) / a, d < s - 1 ? 0.5 : 1) : 0, S = y ? { x: h.x + o * A, y: h.y + n * A } : h, P = l !== 0 ? Math.min((y ? e : 0) / l, d > 1 ? 0.5 : 1) : 0, N = y ? { x: h.x + c * P, y: h.y + g * P } : h;
1028
1028
  d > 0 && t.push(`L ${N.x} ${N.y}`), y && t.push(
@@ -1356,7 +1356,7 @@ const f = Object.freeze({
1356
1356
  class k {
1357
1357
  constructor(e) {
1358
1358
  i(this, "svg");
1359
- i(this, "group", Ce());
1359
+ i(this, "group", De());
1360
1360
  i(this, "line");
1361
1361
  i(this, "sourceArrow", null);
1362
1362
  i(this, "targetArrow", null);
@@ -1370,7 +1370,7 @@ class k {
1370
1370
  e.from,
1371
1371
  e.to
1372
1372
  );
1373
- De(this.svg, { x: t, y: s, width: o, height: n }), this.group.style.transform = `scale(${a}, ${h})`;
1373
+ Ce(this.svg, { x: t, y: s, width: o, height: n }), this.group.style.transform = `scale(${a}, ${h})`;
1374
1374
  const d = ge(
1375
1375
  e.from.direction,
1376
1376
  a,
@@ -1752,7 +1752,7 @@ class ft {
1752
1752
  class Ne {
1753
1753
  constructor(e) {
1754
1754
  i(this, "svg");
1755
- i(this, "group", Ce());
1755
+ i(this, "group", De());
1756
1756
  i(this, "line");
1757
1757
  i(this, "sourceArrow", null);
1758
1758
  i(this, "targetArrow", null);
@@ -1771,7 +1771,7 @@ class Ne {
1771
1771
  e.from,
1772
1772
  e.to
1773
1773
  );
1774
- De(this.svg, { x: t, y: s, width: o, height: n }), this.group.style.transform = `scale(${a}, ${h})`;
1774
+ Ce(this.svg, { x: t, y: s, width: o, height: n }), this.group.style.transform = `scale(${a}, ${h})`;
1775
1775
  const d = { x: o, y: n }, c = new at({
1776
1776
  to: d,
1777
1777
  sourceOffset: this.sourceOffset,
@@ -1986,7 +1986,7 @@ class Re {
1986
1986
  return { ...this.viewportStore.getContentMatrix() };
1987
1987
  }
1988
1988
  }
1989
- const Fe = (r, e) => {
1989
+ const Ve = (r, e) => {
1990
1990
  const t = new xe(), s = new Le(t), o = new Re(e), n = new me(t, e, r), a = {
1991
1991
  nodes: {
1992
1992
  centerFn: Se,
@@ -2033,7 +2033,7 @@ class z {
2033
2033
  }));
2034
2034
  });
2035
2035
  i(this, "onWindowMouseMove", (e) => {
2036
- if (!F(
2036
+ if (!V(
2037
2037
  this.window,
2038
2038
  this.element,
2039
2039
  e.clientX,
@@ -2064,7 +2064,7 @@ class z {
2064
2064
  });
2065
2065
  i(this, "onWindowTouchMove", (e) => {
2066
2066
  const t = e.touches[0];
2067
- if (!F(
2067
+ if (!V(
2068
2068
  this.window,
2069
2069
  this.element,
2070
2070
  t.clientX,
@@ -2116,7 +2116,7 @@ class z {
2116
2116
  this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
2117
2117
  }
2118
2118
  }
2119
- class J {
2119
+ class q {
2120
2120
  constructor(e, t, s, o) {
2121
2121
  i(this, "grabbedNode", null);
2122
2122
  i(this, "maxNodePriority", 0);
@@ -2196,7 +2196,7 @@ class J {
2196
2196
  });
2197
2197
  });
2198
2198
  i(this, "onWindowMouseMove", (e) => {
2199
- if (!F(
2199
+ if (!V(
2200
2200
  this.window,
2201
2201
  this.element,
2202
2202
  e.clientX,
@@ -2217,7 +2217,7 @@ class J {
2217
2217
  if (e.touches.length !== 1)
2218
2218
  return;
2219
2219
  const t = e.touches[0];
2220
- if (!F(
2220
+ if (!V(
2221
2221
  this.window,
2222
2222
  this.element,
2223
2223
  t.clientX,
@@ -2237,7 +2237,7 @@ class J {
2237
2237
  this.canvas = e, this.element = t, this.window = s, this.params = o, this.graph = e.graph, this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.graph.onBeforeClear.subscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
2238
2238
  }
2239
2239
  static configure(e, t, s, o) {
2240
- new J(e, t, s, o);
2240
+ new q(e, t, s, o);
2241
2241
  }
2242
2242
  moveNode(e, t) {
2243
2243
  if (this.graph.getNode(e.nodeId) === null)
@@ -2292,7 +2292,7 @@ class J {
2292
2292
  x: e.x - t.x,
2293
2293
  y: e.y - t.y
2294
2294
  }, o = this.canvas.viewport.getViewportMatrix();
2295
- return D(o, s);
2295
+ return C(o, s);
2296
2296
  }
2297
2297
  adjustNodeCoords(e) {
2298
2298
  const t = this.params.gridSize;
@@ -2350,7 +2350,7 @@ class H {
2350
2350
  }), this.startRegisteredTransform());
2351
2351
  });
2352
2352
  i(this, "onWindowMouseMove", (e) => {
2353
- const t = F(
2353
+ const t = V(
2354
2354
  this.window,
2355
2355
  this.element,
2356
2356
  e.clientX,
@@ -2390,7 +2390,7 @@ class H {
2390
2390
  i(this, "onWindowTouchMove", (e) => {
2391
2391
  const t = $(e);
2392
2392
  if (!t.touches.every(
2393
- (o) => F(this.window, this.element, o[0], o[1])
2393
+ (o) => V(this.window, this.element, o[0], o[1])
2394
2394
  )) {
2395
2395
  this.stopTouchDrag();
2396
2396
  return;
@@ -2472,7 +2472,7 @@ class H {
2472
2472
  this.transformInProgress = !1, this.params.onTransformFinished();
2473
2473
  }
2474
2474
  }
2475
- class q {
2475
+ class J {
2476
2476
  constructor(e, t, s, o, n, a) {
2477
2477
  i(this, "canvasResizeObserver");
2478
2478
  i(this, "nodeHorizontal");
@@ -2531,7 +2531,7 @@ class q {
2531
2531
  ), this.viewportMatrix = this.viewport.getViewportMatrix(), this.trigger.subscribe(this.updateLoadedArea), this.canvasResizeObserver.observe(this.element), this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated);
2532
2532
  }
2533
2533
  static configure(e, t, s, o, n, a) {
2534
- new q(
2534
+ new J(
2535
2535
  e,
2536
2536
  t,
2537
2537
  s,
@@ -2611,7 +2611,7 @@ class ee {
2611
2611
  i(this, "onEdgeCreated", (e) => {
2612
2612
  this.params.onAfterEdgeCreated(e);
2613
2613
  });
2614
- this.canvas = e, this.overlayLayer = t, this.viewportStore = s, this.window = o, this.params = n, this.overlayCanvas = Fe(
2614
+ this.canvas = e, this.overlayLayer = t, this.viewportStore = s, this.window = o, this.params = n, this.overlayCanvas = Ve(
2615
2615
  this.overlayLayer,
2616
2616
  this.viewportStore
2617
2617
  ), z.configure(
@@ -2649,10 +2649,10 @@ class ee {
2649
2649
  grabPort(e, t, s) {
2650
2650
  const o = this.canvas.graph.getPort(e);
2651
2651
  this.staticPortId = e;
2652
- const n = o.element.getBoundingClientRect(), a = n.x + n.width / 2, h = n.y + n.height / 2, d = this.overlayLayer.getBoundingClientRect(), c = this.canvas.viewport.getViewportMatrix(), g = D(c, {
2652
+ const n = o.element.getBoundingClientRect(), a = n.x + n.width / 2, h = n.y + n.height / 2, d = this.overlayLayer.getBoundingClientRect(), c = this.canvas.viewport.getViewportMatrix(), g = C(c, {
2653
2653
  x: a - d.x,
2654
2654
  y: h - d.y
2655
- }), l = D(c, {
2655
+ }), l = C(c, {
2656
2656
  x: t.x - d.x,
2657
2657
  y: t.y - d.y
2658
2658
  }), u = {
@@ -2691,7 +2691,7 @@ class ee {
2691
2691
  const t = this.overlayLayer.getBoundingClientRect(), s = {
2692
2692
  x: e.x - t.x,
2693
2693
  y: e.y - t.y
2694
- }, o = this.canvas.viewport.getViewportMatrix(), n = D(o, s);
2694
+ }, o = this.canvas.viewport.getViewportMatrix(), n = C(o, s);
2695
2695
  this.overlayCanvas.updateNode(T.Dragging, {
2696
2696
  x: n.x,
2697
2697
  y: n.y
@@ -2707,7 +2707,7 @@ class te {
2707
2707
  i(this, "onEdgeReattached", (e) => {
2708
2708
  this.params.onAfterEdgeReattached(e);
2709
2709
  });
2710
- this.canvas = e, this.overlayLayer = t, this.viewportStore = s, this.window = o, this.params = n, this.overlayCanvas = Fe(
2710
+ this.canvas = e, this.overlayLayer = t, this.viewportStore = s, this.window = o, this.params = n, this.overlayCanvas = Ve(
2711
2711
  this.overlayLayer,
2712
2712
  this.viewportStore
2713
2713
  ), z.configure(
@@ -2751,10 +2751,10 @@ class te {
2751
2751
  const d = this.canvas.graph.getPort(e), c = this.canvas.graph.getPort(h), g = c.element.getBoundingClientRect(), l = {
2752
2752
  x: g.x + g.width / 2,
2753
2753
  y: g.y + g.height / 2
2754
- }, u = this.canvas.viewport.getViewportMatrix(), w = this.overlayLayer.getBoundingClientRect(), y = D(u, {
2754
+ }, u = this.canvas.viewport.getViewportMatrix(), w = this.overlayLayer.getBoundingClientRect(), y = C(u, {
2755
2755
  x: l.x - w.x,
2756
2756
  y: l.y - w.y
2757
- }), x = D(u, {
2757
+ }), x = C(u, {
2758
2758
  x: t.x - w.x,
2759
2759
  y: t.y - w.y
2760
2760
  });
@@ -2773,12 +2773,12 @@ class te {
2773
2773
  overlayId: T.Dragging,
2774
2774
  portCoords: x,
2775
2775
  portDirection: d.direction
2776
- }, [C, P] = this.isTargetDragging ? [A, S] : [S, A];
2777
- this.overlayCanvas.addNode(B(C)), this.overlayCanvas.addNode(B(P));
2776
+ }, [D, P] = this.isTargetDragging ? [A, S] : [S, A];
2777
+ this.overlayCanvas.addNode(B(D)), this.overlayCanvas.addNode(B(P));
2778
2778
  const N = this.params.draggingEdgeShapeFactory !== null ? this.params.draggingEdgeShapeFactory(T.Edge) : o.shape;
2779
2779
  return this.overlayCanvas.addEdge({
2780
2780
  id: T.Edge,
2781
- from: C.overlayId,
2781
+ from: D.overlayId,
2782
2782
  to: P.overlayId,
2783
2783
  shape: N
2784
2784
  }), !0;
@@ -2790,7 +2790,7 @@ class te {
2790
2790
  const t = this.overlayLayer.getBoundingClientRect(), s = {
2791
2791
  x: e.x - t.x,
2792
2792
  y: e.y - t.y
2793
- }, o = this.canvas.viewport.getViewportMatrix(), n = D(o, s);
2793
+ }, o = this.canvas.viewport.getViewportMatrix(), n = C(o, s);
2794
2794
  this.overlayCanvas.updateNode(T.Dragging, {
2795
2795
  x: n.x,
2796
2796
  y: n.y
@@ -2932,7 +2932,7 @@ class oe {
2932
2932
  new oe(e, t, s, o);
2933
2933
  }
2934
2934
  }
2935
- const Ct = () => {
2935
+ const Dt = () => {
2936
2936
  const r = document.createElement("div");
2937
2937
  return r.style.width = "100%", r.style.height = "100%", r.style.position = "relative", r;
2938
2938
  }, Y = () => {
@@ -2942,13 +2942,13 @@ const Ct = () => {
2942
2942
  const r = Y();
2943
2943
  return r.style.pointerEvents = "none", r;
2944
2944
  };
2945
- class Dt {
2945
+ class Ct {
2946
2946
  constructor(e) {
2947
2947
  i(this, "background", Y());
2948
2948
  i(this, "main", Y());
2949
2949
  i(this, "overlayConnectablePorts", pe());
2950
2950
  i(this, "overlayDraggableEdges", pe());
2951
- i(this, "host", Ct());
2951
+ i(this, "host", Dt());
2952
2952
  this.element = e, this.element.appendChild(this.host), this.host.appendChild(this.background), this.host.appendChild(this.main), this.host.appendChild(this.overlayConnectablePorts), this.host.appendChild(this.overlayDraggableEdges);
2953
2953
  }
2954
2954
  destroy() {
@@ -3055,11 +3055,11 @@ const G = (r) => () => r, we = G(0), Nt = () => {
3055
3055
  }
3056
3056
  };
3057
3057
  }, Rt = (r) => {
3058
- var w, y, x, A, S, C;
3058
+ var w, y, x, A, S, D;
3059
3059
  const e = ((w = r.events) == null ? void 0 : w.onNodeDragStarted) ?? (() => {
3060
3060
  }), t = ((y = r.events) == null ? void 0 : y.onNodeDrag) ?? (() => {
3061
3061
  }), s = r.nodeDragVerifier ?? (() => !0), o = ((x = r.events) == null ? void 0 : x.onNodeDragFinished) ?? (() => {
3062
- }), n = r.moveOnTop !== !1, a = r.moveEdgesOnTop !== !1 && n, h = (A = r.mouse) == null ? void 0 : A.dragCursor, d = h !== void 0 ? h : "grab", c = (S = r.mouse) == null ? void 0 : S.mouseDownEventVerifier, g = c !== void 0 ? c : (P) => P.button === 0, l = (C = r.mouse) == null ? void 0 : C.mouseUpEventVerifier, u = l !== void 0 ? l : (P) => P.button === 0;
3062
+ }), n = r.moveOnTop !== !1, a = r.moveEdgesOnTop !== !1 && n, h = (A = r.mouse) == null ? void 0 : A.dragCursor, d = h !== void 0 ? h : "grab", c = (S = r.mouse) == null ? void 0 : S.mouseDownEventVerifier, g = c !== void 0 ? c : (P) => P.button === 0, l = (D = r.mouse) == null ? void 0 : D.mouseUpEventVerifier, u = l !== void 0 ? l : (P) => P.button === 0;
3063
3063
  return {
3064
3064
  moveOnTop: n,
3065
3065
  moveEdgesOnTop: a,
@@ -3072,7 +3072,7 @@ const G = (r) => () => r, we = G(0), Nt = () => {
3072
3072
  nodeDragVerifier: s,
3073
3073
  onNodeDragFinished: o
3074
3074
  };
3075
- }, Ft = (r) => {
3075
+ }, Vt = (r) => {
3076
3076
  const e = r.minX !== null ? r.minX : -1 / 0, t = r.maxX !== null ? r.maxX : 1 / 0, s = r.minY !== null ? r.minY : -1 / 0, o = r.maxY !== null ? r.maxY : 1 / 0;
3077
3077
  return (n) => {
3078
3078
  let a = n.nextTransform.x, h = n.nextTransform.y;
@@ -3082,7 +3082,7 @@ const G = (r) => () => r, we = G(0), Nt = () => {
3082
3082
  const g = n.canvasHeight * n.prevTransform.scale, l = o - g;
3083
3083
  return h > l && h > n.prevTransform.y && (h = Math.max(n.prevTransform.y, l)), { scale: n.nextTransform.scale, x: a, y: h };
3084
3084
  };
3085
- }, Vt = (r) => {
3085
+ }, Ft = (r) => {
3086
3086
  const e = r.maxContentScale, t = r.minContentScale, s = e !== null ? 1 / e : 0, o = t !== null ? 1 / t : 1 / 0;
3087
3087
  return (n) => {
3088
3088
  const a = n.prevTransform, h = n.nextTransform;
@@ -3116,12 +3116,12 @@ const G = (r) => () => r, we = G(0), Nt = () => {
3116
3116
  return r;
3117
3117
  switch (r.type) {
3118
3118
  case "scale-limit":
3119
- return Vt({
3119
+ return Ft({
3120
3120
  minContentScale: r.minContentScale ?? 0,
3121
3121
  maxContentScale: r.maxContentScale ?? 1 / 0
3122
3122
  });
3123
3123
  case "shift-limit":
3124
- return Ft({
3124
+ return Vt({
3125
3125
  minX: r.minX ?? -1 / 0,
3126
3126
  maxX: r.maxX ?? 1 / 0,
3127
3127
  minY: r.minY ?? -1 / 0,
@@ -3129,7 +3129,7 @@ const G = (r) => () => r, we = G(0), Nt = () => {
3129
3129
  });
3130
3130
  }
3131
3131
  }, ye = (r) => {
3132
- var y, x, A, S, C, P, N, V, ne, ae, he, de;
3132
+ var y, x, A, S, D, P, N, F, ne, ae, he, de;
3133
3133
  const e = (y = r == null ? void 0 : r.scale) == null ? void 0 : y.mouseWheelSensitivity, t = e !== void 0 ? e : 1.2, s = r == null ? void 0 : r.transformPreprocessor;
3134
3134
  let o;
3135
3135
  s !== void 0 ? Array.isArray(s) ? o = It(
@@ -3139,10 +3139,10 @@ const G = (r) => () => r, we = G(0), Nt = () => {
3139
3139
  ) : o = fe(s) : o = (M) => M.nextTransform;
3140
3140
  const n = ((x = r == null ? void 0 : r.shift) == null ? void 0 : x.cursor) !== void 0 ? r.shift.cursor : "grab", a = ((A = r == null ? void 0 : r.events) == null ? void 0 : A.onBeforeTransformChange) ?? (() => {
3141
3141
  }), h = ((S = r == null ? void 0 : r.events) == null ? void 0 : S.onTransformChange) ?? (() => {
3142
- }), d = (C = r == null ? void 0 : r.shift) == null ? void 0 : C.mouseDownEventVerifier, c = d !== void 0 ? d : (M) => M.button === 0, g = (P = r == null ? void 0 : r.shift) == null ? void 0 : P.mouseUpEventVerifier, l = g !== void 0 ? g : (M) => M.button === 0, u = (N = r == null ? void 0 : r.scale) == null ? void 0 : N.mouseWheelEventVerifier, w = u !== void 0 ? u : () => !0;
3142
+ }), d = (D = r == null ? void 0 : r.shift) == null ? void 0 : D.mouseDownEventVerifier, c = d !== void 0 ? d : (M) => M.button === 0, g = (P = r == null ? void 0 : r.shift) == null ? void 0 : P.mouseUpEventVerifier, l = g !== void 0 ? g : (M) => M.button === 0, u = (N = r == null ? void 0 : r.scale) == null ? void 0 : N.mouseWheelEventVerifier, w = u !== void 0 ? u : () => !0;
3143
3143
  return {
3144
3144
  wheelSensitivity: t,
3145
- onTransformStarted: ((V = r == null ? void 0 : r.events) == null ? void 0 : V.onTransformStarted) ?? (() => {
3145
+ onTransformStarted: ((F = r == null ? void 0 : r.events) == null ? void 0 : F.onTransformStarted) ?? (() => {
3146
3146
  }),
3147
3147
  onTransformFinished: ((ne = r == null ? void 0 : r.events) == null ? void 0 : ne.onTransformFinished) ?? (() => {
3148
3148
  }),
@@ -3230,7 +3230,7 @@ class Ht extends Error {
3230
3230
  i(this, "name", "CanvasBuilderError");
3231
3231
  }
3232
3232
  }
3233
- class Ve {
3233
+ class Fe {
3234
3234
  constructor(e, t, s) {
3235
3235
  i(this, "dt");
3236
3236
  i(this, "nodeMass");
@@ -3241,17 +3241,22 @@ class Ve {
3241
3241
  this.graph = e, this.currentCoords = t, this.dt = s.dtSec, this.nodeMass = s.nodeMass, this.edgeEquilibriumLength = s.edgeEquilibriumLength, this.edgeStiffness = s.edgeStiffness, this.distanceVectorGenerator = s.distanceVectorGenerator, this.nodeForcesApplicationStrategy = s.nodeForcesApplicationStrategy;
3242
3242
  }
3243
3243
  apply() {
3244
- let e = 0;
3245
- const t = /* @__PURE__ */ new Map();
3246
- return this.graph.getAllNodeIds().forEach((o) => {
3247
- t.set(o, { x: 0, y: 0 });
3248
- }), this.nodeForcesApplicationStrategy.apply(this.currentCoords, t), this.applyEdgeForces(t), this.currentCoords.forEach((o, n) => {
3249
- const a = t.get(n), h = {
3250
- x: a.x / this.nodeMass * this.dt,
3251
- y: a.y / this.nodeMass * this.dt
3252
- }, d = h.x * this.dt, c = h.y * this.dt;
3253
- o.x += d, o.y += c, e = Math.max(e, Math.sqrt(d * d + c * c));
3254
- }), e;
3244
+ let e = 0, t = 0;
3245
+ const s = /* @__PURE__ */ new Map();
3246
+ return this.graph.getAllNodeIds().forEach((n) => {
3247
+ s.set(n, { x: 0, y: 0 });
3248
+ }), this.nodeForcesApplicationStrategy.apply(this.currentCoords, s), this.applyEdgeForces(s), this.currentCoords.forEach((n, a) => {
3249
+ const h = s.get(a), d = {
3250
+ x: h.x / this.nodeMass * this.dt,
3251
+ y: h.y / this.nodeMass * this.dt
3252
+ };
3253
+ t = Math.max(
3254
+ t,
3255
+ Math.sqrt(d.x * d.x + d.y * d.y)
3256
+ );
3257
+ const c = d.x * this.dt, g = d.y * this.dt;
3258
+ n.x += c, n.y += g, e = Math.max(e, Math.sqrt(c * c + g * g));
3259
+ }), [e, t];
3255
3260
  }
3256
3261
  applyEdgeForces(e) {
3257
3262
  this.graph.getAllEdgeIds().forEach((t) => {
@@ -3704,19 +3709,22 @@ class Kt {
3704
3709
  this.params.rand,
3705
3710
  this.params.edgeEquilibriumLength
3706
3711
  );
3707
- for (let s = 0; s < this.params.maxIterations && !(new Ve(
3708
- e,
3709
- t,
3710
- {
3711
- distanceVectorGenerator: this.distanceVectorGenerator,
3712
- nodeForcesApplicationStrategy: this.nodeForcesApplicationStrategy,
3713
- dtSec: this.params.dtSec,
3714
- nodeMass: this.params.nodeMass,
3715
- edgeEquilibriumLength: this.params.edgeEquilibriumLength,
3716
- edgeStiffness: this.params.edgeStiffness
3717
- }
3718
- ).apply() < this.params.convergenceDelta); s++)
3719
- ;
3712
+ for (let s = 0; s < this.params.maxIterations; s++) {
3713
+ const o = new Fe(
3714
+ e,
3715
+ t,
3716
+ {
3717
+ distanceVectorGenerator: this.distanceVectorGenerator,
3718
+ nodeForcesApplicationStrategy: this.nodeForcesApplicationStrategy,
3719
+ dtSec: this.params.dtSec,
3720
+ nodeMass: this.params.nodeMass,
3721
+ edgeEquilibriumLength: this.params.edgeEquilibriumLength,
3722
+ edgeStiffness: this.params.edgeStiffness
3723
+ }
3724
+ ), [n, a] = o.apply();
3725
+ if (n < this.params.convergenceDelta || a < this.params.convergenceVelocity)
3726
+ break;
3727
+ }
3720
3728
  return t;
3721
3729
  }
3722
3730
  }
@@ -3724,37 +3732,44 @@ class Qt {
3724
3732
  constructor(e) {
3725
3733
  i(this, "distanceVectorGenerator");
3726
3734
  i(this, "nodeForcesApplicationStrategy");
3727
- this.params = e, this.distanceVectorGenerator = new $e(e.rand), this.nodeForcesApplicationStrategy = Be({
3735
+ i(this, "convergenceDelta");
3736
+ i(this, "convergenceVelocity");
3737
+ i(this, "maxTimeDeltaSec");
3738
+ i(this, "nodeMass");
3739
+ i(this, "edgeEquilibriumLength");
3740
+ i(this, "edgeStiffness");
3741
+ i(this, "rand");
3742
+ this.convergenceDelta = e.convergenceDelta, this.convergenceVelocity = e.convergenceVelocity, this.maxTimeDeltaSec = e.maxTimeDeltaSec, this.nodeMass = e.nodeMass, this.edgeEquilibriumLength = e.edgeEquilibriumLength, this.edgeStiffness = e.edgeStiffness, this.rand = e.rand, this.distanceVectorGenerator = new $e(e.rand), this.nodeForcesApplicationStrategy = Be({
3728
3743
  distanceVectorGenerator: this.distanceVectorGenerator,
3729
- nodeCharge: this.params.nodeCharge,
3730
- effectiveDistance: this.params.effectiveDistance,
3731
- maxForce: this.params.maxForce,
3732
- nodeForceCoefficient: this.params.nodeForceCoefficient,
3733
- theta: this.params.barnesHutTheta,
3734
- areaRadiusThreshold: this.params.barnesHutAreaRadiusThreshold,
3735
- nodeMass: this.params.nodeMass
3744
+ nodeCharge: e.nodeCharge,
3745
+ effectiveDistance: e.effectiveDistance,
3746
+ maxForce: e.maxForce,
3747
+ nodeForceCoefficient: e.nodeForceCoefficient,
3748
+ theta: e.barnesHutTheta,
3749
+ areaRadiusThreshold: e.barnesHutAreaRadiusThreshold,
3750
+ nodeMass: e.nodeMass
3736
3751
  });
3737
3752
  }
3738
3753
  calculateNextCoordinates(e, t) {
3739
3754
  const s = Ie(
3740
3755
  e,
3741
- this.params.rand,
3742
- this.params.edgeEquilibriumLength
3743
- );
3744
- return new Ve(
3756
+ this.rand,
3757
+ this.edgeEquilibriumLength
3758
+ ), o = new Fe(
3745
3759
  e,
3746
3760
  s,
3747
3761
  {
3748
3762
  distanceVectorGenerator: this.distanceVectorGenerator,
3749
3763
  nodeForcesApplicationStrategy: this.nodeForcesApplicationStrategy,
3750
- dtSec: Math.min(t, this.params.maxTimeDeltaSec),
3751
- nodeMass: this.params.nodeMass,
3752
- edgeEquilibriumLength: this.params.edgeEquilibriumLength,
3753
- edgeStiffness: this.params.edgeStiffness
3764
+ dtSec: Math.min(t, this.maxTimeDeltaSec),
3765
+ nodeMass: this.nodeMass,
3766
+ edgeEquilibriumLength: this.edgeEquilibriumLength,
3767
+ edgeStiffness: this.edgeStiffness
3754
3768
  }
3755
- ).apply() < this.params.convergenceDelta && !e.getAllNodeIds().some((h) => {
3756
- const d = e.getNode(h);
3757
- return d.x === null || d.y === null;
3769
+ ), [n, a] = o.apply();
3770
+ return (n < this.convergenceDelta || a < this.convergenceVelocity) && !e.getAllNodeIds().some((d) => {
3771
+ const c = e.getNode(d);
3772
+ return c.x === null || c.y === null;
3758
3773
  }) ? /* @__PURE__ */ new Map() : s;
3759
3774
  }
3760
3775
  }
@@ -3777,7 +3792,8 @@ const Oe = (r) => {
3777
3792
  effectiveDistance: 1e3,
3778
3793
  dtSec: 0.01,
3779
3794
  maxIterations: 1e3,
3780
- convergenceDelta: 1,
3795
+ convergenceDelta: 0,
3796
+ convergenceVelocity: 10,
3781
3797
  maxForce: 1e7,
3782
3798
  nodeForceCoefficient: 1,
3783
3799
  barnesHutAreaRadiusThreshold: 0.01,
@@ -3798,6 +3814,7 @@ const Oe = (r) => {
3798
3814
  effectiveDistance: v.effectiveDistance,
3799
3815
  edgeStiffness: (o == null ? void 0 : o.edgeStiffness) ?? v.edgeStiffness,
3800
3816
  convergenceDelta: (o == null ? void 0 : o.convergenceDelta) ?? v.convergenceDelta,
3817
+ convergenceVelocity: (o == null ? void 0 : o.convergenceVelocity) ?? v.convergenceVelocity,
3801
3818
  maxForce: (o == null ? void 0 : o.maxForce) ?? v.maxForce,
3802
3819
  nodeForceCoefficient: (o == null ? void 0 : o.nodeForceCoefficient) ?? v.nodeForceCoefficient,
3803
3820
  barnesHutTheta: ((t = o == null ? void 0 : o.barnesHut) == null ? void 0 : t.theta) ?? v.barnesHutTheta,
@@ -3805,12 +3822,12 @@ const Oe = (r) => {
3805
3822
  });
3806
3823
  }
3807
3824
  }
3808
- }, Jt = (r) => r instanceof j ? {
3825
+ }, qt = (r) => r instanceof j ? {
3809
3826
  type: "manual",
3810
3827
  trigger: r
3811
3828
  } : {
3812
3829
  type: "topologyChangeTimeout"
3813
- }, qt = (r) => {
3830
+ }, Jt = (r) => {
3814
3831
  var e, t;
3815
3832
  switch (r == null ? void 0 : r.type) {
3816
3833
  case "custom":
@@ -3827,6 +3844,7 @@ const Oe = (r) => {
3827
3844
  edgeStiffness: (r == null ? void 0 : r.edgeStiffness) ?? v.edgeStiffness,
3828
3845
  effectiveDistance: (r == null ? void 0 : r.effectiveDistance) ?? v.effectiveDistance,
3829
3846
  convergenceDelta: (r == null ? void 0 : r.convergenceDelta) ?? v.convergenceDelta,
3847
+ convergenceVelocity: (r == null ? void 0 : r.convergenceVelocity) ?? v.convergenceVelocity,
3830
3848
  maxForce: (r == null ? void 0 : r.maxForce) ?? v.maxForce,
3831
3849
  nodeForceCoefficient: (r == null ? void 0 : r.nodeForceCoefficient) ?? v.nodeForceCoefficient,
3832
3850
  barnesHutTheta: ((e = r == null ? void 0 : r.barnesHut) == null ? void 0 : e.theta) ?? v.barnesHutTheta,
@@ -3835,8 +3853,8 @@ const Oe = (r) => {
3835
3853
  }
3836
3854
  }
3837
3855
  }, _t = (r) => ({
3838
- algorithm: qt(r == null ? void 0 : r.algorithm),
3839
- applyOn: Jt(r == null ? void 0 : r.applyOn)
3856
+ algorithm: Jt(r == null ? void 0 : r.algorithm),
3857
+ applyOn: qt(r == null ? void 0 : r.applyOn)
3840
3858
  }), er = (r, e) => ({
3841
3859
  ...r,
3842
3860
  onNodeDragStarted: (t) => {
@@ -3949,7 +3967,7 @@ class or {
3949
3967
  if (this.used)
3950
3968
  throw new Ht("CanvasBuilder is a single use object");
3951
3969
  this.used = !0;
3952
- const e = new Dt(this.element);
3970
+ const e = new Ct(this.element);
3953
3971
  let t = new me(
3954
3972
  this.graphStore,
3955
3973
  this.viewportStore,
@@ -3978,7 +3996,7 @@ class or {
3978
3996
  this.hasAnimatedLayout && (a = er(
3979
3997
  a,
3980
3998
  this.animationStaticNodes
3981
- )), J.configure(
3999
+ )), q.configure(
3982
4000
  o,
3983
4001
  e.main,
3984
4002
  this.window,
@@ -4012,7 +4030,7 @@ class or {
4012
4030
  a
4013
4031
  );
4014
4032
  }
4015
- this.virtualScrollConfig !== void 0 ? q.configure(
4033
+ this.virtualScrollConfig !== void 0 ? J.configure(
4016
4034
  o,
4017
4035
  e.main,
4018
4036
  this.window,
@@ -1 +1 @@
1
- (function(E,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(E=typeof globalThis<"u"?globalThis:E||self,x(E.HtmlGraph={}))})(this,function(E){"use strict";var sr=Object.defineProperty;var or=(E,x,C)=>x in E?sr(E,x,{enumerable:!0,configurable:!0,writable:!0,value:C}):E[x]=C;var i=(E,x,C)=>or(E,typeof x!="symbol"?x+"":x,C);const x=(r,e)=>({x:r.scale*e.x+r.x,y:r.scale*e.y+r.y});var C=(r=>(r.Line="line",r.NodeCycle="node-cycle",r.PortCycle="port-cycle",r))(C||{});const Ke=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r.style.overflow="hidden",r},Qe=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="0",r.style.height="0",r},Ze=r=>{r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.visibility="hidden"};class de{constructor(e,t,s){i(this,"host",Ke());i(this,"container",Qe());i(this,"edgeIdToElementMap",new Map);i(this,"attachedNodeIds",new Set);i(this,"applyTransform",()=>{const e=this.viewportStore.getContentMatrix();this.container.style.transform=`matrix(${e.scale}, 0, 0, ${e.scale}, ${e.x}, ${e.y})`});this.graphStore=e,this.viewportStore=t,this.element=s,this.element.appendChild(this.host),this.host.appendChild(this.container),this.viewportStore.onAfterUpdated.subscribe(this.applyTransform)}attachNode(e){const t=this.graphStore.getNode(e);Ze(t.element),this.attachedNodeIds.add(e),this.container.appendChild(t.element),this.updateNodePosition(e),this.updateNodePriority(e),t.element.style.visibility="visible"}detachNode(e){const t=this.graphStore.getNode(e);this.container.removeChild(t.element),this.attachedNodeIds.delete(e)}attachEdge(e){const t=this.graphStore.getEdge(e).payload.shape.svg;this.edgeIdToElementMap.set(e,t),this.container.appendChild(t),this.renderEdge(e),this.updateEdgePriority(e)}detachEdge(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t),this.edgeIdToElementMap.delete(e)}clear(){this.edgeIdToElementMap.forEach((e,t)=>{this.detachEdge(t)}),this.attachedNodeIds.forEach(e=>{this.detachNode(e)})}destroy(){this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform),this.element.removeChild(this.host),this.host.removeChild(this.container)}updateNodePosition(e){const t=this.graphStore.getNode(e),{width:s,height:o}=t.element.getBoundingClientRect(),n=this.viewportStore.getViewportMatrix().scale,{payload:a}=t,h=a.centerFn(s,o),d=a.x-n*h.x,c=a.y-n*h.y;t.element.style.transform=`translate(${d}px, ${c}px)`}updateNodePriority(e){const t=this.graphStore.getNode(e);t.element.style.zIndex=`${t.payload.priority}`}updateEdgeShape(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t);const o=this.graphStore.getEdge(e).payload.shape.svg;this.edgeIdToElementMap.set(e,o),this.container.appendChild(o)}renderEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),o=this.graphStore.getPort(t.to),n=s.element.getBoundingClientRect(),a=o.element.getBoundingClientRect(),h=this.host.getBoundingClientRect(),d=this.viewportStore.getViewportMatrix(),c=this.createEdgeRenderPort(s,n,h,d),g=this.createEdgeRenderPort(o,a,h,d);let l=C.Line;s.element===o.element?l=C.PortCycle:s.nodeId===o.nodeId&&(l=C.NodeCycle),t.payload.shape.render({from:c,to:g,category:l})}updateEdgePriority(e){const t=this.graphStore.getEdge(e);t.payload.shape.svg.style.zIndex=`${t.payload.priority}`}createEdgeRenderPort(e,t,s,o){const n={x:t.left-s.left,y:t.top-s.top},a=x(o,n);return{x:a.x,y:a.y,width:t.width*o.scale,height:t.height*o.scale,direction:e.payload.direction}}}class Je{constructor(e){i(this,"xFrom",1/0);i(this,"yFrom",1/0);i(this,"xTo",1/0);i(this,"yTo",1/0);this.graphStore=e}setRenderingBox(e){this.xFrom=e.x,this.xTo=e.x+e.width,this.yFrom=e.y,this.yTo=e.y+e.height}hasNode(e){const t=this.graphStore.getNode(e).payload,{x:s,y:o}=t;return s>=this.xFrom&&s<=this.xTo&&o>=this.yFrom&&o<=this.yTo}hasEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,o=this.graphStore.getPort(t.to).nodeId,n=this.graphStore.getNode(s).payload,a=this.graphStore.getNode(o).payload,h=Math.min(n.x,a.x),d=Math.max(n.x,a.x),c=Math.min(n.y,a.y),g=Math.max(n.y,a.y);return h<=this.xTo&&d>=this.xFrom&&c<=this.yTo&&g>=this.yFrom}}class qe{constructor(e,t,s,o){i(this,"attachedNodes",new Set);i(this,"attachedEdges",new Set);i(this,"renderingBox");i(this,"updateViewport",e=>{this.renderingBox.setRenderingBox(e);const t=new Set,s=new Set,o=new Set,n=new Set;this.graphStore.getAllNodeIds().forEach(a=>{const h=this.renderingBox.hasNode(a),d=this.attachedNodes.has(a);h&&!d?t.add(a):!h&&d&&s.add(a)}),this.graphStore.getAllEdgeIds().forEach(a=>{const h=this.renderingBox.hasEdge(a),d=this.attachedEdges.has(a),c=this.graphStore.getEdge(a),g=this.graphStore.getPort(c.from).nodeId,l=this.graphStore.getPort(c.to).nodeId;h&&(this.renderingBox.hasNode(g)||(t.add(g),s.delete(g)),this.renderingBox.hasNode(l)||(t.add(l),s.delete(l))),h&&!d?o.add(a):!h&&d&&n.add(a)}),n.forEach(a=>{this.handleDetachEdge(a)}),s.forEach(a=>{this.handleDetachNode(a)}),t.forEach(a=>{this.attachedNodes.has(a)||this.handleAttachNode(a)}),o.forEach(a=>{this.handleAttachEdge(a)})});this.htmlView=e,this.graphStore=t,this.trigger=s,this.params=o,this.renderingBox=new Je(this.graphStore),this.trigger.subscribe(this.updateViewport)}attachNode(e){this.renderingBox.hasNode(e)&&this.handleAttachNode(e)}detachNode(e){this.attachedNodes.has(e)&&this.handleDetachNode(e)}attachEdge(e){this.renderingBox.hasEdge(e)&&this.attachEdgeEntities(e)}detachEdge(e){this.attachedEdges.has(e)&&this.handleDetachEdge(e)}updateNodePosition(e){this.attachedNodes.has(e)?this.htmlView.updateNodePosition(e):this.renderingBox.hasNode(e)&&(this.handleAttachNode(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(t=>{this.attachEdgeEntities(t)}))}updateNodePriority(e){this.attachedNodes.has(e)&&this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgeShape(e)}renderEdge(e){this.attachedEdges.has(e)&&this.htmlView.renderEdge(e)}updateEdgePriority(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgePriority(e)}clear(){this.htmlView.clear(),this.attachedNodes.clear(),this.attachedEdges.clear()}destroy(){this.clear(),this.htmlView.destroy(),this.trigger.unsubscribe(this.updateViewport)}attachEdgeEntities(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,o=this.graphStore.getPort(t.to).nodeId;this.attachedNodes.has(s)||this.handleAttachNode(s),this.attachedNodes.has(o)||this.handleAttachNode(o),this.handleAttachEdge(e)}handleAttachNode(e){this.params.onBeforeNodeAttached(e),this.attachedNodes.add(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.attachedNodes.delete(e),this.params.onAfterNodeDetached(e)}handleAttachEdge(e){this.attachedEdges.add(e),this.htmlView.attachEdge(e)}handleDetachEdge(e){this.htmlView.detachEdge(e),this.attachedEdges.delete(e)}}class _e{constructor(e,t){i(this,"deferredNodes",new Set);i(this,"deferredEdges",new Set);this.htmlView=e,this.graphStore=t}attachNode(e){this.isNodeValid(e)?this.htmlView.attachNode(e):this.deferredNodes.add(e)}detachNode(e){this.deferredNodes.has(e)?this.deferredNodes.delete(e):this.htmlView.detachNode(e)}attachEdge(e){this.isEdgeValid(e)?this.htmlView.attachEdge(e):this.deferredEdges.add(e)}detachEdge(e){this.deferredEdges.has(e)?this.deferredEdges.delete(e):this.htmlView.detachEdge(e)}updateNodePosition(e){this.deferredNodes.has(e)?this.tryAttachNode(e):this.htmlView.updateNodePosition(e)}updateNodePriority(e){this.deferredNodes.has(e)?this.tryAttachNode(e):this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.updateEdgeShape(e)}renderEdge(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.renderEdge(e)}updateEdgePriority(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.updateEdgePriority(e)}clear(){this.deferredNodes.clear(),this.deferredEdges.clear(),this.htmlView.clear()}destroy(){this.htmlView.destroy()}isNodeValid(e){const t=this.graphStore.getNode(e);return!(t.payload.x===null||t.payload.y===null)}tryAttachNode(e){this.isNodeValid(e)&&(this.deferredNodes.delete(e),this.htmlView.attachNode(e))}isEdgeValid(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),o=this.graphStore.getPort(t.to);return!(this.deferredNodes.has(s.nodeId)||this.deferredNodes.has(o.nodeId))}tryAttachEdge(e){this.isEdgeValid(e)&&(this.deferredEdges.delete(e),this.htmlView.attachEdge(e))}}class U{constructor(){i(this,"callbacks",new Set)}subscribe(e){this.callbacks.add(e)}unsubscribe(e){this.callbacks.delete(e)}emit(e){this.callbacks.forEach(t=>{t(e)})}}const S=()=>{const r=new U;return[r,r]};class G{constructor(e){i(this,"counter",0);this.checkExists=e}create(e){if(e!==void 0)return e;for(;this.checkExists(this.counter);)this.counter++;return this.counter}reset(){this.counter=0}}class P extends Error{constructor(){super(...arguments);i(this,"name","CanvasError")}}class ce{constructor(e,t,s,o,n,a){i(this,"nodeIdGenerator",new G(e=>this.graphStore.getNode(e)!==void 0));i(this,"portIdGenerator",new G(e=>this.graphStore.getPort(e)!==void 0));i(this,"edgeIdGenerator",new G(e=>this.graphStore.getEdge(e)!==void 0));i(this,"onAfterNodeAdded",e=>{this.htmlView.attachNode(e)});i(this,"onAfterNodeUpdated",e=>{this.htmlView.updateNodePosition(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});i(this,"onAfterNodePriorityUpdated",e=>{this.htmlView.updateNodePriority(e)});i(this,"onBeforeNodeRemoved",e=>{this.graphStore.getNodePortIds(e).forEach(t=>{this.unmarkPort(t)}),this.htmlView.detachNode(e)});i(this,"onAfterPortUpdated",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});i(this,"onBeforePortUnmarked",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(t=>{this.removeEdge(t)})});i(this,"onAfterEdgeAdded",e=>{this.htmlView.attachEdge(e)});i(this,"onAfterEdgeShapeUpdated",e=>{this.htmlView.updateEdgeShape(e)});i(this,"onAfterEdgeUpdated",e=>{this.htmlView.renderEdge(e)});i(this,"onAfterEdgePriorityUpdated",e=>{this.htmlView.updateEdgePriority(e)});i(this,"onBeforeEdgeRemoved",e=>{this.htmlView.detachEdge(e)});i(this,"onBeforeClear",()=>{this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset(),this.htmlView.clear()});i(this,"onBeforeDestroyEmitter");i(this,"destroyed",!1);i(this,"onBeforeDestroy");this.graph=e,this.viewport=t,this.graphStore=s,this.viewportStore=o,this.htmlView=n,this.params=a,this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.subscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.subscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.subscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.subscribe(this.onBeforeClear),[this.onBeforeDestroyEmitter,this.onBeforeDestroy]=S()}addNode(e){const t=this.nodeIdGenerator.create(e.id);if(this.graphStore.getNode(t)!==void 0)throw new P("failed to add node with existing id");if(this.graphStore.getElementNodeId(e.element)!==void 0)throw new P("failed to add node with html element already in use by another node");if(this.graphStore.addNode({id:t,element:e.element,x:e.x??null,y:e.y??null,centerFn:e.centerFn??this.params.nodes.centerFn,priority:e.priority??this.params.nodes.priorityFn()}),e.ports!==void 0)for(const s of e.ports)this.markPort({id:s.id,element:s.element,nodeId:t,direction:s.direction});return this}updateNode(e,t){if(this.graphStore.getNode(e)===void 0)throw new P("failed to update nonexistent node");return this.graphStore.updateNode(e,t??{}),this}removeNode(e){if(this.graphStore.getNode(e)===void 0)throw new P("failed to remove nonexistent node");return this.graphStore.removeNode(e),this}markPort(e){const t=this.portIdGenerator.create(e.id);if(this.graphStore.getPort(t)!==void 0)throw new P("failed to add port with existing id");if(this.graphStore.getNode(e.nodeId)===void 0)throw new P("failed to mark port for nonexistent node");return this.graphStore.addPort({id:t,element:e.element,nodeId:e.nodeId,direction:e.direction??this.params.ports.direction}),this}updatePort(e,t){if(this.graphStore.getPort(e)===void 0)throw new P("failed to update nonexistent port");return this.graphStore.updatePort(e,t??{}),this}unmarkPort(e){if(this.graphStore.getPort(e)===void 0)throw new P("failed to unmark nonexistent port");return this.graphStore.removePort(e),this}addEdge(e){const t=this.edgeIdGenerator.create(e.id);if(this.graphStore.getEdge(t)!==void 0)throw new P("failed to add edge with existing id");if(this.graphStore.getPort(e.from)===void 0)throw new P("failed to add edge from nonexistent port");if(this.graphStore.getPort(e.to)===void 0)throw new P("failed to add edge to nonexistent port");return this.graphStore.addEdge({id:t,from:e.from,to:e.to,shape:e.shape??this.params.edges.shapeFactory(t),priority:e.priority??this.params.edges.priorityFn()}),this}updateEdge(e,t){if(this.graphStore.getEdge(e)===void 0)throw new P("failed to update nonexistent edge");return this.graphStore.updateEdge(e,t??{}),this}removeEdge(e){if(this.graphStore.getEdge(e)===void 0)throw new P("failed to remove nonexistent edge");return this.graphStore.removeEdge(e),this}clear(){return this.graphStore.clear(),this}patchViewportMatrix(e){return this.viewportStore.patchViewportMatrix(e),this}patchContentMatrix(e){return this.viewportStore.patchContentMatrix(e),this}destroy(){this.destroyed||(this.clear(),this.onBeforeDestroyEmitter.emit(),this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.unsubscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear),this.htmlView.destroy(),this.destroyed=!0)}}class et{constructor(){i(this,"singleToMultiMap",new Map);i(this,"multiToSingleMap",new Map)}addRecord(e,t){const s=this.singleToMultiMap.get(e);s===void 0?this.singleToMultiMap.set(e,new Set([t])):s.add(t),this.multiToSingleMap.set(t,e)}getMultiBySingle(e){const t=this.singleToMultiMap.get(e)??new Set;return Array.from(t.values())}removeByMulti(e){const t=this.multiToSingleMap.get(e),s=this.singleToMultiMap.get(t);s.delete(e),s.size===0&&this.singleToMultiMap.delete(t),this.multiToSingleMap.delete(e)}getByMulti(e){return this.multiToSingleMap.get(e)}removeBySingle(e){this.singleToMultiMap.get(e).forEach(s=>{this.multiToSingleMap.delete(s)}),this.singleToMultiMap.delete(e)}clear(){this.singleToMultiMap.clear(),this.multiToSingleMap.clear()}forEachSingle(e){this.singleToMultiMap.forEach((t,s)=>{e(s)})}hasSingle(e){return this.singleToMultiMap.get(e)!==void 0}hasMulti(e){return this.multiToSingleMap.get(e)!==void 0}}class le{constructor(){i(this,"nodes",new Map);i(this,"ports",new Map);i(this,"edges",new Map);i(this,"nodesElementsMap",new Map);i(this,"portIncomingEdges",new Map);i(this,"portOutcomingEdges",new Map);i(this,"portCycleEdges",new Map);i(this,"elementPorts",new et);i(this,"afterNodeAddedEmitter");i(this,"onAfterNodeAdded");i(this,"afterNodeUpdatedEmitter");i(this,"onAfterNodeUpdated");i(this,"afterNodePriorityUpdatedEmitter");i(this,"onAfterNodePriorityUpdated");i(this,"beforeNodeRemovedEmitter");i(this,"onBeforeNodeRemoved");i(this,"afterPortAddedEmitter");i(this,"onAfterPortAdded");i(this,"afterPortUpdatedEmitter");i(this,"onAfterPortUpdated");i(this,"beforePortRemovedEmitter");i(this,"onBeforePortRemoved");i(this,"afterEdgeAddedEmitter");i(this,"onAfterEdgeAdded");i(this,"afterEdgeShapeUpdatedEmitter");i(this,"onAfterEdgeShapeUpdated");i(this,"afterEdgeUpdatedEmitter");i(this,"onAfterEdgeUpdated");i(this,"afterEdgePriorityUpdatedEmitter");i(this,"onAfterEdgePriorityUpdated");i(this,"beforeEdgeRemovedEmitter");i(this,"onBeforeEdgeRemoved");i(this,"beforeClearEmitter");i(this,"onBeforeClear");[this.afterNodeAddedEmitter,this.onAfterNodeAdded]=S(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=S(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=S(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=S(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=S(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=S(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=S(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=S(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=S(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=S(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=S(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=S(),[this.beforeClearEmitter,this.onBeforeClear]=S()}addNode(e){const t=new Map,s={element:e.element,payload:{x:e.x,y:e.y,centerFn:e.centerFn,priority:e.priority},ports:t};this.nodes.set(e.id,s),this.nodesElementsMap.set(e.element,e.id),this.afterNodeAddedEmitter.emit(e.id)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(e){return this.nodes.get(e)}getElementNodeId(e){return this.nodesElementsMap.get(e)}updateNode(e,t){const s=this.nodes.get(e).payload;s.x=t.x??s.x,s.y=t.y??s.y,s.centerFn=t.centerFn??s.centerFn,t.priority!==void 0&&(s.priority=t.priority,this.afterNodePriorityUpdatedEmitter.emit(e)),this.afterNodeUpdatedEmitter.emit(e)}removeNode(e){this.beforeNodeRemovedEmitter.emit(e);const t=this.nodes.get(e);this.nodesElementsMap.delete(t.element),this.nodes.delete(e)}addPort(e){this.ports.set(e.id,{element:e.element,payload:{direction:e.direction},nodeId:e.nodeId}),this.elementPorts.addRecord(e.element,e.id),this.portCycleEdges.set(e.id,new Set),this.portIncomingEdges.set(e.id,new Set),this.portOutcomingEdges.set(e.id,new Set),this.nodes.get(e.nodeId).ports.set(e.id,e.element),this.afterPortAddedEmitter.emit(e.id)}getPort(e){return this.ports.get(e)}updatePort(e,t){const s=this.ports.get(e).payload;s.direction=t.direction??s.direction,this.afterPortUpdatedEmitter.emit(e)}getAllPortIds(){return Array.from(this.ports.keys())}getElementPortIds(e){return this.elementPorts.getMultiBySingle(e)}getNodePortIds(e){const t=this.nodes.get(e);if(t!==void 0)return Array.from(t.ports.keys())}removePort(e){const t=this.ports.get(e).nodeId;this.beforePortRemovedEmitter.emit(e),this.nodes.get(t).ports.delete(e),this.ports.delete(e),this.elementPorts.removeByMulti(e)}addEdge(e){this.addEdgeInternal(e),this.afterEdgeAddedEmitter.emit(e.id)}updateEdge(e,t){if(t.from!==void 0||t.to!==void 0){const o=this.edges.get(e),n=o.payload;this.removeEdgeInternal(e),this.addEdgeInternal({id:e,from:t.from??o.from,to:t.to??o.to,shape:n.shape,priority:n.priority})}const s=this.edges.get(e);t.shape!==void 0&&(s.payload.shape=t.shape,this.afterEdgeShapeUpdatedEmitter.emit(e)),t.priority!==void 0&&(s.payload.priority=t.priority,this.afterEdgePriorityUpdatedEmitter.emit(e)),this.afterEdgeUpdatedEmitter.emit(e)}getAllEdgeIds(){return Array.from(this.edges.keys())}getEdge(e){return this.edges.get(e)}removeEdge(e){this.beforeEdgeRemovedEmitter.emit(e),this.removeEdgeInternal(e)}clear(){this.beforeClearEmitter.emit(),this.portIncomingEdges.clear(),this.portOutcomingEdges.clear(),this.portCycleEdges.clear(),this.elementPorts.clear(),this.nodesElementsMap.clear(),this.edges.clear(),this.ports.clear(),this.nodes.clear()}getPortIncomingEdgeIds(e){return Array.from(this.portIncomingEdges.get(e))}getPortOutgoingEdgeIds(e){return Array.from(this.portOutcomingEdges.get(e))}getPortCycleEdgeIds(e){return Array.from(this.portCycleEdges.get(e))}getPortAdjacentEdgeIds(e){return[...this.getPortIncomingEdgeIds(e),...this.getPortOutgoingEdgeIds(e),...this.getPortCycleEdgeIds(e)]}getNodeIncomingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(o=>{this.getPortIncomingEdgeIds(o).filter(n=>{const a=this.getEdge(n);return this.getPort(a.from).nodeId!==e}).forEach(n=>{s.push(n)})}),s}getNodeOutgoingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(o=>{this.getPortOutgoingEdgeIds(o).filter(n=>{const a=this.getEdge(n);return this.getPort(a.to).nodeId!==e}).forEach(n=>{s.push(n)})}),s}getNodeCycleEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(o=>{this.getPortCycleEdgeIds(o).forEach(n=>{s.push(n)}),this.getPortIncomingEdgeIds(o).filter(n=>{const a=this.getEdge(n);return this.getPort(a.to).nodeId===e}).forEach(n=>{s.push(n)})}),s}getNodeAdjacentEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(o=>{this.getPortIncomingEdgeIds(o).forEach(n=>{s.push(n)}),this.getPortOutgoingEdgeIds(o).forEach(n=>{s.push(n)}),this.getPortCycleEdgeIds(o).forEach(n=>{s.push(n)})}),s}addEdgeInternal(e){this.edges.set(e.id,{from:e.from,to:e.to,payload:{shape:e.shape,priority:e.priority}}),e.from!==e.to?(this.portOutcomingEdges.get(e.from).add(e.id),this.portIncomingEdges.get(e.to).add(e.id)):this.portCycleEdges.get(e.from).add(e.id)}removeEdgeInternal(e){const t=this.edges.get(e),s=t.from,o=t.to;this.portCycleEdges.get(s).delete(e),this.portCycleEdges.get(o).delete(e),this.portIncomingEdges.get(s).delete(e),this.portIncomingEdges.get(o).delete(e),this.portOutcomingEdges.get(s).delete(e),this.portOutcomingEdges.get(o).delete(e),this.edges.delete(e)}}const ge=r=>({scale:1/r.scale,x:-r.x/r.scale,y:-r.y/r.scale}),ue={scale:1,x:0,y:0};class tt{constructor(){i(this,"viewportMatrix",ue);i(this,"contentMatrix",ue);i(this,"afterUpdateEmitter");i(this,"onAfterUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=S()}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(e){this.viewportMatrix={scale:e.scale??this.viewportMatrix.scale,x:e.x??this.viewportMatrix.x,y:e.y??this.viewportMatrix.y},this.contentMatrix=ge(this.viewportMatrix),this.afterUpdateEmitter.emit()}patchContentMatrix(e){this.contentMatrix={scale:e.scale??this.contentMatrix.scale,x:e.x??this.contentMatrix.x,y:e.y??this.contentMatrix.y},this.viewportMatrix=ge(this.contentMatrix),this.afterUpdateEmitter.emit()}}class j{constructor(e){i(this,"elementToNodeId",new Map);i(this,"nodesResizeObserver");i(this,"onAfterNodeAdded",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.set(t.element,e),this.nodesResizeObserver.observe(t.element)});i(this,"onBeforeNodeRemoved",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.delete(t.element),this.nodesResizeObserver.unobserve(t.element)});i(this,"onBeforeClear",()=>{this.nodesResizeObserver.disconnect(),this.elementToNodeId.clear()});this.canvas=e,this.nodesResizeObserver=new ResizeObserver(t=>{t.forEach(s=>{const o=s.target;this.handleNodeResize(o)})}),this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear)}static configure(e){new j(e)}handleNodeResize(e){const t=this.elementToNodeId.get(e);this.canvas.updateNode(t)}}const rt=(r,e,t)=>{const{x:s,y:o,width:n,height:a}=r.getBoundingClientRect();return e>=s&&e<=s+n&&t>=o&&t<=o+a},st=(r,e,t)=>e>=0&&e<=r.innerWidth&&t>=0&&t<=r.innerHeight,V=(r,e,t,s)=>rt(e,t,s)&&st(r,t,s),B=(r,e)=>{e!==null?r.style.cursor=e:r.style.removeProperty("cursor")},O=r=>{const e=document.createElement("div");return{id:r.overlayId,element:e,x:r.portCoords.x,y:r.portCoords.y,ports:[{id:r.overlayId,element:e,direction:r.portDirection}]}},ot=(r,e)=>{let t=e;for(;t!==null;){const s=r.getElementPortIds(t)[0]??null;if(s!==null)return{status:"portFound",portId:s};if(r.getElementNodeId(t)!==null)return{status:"nodeEncountered"};t=t.parentElement}return{status:"notFound"}};function*pe(r,e){const t=r.elementsFromPoint(e.x,e.y);for(const s of t){if(s.shadowRoot!==null){const o=pe(s.shadowRoot,e);for(const n of o)yield n}yield s}}const we=(r,e)=>{const t=pe(document,e);for(const s of t){const o=ot(r,s);if(o.status==="portFound")return o.portId;if(o.status==="nodeEncountered")return null}return null};var N=(r=>(r.Static="static",r.Dragging="dragging",r.Edge="edge",r))(N||{});const fe=(r,e)=>({x:r/2,y:e/2}),p={x:0,y:0},m=(r,e,t)=>({x:e.x*r.x-e.y*r.y+((1-e.x)*t.x+e.y*t.y),y:e.y*r.x+e.x*r.y+((1-e.x)*t.y-e.y*t.x)}),ye=(r,e)=>{const t={x:r.x+r.width/2,y:r.y+r.height/2},s={x:e.x+e.width/2,y:e.y+e.height/2},o=Math.min(t.x,s.x),n=Math.min(t.y,s.y),a=Math.abs(s.x-t.x),h=Math.abs(s.y-t.y),d=t.x<=s.x?1:-1,c=t.y<=s.y?1:-1;return{x:o,y:n,width:a,height:h,flipX:d,flipY:c}},W=(r,e,t,s)=>({x:e*r.x+(1-e)/2*s.x,y:t*r.y+(1-t)/2*s.y});class it{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p),o=m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to),n={x:s.x+this.params.sourceDirection.x*this.params.curvature,y:s.y+this.params.sourceDirection.y*this.params.curvature},a={x:o.x-this.params.targetDirection.x*this.params.curvature,y:o.y-this.params.targetDirection.y*this.params.curvature},h=`M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${o.x} ${o.y}`,d=this.params.hasSourceArrow?"":`M ${p.x} ${p.y} L ${s.x} ${s.y} `,c=this.params.hasTargetArrow?"":` M ${o.x} ${o.y} L ${this.params.to.x} ${this.params.to.y}`;this.path=`${d}${h}${c}`}}class nt{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,o=this.params.arrowLength,n=Math.cos(this.params.detourDirection)*this.params.detourDistance,a=Math.sin(this.params.detourDirection)*this.params.detourDistance,h=n*this.params.flipX,d=a*this.params.flipY,c=m({x:o,y:p.y},this.params.sourceDirection,p),g={x:c.x+h,y:c.y+d},l=m({x:this.params.to.x-o,y:this.params.to.y},this.params.targetDirection,this.params.to),u={x:l.x+h,y:l.y+d},w={x:(g.x+u.x)/2,y:(g.y+u.y)/2},y={x:c.x+this.params.curvature*this.params.sourceDirection.x,y:c.y+this.params.curvature*this.params.sourceDirection.y},A={x:l.x-this.params.curvature*this.params.targetDirection.x,y:l.y-this.params.curvature*this.params.targetDirection.y},b={x:c.x+h,y:c.y+d},T={x:l.x+h,y:l.y+d};this.path=[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${y.x} ${y.y} ${b.x} ${b.y} ${w.x} ${w.y}`,`C ${T.x} ${T.y} ${A.x} ${A.y} ${l.x} ${l.y}`,`L ${s.x} ${s.y}`].join(" "),this.midpoint=W(w,e.flipX,e.flipY,e.to)}}const K=Object.freeze({edgeColor:"--edge-color"}),me=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.style.pointerEvents="none",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.overflow="visible",e.style.setProperty(K.edgeColor,r),e},ve=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke",`var(${K.edgeColor})`),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e},z=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("fill",`var(${K.edgeColor})`),r},Ee=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.transformOrigin="50% 50%",r},Ae=(r,e)=>{r.style.transform=`translate(${e.x}px, ${e.y}px)`,r.style.width=`${Math.max(e.width,1)}px`,r.style.height=`${Math.max(e.height,1)}px`},L=(r,e)=>{const t=[];if(r.length>0&&t.push(`M ${r[0].x} ${r[0].y}`),r.length===2&&t.push(`L ${r[1].x} ${r[1].y}`),r.length>2){const s=r.length-1;let o=0,n=0,a=0;r.forEach((h,d)=>{let c=0,g=0,l=0;const u=d>0,w=d<s,y=u&&w;if(u&&(c=-o,g=-n,l=a),w){const $=r[d+1];o=$.x-h.x,n=$.y-h.y,a=Math.sqrt(o*o+n*n)}const b=a!==0?Math.min((y?e:0)/a,d<s-1?.5:1):0,T=y?{x:h.x+o*b,y:h.y+n*b}:h,D=l!==0?Math.min((y?e:0)/l,d>1?.5:1):0,R=y?{x:h.x+c*D,y:h.y+g*D}:h;d>0&&t.push(`L ${R.x} ${R.y}`),y&&t.push(`C ${h.x} ${h.y} ${h.x} ${h.y} ${T.x} ${T.y}`)})}return t.join(" ")};class at{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,o=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=m({x:a,y:p.y},this.params.sourceDirection,p),d=m({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.x+d.x)/2,n),g=this.params.to.y/2,l={x:this.params.flipX>0?c:-n,y:h.y},u={x:l.x,y:g},w={x:this.params.flipX>0?this.params.to.x-c:this.params.to.x+n,y:d.y},y={x:w.x,y:g};this.path=L([s,h,l,u,y,w,d,o],this.params.roundness)}}class ht{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,o=this.params.arrowLength+this.params.arrowOffset,n=m({x:o,y:p.y},this.params.sourceDirection,p),a=Math.cos(this.params.detourDirection)*this.params.detourDistance,h=Math.sin(this.params.detourDirection)*this.params.detourDistance,d=a*this.params.flipX,c=h*this.params.flipY,g={x:n.x+d,y:n.y+c},l=m({x:this.params.to.x-o,y:this.params.to.y},this.params.targetDirection,this.params.to),u={x:l.x+d,y:l.y+c},w={x:(g.x+u.x)/2,y:(g.y+u.y)/2};this.midpoint=W(w,e.flipX,e.flipY,e.to),this.path=L([t,n,g,u,l,s],this.params.roundness)}}class dt{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,o=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=m({x:n,y:p.y},this.params.sourceDirection,p),h=m({x:this.params.to.x-n,y:this.params.to.y},this.params.targetDirection,this.params.to);this.path=L([s,a,h,o],this.params.roundness)}}class ct{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,o=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=m({x:a,y:p.y},this.params.sourceDirection,p),d=m({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.y+d.y)/2,n),g=this.params.to.x/2,l={x:h.x,y:this.params.flipY>0?c:-n},u={x:g,y:l.y},w={x:d.x,y:this.params.flipY>0?this.params.to.y-c:this.params.to.y+n},y={x:g,y:w.y};this.path=L([s,h,l,u,y,w,d,o],this.params.roundness)}}class Q{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.arrowOffset,s=this.params.side,o=this.params.arrowLength+t,n=o+2*s,h=[{x:this.params.arrowLength,y:p.y},{x:o,y:p.y},{x:o,y:this.params.side},{x:n,y:this.params.side},{x:n,y:-this.params.side},{x:o,y:-this.params.side},{x:o,y:p.y},{x:this.params.arrowLength,y:p.y}].map(c=>m(c,this.params.sourceDirection,p)),d=`M ${p.x} ${p.y} L ${h[0].x} ${h[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":d}${L(h,this.params.roundness)}`,this.midpoint={x:(h[3].x+h[4].x)/2,y:(h[3].y+h[4].y)/2}}}class lt{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.smallRadius,s=this.params.radius,o=t+s,n=t*s/o,a=Math.sqrt(o*o-t*t),h=a*t/o,d=a+s+this.params.arrowLength,c=this.params.arrowLength+h,l=[{x:this.params.arrowLength,y:p.y},{x:c,y:n},{x:c,y:-n},{x:d,y:0}].map(y=>m(y,this.params.sourceDirection,p)),u=[`M ${l[0].x} ${l[0].y}`,`A ${t} ${t} 0 0 1 ${l[1].x} ${l[1].y}`,`A ${s} ${s} 0 1 0 ${l[2].x} ${l[2].y}`,`A ${t} ${t} 0 0 1 ${l[0].x} ${l[0].y}`].join(" "),w=`M 0 0 L ${l[0].x} ${l[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":w}${u}`,this.midpoint=l[3]}}class gt{constructor(e){i(this,"path");i(this,"midpoint");i(this,"diagonalDistance");this.params=e;const t=this.params.to;if(this.midpoint={x:t.x/2,y:t.y/2},this.diagonalDistance=Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y),Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y)===0){this.path="";return}const o=this.createDirectLinePoint({offset:this.params.sourceOffset,hasArrow:this.params.hasSourceArrow,flip:1,shift:p}),n=this.createDirectLinePoint({offset:this.params.targetOffset,hasArrow:this.params.hasTargetArrow,flip:-1,shift:this.params.to});this.path=`M ${o.x} ${o.y} L ${n.x} ${n.y}`}createDirectLinePoint(e){const t=e.hasArrow?this.params.arrowLength:0,s=e.offset+t,o=e.flip*s/this.diagonalDistance;return{x:this.params.to.x*o+e.shift.x,y:this.params.to.y*o+e.shift.y}}}class ut{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,o=this.params.arrowLength+this.params.arrowOffset,n=m({x:o,y:p.y},this.params.sourceDirection,p),a=m({x:this.params.to.x-o,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.y/2,c=d+Math.abs(this.params.detourDistance),g=d+c*this.params.flipY*h,l={x:(n.x+a.x)/2,y:g};this.midpoint=W(l,e.flipX,e.flipY,e.to),this.path=L([t,n,{x:n.x,y:g},{x:a.x,y:g},a,s],this.params.roundness)}}class pt{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,o=this.params.arrowLength+this.params.arrowOffset,n=m({x:o,y:p.y},this.params.sourceDirection,p),a=m({x:this.params.to.x-o,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.x/2,c=d+Math.abs(this.params.detourDistance),g=d+c*this.params.flipX*h,l={x:g,y:(n.y+a.y)/2};this.midpoint=W(l,e.flipX,e.flipY,e.to),this.path=L([t,n,{x:g,y:n.y},{x:g,y:a.y},a,s],this.params.roundness)}}const f=Object.freeze({color:"#777777",width:1,arrowLength:20,polygonArrowRadius:4,circleArrowRadius:8,wedgeArrowSmallRadius:20,wedgeArrowRadius:100,wedgeArrowAngle:Math.PI/12,arrowOffset:15,hasSourceArrow:!1,hasTargetArrow:!1,cycleRadius:30,cycleSquareSide:30,roundness:10,detourDistance:100,detourDirection:-Math.PI/2,detourDirectionVertical:0,smallCycleRadius:15,curvature:90,interactiveWidth:10,preOffset:0}),xe=(r,e,t)=>({x:e*Math.cos(r),y:t*Math.sin(r)});class k{constructor(e){i(this,"svg");i(this,"group",Ee());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"onAfterRender");i(this,"afterRenderEmitter");i(this,"arrowRenderer");this.params=e,[this.afterRenderEmitter,this.onAfterRender]=S(),this.arrowRenderer=this.params.arrowRenderer,this.svg=me(e.color),this.svg.appendChild(this.group),this.line=ve(e.width),this.group.appendChild(this.line),e.hasSourceArrow&&(this.sourceArrow=z(),this.group.appendChild(this.sourceArrow)),e.hasTargetArrow&&(this.targetArrow=z(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:o,height:n,flipX:a,flipY:h}=ye(e.from,e.to);Ae(this.svg,{x:t,y:s,width:o,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d=xe(e.from.direction,a,h),c=xe(e.to.direction,a,h),g={x:o,y:n};let l={x:-c.x,y:-c.y},u;e.category===C.PortCycle?(u=this.params.createCyclePath,l=d):e.category===C.NodeCycle?u=this.params.createDetourPath:u=this.params.createLinePath;const w=u(d,c,g,a,h);this.line.setAttribute("d",w.path);let y=null;this.sourceArrow&&(y=this.arrowRenderer({direction:d,shift:p,arrowLength:this.params.arrowLength}),this.sourceArrow.setAttribute("d",y));let A=null;this.targetArrow&&(A=this.arrowRenderer({direction:l,shift:g,arrowLength:this.params.arrowLength}),this.targetArrow.setAttribute("d",A)),this.afterRenderEmitter.emit({edgePath:w,sourceArrowPath:y,targetArrowPath:A})}}const wt=r=>e=>{const s=[p,{x:e.arrowLength,y:r.radius},{x:e.arrowLength,y:-r.radius}].map(h=>m(h,e.direction,p)).map(h=>({x:h.x+e.shift.x,y:h.y+e.shift.y})),o=`M ${s[0].x} ${s[0].y}`,n=`L ${s[1].x} ${s[1].y}`,a=`L ${s[2].x} ${s[2].y}`;return`${o} ${n} ${a} Z`},ft=r=>e=>{const t=r.radius,s=e.arrowLength,o=(s*s+2*s*t)/(2*t),n=o+t,a=s+t-t*(s+t)/n,h=t*o/n,c=[p,{x:a,y:-h},{x:a,y:h}].map(y=>m(y,e.direction,p)).map(y=>({x:y.x+e.shift.x,y:y.y+e.shift.y})),g=`M ${c[0].x} ${c[0].y}`,l=`A ${o} ${o} 0 0 0 ${c[1].x} ${c[1].y}`,u=`A ${t} ${t} 0 0 0 ${c[2].x} ${c[2].y}`,w=`A ${o} ${o} 0 0 0 ${c[0].x} ${c[0].y}`;return`${g} ${l} ${u} ${w}`},yt=r=>e=>{const t=r.smallRadius,s=r.radius,o=m({x:e.arrowLength,y:0},{x:Math.cos(r.angle),y:Math.sin(r.angle)},{x:e.arrowLength+r.smallRadius,y:0}),a=[p,{x:o.x,y:-o.y},o].map(l=>m(l,e.direction,p)).map(l=>({x:l.x+e.shift.x,y:l.y+e.shift.y})),h=`M ${a[0].x} ${a[0].y}`,d=`A ${s} ${s} 0 0 1 ${a[1].x} ${a[1].y}`,c=`A ${t} ${t} 0 0 1 ${a[2].x} ${a[2].y}`,g=`A ${s} ${s} 0 0 1 ${a[0].x} ${a[0].y}`;return`${h} ${d} ${c} ${g}`},I=r=>{if(typeof r=="function")return r;switch(r.type){case"triangle":return wt({radius:r.radius??f.polygonArrowRadius});case"arc":return ft({radius:r.radius??f.circleArrowRadius});default:return yt({smallRadius:r.smallRadius??f.wedgeArrowSmallRadius,angle:r.angle??f.wedgeArrowAngle,radius:r.radius??f.wedgeArrowRadius})}};class Se{constructor(e){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"arrowLength");i(this,"curvature");i(this,"portCycleRadius");i(this,"portCycleSmallRadius");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");i(this,"pathShape");i(this,"createCyclePath",e=>new lt({sourceDirection:e,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createDetourPath",(e,t,s,o,n)=>new nt({to:s,sourceDirection:e,targetDirection:t,flipX:o,flipY:n,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createLinePath",(e,t,s)=>new it({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.curvature=(e==null?void 0:e.curvature)??f.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??f.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??f.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??f.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new k({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class be{constructor(e){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"arrowLength");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");i(this,"pathShape");i(this,"createCyclePath",e=>new Q({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createDetourPath",(e,t,s,o,n)=>new ut({to:s,sourceDirection:e,targetDirection:t,flipX:o,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createLinePath",(e,t,s,o)=>new at({to:s,sourceDirection:e,targetDirection:t,flipX:o,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new k({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Pe{constructor(e){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"arrowLength");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");i(this,"pathShape");i(this,"createCyclePath",e=>new Q({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createDetourPath",(e,t,s,o,n)=>new ht({to:s,sourceDirection:e,targetDirection:t,flipX:o,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createLinePath",(e,t,s)=>new dt({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??f.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new k({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Te{constructor(e){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"arrowLength");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");i(this,"pathShape");i(this,"createCyclePath",e=>new Q({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createDetourPath",(e,t,s,o,n)=>new pt({to:s,sourceDirection:e,targetDirection:t,flipX:o,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createLinePath",(e,t,s,o,n)=>new ct({to:s,sourceDirection:e,targetDirection:t,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new k({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Z{constructor(e){i(this,"svg");i(this,"group",Ee());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"color");i(this,"width");i(this,"arrowLength");i(this,"sourceOffset");i(this,"targetOffset");i(this,"onAfterRender");i(this,"afterRenderEmitter");i(this,"arrowRenderer");[this.afterRenderEmitter,this.onAfterRender]=S(),this.color=(e==null?void 0:e.color)??f.color,this.width=(e==null?void 0:e.width)??f.width,this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowRenderer=I((e==null?void 0:e.arrowRenderer)??{}),this.sourceOffset=(e==null?void 0:e.sourceOffset)??f.preOffset,this.targetOffset=(e==null?void 0:e.targetOffset)??f.preOffset,this.svg=me(this.color),this.svg.appendChild(this.group),this.line=ve(this.width),this.group.appendChild(this.line),e!=null&&e.hasSourceArrow&&(this.sourceArrow=z(),this.group.appendChild(this.sourceArrow)),e!=null&&e.hasTargetArrow&&(this.targetArrow=z(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:o,height:n,flipX:a,flipY:h}=ye(e.from,e.to);Ae(this.svg,{x:t,y:s,width:o,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d={x:o,y:n},c=new gt({to:d,sourceOffset:this.sourceOffset,targetOffset:this.targetOffset,hasSourceArrow:this.sourceArrow!==null,hasTargetArrow:this.targetArrow!==null,arrowLength:this.arrowLength});this.line.setAttribute("d",c.path);let g=null,l=null;const u=c.diagonalDistance;if(u===0)this.sourceArrow!==null&&(g="",this.sourceArrow.setAttribute("d",g)),this.targetArrow!==null&&(l="",this.targetArrow.setAttribute("d",l));else{const w={x:d.x/u,y:d.y/u};if(this.sourceArrow){const y={x:w.x*this.sourceOffset,y:w.y*this.sourceOffset};g=this.arrowRenderer({direction:w,shift:y,arrowLength:this.arrowLength}),this.sourceArrow.setAttribute("d",g)}if(this.targetArrow){const y={x:w.x*this.targetOffset,y:w.y*this.targetOffset};l=this.arrowRenderer({direction:{x:-w.x,y:-w.y},shift:{x:d.x-y.x,y:d.y-y.y},arrowLength:this.arrowLength}),this.targetArrow.setAttribute("d",l)}}this.afterRenderEmitter.emit({edgePath:c,sourceArrowPath:g,targetArrowPath:l})}}const mt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.pointerEvents="auto",r.style.cursor="pointer",r},vt=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke","transparent"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e.setAttribute("stroke-linecap","round"),e},Ce=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke-linejoin","round"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","transparent"),e.setAttribute("stroke","transparent"),e};class De extends Error{constructor(e){super(e),this.name="InteractiveEdgeError"}}class J{constructor(e,t){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"handle",mt());i(this,"onAfterRender");i(this,"interactiveLine");i(this,"interactiveSourceArrow",null);i(this,"interactiveTargetArrow",null);if(this.baseEdge=e,e instanceof J)throw new De("interactive edge can be configured only once");this.svg=this.baseEdge.svg,this.group=this.baseEdge.group,this.line=this.baseEdge.line,this.sourceArrow=this.baseEdge.sourceArrow,this.targetArrow=this.baseEdge.targetArrow,this.onAfterRender=this.baseEdge.onAfterRender;const s=(t==null?void 0:t.distance)??f.interactiveWidth;this.interactiveLine=vt(s),this.handle.appendChild(this.interactiveLine),this.sourceArrow&&(this.interactiveSourceArrow=Ce(s),this.handle.appendChild(this.interactiveSourceArrow)),this.targetArrow&&(this.interactiveTargetArrow=Ce(s),this.handle.appendChild(this.interactiveTargetArrow)),this.group.appendChild(this.handle),this.baseEdge.onAfterRender.subscribe(o=>{this.interactiveLine.setAttribute("d",o.edgePath.path),this.interactiveSourceArrow&&this.interactiveSourceArrow.setAttribute("d",o.sourceArrowPath),this.interactiveTargetArrow&&this.interactiveTargetArrow.setAttribute("d",o.targetArrowPath)})}render(e){this.baseEdge.render(e)}}class Et{constructor(e,t){i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"svg");this.baseShape=e,this.midpointElement=t,this.svg=this.baseShape.svg,this.group=this.baseShape.group,this.line=this.baseShape.line,this.sourceArrow=this.baseShape.sourceArrow,this.targetArrow=this.baseShape.targetArrow,this.onAfterRender=this.baseShape.onAfterRender,this.svg.append(this.midpointElement),this.baseShape.onAfterRender.subscribe(s=>{const o=s.edgePath.midpoint,n=`translate(${o.x}px, ${o.y}px)`;this.midpointElement.style.setProperty("transform",n)})}render(e){this.baseShape.render(e)}}class Ne{constructor(e){i(this,"onAfterNodeAdded");i(this,"onAfterNodeUpdated");i(this,"onAfterNodePriorityUpdated");i(this,"onBeforeNodeRemoved");i(this,"onAfterPortMarked");i(this,"onAfterPortUpdated");i(this,"onBeforePortUnmarked");i(this,"onAfterEdgeAdded");i(this,"onAfterEdgeShapeUpdated");i(this,"onAfterEdgeUpdated");i(this,"onAfterEdgePriorityUpdated");i(this,"onBeforeEdgeRemoved");i(this,"onBeforeClear");this.graphStore=e,this.onAfterNodeAdded=this.graphStore.onAfterNodeAdded,this.onAfterNodeUpdated=this.graphStore.onAfterNodeUpdated,this.onAfterNodePriorityUpdated=this.graphStore.onAfterNodePriorityUpdated,this.onBeforeNodeRemoved=this.graphStore.onBeforeNodeRemoved,this.onAfterPortMarked=this.graphStore.onAfterPortAdded,this.onAfterPortUpdated=this.graphStore.onAfterPortUpdated,this.onBeforePortUnmarked=this.graphStore.onBeforePortRemoved,this.onAfterEdgeAdded=this.graphStore.onAfterEdgeAdded,this.onAfterEdgeShapeUpdated=this.graphStore.onAfterEdgeShapeUpdated,this.onAfterEdgeUpdated=this.graphStore.onAfterEdgeUpdated,this.onAfterEdgePriorityUpdated=this.graphStore.onAfterEdgePriorityUpdated,this.onBeforeEdgeRemoved=this.graphStore.onBeforeEdgeRemoved,this.onBeforeClear=this.graphStore.onBeforeClear}getNode(e){const t=this.graphStore.getNode(e);if(t===void 0)return null;const s=t.payload;return{element:t.element,x:s.x,y:s.y,centerFn:s.centerFn,priority:s.priority}}getElementNodeId(e){return this.graphStore.getElementNodeId(e)??null}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(e){const t=this.graphStore.getPort(e);return t===void 0?null:{element:t.element,direction:t.payload.direction,nodeId:t.nodeId}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(e){return this.graphStore.getNodePortIds(e)??null}getElementPortIds(e){return[...this.graphStore.getElementPortIds(e)]}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(e){const t=this.graphStore.getEdge(e);if(t===void 0)return null;const s=t.payload;return{from:t.from,to:t.to,priority:s.priority,shape:s.shape}}getPortIncomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortIncomingEdgeIds(e)}getPortOutgoingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortOutgoingEdgeIds(e)}getPortCycleEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortCycleEdgeIds(e)}getPortAdjacentEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortAdjacentEdgeIds(e)}getNodeIncomingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeIncomingEdgeIds(e)}getNodeOutgoingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeOutgoingEdgeIds(e)}getNodeCycleEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeCycleEdgeIds(e)}getNodeAdjacentEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeAdjacentEdgeIds(e)}}class Me{constructor(e){i(this,"onAfterUpdated");this.viewportStore=e,this.onAfterUpdated=this.viewportStore.onAfterUpdated}getViewportMatrix(){return{...this.viewportStore.getViewportMatrix()}}getContentMatrix(){return{...this.viewportStore.getContentMatrix()}}}const Le=(r,e)=>{const t=new le,s=new Ne(t),o=new Me(e),n=new de(t,e,r),a={nodes:{centerFn:fe,priorityFn:()=>0},edges:{shapeFactory:()=>new Z,priorityFn:()=>0},ports:{direction:0}};return new ce(s,o,t,e,n,a)};class H{constructor(e,t,s,o){i(this,"onAfterPortMarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.hookPortEvents(t.element)});i(this,"onBeforePortUnmarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.unhookPortEvents(t.element)});i(this,"onPortMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.canvas.graph.getElementPortIds(t)[0];this.params.onPortPointerDown(s,{x:e.clientX,y:e.clientY})&&(e.stopPropagation(),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}))});i(this,"onWindowMouseMove",e=>{if(!V(this.window,this.element,e.clientX,e.clientY)){this.stopMouseDrag();return}this.params.onPointerMove({x:e.clientX,y:e.clientY})});i(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&(this.params.onPointerUp({x:e.clientX,y:e.clientY}),this.stopMouseDrag())});i(this,"onPortTouchStart",e=>{if(e.touches.length!==1)return;const t=e.touches[0],s=e.currentTarget,o=this.canvas.graph.getElementPortIds(s)[0];this.params.onPortPointerDown(o,{x:t.clientX,y:t.clientY})&&(e.stopPropagation(),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}))});i(this,"onWindowTouchMove",e=>{const t=e.touches[0];if(!V(this.window,this.element,t.clientX,t.clientY)){this.stopTouchDrag();return}this.params.onPointerMove({x:t.clientX,y:t.clientY})});i(this,"onWindowTouchFinish",e=>{const t=e.changedTouches[0];this.params.onPointerUp({x:t.clientX,y:t.clientY}),this.stopTouchDrag()});i(this,"onBeforeClear",()=>{this.canvas.graph.getAllPortIds().forEach(e=>{const t=this.canvas.graph.getPort(e);this.unhookPortEvents(t.element)})});i(this,"onBeforeDestroy",()=>{this.params.onStopDrag(),this.removeWindowMouseListeners(),this.removeWindowTouchListeners()});this.canvas=e,this.element=t,this.window=s,this.params=o,this.canvas.graph.onAfterPortMarked.subscribe(this.onAfterPortMarked),this.canvas.graph.onBeforePortUnmarked.subscribe(this.onBeforePortUnmarked),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,o){new H(e,t,s,o)}hookPortEvents(e){e.addEventListener("mousedown",this.onPortMouseDown,{passive:!0}),e.addEventListener("touchstart",this.onPortTouchStart,{passive:!0})}unhookPortEvents(e){e.removeEventListener("mousedown",this.onPortMouseDown),e.removeEventListener("touchstart",this.onPortTouchStart)}stopMouseDrag(){this.params.onStopDrag(),this.removeWindowMouseListeners()}stopTouchDrag(){this.params.onStopDrag(),this.removeWindowTouchListeners()}removeWindowMouseListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}removeWindowTouchListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class q{constructor(e,t,s,o){i(this,"grabbedNode",null);i(this,"maxNodePriority",0);i(this,"graph");i(this,"onAfterNodeAdded",e=>{this.updateMaxNodePriority(e);const t=this.graph.getNode(e);t.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),t.element.addEventListener("touchstart",this.onTouchStart,{passive:!0})});i(this,"onAfterNodeUpdated",e=>{this.updateMaxNodePriority(e)});i(this,"onBeforeNodeRemoved",e=>{const t=this.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)});i(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});i(this,"onBeforeClear",()=>{this.canvas.graph.getAllNodeIds().forEach(e=>{const t=this.canvas.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)}),this.maxNodePriority=0});i(this,"onMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.graph.getElementNodeId(t),o=this.graph.getNode(s);if(!this.params.nodeDragVerifier(s))return;this.params.onNodeDragStarted(s),e.stopPropagation();const a=this.calculateContentPoint({x:e.clientX,y:e.clientY});this.grabbedNode={nodeId:s,dx:a.x-o.x,dy:a.y-o.y},B(this.element,this.params.dragCursor),this.moveNodeOnTop(s),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0})});i(this,"onTouchStart",e=>{if(e.touches.length!==1)return;e.stopPropagation();const t=e.touches[0],s=e.currentTarget,o=this.canvas.graph.getElementNodeId(s),n=this.graph.getNode(o);if(!this.params.nodeDragVerifier({nodeId:o,element:n.element,x:n.x,y:n.y}))return;const h=this.calculateContentPoint({x:t.clientX,y:t.clientY});this.grabbedNode={nodeId:o,dx:h.x-n.x,dy:h.y-n.y},this.moveNodeOnTop(o),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0})});i(this,"onWindowMouseMove",e=>{if(!V(this.window,this.element,e.clientX,e.clientY)){this.cancelMouseDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:e.clientX,y:e.clientY})});i(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&this.cancelMouseDrag()});i(this,"onWindowTouchMove",e=>{if(e.touches.length!==1)return;const t=e.touches[0];if(!V(this.window,this.element,t.clientX,t.clientY)){this.cancelTouchDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:t.clientX,y:t.clientY})});i(this,"onWindowTouchFinish",()=>{this.cancelTouchDrag()});this.canvas=e,this.element=t,this.window=s,this.params=o,this.graph=e.graph,this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,o){new q(e,t,s,o)}moveNode(e,t){if(this.graph.getNode(e.nodeId)===null)return;const o=this.calculateContentPoint(t),n={x:o.x-e.dx,y:o.y-e.dy},a=this.adjustNodeCoords(n);this.canvas.updateNode(e.nodeId,{x:a.x,y:a.y}),this.params.onNodeDrag(e.nodeId)}moveNodeOnTop(e){if(this.params.moveOnTop){if(this.maxNodePriority++,this.params.moveEdgesOnTop){const t=this.maxNodePriority;this.maxNodePriority++,this.graph.getNodeAdjacentEdgeIds(e).forEach(o=>{this.canvas.updateEdge(o,{priority:t})})}this.canvas.updateNode(e,{priority:this.maxNodePriority})}}cancelMouseDrag(){this.grabbedNode!==null&&this.graph.getNode(this.grabbedNode.nodeId)!==null&&this.params.onNodeDragFinished(this.grabbedNode.nodeId),this.grabbedNode=null,B(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){if(this.grabbedNode!==null){const e=this.graph.getNode(this.grabbedNode.nodeId);e!==null&&this.params.onNodeDragFinished({nodeId:this.grabbedNode.nodeId,element:e.element,x:e.x,y:e.y})}this.grabbedNode=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}updateMaxNodePriority(e){const t=this.graph.getNode(e).priority;this.maxNodePriority=Math.max(this.maxNodePriority,t)}calculateContentPoint(e){const t=this.element.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},o=this.canvas.viewport.getViewportMatrix();return x(o,s)}adjustNodeCoords(e){const t=this.params.gridSize;if(t!==null){const s=t/2;return{x:Math.floor((e.x+s)/t)*t,y:Math.floor((e.y+s)/t)*t}}return e}}const At=(r,e,t)=>({scale:r.scale,x:r.x+r.scale*e,y:r.y+r.scale*t}),xt=(r,e,t,s)=>({scale:r.scale*e,x:r.scale*(1-e)*t+r.x,y:r.scale*(1-e)*s+r.y}),X=r=>{const e=[],t=r.touches.length;for(let h=0;h<t;h++)e.push([r.touches[h].clientX,r.touches[h].clientY]);const s=e.reduce((h,d)=>[h[0]+d[0],h[1]+d[1]],[0,0]),o=[s[0]/t,s[1]/t],a=e.map(h=>[h[0]-o[0],h[1]-o[1]]).reduce((h,d)=>h+Math.sqrt(d[0]*d[0]+d[1]*d[1]),0);return{x:o[0],y:o[1],scale:a/t,touchesCnt:t,touches:e}};class Y{constructor(e,t,s,o){i(this,"viewport");i(this,"prevTouches",null);i(this,"wheelFinishTimer",null);i(this,"transformInProgress",!1);i(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});i(this,"onMouseDown",e=>{this.element===null||!this.params.mouseDownEventVerifier(e)||(B(this.element,this.params.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}),this.startRegisteredTransform())});i(this,"onWindowMouseMove",e=>{const t=V(this.window,this.element,e.clientX,e.clientY);if(this.element===null||!t){this.stopMouseDrag();return}const s=-e.movementX,o=-e.movementY;this.moveViewport(s,o)});i(this,"onWindowMouseUp",e=>{this.element===null||!this.params.mouseUpEventVerifier(e)||this.stopMouseDrag()});i(this,"onWheelScroll",e=>{if(!this.params.mouseWheelEventVerifier(e))return;const{left:t,top:s}=this.element.getBoundingClientRect(),o=e.clientX-t,n=e.clientY-s,h=1/(e.deltaY<0?this.params.wheelSensitivity:1/this.params.wheelSensitivity);this.wheelFinishTimer===null&&this.params.onTransformStarted(),this.scaleViewport(h,o,n),this.wheelFinishTimer!==null&&clearTimeout(this.wheelFinishTimer),this.wheelFinishTimer=setTimeout(()=>{this.transformInProgress||this.params.onTransformFinished(),this.wheelFinishTimer=null},this.params.scaleWheelFinishTimeout)});i(this,"onTouchStart",e=>{if(this.prevTouches!==null){this.prevTouches=X(e);return}this.prevTouches=X(e),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}),this.startRegisteredTransform()});i(this,"onWindowTouchMove",e=>{const t=X(e);if(!t.touches.every(o=>V(this.window,this.element,o[0],o[1]))){this.stopTouchDrag();return}if((t.touchesCnt===1||t.touchesCnt===2)&&this.moveViewport(-(t.x-this.prevTouches.x),-(t.y-this.prevTouches.y)),t.touchesCnt===2){const{left:o,top:n}=this.element.getBoundingClientRect(),a=this.prevTouches.x-o,h=this.prevTouches.y-n,c=1/(t.scale/this.prevTouches.scale);this.scaleViewport(c,a,h)}this.prevTouches=t});i(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=X(e):this.stopTouchDrag()});i(this,"observer",new ResizeObserver(()=>{const e=this.viewport.getViewportMatrix(),{width:t,height:s}=this.element.getBoundingClientRect(),o=this.params.transformPreprocessor({prevTransform:e,nextTransform:e,canvasWidth:t,canvasHeight:s});this.params.onResizeTransformStarted(),this.canvas.patchViewportMatrix(o),this.params.onResizeTransformFinished()}));i(this,"preventWheelScaleListener",e=>{e.preventDefault()});this.canvas=e,this.element=t,this.window=s,this.params=o,this.element.addEventListener("wheel",this.preventWheelScaleListener,{passive:!1}),this.viewport=e.viewport,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),this.element.addEventListener("wheel",this.onWheelScroll,{passive:!0}),this.element.addEventListener("touchstart",this.onTouchStart,{passive:!0}),e.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,o){new Y(e,t,s,o)}moveViewport(e,t){const s=this.viewport.getViewportMatrix(),o=At(s,e,t),{width:n,height:a}=this.element.getBoundingClientRect(),h=this.params.transformPreprocessor({prevTransform:s,nextTransform:o,canvasWidth:n,canvasHeight:a});this.performTransform(h)}scaleViewport(e,t,s){const o=this.canvas.viewport.getViewportMatrix(),n=xt(o,e,t,s),{width:a,height:h}=this.element.getBoundingClientRect(),d=this.params.transformPreprocessor({prevTransform:o,nextTransform:n,canvasWidth:a,canvasHeight:h});this.performTransform(d)}stopMouseDrag(){B(this.element,null),this.removeMouseDragListeners(),this.finishRegisteredTransform()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.finishRegisteredTransform()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}performTransform(e){this.params.onBeforeTransformChange(),this.canvas.patchViewportMatrix(e),this.params.onTransformChange()}startRegisteredTransform(){this.transformInProgress=!0,this.params.onTransformStarted()}finishRegisteredTransform(){this.transformInProgress=!1,this.params.onTransformFinished()}}class _{constructor(e,t,s,o,n,a){i(this,"canvasResizeObserver");i(this,"nodeHorizontal");i(this,"nodeVertical");i(this,"viewport");i(this,"viewportWidth",0);i(this,"viewportHeight",0);i(this,"viewportMatrix");i(this,"loadedArea",{xFrom:1/0,xTo:1/0,yFrom:1/0,yTo:1/0});i(this,"updateLoadedArea",e=>{this.loadedArea={xFrom:e.x,xTo:e.x+e.width,yFrom:e.y,yTo:e.y+e.height}});i(this,"onAfterViewportUpdated",()=>{this.userTransformInProgress||(this.viewportMatrix=this.viewport.getViewportMatrix(),this.loadAreaAroundViewport())});i(this,"userTransformInProgress",!1);this.canvas=e,this.element=t,this.window=s,this.trigger=n,this.params=a,this.nodeHorizontal=this.params.nodeVerticalRadius,this.nodeVertical=this.params.nodeHorizontalRadius,this.canvasResizeObserver=new ResizeObserver(d=>{const c=d[0];this.viewportWidth=c.contentRect.width,this.viewportHeight=c.contentRect.height,this.scheduleLoadAreaAroundViewport()}),this.viewport=e.viewport;const h={...o,onResizeTransformStarted:()=>{this.userTransformInProgress=!0,o.onResizeTransformStarted()},onResizeTransformFinished:()=>{this.userTransformInProgress=!1,o.onResizeTransformFinished()},onBeforeTransformChange:()=>{this.userTransformInProgress=!0,o.onBeforeTransformChange()},onTransformChange:()=>{this.userTransformInProgress=!1;const d=this.viewportMatrix;this.viewportMatrix=this.viewport.getViewportMatrix(),d.scale!==this.viewportMatrix.scale&&this.scheduleEnsureViewportAreaLoaded(),o.onTransformChange()},onTransformFinished:()=>{this.scheduleLoadAreaAroundViewport(),o.onTransformFinished()}};Y.configure(e,this.element,this.window,h),this.viewportMatrix=this.viewport.getViewportMatrix(),this.trigger.subscribe(this.updateLoadedArea),this.canvasResizeObserver.observe(this.element),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated)}static configure(e,t,s,o,n,a){new _(e,t,s,o,n,a)}scheduleLoadAreaAroundViewport(){setTimeout(()=>{this.loadAreaAroundViewport()})}scheduleEnsureViewportAreaLoaded(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-this.nodeHorizontal,o=this.viewportMatrix.y-this.nodeVertical,n=this.viewportMatrix.x+e+this.nodeHorizontal,a=this.viewportMatrix.y+t+this.nodeVertical;this.loadedArea.xFrom<s&&this.loadedArea.xTo>n&&this.loadedArea.yFrom<o&&this.loadedArea.yTo>a||this.scheduleLoadAreaAroundViewport()}loadAreaAroundViewport(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-e-this.nodeHorizontal,o=this.viewportMatrix.y-t-this.nodeVertical,n=3*e+2*this.nodeHorizontal,a=3*t+2*this.nodeVertical;this.trigger.emit({x:s,y:o,width:n,height:a})}}const St=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.style.position="absolute",r.style.inset="0",r},bt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","rect");return r.setAttribute("fill","url(#pattern)"),r},Pt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","pattern");return r.setAttribute("id","pattern"),r};class ee{constructor(e,t,s){i(this,"svg",St());i(this,"patternRenderingRectangle",bt());i(this,"pattern",Pt());i(this,"patternContent");i(this,"tileWidth");i(this,"tileHeight");i(this,"halfTileWidth");i(this,"halfTileHeight");i(this,"maxViewportScale");i(this,"visible",!1);i(this,"resizeObserver",new ResizeObserver(e=>{const t=e[0],{width:s,height:o}=t.contentRect;this.svg.setAttribute("width",`${s}`),this.svg.setAttribute("height",`${o}`),this.patternRenderingRectangle.setAttribute("width",`${s}`),this.patternRenderingRectangle.setAttribute("height",`${o}`);const n=this.tileWidth/s,a=this.tileHeight/o;this.pattern.setAttribute("width",`${n}`),this.pattern.setAttribute("height",`${a}`)}));i(this,"onAfterTransformUpdated",()=>{const e=this.canvas.viewport.getContentMatrix(),t=e.x-this.halfTileWidth*e.scale,s=e.y-this.halfTileHeight*e.scale,o=`matrix(${e.scale}, 0, 0, ${e.scale}, ${t}, ${s})`;this.pattern.setAttribute("patternTransform",o),this.updateVisibility()});this.canvas=e,this.backgroundHost=s,this.tileWidth=t.tileWidth,this.tileHeight=t.tileHeight,this.halfTileWidth=this.tileWidth/2,this.halfTileHeight=this.tileHeight/2,this.patternContent=t.renderer,this.maxViewportScale=t.maxViewportScale;const o=`translate(${this.halfTileWidth}, ${this.halfTileHeight})`;this.patternContent.setAttribute("transform",o),this.pattern.appendChild(this.patternContent);const n=document.createElementNS("http://www.w3.org/2000/svg","defs");n.appendChild(this.pattern),this.svg.appendChild(n),this.svg.appendChild(this.patternRenderingRectangle),this.resizeObserver.observe(this.backgroundHost),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated),this.onAfterTransformUpdated()}static configure(e,t,s){new ee(e,t,s)}updateVisibility(){const t=this.canvas.viewport.getViewportMatrix().scale>this.maxViewportScale;t&&this.visible?(this.visible=!1,this.backgroundHost.removeChild(this.svg)):!t&&!this.visible&&(this.visible=!0,this.backgroundHost.appendChild(this.svg))}}class te{constructor(e,t,s,o,n){i(this,"overlayCanvas");i(this,"staticPortId",null);i(this,"isTargetDragging",!0);i(this,"onEdgeCreated",e=>{this.params.onAfterEdgeCreated(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=o,this.params=n,this.overlayCanvas=Le(this.overlayLayer,this.viewportStore),H.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>{const d=this.params.connectionTypeResolver(a);return d===null?!1:(this.grabPort(a,h,d),!0)},onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,o,n){new te(e,t,s,o,n)}grabPort(e,t,s){const o=this.canvas.graph.getPort(e);this.staticPortId=e;const n=o.element.getBoundingClientRect(),a=n.x+n.width/2,h=n.y+n.height/2,d=this.overlayLayer.getBoundingClientRect(),c=this.canvas.viewport.getViewportMatrix(),g=x(c,{x:a-d.x,y:h-d.y}),l=x(c,{x:t.x-d.x,y:t.y-d.y}),u={overlayId:N.Static,portCoords:g,portDirection:o.direction},w={overlayId:N.Dragging,portCoords:l,portDirection:this.params.dragPortDirection};this.isTargetDragging=s==="direct";const[y,A]=this.isTargetDragging?[u,w]:[w,u];this.overlayCanvas.addNode(O(y)),this.overlayCanvas.addNode(O(A)),this.overlayCanvas.addEdge({from:y.overlayId,to:A.overlayId,shape:this.params.edgeShapeFactory(N.Edge)})}resetDragState(){this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}tryCreateConnection(e){const t=we(this.canvas.graph,e),s=this.staticPortId;if(t===null){this.params.onEdgeCreationInterrupted({staticPortId:s,isDirect:this.isTargetDragging});return}const o=this.isTargetDragging?s:t,n=this.isTargetDragging?t:s,a={from:o,to:n},h=this.params.connectionPreprocessor(a);h!==null?(this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)):this.params.onEdgeCreationPrevented(a)}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},o=this.canvas.viewport.getViewportMatrix(),n=x(o,s);this.overlayCanvas.updateNode(N.Dragging,{x:n.x,y:n.y})}}class re{constructor(e,t,s,o,n){i(this,"overlayCanvas");i(this,"staticPortId",null);i(this,"isTargetDragging",!0);i(this,"draggingEdgePayload",null);i(this,"onEdgeReattached",e=>{this.params.onAfterEdgeReattached(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=o,this.params=n,this.overlayCanvas=Le(this.overlayLayer,this.viewportStore),H.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>this.tryStartEdgeDragging(a,h),onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,o,n){new re(e,t,s,o,n)}tryStartEdgeDragging(e,t){const s=this.params.draggingEdgeResolver(e);if(s===null)return!1;const o=this.canvas.graph.getEdge(s);if(o===null)return!1;const n=e===o.from,a=e===o.to,h=n?o.to:o.from;this.staticPortId=h,this.isTargetDragging=a;const d=this.canvas.graph.getPort(e),c=this.canvas.graph.getPort(h),g=c.element.getBoundingClientRect(),l={x:g.x+g.width/2,y:g.y+g.height/2},u=this.canvas.viewport.getViewportMatrix(),w=this.overlayLayer.getBoundingClientRect(),y=x(u,{x:l.x-w.x,y:l.y-w.y}),A=x(u,{x:t.x-w.x,y:t.y-w.y});this.draggingEdgePayload={id:s,from:o.from,to:o.to,shape:o.shape,priority:o.priority},this.canvas.removeEdge(s);const b={overlayId:N.Static,portCoords:y,portDirection:c.direction},T={overlayId:N.Dragging,portCoords:A,portDirection:d.direction},[M,D]=this.isTargetDragging?[b,T]:[T,b];this.overlayCanvas.addNode(O(M)),this.overlayCanvas.addNode(O(D));const R=this.params.draggingEdgeShapeFactory!==null?this.params.draggingEdgeShapeFactory(N.Edge):o.shape;return this.overlayCanvas.addEdge({id:N.Edge,from:M.overlayId,to:D.overlayId,shape:R}),!0}resetDragState(){this.draggingEdgePayload=null,this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},o=this.canvas.viewport.getViewportMatrix(),n=x(o,s);this.overlayCanvas.updateNode(N.Dragging,{x:n.x,y:n.y})}tryCreateConnection(e){const t=we(this.canvas.graph,e);if(this.overlayCanvas.removeEdge(N.Edge),t===null){const d=this.draggingEdgePayload;this.params.onEdgeReattachInterrupted({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority});return}const[s,o]=this.isTargetDragging?[this.staticPortId,t]:[t,this.staticPortId],n=this.draggingEdgePayload,a={id:n.id,from:s,to:o,shape:n.shape,priority:n.priority},h=this.params.connectionPreprocessor(a);if(h!==null)this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeReattached);else{const d=this.draggingEdgePayload;this.params.onEdgeReattachPrevented({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority})}}}class se{constructor(e,t,s){this.canvas=e,this.layoutAlgorithm=t,this.trigger=s,this.trigger.subscribe(()=>{this.applyLayout()})}static configure(e,t,s){new se(e,t,s)}applyLayout(){this.layoutAlgorithm.calculateCoordinates(this.canvas.graph).forEach((t,s)=>{this.canvas.updateNode(s,t)})}}class oe{constructor(e,t){i(this,"applyScheduled",!1);this.canvas=e,this.layoutAlgorithm=t,this.canvas.graph.onAfterNodeAdded.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onBeforeNodeRemoved.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onAfterEdgeAdded.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onBeforeEdgeRemoved.subscribe(()=>{this.scheduleApply()})}static configure(e,t){new oe(e,t)}scheduleApply(){this.applyScheduled||(this.applyScheduled=!0,setTimeout(()=>{this.applyScheduled=!1,this.applyLayout()}))}applyLayout(){this.layoutAlgorithm.calculateCoordinates(this.canvas.graph).forEach((t,s)=>{this.canvas.updateNode(s,t)})}}class Tt{static configure(e,t){const s=t.applyOn;switch(s.type){case"manual":{se.configure(e,t.algorithm,s.trigger);break}case"topologyChangeTimeout":{oe.configure(e,t.algorithm);break}}}}class Ct{constructor(e,t){i(this,"previousTimeStamp");i(this,"step",e=>{if(this.previousTimeStamp===void 0)this.previousTimeStamp=e;else{const t=(e-this.previousTimeStamp)/1e3;this.previousTimeStamp=e,this.callback(t)}this.win.requestAnimationFrame(this.step)});this.win=e,this.callback=t,this.win.requestAnimationFrame(this.step)}}class ie{constructor(e,t,s,o){i(this,"step",e=>{this.algorithm.calculateNextCoordinates(this.canvas.graph,e).forEach((s,o)=>{this.staticNodes.has(o)||this.canvas.updateNode(o,{x:s.x,y:s.y})})});this.canvas=e,this.algorithm=t,this.staticNodes=s,this.win=o,new Ct(this.win,this.step)}static configure(e,t,s,o){new ie(e,t,s,o)}}const Dt=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r},ne=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.inset="0",r},Re=()=>{const r=ne();return r.style.pointerEvents="none",r};class Nt{constructor(e){i(this,"background",ne());i(this,"main",ne());i(this,"overlayConnectablePorts",Re());i(this,"overlayDraggableEdges",Re());i(this,"host",Dt());this.element=e,this.element.appendChild(this.host),this.host.appendChild(this.background),this.host.appendChild(this.main),this.host.appendChild(this.overlayConnectablePorts),this.host.appendChild(this.overlayDraggableEdges)}destroy(){this.host.removeChild(this.background),this.host.removeChild(this.main),this.host.removeChild(this.overlayConnectablePorts),this.host.removeChild(this.overlayDraggableEdges),this.element.removeChild(this.host)}}const ae=r=>()=>r,Fe=ae(0),Mt=()=>{let r=0;return()=>r++},Lt=(r,e)=>{let t=Fe,s=Fe;const o=Mt();return r==="incremental"&&(t=o),e==="incremental"&&(s=o),typeof r=="number"&&(t=ae(r)),typeof e=="number"&&(s=ae(e)),typeof r=="function"&&(t=r),typeof e=="function"&&(s=e),{nodesPriorityFn:t,edgesPriorityFn:s}},he=r=>{if(typeof r=="function")return r;switch(r.type){case"straight":return()=>new Pe({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance,detourDirection:r.detourDirection});case"horizontal":return()=>new be({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"vertical":return()=>new Te({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"direct":return()=>new Z({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,sourceOffset:r.sourceOffset,targetOffset:r.targetOffset});default:return()=>new Se({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleRadius:r.cycleRadius,smallCycleRadius:r.smallCycleRadius,curvature:r.curvature,detourDistance:r.detourDistance,detourDirection:r.detourDirection})}},Rt=r=>{var t,s,o,n,a;const e=Lt((t=r.nodes)==null?void 0:t.priority,(s=r.edges)==null?void 0:s.priority);return{nodes:{centerFn:((o=r.nodes)==null?void 0:o.centerFn)??fe,priorityFn:e.nodesPriorityFn},ports:{direction:((n=r.ports)==null?void 0:n.direction)??0},edges:{shapeFactory:he(((a=r.edges)==null?void 0:a.shape)??{}),priorityFn:e.edgesPriorityFn}}},Ft=r=>{var w,y,A,b,T,M;const e=((w=r.events)==null?void 0:w.onNodeDragStarted)??(()=>{}),t=((y=r.events)==null?void 0:y.onNodeDrag)??(()=>{}),s=r.nodeDragVerifier??(()=>!0),o=((A=r.events)==null?void 0:A.onNodeDragFinished)??(()=>{}),n=r.moveOnTop!==!1,a=r.moveEdgesOnTop!==!1&&n,h=(b=r.mouse)==null?void 0:b.dragCursor,d=h!==void 0?h:"grab",c=(T=r.mouse)==null?void 0:T.mouseDownEventVerifier,g=c!==void 0?c:D=>D.button===0,l=(M=r.mouse)==null?void 0:M.mouseUpEventVerifier,u=l!==void 0?l:D=>D.button===0;return{moveOnTop:n,moveEdgesOnTop:a,dragCursor:d,gridSize:r.gridSize??null,mouseDownEventVerifier:g,mouseUpEventVerifier:u,onNodeDragStarted:e,onNodeDrag:t,nodeDragVerifier:s,onNodeDragFinished:o}},Vt=r=>{const e=r.minX!==null?r.minX:-1/0,t=r.maxX!==null?r.maxX:1/0,s=r.minY!==null?r.minY:-1/0,o=r.maxY!==null?r.maxY:1/0;return n=>{let a=n.nextTransform.x,h=n.nextTransform.y;a<e&&a<n.prevTransform.x&&(a=Math.min(n.prevTransform.x,e));const d=n.canvasWidth*n.prevTransform.scale,c=t-d;a>c&&a>n.prevTransform.x&&(a=Math.max(n.prevTransform.x,c)),h<s&&h<n.prevTransform.y&&(h=Math.min(n.prevTransform.y,s));const g=n.canvasHeight*n.prevTransform.scale,l=o-g;return h>l&&h>n.prevTransform.y&&(h=Math.max(n.prevTransform.y,l)),{scale:n.nextTransform.scale,x:a,y:h}}},It=r=>{const e=r.maxContentScale,t=r.minContentScale,s=e!==null?1/e:0,o=t!==null?1/t:1/0;return n=>{const a=n.prevTransform,h=n.nextTransform;let d=h.scale,c=h.x,g=h.y;if(h.scale>o&&h.scale>a.scale){d=Math.max(a.scale,o),c=a.x,g=a.y;const l=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*l,g=a.y+(h.y-a.y)*l}if(h.scale<s&&h.scale<a.scale){d=Math.min(a.scale,s),c=a.x,g=a.y;const l=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*l,g=a.y+(h.y-a.y)*l}return{scale:d,x:c,y:g}}},$t=r=>e=>r.reduce((t,s)=>s({prevTransform:e.prevTransform,nextTransform:t,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),Ve=r=>{if(typeof r=="function")return r;switch(r.type){case"scale-limit":return It({minContentScale:r.minContentScale??0,maxContentScale:r.maxContentScale??1/0});case"shift-limit":return Vt({minX:r.minX??-1/0,maxX:r.maxX??1/0,minY:r.minY??-1/0,maxY:r.maxY??1/0})}},Ie=r=>{var y,A,b,T,M,D,R,$,Xe,Ye,Ge,je;const e=(y=r==null?void 0:r.scale)==null?void 0:y.mouseWheelSensitivity,t=e!==void 0?e:1.2,s=r==null?void 0:r.transformPreprocessor;let o;s!==void 0?Array.isArray(s)?o=$t(s.map(F=>Ve(F))):o=Ve(s):o=F=>F.nextTransform;const n=((A=r==null?void 0:r.shift)==null?void 0:A.cursor)!==void 0?r.shift.cursor:"grab",a=((b=r==null?void 0:r.events)==null?void 0:b.onBeforeTransformChange)??(()=>{}),h=((T=r==null?void 0:r.events)==null?void 0:T.onTransformChange)??(()=>{}),d=(M=r==null?void 0:r.shift)==null?void 0:M.mouseDownEventVerifier,c=d!==void 0?d:F=>F.button===0,g=(D=r==null?void 0:r.shift)==null?void 0:D.mouseUpEventVerifier,l=g!==void 0?g:F=>F.button===0,u=(R=r==null?void 0:r.scale)==null?void 0:R.mouseWheelEventVerifier,w=u!==void 0?u:()=>!0;return{wheelSensitivity:t,onTransformStarted:(($=r==null?void 0:r.events)==null?void 0:$.onTransformStarted)??(()=>{}),onTransformFinished:((Xe=r==null?void 0:r.events)==null?void 0:Xe.onTransformFinished)??(()=>{}),onBeforeTransformChange:a,onTransformChange:h,transformPreprocessor:o,shiftCursor:n,mouseDownEventVerifier:c,mouseUpEventVerifier:l,mouseWheelEventVerifier:w,scaleWheelFinishTimeout:((Ye=r==null?void 0:r.scale)==null?void 0:Ye.wheelFinishTimeout)??500,onResizeTransformStarted:((Ge=r==null?void 0:r.events)==null?void 0:Ge.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((je=r==null?void 0:r.events)==null?void 0:je.onResizeTransformFinished)??(()=>{})}},Ut=(r,e)=>{const t=document.createElementNS("http://www.w3.org/2000/svg","circle");return t.setAttribute("cx","0"),t.setAttribute("cy","0"),t.setAttribute("r",`${r}`),t.setAttribute("fill",`${e}`),t},Bt=r=>r instanceof SVGElement?r:Ut((r==null?void 0:r.radius)??1.5,(r==null?void 0:r.color)??"#d8d8d8"),Ot=r=>{const e=r.tileDimensions,t=(e==null?void 0:e.width)??25,s=(e==null?void 0:e.height)??25,o=Bt(r.renderer??{});return{tileWidth:t,tileHeight:s,renderer:o,maxViewportScale:r.maxViewportScale??10}},Wt=(r,e,t)=>{var c,g,l;const s=()=>"direct",o=u=>u,n=u=>u.button===0,a=()=>{},h=()=>{},d=()=>{};return{connectionTypeResolver:r.connectionTypeResolver??s,connectionPreprocessor:r.connectionPreprocessor??o,mouseDownEventVerifier:r.mouseDownEventVerifier??n,mouseUpEventVerifier:r.mouseUpEventVerifier??n,onAfterEdgeCreated:((c=r.events)==null?void 0:c.onAfterEdgeCreated)??a,onEdgeCreationInterrupted:((g=r.events)==null?void 0:g.onEdgeCreationInterrupted)??d,onEdgeCreationPrevented:((l=r.events)==null?void 0:l.onEdgeCreationPrevented)??h,dragPortDirection:r.dragPortDirection??t,edgeShapeFactory:r.edgeShape!==void 0?he(r.edgeShape):e}},zt=(r,e)=>{var c,g,l;const t=u=>u,s=u=>u.button===0&&u.ctrlKey,o=u=>u.button===0,n=u=>{const w=e.getPortAdjacentEdgeIds(u);return w.length>0?w[w.length-1]:null},a=()=>{},h=()=>{},d=()=>{};return{connectionPreprocessor:r.connectionPreprocessor??t,mouseDownEventVerifier:r.mouseDownEventVerifier??s,mouseUpEventVerifier:r.mouseUpEventVerifier??o,draggingEdgeResolver:r.draggingEdgeResolver??n,draggingEdgeShapeFactory:r.draggingEdgeShape!==void 0?he(r.draggingEdgeShape):null,onAfterEdgeReattached:((c=r.events)==null?void 0:c.onAfterEdgeReattached)??a,onEdgeReattachInterrupted:((g=r.events)==null?void 0:g.onEdgeReattachInterrupted)??d,onEdgeReattachPrevented:((l=r.events)==null?void 0:l.onEdgeReattachPrevented)??h}},kt=r=>({nodeVerticalRadius:r.nodeContainingRadius.vertical,nodeHorizontalRadius:r.nodeContainingRadius.horizontal}),Ht=r=>{var e,t;return{onAfterNodeDetached:((e=r==null?void 0:r.events)==null?void 0:e.onAfterNodeDetached)??(()=>{}),onBeforeNodeAttached:((t=r==null?void 0:r.events)==null?void 0:t.onBeforeNodeAttached)??(()=>{})}};class $e extends Error{constructor(){super(...arguments);i(this,"name","CanvasBuilderError")}}class Ue{constructor(e,t,s){i(this,"dt");i(this,"nodeMass");i(this,"edgeEquilibriumLength");i(this,"edgeStiffness");i(this,"nodeForcesApplicationStrategy");i(this,"distanceVectorGenerator");this.graph=e,this.currentCoords=t,this.dt=s.dtSec,this.nodeMass=s.nodeMass,this.edgeEquilibriumLength=s.edgeEquilibriumLength,this.edgeStiffness=s.edgeStiffness,this.distanceVectorGenerator=s.distanceVectorGenerator,this.nodeForcesApplicationStrategy=s.nodeForcesApplicationStrategy}apply(){let e=0;const t=new Map;return this.graph.getAllNodeIds().forEach(o=>{t.set(o,{x:0,y:0})}),this.nodeForcesApplicationStrategy.apply(this.currentCoords,t),this.applyEdgeForces(t),this.currentCoords.forEach((o,n)=>{const a=t.get(n),h={x:a.x/this.nodeMass*this.dt,y:a.y/this.nodeMass*this.dt},d=h.x*this.dt,c=h.y*this.dt;o.x+=d,o.y+=c,e=Math.max(e,Math.sqrt(d*d+c*c))}),e}applyEdgeForces(e){this.graph.getAllEdgeIds().forEach(t=>{const s=this.graph.getEdge(t),o=this.graph.getPort(s.from),n=this.graph.getPort(s.to),a=this.currentCoords.get(o.nodeId),h=this.currentCoords.get(n.nodeId),d=this.distanceVectorGenerator.create(a,h),g=(d.d-this.edgeEquilibriumLength)*this.edgeStiffness,l=d.ex*g,u=d.ey*g,w=e.get(o.nodeId),y=e.get(n.nodeId);w.x+=l,w.y+=u,y.x-=l,y.y-=u})}}const Be=(r,e,t)=>{const s=new Map,o=r.getAllNodeIds(),n=Math.sqrt(o.length)*t;return o.forEach(a=>{const h=r.getNode(a);s.set(a,{x:h.x??n*e(),y:h.y??n*e()})}),s};class Oe{constructor(e){i(this,"PI2",2*Math.PI);this.rand=e}create(e,t){const s=t.x-e.x,o=t.y-e.y,n=s*s+o*o;if(n===0){const c=this.PI2*this.rand();return{ex:Math.cos(c),ey:Math.sin(c),d:0}}const a=Math.sqrt(n),h=s/a,d=o/a;return{ex:h,ey:d,d:a}}}const We=r=>{if(r.distance===0)return r.maxForce;const e=r.coefficient*(r.sourceCharge*r.targetCharge/(r.distance*r.distance));return Math.min(e,r.maxForce)};class Xt{constructor(e){i(this,"effectiveDistance");i(this,"nodeCharge");i(this,"distanceVectorGenerator");i(this,"maxForce");this.effectiveDistance=e.effectiveDistance,this.nodeCharge=e.nodeCharge,this.distanceVectorGenerator=e.distanceVectorGenerator,this.maxForce=e.maxForce}apply(e,t){const s=Array.from(t.keys()),o=s.length;for(let n=0;n<o;n++){const a=s[n];for(let h=n+1;h<o;h++){const d=s[h],c=e.get(a),g=e.get(d),l=this.distanceVectorGenerator.create(c,g);if(l.d>this.effectiveDistance)continue;const u=We({coefficient:1,sourceCharge:this.nodeCharge,targetCharge:this.nodeCharge,distance:l.d,maxForce:this.maxForce}),w=u*l.ex,y=u*l.ey,A=t.get(a),b=t.get(d);A.x-=w,A.y-=y,b.x+=w,b.y+=y}}}}const Yt=r=>{if(r.size===0)return{centerX:0,centerY:0,radius:0};let e=1/0,t=-1/0,s=1/0,o=-1/0;r.forEach(d=>{e=Math.min(e,d.x),t=Math.max(t,d.x),s=Math.min(s,d.y),o=Math.max(o,d.y)});const n=t-e,a=o-s,h=Math.max(n,a);return{centerX:(e+t)/2,centerY:(s+o)/2,radius:h/2}};class Gt{constructor(e){i(this,"root");i(this,"leaves",new Map);i(this,"coords");i(this,"areaRadiusThreshold");i(this,"nodeMass");i(this,"nodeCharge");i(this,"sortedParentNodes",[]);this.coords=e.coords,this.areaRadiusThreshold=e.areaRadiusThreshold,this.nodeMass=e.nodeMass,this.nodeCharge=e.nodeCharge,this.root={nodeIds:new Set(e.coords.keys()),box:e.box,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},parent:null,lb:null,lt:null,rb:null,rt:null};let t=[this.root];for(;t.length>0;){const s=[];for(;t.length>0;){const o=t.pop();this.processNode(o).forEach(a=>{s.push(a)})}t=s}this.sortedParentNodes.reverse().forEach(s=>{let o=0,n=0,a=0,h=0;s.lb!==null&&(a+=s.lb.totalMass,h+=s.lb.totalCharge,o+=s.lb.chargeCenter.x*s.lb.totalCharge,n+=s.lb.chargeCenter.y*s.lb.totalCharge),s.lt!==null&&(a+=s.lt.totalMass,h+=s.lt.totalCharge,o+=s.lt.chargeCenter.x*s.lt.totalCharge,n+=s.lt.chargeCenter.y*s.lt.totalCharge),s.rb!==null&&(a+=s.rb.totalMass,h+=s.rb.totalCharge,o+=s.rb.chargeCenter.x*s.rb.totalCharge,n+=s.rb.chargeCenter.y*s.rb.totalCharge),s.rt!==null&&(a+=s.rt.totalMass,h+=s.rt.totalCharge,o+=s.rt.chargeCenter.x*s.rt.totalCharge,n+=s.rt.chargeCenter.y*s.rt.totalCharge),s.totalMass=a,s.totalCharge=h,s.chargeCenter.x=o/h,s.chargeCenter.y=n/h})}getRoot(){return this.root}getLeaf(e){return this.leaves.get(e)}processNode(e){if(e.nodeIds.size<2)return this.setLeaf(e),[];const{centerX:t,centerY:s,radius:o}=e.box;if(o<this.areaRadiusThreshold)return this.setLeaf(e),[];this.sortedParentNodes.push(e);const n=new Set,a=new Set,h=new Set,d=new Set,c=o/2;e.nodeIds.forEach(u=>{const{x:w,y}=this.coords.get(u);w<t?y<s?d.add(u):h.add(u):y<s?a.add(u):n.add(u),e.nodeIds.delete(u)});const g={parent:e,lb:null,lt:null,rb:null,rt:null},l=[];if(n.size>0){const u={nodeIds:n,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},box:{centerX:t+c,centerY:s+c,radius:c},...g};e.rt=u,l.push(u)}if(a.size>0){const u={nodeIds:a,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},box:{centerX:t+c,centerY:s-c,radius:c},...g};e.rb=u,l.push(u)}if(h.size>0){const u={nodeIds:h,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},box:{centerX:t-c,centerY:s+c,radius:c},...g};e.lt=u,l.push(u)}if(d.size>0){const u={nodeIds:d,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},box:{centerX:t-c,centerY:s-c,radius:c},...g};e.lb=u,l.push(u)}return l}setLeaf(e){e.totalMass=this.nodeMass*e.nodeIds.size,e.totalCharge=this.nodeCharge*e.nodeIds.size,e.chargeCenter=this.calculateLeafChargeCenter(e.nodeIds),e.nodeIds.forEach(t=>{this.leaves.set(t,e)})}calculateLeafChargeCenter(e){if(e.size===0)return{x:0,y:0};let t=0,s=0;return e.forEach(o=>{const n=this.coords.get(o);t+=n.x,s+=n.y}),{x:t/e.size,y:s/e.size}}}class jt{constructor(e){i(this,"areaRadiusThreshold");i(this,"nodeMass");i(this,"nodeCharge");i(this,"theta");i(this,"distanceVectorGenerator");i(this,"nodeForceCoefficient");i(this,"maxForce");this.areaRadiusThreshold=e.areaRadiusThreshold,this.nodeMass=e.nodeMass,this.nodeCharge=e.nodeCharge,this.theta=e.theta,this.distanceVectorGenerator=e.distanceVectorGenerator,this.nodeForceCoefficient=e.nodeForceCoefficient,this.maxForce=e.maxForce}apply(e,t){const s=Yt(e),o=new Gt({box:s,coords:e,areaRadiusThreshold:this.areaRadiusThreshold,nodeMass:this.nodeMass,nodeCharge:this.nodeCharge});e.forEach((n,a)=>{const h=this.calculateForceForNode(o.getLeaf(a),a,e),d=t.get(a);this.applyForce(d,h)})}calculateForceForNode(e,t,s){const o=s.get(t),n={x:0,y:0};e.nodeIds.forEach(h=>{if(h!==t){const d=s.get(h),c=this.calculateNodeRepulsiveForce({sourceCharge:this.nodeCharge,targetCharge:this.nodeCharge,sourceCoords:d,targetCoords:o});this.applyForce(n,c)}});let a=e;for(;a!==null;){const h=a.parent;if(h!==null){const d=this.distanceVectorGenerator.create(h.chargeCenter,o);h.box.radius*2<d.d*this.theta?(this.tryApplyFarForce({totalForce:n,targetCoords:o,target:h.lb,current:a}),this.tryApplyFarForce({totalForce:n,targetCoords:o,target:h.rb,current:a}),this.tryApplyFarForce({totalForce:n,targetCoords:o,target:h.rt,current:a}),this.tryApplyFarForce({totalForce:n,targetCoords:o,target:h.lt,current:a})):(this.tryApplyNearForce({totalForce:n,targetCoords:o,target:h.lb,current:a,nodesCoords:s}),this.tryApplyNearForce({totalForce:n,targetCoords:o,target:h.rb,current:a,nodesCoords:s}),this.tryApplyNearForce({totalForce:n,targetCoords:o,target:h.rt,current:a,nodesCoords:s}),this.tryApplyNearForce({totalForce:n,targetCoords:o,target:h.lt,current:a,nodesCoords:s}))}a=a.parent}return n}calculateExactForce(e,t,s){const o={x:0,y:0},n=[e];for(;n.length>0;){const a=n.pop();a.nodeIds.forEach(h=>{const d=s.get(h),c=this.calculateNodeRepulsiveForce({sourceCharge:this.nodeCharge,targetCharge:this.nodeCharge,sourceCoords:d,targetCoords:t});this.applyForce(o,c)}),a.lb!==null&&n.push(a.lb),a.rb!==null&&n.push(a.rb),a.lt!==null&&n.push(a.lt),a.rt!==null&&n.push(a.rt)}return o}calculateApproximateForce(e,t){return this.calculateNodeRepulsiveForce({sourceCharge:this.nodeCharge,targetCharge:e.totalCharge,sourceCoords:e.chargeCenter,targetCoords:t})}calculateNodeRepulsiveForce(e){const t=this.distanceVectorGenerator.create(e.sourceCoords,e.targetCoords),s=We({coefficient:this.nodeForceCoefficient,sourceCharge:e.sourceCharge,targetCharge:e.targetCharge,distance:t.d,maxForce:this.maxForce});return{x:s*t.ex,y:s*t.ey}}applyForce(e,t){e.x+=t.x,e.y+=t.y}tryApplyFarForce(e){if(e.target!==null&&e.target!==e.current){const t=this.calculateApproximateForce(e.target,e.targetCoords);this.applyForce(e.totalForce,t)}}tryApplyNearForce(e){if(e.target!==null&&e.target!==e.current){const t=this.calculateExactForce(e.target,e.targetCoords,e.nodesCoords);this.applyForce(e.totalForce,t)}}}const ze=r=>r.theta!==0?new jt({nodeCharge:r.nodeCharge,nodeForceCoefficient:r.nodeForceCoefficient,distanceVectorGenerator:r.distanceVectorGenerator,maxForce:r.maxForce,theta:r.theta,nodeMass:r.nodeMass,areaRadiusThreshold:r.areaRadiusThreshold}):new Xt({nodeCharge:r.nodeCharge,nodeForceCoefficient:r.nodeForceCoefficient,distanceVectorGenerator:r.distanceVectorGenerator,effectiveDistance:r.effectiveDistance,maxForce:r.maxForce});class Kt{constructor(e){i(this,"distanceVectorGenerator");i(this,"nodeForcesApplicationStrategy");this.params=e,this.distanceVectorGenerator=new Oe(this.params.rand),this.nodeForcesApplicationStrategy=ze({distanceVectorGenerator:this.distanceVectorGenerator,nodeCharge:this.params.nodeCharge,effectiveDistance:this.params.effectiveDistance,maxForce:this.params.maxForce,nodeForceCoefficient:this.params.nodeForceCoefficient,theta:this.params.barnesHutTheta,areaRadiusThreshold:this.params.barnesHutAreaRadiusThreshold,nodeMass:this.params.nodeMass})}calculateCoordinates(e){const t=Be(e,this.params.rand,this.params.edgeEquilibriumLength);for(let s=0;s<this.params.maxIterations&&!(new Ue(e,t,{distanceVectorGenerator:this.distanceVectorGenerator,nodeForcesApplicationStrategy:this.nodeForcesApplicationStrategy,dtSec:this.params.dtSec,nodeMass:this.params.nodeMass,edgeEquilibriumLength:this.params.edgeEquilibriumLength,edgeStiffness:this.params.edgeStiffness}).apply()<this.params.convergenceDelta);s++);return t}}class Qt{constructor(e){i(this,"distanceVectorGenerator");i(this,"nodeForcesApplicationStrategy");this.params=e,this.distanceVectorGenerator=new Oe(e.rand),this.nodeForcesApplicationStrategy=ze({distanceVectorGenerator:this.distanceVectorGenerator,nodeCharge:this.params.nodeCharge,effectiveDistance:this.params.effectiveDistance,maxForce:this.params.maxForce,nodeForceCoefficient:this.params.nodeForceCoefficient,theta:this.params.barnesHutTheta,areaRadiusThreshold:this.params.barnesHutAreaRadiusThreshold,nodeMass:this.params.nodeMass})}calculateNextCoordinates(e,t){const s=Be(e,this.params.rand,this.params.edgeEquilibriumLength);return new Ue(e,s,{distanceVectorGenerator:this.distanceVectorGenerator,nodeForcesApplicationStrategy:this.nodeForcesApplicationStrategy,dtSec:Math.min(t,this.params.maxTimeDeltaSec),nodeMass:this.params.nodeMass,edgeEquilibriumLength:this.params.edgeEquilibriumLength,edgeStiffness:this.params.edgeStiffness}).apply()<this.params.convergenceDelta&&!e.getAllNodeIds().some(h=>{const d=e.getNode(h);return d.x===null||d.y===null})?new Map:s}}const ke=r=>{let e=1779033703,t=3144134277,s=1013904242,o=2773480762;for(let n=0,a;n<r.length;n++)a=r.charCodeAt(n),e=t^Math.imul(e^a,597399067),t=s^Math.imul(t^a,2869860233),s=o^Math.imul(s^a,951274213),o=e^Math.imul(o^a,2716044179);return e=Math.imul(s^e>>>18,597399067),t=Math.imul(o^t>>>22,2869860233),s=Math.imul(e^s>>>17,951274213),o=Math.imul(t^o>>>19,2716044179),e^=t^s^o,t^=e,s^=e,o^=e,[e>>>0,t>>>0,s>>>0,o>>>0]},He=(r,e,t,s)=>function(){r|=0,e|=0,t|=0,s|=0;const o=(r+e|0)+s|0;return s=s+1|0,r=e^e>>>9,e=t+(t<<3)|0,t=t<<21|t>>>11,t=t+o|0,(o>>>0)/4294967296},v=Object.freeze({seed:"HTMLGraph is awesome",maxTimeDeltaSec:.01,nodeCharge:1e5,nodeMass:1,edgeEquilibriumLength:300,edgeStiffness:1e3,effectiveDistance:1e3,dtSec:.01,maxIterations:1e3,convergenceDelta:1,maxForce:1e7,nodeForceCoefficient:1,barnesHutAreaRadiusThreshold:.01,barnesHutTheta:1}),Zt=r=>{var e,t,s;switch((e=r==null?void 0:r.algorithm)==null?void 0:e.type){case"custom":return r.algorithm.instance;default:{const o=r==null?void 0:r.algorithm,n=ke((o==null?void 0:o.seed)??v.seed),a=He(n[0],n[1],n[2],n[3]);return new Qt({rand:a,maxTimeDeltaSec:(o==null?void 0:o.maxTimeDeltaSec)??v.maxTimeDeltaSec,nodeCharge:(o==null?void 0:o.nodeCharge)??v.nodeCharge,nodeMass:(o==null?void 0:o.nodeMass)??v.nodeMass,edgeEquilibriumLength:(o==null?void 0:o.edgeEquilibriumLength)??v.edgeEquilibriumLength,effectiveDistance:v.effectiveDistance,edgeStiffness:(o==null?void 0:o.edgeStiffness)??v.edgeStiffness,convergenceDelta:(o==null?void 0:o.convergenceDelta)??v.convergenceDelta,maxForce:(o==null?void 0:o.maxForce)??v.maxForce,nodeForceCoefficient:(o==null?void 0:o.nodeForceCoefficient)??v.nodeForceCoefficient,barnesHutTheta:((t=o==null?void 0:o.barnesHut)==null?void 0:t.theta)??v.barnesHutTheta,barnesHutAreaRadiusThreshold:((s=o==null?void 0:o.barnesHut)==null?void 0:s.areaRadiusThreshold)??v.barnesHutAreaRadiusThreshold})}}},Jt=r=>r instanceof U?{type:"manual",trigger:r}:{type:"topologyChangeTimeout"},qt=r=>{var e,t;switch(r==null?void 0:r.type){case"custom":return r.instance;default:{const s=ke((r==null?void 0:r.seed)??v.seed),o=He(s[0],s[1],s[2],s[3]);return new Kt({dtSec:(r==null?void 0:r.dtSec)??v.dtSec,maxIterations:(r==null?void 0:r.maxIterations)??v.maxIterations,rand:o,nodeCharge:(r==null?void 0:r.nodeCharge)??v.nodeCharge,nodeMass:(r==null?void 0:r.nodeMass)??v.nodeMass,edgeEquilibriumLength:(r==null?void 0:r.edgeEquilibriumLength)??v.edgeEquilibriumLength,edgeStiffness:(r==null?void 0:r.edgeStiffness)??v.edgeStiffness,effectiveDistance:(r==null?void 0:r.effectiveDistance)??v.effectiveDistance,convergenceDelta:(r==null?void 0:r.convergenceDelta)??v.convergenceDelta,maxForce:(r==null?void 0:r.maxForce)??v.maxForce,nodeForceCoefficient:(r==null?void 0:r.nodeForceCoefficient)??v.nodeForceCoefficient,barnesHutTheta:((e=r==null?void 0:r.barnesHut)==null?void 0:e.theta)??v.barnesHutTheta,barnesHutAreaRadiusThreshold:((t=r==null?void 0:r.barnesHut)==null?void 0:t.areaRadiusThreshold)??v.barnesHutAreaRadiusThreshold})}}},_t=r=>({algorithm:qt(r==null?void 0:r.algorithm),applyOn:Jt(r==null?void 0:r.applyOn)}),er=(r,e)=>({...r,onNodeDragStarted:t=>{e.add(t),r.onNodeDragStarted(t)},onNodeDragFinished:t=>{e.delete(t),r.onNodeDragFinished(t)}}),tr=(r,e)=>{r.onBeforeNodeRemoved.subscribe(t=>{e.delete(t)}),r.onBeforeClear.subscribe(()=>{e.clear()})};class rr{constructor(e){i(this,"used",!1);i(this,"canvasDefaults",{});i(this,"dragConfig",{});i(this,"transformConfig",{});i(this,"backgroundConfig",{});i(this,"connectablePortsConfig",{});i(this,"draggableEdgesConfig",{});i(this,"virtualScrollConfig");i(this,"layoutConfig",{});i(this,"animatedLayoutConfig",{});i(this,"hasDraggableNodes",!1);i(this,"hasTransformableViewport",!1);i(this,"hasNodeResizeReactiveEdges",!1);i(this,"hasBackground",!1);i(this,"hasUserConnectablePorts",!1);i(this,"hasUserDraggableEdges",!1);i(this,"hasAnimatedLayout",!1);i(this,"hasLayout",!1);i(this,"boxRenderingTrigger",new U);i(this,"graphStore",new le);i(this,"viewportStore",new tt);i(this,"graph",new Ne(this.graphStore));i(this,"viewport",new Me(this.viewportStore));i(this,"window",window);i(this,"animationStaticNodes",new Set);this.element=e}setDefaults(e){return this.canvasDefaults=e,this}enableUserDraggableNodes(e){return this.hasDraggableNodes=!0,this.dragConfig=e??{},this}enableUserTransformableViewport(e){return this.hasTransformableViewport=!0,this.transformConfig=e??{},this}enableNodeResizeReactiveEdges(){return this.hasNodeResizeReactiveEdges=!0,this}enableVirtualScroll(e){return this.virtualScrollConfig=e,this}enableBackground(e){return this.hasBackground=!0,this.backgroundConfig=e??{},this}enableUserConnectablePorts(e){return this.hasUserConnectablePorts=!0,this.connectablePortsConfig=e??{},this}enableUserDraggableEdges(e){return this.hasUserDraggableEdges=!0,this.draggableEdgesConfig=e??{},this}enableLayout(e){return this.layoutConfig=e??{},this.hasLayout=!0,this.hasAnimatedLayout=!1,this}enableAnimatedLayout(e){return this.animatedLayoutConfig=e??{},this.hasAnimatedLayout=!0,this.hasLayout=!1,this}build(){if(this.used)throw new $e("CanvasBuilder is a single use object");this.used=!0;const e=new Nt(this.element);let t=new de(this.graphStore,this.viewportStore,e.main);this.virtualScrollConfig!==void 0&&(t=new qe(t,this.graphStore,this.boxRenderingTrigger,Ht(this.virtualScrollConfig))),t=new _e(t,this.graphStore);const s=Rt(this.canvasDefaults),o=new ce(this.graph,this.viewport,this.graphStore,this.viewportStore,t,s);if(this.hasBackground&&ee.configure(o,Ot(this.backgroundConfig),e.background),this.hasNodeResizeReactiveEdges&&j.configure(o),this.hasDraggableNodes){let a=Ft(this.dragConfig);this.hasAnimatedLayout&&(a=er(a,this.animationStaticNodes)),q.configure(o,e.main,this.window,a)}if(this.hasUserConnectablePorts){const a=Wt(this.connectablePortsConfig,s.edges.shapeFactory,s.ports.direction);te.configure(o,e.overlayConnectablePorts,this.viewportStore,this.window,a)}if(this.hasUserDraggableEdges){const a=zt(this.draggableEdgesConfig,o.graph);re.configure(o,e.overlayDraggableEdges,this.viewportStore,this.window,a)}this.virtualScrollConfig!==void 0?_.configure(o,e.main,this.window,Ie(this.transformConfig),this.boxRenderingTrigger,kt(this.virtualScrollConfig)):this.hasTransformableViewport&&Y.configure(o,e.main,this.window,Ie(this.transformConfig)),this.hasLayout&&Tt.configure(o,_t(this.layoutConfig)),this.hasAnimatedLayout&&(tr(o.graph,this.animationStaticNodes),ie.configure(o,Zt(this.animatedLayoutConfig),this.animationStaticNodes,this.window));const n=()=>{e.destroy(),o.onBeforeDestroy.unsubscribe(n)};return o.onBeforeDestroy.subscribe(n),o}}E.BezierEdgeShape=Se,E.CanvasBuilder=rr,E.CanvasBuilderError=$e,E.CanvasError=P,E.ConnectionCategory=C,E.DirectEdgeShape=Z,E.EventSubject=U,E.HorizontalEdgeShape=be,E.InteractiveEdgeError=De,E.InteractiveEdgeShape=J,E.MidpointEdgeShape=Et,E.StraightEdgeShape=Pe,E.VerticalEdgeShape=Te,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
1
+ (function(E,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(E=typeof globalThis<"u"?globalThis:E||self,A(E.HtmlGraph={}))})(this,function(E){"use strict";var sr=Object.defineProperty;var or=(E,A,C)=>A in E?sr(E,A,{enumerable:!0,configurable:!0,writable:!0,value:C}):E[A]=C;var i=(E,A,C)=>or(E,typeof A!="symbol"?A+"":A,C);const A=(r,e)=>({x:r.scale*e.x+r.x,y:r.scale*e.y+r.y});var C=(r=>(r.Line="line",r.NodeCycle="node-cycle",r.PortCycle="port-cycle",r))(C||{});const Ke=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r.style.overflow="hidden",r},Qe=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="0",r.style.height="0",r},Ze=r=>{r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.visibility="hidden"};class de{constructor(e,t,s){i(this,"host",Ke());i(this,"container",Qe());i(this,"edgeIdToElementMap",new Map);i(this,"attachedNodeIds",new Set);i(this,"applyTransform",()=>{const e=this.viewportStore.getContentMatrix();this.container.style.transform=`matrix(${e.scale}, 0, 0, ${e.scale}, ${e.x}, ${e.y})`});this.graphStore=e,this.viewportStore=t,this.element=s,this.element.appendChild(this.host),this.host.appendChild(this.container),this.viewportStore.onAfterUpdated.subscribe(this.applyTransform)}attachNode(e){const t=this.graphStore.getNode(e);Ze(t.element),this.attachedNodeIds.add(e),this.container.appendChild(t.element),this.updateNodePosition(e),this.updateNodePriority(e),t.element.style.visibility="visible"}detachNode(e){const t=this.graphStore.getNode(e);this.container.removeChild(t.element),this.attachedNodeIds.delete(e)}attachEdge(e){const t=this.graphStore.getEdge(e).payload.shape.svg;this.edgeIdToElementMap.set(e,t),this.container.appendChild(t),this.renderEdge(e),this.updateEdgePriority(e)}detachEdge(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t),this.edgeIdToElementMap.delete(e)}clear(){this.edgeIdToElementMap.forEach((e,t)=>{this.detachEdge(t)}),this.attachedNodeIds.forEach(e=>{this.detachNode(e)})}destroy(){this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform),this.element.removeChild(this.host),this.host.removeChild(this.container)}updateNodePosition(e){const t=this.graphStore.getNode(e),{width:s,height:o}=t.element.getBoundingClientRect(),n=this.viewportStore.getViewportMatrix().scale,{payload:a}=t,h=a.centerFn(s,o),d=a.x-n*h.x,c=a.y-n*h.y;t.element.style.transform=`translate(${d}px, ${c}px)`}updateNodePriority(e){const t=this.graphStore.getNode(e);t.element.style.zIndex=`${t.payload.priority}`}updateEdgeShape(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t);const o=this.graphStore.getEdge(e).payload.shape.svg;this.edgeIdToElementMap.set(e,o),this.container.appendChild(o)}renderEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),o=this.graphStore.getPort(t.to),n=s.element.getBoundingClientRect(),a=o.element.getBoundingClientRect(),h=this.host.getBoundingClientRect(),d=this.viewportStore.getViewportMatrix(),c=this.createEdgeRenderPort(s,n,h,d),g=this.createEdgeRenderPort(o,a,h,d);let l=C.Line;s.element===o.element?l=C.PortCycle:s.nodeId===o.nodeId&&(l=C.NodeCycle),t.payload.shape.render({from:c,to:g,category:l})}updateEdgePriority(e){const t=this.graphStore.getEdge(e);t.payload.shape.svg.style.zIndex=`${t.payload.priority}`}createEdgeRenderPort(e,t,s,o){const n={x:t.left-s.left,y:t.top-s.top},a=A(o,n);return{x:a.x,y:a.y,width:t.width*o.scale,height:t.height*o.scale,direction:e.payload.direction}}}class qe{constructor(e){i(this,"xFrom",1/0);i(this,"yFrom",1/0);i(this,"xTo",1/0);i(this,"yTo",1/0);this.graphStore=e}setRenderingBox(e){this.xFrom=e.x,this.xTo=e.x+e.width,this.yFrom=e.y,this.yTo=e.y+e.height}hasNode(e){const t=this.graphStore.getNode(e).payload,{x:s,y:o}=t;return s>=this.xFrom&&s<=this.xTo&&o>=this.yFrom&&o<=this.yTo}hasEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,o=this.graphStore.getPort(t.to).nodeId,n=this.graphStore.getNode(s).payload,a=this.graphStore.getNode(o).payload,h=Math.min(n.x,a.x),d=Math.max(n.x,a.x),c=Math.min(n.y,a.y),g=Math.max(n.y,a.y);return h<=this.xTo&&d>=this.xFrom&&c<=this.yTo&&g>=this.yFrom}}class Je{constructor(e,t,s,o){i(this,"attachedNodes",new Set);i(this,"attachedEdges",new Set);i(this,"renderingBox");i(this,"updateViewport",e=>{this.renderingBox.setRenderingBox(e);const t=new Set,s=new Set,o=new Set,n=new Set;this.graphStore.getAllNodeIds().forEach(a=>{const h=this.renderingBox.hasNode(a),d=this.attachedNodes.has(a);h&&!d?t.add(a):!h&&d&&s.add(a)}),this.graphStore.getAllEdgeIds().forEach(a=>{const h=this.renderingBox.hasEdge(a),d=this.attachedEdges.has(a),c=this.graphStore.getEdge(a),g=this.graphStore.getPort(c.from).nodeId,l=this.graphStore.getPort(c.to).nodeId;h&&(this.renderingBox.hasNode(g)||(t.add(g),s.delete(g)),this.renderingBox.hasNode(l)||(t.add(l),s.delete(l))),h&&!d?o.add(a):!h&&d&&n.add(a)}),n.forEach(a=>{this.handleDetachEdge(a)}),s.forEach(a=>{this.handleDetachNode(a)}),t.forEach(a=>{this.attachedNodes.has(a)||this.handleAttachNode(a)}),o.forEach(a=>{this.handleAttachEdge(a)})});this.htmlView=e,this.graphStore=t,this.trigger=s,this.params=o,this.renderingBox=new qe(this.graphStore),this.trigger.subscribe(this.updateViewport)}attachNode(e){this.renderingBox.hasNode(e)&&this.handleAttachNode(e)}detachNode(e){this.attachedNodes.has(e)&&this.handleDetachNode(e)}attachEdge(e){this.renderingBox.hasEdge(e)&&this.attachEdgeEntities(e)}detachEdge(e){this.attachedEdges.has(e)&&this.handleDetachEdge(e)}updateNodePosition(e){this.attachedNodes.has(e)?this.htmlView.updateNodePosition(e):this.renderingBox.hasNode(e)&&(this.handleAttachNode(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(t=>{this.attachEdgeEntities(t)}))}updateNodePriority(e){this.attachedNodes.has(e)&&this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgeShape(e)}renderEdge(e){this.attachedEdges.has(e)&&this.htmlView.renderEdge(e)}updateEdgePriority(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgePriority(e)}clear(){this.htmlView.clear(),this.attachedNodes.clear(),this.attachedEdges.clear()}destroy(){this.clear(),this.htmlView.destroy(),this.trigger.unsubscribe(this.updateViewport)}attachEdgeEntities(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,o=this.graphStore.getPort(t.to).nodeId;this.attachedNodes.has(s)||this.handleAttachNode(s),this.attachedNodes.has(o)||this.handleAttachNode(o),this.handleAttachEdge(e)}handleAttachNode(e){this.params.onBeforeNodeAttached(e),this.attachedNodes.add(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.attachedNodes.delete(e),this.params.onAfterNodeDetached(e)}handleAttachEdge(e){this.attachedEdges.add(e),this.htmlView.attachEdge(e)}handleDetachEdge(e){this.htmlView.detachEdge(e),this.attachedEdges.delete(e)}}class _e{constructor(e,t){i(this,"deferredNodes",new Set);i(this,"deferredEdges",new Set);this.htmlView=e,this.graphStore=t}attachNode(e){this.isNodeValid(e)?this.htmlView.attachNode(e):this.deferredNodes.add(e)}detachNode(e){this.deferredNodes.has(e)?this.deferredNodes.delete(e):this.htmlView.detachNode(e)}attachEdge(e){this.isEdgeValid(e)?this.htmlView.attachEdge(e):this.deferredEdges.add(e)}detachEdge(e){this.deferredEdges.has(e)?this.deferredEdges.delete(e):this.htmlView.detachEdge(e)}updateNodePosition(e){this.deferredNodes.has(e)?this.tryAttachNode(e):this.htmlView.updateNodePosition(e)}updateNodePriority(e){this.deferredNodes.has(e)?this.tryAttachNode(e):this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.updateEdgeShape(e)}renderEdge(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.renderEdge(e)}updateEdgePriority(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.updateEdgePriority(e)}clear(){this.deferredNodes.clear(),this.deferredEdges.clear(),this.htmlView.clear()}destroy(){this.htmlView.destroy()}isNodeValid(e){const t=this.graphStore.getNode(e);return!(t.payload.x===null||t.payload.y===null)}tryAttachNode(e){this.isNodeValid(e)&&(this.deferredNodes.delete(e),this.htmlView.attachNode(e))}isEdgeValid(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),o=this.graphStore.getPort(t.to);return!(this.deferredNodes.has(s.nodeId)||this.deferredNodes.has(o.nodeId))}tryAttachEdge(e){this.isEdgeValid(e)&&(this.deferredEdges.delete(e),this.htmlView.attachEdge(e))}}class U{constructor(){i(this,"callbacks",new Set)}subscribe(e){this.callbacks.add(e)}unsubscribe(e){this.callbacks.delete(e)}emit(e){this.callbacks.forEach(t=>{t(e)})}}const S=()=>{const r=new U;return[r,r]};class G{constructor(e){i(this,"counter",0);this.checkExists=e}create(e){if(e!==void 0)return e;for(;this.checkExists(this.counter);)this.counter++;return this.counter}reset(){this.counter=0}}class P extends Error{constructor(){super(...arguments);i(this,"name","CanvasError")}}class ce{constructor(e,t,s,o,n,a){i(this,"nodeIdGenerator",new G(e=>this.graphStore.getNode(e)!==void 0));i(this,"portIdGenerator",new G(e=>this.graphStore.getPort(e)!==void 0));i(this,"edgeIdGenerator",new G(e=>this.graphStore.getEdge(e)!==void 0));i(this,"onAfterNodeAdded",e=>{this.htmlView.attachNode(e)});i(this,"onAfterNodeUpdated",e=>{this.htmlView.updateNodePosition(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});i(this,"onAfterNodePriorityUpdated",e=>{this.htmlView.updateNodePriority(e)});i(this,"onBeforeNodeRemoved",e=>{this.graphStore.getNodePortIds(e).forEach(t=>{this.unmarkPort(t)}),this.htmlView.detachNode(e)});i(this,"onAfterPortUpdated",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});i(this,"onBeforePortUnmarked",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(t=>{this.removeEdge(t)})});i(this,"onAfterEdgeAdded",e=>{this.htmlView.attachEdge(e)});i(this,"onAfterEdgeShapeUpdated",e=>{this.htmlView.updateEdgeShape(e)});i(this,"onAfterEdgeUpdated",e=>{this.htmlView.renderEdge(e)});i(this,"onAfterEdgePriorityUpdated",e=>{this.htmlView.updateEdgePriority(e)});i(this,"onBeforeEdgeRemoved",e=>{this.htmlView.detachEdge(e)});i(this,"onBeforeClear",()=>{this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset(),this.htmlView.clear()});i(this,"onBeforeDestroyEmitter");i(this,"destroyed",!1);i(this,"onBeforeDestroy");this.graph=e,this.viewport=t,this.graphStore=s,this.viewportStore=o,this.htmlView=n,this.params=a,this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.subscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.subscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.subscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.subscribe(this.onBeforeClear),[this.onBeforeDestroyEmitter,this.onBeforeDestroy]=S()}addNode(e){const t=this.nodeIdGenerator.create(e.id);if(this.graphStore.getNode(t)!==void 0)throw new P("failed to add node with existing id");if(this.graphStore.getElementNodeId(e.element)!==void 0)throw new P("failed to add node with html element already in use by another node");if(this.graphStore.addNode({id:t,element:e.element,x:e.x??null,y:e.y??null,centerFn:e.centerFn??this.params.nodes.centerFn,priority:e.priority??this.params.nodes.priorityFn()}),e.ports!==void 0)for(const s of e.ports)this.markPort({id:s.id,element:s.element,nodeId:t,direction:s.direction});return this}updateNode(e,t){if(this.graphStore.getNode(e)===void 0)throw new P("failed to update nonexistent node");return this.graphStore.updateNode(e,t??{}),this}removeNode(e){if(this.graphStore.getNode(e)===void 0)throw new P("failed to remove nonexistent node");return this.graphStore.removeNode(e),this}markPort(e){const t=this.portIdGenerator.create(e.id);if(this.graphStore.getPort(t)!==void 0)throw new P("failed to add port with existing id");if(this.graphStore.getNode(e.nodeId)===void 0)throw new P("failed to mark port for nonexistent node");return this.graphStore.addPort({id:t,element:e.element,nodeId:e.nodeId,direction:e.direction??this.params.ports.direction}),this}updatePort(e,t){if(this.graphStore.getPort(e)===void 0)throw new P("failed to update nonexistent port");return this.graphStore.updatePort(e,t??{}),this}unmarkPort(e){if(this.graphStore.getPort(e)===void 0)throw new P("failed to unmark nonexistent port");return this.graphStore.removePort(e),this}addEdge(e){const t=this.edgeIdGenerator.create(e.id);if(this.graphStore.getEdge(t)!==void 0)throw new P("failed to add edge with existing id");if(this.graphStore.getPort(e.from)===void 0)throw new P("failed to add edge from nonexistent port");if(this.graphStore.getPort(e.to)===void 0)throw new P("failed to add edge to nonexistent port");return this.graphStore.addEdge({id:t,from:e.from,to:e.to,shape:e.shape??this.params.edges.shapeFactory(t),priority:e.priority??this.params.edges.priorityFn()}),this}updateEdge(e,t){if(this.graphStore.getEdge(e)===void 0)throw new P("failed to update nonexistent edge");return this.graphStore.updateEdge(e,t??{}),this}removeEdge(e){if(this.graphStore.getEdge(e)===void 0)throw new P("failed to remove nonexistent edge");return this.graphStore.removeEdge(e),this}clear(){return this.graphStore.clear(),this}patchViewportMatrix(e){return this.viewportStore.patchViewportMatrix(e),this}patchContentMatrix(e){return this.viewportStore.patchContentMatrix(e),this}destroy(){this.destroyed||(this.clear(),this.onBeforeDestroyEmitter.emit(),this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.unsubscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear),this.htmlView.destroy(),this.destroyed=!0)}}class et{constructor(){i(this,"singleToMultiMap",new Map);i(this,"multiToSingleMap",new Map)}addRecord(e,t){const s=this.singleToMultiMap.get(e);s===void 0?this.singleToMultiMap.set(e,new Set([t])):s.add(t),this.multiToSingleMap.set(t,e)}getMultiBySingle(e){const t=this.singleToMultiMap.get(e)??new Set;return Array.from(t.values())}removeByMulti(e){const t=this.multiToSingleMap.get(e),s=this.singleToMultiMap.get(t);s.delete(e),s.size===0&&this.singleToMultiMap.delete(t),this.multiToSingleMap.delete(e)}getByMulti(e){return this.multiToSingleMap.get(e)}removeBySingle(e){this.singleToMultiMap.get(e).forEach(s=>{this.multiToSingleMap.delete(s)}),this.singleToMultiMap.delete(e)}clear(){this.singleToMultiMap.clear(),this.multiToSingleMap.clear()}forEachSingle(e){this.singleToMultiMap.forEach((t,s)=>{e(s)})}hasSingle(e){return this.singleToMultiMap.get(e)!==void 0}hasMulti(e){return this.multiToSingleMap.get(e)!==void 0}}class le{constructor(){i(this,"nodes",new Map);i(this,"ports",new Map);i(this,"edges",new Map);i(this,"nodesElementsMap",new Map);i(this,"portIncomingEdges",new Map);i(this,"portOutcomingEdges",new Map);i(this,"portCycleEdges",new Map);i(this,"elementPorts",new et);i(this,"afterNodeAddedEmitter");i(this,"onAfterNodeAdded");i(this,"afterNodeUpdatedEmitter");i(this,"onAfterNodeUpdated");i(this,"afterNodePriorityUpdatedEmitter");i(this,"onAfterNodePriorityUpdated");i(this,"beforeNodeRemovedEmitter");i(this,"onBeforeNodeRemoved");i(this,"afterPortAddedEmitter");i(this,"onAfterPortAdded");i(this,"afterPortUpdatedEmitter");i(this,"onAfterPortUpdated");i(this,"beforePortRemovedEmitter");i(this,"onBeforePortRemoved");i(this,"afterEdgeAddedEmitter");i(this,"onAfterEdgeAdded");i(this,"afterEdgeShapeUpdatedEmitter");i(this,"onAfterEdgeShapeUpdated");i(this,"afterEdgeUpdatedEmitter");i(this,"onAfterEdgeUpdated");i(this,"afterEdgePriorityUpdatedEmitter");i(this,"onAfterEdgePriorityUpdated");i(this,"beforeEdgeRemovedEmitter");i(this,"onBeforeEdgeRemoved");i(this,"beforeClearEmitter");i(this,"onBeforeClear");[this.afterNodeAddedEmitter,this.onAfterNodeAdded]=S(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=S(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=S(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=S(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=S(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=S(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=S(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=S(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=S(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=S(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=S(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=S(),[this.beforeClearEmitter,this.onBeforeClear]=S()}addNode(e){const t=new Map,s={element:e.element,payload:{x:e.x,y:e.y,centerFn:e.centerFn,priority:e.priority},ports:t};this.nodes.set(e.id,s),this.nodesElementsMap.set(e.element,e.id),this.afterNodeAddedEmitter.emit(e.id)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(e){return this.nodes.get(e)}getElementNodeId(e){return this.nodesElementsMap.get(e)}updateNode(e,t){const s=this.nodes.get(e).payload;s.x=t.x??s.x,s.y=t.y??s.y,s.centerFn=t.centerFn??s.centerFn,t.priority!==void 0&&(s.priority=t.priority,this.afterNodePriorityUpdatedEmitter.emit(e)),this.afterNodeUpdatedEmitter.emit(e)}removeNode(e){this.beforeNodeRemovedEmitter.emit(e);const t=this.nodes.get(e);this.nodesElementsMap.delete(t.element),this.nodes.delete(e)}addPort(e){this.ports.set(e.id,{element:e.element,payload:{direction:e.direction},nodeId:e.nodeId}),this.elementPorts.addRecord(e.element,e.id),this.portCycleEdges.set(e.id,new Set),this.portIncomingEdges.set(e.id,new Set),this.portOutcomingEdges.set(e.id,new Set),this.nodes.get(e.nodeId).ports.set(e.id,e.element),this.afterPortAddedEmitter.emit(e.id)}getPort(e){return this.ports.get(e)}updatePort(e,t){const s=this.ports.get(e).payload;s.direction=t.direction??s.direction,this.afterPortUpdatedEmitter.emit(e)}getAllPortIds(){return Array.from(this.ports.keys())}getElementPortIds(e){return this.elementPorts.getMultiBySingle(e)}getNodePortIds(e){const t=this.nodes.get(e);if(t!==void 0)return Array.from(t.ports.keys())}removePort(e){const t=this.ports.get(e).nodeId;this.beforePortRemovedEmitter.emit(e),this.nodes.get(t).ports.delete(e),this.ports.delete(e),this.elementPorts.removeByMulti(e)}addEdge(e){this.addEdgeInternal(e),this.afterEdgeAddedEmitter.emit(e.id)}updateEdge(e,t){if(t.from!==void 0||t.to!==void 0){const o=this.edges.get(e),n=o.payload;this.removeEdgeInternal(e),this.addEdgeInternal({id:e,from:t.from??o.from,to:t.to??o.to,shape:n.shape,priority:n.priority})}const s=this.edges.get(e);t.shape!==void 0&&(s.payload.shape=t.shape,this.afterEdgeShapeUpdatedEmitter.emit(e)),t.priority!==void 0&&(s.payload.priority=t.priority,this.afterEdgePriorityUpdatedEmitter.emit(e)),this.afterEdgeUpdatedEmitter.emit(e)}getAllEdgeIds(){return Array.from(this.edges.keys())}getEdge(e){return this.edges.get(e)}removeEdge(e){this.beforeEdgeRemovedEmitter.emit(e),this.removeEdgeInternal(e)}clear(){this.beforeClearEmitter.emit(),this.portIncomingEdges.clear(),this.portOutcomingEdges.clear(),this.portCycleEdges.clear(),this.elementPorts.clear(),this.nodesElementsMap.clear(),this.edges.clear(),this.ports.clear(),this.nodes.clear()}getPortIncomingEdgeIds(e){return Array.from(this.portIncomingEdges.get(e))}getPortOutgoingEdgeIds(e){return Array.from(this.portOutcomingEdges.get(e))}getPortCycleEdgeIds(e){return Array.from(this.portCycleEdges.get(e))}getPortAdjacentEdgeIds(e){return[...this.getPortIncomingEdgeIds(e),...this.getPortOutgoingEdgeIds(e),...this.getPortCycleEdgeIds(e)]}getNodeIncomingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(o=>{this.getPortIncomingEdgeIds(o).filter(n=>{const a=this.getEdge(n);return this.getPort(a.from).nodeId!==e}).forEach(n=>{s.push(n)})}),s}getNodeOutgoingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(o=>{this.getPortOutgoingEdgeIds(o).filter(n=>{const a=this.getEdge(n);return this.getPort(a.to).nodeId!==e}).forEach(n=>{s.push(n)})}),s}getNodeCycleEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(o=>{this.getPortCycleEdgeIds(o).forEach(n=>{s.push(n)}),this.getPortIncomingEdgeIds(o).filter(n=>{const a=this.getEdge(n);return this.getPort(a.to).nodeId===e}).forEach(n=>{s.push(n)})}),s}getNodeAdjacentEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(o=>{this.getPortIncomingEdgeIds(o).forEach(n=>{s.push(n)}),this.getPortOutgoingEdgeIds(o).forEach(n=>{s.push(n)}),this.getPortCycleEdgeIds(o).forEach(n=>{s.push(n)})}),s}addEdgeInternal(e){this.edges.set(e.id,{from:e.from,to:e.to,payload:{shape:e.shape,priority:e.priority}}),e.from!==e.to?(this.portOutcomingEdges.get(e.from).add(e.id),this.portIncomingEdges.get(e.to).add(e.id)):this.portCycleEdges.get(e.from).add(e.id)}removeEdgeInternal(e){const t=this.edges.get(e),s=t.from,o=t.to;this.portCycleEdges.get(s).delete(e),this.portCycleEdges.get(o).delete(e),this.portIncomingEdges.get(s).delete(e),this.portIncomingEdges.get(o).delete(e),this.portOutcomingEdges.get(s).delete(e),this.portOutcomingEdges.get(o).delete(e),this.edges.delete(e)}}const ge=r=>({scale:1/r.scale,x:-r.x/r.scale,y:-r.y/r.scale}),ue={scale:1,x:0,y:0};class tt{constructor(){i(this,"viewportMatrix",ue);i(this,"contentMatrix",ue);i(this,"afterUpdateEmitter");i(this,"onAfterUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=S()}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(e){this.viewportMatrix={scale:e.scale??this.viewportMatrix.scale,x:e.x??this.viewportMatrix.x,y:e.y??this.viewportMatrix.y},this.contentMatrix=ge(this.viewportMatrix),this.afterUpdateEmitter.emit()}patchContentMatrix(e){this.contentMatrix={scale:e.scale??this.contentMatrix.scale,x:e.x??this.contentMatrix.x,y:e.y??this.contentMatrix.y},this.viewportMatrix=ge(this.contentMatrix),this.afterUpdateEmitter.emit()}}class j{constructor(e){i(this,"elementToNodeId",new Map);i(this,"nodesResizeObserver");i(this,"onAfterNodeAdded",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.set(t.element,e),this.nodesResizeObserver.observe(t.element)});i(this,"onBeforeNodeRemoved",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.delete(t.element),this.nodesResizeObserver.unobserve(t.element)});i(this,"onBeforeClear",()=>{this.nodesResizeObserver.disconnect(),this.elementToNodeId.clear()});this.canvas=e,this.nodesResizeObserver=new ResizeObserver(t=>{t.forEach(s=>{const o=s.target;this.handleNodeResize(o)})}),this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear)}static configure(e){new j(e)}handleNodeResize(e){const t=this.elementToNodeId.get(e);this.canvas.updateNode(t)}}const rt=(r,e,t)=>{const{x:s,y:o,width:n,height:a}=r.getBoundingClientRect();return e>=s&&e<=s+n&&t>=o&&t<=o+a},st=(r,e,t)=>e>=0&&e<=r.innerWidth&&t>=0&&t<=r.innerHeight,F=(r,e,t,s)=>rt(e,t,s)&&st(r,t,s),B=(r,e)=>{e!==null?r.style.cursor=e:r.style.removeProperty("cursor")},O=r=>{const e=document.createElement("div");return{id:r.overlayId,element:e,x:r.portCoords.x,y:r.portCoords.y,ports:[{id:r.overlayId,element:e,direction:r.portDirection}]}},ot=(r,e)=>{let t=e;for(;t!==null;){const s=r.getElementPortIds(t)[0]??null;if(s!==null)return{status:"portFound",portId:s};if(r.getElementNodeId(t)!==null)return{status:"nodeEncountered"};t=t.parentElement}return{status:"notFound"}};function*pe(r,e){const t=r.elementsFromPoint(e.x,e.y);for(const s of t){if(s.shadowRoot!==null){const o=pe(s.shadowRoot,e);for(const n of o)yield n}yield s}}const we=(r,e)=>{const t=pe(document,e);for(const s of t){const o=ot(r,s);if(o.status==="portFound")return o.portId;if(o.status==="nodeEncountered")return null}return null};var N=(r=>(r.Static="static",r.Dragging="dragging",r.Edge="edge",r))(N||{});const fe=(r,e)=>({x:r/2,y:e/2}),p={x:0,y:0},m=(r,e,t)=>({x:e.x*r.x-e.y*r.y+((1-e.x)*t.x+e.y*t.y),y:e.y*r.x+e.x*r.y+((1-e.x)*t.y-e.y*t.x)}),ye=(r,e)=>{const t={x:r.x+r.width/2,y:r.y+r.height/2},s={x:e.x+e.width/2,y:e.y+e.height/2},o=Math.min(t.x,s.x),n=Math.min(t.y,s.y),a=Math.abs(s.x-t.x),h=Math.abs(s.y-t.y),d=t.x<=s.x?1:-1,c=t.y<=s.y?1:-1;return{x:o,y:n,width:a,height:h,flipX:d,flipY:c}},W=(r,e,t,s)=>({x:e*r.x+(1-e)/2*s.x,y:t*r.y+(1-t)/2*s.y});class it{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p),o=m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to),n={x:s.x+this.params.sourceDirection.x*this.params.curvature,y:s.y+this.params.sourceDirection.y*this.params.curvature},a={x:o.x-this.params.targetDirection.x*this.params.curvature,y:o.y-this.params.targetDirection.y*this.params.curvature},h=`M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${o.x} ${o.y}`,d=this.params.hasSourceArrow?"":`M ${p.x} ${p.y} L ${s.x} ${s.y} `,c=this.params.hasTargetArrow?"":` M ${o.x} ${o.y} L ${this.params.to.x} ${this.params.to.y}`;this.path=`${d}${h}${c}`}}class nt{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,o=this.params.arrowLength,n=Math.cos(this.params.detourDirection)*this.params.detourDistance,a=Math.sin(this.params.detourDirection)*this.params.detourDistance,h=n*this.params.flipX,d=a*this.params.flipY,c=m({x:o,y:p.y},this.params.sourceDirection,p),g={x:c.x+h,y:c.y+d},l=m({x:this.params.to.x-o,y:this.params.to.y},this.params.targetDirection,this.params.to),u={x:l.x+h,y:l.y+d},w={x:(g.x+u.x)/2,y:(g.y+u.y)/2},y={x:c.x+this.params.curvature*this.params.sourceDirection.x,y:c.y+this.params.curvature*this.params.sourceDirection.y},x={x:l.x-this.params.curvature*this.params.targetDirection.x,y:l.y-this.params.curvature*this.params.targetDirection.y},b={x:c.x+h,y:c.y+d},T={x:l.x+h,y:l.y+d};this.path=[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${y.x} ${y.y} ${b.x} ${b.y} ${w.x} ${w.y}`,`C ${T.x} ${T.y} ${x.x} ${x.y} ${l.x} ${l.y}`,`L ${s.x} ${s.y}`].join(" "),this.midpoint=W(w,e.flipX,e.flipY,e.to)}}const K=Object.freeze({edgeColor:"--edge-color"}),me=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.style.pointerEvents="none",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.overflow="visible",e.style.setProperty(K.edgeColor,r),e},ve=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke",`var(${K.edgeColor})`),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e},k=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("fill",`var(${K.edgeColor})`),r},Ee=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.transformOrigin="50% 50%",r},xe=(r,e)=>{r.style.transform=`translate(${e.x}px, ${e.y}px)`,r.style.width=`${Math.max(e.width,1)}px`,r.style.height=`${Math.max(e.height,1)}px`},L=(r,e)=>{const t=[];if(r.length>0&&t.push(`M ${r[0].x} ${r[0].y}`),r.length===2&&t.push(`L ${r[1].x} ${r[1].y}`),r.length>2){const s=r.length-1;let o=0,n=0,a=0;r.forEach((h,d)=>{let c=0,g=0,l=0;const u=d>0,w=d<s,y=u&&w;if(u&&(c=-o,g=-n,l=a),w){const $=r[d+1];o=$.x-h.x,n=$.y-h.y,a=Math.sqrt(o*o+n*n)}const b=a!==0?Math.min((y?e:0)/a,d<s-1?.5:1):0,T=y?{x:h.x+o*b,y:h.y+n*b}:h,D=l!==0?Math.min((y?e:0)/l,d>1?.5:1):0,R=y?{x:h.x+c*D,y:h.y+g*D}:h;d>0&&t.push(`L ${R.x} ${R.y}`),y&&t.push(`C ${h.x} ${h.y} ${h.x} ${h.y} ${T.x} ${T.y}`)})}return t.join(" ")};class at{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,o=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=m({x:a,y:p.y},this.params.sourceDirection,p),d=m({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.x+d.x)/2,n),g=this.params.to.y/2,l={x:this.params.flipX>0?c:-n,y:h.y},u={x:l.x,y:g},w={x:this.params.flipX>0?this.params.to.x-c:this.params.to.x+n,y:d.y},y={x:w.x,y:g};this.path=L([s,h,l,u,y,w,d,o],this.params.roundness)}}class ht{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,o=this.params.arrowLength+this.params.arrowOffset,n=m({x:o,y:p.y},this.params.sourceDirection,p),a=Math.cos(this.params.detourDirection)*this.params.detourDistance,h=Math.sin(this.params.detourDirection)*this.params.detourDistance,d=a*this.params.flipX,c=h*this.params.flipY,g={x:n.x+d,y:n.y+c},l=m({x:this.params.to.x-o,y:this.params.to.y},this.params.targetDirection,this.params.to),u={x:l.x+d,y:l.y+c},w={x:(g.x+u.x)/2,y:(g.y+u.y)/2};this.midpoint=W(w,e.flipX,e.flipY,e.to),this.path=L([t,n,g,u,l,s],this.params.roundness)}}class dt{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,o=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=m({x:n,y:p.y},this.params.sourceDirection,p),h=m({x:this.params.to.x-n,y:this.params.to.y},this.params.targetDirection,this.params.to);this.path=L([s,a,h,o],this.params.roundness)}}class ct{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,o=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=m({x:a,y:p.y},this.params.sourceDirection,p),d=m({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.y+d.y)/2,n),g=this.params.to.x/2,l={x:h.x,y:this.params.flipY>0?c:-n},u={x:g,y:l.y},w={x:d.x,y:this.params.flipY>0?this.params.to.y-c:this.params.to.y+n},y={x:g,y:w.y};this.path=L([s,h,l,u,y,w,d,o],this.params.roundness)}}class Q{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.arrowOffset,s=this.params.side,o=this.params.arrowLength+t,n=o+2*s,h=[{x:this.params.arrowLength,y:p.y},{x:o,y:p.y},{x:o,y:this.params.side},{x:n,y:this.params.side},{x:n,y:-this.params.side},{x:o,y:-this.params.side},{x:o,y:p.y},{x:this.params.arrowLength,y:p.y}].map(c=>m(c,this.params.sourceDirection,p)),d=`M ${p.x} ${p.y} L ${h[0].x} ${h[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":d}${L(h,this.params.roundness)}`,this.midpoint={x:(h[3].x+h[4].x)/2,y:(h[3].y+h[4].y)/2}}}class lt{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.smallRadius,s=this.params.radius,o=t+s,n=t*s/o,a=Math.sqrt(o*o-t*t),h=a*t/o,d=a+s+this.params.arrowLength,c=this.params.arrowLength+h,l=[{x:this.params.arrowLength,y:p.y},{x:c,y:n},{x:c,y:-n},{x:d,y:0}].map(y=>m(y,this.params.sourceDirection,p)),u=[`M ${l[0].x} ${l[0].y}`,`A ${t} ${t} 0 0 1 ${l[1].x} ${l[1].y}`,`A ${s} ${s} 0 1 0 ${l[2].x} ${l[2].y}`,`A ${t} ${t} 0 0 1 ${l[0].x} ${l[0].y}`].join(" "),w=`M 0 0 L ${l[0].x} ${l[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":w}${u}`,this.midpoint=l[3]}}class gt{constructor(e){i(this,"path");i(this,"midpoint");i(this,"diagonalDistance");this.params=e;const t=this.params.to;if(this.midpoint={x:t.x/2,y:t.y/2},this.diagonalDistance=Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y),Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y)===0){this.path="";return}const o=this.createDirectLinePoint({offset:this.params.sourceOffset,hasArrow:this.params.hasSourceArrow,flip:1,shift:p}),n=this.createDirectLinePoint({offset:this.params.targetOffset,hasArrow:this.params.hasTargetArrow,flip:-1,shift:this.params.to});this.path=`M ${o.x} ${o.y} L ${n.x} ${n.y}`}createDirectLinePoint(e){const t=e.hasArrow?this.params.arrowLength:0,s=e.offset+t,o=e.flip*s/this.diagonalDistance;return{x:this.params.to.x*o+e.shift.x,y:this.params.to.y*o+e.shift.y}}}class ut{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,o=this.params.arrowLength+this.params.arrowOffset,n=m({x:o,y:p.y},this.params.sourceDirection,p),a=m({x:this.params.to.x-o,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.y/2,c=d+Math.abs(this.params.detourDistance),g=d+c*this.params.flipY*h,l={x:(n.x+a.x)/2,y:g};this.midpoint=W(l,e.flipX,e.flipY,e.to),this.path=L([t,n,{x:n.x,y:g},{x:a.x,y:g},a,s],this.params.roundness)}}class pt{constructor(e){i(this,"path");i(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?m({x:this.params.arrowLength,y:p.y},this.params.sourceDirection,p):p,s=this.params.hasTargetArrow?m({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,o=this.params.arrowLength+this.params.arrowOffset,n=m({x:o,y:p.y},this.params.sourceDirection,p),a=m({x:this.params.to.x-o,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.x/2,c=d+Math.abs(this.params.detourDistance),g=d+c*this.params.flipX*h,l={x:g,y:(n.y+a.y)/2};this.midpoint=W(l,e.flipX,e.flipY,e.to),this.path=L([t,n,{x:g,y:n.y},{x:g,y:a.y},a,s],this.params.roundness)}}const f=Object.freeze({color:"#777777",width:1,arrowLength:20,polygonArrowRadius:4,circleArrowRadius:8,wedgeArrowSmallRadius:20,wedgeArrowRadius:100,wedgeArrowAngle:Math.PI/12,arrowOffset:15,hasSourceArrow:!1,hasTargetArrow:!1,cycleRadius:30,cycleSquareSide:30,roundness:10,detourDistance:100,detourDirection:-Math.PI/2,detourDirectionVertical:0,smallCycleRadius:15,curvature:90,interactiveWidth:10,preOffset:0}),Ae=(r,e,t)=>({x:e*Math.cos(r),y:t*Math.sin(r)});class z{constructor(e){i(this,"svg");i(this,"group",Ee());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"onAfterRender");i(this,"afterRenderEmitter");i(this,"arrowRenderer");this.params=e,[this.afterRenderEmitter,this.onAfterRender]=S(),this.arrowRenderer=this.params.arrowRenderer,this.svg=me(e.color),this.svg.appendChild(this.group),this.line=ve(e.width),this.group.appendChild(this.line),e.hasSourceArrow&&(this.sourceArrow=k(),this.group.appendChild(this.sourceArrow)),e.hasTargetArrow&&(this.targetArrow=k(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:o,height:n,flipX:a,flipY:h}=ye(e.from,e.to);xe(this.svg,{x:t,y:s,width:o,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d=Ae(e.from.direction,a,h),c=Ae(e.to.direction,a,h),g={x:o,y:n};let l={x:-c.x,y:-c.y},u;e.category===C.PortCycle?(u=this.params.createCyclePath,l=d):e.category===C.NodeCycle?u=this.params.createDetourPath:u=this.params.createLinePath;const w=u(d,c,g,a,h);this.line.setAttribute("d",w.path);let y=null;this.sourceArrow&&(y=this.arrowRenderer({direction:d,shift:p,arrowLength:this.params.arrowLength}),this.sourceArrow.setAttribute("d",y));let x=null;this.targetArrow&&(x=this.arrowRenderer({direction:l,shift:g,arrowLength:this.params.arrowLength}),this.targetArrow.setAttribute("d",x)),this.afterRenderEmitter.emit({edgePath:w,sourceArrowPath:y,targetArrowPath:x})}}const wt=r=>e=>{const s=[p,{x:e.arrowLength,y:r.radius},{x:e.arrowLength,y:-r.radius}].map(h=>m(h,e.direction,p)).map(h=>({x:h.x+e.shift.x,y:h.y+e.shift.y})),o=`M ${s[0].x} ${s[0].y}`,n=`L ${s[1].x} ${s[1].y}`,a=`L ${s[2].x} ${s[2].y}`;return`${o} ${n} ${a} Z`},ft=r=>e=>{const t=r.radius,s=e.arrowLength,o=(s*s+2*s*t)/(2*t),n=o+t,a=s+t-t*(s+t)/n,h=t*o/n,c=[p,{x:a,y:-h},{x:a,y:h}].map(y=>m(y,e.direction,p)).map(y=>({x:y.x+e.shift.x,y:y.y+e.shift.y})),g=`M ${c[0].x} ${c[0].y}`,l=`A ${o} ${o} 0 0 0 ${c[1].x} ${c[1].y}`,u=`A ${t} ${t} 0 0 0 ${c[2].x} ${c[2].y}`,w=`A ${o} ${o} 0 0 0 ${c[0].x} ${c[0].y}`;return`${g} ${l} ${u} ${w}`},yt=r=>e=>{const t=r.smallRadius,s=r.radius,o=m({x:e.arrowLength,y:0},{x:Math.cos(r.angle),y:Math.sin(r.angle)},{x:e.arrowLength+r.smallRadius,y:0}),a=[p,{x:o.x,y:-o.y},o].map(l=>m(l,e.direction,p)).map(l=>({x:l.x+e.shift.x,y:l.y+e.shift.y})),h=`M ${a[0].x} ${a[0].y}`,d=`A ${s} ${s} 0 0 1 ${a[1].x} ${a[1].y}`,c=`A ${t} ${t} 0 0 1 ${a[2].x} ${a[2].y}`,g=`A ${s} ${s} 0 0 1 ${a[0].x} ${a[0].y}`;return`${h} ${d} ${c} ${g}`},I=r=>{if(typeof r=="function")return r;switch(r.type){case"triangle":return wt({radius:r.radius??f.polygonArrowRadius});case"arc":return ft({radius:r.radius??f.circleArrowRadius});default:return yt({smallRadius:r.smallRadius??f.wedgeArrowSmallRadius,angle:r.angle??f.wedgeArrowAngle,radius:r.radius??f.wedgeArrowRadius})}};class Se{constructor(e){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"arrowLength");i(this,"curvature");i(this,"portCycleRadius");i(this,"portCycleSmallRadius");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");i(this,"pathShape");i(this,"createCyclePath",e=>new lt({sourceDirection:e,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createDetourPath",(e,t,s,o,n)=>new nt({to:s,sourceDirection:e,targetDirection:t,flipX:o,flipY:n,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createLinePath",(e,t,s)=>new it({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.curvature=(e==null?void 0:e.curvature)??f.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??f.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??f.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??f.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class be{constructor(e){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"arrowLength");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");i(this,"pathShape");i(this,"createCyclePath",e=>new Q({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createDetourPath",(e,t,s,o,n)=>new ut({to:s,sourceDirection:e,targetDirection:t,flipX:o,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createLinePath",(e,t,s,o)=>new at({to:s,sourceDirection:e,targetDirection:t,flipX:o,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Pe{constructor(e){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"arrowLength");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");i(this,"pathShape");i(this,"createCyclePath",e=>new Q({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createDetourPath",(e,t,s,o,n)=>new ht({to:s,sourceDirection:e,targetDirection:t,flipX:o,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createLinePath",(e,t,s)=>new dt({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??f.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Te{constructor(e){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"arrowLength");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");i(this,"pathShape");i(this,"createCyclePath",e=>new Q({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createDetourPath",(e,t,s,o,n)=>new pt({to:s,sourceDirection:e,targetDirection:t,flipX:o,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));i(this,"createLinePath",(e,t,s,o,n)=>new ct({to:s,sourceDirection:e,targetDirection:t,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Z{constructor(e){i(this,"svg");i(this,"group",Ee());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"color");i(this,"width");i(this,"arrowLength");i(this,"sourceOffset");i(this,"targetOffset");i(this,"onAfterRender");i(this,"afterRenderEmitter");i(this,"arrowRenderer");[this.afterRenderEmitter,this.onAfterRender]=S(),this.color=(e==null?void 0:e.color)??f.color,this.width=(e==null?void 0:e.width)??f.width,this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowRenderer=I((e==null?void 0:e.arrowRenderer)??{}),this.sourceOffset=(e==null?void 0:e.sourceOffset)??f.preOffset,this.targetOffset=(e==null?void 0:e.targetOffset)??f.preOffset,this.svg=me(this.color),this.svg.appendChild(this.group),this.line=ve(this.width),this.group.appendChild(this.line),e!=null&&e.hasSourceArrow&&(this.sourceArrow=k(),this.group.appendChild(this.sourceArrow)),e!=null&&e.hasTargetArrow&&(this.targetArrow=k(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:o,height:n,flipX:a,flipY:h}=ye(e.from,e.to);xe(this.svg,{x:t,y:s,width:o,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d={x:o,y:n},c=new gt({to:d,sourceOffset:this.sourceOffset,targetOffset:this.targetOffset,hasSourceArrow:this.sourceArrow!==null,hasTargetArrow:this.targetArrow!==null,arrowLength:this.arrowLength});this.line.setAttribute("d",c.path);let g=null,l=null;const u=c.diagonalDistance;if(u===0)this.sourceArrow!==null&&(g="",this.sourceArrow.setAttribute("d",g)),this.targetArrow!==null&&(l="",this.targetArrow.setAttribute("d",l));else{const w={x:d.x/u,y:d.y/u};if(this.sourceArrow){const y={x:w.x*this.sourceOffset,y:w.y*this.sourceOffset};g=this.arrowRenderer({direction:w,shift:y,arrowLength:this.arrowLength}),this.sourceArrow.setAttribute("d",g)}if(this.targetArrow){const y={x:w.x*this.targetOffset,y:w.y*this.targetOffset};l=this.arrowRenderer({direction:{x:-w.x,y:-w.y},shift:{x:d.x-y.x,y:d.y-y.y},arrowLength:this.arrowLength}),this.targetArrow.setAttribute("d",l)}}this.afterRenderEmitter.emit({edgePath:c,sourceArrowPath:g,targetArrowPath:l})}}const mt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.pointerEvents="auto",r.style.cursor="pointer",r},vt=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke","transparent"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e.setAttribute("stroke-linecap","round"),e},Ce=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke-linejoin","round"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","transparent"),e.setAttribute("stroke","transparent"),e};class De extends Error{constructor(e){super(e),this.name="InteractiveEdgeError"}}class q{constructor(e,t){i(this,"svg");i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"handle",mt());i(this,"onAfterRender");i(this,"interactiveLine");i(this,"interactiveSourceArrow",null);i(this,"interactiveTargetArrow",null);if(this.baseEdge=e,e instanceof q)throw new De("interactive edge can be configured only once");this.svg=this.baseEdge.svg,this.group=this.baseEdge.group,this.line=this.baseEdge.line,this.sourceArrow=this.baseEdge.sourceArrow,this.targetArrow=this.baseEdge.targetArrow,this.onAfterRender=this.baseEdge.onAfterRender;const s=(t==null?void 0:t.distance)??f.interactiveWidth;this.interactiveLine=vt(s),this.handle.appendChild(this.interactiveLine),this.sourceArrow&&(this.interactiveSourceArrow=Ce(s),this.handle.appendChild(this.interactiveSourceArrow)),this.targetArrow&&(this.interactiveTargetArrow=Ce(s),this.handle.appendChild(this.interactiveTargetArrow)),this.group.appendChild(this.handle),this.baseEdge.onAfterRender.subscribe(o=>{this.interactiveLine.setAttribute("d",o.edgePath.path),this.interactiveSourceArrow&&this.interactiveSourceArrow.setAttribute("d",o.sourceArrowPath),this.interactiveTargetArrow&&this.interactiveTargetArrow.setAttribute("d",o.targetArrowPath)})}render(e){this.baseEdge.render(e)}}class Et{constructor(e,t){i(this,"group");i(this,"line");i(this,"sourceArrow");i(this,"targetArrow");i(this,"onAfterRender");i(this,"svg");this.baseShape=e,this.midpointElement=t,this.svg=this.baseShape.svg,this.group=this.baseShape.group,this.line=this.baseShape.line,this.sourceArrow=this.baseShape.sourceArrow,this.targetArrow=this.baseShape.targetArrow,this.onAfterRender=this.baseShape.onAfterRender,this.svg.append(this.midpointElement),this.baseShape.onAfterRender.subscribe(s=>{const o=s.edgePath.midpoint,n=`translate(${o.x}px, ${o.y}px)`;this.midpointElement.style.setProperty("transform",n)})}render(e){this.baseShape.render(e)}}class Ne{constructor(e){i(this,"onAfterNodeAdded");i(this,"onAfterNodeUpdated");i(this,"onAfterNodePriorityUpdated");i(this,"onBeforeNodeRemoved");i(this,"onAfterPortMarked");i(this,"onAfterPortUpdated");i(this,"onBeforePortUnmarked");i(this,"onAfterEdgeAdded");i(this,"onAfterEdgeShapeUpdated");i(this,"onAfterEdgeUpdated");i(this,"onAfterEdgePriorityUpdated");i(this,"onBeforeEdgeRemoved");i(this,"onBeforeClear");this.graphStore=e,this.onAfterNodeAdded=this.graphStore.onAfterNodeAdded,this.onAfterNodeUpdated=this.graphStore.onAfterNodeUpdated,this.onAfterNodePriorityUpdated=this.graphStore.onAfterNodePriorityUpdated,this.onBeforeNodeRemoved=this.graphStore.onBeforeNodeRemoved,this.onAfterPortMarked=this.graphStore.onAfterPortAdded,this.onAfterPortUpdated=this.graphStore.onAfterPortUpdated,this.onBeforePortUnmarked=this.graphStore.onBeforePortRemoved,this.onAfterEdgeAdded=this.graphStore.onAfterEdgeAdded,this.onAfterEdgeShapeUpdated=this.graphStore.onAfterEdgeShapeUpdated,this.onAfterEdgeUpdated=this.graphStore.onAfterEdgeUpdated,this.onAfterEdgePriorityUpdated=this.graphStore.onAfterEdgePriorityUpdated,this.onBeforeEdgeRemoved=this.graphStore.onBeforeEdgeRemoved,this.onBeforeClear=this.graphStore.onBeforeClear}getNode(e){const t=this.graphStore.getNode(e);if(t===void 0)return null;const s=t.payload;return{element:t.element,x:s.x,y:s.y,centerFn:s.centerFn,priority:s.priority}}getElementNodeId(e){return this.graphStore.getElementNodeId(e)??null}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(e){const t=this.graphStore.getPort(e);return t===void 0?null:{element:t.element,direction:t.payload.direction,nodeId:t.nodeId}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(e){return this.graphStore.getNodePortIds(e)??null}getElementPortIds(e){return[...this.graphStore.getElementPortIds(e)]}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(e){const t=this.graphStore.getEdge(e);if(t===void 0)return null;const s=t.payload;return{from:t.from,to:t.to,priority:s.priority,shape:s.shape}}getPortIncomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortIncomingEdgeIds(e)}getPortOutgoingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortOutgoingEdgeIds(e)}getPortCycleEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortCycleEdgeIds(e)}getPortAdjacentEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortAdjacentEdgeIds(e)}getNodeIncomingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeIncomingEdgeIds(e)}getNodeOutgoingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeOutgoingEdgeIds(e)}getNodeCycleEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeCycleEdgeIds(e)}getNodeAdjacentEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeAdjacentEdgeIds(e)}}class Me{constructor(e){i(this,"onAfterUpdated");this.viewportStore=e,this.onAfterUpdated=this.viewportStore.onAfterUpdated}getViewportMatrix(){return{...this.viewportStore.getViewportMatrix()}}getContentMatrix(){return{...this.viewportStore.getContentMatrix()}}}const Le=(r,e)=>{const t=new le,s=new Ne(t),o=new Me(e),n=new de(t,e,r),a={nodes:{centerFn:fe,priorityFn:()=>0},edges:{shapeFactory:()=>new Z,priorityFn:()=>0},ports:{direction:0}};return new ce(s,o,t,e,n,a)};class H{constructor(e,t,s,o){i(this,"onAfterPortMarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.hookPortEvents(t.element)});i(this,"onBeforePortUnmarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.unhookPortEvents(t.element)});i(this,"onPortMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.canvas.graph.getElementPortIds(t)[0];this.params.onPortPointerDown(s,{x:e.clientX,y:e.clientY})&&(e.stopPropagation(),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}))});i(this,"onWindowMouseMove",e=>{if(!F(this.window,this.element,e.clientX,e.clientY)){this.stopMouseDrag();return}this.params.onPointerMove({x:e.clientX,y:e.clientY})});i(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&(this.params.onPointerUp({x:e.clientX,y:e.clientY}),this.stopMouseDrag())});i(this,"onPortTouchStart",e=>{if(e.touches.length!==1)return;const t=e.touches[0],s=e.currentTarget,o=this.canvas.graph.getElementPortIds(s)[0];this.params.onPortPointerDown(o,{x:t.clientX,y:t.clientY})&&(e.stopPropagation(),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}))});i(this,"onWindowTouchMove",e=>{const t=e.touches[0];if(!F(this.window,this.element,t.clientX,t.clientY)){this.stopTouchDrag();return}this.params.onPointerMove({x:t.clientX,y:t.clientY})});i(this,"onWindowTouchFinish",e=>{const t=e.changedTouches[0];this.params.onPointerUp({x:t.clientX,y:t.clientY}),this.stopTouchDrag()});i(this,"onBeforeClear",()=>{this.canvas.graph.getAllPortIds().forEach(e=>{const t=this.canvas.graph.getPort(e);this.unhookPortEvents(t.element)})});i(this,"onBeforeDestroy",()=>{this.params.onStopDrag(),this.removeWindowMouseListeners(),this.removeWindowTouchListeners()});this.canvas=e,this.element=t,this.window=s,this.params=o,this.canvas.graph.onAfterPortMarked.subscribe(this.onAfterPortMarked),this.canvas.graph.onBeforePortUnmarked.subscribe(this.onBeforePortUnmarked),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,o){new H(e,t,s,o)}hookPortEvents(e){e.addEventListener("mousedown",this.onPortMouseDown,{passive:!0}),e.addEventListener("touchstart",this.onPortTouchStart,{passive:!0})}unhookPortEvents(e){e.removeEventListener("mousedown",this.onPortMouseDown),e.removeEventListener("touchstart",this.onPortTouchStart)}stopMouseDrag(){this.params.onStopDrag(),this.removeWindowMouseListeners()}stopTouchDrag(){this.params.onStopDrag(),this.removeWindowTouchListeners()}removeWindowMouseListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}removeWindowTouchListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class J{constructor(e,t,s,o){i(this,"grabbedNode",null);i(this,"maxNodePriority",0);i(this,"graph");i(this,"onAfterNodeAdded",e=>{this.updateMaxNodePriority(e);const t=this.graph.getNode(e);t.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),t.element.addEventListener("touchstart",this.onTouchStart,{passive:!0})});i(this,"onAfterNodeUpdated",e=>{this.updateMaxNodePriority(e)});i(this,"onBeforeNodeRemoved",e=>{const t=this.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)});i(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});i(this,"onBeforeClear",()=>{this.canvas.graph.getAllNodeIds().forEach(e=>{const t=this.canvas.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)}),this.maxNodePriority=0});i(this,"onMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.graph.getElementNodeId(t),o=this.graph.getNode(s);if(!this.params.nodeDragVerifier(s))return;this.params.onNodeDragStarted(s),e.stopPropagation();const a=this.calculateContentPoint({x:e.clientX,y:e.clientY});this.grabbedNode={nodeId:s,dx:a.x-o.x,dy:a.y-o.y},B(this.element,this.params.dragCursor),this.moveNodeOnTop(s),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0})});i(this,"onTouchStart",e=>{if(e.touches.length!==1)return;e.stopPropagation();const t=e.touches[0],s=e.currentTarget,o=this.canvas.graph.getElementNodeId(s),n=this.graph.getNode(o);if(!this.params.nodeDragVerifier({nodeId:o,element:n.element,x:n.x,y:n.y}))return;const h=this.calculateContentPoint({x:t.clientX,y:t.clientY});this.grabbedNode={nodeId:o,dx:h.x-n.x,dy:h.y-n.y},this.moveNodeOnTop(o),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0})});i(this,"onWindowMouseMove",e=>{if(!F(this.window,this.element,e.clientX,e.clientY)){this.cancelMouseDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:e.clientX,y:e.clientY})});i(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&this.cancelMouseDrag()});i(this,"onWindowTouchMove",e=>{if(e.touches.length!==1)return;const t=e.touches[0];if(!F(this.window,this.element,t.clientX,t.clientY)){this.cancelTouchDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:t.clientX,y:t.clientY})});i(this,"onWindowTouchFinish",()=>{this.cancelTouchDrag()});this.canvas=e,this.element=t,this.window=s,this.params=o,this.graph=e.graph,this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,o){new J(e,t,s,o)}moveNode(e,t){if(this.graph.getNode(e.nodeId)===null)return;const o=this.calculateContentPoint(t),n={x:o.x-e.dx,y:o.y-e.dy},a=this.adjustNodeCoords(n);this.canvas.updateNode(e.nodeId,{x:a.x,y:a.y}),this.params.onNodeDrag(e.nodeId)}moveNodeOnTop(e){if(this.params.moveOnTop){if(this.maxNodePriority++,this.params.moveEdgesOnTop){const t=this.maxNodePriority;this.maxNodePriority++,this.graph.getNodeAdjacentEdgeIds(e).forEach(o=>{this.canvas.updateEdge(o,{priority:t})})}this.canvas.updateNode(e,{priority:this.maxNodePriority})}}cancelMouseDrag(){this.grabbedNode!==null&&this.graph.getNode(this.grabbedNode.nodeId)!==null&&this.params.onNodeDragFinished(this.grabbedNode.nodeId),this.grabbedNode=null,B(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){if(this.grabbedNode!==null){const e=this.graph.getNode(this.grabbedNode.nodeId);e!==null&&this.params.onNodeDragFinished({nodeId:this.grabbedNode.nodeId,element:e.element,x:e.x,y:e.y})}this.grabbedNode=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}updateMaxNodePriority(e){const t=this.graph.getNode(e).priority;this.maxNodePriority=Math.max(this.maxNodePriority,t)}calculateContentPoint(e){const t=this.element.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},o=this.canvas.viewport.getViewportMatrix();return A(o,s)}adjustNodeCoords(e){const t=this.params.gridSize;if(t!==null){const s=t/2;return{x:Math.floor((e.x+s)/t)*t,y:Math.floor((e.y+s)/t)*t}}return e}}const xt=(r,e,t)=>({scale:r.scale,x:r.x+r.scale*e,y:r.y+r.scale*t}),At=(r,e,t,s)=>({scale:r.scale*e,x:r.scale*(1-e)*t+r.x,y:r.scale*(1-e)*s+r.y}),X=r=>{const e=[],t=r.touches.length;for(let h=0;h<t;h++)e.push([r.touches[h].clientX,r.touches[h].clientY]);const s=e.reduce((h,d)=>[h[0]+d[0],h[1]+d[1]],[0,0]),o=[s[0]/t,s[1]/t],a=e.map(h=>[h[0]-o[0],h[1]-o[1]]).reduce((h,d)=>h+Math.sqrt(d[0]*d[0]+d[1]*d[1]),0);return{x:o[0],y:o[1],scale:a/t,touchesCnt:t,touches:e}};class Y{constructor(e,t,s,o){i(this,"viewport");i(this,"prevTouches",null);i(this,"wheelFinishTimer",null);i(this,"transformInProgress",!1);i(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});i(this,"onMouseDown",e=>{this.element===null||!this.params.mouseDownEventVerifier(e)||(B(this.element,this.params.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}),this.startRegisteredTransform())});i(this,"onWindowMouseMove",e=>{const t=F(this.window,this.element,e.clientX,e.clientY);if(this.element===null||!t){this.stopMouseDrag();return}const s=-e.movementX,o=-e.movementY;this.moveViewport(s,o)});i(this,"onWindowMouseUp",e=>{this.element===null||!this.params.mouseUpEventVerifier(e)||this.stopMouseDrag()});i(this,"onWheelScroll",e=>{if(!this.params.mouseWheelEventVerifier(e))return;const{left:t,top:s}=this.element.getBoundingClientRect(),o=e.clientX-t,n=e.clientY-s,h=1/(e.deltaY<0?this.params.wheelSensitivity:1/this.params.wheelSensitivity);this.wheelFinishTimer===null&&this.params.onTransformStarted(),this.scaleViewport(h,o,n),this.wheelFinishTimer!==null&&clearTimeout(this.wheelFinishTimer),this.wheelFinishTimer=setTimeout(()=>{this.transformInProgress||this.params.onTransformFinished(),this.wheelFinishTimer=null},this.params.scaleWheelFinishTimeout)});i(this,"onTouchStart",e=>{if(this.prevTouches!==null){this.prevTouches=X(e);return}this.prevTouches=X(e),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}),this.startRegisteredTransform()});i(this,"onWindowTouchMove",e=>{const t=X(e);if(!t.touches.every(o=>F(this.window,this.element,o[0],o[1]))){this.stopTouchDrag();return}if((t.touchesCnt===1||t.touchesCnt===2)&&this.moveViewport(-(t.x-this.prevTouches.x),-(t.y-this.prevTouches.y)),t.touchesCnt===2){const{left:o,top:n}=this.element.getBoundingClientRect(),a=this.prevTouches.x-o,h=this.prevTouches.y-n,c=1/(t.scale/this.prevTouches.scale);this.scaleViewport(c,a,h)}this.prevTouches=t});i(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=X(e):this.stopTouchDrag()});i(this,"observer",new ResizeObserver(()=>{const e=this.viewport.getViewportMatrix(),{width:t,height:s}=this.element.getBoundingClientRect(),o=this.params.transformPreprocessor({prevTransform:e,nextTransform:e,canvasWidth:t,canvasHeight:s});this.params.onResizeTransformStarted(),this.canvas.patchViewportMatrix(o),this.params.onResizeTransformFinished()}));i(this,"preventWheelScaleListener",e=>{e.preventDefault()});this.canvas=e,this.element=t,this.window=s,this.params=o,this.element.addEventListener("wheel",this.preventWheelScaleListener,{passive:!1}),this.viewport=e.viewport,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),this.element.addEventListener("wheel",this.onWheelScroll,{passive:!0}),this.element.addEventListener("touchstart",this.onTouchStart,{passive:!0}),e.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,o){new Y(e,t,s,o)}moveViewport(e,t){const s=this.viewport.getViewportMatrix(),o=xt(s,e,t),{width:n,height:a}=this.element.getBoundingClientRect(),h=this.params.transformPreprocessor({prevTransform:s,nextTransform:o,canvasWidth:n,canvasHeight:a});this.performTransform(h)}scaleViewport(e,t,s){const o=this.canvas.viewport.getViewportMatrix(),n=At(o,e,t,s),{width:a,height:h}=this.element.getBoundingClientRect(),d=this.params.transformPreprocessor({prevTransform:o,nextTransform:n,canvasWidth:a,canvasHeight:h});this.performTransform(d)}stopMouseDrag(){B(this.element,null),this.removeMouseDragListeners(),this.finishRegisteredTransform()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.finishRegisteredTransform()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}performTransform(e){this.params.onBeforeTransformChange(),this.canvas.patchViewportMatrix(e),this.params.onTransformChange()}startRegisteredTransform(){this.transformInProgress=!0,this.params.onTransformStarted()}finishRegisteredTransform(){this.transformInProgress=!1,this.params.onTransformFinished()}}class _{constructor(e,t,s,o,n,a){i(this,"canvasResizeObserver");i(this,"nodeHorizontal");i(this,"nodeVertical");i(this,"viewport");i(this,"viewportWidth",0);i(this,"viewportHeight",0);i(this,"viewportMatrix");i(this,"loadedArea",{xFrom:1/0,xTo:1/0,yFrom:1/0,yTo:1/0});i(this,"updateLoadedArea",e=>{this.loadedArea={xFrom:e.x,xTo:e.x+e.width,yFrom:e.y,yTo:e.y+e.height}});i(this,"onAfterViewportUpdated",()=>{this.userTransformInProgress||(this.viewportMatrix=this.viewport.getViewportMatrix(),this.loadAreaAroundViewport())});i(this,"userTransformInProgress",!1);this.canvas=e,this.element=t,this.window=s,this.trigger=n,this.params=a,this.nodeHorizontal=this.params.nodeVerticalRadius,this.nodeVertical=this.params.nodeHorizontalRadius,this.canvasResizeObserver=new ResizeObserver(d=>{const c=d[0];this.viewportWidth=c.contentRect.width,this.viewportHeight=c.contentRect.height,this.scheduleLoadAreaAroundViewport()}),this.viewport=e.viewport;const h={...o,onResizeTransformStarted:()=>{this.userTransformInProgress=!0,o.onResizeTransformStarted()},onResizeTransformFinished:()=>{this.userTransformInProgress=!1,o.onResizeTransformFinished()},onBeforeTransformChange:()=>{this.userTransformInProgress=!0,o.onBeforeTransformChange()},onTransformChange:()=>{this.userTransformInProgress=!1;const d=this.viewportMatrix;this.viewportMatrix=this.viewport.getViewportMatrix(),d.scale!==this.viewportMatrix.scale&&this.scheduleEnsureViewportAreaLoaded(),o.onTransformChange()},onTransformFinished:()=>{this.scheduleLoadAreaAroundViewport(),o.onTransformFinished()}};Y.configure(e,this.element,this.window,h),this.viewportMatrix=this.viewport.getViewportMatrix(),this.trigger.subscribe(this.updateLoadedArea),this.canvasResizeObserver.observe(this.element),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated)}static configure(e,t,s,o,n,a){new _(e,t,s,o,n,a)}scheduleLoadAreaAroundViewport(){setTimeout(()=>{this.loadAreaAroundViewport()})}scheduleEnsureViewportAreaLoaded(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-this.nodeHorizontal,o=this.viewportMatrix.y-this.nodeVertical,n=this.viewportMatrix.x+e+this.nodeHorizontal,a=this.viewportMatrix.y+t+this.nodeVertical;this.loadedArea.xFrom<s&&this.loadedArea.xTo>n&&this.loadedArea.yFrom<o&&this.loadedArea.yTo>a||this.scheduleLoadAreaAroundViewport()}loadAreaAroundViewport(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-e-this.nodeHorizontal,o=this.viewportMatrix.y-t-this.nodeVertical,n=3*e+2*this.nodeHorizontal,a=3*t+2*this.nodeVertical;this.trigger.emit({x:s,y:o,width:n,height:a})}}const St=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.style.position="absolute",r.style.inset="0",r},bt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","rect");return r.setAttribute("fill","url(#pattern)"),r},Pt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","pattern");return r.setAttribute("id","pattern"),r};class ee{constructor(e,t,s){i(this,"svg",St());i(this,"patternRenderingRectangle",bt());i(this,"pattern",Pt());i(this,"patternContent");i(this,"tileWidth");i(this,"tileHeight");i(this,"halfTileWidth");i(this,"halfTileHeight");i(this,"maxViewportScale");i(this,"visible",!1);i(this,"resizeObserver",new ResizeObserver(e=>{const t=e[0],{width:s,height:o}=t.contentRect;this.svg.setAttribute("width",`${s}`),this.svg.setAttribute("height",`${o}`),this.patternRenderingRectangle.setAttribute("width",`${s}`),this.patternRenderingRectangle.setAttribute("height",`${o}`);const n=this.tileWidth/s,a=this.tileHeight/o;this.pattern.setAttribute("width",`${n}`),this.pattern.setAttribute("height",`${a}`)}));i(this,"onAfterTransformUpdated",()=>{const e=this.canvas.viewport.getContentMatrix(),t=e.x-this.halfTileWidth*e.scale,s=e.y-this.halfTileHeight*e.scale,o=`matrix(${e.scale}, 0, 0, ${e.scale}, ${t}, ${s})`;this.pattern.setAttribute("patternTransform",o),this.updateVisibility()});this.canvas=e,this.backgroundHost=s,this.tileWidth=t.tileWidth,this.tileHeight=t.tileHeight,this.halfTileWidth=this.tileWidth/2,this.halfTileHeight=this.tileHeight/2,this.patternContent=t.renderer,this.maxViewportScale=t.maxViewportScale;const o=`translate(${this.halfTileWidth}, ${this.halfTileHeight})`;this.patternContent.setAttribute("transform",o),this.pattern.appendChild(this.patternContent);const n=document.createElementNS("http://www.w3.org/2000/svg","defs");n.appendChild(this.pattern),this.svg.appendChild(n),this.svg.appendChild(this.patternRenderingRectangle),this.resizeObserver.observe(this.backgroundHost),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated),this.onAfterTransformUpdated()}static configure(e,t,s){new ee(e,t,s)}updateVisibility(){const t=this.canvas.viewport.getViewportMatrix().scale>this.maxViewportScale;t&&this.visible?(this.visible=!1,this.backgroundHost.removeChild(this.svg)):!t&&!this.visible&&(this.visible=!0,this.backgroundHost.appendChild(this.svg))}}class te{constructor(e,t,s,o,n){i(this,"overlayCanvas");i(this,"staticPortId",null);i(this,"isTargetDragging",!0);i(this,"onEdgeCreated",e=>{this.params.onAfterEdgeCreated(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=o,this.params=n,this.overlayCanvas=Le(this.overlayLayer,this.viewportStore),H.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>{const d=this.params.connectionTypeResolver(a);return d===null?!1:(this.grabPort(a,h,d),!0)},onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,o,n){new te(e,t,s,o,n)}grabPort(e,t,s){const o=this.canvas.graph.getPort(e);this.staticPortId=e;const n=o.element.getBoundingClientRect(),a=n.x+n.width/2,h=n.y+n.height/2,d=this.overlayLayer.getBoundingClientRect(),c=this.canvas.viewport.getViewportMatrix(),g=A(c,{x:a-d.x,y:h-d.y}),l=A(c,{x:t.x-d.x,y:t.y-d.y}),u={overlayId:N.Static,portCoords:g,portDirection:o.direction},w={overlayId:N.Dragging,portCoords:l,portDirection:this.params.dragPortDirection};this.isTargetDragging=s==="direct";const[y,x]=this.isTargetDragging?[u,w]:[w,u];this.overlayCanvas.addNode(O(y)),this.overlayCanvas.addNode(O(x)),this.overlayCanvas.addEdge({from:y.overlayId,to:x.overlayId,shape:this.params.edgeShapeFactory(N.Edge)})}resetDragState(){this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}tryCreateConnection(e){const t=we(this.canvas.graph,e),s=this.staticPortId;if(t===null){this.params.onEdgeCreationInterrupted({staticPortId:s,isDirect:this.isTargetDragging});return}const o=this.isTargetDragging?s:t,n=this.isTargetDragging?t:s,a={from:o,to:n},h=this.params.connectionPreprocessor(a);h!==null?(this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)):this.params.onEdgeCreationPrevented(a)}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},o=this.canvas.viewport.getViewportMatrix(),n=A(o,s);this.overlayCanvas.updateNode(N.Dragging,{x:n.x,y:n.y})}}class re{constructor(e,t,s,o,n){i(this,"overlayCanvas");i(this,"staticPortId",null);i(this,"isTargetDragging",!0);i(this,"draggingEdgePayload",null);i(this,"onEdgeReattached",e=>{this.params.onAfterEdgeReattached(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=o,this.params=n,this.overlayCanvas=Le(this.overlayLayer,this.viewportStore),H.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>this.tryStartEdgeDragging(a,h),onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,o,n){new re(e,t,s,o,n)}tryStartEdgeDragging(e,t){const s=this.params.draggingEdgeResolver(e);if(s===null)return!1;const o=this.canvas.graph.getEdge(s);if(o===null)return!1;const n=e===o.from,a=e===o.to,h=n?o.to:o.from;this.staticPortId=h,this.isTargetDragging=a;const d=this.canvas.graph.getPort(e),c=this.canvas.graph.getPort(h),g=c.element.getBoundingClientRect(),l={x:g.x+g.width/2,y:g.y+g.height/2},u=this.canvas.viewport.getViewportMatrix(),w=this.overlayLayer.getBoundingClientRect(),y=A(u,{x:l.x-w.x,y:l.y-w.y}),x=A(u,{x:t.x-w.x,y:t.y-w.y});this.draggingEdgePayload={id:s,from:o.from,to:o.to,shape:o.shape,priority:o.priority},this.canvas.removeEdge(s);const b={overlayId:N.Static,portCoords:y,portDirection:c.direction},T={overlayId:N.Dragging,portCoords:x,portDirection:d.direction},[M,D]=this.isTargetDragging?[b,T]:[T,b];this.overlayCanvas.addNode(O(M)),this.overlayCanvas.addNode(O(D));const R=this.params.draggingEdgeShapeFactory!==null?this.params.draggingEdgeShapeFactory(N.Edge):o.shape;return this.overlayCanvas.addEdge({id:N.Edge,from:M.overlayId,to:D.overlayId,shape:R}),!0}resetDragState(){this.draggingEdgePayload=null,this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},o=this.canvas.viewport.getViewportMatrix(),n=A(o,s);this.overlayCanvas.updateNode(N.Dragging,{x:n.x,y:n.y})}tryCreateConnection(e){const t=we(this.canvas.graph,e);if(this.overlayCanvas.removeEdge(N.Edge),t===null){const d=this.draggingEdgePayload;this.params.onEdgeReattachInterrupted({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority});return}const[s,o]=this.isTargetDragging?[this.staticPortId,t]:[t,this.staticPortId],n=this.draggingEdgePayload,a={id:n.id,from:s,to:o,shape:n.shape,priority:n.priority},h=this.params.connectionPreprocessor(a);if(h!==null)this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeReattached);else{const d=this.draggingEdgePayload;this.params.onEdgeReattachPrevented({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority})}}}class se{constructor(e,t,s){this.canvas=e,this.layoutAlgorithm=t,this.trigger=s,this.trigger.subscribe(()=>{this.applyLayout()})}static configure(e,t,s){new se(e,t,s)}applyLayout(){this.layoutAlgorithm.calculateCoordinates(this.canvas.graph).forEach((t,s)=>{this.canvas.updateNode(s,t)})}}class oe{constructor(e,t){i(this,"applyScheduled",!1);this.canvas=e,this.layoutAlgorithm=t,this.canvas.graph.onAfterNodeAdded.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onBeforeNodeRemoved.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onAfterEdgeAdded.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onBeforeEdgeRemoved.subscribe(()=>{this.scheduleApply()})}static configure(e,t){new oe(e,t)}scheduleApply(){this.applyScheduled||(this.applyScheduled=!0,setTimeout(()=>{this.applyScheduled=!1,this.applyLayout()}))}applyLayout(){this.layoutAlgorithm.calculateCoordinates(this.canvas.graph).forEach((t,s)=>{this.canvas.updateNode(s,t)})}}class Tt{static configure(e,t){const s=t.applyOn;switch(s.type){case"manual":{se.configure(e,t.algorithm,s.trigger);break}case"topologyChangeTimeout":{oe.configure(e,t.algorithm);break}}}}class Ct{constructor(e,t){i(this,"previousTimeStamp");i(this,"step",e=>{if(this.previousTimeStamp===void 0)this.previousTimeStamp=e;else{const t=(e-this.previousTimeStamp)/1e3;this.previousTimeStamp=e,this.callback(t)}this.win.requestAnimationFrame(this.step)});this.win=e,this.callback=t,this.win.requestAnimationFrame(this.step)}}class ie{constructor(e,t,s,o){i(this,"step",e=>{this.algorithm.calculateNextCoordinates(this.canvas.graph,e).forEach((s,o)=>{this.staticNodes.has(o)||this.canvas.updateNode(o,{x:s.x,y:s.y})})});this.canvas=e,this.algorithm=t,this.staticNodes=s,this.win=o,new Ct(this.win,this.step)}static configure(e,t,s,o){new ie(e,t,s,o)}}const Dt=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r},ne=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.inset="0",r},Re=()=>{const r=ne();return r.style.pointerEvents="none",r};class Nt{constructor(e){i(this,"background",ne());i(this,"main",ne());i(this,"overlayConnectablePorts",Re());i(this,"overlayDraggableEdges",Re());i(this,"host",Dt());this.element=e,this.element.appendChild(this.host),this.host.appendChild(this.background),this.host.appendChild(this.main),this.host.appendChild(this.overlayConnectablePorts),this.host.appendChild(this.overlayDraggableEdges)}destroy(){this.host.removeChild(this.background),this.host.removeChild(this.main),this.host.removeChild(this.overlayConnectablePorts),this.host.removeChild(this.overlayDraggableEdges),this.element.removeChild(this.host)}}const ae=r=>()=>r,Ve=ae(0),Mt=()=>{let r=0;return()=>r++},Lt=(r,e)=>{let t=Ve,s=Ve;const o=Mt();return r==="incremental"&&(t=o),e==="incremental"&&(s=o),typeof r=="number"&&(t=ae(r)),typeof e=="number"&&(s=ae(e)),typeof r=="function"&&(t=r),typeof e=="function"&&(s=e),{nodesPriorityFn:t,edgesPriorityFn:s}},he=r=>{if(typeof r=="function")return r;switch(r.type){case"straight":return()=>new Pe({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance,detourDirection:r.detourDirection});case"horizontal":return()=>new be({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"vertical":return()=>new Te({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"direct":return()=>new Z({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,sourceOffset:r.sourceOffset,targetOffset:r.targetOffset});default:return()=>new Se({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleRadius:r.cycleRadius,smallCycleRadius:r.smallCycleRadius,curvature:r.curvature,detourDistance:r.detourDistance,detourDirection:r.detourDirection})}},Rt=r=>{var t,s,o,n,a;const e=Lt((t=r.nodes)==null?void 0:t.priority,(s=r.edges)==null?void 0:s.priority);return{nodes:{centerFn:((o=r.nodes)==null?void 0:o.centerFn)??fe,priorityFn:e.nodesPriorityFn},ports:{direction:((n=r.ports)==null?void 0:n.direction)??0},edges:{shapeFactory:he(((a=r.edges)==null?void 0:a.shape)??{}),priorityFn:e.edgesPriorityFn}}},Vt=r=>{var w,y,x,b,T,M;const e=((w=r.events)==null?void 0:w.onNodeDragStarted)??(()=>{}),t=((y=r.events)==null?void 0:y.onNodeDrag)??(()=>{}),s=r.nodeDragVerifier??(()=>!0),o=((x=r.events)==null?void 0:x.onNodeDragFinished)??(()=>{}),n=r.moveOnTop!==!1,a=r.moveEdgesOnTop!==!1&&n,h=(b=r.mouse)==null?void 0:b.dragCursor,d=h!==void 0?h:"grab",c=(T=r.mouse)==null?void 0:T.mouseDownEventVerifier,g=c!==void 0?c:D=>D.button===0,l=(M=r.mouse)==null?void 0:M.mouseUpEventVerifier,u=l!==void 0?l:D=>D.button===0;return{moveOnTop:n,moveEdgesOnTop:a,dragCursor:d,gridSize:r.gridSize??null,mouseDownEventVerifier:g,mouseUpEventVerifier:u,onNodeDragStarted:e,onNodeDrag:t,nodeDragVerifier:s,onNodeDragFinished:o}},Ft=r=>{const e=r.minX!==null?r.minX:-1/0,t=r.maxX!==null?r.maxX:1/0,s=r.minY!==null?r.minY:-1/0,o=r.maxY!==null?r.maxY:1/0;return n=>{let a=n.nextTransform.x,h=n.nextTransform.y;a<e&&a<n.prevTransform.x&&(a=Math.min(n.prevTransform.x,e));const d=n.canvasWidth*n.prevTransform.scale,c=t-d;a>c&&a>n.prevTransform.x&&(a=Math.max(n.prevTransform.x,c)),h<s&&h<n.prevTransform.y&&(h=Math.min(n.prevTransform.y,s));const g=n.canvasHeight*n.prevTransform.scale,l=o-g;return h>l&&h>n.prevTransform.y&&(h=Math.max(n.prevTransform.y,l)),{scale:n.nextTransform.scale,x:a,y:h}}},It=r=>{const e=r.maxContentScale,t=r.minContentScale,s=e!==null?1/e:0,o=t!==null?1/t:1/0;return n=>{const a=n.prevTransform,h=n.nextTransform;let d=h.scale,c=h.x,g=h.y;if(h.scale>o&&h.scale>a.scale){d=Math.max(a.scale,o),c=a.x,g=a.y;const l=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*l,g=a.y+(h.y-a.y)*l}if(h.scale<s&&h.scale<a.scale){d=Math.min(a.scale,s),c=a.x,g=a.y;const l=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*l,g=a.y+(h.y-a.y)*l}return{scale:d,x:c,y:g}}},$t=r=>e=>r.reduce((t,s)=>s({prevTransform:e.prevTransform,nextTransform:t,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),Fe=r=>{if(typeof r=="function")return r;switch(r.type){case"scale-limit":return It({minContentScale:r.minContentScale??0,maxContentScale:r.maxContentScale??1/0});case"shift-limit":return Ft({minX:r.minX??-1/0,maxX:r.maxX??1/0,minY:r.minY??-1/0,maxY:r.maxY??1/0})}},Ie=r=>{var y,x,b,T,M,D,R,$,Xe,Ye,Ge,je;const e=(y=r==null?void 0:r.scale)==null?void 0:y.mouseWheelSensitivity,t=e!==void 0?e:1.2,s=r==null?void 0:r.transformPreprocessor;let o;s!==void 0?Array.isArray(s)?o=$t(s.map(V=>Fe(V))):o=Fe(s):o=V=>V.nextTransform;const n=((x=r==null?void 0:r.shift)==null?void 0:x.cursor)!==void 0?r.shift.cursor:"grab",a=((b=r==null?void 0:r.events)==null?void 0:b.onBeforeTransformChange)??(()=>{}),h=((T=r==null?void 0:r.events)==null?void 0:T.onTransformChange)??(()=>{}),d=(M=r==null?void 0:r.shift)==null?void 0:M.mouseDownEventVerifier,c=d!==void 0?d:V=>V.button===0,g=(D=r==null?void 0:r.shift)==null?void 0:D.mouseUpEventVerifier,l=g!==void 0?g:V=>V.button===0,u=(R=r==null?void 0:r.scale)==null?void 0:R.mouseWheelEventVerifier,w=u!==void 0?u:()=>!0;return{wheelSensitivity:t,onTransformStarted:(($=r==null?void 0:r.events)==null?void 0:$.onTransformStarted)??(()=>{}),onTransformFinished:((Xe=r==null?void 0:r.events)==null?void 0:Xe.onTransformFinished)??(()=>{}),onBeforeTransformChange:a,onTransformChange:h,transformPreprocessor:o,shiftCursor:n,mouseDownEventVerifier:c,mouseUpEventVerifier:l,mouseWheelEventVerifier:w,scaleWheelFinishTimeout:((Ye=r==null?void 0:r.scale)==null?void 0:Ye.wheelFinishTimeout)??500,onResizeTransformStarted:((Ge=r==null?void 0:r.events)==null?void 0:Ge.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((je=r==null?void 0:r.events)==null?void 0:je.onResizeTransformFinished)??(()=>{})}},Ut=(r,e)=>{const t=document.createElementNS("http://www.w3.org/2000/svg","circle");return t.setAttribute("cx","0"),t.setAttribute("cy","0"),t.setAttribute("r",`${r}`),t.setAttribute("fill",`${e}`),t},Bt=r=>r instanceof SVGElement?r:Ut((r==null?void 0:r.radius)??1.5,(r==null?void 0:r.color)??"#d8d8d8"),Ot=r=>{const e=r.tileDimensions,t=(e==null?void 0:e.width)??25,s=(e==null?void 0:e.height)??25,o=Bt(r.renderer??{});return{tileWidth:t,tileHeight:s,renderer:o,maxViewportScale:r.maxViewportScale??10}},Wt=(r,e,t)=>{var c,g,l;const s=()=>"direct",o=u=>u,n=u=>u.button===0,a=()=>{},h=()=>{},d=()=>{};return{connectionTypeResolver:r.connectionTypeResolver??s,connectionPreprocessor:r.connectionPreprocessor??o,mouseDownEventVerifier:r.mouseDownEventVerifier??n,mouseUpEventVerifier:r.mouseUpEventVerifier??n,onAfterEdgeCreated:((c=r.events)==null?void 0:c.onAfterEdgeCreated)??a,onEdgeCreationInterrupted:((g=r.events)==null?void 0:g.onEdgeCreationInterrupted)??d,onEdgeCreationPrevented:((l=r.events)==null?void 0:l.onEdgeCreationPrevented)??h,dragPortDirection:r.dragPortDirection??t,edgeShapeFactory:r.edgeShape!==void 0?he(r.edgeShape):e}},kt=(r,e)=>{var c,g,l;const t=u=>u,s=u=>u.button===0&&u.ctrlKey,o=u=>u.button===0,n=u=>{const w=e.getPortAdjacentEdgeIds(u);return w.length>0?w[w.length-1]:null},a=()=>{},h=()=>{},d=()=>{};return{connectionPreprocessor:r.connectionPreprocessor??t,mouseDownEventVerifier:r.mouseDownEventVerifier??s,mouseUpEventVerifier:r.mouseUpEventVerifier??o,draggingEdgeResolver:r.draggingEdgeResolver??n,draggingEdgeShapeFactory:r.draggingEdgeShape!==void 0?he(r.draggingEdgeShape):null,onAfterEdgeReattached:((c=r.events)==null?void 0:c.onAfterEdgeReattached)??a,onEdgeReattachInterrupted:((g=r.events)==null?void 0:g.onEdgeReattachInterrupted)??d,onEdgeReattachPrevented:((l=r.events)==null?void 0:l.onEdgeReattachPrevented)??h}},zt=r=>({nodeVerticalRadius:r.nodeContainingRadius.vertical,nodeHorizontalRadius:r.nodeContainingRadius.horizontal}),Ht=r=>{var e,t;return{onAfterNodeDetached:((e=r==null?void 0:r.events)==null?void 0:e.onAfterNodeDetached)??(()=>{}),onBeforeNodeAttached:((t=r==null?void 0:r.events)==null?void 0:t.onBeforeNodeAttached)??(()=>{})}};class $e extends Error{constructor(){super(...arguments);i(this,"name","CanvasBuilderError")}}class Ue{constructor(e,t,s){i(this,"dt");i(this,"nodeMass");i(this,"edgeEquilibriumLength");i(this,"edgeStiffness");i(this,"nodeForcesApplicationStrategy");i(this,"distanceVectorGenerator");this.graph=e,this.currentCoords=t,this.dt=s.dtSec,this.nodeMass=s.nodeMass,this.edgeEquilibriumLength=s.edgeEquilibriumLength,this.edgeStiffness=s.edgeStiffness,this.distanceVectorGenerator=s.distanceVectorGenerator,this.nodeForcesApplicationStrategy=s.nodeForcesApplicationStrategy}apply(){let e=0,t=0;const s=new Map;return this.graph.getAllNodeIds().forEach(n=>{s.set(n,{x:0,y:0})}),this.nodeForcesApplicationStrategy.apply(this.currentCoords,s),this.applyEdgeForces(s),this.currentCoords.forEach((n,a)=>{const h=s.get(a),d={x:h.x/this.nodeMass*this.dt,y:h.y/this.nodeMass*this.dt};t=Math.max(t,Math.sqrt(d.x*d.x+d.y*d.y));const c=d.x*this.dt,g=d.y*this.dt;n.x+=c,n.y+=g,e=Math.max(e,Math.sqrt(c*c+g*g))}),[e,t]}applyEdgeForces(e){this.graph.getAllEdgeIds().forEach(t=>{const s=this.graph.getEdge(t),o=this.graph.getPort(s.from),n=this.graph.getPort(s.to),a=this.currentCoords.get(o.nodeId),h=this.currentCoords.get(n.nodeId),d=this.distanceVectorGenerator.create(a,h),g=(d.d-this.edgeEquilibriumLength)*this.edgeStiffness,l=d.ex*g,u=d.ey*g,w=e.get(o.nodeId),y=e.get(n.nodeId);w.x+=l,w.y+=u,y.x-=l,y.y-=u})}}const Be=(r,e,t)=>{const s=new Map,o=r.getAllNodeIds(),n=Math.sqrt(o.length)*t;return o.forEach(a=>{const h=r.getNode(a);s.set(a,{x:h.x??n*e(),y:h.y??n*e()})}),s};class Oe{constructor(e){i(this,"PI2",2*Math.PI);this.rand=e}create(e,t){const s=t.x-e.x,o=t.y-e.y,n=s*s+o*o;if(n===0){const c=this.PI2*this.rand();return{ex:Math.cos(c),ey:Math.sin(c),d:0}}const a=Math.sqrt(n),h=s/a,d=o/a;return{ex:h,ey:d,d:a}}}const We=r=>{if(r.distance===0)return r.maxForce;const e=r.coefficient*(r.sourceCharge*r.targetCharge/(r.distance*r.distance));return Math.min(e,r.maxForce)};class Xt{constructor(e){i(this,"effectiveDistance");i(this,"nodeCharge");i(this,"distanceVectorGenerator");i(this,"maxForce");this.effectiveDistance=e.effectiveDistance,this.nodeCharge=e.nodeCharge,this.distanceVectorGenerator=e.distanceVectorGenerator,this.maxForce=e.maxForce}apply(e,t){const s=Array.from(t.keys()),o=s.length;for(let n=0;n<o;n++){const a=s[n];for(let h=n+1;h<o;h++){const d=s[h],c=e.get(a),g=e.get(d),l=this.distanceVectorGenerator.create(c,g);if(l.d>this.effectiveDistance)continue;const u=We({coefficient:1,sourceCharge:this.nodeCharge,targetCharge:this.nodeCharge,distance:l.d,maxForce:this.maxForce}),w=u*l.ex,y=u*l.ey,x=t.get(a),b=t.get(d);x.x-=w,x.y-=y,b.x+=w,b.y+=y}}}}const Yt=r=>{if(r.size===0)return{centerX:0,centerY:0,radius:0};let e=1/0,t=-1/0,s=1/0,o=-1/0;r.forEach(d=>{e=Math.min(e,d.x),t=Math.max(t,d.x),s=Math.min(s,d.y),o=Math.max(o,d.y)});const n=t-e,a=o-s,h=Math.max(n,a);return{centerX:(e+t)/2,centerY:(s+o)/2,radius:h/2}};class Gt{constructor(e){i(this,"root");i(this,"leaves",new Map);i(this,"coords");i(this,"areaRadiusThreshold");i(this,"nodeMass");i(this,"nodeCharge");i(this,"sortedParentNodes",[]);this.coords=e.coords,this.areaRadiusThreshold=e.areaRadiusThreshold,this.nodeMass=e.nodeMass,this.nodeCharge=e.nodeCharge,this.root={nodeIds:new Set(e.coords.keys()),box:e.box,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},parent:null,lb:null,lt:null,rb:null,rt:null};let t=[this.root];for(;t.length>0;){const s=[];for(;t.length>0;){const o=t.pop();this.processNode(o).forEach(a=>{s.push(a)})}t=s}this.sortedParentNodes.reverse().forEach(s=>{let o=0,n=0,a=0,h=0;s.lb!==null&&(a+=s.lb.totalMass,h+=s.lb.totalCharge,o+=s.lb.chargeCenter.x*s.lb.totalCharge,n+=s.lb.chargeCenter.y*s.lb.totalCharge),s.lt!==null&&(a+=s.lt.totalMass,h+=s.lt.totalCharge,o+=s.lt.chargeCenter.x*s.lt.totalCharge,n+=s.lt.chargeCenter.y*s.lt.totalCharge),s.rb!==null&&(a+=s.rb.totalMass,h+=s.rb.totalCharge,o+=s.rb.chargeCenter.x*s.rb.totalCharge,n+=s.rb.chargeCenter.y*s.rb.totalCharge),s.rt!==null&&(a+=s.rt.totalMass,h+=s.rt.totalCharge,o+=s.rt.chargeCenter.x*s.rt.totalCharge,n+=s.rt.chargeCenter.y*s.rt.totalCharge),s.totalMass=a,s.totalCharge=h,s.chargeCenter.x=o/h,s.chargeCenter.y=n/h})}getRoot(){return this.root}getLeaf(e){return this.leaves.get(e)}processNode(e){if(e.nodeIds.size<2)return this.setLeaf(e),[];const{centerX:t,centerY:s,radius:o}=e.box;if(o<this.areaRadiusThreshold)return this.setLeaf(e),[];this.sortedParentNodes.push(e);const n=new Set,a=new Set,h=new Set,d=new Set,c=o/2;e.nodeIds.forEach(u=>{const{x:w,y}=this.coords.get(u);w<t?y<s?d.add(u):h.add(u):y<s?a.add(u):n.add(u),e.nodeIds.delete(u)});const g={parent:e,lb:null,lt:null,rb:null,rt:null},l=[];if(n.size>0){const u={nodeIds:n,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},box:{centerX:t+c,centerY:s+c,radius:c},...g};e.rt=u,l.push(u)}if(a.size>0){const u={nodeIds:a,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},box:{centerX:t+c,centerY:s-c,radius:c},...g};e.rb=u,l.push(u)}if(h.size>0){const u={nodeIds:h,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},box:{centerX:t-c,centerY:s+c,radius:c},...g};e.lt=u,l.push(u)}if(d.size>0){const u={nodeIds:d,totalMass:0,totalCharge:0,chargeCenter:{x:0,y:0},box:{centerX:t-c,centerY:s-c,radius:c},...g};e.lb=u,l.push(u)}return l}setLeaf(e){e.totalMass=this.nodeMass*e.nodeIds.size,e.totalCharge=this.nodeCharge*e.nodeIds.size,e.chargeCenter=this.calculateLeafChargeCenter(e.nodeIds),e.nodeIds.forEach(t=>{this.leaves.set(t,e)})}calculateLeafChargeCenter(e){if(e.size===0)return{x:0,y:0};let t=0,s=0;return e.forEach(o=>{const n=this.coords.get(o);t+=n.x,s+=n.y}),{x:t/e.size,y:s/e.size}}}class jt{constructor(e){i(this,"areaRadiusThreshold");i(this,"nodeMass");i(this,"nodeCharge");i(this,"theta");i(this,"distanceVectorGenerator");i(this,"nodeForceCoefficient");i(this,"maxForce");this.areaRadiusThreshold=e.areaRadiusThreshold,this.nodeMass=e.nodeMass,this.nodeCharge=e.nodeCharge,this.theta=e.theta,this.distanceVectorGenerator=e.distanceVectorGenerator,this.nodeForceCoefficient=e.nodeForceCoefficient,this.maxForce=e.maxForce}apply(e,t){const s=Yt(e),o=new Gt({box:s,coords:e,areaRadiusThreshold:this.areaRadiusThreshold,nodeMass:this.nodeMass,nodeCharge:this.nodeCharge});e.forEach((n,a)=>{const h=this.calculateForceForNode(o.getLeaf(a),a,e),d=t.get(a);this.applyForce(d,h)})}calculateForceForNode(e,t,s){const o=s.get(t),n={x:0,y:0};e.nodeIds.forEach(h=>{if(h!==t){const d=s.get(h),c=this.calculateNodeRepulsiveForce({sourceCharge:this.nodeCharge,targetCharge:this.nodeCharge,sourceCoords:d,targetCoords:o});this.applyForce(n,c)}});let a=e;for(;a!==null;){const h=a.parent;if(h!==null){const d=this.distanceVectorGenerator.create(h.chargeCenter,o);h.box.radius*2<d.d*this.theta?(this.tryApplyFarForce({totalForce:n,targetCoords:o,target:h.lb,current:a}),this.tryApplyFarForce({totalForce:n,targetCoords:o,target:h.rb,current:a}),this.tryApplyFarForce({totalForce:n,targetCoords:o,target:h.rt,current:a}),this.tryApplyFarForce({totalForce:n,targetCoords:o,target:h.lt,current:a})):(this.tryApplyNearForce({totalForce:n,targetCoords:o,target:h.lb,current:a,nodesCoords:s}),this.tryApplyNearForce({totalForce:n,targetCoords:o,target:h.rb,current:a,nodesCoords:s}),this.tryApplyNearForce({totalForce:n,targetCoords:o,target:h.rt,current:a,nodesCoords:s}),this.tryApplyNearForce({totalForce:n,targetCoords:o,target:h.lt,current:a,nodesCoords:s}))}a=a.parent}return n}calculateExactForce(e,t,s){const o={x:0,y:0},n=[e];for(;n.length>0;){const a=n.pop();a.nodeIds.forEach(h=>{const d=s.get(h),c=this.calculateNodeRepulsiveForce({sourceCharge:this.nodeCharge,targetCharge:this.nodeCharge,sourceCoords:d,targetCoords:t});this.applyForce(o,c)}),a.lb!==null&&n.push(a.lb),a.rb!==null&&n.push(a.rb),a.lt!==null&&n.push(a.lt),a.rt!==null&&n.push(a.rt)}return o}calculateApproximateForce(e,t){return this.calculateNodeRepulsiveForce({sourceCharge:this.nodeCharge,targetCharge:e.totalCharge,sourceCoords:e.chargeCenter,targetCoords:t})}calculateNodeRepulsiveForce(e){const t=this.distanceVectorGenerator.create(e.sourceCoords,e.targetCoords),s=We({coefficient:this.nodeForceCoefficient,sourceCharge:e.sourceCharge,targetCharge:e.targetCharge,distance:t.d,maxForce:this.maxForce});return{x:s*t.ex,y:s*t.ey}}applyForce(e,t){e.x+=t.x,e.y+=t.y}tryApplyFarForce(e){if(e.target!==null&&e.target!==e.current){const t=this.calculateApproximateForce(e.target,e.targetCoords);this.applyForce(e.totalForce,t)}}tryApplyNearForce(e){if(e.target!==null&&e.target!==e.current){const t=this.calculateExactForce(e.target,e.targetCoords,e.nodesCoords);this.applyForce(e.totalForce,t)}}}const ke=r=>r.theta!==0?new jt({nodeCharge:r.nodeCharge,nodeForceCoefficient:r.nodeForceCoefficient,distanceVectorGenerator:r.distanceVectorGenerator,maxForce:r.maxForce,theta:r.theta,nodeMass:r.nodeMass,areaRadiusThreshold:r.areaRadiusThreshold}):new Xt({nodeCharge:r.nodeCharge,nodeForceCoefficient:r.nodeForceCoefficient,distanceVectorGenerator:r.distanceVectorGenerator,effectiveDistance:r.effectiveDistance,maxForce:r.maxForce});class Kt{constructor(e){i(this,"distanceVectorGenerator");i(this,"nodeForcesApplicationStrategy");this.params=e,this.distanceVectorGenerator=new Oe(this.params.rand),this.nodeForcesApplicationStrategy=ke({distanceVectorGenerator:this.distanceVectorGenerator,nodeCharge:this.params.nodeCharge,effectiveDistance:this.params.effectiveDistance,maxForce:this.params.maxForce,nodeForceCoefficient:this.params.nodeForceCoefficient,theta:this.params.barnesHutTheta,areaRadiusThreshold:this.params.barnesHutAreaRadiusThreshold,nodeMass:this.params.nodeMass})}calculateCoordinates(e){const t=Be(e,this.params.rand,this.params.edgeEquilibriumLength);for(let s=0;s<this.params.maxIterations;s++){const o=new Ue(e,t,{distanceVectorGenerator:this.distanceVectorGenerator,nodeForcesApplicationStrategy:this.nodeForcesApplicationStrategy,dtSec:this.params.dtSec,nodeMass:this.params.nodeMass,edgeEquilibriumLength:this.params.edgeEquilibriumLength,edgeStiffness:this.params.edgeStiffness}),[n,a]=o.apply();if(n<this.params.convergenceDelta||a<this.params.convergenceVelocity)break}return t}}class Qt{constructor(e){i(this,"distanceVectorGenerator");i(this,"nodeForcesApplicationStrategy");i(this,"convergenceDelta");i(this,"convergenceVelocity");i(this,"maxTimeDeltaSec");i(this,"nodeMass");i(this,"edgeEquilibriumLength");i(this,"edgeStiffness");i(this,"rand");this.convergenceDelta=e.convergenceDelta,this.convergenceVelocity=e.convergenceVelocity,this.maxTimeDeltaSec=e.maxTimeDeltaSec,this.nodeMass=e.nodeMass,this.edgeEquilibriumLength=e.edgeEquilibriumLength,this.edgeStiffness=e.edgeStiffness,this.rand=e.rand,this.distanceVectorGenerator=new Oe(e.rand),this.nodeForcesApplicationStrategy=ke({distanceVectorGenerator:this.distanceVectorGenerator,nodeCharge:e.nodeCharge,effectiveDistance:e.effectiveDistance,maxForce:e.maxForce,nodeForceCoefficient:e.nodeForceCoefficient,theta:e.barnesHutTheta,areaRadiusThreshold:e.barnesHutAreaRadiusThreshold,nodeMass:e.nodeMass})}calculateNextCoordinates(e,t){const s=Be(e,this.rand,this.edgeEquilibriumLength),o=new Ue(e,s,{distanceVectorGenerator:this.distanceVectorGenerator,nodeForcesApplicationStrategy:this.nodeForcesApplicationStrategy,dtSec:Math.min(t,this.maxTimeDeltaSec),nodeMass:this.nodeMass,edgeEquilibriumLength:this.edgeEquilibriumLength,edgeStiffness:this.edgeStiffness}),[n,a]=o.apply();return(n<this.convergenceDelta||a<this.convergenceVelocity)&&!e.getAllNodeIds().some(d=>{const c=e.getNode(d);return c.x===null||c.y===null})?new Map:s}}const ze=r=>{let e=1779033703,t=3144134277,s=1013904242,o=2773480762;for(let n=0,a;n<r.length;n++)a=r.charCodeAt(n),e=t^Math.imul(e^a,597399067),t=s^Math.imul(t^a,2869860233),s=o^Math.imul(s^a,951274213),o=e^Math.imul(o^a,2716044179);return e=Math.imul(s^e>>>18,597399067),t=Math.imul(o^t>>>22,2869860233),s=Math.imul(e^s>>>17,951274213),o=Math.imul(t^o>>>19,2716044179),e^=t^s^o,t^=e,s^=e,o^=e,[e>>>0,t>>>0,s>>>0,o>>>0]},He=(r,e,t,s)=>function(){r|=0,e|=0,t|=0,s|=0;const o=(r+e|0)+s|0;return s=s+1|0,r=e^e>>>9,e=t+(t<<3)|0,t=t<<21|t>>>11,t=t+o|0,(o>>>0)/4294967296},v=Object.freeze({seed:"HTMLGraph is awesome",maxTimeDeltaSec:.01,nodeCharge:1e5,nodeMass:1,edgeEquilibriumLength:300,edgeStiffness:1e3,effectiveDistance:1e3,dtSec:.01,maxIterations:1e3,convergenceDelta:0,convergenceVelocity:10,maxForce:1e7,nodeForceCoefficient:1,barnesHutAreaRadiusThreshold:.01,barnesHutTheta:1}),Zt=r=>{var e,t,s;switch((e=r==null?void 0:r.algorithm)==null?void 0:e.type){case"custom":return r.algorithm.instance;default:{const o=r==null?void 0:r.algorithm,n=ze((o==null?void 0:o.seed)??v.seed),a=He(n[0],n[1],n[2],n[3]);return new Qt({rand:a,maxTimeDeltaSec:(o==null?void 0:o.maxTimeDeltaSec)??v.maxTimeDeltaSec,nodeCharge:(o==null?void 0:o.nodeCharge)??v.nodeCharge,nodeMass:(o==null?void 0:o.nodeMass)??v.nodeMass,edgeEquilibriumLength:(o==null?void 0:o.edgeEquilibriumLength)??v.edgeEquilibriumLength,effectiveDistance:v.effectiveDistance,edgeStiffness:(o==null?void 0:o.edgeStiffness)??v.edgeStiffness,convergenceDelta:(o==null?void 0:o.convergenceDelta)??v.convergenceDelta,convergenceVelocity:(o==null?void 0:o.convergenceVelocity)??v.convergenceVelocity,maxForce:(o==null?void 0:o.maxForce)??v.maxForce,nodeForceCoefficient:(o==null?void 0:o.nodeForceCoefficient)??v.nodeForceCoefficient,barnesHutTheta:((t=o==null?void 0:o.barnesHut)==null?void 0:t.theta)??v.barnesHutTheta,barnesHutAreaRadiusThreshold:((s=o==null?void 0:o.barnesHut)==null?void 0:s.areaRadiusThreshold)??v.barnesHutAreaRadiusThreshold})}}},qt=r=>r instanceof U?{type:"manual",trigger:r}:{type:"topologyChangeTimeout"},Jt=r=>{var e,t;switch(r==null?void 0:r.type){case"custom":return r.instance;default:{const s=ze((r==null?void 0:r.seed)??v.seed),o=He(s[0],s[1],s[2],s[3]);return new Kt({dtSec:(r==null?void 0:r.dtSec)??v.dtSec,maxIterations:(r==null?void 0:r.maxIterations)??v.maxIterations,rand:o,nodeCharge:(r==null?void 0:r.nodeCharge)??v.nodeCharge,nodeMass:(r==null?void 0:r.nodeMass)??v.nodeMass,edgeEquilibriumLength:(r==null?void 0:r.edgeEquilibriumLength)??v.edgeEquilibriumLength,edgeStiffness:(r==null?void 0:r.edgeStiffness)??v.edgeStiffness,effectiveDistance:(r==null?void 0:r.effectiveDistance)??v.effectiveDistance,convergenceDelta:(r==null?void 0:r.convergenceDelta)??v.convergenceDelta,convergenceVelocity:(r==null?void 0:r.convergenceVelocity)??v.convergenceVelocity,maxForce:(r==null?void 0:r.maxForce)??v.maxForce,nodeForceCoefficient:(r==null?void 0:r.nodeForceCoefficient)??v.nodeForceCoefficient,barnesHutTheta:((e=r==null?void 0:r.barnesHut)==null?void 0:e.theta)??v.barnesHutTheta,barnesHutAreaRadiusThreshold:((t=r==null?void 0:r.barnesHut)==null?void 0:t.areaRadiusThreshold)??v.barnesHutAreaRadiusThreshold})}}},_t=r=>({algorithm:Jt(r==null?void 0:r.algorithm),applyOn:qt(r==null?void 0:r.applyOn)}),er=(r,e)=>({...r,onNodeDragStarted:t=>{e.add(t),r.onNodeDragStarted(t)},onNodeDragFinished:t=>{e.delete(t),r.onNodeDragFinished(t)}}),tr=(r,e)=>{r.onBeforeNodeRemoved.subscribe(t=>{e.delete(t)}),r.onBeforeClear.subscribe(()=>{e.clear()})};class rr{constructor(e){i(this,"used",!1);i(this,"canvasDefaults",{});i(this,"dragConfig",{});i(this,"transformConfig",{});i(this,"backgroundConfig",{});i(this,"connectablePortsConfig",{});i(this,"draggableEdgesConfig",{});i(this,"virtualScrollConfig");i(this,"layoutConfig",{});i(this,"animatedLayoutConfig",{});i(this,"hasDraggableNodes",!1);i(this,"hasTransformableViewport",!1);i(this,"hasNodeResizeReactiveEdges",!1);i(this,"hasBackground",!1);i(this,"hasUserConnectablePorts",!1);i(this,"hasUserDraggableEdges",!1);i(this,"hasAnimatedLayout",!1);i(this,"hasLayout",!1);i(this,"boxRenderingTrigger",new U);i(this,"graphStore",new le);i(this,"viewportStore",new tt);i(this,"graph",new Ne(this.graphStore));i(this,"viewport",new Me(this.viewportStore));i(this,"window",window);i(this,"animationStaticNodes",new Set);this.element=e}setDefaults(e){return this.canvasDefaults=e,this}enableUserDraggableNodes(e){return this.hasDraggableNodes=!0,this.dragConfig=e??{},this}enableUserTransformableViewport(e){return this.hasTransformableViewport=!0,this.transformConfig=e??{},this}enableNodeResizeReactiveEdges(){return this.hasNodeResizeReactiveEdges=!0,this}enableVirtualScroll(e){return this.virtualScrollConfig=e,this}enableBackground(e){return this.hasBackground=!0,this.backgroundConfig=e??{},this}enableUserConnectablePorts(e){return this.hasUserConnectablePorts=!0,this.connectablePortsConfig=e??{},this}enableUserDraggableEdges(e){return this.hasUserDraggableEdges=!0,this.draggableEdgesConfig=e??{},this}enableLayout(e){return this.layoutConfig=e??{},this.hasLayout=!0,this.hasAnimatedLayout=!1,this}enableAnimatedLayout(e){return this.animatedLayoutConfig=e??{},this.hasAnimatedLayout=!0,this.hasLayout=!1,this}build(){if(this.used)throw new $e("CanvasBuilder is a single use object");this.used=!0;const e=new Nt(this.element);let t=new de(this.graphStore,this.viewportStore,e.main);this.virtualScrollConfig!==void 0&&(t=new Je(t,this.graphStore,this.boxRenderingTrigger,Ht(this.virtualScrollConfig))),t=new _e(t,this.graphStore);const s=Rt(this.canvasDefaults),o=new ce(this.graph,this.viewport,this.graphStore,this.viewportStore,t,s);if(this.hasBackground&&ee.configure(o,Ot(this.backgroundConfig),e.background),this.hasNodeResizeReactiveEdges&&j.configure(o),this.hasDraggableNodes){let a=Vt(this.dragConfig);this.hasAnimatedLayout&&(a=er(a,this.animationStaticNodes)),J.configure(o,e.main,this.window,a)}if(this.hasUserConnectablePorts){const a=Wt(this.connectablePortsConfig,s.edges.shapeFactory,s.ports.direction);te.configure(o,e.overlayConnectablePorts,this.viewportStore,this.window,a)}if(this.hasUserDraggableEdges){const a=kt(this.draggableEdgesConfig,o.graph);re.configure(o,e.overlayDraggableEdges,this.viewportStore,this.window,a)}this.virtualScrollConfig!==void 0?_.configure(o,e.main,this.window,Ie(this.transformConfig),this.boxRenderingTrigger,zt(this.virtualScrollConfig)):this.hasTransformableViewport&&Y.configure(o,e.main,this.window,Ie(this.transformConfig)),this.hasLayout&&Tt.configure(o,_t(this.layoutConfig)),this.hasAnimatedLayout&&(tr(o.graph,this.animationStaticNodes),ie.configure(o,Zt(this.animatedLayoutConfig),this.animationStaticNodes,this.window));const n=()=>{e.destroy(),o.onBeforeDestroy.unsubscribe(n)};return o.onBeforeDestroy.subscribe(n),o}}E.BezierEdgeShape=Se,E.CanvasBuilder=rr,E.CanvasBuilderError=$e,E.CanvasError=P,E.ConnectionCategory=C,E.DirectEdgeShape=Z,E.EventSubject=U,E.HorizontalEdgeShape=be,E.InteractiveEdgeError=De,E.InteractiveEdgeShape=q,E.MidpointEdgeShape=Et,E.StraightEdgeShape=Pe,E.VerticalEdgeShape=Te,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@html-graph/html-graph",
3
3
  "author": "Dmitry Marov <d.marov94@gmail.com>",
4
4
  "private": false,
5
- "version": "7.3.0",
5
+ "version": "7.4.0",
6
6
  "type": "module",
7
7
  "main": "dist/html-graph.js",
8
8
  "types": "dist/html-graph.d.ts",