@html-graph/html-graph 0.0.59 → 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, g = 0, w = 0;
246
- const m = c > 0, y = c < s, v = m && y;
247
- if (m && (d = -o, g = -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 + g * 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} `, g = this.targetArrow ? "" : ` M ${i.x} ${i.y} L ${e.x} ${e.y}`;
318
- return `${d}${c}${g}`;
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), g = p({ x: e.x - c, y: e.y }, s, e), w = Math.max((d.x + g.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: g.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, g, 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), g = p({ x: e.x - c, y: e.y }, s, e), w = Math.max((d.y + g.y) / 2, h), m = e.x / 2, y = { x: d.x, y: o > 0 ? w : -h }, v = { x: m, y: y.y }, S = {
429
- x: g.x,
430
- y: o > 0 ? e.y - w : e.y + h
431
- }, P = { x: m, y: S.y };
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 = {
439
+ x: u.x,
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, g, 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 }
462
- ].map((m) => p(m, e, l)), g = [
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} `;
468
- return `${this.arrow !== null ? "" : w}${g}`;
470
+ { x: h, y: a },
471
+ { x: h, y: -a }
472
+ ].map((m) => p(m, e, l)), u = [
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} `;
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, g = this.side, w = this.arrowLength + d, m = w + 2 * g;
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, g = 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,
550
- y: w.y + g
559
+ x: w.x + c,
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,
557
- y: y.y + g
558
- }, S = { x: (m.x + v.x) / 2, y: (m.y + v.y) / 2 }, P = {
566
+ x: y.x + c,
567
+ y: y.y + u
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,
566
- y: w.y + g
575
+ x: w.x + c,
576
+ y: w.y + u
567
577
  }, T = {
568
- x: y.x + d,
569
- y: y.y + g
578
+ x: y.x + c,
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, g) {
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(g) * d, this.detourY = Math.sin(g) * 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
- ), g = this.detourX * o, w = this.detourY * i, m = { x: d.x + g, 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
- ), v = { x: y.x + g, y: y.y + w };
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
922
  constructor(e, t) {
937
- a(this, "canvasWrapper", null);
938
- a(this, "host", ue());
939
- a(this, "container", ge());
940
- a(this, "nodesResizeObserver");
941
- a(this, "nodeElementToIdMap", /* @__PURE__ */ new Map());
942
- a(this, "nodeIdToWrapperElementMap", new ye());
943
- a(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
944
- this.graphStore = e, this.viewportTransformer = t, this.host.appendChild(this.container), this.nodesResizeObserver = this.createNodesResizeObserver();
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.nodesResizeObserver.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.nodesResizeObserver.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,104 +961,83 @@ class me {
977
961
  });
978
962
  }
979
963
  destroy() {
980
- this.nodesResizeObserver.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}`;
1001
- }
1002
- updatePortEdges(e) {
1003
- this.graphStore.getPortAdjacentEdgeIds(e).forEach((s) => {
1004
- this.updateEdgeCoordinates(s);
1005
- });
1006
- }
1007
- createNodesResizeObserver() {
1008
- return new ResizeObserver((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 } = t.getBoundingClientRect(), i = this.viewportTransformer.getViewportMatrix().scale, n = this.graphStore.getNode(e), { x: h, y: c } = n.centerFn(s, o), d = n.x - i * h, g = n.y - i * c;
1019
- t.style.transform = `matrix(1, 0, 0, 1, ${d}, ${g})`;
1020
- }
1021
- updateEdgeCoordinates(e) {
1022
- const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from), o = this.graphStore.getPort(t.to), i = s.element.getBoundingClientRect(), n = o.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), 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
1025
- }, g = {
1026
- x: c.scale * (n.left - h.left) + c.dx,
1027
- y: c.scale * (n.top - h.top) + c.dy
978
+ this.edgeIdToElementMap.set(e, s.shape.svg), this.container.appendChild(s.shape.svg);
979
+ }
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
984
+ }, u = {
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
- x: g.x + m.x,
1039
- y: g.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;
997
+ x: u.x + m.x,
998
+ 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;
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) {
1054
- a(this, "publicViewportTransformer");
1055
- a(this, "publicGraphStore");
1056
- a(this, "canvasController");
1057
- const n = new Q(), h = new q();
1058
- this.publicGraphStore = new ee(h), this.publicViewportTransformer = new Z(
1059
- n
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
1060
1023
  );
1061
- const c = new me(h, n);
1024
+ const o = new ye(s, t);
1062
1025
  this.canvasController = new le(
1063
- h,
1064
- c,
1065
- n,
1066
- e,
1067
- t,
1068
1026
  s,
1069
1027
  o,
1070
- i
1028
+ t,
1029
+ e.nodesCenterFn,
1030
+ e.portsCenterFn,
1031
+ e.portsDirection,
1032
+ e.nodesPriorityFn,
1033
+ e.edgesPriorityFn
1071
1034
  );
1072
1035
  }
