@html-graph/html-graph 2.0.1 → 2.2.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.
@@ -1,1394 +1,962 @@
1
- var oe = Object.defineProperty;
2
- var re = (t, e, o) => e in t ? oe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
3
- var i = (t, e, o) => re(t, typeof e != "symbol" ? e + "" : e, o);
4
- class ie {
5
- constructor(e) {
6
- i(this, "viewport");
7
- i(this, "graph");
8
- i(this, "internalTransformation");
9
- i(this, "internalModel");
10
- i(this, "graphStoreController");
11
- i(this, "htmlView");
12
- i(this, "onAfterNodeAdded", (e) => {
13
- this.htmlView.attachNode(e);
14
- });
15
- i(this, "onAfterEdgeAdded", (e) => {
16
- this.htmlView.attachEdge(e);
17
- });
18
- i(this, "onAfterEdgeShapeUpdated", (e) => {
19
- this.htmlView.updateEdgeShape(e);
20
- });
21
- i(this, "onAfterEdgePriorityUpdated", (e) => {
22
- this.htmlView.updateEdgePriority(e);
23
- });
24
- i(this, "onAfterEdgeUpdated", (e) => {
25
- this.htmlView.renderEdge(e);
26
- });
27
- i(this, "onAfterPortUpdated", (e) => {
28
- this.internalModel.getPortAdjacentEdgeIds(e).forEach((r) => {
29
- this.htmlView.renderEdge(r);
30
- });
31
- });
32
- i(this, "onAfterNodePriorityUpdated", (e) => {
33
- this.htmlView.updateNodePriority(e);
34
- });
35
- i(this, "onAfterNodeUpdated", (e) => {
36
- this.htmlView.updateNodeCoordinates(e), this.internalModel.getNodeAdjacentEdgeIds(e).forEach((r) => {
37
- this.htmlView.renderEdge(r);
38
- });
39
- });
40
- i(this, "onBeforeEdgeRemoved", (e) => {
41
- this.htmlView.detachEdge(e);
42
- });
43
- i(this, "onBeforeNodeRemoved", (e) => {
44
- this.htmlView.detachNode(e);
45
- });
46
- this.graph = e.graph, this.internalModel = e.graphStore, this.internalTransformation = e.viewportTransformer, this.viewport = e.viewport, this.htmlView = e.htmlView, this.graphStoreController = e.graphStoreController, this.graphStoreController.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graphStoreController.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded), this.graphStoreController.onAfterEdgeShapeUpdated.subscribe(
47
- this.onAfterEdgeShapeUpdated
48
- ), this.graphStoreController.onAfterEdgePriorityUpdated.subscribe(
49
- this.onAfterEdgePriorityUpdated
50
- ), this.graphStoreController.onAfterEdgeUpdated.subscribe(
51
- this.onAfterEdgeUpdated
52
- ), this.graphStoreController.onAfterPortUpdated.subscribe(
53
- this.onAfterPortUpdated
54
- ), this.graphStoreController.onAfterNodePriorityUpdated.subscribe(
55
- this.onAfterNodePriorityUpdated
56
- ), this.graphStoreController.onAfterNodeUpdated.subscribe(
57
- this.onAfterNodeUpdated
58
- ), this.graphStoreController.onBeforeEdgeRemoved.subscribe(
59
- this.onBeforeEdgeRemoved
60
- ), this.graphStoreController.onBeforeNodeRemoved.subscribe(
61
- this.onBeforeNodeRemoved
62
- );
1
+ var tt = Object.defineProperty;
2
+ var et = (e, t, o) => t in e ? tt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
+ var i = (e, t, o) => et(e, typeof t != "symbol" ? t + "" : t, o);
4
+ class ot {
5
+ constructor(t) {
6
+ this.graphStore = t;
7
+ }
8
+ getNode(t) {
9
+ const o = this.graphStore.getNode(t);
10
+ return o === void 0 ? null : {
11
+ element: o.element,
12
+ x: o.x,
13
+ y: o.y,
14
+ centerFn: o.centerFn,
15
+ priority: o.priority
16
+ };
63
17
  }
64
- attach(e) {
65
- return this.htmlView.attach(e), this;
18
+ getAllNodeIds() {
19
+ return this.graphStore.getAllNodeIds();
66
20
  }
67
- detach() {
68
- return this.htmlView.detach(), this;
21
+ getPort(t) {
22
+ const o = this.graphStore.getPort(t);
23
+ return o === void 0 ? null : {
24
+ element: o.element,
25
+ direction: o.direction
26
+ };
69
27
  }
70
- addNode(e) {
71
- return this.graphStoreController.addNode(e), this;
28
+ getAllPortIds() {
29
+ return this.graphStore.getAllPortIds();
72
30
  }
73
- updateNode(e, o) {
74
- return this.graphStoreController.updateNode(e, o ?? {}), this;
31
+ getNodePortIds(t) {
32
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodePortIds(t);
75
33
  }
76
- removeNode(e) {
77
- return this.graphStoreController.removeNode(e), this;
34
+ /**
35
+ * @deprecated
36
+ * use graph.getPort()?.nodeId ?? null instead
37
+ */
38
+ getPortNodeId(t) {
39
+ var o;
40
+ return ((o = this.graphStore.getPort(t)) == null ? void 0 : o.nodeId) ?? null;
78
41
  }
79
- addEdge(e) {
80
- return this.graphStoreController.addEdge(e), this;
42
+ getAllEdgeIds() {
43
+ return this.graphStore.getAllEdgeIds();
81
44
  }
82
- updateEdge(e, o) {
83
- return this.graphStoreController.updateEdge(e, o ?? {}), this;
45
+ getEdge(t) {
46
+ const o = this.graphStore.getEdge(t);
47
+ return o === void 0 ? null : { from: o.from, to: o.to, priority: o.priority };
84
48
  }
85
- removeEdge(e) {
86
- return this.graphStoreController.removeEdge(e), this;
49
+ getPortIncomingEdgeIds(t) {
50
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortIncomingEdgeIds(t);
87
51
  }
88
- markPort(e) {
89
- return this.graphStoreController.markPort(e), this;
52
+ getPortOutcomingEdgeIds(t) {
53
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortOutcomingEdgeIds(t);
90
54
  }
91
- updatePort(e, o) {
92
- return this.graphStoreController.updatePort(e, o ?? {}), this;
55
+ getPortCycleEdgeIds(t) {
56
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortCycleEdgeIds(t);
93
57
  }
94
- unmarkPort(e) {
95
- return this.graphStoreController.unmarkPort(e), this;
58
+ getPortAdjacentEdgeIds(t) {
59
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortAdjacentEdgeIds(t);
96
60
  }
97
- patchViewportMatrix(e) {
98
- return this.internalTransformation.patchViewportMatrix(e), this;
61
+ getNodeIncomingEdgeIds(t) {
62
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeIncomingEdgeIds(t);
99
63
  }
100
- patchContentMatrix(e) {
101
- return this.internalTransformation.patchContentMatrix(e), this;
64
+ getNodeOutcomingEdgeIds(t) {
65
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeOutcomingEdgeIds(t);
102
66
  }
103
- clear() {
104
- return this.htmlView.clear(), this.graphStoreController.clear(), this;
67
+ getNodeCycleEdgeIds(t) {
68
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeCycleEdgeIds(t);
105
69
  }
106
- destroy() {
107
- this.htmlView.destroy(), this.graphStoreController.clear(), this.graphStoreController.onAfterNodeAdded.unsubscribe(
108
- this.onAfterNodeAdded
109
- ), this.graphStoreController.onAfterEdgeAdded.unsubscribe(
110
- this.onAfterEdgeAdded
111
- ), this.graphStoreController.onAfterEdgeShapeUpdated.unsubscribe(
112
- this.onAfterEdgeShapeUpdated
113
- ), this.graphStoreController.onAfterEdgePriorityUpdated.unsubscribe(
114
- this.onAfterEdgePriorityUpdated
115
- ), this.graphStoreController.onAfterEdgeUpdated.unsubscribe(
116
- this.onAfterEdgeUpdated
117
- ), this.graphStoreController.onAfterPortUpdated.unsubscribe(
118
- this.onAfterPortUpdated
119
- ), this.graphStoreController.onAfterNodePriorityUpdated.unsubscribe(
120
- this.onAfterNodePriorityUpdated
121
- ), this.graphStoreController.onAfterNodeUpdated.unsubscribe(
122
- this.onAfterNodeUpdated
123
- ), this.graphStoreController.onBeforeEdgeRemoved.unsubscribe(
124
- this.onBeforeEdgeRemoved
125
- ), this.graphStoreController.onBeforeNodeRemoved.unsubscribe(
126
- this.onBeforeNodeRemoved
127
- );
70
+ getNodeAdjacentEdgeIds(t) {
71
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeAdjacentEdgeIds(t);
128
72
  }
129
73
  }
130
- class L {
131
- constructor(e) {
132
- i(this, "counter", 0);
133
- this.checkExists = e;
74
+ class rt {
75
+ constructor(t) {
76
+ this.transformer = t;
134
77
  }
135
- create(e) {
136
- if (e !== void 0)
137
- return e;
138
- for (; this.checkExists(this.counter); )
139
- this.counter++;
140
- return this.counter;
78
+ getViewportMatrix() {
79
+ return { ...this.transformer.getViewportMatrix() };
141
80
  }
142
- reset() {
143
- this.counter = 0;
81
+ getContentMatrix() {
82
+ return { ...this.transformer.getContentMatrix() };
144
83
  }
145
84
  }
146
- class E extends Error {
147
- constructor() {
148
- super(...arguments);
149
- i(this, "name", "HtmlGraphError");
85
+ class it {
86
+ constructor(t, o, r) {
87
+ i(this, "viewport");
88
+ i(this, "graph");
89
+ this.graphStore = t, this.viewportStore = o, this.htmlView = r, this.graph = new ot(this.graphStore), this.viewport = new rt(this.viewportStore);
150
90
  }
151
- }
152
- class q {
153
- constructor() {
154
- i(this, "callbacks", /* @__PURE__ */ new Set());
91
+ attach(t) {
92
+ this.htmlView.attach(t);
93
+ }
94
+ detach() {
95
+ this.htmlView.detach();
155
96
  }
156
- subscribe(e) {
157
- this.callbacks.add(e);
97
+ addNode(t) {
98
+ this.graphStore.addNode(t), this.htmlView.attachNode(t.id);
158
99
  }
159
- unsubscribe(e) {
160
- this.callbacks.delete(e);
100
+ updateNode(t, o) {
101
+ const r = this.graphStore.getNode(t);
102
+ r.x = (o == null ? void 0 : o.x) ?? r.x, r.y = (o == null ? void 0 : o.y) ?? r.y, r.centerFn = o.centerFn ?? r.centerFn, this.htmlView.updateNodeCoordinates(t), this.graphStore.getNodeAdjacentEdgeIds(t).forEach((h) => {
103
+ this.htmlView.renderEdge(h);
104
+ }), o.priority !== void 0 && (r.priority = o.priority, this.htmlView.updateNodePriority(t));
161
105
  }
162
- emit(e) {
163
- this.callbacks.forEach((o) => {
164
- o(e);
106
+ removeNode(t) {
107
+ this.graphStore.getNodePortIds(t).forEach((o) => {
108
+ this.unmarkPort(o);
109
+ }), this.graphStore.removeNode(t), this.htmlView.detachNode(t);
110
+ }
111
+ markPort(t) {
112
+ this.graphStore.addPort(t);
113
+ }
114
+ updatePort(t, o) {
115
+ const r = this.graphStore.getPort(t);
116
+ r.direction = o.direction ?? r.direction, this.graphStore.getPortAdjacentEdgeIds(t).forEach((h) => {
117
+ this.htmlView.renderEdge(h);
165
118
  });
166
119
  }
120
+ unmarkPort(t) {
121
+ this.graphStore.getPortAdjacentEdgeIds(t).forEach((o) => {
122
+ this.removeEdge(o);
123
+ }), this.graphStore.removePort(t);
124
+ }
125
+ addEdge(t) {
126
+ this.graphStore.addEdge(t), this.htmlView.attachEdge(t.id);
127
+ }
128
+ updateEdge(t, o) {
129
+ const r = this.graphStore.getEdge(t);
130
+ o.shape !== void 0 && (r.shape = o.shape, this.htmlView.updateEdgeShape(t)), o.from !== void 0 && this.graphStore.updateEdgeFrom(t, o.from), o.to !== void 0 && this.graphStore.updateEdgeTo(t, o.to), this.htmlView.renderEdge(t), o.priority !== void 0 && (r.priority = o.priority, this.htmlView.updateEdgePriority(t));
131
+ }
132
+ removeEdge(t) {
133
+ this.graphStore.removeEdge(t), this.htmlView.detachEdge(t);
134
+ }
135
+ patchViewportMatrix(t) {
136
+ this.viewportStore.patchViewportMatrix(t);
137
+ }
138
+ patchContentMatrix(t) {
139
+ this.viewportStore.patchContentMatrix(t);
140
+ }
141
+ clear() {
142
+ this.htmlView.clear(), this.graphStore.clear();
143
+ }
144
+ destroy() {
145
+ this.clear(), this.htmlView.destroy();
146
+ }
167
147
  }
168
- const p = () => {
169
- const t = new q();
170
- return [t, t];
148
+ const C = (e, t, o) => {
149
+ const { x: r, y: n, width: h, height: s } = e.getBoundingClientRect();
150
+ return t >= r && t <= r + h && o >= n && o <= n + s;
151
+ }, $ = (e, t, o) => t >= 0 && t <= e.innerWidth && o >= 0 && o <= e.innerHeight, W = (e, t) => {
152
+ t !== null ? e.style.cursor = t : e.style.removeProperty("cursor");
153
+ }, st = (e) => {
154
+ var g, y, x, v, A, S;
155
+ const t = ((g = e == null ? void 0 : e.events) == null ? void 0 : g.onNodeDrag) ?? (() => {
156
+ }), o = ((y = e == null ? void 0 : e.events) == null ? void 0 : y.onBeforeNodeDrag) ?? (() => !0), r = ((x = e == null ? void 0 : e.events) == null ? void 0 : x.onNodeDragFinished) ?? (() => {
157
+ }), n = (e == null ? void 0 : e.moveOnTop) === !1, h = (v = e == null ? void 0 : e.mouse) == null ? void 0 : v.dragCursor, s = h !== void 0 ? h : "grab", c = (A = e == null ? void 0 : e.mouse) == null ? void 0 : A.mouseDownEventVerifier, d = c !== void 0 ? c : (T) => T.button === 0, a = (S = e == null ? void 0 : e.mouse) == null ? void 0 : S.mouseUpEventVerifier;
158
+ return {
159
+ freezePriority: n,
160
+ dragCursor: s,
161
+ mouseDownEventVerifier: d,
162
+ mouseUpEventVerifier: a !== void 0 ? a : (T) => T.button === 0,
163
+ onNodeDrag: t,
164
+ onBeforeNodeDrag: o,
165
+ onNodeDragFinished: r
166
+ };
171
167
  };
172
- class se {
173
- constructor(e, o) {
174
- i(this, "nodeIdGenerator", new L(
175
- (e) => this.graphStore.getNode(e) !== void 0
176
- ));
177
- i(this, "portIdGenerator", new L(
178
- (e) => this.graphStore.getPort(e) !== void 0
179
- ));
180
- i(this, "edgeIdGenerator", new L(
181
- (e) => this.graphStore.getEdge(e) !== void 0
182
- ));
183
- i(this, "onAfterNodeAdded");
184
- i(this, "onAfterNodeAddedEmitter");
185
- i(this, "onAfterEdgeAdded");
186
- i(this, "onAfterEdgeAddedEmitter");
187
- i(this, "onAfterEdgeShapeUpdated");
188
- i(this, "onAfterEdgeShapeUpdatedEmitter");
189
- i(this, "onAfterEdgePriorityUpdated");
190
- i(this, "onAfterEdgePriorityUpdatedEmitter");
191
- i(this, "onAfterEdgeUpdated");
192
- i(this, "onAfterEdgeUpdatedEmitter");
193
- i(this, "onAfterPortUpdated");
194
- i(this, "onAfterPortUpdatedEmitter");
195
- i(this, "onAfterNodePriorityUpdated");
196
- i(this, "onAfterNodePriorityUpdatedEmitter");
197
- i(this, "onAfterNodeUpdated");
198
- i(this, "onAfterNodeUpdatedEmitter");
199
- i(this, "onBeforeEdgeRemoved");
200
- i(this, "onBeforeEdgeRemovedEmitter");
201
- i(this, "onBeforeNodeRemoved");
202
- i(this, "onBeforeNodeRemovedEmitter");
203
- this.graphStore = e, this.options = o, [this.onAfterNodeAddedEmitter, this.onAfterNodeAdded] = p(), [this.onAfterEdgeAddedEmitter, this.onAfterEdgeAdded] = p(), [this.onAfterEdgeShapeUpdatedEmitter, this.onAfterEdgeShapeUpdated] = p(), [this.onAfterEdgePriorityUpdatedEmitter, this.onAfterEdgePriorityUpdated] = p(), [this.onAfterEdgeUpdatedEmitter, this.onAfterEdgeUpdated] = p(), [this.onAfterPortUpdatedEmitter, this.onAfterPortUpdated] = p(), [this.onAfterNodePriorityUpdatedEmitter, this.onAfterNodePriorityUpdated] = p(), [this.onAfterNodeUpdatedEmitter, this.onAfterNodeUpdated] = p(), [this.onBeforeEdgeRemovedEmitter, this.onBeforeEdgeRemoved] = p(), [this.onBeforeNodeRemovedEmitter, this.onBeforeNodeRemoved] = p();
204
- }
205
- addNode(e) {
206
- const o = this.nodeIdGenerator.create(e.id);
207
- if (this.graphStore.getNode(o) !== void 0)
208
- throw new E("failed to add node with existing id");
209
- this.graphStore.addNode({
210
- nodeId: o,
211
- element: e.element,
212
- x: e.x,
213
- y: e.y,
214
- centerFn: e.centerFn ?? this.options.nodes.centerFn,
215
- priority: e.priority ?? this.options.nodes.priorityFn()
216
- }), this.onAfterNodeAddedEmitter.emit(o), Array.from(e.ports ?? []).forEach((r) => {
217
- this.markPort({
218
- id: r.id,
219
- element: r.element,
220
- nodeId: o,
221
- direction: r.direction
222
- });
168
+ class nt {
169
+ constructor(t, o) {
170
+ i(this, "graph");
171
+ i(this, "viewport");
172
+ i(this, "maxNodePriority", 0);
173
+ i(this, "nodes", /* @__PURE__ */ new Map());
174
+ i(this, "grabbedNodeId", null);
175
+ i(this, "element", null);
176
+ i(this, "onWindowMouseMove", (t) => {
177
+ if (this.element !== null && (!C(this.element, t.clientX, t.clientY) || !$(this.window, t.clientX, t.clientY))) {
178
+ this.cancelMouseDrag();
179
+ return;
180
+ }
181
+ this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, t.movementX, t.movementY);
223
182
  });
224
- }
225
- markPort(e) {
226
- const o = this.portIdGenerator.create(e.id);
227
- if (this.graphStore.getPort(o) !== void 0)
228
- throw new E("failed to add port with existing id");
229
- if (this.graphStore.getNode(e.nodeId) === void 0)
230
- throw new E("failed to set port on nonexisting node");
231
- this.graphStore.addPort({
232
- portId: o,
233
- element: e.element,
234
- nodeId: e.nodeId,
235
- direction: e.direction ?? this.options.ports.direction
183
+ i(this, "onWindowMouseUp", (t) => {
184
+ this.options.mouseUpEventVerifier(t) && this.cancelMouseDrag();
185
+ });
186
+ i(this, "onWindowTouchMove", (t) => {
187
+ if (t.touches.length !== 1)
188
+ return;
189
+ const o = t.touches[0];
190
+ if (this.element !== null && (!C(this.element, o.clientX, o.clientY) || !$(this.window, o.clientX, o.clientY))) {
191
+ this.cancelTouchDrag();
192
+ return;
193
+ }
194
+ if (this.grabbedNodeId !== null && this.previousTouchCoords !== null) {
195
+ const r = o.clientX - this.previousTouchCoords.x, n = o.clientY - this.previousTouchCoords.y;
196
+ this.dragNode(this.grabbedNodeId, r, n), this.previousTouchCoords = {
197
+ x: t.touches[0].clientX,
198
+ y: t.touches[0].clientY
199
+ };
200
+ }
201
+ });
202
+ i(this, "onWindowTouchFinish", () => {
203
+ this.previousTouchCoords = null, this.cancelTouchDrag();
236
204
  });
205
+ i(this, "previousTouchCoords", null);
206
+ i(this, "window", window);
207
+ i(this, "options");
208
+ this.canvas = t, this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.options = st(o ?? {});
237
209
  }
238
- addEdge(e) {
239
- const o = this.edgeIdGenerator.create(e.id);
240
- if (this.graphStore.getEdge(o) !== void 0)
241
- throw new E("failed to add edge with existing id");
242
- if (this.graphStore.getPort(e.from) === void 0)
243
- throw new E("failed to add edge from nonexisting port");
244
- if (this.graphStore.getPort(e.to) === void 0)
245
- throw new E("failed to add edge to nonexisting port");
246
- this.graphStore.addEdge({
247
- edgeId: o,
248
- from: e.from,
249
- to: e.to,
250
- shape: e.shape ?? this.options.edges.shapeFactory(),
251
- priority: e.priority ?? this.options.edges.priorityFn()
252
- }), this.onAfterEdgeAddedEmitter.emit(o);
253
- }
254
- updateEdge(e, o) {
255
- const r = this.graphStore.getEdge(e);
256
- if (r === void 0)
257
- throw new E("failed to update nonexisting edge");
258
- o.shape !== void 0 && (r.shape = o.shape, this.onAfterEdgeShapeUpdatedEmitter.emit(e)), o.from !== void 0 && this.graphStore.updateEdgeFrom(e, o.from), o.to !== void 0 && this.graphStore.updateEdgeTo(e, o.to), this.onAfterEdgeUpdatedEmitter.emit(e), o.priority !== void 0 && (r.priority = o.priority, this.onAfterEdgePriorityUpdatedEmitter.emit(e));
210
+ attach(t) {
211
+ this.detach(), this.element = t, this.canvas.attach(this.element);
259
212
  }
260
- updatePort(e, o) {
261
- const r = this.graphStore.getPort(e);
262
- if (r === void 0)
263
- throw new E("failed to unset nonexisting port");
264
- r.direction = o.direction ?? r.direction, this.onAfterPortUpdatedEmitter.emit(e);
213
+ detach() {
214
+ this.canvas.detach(), this.element !== null && (this.element = null);
265
215
  }
266
- updateNode(e, o) {
267
- const r = this.graphStore.getNode(e);
268
- if (r === void 0)
269
- throw new E("failed to update nonexisting node");
270
- r.x = (o == null ? void 0 : o.x) ?? r.x, r.y = (o == null ? void 0 : o.y) ?? r.y, r.centerFn = o.centerFn ?? r.centerFn, this.onAfterNodeUpdatedEmitter.emit(e), o.priority !== void 0 && (r.priority = o.priority, this.onAfterNodePriorityUpdatedEmitter.emit(e));
216
+ addNode(t) {
217
+ this.canvas.addNode(t), this.updateMaxNodePriority(t.id);
218
+ const o = (n) => {
219
+ if (this.element === null || !this.options.mouseDownEventVerifier(n))
220
+ return;
221
+ const h = this.graph.getNode(t.id);
222
+ this.options.onBeforeNodeDrag({
223
+ nodeId: t.id,
224
+ element: t.element,
225
+ x: h.x,
226
+ y: h.y
227
+ }) && (n.stopImmediatePropagation(), this.grabbedNodeId = t.id, W(this.element, this.options.dragCursor), this.moveNodeOnTop(t.id), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
228
+ }, r = (n) => {
229
+ if (n.touches.length !== 1)
230
+ return;
231
+ n.stopImmediatePropagation(), this.previousTouchCoords = {
232
+ x: n.touches[0].clientX,
233
+ y: n.touches[0].clientY
234
+ };
235
+ const h = this.graph.getNode(t.id);
236
+ this.options.onBeforeNodeDrag({
237
+ nodeId: t.id,
238
+ element: t.element,
239
+ x: h.x,
240
+ y: h.y
241
+ }) && (this.grabbedNodeId = t.id, this.moveNodeOnTop(t.id), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish));
242
+ };
243
+ this.nodes.set(t.id, {
244
+ element: t.element,
245
+ onMouseDown: o,
246
+ onTouchStart: r
247
+ }), t.element.addEventListener("mousedown", o), t.element.addEventListener("touchstart", r);
271
248
  }
272
- removeEdge(e) {
273
- if (this.graphStore.getEdge(e) === void 0)
274
- throw new E("failed to remove nonexisting edge");
275
- this.onBeforeEdgeRemovedEmitter.emit(e), this.graphStore.removeEdge(e);
249
+ updateNode(t, o) {
250
+ this.canvas.updateNode(t, o), this.updateMaxNodePriority(t);
276
251
  }
277
- unmarkPort(e) {
278
- if (this.graphStore.getPort(e) === void 0)
279
- throw new E("failed to unset nonexisting port");
280
- this.graphStore.getPortAdjacentEdgeIds(e).forEach((o) => {
281
- this.removeEdge(o);
282
- }), this.graphStore.removePort(e);
252
+ removeNode(t) {
253
+ const o = this.nodes.get(t);
254
+ o !== void 0 && (o.element.removeEventListener("mousedown", o.onMouseDown), o.element.removeEventListener("touchstart", o.onTouchStart)), this.nodes.delete(t), this.canvas.removeNode(t);
283
255
  }
284
- removeNode(e) {
285
- if (this.graphStore.getNode(e) === void 0)
286
- throw new E("failed to remove nonexisting node");
287
- this.graphStore.getNodePortIds(e).forEach((o) => {
288
- this.unmarkPort(o);
289
- }), this.onBeforeNodeRemovedEmitter.emit(e), this.graphStore.removeNode(e);
256
+ markPort(t) {
257
+ this.canvas.markPort(t);
258
+ }
259
+ updatePort(t, o) {
260
+ this.canvas.updatePort(t, o);
261
+ }
262
+ unmarkPort(t) {
263
+ this.canvas.unmarkPort(t);
264
+ }
265
+ addEdge(t) {
266
+ this.canvas.addEdge(t);
267
+ }
268
+ updateEdge(t, o) {
269
+ this.canvas.updateEdge(t, o);
270
+ }
271
+ removeEdge(t) {
272
+ this.canvas.removeEdge(t);
273
+ }
274
+ patchViewportMatrix(t) {
275
+ this.canvas.patchViewportMatrix(t);
276
+ }
277
+ patchContentMatrix(t) {
278
+ this.canvas.patchContentMatrix(t);
290
279
  }
291
280
  clear() {
292
- this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset();
281
+ this.canvas.clear(), this.nodes.forEach((t) => {
282
+ t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart);
283
+ }), this.nodes.clear(), this.maxNodePriority = 0;
293
284
  }
294
- }
295
- const ne = (t, e) => ({
296
- x: t / 2,
297
- y: e / 2
298
- }), v = (t, e, o) => ({
299
- x: e.x * t.x - e.y * t.y + ((1 - e.x) * o.x + e.y * o.y),
300
- y: e.y * t.x + e.x * t.y + ((1 - e.x) * o.y - e.y * o.x)
301
- }), T = (t, e, o) => ({ x: e * Math.cos(t), y: o * Math.sin(t) }), w = {
302
- x: 0,
303
- y: 0
304
- }, m = (t, e, o, r) => {
305
- const d = [
306
- w,
307
- { x: o, y: r },
308
- { x: o, y: -r }
309
- ].map((a) => v(a, t, w)).map((a) => ({ x: a.x + e.x, y: a.y + e.y })), s = `M ${d[0].x} ${d[0].y}`, h = `L ${d[1].x} ${d[1].y}`, c = `L ${d[2].x} ${d[2].y}`;
310
- return `${s} ${h} ${c}`;
311
- }, D = (t, e) => {
312
- const o = [];
313
- 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) {
314
- const r = t.length - 1;
315
- let n = 0, d = 0, s = 0;
316
- t.forEach((h, c) => {
317
- let a = 0, l = 0, g = 0;
318
- const f = c > 0, x = c < r, y = f && x;
319
- if (f && (a = -n, l = -d, g = s), x) {
320
- const C = t[c + 1];
321
- n = C.x - h.x, d = C.y - h.y, s = Math.sqrt(n * n + d * d);
322
- }
323
- const A = s !== 0 ? Math.min((y ? e : 0) / s, c < r - 1 ? 0.5 : 1) : 0, N = y ? { x: h.x + n * A, y: h.y + d * A } : h, V = g !== 0 ? Math.min((y ? e : 0) / g, c > 1 ? 0.5 : 1) : 0, b = y ? { x: h.x + a * V, y: h.y + l * V } : h;
324
- c > 0 && o.push(`L ${b.x} ${b.y}`), y && o.push(
325
- `C ${h.x} ${h.y} ${h.x} ${h.y} ${N.x} ${N.y}`
326
- );
285
+ destroy() {
286
+ this.detach(), this.clear(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
287
+ }
288
+ dragNode(t, o, r) {
289
+ const n = this.graph.getNode(t);
290
+ if (n === null)
291
+ return;
292
+ const h = this.canvas.viewport.getContentMatrix(), s = h.scale * n.x + h.x, c = h.scale * n.y + h.y, d = s + o, a = c + r, l = this.canvas.viewport.getViewportMatrix(), g = l.scale * d + l.x, y = l.scale * a + l.y;
293
+ this.canvas.updateNode(t, { x: g, y }), this.options.onNodeDrag({
294
+ nodeId: t,
295
+ element: n.element,
296
+ x: g,
297
+ y
327
298
  });
328
299
  }
329
- return o.join(" ");
330
- }, F = () => {
331
- const t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
332
- return t.style.pointerEvents = "none", t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.overflow = "visible", t;
333
- }, U = () => {
334
- const t = document.createElementNS("http://www.w3.org/2000/svg", "g");
335
- return t.style.transformOrigin = "50% 50%", t;
336
- }, B = (t, e) => {
337
- const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
338
- return o.setAttribute("stroke", t), o.setAttribute("stroke-width", `${e}`), o.setAttribute("fill", "none"), o;
339
- }, M = (t) => {
340
- const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
341
- return e.setAttribute("fill", t), e;
342
- }, k = (t, e) => {
343
- const o = {
344
- x: t.x + t.width / 2,
345
- y: t.y + t.height / 2
346
- }, r = {
347
- x: e.x + e.width / 2,
348
- y: e.y + e.height / 2
349
- }, n = Math.min(o.x, r.x), d = Math.min(o.y, r.y), s = Math.abs(r.x - o.x), h = Math.abs(r.y - o.y), c = o.x <= r.x ? 1 : -1, a = o.y <= r.y ? 1 : -1;
350
- return {
351
- x: n,
352
- y: d,
353
- width: s,
354
- height: h,
355
- flipX: c,
356
- flipY: a
300
+ updateMaxNodePriority(t) {
301
+ const o = this.graph.getNode(t).priority;
302
+ this.maxNodePriority = Math.max(this.maxNodePriority, o);
303
+ }
304
+ moveNodeOnTop(t) {
305
+ if (this.options.freezePriority)
306
+ return;
307
+ this.maxNodePriority += 2, this.updateNode(t, { priority: this.maxNodePriority });
308
+ const o = this.maxNodePriority - 1;
309
+ this.graph.getNodeAdjacentEdgeIds(t).forEach((n) => {
310
+ this.updateEdge(n, { priority: o });
311
+ });
312
+ }
313
+ cancelMouseDrag() {
314
+ const t = this.graph.getNode(this.grabbedNodeId);
315
+ t !== null && this.options.onNodeDragFinished({
316
+ nodeId: this.grabbedNodeId,
317
+ element: t.element,
318
+ x: t.x,
319
+ y: t.y
320
+ }), this.grabbedNodeId = null, this.element !== null && W(this.element, null), this.removeMouseDragListeners();
321
+ }
322
+ removeMouseDragListeners() {
323
+ this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
324
+ }
325
+ cancelTouchDrag() {
326
+ this.previousTouchCoords = null;
327
+ const t = this.graph.getNode(this.grabbedNodeId);
328
+ t !== null && this.options.onNodeDragFinished({
329
+ nodeId: this.grabbedNodeId,
330
+ element: t.element,
331
+ x: t.x,
332
+ y: t.y
333
+ }), this.grabbedNodeId = null, this.removeTouchDragListeners();
334
+ }
335
+ removeTouchDragListeners() {
336
+ this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
337
+ }
338
+ }
339
+ const ht = (e) => {
340
+ const t = e.minX !== null ? e.minX : -1 / 0, o = e.maxX !== null ? e.maxX : 1 / 0, r = e.minY !== null ? e.minY : -1 / 0, n = e.maxY !== null ? e.maxY : 1 / 0;
341
+ return (h) => {
342
+ let s = h.nextTransform.x, c = h.nextTransform.y;
343
+ s < t && s < h.prevTransform.x && (s = Math.min(h.prevTransform.x, t));
344
+ const d = h.canvasWidth * h.prevTransform.scale, a = o - d;
345
+ s > a && s > h.prevTransform.x && (s = Math.max(h.prevTransform.x, a)), c < r && c < h.prevTransform.y && (c = Math.min(h.prevTransform.y, r));
346
+ const l = h.canvasHeight * h.prevTransform.scale, g = n - l;
347
+ return c > g && c > h.prevTransform.y && (c = Math.max(h.prevTransform.y, g)), { scale: h.nextTransform.scale, x: s, y: c };
357
348
  };
358
- }, he = (t) => {
359
- const e = v(
360
- { x: t.arrowLength, y: w.y },
361
- t.fromVect,
362
- w
363
- ), o = v(
364
- { x: t.to.x - t.arrowLength, y: t.to.y },
365
- t.toVect,
366
- t.to
367
- ), r = {
368
- x: e.x + t.fromVect.x * t.curvature,
369
- y: e.y + t.fromVect.y * t.curvature
370
- }, n = {
371
- x: o.x - t.toVect.x * t.curvature,
372
- y: o.y - t.toVect.y * t.curvature
373
- }, d = `M ${e.x} ${e.y} C ${r.x} ${r.y}, ${n.x} ${n.y}, ${o.x} ${o.y}`, s = t.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${e.x} ${e.y} `, h = t.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${t.to.x} ${t.to.y}`;
374
- return `${s}${d}${h}`;
375
- }, de = (t) => {
376
- const e = t.hasSourceArrow ? v(
377
- { x: t.arrowLength, y: w.y },
378
- t.fromVect,
379
- w
380
- ) : w, o = t.hasTargetArrow ? v(
381
- { x: t.to.x - t.arrowLength, y: t.to.y },
382
- t.toVect,
383
- t.to
384
- ) : t.to, r = t.arrowLength, n = Math.cos(t.detourDirection) * t.detourDistance, d = Math.sin(t.detourDirection) * t.detourDistance, s = n * t.flipX, h = d * t.flipY, c = v(
385
- { x: r, y: w.y },
386
- t.fromVect,
387
- w
388
- ), a = {
389
- x: c.x + s,
390
- y: c.y + h
391
- }, l = v(
392
- { x: t.to.x - r, y: t.to.y },
393
- t.toVect,
394
- t.to
395
- ), g = {
396
- x: l.x + s,
397
- y: l.y + h
398
- }, f = { x: (a.x + g.x) / 2, y: (a.y + g.y) / 2 }, x = {
399
- x: c.x + t.curvature * t.fromVect.x,
400
- y: c.y + t.curvature * t.fromVect.y
401
- }, y = {
402
- x: l.x - t.curvature * t.toVect.x,
403
- y: l.y - t.curvature * t.toVect.y
404
- }, S = {
405
- x: c.x + s,
406
- y: c.y + h
407
- }, A = {
408
- x: l.x + s,
409
- y: l.y + h
349
+ }, ct = (e) => {
350
+ const t = e.maxContentScale, o = e.minContentScale, r = t !== null ? 1 / t : 0, n = o !== null ? 1 / o : 1 / 0;
351
+ return (h) => {
352
+ const s = h.prevTransform, c = h.nextTransform;
353
+ let d = c.scale, a = c.x, l = c.y;
354
+ if (c.scale > n && c.scale > s.scale) {
355
+ d = Math.max(s.scale, n), a = s.x, l = s.y;
356
+ const g = (d - s.scale) / (c.scale - s.scale);
357
+ a = s.x + (c.x - s.x) * g, l = s.y + (c.y - s.y) * g;
358
+ }
359
+ if (c.scale < r && c.scale < s.scale) {
360
+ d = Math.min(s.scale, r), a = s.x, l = s.y;
361
+ const g = (d - s.scale) / (c.scale - s.scale);
362
+ a = s.x + (c.x - s.x) * g, l = s.y + (c.y - s.y) * g;
363
+ }
364
+ return {
365
+ scale: d,
366
+ x: a,
367
+ y: l
368
+ };
410
369
  };
411
- return [
412
- `M ${e.x} ${e.y}`,
413
- `L ${c.x} ${c.y}`,
414
- `C ${x.x} ${x.y} ${S.x} ${S.y} ${f.x} ${f.y}`,
415
- `C ${A.x} ${A.y} ${y.x} ${y.y} ${l.x} ${l.y}`,
416
- `L ${o.x} ${o.y}`
417
- ].join(" ");
418
- }, ce = (t) => {
419
- const e = t.hasSourceArrow ? v(
420
- { x: t.arrowLength, y: w.y },
421
- t.fromVect,
422
- w
423
- ) : w, o = t.hasTargetArrow ? v(
424
- { x: t.to.x - t.arrowLength, y: t.to.y },
425
- t.toVect,
426
- t.to
427
- ) : t.to, r = t.arrowLength + t.arrowOffset, n = r - t.roundness, d = v({ x: n, y: w.y }, t.fromVect, w), s = v(
428
- { x: t.to.x - n, y: t.to.y },
429
- t.toVect,
430
- t.to
431
- ), h = Math.max((d.x + s.x) / 2, r), c = t.to.y / 2, a = { x: t.flipX > 0 ? h : -r, y: d.y }, l = { x: a.x, y: c }, g = {
432
- x: t.flipX > 0 ? t.to.x - h : t.to.x + r,
433
- y: s.y
434
- }, f = { x: g.x, y: c };
435
- return D(
436
- [e, d, a, l, f, g, s, o],
437
- t.roundness
438
- );
439
- }, X = (t) => {
440
- const e = t.hasSourceArrow ? v(
441
- { x: t.arrowLength, y: w.y },
442
- t.fromVect,
443
- w
444
- ) : w, o = t.hasTargetArrow ? v(
445
- { x: t.to.x - t.arrowLength, y: t.to.y },
446
- t.toVect,
447
- t.to
448
- ) : t.to, r = t.arrowLength + t.arrowOffset, n = v(
449
- { x: r, y: w.y },
450
- t.fromVect,
451
- w
452
- ), d = Math.cos(t.detourDirection) * t.detourDistance, s = Math.sin(t.detourDirection) * t.detourDistance, h = d * t.flipX, c = s * t.flipY, a = { x: n.x + h, y: n.y + c }, l = v(
453
- { x: t.to.x - r, y: t.to.y },
454
- t.toVect,
455
- t.to
456
- ), g = { x: l.x + h, y: l.y + c };
457
- return D(
458
- [e, n, a, g, l, o],
459
- t.roundness
460
- );
461
- }, ae = (t) => {
462
- const e = t.hasSourceArrow ? v(
463
- { x: t.arrowLength, y: w.y },
464
- t.fromVect,
465
- w
466
- ) : w, o = t.hasTargetArrow ? v(
467
- { x: t.to.x - t.arrowLength, y: t.to.y },
468
- t.toVect,
469
- t.to
470
- ) : t.to, r = t.arrowLength + t.arrowOffset, n = v({ x: r, y: w.y }, t.fromVect, w), d = v(
471
- { x: t.to.x - r, y: t.to.y },
472
- t.toVect,
473
- t.to
474
- );
475
- return D([e, n, d, o], t.roundness);
476
- }, le = (t) => {
477
- const e = t.hasSourceArrow ? v(
478
- { x: t.arrowLength, y: w.y },
479
- t.fromVect,
480
- w
481
- ) : w, o = t.hasTargetArrow ? v(
482
- { x: t.to.x - t.arrowLength, y: t.to.y },
483
- t.toVect,
484
- t.to
485
- ) : t.to, r = t.arrowLength + t.arrowOffset, n = r - t.roundness, d = v({ x: n, y: w.y }, t.fromVect, w), s = v(
486
- { x: t.to.x - n, y: t.to.y },
487
- t.toVect,
488
- t.to
489
- ), h = Math.max((d.y + s.y) / 2, r), c = t.to.x / 2, a = { x: d.x, y: t.flipY > 0 ? h : -r }, l = { x: c, y: a.y }, g = {
490
- x: s.x,
491
- y: t.flipY > 0 ? t.to.y - h : t.to.y + r
492
- }, f = { x: c, y: g.y };
493
- return D(
494
- [e, d, a, l, f, g, s, o],
495
- t.roundness
370
+ }, dt = (e) => (t) => e.reduce(
371
+ (o, r) => r({
372
+ prevTransform: t.prevTransform,
373
+ nextTransform: o,
374
+ canvasWidth: t.canvasWidth,
375
+ canvasHeight: t.canvasHeight
376
+ }),
377
+ t.nextTransform
378
+ ), _ = (e) => {
379
+ if (typeof e == "function")
380
+ return e;
381
+ switch (e.type) {
382
+ case "scale-limit":
383
+ return ct({
384
+ minContentScale: e.minContentScale ?? 0,
385
+ maxContentScale: e.maxContentScale ?? 1 / 0
386
+ });
387
+ case "shift-limit":
388
+ return ht({
389
+ minX: e.minX ?? -1 / 0,
390
+ maxX: e.maxX ?? 1 / 0,
391
+ minY: e.minY ?? -1 / 0,
392
+ maxY: e.maxY ?? 1 / 0
393
+ });
394
+ }
395
+ }, at = (e) => {
396
+ var v, A, S, T, z, L, D, P, U, j, G, K;
397
+ const t = (v = e == null ? void 0 : e.scale) == null ? void 0 : v.mouseWheelSensitivity, o = t !== void 0 ? t : 1.2, r = e == null ? void 0 : e.transformPreprocessor;
398
+ let n;
399
+ r !== void 0 ? Array.isArray(r) ? n = dt(
400
+ r.map(
401
+ (V) => _(V)
402
+ )
403
+ ) : n = _(r) : n = (V) => V.nextTransform;
404
+ const h = ((A = e == null ? void 0 : e.shift) == null ? void 0 : A.cursor) !== void 0 ? e.shift.cursor : "grab", s = ((S = e == null ? void 0 : e.events) == null ? void 0 : S.onBeforeTransformChange) ?? (() => {
405
+ }), c = ((T = e == null ? void 0 : e.events) == null ? void 0 : T.onTransformChange) ?? (() => {
406
+ }), d = (z = e == null ? void 0 : e.shift) == null ? void 0 : z.mouseDownEventVerifier, a = d !== void 0 ? d : (V) => V.button === 0, l = (L = e == null ? void 0 : e.shift) == null ? void 0 : L.mouseUpEventVerifier, g = l !== void 0 ? l : (V) => V.button === 0, y = (D = e == null ? void 0 : e.scale) == null ? void 0 : D.mouseWheelEventVerifier, x = y !== void 0 ? y : () => !0;
407
+ return {
408
+ wheelSensitivity: o,
409
+ onTransformStarted: ((P = e == null ? void 0 : e.events) == null ? void 0 : P.onTransformStarted) ?? (() => {
410
+ }),
411
+ onTransformFinished: ((U = e == null ? void 0 : e.events) == null ? void 0 : U.onTransformFinished) ?? (() => {
412
+ }),
413
+ onBeforeTransformChange: s,
414
+ onTransformChange: c,
415
+ transformPreprocessor: n,
416
+ shiftCursor: h,
417
+ mouseDownEventVerifier: a,
418
+ mouseUpEventVerifier: g,
419
+ mouseWheelEventVerifier: x,
420
+ scaleWheelFinishTimeout: ((j = e == null ? void 0 : e.scale) == null ? void 0 : j.wheelFinishTimeout) ?? 500,
421
+ onResizeTransformStarted: ((G = e == null ? void 0 : e.events) == null ? void 0 : G.onResizeTransformStarted) ?? (() => {
422
+ }),
423
+ onResizeTransformFinished: ((K = e == null ? void 0 : e.events) == null ? void 0 : K.onResizeTransformFinished) ?? (() => {
424
+ })
425
+ };
426
+ }, m = (e) => {
427
+ const t = [], o = e.touches.length;
428
+ for (let c = 0; c < o; c++)
429
+ t.push([e.touches[c].clientX, e.touches[c].clientY]);
430
+ const r = t.reduce(
431
+ (c, d) => [c[0] + d[0], c[1] + d[1]],
432
+ [0, 0]
433
+ ), n = [r[0] / o, r[1] / o], s = t.map((c) => [c[0] - n[0], c[1] - n[1]]).reduce(
434
+ (c, d) => c + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
435
+ 0
496
436
  );
497
- }, H = (t) => {
498
- const e = t.arrowOffset, o = t.side, r = t.arrowLength + e, n = r + 2 * o, s = [
499
- { x: t.arrowLength, y: w.y },
500
- { x: r, y: w.y },
501
- { x: r, y: t.side },
502
- { x: n, y: t.side },
503
- { x: n, y: -t.side },
504
- { x: r, y: -t.side },
505
- { x: r, y: w.y },
506
- { x: t.arrowLength, y: w.y }
507
- ].map(
508
- (c) => v(c, t.fromVect, w)
509
- ), h = `M ${w.x} ${w.y} L ${s[0].x} ${s[0].y} `;
510
- return `${t.hasSourceArrow || t.hasTargetArrow ? "" : h}${D(s, t.roundness)}`;
511
- }, ge = (t) => {
512
- const e = t.smallRadius, o = t.radius, r = Math.sqrt(e * e + o * o), n = e + o, d = t.arrowLength + r * (1 - o / n), s = e * o / n, c = [
513
- { x: t.arrowLength, y: w.y },
514
- { x: d, y: s },
515
- { x: d, y: -s }
516
- ].map((g) => v(g, t.fromVect, w)), a = [
517
- `M ${c[0].x} ${c[0].y}`,
518
- `A ${e} ${e} 0 0 1 ${c[1].x} ${c[1].y}`,
519
- `A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,
520
- `A ${e} ${e} 0 0 1 ${c[0].x} ${c[0].y}`
521
- ].join(" "), l = `M 0 0 L ${c[0].x} ${c[0].y} `;
522
- return `${t.hasSourceArrow || t.hasTargetArrow ? "" : l}${a}`;
523
- }, u = Object.freeze({
524
- color: "#777777",
525
- width: 1,
526
- arrowLength: 15,
527
- arrowWidth: 4,
528
- arrowOffset: 15,
529
- hasSourceArrow: !1,
530
- hasTargetArrow: !1,
531
- cycleRadius: 30,
532
- cycleSquareSide: 30,
533
- roundness: 10,
534
- detourDistance: 100,
535
- detourDirection: -Math.PI / 2,
536
- detourDirectionVertical: 0,
537
- smallCycleRadius: 15,
538
- curvature: 90
437
+ return {
438
+ x: n[0],
439
+ y: n[1],
440
+ scale: s / o,
441
+ touchesCnt: o,
442
+ touches: t
443
+ };
444
+ }, lt = (e, t, o) => ({
445
+ scale: e.scale,
446
+ x: e.x + e.scale * t,
447
+ y: e.y + e.scale * o
448
+ }), gt = (e, t, o, r) => ({
449
+ scale: e.scale * t,
450
+ x: e.scale * (1 - t) * o + e.x,
451
+ y: e.scale * (1 - t) * r + e.y
539
452
  });
540
- class ue {
541
- constructor(e) {
542
- i(this, "svg", F());
543
- i(this, "group", U());
544
- i(this, "line");
545
- i(this, "sourceArrow", null);
546
- i(this, "targetArrow", null);
547
- i(this, "arrowLength");
548
- i(this, "arrowWidth");
549
- i(this, "curvature");
550
- i(this, "portCycleRadius");
551
- i(this, "portCycleSmallRadius");
552
- i(this, "detourDirection");
553
- i(this, "detourDistance");
554
- i(this, "hasSourceArrow");
555
- i(this, "hasTargetArrow");
556
- this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.curvature = (e == null ? void 0 : e.curvature) ?? u.curvature, this.portCycleRadius = (e == null ? void 0 : e.cycleRadius) ?? u.cycleRadius, this.portCycleSmallRadius = (e == null ? void 0 : e.smallCycleRadius) ?? u.smallCycleRadius, this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow;
557
- const o = (e == null ? void 0 : e.color) ?? u.color, r = (e == null ? void 0 : e.width) ?? u.width;
558
- this.svg.appendChild(this.group), this.line = B(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));
559
- }
560
- render(e) {
561
- const { x: o, y: r, width: n, height: d, flipX: s, flipY: h } = k(
562
- e.from,
563
- e.to
564
- );
565
- this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${d}px`, this.group.style.transform = `scale(${s}, ${h})`;
566
- const c = T(
567
- e.from.direction,
568
- s,
569
- h
570
- ), a = T(e.to.direction, s, h), l = {
571
- x: n,
572
- y: d
573
- };
574
- let g, f = a, x = -this.arrowLength;
575
- if (e.from.portId === e.to.portId ? (g = ge({
576
- fromVect: c,
577
- radius: this.portCycleRadius,
578
- smallRadius: this.portCycleSmallRadius,
579
- arrowLength: this.arrowLength,
580
- hasSourceArrow: this.hasSourceArrow,
581
- hasTargetArrow: this.hasTargetArrow
582
- }), f = c, x = this.arrowLength) : e.from.nodeId === e.to.nodeId ? g = de({
583
- to: l,
584
- fromVect: c,
585
- toVect: a,
586
- flipX: s,
587
- flipY: h,
588
- arrowLength: this.arrowLength,
589
- detourDirection: this.detourDirection,
590
- detourDistance: this.detourDistance,
591
- curvature: this.curvature,
592
- hasSourceArrow: this.hasSourceArrow,
593
- hasTargetArrow: this.hasTargetArrow
594
- }) : g = he({
595
- to: l,
596
- fromVect: c,
597
- toVect: a,
598
- arrowLength: this.arrowLength,
599
- curvature: this.curvature,
600
- hasSourceArrow: this.hasSourceArrow,
601
- hasTargetArrow: this.hasTargetArrow
602
- }), this.line.setAttribute("d", g), this.sourceArrow) {
603
- const y = m(
604
- c,
605
- w,
606
- this.arrowLength,
607
- this.arrowWidth
608
- );
609
- this.sourceArrow.setAttribute("d", y);
610
- }
611
- if (this.targetArrow) {
612
- const y = m(
613
- f,
614
- l,
615
- x,
616
- this.arrowWidth
617
- );
618
- this.targetArrow.setAttribute("d", y);
619
- }
453
+ class O {
454
+ constructor(t, o) {
455
+ i(this, "graph");
456
+ i(this, "viewport");
457
+ i(this, "element", null);
458
+ i(this, "prevTouches", null);
459
+ i(this, "window", window);
460
+ i(this, "wheelFinishTimer", null);
461
+ i(this, "onMouseDown", (t) => {
462
+ this.element === null || !this.options.mouseDownEventVerifier(t) || (W(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.options.onTransformStarted());
463
+ });
464
+ i(this, "onWindowMouseMove", (t) => {
465
+ if (this.element === null || !C(this.element, t.clientX, t.clientY) || !$(this.window, t.clientX, t.clientY)) {
466
+ this.stopMouseDrag();
467
+ return;
468
+ }
469
+ const o = -t.movementX, r = -t.movementY;
470
+ this.moveViewport(this.element, o, r);
471
+ });
472
+ i(this, "onWindowMouseUp", (t) => {
473
+ this.element === null || !this.options.mouseUpEventVerifier(t) || this.stopMouseDrag();
474
+ });
475
+ i(this, "onWheelScroll", (t) => {
476
+ if (!this.options.mouseWheelEventVerifier(t))
477
+ return;
478
+ t.preventDefault();
479
+ const { left: o, top: r } = this.element.getBoundingClientRect(), n = t.clientX - o, h = t.clientY - r, c = 1 / (t.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
480
+ this.wheelFinishTimer === null && this.options.onTransformStarted(), this.scaleViewport(this.element, c, n, h), this.wheelFinishTimer !== null && clearTimeout(this.wheelFinishTimer), this.wheelFinishTimer = setTimeout(() => {
481
+ this.options.onTransformFinished(), this.wheelFinishTimer = null;
482
+ }, this.options.scaleWheelFinishTimeout);
483
+ });
484
+ i(this, "onTouchStart", (t) => {
485
+ if (this.prevTouches !== null) {
486
+ this.prevTouches = m(t);
487
+ return;
488
+ }
489
+ this.prevTouches = m(t), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish), this.options.onTransformStarted();
490
+ });
491
+ i(this, "onWindowTouchMove", (t) => {
492
+ const o = this.element;
493
+ if (o === null)
494
+ return;
495
+ const r = m(t);
496
+ if (!r.touches.every(
497
+ (h) => C(o, h[0], h[1]) && $(this.window, h[0], h[1])
498
+ )) {
499
+ this.stopTouchDrag();
500
+ return;
501
+ }
502
+ if ((r.touchesCnt === 1 || r.touchesCnt === 2) && this.moveViewport(
503
+ o,
504
+ -(r.x - this.prevTouches.x),
505
+ -(r.y - this.prevTouches.y)
506
+ ), r.touchesCnt === 2) {
507
+ const { left: h, top: s } = o.getBoundingClientRect(), c = this.prevTouches.x - h, d = this.prevTouches.y - s, l = 1 / (r.scale / this.prevTouches.scale);
508
+ this.scaleViewport(o, l, c, d);
509
+ }
510
+ this.prevTouches = r;
511
+ });
512
+ i(this, "onWindowTouchFinish", (t) => {
513
+ t.touches.length > 0 ? this.prevTouches = m(t) : this.stopTouchDrag();
514
+ });
515
+ i(this, "observer", new ResizeObserver(() => {
516
+ const t = this.canvas.viewport.getViewportMatrix(), { width: o, height: r } = this.element.getBoundingClientRect(), n = this.options.transformPreprocessor({
517
+ prevTransform: t,
518
+ nextTransform: t,
519
+ canvasWidth: o,
520
+ canvasHeight: r
521
+ });
522
+ this.options.onResizeTransformStarted(), this.canvas.patchViewportMatrix(n), this.options.onResizeTransformFinished();
523
+ }));
524
+ i(this, "options");
525
+ this.canvas = t, this.options = at(o), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph;
620
526
  }
621
- }
622
- class we {
623
- constructor(e) {
624
- i(this, "svg", F());
625
- i(this, "group", U());
626
- i(this, "line");
627
- i(this, "sourceArrow", null);
628
- i(this, "targetArrow", null);
629
- i(this, "arrowLength");
630
- i(this, "arrowWidth");
631
- i(this, "arrowOffset");
632
- i(this, "roundness");
633
- i(this, "cycleSquareSide");
634
- i(this, "detourDirection");
635
- i(this, "detourDistance");
636
- i(this, "hasSourceArrow");
637
- i(this, "hasTargetArrow");
638
- this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
639
- const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
640
- this.roundness = Math.min(
641
- o,
642
- this.arrowOffset,
643
- this.cycleSquareSide / 2
644
- ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow;
645
- const r = (e == null ? void 0 : e.color) ?? u.color, n = (e == null ? void 0 : e.width) ?? u.width;
646
- this.svg.appendChild(this.group), this.line = B(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));
647
- }
648
- render(e) {
649
- const { x: o, y: r, width: n, height: d, flipX: s, flipY: h } = k(
650
- e.from,
651
- e.to
652
- );
653
- this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${d}px`, this.group.style.transform = `scale(${s}, ${h})`;
654
- const c = T(
655
- e.from.direction,
656
- s,
657
- h
658
- ), a = T(e.to.direction, s, h), l = {
659
- x: n,
660
- y: d
661
- };
662
- let g, f = a, x = -this.arrowLength;
663
- if (e.from.portId === e.to.portId ? (g = H({
664
- fromVect: c,
665
- arrowLength: this.arrowLength,
666
- side: this.cycleSquareSide,
667
- arrowOffset: this.arrowOffset,
668
- roundness: this.roundness,
669
- hasSourceArrow: this.hasSourceArrow,
670
- hasTargetArrow: this.hasTargetArrow
671
- }), f = c, x = this.arrowLength) : e.from.nodeId === e.to.nodeId ? g = X({
672
- to: l,
673
- fromVect: c,
674
- toVect: a,
675
- flipX: s,
676
- flipY: h,
677
- arrowLength: this.arrowLength,
678
- arrowOffset: this.arrowOffset,
679
- roundness: this.roundness,
680
- detourDirection: this.detourDirection,
681
- detourDistance: this.detourDistance,
682
- hasSourceArrow: this.hasSourceArrow,
683
- hasTargetArrow: this.hasTargetArrow
684
- }) : g = ce({
685
- to: l,
686
- fromVect: c,
687
- toVect: a,
688
- flipX: s,
689
- arrowLength: this.arrowLength,
690
- arrowOffset: this.arrowOffset,
691
- roundness: this.roundness,
692
- hasSourceArrow: this.hasSourceArrow,
693
- hasTargetArrow: this.hasTargetArrow
694
- }), this.line.setAttribute("d", g), this.sourceArrow) {
695
- const y = m(
696
- c,
697
- w,
698
- this.arrowLength,
699
- this.arrowWidth
700
- );
701
- this.sourceArrow.setAttribute("d", y);
702
- }
703
- if (this.targetArrow) {
704
- const y = m(
705
- f,
706
- l,
707
- x,
708
- this.arrowWidth
709
- );
710
- this.targetArrow.setAttribute("d", y);
711
- }
527
+ attach(t) {
528
+ this.detach(), this.element = t, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.canvas.attach(this.element);
712
529
  }
713
- }
714
- class fe {
715
- constructor(e) {
716
- i(this, "svg", F());
717
- i(this, "group", U());
718
- i(this, "line");
719
- i(this, "sourceArrow", null);
720
- i(this, "targetArrow", null);
721
- i(this, "arrowLength");
722
- i(this, "arrowWidth");
723
- i(this, "arrowOffset");
724
- i(this, "roundness");
725
- i(this, "cycleSquareSide");
726
- i(this, "detourDirection");
727
- i(this, "detourDistance");
728
- i(this, "hasSourceArrow");
729
- i(this, "hasTargetArrow");
730
- this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
731
- const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
732
- this.roundness = Math.min(
733
- o,
734
- this.arrowOffset,
735
- this.cycleSquareSide / 2
736
- ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow;
737
- const r = (e == null ? void 0 : e.color) ?? u.color, n = (e == null ? void 0 : e.width) ?? u.width;
738
- this.svg.appendChild(this.group), this.line = B(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));
739
- }
740
- render(e) {
741
- const { x: o, y: r, width: n, height: d, flipX: s, flipY: h } = k(
742
- e.from,
743
- e.to
744
- );
745
- this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${d}px`, this.group.style.transform = `scale(${s}, ${h})`;
746
- const c = T(
747
- e.from.direction,
748
- s,
749
- h
750
- ), a = T(e.to.direction, s, h), l = {
751
- x: n,
752
- y: d
753
- };
754
- let g, f = a, x = -this.arrowLength;
755
- if (e.from.portId === e.to.portId ? (g = H({
756
- fromVect: c,
757
- arrowLength: this.arrowLength,
758
- side: this.cycleSquareSide,
759
- arrowOffset: this.arrowOffset,
760
- roundness: this.roundness,
761
- hasSourceArrow: this.hasSourceArrow,
762
- hasTargetArrow: this.hasTargetArrow
763
- }), f = c, x = this.arrowLength) : e.from.nodeId === e.to.nodeId ? g = X({
764
- to: l,
765
- fromVect: c,
766
- toVect: a,
767
- flipX: s,
768
- flipY: h,
769
- arrowLength: this.arrowLength,
770
- arrowOffset: this.arrowOffset,
771
- roundness: this.roundness,
772
- detourDirection: this.detourDirection,
773
- detourDistance: this.detourDistance,
774
- hasSourceArrow: this.hasSourceArrow,
775
- hasTargetArrow: this.hasTargetArrow
776
- }) : g = ae({
777
- to: l,
778
- fromVect: c,
779
- toVect: a,
780
- arrowLength: this.arrowLength,
781
- arrowOffset: this.arrowOffset,
782
- roundness: this.roundness,
783
- hasSourceArrow: this.hasSourceArrow,
784
- hasTargetArrow: this.hasTargetArrow
785
- }), this.line.setAttribute("d", g), this.sourceArrow) {
786
- const y = m(
787
- c,
788
- w,
789
- this.arrowLength,
790
- this.arrowWidth
791
- );
792
- this.sourceArrow.setAttribute("d", y);
793
- }
794
- if (this.targetArrow) {
795
- const y = m(
796
- f,
797
- l,
798
- x,
799
- this.arrowWidth
800
- );
801
- this.targetArrow.setAttribute("d", y);
802
- }
530
+ detach() {
531
+ 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);
803
532
  }
804
- }
805
- class ye {
806
- constructor(e) {
807
- i(this, "svg", F());
808
- i(this, "group", U());
809
- i(this, "line");
810
- i(this, "sourceArrow", null);
811
- i(this, "targetArrow", null);
812
- i(this, "arrowLength");
813
- i(this, "arrowWidth");
814
- i(this, "arrowOffset");
815
- i(this, "roundness");
816
- i(this, "cycleSquareSide");
817
- i(this, "detourDirection");
818
- i(this, "detourDistance");
819
- i(this, "hasSourceArrow");
820
- i(this, "hasTargetArrow");
821
- this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
822
- const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
823
- this.roundness = Math.min(
824
- o,
825
- this.arrowOffset,
826
- this.cycleSquareSide / 2
827
- ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirectionVertical, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow;
828
- const r = (e == null ? void 0 : e.color) ?? u.color, n = (e == null ? void 0 : e.width) ?? u.width;
829
- this.svg.appendChild(this.group), this.line = B(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));
830
- }
831
- render(e) {
832
- const { x: o, y: r, width: n, height: d, flipX: s, flipY: h } = k(
833
- e.from,
834
- e.to
835
- );
836
- this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${d}px`, this.group.style.transform = `scale(${s}, ${h})`;
837
- const c = T(
838
- e.from.direction,
839
- s,
840
- h
841
- ), a = T(e.to.direction, s, h), l = {
842
- x: n,
843
- y: d
844
- };
845
- let g, f = a, x = -this.arrowLength;
846
- if (e.from.portId === e.to.portId ? (g = H({
847
- fromVect: c,
848
- arrowLength: this.arrowLength,
849
- side: this.cycleSquareSide,
850
- arrowOffset: this.arrowOffset,
851
- roundness: this.roundness,
852
- hasSourceArrow: this.hasSourceArrow,
853
- hasTargetArrow: this.hasTargetArrow
854
- }), f = c, x = this.arrowLength) : e.from.nodeId === e.to.nodeId ? g = X({
855
- to: l,
856
- fromVect: c,
857
- toVect: a,
858
- flipX: s,
859
- flipY: h,
860
- arrowLength: this.arrowLength,
861
- arrowOffset: this.arrowOffset,
862
- roundness: this.roundness,
863
- detourDirection: this.detourDirection,
864
- detourDistance: this.detourDistance,
865
- hasSourceArrow: this.hasSourceArrow,
866
- hasTargetArrow: this.hasTargetArrow
867
- }) : g = le({
868
- to: l,
869
- fromVect: c,
870
- toVect: a,
871
- flipY: h,
872
- arrowLength: this.arrowLength,
873
- arrowOffset: this.arrowOffset,
874
- roundness: this.roundness,
875
- hasSourceArrow: this.hasSourceArrow,
876
- hasTargetArrow: this.hasTargetArrow
877
- }), this.line.setAttribute("d", g), this.sourceArrow) {
878
- const y = m(
879
- c,
880
- w,
881
- this.arrowLength,
882
- this.arrowWidth
883
- );
884
- this.sourceArrow.setAttribute("d", y);
885
- }
886
- if (this.targetArrow) {
887
- const y = m(
888
- f,
889
- l,
890
- x,
891
- this.arrowWidth
892
- );
893
- this.targetArrow.setAttribute("d", y);
894
- }
533
+ addNode(t) {
534
+ this.canvas.addNode(t);
895
535
  }
896
- }
897
- const ve = (t) => {
898
- if (typeof t == "function")
899
- return t;
900
- switch (t == null ? void 0 : t.type) {
901
- case "straight":
902
- return () => new fe({
903
- color: t.color,
904
- width: t.width,
905
- arrowLength: t.arrowLength,
906
- arrowWidth: t.arrowWidth,
907
- arrowOffset: t.arrowOffset,
908
- hasSourceArrow: t.hasSourceArrow,
909
- hasTargetArrow: t.hasTargetArrow,
910
- cycleSquareSide: t.cycleSquareSide,
911
- roundness: t.roundness,
912
- detourDistance: t.detourDistance,
913
- detourDirection: t.detourDirection
914
- });
915
- case "horizontal":
916
- return () => new we({
917
- color: t.color,
918
- width: t.width,
919
- arrowLength: t.arrowLength,
920
- arrowWidth: t.arrowWidth,
921
- arrowOffset: t.arrowOffset,
922
- hasSourceArrow: t.hasSourceArrow,
923
- hasTargetArrow: t.hasTargetArrow,
924
- cycleSquareSide: t.cycleSquareSide,
925
- roundness: t.roundness,
926
- detourDistance: t.detourDistance,
927
- detourDirection: t.detourDirection
928
- });
929
- case "vertical":
930
- return () => new ye({
931
- color: t.color,
932
- width: t.width,
933
- arrowLength: t.arrowLength,
934
- arrowWidth: t.arrowWidth,
935
- arrowOffset: t.arrowOffset,
936
- hasSourceArrow: t.hasSourceArrow,
937
- hasTargetArrow: t.hasTargetArrow,
938
- cycleSquareSide: t.cycleSquareSide,
939
- roundness: t.roundness,
940
- detourDistance: t.detourDistance,
941
- detourDirection: t.detourDirection
942
- });
943
- default:
944
- return () => new ue({
945
- color: t.color,
946
- width: t.width,
947
- arrowLength: t.arrowLength,
948
- arrowWidth: t.arrowWidth,
949
- hasSourceArrow: t.hasSourceArrow,
950
- hasTargetArrow: t.hasTargetArrow,
951
- cycleRadius: t.cycleRadius,
952
- smallCycleRadius: t.smallCycleRadius,
953
- curvature: t.curvature,
954
- detourDistance: t.detourDistance,
955
- detourDirection: t.detourDirection
956
- });
536
+ updateNode(t, o) {
537
+ this.canvas.updateNode(t, o);
957
538
  }
958
- }, Y = (t) => () => t, J = Y(0), xe = () => {
959
- let t = 0;
960
- return () => t++;
961
- }, Ee = (t, e) => {
962
- let o = J, r = J;
963
- const n = xe();
964
- 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), {
965
- nodesPriorityFn: o,
966
- edgesPriorityFn: r
967
- };
968
- }, Ae = (t) => {
969
- var o, r, n, d, s;
970
- const e = Ee(
971
- (o = t == null ? void 0 : t.nodes) == null ? void 0 : o.priority,
972
- (r = t == null ? void 0 : t.edges) == null ? void 0 : r.priority
973
- );
974
- return {
975
- nodes: {
976
- centerFn: ((n = t == null ? void 0 : t.nodes) == null ? void 0 : n.centerFn) ?? ne,
977
- priorityFn: e.nodesPriorityFn
978
- },
979
- ports: {
980
- direction: ((d = t == null ? void 0 : t.ports) == null ? void 0 : d.direction) ?? 0
981
- },
982
- edges: {
983
- shapeFactory: ve(((s = t == null ? void 0 : t.edges) == null ? void 0 : s.shape) ?? {}),
984
- priorityFn: e.edgesPriorityFn
985
- }
986
- };
987
- }, Q = (t) => ({
988
- scale: 1 / t.scale,
989
- x: -t.x / t.scale,
990
- y: -t.y / t.scale
991
- }), Z = {
992
- scale: 1,
993
- x: 0,
994
- y: 0
995
- };
996
- class pe {
997
- constructor() {
998
- i(this, "viewportMatrix", Z);
999
- i(this, "contentMatrix", Z);
1000
- i(this, "emitter");
1001
- i(this, "onAfterUpdate");
1002
- [this.emitter, this.onAfterUpdate] = p();
539
+ removeNode(t) {
540
+ this.canvas.removeNode(t);
1003
541
  }
1004
- getViewportMatrix() {
1005
- return this.viewportMatrix;
542
+ markPort(t) {
543
+ this.canvas.markPort(t);
1006
544
  }
1007
- getContentMatrix() {
1008
- return this.contentMatrix;
545
+ updatePort(t, o) {
546
+ this.canvas.updatePort(t, o);
1009
547
  }
1010
- patchViewportMatrix(e) {
1011
- this.viewportMatrix = {
1012
- scale: e.scale ?? this.viewportMatrix.scale,
1013
- x: e.x ?? this.viewportMatrix.x,
1014
- y: e.y ?? this.viewportMatrix.y
1015
- }, this.contentMatrix = Q(this.viewportMatrix), this.emitter.emit();
548
+ unmarkPort(t) {
549
+ this.canvas.unmarkPort(t);
1016
550
  }
1017
- patchContentMatrix(e) {
1018
- this.contentMatrix = {
1019
- scale: e.scale ?? this.contentMatrix.scale,
1020
- x: e.x ?? this.contentMatrix.x,
1021
- y: e.y ?? this.contentMatrix.y
1022
- }, this.viewportMatrix = Q(this.contentMatrix), this.emitter.emit();
551
+ addEdge(t) {
552
+ this.canvas.addEdge(t);
553
+ }
554
+ updateEdge(t, o) {
555
+ this.canvas.updateEdge(t, o);
556
+ }
557
+ removeEdge(t) {
558
+ this.canvas.removeEdge(t);
559
+ }
560
+ patchViewportMatrix(t) {
561
+ this.canvas.patchViewportMatrix(t);
562
+ }
563
+ patchContentMatrix(t) {
564
+ this.canvas.patchContentMatrix(t);
565
+ }
566
+ clear() {
567
+ this.canvas.clear();
568
+ }
569
+ destroy() {
570
+ this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
571
+ }
572
+ moveViewport(t, o, r) {
573
+ const n = this.viewport.getViewportMatrix(), h = lt(n, o, r), { width: s, height: c } = t.getBoundingClientRect(), d = this.options.transformPreprocessor({
574
+ prevTransform: n,
575
+ nextTransform: h,
576
+ canvasWidth: s,
577
+ canvasHeight: c
578
+ });
579
+ this.performTransform(d);
580
+ }
581
+ scaleViewport(t, o, r, n) {
582
+ const h = this.canvas.viewport.getViewportMatrix(), s = gt(h, o, r, n), { width: c, height: d } = t.getBoundingClientRect(), a = this.options.transformPreprocessor({
583
+ prevTransform: h,
584
+ nextTransform: s,
585
+ canvasWidth: c,
586
+ canvasHeight: d
587
+ });
588
+ this.performTransform(a);
589
+ }
590
+ stopMouseDrag() {
591
+ this.element !== null && W(this.element, null), this.removeMouseDragListeners(), this.options.onTransformFinished();
592
+ }
593
+ removeMouseDragListeners() {
594
+ this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
595
+ }
596
+ stopTouchDrag() {
597
+ this.prevTouches = null, this.removeTouchDragListeners(), this.options.onTransformFinished();
598
+ }
599
+ removeTouchDragListeners() {
600
+ this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
601
+ }
602
+ performTransform(t) {
603
+ this.options.onBeforeTransformChange(), this.canvas.patchViewportMatrix(t), this.options.onTransformChange();
1023
604
  }
1024
605
  }
1025
- class Se {
1026
- constructor(e) {
1027
- this.transformer = e;
606
+ class ut {
607
+ constructor() {
608
+ i(this, "keyMap", /* @__PURE__ */ new Map());
609
+ i(this, "valueMap", /* @__PURE__ */ new Map());
1028
610
  }
1029
- getViewportMatrix() {
1030
- return { ...this.transformer.getViewportMatrix() };
611
+ set(t, o) {
612
+ this.keyMap.set(t, o), this.valueMap.set(o, t);
1031
613
  }
1032
- getContentMatrix() {
1033
- return { ...this.transformer.getContentMatrix() };
614
+ hasKey(t) {
615
+ return this.keyMap.has(t);
616
+ }
617
+ hasValue(t) {
618
+ return this.valueMap.has(t);
619
+ }
620
+ getByKey(t) {
621
+ return this.keyMap.get(t);
622
+ }
623
+ getByValue(t) {
624
+ return this.valueMap.get(t);
625
+ }
626
+ deleteByKey(t) {
627
+ const o = this.keyMap.get(t);
628
+ o !== void 0 && this.valueMap.delete(o), this.keyMap.delete(t);
629
+ }
630
+ deleteByValue(t) {
631
+ const o = this.valueMap.get(t);
632
+ o !== void 0 && this.keyMap.delete(o), this.valueMap.delete(t);
633
+ }
634
+ forEach(t) {
635
+ this.keyMap.forEach((o, r) => {
636
+ t(o, r);
637
+ });
638
+ }
639
+ clear() {
640
+ this.keyMap.clear(), this.valueMap.clear();
1034
641
  }
1035
642
  }
1036
- class Ne {
1037
- constructor(e) {
1038
- this.graphStore = e;
643
+ class wt {
644
+ constructor(t) {
645
+ i(this, "viewport");
646
+ i(this, "graph");
647
+ i(this, "nodes", new ut());
648
+ i(this, "nodesResizeObserver");
649
+ i(this, "window", window);
650
+ this.canvas = t, this.nodesResizeObserver = new this.window.ResizeObserver((o) => {
651
+ o.forEach((r) => {
652
+ const n = r.target;
653
+ this.handleNodeResize(n);
654
+ });
655
+ }), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph;
1039
656
  }
1040
- getNode(e) {
1041
- const o = this.graphStore.getNode(e);
1042
- return o === void 0 ? null : {
1043
- element: o.element,
1044
- x: o.x,
1045
- y: o.y,
1046
- centerFn: o.centerFn,
1047
- priority: o.priority
1048
- };
657
+ attach(t) {
658
+ this.canvas.attach(t);
1049
659
  }
1050
- getAllNodeIds() {
1051
- return this.graphStore.getAllNodeIds();
660
+ detach() {
661
+ this.canvas.detach();
1052
662
  }
1053
- getPort(e) {
1054
- const o = this.graphStore.getPort(e);
1055
- return o === void 0 ? null : {
1056
- element: o.element,
1057
- direction: o.direction
1058
- };
663
+ addNode(t) {
664
+ this.canvas.addNode(t), this.nodes.set(t.id, t.element), this.nodesResizeObserver.observe(t.element);
1059
665
  }
1060
- getAllPortIds() {
1061
- return this.graphStore.getAllPortIds();
666
+ updateNode(t, o) {
667
+ this.canvas.updateNode(t, o);
1062
668
  }
1063
- getNodePortIds(e) {
1064
- return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodePortIds(e);
669
+ removeNode(t) {
670
+ this.canvas.removeNode(t);
671
+ const o = this.nodes.getByKey(t);
672
+ this.nodes.deleteByKey(t), this.nodesResizeObserver.unobserve(o);
1065
673
  }
1066
- getPortNodeId(e) {
1067
- return this.graphStore.getPortNodeId(e) ?? null;
674
+ markPort(t) {
675
+ this.canvas.markPort(t);
1068
676
  }
1069
- getAllEdgeIds() {
1070
- return this.graphStore.getAllEdgeIds();
677
+ updatePort(t, o) {
678
+ this.canvas.updatePort(t, o);
1071
679
  }
1072
- getEdge(e) {
1073
- const o = this.graphStore.getEdge(e);
1074
- return o === void 0 ? null : { from: o.from, to: o.to, priority: o.priority };
680
+ unmarkPort(t) {
681
+ this.canvas.unmarkPort(t);
1075
682
  }
1076
- getPortIncomingEdgeIds(e) {
1077
- return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortIncomingEdgeIds(e);
683
+ addEdge(t) {
684
+ this.canvas.addEdge(t);
1078
685
  }
1079
- getPortOutcomingEdgeIds(e) {
1080
- return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortOutcomingEdgeIds(e);
686
+ updateEdge(t, o) {
687
+ this.canvas.updateEdge(t, o);
1081
688
  }
1082
- getPortCycleEdgeIds(e) {
1083
- return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortCycleEdgeIds(e);
689
+ removeEdge(t) {
690
+ this.canvas.removeEdge(t);
1084
691
  }
1085
- getPortAdjacentEdgeIds(e) {
1086
- return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortAdjacentEdgeIds(e);
692
+ patchViewportMatrix(t) {
693
+ this.canvas.patchViewportMatrix(t);
1087
694
  }
1088
- getNodeIncomingEdgeIds(e) {
1089
- return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeIncomingEdgeIds(e);
695
+ patchContentMatrix(t) {
696
+ this.canvas.patchContentMatrix(t);
1090
697
  }
1091
- getNodeOutcomingEdgeIds(e) {
1092
- return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeOutcomingEdgeIds(e);
698
+ clear() {
699
+ this.canvas.clear(), this.nodesResizeObserver.disconnect(), this.nodes.clear();
1093
700
  }
1094
- getNodeCycleEdgeIds(e) {
1095
- return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeCycleEdgeIds(e);
701
+ destroy() {
702
+ this.clear(), this.canvas.destroy();
1096
703
  }
1097
- getNodeAdjacentEdgeIds(e) {
1098
- return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeAdjacentEdgeIds(e);
704
+ handleNodeResize(t) {
705
+ const o = this.nodes.getByValue(t);
706
+ this.canvas.updateNode(o, {}), this.graph.getNodeAdjacentEdgeIds(o).forEach((n) => {
707
+ this.canvas.updateEdge(n, {});
708
+ });
709
+ }
710
+ }
711
+ class yt {
712
+ constructor(t, o, r, n) {
713
+ i(this, "graph");
714
+ i(this, "viewport");
715
+ i(this, "canvas");
716
+ i(this, "element", null);
717
+ i(this, "canvasResizeObserver");
718
+ i(this, "window", window);
719
+ i(this, "nodeHorizontal");
720
+ i(this, "nodeVertical");
721
+ i(this, "viewportWidth", 0);
722
+ i(this, "viewportHeight", 0);
723
+ i(this, "viewportMatrix");
724
+ i(this, "loadedArea", {
725
+ xFrom: 1 / 0,
726
+ xTo: 1 / 0,
727
+ yFrom: 1 / 0,
728
+ yTo: 1 / 0
729
+ });
730
+ i(this, "updateLoadedArea", (t) => {
731
+ this.loadedArea = {
732
+ xFrom: t.x,
733
+ xTo: t.x + t.width,
734
+ yFrom: t.y,
735
+ yTo: t.y + t.height
736
+ };
737
+ });
738
+ var d, a;
739
+ 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) => {
740
+ const g = l[0];
741
+ this.viewportWidth = g.contentRect.width, this.viewportHeight = g.contentRect.height, this.scheduleLoadAreaAroundViewport();
742
+ });
743
+ const h = ((d = r == null ? void 0 : r.events) == null ? void 0 : d.onTransformFinished) ?? (() => {
744
+ }), s = ((a = r == null ? void 0 : r.events) == null ? void 0 : a.onTransformChange) ?? (() => {
745
+ }), c = {
746
+ ...r,
747
+ events: {
748
+ ...r == null ? void 0 : r.events,
749
+ onTransformChange: () => {
750
+ const l = this.viewportMatrix;
751
+ this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), l.scale !== this.viewportMatrix.scale && this.scheduleEnsureViewportAreaLoaded(), s();
752
+ },
753
+ onTransformFinished: () => {
754
+ this.scheduleLoadAreaAroundViewport(), h();
755
+ }
756
+ }
757
+ };
758
+ this.canvas = new O(
759
+ t,
760
+ c
761
+ ), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.trigger.subscribe(this.updateLoadedArea);
1099
762
  }
1100
- }
1101
- class Te {
1102
- constructor() {
1103
- i(this, "nodes", /* @__PURE__ */ new Map());
1104
- i(this, "ports", /* @__PURE__ */ new Map());
1105
- i(this, "nodePorts", /* @__PURE__ */ new Map());
1106
- i(this, "portNodeId", /* @__PURE__ */ new Map());
1107
- i(this, "edges", /* @__PURE__ */ new Map());
1108
- i(this, "incommingEdges", /* @__PURE__ */ new Map());
1109
- i(this, "outcommingEdges", /* @__PURE__ */ new Map());
1110
- i(this, "cycleEdges", /* @__PURE__ */ new Map());
763
+ attach(t) {
764
+ this.detach(), this.element = t, this.canvasResizeObserver.observe(this.element), this.canvas.attach(t);
1111
765
  }
1112
- addNode(e) {
1113
- this.nodes.set(e.nodeId, {
1114
- element: e.element,
1115
- x: e.x,
1116
- y: e.y,
1117
- centerFn: e.centerFn,
1118
- priority: e.priority
1119
- }), this.nodePorts.set(e.nodeId, /* @__PURE__ */ new Map());
766
+ detach() {
767
+ this.element !== null && (this.canvasResizeObserver.unobserve(this.element), this.element = null, this.viewportWidth = 0, this.viewportHeight = 0), this.canvas.detach();
1120
768
  }
1121
- getAllNodeIds() {
1122
- return Array.from(this.nodes.keys());
769
+ addNode(t) {
770
+ this.canvas.addNode(t);
1123
771
  }
1124
- getNode(e) {
1125
- return this.nodes.get(e);
772
+ updateNode(t, o) {
773
+ this.canvas.updateNode(t, o);
1126
774
  }
1127
- removeNode(e) {
1128
- this.nodes.delete(e), this.nodePorts.delete(e);
775
+ removeNode(t) {
776
+ this.canvas.removeNode(t);
1129
777
  }
1130
- addPort(e) {
1131
- this.ports.set(e.portId, {
1132
- element: e.element,
1133
- direction: e.direction
1134
- }), this.cycleEdges.set(e.portId, /* @__PURE__ */ new Set()), this.incommingEdges.set(e.portId, /* @__PURE__ */ new Set()), this.outcommingEdges.set(e.portId, /* @__PURE__ */ new Set()), this.portNodeId.set(e.portId, e.nodeId), this.nodePorts.get(e.nodeId).set(e.portId, e.element);
778
+ markPort(t) {
779
+ this.canvas.markPort(t);
1135
780
  }
1136
- getPort(e) {
1137
- return this.ports.get(e);
781
+ updatePort(t, o) {
782
+ this.canvas.updatePort(t, o);
1138
783
  }
1139
- getAllPortIds() {
1140
- return Array.from(this.ports.keys());
784
+ unmarkPort(t) {
785
+ this.canvas.unmarkPort(t);
1141
786
  }
1142
- getNodePortIds(e) {
1143
- const o = this.nodePorts.get(e);
1144
- if (o !== void 0)
1145
- return Array.from(o.keys());
1146
- }
1147
- getPortNodeId(e) {
1148
- return this.portNodeId.get(e);
1149
- }
1150
- removePort(e) {
1151
- const o = this.portNodeId.get(e);
1152
- this.portNodeId.delete(e), this.nodePorts.get(o).delete(e), this.ports.delete(e);
1153
- }
1154
- addEdge(e) {
1155
- this.edges.set(e.edgeId, {
1156
- from: e.from,
1157
- to: e.to,
1158
- shape: e.shape,
1159
- priority: e.priority
1160
- }), e.from !== e.to ? (this.outcommingEdges.get(e.from).add(e.edgeId), this.incommingEdges.get(e.to).add(e.edgeId)) : this.cycleEdges.get(e.from).add(e.edgeId);
1161
- }
1162
- updateEdgeFrom(e, o) {
1163
- const r = this.edges.get(e);
1164
- this.removeEdge(e), this.addEdge({
1165
- edgeId: e,
1166
- from: o,
1167
- to: r.to,
1168
- shape: r.shape,
1169
- priority: r.priority
1170
- });
787
+ addEdge(t) {
788
+ this.canvas.addEdge(t);
1171
789
  }
1172
- updateEdgeTo(e, o) {
1173
- const r = this.edges.get(e);
1174
- this.removeEdge(e), this.addEdge({
1175
- edgeId: e,
1176
- from: r.from,
1177
- to: o,
1178
- shape: r.shape,
1179
- priority: r.priority
1180
- });
790
+ updateEdge(t, o) {
791
+ this.canvas.updateEdge(t, o);
1181
792
  }
1182
- getAllEdgeIds() {
1183
- return Array.from(this.edges.keys());
793
+ removeEdge(t) {
794
+ this.canvas.removeEdge(t);
1184
795
  }
1185
- getEdge(e) {
1186
- return this.edges.get(e);
796
+ patchViewportMatrix(t) {
797
+ this.canvas.patchViewportMatrix(t), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.loadAreaAroundViewport();
1187
798
  }
1188
- removeEdge(e) {
1189
- const o = this.edges.get(e), r = o.from, n = o.to;
1190
- 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);
799
+ patchContentMatrix(t) {
800
+ this.canvas.patchContentMatrix(t), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.loadAreaAroundViewport();
1191
801
  }
1192
802
  clear() {
1193
- this.edges.clear(), this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear(), this.ports.clear(), this.nodePorts.clear(), this.portNodeId.clear(), this.nodes.clear();
1194
- }
1195
- getPortIncomingEdgeIds(e) {
1196
- return Array.from(this.incommingEdges.get(e));
1197
- }
1198
- getPortOutcomingEdgeIds(e) {
1199
- return Array.from(this.outcommingEdges.get(e));
1200
- }
1201
- getPortCycleEdgeIds(e) {
1202
- return Array.from(this.cycleEdges.get(e));
1203
- }
1204
- getPortAdjacentEdgeIds(e) {
1205
- return [
1206
- ...this.getPortIncomingEdgeIds(e),
1207
- ...this.getPortOutcomingEdgeIds(e),
1208
- ...this.getPortCycleEdgeIds(e)
1209
- ];
1210
- }
1211
- getNodeIncomingEdgeIds(e) {
1212
- const o = Array.from(this.nodePorts.get(e).keys());
1213
- let r = [];
1214
- return o.forEach((n) => {
1215
- r = [...r, ...this.getPortIncomingEdgeIds(n)];
1216
- }), r;
803
+ this.canvas.clear();
1217
804
  }
1218
- getNodeOutcomingEdgeIds(e) {
1219
- const o = Array.from(this.nodePorts.get(e).keys());
1220
- let r = [];
1221
- return o.forEach((n) => {
1222
- r = [...r, ...this.getPortOutcomingEdgeIds(n)];
1223
- }), r;
805
+ destroy() {
806
+ this.trigger.unsubscribe(this.updateLoadedArea), this.canvas.destroy();
1224
807
  }
1225
- getNodeCycleEdgeIds(e) {
1226
- const o = Array.from(this.nodePorts.get(e).keys());
1227
- let r = [];
1228
- return o.forEach((n) => {
1229
- r = [...r, ...this.getPortCycleEdgeIds(n)];
1230
- }), r;
808
+ scheduleLoadAreaAroundViewport() {
809
+ setTimeout(() => {
810
+ this.loadAreaAroundViewport();
811
+ });
1231
812
  }
1232
- getNodeAdjacentEdgeIds(e) {
1233
- return [
1234
- ...this.getNodeIncomingEdgeIds(e),
1235
- ...this.getNodeOutcomingEdgeIds(e),
1236
- ...this.getNodeCycleEdgeIds(e)
1237
- ];
813
+ scheduleEnsureViewportAreaLoaded() {
814
+ const t = 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 + t + this.nodeHorizontal, s = this.viewportMatrix.y + o + this.nodeVertical;
815
+ this.loadedArea.xFrom < r && this.loadedArea.xTo > h && this.loadedArea.yFrom < n && this.loadedArea.yTo > s || this.scheduleLoadAreaAroundViewport();
1238
816
  }
1239
- }
1240
- class me {
1241
- constructor(e, o) {
1242
- i(this, "viewport");
1243
- i(this, "graph");
1244
- i(this, "viewportTransformer");
1245
- i(this, "graphStore");
1246
- i(this, "htmlView");
1247
- i(this, "graphStoreController");
1248
- this.graphStore = new Te(), this.graph = new Ne(this.graphStore), this.viewportTransformer = new pe(), this.viewport = new Se(this.viewportTransformer), this.htmlView = o(this.graphStore, this.viewportTransformer), this.graphStoreController = new se(
1249
- this.graphStore,
1250
- Ae(e)
1251
- );
817
+ loadAreaAroundViewport() {
818
+ const t = this.viewportWidth * this.viewportMatrix.scale, o = this.viewportHeight * this.viewportMatrix.scale, r = this.viewportMatrix.x - t - this.nodeHorizontal, n = this.viewportMatrix.y - o - this.nodeVertical, h = 3 * t + 2 * this.nodeHorizontal, s = 3 * o + 2 * this.nodeVertical;
819
+ this.trigger.emit({ x: r, y: n, width: h, height: s });
1252
820
  }
1253
821
  }
1254
- const Me = () => {
1255
- const t = document.createElement("div");
1256
- return t.style.width = "100%", t.style.height = "100%", t.style.position = "relative", t.style.overflow = "hidden", t;
1257
- }, Pe = () => {
1258
- const t = document.createElement("div");
1259
- return t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.width = "0", t.style.height = "0", t;
1260
- }, Ve = () => {
1261
- const t = document.createElement("div");
1262
- return t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.visibility = "hidden", t;
822
+ const vt = () => {
823
+ const e = document.createElement("div");
824
+ return e.style.width = "100%", e.style.height = "100%", e.style.position = "relative", e.style.overflow = "hidden", e;
825
+ }, ft = () => {
826
+ const e = document.createElement("div");
827
+ return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.width = "0", e.style.height = "0", e;
828
+ }, xt = () => {
829
+ const e = document.createElement("div");
830
+ return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.visibility = "hidden", e;
1263
831
  };
1264
- class ee {
1265
- constructor(e, o) {
832
+ class Et {
833
+ constructor(t, o) {
1266
834
  i(this, "canvasWrapper", null);
1267
- i(this, "host", Me());
1268
- i(this, "container", Pe());
835
+ i(this, "host", vt());
836
+ i(this, "container", ft());
1269
837
  i(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
1270
838
  i(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
1271
839
  i(this, "applyTransform", () => {
1272
- const e = this.viewportTransformer.getContentMatrix();
1273
- this.container.style.transform = `matrix(${e.scale}, 0, 0, ${e.scale}, ${e.x}, ${e.y})`;
840
+ const t = this.viewportStore.getContentMatrix();
841
+ this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.x}, ${t.y})`;
1274
842
  });
1275
- this.graphStore = e, this.viewportTransformer = o, this.host.appendChild(this.container), this.viewportTransformer.onAfterUpdate.subscribe(this.applyTransform);
843
+ this.graphStore = t, this.viewportStore = o, this.host.appendChild(this.container), this.viewportStore.onAfterUpdate.subscribe(this.applyTransform);
1276
844
  }
1277
- attach(e) {
1278
- this.detach(), this.canvasWrapper = e, this.canvasWrapper.appendChild(this.host);
845
+ attach(t) {
846
+ this.detach(), this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
1279
847
  }
1280
848
  detach() {
1281
849
  this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
1282
850
  }
1283
- attachNode(e) {
1284
- const o = this.graphStore.getNode(e), r = Ve();
1285
- r.appendChild(o.element), this.container.appendChild(r), this.nodeIdToWrapperElementMap.set(e, r), this.updateNodeCoordinates(e), this.updateNodePriority(e), r.style.visibility = "visible";
851
+ attachNode(t) {
852
+ const o = this.graphStore.getNode(t), r = xt();
853
+ r.appendChild(o.element), this.container.appendChild(r), this.nodeIdToWrapperElementMap.set(t, r), this.updateNodeCoordinates(t), this.updateNodePriority(t), r.style.visibility = "visible";
1286
854
  }
1287
- detachNode(e) {
1288
- const o = this.graphStore.getNode(e), r = this.nodeIdToWrapperElementMap.get(e);
1289
- r.removeChild(o.element), this.container.removeChild(r), this.nodeIdToWrapperElementMap.delete(e);
855
+ detachNode(t) {
856
+ const o = this.nodeIdToWrapperElementMap.get(t);
857
+ o.removeChild(o.firstChild), this.container.removeChild(o), this.nodeIdToWrapperElementMap.delete(t);
1290
858
  }
1291
- attachEdge(e) {
1292
- const o = this.graphStore.getEdge(e);
1293
- this.edgeIdToElementMap.set(e, o.shape.svg), this.container.appendChild(o.shape.svg), this.renderEdge(e), this.updateEdgePriority(e);
859
+ attachEdge(t) {
860
+ const o = this.graphStore.getEdge(t).shape.svg;
861
+ this.edgeIdToElementMap.set(t, o), this.container.appendChild(o), this.renderEdge(t), this.updateEdgePriority(t);
1294
862
  }
1295
- detachEdge(e) {
1296
- const o = this.graphStore.getEdge(e);
1297
- this.container.removeChild(o.shape.svg), this.edgeIdToElementMap.delete(e);
863
+ detachEdge(t) {
864
+ const o = this.edgeIdToElementMap.get(t);
865
+ this.container.removeChild(o), this.edgeIdToElementMap.delete(t);
1298
866
  }
1299
867
  clear() {
1300
- this.edgeIdToElementMap.forEach((e, o) => {
868
+ this.edgeIdToElementMap.forEach((t, o) => {
1301
869
  this.detachEdge(o);
1302
- }), this.nodeIdToWrapperElementMap.forEach((e, o) => {
870
+ }), this.nodeIdToWrapperElementMap.forEach((t, o) => {
1303
871
  this.detachNode(o);
1304
872
  });
1305
873
  }
1306
874
  destroy() {
1307
- this.clear(), this.detach(), this.viewportTransformer.onAfterUpdate.unsubscribe(this.applyTransform), this.host.removeChild(this.container);
875
+ this.viewportStore.onAfterUpdate.unsubscribe(this.applyTransform), this.clear(), this.detach(), this.host.removeChild(this.container);
1308
876
  }
1309
- updateNodeCoordinates(e) {
1310
- const o = this.nodeIdToWrapperElementMap.get(e), r = this.graphStore.getNode(e), { width: n, height: d } = r.element.getBoundingClientRect(), s = this.viewportTransformer.getViewportMatrix().scale, h = r.centerFn(n, d), c = r.x - s * h.x, a = r.y - s * h.y;
1311
- o.style.transform = `translate(${c}px, ${a}px)`;
877
+ updateNodeCoordinates(t) {
878
+ const o = this.nodeIdToWrapperElementMap.get(t), r = this.graphStore.getNode(t), { width: n, height: h } = r.element.getBoundingClientRect(), s = this.viewportStore.getViewportMatrix().scale, c = r.centerFn(n, h), d = r.x - s * c.x, a = r.y - s * c.y;
879
+ o.style.transform = `translate(${d}px, ${a}px)`;
1312
880
  }
1313
- updateNodePriority(e) {
1314
- const o = this.graphStore.getNode(e), r = this.nodeIdToWrapperElementMap.get(e);
881
+ updateNodePriority(t) {
882
+ const o = this.graphStore.getNode(t), r = this.nodeIdToWrapperElementMap.get(t);
1315
883
  r.style.zIndex = `${o.priority}`;
1316
884
  }
1317
- updateEdgeShape(e) {
1318
- const o = this.edgeIdToElementMap.get(e);
885
+ updateEdgeShape(t) {
886
+ const o = this.edgeIdToElementMap.get(t);
1319
887
  this.container.removeChild(o);
1320
- const r = this.graphStore.getEdge(e);
1321
- this.edgeIdToElementMap.set(e, r.shape.svg), this.container.appendChild(r.shape.svg);
888
+ const r = this.graphStore.getEdge(t);
889
+ this.edgeIdToElementMap.set(t, r.shape.svg), this.container.appendChild(r.shape.svg);
1322
890
  }
1323
- renderEdge(e) {
1324
- const o = this.graphStore.getEdge(e), r = this.graphStore.getPort(o.from), n = this.graphStore.getPort(o.to), d = r.element.getBoundingClientRect(), s = n.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), c = this.viewportTransformer.getViewportMatrix(), a = {
1325
- x: c.scale * (d.left - h.left) + c.x,
1326
- y: c.scale * (d.top - h.top) + c.y
891
+ renderEdge(t) {
892
+ const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from), n = this.graphStore.getPort(o.to), h = r.element.getBoundingClientRect(), s = n.element.getBoundingClientRect(), c = this.host.getBoundingClientRect(), d = this.viewportStore.getViewportMatrix(), a = {
893
+ x: d.scale * (h.left - c.left) + d.x,
894
+ y: d.scale * (h.top - c.top) + d.y
1327
895
  }, l = {
1328
- x: c.scale * (s.left - h.left) + c.x,
1329
- y: c.scale * (s.top - h.top) + c.y
896
+ x: d.scale * (s.left - c.left) + d.x,
897
+ y: d.scale * (s.top - c.top) + d.y
1330
898
  }, g = {
1331
899
  x: a.x,
1332
900
  y: a.y,
1333
- width: d.width * c.scale,
1334
- height: d.height * c.scale,
901
+ width: h.width * d.scale,
902
+ height: h.height * d.scale,
1335
903
  direction: r.direction,
1336
904
  portId: o.from,
1337
- nodeId: this.graphStore.getPortNodeId(o.from)
1338
- }, f = {
905
+ nodeId: r.nodeId
906
+ }, y = {
1339
907
  x: l.x,
1340
908
  y: l.y,
1341
- width: s.width * c.scale,
1342
- height: s.height * c.scale,
909
+ width: s.width * d.scale,
910
+ height: s.height * d.scale,
1343
911
  direction: n.direction,
1344
912
  portId: o.to,
1345
- nodeId: this.graphStore.getPortNodeId(o.to)
913
+ nodeId: n.nodeId
1346
914
  };
1347
915
  o.shape.render({
1348
916
  from: g,
1349
- to: f
917
+ to: y
1350
918
  });
1351
919
  }
1352
- updateEdgePriority(e) {
1353
- const o = this.graphStore.getEdge(e);
920
+ updateEdgePriority(t) {
921
+ const o = this.graphStore.getEdge(t);
1354
922
  o.shape.svg.style.zIndex = `${o.priority}`;
1355
923
  }
1356
924
  }
1357
- class be {
1358
- constructor(e) {
925
+ class St {
926
+ constructor(t) {
1359
927
  i(this, "xFrom", 1 / 0);
1360
928
  i(this, "yFrom", 1 / 0);
1361
929
  i(this, "xTo", 1 / 0);
1362
930
  i(this, "yTo", 1 / 0);
1363
- this.graphStore = e;
931
+ this.graphStore = t;
1364
932
  }
1365
- setRenderingBox(e) {
1366
- this.xFrom = e.x, this.xTo = e.x + e.width, this.yFrom = e.y, this.yTo = e.y + e.height;
933
+ setRenderingBox(t) {
934
+ this.xFrom = t.x, this.xTo = t.x + t.width, this.yFrom = t.y, this.yTo = t.y + t.height;
1367
935
  }
1368
- hasNode(e) {
1369
- const o = this.graphStore.getNode(e);
936
+ hasNode(t) {
937
+ const o = this.graphStore.getNode(t);
1370
938
  return o.x >= this.xFrom && o.x <= this.xTo && o.y >= this.yFrom && o.y <= this.yTo;
1371
939
  }
1372
- hasEdge(e) {
1373
- const o = this.graphStore.getEdge(e), r = this.graphStore.getPortNodeId(o.from), n = this.graphStore.getPortNodeId(o.to), d = this.graphStore.getNode(r), s = this.graphStore.getNode(n), h = Math.min(d.x, s.x), c = Math.max(d.x, s.x), a = Math.min(d.y, s.y), l = Math.max(d.y, s.y);
1374
- return h <= this.xTo && c >= this.xFrom && a <= this.yTo && l >= this.yFrom;
940
+ hasEdge(t) {
941
+ const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from).nodeId, n = this.graphStore.getPort(o.to).nodeId, h = this.graphStore.getNode(r), s = this.graphStore.getNode(n), c = Math.min(h.x, s.x), d = Math.max(h.x, s.x), a = Math.min(h.y, s.y), l = Math.max(h.y, s.y);
942
+ return c <= this.xTo && d >= this.xFrom && a <= this.yTo && l >= this.yFrom;
1375
943
  }
1376
944
  }
1377
- class Ce {
1378
- constructor(e, o, r) {
945
+ class At {
946
+ constructor(t, o, r) {
1379
947
  i(this, "attachedNodes", /* @__PURE__ */ new Set());
1380
948
  i(this, "attachedEdges", /* @__PURE__ */ new Set());
1381
949
  i(this, "renderingBox");
1382
- i(this, "updateViewport", (e) => {
1383
- this.renderingBox.setRenderingBox(e);
1384
- const o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
950
+ i(this, "updateViewport", (t) => {
951
+ this.renderingBox.setRenderingBox(t);
952
+ const o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set();
1385
953
  this.graphStore.getAllNodeIds().forEach((s) => {
1386
- const h = this.renderingBox.hasNode(s), c = this.attachedNodes.has(s);
1387
- h && !c ? o.add(s) : !h && c && r.add(s);
954
+ const c = this.renderingBox.hasNode(s), d = this.attachedNodes.has(s);
955
+ c && !d ? o.add(s) : !c && d && r.add(s);
1388
956
  }), this.graphStore.getAllEdgeIds().forEach((s) => {
1389
- const h = this.renderingBox.hasEdge(s), c = this.attachedEdges.has(s), a = this.graphStore.getEdge(s), l = this.graphStore.getPortNodeId(a.from), g = this.graphStore.getPortNodeId(a.to);
1390
- h && (this.renderingBox.hasNode(l) || (o.add(l), r.delete(l)), this.renderingBox.hasNode(g) || (o.add(g), r.delete(g))), h && !c ? n.add(s) : !h && c && d.add(s);
1391
- }), d.forEach((s) => {
957
+ const c = this.renderingBox.hasEdge(s), d = this.attachedEdges.has(s), a = this.graphStore.getEdge(s), l = this.graphStore.getPort(a.from).nodeId, g = this.graphStore.getPort(a.to).nodeId;
958
+ c && (this.renderingBox.hasNode(l) || (o.add(l), r.delete(l)), this.renderingBox.hasNode(g) || (o.add(g), r.delete(g))), c && !d ? n.add(s) : !c && d && h.add(s);
959
+ }), h.forEach((s) => {
1392
960
  this.handleDetachEdge(s);
1393
961
  }), r.forEach((s) => {
1394
962
  this.handleDetachNode(s);
@@ -1398,42 +966,42 @@ class Ce {
1398
966
  this.handleAttachEdge(s);
1399
967
  });
1400
968
  });
1401
- this.htmlView = e, this.graphStore = o, this.trigger = r, this.renderingBox = new be(this.graphStore), this.trigger.subscribe(this.updateViewport);
969
+ this.htmlView = t, this.graphStore = o, this.trigger = r, this.renderingBox = new St(this.graphStore), this.trigger.subscribe(this.updateViewport);
1402
970
  }
1403
- attach(e) {
1404
- this.htmlView.attach(e);
971
+ attach(t) {
972
+ this.htmlView.attach(t);
1405
973
  }
1406
974
  detach() {
1407
975
  this.htmlView.detach();
1408
976
  }
1409
- attachNode(e) {
1410
- this.renderingBox.hasNode(e) && this.handleAttachNode(e);
977
+ attachNode(t) {
978
+ this.renderingBox.hasNode(t) && this.handleAttachNode(t);
1411
979
  }
1412
- detachNode(e) {
1413
- this.attachedNodes.has(e) && this.handleDetachNode(e);
980
+ detachNode(t) {
981
+ this.attachedNodes.has(t) && this.handleDetachNode(t);
1414
982
  }
1415
- attachEdge(e) {
1416
- this.renderingBox.hasEdge(e) && this.attachEdgeEntities(e);
983
+ attachEdge(t) {
984
+ this.renderingBox.hasEdge(t) && this.attachEdgeEntities(t);
1417
985
  }
1418
- detachEdge(e) {
1419
- this.attachedEdges.has(e) && this.handleDetachEdge(e);
986
+ detachEdge(t) {
987
+ this.attachedEdges.has(t) && this.handleDetachEdge(t);
1420
988
  }
1421
- updateNodeCoordinates(e) {
1422
- this.attachedNodes.has(e) ? this.htmlView.updateNodeCoordinates(e) : this.renderingBox.hasNode(e) && (this.handleAttachNode(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((o) => {
989
+ updateNodeCoordinates(t) {
990
+ this.attachedNodes.has(t) ? this.htmlView.updateNodeCoordinates(t) : this.renderingBox.hasNode(t) && (this.handleAttachNode(t), this.graphStore.getNodeAdjacentEdgeIds(t).forEach((o) => {
1423
991
  this.attachEdgeEntities(o);
1424
992
  }));
1425
993
  }
1426
- updateNodePriority(e) {
1427
- this.attachedNodes.has(e) && this.htmlView.updateNodePriority(e);
994
+ updateNodePriority(t) {
995
+ this.attachedNodes.has(t) && this.htmlView.updateNodePriority(t);
1428
996
  }
1429
- updateEdgeShape(e) {
1430
- this.attachedEdges.has(e) && this.htmlView.updateEdgeShape(e);
997
+ updateEdgeShape(t) {
998
+ this.attachedEdges.has(t) && this.htmlView.updateEdgeShape(t);
1431
999
  }
1432
- renderEdge(e) {
1433
- this.attachedEdges.has(e) && this.htmlView.renderEdge(e);
1000
+ renderEdge(t) {
1001
+ this.attachedEdges.has(t) && this.htmlView.renderEdge(t);
1434
1002
  }
1435
- updateEdgePriority(e) {
1436
- this.attachedEdges.has(e) && this.htmlView.updateEdgePriority(e);
1003
+ updateEdgePriority(t) {
1004
+ this.attachedEdges.has(t) && this.htmlView.updateEdgePriority(t);
1437
1005
  }
1438
1006
  clear() {
1439
1007
  this.htmlView.clear(), this.attachedNodes.clear(), this.attachedEdges.clear();
@@ -1441,715 +1009,1108 @@ class Ce {
1441
1009
  destroy() {
1442
1010
  this.clear(), this.htmlView.destroy(), this.trigger.unsubscribe(this.updateViewport);
1443
1011
  }
1444
- attachEdgeEntities(e) {
1445
- const o = this.graphStore.getEdge(e), r = this.graphStore.getPortNodeId(o.from), n = this.graphStore.getPortNodeId(o.to);
1446
- this.attachedNodes.has(r) || this.handleAttachNode(r), this.attachedNodes.has(n) || this.handleAttachNode(n), this.handleAttachEdge(e);
1012
+ attachEdgeEntities(t) {
1013
+ const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from).nodeId, n = this.graphStore.getPort(o.to).nodeId;
1014
+ this.attachedNodes.has(r) || this.handleAttachNode(r), this.attachedNodes.has(n) || this.handleAttachNode(n), this.handleAttachEdge(t);
1447
1015
  }
1448
- handleAttachNode(e) {
1449
- this.attachedNodes.add(e), this.htmlView.attachNode(e);
1016
+ handleAttachNode(t) {
1017
+ this.attachedNodes.add(t), this.htmlView.attachNode(t);
1450
1018
  }
1451
- handleDetachNode(e) {
1452
- this.htmlView.detachNode(e), this.attachedNodes.delete(e);
1019
+ handleDetachNode(t) {
1020
+ this.htmlView.detachNode(t), this.attachedNodes.delete(t);
1453
1021
  }
1454
- handleAttachEdge(e) {
1455
- this.attachedEdges.add(e), this.htmlView.attachEdge(e);
1022
+ handleAttachEdge(t) {
1023
+ this.attachedEdges.add(t), this.htmlView.attachEdge(t);
1456
1024
  }
1457
- handleDetachEdge(e) {
1458
- this.htmlView.detachEdge(e), this.attachedEdges.delete(e);
1025
+ handleDetachEdge(t) {
1026
+ this.htmlView.detachEdge(t), this.attachedEdges.delete(t);
1459
1027
  }
1460
1028
  }
1461
- const Le = (t, e) => new ee(t, e), De = (t) => (e, o) => new Ce(
1462
- new ee(e, o),
1463
- e,
1464
- t
1465
- ), I = (t, e, o) => {
1466
- const { x: r, y: n, width: d, height: s } = t.getBoundingClientRect();
1467
- return e >= r && e <= r + d && o >= n && o <= n + s;
1468
- }, W = (t, e, o) => e >= 0 && e <= t.innerWidth && o >= 0 && o <= t.innerHeight, R = (t, e) => {
1469
- e !== null ? t.style.cursor = e : t.style.removeProperty("cursor");
1470
- }, $e = (t) => {
1471
- var g, f, x, y, S, A;
1472
- const e = ((g = t == null ? void 0 : t.events) == null ? void 0 : g.onNodeDrag) ?? (() => {
1473
- }), 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) ?? (() => {
1474
- }), n = (t == null ? void 0 : t.moveOnTop) === !1, d = (y = t == null ? void 0 : t.mouse) == null ? void 0 : y.dragCursor, s = d !== void 0 ? d : "grab", h = (S = t == null ? void 0 : t.mouse) == null ? void 0 : S.mouseDownEventVerifier, c = h !== void 0 ? h : (N) => N.button === 0, a = (A = t == null ? void 0 : t.mouse) == null ? void 0 : A.mouseUpEventVerifier;
1475
- return {
1476
- freezePriority: n,
1477
- dragCursor: s,
1478
- mouseDownEventVerifier: c,
1479
- mouseUpEventVerifier: a !== void 0 ? a : (N) => N.button === 0,
1480
- onNodeDrag: e,
1481
- onBeforeNodeDrag: o,
1482
- onNodeDragFinished: r
1483
- };
1484
- };
1485
- class Ie {
1486
- constructor(e, o) {
1487
- i(this, "graph");
1488
- i(this, "viewport");
1489
- i(this, "maxNodePriority", 0);
1490
- i(this, "nodes", /* @__PURE__ */ new Map());
1491
- i(this, "grabbedNodeId", null);
1492
- i(this, "nodeIdGenerator", new L(
1493
- (e) => this.nodes.has(e)
1494
- ));
1495
- i(this, "element", null);
1496
- i(this, "onWindowMouseMove", (e) => {
1497
- if (this.element !== null && (!I(this.element, e.clientX, e.clientY) || !W(this.window, e.clientX, e.clientY))) {
1498
- this.cancelMouseDrag();
1499
- return;
1500
- }
1501
- this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
1502
- });
1503
- i(this, "onWindowMouseUp", (e) => {
1504
- this.options.mouseUpEventVerifier(e) && this.cancelMouseDrag();
1505
- });
1506
- i(this, "onWindowTouchMove", (e) => {
1507
- if (e.touches.length !== 1)
1508
- return;
1509
- const o = e.touches[0];
1510
- if (this.element !== null && (!I(this.element, o.clientX, o.clientY) || !W(this.window, o.clientX, o.clientY))) {
1511
- this.cancelTouchDrag();
1512
- return;
1513
- }
1514
- if (this.grabbedNodeId !== null && this.previousTouchCoords !== null) {
1515
- const r = o.clientX - this.previousTouchCoords.x, n = o.clientY - this.previousTouchCoords.y;
1516
- this.dragNode(this.grabbedNodeId, r, n), this.previousTouchCoords = {
1517
- x: e.touches[0].clientX,
1518
- y: e.touches[0].clientY
1519
- };
1520
- }
1521
- });
1522
- i(this, "onWindowTouchFinish", () => {
1523
- this.previousTouchCoords = null, this.cancelTouchDrag();
1524
- });
1525
- i(this, "previousTouchCoords", null);
1526
- i(this, "window", window);
1527
- i(this, "options");
1528
- this.canvas = e, this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.options = $e(o ?? {});
1529
- }
1530
- attach(e) {
1531
- return this.detach(), this.element = e, this.canvas.attach(this.element), this;
1532
- }
1533
- detach() {
1534
- return this.canvas.detach(), this.element !== null && (this.element = null), this;
1535
- }
1536
- addNode(e) {
1537
- const o = this.nodeIdGenerator.create(e.id);
1538
- this.canvas.addNode({ ...e, id: o }), this.updateMaxNodePriority(o);
1539
- const r = (d) => {
1540
- if (this.element === null || !this.options.mouseDownEventVerifier(d))
1541
- return;
1542
- const s = this.graph.getNode(o);
1543
- this.options.onBeforeNodeDrag({
1544
- nodeId: o,
1545
- element: e.element,
1546
- x: s.x,
1547
- y: s.y
1548
- }) && (d.stopImmediatePropagation(), this.grabbedNodeId = o, R(this.element, this.options.dragCursor), this.moveNodeOnTop(o), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
1549
- }, n = (d) => {
1550
- if (d.touches.length !== 1)
1551
- return;
1552
- d.stopImmediatePropagation(), this.previousTouchCoords = {
1553
- x: d.touches[0].clientX,
1554
- y: d.touches[0].clientY
1555
- };
1556
- const s = this.graph.getNode(o);
1557
- this.options.onBeforeNodeDrag({
1558
- nodeId: o,
1559
- element: e.element,
1560
- x: s.x,
1561
- y: s.y
1562
- }) && (this.grabbedNodeId = o, this.moveNodeOnTop(o), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish));
1563
- };
1564
- return this.nodes.set(o, {
1565
- element: e.element,
1566
- onMouseDown: r,
1567
- onTouchStart: n
1568
- }), e.element.addEventListener("mousedown", r), e.element.addEventListener("touchstart", n), this;
1569
- }
1570
- updateNode(e, o) {
1571
- return this.canvas.updateNode(e, o), this.updateMaxNodePriority(e), this;
1572
- }
1573
- removeNode(e) {
1574
- const o = this.nodes.get(e);
1575
- return o !== void 0 && (o.element.removeEventListener("mousedown", o.onMouseDown), o.element.removeEventListener("touchstart", o.onTouchStart)), this.nodes.delete(e), this.canvas.removeNode(e), this;
1576
- }
1577
- markPort(e) {
1578
- return this.canvas.markPort(e), this;
1579
- }
1580
- updatePort(e, o) {
1581
- return this.canvas.updatePort(e, o), this;
1582
- }
1583
- unmarkPort(e) {
1584
- return this.canvas.unmarkPort(e), this;
1585
- }
1586
- addEdge(e) {
1587
- return this.canvas.addEdge(e), this;
1588
- }
1589
- updateEdge(e, o) {
1590
- return this.canvas.updateEdge(e, o), this;
1591
- }
1592
- removeEdge(e) {
1593
- return this.canvas.removeEdge(e), this;
1594
- }
1595
- patchViewportMatrix(e) {
1596
- return this.canvas.patchViewportMatrix(e), this;
1597
- }
1598
- patchContentMatrix(e) {
1599
- return this.canvas.patchContentMatrix(e), this;
1029
+ class q {
1030
+ constructor() {
1031
+ i(this, "callbacks", /* @__PURE__ */ new Set());
1600
1032
  }
1601
- clear() {
1602
- return this.canvas.clear(), this.nodes.forEach((e) => {
1603
- e.element.removeEventListener("mousedown", e.onMouseDown), e.element.removeEventListener("touchstart", e.onTouchStart);
1604
- }), this.nodes.clear(), this.maxNodePriority = 0, this;
1033
+ subscribe(t) {
1034
+ this.callbacks.add(t);
1605
1035
  }
1606
- destroy() {
1607
- this.detach(), this.clear(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
1036
+ unsubscribe(t) {
1037
+ this.callbacks.delete(t);
1608
1038
  }
1609
- dragNode(e, o, r) {
1610
- const n = this.graph.getNode(e);
1611
- if (n === null)
1612
- return;
1613
- const d = this.canvas.viewport.getContentMatrix(), s = d.scale * n.x + d.x, h = d.scale * n.y + d.y, c = s + o, a = h + r, l = this.canvas.viewport.getViewportMatrix(), g = l.scale * c + l.x, f = l.scale * a + l.y;
1614
- this.canvas.updateNode(e, { x: g, y: f }), this.options.onNodeDrag({
1615
- nodeId: e,
1616
- element: n.element,
1617
- x: g,
1618
- y: f
1039
+ emit(t) {
1040
+ this.callbacks.forEach((o) => {
1041
+ o(t);
1619
1042
  });
1620
1043
  }
1621
- updateMaxNodePriority(e) {
1622
- const o = this.graph.getNode(e).priority;
1623
- this.maxNodePriority = Math.max(this.maxNodePriority, o);
1044
+ }
1045
+ const Tt = () => {
1046
+ const e = new q();
1047
+ return [e, e];
1048
+ };
1049
+ class Y {
1050
+ constructor(t) {
1051
+ i(this, "counter", 0);
1052
+ this.checkExists = t;
1624
1053
  }
1625
- moveNodeOnTop(e) {
1626
- if (this.options.freezePriority)
1627
- return;
1628
- this.maxNodePriority += 2, this.updateNode(e, { priority: this.maxNodePriority });
1629
- const o = this.maxNodePriority - 1;
1630
- this.graph.getNodeAdjacentEdgeIds(e).forEach((n) => {
1631
- this.updateEdge(n, { priority: o });
1632
- });
1054
+ create(t) {
1055
+ if (t !== void 0)
1056
+ return t;
1057
+ for (; this.checkExists(this.counter); )
1058
+ this.counter++;
1059
+ return this.counter;
1633
1060
  }
1634
- cancelMouseDrag() {
1635
- const e = this.graph.getNode(this.grabbedNodeId);
1636
- e !== null && this.options.onNodeDragFinished({
1637
- nodeId: this.grabbedNodeId,
1638
- element: e.element,
1639
- x: e.x,
1640
- y: e.y
1641
- }), this.grabbedNodeId = null, this.element !== null && R(this.element, null), this.removeMouseDragListeners();
1061
+ reset() {
1062
+ this.counter = 0;
1642
1063
  }
1643
- removeMouseDragListeners() {
1644
- this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
1064
+ }
1065
+ class E extends Error {
1066
+ constructor() {
1067
+ super(...arguments);
1068
+ i(this, "name", "HtmlGraphError");
1645
1069
  }
1646
- cancelTouchDrag() {
1647
- this.previousTouchCoords = null;
1648
- const e = this.graph.getNode(this.grabbedNodeId);
1649
- e !== null && this.options.onNodeDragFinished({
1650
- nodeId: this.grabbedNodeId,
1651
- element: e.element,
1652
- x: e.x,
1653
- y: e.y
1654
- }), this.grabbedNodeId = null, this.removeTouchDragListeners();
1070
+ }
1071
+ const pt = (e, t) => ({
1072
+ x: e / 2,
1073
+ y: t / 2
1074
+ }), X = (e) => () => e, J = X(0), Mt = () => {
1075
+ let e = 0;
1076
+ return () => e++;
1077
+ }, Nt = (e, t) => {
1078
+ let o = J, r = J;
1079
+ const n = Mt();
1080
+ return e === "incremental" && (o = n), t === "incremental" && (r = n), typeof e == "number" && (o = X(e)), typeof t == "number" && (r = X(t)), typeof e == "function" && (o = e), typeof t == "function" && (r = t), {
1081
+ nodesPriorityFn: o,
1082
+ edgesPriorityFn: r
1083
+ };
1084
+ }, f = (e, t, o) => ({
1085
+ x: t.x * e.x - t.y * e.y + ((1 - t.x) * o.x + t.y * o.y),
1086
+ y: t.y * e.x + t.x * e.y + ((1 - t.x) * o.y - t.y * o.x)
1087
+ }), p = (e, t, o) => ({ x: t * Math.cos(e), y: o * Math.sin(e) }), w = {
1088
+ x: 0,
1089
+ y: 0
1090
+ }, M = (e, t, o, r) => {
1091
+ const h = [
1092
+ w,
1093
+ { x: o, y: r },
1094
+ { x: o, y: -r }
1095
+ ].map((a) => f(a, e, w)).map((a) => ({ x: a.x + t.x, y: a.y + t.y })), s = `M ${h[0].x} ${h[0].y}`, c = `L ${h[1].x} ${h[1].y}`, d = `L ${h[2].x} ${h[2].y}`;
1096
+ return `${s} ${c} ${d}`;
1097
+ }, b = (e, t) => {
1098
+ const o = [];
1099
+ if (e.length > 0 && o.push(`M ${e[0].x} ${e[0].y}`), e.length === 2 && o.push(`L ${e[1].x} ${e[1].y}`), e.length > 2) {
1100
+ const r = e.length - 1;
1101
+ let n = 0, h = 0, s = 0;
1102
+ e.forEach((c, d) => {
1103
+ let a = 0, l = 0, g = 0;
1104
+ const y = d > 0, x = d < r, v = y && x;
1105
+ if (y && (a = -n, l = -h, g = s), x) {
1106
+ const P = e[d + 1];
1107
+ n = P.x - c.x, h = P.y - c.y, s = Math.sqrt(n * n + h * h);
1108
+ }
1109
+ const S = s !== 0 ? Math.min((v ? t : 0) / s, d < r - 1 ? 0.5 : 1) : 0, T = v ? { x: c.x + n * S, y: c.y + h * S } : c, L = g !== 0 ? Math.min((v ? t : 0) / g, d > 1 ? 0.5 : 1) : 0, D = v ? { x: c.x + a * L, y: c.y + l * L } : c;
1110
+ d > 0 && o.push(`L ${D.x} ${D.y}`), v && o.push(
1111
+ `C ${c.x} ${c.y} ${c.x} ${c.y} ${T.x} ${T.y}`
1112
+ );
1113
+ });
1655
1114
  }
1656
- removeTouchDragListeners() {
1657
- this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1115
+ return o.join(" ");
1116
+ }, I = () => {
1117
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1118
+ return e.style.pointerEvents = "none", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.overflow = "visible", e;
1119
+ }, F = () => {
1120
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "g");
1121
+ return e.style.transformOrigin = "50% 50%", e;
1122
+ }, R = (e, t) => {
1123
+ const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1124
+ return o.setAttribute("stroke", e), o.setAttribute("stroke-width", `${t}`), o.setAttribute("fill", "none"), o;
1125
+ }, N = (e) => {
1126
+ const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
1127
+ return t.setAttribute("fill", e), t;
1128
+ }, k = (e, t) => {
1129
+ const o = {
1130
+ x: e.x + e.width / 2,
1131
+ y: e.y + e.height / 2
1132
+ }, r = {
1133
+ x: t.x + t.width / 2,
1134
+ y: t.y + t.height / 2
1135
+ }, n = Math.min(o.x, r.x), h = Math.min(o.y, r.y), s = Math.abs(r.x - o.x), c = Math.abs(r.y - o.y), d = o.x <= r.x ? 1 : -1, a = o.y <= r.y ? 1 : -1;
1136
+ return {
1137
+ x: n,
1138
+ y: h,
1139
+ width: s,
1140
+ height: c,
1141
+ flipX: d,
1142
+ flipY: a
1143
+ };
1144
+ }, Vt = (e) => {
1145
+ const t = f(
1146
+ { x: e.arrowLength, y: w.y },
1147
+ e.fromVect,
1148
+ w
1149
+ ), o = f(
1150
+ { x: e.to.x - e.arrowLength, y: e.to.y },
1151
+ e.toVect,
1152
+ e.to
1153
+ ), r = {
1154
+ x: t.x + e.fromVect.x * e.curvature,
1155
+ y: t.y + e.fromVect.y * e.curvature
1156
+ }, n = {
1157
+ x: o.x - e.toVect.x * e.curvature,
1158
+ y: o.y - e.toVect.y * e.curvature
1159
+ }, h = `M ${t.x} ${t.y} C ${r.x} ${r.y}, ${n.x} ${n.y}, ${o.x} ${o.y}`, s = e.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${t.x} ${t.y} `, c = e.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${e.to.x} ${e.to.y}`;
1160
+ return `${s}${h}${c}`;
1161
+ }, Lt = (e) => {
1162
+ const t = e.hasSourceArrow ? f(
1163
+ { x: e.arrowLength, y: w.y },
1164
+ e.fromVect,
1165
+ w
1166
+ ) : w, o = e.hasTargetArrow ? f(
1167
+ { x: e.to.x - e.arrowLength, y: e.to.y },
1168
+ e.toVect,
1169
+ e.to
1170
+ ) : e.to, r = e.arrowLength, n = Math.cos(e.detourDirection) * e.detourDistance, h = Math.sin(e.detourDirection) * e.detourDistance, s = n * e.flipX, c = h * e.flipY, d = f(
1171
+ { x: r, y: w.y },
1172
+ e.fromVect,
1173
+ w
1174
+ ), a = {
1175
+ x: d.x + s,
1176
+ y: d.y + c
1177
+ }, l = f(
1178
+ { x: e.to.x - r, y: e.to.y },
1179
+ e.toVect,
1180
+ e.to
1181
+ ), g = {
1182
+ x: l.x + s,
1183
+ y: l.y + c
1184
+ }, y = { x: (a.x + g.x) / 2, y: (a.y + g.y) / 2 }, x = {
1185
+ x: d.x + e.curvature * e.fromVect.x,
1186
+ y: d.y + e.curvature * e.fromVect.y
1187
+ }, v = {
1188
+ x: l.x - e.curvature * e.toVect.x,
1189
+ y: l.y - e.curvature * e.toVect.y
1190
+ }, A = {
1191
+ x: d.x + s,
1192
+ y: d.y + c
1193
+ }, S = {
1194
+ x: l.x + s,
1195
+ y: l.y + c
1196
+ };
1197
+ return [
1198
+ `M ${t.x} ${t.y}`,
1199
+ `L ${d.x} ${d.y}`,
1200
+ `C ${x.x} ${x.y} ${A.x} ${A.y} ${y.x} ${y.y}`,
1201
+ `C ${S.x} ${S.y} ${v.x} ${v.y} ${l.x} ${l.y}`,
1202
+ `L ${o.x} ${o.y}`
1203
+ ].join(" ");
1204
+ }, Dt = (e) => {
1205
+ const t = e.hasSourceArrow ? f(
1206
+ { x: e.arrowLength, y: w.y },
1207
+ e.fromVect,
1208
+ w
1209
+ ) : w, o = e.hasTargetArrow ? f(
1210
+ { x: e.to.x - e.arrowLength, y: e.to.y },
1211
+ e.toVect,
1212
+ e.to
1213
+ ) : e.to, r = e.arrowLength + e.arrowOffset, n = r - e.roundness, h = f({ x: n, y: w.y }, e.fromVect, w), s = f(
1214
+ { x: e.to.x - n, y: e.to.y },
1215
+ e.toVect,
1216
+ e.to
1217
+ ), c = Math.max((h.x + s.x) / 2, r), d = e.to.y / 2, a = { x: e.flipX > 0 ? c : -r, y: h.y }, l = { x: a.x, y: d }, g = {
1218
+ x: e.flipX > 0 ? e.to.x - c : e.to.x + r,
1219
+ y: s.y
1220
+ }, y = { x: g.x, y: d };
1221
+ return b(
1222
+ [t, h, a, l, y, g, s, o],
1223
+ e.roundness
1224
+ );
1225
+ }, B = (e) => {
1226
+ const t = e.hasSourceArrow ? f(
1227
+ { x: e.arrowLength, y: w.y },
1228
+ e.fromVect,
1229
+ w
1230
+ ) : w, o = e.hasTargetArrow ? f(
1231
+ { x: e.to.x - e.arrowLength, y: e.to.y },
1232
+ e.toVect,
1233
+ e.to
1234
+ ) : e.to, r = e.arrowLength + e.arrowOffset, n = f(
1235
+ { x: r, y: w.y },
1236
+ e.fromVect,
1237
+ w
1238
+ ), h = Math.cos(e.detourDirection) * e.detourDistance, s = Math.sin(e.detourDirection) * e.detourDistance, c = h * e.flipX, d = s * e.flipY, a = { x: n.x + c, y: n.y + d }, l = f(
1239
+ { x: e.to.x - r, y: e.to.y },
1240
+ e.toVect,
1241
+ e.to
1242
+ ), g = { x: l.x + c, y: l.y + d };
1243
+ return b(
1244
+ [t, n, a, g, l, o],
1245
+ e.roundness
1246
+ );
1247
+ }, Pt = (e) => {
1248
+ const t = e.hasSourceArrow ? f(
1249
+ { x: e.arrowLength, y: w.y },
1250
+ e.fromVect,
1251
+ w
1252
+ ) : w, o = e.hasTargetArrow ? f(
1253
+ { x: e.to.x - e.arrowLength, y: e.to.y },
1254
+ e.toVect,
1255
+ e.to
1256
+ ) : e.to, r = e.arrowLength + e.arrowOffset, n = f({ x: r, y: w.y }, e.fromVect, w), h = f(
1257
+ { x: e.to.x - r, y: e.to.y },
1258
+ e.toVect,
1259
+ e.to
1260
+ );
1261
+ return b([t, n, h, o], e.roundness);
1262
+ }, bt = (e) => {
1263
+ const t = e.hasSourceArrow ? f(
1264
+ { x: e.arrowLength, y: w.y },
1265
+ e.fromVect,
1266
+ w
1267
+ ) : w, o = e.hasTargetArrow ? f(
1268
+ { x: e.to.x - e.arrowLength, y: e.to.y },
1269
+ e.toVect,
1270
+ e.to
1271
+ ) : e.to, r = e.arrowLength + e.arrowOffset, n = r - e.roundness, h = f({ x: n, y: w.y }, e.fromVect, w), s = f(
1272
+ { x: e.to.x - n, y: e.to.y },
1273
+ e.toVect,
1274
+ e.to
1275
+ ), c = Math.max((h.y + s.y) / 2, r), d = e.to.x / 2, a = { x: h.x, y: e.flipY > 0 ? c : -r }, l = { x: d, y: a.y }, g = {
1276
+ x: s.x,
1277
+ y: e.flipY > 0 ? e.to.y - c : e.to.y + r
1278
+ }, y = { x: d, y: g.y };
1279
+ return b(
1280
+ [t, h, a, l, y, g, s, o],
1281
+ e.roundness
1282
+ );
1283
+ }, H = (e) => {
1284
+ const t = e.arrowOffset, o = e.side, r = e.arrowLength + t, n = r + 2 * o, s = [
1285
+ { x: e.arrowLength, y: w.y },
1286
+ { x: r, y: w.y },
1287
+ { x: r, y: e.side },
1288
+ { x: n, y: e.side },
1289
+ { x: n, y: -e.side },
1290
+ { x: r, y: -e.side },
1291
+ { x: r, y: w.y },
1292
+ { x: e.arrowLength, y: w.y }
1293
+ ].map(
1294
+ (d) => f(d, e.fromVect, w)
1295
+ ), c = `M ${w.x} ${w.y} L ${s[0].x} ${s[0].y} `;
1296
+ return `${e.hasSourceArrow || e.hasTargetArrow ? "" : c}${b(s, e.roundness)}`;
1297
+ }, mt = (e) => {
1298
+ const t = e.smallRadius, o = e.radius, r = Math.sqrt(t * t + o * o), n = t + o, h = e.arrowLength + r * (1 - o / n), s = t * o / n, d = [
1299
+ { x: e.arrowLength, y: w.y },
1300
+ { x: h, y: s },
1301
+ { x: h, y: -s }
1302
+ ].map((g) => f(g, e.fromVect, w)), a = [
1303
+ `M ${d[0].x} ${d[0].y}`,
1304
+ `A ${t} ${t} 0 0 1 ${d[1].x} ${d[1].y}`,
1305
+ `A ${o} ${o} 0 1 0 ${d[2].x} ${d[2].y}`,
1306
+ `A ${t} ${t} 0 0 1 ${d[0].x} ${d[0].y}`
1307
+ ].join(" "), l = `M 0 0 L ${d[0].x} ${d[0].y} `;
1308
+ return `${e.hasSourceArrow || e.hasTargetArrow ? "" : l}${a}`;
1309
+ }, u = Object.freeze({
1310
+ color: "#777777",
1311
+ width: 1,
1312
+ arrowLength: 15,
1313
+ arrowWidth: 4,
1314
+ arrowOffset: 15,
1315
+ hasSourceArrow: !1,
1316
+ hasTargetArrow: !1,
1317
+ cycleRadius: 30,
1318
+ cycleSquareSide: 30,
1319
+ roundness: 10,
1320
+ detourDistance: 100,
1321
+ detourDirection: -Math.PI / 2,
1322
+ detourDirectionVertical: 0,
1323
+ smallCycleRadius: 15,
1324
+ curvature: 90
1325
+ });
1326
+ class Ct {
1327
+ constructor(t) {
1328
+ i(this, "svg", I());
1329
+ i(this, "group", F());
1330
+ i(this, "line");
1331
+ i(this, "sourceArrow", null);
1332
+ i(this, "targetArrow", null);
1333
+ i(this, "arrowLength");
1334
+ i(this, "arrowWidth");
1335
+ i(this, "curvature");
1336
+ i(this, "portCycleRadius");
1337
+ i(this, "portCycleSmallRadius");
1338
+ i(this, "detourDirection");
1339
+ i(this, "detourDistance");
1340
+ i(this, "hasSourceArrow");
1341
+ i(this, "hasTargetArrow");
1342
+ this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? u.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? u.arrowWidth, this.curvature = (t == null ? void 0 : t.curvature) ?? u.curvature, this.portCycleRadius = (t == null ? void 0 : t.cycleRadius) ?? u.cycleRadius, this.portCycleSmallRadius = (t == null ? void 0 : t.smallCycleRadius) ?? u.smallCycleRadius, this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? u.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? u.hasTargetArrow;
1343
+ const o = (t == null ? void 0 : t.color) ?? u.color, r = (t == null ? void 0 : t.width) ?? u.width;
1344
+ this.svg.appendChild(this.group), this.line = R(o, r), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(o), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(o), this.group.appendChild(this.targetArrow));
1345
+ }
1346
+ render(t) {
1347
+ const { x: o, y: r, width: n, height: h, flipX: s, flipY: c } = k(
1348
+ t.from,
1349
+ t.to
1350
+ );
1351
+ 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}, ${c})`;
1352
+ const d = p(
1353
+ t.from.direction,
1354
+ s,
1355
+ c
1356
+ ), a = p(t.to.direction, s, c), l = {
1357
+ x: n,
1358
+ y: h
1359
+ };
1360
+ let g, y = a, x = -this.arrowLength;
1361
+ if (t.from.portId === t.to.portId ? (g = mt({
1362
+ fromVect: d,
1363
+ radius: this.portCycleRadius,
1364
+ smallRadius: this.portCycleSmallRadius,
1365
+ arrowLength: this.arrowLength,
1366
+ hasSourceArrow: this.hasSourceArrow,
1367
+ hasTargetArrow: this.hasTargetArrow
1368
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = Lt({
1369
+ to: l,
1370
+ fromVect: d,
1371
+ toVect: a,
1372
+ flipX: s,
1373
+ flipY: c,
1374
+ arrowLength: this.arrowLength,
1375
+ detourDirection: this.detourDirection,
1376
+ detourDistance: this.detourDistance,
1377
+ curvature: this.curvature,
1378
+ hasSourceArrow: this.hasSourceArrow,
1379
+ hasTargetArrow: this.hasTargetArrow
1380
+ }) : g = Vt({
1381
+ to: l,
1382
+ fromVect: d,
1383
+ toVect: a,
1384
+ arrowLength: this.arrowLength,
1385
+ curvature: this.curvature,
1386
+ hasSourceArrow: this.hasSourceArrow,
1387
+ hasTargetArrow: this.hasTargetArrow
1388
+ }), this.line.setAttribute("d", g), this.sourceArrow) {
1389
+ const v = M(
1390
+ d,
1391
+ w,
1392
+ this.arrowLength,
1393
+ this.arrowWidth
1394
+ );
1395
+ this.sourceArrow.setAttribute("d", v);
1396
+ }
1397
+ if (this.targetArrow) {
1398
+ const v = M(
1399
+ y,
1400
+ l,
1401
+ x,
1402
+ this.arrowWidth
1403
+ );
1404
+ this.targetArrow.setAttribute("d", v);
1405
+ }
1658
1406
  }
1659
1407
  }
1660
- const We = (t) => {
1661
- 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;
1662
- return (d) => {
1663
- let s = d.nextTransform.x, h = d.nextTransform.y;
1664
- s < e && s < d.prevTransform.x && (s = Math.min(d.prevTransform.x, e));
1665
- const c = d.canvasWidth * d.prevTransform.scale, a = o - c;
1666
- s > a && s > d.prevTransform.x && (s = Math.max(d.prevTransform.x, a)), h < r && h < d.prevTransform.y && (h = Math.min(d.prevTransform.y, r));
1667
- const l = d.canvasHeight * d.prevTransform.scale, g = n - l;
1668
- return h > g && h > d.prevTransform.y && (h = Math.max(d.prevTransform.y, g)), { scale: d.nextTransform.scale, x: s, y: h };
1669
- };
1670
- }, Re = (t) => {
1671
- const e = t.maxContentScale, o = t.minContentScale, r = e !== null ? 1 / e : 0, n = o !== null ? 1 / o : 1 / 0;
1672
- return (d) => {
1673
- const s = d.prevTransform, h = d.nextTransform;
1674
- let c = h.scale, a = h.x, l = h.y;
1675
- if (h.scale > n && h.scale > s.scale) {
1676
- c = Math.max(s.scale, n), a = s.x, l = s.y;
1677
- const g = (c - s.scale) / (h.scale - s.scale);
1678
- a = s.x + (h.x - s.x) * g, l = s.y + (h.y - s.y) * g;
1408
+ class $t {
1409
+ constructor(t) {
1410
+ i(this, "svg", I());
1411
+ i(this, "group", F());
1412
+ i(this, "line");
1413
+ i(this, "sourceArrow", null);
1414
+ i(this, "targetArrow", null);
1415
+ i(this, "arrowLength");
1416
+ i(this, "arrowWidth");
1417
+ i(this, "arrowOffset");
1418
+ i(this, "roundness");
1419
+ i(this, "cycleSquareSide");
1420
+ i(this, "detourDirection");
1421
+ i(this, "detourDistance");
1422
+ i(this, "hasSourceArrow");
1423
+ i(this, "hasTargetArrow");
1424
+ this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? u.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (t == null ? void 0 : t.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (t == null ? void 0 : t.cycleSquareSide) ?? u.cycleSquareSide;
1425
+ const o = (t == null ? void 0 : t.roundness) ?? u.roundness;
1426
+ this.roundness = Math.min(
1427
+ o,
1428
+ this.arrowOffset,
1429
+ this.cycleSquareSide / 2
1430
+ ), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? u.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? u.hasTargetArrow;
1431
+ const r = (t == null ? void 0 : t.color) ?? u.color, n = (t == null ? void 0 : t.width) ?? u.width;
1432
+ this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
1433
+ }
1434
+ render(t) {
1435
+ const { x: o, y: r, width: n, height: h, flipX: s, flipY: c } = k(
1436
+ t.from,
1437
+ t.to
1438
+ );
1439
+ 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}, ${c})`;
1440
+ const d = p(
1441
+ t.from.direction,
1442
+ s,
1443
+ c
1444
+ ), a = p(t.to.direction, s, c), l = {
1445
+ x: n,
1446
+ y: h
1447
+ };
1448
+ let g, y = a, x = -this.arrowLength;
1449
+ if (t.from.portId === t.to.portId ? (g = H({
1450
+ fromVect: d,
1451
+ arrowLength: this.arrowLength,
1452
+ side: this.cycleSquareSide,
1453
+ arrowOffset: this.arrowOffset,
1454
+ roundness: this.roundness,
1455
+ hasSourceArrow: this.hasSourceArrow,
1456
+ hasTargetArrow: this.hasTargetArrow
1457
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = B({
1458
+ to: l,
1459
+ fromVect: d,
1460
+ toVect: a,
1461
+ flipX: s,
1462
+ flipY: c,
1463
+ arrowLength: this.arrowLength,
1464
+ arrowOffset: this.arrowOffset,
1465
+ roundness: this.roundness,
1466
+ detourDirection: this.detourDirection,
1467
+ detourDistance: this.detourDistance,
1468
+ hasSourceArrow: this.hasSourceArrow,
1469
+ hasTargetArrow: this.hasTargetArrow
1470
+ }) : g = Dt({
1471
+ to: l,
1472
+ fromVect: d,
1473
+ toVect: a,
1474
+ flipX: s,
1475
+ arrowLength: this.arrowLength,
1476
+ arrowOffset: this.arrowOffset,
1477
+ roundness: this.roundness,
1478
+ hasSourceArrow: this.hasSourceArrow,
1479
+ hasTargetArrow: this.hasTargetArrow
1480
+ }), this.line.setAttribute("d", g), this.sourceArrow) {
1481
+ const v = M(
1482
+ d,
1483
+ w,
1484
+ this.arrowLength,
1485
+ this.arrowWidth
1486
+ );
1487
+ this.sourceArrow.setAttribute("d", v);
1679
1488
  }
1680
- if (h.scale < r && h.scale < s.scale) {
1681
- c = Math.min(s.scale, r), a = s.x, l = s.y;
1682
- const g = (c - s.scale) / (h.scale - s.scale);
1683
- a = s.x + (h.x - s.x) * g, l = s.y + (h.y - s.y) * g;
1489
+ if (this.targetArrow) {
1490
+ const v = M(
1491
+ y,
1492
+ l,
1493
+ x,
1494
+ this.arrowWidth
1495
+ );
1496
+ this.targetArrow.setAttribute("d", v);
1684
1497
  }
1685
- return {
1686
- scale: c,
1687
- x: a,
1688
- y: l
1498
+ }
1499
+ }
1500
+ class Wt {
1501
+ constructor(t) {
1502
+ i(this, "svg", I());
1503
+ i(this, "group", F());
1504
+ i(this, "line");
1505
+ i(this, "sourceArrow", null);
1506
+ i(this, "targetArrow", null);
1507
+ i(this, "arrowLength");
1508
+ i(this, "arrowWidth");
1509
+ i(this, "arrowOffset");
1510
+ i(this, "roundness");
1511
+ i(this, "cycleSquareSide");
1512
+ i(this, "detourDirection");
1513
+ i(this, "detourDistance");
1514
+ i(this, "hasSourceArrow");
1515
+ i(this, "hasTargetArrow");
1516
+ this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? u.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (t == null ? void 0 : t.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (t == null ? void 0 : t.cycleSquareSide) ?? u.cycleSquareSide;
1517
+ const o = (t == null ? void 0 : t.roundness) ?? u.roundness;
1518
+ this.roundness = Math.min(
1519
+ o,
1520
+ this.arrowOffset,
1521
+ this.cycleSquareSide / 2
1522
+ ), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? u.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? u.hasTargetArrow;
1523
+ const r = (t == null ? void 0 : t.color) ?? u.color, n = (t == null ? void 0 : t.width) ?? u.width;
1524
+ this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
1525
+ }
1526
+ render(t) {
1527
+ const { x: o, y: r, width: n, height: h, flipX: s, flipY: c } = k(
1528
+ t.from,
1529
+ t.to
1530
+ );
1531
+ 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}, ${c})`;
1532
+ const d = p(
1533
+ t.from.direction,
1534
+ s,
1535
+ c
1536
+ ), a = p(t.to.direction, s, c), l = {
1537
+ x: n,
1538
+ y: h
1689
1539
  };
1690
- };
1691
- }, Fe = (t) => (e) => t.reduce(
1692
- (o, r) => r({
1693
- prevTransform: e.prevTransform,
1694
- nextTransform: o,
1695
- canvasWidth: e.canvasWidth,
1696
- canvasHeight: e.canvasHeight
1697
- }),
1698
- e.nextTransform
1699
- ), O = (t) => {
1700
- if (typeof t == "function")
1701
- return t;
1702
- switch (t.type) {
1703
- case "scale-limit":
1704
- return Re({
1705
- minContentScale: t.minContentScale ?? 0,
1706
- maxContentScale: t.maxContentScale ?? 1 / 0
1707
- });
1708
- case "shift-limit":
1709
- return We({
1710
- minX: t.minX ?? -1 / 0,
1711
- maxX: t.maxX ?? 1 / 0,
1712
- minY: t.minY ?? -1 / 0,
1713
- maxY: t.maxY ?? 1 / 0
1714
- });
1540
+ let g, y = a, x = -this.arrowLength;
1541
+ if (t.from.portId === t.to.portId ? (g = H({
1542
+ fromVect: d,
1543
+ arrowLength: this.arrowLength,
1544
+ side: this.cycleSquareSide,
1545
+ arrowOffset: this.arrowOffset,
1546
+ roundness: this.roundness,
1547
+ hasSourceArrow: this.hasSourceArrow,
1548
+ hasTargetArrow: this.hasTargetArrow
1549
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = B({
1550
+ to: l,
1551
+ fromVect: d,
1552
+ toVect: a,
1553
+ flipX: s,
1554
+ flipY: c,
1555
+ arrowLength: this.arrowLength,
1556
+ arrowOffset: this.arrowOffset,
1557
+ roundness: this.roundness,
1558
+ detourDirection: this.detourDirection,
1559
+ detourDistance: this.detourDistance,
1560
+ hasSourceArrow: this.hasSourceArrow,
1561
+ hasTargetArrow: this.hasTargetArrow
1562
+ }) : g = Pt({
1563
+ to: l,
1564
+ fromVect: d,
1565
+ toVect: a,
1566
+ arrowLength: this.arrowLength,
1567
+ arrowOffset: this.arrowOffset,
1568
+ roundness: this.roundness,
1569
+ hasSourceArrow: this.hasSourceArrow,
1570
+ hasTargetArrow: this.hasTargetArrow
1571
+ }), this.line.setAttribute("d", g), this.sourceArrow) {
1572
+ const v = M(
1573
+ d,
1574
+ w,
1575
+ this.arrowLength,
1576
+ this.arrowWidth
1577
+ );
1578
+ this.sourceArrow.setAttribute("d", v);
1579
+ }
1580
+ if (this.targetArrow) {
1581
+ const v = M(
1582
+ y,
1583
+ l,
1584
+ x,
1585
+ this.arrowWidth
1586
+ );
1587
+ this.targetArrow.setAttribute("d", v);
1588
+ }
1715
1589
  }
1716
- }, Ue = (t) => {
1717
- var y, S, A, N, z, V, b, C, j, G, K, _;
1718
- const e = (y = t == null ? void 0 : t.scale) == null ? void 0 : y.mouseWheelSensitivity, o = e !== void 0 ? e : 1.2, r = t == null ? void 0 : t.transformPreprocessor;
1719
- let n;
1720
- r !== void 0 ? Array.isArray(r) ? n = Fe(
1721
- r.map(
1722
- (P) => O(P)
1723
- )
1724
- ) : n = O(r) : n = (P) => P.nextTransform;
1725
- const d = ((S = t == null ? void 0 : t.shift) == null ? void 0 : S.cursor) !== void 0 ? t.shift.cursor : "grab", s = ((A = t == null ? void 0 : t.events) == null ? void 0 : A.onBeforeTransformChange) ?? (() => {
1726
- }), h = ((N = t == null ? void 0 : t.events) == null ? void 0 : N.onTransformChange) ?? (() => {
1727
- }), c = (z = t == null ? void 0 : t.shift) == null ? void 0 : z.mouseDownEventVerifier, a = c !== void 0 ? c : (P) => P.button === 0, l = (V = t == null ? void 0 : t.shift) == null ? void 0 : V.mouseUpEventVerifier, g = l !== void 0 ? l : (P) => P.button === 0, f = (b = t == null ? void 0 : t.scale) == null ? void 0 : b.mouseWheelEventVerifier, x = f !== void 0 ? f : () => !0;
1728
- return {
1729
- wheelSensitivity: o,
1730
- onTransformStarted: ((C = t == null ? void 0 : t.events) == null ? void 0 : C.onTransformStarted) ?? (() => {
1731
- }),
1732
- onTransformFinished: ((j = t == null ? void 0 : t.events) == null ? void 0 : j.onTransformFinished) ?? (() => {
1733
- }),
1734
- onBeforeTransformChange: s,
1735
- onTransformChange: h,
1736
- transformPreprocessor: n,
1737
- shiftCursor: d,
1738
- mouseDownEventVerifier: a,
1739
- mouseUpEventVerifier: g,
1740
- mouseWheelEventVerifier: x,
1741
- scaleWheelFinishTimeout: ((G = t == null ? void 0 : t.scale) == null ? void 0 : G.wheelFinishTimeout) ?? 500,
1742
- onResizeTransformStarted: ((K = t == null ? void 0 : t.events) == null ? void 0 : K.onResizeTransformStarted) ?? (() => {
1743
- }),
1744
- onResizeTransformFinished: ((_ = t == null ? void 0 : t.events) == null ? void 0 : _.onResizeTransformFinished) ?? (() => {
1745
- })
1746
- };
1747
- }, $ = (t) => {
1748
- const e = [], o = t.touches.length;
1749
- for (let h = 0; h < o; h++)
1750
- e.push([t.touches[h].clientX, t.touches[h].clientY]);
1751
- const r = e.reduce(
1752
- (h, c) => [h[0] + c[0], h[1] + c[1]],
1753
- [0, 0]
1754
- ), n = [r[0] / o, r[1] / o], s = e.map((h) => [h[0] - n[0], h[1] - n[1]]).reduce(
1755
- (h, c) => h + Math.sqrt(c[0] * c[0] + c[1] * c[1]),
1756
- 0
1757
- );
1758
- return {
1759
- x: n[0],
1760
- y: n[1],
1761
- scale: s / o,
1762
- touchesCnt: o,
1763
- touches: e
1764
- };
1765
- }, Be = (t, e, o) => ({
1766
- scale: t.scale,
1767
- x: t.x + t.scale * e,
1768
- y: t.y + t.scale * o
1769
- }), ke = (t, e, o, r) => ({
1770
- scale: t.scale * e,
1771
- x: t.scale * (1 - e) * o + t.x,
1772
- y: t.scale * (1 - e) * r + t.y
1773
- });
1774
- class te {
1775
- constructor(e, o) {
1776
- i(this, "graph");
1777
- i(this, "viewport");
1778
- i(this, "element", null);
1779
- i(this, "prevTouches", null);
1780
- i(this, "window", window);
1781
- i(this, "wheelFinishTimer", null);
1782
- i(this, "onMouseDown", (e) => {
1783
- this.element === null || !this.options.mouseDownEventVerifier(e) || (R(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.options.onTransformStarted());
1784
- });
1785
- i(this, "onWindowMouseMove", (e) => {
1786
- if (this.element === null || !I(this.element, e.clientX, e.clientY) || !W(this.window, e.clientX, e.clientY)) {
1787
- this.stopMouseDrag();
1788
- return;
1789
- }
1790
- const o = -e.movementX, r = -e.movementY;
1791
- this.moveViewport(this.element, o, r);
1792
- });
1793
- i(this, "onWindowMouseUp", (e) => {
1794
- this.element === null || !this.options.mouseUpEventVerifier(e) || this.stopMouseDrag();
1795
- });
1796
- i(this, "onWheelScroll", (e) => {
1797
- if (!this.options.mouseWheelEventVerifier(e))
1798
- return;
1799
- e.preventDefault();
1800
- const { left: o, top: r } = this.element.getBoundingClientRect(), n = e.clientX - o, d = e.clientY - r, h = 1 / (e.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
1801
- this.wheelFinishTimer === null && this.options.onTransformStarted(), this.scaleViewport(this.element, h, n, d), this.wheelFinishTimer !== null && clearTimeout(this.wheelFinishTimer), this.wheelFinishTimer = setTimeout(() => {
1802
- this.options.onTransformFinished(), this.wheelFinishTimer = null;
1803
- }, this.options.scaleWheelFinishTimeout);
1804
- });
1805
- i(this, "onTouchStart", (e) => {
1806
- if (this.prevTouches !== null) {
1807
- this.prevTouches = $(e);
1808
- return;
1809
- }
1810
- this.prevTouches = $(e), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish), this.options.onTransformStarted();
1811
- });
1812
- i(this, "onWindowTouchMove", (e) => {
1813
- const o = this.element;
1814
- if (o === null)
1815
- return;
1816
- const r = $(e);
1817
- if (!r.touches.every(
1818
- (d) => I(o, d[0], d[1]) && W(this.window, d[0], d[1])
1819
- )) {
1820
- this.stopTouchDrag();
1821
- return;
1822
- }
1823
- if ((r.touchesCnt === 1 || r.touchesCnt === 2) && this.moveViewport(
1824
- o,
1825
- -(r.x - this.prevTouches.x),
1826
- -(r.y - this.prevTouches.y)
1827
- ), r.touchesCnt === 2) {
1828
- const { left: d, top: s } = o.getBoundingClientRect(), h = this.prevTouches.x - d, c = this.prevTouches.y - s, l = 1 / (r.scale / this.prevTouches.scale);
1829
- this.scaleViewport(o, l, h, c);
1830
- }
1831
- this.prevTouches = r;
1832
- });
1833
- i(this, "onWindowTouchFinish", (e) => {
1834
- e.touches.length > 0 ? this.prevTouches = $(e) : this.stopTouchDrag();
1835
- });
1836
- i(this, "observer", new ResizeObserver(() => {
1837
- const e = this.canvas.viewport.getViewportMatrix(), { width: o, height: r } = this.element.getBoundingClientRect(), n = this.options.transformPreprocessor({
1838
- prevTransform: e,
1839
- nextTransform: e,
1840
- canvasWidth: o,
1841
- canvasHeight: r
1590
+ }
1591
+ class It {
1592
+ constructor(t) {
1593
+ i(this, "svg", I());
1594
+ i(this, "group", F());
1595
+ i(this, "line");
1596
+ i(this, "sourceArrow", null);
1597
+ i(this, "targetArrow", null);
1598
+ i(this, "arrowLength");
1599
+ i(this, "arrowWidth");
1600
+ i(this, "arrowOffset");
1601
+ i(this, "roundness");
1602
+ i(this, "cycleSquareSide");
1603
+ i(this, "detourDirection");
1604
+ i(this, "detourDistance");
1605
+ i(this, "hasSourceArrow");
1606
+ i(this, "hasTargetArrow");
1607
+ this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? u.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (t == null ? void 0 : t.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (t == null ? void 0 : t.cycleSquareSide) ?? u.cycleSquareSide;
1608
+ const o = (t == null ? void 0 : t.roundness) ?? u.roundness;
1609
+ this.roundness = Math.min(
1610
+ o,
1611
+ this.arrowOffset,
1612
+ this.cycleSquareSide / 2
1613
+ ), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? u.detourDirectionVertical, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? u.hasTargetArrow;
1614
+ const r = (t == null ? void 0 : t.color) ?? u.color, n = (t == null ? void 0 : t.width) ?? u.width;
1615
+ this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
1616
+ }
1617
+ render(t) {
1618
+ const { x: o, y: r, width: n, height: h, flipX: s, flipY: c } = k(
1619
+ t.from,
1620
+ t.to
1621
+ );
1622
+ 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}, ${c})`;
1623
+ const d = p(
1624
+ t.from.direction,
1625
+ s,
1626
+ c
1627
+ ), a = p(t.to.direction, s, c), l = {
1628
+ x: n,
1629
+ y: h
1630
+ };
1631
+ let g, y = a, x = -this.arrowLength;
1632
+ if (t.from.portId === t.to.portId ? (g = H({
1633
+ fromVect: d,
1634
+ arrowLength: this.arrowLength,
1635
+ side: this.cycleSquareSide,
1636
+ arrowOffset: this.arrowOffset,
1637
+ roundness: this.roundness,
1638
+ hasSourceArrow: this.hasSourceArrow,
1639
+ hasTargetArrow: this.hasTargetArrow
1640
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = B({
1641
+ to: l,
1642
+ fromVect: d,
1643
+ toVect: a,
1644
+ flipX: s,
1645
+ flipY: c,
1646
+ arrowLength: this.arrowLength,
1647
+ arrowOffset: this.arrowOffset,
1648
+ roundness: this.roundness,
1649
+ detourDirection: this.detourDirection,
1650
+ detourDistance: this.detourDistance,
1651
+ hasSourceArrow: this.hasSourceArrow,
1652
+ hasTargetArrow: this.hasTargetArrow
1653
+ }) : g = bt({
1654
+ to: l,
1655
+ fromVect: d,
1656
+ toVect: a,
1657
+ flipY: c,
1658
+ arrowLength: this.arrowLength,
1659
+ arrowOffset: this.arrowOffset,
1660
+ roundness: this.roundness,
1661
+ hasSourceArrow: this.hasSourceArrow,
1662
+ hasTargetArrow: this.hasTargetArrow
1663
+ }), this.line.setAttribute("d", g), this.sourceArrow) {
1664
+ const v = M(
1665
+ d,
1666
+ w,
1667
+ this.arrowLength,
1668
+ this.arrowWidth
1669
+ );
1670
+ this.sourceArrow.setAttribute("d", v);
1671
+ }
1672
+ if (this.targetArrow) {
1673
+ const v = M(
1674
+ y,
1675
+ l,
1676
+ x,
1677
+ this.arrowWidth
1678
+ );
1679
+ this.targetArrow.setAttribute("d", v);
1680
+ }
1681
+ }
1682
+ }
1683
+ const Ft = (e) => {
1684
+ if (typeof e == "function")
1685
+ return e;
1686
+ switch (e == null ? void 0 : e.type) {
1687
+ case "straight":
1688
+ return () => new Wt({
1689
+ color: e.color,
1690
+ width: e.width,
1691
+ arrowLength: e.arrowLength,
1692
+ arrowWidth: e.arrowWidth,
1693
+ arrowOffset: e.arrowOffset,
1694
+ hasSourceArrow: e.hasSourceArrow,
1695
+ hasTargetArrow: e.hasTargetArrow,
1696
+ cycleSquareSide: e.cycleSquareSide,
1697
+ roundness: e.roundness,
1698
+ detourDistance: e.detourDistance,
1699
+ detourDirection: e.detourDirection
1842
1700
  });
1843
- this.options.onResizeTransformStarted(), this.canvas.patchViewportMatrix(n), this.options.onResizeTransformFinished();
1844
- }));
1845
- i(this, "options");
1846
- this.canvas = e, this.options = Ue(o), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph;
1701
+ case "horizontal":
1702
+ return () => new $t({
1703
+ color: e.color,
1704
+ width: e.width,
1705
+ arrowLength: e.arrowLength,
1706
+ arrowWidth: e.arrowWidth,
1707
+ arrowOffset: e.arrowOffset,
1708
+ hasSourceArrow: e.hasSourceArrow,
1709
+ hasTargetArrow: e.hasTargetArrow,
1710
+ cycleSquareSide: e.cycleSquareSide,
1711
+ roundness: e.roundness,
1712
+ detourDistance: e.detourDistance,
1713
+ detourDirection: e.detourDirection
1714
+ });
1715
+ case "vertical":
1716
+ return () => new It({
1717
+ color: e.color,
1718
+ width: e.width,
1719
+ arrowLength: e.arrowLength,
1720
+ arrowWidth: e.arrowWidth,
1721
+ arrowOffset: e.arrowOffset,
1722
+ hasSourceArrow: e.hasSourceArrow,
1723
+ hasTargetArrow: e.hasTargetArrow,
1724
+ cycleSquareSide: e.cycleSquareSide,
1725
+ roundness: e.roundness,
1726
+ detourDistance: e.detourDistance,
1727
+ detourDirection: e.detourDirection
1728
+ });
1729
+ default:
1730
+ return () => new Ct({
1731
+ color: e.color,
1732
+ width: e.width,
1733
+ arrowLength: e.arrowLength,
1734
+ arrowWidth: e.arrowWidth,
1735
+ hasSourceArrow: e.hasSourceArrow,
1736
+ hasTargetArrow: e.hasTargetArrow,
1737
+ cycleRadius: e.cycleRadius,
1738
+ smallCycleRadius: e.smallCycleRadius,
1739
+ curvature: e.curvature,
1740
+ detourDistance: e.detourDistance,
1741
+ detourDirection: e.detourDirection
1742
+ });
1743
+ }
1744
+ }, Rt = (e) => {
1745
+ var o, r, n, h, s;
1746
+ const t = Nt(
1747
+ (o = e == null ? void 0 : e.nodes) == null ? void 0 : o.priority,
1748
+ (r = e == null ? void 0 : e.edges) == null ? void 0 : r.priority
1749
+ );
1750
+ return {
1751
+ nodes: {
1752
+ centerFn: ((n = e == null ? void 0 : e.nodes) == null ? void 0 : n.centerFn) ?? pt,
1753
+ priorityFn: t.nodesPriorityFn
1754
+ },
1755
+ ports: {
1756
+ direction: ((h = e == null ? void 0 : e.ports) == null ? void 0 : h.direction) ?? 0
1757
+ },
1758
+ edges: {
1759
+ shapeFactory: Ft(((s = e == null ? void 0 : e.edges) == null ? void 0 : s.shape) ?? {}),
1760
+ priorityFn: t.edgesPriorityFn
1761
+ }
1762
+ };
1763
+ };
1764
+ class kt {
1765
+ constructor(t, o) {
1766
+ i(this, "nodeIdGenerator", new Y(
1767
+ (t) => this.graph.getNode(t) !== null
1768
+ ));
1769
+ i(this, "portIdGenerator", new Y(
1770
+ (t) => this.graph.getPort(t) !== null
1771
+ ));
1772
+ i(this, "edgeIdGenerator", new Y(
1773
+ (t) => this.graph.getEdge(t) !== null
1774
+ ));
1775
+ i(this, "defaults");
1776
+ /**
1777
+ * provides api for accessing graph model
1778
+ */
1779
+ i(this, "graph");
1780
+ /**
1781
+ * provides api for accessing viewport state
1782
+ */
1783
+ i(this, "viewport");
1784
+ this.controller = t, this.defaults = Rt(o), this.graph = t.graph, this.viewport = t.viewport;
1847
1785
  }
1848
- attach(e) {
1849
- return 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), this;
1786
+ /**
1787
+ * attaches canvas to given element
1788
+ * detaches element first when canvas is attached
1789
+ */
1790
+ attach(t) {
1791
+ return this.controller.attach(t), this;
1850
1792
  }
1793
+ /**
1794
+ * detaches canvas from element when attached
1795
+ */
1851
1796
  detach() {
1852
- return this.canvas.detach(), this.element !== null && (this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element = null), this;
1797
+ return this.controller.detach(), this;
1853
1798
  }
1854
- addNode(e) {
1855
- return this.canvas.addNode(e), this;
1799
+ /**
1800
+ * adds node to graph
1801
+ */
1802
+ addNode(t) {
1803
+ const o = this.nodeIdGenerator.create(t.id);
1804
+ if (this.graph.getNode(o) !== null)
1805
+ throw new E("failed to add node with existing id");
1806
+ if (this.controller.addNode({
1807
+ id: o,
1808
+ element: t.element,
1809
+ x: t.x,
1810
+ y: t.y,
1811
+ centerFn: t.centerFn ?? this.defaults.nodes.centerFn,
1812
+ priority: t.priority ?? this.defaults.nodes.priorityFn()
1813
+ }), t.ports !== void 0)
1814
+ for (const r of t.ports)
1815
+ this.markPort({
1816
+ id: r.id,
1817
+ element: r.element,
1818
+ nodeId: o,
1819
+ direction: r.direction
1820
+ });
1821
+ return this;
1856
1822
  }
1857
- updateNode(e, o) {
1858
- return this.canvas.updateNode(e, o), this;
1823
+ /**
1824
+ * updates node parameters
1825
+ */
1826
+ updateNode(t, o) {
1827
+ if (this.graph.getNode(t) === null)
1828
+ throw new E("failed to update nonexisting node");
1829
+ return this.controller.updateNode(t, o ?? {}), this;
1859
1830
  }
1860
- removeNode(e) {
1861
- return this.canvas.removeNode(e), this;
1831
+ /**
1832
+ * removes node from graph
1833
+ * all the ports of node get unmarked
1834
+ * all the edges adjacent to node get removed
1835
+ */
1836
+ removeNode(t) {
1837
+ if (this.graph.getNode(t) === null)
1838
+ throw new E("failed to remove nonexisting node");
1839
+ return this.controller.removeNode(t), this;
1862
1840
  }
1863
- markPort(e) {
1864
- return this.canvas.markPort(e), this;
1841
+ /**
1842
+ * marks element as port of node
1843
+ */
1844
+ markPort(t) {
1845
+ const o = this.portIdGenerator.create(t.id);
1846
+ if (this.graph.getPort(o) !== null)
1847
+ throw new E("failed to add port with existing id");
1848
+ if (this.graph.getNode(t.nodeId) === null)
1849
+ throw new E("failed to set port on nonexisting node");
1850
+ return this.controller.markPort({
1851
+ id: o,
1852
+ element: t.element,
1853
+ nodeId: t.nodeId,
1854
+ direction: t.direction ?? this.defaults.ports.direction
1855
+ }), this;
1865
1856
  }
1866
- updatePort(e, o) {
1867
- return this.canvas.updatePort(e, o), this;
1857
+ /**
1858
+ * updates port and attached edges
1859
+ */
1860
+ updatePort(t, o) {
1861
+ if (this.graph.getPort(t) === null)
1862
+ throw new E("failed to unset nonexisting port");
1863
+ return this.controller.updatePort(t, o ?? {}), this;
1868
1864
  }
1869
- unmarkPort(e) {
1870
- return this.canvas.unmarkPort(e), this;
1865
+ /**
1866
+ * ummarks element as port of node
1867
+ * all the edges adjacent to port get removed
1868
+ */
1869
+ unmarkPort(t) {
1870
+ if (this.graph.getPort(t) === null)
1871
+ throw new E("failed to unset nonexisting port");
1872
+ return this.controller.unmarkPort(t), this;
1871
1873
  }
1872
- addEdge(e) {
1873
- return this.canvas.addEdge(e), this;
1874
+ /**
1875
+ * adds edge to graph
1876
+ */
1877
+ addEdge(t) {
1878
+ const o = this.edgeIdGenerator.create(t.id);
1879
+ if (this.graph.getEdge(o) !== null)
1880
+ throw new E("failed to add edge with existing id");
1881
+ if (this.graph.getPort(t.from) === null)
1882
+ throw new E("failed to add edge from nonexisting port");
1883
+ if (this.graph.getPort(t.to) === null)
1884
+ throw new E("failed to add edge to nonexisting port");
1885
+ return this.controller.addEdge({
1886
+ id: o,
1887
+ from: t.from,
1888
+ to: t.to,
1889
+ shape: t.shape ?? this.defaults.edges.shapeFactory(),
1890
+ priority: t.priority ?? this.defaults.edges.priorityFn()
1891
+ }), this;
1874
1892
  }
1875
- updateEdge(e, o) {
1876
- return this.canvas.updateEdge(e, o), this;
1893
+ /**
1894
+ * updates edge
1895
+ */
1896
+ updateEdge(t, o) {
1897
+ if (this.graph.getEdge(t) === null)
1898
+ throw new E("failed to update nonexisting edge");
1899
+ return this.controller.updateEdge(t, o ?? {}), this;
1877
1900
  }
1878
- removeEdge(e) {
1879
- return this.canvas.removeEdge(e), this;
1901
+ /**
1902
+ * removes edge from graph
1903
+ */
1904
+ removeEdge(t) {
1905
+ if (this.graph.getEdge(t) === null)
1906
+ throw new E("failed to remove nonexisting edge");
1907
+ return this.controller.removeEdge(t), this;
1880
1908
  }
1881
- patchViewportMatrix(e) {
1882
- return this.canvas.patchViewportMatrix(e), this;
1909
+ /**
1910
+ * applies transformation for viewport
1911
+ */
1912
+ patchViewportMatrix(t) {
1913
+ return this.controller.patchViewportMatrix(t), this;
1883
1914
  }
1884
- patchContentMatrix(e) {
1885
- return this.canvas.patchContentMatrix(e), this;
1915
+ /**
1916
+ * applies transformation for content
1917
+ */
1918
+ patchContentMatrix(t) {
1919
+ return this.controller.patchContentMatrix(t), this;
1886
1920
  }
1921
+ /**
1922
+ * clears canvas from nodes and edges
1923
+ * canvas gets rolled back to initial state and can be reused
1924
+ */
1887
1925
  clear() {
1888
- return this.canvas.clear(), this;
1926
+ return this.controller.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset(), this;
1889
1927
  }
1928
+ /**
1929
+ * destroys canvas
1930
+ * canvas element gets rolled back to initial state, and can not be reused
1931
+ */
1890
1932
  destroy() {
1891
- this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
1892
- }
1893
- moveViewport(e, o, r) {
1894
- const n = this.viewport.getViewportMatrix(), d = Be(n, o, r), { width: s, height: h } = e.getBoundingClientRect(), c = this.options.transformPreprocessor({
1895
- prevTransform: n,
1896
- nextTransform: d,
1897
- canvasWidth: s,
1898
- canvasHeight: h
1899
- });
1900
- this.performTransform(c);
1901
- }
1902
- scaleViewport(e, o, r, n) {
1903
- const d = this.canvas.viewport.getViewportMatrix(), s = ke(d, o, r, n), { width: h, height: c } = e.getBoundingClientRect(), a = this.options.transformPreprocessor({
1904
- prevTransform: d,
1905
- nextTransform: s,
1906
- canvasWidth: h,
1907
- canvasHeight: c
1908
- });
1909
- this.performTransform(a);
1910
- }
1911
- stopMouseDrag() {
1912
- this.element !== null && R(this.element, null), this.removeMouseDragListeners(), this.options.onTransformFinished();
1913
- }
1914
- removeMouseDragListeners() {
1915
- this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
1916
- }
1917
- stopTouchDrag() {
1918
- this.prevTouches = null, this.removeTouchDragListeners(), this.options.onTransformFinished();
1919
- }
1920
- removeTouchDragListeners() {
1921
- this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1922
- }
1923
- performTransform(e) {
1924
- this.options.onBeforeTransformChange(), this.canvas.patchViewportMatrix(e), this.options.onTransformChange();
1933
+ this.controller.destroy();
1925
1934
  }
1926
1935
  }
1927
- class ze {
1936
+ class zt {
1928
1937
  constructor() {
1929
- i(this, "keyMap", /* @__PURE__ */ new Map());
1930
- i(this, "valueMap", /* @__PURE__ */ new Map());
1931
- }
1932
- set(e, o) {
1933
- this.keyMap.set(e, o), this.valueMap.set(o, e);
1934
- }
1935
- hasKey(e) {
1936
- return this.keyMap.has(e);
1937
- }
1938
- hasValue(e) {
1939
- return this.valueMap.has(e);
1940
- }
1941
- getByKey(e) {
1942
- return this.keyMap.get(e);
1943
- }
1944
- getByValue(e) {
1945
- return this.valueMap.get(e);
1946
- }
1947
- deleteByKey(e) {
1948
- const o = this.keyMap.get(e);
1949
- o !== void 0 && this.valueMap.delete(o), this.keyMap.delete(e);
1950
- }
1951
- deleteByValue(e) {
1952
- const o = this.valueMap.get(e);
1953
- o !== void 0 && this.keyMap.delete(o), this.valueMap.delete(e);
1954
- }
1955
- forEach(e) {
1956
- this.keyMap.forEach((o, r) => {
1957
- e(o, r);
1958
- });
1959
- }
1960
- clear() {
1961
- this.keyMap.clear(), this.valueMap.clear();
1962
- }
1963
- }
1964
- class Ye {
1965
- constructor(e) {
1966
- i(this, "viewport");
1967
- i(this, "graph");
1968
- i(this, "nodes", new ze());
1969
- i(this, "nodeIdGenerator", new L(
1970
- (e) => this.nodes.hasKey(e)
1971
- ));
1972
- i(this, "nodesResizeObserver");
1973
- i(this, "window", window);
1974
- this.canvas = e, this.nodesResizeObserver = new this.window.ResizeObserver((o) => {
1975
- o.forEach((r) => {
1976
- const n = r.target;
1977
- this.handleNodeResize(n);
1978
- });
1979
- }), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph;
1980
- }
1981
- attach(e) {
1982
- return this.canvas.attach(e), this;
1983
- }
1984
- detach() {
1985
- return this.canvas.detach(), this;
1986
- }
1987
- addNode(e) {
1988
- const o = this.nodeIdGenerator.create(e.id);
1989
- return this.canvas.addNode({
1990
- ...e,
1991
- id: o
1992
- }), this.nodes.set(o, e.element), this.nodesResizeObserver.observe(e.element), this;
1993
- }
1994
- updateNode(e, o) {
1995
- return this.canvas.updateNode(e, o), this;
1996
- }
1997
- removeNode(e) {
1998
- this.canvas.removeNode(e);
1999
- const o = this.nodes.getByKey(e);
2000
- return this.nodes.deleteByKey(e), this.nodesResizeObserver.unobserve(o), this;
2001
- }
2002
- markPort(e) {
2003
- return this.canvas.markPort(e), this;
2004
- }
2005
- updatePort(e, o) {
2006
- return this.canvas.updatePort(e, o), this;
2007
- }
2008
- unmarkPort(e) {
2009
- return this.canvas.unmarkPort(e), this;
1938
+ i(this, "nodes", /* @__PURE__ */ new Map());
1939
+ i(this, "ports", /* @__PURE__ */ new Map());
1940
+ i(this, "edges", /* @__PURE__ */ new Map());
1941
+ i(this, "incommingEdges", /* @__PURE__ */ new Map());
1942
+ i(this, "outcommingEdges", /* @__PURE__ */ new Map());
1943
+ i(this, "cycleEdges", /* @__PURE__ */ new Map());
2010
1944
  }
2011
- addEdge(e) {
2012
- return this.canvas.addEdge(e), this;
1945
+ addNode(t) {
1946
+ const o = /* @__PURE__ */ new Map(), r = {
1947
+ element: t.element,
1948
+ x: t.x,
1949
+ y: t.y,
1950
+ centerFn: t.centerFn,
1951
+ priority: t.priority,
1952
+ ports: o
1953
+ };
1954
+ this.nodes.set(t.id, r);
2013
1955
  }
2014
- updateEdge(e, o) {
2015
- return this.canvas.updateEdge(e, o), this;
1956
+ getAllNodeIds() {
1957
+ return Array.from(this.nodes.keys());
2016
1958
  }
2017
- removeEdge(e) {
2018
- return this.canvas.removeEdge(e), this;
1959
+ getNode(t) {
1960
+ return this.nodes.get(t);
2019
1961
  }
2020
- patchViewportMatrix(e) {
2021
- return this.canvas.patchViewportMatrix(e), this;
1962
+ removeNode(t) {
1963
+ this.nodes.delete(t);
2022
1964
  }
2023
- patchContentMatrix(e) {
2024
- return this.canvas.patchContentMatrix(e), this;
1965
+ addPort(t) {
1966
+ this.ports.set(t.id, {
1967
+ element: t.element,
1968
+ direction: t.direction,
1969
+ nodeId: t.nodeId
1970
+ }), this.cycleEdges.set(t.id, /* @__PURE__ */ new Set()), this.incommingEdges.set(t.id, /* @__PURE__ */ new Set()), this.outcommingEdges.set(t.id, /* @__PURE__ */ new Set()), this.nodes.get(t.nodeId).ports.set(t.id, t.element);
2025
1971
  }
2026
- clear() {
2027
- return this.canvas.clear(), this.nodesResizeObserver.disconnect(), this.nodes.clear(), this;
1972
+ getPort(t) {
1973
+ return this.ports.get(t);
2028
1974
  }
2029
- destroy() {
2030
- this.clear(), this.canvas.destroy();
1975
+ getAllPortIds() {
1976
+ return Array.from(this.ports.keys());
2031
1977
  }
2032
- handleNodeResize(e) {
2033
- const o = this.nodes.getByValue(e);
2034
- this.canvas.updateNode(o), this.graph.getNodeAdjacentEdgeIds(o).forEach((n) => {
2035
- this.canvas.updateEdge(n);
1978
+ getNodePortIds(t) {
1979
+ const o = this.nodes.get(t);
1980
+ if (o !== void 0)
1981
+ return Array.from(o.ports.keys());
1982
+ }
1983
+ removePort(t) {
1984
+ const o = this.ports.get(t).nodeId;
1985
+ this.nodes.get(o).ports.delete(t), this.ports.delete(t);
1986
+ }
1987
+ addEdge(t) {
1988
+ this.edges.set(t.id, {
1989
+ from: t.from,
1990
+ to: t.to,
1991
+ shape: t.shape,
1992
+ priority: t.priority
1993
+ }), t.from !== t.to ? (this.outcommingEdges.get(t.from).add(t.id), this.incommingEdges.get(t.to).add(t.id)) : this.cycleEdges.get(t.from).add(t.id);
1994
+ }
1995
+ updateEdgeFrom(t, o) {
1996
+ const r = this.edges.get(t);
1997
+ this.removeEdge(t), this.addEdge({
1998
+ id: t,
1999
+ from: o,
2000
+ to: r.to,
2001
+ shape: r.shape,
2002
+ priority: r.priority
2036
2003
  });
2037
2004
  }
2038
- }
2039
- class Xe {
2040
- constructor(e, o, r, n) {
2041
- i(this, "graph");
2042
- i(this, "viewport");
2043
- i(this, "canvas");
2044
- i(this, "element", null);
2045
- i(this, "canvasResizeObserver");
2046
- i(this, "window", window);
2047
- i(this, "nodeHorizontal");
2048
- i(this, "nodeVertical");
2049
- i(this, "viewportWidth", 0);
2050
- i(this, "viewportHeight", 0);
2051
- i(this, "viewportMatrix");
2052
- i(this, "loadedArea", {
2053
- xFrom: 1 / 0,
2054
- xTo: 1 / 0,
2055
- yFrom: 1 / 0,
2056
- yTo: 1 / 0
2057
- });
2058
- i(this, "updateLoadedArea", (e) => {
2059
- this.loadedArea = {
2060
- xFrom: e.x,
2061
- xTo: e.x + e.width,
2062
- yFrom: e.y,
2063
- yTo: e.y + e.height
2064
- };
2065
- });
2066
- var c, a;
2067
- 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) => {
2068
- const g = l[0];
2069
- this.viewportWidth = g.contentRect.width, this.viewportHeight = g.contentRect.height, this.scheduleLoadAreaAroundViewport();
2005
+ updateEdgeTo(t, o) {
2006
+ const r = this.edges.get(t);
2007
+ this.removeEdge(t), this.addEdge({
2008
+ id: t,
2009
+ from: r.from,
2010
+ to: o,
2011
+ shape: r.shape,
2012
+ priority: r.priority
2070
2013
  });
2071
- const d = ((c = r == null ? void 0 : r.events) == null ? void 0 : c.onTransformFinished) ?? (() => {
2072
- }), s = ((a = r == null ? void 0 : r.events) == null ? void 0 : a.onTransformChange) ?? (() => {
2073
- }), h = {
2074
- ...r,
2075
- events: {
2076
- ...r == null ? void 0 : r.events,
2077
- onTransformChange: () => {
2078
- const l = this.viewportMatrix;
2079
- this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), l.scale !== this.viewportMatrix.scale && this.scheduleEnsureViewportAreaLoaded(), s();
2080
- },
2081
- onTransformFinished: () => {
2082
- this.scheduleLoadAreaAroundViewport(), d();
2083
- }
2084
- }
2085
- };
2086
- this.canvas = new te(
2087
- e,
2088
- h
2089
- ), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.trigger.subscribe(this.updateLoadedArea);
2090
- }
2091
- attach(e) {
2092
- return this.detach(), this.element = e, this.canvasResizeObserver.observe(this.element), this.canvas.attach(e), this;
2093
2014
  }
2094
- detach() {
2095
- return this.element !== null && (this.canvasResizeObserver.unobserve(this.element), this.element = null, this.viewportWidth = 0, this.viewportHeight = 0), this.canvas.detach(), this;
2015
+ getAllEdgeIds() {
2016
+ return Array.from(this.edges.keys());
2096
2017
  }
2097
- addNode(e) {
2098
- return this.canvas.addNode(e), this;
2018
+ getEdge(t) {
2019
+ return this.edges.get(t);
2099
2020
  }
2100
- updateNode(e, o) {
2101
- return this.canvas.updateNode(e, o), this;
2021
+ removeEdge(t) {
2022
+ const o = this.edges.get(t), r = o.from, n = o.to;
2023
+ this.cycleEdges.get(r).delete(t), this.cycleEdges.get(n).delete(t), this.incommingEdges.get(r).delete(t), this.incommingEdges.get(n).delete(t), this.outcommingEdges.get(r).delete(t), this.outcommingEdges.get(n).delete(t), this.edges.delete(t);
2102
2024
  }
2103
- removeNode(e) {
2104
- return this.canvas.removeNode(e), this;
2025
+ clear() {
2026
+ this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear(), this.edges.clear(), this.ports.clear(), this.nodes.clear();
2105
2027
  }
2106
- markPort(e) {
2107
- return this.canvas.markPort(e), this;
2028
+ getPortIncomingEdgeIds(t) {
2029
+ return Array.from(this.incommingEdges.get(t));
2108
2030
  }
2109
- updatePort(e, o) {
2110
- return this.canvas.updatePort(e, o), this;
2031
+ getPortOutcomingEdgeIds(t) {
2032
+ return Array.from(this.outcommingEdges.get(t));
2111
2033
  }
2112
- unmarkPort(e) {
2113
- return this.canvas.unmarkPort(e), this;
2034
+ getPortCycleEdgeIds(t) {
2035
+ return Array.from(this.cycleEdges.get(t));
2114
2036
  }
2115
- addEdge(e) {
2116
- return this.canvas.addEdge(e), this;
2037
+ getPortAdjacentEdgeIds(t) {
2038
+ return [
2039
+ ...this.getPortIncomingEdgeIds(t),
2040
+ ...this.getPortOutcomingEdgeIds(t),
2041
+ ...this.getPortCycleEdgeIds(t)
2042
+ ];
2117
2043
  }
2118
- updateEdge(e, o) {
2119
- return this.canvas.updateEdge(e, o), this;
2044
+ getNodeIncomingEdgeIds(t) {
2045
+ const o = Array.from(this.nodes.get(t).ports.keys());
2046
+ let r = [];
2047
+ return o.forEach((n) => {
2048
+ r = [...r, ...this.getPortIncomingEdgeIds(n)];
2049
+ }), r;
2120
2050
  }
2121
- removeEdge(e) {
2122
- return this.canvas.removeEdge(e), this;
2051
+ getNodeOutcomingEdgeIds(t) {
2052
+ const o = Array.from(this.nodes.get(t).ports.keys());
2053
+ let r = [];
2054
+ return o.forEach((n) => {
2055
+ r = [...r, ...this.getPortOutcomingEdgeIds(n)];
2056
+ }), r;
2123
2057
  }
2124
- patchViewportMatrix(e) {
2125
- return this.canvas.patchViewportMatrix(e), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.loadAreaAroundViewport(), this;
2058
+ getNodeCycleEdgeIds(t) {
2059
+ const o = Array.from(this.nodes.get(t).ports.keys());
2060
+ let r = [];
2061
+ return o.forEach((n) => {
2062
+ r = [...r, ...this.getPortCycleEdgeIds(n)];
2063
+ }), r;
2126
2064
  }
2127
- patchContentMatrix(e) {
2128
- return this.canvas.patchContentMatrix(e), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.loadAreaAroundViewport(), this;
2065
+ getNodeAdjacentEdgeIds(t) {
2066
+ return [
2067
+ ...this.getNodeIncomingEdgeIds(t),
2068
+ ...this.getNodeOutcomingEdgeIds(t),
2069
+ ...this.getNodeCycleEdgeIds(t)
2070
+ ];
2129
2071
  }
2130
- clear() {
2131
- return this.canvas.clear(), this;
2072
+ }
2073
+ const Q = (e) => ({
2074
+ scale: 1 / e.scale,
2075
+ x: -e.x / e.scale,
2076
+ y: -e.y / e.scale
2077
+ }), Z = {
2078
+ scale: 1,
2079
+ x: 0,
2080
+ y: 0
2081
+ };
2082
+ class Yt {
2083
+ constructor() {
2084
+ i(this, "viewportMatrix", Z);
2085
+ i(this, "contentMatrix", Z);
2086
+ i(this, "emitter");
2087
+ i(this, "onAfterUpdate");
2088
+ [this.emitter, this.onAfterUpdate] = Tt();
2132
2089
  }
2133
- destroy() {
2134
- this.trigger.unsubscribe(this.updateLoadedArea), this.canvas.destroy();
2090
+ getViewportMatrix() {
2091
+ return this.viewportMatrix;
2135
2092
  }
2136
- scheduleLoadAreaAroundViewport() {
2137
- setTimeout(() => {
2138
- this.loadAreaAroundViewport();
2139
- });
2093
+ getContentMatrix() {
2094
+ return this.contentMatrix;
2140
2095
  }
2141
- scheduleEnsureViewportAreaLoaded() {
2142
- 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, d = this.viewportMatrix.x + e + this.nodeHorizontal, s = this.viewportMatrix.y + o + this.nodeVertical;
2143
- this.loadedArea.xFrom < r && this.loadedArea.xTo > d && this.loadedArea.yFrom < n && this.loadedArea.yTo > s || this.scheduleLoadAreaAroundViewport();
2096
+ patchViewportMatrix(t) {
2097
+ this.viewportMatrix = {
2098
+ scale: t.scale ?? this.viewportMatrix.scale,
2099
+ x: t.x ?? this.viewportMatrix.x,
2100
+ y: t.y ?? this.viewportMatrix.y
2101
+ }, this.contentMatrix = Q(this.viewportMatrix), this.emitter.emit();
2144
2102
  }
2145
- loadAreaAroundViewport() {
2146
- 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, d = 3 * e + 2 * this.nodeHorizontal, s = 3 * o + 2 * this.nodeVertical;
2147
- this.trigger.emit({ x: r, y: n, width: d, height: s });
2103
+ patchContentMatrix(t) {
2104
+ this.contentMatrix = {
2105
+ scale: t.scale ?? this.contentMatrix.scale,
2106
+ x: t.x ?? this.contentMatrix.x,
2107
+ y: t.y ?? this.contentMatrix.y
2108
+ }, this.viewportMatrix = Q(this.contentMatrix), this.emitter.emit();
2148
2109
  }
2149
2110
  }
2150
- class je {
2111
+ class Bt {
2151
2112
  constructor() {
2152
- i(this, "coreOptions", {});
2113
+ i(this, "canvasDefaults", {});
2153
2114
  i(this, "dragOptions");
2154
2115
  i(this, "transformOptions");
2155
2116
  i(this, "virtualScrollOptions");
@@ -2159,22 +2120,29 @@ class je {
2159
2120
  i(this, "boxRenderingTrigger");
2160
2121
  }
2161
2122
  /**
2162
- * specifies options for fundamental aspects of visualization
2123
+ * specifies default values for graph entities
2124
+ */
2125
+ setDefaults(t) {
2126
+ return this.canvasDefaults = t, this;
2127
+ }
2128
+ /**
2129
+ * @deprecated
2130
+ * use setDefaults instead
2163
2131
  */
2164
- setOptions(e) {
2165
- return this.coreOptions = e, this;
2132
+ setOptions(t) {
2133
+ return this.setDefaults(t), this;
2166
2134
  }
2167
2135
  /**
2168
- * enables nodes draggable bu user
2136
+ * enables nodes draggable by user
2169
2137
  */
2170
- enableUserDraggableNodes(e) {
2171
- return this.hasDraggableNode = !0, this.dragOptions = e, this;
2138
+ enableUserDraggableNodes(t) {
2139
+ return this.hasDraggableNode = !0, this.dragOptions = t, this;
2172
2140
  }
2173
2141
  /**
2174
2142
  * enables viewport transformable by user
2175
2143
  */
2176
- enableUserTransformableViewport(e) {
2177
- return this.hasTransformableViewport = !0, this.transformOptions = e, this;
2144
+ enableUserTransformableViewport(t) {
2145
+ return this.hasTransformableViewport = !0, this.transformOptions = t, this;
2178
2146
  }
2179
2147
  /**
2180
2148
  * enables automatic edges update on node resize
@@ -2185,40 +2153,51 @@ class je {
2185
2153
  /**
2186
2154
  * sets emitter for rendering graph inside bounded area
2187
2155
  */
2188
- enableBoxAreaRendering(e) {
2189
- return this.boxRenderingTrigger = e, this;
2156
+ enableBoxAreaRendering(t) {
2157
+ return this.boxRenderingTrigger = t, this;
2190
2158
  }
2191
- enableVirtualScroll(e) {
2192
- return this.virtualScrollOptions = e, this;
2159
+ enableVirtualScroll(t) {
2160
+ return this.virtualScrollOptions = t, this;
2193
2161
  }
2194
2162
  /**
2195
2163
  * builds final canvas
2196
2164
  */
2197
2165
  build() {
2198
- let e = this.boxRenderingTrigger;
2199
- this.virtualScrollOptions !== void 0 && e === void 0 && (e = new q());
2200
- const o = e !== void 0 ? De(e) : Le, r = new me(this.coreOptions, o);
2201
- let n = new ie(r);
2202
- return this.hasResizeReactiveNodes && (n = new Ye(n)), this.hasDraggableNode && (n = new Ie(n, this.dragOptions)), this.virtualScrollOptions !== void 0 ? n = new Xe(
2203
- n,
2204
- e,
2166
+ let t = this.boxRenderingTrigger;
2167
+ this.virtualScrollOptions !== void 0 && t === void 0 && (t = new q());
2168
+ const o = new zt(), r = new Yt();
2169
+ let n = new Et(o, r);
2170
+ t !== void 0 && (n = new At(n, o, t));
2171
+ let h = new it(
2172
+ o,
2173
+ r,
2174
+ n
2175
+ );
2176
+ this.hasResizeReactiveNodes && (h = new wt(h)), this.hasDraggableNode && (h = new nt(
2177
+ h,
2178
+ this.dragOptions
2179
+ )), this.virtualScrollOptions !== void 0 ? h = new yt(
2180
+ h,
2181
+ t,
2205
2182
  this.transformOptions,
2206
2183
  this.virtualScrollOptions
2207
- ) : this.hasTransformableViewport && (n = new te(
2208
- n,
2184
+ ) : this.hasTransformableViewport && (h = new O(
2185
+ h,
2209
2186
  this.transformOptions
2210
- )), this.reset(), n;
2187
+ ));
2188
+ const s = new kt(h, this.canvasDefaults);
2189
+ return this.reset(), s;
2211
2190
  }
2212
2191
  reset() {
2213
- this.coreOptions = {}, 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;
2192
+ 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;
2214
2193
  }
2215
2194
  }
2216
2195
  export {
2217
- ue as BezierEdgeShape,
2218
- je as CanvasBuilder,
2196
+ Ct as BezierEdgeShape,
2197
+ Bt as CanvasBuilder,
2219
2198
  q as EventSubject,
2220
- we as HorizontalEdgeShape,
2199
+ $t as HorizontalEdgeShape,
2221
2200
  E as HtmlGraphError,
2222
- fe as StraightEdgeShape,
2223
- ye as VerticalEdgeShape
2201
+ Wt as StraightEdgeShape,
2202
+ It as VerticalEdgeShape
2224
2203
  };