@html-graph/html-graph 0.1.7 → 1.1.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.
package/dist/main.js CHANGED
@@ -26,11 +26,11 @@ const O = (e, t) => ({
26
26
  let l = 0, a = 0, g = 0;
27
27
  const y = d > 0, x = d < r, f = y && x;
28
28
  if (y && (l = -i, a = -s, g = h), x) {
29
- const I = e[d + 1];
30
- i = I.x - c.x, s = I.y - c.y, h = Math.sqrt(i * i + s * s);
29
+ const D = e[d + 1];
30
+ i = D.x - c.x, s = D.y - c.y, h = Math.sqrt(i * i + s * s);
31
31
  }
32
- const S = h !== 0 ? Math.min((f ? t : 0) / h, d < r - 1 ? 0.5 : 1) : 0, T = f ? { x: c.x + i * S, y: c.y + s * S } : c, P = g !== 0 ? Math.min((f ? t : 0) / g, d > 1 ? 0.5 : 1) : 0, D = f ? { x: c.x + l * P, y: c.y + a * P } : c;
33
- d > 0 && o.push(`L ${D.x} ${D.y}`), f && o.push(
32
+ const E = h !== 0 ? Math.min((f ? t : 0) / h, d < r - 1 ? 0.5 : 1) : 0, T = f ? { x: c.x + i * E, y: c.y + s * E } : c, L = g !== 0 ? Math.min((f ? t : 0) / g, d > 1 ? 0.5 : 1) : 0, m = f ? { x: c.x + l * L, y: c.y + a * L } : c;
33
+ d > 0 && o.push(`L ${m.x} ${m.y}`), f && o.push(
34
34
  `C ${c.x} ${c.y} ${c.x} ${c.y} ${T.x} ${T.y}`
35
35
  );
36
36
  });
@@ -113,7 +113,7 @@ const O = (e, t) => ({
113
113
  }, A = {
114
114
  x: d.x + h,
115
115
  y: d.y + c
116
- }, S = {
116
+ }, E = {
117
117
  x: a.x + h,
118
118
  y: a.y + c
119
119
  };
@@ -121,7 +121,7 @@ const O = (e, t) => ({
121
121
  `M ${t.x} ${t.y}`,
122
122
  `L ${d.x} ${d.y}`,
123
123
  `C ${x.x} ${x.y} ${A.x} ${A.y} ${y.x} ${y.y}`,
124
- `C ${S.x} ${S.y} ${f.x} ${f.y} ${a.x} ${a.y}`,
124
+ `C ${E.x} ${E.y} ${f.x} ${f.y} ${a.x} ${a.y}`,
125
125
  `L ${o.x} ${o.y}`
126
126
  ].join(" ");
127
127
  }, et = (e) => {
@@ -145,7 +145,7 @@ const O = (e, t) => ({
145
145
  [t, s, l, a, y, g, h, o],
146
146
  e.roundness
147
147
  );
148
- }, G = (e) => {
148
+ }, U = (e) => {
149
149
  const t = e.hasSourceArrow ? v(
150
150
  { x: e.arrowLength, y: w.y },
151
151
  e.fromVect,
@@ -203,7 +203,7 @@ const O = (e, t) => ({
203
203
  [t, s, l, a, y, g, h, o],
204
204
  e.roundness
205
205
  );
206
- }, U = (e) => {
206
+ }, G = (e) => {
207
207
  const t = e.arrowOffset, o = e.side, r = e.arrowLength + t, i = r + 2 * o, h = [
208
208
  { x: e.arrowLength, y: w.y },
209
209
  { x: r, y: w.y },
@@ -268,31 +268,27 @@ class nt {
268
268
  }
269
269
  render(t) {
270
270
  const { x: o, y: r, width: i, height: s, flipX: h, flipY: c } = Y(
271
- t.source,
272
- t.target
271
+ t.from,
272
+ t.to
273
273
  );
274
274
  this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${c})`;
275
275
  const d = M(
276
- t.source.direction,
277
- h,
278
- c
279
- ), l = M(
280
- t.target.direction,
276
+ t.from.direction,
281
277
  h,
282
278
  c
283
- ), a = {
279
+ ), l = M(t.to.direction, h, c), a = {
284
280
  x: i,
285
281
  y: s
286
282
  };
287
283
  let g, y = l, x = -this.arrowLength;
288
- if (t.source.portId === t.target.portId ? (g = it({
284
+ if (t.from.portId === t.to.portId ? (g = it({
289
285
  fromVect: d,
290
286
  radius: this.portCycleRadius,
291
287
  smallRadius: this.portCycleSmallRadius,
292
288
  arrowLength: this.arrowLength,
293
289
  hasSourceArrow: this.hasSourceArrow,
294
290
  hasTargetArrow: this.hasTargetArrow
295
- }), y = d, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? g = tt({
291
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = tt({
296
292
  to: a,
297
293
  fromVect: d,
298
294
  toVect: l,
@@ -360,24 +356,20 @@ class st {
360
356
  }
361
357
  render(t) {
362
358
  const { x: o, y: r, width: i, height: s, flipX: h, flipY: c } = Y(
363
- t.source,
364
- t.target
359
+ t.from,
360
+ t.to
365
361
  );
366
362
  this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${c})`;
367
363
  const d = M(
368
- t.source.direction,
369
- h,
370
- c
371
- ), l = M(
372
- t.target.direction,
364
+ t.from.direction,
373
365
  h,
374
366
  c
375
- ), a = {
367
+ ), l = M(t.to.direction, h, c), a = {
376
368
  x: i,
377
369
  y: s
378
370
  };
379
371
  let g, y = l, x = -this.arrowLength;
380
- if (t.source.portId === t.target.portId ? (g = U({
372
+ if (t.from.portId === t.to.portId ? (g = G({
381
373
  fromVect: d,
382
374
  arrowLength: this.arrowLength,
383
375
  side: this.cycleSquareSide,
@@ -385,7 +377,7 @@ class st {
385
377
  roundness: this.roundness,
386
378
  hasSourceArrow: this.hasSourceArrow,
387
379
  hasTargetArrow: this.hasTargetArrow
388
- }), y = d, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? g = G({
380
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = U({
389
381
  to: a,
390
382
  fromVect: d,
391
383
  toVect: l,
@@ -456,24 +448,20 @@ class ht {
456
448
  }
457
449
  render(t) {
458
450
  const { x: o, y: r, width: i, height: s, flipX: h, flipY: c } = Y(
459
- t.source,
460
- t.target
451
+ t.from,
452
+ t.to
461
453
  );
462
454
  this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${c})`;
463
455
  const d = M(
464
- t.source.direction,
465
- h,
466
- c
467
- ), l = M(
468
- t.target.direction,
456
+ t.from.direction,
469
457
  h,
470
458
  c
471
- ), a = {
459
+ ), l = M(t.to.direction, h, c), a = {
472
460
  x: i,
473
461
  y: s
474
462
  };
475
463
  let g, y = l, x = -this.arrowLength;
476
- if (t.source.portId === t.target.portId ? (g = U({
464
+ if (t.from.portId === t.to.portId ? (g = G({
477
465
  fromVect: d,
478
466
  arrowLength: this.arrowLength,
479
467
  side: this.cycleSquareSide,
@@ -481,7 +469,7 @@ class ht {
481
469
  roundness: this.roundness,
482
470
  hasSourceArrow: this.hasSourceArrow,
483
471
  hasTargetArrow: this.hasTargetArrow
484
- }), y = d, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? g = G({
472
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = U({
485
473
  to: a,
486
474
  fromVect: d,
487
475
  toVect: l,
@@ -551,24 +539,20 @@ class ct {
551
539
  }
552
540
  render(t) {
553
541
  const { x: o, y: r, width: i, height: s, flipX: h, flipY: c } = Y(
554
- t.source,
555
- t.target
542
+ t.from,
543
+ t.to
556
544
  );
557
545
  this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${s}px`, this.group.style.transform = `scale(${h}, ${c})`;
558
546
  const d = M(
559
- t.source.direction,
547
+ t.from.direction,
560
548
  h,
561
549
  c
562
- ), l = M(
563
- t.target.direction,
564
- h,
565
- c
566
- ), a = {
550
+ ), l = M(t.to.direction, h, c), a = {
567
551
  x: i,
568
552
  y: s
569
553
  };
570
554
  let g, y = l, x = -this.arrowLength;
571
- if (t.source.portId === t.target.portId ? (g = U({
555
+ if (t.from.portId === t.to.portId ? (g = G({
572
556
  fromVect: d,
573
557
  arrowLength: this.arrowLength,
574
558
  side: this.cycleSquareSide,
@@ -576,7 +560,7 @@ class ct {
576
560
  roundness: this.roundness,
577
561
  hasSourceArrow: this.hasSourceArrow,
578
562
  hasTargetArrow: this.hasTargetArrow
579
- }), y = d, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? g = G({
563
+ }), y = d, x = this.arrowLength) : t.from.nodeId === t.to.nodeId ? g = U({
580
564
  to: a,
581
565
  fromVect: d,
582
566
  toVect: l,
@@ -852,12 +836,12 @@ class gt {
852
836
  }
853
837
  const K = (e) => ({
854
838
  scale: 1 / e.scale,
855
- dx: -e.dx / e.scale,
856
- dy: -e.dy / e.scale
839
+ x: -e.x / e.scale,
840
+ y: -e.y / e.scale
857
841
  }), _ = {
858
842
  scale: 1,
859
- dx: 0,
860
- dy: 0
843
+ x: 0,
844
+ y: 0
861
845
  };
862
846
  class ut {
863
847
  constructor() {
@@ -873,15 +857,15 @@ class ut {
873
857
  patchViewportMatrix(t) {
874
858
  this.viewportMatrix = {
875
859
  scale: t.scale ?? this.viewportMatrix.scale,
876
- dx: t.dx ?? this.viewportMatrix.dx,
877
- dy: t.dy ?? this.viewportMatrix.dy
860
+ x: t.x ?? this.viewportMatrix.x,
861
+ y: t.y ?? this.viewportMatrix.y
878
862
  }, this.contentMatrix = K(this.viewportMatrix);
879
863
  }
880
864
  patchContentMatrix(t) {
881
865
  this.contentMatrix = {
882
866
  scale: t.scale ?? this.contentMatrix.scale,
883
- dx: t.dx ?? this.contentMatrix.dx,
884
- dy: t.dy ?? this.contentMatrix.dy
867
+ x: t.x ?? this.contentMatrix.x,
868
+ y: t.y ?? this.contentMatrix.y
885
869
  }, this.viewportMatrix = K(this.contentMatrix);
886
870
  }
887
871
  }
@@ -923,7 +907,7 @@ class xt {
923
907
  }
924
908
  applyTransform() {
925
909
  const t = this.viewportTransformer.getContentMatrix();
926
- this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.dx}, ${t.dy})`;
910
+ this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.x}, ${t.y})`;
927
911
  }
928
912
  attachNode(t) {
929
913
  const o = this.graphStore.getNode(t), r = vt();
@@ -967,11 +951,11 @@ class xt {
967
951
  }
968
952
  renderEdge(t) {
969
953
  const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from), i = this.graphStore.getPort(o.to), s = r.element.getBoundingClientRect(), h = i.element.getBoundingClientRect(), c = this.host.getBoundingClientRect(), d = this.viewportTransformer.getViewportMatrix(), l = {
970
- x: d.scale * (s.left - c.left) + d.dx,
971
- y: d.scale * (s.top - c.top) + d.dy
954
+ x: d.scale * (s.left - c.left) + d.x,
955
+ y: d.scale * (s.top - c.top) + d.y
972
956
  }, a = {
973
- x: d.scale * (h.left - c.left) + d.dx,
974
- y: d.scale * (h.top - c.top) + d.dy
957
+ x: d.scale * (h.left - c.left) + d.x,
958
+ y: d.scale * (h.top - c.top) + d.y
975
959
  }, g = {
976
960
  x: l.x,
977
961
  y: l.y,
@@ -990,8 +974,8 @@ class xt {
990
974
  nodeId: this.graphStore.getPortNodeId(o.to)
991
975
  };
992
976
  o.shape.render({
993
- source: g,
994
- target: y
977
+ from: g,
978
+ to: y
995
979
  });
996
980
  }
997
981
  updateEdgePriority(t) {
@@ -999,7 +983,7 @@ class xt {
999
983
  o.shape.svg.style.zIndex = `${o.priority}`;
1000
984
  }
1001
985
  }
1002
- class m {
986
+ class I {
1003
987
  constructor(t) {
1004
988
  n(this, "counter", 0);
1005
989
  this.checkExists = t;
@@ -1015,21 +999,21 @@ class m {
1015
999
  this.counter = 0;
1016
1000
  }
1017
1001
  }
1018
- class E extends Error {
1002
+ class S extends Error {
1019
1003
  constructor() {
1020
1004
  super(...arguments);
1021
1005
  n(this, "name", "HtmlGraphError");
1022
1006
  }
1023
1007
  }
1024
- class Et {
1008
+ class St {
1025
1009
  constructor(t, o, r, i, s, h, c) {
1026
- n(this, "nodeIdGenerator", new m(
1010
+ n(this, "nodeIdGenerator", new I(
1027
1011
  (t) => this.graphStore.getNode(t) !== void 0
1028
1012
  ));
1029
- n(this, "portIdGenerator", new m(
1013
+ n(this, "portIdGenerator", new I(
1030
1014
  (t) => this.graphStore.getPort(t) !== void 0
1031
1015
  ));
1032
- n(this, "edgeIdGenerator", new m(
1016
+ n(this, "edgeIdGenerator", new I(
1033
1017
  (t) => this.graphStore.getEdge(t) !== void 0
1034
1018
  ));
1035
1019
  this.graphStore = t, this.htmlController = o, this.viewportTransformer = r, this.defaultNodesCenterFn = i, this.defaultPortsDirection = s, this.defaultNodesPriorityFn = h, this.defaultEdgesPriorityFn = c;
@@ -1043,7 +1027,7 @@ class Et {
1043
1027
  addNode(t) {
1044
1028
  const o = this.nodeIdGenerator.create(t.nodeId);
1045
1029
  if (this.graphStore.getNode(o) !== void 0)
1046
- throw new E("failed to add node with existing id");
1030
+ throw new S("failed to add node with existing id");
1047
1031
  this.graphStore.addNode({
1048
1032
  nodeId: o,
1049
1033
  element: t.element,
@@ -1063,9 +1047,9 @@ class Et {
1063
1047
  markPort(t) {
1064
1048
  const o = this.portIdGenerator.create(t.portId);
1065
1049
  if (this.graphStore.getPort(o) !== void 0)
1066
- throw new E("failed to add port with existing id");
1050
+ throw new S("failed to add port with existing id");
1067
1051
  if (this.graphStore.getNode(t.nodeId) === void 0)
1068
- throw new E("failed to set port on nonexisting node");
1052
+ throw new S("failed to set port on nonexisting node");
1069
1053
  this.graphStore.addPort({
1070
1054
  portId: o,
1071
1055
  element: t.element,
@@ -1076,11 +1060,11 @@ class Et {
1076
1060
  addEdge(t) {
1077
1061
  const o = this.edgeIdGenerator.create(t.edgeId);
1078
1062
  if (this.graphStore.getEdge(o) !== void 0)
1079
- throw new E("failed to add edge with existing id");
1063
+ throw new S("failed to add edge with existing id");
1080
1064
  if (this.graphStore.getPort(t.from) === void 0)
1081
- throw new E("failed to add edge from nonexisting port");
1065
+ throw new S("failed to add edge from nonexisting port");
1082
1066
  if (this.graphStore.getPort(t.to) === void 0)
1083
- throw new E("failed to add edge to nonexisting port");
1067
+ throw new S("failed to add edge to nonexisting port");
1084
1068
  this.graphStore.addEdge({
1085
1069
  edgeId: o,
1086
1070
  from: t.from,
@@ -1092,13 +1076,13 @@ class Et {
1092
1076
  updateEdge(t) {
1093
1077
  const o = this.graphStore.getEdge(t.edgeId);
1094
1078
  if (o === void 0)
1095
- throw new E("failed to update nonexisting edge");
1079
+ throw new S("failed to update nonexisting edge");
1096
1080
  t.shape !== void 0 && (o.shape = t.shape, this.htmlController.updateEdgeShape(t.edgeId)), t.priority !== void 0 && (o.priority = t.priority, this.htmlController.updateEdgePriority(t.edgeId)), t.from !== void 0 && this.graphStore.updateEdgeFrom(t.edgeId, t.from), t.to !== void 0 && this.graphStore.updateEdgeTo(t.edgeId, t.to), this.htmlController.renderEdge(t.edgeId);
1097
1081
  }
1098
1082
  updatePort(t, o) {
1099
1083
  const r = this.graphStore.getPort(t);
1100
1084
  if (r === void 0)
1101
- throw new E("failed to unset nonexisting port");
1085
+ throw new S("failed to unset nonexisting port");
1102
1086
  r.direction = o.direction ?? r.direction, this.graphStore.getPortAdjacentEdgeIds(t).forEach((s) => {
1103
1087
  this.htmlController.renderEdge(s);
1104
1088
  });
@@ -1106,26 +1090,26 @@ class Et {
1106
1090
  updateNode(t, o) {
1107
1091
  const r = this.graphStore.getNode(t);
1108
1092
  if (r === void 0)
1109
- throw new E("failed to update nonexisting node");
1093
+ throw new S("failed to update nonexisting node");
1110
1094
  r.x = (o == null ? void 0 : o.x) ?? r.x, r.y = (o == null ? void 0 : o.y) ?? r.y, r.centerFn = (o == null ? void 0 : o.centerFn) ?? r.centerFn, r.priority = (o == null ? void 0 : o.priority) ?? r.priority, this.htmlController.updateNodeCoordinates(t), this.htmlController.updateNodePriority(t), this.graphStore.getNodeAdjacentEdgeIds(t).forEach((s) => {
1111
1095
  this.htmlController.renderEdge(s);
1112
1096
  });
1113
1097
  }
1114
1098
  removeEdge(t) {
1115
1099
  if (this.graphStore.getEdge(t) === void 0)
1116
- throw new E("failed to remove nonexisting edge");
1100
+ throw new S("failed to remove nonexisting edge");
1117
1101
  this.htmlController.detachEdge(t), this.graphStore.removeEdge(t);
1118
1102
  }
1119
1103
  unmarkPort(t) {
1120
1104
  if (this.graphStore.getPort(t) === void 0)
1121
- throw new E("failed to unset nonexisting port");
1105
+ throw new S("failed to unset nonexisting port");
1122
1106
  this.graphStore.getPortAdjacentEdgeIds(t).forEach((o) => {
1123
1107
  this.removeEdge(o);
1124
1108
  }), this.graphStore.removePort(t);
1125
1109
  }
1126
1110
  removeNode(t) {
1127
1111
  if (this.graphStore.getNode(t) === void 0)
1128
- throw new E("failed to remove nonexisting node");
1112
+ throw new S("failed to remove nonexisting node");
1129
1113
  this.graphStore.getNodePortIds(t).forEach((o) => {
1130
1114
  this.unmarkPort(o);
1131
1115
  }), this.htmlController.detachNode(t), this.graphStore.removeNode(t);
@@ -1143,7 +1127,7 @@ class Et {
1143
1127
  this.clear(), this.htmlController.destroy();
1144
1128
  }
1145
1129
  }
1146
- class St {
1130
+ class Et {
1147
1131
  constructor(t) {
1148
1132
  this.graphStore = t;
1149
1133
  }
@@ -1171,7 +1155,7 @@ class St {
1171
1155
  return this.graphStore.getAllPortIds();
1172
1156
  }
1173
1157
  getNodePortIds(t) {
1174
- return this.graphStore.getNodePortIds(t);
1158
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodePortIds(t);
1175
1159
  }
1176
1160
  getPortNodeId(t) {
1177
1161
  return this.graphStore.getPortNodeId(t) ?? null;
@@ -1184,28 +1168,28 @@ class St {
1184
1168
  return o === void 0 ? null : { from: o.from, to: o.to, priority: o.priority };
1185
1169
  }
1186
1170
  getPortIncomingEdgeIds(t) {
1187
- return this.graphStore.getPortIncomingEdgeIds(t);
1171
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortIncomingEdgeIds(t);
1188
1172
  }
1189
1173
  getPortOutcomingEdgeIds(t) {
1190
- return this.graphStore.getPortOutcomingEdgeIds(t);
1174
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortOutcomingEdgeIds(t);
1191
1175
  }
1192
1176
  getPortCycleEdgeIds(t) {
1193
- return this.graphStore.getPortCycleEdgeIds(t);
1177
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortCycleEdgeIds(t);
1194
1178
  }
1195
1179
  getPortAdjacentEdgeIds(t) {
1196
- return this.graphStore.getPortAdjacentEdgeIds(t);
1180
+ return this.graphStore.getPort(t) === void 0 ? null : this.graphStore.getPortAdjacentEdgeIds(t);
1197
1181
  }
1198
1182
  getNodeIncomingEdgeIds(t) {
1199
- return this.graphStore.getNodeIncomingEdgeIds(t);
1183
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeIncomingEdgeIds(t);
1200
1184
  }
1201
1185
  getNodeOutcomingEdgeIds(t) {
1202
- return this.graphStore.getNodeOutcomingEdgeIds(t);
1186
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeOutcomingEdgeIds(t);
1203
1187
  }
1204
1188
  getNodeCycleEdgeIds(t) {
1205
- return this.graphStore.getNodeCycleEdgeIds(t);
1189
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeCycleEdgeIds(t);
1206
1190
  }
1207
1191
  getNodeAdjacentEdgeIds(t) {
1208
- return this.graphStore.getNodeAdjacentEdgeIds(t);
1192
+ return this.graphStore.getNode(t) === void 0 ? null : this.graphStore.getNodeAdjacentEdgeIds(t);
1209
1193
  }
1210
1194
  }
1211
1195
  class At {
@@ -1216,9 +1200,9 @@ class At {
1216
1200
  n(this, "edgeShapeFactory");
1217
1201
  this.apiOptions = t;
1218
1202
  const o = at(this.apiOptions), r = new ut(), i = new gt();
1219
- this.model = new St(i), this.transformation = new wt(r);
1203
+ this.model = new Et(i), this.transformation = new wt(r);
1220
1204
  const s = new xt(i, r);
1221
- this.canvasController = new Et(
1205
+ this.canvasController = new St(
1222
1206
  i,
1223
1207
  s,
1224
1208
  r,
@@ -1309,13 +1293,13 @@ class At {
1309
1293
  const V = (e, t, o) => {
1310
1294
  const { x: r, y: i, width: s, height: h } = e.getBoundingClientRect();
1311
1295
  return t >= r && t <= r + s && o >= i && o <= i + h;
1312
- }, b = (e, t, o) => t >= 0 && t <= e.innerWidth && o >= 0 && o <= e.innerHeight, p = (e, t) => {
1296
+ }, p = (e, t, o) => t >= 0 && t <= e.innerWidth && o >= 0 && o <= e.innerHeight, b = (e, t) => {
1313
1297
  t !== null ? e.style.cursor = t : e.style.removeProperty("cursor");
1314
1298
  }, Tt = (e) => {
1315
- var g, y, x, f, A, S;
1299
+ var g, y, x, f, A, E;
1316
1300
  const t = ((g = e == null ? void 0 : e.events) == null ? void 0 : g.onNodeDrag) ?? (() => {
1317
1301
  }), 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) ?? (() => {
1318
- }), i = (e == null ? void 0 : e.moveOnTop) === !1, s = (f = e == null ? void 0 : e.mouse) == null ? void 0 : f.dragCursor, h = s !== void 0 ? s : "grab", c = (A = e == null ? void 0 : e.mouse) == null ? void 0 : A.mouseDownEventVerifier, d = c !== void 0 ? c : (T) => T.button === 0, l = (S = e == null ? void 0 : e.mouse) == null ? void 0 : S.mouseUpEventVerifier;
1302
+ }), i = (e == null ? void 0 : e.moveOnTop) === !1, s = (f = e == null ? void 0 : e.mouse) == null ? void 0 : f.dragCursor, h = s !== void 0 ? s : "grab", c = (A = e == null ? void 0 : e.mouse) == null ? void 0 : A.mouseDownEventVerifier, d = c !== void 0 ? c : (T) => T.button === 0, l = (E = e == null ? void 0 : e.mouse) == null ? void 0 : E.mouseUpEventVerifier;
1319
1303
  return {
1320
1304
  freezePriority: i,
1321
1305
  dragCursor: h,
@@ -1333,12 +1317,12 @@ class Mt {
1333
1317
  n(this, "maxNodePriority", 0);
1334
1318
  n(this, "nodes", /* @__PURE__ */ new Map());
1335
1319
  n(this, "grabbedNodeId", null);
1336
- n(this, "nodeIdGenerator", new m(
1320
+ n(this, "nodeIdGenerator", new I(
1337
1321
  (t) => this.nodes.has(t)
1338
1322
  ));
1339
1323
  n(this, "element", null);
1340
1324
  n(this, "onWindowMouseMove", (t) => {
1341
- if (this.element !== null && (!V(this.element, t.clientX, t.clientY) || !b(this.window, t.clientX, t.clientY))) {
1325
+ if (this.element !== null && (!V(this.element, t.clientX, t.clientY) || !p(this.window, t.clientX, t.clientY))) {
1342
1326
  this.cancelMouseDrag();
1343
1327
  return;
1344
1328
  }
@@ -1351,7 +1335,7 @@ class Mt {
1351
1335
  if (t.touches.length !== 1)
1352
1336
  return;
1353
1337
  const o = t.touches[0];
1354
- if (this.element !== null && (!V(this.element, o.clientX, o.clientY) || !b(this.window, o.clientX, o.clientY))) {
1338
+ if (this.element !== null && (!V(this.element, o.clientX, o.clientY) || !p(this.window, o.clientX, o.clientY))) {
1355
1339
  this.cancelTouchDrag();
1356
1340
  return;
1357
1341
  }
@@ -1389,7 +1373,7 @@ class Mt {
1389
1373
  element: t.element,
1390
1374
  x: h.x,
1391
1375
  y: h.y
1392
- }) && (s.stopImmediatePropagation(), this.grabbedNodeId = o, p(this.element, this.options.dragCursor), this.moveNodeOnTop(o), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
1376
+ }) && (s.stopImmediatePropagation(), this.grabbedNodeId = o, b(this.element, this.options.dragCursor), this.moveNodeOnTop(o), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
1393
1377
  }, i = (s) => {
1394
1378
  if (s.touches.length !== 1)
1395
1379
  return;
@@ -1454,7 +1438,7 @@ class Mt {
1454
1438
  const i = this.model.getNode(t);
1455
1439
  if (i === null)
1456
1440
  return;
1457
- const s = this.canvas.transformation.getContentMatrix(), h = s.scale * i.x + s.dx, c = s.scale * i.y + s.dy, d = h + o, l = c + r, a = this.canvas.transformation.getViewportMatrix(), g = a.scale * d + a.dx, y = a.scale * l + a.dy;
1441
+ const s = this.canvas.transformation.getContentMatrix(), h = s.scale * i.x + s.x, c = s.scale * i.y + s.y, d = h + o, l = c + r, a = this.canvas.transformation.getViewportMatrix(), g = a.scale * d + a.x, y = a.scale * l + a.y;
1458
1442
  this.canvas.updateNode(t, { x: g, y }), this.options.onNodeDrag({
1459
1443
  nodeId: t,
1460
1444
  element: i.element,
@@ -1482,7 +1466,7 @@ class Mt {
1482
1466
  element: t.element,
1483
1467
  x: t.x,
1484
1468
  y: t.y
1485
- }), this.grabbedNodeId = null, this.element !== null && p(this.element, null), this.removeMouseDragListeners();
1469
+ }), this.grabbedNodeId = null, this.element !== null && b(this.element, null), this.removeMouseDragListeners();
1486
1470
  }
1487
1471
  removeMouseDragListeners() {
1488
1472
  this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
@@ -1504,35 +1488,35 @@ class Mt {
1504
1488
  const Ct = (e) => {
1505
1489
  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, i = e.maxY !== null ? e.maxY : 1 / 0;
1506
1490
  return (s) => {
1507
- let h = s.nextTransform.dx, c = s.nextTransform.dy;
1508
- h < t && h < s.prevTransform.dx && (h = Math.min(s.prevTransform.dx, t));
1509
- const d = s.canvasWidth * s.prevTransform.scale;
1510
- h > o - d && h > s.prevTransform.dx && (h = Math.max(s.prevTransform.dx, o - d)), c < r && c < s.prevTransform.dy && (c = Math.min(s.prevTransform.dy, r));
1511
- const l = s.canvasHeight * s.prevTransform.scale;
1512
- return c > i - l && c > s.prevTransform.dy && (c = Math.max(s.prevTransform.dy, i - l)), { scale: s.nextTransform.scale, dx: h, dy: c };
1491
+ let h = s.nextTransform.x, c = s.nextTransform.y;
1492
+ h < t && h < s.prevTransform.x && (h = Math.min(s.prevTransform.x, t));
1493
+ const d = s.canvasWidth * s.prevTransform.scale, l = o - d;
1494
+ h > l && h > s.prevTransform.x && (h = Math.max(s.prevTransform.x, l)), c < r && c < s.prevTransform.y && (c = Math.min(s.prevTransform.y, r));
1495
+ const a = s.canvasHeight * s.prevTransform.scale, g = i - a;
1496
+ return c > g && c > s.prevTransform.y && (c = Math.max(s.prevTransform.y, g)), { scale: s.nextTransform.scale, x: h, y: c };
1513
1497
  };
1514
1498
  }, Nt = (e) => {
1515
1499
  const t = e.maxContentScale, o = e.minContentScale, r = t !== null ? 1 / t : 0, i = o !== null ? 1 / o : 1 / 0;
1516
1500
  return (s) => {
1517
1501
  const h = s.prevTransform, c = s.nextTransform;
1518
- let d = c.scale, l = c.dx, a = c.dy;
1502
+ let d = c.scale, l = c.x, a = c.y;
1519
1503
  if (c.scale > i && c.scale > h.scale) {
1520
- d = Math.max(h.scale, i), l = h.dx, a = h.dy;
1504
+ d = Math.max(h.scale, i), l = h.x, a = h.y;
1521
1505
  const g = (d - h.scale) / (c.scale - h.scale);
1522
- l = h.dx + (c.dx - h.dx) * g, a = h.dy + (c.dy - h.dy) * g;
1506
+ l = h.x + (c.x - h.x) * g, a = h.y + (c.y - h.y) * g;
1523
1507
  }
1524
1508
  if (c.scale < r && c.scale < h.scale) {
1525
- d = Math.min(h.scale, r), l = h.dx, a = h.dy;
1509
+ d = Math.min(h.scale, r), l = h.x, a = h.y;
1526
1510
  const g = (d - h.scale) / (c.scale - h.scale);
1527
- l = h.dx + (c.dx - h.dx) * g, a = h.dy + (c.dy - h.dy) * g;
1511
+ l = h.x + (c.x - h.x) * g, a = h.y + (c.y - h.y) * g;
1528
1512
  }
1529
1513
  return {
1530
1514
  scale: d,
1531
- dx: l,
1532
- dy: a
1515
+ x: l,
1516
+ y: a
1533
1517
  };
1534
1518
  };
1535
- }, Lt = (e) => (t) => e.reduce(
1519
+ }, Pt = (e) => (t) => e.reduce(
1536
1520
  (o, r) => r({
1537
1521
  prevTransform: t.prevTransform,
1538
1522
  nextTransform: o,
@@ -1557,21 +1541,21 @@ const Ct = (e) => {
1557
1541
  maxY: e.maxY ?? 1 / 0
1558
1542
  });
1559
1543
  }
1560
- }, Pt = (e) => {
1561
- var f, A, S, T, X, P, D, I, j;
1544
+ }, Lt = (e) => {
1545
+ var f, A, E, T, X, L, m, D, j;
1562
1546
  const t = (f = e == null ? void 0 : e.scale) == null ? void 0 : f.mouseWheelSensitivity, o = t !== void 0 ? t : 1.2, r = e == null ? void 0 : e.transformPreprocessor;
1563
1547
  let i;
1564
- r !== void 0 ? Array.isArray(r) ? i = Lt(
1548
+ r !== void 0 ? Array.isArray(r) ? i = Pt(
1565
1549
  r.map(
1566
- (L) => J(L)
1550
+ (P) => J(P)
1567
1551
  )
1568
- ) : i = J(r) : i = (L) => L.nextTransform;
1569
- const s = ((A = e == null ? void 0 : e.shift) == null ? void 0 : A.cursor) !== void 0 ? e.shift.cursor : "grab", h = ((S = e == null ? void 0 : e.events) == null ? void 0 : S.onBeforeTransformChange) ?? (() => {
1552
+ ) : i = J(r) : i = (P) => P.nextTransform;
1553
+ const s = ((A = e == null ? void 0 : e.shift) == null ? void 0 : A.cursor) !== void 0 ? e.shift.cursor : "grab", h = ((E = e == null ? void 0 : e.events) == null ? void 0 : E.onBeforeTransformChange) ?? (() => {
1570
1554
  }), c = ((T = e == null ? void 0 : e.events) == null ? void 0 : T.onTransformChange) ?? (() => {
1571
- }), d = (X = e == null ? void 0 : e.shift) == null ? void 0 : X.mouseDownEventVerifier, l = d !== void 0 ? d : (L) => L.button === 0, a = (P = e == null ? void 0 : e.shift) == null ? void 0 : P.mouseUpEventVerifier, g = a !== void 0 ? a : (L) => L.button === 0, y = (D = e == null ? void 0 : e.scale) == null ? void 0 : D.mouseWheelEventVerifier, x = y !== void 0 ? y : () => !0;
1555
+ }), d = (X = e == null ? void 0 : e.shift) == null ? void 0 : X.mouseDownEventVerifier, l = d !== void 0 ? d : (P) => P.button === 0, a = (L = e == null ? void 0 : e.shift) == null ? void 0 : L.mouseUpEventVerifier, g = a !== void 0 ? a : (P) => P.button === 0, y = (m = e == null ? void 0 : e.scale) == null ? void 0 : m.mouseWheelEventVerifier, x = y !== void 0 ? y : () => !0;
1572
1556
  return {
1573
1557
  wheelSensitivity: o,
1574
- onTransformStarted: ((I = e == null ? void 0 : e.events) == null ? void 0 : I.onTransformStarted) ?? (() => {
1558
+ onTransformStarted: ((D = e == null ? void 0 : e.events) == null ? void 0 : D.onTransformStarted) ?? (() => {
1575
1559
  }),
1576
1560
  onTransformFinished: ((j = e == null ? void 0 : e.events) == null ? void 0 : j.onTransformFinished) ?? (() => {
1577
1561
  }),
@@ -1601,16 +1585,16 @@ const Ct = (e) => {
1601
1585
  touchesCnt: o,
1602
1586
  touches: t
1603
1587
  };
1604
- }, Dt = (e, t, o) => ({
1588
+ }, mt = (e, t, o) => ({
1605
1589
  scale: e.scale,
1606
- dx: e.dx + e.scale * t,
1607
- dy: e.dy + e.scale * o
1608
- }), It = (e, t, o, r) => ({
1590
+ x: e.x + e.scale * t,
1591
+ y: e.y + e.scale * o
1592
+ }), Dt = (e, t, o, r) => ({
1609
1593
  scale: e.scale * t,
1610
- dx: e.scale * (1 - t) * o + e.dx,
1611
- dy: e.scale * (1 - t) * r + e.dy
1594
+ x: e.scale * (1 - t) * o + e.x,
1595
+ y: e.scale * (1 - t) * r + e.y
1612
1596
  });
1613
- class mt {
1597
+ class It {
1614
1598
  constructor(t, o) {
1615
1599
  n(this, "model");
1616
1600
  n(this, "transformation");
@@ -1618,10 +1602,10 @@ class mt {
1618
1602
  n(this, "prevTouches", null);
1619
1603
  n(this, "window", window);
1620
1604
  n(this, "onMouseDown", (t) => {
1621
- this.element === null || !this.options.mouseDownEventVerifier(t) || (p(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.options.onTransformStarted());
1605
+ this.element === null || !this.options.mouseDownEventVerifier(t) || (b(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.options.onTransformStarted());
1622
1606
  });
1623
1607
  n(this, "onWindowMouseMove", (t) => {
1624
- if (this.element === null || !V(this.element, t.clientX, t.clientY) || !b(this.window, t.clientX, t.clientY)) {
1608
+ if (this.element === null || !V(this.element, t.clientX, t.clientY) || !p(this.window, t.clientX, t.clientY)) {
1625
1609
  this.stopMouseDrag();
1626
1610
  return;
1627
1611
  }
@@ -1647,7 +1631,7 @@ class mt {
1647
1631
  return;
1648
1632
  const r = B(t);
1649
1633
  if (!r.touches.every(
1650
- (s) => V(o, s[0], s[1]) && b(this.window, s[0], s[1])
1634
+ (s) => V(o, s[0], s[1]) && p(this.window, s[0], s[1])
1651
1635
  )) {
1652
1636
  this.stopTouchDrag();
1653
1637
  return;
@@ -1675,7 +1659,7 @@ class mt {
1675
1659
  this.canvas.patchViewportMatrix(i), this.options.onTransformChange();
1676
1660
  }));
1677
1661
  n(this, "options");
1678
- this.canvas = t, this.options = Pt(o), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1662
+ this.canvas = t, this.options = Lt(o), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1679
1663
  }
1680
1664
  attach(t) {
1681
1665
  return 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), this;
@@ -1724,7 +1708,7 @@ class mt {
1724
1708
  }
1725
1709
  moveViewport(t, o, r) {
1726
1710
  this.options.onBeforeTransformChange();
1727
- const i = this.transformation.getViewportMatrix(), s = Dt(i, o, r), { width: h, height: c } = t.getBoundingClientRect(), d = this.options.transformPreprocessor({
1711
+ const i = this.transformation.getViewportMatrix(), s = mt(i, o, r), { width: h, height: c } = t.getBoundingClientRect(), d = this.options.transformPreprocessor({
1728
1712
  prevTransform: i,
1729
1713
  nextTransform: s,
1730
1714
  canvasWidth: h,
@@ -1734,7 +1718,7 @@ class mt {
1734
1718
  }
1735
1719
  scaleViewport(t, o, r, i) {
1736
1720
  this.options.onBeforeTransformChange();
1737
- const s = this.canvas.transformation.getViewportMatrix(), h = It(s, o, r, i), { width: c, height: d } = t.getBoundingClientRect(), l = this.options.transformPreprocessor({
1721
+ const s = this.canvas.transformation.getViewportMatrix(), h = Dt(s, o, r, i), { width: c, height: d } = t.getBoundingClientRect(), l = this.options.transformPreprocessor({
1738
1722
  prevTransform: s,
1739
1723
  nextTransform: h,
1740
1724
  canvasWidth: c,
@@ -1743,7 +1727,7 @@ class mt {
1743
1727
  this.canvas.patchViewportMatrix(l), this.options.onTransformChange();
1744
1728
  }
1745
1729
  stopMouseDrag() {
1746
- this.element !== null && p(this.element, null), this.removeMouseDragListeners(), this.options.onTransformFinished();
1730
+ this.element !== null && b(this.element, null), this.removeMouseDragListeners(), this.options.onTransformFinished();
1747
1731
  }
1748
1732
  removeMouseDragListeners() {
1749
1733
  this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
@@ -1797,7 +1781,7 @@ class Vt {
1797
1781
  n(this, "transformation");
1798
1782
  n(this, "model");
1799
1783
  n(this, "nodes", new $t());
1800
- n(this, "nodeIdGenerator", new m(
1784
+ n(this, "nodeIdGenerator", new I(
1801
1785
  (t) => this.nodes.hasKey(t)
1802
1786
  ));
1803
1787
  n(this, "nodesResizeObserver");
@@ -1866,7 +1850,7 @@ class Vt {
1866
1850
  });
1867
1851
  }
1868
1852
  }
1869
- class pt {
1853
+ class bt {
1870
1854
  constructor() {
1871
1855
  n(this, "coreOptions");
1872
1856
  n(this, "dragOptions");
@@ -1881,7 +1865,14 @@ class pt {
1881
1865
  setUserDraggableNodes(t) {
1882
1866
  return this.isDraggable = !0, this.dragOptions = t, this;
1883
1867
  }
1868
+ /**
1869
+ * @deprecated
1870
+ * use setUserTransformableViewport instead
1871
+ */
1884
1872
  setUserTransformableCanvas(t) {
1873
+ return this.setUserTransformableViewport(t);
1874
+ }
1875
+ setUserTransformableViewport(t) {
1885
1876
  return this.isTransformable = !0, this.transformOptions = t, this;
1886
1877
  }
1887
1878
  setResizeReactiveNodes() {
@@ -1889,18 +1880,20 @@ class pt {
1889
1880
  }
1890
1881
  build() {
1891
1882
  let t = new At(this.coreOptions);
1892
- return this.hasResizeReactiveNodes && (t = new Vt(t)), this.isDraggable && (t = new Mt(t, this.dragOptions)), this.isTransformable && (t = new mt(t, this.transformOptions)), t;
1883
+ return this.hasResizeReactiveNodes && (t = new Vt(t)), this.isDraggable && (t = new Mt(t, this.dragOptions)), this.isTransformable && (t = new It(t, this.transformOptions)), t;
1893
1884
  }
1894
1885
  }
1895
1886
  export {
1896
1887
  nt as BezierEdgeShape,
1888
+ bt as CanvasBuilder,
1897
1889
  At as CanvasCore,
1898
1890
  st as HorizontalEdgeShape,
1899
- pt as HtmlGraphBuilder,
1900
- E as HtmlGraphError,
1891
+ bt as HtmlGraphBuilder,
1892
+ S as HtmlGraphError,
1901
1893
  Vt as ResizeReactiveNodesCanvas,
1902
1894
  ht as StraightEdgeShape,
1903
1895
  Mt as UserDraggableNodesCanvas,
1904
- mt as UserTransformableCanvas,
1896
+ It as UserTransformableCanvas,
1897
+ It as UserTransformableViewportCanvas,
1905
1898
  ct as VerticalEdgeShape
1906
1899
  };