@html-graph/html-graph 0.0.47 → 0.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,28 +1,28 @@
1
- var F = Object.defineProperty;
2
- var k = (n, t, e) => t in n ? F(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
- var r = (n, t, e) => k(n, typeof t != "symbol" ? t + "" : t, e);
4
- class j {
5
- constructor(t, e, o, s, i) {
6
- r(this, "canvasWrapper", null);
7
- r(this, "host");
8
- r(this, "nodesContainer");
9
- r(this, "connectionsContainer");
10
- r(this, "canvas");
11
- r(this, "canvasCtx");
12
- r(this, "hostResizeObserver");
13
- r(this, "nodesResizeObserver");
14
- r(this, "nodeElementToIdMap", /* @__PURE__ */ new Map());
15
- r(this, "nodeWrapperElementToIdMap", /* @__PURE__ */ new Map());
16
- r(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
17
- r(this, "connectionIdToElementMap", /* @__PURE__ */ new Map());
18
- r(this, "currentZIndex", 0);
19
- r(this, "layers", {
20
- "connections-on-top": {
1
+ var D = Object.defineProperty;
2
+ var F = (o, t, e) => t in o ? D(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
+ var n = (o, t, e) => F(o, typeof t != "symbol" ? t + "" : t, e);
4
+ class k {
5
+ constructor(t, e, s, r, a) {
6
+ n(this, "canvasWrapper", null);
7
+ n(this, "host");
8
+ n(this, "nodesContainer");
9
+ n(this, "connectionsContainer");
10
+ n(this, "canvas");
11
+ n(this, "canvasCtx");
12
+ n(this, "hostResizeObserver");
13
+ n(this, "nodesResizeObserver");
14
+ n(this, "nodeElementToIdMap", /* @__PURE__ */ new Map());
15
+ n(this, "nodeWrapperElementToIdMap", /* @__PURE__ */ new Map());
16
+ n(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
17
+ n(this, "connectionIdToElementMap", /* @__PURE__ */ new Map());
18
+ n(this, "currentZIndex", 0);
19
+ n(this, "layers", {
20
+ "edges-on-top": {
21
21
  create: () => {
22
22
  this.host.appendChild(this.nodesContainer), this.host.appendChild(this.connectionsContainer);
23
23
  },
24
- update: (t, e, o) => {
25
- this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${o})`, this.connectionsContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${o})`;
24
+ update: (t, e, s) => {
25
+ this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`, this.connectionsContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`;
26
26
  },
27
27
  moveOnTop: (t) => {
28
28
  this.currentZIndex += 1;
@@ -30,17 +30,17 @@ class j {
30
30
  e.style.zIndex = `${this.currentZIndex}`;
31
31
  }
32
32
  },
33
- "connections-follow-node": {
33
+ "edges-follow-node": {
34
34
  create: () => {
35
35
  this.host.appendChild(this.nodesContainer), this.connectionsContainer = this.nodesContainer;
36
36
  },
37
- update: (t, e, o) => {
38
- this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${o})`;
37
+ update: (t, e, s) => {
38
+ this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`;
39
39
  },
40
40
  moveOnTop: (t) => {
41
41
  const e = this.nodeIdToWrapperElementMap.get(t);
42
- this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.graphStore.getNodeAdjacentConnections(t).forEach((s) => {
43
- this.connectionIdToElementMap.get(s).style.zIndex = `${this.currentZIndex - 1}`;
42
+ this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.graphStore.getNodeAdjacentConnections(t).forEach((r) => {
43
+ this.connectionIdToElementMap.get(r).style.zIndex = `${this.currentZIndex - 1}`;
44
44
  });
45
45
  }
46
46
  },
@@ -48,8 +48,8 @@ class j {
48
48
  create: () => {
49
49
  this.host.appendChild(this.connectionsContainer), this.host.appendChild(this.nodesContainer);
50
50
  },
51
- update: (t, e, o) => {
52
- this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${o})`, this.connectionsContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${o})`;
51
+ update: (t, e, s) => {
52
+ this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`, this.connectionsContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`;
53
53
  },
54
54
  moveOnTop: (t) => {
55
55
  this.currentZIndex += 1;
@@ -58,11 +58,11 @@ class j {
58
58
  }
59
59
  }
60
60
  });
61
- this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer = o, this.layersMode = s, this.backgroundDrawingFn = i, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.connectionsContainer = this.createConnectionsContainer();
62
- const h = this.canvas.getContext("2d");
63
- if (h === null)
61
+ this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer = s, this.layersMode = r, this.backgroundDrawingFn = a, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.connectionsContainer = this.createConnectionsContainer();
62
+ const c = this.canvas.getContext("2d");
63
+ if (c === null)
64
64
  throw new Error("unable to get canvas context");
65
- this.canvasCtx = h, this.host.appendChild(this.canvas), this.layers[this.layersMode].create(), this.hostResizeObserver = this.createHostResizeObserver(), this.hostResizeObserver.observe(this.host), this.nodesResizeObserver = this.createNodesResizeObserver();
65
+ this.canvasCtx = c, this.host.appendChild(this.canvas), this.layers[this.layersMode].create(), this.hostResizeObserver = this.createHostResizeObserver(), this.hostResizeObserver.observe(this.host), this.nodesResizeObserver = this.createNodesResizeObserver();
66
66
  }
67
67
  clear() {
68
68
  Array.from(this.connectionIdToElementMap.keys()).forEach((t) => {
@@ -72,32 +72,32 @@ class j {
72
72
  });
73
73
  }
74
74
  attach(t) {
75
- this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
75
+ this.detach(), this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
76
76
  }
77
77
  detach() {
78
- this.canvasWrapper !== null && this.canvasWrapper.removeChild(this.host);
78
+ this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
79
79
  }
80
80
  destroy() {
81
- this.hostResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.connectionsContainer), this.host.removeChild(this.nodesContainer), this.canvasWrapper !== null && this.canvasWrapper.removeChild(this.host);
81
+ this.hostResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.connectionsContainer), this.host.removeChild(this.nodesContainer), this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
82
82
  }
83
83
  applyTransform() {
84
84
  this.backgroundDrawingFn(this.canvasCtx, this.publicViewportTransformer);
85
- const [t, e] = this.viewportTransformer.getViewCoords(0, 0), o = this.viewportTransformer.getViewScale();
86
- this.layers[this.layersMode].update(o, t, e);
85
+ const [t, e] = this.viewportTransformer.getViewCoords(0, 0), s = this.viewportTransformer.getViewScale();
86
+ this.layers[this.layersMode].update(s, t, e);
87
87
  }
88
88
  attachNode(t) {
89
- const e = this.graphStore.getNode(t), o = document.createElement("div");
90
- o.appendChild(e.element), o.style.position = "absolute", o.style.top = "0", o.style.left = "0", o.style.zIndex = `${this.currentZIndex}`, this.currentZIndex += 1, o.style.visibility = "hidden", this.nodesContainer.appendChild(o), this.nodeElementToIdMap.set(e.element, t), this.nodeWrapperElementToIdMap.set(o, t), this.nodeIdToWrapperElementMap.set(t, o), this.updateNodeCoords(t, e.x, e.y), this.nodesResizeObserver.observe(o), o.style.visibility = "visible";
89
+ const e = this.graphStore.getNode(t), s = document.createElement("div");
90
+ s.appendChild(e.element), s.style.position = "absolute", s.style.top = "0", s.style.left = "0", s.style.zIndex = `${this.currentZIndex}`, this.currentZIndex += 1, s.style.visibility = "hidden", this.nodesContainer.appendChild(s), this.nodeElementToIdMap.set(e.element, t), this.nodeWrapperElementToIdMap.set(s, t), this.nodeIdToWrapperElementMap.set(t, s), this.updateNodeCoords(t, e.x, e.y), this.nodesResizeObserver.observe(s), s.style.visibility = "visible";
91
91
  }
92
92
  detachNode(t) {
93
93
  const e = this.graphStore.getNode(t);
94
94
  this.nodesResizeObserver.unobserve(e.element), this.nodesContainer.removeChild(e.element);
95
- const o = this.nodeIdToWrapperElementMap.get(t);
96
- o.removeChild(e.element), this.nodeElementToIdMap.delete(e.element), this.nodeWrapperElementToIdMap.delete(o), this.nodeIdToWrapperElementMap.delete(t);
95
+ const s = this.nodeIdToWrapperElementMap.get(t);
96
+ s.removeChild(e.element), this.nodeElementToIdMap.delete(e.element), this.nodeWrapperElementToIdMap.delete(s), this.nodeIdToWrapperElementMap.delete(t);
97
97
  }
98
98
  attachConnection(t) {
99
- const o = this.graphStore.getConnection(t).controller.svg;
100
- o.style.transformOrigin = "50% 50%", o.style.position = "absolute", o.style.top = "0", o.style.left = "0", o.style.zIndex = `${this.currentZIndex}`, this.currentZIndex += 1, this.connectionIdToElementMap.set(t, o), this.updateConnectionCoords(t), this.connectionsContainer.appendChild(o);
99
+ const s = this.graphStore.getConnection(t).controller.svg;
100
+ s.style.transformOrigin = "50% 50%", s.style.position = "absolute", s.style.top = "0", s.style.left = "0", s.style.zIndex = `${this.currentZIndex}`, this.currentZIndex += 1, this.connectionIdToElementMap.set(t, s), this.updateConnectionCoords(t), this.connectionsContainer.appendChild(s);
101
101
  }
102
102
  detachConnection(t) {
103
103
  const e = this.connectionIdToElementMap.get(t);
@@ -106,15 +106,15 @@ class j {
106
106
  moveNodeOnTop(t) {
107
107
  this.layers[this.layersMode].moveOnTop(t);
108
108
  }
109
- updateNodePosition(t) {
110
- const e = this.graphStore.getNode(t), o = this.graphStore.getNodeAdjacentConnections(t);
111
- this.updateNodeCoords(t, e.x, e.y), o.forEach((s) => {
112
- this.updateConnectionCoords(s);
109
+ updateNodeCoordinates(t) {
110
+ const e = this.graphStore.getNode(t), s = this.graphStore.getNodeAdjacentConnections(t);
111
+ this.updateNodeCoords(t, e.x, e.y), s.forEach((r) => {
112
+ this.updateConnectionCoords(r);
113
113
  });
114
114
  }
115
115
  updatePortConnections(t) {
116
- this.graphStore.getPortAdjacentConnections(t).forEach((o) => {
117
- this.updateConnectionCoords(o);
116
+ this.graphStore.getPortAdjacentConnections(t).forEach((s) => {
117
+ this.updateConnectionCoords(s);
118
118
  });
119
119
  }
120
120
  getViewportDimensions() {
@@ -145,9 +145,9 @@ class j {
145
145
  createNodesResizeObserver() {
146
146
  return new ResizeObserver((t) => {
147
147
  t.forEach((e) => {
148
- const o = e.target, s = this.nodeWrapperElementToIdMap.get(o), i = this.graphStore.getNode(s);
149
- this.updateNodeCoords(s, i.x, i.y), this.graphStore.getNodeAdjacentConnections(s).forEach((a) => {
150
- this.updateConnectionCoords(a);
148
+ const s = e.target, r = this.nodeWrapperElementToIdMap.get(s), a = this.graphStore.getNode(r);
149
+ this.updateNodeCoords(r, a.x, a.y), this.graphStore.getNodeAdjacentConnections(r).forEach((h) => {
150
+ this.updateConnectionCoords(h);
151
151
  });
152
152
  });
153
153
  });
@@ -156,71 +156,35 @@ class j {
156
156
  const { width: t, height: e } = this.host.getBoundingClientRect();
157
157
  this.canvas.width = t, this.canvas.height = e;
158
158
  }
159
- updateNodeCoords(t, e, o) {
160
- const s = this.nodeIdToWrapperElementMap.get(t), { width: i, height: h } = s.getBoundingClientRect(), a = this.viewportTransformer.getAbsScale(), c = this.graphStore.getNode(t), [l, g] = c.centerFn(i, h);
161
- s.style.transform = `matrix(1, 0, 0, 1, ${e - a * l}, ${o - a * g})`;
159
+ updateNodeCoords(t, e, s) {
160
+ const r = this.nodeIdToWrapperElementMap.get(t), { width: a, height: c } = r.getBoundingClientRect(), h = this.viewportTransformer.getAbsScale(), i = this.graphStore.getNode(t), [d, g] = i.centerFn(a, c);
161
+ r.style.transform = `matrix(1, 0, 0, 1, ${e - h * d}, ${s - h * g})`;
162
162
  }
163
163
  updateConnectionCoords(t) {
164
- const e = this.graphStore.getConnection(t), o = this.graphStore.getPort(e.from), s = this.graphStore.getPort(e.to), i = o.element.getBoundingClientRect(), h = s.element.getBoundingClientRect(), a = this.host.getBoundingClientRect(), [c, l] = this.viewportTransformer.getAbsCoords(
165
- i.left - a.left,
166
- i.top - a.top
167
- ), [g, d] = this.viewportTransformer.getAbsCoords(
168
- h.left - a.left,
169
- h.top - a.top
170
- ), m = this.viewportTransformer.getAbsScale(), [u, p] = o.centerFn(
171
- i.width * m,
172
- i.height * m
173
- ), [f, y] = s.centerFn(
174
- h.width * m,
175
- h.height * m
176
- ), S = u + c, b = p + l, N = f + g, C = y + d, w = Math.min(S, N), T = Math.min(b, C), E = Math.abs(N - S), x = Math.abs(C - b), M = this.connectionIdToElementMap.get(t), L = S <= N, V = b <= C;
177
- M.style.transform = `matrix(${L ? 1 : -1}, 0, 0, ${V ? 1 : -1}, ${w}, ${T})`, e.controller.update(w, T, E, x, o, s);
164
+ const e = this.graphStore.getConnection(t), s = this.graphStore.getPort(e.from), r = this.graphStore.getPort(e.to), a = s.element.getBoundingClientRect(), c = r.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), [i, d] = this.viewportTransformer.getAbsCoords(
165
+ a.left - h.left,
166
+ a.top - h.top
167
+ ), [g, l] = this.viewportTransformer.getAbsCoords(
168
+ c.left - h.left,
169
+ c.top - h.top
170
+ ), u = this.viewportTransformer.getAbsScale(), [w, m] = s.centerFn(
171
+ a.width * u,
172
+ a.height * u
173
+ ), [p, C] = r.centerFn(
174
+ c.width * u,
175
+ c.height * u
176
+ ), f = w + i, y = m + d, b = p + g, E = C + l, $ = Math.min(f, b), N = Math.min(y, E), A = Math.abs(b - f), P = Math.abs(E - y);
177
+ e.controller.update($, N, A, P, s, r);
178
178
  }
179
179
  }
180
- class D {
180
+ class W {
181
181
  constructor() {
182
- r(this, "state", {
182
+ n(this, "state", {
183
183
  scale: 1,
184
184
  x: 0,
185
185
  y: 0
186
186
  });
187
187
  }
188
- /**
189
- * dx2 - traslate x
190
- * dy2 - traslate y
191
- *
192
- * direct transform
193
- * s1 0 dx1 1 0 dx2
194
- * 0 s1 dy1 0 1 dy2
195
- * 0 0 1 0 0 1
196
- *
197
- * [s, dx, dy] = [s1, s * dx2 + dx1, s * dy2 + dy1]
198
- */
199
- applyShift(t, e) {
200
- this.state = {
201
- scale: this.state.scale,
202
- x: this.state.scale * t + this.state.x,
203
- y: this.state.scale * e + this.state.y
204
- };
205
- }
206
- /**
207
- * s2 - scale
208
- * cx - scale pivot x
209
- * cy - scale pivot y
210
- *
211
- * s1 0 dx1 s2 0 (1 - s2) * cx
212
- * 0 s1 dy1 0 s2 (1 - s2) * cy
213
- * 0 0 1 0 0 1
214
- *
215
- * [s, dx, dy] = [s1 * s2, s1 * (1 - s2) * cx + dx1, s1 * (1 - s2) * cy + dy1]
216
- */
217
- applyScale(t, e, o) {
218
- this.state = {
219
- scale: this.state.scale * t,
220
- x: this.state.scale * (1 - t) * e + this.state.x,
221
- y: this.state.scale * (1 - t) * o + this.state.y
222
- };
223
- }
224
188
  getViewCoords(t, e) {
225
189
  return [
226
190
  (t - this.state.x) / this.state.scale,
@@ -239,15 +203,15 @@ class D {
239
203
  getAbsScale() {
240
204
  return this.state.scale;
241
205
  }
242
- patchState(t, e, o) {
206
+ patchState(t, e, s) {
243
207
  this.state = {
244
208
  scale: t ?? this.state.scale,
245
209
  x: e ?? this.state.x,
246
- y: o ?? this.state.y
210
+ y: s ?? this.state.y
247
211
  };
248
212
  }
249
213
  }
250
- class W {
214
+ class j {
251
215
  constructor(t) {
252
216
  this.transformer = t;
253
217
  }
@@ -282,26 +246,20 @@ class W {
282
246
  }
283
247
  class R {
284
248
  constructor() {
285
- r(this, "nodes", /* @__PURE__ */ Object.create(null));
286
- r(this, "ports", /* @__PURE__ */ Object.create(null));
287
- r(this, "nodePorts", /* @__PURE__ */ Object.create(null));
288
- r(this, "portNodeId", /* @__PURE__ */ Object.create(null));
289
- r(this, "connections", /* @__PURE__ */ Object.create(null));
290
- r(this, "incommingConnections", /* @__PURE__ */ Object.create(null));
291
- r(this, "outcommingConnections", /* @__PURE__ */ Object.create(null));
292
- r(this, "cycleConnections", /* @__PURE__ */ Object.create(null));
249
+ n(this, "nodes", /* @__PURE__ */ Object.create(null));
250
+ n(this, "ports", /* @__PURE__ */ Object.create(null));
251
+ n(this, "nodePorts", /* @__PURE__ */ Object.create(null));
252
+ n(this, "portNodeId", /* @__PURE__ */ Object.create(null));
253
+ n(this, "connections", /* @__PURE__ */ Object.create(null));
254
+ n(this, "incommingConnections", /* @__PURE__ */ Object.create(null));
255
+ n(this, "outcommingConnections", /* @__PURE__ */ Object.create(null));
256
+ n(this, "cycleConnections", /* @__PURE__ */ Object.create(null));
293
257
  }
294
258
  getAllNodes() {
295
- return Object.keys(this.nodes);
296
- }
297
- getAllPorts() {
298
- return Object.keys(this.ports);
299
- }
300
- getAllConnections() {
301
- return Object.keys(this.connections);
259
+ return this.nodes;
302
260
  }
303
- addNode(t, e, o, s, i) {
304
- this.nodes[t] = { element: e, x: o, y: s, centerFn: i }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
261
+ addNode(t, e, s, r, a) {
262
+ this.nodes[t] = { element: e, x: s, y: r, centerFn: a }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
305
263
  }
306
264
  hasNode(t) {
307
265
  return this.nodes[t] !== void 0;
@@ -309,25 +267,25 @@ class R {
309
267
  getNode(t) {
310
268
  return this.nodes[t];
311
269
  }
312
- updateNodeCoords(t, e, o) {
313
- this.nodes[t].x = e, this.nodes[t].y = o;
270
+ updateNodeCoords(t, e, s) {
271
+ this.nodes[t].x = e, this.nodes[t].y = s;
314
272
  }
315
273
  updateConnectionController(t, e) {
316
274
  this.connections[t].controller = e;
317
275
  }
318
276
  removeNode(t) {
319
- this.getNodeAdjacentConnections(t).forEach((s) => {
320
- this.removeConnection(s);
277
+ this.getNodeAdjacentConnections(t).forEach((r) => {
278
+ this.removeConnection(r);
321
279
  }), delete this.nodes[t];
322
- const o = this.nodePorts[t];
323
- Object.keys(o).forEach((s) => {
324
- delete this.portNodeId[s];
280
+ const s = this.nodePorts[t];
281
+ Object.keys(s).forEach((r) => {
282
+ delete this.portNodeId[r];
325
283
  }), delete this.nodePorts[t];
326
284
  }
327
- addPort(t, e, o, s, i) {
328
- this.ports[t] = { element: e, centerFn: s, direction: i }, this.cycleConnections[t] = {}, this.incommingConnections[t] = {}, this.outcommingConnections[t] = {}, this.portNodeId[t] = o;
329
- const h = this.nodePorts[o];
330
- h !== void 0 && (h[t] = e);
285
+ addPort(t, e, s, r, a) {
286
+ this.ports[t] = { element: e, centerFn: r, direction: a }, this.cycleConnections[t] = {}, this.incommingConnections[t] = {}, this.outcommingConnections[t] = {}, this.portNodeId[t] = s;
287
+ const c = this.nodePorts[s];
288
+ c !== void 0 && (c[t] = e);
331
289
  }
332
290
  getPort(t) {
333
291
  return this.ports[t];
@@ -339,24 +297,24 @@ class R {
339
297
  return this.portNodeId[t] !== void 0;
340
298
  }
341
299
  removePort(t) {
342
- Object.keys(this.cycleConnections[t]).forEach((s) => {
343
- this.removeConnection(s);
344
- }), delete this.cycleConnections[t], Object.keys(this.incommingConnections[t]).forEach((s) => {
345
- this.removeConnection(s);
346
- }), delete this.incommingConnections[t], Object.keys(this.outcommingConnections[t]).forEach((s) => {
347
- this.removeConnection(s);
300
+ Object.keys(this.cycleConnections[t]).forEach((r) => {
301
+ this.removeConnection(r);
302
+ }), delete this.cycleConnections[t], Object.keys(this.incommingConnections[t]).forEach((r) => {
303
+ this.removeConnection(r);
304
+ }), delete this.incommingConnections[t], Object.keys(this.outcommingConnections[t]).forEach((r) => {
305
+ this.removeConnection(r);
348
306
  }), delete this.outcommingConnections[t];
349
307
  const e = this.portNodeId[t];
350
308
  delete this.portNodeId[t];
351
- const o = this.nodePorts[e];
352
- delete o[t], delete this.ports[t];
309
+ const s = this.nodePorts[e];
310
+ delete s[t], delete this.ports[t];
353
311
  }
354
- addConnection(t, e, o, s) {
312
+ addConnection(t, e, s, r) {
355
313
  this.connections[t] = {
356
314
  from: e,
357
- to: o,
358
- controller: s
359
- }, e !== o ? (this.outcommingConnections[e][t] = !0, this.incommingConnections[o][t] = !0) : this.cycleConnections[e][t] = !0;
315
+ to: s,
316
+ controller: r
317
+ }, e !== s ? (this.outcommingConnections[e][t] = !0, this.incommingConnections[s][t] = !0) : this.cycleConnections[e][t] = !0;
360
318
  }
361
319
  getConnection(t) {
362
320
  return this.connections[t];
@@ -365,17 +323,8 @@ class R {
365
323
  return this.connections[t] !== void 0;
366
324
  }
367
325
  removeConnection(t) {
368
- const e = this.connections[t], o = e.from, s = e.to;
369
- delete this.cycleConnections[o][t], delete this.cycleConnections[s][t], delete this.incommingConnections[o][t], delete this.incommingConnections[s][t], delete this.outcommingConnections[o][t], delete this.outcommingConnections[s][t], delete this.connections[t];
370
- }
371
- getPortIncomingConnections(t) {
372
- return Object.keys(this.incommingConnections[t] ?? {});
373
- }
374
- getPortOutcomingConnections(t) {
375
- return Object.keys(this.outcommingConnections[t] ?? {});
376
- }
377
- getPortCycleConnections(t) {
378
- return Object.keys(this.cycleConnections[t] ?? {});
326
+ const e = this.connections[t], s = e.from, r = e.to;
327
+ delete this.cycleConnections[s][t], delete this.cycleConnections[r][t], delete this.incommingConnections[s][t], delete this.incommingConnections[r][t], delete this.outcommingConnections[s][t], delete this.outcommingConnections[r][t], delete this.connections[t];
379
328
  }
380
329
  getPortAdjacentConnections(t) {
381
330
  return [
@@ -384,27 +333,6 @@ class R {
384
333
  ...this.getPortCycleConnections(t)
385
334
  ];
386
335
  }
387
- getNodeIncomingConnections(t) {
388
- const e = Object.keys(this.nodePorts[t]);
389
- let o = [];
390
- return e.forEach((s) => {
391
- o = [...o, ...this.getPortIncomingConnections(s)];
392
- }), o;
393
- }
394
- getNodeOutcomingConnections(t) {
395
- const e = Object.keys(this.nodePorts[t]);
396
- let o = [];
397
- return e.forEach((s) => {
398
- o = [...o, ...this.getPortOutcomingConnections(s)];
399
- }), o;
400
- }
401
- getNodeCycleConnections(t) {
402
- const e = Object.keys(this.nodePorts[t]);
403
- let o = [];
404
- return e.forEach((s) => {
405
- o = [...o, ...this.getPortCycleConnections(s)];
406
- }), o;
407
- }
408
336
  getNodeAdjacentConnections(t) {
409
337
  return [
410
338
  ...this.getNodeIncomingConnections(t),
@@ -415,252 +343,319 @@ class R {
415
343
  clear() {
416
344
  this.nodes = /* @__PURE__ */ Object.create(null), this.ports = /* @__PURE__ */ Object.create(null), this.nodePorts = /* @__PURE__ */ Object.create(null), this.portNodeId = /* @__PURE__ */ Object.create(null), this.connections = /* @__PURE__ */ Object.create(null), this.incommingConnections = /* @__PURE__ */ Object.create(null), this.outcommingConnections = /* @__PURE__ */ Object.create(null), this.cycleConnections = /* @__PURE__ */ Object.create(null);
417
345
  }
418
- }
419
- class z {
420
- constructor(t) {
421
- this.graphStore = t;
422
- }
423
- getNode(t) {
424
- const e = this.graphStore.getNode(t);
425
- return e === void 0 ? null : { x: e.x, y: e.y };
426
- }
427
- getPort(t) {
428
- const e = this.graphStore.getPortNode(t);
429
- return e === void 0 ? null : { nodeId: e };
430
- }
431
- getConnection(t) {
432
- const e = this.graphStore.getConnection(t);
433
- return e === void 0 ? null : { from: e.from, to: e.to };
434
- }
435
- getAllNodes() {
436
- return this.graphStore.getAllNodes();
437
- }
438
- getAllPorts() {
439
- return this.graphStore.getAllPorts();
440
- }
441
- getAllConnections() {
442
- return this.graphStore.getAllConnections();
443
- }
444
- hasNode(t) {
445
- return this.graphStore.hasNode(t);
446
- }
447
- hasPort(t) {
448
- return this.graphStore.hasPort(t);
449
- }
450
- hasConnection(t) {
451
- return this.graphStore.hasConnection(t);
452
- }
453
346
  getPortIncomingConnections(t) {
454
- return this.graphStore.getPortIncomingConnections(t);
347
+ return Object.keys(this.incommingConnections[t] ?? {});
455
348
  }
456
349
  getPortOutcomingConnections(t) {
457
- return this.graphStore.getPortOutcomingConnections(t);
350
+ return Object.keys(this.outcommingConnections[t] ?? {});
458
351
  }
459
352
  getPortCycleConnections(t) {
460
- return this.graphStore.getPortCycleConnections(t);
461
- }
462
- getPortAdjacentConnections(t) {
463
- return this.graphStore.getPortAdjacentConnections(t);
353
+ return Object.keys(this.cycleConnections[t] ?? {});
464
354
  }
465
355
  getNodeIncomingConnections(t) {
466
- return this.graphStore.getNodeIncomingConnections(t);
356
+ const e = Object.keys(this.nodePorts[t]);
357
+ let s = [];
358
+ return e.forEach((r) => {
359
+ s = [...s, ...this.getPortIncomingConnections(r)];
360
+ }), s;
467
361
  }
468
362
  getNodeOutcomingConnections(t) {
469
- return this.graphStore.getNodeOutcomingConnections(t);
363
+ const e = Object.keys(this.nodePorts[t]);
364
+ let s = [];
365
+ return e.forEach((r) => {
366
+ s = [...s, ...this.getPortOutcomingConnections(r)];
367
+ }), s;
470
368
  }
471
369
  getNodeCycleConnections(t) {
472
- return this.graphStore.getNodeCycleConnections(t);
473
- }
474
- getNodeAdjacentConnections(t) {
475
- return this.graphStore.getNodeAdjacentConnections(t);
370
+ const e = Object.keys(this.nodePorts[t]);
371
+ let s = [];
372
+ return e.forEach((r) => {
373
+ s = [...s, ...this.getPortCycleConnections(r)];
374
+ }), s;
476
375
  }
477
376
  }
478
377
  class v {
479
378
  static getPortCenter(t) {
480
- const { top: e, left: o, width: s, height: i } = t.element.getBoundingClientRect(), h = t.centerFn(s, i);
481
- return [o + h[0], e + h[1]];
379
+ const { top: e, left: s, width: r, height: a } = t.element.getBoundingClientRect(), c = t.centerFn(r, a);
380
+ return [s + c[0], e + c[1]];
482
381
  }
483
- static rotate(t, e, o) {
382
+ static rotate(t, e, s) {
484
383
  return [
485
- e[0] * t[0] - e[1] * t[1] + ((1 - e[0]) * o[0] + e[1] * o[1]),
486
- e[1] * t[0] + e[0] * t[1] + ((1 - e[0]) * o[1] - e[1] * o[0])
384
+ e[0] * t[0] - e[1] * t[1] + ((1 - e[0]) * s[0] + e[1] * s[1]),
385
+ e[1] * t[0] + e[0] * t[1] + ((1 - e[0]) * s[1] - e[1] * s[0])
487
386
  ];
488
387
  }
489
- static getDirectionVector(t, e, o) {
490
- return [e * Math.cos(t ?? 0), o * Math.sin(t ?? 0)];
388
+ static getDirectionVector(t, e, s) {
389
+ return [e * Math.cos(t ?? 0), s * Math.sin(t ?? 0)];
491
390
  }
492
- static getArrowPath(t, e, o, s, i) {
493
- const a = [
391
+ static getArrowPath(t, e, s, r, a) {
392
+ const h = [
494
393
  [0, 0],
495
- [s, i],
496
- [s, -i]
497
- ].map((d) => this.rotate(d, t, [0, 0])).map((d) => [d[0] + e, d[1] + o]), c = `M ${a[0][0]} ${a[0][1]}`, l = `L ${a[1][0]} ${a[1][1]}`, g = `L ${a[2][0]} ${a[2][1]}`;
498
- return `${c} ${l} ${g}`;
499
- }
500
- static getArrowOffsetPath(t, e, o, s, i) {
501
- const a = [
502
- [s, 0],
503
- [s + i, 0]
504
- ].map((c) => this.rotate(c, t, [0, 0])).map((c) => [c[0] + e, c[1] + o]);
505
- return `M ${a[0][0]} ${a[0][1]} L ${a[1][0]} ${a[1][1]}`;
394
+ [r, a],
395
+ [r, -a]
396
+ ].map((l) => this.rotate(l, t, [0, 0])).map((l) => [l[0] + e, l[1] + s]), i = `M ${h[0][0]} ${h[0][1]}`, d = `L ${h[1][0]} ${h[1][1]}`, g = `L ${h[2][0]} ${h[2][1]}`;
397
+ return `${i} ${d} ${g}`;
398
+ }
399
+ static getArrowOffsetPath(t, e, s, r, a) {
400
+ const h = [
401
+ [r, 0],
402
+ [r + a, 0]
403
+ ].map((i) => this.rotate(i, t, [0, 0])).map((i) => [i[0] + e, i[1] + s]);
404
+ return `M ${h[0][0]} ${h[0][1]} L ${h[1][0]} ${h[1][1]}`;
405
+ }
406
+ static createStraightPath(t) {
407
+ return t.map((e, s) => `${s === 0 ? "M" : "L"} ${e[0]} ${e[1]}`).join(" ");
506
408
  }
507
409
  }
508
- class G {
509
- constructor(t, e, o, s, i, h, a) {
510
- r(this, "svg");
511
- r(this, "group");
512
- r(this, "line");
513
- r(this, "sourceArrow", null);
514
- r(this, "targetArrow", null);
515
- this.color = t, this.width = e, this.curvature = o, this.arrowLength = s, this.arrowWidth = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
410
+ class B {
411
+ constructor(t, e, s, r, a, c, h) {
412
+ n(this, "svg");
413
+ n(this, "group");
414
+ n(this, "line");
415
+ n(this, "sourceArrow", null);
416
+ n(this, "targetArrow", null);
417
+ this.color = t, this.width = e, this.curvature = s, this.arrowLength = r, this.arrowWidth = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", c && (this.sourceArrow = document.createElementNS(
516
418
  "http://www.w3.org/2000/svg",
517
419
  "path"
518
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = document.createElementNS(
420
+ ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = document.createElementNS(
519
421
  "http://www.w3.org/2000/svg",
520
422
  "path"
521
423
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
522
424
  }
523
- update(t, e, o, s, i, h) {
524
- this.svg.style.width = `${o}px`, this.svg.style.height = `${s}px`;
525
- const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
526
- this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
527
- const d = v.getDirectionVector(
528
- i.direction,
529
- l,
530
- g
531
- ), m = v.getDirectionVector(
532
- h.direction,
533
- l,
534
- g
535
- ), u = v.rotate(
536
- [this.arrowLength, 0],
537
- d,
538
- [0, 0]
539
- ), p = v.rotate(
540
- [o - this.arrowLength, s],
541
- m,
542
- [o, s]
543
- ), f = [
544
- u[0] + d[0] * this.curvature,
545
- u[1] + d[1] * this.curvature
546
- ], y = [
547
- p[0] - m[0] * this.curvature,
548
- p[1] - m[1] * this.curvature
549
- ], S = `M ${u[0]} ${u[1]}`, b = `C ${f[0]} ${f[1]}, ${y[0]} ${y[1]}, ${p[0]} ${p[1]}`, N = `M 0 0 L ${u[0]} ${u[1]} `, C = ` M ${p[0]} ${p[1]} L ${o} ${s}`, w = `${this.sourceArrow ? "" : N}${S} ${b}${this.targetArrow ? "" : C}`;
550
- if (this.line.setAttribute("d", w), this.sourceArrow) {
551
- const T = v.getArrowPath(
552
- d,
425
+ update(t, e, s, r, a, c) {
426
+ this.svg.style.width = `${s}px`, this.svg.style.height = `${r}px`;
427
+ const h = v.getPortCenter(a), i = v.getPortCenter(c), d = h[0] <= i[0] ? 1 : -1, g = h[1] <= i[1] ? 1 : -1;
428
+ this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${d}, ${g})`;
429
+ const l = v.getDirectionVector(a.direction, d, g), u = v.getDirectionVector(c.direction, d, g), w = v.rotate([this.arrowLength, 0], l, [0, 0]), m = v.rotate([s - this.arrowLength, r], u, [
430
+ s,
431
+ r
432
+ ]), p = [
433
+ w[0] + l[0] * this.curvature,
434
+ w[1] + l[1] * this.curvature
435
+ ], C = [
436
+ m[0] - u[0] * this.curvature,
437
+ m[1] - u[1] * this.curvature
438
+ ], f = `M ${w[0]} ${w[1]} C ${p[0]} ${p[1]}, ${C[0]} ${C[1]}, ${m[0]} ${m[1]}`, y = this.sourceArrow ? "" : `M 0 0 L ${w[0]} ${w[1]} `, b = this.targetArrow ? "" : ` M ${m[0]} ${m[1]} L ${s} ${r}`, E = `${y}${f}${b}`;
439
+ if (this.line.setAttribute("d", E), this.sourceArrow) {
440
+ const $ = v.getArrowPath(
441
+ l,
553
442
  0,
554
443
  0,
555
444
  this.arrowLength,
556
445
  this.arrowWidth
557
446
  );
558
- this.sourceArrow.setAttribute("d", T);
447
+ this.sourceArrow.setAttribute("d", $);
559
448
  }
560
449
  if (this.targetArrow) {
561
- const T = v.getArrowPath(
562
- m,
563
- o,
450
+ const $ = v.getArrowPath(
451
+ u,
564
452
  s,
453
+ r,
565
454
  -this.arrowLength,
566
455
  this.arrowWidth
567
456
  );
568
- this.targetArrow.setAttribute("d", T);
457
+ this.targetArrow.setAttribute("d", $);
569
458
  }
570
459
  }
571
460
  }
572
- const B = (n) => () => new G(
573
- n.color ?? "#5c5c5c",
574
- n.width ?? 1,
575
- n.curvature ?? 90,
576
- n.arrowLength ?? 15,
577
- n.arrowWidth ?? 4,
578
- n.hasSourceArrow ?? !1,
579
- n.hasTargetArrow ?? !1
580
- );
581
- class Y {
582
- constructor(t, e, o, s, i, h, a) {
583
- r(this, "svg");
584
- r(this, "group");
585
- r(this, "line");
586
- r(this, "sourceArrow", null);
587
- r(this, "targetArrow", null);
588
- this.color = t, this.width = e, this.arrowLength = o, this.arrowWidth = s, this.minPortOffset = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
461
+ class z {
462
+ constructor(t, e, s, r, a, c, h, i) {
463
+ n(this, "svg");
464
+ n(this, "group");
465
+ n(this, "line");
466
+ n(this, "sourceArrow", null);
467
+ n(this, "targetArrow", null);
468
+ n(this, "roundness");
469
+ this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = r, this.minPortOffset = a, this.roundness = Math.min(this.minPortOffset, i), this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", c && (this.sourceArrow = document.createElementNS(
589
470
  "http://www.w3.org/2000/svg",
590
471
  "path"
591
- ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = document.createElementNS(
472
+ ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = document.createElementNS(
592
473
  "http://www.w3.org/2000/svg",
593
474
  "path"
594
475
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
595
476
  }
596
- update(t, e, o, s, i, h) {
597
- this.svg.style.width = `${o}px`, this.svg.style.height = `${s}px`;
598
- const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
599
- this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
600
- const d = v.getDirectionVector(
601
- i.direction,
602
- l,
603
- g
604
- ), m = v.getDirectionVector(
605
- h.direction,
477
+ update(t, e, s, r, a, c) {
478
+ this.svg.style.width = `${s}px`, this.svg.style.height = `${r}px`;
479
+ const h = v.getPortCenter(a), i = v.getPortCenter(c), d = h[0] <= i[0] ? 1 : -1, g = h[1] <= i[1] ? 1 : -1;
480
+ this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${d}, ${g})`;
481
+ const l = v.getDirectionVector(a.direction, d, g), u = v.getDirectionVector(c.direction, d, g);
482
+ console.log(this.roundness);
483
+ const w = this.arrowLength + this.minPortOffset, m = v.rotate([w, 0], l, [0, 0]), p = v.rotate([s - w, r], u, [s, r]), [C, f] = [s / 2, r / 2], b = d * (p[0] - m[0]) > 0 ? v.createStraightPath([
484
+ [m[0], m[1]],
485
+ [C, m[1]],
486
+ [C, p[1]],
487
+ [p[0], p[1]]
488
+ ]) : v.createStraightPath([
489
+ [m[0], m[1]],
490
+ [m[0], f],
491
+ [p[0], f],
492
+ [p[0], p[1]]
493
+ ]), E = v.getArrowOffsetPath(
606
494
  l,
607
- g
608
- ), u = v.rotate(
609
- [this.arrowLength + this.minPortOffset, 0],
610
- d,
611
- [0, 0]
612
- ), p = v.rotate(
613
- [o - this.arrowLength - this.minPortOffset, s],
614
- m,
615
- [o, s]
616
- ), [f, y] = [o / 2, s / 2], S = l * (p[0] - u[0]) > 0 ? `M ${u[0]} ${u[1]} L ${f} ${u[1]} L ${f} ${p[1]} L ${p[0]} ${p[1]}` : `M ${u[0]} ${u[1]} L ${u[0]} ${y} L ${p[0]} ${y} L ${p[0]} ${p[1]}`, b = `M 0 0 L ${u[0]} ${u[1]} `, N = ` M ${p[0]} ${p[1]} L ${o} ${s}`, C = v.getArrowOffsetPath(
617
- d,
618
495
  0,
619
496
  0,
620
497
  this.arrowLength,
621
498
  this.minPortOffset
622
- ), w = v.getArrowOffsetPath(
623
- m,
624
- o,
499
+ ), $ = v.getArrowOffsetPath(
500
+ u,
625
501
  s,
502
+ r,
626
503
  -this.arrowLength,
627
504
  -this.minPortOffset
628
- ), T = `${this.sourceArrow ? C : b}${S}${this.targetArrow ? w : N}`;
629
- if (this.line.setAttribute("d", T), this.sourceArrow) {
630
- const E = v.getArrowPath(
631
- d,
505
+ ), N = `M 0 0 L ${m[0]} ${m[1]} `, A = ` M ${p[0]} ${p[1]} L ${s} ${r}`, P = this.sourceArrow ? E : N, L = this.targetArrow ? $ : A, V = `${P}${b}${L}`;
506
+ if (this.line.setAttribute("d", V), this.sourceArrow) {
507
+ const x = v.getArrowPath(
508
+ l,
632
509
  0,
633
510
  0,
634
511
  this.arrowLength,
635
512
  this.arrowWidth
636
513
  );
637
- this.sourceArrow.setAttribute("d", E);
514
+ this.sourceArrow.setAttribute("d", x);
638
515
  }
639
516
  if (this.targetArrow) {
640
- const E = v.getArrowPath(
641
- m,
642
- o,
517
+ const x = v.getArrowPath(
518
+ u,
643
519
  s,
520
+ r,
644
521
  -this.arrowLength,
645
522
  this.arrowWidth
646
523
  );
647
- this.targetArrow.setAttribute("d", E);
524
+ this.targetArrow.setAttribute("d", x);
525
+ }
526
+ }
527
+ }
528
+ class Y {
529
+ constructor(t, e, s, r, a, c, h) {
530
+ n(this, "svg");
531
+ n(this, "group");
532
+ n(this, "line");
533
+ n(this, "arrow", null);
534
+ this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = r, this.radius = c, this.smallRadius = h, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", a && (this.arrow = document.createElementNS(
535
+ "http://www.w3.org/2000/svg",
536
+ "path"
537
+ ), this.arrow.setAttribute("fill", this.color), this.group.appendChild(this.arrow)), this.svg.style.overflow = "visible", this.svg.style.width = "0px", this.svg.style.height = "0px";
538
+ }
539
+ update(t, e, s, r, a) {
540
+ this.svg.style.transform = `translate(${t}px, ${e}px)`;
541
+ const c = v.getDirectionVector(a.direction, 1, 1), h = this.smallRadius, i = this.radius, d = Math.sqrt(h * h + i * i), g = h + i, l = this.arrowLength + d * (1 - i / g), u = h * i / g, m = [
542
+ [this.arrowLength, 0],
543
+ [l, u],
544
+ [l, -u]
545
+ ].map((y) => v.rotate(y, c, [0, 0])), p = [
546
+ `M ${m[0][0]} ${m[0][1]}`,
547
+ `A ${h} ${h} 0 0 1 ${m[1][0]} ${m[1][1]}`,
548
+ `A ${i} ${i} 0 1 0 ${m[2][0]} ${m[2][1]}`,
549
+ `A ${h} ${h} 0 0 1 ${m[0][0]} ${m[0][1]}`
550
+ ].join(" "), C = `M 0 0 L ${m[0][0]} ${m[0][1]} `, f = `${this.arrow !== null ? "" : C}${p}`;
551
+ if (this.line.setAttribute("d", f), this.arrow) {
552
+ const y = v.getArrowPath(
553
+ c,
554
+ 0,
555
+ 0,
556
+ this.arrowLength,
557
+ this.arrowWidth
558
+ );
559
+ this.arrow.setAttribute("d", y);
560
+ }
561
+ }
562
+ }
563
+ class G {
564
+ constructor(t, e, s, r, a, c, h, i) {
565
+ n(this, "svg");
566
+ n(this, "group");
567
+ n(this, "line");
568
+ n(this, "arrow", null);
569
+ n(this, "roundness");
570
+ n(this, "points");
571
+ this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = r, this.side = c, this.minPortOffset = h, this.roundness = Math.min(i, this.minPortOffset, this.side / 2), this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", a && (this.arrow = document.createElementNS(
572
+ "http://www.w3.org/2000/svg",
573
+ "path"
574
+ ), this.arrow.setAttribute("fill", this.color), this.group.appendChild(this.arrow)), this.svg.style.overflow = "visible", this.svg.style.width = "0px", this.svg.style.height = "0px";
575
+ const d = this.minPortOffset, g = this.side, l = this.arrowLength + d, u = this.roundness, w = l - u, m = l + u, p = g - u, C = l + 2 * g, f = C - u;
576
+ console.log(u), this.points = [
577
+ [this.arrowLength, 0],
578
+ [w, 0],
579
+ [l, u],
580
+ [l, p],
581
+ [m, g],
582
+ [f, g],
583
+ [C, p],
584
+ [C, -p],
585
+ [f, -g],
586
+ [m, -g],
587
+ [l, -p],
588
+ [l, -u]
589
+ ];
590
+ }
591
+ update(t, e, s, r, a) {
592
+ this.svg.style.transform = `translate(${t}px, ${e}px)`;
593
+ const c = v.getDirectionVector(a.direction, 1, 1), h = this.roundness, i = this.points.map((u) => v.rotate(u, c, [0, 0])), d = [
594
+ `M ${i[0][0]} ${i[0][1]}`,
595
+ `L ${i[1][0]} ${i[1][1]}`,
596
+ `A ${h} ${h} 0 0 1 ${i[2][0]} ${i[2][1]}`,
597
+ `L ${i[3][0]} ${i[3][1]}`,
598
+ `A ${h} ${h} 0 0 0 ${i[4][0]} ${i[4][1]}`,
599
+ `L ${i[5][0]} ${i[5][1]}`,
600
+ `A ${h} ${h} 0 0 0 ${i[6][0]} ${i[6][1]}`,
601
+ `L ${i[7][0]} ${i[7][1]}`,
602
+ `A ${h} ${h} 0 0 0 ${i[8][0]} ${i[8][1]}`,
603
+ `L ${i[9][0]} ${i[9][1]}`,
604
+ `A ${h} ${h} 0 0 0 ${i[10][0]} ${i[10][1]}`,
605
+ `L ${i[11][0]} ${i[11][1]}`,
606
+ `A ${h} ${h} 0 0 1 ${i[1][0]} ${i[1][1]}`
607
+ ].join(" "), g = `M 0 0 L ${i[0][0]} ${i[0][1]} `, l = `${this.arrow ? "" : g}${d}`;
608
+ if (this.line.setAttribute("d", l), this.arrow) {
609
+ const u = v.getArrowPath(
610
+ c,
611
+ 0,
612
+ 0,
613
+ this.arrowLength,
614
+ this.arrowWidth
615
+ );
616
+ this.arrow.setAttribute("d", u);
648
617
  }
649
618
  }
650
619
  }
651
- const X = (n) => () => new Y(
652
- n.color,
653
- n.width,
654
- n.arrowLength,
655
- n.arrowWidth,
656
- n.minPortOffset,
657
- n.hasSourceArrow,
658
- n.hasTargetArrow
620
+ var T = /* @__PURE__ */ ((o) => (o.Regular = "regular", o.Cycle = "cycle", o))(T || {});
621
+ const X = (o) => (t) => t === "cycle" ? new Y(
622
+ o.color,
623
+ o.width,
624
+ o.arrowLength,
625
+ o.arrowWidth,
626
+ o.hasSourceArrow || o.hasTargetArrow,
627
+ o.cycleRadius,
628
+ o.smallCycleRadius
629
+ ) : new B(
630
+ o.color,
631
+ o.width,
632
+ o.curvature,
633
+ o.arrowLength,
634
+ o.arrowWidth,
635
+ o.hasSourceArrow,
636
+ o.hasTargetArrow
637
+ ), Z = (o) => (t) => t === T.Cycle && t === "cycle" ? new G(
638
+ o.color,
639
+ o.width,
640
+ o.arrowLength,
641
+ o.arrowWidth,
642
+ o.hasSourceArrow || o.hasTargetArrow,
643
+ o.cycleSquareSide,
644
+ o.minPortOffset,
645
+ o.roundness
646
+ ) : new z(
647
+ o.color,
648
+ o.width,
649
+ o.arrowLength,
650
+ o.arrowWidth,
651
+ o.minPortOffset,
652
+ o.hasSourceArrow,
653
+ o.hasTargetArrow,
654
+ o.roundness
659
655
  );
660
- var $ = /* @__PURE__ */ ((n) => (n.Regular = "regular", n.Cycle = "cycle", n))($ || {});
661
- class A {
656
+ class S {
662
657
  constructor() {
663
- r(this, "counter", 0);
658
+ n(this, "counter", 0);
664
659
  }
665
660
  next() {
666
661
  const t = `${this.counter}`;
@@ -670,25 +665,19 @@ class A {
670
665
  this.counter = 0;
671
666
  }
672
667
  }
673
- class Z {
674
- constructor(t, e, o, s, i) {
675
- r(this, "nodeIdGenerator", new A());
676
- r(this, "portIdGenerator", new A());
677
- r(this, "connectionIdGenerator", new A());
678
- this.graphStore = t, this.htmlController = e, this.viewportTransformer = o, this.nodesCenterFn = s, this.portsCenterFn = i;
668
+ class U {
669
+ constructor(t, e, s, r, a) {
670
+ n(this, "nodeIdGenerator", new S());
671
+ n(this, "portIdGenerator", new S());
672
+ n(this, "connectionIdGenerator", new S());
673
+ this.graphStore = t, this.htmlController = e, this.viewportTransformer = s, this.nodesCenterFn = r, this.portsCenterFn = a;
679
674
  }
680
675
  moveNodeOnTop(t) {
681
676
  if (!this.graphStore.hasNode(t))
682
677
  throw new Error("failed to move on top nonexisting node");
683
678
  this.htmlController.moveNodeOnTop(t);
684
679
  }
685
- dragNode(t, e, o) {
686
- if (!this.graphStore.hasNode(t))
687
- throw new Error("failed to drag nonexisting node");
688
- const s = this.graphStore.getNode(t), [i, h] = this.viewportTransformer.getViewCoords(s.x, s.y), a = i + e, c = h + o, [l, g] = this.viewportTransformer.getAbsCoords(a, c);
689
- this.graphStore.updateNodeCoords(t, l, g), this.htmlController.updateNodePosition(t);
690
- }
691
- addNode(t, e, o, s, i, h) {
680
+ addNode(t, e, s, r, a, c) {
692
681
  if (t === void 0)
693
682
  do
694
683
  t = this.nodeIdGenerator.next();
@@ -698,34 +687,34 @@ class Z {
698
687
  this.graphStore.addNode(
699
688
  t,
700
689
  e,
701
- o,
702
690
  s,
703
- h ?? this.nodesCenterFn
704
- ), this.htmlController.attachNode(t), i !== void 0 && Object.entries(i).forEach(([a, c]) => {
705
- c instanceof HTMLElement ? this.markPort(a, c, t, this.portsCenterFn, null) : this.markPort(
706
- a,
707
- c.element,
691
+ r,
692
+ c ?? this.nodesCenterFn
693
+ ), this.htmlController.attachNode(t), a !== void 0 && Object.entries(a).forEach(([h, i]) => {
694
+ i instanceof HTMLElement ? this.markPort(h, i, t, this.portsCenterFn, null) : this.markPort(
695
+ h,
696
+ i.element,
708
697
  t,
709
- c.centerFn ?? this.portsCenterFn,
710
- c.direction ?? null
698
+ i.centerFn ?? this.portsCenterFn,
699
+ i.direction ?? null
711
700
  );
712
701
  });
713
702
  }
714
- markPort(t, e, o, s, i) {
703
+ markPort(t, e, s, r, a) {
715
704
  if (t === void 0)
716
705
  do
717
706
  t = this.portIdGenerator.next();
718
707
  while (this.graphStore.hasPort(t));
719
- if (!this.graphStore.hasNode(o))
708
+ if (!this.graphStore.hasNode(s))
720
709
  throw new Error("failed to set port on nonexisting node");
721
710
  if (this.graphStore.hasPort(t))
722
711
  throw new Error("failed to add port with existing id");
723
712
  this.graphStore.addPort(
724
713
  t,
725
714
  e,
726
- o,
727
- s ?? this.portsCenterFn,
728
- i ?? null
715
+ s,
716
+ r ?? this.portsCenterFn,
717
+ a ?? null
729
718
  );
730
719
  }
731
720
  updatePortConnections(t) {
@@ -740,20 +729,21 @@ class Z {
740
729
  this.removeConnection(e);
741
730
  }), this.graphStore.removePort(t);
742
731
  }
743
- addConnection(t, e, o, s) {
732
+ addConnection(t, e, s, r) {
744
733
  if (t === void 0)
745
734
  do
746
735
  t = this.connectionIdGenerator.next();
747
736
  while (this.graphStore.hasConnection(t));
748
737
  if (!this.graphStore.hasPort(e))
749
738
  throw new Error("failed to add connection from nonexisting port");
750
- if (!this.graphStore.hasPort(o))
739
+ if (!this.graphStore.hasPort(s))
751
740
  throw new Error("failed to add connection to nonexisting port");
752
- this.graphStore.addConnection(
741
+ let a = T.Regular;
742
+ e === s && (a = T.Cycle), this.graphStore.addConnection(
753
743
  t,
754
744
  e,
755
- o,
756
- s($.Regular)
745
+ s,
746
+ r(a)
757
747
  ), this.htmlController.attachConnection(t);
758
748
  }
759
749
  removeConnection(t) {
@@ -766,31 +756,25 @@ class Z {
766
756
  throw new Error("failed to remove nonexisting node");
767
757
  this.htmlController.detachNode(t), this.graphStore.removeNode(t);
768
758
  }
769
- patchViewportState(t, e, o) {
770
- this.viewportTransformer.patchState(t, e, o), this.htmlController.applyTransform();
771
- }
772
- moveViewport(t, e) {
773
- this.viewportTransformer.applyShift(t, e), this.htmlController.applyTransform();
774
- }
775
- scaleContent(t, e, o) {
776
- this.viewportTransformer.applyScale(t, e, o), this.htmlController.applyTransform();
759
+ patchViewportState(t, e, s) {
760
+ this.viewportTransformer.patchState(t, e, s), this.htmlController.applyTransform();
777
761
  }
778
762
  moveToNodes(t) {
779
763
  if (t.length === 0)
780
764
  return;
781
- const e = t.map((m) => this.graphStore.getNode(m)).filter((m) => m !== void 0);
765
+ const e = t.map((u) => this.graphStore.getNode(u)).filter((u) => u !== void 0);
782
766
  if (e.length < t.length)
783
767
  throw new Error("failed to move to nonexisting node");
784
- const [o, s] = e.reduce(
785
- (m, u) => [m[0] + u.x, m[1] + u.y],
768
+ const [s, r] = e.reduce(
769
+ (u, w) => [u[0] + w.x, u[1] + w.y],
786
770
  [0, 0]
787
- ), i = o / e.length, h = s / e.length, [a, c] = this.htmlController.getViewportDimensions(), l = this.viewportTransformer.getAbsScale(), g = i - l * a / 2, d = h - l * c / 2;
788
- this.patchViewportState(null, g, d);
771
+ ), a = s / e.length, c = r / e.length, [h, i] = this.htmlController.getViewportDimensions(), d = this.viewportTransformer.getAbsScale(), g = a - d * h / 2, l = c - d * i / 2;
772
+ this.patchViewportState(null, g, l);
789
773
  }
790
- updateNodeCoords(t, e, o) {
774
+ updateNodeCoordinates(t, e, s) {
791
775
  if (!this.graphStore.hasNode(t))
792
776
  throw new Error("failed to update coordinates of nonexisting node");
793
- this.graphStore.updateNodeCoords(t, e, o), this.htmlController.updateNodePosition(t);
777
+ this.graphStore.updateNodeCoords(t, e, s), this.htmlController.updateNodeCoordinates(t);
794
778
  }
795
779
  updateConnectionController(t, e) {
796
780
  if (!this.graphStore.hasConnection(t))
@@ -811,139 +795,138 @@ class Z {
811
795
  }
812
796
  }
813
797
  class H {
814
- constructor(t, e, o, s) {
815
- r(this, "htmlController");
816
- r(this, "viewportTransformer");
817
- r(this, "graphStore");
818
- r(this, "publicViewportTransformer");
819
- r(this, "publicGraphStore");
820
- r(this, "canvasController");
821
- this.viewportTransformer = new D(), this.publicViewportTransformer = new W(
822
- this.viewportTransformer
823
- ), this.graphStore = new R(), this.publicGraphStore = new z(this.graphStore), this.htmlController = new j(
824
- this.graphStore,
825
- this.viewportTransformer,
798
+ constructor(t, e, s, r) {
799
+ n(this, "publicViewportTransformer");
800
+ n(this, "canvasController");
801
+ const a = new W(), c = new R();
802
+ this.publicViewportTransformer = new j(
803
+ a
804
+ );
805
+ const h = new k(
806
+ c,
807
+ a,
826
808
  this.publicViewportTransformer,
827
809
  t,
828
810
  e
829
- ), this.canvasController = new Z(
830
- this.graphStore,
831
- this.htmlController,
832
- this.viewportTransformer,
833
- o,
834
- s
811
+ );
812
+ this.canvasController = new U(
813
+ c,
814
+ h,
815
+ a,
816
+ s,
817
+ r
835
818
  );
836
819
  }
837
820
  }
838
- const P = (n, t) => [
839
- n / 2,
821
+ const M = (o, t) => [
822
+ o / 2,
840
823
  t / 2
841
- ], U = () => () => {
842
- }, q = (n, t, e, o, s, i) => {
843
- n.clearRect(0, 0, n.canvas.width, n.canvas.height), n.save(), n.fillStyle = i, n.fillRect(0, 0, n.canvas.width, n.canvas.height);
844
- const h = t.getViewCoords(0, 0), a = t.getViewScale(), c = o * a;
845
- let l = 0, g = 0, d = c / 2;
824
+ ], _ = () => () => {
825
+ }, q = (o, t, e, s, r, a) => {
826
+ o.clearRect(0, 0, o.canvas.width, o.canvas.height), o.fillStyle = a, o.fillRect(0, 0, o.canvas.width, o.canvas.height);
827
+ const c = t.getViewCoords(0, 0), h = t.getViewScale(), i = s * h;
828
+ let d = 0, g = 0, l = i / 2;
846
829
  do
847
- d *= 2, l = n.canvas.width / d, g = n.canvas.height / d;
848
- while (l * g > 1e4);
849
- const m = h[0] - Math.floor(h[0] / d) * d, u = h[1] - Math.floor(h[1] / d) * d, p = s * a, f = 2 * Math.PI, y = m - d, S = u - d, b = n.canvas.width + m, N = n.canvas.height + u;
850
- n.fillStyle = e;
851
- for (let C = y; C <= b; C += d)
852
- for (let w = S; w <= N; w += d)
853
- n.beginPath(), n.arc(C, w, p, 0, f), n.closePath(), n.fill();
854
- n.restore();
855
- }, J = (n, t, e, o) => (s, i) => {
830
+ l *= 2, d = o.canvas.width / l, g = o.canvas.height / l;
831
+ while (d * g > 1e4);
832
+ const u = c[0] - Math.floor(c[0] / l) * l, w = c[1] - Math.floor(c[1] / l) * l, m = r * h, p = 2 * Math.PI, C = u - l, f = w - l, y = o.canvas.width + u, b = o.canvas.height + w;
833
+ o.fillStyle = e;
834
+ for (let E = C; E <= y; E += l)
835
+ for (let $ = f; $ <= b; $ += l)
836
+ o.beginPath(), o.arc(E, $, m, 0, p), o.closePath(), o.fill();
837
+ }, J = (o, t, e, s) => (r, a) => {
856
838
  q(
857
- s,
858
- i,
859
- n,
839
+ r,
840
+ a,
841
+ o,
860
842
  t,
861
843
  e,
862
- o
844
+ s
863
845
  );
864
- }, K = (n, t) => {
865
- n.fillStyle = t, n.fillRect(0, 0, n.canvas.width, n.canvas.height);
866
- }, Q = (n) => (t) => {
867
- K(t, n);
868
- }, _ = (n) => {
869
- switch (n == null ? void 0 : n.type) {
846
+ }, K = (o, t) => {
847
+ o.fillStyle = t, o.fillRect(0, 0, o.canvas.width, o.canvas.height);
848
+ }, Q = (o) => (t) => {
849
+ K(t, o);
850
+ }, I = (o) => {
851
+ switch (o == null ? void 0 : o.type) {
870
852
  case "custom":
871
- return n.drawingFn;
853
+ return o.drawingFn;
872
854
  case "dots":
873
855
  return J(
874
- n.dotColor ?? "#d8d8d8",
875
- n.dotGap ?? 25,
876
- n.dotRadius ?? 1.5,
877
- n.color ?? "#ffffff"
856
+ o.dotColor ?? "#d8d8d8",
857
+ o.dotGap ?? 25,
858
+ o.dotRadius ?? 1.5,
859
+ o.color ?? "#ffffff"
878
860
  );
879
861
  case "color":
880
- return Q(n.color ?? "#ffffff");
862
+ return Q(o.color ?? "#ffffff");
881
863
  default:
882
- return U();
864
+ return _();
883
865
  }
884
- }, O = (n) => {
885
- switch (n == null ? void 0 : n.type) {
866
+ }, O = (o) => {
867
+ switch (o == null ? void 0 : o.type) {
886
868
  case "custom":
887
- return n.controllerFactory;
869
+ return o.controllerFactory;
888
870
  case "straight":
889
- return X({
890
- color: n.color ?? "#5c5c5c",
891
- width: n.width ?? 1,
892
- arrowLength: n.arrowLength ?? 15,
893
- arrowWidth: n.arrowWidth ?? 4,
894
- minPortOffset: n.minPortOffset ?? 15,
895
- hasSourceArrow: n.hasSourceArrow ?? !1,
896
- hasTargetArrow: n.hasTargetArrow ?? !1
871
+ return Z({
872
+ color: o.color ?? "#5c5c5c",
873
+ width: o.width ?? 1,
874
+ arrowLength: o.arrowLength ?? 15,
875
+ arrowWidth: o.arrowWidth ?? 4,
876
+ minPortOffset: o.minPortOffset ?? 15,
877
+ hasSourceArrow: o.hasSourceArrow ?? !1,
878
+ hasTargetArrow: o.hasTargetArrow ?? !1,
879
+ cycleSquareSide: o.cycleSquareSide ?? 30,
880
+ roundness: o.roundness ?? 5
897
881
  });
898
882
  default:
899
- return B({
900
- color: n.color ?? "#5c5c5c",
901
- width: n.width ?? 1,
902
- curvature: n.curvature ?? 90,
903
- arrowLength: n.arrowLength ?? 15,
904
- arrowWidth: n.arrowWidth ?? 4,
905
- hasSourceArrow: n.hasSourceArrow ?? !1,
906
- hasTargetArrow: n.hasTargetArrow ?? !1
883
+ return X({
884
+ color: o.color ?? "#5c5c5c",
885
+ width: o.width ?? 1,
886
+ curvature: o.curvature ?? 90,
887
+ arrowLength: o.arrowLength ?? 15,
888
+ arrowWidth: o.arrowWidth ?? 4,
889
+ hasSourceArrow: o.hasSourceArrow ?? !1,
890
+ hasTargetArrow: o.hasTargetArrow ?? !1,
891
+ cycleRadius: o.cycleRadius ?? 30,
892
+ smallCycleRadius: o.smallCycleRadius ?? 15
907
893
  });
908
894
  }
909
- }, I = (n) => {
910
- var t, e, o;
895
+ }, tt = (o) => {
896
+ var t, e, s;
911
897
  return {
912
898
  background: {
913
- drawingFn: _(
914
- n.background ?? { type: "none" }
899
+ drawingFn: I(
900
+ o.background ?? { type: "none" }
915
901
  )
916
902
  },
917
903
  nodes: {
918
- centerFn: ((t = n.nodes) == null ? void 0 : t.centerFn) ?? P
904
+ centerFn: ((t = o.nodes) == null ? void 0 : t.centerFn) ?? M
919
905
  },
920
906
  ports: {
921
- centerFn: ((e = n.ports) == null ? void 0 : e.centerFn) ?? P
907
+ centerFn: ((e = o.ports) == null ? void 0 : e.centerFn) ?? M
922
908
  },
923
- connections: {
924
- controllerFactory: O(
925
- n.connections ?? {}
926
- )
909
+ edges: {
910
+ controllerFactory: O(o.edges ?? {})
927
911
  },
928
912
  layers: {
929
- mode: ((o = n.layers) == null ? void 0 : o.mode) ?? "connections-follow-node"
913
+ mode: ((s = o.layers) == null ? void 0 : s.mode) ?? "edges-follow-node"
930
914
  }
931
915
  };
932
916
  };
933
- class tt {
917
+ class et {
934
918
  constructor(t) {
935
- r(this, "transformation");
936
- r(this, "model");
937
- r(this, "di");
938
- r(this, "connectionControllerFactory");
919
+ n(this, "transformation");
920
+ n(this, "di");
921
+ n(this, "connectionControllerFactory");
939
922
  this.apiOptions = t;
940
- const e = I(this.apiOptions ?? {});
923
+ const e = tt(this.apiOptions ?? {});
941
924
  this.di = new H(
942
925
  e.layers.mode,
943
926
  e.background.drawingFn,
944
927
  e.nodes.centerFn,
945
928
  e.ports.centerFn
946
- ), this.transformation = this.di.publicViewportTransformer, this.model = this.di.publicGraphStore, this.connectionControllerFactory = e.connections.controllerFactory;
929
+ ), this.transformation = this.di.publicViewportTransformer, this.connectionControllerFactory = e.edges.controllerFactory;
947
930
  }
948
931
  addNode(t) {
949
932
  return this.di.canvasController.addNode(
@@ -970,13 +953,13 @@ class tt {
970
953
  t.direction
971
954
  ), this;
972
955
  }
973
- updatePortConnections(t) {
956
+ updatePortEdges(t) {
974
957
  return this.di.canvasController.updatePortConnections(t), this;
975
958
  }
976
959
  unmarkPort(t) {
977
960
  return this.di.canvasController.unmarkPort(t), this;
978
961
  }
979
- addConnection(t) {
962
+ addEdge(t) {
980
963
  const e = t.options !== void 0 ? O(t.options) : this.connectionControllerFactory;
981
964
  return this.di.canvasController.addConnection(
982
965
  t.id,
@@ -985,7 +968,7 @@ class tt {
985
968
  e
986
969
  ), this;
987
970
  }
988
- removeConnection(t) {
971
+ removeEdge(t) {
989
972
  return this.di.canvasController.removeConnection(t), this;
990
973
  }
991
974
  patchViewportState(t) {
@@ -995,24 +978,11 @@ class tt {
995
978
  t.y ?? null
996
979
  ), this;
997
980
  }
998
- moveViewport(t) {
999
- return this.di.canvasController.moveViewport(
1000
- t.x ?? 0,
1001
- t.y ?? 0
1002
- ), this;
1003
- }
1004
- scaleViewport(t) {
1005
- return this.di.canvasController.scaleContent(
1006
- t.scale,
1007
- t.x ?? 0,
1008
- t.y ?? 0
1009
- ), this;
1010
- }
1011
981
  moveToNodes(t) {
1012
982
  return this.di.canvasController.moveToNodes(t), this;
1013
983
  }
1014
- updateNodeCoords(t, e, o) {
1015
- return this.di.canvasController.updateNodeCoords(t, e, o), this;
984
+ updateNodeCoordinates(t, e, s) {
985
+ return this.di.canvasController.updateNodeCoordinates(t, e, s), this;
1016
986
  }
1017
987
  updateConnection(t, e) {
1018
988
  return e.controller !== void 0 && this.di.canvasController.updateConnectionController(
@@ -1020,9 +990,6 @@ class tt {
1020
990
  e.controller
1021
991
  ), this;
1022
992
  }
1023
- dragNode(t, e, o) {
1024
- return this.di.canvasController.dragNode(t, e, o), this;
1025
- }
1026
993
  clear() {
1027
994
  return this.di.canvasController.clear(), this;
1028
995
  }
@@ -1036,48 +1003,54 @@ class tt {
1036
1003
  this.di.canvasController.destroy();
1037
1004
  }
1038
1005
  }
1039
- class et {
1040
- constructor(t) {
1041
- r(this, "transformation");
1042
- r(this, "model");
1043
- r(this, "nodes", /* @__PURE__ */ new Map());
1044
- r(this, "grabbedNodeId", null);
1045
- r(this, "nodeIdGenerator", new A());
1046
- r(this, "element", null);
1047
- r(this, "onCanvasMouseUp", () => {
1006
+ class st {
1007
+ constructor(t, e) {
1008
+ n(this, "transformation");
1009
+ n(this, "nodes", /* @__PURE__ */ new Map());
1010
+ n(this, "grabbedNodeId", null);
1011
+ n(this, "onNodeDrag");
1012
+ n(this, "onBeforeNodeDrag");
1013
+ n(this, "nodeIdGenerator", new S());
1014
+ n(this, "element", null);
1015
+ n(this, "onCanvasMouseUp", () => {
1048
1016
  this.setCursor(null), this.grabbedNodeId = null;
1049
1017
  });
1050
- r(this, "onCanvasMouseMove", (t) => {
1051
- this.grabbedNodeId !== null && (t.stopPropagation(), this.canvas.dragNode(
1052
- this.grabbedNodeId,
1053
- t.movementX,
1054
- t.movementY
1055
- ));
1018
+ n(this, "onCanvasMouseMove", (t) => {
1019
+ this.grabbedNodeId !== null && (t.stopPropagation(), this.dragNode(this.grabbedNodeId, t.movementX, t.movementY));
1056
1020
  });
1057
- r(this, "onCanvasTouchStart", (t) => {
1021
+ n(this, "onCanvasTouchStart", (t) => {
1058
1022
  this.previousTouchCoords = [
1059
1023
  t.touches[0].clientX,
1060
1024
  t.touches[0].clientY
1061
1025
  ];
1062
1026
  });
1063
- r(this, "onCanvasTouchMove", (t) => {
1027
+ n(this, "onCanvasTouchMove", (t) => {
1064
1028
  if (this.grabbedNodeId === null || t.touches.length !== 1 || this.previousTouchCoords === null)
1065
1029
  return;
1066
1030
  t.stopImmediatePropagation();
1067
- const [e, o] = [
1031
+ const [e, s] = [
1068
1032
  t.touches[0].clientX - this.previousTouchCoords[0],
1069
1033
  t.touches[0].clientY - this.previousTouchCoords[1]
1070
1034
  ];
1071
- this.canvas.dragNode(this.grabbedNodeId, e, o), this.previousTouchCoords = [
1035
+ this.dragNode(this.grabbedNodeId, e, s), this.previousTouchCoords = [
1072
1036
  t.touches[0].clientX,
1073
1037
  t.touches[0].clientY
1074
1038
  ];
1075
1039
  });
1076
- r(this, "onCanvasTouchEnd", () => {
1077
- this.previousTouchCoords = null, this.grabbedNodeId = null;
1040
+ n(this, "onCanvasTouchEnd", (t) => {
1041
+ t.touches.length > 0 ? this.previousTouchCoords = [
1042
+ t.touches[0].clientX,
1043
+ t.touches[0].clientY
1044
+ ] : (this.previousTouchCoords = null, this.grabbedNodeId = null);
1078
1045
  });
1079
- r(this, "previousTouchCoords", null);
1080
- this.canvas = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1046
+ n(this, "previousTouchCoords", null);
1047
+ var a, c;
1048
+ this.canvas = t, this.transformation = this.canvas.transformation;
1049
+ const s = () => {
1050
+ };
1051
+ this.onNodeDrag = ((a = e == null ? void 0 : e.events) == null ? void 0 : a.onNodeDrag) ?? s;
1052
+ const r = () => !0;
1053
+ this.onBeforeNodeDrag = ((c = e == null ? void 0 : e.events) == null ? void 0 : c.onBeforeNodeDrag) ?? r;
1081
1054
  }
1082
1055
  addNode(t) {
1083
1056
  let e = t.id;
@@ -1086,131 +1059,157 @@ class et {
1086
1059
  e = this.nodeIdGenerator.next();
1087
1060
  while (this.nodes.has(e));
1088
1061
  this.canvas.addNode(t);
1089
- const o = (i) => {
1090
- i.stopImmediatePropagation(), this.grabbedNodeId = e, this.setCursor("grab"), this.canvas.moveNodeOnTop(e);
1091
- }, s = (i) => {
1092
- i.touches.length === 1 && (this.grabbedNodeId = e, this.canvas.moveNodeOnTop(e));
1062
+ const s = (a) => {
1063
+ this.onBeforeNodeDrag({
1064
+ nodeId: e,
1065
+ element: t.element,
1066
+ x: t.x,
1067
+ y: t.y
1068
+ }) && (a.stopImmediatePropagation(), this.grabbedNodeId = e, this.setCursor("grab"), this.canvas.moveNodeOnTop(e));
1069
+ }, r = (a) => {
1070
+ this.onBeforeNodeDrag({
1071
+ nodeId: e,
1072
+ element: t.element,
1073
+ x: t.x,
1074
+ y: t.y
1075
+ }) && a.touches.length === 1 && (this.grabbedNodeId = e, this.canvas.moveNodeOnTop(e));
1093
1076
  };
1094
1077
  return this.nodes.set(e, {
1095
- el: t.element,
1096
- onMouseDown: o,
1097
- onTouchStart: s
1098
- }), t.element.addEventListener("mousedown", o), t.element.addEventListener("touchstart", s), this;
1078
+ element: t.element,
1079
+ onMouseDown: s,
1080
+ onTouchStart: r,
1081
+ x: t.x,
1082
+ y: t.y
1083
+ }), t.element.addEventListener("mousedown", s), t.element.addEventListener("touchstart", r), this;
1099
1084
  }
1100
1085
  removeNode(t) {
1101
1086
  const e = this.nodes.get(t);
1102
- return e !== void 0 && (e.el.removeEventListener("mousedown", e.onMouseDown), e.el.removeEventListener("touchstart", e.onTouchStart)), this.canvas.removeNode(t), this.nodes.delete(t), this;
1087
+ return e !== void 0 && (e.element.removeEventListener("mousedown", e.onMouseDown), e.element.removeEventListener("touchstart", e.onTouchStart)), this.canvas.removeNode(t), this.nodes.delete(t), this;
1103
1088
  }
1104
1089
  markPort(t) {
1105
1090
  return this.canvas.markPort(t), this;
1106
1091
  }
1107
- updatePortConnections(t) {
1108
- return this.canvas.updatePortConnections(t), this;
1092
+ updatePortEdges(t) {
1093
+ return this.canvas.updatePortEdges(t), this;
1109
1094
  }
1110
1095
  unmarkPort(t) {
1111
1096
  return this.canvas.unmarkPort(t), this;
1112
1097
  }
1113
- addConnection(t) {
1114
- return this.canvas.addConnection(t), this;
1098
+ addEdge(t) {
1099
+ return this.canvas.addEdge(t), this;
1115
1100
  }
1116
- removeConnection(t) {
1117
- return this.canvas.removeConnection(t), this;
1101
+ removeEdge(t) {
1102
+ return this.canvas.removeEdge(t), this;
1118
1103
  }
1119
1104
  patchViewportState(t) {
1120
1105
  return this.canvas.patchViewportState(t), this;
1121
1106
  }
1122
- moveViewport(t) {
1123
- return this.canvas.moveViewport(t), this;
1124
- }
1125
- scaleViewport(t) {
1126
- return this.canvas.scaleViewport(t), this;
1127
- }
1128
1107
  moveToNodes(t) {
1129
1108
  return this.canvas.moveToNodes(t), this;
1130
1109
  }
1131
- updateNodeCoords(t, e, o) {
1132
- return this.canvas.updateNodeCoords(t, e, o), this;
1110
+ updateNodeCoordinates(t, e, s) {
1111
+ return this.canvas.updateNodeCoordinates(t, e, s), this;
1133
1112
  }
1134
1113
  updateConnection(t, e) {
1135
1114
  return this.canvas.updateConnection(t, e), this;
1136
1115
  }
1137
- dragNode(t, e, o) {
1138
- return this.canvas.dragNode(t, e, o), this;
1139
- }
1140
1116
  moveNodeOnTop(t) {
1141
1117
  return this.canvas.moveNodeOnTop(t), this;
1142
1118
  }
1143
1119
  clear() {
1144
1120
  return this.canvas.clear(), this.nodes.forEach((t) => {
1145
- t.el.removeEventListener("mousedown", t.onMouseDown), t.el.removeEventListener("touchstart", t.onTouchStart);
1121
+ t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart);
1146
1122
  }), this.nodes.clear(), this;
1147
1123
  }
1148
1124
  attach(t) {
1149
- return this.canvas.attach(t), this.element = t, this.element.addEventListener("mouseup", this.onCanvasMouseUp), this.element.addEventListener("mousemove", this.onCanvasMouseMove), this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.element.addEventListener("touchmove", this.onCanvasTouchMove), this.element.addEventListener("touchend", this.onCanvasTouchEnd), this.element.addEventListener("touchcancel", this.onCanvasTouchEnd), this;
1125
+ return this.detach(), this.element = t, this.canvas.attach(this.element), this.element.addEventListener("mouseup", this.onCanvasMouseUp), this.element.addEventListener("mousemove", this.onCanvasMouseMove), this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.element.addEventListener("touchmove", this.onCanvasTouchMove), this.element.addEventListener("touchend", this.onCanvasTouchEnd), this.element.addEventListener("touchcancel", this.onCanvasTouchEnd), this;
1150
1126
  }
1151
1127
  detach() {
1152
1128
  return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mouseup", this.onCanvasMouseUp), this.element.removeEventListener("mousemove", this.onCanvasMouseMove), this.element.removeEventListener("touchstart", this.onCanvasTouchStart), this.element.removeEventListener("touchmove", this.onCanvasTouchMove), this.element.removeEventListener("touchend", this.onCanvasTouchEnd), this.element.removeEventListener("touchcancel", this.onCanvasTouchEnd), this.element = null), this;
1153
1129
  }
1154
1130
  destroy() {
1155
1131
  this.detach(), this.nodes.forEach((t) => {
1156
- t.el.removeEventListener("mousedown", t.onMouseDown), t.el.removeEventListener("touchstart", t.onTouchStart);
1157
- }), this.canvas.destroy();
1132
+ t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart);
1133
+ }), this.nodes.clear(), this.canvas.destroy();
1158
1134
  }
1159
1135
  setCursor(t) {
1160
1136
  this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1161
1137
  }
1138
+ dragNode(t, e, s) {
1139
+ const r = this.nodes.get(t);
1140
+ if (r === void 0)
1141
+ throw new Error("failed to drag nonexisting node");
1142
+ const [a, c] = this.transformation.getViewCoords(r.x, r.y), h = a + e, i = c + s, [d, g] = this.transformation.getAbsCoords(h, i);
1143
+ r.x = d, r.y = g, this.canvas.updateNodeCoordinates(t, d, g), this.onNodeDrag({
1144
+ nodeId: t,
1145
+ element: r.element,
1146
+ x: r.x,
1147
+ y: r.y
1148
+ });
1149
+ }
1162
1150
  }
1163
1151
  class ot {
1164
1152
  constructor(t, e) {
1165
- r(this, "transformation");
1166
- r(this, "model");
1167
- r(this, "element", null);
1168
- r(this, "isMoving", !1);
1169
- r(this, "prevTouches", null);
1170
- r(this, "isScalable");
1171
- r(this, "isShiftable");
1172
- r(this, "minContentScale");
1173
- r(this, "maxContentScale");
1174
- r(this, "wheelSensitivity");
1175
- r(this, "onMouseDown", () => {
1153
+ n(this, "transformation");
1154
+ n(this, "element", null);
1155
+ n(this, "isMoving", !1);
1156
+ n(this, "prevTouches", null);
1157
+ n(this, "onTransform");
1158
+ n(this, "onBeforeTransform");
1159
+ n(this, "isScalable");
1160
+ n(this, "isShiftable");
1161
+ n(this, "minViewScale");
1162
+ n(this, "maxViewScale");
1163
+ n(this, "wheelSensitivity");
1164
+ n(this, "onMouseDown", () => {
1176
1165
  this.setCursor("grab"), this.isMoving = !0;
1177
1166
  });
1178
- r(this, "onMouseMove", (t) => {
1179
- !this.isMoving || !this.isShiftable || this.canvas.moveViewport({ x: -t.movementX, y: -t.movementY });
1167
+ n(this, "onMouseMove", (t) => {
1168
+ if (!this.isMoving || !this.isShiftable)
1169
+ return;
1170
+ const e = -t.movementX, s = -t.movementY;
1171
+ this.moveViewport(e, s);
1180
1172
  });
1181
- r(this, "onMouseUp", () => {
1173
+ n(this, "onMouseUp", () => {
1182
1174
  this.setCursor(null), this.isMoving = !1;
1183
1175
  });
1184
- r(this, "onWheelScroll", (t) => {
1176
+ n(this, "onWheelScroll", (t) => {
1185
1177
  if (this.element === null || this.isScalable === !1)
1186
1178
  return;
1187
1179
  t.preventDefault();
1188
- const { left: e, top: o } = this.element.getBoundingClientRect(), s = t.clientX - e, i = t.clientY - o, h = t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity, a = this.canvas.transformation.getViewScale() * h;
1189
- this.checkNextScaleValid(a) && this.canvas.scaleViewport({ scale: 1 / h, x: s, y: i });
1180
+ const { left: e, top: s } = this.element.getBoundingClientRect(), r = t.clientX - e, a = t.clientY - s, h = 1 / (t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
1181
+ this.scaleViewport(h, r, a);
1190
1182
  });
1191
- r(this, "onTouchStart", (t) => {
1183
+ n(this, "onTouchStart", (t) => {
1192
1184
  this.prevTouches = this.getAverageTouch(t);
1193
1185
  });
1194
- r(this, "onTouchMove", (t) => {
1186
+ n(this, "onTouchMove", (t) => {
1195
1187
  if (this.prevTouches === null || this.element === null || !this.isShiftable)
1196
1188
  return;
1197
1189
  const e = this.getAverageTouch(t);
1198
- if ((e.touchesCnt === 1 || e.touchesCnt === 2) && this.canvas.moveViewport({
1199
- x: -(e.x - this.prevTouches.x),
1200
- y: -(e.y - this.prevTouches.y)
1201
- }), e.touchesCnt === 2 && this.isScalable) {
1202
- const { left: o, top: s } = this.element.getBoundingClientRect(), i = this.prevTouches.x - o, h = this.prevTouches.y - s, a = e.scale / this.prevTouches.scale, c = this.canvas.transformation.getViewScale() * a;
1203
- this.checkNextScaleValid(c) && this.canvas.scaleViewport({ scale: 1 / a, x: i, y: h });
1190
+ if ((e.touchesCnt === 1 || e.touchesCnt === 2) && this.moveViewport(
1191
+ -(e.x - this.prevTouches.x),
1192
+ -(e.y - this.prevTouches.y)
1193
+ ), e.touchesCnt === 2 && this.isScalable) {
1194
+ const { left: s, top: r } = this.element.getBoundingClientRect(), a = this.prevTouches.x - s, c = this.prevTouches.y - r, i = 1 / (e.scale / this.prevTouches.scale);
1195
+ this.scaleViewport(i, a, c);
1204
1196
  }
1205
1197
  this.prevTouches = e, t.preventDefault();
1206
1198
  });
1207
- r(this, "onTouchEnd", () => {
1208
- this.prevTouches = null;
1199
+ n(this, "onTouchEnd", (t) => {
1200
+ t.touches.length > 0 ? this.prevTouches = this.getAverageTouch(t) : this.prevTouches = null;
1209
1201
  });
1210
- var s, i, h, a, c, l, g, d, m, u;
1211
- this.canvas = t, this.options = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((i = (s = this.options) == null ? void 0 : s.scale) == null ? void 0 : i.enabled) !== !1, this.minContentScale = ((a = (h = this.options) == null ? void 0 : h.scale) == null ? void 0 : a.minContent) ?? null, this.maxContentScale = ((l = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : l.maxContent) ?? null, this.isShiftable = ((d = (g = this.options) == null ? void 0 : g.shift) == null ? void 0 : d.enabled) !== !1;
1212
- const o = (u = (m = this.options) == null ? void 0 : m.scale) == null ? void 0 : u.wheelSensitivity;
1213
- this.wheelSensitivity = o !== void 0 ? o : 1.2;
1202
+ var i, d, g, l, u, w, m, p, C, f, y, b;
1203
+ this.canvas = t, this.options = e, this.transformation = this.canvas.transformation;
1204
+ const s = ((d = (i = this.options) == null ? void 0 : i.scale) == null ? void 0 : d.min) ?? null, r = ((l = (g = this.options) == null ? void 0 : g.scale) == null ? void 0 : l.max) ?? null;
1205
+ this.isScalable = ((w = (u = this.options) == null ? void 0 : u.scale) == null ? void 0 : w.enabled) !== !1, this.minViewScale = r !== null ? 1 / r : null, this.maxViewScale = s !== null ? 1 / s : null, this.isShiftable = ((p = (m = this.options) == null ? void 0 : m.shift) == null ? void 0 : p.enabled) !== !1;
1206
+ const a = (f = (C = this.options) == null ? void 0 : C.scale) == null ? void 0 : f.wheelSensitivity;
1207
+ this.wheelSensitivity = a !== void 0 ? a : 1.2;
1208
+ const c = () => {
1209
+ };
1210
+ this.onTransform = ((y = e == null ? void 0 : e.events) == null ? void 0 : y.onTransform) ?? c;
1211
+ const h = () => !0;
1212
+ this.onBeforeTransform = ((b = e == null ? void 0 : e.events) == null ? void 0 : b.onBeforeTransform) ?? h;
1214
1213
  }
1215
1214
  addNode(t) {
1216
1215
  return this.canvas.addNode(t), this;
@@ -1221,39 +1220,30 @@ class ot {
1221
1220
  markPort(t) {
1222
1221
  return this.canvas.markPort(t), this;
1223
1222
  }
1224
- updatePortConnections(t) {
1225
- return this.canvas.updatePortConnections(t), this;
1223
+ updatePortEdges(t) {
1224
+ return this.canvas.updatePortEdges(t), this;
1226
1225
  }
1227
1226
  unmarkPort(t) {
1228
1227
  return this.canvas.unmarkPort(t), this;
1229
1228
  }
1230
- addConnection(t) {
1231
- return this.canvas.addConnection(t), this;
1229
+ addEdge(t) {
1230
+ return this.canvas.addEdge(t), this;
1232
1231
  }
1233
- removeConnection(t) {
1234
- return this.canvas.removeConnection(t), this;
1232
+ removeEdge(t) {
1233
+ return this.canvas.removeEdge(t), this;
1235
1234
  }
1236
1235
  patchViewportState(t) {
1237
1236
  return this.canvas.patchViewportState(t), this;
1238
1237
  }
1239
- moveViewport(t) {
1240
- return this.canvas.moveViewport(t), this;
1241
- }
1242
- scaleViewport(t) {
1243
- return this.canvas.scaleViewport(t), this;
1244
- }
1245
1238
  moveToNodes(t) {
1246
1239
  return this.canvas.moveToNodes(t), this;
1247
1240
  }
1248
- updateNodeCoords(t, e, o) {
1249
- return this.canvas.updateNodeCoords(t, e, o), this;
1241
+ updateNodeCoordinates(t, e, s) {
1242
+ return this.canvas.updateNodeCoordinates(t, e, s), this;
1250
1243
  }
1251
1244
  updateConnection(t, e) {
1252
1245
  return this.canvas.updateConnection(t, e), this;
1253
1246
  }
1254
- dragNode(t, e, o) {
1255
- return this.canvas.dragNode(t, e, o), this;
1256
- }
1257
1247
  moveNodeOnTop(t) {
1258
1248
  return this.canvas.moveNodeOnTop(t), this;
1259
1249
  }
@@ -1261,65 +1251,79 @@ class ot {
1261
1251
  return this.canvas.clear(), this;
1262
1252
  }
1263
1253
  attach(t) {
1264
- return this.canvas.attach(t), this.element = t, this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("mousemove", this.onMouseMove), this.element.addEventListener("mouseup", this.onMouseUp), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.element.addEventListener("touchmove", this.onTouchMove), this.element.addEventListener("touchend", this.onTouchEnd), this.element.addEventListener("touchcancel", this.onTouchEnd), this;
1254
+ return this.detach(), this.element = t, this.canvas.attach(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("mousemove", this.onMouseMove), this.element.addEventListener("mouseup", this.onMouseUp), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.element.addEventListener("touchmove", this.onTouchMove), this.element.addEventListener("touchend", this.onTouchEnd), this.element.addEventListener("touchcancel", this.onTouchEnd), this;
1265
1255
  }
1266
1256
  detach() {
1267
- return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("mousemove", this.onMouseMove), this.element.removeEventListener("mouseup", this.onMouseUp), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("touchmove", this.onTouchMove), this.element.removeEventListener("touchend", this.onTouchEnd), this.element.removeEventListener("touchcancel", this.onTouchEnd)), this.element = null, this;
1257
+ return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("mousemove", this.onMouseMove), this.element.removeEventListener("mouseup", this.onMouseUp), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("touchmove", this.onTouchMove), this.element.removeEventListener("touchend", this.onTouchEnd), this.element.removeEventListener("touchcancel", this.onTouchEnd), this.element = null), this;
1268
1258
  }
1269
1259
  destroy() {
1270
1260
  this.detach(), this.canvas.destroy();
1271
1261
  }
1272
1262
  getAverageTouch(t) {
1273
- const e = [], o = t.touches.length;
1274
- for (let c = 0; c < o; c++)
1275
- e.push([t.touches[c].clientX, t.touches[c].clientY]);
1276
- const s = e.reduce(
1277
- (c, l) => [c[0] + l[0], c[1] + l[1]],
1263
+ const e = [], s = t.touches.length;
1264
+ for (let i = 0; i < s; i++)
1265
+ e.push([t.touches[i].clientX, t.touches[i].clientY]);
1266
+ const r = e.reduce(
1267
+ (i, d) => [i[0] + d[0], i[1] + d[1]],
1278
1268
  [0, 0]
1279
- ), i = [s[0] / o, s[1] / o], a = e.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1280
- (c, l) => c + Math.sqrt(l[0] * l[0] + l[1] * l[1]),
1269
+ ), a = [r[0] / s, r[1] / s], h = e.map((i) => [i[0] - a[0], i[1] - a[1]]).reduce(
1270
+ (i, d) => i + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
1281
1271
  0
1282
1272
  );
1283
- return { x: i[0], y: i[1], scale: a / o, touchesCnt: o };
1284
- }
1285
- checkNextScaleValid(t) {
1286
- const e = this.canvas.transformation.getViewScale();
1287
- return !(this.maxContentScale !== null && t > this.maxContentScale && t > e || this.minContentScale !== null && t < this.minContentScale && t < e);
1273
+ return { x: a[0], y: a[1], scale: h / s, touchesCnt: s };
1288
1274
  }
1289
1275
  setCursor(t) {
1290
1276
  this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1291
1277
  }
1278
+ moveViewport(t, e) {
1279
+ const [s, r] = this.transformation.getAbsCoords(0, 0), a = this.canvas.transformation.getAbsScale(), c = {
1280
+ scale: a,
1281
+ x: s + a * t,
1282
+ y: r + a * e
1283
+ };
1284
+ this.onBeforeTransform({ ...c }) && (this.canvas.patchViewportState(c), this.onTransform(c));
1285
+ }
1286
+ scaleViewport(t, e, s) {
1287
+ const [r, a] = this.canvas.transformation.getAbsCoords(0, 0), c = this.canvas.transformation.getAbsScale(), h = c * t, i = c * (1 - t) * e + r, d = c * (1 - t) * s + a;
1288
+ if (this.maxViewScale !== null && h > this.maxViewScale && h > c || this.minViewScale !== null && h < this.minViewScale && h < c)
1289
+ return;
1290
+ const g = { scale: h, x: i, y: d };
1291
+ this.onBeforeTransform({ ...g }) && (this.canvas.patchViewportState(g), this.onTransform(g));
1292
+ }
1292
1293
  }
1293
- class st {
1294
+ class nt {
1294
1295
  constructor() {
1295
- r(this, "coreOptions");
1296
- r(this, "transformOptions");
1297
- r(this, "isDraggable", !1);
1298
- r(this, "isTransformable", !1);
1296
+ n(this, "coreOptions");
1297
+ n(this, "dragOptions");
1298
+ n(this, "transformOptions");
1299
+ n(this, "isDraggable", !1);
1300
+ n(this, "isTransformable", !1);
1299
1301
  }
1300
1302
  setOptions(t) {
1301
1303
  return this.coreOptions = t, this;
1302
1304
  }
1303
- setDraggableNodes() {
1304
- return this.isDraggable = !0, this;
1305
+ setUserDraggableNodes(t) {
1306
+ return this.isDraggable = !0, this.dragOptions = t, this;
1305
1307
  }
1306
- setTransformableCanvas(t) {
1308
+ setUserTransformableCanvas(t) {
1307
1309
  return this.isTransformable = !0, this.transformOptions = t, this;
1308
1310
  }
1309
1311
  build() {
1310
- let t = new tt(this.coreOptions);
1311
- return this.isDraggable && (t = new et(t)), this.isTransformable && (t = new ot(t, this.transformOptions)), t;
1312
+ let t = new et(this.coreOptions);
1313
+ return this.isDraggable && (t = new st(t, this.dragOptions)), this.isTransformable && (t = new ot(t, this.transformOptions)), t;
1312
1314
  }
1313
1315
  }
1314
1316
  export {
1315
- G as BezierConnectionController,
1316
- tt as CanvasCore,
1317
- $ as ConnectionType,
1318
- v as ConnectionUtils,
1319
- et as DraggableNodesCanvas,
1320
- st as HtmlGraphBuilder,
1321
- Y as StraightConnectionController,
1322
- ot as TransformableCanvas,
1323
- B as createBezierConnectionControllerFactory,
1324
- X as createStraightConnectionControllerFactory
1317
+ B as BezierEdgeController,
1318
+ et as CanvasCore,
1319
+ Y as CycleCircleEdgeController,
1320
+ G as CycleSquareEdgeController,
1321
+ T as EdgeType,
1322
+ v as EdgeUtils,
1323
+ nt as HtmlGraphBuilder,
1324
+ z as StraightEdgeController,
1325
+ st as UserDraggableNodesCanvas,
1326
+ ot as UserTransformableCanvas,
1327
+ X as createBezierEdgeControllerFactory,
1328
+ Z as createStraightEdgeControllerFactory
1325
1329
  };