1073
1036
  }
1074
1037
  const H = (r, e) => ({
1075
1038
  x: r / 2,
1076
1039
  y: e / 2
1077
- }), u = {
1040
+ }), g = {
1078
1041
  edgeColor: "#5c5c5c",
1079
1042
  edgeWidth: 1,
1080
1043
  edgeArrowLength: 15,
@@ -1094,65 +1057,65 @@ const H = (r, e) => ({
1094
1057
  return r.factory;
1095
1058
  case "straight":
1096
1059
  return he({
1097
- color: r.color ?? u.edgeColor,
1098
- width: r.width ?? u.edgeWidth,
1099
- arrowLength: r.arrowLength ?? u.edgeArrowLength,
1100
- arrowWidth: r.arrowWidth ?? u.edgeArrowWidth,
1101
- arrowOffset: r.arrowOffset ?? u.edgeArrowOffset,
1102
- hasSourceArrow: r.hasSourceArrow ?? u.hasSourceArrow,
1103
- hasTargetArrow: r.hasTargetArrow ?? u.hasTargetArrow,
1104
- cycleSquareSide: r.cycleSquareSide ?? u.cycleSize,
1105
- roundness: r.roundness ?? u.roundness,
1106
- detourDistance: r.detourDistance ?? u.detourDistance,
1107
- detourDirection: r.detourDirection ?? u.detourDirection
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
1108
1071
  });
1109
1072
  case "horizontal":
1110
- return de({
1111
- color: r.color ?? u.edgeColor,
1112
- width: r.width ?? u.edgeWidth,
1113
- arrowLength: r.arrowLength ?? u.edgeArrowLength,
1114
- arrowWidth: r.arrowWidth ?? u.edgeArrowWidth,
1115
- arrowOffset: r.arrowOffset ?? u.edgeArrowOffset,
1116
- hasSourceArrow: r.hasSourceArrow ?? u.hasSourceArrow,
1117
- hasTargetArrow: r.hasTargetArrow ?? u.hasTargetArrow,
1118
- cycleSquareSide: r.cycleSquareSide ?? u.cycleSize,
1119
- roundness: r.roundness ?? u.roundness,
1120
- detourDistance: r.detourDistance ?? u.detourDistance,
1121
- detourDirection: r.detourDirection ?? u.detourDirection
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
1122
1085
  });
1123
1086
  case "vertical":
1124
- return ce({
1125
- color: r.color ?? u.edgeColor,
1126
- width: r.width ?? u.edgeWidth,
1127
- arrowLength: r.arrowLength ?? u.edgeArrowLength,
1128
- arrowWidth: r.arrowWidth ?? u.edgeArrowWidth,
1129
- arrowOffset: r.arrowOffset ?? u.edgeArrowOffset,
1130
- hasSourceArrow: r.hasSourceArrow ?? u.hasSourceArrow,
1131
- hasTargetArrow: r.hasTargetArrow ?? u.hasTargetArrow,
1132
- cycleSquareSide: r.cycleSquareSide ?? u.cycleSize,
1133
- roundness: r.roundness ?? u.roundness,
1134
- detourDistance: r.detourDistance ?? u.detourDistance,
1135
- detourDirection: r.detourDirection ?? u.detourDirection
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
1136
1099
  });
1137
1100
  default:
1138
1101
  return ae({
1139
- color: r.color ?? u.edgeColor,
1140
- width: r.width ?? u.edgeWidth,
1141
- arrowLength: r.arrowLength ?? u.edgeArrowLength,
1142
- arrowWidth: r.arrowWidth ?? u.edgeArrowWidth,
1143
- hasSourceArrow: r.hasSourceArrow ?? u.hasSourceArrow,
1144
- hasTargetArrow: r.hasTargetArrow ?? u.hasTargetArrow,
1145
- cycleRadius: r.cycleRadius ?? u.cycleSize,
1146
- detourDistance: r.detourDistance ?? u.detourDistance,
1147
- detourDirection: r.detourDirection ?? u.detourDirection,
1148
- smallCycleRadius: r.smallCycleRadius ?? u.smallCycleSize,
1149
- curvature: r.curvature ?? u.curvature
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
1150
1113
  });
1151
1114
  }
1152
1115
  }, z = (r) => () => r, U = z(0), k = () => {
1153
1116
  let r = 0;
1154
1117
  return () => r++;
1155
- }, ve = (r, e) => {
1118
+ }, pe = (r, e) => {
1156
1119
  const t = [
1157
1120
  U,
1158
1121
  U
@@ -1160,9 +1123,9 @@ const H = (r, e) => ({
1160
1123
  r === "incremental" && (t[0] = k()), e === "incremental" && (t[1] = k());
1161
1124
  const s = k();
1162
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;
1163
- }, fe = (r) => {
1164
- var s, o, i, n, h, c;
1165
- const [e, t] = ve(
1126
+ }, ve = (r) => {
1127
+ var s, o, i, h, a, d;
1128
+ const [e, t] = pe(
1166
1129
  (s = r.nodes) == null ? void 0 : s.priority,
1167
1130
  (o = r.edges) == null ? void 0 : o.priority
1168
1131
  );
@@ -1172,106 +1135,154 @@ const H = (r, e) => ({
1172
1135
  priorityFn: e
1173
1136
  },
1174
1137
  ports: {
1175
- centerFn: ((n = r.ports) == null ? void 0 : n.centerFn) ?? H,
1176
- 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
1177
1140
  },
1178
1141
  edges: {
1179
- shapeFactory: R(((c = r.edges) == null ? void 0 : c.shape) ?? {}),
1142
+ shapeFactory: R(((d = r.edges) == null ? void 0 : d.shape) ?? {}),
1180
1143
  priorityFn: t
1181
1144
  }
1182
1145
  };
1183
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
+ }
1184
1184
  class xe {
1185
1185
  constructor(e) {
1186
- a(this, "transformation");
1187
- a(this, "model");
1188
- a(this, "di");
1189
- a(this, "edgeShapeFactory");
1190
- this.apiOptions = e;
1191
- const t = fe(this.apiOptions ?? {});
1192
- this.di = new pe(
1193
- t.nodes.centerFn,
1194
- t.ports.centerFn,
1195
- t.ports.direction,
1196
- t.nodes.priorityFn,
1197
- t.edges.priorityFn
1198
- ), 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;
1199
1211
  }
1200
1212
  addNode(e) {
1201
- return this.di.canvasController.addNode(
1202
- e.id,
1203
- e.element,
1204
- e.x,
1205
- e.y,
1206
- e.ports,
1207
- e.centerFn,
1208
- e.priority
1209
- ), 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;
1210
1223
  }
1211
1224
  updateNode(e, t) {
1212
- return this.di.canvasController.updateNode(
1213
- e,
1214
- t.x,
1215
- t.y,
1216
- t.priority,
1217
- t.centerFn
1218
- ), 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;
1219
1231
  }
1220
1232
  removeNode(e) {
1221
- 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;
1222
1238
  }
1223
1239
  markPort(e) {
1224
- return this.di.canvasController.markPort(
1225
- e.id,
1226
- e.element,
1227
- e.nodeId,
1228
- e.centerFn,
1229
- e.direction
1230
- ), 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;
1231
1247
  }
1232
1248
  updatePort(e, t) {
1233
- return this.di.canvasController.updatePort(
1234
- e,
1235
- t == null ? void 0 : t.direction,
1236
- t == null ? void 0 : t.centerFn
1237
- ), 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;
1238
1253
  }
1239
1254
  unmarkPort(e) {
1240
1255
  return this.di.canvasController.unmarkPort(e), this;
1241
1256
  }
1242
1257
  addEdge(e) {
1243
1258
  const t = e.shape !== void 0 ? R(e.shape) : this.edgeShapeFactory;
1244
- return this.di.canvasController.addEdge(
1245
- e.id,
1246
- e.from,
1247
- e.to,
1248
- t,
1249
- e.priority
1250
- ), this;
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;
1251
1266
  }
1252
1267
  updateEdge(e, t) {
1253
- const s = t.shape !== void 0 ? R(t.shape) : void 0;
1254
- 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;
1255
1274
  }
1256
1275
  removeEdge(e) {
1257
1276
  return this.di.canvasController.removeEdge(e), this;
1258
1277
  }
1259
1278
  patchViewportMatrix(e) {
1260
- return this.di.canvasController.patchViewportMatrix(
1261
- e.scale ?? null,
1262
- e.dx ?? null,
1263
- e.dy ?? null
1264
- ), this;
1279
+ return this.di.canvasController.patchViewportMatrix(e), this;
1265
1280
  }
1266
1281
  patchContentMatrix(e) {
1267
- return this.di.canvasController.patchContentMatrix(
1268
- e.scale ?? null,
1269
- e.dx ?? null,
1270
- e.dy ?? null
1271
- ), this;
1282
+ return this.di.canvasController.patchContentMatrix(e), this;
1272
1283
  }
1273
1284
  clear() {
1274
- return this.di.canvasController.clear(), this;
1285
+ return this.di.canvasController.clear(), this.nodes.clear(), this;
1275
1286
  }
1276
1287
  attach(e) {
1277
1288
  return this.di.canvasController.attach(e), this;
@@ -1280,48 +1291,48 @@ class xe {
1280
1291
  return this.di.canvasController.detach(), this;
1281
1292
  }
1282
1293
  destroy() {
1283
- this.di.canvasController.destroy();
1294
+ this.clear(), this.di.canvasController.destroy(), this.nodesResizeObserver.disconnect();
1284
1295
  }
1285
1296
  }
1286
- const V = (r, e, t) => {
1287
- const { x: s, y: o, width: i, height: n } = r.getBoundingClientRect();
1288
- return e >= s && e < s + i && t >= o && t <= o + n;
1289
- }, O = (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) => {
1290
1301
  e !== null ? r.style.cursor = e : r.style.removeProperty("cursor");
1291
1302
  };
1292
1303
  class Ee {
1293
1304
  constructor(e, t) {
1294
- a(this, "model");
1295
- a(this, "transformation");
1296
- a(this, "maxNodePriority", 0);
1297
- a(this, "nodes", /* @__PURE__ */ new Map());
1298
- a(this, "grabbedNodeId", null);
1299
- a(this, "onNodeDrag");
1300
- a(this, "onBeforeNodeDrag");
1301
- 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(
1302
1313
  (e) => this.nodes.has(e)
1303
1314
  ));
1304
- a(this, "element", null);
1305
- a(this, "onCanvasMouseUp", () => {
1315
+ n(this, "element", null);
1316
+ n(this, "onCanvasMouseUp", () => {
1306
1317
  this.cancelMouseDrag();
1307
1318
  });
1308
- a(this, "onCanvasMouseMove", (e) => {
1309
- if (this.element !== null && (!V(this.element, e.clientX, e.clientY) || !O(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))) {
1310
1321
  this.cancelMouseDrag();
1311
1322
  return;
1312
1323
  }
1313
1324
  this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
1314
1325
  });
1315
- a(this, "onCanvasTouchStart", (e) => {
1326
+ n(this, "onCanvasTouchStart", (e) => {
1316
1327
  this.previousTouchCoords = [
1317
1328
  e.touches[0].clientX,
1318
1329
  e.touches[0].clientY
1319
1330
  ];
1320
1331
  });
1321
- a(this, "onCanvasTouchMove", (e) => {
1332
+ n(this, "onCanvasTouchMove", (e) => {
1322
1333
  if (e.touches.length === 1) {
1323
1334
  const t = e.touches[0];
1324
- if (this.element !== null && (!V(this.element, t.clientX, t.clientY) || !O(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))) {
1325
1336
  this.cancelTouchDrag();
1326
1337
  return;
1327
1338
  }
@@ -1335,23 +1346,23 @@ class Ee {
1335
1346
  }
1336
1347
  }
1337
1348
  });
1338
- a(this, "onCanvasTouchEnd", (e) => {
1349
+ n(this, "onCanvasTouchEnd", (e) => {
1339
1350
  e.touches.length > 0 ? this.previousTouchCoords = [
1340
1351
  e.touches[0].clientX,
1341
1352
  e.touches[0].clientY
1342
1353
  ] : this.cancelTouchDrag();
1343
1354
  });
1344
- a(this, "previousTouchCoords", null);
1345
- a(this, "freezePriority");
1346
- a(this, "window", window);
1347
- a(this, "dragCursor");
1348
- 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;
1349
1360
  this.canvas = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
1350
1361
  const s = () => {
1351
1362
  };
1352
1363
  this.onNodeDrag = ((i = t == null ? void 0 : t.events) == null ? void 0 : i.onNodeDrag) ?? s;
1353
1364
  const o = () => !0;
1354
- 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";
1355
1366
  }
1356
1367
  addNode(e) {
1357
1368
  const t = this.nodeIdGenerator.create(e.id);
@@ -1359,20 +1370,20 @@ class Ee {
1359
1370
  const s = (i) => {
1360
1371
  if (this.element === null)
1361
1372
  return;
1362
- const n = this.model.getNode(t);
1373
+ const h = this.model.getNode(t);
1363
1374
  this.onBeforeNodeDrag({
1364
1375
  nodeId: t,
1365
1376
  element: e.element,
1366
- x: n.x,
1367
- y: n.y
1368
- }) && (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));
1369
1380
  }, o = (i) => {
1370
- const n = this.model.getNode(t);
1381
+ const h = this.model.getNode(t);
1371
1382
  this.onBeforeNodeDrag({
1372
1383
  nodeId: t,
1373
1384
  element: e.element,
1374
- x: n.x,
1375
- y: n.y
1385
+ x: h.x,
1386
+ y: h.y
1376
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));
1377
1388
  };
1378
1389
  return this.nodes.set(t, {
@@ -1431,8 +1442,8 @@ class Ee {
1431
1442
  dragNode(e, t, s) {
1432
1443
  const o = this.model.getNode(e);
1433
1444
  if (o === null)
1434
- throw new C("failed to drag nonexisting node");
1435
- 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, g = this.canvas.transformation.getViewportMatrix(), w = g.scale * c + g.dx, m = g.scale * d + g.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;
1436
1447
  this.canvas.updateNode(e, { x: w, y: m }), this.onNodeDrag({
1437
1448
  nodeId: e,
1438
1449
  element: o.element,
@@ -1454,7 +1465,7 @@ class Ee {
1454
1465
  });
1455
1466
  }
1456
1467
  cancelMouseDrag() {
1457
- 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();
1458
1469
  }
1459
1470
  removeMouseDragListeners() {
1460
1471
  this.window.removeEventListener("mouseup", this.onCanvasMouseUp), this.window.removeEventListener("mousemove", this.onCanvasMouseMove);
@@ -1466,26 +1477,26 @@ class Ee {
1466
1477
  this.window.removeEventListener("touchmove", this.onCanvasTouchMove), this.window.removeEventListener("touchend", this.onCanvasTouchEnd), this.window.removeEventListener("touchcancel", this.onCanvasTouchEnd);
1467
1478
  }
1468
1479
  }
1469
- const Ce = () => {
1470
- }, Ae = (r, e) => e, Se = (r, e) => {
1480
+ const Ae = () => {
1481
+ }, Ce = (r, e) => e, Pe = (r, e) => {
1471
1482
  const t = e !== null ? 1 / e : null, s = r !== null ? 1 / r : null;
1472
1483
  return (o, i) => s !== null && i.scale > s && i.scale > o.scale || t !== null && i.scale < t && i.scale < o.scale ? o : i;
1473
- }, Pe = (r, e, t, s) => (o, i, n, h) => {
1474
- let c = i.dx, d = i.dy;
1475
- r !== null && c < r && c < o.dx && (c = o.dx);
1476
- const g = n * o.scale;
1477
- e !== null && c > e - g && c > o.dx && (c = o.dx), t !== null && d < t && d < o.dy && (d = o.dy);
1478
- const w = h * o.scale;
1479
- 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 };
1480
1491
  }, K = (r) => {
1481
1492
  switch (r.type) {
1482
1493
  case "scale-limit":
1483
- return Se(
1494
+ return Pe(
1484
1495
  r.minContentScale ?? null,
1485
1496
  r.maxContentScale ?? null
1486
1497
  );
1487
1498
  case "shift-limit":
1488
- return Pe(
1499
+ return Se(
1489
1500
  r.minX ?? null,
1490
1501
  r.maxX ?? null,
1491
1502
  r.minY ?? null,
@@ -1495,53 +1506,53 @@ const Ce = () => {
1495
1506
  return r.preprocessorFn;
1496
1507
  }
1497
1508
  }, Me = (r) => (e, t, s, o) => r.reduce(
1498
- (i, n) => n(e, i, s, o),
1509
+ (i, h) => h(e, i, s, o),
1499
1510
  t
1500
1511
  );
1501
1512
  class Ne {
1502
1513
  constructor(e, t) {
1503
- a(this, "model");
1504
- a(this, "transformation");
1505
- a(this, "element", null);
1506
- a(this, "prevTouches", null);
1507
- a(this, "onTransformFinished");
1508
- a(this, "transformPreprocessor");
1509
- a(this, "isScalable");
1510
- a(this, "isShiftable");
1511
- a(this, "wheelSensitivity");
1512
- a(this, "window", window);
1513
- a(this, "onMouseDown", () => {
1514
- 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));
1515
1526
  });
1516
- a(this, "onMouseMove", (e) => {
1527
+ n(this, "onMouseMove", (e) => {
1517
1528
  if (!this.isShiftable || this.element === null)
1518
1529
  return;
1519
- if (!V(this.element, e.clientX, e.clientY) || !O(this.window, e.clientX, e.clientY)) {
1530
+ if (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY)) {
1520
1531
  this.stopMouseDrag();
1521
1532
  return;
1522
1533
  }
1523
1534
  const t = -e.movementX, s = -e.movementY;
1524
1535
  this.moveViewport(t, s);
1525
1536
  });
1526
- a(this, "onMouseUp", () => {
1537
+ n(this, "onMouseUp", () => {
1527
1538
  this.stopMouseDrag();
1528
1539
  });
1529
- a(this, "onWheelScroll", (e) => {
1540
+ n(this, "onWheelScroll", (e) => {
1530
1541
  if (this.element === null || this.isScalable === !1)
1531
1542
  return;
1532
1543
  e.preventDefault();
1533
- 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);
1534
- 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);
1535
1546
  });
1536
- a(this, "onTouchStart", (e) => {
1547
+ n(this, "onTouchStart", (e) => {
1537
1548
  this.prevTouches = this.getAverageTouch(e), this.window.addEventListener("touchmove", this.onTouchMove), this.window.addEventListener("touchend", this.onTouchEnd), this.window.addEventListener("touchcancel", this.onTouchEnd);
1538
1549
  });
1539
- a(this, "onTouchMove", (e) => {
1550
+ n(this, "onTouchMove", (e) => {
1540
1551
  if (this.prevTouches === null || !this.isShiftable || this.element === null)
1541
1552
  return;
1542
1553
  const t = this.getAverageTouch(e);
1543
1554
  if (!t.touches.every(
1544
- (o) => V(this.element, o[0], o[1]) && O(this.window, o[0], o[1])
1555
+ (o) => W(this.element, o[0], o[1]) && V(this.window, o[0], o[1])
1545
1556
  )) {
1546
1557
  this.stopTouchDrag();
1547
1558
  return;
@@ -1550,15 +1561,15 @@ class Ne {
1550
1561
  -(t.x - this.prevTouches.x),
1551
1562
  -(t.y - this.prevTouches.y)
1552
1563
  ), t.touchesCnt === 2 && this.isScalable) {
1553
- 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);
1554
- 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);
1555
1566
  }
1556
1567
  this.prevTouches = t;
1557
1568
  });
1558
- a(this, "onTouchEnd", (e) => {
1569
+ n(this, "onTouchEnd", (e) => {
1559
1570
  e.touches.length > 0 ? this.prevTouches = this.getAverageTouch(e) : this.stopTouchDrag();
1560
1571
  });
1561
- a(this, "observer", new ResizeObserver(() => {
1572
+ n(this, "observer", new ResizeObserver(() => {
1562
1573
  if (this.element !== null) {
1563
1574
  const e = this.canvas.transformation.getViewportMatrix(), { width: t, height: s } = this.element.getBoundingClientRect(), o = this.transformPreprocessor(
1564
1575
  e,
@@ -1569,17 +1580,17 @@ class Ne {
1569
1580
  this.canvas.patchViewportMatrix(o), this.onTransformFinished();
1570
1581
  }
1571
1582
  }));
1572
- a(this, "shiftCursor");
1573
- var i, n, h, c, d, g, w, m;
1574
- 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;
1575
- const s = (g = (d = this.options) == null ? void 0 : d.scale) == null ? void 0 : g.wheelSensitivity;
1576
- 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;
1577
1588
  const o = t == null ? void 0 : t.transformPreprocessor;
1578
1589
  o !== void 0 ? Array.isArray(o) ? this.transformPreprocessor = Me(
1579
1590
  o.map(
1580
1591
  (y) => K(y)
1581
1592
  )
1582
- ) : 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";
1583
1594
  }
1584
1595
  addNode(e) {
1585
1596
  return this.canvas.addNode(e), this;
@@ -1628,19 +1639,19 @@ class Ne {
1628
1639
  }
1629
1640
  getAverageTouch(e) {
1630
1641
  const t = [], s = e.touches.length;
1631
- for (let c = 0; c < s; c++)
1632
- 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]);
1633
1644
  const o = t.reduce(
1634
- (c, d) => [c[0] + d[0], c[1] + d[1]],
1645
+ (d, c) => [d[0] + c[0], d[1] + c[1]],
1635
1646
  [0, 0]
1636
- ), i = [o[0] / s, o[1] / s], h = t.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
1637
- (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]),
1638
1649
  0
1639
1650
  );
1640
1651
  return {
1641
1652
  x: i[0],
1642
1653
  y: i[1],
1643
- scale: h / s,
1654
+ scale: a / s,
1644
1655
  touchesCnt: s,
1645
1656
  touches: t
1646
1657
  };
@@ -1652,13 +1663,13 @@ class Ne {
1652
1663
  dy: s.dy + s.scale * t
1653
1664
  };
1654
1665
  if (this.element !== null) {
1655
- const { width: i, height: n } = this.element.getBoundingClientRect(), h = this.transformPreprocessor(
1666
+ const { width: i, height: h } = this.element.getBoundingClientRect(), a = this.transformPreprocessor(
1656
1667
  s,
1657
1668
  o,
1658
1669
  i,
1659
- n
1670
+ h
1660
1671
  );
1661
- this.canvas.patchViewportMatrix(h), this.onTransformFinished();
1672
+ this.canvas.patchViewportMatrix(a), this.onTransformFinished();
1662
1673
  }
1663
1674
  }
1664
1675
  scaleViewport(e, t, s) {
@@ -1668,16 +1679,16 @@ class Ne {
1668
1679
  scale: o.scale * e,
1669
1680
  dx: o.scale * (1 - e) * t + o.dx,
1670
1681
  dy: o.scale * (1 - e) * s + o.dy
1671
- }, { width: n, height: h } = this.element.getBoundingClientRect(), c = this.transformPreprocessor(
1682
+ }, { width: h, height: a } = this.element.getBoundingClientRect(), d = this.transformPreprocessor(
1672
1683
  o,
1673
1684
  i,
1674
- n,
1675
- h
1685
+ h,
1686
+ a
1676
1687
  );
1677
- this.canvas.patchViewportMatrix(c), this.onTransformFinished();
1688
+ this.canvas.patchViewportMatrix(d), this.onTransformFinished();
1678
1689
  }
1679
1690
  stopMouseDrag() {
1680
- this.element !== null && I(this.element, null), this.removeMouseDragListeners();
1691
+ this.element !== null && O(this.element, null), this.removeMouseDragListeners();
1681
1692
  }
1682
1693
  removeMouseDragListeners() {
1683
1694
  this.window.removeEventListener("mousemove", this.onMouseMove), this.window.removeEventListener("mouseup", this.onMouseUp);
@@ -1691,11 +1702,11 @@ class Ne {
1691
1702
  }
1692
1703
  class Te {
1693
1704
  constructor() {
1694
- a(this, "coreOptions");
1695
- a(this, "dragOptions");
1696
- a(this, "transformOptions");
1697
- a(this, "isDraggable", !1);
1698
- 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);
1699
1710
  }
1700
1711
  setOptions(e) {
1701
1712
  return this.coreOptions = e, this;
@@ -1718,16 +1729,16 @@ export {
1718
1729
  B as CycleSquareEdgeShape,
1719
1730
  ne as DetourBezierEdgeShape,
1720
1731
  G as DetourStraightEdgeShape,
1721
- A as EdgeType,
1732
+ C as EdgeType,
1722
1733
  se as HorizontalEdgeShape,
1723
1734
  Te as HtmlGraphBuilder,
1724
- C as HtmlGraphError,
1735
+ f as HtmlGraphError,
1725
1736
  re as StraightEdgeShape,
1726
1737
  Ee as UserDraggableNodesCanvas,
1727
1738
  Ne as UserTransformableCanvas,
1728
1739
  oe as VerticalEdgeShape,
1729
1740
  ae as createBezierEdgeShapeFactory,
1730
- de as createHorizontalEdgeShapeFactory,
1741
+ ce as createHorizontalEdgeShapeFactory,
1731
1742
  he as createStraightEdgeShareFactory,
1732
- ce as createVerticalEdgeShapeFactory
1743
+ de as createVerticalEdgeShapeFactory
1733
1744
  };