@html-graph/html-graph 0.0.60 → 0.0.61

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,6 +1,6 @@
1
1
  var _ = Object.defineProperty;
2
2
  var J = (r, e, t) => e in r ? _(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var a = (r, e, t) => J(r, typeof e != "symbol" ? e + "" : e, t);
3
+ var n = (r, e, t) => J(r, typeof e != "symbol" ? e + "" : e, t);
4
4
  const Y = (r) => ({
5
5
  scale: 1 / r.scale,
6
6
  dx: -r.dx / r.scale,
@@ -12,8 +12,8 @@ const Y = (r) => ({
12
12
  };
13
13
  class Q {
14
14
  constructor() {
15
- a(this, "viewportMatrix", X);
16
- a(this, "contentMatrix", X);
15
+ n(this, "viewportMatrix", X);
16
+ n(this, "contentMatrix", X);
17
17
  }
18
18
  getViewportMatrix() {
19
19
  return this.viewportMatrix;
@@ -21,18 +21,18 @@ class Q {
21
21
  getContentMatrix() {
22
22
  return this.contentMatrix;
23
23
  }
24
- patchViewportMatrix(e, t, s) {
24
+ patchViewportMatrix(e) {
25
25
  this.viewportMatrix = {
26
- scale: e ?? this.viewportMatrix.scale,
27
- dx: t ?? this.viewportMatrix.dx,
28
- dy: s ?? this.viewportMatrix.dy
26
+ scale: e.scale ?? this.viewportMatrix.scale,
27
+ dx: e.dx ?? this.viewportMatrix.dx,
28
+ dy: e.dy ?? this.viewportMatrix.dy
29
29
  }, this.contentMatrix = Y(this.viewportMatrix);
30
30
  }
31
- patchContentMatrix(e, t, s) {
31
+ patchContentMatrix(e) {
32
32
  this.contentMatrix = {
33
- scale: e ?? this.contentMatrix.scale,
34
- dx: t ?? this.contentMatrix.dx,
35
- dy: s ?? this.contentMatrix.dy
33
+ scale: e.scale ?? this.contentMatrix.scale,
34
+ dx: e.dx ?? this.contentMatrix.dx,
35
+ dy: e.dy ?? this.contentMatrix.dy
36
36
  }, this.viewportMatrix = Y(this.contentMatrix);
37
37
  }
38
38
  }
@@ -49,17 +49,23 @@ class Z {
49
49
  }
50
50
  class q {
51
51
  constructor() {
52
- a(this, "nodes", /* @__PURE__ */ new Map());
53
- a(this, "ports", /* @__PURE__ */ new Map());
54
- a(this, "nodePorts", /* @__PURE__ */ new Map());
55
- a(this, "portNodeId", /* @__PURE__ */ new Map());
56
- a(this, "edges", /* @__PURE__ */ new Map());
57
- a(this, "incommingEdges", /* @__PURE__ */ new Map());
58
- a(this, "outcommingEdges", /* @__PURE__ */ new Map());
59
- a(this, "cycleEdges", /* @__PURE__ */ new Map());
60
- }
61
- addNode(e, t, s, o, i, n) {
62
- this.nodes.set(e, { element: t, x: s, y: o, centerFn: i, priority: n }), this.nodePorts.set(e, /* @__PURE__ */ new Map());
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());
63
69
  }
64
70
  getAllNodeIds() {
65
71
  return Array.from(this.nodes.keys());
@@ -70,8 +76,12 @@ class q {
70
76
  removeNode(e) {
71
77
  this.nodes.delete(e), this.nodePorts.delete(e);
72
78
  }
73
- addPort(e, t, s, o, i) {
74
- this.ports.set(e, { element: t, centerFn: o, direction: i }), this.cycleEdges.set(e, /* @__PURE__ */ new Set()), this.incommingEdges.set(e, /* @__PURE__ */ new Set()), this.outcommingEdges.set(e, /* @__PURE__ */ new Set()), this.portNodeId.set(e, s), this.nodePorts.get(s).set(e, t);
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);
75
85
  }
76
86
  getPort(e) {
77
87
  return this.ports.get(e);
@@ -91,13 +101,13 @@ class q {
91
101
  const t = this.portNodeId.get(e);
92
102
  this.portNodeId.delete(e), this.nodePorts.get(t).delete(e), this.ports.delete(e);
93
103
  }
94
- addEdge(e, t, s, o, i) {
95
- this.edges.set(e, {
96
- from: t,
97
- to: s,
98
- shape: o,
99
- priority: i
100
- }), t !== s ? (this.outcommingEdges.get(t).add(e), this.incommingEdges.get(s).add(e)) : this.cycleEdges.get(t).add(e);
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);
101
111
  }
102
112
  getAllEdgeIds() {
103
113
  return Array.from(this.edges.keys());
@@ -229,28 +239,28 @@ const l = {
229
239
  }, p = (r, e, t) => ({
230
240
  x: e.x * r.x - e.y * r.y + ((1 - e.x) * t.x + e.y * t.y),
231
241
  y: e.y * r.x + e.x * r.y + ((1 - e.x) * t.y - e.y * t.x)
232
- }), f = (r, e, t) => ({ x: e * Math.cos(r), y: t * Math.sin(r) }), x = (r, e, t, s) => {
242
+ }), x = (r, e, t) => ({ x: e * Math.cos(r), y: t * Math.sin(r) }), E = (r, e, t, s) => {
233
243
  const i = [
234
244
  l,
235
245
  { x: t, y: s },
236
246
  { x: t, y: -s }
237
- ].map((d) => p(d, r, l)).map((d) => ({ x: d.x + e.x, y: d.y + e.y })), n = `M ${i[0].x} ${i[0].y}`, h = `L ${i[1].x} ${i[1].y}`, c = `L ${i[2].x} ${i[2].y}`;
238
- return `${n} ${h} ${c}`;
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}`;
239
249
  }, D = (r, e) => {
240
250
  const t = [];
241
251
  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) {
242
252
  const s = r.length - 1;
243
- let o = 0, i = 0, n = 0;
244
- r.forEach((h, c) => {
245
- let d = 0, u = 0, w = 0;
246
- const m = c > 0, y = c < s, v = m && y;
247
- if (m && (d = -o, u = -i, w = n), y) {
248
- const j = r[c + 1];
249
- o = j.x - h.x, i = j.y - h.y, n = Math.sqrt(o * o + i * i);
253
+ let o = 0, i = 0, h = 0;
254
+ r.forEach((a, d) => {
255
+ 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) {
258
+ const j = r[d + 1];
259
+ o = j.x - a.x, i = j.y - a.y, h = Math.sqrt(o * o + i * i);
250
260
  }
251
- const P = Math.min((v ? e : 0) / n, c < s - 1 ? 0.5 : 1), M = v ? { x: h.x + o * P, y: h.y + i * P } : h, T = Math.min((v ? e : 0) / w, c > 1 ? 0.5 : 1), W = v ? { x: h.x + d * T, y: h.y + u * T } : h;
252
- c > 0 && t.push(`L ${W.x} ${W.y}`), v && t.push(
253
- `C ${h.x} ${h.y} ${h.x} ${h.y} ${M.x} ${M.y}`
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}`
254
264
  );
255
265
  });
256
266
  }
@@ -264,39 +274,39 @@ const l = {
264
274
  }, L = (r, e) => {
265
275
  const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
266
276
  return t.setAttribute("stroke", r), t.setAttribute("stroke-width", `${e}`), t.setAttribute("fill", "none"), t;
267
- }, E = (r) => {
277
+ }, A = (r) => {
268
278
  const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
269
279
  return e.setAttribute("fill", r), e;
270
280
  };
271
281
  class te {
272
- constructor(e, t, s, o, i, n, h) {
273
- a(this, "svg", N());
274
- a(this, "group", $());
275
- a(this, "line");
276
- a(this, "sourceArrow", null);
277
- a(this, "targetArrow", null);
278
- this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), n && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
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));
279
289
  }
280
290
  update(e, t, s, o, i) {
281
291
  this.group.style.transform = `scale(${t}, ${s})`;
282
- const n = f(o, t, s), h = f(i, t, s), c = this.createLinePath(e, n, h);
283
- if (this.line.setAttribute("d", c), this.sourceArrow) {
284
- const d = x(
285
- n,
292
+ const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a);
293
+ if (this.line.setAttribute("d", d), this.sourceArrow) {
294
+ const c = E(
295
+ h,
286
296
  l,
287
297
  this.arrowLength,
288
298
  this.arrowWidth
289
299
  );
290
- this.sourceArrow.setAttribute("d", d);
300
+ this.sourceArrow.setAttribute("d", c);
291
301
  }
292
302
  if (this.targetArrow) {
293
- const d = x(
294
- h,
303
+ const c = E(
304
+ a,
295
305
  e,
296
306
  -this.arrowLength,
297
307
  this.arrowWidth
298
308
  );
299
- this.targetArrow.setAttribute("d", d);
309
+ this.targetArrow.setAttribute("d", c);
300
310
  }
301
311
  }
302
312
  createLinePath(e, t, s) {
@@ -308,175 +318,175 @@ class te {
308
318
  { x: e.x - this.arrowLength, y: e.y },
309
319
  s,
310
320
  e
311
- ), n = {
321
+ ), h = {
312
322
  x: o.x + t.x * this.curvature,
313
323
  y: o.y + t.y * this.curvature
314
- }, h = {
324
+ }, a = {
315
325
  x: i.x - s.x * this.curvature,
316
326
  y: i.y - s.y * this.curvature
317
- }, c = `M ${o.x} ${o.y} C ${n.x} ${n.y}, ${h.x} ${h.y}, ${i.x} ${i.y}`, d = 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}`;
318
- return `${d}${c}${u}`;
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}`;
328
+ return `${c}${d}${u}`;
319
329
  }
320
330
  }
321
331
  class re {
322
- constructor(e, t, s, o, i, n, h, c) {
323
- a(this, "svg", N());
324
- a(this, "group", $());
325
- a(this, "line");
326
- a(this, "sourceArrow", null);
327
- a(this, "targetArrow", null);
328
- this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = c, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), n && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
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));
329
339
  }
330
340
  update(e, t, s, o, i) {
331
341
  this.group.style.transform = `scale(${t}, ${s})`;
332
- const n = f(o, t, s), h = f(i, t, s), c = this.createLinePath(e, n, h);
333
- if (this.line.setAttribute("d", c), this.sourceArrow) {
334
- const d = x(
335
- n,
342
+ const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a);
343
+ if (this.line.setAttribute("d", d), this.sourceArrow) {
344
+ const c = E(
345
+ h,
336
346
  l,
337
347
  this.arrowLength,
338
348
  this.arrowWidth
339
349
  );
340
- this.sourceArrow.setAttribute("d", d);
350
+ this.sourceArrow.setAttribute("d", c);
341
351
  }
342
352
  if (this.targetArrow) {
343
- const d = x(
344
- h,
353
+ const c = E(
354
+ a,
345
355
  e,
346
356
  -this.arrowLength,
347
357
  this.arrowWidth
348
358
  );
349
- this.targetArrow.setAttribute("d", d);
359
+ this.targetArrow.setAttribute("d", c);
350
360
  }
351
361
  }
352
362
  createLinePath(e, t, s) {
353
- 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, n = this.arrowLength + this.arrowOffset, h = p({ x: n, y: l.y }, t, l), c = p({ x: e.x - n, y: e.y }, s, e);
354
- return D([o, h, c, i], this.roundness);
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);
355
365
  }
356
366
  }
357
367
  class se {
358
- constructor(e, t, s, o, i, n, h, c) {
359
- a(this, "svg", N());
360
- a(this, "group", $());
361
- a(this, "line");
362
- a(this, "sourceArrow", null);
363
- a(this, "targetArrow", null);
364
- this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = c, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), n && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
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));
365
375
  }
