@html-graph/html-graph 2.4.0 → 2.5.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.
- package/dist/html-graph.d.ts +14 -1
- package/dist/html-graph.js +38 -26
- package/dist/html-graph.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/html-graph.d.ts
CHANGED
|
@@ -97,6 +97,7 @@ declare type BezierEdgeShapeConfig = {
|
|
|
97
97
|
} & BezierEdgeParams;
|
|
98
98
|
|
|
99
99
|
export declare class Canvas {
|
|
100
|
+
readonly element: HTMLElement;
|
|
100
101
|
private readonly controller;
|
|
101
102
|
private readonly nodeIdGenerator;
|
|
102
103
|
private readonly portIdGenerator;
|
|
@@ -110,13 +111,17 @@ export declare class Canvas {
|
|
|
110
111
|
* provides api for accessing viewport state
|
|
111
112
|
*/
|
|
112
113
|
readonly viewport: Viewport;
|
|
113
|
-
constructor(controller: CanvasController, options: CanvasDefaults);
|
|
114
|
+
constructor(element: HTMLElement, controller: CanvasController, options: CanvasDefaults);
|
|
114
115
|
/**
|
|
116
|
+
* @deprecated
|
|
117
|
+
* use CanvasBuilder.attach instead
|
|
115
118
|
* attaches canvas to given element
|
|
116
119
|
* detaches element first when canvas is attached
|
|
117
120
|
*/
|
|
118
121
|
attach(element: HTMLElement): Canvas;
|
|
119
122
|
/**
|
|
123
|
+
* @deprecated
|
|
124
|
+
* attach canvas once instead, then reattach wrapper element
|
|
120
125
|
* detaches canvas from element when attached
|
|
121
126
|
*/
|
|
122
127
|
detach(): Canvas;
|
|
@@ -180,6 +185,7 @@ export declare class Canvas {
|
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
export declare class CanvasBuilder {
|
|
188
|
+
private element;
|
|
183
189
|
private canvasDefaults;
|
|
184
190
|
private dragOptions;
|
|
185
191
|
private transformOptions;
|
|
@@ -188,6 +194,7 @@ export declare class CanvasBuilder {
|
|
|
188
194
|
private hasTransformableViewport;
|
|
189
195
|
private hasResizeReactiveNodes;
|
|
190
196
|
private boxRenderingTrigger;
|
|
197
|
+
attach(element: HTMLElement): CanvasBuilder;
|
|
191
198
|
/**
|
|
192
199
|
* specifies default values for graph entities
|
|
193
200
|
*/
|
|
@@ -224,7 +231,13 @@ export declare class CanvasBuilder {
|
|
|
224
231
|
declare interface CanvasController {
|
|
225
232
|
readonly graph: Graph;
|
|
226
233
|
readonly viewport: Viewport;
|
|
234
|
+
/**
|
|
235
|
+
* @deprecated
|
|
236
|
+
*/
|
|
227
237
|
attach(element: HTMLElement): void;
|
|
238
|
+
/**
|
|
239
|
+
* @deprecated
|
|
240
|
+
*/
|
|
228
241
|
detach(): void;
|
|
229
242
|
addNode(node: AddNodeRequest_3): void;
|
|
230
243
|
updateNode(nodeId: unknown, request: UpdateNodeRequest_3): void;
|
package/dist/html-graph.js
CHANGED
|
@@ -1057,7 +1057,7 @@ const Se = (t, e) => ({
|
|
|
1057
1057
|
}), Y = (t) => () => t, Z = Y(0), Ne = () => {
|
|
1058
1058
|
let t = 0;
|
|
1059
1059
|
return () => t++;
|
|
1060
|
-
},
|
|
1060
|
+
}, me = (t, e) => {
|
|
1061
1061
|
let o = Z, r = Z;
|
|
1062
1062
|
const n = Ne();
|
|
1063
1063
|
return t === "incremental" && (o = n), e === "incremental" && (r = n), typeof t == "number" && (o = Y(t)), typeof e == "number" && (r = Y(e)), typeof t == "function" && (o = t), typeof e == "function" && (r = e), {
|
|
@@ -1067,10 +1067,10 @@ const Se = (t, e) => ({
|
|
|
1067
1067
|
}, y = (t, e, o) => ({
|
|
1068
1068
|
x: e.x * t.x - e.y * t.y + ((1 - e.x) * o.x + e.y * o.y),
|
|
1069
1069
|
y: e.y * t.x + e.x * t.y + ((1 - e.x) * o.y - e.y * o.x)
|
|
1070
|
-
}),
|
|
1070
|
+
}), m = (t, e, o) => ({ x: e * Math.cos(t), y: o * Math.sin(t) }), w = {
|
|
1071
1071
|
x: 0,
|
|
1072
1072
|
y: 0
|
|
1073
|
-
},
|
|
1073
|
+
}, T = (t, e, o, r) => {
|
|
1074
1074
|
const h = [
|
|
1075
1075
|
w,
|
|
1076
1076
|
{ x: o, y: r },
|
|
@@ -1124,7 +1124,7 @@ const Se = (t, e) => ({
|
|
|
1124
1124
|
flipX: c,
|
|
1125
1125
|
flipY: a
|
|
1126
1126
|
};
|
|
1127
|
-
},
|
|
1127
|
+
}, Te = (t) => {
|
|
1128
1128
|
const e = y(
|
|
1129
1129
|
{ x: t.arrowLength, y: w.y },
|
|
1130
1130
|
t.fromVect,
|
|
@@ -1332,11 +1332,11 @@ class De {
|
|
|
1332
1332
|
e.to
|
|
1333
1333
|
);
|
|
1334
1334
|
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${h}px`, this.group.style.transform = `scale(${s}, ${d})`;
|
|
1335
|
-
const c =
|
|
1335
|
+
const c = m(
|
|
1336
1336
|
e.from.direction,
|
|
1337
1337
|
s,
|
|
1338
1338
|
d
|
|
1339
|
-
), a =
|
|
1339
|
+
), a = m(e.to.direction, s, d), l = {
|
|
1340
1340
|
x: n,
|
|
1341
1341
|
y: h
|
|
1342
1342
|
};
|
|
@@ -1360,7 +1360,7 @@ class De {
|
|
|
1360
1360
|
curvature: this.curvature,
|
|
1361
1361
|
hasSourceArrow: this.hasSourceArrow,
|
|
1362
1362
|
hasTargetArrow: this.hasTargetArrow
|
|
1363
|
-
}) : g =
|
|
1363
|
+
}) : g = Te({
|
|
1364
1364
|
to: l,
|
|
1365
1365
|
fromVect: c,
|
|
1366
1366
|
toVect: a,
|
|
@@ -1369,7 +1369,7 @@ class De {
|
|
|
1369
1369
|
hasSourceArrow: this.hasSourceArrow,
|
|
1370
1370
|
hasTargetArrow: this.hasTargetArrow
|
|
1371
1371
|
}), this.line.setAttribute("d", g), this.sourceArrow) {
|
|
1372
|
-
const v =
|
|
1372
|
+
const v = T(
|
|
1373
1373
|
c,
|
|
1374
1374
|
w,
|
|
1375
1375
|
this.arrowLength,
|
|
@@ -1378,7 +1378,7 @@ class De {
|
|
|
1378
1378
|
this.sourceArrow.setAttribute("d", v);
|
|
1379
1379
|
}
|
|
1380
1380
|
if (this.targetArrow) {
|
|
1381
|
-
const v =
|
|
1381
|
+
const v = T(
|
|
1382
1382
|
f,
|
|
1383
1383
|
l,
|
|
1384
1384
|
x,
|
|
@@ -1420,11 +1420,11 @@ class Ce {
|
|
|
1420
1420
|
e.to
|
|
1421
1421
|
);
|
|
1422
1422
|
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${h}px`, this.group.style.transform = `scale(${s}, ${d})`;
|
|
1423
|
-
const c =
|
|
1423
|
+
const c = m(
|
|
1424
1424
|
e.from.direction,
|
|
1425
1425
|
s,
|
|
1426
1426
|
d
|
|
1427
|
-
), a =
|
|
1427
|
+
), a = m(e.to.direction, s, d), l = {
|
|
1428
1428
|
x: n,
|
|
1429
1429
|
y: h
|
|
1430
1430
|
};
|
|
@@ -1461,7 +1461,7 @@ class Ce {
|
|
|
1461
1461
|
hasSourceArrow: this.hasSourceArrow,
|
|
1462
1462
|
hasTargetArrow: this.hasTargetArrow
|
|
1463
1463
|
}), this.line.setAttribute("d", g), this.sourceArrow) {
|
|
1464
|
-
const v =
|
|
1464
|
+
const v = T(
|
|
1465
1465
|
c,
|
|
1466
1466
|
w,
|
|
1467
1467
|
this.arrowLength,
|
|
@@ -1470,7 +1470,7 @@ class Ce {
|
|
|
1470
1470
|
this.sourceArrow.setAttribute("d", v);
|
|
1471
1471
|
}
|
|
1472
1472
|
if (this.targetArrow) {
|
|
1473
|
-
const v =
|
|
1473
|
+
const v = T(
|
|
1474
1474
|
f,
|
|
1475
1475
|
l,
|
|
1476
1476
|
x,
|
|
@@ -1512,11 +1512,11 @@ class Ue {
|
|
|
1512
1512
|
e.to
|
|
1513
1513
|
);
|
|
1514
1514
|
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${h}px`, this.group.style.transform = `scale(${s}, ${d})`;
|
|
1515
|
-
const c =
|
|
1515
|
+
const c = m(
|
|
1516
1516
|
e.from.direction,
|
|
1517
1517
|
s,
|
|
1518
1518
|
d
|
|
1519
|
-
), a =
|
|
1519
|
+
), a = m(e.to.direction, s, d), l = {
|
|
1520
1520
|
x: n,
|
|
1521
1521
|
y: h
|
|
1522
1522
|
};
|
|
@@ -1552,7 +1552,7 @@ class Ue {
|
|
|
1552
1552
|
hasSourceArrow: this.hasSourceArrow,
|
|
1553
1553
|
hasTargetArrow: this.hasTargetArrow
|
|
1554
1554
|
}), this.line.setAttribute("d", g), this.sourceArrow) {
|
|
1555
|
-
const v =
|
|
1555
|
+
const v = T(
|
|
1556
1556
|
c,
|
|
1557
1557
|
w,
|
|
1558
1558
|
this.arrowLength,
|
|
@@ -1561,7 +1561,7 @@ class Ue {
|
|
|
1561
1561
|
this.sourceArrow.setAttribute("d", v);
|
|
1562
1562
|
}
|
|
1563
1563
|
if (this.targetArrow) {
|
|
1564
|
-
const v =
|
|
1564
|
+
const v = T(
|
|
1565
1565
|
f,
|
|
1566
1566
|
l,
|
|
1567
1567
|
x,
|
|
@@ -1603,11 +1603,11 @@ class $e {
|
|
|
1603
1603
|
e.to
|
|
1604
1604
|
);
|
|
1605
1605
|
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${h}px`, this.group.style.transform = `scale(${s}, ${d})`;
|
|
1606
|
-
const c =
|
|
1606
|
+
const c = m(
|
|
1607
1607
|
e.from.direction,
|
|
1608
1608
|
s,
|
|
1609
1609
|
d
|
|
1610
|
-
), a =
|
|
1610
|
+
), a = m(e.to.direction, s, d), l = {
|
|
1611
1611
|
x: n,
|
|
1612
1612
|
y: h
|
|
1613
1613
|
};
|
|
@@ -1644,7 +1644,7 @@ class $e {
|
|
|
1644
1644
|
hasSourceArrow: this.hasSourceArrow,
|
|
1645
1645
|
hasTargetArrow: this.hasTargetArrow
|
|
1646
1646
|
}), this.line.setAttribute("d", g), this.sourceArrow) {
|
|
1647
|
-
const v =
|
|
1647
|
+
const v = T(
|
|
1648
1648
|
c,
|
|
1649
1649
|
w,
|
|
1650
1650
|
this.arrowLength,
|
|
@@ -1653,7 +1653,7 @@ class $e {
|
|
|
1653
1653
|
this.sourceArrow.setAttribute("d", v);
|
|
1654
1654
|
}
|
|
1655
1655
|
if (this.targetArrow) {
|
|
1656
|
-
const v =
|
|
1656
|
+
const v = T(
|
|
1657
1657
|
f,
|
|
1658
1658
|
l,
|
|
1659
1659
|
x,
|
|
@@ -1726,7 +1726,7 @@ const Re = (t) => {
|
|
|
1726
1726
|
}
|
|
1727
1727
|
}, Ie = (t) => {
|
|
1728
1728
|
var o, r, n, h, s;
|
|
1729
|
-
const e =
|
|
1729
|
+
const e = me(
|
|
1730
1730
|
(o = t == null ? void 0 : t.nodes) == null ? void 0 : o.priority,
|
|
1731
1731
|
(r = t == null ? void 0 : t.edges) == null ? void 0 : r.priority
|
|
1732
1732
|
);
|
|
@@ -1745,7 +1745,7 @@ const Re = (t) => {
|
|
|
1745
1745
|
};
|
|
1746
1746
|
};
|
|
1747
1747
|
class We {
|
|
1748
|
-
constructor(e, o) {
|
|
1748
|
+
constructor(e, o, r) {
|
|
1749
1749
|
i(this, "nodeIdGenerator", new z(
|
|
1750
1750
|
(e) => this.graph.getNode(e) !== null
|
|
1751
1751
|
));
|
|
@@ -1764,9 +1764,11 @@ class We {
|
|
|
1764
1764
|
* provides api for accessing viewport state
|
|
1765
1765
|
*/
|
|
1766
1766
|
i(this, "viewport");
|
|
1767
|
-
this.
|
|
1767
|
+
this.element = e, this.controller = o, this.defaults = Ie(r), this.graph = o.graph, this.viewport = o.viewport, this.attach(this.element);
|
|
1768
1768
|
}
|
|
1769
1769
|
/**
|
|
1770
|
+
* @deprecated
|
|
1771
|
+
* use CanvasBuilder.attach instead
|
|
1770
1772
|
* attaches canvas to given element
|
|
1771
1773
|
* detaches element first when canvas is attached
|
|
1772
1774
|
*/
|
|
@@ -1774,6 +1776,8 @@ class We {
|
|
|
1774
1776
|
return this.controller.attach(e), this;
|
|
1775
1777
|
}
|
|
1776
1778
|
/**
|
|
1779
|
+
* @deprecated
|
|
1780
|
+
* attach canvas once instead, then reattach wrapper element
|
|
1777
1781
|
* detaches canvas from element when attached
|
|
1778
1782
|
*/
|
|
1779
1783
|
detach() {
|
|
@@ -2162,6 +2166,7 @@ class j {
|
|
|
2162
2166
|
}
|
|
2163
2167
|
class ze {
|
|
2164
2168
|
constructor() {
|
|
2169
|
+
i(this, "element", null);
|
|
2165
2170
|
i(this, "canvasDefaults", {});
|
|
2166
2171
|
i(this, "dragOptions");
|
|
2167
2172
|
i(this, "transformOptions");
|
|
@@ -2171,6 +2176,9 @@ class ze {
|
|
|
2171
2176
|
i(this, "hasResizeReactiveNodes", !1);
|
|
2172
2177
|
i(this, "boxRenderingTrigger");
|
|
2173
2178
|
}
|
|
2179
|
+
attach(e) {
|
|
2180
|
+
return this.element = e, this;
|
|
2181
|
+
}
|
|
2174
2182
|
/**
|
|
2175
2183
|
* specifies default values for graph entities
|
|
2176
2184
|
*/
|
|
@@ -2215,6 +2223,10 @@ class ze {
|
|
|
2215
2223
|
* builds final canvas
|
|
2216
2224
|
*/
|
|
2217
2225
|
build() {
|
|
2226
|
+
if (this.element === null)
|
|
2227
|
+
throw new E(
|
|
2228
|
+
"unable to build canvas when no attach element specified"
|
|
2229
|
+
);
|
|
2218
2230
|
let e = this.boxRenderingTrigger;
|
|
2219
2231
|
this.virtualScrollOptions !== void 0 && e === void 0 && (e = new te());
|
|
2220
2232
|
const o = new Fe(), r = new Be();
|
|
@@ -2237,11 +2249,11 @@ class ze {
|
|
|
2237
2249
|
h,
|
|
2238
2250
|
this.transformOptions
|
|
2239
2251
|
));
|
|
2240
|
-
const s = new We(h, this.canvasDefaults);
|
|
2252
|
+
const s = new We(this.element, h, this.canvasDefaults);
|
|
2241
2253
|
return this.hasResizeReactiveNodes && j.configure(s), this.reset(), s;
|
|
2242
2254
|
}
|
|
2243
2255
|
reset() {
|
|
2244
|
-
this.canvasDefaults = {}, this.dragOptions = void 0, this.transformOptions = void 0, this.virtualScrollOptions = void 0, this.hasDraggableNode = !1, this.hasTransformableViewport = !1, this.hasResizeReactiveNodes = !1, this.boxRenderingTrigger = void 0;
|
|
2256
|
+
this.element = null, this.canvasDefaults = {}, this.dragOptions = void 0, this.transformOptions = void 0, this.virtualScrollOptions = void 0, this.hasDraggableNode = !1, this.hasTransformableViewport = !1, this.hasResizeReactiveNodes = !1, this.boxRenderingTrigger = void 0;
|
|
2245
2257
|
}
|
|
2246
2258
|
}
|
|
2247
2259
|
export {
|
package/dist/html-graph.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(A,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(A=typeof globalThis<"u"?globalThis:A||self,p(A.HtmlGraph={}))})(this,function(A){"use strict";var ze=Object.defineProperty;var ke=(A,p,L)=>p in A?ze(A,p,{enumerable:!0,configurable:!0,writable:!0,value:L}):A[p]=L;var i=(A,p,L)=>ke(A,typeof p!="symbol"?p+"":p,L);class p{constructor(e){i(this,"onAfterNodeAdded");i(this,"onAfterNodeCoordinatesUpdated");i(this,"onAfterNodeUpdated");i(this,"onAfterNodePriorityUpdated");i(this,"onBeforeNodeRemoved");i(this,"onAfterPortMarked");i(this,"onAfterPortAdded");i(this,"onAfterPortUpdated");i(this,"onAfterPortDirectionUpdated");i(this,"onBeforePortUnmarked");i(this,"onBeforePortRemoved");i(this,"onAfterEdgeAdded");i(this,"onAfterEdgeShapeUpdated");i(this,"onAfterEdgeUpdated");i(this,"onAfterEdgeAdjacentPortsUpdated");i(this,"onAfterEdgePriorityUpdated");i(this,"onBeforeEdgeRemoved");i(this,"onBeforeClear");this.graphStore=e,this.onAfterNodeAdded=this.graphStore.onAfterNodeAdded,this.onAfterNodeUpdated=this.graphStore.onAfterNodeUpdated,this.onAfterNodeCoordinatesUpdated=this.onAfterNodeUpdated,this.onAfterNodePriorityUpdated=this.graphStore.onAfterNodePriorityUpdated,this.onBeforeNodeRemoved=this.graphStore.onBeforeNodeRemoved,this.onAfterPortMarked=this.graphStore.onAfterPortAdded,this.onAfterPortAdded=this.onAfterPortMarked,this.onAfterPortUpdated=this.graphStore.onAfterPortUpdated,this.onAfterPortDirectionUpdated=this.onAfterPortUpdated,this.onBeforePortUnmarked=this.graphStore.onBeforePortRemoved,this.onBeforePortRemoved=this.onBeforePortUnmarked,this.onAfterEdgeAdded=this.graphStore.onAfterEdgeAdded,this.onAfterEdgeShapeUpdated=this.graphStore.onAfterEdgeShapeUpdated,this.onAfterEdgeUpdated=this.graphStore.onAfterEdgeUpdated,this.onAfterEdgeAdjacentPortsUpdated=this.onAfterEdgeUpdated,this.onAfterEdgePriorityUpdated=this.graphStore.onAfterEdgePriorityUpdated,this.onBeforeEdgeRemoved=this.graphStore.onBeforeEdgeRemoved,this.onBeforeClear=this.graphStore.onBeforeClear}getNode(e){const o=this.graphStore.getNode(e);return o===void 0?null:{element:o.element,x:o.x,y:o.y,centerFn:o.centerFn,priority:o.priority}}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(e){const o=this.graphStore.getPort(e);return o===void 0?null:{element:o.element,direction:o.direction,nodeId:o.nodeId}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(e){return this.graphStore.getNodePortIds(e)??null}getPortNodeId(e){var o;return((o=this.graphStore.getPort(e))==null?void 0:o.nodeId)??null}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(e){const o=this.graphStore.getEdge(e);return o===void 0?null:{from:o.from,to:o.to,priority:o.priority}}getPortIncomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortIncomingEdgeIds(e)}getPortOutcomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortOutcomingEdgeIds(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)}getNodeOutcomingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeOutcomingEdgeIds(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 L{constructor(e){i(this,"onBeforeUpdated");i(this,"onAfterUpdated");this.transformer=e,this.onBeforeUpdated=this.transformer.onBeforeUpdated,this.onAfterUpdated=this.transformer.onAfterUpdated}getViewportMatrix(){return{...this.transformer.getViewportMatrix()}}getContentMatrix(){return{...this.transformer.getContentMatrix()}}}class ce{constructor(e,o,r){i(this,"viewport");i(this,"graph");i(this,"onAfterNodeAdded",e=>{this.htmlView.attachNode(e)});i(this,"onAfterNodeUpdated",e=>{this.htmlView.updateNodePosition(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(r=>{this.htmlView.renderEdge(r)})});i(this,"onAfterNodePriorityUpdated",e=>{this.htmlView.updateNodePriority(e)});i(this,"onBeforeNodeRemoved",e=>{this.graphStore.getNodePortIds(e).forEach(o=>{this.unmarkPort(o)}),this.htmlView.detachNode(e)});i(this,"onAfterPortUpdated",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(r=>{this.htmlView.renderEdge(r)})});i(this,"onBeforePortUnmarked",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(o=>{this.removeEdge(o)})});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.htmlView.clear()});this.graphStore=e,this.viewportStore=o,this.htmlView=r,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.graph=new p(this.graphStore),this.viewport=new L(this.viewportStore)}attach(e){this.htmlView.attach(e)}detach(){this.htmlView.detach()}addNode(e){this.graphStore.addNode(e)}updateNode(e,o){this.graphStore.updateNode(e,o)}removeNode(e){this.graphStore.removeNode(e)}markPort(e){this.graphStore.addPort(e)}updatePort(e,o){this.graphStore.updatePort(e,o)}unmarkPort(e){this.graphStore.removePort(e)}addEdge(e){this.graphStore.addEdge(e)}updateEdge(e,o){this.graphStore.updateEdge(e,o)}removeEdge(e){this.graphStore.removeEdge(e)}patchViewportMatrix(e){this.viewportStore.patchViewportMatrix(e)}patchContentMatrix(e){this.viewportStore.patchContentMatrix(e)}clear(){this.graphStore.clear()}destroy(){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.clear(),this.htmlView.destroy()}}const R=(t,e,o)=>{const{x:r,y:n,width:h,height:s}=t.getBoundingClientRect();return e>=r&&e<=r+h&&o>=n&&o<=n+s},I=(t,e,o)=>e>=0&&e<=t.innerWidth&&o>=0&&o<=t.innerHeight,W=(t,e)=>{e!==null?t.style.cursor=e:t.style.removeProperty("cursor")},ae=t=>{var g,f,x,v,m,N;const e=((g=t==null?void 0:t.events)==null?void 0:g.onNodeDrag)??(()=>{}),o=((f=t==null?void 0:t.events)==null?void 0:f.onBeforeNodeDrag)??(()=>!0),r=((x=t==null?void 0:t.events)==null?void 0:x.onNodeDragFinished)??(()=>{}),n=(t==null?void 0:t.moveOnTop)===!1,h=(v=t==null?void 0:t.mouse)==null?void 0:v.dragCursor,s=h!==void 0?h:"grab",d=(m=t==null?void 0:t.mouse)==null?void 0:m.mouseDownEventVerifier,c=d!==void 0?d:T=>T.button===0,a=(N=t==null?void 0:t.mouse)==null?void 0:N.mouseUpEventVerifier;return{freezePriority:n,dragCursor:s,mouseDownEventVerifier:c,mouseUpEventVerifier:a!==void 0?a:T=>T.button===0,onNodeDrag:e,onBeforeNodeDrag:o,onNodeDragFinished:r}};class le{constructor(e,o){i(this,"graph");i(this,"viewport");i(this,"maxNodePriority",0);i(this,"nodes",new Map);i(this,"grabbedNodeId",null);i(this,"element",null);i(this,"onWindowMouseMove",e=>{if(this.element!==null&&(!R(this.element,e.clientX,e.clientY)||!I(this.window,e.clientX,e.clientY))){this.cancelMouseDrag();return}this.grabbedNodeId!==null&&this.dragNode(this.grabbedNodeId,e.movementX,e.movementY)});i(this,"onWindowMouseUp",e=>{this.options.mouseUpEventVerifier(e)&&this.cancelMouseDrag()});i(this,"onWindowTouchMove",e=>{if(e.touches.length!==1)return;const o=e.touches[0];if(this.element!==null&&(!R(this.element,o.clientX,o.clientY)||!I(this.window,o.clientX,o.clientY))){this.cancelTouchDrag();return}if(this.grabbedNodeId!==null&&this.previousTouchCoords!==null){const r=o.clientX-this.previousTouchCoords.x,n=o.clientY-this.previousTouchCoords.y;this.dragNode(this.grabbedNodeId,r,n),this.previousTouchCoords={x:e.touches[0].clientX,y:e.touches[0].clientY}}});i(this,"onWindowTouchFinish",()=>{this.previousTouchCoords=null,this.cancelTouchDrag()});i(this,"previousTouchCoords",null);i(this,"window",window);i(this,"options");this.canvas=e,this.viewport=this.canvas.viewport,this.graph=this.canvas.graph,this.options=ae(o??{})}attach(e){this.detach(),this.element=e,this.canvas.attach(this.element)}detach(){this.canvas.detach(),this.element!==null&&(this.element=null)}addNode(e){this.canvas.addNode(e),this.updateMaxNodePriority(e.id);const o=n=>{if(this.element===null||!this.options.mouseDownEventVerifier(n))return;const h=this.graph.getNode(e.id);this.options.onBeforeNodeDrag({nodeId:e.id,element:e.element,x:h.x,y:h.y})&&(n.stopImmediatePropagation(),this.grabbedNodeId=e.id,W(this.element,this.options.dragCursor),this.moveNodeOnTop(e.id),this.window.addEventListener("mouseup",this.onWindowMouseUp),this.window.addEventListener("mousemove",this.onWindowMouseMove))},r=n=>{if(n.touches.length!==1)return;n.stopImmediatePropagation(),this.previousTouchCoords={x:n.touches[0].clientX,y:n.touches[0].clientY};const h=this.graph.getNode(e.id);this.options.onBeforeNodeDrag({nodeId:e.id,element:e.element,x:h.x,y:h.y})&&(this.grabbedNodeId=e.id,this.moveNodeOnTop(e.id),this.window.addEventListener("touchmove",this.onWindowTouchMove),this.window.addEventListener("touchend",this.onWindowTouchFinish),this.window.addEventListener("touchcancel",this.onWindowTouchFinish))};this.nodes.set(e.id,{element:e.element,onMouseDown:o,onTouchStart:r}),e.element.addEventListener("mousedown",o),e.element.addEventListener("touchstart",r)}updateNode(e,o){this.canvas.updateNode(e,o),this.updateMaxNodePriority(e)}removeNode(e){const o=this.nodes.get(e);o!==void 0&&(o.element.removeEventListener("mousedown",o.onMouseDown),o.element.removeEventListener("touchstart",o.onTouchStart)),this.nodes.delete(e),this.canvas.removeNode(e)}markPort(e){this.canvas.markPort(e)}updatePort(e,o){this.canvas.updatePort(e,o)}unmarkPort(e){this.canvas.unmarkPort(e)}addEdge(e){this.canvas.addEdge(e)}updateEdge(e,o){this.canvas.updateEdge(e,o)}removeEdge(e){this.canvas.removeEdge(e)}patchViewportMatrix(e){this.canvas.patchViewportMatrix(e)}patchContentMatrix(e){this.canvas.patchContentMatrix(e)}clear(){this.canvas.clear(),this.nodes.forEach(e=>{e.element.removeEventListener("mousedown",e.onMouseDown),e.element.removeEventListener("touchstart",e.onTouchStart)}),this.nodes.clear(),this.maxNodePriority=0}destroy(){this.detach(),this.clear(),this.removeMouseDragListeners(),this.removeTouchDragListeners(),this.canvas.destroy()}dragNode(e,o,r){const n=this.graph.getNode(e);if(n===null)return;const h=this.canvas.viewport.getContentMatrix(),s=h.scale*n.x+h.x,d=h.scale*n.y+h.y,c=s+o,a=d+r,l=this.canvas.viewport.getViewportMatrix(),g=l.scale*c+l.x,f=l.scale*a+l.y;this.canvas.updateNode(e,{x:g,y:f}),this.options.onNodeDrag({nodeId:e,element:n.element,x:g,y:f})}updateMaxNodePriority(e){const o=this.graph.getNode(e).priority;this.maxNodePriority=Math.max(this.maxNodePriority,o)}moveNodeOnTop(e){if(this.options.freezePriority)return;this.maxNodePriority+=2,this.updateNode(e,{priority:this.maxNodePriority});const o=this.maxNodePriority-1;this.graph.getNodeAdjacentEdgeIds(e).forEach(n=>{this.updateEdge(n,{priority:o})})}cancelMouseDrag(){const e=this.graph.getNode(this.grabbedNodeId);e!==null&&this.options.onNodeDragFinished({nodeId:this.grabbedNodeId,element:e.element,x:e.x,y:e.y}),this.grabbedNodeId=null,this.element!==null&&W(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){this.previousTouchCoords=null;const e=this.graph.getNode(this.grabbedNodeId);e!==null&&this.options.onNodeDragFinished({nodeId:this.grabbedNodeId,element:e.element,x:e.x,y:e.y}),this.grabbedNodeId=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}const ge=t=>{const e=t.minX!==null?t.minX:-1/0,o=t.maxX!==null?t.maxX:1/0,r=t.minY!==null?t.minY:-1/0,n=t.maxY!==null?t.maxY:1/0;return h=>{let s=h.nextTransform.x,d=h.nextTransform.y;s<e&&s<h.prevTransform.x&&(s=Math.min(h.prevTransform.x,e));const c=h.canvasWidth*h.prevTransform.scale,a=o-c;s>a&&s>h.prevTransform.x&&(s=Math.max(h.prevTransform.x,a)),d<r&&d<h.prevTransform.y&&(d=Math.min(h.prevTransform.y,r));const l=h.canvasHeight*h.prevTransform.scale,g=n-l;return d>g&&d>h.prevTransform.y&&(d=Math.max(h.prevTransform.y,g)),{scale:h.nextTransform.scale,x:s,y:d}}},ue=t=>{const e=t.maxContentScale,o=t.minContentScale,r=e!==null?1/e:0,n=o!==null?1/o:1/0;return h=>{const s=h.prevTransform,d=h.nextTransform;let c=d.scale,a=d.x,l=d.y;if(d.scale>n&&d.scale>s.scale){c=Math.max(s.scale,n),a=s.x,l=s.y;const g=(c-s.scale)/(d.scale-s.scale);a=s.x+(d.x-s.x)*g,l=s.y+(d.y-s.y)*g}if(d.scale<r&&d.scale<s.scale){c=Math.min(s.scale,r),a=s.x,l=s.y;const g=(c-s.scale)/(d.scale-s.scale);a=s.x+(d.x-s.x)*g,l=s.y+(d.y-s.y)*g}return{scale:c,x:a,y:l}}},we=t=>e=>t.reduce((o,r)=>r({prevTransform:e.prevTransform,nextTransform:o,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),Q=t=>{if(typeof t=="function")return t;switch(t.type){case"scale-limit":return ue({minContentScale:t.minContentScale??0,maxContentScale:t.maxContentScale??1/0});case"shift-limit":return ge({minX:t.minX??-1/0,maxX:t.maxX??1/0,minY:t.minY??-1/0,maxY:t.maxY??1/0})}},fe=t=>{var v,m,N,T,K,C,U,$,se,ne,he,de;const e=(v=t==null?void 0:t.scale)==null?void 0:v.mouseWheelSensitivity,o=e!==void 0?e:1.2,r=t==null?void 0:t.transformPreprocessor;let n;r!==void 0?Array.isArray(r)?n=we(r.map(V=>Q(V))):n=Q(r):n=V=>V.nextTransform;const h=((m=t==null?void 0:t.shift)==null?void 0:m.cursor)!==void 0?t.shift.cursor:"grab",s=((N=t==null?void 0:t.events)==null?void 0:N.onBeforeTransformChange)??(()=>{}),d=((T=t==null?void 0:t.events)==null?void 0:T.onTransformChange)??(()=>{}),c=(K=t==null?void 0:t.shift)==null?void 0:K.mouseDownEventVerifier,a=c!==void 0?c:V=>V.button===0,l=(C=t==null?void 0:t.shift)==null?void 0:C.mouseUpEventVerifier,g=l!==void 0?l:V=>V.button===0,f=(U=t==null?void 0:t.scale)==null?void 0:U.mouseWheelEventVerifier,x=f!==void 0?f:()=>!0;return{wheelSensitivity:o,onTransformStarted:(($=t==null?void 0:t.events)==null?void 0:$.onTransformStarted)??(()=>{}),onTransformFinished:((se=t==null?void 0:t.events)==null?void 0:se.onTransformFinished)??(()=>{}),onBeforeTransformChange:s,onTransformChange:d,transformPreprocessor:n,shiftCursor:h,mouseDownEventVerifier:a,mouseUpEventVerifier:g,mouseWheelEventVerifier:x,scaleWheelFinishTimeout:((ne=t==null?void 0:t.scale)==null?void 0:ne.wheelFinishTimeout)??500,onResizeTransformStarted:((he=t==null?void 0:t.events)==null?void 0:he.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((de=t==null?void 0:t.events)==null?void 0:de.onResizeTransformFinished)??(()=>{})}},F=t=>{const e=[],o=t.touches.length;for(let d=0;d<o;d++)e.push([t.touches[d].clientX,t.touches[d].clientY]);const r=e.reduce((d,c)=>[d[0]+c[0],d[1]+c[1]],[0,0]),n=[r[0]/o,r[1]/o],s=e.map(d=>[d[0]-n[0],d[1]-n[1]]).reduce((d,c)=>d+Math.sqrt(c[0]*c[0]+c[1]*c[1]),0);return{x:n[0],y:n[1],scale:s/o,touchesCnt:o,touches:e}},ve=(t,e,o)=>({scale:t.scale,x:t.x+t.scale*e,y:t.y+t.scale*o}),ye=(t,e,o,r)=>({scale:t.scale*e,x:t.scale*(1-e)*o+t.x,y:t.scale*(1-e)*r+t.y});class Z{constructor(e,o){i(this,"graph");i(this,"viewport");i(this,"element",null);i(this,"prevTouches",null);i(this,"window",window);i(this,"wheelFinishTimer",null);i(this,"onMouseDown",e=>{this.element===null||!this.options.mouseDownEventVerifier(e)||(W(this.element,this.options.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove),this.window.addEventListener("mouseup",this.onWindowMouseUp),this.options.onTransformStarted())});i(this,"onWindowMouseMove",e=>{if(this.element===null||!R(this.element,e.clientX,e.clientY)||!I(this.window,e.clientX,e.clientY)){this.stopMouseDrag();return}const o=-e.movementX,r=-e.movementY;this.moveViewport(this.element,o,r)});i(this,"onWindowMouseUp",e=>{this.element===null||!this.options.mouseUpEventVerifier(e)||this.stopMouseDrag()});i(this,"onWheelScroll",e=>{if(!this.options.mouseWheelEventVerifier(e))return;e.preventDefault();const{left:o,top:r}=this.element.getBoundingClientRect(),n=e.clientX-o,h=e.clientY-r,d=1/(e.deltaY<0?this.options.wheelSensitivity:1/this.options.wheelSensitivity);this.wheelFinishTimer===null&&this.options.onTransformStarted(),this.scaleViewport(this.element,d,n,h),this.wheelFinishTimer!==null&&clearTimeout(this.wheelFinishTimer),this.wheelFinishTimer=setTimeout(()=>{this.options.onTransformFinished(),this.wheelFinishTimer=null},this.options.scaleWheelFinishTimeout)});i(this,"onTouchStart",e=>{if(this.prevTouches!==null){this.prevTouches=F(e);return}this.prevTouches=F(e),this.window.addEventListener("touchmove",this.onWindowTouchMove),this.window.addEventListener("touchend",this.onWindowTouchFinish),this.window.addEventListener("touchcancel",this.onWindowTouchFinish),this.options.onTransformStarted()});i(this,"onWindowTouchMove",e=>{const o=this.element;if(o===null)return;const r=F(e);if(!r.touches.every(h=>R(o,h[0],h[1])&&I(this.window,h[0],h[1]))){this.stopTouchDrag();return}if((r.touchesCnt===1||r.touchesCnt===2)&&this.moveViewport(o,-(r.x-this.prevTouches.x),-(r.y-this.prevTouches.y)),r.touchesCnt===2){const{left:h,top:s}=o.getBoundingClientRect(),d=this.prevTouches.x-h,c=this.prevTouches.y-s,l=1/(r.scale/this.prevTouches.scale);this.scaleViewport(o,l,d,c)}this.prevTouches=r});i(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=F(e):this.stopTouchDrag()});i(this,"observer",new ResizeObserver(()=>{const e=this.canvas.viewport.getViewportMatrix(),{width:o,height:r}=this.element.getBoundingClientRect(),n=this.options.transformPreprocessor({prevTransform:e,nextTransform:e,canvasWidth:o,canvasHeight:r});this.options.onResizeTransformStarted(),this.canvas.patchViewportMatrix(n),this.options.onResizeTransformFinished()}));i(this,"options");this.canvas=e,this.options=fe(o),this.viewport=this.canvas.viewport,this.graph=this.canvas.graph}attach(e){this.detach(),this.element=e,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown),this.element.addEventListener("wheel",this.onWheelScroll),this.element.addEventListener("touchstart",this.onTouchStart),this.canvas.attach(this.element)}detach(){this.canvas.detach(),this.element!==null&&(this.observer.unobserve(this.element),this.element.removeEventListener("mousedown",this.onMouseDown),this.element.removeEventListener("wheel",this.onWheelScroll),this.element.removeEventListener("touchstart",this.onTouchStart),this.element=null)}addNode(e){this.canvas.addNode(e)}updateNode(e,o){this.canvas.updateNode(e,o)}removeNode(e){this.canvas.removeNode(e)}markPort(e){this.canvas.markPort(e)}updatePort(e,o){this.canvas.updatePort(e,o)}unmarkPort(e){this.canvas.unmarkPort(e)}addEdge(e){this.canvas.addEdge(e)}updateEdge(e,o){this.canvas.updateEdge(e,o)}removeEdge(e){this.canvas.removeEdge(e)}patchViewportMatrix(e){this.canvas.patchViewportMatrix(e)}patchContentMatrix(e){this.canvas.patchContentMatrix(e)}clear(){this.canvas.clear()}destroy(){this.detach(),this.removeMouseDragListeners(),this.removeTouchDragListeners(),this.canvas.destroy()}moveViewport(e,o,r){const n=this.viewport.getViewportMatrix(),h=ve(n,o,r),{width:s,height:d}=e.getBoundingClientRect(),c=this.options.transformPreprocessor({prevTransform:n,nextTransform:h,canvasWidth:s,canvasHeight:d});this.performTransform(c)}scaleViewport(e,o,r,n){const h=this.canvas.viewport.getViewportMatrix(),s=ye(h,o,r,n),{width:d,height:c}=e.getBoundingClientRect(),a=this.options.transformPreprocessor({prevTransform:h,nextTransform:s,canvasWidth:d,canvasHeight:c});this.performTransform(a)}stopMouseDrag(){this.element!==null&&W(this.element,null),this.removeMouseDragListeners(),this.options.onTransformFinished()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.options.onTransformFinished()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}performTransform(e){this.options.onBeforeTransformChange(),this.canvas.patchViewportMatrix(e),this.options.onTransformChange()}}class xe{constructor(e,o,r,n){i(this,"graph");i(this,"viewport");i(this,"canvas");i(this,"element",null);i(this,"canvasResizeObserver");i(this,"window",window);i(this,"nodeHorizontal");i(this,"nodeVertical");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}});var c,a;this.trigger=o,this.virtualScrollOptions=n,this.nodeHorizontal=this.virtualScrollOptions.nodeContainingRadius.horizontal,this.nodeVertical=this.virtualScrollOptions.nodeContainingRadius.vertical,this.canvasResizeObserver=new this.window.ResizeObserver(l=>{const g=l[0];this.viewportWidth=g.contentRect.width,this.viewportHeight=g.contentRect.height,this.scheduleLoadAreaAroundViewport()});const h=((c=r==null?void 0:r.events)==null?void 0:c.onTransformFinished)??(()=>{}),s=((a=r==null?void 0:r.events)==null?void 0:a.onTransformChange)??(()=>{}),d={...r,events:{...r==null?void 0:r.events,onTransformChange:()=>{const l=this.viewportMatrix;this.viewportMatrix=this.canvas.viewport.getViewportMatrix(),l.scale!==this.viewportMatrix.scale&&this.scheduleEnsureViewportAreaLoaded(),s()},onTransformFinished:()=>{this.scheduleLoadAreaAroundViewport(),h()}}};this.canvas=new Z(e,d),this.viewportMatrix=this.canvas.viewport.getViewportMatrix(),this.viewport=this.canvas.viewport,this.graph=this.canvas.graph,this.trigger.subscribe(this.updateLoadedArea)}attach(e){this.detach(),this.element=e,this.canvasResizeObserver.observe(this.element),this.canvas.attach(e)}detach(){this.element!==null&&(this.canvasResizeObserver.unobserve(this.element),this.element=null,this.viewportWidth=0,this.viewportHeight=0),this.canvas.detach()}addNode(e){this.canvas.addNode(e)}updateNode(e,o){this.canvas.updateNode(e,o)}removeNode(e){this.canvas.removeNode(e)}markPort(e){this.canvas.markPort(e)}updatePort(e,o){this.canvas.updatePort(e,o)}unmarkPort(e){this.canvas.unmarkPort(e)}addEdge(e){this.canvas.addEdge(e)}updateEdge(e,o){this.canvas.updateEdge(e,o)}removeEdge(e){this.canvas.removeEdge(e)}patchViewportMatrix(e){this.canvas.patchViewportMatrix(e),this.viewportMatrix=this.canvas.viewport.getViewportMatrix(),this.loadAreaAroundViewport()}patchContentMatrix(e){this.canvas.patchContentMatrix(e),this.viewportMatrix=this.canvas.viewport.getViewportMatrix(),this.loadAreaAroundViewport()}clear(){this.canvas.clear()}destroy(){this.trigger.unsubscribe(this.updateLoadedArea),this.canvas.destroy()}scheduleLoadAreaAroundViewport(){setTimeout(()=>{this.loadAreaAroundViewport()})}scheduleEnsureViewportAreaLoaded(){const e=this.viewportWidth*this.viewportMatrix.scale,o=this.viewportHeight*this.viewportMatrix.scale,r=this.viewportMatrix.x-this.nodeHorizontal,n=this.viewportMatrix.y-this.nodeVertical,h=this.viewportMatrix.x+e+this.nodeHorizontal,s=this.viewportMatrix.y+o+this.nodeVertical;this.loadedArea.xFrom<r&&this.loadedArea.xTo>h&&this.loadedArea.yFrom<n&&this.loadedArea.yTo>s||this.scheduleLoadAreaAroundViewport()}loadAreaAroundViewport(){const e=this.viewportWidth*this.viewportMatrix.scale,o=this.viewportHeight*this.viewportMatrix.scale,r=this.viewportMatrix.x-e-this.nodeHorizontal,n=this.viewportMatrix.y-o-this.nodeVertical,h=3*e+2*this.nodeHorizontal,s=3*o+2*this.nodeVertical;this.trigger.emit({x:r,y:n,width:h,height:s})}}const Ae=()=>{const t=document.createElement("div");return t.style.width="100%",t.style.height="100%",t.style.position="relative",t.style.overflow="hidden",t},Ee=()=>{const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="0",t.style.height="0",t},pe=()=>{const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.visibility="hidden",t};class Se{constructor(e,o){i(this,"canvasWrapper",null);i(this,"host",Ae());i(this,"container",Ee());i(this,"nodeIdToWrapperElementMap",new Map);i(this,"edgeIdToElementMap",new Map);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=o,this.host.appendChild(this.container),this.viewportStore.onAfterUpdated.subscribe(this.applyTransform)}attach(e){this.detach(),this.canvasWrapper=e,this.canvasWrapper.appendChild(this.host),this.graphStore.getAllEdgeIds().forEach(o=>{this.renderEdge(o)})}detach(){this.canvasWrapper!==null&&(this.canvasWrapper.removeChild(this.host),this.canvasWrapper=null)}attachNode(e){const o=this.graphStore.getNode(e),r=pe();r.appendChild(o.element),this.container.appendChild(r),this.nodeIdToWrapperElementMap.set(e,r),this.updateNodePosition(e),this.updateNodePriority(e),r.style.visibility="visible"}detachNode(e){const o=this.nodeIdToWrapperElementMap.get(e);o.removeChild(o.firstChild),this.container.removeChild(o),this.nodeIdToWrapperElementMap.delete(e)}attachEdge(e){const o=this.graphStore.getEdge(e).shape.svg;this.edgeIdToElementMap.set(e,o),this.container.appendChild(o),this.renderEdge(e),this.updateEdgePriority(e)}detachEdge(e){const o=this.edgeIdToElementMap.get(e);this.container.removeChild(o),this.edgeIdToElementMap.delete(e)}clear(){this.edgeIdToElementMap.forEach((e,o)=>{this.detachEdge(o)}),this.nodeIdToWrapperElementMap.forEach((e,o)=>{this.detachNode(o)})}destroy(){this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform),this.clear(),this.detach(),this.host.removeChild(this.container)}updateNodePosition(e){const o=this.nodeIdToWrapperElementMap.get(e),r=this.graphStore.getNode(e),{width:n,height:h}=r.element.getBoundingClientRect(),s=this.viewportStore.getViewportMatrix().scale,d=r.centerFn(n,h),c=r.x-s*d.x,a=r.y-s*d.y;o.style.transform=`translate(${c}px, ${a}px)`}updateNodePriority(e){const o=this.graphStore.getNode(e),r=this.nodeIdToWrapperElementMap.get(e);r.style.zIndex=`${o.priority}`}updateEdgeShape(e){const o=this.edgeIdToElementMap.get(e);this.container.removeChild(o);const r=this.graphStore.getEdge(e);this.edgeIdToElementMap.set(e,r.shape.svg),this.container.appendChild(r.shape.svg)}renderEdge(e){const o=this.graphStore.getEdge(e),r=this.graphStore.getPort(o.from),n=this.graphStore.getPort(o.to),h=r.element.getBoundingClientRect(),s=n.element.getBoundingClientRect(),d=this.host.getBoundingClientRect(),c=this.viewportStore.getViewportMatrix(),a={x:c.scale*(h.left-d.left)+c.x,y:c.scale*(h.top-d.top)+c.y},l={x:c.scale*(s.left-d.left)+c.x,y:c.scale*(s.top-d.top)+c.y},g={x:a.x,y:a.y,width:h.width*c.scale,height:h.height*c.scale,direction:r.direction,portId:o.from,nodeId:r.nodeId},f={x:l.x,y:l.y,width:s.width*c.scale,height:s.height*c.scale,direction:n.direction,portId:o.to,nodeId:n.nodeId};o.shape.render({from:g,to:f})}updateEdgePriority(e){const o=this.graphStore.getEdge(e);o.shape.svg.style.zIndex=`${o.priority}`}}class Ne{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 o=this.graphStore.getNode(e);return o.x>=this.xFrom&&o.x<=this.xTo&&o.y>=this.yFrom&&o.y<=this.yTo}hasEdge(e){const o=this.graphStore.getEdge(e),r=this.graphStore.getPort(o.from).nodeId,n=this.graphStore.getPort(o.to).nodeId,h=this.graphStore.getNode(r),s=this.graphStore.getNode(n),d=Math.min(h.x,s.x),c=Math.max(h.x,s.x),a=Math.min(h.y,s.y),l=Math.max(h.y,s.y);return d<=this.xTo&&c>=this.xFrom&&a<=this.yTo&&l>=this.yFrom}}class me{constructor(e,o,r){i(this,"attachedNodes",new Set);i(this,"attachedEdges",new Set);i(this,"renderingBox");i(this,"updateViewport",e=>{this.renderingBox.setRenderingBox(e);const o=new Set,r=new Set,n=new Set,h=new Set;this.graphStore.getAllNodeIds().forEach(s=>{const d=this.renderingBox.hasNode(s),c=this.attachedNodes.has(s);d&&!c?o.add(s):!d&&c&&r.add(s)}),this.graphStore.getAllEdgeIds().forEach(s=>{const d=this.renderingBox.hasEdge(s),c=this.attachedEdges.has(s),a=this.graphStore.getEdge(s),l=this.graphStore.getPort(a.from).nodeId,g=this.graphStore.getPort(a.to).nodeId;d&&(this.renderingBox.hasNode(l)||(o.add(l),r.delete(l)),this.renderingBox.hasNode(g)||(o.add(g),r.delete(g))),d&&!c?n.add(s):!d&&c&&h.add(s)}),h.forEach(s=>{this.handleDetachEdge(s)}),r.forEach(s=>{this.handleDetachNode(s)}),o.forEach(s=>{this.attachedNodes.has(s)||this.handleAttachNode(s)}),n.forEach(s=>{this.handleAttachEdge(s)})});this.htmlView=e,this.graphStore=o,this.trigger=r,this.renderingBox=new Ne(this.graphStore),this.trigger.subscribe(this.updateViewport)}attach(e){this.htmlView.attach(e)}detach(){this.htmlView.detach()}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(o=>{this.attachEdgeEntities(o)}))}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 o=this.graphStore.getEdge(e),r=this.graphStore.getPort(o.from).nodeId,n=this.graphStore.getPort(o.to).nodeId;this.attachedNodes.has(r)||this.handleAttachNode(r),this.attachedNodes.has(n)||this.handleAttachNode(n),this.handleAttachEdge(e)}handleAttachNode(e){this.attachedNodes.add(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.attachedNodes.delete(e)}handleAttachEdge(e){this.attachedEdges.add(e),this.htmlView.attachEdge(e)}handleDetachEdge(e){this.htmlView.detachEdge(e),this.attachedEdges.delete(e)}}class X{constructor(){i(this,"callbacks",new Set)}subscribe(e){this.callbacks.add(e)}unsubscribe(e){this.callbacks.delete(e)}emit(e){this.callbacks.forEach(o=>{o(e)})}}const E=()=>{const t=new X;return[t,t]};class H{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 S extends Error{constructor(){super(...arguments);i(this,"name","HtmlGraphError")}}const Te=(t,e)=>({x:t/2,y:e/2}),j=t=>()=>t,O=j(0),be=()=>{let t=0;return()=>t++},Pe=(t,e)=>{let o=O,r=O;const n=be();return t==="incremental"&&(o=n),e==="incremental"&&(r=n),typeof t=="number"&&(o=j(t)),typeof e=="number"&&(r=j(e)),typeof t=="function"&&(o=t),typeof e=="function"&&(r=e),{nodesPriorityFn:o,edgesPriorityFn:r}},y=(t,e,o)=>({x:e.x*t.x-e.y*t.y+((1-e.x)*o.x+e.y*o.y),y:e.y*t.x+e.x*t.y+((1-e.x)*o.y-e.y*o.x)}),b=(t,e,o)=>({x:e*Math.cos(t),y:o*Math.sin(t)}),u={x:0,y:0},P=(t,e,o,r)=>{const h=[u,{x:o,y:r},{x:o,y:-r}].map(a=>y(a,t,u)).map(a=>({x:a.x+e.x,y:a.y+e.y})),s=`M ${h[0].x} ${h[0].y}`,d=`L ${h[1].x} ${h[1].y}`,c=`L ${h[2].x} ${h[2].y}`;return`${s} ${d} ${c}`},D=(t,e)=>{const o=[];if(t.length>0&&o.push(`M ${t[0].x} ${t[0].y}`),t.length===2&&o.push(`L ${t[1].x} ${t[1].y}`),t.length>2){const r=t.length-1;let n=0,h=0,s=0;t.forEach((d,c)=>{let a=0,l=0,g=0;const f=c>0,x=c<r,v=f&&x;if(f&&(a=-n,l=-h,g=s),x){const $=t[c+1];n=$.x-d.x,h=$.y-d.y,s=Math.sqrt(n*n+h*h)}const N=s!==0?Math.min((v?e:0)/s,c<r-1?.5:1):0,T=v?{x:d.x+n*N,y:d.y+h*N}:d,C=g!==0?Math.min((v?e:0)/g,c>1?.5:1):0,U=v?{x:d.x+a*C,y:d.y+l*C}:d;c>0&&o.push(`L ${U.x} ${U.y}`),v&&o.push(`C ${d.x} ${d.y} ${d.x} ${d.y} ${T.x} ${T.y}`)})}return o.join(" ")},B=()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.style.pointerEvents="none",t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.overflow="visible",t},z=()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.style.transformOrigin="50% 50%",t},k=(t,e)=>{const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("stroke",t),o.setAttribute("stroke-width",`${e}`),o.setAttribute("fill","none"),o},M=t=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("fill",t),e},Y=(t,e)=>{const o={x:t.x+t.width/2,y:t.y+t.height/2},r={x:e.x+e.width/2,y:e.y+e.height/2},n=Math.min(o.x,r.x),h=Math.min(o.y,r.y),s=Math.abs(r.x-o.x),d=Math.abs(r.y-o.y),c=o.x<=r.x?1:-1,a=o.y<=r.y?1:-1;return{x:n,y:h,width:s,height:d,flipX:c,flipY:a}},Me=t=>{const e=y({x:t.arrowLength,y:u.y},t.fromVect,u),o=y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to),r={x:e.x+t.fromVect.x*t.curvature,y:e.y+t.fromVect.y*t.curvature},n={x:o.x-t.toVect.x*t.curvature,y:o.y-t.toVect.y*t.curvature},h=`M ${e.x} ${e.y} C ${r.x} ${r.y}, ${n.x} ${n.y}, ${o.x} ${o.y}`,s=t.hasSourceArrow?"":`M ${u.x} ${u.y} L ${e.x} ${e.y} `,d=t.hasTargetArrow?"":` M ${o.x} ${o.y} L ${t.to.x} ${t.to.y}`;return`${s}${h}${d}`},Ve=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength,n=Math.cos(t.detourDirection)*t.detourDistance,h=Math.sin(t.detourDirection)*t.detourDistance,s=n*t.flipX,d=h*t.flipY,c=y({x:r,y:u.y},t.fromVect,u),a={x:c.x+s,y:c.y+d},l=y({x:t.to.x-r,y:t.to.y},t.toVect,t.to),g={x:l.x+s,y:l.y+d},f={x:(a.x+g.x)/2,y:(a.y+g.y)/2},x={x:c.x+t.curvature*t.fromVect.x,y:c.y+t.curvature*t.fromVect.y},v={x:l.x-t.curvature*t.toVect.x,y:l.y-t.curvature*t.toVect.y},m={x:c.x+s,y:c.y+d},N={x:l.x+s,y:l.y+d};return[`M ${e.x} ${e.y}`,`L ${c.x} ${c.y}`,`C ${x.x} ${x.y} ${m.x} ${m.y} ${f.x} ${f.y}`,`C ${N.x} ${N.y} ${v.x} ${v.y} ${l.x} ${l.y}`,`L ${o.x} ${o.y}`].join(" ")},Le=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength+t.arrowOffset,n=r-t.roundness,h=y({x:n,y:u.y},t.fromVect,u),s=y({x:t.to.x-n,y:t.to.y},t.toVect,t.to),d=Math.max((h.x+s.x)/2,r),c=t.to.y/2,a={x:t.flipX>0?d:-r,y:h.y},l={x:a.x,y:c},g={x:t.flipX>0?t.to.x-d:t.to.x+r,y:s.y},f={x:g.x,y:c};return D([e,h,a,l,f,g,s,o],t.roundness)},G=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength+t.arrowOffset,n=y({x:r,y:u.y},t.fromVect,u),h=Math.cos(t.detourDirection)*t.detourDistance,s=Math.sin(t.detourDirection)*t.detourDistance,d=h*t.flipX,c=s*t.flipY,a={x:n.x+d,y:n.y+c},l=y({x:t.to.x-r,y:t.to.y},t.toVect,t.to),g={x:l.x+d,y:l.y+c};return D([e,n,a,g,l,o],t.roundness)},De=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength+t.arrowOffset,n=y({x:r,y:u.y},t.fromVect,u),h=y({x:t.to.x-r,y:t.to.y},t.toVect,t.to);return D([e,n,h,o],t.roundness)},Ce=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength+t.arrowOffset,n=r-t.roundness,h=y({x:n,y:u.y},t.fromVect,u),s=y({x:t.to.x-n,y:t.to.y},t.toVect,t.to),d=Math.max((h.y+s.y)/2,r),c=t.to.x/2,a={x:h.x,y:t.flipY>0?d:-r},l={x:c,y:a.y},g={x:s.x,y:t.flipY>0?t.to.y-d:t.to.y+r},f={x:c,y:g.y};return D([e,h,a,l,f,g,s,o],t.roundness)},_=t=>{const e=t.arrowOffset,o=t.side,r=t.arrowLength+e,n=r+2*o,s=[{x:t.arrowLength,y:u.y},{x:r,y:u.y},{x:r,y:t.side},{x:n,y:t.side},{x:n,y:-t.side},{x:r,y:-t.side},{x:r,y:u.y},{x:t.arrowLength,y:u.y}].map(c=>y(c,t.fromVect,u)),d=`M ${u.x} ${u.y} L ${s[0].x} ${s[0].y} `;return`${t.hasSourceArrow||t.hasTargetArrow?"":d}${D(s,t.roundness)}`},Ue=t=>{const e=t.smallRadius,o=t.radius,r=Math.sqrt(e*e+o*o),n=e+o,h=t.arrowLength+r*(1-o/n),s=e*o/n,c=[{x:t.arrowLength,y:u.y},{x:h,y:s},{x:h,y:-s}].map(g=>y(g,t.fromVect,u)),a=[`M ${c[0].x} ${c[0].y}`,`A ${e} ${e} 0 0 1 ${c[1].x} ${c[1].y}`,`A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,`A ${e} ${e} 0 0 1 ${c[0].x} ${c[0].y}`].join(" "),l=`M 0 0 L ${c[0].x} ${c[0].y} `;return`${t.hasSourceArrow||t.hasTargetArrow?"":l}${a}`},w=Object.freeze({color:"#777777",width:1,arrowLength:15,arrowWidth:4,arrowOffset:15,hasSourceArrow:!1,hasTargetArrow:!1,cycleRadius:30,cycleSquareSide:30,roundness:10,detourDistance:100,detourDirection:-Math.PI/2,detourDirectionVertical:0,smallCycleRadius:15,curvature:90});class q{constructor(e){i(this,"svg",B());i(this,"group",z());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"arrowLength");i(this,"arrowWidth");i(this,"curvature");i(this,"portCycleRadius");i(this,"portCycleSmallRadius");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");this.arrowLength=(e==null?void 0:e.arrowLength)??w.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??w.arrowWidth,this.curvature=(e==null?void 0:e.curvature)??w.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??w.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??w.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??w.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??w.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??w.hasTargetArrow;const o=(e==null?void 0:e.color)??w.color,r=(e==null?void 0:e.width)??w.width;this.svg.appendChild(this.group),this.line=k(o,r),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=M(o),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=M(o),this.group.appendChild(this.targetArrow))}render(e){const{x:o,y:r,width:n,height:h,flipX:s,flipY:d}=Y(e.from,e.to);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${n}px`,this.svg.style.height=`${h}px`,this.group.style.transform=`scale(${s}, ${d})`;const c=b(e.from.direction,s,d),a=b(e.to.direction,s,d),l={x:n,y:h};let g,f=a,x=-this.arrowLength;if(e.from.portId===e.to.portId?(g=Ue({fromVect:c,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,x=this.arrowLength):e.from.nodeId===e.to.nodeId?g=Ve({to:l,fromVect:c,toVect:a,flipX:s,flipY:d,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=Me({to:l,fromVect:c,toVect:a,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=P(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=P(f,l,x,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class ee{constructor(e){i(this,"svg",B());i(this,"group",z());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"arrowLength");i(this,"arrowWidth");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");this.arrowLength=(e==null?void 0:e.arrowLength)??w.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??w.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??w.cycleSquareSide;const o=(e==null?void 0:e.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??w.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??w.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??w.hasTargetArrow;const r=(e==null?void 0:e.color)??w.color,n=(e==null?void 0:e.width)??w.width;this.svg.appendChild(this.group),this.line=k(r,n),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=M(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=M(r),this.group.appendChild(this.targetArrow))}render(e){const{x:o,y:r,width:n,height:h,flipX:s,flipY:d}=Y(e.from,e.to);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${n}px`,this.svg.style.height=`${h}px`,this.group.style.transform=`scale(${s}, ${d})`;const c=b(e.from.direction,s,d),a=b(e.to.direction,s,d),l={x:n,y:h};let g,f=a,x=-this.arrowLength;if(e.from.portId===e.to.portId?(g=_({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,x=this.arrowLength):e.from.nodeId===e.to.nodeId?g=G({to:l,fromVect:c,toVect:a,flipX:s,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=Le({to:l,fromVect:c,toVect:a,flipX:s,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=P(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=P(f,l,x,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class te{constructor(e){i(this,"svg",B());i(this,"group",z());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"arrowLength");i(this,"arrowWidth");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");this.arrowLength=(e==null?void 0:e.arrowLength)??w.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??w.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??w.cycleSquareSide;const o=(e==null?void 0:e.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??w.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??w.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??w.hasTargetArrow;const r=(e==null?void 0:e.color)??w.color,n=(e==null?void 0:e.width)??w.width;this.svg.appendChild(this.group),this.line=k(r,n),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=M(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=M(r),this.group.appendChild(this.targetArrow))}render(e){const{x:o,y:r,width:n,height:h,flipX:s,flipY:d}=Y(e.from,e.to);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${n}px`,this.svg.style.height=`${h}px`,this.group.style.transform=`scale(${s}, ${d})`;const c=b(e.from.direction,s,d),a=b(e.to.direction,s,d),l={x:n,y:h};let g,f=a,x=-this.arrowLength;if(e.from.portId===e.to.portId?(g=_({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,x=this.arrowLength):e.from.nodeId===e.to.nodeId?g=G({to:l,fromVect:c,toVect:a,flipX:s,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=De({to:l,fromVect:c,toVect:a,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=P(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=P(f,l,x,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class oe{constructor(e){i(this,"svg",B());i(this,"group",z());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"arrowLength");i(this,"arrowWidth");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");this.arrowLength=(e==null?void 0:e.arrowLength)??w.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??w.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??w.cycleSquareSide;const o=(e==null?void 0:e.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??w.detourDirectionVertical,this.detourDistance=(e==null?void 0:e.detourDistance)??w.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??w.hasTargetArrow;const r=(e==null?void 0:e.color)??w.color,n=(e==null?void 0:e.width)??w.width;this.svg.appendChild(this.group),this.line=k(r,n),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=M(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=M(r),this.group.appendChild(this.targetArrow))}render(e){const{x:o,y:r,width:n,height:h,flipX:s,flipY:d}=Y(e.from,e.to);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${n}px`,this.svg.style.height=`${h}px`,this.group.style.transform=`scale(${s}, ${d})`;const c=b(e.from.direction,s,d),a=b(e.to.direction,s,d),l={x:n,y:h};let g,f=a,x=-this.arrowLength;if(e.from.portId===e.to.portId?(g=_({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,x=this.arrowLength):e.from.nodeId===e.to.nodeId?g=G({to:l,fromVect:c,toVect:a,flipX:s,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=Ce({to:l,fromVect:c,toVect:a,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=P(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=P(f,l,x,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}const $e=t=>{if(typeof t=="function")return t;switch(t==null?void 0:t.type){case"straight":return()=>new te({color:t.color,width:t.width,arrowLength:t.arrowLength,arrowWidth:t.arrowWidth,arrowOffset:t.arrowOffset,hasSourceArrow:t.hasSourceArrow,hasTargetArrow:t.hasTargetArrow,cycleSquareSide:t.cycleSquareSide,roundness:t.roundness,detourDistance:t.detourDistance,detourDirection:t.detourDirection});case"horizontal":return()=>new ee({color:t.color,width:t.width,arrowLength:t.arrowLength,arrowWidth:t.arrowWidth,arrowOffset:t.arrowOffset,hasSourceArrow:t.hasSourceArrow,hasTargetArrow:t.hasTargetArrow,cycleSquareSide:t.cycleSquareSide,roundness:t.roundness,detourDistance:t.detourDistance,detourDirection:t.detourDirection});case"vertical":return()=>new oe({color:t.color,width:t.width,arrowLength:t.arrowLength,arrowWidth:t.arrowWidth,arrowOffset:t.arrowOffset,hasSourceArrow:t.hasSourceArrow,hasTargetArrow:t.hasTargetArrow,cycleSquareSide:t.cycleSquareSide,roundness:t.roundness,detourDistance:t.detourDistance,detourDirection:t.detourDirection});default:return()=>new q({color:t.color,width:t.width,arrowLength:t.arrowLength,arrowWidth:t.arrowWidth,hasSourceArrow:t.hasSourceArrow,hasTargetArrow:t.hasTargetArrow,cycleRadius:t.cycleRadius,smallCycleRadius:t.smallCycleRadius,curvature:t.curvature,detourDistance:t.detourDistance,detourDirection:t.detourDirection})}},Re=t=>{var o,r,n,h,s;const e=Pe((o=t==null?void 0:t.nodes)==null?void 0:o.priority,(r=t==null?void 0:t.edges)==null?void 0:r.priority);return{nodes:{centerFn:((n=t==null?void 0:t.nodes)==null?void 0:n.centerFn)??Te,priorityFn:e.nodesPriorityFn},ports:{direction:((h=t==null?void 0:t.ports)==null?void 0:h.direction)??0},edges:{shapeFactory:$e(((s=t==null?void 0:t.edges)==null?void 0:s.shape)??{}),priorityFn:e.edgesPriorityFn}}};class Ie{constructor(e,o){i(this,"nodeIdGenerator",new H(e=>this.graph.getNode(e)!==null));i(this,"portIdGenerator",new H(e=>this.graph.getPort(e)!==null));i(this,"edgeIdGenerator",new H(e=>this.graph.getEdge(e)!==null));i(this,"defaults");i(this,"graph");i(this,"viewport");this.controller=e,this.defaults=Re(o),this.graph=e.graph,this.viewport=e.viewport}attach(e){return this.controller.attach(e),this}detach(){return this.controller.detach(),this}addNode(e){const o=this.nodeIdGenerator.create(e.id);if(this.graph.getNode(o)!==null)throw new S("failed to add node with existing id");if(this.controller.addNode({id:o,element:e.element,x:e.x,y:e.y,centerFn:e.centerFn??this.defaults.nodes.centerFn,priority:e.priority??this.defaults.nodes.priorityFn()}),e.ports!==void 0)for(const r of e.ports)this.markPort({id:r.id,element:r.element,nodeId:o,direction:r.direction});return this}updateNode(e,o){if(this.graph.getNode(e)===null)throw new S("failed to update nonexisting node");return this.controller.updateNode(e,o??{}),this}removeNode(e){if(this.graph.getNode(e)===null)throw new S("failed to remove nonexisting node");return this.controller.removeNode(e),this}markPort(e){const o=this.portIdGenerator.create(e.id);if(this.graph.getPort(o)!==null)throw new S("failed to add port with existing id");if(this.graph.getNode(e.nodeId)===null)throw new S("failed to set port on nonexisting node");return this.controller.markPort({id:o,element:e.element,nodeId:e.nodeId,direction:e.direction??this.defaults.ports.direction}),this}updatePort(e,o){if(this.graph.getPort(e)===null)throw new S("failed to unset nonexisting port");return this.controller.updatePort(e,o??{}),this}unmarkPort(e){if(this.graph.getPort(e)===null)throw new S("failed to unset nonexisting port");return this.controller.unmarkPort(e),this}addEdge(e){const o=this.edgeIdGenerator.create(e.id);if(this.graph.getEdge(o)!==null)throw new S("failed to add edge with existing id");if(this.graph.getPort(e.from)===null)throw new S("failed to add edge from nonexisting port");if(this.graph.getPort(e.to)===null)throw new S("failed to add edge to nonexisting port");return this.controller.addEdge({id:o,from:e.from,to:e.to,shape:e.shape??this.defaults.edges.shapeFactory(),priority:e.priority??this.defaults.edges.priorityFn()}),this}updateEdge(e,o){if(this.graph.getEdge(e)===null)throw new S("failed to update nonexisting edge");return this.controller.updateEdge(e,o??{}),this}removeEdge(e){if(this.graph.getEdge(e)===null)throw new S("failed to remove nonexisting edge");return this.controller.removeEdge(e),this}patchViewportMatrix(e){return this.controller.patchViewportMatrix(e),this}patchContentMatrix(e){return this.controller.patchContentMatrix(e),this}clear(){return this.controller.clear(),this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset(),this}destroy(){this.controller.destroy()}}class We{constructor(){i(this,"nodes",new Map);i(this,"ports",new Map);i(this,"edges",new Map);i(this,"incommingEdges",new Map);i(this,"outcommingEdges",new Map);i(this,"cycleEdges",new Map);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]=E(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=E(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=E(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=E(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=E(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=E(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=E(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=E(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=E(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=E(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=E(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=E(),[this.beforeClearEmitter,this.onBeforeClear]=E()}addNode(e){const o=new Map,r={element:e.element,x:e.x,y:e.y,centerFn:e.centerFn,priority:e.priority,ports:o};this.nodes.set(e.id,r),this.afterNodeAddedEmitter.emit(e.id)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(e){return this.nodes.get(e)}updateNode(e,o){const r=this.nodes.get(e);r.x=o.x??r.x,r.y=o.y??r.y,r.centerFn=o.centerFn??r.centerFn,o.priority!==void 0&&(r.priority=o.priority,this.afterNodePriorityUpdatedEmitter.emit(e)),this.afterNodeUpdatedEmitter.emit(e)}removeNode(e){this.beforeNodeRemovedEmitter.emit(e),this.nodes.delete(e)}addPort(e){this.ports.set(e.id,{element:e.element,direction:e.direction,nodeId:e.nodeId}),this.cycleEdges.set(e.id,new Set),this.incommingEdges.set(e.id,new Set),this.outcommingEdges.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,o){const r=this.ports.get(e);r.direction=o.direction??r.direction,this.afterPortUpdatedEmitter.emit(e)}getAllPortIds(){return Array.from(this.ports.keys())}getNodePortIds(e){const o=this.nodes.get(e);if(o!==void 0)return Array.from(o.ports.keys())}removePort(e){const o=this.ports.get(e).nodeId;this.beforePortRemovedEmitter.emit(e),this.nodes.get(o).ports.delete(e),this.ports.delete(e)}addEdge(e){this.addEdgeInternal(e),this.afterEdgeAddedEmitter.emit(e.id)}updateEdge(e,o){if(o.from!==void 0||o.to!==void 0){const n=this.edges.get(e);this.removeEdgeInternal(e),this.addEdgeInternal({id:e,from:o.from??n.from,to:o.to??n.to,shape:n.shape,priority:n.priority})}const r=this.edges.get(e);o.shape!==void 0&&(r.shape=o.shape,this.afterEdgeShapeUpdatedEmitter.emit(e)),o.priority!==void 0&&(r.priority=o.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.incommingEdges.clear(),this.outcommingEdges.clear(),this.cycleEdges.clear(),this.edges.clear(),this.ports.clear(),this.nodes.clear()}getPortIncomingEdgeIds(e){return Array.from(this.incommingEdges.get(e))}getPortOutcomingEdgeIds(e){return Array.from(this.outcommingEdges.get(e))}getPortCycleEdgeIds(e){return Array.from(this.cycleEdges.get(e))}getPortAdjacentEdgeIds(e){return[...this.getPortIncomingEdgeIds(e),...this.getPortOutcomingEdgeIds(e),...this.getPortCycleEdgeIds(e)]}getNodeIncomingEdgeIds(e){const o=Array.from(this.nodes.get(e).ports.keys());let r=[];return o.forEach(n=>{r=[...r,...this.getPortIncomingEdgeIds(n)]}),r}getNodeOutcomingEdgeIds(e){const o=Array.from(this.nodes.get(e).ports.keys());let r=[];return o.forEach(n=>{r=[...r,...this.getPortOutcomingEdgeIds(n)]}),r}getNodeCycleEdgeIds(e){const o=Array.from(this.nodes.get(e).ports.keys());let r=[];return o.forEach(n=>{r=[...r,...this.getPortCycleEdgeIds(n)]}),r}getNodeAdjacentEdgeIds(e){return[...this.getNodeIncomingEdgeIds(e),...this.getNodeOutcomingEdgeIds(e),...this.getNodeCycleEdgeIds(e)]}addEdgeInternal(e){this.edges.set(e.id,{from:e.from,to:e.to,shape:e.shape,priority:e.priority}),e.from!==e.to?(this.outcommingEdges.get(e.from).add(e.id),this.incommingEdges.get(e.to).add(e.id)):this.cycleEdges.get(e.from).add(e.id)}removeEdgeInternal(e){const o=this.edges.get(e),r=o.from,n=o.to;this.cycleEdges.get(r).delete(e),this.cycleEdges.get(n).delete(e),this.incommingEdges.get(r).delete(e),this.incommingEdges.get(n).delete(e),this.outcommingEdges.get(r).delete(e),this.outcommingEdges.get(n).delete(e),this.edges.delete(e)}}const re=t=>({scale:1/t.scale,x:-t.x/t.scale,y:-t.y/t.scale}),ie={scale:1,x:0,y:0};class Fe{constructor(){i(this,"viewportMatrix",ie);i(this,"contentMatrix",ie);i(this,"afterUpdateEmitter");i(this,"onAfterUpdated");i(this,"beforeUpdateEmitter");i(this,"onBeforeUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=E(),[this.beforeUpdateEmitter,this.onBeforeUpdated]=E()}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(e){this.beforeUpdateEmitter.emit(),this.viewportMatrix={scale:e.scale??this.viewportMatrix.scale,x:e.x??this.viewportMatrix.x,y:e.y??this.viewportMatrix.y},this.contentMatrix=re(this.viewportMatrix),this.afterUpdateEmitter.emit()}patchContentMatrix(e){this.beforeUpdateEmitter.emit(),this.contentMatrix={scale:e.scale??this.contentMatrix.scale,x:e.x??this.contentMatrix.x,y:e.y??this.contentMatrix.y},this.viewportMatrix=re(this.contentMatrix),this.afterUpdateEmitter.emit()}}class J{constructor(e){i(this,"elementToNodeId",new Map);i(this,"nodesResizeObserver");i(this,"onAfterNodeAdded",e=>{const o=this.canvas.graph.getNode(e);this.elementToNodeId.set(o.element,e),this.nodesResizeObserver.observe(o.element)});i(this,"onBeforeNodeRemoved",e=>{const o=this.canvas.graph.getNode(e);this.elementToNodeId.delete(o.element),this.nodesResizeObserver.unobserve(o.element)});i(this,"onBeforeClear",()=>{this.nodesResizeObserver.disconnect(),this.elementToNodeId.clear()});this.canvas=e,this.nodesResizeObserver=new ResizeObserver(o=>{o.forEach(r=>{const n=r.target;this.handleNodeResize(n)})}),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 o=this.elementToNodeId.get(e);this.canvas.updateNode(o),this.canvas.graph.getNodeAdjacentEdgeIds(o).forEach(n=>{this.canvas.updateEdge(n)})}}class Be{constructor(){i(this,"canvasDefaults",{});i(this,"dragOptions");i(this,"transformOptions");i(this,"virtualScrollOptions");i(this,"hasDraggableNode",!1);i(this,"hasTransformableViewport",!1);i(this,"hasResizeReactiveNodes",!1);i(this,"boxRenderingTrigger")}setDefaults(e){return this.canvasDefaults=e,this}setOptions(e){return this.setDefaults(e),this}enableUserDraggableNodes(e){return this.hasDraggableNode=!0,this.dragOptions=e,this}enableUserTransformableViewport(e){return this.hasTransformableViewport=!0,this.transformOptions=e,this}enableResizeReactiveNodes(){return this.hasResizeReactiveNodes=!0,this}enableBoxAreaRendering(e){return this.boxRenderingTrigger=e,this}enableVirtualScroll(e){return this.virtualScrollOptions=e,this}build(){let e=this.boxRenderingTrigger;this.virtualScrollOptions!==void 0&&e===void 0&&(e=new X);const o=new We,r=new Fe;let n=new Se(o,r);e!==void 0&&(n=new me(n,o,e));let h=new ce(o,r,n);this.hasDraggableNode&&(h=new le(h,this.dragOptions)),this.virtualScrollOptions!==void 0?h=new xe(h,e,this.transformOptions,this.virtualScrollOptions):this.hasTransformableViewport&&(h=new Z(h,this.transformOptions));const s=new Ie(h,this.canvasDefaults);return this.hasResizeReactiveNodes&&J.configure(s),this.reset(),s}reset(){this.canvasDefaults={},this.dragOptions=void 0,this.transformOptions=void 0,this.virtualScrollOptions=void 0,this.hasDraggableNode=!1,this.hasTransformableViewport=!1,this.hasResizeReactiveNodes=!1,this.boxRenderingTrigger=void 0}}A.BezierEdgeShape=q,A.CanvasBuilder=Be,A.EventSubject=X,A.HorizontalEdgeShape=ee,A.HtmlGraphError=S,A.StraightEdgeShape=te,A.VerticalEdgeShape=oe,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(A,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(A=typeof globalThis<"u"?globalThis:A||self,S(A.HtmlGraph={}))})(this,function(A){"use strict";var ze=Object.defineProperty;var ke=(A,S,L)=>S in A?ze(A,S,{enumerable:!0,configurable:!0,writable:!0,value:L}):A[S]=L;var i=(A,S,L)=>ke(A,typeof S!="symbol"?S+"":S,L);class S{constructor(e){i(this,"onAfterNodeAdded");i(this,"onAfterNodeCoordinatesUpdated");i(this,"onAfterNodeUpdated");i(this,"onAfterNodePriorityUpdated");i(this,"onBeforeNodeRemoved");i(this,"onAfterPortMarked");i(this,"onAfterPortAdded");i(this,"onAfterPortUpdated");i(this,"onAfterPortDirectionUpdated");i(this,"onBeforePortUnmarked");i(this,"onBeforePortRemoved");i(this,"onAfterEdgeAdded");i(this,"onAfterEdgeShapeUpdated");i(this,"onAfterEdgeUpdated");i(this,"onAfterEdgeAdjacentPortsUpdated");i(this,"onAfterEdgePriorityUpdated");i(this,"onBeforeEdgeRemoved");i(this,"onBeforeClear");this.graphStore=e,this.onAfterNodeAdded=this.graphStore.onAfterNodeAdded,this.onAfterNodeUpdated=this.graphStore.onAfterNodeUpdated,this.onAfterNodeCoordinatesUpdated=this.onAfterNodeUpdated,this.onAfterNodePriorityUpdated=this.graphStore.onAfterNodePriorityUpdated,this.onBeforeNodeRemoved=this.graphStore.onBeforeNodeRemoved,this.onAfterPortMarked=this.graphStore.onAfterPortAdded,this.onAfterPortAdded=this.onAfterPortMarked,this.onAfterPortUpdated=this.graphStore.onAfterPortUpdated,this.onAfterPortDirectionUpdated=this.onAfterPortUpdated,this.onBeforePortUnmarked=this.graphStore.onBeforePortRemoved,this.onBeforePortRemoved=this.onBeforePortUnmarked,this.onAfterEdgeAdded=this.graphStore.onAfterEdgeAdded,this.onAfterEdgeShapeUpdated=this.graphStore.onAfterEdgeShapeUpdated,this.onAfterEdgeUpdated=this.graphStore.onAfterEdgeUpdated,this.onAfterEdgeAdjacentPortsUpdated=this.onAfterEdgeUpdated,this.onAfterEdgePriorityUpdated=this.graphStore.onAfterEdgePriorityUpdated,this.onBeforeEdgeRemoved=this.graphStore.onBeforeEdgeRemoved,this.onBeforeClear=this.graphStore.onBeforeClear}getNode(e){const o=this.graphStore.getNode(e);return o===void 0?null:{element:o.element,x:o.x,y:o.y,centerFn:o.centerFn,priority:o.priority}}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(e){const o=this.graphStore.getPort(e);return o===void 0?null:{element:o.element,direction:o.direction,nodeId:o.nodeId}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(e){return this.graphStore.getNodePortIds(e)??null}getPortNodeId(e){var o;return((o=this.graphStore.getPort(e))==null?void 0:o.nodeId)??null}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(e){const o=this.graphStore.getEdge(e);return o===void 0?null:{from:o.from,to:o.to,priority:o.priority}}getPortIncomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortIncomingEdgeIds(e)}getPortOutcomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortOutcomingEdgeIds(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)}getNodeOutcomingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeOutcomingEdgeIds(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 L{constructor(e){i(this,"onBeforeUpdated");i(this,"onAfterUpdated");this.transformer=e,this.onBeforeUpdated=this.transformer.onBeforeUpdated,this.onAfterUpdated=this.transformer.onAfterUpdated}getViewportMatrix(){return{...this.transformer.getViewportMatrix()}}getContentMatrix(){return{...this.transformer.getContentMatrix()}}}class ce{constructor(e,o,r){i(this,"viewport");i(this,"graph");i(this,"onAfterNodeAdded",e=>{this.htmlView.attachNode(e)});i(this,"onAfterNodeUpdated",e=>{this.htmlView.updateNodePosition(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(r=>{this.htmlView.renderEdge(r)})});i(this,"onAfterNodePriorityUpdated",e=>{this.htmlView.updateNodePriority(e)});i(this,"onBeforeNodeRemoved",e=>{this.graphStore.getNodePortIds(e).forEach(o=>{this.unmarkPort(o)}),this.htmlView.detachNode(e)});i(this,"onAfterPortUpdated",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(r=>{this.htmlView.renderEdge(r)})});i(this,"onBeforePortUnmarked",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(o=>{this.removeEdge(o)})});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.htmlView.clear()});this.graphStore=e,this.viewportStore=o,this.htmlView=r,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.graph=new S(this.graphStore),this.viewport=new L(this.viewportStore)}attach(e){this.htmlView.attach(e)}detach(){this.htmlView.detach()}addNode(e){this.graphStore.addNode(e)}updateNode(e,o){this.graphStore.updateNode(e,o)}removeNode(e){this.graphStore.removeNode(e)}markPort(e){this.graphStore.addPort(e)}updatePort(e,o){this.graphStore.updatePort(e,o)}unmarkPort(e){this.graphStore.removePort(e)}addEdge(e){this.graphStore.addEdge(e)}updateEdge(e,o){this.graphStore.updateEdge(e,o)}removeEdge(e){this.graphStore.removeEdge(e)}patchViewportMatrix(e){this.viewportStore.patchViewportMatrix(e)}patchContentMatrix(e){this.viewportStore.patchContentMatrix(e)}clear(){this.graphStore.clear()}destroy(){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.clear(),this.htmlView.destroy()}}const R=(t,e,o)=>{const{x:r,y:n,width:h,height:s}=t.getBoundingClientRect();return e>=r&&e<=r+h&&o>=n&&o<=n+s},I=(t,e,o)=>e>=0&&e<=t.innerWidth&&o>=0&&o<=t.innerHeight,W=(t,e)=>{e!==null?t.style.cursor=e:t.style.removeProperty("cursor")},ae=t=>{var g,f,x,v,m,N;const e=((g=t==null?void 0:t.events)==null?void 0:g.onNodeDrag)??(()=>{}),o=((f=t==null?void 0:t.events)==null?void 0:f.onBeforeNodeDrag)??(()=>!0),r=((x=t==null?void 0:t.events)==null?void 0:x.onNodeDragFinished)??(()=>{}),n=(t==null?void 0:t.moveOnTop)===!1,h=(v=t==null?void 0:t.mouse)==null?void 0:v.dragCursor,s=h!==void 0?h:"grab",d=(m=t==null?void 0:t.mouse)==null?void 0:m.mouseDownEventVerifier,c=d!==void 0?d:T=>T.button===0,a=(N=t==null?void 0:t.mouse)==null?void 0:N.mouseUpEventVerifier;return{freezePriority:n,dragCursor:s,mouseDownEventVerifier:c,mouseUpEventVerifier:a!==void 0?a:T=>T.button===0,onNodeDrag:e,onBeforeNodeDrag:o,onNodeDragFinished:r}};class le{constructor(e,o){i(this,"graph");i(this,"viewport");i(this,"maxNodePriority",0);i(this,"nodes",new Map);i(this,"grabbedNodeId",null);i(this,"element",null);i(this,"onWindowMouseMove",e=>{if(this.element!==null&&(!R(this.element,e.clientX,e.clientY)||!I(this.window,e.clientX,e.clientY))){this.cancelMouseDrag();return}this.grabbedNodeId!==null&&this.dragNode(this.grabbedNodeId,e.movementX,e.movementY)});i(this,"onWindowMouseUp",e=>{this.options.mouseUpEventVerifier(e)&&this.cancelMouseDrag()});i(this,"onWindowTouchMove",e=>{if(e.touches.length!==1)return;const o=e.touches[0];if(this.element!==null&&(!R(this.element,o.clientX,o.clientY)||!I(this.window,o.clientX,o.clientY))){this.cancelTouchDrag();return}if(this.grabbedNodeId!==null&&this.previousTouchCoords!==null){const r=o.clientX-this.previousTouchCoords.x,n=o.clientY-this.previousTouchCoords.y;this.dragNode(this.grabbedNodeId,r,n),this.previousTouchCoords={x:e.touches[0].clientX,y:e.touches[0].clientY}}});i(this,"onWindowTouchFinish",()=>{this.previousTouchCoords=null,this.cancelTouchDrag()});i(this,"previousTouchCoords",null);i(this,"window",window);i(this,"options");this.canvas=e,this.viewport=this.canvas.viewport,this.graph=this.canvas.graph,this.options=ae(o??{})}attach(e){this.detach(),this.element=e,this.canvas.attach(this.element)}detach(){this.canvas.detach(),this.element!==null&&(this.element=null)}addNode(e){this.canvas.addNode(e),this.updateMaxNodePriority(e.id);const o=n=>{if(this.element===null||!this.options.mouseDownEventVerifier(n))return;const h=this.graph.getNode(e.id);this.options.onBeforeNodeDrag({nodeId:e.id,element:e.element,x:h.x,y:h.y})&&(n.stopImmediatePropagation(),this.grabbedNodeId=e.id,W(this.element,this.options.dragCursor),this.moveNodeOnTop(e.id),this.window.addEventListener("mouseup",this.onWindowMouseUp),this.window.addEventListener("mousemove",this.onWindowMouseMove))},r=n=>{if(n.touches.length!==1)return;n.stopImmediatePropagation(),this.previousTouchCoords={x:n.touches[0].clientX,y:n.touches[0].clientY};const h=this.graph.getNode(e.id);this.options.onBeforeNodeDrag({nodeId:e.id,element:e.element,x:h.x,y:h.y})&&(this.grabbedNodeId=e.id,this.moveNodeOnTop(e.id),this.window.addEventListener("touchmove",this.onWindowTouchMove),this.window.addEventListener("touchend",this.onWindowTouchFinish),this.window.addEventListener("touchcancel",this.onWindowTouchFinish))};this.nodes.set(e.id,{element:e.element,onMouseDown:o,onTouchStart:r}),e.element.addEventListener("mousedown",o),e.element.addEventListener("touchstart",r)}updateNode(e,o){this.canvas.updateNode(e,o),this.updateMaxNodePriority(e)}removeNode(e){const o=this.nodes.get(e);o!==void 0&&(o.element.removeEventListener("mousedown",o.onMouseDown),o.element.removeEventListener("touchstart",o.onTouchStart)),this.nodes.delete(e),this.canvas.removeNode(e)}markPort(e){this.canvas.markPort(e)}updatePort(e,o){this.canvas.updatePort(e,o)}unmarkPort(e){this.canvas.unmarkPort(e)}addEdge(e){this.canvas.addEdge(e)}updateEdge(e,o){this.canvas.updateEdge(e,o)}removeEdge(e){this.canvas.removeEdge(e)}patchViewportMatrix(e){this.canvas.patchViewportMatrix(e)}patchContentMatrix(e){this.canvas.patchContentMatrix(e)}clear(){this.canvas.clear(),this.nodes.forEach(e=>{e.element.removeEventListener("mousedown",e.onMouseDown),e.element.removeEventListener("touchstart",e.onTouchStart)}),this.nodes.clear(),this.maxNodePriority=0}destroy(){this.detach(),this.clear(),this.removeMouseDragListeners(),this.removeTouchDragListeners(),this.canvas.destroy()}dragNode(e,o,r){const n=this.graph.getNode(e);if(n===null)return;const h=this.canvas.viewport.getContentMatrix(),s=h.scale*n.x+h.x,d=h.scale*n.y+h.y,c=s+o,a=d+r,l=this.canvas.viewport.getViewportMatrix(),g=l.scale*c+l.x,f=l.scale*a+l.y;this.canvas.updateNode(e,{x:g,y:f}),this.options.onNodeDrag({nodeId:e,element:n.element,x:g,y:f})}updateMaxNodePriority(e){const o=this.graph.getNode(e).priority;this.maxNodePriority=Math.max(this.maxNodePriority,o)}moveNodeOnTop(e){if(this.options.freezePriority)return;this.maxNodePriority+=2,this.updateNode(e,{priority:this.maxNodePriority});const o=this.maxNodePriority-1;this.graph.getNodeAdjacentEdgeIds(e).forEach(n=>{this.updateEdge(n,{priority:o})})}cancelMouseDrag(){const e=this.graph.getNode(this.grabbedNodeId);e!==null&&this.options.onNodeDragFinished({nodeId:this.grabbedNodeId,element:e.element,x:e.x,y:e.y}),this.grabbedNodeId=null,this.element!==null&&W(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){this.previousTouchCoords=null;const e=this.graph.getNode(this.grabbedNodeId);e!==null&&this.options.onNodeDragFinished({nodeId:this.grabbedNodeId,element:e.element,x:e.x,y:e.y}),this.grabbedNodeId=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}const ge=t=>{const e=t.minX!==null?t.minX:-1/0,o=t.maxX!==null?t.maxX:1/0,r=t.minY!==null?t.minY:-1/0,n=t.maxY!==null?t.maxY:1/0;return h=>{let s=h.nextTransform.x,d=h.nextTransform.y;s<e&&s<h.prevTransform.x&&(s=Math.min(h.prevTransform.x,e));const c=h.canvasWidth*h.prevTransform.scale,a=o-c;s>a&&s>h.prevTransform.x&&(s=Math.max(h.prevTransform.x,a)),d<r&&d<h.prevTransform.y&&(d=Math.min(h.prevTransform.y,r));const l=h.canvasHeight*h.prevTransform.scale,g=n-l;return d>g&&d>h.prevTransform.y&&(d=Math.max(h.prevTransform.y,g)),{scale:h.nextTransform.scale,x:s,y:d}}},ue=t=>{const e=t.maxContentScale,o=t.minContentScale,r=e!==null?1/e:0,n=o!==null?1/o:1/0;return h=>{const s=h.prevTransform,d=h.nextTransform;let c=d.scale,a=d.x,l=d.y;if(d.scale>n&&d.scale>s.scale){c=Math.max(s.scale,n),a=s.x,l=s.y;const g=(c-s.scale)/(d.scale-s.scale);a=s.x+(d.x-s.x)*g,l=s.y+(d.y-s.y)*g}if(d.scale<r&&d.scale<s.scale){c=Math.min(s.scale,r),a=s.x,l=s.y;const g=(c-s.scale)/(d.scale-s.scale);a=s.x+(d.x-s.x)*g,l=s.y+(d.y-s.y)*g}return{scale:c,x:a,y:l}}},we=t=>e=>t.reduce((o,r)=>r({prevTransform:e.prevTransform,nextTransform:o,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),Q=t=>{if(typeof t=="function")return t;switch(t.type){case"scale-limit":return ue({minContentScale:t.minContentScale??0,maxContentScale:t.maxContentScale??1/0});case"shift-limit":return ge({minX:t.minX??-1/0,maxX:t.maxX??1/0,minY:t.minY??-1/0,maxY:t.maxY??1/0})}},fe=t=>{var v,m,N,T,K,C,U,$,se,ne,he,de;const e=(v=t==null?void 0:t.scale)==null?void 0:v.mouseWheelSensitivity,o=e!==void 0?e:1.2,r=t==null?void 0:t.transformPreprocessor;let n;r!==void 0?Array.isArray(r)?n=we(r.map(V=>Q(V))):n=Q(r):n=V=>V.nextTransform;const h=((m=t==null?void 0:t.shift)==null?void 0:m.cursor)!==void 0?t.shift.cursor:"grab",s=((N=t==null?void 0:t.events)==null?void 0:N.onBeforeTransformChange)??(()=>{}),d=((T=t==null?void 0:t.events)==null?void 0:T.onTransformChange)??(()=>{}),c=(K=t==null?void 0:t.shift)==null?void 0:K.mouseDownEventVerifier,a=c!==void 0?c:V=>V.button===0,l=(C=t==null?void 0:t.shift)==null?void 0:C.mouseUpEventVerifier,g=l!==void 0?l:V=>V.button===0,f=(U=t==null?void 0:t.scale)==null?void 0:U.mouseWheelEventVerifier,x=f!==void 0?f:()=>!0;return{wheelSensitivity:o,onTransformStarted:(($=t==null?void 0:t.events)==null?void 0:$.onTransformStarted)??(()=>{}),onTransformFinished:((se=t==null?void 0:t.events)==null?void 0:se.onTransformFinished)??(()=>{}),onBeforeTransformChange:s,onTransformChange:d,transformPreprocessor:n,shiftCursor:h,mouseDownEventVerifier:a,mouseUpEventVerifier:g,mouseWheelEventVerifier:x,scaleWheelFinishTimeout:((ne=t==null?void 0:t.scale)==null?void 0:ne.wheelFinishTimeout)??500,onResizeTransformStarted:((he=t==null?void 0:t.events)==null?void 0:he.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((de=t==null?void 0:t.events)==null?void 0:de.onResizeTransformFinished)??(()=>{})}},F=t=>{const e=[],o=t.touches.length;for(let d=0;d<o;d++)e.push([t.touches[d].clientX,t.touches[d].clientY]);const r=e.reduce((d,c)=>[d[0]+c[0],d[1]+c[1]],[0,0]),n=[r[0]/o,r[1]/o],s=e.map(d=>[d[0]-n[0],d[1]-n[1]]).reduce((d,c)=>d+Math.sqrt(c[0]*c[0]+c[1]*c[1]),0);return{x:n[0],y:n[1],scale:s/o,touchesCnt:o,touches:e}},ve=(t,e,o)=>({scale:t.scale,x:t.x+t.scale*e,y:t.y+t.scale*o}),ye=(t,e,o,r)=>({scale:t.scale*e,x:t.scale*(1-e)*o+t.x,y:t.scale*(1-e)*r+t.y});class Z{constructor(e,o){i(this,"graph");i(this,"viewport");i(this,"element",null);i(this,"prevTouches",null);i(this,"window",window);i(this,"wheelFinishTimer",null);i(this,"onMouseDown",e=>{this.element===null||!this.options.mouseDownEventVerifier(e)||(W(this.element,this.options.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove),this.window.addEventListener("mouseup",this.onWindowMouseUp),this.options.onTransformStarted())});i(this,"onWindowMouseMove",e=>{if(this.element===null||!R(this.element,e.clientX,e.clientY)||!I(this.window,e.clientX,e.clientY)){this.stopMouseDrag();return}const o=-e.movementX,r=-e.movementY;this.moveViewport(this.element,o,r)});i(this,"onWindowMouseUp",e=>{this.element===null||!this.options.mouseUpEventVerifier(e)||this.stopMouseDrag()});i(this,"onWheelScroll",e=>{if(!this.options.mouseWheelEventVerifier(e))return;e.preventDefault();const{left:o,top:r}=this.element.getBoundingClientRect(),n=e.clientX-o,h=e.clientY-r,d=1/(e.deltaY<0?this.options.wheelSensitivity:1/this.options.wheelSensitivity);this.wheelFinishTimer===null&&this.options.onTransformStarted(),this.scaleViewport(this.element,d,n,h),this.wheelFinishTimer!==null&&clearTimeout(this.wheelFinishTimer),this.wheelFinishTimer=setTimeout(()=>{this.options.onTransformFinished(),this.wheelFinishTimer=null},this.options.scaleWheelFinishTimeout)});i(this,"onTouchStart",e=>{if(this.prevTouches!==null){this.prevTouches=F(e);return}this.prevTouches=F(e),this.window.addEventListener("touchmove",this.onWindowTouchMove),this.window.addEventListener("touchend",this.onWindowTouchFinish),this.window.addEventListener("touchcancel",this.onWindowTouchFinish),this.options.onTransformStarted()});i(this,"onWindowTouchMove",e=>{const o=this.element;if(o===null)return;const r=F(e);if(!r.touches.every(h=>R(o,h[0],h[1])&&I(this.window,h[0],h[1]))){this.stopTouchDrag();return}if((r.touchesCnt===1||r.touchesCnt===2)&&this.moveViewport(o,-(r.x-this.prevTouches.x),-(r.y-this.prevTouches.y)),r.touchesCnt===2){const{left:h,top:s}=o.getBoundingClientRect(),d=this.prevTouches.x-h,c=this.prevTouches.y-s,l=1/(r.scale/this.prevTouches.scale);this.scaleViewport(o,l,d,c)}this.prevTouches=r});i(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=F(e):this.stopTouchDrag()});i(this,"observer",new ResizeObserver(()=>{const e=this.canvas.viewport.getViewportMatrix(),{width:o,height:r}=this.element.getBoundingClientRect(),n=this.options.transformPreprocessor({prevTransform:e,nextTransform:e,canvasWidth:o,canvasHeight:r});this.options.onResizeTransformStarted(),this.canvas.patchViewportMatrix(n),this.options.onResizeTransformFinished()}));i(this,"options");this.canvas=e,this.options=fe(o),this.viewport=this.canvas.viewport,this.graph=this.canvas.graph}attach(e){this.detach(),this.element=e,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown),this.element.addEventListener("wheel",this.onWheelScroll),this.element.addEventListener("touchstart",this.onTouchStart),this.canvas.attach(this.element)}detach(){this.canvas.detach(),this.element!==null&&(this.observer.unobserve(this.element),this.element.removeEventListener("mousedown",this.onMouseDown),this.element.removeEventListener("wheel",this.onWheelScroll),this.element.removeEventListener("touchstart",this.onTouchStart),this.element=null)}addNode(e){this.canvas.addNode(e)}updateNode(e,o){this.canvas.updateNode(e,o)}removeNode(e){this.canvas.removeNode(e)}markPort(e){this.canvas.markPort(e)}updatePort(e,o){this.canvas.updatePort(e,o)}unmarkPort(e){this.canvas.unmarkPort(e)}addEdge(e){this.canvas.addEdge(e)}updateEdge(e,o){this.canvas.updateEdge(e,o)}removeEdge(e){this.canvas.removeEdge(e)}patchViewportMatrix(e){this.canvas.patchViewportMatrix(e)}patchContentMatrix(e){this.canvas.patchContentMatrix(e)}clear(){this.canvas.clear()}destroy(){this.detach(),this.removeMouseDragListeners(),this.removeTouchDragListeners(),this.canvas.destroy()}moveViewport(e,o,r){const n=this.viewport.getViewportMatrix(),h=ve(n,o,r),{width:s,height:d}=e.getBoundingClientRect(),c=this.options.transformPreprocessor({prevTransform:n,nextTransform:h,canvasWidth:s,canvasHeight:d});this.performTransform(c)}scaleViewport(e,o,r,n){const h=this.canvas.viewport.getViewportMatrix(),s=ye(h,o,r,n),{width:d,height:c}=e.getBoundingClientRect(),a=this.options.transformPreprocessor({prevTransform:h,nextTransform:s,canvasWidth:d,canvasHeight:c});this.performTransform(a)}stopMouseDrag(){this.element!==null&&W(this.element,null),this.removeMouseDragListeners(),this.options.onTransformFinished()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.options.onTransformFinished()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}performTransform(e){this.options.onBeforeTransformChange(),this.canvas.patchViewportMatrix(e),this.options.onTransformChange()}}class xe{constructor(e,o,r,n){i(this,"graph");i(this,"viewport");i(this,"canvas");i(this,"element",null);i(this,"canvasResizeObserver");i(this,"window",window);i(this,"nodeHorizontal");i(this,"nodeVertical");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}});var c,a;this.trigger=o,this.virtualScrollOptions=n,this.nodeHorizontal=this.virtualScrollOptions.nodeContainingRadius.horizontal,this.nodeVertical=this.virtualScrollOptions.nodeContainingRadius.vertical,this.canvasResizeObserver=new this.window.ResizeObserver(l=>{const g=l[0];this.viewportWidth=g.contentRect.width,this.viewportHeight=g.contentRect.height,this.scheduleLoadAreaAroundViewport()});const h=((c=r==null?void 0:r.events)==null?void 0:c.onTransformFinished)??(()=>{}),s=((a=r==null?void 0:r.events)==null?void 0:a.onTransformChange)??(()=>{}),d={...r,events:{...r==null?void 0:r.events,onTransformChange:()=>{const l=this.viewportMatrix;this.viewportMatrix=this.canvas.viewport.getViewportMatrix(),l.scale!==this.viewportMatrix.scale&&this.scheduleEnsureViewportAreaLoaded(),s()},onTransformFinished:()=>{this.scheduleLoadAreaAroundViewport(),h()}}};this.canvas=new Z(e,d),this.viewportMatrix=this.canvas.viewport.getViewportMatrix(),this.viewport=this.canvas.viewport,this.graph=this.canvas.graph,this.trigger.subscribe(this.updateLoadedArea)}attach(e){this.detach(),this.element=e,this.canvasResizeObserver.observe(this.element),this.canvas.attach(e)}detach(){this.element!==null&&(this.canvasResizeObserver.unobserve(this.element),this.element=null,this.viewportWidth=0,this.viewportHeight=0),this.canvas.detach()}addNode(e){this.canvas.addNode(e)}updateNode(e,o){this.canvas.updateNode(e,o)}removeNode(e){this.canvas.removeNode(e)}markPort(e){this.canvas.markPort(e)}updatePort(e,o){this.canvas.updatePort(e,o)}unmarkPort(e){this.canvas.unmarkPort(e)}addEdge(e){this.canvas.addEdge(e)}updateEdge(e,o){this.canvas.updateEdge(e,o)}removeEdge(e){this.canvas.removeEdge(e)}patchViewportMatrix(e){this.canvas.patchViewportMatrix(e),this.viewportMatrix=this.canvas.viewport.getViewportMatrix(),this.loadAreaAroundViewport()}patchContentMatrix(e){this.canvas.patchContentMatrix(e),this.viewportMatrix=this.canvas.viewport.getViewportMatrix(),this.loadAreaAroundViewport()}clear(){this.canvas.clear()}destroy(){this.trigger.unsubscribe(this.updateLoadedArea),this.canvas.destroy()}scheduleLoadAreaAroundViewport(){setTimeout(()=>{this.loadAreaAroundViewport()})}scheduleEnsureViewportAreaLoaded(){const e=this.viewportWidth*this.viewportMatrix.scale,o=this.viewportHeight*this.viewportMatrix.scale,r=this.viewportMatrix.x-this.nodeHorizontal,n=this.viewportMatrix.y-this.nodeVertical,h=this.viewportMatrix.x+e+this.nodeHorizontal,s=this.viewportMatrix.y+o+this.nodeVertical;this.loadedArea.xFrom<r&&this.loadedArea.xTo>h&&this.loadedArea.yFrom<n&&this.loadedArea.yTo>s||this.scheduleLoadAreaAroundViewport()}loadAreaAroundViewport(){const e=this.viewportWidth*this.viewportMatrix.scale,o=this.viewportHeight*this.viewportMatrix.scale,r=this.viewportMatrix.x-e-this.nodeHorizontal,n=this.viewportMatrix.y-o-this.nodeVertical,h=3*e+2*this.nodeHorizontal,s=3*o+2*this.nodeVertical;this.trigger.emit({x:r,y:n,width:h,height:s})}}const Ae=()=>{const t=document.createElement("div");return t.style.width="100%",t.style.height="100%",t.style.position="relative",t.style.overflow="hidden",t},Ee=()=>{const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="0",t.style.height="0",t},pe=()=>{const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.visibility="hidden",t};class Se{constructor(e,o){i(this,"canvasWrapper",null);i(this,"host",Ae());i(this,"container",Ee());i(this,"nodeIdToWrapperElementMap",new Map);i(this,"edgeIdToElementMap",new Map);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=o,this.host.appendChild(this.container),this.viewportStore.onAfterUpdated.subscribe(this.applyTransform)}attach(e){this.detach(),this.canvasWrapper=e,this.canvasWrapper.appendChild(this.host),this.graphStore.getAllEdgeIds().forEach(o=>{this.renderEdge(o)})}detach(){this.canvasWrapper!==null&&(this.canvasWrapper.removeChild(this.host),this.canvasWrapper=null)}attachNode(e){const o=this.graphStore.getNode(e),r=pe();r.appendChild(o.element),this.container.appendChild(r),this.nodeIdToWrapperElementMap.set(e,r),this.updateNodePosition(e),this.updateNodePriority(e),r.style.visibility="visible"}detachNode(e){const o=this.nodeIdToWrapperElementMap.get(e);o.removeChild(o.firstChild),this.container.removeChild(o),this.nodeIdToWrapperElementMap.delete(e)}attachEdge(e){const o=this.graphStore.getEdge(e).shape.svg;this.edgeIdToElementMap.set(e,o),this.container.appendChild(o),this.renderEdge(e),this.updateEdgePriority(e)}detachEdge(e){const o=this.edgeIdToElementMap.get(e);this.container.removeChild(o),this.edgeIdToElementMap.delete(e)}clear(){this.edgeIdToElementMap.forEach((e,o)=>{this.detachEdge(o)}),this.nodeIdToWrapperElementMap.forEach((e,o)=>{this.detachNode(o)})}destroy(){this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform),this.clear(),this.detach(),this.host.removeChild(this.container)}updateNodePosition(e){const o=this.nodeIdToWrapperElementMap.get(e),r=this.graphStore.getNode(e),{width:n,height:h}=r.element.getBoundingClientRect(),s=this.viewportStore.getViewportMatrix().scale,d=r.centerFn(n,h),c=r.x-s*d.x,a=r.y-s*d.y;o.style.transform=`translate(${c}px, ${a}px)`}updateNodePriority(e){const o=this.graphStore.getNode(e),r=this.nodeIdToWrapperElementMap.get(e);r.style.zIndex=`${o.priority}`}updateEdgeShape(e){const o=this.edgeIdToElementMap.get(e);this.container.removeChild(o);const r=this.graphStore.getEdge(e);this.edgeIdToElementMap.set(e,r.shape.svg),this.container.appendChild(r.shape.svg)}renderEdge(e){const o=this.graphStore.getEdge(e),r=this.graphStore.getPort(o.from),n=this.graphStore.getPort(o.to),h=r.element.getBoundingClientRect(),s=n.element.getBoundingClientRect(),d=this.host.getBoundingClientRect(),c=this.viewportStore.getViewportMatrix(),a={x:c.scale*(h.left-d.left)+c.x,y:c.scale*(h.top-d.top)+c.y},l={x:c.scale*(s.left-d.left)+c.x,y:c.scale*(s.top-d.top)+c.y},g={x:a.x,y:a.y,width:h.width*c.scale,height:h.height*c.scale,direction:r.direction,portId:o.from,nodeId:r.nodeId},f={x:l.x,y:l.y,width:s.width*c.scale,height:s.height*c.scale,direction:n.direction,portId:o.to,nodeId:n.nodeId};o.shape.render({from:g,to:f})}updateEdgePriority(e){const o=this.graphStore.getEdge(e);o.shape.svg.style.zIndex=`${o.priority}`}}class Ne{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 o=this.graphStore.getNode(e);return o.x>=this.xFrom&&o.x<=this.xTo&&o.y>=this.yFrom&&o.y<=this.yTo}hasEdge(e){const o=this.graphStore.getEdge(e),r=this.graphStore.getPort(o.from).nodeId,n=this.graphStore.getPort(o.to).nodeId,h=this.graphStore.getNode(r),s=this.graphStore.getNode(n),d=Math.min(h.x,s.x),c=Math.max(h.x,s.x),a=Math.min(h.y,s.y),l=Math.max(h.y,s.y);return d<=this.xTo&&c>=this.xFrom&&a<=this.yTo&&l>=this.yFrom}}class me{constructor(e,o,r){i(this,"attachedNodes",new Set);i(this,"attachedEdges",new Set);i(this,"renderingBox");i(this,"updateViewport",e=>{this.renderingBox.setRenderingBox(e);const o=new Set,r=new Set,n=new Set,h=new Set;this.graphStore.getAllNodeIds().forEach(s=>{const d=this.renderingBox.hasNode(s),c=this.attachedNodes.has(s);d&&!c?o.add(s):!d&&c&&r.add(s)}),this.graphStore.getAllEdgeIds().forEach(s=>{const d=this.renderingBox.hasEdge(s),c=this.attachedEdges.has(s),a=this.graphStore.getEdge(s),l=this.graphStore.getPort(a.from).nodeId,g=this.graphStore.getPort(a.to).nodeId;d&&(this.renderingBox.hasNode(l)||(o.add(l),r.delete(l)),this.renderingBox.hasNode(g)||(o.add(g),r.delete(g))),d&&!c?n.add(s):!d&&c&&h.add(s)}),h.forEach(s=>{this.handleDetachEdge(s)}),r.forEach(s=>{this.handleDetachNode(s)}),o.forEach(s=>{this.attachedNodes.has(s)||this.handleAttachNode(s)}),n.forEach(s=>{this.handleAttachEdge(s)})});this.htmlView=e,this.graphStore=o,this.trigger=r,this.renderingBox=new Ne(this.graphStore),this.trigger.subscribe(this.updateViewport)}attach(e){this.htmlView.attach(e)}detach(){this.htmlView.detach()}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(o=>{this.attachEdgeEntities(o)}))}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 o=this.graphStore.getEdge(e),r=this.graphStore.getPort(o.from).nodeId,n=this.graphStore.getPort(o.to).nodeId;this.attachedNodes.has(r)||this.handleAttachNode(r),this.attachedNodes.has(n)||this.handleAttachNode(n),this.handleAttachEdge(e)}handleAttachNode(e){this.attachedNodes.add(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.attachedNodes.delete(e)}handleAttachEdge(e){this.attachedEdges.add(e),this.htmlView.attachEdge(e)}handleDetachEdge(e){this.htmlView.detachEdge(e),this.attachedEdges.delete(e)}}class X{constructor(){i(this,"callbacks",new Set)}subscribe(e){this.callbacks.add(e)}unsubscribe(e){this.callbacks.delete(e)}emit(e){this.callbacks.forEach(o=>{o(e)})}}const E=()=>{const t=new X;return[t,t]};class H{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","HtmlGraphError")}}const Te=(t,e)=>({x:t/2,y:e/2}),j=t=>()=>t,O=j(0),be=()=>{let t=0;return()=>t++},Pe=(t,e)=>{let o=O,r=O;const n=be();return t==="incremental"&&(o=n),e==="incremental"&&(r=n),typeof t=="number"&&(o=j(t)),typeof e=="number"&&(r=j(e)),typeof t=="function"&&(o=t),typeof e=="function"&&(r=e),{nodesPriorityFn:o,edgesPriorityFn:r}},y=(t,e,o)=>({x:e.x*t.x-e.y*t.y+((1-e.x)*o.x+e.y*o.y),y:e.y*t.x+e.x*t.y+((1-e.x)*o.y-e.y*o.x)}),b=(t,e,o)=>({x:e*Math.cos(t),y:o*Math.sin(t)}),u={x:0,y:0},P=(t,e,o,r)=>{const h=[u,{x:o,y:r},{x:o,y:-r}].map(a=>y(a,t,u)).map(a=>({x:a.x+e.x,y:a.y+e.y})),s=`M ${h[0].x} ${h[0].y}`,d=`L ${h[1].x} ${h[1].y}`,c=`L ${h[2].x} ${h[2].y}`;return`${s} ${d} ${c}`},D=(t,e)=>{const o=[];if(t.length>0&&o.push(`M ${t[0].x} ${t[0].y}`),t.length===2&&o.push(`L ${t[1].x} ${t[1].y}`),t.length>2){const r=t.length-1;let n=0,h=0,s=0;t.forEach((d,c)=>{let a=0,l=0,g=0;const f=c>0,x=c<r,v=f&&x;if(f&&(a=-n,l=-h,g=s),x){const $=t[c+1];n=$.x-d.x,h=$.y-d.y,s=Math.sqrt(n*n+h*h)}const N=s!==0?Math.min((v?e:0)/s,c<r-1?.5:1):0,T=v?{x:d.x+n*N,y:d.y+h*N}:d,C=g!==0?Math.min((v?e:0)/g,c>1?.5:1):0,U=v?{x:d.x+a*C,y:d.y+l*C}:d;c>0&&o.push(`L ${U.x} ${U.y}`),v&&o.push(`C ${d.x} ${d.y} ${d.x} ${d.y} ${T.x} ${T.y}`)})}return o.join(" ")},B=()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","svg");return t.style.pointerEvents="none",t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.overflow="visible",t},z=()=>{const t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.style.transformOrigin="50% 50%",t},k=(t,e)=>{const o=document.createElementNS("http://www.w3.org/2000/svg","path");return o.setAttribute("stroke",t),o.setAttribute("stroke-width",`${e}`),o.setAttribute("fill","none"),o},M=t=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("fill",t),e},Y=(t,e)=>{const o={x:t.x+t.width/2,y:t.y+t.height/2},r={x:e.x+e.width/2,y:e.y+e.height/2},n=Math.min(o.x,r.x),h=Math.min(o.y,r.y),s=Math.abs(r.x-o.x),d=Math.abs(r.y-o.y),c=o.x<=r.x?1:-1,a=o.y<=r.y?1:-1;return{x:n,y:h,width:s,height:d,flipX:c,flipY:a}},Me=t=>{const e=y({x:t.arrowLength,y:u.y},t.fromVect,u),o=y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to),r={x:e.x+t.fromVect.x*t.curvature,y:e.y+t.fromVect.y*t.curvature},n={x:o.x-t.toVect.x*t.curvature,y:o.y-t.toVect.y*t.curvature},h=`M ${e.x} ${e.y} C ${r.x} ${r.y}, ${n.x} ${n.y}, ${o.x} ${o.y}`,s=t.hasSourceArrow?"":`M ${u.x} ${u.y} L ${e.x} ${e.y} `,d=t.hasTargetArrow?"":` M ${o.x} ${o.y} L ${t.to.x} ${t.to.y}`;return`${s}${h}${d}`},Ve=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength,n=Math.cos(t.detourDirection)*t.detourDistance,h=Math.sin(t.detourDirection)*t.detourDistance,s=n*t.flipX,d=h*t.flipY,c=y({x:r,y:u.y},t.fromVect,u),a={x:c.x+s,y:c.y+d},l=y({x:t.to.x-r,y:t.to.y},t.toVect,t.to),g={x:l.x+s,y:l.y+d},f={x:(a.x+g.x)/2,y:(a.y+g.y)/2},x={x:c.x+t.curvature*t.fromVect.x,y:c.y+t.curvature*t.fromVect.y},v={x:l.x-t.curvature*t.toVect.x,y:l.y-t.curvature*t.toVect.y},m={x:c.x+s,y:c.y+d},N={x:l.x+s,y:l.y+d};return[`M ${e.x} ${e.y}`,`L ${c.x} ${c.y}`,`C ${x.x} ${x.y} ${m.x} ${m.y} ${f.x} ${f.y}`,`C ${N.x} ${N.y} ${v.x} ${v.y} ${l.x} ${l.y}`,`L ${o.x} ${o.y}`].join(" ")},Le=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength+t.arrowOffset,n=r-t.roundness,h=y({x:n,y:u.y},t.fromVect,u),s=y({x:t.to.x-n,y:t.to.y},t.toVect,t.to),d=Math.max((h.x+s.x)/2,r),c=t.to.y/2,a={x:t.flipX>0?d:-r,y:h.y},l={x:a.x,y:c},g={x:t.flipX>0?t.to.x-d:t.to.x+r,y:s.y},f={x:g.x,y:c};return D([e,h,a,l,f,g,s,o],t.roundness)},G=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength+t.arrowOffset,n=y({x:r,y:u.y},t.fromVect,u),h=Math.cos(t.detourDirection)*t.detourDistance,s=Math.sin(t.detourDirection)*t.detourDistance,d=h*t.flipX,c=s*t.flipY,a={x:n.x+d,y:n.y+c},l=y({x:t.to.x-r,y:t.to.y},t.toVect,t.to),g={x:l.x+d,y:l.y+c};return D([e,n,a,g,l,o],t.roundness)},De=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength+t.arrowOffset,n=y({x:r,y:u.y},t.fromVect,u),h=y({x:t.to.x-r,y:t.to.y},t.toVect,t.to);return D([e,n,h,o],t.roundness)},Ce=t=>{const e=t.hasSourceArrow?y({x:t.arrowLength,y:u.y},t.fromVect,u):u,o=t.hasTargetArrow?y({x:t.to.x-t.arrowLength,y:t.to.y},t.toVect,t.to):t.to,r=t.arrowLength+t.arrowOffset,n=r-t.roundness,h=y({x:n,y:u.y},t.fromVect,u),s=y({x:t.to.x-n,y:t.to.y},t.toVect,t.to),d=Math.max((h.y+s.y)/2,r),c=t.to.x/2,a={x:h.x,y:t.flipY>0?d:-r},l={x:c,y:a.y},g={x:s.x,y:t.flipY>0?t.to.y-d:t.to.y+r},f={x:c,y:g.y};return D([e,h,a,l,f,g,s,o],t.roundness)},_=t=>{const e=t.arrowOffset,o=t.side,r=t.arrowLength+e,n=r+2*o,s=[{x:t.arrowLength,y:u.y},{x:r,y:u.y},{x:r,y:t.side},{x:n,y:t.side},{x:n,y:-t.side},{x:r,y:-t.side},{x:r,y:u.y},{x:t.arrowLength,y:u.y}].map(c=>y(c,t.fromVect,u)),d=`M ${u.x} ${u.y} L ${s[0].x} ${s[0].y} `;return`${t.hasSourceArrow||t.hasTargetArrow?"":d}${D(s,t.roundness)}`},Ue=t=>{const e=t.smallRadius,o=t.radius,r=Math.sqrt(e*e+o*o),n=e+o,h=t.arrowLength+r*(1-o/n),s=e*o/n,c=[{x:t.arrowLength,y:u.y},{x:h,y:s},{x:h,y:-s}].map(g=>y(g,t.fromVect,u)),a=[`M ${c[0].x} ${c[0].y}`,`A ${e} ${e} 0 0 1 ${c[1].x} ${c[1].y}`,`A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,`A ${e} ${e} 0 0 1 ${c[0].x} ${c[0].y}`].join(" "),l=`M 0 0 L ${c[0].x} ${c[0].y} `;return`${t.hasSourceArrow||t.hasTargetArrow?"":l}${a}`},w=Object.freeze({color:"#777777",width:1,arrowLength:15,arrowWidth:4,arrowOffset:15,hasSourceArrow:!1,hasTargetArrow:!1,cycleRadius:30,cycleSquareSide:30,roundness:10,detourDistance:100,detourDirection:-Math.PI/2,detourDirectionVertical:0,smallCycleRadius:15,curvature:90});class q{constructor(e){i(this,"svg",B());i(this,"group",z());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"arrowLength");i(this,"arrowWidth");i(this,"curvature");i(this,"portCycleRadius");i(this,"portCycleSmallRadius");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");this.arrowLength=(e==null?void 0:e.arrowLength)??w.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??w.arrowWidth,this.curvature=(e==null?void 0:e.curvature)??w.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??w.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??w.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??w.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??w.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??w.hasTargetArrow;const o=(e==null?void 0:e.color)??w.color,r=(e==null?void 0:e.width)??w.width;this.svg.appendChild(this.group),this.line=k(o,r),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=M(o),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=M(o),this.group.appendChild(this.targetArrow))}render(e){const{x:o,y:r,width:n,height:h,flipX:s,flipY:d}=Y(e.from,e.to);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${n}px`,this.svg.style.height=`${h}px`,this.group.style.transform=`scale(${s}, ${d})`;const c=b(e.from.direction,s,d),a=b(e.to.direction,s,d),l={x:n,y:h};let g,f=a,x=-this.arrowLength;if(e.from.portId===e.to.portId?(g=Ue({fromVect:c,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,x=this.arrowLength):e.from.nodeId===e.to.nodeId?g=Ve({to:l,fromVect:c,toVect:a,flipX:s,flipY:d,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=Me({to:l,fromVect:c,toVect:a,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=P(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=P(f,l,x,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class ee{constructor(e){i(this,"svg",B());i(this,"group",z());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"arrowLength");i(this,"arrowWidth");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");this.arrowLength=(e==null?void 0:e.arrowLength)??w.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??w.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??w.cycleSquareSide;const o=(e==null?void 0:e.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??w.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??w.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??w.hasTargetArrow;const r=(e==null?void 0:e.color)??w.color,n=(e==null?void 0:e.width)??w.width;this.svg.appendChild(this.group),this.line=k(r,n),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=M(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=M(r),this.group.appendChild(this.targetArrow))}render(e){const{x:o,y:r,width:n,height:h,flipX:s,flipY:d}=Y(e.from,e.to);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${n}px`,this.svg.style.height=`${h}px`,this.group.style.transform=`scale(${s}, ${d})`;const c=b(e.from.direction,s,d),a=b(e.to.direction,s,d),l={x:n,y:h};let g,f=a,x=-this.arrowLength;if(e.from.portId===e.to.portId?(g=_({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,x=this.arrowLength):e.from.nodeId===e.to.nodeId?g=G({to:l,fromVect:c,toVect:a,flipX:s,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=Le({to:l,fromVect:c,toVect:a,flipX:s,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=P(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=P(f,l,x,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class te{constructor(e){i(this,"svg",B());i(this,"group",z());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"arrowLength");i(this,"arrowWidth");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");this.arrowLength=(e==null?void 0:e.arrowLength)??w.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??w.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??w.cycleSquareSide;const o=(e==null?void 0:e.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??w.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??w.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??w.hasTargetArrow;const r=(e==null?void 0:e.color)??w.color,n=(e==null?void 0:e.width)??w.width;this.svg.appendChild(this.group),this.line=k(r,n),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=M(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=M(r),this.group.appendChild(this.targetArrow))}render(e){const{x:o,y:r,width:n,height:h,flipX:s,flipY:d}=Y(e.from,e.to);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${n}px`,this.svg.style.height=`${h}px`,this.group.style.transform=`scale(${s}, ${d})`;const c=b(e.from.direction,s,d),a=b(e.to.direction,s,d),l={x:n,y:h};let g,f=a,x=-this.arrowLength;if(e.from.portId===e.to.portId?(g=_({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,x=this.arrowLength):e.from.nodeId===e.to.nodeId?g=G({to:l,fromVect:c,toVect:a,flipX:s,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=De({to:l,fromVect:c,toVect:a,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=P(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=P(f,l,x,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}class oe{constructor(e){i(this,"svg",B());i(this,"group",z());i(this,"line");i(this,"sourceArrow",null);i(this,"targetArrow",null);i(this,"arrowLength");i(this,"arrowWidth");i(this,"arrowOffset");i(this,"roundness");i(this,"cycleSquareSide");i(this,"detourDirection");i(this,"detourDistance");i(this,"hasSourceArrow");i(this,"hasTargetArrow");this.arrowLength=(e==null?void 0:e.arrowLength)??w.arrowLength,this.arrowWidth=(e==null?void 0:e.arrowWidth)??w.arrowWidth,this.arrowOffset=(e==null?void 0:e.arrowOffset)??w.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??w.cycleSquareSide;const o=(e==null?void 0:e.roundness)??w.roundness;this.roundness=Math.min(o,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??w.detourDirectionVertical,this.detourDistance=(e==null?void 0:e.detourDistance)??w.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??w.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??w.hasTargetArrow;const r=(e==null?void 0:e.color)??w.color,n=(e==null?void 0:e.width)??w.width;this.svg.appendChild(this.group),this.line=k(r,n),this.group.appendChild(this.line),this.hasSourceArrow&&(this.sourceArrow=M(r),this.group.appendChild(this.sourceArrow)),this.hasTargetArrow&&(this.targetArrow=M(r),this.group.appendChild(this.targetArrow))}render(e){const{x:o,y:r,width:n,height:h,flipX:s,flipY:d}=Y(e.from,e.to);this.svg.style.transform=`translate(${o}px, ${r}px)`,this.svg.style.width=`${n}px`,this.svg.style.height=`${h}px`,this.group.style.transform=`scale(${s}, ${d})`;const c=b(e.from.direction,s,d),a=b(e.to.direction,s,d),l={x:n,y:h};let g,f=a,x=-this.arrowLength;if(e.from.portId===e.to.portId?(g=_({fromVect:c,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),f=c,x=this.arrowLength):e.from.nodeId===e.to.nodeId?g=G({to:l,fromVect:c,toVect:a,flipX:s,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}):g=Ce({to:l,fromVect:c,toVect:a,flipY:d,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}),this.line.setAttribute("d",g),this.sourceArrow){const v=P(c,u,this.arrowLength,this.arrowWidth);this.sourceArrow.setAttribute("d",v)}if(this.targetArrow){const v=P(f,l,x,this.arrowWidth);this.targetArrow.setAttribute("d",v)}}}const $e=t=>{if(typeof t=="function")return t;switch(t==null?void 0:t.type){case"straight":return()=>new te({color:t.color,width:t.width,arrowLength:t.arrowLength,arrowWidth:t.arrowWidth,arrowOffset:t.arrowOffset,hasSourceArrow:t.hasSourceArrow,hasTargetArrow:t.hasTargetArrow,cycleSquareSide:t.cycleSquareSide,roundness:t.roundness,detourDistance:t.detourDistance,detourDirection:t.detourDirection});case"horizontal":return()=>new ee({color:t.color,width:t.width,arrowLength:t.arrowLength,arrowWidth:t.arrowWidth,arrowOffset:t.arrowOffset,hasSourceArrow:t.hasSourceArrow,hasTargetArrow:t.hasTargetArrow,cycleSquareSide:t.cycleSquareSide,roundness:t.roundness,detourDistance:t.detourDistance,detourDirection:t.detourDirection});case"vertical":return()=>new oe({color:t.color,width:t.width,arrowLength:t.arrowLength,arrowWidth:t.arrowWidth,arrowOffset:t.arrowOffset,hasSourceArrow:t.hasSourceArrow,hasTargetArrow:t.hasTargetArrow,cycleSquareSide:t.cycleSquareSide,roundness:t.roundness,detourDistance:t.detourDistance,detourDirection:t.detourDirection});default:return()=>new q({color:t.color,width:t.width,arrowLength:t.arrowLength,arrowWidth:t.arrowWidth,hasSourceArrow:t.hasSourceArrow,hasTargetArrow:t.hasTargetArrow,cycleRadius:t.cycleRadius,smallCycleRadius:t.smallCycleRadius,curvature:t.curvature,detourDistance:t.detourDistance,detourDirection:t.detourDirection})}},Re=t=>{var o,r,n,h,s;const e=Pe((o=t==null?void 0:t.nodes)==null?void 0:o.priority,(r=t==null?void 0:t.edges)==null?void 0:r.priority);return{nodes:{centerFn:((n=t==null?void 0:t.nodes)==null?void 0:n.centerFn)??Te,priorityFn:e.nodesPriorityFn},ports:{direction:((h=t==null?void 0:t.ports)==null?void 0:h.direction)??0},edges:{shapeFactory:$e(((s=t==null?void 0:t.edges)==null?void 0:s.shape)??{}),priorityFn:e.edgesPriorityFn}}};class Ie{constructor(e,o,r){i(this,"nodeIdGenerator",new H(e=>this.graph.getNode(e)!==null));i(this,"portIdGenerator",new H(e=>this.graph.getPort(e)!==null));i(this,"edgeIdGenerator",new H(e=>this.graph.getEdge(e)!==null));i(this,"defaults");i(this,"graph");i(this,"viewport");this.element=e,this.controller=o,this.defaults=Re(r),this.graph=o.graph,this.viewport=o.viewport,this.attach(this.element)}attach(e){return this.controller.attach(e),this}detach(){return this.controller.detach(),this}addNode(e){const o=this.nodeIdGenerator.create(e.id);if(this.graph.getNode(o)!==null)throw new p("failed to add node with existing id");if(this.controller.addNode({id:o,element:e.element,x:e.x,y:e.y,centerFn:e.centerFn??this.defaults.nodes.centerFn,priority:e.priority??this.defaults.nodes.priorityFn()}),e.ports!==void 0)for(const r of e.ports)this.markPort({id:r.id,element:r.element,nodeId:o,direction:r.direction});return this}updateNode(e,o){if(this.graph.getNode(e)===null)throw new p("failed to update nonexisting node");return this.controller.updateNode(e,o??{}),this}removeNode(e){if(this.graph.getNode(e)===null)throw new p("failed to remove nonexisting node");return this.controller.removeNode(e),this}markPort(e){const o=this.portIdGenerator.create(e.id);if(this.graph.getPort(o)!==null)throw new p("failed to add port with existing id");if(this.graph.getNode(e.nodeId)===null)throw new p("failed to set port on nonexisting node");return this.controller.markPort({id:o,element:e.element,nodeId:e.nodeId,direction:e.direction??this.defaults.ports.direction}),this}updatePort(e,o){if(this.graph.getPort(e)===null)throw new p("failed to unset nonexisting port");return this.controller.updatePort(e,o??{}),this}unmarkPort(e){if(this.graph.getPort(e)===null)throw new p("failed to unset nonexisting port");return this.controller.unmarkPort(e),this}addEdge(e){const o=this.edgeIdGenerator.create(e.id);if(this.graph.getEdge(o)!==null)throw new p("failed to add edge with existing id");if(this.graph.getPort(e.from)===null)throw new p("failed to add edge from nonexisting port");if(this.graph.getPort(e.to)===null)throw new p("failed to add edge to nonexisting port");return this.controller.addEdge({id:o,from:e.from,to:e.to,shape:e.shape??this.defaults.edges.shapeFactory(),priority:e.priority??this.defaults.edges.priorityFn()}),this}updateEdge(e,o){if(this.graph.getEdge(e)===null)throw new p("failed to update nonexisting edge");return this.controller.updateEdge(e,o??{}),this}removeEdge(e){if(this.graph.getEdge(e)===null)throw new p("failed to remove nonexisting edge");return this.controller.removeEdge(e),this}patchViewportMatrix(e){return this.controller.patchViewportMatrix(e),this}patchContentMatrix(e){return this.controller.patchContentMatrix(e),this}clear(){return this.controller.clear(),this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset(),this}destroy(){this.controller.destroy()}}class We{constructor(){i(this,"nodes",new Map);i(this,"ports",new Map);i(this,"edges",new Map);i(this,"incommingEdges",new Map);i(this,"outcommingEdges",new Map);i(this,"cycleEdges",new Map);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]=E(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=E(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=E(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=E(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=E(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=E(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=E(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=E(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=E(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=E(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=E(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=E(),[this.beforeClearEmitter,this.onBeforeClear]=E()}addNode(e){const o=new Map,r={element:e.element,x:e.x,y:e.y,centerFn:e.centerFn,priority:e.priority,ports:o};this.nodes.set(e.id,r),this.afterNodeAddedEmitter.emit(e.id)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(e){return this.nodes.get(e)}updateNode(e,o){const r=this.nodes.get(e);r.x=o.x??r.x,r.y=o.y??r.y,r.centerFn=o.centerFn??r.centerFn,o.priority!==void 0&&(r.priority=o.priority,this.afterNodePriorityUpdatedEmitter.emit(e)),this.afterNodeUpdatedEmitter.emit(e)}removeNode(e){this.beforeNodeRemovedEmitter.emit(e),this.nodes.delete(e)}addPort(e){this.ports.set(e.id,{element:e.element,direction:e.direction,nodeId:e.nodeId}),this.cycleEdges.set(e.id,new Set),this.incommingEdges.set(e.id,new Set),this.outcommingEdges.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,o){const r=this.ports.get(e);r.direction=o.direction??r.direction,this.afterPortUpdatedEmitter.emit(e)}getAllPortIds(){return Array.from(this.ports.keys())}getNodePortIds(e){const o=this.nodes.get(e);if(o!==void 0)return Array.from(o.ports.keys())}removePort(e){const o=this.ports.get(e).nodeId;this.beforePortRemovedEmitter.emit(e),this.nodes.get(o).ports.delete(e),this.ports.delete(e)}addEdge(e){this.addEdgeInternal(e),this.afterEdgeAddedEmitter.emit(e.id)}updateEdge(e,o){if(o.from!==void 0||o.to!==void 0){const n=this.edges.get(e);this.removeEdgeInternal(e),this.addEdgeInternal({id:e,from:o.from??n.from,to:o.to??n.to,shape:n.shape,priority:n.priority})}const r=this.edges.get(e);o.shape!==void 0&&(r.shape=o.shape,this.afterEdgeShapeUpdatedEmitter.emit(e)),o.priority!==void 0&&(r.priority=o.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.incommingEdges.clear(),this.outcommingEdges.clear(),this.cycleEdges.clear(),this.edges.clear(),this.ports.clear(),this.nodes.clear()}getPortIncomingEdgeIds(e){return Array.from(this.incommingEdges.get(e))}getPortOutcomingEdgeIds(e){return Array.from(this.outcommingEdges.get(e))}getPortCycleEdgeIds(e){return Array.from(this.cycleEdges.get(e))}getPortAdjacentEdgeIds(e){return[...this.getPortIncomingEdgeIds(e),...this.getPortOutcomingEdgeIds(e),...this.getPortCycleEdgeIds(e)]}getNodeIncomingEdgeIds(e){const o=Array.from(this.nodes.get(e).ports.keys());let r=[];return o.forEach(n=>{r=[...r,...this.getPortIncomingEdgeIds(n)]}),r}getNodeOutcomingEdgeIds(e){const o=Array.from(this.nodes.get(e).ports.keys());let r=[];return o.forEach(n=>{r=[...r,...this.getPortOutcomingEdgeIds(n)]}),r}getNodeCycleEdgeIds(e){const o=Array.from(this.nodes.get(e).ports.keys());let r=[];return o.forEach(n=>{r=[...r,...this.getPortCycleEdgeIds(n)]}),r}getNodeAdjacentEdgeIds(e){return[...this.getNodeIncomingEdgeIds(e),...this.getNodeOutcomingEdgeIds(e),...this.getNodeCycleEdgeIds(e)]}addEdgeInternal(e){this.edges.set(e.id,{from:e.from,to:e.to,shape:e.shape,priority:e.priority}),e.from!==e.to?(this.outcommingEdges.get(e.from).add(e.id),this.incommingEdges.get(e.to).add(e.id)):this.cycleEdges.get(e.from).add(e.id)}removeEdgeInternal(e){const o=this.edges.get(e),r=o.from,n=o.to;this.cycleEdges.get(r).delete(e),this.cycleEdges.get(n).delete(e),this.incommingEdges.get(r).delete(e),this.incommingEdges.get(n).delete(e),this.outcommingEdges.get(r).delete(e),this.outcommingEdges.get(n).delete(e),this.edges.delete(e)}}const re=t=>({scale:1/t.scale,x:-t.x/t.scale,y:-t.y/t.scale}),ie={scale:1,x:0,y:0};class Fe{constructor(){i(this,"viewportMatrix",ie);i(this,"contentMatrix",ie);i(this,"afterUpdateEmitter");i(this,"onAfterUpdated");i(this,"beforeUpdateEmitter");i(this,"onBeforeUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=E(),[this.beforeUpdateEmitter,this.onBeforeUpdated]=E()}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(e){this.beforeUpdateEmitter.emit(),this.viewportMatrix={scale:e.scale??this.viewportMatrix.scale,x:e.x??this.viewportMatrix.x,y:e.y??this.viewportMatrix.y},this.contentMatrix=re(this.viewportMatrix),this.afterUpdateEmitter.emit()}patchContentMatrix(e){this.beforeUpdateEmitter.emit(),this.contentMatrix={scale:e.scale??this.contentMatrix.scale,x:e.x??this.contentMatrix.x,y:e.y??this.contentMatrix.y},this.viewportMatrix=re(this.contentMatrix),this.afterUpdateEmitter.emit()}}class J{constructor(e){i(this,"elementToNodeId",new Map);i(this,"nodesResizeObserver");i(this,"onAfterNodeAdded",e=>{const o=this.canvas.graph.getNode(e);this.elementToNodeId.set(o.element,e),this.nodesResizeObserver.observe(o.element)});i(this,"onBeforeNodeRemoved",e=>{const o=this.canvas.graph.getNode(e);this.elementToNodeId.delete(o.element),this.nodesResizeObserver.unobserve(o.element)});i(this,"onBeforeClear",()=>{this.nodesResizeObserver.disconnect(),this.elementToNodeId.clear()});this.canvas=e,this.nodesResizeObserver=new ResizeObserver(o=>{o.forEach(r=>{const n=r.target;this.handleNodeResize(n)})}),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 o=this.elementToNodeId.get(e);this.canvas.updateNode(o),this.canvas.graph.getNodeAdjacentEdgeIds(o).forEach(n=>{this.canvas.updateEdge(n)})}}class Be{constructor(){i(this,"element",null);i(this,"canvasDefaults",{});i(this,"dragOptions");i(this,"transformOptions");i(this,"virtualScrollOptions");i(this,"hasDraggableNode",!1);i(this,"hasTransformableViewport",!1);i(this,"hasResizeReactiveNodes",!1);i(this,"boxRenderingTrigger")}attach(e){return this.element=e,this}setDefaults(e){return this.canvasDefaults=e,this}setOptions(e){return this.setDefaults(e),this}enableUserDraggableNodes(e){return this.hasDraggableNode=!0,this.dragOptions=e,this}enableUserTransformableViewport(e){return this.hasTransformableViewport=!0,this.transformOptions=e,this}enableResizeReactiveNodes(){return this.hasResizeReactiveNodes=!0,this}enableBoxAreaRendering(e){return this.boxRenderingTrigger=e,this}enableVirtualScroll(e){return this.virtualScrollOptions=e,this}build(){if(this.element===null)throw new p("unable to build canvas when no attach element specified");let e=this.boxRenderingTrigger;this.virtualScrollOptions!==void 0&&e===void 0&&(e=new X);const o=new We,r=new Fe;let n=new Se(o,r);e!==void 0&&(n=new me(n,o,e));let h=new ce(o,r,n);this.hasDraggableNode&&(h=new le(h,this.dragOptions)),this.virtualScrollOptions!==void 0?h=new xe(h,e,this.transformOptions,this.virtualScrollOptions):this.hasTransformableViewport&&(h=new Z(h,this.transformOptions));const s=new Ie(this.element,h,this.canvasDefaults);return this.hasResizeReactiveNodes&&J.configure(s),this.reset(),s}reset(){this.element=null,this.canvasDefaults={},this.dragOptions=void 0,this.transformOptions=void 0,this.virtualScrollOptions=void 0,this.hasDraggableNode=!1,this.hasTransformableViewport=!1,this.hasResizeReactiveNodes=!1,this.boxRenderingTrigger=void 0}}A.BezierEdgeShape=q,A.CanvasBuilder=Be,A.EventSubject=X,A.HorizontalEdgeShape=ee,A.HtmlGraphError=p,A.StraightEdgeShape=te,A.VerticalEdgeShape=oe,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|