@html-graph/html-graph 0.0.48 → 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 = (s, t, e) => t in s ? F(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var r = (s, t, e) => k(s, typeof t != "symbol" ? t + "" : t, e);
4
- class j {
5
- constructor(t, e, o, n, 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((n) => {
43
- this.connectionIdToElementMap.get(n).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 = n, 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,7 +72,7 @@ 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
78
  this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
@@ -82,22 +82,22 @@ class j {
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);
@@ -107,14 +107,14 @@ class j {
107
107
  this.layers[this.layersMode].moveOnTop(t);
108
108
  }
109
109
  updateNodeCoordinates(t) {
110
- const e = this.graphStore.getNode(t), o = this.graphStore.getNodeAdjacentConnections(t);
111
- this.updateNodeCoords(t, e.x, e.y), o.forEach((n) => {
112
- this.updateConnectionCoords(n);
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, n = this.nodeWrapperElementToIdMap.get(o), i = this.graphStore.getNode(n);
149
- this.updateNodeCoords(n, i.x, i.y), this.graphStore.getNodeAdjacentConnections(n).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,30 +156,30 @@ 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 n = this.nodeIdToWrapperElementMap.get(t), { width: i, height: h } = n.getBoundingClientRect(), a = this.viewportTransformer.getAbsScale(), c = this.graphStore.getNode(t), [l, g] = c.centerFn(i, h);
161
- n.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), n = this.graphStore.getPort(e.to), i = o.element.getBoundingClientRect(), h = n.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
- ), [C, w] = n.centerFn(
174
- h.width * m,
175
- h.height * m
176
- ), b = u + c, T = p + l, S = C + g, f = w + d, y = Math.min(b, S), N = Math.min(T, f), E = Math.abs(S - b), O = Math.abs(f - T), x = this.connectionIdToElementMap.get(t), L = b <= S, V = T <= f;
177
- x.style.transform = `matrix(${L ? 1 : -1}, 0, 0, ${V ? 1 : -1}, ${y}, ${N})`, e.controller.update(y, N, E, O, o, n);
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
@@ -203,15 +203,15 @@ class D {
203
203
  getAbsScale() {
204
204
  return this.state.scale;
205
205
  }
206
- patchState(t, e, o) {
206
+ patchState(t, e, s) {
207
207
  this.state = {
208
208
  scale: t ?? this.state.scale,
209
209
  x: e ?? this.state.x,
210
- y: o ?? this.state.y
210
+ y: s ?? this.state.y
211
211
  };
212
212
  }
213
213
  }
214
- class W {
214
+ class j {
215
215
  constructor(t) {
216
216
  this.transformer = t;
217
217
  }
@@ -246,20 +246,20 @@ class W {
246
246
  }
247
247
  class R {
248
248
  constructor() {
249
- r(this, "nodes", /* @__PURE__ */ Object.create(null));
250
- r(this, "ports", /* @__PURE__ */ Object.create(null));
251
- r(this, "nodePorts", /* @__PURE__ */ Object.create(null));
252
- r(this, "portNodeId", /* @__PURE__ */ Object.create(null));
253
- r(this, "connections", /* @__PURE__ */ Object.create(null));
254
- r(this, "incommingConnections", /* @__PURE__ */ Object.create(null));
255
- r(this, "outcommingConnections", /* @__PURE__ */ Object.create(null));
256
- 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));
257
257
  }
258
258
  getAllNodes() {
259
259
  return this.nodes;
260
260
  }
261
- addNode(t, e, o, n, i) {
262
- this.nodes[t] = { element: e, x: o, y: n, 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);
263
263
  }
264
264
  hasNode(t) {
265
265
  return this.nodes[t] !== void 0;
@@ -267,25 +267,25 @@ class R {
267
267
  getNode(t) {
268
268
  return this.nodes[t];
269
269
  }
270
- updateNodeCoords(t, e, o) {
271
- 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;
272
272
  }
273
273
  updateConnectionController(t, e) {
274
274
  this.connections[t].controller = e;
275
275
  }
276
276
  removeNode(t) {
277
- this.getNodeAdjacentConnections(t).forEach((n) => {
278
- this.removeConnection(n);
277
+ this.getNodeAdjacentConnections(t).forEach((r) => {
278
+ this.removeConnection(r);
279
279
  }), delete this.nodes[t];
280
- const o = this.nodePorts[t];
281
- Object.keys(o).forEach((n) => {
282
- delete this.portNodeId[n];
280
+ const s = this.nodePorts[t];
281
+ Object.keys(s).forEach((r) => {
282
+ delete this.portNodeId[r];
283
283
  }), delete this.nodePorts[t];
284
284
  }
285
- addPort(t, e, o, n, i) {
286
- this.ports[t] = { element: e, centerFn: n, direction: i }, this.cycleConnections[t] = {}, this.incommingConnections[t] = {}, this.outcommingConnections[t] = {}, this.portNodeId[t] = o;
287
- const h = this.nodePorts[o];
288
- 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);
289
289
  }
290
290
  getPort(t) {
291
291
  return this.ports[t];
@@ -297,24 +297,24 @@ class R {
297
297
  return this.portNodeId[t] !== void 0;
298
298
  }
299
299
  removePort(t) {
300
- Object.keys(this.cycleConnections[t]).forEach((n) => {
301
- this.removeConnection(n);
302
- }), delete this.cycleConnections[t], Object.keys(this.incommingConnections[t]).forEach((n) => {
303
- this.removeConnection(n);
304
- }), delete this.incommingConnections[t], Object.keys(this.outcommingConnections[t]).forEach((n) => {
305
- this.removeConnection(n);
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);
306
306
  }), delete this.outcommingConnections[t];
307
307
  const e = this.portNodeId[t];
308
308
  delete this.portNodeId[t];
309
- const o = this.nodePorts[e];
310
- delete o[t], delete this.ports[t];
309
+ const s = this.nodePorts[e];
310
+ delete s[t], delete this.ports[t];
311
311
  }
312
- addConnection(t, e, o, n) {
312
+ addConnection(t, e, s, r) {
313
313
  this.connections[t] = {
314
314
  from: e,
315
- to: o,
316
- controller: n
317
- }, 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;
318
318
  }
319
319
  getConnection(t) {
320
320
  return this.connections[t];
@@ -323,8 +323,8 @@ class R {
323
323
  return this.connections[t] !== void 0;
324
324
  }
325
325
  removeConnection(t) {
326
- const e = this.connections[t], o = e.from, n = e.to;
327
- delete this.cycleConnections[o][t], delete this.cycleConnections[n][t], delete this.incommingConnections[o][t], delete this.incommingConnections[n][t], delete this.outcommingConnections[o][t], delete this.outcommingConnections[n][t], delete this.connections[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];
328
328
  }
329
329
  getPortAdjacentConnections(t) {
330
330
  return [
@@ -354,238 +354,308 @@ class R {
354
354
  }
355
355
  getNodeIncomingConnections(t) {
356
356
  const e = Object.keys(this.nodePorts[t]);
357
- let o = [];
358
- return e.forEach((n) => {
359
- o = [...o, ...this.getPortIncomingConnections(n)];
360
- }), o;
357
+ let s = [];
358
+ return e.forEach((r) => {
359
+ s = [...s, ...this.getPortIncomingConnections(r)];
360
+ }), s;
361
361
  }
362
362
  getNodeOutcomingConnections(t) {
363
363
  const e = Object.keys(this.nodePorts[t]);
364
- let o = [];
365
- return e.forEach((n) => {
366
- o = [...o, ...this.getPortOutcomingConnections(n)];
367
- }), o;
364
+ let s = [];
365
+ return e.forEach((r) => {
366
+ s = [...s, ...this.getPortOutcomingConnections(r)];
367
+ }), s;
368
368
  }
369
369
  getNodeCycleConnections(t) {
370
370
  const e = Object.keys(this.nodePorts[t]);
371
- let o = [];
372
- return e.forEach((n) => {
373
- o = [...o, ...this.getPortCycleConnections(n)];
374
- }), o;
375
- }
376
- }
377
- class z {
378
- constructor(t) {
379
- this.graphStore = t;
380
- }
381
- getNode(t) {
382
- const e = this.graphStore.getNode(t);
383
- return e === void 0 ? null : { x: e.x, y: e.y, element: e.element };
384
- }
385
- getNodes(t) {
386
- const e = Object.entries(this.graphStore.getAllNodes()).map(
387
- ([o, n]) => ({
388
- id: o,
389
- x: n.x,
390
- y: n.y,
391
- element: n.element
392
- })
393
- );
394
- if (t !== void 0) {
395
- const o = /* @__PURE__ */ new Set();
396
- return t.forEach((n) => {
397
- o.add(n);
398
- }), e.filter((n) => o.has(n.id));
399
- }
400
- return e;
371
+ let s = [];
372
+ return e.forEach((r) => {
373
+ s = [...s, ...this.getPortCycleConnections(r)];
374
+ }), s;
401
375
  }
402
376
  }
403
377
  class v {
404
378
  static getPortCenter(t) {
405
- const { top: e, left: o, width: n, height: i } = t.element.getBoundingClientRect(), h = t.centerFn(n, i);
406
- 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]];
407
381
  }
408
- static rotate(t, e, o) {
382
+ static rotate(t, e, s) {
409
383
  return [
410
- e[0] * t[0] - e[1] * t[1] + ((1 - e[0]) * o[0] + e[1] * o[1]),
411
- 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])
412
386
  ];
413
387
  }
414
- static getDirectionVector(t, e, o) {
415
- 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)];
416
390
  }
417
- static getArrowPath(t, e, o, n, i) {
418
- const a = [
391
+ static getArrowPath(t, e, s, r, a) {
392
+ const h = [
419
393
  [0, 0],
420
- [n, i],
421
- [n, -i]
422
- ].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]}`;
423
- return `${c} ${l} ${g}`;
424
- }
425
- static getArrowOffsetPath(t, e, o, n, i) {
426
- const a = [
427
- [n, 0],
428
- [n + i, 0]
429
- ].map((c) => this.rotate(c, t, [0, 0])).map((c) => [c[0] + e, c[1] + o]);
430
- 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(" ");
431
408
  }
432
409
  }
433
- class G {
434
- constructor(t, e, o, n, i, h, a) {
435
- r(this, "svg");
436
- r(this, "group");
437
- r(this, "line");
438
- r(this, "sourceArrow", null);
439
- r(this, "targetArrow", null);
440
- this.color = t, this.width = e, this.curvature = o, this.arrowLength = n, 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(
441
418
  "http://www.w3.org/2000/svg",
442
419
  "path"
443
- ), 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(
444
421
  "http://www.w3.org/2000/svg",
445
422
  "path"
446
423
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
447
424
  }
448
- update(t, e, o, n, i, h) {
449
- this.svg.style.width = `${o}px`, this.svg.style.height = `${n}px`;
450
- const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
451
- this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
452
- const d = v.getDirectionVector(
453
- i.direction,
454
- l,
455
- g
456
- ), m = v.getDirectionVector(
457
- h.direction,
458
- l,
459
- g
460
- ), u = v.rotate(
461
- [this.arrowLength, 0],
462
- d,
463
- [0, 0]
464
- ), p = v.rotate(
465
- [o - this.arrowLength, n],
466
- m,
467
- [o, n]
468
- ), C = [
469
- u[0] + d[0] * this.curvature,
470
- u[1] + d[1] * this.curvature
471
- ], w = [
472
- p[0] - m[0] * this.curvature,
473
- p[1] - m[1] * this.curvature
474
- ], b = `M ${u[0]} ${u[1]}`, T = `C ${C[0]} ${C[1]}, ${w[0]} ${w[1]}, ${p[0]} ${p[1]}`, S = `M 0 0 L ${u[0]} ${u[1]} `, f = ` M ${p[0]} ${p[1]} L ${o} ${n}`, y = `${this.sourceArrow ? "" : S}${b} ${T}${this.targetArrow ? "" : f}`;
475
- if (this.line.setAttribute("d", y), this.sourceArrow) {
476
- const N = v.getArrowPath(
477
- 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,
478
442
  0,
479
443
  0,
480
444
  this.arrowLength,
481
445
  this.arrowWidth
482
446
  );
483
- this.sourceArrow.setAttribute("d", N);
447
+ this.sourceArrow.setAttribute("d", $);
484
448
  }
485
449
  if (this.targetArrow) {
486
- const N = v.getArrowPath(
487
- m,
488
- o,
489
- n,
450
+ const $ = v.getArrowPath(
451
+ u,
452
+ s,
453
+ r,
490
454
  -this.arrowLength,
491
455
  this.arrowWidth
492
456
  );
493
- this.targetArrow.setAttribute("d", N);
457
+ this.targetArrow.setAttribute("d", $);
494
458
  }
495
459
  }
496
460
  }
497
- const B = (s) => () => new G(
498
- s.color ?? "#5c5c5c",
499
- s.width ?? 1,
500
- s.curvature ?? 90,
501
- s.arrowLength ?? 15,
502
- s.arrowWidth ?? 4,
503
- s.hasSourceArrow ?? !1,
504
- s.hasTargetArrow ?? !1
505
- );
506
- class Y {
507
- constructor(t, e, o, n, i, h, a) {
508
- r(this, "svg");
509
- r(this, "group");
510
- r(this, "line");
511
- r(this, "sourceArrow", null);
512
- r(this, "targetArrow", null);
513
- this.color = t, this.width = e, this.arrowLength = o, this.arrowWidth = n, 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(
514
470
  "http://www.w3.org/2000/svg",
515
471
  "path"
516
- ), 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(
517
473
  "http://www.w3.org/2000/svg",
518
474
  "path"
519
475
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
520
476
  }
521
- update(t, e, o, n, i, h) {
522
- this.svg.style.width = `${o}px`, this.svg.style.height = `${n}px`;
523
- const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
524
- this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
525
- const d = v.getDirectionVector(
526
- i.direction,
527
- l,
528
- g
529
- ), m = v.getDirectionVector(
530
- 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(
531
494
  l,
532
- g
533
- ), u = v.rotate(
534
- [this.arrowLength + this.minPortOffset, 0],
535
- d,
536
- [0, 0]
537
- ), p = v.rotate(
538
- [o - this.arrowLength - this.minPortOffset, n],
539
- m,
540
- [o, n]
541
- ), [C, w] = [o / 2, n / 2], b = l * (p[0] - u[0]) > 0 ? `M ${u[0]} ${u[1]} L ${C} ${u[1]} L ${C} ${p[1]} L ${p[0]} ${p[1]}` : `M ${u[0]} ${u[1]} L ${u[0]} ${w} L ${p[0]} ${w} L ${p[0]} ${p[1]}`, T = `M 0 0 L ${u[0]} ${u[1]} `, S = ` M ${p[0]} ${p[1]} L ${o} ${n}`, f = v.getArrowOffsetPath(
542
- d,
543
495
  0,
544
496
  0,
545
497
  this.arrowLength,
546
498
  this.minPortOffset
547
- ), y = v.getArrowOffsetPath(
548
- m,
549
- o,
550
- n,
499
+ ), $ = v.getArrowOffsetPath(
500
+ u,
501
+ s,
502
+ r,
551
503
  -this.arrowLength,
552
504
  -this.minPortOffset
553
- ), N = `${this.sourceArrow ? f : T}${b}${this.targetArrow ? y : S}`;
554
- if (this.line.setAttribute("d", N), this.sourceArrow) {
555
- const E = v.getArrowPath(
556
- 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,
557
509
  0,
558
510
  0,
559
511
  this.arrowLength,
560
512
  this.arrowWidth
561
513
  );
562
- this.sourceArrow.setAttribute("d", E);
514
+ this.sourceArrow.setAttribute("d", x);
563
515
  }
564
516
  if (this.targetArrow) {
565
- const E = v.getArrowPath(
566
- m,
567
- o,
568
- n,
517
+ const x = v.getArrowPath(
518
+ u,
519
+ s,
520
+ r,
569
521
  -this.arrowLength,
570
522
  this.arrowWidth
571
523
  );
572
- 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);
573
560
  }
574
561
  }
575
562
  }
576
- const X = (s) => () => new Y(
577
- s.color,
578
- s.width,
579
- s.arrowLength,
580
- s.arrowWidth,
581
- s.minPortOffset,
582
- s.hasSourceArrow,
583
- s.hasTargetArrow
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);
617
+ }
618
+ }
619
+ }
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
584
655
  );
585
- var P = /* @__PURE__ */ ((s) => (s.Regular = "regular", s.Cycle = "cycle", s))(P || {});
586
- class A {
656
+ class S {
587
657
  constructor() {
588
- r(this, "counter", 0);
658
+ n(this, "counter", 0);
589
659
  }
590
660
  next() {
591
661
  const t = `${this.counter}`;
@@ -595,19 +665,19 @@ class A {
595
665
  this.counter = 0;
596
666
  }
597
667
  }
598
- class Z {
599
- constructor(t, e, o, n, i) {
600
- r(this, "nodeIdGenerator", new A());
601
- r(this, "portIdGenerator", new A());
602
- r(this, "connectionIdGenerator", new A());
603
- this.graphStore = t, this.htmlController = e, this.viewportTransformer = o, this.nodesCenterFn = n, 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;
604
674
  }
605
675
  moveNodeOnTop(t) {
606
676
  if (!this.graphStore.hasNode(t))
607
677
  throw new Error("failed to move on top nonexisting node");
608
678
  this.htmlController.moveNodeOnTop(t);
609
679
  }
610
- addNode(t, e, o, n, i, h) {
680
+ addNode(t, e, s, r, a, c) {
611
681
  if (t === void 0)
612
682
  do
613
683
  t = this.nodeIdGenerator.next();
@@ -617,34 +687,34 @@ class Z {
617
687
  this.graphStore.addNode(
618
688
  t,
619
689
  e,
620
- o,
621
- n,
622
- h ?? this.nodesCenterFn
623
- ), this.htmlController.attachNode(t), i !== void 0 && Object.entries(i).forEach(([a, c]) => {
624
- c instanceof HTMLElement ? this.markPort(a, c, t, this.portsCenterFn, null) : this.markPort(
625
- a,
626
- c.element,
690
+ s,
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,
627
697
  t,
628
- c.centerFn ?? this.portsCenterFn,
629
- c.direction ?? null
698
+ i.centerFn ?? this.portsCenterFn,
699
+ i.direction ?? null
630
700
  );
631
701
  });
632
702
  }
633
- markPort(t, e, o, n, i) {
703
+ markPort(t, e, s, r, a) {
634
704
  if (t === void 0)
635
705
  do
636
706
  t = this.portIdGenerator.next();
637
707
  while (this.graphStore.hasPort(t));
638
- if (!this.graphStore.hasNode(o))
708
+ if (!this.graphStore.hasNode(s))
639
709
  throw new Error("failed to set port on nonexisting node");
640
710
  if (this.graphStore.hasPort(t))
641
711
  throw new Error("failed to add port with existing id");
642
712
  this.graphStore.addPort(
643
713
  t,
644
714
  e,
645
- o,
646
- n ?? this.portsCenterFn,
647
- i ?? null
715
+ s,
716
+ r ?? this.portsCenterFn,
717
+ a ?? null
648
718
  );
649
719
  }
650
720
  updatePortConnections(t) {
@@ -659,20 +729,21 @@ class Z {
659
729
  this.removeConnection(e);
660
730
  }), this.graphStore.removePort(t);
661
731
  }
662
- addConnection(t, e, o, n) {
732
+ addConnection(t, e, s, r) {
663
733
  if (t === void 0)
664
734
  do
665
735
  t = this.connectionIdGenerator.next();
666
736
  while (this.graphStore.hasConnection(t));
667
737
  if (!this.graphStore.hasPort(e))
668
738
  throw new Error("failed to add connection from nonexisting port");
669
- if (!this.graphStore.hasPort(o))
739
+ if (!this.graphStore.hasPort(s))
670
740
  throw new Error("failed to add connection to nonexisting port");
671
- this.graphStore.addConnection(
741
+ let a = T.Regular;
742
+ e === s && (a = T.Cycle), this.graphStore.addConnection(
672
743
  t,
673
744
  e,
674
- o,
675
- n(P.Regular)
745
+ s,
746
+ r(a)
676
747
  ), this.htmlController.attachConnection(t);
677
748
  }
678
749
  removeConnection(t) {
@@ -685,25 +756,25 @@ class Z {
685
756
  throw new Error("failed to remove nonexisting node");
686
757
  this.htmlController.detachNode(t), this.graphStore.removeNode(t);
687
758
  }
688
- patchViewportState(t, e, o) {
689
- this.viewportTransformer.patchState(t, e, o), this.htmlController.applyTransform();
759
+ patchViewportState(t, e, s) {
760
+ this.viewportTransformer.patchState(t, e, s), this.htmlController.applyTransform();
690
761
  }
691
762
  moveToNodes(t) {
692
763
  if (t.length === 0)
693
764
  return;
694
- 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);
695
766
  if (e.length < t.length)
696
767
  throw new Error("failed to move to nonexisting node");
697
- const [o, n] = e.reduce(
698
- (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],
699
770
  [0, 0]
700
- ), i = o / e.length, h = n / e.length, [a, c] = this.htmlController.getViewportDimensions(), l = this.viewportTransformer.getAbsScale(), g = i - l * a / 2, d = h - l * c / 2;
701
- 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);
702
773
  }
703
- updateNodeCoordinates(t, e, o) {
774
+ updateNodeCoordinates(t, e, s) {
704
775
  if (!this.graphStore.hasNode(t))
705
776
  throw new Error("failed to update coordinates of nonexisting node");
706
- this.graphStore.updateNodeCoords(t, e, o), this.htmlController.updateNodeCoordinates(t);
777
+ this.graphStore.updateNodeCoords(t, e, s), this.htmlController.updateNodeCoordinates(t);
707
778
  }
708
779
  updateConnectionController(t, e) {
709
780
  if (!this.graphStore.hasConnection(t))
@@ -724,138 +795,138 @@ class Z {
724
795
  }
725
796
  }
726
797
  class H {
727
- constructor(t, e, o, n) {
728
- r(this, "publicViewportTransformer");
729
- r(this, "publicGraphStore");
730
- r(this, "canvasController");
731
- const i = new D(), h = new R();
732
- this.publicViewportTransformer = new W(
733
- i
734
- ), this.publicGraphStore = new z(h);
735
- const a = new j(
736
- h,
737
- i,
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,
738
808
  this.publicViewportTransformer,
739
809
  t,
740
810
  e
741
811
  );
742
- this.canvasController = new Z(
812
+ this.canvasController = new U(
813
+ c,
743
814
  h,
744
815
  a,
745
- i,
746
- o,
747
- n
816
+ s,
817
+ r
748
818
  );
749
819
  }
750
820
  }
751
- const $ = (s, t) => [
752
- s / 2,
821
+ const M = (o, t) => [
822
+ o / 2,
753
823
  t / 2
754
- ], U = () => () => {
755
- }, J = (s, t, e, o, n, i) => {
756
- s.clearRect(0, 0, s.canvas.width, s.canvas.height), s.fillStyle = i, s.fillRect(0, 0, s.canvas.width, s.canvas.height);
757
- const h = t.getViewCoords(0, 0), a = t.getViewScale(), c = o * a;
758
- 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;
759
829
  do
760
- d *= 2, l = s.canvas.width / d, g = s.canvas.height / d;
761
- while (l * g > 1e4);
762
- const m = h[0] - Math.floor(h[0] / d) * d, u = h[1] - Math.floor(h[1] / d) * d, p = n * a, C = 2 * Math.PI, w = m - d, b = u - d, T = s.canvas.width + m, S = s.canvas.height + u;
763
- s.fillStyle = e;
764
- for (let f = w; f <= T; f += d)
765
- for (let y = b; y <= S; y += d)
766
- s.beginPath(), s.arc(f, y, p, 0, C), s.closePath(), s.fill();
767
- }, K = (s, t, e, o) => (n, i) => {
768
- J(
769
- n,
770
- i,
771
- s,
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) => {
838
+ q(
839
+ r,
840
+ a,
841
+ o,
772
842
  t,
773
843
  e,
774
- o
844
+ s
775
845
  );
776
- }, Q = (s, t) => {
777
- s.fillStyle = t, s.fillRect(0, 0, s.canvas.width, s.canvas.height);
778
- }, _ = (s) => (t) => {
779
- Q(t, s);
780
- }, q = (s) => {
781
- switch (s == null ? void 0 : s.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) {
782
852
  case "custom":
783
- return s.drawingFn;
853
+ return o.drawingFn;
784
854
  case "dots":
785
- return K(
786
- s.dotColor ?? "#d8d8d8",
787
- s.dotGap ?? 25,
788
- s.dotRadius ?? 1.5,
789
- s.color ?? "#ffffff"
855
+ return J(
856
+ o.dotColor ?? "#d8d8d8",
857
+ o.dotGap ?? 25,
858
+ o.dotRadius ?? 1.5,
859
+ o.color ?? "#ffffff"
790
860
  );
791
861
  case "color":
792
- return _(s.color ?? "#ffffff");
862
+ return Q(o.color ?? "#ffffff");
793
863
  default:
794
- return U();
864
+ return _();
795
865
  }
796
- }, M = (s) => {
797
- switch (s == null ? void 0 : s.type) {
866
+ }, O = (o) => {
867
+ switch (o == null ? void 0 : o.type) {
798
868
  case "custom":
799
- return s.controllerFactory;
869
+ return o.controllerFactory;
800
870
  case "straight":
801
- return X({
802
- color: s.color ?? "#5c5c5c",
803
- width: s.width ?? 1,
804
- arrowLength: s.arrowLength ?? 15,
805
- arrowWidth: s.arrowWidth ?? 4,
806
- minPortOffset: s.minPortOffset ?? 15,
807
- hasSourceArrow: s.hasSourceArrow ?? !1,
808
- hasTargetArrow: s.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
809
881
  });
810
882
  default:
811
- return B({
812
- color: s.color ?? "#5c5c5c",
813
- width: s.width ?? 1,
814
- curvature: s.curvature ?? 90,
815
- arrowLength: s.arrowLength ?? 15,
816
- arrowWidth: s.arrowWidth ?? 4,
817
- hasSourceArrow: s.hasSourceArrow ?? !1,
818
- hasTargetArrow: s.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
819
893
  });
820
894
  }
821
- }, I = (s) => {
822
- var t, e, o;
895
+ }, tt = (o) => {
896
+ var t, e, s;
823
897
  return {
824
898
  background: {
825
- drawingFn: q(
826
- s.background ?? { type: "none" }
899
+ drawingFn: I(
900
+ o.background ?? { type: "none" }
827
901
  )
828
902
  },
829
903
  nodes: {
830
- centerFn: ((t = s.nodes) == null ? void 0 : t.centerFn) ?? $
904
+ centerFn: ((t = o.nodes) == null ? void 0 : t.centerFn) ?? M
831
905
  },
832
906
  ports: {
833
- centerFn: ((e = s.ports) == null ? void 0 : e.centerFn) ?? $
907
+ centerFn: ((e = o.ports) == null ? void 0 : e.centerFn) ?? M
834
908
  },
835
- connections: {
836
- controllerFactory: M(
837
- s.connections ?? {}
838
- )
909
+ edges: {
910
+ controllerFactory: O(o.edges ?? {})
839
911
  },
840
912
  layers: {
841
- mode: ((o = s.layers) == null ? void 0 : o.mode) ?? "connections-follow-node"
913
+ mode: ((s = o.layers) == null ? void 0 : s.mode) ?? "edges-follow-node"
842
914
  }
843
915
  };
844
916
  };
845
- class tt {
917
+ class et {
846
918
  constructor(t) {
847
- r(this, "transformation");
848
- r(this, "model");
849
- r(this, "di");
850
- r(this, "connectionControllerFactory");
919
+ n(this, "transformation");
920
+ n(this, "di");
921
+ n(this, "connectionControllerFactory");
851
922
  this.apiOptions = t;
852
- const e = I(this.apiOptions ?? {});
923
+ const e = tt(this.apiOptions ?? {});
853
924
  this.di = new H(
854
925
  e.layers.mode,
855
926
  e.background.drawingFn,
856
927
  e.nodes.centerFn,
857
928
  e.ports.centerFn
858
- ), 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;
859
930
  }
860
931
  addNode(t) {
861
932
  return this.di.canvasController.addNode(
@@ -882,14 +953,14 @@ class tt {
882
953
  t.direction
883
954
  ), this;
884
955
  }
885
- updatePortConnections(t) {
956
+ updatePortEdges(t) {
886
957
  return this.di.canvasController.updatePortConnections(t), this;
887
958
  }
888
959
  unmarkPort(t) {
889
960
  return this.di.canvasController.unmarkPort(t), this;
890
961
  }
891
- addConnection(t) {
892
- const e = t.options !== void 0 ? M(t.options) : this.connectionControllerFactory;
962
+ addEdge(t) {
963
+ const e = t.options !== void 0 ? O(t.options) : this.connectionControllerFactory;
893
964
  return this.di.canvasController.addConnection(
894
965
  t.id,
895
966
  t.from,
@@ -897,7 +968,7 @@ class tt {
897
968
  e
898
969
  ), this;
899
970
  }
900
- removeConnection(t) {
971
+ removeEdge(t) {
901
972
  return this.di.canvasController.removeConnection(t), this;
902
973
  }
903
974
  patchViewportState(t) {
@@ -910,8 +981,8 @@ class tt {
910
981
  moveToNodes(t) {
911
982
  return this.di.canvasController.moveToNodes(t), this;
912
983
  }
913
- updateNodeCoordinates(t, e, o) {
914
- return this.di.canvasController.updateNodeCoordinates(t, e, o), this;
984
+ updateNodeCoordinates(t, e, s) {
985
+ return this.di.canvasController.updateNodeCoordinates(t, e, s), this;
915
986
  }
916
987
  updateConnection(t, e) {
917
988
  return e.controller !== void 0 && this.di.canvasController.updateConnectionController(
@@ -932,50 +1003,54 @@ class tt {
932
1003
  this.di.canvasController.destroy();
933
1004
  }
934
1005
  }
935
- class et {
1006
+ class st {
936
1007
  constructor(t, e) {
937
- r(this, "transformation");
938
- r(this, "model");
939
- r(this, "nodes", /* @__PURE__ */ new Map());
940
- r(this, "grabbedNodeId", null);
941
- r(this, "onNodeDrag");
942
- r(this, "nodeIdGenerator", new A());
943
- r(this, "element", null);
944
- r(this, "onCanvasMouseUp", () => {
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", () => {
945
1016
  this.setCursor(null), this.grabbedNodeId = null;
946
1017
  });
947
- r(this, "onCanvasMouseMove", (t) => {
1018
+ n(this, "onCanvasMouseMove", (t) => {
948
1019
  this.grabbedNodeId !== null && (t.stopPropagation(), this.dragNode(this.grabbedNodeId, t.movementX, t.movementY));
949
1020
  });
950
- r(this, "onCanvasTouchStart", (t) => {
1021
+ n(this, "onCanvasTouchStart", (t) => {
951
1022
  this.previousTouchCoords = [
952
1023
  t.touches[0].clientX,
953
1024
  t.touches[0].clientY
954
1025
  ];
955
1026
  });
956
- r(this, "onCanvasTouchMove", (t) => {
1027
+ n(this, "onCanvasTouchMove", (t) => {
957
1028
  if (this.grabbedNodeId === null || t.touches.length !== 1 || this.previousTouchCoords === null)
958
1029
  return;
959
1030
  t.stopImmediatePropagation();
960
- const [e, o] = [
1031
+ const [e, s] = [
961
1032
  t.touches[0].clientX - this.previousTouchCoords[0],
962
1033
  t.touches[0].clientY - this.previousTouchCoords[1]
963
1034
  ];
964
- this.dragNode(this.grabbedNodeId, e, o), this.previousTouchCoords = [
1035
+ this.dragNode(this.grabbedNodeId, e, s), this.previousTouchCoords = [
965
1036
  t.touches[0].clientX,
966
1037
  t.touches[0].clientY
967
1038
  ];
968
1039
  });
969
- r(this, "onCanvasTouchEnd", (t) => {
1040
+ n(this, "onCanvasTouchEnd", (t) => {
970
1041
  t.touches.length > 0 ? this.previousTouchCoords = [
971
1042
  t.touches[0].clientX,
972
1043
  t.touches[0].clientY
973
1044
  ] : (this.previousTouchCoords = null, this.grabbedNodeId = null);
974
1045
  });
975
- r(this, "previousTouchCoords", null);
976
- var o;
977
- this.canvas = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.onNodeDrag = ((o = e == null ? void 0 : e.events) == null ? void 0 : o.onNodeDrag) ?? (() => {
978
- });
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;
979
1054
  }
980
1055
  addNode(t) {
981
1056
  let e = t.id;
@@ -984,35 +1059,47 @@ class et {
984
1059
  e = this.nodeIdGenerator.next();
985
1060
  while (this.nodes.has(e));
986
1061
  this.canvas.addNode(t);
987
- const o = (i) => {
988
- i.stopImmediatePropagation(), this.grabbedNodeId = e, this.setCursor("grab"), this.canvas.moveNodeOnTop(e);
989
- }, n = (i) => {
990
- 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));
991
1076
  };
992
1077
  return this.nodes.set(e, {
993
- el: t.element,
994
- onMouseDown: o,
995
- onTouchStart: n
996
- }), t.element.addEventListener("mousedown", o), t.element.addEventListener("touchstart", n), 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;
997
1084
  }
998
1085
  removeNode(t) {
999
1086
  const e = this.nodes.get(t);
1000
- 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;
1001
1088
  }
1002
1089
  markPort(t) {
1003
1090
  return this.canvas.markPort(t), this;
1004
1091
  }
1005
- updatePortConnections(t) {
1006
- return this.canvas.updatePortConnections(t), this;
1092
+ updatePortEdges(t) {
1093
+ return this.canvas.updatePortEdges(t), this;
1007
1094
  }
1008
1095
  unmarkPort(t) {
1009
1096
  return this.canvas.unmarkPort(t), this;
1010
1097
  }
1011
- addConnection(t) {
1012
- return this.canvas.addConnection(t), this;
1098
+ addEdge(t) {
1099
+ return this.canvas.addEdge(t), this;
1013
1100
  }
1014
- removeConnection(t) {
1015
- return this.canvas.removeConnection(t), this;
1101
+ removeEdge(t) {
1102
+ return this.canvas.removeEdge(t), this;
1016
1103
  }
1017
1104
  patchViewportState(t) {
1018
1105
  return this.canvas.patchViewportState(t), this;
@@ -1020,8 +1107,8 @@ class et {
1020
1107
  moveToNodes(t) {
1021
1108
  return this.canvas.moveToNodes(t), this;
1022
1109
  }
1023
- updateNodeCoordinates(t, e, o) {
1024
- return this.canvas.updateNodeCoordinates(t, e, o), this;
1110
+ updateNodeCoordinates(t, e, s) {
1111
+ return this.canvas.updateNodeCoordinates(t, e, s), this;
1025
1112
  }
1026
1113
  updateConnection(t, e) {
1027
1114
  return this.canvas.updateConnection(t, e), this;
@@ -1031,67 +1118,72 @@ class et {
1031
1118
  }
1032
1119
  clear() {
1033
1120
  return this.canvas.clear(), this.nodes.forEach((t) => {
1034
- 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);
1035
1122
  }), this.nodes.clear(), this;
1036
1123
  }
1037
1124
  attach(t) {
1038
- 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;
1039
1126
  }
1040
1127
  detach() {
1041
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;
1042
1129
  }
1043
1130
  destroy() {
1044
1131
  this.detach(), this.nodes.forEach((t) => {
1045
- t.el.removeEventListener("mousedown", t.onMouseDown), t.el.removeEventListener("touchstart", t.onTouchStart);
1132
+ t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart);
1046
1133
  }), this.nodes.clear(), this.canvas.destroy();
1047
1134
  }
1048
1135
  setCursor(t) {
1049
1136
  this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1050
1137
  }
1051
- dragNode(t, e, o) {
1052
- const n = this.model.getNode(t);
1053
- if (n === null)
1138
+ dragNode(t, e, s) {
1139
+ const r = this.nodes.get(t);
1140
+ if (r === void 0)
1054
1141
  throw new Error("failed to drag nonexisting node");
1055
- const [i, h] = this.transformation.getViewCoords(n.x, n.y), a = i + e, c = h + o, [l, g] = this.transformation.getAbsCoords(a, c);
1056
- this.canvas.updateNodeCoordinates(t, l, g), this.onNodeDrag(t);
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
+ });
1057
1149
  }
1058
1150
  }
1059
1151
  class ot {
1060
1152
  constructor(t, e) {
1061
- r(this, "transformation");
1062
- r(this, "model");
1063
- r(this, "element", null);
1064
- r(this, "isMoving", !1);
1065
- r(this, "prevTouches", null);
1066
- r(this, "onTransform");
1067
- r(this, "isScalable");
1068
- r(this, "isShiftable");
1069
- r(this, "minViewScale");
1070
- r(this, "maxViewScale");
1071
- r(this, "wheelSensitivity");
1072
- 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", () => {
1073
1165
  this.setCursor("grab"), this.isMoving = !0;
1074
1166
  });
1075
- r(this, "onMouseMove", (t) => {
1167
+ n(this, "onMouseMove", (t) => {
1076
1168
  if (!this.isMoving || !this.isShiftable)
1077
1169
  return;
1078
- const e = -t.movementX, o = -t.movementY;
1079
- this.moveViewport(e, o);
1170
+ const e = -t.movementX, s = -t.movementY;
1171
+ this.moveViewport(e, s);
1080
1172
  });
1081
- r(this, "onMouseUp", () => {
1173
+ n(this, "onMouseUp", () => {
1082
1174
  this.setCursor(null), this.isMoving = !1;
1083
1175
  });
1084
- r(this, "onWheelScroll", (t) => {
1176
+ n(this, "onWheelScroll", (t) => {
1085
1177
  if (this.element === null || this.isScalable === !1)
1086
1178
  return;
1087
1179
  t.preventDefault();
1088
- const { left: e, top: o } = this.element.getBoundingClientRect(), n = t.clientX - e, i = t.clientY - o, a = 1 / (t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
1089
- this.scaleViewport(a, n, 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);
1090
1182
  });
1091
- r(this, "onTouchStart", (t) => {
1183
+ n(this, "onTouchStart", (t) => {
1092
1184
  this.prevTouches = this.getAverageTouch(t);
1093
1185
  });
1094
- r(this, "onTouchMove", (t) => {
1186
+ n(this, "onTouchMove", (t) => {
1095
1187
  if (this.prevTouches === null || this.element === null || !this.isShiftable)
1096
1188
  return;
1097
1189
  const e = this.getAverageTouch(t);
@@ -1099,21 +1191,25 @@ class ot {
1099
1191
  -(e.x - this.prevTouches.x),
1100
1192
  -(e.y - this.prevTouches.y)
1101
1193
  ), e.touchesCnt === 2 && this.isScalable) {
1102
- const { left: o, top: n } = this.element.getBoundingClientRect(), i = this.prevTouches.x - o, h = this.prevTouches.y - n, c = 1 / (e.scale / this.prevTouches.scale);
1103
- this.scaleViewport(c, i, h);
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);
1104
1196
  }
1105
1197
  this.prevTouches = e, t.preventDefault();
1106
1198
  });
1107
- r(this, "onTouchEnd", (t) => {
1199
+ n(this, "onTouchEnd", (t) => {
1108
1200
  t.touches.length > 0 ? this.prevTouches = this.getAverageTouch(t) : this.prevTouches = null;
1109
1201
  });
1110
- var h, a, c, l, g, d, m, u, p, C, w;
1111
- this.canvas = t, this.options = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1112
- const o = ((a = (h = this.options) == null ? void 0 : h.scale) == null ? void 0 : a.minContent) ?? null, n = ((l = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : l.maxContent) ?? null;
1113
- this.isScalable = ((d = (g = this.options) == null ? void 0 : g.scale) == null ? void 0 : d.enabled) !== !1, this.minViewScale = n !== null ? 1 / n : null, this.maxViewScale = o !== null ? 1 / o : null, this.isShiftable = ((u = (m = this.options) == null ? void 0 : m.shift) == null ? void 0 : u.enabled) !== !1;
1114
- const i = (C = (p = this.options) == null ? void 0 : p.scale) == null ? void 0 : C.wheelSensitivity;
1115
- this.wheelSensitivity = i !== void 0 ? i : 1.2, this.onTransform = ((w = e == null ? void 0 : e.events) == null ? void 0 : w.onTransform) ?? (() => {
1116
- });
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;
1117
1213
  }
1118
1214
  addNode(t) {
1119
1215
  return this.canvas.addNode(t), this;
@@ -1124,17 +1220,17 @@ class ot {
1124
1220
  markPort(t) {
1125
1221
  return this.canvas.markPort(t), this;
1126
1222
  }
1127
- updatePortConnections(t) {
1128
- return this.canvas.updatePortConnections(t), this;
1223
+ updatePortEdges(t) {
1224
+ return this.canvas.updatePortEdges(t), this;
1129
1225
  }
1130
1226
  unmarkPort(t) {
1131
1227
  return this.canvas.unmarkPort(t), this;
1132
1228
  }
1133
- addConnection(t) {
1134
- return this.canvas.addConnection(t), this;
1229
+ addEdge(t) {
1230
+ return this.canvas.addEdge(t), this;
1135
1231
  }
1136
- removeConnection(t) {
1137
- return this.canvas.removeConnection(t), this;
1232
+ removeEdge(t) {
1233
+ return this.canvas.removeEdge(t), this;
1138
1234
  }
1139
1235
  patchViewportState(t) {
1140
1236
  return this.canvas.patchViewportState(t), this;
@@ -1142,8 +1238,8 @@ class ot {
1142
1238
  moveToNodes(t) {
1143
1239
  return this.canvas.moveToNodes(t), this;
1144
1240
  }
1145
- updateNodeCoordinates(t, e, o) {
1146
- return this.canvas.updateNodeCoordinates(t, e, o), this;
1241
+ updateNodeCoordinates(t, e, s) {
1242
+ return this.canvas.updateNodeCoordinates(t, e, s), this;
1147
1243
  }
1148
1244
  updateConnection(t, e) {
1149
1245
  return this.canvas.updateConnection(t, e), this;
@@ -1155,74 +1251,79 @@ class ot {
1155
1251
  return this.canvas.clear(), this;
1156
1252
  }
1157
1253
  attach(t) {
1158
- 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;
1159
1255
  }
1160
1256
  detach() {
1161
- 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;
1162
1258
  }
1163
1259
  destroy() {
1164
1260
  this.detach(), this.canvas.destroy();
1165
1261
  }
1166
1262
  getAverageTouch(t) {
1167
- const e = [], o = t.touches.length;
1168
- for (let c = 0; c < o; c++)
1169
- e.push([t.touches[c].clientX, t.touches[c].clientY]);
1170
- const n = e.reduce(
1171
- (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]],
1172
1268
  [0, 0]
1173
- ), i = [n[0] / o, n[1] / o], a = e.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1174
- (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]),
1175
1271
  0
1176
1272
  );
1177
- return { x: i[0], y: i[1], scale: a / o, touchesCnt: o };
1273
+ return { x: a[0], y: a[1], scale: h / s, touchesCnt: s };
1178
1274
  }
1179
1275
  setCursor(t) {
1180
1276
  this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
1181
1277
  }
1182
1278
  moveViewport(t, e) {
1183
- const [o, n] = this.transformation.getAbsCoords(0, 0), i = this.canvas.transformation.getAbsScale();
1184
- this.canvas.patchViewportState({
1185
- scale: i,
1186
- x: o + i * t,
1187
- y: n + i * e
1188
- }), this.onTransform();
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));
1189
1285
  }
1190
- scaleViewport(t, e, o) {
1191
- const [n, i] = this.canvas.transformation.getAbsCoords(0, 0), h = this.canvas.transformation.getAbsScale(), a = h * t, c = h * (1 - t) * e + n, l = h * (1 - t) * o + i;
1192
- this.maxViewScale !== null && a > this.maxViewScale && a > h || this.minViewScale !== null && a < this.minViewScale && a < h || (this.canvas.patchViewportState({ scale: a, x: c, y: l }), this.onTransform());
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));
1193
1292
  }
1194
1293
  }
1195
- class st {
1294
+ class nt {
1196
1295
  constructor() {
1197
- r(this, "coreOptions");
1198
- r(this, "dragOptions");
1199
- r(this, "transformOptions");
1200
- r(this, "isDraggable", !1);
1201
- 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);
1202
1301
  }
1203
1302
  setOptions(t) {
1204
1303
  return this.coreOptions = t, this;
1205
1304
  }
1206
- setDraggableNodes(t) {
1305
+ setUserDraggableNodes(t) {
1207
1306
  return this.isDraggable = !0, this.dragOptions = t, this;
1208
1307
  }
1209
- setTransformableCanvas(t) {
1308
+ setUserTransformableCanvas(t) {
1210
1309
  return this.isTransformable = !0, this.transformOptions = t, this;
1211
1310
  }
1212
1311
  build() {
1213
- let t = new tt(this.coreOptions);
1214
- return this.isDraggable && (t = new et(t, this.dragOptions)), 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;
1215
1314
  }
1216
1315
  }
1217
1316
  export {
1218
- G as BezierConnectionController,
1219
- tt as CanvasCore,
1220
- P as ConnectionType,
1221
- v as ConnectionUtils,
1222
- et as DraggableNodesCanvas,
1223
- st as HtmlGraphBuilder,
1224
- Y as StraightConnectionController,
1225
- ot as TransformableCanvas,
1226
- B as createBezierConnectionControllerFactory,
1227
- 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
1228
1329
  };