366
376
  update(e, t, s, o, i) {
367
377
  this.group.style.transform = `scale(${t}, ${s})`;
368
- const n = f(o, t, s), h = f(i, t, s), c = this.createLinePath(e, n, h, t);
369
- if (this.line.setAttribute("d", c), this.sourceArrow) {
370
- const d = x(
371
- n,
378
+ const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t);
379
+ if (this.line.setAttribute("d", d), this.sourceArrow) {
380
+ const c = E(
381
+ h,
372
382
  l,
373
383
  this.arrowLength,
374
384
  this.arrowWidth
375
385
  );
376
- this.sourceArrow.setAttribute("d", d);
386
+ this.sourceArrow.setAttribute("d", c);
377
387
  }
378
388
  if (this.targetArrow) {
379
- const d = x(
380
- h,
389
+ const c = E(
390
+ a,
381
391
  e,
382
392
  -this.arrowLength,
383
393
  this.arrowWidth
384
394
  );
385
- this.targetArrow.setAttribute("d", d);
395
+ this.targetArrow.setAttribute("d", c);
386
396
  }
387
397
  }
388
398
  createLinePath(e, t, s, o) {
389
- const i = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, n = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, h = this.arrowLength + this.arrowOffset, c = h - this.roundness, d = p({ x: c, y: l.y }, t, l), u = p({ x: e.x - c, y: e.y }, s, e), w = Math.max((d.x + u.x) / 2, h), m = e.y / 2, y = { x: o > 0 ? w : -h, y: d.y }, v = { x: y.x, y: m }, S = { x: o > 0 ? e.x - w : e.x + h, y: u.y }, P = { x: S.x, y: m };
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 };
390
400
  return D(
391
- [i, d, y, v, P, S, u, n],
401
+ [i, c, y, v, S, P, u, h],
392
402
  this.roundness
393
403
  );
394
404
  }
395
405
  }
396
406
  class oe {
397
- constructor(e, t, s, o, i, n, h, c) {
398
- a(this, "svg", N());
399
- a(this, "group", $());
400
- a(this, "line");
401
- a(this, "sourceArrow", null);
402
- a(this, "targetArrow", null);
403
- this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = c, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), n && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
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));
404
414
  }
405
415
  update(e, t, s, o, i) {
406
416
  this.group.style.transform = `scale(${t}, ${s})`;
407
- const n = f(o, t, s), h = f(i, t, s), c = this.createLinePath(e, n, h, s);
408
- if (this.line.setAttribute("d", c), this.sourceArrow) {
409
- const d = x(
410
- n,
417
+ const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, s);
418
+ if (this.line.setAttribute("d", d), this.sourceArrow) {
419
+ const c = E(
420
+ h,
411
421
  l,
412
422
  this.arrowLength,
413
423
  this.arrowWidth
414
424
  );
415
- this.sourceArrow.setAttribute("d", d);
425
+ this.sourceArrow.setAttribute("d", c);
416
426
  }
417
427
  if (this.targetArrow) {
418
- const d = x(
419
- h,
428
+ const c = E(
429
+ a,
420
430
  e,
421
431
  -this.arrowLength,
422
432
  this.arrowWidth
423
433
  );
424
- this.targetArrow.setAttribute("d", d);
434
+ this.targetArrow.setAttribute("d", c);
425
435
  }
426
436
  }
427
437
  createLinePath(e, t, s, o) {
428
- const i = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, n = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, h = this.arrowLength + this.arrowOffset, c = h - this.roundness, d = p({ x: c, y: l.y }, t, l), u = p({ x: e.x - c, y: e.y }, s, e), w = Math.max((d.y + u.y) / 2, h), m = e.x / 2, y = { x: d.x, y: o > 0 ? w : -h }, v = { x: m, y: y.y }, S = {
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 = {
429
439
  x: u.x,
430
- y: o > 0 ? e.y - w : e.y + h
431
- }, P = { x: m, y: S.y };
440
+ y: o > 0 ? e.y - w : e.y + a
441
+ }, S = { x: m, y: P.y };
432
442
  return D(
433
- [i, d, y, v, P, S, u, n],
443
+ [i, c, y, v, S, P, u, h],
434
444
  this.roundness
435
445
  );
436
446
  }
437
447
  }
438
448
  class ie {
439
- constructor(e, t, s, o, i, n, h) {
440
- a(this, "svg", N());
441
- a(this, "line");
442
- a(this, "arrow", null);
443
- this.arrowLength = s, this.arrowWidth = o, this.radius = n, this.smallRadius = h, this.line = L(e, t), this.svg.appendChild(this.line), i && (this.arrow = E(e), this.svg.appendChild(this.arrow));
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));
444
454
  }
