@html-graph/html-graph 0.0.45 → 0.0.47

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 = (n, t, e) => t in n ? F(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
+ var r = (n, t, e) => k(n, typeof t != "symbol" ? t + "" : t, e);
4
+ class j {
5
+ constructor(t, e, o, s, i) {
6
6
  r(this, "canvasWrapper", null);
7
7
  r(this, "host");
8
8
  r(this, "nodesContainer");
@@ -39,7 +39,7 @@ 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) => {
42
+ this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.graphStore.getNodeAdjacentConnections(t).forEach((s) => {
43
43
  this.connectionIdToElementMap.get(s).style.zIndex = `${this.currentZIndex - 1}`;
44
44
  });
45
45
  }
@@ -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 = s, this.backgroundDrawingFn = i, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.connectionsContainer = this.createConnectionsContainer();
62
+ const h = this.canvas.getContext("2d");
63
+ if (h === null)
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) => {
@@ -83,30 +81,22 @@ class F {
83
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);
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
109
  updateNodePosition(t) {
120
- const e = this.di.graphStore.getNode(t), o = this.di.graphStore.getNodeAdjacentConnections(t);
110
+ const e = this.graphStore.getNode(t), o = this.graphStore.getNodeAdjacentConnections(t);
121
111
  this.updateNodeCoords(t, e.x, e.y), o.forEach((s) => {
122
112
  this.updateConnectionCoords(s);
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, s = this.nodeWrapperElementToIdMap.get(o), i = this.graphStore.getNode(s);
149
+ this.updateNodeCoords(s, i.x, i.y), this.graphStore.getNodeAdjacentConnections(s).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 s = this.nodeIdToWrapperElementMap.get(t), { width: i, height: h } = s.getBoundingClientRect(), a = this.viewportTransformer.getAbsScale(), c = this.graphStore.getNode(t), [l, g] = c.centerFn(i, h);
161
+ s.style.transform = `matrix(1, 0, 0, 1, ${e - a * l}, ${o - a * g})`;
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), s = this.graphStore.getPort(e.to), i = o.element.getBoundingClientRect(), h = s.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
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
183
173
  ), [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);
174
+ h.width * m,
175
+ h.height * m
176
+ ), S = u + c, b = p + l, N = f + g, C = y + d, w = Math.min(S, N), T = Math.min(b, C), E = Math.abs(N - S), x = Math.abs(C - b), M = this.connectionIdToElementMap.get(t), L = S <= N, V = b <= C;
177
+ M.style.transform = `matrix(${L ? 1 : -1}, 0, 0, ${V ? 1 : -1}, ${w}, ${T})`, e.controller.update(w, T, E, x, o, s);
188
178
  }
189
179
  }
