@html-graph/html-graph 7.1.1 → 7.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.
@@ -467,6 +467,7 @@ export declare interface DraggableNodesConfig {
467
467
  readonly mouseUpEventVerifier?: MouseEventVerifier;
468
468
  };
469
469
  readonly events?: {
470
+ readonly onNodeDragStarted?: (nodeId: Identifier) => void;
470
471
  readonly onNodeDrag?: (nodeId: Identifier) => void;
471
472
  readonly onNodeDragFinished?: (nodeId: Identifier) => void;
472
473
  };
@@ -1,7 +1,7 @@
1
1
  var Fe = Object.defineProperty;
2
2
  var Oe = (r, e, t) => e in r ? Fe(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
3
  var o = (r, e, t) => Oe(r, typeof e != "symbol" ? e + "" : e, t);
4
- const D = (r, e) => ({
4
+ const N = (r, e) => ({
5
5
  x: r.scale * e.x + r.x,
6
6
  y: r.scale * e.y + r.y
7
7
  });
@@ -90,7 +90,7 @@ class ye {
90
90
  const n = {
91
91
  x: t.left - s.left,
92
92
  y: t.top - s.top
93
- }, a = D(i, n);
93
+ }, a = N(i, n);
94
94
  return {
95
95
  x: a.x,
96
96
  y: a.y,
@@ -886,11 +886,11 @@ const xe = (r, e) => {
886
886
  }
887
887
  return null;
888
888
  };
889
- var b = /* @__PURE__ */ ((r) => (r.Static = "static", r.Dragging = "dragging", r.Edge = "edge", r))(b || {});
889
+ var T = /* @__PURE__ */ ((r) => (r.Static = "static", r.Dragging = "dragging", r.Edge = "edge", r))(T || {});
890
890
  const Se = (r, e) => ({
891
891
  x: r / 2,
892
892
  y: e / 2
893
- }), p = {
893
+ }), u = {
894
894
  x: 0,
895
895
  y: 0
896
896
  }, y = (r, e, t) => ({
@@ -924,9 +924,9 @@ class Qe {
924
924
  const t = this.params.to;
925
925
  this.midpoint = { x: t.x / 2, y: t.y / 2 };
926
926
  const s = y(
927
- { x: this.params.arrowLength, y: p.y },
927
+ { x: this.params.arrowLength, y: u.y },
928
928
  this.params.sourceDirection,
929
- p
929
+ u
930
930
  ), i = y(
931
931
  { x: this.params.to.x - this.params.arrowLength, y: this.params.to.y },
932
932
  this.params.targetDirection,
@@ -937,7 +937,7 @@ class Qe {
937
937
  }, a = {
938
938
  x: i.x - this.params.targetDirection.x * this.params.curvature,
939
939
  y: i.y - this.params.targetDirection.y * this.params.curvature
940
- }, h = `M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`, d = this.params.hasSourceArrow ? "" : `M ${p.x} ${p.y} L ${s.x} ${s.y} `, c = this.params.hasTargetArrow ? "" : ` M ${i.x} ${i.y} L ${this.params.to.x} ${this.params.to.y}`;
940
+ }, h = `M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`, d = this.params.hasSourceArrow ? "" : `M ${u.x} ${u.y} L ${s.x} ${s.y} `, c = this.params.hasTargetArrow ? "" : ` M ${i.x} ${i.y} L ${this.params.to.x} ${this.params.to.y}`;
941
941
  this.path = `${d}${h}${c}`;
942
942
  }
943
943
  }
@@ -947,10 +947,10 @@ class qe {
947
947
  o(this, "midpoint");
948
948
  this.params = e;
949
949
  const t = this.params.hasSourceArrow ? y(
950
- { x: this.params.arrowLength, y: p.y },
950
+ { x: this.params.arrowLength, y: u.y },
951
951
  this.params.sourceDirection,
952
- p
953
- ) : p, s = this.params.hasTargetArrow ? y(
952
+ u
953
+ ) : u, s = this.params.hasTargetArrow ? y(
954
954
  {
955
955
  x: this.params.to.x - this.params.arrowLength,
956
956
  y: this.params.to.y
@@ -958,9 +958,9 @@ class qe {
958
958
  this.params.targetDirection,
959
959
  this.params.to
960
960
  ) : this.params.to, i = this.params.arrowLength, n = Math.cos(this.params.detourDirection) * this.params.detourDistance, a = Math.sin(this.params.detourDirection) * this.params.detourDistance, h = n * this.params.flipX, d = a * this.params.flipY, c = y(
961
- { x: i, y: p.y },
961
+ { x: i, y: u.y },
962
962
  this.params.sourceDirection,
963
- p
963
+ u
964
964
  ), g = {
965
965
  x: c.x + h,
966
966
  y: c.y + d
@@ -968,12 +968,12 @@ class qe {
968
968
  { x: this.params.to.x - i, y: this.params.to.y },
969
969
  this.params.targetDirection,
970
970
  this.params.to
971
- ), u = {
971
+ ), p = {
972
972
  x: l.x + h,
973
973
  y: l.y + d
974
974
  }, w = {
975
- x: (g.x + u.x) / 2,
976
- y: (g.y + u.y) / 2
975
+ x: (g.x + p.x) / 2,
976
+ y: (g.y + p.y) / 2
977
977
  }, m = {
978
978
  x: c.x + this.params.curvature * this.params.sourceDirection.x,
979
979
  y: c.y + this.params.curvature * this.params.sourceDirection.y
@@ -1012,20 +1012,20 @@ const Z = Object.freeze({
1012
1012
  return r.style.transformOrigin = "50% 50%", r;
1013
1013
  }, Ne = (r, e) => {
1014
1014
  r.style.transform = `translate(${e.x}px, ${e.y}px)`, r.style.width = `${Math.max(e.width, 1)}px`, r.style.height = `${Math.max(e.height, 1)}px`;
1015
- }, L = (r, e) => {
1015
+ }, R = (r, e) => {
1016
1016
  const t = [];
1017
1017
  if (r.length > 0 && t.push(`M ${r[0].x} ${r[0].y}`), r.length === 2 && t.push(`L ${r[1].x} ${r[1].y}`), r.length > 2) {
1018
1018
  const s = r.length - 1;
1019
1019
  let i = 0, n = 0, a = 0;
1020
1020
  r.forEach((h, d) => {
1021
1021
  let c = 0, g = 0, l = 0;
1022
- const u = d > 0, w = d < s, m = u && w;
1023
- if (u && (c = -i, g = -n, l = a), w) {
1022
+ const p = d > 0, w = d < s, m = p && w;
1023
+ if (p && (c = -i, g = -n, l = a), w) {
1024
1024
  const $ = r[d + 1];
1025
1025
  i = $.x - h.x, n = $.y - h.y, a = Math.sqrt(i * i + n * n);
1026
1026
  }
1027
- const E = a !== 0 ? Math.min((m ? e : 0) / a, d < s - 1 ? 0.5 : 1) : 0, A = m ? { x: h.x + i * E, y: h.y + n * E } : h, T = l !== 0 ? Math.min((m ? e : 0) / l, d > 1 ? 0.5 : 1) : 0, N = m ? { x: h.x + c * T, y: h.y + g * T } : h;
1028
- d > 0 && t.push(`L ${N.x} ${N.y}`), m && t.push(
1027
+ const E = a !== 0 ? Math.min((m ? e : 0) / a, d < s - 1 ? 0.5 : 1) : 0, A = m ? { x: h.x + i * E, y: h.y + n * E } : h, b = l !== 0 ? Math.min((m ? e : 0) / l, d > 1 ? 0.5 : 1) : 0, M = m ? { x: h.x + c * b, y: h.y + g * b } : h;
1028
+ d > 0 && t.push(`L ${M.x} ${M.y}`), m && t.push(
1029
1029
  `C ${h.x} ${h.y} ${h.x} ${h.y} ${A.x} ${A.y}`
1030
1030
  );
1031
1031
  });
@@ -1040,10 +1040,10 @@ class _e {
1040
1040
  const t = this.params.to;
1041
1041
  this.midpoint = { x: t.x / 2, y: t.y / 2 };
1042
1042
  const s = this.params.hasSourceArrow ? y(
1043
- { x: this.params.arrowLength, y: p.y },
1043
+ { x: this.params.arrowLength, y: u.y },
1044
1044
  this.params.sourceDirection,
1045
- p
1046
- ) : p, i = this.params.hasTargetArrow ? y(
1045
+ u
1046
+ ) : u, i = this.params.hasTargetArrow ? y(
1047
1047
  {
1048
1048
  x: this.params.to.x - this.params.arrowLength,
1049
1049
  y: this.params.to.y
@@ -1051,9 +1051,9 @@ class _e {
1051
1051
  this.params.targetDirection,
1052
1052
  this.params.to
1053
1053
  ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, a = n - this.params.roundness, h = y(
1054
- { x: a, y: p.y },
1054
+ { x: a, y: u.y },
1055
1055
  this.params.sourceDirection,
1056
- p
1056
+ u
1057
1057
  ), d = y(
1058
1058
  { x: this.params.to.x - a, y: this.params.to.y },
1059
1059
  this.params.targetDirection,
@@ -1061,12 +1061,12 @@ class _e {
1061
1061
  ), c = Math.max((h.x + d.x) / 2, n), g = this.params.to.y / 2, l = {
1062
1062
  x: this.params.flipX > 0 ? c : -n,
1063
1063
  y: h.y
1064
- }, u = { x: l.x, y: g }, w = {
1064
+ }, p = { x: l.x, y: g }, w = {
1065
1065
  x: this.params.flipX > 0 ? this.params.to.x - c : this.params.to.x + n,
1066
1066
  y: d.y
1067
1067
  }, m = { x: w.x, y: g };
1068
- this.path = L(
1069
- [s, h, l, u, m, w, d, i],
1068
+ this.path = R(
1069
+ [s, h, l, p, m, w, d, i],
1070
1070
  this.params.roundness
1071
1071
  );
1072
1072
  }
@@ -1077,10 +1077,10 @@ class et {
1077
1077
  o(this, "midpoint");
1078
1078
  this.params = e;
1079
1079
  const t = this.params.hasSourceArrow ? y(
1080
- { x: this.params.arrowLength, y: p.y },
1080
+ { x: this.params.arrowLength, y: u.y },
1081
1081
  this.params.sourceDirection,
1082
- p
1083
- ) : p, s = this.params.hasTargetArrow ? y(
1082
+ u
1083
+ ) : u, s = this.params.hasTargetArrow ? y(
1084
1084
  {
1085
1085
  x: this.params.to.x - this.params.arrowLength,
1086
1086
  y: this.params.to.y
@@ -1088,16 +1088,16 @@ class et {
1088
1088
  this.params.targetDirection,
1089
1089
  this.params.to
1090
1090
  ) : this.params.to, i = this.params.arrowLength + this.params.arrowOffset, n = y(
1091
- { x: i, y: p.y },
1091
+ { x: i, y: u.y },
1092
1092
  this.params.sourceDirection,
1093
- p
1093
+ u
1094
1094
  ), a = Math.cos(this.params.detourDirection) * this.params.detourDistance, h = Math.sin(this.params.detourDirection) * this.params.detourDistance, d = a * this.params.flipX, c = h * this.params.flipY, g = { x: n.x + d, y: n.y + c }, l = y(
1095
1095
  { x: this.params.to.x - i, y: this.params.to.y },
1096
1096
  this.params.targetDirection,
1097
1097
  this.params.to
1098
- ), u = { x: l.x + d, y: l.y + c }, w = { x: (g.x + u.x) / 2, y: (g.y + u.y) / 2 };
1099
- this.midpoint = W(w, e.flipX, e.flipY, e.to), this.path = L(
1100
- [t, n, g, u, l, s],
1098
+ ), p = { x: l.x + d, y: l.y + c }, w = { x: (g.x + p.x) / 2, y: (g.y + p.y) / 2 };
1099
+ this.midpoint = W(w, e.flipX, e.flipY, e.to), this.path = R(
1100
+ [t, n, g, p, l, s],
1101
1101
  this.params.roundness
1102
1102
  );
1103
1103
  }
@@ -1110,10 +1110,10 @@ class tt {
1110
1110
  const t = this.params.to;
1111
1111
  this.midpoint = { x: t.x / 2, y: t.y / 2 };
1112
1112
  const s = this.params.hasSourceArrow ? y(
1113
- { x: this.params.arrowLength, y: p.y },
1113
+ { x: this.params.arrowLength, y: u.y },
1114
1114
  this.params.sourceDirection,
1115
- p
1116
- ) : p, i = this.params.hasTargetArrow ? y(
1115
+ u
1116
+ ) : u, i = this.params.hasTargetArrow ? y(
1117
1117
  {
1118
1118
  x: this.params.to.x - this.params.arrowLength,
1119
1119
  y: this.params.to.y
@@ -1121,15 +1121,15 @@ class tt {
1121
1121
  this.params.targetDirection,
1122
1122
  this.params.to
1123
1123
  ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, a = y(
1124
- { x: n, y: p.y },
1124
+ { x: n, y: u.y },
1125
1125
  this.params.sourceDirection,
1126
- p
1126
+ u
1127
1127
  ), h = y(
1128
1128
  { x: this.params.to.x - n, y: this.params.to.y },
1129
1129
  this.params.targetDirection,
1130
1130
  this.params.to
1131
1131
  );
1132
- this.path = L([s, a, h, i], this.params.roundness);
1132
+ this.path = R([s, a, h, i], this.params.roundness);
1133
1133
  }
1134
1134
  }
1135
1135
  class rt {
@@ -1140,10 +1140,10 @@ class rt {
1140
1140
  const t = this.params.to;
1141
1141
  this.midpoint = { x: t.x / 2, y: t.y / 2 };
1142
1142
  const s = this.params.hasSourceArrow ? y(
1143
- { x: this.params.arrowLength, y: p.y },
1143
+ { x: this.params.arrowLength, y: u.y },
1144
1144
  this.params.sourceDirection,
1145
- p
1146
- ) : p, i = this.params.hasTargetArrow ? y(
1145
+ u
1146
+ ) : u, i = this.params.hasTargetArrow ? y(
1147
1147
  {
1148
1148
  x: this.params.to.x - this.params.arrowLength,
1149
1149
  y: this.params.to.y
@@ -1151,9 +1151,9 @@ class rt {
1151
1151
  this.params.targetDirection,
1152
1152
  this.params.to
1153
1153
  ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, a = n - this.params.roundness, h = y(
1154
- { x: a, y: p.y },
1154
+ { x: a, y: u.y },
1155
1155
  this.params.sourceDirection,
1156
- p
1156
+ u
1157
1157
  ), d = y(
1158
1158
  { x: this.params.to.x - a, y: this.params.to.y },
1159
1159
  this.params.targetDirection,
@@ -1161,12 +1161,12 @@ class rt {
1161
1161
  ), c = Math.max((h.y + d.y) / 2, n), g = this.params.to.x / 2, l = {
1162
1162
  x: h.x,
1163
1163
  y: this.params.flipY > 0 ? c : -n
1164
- }, u = { x: g, y: l.y }, w = {
1164
+ }, p = { x: g, y: l.y }, w = {
1165
1165
  x: d.x,
1166
1166
  y: this.params.flipY > 0 ? this.params.to.y - c : this.params.to.y + n
1167
1167
  }, m = { x: g, y: w.y };
1168
- this.path = L(
1169
- [s, h, l, u, m, w, d, i],
1168
+ this.path = R(
1169
+ [s, h, l, p, m, w, d, i],
1170
1170
  this.params.roundness
1171
1171
  );
1172
1172
  }
@@ -1177,18 +1177,18 @@ class J {
1177
1177
  o(this, "midpoint");
1178
1178
  this.params = e;
1179
1179
  const t = this.params.arrowOffset, s = this.params.side, i = this.params.arrowLength + t, n = i + 2 * s, h = [
1180
- { x: this.params.arrowLength, y: p.y },
1181
- { x: i, y: p.y },
1180
+ { x: this.params.arrowLength, y: u.y },
1181
+ { x: i, y: u.y },
1182
1182
  { x: i, y: this.params.side },
1183
1183
  { x: n, y: this.params.side },
1184
1184
  { x: n, y: -this.params.side },
1185
1185
  { x: i, y: -this.params.side },
1186
- { x: i, y: p.y },
1187
- { x: this.params.arrowLength, y: p.y }
1186
+ { x: i, y: u.y },
1187
+ { x: this.params.arrowLength, y: u.y }
1188
1188
  ].map(
1189
- (c) => y(c, this.params.sourceDirection, p)
1190
- ), d = `M ${p.x} ${p.y} L ${h[0].x} ${h[0].y} `;
1191
- this.path = `${this.params.hasSourceArrow || this.params.hasTargetArrow ? "" : d}${L(h, this.params.roundness)}`, this.midpoint = { x: (h[3].x + h[4].x) / 2, y: (h[3].y + h[4].y) / 2 };
1189
+ (c) => y(c, this.params.sourceDirection, u)
1190
+ ), d = `M ${u.x} ${u.y} L ${h[0].x} ${h[0].y} `;
1191
+ this.path = `${this.params.hasSourceArrow || this.params.hasTargetArrow ? "" : d}${R(h, this.params.roundness)}`, this.midpoint = { x: (h[3].x + h[4].x) / 2, y: (h[3].y + h[4].y) / 2 };
1192
1192
  }
1193
1193
  }
1194
1194
  class st {
@@ -1197,19 +1197,19 @@ class st {
1197
1197
  o(this, "midpoint");
1198
1198
  this.params = e;
1199
1199
  const t = this.params.smallRadius, s = this.params.radius, i = t + s, n = t * s / i, a = Math.sqrt(i * i - t * t), h = a * t / i, d = a + s + this.params.arrowLength, c = this.params.arrowLength + h, l = [
1200
- { x: this.params.arrowLength, y: p.y },
1200
+ { x: this.params.arrowLength, y: u.y },
1201
1201
  { x: c, y: n },
1202
1202
  { x: c, y: -n },
1203
1203
  { x: d, y: 0 }
1204
1204
  ].map(
1205
- (m) => y(m, this.params.sourceDirection, p)
1206
- ), u = [
1205
+ (m) => y(m, this.params.sourceDirection, u)
1206
+ ), p = [
1207
1207
  `M ${l[0].x} ${l[0].y}`,
1208
1208
  `A ${t} ${t} 0 0 1 ${l[1].x} ${l[1].y}`,
1209
1209
  `A ${s} ${s} 0 1 0 ${l[2].x} ${l[2].y}`,
1210
1210
  `A ${t} ${t} 0 0 1 ${l[0].x} ${l[0].y}`
1211
1211
  ].join(" "), w = `M 0 0 L ${l[0].x} ${l[0].y} `;
1212
- this.path = `${this.params.hasSourceArrow || this.params.hasTargetArrow ? "" : w}${u}`, this.midpoint = l[3];
1212
+ this.path = `${this.params.hasSourceArrow || this.params.hasTargetArrow ? "" : w}${p}`, this.midpoint = l[3];
1213
1213
  }
1214
1214
  }
1215
1215
  class ot {
@@ -1231,7 +1231,7 @@ class ot {
1231
1231
  offset: this.params.sourceOffset,
1232
1232
  hasArrow: this.params.hasSourceArrow,
1233
1233
  flip: 1,
1234
- shift: p
1234
+ shift: u
1235
1235
  }), n = this.createDirectLinePoint({
1236
1236
  offset: this.params.targetOffset,
1237
1237
  hasArrow: this.params.hasTargetArrow,
@@ -1254,10 +1254,10 @@ class it {
1254
1254
  o(this, "midpoint");
1255
1255
  this.params = e;
1256
1256
  const t = this.params.hasSourceArrow ? y(
1257
- { x: this.params.arrowLength, y: p.y },
1257
+ { x: this.params.arrowLength, y: u.y },
1258
1258
  this.params.sourceDirection,
1259
- p
1260
- ) : p, s = this.params.hasTargetArrow ? y(
1259
+ u
1260
+ ) : u, s = this.params.hasTargetArrow ? y(
1261
1261
  {
1262
1262
  x: this.params.to.x - this.params.arrowLength,
1263
1263
  y: this.params.to.y
@@ -1265,9 +1265,9 @@ class it {
1265
1265
  this.params.targetDirection,
1266
1266
  this.params.to
1267
1267
  ) : this.params.to, i = this.params.arrowLength + this.params.arrowOffset, n = y(
1268
- { x: i, y: p.y },
1268
+ { x: i, y: u.y },
1269
1269
  this.params.sourceDirection,
1270
- p
1270
+ u
1271
1271
  ), a = y(
1272
1272
  { x: this.params.to.x - i, y: this.params.to.y },
1273
1273
  this.params.targetDirection,
@@ -1276,7 +1276,7 @@ class it {
1276
1276
  x: (n.x + a.x) / 2,
1277
1277
  y: g
1278
1278
  };
1279
- this.midpoint = W(l, e.flipX, e.flipY, e.to), this.path = L(
1279
+ this.midpoint = W(l, e.flipX, e.flipY, e.to), this.path = R(
1280
1280
  [
1281
1281
  t,
1282
1282
  n,
@@ -1295,10 +1295,10 @@ class nt {
1295
1295
  o(this, "midpoint");
1296
1296
  this.params = e;
1297
1297
  const t = this.params.hasSourceArrow ? y(
1298
- { x: this.params.arrowLength, y: p.y },
1298
+ { x: this.params.arrowLength, y: u.y },
1299
1299
  this.params.sourceDirection,
1300
- p
1301
- ) : p, s = this.params.hasTargetArrow ? y(
1300
+ u
1301
+ ) : u, s = this.params.hasTargetArrow ? y(
1302
1302
  {
1303
1303
  x: this.params.to.x - this.params.arrowLength,
1304
1304
  y: this.params.to.y
@@ -1306,9 +1306,9 @@ class nt {
1306
1306
  this.params.targetDirection,
1307
1307
  this.params.to
1308
1308
  ) : this.params.to, i = this.params.arrowLength + this.params.arrowOffset, n = y(
1309
- { x: i, y: p.y },
1309
+ { x: i, y: u.y },
1310
1310
  this.params.sourceDirection,
1311
- p
1311
+ u
1312
1312
  ), a = y(
1313
1313
  { x: this.params.to.x - i, y: this.params.to.y },
1314
1314
  this.params.targetDirection,
@@ -1317,7 +1317,7 @@ class nt {
1317
1317
  x: g,
1318
1318
  y: (n.y + a.y) / 2
1319
1319
  };
1320
- this.midpoint = W(l, e.flipX, e.flipY, e.to), this.path = L(
1320
+ this.midpoint = W(l, e.flipX, e.flipY, e.to), this.path = R(
1321
1321
  [
1322
1322
  t,
1323
1323
  n,
@@ -1383,9 +1383,9 @@ class k {
1383
1383
  x: i,
1384
1384
  y: n
1385
1385
  };
1386
- let l = { x: -c.x, y: -c.y }, u;
1387
- e.category === C.PortCycle ? (u = this.params.createCyclePath, l = d) : e.category === C.NodeCycle ? u = this.params.createDetourPath : u = this.params.createLinePath;
1388
- const w = u(
1386
+ let l = { x: -c.x, y: -c.y }, p;
1387
+ e.category === C.PortCycle ? (p = this.params.createCyclePath, l = d) : e.category === C.NodeCycle ? p = this.params.createDetourPath : p = this.params.createLinePath;
1388
+ const w = p(
1389
1389
  d,
1390
1390
  c,
1391
1391
  g,
@@ -1396,7 +1396,7 @@ class k {
1396
1396
  let m = null;
1397
1397
  this.sourceArrow && (m = this.arrowRenderer({
1398
1398
  direction: d,
1399
- shift: p,
1399
+ shift: u,
1400
1400
  arrowLength: this.params.arrowLength
1401
1401
  }), this.sourceArrow.setAttribute("d", m));
1402
1402
  let v = null;
@@ -1413,24 +1413,24 @@ class k {
1413
1413
  }
1414
1414
  const at = (r) => (e) => {
1415
1415
  const s = [
1416
- p,
1416
+ u,
1417
1417
  { x: e.arrowLength, y: r.radius },
1418
1418
  { x: e.arrowLength, y: -r.radius }
1419
1419
  ].map(
1420
- (h) => y(h, e.direction, p)
1420
+ (h) => y(h, e.direction, u)
1421
1421
  ).map((h) => ({
1422
1422
  x: h.x + e.shift.x,
1423
1423
  y: h.y + e.shift.y
1424
1424
  })), i = `M ${s[0].x} ${s[0].y}`, n = `L ${s[1].x} ${s[1].y}`, a = `L ${s[2].x} ${s[2].y}`;
1425
1425
  return `${i} ${n} ${a} Z`;
1426
1426
  }, ht = (r) => (e) => {
1427
- const t = r.radius, s = e.arrowLength, i = (s * s + 2 * s * t) / (2 * t), n = i + t, a = s + t - t * (s + t) / n, h = t * i / n, c = [p, { x: a, y: -h }, { x: a, y: h }].map(
1428
- (m) => y(m, e.direction, p)
1427
+ const t = r.radius, s = e.arrowLength, i = (s * s + 2 * s * t) / (2 * t), n = i + t, a = s + t - t * (s + t) / n, h = t * i / n, c = [u, { x: a, y: -h }, { x: a, y: h }].map(
1428
+ (m) => y(m, e.direction, u)
1429
1429
  ).map((m) => ({
1430
1430
  x: m.x + e.shift.x,
1431
1431
  y: m.y + e.shift.y
1432
- })), g = `M ${c[0].x} ${c[0].y}`, l = `A ${i} ${i} 0 0 0 ${c[1].x} ${c[1].y}`, u = `A ${t} ${t} 0 0 0 ${c[2].x} ${c[2].y}`, w = `A ${i} ${i} 0 0 0 ${c[0].x} ${c[0].y}`;
1433
- return `${g} ${l} ${u} ${w}`;
1432
+ })), g = `M ${c[0].x} ${c[0].y}`, l = `A ${i} ${i} 0 0 0 ${c[1].x} ${c[1].y}`, p = `A ${t} ${t} 0 0 0 ${c[2].x} ${c[2].y}`, w = `A ${i} ${i} 0 0 0 ${c[0].x} ${c[0].y}`;
1433
+ return `${g} ${l} ${p} ${w}`;
1434
1434
  }, dt = (r) => (e) => {
1435
1435
  const t = r.smallRadius, s = r.radius, i = y(
1436
1436
  {
@@ -1445,8 +1445,8 @@ const at = (r) => (e) => {
1445
1445
  x: e.arrowLength + r.smallRadius,
1446
1446
  y: 0
1447
1447
  }
1448
- ), a = [p, { x: i.x, y: -i.y }, i].map(
1449
- (l) => y(l, e.direction, p)
1448
+ ), a = [u, { x: i.x, y: -i.y }, i].map(
1449
+ (l) => y(l, e.direction, u)
1450
1450
  ).map((l) => ({
1451
1451
  x: l.x + e.shift.x,
1452
1452
  y: l.y + e.shift.y
@@ -1782,13 +1782,13 @@ class Me {
1782
1782
  });
1783
1783
  this.line.setAttribute("d", c.path);
1784
1784
  let g = null, l = null;
1785
- const u = c.diagonalDistance;
1786
- if (u === 0)
1785
+ const p = c.diagonalDistance;
1786
+ if (p === 0)
1787
1787
  this.sourceArrow !== null && (g = "", this.sourceArrow.setAttribute("d", g)), this.targetArrow !== null && (l = "", this.targetArrow.setAttribute("d", l));
1788
1788
  else {
1789
1789
  const w = {
1790
- x: d.x / u,
1791
- y: d.y / u
1790
+ x: d.x / p,
1791
+ y: d.y / p
1792
1792
  };
1793
1793
  if (this.sourceArrow) {
1794
1794
  const m = {
@@ -2152,7 +2152,7 @@ class Q {
2152
2152
  const t = e.currentTarget, s = this.graph.getElementNodeId(t), i = this.graph.getNode(s);
2153
2153
  if (!this.params.nodeDragVerifier(s))
2154
2154
  return;
2155
- e.stopPropagation();
2155
+ this.params.onNodeDragStarted(s), e.stopPropagation();
2156
2156
  const a = this.calculateContentPoint({
2157
2157
  x: e.clientX,
2158
2158
  y: e.clientY
@@ -2292,7 +2292,7 @@ class Q {
2292
2292
  x: e.x - t.x,
2293
2293
  y: e.y - t.y
2294
2294
  }, i = this.canvas.viewport.getViewportMatrix();
2295
- return D(i, s);
2295
+ return N(i, s);
2296
2296
  }
2297
2297
  adjustNodeCoords(e) {
2298
2298
  const t = this.params.gridSize;
@@ -2649,27 +2649,27 @@ class ee {
2649
2649
  grabPort(e, t, s) {
2650
2650
  const i = this.canvas.graph.getPort(e);
2651
2651
  this.staticPortId = e;
2652
- const n = i.element.getBoundingClientRect(), a = n.x + n.width / 2, h = n.y + n.height / 2, d = this.overlayLayer.getBoundingClientRect(), c = this.canvas.viewport.getViewportMatrix(), g = D(c, {
2652
+ const n = i.element.getBoundingClientRect(), a = n.x + n.width / 2, h = n.y + n.height / 2, d = this.overlayLayer.getBoundingClientRect(), c = this.canvas.viewport.getViewportMatrix(), g = N(c, {
2653
2653
  x: a - d.x,
2654
2654
  y: h - d.y
2655
- }), l = D(c, {
2655
+ }), l = N(c, {
2656
2656
  x: t.x - d.x,
2657
2657
  y: t.y - d.y
2658
- }), u = {
2659
- overlayId: b.Static,
2658
+ }), p = {
2659
+ overlayId: T.Static,
2660
2660
  portCoords: g,
2661
2661
  portDirection: i.direction
2662
2662
  }, w = {
2663
- overlayId: b.Dragging,
2663
+ overlayId: T.Dragging,
2664
2664
  portCoords: l,
2665
2665
  portDirection: this.params.dragPortDirection
2666
2666
  };
2667
2667
  this.isTargetDragging = s === "direct";
2668
- const [m, v] = this.isTargetDragging ? [u, w] : [w, u];
2668
+ const [m, v] = this.isTargetDragging ? [p, w] : [w, p];
2669
2669
  this.overlayCanvas.addNode(F(m)), this.overlayCanvas.addNode(F(v)), this.overlayCanvas.addEdge({
2670
2670
  from: m.overlayId,
2671
2671
  to: v.overlayId,
2672
- shape: this.params.edgeShapeFactory(b.Edge)
2672
+ shape: this.params.edgeShapeFactory(T.Edge)
2673
2673
  });
2674
2674
  }
2675
2675
  resetDragState() {
@@ -2691,8 +2691,8 @@ class ee {
2691
2691
  const t = this.overlayLayer.getBoundingClientRect(), s = {
2692
2692
  x: e.x - t.x,
2693
2693
  y: e.y - t.y
2694
- }, i = this.canvas.viewport.getViewportMatrix(), n = D(i, s);
2695
- this.overlayCanvas.updateNode(b.Dragging, {
2694
+ }, i = this.canvas.viewport.getViewportMatrix(), n = N(i, s);
2695
+ this.overlayCanvas.updateNode(T.Dragging, {
2696
2696
  x: n.x,
2697
2697
  y: n.y
2698
2698
  });
@@ -2751,10 +2751,10 @@ class te {
2751
2751
  const d = this.canvas.graph.getPort(e), c = this.canvas.graph.getPort(h), g = c.element.getBoundingClientRect(), l = {
2752
2752
  x: g.x + g.width / 2,
2753
2753
  y: g.y + g.height / 2
2754
- }, u = this.canvas.viewport.getViewportMatrix(), w = this.overlayLayer.getBoundingClientRect(), m = D(u, {
2754
+ }, p = this.canvas.viewport.getViewportMatrix(), w = this.overlayLayer.getBoundingClientRect(), m = N(p, {
2755
2755
  x: l.x - w.x,
2756
2756
  y: l.y - w.y
2757
- }), v = D(u, {
2757
+ }), v = N(p, {
2758
2758
  x: t.x - w.x,
2759
2759
  y: t.y - w.y
2760
2760
  });
@@ -2766,21 +2766,21 @@ class te {
2766
2766
  priority: i.priority
2767
2767
  }, this.canvas.removeEdge(s);
2768
2768
  const E = {
2769
- overlayId: b.Static,
2769
+ overlayId: T.Static,
2770
2770
  portCoords: m,
2771
2771
  portDirection: c.direction
2772
2772
  }, A = {
2773
- overlayId: b.Dragging,
2773
+ overlayId: T.Dragging,
2774
2774
  portCoords: v,
2775
2775
  portDirection: d.direction
2776
- }, [R, T] = this.isTargetDragging ? [E, A] : [A, E];
2777
- this.overlayCanvas.addNode(F(R)), this.overlayCanvas.addNode(F(T));
2778
- const N = this.params.draggingEdgeShapeFactory !== null ? this.params.draggingEdgeShapeFactory(b.Edge) : i.shape;
2776
+ }, [D, b] = this.isTargetDragging ? [E, A] : [A, E];
2777
+ this.overlayCanvas.addNode(F(D)), this.overlayCanvas.addNode(F(b));
2778
+ const M = this.params.draggingEdgeShapeFactory !== null ? this.params.draggingEdgeShapeFactory(T.Edge) : i.shape;
2779
2779
  return this.overlayCanvas.addEdge({
2780
- id: b.Edge,
2781
- from: R.overlayId,
2782
- to: T.overlayId,
2783
- shape: N
2780
+ id: T.Edge,
2781
+ from: D.overlayId,
2782
+ to: b.overlayId,
2783
+ shape: M
2784
2784
  }), !0;
2785
2785
  }
2786
2786
  resetDragState() {
@@ -2790,15 +2790,15 @@ class te {
2790
2790
  const t = this.overlayLayer.getBoundingClientRect(), s = {
2791
2791
  x: e.x - t.x,
2792
2792
  y: e.y - t.y
2793
- }, i = this.canvas.viewport.getViewportMatrix(), n = D(i, s);
2794
- this.overlayCanvas.updateNode(b.Dragging, {
2793
+ }, i = this.canvas.viewport.getViewportMatrix(), n = N(i, s);
2794
+ this.overlayCanvas.updateNode(T.Dragging, {
2795
2795
  x: n.x,
2796
2796
  y: n.y
2797
2797
  });
2798
2798
  }
2799
2799
  tryCreateConnection(e) {
2800
2800
  const t = xe(this.canvas.graph, e);
2801
- if (this.overlayCanvas.removeEdge(b.Edge), t === null) {
2801
+ if (this.overlayCanvas.removeEdge(T.Edge), t === null) {
2802
2802
  const d = this.draggingEdgePayload;
2803
2803
  this.params.onEdgeReattachInterrupted({
2804
2804
  id: d.id,
@@ -3055,20 +3055,22 @@ const j = (r) => () => r, we = j(0), Tt = () => {
3055
3055
  }
3056
3056
  };
3057
3057
  }, Mt = (r) => {
3058
- var u, w, m, v, E;
3059
- const e = ((u = r.events) == null ? void 0 : u.onNodeDrag) ?? (() => {
3060
- }), t = r.nodeDragVerifier ?? (() => !0), s = ((w = r.events) == null ? void 0 : w.onNodeDragFinished) ?? (() => {
3061
- }), i = r.moveOnTop !== !1, n = r.moveEdgesOnTop !== !1 && i, a = (m = r.mouse) == null ? void 0 : m.dragCursor, h = a !== void 0 ? a : "grab", d = (v = r.mouse) == null ? void 0 : v.mouseDownEventVerifier, c = d !== void 0 ? d : (A) => A.button === 0, g = (E = r.mouse) == null ? void 0 : E.mouseUpEventVerifier, l = g !== void 0 ? g : (A) => A.button === 0;
3058
+ var w, m, v, E, A, D;
3059
+ const e = ((w = r.events) == null ? void 0 : w.onNodeDragStarted) ?? (() => {
3060
+ }), t = ((m = r.events) == null ? void 0 : m.onNodeDrag) ?? (() => {
3061
+ }), s = r.nodeDragVerifier ?? (() => !0), i = ((v = r.events) == null ? void 0 : v.onNodeDragFinished) ?? (() => {
3062
+ }), n = r.moveOnTop !== !1, a = r.moveEdgesOnTop !== !1 && n, h = (E = r.mouse) == null ? void 0 : E.dragCursor, d = h !== void 0 ? h : "grab", c = (A = r.mouse) == null ? void 0 : A.mouseDownEventVerifier, g = c !== void 0 ? c : (b) => b.button === 0, l = (D = r.mouse) == null ? void 0 : D.mouseUpEventVerifier, p = l !== void 0 ? l : (b) => b.button === 0;
3062
3063
  return {
3063
- moveOnTop: i,
3064
- moveEdgesOnTop: n,
3065
- dragCursor: h,
3064
+ moveOnTop: n,
3065
+ moveEdgesOnTop: a,
3066
+ dragCursor: d,
3066
3067
  gridSize: r.gridSize ?? null,
3067
- mouseDownEventVerifier: c,
3068
- mouseUpEventVerifier: l,
3069
- onNodeDrag: e,
3070
- nodeDragVerifier: t,
3071
- onNodeDragFinished: s
3068
+ mouseDownEventVerifier: g,
3069
+ mouseUpEventVerifier: p,
3070
+ onNodeDragStarted: e,
3071
+ onNodeDrag: t,
3072
+ nodeDragVerifier: s,
3073
+ onNodeDragFinished: i
3072
3074
  };
3073
3075
  }, Lt = (r) => {
3074
3076
  const e = r.minX !== null ? r.minX : -1 / 0, t = r.maxX !== null ? r.maxX : 1 / 0, s = r.minY !== null ? r.minY : -1 / 0, i = r.maxY !== null ? r.maxY : 1 / 0;
@@ -3127,17 +3129,17 @@ const j = (r) => () => r, we = j(0), Tt = () => {
3127
3129
  });
3128
3130
  }
3129
3131
  }, me = (r) => {
3130
- var m, v, E, A, R, T, N, $, ne, ae, he, de;
3132
+ var m, v, E, A, D, b, M, $, ne, ae, he, de;
3131
3133
  const e = (m = r == null ? void 0 : r.scale) == null ? void 0 : m.mouseWheelSensitivity, t = e !== void 0 ? e : 1.2, s = r == null ? void 0 : r.transformPreprocessor;
3132
3134
  let i;
3133
3135
  s !== void 0 ? Array.isArray(s) ? i = Ct(
3134
3136
  s.map(
3135
- (M) => fe(M)
3137
+ (L) => fe(L)
3136
3138
  )
3137
- ) : i = fe(s) : i = (M) => M.nextTransform;
3139
+ ) : i = fe(s) : i = (L) => L.nextTransform;
3138
3140
  const n = ((v = r == null ? void 0 : r.shift) == null ? void 0 : v.cursor) !== void 0 ? r.shift.cursor : "grab", a = ((E = r == null ? void 0 : r.events) == null ? void 0 : E.onBeforeTransformChange) ?? (() => {
3139
3141
  }), h = ((A = r == null ? void 0 : r.events) == null ? void 0 : A.onTransformChange) ?? (() => {
3140
- }), d = (R = r == null ? void 0 : r.shift) == null ? void 0 : R.mouseDownEventVerifier, c = d !== void 0 ? d : (M) => M.button === 0, g = (T = r == null ? void 0 : r.shift) == null ? void 0 : T.mouseUpEventVerifier, l = g !== void 0 ? g : (M) => M.button === 0, u = (N = r == null ? void 0 : r.scale) == null ? void 0 : N.mouseWheelEventVerifier, w = u !== void 0 ? u : () => !0;
3142
+ }), d = (D = r == null ? void 0 : r.shift) == null ? void 0 : D.mouseDownEventVerifier, c = d !== void 0 ? d : (L) => L.button === 0, g = (b = r == null ? void 0 : r.shift) == null ? void 0 : b.mouseUpEventVerifier, l = g !== void 0 ? g : (L) => L.button === 0, p = (M = r == null ? void 0 : r.scale) == null ? void 0 : M.mouseWheelEventVerifier, w = p !== void 0 ? p : () => !0;
3141
3143
  return {
3142
3144
  wheelSensitivity: t,
3143
3145
  onTransformStarted: (($ = r == null ? void 0 : r.events) == null ? void 0 : $.onTransformStarted) ?? (() => {
@@ -3176,7 +3178,7 @@ const j = (r) => () => r, we = j(0), Tt = () => {
3176
3178
  };
3177
3179
  }, Ut = (r, e, t) => {
3178
3180
  var c, g, l;
3179
- const s = () => "direct", i = (u) => u, n = (u) => u.button === 0, a = () => {
3181
+ const s = () => "direct", i = (p) => p, n = (p) => p.button === 0, a = () => {
3180
3182
  }, h = () => {
3181
3183
  }, d = () => {
3182
3184
  };
@@ -3193,8 +3195,8 @@ const j = (r) => () => r, we = j(0), Tt = () => {
3193
3195
  };
3194
3196
  }, Bt = (r, e) => {
3195
3197
  var c, g, l;
3196
- const t = (u) => u, s = (u) => u.button === 0 && u.ctrlKey, i = (u) => u.button === 0, n = (u) => {
3197
- const w = e.getPortAdjacentEdgeIds(u);
3198
+ const t = (p) => p, s = (p) => p.button === 0 && p.ctrlKey, i = (p) => p.button === 0, n = (p) => {
3199
+ const w = e.getPortAdjacentEdgeIds(p);
3198
3200
  return w.length > 0 ? w[w.length - 1] : null;
3199
3201
  }, a = () => {
3200
3202
  }, h = () => {
@@ -3268,12 +3270,12 @@ class $e {
3268
3270
  const c = s[d], g = i.getVector(h, c);
3269
3271
  if (g.d > this.effectiveDistance)
3270
3272
  continue;
3271
- const l = this.k / g.d2, u = l * g.ex, w = l * g.ey, m = u / 2, v = w / 2, E = t.get(h), A = t.get(c);
3273
+ const l = this.k / g.d2, p = l * g.ex, w = l * g.ey, m = p / 2, v = w / 2, E = t.get(h), A = t.get(c);
3272
3274
  E.x -= m, E.y -= v, A.x += m, A.y += v;
3273
3275
  }
3274
3276
  }
3275
3277
  return this.graph.getAllEdgeIds().forEach((a) => {
3276
- const h = this.graph.getEdge(a), d = this.graph.getPort(h.from), c = this.graph.getPort(h.to), g = i.getVector(d.nodeId, c.nodeId), u = (g.d - this.edgeEquilibriumLength) * this.edgeStiffness / 2, w = g.ex * u, m = g.ey * u, v = t.get(d.nodeId), E = t.get(c.nodeId);
3278
+ const h = this.graph.getEdge(a), d = this.graph.getPort(h.from), c = this.graph.getPort(h.to), g = i.getVector(d.nodeId, c.nodeId), p = (g.d - this.edgeEquilibriumLength) * this.edgeStiffness / 2, w = g.ex * p, m = g.ey * p, v = t.get(d.nodeId), E = t.get(c.nodeId);
3277
3279
  v.x += w, v.y += m, E.x -= w, E.y -= m;
3278
3280
  }), this.currentCoords.forEach((a, h) => {
3279
3281
  const d = t.get(h), c = {
@@ -3409,7 +3411,9 @@ const Ue = (r) => {
3409
3411
  applyOn: Ht(r == null ? void 0 : r.applyOn)
3410
3412
  }), Kt = (r, e) => ({
3411
3413
  ...r,
3412
- nodeDragVerifier: (t) => (e.add(t), r.nodeDragVerifier(t)),
3414
+ onNodeDragStarted: (t) => {
3415
+ e.add(t), r.onNodeDragStarted(t);
3416
+ },
3413
3417
  onNodeDragFinished: (t) => {
3414
3418
  e.delete(t), r.onNodeDragFinished(t);
3415
3419
  }
@@ -1 +1 @@
1
- (function(E,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(E=typeof globalThis<"u"?globalThis:E||self,A(E.HtmlGraph={}))})(this,function(E){"use strict";var Qt=Object.defineProperty;var qt=(E,A,D)=>A in E?Qt(E,A,{enumerable:!0,configurable:!0,writable:!0,value:D}):E[A]=D;var o=(E,A,D)=>qt(E,typeof A!="symbol"?A+"":A,D);const A=(r,e)=>({x:r.scale*e.x+r.x,y:r.scale*e.y+r.y});var D=(r=>(r.Line="line",r.NodeCycle="node-cycle",r.PortCycle="port-cycle",r))(D||{});const Ye=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r.style.overflow="hidden",r},je=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="0",r.style.height="0",r},Ge=r=>{r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.visibility="hidden"};class de{constructor(e,t,s){o(this,"host",Ye());o(this,"container",je());o(this,"edgeIdToElementMap",new Map);o(this,"attachedNodeIds",new Set);o(this,"applyTransform",()=>{const e=this.viewportStore.getContentMatrix();this.container.style.transform=`matrix(${e.scale}, 0, 0, ${e.scale}, ${e.x}, ${e.y})`});this.graphStore=e,this.viewportStore=t,this.element=s,this.element.appendChild(this.host),this.host.appendChild(this.container),this.viewportStore.onAfterUpdated.subscribe(this.applyTransform)}attachNode(e){const t=this.graphStore.getNode(e);Ge(t.element),this.attachedNodeIds.add(e),this.container.appendChild(t.element),this.updateNodePosition(e),this.updateNodePriority(e),t.element.style.visibility="visible"}detachNode(e){const t=this.graphStore.getNode(e);this.container.removeChild(t.element),this.attachedNodeIds.delete(e)}attachEdge(e){const t=this.graphStore.getEdge(e).payload.shape.svg;this.edgeIdToElementMap.set(e,t),this.container.appendChild(t),this.renderEdge(e),this.updateEdgePriority(e)}detachEdge(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t),this.edgeIdToElementMap.delete(e)}clear(){this.edgeIdToElementMap.forEach((e,t)=>{this.detachEdge(t)}),this.attachedNodeIds.forEach(e=>{this.detachNode(e)})}destroy(){this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform),this.element.removeChild(this.host),this.host.removeChild(this.container)}updateNodePosition(e){const t=this.graphStore.getNode(e),{width:s,height:i}=t.element.getBoundingClientRect(),n=this.viewportStore.getViewportMatrix().scale,{payload:a}=t,h=a.centerFn(s,i),d=a.x-n*h.x,c=a.y-n*h.y;t.element.style.transform=`translate(${d}px, ${c}px)`}updateNodePriority(e){const t=this.graphStore.getNode(e);t.element.style.zIndex=`${t.payload.priority}`}updateEdgeShape(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t);const i=this.graphStore.getEdge(e).payload.shape.svg;this.edgeIdToElementMap.set(e,i),this.container.appendChild(i)}renderEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),i=this.graphStore.getPort(t.to),n=s.element.getBoundingClientRect(),a=i.element.getBoundingClientRect(),h=this.host.getBoundingClientRect(),d=this.viewportStore.getViewportMatrix(),c=this.createEdgeRenderPort(s,n,h,d),g=this.createEdgeRenderPort(i,a,h,d);let l=D.Line;s.element===i.element?l=D.PortCycle:s.nodeId===i.nodeId&&(l=D.NodeCycle),t.payload.shape.render({from:c,to:g,category:l})}updateEdgePriority(e){const t=this.graphStore.getEdge(e);t.payload.shape.svg.style.zIndex=`${t.payload.priority}`}createEdgeRenderPort(e,t,s,i){const n={x:t.left-s.left,y:t.top-s.top},a=A(i,n);return{x:a.x,y:a.y,width:t.width*i.scale,height:t.height*i.scale,direction:e.payload.direction}}}class Ke{constructor(e){o(this,"xFrom",1/0);o(this,"yFrom",1/0);o(this,"xTo",1/0);o(this,"yTo",1/0);this.graphStore=e}setRenderingBox(e){this.xFrom=e.x,this.xTo=e.x+e.width,this.yFrom=e.y,this.yTo=e.y+e.height}hasNode(e){const t=this.graphStore.getNode(e).payload,{x:s,y:i}=t;return s>=this.xFrom&&s<=this.xTo&&i>=this.yFrom&&i<=this.yTo}hasEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,i=this.graphStore.getPort(t.to).nodeId,n=this.graphStore.getNode(s).payload,a=this.graphStore.getNode(i).payload,h=Math.min(n.x,a.x),d=Math.max(n.x,a.x),c=Math.min(n.y,a.y),g=Math.max(n.y,a.y);return h<=this.xTo&&d>=this.xFrom&&c<=this.yTo&&g>=this.yFrom}}class Ze{constructor(e,t,s,i){o(this,"attachedNodes",new Set);o(this,"attachedEdges",new Set);o(this,"renderingBox");o(this,"updateViewport",e=>{this.renderingBox.setRenderingBox(e);const t=new Set,s=new Set,i=new Set,n=new Set;this.graphStore.getAllNodeIds().forEach(a=>{const h=this.renderingBox.hasNode(a),d=this.attachedNodes.has(a);h&&!d?t.add(a):!h&&d&&s.add(a)}),this.graphStore.getAllEdgeIds().forEach(a=>{const h=this.renderingBox.hasEdge(a),d=this.attachedEdges.has(a),c=this.graphStore.getEdge(a),g=this.graphStore.getPort(c.from).nodeId,l=this.graphStore.getPort(c.to).nodeId;h&&(this.renderingBox.hasNode(g)||(t.add(g),s.delete(g)),this.renderingBox.hasNode(l)||(t.add(l),s.delete(l))),h&&!d?i.add(a):!h&&d&&n.add(a)}),n.forEach(a=>{this.handleDetachEdge(a)}),s.forEach(a=>{this.handleDetachNode(a)}),t.forEach(a=>{this.attachedNodes.has(a)||this.handleAttachNode(a)}),i.forEach(a=>{this.handleAttachEdge(a)})});this.htmlView=e,this.graphStore=t,this.trigger=s,this.params=i,this.renderingBox=new Ke(this.graphStore),this.trigger.subscribe(this.updateViewport)}attachNode(e){this.renderingBox.hasNode(e)&&this.handleAttachNode(e)}detachNode(e){this.attachedNodes.has(e)&&this.handleDetachNode(e)}attachEdge(e){this.renderingBox.hasEdge(e)&&this.attachEdgeEntities(e)}detachEdge(e){this.attachedEdges.has(e)&&this.handleDetachEdge(e)}updateNodePosition(e){this.attachedNodes.has(e)?this.htmlView.updateNodePosition(e):this.renderingBox.hasNode(e)&&(this.handleAttachNode(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(t=>{this.attachEdgeEntities(t)}))}updateNodePriority(e){this.attachedNodes.has(e)&&this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgeShape(e)}renderEdge(e){this.attachedEdges.has(e)&&this.htmlView.renderEdge(e)}updateEdgePriority(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgePriority(e)}clear(){this.htmlView.clear(),this.attachedNodes.clear(),this.attachedEdges.clear()}destroy(){this.clear(),this.htmlView.destroy(),this.trigger.unsubscribe(this.updateViewport)}attachEdgeEntities(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,i=this.graphStore.getPort(t.to).nodeId;this.attachedNodes.has(s)||this.handleAttachNode(s),this.attachedNodes.has(i)||this.handleAttachNode(i),this.handleAttachEdge(e)}handleAttachNode(e){this.params.onBeforeNodeAttached(e),this.attachedNodes.add(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.attachedNodes.delete(e),this.params.onAfterNodeDetached(e)}handleAttachEdge(e){this.attachedEdges.add(e),this.htmlView.attachEdge(e)}handleDetachEdge(e){this.htmlView.detachEdge(e),this.attachedEdges.delete(e)}}class Je{constructor(e,t){o(this,"deferredNodes",new Set);o(this,"deferredEdges",new Set);this.htmlView=e,this.graphStore=t}attachNode(e){this.isNodeValid(e)?this.htmlView.attachNode(e):this.deferredNodes.add(e)}detachNode(e){this.deferredNodes.has(e)?this.deferredNodes.delete(e):this.htmlView.detachNode(e)}attachEdge(e){this.isEdgeValid(e)?this.htmlView.attachEdge(e):this.deferredEdges.add(e)}detachEdge(e){this.deferredEdges.has(e)?this.deferredEdges.delete(e):this.htmlView.detachEdge(e)}updateNodePosition(e){this.deferredNodes.has(e)?this.tryAttachNode(e):this.htmlView.updateNodePosition(e)}updateNodePriority(e){this.deferredNodes.has(e)?this.tryAttachNode(e):this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.updateEdgeShape(e)}renderEdge(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.renderEdge(e)}updateEdgePriority(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.updateEdgePriority(e)}clear(){this.deferredNodes.clear(),this.deferredEdges.clear(),this.htmlView.clear()}destroy(){this.htmlView.destroy()}isNodeValid(e){const t=this.graphStore.getNode(e);return!(t.payload.x===null||t.payload.y===null)}tryAttachNode(e){this.isNodeValid(e)&&(this.deferredNodes.delete(e),this.htmlView.attachNode(e))}isEdgeValid(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),i=this.graphStore.getPort(t.to);return!(this.deferredNodes.has(s.nodeId)||this.deferredNodes.has(i.nodeId))}tryAttachEdge(e){this.isEdgeValid(e)&&(this.deferredEdges.delete(e),this.htmlView.attachEdge(e))}}class B{constructor(){o(this,"callbacks",new Set)}subscribe(e){this.callbacks.add(e)}unsubscribe(e){this.callbacks.delete(e)}emit(e){this.callbacks.forEach(t=>{t(e)})}}const P=()=>{const r=new B;return[r,r]};class j{constructor(e){o(this,"counter",0);this.checkExists=e}create(e){if(e!==void 0)return e;for(;this.checkExists(this.counter);)this.counter++;return this.counter}reset(){this.counter=0}}class T extends Error{constructor(){super(...arguments);o(this,"name","CanvasError")}}class ce{constructor(e,t,s,i,n,a){o(this,"nodeIdGenerator",new j(e=>this.graphStore.getNode(e)!==void 0));o(this,"portIdGenerator",new j(e=>this.graphStore.getPort(e)!==void 0));o(this,"edgeIdGenerator",new j(e=>this.graphStore.getEdge(e)!==void 0));o(this,"onAfterNodeAdded",e=>{this.htmlView.attachNode(e)});o(this,"onAfterNodeUpdated",e=>{this.htmlView.updateNodePosition(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});o(this,"onAfterNodePriorityUpdated",e=>{this.htmlView.updateNodePriority(e)});o(this,"onBeforeNodeRemoved",e=>{this.graphStore.getNodePortIds(e).forEach(t=>{this.unmarkPort(t)}),this.htmlView.detachNode(e)});o(this,"onAfterPortUpdated",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});o(this,"onBeforePortUnmarked",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(t=>{this.removeEdge(t)})});o(this,"onAfterEdgeAdded",e=>{this.htmlView.attachEdge(e)});o(this,"onAfterEdgeShapeUpdated",e=>{this.htmlView.updateEdgeShape(e)});o(this,"onAfterEdgeUpdated",e=>{this.htmlView.renderEdge(e)});o(this,"onAfterEdgePriorityUpdated",e=>{this.htmlView.updateEdgePriority(e)});o(this,"onBeforeEdgeRemoved",e=>{this.htmlView.detachEdge(e)});o(this,"onBeforeClear",()=>{this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset(),this.htmlView.clear()});o(this,"onBeforeDestroyEmitter");o(this,"destroyed",!1);o(this,"onBeforeDestroy");this.graph=e,this.viewport=t,this.graphStore=s,this.viewportStore=i,this.htmlView=n,this.params=a,this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.subscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.subscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.subscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.subscribe(this.onBeforeClear),[this.onBeforeDestroyEmitter,this.onBeforeDestroy]=P()}addNode(e){const t=this.nodeIdGenerator.create(e.id);if(this.graphStore.getNode(t)!==void 0)throw new T("failed to add node with existing id");if(this.graphStore.getElementNodeId(e.element)!==void 0)throw new T("failed to add node with html element already in use by another node");if(this.graphStore.addNode({id:t,element:e.element,x:e.x??null,y:e.y??null,centerFn:e.centerFn??this.params.nodes.centerFn,priority:e.priority??this.params.nodes.priorityFn()}),e.ports!==void 0)for(const s of e.ports)this.markPort({id:s.id,element:s.element,nodeId:t,direction:s.direction});return this}updateNode(e,t){if(this.graphStore.getNode(e)===void 0)throw new T("failed to update nonexistent node");return this.graphStore.updateNode(e,t??{}),this}removeNode(e){if(this.graphStore.getNode(e)===void 0)throw new T("failed to remove nonexistent node");return this.graphStore.removeNode(e),this}markPort(e){const t=this.portIdGenerator.create(e.id);if(this.graphStore.getPort(t)!==void 0)throw new T("failed to add port with existing id");if(this.graphStore.getNode(e.nodeId)===void 0)throw new T("failed to mark port for nonexistent node");return this.graphStore.addPort({id:t,element:e.element,nodeId:e.nodeId,direction:e.direction??this.params.ports.direction}),this}updatePort(e,t){if(this.graphStore.getPort(e)===void 0)throw new T("failed to update nonexistent port");return this.graphStore.updatePort(e,t??{}),this}unmarkPort(e){if(this.graphStore.getPort(e)===void 0)throw new T("failed to unmark nonexistent port");return this.graphStore.removePort(e),this}addEdge(e){const t=this.edgeIdGenerator.create(e.id);if(this.graphStore.getEdge(t)!==void 0)throw new T("failed to add edge with existing id");if(this.graphStore.getPort(e.from)===void 0)throw new T("failed to add edge from nonexistent port");if(this.graphStore.getPort(e.to)===void 0)throw new T("failed to add edge to nonexistent port");return this.graphStore.addEdge({id:t,from:e.from,to:e.to,shape:e.shape??this.params.edges.shapeFactory(t),priority:e.priority??this.params.edges.priorityFn()}),this}updateEdge(e,t){if(this.graphStore.getEdge(e)===void 0)throw new T("failed to update nonexistent edge");return this.graphStore.updateEdge(e,t??{}),this}removeEdge(e){if(this.graphStore.getEdge(e)===void 0)throw new T("failed to remove nonexistent edge");return this.graphStore.removeEdge(e),this}clear(){return this.graphStore.clear(),this}patchViewportMatrix(e){return this.viewportStore.patchViewportMatrix(e),this}patchContentMatrix(e){return this.viewportStore.patchContentMatrix(e),this}destroy(){this.destroyed||(this.clear(),this.onBeforeDestroyEmitter.emit(),this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.unsubscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear),this.htmlView.destroy(),this.destroyed=!0)}}class Qe{constructor(){o(this,"singleToMultiMap",new Map);o(this,"multiToSingleMap",new Map)}addRecord(e,t){const s=this.singleToMultiMap.get(e);s===void 0?this.singleToMultiMap.set(e,new Set([t])):s.add(t),this.multiToSingleMap.set(t,e)}getMultiBySingle(e){const t=this.singleToMultiMap.get(e)??new Set;return Array.from(t.values())}removeByMulti(e){const t=this.multiToSingleMap.get(e),s=this.singleToMultiMap.get(t);s.delete(e),s.size===0&&this.singleToMultiMap.delete(t),this.multiToSingleMap.delete(e)}getByMulti(e){return this.multiToSingleMap.get(e)}removeBySingle(e){this.singleToMultiMap.get(e).forEach(s=>{this.multiToSingleMap.delete(s)}),this.singleToMultiMap.delete(e)}clear(){this.singleToMultiMap.clear(),this.multiToSingleMap.clear()}forEachSingle(e){this.singleToMultiMap.forEach((t,s)=>{e(s)})}hasSingle(e){return this.singleToMultiMap.get(e)!==void 0}hasMulti(e){return this.multiToSingleMap.get(e)!==void 0}}class le{constructor(){o(this,"nodes",new Map);o(this,"ports",new Map);o(this,"edges",new Map);o(this,"nodesElementsMap",new Map);o(this,"portIncomingEdges",new Map);o(this,"portOutcomingEdges",new Map);o(this,"portCycleEdges",new Map);o(this,"elementPorts",new Qe);o(this,"afterNodeAddedEmitter");o(this,"onAfterNodeAdded");o(this,"afterNodeUpdatedEmitter");o(this,"onAfterNodeUpdated");o(this,"afterNodePriorityUpdatedEmitter");o(this,"onAfterNodePriorityUpdated");o(this,"beforeNodeRemovedEmitter");o(this,"onBeforeNodeRemoved");o(this,"afterPortAddedEmitter");o(this,"onAfterPortAdded");o(this,"afterPortUpdatedEmitter");o(this,"onAfterPortUpdated");o(this,"beforePortRemovedEmitter");o(this,"onBeforePortRemoved");o(this,"afterEdgeAddedEmitter");o(this,"onAfterEdgeAdded");o(this,"afterEdgeShapeUpdatedEmitter");o(this,"onAfterEdgeShapeUpdated");o(this,"afterEdgeUpdatedEmitter");o(this,"onAfterEdgeUpdated");o(this,"afterEdgePriorityUpdatedEmitter");o(this,"onAfterEdgePriorityUpdated");o(this,"beforeEdgeRemovedEmitter");o(this,"onBeforeEdgeRemoved");o(this,"beforeClearEmitter");o(this,"onBeforeClear");[this.afterNodeAddedEmitter,this.onAfterNodeAdded]=P(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=P(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=P(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=P(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=P(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=P(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=P(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=P(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=P(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=P(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=P(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=P(),[this.beforeClearEmitter,this.onBeforeClear]=P()}addNode(e){const t=new Map,s={element:e.element,payload:{x:e.x,y:e.y,centerFn:e.centerFn,priority:e.priority},ports:t};this.nodes.set(e.id,s),this.nodesElementsMap.set(e.element,e.id),this.afterNodeAddedEmitter.emit(e.id)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(e){return this.nodes.get(e)}getElementNodeId(e){return this.nodesElementsMap.get(e)}updateNode(e,t){const s=this.nodes.get(e).payload;s.x=t.x??s.x,s.y=t.y??s.y,s.centerFn=t.centerFn??s.centerFn,t.priority!==void 0&&(s.priority=t.priority,this.afterNodePriorityUpdatedEmitter.emit(e)),this.afterNodeUpdatedEmitter.emit(e)}removeNode(e){this.beforeNodeRemovedEmitter.emit(e);const t=this.nodes.get(e);this.nodesElementsMap.delete(t.element),this.nodes.delete(e)}addPort(e){this.ports.set(e.id,{element:e.element,payload:{direction:e.direction},nodeId:e.nodeId}),this.elementPorts.addRecord(e.element,e.id),this.portCycleEdges.set(e.id,new Set),this.portIncomingEdges.set(e.id,new Set),this.portOutcomingEdges.set(e.id,new Set),this.nodes.get(e.nodeId).ports.set(e.id,e.element),this.afterPortAddedEmitter.emit(e.id)}getPort(e){return this.ports.get(e)}updatePort(e,t){const s=this.ports.get(e).payload;s.direction=t.direction??s.direction,this.afterPortUpdatedEmitter.emit(e)}getAllPortIds(){return Array.from(this.ports.keys())}getElementPortIds(e){return this.elementPorts.getMultiBySingle(e)}getNodePortIds(e){const t=this.nodes.get(e);if(t!==void 0)return Array.from(t.ports.keys())}removePort(e){const t=this.ports.get(e).nodeId;this.beforePortRemovedEmitter.emit(e),this.nodes.get(t).ports.delete(e),this.ports.delete(e),this.elementPorts.removeByMulti(e)}addEdge(e){this.addEdgeInternal(e),this.afterEdgeAddedEmitter.emit(e.id)}updateEdge(e,t){if(t.from!==void 0||t.to!==void 0){const i=this.edges.get(e),n=i.payload;this.removeEdgeInternal(e),this.addEdgeInternal({id:e,from:t.from??i.from,to:t.to??i.to,shape:n.shape,priority:n.priority})}const s=this.edges.get(e);t.shape!==void 0&&(s.payload.shape=t.shape,this.afterEdgeShapeUpdatedEmitter.emit(e)),t.priority!==void 0&&(s.payload.priority=t.priority,this.afterEdgePriorityUpdatedEmitter.emit(e)),this.afterEdgeUpdatedEmitter.emit(e)}getAllEdgeIds(){return Array.from(this.edges.keys())}getEdge(e){return this.edges.get(e)}removeEdge(e){this.beforeEdgeRemovedEmitter.emit(e),this.removeEdgeInternal(e)}clear(){this.beforeClearEmitter.emit(),this.portIncomingEdges.clear(),this.portOutcomingEdges.clear(),this.portCycleEdges.clear(),this.elementPorts.clear(),this.nodesElementsMap.clear(),this.edges.clear(),this.ports.clear(),this.nodes.clear()}getPortIncomingEdgeIds(e){return Array.from(this.portIncomingEdges.get(e))}getPortOutgoingEdgeIds(e){return Array.from(this.portOutcomingEdges.get(e))}getPortCycleEdgeIds(e){return Array.from(this.portCycleEdges.get(e))}getPortAdjacentEdgeIds(e){return[...this.getPortIncomingEdgeIds(e),...this.getPortOutgoingEdgeIds(e),...this.getPortCycleEdgeIds(e)]}getNodeIncomingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(i=>{this.getPortIncomingEdgeIds(i).filter(n=>{const a=this.getEdge(n);return this.getPort(a.from).nodeId!==e}).forEach(n=>{s.push(n)})}),s}getNodeOutgoingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(i=>{this.getPortOutgoingEdgeIds(i).filter(n=>{const a=this.getEdge(n);return this.getPort(a.to).nodeId!==e}).forEach(n=>{s.push(n)})}),s}getNodeCycleEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(i=>{this.getPortCycleEdgeIds(i).forEach(n=>{s.push(n)}),this.getPortIncomingEdgeIds(i).filter(n=>{const a=this.getEdge(n);return this.getPort(a.to).nodeId===e}).forEach(n=>{s.push(n)})}),s}getNodeAdjacentEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(i=>{this.getPortIncomingEdgeIds(i).forEach(n=>{s.push(n)}),this.getPortOutgoingEdgeIds(i).forEach(n=>{s.push(n)}),this.getPortCycleEdgeIds(i).forEach(n=>{s.push(n)})}),s}addEdgeInternal(e){this.edges.set(e.id,{from:e.from,to:e.to,payload:{shape:e.shape,priority:e.priority}}),e.from!==e.to?(this.portOutcomingEdges.get(e.from).add(e.id),this.portIncomingEdges.get(e.to).add(e.id)):this.portCycleEdges.get(e.from).add(e.id)}removeEdgeInternal(e){const t=this.edges.get(e),s=t.from,i=t.to;this.portCycleEdges.get(s).delete(e),this.portCycleEdges.get(i).delete(e),this.portIncomingEdges.get(s).delete(e),this.portIncomingEdges.get(i).delete(e),this.portOutcomingEdges.get(s).delete(e),this.portOutcomingEdges.get(i).delete(e),this.edges.delete(e)}}const ge=r=>({scale:1/r.scale,x:-r.x/r.scale,y:-r.y/r.scale}),ue={scale:1,x:0,y:0};class qe{constructor(){o(this,"viewportMatrix",ue);o(this,"contentMatrix",ue);o(this,"afterUpdateEmitter");o(this,"onAfterUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=P()}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(e){this.viewportMatrix={scale:e.scale??this.viewportMatrix.scale,x:e.x??this.viewportMatrix.x,y:e.y??this.viewportMatrix.y},this.contentMatrix=ge(this.viewportMatrix),this.afterUpdateEmitter.emit()}patchContentMatrix(e){this.contentMatrix={scale:e.scale??this.contentMatrix.scale,x:e.x??this.contentMatrix.x,y:e.y??this.contentMatrix.y},this.viewportMatrix=ge(this.contentMatrix),this.afterUpdateEmitter.emit()}}class G{constructor(e){o(this,"elementToNodeId",new Map);o(this,"nodesResizeObserver");o(this,"onAfterNodeAdded",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.set(t.element,e),this.nodesResizeObserver.observe(t.element)});o(this,"onBeforeNodeRemoved",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.delete(t.element),this.nodesResizeObserver.unobserve(t.element)});o(this,"onBeforeClear",()=>{this.nodesResizeObserver.disconnect(),this.elementToNodeId.clear()});this.canvas=e,this.nodesResizeObserver=new ResizeObserver(t=>{t.forEach(s=>{const i=s.target;this.handleNodeResize(i)})}),this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear)}static configure(e){new G(e)}handleNodeResize(e){const t=this.elementToNodeId.get(e);this.canvas.updateNode(t)}}const _e=(r,e,t)=>{const{x:s,y:i,width:n,height:a}=r.getBoundingClientRect();return e>=s&&e<=s+n&&t>=i&&t<=i+a},et=(r,e,t)=>e>=0&&e<=r.innerWidth&&t>=0&&t<=r.innerHeight,V=(r,e,t,s)=>_e(e,t,s)&&et(r,t,s),F=(r,e)=>{e!==null?r.style.cursor=e:r.style.removeProperty("cursor")},O=r=>{const e=document.createElement("div");return{id:r.overlayId,element:e,x:r.portCoords.x,y:r.portCoords.y,ports:[{id:r.overlayId,element:e,direction:r.portDirection}]}},tt=(r,e)=>{let t=e;for(;t!==null;){const s=r.getElementPortIds(t)[0]??null;if(s!==null)return{status:"portFound",portId:s};if(r.getElementNodeId(t)!==null)return{status:"nodeEncountered"};t=t.parentElement}return{status:"notFound"}};function*pe(r,e){const t=r.elementsFromPoint(e.x,e.y);for(const s of t){if(s.shadowRoot!==null){const i=pe(s.shadowRoot,e);for(const n of i)yield n}yield s}}const we=(r,e)=>{const t=pe(document,e);for(const s of t){const i=tt(r,s);if(i.status==="portFound")return i.portId;if(i.status==="nodeEncountered")return null}return null};var N=(r=>(r.Static="static",r.Dragging="dragging",r.Edge="edge",r))(N||{});const fe=(r,e)=>({x:r/2,y:e/2}),u={x:0,y:0},y=(r,e,t)=>({x:e.x*r.x-e.y*r.y+((1-e.x)*t.x+e.y*t.y),y:e.y*r.x+e.x*r.y+((1-e.x)*t.y-e.y*t.x)}),me=(r,e)=>{const t={x:r.x+r.width/2,y:r.y+r.height/2},s={x:e.x+e.width/2,y:e.y+e.height/2},i=Math.min(t.x,s.x),n=Math.min(t.y,s.y),a=Math.abs(s.x-t.x),h=Math.abs(s.y-t.y),d=t.x<=s.x?1:-1,c=t.y<=s.y?1:-1;return{x:i,y:n,width:a,height:h,flipX:d,flipY:c}},W=(r,e,t,s)=>({x:e*r.x+(1-e)/2*s.x,y:t*r.y+(1-t)/2*s.y});class rt{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u),i=y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to),n={x:s.x+this.params.sourceDirection.x*this.params.curvature,y:s.y+this.params.sourceDirection.y*this.params.curvature},a={x:i.x-this.params.targetDirection.x*this.params.curvature,y:i.y-this.params.targetDirection.y*this.params.curvature},h=`M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`,d=this.params.hasSourceArrow?"":`M ${u.x} ${u.y} L ${s.x} ${s.y} `,c=this.params.hasTargetArrow?"":` M ${i.x} ${i.y} L ${this.params.to.x} ${this.params.to.y}`;this.path=`${d}${h}${c}`}}class st{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength,n=Math.cos(this.params.detourDirection)*this.params.detourDistance,a=Math.sin(this.params.detourDirection)*this.params.detourDistance,h=n*this.params.flipX,d=a*this.params.flipY,c=y({x:i,y:u.y},this.params.sourceDirection,u),g={x:c.x+h,y:c.y+d},l=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),p={x:l.x+h,y:l.y+d},w={x:(g.x+p.x)/2,y:(g.y+p.y)/2},m={x:c.x+this.params.curvature*this.params.sourceDirection.x,y:c.y+this.params.curvature*this.params.sourceDirection.y},v={x:l.x-this.params.curvature*this.params.targetDirection.x,y:l.y-this.params.curvature*this.params.targetDirection.y},x={x:c.x+h,y:c.y+d},S={x:l.x+h,y:l.y+d};this.path=[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${m.x} ${m.y} ${x.x} ${x.y} ${w.x} ${w.y}`,`C ${S.x} ${S.y} ${v.x} ${v.y} ${l.x} ${l.y}`,`L ${s.x} ${s.y}`].join(" "),this.midpoint=W(w,e.flipX,e.flipY,e.to)}}const K=Object.freeze({edgeColor:"--edge-color"}),ye=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.style.pointerEvents="none",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.overflow="visible",e.style.setProperty(K.edgeColor,r),e},ve=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke",`var(${K.edgeColor})`),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e},k=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("fill",`var(${K.edgeColor})`),r},Ee=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.transformOrigin="50% 50%",r},Ae=(r,e)=>{r.style.transform=`translate(${e.x}px, ${e.y}px)`,r.style.width=`${Math.max(e.width,1)}px`,r.style.height=`${Math.max(e.height,1)}px`},L=(r,e)=>{const t=[];if(r.length>0&&t.push(`M ${r[0].x} ${r[0].y}`),r.length===2&&t.push(`L ${r[1].x} ${r[1].y}`),r.length>2){const s=r.length-1;let i=0,n=0,a=0;r.forEach((h,d)=>{let c=0,g=0,l=0;const p=d>0,w=d<s,m=p&&w;if(p&&(c=-i,g=-n,l=a),w){const U=r[d+1];i=U.x-h.x,n=U.y-h.y,a=Math.sqrt(i*i+n*n)}const x=a!==0?Math.min((m?e:0)/a,d<s-1?.5:1):0,S=m?{x:h.x+i*x,y:h.y+n*x}:h,M=l!==0?Math.min((m?e:0)/l,d>1?.5:1):0,C=m?{x:h.x+c*M,y:h.y+g*M}:h;d>0&&t.push(`L ${C.x} ${C.y}`),m&&t.push(`C ${h.x} ${h.y} ${h.x} ${h.y} ${S.x} ${S.y}`)})}return t.join(" ")};class ot{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=y({x:a,y:u.y},this.params.sourceDirection,u),d=y({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.x+d.x)/2,n),g=this.params.to.y/2,l={x:this.params.flipX>0?c:-n,y:h.y},p={x:l.x,y:g},w={x:this.params.flipX>0?this.params.to.x-c:this.params.to.x+n,y:d.y},m={x:w.x,y:g};this.path=L([s,h,l,p,m,w,d,i],this.params.roundness)}}class it{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=Math.cos(this.params.detourDirection)*this.params.detourDistance,h=Math.sin(this.params.detourDirection)*this.params.detourDistance,d=a*this.params.flipX,c=h*this.params.flipY,g={x:n.x+d,y:n.y+c},l=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),p={x:l.x+d,y:l.y+c},w={x:(g.x+p.x)/2,y:(g.y+p.y)/2};this.midpoint=W(w,e.flipX,e.flipY,e.to),this.path=L([t,n,g,p,l,s],this.params.roundness)}}class nt{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=y({x:n,y:u.y},this.params.sourceDirection,u),h=y({x:this.params.to.x-n,y:this.params.to.y},this.params.targetDirection,this.params.to);this.path=L([s,a,h,i],this.params.roundness)}}class at{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=y({x:a,y:u.y},this.params.sourceDirection,u),d=y({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.y+d.y)/2,n),g=this.params.to.x/2,l={x:h.x,y:this.params.flipY>0?c:-n},p={x:g,y:l.y},w={x:d.x,y:this.params.flipY>0?this.params.to.y-c:this.params.to.y+n},m={x:g,y:w.y};this.path=L([s,h,l,p,m,w,d,i],this.params.roundness)}}class Z{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.arrowOffset,s=this.params.side,i=this.params.arrowLength+t,n=i+2*s,h=[{x:this.params.arrowLength,y:u.y},{x:i,y:u.y},{x:i,y:this.params.side},{x:n,y:this.params.side},{x:n,y:-this.params.side},{x:i,y:-this.params.side},{x:i,y:u.y},{x:this.params.arrowLength,y:u.y}].map(c=>y(c,this.params.sourceDirection,u)),d=`M ${u.x} ${u.y} L ${h[0].x} ${h[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":d}${L(h,this.params.roundness)}`,this.midpoint={x:(h[3].x+h[4].x)/2,y:(h[3].y+h[4].y)/2}}}class ht{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.smallRadius,s=this.params.radius,i=t+s,n=t*s/i,a=Math.sqrt(i*i-t*t),h=a*t/i,d=a+s+this.params.arrowLength,c=this.params.arrowLength+h,l=[{x:this.params.arrowLength,y:u.y},{x:c,y:n},{x:c,y:-n},{x:d,y:0}].map(m=>y(m,this.params.sourceDirection,u)),p=[`M ${l[0].x} ${l[0].y}`,`A ${t} ${t} 0 0 1 ${l[1].x} ${l[1].y}`,`A ${s} ${s} 0 1 0 ${l[2].x} ${l[2].y}`,`A ${t} ${t} 0 0 1 ${l[0].x} ${l[0].y}`].join(" "),w=`M 0 0 L ${l[0].x} ${l[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":w}${p}`,this.midpoint=l[3]}}class dt{constructor(e){o(this,"path");o(this,"midpoint");o(this,"diagonalDistance");this.params=e;const t=this.params.to;if(this.midpoint={x:t.x/2,y:t.y/2},this.diagonalDistance=Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y),Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y)===0){this.path="";return}const i=this.createDirectLinePoint({offset:this.params.sourceOffset,hasArrow:this.params.hasSourceArrow,flip:1,shift:u}),n=this.createDirectLinePoint({offset:this.params.targetOffset,hasArrow:this.params.hasTargetArrow,flip:-1,shift:this.params.to});this.path=`M ${i.x} ${i.y} L ${n.x} ${n.y}`}createDirectLinePoint(e){const t=e.hasArrow?this.params.arrowLength:0,s=e.offset+t,i=e.flip*s/this.diagonalDistance;return{x:this.params.to.x*i+e.shift.x,y:this.params.to.y*i+e.shift.y}}}class ct{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.y/2,c=d+Math.abs(this.params.detourDistance),g=d+c*this.params.flipY*h,l={x:(n.x+a.x)/2,y:g};this.midpoint=W(l,e.flipX,e.flipY,e.to),this.path=L([t,n,{x:n.x,y:g},{x:a.x,y:g},a,s],this.params.roundness)}}class lt{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.x/2,c=d+Math.abs(this.params.detourDistance),g=d+c*this.params.flipX*h,l={x:g,y:(n.y+a.y)/2};this.midpoint=W(l,e.flipX,e.flipY,e.to),this.path=L([t,n,{x:g,y:n.y},{x:g,y:a.y},a,s],this.params.roundness)}}const f=Object.freeze({color:"#777777",width:1,arrowLength:20,polygonArrowRadius:4,circleArrowRadius:8,wedgeArrowSmallRadius:20,wedgeArrowRadius:100,wedgeArrowAngle:Math.PI/12,arrowOffset:15,hasSourceArrow:!1,hasTargetArrow:!1,cycleRadius:30,cycleSquareSide:30,roundness:10,detourDistance:100,detourDirection:-Math.PI/2,detourDirectionVertical:0,smallCycleRadius:15,curvature:90,interactiveWidth:10,preOffset:0}),xe=(r,e,t)=>({x:e*Math.cos(r),y:t*Math.sin(r)});class z{constructor(e){o(this,"svg");o(this,"group",Ee());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"onAfterRender");o(this,"afterRenderEmitter");o(this,"arrowRenderer");this.params=e,[this.afterRenderEmitter,this.onAfterRender]=P(),this.arrowRenderer=this.params.arrowRenderer,this.svg=ye(e.color),this.svg.appendChild(this.group),this.line=ve(e.width),this.group.appendChild(this.line),e.hasSourceArrow&&(this.sourceArrow=k(),this.group.appendChild(this.sourceArrow)),e.hasTargetArrow&&(this.targetArrow=k(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:a,flipY:h}=me(e.from,e.to);Ae(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d=xe(e.from.direction,a,h),c=xe(e.to.direction,a,h),g={x:i,y:n};let l={x:-c.x,y:-c.y},p;e.category===D.PortCycle?(p=this.params.createCyclePath,l=d):e.category===D.NodeCycle?p=this.params.createDetourPath:p=this.params.createLinePath;const w=p(d,c,g,a,h);this.line.setAttribute("d",w.path);let m=null;this.sourceArrow&&(m=this.arrowRenderer({direction:d,shift:u,arrowLength:this.params.arrowLength}),this.sourceArrow.setAttribute("d",m));let v=null;this.targetArrow&&(v=this.arrowRenderer({direction:l,shift:g,arrowLength:this.params.arrowLength}),this.targetArrow.setAttribute("d",v)),this.afterRenderEmitter.emit({edgePath:w,sourceArrowPath:m,targetArrowPath:v})}}const gt=r=>e=>{const s=[u,{x:e.arrowLength,y:r.radius},{x:e.arrowLength,y:-r.radius}].map(h=>y(h,e.direction,u)).map(h=>({x:h.x+e.shift.x,y:h.y+e.shift.y})),i=`M ${s[0].x} ${s[0].y}`,n=`L ${s[1].x} ${s[1].y}`,a=`L ${s[2].x} ${s[2].y}`;return`${i} ${n} ${a} Z`},ut=r=>e=>{const t=r.radius,s=e.arrowLength,i=(s*s+2*s*t)/(2*t),n=i+t,a=s+t-t*(s+t)/n,h=t*i/n,c=[u,{x:a,y:-h},{x:a,y:h}].map(m=>y(m,e.direction,u)).map(m=>({x:m.x+e.shift.x,y:m.y+e.shift.y})),g=`M ${c[0].x} ${c[0].y}`,l=`A ${i} ${i} 0 0 0 ${c[1].x} ${c[1].y}`,p=`A ${t} ${t} 0 0 0 ${c[2].x} ${c[2].y}`,w=`A ${i} ${i} 0 0 0 ${c[0].x} ${c[0].y}`;return`${g} ${l} ${p} ${w}`},pt=r=>e=>{const t=r.smallRadius,s=r.radius,i=y({x:e.arrowLength,y:0},{x:Math.cos(r.angle),y:Math.sin(r.angle)},{x:e.arrowLength+r.smallRadius,y:0}),a=[u,{x:i.x,y:-i.y},i].map(l=>y(l,e.direction,u)).map(l=>({x:l.x+e.shift.x,y:l.y+e.shift.y})),h=`M ${a[0].x} ${a[0].y}`,d=`A ${s} ${s} 0 0 1 ${a[1].x} ${a[1].y}`,c=`A ${t} ${t} 0 0 1 ${a[2].x} ${a[2].y}`,g=`A ${s} ${s} 0 0 1 ${a[0].x} ${a[0].y}`;return`${h} ${d} ${c} ${g}`},I=r=>{if(typeof r=="function")return r;switch(r.type){case"triangle":return gt({radius:r.radius??f.polygonArrowRadius});case"arc":return ut({radius:r.radius??f.circleArrowRadius});default:return pt({smallRadius:r.smallRadius??f.wedgeArrowSmallRadius,angle:r.angle??f.wedgeArrowAngle,radius:r.radius??f.wedgeArrowRadius})}};class Se{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"curvature");o(this,"portCycleRadius");o(this,"portCycleSmallRadius");o(this,"detourDirection");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new ht({sourceDirection:e,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new st({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s)=>new rt({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.curvature=(e==null?void 0:e.curvature)??f.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??f.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??f.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??f.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Pe{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new Z({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new ct({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s,i)=>new ot({to:s,sourceDirection:e,targetDirection:t,flipX:i,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class be{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDirection");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new Z({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new it({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s)=>new nt({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??f.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Te{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new Z({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new lt({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s,i,n)=>new at({to:s,sourceDirection:e,targetDirection:t,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class J{constructor(e){o(this,"svg");o(this,"group",Ee());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"color");o(this,"width");o(this,"arrowLength");o(this,"sourceOffset");o(this,"targetOffset");o(this,"onAfterRender");o(this,"afterRenderEmitter");o(this,"arrowRenderer");[this.afterRenderEmitter,this.onAfterRender]=P(),this.color=(e==null?void 0:e.color)??f.color,this.width=(e==null?void 0:e.width)??f.width,this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowRenderer=I((e==null?void 0:e.arrowRenderer)??{}),this.sourceOffset=(e==null?void 0:e.sourceOffset)??f.preOffset,this.targetOffset=(e==null?void 0:e.targetOffset)??f.preOffset,this.svg=ye(this.color),this.svg.appendChild(this.group),this.line=ve(this.width),this.group.appendChild(this.line),e!=null&&e.hasSourceArrow&&(this.sourceArrow=k(),this.group.appendChild(this.sourceArrow)),e!=null&&e.hasTargetArrow&&(this.targetArrow=k(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:a,flipY:h}=me(e.from,e.to);Ae(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d={x:i,y:n},c=new dt({to:d,sourceOffset:this.sourceOffset,targetOffset:this.targetOffset,hasSourceArrow:this.sourceArrow!==null,hasTargetArrow:this.targetArrow!==null,arrowLength:this.arrowLength});this.line.setAttribute("d",c.path);let g=null,l=null;const p=c.diagonalDistance;if(p===0)this.sourceArrow!==null&&(g="",this.sourceArrow.setAttribute("d",g)),this.targetArrow!==null&&(l="",this.targetArrow.setAttribute("d",l));else{const w={x:d.x/p,y:d.y/p};if(this.sourceArrow){const m={x:w.x*this.sourceOffset,y:w.y*this.sourceOffset};g=this.arrowRenderer({direction:w,shift:m,arrowLength:this.arrowLength}),this.sourceArrow.setAttribute("d",g)}if(this.targetArrow){const m={x:w.x*this.targetOffset,y:w.y*this.targetOffset};l=this.arrowRenderer({direction:{x:-w.x,y:-w.y},shift:{x:d.x-m.x,y:d.y-m.y},arrowLength:this.arrowLength}),this.targetArrow.setAttribute("d",l)}}this.afterRenderEmitter.emit({edgePath:c,sourceArrowPath:g,targetArrowPath:l})}}const wt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.pointerEvents="auto",r.style.cursor="pointer",r},ft=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke","transparent"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e.setAttribute("stroke-linecap","round"),e},De=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke-linejoin","round"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","transparent"),e.setAttribute("stroke","transparent"),e};class Ne extends Error{constructor(e){super(e),this.name="InteractiveEdgeError"}}class Q{constructor(e,t){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"handle",wt());o(this,"onAfterRender");o(this,"interactiveLine");o(this,"interactiveSourceArrow",null);o(this,"interactiveTargetArrow",null);if(this.baseEdge=e,e instanceof Q)throw new Ne("interactive edge can be configured only once");this.svg=this.baseEdge.svg,this.group=this.baseEdge.group,this.line=this.baseEdge.line,this.sourceArrow=this.baseEdge.sourceArrow,this.targetArrow=this.baseEdge.targetArrow,this.onAfterRender=this.baseEdge.onAfterRender;const s=(t==null?void 0:t.distance)??f.interactiveWidth;this.interactiveLine=ft(s),this.handle.appendChild(this.interactiveLine),this.sourceArrow&&(this.interactiveSourceArrow=De(s),this.handle.appendChild(this.interactiveSourceArrow)),this.targetArrow&&(this.interactiveTargetArrow=De(s),this.handle.appendChild(this.interactiveTargetArrow)),this.group.appendChild(this.handle),this.baseEdge.onAfterRender.subscribe(i=>{this.interactiveLine.setAttribute("d",i.edgePath.path),this.interactiveSourceArrow&&this.interactiveSourceArrow.setAttribute("d",i.sourceArrowPath),this.interactiveTargetArrow&&this.interactiveTargetArrow.setAttribute("d",i.targetArrowPath)})}render(e){this.baseEdge.render(e)}}class mt{constructor(e,t){o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"svg");this.baseShape=e,this.midpointElement=t,this.svg=this.baseShape.svg,this.group=this.baseShape.group,this.line=this.baseShape.line,this.sourceArrow=this.baseShape.sourceArrow,this.targetArrow=this.baseShape.targetArrow,this.onAfterRender=this.baseShape.onAfterRender,this.svg.append(this.midpointElement),this.baseShape.onAfterRender.subscribe(s=>{const i=s.edgePath.midpoint,n=`translate(${i.x}px, ${i.y}px)`;this.midpointElement.style.setProperty("transform",n)})}render(e){this.baseShape.render(e)}}class Me{constructor(e){o(this,"onAfterNodeAdded");o(this,"onAfterNodeUpdated");o(this,"onAfterNodePriorityUpdated");o(this,"onBeforeNodeRemoved");o(this,"onAfterPortMarked");o(this,"onAfterPortUpdated");o(this,"onBeforePortUnmarked");o(this,"onAfterEdgeAdded");o(this,"onAfterEdgeShapeUpdated");o(this,"onAfterEdgeUpdated");o(this,"onAfterEdgePriorityUpdated");o(this,"onBeforeEdgeRemoved");o(this,"onBeforeClear");this.graphStore=e,this.onAfterNodeAdded=this.graphStore.onAfterNodeAdded,this.onAfterNodeUpdated=this.graphStore.onAfterNodeUpdated,this.onAfterNodePriorityUpdated=this.graphStore.onAfterNodePriorityUpdated,this.onBeforeNodeRemoved=this.graphStore.onBeforeNodeRemoved,this.onAfterPortMarked=this.graphStore.onAfterPortAdded,this.onAfterPortUpdated=this.graphStore.onAfterPortUpdated,this.onBeforePortUnmarked=this.graphStore.onBeforePortRemoved,this.onAfterEdgeAdded=this.graphStore.onAfterEdgeAdded,this.onAfterEdgeShapeUpdated=this.graphStore.onAfterEdgeShapeUpdated,this.onAfterEdgeUpdated=this.graphStore.onAfterEdgeUpdated,this.onAfterEdgePriorityUpdated=this.graphStore.onAfterEdgePriorityUpdated,this.onBeforeEdgeRemoved=this.graphStore.onBeforeEdgeRemoved,this.onBeforeClear=this.graphStore.onBeforeClear}getNode(e){const t=this.graphStore.getNode(e);if(t===void 0)return null;const s=t.payload;return{element:t.element,x:s.x,y:s.y,centerFn:s.centerFn,priority:s.priority}}getElementNodeId(e){return this.graphStore.getElementNodeId(e)??null}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(e){const t=this.graphStore.getPort(e);return t===void 0?null:{element:t.element,direction:t.payload.direction,nodeId:t.nodeId}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(e){return this.graphStore.getNodePortIds(e)??null}getElementPortIds(e){return[...this.graphStore.getElementPortIds(e)]}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(e){const t=this.graphStore.getEdge(e);if(t===void 0)return null;const s=t.payload;return{from:t.from,to:t.to,priority:s.priority,shape:s.shape}}getPortIncomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortIncomingEdgeIds(e)}getPortOutgoingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortOutgoingEdgeIds(e)}getPortCycleEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortCycleEdgeIds(e)}getPortAdjacentEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortAdjacentEdgeIds(e)}getNodeIncomingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeIncomingEdgeIds(e)}getNodeOutgoingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeOutgoingEdgeIds(e)}getNodeCycleEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeCycleEdgeIds(e)}getNodeAdjacentEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeAdjacentEdgeIds(e)}}class Le{constructor(e){o(this,"onAfterUpdated");this.viewportStore=e,this.onAfterUpdated=this.viewportStore.onAfterUpdated}getViewportMatrix(){return{...this.viewportStore.getViewportMatrix()}}getContentMatrix(){return{...this.viewportStore.getContentMatrix()}}}const Ce=(r,e)=>{const t=new le,s=new Me(t),i=new Le(e),n=new de(t,e,r),a={nodes:{centerFn:fe,priorityFn:()=>0},edges:{shapeFactory:()=>new J,priorityFn:()=>0},ports:{direction:0}};return new ce(s,i,t,e,n,a)};class H{constructor(e,t,s,i){o(this,"onAfterPortMarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.hookPortEvents(t.element)});o(this,"onBeforePortUnmarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.unhookPortEvents(t.element)});o(this,"onPortMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.canvas.graph.getElementPortIds(t)[0];this.params.onPortPointerDown(s,{x:e.clientX,y:e.clientY})&&(e.stopPropagation(),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}))});o(this,"onWindowMouseMove",e=>{if(!V(this.window,this.element,e.clientX,e.clientY)){this.stopMouseDrag();return}this.params.onPointerMove({x:e.clientX,y:e.clientY})});o(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&(this.params.onPointerUp({x:e.clientX,y:e.clientY}),this.stopMouseDrag())});o(this,"onPortTouchStart",e=>{if(e.touches.length!==1)return;const t=e.touches[0],s=e.currentTarget,i=this.canvas.graph.getElementPortIds(s)[0];this.params.onPortPointerDown(i,{x:t.clientX,y:t.clientY})&&(e.stopPropagation(),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}))});o(this,"onWindowTouchMove",e=>{const t=e.touches[0];if(!V(this.window,this.element,t.clientX,t.clientY)){this.stopTouchDrag();return}this.params.onPointerMove({x:t.clientX,y:t.clientY})});o(this,"onWindowTouchFinish",e=>{const t=e.changedTouches[0];this.params.onPointerUp({x:t.clientX,y:t.clientY}),this.stopTouchDrag()});o(this,"onBeforeClear",()=>{this.canvas.graph.getAllPortIds().forEach(e=>{const t=this.canvas.graph.getPort(e);this.unhookPortEvents(t.element)})});o(this,"onBeforeDestroy",()=>{this.params.onStopDrag(),this.removeWindowMouseListeners(),this.removeWindowTouchListeners()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.canvas.graph.onAfterPortMarked.subscribe(this.onAfterPortMarked),this.canvas.graph.onBeforePortUnmarked.subscribe(this.onBeforePortUnmarked),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new H(e,t,s,i)}hookPortEvents(e){e.addEventListener("mousedown",this.onPortMouseDown,{passive:!0}),e.addEventListener("touchstart",this.onPortTouchStart,{passive:!0})}unhookPortEvents(e){e.removeEventListener("mousedown",this.onPortMouseDown),e.removeEventListener("touchstart",this.onPortTouchStart)}stopMouseDrag(){this.params.onStopDrag(),this.removeWindowMouseListeners()}stopTouchDrag(){this.params.onStopDrag(),this.removeWindowTouchListeners()}removeWindowMouseListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}removeWindowTouchListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class q{constructor(e,t,s,i){o(this,"grabbedNode",null);o(this,"maxNodePriority",0);o(this,"graph");o(this,"onAfterNodeAdded",e=>{this.updateMaxNodePriority(e);const t=this.graph.getNode(e);t.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),t.element.addEventListener("touchstart",this.onTouchStart,{passive:!0})});o(this,"onAfterNodeUpdated",e=>{this.updateMaxNodePriority(e)});o(this,"onBeforeNodeRemoved",e=>{const t=this.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)});o(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});o(this,"onBeforeClear",()=>{this.canvas.graph.getAllNodeIds().forEach(e=>{const t=this.canvas.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)}),this.maxNodePriority=0});o(this,"onMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.graph.getElementNodeId(t),i=this.graph.getNode(s);if(!this.params.nodeDragVerifier(s))return;e.stopPropagation();const a=this.calculateContentPoint({x:e.clientX,y:e.clientY});this.grabbedNode={nodeId:s,dx:a.x-i.x,dy:a.y-i.y},F(this.element,this.params.dragCursor),this.moveNodeOnTop(s),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0})});o(this,"onTouchStart",e=>{if(e.touches.length!==1)return;e.stopPropagation();const t=e.touches[0],s=e.currentTarget,i=this.canvas.graph.getElementNodeId(s),n=this.graph.getNode(i);if(!this.params.nodeDragVerifier({nodeId:i,element:n.element,x:n.x,y:n.y}))return;const h=this.calculateContentPoint({x:t.clientX,y:t.clientY});this.grabbedNode={nodeId:i,dx:h.x-n.x,dy:h.y-n.y},this.moveNodeOnTop(i),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0})});o(this,"onWindowMouseMove",e=>{if(!V(this.window,this.element,e.clientX,e.clientY)){this.cancelMouseDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:e.clientX,y:e.clientY})});o(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&this.cancelMouseDrag()});o(this,"onWindowTouchMove",e=>{if(e.touches.length!==1)return;const t=e.touches[0];if(!V(this.window,this.element,t.clientX,t.clientY)){this.cancelTouchDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:t.clientX,y:t.clientY})});o(this,"onWindowTouchFinish",()=>{this.cancelTouchDrag()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.graph=e.graph,this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new q(e,t,s,i)}moveNode(e,t){if(this.graph.getNode(e.nodeId)===null)return;const i=this.calculateContentPoint(t),n={x:i.x-e.dx,y:i.y-e.dy},a=this.adjustNodeCoords(n);this.canvas.updateNode(e.nodeId,{x:a.x,y:a.y}),this.params.onNodeDrag(e.nodeId)}moveNodeOnTop(e){if(this.params.moveOnTop){if(this.maxNodePriority++,this.params.moveEdgesOnTop){const t=this.maxNodePriority;this.maxNodePriority++,this.graph.getNodeAdjacentEdgeIds(e).forEach(i=>{this.canvas.updateEdge(i,{priority:t})})}this.canvas.updateNode(e,{priority:this.maxNodePriority})}}cancelMouseDrag(){this.grabbedNode!==null&&this.graph.getNode(this.grabbedNode.nodeId)!==null&&this.params.onNodeDragFinished(this.grabbedNode.nodeId),this.grabbedNode=null,F(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){if(this.grabbedNode!==null){const e=this.graph.getNode(this.grabbedNode.nodeId);e!==null&&this.params.onNodeDragFinished({nodeId:this.grabbedNode.nodeId,element:e.element,x:e.x,y:e.y})}this.grabbedNode=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}updateMaxNodePriority(e){const t=this.graph.getNode(e).priority;this.maxNodePriority=Math.max(this.maxNodePriority,t)}calculateContentPoint(e){const t=this.element.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix();return A(i,s)}adjustNodeCoords(e){const t=this.params.gridSize;if(t!==null){const s=t/2;return{x:Math.floor((e.x+s)/t)*t,y:Math.floor((e.y+s)/t)*t}}return e}}const yt=(r,e,t)=>({scale:r.scale,x:r.x+r.scale*e,y:r.y+r.scale*t}),vt=(r,e,t,s)=>({scale:r.scale*e,x:r.scale*(1-e)*t+r.x,y:r.scale*(1-e)*s+r.y}),X=r=>{const e=[],t=r.touches.length;for(let h=0;h<t;h++)e.push([r.touches[h].clientX,r.touches[h].clientY]);const s=e.reduce((h,d)=>[h[0]+d[0],h[1]+d[1]],[0,0]),i=[s[0]/t,s[1]/t],a=e.map(h=>[h[0]-i[0],h[1]-i[1]]).reduce((h,d)=>h+Math.sqrt(d[0]*d[0]+d[1]*d[1]),0);return{x:i[0],y:i[1],scale:a/t,touchesCnt:t,touches:e}};class Y{constructor(e,t,s,i){o(this,"viewport");o(this,"prevTouches",null);o(this,"wheelFinishTimer",null);o(this,"transformInProgress",!1);o(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});o(this,"onMouseDown",e=>{this.element===null||!this.params.mouseDownEventVerifier(e)||(F(this.element,this.params.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}),this.startRegisteredTransform())});o(this,"onWindowMouseMove",e=>{const t=V(this.window,this.element,e.clientX,e.clientY);if(this.element===null||!t){this.stopMouseDrag();return}const s=-e.movementX,i=-e.movementY;this.moveViewport(s,i)});o(this,"onWindowMouseUp",e=>{this.element===null||!this.params.mouseUpEventVerifier(e)||this.stopMouseDrag()});o(this,"onWheelScroll",e=>{if(!this.params.mouseWheelEventVerifier(e))return;const{left:t,top:s}=this.element.getBoundingClientRect(),i=e.clientX-t,n=e.clientY-s,h=1/(e.deltaY<0?this.params.wheelSensitivity:1/this.params.wheelSensitivity);this.wheelFinishTimer===null&&this.params.onTransformStarted(),this.scaleViewport(h,i,n),this.wheelFinishTimer!==null&&clearTimeout(this.wheelFinishTimer),this.wheelFinishTimer=setTimeout(()=>{this.transformInProgress||this.params.onTransformFinished(),this.wheelFinishTimer=null},this.params.scaleWheelFinishTimeout)});o(this,"onTouchStart",e=>{if(this.prevTouches!==null){this.prevTouches=X(e);return}this.prevTouches=X(e),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}),this.startRegisteredTransform()});o(this,"onWindowTouchMove",e=>{const t=X(e);if(!t.touches.every(i=>V(this.window,this.element,i[0],i[1]))){this.stopTouchDrag();return}if((t.touchesCnt===1||t.touchesCnt===2)&&this.moveViewport(-(t.x-this.prevTouches.x),-(t.y-this.prevTouches.y)),t.touchesCnt===2){const{left:i,top:n}=this.element.getBoundingClientRect(),a=this.prevTouches.x-i,h=this.prevTouches.y-n,c=1/(t.scale/this.prevTouches.scale);this.scaleViewport(c,a,h)}this.prevTouches=t});o(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=X(e):this.stopTouchDrag()});o(this,"observer",new ResizeObserver(()=>{const e=this.viewport.getViewportMatrix(),{width:t,height:s}=this.element.getBoundingClientRect(),i=this.params.transformPreprocessor({prevTransform:e,nextTransform:e,canvasWidth:t,canvasHeight:s});this.params.onResizeTransformStarted(),this.canvas.patchViewportMatrix(i),this.params.onResizeTransformFinished()}));o(this,"preventWheelScaleListener",e=>{e.preventDefault()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.element.addEventListener("wheel",this.preventWheelScaleListener,{passive:!1}),this.viewport=e.viewport,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),this.element.addEventListener("wheel",this.onWheelScroll,{passive:!0}),this.element.addEventListener("touchstart",this.onTouchStart,{passive:!0}),e.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new Y(e,t,s,i)}moveViewport(e,t){const s=this.viewport.getViewportMatrix(),i=yt(s,e,t),{width:n,height:a}=this.element.getBoundingClientRect(),h=this.params.transformPreprocessor({prevTransform:s,nextTransform:i,canvasWidth:n,canvasHeight:a});this.performTransform(h)}scaleViewport(e,t,s){const i=this.canvas.viewport.getViewportMatrix(),n=vt(i,e,t,s),{width:a,height:h}=this.element.getBoundingClientRect(),d=this.params.transformPreprocessor({prevTransform:i,nextTransform:n,canvasWidth:a,canvasHeight:h});this.performTransform(d)}stopMouseDrag(){F(this.element,null),this.removeMouseDragListeners(),this.finishRegisteredTransform()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.finishRegisteredTransform()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}performTransform(e){this.params.onBeforeTransformChange(),this.canvas.patchViewportMatrix(e),this.params.onTransformChange()}startRegisteredTransform(){this.transformInProgress=!0,this.params.onTransformStarted()}finishRegisteredTransform(){this.transformInProgress=!1,this.params.onTransformFinished()}}class _{constructor(e,t,s,i,n,a){o(this,"canvasResizeObserver");o(this,"nodeHorizontal");o(this,"nodeVertical");o(this,"viewport");o(this,"viewportWidth",0);o(this,"viewportHeight",0);o(this,"viewportMatrix");o(this,"loadedArea",{xFrom:1/0,xTo:1/0,yFrom:1/0,yTo:1/0});o(this,"updateLoadedArea",e=>{this.loadedArea={xFrom:e.x,xTo:e.x+e.width,yFrom:e.y,yTo:e.y+e.height}});o(this,"onAfterViewportUpdated",()=>{this.userTransformInProgress||(this.viewportMatrix=this.viewport.getViewportMatrix(),this.loadAreaAroundViewport())});o(this,"userTransformInProgress",!1);this.canvas=e,this.element=t,this.window=s,this.trigger=n,this.params=a,this.nodeHorizontal=this.params.nodeVerticalRadius,this.nodeVertical=this.params.nodeHorizontalRadius,this.canvasResizeObserver=new ResizeObserver(d=>{const c=d[0];this.viewportWidth=c.contentRect.width,this.viewportHeight=c.contentRect.height,this.scheduleLoadAreaAroundViewport()}),this.viewport=e.viewport;const h={...i,onResizeTransformStarted:()=>{this.userTransformInProgress=!0,i.onResizeTransformStarted()},onResizeTransformFinished:()=>{this.userTransformInProgress=!1,i.onResizeTransformFinished()},onBeforeTransformChange:()=>{this.userTransformInProgress=!0,i.onBeforeTransformChange()},onTransformChange:()=>{this.userTransformInProgress=!1;const d=this.viewportMatrix;this.viewportMatrix=this.viewport.getViewportMatrix(),d.scale!==this.viewportMatrix.scale&&this.scheduleEnsureViewportAreaLoaded(),i.onTransformChange()},onTransformFinished:()=>{this.scheduleLoadAreaAroundViewport(),i.onTransformFinished()}};Y.configure(e,this.element,this.window,h),this.viewportMatrix=this.viewport.getViewportMatrix(),this.trigger.subscribe(this.updateLoadedArea),this.canvasResizeObserver.observe(this.element),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated)}static configure(e,t,s,i,n,a){new _(e,t,s,i,n,a)}scheduleLoadAreaAroundViewport(){setTimeout(()=>{this.loadAreaAroundViewport()})}scheduleEnsureViewportAreaLoaded(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-this.nodeHorizontal,i=this.viewportMatrix.y-this.nodeVertical,n=this.viewportMatrix.x+e+this.nodeHorizontal,a=this.viewportMatrix.y+t+this.nodeVertical;this.loadedArea.xFrom<s&&this.loadedArea.xTo>n&&this.loadedArea.yFrom<i&&this.loadedArea.yTo>a||this.scheduleLoadAreaAroundViewport()}loadAreaAroundViewport(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-e-this.nodeHorizontal,i=this.viewportMatrix.y-t-this.nodeVertical,n=3*e+2*this.nodeHorizontal,a=3*t+2*this.nodeVertical;this.trigger.emit({x:s,y:i,width:n,height:a})}}const Et=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.style.position="absolute",r.style.inset="0",r},At=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","rect");return r.setAttribute("fill","url(#pattern)"),r},xt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","pattern");return r.setAttribute("id","pattern"),r};class ee{constructor(e,t,s){o(this,"svg",Et());o(this,"patternRenderingRectangle",At());o(this,"pattern",xt());o(this,"patternContent");o(this,"tileWidth");o(this,"tileHeight");o(this,"halfTileWidth");o(this,"halfTileHeight");o(this,"maxViewportScale");o(this,"visible",!1);o(this,"resizeObserver",new ResizeObserver(e=>{const t=e[0],{width:s,height:i}=t.contentRect;this.svg.setAttribute("width",`${s}`),this.svg.setAttribute("height",`${i}`),this.patternRenderingRectangle.setAttribute("width",`${s}`),this.patternRenderingRectangle.setAttribute("height",`${i}`);const n=this.tileWidth/s,a=this.tileHeight/i;this.pattern.setAttribute("width",`${n}`),this.pattern.setAttribute("height",`${a}`)}));o(this,"onAfterTransformUpdated",()=>{const e=this.canvas.viewport.getContentMatrix(),t=e.x-this.halfTileWidth*e.scale,s=e.y-this.halfTileHeight*e.scale,i=`matrix(${e.scale}, 0, 0, ${e.scale}, ${t}, ${s})`;this.pattern.setAttribute("patternTransform",i),this.updateVisibility()});this.canvas=e,this.backgroundHost=s,this.tileWidth=t.tileWidth,this.tileHeight=t.tileHeight,this.halfTileWidth=this.tileWidth/2,this.halfTileHeight=this.tileHeight/2,this.patternContent=t.renderer,this.maxViewportScale=t.maxViewportScale;const i=`translate(${this.halfTileWidth}, ${this.halfTileHeight})`;this.patternContent.setAttribute("transform",i),this.pattern.appendChild(this.patternContent);const n=document.createElementNS("http://www.w3.org/2000/svg","defs");n.appendChild(this.pattern),this.svg.appendChild(n),this.svg.appendChild(this.patternRenderingRectangle),this.resizeObserver.observe(this.backgroundHost),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated),this.onAfterTransformUpdated()}static configure(e,t,s){new ee(e,t,s)}updateVisibility(){const t=this.canvas.viewport.getViewportMatrix().scale>this.maxViewportScale;t&&this.visible?(this.visible=!1,this.backgroundHost.removeChild(this.svg)):!t&&!this.visible&&(this.visible=!0,this.backgroundHost.appendChild(this.svg))}}class te{constructor(e,t,s,i,n){o(this,"overlayCanvas");o(this,"staticPortId",null);o(this,"isTargetDragging",!0);o(this,"onEdgeCreated",e=>{this.params.onAfterEdgeCreated(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=i,this.params=n,this.overlayCanvas=Ce(this.overlayLayer,this.viewportStore),H.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>{const d=this.params.connectionTypeResolver(a);return d===null?!1:(this.grabPort(a,h,d),!0)},onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,i,n){new te(e,t,s,i,n)}grabPort(e,t,s){const i=this.canvas.graph.getPort(e);this.staticPortId=e;const n=i.element.getBoundingClientRect(),a=n.x+n.width/2,h=n.y+n.height/2,d=this.overlayLayer.getBoundingClientRect(),c=this.canvas.viewport.getViewportMatrix(),g=A(c,{x:a-d.x,y:h-d.y}),l=A(c,{x:t.x-d.x,y:t.y-d.y}),p={overlayId:N.Static,portCoords:g,portDirection:i.direction},w={overlayId:N.Dragging,portCoords:l,portDirection:this.params.dragPortDirection};this.isTargetDragging=s==="direct";const[m,v]=this.isTargetDragging?[p,w]:[w,p];this.overlayCanvas.addNode(O(m)),this.overlayCanvas.addNode(O(v)),this.overlayCanvas.addEdge({from:m.overlayId,to:v.overlayId,shape:this.params.edgeShapeFactory(N.Edge)})}resetDragState(){this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}tryCreateConnection(e){const t=we(this.canvas.graph,e),s=this.staticPortId;if(t===null){this.params.onEdgeCreationInterrupted({staticPortId:s,isDirect:this.isTargetDragging});return}const i=this.isTargetDragging?s:t,n=this.isTargetDragging?t:s,a={from:i,to:n},h=this.params.connectionPreprocessor(a);h!==null?(this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)):this.params.onEdgeCreationPrevented(a)}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix(),n=A(i,s);this.overlayCanvas.updateNode(N.Dragging,{x:n.x,y:n.y})}}class re{constructor(e,t,s,i,n){o(this,"overlayCanvas");o(this,"staticPortId",null);o(this,"isTargetDragging",!0);o(this,"draggingEdgePayload",null);o(this,"onEdgeReattached",e=>{this.params.onAfterEdgeReattached(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=i,this.params=n,this.overlayCanvas=Ce(this.overlayLayer,this.viewportStore),H.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>this.tryStartEdgeDragging(a,h),onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,i,n){new re(e,t,s,i,n)}tryStartEdgeDragging(e,t){const s=this.params.draggingEdgeResolver(e);if(s===null)return!1;const i=this.canvas.graph.getEdge(s);if(i===null)return!1;const n=e===i.from,a=e===i.to,h=n?i.to:i.from;this.staticPortId=h,this.isTargetDragging=a;const d=this.canvas.graph.getPort(e),c=this.canvas.graph.getPort(h),g=c.element.getBoundingClientRect(),l={x:g.x+g.width/2,y:g.y+g.height/2},p=this.canvas.viewport.getViewportMatrix(),w=this.overlayLayer.getBoundingClientRect(),m=A(p,{x:l.x-w.x,y:l.y-w.y}),v=A(p,{x:t.x-w.x,y:t.y-w.y});this.draggingEdgePayload={id:s,from:i.from,to:i.to,shape:i.shape,priority:i.priority},this.canvas.removeEdge(s);const x={overlayId:N.Static,portCoords:m,portDirection:c.direction},S={overlayId:N.Dragging,portCoords:v,portDirection:d.direction},[$,M]=this.isTargetDragging?[x,S]:[S,x];this.overlayCanvas.addNode(O($)),this.overlayCanvas.addNode(O(M));const C=this.params.draggingEdgeShapeFactory!==null?this.params.draggingEdgeShapeFactory(N.Edge):i.shape;return this.overlayCanvas.addEdge({id:N.Edge,from:$.overlayId,to:M.overlayId,shape:C}),!0}resetDragState(){this.draggingEdgePayload=null,this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix(),n=A(i,s);this.overlayCanvas.updateNode(N.Dragging,{x:n.x,y:n.y})}tryCreateConnection(e){const t=we(this.canvas.graph,e);if(this.overlayCanvas.removeEdge(N.Edge),t===null){const d=this.draggingEdgePayload;this.params.onEdgeReattachInterrupted({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority});return}const[s,i]=this.isTargetDragging?[this.staticPortId,t]:[t,this.staticPortId],n=this.draggingEdgePayload,a={id:n.id,from:s,to:i,shape:n.shape,priority:n.priority},h=this.params.connectionPreprocessor(a);if(h!==null)this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeReattached);else{const d=this.draggingEdgePayload;this.params.onEdgeReattachPrevented({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority})}}}class se{constructor(e,t,s){this.canvas=e,this.layoutAlgorithm=t,this.trigger=s,this.trigger.subscribe(()=>{this.applyLayout()})}static configure(e,t,s){new se(e,t,s)}applyLayout(){this.layoutAlgorithm.calculateCoordinates(this.canvas.graph).forEach((t,s)=>{this.canvas.updateNode(s,t)})}}class oe{constructor(e,t){o(this,"applyScheduled",!1);this.canvas=e,this.layoutAlgorithm=t,this.canvas.graph.onAfterNodeAdded.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onBeforeNodeRemoved.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onAfterEdgeAdded.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onBeforeEdgeRemoved.subscribe(()=>{this.scheduleApply()})}static configure(e,t){new oe(e,t)}scheduleApply(){this.applyScheduled||(this.applyScheduled=!0,setTimeout(()=>{this.applyScheduled=!1,this.applyLayout()}))}applyLayout(){this.layoutAlgorithm.calculateCoordinates(this.canvas.graph).forEach((t,s)=>{this.canvas.updateNode(s,t)})}}class St{static configure(e,t){const s=t.applyOn;switch(s.type){case"manual":{se.configure(e,t.algorithm,s.trigger);break}case"topologyChangeTimeout":{oe.configure(e,t.algorithm);break}}}}class Pt{constructor(e,t){o(this,"previousTimeStamp");o(this,"step",e=>{if(this.previousTimeStamp===void 0)this.previousTimeStamp=e;else{const t=(e-this.previousTimeStamp)/1e3;this.previousTimeStamp=e,this.callback(t)}this.win.requestAnimationFrame(this.step)});this.win=e,this.callback=t,this.win.requestAnimationFrame(this.step)}}class ie{constructor(e,t,s,i){o(this,"step",e=>{this.algorithm.calculateNextCoordinates(this.canvas.graph,e).forEach((s,i)=>{this.staticNodes.has(i)||this.canvas.updateNode(i,{x:s.x,y:s.y})})});this.canvas=e,this.algorithm=t,this.staticNodes=s,this.win=i,new Pt(this.win,this.step)}static configure(e,t,s,i){new ie(e,t,s,i)}}const bt=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r},ne=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.inset="0",r},Re=()=>{const r=ne();return r.style.pointerEvents="none",r};class Tt{constructor(e){o(this,"background",ne());o(this,"main",ne());o(this,"overlayConnectablePorts",Re());o(this,"overlayDraggableEdges",Re());o(this,"host",bt());this.element=e,this.element.appendChild(this.host),this.host.appendChild(this.background),this.host.appendChild(this.main),this.host.appendChild(this.overlayConnectablePorts),this.host.appendChild(this.overlayDraggableEdges)}destroy(){this.host.removeChild(this.background),this.host.removeChild(this.main),this.host.removeChild(this.overlayConnectablePorts),this.host.removeChild(this.overlayDraggableEdges),this.element.removeChild(this.host)}}const ae=r=>()=>r,Ve=ae(0),Dt=()=>{let r=0;return()=>r++},Nt=(r,e)=>{let t=Ve,s=Ve;const i=Dt();return r==="incremental"&&(t=i),e==="incremental"&&(s=i),typeof r=="number"&&(t=ae(r)),typeof e=="number"&&(s=ae(e)),typeof r=="function"&&(t=r),typeof e=="function"&&(s=e),{nodesPriorityFn:t,edgesPriorityFn:s}},he=r=>{if(typeof r=="function")return r;switch(r.type){case"straight":return()=>new be({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance,detourDirection:r.detourDirection});case"horizontal":return()=>new Pe({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"vertical":return()=>new Te({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"direct":return()=>new J({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,sourceOffset:r.sourceOffset,targetOffset:r.targetOffset});default:return()=>new Se({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleRadius:r.cycleRadius,smallCycleRadius:r.smallCycleRadius,curvature:r.curvature,detourDistance:r.detourDistance,detourDirection:r.detourDirection})}},Mt=r=>{var t,s,i,n,a;const e=Nt((t=r.nodes)==null?void 0:t.priority,(s=r.edges)==null?void 0:s.priority);return{nodes:{centerFn:((i=r.nodes)==null?void 0:i.centerFn)??fe,priorityFn:e.nodesPriorityFn},ports:{direction:((n=r.ports)==null?void 0:n.direction)??0},edges:{shapeFactory:he(((a=r.edges)==null?void 0:a.shape)??{}),priorityFn:e.edgesPriorityFn}}},Lt=r=>{var p,w,m,v,x;const e=((p=r.events)==null?void 0:p.onNodeDrag)??(()=>{}),t=r.nodeDragVerifier??(()=>!0),s=((w=r.events)==null?void 0:w.onNodeDragFinished)??(()=>{}),i=r.moveOnTop!==!1,n=r.moveEdgesOnTop!==!1&&i,a=(m=r.mouse)==null?void 0:m.dragCursor,h=a!==void 0?a:"grab",d=(v=r.mouse)==null?void 0:v.mouseDownEventVerifier,c=d!==void 0?d:S=>S.button===0,g=(x=r.mouse)==null?void 0:x.mouseUpEventVerifier,l=g!==void 0?g:S=>S.button===0;return{moveOnTop:i,moveEdgesOnTop:n,dragCursor:h,gridSize:r.gridSize??null,mouseDownEventVerifier:c,mouseUpEventVerifier:l,onNodeDrag:e,nodeDragVerifier:t,onNodeDragFinished:s}},Ct=r=>{const e=r.minX!==null?r.minX:-1/0,t=r.maxX!==null?r.maxX:1/0,s=r.minY!==null?r.minY:-1/0,i=r.maxY!==null?r.maxY:1/0;return n=>{let a=n.nextTransform.x,h=n.nextTransform.y;a<e&&a<n.prevTransform.x&&(a=Math.min(n.prevTransform.x,e));const d=n.canvasWidth*n.prevTransform.scale,c=t-d;a>c&&a>n.prevTransform.x&&(a=Math.max(n.prevTransform.x,c)),h<s&&h<n.prevTransform.y&&(h=Math.min(n.prevTransform.y,s));const g=n.canvasHeight*n.prevTransform.scale,l=i-g;return h>l&&h>n.prevTransform.y&&(h=Math.max(n.prevTransform.y,l)),{scale:n.nextTransform.scale,x:a,y:h}}},Rt=r=>{const e=r.maxContentScale,t=r.minContentScale,s=e!==null?1/e:0,i=t!==null?1/t:1/0;return n=>{const a=n.prevTransform,h=n.nextTransform;let d=h.scale,c=h.x,g=h.y;if(h.scale>i&&h.scale>a.scale){d=Math.max(a.scale,i),c=a.x,g=a.y;const l=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*l,g=a.y+(h.y-a.y)*l}if(h.scale<s&&h.scale<a.scale){d=Math.min(a.scale,s),c=a.x,g=a.y;const l=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*l,g=a.y+(h.y-a.y)*l}return{scale:d,x:c,y:g}}},Vt=r=>e=>r.reduce((t,s)=>s({prevTransform:e.prevTransform,nextTransform:t,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),$e=r=>{if(typeof r=="function")return r;switch(r.type){case"scale-limit":return Rt({minContentScale:r.minContentScale??0,maxContentScale:r.maxContentScale??1/0});case"shift-limit":return Ct({minX:r.minX??-1/0,maxX:r.maxX??1/0,minY:r.minY??-1/0,maxY:r.maxY??1/0})}},Ie=r=>{var m,v,x,S,$,M,C,U,ke,ze,He,Xe;const e=(m=r==null?void 0:r.scale)==null?void 0:m.mouseWheelSensitivity,t=e!==void 0?e:1.2,s=r==null?void 0:r.transformPreprocessor;let i;s!==void 0?Array.isArray(s)?i=Vt(s.map(R=>$e(R))):i=$e(s):i=R=>R.nextTransform;const n=((v=r==null?void 0:r.shift)==null?void 0:v.cursor)!==void 0?r.shift.cursor:"grab",a=((x=r==null?void 0:r.events)==null?void 0:x.onBeforeTransformChange)??(()=>{}),h=((S=r==null?void 0:r.events)==null?void 0:S.onTransformChange)??(()=>{}),d=($=r==null?void 0:r.shift)==null?void 0:$.mouseDownEventVerifier,c=d!==void 0?d:R=>R.button===0,g=(M=r==null?void 0:r.shift)==null?void 0:M.mouseUpEventVerifier,l=g!==void 0?g:R=>R.button===0,p=(C=r==null?void 0:r.scale)==null?void 0:C.mouseWheelEventVerifier,w=p!==void 0?p:()=>!0;return{wheelSensitivity:t,onTransformStarted:((U=r==null?void 0:r.events)==null?void 0:U.onTransformStarted)??(()=>{}),onTransformFinished:((ke=r==null?void 0:r.events)==null?void 0:ke.onTransformFinished)??(()=>{}),onBeforeTransformChange:a,onTransformChange:h,transformPreprocessor:i,shiftCursor:n,mouseDownEventVerifier:c,mouseUpEventVerifier:l,mouseWheelEventVerifier:w,scaleWheelFinishTimeout:((ze=r==null?void 0:r.scale)==null?void 0:ze.wheelFinishTimeout)??500,onResizeTransformStarted:((He=r==null?void 0:r.events)==null?void 0:He.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((Xe=r==null?void 0:r.events)==null?void 0:Xe.onResizeTransformFinished)??(()=>{})}},$t=(r,e)=>{const t=document.createElementNS("http://www.w3.org/2000/svg","circle");return t.setAttribute("cx","0"),t.setAttribute("cy","0"),t.setAttribute("r",`${r}`),t.setAttribute("fill",`${e}`),t},It=r=>r instanceof SVGElement?r:$t((r==null?void 0:r.radius)??1.5,(r==null?void 0:r.color)??"#d8d8d8"),Ut=r=>{const e=r.tileDimensions,t=(e==null?void 0:e.width)??25,s=(e==null?void 0:e.height)??25,i=It(r.renderer??{});return{tileWidth:t,tileHeight:s,renderer:i,maxViewportScale:r.maxViewportScale??10}},Bt=(r,e,t)=>{var c,g,l;const s=()=>"direct",i=p=>p,n=p=>p.button===0,a=()=>{},h=()=>{},d=()=>{};return{connectionTypeResolver:r.connectionTypeResolver??s,connectionPreprocessor:r.connectionPreprocessor??i,mouseDownEventVerifier:r.mouseDownEventVerifier??n,mouseUpEventVerifier:r.mouseUpEventVerifier??n,onAfterEdgeCreated:((c=r.events)==null?void 0:c.onAfterEdgeCreated)??a,onEdgeCreationInterrupted:((g=r.events)==null?void 0:g.onEdgeCreationInterrupted)??d,onEdgeCreationPrevented:((l=r.events)==null?void 0:l.onEdgeCreationPrevented)??h,dragPortDirection:r.dragPortDirection??t,edgeShapeFactory:r.edgeShape!==void 0?he(r.edgeShape):e}},Ft=(r,e)=>{var c,g,l;const t=p=>p,s=p=>p.button===0&&p.ctrlKey,i=p=>p.button===0,n=p=>{const w=e.getPortAdjacentEdgeIds(p);return w.length>0?w[w.length-1]:null},a=()=>{},h=()=>{},d=()=>{};return{connectionPreprocessor:r.connectionPreprocessor??t,mouseDownEventVerifier:r.mouseDownEventVerifier??s,mouseUpEventVerifier:r.mouseUpEventVerifier??i,draggingEdgeResolver:r.draggingEdgeResolver??n,draggingEdgeShapeFactory:r.draggingEdgeShape!==void 0?he(r.draggingEdgeShape):null,onAfterEdgeReattached:((c=r.events)==null?void 0:c.onAfterEdgeReattached)??a,onEdgeReattachInterrupted:((g=r.events)==null?void 0:g.onEdgeReattachInterrupted)??d,onEdgeReattachPrevented:((l=r.events)==null?void 0:l.onEdgeReattachPrevented)??h}},Ot=r=>({nodeVerticalRadius:r.nodeContainingRadius.vertical,nodeHorizontalRadius:r.nodeContainingRadius.horizontal}),Wt=r=>{var e,t;return{onAfterNodeDetached:((e=r==null?void 0:r.events)==null?void 0:e.onAfterNodeDetached)??(()=>{}),onBeforeNodeAttached:((t=r==null?void 0:r.events)==null?void 0:t.onBeforeNodeAttached)??(()=>{})}};class Ue extends Error{constructor(){super(...arguments);o(this,"name","CanvasBuilderError")}}class kt{constructor(e,t){this.coordinates=e,this.rand=t}getVector(e,t){const s=this.coordinates.get(e),i=this.coordinates.get(t),n=i.x-s.x,a=i.y-s.y,h=n*n+a*a;if(h===0){const l=this.rand()*2*Math.PI;return{ex:Math.cos(l),ey:Math.sin(l),d2:1,d:1}}const d=Math.sqrt(h),c=n/d,g=a/d;return{ex:c,ey:g,d2:h,d}}}class Be{constructor(e,t,s){o(this,"dtSec");o(this,"k");o(this,"nodeMass");o(this,"edgeEquilibriumLength");o(this,"edgeStiffness");o(this,"effectiveDistance");this.graph=e,this.currentCoords=t,this.params=s,this.dtSec=this.params.dtSec,this.k=this.params.nodeCharge*this.params.nodeCharge,this.nodeMass=this.params.nodeMass,this.edgeEquilibriumLength=this.params.edgeEquilibriumLength,this.edgeStiffness=this.params.edgeStiffness,this.effectiveDistance=this.params.effectiveDistance}next(){let e=0;const t=new Map,s=this.graph.getAllNodeIds();s.forEach(a=>{t.set(a,{x:0,y:0})});const i=new kt(this.currentCoords,this.params.rand),n=s.length;for(let a=0;a<n;a++){const h=s[a];for(let d=a+1;d<n;d++){const c=s[d],g=i.getVector(h,c);if(g.d>this.effectiveDistance)continue;const l=this.k/g.d2,p=l*g.ex,w=l*g.ey,m=p/2,v=w/2,x=t.get(h),S=t.get(c);x.x-=m,x.y-=v,S.x+=m,S.y+=v}}return this.graph.getAllEdgeIds().forEach(a=>{const h=this.graph.getEdge(a),d=this.graph.getPort(h.from),c=this.graph.getPort(h.to),g=i.getVector(d.nodeId,c.nodeId),p=(g.d-this.edgeEquilibriumLength)*this.edgeStiffness/2,w=g.ex*p,m=g.ey*p,v=t.get(d.nodeId),x=t.get(c.nodeId);v.x+=w,v.y+=m,x.x-=w,x.y-=m}),this.currentCoords.forEach((a,h)=>{const d=t.get(h),c={x:d.x/this.nodeMass*this.dtSec,y:d.y/this.nodeMass*this.dtSec},g=c.x*this.dtSec,l=c.y*this.dtSec;a.x+=g,a.y+=l,e=Math.max(e,Math.sqrt(g*g+l*l))}),e}}const Fe=(r,e,t)=>{const s=new Map,i=r.getAllNodeIds(),n=Math.sqrt(i.length)*t;return i.forEach(a=>{const h=r.getNode(a);s.set(a,{x:h.x??n*e(),y:h.y??n*e()})}),s};class zt{constructor(e){this.params=e}calculateCoordinates(e){const t=Fe(e,this.params.rand,this.params.edgeEquilibriumLength);for(let s=0;s<this.params.maxIterations&&!(new Be(e,t,{rand:this.params.rand,dtSec:this.params.dtSec,nodeMass:this.params.nodeMass,nodeCharge:this.params.nodeCharge,edgeEquilibriumLength:this.params.edgeEquilibriumLength,effectiveDistance:this.params.effectiveDistance,edgeStiffness:this.params.edgeStiffness}).next()<this.params.convergenceDelta);s++);return t}}class Ht{constructor(e){this.params=e}calculateNextCoordinates(e,t){const s=Fe(e,this.params.rand,this.params.edgeEquilibriumLength);return new Be(e,s,{rand:this.params.rand,dtSec:Math.min(t,this.params.maxTimeDeltaSec),nodeMass:this.params.nodeMass,nodeCharge:this.params.nodeCharge,edgeEquilibriumLength:this.params.edgeEquilibriumLength,effectiveDistance:this.params.effectiveDistance,edgeStiffness:this.params.edgeStiffness}).next()<this.params.convergenceDelta&&!e.getAllNodeIds().some(h=>{const d=e.getNode(h);return d.x===null||d.y===null})?new Map:s}}const Oe=r=>{let e=1779033703,t=3144134277,s=1013904242,i=2773480762;for(let n=0,a;n<r.length;n++)a=r.charCodeAt(n),e=t^Math.imul(e^a,597399067),t=s^Math.imul(t^a,2869860233),s=i^Math.imul(s^a,951274213),i=e^Math.imul(i^a,2716044179);return e=Math.imul(s^e>>>18,597399067),t=Math.imul(i^t>>>22,2869860233),s=Math.imul(e^s>>>17,951274213),i=Math.imul(t^i>>>19,2716044179),e^=t^s^i,t^=e,s^=e,i^=e,[e>>>0,t>>>0,s>>>0,i>>>0]},We=(r,e,t,s)=>function(){r|=0,e|=0,t|=0,s|=0;const i=(r+e|0)+s|0;return s=s+1|0,r=e^e>>>9,e=t+(t<<3)|0,t=t<<21|t>>>11,t=t+i|0,(i>>>0)/4294967296},b=Object.freeze({seed:"HTMLGraph is awesome",maxTimeDeltaSec:.1,nodeCharge:1e5,nodeMass:1,edgeEquilibriumLength:300,edgeStiffness:1e3,effectiveDistance:1e3,dtSec:.02,maxIterations:100,convergenceDelta:.001}),Xt=r=>{var e;switch((e=r==null?void 0:r.algorithm)==null?void 0:e.type){case"custom":return r.algorithm.instance;default:{const t=r==null?void 0:r.algorithm,s=Oe((t==null?void 0:t.seed)??b.seed),i=We(s[0],s[1],s[2],s[3]);return new Ht({rand:i,maxTimeDeltaSec:(t==null?void 0:t.maxTimeDeltaSec)??b.maxTimeDeltaSec,nodeCharge:(t==null?void 0:t.nodeCharge)??b.nodeCharge,nodeMass:(t==null?void 0:t.nodeMass)??b.nodeMass,edgeEquilibriumLength:(t==null?void 0:t.edgeEquilibriumLength)??b.edgeEquilibriumLength,effectiveDistance:b.effectiveDistance,edgeStiffness:(t==null?void 0:t.edgeStiffness)??b.edgeStiffness,convergenceDelta:(t==null?void 0:t.convergenceDelta)??b.convergenceDelta})}}},Yt=r=>r instanceof B?{type:"manual",trigger:r}:{type:"topologyChangeTimeout"},jt=r=>{switch(r==null?void 0:r.type){case"custom":return r.instance;default:{const e=Oe((r==null?void 0:r.seed)??b.seed),t=We(e[0],e[1],e[2],e[3]);return new zt({dtSec:(r==null?void 0:r.dtSec)??b.dtSec,maxIterations:(r==null?void 0:r.maxIterations)??b.maxIterations,rand:t,nodeCharge:(r==null?void 0:r.nodeCharge)??b.nodeCharge,nodeMass:(r==null?void 0:r.nodeMass)??b.nodeMass,edgeEquilibriumLength:(r==null?void 0:r.edgeEquilibriumLength)??b.edgeEquilibriumLength,edgeStiffness:(r==null?void 0:r.edgeStiffness)??b.edgeStiffness,effectiveDistance:(r==null?void 0:r.effectiveDistance)??b.effectiveDistance,convergenceDelta:(r==null?void 0:r.convergenceDelta)??b.convergenceDelta})}}},Gt=r=>({algorithm:jt(r==null?void 0:r.algorithm),applyOn:Yt(r==null?void 0:r.applyOn)}),Kt=(r,e)=>({...r,nodeDragVerifier:t=>(e.add(t),r.nodeDragVerifier(t)),onNodeDragFinished:t=>{e.delete(t),r.onNodeDragFinished(t)}}),Zt=(r,e)=>{r.onBeforeNodeRemoved.subscribe(t=>{e.delete(t)}),r.onBeforeClear.subscribe(()=>{e.clear()})};class Jt{constructor(e){o(this,"used",!1);o(this,"canvasDefaults",{});o(this,"dragConfig",{});o(this,"transformConfig",{});o(this,"backgroundConfig",{});o(this,"connectablePortsConfig",{});o(this,"draggableEdgesConfig",{});o(this,"virtualScrollConfig");o(this,"layoutConfig",{});o(this,"animatedLayoutConfig",{});o(this,"hasDraggableNodes",!1);o(this,"hasTransformableViewport",!1);o(this,"hasNodeResizeReactiveEdges",!1);o(this,"hasBackground",!1);o(this,"hasUserConnectablePorts",!1);o(this,"hasUserDraggableEdges",!1);o(this,"hasAnimatedLayout",!1);o(this,"hasLayout",!1);o(this,"boxRenderingTrigger",new B);o(this,"graphStore",new le);o(this,"viewportStore",new qe);o(this,"graph",new Me(this.graphStore));o(this,"viewport",new Le(this.viewportStore));o(this,"window",window);o(this,"animationStaticNodes",new Set);this.element=e}setDefaults(e){return this.canvasDefaults=e,this}enableUserDraggableNodes(e){return this.hasDraggableNodes=!0,this.dragConfig=e??{},this}enableUserTransformableViewport(e){return this.hasTransformableViewport=!0,this.transformConfig=e??{},this}enableNodeResizeReactiveEdges(){return this.hasNodeResizeReactiveEdges=!0,this}enableVirtualScroll(e){return this.virtualScrollConfig=e,this}enableBackground(e){return this.hasBackground=!0,this.backgroundConfig=e??{},this}enableUserConnectablePorts(e){return this.hasUserConnectablePorts=!0,this.connectablePortsConfig=e??{},this}enableUserDraggableEdges(e){return this.hasUserDraggableEdges=!0,this.draggableEdgesConfig=e??{},this}enableLayout(e){return this.layoutConfig=e??{},this.hasLayout=!0,this.hasAnimatedLayout=!1,this}enableAnimatedLayout(e){return this.animatedLayoutConfig=e??{},this.hasAnimatedLayout=!0,this.hasLayout=!1,this}build(){if(this.used)throw new Ue("CanvasBuilder is a single use object");this.used=!0;const e=new Tt(this.element);let t=new de(this.graphStore,this.viewportStore,e.main);this.virtualScrollConfig!==void 0&&(t=new Ze(t,this.graphStore,this.boxRenderingTrigger,Wt(this.virtualScrollConfig))),t=new Je(t,this.graphStore);const s=Mt(this.canvasDefaults),i=new ce(this.graph,this.viewport,this.graphStore,this.viewportStore,t,s);if(this.hasBackground&&ee.configure(i,Ut(this.backgroundConfig),e.background),this.hasNodeResizeReactiveEdges&&G.configure(i),this.hasDraggableNodes){let a=Lt(this.dragConfig);this.hasAnimatedLayout&&(a=Kt(a,this.animationStaticNodes)),q.configure(i,e.main,this.window,a)}if(this.hasUserConnectablePorts){const a=Bt(this.connectablePortsConfig,s.edges.shapeFactory,s.ports.direction);te.configure(i,e.overlayConnectablePorts,this.viewportStore,this.window,a)}if(this.hasUserDraggableEdges){const a=Ft(this.draggableEdgesConfig,i.graph);re.configure(i,e.overlayDraggableEdges,this.viewportStore,this.window,a)}this.virtualScrollConfig!==void 0?_.configure(i,e.main,this.window,Ie(this.transformConfig),this.boxRenderingTrigger,Ot(this.virtualScrollConfig)):this.hasTransformableViewport&&Y.configure(i,e.main,this.window,Ie(this.transformConfig)),this.hasLayout&&St.configure(i,Gt(this.layoutConfig)),this.hasAnimatedLayout&&(Zt(i.graph,this.animationStaticNodes),ie.configure(i,Xt(this.animatedLayoutConfig),this.animationStaticNodes,this.window));const n=()=>{e.destroy(),i.onBeforeDestroy.unsubscribe(n)};return i.onBeforeDestroy.subscribe(n),i}}E.BezierEdgeShape=Se,E.CanvasBuilder=Jt,E.CanvasBuilderError=Ue,E.CanvasError=T,E.DirectEdgeShape=J,E.EventSubject=B,E.HorizontalEdgeShape=Pe,E.InteractiveEdgeError=Ne,E.InteractiveEdgeShape=Q,E.MidpointEdgeShape=mt,E.StraightEdgeShape=be,E.VerticalEdgeShape=Te,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
1
+ (function(E,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(E=typeof globalThis<"u"?globalThis:E||self,A(E.HtmlGraph={}))})(this,function(E){"use strict";var Qt=Object.defineProperty;var qt=(E,A,N)=>A in E?Qt(E,A,{enumerable:!0,configurable:!0,writable:!0,value:N}):E[A]=N;var o=(E,A,N)=>qt(E,typeof A!="symbol"?A+"":A,N);const A=(r,e)=>({x:r.scale*e.x+r.x,y:r.scale*e.y+r.y});var N=(r=>(r.Line="line",r.NodeCycle="node-cycle",r.PortCycle="port-cycle",r))(N||{});const Ye=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r.style.overflow="hidden",r},je=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="0",r.style.height="0",r},Ge=r=>{r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.visibility="hidden"};class de{constructor(e,t,s){o(this,"host",Ye());o(this,"container",je());o(this,"edgeIdToElementMap",new Map);o(this,"attachedNodeIds",new Set);o(this,"applyTransform",()=>{const e=this.viewportStore.getContentMatrix();this.container.style.transform=`matrix(${e.scale}, 0, 0, ${e.scale}, ${e.x}, ${e.y})`});this.graphStore=e,this.viewportStore=t,this.element=s,this.element.appendChild(this.host),this.host.appendChild(this.container),this.viewportStore.onAfterUpdated.subscribe(this.applyTransform)}attachNode(e){const t=this.graphStore.getNode(e);Ge(t.element),this.attachedNodeIds.add(e),this.container.appendChild(t.element),this.updateNodePosition(e),this.updateNodePriority(e),t.element.style.visibility="visible"}detachNode(e){const t=this.graphStore.getNode(e);this.container.removeChild(t.element),this.attachedNodeIds.delete(e)}attachEdge(e){const t=this.graphStore.getEdge(e).payload.shape.svg;this.edgeIdToElementMap.set(e,t),this.container.appendChild(t),this.renderEdge(e),this.updateEdgePriority(e)}detachEdge(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t),this.edgeIdToElementMap.delete(e)}clear(){this.edgeIdToElementMap.forEach((e,t)=>{this.detachEdge(t)}),this.attachedNodeIds.forEach(e=>{this.detachNode(e)})}destroy(){this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform),this.element.removeChild(this.host),this.host.removeChild(this.container)}updateNodePosition(e){const t=this.graphStore.getNode(e),{width:s,height:i}=t.element.getBoundingClientRect(),n=this.viewportStore.getViewportMatrix().scale,{payload:a}=t,h=a.centerFn(s,i),d=a.x-n*h.x,c=a.y-n*h.y;t.element.style.transform=`translate(${d}px, ${c}px)`}updateNodePriority(e){const t=this.graphStore.getNode(e);t.element.style.zIndex=`${t.payload.priority}`}updateEdgeShape(e){const t=this.edgeIdToElementMap.get(e);this.container.removeChild(t);const i=this.graphStore.getEdge(e).payload.shape.svg;this.edgeIdToElementMap.set(e,i),this.container.appendChild(i)}renderEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),i=this.graphStore.getPort(t.to),n=s.element.getBoundingClientRect(),a=i.element.getBoundingClientRect(),h=this.host.getBoundingClientRect(),d=this.viewportStore.getViewportMatrix(),c=this.createEdgeRenderPort(s,n,h,d),g=this.createEdgeRenderPort(i,a,h,d);let l=N.Line;s.element===i.element?l=N.PortCycle:s.nodeId===i.nodeId&&(l=N.NodeCycle),t.payload.shape.render({from:c,to:g,category:l})}updateEdgePriority(e){const t=this.graphStore.getEdge(e);t.payload.shape.svg.style.zIndex=`${t.payload.priority}`}createEdgeRenderPort(e,t,s,i){const n={x:t.left-s.left,y:t.top-s.top},a=A(i,n);return{x:a.x,y:a.y,width:t.width*i.scale,height:t.height*i.scale,direction:e.payload.direction}}}class Ke{constructor(e){o(this,"xFrom",1/0);o(this,"yFrom",1/0);o(this,"xTo",1/0);o(this,"yTo",1/0);this.graphStore=e}setRenderingBox(e){this.xFrom=e.x,this.xTo=e.x+e.width,this.yFrom=e.y,this.yTo=e.y+e.height}hasNode(e){const t=this.graphStore.getNode(e).payload,{x:s,y:i}=t;return s>=this.xFrom&&s<=this.xTo&&i>=this.yFrom&&i<=this.yTo}hasEdge(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,i=this.graphStore.getPort(t.to).nodeId,n=this.graphStore.getNode(s).payload,a=this.graphStore.getNode(i).payload,h=Math.min(n.x,a.x),d=Math.max(n.x,a.x),c=Math.min(n.y,a.y),g=Math.max(n.y,a.y);return h<=this.xTo&&d>=this.xFrom&&c<=this.yTo&&g>=this.yFrom}}class Ze{constructor(e,t,s,i){o(this,"attachedNodes",new Set);o(this,"attachedEdges",new Set);o(this,"renderingBox");o(this,"updateViewport",e=>{this.renderingBox.setRenderingBox(e);const t=new Set,s=new Set,i=new Set,n=new Set;this.graphStore.getAllNodeIds().forEach(a=>{const h=this.renderingBox.hasNode(a),d=this.attachedNodes.has(a);h&&!d?t.add(a):!h&&d&&s.add(a)}),this.graphStore.getAllEdgeIds().forEach(a=>{const h=this.renderingBox.hasEdge(a),d=this.attachedEdges.has(a),c=this.graphStore.getEdge(a),g=this.graphStore.getPort(c.from).nodeId,l=this.graphStore.getPort(c.to).nodeId;h&&(this.renderingBox.hasNode(g)||(t.add(g),s.delete(g)),this.renderingBox.hasNode(l)||(t.add(l),s.delete(l))),h&&!d?i.add(a):!h&&d&&n.add(a)}),n.forEach(a=>{this.handleDetachEdge(a)}),s.forEach(a=>{this.handleDetachNode(a)}),t.forEach(a=>{this.attachedNodes.has(a)||this.handleAttachNode(a)}),i.forEach(a=>{this.handleAttachEdge(a)})});this.htmlView=e,this.graphStore=t,this.trigger=s,this.params=i,this.renderingBox=new Ke(this.graphStore),this.trigger.subscribe(this.updateViewport)}attachNode(e){this.renderingBox.hasNode(e)&&this.handleAttachNode(e)}detachNode(e){this.attachedNodes.has(e)&&this.handleDetachNode(e)}attachEdge(e){this.renderingBox.hasEdge(e)&&this.attachEdgeEntities(e)}detachEdge(e){this.attachedEdges.has(e)&&this.handleDetachEdge(e)}updateNodePosition(e){this.attachedNodes.has(e)?this.htmlView.updateNodePosition(e):this.renderingBox.hasNode(e)&&(this.handleAttachNode(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(t=>{this.attachEdgeEntities(t)}))}updateNodePriority(e){this.attachedNodes.has(e)&&this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgeShape(e)}renderEdge(e){this.attachedEdges.has(e)&&this.htmlView.renderEdge(e)}updateEdgePriority(e){this.attachedEdges.has(e)&&this.htmlView.updateEdgePriority(e)}clear(){this.htmlView.clear(),this.attachedNodes.clear(),this.attachedEdges.clear()}destroy(){this.clear(),this.htmlView.destroy(),this.trigger.unsubscribe(this.updateViewport)}attachEdgeEntities(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from).nodeId,i=this.graphStore.getPort(t.to).nodeId;this.attachedNodes.has(s)||this.handleAttachNode(s),this.attachedNodes.has(i)||this.handleAttachNode(i),this.handleAttachEdge(e)}handleAttachNode(e){this.params.onBeforeNodeAttached(e),this.attachedNodes.add(e),this.htmlView.attachNode(e)}handleDetachNode(e){this.htmlView.detachNode(e),this.attachedNodes.delete(e),this.params.onAfterNodeDetached(e)}handleAttachEdge(e){this.attachedEdges.add(e),this.htmlView.attachEdge(e)}handleDetachEdge(e){this.htmlView.detachEdge(e),this.attachedEdges.delete(e)}}class Je{constructor(e,t){o(this,"deferredNodes",new Set);o(this,"deferredEdges",new Set);this.htmlView=e,this.graphStore=t}attachNode(e){this.isNodeValid(e)?this.htmlView.attachNode(e):this.deferredNodes.add(e)}detachNode(e){this.deferredNodes.has(e)?this.deferredNodes.delete(e):this.htmlView.detachNode(e)}attachEdge(e){this.isEdgeValid(e)?this.htmlView.attachEdge(e):this.deferredEdges.add(e)}detachEdge(e){this.deferredEdges.has(e)?this.deferredEdges.delete(e):this.htmlView.detachEdge(e)}updateNodePosition(e){this.deferredNodes.has(e)?this.tryAttachNode(e):this.htmlView.updateNodePosition(e)}updateNodePriority(e){this.deferredNodes.has(e)?this.tryAttachNode(e):this.htmlView.updateNodePriority(e)}updateEdgeShape(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.updateEdgeShape(e)}renderEdge(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.renderEdge(e)}updateEdgePriority(e){this.deferredEdges.has(e)?this.tryAttachEdge(e):this.htmlView.updateEdgePriority(e)}clear(){this.deferredNodes.clear(),this.deferredEdges.clear(),this.htmlView.clear()}destroy(){this.htmlView.destroy()}isNodeValid(e){const t=this.graphStore.getNode(e);return!(t.payload.x===null||t.payload.y===null)}tryAttachNode(e){this.isNodeValid(e)&&(this.deferredNodes.delete(e),this.htmlView.attachNode(e))}isEdgeValid(e){const t=this.graphStore.getEdge(e),s=this.graphStore.getPort(t.from),i=this.graphStore.getPort(t.to);return!(this.deferredNodes.has(s.nodeId)||this.deferredNodes.has(i.nodeId))}tryAttachEdge(e){this.isEdgeValid(e)&&(this.deferredEdges.delete(e),this.htmlView.attachEdge(e))}}class B{constructor(){o(this,"callbacks",new Set)}subscribe(e){this.callbacks.add(e)}unsubscribe(e){this.callbacks.delete(e)}emit(e){this.callbacks.forEach(t=>{t(e)})}}const S=()=>{const r=new B;return[r,r]};class j{constructor(e){o(this,"counter",0);this.checkExists=e}create(e){if(e!==void 0)return e;for(;this.checkExists(this.counter);)this.counter++;return this.counter}reset(){this.counter=0}}class T extends Error{constructor(){super(...arguments);o(this,"name","CanvasError")}}class ce{constructor(e,t,s,i,n,a){o(this,"nodeIdGenerator",new j(e=>this.graphStore.getNode(e)!==void 0));o(this,"portIdGenerator",new j(e=>this.graphStore.getPort(e)!==void 0));o(this,"edgeIdGenerator",new j(e=>this.graphStore.getEdge(e)!==void 0));o(this,"onAfterNodeAdded",e=>{this.htmlView.attachNode(e)});o(this,"onAfterNodeUpdated",e=>{this.htmlView.updateNodePosition(e),this.graphStore.getNodeAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});o(this,"onAfterNodePriorityUpdated",e=>{this.htmlView.updateNodePriority(e)});o(this,"onBeforeNodeRemoved",e=>{this.graphStore.getNodePortIds(e).forEach(t=>{this.unmarkPort(t)}),this.htmlView.detachNode(e)});o(this,"onAfterPortUpdated",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(s=>{this.htmlView.renderEdge(s)})});o(this,"onBeforePortUnmarked",e=>{this.graphStore.getPortAdjacentEdgeIds(e).forEach(t=>{this.removeEdge(t)})});o(this,"onAfterEdgeAdded",e=>{this.htmlView.attachEdge(e)});o(this,"onAfterEdgeShapeUpdated",e=>{this.htmlView.updateEdgeShape(e)});o(this,"onAfterEdgeUpdated",e=>{this.htmlView.renderEdge(e)});o(this,"onAfterEdgePriorityUpdated",e=>{this.htmlView.updateEdgePriority(e)});o(this,"onBeforeEdgeRemoved",e=>{this.htmlView.detachEdge(e)});o(this,"onBeforeClear",()=>{this.nodeIdGenerator.reset(),this.portIdGenerator.reset(),this.edgeIdGenerator.reset(),this.htmlView.clear()});o(this,"onBeforeDestroyEmitter");o(this,"destroyed",!1);o(this,"onBeforeDestroy");this.graph=e,this.viewport=t,this.graphStore=s,this.viewportStore=i,this.htmlView=n,this.params=a,this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.subscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.subscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.subscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.subscribe(this.onBeforeClear),[this.onBeforeDestroyEmitter,this.onBeforeDestroy]=S()}addNode(e){const t=this.nodeIdGenerator.create(e.id);if(this.graphStore.getNode(t)!==void 0)throw new T("failed to add node with existing id");if(this.graphStore.getElementNodeId(e.element)!==void 0)throw new T("failed to add node with html element already in use by another node");if(this.graphStore.addNode({id:t,element:e.element,x:e.x??null,y:e.y??null,centerFn:e.centerFn??this.params.nodes.centerFn,priority:e.priority??this.params.nodes.priorityFn()}),e.ports!==void 0)for(const s of e.ports)this.markPort({id:s.id,element:s.element,nodeId:t,direction:s.direction});return this}updateNode(e,t){if(this.graphStore.getNode(e)===void 0)throw new T("failed to update nonexistent node");return this.graphStore.updateNode(e,t??{}),this}removeNode(e){if(this.graphStore.getNode(e)===void 0)throw new T("failed to remove nonexistent node");return this.graphStore.removeNode(e),this}markPort(e){const t=this.portIdGenerator.create(e.id);if(this.graphStore.getPort(t)!==void 0)throw new T("failed to add port with existing id");if(this.graphStore.getNode(e.nodeId)===void 0)throw new T("failed to mark port for nonexistent node");return this.graphStore.addPort({id:t,element:e.element,nodeId:e.nodeId,direction:e.direction??this.params.ports.direction}),this}updatePort(e,t){if(this.graphStore.getPort(e)===void 0)throw new T("failed to update nonexistent port");return this.graphStore.updatePort(e,t??{}),this}unmarkPort(e){if(this.graphStore.getPort(e)===void 0)throw new T("failed to unmark nonexistent port");return this.graphStore.removePort(e),this}addEdge(e){const t=this.edgeIdGenerator.create(e.id);if(this.graphStore.getEdge(t)!==void 0)throw new T("failed to add edge with existing id");if(this.graphStore.getPort(e.from)===void 0)throw new T("failed to add edge from nonexistent port");if(this.graphStore.getPort(e.to)===void 0)throw new T("failed to add edge to nonexistent port");return this.graphStore.addEdge({id:t,from:e.from,to:e.to,shape:e.shape??this.params.edges.shapeFactory(t),priority:e.priority??this.params.edges.priorityFn()}),this}updateEdge(e,t){if(this.graphStore.getEdge(e)===void 0)throw new T("failed to update nonexistent edge");return this.graphStore.updateEdge(e,t??{}),this}removeEdge(e){if(this.graphStore.getEdge(e)===void 0)throw new T("failed to remove nonexistent edge");return this.graphStore.removeEdge(e),this}clear(){return this.graphStore.clear(),this}patchViewportMatrix(e){return this.viewportStore.patchViewportMatrix(e),this}patchContentMatrix(e){return this.viewportStore.patchContentMatrix(e),this}destroy(){this.destroyed||(this.clear(),this.onBeforeDestroyEmitter.emit(),this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded),this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated),this.graphStore.onAfterNodePriorityUpdated.unsubscribe(this.onAfterNodePriorityUpdated),this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved),this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated),this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked),this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded),this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(this.onAfterEdgeShapeUpdated),this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated),this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(this.onAfterEdgePriorityUpdated),this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved),this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear),this.htmlView.destroy(),this.destroyed=!0)}}class Qe{constructor(){o(this,"singleToMultiMap",new Map);o(this,"multiToSingleMap",new Map)}addRecord(e,t){const s=this.singleToMultiMap.get(e);s===void 0?this.singleToMultiMap.set(e,new Set([t])):s.add(t),this.multiToSingleMap.set(t,e)}getMultiBySingle(e){const t=this.singleToMultiMap.get(e)??new Set;return Array.from(t.values())}removeByMulti(e){const t=this.multiToSingleMap.get(e),s=this.singleToMultiMap.get(t);s.delete(e),s.size===0&&this.singleToMultiMap.delete(t),this.multiToSingleMap.delete(e)}getByMulti(e){return this.multiToSingleMap.get(e)}removeBySingle(e){this.singleToMultiMap.get(e).forEach(s=>{this.multiToSingleMap.delete(s)}),this.singleToMultiMap.delete(e)}clear(){this.singleToMultiMap.clear(),this.multiToSingleMap.clear()}forEachSingle(e){this.singleToMultiMap.forEach((t,s)=>{e(s)})}hasSingle(e){return this.singleToMultiMap.get(e)!==void 0}hasMulti(e){return this.multiToSingleMap.get(e)!==void 0}}class le{constructor(){o(this,"nodes",new Map);o(this,"ports",new Map);o(this,"edges",new Map);o(this,"nodesElementsMap",new Map);o(this,"portIncomingEdges",new Map);o(this,"portOutcomingEdges",new Map);o(this,"portCycleEdges",new Map);o(this,"elementPorts",new Qe);o(this,"afterNodeAddedEmitter");o(this,"onAfterNodeAdded");o(this,"afterNodeUpdatedEmitter");o(this,"onAfterNodeUpdated");o(this,"afterNodePriorityUpdatedEmitter");o(this,"onAfterNodePriorityUpdated");o(this,"beforeNodeRemovedEmitter");o(this,"onBeforeNodeRemoved");o(this,"afterPortAddedEmitter");o(this,"onAfterPortAdded");o(this,"afterPortUpdatedEmitter");o(this,"onAfterPortUpdated");o(this,"beforePortRemovedEmitter");o(this,"onBeforePortRemoved");o(this,"afterEdgeAddedEmitter");o(this,"onAfterEdgeAdded");o(this,"afterEdgeShapeUpdatedEmitter");o(this,"onAfterEdgeShapeUpdated");o(this,"afterEdgeUpdatedEmitter");o(this,"onAfterEdgeUpdated");o(this,"afterEdgePriorityUpdatedEmitter");o(this,"onAfterEdgePriorityUpdated");o(this,"beforeEdgeRemovedEmitter");o(this,"onBeforeEdgeRemoved");o(this,"beforeClearEmitter");o(this,"onBeforeClear");[this.afterNodeAddedEmitter,this.onAfterNodeAdded]=S(),[this.afterNodeUpdatedEmitter,this.onAfterNodeUpdated]=S(),[this.afterNodePriorityUpdatedEmitter,this.onAfterNodePriorityUpdated]=S(),[this.beforeNodeRemovedEmitter,this.onBeforeNodeRemoved]=S(),[this.afterPortAddedEmitter,this.onAfterPortAdded]=S(),[this.afterPortUpdatedEmitter,this.onAfterPortUpdated]=S(),[this.beforePortRemovedEmitter,this.onBeforePortRemoved]=S(),[this.afterEdgeAddedEmitter,this.onAfterEdgeAdded]=S(),[this.afterEdgeShapeUpdatedEmitter,this.onAfterEdgeShapeUpdated]=S(),[this.afterEdgeUpdatedEmitter,this.onAfterEdgeUpdated]=S(),[this.afterEdgePriorityUpdatedEmitter,this.onAfterEdgePriorityUpdated]=S(),[this.beforeEdgeRemovedEmitter,this.onBeforeEdgeRemoved]=S(),[this.beforeClearEmitter,this.onBeforeClear]=S()}addNode(e){const t=new Map,s={element:e.element,payload:{x:e.x,y:e.y,centerFn:e.centerFn,priority:e.priority},ports:t};this.nodes.set(e.id,s),this.nodesElementsMap.set(e.element,e.id),this.afterNodeAddedEmitter.emit(e.id)}getAllNodeIds(){return Array.from(this.nodes.keys())}getNode(e){return this.nodes.get(e)}getElementNodeId(e){return this.nodesElementsMap.get(e)}updateNode(e,t){const s=this.nodes.get(e).payload;s.x=t.x??s.x,s.y=t.y??s.y,s.centerFn=t.centerFn??s.centerFn,t.priority!==void 0&&(s.priority=t.priority,this.afterNodePriorityUpdatedEmitter.emit(e)),this.afterNodeUpdatedEmitter.emit(e)}removeNode(e){this.beforeNodeRemovedEmitter.emit(e);const t=this.nodes.get(e);this.nodesElementsMap.delete(t.element),this.nodes.delete(e)}addPort(e){this.ports.set(e.id,{element:e.element,payload:{direction:e.direction},nodeId:e.nodeId}),this.elementPorts.addRecord(e.element,e.id),this.portCycleEdges.set(e.id,new Set),this.portIncomingEdges.set(e.id,new Set),this.portOutcomingEdges.set(e.id,new Set),this.nodes.get(e.nodeId).ports.set(e.id,e.element),this.afterPortAddedEmitter.emit(e.id)}getPort(e){return this.ports.get(e)}updatePort(e,t){const s=this.ports.get(e).payload;s.direction=t.direction??s.direction,this.afterPortUpdatedEmitter.emit(e)}getAllPortIds(){return Array.from(this.ports.keys())}getElementPortIds(e){return this.elementPorts.getMultiBySingle(e)}getNodePortIds(e){const t=this.nodes.get(e);if(t!==void 0)return Array.from(t.ports.keys())}removePort(e){const t=this.ports.get(e).nodeId;this.beforePortRemovedEmitter.emit(e),this.nodes.get(t).ports.delete(e),this.ports.delete(e),this.elementPorts.removeByMulti(e)}addEdge(e){this.addEdgeInternal(e),this.afterEdgeAddedEmitter.emit(e.id)}updateEdge(e,t){if(t.from!==void 0||t.to!==void 0){const i=this.edges.get(e),n=i.payload;this.removeEdgeInternal(e),this.addEdgeInternal({id:e,from:t.from??i.from,to:t.to??i.to,shape:n.shape,priority:n.priority})}const s=this.edges.get(e);t.shape!==void 0&&(s.payload.shape=t.shape,this.afterEdgeShapeUpdatedEmitter.emit(e)),t.priority!==void 0&&(s.payload.priority=t.priority,this.afterEdgePriorityUpdatedEmitter.emit(e)),this.afterEdgeUpdatedEmitter.emit(e)}getAllEdgeIds(){return Array.from(this.edges.keys())}getEdge(e){return this.edges.get(e)}removeEdge(e){this.beforeEdgeRemovedEmitter.emit(e),this.removeEdgeInternal(e)}clear(){this.beforeClearEmitter.emit(),this.portIncomingEdges.clear(),this.portOutcomingEdges.clear(),this.portCycleEdges.clear(),this.elementPorts.clear(),this.nodesElementsMap.clear(),this.edges.clear(),this.ports.clear(),this.nodes.clear()}getPortIncomingEdgeIds(e){return Array.from(this.portIncomingEdges.get(e))}getPortOutgoingEdgeIds(e){return Array.from(this.portOutcomingEdges.get(e))}getPortCycleEdgeIds(e){return Array.from(this.portCycleEdges.get(e))}getPortAdjacentEdgeIds(e){return[...this.getPortIncomingEdgeIds(e),...this.getPortOutgoingEdgeIds(e),...this.getPortCycleEdgeIds(e)]}getNodeIncomingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(i=>{this.getPortIncomingEdgeIds(i).filter(n=>{const a=this.getEdge(n);return this.getPort(a.from).nodeId!==e}).forEach(n=>{s.push(n)})}),s}getNodeOutgoingEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(i=>{this.getPortOutgoingEdgeIds(i).filter(n=>{const a=this.getEdge(n);return this.getPort(a.to).nodeId!==e}).forEach(n=>{s.push(n)})}),s}getNodeCycleEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(i=>{this.getPortCycleEdgeIds(i).forEach(n=>{s.push(n)}),this.getPortIncomingEdgeIds(i).filter(n=>{const a=this.getEdge(n);return this.getPort(a.to).nodeId===e}).forEach(n=>{s.push(n)})}),s}getNodeAdjacentEdgeIds(e){const t=Array.from(this.nodes.get(e).ports.keys()),s=[];return t.forEach(i=>{this.getPortIncomingEdgeIds(i).forEach(n=>{s.push(n)}),this.getPortOutgoingEdgeIds(i).forEach(n=>{s.push(n)}),this.getPortCycleEdgeIds(i).forEach(n=>{s.push(n)})}),s}addEdgeInternal(e){this.edges.set(e.id,{from:e.from,to:e.to,payload:{shape:e.shape,priority:e.priority}}),e.from!==e.to?(this.portOutcomingEdges.get(e.from).add(e.id),this.portIncomingEdges.get(e.to).add(e.id)):this.portCycleEdges.get(e.from).add(e.id)}removeEdgeInternal(e){const t=this.edges.get(e),s=t.from,i=t.to;this.portCycleEdges.get(s).delete(e),this.portCycleEdges.get(i).delete(e),this.portIncomingEdges.get(s).delete(e),this.portIncomingEdges.get(i).delete(e),this.portOutcomingEdges.get(s).delete(e),this.portOutcomingEdges.get(i).delete(e),this.edges.delete(e)}}const ge=r=>({scale:1/r.scale,x:-r.x/r.scale,y:-r.y/r.scale}),ue={scale:1,x:0,y:0};class qe{constructor(){o(this,"viewportMatrix",ue);o(this,"contentMatrix",ue);o(this,"afterUpdateEmitter");o(this,"onAfterUpdated");[this.afterUpdateEmitter,this.onAfterUpdated]=S()}getViewportMatrix(){return this.viewportMatrix}getContentMatrix(){return this.contentMatrix}patchViewportMatrix(e){this.viewportMatrix={scale:e.scale??this.viewportMatrix.scale,x:e.x??this.viewportMatrix.x,y:e.y??this.viewportMatrix.y},this.contentMatrix=ge(this.viewportMatrix),this.afterUpdateEmitter.emit()}patchContentMatrix(e){this.contentMatrix={scale:e.scale??this.contentMatrix.scale,x:e.x??this.contentMatrix.x,y:e.y??this.contentMatrix.y},this.viewportMatrix=ge(this.contentMatrix),this.afterUpdateEmitter.emit()}}class G{constructor(e){o(this,"elementToNodeId",new Map);o(this,"nodesResizeObserver");o(this,"onAfterNodeAdded",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.set(t.element,e),this.nodesResizeObserver.observe(t.element)});o(this,"onBeforeNodeRemoved",e=>{const t=this.canvas.graph.getNode(e);this.elementToNodeId.delete(t.element),this.nodesResizeObserver.unobserve(t.element)});o(this,"onBeforeClear",()=>{this.nodesResizeObserver.disconnect(),this.elementToNodeId.clear()});this.canvas=e,this.nodesResizeObserver=new ResizeObserver(t=>{t.forEach(s=>{const i=s.target;this.handleNodeResize(i)})}),this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear)}static configure(e){new G(e)}handleNodeResize(e){const t=this.elementToNodeId.get(e);this.canvas.updateNode(t)}}const _e=(r,e,t)=>{const{x:s,y:i,width:n,height:a}=r.getBoundingClientRect();return e>=s&&e<=s+n&&t>=i&&t<=i+a},et=(r,e,t)=>e>=0&&e<=r.innerWidth&&t>=0&&t<=r.innerHeight,$=(r,e,t,s)=>_e(e,t,s)&&et(r,t,s),F=(r,e)=>{e!==null?r.style.cursor=e:r.style.removeProperty("cursor")},O=r=>{const e=document.createElement("div");return{id:r.overlayId,element:e,x:r.portCoords.x,y:r.portCoords.y,ports:[{id:r.overlayId,element:e,direction:r.portDirection}]}},tt=(r,e)=>{let t=e;for(;t!==null;){const s=r.getElementPortIds(t)[0]??null;if(s!==null)return{status:"portFound",portId:s};if(r.getElementNodeId(t)!==null)return{status:"nodeEncountered"};t=t.parentElement}return{status:"notFound"}};function*pe(r,e){const t=r.elementsFromPoint(e.x,e.y);for(const s of t){if(s.shadowRoot!==null){const i=pe(s.shadowRoot,e);for(const n of i)yield n}yield s}}const we=(r,e)=>{const t=pe(document,e);for(const s of t){const i=tt(r,s);if(i.status==="portFound")return i.portId;if(i.status==="nodeEncountered")return null}return null};var M=(r=>(r.Static="static",r.Dragging="dragging",r.Edge="edge",r))(M||{});const fe=(r,e)=>({x:r/2,y:e/2}),u={x:0,y:0},y=(r,e,t)=>({x:e.x*r.x-e.y*r.y+((1-e.x)*t.x+e.y*t.y),y:e.y*r.x+e.x*r.y+((1-e.x)*t.y-e.y*t.x)}),me=(r,e)=>{const t={x:r.x+r.width/2,y:r.y+r.height/2},s={x:e.x+e.width/2,y:e.y+e.height/2},i=Math.min(t.x,s.x),n=Math.min(t.y,s.y),a=Math.abs(s.x-t.x),h=Math.abs(s.y-t.y),d=t.x<=s.x?1:-1,c=t.y<=s.y?1:-1;return{x:i,y:n,width:a,height:h,flipX:d,flipY:c}},W=(r,e,t,s)=>({x:e*r.x+(1-e)/2*s.x,y:t*r.y+(1-t)/2*s.y});class rt{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u),i=y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to),n={x:s.x+this.params.sourceDirection.x*this.params.curvature,y:s.y+this.params.sourceDirection.y*this.params.curvature},a={x:i.x-this.params.targetDirection.x*this.params.curvature,y:i.y-this.params.targetDirection.y*this.params.curvature},h=`M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`,d=this.params.hasSourceArrow?"":`M ${u.x} ${u.y} L ${s.x} ${s.y} `,c=this.params.hasTargetArrow?"":` M ${i.x} ${i.y} L ${this.params.to.x} ${this.params.to.y}`;this.path=`${d}${h}${c}`}}class st{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength,n=Math.cos(this.params.detourDirection)*this.params.detourDistance,a=Math.sin(this.params.detourDirection)*this.params.detourDistance,h=n*this.params.flipX,d=a*this.params.flipY,c=y({x:i,y:u.y},this.params.sourceDirection,u),g={x:c.x+h,y:c.y+d},l=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),p={x:l.x+h,y:l.y+d},w={x:(g.x+p.x)/2,y:(g.y+p.y)/2},m={x:c.x+this.params.curvature*this.params.sourceDirection.x,y:c.y+this.params.curvature*this.params.sourceDirection.y},v={x:l.x-this.params.curvature*this.params.targetDirection.x,y:l.y-this.params.curvature*this.params.targetDirection.y},x={x:c.x+h,y:c.y+d},b={x:l.x+h,y:l.y+d};this.path=[`M ${t.x} ${t.y}`,`L ${c.x} ${c.y}`,`C ${m.x} ${m.y} ${x.x} ${x.y} ${w.x} ${w.y}`,`C ${b.x} ${b.y} ${v.x} ${v.y} ${l.x} ${l.y}`,`L ${s.x} ${s.y}`].join(" "),this.midpoint=W(w,e.flipX,e.flipY,e.to)}}const K=Object.freeze({edgeColor:"--edge-color"}),ye=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.style.pointerEvents="none",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.overflow="visible",e.style.setProperty(K.edgeColor,r),e},ve=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke",`var(${K.edgeColor})`),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e},k=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("fill",`var(${K.edgeColor})`),r},Ee=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.transformOrigin="50% 50%",r},Ae=(r,e)=>{r.style.transform=`translate(${e.x}px, ${e.y}px)`,r.style.width=`${Math.max(e.width,1)}px`,r.style.height=`${Math.max(e.height,1)}px`},C=(r,e)=>{const t=[];if(r.length>0&&t.push(`M ${r[0].x} ${r[0].y}`),r.length===2&&t.push(`L ${r[1].x} ${r[1].y}`),r.length>2){const s=r.length-1;let i=0,n=0,a=0;r.forEach((h,d)=>{let c=0,g=0,l=0;const p=d>0,w=d<s,m=p&&w;if(p&&(c=-i,g=-n,l=a),w){const U=r[d+1];i=U.x-h.x,n=U.y-h.y,a=Math.sqrt(i*i+n*n)}const x=a!==0?Math.min((m?e:0)/a,d<s-1?.5:1):0,b=m?{x:h.x+i*x,y:h.y+n*x}:h,D=l!==0?Math.min((m?e:0)/l,d>1?.5:1):0,R=m?{x:h.x+c*D,y:h.y+g*D}:h;d>0&&t.push(`L ${R.x} ${R.y}`),m&&t.push(`C ${h.x} ${h.y} ${h.x} ${h.y} ${b.x} ${b.y}`)})}return t.join(" ")};class ot{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=y({x:a,y:u.y},this.params.sourceDirection,u),d=y({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.x+d.x)/2,n),g=this.params.to.y/2,l={x:this.params.flipX>0?c:-n,y:h.y},p={x:l.x,y:g},w={x:this.params.flipX>0?this.params.to.x-c:this.params.to.x+n,y:d.y},m={x:w.x,y:g};this.path=C([s,h,l,p,m,w,d,i],this.params.roundness)}}class it{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=Math.cos(this.params.detourDirection)*this.params.detourDistance,h=Math.sin(this.params.detourDirection)*this.params.detourDistance,d=a*this.params.flipX,c=h*this.params.flipY,g={x:n.x+d,y:n.y+c},l=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),p={x:l.x+d,y:l.y+c},w={x:(g.x+p.x)/2,y:(g.y+p.y)/2};this.midpoint=W(w,e.flipX,e.flipY,e.to),this.path=C([t,n,g,p,l,s],this.params.roundness)}}class nt{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=y({x:n,y:u.y},this.params.sourceDirection,u),h=y({x:this.params.to.x-n,y:this.params.to.y},this.params.targetDirection,this.params.to);this.path=C([s,a,h,i],this.params.roundness)}}class at{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.to;this.midpoint={x:t.x/2,y:t.y/2};const s=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,i=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,n=this.params.arrowLength+this.params.arrowOffset,a=n-this.params.roundness,h=y({x:a,y:u.y},this.params.sourceDirection,u),d=y({x:this.params.to.x-a,y:this.params.to.y},this.params.targetDirection,this.params.to),c=Math.max((h.y+d.y)/2,n),g=this.params.to.x/2,l={x:h.x,y:this.params.flipY>0?c:-n},p={x:g,y:l.y},w={x:d.x,y:this.params.flipY>0?this.params.to.y-c:this.params.to.y+n},m={x:g,y:w.y};this.path=C([s,h,l,p,m,w,d,i],this.params.roundness)}}class Z{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.arrowOffset,s=this.params.side,i=this.params.arrowLength+t,n=i+2*s,h=[{x:this.params.arrowLength,y:u.y},{x:i,y:u.y},{x:i,y:this.params.side},{x:n,y:this.params.side},{x:n,y:-this.params.side},{x:i,y:-this.params.side},{x:i,y:u.y},{x:this.params.arrowLength,y:u.y}].map(c=>y(c,this.params.sourceDirection,u)),d=`M ${u.x} ${u.y} L ${h[0].x} ${h[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":d}${C(h,this.params.roundness)}`,this.midpoint={x:(h[3].x+h[4].x)/2,y:(h[3].y+h[4].y)/2}}}class ht{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.smallRadius,s=this.params.radius,i=t+s,n=t*s/i,a=Math.sqrt(i*i-t*t),h=a*t/i,d=a+s+this.params.arrowLength,c=this.params.arrowLength+h,l=[{x:this.params.arrowLength,y:u.y},{x:c,y:n},{x:c,y:-n},{x:d,y:0}].map(m=>y(m,this.params.sourceDirection,u)),p=[`M ${l[0].x} ${l[0].y}`,`A ${t} ${t} 0 0 1 ${l[1].x} ${l[1].y}`,`A ${s} ${s} 0 1 0 ${l[2].x} ${l[2].y}`,`A ${t} ${t} 0 0 1 ${l[0].x} ${l[0].y}`].join(" "),w=`M 0 0 L ${l[0].x} ${l[0].y} `;this.path=`${this.params.hasSourceArrow||this.params.hasTargetArrow?"":w}${p}`,this.midpoint=l[3]}}class dt{constructor(e){o(this,"path");o(this,"midpoint");o(this,"diagonalDistance");this.params=e;const t=this.params.to;if(this.midpoint={x:t.x/2,y:t.y/2},this.diagonalDistance=Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y),Math.sqrt(this.params.to.x*this.params.to.x+this.params.to.y*this.params.to.y)===0){this.path="";return}const i=this.createDirectLinePoint({offset:this.params.sourceOffset,hasArrow:this.params.hasSourceArrow,flip:1,shift:u}),n=this.createDirectLinePoint({offset:this.params.targetOffset,hasArrow:this.params.hasTargetArrow,flip:-1,shift:this.params.to});this.path=`M ${i.x} ${i.y} L ${n.x} ${n.y}`}createDirectLinePoint(e){const t=e.hasArrow?this.params.arrowLength:0,s=e.offset+t,i=e.flip*s/this.diagonalDistance;return{x:this.params.to.x*i+e.shift.x,y:this.params.to.y*i+e.shift.y}}}class ct{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.y/2,c=d+Math.abs(this.params.detourDistance),g=d+c*this.params.flipY*h,l={x:(n.x+a.x)/2,y:g};this.midpoint=W(l,e.flipX,e.flipY,e.to),this.path=C([t,n,{x:n.x,y:g},{x:a.x,y:g},a,s],this.params.roundness)}}class lt{constructor(e){o(this,"path");o(this,"midpoint");this.params=e;const t=this.params.hasSourceArrow?y({x:this.params.arrowLength,y:u.y},this.params.sourceDirection,u):u,s=this.params.hasTargetArrow?y({x:this.params.to.x-this.params.arrowLength,y:this.params.to.y},this.params.targetDirection,this.params.to):this.params.to,i=this.params.arrowLength+this.params.arrowOffset,n=y({x:i,y:u.y},this.params.sourceDirection,u),a=y({x:this.params.to.x-i,y:this.params.to.y},this.params.targetDirection,this.params.to),h=this.params.detourDistance>0?1:-1,d=this.params.to.x/2,c=d+Math.abs(this.params.detourDistance),g=d+c*this.params.flipX*h,l={x:g,y:(n.y+a.y)/2};this.midpoint=W(l,e.flipX,e.flipY,e.to),this.path=C([t,n,{x:g,y:n.y},{x:g,y:a.y},a,s],this.params.roundness)}}const f=Object.freeze({color:"#777777",width:1,arrowLength:20,polygonArrowRadius:4,circleArrowRadius:8,wedgeArrowSmallRadius:20,wedgeArrowRadius:100,wedgeArrowAngle:Math.PI/12,arrowOffset:15,hasSourceArrow:!1,hasTargetArrow:!1,cycleRadius:30,cycleSquareSide:30,roundness:10,detourDistance:100,detourDirection:-Math.PI/2,detourDirectionVertical:0,smallCycleRadius:15,curvature:90,interactiveWidth:10,preOffset:0}),xe=(r,e,t)=>({x:e*Math.cos(r),y:t*Math.sin(r)});class z{constructor(e){o(this,"svg");o(this,"group",Ee());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"onAfterRender");o(this,"afterRenderEmitter");o(this,"arrowRenderer");this.params=e,[this.afterRenderEmitter,this.onAfterRender]=S(),this.arrowRenderer=this.params.arrowRenderer,this.svg=ye(e.color),this.svg.appendChild(this.group),this.line=ve(e.width),this.group.appendChild(this.line),e.hasSourceArrow&&(this.sourceArrow=k(),this.group.appendChild(this.sourceArrow)),e.hasTargetArrow&&(this.targetArrow=k(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:a,flipY:h}=me(e.from,e.to);Ae(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d=xe(e.from.direction,a,h),c=xe(e.to.direction,a,h),g={x:i,y:n};let l={x:-c.x,y:-c.y},p;e.category===N.PortCycle?(p=this.params.createCyclePath,l=d):e.category===N.NodeCycle?p=this.params.createDetourPath:p=this.params.createLinePath;const w=p(d,c,g,a,h);this.line.setAttribute("d",w.path);let m=null;this.sourceArrow&&(m=this.arrowRenderer({direction:d,shift:u,arrowLength:this.params.arrowLength}),this.sourceArrow.setAttribute("d",m));let v=null;this.targetArrow&&(v=this.arrowRenderer({direction:l,shift:g,arrowLength:this.params.arrowLength}),this.targetArrow.setAttribute("d",v)),this.afterRenderEmitter.emit({edgePath:w,sourceArrowPath:m,targetArrowPath:v})}}const gt=r=>e=>{const s=[u,{x:e.arrowLength,y:r.radius},{x:e.arrowLength,y:-r.radius}].map(h=>y(h,e.direction,u)).map(h=>({x:h.x+e.shift.x,y:h.y+e.shift.y})),i=`M ${s[0].x} ${s[0].y}`,n=`L ${s[1].x} ${s[1].y}`,a=`L ${s[2].x} ${s[2].y}`;return`${i} ${n} ${a} Z`},ut=r=>e=>{const t=r.radius,s=e.arrowLength,i=(s*s+2*s*t)/(2*t),n=i+t,a=s+t-t*(s+t)/n,h=t*i/n,c=[u,{x:a,y:-h},{x:a,y:h}].map(m=>y(m,e.direction,u)).map(m=>({x:m.x+e.shift.x,y:m.y+e.shift.y})),g=`M ${c[0].x} ${c[0].y}`,l=`A ${i} ${i} 0 0 0 ${c[1].x} ${c[1].y}`,p=`A ${t} ${t} 0 0 0 ${c[2].x} ${c[2].y}`,w=`A ${i} ${i} 0 0 0 ${c[0].x} ${c[0].y}`;return`${g} ${l} ${p} ${w}`},pt=r=>e=>{const t=r.smallRadius,s=r.radius,i=y({x:e.arrowLength,y:0},{x:Math.cos(r.angle),y:Math.sin(r.angle)},{x:e.arrowLength+r.smallRadius,y:0}),a=[u,{x:i.x,y:-i.y},i].map(l=>y(l,e.direction,u)).map(l=>({x:l.x+e.shift.x,y:l.y+e.shift.y})),h=`M ${a[0].x} ${a[0].y}`,d=`A ${s} ${s} 0 0 1 ${a[1].x} ${a[1].y}`,c=`A ${t} ${t} 0 0 1 ${a[2].x} ${a[2].y}`,g=`A ${s} ${s} 0 0 1 ${a[0].x} ${a[0].y}`;return`${h} ${d} ${c} ${g}`},I=r=>{if(typeof r=="function")return r;switch(r.type){case"triangle":return gt({radius:r.radius??f.polygonArrowRadius});case"arc":return ut({radius:r.radius??f.circleArrowRadius});default:return pt({smallRadius:r.smallRadius??f.wedgeArrowSmallRadius,angle:r.angle??f.wedgeArrowAngle,radius:r.radius??f.wedgeArrowRadius})}};class Se{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"curvature");o(this,"portCycleRadius");o(this,"portCycleSmallRadius");o(this,"detourDirection");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new ht({sourceDirection:e,radius:this.portCycleRadius,smallRadius:this.portCycleSmallRadius,arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new st({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,detourDirection:this.detourDirection,detourDistance:this.detourDistance,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s)=>new rt({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,curvature:this.curvature,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.curvature=(e==null?void 0:e.curvature)??f.curvature,this.portCycleRadius=(e==null?void 0:e.cycleRadius)??f.cycleRadius,this.portCycleSmallRadius=(e==null?void 0:e.smallCycleRadius)??f.smallCycleRadius,this.detourDirection=(e==null?void 0:e.detourDirection)??f.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Pe{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new Z({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new ct({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s,i)=>new ot({to:s,sourceDirection:e,targetDirection:t,flipX:i,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class be{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDirection");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new Z({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new it({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDirection:this.detourDirection,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s)=>new nt({to:s,sourceDirection:e,targetDirection:t,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDirection=(e==null?void 0:e.detourDirection)??f.detourDirection,this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class Te{constructor(e){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"arrowLength");o(this,"arrowOffset");o(this,"roundness");o(this,"cycleSquareSide");o(this,"detourDistance");o(this,"hasSourceArrow");o(this,"hasTargetArrow");o(this,"pathShape");o(this,"createCyclePath",e=>new Z({sourceDirection:e,arrowLength:this.arrowLength,side:this.cycleSquareSide,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createDetourPath",(e,t,s,i,n)=>new lt({to:s,sourceDirection:e,targetDirection:t,flipX:i,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,detourDistance:this.detourDistance,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));o(this,"createLinePath",(e,t,s,i,n)=>new at({to:s,sourceDirection:e,targetDirection:t,flipY:n,arrowLength:this.arrowLength,arrowOffset:this.arrowOffset,roundness:this.roundness,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow}));this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowOffset=(e==null?void 0:e.arrowOffset)??f.arrowOffset,this.cycleSquareSide=(e==null?void 0:e.cycleSquareSide)??f.cycleSquareSide;const t=(e==null?void 0:e.roundness)??f.roundness;this.roundness=Math.min(t,this.arrowOffset,this.cycleSquareSide/2),this.detourDistance=(e==null?void 0:e.detourDistance)??f.detourDistance,this.hasSourceArrow=(e==null?void 0:e.hasSourceArrow)??f.hasSourceArrow,this.hasTargetArrow=(e==null?void 0:e.hasTargetArrow)??f.hasTargetArrow,this.pathShape=new z({color:(e==null?void 0:e.color)??f.color,width:(e==null?void 0:e.width)??f.width,arrowRenderer:I((e==null?void 0:e.arrowRenderer)??{}),arrowLength:this.arrowLength,hasSourceArrow:this.hasSourceArrow,hasTargetArrow:this.hasTargetArrow,createCyclePath:this.createCyclePath,createDetourPath:this.createDetourPath,createLinePath:this.createLinePath}),this.svg=this.pathShape.svg,this.group=this.pathShape.group,this.line=this.pathShape.line,this.sourceArrow=this.pathShape.sourceArrow,this.targetArrow=this.pathShape.targetArrow,this.onAfterRender=this.pathShape.onAfterRender}render(e){this.pathShape.render(e)}}class J{constructor(e){o(this,"svg");o(this,"group",Ee());o(this,"line");o(this,"sourceArrow",null);o(this,"targetArrow",null);o(this,"color");o(this,"width");o(this,"arrowLength");o(this,"sourceOffset");o(this,"targetOffset");o(this,"onAfterRender");o(this,"afterRenderEmitter");o(this,"arrowRenderer");[this.afterRenderEmitter,this.onAfterRender]=S(),this.color=(e==null?void 0:e.color)??f.color,this.width=(e==null?void 0:e.width)??f.width,this.arrowLength=(e==null?void 0:e.arrowLength)??f.arrowLength,this.arrowRenderer=I((e==null?void 0:e.arrowRenderer)??{}),this.sourceOffset=(e==null?void 0:e.sourceOffset)??f.preOffset,this.targetOffset=(e==null?void 0:e.targetOffset)??f.preOffset,this.svg=ye(this.color),this.svg.appendChild(this.group),this.line=ve(this.width),this.group.appendChild(this.line),e!=null&&e.hasSourceArrow&&(this.sourceArrow=k(),this.group.appendChild(this.sourceArrow)),e!=null&&e.hasTargetArrow&&(this.targetArrow=k(),this.group.appendChild(this.targetArrow))}render(e){const{x:t,y:s,width:i,height:n,flipX:a,flipY:h}=me(e.from,e.to);Ae(this.svg,{x:t,y:s,width:i,height:n}),this.group.style.transform=`scale(${a}, ${h})`;const d={x:i,y:n},c=new dt({to:d,sourceOffset:this.sourceOffset,targetOffset:this.targetOffset,hasSourceArrow:this.sourceArrow!==null,hasTargetArrow:this.targetArrow!==null,arrowLength:this.arrowLength});this.line.setAttribute("d",c.path);let g=null,l=null;const p=c.diagonalDistance;if(p===0)this.sourceArrow!==null&&(g="",this.sourceArrow.setAttribute("d",g)),this.targetArrow!==null&&(l="",this.targetArrow.setAttribute("d",l));else{const w={x:d.x/p,y:d.y/p};if(this.sourceArrow){const m={x:w.x*this.sourceOffset,y:w.y*this.sourceOffset};g=this.arrowRenderer({direction:w,shift:m,arrowLength:this.arrowLength}),this.sourceArrow.setAttribute("d",g)}if(this.targetArrow){const m={x:w.x*this.targetOffset,y:w.y*this.targetOffset};l=this.arrowRenderer({direction:{x:-w.x,y:-w.y},shift:{x:d.x-m.x,y:d.y-m.y},arrowLength:this.arrowLength}),this.targetArrow.setAttribute("d",l)}}this.afterRenderEmitter.emit({edgePath:c,sourceArrowPath:g,targetArrowPath:l})}}const wt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","g");return r.style.pointerEvents="auto",r.style.cursor="pointer",r},ft=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke","transparent"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","none"),e.setAttribute("stroke-linecap","round"),e},De=r=>{const e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("stroke-linejoin","round"),e.setAttribute("stroke-width",`${r}`),e.setAttribute("fill","transparent"),e.setAttribute("stroke","transparent"),e};class Ne extends Error{constructor(e){super(e),this.name="InteractiveEdgeError"}}class Q{constructor(e,t){o(this,"svg");o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"handle",wt());o(this,"onAfterRender");o(this,"interactiveLine");o(this,"interactiveSourceArrow",null);o(this,"interactiveTargetArrow",null);if(this.baseEdge=e,e instanceof Q)throw new Ne("interactive edge can be configured only once");this.svg=this.baseEdge.svg,this.group=this.baseEdge.group,this.line=this.baseEdge.line,this.sourceArrow=this.baseEdge.sourceArrow,this.targetArrow=this.baseEdge.targetArrow,this.onAfterRender=this.baseEdge.onAfterRender;const s=(t==null?void 0:t.distance)??f.interactiveWidth;this.interactiveLine=ft(s),this.handle.appendChild(this.interactiveLine),this.sourceArrow&&(this.interactiveSourceArrow=De(s),this.handle.appendChild(this.interactiveSourceArrow)),this.targetArrow&&(this.interactiveTargetArrow=De(s),this.handle.appendChild(this.interactiveTargetArrow)),this.group.appendChild(this.handle),this.baseEdge.onAfterRender.subscribe(i=>{this.interactiveLine.setAttribute("d",i.edgePath.path),this.interactiveSourceArrow&&this.interactiveSourceArrow.setAttribute("d",i.sourceArrowPath),this.interactiveTargetArrow&&this.interactiveTargetArrow.setAttribute("d",i.targetArrowPath)})}render(e){this.baseEdge.render(e)}}class mt{constructor(e,t){o(this,"group");o(this,"line");o(this,"sourceArrow");o(this,"targetArrow");o(this,"onAfterRender");o(this,"svg");this.baseShape=e,this.midpointElement=t,this.svg=this.baseShape.svg,this.group=this.baseShape.group,this.line=this.baseShape.line,this.sourceArrow=this.baseShape.sourceArrow,this.targetArrow=this.baseShape.targetArrow,this.onAfterRender=this.baseShape.onAfterRender,this.svg.append(this.midpointElement),this.baseShape.onAfterRender.subscribe(s=>{const i=s.edgePath.midpoint,n=`translate(${i.x}px, ${i.y}px)`;this.midpointElement.style.setProperty("transform",n)})}render(e){this.baseShape.render(e)}}class Me{constructor(e){o(this,"onAfterNodeAdded");o(this,"onAfterNodeUpdated");o(this,"onAfterNodePriorityUpdated");o(this,"onBeforeNodeRemoved");o(this,"onAfterPortMarked");o(this,"onAfterPortUpdated");o(this,"onBeforePortUnmarked");o(this,"onAfterEdgeAdded");o(this,"onAfterEdgeShapeUpdated");o(this,"onAfterEdgeUpdated");o(this,"onAfterEdgePriorityUpdated");o(this,"onBeforeEdgeRemoved");o(this,"onBeforeClear");this.graphStore=e,this.onAfterNodeAdded=this.graphStore.onAfterNodeAdded,this.onAfterNodeUpdated=this.graphStore.onAfterNodeUpdated,this.onAfterNodePriorityUpdated=this.graphStore.onAfterNodePriorityUpdated,this.onBeforeNodeRemoved=this.graphStore.onBeforeNodeRemoved,this.onAfterPortMarked=this.graphStore.onAfterPortAdded,this.onAfterPortUpdated=this.graphStore.onAfterPortUpdated,this.onBeforePortUnmarked=this.graphStore.onBeforePortRemoved,this.onAfterEdgeAdded=this.graphStore.onAfterEdgeAdded,this.onAfterEdgeShapeUpdated=this.graphStore.onAfterEdgeShapeUpdated,this.onAfterEdgeUpdated=this.graphStore.onAfterEdgeUpdated,this.onAfterEdgePriorityUpdated=this.graphStore.onAfterEdgePriorityUpdated,this.onBeforeEdgeRemoved=this.graphStore.onBeforeEdgeRemoved,this.onBeforeClear=this.graphStore.onBeforeClear}getNode(e){const t=this.graphStore.getNode(e);if(t===void 0)return null;const s=t.payload;return{element:t.element,x:s.x,y:s.y,centerFn:s.centerFn,priority:s.priority}}getElementNodeId(e){return this.graphStore.getElementNodeId(e)??null}getAllNodeIds(){return this.graphStore.getAllNodeIds()}getPort(e){const t=this.graphStore.getPort(e);return t===void 0?null:{element:t.element,direction:t.payload.direction,nodeId:t.nodeId}}getAllPortIds(){return this.graphStore.getAllPortIds()}getNodePortIds(e){return this.graphStore.getNodePortIds(e)??null}getElementPortIds(e){return[...this.graphStore.getElementPortIds(e)]}getAllEdgeIds(){return this.graphStore.getAllEdgeIds()}getEdge(e){const t=this.graphStore.getEdge(e);if(t===void 0)return null;const s=t.payload;return{from:t.from,to:t.to,priority:s.priority,shape:s.shape}}getPortIncomingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortIncomingEdgeIds(e)}getPortOutgoingEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortOutgoingEdgeIds(e)}getPortCycleEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortCycleEdgeIds(e)}getPortAdjacentEdgeIds(e){return this.graphStore.getPort(e)===void 0?null:this.graphStore.getPortAdjacentEdgeIds(e)}getNodeIncomingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeIncomingEdgeIds(e)}getNodeOutgoingEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeOutgoingEdgeIds(e)}getNodeCycleEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeCycleEdgeIds(e)}getNodeAdjacentEdgeIds(e){return this.graphStore.getNode(e)===void 0?null:this.graphStore.getNodeAdjacentEdgeIds(e)}}class Le{constructor(e){o(this,"onAfterUpdated");this.viewportStore=e,this.onAfterUpdated=this.viewportStore.onAfterUpdated}getViewportMatrix(){return{...this.viewportStore.getViewportMatrix()}}getContentMatrix(){return{...this.viewportStore.getContentMatrix()}}}const Ce=(r,e)=>{const t=new le,s=new Me(t),i=new Le(e),n=new de(t,e,r),a={nodes:{centerFn:fe,priorityFn:()=>0},edges:{shapeFactory:()=>new J,priorityFn:()=>0},ports:{direction:0}};return new ce(s,i,t,e,n,a)};class H{constructor(e,t,s,i){o(this,"onAfterPortMarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.hookPortEvents(t.element)});o(this,"onBeforePortUnmarked",e=>{const t=this.canvas.graph.getPort(e);this.canvas.graph.getElementPortIds(t.element).length===1&&this.unhookPortEvents(t.element)});o(this,"onPortMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.canvas.graph.getElementPortIds(t)[0];this.params.onPortPointerDown(s,{x:e.clientX,y:e.clientY})&&(e.stopPropagation(),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}))});o(this,"onWindowMouseMove",e=>{if(!$(this.window,this.element,e.clientX,e.clientY)){this.stopMouseDrag();return}this.params.onPointerMove({x:e.clientX,y:e.clientY})});o(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&(this.params.onPointerUp({x:e.clientX,y:e.clientY}),this.stopMouseDrag())});o(this,"onPortTouchStart",e=>{if(e.touches.length!==1)return;const t=e.touches[0],s=e.currentTarget,i=this.canvas.graph.getElementPortIds(s)[0];this.params.onPortPointerDown(i,{x:t.clientX,y:t.clientY})&&(e.stopPropagation(),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}))});o(this,"onWindowTouchMove",e=>{const t=e.touches[0];if(!$(this.window,this.element,t.clientX,t.clientY)){this.stopTouchDrag();return}this.params.onPointerMove({x:t.clientX,y:t.clientY})});o(this,"onWindowTouchFinish",e=>{const t=e.changedTouches[0];this.params.onPointerUp({x:t.clientX,y:t.clientY}),this.stopTouchDrag()});o(this,"onBeforeClear",()=>{this.canvas.graph.getAllPortIds().forEach(e=>{const t=this.canvas.graph.getPort(e);this.unhookPortEvents(t.element)})});o(this,"onBeforeDestroy",()=>{this.params.onStopDrag(),this.removeWindowMouseListeners(),this.removeWindowTouchListeners()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.canvas.graph.onAfterPortMarked.subscribe(this.onAfterPortMarked),this.canvas.graph.onBeforePortUnmarked.subscribe(this.onBeforePortUnmarked),this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new H(e,t,s,i)}hookPortEvents(e){e.addEventListener("mousedown",this.onPortMouseDown,{passive:!0}),e.addEventListener("touchstart",this.onPortTouchStart,{passive:!0})}unhookPortEvents(e){e.removeEventListener("mousedown",this.onPortMouseDown),e.removeEventListener("touchstart",this.onPortTouchStart)}stopMouseDrag(){this.params.onStopDrag(),this.removeWindowMouseListeners()}stopTouchDrag(){this.params.onStopDrag(),this.removeWindowTouchListeners()}removeWindowMouseListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}removeWindowTouchListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}}class q{constructor(e,t,s,i){o(this,"grabbedNode",null);o(this,"maxNodePriority",0);o(this,"graph");o(this,"onAfterNodeAdded",e=>{this.updateMaxNodePriority(e);const t=this.graph.getNode(e);t.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),t.element.addEventListener("touchstart",this.onTouchStart,{passive:!0})});o(this,"onAfterNodeUpdated",e=>{this.updateMaxNodePriority(e)});o(this,"onBeforeNodeRemoved",e=>{const t=this.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)});o(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});o(this,"onBeforeClear",()=>{this.canvas.graph.getAllNodeIds().forEach(e=>{const t=this.canvas.graph.getNode(e);t.element.removeEventListener("mousedown",this.onMouseDown),t.element.removeEventListener("touchstart",this.onTouchStart)}),this.maxNodePriority=0});o(this,"onMouseDown",e=>{if(!this.params.mouseDownEventVerifier(e))return;const t=e.currentTarget,s=this.graph.getElementNodeId(t),i=this.graph.getNode(s);if(!this.params.nodeDragVerifier(s))return;this.params.onNodeDragStarted(s),e.stopPropagation();const a=this.calculateContentPoint({x:e.clientX,y:e.clientY});this.grabbedNode={nodeId:s,dx:a.x-i.x,dy:a.y-i.y},F(this.element,this.params.dragCursor),this.moveNodeOnTop(s),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0})});o(this,"onTouchStart",e=>{if(e.touches.length!==1)return;e.stopPropagation();const t=e.touches[0],s=e.currentTarget,i=this.canvas.graph.getElementNodeId(s),n=this.graph.getNode(i);if(!this.params.nodeDragVerifier({nodeId:i,element:n.element,x:n.x,y:n.y}))return;const h=this.calculateContentPoint({x:t.clientX,y:t.clientY});this.grabbedNode={nodeId:i,dx:h.x-n.x,dy:h.y-n.y},this.moveNodeOnTop(i),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0})});o(this,"onWindowMouseMove",e=>{if(!$(this.window,this.element,e.clientX,e.clientY)){this.cancelMouseDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:e.clientX,y:e.clientY})});o(this,"onWindowMouseUp",e=>{this.params.mouseUpEventVerifier(e)&&this.cancelMouseDrag()});o(this,"onWindowTouchMove",e=>{if(e.touches.length!==1)return;const t=e.touches[0];if(!$(this.window,this.element,t.clientX,t.clientY)){this.cancelTouchDrag();return}this.grabbedNode!==null&&this.moveNode(this.grabbedNode,{x:t.clientX,y:t.clientY})});o(this,"onWindowTouchFinish",()=>{this.cancelTouchDrag()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.graph=e.graph,this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded),this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated),this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved),this.graph.onBeforeClear.subscribe(this.onBeforeClear),this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new q(e,t,s,i)}moveNode(e,t){if(this.graph.getNode(e.nodeId)===null)return;const i=this.calculateContentPoint(t),n={x:i.x-e.dx,y:i.y-e.dy},a=this.adjustNodeCoords(n);this.canvas.updateNode(e.nodeId,{x:a.x,y:a.y}),this.params.onNodeDrag(e.nodeId)}moveNodeOnTop(e){if(this.params.moveOnTop){if(this.maxNodePriority++,this.params.moveEdgesOnTop){const t=this.maxNodePriority;this.maxNodePriority++,this.graph.getNodeAdjacentEdgeIds(e).forEach(i=>{this.canvas.updateEdge(i,{priority:t})})}this.canvas.updateNode(e,{priority:this.maxNodePriority})}}cancelMouseDrag(){this.grabbedNode!==null&&this.graph.getNode(this.grabbedNode.nodeId)!==null&&this.params.onNodeDragFinished(this.grabbedNode.nodeId),this.grabbedNode=null,F(this.element,null),this.removeMouseDragListeners()}removeMouseDragListeners(){this.window.removeEventListener("mouseup",this.onWindowMouseUp),this.window.removeEventListener("mousemove",this.onWindowMouseMove)}cancelTouchDrag(){if(this.grabbedNode!==null){const e=this.graph.getNode(this.grabbedNode.nodeId);e!==null&&this.params.onNodeDragFinished({nodeId:this.grabbedNode.nodeId,element:e.element,x:e.x,y:e.y})}this.grabbedNode=null,this.removeTouchDragListeners()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}updateMaxNodePriority(e){const t=this.graph.getNode(e).priority;this.maxNodePriority=Math.max(this.maxNodePriority,t)}calculateContentPoint(e){const t=this.element.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix();return A(i,s)}adjustNodeCoords(e){const t=this.params.gridSize;if(t!==null){const s=t/2;return{x:Math.floor((e.x+s)/t)*t,y:Math.floor((e.y+s)/t)*t}}return e}}const yt=(r,e,t)=>({scale:r.scale,x:r.x+r.scale*e,y:r.y+r.scale*t}),vt=(r,e,t,s)=>({scale:r.scale*e,x:r.scale*(1-e)*t+r.x,y:r.scale*(1-e)*s+r.y}),X=r=>{const e=[],t=r.touches.length;for(let h=0;h<t;h++)e.push([r.touches[h].clientX,r.touches[h].clientY]);const s=e.reduce((h,d)=>[h[0]+d[0],h[1]+d[1]],[0,0]),i=[s[0]/t,s[1]/t],a=e.map(h=>[h[0]-i[0],h[1]-i[1]]).reduce((h,d)=>h+Math.sqrt(d[0]*d[0]+d[1]*d[1]),0);return{x:i[0],y:i[1],scale:a/t,touchesCnt:t,touches:e}};class Y{constructor(e,t,s,i){o(this,"viewport");o(this,"prevTouches",null);o(this,"wheelFinishTimer",null);o(this,"transformInProgress",!1);o(this,"onBeforeDestroy",()=>{this.removeMouseDragListeners(),this.removeTouchDragListeners()});o(this,"onMouseDown",e=>{this.element===null||!this.params.mouseDownEventVerifier(e)||(F(this.element,this.params.shiftCursor),this.window.addEventListener("mousemove",this.onWindowMouseMove,{passive:!0}),this.window.addEventListener("mouseup",this.onWindowMouseUp,{passive:!0}),this.startRegisteredTransform())});o(this,"onWindowMouseMove",e=>{const t=$(this.window,this.element,e.clientX,e.clientY);if(this.element===null||!t){this.stopMouseDrag();return}const s=-e.movementX,i=-e.movementY;this.moveViewport(s,i)});o(this,"onWindowMouseUp",e=>{this.element===null||!this.params.mouseUpEventVerifier(e)||this.stopMouseDrag()});o(this,"onWheelScroll",e=>{if(!this.params.mouseWheelEventVerifier(e))return;const{left:t,top:s}=this.element.getBoundingClientRect(),i=e.clientX-t,n=e.clientY-s,h=1/(e.deltaY<0?this.params.wheelSensitivity:1/this.params.wheelSensitivity);this.wheelFinishTimer===null&&this.params.onTransformStarted(),this.scaleViewport(h,i,n),this.wheelFinishTimer!==null&&clearTimeout(this.wheelFinishTimer),this.wheelFinishTimer=setTimeout(()=>{this.transformInProgress||this.params.onTransformFinished(),this.wheelFinishTimer=null},this.params.scaleWheelFinishTimeout)});o(this,"onTouchStart",e=>{if(this.prevTouches!==null){this.prevTouches=X(e);return}this.prevTouches=X(e),this.window.addEventListener("touchmove",this.onWindowTouchMove,{passive:!0}),this.window.addEventListener("touchend",this.onWindowTouchFinish,{passive:!0}),this.window.addEventListener("touchcancel",this.onWindowTouchFinish,{passive:!0}),this.startRegisteredTransform()});o(this,"onWindowTouchMove",e=>{const t=X(e);if(!t.touches.every(i=>$(this.window,this.element,i[0],i[1]))){this.stopTouchDrag();return}if((t.touchesCnt===1||t.touchesCnt===2)&&this.moveViewport(-(t.x-this.prevTouches.x),-(t.y-this.prevTouches.y)),t.touchesCnt===2){const{left:i,top:n}=this.element.getBoundingClientRect(),a=this.prevTouches.x-i,h=this.prevTouches.y-n,c=1/(t.scale/this.prevTouches.scale);this.scaleViewport(c,a,h)}this.prevTouches=t});o(this,"onWindowTouchFinish",e=>{e.touches.length>0?this.prevTouches=X(e):this.stopTouchDrag()});o(this,"observer",new ResizeObserver(()=>{const e=this.viewport.getViewportMatrix(),{width:t,height:s}=this.element.getBoundingClientRect(),i=this.params.transformPreprocessor({prevTransform:e,nextTransform:e,canvasWidth:t,canvasHeight:s});this.params.onResizeTransformStarted(),this.canvas.patchViewportMatrix(i),this.params.onResizeTransformFinished()}));o(this,"preventWheelScaleListener",e=>{e.preventDefault()});this.canvas=e,this.element=t,this.window=s,this.params=i,this.element.addEventListener("wheel",this.preventWheelScaleListener,{passive:!1}),this.viewport=e.viewport,this.observer.observe(this.element),this.element.addEventListener("mousedown",this.onMouseDown,{passive:!0}),this.element.addEventListener("wheel",this.onWheelScroll,{passive:!0}),this.element.addEventListener("touchstart",this.onTouchStart,{passive:!0}),e.onBeforeDestroy.subscribe(this.onBeforeDestroy)}static configure(e,t,s,i){new Y(e,t,s,i)}moveViewport(e,t){const s=this.viewport.getViewportMatrix(),i=yt(s,e,t),{width:n,height:a}=this.element.getBoundingClientRect(),h=this.params.transformPreprocessor({prevTransform:s,nextTransform:i,canvasWidth:n,canvasHeight:a});this.performTransform(h)}scaleViewport(e,t,s){const i=this.canvas.viewport.getViewportMatrix(),n=vt(i,e,t,s),{width:a,height:h}=this.element.getBoundingClientRect(),d=this.params.transformPreprocessor({prevTransform:i,nextTransform:n,canvasWidth:a,canvasHeight:h});this.performTransform(d)}stopMouseDrag(){F(this.element,null),this.removeMouseDragListeners(),this.finishRegisteredTransform()}removeMouseDragListeners(){this.window.removeEventListener("mousemove",this.onWindowMouseMove),this.window.removeEventListener("mouseup",this.onWindowMouseUp)}stopTouchDrag(){this.prevTouches=null,this.removeTouchDragListeners(),this.finishRegisteredTransform()}removeTouchDragListeners(){this.window.removeEventListener("touchmove",this.onWindowTouchMove),this.window.removeEventListener("touchend",this.onWindowTouchFinish),this.window.removeEventListener("touchcancel",this.onWindowTouchFinish)}performTransform(e){this.params.onBeforeTransformChange(),this.canvas.patchViewportMatrix(e),this.params.onTransformChange()}startRegisteredTransform(){this.transformInProgress=!0,this.params.onTransformStarted()}finishRegisteredTransform(){this.transformInProgress=!1,this.params.onTransformFinished()}}class _{constructor(e,t,s,i,n,a){o(this,"canvasResizeObserver");o(this,"nodeHorizontal");o(this,"nodeVertical");o(this,"viewport");o(this,"viewportWidth",0);o(this,"viewportHeight",0);o(this,"viewportMatrix");o(this,"loadedArea",{xFrom:1/0,xTo:1/0,yFrom:1/0,yTo:1/0});o(this,"updateLoadedArea",e=>{this.loadedArea={xFrom:e.x,xTo:e.x+e.width,yFrom:e.y,yTo:e.y+e.height}});o(this,"onAfterViewportUpdated",()=>{this.userTransformInProgress||(this.viewportMatrix=this.viewport.getViewportMatrix(),this.loadAreaAroundViewport())});o(this,"userTransformInProgress",!1);this.canvas=e,this.element=t,this.window=s,this.trigger=n,this.params=a,this.nodeHorizontal=this.params.nodeVerticalRadius,this.nodeVertical=this.params.nodeHorizontalRadius,this.canvasResizeObserver=new ResizeObserver(d=>{const c=d[0];this.viewportWidth=c.contentRect.width,this.viewportHeight=c.contentRect.height,this.scheduleLoadAreaAroundViewport()}),this.viewport=e.viewport;const h={...i,onResizeTransformStarted:()=>{this.userTransformInProgress=!0,i.onResizeTransformStarted()},onResizeTransformFinished:()=>{this.userTransformInProgress=!1,i.onResizeTransformFinished()},onBeforeTransformChange:()=>{this.userTransformInProgress=!0,i.onBeforeTransformChange()},onTransformChange:()=>{this.userTransformInProgress=!1;const d=this.viewportMatrix;this.viewportMatrix=this.viewport.getViewportMatrix(),d.scale!==this.viewportMatrix.scale&&this.scheduleEnsureViewportAreaLoaded(),i.onTransformChange()},onTransformFinished:()=>{this.scheduleLoadAreaAroundViewport(),i.onTransformFinished()}};Y.configure(e,this.element,this.window,h),this.viewportMatrix=this.viewport.getViewportMatrix(),this.trigger.subscribe(this.updateLoadedArea),this.canvasResizeObserver.observe(this.element),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated)}static configure(e,t,s,i,n,a){new _(e,t,s,i,n,a)}scheduleLoadAreaAroundViewport(){setTimeout(()=>{this.loadAreaAroundViewport()})}scheduleEnsureViewportAreaLoaded(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-this.nodeHorizontal,i=this.viewportMatrix.y-this.nodeVertical,n=this.viewportMatrix.x+e+this.nodeHorizontal,a=this.viewportMatrix.y+t+this.nodeVertical;this.loadedArea.xFrom<s&&this.loadedArea.xTo>n&&this.loadedArea.yFrom<i&&this.loadedArea.yTo>a||this.scheduleLoadAreaAroundViewport()}loadAreaAroundViewport(){const e=this.viewportWidth*this.viewportMatrix.scale,t=this.viewportHeight*this.viewportMatrix.scale,s=this.viewportMatrix.x-e-this.nodeHorizontal,i=this.viewportMatrix.y-t-this.nodeVertical,n=3*e+2*this.nodeHorizontal,a=3*t+2*this.nodeVertical;this.trigger.emit({x:s,y:i,width:n,height:a})}}const Et=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","svg");return r.style.position="absolute",r.style.inset="0",r},At=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","rect");return r.setAttribute("fill","url(#pattern)"),r},xt=()=>{const r=document.createElementNS("http://www.w3.org/2000/svg","pattern");return r.setAttribute("id","pattern"),r};class ee{constructor(e,t,s){o(this,"svg",Et());o(this,"patternRenderingRectangle",At());o(this,"pattern",xt());o(this,"patternContent");o(this,"tileWidth");o(this,"tileHeight");o(this,"halfTileWidth");o(this,"halfTileHeight");o(this,"maxViewportScale");o(this,"visible",!1);o(this,"resizeObserver",new ResizeObserver(e=>{const t=e[0],{width:s,height:i}=t.contentRect;this.svg.setAttribute("width",`${s}`),this.svg.setAttribute("height",`${i}`),this.patternRenderingRectangle.setAttribute("width",`${s}`),this.patternRenderingRectangle.setAttribute("height",`${i}`);const n=this.tileWidth/s,a=this.tileHeight/i;this.pattern.setAttribute("width",`${n}`),this.pattern.setAttribute("height",`${a}`)}));o(this,"onAfterTransformUpdated",()=>{const e=this.canvas.viewport.getContentMatrix(),t=e.x-this.halfTileWidth*e.scale,s=e.y-this.halfTileHeight*e.scale,i=`matrix(${e.scale}, 0, 0, ${e.scale}, ${t}, ${s})`;this.pattern.setAttribute("patternTransform",i),this.updateVisibility()});this.canvas=e,this.backgroundHost=s,this.tileWidth=t.tileWidth,this.tileHeight=t.tileHeight,this.halfTileWidth=this.tileWidth/2,this.halfTileHeight=this.tileHeight/2,this.patternContent=t.renderer,this.maxViewportScale=t.maxViewportScale;const i=`translate(${this.halfTileWidth}, ${this.halfTileHeight})`;this.patternContent.setAttribute("transform",i),this.pattern.appendChild(this.patternContent);const n=document.createElementNS("http://www.w3.org/2000/svg","defs");n.appendChild(this.pattern),this.svg.appendChild(n),this.svg.appendChild(this.patternRenderingRectangle),this.resizeObserver.observe(this.backgroundHost),this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated),this.onAfterTransformUpdated()}static configure(e,t,s){new ee(e,t,s)}updateVisibility(){const t=this.canvas.viewport.getViewportMatrix().scale>this.maxViewportScale;t&&this.visible?(this.visible=!1,this.backgroundHost.removeChild(this.svg)):!t&&!this.visible&&(this.visible=!0,this.backgroundHost.appendChild(this.svg))}}class te{constructor(e,t,s,i,n){o(this,"overlayCanvas");o(this,"staticPortId",null);o(this,"isTargetDragging",!0);o(this,"onEdgeCreated",e=>{this.params.onAfterEdgeCreated(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=i,this.params=n,this.overlayCanvas=Ce(this.overlayLayer,this.viewportStore),H.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>{const d=this.params.connectionTypeResolver(a);return d===null?!1:(this.grabPort(a,h,d),!0)},onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,i,n){new te(e,t,s,i,n)}grabPort(e,t,s){const i=this.canvas.graph.getPort(e);this.staticPortId=e;const n=i.element.getBoundingClientRect(),a=n.x+n.width/2,h=n.y+n.height/2,d=this.overlayLayer.getBoundingClientRect(),c=this.canvas.viewport.getViewportMatrix(),g=A(c,{x:a-d.x,y:h-d.y}),l=A(c,{x:t.x-d.x,y:t.y-d.y}),p={overlayId:M.Static,portCoords:g,portDirection:i.direction},w={overlayId:M.Dragging,portCoords:l,portDirection:this.params.dragPortDirection};this.isTargetDragging=s==="direct";const[m,v]=this.isTargetDragging?[p,w]:[w,p];this.overlayCanvas.addNode(O(m)),this.overlayCanvas.addNode(O(v)),this.overlayCanvas.addEdge({from:m.overlayId,to:v.overlayId,shape:this.params.edgeShapeFactory(M.Edge)})}resetDragState(){this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}tryCreateConnection(e){const t=we(this.canvas.graph,e),s=this.staticPortId;if(t===null){this.params.onEdgeCreationInterrupted({staticPortId:s,isDirect:this.isTargetDragging});return}const i=this.isTargetDragging?s:t,n=this.isTargetDragging?t:s,a={from:i,to:n},h=this.params.connectionPreprocessor(a);h!==null?(this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)):this.params.onEdgeCreationPrevented(a)}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix(),n=A(i,s);this.overlayCanvas.updateNode(M.Dragging,{x:n.x,y:n.y})}}class re{constructor(e,t,s,i,n){o(this,"overlayCanvas");o(this,"staticPortId",null);o(this,"isTargetDragging",!0);o(this,"draggingEdgePayload",null);o(this,"onEdgeReattached",e=>{this.params.onAfterEdgeReattached(e)});this.canvas=e,this.overlayLayer=t,this.viewportStore=s,this.window=i,this.params=n,this.overlayCanvas=Ce(this.overlayLayer,this.viewportStore),H.configure(this.canvas,this.overlayLayer,this.window,{mouseDownEventVerifier:this.params.mouseDownEventVerifier,mouseUpEventVerifier:this.params.mouseUpEventVerifier,onStopDrag:()=>{this.resetDragState()},onPortPointerDown:(a,h)=>this.tryStartEdgeDragging(a,h),onPointerMove:a=>{this.moveDraggingPort(a)},onPointerUp:a=>{this.tryCreateConnection(a)}})}static configure(e,t,s,i,n){new re(e,t,s,i,n)}tryStartEdgeDragging(e,t){const s=this.params.draggingEdgeResolver(e);if(s===null)return!1;const i=this.canvas.graph.getEdge(s);if(i===null)return!1;const n=e===i.from,a=e===i.to,h=n?i.to:i.from;this.staticPortId=h,this.isTargetDragging=a;const d=this.canvas.graph.getPort(e),c=this.canvas.graph.getPort(h),g=c.element.getBoundingClientRect(),l={x:g.x+g.width/2,y:g.y+g.height/2},p=this.canvas.viewport.getViewportMatrix(),w=this.overlayLayer.getBoundingClientRect(),m=A(p,{x:l.x-w.x,y:l.y-w.y}),v=A(p,{x:t.x-w.x,y:t.y-w.y});this.draggingEdgePayload={id:s,from:i.from,to:i.to,shape:i.shape,priority:i.priority},this.canvas.removeEdge(s);const x={overlayId:M.Static,portCoords:m,portDirection:c.direction},b={overlayId:M.Dragging,portCoords:v,portDirection:d.direction},[L,D]=this.isTargetDragging?[x,b]:[b,x];this.overlayCanvas.addNode(O(L)),this.overlayCanvas.addNode(O(D));const R=this.params.draggingEdgeShapeFactory!==null?this.params.draggingEdgeShapeFactory(M.Edge):i.shape;return this.overlayCanvas.addEdge({id:M.Edge,from:L.overlayId,to:D.overlayId,shape:R}),!0}resetDragState(){this.draggingEdgePayload=null,this.staticPortId=null,this.isTargetDragging=!0,this.overlayCanvas.clear()}moveDraggingPort(e){const t=this.overlayLayer.getBoundingClientRect(),s={x:e.x-t.x,y:e.y-t.y},i=this.canvas.viewport.getViewportMatrix(),n=A(i,s);this.overlayCanvas.updateNode(M.Dragging,{x:n.x,y:n.y})}tryCreateConnection(e){const t=we(this.canvas.graph,e);if(this.overlayCanvas.removeEdge(M.Edge),t===null){const d=this.draggingEdgePayload;this.params.onEdgeReattachInterrupted({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority});return}const[s,i]=this.isTargetDragging?[this.staticPortId,t]:[t,this.staticPortId],n=this.draggingEdgePayload,a={id:n.id,from:s,to:i,shape:n.shape,priority:n.priority},h=this.params.connectionPreprocessor(a);if(h!==null)this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached),this.canvas.addEdge(h),this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeReattached);else{const d=this.draggingEdgePayload;this.params.onEdgeReattachPrevented({id:d.id,from:d.from,to:d.to,shape:d.shape,priority:d.priority})}}}class se{constructor(e,t,s){this.canvas=e,this.layoutAlgorithm=t,this.trigger=s,this.trigger.subscribe(()=>{this.applyLayout()})}static configure(e,t,s){new se(e,t,s)}applyLayout(){this.layoutAlgorithm.calculateCoordinates(this.canvas.graph).forEach((t,s)=>{this.canvas.updateNode(s,t)})}}class oe{constructor(e,t){o(this,"applyScheduled",!1);this.canvas=e,this.layoutAlgorithm=t,this.canvas.graph.onAfterNodeAdded.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onBeforeNodeRemoved.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onAfterEdgeAdded.subscribe(()=>{this.scheduleApply()}),this.canvas.graph.onBeforeEdgeRemoved.subscribe(()=>{this.scheduleApply()})}static configure(e,t){new oe(e,t)}scheduleApply(){this.applyScheduled||(this.applyScheduled=!0,setTimeout(()=>{this.applyScheduled=!1,this.applyLayout()}))}applyLayout(){this.layoutAlgorithm.calculateCoordinates(this.canvas.graph).forEach((t,s)=>{this.canvas.updateNode(s,t)})}}class St{static configure(e,t){const s=t.applyOn;switch(s.type){case"manual":{se.configure(e,t.algorithm,s.trigger);break}case"topologyChangeTimeout":{oe.configure(e,t.algorithm);break}}}}class Pt{constructor(e,t){o(this,"previousTimeStamp");o(this,"step",e=>{if(this.previousTimeStamp===void 0)this.previousTimeStamp=e;else{const t=(e-this.previousTimeStamp)/1e3;this.previousTimeStamp=e,this.callback(t)}this.win.requestAnimationFrame(this.step)});this.win=e,this.callback=t,this.win.requestAnimationFrame(this.step)}}class ie{constructor(e,t,s,i){o(this,"step",e=>{this.algorithm.calculateNextCoordinates(this.canvas.graph,e).forEach((s,i)=>{this.staticNodes.has(i)||this.canvas.updateNode(i,{x:s.x,y:s.y})})});this.canvas=e,this.algorithm=t,this.staticNodes=s,this.win=i,new Pt(this.win,this.step)}static configure(e,t,s,i){new ie(e,t,s,i)}}const bt=()=>{const r=document.createElement("div");return r.style.width="100%",r.style.height="100%",r.style.position="relative",r},ne=()=>{const r=document.createElement("div");return r.style.position="absolute",r.style.inset="0",r},Re=()=>{const r=ne();return r.style.pointerEvents="none",r};class Tt{constructor(e){o(this,"background",ne());o(this,"main",ne());o(this,"overlayConnectablePorts",Re());o(this,"overlayDraggableEdges",Re());o(this,"host",bt());this.element=e,this.element.appendChild(this.host),this.host.appendChild(this.background),this.host.appendChild(this.main),this.host.appendChild(this.overlayConnectablePorts),this.host.appendChild(this.overlayDraggableEdges)}destroy(){this.host.removeChild(this.background),this.host.removeChild(this.main),this.host.removeChild(this.overlayConnectablePorts),this.host.removeChild(this.overlayDraggableEdges),this.element.removeChild(this.host)}}const ae=r=>()=>r,Ve=ae(0),Dt=()=>{let r=0;return()=>r++},Nt=(r,e)=>{let t=Ve,s=Ve;const i=Dt();return r==="incremental"&&(t=i),e==="incremental"&&(s=i),typeof r=="number"&&(t=ae(r)),typeof e=="number"&&(s=ae(e)),typeof r=="function"&&(t=r),typeof e=="function"&&(s=e),{nodesPriorityFn:t,edgesPriorityFn:s}},he=r=>{if(typeof r=="function")return r;switch(r.type){case"straight":return()=>new be({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance,detourDirection:r.detourDirection});case"horizontal":return()=>new Pe({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"vertical":return()=>new Te({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowOffset:r.arrowOffset,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleSquareSide:r.cycleSquareSide,roundness:r.roundness,detourDistance:r.detourDistance});case"direct":return()=>new J({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,sourceOffset:r.sourceOffset,targetOffset:r.targetOffset});default:return()=>new Se({color:r.color,width:r.width,arrowLength:r.arrowLength,arrowRenderer:r.arrowRenderer,hasSourceArrow:r.hasSourceArrow,hasTargetArrow:r.hasTargetArrow,cycleRadius:r.cycleRadius,smallCycleRadius:r.smallCycleRadius,curvature:r.curvature,detourDistance:r.detourDistance,detourDirection:r.detourDirection})}},Mt=r=>{var t,s,i,n,a;const e=Nt((t=r.nodes)==null?void 0:t.priority,(s=r.edges)==null?void 0:s.priority);return{nodes:{centerFn:((i=r.nodes)==null?void 0:i.centerFn)??fe,priorityFn:e.nodesPriorityFn},ports:{direction:((n=r.ports)==null?void 0:n.direction)??0},edges:{shapeFactory:he(((a=r.edges)==null?void 0:a.shape)??{}),priorityFn:e.edgesPriorityFn}}},Lt=r=>{var w,m,v,x,b,L;const e=((w=r.events)==null?void 0:w.onNodeDragStarted)??(()=>{}),t=((m=r.events)==null?void 0:m.onNodeDrag)??(()=>{}),s=r.nodeDragVerifier??(()=>!0),i=((v=r.events)==null?void 0:v.onNodeDragFinished)??(()=>{}),n=r.moveOnTop!==!1,a=r.moveEdgesOnTop!==!1&&n,h=(x=r.mouse)==null?void 0:x.dragCursor,d=h!==void 0?h:"grab",c=(b=r.mouse)==null?void 0:b.mouseDownEventVerifier,g=c!==void 0?c:D=>D.button===0,l=(L=r.mouse)==null?void 0:L.mouseUpEventVerifier,p=l!==void 0?l:D=>D.button===0;return{moveOnTop:n,moveEdgesOnTop:a,dragCursor:d,gridSize:r.gridSize??null,mouseDownEventVerifier:g,mouseUpEventVerifier:p,onNodeDragStarted:e,onNodeDrag:t,nodeDragVerifier:s,onNodeDragFinished:i}},Ct=r=>{const e=r.minX!==null?r.minX:-1/0,t=r.maxX!==null?r.maxX:1/0,s=r.minY!==null?r.minY:-1/0,i=r.maxY!==null?r.maxY:1/0;return n=>{let a=n.nextTransform.x,h=n.nextTransform.y;a<e&&a<n.prevTransform.x&&(a=Math.min(n.prevTransform.x,e));const d=n.canvasWidth*n.prevTransform.scale,c=t-d;a>c&&a>n.prevTransform.x&&(a=Math.max(n.prevTransform.x,c)),h<s&&h<n.prevTransform.y&&(h=Math.min(n.prevTransform.y,s));const g=n.canvasHeight*n.prevTransform.scale,l=i-g;return h>l&&h>n.prevTransform.y&&(h=Math.max(n.prevTransform.y,l)),{scale:n.nextTransform.scale,x:a,y:h}}},Rt=r=>{const e=r.maxContentScale,t=r.minContentScale,s=e!==null?1/e:0,i=t!==null?1/t:1/0;return n=>{const a=n.prevTransform,h=n.nextTransform;let d=h.scale,c=h.x,g=h.y;if(h.scale>i&&h.scale>a.scale){d=Math.max(a.scale,i),c=a.x,g=a.y;const l=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*l,g=a.y+(h.y-a.y)*l}if(h.scale<s&&h.scale<a.scale){d=Math.min(a.scale,s),c=a.x,g=a.y;const l=(d-a.scale)/(h.scale-a.scale);c=a.x+(h.x-a.x)*l,g=a.y+(h.y-a.y)*l}return{scale:d,x:c,y:g}}},Vt=r=>e=>r.reduce((t,s)=>s({prevTransform:e.prevTransform,nextTransform:t,canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight}),e.nextTransform),$e=r=>{if(typeof r=="function")return r;switch(r.type){case"scale-limit":return Rt({minContentScale:r.minContentScale??0,maxContentScale:r.maxContentScale??1/0});case"shift-limit":return Ct({minX:r.minX??-1/0,maxX:r.maxX??1/0,minY:r.minY??-1/0,maxY:r.maxY??1/0})}},Ie=r=>{var m,v,x,b,L,D,R,U,ke,ze,He,Xe;const e=(m=r==null?void 0:r.scale)==null?void 0:m.mouseWheelSensitivity,t=e!==void 0?e:1.2,s=r==null?void 0:r.transformPreprocessor;let i;s!==void 0?Array.isArray(s)?i=Vt(s.map(V=>$e(V))):i=$e(s):i=V=>V.nextTransform;const n=((v=r==null?void 0:r.shift)==null?void 0:v.cursor)!==void 0?r.shift.cursor:"grab",a=((x=r==null?void 0:r.events)==null?void 0:x.onBeforeTransformChange)??(()=>{}),h=((b=r==null?void 0:r.events)==null?void 0:b.onTransformChange)??(()=>{}),d=(L=r==null?void 0:r.shift)==null?void 0:L.mouseDownEventVerifier,c=d!==void 0?d:V=>V.button===0,g=(D=r==null?void 0:r.shift)==null?void 0:D.mouseUpEventVerifier,l=g!==void 0?g:V=>V.button===0,p=(R=r==null?void 0:r.scale)==null?void 0:R.mouseWheelEventVerifier,w=p!==void 0?p:()=>!0;return{wheelSensitivity:t,onTransformStarted:((U=r==null?void 0:r.events)==null?void 0:U.onTransformStarted)??(()=>{}),onTransformFinished:((ke=r==null?void 0:r.events)==null?void 0:ke.onTransformFinished)??(()=>{}),onBeforeTransformChange:a,onTransformChange:h,transformPreprocessor:i,shiftCursor:n,mouseDownEventVerifier:c,mouseUpEventVerifier:l,mouseWheelEventVerifier:w,scaleWheelFinishTimeout:((ze=r==null?void 0:r.scale)==null?void 0:ze.wheelFinishTimeout)??500,onResizeTransformStarted:((He=r==null?void 0:r.events)==null?void 0:He.onResizeTransformStarted)??(()=>{}),onResizeTransformFinished:((Xe=r==null?void 0:r.events)==null?void 0:Xe.onResizeTransformFinished)??(()=>{})}},$t=(r,e)=>{const t=document.createElementNS("http://www.w3.org/2000/svg","circle");return t.setAttribute("cx","0"),t.setAttribute("cy","0"),t.setAttribute("r",`${r}`),t.setAttribute("fill",`${e}`),t},It=r=>r instanceof SVGElement?r:$t((r==null?void 0:r.radius)??1.5,(r==null?void 0:r.color)??"#d8d8d8"),Ut=r=>{const e=r.tileDimensions,t=(e==null?void 0:e.width)??25,s=(e==null?void 0:e.height)??25,i=It(r.renderer??{});return{tileWidth:t,tileHeight:s,renderer:i,maxViewportScale:r.maxViewportScale??10}},Bt=(r,e,t)=>{var c,g,l;const s=()=>"direct",i=p=>p,n=p=>p.button===0,a=()=>{},h=()=>{},d=()=>{};return{connectionTypeResolver:r.connectionTypeResolver??s,connectionPreprocessor:r.connectionPreprocessor??i,mouseDownEventVerifier:r.mouseDownEventVerifier??n,mouseUpEventVerifier:r.mouseUpEventVerifier??n,onAfterEdgeCreated:((c=r.events)==null?void 0:c.onAfterEdgeCreated)??a,onEdgeCreationInterrupted:((g=r.events)==null?void 0:g.onEdgeCreationInterrupted)??d,onEdgeCreationPrevented:((l=r.events)==null?void 0:l.onEdgeCreationPrevented)??h,dragPortDirection:r.dragPortDirection??t,edgeShapeFactory:r.edgeShape!==void 0?he(r.edgeShape):e}},Ft=(r,e)=>{var c,g,l;const t=p=>p,s=p=>p.button===0&&p.ctrlKey,i=p=>p.button===0,n=p=>{const w=e.getPortAdjacentEdgeIds(p);return w.length>0?w[w.length-1]:null},a=()=>{},h=()=>{},d=()=>{};return{connectionPreprocessor:r.connectionPreprocessor??t,mouseDownEventVerifier:r.mouseDownEventVerifier??s,mouseUpEventVerifier:r.mouseUpEventVerifier??i,draggingEdgeResolver:r.draggingEdgeResolver??n,draggingEdgeShapeFactory:r.draggingEdgeShape!==void 0?he(r.draggingEdgeShape):null,onAfterEdgeReattached:((c=r.events)==null?void 0:c.onAfterEdgeReattached)??a,onEdgeReattachInterrupted:((g=r.events)==null?void 0:g.onEdgeReattachInterrupted)??d,onEdgeReattachPrevented:((l=r.events)==null?void 0:l.onEdgeReattachPrevented)??h}},Ot=r=>({nodeVerticalRadius:r.nodeContainingRadius.vertical,nodeHorizontalRadius:r.nodeContainingRadius.horizontal}),Wt=r=>{var e,t;return{onAfterNodeDetached:((e=r==null?void 0:r.events)==null?void 0:e.onAfterNodeDetached)??(()=>{}),onBeforeNodeAttached:((t=r==null?void 0:r.events)==null?void 0:t.onBeforeNodeAttached)??(()=>{})}};class Ue extends Error{constructor(){super(...arguments);o(this,"name","CanvasBuilderError")}}class kt{constructor(e,t){this.coordinates=e,this.rand=t}getVector(e,t){const s=this.coordinates.get(e),i=this.coordinates.get(t),n=i.x-s.x,a=i.y-s.y,h=n*n+a*a;if(h===0){const l=this.rand()*2*Math.PI;return{ex:Math.cos(l),ey:Math.sin(l),d2:1,d:1}}const d=Math.sqrt(h),c=n/d,g=a/d;return{ex:c,ey:g,d2:h,d}}}class Be{constructor(e,t,s){o(this,"dtSec");o(this,"k");o(this,"nodeMass");o(this,"edgeEquilibriumLength");o(this,"edgeStiffness");o(this,"effectiveDistance");this.graph=e,this.currentCoords=t,this.params=s,this.dtSec=this.params.dtSec,this.k=this.params.nodeCharge*this.params.nodeCharge,this.nodeMass=this.params.nodeMass,this.edgeEquilibriumLength=this.params.edgeEquilibriumLength,this.edgeStiffness=this.params.edgeStiffness,this.effectiveDistance=this.params.effectiveDistance}next(){let e=0;const t=new Map,s=this.graph.getAllNodeIds();s.forEach(a=>{t.set(a,{x:0,y:0})});const i=new kt(this.currentCoords,this.params.rand),n=s.length;for(let a=0;a<n;a++){const h=s[a];for(let d=a+1;d<n;d++){const c=s[d],g=i.getVector(h,c);if(g.d>this.effectiveDistance)continue;const l=this.k/g.d2,p=l*g.ex,w=l*g.ey,m=p/2,v=w/2,x=t.get(h),b=t.get(c);x.x-=m,x.y-=v,b.x+=m,b.y+=v}}return this.graph.getAllEdgeIds().forEach(a=>{const h=this.graph.getEdge(a),d=this.graph.getPort(h.from),c=this.graph.getPort(h.to),g=i.getVector(d.nodeId,c.nodeId),p=(g.d-this.edgeEquilibriumLength)*this.edgeStiffness/2,w=g.ex*p,m=g.ey*p,v=t.get(d.nodeId),x=t.get(c.nodeId);v.x+=w,v.y+=m,x.x-=w,x.y-=m}),this.currentCoords.forEach((a,h)=>{const d=t.get(h),c={x:d.x/this.nodeMass*this.dtSec,y:d.y/this.nodeMass*this.dtSec},g=c.x*this.dtSec,l=c.y*this.dtSec;a.x+=g,a.y+=l,e=Math.max(e,Math.sqrt(g*g+l*l))}),e}}const Fe=(r,e,t)=>{const s=new Map,i=r.getAllNodeIds(),n=Math.sqrt(i.length)*t;return i.forEach(a=>{const h=r.getNode(a);s.set(a,{x:h.x??n*e(),y:h.y??n*e()})}),s};class zt{constructor(e){this.params=e}calculateCoordinates(e){const t=Fe(e,this.params.rand,this.params.edgeEquilibriumLength);for(let s=0;s<this.params.maxIterations&&!(new Be(e,t,{rand:this.params.rand,dtSec:this.params.dtSec,nodeMass:this.params.nodeMass,nodeCharge:this.params.nodeCharge,edgeEquilibriumLength:this.params.edgeEquilibriumLength,effectiveDistance:this.params.effectiveDistance,edgeStiffness:this.params.edgeStiffness}).next()<this.params.convergenceDelta);s++);return t}}class Ht{constructor(e){this.params=e}calculateNextCoordinates(e,t){const s=Fe(e,this.params.rand,this.params.edgeEquilibriumLength);return new Be(e,s,{rand:this.params.rand,dtSec:Math.min(t,this.params.maxTimeDeltaSec),nodeMass:this.params.nodeMass,nodeCharge:this.params.nodeCharge,edgeEquilibriumLength:this.params.edgeEquilibriumLength,effectiveDistance:this.params.effectiveDistance,edgeStiffness:this.params.edgeStiffness}).next()<this.params.convergenceDelta&&!e.getAllNodeIds().some(h=>{const d=e.getNode(h);return d.x===null||d.y===null})?new Map:s}}const Oe=r=>{let e=1779033703,t=3144134277,s=1013904242,i=2773480762;for(let n=0,a;n<r.length;n++)a=r.charCodeAt(n),e=t^Math.imul(e^a,597399067),t=s^Math.imul(t^a,2869860233),s=i^Math.imul(s^a,951274213),i=e^Math.imul(i^a,2716044179);return e=Math.imul(s^e>>>18,597399067),t=Math.imul(i^t>>>22,2869860233),s=Math.imul(e^s>>>17,951274213),i=Math.imul(t^i>>>19,2716044179),e^=t^s^i,t^=e,s^=e,i^=e,[e>>>0,t>>>0,s>>>0,i>>>0]},We=(r,e,t,s)=>function(){r|=0,e|=0,t|=0,s|=0;const i=(r+e|0)+s|0;return s=s+1|0,r=e^e>>>9,e=t+(t<<3)|0,t=t<<21|t>>>11,t=t+i|0,(i>>>0)/4294967296},P=Object.freeze({seed:"HTMLGraph is awesome",maxTimeDeltaSec:.1,nodeCharge:1e5,nodeMass:1,edgeEquilibriumLength:300,edgeStiffness:1e3,effectiveDistance:1e3,dtSec:.02,maxIterations:100,convergenceDelta:.001}),Xt=r=>{var e;switch((e=r==null?void 0:r.algorithm)==null?void 0:e.type){case"custom":return r.algorithm.instance;default:{const t=r==null?void 0:r.algorithm,s=Oe((t==null?void 0:t.seed)??P.seed),i=We(s[0],s[1],s[2],s[3]);return new Ht({rand:i,maxTimeDeltaSec:(t==null?void 0:t.maxTimeDeltaSec)??P.maxTimeDeltaSec,nodeCharge:(t==null?void 0:t.nodeCharge)??P.nodeCharge,nodeMass:(t==null?void 0:t.nodeMass)??P.nodeMass,edgeEquilibriumLength:(t==null?void 0:t.edgeEquilibriumLength)??P.edgeEquilibriumLength,effectiveDistance:P.effectiveDistance,edgeStiffness:(t==null?void 0:t.edgeStiffness)??P.edgeStiffness,convergenceDelta:(t==null?void 0:t.convergenceDelta)??P.convergenceDelta})}}},Yt=r=>r instanceof B?{type:"manual",trigger:r}:{type:"topologyChangeTimeout"},jt=r=>{switch(r==null?void 0:r.type){case"custom":return r.instance;default:{const e=Oe((r==null?void 0:r.seed)??P.seed),t=We(e[0],e[1],e[2],e[3]);return new zt({dtSec:(r==null?void 0:r.dtSec)??P.dtSec,maxIterations:(r==null?void 0:r.maxIterations)??P.maxIterations,rand:t,nodeCharge:(r==null?void 0:r.nodeCharge)??P.nodeCharge,nodeMass:(r==null?void 0:r.nodeMass)??P.nodeMass,edgeEquilibriumLength:(r==null?void 0:r.edgeEquilibriumLength)??P.edgeEquilibriumLength,edgeStiffness:(r==null?void 0:r.edgeStiffness)??P.edgeStiffness,effectiveDistance:(r==null?void 0:r.effectiveDistance)??P.effectiveDistance,convergenceDelta:(r==null?void 0:r.convergenceDelta)??P.convergenceDelta})}}},Gt=r=>({algorithm:jt(r==null?void 0:r.algorithm),applyOn:Yt(r==null?void 0:r.applyOn)}),Kt=(r,e)=>({...r,onNodeDragStarted:t=>{e.add(t),r.onNodeDragStarted(t)},onNodeDragFinished:t=>{e.delete(t),r.onNodeDragFinished(t)}}),Zt=(r,e)=>{r.onBeforeNodeRemoved.subscribe(t=>{e.delete(t)}),r.onBeforeClear.subscribe(()=>{e.clear()})};class Jt{constructor(e){o(this,"used",!1);o(this,"canvasDefaults",{});o(this,"dragConfig",{});o(this,"transformConfig",{});o(this,"backgroundConfig",{});o(this,"connectablePortsConfig",{});o(this,"draggableEdgesConfig",{});o(this,"virtualScrollConfig");o(this,"layoutConfig",{});o(this,"animatedLayoutConfig",{});o(this,"hasDraggableNodes",!1);o(this,"hasTransformableViewport",!1);o(this,"hasNodeResizeReactiveEdges",!1);o(this,"hasBackground",!1);o(this,"hasUserConnectablePorts",!1);o(this,"hasUserDraggableEdges",!1);o(this,"hasAnimatedLayout",!1);o(this,"hasLayout",!1);o(this,"boxRenderingTrigger",new B);o(this,"graphStore",new le);o(this,"viewportStore",new qe);o(this,"graph",new Me(this.graphStore));o(this,"viewport",new Le(this.viewportStore));o(this,"window",window);o(this,"animationStaticNodes",new Set);this.element=e}setDefaults(e){return this.canvasDefaults=e,this}enableUserDraggableNodes(e){return this.hasDraggableNodes=!0,this.dragConfig=e??{},this}enableUserTransformableViewport(e){return this.hasTransformableViewport=!0,this.transformConfig=e??{},this}enableNodeResizeReactiveEdges(){return this.hasNodeResizeReactiveEdges=!0,this}enableVirtualScroll(e){return this.virtualScrollConfig=e,this}enableBackground(e){return this.hasBackground=!0,this.backgroundConfig=e??{},this}enableUserConnectablePorts(e){return this.hasUserConnectablePorts=!0,this.connectablePortsConfig=e??{},this}enableUserDraggableEdges(e){return this.hasUserDraggableEdges=!0,this.draggableEdgesConfig=e??{},this}enableLayout(e){return this.layoutConfig=e??{},this.hasLayout=!0,this.hasAnimatedLayout=!1,this}enableAnimatedLayout(e){return this.animatedLayoutConfig=e??{},this.hasAnimatedLayout=!0,this.hasLayout=!1,this}build(){if(this.used)throw new Ue("CanvasBuilder is a single use object");this.used=!0;const e=new Tt(this.element);let t=new de(this.graphStore,this.viewportStore,e.main);this.virtualScrollConfig!==void 0&&(t=new Ze(t,this.graphStore,this.boxRenderingTrigger,Wt(this.virtualScrollConfig))),t=new Je(t,this.graphStore);const s=Mt(this.canvasDefaults),i=new ce(this.graph,this.viewport,this.graphStore,this.viewportStore,t,s);if(this.hasBackground&&ee.configure(i,Ut(this.backgroundConfig),e.background),this.hasNodeResizeReactiveEdges&&G.configure(i),this.hasDraggableNodes){let a=Lt(this.dragConfig);this.hasAnimatedLayout&&(a=Kt(a,this.animationStaticNodes)),q.configure(i,e.main,this.window,a)}if(this.hasUserConnectablePorts){const a=Bt(this.connectablePortsConfig,s.edges.shapeFactory,s.ports.direction);te.configure(i,e.overlayConnectablePorts,this.viewportStore,this.window,a)}if(this.hasUserDraggableEdges){const a=Ft(this.draggableEdgesConfig,i.graph);re.configure(i,e.overlayDraggableEdges,this.viewportStore,this.window,a)}this.virtualScrollConfig!==void 0?_.configure(i,e.main,this.window,Ie(this.transformConfig),this.boxRenderingTrigger,Ot(this.virtualScrollConfig)):this.hasTransformableViewport&&Y.configure(i,e.main,this.window,Ie(this.transformConfig)),this.hasLayout&&St.configure(i,Gt(this.layoutConfig)),this.hasAnimatedLayout&&(Zt(i.graph,this.animationStaticNodes),ie.configure(i,Xt(this.animatedLayoutConfig),this.animationStaticNodes,this.window));const n=()=>{e.destroy(),i.onBeforeDestroy.unsubscribe(n)};return i.onBeforeDestroy.subscribe(n),i}}E.BezierEdgeShape=Se,E.CanvasBuilder=Jt,E.CanvasBuilderError=Ue,E.CanvasError=T,E.DirectEdgeShape=J,E.EventSubject=B,E.HorizontalEdgeShape=Pe,E.InteractiveEdgeError=Ne,E.InteractiveEdgeShape=Q,E.MidpointEdgeShape=mt,E.StraightEdgeShape=be,E.VerticalEdgeShape=Te,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@html-graph/html-graph",
3
3
  "author": "Dmitry Marov <d.marov94@gmail.com>",
4
4
  "private": false,
5
- "version": "7.1.1",
5
+ "version": "7.2.0",
6
6
  "type": "module",
7
7
  "main": "dist/html-graph.js",
8
8
  "types": "dist/html-graph.d.ts",