@html-graph/html-graph 0.0.48 → 0.0.50

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