190
- class W {
180
+ class D {
191
181
  constructor() {
192
182
  r(this, "state", {
193
183
  scale: 1,
@@ -257,7 +247,7 @@ class W {
257
247
  };
258
248
  }
259
249
  }
260
- class D {
250
+ class W {
261
251
  constructor(t) {
262
252
  this.transformer = t;
263
253
  }
@@ -290,10 +280,205 @@ class D {
290
280
  return this.transformer.getAbsScale();
291
281
  }
292
282
  }
293
- class C {
283
+ class R {
284
+ constructor() {
285
+ r(this, "nodes", /* @__PURE__ */ Object.create(null));
286
+ r(this, "ports", /* @__PURE__ */ Object.create(null));
287
+ r(this, "nodePorts", /* @__PURE__ */ Object.create(null));
288
+ r(this, "portNodeId", /* @__PURE__ */ Object.create(null));
289
+ r(this, "connections", /* @__PURE__ */ Object.create(null));
290
+ r(this, "incommingConnections", /* @__PURE__ */ Object.create(null));
291
+ r(this, "outcommingConnections", /* @__PURE__ */ Object.create(null));
292
+ r(this, "cycleConnections", /* @__PURE__ */ Object.create(null));
293
+ }
294
+ getAllNodes() {
295
+ return Object.keys(this.nodes);
296
+ }
297
+ getAllPorts() {
298
+ return Object.keys(this.ports);
299
+ }
300
+ getAllConnections() {
301
+ return Object.keys(this.connections);
302
+ }
303
+ addNode(t, e, o, s, i) {
304
+ this.nodes[t] = { element: e, x: o, y: s, centerFn: i }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
305
+ }
306
+ hasNode(t) {
307
+ return this.nodes[t] !== void 0;
308
+ }
309
+ getNode(t) {
310
+ return this.nodes[t];
311
+ }
312
+ updateNodeCoords(t, e, o) {
313
+ this.nodes[t].x = e, this.nodes[t].y = o;
314
+ }
315
+ updateConnectionController(t, e) {
316
+ this.connections[t].controller = e;
317
+ }
318
+ removeNode(t) {
319
+ this.getNodeAdjacentConnections(t).forEach((s) => {
320
+ this.removeConnection(s);
321
+ }), delete this.nodes[t];
322
+ const o = this.nodePorts[t];
323
+ Object.keys(o).forEach((s) => {
324
+ delete this.portNodeId[s];
325
+ }), delete this.nodePorts[t];
326
+ }
327
+ addPort(t, e, o, s, i) {
328
+ this.ports[t] = { element: e, centerFn: s, direction: i }, this.cycleConnections[t] = {}, this.incommingConnections[t] = {}, this.outcommingConnections[t] = {}, this.portNodeId[t] = o;
329
+ const h = this.nodePorts[o];
330
+ h !== void 0 && (h[t] = e);
331
+ }
332
+ getPort(t) {
333
+ return this.ports[t];
334
+ }
335
+ getPortNode(t) {
336
+ return this.portNodeId[t];
337
+ }
338
+ hasPort(t) {
339
+ return this.portNodeId[t] !== void 0;
340
+ }
341
+ removePort(t) {
342
+ Object.keys(this.cycleConnections[t]).forEach((s) => {
343
+ this.removeConnection(s);
344
+ }), delete this.cycleConnections[t], Object.keys(this.incommingConnections[t]).forEach((s) => {
345
+ this.removeConnection(s);
346
+ }), delete this.incommingConnections[t], Object.keys(this.outcommingConnections[t]).forEach((s) => {
347
+ this.removeConnection(s);
348
+ }), delete this.outcommingConnections[t];
349
+ const e = this.portNodeId[t];
350
+ delete this.portNodeId[t];
351
+ const o = this.nodePorts[e];
352
+ delete o[t], delete this.ports[t];
353
+ }
354
+ addConnection(t, e, o, s) {
355
+ this.connections[t] = {
356
+ from: e,
357
+ to: o,
358
+ controller: s
359
+ }, e !== o ? (this.outcommingConnections[e][t] = !0, this.incommingConnections[o][t] = !0) : this.cycleConnections[e][t] = !0;
360
+ }
361
+ getConnection(t) {
362
+ return this.connections[t];
363
+ }
364
+ hasConnection(t) {
365
+ return this.connections[t] !== void 0;
366
+ }
367
+ removeConnection(t) {
368
+ const e = this.connections[t], o = e.from, s = e.to;
369
+ delete this.cycleConnections[o][t], delete this.cycleConnections[s][t], delete this.incommingConnections[o][t], delete this.incommingConnections[s][t], delete this.outcommingConnections[o][t], delete this.outcommingConnections[s][t], delete this.connections[t];
370
+ }
371
+ getPortIncomingConnections(t) {
372
+ return Object.keys(this.incommingConnections[t] ?? {});
373
+ }
374
+ getPortOutcomingConnections(t) {
375
+ return Object.keys(this.outcommingConnections[t] ?? {});
376
+ }
377
+ getPortCycleConnections(t) {
378
+ return Object.keys(this.cycleConnections[t] ?? {});
379
+ }
380
+ getPortAdjacentConnections(t) {
381
+ return [
382
+ ...this.getPortIncomingConnections(t),
383
+ ...this.getPortOutcomingConnections(t),
384
+ ...this.getPortCycleConnections(t)
385
+ ];
386
+ }
387
+ getNodeIncomingConnections(t) {
388
+ const e = Object.keys(this.nodePorts[t]);
389
+ let o = [];
390
+ return e.forEach((s) => {
391
+ o = [...o, ...this.getPortIncomingConnections(s)];
392
+ }), o;
393
+ }
394
+ getNodeOutcomingConnections(t) {
395
+ const e = Object.keys(this.nodePorts[t]);
396
+ let o = [];
397
+ return e.forEach((s) => {
398
+ o = [...o, ...this.getPortOutcomingConnections(s)];
399
+ }), o;
400
+ }
401
+ getNodeCycleConnections(t) {
402
+ const e = Object.keys(this.nodePorts[t]);
403
+ let o = [];
404
+ return e.forEach((s) => {
405
+ o = [...o, ...this.getPortCycleConnections(s)];
406
+ }), o;
407
+ }
408
+ getNodeAdjacentConnections(t) {
409
+ return [
410
+ ...this.getNodeIncomingConnections(t),
411
+ ...this.getNodeOutcomingConnections(t),
412
+ ...this.getNodeCycleConnections(t)
413
+ ];
414
+ }
415
+ clear() {
416
+ this.nodes = /* @__PURE__ */ Object.create(null), this.ports = /* @__PURE__ */ Object.create(null), this.nodePorts = /* @__PURE__ */ Object.create(null), this.portNodeId = /* @__PURE__ */ Object.create(null), this.connections = /* @__PURE__ */ Object.create(null), this.incommingConnections = /* @__PURE__ */ Object.create(null), this.outcommingConnections = /* @__PURE__ */ Object.create(null), this.cycleConnections = /* @__PURE__ */ Object.create(null);
417
+ }
418
+ }
419
+ class z {
420
+ constructor(t) {
421
+ this.graphStore = t;
422
+ }
423
+ getNode(t) {
424
+ const e = this.graphStore.getNode(t);
425
+ return e === void 0 ? null : { x: e.x, y: e.y };
426
+ }
427
+ getPort(t) {
428
+ const e = this.graphStore.getPortNode(t);
429
+ return e === void 0 ? null : { nodeId: e };
430
+ }
431
+ getConnection(t) {
432
+ const e = this.graphStore.getConnection(t);
433
+ return e === void 0 ? null : { from: e.from, to: e.to };
434
+ }
435
+ getAllNodes() {
436
+ return this.graphStore.getAllNodes();
437
+ }
438
+ getAllPorts() {
439
+ return this.graphStore.getAllPorts();
440
+ }
441
+ getAllConnections() {
442
+ return this.graphStore.getAllConnections();
443
+ }
444
+ hasNode(t) {
445
+ return this.graphStore.hasNode(t);
446
+ }
447
+ hasPort(t) {
448
+ return this.graphStore.hasPort(t);
449
+ }
450
+ hasConnection(t) {
451
+ return this.graphStore.hasConnection(t);
452
+ }
453
+ getPortIncomingConnections(t) {
454
+ return this.graphStore.getPortIncomingConnections(t);
455
+ }
456
+ getPortOutcomingConnections(t) {
457
+ return this.graphStore.getPortOutcomingConnections(t);
458
+ }
459
+ getPortCycleConnections(t) {
460
+ return this.graphStore.getPortCycleConnections(t);
461
+ }
462
+ getPortAdjacentConnections(t) {
463
+ return this.graphStore.getPortAdjacentConnections(t);
464
+ }
465
+ getNodeIncomingConnections(t) {
466
+ return this.graphStore.getNodeIncomingConnections(t);
467
+ }
468
+ getNodeOutcomingConnections(t) {
469
+ return this.graphStore.getNodeOutcomingConnections(t);
470
+ }
471
+ getNodeCycleConnections(t) {
472
+ return this.graphStore.getNodeCycleConnections(t);
473
+ }
474
+ getNodeAdjacentConnections(t) {
475
+ return this.graphStore.getNodeAdjacentConnections(t);
476
+ }
477
+ }
478
+ class v {
294
479
  static getPortCenter(t) {
295
- const { top: e, left: o, width: s, height: i } = t.element.getBoundingClientRect(), c = t.centerFn(s, i);
296
- return [o + c[0], e + c[1]];
480
+ const { top: e, left: o, width: s, height: i } = t.element.getBoundingClientRect(), h = t.centerFn(s, i);
481
+ return [o + h[0], e + h[1]];
297
482
  }
298
483
  static rotate(t, e, o) {
299
484
  return [
@@ -309,25 +494,25 @@ class C {
309
494
  [0, 0],
310
495
  [s, i],
311
496
  [s, -i]
312
- ].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]}`;
313
- return `${h} ${l} ${m}`;
497
+ ].map((d) => this.rotate(d, t, [0, 0])).map((d) => [d[0] + e, d[1] + o]), c = `M ${a[0][0]} ${a[0][1]}`, l = `L ${a[1][0]} ${a[1][1]}`, g = `L ${a[2][0]} ${a[2][1]}`;
498
+ return `${c} ${l} ${g}`;
314
499
  }
315
500
  static getArrowOffsetPath(t, e, o, s, i) {
316
501
  const a = [
317
502
  [s, 0],
318
503
  [s + i, 0]
319
- ].map((h) => this.rotate(h, t, [0, 0])).map((h) => [h[0] + e, h[1] + o]);
504
+ ].map((c) => this.rotate(c, t, [0, 0])).map((c) => [c[0] + e, c[1] + o]);
320
505
  return `M ${a[0][0]} ${a[0][1]} L ${a[1][0]} ${a[1][1]}`;
321
506
  }
322
507
  }
323
- class R {
324
- constructor(t, e, o, s, i, c, a) {
508
+ class G {
509
+ constructor(t, e, o, s, i, h, a) {
325
510
  r(this, "svg");
326
511
  r(this, "group");
327
512
  r(this, "line");
328
513
  r(this, "sourceArrow", null);
329
514
  r(this, "targetArrow", null);
330
- 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(
515
+ this.color = t, this.width = e, this.curvature = o, this.arrowLength = s, this.arrowWidth = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
331
516
  "http://www.w3.org/2000/svg",
332
517
  "path"
333
518
  ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = document.createElementNS(
@@ -335,35 +520,35 @@ class R {
335
520
  "path"
336
521
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
337
522
  }
338
- update(t, e, o, s, i, c) {
523
+ update(t, e, o, s, i, h) {
339
524
  this.svg.style.width = `${o}px`, this.svg.style.height = `${s}px`;
340
- const a = C.getPortCenter(i), h = C.getPortCenter(c), l = a[0] <= h[0] ? 1 : -1, m = a[1] <= h[1] ? 1 : -1;
341
- this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${m})`;
342
- const d = C.getDirectionVector(
525
+ const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
526
+ this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
527
+ const d = v.getDirectionVector(
343
528
  i.direction,
344
529
  l,
345
- m
346
- ), g = C.getDirectionVector(
347
- c.direction,
530
+ g
531
+ ), m = v.getDirectionVector(
532
+ h.direction,
348
533
  l,
349
- m
350
- ), u = C.rotate(
534
+ g
535
+ ), u = v.rotate(
351
536
  [this.arrowLength, 0],
352
537
  d,
353
538
  [0, 0]
354
- ), p = C.rotate(
539
+ ), p = v.rotate(
355
540
  [o - this.arrowLength, s],
356
- g,
541
+ m,
357
542
  [o, s]
358
543
  ), f = [
359
544
  u[0] + d[0] * this.curvature,
360
545
  u[1] + d[1] * this.curvature
361
546
  ], y = [
362
- p[0] - g[0] * this.curvature,
363
- p[1] - g[1] * this.curvature
364
- ], 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}`;
547
+ p[0] - m[0] * this.curvature,
548
+ p[1] - m[1] * this.curvature
549
+ ], S = `M ${u[0]} ${u[1]}`, b = `C ${f[0]} ${f[1]}, ${y[0]} ${y[1]}, ${p[0]} ${p[1]}`, N = `M 0 0 L ${u[0]} ${u[1]} `, C = ` M ${p[0]} ${p[1]} L ${o} ${s}`, w = `${this.sourceArrow ? "" : N}${S} ${b}${this.targetArrow ? "" : C}`;
365
550
  if (this.line.setAttribute("d", w), this.sourceArrow) {
366
- const T = C.getArrowPath(
551
+ const T = v.getArrowPath(
367
552
  d,
368
553
  0,
369
554
  0,
@@ -373,8 +558,8 @@ class R {
373
558
  this.sourceArrow.setAttribute("d", T);
374
559
  }
375
560
  if (this.targetArrow) {
376
- const T = C.getArrowPath(
377
- g,
561
+ const T = v.getArrowPath(
562
+ m,
378
563
  o,
379
564
  s,
380
565
  -this.arrowLength,
@@ -384,7 +569,7 @@ class R {
384
569
  }
385
570
  }
386
571
  }
387
- const z = (n) => () => new R(
572
+ const B = (n) => () => new G(
388
573
  n.color ?? "#5c5c5c",
389
574
  n.width ?? 1,
390
575
  n.curvature ?? 90,
@@ -393,14 +578,14 @@ const z = (n) => () => new R(
393
578
  n.hasSourceArrow ?? !1,
394
579
  n.hasTargetArrow ?? !1
395
580
  );
396
- class G {
397
- constructor(t, e, o, s, i, c, a) {
581
+ class Y {
582
+ constructor(t, e, o, s, i, h, a) {
398
583
  r(this, "svg");
399
584
  r(this, "group");
400
585
  r(this, "line");
401
586
  r(this, "sourceArrow", null);
402
587
  r(this, "targetArrow", null);
403
- 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(
588
+ this.color = t, this.width = e, this.arrowLength = o, this.arrowWidth = s, this.minPortOffset = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
404
589
  "http://www.w3.org/2000/svg",
405
590
  "path"
406
591
  ), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = document.createElementNS(
@@ -408,41 +593,41 @@ class G {
408
593
  "path"
409
594
  ), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
410
595
  }
411
- update(t, e, o, s, i, c) {
596
+ update(t, e, o, s, i, h) {
412
597
  this.svg.style.width = `${o}px`, this.svg.style.height = `${s}px`;
413
- const a = C.getPortCenter(i), h = C.getPortCenter(c), l = a[0] <= h[0] ? 1 : -1, m = a[1] <= h[1] ? 1 : -1;
414
- this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${m})`;
415
- const d = C.getDirectionVector(
598
+ const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
599
+ this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
600
+ const d = v.getDirectionVector(
416
601
  i.direction,
417
602
  l,
418
- m
419
- ), g = C.getDirectionVector(
420
- c.direction,
603
+ g
604
+ ), m = v.getDirectionVector(
605
+ h.direction,
421
606
  l,
422
- m
423
- ), u = C.rotate(
607
+ g
608
+ ), u = v.rotate(
424
609
  [this.arrowLength + this.minPortOffset, 0],
425
610
  d,
426
611
  [0, 0]
427
- ), p = C.rotate(
612
+ ), p = v.rotate(
428
613
  [o - this.arrowLength - this.minPortOffset, s],
429
- g,
614
+ m,
430
615
  [o, s]
431
- ), [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(
616
+ ), [f, y] = [o / 2, s / 2], S = l * (p[0] - u[0]) > 0 ? `M ${u[0]} ${u[1]} L ${f} ${u[1]} L ${f} ${p[1]} L ${p[0]} ${p[1]}` : `M ${u[0]} ${u[1]} L ${u[0]} ${y} L ${p[0]} ${y} L ${p[0]} ${p[1]}`, b = `M 0 0 L ${u[0]} ${u[1]} `, N = ` M ${p[0]} ${p[1]} L ${o} ${s}`, C = v.getArrowOffsetPath(
432
617
  d,
433
618
  0,
434
619
  0,
435
620
  this.arrowLength,
436
621
  this.minPortOffset
437
- ), w = C.getArrowOffsetPath(
438
- g,
622
+ ), w = v.getArrowOffsetPath(
623
+ m,
439
624
  o,
440
625
  s,
441
626
  -this.arrowLength,
442
627
  -this.minPortOffset
443
- ), T = `${this.sourceArrow ? v : S}${b}${this.targetArrow ? w : N}`;
628
+ ), T = `${this.sourceArrow ? C : b}${S}${this.targetArrow ? w : N}`;
444
629
  if (this.line.setAttribute("d", T), this.sourceArrow) {
445
- const E = C.getArrowPath(
630
+ const E = v.getArrowPath(
446
631
  d,
447
632
  0,
448
633
  0,
@@ -452,8 +637,8 @@ class G {
452
637
  this.sourceArrow.setAttribute("d", E);
453
638
  }
454
639
  if (this.targetArrow) {
455
- const E = C.getArrowPath(
456
- g,
640
+ const E = v.getArrowPath(
641
+ m,
457
642
  o,
458
643
  s,
459
644
  -this.arrowLength,
@@ -463,7 +648,7 @@ class G {
463
648
  }
464
649
  }
465
650
  }
466
- const B = (n) => () => new G(
651
+ const X = (n) => () => new Y(
467
652
  n.color,
468
653
  n.width,
469
654
  n.arrowLength,
@@ -473,364 +658,181 @@ const B = (n) => () => new G(
473
658
  n.hasTargetArrow
474
659
  );
475
660
  var $ = /* @__PURE__ */ ((n) => (n.Regular = "regular", n.Cycle = "cycle", n))($ || {});
476
- class Y {
477
- constructor(t) {
478
- this.di = t;
661
+ class A {
662
+ constructor() {
663
+ r(this, "counter", 0);
664
+ }
665
+ next() {
666
+ const t = `${this.counter}`;
667
+ return this.counter++, t;
668
+ }
669
+ reset() {
670
+ this.counter = 0;
671
+ }
672
+ }
673
+ class Z {
674
+ constructor(t, e, o, s, i) {
675
+ r(this, "nodeIdGenerator", new A());
676
+ r(this, "portIdGenerator", new A());
677
+ r(this, "connectionIdGenerator", new A());
678
+ this.graphStore = t, this.htmlController = e, this.viewportTransformer = o, this.nodesCenterFn = s, this.portsCenterFn = i;
479
679
  }
480
680
  moveNodeOnTop(t) {
481
- if (!this.di.graphStore.hasNode(t))
681
+ if (!this.graphStore.hasNode(t))
482
682
  throw new Error("failed to move on top nonexisting node");
483
- this.di.htmlController.moveNodeOnTop(t);
683
+ this.htmlController.moveNodeOnTop(t);
484
684
  }
485
685
  dragNode(t, e, o) {
486
- if (!this.di.graphStore.hasNode(t))
686
+ if (!this.graphStore.hasNode(t))
487
687
  throw new Error("failed to drag nonexisting node");
488
- 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);
489
- this.di.graphStore.updateNodeCoords(t, l, m), this.di.htmlController.updateNodePosition(t);
688
+ const s = this.graphStore.getNode(t), [i, h] = this.viewportTransformer.getViewCoords(s.x, s.y), a = i + e, c = h + o, [l, g] = this.viewportTransformer.getAbsCoords(a, c);
689
+ this.graphStore.updateNodeCoords(t, l, g), this.htmlController.updateNodePosition(t);
490
690
  }
491
- addNode(t, e, o, s, i, c) {
691
+ addNode(t, e, o, s, i, h) {
492
692
  if (t === void 0)
493
693
  do
494
- t = this.di.nodeIdGenerator.next();
495
- while (this.di.graphStore.hasNode(t));
496
- if (this.di.graphStore.hasNode(t))
694
+ t = this.nodeIdGenerator.next();
695
+ while (this.graphStore.hasNode(t));
696
+ if (this.graphStore.hasNode(t))
497
697
  throw new Error("failed to add node with existing id");
498
- this.di.graphStore.addNode(
698
+ this.graphStore.addNode(
499
699
  t,
500
700
  e,
501
701
  o,
502
702
  s,
503
- c ?? this.di.options.nodes.centerFn
504
- ), this.di.htmlController.attachNode(t), i !== void 0 && Object.entries(i).forEach(([a, h]) => {
505
- h instanceof HTMLElement ? this.di.controller.markPort(
506
- a,
507
- h,
508
- t,
509
- this.di.options.ports.centerFn,
510
- null
511
- ) : this.di.controller.markPort(
703
+ h ?? this.nodesCenterFn
704
+ ), this.htmlController.attachNode(t), i !== void 0 && Object.entries(i).forEach(([a, c]) => {
705
+ c instanceof HTMLElement ? this.markPort(a, c, t, this.portsCenterFn, null) : this.markPort(
512
706
  a,
513
- h.element,
707
+ c.element,
514
708
  t,
515
- h.centerFn ?? this.di.options.ports.centerFn,
516
- h.direction ?? null
709
+ c.centerFn ?? this.portsCenterFn,
710
+ c.direction ?? null
517
711
  );
518
712
  });
519
713
  }
520
714
  markPort(t, e, o, s, i) {
521
715
  if (t === void 0)
522
716
  do
523
- t = this.di.portIdGenerator.next();
524
- while (this.di.graphStore.hasPort(t));
525
- if (!this.di.graphStore.hasNode(o))
717
+ t = this.portIdGenerator.next();
718
+ while (this.graphStore.hasPort(t));
719
+ if (!this.graphStore.hasNode(o))
526
720
  throw new Error("failed to set port on nonexisting node");
527
- if (this.di.graphStore.hasPort(t))
721
+ if (this.graphStore.hasPort(t))
528
722
  throw new Error("failed to add port with existing id");
529
- this.di.graphStore.addPort(
723
+ this.graphStore.addPort(
530
724
  t,
531
725
  e,
532
726
  o,
533
- s ?? this.di.options.ports.centerFn,
727
+ s ?? this.portsCenterFn,
534
728
  i ?? null
535
729
  );
536
730
  }
537
731
  updatePortConnections(t) {
538
- if (!this.di.graphStore.hasPort(t))
732
+ if (!this.graphStore.hasPort(t))
539
733
  throw new Error("failed to unset nonexisting port");
540
- this.di.htmlController.updatePortConnections(t);
734
+ this.htmlController.updatePortConnections(t);
541
735
  }
542
736
  unmarkPort(t) {
543
- if (!this.di.graphStore.hasPort(t))
737
+ if (!this.graphStore.hasPort(t))
544
738
  throw new Error("failed to unset nonexisting port");
545
- this.di.graphStore.getPortAdjacentConnections(t).forEach((e) => {
739
+ this.graphStore.getPortAdjacentConnections(t).forEach((e) => {
546
740
  this.removeConnection(e);
547
- }), this.di.graphStore.removePort(t);
741
+ }), this.graphStore.removePort(t);
548
742
  }
549
743
  addConnection(t, e, o, s) {
550
744
  if (t === void 0)
551
745
  do
552
- t = this.di.connectionIdGenerator.next();
553
- while (this.di.graphStore.hasConnection(t));
554
- if (!this.di.graphStore.hasPort(e))
746
+ t = this.connectionIdGenerator.next();
747
+ while (this.graphStore.hasConnection(t));
748
+ if (!this.graphStore.hasPort(e))
555
749
  throw new Error("failed to add connection from nonexisting port");
556
- if (!this.di.graphStore.hasPort(o))
750
+ if (!this.graphStore.hasPort(o))
557
751
  throw new Error("failed to add connection to nonexisting port");
558
- this.di.graphStore.addConnection(
752
+ this.graphStore.addConnection(
559
753
  t,
560
754
  e,
561
755
  o,
562
756
  s($.Regular)
563
- ), this.di.htmlController.attachConnection(t);
757
+ ), this.htmlController.attachConnection(t);
564
758
  }
565
759
  removeConnection(t) {
566
- if (!this.di.graphStore.hasConnection(t))
760
+ if (!this.graphStore.hasConnection(t))
567
761
  throw new Error("failed to remove nonexisting connection");
568
- this.di.htmlController.detachConnection(t), this.di.graphStore.removeConnection(t);
762
+ this.htmlController.detachConnection(t), this.graphStore.removeConnection(t);
569
763
  }
570
764
  removeNode(t) {
571
- if (!this.di.graphStore.hasNode(t))
765
+ if (!this.graphStore.hasNode(t))
572
766
  throw new Error("failed to remove nonexisting node");
573
- this.di.htmlController.detachNode(t), this.di.graphStore.removeNode(t);
767
+ this.htmlController.detachNode(t), this.graphStore.removeNode(t);
574
768
  }
575
- patchViewportTransform(t, e, o) {
576
- this.di.viewportTransformer.patchState(t, e, o), this.di.htmlController.applyTransform();
769
+ patchViewportState(t, e, o) {
770
+ this.viewportTransformer.patchState(t, e, o), this.htmlController.applyTransform();
577
771
  }
578
- moveContent(t, e) {
579
- this.di.viewportTransformer.applyShift(-t, -e), this.di.htmlController.applyTransform();
772
+ moveViewport(t, e) {
773
+ this.viewportTransformer.applyShift(t, e), this.htmlController.applyTransform();
580
774
  }
581
775
  scaleContent(t, e, o) {
582
- this.di.viewportTransformer.applyScale(1 / t, e, o), this.di.htmlController.applyTransform();
776
+ this.viewportTransformer.applyScale(t, e, o), this.htmlController.applyTransform();
583
777
  }
584
778
  moveToNodes(t) {
585
779
  if (t.length === 0)
586
780
  return;
587
- const e = t.map((g) => this.di.graphStore.getNode(g)).filter((g) => g !== void 0);
781
+ const e = t.map((m) => this.graphStore.getNode(m)).filter((m) => m !== void 0);
588
782
  if (e.length < t.length)
589
783
  throw new Error("failed to move to nonexisting node");
590
784
  const [o, s] = e.reduce(
591
- (g, u) => [g[0] + u.x, g[1] + u.y],
785
+ (m, u) => [m[0] + u.x, m[1] + u.y],
592
786
  [0, 0]
593
- ), 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;
594
- this.patchViewportTransform(null, m, d);
787
+ ), i = o / e.length, h = s / e.length, [a, c] = this.htmlController.getViewportDimensions(), l = this.viewportTransformer.getAbsScale(), g = i - l * a / 2, d = h - l * c / 2;
788
+ this.patchViewportState(null, g, d);
595
789
  }
596
790
  updateNodeCoords(t, e, o) {
597
- if (!this.di.graphStore.hasNode(t))
791
+ if (!this.graphStore.hasNode(t))
598
792
  throw new Error("failed to update coordinates of nonexisting node");
599
- this.di.graphStore.updateNodeCoords(t, e, o), this.di.htmlController.updateNodePosition(t);
600
- }
601
- updateConnectionOptions(t, e) {
602
- if (!this.di.graphStore.hasConnection(t))
603
- throw new Error("failed to update nonexisting connection");
604
- this.di.htmlController.detachConnection(t), this.di.graphStore.updateConnectionController(t, e), this.di.htmlController.attachConnection(t);
605
- }
606
- clear() {
607
- this.di.htmlController.clear(), this.di.graphStore.clear(), this.di.nodeIdGenerator.reset(), this.di.portIdGenerator.reset(), this.di.connectionIdGenerator.reset();
608
- }
609
- destroy() {
610
- this.di.htmlController.destroy();
611
- }
612
- }
613
- class X {
614
- constructor() {
615
- r(this, "nodes", /* @__PURE__ */ Object.create(null));
616
- r(this, "ports", /* @__PURE__ */ Object.create(null));
617
- r(this, "nodePorts", /* @__PURE__ */ Object.create(null));
618
- r(this, "portNodeId", /* @__PURE__ */ Object.create(null));
619
- r(this, "connections", /* @__PURE__ */ Object.create(null));
620
- r(this, "incommingConnections", /* @__PURE__ */ Object.create(null));
621
- r(this, "outcommingConnections", /* @__PURE__ */ Object.create(null));
622
- r(this, "cycleConnections", /* @__PURE__ */ Object.create(null));
623
- }
624
- getAllNodes() {
625
- return Object.keys(this.nodes);
626
- }
627
- getAllPorts() {
628
- return Object.keys(this.ports);
629
- }
630
- getAllConnections() {
631
- return Object.keys(this.connections);
632
- }
633
- addNode(t, e, o, s, i) {
634
- this.nodes[t] = { element: e, x: o, y: s, centerFn: i }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
635
- }
636
- hasNode(t) {
637
- return this.nodes[t] !== void 0;
638
- }
639
- getNode(t) {
640
- return this.nodes[t];
641
- }
642
- updateNodeCoords(t, e, o) {
643
- this.nodes[t].x = e, this.nodes[t].y = o;
793
+ this.graphStore.updateNodeCoords(t, e, o), this.htmlController.updateNodePosition(t);
644
794
  }
645
795
  updateConnectionController(t, e) {
646
- this.connections[t].controller = e;
647
- }
648
- removeNode(t) {
649
- this.getNodeAdjacentConnections(t).forEach((s) => {
650
- this.removeConnection(s);
651
- }), delete this.nodes[t];
652
- const o = this.nodePorts[t];
653
- Object.keys(o).forEach((s) => {
654
- delete this.portNodeId[s];
655
- }), delete this.nodePorts[t];
656
- }
657
- addPort(t, e, o, s, i) {
658
- this.ports[t] = { element: e, centerFn: s, direction: i }, this.cycleConnections[t] = {}, this.incommingConnections[t] = {}, this.outcommingConnections[t] = {}, this.portNodeId[t] = o;
659
- const c = this.nodePorts[o];
660
- c !== void 0 && (c[t] = e);
661
- }
662
- getPort(t) {
663
- return this.ports[t];
664
- }
665
- getPortNode(t) {
666
- return this.portNodeId[t];
667
- }
668
- hasPort(t) {
669
- return this.portNodeId[t] !== void 0;
670
- }
671
- removePort(t) {
672
- Object.keys(this.cycleConnections[t]).forEach((s) => {
673
- this.removeConnection(s);
674
- }), delete this.cycleConnections[t], Object.keys(this.incommingConnections[t]).forEach((s) => {
675
- this.removeConnection(s);
676
- }), delete this.incommingConnections[t], Object.keys(this.outcommingConnections[t]).forEach((s) => {
677
- this.removeConnection(s);
678
- }), delete this.outcommingConnections[t];
679
- const e = this.portNodeId[t];
680
- delete this.portNodeId[t];
681
- const o = this.nodePorts[e];
682
- delete o[t], delete this.ports[t];
683
- }
684
- addConnection(t, e, o, s) {
685
- this.connections[t] = {
686
- from: e,
687
- to: o,
688
- controller: s
689
- }, e !== o ? (this.outcommingConnections[e][t] = !0, this.incommingConnections[o][t] = !0) : this.cycleConnections[e][t] = !0;
690
- }
691
- getConnection(t) {
692
- return this.connections[t];
693
- }
694
- hasConnection(t) {
695
- return this.connections[t] !== void 0;
696
- }
697
- removeConnection(t) {
698
- const e = this.connections[t], o = e.from, s = e.to;
699
- 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];
700
- }
701
- getPortIncomingConnections(t) {
702
- return Object.keys(this.incommingConnections[t] ?? {});
703
- }
704
- getPortOutcomingConnections(t) {
705
- return Object.keys(this.outcommingConnections[t] ?? {});
706
- }
707
- getPortCycleConnections(t) {
708
- return Object.keys(this.cycleConnections[t] ?? {});
709
- }
710
- getPortAdjacentConnections(t) {
711
- return [
712
- ...this.getPortIncomingConnections(t),
713
- ...this.getPortOutcomingConnections(t),
714
- ...this.getPortCycleConnections(t)
715
- ];
716
- }
717
- getNodeIncomingConnections(t) {
718
- const e = Object.keys(this.nodePorts[t]);
719
- let o = [];
720
- return e.forEach((s) => {
721
- o = [...o, ...this.getPortIncomingConnections(s)];
722
- }), o;
723
- }
724
- getNodeOutcomingConnections(t) {
725
- const e = Object.keys(this.nodePorts[t]);
726
- let o = [];
727
- return e.forEach((s) => {
728
- o = [...o, ...this.getPortOutcomingConnections(s)];
729
- }), o;
796
+ if (!this.graphStore.hasConnection(t))
797
+ throw new Error("failed to update nonexisting connection");
798
+ this.htmlController.detachConnection(t), this.graphStore.updateConnectionController(t, e), this.htmlController.attachConnection(t);
730
799
  }
731
- getNodeCycleConnections(t) {
732
- const e = Object.keys(this.nodePorts[t]);
733
- let o = [];
734
- return e.forEach((s) => {
735
- o = [...o, ...this.getPortCycleConnections(s)];
736
- }), o;
800
+ attach(t) {
801
+ this.htmlController.attach(t);
737
802
  }
738
- getNodeAdjacentConnections(t) {
739
- return [
740
- ...this.getNodeIncomingConnections(t),
741
- ...this.getNodeOutcomingConnections(t),
742
- ...this.getNodeCycleConnections(t)
743
- ];
803
+ detach() {
804
+ this.htmlController.detach();
744
805
  }
745
806
  clear() {
746
- 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);
747
- }
748
- }
749
- class Z {
750
- constructor(t) {
751
- this.graphStore = t;
752
- }
753
- getNode(t) {
754
- const e = this.graphStore.getNode(t);
755
- return e === void 0 ? null : { x: e.x, y: e.y };
756
- }
757
- getPort(t) {
758
- const e = this.graphStore.getPortNode(t);
759
- return e === void 0 ? null : { nodeId: e };
760
- }
761
- getConnection(t) {
762
- const e = this.graphStore.getConnection(t);
763
- return e === void 0 ? null : { from: e.from, to: e.to };
764
- }
765
- getAllNodes() {
766
- return this.graphStore.getAllNodes();
767
- }
768
- getAllPorts() {
769
- return this.graphStore.getAllPorts();
770
- }
771
- getAllConnections() {
772
- return this.graphStore.getAllConnections();
773
- }
774
- hasNode(t) {
775
- return this.graphStore.hasNode(t);
776
- }
777
- hasPort(t) {
778
- return this.graphStore.hasPort(t);
807
+ this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.connectionIdGenerator.reset();
779
808
  }
780
- hasConnection(t) {
781
- return this.graphStore.hasConnection(t);
782
- }
783
- getPortIncomingConnections(t) {
784
- return this.graphStore.getPortIncomingConnections(t);
785
- }
786
- getPortOutcomingConnections(t) {
787
- return this.graphStore.getPortOutcomingConnections(t);
788
- }
789
- getPortCycleConnections(t) {
790
- return this.graphStore.getPortCycleConnections(t);
791
- }
792
- getPortAdjacentConnections(t) {
793
- return this.graphStore.getPortAdjacentConnections(t);
794
- }
795
- getNodeIncomingConnections(t) {
796
- return this.graphStore.getNodeIncomingConnections(t);
797
- }
798
- getNodeOutcomingConnections(t) {
799
- return this.graphStore.getNodeOutcomingConnections(t);
800
- }
801
- getNodeCycleConnections(t) {
802
- return this.graphStore.getNodeCycleConnections(t);
803
- }
804
- getNodeAdjacentConnections(t) {
805
- return this.graphStore.getNodeAdjacentConnections(t);
806
- }
807
- }
808
- class A {
809
- constructor() {
810
- r(this, "counter", 0);
811
- }
812
- next() {
813
- const t = `${this.counter}`;
814
- return this.counter++, t;
815
- }
816
- reset() {
817
- this.counter = 0;
809
+ destroy() {
810
+ this.htmlController.destroy();
818
811
  }
819
812
  }
820
813
  class H {
821
- constructor(t) {
814
+ constructor(t, e, o, s) {
822
815
  r(this, "htmlController");
823
816
  r(this, "viewportTransformer");
824
- r(this, "publicViewportTransformer");
825
- r(this, "controller");
826
817
  r(this, "graphStore");
818
+ r(this, "publicViewportTransformer");
827
819
  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(
820
+ r(this, "canvasController");
821
+ this.viewportTransformer = new D(), this.publicViewportTransformer = new W(
832
822
  this.viewportTransformer
833
- ), this.controller = new Y(this), this.graphStore = new X(), this.publicGraphStore = new Z(this.graphStore), this.nodeIdGenerator = new A(), this.portIdGenerator = new A(), this.connectionIdGenerator = new A();
823
+ ), this.graphStore = new R(), this.publicGraphStore = new z(this.graphStore), this.htmlController = new j(
824
+ this.graphStore,
825
+ this.viewportTransformer,
826
+ this.publicViewportTransformer,
827
+ t,
828
+ e
829
+ ), this.canvasController = new Z(
830
+ this.graphStore,
831
+ this.htmlController,
832
+ this.viewportTransformer,
833
+ o,
834
+ s
835
+ );
834
836
  }
835
837
  }
836
838
  const P = (n, t) => [
@@ -838,17 +840,18 @@ const P = (n, t) => [
838
840
  t / 2
839
841
  ], U = () => () => {
840
842
  }, 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;
843
+ n.clearRect(0, 0, n.canvas.width, n.canvas.height), n.save(), n.fillStyle = i, n.fillRect(0, 0, n.canvas.width, n.canvas.height);
844
+ const h = t.getViewCoords(0, 0), a = t.getViewScale(), c = o * a;
845
+ let l = 0, g = 0, d = c / 2;
844
846
  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;
847
+ d *= 2, l = n.canvas.width / d, g = n.canvas.height / d;
848
+ while (l * g > 1e4);
849
+ const m = h[0] - Math.floor(h[0] / d) * d, u = h[1] - Math.floor(h[1] / d) * d, p = s * a, f = 2 * Math.PI, y = m - d, S = u - d, b = n.canvas.width + m, N = n.canvas.height + u;
848
850
  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();
851
+ for (let C = y; C <= b; C += d)
852
+ for (let w = S; w <= N; w += d)
853
+ n.beginPath(), n.arc(C, w, p, 0, f), n.closePath(), n.fill();
854
+ n.restore();
852
855
  }, J = (n, t, e, o) => (s, i) => {
853
856
  q(
854
857
  s,
@@ -878,12 +881,12 @@ const P = (n, t) => [
878
881
  default:
879
882
  return U();
880
883
  }
881
- }, x = (n) => {
884
+ }, O = (n) => {
882
885
  switch (n == null ? void 0 : n.type) {
883
886
  case "custom":
884
887
  return n.controllerFactory;
885
888
  case "straight":
886
- return B({
889
+ return X({
887
890
  color: n.color ?? "#5c5c5c",
888
891
  width: n.width ?? 1,
889
892
  arrowLength: n.arrowLength ?? 15,
@@ -893,7 +896,7 @@ const P = (n, t) => [
893
896
  hasTargetArrow: n.hasTargetArrow ?? !1
894
897
  });
895
898
  default:
896
- return z({
899
+ return B({
897
900
  color: n.color ?? "#5c5c5c",
898
901
  width: n.width ?? 1,
899
902
  curvature: n.curvature ?? 90,
@@ -918,7 +921,7 @@ const P = (n, t) => [
918
921
  centerFn: ((e = n.ports) == null ? void 0 : e.centerFn) ?? P
919
922
  },
920
923
  connections: {
921
- controllerFactory: x(
924
+ controllerFactory: O(
922
925
  n.connections ?? {}
923
926
  )
924
927
  },
@@ -931,12 +934,19 @@ class tt {
931
934
  constructor(t) {
932
935
  r(this, "transformation");
933
936
  r(this, "model");
934
- r(this, "options");
935
937
  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;
938
+ r(this, "connectionControllerFactory");
939
+ this.apiOptions = t;
940
+ const e = I(this.apiOptions ?? {});
941
+ this.di = new H(
942
+ e.layers.mode,
943
+ e.background.drawingFn,
944
+ e.nodes.centerFn,
945
+ e.ports.centerFn
946
+ ), this.transformation = this.di.publicViewportTransformer, this.model = this.di.publicGraphStore, this.connectionControllerFactory = e.connections.controllerFactory;
937
947
  }
938
948
  addNode(t) {
939
- return this.di.controller.addNode(
949
+ return this.di.canvasController.addNode(
940
950
  t.id,
941
951
  t.element,
942
952
  t.x,
@@ -946,13 +956,13 @@ class tt {
946
956
  ), this;
947
957
  }
948
958
  moveNodeOnTop(t) {
949
- return this.di.controller.moveNodeOnTop(t), this;
959
+ return this.di.canvasController.moveNodeOnTop(t), this;
950
960
  }
951
961
  removeNode(t) {
952
- return this.di.controller.removeNode(t), this;
962
+ return this.di.canvasController.removeNode(t), this;
953
963
  }
954
964
  markPort(t) {
955
- return this.di.controller.markPort(
965
+ return this.di.canvasController.markPort(
956
966
  t.id,
957
967
  t.element,
958
968
  t.nodeId,
@@ -961,14 +971,14 @@ class tt {
961
971
  ), this;
962
972
  }
963
973
  updatePortConnections(t) {
964
- return this.di.controller.updatePortConnections(t), this;
974
+ return this.di.canvasController.updatePortConnections(t), this;
965
975
  }
966
976
  unmarkPort(t) {
967
- return this.di.controller.unmarkPort(t), this;
977
+ return this.di.canvasController.unmarkPort(t), this;
968
978
  }
969
979
  addConnection(t) {
970
- const e = t.options !== void 0 ? x(t.options) : this.di.options.connections.controllerFactory;
971
- return this.di.controller.addConnection(
980
+ const e = t.options !== void 0 ? O(t.options) : this.connectionControllerFactory;
981
+ return this.di.canvasController.addConnection(
972
982
  t.id,
973
983
  t.from,
974
984
  t.to,
@@ -976,48 +986,54 @@ class tt {
976
986
  ), this;
977
987
  }
978
988
  removeConnection(t) {
979
- return this.di.controller.removeConnection(t), this;
989
+ return this.di.canvasController.removeConnection(t), this;
980
990
  }
981
- patchViewportTransform(t) {
982
- return this.di.controller.patchViewportTransform(
991
+ patchViewportState(t) {
992
+ return this.di.canvasController.patchViewportState(
983
993
  t.scale ?? null,
984
994
  t.x ?? null,
985
995
  t.y ?? null
986
996
  ), this;
987
997
  }
988
- moveContent(t) {
989
- return this.di.controller.moveContent(t.x ?? 0, t.y ?? 0), this;
998
+ moveViewport(t) {
999
+ return this.di.canvasController.moveViewport(
1000
+ t.x ?? 0,
1001
+ t.y ?? 0
1002
+ ), this;
990
1003
  }
991
- scaleContent(t) {
992
- return this.di.controller.scaleContent(
1004
+ scaleViewport(t) {
1005
+ return this.di.canvasController.scaleContent(
993
1006
  t.scale,
994
1007
  t.x ?? 0,
995
1008
  t.y ?? 0
996
1009
  ), this;
997
1010
  }
998
1011
  moveToNodes(t) {
999
- return this.di.controller.moveToNodes(t), this;
1012
+ return this.di.canvasController.moveToNodes(t), this;
1000
1013
  }
1001
1014
  updateNodeCoords(t, e, o) {
1002
- return this.di.controller.updateNodeCoords(t, e, o), this;
1015
+ return this.di.canvasController.updateNodeCoords(t, e, o), this;
1003
1016
  }
1004
- updateConnectionController(t, e) {
1005
- return this.di.controller.updateConnectionOptions(t, e), this;
1017
+ updateConnection(t, e) {
1018
+ return e.controller !== void 0 && this.di.canvasController.updateConnectionController(
1019
+ t,
1020
+ e.controller
1021
+ ), this;
1006
1022
  }
1007
1023
  dragNode(t, e, o) {
1008
- return this.di.controller.dragNode(t, e, o), this;
1024
+ return this.di.canvasController.dragNode(t, e, o), this;
1009
1025
  }
1010
1026
  clear() {
1011
- return this.di.controller.clear(), this;
1027
+ return this.di.canvasController.clear(), this;
1012
1028
  }
1013
1029
  attach(t) {
1014
- return this.di.htmlController.attach(t), this;
1030
+ return this.di.canvasController.attach(t), this;
1015
1031
  }
1016
1032
  detach() {
1017
- return this.di.htmlController.detach(), this;
1033
+ return this.di.canvasController.detach(), this;
1018
1034
  }
1019
1035
  destroy() {
1020
- this.di.controller.destroy();
1036
+ this.di.canvasController.destroy();
1021
1037
  }
1022
1038
  }
1023
1039
  class et {
@@ -1100,14 +1116,14 @@ class et {
1100
1116
  removeConnection(t) {
1101
1117
  return this.canvas.removeConnection(t), this;
1102
1118
  }
1103
- patchViewportTransform(t) {
1104
- return this.canvas.patchViewportTransform(t), this;
1119
+ patchViewportState(t) {
1120
+ return this.canvas.patchViewportState(t), this;
1105
1121
  }
1106
- moveContent(t) {
1107
- return this.canvas.moveContent(t), this;
1122
+ moveViewport(t) {
1123
+ return this.canvas.moveViewport(t), this;
1108
1124
  }
1109
- scaleContent(t) {
1110
- return this.canvas.scaleContent(t), this;
1125
+ scaleViewport(t) {
1126
+ return this.canvas.scaleViewport(t), this;
1111
1127
  }
1112
1128
  moveToNodes(t) {
1113
1129
  return this.canvas.moveToNodes(t), this;
@@ -1115,8 +1131,8 @@ class et {
1115
1131
  updateNodeCoords(t, e, o) {
1116
1132
  return this.canvas.updateNodeCoords(t, e, o), this;
1117
1133
  }
1118
- updateConnectionController(t, e) {
1119
- return this.canvas.updateConnectionController(t, e), this;
1134
+ updateConnection(t, e) {
1135
+ return this.canvas.updateConnection(t, e), this;
1120
1136
  }
1121
1137
  dragNode(t, e, o) {
1122
1138
  return this.canvas.dragNode(t, e, o), this;
@@ -1130,7 +1146,7 @@ class et {
1130
1146
  }), this.nodes.clear(), this;
1131
1147
  }
1132
1148
  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;
1149
+ return this.canvas.attach(t), this.element = t, this.element.addEventListener("mouseup", this.onCanvasMouseUp), this.element.addEventListener("mousemove", this.onCanvasMouseMove), this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.element.addEventListener("touchmove", this.onCanvasTouchMove), this.element.addEventListener("touchend", this.onCanvasTouchEnd), this.element.addEventListener("touchcancel", this.onCanvasTouchEnd), this;
1134
1150
  }
1135
1151
  detach() {
1136
1152
  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;
@@ -1160,7 +1176,7 @@ class ot {
1160
1176
  this.setCursor("grab"), this.isMoving = !0;
1161
1177
  });
1162
1178
  r(this, "onMouseMove", (t) => {
1163
- !this.isMoving || !this.isShiftable || this.canvas.moveContent({ x: t.movementX, y: t.movementY });
1179
+ !this.isMoving || !this.isShiftable || this.canvas.moveViewport({ x: -t.movementX, y: -t.movementY });
1164
1180
  });
1165
1181
  r(this, "onMouseUp", () => {
1166
1182
  this.setCursor(null), this.isMoving = !1;
@@ -1169,8 +1185,8 @@ class ot {
1169
1185
  if (this.element === null || this.isScalable === !1)
1170
1186
  return;
1171
1187
  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 });
1188
+ const { left: e, top: o } = this.element.getBoundingClientRect(), s = t.clientX - e, i = t.clientY - o, h = t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity, a = this.canvas.transformation.getViewScale() * h;
1189
+ this.checkNextScaleValid(a) && this.canvas.scaleViewport({ scale: 1 / h, x: s, y: i });
1174
1190
  });
1175
1191
  r(this, "onTouchStart", (t) => {
1176
1192
  this.prevTouches = this.getAverageTouch(t);
@@ -1179,21 +1195,21 @@ class ot {
1179
1195
  if (this.prevTouches === null || this.element === null || !this.isShiftable)
1180
1196
  return;
1181
1197
  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
1198
+ if ((e.touchesCnt === 1 || e.touchesCnt === 2) && this.canvas.moveViewport({
1199
+ x: -(e.x - this.prevTouches.x),
1200
+ y: -(e.y - this.prevTouches.y)
1185
1201
  }), 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 });
1202
+ const { left: o, top: s } = this.element.getBoundingClientRect(), i = this.prevTouches.x - o, h = this.prevTouches.y - s, a = e.scale / this.prevTouches.scale, c = this.canvas.transformation.getViewScale() * a;
1203
+ this.checkNextScaleValid(c) && this.canvas.scaleViewport({ scale: 1 / a, x: i, y: h });
1188
1204
  }
1189
1205
  this.prevTouches = e, t.preventDefault();
1190
1206
  });
1191
1207
  r(this, "onTouchEnd", () => {
1192
1208
  this.prevTouches = null;
1193
1209
  });
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;
1210
+ var s, i, h, a, c, l, g, d, m, u;
1211
+ this.canvas = t, this.options = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((i = (s = this.options) == null ? void 0 : s.scale) == null ? void 0 : i.enabled) !== !1, this.minContentScale = ((a = (h = this.options) == null ? void 0 : h.scale) == null ? void 0 : a.minContent) ?? null, this.maxContentScale = ((l = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : l.maxContent) ?? null, this.isShiftable = ((d = (g = this.options) == null ? void 0 : g.shift) == null ? void 0 : d.enabled) !== !1;
1212
+ const o = (u = (m = this.options) == null ? void 0 : m.scale) == null ? void 0 : u.wheelSensitivity;
1197
1213
  this.wheelSensitivity = o !== void 0 ? o : 1.2;
1198
1214
  }
1199
1215
  addNode(t) {
@@ -1217,14 +1233,14 @@ class ot {
1217
1233
  removeConnection(t) {
1218
1234
  return this.canvas.removeConnection(t), this;
1219
1235
  }
1220
- patchViewportTransform(t) {
1221
- return this.canvas.patchViewportTransform(t), this;
1236
+ patchViewportState(t) {
1237
+ return this.canvas.patchViewportState(t), this;
1222
1238
  }
1223
- moveContent(t) {
1224
- return this.canvas.moveContent(t), this;
1239
+ moveViewport(t) {
1240
+ return this.canvas.moveViewport(t), this;
1225
1241
  }
1226
- scaleContent(t) {
1227
- return this.canvas.scaleContent(t), this;
1242
+ scaleViewport(t) {
1243
+ return this.canvas.scaleViewport(t), this;
1228
1244
  }
1229
1245
  moveToNodes(t) {
1230
1246
  return this.canvas.moveToNodes(t), this;
@@ -1232,8 +1248,8 @@ class ot {
1232
1248
  updateNodeCoords(t, e, o) {
1233
1249
  return this.canvas.updateNodeCoords(t, e, o), this;
1234
1250
  }
1235
- updateConnectionController(t, e) {
1236
- return this.canvas.updateConnectionController(t, e), this;
1251
+ updateConnection(t, e) {
1252
+ return this.canvas.updateConnection(t, e), this;
1237
1253
  }
1238
1254
  dragNode(t, e, o) {
1239
1255
  return this.canvas.dragNode(t, e, o), this;
@@ -1245,7 +1261,7 @@ class ot {
1245
1261
  return this.canvas.clear(), this;
1246
1262
  }
1247
1263
  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;
1264
+ return this.canvas.attach(t), this.element = t, this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("mousemove", this.onMouseMove), this.element.addEventListener("mouseup", this.onMouseUp), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.element.addEventListener("touchmove", this.onTouchMove), this.element.addEventListener("touchend", this.onTouchEnd), this.element.addEventListener("touchcancel", this.onTouchEnd), this;
1249
1265
  }
1250
1266
  detach() {
1251
1267
  return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("mousemove", this.onMouseMove), this.element.removeEventListener("mouseup", this.onMouseUp), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("touchmove", this.onTouchMove), this.element.removeEventListener("touchend", this.onTouchEnd), this.element.removeEventListener("touchcancel", this.onTouchEnd)), this.element = null, this;
@@ -1255,13 +1271,13 @@ class ot {
1255
1271
  }
1256
1272
  getAverageTouch(t) {
1257
1273
  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]);
1274
+ for (let c = 0; c < o; c++)
1275
+ e.push([t.touches[c].clientX, t.touches[c].clientY]);
1260
1276
  const s = e.reduce(
1261
- (h, l) => [h[0] + l[0], h[1] + l[1]],
1277
+ (c, l) => [c[0] + l[0], c[1] + l[1]],
1262
1278
  [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]),
1279
+ ), i = [s[0] / o, s[1] / o], a = e.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1280
+ (c, l) => c + Math.sqrt(l[0] * l[0] + l[1] * l[1]),
1265
1281
  0
1266
1282
  );
1267
1283
  return { x: i[0], y: i[1], scale: a / o, touchesCnt: o };
@@ -1296,13 +1312,14 @@ class st {
1296
1312
  }
1297
1313
  }
1298
1314
  export {
1299
- R as BezierConnectionController,
1300
- st as CanvasBuilder,
1315
+ G as BezierConnectionController,
1301
1316
  tt as CanvasCore,
1302
- C as ConnectionUtils,
1317
+ $ as ConnectionType,
1318
+ v as ConnectionUtils,
1303
1319
  et as DraggableNodesCanvas,
1304
- G as StraightConnectionController,
1320
+ st as HtmlGraphBuilder,
1321
+ Y as StraightConnectionController,
1305
1322
  ot as TransformableCanvas,
1306
- z as createBezierConnectionControllerFactory,
1307
- B as createStraightConnectionControllerFactory
1323
+ B as createBezierConnectionControllerFactory,
1324
+ X as createStraightConnectionControllerFactory
1308
1325
  };