445
455
  update(e, t, s, o) {
446
- const i = f(o, t, s), n = this.createLinePath(i);
447
- if (this.line.setAttribute("d", n), this.arrow) {
448
- const h = x(
456
+ const i = x(o, t, s), h = this.createLinePath(i);
457
+ if (this.line.setAttribute("d", h), this.arrow) {
458
+ const a = E(
449
459
  i,
450
460
  l,
451
461
  this.arrowLength,
452
462
  this.arrowWidth
453
463
  );
454
- this.arrow.setAttribute("d", h);
464
+ this.arrow.setAttribute("d", a);
455
465
  }
456
466
  }
457
467
  createLinePath(e) {
458
- const t = this.smallRadius, s = this.radius, o = Math.sqrt(t * t + s * s), i = t + s, n = this.arrowLength + o * (1 - s / i), h = t * s / i, d = [
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 = [
459
469
  { x: this.arrowLength, y: l.y },
460
- { x: n, y: h },
461
- { x: n, y: -h }
470
+ { x: h, y: a },
471
+ { x: h, y: -a }
462
472
  ].map((m) => p(m, e, l)), u = [
463
- `M ${d[0].x} ${d[0].y}`,
464
- `A ${t} ${t} 0 0 1 ${d[1].x} ${d[1].y}`,
465
- `A ${s} ${s} 0 1 0 ${d[2].x} ${d[2].y}`,
466
- `A ${t} ${t} 0 0 1 ${d[0].x} ${d[0].y}`
467
- ].join(" "), w = `M 0 0 L ${d[0].x} ${d[0].y} `;
473
+ `M ${c[0].x} ${c[0].y}`,
474
+ `A ${t} ${t} 0 0 1 ${c[1].x} ${c[1].y}`,
475
+ `A ${s} ${s} 0 1 0 ${c[2].x} ${c[2].y}`,
476
+ `A ${t} ${t} 0 0 1 ${c[0].x} ${c[0].y}`
477
+ ].join(" "), w = `M 0 0 L ${c[0].x} ${c[0].y} `;
468
478
  return `${this.arrow !== null ? "" : w}${u}`;
469
479
  }
470
480
  }
471
481
  class B {
472
- constructor(e, t, s, o, i, n, h, c) {
473
- a(this, "svg", N());
474
- a(this, "line");
475
- a(this, "arrow", null);
476
- a(this, "roundness");
477
- a(this, "linePoints");
478
- this.arrowLength = s, this.arrowWidth = o, this.side = n, this.minPortOffset = h, this.roundness = Math.min(c, this.minPortOffset, this.side / 2), this.line = L(e, t), this.svg.appendChild(this.line), i && (this.arrow = E(e), this.svg.appendChild(this.arrow));
479
- const d = this.minPortOffset, u = this.side, w = this.arrowLength + d, m = w + 2 * u;
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));
489
+ const c = this.minPortOffset, u = this.side, w = this.arrowLength + c, m = w + 2 * u;
480
490
  this.linePoints = [
481
491
  { x: this.arrowLength, y: l.y },
482
492
  { x: w, y: l.y },
@@ -489,15 +499,15 @@ class B {
489
499
  ];
490
500
  }
491
501
  update(e, t, s, o) {
492
- const i = f(o, t, s), n = this.createLinePath(i);
493
- if (this.line.setAttribute("d", n), this.arrow) {
494
- const h = x(
502
+ const i = x(o, t, s), h = this.createLinePath(i);
503
+ if (this.line.setAttribute("d", h), this.arrow) {
504
+ const a = E(
495
505
  i,
496
506
  l,
497
507
  this.arrowLength,
498
508
  this.arrowWidth
499
509
  );
500
- this.arrow.setAttribute("d", h);
510
+ this.arrow.setAttribute("d", a);
501
511
  }
502
512
  }
503
513
  createLinePath(e) {
@@ -508,126 +518,126 @@ class B {
508
518
  }
509
519
  }
510
520
  class ne {
511
- constructor(e, t, s, o, i, n, h, c, d) {
512
- a(this, "svg", N());
513
- a(this, "group", $());
514
- a(this, "line");
515
- a(this, "sourceArrow", null);
516
- a(this, "targetArrow", null);
517
- a(this, "detourX");
518
- a(this, "detourY");
519
- this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.detourX = Math.cos(d) * c, this.detourY = Math.sin(d) * c, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), n && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
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));
520
530
  }
521
531
  update(e, t, s, o, i) {
522
532
  this.group.style.transform = `scale(${t}, ${s})`;
523
- const n = f(o, t, s), h = f(i, t, s), c = this.createLinePath(e, n, h, t, s);
524
- if (this.line.setAttribute("d", c), this.sourceArrow) {
525
- const d = x(
526
- n,
533
+ const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t, s);
534
+ if (this.line.setAttribute("d", d), this.sourceArrow) {
535
+ const c = E(
536
+ h,
527
537
  l,
528
538
  this.arrowLength,
529
539
  this.arrowWidth
530
540
  );
531
- this.sourceArrow.setAttribute("d", d);
541
+ this.sourceArrow.setAttribute("d", c);
532
542
  }
533
543
  if (this.targetArrow) {
534
- const d = x(
535
- h,
544
+ const c = E(
545
+ a,
536
546
  e,
537
547
  -this.arrowLength,
538
548
  this.arrowWidth
539
549
  );
540
- this.targetArrow.setAttribute("d", d);
550
+ this.targetArrow.setAttribute("d", c);
541
551
  }
542
552
  }
543
553
  createLinePath(e, t, s, o, i) {
544
- const n = 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, c = this.arrowLength, d = this.detourX * o, u = this.detourY * i, w = p(
545
- { x: c, y: l.y },
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(
555
+ { x: d, y: l.y },
546
556
  t,
547
557
  l
548
558
  ), m = {
549
- x: w.x + d,
559
+ x: w.x + c,
550
560
  y: w.y + u
551
561
  }, y = p(
552
- { x: e.x - c, y: e.y },
562
+ { x: e.x - d, y: e.y },
553
563
  s,
554
564
  e
555
565
  ), v = {
556
- x: y.x + d,
566
+ x: y.x + c,
557
567
  y: y.y + u
558
- }, S = { x: (m.x + v.x) / 2, y: (m.y + v.y) / 2 }, P = {
568
+ }, P = { x: (m.x + v.x) / 2, y: (m.y + v.y) / 2 }, S = {
559
569
  x: w.x + this.curvature * t.x,
560
570
  y: w.y + this.curvature * t.y
561
571
  }, M = {
562
572
  x: y.x - this.curvature * s.x,
563
573
  y: y.y - this.curvature * s.y
564
574
  }, b = {
565
- x: w.x + d,
575
+ x: w.x + c,
566
576
  y: w.y + u
567
577
  }, T = {
568
- x: y.x + d,
578
+ x: y.x + c,
569
579
  y: y.y + u
570
580
  };
571
581
  return [
572
- `M ${n.x} ${n.y}`,
582
+ `M ${h.x} ${h.y}`,
573
583
  `L ${w.x} ${w.y}`,
574
- `C ${P.x} ${P.y} ${b.x} ${b.y} ${S.x} ${S.y}`,
584
+ `C ${S.x} ${S.y} ${b.x} ${b.y} ${P.x} ${P.y}`,
575
585
  `C ${T.x} ${T.y} ${M.x} ${M.y} ${y.x} ${y.y}`,
576
- `L ${h.x} ${h.y}`
586
+ `L ${a.x} ${a.y}`
577
587
  ].join(" ");
578
588
  }
579
589
  }
580
590
  class G {
581
- constructor(e, t, s, o, i, n, h, c, d, u) {
582
- a(this, "svg", N());
583
- a(this, "group", $());
584
- a(this, "line");
585
- a(this, "sourceArrow", null);
586
- a(this, "targetArrow", null);
587
- a(this, "detourX");
588
- a(this, "detourY");
589
- this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = c, this.detourX = Math.cos(u) * d, this.detourY = Math.sin(u) * d, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), n && (this.sourceArrow = E(e), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = E(e), this.group.appendChild(this.targetArrow));
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));
590
600
  }
591
601
  update(e, t, s, o, i) {
592
602
  this.group.style.transform = `scale(${t}, ${s})`;
593
- const n = f(o, t, s), h = f(i, t, s), c = this.createLinePath(e, n, h, t, s);
594
- if (this.line.setAttribute("d", c), this.sourceArrow) {
595
- const d = x(
596
- n,
603
+ const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t, s);
604
+ if (this.line.setAttribute("d", d), this.sourceArrow) {
605
+ const c = E(
606
+ h,
597
607
  l,
598
608
  this.arrowLength,
599
609
  this.arrowWidth
600
610
  );
601
- this.sourceArrow.setAttribute("d", d);
611
+ this.sourceArrow.setAttribute("d", c);
602
612
  }
603
613
  if (this.targetArrow) {
604
- const d = x(
605
- h,
614
+ const c = E(
615
+ a,
606
616
  e,
607
617
  -this.arrowLength,
608
618
  this.arrowWidth
609
619
  );
610
- this.targetArrow.setAttribute("d", d);
620
+ this.targetArrow.setAttribute("d", c);
611
621
  }
612
622
  }
613
623
  createLinePath(e, t, s, o, i) {
614
- const n = 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, c = this.arrowLength + this.arrowOffset, d = p(
615
- { x: c, y: l.y },
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(
625
+ { x: d, y: l.y },
616
626
  t,
617
627
  l
618
- ), u = this.detourX * o, w = this.detourY * i, m = { x: d.x + u, y: d.y + w }, y = p(
619
- { x: e.x - c, y: e.y },
628
+ ), u = this.detourX * o, w = this.detourY * i, m = { x: c.x + u, y: c.y + w }, y = p(
629
+ { x: e.x - d, y: e.y },
620
630
  s,
621
631
  e
622
632
  ), v = { x: y.x + u, y: y.y + w };
623
633
  return D(
624
- [n, d, m, v, y, h],
634
+ [h, c, m, v, y, a],
625
635
  this.roundness
626
636
  );
627
637
  }
628
638
  }
629
- var A = /* @__PURE__ */ ((r) => (r.Regular = "regular", r.PortCycle = "port-cycle", r.NodeCycle = "node-cycle", r))(A || {});
630
- const ae = (r) => (e) => e === A.PortCycle ? new ie(
639
+ 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(
631
641
  r.color,
632
642
  r.width,
633
643
  r.arrowLength,
@@ -635,7 +645,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
635
645
  r.hasSourceArrow || r.hasTargetArrow,
636
646
  r.cycleRadius,
637
647
  r.smallCycleRadius
638
- ) : e === A.NodeCycle ? new ne(
648
+ ) : e === C.NodeCycle ? new ne(
639
649
  r.color,
640
650
  r.width,
641
651
  r.curvature,
@@ -653,7 +663,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
653
663
  r.arrowWidth,
654
664
  r.hasSourceArrow,
655
665
  r.hasTargetArrow
656
- ), he = (r) => (e) => e === A.PortCycle ? new B(
666
+ ), he = (r) => (e) => e === C.PortCycle ? new B(
657
667
  r.color,
658
668
  r.width,
659
669
  r.arrowLength,
@@ -662,7 +672,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
662
672
  r.cycleSquareSide,
663
673
  r.arrowOffset,
664
674
  r.roundness
665
- ) : e === A.NodeCycle ? new G(
675
+ ) : e === C.NodeCycle ? new G(
666
676
  r.color,
667
677
  r.width,
668
678
  r.arrowLength,
@@ -682,7 +692,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
682
692
  r.hasSourceArrow,
683
693
  r.hasTargetArrow,
684
694
  r.roundness
685
- ), ce = (r) => (e) => e === A.PortCycle ? new B(
695
+ ), de = (r) => (e) => e === C.PortCycle ? new B(
686
696
  r.color,
687
697
  r.width,
688
698
  r.arrowLength,
@@ -691,7 +701,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
691
701
  r.cycleSquareSide,
692
702
  r.arrowOffset,
693
703
  r.roundness
694
- ) : e === A.NodeCycle ? new G(
704
+ ) : e === C.NodeCycle ? new G(
695
705
  r.color,
696
706
  r.width,
697
707
  r.arrowLength,
@@ -711,7 +721,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
711
721
  r.hasSourceArrow,
712
722
  r.hasTargetArrow,
713
723
  r.roundness
714
- ), de = (r) => (e) => e === A.PortCycle ? new B(
724
+ ), ce = (r) => (e) => e === C.PortCycle ? new B(
715
725
  r.color,
716
726
  r.width,
717
727
  r.arrowLength,
@@ -720,7 +730,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
720
730
  r.cycleSquareSide,
721
731
  r.arrowOffset,
722
732
  r.roundness
723
- ) : e === A.NodeCycle ? new G(
733
+ ) : e === C.NodeCycle ? new G(
724
734
  r.color,
725
735
  r.width,
726
736
  r.arrowLength,
@@ -741,9 +751,9 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
741
751
  r.hasTargetArrow,
742
752
  r.roundness
743
753
  );
744
- class F {
754
+ class I {
745
755
  constructor(e) {
746
- a(this, "counter", 0);
756
+ n(this, "counter", 0);
747
757
  this.checkExists = e;
748
758
  }
749
759
  create(e) {
@@ -757,144 +767,151 @@ class F {
757
767
  this.counter = 0;
758
768
  }
759
769
  }
760
- class C extends Error {
770
+ class f extends Error {
761
771
  constructor() {
762
772
  super(...arguments);
763
- a(this, "name", "HtmlGraphError");
773
+ n(this, "name", "HtmlGraphError");
764
774
  }
765
775
  }
766
776
  class le {
767
- constructor(e, t, s, o, i, n, h, c) {
768
- a(this, "nodeIdGenerator", new F(
777
+ constructor(e, t, s, o, i, h, a, d) {
778
+ n(this, "nodeIdGenerator", new I(
769
779
  (e) => this.graphStore.getNode(e) !== void 0
770
780
  ));
771
- a(this, "portIdGenerator", new F(
781
+ n(this, "portIdGenerator", new I(
772
782
  (e) => this.graphStore.getPort(e) !== void 0
773
783
  ));
774
- a(this, "edgeIdGenerator", new F(
784
+ n(this, "edgeIdGenerator", new I(
775
785
  (e) => this.graphStore.getEdge(e) !== void 0
776
786
  ));
777
- this.graphStore = e, this.htmlController = t, this.viewportTransformer = s, this.defaultNodesCenterFn = o, this.defaultPortsCenterFn = i, this.defaultPortsDirection = n, this.defaultNodesPriorityFn = h, this.defaultEdgesPriorityFn = c;
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;
778
788
  }
779
- addNode(e, t, s, o, i, n, h) {
780
- if (e = this.nodeIdGenerator.create(e), this.graphStore.getNode(e) !== void 0)
781
- throw new C("failed to add node with existing id");
782
- this.graphStore.addNode(
783
- e,
784
- t,
785
- s,
786
- o,
787
- n ?? this.defaultNodesCenterFn,
788
- h ?? this.defaultNodesPriorityFn()
789
- ), this.htmlController.attachNode(e), Array.from(i ?? []).forEach((c) => {
790
- this.markPort(
791
- c.id,
792
- c.element,
793
- e,
794
- c.centerFn ?? this.defaultPortsCenterFn,
795
- c.direction ?? this.defaultPortsDirection
796
- );
797
- });
789
+ attach(e) {
790
+ this.htmlController.attach(e);
798
791
  }
799
- updateNode(e, t, s, o, i) {
800
- const n = this.graphStore.getNode(e);
801
- if (n === void 0)
802
- throw new C("failed to update nonexisting node");
803
- n.x = t ?? n.x, n.y = s ?? n.y, n.centerFn = i ?? n.centerFn, this.htmlController.updateNodeCoordinates(e), o !== void 0 && (n.priority = o, this.htmlController.updateNodePriority(e));
792
+ detach() {
793
+ this.htmlController.detach();
804
794
  }
805
- removeNode(e) {
806
- if (this.graphStore.getNode(e) === void 0)
807
- throw new C("failed to remove nonexisting node");
808
- (this.graphStore.getNodePortIds(e) ?? []).forEach((t) => {
809
- this.unmarkPort(t);
810
- }), this.htmlController.detachNode(e), this.graphStore.removeNode(e);
795
+ 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,
801
+ element: e.element,
802
+ x: e.x,
803
+ 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
+ });
811
815
  }
812
- markPort(e, t, s, o, i) {
813
- if (e = this.portIdGenerator.create(e), this.graphStore.getNode(s) === void 0)
814
- throw new C("failed to set port on nonexisting node");
815
- if (this.graphStore.getPort(e) !== void 0)
816
- throw new C("failed to add port with existing id");
817
- this.graphStore.addPort(
818
- e,
819
- t,
820
- s,
821
- o ?? this.defaultPortsCenterFn,
822
- i ?? this.defaultPortsDirection
823
- );
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,
824
+ element: e.element,
825
+ nodeId: e.nodeId,
826
+ centerFn: e.centerFn ?? this.defaultPortsCenterFn,
827
+ direction: e.direction ?? this.defaultPortsDirection
828
+ });
824
829
  }
825
- updatePort(e, t, s) {
826
- const o = this.graphStore.getPort(e);
827
- if (o === void 0)
828
- throw new C("failed to unset nonexisting port");
829
- o.direction = t ?? o.direction, o.centerFn = s ?? o.centerFn, this.htmlController.updatePortEdges(e);
830
+ 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,
841
+ from: e.from,
842
+ 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);
830
856
  }
831
- unmarkPort(e) {
832
- if (this.graphStore.getPort(e) === void 0)
833
- throw new C("failed to unset nonexisting port");
834
- this.graphStore.getPortAdjacentEdgeIds(e).forEach((t) => {
835
- this.removeEdge(t);
836
- }), this.graphStore.removePort(e);
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
+ });
837
864
  }
838
- addEdge(e, t, s, o, i) {
839
- if (e = this.edgeIdGenerator.create(e), this.graphStore.getPort(t) === void 0)
840
- throw new C("failed to add edge from nonexisting port");
841
- if (this.graphStore.getPort(s) === void 0)
842
- throw new C("failed to add edge to nonexisting port");
843
- if (this.graphStore.getEdge(e) !== void 0)
844
- throw new C("failed to add edge with existing id");
845
- const n = this.resolveEdgeType(t, s);
846
- this.graphStore.addEdge(
847
- e,
848
- t,
849
- s,
850
- o(n),
851
- i ?? this.defaultEdgesPriorityFn()
852
- ), this.htmlController.attachEdge(e);
853
- }
854
- updateEdge(e, t, s) {
855
- const o = this.graphStore.getEdge(e);
856
- if (o === void 0)
857
- throw new C("failed to update nonexisting edge");
858
- if (t !== void 0) {
859
- const i = this.resolveEdgeType(o.from, o.to);
860
- o.shape = t(i), this.htmlController.updateEdgeShape(e);
861
- }
862
- s !== void 0 && (o.priority = s, this.htmlController.updateEdgePriority(e));
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
+ });
863
872
  }
864
873
  removeEdge(e) {
865
874
  if (this.graphStore.getEdge(e) === void 0)
866
- throw new C("failed to remove nonexisting edge");
875
+ throw new f("failed to remove nonexisting edge");
867
876
  this.htmlController.detachEdge(e), this.graphStore.removeEdge(e);
868
877
  }
869
- patchViewportMatrix(e, t, s) {
870
- this.viewportTransformer.patchViewportMatrix(e, t, s), this.htmlController.applyTransform();
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);
871
884
  }
872
- patchContentMatrix(e, t, s) {
873
- this.viewportTransformer.patchContentMatrix(e, t, s), this.htmlController.applyTransform();
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);
874
891
  }
875
- attach(e) {
876
- this.htmlController.attach(e);
892
+ patchViewportMatrix(e) {
893
+ this.viewportTransformer.patchViewportMatrix(e), this.htmlController.applyTransform();
877
894
  }
878
- detach() {
879
- this.htmlController.detach();
895
+ patchContentMatrix(e) {
896
+ this.viewportTransformer.patchContentMatrix(e), this.htmlController.applyTransform();
880
897
  }
881
898
  clear() {
882
899
  this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset();
883
900
  }
884
901
  destroy() {
885
- this.htmlController.destroy();
902
+ this.clear(), this.htmlController.destroy();
886
903
  }
887
904
  resolveEdgeType(e, t) {
888
905
  if (e === t)
889
- return A.PortCycle;
906
+ return C.PortCycle;
890
907
  const s = this.graphStore.getPortNodeId(e), o = this.graphStore.getPortNodeId(t);
891
- return s === o ? A.NodeCycle : A.Regular;
908
+ return s === o ? C.NodeCycle : C.Regular;
892
909
  }
893
910
  }
894
- const ue = () => {
911
+ const ge = () => {
895
912
  const r = document.createElement("div");
896
913
  return r.style.width = "100%", r.style.height = "100%", r.style.position = "relative", r.style.overflow = "hidden", r;
897
- }, ge = () => {
914
+ }, ue = () => {
898
915
  const r = document.createElement("div");
899
916
  return r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.width = "0", r.style.height = "0", r;
900
917
  }, we = () => {
@@ -902,46 +919,13 @@ const ue = () => {
902
919
  return r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.visibility = "hidden", r;
903
920
  };
904
921
  class ye {
905
- constructor() {
906
- a(this, "keyMap", /* @__PURE__ */ new Map());
907
- a(this, "valueMap", /* @__PURE__ */ new Map());
908
- }
909
- set(e, t) {
910
- this.keyMap.set(e, t), this.valueMap.set(t, e);
911
- }
912
- getByKey(e) {
913
- return this.keyMap.get(e);
914
- }
915
- getByValue(e) {
916
- return this.valueMap.get(e);
917
- }
918
- deleteByKey(e) {
919
- const t = this.keyMap.get(e);
920
- t !== void 0 && this.valueMap.delete(t), this.keyMap.delete(e);
921
- }
922
- deleteByValue(e) {
923
- const t = this.valueMap.get(e);
924
- t !== void 0 && this.keyMap.delete(t), this.valueMap.delete(e);
925
- }
926
- forEach(e) {
927
- this.keyMap.forEach((t, s) => {
928
- e(t, s);
929
- });
930
- }
931
- clear() {
932
- this.keyMap.clear(), this.valueMap.clear();
933
- }
934
- }
935
- class me {
936
- constructor(e, t, s, o) {
937
- a(this, "canvasWrapper", null);
938
- a(this, "host", ue());
939
- a(this, "container", ge());
940
- a(this, "nodeWrappersResizeObserver");
941
- a(this, "nodeElementToIdMap", /* @__PURE__ */ new Map());
942
- a(this, "nodeIdToWrapperElementMap", new ye());
943
- a(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
944
- this.nodeResizeObserverFactory = e, this.getBoundingClientRect = t, this.graphStore = s, this.viewportTransformer = o, this.host.appendChild(this.container), this.nodeWrappersResizeObserver = this.createNodesResizeObserver();
922
+ 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());
928
+ this.graphStore = e, this.viewportTransformer = t, this.host.appendChild(this.container);
945
929
  }
946
930
  attach(e) {
947
931
  this.detach(), this.canvasWrapper = e, this.canvasWrapper.appendChild(this.host);
@@ -955,15 +939,15 @@ class me {
955
939
  }
956
940
  attachNode(e) {
957
941
  const t = this.graphStore.getNode(e), s = we();
958
- s.appendChild(t.element), this.container.appendChild(s), this.nodeElementToIdMap.set(t.element, e), this.nodeIdToWrapperElementMap.set(e, s), this.updateNodeCoordinatesInternal(e), this.updateNodePriority(e), this.nodeWrappersResizeObserver.observe(s), s.style.visibility = "visible";
942
+ s.appendChild(t.element), this.container.appendChild(s), this.nodeIdToWrapperElementMap.set(e, s), this.updateNodeCoordinates(e), this.updateNodePriority(e), s.style.visibility = "visible";
959
943
  }
960
944
  detachNode(e) {
961
- const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.getByKey(e);
962
- this.nodeWrappersResizeObserver.unobserve(s), s.removeChild(t.element), this.container.removeChild(s), this.nodeElementToIdMap.delete(t.element), this.nodeIdToWrapperElementMap.deleteByKey(e);
945
+ const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.get(e);
946
+ s.removeChild(t.element), this.container.removeChild(s), this.nodeIdToWrapperElementMap.delete(e);
963
947
  }
964
948
  attachEdge(e) {
965
949
  const t = this.graphStore.getEdge(e);
966
- this.edgeIdToElementMap.set(e, t.shape.svg), this.container.appendChild(t.shape.svg), this.updateEdgeCoordinates(e), this.updateEdgePriority(e);
950
+ this.edgeIdToElementMap.set(e, t.shape.svg), this.container.appendChild(t.shape.svg), this.updateEdge(e), this.updateEdgePriority(e);
967
951
  }
968
952
  detachEdge(e) {
969
953
  const t = this.graphStore.getEdge(e);
@@ -977,102 +961,76 @@ class me {
977
961
  });
978
962
  }
979
963
  destroy() {
980
- this.nodeWrappersResizeObserver.disconnect(), this.host.removeChild(this.container), this.clear(), this.detach();
964
+ this.clear(), this.detach(), this.host.removeChild(this.container);
981
965
  }
982
966
  updateNodeCoordinates(e) {
983
- const t = this.graphStore.getNodeAdjacentEdgeIds(e);
984
- this.updateNodeCoordinatesInternal(e), t.forEach((s) => {
985
- this.updateEdgeCoordinates(s);
986
- });
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;
968
+ t.style.transform = `translate(${d}px, ${c}px)`;
987
969
  }
988
970
  updateNodePriority(e) {
989
- const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.getByKey(e);
971
+ const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.get(e);
990
972
  s.style.zIndex = `${t.priority}`;
991
973
  }
992
974
  updateEdgeShape(e) {
993
975
  const t = this.edgeIdToElementMap.get(e);
994
976
  this.container.removeChild(t);
995
977
  const s = this.graphStore.getEdge(e);
996
- this.edgeIdToElementMap.set(e, s.shape.svg), this.container.appendChild(s.shape.svg), this.updateEdgeCoordinates(e), this.updateEdgePriority(e);
997
- }
998
- updateEdgePriority(e) {
999
- const t = this.graphStore.getEdge(e);
1000
- t.shape.svg.style.zIndex = `${t.priority}`;
978
+ this.edgeIdToElementMap.set(e, s.shape.svg), this.container.appendChild(s.shape.svg);
1001
979
  }
1002
- updatePortEdges(e) {
1003
- this.graphStore.getPortAdjacentEdgeIds(e).forEach((s) => {
1004
- this.updateEdgeCoordinates(s);
1005
- });
1006
- }
1007
- createNodesResizeObserver() {
1008
- return this.nodeResizeObserverFactory((e) => {
1009
- e.forEach((t) => {
1010
- const s = t.target, o = this.nodeIdToWrapperElementMap.getByValue(s);
1011
- this.updateNodeCoordinatesInternal(o), this.graphStore.getNodeAdjacentEdgeIds(o).forEach((n) => {
1012
- this.updateEdgeCoordinates(n);
1013
- });
1014
- });
1015
- });
1016
- }
1017
- updateNodeCoordinatesInternal(e) {
1018
- const t = this.nodeIdToWrapperElementMap.getByKey(e), { width: s, height: o } = this.getBoundingClientRect.call(t), i = this.viewportTransformer.getViewportMatrix().scale, n = this.graphStore.getNode(e), { x: h, y: c } = n.centerFn(s, o), d = n.x - i * h, u = n.y - i * c;
1019
- t.style.transform = `translate(${d}px, ${u}px)`;
1020
- }
1021
- updateEdgeCoordinates(e) {
1022
- const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from), o = this.graphStore.getPort(t.to), i = this.getBoundingClientRect.call(s.element), n = this.getBoundingClientRect.call(o.element), h = this.getBoundingClientRect.call(this.host), c = this.viewportTransformer.getViewportMatrix(), d = {
1023
- x: c.scale * (i.left - h.left) + c.dx,
1024
- y: c.scale * (i.top - h.top) + c.dy
980
+ 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
1025
984
  }, u = {
1026
- x: c.scale * (n.left - h.left) + c.dx,
1027
- y: c.scale * (n.top - h.top) + c.dy
985
+ x: d.scale * (h.left - a.left) + d.dx,
986
+ y: d.scale * (h.top - a.top) + d.dy
1028
987
  }, w = s.centerFn(
1029
- i.width * c.scale,
1030
- i.height * c.scale
988
+ i.width * d.scale,
989
+ i.height * d.scale
1031
990
  ), m = o.centerFn(
1032
- n.width * c.scale,
1033
- n.height * c.scale
991
+ h.width * d.scale,
992
+ h.height * d.scale
1034
993
  ), y = {
1035
- x: d.x + w.x,
1036
- y: d.y + w.y
994
+ x: c.x + w.x,
995
+ y: c.y + w.y
1037
996
  }, v = {
1038
997
  x: u.x + m.x,
1039
998
  y: u.y + m.y
1040
- }, S = Math.min(y.x, v.x), P = Math.min(y.y, v.y), M = Math.abs(v.x - y.x), b = Math.abs(v.y - y.y);
1041
- t.shape.svg.style.width = `${M}px`, t.shape.svg.style.height = `${b}px`, t.shape.svg.style.transform = `translate(${S}px, ${P}px)`;
1042
- const T = y.x <= v.x ? 1 : -1, W = y.y <= v.y ? 1 : -1;
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;
1043
1002
  t.shape.update(
1044
1003
  { x: M, y: b },
1045
1004
  T,
1046
- W,
1005
+ F,
1047
1006
  s.direction,
1048
1007
  o.direction
1049
1008
  );
1050
1009
  }
1010
+ updateEdgePriority(e) {
1011
+ const t = this.graphStore.getEdge(e);
1012
+ t.shape.svg.style.zIndex = `${t.priority}`;
1013
+ }
1051
1014
  }
1052
- class pe {
1053
- constructor(e, t, s, o, i, n, h) {
1054
- a(this, "publicViewportTransformer");
1055
- a(this, "publicGraphStore");
1056
- a(this, "canvasController");
1057
- const c = new Q(), d = new q();
1058
- this.publicGraphStore = new ee(d), this.publicViewportTransformer = new Z(
1059
- c
1060
- );
1061
- const u = new me(
1062
- e,
1063
- t,
1064
- d,
1065
- c
1015
+ class me {
1016
+ 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
1066
1023
  );
1024
+ const o = new ye(s, t);
1067
1025
  this.canvasController = new le(
1068
- d,
1069
- u,
1070
- c,
1071
1026
  s,
1072
1027
  o,
1073
- i,
1074
- n,
1075
- h
1028
+ t,
1029
+ e.nodesCenterFn,
1030
+ e.portsCenterFn,
1031
+ e.portsDirection,
1032
+ e.nodesPriorityFn,
1033
+ e.edgesPriorityFn
1076
1034
  );
1077
1035
  }
1078
1036
  }
@@ -1093,7 +1051,7 @@ const H = (r, e) => ({
1093
1051
  detourDirection: -Math.PI / 2,
1094
1052
  smallCycleSize: 15,
1095
1053
  curvature: 90
1096
- }, k = (r) => {
1054
+ }, R = (r) => {
1097
1055
  switch (r == null ? void 0 : r.type) {
1098
1056
  case "custom":
1099
1057
  return r.factory;
@@ -1112,7 +1070,7 @@ const H = (r, e) => ({
1112
1070
  detourDirection: r.detourDirection ?? g.detourDirection
1113
1071
  });
1114
1072
  case "horizontal":
1115
- return de({
1073
+ return ce({
1116
1074
  color: r.color ?? g.edgeColor,
1117
1075
  width: r.width ?? g.edgeWidth,
1118
1076
  arrowLength: r.arrowLength ?? g.edgeArrowLength,
@@ -1126,7 +1084,7 @@ const H = (r, e) => ({
1126
1084
  detourDirection: r.detourDirection ?? g.detourDirection
1127
1085
  });
1128
1086
  case "vertical":
1129
- return ce({
1087
+ return de({
1130
1088
  color: r.color ?? g.edgeColor,
1131
1089
  width: r.width ?? g.edgeWidth,
1132
1090
  arrowLength: r.arrowLength ?? g.edgeArrowLength,
@@ -1154,20 +1112,20 @@ const H = (r, e) => ({
1154
1112
  curvature: r.curvature ?? g.curvature
1155
1113
  });
1156
1114
  }
1157
- }, z = (r) => () => r, U = z(0), R = () => {
1115
+ }, z = (r) => () => r, U = z(0), k = () => {
1158
1116
  let r = 0;
1159
1117
  return () => r++;
1160
- }, ve = (r, e) => {
1118
+ }, pe = (r, e) => {
1161
1119
  const t = [
1162
1120
  U,
1163
1121
  U
1164
1122
  ];
1165
- r === "incremental" && (t[0] = R()), e === "incremental" && (t[1] = R());
1166
- const s = R();
1123
+ r === "incremental" && (t[0] = k()), e === "incremental" && (t[1] = k());
1124
+ const s = k();
1167
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;
1168
- }, fe = (r) => {
1169
- var s, o, i, n, h, c;
1170
- const [e, t] = ve(
1126
+ }, ve = (r) => {
1127
+ var s, o, i, h, a, d;
1128
+ const [e, t] = pe(
1171
1129
  (s = r.nodes) == null ? void 0 : s.priority,
1172
1130
  (o = r.edges) == null ? void 0 : o.priority
1173
1131
  );
@@ -1177,109 +1135,154 @@ const H = (r, e) => ({
1177
1135
  priorityFn: e
1178
1136
  },
1179
1137
  ports: {
1180
- centerFn: ((n = r.ports) == null ? void 0 : n.centerFn) ?? H,
1181
- direction: ((h = r.ports) == null ? void 0 : h.direction) ?? 0
1138
+ centerFn: ((h = r.ports) == null ? void 0 : h.centerFn) ?? H,
1139
+ direction: ((a = r.ports) == null ? void 0 : a.direction) ?? 0
1182
1140
  },
1183
1141
  edges: {
1184
- shapeFactory: k(((c = r.edges) == null ? void 0 : c.shape) ?? {}),
1142
+ shapeFactory: R(((d = r.edges) == null ? void 0 : d.shape) ?? {}),
1185
1143
  priorityFn: t
1186
1144
  }
1187
1145
  };
1188
1146
  };
1147
+ class fe {
1148
+ constructor() {
1149
+ n(this, "keyMap", /* @__PURE__ */ new Map());
1150
+ n(this, "valueMap", /* @__PURE__ */ new Map());
1151
+ }
1152
+ set(e, t) {
1153
+ this.keyMap.set(e, t), this.valueMap.set(t, e);
1154
+ }
1155
+ hasKey(e) {
1156
+ return this.keyMap.has(e);
1157
+ }
1158
+ hasValue(e) {
1159
+ return this.valueMap.has(e);
1160
+ }
1161
+ getByKey(e) {
1162
+ return this.keyMap.get(e);
1163
+ }
1164
+ getByValue(e) {
1165
+ return this.valueMap.get(e);
1166
+ }
1167
+ deleteByKey(e) {
1168
+ const t = this.keyMap.get(e);
1169
+ t !== void 0 && this.valueMap.delete(t), this.keyMap.delete(e);
1170
+ }
1171
+ deleteByValue(e) {
1172
+ const t = this.valueMap.get(e);
1173
+ t !== void 0 && this.keyMap.delete(t), this.valueMap.delete(e);
1174
+ }
1175
+ forEach(e) {
1176
+ this.keyMap.forEach((t, s) => {
1177
+ e(t, s);
1178
+ });
1179
+ }
1180
+ clear() {
1181
+ this.keyMap.clear(), this.valueMap.clear();
1182
+ }
1183
+ }
1189
1184
  class xe {
1190
1185
  constructor(e) {
1191
- a(this, "transformation");
1192
- a(this, "model");
1193
- a(this, "di");
1194
- a(this, "edgeShapeFactory");
1195
- a(this, "nodeResizeObserverFactory", (e) => new window.ResizeObserver(e));
1196
- this.apiOptions = e;
1197
- const t = fe(this.apiOptions ?? {});
1198
- this.di = new pe(
1199
- this.nodeResizeObserverFactory,
1200
- Element.prototype.getBoundingClientRect,
1201
- t.nodes.centerFn,
1202
- t.ports.centerFn,
1203
- t.ports.direction,
1204
- t.nodes.priorityFn,
1205
- t.edges.priorityFn
1206
- ), this.transformation = this.di.publicViewportTransformer, this.model = this.di.publicGraphStore, this.edgeShapeFactory = t.edges.shapeFactory;
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;
1207
1211
  }
1208
1212
  addNode(e) {
1209
- return this.di.canvasController.addNode(
1210
- e.id,
1211
- e.element,
1212
- e.x,
1213
- e.y,
1214
- e.ports,
1215
- e.centerFn,
1216
- e.priority
1217
- ), this;
1213
+ const t = this.nodeIdGenerator.create(e.id);
1214
+ return this.di.canvasController.addNode({
1215
+ nodeId: t,
1216
+ element: e.element,
1217
+ x: e.x,
1218
+ y: e.y,
1219
+ ports: e.ports,
1220
+ centerFn: e.centerFn,
1221
+ priority: e.priority
1222
+ }), this.nodes.set(t, e.element), this.nodesResizeObserver.observe(e.element), this;
1218
1223
  }
1219
1224
  updateNode(e, t) {
1220
- return this.di.canvasController.updateNode(
1221
- e,
1222
- t.x,
1223
- t.y,
1224
- t.priority,
1225
- t.centerFn
1226
- ), this;
1225
+ return this.di.canvasController.updateNode(e, {
1226
+ x: t == null ? void 0 : t.x,
1227
+ y: t == null ? void 0 : t.y,
1228
+ priority: t == null ? void 0 : t.priority,
1229
+ centerFn: t == null ? void 0 : t.centerFn
1230
+ }), this;
1227
1231
  }
1228
1232
  removeNode(e) {
1229
- return this.di.canvasController.removeNode(e), this;
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;
1230
1238
  }
1231
1239
  markPort(e) {
1232
- return this.di.canvasController.markPort(
1233
- e.id,
1234
- e.element,
1235
- e.nodeId,
1236
- e.centerFn,
1237
- e.direction
1238
- ), this;
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;
1239
1247
  }
1240
1248
  updatePort(e, t) {
1241
- return this.di.canvasController.updatePort(
1242
- e,
1243
- t == null ? void 0 : t.direction,
1244
- t == null ? void 0 : t.centerFn
1245
- ), this;
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;
1246
1253
  }
1247
1254
  unmarkPort(e) {
1248
1255
  return this.di.canvasController.unmarkPort(e), this;
1249
1256
  }
1250
1257
  addEdge(e) {
1251
- const t = e.shape !== void 0 ? k(e.shape) : this.edgeShapeFactory;
1252
- return this.di.canvasController.addEdge(
1253
- e.id,
1254
- e.from,
1255
- e.to,
1256
- t,
1257
- e.priority
1258
- ), this;
1258
+ const t = e.shape !== void 0 ? R(e.shape) : this.edgeShapeFactory;
1259
+ return this.di.canvasController.addEdge({
1260
+ edgeId: e.id,
1261
+ from: e.from,
1262
+ to: e.to,
1263
+ shapeFactory: t,
1264
+ priority: e.priority
1265
+ }), this;
1259
1266
  }
1260
1267
  updateEdge(e, t) {
1261
- const s = t.shape !== void 0 ? k(t.shape) : void 0;
1262
- return this.di.canvasController.updateEdge(e, s, t.priority), this;
1268
+ const s = (t == null ? void 0 : t.shape) !== void 0 ? R(t.shape) : void 0;
1269
+ return this.di.canvasController.updateEdge({
1270
+ edgeId: e,
1271
+ shape: s,
1272
+ priority: t == null ? void 0 : t.priority
1273
+ }), this;
1263
1274
  }
1264
1275
  removeEdge(e) {
1265
1276
  return this.di.canvasController.removeEdge(e), this;
1266
1277
  }
1267
1278
  patchViewportMatrix(e) {
1268
- return this.di.canvasController.patchViewportMatrix(
1269
- e.scale ?? null,
1270
- e.dx ?? null,
1271
- e.dy ?? null
1272
- ), this;
1279
+ return this.di.canvasController.patchViewportMatrix(e), this;
1273
1280
  }
1274
1281
  patchContentMatrix(e) {
1275
- return this.di.canvasController.patchContentMatrix(
1276
- e.scale ?? null,
1277
- e.dx ?? null,
1278
- e.dy ?? null
1279
- ), this;
1282
+ return this.di.canvasController.patchContentMatrix(e), this;
1280
1283
  }
1281
1284
  clear() {
1282
- return this.di.canvasController.clear(), this;
1285
+ return this.di.canvasController.clear(), this.nodes.clear(), this;
1283
1286
  }
1284
1287
  attach(e) {
1285
1288
  return this.di.canvasController.attach(e), this;
@@ -1288,48 +1291,48 @@ class xe {
1288
1291
  return this.di.canvasController.detach(), this;
1289
1292
  }
1290
1293
  destroy() {
1291
- this.di.canvasController.destroy();
1294
+ this.clear(), this.di.canvasController.destroy(), this.nodesResizeObserver.disconnect();
1292
1295
  }
1293
1296
  }
1294
- const O = (r, e, t) => {
1295
- const { x: s, y: o, width: i, height: n } = r.getBoundingClientRect();
1296
- return e >= s && e < s + i && t >= o && t <= o + n;
1297
- }, V = (r, e, t) => e >= 0 && e < r.innerWidth && t >= 0 && t <= r.innerHeight, I = (r, e) => {
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) => {
1298
1301
  e !== null ? r.style.cursor = e : r.style.removeProperty("cursor");
1299
1302
  };
1300
1303
  class Ee {
1301
1304
  constructor(e, t) {
1302
- a(this, "model");
1303
- a(this, "transformation");
1304
- a(this, "maxNodePriority", 0);
1305
- a(this, "nodes", /* @__PURE__ */ new Map());
1306
- a(this, "grabbedNodeId", null);
1307
- a(this, "onNodeDrag");
1308
- a(this, "onBeforeNodeDrag");
1309
- a(this, "nodeIdGenerator", new F(
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(
1310
1313
  (e) => this.nodes.has(e)
1311
1314
  ));
1312
- a(this, "element", null);
1313
- a(this, "onCanvasMouseUp", () => {
1315
+ n(this, "element", null);
1316
+ n(this, "onCanvasMouseUp", () => {
1314
1317
  this.cancelMouseDrag();
1315
1318
  });
1316
- a(this, "onCanvasMouseMove", (e) => {
1317
- if (this.element !== null && (!O(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY))) {
1319
+ n(this, "onCanvasMouseMove", (e) => {
1320
+ if (this.element !== null && (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY))) {
1318
1321
  this.cancelMouseDrag();
1319
1322
  return;
1320
1323
  }
1321
1324
  this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
1322
1325
  });
1323
- a(this, "onCanvasTouchStart", (e) => {
1326
+ n(this, "onCanvasTouchStart", (e) => {
1324
1327
  this.previousTouchCoords = [
1325
1328
  e.touches[0].clientX,
1326
1329
  e.touches[0].clientY
1327
1330
  ];
1328
1331
  });
1329
- a(this, "onCanvasTouchMove", (e) => {
1332
+ n(this, "onCanvasTouchMove", (e) => {
1330
1333
  if (e.touches.length === 1) {
1331
1334
  const t = e.touches[0];
1332
- if (this.element !== null && (!O(this.element, t.clientX, t.clientY) || !V(this.window, t.clientX, t.clientY))) {
1335
+ if (this.element !== null && (!W(this.element, t.clientX, t.clientY) || !V(this.window, t.clientX, t.clientY))) {
1333
1336
  this.cancelTouchDrag();
1334
1337
  return;
1335
1338
  }
@@ -1343,23 +1346,23 @@ class Ee {
1343
1346
  }
1344
1347
  }
1345
1348
  });
1346
- a(this, "onCanvasTouchEnd", (e) => {
1349
+ n(this, "onCanvasTouchEnd", (e) => {
1347
1350
  e.touches.length > 0 ? this.previousTouchCoords = [
1348
1351
  e.touches[0].clientX,
1349
1352
  e.touches[0].clientY
1350
1353
  ] : this.cancelTouchDrag();
1351
1354
  });
1352
- a(this, "previousTouchCoords", null);
1353
- a(this, "freezePriority");
1354
- a(this, "window", window);
1355
- a(this, "dragCursor");
1356
- var i, n;
1355
+ n(this, "previousTouchCoords", null);
1356
+ n(this, "freezePriority");
1357
+ n(this, "window", window);
1358
+ n(this, "dragCursor");
1359
+ var i, h;
1357
1360
  this.canvas = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1358
1361
  const s = () => {
1359
1362
  };
1360
1363
  this.onNodeDrag = ((i = t == null ? void 0 : t.events) == null ? void 0 : i.onNodeDrag) ?? s;
1361
1364
  const o = () => !0;
1362
- this.onBeforeNodeDrag = ((n = t == null ? void 0 : t.events) == null ? void 0 : n.onBeforeNodeDrag) ?? o, this.freezePriority = (t == null ? void 0 : t.grabPriorityStrategy) === "freeze", this.dragCursor = (t == null ? void 0 : t.dragCursor) !== void 0 ? t.dragCursor : "grab";
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";
1363
1366
  }
1364
1367
  addNode(e) {
1365
1368
  const t = this.nodeIdGenerator.create(e.id);
@@ -1367,20 +1370,20 @@ class Ee {
1367
1370
  const s = (i) => {
1368
1371
  if (this.element === null)
1369
1372
  return;
1370
- const n = this.model.getNode(t);
1373
+ const h = this.model.getNode(t);
1371
1374
  this.onBeforeNodeDrag({
1372
1375
  nodeId: t,
1373
1376
  element: e.element,
1374
- x: n.x,
1375
- y: n.y
1376
- }) && (i.stopImmediatePropagation(), this.grabbedNodeId = t, I(this.element, this.dragCursor), this.moveNodeOnTop(t), this.window.addEventListener("mouseup", this.onCanvasMouseUp), this.window.addEventListener("mousemove", this.onCanvasMouseMove));
1377
+ x: h.x,
1378
+ 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));
1377
1380
  }, o = (i) => {
1378
- const n = this.model.getNode(t);
1381
+ const h = this.model.getNode(t);
1379
1382
  this.onBeforeNodeDrag({
1380
1383
  nodeId: t,
1381
1384
  element: e.element,
1382
- x: n.x,
1383
- y: n.y
1385
+ x: h.x,
1386
+ y: h.y
1384
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));
1385
1388
  };
1386
1389
  return this.nodes.set(t, {
@@ -1439,8 +1442,8 @@ class Ee {
1439
1442
  dragNode(e, t, s) {
1440
1443
  const o = this.model.getNode(e);
1441
1444
  if (o === null)
1442
- throw new C("failed to drag nonexisting node");
1443
- const i = this.canvas.transformation.getContentMatrix(), n = i.scale * o.x + i.dx, h = i.scale * o.y + i.dy, c = n + t, d = h + s, u = this.canvas.transformation.getViewportMatrix(), w = u.scale * c + u.dx, m = u.scale * d + u.dy;
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;
1444
1447
  this.canvas.updateNode(e, { x: w, y: m }), this.onNodeDrag({
1445
1448
  nodeId: e,
1446
1449
  element: o.element,
@@ -1462,7 +1465,7 @@ class Ee {
1462
1465
  });
1463
1466
  }
1464
1467
  cancelMouseDrag() {
1465
- this.grabbedNodeId = null, this.element !== null && I(this.element, null), this.removeMouseDragListeners();
1468
+ this.grabbedNodeId = null, this.element !== null && O(this.element, null), this.removeMouseDragListeners();
1466
1469
  }
1467
1470
  removeMouseDragListeners() {
1468
1471
  this.window.removeEventListener("mouseup", this.onCanvasMouseUp), this.window.removeEventListener("mousemove", this.onCanvasMouseMove);
@@ -1474,26 +1477,26 @@ class Ee {
1474
1477
  this.window.removeEventListener("touchmove", this.onCanvasTouchMove), this.window.removeEventListener("touchend", this.onCanvasTouchEnd), this.window.removeEventListener("touchcancel", this.onCanvasTouchEnd);
1475
1478
  }
1476
1479
  }
1477
- const Ce = () => {
1478
- }, Ae = (r, e) => e, Se = (r, e) => {
1480
+ const Ae = () => {
1481
+ }, Ce = (r, e) => e, Pe = (r, e) => {
1479
1482
  const t = e !== null ? 1 / e : null, s = r !== null ? 1 / r : null;
1480
1483
  return (o, i) => s !== null && i.scale > s && i.scale > o.scale || t !== null && i.scale < t && i.scale < o.scale ? o : i;
1481
- }, Pe = (r, e, t, s) => (o, i, n, h) => {
1482
- let c = i.dx, d = i.dy;
1483
- r !== null && c < r && c < o.dx && (c = o.dx);
1484
- const u = n * o.scale;
1485
- e !== null && c > e - u && c > o.dx && (c = o.dx), t !== null && d < t && d < o.dy && (d = o.dy);
1486
- const w = h * o.scale;
1487
- return s !== null && d > s - w && d > o.dy && (d = o.dy), { scale: i.scale, dx: c, dy: d };
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 };
1488
1491
  }, K = (r) => {
1489
1492
  switch (r.type) {
1490
1493
  case "scale-limit":
1491
- return Se(
1494
+ return Pe(
1492
1495
  r.minContentScale ?? null,
1493
1496
  r.maxContentScale ?? null
1494
1497
  );
1495
1498
  case "shift-limit":
1496
- return Pe(
1499
+ return Se(
1497
1500
  r.minX ?? null,
1498
1501
  r.maxX ?? null,
1499
1502
  r.minY ?? null,
@@ -1503,53 +1506,53 @@ const Ce = () => {
1503
1506
  return r.preprocessorFn;
1504
1507
  }
1505
1508
  }, Me = (r) => (e, t, s, o) => r.reduce(
1506
- (i, n) => n(e, i, s, o),
1509
+ (i, h) => h(e, i, s, o),
1507
1510
  t
1508
1511
  );
1509
1512
  class Ne {
1510
1513
  constructor(e, t) {
1511
- a(this, "model");
1512
- a(this, "transformation");
1513
- a(this, "element", null);
1514
- a(this, "prevTouches", null);
1515
- a(this, "onTransformFinished");
1516
- a(this, "transformPreprocessor");
1517
- a(this, "isScalable");
1518
- a(this, "isShiftable");
1519
- a(this, "wheelSensitivity");
1520
- a(this, "window", window);
1521
- a(this, "onMouseDown", () => {
1522
- this.element !== null && (I(this.element, this.shiftCursor), this.window.addEventListener("mousemove", this.onMouseMove), this.window.addEventListener("mouseup", this.onMouseUp));
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));
1523
1526
  });
1524
- a(this, "onMouseMove", (e) => {
1527
+ n(this, "onMouseMove", (e) => {
1525
1528
  if (!this.isShiftable || this.element === null)
1526
1529
  return;
1527
- if (!O(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY)) {
1530
+ if (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY)) {
1528
1531
  this.stopMouseDrag();
1529
1532
  return;
1530
1533
  }
1531
1534
  const t = -e.movementX, s = -e.movementY;
1532
1535
  this.moveViewport(t, s);
1533
1536
  });
1534
- a(this, "onMouseUp", () => {
1537
+ n(this, "onMouseUp", () => {
1535
1538
  this.stopMouseDrag();
1536
1539
  });
1537
- a(this, "onWheelScroll", (e) => {
1540
+ n(this, "onWheelScroll", (e) => {
1538
1541
  if (this.element === null || this.isScalable === !1)
1539
1542
  return;
1540
1543
  e.preventDefault();
1541
- const { left: t, top: s } = this.element.getBoundingClientRect(), o = e.clientX - t, i = e.clientY - s, h = 1 / (e.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
1542
- this.scaleViewport(h, o, i);
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);
1543
1546
  });
1544
- a(this, "onTouchStart", (e) => {
1547
+ n(this, "onTouchStart", (e) => {
1545
1548
  this.prevTouches = this.getAverageTouch(e), this.window.addEventListener("touchmove", this.onTouchMove), this.window.addEventListener("touchend", this.onTouchEnd), this.window.addEventListener("touchcancel", this.onTouchEnd);
1546
1549
  });
1547
- a(this, "onTouchMove", (e) => {
1550
+ n(this, "onTouchMove", (e) => {
1548
1551
  if (this.prevTouches === null || !this.isShiftable || this.element === null)
1549
1552
  return;
1550
1553
  const t = this.getAverageTouch(e);
1551
1554
  if (!t.touches.every(
1552
- (o) => O(this.element, o[0], o[1]) && V(this.window, o[0], o[1])
1555
+ (o) => W(this.element, o[0], o[1]) && V(this.window, o[0], o[1])
1553
1556
  )) {
1554
1557
  this.stopTouchDrag();
1555
1558
  return;
@@ -1558,15 +1561,15 @@ class Ne {
1558
1561
  -(t.x - this.prevTouches.x),
1559
1562
  -(t.y - this.prevTouches.y)
1560
1563
  ), t.touchesCnt === 2 && this.isScalable) {
1561
- const { left: o, top: i } = this.element.getBoundingClientRect(), n = this.prevTouches.x - o, h = this.prevTouches.y - i, d = 1 / (t.scale / this.prevTouches.scale);
1562
- this.scaleViewport(d, n, h);
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);
1563
1566
  }
1564
1567
  this.prevTouches = t;
1565
1568
  });
1566
- a(this, "onTouchEnd", (e) => {
1569
+ n(this, "onTouchEnd", (e) => {
1567
1570
  e.touches.length > 0 ? this.prevTouches = this.getAverageTouch(e) : this.stopTouchDrag();
1568
1571
  });
1569
- a(this, "observer", new ResizeObserver(() => {
1572
+ n(this, "observer", new ResizeObserver(() => {
1570
1573
  if (this.element !== null) {
1571
1574
  const e = this.canvas.transformation.getViewportMatrix(), { width: t, height: s } = this.element.getBoundingClientRect(), o = this.transformPreprocessor(
1572
1575
  e,
@@ -1577,17 +1580,17 @@ class Ne {
1577
1580
  this.canvas.patchViewportMatrix(o), this.onTransformFinished();
1578
1581
  }
1579
1582
  }));
1580
- a(this, "shiftCursor");
1581
- var i, n, h, c, d, u, w, m;
1582
- this.canvas = e, this.options = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((n = (i = this.options) == null ? void 0 : i.scale) == null ? void 0 : n.enabled) !== !1, this.isShiftable = ((c = (h = this.options) == null ? void 0 : h.shift) == null ? void 0 : c.enabled) !== !1;
1583
- const s = (u = (d = this.options) == null ? void 0 : d.scale) == null ? void 0 : u.wheelSensitivity;
1584
- this.wheelSensitivity = s !== void 0 ? s : 1.2, this.onTransformFinished = ((w = t == null ? void 0 : t.events) == null ? void 0 : w.onTransformFinished) ?? Ce;
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;
1585
1588
  const o = t == null ? void 0 : t.transformPreprocessor;
1586
1589
  o !== void 0 ? Array.isArray(o) ? this.transformPreprocessor = Me(
1587
1590
  o.map(
1588
1591
  (y) => K(y)
1589
1592
  )
1590
- ) : this.transformPreprocessor = K(o) : this.transformPreprocessor = Ae, this.shiftCursor = ((m = t == null ? void 0 : t.shift) == null ? void 0 : m.cursor) !== void 0 ? t.shift.cursor : "grab";
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";
1591
1594
  }
1592
1595
  addNode(e) {
1593
1596
  return this.canvas.addNode(e), this;
@@ -1636,19 +1639,19 @@ class Ne {
1636
1639
  }
1637
1640
  getAverageTouch(e) {
1638
1641
  const t = [], s = e.touches.length;
1639
- for (let c = 0; c < s; c++)
1640
- t.push([e.touches[c].clientX, e.touches[c].clientY]);
1642
+ for (let d = 0; d < s; d++)
1643
+ t.push([e.touches[d].clientX, e.touches[d].clientY]);
1641
1644
  const o = t.reduce(
1642
- (c, d) => [c[0] + d[0], c[1] + d[1]],
1645
+ (d, c) => [d[0] + c[0], d[1] + c[1]],
1643
1646
  [0, 0]
1644
- ), i = [o[0] / s, o[1] / s], h = t.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1645
- (c, d) => c + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
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]),
1646
1649
  0
1647
1650
  );
1648
1651
  return {
1649
1652
  x: i[0],
1650
1653
  y: i[1],
1651
- scale: h / s,
1654
+ scale: a / s,
1652
1655
  touchesCnt: s,
1653
1656
  touches: t
1654
1657
  };
@@ -1660,13 +1663,13 @@ class Ne {
1660
1663
  dy: s.dy + s.scale * t
1661
1664
  };
1662
1665
  if (this.element !== null) {
1663
- const { width: i, height: n } = this.element.getBoundingClientRect(), h = this.transformPreprocessor(
1666
+ const { width: i, height: h } = this.element.getBoundingClientRect(), a = this.transformPreprocessor(
1664
1667
  s,
1665
1668
  o,
1666
1669
  i,
1667
- n
1670
+ h
1668
1671
  );
1669
- this.canvas.patchViewportMatrix(h), this.onTransformFinished();
1672
+ this.canvas.patchViewportMatrix(a), this.onTransformFinished();
1670
1673
  }
1671
1674
  }
1672
1675
  scaleViewport(e, t, s) {
@@ -1676,16 +1679,16 @@ class Ne {
1676
1679
  scale: o.scale * e,
1677
1680
  dx: o.scale * (1 - e) * t + o.dx,
1678
1681
  dy: o.scale * (1 - e) * s + o.dy
1679
- }, { width: n, height: h } = this.element.getBoundingClientRect(), c = this.transformPreprocessor(
1682
+ }, { width: h, height: a } = this.element.getBoundingClientRect(), d = this.transformPreprocessor(
1680
1683
  o,
1681
1684
  i,
1682
- n,
1683
- h
1685
+ h,
1686
+ a
1684
1687
  );
1685
- this.canvas.patchViewportMatrix(c), this.onTransformFinished();
1688
+ this.canvas.patchViewportMatrix(d), this.onTransformFinished();
1686
1689
  }
1687
1690
  stopMouseDrag() {
1688
- this.element !== null && I(this.element, null), this.removeMouseDragListeners();
1691
+ this.element !== null && O(this.element, null), this.removeMouseDragListeners();
1689
1692
  }
1690
1693
  removeMouseDragListeners() {
1691
1694
  this.window.removeEventListener("mousemove", this.onMouseMove), this.window.removeEventListener("mouseup", this.onMouseUp);
@@ -1699,11 +1702,11 @@ class Ne {
1699
1702
  }
1700
1703
  class Te {
1701
1704
  constructor() {
1702
- a(this, "coreOptions");
1703
- a(this, "dragOptions");
1704
- a(this, "transformOptions");
1705
- a(this, "isDraggable", !1);
1706
- a(this, "isTransformable", !1);
1705
+ n(this, "coreOptions");
1706
+ n(this, "dragOptions");
1707
+ n(this, "transformOptions");
1708
+ n(this, "isDraggable", !1);
1709
+ n(this, "isTransformable", !1);
1707
1710
  }
1708
1711
  setOptions(e) {
1709
1712
  return this.coreOptions = e, this;
@@ -1726,16 +1729,16 @@ export {
1726
1729
  B as CycleSquareEdgeShape,
1727
1730
  ne as DetourBezierEdgeShape,
1728
1731
  G as DetourStraightEdgeShape,
1729
- A as EdgeType,
1732
+ C as EdgeType,
1730
1733
  se as HorizontalEdgeShape,
1731
1734
  Te as HtmlGraphBuilder,
1732
- C as HtmlGraphError,
1735
+ f as HtmlGraphError,
1733
1736
  re as StraightEdgeShape,
1734
1737
  Ee as UserDraggableNodesCanvas,
1735
1738
  Ne as UserTransformableCanvas,
1736
1739
  oe as VerticalEdgeShape,
1737
1740
  ae as createBezierEdgeShapeFactory,
1738
- de as createHorizontalEdgeShapeFactory,
1741
+ ce as createHorizontalEdgeShapeFactory,
1739
1742
  he as createStraightEdgeShareFactory,
1740
- ce as createVerticalEdgeShapeFactory
1743
+ de as createVerticalEdgeShapeFactory
1741
1744
  };