@html-graph/html-graph 0.0.46 → 0.0.48

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