@html-graph/html-graph 0.0.61 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,266 +1,37 @@
1
- var _ = Object.defineProperty;
2
- var J = (r, e, t) => e in r ? _(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var n = (r, e, t) => J(r, typeof e != "symbol" ? e + "" : e, t);
4
- const Y = (r) => ({
5
- scale: 1 / r.scale,
6
- dx: -r.dx / r.scale,
7
- dy: -r.dy / r.scale
8
- }), X = {
9
- scale: 1,
10
- dx: 0,
11
- dy: 0
12
- };
13
- class Q {
14
- constructor() {
15
- n(this, "viewportMatrix", X);
16
- n(this, "contentMatrix", X);
17
- }
18
- getViewportMatrix() {
19
- return this.viewportMatrix;
20
- }
21
- getContentMatrix() {
22
- return this.contentMatrix;
23
- }
24
- patchViewportMatrix(e) {
25
- this.viewportMatrix = {
26
- scale: e.scale ?? this.viewportMatrix.scale,
27
- dx: e.dx ?? this.viewportMatrix.dx,
28
- dy: e.dy ?? this.viewportMatrix.dy
29
- }, this.contentMatrix = Y(this.viewportMatrix);
30
- }
31
- patchContentMatrix(e) {
32
- this.contentMatrix = {
33
- scale: e.scale ?? this.contentMatrix.scale,
34
- dx: e.dx ?? this.contentMatrix.dx,
35
- dy: e.dy ?? this.contentMatrix.dy
36
- }, this.viewportMatrix = Y(this.contentMatrix);
37
- }
38
- }
39
- class Z {
40
- constructor(e) {
41
- this.transformer = e;
42
- }
43
- getViewportMatrix() {
44
- return { ...this.transformer.getViewportMatrix() };
45
- }
46
- getContentMatrix() {
47
- return { ...this.transformer.getContentMatrix() };
48
- }
49
- }
50
- class q {
51
- constructor() {
52
- n(this, "nodes", /* @__PURE__ */ new Map());
53
- n(this, "ports", /* @__PURE__ */ new Map());
54
- n(this, "nodePorts", /* @__PURE__ */ new Map());
55
- n(this, "portNodeId", /* @__PURE__ */ new Map());
56
- n(this, "edges", /* @__PURE__ */ new Map());
57
- n(this, "incommingEdges", /* @__PURE__ */ new Map());
58
- n(this, "outcommingEdges", /* @__PURE__ */ new Map());
59
- n(this, "cycleEdges", /* @__PURE__ */ new Map());
60
- }
61
- addNode(e) {
62
- this.nodes.set(e.nodeId, {
63
- element: e.element,
64
- x: e.x,
65
- y: e.y,
66
- centerFn: e.centerFn,
67
- priority: e.priority
68
- }), this.nodePorts.set(e.nodeId, /* @__PURE__ */ new Map());
69
- }
70
- getAllNodeIds() {
71
- return Array.from(this.nodes.keys());
72
- }
73
- getNode(e) {
74
- return this.nodes.get(e);
75
- }
76
- removeNode(e) {
77
- this.nodes.delete(e), this.nodePorts.delete(e);
78
- }
79
- addPort(e) {
80
- this.ports.set(e.portId, {
81
- element: e.element,
82
- centerFn: e.centerFn,
83
- direction: e.direction
84
- }), this.cycleEdges.set(e.portId, /* @__PURE__ */ new Set()), this.incommingEdges.set(e.portId, /* @__PURE__ */ new Set()), this.outcommingEdges.set(e.portId, /* @__PURE__ */ new Set()), this.portNodeId.set(e.portId, e.nodeId), this.nodePorts.get(e.nodeId).set(e.portId, e.element);
85
- }
86
- getPort(e) {
87
- return this.ports.get(e);
88
- }
89
- getAllPortIds() {
90
- return Array.from(this.ports.keys());
91
- }
92
- getNodePortIds(e) {
93
- const t = this.nodePorts.get(e);
94
- if (t !== void 0)
95
- return Array.from(t.keys());
96
- }
97
- getPortNodeId(e) {
98
- return this.portNodeId.get(e);
99
- }
100
- removePort(e) {
101
- const t = this.portNodeId.get(e);
102
- this.portNodeId.delete(e), this.nodePorts.get(t).delete(e), this.ports.delete(e);
103
- }
104
- addEdge(e) {
105
- this.edges.set(e.edgeId, {
106
- from: e.from,
107
- to: e.to,
108
- shape: e.shape,
109
- priority: e.priority
110
- }), e.from !== e.to ? (this.outcommingEdges.get(e.from).add(e.edgeId), this.incommingEdges.get(e.to).add(e.edgeId)) : this.cycleEdges.get(e.from).add(e.edgeId);
111
- }
112
- getAllEdgeIds() {
113
- return Array.from(this.edges.keys());
114
- }
115
- getEdge(e) {
116
- return this.edges.get(e);
117
- }
118
- removeEdge(e) {
119
- const t = this.edges.get(e), s = t.from, o = t.to;
120
- this.cycleEdges.get(s).delete(e), this.cycleEdges.get(o).delete(e), this.incommingEdges.get(s).delete(e), this.incommingEdges.get(o).delete(e), this.outcommingEdges.get(s).delete(e), this.outcommingEdges.get(o).delete(e), this.edges.delete(e);
121
- }
122
- clear() {
123
- this.nodes.clear(), this.ports.clear(), this.nodePorts.clear(), this.portNodeId.clear(), this.edges.clear(), this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear();
124
- }
125
- getPortIncomingEdgeIds(e) {
126
- return Array.from(this.incommingEdges.get(e));
127
- }
128
- getPortOutcomingEdgeIds(e) {
129
- return Array.from(this.outcommingEdges.get(e));
130
- }
131
- getPortCycleEdgeIds(e) {
132
- return Array.from(this.cycleEdges.get(e));
133
- }
134
- getPortAdjacentEdgeIds(e) {
135
- return [
136
- ...this.getPortIncomingEdgeIds(e),
137
- ...this.getPortOutcomingEdgeIds(e),
138
- ...this.getPortCycleEdgeIds(e)
139
- ];
140
- }
141
- getNodeIncomingEdgeIds(e) {
142
- const t = Array.from(this.nodePorts.get(e).keys());
143
- let s = [];
144
- return t.forEach((o) => {
145
- s = [...s, ...this.getPortIncomingEdgeIds(o)];
146
- }), s;
147
- }
148
- getNodeOutcomingEdgeIds(e) {
149
- const t = Array.from(this.nodePorts.get(e).keys());
150
- let s = [];
151
- return t.forEach((o) => {
152
- s = [...s, ...this.getPortOutcomingEdgeIds(o)];
153
- }), s;
154
- }
155
- getNodeCycleEdgeIds(e) {
156
- const t = Array.from(this.nodePorts.get(e).keys());
157
- let s = [];
158
- return t.forEach((o) => {
159
- s = [...s, ...this.getPortCycleEdgeIds(o)];
160
- }), s;
161
- }
162
- getNodeAdjacentEdgeIds(e) {
163
- return [
164
- ...this.getNodeIncomingEdgeIds(e),
165
- ...this.getNodeOutcomingEdgeIds(e),
166
- ...this.getNodeCycleEdgeIds(e)
167
- ];
168
- }
169
- }
170
- class ee {
171
- constructor(e) {
172
- this.graphStore = e;
173
- }
174
- getNode(e) {
175
- const t = this.graphStore.getNode(e);
176
- return t === void 0 ? null : {
177
- element: t.element,
178
- x: t.x,
179
- y: t.y,
180
- centerFn: t.centerFn,
181
- priority: t.priority
182
- };
183
- }
184
- getAllNodeIds() {
185
- return this.graphStore.getAllNodeIds();
186
- }
187
- getPort(e) {
188
- const t = this.graphStore.getPort(e);
189
- return t === void 0 ? null : {
190
- element: t.element,
191
- centerFn: t.centerFn,
192
- direction: t.direction
193
- };
194
- }
195
- getAllPortIds() {
196
- return this.graphStore.getAllPortIds();
197
- }
198
- getNodePortIds(e) {
199
- return this.graphStore.getNodePortIds(e);
200
- }
201
- getPortNodeId(e) {
202
- return this.graphStore.getPortNodeId(e) ?? null;
203
- }
204
- getAllEdgeIds() {
205
- return this.graphStore.getAllEdgeIds();
206
- }
207
- getEdge(e) {
208
- const t = this.graphStore.getEdge(e);
209
- return t === void 0 ? null : { from: t.from, to: t.to, priority: t.priority };
210
- }
211
- getPortIncomingEdgeIds(e) {
212
- return this.graphStore.getPortIncomingEdgeIds(e);
213
- }
214
- getPortOutcomingEdgeIds(e) {
215
- return this.graphStore.getPortOutcomingEdgeIds(e);
216
- }
217
- getPortCycleEdgeIds(e) {
218
- return this.graphStore.getPortCycleEdgeIds(e);
219
- }
220
- getPortAdjacentEdgeIds(e) {
221
- return this.graphStore.getPortAdjacentEdgeIds(e);
222
- }
223
- getNodeIncomingEdgeIds(e) {
224
- return this.graphStore.getNodeIncomingEdgeIds(e);
225
- }
226
- getNodeOutcomingEdgeIds(e) {
227
- return this.graphStore.getNodeOutcomingEdgeIds(e);
228
- }
229
- getNodeCycleEdgeIds(e) {
230
- return this.graphStore.getNodeCycleEdgeIds(e);
231
- }
232
- getNodeAdjacentEdgeIds(e) {
233
- return this.graphStore.getNodeAdjacentEdgeIds(e);
234
- }
235
- }
236
- const l = {
237
- x: 0,
238
- y: 0
239
- }, p = (r, e, t) => ({
1
+ var Q = Object.defineProperty;
2
+ var Z = (r, e, t) => e in r ? Q(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var a = (r, e, t) => Z(r, typeof e != "symbol" ? e + "" : e, t);
4
+ const H = (r, e) => ({
5
+ x: r / 2,
6
+ y: e / 2
7
+ }), v = (r, e, t) => ({
240
8
  x: e.x * r.x - e.y * r.y + ((1 - e.x) * t.x + e.y * t.y),
241
9
  y: e.y * r.x + e.x * r.y + ((1 - e.x) * t.y - e.y * t.x)
242
- }), x = (r, e, t) => ({ x: e * Math.cos(r), y: t * Math.sin(r) }), E = (r, e, t, s) => {
243
- const i = [
10
+ }), x = (r, e, t) => ({ x: e * Math.cos(r), y: t * Math.sin(r) }), l = {
11
+ x: 0,
12
+ y: 0
13
+ }, f = (r, e, t, s) => {
14
+ const o = [
244
15
  l,
245
16
  { x: t, y: s },
246
17
  { x: t, y: -s }
247
- ].map((c) => p(c, r, l)).map((c) => ({ x: c.x + e.x, y: c.y + e.y })), h = `M ${i[0].x} ${i[0].y}`, a = `L ${i[1].x} ${i[1].y}`, d = `L ${i[2].x} ${i[2].y}`;
248
- return `${h} ${a} ${d}`;
249
- }, D = (r, e) => {
18
+ ].map((c) => v(c, r, l)).map((c) => ({ x: c.x + e.x, y: c.y + e.y })), h = `M ${o[0].x} ${o[0].y}`, i = `L ${o[1].x} ${o[1].y}`, d = `L ${o[2].x} ${o[2].y}`;
19
+ return `${h} ${i} ${d}`;
20
+ }, W = (r, e) => {
250
21
  const t = [];
251
22
  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) {
252
23
  const s = r.length - 1;
253
- let o = 0, i = 0, h = 0;
254
- r.forEach((a, d) => {
24
+ let n = 0, o = 0, h = 0;
25
+ r.forEach((i, d) => {
255
26
  let c = 0, u = 0, w = 0;
256
- const m = d > 0, y = d < s, v = m && y;
257
- if (m && (c = -o, u = -i, w = h), y) {
27
+ const m = d > 0, y = d < s, p = m && y;
28
+ if (m && (c = -n, u = -o, w = h), y) {
258
29
  const j = r[d + 1];
259
- o = j.x - a.x, i = j.y - a.y, h = Math.sqrt(o * o + i * i);
30
+ n = j.x - i.x, o = j.y - i.y, h = Math.sqrt(n * n + o * o);
260
31
  }
261
- const S = h !== 0 ? Math.min((v ? e : 0) / h, d < s - 1 ? 0.5 : 1) : 0, M = v ? { x: a.x + o * S, y: a.y + i * S } : a, T = w !== 0 ? Math.min((v ? e : 0) / w, d > 1 ? 0.5 : 1) : 0, F = v ? { x: a.x + c * T, y: a.y + u * T } : a;
262
- d > 0 && t.push(`L ${F.x} ${F.y}`), v && t.push(
263
- `C ${a.x} ${a.y} ${a.x} ${a.y} ${M.x} ${M.y}`
32
+ const P = h !== 0 ? Math.min((p ? e : 0) / h, d < s - 1 ? 0.5 : 1) : 0, S = p ? { x: i.x + n * P, y: i.y + o * P } : i, L = w !== 0 ? Math.min((p ? e : 0) / w, d > 1 ? 0.5 : 1) : 0, F = p ? { x: i.x + c * L, y: i.y + u * L } : i;
33
+ d > 0 && t.push(`L ${F.x} ${F.y}`), p && t.push(
34
+ `C ${i.x} ${i.y} ${i.x} ${i.y} ${S.x} ${S.y}`
264
35
  );
265
36
  });
266
37
  }
@@ -268,30 +39,30 @@ const l = {
268
39
  }, N = () => {
269
40
  const r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
270
41
  return r.style.pointerEvents = "none", r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.overflow = "visible", r;
271
- }, $ = () => {
42
+ }, I = () => {
272
43
  const r = document.createElementNS("http://www.w3.org/2000/svg", "g");
273
44
  return r.style.transformOrigin = "50% 50%", r;
274
- }, L = (r, e) => {
45
+ }, T = (r, e) => {
275
46
  const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
276
47
  return t.setAttribute("stroke", r), t.setAttribute("stroke-width", `${e}`), t.setAttribute("fill", "none"), t;
277
- }, A = (r) => {
48
+ }, E = (r) => {
278
49
  const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
279
50
  return e.setAttribute("fill", r), e;
280
51
  };
281
- class te {
282
- constructor(e, t, s, o, i, h, a) {
283
- n(this, "svg", N());
284
- n(this, "group", $());
285
- n(this, "line");
286
- n(this, "sourceArrow", null);
287
- n(this, "targetArrow", null);
288
- this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
289
- }
290
- update(e, t, s, o, i) {
52
+ class O {
53
+ constructor(e, t, s, n, o, h, i) {
54
+ a(this, "svg", N());
55
+ a(this, "group", I());
56
+ a(this, "line");
57
+ a(this, "sourceArrow", null);
58
+ a(this, "targetArrow", null);
59
+ this.curvature = s, this.arrowLength = n, this.arrowWidth = o, this.svg.appendChild(this.group), this.line = T(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), i && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
60
+ }
61
+ update(e, t, s, n, o) {
291
62
  this.group.style.transform = `scale(${t}, ${s})`;
292
- const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a);
63
+ const h = x(n, t, s), i = x(o, t, s), d = this.createLinePath(e, h, i);
293
64
  if (this.line.setAttribute("d", d), this.sourceArrow) {
294
- const c = E(
65
+ const c = f(
295
66
  h,
296
67
  l,
297
68
  this.arrowLength,
@@ -300,8 +71,8 @@ class te {
300
71
  this.sourceArrow.setAttribute("d", c);
301
72
  }
302
73
  if (this.targetArrow) {
303
- const c = E(
304
- a,
74
+ const c = f(
75
+ i,
305
76
  e,
306
77
  -this.arrowLength,
307
78
  this.arrowWidth
@@ -310,38 +81,38 @@ class te {
310
81
  }
311
82
  }
312
83
  createLinePath(e, t, s) {
313
- const o = p(
84
+ const n = v(
314
85
  { x: this.arrowLength, y: l.y },
315
86
  t,
316
87
  l
317
- ), i = p(
88
+ ), o = v(
318
89
  { x: e.x - this.arrowLength, y: e.y },
319
90
  s,
320
91
  e
321
92
  ), h = {
322
- x: o.x + t.x * this.curvature,
323
- y: o.y + t.y * this.curvature
324
- }, a = {
325
- x: i.x - s.x * this.curvature,
326
- y: i.y - s.y * this.curvature
327
- }, d = `M ${o.x} ${o.y} C ${h.x} ${h.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`, c = this.sourceArrow ? "" : `M ${l.x} ${l.y} L ${o.x} ${o.y} `, u = this.targetArrow ? "" : ` M ${i.x} ${i.y} L ${e.x} ${e.y}`;
93
+ x: n.x + t.x * this.curvature,
94
+ y: n.y + t.y * this.curvature
95
+ }, i = {
96
+ x: o.x - s.x * this.curvature,
97
+ y: o.y - s.y * this.curvature
98
+ }, d = `M ${n.x} ${n.y} C ${h.x} ${h.y}, ${i.x} ${i.y}, ${o.x} ${o.y}`, c = this.sourceArrow ? "" : `M ${l.x} ${l.y} L ${n.x} ${n.y} `, u = this.targetArrow ? "" : ` M ${o.x} ${o.y} L ${e.x} ${e.y}`;
328
99
  return `${c}${d}${u}`;
329
100
  }
330
101
  }
331
- class re {
332
- constructor(e, t, s, o, i, h, a, d) {
333
- n(this, "svg", N());
334
- n(this, "group", $());
335
- n(this, "line");
336
- n(this, "sourceArrow", null);
337
- n(this, "targetArrow", null);
338
- this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = d, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
339
- }
340
- update(e, t, s, o, i) {
102
+ class q {
103
+ constructor(e, t, s, n, o, h, i, d) {
104
+ a(this, "svg", N());
105
+ a(this, "group", I());
106
+ a(this, "line");
107
+ a(this, "sourceArrow", null);
108
+ a(this, "targetArrow", null);
109
+ this.arrowLength = s, this.arrowWidth = n, this.arrowOffset = o, this.roundness = d, this.svg.appendChild(this.group), this.line = T(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), i && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
110
+ }
111
+ update(e, t, s, n, o) {
341
112
  this.group.style.transform = `scale(${t}, ${s})`;
342
- const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a);
113
+ const h = x(n, t, s), i = x(o, t, s), d = this.createLinePath(e, h, i);
343
114
  if (this.line.setAttribute("d", d), this.sourceArrow) {
344
- const c = E(
115
+ const c = f(
345
116
  h,
346
117
  l,
347
118
  this.arrowLength,
@@ -350,8 +121,8 @@ class re {
350
121
  this.sourceArrow.setAttribute("d", c);
351
122
  }
352
123
  if (this.targetArrow) {
353
- const c = E(
354
- a,
124
+ const c = f(
125
+ i,
355
126
  e,
356
127
  -this.arrowLength,
357
128
  this.arrowWidth
@@ -360,24 +131,24 @@ class re {
360
131
  }
361
132
  }
362
133
  createLinePath(e, t, s) {
363
- const o = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, i = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, h = this.arrowLength + this.arrowOffset, a = p({ x: h, y: l.y }, t, l), d = p({ x: e.x - h, y: e.y }, s, e);
364
- return D([o, a, d, i], this.roundness);
134
+ const n = this.sourceArrow ? v({ x: this.arrowLength, y: l.y }, t, l) : l, o = this.targetArrow ? v({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, h = this.arrowLength + this.arrowOffset, i = v({ x: h, y: l.y }, t, l), d = v({ x: e.x - h, y: e.y }, s, e);
135
+ return W([n, i, d, o], this.roundness);
365
136
  }
366
137
  }
367
- class se {
368
- constructor(e, t, s, o, i, h, a, d) {
369
- n(this, "svg", N());
370
- n(this, "group", $());
371
- n(this, "line");
372
- n(this, "sourceArrow", null);
373
- n(this, "targetArrow", null);
374
- this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = d, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
375
- }
376
- update(e, t, s, o, i) {
138
+ class ee {
139
+ constructor(e, t, s, n, o, h, i, d) {
140
+ a(this, "svg", N());
141
+ a(this, "group", I());
142
+ a(this, "line");
143
+ a(this, "sourceArrow", null);
144
+ a(this, "targetArrow", null);
145
+ this.arrowLength = s, this.arrowWidth = n, this.arrowOffset = o, this.roundness = d, this.svg.appendChild(this.group), this.line = T(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), i && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
146
+ }
147
+ update(e, t, s, n, o) {
377
148
  this.group.style.transform = `scale(${t}, ${s})`;
378
- const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t);
149
+ const h = x(n, t, s), i = x(o, t, s), d = this.createLinePath(e, h, i, t);
379
150
  if (this.line.setAttribute("d", d), this.sourceArrow) {
380
- const c = E(
151
+ const c = f(
381
152
  h,
382
153
  l,
383
154
  this.arrowLength,
@@ -386,8 +157,8 @@ class se {
386
157
  this.sourceArrow.setAttribute("d", c);
387
158
  }
388
159
  if (this.targetArrow) {
389
- const c = E(
390
- a,
160
+ const c = f(
161
+ i,
391
162
  e,
392
163
  -this.arrowLength,
393
164
  this.arrowWidth
@@ -395,28 +166,28 @@ class se {
395
166
  this.targetArrow.setAttribute("d", c);
396
167
  }
397
168
  }
398
- createLinePath(e, t, s, o) {
399
- const i = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, h = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, a = this.arrowLength + this.arrowOffset, d = a - this.roundness, c = p({ x: d, y: l.y }, t, l), u = p({ x: e.x - d, y: e.y }, s, e), w = Math.max((c.x + u.x) / 2, a), m = e.y / 2, y = { x: o > 0 ? w : -a, y: c.y }, v = { x: y.x, y: m }, P = { x: o > 0 ? e.x - w : e.x + a, y: u.y }, S = { x: P.x, y: m };
400
- return D(
401
- [i, c, y, v, S, P, u, h],
169
+ createLinePath(e, t, s, n) {
170
+ const o = this.sourceArrow ? v({ x: this.arrowLength, y: l.y }, t, l) : l, h = this.targetArrow ? v({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, i = this.arrowLength + this.arrowOffset, d = i - this.roundness, c = v({ x: d, y: l.y }, t, l), u = v({ x: e.x - d, y: e.y }, s, e), w = Math.max((c.x + u.x) / 2, i), m = e.y / 2, y = { x: n > 0 ? w : -i, y: c.y }, p = { x: y.x, y: m }, M = { x: n > 0 ? e.x - w : e.x + i, y: u.y }, P = { x: M.x, y: m };
171
+ return W(
172
+ [o, c, y, p, P, M, u, h],
402
173
  this.roundness
403
174
  );
404
175
  }
405
176
  }
406
- class oe {
407
- constructor(e, t, s, o, i, h, a, d) {
408
- n(this, "svg", N());
409
- n(this, "group", $());
410
- n(this, "line");
411
- n(this, "sourceArrow", null);
412
- n(this, "targetArrow", null);
413
- this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = d, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
414
- }
415
- update(e, t, s, o, i) {
177
+ class te {
178
+ constructor(e, t, s, n, o, h, i, d) {
179
+ a(this, "svg", N());
180
+ a(this, "group", I());
181
+ a(this, "line");
182
+ a(this, "sourceArrow", null);
183
+ a(this, "targetArrow", null);
184
+ this.arrowLength = s, this.arrowWidth = n, this.arrowOffset = o, this.roundness = d, this.svg.appendChild(this.group), this.line = T(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), i && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
185
+ }
186
+ update(e, t, s, n, o) {
416
187
  this.group.style.transform = `scale(${t}, ${s})`;
417
- const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, s);
188
+ const h = x(n, t, s), i = x(o, t, s), d = this.createLinePath(e, h, i, s);
418
189
  if (this.line.setAttribute("d", d), this.sourceArrow) {
419
- const c = E(
190
+ const c = f(
420
191
  h,
421
192
  l,
422
193
  this.arrowLength,
@@ -425,8 +196,8 @@ class oe {
425
196
  this.sourceArrow.setAttribute("d", c);
426
197
  }
427
198
  if (this.targetArrow) {
428
- const c = E(
429
- a,
199
+ const c = f(
200
+ i,
430
201
  e,
431
202
  -this.arrowLength,
432
203
  this.arrowWidth
@@ -434,42 +205,42 @@ class oe {
434
205
  this.targetArrow.setAttribute("d", c);
435
206
  }
436
207
  }
437
- createLinePath(e, t, s, o) {
438
- const i = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, h = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, a = this.arrowLength + this.arrowOffset, d = a - this.roundness, c = p({ x: d, y: l.y }, t, l), u = p({ x: e.x - d, y: e.y }, s, e), w = Math.max((c.y + u.y) / 2, a), m = e.x / 2, y = { x: c.x, y: o > 0 ? w : -a }, v = { x: m, y: y.y }, P = {
208
+ createLinePath(e, t, s, n) {
209
+ const o = this.sourceArrow ? v({ x: this.arrowLength, y: l.y }, t, l) : l, h = this.targetArrow ? v({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, i = this.arrowLength + this.arrowOffset, d = i - this.roundness, c = v({ x: d, y: l.y }, t, l), u = v({ x: e.x - d, y: e.y }, s, e), w = Math.max((c.y + u.y) / 2, i), m = e.x / 2, y = { x: c.x, y: n > 0 ? w : -i }, p = { x: m, y: y.y }, M = {
439
210
  x: u.x,
440
- y: o > 0 ? e.y - w : e.y + a
441
- }, S = { x: m, y: P.y };
442
- return D(
443
- [i, c, y, v, S, P, u, h],
211
+ y: n > 0 ? e.y - w : e.y + i
212
+ }, P = { x: m, y: M.y };
213
+ return W(
214
+ [o, c, y, p, P, M, u, h],
444
215
  this.roundness
445
216
  );
446
217
  }
447
218
  }
448
- class ie {
449
- constructor(e, t, s, o, i, h, a) {
450
- n(this, "svg", N());
451
- n(this, "line");
452
- n(this, "arrow", null);
453
- this.arrowLength = s, this.arrowWidth = o, this.radius = h, this.smallRadius = a, this.line = L(e, t), this.svg.appendChild(this.line), i && (this.arrow = A(e), this.svg.appendChild(this.arrow));
454
- }
455
- update(e, t, s, o) {
456
- const i = x(o, t, s), h = this.createLinePath(i);
219
+ class re {
220
+ constructor(e, t, s, n, o, h, i) {
221
+ a(this, "svg", N());
222
+ a(this, "line");
223
+ a(this, "arrow", null);
224
+ this.arrowLength = s, this.arrowWidth = n, this.radius = h, this.smallRadius = i, this.line = T(e, t), this.svg.appendChild(this.line), o && (this.arrow = E(e), this.svg.appendChild(this.arrow));
225
+ }
226
+ update(e, t, s, n) {
227
+ const o = x(n, t, s), h = this.createLinePath(o);
457
228
  if (this.line.setAttribute("d", h), this.arrow) {
458
- const a = E(
459
- i,
229
+ const i = f(
230
+ o,
460
231
  l,
461
232
  this.arrowLength,
462
233
  this.arrowWidth
463
234
  );
464
- this.arrow.setAttribute("d", a);
235
+ this.arrow.setAttribute("d", i);
465
236
  }
466
237
  }
467
238
  createLinePath(e) {
468
- const t = this.smallRadius, s = this.radius, o = Math.sqrt(t * t + s * s), i = t + s, h = this.arrowLength + o * (1 - s / i), a = t * s / i, c = [
239
+ const t = this.smallRadius, s = this.radius, n = Math.sqrt(t * t + s * s), o = t + s, h = this.arrowLength + n * (1 - s / o), i = t * s / o, c = [
469
240
  { x: this.arrowLength, y: l.y },
470
- { x: h, y: a },
471
- { x: h, y: -a }
472
- ].map((m) => p(m, e, l)), u = [
241
+ { x: h, y: i },
242
+ { x: h, y: -i }
243
+ ].map((m) => v(m, e, l)), u = [
473
244
  `M ${c[0].x} ${c[0].y}`,
474
245
  `A ${t} ${t} 0 0 1 ${c[1].x} ${c[1].y}`,
475
246
  `A ${s} ${s} 0 1 0 ${c[2].x} ${c[2].y}`,
@@ -478,14 +249,14 @@ class ie {
478
249
  return `${this.arrow !== null ? "" : w}${u}`;
479
250
  }
480
251
  }
481
- class B {
482
- constructor(e, t, s, o, i, h, a, d) {
483
- n(this, "svg", N());
484
- n(this, "line");
485
- n(this, "arrow", null);
486
- n(this, "roundness");
487
- n(this, "linePoints");
488
- this.arrowLength = s, this.arrowWidth = o, this.side = h, this.minPortOffset = a, this.roundness = Math.min(d, this.minPortOffset, this.side / 2), this.line = L(e, t), this.svg.appendChild(this.line), i && (this.arrow = A(e), this.svg.appendChild(this.arrow));
252
+ class X {
253
+ constructor(e, t, s, n, o, h, i, d) {
254
+ a(this, "svg", N());
255
+ a(this, "line");
256
+ a(this, "arrow", null);
257
+ a(this, "roundness");
258
+ a(this, "linePoints");
259
+ this.arrowLength = s, this.arrowWidth = n, this.side = h, this.minPortOffset = i, this.roundness = Math.min(d, this.minPortOffset, this.side / 2), this.line = T(e, t), this.svg.appendChild(this.line), o && (this.arrow = E(e), this.svg.appendChild(this.arrow));
489
260
  const c = this.minPortOffset, u = this.side, w = this.arrowLength + c, m = w + 2 * u;
490
261
  this.linePoints = [
491
262
  { x: this.arrowLength, y: l.y },
@@ -498,41 +269,41 @@ class B {
498
269
  { x: this.arrowLength, y: l.y }
499
270
  ];
500
271
  }
501
- update(e, t, s, o) {
502
- const i = x(o, t, s), h = this.createLinePath(i);
272
+ update(e, t, s, n) {
273
+ const o = x(n, t, s), h = this.createLinePath(o);
503
274
  if (this.line.setAttribute("d", h), this.arrow) {
504
- const a = E(
505
- i,
275
+ const i = f(
276
+ o,
506
277
  l,
507
278
  this.arrowLength,
508
279
  this.arrowWidth
509
280
  );
510
- this.arrow.setAttribute("d", a);
281
+ this.arrow.setAttribute("d", i);
511
282
  }
512
283
  }
513
284
  createLinePath(e) {
514
285
  const t = this.linePoints.map(
515
- (o) => p(o, e, l)
286
+ (n) => v(n, e, l)
516
287
  ), s = `M ${l.x} ${l.y} L ${t[0].x} ${t[0].y} `;
517
- return `${this.arrow ? "" : s}${D(t, this.roundness)}`;
288
+ return `${this.arrow ? "" : s}${W(t, this.roundness)}`;
518
289
  }
519
290
  }
520
- class ne {
521
- constructor(e, t, s, o, i, h, a, d, c) {
522
- n(this, "svg", N());
523
- n(this, "group", $());
524
- n(this, "line");
525
- n(this, "sourceArrow", null);
526
- n(this, "targetArrow", null);
527
- n(this, "detourX");
528
- n(this, "detourY");
529
- this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.detourX = Math.cos(c) * d, this.detourY = Math.sin(c) * d, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
530
- }
531
- update(e, t, s, o, i) {
291
+ class se {
292
+ constructor(e, t, s, n, o, h, i, d, c) {
293
+ a(this, "svg", N());
294
+ a(this, "group", I());
295
+ a(this, "line");
296
+ a(this, "sourceArrow", null);
297
+ a(this, "targetArrow", null);
298
+ a(this, "detourX");
299
+ a(this, "detourY");
300
+ this.curvature = s, this.arrowLength = n, this.arrowWidth = o, this.detourX = Math.cos(c) * d, this.detourY = Math.sin(c) * d, this.svg.appendChild(this.group), this.line = T(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), i && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
301
+ }
302
+ update(e, t, s, n, o) {
532
303
  this.group.style.transform = `scale(${t}, ${s})`;
533
- const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t, s);
304
+ const h = x(n, t, s), i = x(o, t, s), d = this.createLinePath(e, h, i, t, s);
534
305
  if (this.line.setAttribute("d", d), this.sourceArrow) {
535
- const c = E(
306
+ const c = f(
536
307
  h,
537
308
  l,
538
309
  this.arrowLength,
@@ -541,8 +312,8 @@ class ne {
541
312
  this.sourceArrow.setAttribute("d", c);
542
313
  }
543
314
  if (this.targetArrow) {
544
- const c = E(
545
- a,
315
+ const c = f(
316
+ i,
546
317
  e,
547
318
  -this.arrowLength,
548
319
  this.arrowWidth
@@ -550,59 +321,59 @@ class ne {
550
321
  this.targetArrow.setAttribute("d", c);
551
322
  }
552
323
  }
553
- createLinePath(e, t, s, o, i) {
554
- const h = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, a = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, d = this.arrowLength, c = this.detourX * o, u = this.detourY * i, w = p(
324
+ createLinePath(e, t, s, n, o) {
325
+ const h = this.sourceArrow ? v({ x: this.arrowLength, y: l.y }, t, l) : l, i = this.targetArrow ? v({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, d = this.arrowLength, c = this.detourX * n, u = this.detourY * o, w = v(
555
326
  { x: d, y: l.y },
556
327
  t,
557
328
  l
558
329
  ), m = {
559
330
  x: w.x + c,
560
331
  y: w.y + u
561
- }, y = p(
332
+ }, y = v(
562
333
  { x: e.x - d, y: e.y },
563
334
  s,
564
335
  e
565
- ), v = {
336
+ ), p = {
566
337
  x: y.x + c,
567
338
  y: y.y + u
568
- }, P = { x: (m.x + v.x) / 2, y: (m.y + v.y) / 2 }, S = {
339
+ }, M = { x: (m.x + p.x) / 2, y: (m.y + p.y) / 2 }, P = {
569
340
  x: w.x + this.curvature * t.x,
570
341
  y: w.y + this.curvature * t.y
571
- }, M = {
342
+ }, S = {
572
343
  x: y.x - this.curvature * s.x,
573
344
  y: y.y - this.curvature * s.y
574
345
  }, b = {
575
346
  x: w.x + c,
576
347
  y: w.y + u
577
- }, T = {
348
+ }, L = {
578
349
  x: y.x + c,
579
350
  y: y.y + u
580
351
  };
581
352
  return [
582
353
  `M ${h.x} ${h.y}`,
583
354
  `L ${w.x} ${w.y}`,
584
- `C ${S.x} ${S.y} ${b.x} ${b.y} ${P.x} ${P.y}`,
585
- `C ${T.x} ${T.y} ${M.x} ${M.y} ${y.x} ${y.y}`,
586
- `L ${a.x} ${a.y}`
355
+ `C ${P.x} ${P.y} ${b.x} ${b.y} ${M.x} ${M.y}`,
356
+ `C ${L.x} ${L.y} ${S.x} ${S.y} ${y.x} ${y.y}`,
357
+ `L ${i.x} ${i.y}`
587
358
  ].join(" ");
588
359
  }
589
360
  }
590
361
  class G {
591
- constructor(e, t, s, o, i, h, a, d, c, u) {
592
- n(this, "svg", N());
593
- n(this, "group", $());
594
- n(this, "line");
595
- n(this, "sourceArrow", null);
596
- n(this, "targetArrow", null);
597
- n(this, "detourX");
598
- n(this, "detourY");
599
- this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = d, this.detourX = Math.cos(u) * c, this.detourY = Math.sin(u) * c, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
600
- }
601
- update(e, t, s, o, i) {
362
+ constructor(e, t, s, n, o, h, i, d, c, u) {
363
+ a(this, "svg", N());
364
+ a(this, "group", I());
365
+ a(this, "line");
366
+ a(this, "sourceArrow", null);
367
+ a(this, "targetArrow", null);
368
+ a(this, "detourX");
369
+ a(this, "detourY");
370
+ this.arrowLength = s, this.arrowWidth = n, this.arrowOffset = o, this.roundness = d, this.detourX = Math.cos(u) * c, this.detourY = Math.sin(u) * c, this.svg.appendChild(this.group), this.line = T(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), i && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
371
+ }
372
+ update(e, t, s, n, o) {
602
373
  this.group.style.transform = `scale(${t}, ${s})`;
603
- const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t, s);
374
+ const h = x(n, t, s), i = x(o, t, s), d = this.createLinePath(e, h, i, t, s);
604
375
  if (this.line.setAttribute("d", d), this.sourceArrow) {
605
- const c = E(
376
+ const c = f(
606
377
  h,
607
378
  l,
608
379
  this.arrowLength,
@@ -611,8 +382,8 @@ class G {
611
382
  this.sourceArrow.setAttribute("d", c);
612
383
  }
613
384
  if (this.targetArrow) {
614
- const c = E(
615
- a,
385
+ const c = f(
386
+ i,
616
387
  e,
617
388
  -this.arrowLength,
618
389
  this.arrowWidth
@@ -620,24 +391,24 @@ class G {
620
391
  this.targetArrow.setAttribute("d", c);
621
392
  }
622
393
  }
623
- createLinePath(e, t, s, o, i) {
624
- const h = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, a = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, d = this.arrowLength + this.arrowOffset, c = p(
394
+ createLinePath(e, t, s, n, o) {
395
+ const h = this.sourceArrow ? v({ x: this.arrowLength, y: l.y }, t, l) : l, i = this.targetArrow ? v({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, d = this.arrowLength + this.arrowOffset, c = v(
625
396
  { x: d, y: l.y },
626
397
  t,
627
398
  l
628
- ), u = this.detourX * o, w = this.detourY * i, m = { x: c.x + u, y: c.y + w }, y = p(
399
+ ), u = this.detourX * n, w = this.detourY * o, m = { x: c.x + u, y: c.y + w }, y = v(
629
400
  { x: e.x - d, y: e.y },
630
401
  s,
631
402
  e
632
- ), v = { x: y.x + u, y: y.y + w };
633
- return D(
634
- [h, c, m, v, y, a],
403
+ ), p = { x: y.x + u, y: y.y + w };
404
+ return W(
405
+ [h, c, m, p, y, i],
635
406
  this.roundness
636
407
  );
637
408
  }
638
409
  }
639
410
  var C = /* @__PURE__ */ ((r) => (r.Regular = "regular", r.PortCycle = "port-cycle", r.NodeCycle = "node-cycle", r))(C || {});
640
- const ae = (r) => (e) => e === C.PortCycle ? new ie(
411
+ const oe = (r) => (e) => e === C.PortCycle ? new re(
641
412
  r.color,
642
413
  r.width,
643
414
  r.arrowLength,
@@ -645,7 +416,7 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
645
416
  r.hasSourceArrow || r.hasTargetArrow,
646
417
  r.cycleRadius,
647
418
  r.smallCycleRadius
648
- ) : e === C.NodeCycle ? new ne(
419
+ ) : e === C.NodeCycle ? new se(
649
420
  r.color,
650
421
  r.width,
651
422
  r.curvature,
@@ -655,7 +426,7 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
655
426
  r.hasTargetArrow,
656
427
  r.detourDistance,
657
428
  r.detourDirection
658
- ) : new te(
429
+ ) : new O(
659
430
  r.color,
660
431
  r.width,
661
432
  r.curvature,
@@ -663,7 +434,7 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
663
434
  r.arrowWidth,
664
435
  r.hasSourceArrow,
665
436
  r.hasTargetArrow
666
- ), he = (r) => (e) => e === C.PortCycle ? new B(
437
+ ), ne = (r) => (e) => e === C.PortCycle ? new X(
667
438
  r.color,
668
439
  r.width,
669
440
  r.arrowLength,
@@ -683,7 +454,7 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
683
454
  r.roundness,
684
455
  r.detourDistance,
685
456
  r.detourDirection
686
- ) : new re(
457
+ ) : new q(
687
458
  r.color,
688
459
  r.width,
689
460
  r.arrowLength,
@@ -692,7 +463,7 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
692
463
  r.hasSourceArrow,
693
464
  r.hasTargetArrow,
694
465
  r.roundness
695
- ), de = (r) => (e) => e === C.PortCycle ? new B(
466
+ ), ie = (r) => (e) => e === C.PortCycle ? new X(
696
467
  r.color,
697
468
  r.width,
698
469
  r.arrowLength,
@@ -712,7 +483,7 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
712
483
  r.roundness,
713
484
  r.detourDistance,
714
485
  r.detourDirection
715
- ) : new oe(
486
+ ) : new te(
716
487
  r.color,
717
488
  r.width,
718
489
  r.arrowLength,
@@ -721,7 +492,7 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
721
492
  r.hasSourceArrow,
722
493
  r.hasTargetArrow,
723
494
  r.roundness
724
- ), ce = (r) => (e) => e === C.PortCycle ? new B(
495
+ ), ae = (r) => (e) => e === C.PortCycle ? new X(
725
496
  r.color,
726
497
  r.width,
727
498
  r.arrowLength,
@@ -741,7 +512,7 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
741
512
  r.roundness,
742
513
  r.detourDistance,
743
514
  r.detourDirection
744
- ) : new se(
515
+ ) : new ee(
745
516
  r.color,
746
517
  r.width,
747
518
  r.arrowLength,
@@ -750,181 +521,362 @@ const ae = (r) => (e) => e === C.PortCycle ? new ie(
750
521
  r.hasSourceArrow,
751
522
  r.hasTargetArrow,
752
523
  r.roundness
753
- );
754
- class I {
755
- constructor(e) {
756
- n(this, "counter", 0);
757
- this.checkExists = e;
758
- }
759
- create(e) {
760
- if (e !== void 0)
761
- return e;
762
- for (; this.checkExists(this.counter); )
763
- this.counter++;
764
- return this.counter;
765
- }
766
- reset() {
767
- this.counter = 0;
768
- }
769
- }
770
- class f extends Error {
771
- constructor() {
772
- super(...arguments);
773
- n(this, "name", "HtmlGraphError");
774
- }
775
- }
776
- class le {
777
- constructor(e, t, s, o, i, h, a, d) {
778
- n(this, "nodeIdGenerator", new I(
779
- (e) => this.graphStore.getNode(e) !== void 0
780
- ));
781
- n(this, "portIdGenerator", new I(
782
- (e) => this.graphStore.getPort(e) !== void 0
783
- ));
784
- n(this, "edgeIdGenerator", new I(
785
- (e) => this.graphStore.getEdge(e) !== void 0
786
- ));
787
- this.graphStore = e, this.htmlController = t, this.viewportTransformer = s, this.defaultNodesCenterFn = o, this.defaultPortsCenterFn = i, this.defaultPortsDirection = h, this.defaultNodesPriorityFn = a, this.defaultEdgesPriorityFn = d;
788
- }
789
- attach(e) {
790
- this.htmlController.attach(e);
524
+ ), g = {
525
+ edgeColor: "#5c5c5c",
526
+ edgeWidth: 1,
527
+ edgeArrowLength: 15,
528
+ edgeArrowWidth: 4,
529
+ edgeArrowOffset: 15,
530
+ hasSourceArrow: !1,
531
+ hasTargetArrow: !1,
532
+ cycleSize: 30,
533
+ roundness: 10,
534
+ detourDistance: 100,
535
+ detourDirection: -Math.PI / 2,
536
+ smallCycleSize: 15,
537
+ curvature: 90
538
+ }, B = (r) => {
539
+ switch (r == null ? void 0 : r.type) {
540
+ case "custom":
541
+ return r.factory;
542
+ case "straight":
543
+ return ne({
544
+ color: r.color ?? g.edgeColor,
545
+ width: r.width ?? g.edgeWidth,
546
+ arrowLength: r.arrowLength ?? g.edgeArrowLength,
547
+ arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
548
+ arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
549
+ hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
550
+ hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
551
+ cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
552
+ roundness: r.roundness ?? g.roundness,
553
+ detourDistance: r.detourDistance ?? g.detourDistance,
554
+ detourDirection: r.detourDirection ?? g.detourDirection
555
+ });
556
+ case "horizontal":
557
+ return ae({
558
+ color: r.color ?? g.edgeColor,
559
+ width: r.width ?? g.edgeWidth,
560
+ arrowLength: r.arrowLength ?? g.edgeArrowLength,
561
+ arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
562
+ arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
563
+ hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
564
+ hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
565
+ cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
566
+ roundness: r.roundness ?? g.roundness,
567
+ detourDistance: r.detourDistance ?? g.detourDistance,
568
+ detourDirection: r.detourDirection ?? g.detourDirection
569
+ });
570
+ case "vertical":
571
+ return ie({
572
+ color: r.color ?? g.edgeColor,
573
+ width: r.width ?? g.edgeWidth,
574
+ arrowLength: r.arrowLength ?? g.edgeArrowLength,
575
+ arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
576
+ arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
577
+ hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
578
+ hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
579
+ cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
580
+ roundness: r.roundness ?? g.roundness,
581
+ detourDistance: r.detourDistance ?? g.detourDistance,
582
+ detourDirection: r.detourDirection ?? g.detourDirection
583
+ });
584
+ default:
585
+ return oe({
586
+ color: r.color ?? g.edgeColor,
587
+ width: r.width ?? g.edgeWidth,
588
+ arrowLength: r.arrowLength ?? g.edgeArrowLength,
589
+ arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
590
+ hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
591
+ hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
592
+ cycleRadius: r.cycleRadius ?? g.cycleSize,
593
+ smallCycleRadius: r.smallCycleRadius ?? g.smallCycleSize,
594
+ curvature: r.curvature ?? g.curvature,
595
+ detourDistance: r.detourDistance ?? g.detourDistance,
596
+ detourDirection: r.detourDirection ?? g.detourDirection
597
+ });
791
598
  }
792
- detach() {
793
- this.htmlController.detach();
599
+ }, Y = (r) => () => r, U = Y(0), R = () => {
600
+ let r = 0;
601
+ return () => r++;
602
+ }, he = (r, e) => {
603
+ let t = U, s = U;
604
+ r === "incremental" && (t = R()), e === "incremental" && (s = R());
605
+ const n = R();
606
+ return r === "shared-incremental" && (t = n), e === "shared-incremental" && (s = n), typeof r == "number" && (t = Y(r)), typeof e == "number" && (s = Y(e)), typeof r == "function" && (t = r), typeof e == "function" && (s = e), {
607
+ nodesPriorityFn: t,
608
+ edgesPriorityFn: s
609
+ };
610
+ }, de = (r) => {
611
+ var t, s, n, o, h, i;
612
+ const e = he(
613
+ (t = r == null ? void 0 : r.nodes) == null ? void 0 : t.priority,
614
+ (s = r == null ? void 0 : r.edges) == null ? void 0 : s.priority
615
+ );
616
+ return {
617
+ nodes: {
618
+ centerFn: ((n = r == null ? void 0 : r.nodes) == null ? void 0 : n.centerFn) ?? H,
619
+ priorityFn: e.nodesPriorityFn
620
+ },
621
+ ports: {
622
+ centerFn: ((o = r == null ? void 0 : r.ports) == null ? void 0 : o.centerFn) ?? H,
623
+ direction: ((h = r == null ? void 0 : r.ports) == null ? void 0 : h.direction) ?? 0
624
+ },
625
+ edges: {
626
+ shapeFactory: B(((i = r == null ? void 0 : r.edges) == null ? void 0 : i.shape) ?? {}),
627
+ priorityFn: e.edgesPriorityFn
628
+ }
629
+ };
630
+ };
631
+ class ce {
632
+ constructor() {
633
+ a(this, "nodes", /* @__PURE__ */ new Map());
634
+ a(this, "ports", /* @__PURE__ */ new Map());
635
+ a(this, "nodePorts", /* @__PURE__ */ new Map());
636
+ a(this, "portNodeId", /* @__PURE__ */ new Map());
637
+ a(this, "edges", /* @__PURE__ */ new Map());
638
+ a(this, "incommingEdges", /* @__PURE__ */ new Map());
639
+ a(this, "outcommingEdges", /* @__PURE__ */ new Map());
640
+ a(this, "cycleEdges", /* @__PURE__ */ new Map());
794
641
  }
795
642
  addNode(e) {
796
- const t = this.nodeIdGenerator.create(e.nodeId);
797
- if (this.graphStore.getNode(t) !== void 0)
798
- throw new f("failed to add node with existing id");
799
- this.graphStore.addNode({
800
- nodeId: t,
643
+ this.nodes.set(e.nodeId, {
801
644
  element: e.element,
802
645
  x: e.x,
803
646
  y: e.y,
804
- centerFn: e.centerFn ?? this.defaultNodesCenterFn,
805
- priority: e.priority ?? this.defaultNodesPriorityFn()
806
- }), this.htmlController.attachNode(t), Array.from(e.ports ?? []).forEach((s) => {
807
- this.markPort({
808
- portId: s.id,
809
- element: s.element,
810
- nodeId: t,
811
- centerFn: s.centerFn,
812
- direction: s.direction
813
- });
814
- });
647
+ centerFn: e.centerFn,
648
+ priority: e.priority
649
+ }), this.nodePorts.set(e.nodeId, /* @__PURE__ */ new Map());
815
650
  }
816
- markPort(e) {
817
- const t = this.portIdGenerator.create(e.portId);
818
- if (this.graphStore.getPort(t) !== void 0)
819
- throw new f("failed to add port with existing id");
820
- if (this.graphStore.getNode(e.nodeId) === void 0)
821
- throw new f("failed to set port on nonexisting node");
822
- this.graphStore.addPort({
823
- portId: t,
651
+ getAllNodeIds() {
652
+ return Array.from(this.nodes.keys());
653
+ }
654
+ getNode(e) {
655
+ return this.nodes.get(e);
656
+ }
657
+ removeNode(e) {
658
+ this.nodes.delete(e), this.nodePorts.delete(e);
659
+ }
660
+ addPort(e) {
661
+ this.ports.set(e.portId, {
824
662
  element: e.element,
825
- nodeId: e.nodeId,
826
- centerFn: e.centerFn ?? this.defaultPortsCenterFn,
827
- direction: e.direction ?? this.defaultPortsDirection
828
- });
663
+ centerFn: e.centerFn,
664
+ direction: e.direction
665
+ }), this.cycleEdges.set(e.portId, /* @__PURE__ */ new Set()), this.incommingEdges.set(e.portId, /* @__PURE__ */ new Set()), this.outcommingEdges.set(e.portId, /* @__PURE__ */ new Set()), this.portNodeId.set(e.portId, e.nodeId), this.nodePorts.get(e.nodeId).set(e.portId, e.element);
666
+ }
667
+ getPort(e) {
668
+ return this.ports.get(e);
669
+ }
670
+ getAllPortIds() {
671
+ return Array.from(this.ports.keys());
672
+ }
673
+ getNodePortIds(e) {
674
+ const t = this.nodePorts.get(e);
675
+ if (t !== void 0)
676
+ return Array.from(t.keys());
677
+ }
678
+ getPortNodeId(e) {
679
+ return this.portNodeId.get(e);
680
+ }
681
+ removePort(e) {
682
+ const t = this.portNodeId.get(e);
683
+ this.portNodeId.delete(e), this.nodePorts.get(t).delete(e), this.ports.delete(e);
829
684
  }
830
685
  addEdge(e) {
831
- const t = this.edgeIdGenerator.create(e.edgeId);
832
- if (this.graphStore.getEdge(t) !== void 0)
833
- throw new f("failed to add edge with existing id");
834
- if (this.graphStore.getPort(e.from) === void 0)
835
- throw new f("failed to add edge from nonexisting port");
836
- if (this.graphStore.getPort(e.to) === void 0)
837
- throw new f("failed to add edge to nonexisting port");
838
- const s = this.resolveEdgeType(e.from, e.to);
839
- this.graphStore.addEdge({
840
- edgeId: t,
686
+ this.edges.set(e.edgeId, {
841
687
  from: e.from,
842
688
  to: e.to,
843
- shape: e.shapeFactory(s),
844
- priority: e.priority ?? this.defaultEdgesPriorityFn()
845
- }), this.htmlController.attachEdge(t);
846
- }
847
- updateEdge(e) {
848
- const t = this.graphStore.getEdge(e.edgeId);
849
- if (t === void 0)
850
- throw new f("failed to update nonexisting edge");
851
- if (e.shape !== void 0) {
852
- const s = this.resolveEdgeType(t.from, t.to);
853
- t.shape = e.shape(s), this.htmlController.updateEdgeShape(e.edgeId);
854
- }
855
- e.priority !== void 0 && (t.priority = e.priority, this.htmlController.updateEdgePriority(e.edgeId)), this.htmlController.updateEdge(e.edgeId);
689
+ shape: e.shape,
690
+ priority: e.priority
691
+ }), e.from !== e.to ? (this.outcommingEdges.get(e.from).add(e.edgeId), this.incommingEdges.get(e.to).add(e.edgeId)) : this.cycleEdges.get(e.from).add(e.edgeId);
856
692
  }
857
- updatePort(e, t) {
858
- const s = this.graphStore.getPort(e);
859
- if (s === void 0)
860
- throw new f("failed to unset nonexisting port");
861
- s.direction = t.direction ?? s.direction, s.centerFn = t.centerFn ?? s.centerFn, this.graphStore.getPortAdjacentEdgeIds(e).forEach((i) => {
862
- this.htmlController.updateEdge(i);
863
- });
693
+ getAllEdgeIds() {
694
+ return Array.from(this.edges.keys());
864
695
  }
865
- updateNode(e, t) {
866
- const s = this.graphStore.getNode(e);
867
- if (s === void 0)
868
- throw new f("failed to update nonexisting node");
869
- s.x = (t == null ? void 0 : t.x) ?? s.x, s.y = (t == null ? void 0 : t.y) ?? s.y, s.centerFn = (t == null ? void 0 : t.centerFn) ?? s.centerFn, s.priority = (t == null ? void 0 : t.priority) ?? s.priority, this.htmlController.updateNodeCoordinates(e), this.htmlController.updateNodePriority(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((i) => {
870
- this.htmlController.updateEdge(i);
871
- });
696
+ getEdge(e) {
697
+ return this.edges.get(e);
872
698
  }
873
699
  removeEdge(e) {
874
- if (this.graphStore.getEdge(e) === void 0)
875
- throw new f("failed to remove nonexisting edge");
876
- this.htmlController.detachEdge(e), this.graphStore.removeEdge(e);
700
+ const t = this.edges.get(e), s = t.from, n = t.to;
701
+ this.cycleEdges.get(s).delete(e), this.cycleEdges.get(n).delete(e), this.incommingEdges.get(s).delete(e), this.incommingEdges.get(n).delete(e), this.outcommingEdges.get(s).delete(e), this.outcommingEdges.get(n).delete(e), this.edges.delete(e);
877
702
  }
878
- unmarkPort(e) {
879
- if (this.graphStore.getPort(e) === void 0)
880
- throw new f("failed to unset nonexisting port");
881
- this.graphStore.getPortAdjacentEdgeIds(e).forEach((t) => {
882
- this.removeEdge(t);
883
- }), this.graphStore.removePort(e);
703
+ clear() {
704
+ this.nodes.clear(), this.ports.clear(), this.nodePorts.clear(), this.portNodeId.clear(), this.edges.clear(), this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear();
884
705
  }
885
- removeNode(e) {
886
- if (this.graphStore.getNode(e) === void 0)
887
- throw new f("failed to remove nonexisting node");
888
- this.graphStore.getNodePortIds(e).forEach((t) => {
889
- this.unmarkPort(t);
890
- }), this.htmlController.detachNode(e), this.graphStore.removeNode(e);
706
+ getPortIncomingEdgeIds(e) {
707
+ return Array.from(this.incommingEdges.get(e));
708
+ }
709
+ getPortOutcomingEdgeIds(e) {
710
+ return Array.from(this.outcommingEdges.get(e));
711
+ }
712
+ getPortCycleEdgeIds(e) {
713
+ return Array.from(this.cycleEdges.get(e));
714
+ }
715
+ getPortAdjacentEdgeIds(e) {
716
+ return [
717
+ ...this.getPortIncomingEdgeIds(e),
718
+ ...this.getPortOutcomingEdgeIds(e),
719
+ ...this.getPortCycleEdgeIds(e)
720
+ ];
721
+ }
722
+ getNodeIncomingEdgeIds(e) {
723
+ const t = Array.from(this.nodePorts.get(e).keys());
724
+ let s = [];
725
+ return t.forEach((n) => {
726
+ s = [...s, ...this.getPortIncomingEdgeIds(n)];
727
+ }), s;
728
+ }
729
+ getNodeOutcomingEdgeIds(e) {
730
+ const t = Array.from(this.nodePorts.get(e).keys());
731
+ let s = [];
732
+ return t.forEach((n) => {
733
+ s = [...s, ...this.getPortOutcomingEdgeIds(n)];
734
+ }), s;
735
+ }
736
+ getNodeCycleEdgeIds(e) {
737
+ const t = Array.from(this.nodePorts.get(e).keys());
738
+ let s = [];
739
+ return t.forEach((n) => {
740
+ s = [...s, ...this.getPortCycleEdgeIds(n)];
741
+ }), s;
742
+ }
743
+ getNodeAdjacentEdgeIds(e) {
744
+ return [
745
+ ...this.getNodeIncomingEdgeIds(e),
746
+ ...this.getNodeOutcomingEdgeIds(e),
747
+ ...this.getNodeCycleEdgeIds(e)
748
+ ];
749
+ }
750
+ }
751
+ class le {
752
+ constructor(e) {
753
+ this.graphStore = e;
754
+ }
755
+ getNode(e) {
756
+ const t = this.graphStore.getNode(e);
757
+ return t === void 0 ? null : {
758
+ element: t.element,
759
+ x: t.x,
760
+ y: t.y,
761
+ centerFn: t.centerFn,
762
+ priority: t.priority
763
+ };
764
+ }
765
+ getAllNodeIds() {
766
+ return this.graphStore.getAllNodeIds();
767
+ }
768
+ getPort(e) {
769
+ const t = this.graphStore.getPort(e);
770
+ return t === void 0 ? null : {
771
+ element: t.element,
772
+ centerFn: t.centerFn,
773
+ direction: t.direction
774
+ };
775
+ }
776
+ getAllPortIds() {
777
+ return this.graphStore.getAllPortIds();
778
+ }
779
+ getNodePortIds(e) {
780
+ return this.graphStore.getNodePortIds(e);
781
+ }
782
+ getPortNodeId(e) {
783
+ return this.graphStore.getPortNodeId(e) ?? null;
784
+ }
785
+ getAllEdgeIds() {
786
+ return this.graphStore.getAllEdgeIds();
787
+ }
788
+ getEdge(e) {
789
+ const t = this.graphStore.getEdge(e);
790
+ return t === void 0 ? null : { from: t.from, to: t.to, priority: t.priority };
791
+ }
792
+ getPortIncomingEdgeIds(e) {
793
+ return this.graphStore.getPortIncomingEdgeIds(e);
794
+ }
795
+ getPortOutcomingEdgeIds(e) {
796
+ return this.graphStore.getPortOutcomingEdgeIds(e);
797
+ }
798
+ getPortCycleEdgeIds(e) {
799
+ return this.graphStore.getPortCycleEdgeIds(e);
800
+ }
801
+ getPortAdjacentEdgeIds(e) {
802
+ return this.graphStore.getPortAdjacentEdgeIds(e);
803
+ }
804
+ getNodeIncomingEdgeIds(e) {
805
+ return this.graphStore.getNodeIncomingEdgeIds(e);
806
+ }
807
+ getNodeOutcomingEdgeIds(e) {
808
+ return this.graphStore.getNodeOutcomingEdgeIds(e);
809
+ }
810
+ getNodeCycleEdgeIds(e) {
811
+ return this.graphStore.getNodeCycleEdgeIds(e);
812
+ }
813
+ getNodeAdjacentEdgeIds(e) {
814
+ return this.graphStore.getNodeAdjacentEdgeIds(e);
815
+ }
816
+ }
817
+ const K = (r) => ({
818
+ scale: 1 / r.scale,
819
+ dx: -r.dx / r.scale,
820
+ dy: -r.dy / r.scale
821
+ }), _ = {
822
+ scale: 1,
823
+ dx: 0,
824
+ dy: 0
825
+ };
826
+ class ge {
827
+ constructor() {
828
+ a(this, "viewportMatrix", _);
829
+ a(this, "contentMatrix", _);
830
+ }
831
+ getViewportMatrix() {
832
+ return this.viewportMatrix;
833
+ }
834
+ getContentMatrix() {
835
+ return this.contentMatrix;
891
836
  }
892
837
  patchViewportMatrix(e) {
893
- this.viewportTransformer.patchViewportMatrix(e), this.htmlController.applyTransform();
838
+ this.viewportMatrix = {
839
+ scale: e.scale ?? this.viewportMatrix.scale,
840
+ dx: e.dx ?? this.viewportMatrix.dx,
841
+ dy: e.dy ?? this.viewportMatrix.dy
842
+ }, this.contentMatrix = K(this.viewportMatrix);
894
843
  }
895
844
  patchContentMatrix(e) {
896
- this.viewportTransformer.patchContentMatrix(e), this.htmlController.applyTransform();
845
+ this.contentMatrix = {
846
+ scale: e.scale ?? this.contentMatrix.scale,
847
+ dx: e.dx ?? this.contentMatrix.dx,
848
+ dy: e.dy ?? this.contentMatrix.dy
849
+ }, this.viewportMatrix = K(this.contentMatrix);
897
850
  }
898
- clear() {
899
- this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset();
851
+ }
852
+ class ue {
853
+ constructor(e) {
854
+ this.transformer = e;
900
855
  }
901
- destroy() {
902
- this.clear(), this.htmlController.destroy();
856
+ getViewportMatrix() {
857
+ return { ...this.transformer.getViewportMatrix() };
903
858
  }
904
- resolveEdgeType(e, t) {
905
- if (e === t)
906
- return C.PortCycle;
907
- const s = this.graphStore.getPortNodeId(e), o = this.graphStore.getPortNodeId(t);
908
- return s === o ? C.NodeCycle : C.Regular;
859
+ getContentMatrix() {
860
+ return { ...this.transformer.getContentMatrix() };
909
861
  }
910
862
  }
911
- const ge = () => {
863
+ const we = () => {
912
864
  const r = document.createElement("div");
913
865
  return r.style.width = "100%", r.style.height = "100%", r.style.position = "relative", r.style.overflow = "hidden", r;
914
- }, ue = () => {
866
+ }, ye = () => {
915
867
  const r = document.createElement("div");
916
868
  return r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.width = "0", r.style.height = "0", r;
917
- }, we = () => {
869
+ }, me = () => {
918
870
  const r = document.createElement("div");
919
871
  return r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.visibility = "hidden", r;
920
872
  };
921
- class ye {
873
+ class ve {
922
874
  constructor(e, t) {
923
- n(this, "canvasWrapper", null);
924
- n(this, "host", ge());
925
- n(this, "container", ue());
926
- n(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
927
- n(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
875
+ a(this, "canvasWrapper", null);
876
+ a(this, "host", we());
877
+ a(this, "container", ye());
878
+ a(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
879
+ a(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
928
880
  this.graphStore = e, this.viewportTransformer = t, this.host.appendChild(this.container);
929
881
  }
930
882
  attach(e) {
@@ -938,7 +890,7 @@ class ye {
938
890
  this.container.style.transform = `matrix(${e.scale}, 0, 0, ${e.scale}, ${e.dx}, ${e.dy})`;
939
891
  }
940
892
  attachNode(e) {
941
- const t = this.graphStore.getNode(e), s = we();
893
+ const t = this.graphStore.getNode(e), s = me();
942
894
  s.appendChild(t.element), this.container.appendChild(s), this.nodeIdToWrapperElementMap.set(e, s), this.updateNodeCoordinates(e), this.updateNodePriority(e), s.style.visibility = "visible";
943
895
  }
944
896
  detachNode(e) {
@@ -964,7 +916,7 @@ class ye {
964
916
  this.clear(), this.detach(), this.host.removeChild(this.container);
965
917
  }
966
918
  updateNodeCoordinates(e) {
967
- const t = this.nodeIdToWrapperElementMap.get(e), s = this.graphStore.getNode(e), { width: o, height: i } = s.element.getBoundingClientRect(), h = this.viewportTransformer.getViewportMatrix().scale, a = s.centerFn(o, i), d = s.x - h * a.x, c = s.y - h * a.y;
919
+ const t = this.nodeIdToWrapperElementMap.get(e), s = this.graphStore.getNode(e), { width: n, height: o } = s.element.getBoundingClientRect(), h = this.viewportTransformer.getViewportMatrix().scale, i = s.centerFn(n, o), d = s.x - h * i.x, c = s.y - h * i.y;
968
920
  t.style.transform = `translate(${d}px, ${c}px)`;
969
921
  }
970
922
  updateNodePriority(e) {
@@ -978,33 +930,33 @@ class ye {
978
930
  this.edgeIdToElementMap.set(e, s.shape.svg), this.container.appendChild(s.shape.svg);
979
931
  }
980
932
  updateEdge(e) {
981
- const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from), o = this.graphStore.getPort(t.to), i = s.element.getBoundingClientRect(), h = o.element.getBoundingClientRect(), a = this.host.getBoundingClientRect(), d = this.viewportTransformer.getViewportMatrix(), c = {
982
- x: d.scale * (i.left - a.left) + d.dx,
983
- y: d.scale * (i.top - a.top) + d.dy
933
+ const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from), n = this.graphStore.getPort(t.to), o = s.element.getBoundingClientRect(), h = n.element.getBoundingClientRect(), i = this.host.getBoundingClientRect(), d = this.viewportTransformer.getViewportMatrix(), c = {
934
+ x: d.scale * (o.left - i.left) + d.dx,
935
+ y: d.scale * (o.top - i.top) + d.dy
984
936
  }, u = {
985
- x: d.scale * (h.left - a.left) + d.dx,
986
- y: d.scale * (h.top - a.top) + d.dy
937
+ x: d.scale * (h.left - i.left) + d.dx,
938
+ y: d.scale * (h.top - i.top) + d.dy
987
939
  }, w = s.centerFn(
988
- i.width * d.scale,
989
- i.height * d.scale
990
- ), m = o.centerFn(
940
+ o.width * d.scale,
941
+ o.height * d.scale
942
+ ), m = n.centerFn(
991
943
  h.width * d.scale,
992
944
  h.height * d.scale
993
945
  ), y = {
994
946
  x: c.x + w.x,
995
947
  y: c.y + w.y
996
- }, v = {
948
+ }, p = {
997
949
  x: u.x + m.x,
998
950
  y: u.y + m.y
999
- }, P = Math.min(y.x, v.x), S = Math.min(y.y, v.y), M = Math.abs(v.x - y.x), b = Math.abs(v.y - y.y);
1000
- t.shape.svg.style.width = `${M}px`, t.shape.svg.style.height = `${b}px`, t.shape.svg.style.transform = `translate(${P}px, ${S}px)`;
1001
- const T = y.x <= v.x ? 1 : -1, F = y.y <= v.y ? 1 : -1;
951
+ }, M = Math.min(y.x, p.x), P = Math.min(y.y, p.y), S = Math.abs(p.x - y.x), b = Math.abs(p.y - y.y);
952
+ t.shape.svg.style.width = `${S}px`, t.shape.svg.style.height = `${b}px`, t.shape.svg.style.transform = `translate(${M}px, ${P}px)`;
953
+ const L = y.x <= p.x ? 1 : -1, F = y.y <= p.y ? 1 : -1;
1002
954
  t.shape.update(
1003
- { x: M, y: b },
1004
- T,
955
+ { x: S, y: b },
956
+ L,
1005
957
  F,
1006
958
  s.direction,
1007
- o.direction
959
+ n.direction
1008
960
  );
1009
961
  }
1010
962
  updateEdgePriority(e) {
@@ -1012,217 +964,203 @@ class ye {
1012
964
  t.shape.svg.style.zIndex = `${t.priority}`;
1013
965
  }
1014
966
  }
1015
- class me {
967
+ class $ {
1016
968
  constructor(e) {
1017
- n(this, "publicViewportTransformer");
1018
- n(this, "publicGraphStore");
1019
- n(this, "canvasController");
1020
- const t = new Q(), s = new q();
1021
- this.publicGraphStore = new ee(s), this.publicViewportTransformer = new Z(
1022
- t
1023
- );
1024
- const o = new ye(s, t);
1025
- this.canvasController = new le(
1026
- s,
1027
- o,
1028
- t,
1029
- e.nodesCenterFn,
1030
- e.portsCenterFn,
1031
- e.portsDirection,
1032
- e.nodesPriorityFn,
1033
- e.edgesPriorityFn
1034
- );
969
+ a(this, "counter", 0);
970
+ this.checkExists = e;
971
+ }
972
+ create(e) {
973
+ if (e !== void 0)
974
+ return e;
975
+ for (; this.checkExists(this.counter); )
976
+ this.counter++;
977
+ return this.counter;
978
+ }
979
+ reset() {
980
+ this.counter = 0;
1035
981
  }
1036
982
  }
1037
- const H = (r, e) => ({
1038
- x: r / 2,
1039
- y: e / 2
1040
- }), g = {
1041
- edgeColor: "#5c5c5c",
1042
- edgeWidth: 1,
1043
- edgeArrowLength: 15,
1044
- edgeArrowWidth: 4,
1045
- edgeArrowOffset: 15,
1046
- hasSourceArrow: !1,
1047
- hasTargetArrow: !1,
1048
- cycleSize: 30,
1049
- roundness: 10,
1050
- detourDistance: 100,
1051
- detourDirection: -Math.PI / 2,
1052
- smallCycleSize: 15,
1053
- curvature: 90
1054
- }, R = (r) => {
1055
- switch (r == null ? void 0 : r.type) {
1056
- case "custom":
1057
- return r.factory;
1058
- case "straight":
1059
- return he({
1060
- color: r.color ?? g.edgeColor,
1061
- width: r.width ?? g.edgeWidth,
1062
- arrowLength: r.arrowLength ?? g.edgeArrowLength,
1063
- arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
1064
- arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
1065
- hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
1066
- hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
1067
- cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
1068
- roundness: r.roundness ?? g.roundness,
1069
- detourDistance: r.detourDistance ?? g.detourDistance,
1070
- detourDirection: r.detourDirection ?? g.detourDirection
1071
- });
1072
- case "horizontal":
1073
- return ce({
1074
- color: r.color ?? g.edgeColor,
1075
- width: r.width ?? g.edgeWidth,
1076
- arrowLength: r.arrowLength ?? g.edgeArrowLength,
1077
- arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
1078
- arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
1079
- hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
1080
- hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
1081
- cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
1082
- roundness: r.roundness ?? g.roundness,
1083
- detourDistance: r.detourDistance ?? g.detourDistance,
1084
- detourDirection: r.detourDirection ?? g.detourDirection
1085
- });
1086
- case "vertical":
1087
- return de({
1088
- color: r.color ?? g.edgeColor,
1089
- width: r.width ?? g.edgeWidth,
1090
- arrowLength: r.arrowLength ?? g.edgeArrowLength,
1091
- arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
1092
- arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
1093
- hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
1094
- hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
1095
- cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
1096
- roundness: r.roundness ?? g.roundness,
1097
- detourDistance: r.detourDistance ?? g.detourDistance,
1098
- detourDirection: r.detourDirection ?? g.detourDirection
1099
- });
1100
- default:
1101
- return ae({
1102
- color: r.color ?? g.edgeColor,
1103
- width: r.width ?? g.edgeWidth,
1104
- arrowLength: r.arrowLength ?? g.edgeArrowLength,
1105
- arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
1106
- hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
1107
- hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
1108
- cycleRadius: r.cycleRadius ?? g.cycleSize,
1109
- detourDistance: r.detourDistance ?? g.detourDistance,
1110
- detourDirection: r.detourDirection ?? g.detourDirection,
1111
- smallCycleRadius: r.smallCycleRadius ?? g.smallCycleSize,
1112
- curvature: r.curvature ?? g.curvature
983
+ class A extends Error {
984
+ constructor() {
985
+ super(...arguments);
986
+ a(this, "name", "HtmlGraphError");
987
+ }
988
+ }
989
+ class pe {
990
+ constructor(e, t, s, n, o, h, i, d) {
991
+ a(this, "nodeIdGenerator", new $(
992
+ (e) => this.graphStore.getNode(e) !== void 0
993
+ ));
994
+ a(this, "portIdGenerator", new $(
995
+ (e) => this.graphStore.getPort(e) !== void 0
996
+ ));
997
+ a(this, "edgeIdGenerator", new $(
998
+ (e) => this.graphStore.getEdge(e) !== void 0
999
+ ));
1000
+ this.graphStore = e, this.htmlController = t, this.viewportTransformer = s, this.defaultNodesCenterFn = n, this.defaultPortsCenterFn = o, this.defaultPortsDirection = h, this.defaultNodesPriorityFn = i, this.defaultEdgesPriorityFn = d;
1001
+ }
1002
+ attach(e) {
1003
+ this.htmlController.attach(e);
1004
+ }
1005
+ detach() {
1006
+ this.htmlController.detach();
1007
+ }
1008
+ addNode(e) {
1009
+ const t = this.nodeIdGenerator.create(e.nodeId);
1010
+ if (this.graphStore.getNode(t) !== void 0)
1011
+ throw new A("failed to add node with existing id");
1012
+ this.graphStore.addNode({
1013
+ nodeId: t,
1014
+ element: e.element,
1015
+ x: e.x,
1016
+ y: e.y,
1017
+ centerFn: e.centerFn ?? this.defaultNodesCenterFn,
1018
+ priority: e.priority ?? this.defaultNodesPriorityFn()
1019
+ }), this.htmlController.attachNode(t), Array.from(e.ports ?? []).forEach((s) => {
1020
+ this.markPort({
1021
+ portId: s.id,
1022
+ element: s.element,
1023
+ nodeId: t,
1024
+ centerFn: s.centerFn,
1025
+ direction: s.direction
1113
1026
  });
1027
+ });
1114
1028
  }
1115
- }, z = (r) => () => r, U = z(0), k = () => {
1116
- let r = 0;
1117
- return () => r++;
1118
- }, pe = (r, e) => {
1119
- const t = [
1120
- U,
1121
- U
1122
- ];
1123
- r === "incremental" && (t[0] = k()), e === "incremental" && (t[1] = k());
1124
- const s = k();
1125
- return r === "shared-incremental" && (t[0] = s), e === "shared-incremental" && (t[1] = s), typeof r == "number" && (t[0] = z(r)), typeof e == "number" && (t[1] = z(e)), typeof r == "function" && (t[0] = r), typeof e == "function" && (t[1] = e), t;
1126
- }, ve = (r) => {
1127
- var s, o, i, h, a, d;
1128
- const [e, t] = pe(
1129
- (s = r.nodes) == null ? void 0 : s.priority,
1130
- (o = r.edges) == null ? void 0 : o.priority
1131
- );
1132
- return {
1133
- nodes: {
1134
- centerFn: ((i = r.nodes) == null ? void 0 : i.centerFn) ?? H,
1135
- priorityFn: e
1136
- },
1137
- ports: {
1138
- centerFn: ((h = r.ports) == null ? void 0 : h.centerFn) ?? H,
1139
- direction: ((a = r.ports) == null ? void 0 : a.direction) ?? 0
1140
- },
1141
- edges: {
1142
- shapeFactory: R(((d = r.edges) == null ? void 0 : d.shape) ?? {}),
1143
- priorityFn: t
1144
- }
1145
- };
1146
- };
1147
- class fe {
1148
- constructor() {
1149
- n(this, "keyMap", /* @__PURE__ */ new Map());
1150
- n(this, "valueMap", /* @__PURE__ */ new Map());
1029
+ markPort(e) {
1030
+ const t = this.portIdGenerator.create(e.portId);
1031
+ if (this.graphStore.getPort(t) !== void 0)
1032
+ throw new A("failed to add port with existing id");
1033
+ if (this.graphStore.getNode(e.nodeId) === void 0)
1034
+ throw new A("failed to set port on nonexisting node");
1035
+ this.graphStore.addPort({
1036
+ portId: t,
1037
+ element: e.element,
1038
+ nodeId: e.nodeId,
1039
+ centerFn: e.centerFn ?? this.defaultPortsCenterFn,
1040
+ direction: e.direction ?? this.defaultPortsDirection
1041
+ });
1042
+ }
1043
+ addEdge(e) {
1044
+ const t = this.edgeIdGenerator.create(e.edgeId);
1045
+ if (this.graphStore.getEdge(t) !== void 0)
1046
+ throw new A("failed to add edge with existing id");
1047
+ if (this.graphStore.getPort(e.from) === void 0)
1048
+ throw new A("failed to add edge from nonexisting port");
1049
+ if (this.graphStore.getPort(e.to) === void 0)
1050
+ throw new A("failed to add edge to nonexisting port");
1051
+ const s = this.resolveEdgeType(e.from, e.to);
1052
+ this.graphStore.addEdge({
1053
+ edgeId: t,
1054
+ from: e.from,
1055
+ to: e.to,
1056
+ shape: e.shapeFactory(s),
1057
+ priority: e.priority ?? this.defaultEdgesPriorityFn()
1058
+ }), this.htmlController.attachEdge(t);
1151
1059
  }
1152
- set(e, t) {
1153
- this.keyMap.set(e, t), this.valueMap.set(t, e);
1060
+ updateEdge(e) {
1061
+ const t = this.graphStore.getEdge(e.edgeId);
1062
+ if (t === void 0)
1063
+ throw new A("failed to update nonexisting edge");
1064
+ if (e.shape !== void 0) {
1065
+ const s = this.resolveEdgeType(t.from, t.to);
1066
+ t.shape = e.shape(s), this.htmlController.updateEdgeShape(e.edgeId);
1067
+ }
1068
+ e.priority !== void 0 && (t.priority = e.priority, this.htmlController.updateEdgePriority(e.edgeId)), this.htmlController.updateEdge(e.edgeId);
1154
1069
  }
1155
- hasKey(e) {
1156
- return this.keyMap.has(e);
1070
+ updatePort(e, t) {
1071
+ const s = this.graphStore.getPort(e);
1072
+ if (s === void 0)
1073
+ throw new A("failed to unset nonexisting port");
1074
+ s.direction = t.direction ?? s.direction, s.centerFn = t.centerFn ?? s.centerFn, this.graphStore.getPortAdjacentEdgeIds(e).forEach((o) => {
1075
+ this.htmlController.updateEdge(o);
1076
+ });
1157
1077
  }
1158
- hasValue(e) {
1159
- return this.valueMap.has(e);
1078
+ updateNode(e, t) {
1079
+ const s = this.graphStore.getNode(e);
1080
+ if (s === void 0)
1081
+ throw new A("failed to update nonexisting node");
1082
+ s.x = (t == null ? void 0 : t.x) ?? s.x, s.y = (t == null ? void 0 : t.y) ?? s.y, s.centerFn = (t == null ? void 0 : t.centerFn) ?? s.centerFn, s.priority = (t == null ? void 0 : t.priority) ?? s.priority, this.htmlController.updateNodeCoordinates(e), this.htmlController.updateNodePriority(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((o) => {
1083
+ this.htmlController.updateEdge(o);
1084
+ });
1160
1085
  }
1161
- getByKey(e) {
1162
- return this.keyMap.get(e);
1086
+ removeEdge(e) {
1087
+ if (this.graphStore.getEdge(e) === void 0)
1088
+ throw new A("failed to remove nonexisting edge");
1089
+ this.htmlController.detachEdge(e), this.graphStore.removeEdge(e);
1163
1090
  }
1164
- getByValue(e) {
1165
- return this.valueMap.get(e);
1091
+ unmarkPort(e) {
1092
+ if (this.graphStore.getPort(e) === void 0)
1093
+ throw new A("failed to unset nonexisting port");
1094
+ this.graphStore.getPortAdjacentEdgeIds(e).forEach((t) => {
1095
+ this.removeEdge(t);
1096
+ }), this.graphStore.removePort(e);
1166
1097
  }
1167
- deleteByKey(e) {
1168
- const t = this.keyMap.get(e);
1169
- t !== void 0 && this.valueMap.delete(t), this.keyMap.delete(e);
1098
+ removeNode(e) {
1099
+ if (this.graphStore.getNode(e) === void 0)
1100
+ throw new A("failed to remove nonexisting node");
1101
+ this.graphStore.getNodePortIds(e).forEach((t) => {
1102
+ this.unmarkPort(t);
1103
+ }), this.htmlController.detachNode(e), this.graphStore.removeNode(e);
1170
1104
  }
1171
- deleteByValue(e) {
1172
- const t = this.valueMap.get(e);
1173
- t !== void 0 && this.keyMap.delete(t), this.valueMap.delete(e);
1105
+ patchViewportMatrix(e) {
1106
+ this.viewportTransformer.patchViewportMatrix(e), this.htmlController.applyTransform();
1174
1107
  }
1175
- forEach(e) {
1176
- this.keyMap.forEach((t, s) => {
1177
- e(t, s);
1178
- });
1108
+ patchContentMatrix(e) {
1109
+ this.viewportTransformer.patchContentMatrix(e), this.htmlController.applyTransform();
1179
1110
  }
1180
1111
  clear() {
1181
- this.keyMap.clear(), this.valueMap.clear();
1112
+ this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset();
1113
+ }
1114
+ destroy() {
1115
+ this.clear(), this.htmlController.destroy();
1116
+ }
1117
+ resolveEdgeType(e, t) {
1118
+ if (e === t)
1119
+ return C.PortCycle;
1120
+ const s = this.graphStore.getPortNodeId(e), n = this.graphStore.getPortNodeId(t);
1121
+ return s === n ? C.NodeCycle : C.Regular;
1182
1122
  }
1183
1123
  }
1184
1124
  class xe {
1185
1125
  constructor(e) {
1186
- n(this, "transformation");
1187
- n(this, "model");
1188
- n(this, "di");
1189
- n(this, "edgeShapeFactory");
1190
- n(this, "nodes", new fe());
1191
- n(this, "nodeIdGenerator", new I(
1192
- (e) => this.nodes.hasKey(e)
1193
- ));
1194
- n(this, "nodesResizeObserver");
1195
- this.apiOptions = e, this.nodesResizeObserver = new window.ResizeObserver((s) => {
1196
- s.forEach((o) => {
1197
- const i = o.target, h = this.nodes.getByValue(i);
1198
- this.updateNode(h), this.model.getNodeAdjacentEdgeIds(h).forEach((d) => {
1199
- this.updateEdge(d);
1200
- });
1201
- });
1202
- });
1203
- const t = ve(this.apiOptions ?? {});
1204
- this.di = new me({
1205
- nodesCenterFn: t.nodes.centerFn,
1206
- nodesPriorityFn: t.nodes.priorityFn,
1207
- portsCenterFn: t.ports.centerFn,
1208
- portsDirection: t.ports.direction,
1209
- edgesPriorityFn: t.edges.priorityFn
1210
- }), this.transformation = this.di.publicViewportTransformer, this.model = this.di.publicGraphStore, this.edgeShapeFactory = t.edges.shapeFactory;
1126
+ a(this, "transformation");
1127
+ a(this, "model");
1128
+ a(this, "canvasController");
1129
+ a(this, "edgeShapeFactory");
1130
+ this.apiOptions = e;
1131
+ const t = de(this.apiOptions), s = new ge(), n = new ce();
1132
+ this.model = new le(n), this.transformation = new ue(s);
1133
+ const o = new ve(n, s);
1134
+ this.canvasController = new pe(
1135
+ n,
1136
+ o,
1137
+ s,
1138
+ t.nodes.centerFn,
1139
+ t.ports.centerFn,
1140
+ t.ports.direction,
1141
+ t.nodes.priorityFn,
1142
+ t.edges.priorityFn
1143
+ ), this.edgeShapeFactory = t.edges.shapeFactory;
1144
+ }
1145
+ attach(e) {
1146
+ return this.canvasController.attach(e), this;
1147
+ }
1148
+ detach() {
1149
+ return this.canvasController.detach(), this;
1211
1150
  }
1212
1151
  addNode(e) {
1213
- const t = this.nodeIdGenerator.create(e.id);
1214
- return this.di.canvasController.addNode({
1215
- nodeId: t,
1152
+ return this.canvasController.addNode({
1153
+ nodeId: e.id,
1216
1154
  element: e.element,
1217
1155
  x: e.x,
1218
1156
  y: e.y,
1219
1157
  ports: e.ports,
1220
1158
  centerFn: e.centerFn,
1221
1159
  priority: e.priority
1222
- }), this.nodes.set(t, e.element), this.nodesResizeObserver.observe(e.element), this;
1160
+ }), this;
1223
1161
  }
1224
1162
  updateNode(e, t) {
1225
- return this.di.canvasController.updateNode(e, {
1163
+ return this.canvasController.updateNode(e, {
1226
1164
  x: t == null ? void 0 : t.x,
1227
1165
  y: t == null ? void 0 : t.y,
1228
1166
  priority: t == null ? void 0 : t.priority,
@@ -1230,33 +1168,11 @@ class xe {
1230
1168
  }), this;
1231
1169
  }
1232
1170
  removeNode(e) {
1233
- this.di.canvasController.removeNode(e);
1234
- const t = this.nodes.getByKey(e);
1235
- if (this.nodes.deleteByKey(e), t === void 0)
1236
- throw new f("failed to remove non existing node");
1237
- return this.nodesResizeObserver.unobserve(t), this;
1238
- }
1239
- markPort(e) {
1240
- return this.di.canvasController.markPort({
1241
- portId: e.id,
1242
- element: e.element,
1243
- nodeId: e.nodeId,
1244
- centerFn: e.centerFn,
1245
- direction: e.direction
1246
- }), this;
1247
- }
1248
- updatePort(e, t) {
1249
- return this.di.canvasController.updatePort(e, {
1250
- direction: t == null ? void 0 : t.direction,
1251
- centerFn: t == null ? void 0 : t.centerFn
1252
- }), this;
1253
- }
1254
- unmarkPort(e) {
1255
- return this.di.canvasController.unmarkPort(e), this;
1171
+ return this.canvasController.removeNode(e), this;
1256
1172
  }
1257
1173
  addEdge(e) {
1258
- const t = e.shape !== void 0 ? R(e.shape) : this.edgeShapeFactory;
1259
- return this.di.canvasController.addEdge({
1174
+ const t = e.shape !== void 0 ? B(e.shape) : this.edgeShapeFactory;
1175
+ return this.canvasController.addEdge({
1260
1176
  edgeId: e.id,
1261
1177
  from: e.from,
1262
1178
  to: e.to,
@@ -1265,110 +1181,117 @@ class xe {
1265
1181
  }), this;
1266
1182
  }
1267
1183
  updateEdge(e, t) {
1268
- const s = (t == null ? void 0 : t.shape) !== void 0 ? R(t.shape) : void 0;
1269
- return this.di.canvasController.updateEdge({
1184
+ const s = (t == null ? void 0 : t.shape) !== void 0 ? B(t.shape) : void 0;
1185
+ return this.canvasController.updateEdge({
1270
1186
  edgeId: e,
1271
1187
  shape: s,
1272
1188
  priority: t == null ? void 0 : t.priority
1273
1189
  }), this;
1274
1190
  }
1275
1191
  removeEdge(e) {
1276
- return this.di.canvasController.removeEdge(e), this;
1192
+ return this.canvasController.removeEdge(e), this;
1193
+ }
1194
+ markPort(e) {
1195
+ return this.canvasController.markPort({
1196
+ portId: e.id,
1197
+ element: e.element,
1198
+ nodeId: e.nodeId,
1199
+ centerFn: e.centerFn,
1200
+ direction: e.direction
1201
+ }), this;
1202
+ }
1203
+ updatePortMark(e, t) {
1204
+ return this.canvasController.updatePort(e, {
1205
+ direction: t == null ? void 0 : t.direction,
1206
+ centerFn: t == null ? void 0 : t.centerFn
1207
+ }), this;
1208
+ }
1209
+ unmarkPort(e) {
1210
+ return this.canvasController.unmarkPort(e), this;
1277
1211
  }
1278
1212
  patchViewportMatrix(e) {
1279
- return this.di.canvasController.patchViewportMatrix(e), this;
1213
+ return this.canvasController.patchViewportMatrix(e), this;
1280
1214
  }
1281
1215
  patchContentMatrix(e) {
1282
- return this.di.canvasController.patchContentMatrix(e), this;
1216
+ return this.canvasController.patchContentMatrix(e), this;
1283
1217
  }
1284
1218
  clear() {
1285
- return this.di.canvasController.clear(), this.nodes.clear(), this;
1286
- }
1287
- attach(e) {
1288
- return this.di.canvasController.attach(e), this;
1289
- }
1290
- detach() {
1291
- return this.di.canvasController.detach(), this;
1219
+ return this.canvasController.clear(), this;
1292
1220
  }
1293
1221
  destroy() {
1294
- this.clear(), this.di.canvasController.destroy(), this.nodesResizeObserver.disconnect();
1222
+ this.clear(), this.canvasController.destroy();
1295
1223
  }
1296
1224
  }
1297
- const W = (r, e, t) => {
1298
- const { x: s, y: o, width: i, height: h } = r.getBoundingClientRect();
1299
- return e >= s && e < s + i && t >= o && t <= o + h;
1300
- }, V = (r, e, t) => e >= 0 && e < r.innerWidth && t >= 0 && t <= r.innerHeight, O = (r, e) => {
1225
+ const D = (r, e, t) => {
1226
+ const { x: s, y: n, width: o, height: h } = r.getBoundingClientRect();
1227
+ return e >= s && e <= s + o && t >= n && t <= n + h;
1228
+ }, k = (r, e, t) => e >= 0 && e <= r.innerWidth && t >= 0 && t <= r.innerHeight, V = (r, e) => {
1301
1229
  e !== null ? r.style.cursor = e : r.style.removeProperty("cursor");
1302
1230
  };
1303
- class Ee {
1231
+ class fe {
1304
1232
  constructor(e, t) {
1305
- n(this, "model");
1306
- n(this, "transformation");
1307
- n(this, "maxNodePriority", 0);
1308
- n(this, "nodes", /* @__PURE__ */ new Map());
1309
- n(this, "grabbedNodeId", null);
1310
- n(this, "onNodeDrag");
1311
- n(this, "onBeforeNodeDrag");
1312
- n(this, "nodeIdGenerator", new I(
1233
+ a(this, "model");
1234
+ a(this, "transformation");
1235
+ a(this, "maxNodePriority", 0);
1236
+ a(this, "nodes", /* @__PURE__ */ new Map());
1237
+ a(this, "grabbedNodeId", null);
1238
+ a(this, "onNodeDrag");
1239
+ a(this, "onBeforeNodeDrag");
1240
+ a(this, "nodeIdGenerator", new $(
1313
1241
  (e) => this.nodes.has(e)
1314
1242
  ));
1315
- n(this, "element", null);
1316
- n(this, "onCanvasMouseUp", () => {
1317
- this.cancelMouseDrag();
1318
- });
1319
- n(this, "onCanvasMouseMove", (e) => {
1320
- if (this.element !== null && (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY))) {
1243
+ a(this, "element", null);
1244
+ a(this, "onWindowMouseMove", (e) => {
1245
+ if (this.element !== null && (!D(this.element, e.clientX, e.clientY) || !k(this.window, e.clientX, e.clientY))) {
1321
1246
  this.cancelMouseDrag();
1322
1247
  return;
1323
1248
  }
1324
1249
  this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
1325
1250
  });
1326
- n(this, "onCanvasTouchStart", (e) => {
1327
- this.previousTouchCoords = [
1328
- e.touches[0].clientX,
1329
- e.touches[0].clientY
1330
- ];
1251
+ a(this, "onWindowMouseUp", (e) => {
1252
+ e.button === 0 && this.cancelMouseDrag();
1331
1253
  });
1332
- n(this, "onCanvasTouchMove", (e) => {
1333
- if (e.touches.length === 1) {
1334
- const t = e.touches[0];
1335
- if (this.element !== null && (!W(this.element, t.clientX, t.clientY) || !V(this.window, t.clientX, t.clientY))) {
1336
- this.cancelTouchDrag();
1337
- return;
1338
- }
1339
- if (this.grabbedNodeId !== null && this.previousTouchCoords !== null) {
1340
- e.stopImmediatePropagation();
1341
- const s = t.clientX - this.previousTouchCoords[0], o = t.clientY - this.previousTouchCoords[1];
1342
- this.dragNode(this.grabbedNodeId, s, o), this.previousTouchCoords = [
1343
- e.touches[0].clientX,
1344
- e.touches[0].clientY
1345
- ];
1346
- }
1254
+ a(this, "onWindowTouchMove", (e) => {
1255
+ if (e.touches.length !== 1)
1256
+ return;
1257
+ const t = e.touches[0];
1258
+ if (this.element !== null && (!D(this.element, t.clientX, t.clientY) || !k(this.window, t.clientX, t.clientY))) {
1259
+ this.cancelTouchDrag();
1260
+ return;
1261
+ }
1262
+ if (this.grabbedNodeId !== null && this.previousTouchCoords !== null) {
1263
+ const s = t.clientX - this.previousTouchCoords.x, n = t.clientY - this.previousTouchCoords.y;
1264
+ this.dragNode(this.grabbedNodeId, s, n), this.previousTouchCoords = {
1265
+ x: e.touches[0].clientX,
1266
+ y: e.touches[0].clientY
1267
+ };
1347
1268
  }
1348
1269
  });
1349
- n(this, "onCanvasTouchEnd", (e) => {
1350
- e.touches.length > 0 ? this.previousTouchCoords = [
1351
- e.touches[0].clientX,
1352
- e.touches[0].clientY
1353
- ] : this.cancelTouchDrag();
1270
+ a(this, "onWindowTouchFinish", (e) => {
1271
+ e.touches.length > 0 ? this.previousTouchCoords = {
1272
+ x: e.touches[0].clientX,
1273
+ y: e.touches[0].clientY
1274
+ } : this.cancelTouchDrag();
1354
1275
  });
1355
- n(this, "previousTouchCoords", null);
1356
- n(this, "freezePriority");
1357
- n(this, "window", window);
1358
- n(this, "dragCursor");
1359
- var i, h;
1360
- this.canvas = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1361
- const s = () => {
1362
- };
1363
- this.onNodeDrag = ((i = t == null ? void 0 : t.events) == null ? void 0 : i.onNodeDrag) ?? s;
1364
- const o = () => !0;
1365
- this.onBeforeNodeDrag = ((h = t == null ? void 0 : t.events) == null ? void 0 : h.onBeforeNodeDrag) ?? o, this.freezePriority = (t == null ? void 0 : t.grabPriorityStrategy) === "freeze", this.dragCursor = (t == null ? void 0 : t.dragCursor) !== void 0 ? t.dragCursor : "grab";
1276
+ a(this, "previousTouchCoords", null);
1277
+ a(this, "freezePriority");
1278
+ a(this, "window", window);
1279
+ a(this, "dragCursor");
1280
+ var s, n;
1281
+ this.canvas = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.onNodeDrag = ((s = t == null ? void 0 : t.events) == null ? void 0 : s.onNodeDrag) ?? (() => {
1282
+ }), this.onBeforeNodeDrag = ((n = t == null ? void 0 : t.events) == null ? void 0 : n.onBeforeNodeDrag) ?? (() => !0), this.freezePriority = (t == null ? void 0 : t.moveOnTop) === !1, this.dragCursor = (t == null ? void 0 : t.dragCursor) !== void 0 ? t.dragCursor : "grab";
1283
+ }
1284
+ attach(e) {
1285
+ return this.detach(), this.element = e, this.canvas.attach(this.element), this;
1286
+ }
1287
+ detach() {
1288
+ return this.canvas.detach(), this.element !== null && (this.element = null), this;
1366
1289
  }
1367
1290
  addNode(e) {
1368
1291
  const t = this.nodeIdGenerator.create(e.id);
1369
1292
  this.canvas.addNode({ ...e, id: t }), this.updateMaxNodePriority(t);
1370
- const s = (i) => {
1371
- if (this.element === null)
1293
+ const s = (o) => {
1294
+ if (this.element === null || o.button !== 0)
1372
1295
  return;
1373
1296
  const h = this.model.getNode(t);
1374
1297
  this.onBeforeNodeDrag({
@@ -1376,34 +1299,38 @@ class Ee {
1376
1299
  element: e.element,
1377
1300
  x: h.x,
1378
1301
  y: h.y
1379
- }) && (i.stopImmediatePropagation(), this.grabbedNodeId = t, O(this.element, this.dragCursor), this.moveNodeOnTop(t), this.window.addEventListener("mouseup", this.onCanvasMouseUp), this.window.addEventListener("mousemove", this.onCanvasMouseMove));
1380
- }, o = (i) => {
1302
+ }) && (o.stopImmediatePropagation(), this.grabbedNodeId = t, V(this.element, this.dragCursor), this.moveNodeOnTop(t), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
1303
+ }, n = (o) => {
1304
+ o.stopImmediatePropagation(), this.previousTouchCoords = {
1305
+ x: o.touches[0].clientX,
1306
+ y: o.touches[0].clientY
1307
+ };
1381
1308
  const h = this.model.getNode(t);
1382
1309
  this.onBeforeNodeDrag({
1383
1310
  nodeId: t,
1384
1311
  element: e.element,
1385
1312
  x: h.x,
1386
1313
  y: h.y
1387
- }) && i.touches.length === 1 && (this.grabbedNodeId = t, this.moveNodeOnTop(t), this.window.addEventListener("touchmove", this.onCanvasTouchMove), this.window.addEventListener("touchend", this.onCanvasTouchEnd), this.window.addEventListener("touchcancel", this.onCanvasTouchEnd));
1314
+ }) && o.touches.length === 1 && (this.grabbedNodeId = t, this.moveNodeOnTop(t), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish));
1388
1315
  };
1389
1316
  return this.nodes.set(t, {
1390
1317
  element: e.element,
1391
1318
  onMouseDown: s,
1392
- onTouchStart: o
1393
- }), e.element.addEventListener("mousedown", s), e.element.addEventListener("touchstart", o), this;
1319
+ onTouchStart: n
1320
+ }), e.element.addEventListener("mousedown", s), e.element.addEventListener("touchstart", n), this;
1394
1321
  }
1395
1322
  updateNode(e, t) {
1396
1323
  return this.canvas.updateNode(e, t), this.updateMaxNodePriority(e), this;
1397
1324
  }
1398
1325
  removeNode(e) {
1399
1326
  const t = this.nodes.get(e);
1400
- return t !== void 0 && (t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart)), this.canvas.removeNode(e), this.nodes.delete(e), this;
1327
+ return t !== void 0 && (t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart)), this.nodes.delete(e), this.canvas.removeNode(e), this;
1401
1328
  }
1402
1329
  markPort(e) {
1403
1330
  return this.canvas.markPort(e), this;
1404
1331
  }
1405
- updatePort(e, t) {
1406
- return this.canvas.updatePort(e, t), this;
1332
+ updatePortMark(e, t) {
1333
+ return this.canvas.updatePortMark(e, t), this;
1407
1334
  }
1408
1335
  unmarkPort(e) {
1409
1336
  return this.canvas.unmarkPort(e), this;
@@ -1428,27 +1355,19 @@ class Ee {
1428
1355
  e.element.removeEventListener("mousedown", e.onMouseDown), e.element.removeEventListener("touchstart", e.onTouchStart);
1429
1356
  }), this.nodes.clear(), this.maxNodePriority = 0, this;
1430
1357
  }
1431
- attach(e) {
1432
- return this.detach(), this.element = e, this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.canvas.attach(this.element), this;
1433
- }
1434
- detach() {
1435
- return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("touchstart", this.onCanvasTouchStart), this.element = null), this;
1436
- }
1437
1358
  destroy() {
1438
- this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.nodes.forEach((e) => {
1439
- e.element.removeEventListener("mousedown", e.onMouseDown), e.element.removeEventListener("touchstart", e.onTouchStart);
1440
- }), this.nodes.clear(), this.canvas.destroy();
1359
+ this.detach(), this.clear(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
1441
1360
  }
1442
1361
  dragNode(e, t, s) {
1443
- const o = this.model.getNode(e);
1444
- if (o === null)
1445
- throw new f("failed to drag nonexisting node");
1446
- const i = this.canvas.transformation.getContentMatrix(), h = i.scale * o.x + i.dx, a = i.scale * o.y + i.dy, d = h + t, c = a + s, u = this.canvas.transformation.getViewportMatrix(), w = u.scale * d + u.dx, m = u.scale * c + u.dy;
1362
+ const n = this.model.getNode(e);
1363
+ if (n === null)
1364
+ return;
1365
+ const o = this.canvas.transformation.getContentMatrix(), h = o.scale * n.x + o.dx, i = o.scale * n.y + o.dy, d = h + t, c = i + s, u = this.canvas.transformation.getViewportMatrix(), w = u.scale * d + u.dx, m = u.scale * c + u.dy;
1447
1366
  this.canvas.updateNode(e, { x: w, y: m }), this.onNodeDrag({
1448
1367
  nodeId: e,
1449
- element: o.element,
1450
- x: o.x,
1451
- y: o.y
1368
+ element: n.element,
1369
+ x: n.x,
1370
+ y: n.y
1452
1371
  });
1453
1372
  }
1454
1373
  updateMaxNodePriority(e) {
@@ -1460,137 +1379,184 @@ class Ee {
1460
1379
  return;
1461
1380
  this.maxNodePriority += 2, this.updateNode(e, { priority: this.maxNodePriority });
1462
1381
  const t = this.maxNodePriority - 1;
1463
- this.model.getNodeAdjacentEdgeIds(e).forEach((o) => {
1464
- this.updateEdge(o, { priority: t });
1382
+ this.model.getNodeAdjacentEdgeIds(e).forEach((n) => {
1383
+ this.updateEdge(n, { priority: t });
1465
1384
  });
1466
1385
  }
1467
1386
  cancelMouseDrag() {
1468
- this.grabbedNodeId = null, this.element !== null && O(this.element, null), this.removeMouseDragListeners();
1387
+ this.grabbedNodeId = null, this.element !== null && V(this.element, null), this.removeMouseDragListeners();
1469
1388
  }
1470
1389
  removeMouseDragListeners() {
1471
- this.window.removeEventListener("mouseup", this.onCanvasMouseUp), this.window.removeEventListener("mousemove", this.onCanvasMouseMove);
1390
+ this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
1472
1391
  }
1473
1392
  cancelTouchDrag() {
1474
1393
  this.previousTouchCoords = null, this.grabbedNodeId = null, this.removeTouchDragListeners();
1475
1394
  }
1476
1395
  removeTouchDragListeners() {
1477
- this.window.removeEventListener("touchmove", this.onCanvasTouchMove), this.window.removeEventListener("touchend", this.onCanvasTouchEnd), this.window.removeEventListener("touchcancel", this.onCanvasTouchEnd);
1396
+ this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1478
1397
  }
1479
1398
  }
1480
- const Ae = () => {
1481
- }, Ce = (r, e) => e, Pe = (r, e) => {
1482
- const t = e !== null ? 1 / e : null, s = r !== null ? 1 / r : null;
1483
- return (o, i) => s !== null && i.scale > s && i.scale > o.scale || t !== null && i.scale < t && i.scale < o.scale ? o : i;
1484
- }, Se = (r, e, t, s) => (o, i, h, a) => {
1485
- let d = i.dx, c = i.dy;
1486
- r !== null && d < r && d < o.dx && (d = o.dx);
1487
- const u = h * o.scale;
1488
- e !== null && d > e - u && d > o.dx && (d = o.dx), t !== null && c < t && c < o.dy && (c = o.dy);
1489
- const w = a * o.scale;
1490
- return s !== null && c > s - w && c > o.dy && (c = o.dy), { scale: i.scale, dx: d, dy: c };
1491
- }, K = (r) => {
1399
+ const Ee = (r) => {
1400
+ const e = r.maxContentScale, t = r.minContentScale, s = e !== null ? 1 / e : 0, n = t !== null ? 1 / t : 1 / 0;
1401
+ return (o) => {
1402
+ let h = o.nextTransform.scale, i = o.nextTransform.dx, d = o.nextTransform.dy;
1403
+ return o.nextTransform.scale > n && o.nextTransform.scale > o.prevTransform.scale && (h = Math.max(o.prevTransform.scale, n), i = o.prevTransform.dx, d = o.prevTransform.dy), o.nextTransform.scale < s && o.nextTransform.scale < o.prevTransform.scale && (h = Math.min(o.prevTransform.scale, s), i = o.prevTransform.dx, d = o.prevTransform.dy), {
1404
+ scale: h,
1405
+ dx: i,
1406
+ dy: d
1407
+ };
1408
+ };
1409
+ }, Ae = (r) => {
1410
+ 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, n = r.maxY !== null ? r.maxY : 1 / 0;
1411
+ return (o) => {
1412
+ let h = o.nextTransform.dx, i = o.nextTransform.dy;
1413
+ h < e && h < o.prevTransform.dx && (h = Math.min(o.prevTransform.dx, e));
1414
+ const d = o.canvasWidth * o.prevTransform.scale;
1415
+ h > t - d && h > o.prevTransform.dx && (h = Math.max(o.prevTransform.dx, t - d)), i < s && i < o.prevTransform.dy && (i = Math.min(o.prevTransform.dy, s));
1416
+ const c = o.canvasHeight * o.prevTransform.scale;
1417
+ return i > n - c && i > o.prevTransform.dy && (i = Math.max(o.prevTransform.dy, n - c)), { scale: o.nextTransform.scale, dx: h, dy: i };
1418
+ };
1419
+ }, J = (r) => {
1420
+ if (typeof r == "function")
1421
+ return r;
1492
1422
  switch (r.type) {
1493
1423
  case "scale-limit":
1494
- return Pe(
1495
- r.minContentScale ?? null,
1496
- r.maxContentScale ?? null
1497
- );
1424
+ return Ee({
1425
+ minContentScale: r.minContentScale ?? 0,
1426
+ maxContentScale: r.maxContentScale ?? 1 / 0
1427
+ });
1498
1428
  case "shift-limit":
1499
- return Se(
1500
- r.minX ?? null,
1501
- r.maxX ?? null,
1502
- r.minY ?? null,
1503
- r.maxY ?? null
1504
- );
1505
- default:
1506
- return r.preprocessorFn;
1429
+ return Ae({
1430
+ minX: r.minX ?? -1 / 0,
1431
+ maxX: r.maxX ?? 1 / 0,
1432
+ minY: r.minY ?? -1 / 0,
1433
+ maxY: r.maxY ?? 1 / 0
1434
+ });
1507
1435
  }
1508
- }, Me = (r) => (e, t, s, o) => r.reduce(
1509
- (i, h) => h(e, i, s, o),
1510
- t
1511
- );
1436
+ }, Ce = (r) => (e) => r.reduce(
1437
+ (t, s) => s({
1438
+ prevTransform: e.prevTransform,
1439
+ nextTransform: t,
1440
+ canvasWidth: e.canvasWidth,
1441
+ canvasHeight: e.canvasHeight
1442
+ }),
1443
+ e.nextTransform
1444
+ ), Me = (r) => {
1445
+ var d, c, u, w;
1446
+ const e = (d = r == null ? void 0 : r.scale) == null ? void 0 : d.wheelSensitivity, t = e !== void 0 ? e : 1.2, s = r == null ? void 0 : r.transformPreprocessor;
1447
+ let n;
1448
+ s !== void 0 ? Array.isArray(s) ? n = Ce(
1449
+ s.map(
1450
+ (m) => J(m)
1451
+ )
1452
+ ) : n = J(s) : n = (m) => m.nextTransform;
1453
+ const o = ((c = r == null ? void 0 : r.shift) == null ? void 0 : c.cursor) !== void 0 ? r.shift.cursor : "grab", h = ((u = r == null ? void 0 : r.events) == null ? void 0 : u.onBeforeTransformStarted) ?? (() => {
1454
+ }), i = ((w = r == null ? void 0 : r.events) == null ? void 0 : w.onTransformFinished) ?? (() => {
1455
+ });
1456
+ return {
1457
+ wheelSensitivity: t,
1458
+ onBeforeTransformStarted: h,
1459
+ onTransformFinished: i,
1460
+ transformPreprocessor: n,
1461
+ shiftCursor: o
1462
+ };
1463
+ }, z = (r) => {
1464
+ const e = [], t = r.touches.length;
1465
+ for (let i = 0; i < t; i++)
1466
+ e.push([r.touches[i].clientX, r.touches[i].clientY]);
1467
+ const s = e.reduce(
1468
+ (i, d) => [i[0] + d[0], i[1] + d[1]],
1469
+ [0, 0]
1470
+ ), n = [s[0] / t, s[1] / t], h = e.map((i) => [i[0] - n[0], i[1] - n[1]]).reduce(
1471
+ (i, d) => i + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
1472
+ 0
1473
+ );
1474
+ return {
1475
+ x: n[0],
1476
+ y: n[1],
1477
+ scale: h / t,
1478
+ touchesCnt: t,
1479
+ touches: e
1480
+ };
1481
+ }, Pe = (r, e, t) => ({
1482
+ scale: r.scale,
1483
+ dx: r.dx + r.scale * e,
1484
+ dy: r.dy + r.scale * t
1485
+ }), Se = (r, e, t, s) => ({
1486
+ scale: r.scale * e,
1487
+ dx: r.scale * (1 - e) * t + r.dx,
1488
+ dy: r.scale * (1 - e) * s + r.dy
1489
+ });
1512
1490
  class Ne {
1513
1491
  constructor(e, t) {
1514
- n(this, "model");
1515
- n(this, "transformation");
1516
- n(this, "element", null);
1517
- n(this, "prevTouches", null);
1518
- n(this, "onTransformFinished");
1519
- n(this, "transformPreprocessor");
1520
- n(this, "isScalable");
1521
- n(this, "isShiftable");
1522
- n(this, "wheelSensitivity");
1523
- n(this, "window", window);
1524
- n(this, "onMouseDown", () => {
1525
- this.element !== null && (O(this.element, this.shiftCursor), this.window.addEventListener("mousemove", this.onMouseMove), this.window.addEventListener("mouseup", this.onMouseUp));
1492
+ a(this, "model");
1493
+ a(this, "transformation");
1494
+ a(this, "element", null);
1495
+ a(this, "prevTouches", null);
1496
+ a(this, "window", window);
1497
+ a(this, "onMouseDown", (e) => {
1498
+ this.element === null || e.button !== 0 || (V(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp));
1526
1499
  });
1527
- n(this, "onMouseMove", (e) => {
1528
- if (!this.isShiftable || this.element === null)
1529
- return;
1530
- if (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY)) {
1500
+ a(this, "onWindowMouseMove", (e) => {
1501
+ if (this.element === null || !D(this.element, e.clientX, e.clientY) || !k(this.window, e.clientX, e.clientY)) {
1531
1502
  this.stopMouseDrag();
1532
1503
  return;
1533
1504
  }
1534
1505
  const t = -e.movementX, s = -e.movementY;
1535
- this.moveViewport(t, s);
1506
+ this.moveViewport(this.element, t, s);
1536
1507
  });
1537
- n(this, "onMouseUp", () => {
1538
- this.stopMouseDrag();
1508
+ a(this, "onWindowMouseUp", (e) => {
1509
+ this.element === null || e.button !== 0 || this.stopMouseDrag();
1539
1510
  });
1540
- n(this, "onWheelScroll", (e) => {
1541
- if (this.element === null || this.isScalable === !1)
1542
- return;
1511
+ a(this, "onWheelScroll", (e) => {
1543
1512
  e.preventDefault();
1544
- const { left: t, top: s } = this.element.getBoundingClientRect(), o = e.clientX - t, i = e.clientY - s, a = 1 / (e.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
1545
- this.scaleViewport(a, o, i);
1513
+ const { left: t, top: s } = this.element.getBoundingClientRect(), n = e.clientX - t, o = e.clientY - s, i = 1 / (e.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
1514
+ this.scaleViewport(this.element, i, n, o);
1546
1515
  });
1547
- n(this, "onTouchStart", (e) => {
1548
- this.prevTouches = this.getAverageTouch(e), this.window.addEventListener("touchmove", this.onTouchMove), this.window.addEventListener("touchend", this.onTouchEnd), this.window.addEventListener("touchcancel", this.onTouchEnd);
1516
+ a(this, "onTouchStart", (e) => {
1517
+ this.prevTouches = z(e), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish);
1549
1518
  });
1550
- n(this, "onTouchMove", (e) => {
1551
- if (this.prevTouches === null || !this.isShiftable || this.element === null)
1519
+ a(this, "onWindowTouchMove", (e) => {
1520
+ const t = this.element;
1521
+ if (t === null)
1552
1522
  return;
1553
- const t = this.getAverageTouch(e);
1554
- if (!t.touches.every(
1555
- (o) => W(this.element, o[0], o[1]) && V(this.window, o[0], o[1])
1523
+ const s = z(e);
1524
+ if (!s.touches.every(
1525
+ (o) => D(t, o[0], o[1]) && k(this.window, o[0], o[1])
1556
1526
  )) {
1557
1527
  this.stopTouchDrag();
1558
1528
  return;
1559
1529
  }
1560
- if ((t.touchesCnt === 1 || t.touchesCnt === 2) && this.moveViewport(
1561
- -(t.x - this.prevTouches.x),
1562
- -(t.y - this.prevTouches.y)
1563
- ), t.touchesCnt === 2 && this.isScalable) {
1564
- const { left: o, top: i } = this.element.getBoundingClientRect(), h = this.prevTouches.x - o, a = this.prevTouches.y - i, c = 1 / (t.scale / this.prevTouches.scale);
1565
- this.scaleViewport(c, h, a);
1530
+ if ((s.touchesCnt === 1 || s.touchesCnt === 2) && this.moveViewport(
1531
+ t,
1532
+ -(s.x - this.prevTouches.x),
1533
+ -(s.y - this.prevTouches.y)
1534
+ ), s.touchesCnt === 2) {
1535
+ const { left: o, top: h } = t.getBoundingClientRect(), i = this.prevTouches.x - o, d = this.prevTouches.y - h, u = 1 / (s.scale / this.prevTouches.scale);
1536
+ this.scaleViewport(t, u, i, d);
1566
1537
  }
1567
- this.prevTouches = t;
1538
+ this.prevTouches = s;
1568
1539
  });
1569
- n(this, "onTouchEnd", (e) => {
1570
- e.touches.length > 0 ? this.prevTouches = this.getAverageTouch(e) : this.stopTouchDrag();
1540
+ a(this, "onWindowTouchFinish", (e) => {
1541
+ e.touches.length > 0 ? this.prevTouches = z(e) : this.stopTouchDrag();
1571
1542
  });
1572
- n(this, "observer", new ResizeObserver(() => {
1573
- if (this.element !== null) {
1574
- const e = this.canvas.transformation.getViewportMatrix(), { width: t, height: s } = this.element.getBoundingClientRect(), o = this.transformPreprocessor(
1575
- e,
1576
- e,
1577
- t,
1578
- s
1579
- );
1580
- this.canvas.patchViewportMatrix(o), this.onTransformFinished();
1581
- }
1543
+ a(this, "observer", new ResizeObserver(() => {
1544
+ const e = this.canvas.transformation.getViewportMatrix(), { width: t, height: s } = this.element.getBoundingClientRect(), n = this.options.transformPreprocessor({
1545
+ prevTransform: e,
1546
+ nextTransform: e,
1547
+ canvasWidth: t,
1548
+ canvasHeight: s
1549
+ });
1550
+ this.canvas.patchViewportMatrix(n), this.options.onTransformFinished();
1582
1551
  }));
1583
- n(this, "shiftCursor");
1584
- var i, h, a, d, c, u, w, m;
1585
- this.canvas = e, this.options = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((h = (i = this.options) == null ? void 0 : i.scale) == null ? void 0 : h.enabled) !== !1, this.isShiftable = ((d = (a = this.options) == null ? void 0 : a.shift) == null ? void 0 : d.enabled) !== !1;
1586
- const s = (u = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : u.wheelSensitivity;
1587
- this.wheelSensitivity = s !== void 0 ? s : 1.2, this.onTransformFinished = ((w = t == null ? void 0 : t.events) == null ? void 0 : w.onTransformFinished) ?? Ae;
1588
- const o = t == null ? void 0 : t.transformPreprocessor;
1589
- o !== void 0 ? Array.isArray(o) ? this.transformPreprocessor = Me(
1590
- o.map(
1591
- (y) => K(y)
1592
- )
1593
- ) : this.transformPreprocessor = K(o) : this.transformPreprocessor = Ce, this.shiftCursor = ((m = t == null ? void 0 : t.shift) == null ? void 0 : m.cursor) !== void 0 ? t.shift.cursor : "grab";
1552
+ a(this, "options");
1553
+ this.canvas = e, this.options = Me(t), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1554
+ }
1555
+ attach(e) {
1556
+ return this.detach(), this.element = e, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.canvas.attach(this.element), this;
1557
+ }
1558
+ detach() {
1559
+ return this.canvas.detach(), this.element !== null && (this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element = null), this;
1594
1560
  }
1595
1561
  addNode(e) {
1596
1562
  return this.canvas.addNode(e), this;
@@ -1604,8 +1570,8 @@ class Ne {
1604
1570
  markPort(e) {
1605
1571
  return this.canvas.markPort(e), this;
1606
1572
  }
1607
- updatePort(e, t) {
1608
- return this.canvas.updatePort(e, t), this;
1573
+ updatePortMark(e, t) {
1574
+ return this.canvas.updatePortMark(e, t), this;
1609
1575
  }
1610
1576
  unmarkPort(e) {
1611
1577
  return this.canvas.unmarkPort(e), this;
@@ -1628,85 +1594,161 @@ class Ne {
1628
1594
  clear() {
1629
1595
  return this.canvas.clear(), this;
1630
1596
  }
1631
- attach(e) {
1632
- return this.detach(), this.element = e, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.canvas.attach(this.element), this;
1633
- }
1634
- detach() {
1635
- return this.canvas.detach(), this.element !== null && (this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element = null), this;
1636
- }
1637
1597
  destroy() {
1638
1598
  this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
1639
1599
  }
1640
- getAverageTouch(e) {
1641
- const t = [], s = e.touches.length;
1642
- for (let d = 0; d < s; d++)
1643
- t.push([e.touches[d].clientX, e.touches[d].clientY]);
1644
- const o = t.reduce(
1645
- (d, c) => [d[0] + c[0], d[1] + c[1]],
1646
- [0, 0]
1647
- ), i = [o[0] / s, o[1] / s], a = t.map((d) => [d[0] - i[0], d[1] - i[1]]).reduce(
1648
- (d, c) => d + Math.sqrt(c[0] * c[0] + c[1] * c[1]),
1649
- 0
1650
- );
1651
- return {
1652
- x: i[0],
1653
- y: i[1],
1654
- scale: a / s,
1655
- touchesCnt: s,
1656
- touches: t
1657
- };
1658
- }
1659
- moveViewport(e, t) {
1660
- const s = this.transformation.getViewportMatrix(), o = {
1661
- scale: s.scale,
1662
- dx: s.dx + s.scale * e,
1663
- dy: s.dy + s.scale * t
1664
- };
1665
- if (this.element !== null) {
1666
- const { width: i, height: h } = this.element.getBoundingClientRect(), a = this.transformPreprocessor(
1667
- s,
1668
- o,
1669
- i,
1670
- h
1671
- );
1672
- this.canvas.patchViewportMatrix(a), this.onTransformFinished();
1673
- }
1674
- }
1675
- scaleViewport(e, t, s) {
1676
- if (this.element === null)
1677
- return;
1678
- const o = this.canvas.transformation.getViewportMatrix(), i = {
1679
- scale: o.scale * e,
1680
- dx: o.scale * (1 - e) * t + o.dx,
1681
- dy: o.scale * (1 - e) * s + o.dy
1682
- }, { width: h, height: a } = this.element.getBoundingClientRect(), d = this.transformPreprocessor(
1683
- o,
1684
- i,
1685
- h,
1686
- a
1687
- );
1688
- this.canvas.patchViewportMatrix(d), this.onTransformFinished();
1600
+ moveViewport(e, t, s) {
1601
+ this.options.onBeforeTransformStarted();
1602
+ const n = this.transformation.getViewportMatrix(), o = Pe(n, t, s), { width: h, height: i } = e.getBoundingClientRect(), d = this.options.transformPreprocessor({
1603
+ prevTransform: n,
1604
+ nextTransform: o,
1605
+ canvasWidth: h,
1606
+ canvasHeight: i
1607
+ });
1608
+ this.canvas.patchViewportMatrix(d), this.options.onTransformFinished();
1609
+ }
1610
+ scaleViewport(e, t, s, n) {
1611
+ this.options.onBeforeTransformStarted();
1612
+ const o = this.canvas.transformation.getViewportMatrix(), h = Se(o, t, s, n), { width: i, height: d } = e.getBoundingClientRect(), c = this.options.transformPreprocessor({
1613
+ prevTransform: o,
1614
+ nextTransform: h,
1615
+ canvasWidth: i,
1616
+ canvasHeight: d
1617
+ });
1618
+ this.canvas.patchViewportMatrix(c), this.options.onTransformFinished();
1689
1619
  }
1690
1620
  stopMouseDrag() {
1691
- this.element !== null && O(this.element, null), this.removeMouseDragListeners();
1621
+ this.element !== null && V(this.element, null), this.removeMouseDragListeners();
1692
1622
  }
1693
1623
  removeMouseDragListeners() {
1694
- this.window.removeEventListener("mousemove", this.onMouseMove), this.window.removeEventListener("mouseup", this.onMouseUp);
1624
+ this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
1695
1625
  }
1696
1626
  stopTouchDrag() {
1697
1627
  this.prevTouches = null, this.removeTouchDragListeners();
1698
1628
  }
1699
1629
  removeTouchDragListeners() {
1700
- this.window.removeEventListener("touchmove", this.onTouchMove), this.window.removeEventListener("touchend", this.onTouchEnd), this.window.removeEventListener("touchcancel", this.onTouchEnd);
1630
+ this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1701
1631
  }
1702
1632
  }
1703
1633
  class Te {
1704
1634
  constructor() {
1705
- n(this, "coreOptions");
1706
- n(this, "dragOptions");
1707
- n(this, "transformOptions");
1708
- n(this, "isDraggable", !1);
1709
- n(this, "isTransformable", !1);
1635
+ a(this, "keyMap", /* @__PURE__ */ new Map());
1636
+ a(this, "valueMap", /* @__PURE__ */ new Map());
1637
+ }
1638
+ set(e, t) {
1639
+ this.keyMap.set(e, t), this.valueMap.set(t, e);
1640
+ }
1641
+ hasKey(e) {
1642
+ return this.keyMap.has(e);
1643
+ }
1644
+ hasValue(e) {
1645
+ return this.valueMap.has(e);
1646
+ }
1647
+ getByKey(e) {
1648
+ return this.keyMap.get(e);
1649
+ }
1650
+ getByValue(e) {
1651
+ return this.valueMap.get(e);
1652
+ }
1653
+ deleteByKey(e) {
1654
+ const t = this.keyMap.get(e);
1655
+ t !== void 0 && this.valueMap.delete(t), this.keyMap.delete(e);
1656
+ }
1657
+ deleteByValue(e) {
1658
+ const t = this.valueMap.get(e);
1659
+ t !== void 0 && this.keyMap.delete(t), this.valueMap.delete(e);
1660
+ }
1661
+ forEach(e) {
1662
+ this.keyMap.forEach((t, s) => {
1663
+ e(t, s);
1664
+ });
1665
+ }
1666
+ clear() {
1667
+ this.keyMap.clear(), this.valueMap.clear();
1668
+ }
1669
+ }
1670
+ class Le {
1671
+ constructor(e) {
1672
+ a(this, "transformation");
1673
+ a(this, "model");
1674
+ a(this, "nodes", new Te());
1675
+ a(this, "nodeIdGenerator", new $(
1676
+ (e) => this.nodes.hasKey(e)
1677
+ ));
1678
+ a(this, "nodesResizeObserver");
1679
+ this.canvas = e, this.nodesResizeObserver = new window.ResizeObserver((t) => {
1680
+ t.forEach((s) => {
1681
+ const n = s.target;
1682
+ this.reactNodeChange(n);
1683
+ });
1684
+ }), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1685
+ }
1686
+ attach(e) {
1687
+ return this.canvas.attach(e), this;
1688
+ }
1689
+ detach() {
1690
+ return this.canvas.detach(), this;
1691
+ }
1692
+ addNode(e) {
1693
+ const t = this.nodeIdGenerator.create(e.id);
1694
+ return this.canvas.addNode({
1695
+ ...e,
1696
+ id: t
1697
+ }), this.nodes.set(t, e.element), this.nodesResizeObserver.observe(e.element), this;
1698
+ }
1699
+ updateNode(e, t) {
1700
+ return this.canvas.updateNode(e, t), this;
1701
+ }
1702
+ removeNode(e) {
1703
+ this.canvas.removeNode(e);
1704
+ const t = this.nodes.getByKey(e);
1705
+ return this.nodes.deleteByKey(e), this.nodesResizeObserver.unobserve(t), this;
1706
+ }
1707
+ markPort(e) {
1708
+ return this.canvas.markPort(e), this;
1709
+ }
1710
+ updatePortMark(e, t) {
1711
+ return this.canvas.updatePortMark(e, t), this;
1712
+ }
1713
+ unmarkPort(e) {
1714
+ return this.canvas.unmarkPort(e), this;
1715
+ }
1716
+ addEdge(e) {
1717
+ return this.canvas.addEdge(e), this;
1718
+ }
1719
+ updateEdge(e, t) {
1720
+ return this.canvas.updateEdge(e, t), this;
1721
+ }
1722
+ removeEdge(e) {
1723
+ return this.canvas.removeEdge(e), this;
1724
+ }
1725
+ patchViewportMatrix(e) {
1726
+ return this.canvas.patchViewportMatrix(e), this;
1727
+ }
1728
+ patchContentMatrix(e) {
1729
+ return this.canvas.patchContentMatrix(e), this;
1730
+ }
1731
+ clear() {
1732
+ return this.canvas.clear(), this.nodesResizeObserver.disconnect(), this.nodes.clear(), this;
1733
+ }
1734
+ destroy() {
1735
+ this.clear(), this.canvas.destroy();
1736
+ }
1737
+ reactNodeChange(e) {
1738
+ const t = this.nodes.getByValue(e);
1739
+ this.canvas.updateNode(t), this.model.getNodeAdjacentEdgeIds(t).forEach((n) => {
1740
+ this.canvas.updateEdge(n);
1741
+ });
1742
+ }
1743
+ }
1744
+ class Ie {
1745
+ constructor() {
1746
+ a(this, "coreOptions");
1747
+ a(this, "dragOptions");
1748
+ a(this, "transformOptions");
1749
+ a(this, "isDraggable", !1);
1750
+ a(this, "isTransformable", !1);
1751
+ a(this, "hasResizeReactiveNodes", !1);
1710
1752
  }
1711
1753
  setOptions(e) {
1712
1754
  return this.coreOptions = e, this;
@@ -1717,28 +1759,32 @@ class Te {
1717
1759
  setUserTransformableCanvas(e) {
1718
1760
  return this.isTransformable = !0, this.transformOptions = e, this;
1719
1761
  }
1762
+ setResizableReactiveNodes() {
1763
+ return this.hasResizeReactiveNodes = !0, this;
1764
+ }
1720
1765
  build() {
1721
1766
  let e = new xe(this.coreOptions);
1722
- return this.isDraggable && (e = new Ee(e, this.dragOptions)), this.isTransformable && (e = new Ne(e, this.transformOptions)), e;
1767
+ return this.hasResizeReactiveNodes && (e = new Le(e)), this.isDraggable && (e = new fe(e, this.dragOptions)), this.isTransformable && (e = new Ne(e, this.transformOptions)), e;
1723
1768
  }
1724
1769
  }
1725
1770
  export {
1726
- te as BezierEdgeShape,
1771
+ O as BezierEdgeShape,
1727
1772
  xe as CanvasCore,
1728
- ie as CycleCircleEdgeShape,
1729
- B as CycleSquareEdgeShape,
1730
- ne as DetourBezierEdgeShape,
1773
+ re as CycleCircleEdgeShape,
1774
+ X as CycleSquareEdgeShape,
1775
+ se as DetourBezierEdgeShape,
1731
1776
  G as DetourStraightEdgeShape,
1732
1777
  C as EdgeType,
1733
- se as HorizontalEdgeShape,
1734
- Te as HtmlGraphBuilder,
1735
- f as HtmlGraphError,
1736
- re as StraightEdgeShape,
1737
- Ee as UserDraggableNodesCanvas,
1778
+ ee as HorizontalEdgeShape,
1779
+ Ie as HtmlGraphBuilder,
1780
+ A as HtmlGraphError,
1781
+ Le as ResizeReactiveNodesCanvas,
1782
+ q as StraightEdgeShape,
1783
+ fe as UserDraggableNodesCanvas,
1738
1784
  Ne as UserTransformableCanvas,
1739
- oe as VerticalEdgeShape,
1740
- ae as createBezierEdgeShapeFactory,
1741
- ce as createHorizontalEdgeShapeFactory,
1742
- he as createStraightEdgeShareFactory,
1743
- de as createVerticalEdgeShapeFactory
1785
+ te as VerticalEdgeShape,
1786
+ oe as createBezierEdgeShapeFactory,
1787
+ ae as createHorizontalEdgeShapeFactory,
1788
+ ne as createStraightEdgeShareFactory,
1789
+ ie as createVerticalEdgeShapeFactory
1744
1790
  };