@html-graph/html-graph 2.1.0 → 2.2.0

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.
@@ -1,75 +1,7 @@
1
1
  var tt = Object.defineProperty;
2
2
  var et = (e, t, o) => t in e ? tt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
3
3
  var i = (e, t, o) => et(e, typeof t != "symbol" ? t + "" : t, o);
4
- class O {
5
- constructor() {
6
- i(this, "callbacks", /* @__PURE__ */ new Set());
7
- }
8
- subscribe(t) {
9
- this.callbacks.add(t);
10
- }
11
- unsubscribe(t) {
12
- this.callbacks.delete(t);
13
- }
14
- emit(t) {
15
- this.callbacks.forEach((o) => {
16
- o(t);
17
- });
18
- }
19
- }
20
- const ot = () => {
21
- const e = new O();
22
- return [e, e];
23
- }, _ = (e) => ({
24
- scale: 1 / e.scale,
25
- x: -e.x / e.scale,
26
- y: -e.y / e.scale
27
- }), J = {
28
- scale: 1,
29
- x: 0,
30
- y: 0
31
- };
32
- class rt {
33
- constructor() {
34
- i(this, "viewportMatrix", J);
35
- i(this, "contentMatrix", J);
36
- i(this, "emitter");
37
- i(this, "onAfterUpdate");
38
- [this.emitter, this.onAfterUpdate] = ot();
39
- }
40
- getViewportMatrix() {
41
- return this.viewportMatrix;
42
- }
43
- getContentMatrix() {
44
- return this.contentMatrix;
45
- }
46
- patchViewportMatrix(t) {
47
- this.viewportMatrix = {
48
- scale: t.scale ?? this.viewportMatrix.scale,
49
- x: t.x ?? this.viewportMatrix.x,
50
- y: t.y ?? this.viewportMatrix.y
51
- }, this.contentMatrix = _(this.viewportMatrix), this.emitter.emit();
52
- }
53
- patchContentMatrix(t) {
54
- this.contentMatrix = {
55
- scale: t.scale ?? this.contentMatrix.scale,
56
- x: t.x ?? this.contentMatrix.x,
57
- y: t.y ?? this.contentMatrix.y
58
- }, this.viewportMatrix = _(this.contentMatrix), this.emitter.emit();
59
- }
60
- }
61
- class it {
62
- constructor(t) {
63
- this.transformer = t;
64
- }
65
- getViewportMatrix() {
66
- return { ...this.transformer.getViewportMatrix() };
67
- }
68
- getContentMatrix() {
69
- return { ...this.transformer.getContentMatrix() };
70
- }
71
- }
72
- class st {
4
+ class ot {
73
5
  constructor(t) {
74
6
  this.graphStore = t;
75
7
  }
@@ -99,8 +31,13 @@ class st {
99
31
  getNodePortIds(t) {
100
32
  return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodePortIds(t);
101
33
  }
34
+ /**
35
+ * @deprecated
36
+ * use graph.getPort()?.nodeId ?? null instead
37
+ */
102
38
  getPortNodeId(t) {
103
- return this.graphStore.getPortNodeId(t) ?? null;
39
+ var o;
40
+ return ((o = this.graphStore.getPort(t)) == null ? void 0 : o.nodeId) ?? null;
104
41
  }
105
42
  getAllEdgeIds() {
106
43
  return this.graphStore.getAllEdgeIds();
@@ -134,11 +71,22 @@ class st {
134
71
  return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeAdjacentEdgeIds(t);
135
72
  }
136
73
  }
137
- class nt {
74
+ class rt {
75
+ constructor(t) {
76
+ this.transformer = t;
77
+ }
78
+ getViewportMatrix() {
79
+ return { ...this.transformer.getViewportMatrix() };
80
+ }
81
+ getContentMatrix() {
82
+ return { ...this.transformer.getContentMatrix() };
83
+ }
84
+ }
85
+ class it {
138
86
  constructor(t, o, r) {
139
87
  i(this, "viewport");
140
88
  i(this, "graph");
141
- this.graphStore = t, this.viewportTransformer = o, this.htmlView = r, this.graph = new st(this.graphStore), this.viewport = new it(this.viewportTransformer);
89
+ this.graphStore = t, this.viewportStore = o, this.htmlView = r, this.graph = new ot(this.graphStore), this.viewport = new rt(this.viewportStore);
142
90
  }
143
91
  attach(t) {
144
92
  this.htmlView.attach(t);
@@ -158,7 +106,7 @@ class nt {
158
106
  removeNode(t) {
159
107
  this.graphStore.getNodePortIds(t).forEach((o) => {
160
108
  this.unmarkPort(o);
161
- }), this.htmlView.detachNode(t), this.graphStore.removeNode(t);
109
+ }), this.graphStore.removeNode(t), this.htmlView.detachNode(t);
162
110
  }
163
111
  markPort(t) {
164
112
  this.graphStore.addPort(t);
@@ -182,13 +130,13 @@ class nt {
182
130
  o.shape !== void 0 && (r.shape = o.shape, this.htmlView.updateEdgeShape(t)), o.from !== void 0 && this.graphStore.updateEdgeFrom(t, o.from), o.to !== void 0 && this.graphStore.updateEdgeTo(t, o.to), this.htmlView.renderEdge(t), o.priority !== void 0 && (r.priority = o.priority, this.htmlView.updateEdgePriority(t));
183
131
  }
184
132
  removeEdge(t) {
185
- this.htmlView.detachEdge(t), this.graphStore.removeEdge(t);
133
+ this.graphStore.removeEdge(t), this.htmlView.detachEdge(t);
186
134
  }
187
135
  patchViewportMatrix(t) {
188
- this.viewportTransformer.patchViewportMatrix(t);
136
+ this.viewportStore.patchViewportMatrix(t);
189
137
  }
190
138
  patchContentMatrix(t) {
191
- this.viewportTransformer.patchContentMatrix(t);
139
+ this.viewportStore.patchContentMatrix(t);
192
140
  }
193
141
  clear() {
194
142
  this.htmlView.clear(), this.graphStore.clear();
@@ -202,7 +150,7 @@ const C = (e, t, o) => {
202
150
  return t >= r && t <= r + h && o >= n && o <= n + s;
203
151
  }, $ = (e, t, o) => t >= 0 && t <= e.innerWidth && o >= 0 && o <= e.innerHeight, W = (e, t) => {
204
152
  t !== null ? e.style.cursor = t : e.style.removeProperty("cursor");
205
- }, ht = (e) => {
153
+ }, st = (e) => {
206
154
  var g, y, x, v, A, S;
207
155
  const t = ((g = e == null ? void 0 : e.events) == null ? void 0 : g.onNodeDrag) ?? (() => {
208
156
  }), o = ((y = e == null ? void 0 : e.events) == null ? void 0 : y.onBeforeNodeDrag) ?? (() => !0), r = ((x = e == null ? void 0 : e.events) == null ? void 0 : x.onNodeDragFinished) ?? (() => {
@@ -217,7 +165,7 @@ const C = (e, t, o) => {
217
165
  onNodeDragFinished: r
218
166
  };
219
167
  };
220
- class ct {
168
+ class nt {
221
169
  constructor(t, o) {
222
170
  i(this, "graph");
223
171
  i(this, "viewport");
@@ -257,7 +205,7 @@ class ct {
257
205
  i(this, "previousTouchCoords", null);
258
206
  i(this, "window", window);
259
207
  i(this, "options");
260
- this.canvas = t, this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.options = ht(o ?? {});
208
+ this.canvas = t, this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.options = st(o ?? {});
261
209
  }
262
210
  attach(t) {
263
211
  this.detach(), this.element = t, this.canvas.attach(this.element);
@@ -388,7 +336,7 @@ class ct {
388
336
  this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
389
337
  }
390
338
  }
391
- const dt = (e) => {
339
+ const ht = (e) => {
392
340
  const t = e.minX !== null ? e.minX : -1 / 0, o = e.maxX !== null ? e.maxX : 1 / 0, r = e.minY !== null ? e.minY : -1 / 0, n = e.maxY !== null ? e.maxY : 1 / 0;
393
341
  return (h) => {
394
342
  let s = h.nextTransform.x, c = h.nextTransform.y;
@@ -398,7 +346,7 @@ const dt = (e) => {
398
346
  const l = h.canvasHeight * h.prevTransform.scale, g = n - l;
399
347
  return c > g && c > h.prevTransform.y && (c = Math.max(h.prevTransform.y, g)), { scale: h.nextTransform.scale, x: s, y: c };
400
348
  };
401
- }, at = (e) => {
349
+ }, ct = (e) => {
402
350
  const t = e.maxContentScale, o = e.minContentScale, r = t !== null ? 1 / t : 0, n = o !== null ? 1 / o : 1 / 0;
403
351
  return (h) => {
404
352
  const s = h.prevTransform, c = h.nextTransform;
@@ -419,7 +367,7 @@ const dt = (e) => {
419
367
  y: l
420
368
  };
421
369
  };
422
- }, lt = (e) => (t) => e.reduce(
370
+ }, dt = (e) => (t) => e.reduce(
423
371
  (o, r) => r({
424
372
  prevTransform: t.prevTransform,
425
373
  nextTransform: o,
@@ -427,38 +375,38 @@ const dt = (e) => {
427
375
  canvasHeight: t.canvasHeight
428
376
  }),
429
377
  t.nextTransform
430
- ), Q = (e) => {
378
+ ), _ = (e) => {
431
379
  if (typeof e == "function")
432
380
  return e;
433
381
  switch (e.type) {
434
382
  case "scale-limit":
435
- return at({
383
+ return ct({
436
384
  minContentScale: e.minContentScale ?? 0,
437
385
  maxContentScale: e.maxContentScale ?? 1 / 0
438
386
  });
439
387
  case "shift-limit":
440
- return dt({
388
+ return ht({
441
389
  minX: e.minX ?? -1 / 0,
442
390
  maxX: e.maxX ?? 1 / 0,
443
391
  minY: e.minY ?? -1 / 0,
444
392
  maxY: e.maxY ?? 1 / 0
445
393
  });
446
394
  }
447
- }, gt = (e) => {
448
- var v, A, S, T, z, P, L, m, U, j, G, K;
395
+ }, at = (e) => {
396
+ var v, A, S, T, z, L, D, P, U, j, G, K;
449
397
  const t = (v = e == null ? void 0 : e.scale) == null ? void 0 : v.mouseWheelSensitivity, o = t !== void 0 ? t : 1.2, r = e == null ? void 0 : e.transformPreprocessor;
450
398
  let n;
451
- r !== void 0 ? Array.isArray(r) ? n = lt(
399
+ r !== void 0 ? Array.isArray(r) ? n = dt(
452
400
  r.map(
453
- (V) => Q(V)
401
+ (V) => _(V)
454
402
  )
455
- ) : n = Q(r) : n = (V) => V.nextTransform;
403
+ ) : n = _(r) : n = (V) => V.nextTransform;
456
404
  const h = ((A = e == null ? void 0 : e.shift) == null ? void 0 : A.cursor) !== void 0 ? e.shift.cursor : "grab", s = ((S = e == null ? void 0 : e.events) == null ? void 0 : S.onBeforeTransformChange) ?? (() => {
457
405
  }), c = ((T = e == null ? void 0 : e.events) == null ? void 0 : T.onTransformChange) ?? (() => {
458
- }), d = (z = e == null ? void 0 : e.shift) == null ? void 0 : z.mouseDownEventVerifier, a = d !== void 0 ? d : (V) => V.button === 0, l = (P = e == null ? void 0 : e.shift) == null ? void 0 : P.mouseUpEventVerifier, g = l !== void 0 ? l : (V) => V.button === 0, y = (L = e == null ? void 0 : e.scale) == null ? void 0 : L.mouseWheelEventVerifier, x = y !== void 0 ? y : () => !0;
406
+ }), d = (z = e == null ? void 0 : e.shift) == null ? void 0 : z.mouseDownEventVerifier, a = d !== void 0 ? d : (V) => V.button === 0, l = (L = e == null ? void 0 : e.shift) == null ? void 0 : L.mouseUpEventVerifier, g = l !== void 0 ? l : (V) => V.button === 0, y = (D = e == null ? void 0 : e.scale) == null ? void 0 : D.mouseWheelEventVerifier, x = y !== void 0 ? y : () => !0;
459
407
  return {
460
408
  wheelSensitivity: o,
461
- onTransformStarted: ((m = e == null ? void 0 : e.events) == null ? void 0 : m.onTransformStarted) ?? (() => {
409
+ onTransformStarted: ((P = e == null ? void 0 : e.events) == null ? void 0 : P.onTransformStarted) ?? (() => {
462
410
  }),
463
411
  onTransformFinished: ((U = e == null ? void 0 : e.events) == null ? void 0 : U.onTransformFinished) ?? (() => {
464
412
  }),
@@ -475,7 +423,7 @@ const dt = (e) => {
475
423
  onResizeTransformFinished: ((K = e == null ? void 0 : e.events) == null ? void 0 : K.onResizeTransformFinished) ?? (() => {
476
424
  })
477
425
  };
478
- }, b = (e) => {
426
+ }, m = (e) => {
479
427
  const t = [], o = e.touches.length;
480
428
  for (let c = 0; c < o; c++)
481
429
  t.push([e.touches[c].clientX, e.touches[c].clientY]);
@@ -493,16 +441,16 @@ const dt = (e) => {
493
441
  touchesCnt: o,
494
442
  touches: t
495
443
  };
496
- }, ut = (e, t, o) => ({
444
+ }, lt = (e, t, o) => ({
497
445
  scale: e.scale,
498
446
  x: e.x + e.scale * t,
499
447
  y: e.y + e.scale * o
500
- }), wt = (e, t, o, r) => ({
448
+ }), gt = (e, t, o, r) => ({
501
449
  scale: e.scale * t,
502
450
  x: e.scale * (1 - t) * o + e.x,
503
451
  y: e.scale * (1 - t) * r + e.y
504
452
  });
505
- class q {
453
+ class O {
506
454
  constructor(t, o) {
507
455
  i(this, "graph");
508
456
  i(this, "viewport");
@@ -535,16 +483,16 @@ class q {
535
483
  });
536
484
  i(this, "onTouchStart", (t) => {
537
485
  if (this.prevTouches !== null) {
538
- this.prevTouches = b(t);
486
+ this.prevTouches = m(t);
539
487
  return;
540
488
  }
541
- this.prevTouches = b(t), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish), this.options.onTransformStarted();
489
+ this.prevTouches = m(t), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish), this.options.onTransformStarted();
542
490
  });
543
491
  i(this, "onWindowTouchMove", (t) => {
544
492
  const o = this.element;
545
493
  if (o === null)
546
494
  return;
547
- const r = b(t);
495
+ const r = m(t);
548
496
  if (!r.touches.every(
549
497
  (h) => C(o, h[0], h[1]) && $(this.window, h[0], h[1])
550
498
  )) {
@@ -562,7 +510,7 @@ class q {
562
510
  this.prevTouches = r;
563
511
  });
564
512
  i(this, "onWindowTouchFinish", (t) => {
565
- t.touches.length > 0 ? this.prevTouches = b(t) : this.stopTouchDrag();
513
+ t.touches.length > 0 ? this.prevTouches = m(t) : this.stopTouchDrag();
566
514
  });
567
515
  i(this, "observer", new ResizeObserver(() => {
568
516
  const t = this.canvas.viewport.getViewportMatrix(), { width: o, height: r } = this.element.getBoundingClientRect(), n = this.options.transformPreprocessor({
@@ -574,7 +522,7 @@ class q {
574
522
  this.options.onResizeTransformStarted(), this.canvas.patchViewportMatrix(n), this.options.onResizeTransformFinished();
575
523
  }));
576
524
  i(this, "options");
577
- this.canvas = t, this.options = gt(o), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph;
525
+ this.canvas = t, this.options = at(o), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph;
578
526
  }
579
527
  attach(t) {
580
528
  this.detach(), this.element = t, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.canvas.attach(this.element);
@@ -622,7 +570,7 @@ class q {
622
570
  this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
623
571
  }
624
572
  moveViewport(t, o, r) {
625
- const n = this.viewport.getViewportMatrix(), h = ut(n, o, r), { width: s, height: c } = t.getBoundingClientRect(), d = this.options.transformPreprocessor({
573
+ const n = this.viewport.getViewportMatrix(), h = lt(n, o, r), { width: s, height: c } = t.getBoundingClientRect(), d = this.options.transformPreprocessor({
626
574
  prevTransform: n,
627
575
  nextTransform: h,
628
576
  canvasWidth: s,
@@ -631,7 +579,7 @@ class q {
631
579
  this.performTransform(d);
632
580
  }
633
581
  scaleViewport(t, o, r, n) {
634
- const h = this.canvas.viewport.getViewportMatrix(), s = wt(h, o, r, n), { width: c, height: d } = t.getBoundingClientRect(), a = this.options.transformPreprocessor({
582
+ const h = this.canvas.viewport.getViewportMatrix(), s = gt(h, o, r, n), { width: c, height: d } = t.getBoundingClientRect(), a = this.options.transformPreprocessor({
635
583
  prevTransform: h,
636
584
  nextTransform: s,
637
585
  canvasWidth: c,
@@ -655,7 +603,7 @@ class q {
655
603
  this.options.onBeforeTransformChange(), this.canvas.patchViewportMatrix(t), this.options.onTransformChange();
656
604
  }
657
605
  }
658
- class yt {
606
+ class ut {
659
607
  constructor() {
660
608
  i(this, "keyMap", /* @__PURE__ */ new Map());
661
609
  i(this, "valueMap", /* @__PURE__ */ new Map());
@@ -692,11 +640,11 @@ class yt {
692
640
  this.keyMap.clear(), this.valueMap.clear();
693
641
  }
694
642
  }
695
- class vt {
643
+ class wt {
696
644
  constructor(t) {
697
645
  i(this, "viewport");
698
646
  i(this, "graph");
699
- i(this, "nodes", new yt());
647
+ i(this, "nodes", new ut());
700
648
  i(this, "nodesResizeObserver");
701
649
  i(this, "window", window);
702
650
  this.canvas = t, this.nodesResizeObserver = new this.window.ResizeObserver((o) => {
@@ -760,7 +708,7 @@ class vt {
760
708
  });
761
709
  }
762
710
  }
763
- class ft {
711
+ class yt {
764
712
  constructor(t, o, r, n) {
765
713
  i(this, "graph");
766
714
  i(this, "viewport");
@@ -807,7 +755,7 @@ class ft {
807
755
  }
808
756
  }
809
757
  };
810
- this.canvas = new q(
758
+ this.canvas = new O(
811
759
  t,
812
760
  c
813
761
  ), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.trigger.subscribe(this.updateLoadedArea);
@@ -871,28 +819,28 @@ class ft {
871
819
  this.trigger.emit({ x: r, y: n, width: h, height: s });
872
820
  }
873
821
  }
874
- const xt = () => {
822
+ const vt = () => {
875
823
  const e = document.createElement("div");
876
824
  return e.style.width = "100%", e.style.height = "100%", e.style.position = "relative", e.style.overflow = "hidden", e;
877
- }, Et = () => {
825
+ }, ft = () => {
878
826
  const e = document.createElement("div");
879
827
  return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.width = "0", e.style.height = "0", e;
880
- }, St = () => {
828
+ }, xt = () => {
881
829
  const e = document.createElement("div");
882
830
  return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.visibility = "hidden", e;
883
831
  };
884
- class At {
832
+ class Et {
885
833
  constructor(t, o) {
886
834
  i(this, "canvasWrapper", null);
887
- i(this, "host", xt());
888
- i(this, "container", Et());
835
+ i(this, "host", vt());
836
+ i(this, "container", ft());
889
837
  i(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
890
838
  i(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
891
839
  i(this, "applyTransform", () => {
892
- const t = this.viewportTransformer.getContentMatrix();
840
+ const t = this.viewportStore.getContentMatrix();
893
841
  this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.x}, ${t.y})`;
894
842
  });
895
- this.graphStore = t, this.viewportTransformer = o, this.host.appendChild(this.container), this.viewportTransformer.onAfterUpdate.subscribe(this.applyTransform);
843
+ this.graphStore = t, this.viewportStore = o, this.host.appendChild(this.container), this.viewportStore.onAfterUpdate.subscribe(this.applyTransform);
896
844
  }
897
845
  attach(t) {
898
846
  this.detach(), this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
@@ -901,20 +849,20 @@ class At {
901
849
  this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
902
850
  }
903
851
  attachNode(t) {
904
- const o = this.graphStore.getNode(t), r = St();
852
+ const o = this.graphStore.getNode(t), r = xt();
905
853
  r.appendChild(o.element), this.container.appendChild(r), this.nodeIdToWrapperElementMap.set(t, r), this.updateNodeCoordinates(t), this.updateNodePriority(t), r.style.visibility = "visible";
906
854
  }
907
855
  detachNode(t) {
908
- const o = this.graphStore.getNode(t), r = this.nodeIdToWrapperElementMap.get(t);
909
- r.removeChild(o.element), this.container.removeChild(r), this.nodeIdToWrapperElementMap.delete(t);
856
+ const o = this.nodeIdToWrapperElementMap.get(t);
857
+ o.removeChild(o.firstChild), this.container.removeChild(o), this.nodeIdToWrapperElementMap.delete(t);
910
858
  }
911
859
  attachEdge(t) {
912
- const o = this.graphStore.getEdge(t);
913
- this.edgeIdToElementMap.set(t, o.shape.svg), this.container.appendChild(o.shape.svg), this.renderEdge(t), this.updateEdgePriority(t);
860
+ const o = this.graphStore.getEdge(t).shape.svg;
861
+ this.edgeIdToElementMap.set(t, o), this.container.appendChild(o), this.renderEdge(t), this.updateEdgePriority(t);
914
862
  }
915
863
  detachEdge(t) {
916
- const o = this.graphStore.getEdge(t);
917
- this.container.removeChild(o.shape.svg), this.edgeIdToElementMap.delete(t);
864
+ const o = this.edgeIdToElementMap.get(t);
865
+ this.container.removeChild(o), this.edgeIdToElementMap.delete(t);
918
866
  }
919
867
  clear() {
920
868
  this.edgeIdToElementMap.forEach((t, o) => {
@@ -924,10 +872,10 @@ class At {
924
872
  });
925
873
  }
926
874
  destroy() {
927
- this.viewportTransformer.onAfterUpdate.unsubscribe(this.applyTransform), this.clear(), this.detach(), this.host.removeChild(this.container);
875
+ this.viewportStore.onAfterUpdate.unsubscribe(this.applyTransform), this.clear(), this.detach(), this.host.removeChild(this.container);
928
876
  }
929
877
  updateNodeCoordinates(t) {
930
- const o = this.nodeIdToWrapperElementMap.get(t), r = this.graphStore.getNode(t), { width: n, height: h } = r.element.getBoundingClientRect(), s = this.viewportTransformer.getViewportMatrix().scale, c = r.centerFn(n, h), d = r.x - s * c.x, a = r.y - s * c.y;
878
+ const o = this.nodeIdToWrapperElementMap.get(t), r = this.graphStore.getNode(t), { width: n, height: h } = r.element.getBoundingClientRect(), s = this.viewportStore.getViewportMatrix().scale, c = r.centerFn(n, h), d = r.x - s * c.x, a = r.y - s * c.y;
931
879
  o.style.transform = `translate(${d}px, ${a}px)`;
932
880
  }
933
881
  updateNodePriority(t) {
@@ -941,7 +889,7 @@ class At {
941
889
  this.edgeIdToElementMap.set(t, r.shape.svg), this.container.appendChild(r.shape.svg);
942
890
  }
943
891
  renderEdge(t) {
944
- const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from), n = this.graphStore.getPort(o.to), h = r.element.getBoundingClientRect(), s = n.element.getBoundingClientRect(), c = this.host.getBoundingClientRect(), d = this.viewportTransformer.getViewportMatrix(), a = {
892
+ const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from), n = this.graphStore.getPort(o.to), h = r.element.getBoundingClientRect(), s = n.element.getBoundingClientRect(), c = this.host.getBoundingClientRect(), d = this.viewportStore.getViewportMatrix(), a = {
945
893
  x: d.scale * (h.left - c.left) + d.x,
946
894
  y: d.scale * (h.top - c.top) + d.y
947
895
  }, l = {
@@ -954,7 +902,7 @@ class At {
954
902
  height: h.height * d.scale,
955
903
  direction: r.direction,
956
904
  portId: o.from,
957
- nodeId: this.graphStore.getPortNodeId(o.from)
905
+ nodeId: r.nodeId
958
906
  }, y = {
959
907
  x: l.x,
960
908
  y: l.y,
@@ -962,7 +910,7 @@ class At {
962
910
  height: s.height * d.scale,
963
911
  direction: n.direction,
964
912
  portId: o.to,
965
- nodeId: this.graphStore.getPortNodeId(o.to)
913
+ nodeId: n.nodeId
966
914
  };
967
915
  o.shape.render({
968
916
  from: g,
@@ -974,7 +922,7 @@ class At {
974
922
  o.shape.svg.style.zIndex = `${o.priority}`;
975
923
  }
976
924
  }
977
- class Tt {
925
+ class St {
978
926
  constructor(t) {
979
927
  i(this, "xFrom", 1 / 0);
980
928
  i(this, "yFrom", 1 / 0);
@@ -990,11 +938,11 @@ class Tt {
990
938
  return o.x >= this.xFrom && o.x <= this.xTo && o.y >= this.yFrom && o.y <= this.yTo;
991
939
  }
992
940
  hasEdge(t) {
993
- const o = this.graphStore.getEdge(t), r = this.graphStore.getPortNodeId(o.from), n = this.graphStore.getPortNodeId(o.to), h = this.graphStore.getNode(r), s = this.graphStore.getNode(n), c = Math.min(h.x, s.x), d = Math.max(h.x, s.x), a = Math.min(h.y, s.y), l = Math.max(h.y, s.y);
941
+ const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from).nodeId, n = this.graphStore.getPort(o.to).nodeId, h = this.graphStore.getNode(r), s = this.graphStore.getNode(n), c = Math.min(h.x, s.x), d = Math.max(h.x, s.x), a = Math.min(h.y, s.y), l = Math.max(h.y, s.y);
994
942
  return c <= this.xTo && d >= this.xFrom && a <= this.yTo && l >= this.yFrom;
995
943
  }
996
944
  }
997
- class pt {
945
+ class At {
998
946
  constructor(t, o, r) {
999
947
  i(this, "attachedNodes", /* @__PURE__ */ new Set());
1000
948
  i(this, "attachedEdges", /* @__PURE__ */ new Set());
@@ -1006,7 +954,7 @@ class pt {
1006
954
  const c = this.renderingBox.hasNode(s), d = this.attachedNodes.has(s);
1007
955
  c && !d ? o.add(s) : !c && d && r.add(s);
1008
956
  }), this.graphStore.getAllEdgeIds().forEach((s) => {
1009
- const c = this.renderingBox.hasEdge(s), d = this.attachedEdges.has(s), a = this.graphStore.getEdge(s), l = this.graphStore.getPortNodeId(a.from), g = this.graphStore.getPortNodeId(a.to);
957
+ const c = this.renderingBox.hasEdge(s), d = this.attachedEdges.has(s), a = this.graphStore.getEdge(s), l = this.graphStore.getPort(a.from).nodeId, g = this.graphStore.getPort(a.to).nodeId;
1010
958
  c && (this.renderingBox.hasNode(l) || (o.add(l), r.delete(l)), this.renderingBox.hasNode(g) || (o.add(g), r.delete(g))), c && !d ? n.add(s) : !c && d && h.add(s);
1011
959
  }), h.forEach((s) => {
1012
960
  this.handleDetachEdge(s);
@@ -1018,7 +966,7 @@ class pt {
1018
966
  this.handleAttachEdge(s);
1019
967
  });
1020
968
  });
1021
- this.htmlView = t, this.graphStore = o, this.trigger = r, this.renderingBox = new Tt(this.graphStore), this.trigger.subscribe(this.updateViewport);
969
+ this.htmlView = t, this.graphStore = o, this.trigger = r, this.renderingBox = new St(this.graphStore), this.trigger.subscribe(this.updateViewport);
1022
970
  }
1023
971
  attach(t) {
1024
972
  this.htmlView.attach(t);
@@ -1062,7 +1010,7 @@ class pt {
1062
1010
  this.clear(), this.htmlView.destroy(), this.trigger.unsubscribe(this.updateViewport);
1063
1011
  }
1064
1012
  attachEdgeEntities(t) {
1065
- const o = this.graphStore.getEdge(t), r = this.graphStore.getPortNodeId(o.from), n = this.graphStore.getPortNodeId(o.to);
1013
+ const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from).nodeId, n = this.graphStore.getPort(o.to).nodeId;
1066
1014
  this.attachedNodes.has(r) || this.handleAttachNode(r), this.attachedNodes.has(n) || this.handleAttachNode(n), this.handleAttachEdge(t);
1067
1015
  }
1068
1016
  handleAttachNode(t) {
@@ -1078,6 +1026,26 @@ class pt {
1078
1026
  this.htmlView.detachEdge(t), this.attachedEdges.delete(t);
1079
1027
  }
1080
1028
  }
1029
+ class q {
1030
+ constructor() {
1031
+ i(this, "callbacks", /* @__PURE__ */ new Set());
1032
+ }
1033
+ subscribe(t) {
1034
+ this.callbacks.add(t);
1035
+ }
1036
+ unsubscribe(t) {
1037
+ this.callbacks.delete(t);
1038
+ }
1039
+ emit(t) {
1040
+ this.callbacks.forEach((o) => {
1041
+ o(t);
1042
+ });
1043
+ }
1044
+ }
1045
+ const Tt = () => {
1046
+ const e = new q();
1047
+ return [e, e];
1048
+ };
1081
1049
  class Y {
1082
1050
  constructor(t) {
1083
1051
  i(this, "counter", 0);
@@ -1100,14 +1068,14 @@ class E extends Error {
1100
1068
  i(this, "name", "HtmlGraphError");
1101
1069
  }
1102
1070
  }
1103
- const Nt = (e, t) => ({
1071
+ const pt = (e, t) => ({
1104
1072
  x: e / 2,
1105
1073
  y: t / 2
1106
- }), X = (e) => () => e, Z = X(0), Mt = () => {
1074
+ }), X = (e) => () => e, J = X(0), Mt = () => {
1107
1075
  let e = 0;
1108
1076
  return () => e++;
1109
- }, Vt = (e, t) => {
1110
- let o = Z, r = Z;
1077
+ }, Nt = (e, t) => {
1078
+ let o = J, r = J;
1111
1079
  const n = Mt();
1112
1080
  return e === "incremental" && (o = n), t === "incremental" && (r = n), typeof e == "number" && (o = X(e)), typeof t == "number" && (r = X(t)), typeof e == "function" && (o = e), typeof t == "function" && (r = t), {
1113
1081
  nodesPriorityFn: o,
@@ -1119,14 +1087,14 @@ const Nt = (e, t) => ({
1119
1087
  }), p = (e, t, o) => ({ x: t * Math.cos(e), y: o * Math.sin(e) }), w = {
1120
1088
  x: 0,
1121
1089
  y: 0
1122
- }, N = (e, t, o, r) => {
1090
+ }, M = (e, t, o, r) => {
1123
1091
  const h = [
1124
1092
  w,
1125
1093
  { x: o, y: r },
1126
1094
  { x: o, y: -r }
1127
1095
  ].map((a) => f(a, e, w)).map((a) => ({ x: a.x + t.x, y: a.y + t.y })), s = `M ${h[0].x} ${h[0].y}`, c = `L ${h[1].x} ${h[1].y}`, d = `L ${h[2].x} ${h[2].y}`;
1128
1096
  return `${s} ${c} ${d}`;
1129
- }, D = (e, t) => {
1097
+ }, b = (e, t) => {
1130
1098
  const o = [];
1131
1099
  if (e.length > 0 && o.push(`M ${e[0].x} ${e[0].y}`), e.length === 2 && o.push(`L ${e[1].x} ${e[1].y}`), e.length > 2) {
1132
1100
  const r = e.length - 1;
@@ -1135,26 +1103,26 @@ const Nt = (e, t) => ({
1135
1103
  let a = 0, l = 0, g = 0;
1136
1104
  const y = d > 0, x = d < r, v = y && x;
1137
1105
  if (y && (a = -n, l = -h, g = s), x) {
1138
- const m = e[d + 1];
1139
- n = m.x - c.x, h = m.y - c.y, s = Math.sqrt(n * n + h * h);
1106
+ const P = e[d + 1];
1107
+ n = P.x - c.x, h = P.y - c.y, s = Math.sqrt(n * n + h * h);
1140
1108
  }
1141
- const S = s !== 0 ? Math.min((v ? t : 0) / s, d < r - 1 ? 0.5 : 1) : 0, T = v ? { x: c.x + n * S, y: c.y + h * S } : c, P = g !== 0 ? Math.min((v ? t : 0) / g, d > 1 ? 0.5 : 1) : 0, L = v ? { x: c.x + a * P, y: c.y + l * P } : c;
1142
- d > 0 && o.push(`L ${L.x} ${L.y}`), v && o.push(
1109
+ const S = s !== 0 ? Math.min((v ? t : 0) / s, d < r - 1 ? 0.5 : 1) : 0, T = v ? { x: c.x + n * S, y: c.y + h * S } : c, L = g !== 0 ? Math.min((v ? t : 0) / g, d > 1 ? 0.5 : 1) : 0, D = v ? { x: c.x + a * L, y: c.y + l * L } : c;
1110
+ d > 0 && o.push(`L ${D.x} ${D.y}`), v && o.push(
1143
1111
  `C ${c.x} ${c.y} ${c.x} ${c.y} ${T.x} ${T.y}`
1144
1112
  );
1145
1113
  });
1146
1114
  }
1147
1115
  return o.join(" ");
1148
- }, F = () => {
1116
+ }, I = () => {
1149
1117
  const e = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1150
1118
  return e.style.pointerEvents = "none", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.overflow = "visible", e;
1151
- }, I = () => {
1119
+ }, F = () => {
1152
1120
  const e = document.createElementNS("http://www.w3.org/2000/svg", "g");
1153
1121
  return e.style.transformOrigin = "50% 50%", e;
1154
1122
  }, R = (e, t) => {
1155
1123
  const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1156
1124
  return o.setAttribute("stroke", e), o.setAttribute("stroke-width", `${t}`), o.setAttribute("fill", "none"), o;
1157
- }, M = (e) => {
1125
+ }, N = (e) => {
1158
1126
  const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
1159
1127
  return t.setAttribute("fill", e), t;
1160
1128
  }, k = (e, t) => {
@@ -1173,7 +1141,7 @@ const Nt = (e, t) => ({
1173
1141
  flipX: d,
1174
1142
  flipY: a
1175
1143
  };
1176
- }, Pt = (e) => {
1144
+ }, Vt = (e) => {
1177
1145
  const t = f(
1178
1146
  { x: e.arrowLength, y: w.y },
1179
1147
  e.fromVect,
@@ -1233,7 +1201,7 @@ const Nt = (e, t) => ({
1233
1201
  `C ${S.x} ${S.y} ${v.x} ${v.y} ${l.x} ${l.y}`,
1234
1202
  `L ${o.x} ${o.y}`
1235
1203
  ].join(" ");
1236
- }, mt = (e) => {
1204
+ }, Dt = (e) => {
1237
1205
  const t = e.hasSourceArrow ? f(
1238
1206
  { x: e.arrowLength, y: w.y },
1239
1207
  e.fromVect,
@@ -1250,7 +1218,7 @@ const Nt = (e, t) => ({
1250
1218
  x: e.flipX > 0 ? e.to.x - c : e.to.x + r,
1251
1219
  y: s.y
1252
1220
  }, y = { x: g.x, y: d };
1253
- return D(
1221
+ return b(
1254
1222
  [t, h, a, l, y, g, s, o],
1255
1223
  e.roundness
1256
1224
  );
@@ -1272,11 +1240,11 @@ const Nt = (e, t) => ({
1272
1240
  e.toVect,
1273
1241
  e.to
1274
1242
  ), g = { x: l.x + c, y: l.y + d };
1275
- return D(
1243
+ return b(
1276
1244
  [t, n, a, g, l, o],
1277
1245
  e.roundness
1278
1246
  );
1279
- }, Dt = (e) => {
1247
+ }, Pt = (e) => {
1280
1248
  const t = e.hasSourceArrow ? f(
1281
1249
  { x: e.arrowLength, y: w.y },
1282
1250
  e.fromVect,
@@ -1290,7 +1258,7 @@ const Nt = (e, t) => ({
1290
1258
  e.toVect,
1291
1259
  e.to
1292
1260
  );
1293
- return D([t, n, h, o], e.roundness);
1261
+ return b([t, n, h, o], e.roundness);
1294
1262
  }, bt = (e) => {
1295
1263
  const t = e.hasSourceArrow ? f(
1296
1264
  { x: e.arrowLength, y: w.y },
@@ -1308,7 +1276,7 @@ const Nt = (e, t) => ({
1308
1276
  x: s.x,
1309
1277
  y: e.flipY > 0 ? e.to.y - c : e.to.y + r
1310
1278
  }, y = { x: d, y: g.y };
1311
- return D(
1279
+ return b(
1312
1280
  [t, h, a, l, y, g, s, o],
1313
1281
  e.roundness
1314
1282
  );
@@ -1325,8 +1293,8 @@ const Nt = (e, t) => ({
1325
1293
  ].map(
1326
1294
  (d) => f(d, e.fromVect, w)
1327
1295
  ), c = `M ${w.x} ${w.y} L ${s[0].x} ${s[0].y} `;
1328
- return `${e.hasSourceArrow || e.hasTargetArrow ? "" : c}${D(s, e.roundness)}`;
1329
- }, Ct = (e) => {
1296
+ return `${e.hasSourceArrow || e.hasTargetArrow ? "" : c}${b(s, e.roundness)}`;
1297
+ }, mt = (e) => {
1330
1298
  const t = e.smallRadius, o = e.radius, r = Math.sqrt(t * t + o * o), n = t + o, h = e.arrowLength + r * (1 - o / n), s = t * o / n, d = [
1331
1299
  { x: e.arrowLength, y: w.y },
1332
1300
  { x: h, y: s },
@@ -1355,10 +1323,10 @@ const Nt = (e, t) => ({
1355
1323
  smallCycleRadius: 15,
1356
1324
  curvature: 90
1357
1325
  });
1358
- class $t {
1326
+ class Ct {
1359
1327
  constructor(t) {
1360
- i(this, "svg", F());
1361
- i(this, "group", I());
1328
+ i(this, "svg", I());
1329
+ i(this, "group", F());
1362
1330
  i(this, "line");
1363
1331
  i(this, "sourceArrow", null);
1364
1332
  i(this, "targetArrow", null);
@@ -1373,7 +1341,7 @@ class $t {
1373
1341
  i(this, "hasTargetArrow");
1374
1342
  this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? u.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? u.arrowWidth, this.curvature = (t == null ? void 0 : t.curvature) ?? u.curvature, this.portCycleRadius = (t == null ? void 0 : t.cycleRadius) ?? u.cycleRadius, this.portCycleSmallRadius = (t == null ? void 0 : t.smallCycleRadius) ?? u.smallCycleRadius, this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? u.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? u.hasTargetArrow;
1375
1343
  const o = (t == null ? void 0 : t.color) ?? u.color, r = (t == null ? void 0 : t.width) ?? u.width;
1376
- this.svg.appendChild(this.group), this.line = R(o, r), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = M(o), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = M(o), this.group.appendChild(this.targetArrow));
1344
+ this.svg.appendChild(this.group), this.line = R(o, r), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(o), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(o), this.group.appendChild(this.targetArrow));
1377
1345
  }
1378
1346
  render(t) {
1379
1347
  const { x: o, y: r, width: n, height: h, flipX: s, flipY: c } = k(
@@ -1390,7 +1358,7 @@ class $t {
1390
1358
  y: h
1391
1359
  };
1392
1360
  let g, y = a, x = -this.arrowLength;
1393
- if (t.from.portId === t.to.portId ? (g = Ct({
1361
+ if (t.from.portId === t.to.portId ? (g = mt({
1394
1362
  fromVect: d,
1395
1363
  radius: this.portCycleRadius,
1396
1364
  smallRadius: this.portCycleSmallRadius,
@@ -1409,7 +1377,7 @@ class $t {
1409
1377
  curvature: this.curvature,
1410
1378
  hasSourceArrow: this.hasSourceArrow,
1411
1379
  hasTargetArrow: this.hasTargetArrow
1412
- }) : g = Pt({
1380
+ }) : g = Vt({
1413
1381
  to: l,
1414
1382
  fromVect: d,
1415
1383
  toVect: a,
@@ -1418,7 +1386,7 @@ class $t {
1418
1386
  hasSourceArrow: this.hasSourceArrow,
1419
1387
  hasTargetArrow: this.hasTargetArrow
1420
1388
  }), this.line.setAttribute("d", g), this.sourceArrow) {
1421
- const v = N(
1389
+ const v = M(
1422
1390
  d,
1423
1391
  w,
1424
1392
  this.arrowLength,
@@ -1427,7 +1395,7 @@ class $t {
1427
1395
  this.sourceArrow.setAttribute("d", v);
1428
1396
  }
1429
1397
  if (this.targetArrow) {
1430
- const v = N(
1398
+ const v = M(
1431
1399
  y,
1432
1400
  l,
1433
1401
  x,
@@ -1437,10 +1405,10 @@ class $t {
1437
1405
  }
1438
1406
  }
1439
1407
  }
1440
- class Wt {
1408
+ class $t {
1441
1409
  constructor(t) {
1442
- i(this, "svg", F());
1443
- i(this, "group", I());
1410
+ i(this, "svg", I());
1411
+ i(this, "group", F());
1444
1412
  i(this, "line");
1445
1413
  i(this, "sourceArrow", null);
1446
1414
  i(this, "targetArrow", null);
@@ -1461,7 +1429,7 @@ class Wt {
1461
1429
  this.cycleSquareSide / 2
1462
1430
  ), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? u.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? u.hasTargetArrow;
1463
1431
  const r = (t == null ? void 0 : t.color) ?? u.color, n = (t == null ? void 0 : t.width) ?? u.width;
1464
- this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = M(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = M(r), this.group.appendChild(this.targetArrow));
1432
+ this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
1465
1433
  }
1466
1434
  render(t) {
1467
1435
  const { x: o, y: r, width: n, height: h, flipX: s, flipY: c } = k(
@@ -1499,7 +1467,7 @@ class Wt {
1499
1467
  detourDistance: this.detourDistance,
1500
1468
  hasSourceArrow: this.hasSourceArrow,
1501
1469
  hasTargetArrow: this.hasTargetArrow
1502
- }) : g = mt({
1470
+ }) : g = Dt({
1503
1471
  to: l,
1504
1472
  fromVect: d,
1505
1473
  toVect: a,
@@ -1510,7 +1478,7 @@ class Wt {
1510
1478
  hasSourceArrow: this.hasSourceArrow,
1511
1479
  hasTargetArrow: this.hasTargetArrow
1512
1480
  }), this.line.setAttribute("d", g), this.sourceArrow) {
1513
- const v = N(
1481
+ const v = M(
1514
1482
  d,
1515
1483
  w,
1516
1484
  this.arrowLength,
@@ -1519,7 +1487,7 @@ class Wt {
1519
1487
  this.sourceArrow.setAttribute("d", v);
1520
1488
  }
1521
1489
  if (this.targetArrow) {
1522
- const v = N(
1490
+ const v = M(
1523
1491
  y,
1524
1492
  l,
1525
1493
  x,
@@ -1529,10 +1497,10 @@ class Wt {
1529
1497
  }
1530
1498
  }
1531
1499
  }
1532
- class Ft {
1500
+ class Wt {
1533
1501
  constructor(t) {
1534
- i(this, "svg", F());
1535
- i(this, "group", I());
1502
+ i(this, "svg", I());
1503
+ i(this, "group", F());
1536
1504
  i(this, "line");
1537
1505
  i(this, "sourceArrow", null);
1538
1506
  i(this, "targetArrow", null);
@@ -1553,7 +1521,7 @@ class Ft {
1553
1521
  this.cycleSquareSide / 2
1554
1522
  ), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? u.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? u.hasTargetArrow;
1555
1523
  const r = (t == null ? void 0 : t.color) ?? u.color, n = (t == null ? void 0 : t.width) ?? u.width;
1556
- this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = M(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = M(r), this.group.appendChild(this.targetArrow));
1524
+ this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
1557
1525
  }
1558
1526
  render(t) {
1559
1527
  const { x: o, y: r, width: n, height: h, flipX: s, flipY: c } = k(
@@ -1591,7 +1559,7 @@ class Ft {
1591
1559
  detourDistance: this.detourDistance,
1592
1560
  hasSourceArrow: this.hasSourceArrow,
1593
1561
  hasTargetArrow: this.hasTargetArrow
1594
- }) : g = Dt({
1562
+ }) : g = Pt({
1595
1563
  to: l,
1596
1564
  fromVect: d,
1597
1565
  toVect: a,
@@ -1601,7 +1569,7 @@ class Ft {
1601
1569
  hasSourceArrow: this.hasSourceArrow,
1602
1570
  hasTargetArrow: this.hasTargetArrow
1603
1571
  }), this.line.setAttribute("d", g), this.sourceArrow) {
1604
- const v = N(
1572
+ const v = M(
1605
1573
  d,
1606
1574
  w,
1607
1575
  this.arrowLength,
@@ -1610,7 +1578,7 @@ class Ft {
1610
1578
  this.sourceArrow.setAttribute("d", v);
1611
1579
  }
1612
1580
  if (this.targetArrow) {
1613
- const v = N(
1581
+ const v = M(
1614
1582
  y,
1615
1583
  l,
1616
1584
  x,
@@ -1622,8 +1590,8 @@ class Ft {
1622
1590
  }
1623
1591
  class It {
1624
1592
  constructor(t) {
1625
- i(this, "svg", F());
1626
- i(this, "group", I());
1593
+ i(this, "svg", I());
1594
+ i(this, "group", F());
1627
1595
  i(this, "line");
1628
1596
  i(this, "sourceArrow", null);
1629
1597
  i(this, "targetArrow", null);
@@ -1644,7 +1612,7 @@ class It {
1644
1612
  this.cycleSquareSide / 2
1645
1613
  ), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? u.detourDirectionVertical, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? u.hasTargetArrow;
1646
1614
  const r = (t == null ? void 0 : t.color) ?? u.color, n = (t == null ? void 0 : t.width) ?? u.width;
1647
- this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = M(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = M(r), this.group.appendChild(this.targetArrow));
1615
+ this.svg.appendChild(this.group), this.line = R(r, n), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
1648
1616
  }
1649
1617
  render(t) {
1650
1618
  const { x: o, y: r, width: n, height: h, flipX: s, flipY: c } = k(
@@ -1693,7 +1661,7 @@ class It {
1693
1661
  hasSourceArrow: this.hasSourceArrow,
1694
1662
  hasTargetArrow: this.hasTargetArrow
1695
1663
  }), this.line.setAttribute("d", g), this.sourceArrow) {
1696
- const v = N(
1664
+ const v = M(
1697
1665
  d,
1698
1666
  w,
1699
1667
  this.arrowLength,
@@ -1702,7 +1670,7 @@ class It {
1702
1670
  this.sourceArrow.setAttribute("d", v);
1703
1671
  }
1704
1672
  if (this.targetArrow) {
1705
- const v = N(
1673
+ const v = M(
1706
1674
  y,
1707
1675
  l,
1708
1676
  x,
@@ -1712,12 +1680,12 @@ class It {
1712
1680
  }
1713
1681
  }
1714
1682
  }
1715
- const Rt = (e) => {
1683
+ const Ft = (e) => {
1716
1684
  if (typeof e == "function")
1717
1685
  return e;
1718
1686
  switch (e == null ? void 0 : e.type) {
1719
1687
  case "straight":
1720
- return () => new Ft({
1688
+ return () => new Wt({
1721
1689
  color: e.color,
1722
1690
  width: e.width,
1723
1691
  arrowLength: e.arrowLength,
@@ -1731,7 +1699,7 @@ const Rt = (e) => {
1731
1699
  detourDirection: e.detourDirection
1732
1700
  });
1733
1701
  case "horizontal":
1734
- return () => new Wt({
1702
+ return () => new $t({
1735
1703
  color: e.color,
1736
1704
  width: e.width,
1737
1705
  arrowLength: e.arrowLength,
@@ -1759,7 +1727,7 @@ const Rt = (e) => {
1759
1727
  detourDirection: e.detourDirection
1760
1728
  });
1761
1729
  default:
1762
- return () => new $t({
1730
+ return () => new Ct({
1763
1731
  color: e.color,
1764
1732
  width: e.width,
1765
1733
  arrowLength: e.arrowLength,
@@ -1773,27 +1741,27 @@ const Rt = (e) => {
1773
1741
  detourDirection: e.detourDirection
1774
1742
  });
1775
1743
  }
1776
- }, kt = (e) => {
1744
+ }, Rt = (e) => {
1777
1745
  var o, r, n, h, s;
1778
- const t = Vt(
1746
+ const t = Nt(
1779
1747
  (o = e == null ? void 0 : e.nodes) == null ? void 0 : o.priority,
1780
1748
  (r = e == null ? void 0 : e.edges) == null ? void 0 : r.priority
1781
1749
  );
1782
1750
  return {
1783
1751
  nodes: {
1784
- centerFn: ((n = e == null ? void 0 : e.nodes) == null ? void 0 : n.centerFn) ?? Nt,
1752
+ centerFn: ((n = e == null ? void 0 : e.nodes) == null ? void 0 : n.centerFn) ?? pt,
1785
1753
  priorityFn: t.nodesPriorityFn
1786
1754
  },
1787
1755
  ports: {
1788
1756
  direction: ((h = e == null ? void 0 : e.ports) == null ? void 0 : h.direction) ?? 0
1789
1757
  },
1790
1758
  edges: {
1791
- shapeFactory: Rt(((s = e == null ? void 0 : e.edges) == null ? void 0 : s.shape) ?? {}),
1759
+ shapeFactory: Ft(((s = e == null ? void 0 : e.edges) == null ? void 0 : s.shape) ?? {}),
1792
1760
  priorityFn: t.edgesPriorityFn
1793
1761
  }
1794
1762
  };
1795
1763
  };
1796
- class zt {
1764
+ class kt {
1797
1765
  constructor(t, o) {
1798
1766
  i(this, "nodeIdGenerator", new Y(
1799
1767
  (t) => this.graph.getNode(t) !== null
@@ -1813,7 +1781,7 @@ class zt {
1813
1781
  * provides api for accessing viewport state
1814
1782
  */
1815
1783
  i(this, "viewport");
1816
- this.controller = t, this.defaults = kt(o), this.graph = t.graph, this.viewport = t.viewport;
1784
+ this.controller = t, this.defaults = Rt(o), this.graph = t.graph, this.viewport = t.viewport;
1817
1785
  }
1818
1786
  /**
1819
1787
  * attaches canvas to given element
@@ -1835,21 +1803,22 @@ class zt {
1835
1803
  const o = this.nodeIdGenerator.create(t.id);
1836
1804
  if (this.graph.getNode(o) !== null)
1837
1805
  throw new E("failed to add node with existing id");
1838
- return this.controller.addNode({
1806
+ if (this.controller.addNode({
1839
1807
  id: o,
1840
1808
  element: t.element,
1841
1809
  x: t.x,
1842
1810
  y: t.y,
1843
1811
  centerFn: t.centerFn ?? this.defaults.nodes.centerFn,
1844
1812
  priority: t.priority ?? this.defaults.nodes.priorityFn()
1845
- }), Array.from(t.ports ?? []).forEach((r) => {
1846
- this.markPort({
1847
- id: r.id,
1848
- element: r.element,
1849
- nodeId: o,
1850
- direction: r.direction
1851
- });
1852
- }), this;
1813
+ }), t.ports !== void 0)
1814
+ for (const r of t.ports)
1815
+ this.markPort({
1816
+ id: r.id,
1817
+ element: r.element,
1818
+ nodeId: o,
1819
+ direction: r.direction
1820
+ });
1821
+ return this;
1853
1822
  }
1854
1823
  /**
1855
1824
  * updates node parameters
@@ -1964,25 +1933,25 @@ class zt {
1964
1933
  this.controller.destroy();
1965
1934
  }
1966
1935
  }
1967
- class Yt {
1936
+ class zt {
1968
1937
  constructor() {
1969
1938
  i(this, "nodes", /* @__PURE__ */ new Map());
1970
1939
  i(this, "ports", /* @__PURE__ */ new Map());
1971
- i(this, "nodePorts", /* @__PURE__ */ new Map());
1972
- i(this, "portNodeId", /* @__PURE__ */ new Map());
1973
1940
  i(this, "edges", /* @__PURE__ */ new Map());
1974
1941
  i(this, "incommingEdges", /* @__PURE__ */ new Map());
1975
1942
  i(this, "outcommingEdges", /* @__PURE__ */ new Map());
1976
1943
  i(this, "cycleEdges", /* @__PURE__ */ new Map());
1977
1944
  }
1978
1945
  addNode(t) {
1979
- this.nodes.set(t.id, {
1946
+ const o = /* @__PURE__ */ new Map(), r = {
1980
1947
  element: t.element,
1981
1948
  x: t.x,
1982
1949
  y: t.y,
1983
1950
  centerFn: t.centerFn,
1984
- priority: t.priority
1985
- }), this.nodePorts.set(t.id, /* @__PURE__ */ new Map());
1951
+ priority: t.priority,
1952
+ ports: o
1953
+ };
1954
+ this.nodes.set(t.id, r);
1986
1955
  }
1987
1956
  getAllNodeIds() {
1988
1957
  return Array.from(this.nodes.keys());
@@ -1991,13 +1960,14 @@ class Yt {
1991
1960
  return this.nodes.get(t);
1992
1961
  }
1993
1962
  removeNode(t) {
1994
- this.nodes.delete(t), this.nodePorts.delete(t);
1963
+ this.nodes.delete(t);
1995
1964
  }
1996
1965
  addPort(t) {
1997
1966
  this.ports.set(t.id, {
1998
1967
  element: t.element,
1999
- direction: t.direction
2000
- }), this.cycleEdges.set(t.id, /* @__PURE__ */ new Set()), this.incommingEdges.set(t.id, /* @__PURE__ */ new Set()), this.outcommingEdges.set(t.id, /* @__PURE__ */ new Set()), this.portNodeId.set(t.id, t.nodeId), this.nodePorts.get(t.nodeId).set(t.id, t.element);
1968
+ direction: t.direction,
1969
+ nodeId: t.nodeId
1970
+ }), this.cycleEdges.set(t.id, /* @__PURE__ */ new Set()), this.incommingEdges.set(t.id, /* @__PURE__ */ new Set()), this.outcommingEdges.set(t.id, /* @__PURE__ */ new Set()), this.nodes.get(t.nodeId).ports.set(t.id, t.element);
2001
1971
  }
2002
1972
  getPort(t) {
2003
1973
  return this.ports.get(t);
@@ -2006,16 +1976,13 @@ class Yt {
2006
1976
  return Array.from(this.ports.keys());
2007
1977
  }
2008
1978
  getNodePortIds(t) {
2009
- const o = this.nodePorts.get(t);
1979
+ const o = this.nodes.get(t);
2010
1980
  if (o !== void 0)
2011
- return Array.from(o.keys());
2012
- }
2013
- getPortNodeId(t) {
2014
- return this.portNodeId.get(t);
1981
+ return Array.from(o.ports.keys());
2015
1982
  }
2016
1983
  removePort(t) {
2017
- const o = this.portNodeId.get(t);
2018
- this.portNodeId.delete(t), this.nodePorts.get(o).delete(t), this.ports.delete(t);
1984
+ const o = this.ports.get(t).nodeId;
1985
+ this.nodes.get(o).ports.delete(t), this.ports.delete(t);
2019
1986
  }
2020
1987
  addEdge(t) {
2021
1988
  this.edges.set(t.id, {
@@ -2056,7 +2023,7 @@ class Yt {
2056
2023
  this.cycleEdges.get(r).delete(t), this.cycleEdges.get(n).delete(t), this.incommingEdges.get(r).delete(t), this.incommingEdges.get(n).delete(t), this.outcommingEdges.get(r).delete(t), this.outcommingEdges.get(n).delete(t), this.edges.delete(t);
2057
2024
  }
2058
2025
  clear() {
2059
- this.edges.clear(), this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear(), this.ports.clear(), this.nodePorts.clear(), this.portNodeId.clear(), this.nodes.clear();
2026
+ this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear(), this.edges.clear(), this.ports.clear(), this.nodes.clear();
2060
2027
  }
2061
2028
  getPortIncomingEdgeIds(t) {
2062
2029
  return Array.from(this.incommingEdges.get(t));
@@ -2075,21 +2042,21 @@ class Yt {
2075
2042
  ];
2076
2043
  }
2077
2044
  getNodeIncomingEdgeIds(t) {
2078
- const o = Array.from(this.nodePorts.get(t).keys());
2045
+ const o = Array.from(this.nodes.get(t).ports.keys());
2079
2046
  let r = [];
2080
2047
  return o.forEach((n) => {
2081
2048
  r = [...r, ...this.getPortIncomingEdgeIds(n)];
2082
2049
  }), r;
2083
2050
  }
2084
2051
  getNodeOutcomingEdgeIds(t) {
2085
- const o = Array.from(this.nodePorts.get(t).keys());
2052
+ const o = Array.from(this.nodes.get(t).ports.keys());
2086
2053
  let r = [];
2087
2054
  return o.forEach((n) => {
2088
2055
  r = [...r, ...this.getPortOutcomingEdgeIds(n)];
2089
2056
  }), r;
2090
2057
  }
2091
2058
  getNodeCycleEdgeIds(t) {
2092
- const o = Array.from(this.nodePorts.get(t).keys());
2059
+ const o = Array.from(this.nodes.get(t).ports.keys());
2093
2060
  let r = [];
2094
2061
  return o.forEach((n) => {
2095
2062
  r = [...r, ...this.getPortCycleEdgeIds(n)];
@@ -2103,6 +2070,44 @@ class Yt {
2103
2070
  ];
2104
2071
  }
2105
2072
  }
2073
+ const Q = (e) => ({
2074
+ scale: 1 / e.scale,
2075
+ x: -e.x / e.scale,
2076
+ y: -e.y / e.scale
2077
+ }), Z = {
2078
+ scale: 1,
2079
+ x: 0,
2080
+ y: 0
2081
+ };
2082
+ class Yt {
2083
+ constructor() {
2084
+ i(this, "viewportMatrix", Z);
2085
+ i(this, "contentMatrix", Z);
2086
+ i(this, "emitter");
2087
+ i(this, "onAfterUpdate");
2088
+ [this.emitter, this.onAfterUpdate] = Tt();
2089
+ }
2090
+ getViewportMatrix() {
2091
+ return this.viewportMatrix;
2092
+ }
2093
+ getContentMatrix() {
2094
+ return this.contentMatrix;
2095
+ }
2096
+ patchViewportMatrix(t) {
2097
+ this.viewportMatrix = {
2098
+ scale: t.scale ?? this.viewportMatrix.scale,
2099
+ x: t.x ?? this.viewportMatrix.x,
2100
+ y: t.y ?? this.viewportMatrix.y
2101
+ }, this.contentMatrix = Q(this.viewportMatrix), this.emitter.emit();
2102
+ }
2103
+ patchContentMatrix(t) {
2104
+ this.contentMatrix = {
2105
+ scale: t.scale ?? this.contentMatrix.scale,
2106
+ x: t.x ?? this.contentMatrix.x,
2107
+ y: t.y ?? this.contentMatrix.y
2108
+ }, this.viewportMatrix = Q(this.contentMatrix), this.emitter.emit();
2109
+ }
2110
+ }
2106
2111
  class Bt {
2107
2112
  constructor() {
2108
2113
  i(this, "canvasDefaults", {});
@@ -2159,28 +2164,28 @@ class Bt {
2159
2164
  */
2160
2165
  build() {
2161
2166
  let t = this.boxRenderingTrigger;
2162
- this.virtualScrollOptions !== void 0 && t === void 0 && (t = new O());
2163
- const o = new Yt(), r = new rt();
2164
- let n = new At(o, r);
2165
- t !== void 0 && (n = new pt(n, o, t));
2166
- let h = new nt(
2167
+ this.virtualScrollOptions !== void 0 && t === void 0 && (t = new q());
2168
+ const o = new zt(), r = new Yt();
2169
+ let n = new Et(o, r);
2170
+ t !== void 0 && (n = new At(n, o, t));
2171
+ let h = new it(
2167
2172
  o,
2168
2173
  r,
2169
2174
  n
2170
2175
  );
2171
- this.hasResizeReactiveNodes && (h = new vt(h)), this.hasDraggableNode && (h = new ct(
2176
+ this.hasResizeReactiveNodes && (h = new wt(h)), this.hasDraggableNode && (h = new nt(
2172
2177
  h,
2173
2178
  this.dragOptions
2174
- )), this.virtualScrollOptions !== void 0 ? h = new ft(
2179
+ )), this.virtualScrollOptions !== void 0 ? h = new yt(
2175
2180
  h,
2176
2181
  t,
2177
2182
  this.transformOptions,
2178
2183
  this.virtualScrollOptions
2179
- ) : this.hasTransformableViewport && (h = new q(
2184
+ ) : this.hasTransformableViewport && (h = new O(
2180
2185
  h,
2181
2186
  this.transformOptions
2182
2187
  ));
2183
- const s = new zt(h, this.canvasDefaults);
2188
+ const s = new kt(h, this.canvasDefaults);
2184
2189
  return this.reset(), s;
2185
2190
  }
2186
2191
  reset() {
@@ -2188,11 +2193,11 @@ class Bt {
2188
2193
  }
2189
2194
  }
2190
2195
  export {
2191
- $t as BezierEdgeShape,
2196
+ Ct as BezierEdgeShape,
2192
2197
  Bt as CanvasBuilder,
2193
- O as EventSubject,
2194
- Wt as HorizontalEdgeShape,
2198
+ q as EventSubject,
2199
+ $t as HorizontalEdgeShape,
2195
2200
  E as HtmlGraphError,
2196
- Ft as StraightEdgeShape,
2201
+ Wt as StraightEdgeShape,
2197
2202
  It as VerticalEdgeShape
2198
2203
  };