@html-graph/html-graph 3.13.0 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,22 @@
1
- var Ae = Object.defineProperty;
2
- var Ee = (r, e, t) => e in r ? Ae(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var o = (r, e, t) => Ee(r, typeof e != "symbol" ? e + "" : e, t);
4
- const xe = () => {
1
+ var Ne = Object.defineProperty;
2
+ var Me = (r, e, t) => e in r ? Ne(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var o = (r, e, t) => Me(r, typeof e != "symbol" ? e + "" : e, t);
4
+ const Le = () => {
5
5
  const r = document.createElement("div");
6
6
  return r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.width = "0", r.style.height = "0", r;
7
- }, Se = () => {
7
+ }, Re = () => {
8
8
  const r = document.createElement("div");
9
9
  return r.style.width = "100%", r.style.height = "100%", r.style.position = "relative", r.style.overflow = "hidden", r;
10
- }, be = (r) => {
10
+ }, Ce = (r) => {
11
11
  r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.visibility = "hidden";
12
12
  }, T = (r, e) => ({
13
13
  x: r.scale * e.x + r.x,
14
14
  y: r.scale * e.y + r.y
15
15
  });
16
- class he {
16
+ class ue {
17
17
  constructor(e, t, s) {
18
- o(this, "host", Se());
19
- o(this, "container", xe());
18
+ o(this, "host", Re());
19
+ o(this, "container", Le());
20
20
  o(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
21
21
  o(this, "applyTransform", () => {
22
22
  const e = this.viewportStore.getContentMatrix();
@@ -26,7 +26,7 @@ class he {
26
26
  }
27
27
  attachNode(e) {
28
28
  const t = this.graphStore.getNode(e);
29
- be(t.element), this.container.appendChild(t.element), this.updateNodePosition(e), this.updateNodePriority(e), t.element.style.visibility = "visible";
29
+ Ce(t.element), this.container.appendChild(t.element), this.updateNodePosition(e), this.updateNodePriority(e), t.element.style.visibility = "visible";
30
30
  }
31
31
  detachNode(e) {
32
32
  const t = this.graphStore.getNode(e);
@@ -51,8 +51,8 @@ class he {
51
51
  this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform), this.clear(), this.element.removeChild(this.host), this.host.removeChild(this.container);
52
52
  }
53
53
  updateNodePosition(e) {
54
- const t = this.graphStore.getNode(e), { width: s, height: i } = t.element.getBoundingClientRect(), n = this.viewportStore.getViewportMatrix().scale, h = t.centerFn(s, i), a = t.x - n * h.x, d = t.y - n * h.y;
55
- t.element.style.transform = `translate(${a}px, ${d}px)`;
54
+ const t = this.graphStore.getNode(e), { width: s, height: i } = t.element.getBoundingClientRect(), n = this.viewportStore.getViewportMatrix().scale, a = t.centerFn(s, i), h = t.x - n * a.x, d = t.y - n * a.y;
55
+ t.element.style.transform = `translate(${h}px, ${d}px)`;
56
56
  }
57
57
  updateNodePriority(e) {
58
58
  const t = this.graphStore.getNode(e);
@@ -65,33 +65,33 @@ class he {
65
65
  this.edgeIdToElementMap.set(e, s.shape.svg), this.container.appendChild(s.shape.svg);
66
66
  }
67
67
  renderEdge(e) {
68
- const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from), i = this.graphStore.getPort(t.to), n = s.element.getBoundingClientRect(), h = i.element.getBoundingClientRect(), a = this.host.getBoundingClientRect(), d = this.viewportStore.getViewportMatrix(), c = this.createEdgeRenderPort(
68
+ const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from), i = this.graphStore.getPort(t.to), n = s.element.getBoundingClientRect(), a = i.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), d = this.viewportStore.getViewportMatrix(), c = this.createEdgeRenderPort(
69
69
  t.from,
70
70
  s,
71
71
  n,
72
- a,
72
+ h,
73
73
  d
74
- ), g = this.createEdgeRenderPort(
74
+ ), l = this.createEdgeRenderPort(
75
75
  t.to,
76
76
  i,
77
- h,
78
77
  a,
78
+ h,
79
79
  d
80
80
  );
81
- t.shape.render({ from: c, to: g });
81
+ t.shape.render({ from: c, to: l });
82
82
  }
83
83
  updateEdgePriority(e) {
84
84
  const t = this.graphStore.getEdge(e);
85
85
  t.shape.svg.style.zIndex = `${t.priority}`;
86
86
  }
87
87
  createEdgeRenderPort(e, t, s, i, n) {
88
- const h = {
88
+ const a = {
89
89
  x: s.left - i.left,
90
90
  y: s.top - i.top
91
- }, a = T(n, h);
91
+ }, h = T(n, a);
92
92
  return {
93
- x: a.x,
94
- y: a.y,
93
+ x: h.x,
94
+ y: h.y,
95
95
  width: s.width * n.scale,
96
96
  height: s.height * n.scale,
97
97
  direction: t.direction,
@@ -100,7 +100,7 @@ class he {
100
100
  };
101
101
  }
102
102
  }
103
- class Pe {
103
+ class Ie {
104
104
  constructor(e) {
105
105
  o(this, "xFrom", 1 / 0);
106
106
  o(this, "yFrom", 1 / 0);
@@ -116,11 +116,11 @@ class Pe {
116
116
  return t.x >= this.xFrom && t.x <= this.xTo && t.y >= this.yFrom && t.y <= this.yTo;
117
117
  }
118
118
  hasEdge(e) {
119
- const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from).nodeId, i = this.graphStore.getPort(t.to).nodeId, n = this.graphStore.getNode(s), h = this.graphStore.getNode(i), a = Math.min(n.x, h.x), d = Math.max(n.x, h.x), c = Math.min(n.y, h.y), g = Math.max(n.y, h.y);
120
- return a <= this.xTo && d >= this.xFrom && c <= this.yTo && g >= this.yFrom;
119
+ const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from).nodeId, i = this.graphStore.getPort(t.to).nodeId, n = this.graphStore.getNode(s), a = this.graphStore.getNode(i), h = Math.min(n.x, a.x), d = Math.max(n.x, a.x), c = Math.min(n.y, a.y), l = Math.max(n.y, a.y);
120
+ return h <= this.xTo && d >= this.xFrom && c <= this.yTo && l >= this.yFrom;
121
121
  }
122
122
  }
123
- class Te {
123
+ class Ue {
124
124
  constructor(e, t, s) {
125
125
  o(this, "attachedNodes", /* @__PURE__ */ new Set());
126
126
  o(this, "attachedEdges", /* @__PURE__ */ new Set());
@@ -128,23 +128,23 @@ class Te {
128
128
  o(this, "updateViewport", (e) => {
129
129
  this.renderingBox.setRenderingBox(e);
130
130
  const t = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
131
- this.graphStore.getAllNodeIds().forEach((h) => {
132
- const a = this.renderingBox.hasNode(h), d = this.attachedNodes.has(h);
133
- a && !d ? t.add(h) : !a && d && s.add(h);
134
- }), this.graphStore.getAllEdgeIds().forEach((h) => {
135
- const a = this.renderingBox.hasEdge(h), d = this.attachedEdges.has(h), c = this.graphStore.getEdge(h), g = this.graphStore.getPort(c.from).nodeId, l = this.graphStore.getPort(c.to).nodeId;
136
- a && (this.renderingBox.hasNode(g) || (t.add(g), s.delete(g)), this.renderingBox.hasNode(l) || (t.add(l), s.delete(l))), a && !d ? i.add(h) : !a && d && n.add(h);
137
- }), n.forEach((h) => {
138
- this.handleDetachEdge(h);
139
- }), s.forEach((h) => {
140
- this.handleDetachNode(h);
141
- }), t.forEach((h) => {
142
- this.attachedNodes.has(h) || this.handleAttachNode(h);
143
- }), i.forEach((h) => {
144
- this.handleAttachEdge(h);
131
+ this.graphStore.getAllNodeIds().forEach((a) => {
132
+ const h = this.renderingBox.hasNode(a), d = this.attachedNodes.has(a);
133
+ h && !d ? t.add(a) : !h && d && s.add(a);
134
+ }), this.graphStore.getAllEdgeIds().forEach((a) => {
135
+ const h = this.renderingBox.hasEdge(a), d = this.attachedEdges.has(a), c = this.graphStore.getEdge(a), l = this.graphStore.getPort(c.from).nodeId, g = this.graphStore.getPort(c.to).nodeId;
136
+ h && (this.renderingBox.hasNode(l) || (t.add(l), s.delete(l)), this.renderingBox.hasNode(g) || (t.add(g), s.delete(g))), h && !d ? i.add(a) : !h && d && n.add(a);
137
+ }), n.forEach((a) => {
138
+ this.handleDetachEdge(a);
139
+ }), s.forEach((a) => {
140
+ this.handleDetachNode(a);
141
+ }), t.forEach((a) => {
142
+ this.attachedNodes.has(a) || this.handleAttachNode(a);
143
+ }), i.forEach((a) => {
144
+ this.handleAttachEdge(a);
145
145
  });
146
146
  });
147
- this.htmlView = e, this.graphStore = t, this.trigger = s, this.renderingBox = new Pe(this.graphStore), this.trigger.subscribe(this.updateViewport);
147
+ this.htmlView = e, this.graphStore = t, this.trigger = s, this.renderingBox = new Ie(this.graphStore), this.trigger.subscribe(this.updateViewport);
148
148
  }
149
149
  attachNode(e) {
150
150
  this.renderingBox.hasNode(e) && this.handleAttachNode(e);
@@ -198,7 +198,7 @@ class Te {
198
198
  this.htmlView.detachEdge(e), this.attachedEdges.delete(e);
199
199
  }
200
200
  }
201
- class ae {
201
+ class pe {
202
202
  constructor() {
203
203
  o(this, "callbacks", /* @__PURE__ */ new Set());
204
204
  }
@@ -214,11 +214,11 @@ class ae {
214
214
  });
215
215
  }
216
216
  }
217
- const y = () => {
218
- const r = new ae();
217
+ const A = () => {
218
+ const r = new pe();
219
219
  return [r, r];
220
220
  };
221
- class De {
221
+ class Ve {
222
222
  constructor(e) {
223
223
  o(this, "onBeforeUpdated");
224
224
  o(this, "onAfterUpdated");
@@ -231,7 +231,7 @@ class De {
231
231
  return { ...this.viewportStore.getContentMatrix() };
232
232
  }
233
233
  }
234
- class Ne {
234
+ class Be {
235
235
  constructor(e) {
236
236
  o(this, "onAfterNodeAdded");
237
237
  o(this, "onAfterNodeUpdated");
@@ -261,7 +261,6 @@ class Ne {
261
261
  getElementNodeId(e) {
262
262
  return this.graphStore.getElementNodeId(e) ?? null;
263
263
  }
264
- // TODO: use Set in v4
265
264
  getAllNodeIds() {
266
265
  return this.graphStore.getAllNodeIds();
267
266
  }
@@ -273,60 +272,74 @@ class Ne {
273
272
  nodeId: t.nodeId
274
273
  };
275
274
  }
276
- // TODO: use Set in v4
277
275
  getAllPortIds() {
278
276
  return this.graphStore.getAllPortIds();
279
277
  }
280
- // TODO: use Set in v4
281
278
  getNodePortIds(e) {
282
279
  return this.graphStore.getNodePortIds(e) ?? null;
283
280
  }
284
- // TODO: use Set in v4
281
+ getElementPortIds(e) {
282
+ return [...this.graphStore.getElementPortIds(e)];
283
+ }
284
+ /**
285
+ * @deprecated
286
+ * use getElementPortIds instead
287
+ */
285
288
  getElementPortsIds(e) {
286
- return [...this.graphStore.getElementPortsIds(e)];
289
+ return this.getElementPortIds(e);
287
290
  }
288
- // TODO: use Set in v4
289
291
  getAllEdgeIds() {
290
292
  return this.graphStore.getAllEdgeIds();
291
293
  }
292
294
  getEdge(e) {
293
295
  const t = this.graphStore.getEdge(e);
294
- return t === void 0 ? null : { from: t.from, to: t.to, priority: t.priority };
296
+ return t === void 0 ? null : {
297
+ from: t.from,
298
+ to: t.to,
299
+ priority: t.priority,
300
+ shape: t.shape
301
+ };
295
302
  }
296
- // TODO: use Set in v4
297
303
  getPortIncomingEdgeIds(e) {
298
304
  return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortIncomingEdgeIds(e);
299
305
  }
300
- // TODO: use Set in v4
306
+ getPortOutgoingEdgeIds(e) {
307
+ return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortOutgoingEdgeIds(e);
308
+ }
309
+ /**
310
+ * @deprecated
311
+ * use getPortOutgoingEdgeIds instead
312
+ */
301
313
  getPortOutcomingEdgeIds(e) {
302
- return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortOutcomingEdgeIds(e);
314
+ return this.getPortOutgoingEdgeIds(e);
303
315
  }
304
- // TODO: use Set in v4
305
316
  getPortCycleEdgeIds(e) {
306
317
  return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortCycleEdgeIds(e);
307
318
  }
308
- // TODO: use Set in v4
309
319
  getPortAdjacentEdgeIds(e) {
310
320
  return this.graphStore.getPort(e) === void 0 ? null : this.graphStore.getPortAdjacentEdgeIds(e);
311
321
  }
312
- // TODO: use Set in v4
313
322
  getNodeIncomingEdgeIds(e) {
314
323
  return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeIncomingEdgeIds(e);
315
324
  }
316
- // TODO: use Set in v4
325
+ getNodeOutgoingEdgeIds(e) {
326
+ return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeOutgoingEdgeIds(e);
327
+ }
328
+ /**
329
+ * @deprecated
330
+ * use getNodeOutgoingEdgeIds instead
331
+ */
317
332
  getNodeOutcomingEdgeIds(e) {
318
- return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeOutcomingEdgeIds(e);
333
+ return this.getNodeOutgoingEdgeIds(e);
319
334
  }
320
- // TODO: use Set in v4
321
335
  getNodeCycleEdgeIds(e) {
322
336
  return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeCycleEdgeIds(e);
323
337
  }
324
- // TODO: use Set in v4
325
338
  getNodeAdjacentEdgeIds(e) {
326
339
  return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeAdjacentEdgeIds(e);
327
340
  }
328
341
  }
329
- class W {
342
+ class O {
330
343
  constructor(e) {
331
344
  o(this, "counter", 0);
332
345
  this.checkExists = e;
@@ -342,13 +355,13 @@ class W {
342
355
  this.counter = 0;
343
356
  }
344
357
  }
345
- class x extends Error {
358
+ class S extends Error {
346
359
  constructor() {
347
360
  super(...arguments);
348
361
  o(this, "name", "HtmlGraphError");
349
362
  }
350
363
  }
351
- class de {
364
+ class we {
352
365
  constructor(e, t, s, i, n) {
353
366
  /**
354
367
  * provides api for accessing model of rendered graph
@@ -358,13 +371,13 @@ class de {
358
371
  * provides api for accessing viewport state
359
372
  */
360
373
  o(this, "viewport");
361
- o(this, "nodeIdGenerator", new W(
374
+ o(this, "nodeIdGenerator", new O(
362
375
  (e) => this.graph.getNode(e) !== null
363
376
  ));
364
- o(this, "portIdGenerator", new W(
377
+ o(this, "portIdGenerator", new O(
365
378
  (e) => this.graph.getPort(e) !== null
366
379
  ));
367
- o(this, "edgeIdGenerator", new W(
380
+ o(this, "edgeIdGenerator", new O(
368
381
  (e) => this.graph.getEdge(e) !== null
369
382
  ));
370
383
  o(this, "onAfterNodeAdded", (e) => {
@@ -416,13 +429,13 @@ class de {
416
429
  * emits event just before destruction of canvas
417
430
  */
418
431
  o(this, "onBeforeDestroy");
419
- this.element = e, this.graphStore = t, this.viewportStore = s, this.htmlView = i, this.params = n, this.graph = new Ne(this.graphStore), this.viewport = new De(this.viewportStore), this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.subscribe(
432
+ this.element = e, this.graphStore = t, this.viewportStore = s, this.htmlView = i, this.params = n, this.graph = new Be(this.graphStore), this.viewport = new Ve(this.viewportStore), this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.subscribe(
420
433
  this.onAfterNodePriorityUpdated
421
434
  ), this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated), this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked), this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded), this.graphStore.onAfterEdgeShapeUpdated.subscribe(
422
435
  this.onAfterEdgeShapeUpdated
423
436
  ), this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.subscribe(
424
437
  this.onAfterEdgePriorityUpdated
425
- ), this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.subscribe(this.onBeforeClear), [this.onBeforeDestroyEmitter, this.onBeforeDestroy] = y();
438
+ ), this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.subscribe(this.onBeforeClear), [this.onBeforeDestroyEmitter, this.onBeforeDestroy] = A();
426
439
  }
427
440
  /**
428
441
  * adds new node
@@ -430,9 +443,9 @@ class de {
430
443
  addNode(e) {
431
444
  const t = this.nodeIdGenerator.create(e.id);
432
445
  if (this.graph.getNode(t) !== null)
433
- throw new x("failed to add node with existing id");
446
+ throw new S("failed to add node with existing id");
434
447
  if (this.graphStore.getElementNodeId(e.element) !== void 0)
435
- throw new x(
448
+ throw new S(
436
449
  "failed to add node with html element already in use by another node"
437
450
  );
438
451
  if (this.graphStore.addNode({
@@ -457,7 +470,7 @@ class de {
457
470
  */
458
471
  updateNode(e, t) {
459
472
  if (this.graph.getNode(e) === null)
460
- throw new x("failed to update non existing node");
473
+ throw new S("failed to update non existing node");
461
474
  return this.graphStore.updateNode(e, t ?? {}), this;
462
475
  }
463
476
  /**
@@ -467,7 +480,7 @@ class de {
467
480
  */
468
481
  removeNode(e) {
469
482
  if (this.graph.getNode(e) === null)
470
- throw new x("failed to remove non existing node");
483
+ throw new S("failed to remove non existing node");
471
484
  return this.graphStore.removeNode(e), this;
472
485
  }
473
486
  /**
@@ -476,9 +489,9 @@ class de {
476
489
  markPort(e) {
477
490
  const t = this.portIdGenerator.create(e.id);
478
491
  if (this.graph.getPort(t) !== null)
479
- throw new x("failed to add port with existing id");
492
+ throw new S("failed to add port with existing id");
480
493
  if (this.graph.getNode(e.nodeId) === null)
481
- throw new x("failed to mark port for nonexistent node");
494
+ throw new S("failed to mark port for nonexistent node");
482
495
  return this.graphStore.addPort({
483
496
  id: t,
484
497
  element: e.element,
@@ -491,7 +504,7 @@ class de {
491
504
  */
492
505
  updatePort(e, t) {
493
506
  if (this.graph.getPort(e) === null)
494
- throw new x("failed to update nonexistent port");
507
+ throw new S("failed to update nonexistent port");
495
508
  return this.graphStore.updatePort(e, t ?? {}), this;
496
509
  }
497
510
  /**
@@ -500,7 +513,7 @@ class de {
500
513
  */
501
514
  unmarkPort(e) {
502
515
  if (this.graph.getPort(e) === null)
503
- throw new x("failed to unmark non existing port");
516
+ throw new S("failed to unmark non existing port");
504
517
  return this.graphStore.removePort(e), this;
505
518
  }
506
519
  /**
@@ -509,11 +522,11 @@ class de {
509
522
  addEdge(e) {
510
523
  const t = this.edgeIdGenerator.create(e.id);
511
524
  if (this.graph.getEdge(t) !== null)
512
- throw new x("failed to add edge with existing id");
525
+ throw new S("failed to add edge with existing id");
513
526
  if (this.graph.getPort(e.from) === null)
514
- throw new x("failed to add edge from nonexistent port");
527
+ throw new S("failed to add edge from nonexistent port");
515
528
  if (this.graph.getPort(e.to) === null)
516
- throw new x("failed to add edge to nonexistent port");
529
+ throw new S("failed to add edge to nonexistent port");
517
530
  return this.graphStore.addEdge({
518
531
  id: t,
519
532
  from: e.from,
@@ -527,7 +540,7 @@ class de {
527
540
  */
528
541
  updateEdge(e, t) {
529
542
  if (this.graph.getEdge(e) === null)
530
- throw new x("failed to update nonexistent edge");
543
+ throw new S("failed to update nonexistent edge");
531
544
  return this.graphStore.updateEdge(e, t ?? {}), this;
532
545
  }
533
546
  /**
@@ -535,7 +548,7 @@ class de {
535
548
  */
536
549
  removeEdge(e) {
537
550
  if (this.graph.getEdge(e) === null)
538
- throw new x("failed to remove nonexistent edge");
551
+ throw new S("failed to remove nonexistent edge");
539
552
  return this.graphStore.removeEdge(e), this;
540
553
  }
541
554
  /**
@@ -571,7 +584,7 @@ class de {
571
584
  ), this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear), this.htmlView.destroy();
572
585
  }
573
586
  }
574
- class Me {
587
+ class We {
575
588
  constructor() {
576
589
  o(this, "singleToMultiMap", /* @__PURE__ */ new Map());
577
590
  o(this, "multiToSingleMap", /* @__PURE__ */ new Map());
@@ -611,7 +624,7 @@ class Me {
611
624
  return this.multiToSingleMap.get(e) !== void 0;
612
625
  }
613
626
  }
614
- class ce {
627
+ class fe {
615
628
  constructor() {
616
629
  o(this, "nodes", /* @__PURE__ */ new Map());
617
630
  o(this, "ports", /* @__PURE__ */ new Map());
@@ -620,7 +633,7 @@ class ce {
620
633
  o(this, "incomingEdges", /* @__PURE__ */ new Map());
621
634
  o(this, "outcomingEdges", /* @__PURE__ */ new Map());
622
635
  o(this, "cycleEdges", /* @__PURE__ */ new Map());
623
- o(this, "elementPorts", new Me());
636
+ o(this, "elementPorts", new We());
624
637
  o(this, "afterNodeAddedEmitter");
625
638
  o(this, "onAfterNodeAdded");
626
639
  o(this, "afterNodeUpdatedEmitter");
@@ -647,7 +660,7 @@ class ce {
647
660
  o(this, "onBeforeEdgeRemoved");
648
661
  o(this, "beforeClearEmitter");
649
662
  o(this, "onBeforeClear");
650
- [this.afterNodeAddedEmitter, this.onAfterNodeAdded] = y(), [this.afterNodeUpdatedEmitter, this.onAfterNodeUpdated] = y(), [this.afterNodePriorityUpdatedEmitter, this.onAfterNodePriorityUpdated] = y(), [this.beforeNodeRemovedEmitter, this.onBeforeNodeRemoved] = y(), [this.afterPortAddedEmitter, this.onAfterPortAdded] = y(), [this.afterPortUpdatedEmitter, this.onAfterPortUpdated] = y(), [this.beforePortRemovedEmitter, this.onBeforePortRemoved] = y(), [this.afterEdgeAddedEmitter, this.onAfterEdgeAdded] = y(), [this.afterEdgeShapeUpdatedEmitter, this.onAfterEdgeShapeUpdated] = y(), [this.afterEdgeUpdatedEmitter, this.onAfterEdgeUpdated] = y(), [this.afterEdgePriorityUpdatedEmitter, this.onAfterEdgePriorityUpdated] = y(), [this.beforeEdgeRemovedEmitter, this.onBeforeEdgeRemoved] = y(), [this.beforeClearEmitter, this.onBeforeClear] = y();
663
+ [this.afterNodeAddedEmitter, this.onAfterNodeAdded] = A(), [this.afterNodeUpdatedEmitter, this.onAfterNodeUpdated] = A(), [this.afterNodePriorityUpdatedEmitter, this.onAfterNodePriorityUpdated] = A(), [this.beforeNodeRemovedEmitter, this.onBeforeNodeRemoved] = A(), [this.afterPortAddedEmitter, this.onAfterPortAdded] = A(), [this.afterPortUpdatedEmitter, this.onAfterPortUpdated] = A(), [this.beforePortRemovedEmitter, this.onBeforePortRemoved] = A(), [this.afterEdgeAddedEmitter, this.onAfterEdgeAdded] = A(), [this.afterEdgeShapeUpdatedEmitter, this.onAfterEdgeShapeUpdated] = A(), [this.afterEdgeUpdatedEmitter, this.onAfterEdgeUpdated] = A(), [this.afterEdgePriorityUpdatedEmitter, this.onAfterEdgePriorityUpdated] = A(), [this.beforeEdgeRemovedEmitter, this.onBeforeEdgeRemoved] = A(), [this.beforeClearEmitter, this.onBeforeClear] = A();
651
664
  }
652
665
  addNode(e) {
653
666
  const t = /* @__PURE__ */ new Map(), s = {
@@ -695,7 +708,7 @@ class ce {
695
708
  getAllPortIds() {
696
709
  return Array.from(this.ports.keys());
697
710
  }
698
- getElementPortsIds(e) {
711
+ getElementPortIds(e) {
699
712
  return this.elementPorts.getMultiBySingle(e);
700
713
  }
701
714
  getNodePortIds(e) {
@@ -739,7 +752,7 @@ class ce {
739
752
  getPortIncomingEdgeIds(e) {
740
753
  return Array.from(this.incomingEdges.get(e));
741
754
  }
742
- getPortOutcomingEdgeIds(e) {
755
+ getPortOutgoingEdgeIds(e) {
743
756
  return Array.from(this.outcomingEdges.get(e));
744
757
  }
745
758
  getPortCycleEdgeIds(e) {
@@ -748,7 +761,7 @@ class ce {
748
761
  getPortAdjacentEdgeIds(e) {
749
762
  return [
750
763
  ...this.getPortIncomingEdgeIds(e),
751
- ...this.getPortOutcomingEdgeIds(e),
764
+ ...this.getPortOutgoingEdgeIds(e),
752
765
  ...this.getPortCycleEdgeIds(e)
753
766
  ];
754
767
  }
@@ -759,11 +772,11 @@ class ce {
759
772
  s = [...s, ...this.getPortIncomingEdgeIds(i)];
760
773
  }), s;
761
774
  }
762
- getNodeOutcomingEdgeIds(e) {
775
+ getNodeOutgoingEdgeIds(e) {
763
776
  const t = Array.from(this.nodes.get(e).ports.keys());
764
777
  let s = [];
765
778
  return t.forEach((i) => {
766
- s = [...s, ...this.getPortOutcomingEdgeIds(i)];
779
+ s = [...s, ...this.getPortOutgoingEdgeIds(i)];
767
780
  }), s;
768
781
  }
769
782
  getNodeCycleEdgeIds(e) {
@@ -776,7 +789,7 @@ class ce {
776
789
  getNodeAdjacentEdgeIds(e) {
777
790
  return [
778
791
  ...this.getNodeIncomingEdgeIds(e),
779
- ...this.getNodeOutcomingEdgeIds(e),
792
+ ...this.getNodeOutgoingEdgeIds(e),
780
793
  ...this.getNodeCycleEdgeIds(e)
781
794
  ];
782
795
  }
@@ -793,24 +806,24 @@ class ce {
793
806
  this.cycleEdges.get(s).delete(e), this.cycleEdges.get(i).delete(e), this.incomingEdges.get(s).delete(e), this.incomingEdges.get(i).delete(e), this.outcomingEdges.get(s).delete(e), this.outcomingEdges.get(i).delete(e), this.edges.delete(e);
794
807
  }
795
808
  }
796
- const q = (r) => ({
809
+ const se = (r) => ({
797
810
  scale: 1 / r.scale,
798
811
  x: -r.x / r.scale,
799
812
  y: -r.y / r.scale
800
- }), ee = {
813
+ }), ie = {
801
814
  scale: 1,
802
815
  x: 0,
803
816
  y: 0
804
817
  };
805
- class Le {
818
+ class $e {
806
819
  constructor() {
807
- o(this, "viewportMatrix", ee);
808
- o(this, "contentMatrix", ee);
820
+ o(this, "viewportMatrix", ie);
821
+ o(this, "contentMatrix", ie);
809
822
  o(this, "afterUpdateEmitter");
810
823
  o(this, "onAfterUpdated");
811
824
  o(this, "beforeUpdateEmitter");
812
825
  o(this, "onBeforeUpdated");
813
- [this.afterUpdateEmitter, this.onAfterUpdated] = y(), [this.beforeUpdateEmitter, this.onBeforeUpdated] = y();
826
+ [this.afterUpdateEmitter, this.onAfterUpdated] = A(), [this.beforeUpdateEmitter, this.onBeforeUpdated] = A();
814
827
  }
815
828
  getViewportMatrix() {
816
829
  return this.viewportMatrix;
@@ -823,17 +836,17 @@ class Le {
823
836
  scale: e.scale ?? this.viewportMatrix.scale,
824
837
  x: e.x ?? this.viewportMatrix.x,
825
838
  y: e.y ?? this.viewportMatrix.y
826
- }, this.contentMatrix = q(this.viewportMatrix), this.afterUpdateEmitter.emit();
839
+ }, this.contentMatrix = se(this.viewportMatrix), this.afterUpdateEmitter.emit();
827
840
  }
828
841
  patchContentMatrix(e) {
829
842
  this.beforeUpdateEmitter.emit(), this.contentMatrix = {
830
843
  scale: e.scale ?? this.contentMatrix.scale,
831
844
  x: e.x ?? this.contentMatrix.x,
832
845
  y: e.y ?? this.contentMatrix.y
833
- }, this.viewportMatrix = q(this.contentMatrix), this.afterUpdateEmitter.emit();
846
+ }, this.viewportMatrix = se(this.contentMatrix), this.afterUpdateEmitter.emit();
834
847
  }
835
848
  }
836
- class k {
849
+ class Y {
837
850
  constructor(e) {
838
851
  o(this, "elementToNodeId", /* @__PURE__ */ new Map());
839
852
  o(this, "nodesResizeObserver");
@@ -859,1620 +872,1780 @@ class k {
859
872
  }), this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
860
873
  }
861
874
  static configure(e) {
862
- new k(e);
875
+ new Y(e);
863
876
  }
864
877
  handleNodeResize(e) {
865
878
  const t = this.elementToNodeId.get(e);
866
879
  this.canvas.updateNode(t);
867
880
  }
868
881
  }
869
- const Re = (r, e, t) => {
870
- const { x: s, y: i, width: n, height: h } = r.getBoundingClientRect();
871
- return e >= s && e <= s + n && t >= i && t <= i + h;
872
- }, Ie = (r, e, t) => e >= 0 && e <= r.innerWidth && t >= 0 && t <= r.innerHeight, D = (r, e, t, s) => Re(e, t, s) && Ie(r, t, s), B = (r, e) => {
882
+ const Fe = (r, e, t) => {
883
+ const { x: s, y: i, width: n, height: a } = r.getBoundingClientRect();
884
+ return e >= s && e <= s + n && t >= i && t <= i + a;
885
+ }, Oe = (r, e, t) => e >= 0 && e <= r.innerWidth && t >= 0 && t <= r.innerHeight, L = (r, e, t, s) => Fe(e, t, s) && Oe(r, t, s), U = (r, e) => {
873
886
  e !== null ? r.style.cursor = e : r.style.removeProperty("cursor");
874
- };
875
- class z {
876
- constructor(e, t, s, i) {
877
- o(this, "grabbedNodeId", null);
878
- o(this, "maxNodePriority", 0);
879
- o(this, "previousTouchCoordinates", null);
880
- o(this, "graph");
881
- o(this, "onAfterNodeAdded", (e) => {
882
- this.updateMaxNodePriority(e);
883
- const t = this.graph.getNode(e);
884
- t.element.addEventListener("mousedown", this.onMouseDown, {
885
- passive: !0
886
- }), t.element.addEventListener("touchstart", this.onTouchStart, {
887
- passive: !0
888
- });
889
- });
890
- o(this, "onAfterNodeUpdated", (e) => {
891
- this.updateMaxNodePriority(e);
892
- });
893
- o(this, "onBeforeNodeRemoved", (e) => {
894
- const t = this.graph.getNode(e);
895
- t.element.removeEventListener("mousedown", this.onMouseDown), t.element.removeEventListener("touchstart", this.onTouchStart);
896
- });
897
- o(this, "onBeforeDestroy", () => {
898
- this.graph.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded), this.graph.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated), this.graph.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved), this.graph.onBeforeClear.unsubscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy), this.removeMouseDragListeners(), this.removeTouchDragListeners();
899
- });
900
- o(this, "onBeforeClear", () => {
901
- this.canvas.graph.getAllNodeIds().forEach((e) => {
902
- const t = this.canvas.graph.getNode(e);
903
- t.element.removeEventListener("mousedown", this.onMouseDown), t.element.removeEventListener("touchstart", this.onTouchStart);
904
- }), this.maxNodePriority = 0;
905
- });
906
- o(this, "onMouseDown", (e) => {
907
- if (!this.config.mouseDownEventVerifier(e))
908
- return;
909
- const t = e.currentTarget, s = this.graph.getElementNodeId(t), i = this.graph.getNode(s);
910
- this.config.onBeforeNodeDrag({
911
- nodeId: s,
912
- element: i.element,
913
- x: i.x,
914
- y: i.y
915
- }) && (e.stopImmediatePropagation(), this.grabbedNodeId = s, B(this.element, this.config.dragCursor), this.moveNodeOnTop(s), this.window.addEventListener("mouseup", this.onWindowMouseUp, {
916
- passive: !0
917
- }), this.window.addEventListener("mousemove", this.onWindowMouseMove, {
918
- passive: !0
919
- }));
920
- });
921
- o(this, "onTouchStart", (e) => {
922
- if (e.touches.length !== 1)
923
- return;
924
- e.stopImmediatePropagation(), this.previousTouchCoordinates = {
925
- x: e.touches[0].clientX,
926
- y: e.touches[0].clientY
927
- };
928
- const t = e.currentTarget, s = this.canvas.graph.getElementNodeId(t), i = this.graph.getNode(s);
929
- this.config.onBeforeNodeDrag({
930
- nodeId: s,
931
- element: i.element,
932
- x: i.x,
933
- y: i.y
934
- }) && (this.grabbedNodeId = s, this.moveNodeOnTop(s), this.window.addEventListener("touchmove", this.onWindowTouchMove, {
935
- passive: !0
936
- }), this.window.addEventListener("touchend", this.onWindowTouchFinish, {
937
- passive: !0
938
- }), this.window.addEventListener("touchcancel", this.onWindowTouchFinish, {
939
- passive: !0
940
- }));
941
- });
942
- o(this, "onWindowMouseMove", (e) => {
943
- if (!D(
944
- this.window,
945
- this.element,
946
- e.clientX,
947
- e.clientY
948
- )) {
949
- this.cancelMouseDrag();
950
- return;
951
- }
952
- this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
953
- });
954
- o(this, "onWindowMouseUp", (e) => {
955
- this.config.mouseUpEventVerifier(e) && this.cancelMouseDrag();
956
- });
957
- o(this, "onWindowTouchMove", (e) => {
958
- if (e.touches.length !== 1)
959
- return;
960
- const t = e.touches[0];
961
- if (!D(
962
- this.window,
963
- this.element,
964
- t.clientX,
965
- t.clientY
966
- )) {
967
- this.cancelTouchDrag();
968
- return;
969
- }
970
- if (this.grabbedNodeId !== null && this.previousTouchCoordinates !== null) {
971
- const i = t.clientX - this.previousTouchCoordinates.x, n = t.clientY - this.previousTouchCoordinates.y;
972
- this.dragNode(this.grabbedNodeId, i, n), this.previousTouchCoordinates = {
973
- x: e.touches[0].clientX,
974
- y: e.touches[0].clientY
975
- };
887
+ }, V = (r) => {
888
+ const e = document.createElement("div");
889
+ return {
890
+ id: r.overlayId,
891
+ element: e,
892
+ x: r.portCoords.x,
893
+ y: r.portCoords.y,
894
+ ports: [
895
+ {
896
+ id: r.overlayId,
897
+ element: e,
898
+ direction: r.portDirection
976
899
  }
977
- });
978
- o(this, "onWindowTouchFinish", () => {
979
- this.previousTouchCoordinates = null, this.cancelTouchDrag();
980
- });
981
- this.canvas = e, this.element = t, this.window = s, this.config = i, this.graph = e.graph, this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.graph.onBeforeClear.subscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
900
+ ]
901
+ };
902
+ }, ke = (r, e) => {
903
+ let t = e, s = null;
904
+ for (; t !== null && (s = r.getElementPortIds(t)[0] ?? null, s === null); )
905
+ t = t.parentElement;
906
+ return s;
907
+ }, ve = (r, e) => {
908
+ const t = document.elementsFromPoint(e.x, e.y);
909
+ for (const s of t) {
910
+ const i = ke(r, s);
911
+ if (i !== null)
912
+ return i;
982
913
  }
983
- static configure(e, t, s, i) {
984
- new z(e, t, s, i);
914
+ return null;
915
+ };
916
+ var b = /* @__PURE__ */ ((r) => (r.Static = "static", r.Dragging = "dragging", r.Edge = "edge", r))(b || {});
917
+ const me = (r, e) => ({
918
+ x: r / 2,
919
+ y: e / 2
920
+ }), m = (r, e, t) => ({
921
+ x: e.x * r.x - e.y * r.y + ((1 - e.x) * t.x + e.y * t.y),
922
+ y: e.y * r.x + e.x * r.y + ((1 - e.x) * t.y - e.y * t.x)
923
+ }), w = {
924
+ x: 0,
925
+ y: 0
926
+ };
927
+ class ze {
928
+ constructor(e) {
929
+ o(this, "path");
930
+ o(this, "midpoint");
931
+ this.params = e;
932
+ const t = this.params.to;
933
+ this.midpoint = { x: t.x / 2, y: t.y / 2 };
934
+ const s = m(
935
+ { x: this.params.arrowLength, y: w.y },
936
+ this.params.sourceDirection,
937
+ w
938
+ ), i = m(
939
+ { x: this.params.to.x - this.params.arrowLength, y: this.params.to.y },
940
+ this.params.targetDirection,
941
+ this.params.to
942
+ ), n = {
943
+ x: s.x + this.params.sourceDirection.x * this.params.curvature,
944
+ y: s.y + this.params.sourceDirection.y * this.params.curvature
945
+ }, a = {
946
+ x: i.x - this.params.targetDirection.x * this.params.curvature,
947
+ y: i.y - this.params.targetDirection.y * this.params.curvature
948
+ }, h = `M ${s.x} ${s.y} C ${n.x} ${n.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`, d = this.params.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${s.x} ${s.y} `, c = this.params.hasTargetArrow ? "" : ` M ${i.x} ${i.y} L ${this.params.to.x} ${this.params.to.y}`;
949
+ this.path = `${d}${h}${c}`;
985
950
  }
986
- dragNode(e, t, s) {
987
- const i = this.graph.getNode(e);
988
- if (i === null)
989
- return;
990
- const n = this.canvas.viewport.getContentMatrix(), h = T(n, {
991
- x: i.x,
992
- y: i.y
993
- }), a = T(
994
- { scale: 1, x: t, y: s },
995
- h
996
- ), d = this.canvas.viewport.getViewportMatrix(), c = T(d, a);
997
- this.canvas.updateNode(e, { x: c.x, y: c.y }), this.config.onNodeDrag({
998
- nodeId: e,
999
- element: i.element,
1000
- x: c.x,
1001
- y: c.y
1002
- });
951
+ }
952
+ const ye = (r, e, t, s) => ({
953
+ x: e * r.x + (1 - e) / 2 * s.x,
954
+ y: t * r.y + (1 - t) / 2 * s.y
955
+ });
956
+ class Xe {
957
+ constructor(e) {
958
+ o(this, "path");
959
+ o(this, "midpoint");
960
+ this.params = e;
961
+ const t = this.params.hasSourceArrow ? m(
962
+ { x: this.params.arrowLength, y: w.y },
963
+ this.params.sourceDirection,
964
+ w
965
+ ) : w, s = this.params.hasTargetArrow ? m(
966
+ {
967
+ x: this.params.to.x - this.params.arrowLength,
968
+ y: this.params.to.y
969
+ },
970
+ this.params.targetDirection,
971
+ this.params.to
972
+ ) : this.params.to, i = this.params.arrowLength, n = Math.cos(this.params.detourDirection) * this.params.detourDistance, a = Math.sin(this.params.detourDirection) * this.params.detourDistance, h = n * this.params.flipX, d = a * this.params.flipY, c = m(
973
+ { x: i, y: w.y },
974
+ this.params.sourceDirection,
975
+ w
976
+ ), l = {
977
+ x: c.x + h,
978
+ y: c.y + d
979
+ }, g = m(
980
+ { x: this.params.to.x - i, y: this.params.to.y },
981
+ this.params.targetDirection,
982
+ this.params.to
983
+ ), p = {
984
+ x: g.x + h,
985
+ y: g.y + d
986
+ }, f = {
987
+ x: (l.x + p.x) / 2,
988
+ y: (l.y + p.y) / 2
989
+ }, v = {
990
+ x: c.x + this.params.curvature * this.params.sourceDirection.x,
991
+ y: c.y + this.params.curvature * this.params.sourceDirection.y
992
+ }, y = {
993
+ x: g.x - this.params.curvature * this.params.targetDirection.x,
994
+ y: g.y - this.params.curvature * this.params.targetDirection.y
995
+ }, E = {
996
+ x: c.x + h,
997
+ y: c.y + d
998
+ }, x = {
999
+ x: g.x + h,
1000
+ y: g.y + d
1001
+ };
1002
+ this.path = [
1003
+ `M ${t.x} ${t.y}`,
1004
+ `L ${c.x} ${c.y}`,
1005
+ `C ${v.x} ${v.y} ${E.x} ${E.y} ${f.x} ${f.y}`,
1006
+ `C ${x.x} ${x.y} ${y.x} ${y.y} ${g.x} ${g.y}`,
1007
+ `L ${s.x} ${s.y}`
1008
+ ].join(" "), this.midpoint = ye(f, e.flipX, e.flipY, e.to);
1003
1009
  }
1004
- moveNodeOnTop(e) {
1005
- if (this.config.moveOnTop) {
1006
- if (this.maxNodePriority++, this.config.moveEdgesOnTop) {
1007
- const t = this.maxNodePriority;
1008
- this.maxNodePriority++, this.graph.getNodeAdjacentEdgeIds(e).forEach((i) => {
1009
- this.canvas.updateEdge(i, { priority: t });
1010
- });
1010
+ }
1011
+ const C = (r, e) => {
1012
+ const t = [];
1013
+ 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) {
1014
+ const s = r.length - 1;
1015
+ let i = 0, n = 0, a = 0;
1016
+ r.forEach((h, d) => {
1017
+ let c = 0, l = 0, g = 0;
1018
+ const p = d > 0, f = d < s, v = p && f;
1019
+ if (p && (c = -i, l = -n, g = a), f) {
1020
+ const R = r[d + 1];
1021
+ i = R.x - h.x, n = R.y - h.y, a = Math.sqrt(i * i + n * n);
1011
1022
  }
1012
- this.canvas.updateNode(e, { priority: this.maxNodePriority });
1013
- }
1014
- }
1015
- cancelMouseDrag() {
1016
- const e = this.graph.getNode(this.grabbedNodeId);
1017
- e !== null && this.config.onNodeDragFinished({
1018
- nodeId: this.grabbedNodeId,
1019
- element: e.element,
1020
- x: e.x,
1021
- y: e.y
1022
- }), this.grabbedNodeId = null, B(this.element, null), this.removeMouseDragListeners();
1023
- }
1024
- removeMouseDragListeners() {
1025
- this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
1026
- }
1027
- cancelTouchDrag() {
1028
- this.previousTouchCoordinates = null;
1029
- const e = this.graph.getNode(this.grabbedNodeId);
1030
- e !== null && this.config.onNodeDragFinished({
1031
- nodeId: this.grabbedNodeId,
1032
- element: e.element,
1033
- x: e.x,
1034
- y: e.y
1035
- }), this.grabbedNodeId = null, this.removeTouchDragListeners();
1023
+ const E = a !== 0 ? Math.min((v ? e : 0) / a, d < s - 1 ? 0.5 : 1) : 0, x = v ? { x: h.x + i * E, y: h.y + n * E } : h, D = g !== 0 ? Math.min((v ? e : 0) / g, d > 1 ? 0.5 : 1) : 0, N = v ? { x: h.x + c * D, y: h.y + l * D } : h;
1024
+ d > 0 && t.push(`L ${N.x} ${N.y}`), v && t.push(
1025
+ `C ${h.x} ${h.y} ${h.x} ${h.y} ${x.x} ${x.y}`
1026
+ );
1027
+ });
1036
1028
  }
1037
- removeTouchDragListeners() {
1038
- this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1029
+ return t.join(" ");
1030
+ };
1031
+ class Ye {
1032
+ constructor(e) {
1033
+ o(this, "path");
1034
+ o(this, "midpoint");
1035
+ this.params = e;
1036
+ const t = this.params.to;
1037
+ this.midpoint = { x: t.x / 2, y: t.y / 2 };
1038
+ const s = this.params.hasSourceArrow ? m(
1039
+ { x: this.params.arrowLength, y: w.y },
1040
+ this.params.sourceDirection,
1041
+ w
1042
+ ) : w, i = this.params.hasTargetArrow ? m(
1043
+ {
1044
+ x: this.params.to.x - this.params.arrowLength,
1045
+ y: this.params.to.y
1046
+ },
1047
+ this.params.targetDirection,
1048
+ this.params.to
1049
+ ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, a = n - this.params.roundness, h = m(
1050
+ { x: a, y: w.y },
1051
+ this.params.sourceDirection,
1052
+ w
1053
+ ), d = m(
1054
+ { x: this.params.to.x - a, y: this.params.to.y },
1055
+ this.params.targetDirection,
1056
+ this.params.to
1057
+ ), c = Math.max((h.x + d.x) / 2, n), l = this.params.to.y / 2, g = {
1058
+ x: this.params.flipX > 0 ? c : -n,
1059
+ y: h.y
1060
+ }, p = { x: g.x, y: l }, f = {
1061
+ x: this.params.flipX > 0 ? this.params.to.x - c : this.params.to.x + n,
1062
+ y: d.y
1063
+ }, v = { x: f.x, y: l };
1064
+ this.path = C(
1065
+ [s, h, g, p, v, f, d, i],
1066
+ this.params.roundness
1067
+ );
1068
+ }
1069
+ }
1070
+ class H {
1071
+ constructor(e) {
1072
+ o(this, "path");
1073
+ o(this, "midpoint");
1074
+ this.params = e;
1075
+ const t = this.params.hasSourceArrow ? m(
1076
+ { x: this.params.arrowLength, y: w.y },
1077
+ this.params.sourceDirection,
1078
+ w
1079
+ ) : w, s = this.params.hasTargetArrow ? m(
1080
+ {
1081
+ x: this.params.to.x - this.params.arrowLength,
1082
+ y: this.params.to.y
1083
+ },
1084
+ this.params.targetDirection,
1085
+ this.params.to
1086
+ ) : this.params.to, i = this.params.arrowLength + this.params.arrowOffset, n = m(
1087
+ { x: i, y: w.y },
1088
+ this.params.sourceDirection,
1089
+ w
1090
+ ), a = Math.cos(this.params.detourDirection) * this.params.detourDistance, h = Math.sin(this.params.detourDirection) * this.params.detourDistance, d = a * this.params.flipX, c = h * this.params.flipY, l = { x: n.x + d, y: n.y + c }, g = m(
1091
+ { x: this.params.to.x - i, y: this.params.to.y },
1092
+ this.params.targetDirection,
1093
+ this.params.to
1094
+ ), p = { x: g.x + d, y: g.y + c }, f = { x: (l.x + p.x) / 2, y: (l.y + p.y) / 2 };
1095
+ this.midpoint = ye(f, e.flipX, e.flipY, e.to), this.path = C(
1096
+ [t, n, l, p, g, s],
1097
+ this.params.roundness
1098
+ );
1099
+ }
1100
+ }
1101
+ class He {
1102
+ constructor(e) {
1103
+ o(this, "path");
1104
+ o(this, "midpoint");
1105
+ this.params = e;
1106
+ const t = this.params.to;
1107
+ this.midpoint = { x: t.x / 2, y: t.y / 2 };
1108
+ const s = this.params.hasSourceArrow ? m(
1109
+ { x: this.params.arrowLength, y: w.y },
1110
+ this.params.sourceDirection,
1111
+ w
1112
+ ) : w, i = this.params.hasTargetArrow ? m(
1113
+ {
1114
+ x: this.params.to.x - this.params.arrowLength,
1115
+ y: this.params.to.y
1116
+ },
1117
+ this.params.targetDirection,
1118
+ this.params.to
1119
+ ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, a = m(
1120
+ { x: n, y: w.y },
1121
+ this.params.sourceDirection,
1122
+ w
1123
+ ), h = m(
1124
+ { x: this.params.to.x - n, y: this.params.to.y },
1125
+ this.params.targetDirection,
1126
+ this.params.to
1127
+ );
1128
+ this.path = C([s, a, h, i], this.params.roundness);
1129
+ }
1130
+ }
1131
+ class je {
1132
+ constructor(e) {
1133
+ o(this, "path");
1134
+ o(this, "midpoint");
1135
+ this.params = e;
1136
+ const t = this.params.to;
1137
+ this.midpoint = { x: t.x / 2, y: t.y / 2 };
1138
+ const s = this.params.hasSourceArrow ? m(
1139
+ { x: this.params.arrowLength, y: w.y },
1140
+ this.params.sourceDirection,
1141
+ w
1142
+ ) : w, i = this.params.hasTargetArrow ? m(
1143
+ {
1144
+ x: this.params.to.x - this.params.arrowLength,
1145
+ y: this.params.to.y
1146
+ },
1147
+ this.params.targetDirection,
1148
+ this.params.to
1149
+ ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, a = n - this.params.roundness, h = m(
1150
+ { x: a, y: w.y },
1151
+ this.params.sourceDirection,
1152
+ w
1153
+ ), d = m(
1154
+ { x: this.params.to.x - a, y: this.params.to.y },
1155
+ this.params.targetDirection,
1156
+ this.params.to
1157
+ ), c = Math.max((h.y + d.y) / 2, n), l = this.params.to.x / 2, g = {
1158
+ x: h.x,
1159
+ y: this.params.flipY > 0 ? c : -n
1160
+ }, p = { x: l, y: g.y }, f = {
1161
+ x: d.x,
1162
+ y: this.params.flipY > 0 ? this.params.to.y - c : this.params.to.y + n
1163
+ }, v = { x: l, y: f.y };
1164
+ this.path = C(
1165
+ [s, h, g, p, v, f, d, i],
1166
+ this.params.roundness
1167
+ );
1168
+ }
1169
+ }
1170
+ class j {
1171
+ constructor(e) {
1172
+ o(this, "path");
1173
+ o(this, "midpoint");
1174
+ this.params = e;
1175
+ const t = this.params.arrowOffset, s = this.params.side, i = this.params.arrowLength + t, n = i + 2 * s, h = [
1176
+ { x: this.params.arrowLength, y: w.y },
1177
+ { x: i, y: w.y },
1178
+ { x: i, y: this.params.side },
1179
+ { x: n, y: this.params.side },
1180
+ { x: n, y: -this.params.side },
1181
+ { x: i, y: -this.params.side },
1182
+ { x: i, y: w.y },
1183
+ { x: this.params.arrowLength, y: w.y }
1184
+ ].map(
1185
+ (c) => m(c, this.params.sourceDirection, w)
1186
+ ), d = `M ${w.x} ${w.y} L ${h[0].x} ${h[0].y} `;
1187
+ this.path = `${this.params.hasSourceArrow || this.params.hasTargetArrow ? "" : d}${C(h, this.params.roundness)}`, this.midpoint = { x: (h[3].x + h[4].x) / 2, y: (h[3].y + h[4].y) / 2 };
1188
+ }
1189
+ }
1190
+ class Ge {
1191
+ constructor(e) {
1192
+ o(this, "path");
1193
+ o(this, "midpoint");
1194
+ this.params = e;
1195
+ const t = this.params.smallRadius, s = this.params.radius, i = t + s, n = t * s / i, a = Math.sqrt(i * i - t * t), h = a * t / i, d = a + s + this.params.arrowLength, c = this.params.arrowLength + h, g = [
1196
+ { x: this.params.arrowLength, y: w.y },
1197
+ { x: c, y: n },
1198
+ { x: c, y: -n },
1199
+ { x: d, y: 0 }
1200
+ ].map(
1201
+ (v) => m(v, this.params.sourceDirection, w)
1202
+ ), p = [
1203
+ `M ${g[0].x} ${g[0].y}`,
1204
+ `A ${t} ${t} 0 0 1 ${g[1].x} ${g[1].y}`,
1205
+ `A ${s} ${s} 0 1 0 ${g[2].x} ${g[2].y}`,
1206
+ `A ${t} ${t} 0 0 1 ${g[0].x} ${g[0].y}`
1207
+ ].join(" "), f = `M 0 0 L ${g[0].x} ${g[0].y} `;
1208
+ this.path = `${this.params.hasSourceArrow || this.params.hasTargetArrow ? "" : f}${p}`, this.midpoint = g[3];
1209
+ }
1210
+ }
1211
+ class Ke {
1212
+ constructor(e) {
1213
+ o(this, "path");
1214
+ o(this, "midpoint");
1215
+ o(this, "diagonalDistance");
1216
+ this.params = e;
1217
+ const t = this.params.to;
1218
+ if (this.midpoint = { x: t.x / 2, y: t.y / 2 }, this.diagonalDistance = Math.sqrt(
1219
+ this.params.to.x * this.params.to.x + this.params.to.y * this.params.to.y
1220
+ ), Math.sqrt(
1221
+ this.params.to.x * this.params.to.x + this.params.to.y * this.params.to.y
1222
+ ) === 0) {
1223
+ this.path = "";
1224
+ return;
1225
+ }
1226
+ const i = this.createDirectLinePoint({
1227
+ offset: this.params.sourceOffset,
1228
+ hasArrow: this.params.hasSourceArrow,
1229
+ flip: 1,
1230
+ shift: w
1231
+ }), n = this.createDirectLinePoint({
1232
+ offset: this.params.targetOffset,
1233
+ hasArrow: this.params.hasTargetArrow,
1234
+ flip: -1,
1235
+ shift: this.params.to
1236
+ });
1237
+ this.path = `M ${i.x} ${i.y} L ${n.x} ${n.y}`;
1238
+ }
1239
+ createDirectLinePoint(e) {
1240
+ const t = e.hasArrow ? this.params.arrowLength : 0, s = e.offset + t, i = e.flip * s / this.diagonalDistance;
1241
+ return {
1242
+ x: this.params.to.x * i + e.shift.x,
1243
+ y: this.params.to.y * i + e.shift.y
1244
+ };
1245
+ }
1246
+ }
1247
+ const Ee = (r, e) => {
1248
+ r.style.transform = `translate(${e.x}px, ${e.y}px)`, r.style.width = `${Math.max(e.width, 1)}px`, r.style.height = `${Math.max(e.height, 1)}px`;
1249
+ }, G = Object.freeze({
1250
+ edgeColor: "--edge-color"
1251
+ }), Ae = (r) => {
1252
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1253
+ return e.style.pointerEvents = "none", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.overflow = "visible", e.style.setProperty(G.edgeColor, r), e;
1254
+ }, B = () => {
1255
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
1256
+ return r.setAttribute("fill", `var(${G.edgeColor})`), r;
1257
+ }, xe = () => {
1258
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "g");
1259
+ return r.style.transformOrigin = "50% 50%", r;
1260
+ }, Se = (r) => {
1261
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
1262
+ return e.setAttribute("stroke", `var(${G.edgeColor})`), e.setAttribute("stroke-width", `${r}`), e.setAttribute("fill", "none"), e;
1263
+ }, be = (r, e) => {
1264
+ const t = {
1265
+ x: r.x + r.width / 2,
1266
+ y: r.y + r.height / 2
1267
+ }, s = {
1268
+ x: e.x + e.width / 2,
1269
+ y: e.y + e.height / 2
1270
+ }, i = Math.min(t.x, s.x), n = Math.min(t.y, s.y), a = Math.abs(s.x - t.x), h = Math.abs(s.y - t.y), d = t.x <= s.x ? 1 : -1, c = t.y <= s.y ? 1 : -1;
1271
+ return {
1272
+ x: i,
1273
+ y: n,
1274
+ width: a,
1275
+ height: h,
1276
+ flipX: d,
1277
+ flipY: c
1278
+ };
1279
+ }, k = (r, e, t, s) => {
1280
+ const n = [
1281
+ w,
1282
+ { x: t, y: s },
1283
+ { x: t, y: -s }
1284
+ ].map((c) => m(c, r, w)).map((c) => ({ x: c.x + e.x, y: c.y + e.y })), a = `M ${n[0].x} ${n[0].y}`, h = `L ${n[1].x} ${n[1].y}`, d = `L ${n[2].x} ${n[2].y}`;
1285
+ return `${a} ${h} ${d} Z`;
1286
+ }, u = Object.freeze({
1287
+ color: "#777777",
1288
+ width: 1,
1289
+ arrowLength: 15,
1290
+ arrowWidth: 4,
1291
+ arrowOffset: 15,
1292
+ hasSourceArrow: !1,
1293
+ hasTargetArrow: !1,
1294
+ cycleRadius: 30,
1295
+ cycleSquareSide: 30,
1296
+ roundness: 10,
1297
+ detourDistance: 100,
1298
+ detourDirection: -Math.PI / 2,
1299
+ detourDirectionVertical: 0,
1300
+ smallCycleRadius: 15,
1301
+ curvature: 90,
1302
+ interactiveWidth: 10,
1303
+ preOffset: 0
1304
+ }), ne = (r, e, t) => ({ x: e * Math.cos(r), y: t * Math.sin(r) });
1305
+ class W {
1306
+ constructor(e) {
1307
+ o(this, "svg");
1308
+ o(this, "group", xe());
1309
+ o(this, "line");
1310
+ o(this, "sourceArrow", null);
1311
+ o(this, "targetArrow", null);
1312
+ o(this, "onAfterRender");
1313
+ o(this, "afterRenderEmitter");
1314
+ this.params = e, [this.afterRenderEmitter, this.onAfterRender] = A(), this.svg = Ae(e.color), this.svg.appendChild(this.group), this.line = Se(e.width), this.group.appendChild(this.line), e.hasSourceArrow && (this.sourceArrow = B(), this.group.appendChild(this.sourceArrow)), e.hasTargetArrow && (this.targetArrow = B(), this.group.appendChild(this.targetArrow));
1315
+ }
1316
+ render(e) {
1317
+ const { x: t, y: s, width: i, height: n, flipX: a, flipY: h } = be(
1318
+ e.from,
1319
+ e.to
1320
+ );
1321
+ Ee(this.svg, { x: t, y: s, width: i, height: n }), this.group.style.transform = `scale(${a}, ${h})`;
1322
+ const d = ne(
1323
+ e.from.direction,
1324
+ a,
1325
+ h
1326
+ ), c = ne(
1327
+ e.to.direction,
1328
+ a,
1329
+ h
1330
+ ), l = {
1331
+ x: i,
1332
+ y: n
1333
+ };
1334
+ let g = c, p = -this.params.arrowLength, f;
1335
+ e.from.portId === e.to.portId ? (f = this.params.createCyclePath, g = d, p = this.params.arrowLength) : e.from.nodeId === e.to.nodeId ? f = this.params.createDetourPath : f = this.params.createLinePath;
1336
+ const v = f(
1337
+ d,
1338
+ c,
1339
+ l,
1340
+ a,
1341
+ h
1342
+ );
1343
+ this.line.setAttribute("d", v.path);
1344
+ let y = null;
1345
+ this.sourceArrow && (y = k(
1346
+ d,
1347
+ w,
1348
+ this.params.arrowLength,
1349
+ this.params.arrowWidth
1350
+ ), this.sourceArrow.setAttribute("d", y));
1351
+ let E = null;
1352
+ this.targetArrow && (E = k(
1353
+ g,
1354
+ l,
1355
+ p,
1356
+ this.params.arrowWidth
1357
+ ), this.targetArrow.setAttribute("d", E)), this.afterRenderEmitter.emit({
1358
+ edgePath: v,
1359
+ sourceArrowPath: y,
1360
+ targetArrowPath: E
1361
+ });
1362
+ }
1363
+ }
1364
+ class Ze {
1365
+ constructor(e) {
1366
+ o(this, "svg");
1367
+ o(this, "group");
1368
+ o(this, "line");
1369
+ o(this, "sourceArrow");
1370
+ o(this, "targetArrow");
1371
+ o(this, "onAfterRender");
1372
+ o(this, "arrowLength");
1373
+ o(this, "arrowWidth");
1374
+ o(this, "curvature");
1375
+ o(this, "portCycleRadius");
1376
+ o(this, "portCycleSmallRadius");
1377
+ o(this, "detourDirection");
1378
+ o(this, "detourDistance");
1379
+ o(this, "hasSourceArrow");
1380
+ o(this, "hasTargetArrow");
1381
+ o(this, "pathShape");
1382
+ o(this, "createCyclePath", (e) => new Ge({
1383
+ sourceDirection: e,
1384
+ radius: this.portCycleRadius,
1385
+ smallRadius: this.portCycleSmallRadius,
1386
+ arrowLength: this.arrowLength,
1387
+ hasSourceArrow: this.hasSourceArrow,
1388
+ hasTargetArrow: this.hasTargetArrow
1389
+ }));
1390
+ o(this, "createDetourPath", (e, t, s, i, n) => new Xe({
1391
+ to: s,
1392
+ sourceDirection: e,
1393
+ targetDirection: t,
1394
+ flipX: i,
1395
+ flipY: n,
1396
+ arrowLength: this.arrowLength,
1397
+ detourDirection: this.detourDirection,
1398
+ detourDistance: this.detourDistance,
1399
+ curvature: this.curvature,
1400
+ hasSourceArrow: this.hasSourceArrow,
1401
+ hasTargetArrow: this.hasTargetArrow
1402
+ }));
1403
+ o(this, "createLinePath", (e, t, s) => new ze({
1404
+ to: s,
1405
+ sourceDirection: e,
1406
+ targetDirection: t,
1407
+ arrowLength: this.arrowLength,
1408
+ curvature: this.curvature,
1409
+ hasSourceArrow: this.hasSourceArrow,
1410
+ hasTargetArrow: this.hasTargetArrow
1411
+ }));
1412
+ this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.curvature = (e == null ? void 0 : e.curvature) ?? u.curvature, this.portCycleRadius = (e == null ? void 0 : e.cycleRadius) ?? u.cycleRadius, this.portCycleSmallRadius = (e == null ? void 0 : e.smallCycleRadius) ?? u.smallCycleRadius, this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow, this.pathShape = new W({
1413
+ color: (e == null ? void 0 : e.color) ?? u.color,
1414
+ width: (e == null ? void 0 : e.width) ?? u.width,
1415
+ arrowLength: this.arrowLength,
1416
+ arrowWidth: this.arrowWidth,
1417
+ hasSourceArrow: this.hasSourceArrow,
1418
+ hasTargetArrow: this.hasTargetArrow,
1419
+ createCyclePath: this.createCyclePath,
1420
+ createDetourPath: this.createDetourPath,
1421
+ createLinePath: this.createLinePath
1422
+ }), this.svg = this.pathShape.svg, this.group = this.pathShape.group, this.line = this.pathShape.line, this.sourceArrow = this.pathShape.sourceArrow, this.targetArrow = this.pathShape.targetArrow, this.onAfterRender = this.pathShape.onAfterRender;
1423
+ }
1424
+ render(e) {
1425
+ this.pathShape.render(e);
1426
+ }
1427
+ }
1428
+ class Je {
1429
+ constructor(e) {
1430
+ o(this, "svg");
1431
+ o(this, "group");
1432
+ o(this, "line");
1433
+ o(this, "sourceArrow");
1434
+ o(this, "targetArrow");
1435
+ o(this, "onAfterRender");
1436
+ o(this, "arrowLength");
1437
+ o(this, "arrowWidth");
1438
+ o(this, "arrowOffset");
1439
+ o(this, "roundness");
1440
+ o(this, "cycleSquareSide");
1441
+ o(this, "detourDirection");
1442
+ o(this, "detourDistance");
1443
+ o(this, "hasSourceArrow");
1444
+ o(this, "hasTargetArrow");
1445
+ o(this, "pathShape");
1446
+ o(this, "createCyclePath", (e) => new j({
1447
+ sourceDirection: e,
1448
+ arrowLength: this.arrowLength,
1449
+ side: this.cycleSquareSide,
1450
+ arrowOffset: this.arrowOffset,
1451
+ roundness: this.roundness,
1452
+ hasSourceArrow: this.hasSourceArrow,
1453
+ hasTargetArrow: this.hasTargetArrow
1454
+ }));
1455
+ o(this, "createDetourPath", (e, t, s, i, n) => new H({
1456
+ to: s,
1457
+ sourceDirection: e,
1458
+ targetDirection: t,
1459
+ flipX: i,
1460
+ flipY: n,
1461
+ arrowLength: this.arrowLength,
1462
+ arrowOffset: this.arrowOffset,
1463
+ roundness: this.roundness,
1464
+ detourDirection: this.detourDirection,
1465
+ detourDistance: this.detourDistance,
1466
+ hasSourceArrow: this.hasSourceArrow,
1467
+ hasTargetArrow: this.hasTargetArrow
1468
+ }));
1469
+ o(this, "createLinePath", (e, t, s, i) => new Ye({
1470
+ to: s,
1471
+ sourceDirection: e,
1472
+ targetDirection: t,
1473
+ flipX: i,
1474
+ arrowLength: this.arrowLength,
1475
+ arrowOffset: this.arrowOffset,
1476
+ roundness: this.roundness,
1477
+ hasSourceArrow: this.hasSourceArrow,
1478
+ hasTargetArrow: this.hasTargetArrow
1479
+ }));
1480
+ this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
1481
+ const t = (e == null ? void 0 : e.roundness) ?? u.roundness;
1482
+ this.roundness = Math.min(
1483
+ t,
1484
+ this.arrowOffset,
1485
+ this.cycleSquareSide / 2
1486
+ ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow, this.pathShape = new W({
1487
+ color: (e == null ? void 0 : e.color) ?? u.color,
1488
+ width: (e == null ? void 0 : e.width) ?? u.width,
1489
+ arrowLength: this.arrowLength,
1490
+ arrowWidth: this.arrowWidth,
1491
+ hasSourceArrow: this.hasSourceArrow,
1492
+ hasTargetArrow: this.hasTargetArrow,
1493
+ createCyclePath: this.createCyclePath,
1494
+ createDetourPath: this.createDetourPath,
1495
+ createLinePath: this.createLinePath
1496
+ }), this.svg = this.pathShape.svg, this.group = this.pathShape.group, this.line = this.pathShape.line, this.sourceArrow = this.pathShape.sourceArrow, this.targetArrow = this.pathShape.targetArrow, this.onAfterRender = this.pathShape.onAfterRender;
1497
+ }
1498
+ render(e) {
1499
+ this.pathShape.render(e);
1500
+ }
1501
+ }
1502
+ class Qe {
1503
+ constructor(e) {
1504
+ o(this, "svg");
1505
+ o(this, "group");
1506
+ o(this, "line");
1507
+ o(this, "sourceArrow");
1508
+ o(this, "targetArrow");
1509
+ o(this, "onAfterRender");
1510
+ o(this, "arrowLength");
1511
+ o(this, "arrowWidth");
1512
+ o(this, "arrowOffset");
1513
+ o(this, "roundness");
1514
+ o(this, "cycleSquareSide");
1515
+ o(this, "detourDirection");
1516
+ o(this, "detourDistance");
1517
+ o(this, "hasSourceArrow");
1518
+ o(this, "hasTargetArrow");
1519
+ o(this, "pathShape");
1520
+ o(this, "createCyclePath", (e) => new j({
1521
+ sourceDirection: e,
1522
+ arrowLength: this.arrowLength,
1523
+ side: this.cycleSquareSide,
1524
+ arrowOffset: this.arrowOffset,
1525
+ roundness: this.roundness,
1526
+ hasSourceArrow: this.hasSourceArrow,
1527
+ hasTargetArrow: this.hasTargetArrow
1528
+ }));
1529
+ o(this, "createDetourPath", (e, t, s, i, n) => new H({
1530
+ to: s,
1531
+ sourceDirection: e,
1532
+ targetDirection: t,
1533
+ flipX: i,
1534
+ flipY: n,
1535
+ arrowLength: this.arrowLength,
1536
+ arrowOffset: this.arrowOffset,
1537
+ roundness: this.roundness,
1538
+ detourDirection: this.detourDirection,
1539
+ detourDistance: this.detourDistance,
1540
+ hasSourceArrow: this.hasSourceArrow,
1541
+ hasTargetArrow: this.hasTargetArrow
1542
+ }));
1543
+ o(this, "createLinePath", (e, t, s) => new He({
1544
+ to: s,
1545
+ sourceDirection: e,
1546
+ targetDirection: t,
1547
+ arrowLength: this.arrowLength,
1548
+ arrowOffset: this.arrowOffset,
1549
+ roundness: this.roundness,
1550
+ hasSourceArrow: this.hasSourceArrow,
1551
+ hasTargetArrow: this.hasTargetArrow
1552
+ }));
1553
+ this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
1554
+ const t = (e == null ? void 0 : e.roundness) ?? u.roundness;
1555
+ this.roundness = Math.min(
1556
+ t,
1557
+ this.arrowOffset,
1558
+ this.cycleSquareSide / 2
1559
+ ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow, this.pathShape = new W({
1560
+ color: (e == null ? void 0 : e.color) ?? u.color,
1561
+ width: (e == null ? void 0 : e.width) ?? u.width,
1562
+ arrowLength: this.arrowLength,
1563
+ arrowWidth: this.arrowWidth,
1564
+ hasSourceArrow: this.hasSourceArrow,
1565
+ hasTargetArrow: this.hasTargetArrow,
1566
+ createCyclePath: this.createCyclePath,
1567
+ createDetourPath: this.createDetourPath,
1568
+ createLinePath: this.createLinePath
1569
+ }), this.svg = this.pathShape.svg, this.group = this.pathShape.group, this.line = this.pathShape.line, this.sourceArrow = this.pathShape.sourceArrow, this.targetArrow = this.pathShape.targetArrow, this.onAfterRender = this.pathShape.onAfterRender;
1039
1570
  }
1040
- updateMaxNodePriority(e) {
1041
- const t = this.graph.getNode(e).priority;
1042
- this.maxNodePriority = Math.max(this.maxNodePriority, t);
1571
+ render(e) {
1572
+ this.pathShape.render(e);
1043
1573
  }
1044
1574
  }
1045
- const Be = (r, e, t) => ({
1046
- scale: r.scale,
1047
- x: r.x + r.scale * e,
1048
- y: r.y + r.scale * t
1049
- }), Ve = (r, e, t, s) => ({
1050
- scale: r.scale * e,
1051
- x: r.scale * (1 - e) * t + r.x,
1052
- y: r.scale * (1 - e) * s + r.y
1053
- }), I = (r) => {
1054
- const e = [], t = r.touches.length;
1055
- for (let a = 0; a < t; a++)
1056
- e.push([r.touches[a].clientX, r.touches[a].clientY]);
1057
- const s = e.reduce(
1058
- (a, d) => [a[0] + d[0], a[1] + d[1]],
1059
- [0, 0]
1060
- ), i = [s[0] / t, s[1] / t], h = e.map((a) => [a[0] - i[0], a[1] - i[1]]).reduce(
1061
- (a, d) => a + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
1062
- 0
1063
- );
1064
- return {
1065
- x: i[0],
1066
- y: i[1],
1067
- scale: h / t,
1068
- touchesCnt: t,
1069
- touches: e
1070
- };
1071
- };
1072
- class U {
1073
- constructor(e, t, s, i) {
1074
- o(this, "viewport");
1075
- o(this, "prevTouches", null);
1076
- o(this, "wheelFinishTimer", null);
1077
- o(this, "transformInProgress", !1);
1078
- o(this, "onBeforeDestroy", () => {
1079
- this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("wheel", this.preventWheelScaleListener), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
1080
- });
1081
- o(this, "onMouseDown", (e) => {
1082
- this.element === null || !this.params.mouseDownEventVerifier(e) || (B(this.element, this.params.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove, {
1083
- passive: !0
1084
- }), this.window.addEventListener("mouseup", this.onWindowMouseUp, {
1085
- passive: !0
1086
- }), this.startRegisteredTransform());
1087
- });
1088
- o(this, "onWindowMouseMove", (e) => {
1089
- const t = D(
1090
- this.window,
1091
- this.element,
1092
- e.clientX,
1093
- e.clientY
1094
- );
1095
- if (this.element === null || !t) {
1096
- this.stopMouseDrag();
1097
- return;
1098
- }
1099
- const s = -e.movementX, i = -e.movementY;
1100
- this.moveViewport(s, i);
1101
- });
1102
- o(this, "onWindowMouseUp", (e) => {
1103
- this.element === null || !this.params.mouseUpEventVerifier(e) || this.stopMouseDrag();
1104
- });
1105
- o(this, "onWheelScroll", (e) => {
1106
- if (!this.params.mouseWheelEventVerifier(e))
1107
- return;
1108
- const { left: t, top: s } = this.element.getBoundingClientRect(), i = e.clientX - t, n = e.clientY - s, a = 1 / (e.deltaY < 0 ? this.params.wheelSensitivity : 1 / this.params.wheelSensitivity);
1109
- this.wheelFinishTimer === null && this.params.onTransformStarted(), this.scaleViewport(a, i, n), this.wheelFinishTimer !== null && clearTimeout(this.wheelFinishTimer), this.wheelFinishTimer = setTimeout(() => {
1110
- this.transformInProgress || this.params.onTransformFinished(), this.wheelFinishTimer = null;
1111
- }, this.params.scaleWheelFinishTimeout);
1112
- });
1113
- o(this, "onTouchStart", (e) => {
1114
- if (this.prevTouches !== null) {
1115
- this.prevTouches = I(e);
1116
- return;
1117
- }
1118
- this.prevTouches = I(e), this.window.addEventListener("touchmove", this.onWindowTouchMove, {
1119
- passive: !0
1120
- }), this.window.addEventListener("touchend", this.onWindowTouchFinish, {
1121
- passive: !0
1122
- }), this.window.addEventListener("touchcancel", this.onWindowTouchFinish, {
1123
- passive: !0
1124
- }), this.startRegisteredTransform();
1125
- });
1126
- o(this, "onWindowTouchMove", (e) => {
1127
- const t = I(e);
1128
- if (!t.touches.every(
1129
- (i) => D(this.window, this.element, i[0], i[1])
1130
- )) {
1131
- this.stopTouchDrag();
1132
- return;
1133
- }
1134
- if ((t.touchesCnt === 1 || t.touchesCnt === 2) && this.moveViewport(
1135
- -(t.x - this.prevTouches.x),
1136
- -(t.y - this.prevTouches.y)
1137
- ), t.touchesCnt === 2) {
1138
- const { left: i, top: n } = this.element.getBoundingClientRect(), h = this.prevTouches.x - i, a = this.prevTouches.y - n, c = 1 / (t.scale / this.prevTouches.scale);
1139
- this.scaleViewport(c, h, a);
1140
- }
1141
- this.prevTouches = t;
1142
- });
1143
- o(this, "onWindowTouchFinish", (e) => {
1144
- e.touches.length > 0 ? this.prevTouches = I(e) : this.stopTouchDrag();
1145
- });
1146
- o(this, "observer", new ResizeObserver(() => {
1147
- const e = this.viewport.getViewportMatrix(), { width: t, height: s } = this.element.getBoundingClientRect(), i = this.params.transformPreprocessor({
1148
- prevTransform: e,
1149
- nextTransform: e,
1150
- canvasWidth: t,
1151
- canvasHeight: s
1152
- });
1153
- this.params.onResizeTransformStarted(), this.canvas.patchViewportMatrix(i), this.params.onResizeTransformFinished();
1575
+ class _e {
1576
+ constructor(e) {
1577
+ o(this, "svg");
1578
+ o(this, "group");
1579
+ o(this, "line");
1580
+ o(this, "sourceArrow");
1581
+ o(this, "targetArrow");
1582
+ o(this, "onAfterRender");
1583
+ o(this, "arrowLength");
1584
+ o(this, "arrowWidth");
1585
+ o(this, "arrowOffset");
1586
+ o(this, "roundness");
1587
+ o(this, "cycleSquareSide");
1588
+ o(this, "detourDirection");
1589
+ o(this, "detourDistance");
1590
+ o(this, "hasSourceArrow");
1591
+ o(this, "hasTargetArrow");
1592
+ o(this, "pathShape");
1593
+ o(this, "createCyclePath", (e) => new j({
1594
+ sourceDirection: e,
1595
+ arrowLength: this.arrowLength,
1596
+ side: this.cycleSquareSide,
1597
+ arrowOffset: this.arrowOffset,
1598
+ roundness: this.roundness,
1599
+ hasSourceArrow: this.hasSourceArrow,
1600
+ hasTargetArrow: this.hasTargetArrow
1154
1601
  }));
1155
- o(this, "preventWheelScaleListener", (e) => {
1156
- e.preventDefault();
1157
- });
1158
- this.canvas = e, this.element = t, this.window = s, this.params = i, this.element.addEventListener("wheel", this.preventWheelScaleListener, {
1159
- passive: !1
1160
- }), this.viewport = e.viewport, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown, {
1161
- passive: !0
1162
- }), this.element.addEventListener("wheel", this.onWheelScroll, {
1163
- passive: !0
1164
- }), this.element.addEventListener("touchstart", this.onTouchStart, {
1165
- passive: !0
1166
- }), e.onBeforeDestroy.subscribe(this.onBeforeDestroy);
1602
+ o(this, "createDetourPath", (e, t, s, i, n) => new H({
1603
+ to: s,
1604
+ sourceDirection: e,
1605
+ targetDirection: t,
1606
+ flipX: i,
1607
+ flipY: n,
1608
+ arrowLength: this.arrowLength,
1609
+ arrowOffset: this.arrowOffset,
1610
+ roundness: this.roundness,
1611
+ detourDirection: this.detourDirection,
1612
+ detourDistance: this.detourDistance,
1613
+ hasSourceArrow: this.hasSourceArrow,
1614
+ hasTargetArrow: this.hasTargetArrow
1615
+ }));
1616
+ o(this, "createLinePath", (e, t, s, i, n) => new je({
1617
+ to: s,
1618
+ sourceDirection: e,
1619
+ targetDirection: t,
1620
+ flipY: n,
1621
+ arrowLength: this.arrowLength,
1622
+ arrowOffset: this.arrowOffset,
1623
+ roundness: this.roundness,
1624
+ hasSourceArrow: this.hasSourceArrow,
1625
+ hasTargetArrow: this.hasTargetArrow
1626
+ }));
1627
+ this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
1628
+ const t = (e == null ? void 0 : e.roundness) ?? u.roundness;
1629
+ this.roundness = Math.min(
1630
+ t,
1631
+ this.arrowOffset,
1632
+ this.cycleSquareSide / 2
1633
+ ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirectionVertical, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow, this.pathShape = new W({
1634
+ color: (e == null ? void 0 : e.color) ?? u.color,
1635
+ width: (e == null ? void 0 : e.width) ?? u.width,
1636
+ arrowLength: this.arrowLength,
1637
+ arrowWidth: this.arrowWidth,
1638
+ hasSourceArrow: this.hasSourceArrow,
1639
+ hasTargetArrow: this.hasTargetArrow,
1640
+ createCyclePath: this.createCyclePath,
1641
+ createDetourPath: this.createDetourPath,
1642
+ createLinePath: this.createLinePath
1643
+ }), this.svg = this.pathShape.svg, this.group = this.pathShape.group, this.line = this.pathShape.line, this.sourceArrow = this.pathShape.sourceArrow, this.targetArrow = this.pathShape.targetArrow, this.onAfterRender = this.pathShape.onAfterRender;
1167
1644
  }
1168
- static configure(e, t, s, i) {
1169
- new U(e, t, s, i);
1645
+ render(e) {
1646
+ this.pathShape.render(e);
1170
1647
  }
1171
- moveViewport(e, t) {
1172
- const s = this.viewport.getViewportMatrix(), i = Be(s, e, t), { width: n, height: h } = this.element.getBoundingClientRect(), a = this.params.transformPreprocessor({
1173
- prevTransform: s,
1174
- nextTransform: i,
1175
- canvasWidth: n,
1176
- canvasHeight: h
1177
- });
1178
- this.performTransform(a);
1648
+ }
1649
+ const he = (r) => {
1650
+ if (r.diagonalDistance === 0)
1651
+ return "";
1652
+ const e = r.offset / r.diagonalDistance, t = r.flip * r.to.x, s = r.flip * r.to.y, i = {
1653
+ x: t * e + r.shift.x,
1654
+ y: s * e + r.shift.y
1655
+ }, n = {
1656
+ x: t / r.diagonalDistance,
1657
+ y: s / r.diagonalDistance
1658
+ };
1659
+ return k(
1660
+ n,
1661
+ i,
1662
+ r.arrowLength,
1663
+ r.arrowWidth
1664
+ );
1665
+ };
1666
+ class Pe {
1667
+ constructor(e) {
1668
+ o(this, "svg");
1669
+ o(this, "group", xe());
1670
+ o(this, "line");
1671
+ o(this, "sourceArrow", null);
1672
+ o(this, "targetArrow", null);
1673
+ o(this, "color");
1674
+ o(this, "width");
1675
+ o(this, "arrowLength");
1676
+ o(this, "arrowWidth");
1677
+ o(this, "sourceOffset");
1678
+ o(this, "targetOffset");
1679
+ o(this, "onAfterRender");
1680
+ o(this, "afterRenderEmitter");
1681
+ [this.afterRenderEmitter, this.onAfterRender] = A(), this.color = (e == null ? void 0 : e.color) ?? u.color, this.width = (e == null ? void 0 : e.width) ?? u.width, this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.sourceOffset = (e == null ? void 0 : e.sourceOffset) ?? u.preOffset, this.targetOffset = (e == null ? void 0 : e.targetOffset) ?? u.preOffset, this.svg = Ae(this.color), this.svg.appendChild(this.group), this.line = Se(this.width), this.group.appendChild(this.line), e != null && e.hasSourceArrow && (this.sourceArrow = B(), this.group.appendChild(this.sourceArrow)), e != null && e.hasTargetArrow && (this.targetArrow = B(), this.group.appendChild(this.targetArrow));
1179
1682
  }
1180
- scaleViewport(e, t, s) {
1181
- const i = this.canvas.viewport.getViewportMatrix(), n = Ve(i, e, t, s), { width: h, height: a } = this.element.getBoundingClientRect(), d = this.params.transformPreprocessor({
1182
- prevTransform: i,
1183
- nextTransform: n,
1184
- canvasWidth: h,
1185
- canvasHeight: a
1683
+ render(e) {
1684
+ const { x: t, y: s, width: i, height: n, flipX: a, flipY: h } = be(
1685
+ e.from,
1686
+ e.to
1687
+ );
1688
+ Ee(this.svg, { x: t, y: s, width: i, height: n }), this.group.style.transform = `scale(${a}, ${h})`;
1689
+ const d = { x: i, y: n }, c = new Ke({
1690
+ to: d,
1691
+ sourceOffset: this.sourceOffset,
1692
+ targetOffset: this.targetOffset,
1693
+ hasSourceArrow: this.sourceArrow !== null,
1694
+ hasTargetArrow: this.targetArrow !== null,
1695
+ arrowLength: this.arrowLength
1696
+ });
1697
+ this.line.setAttribute("d", c.path);
1698
+ let l = null;
1699
+ this.sourceArrow && (l = he({
1700
+ diagonalDistance: c.diagonalDistance,
1701
+ to: d,
1702
+ offset: this.sourceOffset,
1703
+ flip: 1,
1704
+ shift: w,
1705
+ arrowWidth: this.arrowWidth,
1706
+ arrowLength: this.arrowLength
1707
+ }), this.sourceArrow.setAttribute("d", l));
1708
+ let g = null;
1709
+ this.targetArrow && (g = he({
1710
+ diagonalDistance: c.diagonalDistance,
1711
+ to: d,
1712
+ offset: this.targetOffset,
1713
+ flip: -1,
1714
+ shift: d,
1715
+ arrowWidth: this.arrowWidth,
1716
+ arrowLength: this.arrowLength
1717
+ }), this.targetArrow.setAttribute("d", g)), this.afterRenderEmitter.emit({
1718
+ edgePath: c,
1719
+ sourceArrowPath: l,
1720
+ targetArrowPath: g
1186
1721
  });
1187
- this.performTransform(d);
1188
- }
1189
- stopMouseDrag() {
1190
- B(this.element, null), this.removeMouseDragListeners(), this.finishRegisteredTransform();
1191
- }
1192
- removeMouseDragListeners() {
1193
- this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
1194
- }
1195
- stopTouchDrag() {
1196
- this.prevTouches = null, this.removeTouchDragListeners(), this.finishRegisteredTransform();
1197
- }
1198
- removeTouchDragListeners() {
1199
- this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1200
- }
1201
- performTransform(e) {
1202
- this.params.onBeforeTransformChange(), this.canvas.patchViewportMatrix(e), this.params.onTransformChange();
1203
- }
1204
- startRegisteredTransform() {
1205
- this.transformInProgress = !0, this.params.onTransformStarted();
1206
1722
  }
1207
- finishRegisteredTransform() {
1208
- this.transformInProgress = !1, this.params.onTransformFinished();
1723
+ }
1724
+ const qe = () => {
1725
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "g");
1726
+ return r.style.pointerEvents = "auto", r.style.cursor = "pointer", r;
1727
+ }, et = (r) => {
1728
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
1729
+ return e.setAttribute("stroke", "transparent"), e.setAttribute("stroke-width", `${r}`), e.setAttribute("fill", "none"), e.setAttribute("stroke-linecap", "round"), e;
1730
+ }, ae = (r) => {
1731
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
1732
+ return e.setAttribute("stroke-linejoin", "round"), e.setAttribute("stroke-width", `${r}`), e.setAttribute("fill", "transparent"), e.setAttribute("stroke", "transparent"), e;
1733
+ };
1734
+ class tt extends Error {
1735
+ constructor(e) {
1736
+ super(e), this.name = "InteractiveEdgeError";
1209
1737
  }
1210
1738
  }
1211
- class X {
1212
- constructor(e, t, s, i, n, h) {
1213
- o(this, "canvasResizeObserver");
1214
- o(this, "nodeHorizontal");
1215
- o(this, "nodeVertical");
1216
- o(this, "viewport");
1217
- o(this, "viewportWidth", 0);
1218
- o(this, "viewportHeight", 0);
1219
- o(this, "viewportMatrix");
1220
- o(this, "loadedArea", {
1221
- xFrom: 1 / 0,
1222
- xTo: 1 / 0,
1223
- yFrom: 1 / 0,
1224
- yTo: 1 / 0
1225
- });
1226
- o(this, "updateLoadedArea", (e) => {
1227
- this.loadedArea = {
1228
- xFrom: e.x,
1229
- xTo: e.x + e.width,
1230
- yFrom: e.y,
1231
- yTo: e.y + e.height
1232
- };
1233
- });
1234
- o(this, "onBeforeDestroy", () => {
1235
- this.trigger.unsubscribe(this.updateLoadedArea), this.canvasResizeObserver.unobserve(this.element), this.canvas.viewport.onAfterUpdated.unsubscribe(
1236
- this.onAfterViewportUpdated
1237
- ), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
1238
- });
1239
- o(this, "onAfterViewportUpdated", () => {
1240
- this.userTransformInProgress || (this.viewportMatrix = this.viewport.getViewportMatrix(), this.loadAreaAroundViewport());
1739
+ class Te {
1740
+ constructor(e, t) {
1741
+ o(this, "svg");
1742
+ o(this, "group");
1743
+ o(this, "line");
1744
+ o(this, "sourceArrow");
1745
+ o(this, "targetArrow");
1746
+ o(this, "handle", qe());
1747
+ o(this, "onAfterRender");
1748
+ o(this, "interactiveLine");
1749
+ o(this, "interactiveSourceArrow", null);
1750
+ o(this, "interactiveTargetArrow", null);
1751
+ if (this.baseEdge = e, e instanceof Te)
1752
+ throw new tt(
1753
+ "interactive edge can be configured only once"
1754
+ );
1755
+ this.svg = this.baseEdge.svg, this.group = this.baseEdge.group, this.line = this.baseEdge.line, this.sourceArrow = this.baseEdge.sourceArrow, this.targetArrow = this.baseEdge.targetArrow, this.onAfterRender = this.baseEdge.onAfterRender;
1756
+ const s = (t == null ? void 0 : t.width) ?? u.interactiveWidth;
1757
+ this.interactiveLine = et(s), this.handle.appendChild(this.interactiveLine), this.sourceArrow && (this.interactiveSourceArrow = ae(s), this.handle.appendChild(this.interactiveSourceArrow)), this.targetArrow && (this.interactiveTargetArrow = ae(s), this.handle.appendChild(this.interactiveTargetArrow)), this.group.appendChild(this.handle), this.baseEdge.onAfterRender.subscribe((i) => {
1758
+ this.interactiveLine.setAttribute("d", i.edgePath.path), this.interactiveSourceArrow && this.interactiveSourceArrow.setAttribute("d", i.sourceArrowPath), this.interactiveTargetArrow && this.interactiveTargetArrow.setAttribute("d", i.targetArrowPath);
1241
1759
  });
1242
- o(this, "userTransformInProgress", !1);
1243
- this.canvas = e, this.element = t, this.window = s, this.trigger = n, this.params = h, this.nodeHorizontal = this.params.nodeContainingRadius.horizontal, this.nodeVertical = this.params.nodeContainingRadius.vertical, this.canvasResizeObserver = new ResizeObserver((d) => {
1244
- const c = d[0];
1245
- this.viewportWidth = c.contentRect.width, this.viewportHeight = c.contentRect.height, this.scheduleLoadAreaAroundViewport();
1246
- }), this.viewport = e.viewport;
1247
- const a = {
1248
- ...i,
1249
- onResizeTransformStarted: () => {
1250
- this.userTransformInProgress = !0, i.onResizeTransformStarted();
1251
- },
1252
- onResizeTransformFinished: () => {
1253
- this.userTransformInProgress = !1, i.onResizeTransformFinished();
1254
- },
1255
- onBeforeTransformChange: () => {
1256
- this.userTransformInProgress = !0, i.onBeforeTransformChange();
1257
- },
1258
- onTransformChange: () => {
1259
- this.userTransformInProgress = !1;
1260
- const d = this.viewportMatrix;
1261
- this.viewportMatrix = this.viewport.getViewportMatrix(), d.scale !== this.viewportMatrix.scale && this.scheduleEnsureViewportAreaLoaded(), i.onTransformChange();
1262
- },
1263
- onTransformFinished: () => {
1264
- this.scheduleLoadAreaAroundViewport(), i.onTransformFinished();
1265
- }
1266
- };
1267
- U.configure(
1268
- e,
1269
- this.element,
1270
- this.window,
1271
- a
1272
- ), this.viewportMatrix = this.viewport.getViewportMatrix(), this.trigger.subscribe(this.updateLoadedArea), this.canvasResizeObserver.observe(this.element), this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
1273
1760
  }
1274
- static configure(e, t, s, i, n, h) {
1275
- new X(
1276
- e,
1277
- t,
1278
- s,
1279
- i,
1280
- n,
1281
- h
1282
- );
1761
+ render(e) {
1762
+ this.baseEdge.render(e);
1283
1763
  }
1284
- scheduleLoadAreaAroundViewport() {
1285
- setTimeout(() => {
1286
- this.loadAreaAroundViewport();
1764
+ }
1765
+ class xt {
1766
+ constructor(e, t) {
1767
+ o(this, "group");
1768
+ o(this, "line");
1769
+ o(this, "sourceArrow");
1770
+ o(this, "targetArrow");
1771
+ o(this, "onAfterRender");
1772
+ o(this, "svg");
1773
+ /**
1774
+ * @deprecated
1775
+ * use midpointElement instead
1776
+ */
1777
+ o(this, "medianElement");
1778
+ this.baseShape = e, this.midpointElement = t, this.medianElement = this.midpointElement, this.svg = this.baseShape.svg, this.group = this.baseShape.group, this.line = this.baseShape.line, this.sourceArrow = this.baseShape.sourceArrow, this.targetArrow = this.baseShape.targetArrow, this.onAfterRender = this.baseShape.onAfterRender, this.svg.append(this.midpointElement), this.baseShape.onAfterRender.subscribe((s) => {
1779
+ const i = s.edgePath.midpoint, n = `translate(${i.x}px, ${i.y}px)`;
1780
+ this.midpointElement.style.setProperty("transform", n);
1287
1781
  });
1288
1782
  }
1289
- scheduleEnsureViewportAreaLoaded() {
1290
- const e = this.viewportWidth * this.viewportMatrix.scale, t = this.viewportHeight * this.viewportMatrix.scale, s = this.viewportMatrix.x - this.nodeHorizontal, i = this.viewportMatrix.y - this.nodeVertical, n = this.viewportMatrix.x + e + this.nodeHorizontal, h = this.viewportMatrix.y + t + this.nodeVertical;
1291
- this.loadedArea.xFrom < s && this.loadedArea.xTo > n && this.loadedArea.yFrom < i && this.loadedArea.yTo > h || this.scheduleLoadAreaAroundViewport();
1292
- }
1293
- loadAreaAroundViewport() {
1294
- const e = this.viewportWidth * this.viewportMatrix.scale, t = this.viewportHeight * this.viewportMatrix.scale, s = this.viewportMatrix.x - e - this.nodeHorizontal, i = this.viewportMatrix.y - t - this.nodeVertical, n = 3 * e + 2 * this.nodeHorizontal, h = 3 * t + 2 * this.nodeVertical;
1295
- this.trigger.emit({ x: s, y: i, width: n, height: h });
1783
+ render(e) {
1784
+ this.baseShape.render(e);
1296
1785
  }
1297
1786
  }
1298
- const Ue = () => {
1299
- const r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1300
- return r.style.position = "absolute", r.style.inset = "0", r;
1301
- }, Ce = () => {
1302
- const r = document.createElementNS("http://www.w3.org/2000/svg", "rect");
1303
- return r.setAttribute("fill", "url(#pattern)"), r;
1304
- }, We = () => {
1305
- const r = document.createElementNS(
1306
- "http://www.w3.org/2000/svg",
1307
- "pattern"
1787
+ const De = (r, e) => {
1788
+ const t = new fe(), s = new ue(t, e, r), i = {
1789
+ nodes: {
1790
+ centerFn: me,
1791
+ priorityFn: () => 0
1792
+ },
1793
+ edges: {
1794
+ shapeFactory: () => new Pe(),
1795
+ priorityFn: () => 0
1796
+ },
1797
+ ports: {
1798
+ direction: 0
1799
+ }
1800
+ };
1801
+ return new we(
1802
+ r,
1803
+ t,
1804
+ e,
1805
+ s,
1806
+ i
1308
1807
  );
1309
- return r.setAttribute("id", "pattern"), r;
1310
1808
  };
1311
- class Y {
1312
- constructor(e, t, s) {
1313
- o(this, "svg", Ue());
1314
- o(this, "patternRenderingRectangle", Ce());
1315
- o(this, "pattern", We());
1316
- o(this, "patternContent");
1317
- o(this, "tileWidth");
1318
- o(this, "tileHeight");
1319
- o(this, "halfTileWidth");
1320
- o(this, "halfTileHeight");
1321
- o(this, "maxViewportScale");
1322
- o(this, "visible", !1);
1323
- o(this, "resizeObserver", new ResizeObserver((e) => {
1324
- const t = e[0], { width: s, height: i } = t.contentRect;
1325
- this.svg.setAttribute("width", `${s}`), this.svg.setAttribute("height", `${i}`), this.patternRenderingRectangle.setAttribute("width", `${s}`), this.patternRenderingRectangle.setAttribute("height", `${i}`);
1326
- const n = this.tileWidth / s, h = this.tileHeight / i;
1327
- this.pattern.setAttribute("width", `${n}`), this.pattern.setAttribute("height", `${h}`);
1328
- }));
1329
- o(this, "onAfterTransformUpdated", () => {
1330
- const e = this.canvas.viewport.getContentMatrix(), t = e.x - this.halfTileWidth * e.scale, s = e.y - this.halfTileHeight * e.scale, i = `matrix(${e.scale}, 0, 0, ${e.scale}, ${t}, ${s})`;
1331
- this.pattern.setAttribute("patternTransform", i), this.updateVisibility();
1809
+ class K {
1810
+ constructor(e, t, s, i) {
1811
+ o(this, "grabbedNodeId", null);
1812
+ o(this, "maxNodePriority", 0);
1813
+ o(this, "previousTouchCoordinates", null);
1814
+ o(this, "graph");
1815
+ o(this, "onAfterNodeAdded", (e) => {
1816
+ this.updateMaxNodePriority(e);
1817
+ const t = this.graph.getNode(e);
1818
+ t.element.addEventListener("mousedown", this.onMouseDown, {
1819
+ passive: !0
1820
+ }), t.element.addEventListener("touchstart", this.onTouchStart, {
1821
+ passive: !0
1822
+ });
1823
+ });
1824
+ o(this, "onAfterNodeUpdated", (e) => {
1825
+ this.updateMaxNodePriority(e);
1826
+ });
1827
+ o(this, "onBeforeNodeRemoved", (e) => {
1828
+ const t = this.graph.getNode(e);
1829
+ t.element.removeEventListener("mousedown", this.onMouseDown), t.element.removeEventListener("touchstart", this.onTouchStart);
1332
1830
  });
1333
1831
  o(this, "onBeforeDestroy", () => {
1334
- this.resizeObserver.unobserve(this.host), this.host.removeChild(this.svg), this.canvas.viewport.onAfterUpdated.unsubscribe(
1335
- this.onAfterTransformUpdated
1336
- ), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
1832
+ this.graph.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded), this.graph.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated), this.graph.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved), this.graph.onBeforeClear.unsubscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy), this.removeMouseDragListeners(), this.removeTouchDragListeners();
1337
1833
  });
1338
- this.canvas = e, this.host = s, this.tileWidth = t.tileWidth, this.tileHeight = t.tileHeight, this.halfTileWidth = this.tileWidth / 2, this.halfTileHeight = this.tileHeight / 2, this.patternContent = t.renderer, this.maxViewportScale = t.maxViewportScale;
1339
- const i = `translate(${this.halfTileWidth}, ${this.halfTileHeight})`;
1340
- this.patternContent.setAttribute("transform", i), this.pattern.appendChild(this.patternContent);
1341
- const n = document.createElementNS("http://www.w3.org/2000/svg", "defs");
1342
- n.appendChild(this.pattern), this.svg.appendChild(n), this.svg.appendChild(this.patternRenderingRectangle), this.resizeObserver.observe(this.host), this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated), this.onAfterTransformUpdated(), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
1343
- }
1344
- static configure(e, t, s) {
1345
- new Y(e, t, s);
1346
- }
1347
- updateVisibility() {
1348
- const t = this.canvas.viewport.getViewportMatrix().scale > this.maxViewportScale;
1349
- t && this.visible ? (this.visible = !1, this.host.removeChild(this.svg)) : !t && !this.visible && (this.visible = !0, this.host.appendChild(this.svg));
1350
- }
1351
- }
1352
- const le = (r, e) => ({
1353
- x: r / 2,
1354
- y: e / 2
1355
- });
1356
- class H {
1357
- constructor(e, t, s, i, n) {
1358
- o(this, "overlayCanvas");
1359
- o(this, "staticOverlayPortId", "static");
1360
- o(this, "draggingOverlayPortId", "dragging");
1361
- o(this, "staticPortId", null);
1362
- o(this, "isDirect", !0);
1363
- o(this, "onAfterPortMarked", (e) => {
1364
- const t = this.canvas.graph.getPort(e);
1365
- this.canvas.graph.getElementPortsIds(t.element).length === 1 && this.hookPortEvents(t.element);
1834
+ o(this, "onBeforeClear", () => {
1835
+ this.canvas.graph.getAllNodeIds().forEach((e) => {
1836
+ const t = this.canvas.graph.getNode(e);
1837
+ t.element.removeEventListener("mousedown", this.onMouseDown), t.element.removeEventListener("touchstart", this.onTouchStart);
1838
+ }), this.maxNodePriority = 0;
1366
1839
  });
1367
- o(this, "onBeforePortUnmarked", (e) => {
1368
- const t = this.canvas.graph.getPort(e);
1369
- this.canvas.graph.getElementPortsIds(t.element).length === 1 && this.unhookPortEvents(t.element);
1840
+ o(this, "onMouseDown", (e) => {
1841
+ if (!this.config.mouseDownEventVerifier(e))
1842
+ return;
1843
+ const t = e.currentTarget, s = this.graph.getElementNodeId(t), i = this.graph.getNode(s);
1844
+ this.config.onBeforeNodeDrag({
1845
+ nodeId: s,
1846
+ element: i.element,
1847
+ x: i.x,
1848
+ y: i.y
1849
+ }) && (e.stopImmediatePropagation(), this.grabbedNodeId = s, U(this.element, this.config.dragCursor), this.moveNodeOnTop(s), this.window.addEventListener("mouseup", this.onWindowMouseUp, {
1850
+ passive: !0
1851
+ }), this.window.addEventListener("mousemove", this.onWindowMouseMove, {
1852
+ passive: !0
1853
+ }));
1370
1854
  });
1371
- o(this, "onPortMouseDown", (e) => {
1372
- const t = e.currentTarget;
1373
- this.params.mouseDownEventVerifier(e) && this.isPortConnectionAllowed(t) && (e.stopPropagation(), this.grabPort(t, { x: e.clientX, y: e.clientY }), this.window.addEventListener("mousemove", this.onWindowMouseMove, {
1855
+ o(this, "onTouchStart", (e) => {
1856
+ if (e.touches.length !== 1)
1857
+ return;
1858
+ e.stopImmediatePropagation(), this.previousTouchCoordinates = {
1859
+ x: e.touches[0].clientX,
1860
+ y: e.touches[0].clientY
1861
+ };
1862
+ const t = e.currentTarget, s = this.canvas.graph.getElementNodeId(t), i = this.graph.getNode(s);
1863
+ this.config.onBeforeNodeDrag({
1864
+ nodeId: s,
1865
+ element: i.element,
1866
+ x: i.x,
1867
+ y: i.y
1868
+ }) && (this.grabbedNodeId = s, this.moveNodeOnTop(s), this.window.addEventListener("touchmove", this.onWindowTouchMove, {
1374
1869
  passive: !0
1375
- }), this.window.addEventListener("mouseup", this.onWindowMouseUp, {
1870
+ }), this.window.addEventListener("touchend", this.onWindowTouchFinish, {
1871
+ passive: !0
1872
+ }), this.window.addEventListener("touchcancel", this.onWindowTouchFinish, {
1376
1873
  passive: !0
1377
1874
  }));
1378
1875
  });
1379
1876
  o(this, "onWindowMouseMove", (e) => {
1380
- if (!D(
1877
+ if (!L(
1381
1878
  this.window,
1382
- this.overlayLayer,
1879
+ this.element,
1383
1880
  e.clientX,
1384
1881
  e.clientY
1385
1882
  )) {
1386
- this.stopMouseDrag();
1883
+ this.cancelMouseDrag();
1387
1884
  return;
1388
1885
  }
1389
- this.moveDraggingNode({ x: e.clientX, y: e.clientY });
1886
+ this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
1390
1887
  });
1391
1888
  o(this, "onWindowMouseUp", (e) => {
1392
- this.params.mouseUpEventVerifier(e) && (this.tryCreateConnection({ x: e.clientX, y: e.clientY }), this.stopMouseDrag());
1393
- });
1394
- o(this, "onPortTouchStart", (e) => {
1395
- const t = e.currentTarget;
1396
- if (!(e.touches.length === 1 && this.isPortConnectionAllowed(t)))
1397
- return;
1398
- e.stopPropagation();
1399
- const i = e.touches[0];
1400
- this.grabPort(t, { x: i.clientX, y: i.clientY }), this.window.addEventListener("touchmove", this.onWindowTouchMove, {
1401
- passive: !0
1402
- }), this.window.addEventListener("touchend", this.onWindowTouchFinish, {
1403
- passive: !0
1404
- }), this.window.addEventListener("touchcancel", this.onWindowTouchFinish, {
1405
- passive: !0
1406
- });
1889
+ this.config.mouseUpEventVerifier(e) && this.cancelMouseDrag();
1407
1890
  });
1408
1891
  o(this, "onWindowTouchMove", (e) => {
1892
+ if (e.touches.length !== 1)
1893
+ return;
1409
1894
  const t = e.touches[0];
1410
- if (!D(
1895
+ if (!L(
1411
1896
  this.window,
1412
- this.overlayLayer,
1897
+ this.element,
1413
1898
  t.clientX,
1414
1899
  t.clientY
1415
1900
  )) {
1416
- this.stopTouchDrag();
1901
+ this.cancelTouchDrag();
1417
1902
  return;
1418
1903
  }
1419
- this.moveDraggingNode({ x: t.clientX, y: t.clientY });
1420
- });
1421
- o(this, "onWindowTouchFinish", (e) => {
1422
- const t = e.changedTouches[0];
1423
- this.tryCreateConnection({ x: t.clientX, y: t.clientY }), this.stopTouchDrag();
1424
- });
1425
- o(this, "onBeforeClear", () => {
1426
- this.canvas.graph.getAllPortIds().forEach((e) => {
1427
- const t = this.canvas.graph.getPort(e);
1428
- this.unhookPortEvents(t.element);
1429
- });
1430
- });
1431
- o(this, "onBeforeDestroy", () => {
1432
- this.stopMouseDrag(), this.stopTouchDrag(), this.canvas.graph.onAfterPortMarked.unsubscribe(this.onAfterPortMarked), this.canvas.graph.onBeforePortUnmarked.unsubscribe(
1433
- this.onBeforePortUnmarked
1434
- ), this.canvas.graph.onBeforeClear.unsubscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
1435
- });
1436
- o(this, "onEdgeCreated", (e) => {
1437
- this.params.onAfterEdgeCreated(e);
1438
- });
1439
- this.canvas = e, this.overlayLayer = t, this.viewportStore = s, this.window = i, this.params = n;
1440
- const h = new ce(), a = new he(
1441
- h,
1442
- this.viewportStore,
1443
- this.overlayLayer
1444
- ), d = {
1445
- nodes: {
1446
- centerFn: le,
1447
- priorityFn: () => 0
1448
- },
1449
- edges: {
1450
- shapeFactory: this.params.edgeShapeFactory,
1451
- priorityFn: () => 0
1452
- },
1453
- ports: {
1454
- direction: 0
1904
+ if (this.grabbedNodeId !== null && this.previousTouchCoordinates !== null) {
1905
+ const i = t.clientX - this.previousTouchCoordinates.x, n = t.clientY - this.previousTouchCoordinates.y;
1906
+ this.dragNode(this.grabbedNodeId, i, n), this.previousTouchCoordinates = {
1907
+ x: e.touches[0].clientX,
1908
+ y: e.touches[0].clientY
1909
+ };
1455
1910
  }
1456
- };
1457
- this.overlayCanvas = new de(
1458
- this.overlayLayer,
1459
- h,
1460
- this.viewportStore,
1461
- a,
1462
- d
1463
- ), this.canvas.graph.onAfterPortMarked.subscribe(this.onAfterPortMarked), this.canvas.graph.onBeforePortUnmarked.subscribe(this.onBeforePortUnmarked), this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
1464
- }
1465
- static configure(e, t, s, i, n) {
1466
- new H(
1467
- e,
1468
- t,
1469
- s,
1470
- i,
1471
- n
1472
- );
1473
- }
1474
- grabPort(e, t) {
1475
- const s = this.canvas.graph.getElementPortsIds(e)[0], i = this.canvas.graph.getPort(s);
1476
- this.staticPortId = s;
1477
- const n = this.params.connectionTypeResolver(this.staticPortId), h = e.getBoundingClientRect(), a = h.x + h.width / 2, d = h.y + h.height / 2, c = this.overlayLayer.getBoundingClientRect(), g = this.canvas.viewport.getViewportMatrix(), l = T(g, {
1478
- x: a - c.x,
1479
- y: d - c.y
1480
- }), p = T(g, {
1481
- x: t.x - c.x,
1482
- y: t.y - c.y
1483
- }), f = {
1484
- overlayId: this.staticOverlayPortId,
1485
- portCoords: l,
1486
- portDirection: i.direction
1487
- }, v = {
1488
- overlayId: this.draggingOverlayPortId,
1489
- portCoords: p,
1490
- portDirection: this.params.dragPortDirection
1491
- };
1492
- this.isDirect = n === "direct";
1493
- const E = this.isDirect ? f : v, A = this.isDirect ? v : f;
1494
- this.createOverlayGraph(E, A);
1495
- }
1496
- hookPortEvents(e) {
1497
- e.addEventListener("mousedown", this.onPortMouseDown, {
1498
- passive: !0
1499
- }), e.addEventListener("touchstart", this.onPortTouchStart, {
1500
- passive: !0
1501
1911
  });
1502
- }
1503
- unhookPortEvents(e) {
1504
- e.removeEventListener("mousedown", this.onPortMouseDown), e.removeEventListener("touchstart", this.onPortTouchStart);
1505
- }
1506
- stopMouseDrag() {
1507
- this.resetDragState(), this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
1508
- }
1509
- stopTouchDrag() {
1510
- this.resetDragState(), this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1511
- }
1512
- resetDragState() {
1513
- this.staticPortId = null, this.isDirect = !0, this.overlayCanvas.clear();
1514
- }
1515
- createOverlayGraph(e, t) {
1516
- const s = this.createAddNodeRequest(e);
1517
- this.overlayCanvas.addNode(s);
1518
- const i = this.createAddNodeRequest(t);
1519
- this.overlayCanvas.addNode(i), this.overlayCanvas.addEdge({
1520
- from: e.overlayId,
1521
- to: t.overlayId
1912
+ o(this, "onWindowTouchFinish", () => {
1913
+ this.previousTouchCoordinates = null, this.cancelTouchDrag();
1522
1914
  });
1915
+ this.canvas = e, this.element = t, this.window = s, this.config = i, this.graph = e.graph, this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.graph.onBeforeClear.subscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
1523
1916
  }
1524
- createAddNodeRequest(e) {
1525
- const t = document.createElement("div");
1526
- return {
1527
- id: e.overlayId,
1528
- element: t,
1529
- x: e.portCoords.x,
1530
- y: e.portCoords.y,
1531
- ports: [
1532
- {
1533
- id: e.overlayId,
1534
- element: t,
1535
- direction: e.portDirection
1536
- }
1537
- ]
1538
- };
1917
+ static configure(e, t, s, i) {
1918
+ new K(e, t, s, i);
1539
1919
  }
1540
- tryCreateConnection(e) {
1541
- const t = this.findPortAtPoint(e);
1542
- if (t === null) {
1543
- this.params.onEdgeCreationInterrupted(this.staticPortId, this.isDirect);
1920
+ dragNode(e, t, s) {
1921
+ const i = this.graph.getNode(e);
1922
+ if (i === null)
1544
1923
  return;
1545
- }
1546
- const s = this.isDirect ? this.staticPortId : t, i = this.isDirect ? t : this.staticPortId, n = { from: s, to: i }, h = this.params.connectionPreprocessor(n);
1547
- h !== null ? (this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated), this.canvas.addEdge(h), this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)) : this.params.onEdgeCreationPrevented(n);
1548
- }
1549
- moveDraggingNode(e) {
1550
- const t = this.overlayLayer.getBoundingClientRect(), s = {
1551
- x: e.x - t.x,
1552
- y: e.y - t.y
1553
- }, i = this.canvas.viewport.getViewportMatrix(), n = T(i, s);
1554
- this.overlayCanvas.updateNode(this.draggingOverlayPortId, {
1555
- x: n.x,
1556
- y: n.y
1924
+ const n = this.canvas.viewport.getContentMatrix(), a = T(n, {
1925
+ x: i.x,
1926
+ y: i.y
1927
+ }), h = T(
1928
+ { scale: 1, x: t, y: s },
1929
+ a
1930
+ ), d = this.canvas.viewport.getViewportMatrix(), c = T(d, h);
1931
+ this.canvas.updateNode(e, { x: c.x, y: c.y }), this.config.onNodeDrag({
1932
+ nodeId: e,
1933
+ element: i.element,
1934
+ x: c.x,
1935
+ y: c.y
1557
1936
  });
1558
1937
  }
1559
- findPortAtPoint(e) {
1560
- const t = document.elementsFromPoint(e.x, e.y);
1561
- for (const s of t) {
1562
- const i = this.findPortAtElement(s);
1563
- if (i !== null)
1564
- return i;
1938
+ moveNodeOnTop(e) {
1939
+ if (this.config.moveOnTop) {
1940
+ if (this.maxNodePriority++, this.config.moveEdgesOnTop) {
1941
+ const t = this.maxNodePriority;
1942
+ this.maxNodePriority++, this.graph.getNodeAdjacentEdgeIds(e).forEach((i) => {
1943
+ this.canvas.updateEdge(i, { priority: t });
1944
+ });
1945
+ }
1946
+ this.canvas.updateNode(e, { priority: this.maxNodePriority });
1565
1947
  }
1566
- return null;
1567
- }
1568
- findPortAtElement(e) {
1569
- let t = e, s = null;
1570
- for (; t !== null && (s = this.canvas.graph.getElementPortsIds(t)[0] ?? null, s === null); )
1571
- t = t.parentElement;
1572
- return s;
1573
- }
1574
- isPortConnectionAllowed(e) {
1575
- const t = this.canvas.graph.getElementPortsIds(e)[0];
1576
- return this.params.connectionTypeResolver(t) !== null;
1577
- }
1578
- }
1579
- const $e = () => {
1580
- const r = document.createElement("div");
1581
- return r.style.width = "100%", r.style.height = "100%", r.style.position = "relative", r;
1582
- }, $ = () => {
1583
- const r = document.createElement("div");
1584
- return r.style.position = "absolute", r.style.inset = "0", r;
1585
- };
1586
- class Oe {
1587
- constructor(e) {
1588
- o(this, "background", $());
1589
- o(this, "main", $());
1590
- o(this, "overlay", $());
1591
- o(this, "host", $e());
1592
- this.element = e, this.element.appendChild(this.host), this.host.appendChild(this.background), this.host.appendChild(this.main), this.overlay.style.pointerEvents = "none", this.host.appendChild(this.overlay);
1593
- }
1594
- destroy() {
1595
- this.host.removeChild(this.background), this.host.removeChild(this.main), this.host.removeChild(this.overlay), this.element.removeChild(this.host);
1596
- }
1597
- }
1598
- const O = (r) => () => r, te = O(0), Fe = () => {
1599
- let r = 0;
1600
- return () => r++;
1601
- }, ke = (r, e) => {
1602
- let t = te, s = te;
1603
- const i = Fe();
1604
- return r === "incremental" && (t = i), e === "incremental" && (s = i), typeof r == "number" && (t = O(r)), typeof e == "number" && (s = O(e)), typeof r == "function" && (t = r), typeof e == "function" && (s = e), {
1605
- nodesPriorityFn: t,
1606
- edgesPriorityFn: s
1607
- };
1608
- }, m = (r, e, t) => ({
1609
- x: e.x * r.x - e.y * r.y + ((1 - e.x) * t.x + e.y * t.y),
1610
- y: e.y * r.x + e.x * r.y + ((1 - e.x) * t.y - e.y * t.x)
1611
- }), w = {
1612
- x: 0,
1613
- y: 0
1614
- };
1615
- class ze {
1616
- constructor(e) {
1617
- o(this, "path");
1618
- o(this, "midpoint");
1619
- this.params = e;
1620
- const t = this.params.to;
1621
- this.midpoint = { x: t.x / 2, y: t.y / 2 };
1622
- const s = m(
1623
- { x: this.params.arrowLength, y: w.y },
1624
- this.params.sourceDirection,
1625
- w
1626
- ), i = m(
1627
- { x: this.params.to.x - this.params.arrowLength, y: this.params.to.y },
1628
- this.params.targetDirection,
1629
- this.params.to
1630
- ), n = {
1631
- x: s.x + this.params.sourceDirection.x * this.params.curvature,
1632
- y: s.y + this.params.sourceDirection.y * this.params.curvature
1633
- }, h = {
1634
- x: i.x - this.params.targetDirection.x * this.params.curvature,
1635
- y: i.y - this.params.targetDirection.y * this.params.curvature
1636
- }, a = `M ${s.x} ${s.y} C ${n.x} ${n.y}, ${h.x} ${h.y}, ${i.x} ${i.y}`, d = this.params.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${s.x} ${s.y} `, c = this.params.hasTargetArrow ? "" : ` M ${i.x} ${i.y} L ${this.params.to.x} ${this.params.to.y}`;
1637
- this.path = `${d}${a}${c}`;
1638
1948
  }
1639
- }
1640
- const ge = (r, e, t, s) => ({
1641
- x: e * r.x + (1 - e) / 2 * s.x,
1642
- y: t * r.y + (1 - t) / 2 * s.y
1643
- });
1644
- class Xe {
1645
- constructor(e) {
1646
- o(this, "path");
1647
- o(this, "midpoint");
1648
- this.params = e;
1649
- const t = this.params.hasSourceArrow ? m(
1650
- { x: this.params.arrowLength, y: w.y },
1651
- this.params.sourceDirection,
1652
- w
1653
- ) : w, s = this.params.hasTargetArrow ? m(
1654
- {
1655
- x: this.params.to.x - this.params.arrowLength,
1656
- y: this.params.to.y
1657
- },
1658
- this.params.targetDirection,
1659
- this.params.to
1660
- ) : this.params.to, i = this.params.arrowLength, n = Math.cos(this.params.detourDirection) * this.params.detourDistance, h = Math.sin(this.params.detourDirection) * this.params.detourDistance, a = n * this.params.flipX, d = h * this.params.flipY, c = m(
1661
- { x: i, y: w.y },
1662
- this.params.sourceDirection,
1663
- w
1664
- ), g = {
1665
- x: c.x + a,
1666
- y: c.y + d
1667
- }, l = m(
1668
- { x: this.params.to.x - i, y: this.params.to.y },
1669
- this.params.targetDirection,
1670
- this.params.to
1671
- ), p = {
1672
- x: l.x + a,
1673
- y: l.y + d
1674
- }, f = {
1675
- x: (g.x + p.x) / 2,
1676
- y: (g.y + p.y) / 2
1677
- }, v = {
1678
- x: c.x + this.params.curvature * this.params.sourceDirection.x,
1679
- y: c.y + this.params.curvature * this.params.sourceDirection.y
1680
- }, E = {
1681
- x: l.x - this.params.curvature * this.params.targetDirection.x,
1682
- y: l.y - this.params.curvature * this.params.targetDirection.y
1683
- }, A = {
1684
- x: c.x + a,
1685
- y: c.y + d
1686
- }, S = {
1687
- x: l.x + a,
1688
- y: l.y + d
1689
- };
1690
- this.path = [
1691
- `M ${t.x} ${t.y}`,
1692
- `L ${c.x} ${c.y}`,
1693
- `C ${v.x} ${v.y} ${A.x} ${A.y} ${f.x} ${f.y}`,
1694
- `C ${S.x} ${S.y} ${E.x} ${E.y} ${l.x} ${l.y}`,
1695
- `L ${s.x} ${s.y}`
1696
- ].join(" "), this.midpoint = ge(f, e.flipX, e.flipY, e.to);
1949
+ cancelMouseDrag() {
1950
+ const e = this.graph.getNode(this.grabbedNodeId);
1951
+ e !== null && this.config.onNodeDragFinished({
1952
+ nodeId: this.grabbedNodeId,
1953
+ element: e.element,
1954
+ x: e.x,
1955
+ y: e.y
1956
+ }), this.grabbedNodeId = null, U(this.element, null), this.removeMouseDragListeners();
1697
1957
  }
1698
- }
1699
- const R = (r, e) => {
1700
- const t = [];
1701
- 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) {
1702
- const s = r.length - 1;
1703
- let i = 0, n = 0, h = 0;
1704
- r.forEach((a, d) => {
1705
- let c = 0, g = 0, l = 0;
1706
- const p = d > 0, f = d < s, v = p && f;
1707
- if (p && (c = -i, g = -n, l = h), f) {
1708
- const L = r[d + 1];
1709
- i = L.x - a.x, n = L.y - a.y, h = Math.sqrt(i * i + n * n);
1710
- }
1711
- const A = h !== 0 ? Math.min((v ? e : 0) / h, d < s - 1 ? 0.5 : 1) : 0, S = v ? { x: a.x + i * A, y: a.y + n * A } : a, N = l !== 0 ? Math.min((v ? e : 0) / l, d > 1 ? 0.5 : 1) : 0, M = v ? { x: a.x + c * N, y: a.y + g * N } : a;
1712
- d > 0 && t.push(`L ${M.x} ${M.y}`), v && t.push(
1713
- `C ${a.x} ${a.y} ${a.x} ${a.y} ${S.x} ${S.y}`
1714
- );
1715
- });
1958
+ removeMouseDragListeners() {
1959
+ this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
1716
1960
  }
1717
- return t.join(" ");
1718
- };
1719
- class Ye {
1720
- constructor(e) {
1721
- o(this, "path");
1722
- o(this, "midpoint");
1723
- this.params = e;
1724
- const t = this.params.to;
1725
- this.midpoint = { x: t.x / 2, y: t.y / 2 };
1726
- const s = this.params.hasSourceArrow ? m(
1727
- { x: this.params.arrowLength, y: w.y },
1728
- this.params.sourceDirection,
1729
- w
1730
- ) : w, i = this.params.hasTargetArrow ? m(
1731
- {
1732
- x: this.params.to.x - this.params.arrowLength,
1733
- y: this.params.to.y
1734
- },
1735
- this.params.targetDirection,
1736
- this.params.to
1737
- ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, h = n - this.params.roundness, a = m(
1738
- { x: h, y: w.y },
1739
- this.params.sourceDirection,
1740
- w
1741
- ), d = m(
1742
- { x: this.params.to.x - h, y: this.params.to.y },
1743
- this.params.targetDirection,
1744
- this.params.to
1745
- ), c = Math.max((a.x + d.x) / 2, n), g = this.params.to.y / 2, l = {
1746
- x: this.params.flipX > 0 ? c : -n,
1747
- y: a.y
1748
- }, p = { x: l.x, y: g }, f = {
1749
- x: this.params.flipX > 0 ? this.params.to.x - c : this.params.to.x + n,
1750
- y: d.y
1751
- }, v = { x: f.x, y: g };
1752
- this.path = R(
1753
- [s, a, l, p, v, f, d, i],
1754
- this.params.roundness
1755
- );
1961
+ cancelTouchDrag() {
1962
+ this.previousTouchCoordinates = null;
1963
+ const e = this.graph.getNode(this.grabbedNodeId);
1964
+ e !== null && this.config.onNodeDragFinished({
1965
+ nodeId: this.grabbedNodeId,
1966
+ element: e.element,
1967
+ x: e.x,
1968
+ y: e.y
1969
+ }), this.grabbedNodeId = null, this.removeTouchDragListeners();
1756
1970
  }
1757
- }
1758
- class j {
1759
- constructor(e) {
1760
- o(this, "path");
1761
- o(this, "midpoint");
1762
- this.params = e;
1763
- const t = this.params.hasSourceArrow ? m(
1764
- { x: this.params.arrowLength, y: w.y },
1765
- this.params.sourceDirection,
1766
- w
1767
- ) : w, s = this.params.hasTargetArrow ? m(
1768
- {
1769
- x: this.params.to.x - this.params.arrowLength,
1770
- y: this.params.to.y
1771
- },
1772
- this.params.targetDirection,
1773
- this.params.to
1774
- ) : this.params.to, i = this.params.arrowLength + this.params.arrowOffset, n = m(
1775
- { x: i, y: w.y },
1776
- this.params.sourceDirection,
1777
- w
1778
- ), h = Math.cos(this.params.detourDirection) * this.params.detourDistance, a = Math.sin(this.params.detourDirection) * this.params.detourDistance, d = h * this.params.flipX, c = a * this.params.flipY, g = { x: n.x + d, y: n.y + c }, l = m(
1779
- { x: this.params.to.x - i, y: this.params.to.y },
1780
- this.params.targetDirection,
1781
- this.params.to
1782
- ), p = { x: l.x + d, y: l.y + c }, f = { x: (g.x + p.x) / 2, y: (g.y + p.y) / 2 };
1783
- this.midpoint = ge(f, e.flipX, e.flipY, e.to), this.path = R(
1784
- [t, n, g, p, l, s],
1785
- this.params.roundness
1786
- );
1971
+ removeTouchDragListeners() {
1972
+ this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1787
1973
  }
1788
- }
1789
- class He {
1790
- constructor(e) {
1791
- o(this, "path");
1792
- o(this, "midpoint");
1793
- this.params = e;
1794
- const t = this.params.to;
1795
- this.midpoint = { x: t.x / 2, y: t.y / 2 };
1796
- const s = this.params.hasSourceArrow ? m(
1797
- { x: this.params.arrowLength, y: w.y },
1798
- this.params.sourceDirection,
1799
- w
1800
- ) : w, i = this.params.hasTargetArrow ? m(
1801
- {
1802
- x: this.params.to.x - this.params.arrowLength,
1803
- y: this.params.to.y
1804
- },
1805
- this.params.targetDirection,
1806
- this.params.to
1807
- ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, h = m(
1808
- { x: n, y: w.y },
1809
- this.params.sourceDirection,
1810
- w
1811
- ), a = m(
1812
- { x: this.params.to.x - n, y: this.params.to.y },
1813
- this.params.targetDirection,
1814
- this.params.to
1815
- );
1816
- this.path = R([s, h, a, i], this.params.roundness);
1974
+ updateMaxNodePriority(e) {
1975
+ const t = this.graph.getNode(e).priority;
1976
+ this.maxNodePriority = Math.max(this.maxNodePriority, t);
1817
1977
  }
1818
1978
  }
1819
- class je {
1820
- constructor(e) {
1821
- o(this, "path");
1822
- o(this, "midpoint");
1823
- this.params = e;
1824
- const t = this.params.to;
1825
- this.midpoint = { x: t.x / 2, y: t.y / 2 };
1826
- const s = this.params.hasSourceArrow ? m(
1827
- { x: this.params.arrowLength, y: w.y },
1828
- this.params.sourceDirection,
1829
- w
1830
- ) : w, i = this.params.hasTargetArrow ? m(
1831
- {
1832
- x: this.params.to.x - this.params.arrowLength,
1833
- y: this.params.to.y
1834
- },
1835
- this.params.targetDirection,
1836
- this.params.to
1837
- ) : this.params.to, n = this.params.arrowLength + this.params.arrowOffset, h = n - this.params.roundness, a = m(
1838
- { x: h, y: w.y },
1839
- this.params.sourceDirection,
1840
- w
1841
- ), d = m(
1842
- { x: this.params.to.x - h, y: this.params.to.y },
1843
- this.params.targetDirection,
1844
- this.params.to
1845
- ), c = Math.max((a.y + d.y) / 2, n), g = this.params.to.x / 2, l = {
1846
- x: a.x,
1847
- y: this.params.flipY > 0 ? c : -n
1848
- }, p = { x: g, y: l.y }, f = {
1849
- x: d.x,
1850
- y: this.params.flipY > 0 ? this.params.to.y - c : this.params.to.y + n
1851
- }, v = { x: g, y: f.y };
1852
- this.path = R(
1853
- [s, a, l, p, v, f, d, i],
1854
- this.params.roundness
1855
- );
1979
+ const rt = (r, e, t) => ({
1980
+ scale: r.scale,
1981
+ x: r.x + r.scale * e,
1982
+ y: r.y + r.scale * t
1983
+ }), ot = (r, e, t, s) => ({
1984
+ scale: r.scale * e,
1985
+ x: r.scale * (1 - e) * t + r.x,
1986
+ y: r.scale * (1 - e) * s + r.y
1987
+ }), I = (r) => {
1988
+ const e = [], t = r.touches.length;
1989
+ for (let h = 0; h < t; h++)
1990
+ e.push([r.touches[h].clientX, r.touches[h].clientY]);
1991
+ const s = e.reduce(
1992
+ (h, d) => [h[0] + d[0], h[1] + d[1]],
1993
+ [0, 0]
1994
+ ), i = [s[0] / t, s[1] / t], a = e.map((h) => [h[0] - i[0], h[1] - i[1]]).reduce(
1995
+ (h, d) => h + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
1996
+ 0
1997
+ );
1998
+ return {
1999
+ x: i[0],
2000
+ y: i[1],
2001
+ scale: a / t,
2002
+ touchesCnt: t,
2003
+ touches: e
2004
+ };
2005
+ };
2006
+ class $ {
2007
+ constructor(e, t, s, i) {
2008
+ o(this, "viewport");
2009
+ o(this, "prevTouches", null);
2010
+ o(this, "wheelFinishTimer", null);
2011
+ o(this, "transformInProgress", !1);
2012
+ o(this, "onBeforeDestroy", () => {
2013
+ this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("wheel", this.preventWheelScaleListener), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
2014
+ });
2015
+ o(this, "onMouseDown", (e) => {
2016
+ this.element === null || !this.params.mouseDownEventVerifier(e) || (U(this.element, this.params.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove, {
2017
+ passive: !0
2018
+ }), this.window.addEventListener("mouseup", this.onWindowMouseUp, {
2019
+ passive: !0
2020
+ }), this.startRegisteredTransform());
2021
+ });
2022
+ o(this, "onWindowMouseMove", (e) => {
2023
+ const t = L(
2024
+ this.window,
2025
+ this.element,
2026
+ e.clientX,
2027
+ e.clientY
2028
+ );
2029
+ if (this.element === null || !t) {
2030
+ this.stopMouseDrag();
2031
+ return;
2032
+ }
2033
+ const s = -e.movementX, i = -e.movementY;
2034
+ this.moveViewport(s, i);
2035
+ });
2036
+ o(this, "onWindowMouseUp", (e) => {
2037
+ this.element === null || !this.params.mouseUpEventVerifier(e) || this.stopMouseDrag();
2038
+ });
2039
+ o(this, "onWheelScroll", (e) => {
2040
+ if (!this.params.mouseWheelEventVerifier(e))
2041
+ return;
2042
+ const { left: t, top: s } = this.element.getBoundingClientRect(), i = e.clientX - t, n = e.clientY - s, h = 1 / (e.deltaY < 0 ? this.params.wheelSensitivity : 1 / this.params.wheelSensitivity);
2043
+ this.wheelFinishTimer === null && this.params.onTransformStarted(), this.scaleViewport(h, i, n), this.wheelFinishTimer !== null && clearTimeout(this.wheelFinishTimer), this.wheelFinishTimer = setTimeout(() => {
2044
+ this.transformInProgress || this.params.onTransformFinished(), this.wheelFinishTimer = null;
2045
+ }, this.params.scaleWheelFinishTimeout);
2046
+ });
2047
+ o(this, "onTouchStart", (e) => {
2048
+ if (this.prevTouches !== null) {
2049
+ this.prevTouches = I(e);
2050
+ return;
2051
+ }
2052
+ this.prevTouches = I(e), this.window.addEventListener("touchmove", this.onWindowTouchMove, {
2053
+ passive: !0
2054
+ }), this.window.addEventListener("touchend", this.onWindowTouchFinish, {
2055
+ passive: !0
2056
+ }), this.window.addEventListener("touchcancel", this.onWindowTouchFinish, {
2057
+ passive: !0
2058
+ }), this.startRegisteredTransform();
2059
+ });
2060
+ o(this, "onWindowTouchMove", (e) => {
2061
+ const t = I(e);
2062
+ if (!t.touches.every(
2063
+ (i) => L(this.window, this.element, i[0], i[1])
2064
+ )) {
2065
+ this.stopTouchDrag();
2066
+ return;
2067
+ }
2068
+ if ((t.touchesCnt === 1 || t.touchesCnt === 2) && this.moveViewport(
2069
+ -(t.x - this.prevTouches.x),
2070
+ -(t.y - this.prevTouches.y)
2071
+ ), t.touchesCnt === 2) {
2072
+ const { left: i, top: n } = this.element.getBoundingClientRect(), a = this.prevTouches.x - i, h = this.prevTouches.y - n, c = 1 / (t.scale / this.prevTouches.scale);
2073
+ this.scaleViewport(c, a, h);
2074
+ }
2075
+ this.prevTouches = t;
2076
+ });
2077
+ o(this, "onWindowTouchFinish", (e) => {
2078
+ e.touches.length > 0 ? this.prevTouches = I(e) : this.stopTouchDrag();
2079
+ });
2080
+ o(this, "observer", new ResizeObserver(() => {
2081
+ const e = this.viewport.getViewportMatrix(), { width: t, height: s } = this.element.getBoundingClientRect(), i = this.params.transformPreprocessor({
2082
+ prevTransform: e,
2083
+ nextTransform: e,
2084
+ canvasWidth: t,
2085
+ canvasHeight: s
2086
+ });
2087
+ this.params.onResizeTransformStarted(), this.canvas.patchViewportMatrix(i), this.params.onResizeTransformFinished();
2088
+ }));
2089
+ o(this, "preventWheelScaleListener", (e) => {
2090
+ e.preventDefault();
2091
+ });
2092
+ this.canvas = e, this.element = t, this.window = s, this.params = i, this.element.addEventListener("wheel", this.preventWheelScaleListener, {
2093
+ passive: !1
2094
+ }), this.viewport = e.viewport, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown, {
2095
+ passive: !0
2096
+ }), this.element.addEventListener("wheel", this.onWheelScroll, {
2097
+ passive: !0
2098
+ }), this.element.addEventListener("touchstart", this.onTouchStart, {
2099
+ passive: !0
2100
+ }), e.onBeforeDestroy.subscribe(this.onBeforeDestroy);
1856
2101
  }
1857
- }
1858
- class G {
1859
- constructor(e) {
1860
- o(this, "path");
1861
- o(this, "midpoint");
1862
- this.params = e;
1863
- const t = this.params.arrowOffset, s = this.params.side, i = this.params.arrowLength + t, n = i + 2 * s, a = [
1864
- { x: this.params.arrowLength, y: w.y },
1865
- { x: i, y: w.y },
1866
- { x: i, y: this.params.side },
1867
- { x: n, y: this.params.side },
1868
- { x: n, y: -this.params.side },
1869
- { x: i, y: -this.params.side },
1870
- { x: i, y: w.y },
1871
- { x: this.params.arrowLength, y: w.y }
1872
- ].map(
1873
- (c) => m(c, this.params.sourceDirection, w)
1874
- ), d = `M ${w.x} ${w.y} L ${a[0].x} ${a[0].y} `;
1875
- this.path = `${this.params.hasSourceArrow || this.params.hasTargetArrow ? "" : d}${R(a, this.params.roundness)}`, this.midpoint = { x: (a[3].x + a[4].x) / 2, y: (a[3].y + a[4].y) / 2 };
2102
+ static configure(e, t, s, i) {
2103
+ new $(e, t, s, i);
1876
2104
  }
1877
- }
1878
- class Ge {
1879
- constructor(e) {
1880
- o(this, "path");
1881
- o(this, "midpoint");
1882
- this.params = e;
1883
- const t = this.params.smallRadius, s = this.params.radius, i = t + s, n = t * s / i, h = Math.sqrt(i * i - t * t), a = h * t / i, d = h + s + this.params.arrowLength, c = this.params.arrowLength + a, l = [
1884
- { x: this.params.arrowLength, y: w.y },
1885
- { x: c, y: n },
1886
- { x: c, y: -n },
1887
- { x: d, y: 0 }
1888
- ].map(
1889
- (v) => m(v, this.params.sourceDirection, w)
1890
- ), p = [
1891
- `M ${l[0].x} ${l[0].y}`,
1892
- `A ${t} ${t} 0 0 1 ${l[1].x} ${l[1].y}`,
1893
- `A ${s} ${s} 0 1 0 ${l[2].x} ${l[2].y}`,
1894
- `A ${t} ${t} 0 0 1 ${l[0].x} ${l[0].y}`
1895
- ].join(" "), f = `M 0 0 L ${l[0].x} ${l[0].y} `;
1896
- this.path = `${this.params.hasSourceArrow || this.params.hasTargetArrow ? "" : f}${p}`, this.midpoint = l[3];
2105
+ moveViewport(e, t) {
2106
+ const s = this.viewport.getViewportMatrix(), i = rt(s, e, t), { width: n, height: a } = this.element.getBoundingClientRect(), h = this.params.transformPreprocessor({
2107
+ prevTransform: s,
2108
+ nextTransform: i,
2109
+ canvasWidth: n,
2110
+ canvasHeight: a
2111
+ });
2112
+ this.performTransform(h);
1897
2113
  }
1898
- }
1899
- class Ze {
1900
- constructor(e) {
1901
- o(this, "path");
1902
- o(this, "midpoint");
1903
- o(this, "diagonalDistance");
1904
- this.params = e;
1905
- const t = this.params.to;
1906
- if (this.midpoint = { x: t.x / 2, y: t.y / 2 }, this.diagonalDistance = Math.sqrt(
1907
- this.params.to.x * this.params.to.x + this.params.to.y * this.params.to.y
1908
- ), Math.sqrt(
1909
- this.params.to.x * this.params.to.x + this.params.to.y * this.params.to.y
1910
- ) === 0) {
1911
- this.path = "";
1912
- return;
1913
- }
1914
- const i = this.createDirectLinePoint({
1915
- offset: this.params.sourceOffset,
1916
- hasArrow: this.params.hasSourceArrow,
1917
- flip: 1,
1918
- shift: w
1919
- }), n = this.createDirectLinePoint({
1920
- offset: this.params.targetOffset,
1921
- hasArrow: this.params.hasTargetArrow,
1922
- flip: -1,
1923
- shift: this.params.to
2114
+ scaleViewport(e, t, s) {
2115
+ const i = this.canvas.viewport.getViewportMatrix(), n = ot(i, e, t, s), { width: a, height: h } = this.element.getBoundingClientRect(), d = this.params.transformPreprocessor({
2116
+ prevTransform: i,
2117
+ nextTransform: n,
2118
+ canvasWidth: a,
2119
+ canvasHeight: h
1924
2120
  });
1925
- this.path = `M ${i.x} ${i.y} L ${n.x} ${n.y}`;
2121
+ this.performTransform(d);
1926
2122
  }
1927
- createDirectLinePoint(e) {
1928
- const t = e.hasArrow ? this.params.arrowLength : 0, s = e.offset + t, i = e.flip * s / this.diagonalDistance;
1929
- return {
1930
- x: this.params.to.x * i + e.shift.x,
1931
- y: this.params.to.y * i + e.shift.y
1932
- };
2123
+ stopMouseDrag() {
2124
+ U(this.element, null), this.removeMouseDragListeners(), this.finishRegisteredTransform();
1933
2125
  }
1934
- }
1935
- const ue = (r, e) => {
1936
- r.style.transform = `translate(${e.x}px, ${e.y}px)`, r.style.width = `${Math.max(e.width, 1)}px`, r.style.height = `${Math.max(e.height, 1)}px`;
1937
- }, Z = Object.freeze({
1938
- edgeColor: "--edge-color"
1939
- }), we = (r) => {
1940
- const e = document.createElementNS("http://www.w3.org/2000/svg", "svg");
1941
- return e.style.pointerEvents = "none", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.overflow = "visible", e.style.setProperty(Z.edgeColor, r), e;
1942
- }, V = () => {
1943
- const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
1944
- return r.setAttribute("fill", `var(${Z.edgeColor})`), r;
1945
- }, pe = () => {
1946
- const r = document.createElementNS("http://www.w3.org/2000/svg", "g");
1947
- return r.style.transformOrigin = "50% 50%", r;
1948
- }, fe = (r) => {
1949
- const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
1950
- return e.setAttribute("stroke", `var(${Z.edgeColor})`), e.setAttribute("stroke-width", `${r}`), e.setAttribute("fill", "none"), e;
1951
- }, ve = (r, e) => {
1952
- const t = {
1953
- x: r.x + r.width / 2,
1954
- y: r.y + r.height / 2
1955
- }, s = {
1956
- x: e.x + e.width / 2,
1957
- y: e.y + e.height / 2
1958
- }, i = Math.min(t.x, s.x), n = Math.min(t.y, s.y), h = Math.abs(s.x - t.x), a = Math.abs(s.y - t.y), d = t.x <= s.x ? 1 : -1, c = t.y <= s.y ? 1 : -1;
1959
- return {
1960
- x: i,
1961
- y: n,
1962
- width: h,
1963
- height: a,
1964
- flipX: d,
1965
- flipY: c
1966
- };
1967
- }, F = (r, e, t, s) => {
1968
- const n = [
1969
- w,
1970
- { x: t, y: s },
1971
- { x: t, y: -s }
1972
- ].map((c) => m(c, r, w)).map((c) => ({ x: c.x + e.x, y: c.y + e.y })), h = `M ${n[0].x} ${n[0].y}`, a = `L ${n[1].x} ${n[1].y}`, d = `L ${n[2].x} ${n[2].y}`;
1973
- return `${h} ${a} ${d} Z`;
1974
- }, u = Object.freeze({
1975
- color: "#777777",
1976
- width: 1,
1977
- arrowLength: 15,
1978
- arrowWidth: 4,
1979
- arrowOffset: 15,
1980
- hasSourceArrow: !1,
1981
- hasTargetArrow: !1,
1982
- cycleRadius: 30,
1983
- cycleSquareSide: 30,
1984
- roundness: 10,
1985
- detourDistance: 100,
1986
- detourDirection: -Math.PI / 2,
1987
- detourDirectionVertical: 0,
1988
- smallCycleRadius: 15,
1989
- curvature: 90,
1990
- interactiveWidth: 10,
1991
- preOffset: 0
1992
- }), re = (r, e, t) => ({ x: e * Math.cos(r), y: t * Math.sin(r) });
1993
- class C {
1994
- constructor(e) {
1995
- o(this, "svg");
1996
- o(this, "group", pe());
1997
- o(this, "line");
1998
- o(this, "sourceArrow", null);
1999
- o(this, "targetArrow", null);
2000
- o(this, "onAfterRender");
2001
- o(this, "afterRenderEmitter");
2002
- this.params = e, [this.afterRenderEmitter, this.onAfterRender] = y(), this.svg = we(e.color), this.svg.appendChild(this.group), this.line = fe(e.width), this.group.appendChild(this.line), e.hasSourceArrow && (this.sourceArrow = V(), this.group.appendChild(this.sourceArrow)), e.hasTargetArrow && (this.targetArrow = V(), this.group.appendChild(this.targetArrow));
2126
+ removeMouseDragListeners() {
2127
+ this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
2003
2128
  }
2004
- render(e) {
2005
- const { x: t, y: s, width: i, height: n, flipX: h, flipY: a } = ve(
2006
- e.from,
2007
- e.to
2008
- );
2009
- ue(this.svg, { x: t, y: s, width: i, height: n }), this.group.style.transform = `scale(${h}, ${a})`;
2010
- const d = re(
2011
- e.from.direction,
2012
- h,
2013
- a
2014
- ), c = re(
2015
- e.to.direction,
2016
- h,
2017
- a
2018
- ), g = {
2019
- x: i,
2020
- y: n
2021
- };
2022
- let l = c, p = -this.params.arrowLength, f;
2023
- e.from.portId === e.to.portId ? (f = this.params.createCyclePath, l = d, p = this.params.arrowLength) : e.from.nodeId === e.to.nodeId ? f = this.params.createDetourPath : f = this.params.createLinePath;
2024
- const v = f(
2025
- d,
2026
- c,
2027
- g,
2028
- h,
2029
- a
2030
- );
2031
- this.line.setAttribute("d", v.path);
2032
- let E = null;
2033
- this.sourceArrow && (E = F(
2034
- d,
2035
- w,
2036
- this.params.arrowLength,
2037
- this.params.arrowWidth
2038
- ), this.sourceArrow.setAttribute("d", E));
2039
- let A = null;
2040
- this.targetArrow && (A = F(
2041
- l,
2042
- g,
2043
- p,
2044
- this.params.arrowWidth
2045
- ), this.targetArrow.setAttribute("d", A)), this.afterRenderEmitter.emit({
2046
- edgePath: v,
2047
- sourceArrowPath: E,
2048
- targetArrowPath: A
2049
- });
2129
+ stopTouchDrag() {
2130
+ this.prevTouches = null, this.removeTouchDragListeners(), this.finishRegisteredTransform();
2050
2131
  }
2051
- }
2052
- class Je {
2053
- constructor(e) {
2054
- o(this, "svg");
2055
- o(this, "group");
2056
- o(this, "line");
2057
- o(this, "sourceArrow");
2058
- o(this, "targetArrow");
2059
- o(this, "onAfterRender");
2060
- o(this, "arrowLength");
2061
- o(this, "arrowWidth");
2062
- o(this, "curvature");
2063
- o(this, "portCycleRadius");
2064
- o(this, "portCycleSmallRadius");
2065
- o(this, "detourDirection");
2066
- o(this, "detourDistance");
2067
- o(this, "hasSourceArrow");
2068
- o(this, "hasTargetArrow");
2069
- o(this, "pathShape");
2070
- o(this, "createCyclePath", (e) => new Ge({
2071
- sourceDirection: e,
2072
- radius: this.portCycleRadius,
2073
- smallRadius: this.portCycleSmallRadius,
2074
- arrowLength: this.arrowLength,
2075
- hasSourceArrow: this.hasSourceArrow,
2076
- hasTargetArrow: this.hasTargetArrow
2077
- }));
2078
- o(this, "createDetourPath", (e, t, s, i, n) => new Xe({
2079
- to: s,
2080
- sourceDirection: e,
2081
- targetDirection: t,
2082
- flipX: i,
2083
- flipY: n,
2084
- arrowLength: this.arrowLength,
2085
- detourDirection: this.detourDirection,
2086
- detourDistance: this.detourDistance,
2087
- curvature: this.curvature,
2088
- hasSourceArrow: this.hasSourceArrow,
2089
- hasTargetArrow: this.hasTargetArrow
2090
- }));
2091
- o(this, "createLinePath", (e, t, s) => new ze({
2092
- to: s,
2093
- sourceDirection: e,
2094
- targetDirection: t,
2095
- arrowLength: this.arrowLength,
2096
- curvature: this.curvature,
2097
- hasSourceArrow: this.hasSourceArrow,
2098
- hasTargetArrow: this.hasTargetArrow
2099
- }));
2100
- this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.curvature = (e == null ? void 0 : e.curvature) ?? u.curvature, this.portCycleRadius = (e == null ? void 0 : e.cycleRadius) ?? u.cycleRadius, this.portCycleSmallRadius = (e == null ? void 0 : e.smallCycleRadius) ?? u.smallCycleRadius, this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow, this.pathShape = new C({
2101
- color: (e == null ? void 0 : e.color) ?? u.color,
2102
- width: (e == null ? void 0 : e.width) ?? u.width,
2103
- arrowLength: this.arrowLength,
2104
- arrowWidth: this.arrowWidth,
2105
- hasSourceArrow: this.hasSourceArrow,
2106
- hasTargetArrow: this.hasTargetArrow,
2107
- createCyclePath: this.createCyclePath,
2108
- createDetourPath: this.createDetourPath,
2109
- createLinePath: this.createLinePath
2110
- }), this.svg = this.pathShape.svg, this.group = this.pathShape.group, this.line = this.pathShape.line, this.sourceArrow = this.pathShape.sourceArrow, this.targetArrow = this.pathShape.targetArrow, this.onAfterRender = this.pathShape.onAfterRender;
2132
+ removeTouchDragListeners() {
2133
+ this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
2111
2134
  }
2112
- render(e) {
2113
- this.pathShape.render(e);
2135
+ performTransform(e) {
2136
+ this.params.onBeforeTransformChange(), this.canvas.patchViewportMatrix(e), this.params.onTransformChange();
2137
+ }
2138
+ startRegisteredTransform() {
2139
+ this.transformInProgress = !0, this.params.onTransformStarted();
2140
+ }
2141
+ finishRegisteredTransform() {
2142
+ this.transformInProgress = !1, this.params.onTransformFinished();
2114
2143
  }
2115
2144
  }
2116
- class Ke {
2117
- constructor(e) {
2118
- o(this, "svg");
2119
- o(this, "group");
2120
- o(this, "line");
2121
- o(this, "sourceArrow");
2122
- o(this, "targetArrow");
2123
- o(this, "onAfterRender");
2124
- o(this, "arrowLength");
2125
- o(this, "arrowWidth");
2126
- o(this, "arrowOffset");
2127
- o(this, "roundness");
2128
- o(this, "cycleSquareSide");
2129
- o(this, "detourDirection");
2130
- o(this, "detourDistance");
2131
- o(this, "hasSourceArrow");
2132
- o(this, "hasTargetArrow");
2133
- o(this, "pathShape");
2134
- o(this, "createCyclePath", (e) => new G({
2135
- sourceDirection: e,
2136
- arrowLength: this.arrowLength,
2137
- side: this.cycleSquareSide,
2138
- arrowOffset: this.arrowOffset,
2139
- roundness: this.roundness,
2140
- hasSourceArrow: this.hasSourceArrow,
2141
- hasTargetArrow: this.hasTargetArrow
2142
- }));
2143
- o(this, "createDetourPath", (e, t, s, i, n) => new j({
2144
- to: s,
2145
- sourceDirection: e,
2146
- targetDirection: t,
2147
- flipX: i,
2148
- flipY: n,
2149
- arrowLength: this.arrowLength,
2150
- arrowOffset: this.arrowOffset,
2151
- roundness: this.roundness,
2152
- detourDirection: this.detourDirection,
2153
- detourDistance: this.detourDistance,
2154
- hasSourceArrow: this.hasSourceArrow,
2155
- hasTargetArrow: this.hasTargetArrow
2156
- }));
2157
- o(this, "createLinePath", (e, t, s, i) => new Ye({
2158
- to: s,
2159
- sourceDirection: e,
2160
- targetDirection: t,
2161
- flipX: i,
2162
- arrowLength: this.arrowLength,
2163
- arrowOffset: this.arrowOffset,
2164
- roundness: this.roundness,
2165
- hasSourceArrow: this.hasSourceArrow,
2166
- hasTargetArrow: this.hasTargetArrow
2167
- }));
2168
- this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
2169
- const t = (e == null ? void 0 : e.roundness) ?? u.roundness;
2170
- this.roundness = Math.min(
2145
+ class Z {
2146
+ constructor(e, t, s, i, n, a) {
2147
+ o(this, "canvasResizeObserver");
2148
+ o(this, "nodeHorizontal");
2149
+ o(this, "nodeVertical");
2150
+ o(this, "viewport");
2151
+ o(this, "viewportWidth", 0);
2152
+ o(this, "viewportHeight", 0);
2153
+ o(this, "viewportMatrix");
2154
+ o(this, "loadedArea", {
2155
+ xFrom: 1 / 0,
2156
+ xTo: 1 / 0,
2157
+ yFrom: 1 / 0,
2158
+ yTo: 1 / 0
2159
+ });
2160
+ o(this, "updateLoadedArea", (e) => {
2161
+ this.loadedArea = {
2162
+ xFrom: e.x,
2163
+ xTo: e.x + e.width,
2164
+ yFrom: e.y,
2165
+ yTo: e.y + e.height
2166
+ };
2167
+ });
2168
+ o(this, "onBeforeDestroy", () => {
2169
+ this.trigger.unsubscribe(this.updateLoadedArea), this.canvasResizeObserver.unobserve(this.element), this.canvas.viewport.onAfterUpdated.unsubscribe(
2170
+ this.onAfterViewportUpdated
2171
+ ), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
2172
+ });
2173
+ o(this, "onAfterViewportUpdated", () => {
2174
+ this.userTransformInProgress || (this.viewportMatrix = this.viewport.getViewportMatrix(), this.loadAreaAroundViewport());
2175
+ });
2176
+ o(this, "userTransformInProgress", !1);
2177
+ this.canvas = e, this.element = t, this.window = s, this.trigger = n, this.params = a, this.nodeHorizontal = this.params.nodeContainingRadius.horizontal, this.nodeVertical = this.params.nodeContainingRadius.vertical, this.canvasResizeObserver = new ResizeObserver((d) => {
2178
+ const c = d[0];
2179
+ this.viewportWidth = c.contentRect.width, this.viewportHeight = c.contentRect.height, this.scheduleLoadAreaAroundViewport();
2180
+ }), this.viewport = e.viewport;
2181
+ const h = {
2182
+ ...i,
2183
+ onResizeTransformStarted: () => {
2184
+ this.userTransformInProgress = !0, i.onResizeTransformStarted();
2185
+ },
2186
+ onResizeTransformFinished: () => {
2187
+ this.userTransformInProgress = !1, i.onResizeTransformFinished();
2188
+ },
2189
+ onBeforeTransformChange: () => {
2190
+ this.userTransformInProgress = !0, i.onBeforeTransformChange();
2191
+ },
2192
+ onTransformChange: () => {
2193
+ this.userTransformInProgress = !1;
2194
+ const d = this.viewportMatrix;
2195
+ this.viewportMatrix = this.viewport.getViewportMatrix(), d.scale !== this.viewportMatrix.scale && this.scheduleEnsureViewportAreaLoaded(), i.onTransformChange();
2196
+ },
2197
+ onTransformFinished: () => {
2198
+ this.scheduleLoadAreaAroundViewport(), i.onTransformFinished();
2199
+ }
2200
+ };
2201
+ $.configure(
2202
+ e,
2203
+ this.element,
2204
+ this.window,
2205
+ h
2206
+ ), this.viewportMatrix = this.viewport.getViewportMatrix(), this.trigger.subscribe(this.updateLoadedArea), this.canvasResizeObserver.observe(this.element), this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
2207
+ }
2208
+ static configure(e, t, s, i, n, a) {
2209
+ new Z(
2210
+ e,
2171
2211
  t,
2172
- this.arrowOffset,
2173
- this.cycleSquareSide / 2
2174
- ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow, this.pathShape = new C({
2175
- color: (e == null ? void 0 : e.color) ?? u.color,
2176
- width: (e == null ? void 0 : e.width) ?? u.width,
2177
- arrowLength: this.arrowLength,
2178
- arrowWidth: this.arrowWidth,
2179
- hasSourceArrow: this.hasSourceArrow,
2180
- hasTargetArrow: this.hasTargetArrow,
2181
- createCyclePath: this.createCyclePath,
2182
- createDetourPath: this.createDetourPath,
2183
- createLinePath: this.createLinePath
2184
- }), this.svg = this.pathShape.svg, this.group = this.pathShape.group, this.line = this.pathShape.line, this.sourceArrow = this.pathShape.sourceArrow, this.targetArrow = this.pathShape.targetArrow, this.onAfterRender = this.pathShape.onAfterRender;
2212
+ s,
2213
+ i,
2214
+ n,
2215
+ a
2216
+ );
2185
2217
  }
2186
- render(e) {
2187
- this.pathShape.render(e);
2218
+ scheduleLoadAreaAroundViewport() {
2219
+ setTimeout(() => {
2220
+ this.loadAreaAroundViewport();
2221
+ });
2222
+ }
2223
+ scheduleEnsureViewportAreaLoaded() {
2224
+ const e = this.viewportWidth * this.viewportMatrix.scale, t = this.viewportHeight * this.viewportMatrix.scale, s = this.viewportMatrix.x - this.nodeHorizontal, i = this.viewportMatrix.y - this.nodeVertical, n = this.viewportMatrix.x + e + this.nodeHorizontal, a = this.viewportMatrix.y + t + this.nodeVertical;
2225
+ this.loadedArea.xFrom < s && this.loadedArea.xTo > n && this.loadedArea.yFrom < i && this.loadedArea.yTo > a || this.scheduleLoadAreaAroundViewport();
2226
+ }
2227
+ loadAreaAroundViewport() {
2228
+ const e = this.viewportWidth * this.viewportMatrix.scale, t = this.viewportHeight * this.viewportMatrix.scale, s = this.viewportMatrix.x - e - this.nodeHorizontal, i = this.viewportMatrix.y - t - this.nodeVertical, n = 3 * e + 2 * this.nodeHorizontal, a = 3 * t + 2 * this.nodeVertical;
2229
+ this.trigger.emit({ x: s, y: i, width: n, height: a });
2188
2230
  }
2189
2231
  }
2190
- class Qe {
2191
- constructor(e) {
2192
- o(this, "svg");
2193
- o(this, "group");
2194
- o(this, "line");
2195
- o(this, "sourceArrow");
2196
- o(this, "targetArrow");
2197
- o(this, "onAfterRender");
2198
- o(this, "arrowLength");
2199
- o(this, "arrowWidth");
2200
- o(this, "arrowOffset");
2201
- o(this, "roundness");
2202
- o(this, "cycleSquareSide");
2203
- o(this, "detourDirection");
2204
- o(this, "detourDistance");
2205
- o(this, "hasSourceArrow");
2206
- o(this, "hasTargetArrow");
2207
- o(this, "pathShape");
2208
- o(this, "createCyclePath", (e) => new G({
2209
- sourceDirection: e,
2210
- arrowLength: this.arrowLength,
2211
- side: this.cycleSquareSide,
2212
- arrowOffset: this.arrowOffset,
2213
- roundness: this.roundness,
2214
- hasSourceArrow: this.hasSourceArrow,
2215
- hasTargetArrow: this.hasTargetArrow
2216
- }));
2217
- o(this, "createDetourPath", (e, t, s, i, n) => new j({
2218
- to: s,
2219
- sourceDirection: e,
2220
- targetDirection: t,
2221
- flipX: i,
2222
- flipY: n,
2223
- arrowLength: this.arrowLength,
2224
- arrowOffset: this.arrowOffset,
2225
- roundness: this.roundness,
2226
- detourDirection: this.detourDirection,
2227
- detourDistance: this.detourDistance,
2228
- hasSourceArrow: this.hasSourceArrow,
2229
- hasTargetArrow: this.hasTargetArrow
2230
- }));
2231
- o(this, "createLinePath", (e, t, s) => new He({
2232
- to: s,
2233
- sourceDirection: e,
2234
- targetDirection: t,
2235
- arrowLength: this.arrowLength,
2236
- arrowOffset: this.arrowOffset,
2237
- roundness: this.roundness,
2238
- hasSourceArrow: this.hasSourceArrow,
2239
- hasTargetArrow: this.hasTargetArrow
2232
+ const st = () => {
2233
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2234
+ return r.style.position = "absolute", r.style.inset = "0", r;
2235
+ }, it = () => {
2236
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "rect");
2237
+ return r.setAttribute("fill", "url(#pattern)"), r;
2238
+ }, nt = () => {
2239
+ const r = document.createElementNS(
2240
+ "http://www.w3.org/2000/svg",
2241
+ "pattern"
2242
+ );
2243
+ return r.setAttribute("id", "pattern"), r;
2244
+ };
2245
+ class J {
2246
+ constructor(e, t, s) {
2247
+ o(this, "svg", st());
2248
+ o(this, "patternRenderingRectangle", it());
2249
+ o(this, "pattern", nt());
2250
+ o(this, "patternContent");
2251
+ o(this, "tileWidth");
2252
+ o(this, "tileHeight");
2253
+ o(this, "halfTileWidth");
2254
+ o(this, "halfTileHeight");
2255
+ o(this, "maxViewportScale");
2256
+ o(this, "visible", !1);
2257
+ o(this, "resizeObserver", new ResizeObserver((e) => {
2258
+ const t = e[0], { width: s, height: i } = t.contentRect;
2259
+ this.svg.setAttribute("width", `${s}`), this.svg.setAttribute("height", `${i}`), this.patternRenderingRectangle.setAttribute("width", `${s}`), this.patternRenderingRectangle.setAttribute("height", `${i}`);
2260
+ const n = this.tileWidth / s, a = this.tileHeight / i;
2261
+ this.pattern.setAttribute("width", `${n}`), this.pattern.setAttribute("height", `${a}`);
2240
2262
  }));
2241
- this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
2242
- const t = (e == null ? void 0 : e.roundness) ?? u.roundness;
2243
- this.roundness = Math.min(
2244
- t,
2245
- this.arrowOffset,
2246
- this.cycleSquareSide / 2
2247
- ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow, this.pathShape = new C({
2248
- color: (e == null ? void 0 : e.color) ?? u.color,
2249
- width: (e == null ? void 0 : e.width) ?? u.width,
2250
- arrowLength: this.arrowLength,
2251
- arrowWidth: this.arrowWidth,
2252
- hasSourceArrow: this.hasSourceArrow,
2253
- hasTargetArrow: this.hasTargetArrow,
2254
- createCyclePath: this.createCyclePath,
2255
- createDetourPath: this.createDetourPath,
2256
- createLinePath: this.createLinePath
2257
- }), this.svg = this.pathShape.svg, this.group = this.pathShape.group, this.line = this.pathShape.line, this.sourceArrow = this.pathShape.sourceArrow, this.targetArrow = this.pathShape.targetArrow, this.onAfterRender = this.pathShape.onAfterRender;
2263
+ o(this, "onAfterTransformUpdated", () => {
2264
+ const e = this.canvas.viewport.getContentMatrix(), t = e.x - this.halfTileWidth * e.scale, s = e.y - this.halfTileHeight * e.scale, i = `matrix(${e.scale}, 0, 0, ${e.scale}, ${t}, ${s})`;
2265
+ this.pattern.setAttribute("patternTransform", i), this.updateVisibility();
2266
+ });
2267
+ o(this, "onBeforeDestroy", () => {
2268
+ this.resizeObserver.unobserve(this.host), this.host.removeChild(this.svg), this.canvas.viewport.onAfterUpdated.unsubscribe(
2269
+ this.onAfterTransformUpdated
2270
+ ), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
2271
+ });
2272
+ this.canvas = e, this.host = s, this.tileWidth = t.tileWidth, this.tileHeight = t.tileHeight, this.halfTileWidth = this.tileWidth / 2, this.halfTileHeight = this.tileHeight / 2, this.patternContent = t.renderer, this.maxViewportScale = t.maxViewportScale;
2273
+ const i = `translate(${this.halfTileWidth}, ${this.halfTileHeight})`;
2274
+ this.patternContent.setAttribute("transform", i), this.pattern.appendChild(this.patternContent);
2275
+ const n = document.createElementNS("http://www.w3.org/2000/svg", "defs");
2276
+ n.appendChild(this.pattern), this.svg.appendChild(n), this.svg.appendChild(this.patternRenderingRectangle), this.resizeObserver.observe(this.host), this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated), this.onAfterTransformUpdated(), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
2258
2277
  }
2259
- render(e) {
2260
- this.pathShape.render(e);
2278
+ static configure(e, t, s) {
2279
+ new J(e, t, s);
2280
+ }
2281
+ updateVisibility() {
2282
+ const t = this.canvas.viewport.getViewportMatrix().scale > this.maxViewportScale;
2283
+ t && this.visible ? (this.visible = !1, this.host.removeChild(this.svg)) : !t && !this.visible && (this.visible = !0, this.host.appendChild(this.svg));
2261
2284
  }
2262
2285
  }
2263
- class _e {
2264
- constructor(e) {
2265
- o(this, "svg");
2266
- o(this, "group");
2267
- o(this, "line");
2268
- o(this, "sourceArrow");
2269
- o(this, "targetArrow");
2270
- o(this, "onAfterRender");
2271
- o(this, "arrowLength");
2272
- o(this, "arrowWidth");
2273
- o(this, "arrowOffset");
2274
- o(this, "roundness");
2275
- o(this, "cycleSquareSide");
2276
- o(this, "detourDirection");
2277
- o(this, "detourDistance");
2278
- o(this, "hasSourceArrow");
2279
- o(this, "hasTargetArrow");
2280
- o(this, "pathShape");
2281
- o(this, "createCyclePath", (e) => new G({
2282
- sourceDirection: e,
2283
- arrowLength: this.arrowLength,
2284
- side: this.cycleSquareSide,
2285
- arrowOffset: this.arrowOffset,
2286
- roundness: this.roundness,
2287
- hasSourceArrow: this.hasSourceArrow,
2288
- hasTargetArrow: this.hasTargetArrow
2289
- }));
2290
- o(this, "createDetourPath", (e, t, s, i, n) => new j({
2291
- to: s,
2292
- sourceDirection: e,
2293
- targetDirection: t,
2294
- flipX: i,
2295
- flipY: n,
2296
- arrowLength: this.arrowLength,
2297
- arrowOffset: this.arrowOffset,
2298
- roundness: this.roundness,
2299
- detourDirection: this.detourDirection,
2300
- detourDistance: this.detourDistance,
2301
- hasSourceArrow: this.hasSourceArrow,
2302
- hasTargetArrow: this.hasTargetArrow
2303
- }));
2304
- o(this, "createLinePath", (e, t, s, i, n) => new je({
2305
- to: s,
2306
- sourceDirection: e,
2307
- targetDirection: t,
2308
- flipY: n,
2309
- arrowLength: this.arrowLength,
2310
- arrowOffset: this.arrowOffset,
2311
- roundness: this.roundness,
2312
- hasSourceArrow: this.hasSourceArrow,
2313
- hasTargetArrow: this.hasTargetArrow
2314
- }));
2315
- this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.arrowOffset = (e == null ? void 0 : e.arrowOffset) ?? u.arrowOffset, this.cycleSquareSide = (e == null ? void 0 : e.cycleSquareSide) ?? u.cycleSquareSide;
2316
- const t = (e == null ? void 0 : e.roundness) ?? u.roundness;
2317
- this.roundness = Math.min(
2318
- t,
2319
- this.arrowOffset,
2320
- this.cycleSquareSide / 2
2321
- ), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirectionVertical, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow, this.pathShape = new C({
2322
- color: (e == null ? void 0 : e.color) ?? u.color,
2323
- width: (e == null ? void 0 : e.width) ?? u.width,
2324
- arrowLength: this.arrowLength,
2325
- arrowWidth: this.arrowWidth,
2326
- hasSourceArrow: this.hasSourceArrow,
2327
- hasTargetArrow: this.hasTargetArrow,
2328
- createCyclePath: this.createCyclePath,
2329
- createDetourPath: this.createDetourPath,
2330
- createLinePath: this.createLinePath
2331
- }), this.svg = this.pathShape.svg, this.group = this.pathShape.group, this.line = this.pathShape.line, this.sourceArrow = this.pathShape.sourceArrow, this.targetArrow = this.pathShape.targetArrow, this.onAfterRender = this.pathShape.onAfterRender;
2286
+ class F {
2287
+ constructor(e, t, s, i) {
2288
+ o(this, "onAfterPortMarked", (e) => {
2289
+ const t = this.canvas.graph.getPort(e);
2290
+ this.canvas.graph.getElementPortIds(t.element).length === 1 && this.hookPortEvents(t.element);
2291
+ });
2292
+ o(this, "onBeforePortUnmarked", (e) => {
2293
+ const t = this.canvas.graph.getPort(e);
2294
+ this.canvas.graph.getElementPortIds(t.element).length === 1 && this.unhookPortEvents(t.element);
2295
+ });
2296
+ o(this, "onPortMouseDown", (e) => {
2297
+ if (!this.params.mouseDownEventVerifier(e))
2298
+ return;
2299
+ const t = e.currentTarget, s = this.canvas.graph.getElementPortIds(t)[0];
2300
+ this.params.onPortPointerDown(s, {
2301
+ x: e.clientX,
2302
+ y: e.clientY
2303
+ }) && (e.stopPropagation(), this.window.addEventListener("mousemove", this.onWindowMouseMove, {
2304
+ passive: !0
2305
+ }), this.window.addEventListener("mouseup", this.onWindowMouseUp, {
2306
+ passive: !0
2307
+ }));
2308
+ });
2309
+ o(this, "onWindowMouseMove", (e) => {
2310
+ if (!L(
2311
+ this.window,
2312
+ this.element,
2313
+ e.clientX,
2314
+ e.clientY
2315
+ )) {
2316
+ this.stopMouseDrag();
2317
+ return;
2318
+ }
2319
+ this.params.onPointerMove({ x: e.clientX, y: e.clientY });
2320
+ });
2321
+ o(this, "onWindowMouseUp", (e) => {
2322
+ this.params.mouseUpEventVerifier(e) && (this.params.onPointerUp({ x: e.clientX, y: e.clientY }), this.stopMouseDrag());
2323
+ });
2324
+ o(this, "onPortTouchStart", (e) => {
2325
+ if (e.touches.length !== 1)
2326
+ return;
2327
+ const t = e.touches[0], s = e.currentTarget, i = this.canvas.graph.getElementPortIds(s)[0];
2328
+ this.params.onPortPointerDown(i, {
2329
+ x: t.clientX,
2330
+ y: t.clientY
2331
+ }) && (e.stopPropagation(), this.window.addEventListener("touchmove", this.onWindowTouchMove, {
2332
+ passive: !0
2333
+ }), this.window.addEventListener("touchend", this.onWindowTouchFinish, {
2334
+ passive: !0
2335
+ }), this.window.addEventListener("touchcancel", this.onWindowTouchFinish, {
2336
+ passive: !0
2337
+ }));
2338
+ });
2339
+ o(this, "onWindowTouchMove", (e) => {
2340
+ const t = e.touches[0];
2341
+ if (!L(
2342
+ this.window,
2343
+ this.element,
2344
+ t.clientX,
2345
+ t.clientY
2346
+ )) {
2347
+ this.stopTouchDrag();
2348
+ return;
2349
+ }
2350
+ this.params.onPointerMove({ x: t.clientX, y: t.clientY });
2351
+ });
2352
+ o(this, "onWindowTouchFinish", (e) => {
2353
+ const t = e.changedTouches[0];
2354
+ this.params.onPointerUp({ x: t.clientX, y: t.clientY }), this.stopTouchDrag();
2355
+ });
2356
+ o(this, "onBeforeClear", () => {
2357
+ this.canvas.graph.getAllPortIds().forEach((e) => {
2358
+ const t = this.canvas.graph.getPort(e);
2359
+ this.unhookPortEvents(t.element);
2360
+ });
2361
+ });
2362
+ o(this, "onBeforeDestroy", () => {
2363
+ this.stopMouseDrag(), this.stopTouchDrag(), this.canvas.graph.onAfterPortMarked.unsubscribe(this.onAfterPortMarked), this.canvas.graph.onBeforePortUnmarked.unsubscribe(
2364
+ this.onBeforePortUnmarked
2365
+ ), this.canvas.graph.onBeforeClear.unsubscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
2366
+ });
2367
+ this.canvas = e, this.element = t, this.window = s, this.params = i, this.canvas.graph.onAfterPortMarked.subscribe(this.onAfterPortMarked), this.canvas.graph.onBeforePortUnmarked.subscribe(this.onBeforePortUnmarked), this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
2332
2368
  }
2333
- render(e) {
2334
- this.pathShape.render(e);
2369
+ static configure(e, t, s, i) {
2370
+ new F(e, t, s, i);
2371
+ }
2372
+ hookPortEvents(e) {
2373
+ e.addEventListener("mousedown", this.onPortMouseDown, {
2374
+ passive: !0
2375
+ }), e.addEventListener("touchstart", this.onPortTouchStart, {
2376
+ passive: !0
2377
+ });
2378
+ }
2379
+ unhookPortEvents(e) {
2380
+ e.removeEventListener("mousedown", this.onPortMouseDown), e.removeEventListener("touchstart", this.onPortTouchStart);
2381
+ }
2382
+ stopMouseDrag() {
2383
+ this.params.onStopDrag(), this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
2384
+ }
2385
+ stopTouchDrag() {
2386
+ this.params.onStopDrag(), this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
2335
2387
  }
2336
2388
  }
2337
- const oe = (r) => {
2338
- if (r.diagonalDistance === 0)
2339
- return "";
2340
- const e = r.offset / r.diagonalDistance, t = r.flip * r.to.x, s = r.flip * r.to.y, i = {
2341
- x: t * e + r.shift.x,
2342
- y: s * e + r.shift.y
2343
- }, n = {
2344
- x: t / r.diagonalDistance,
2345
- y: s / r.diagonalDistance
2346
- };
2347
- return F(
2348
- n,
2349
- i,
2350
- r.arrowLength,
2351
- r.arrowWidth
2352
- );
2353
- };
2354
- class qe {
2355
- constructor(e) {
2356
- o(this, "svg");
2357
- o(this, "group", pe());
2358
- o(this, "line");
2359
- o(this, "sourceArrow", null);
2360
- o(this, "targetArrow", null);
2361
- o(this, "color");
2362
- o(this, "width");
2363
- o(this, "arrowLength");
2364
- o(this, "arrowWidth");
2365
- o(this, "sourceOffset");
2366
- o(this, "targetOffset");
2367
- o(this, "onAfterRender");
2368
- o(this, "afterRenderEmitter");
2369
- [this.afterRenderEmitter, this.onAfterRender] = y(), this.color = (e == null ? void 0 : e.color) ?? u.color, this.width = (e == null ? void 0 : e.width) ?? u.width, this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.sourceOffset = (e == null ? void 0 : e.sourceOffset) ?? u.preOffset, this.targetOffset = (e == null ? void 0 : e.targetOffset) ?? u.preOffset, this.svg = we(this.color), this.svg.appendChild(this.group), this.line = fe(this.width), this.group.appendChild(this.line), e != null && e.hasSourceArrow && (this.sourceArrow = V(), this.group.appendChild(this.sourceArrow)), e != null && e.hasTargetArrow && (this.targetArrow = V(), this.group.appendChild(this.targetArrow));
2389
+ class Q {
2390
+ constructor(e, t, s, i, n) {
2391
+ o(this, "overlayCanvas");
2392
+ o(this, "staticPortId", null);
2393
+ o(this, "isTargetDragging", !0);
2394
+ o(this, "onEdgeCreated", (e) => {
2395
+ this.params.onAfterEdgeCreated(e);
2396
+ });
2397
+ this.canvas = e, this.overlayLayer = t, this.viewportStore = s, this.window = i, this.params = n, this.overlayCanvas = De(
2398
+ this.overlayLayer,
2399
+ this.viewportStore
2400
+ ), F.configure(
2401
+ this.canvas,
2402
+ this.overlayLayer,
2403
+ this.window,
2404
+ {
2405
+ mouseDownEventVerifier: this.params.mouseDownEventVerifier,
2406
+ mouseUpEventVerifier: this.params.mouseUpEventVerifier,
2407
+ onStopDrag: () => {
2408
+ this.resetDragState();
2409
+ },
2410
+ onPortPointerDown: (a, h) => {
2411
+ const d = this.params.connectionTypeResolver(a);
2412
+ return d === null ? !1 : (this.grabPort(a, h, d), !0);
2413
+ },
2414
+ onPointerMove: (a) => {
2415
+ this.moveDraggingPort(a);
2416
+ },
2417
+ onPointerUp: (a) => {
2418
+ this.tryCreateConnection(a);
2419
+ }
2420
+ }
2421
+ );
2370
2422
  }
2371
- render(e) {
2372
- const { x: t, y: s, width: i, height: n, flipX: h, flipY: a } = ve(
2373
- e.from,
2374
- e.to
2423
+ static configure(e, t, s, i, n) {
2424
+ new Q(
2425
+ e,
2426
+ t,
2427
+ s,
2428
+ i,
2429
+ n
2375
2430
  );
2376
- ue(this.svg, { x: t, y: s, width: i, height: n }), this.group.style.transform = `scale(${h}, ${a})`;
2377
- const d = { x: i, y: n }, c = new Ze({
2378
- to: d,
2379
- sourceOffset: this.sourceOffset,
2380
- targetOffset: this.targetOffset,
2381
- hasSourceArrow: this.sourceArrow !== null,
2382
- hasTargetArrow: this.targetArrow !== null,
2383
- arrowLength: this.arrowLength
2431
+ }
2432
+ grabPort(e, t, s) {
2433
+ const i = this.canvas.graph.getPort(e);
2434
+ this.staticPortId = e;
2435
+ const n = i.element.getBoundingClientRect(), a = n.x + n.width / 2, h = n.y + n.height / 2, d = this.overlayLayer.getBoundingClientRect(), c = this.canvas.viewport.getViewportMatrix(), l = T(c, {
2436
+ x: a - d.x,
2437
+ y: h - d.y
2438
+ }), g = T(c, {
2439
+ x: t.x - d.x,
2440
+ y: t.y - d.y
2441
+ }), p = {
2442
+ overlayId: b.Static,
2443
+ portCoords: l,
2444
+ portDirection: i.direction
2445
+ }, f = {
2446
+ overlayId: b.Dragging,
2447
+ portCoords: g,
2448
+ portDirection: this.params.dragPortDirection
2449
+ };
2450
+ this.isTargetDragging = s === "direct";
2451
+ const [v, y] = this.isTargetDragging ? [p, f] : [f, p];
2452
+ this.overlayCanvas.addNode(V(v)), this.overlayCanvas.addNode(V(y)), this.overlayCanvas.addEdge({
2453
+ from: v.overlayId,
2454
+ to: y.overlayId,
2455
+ shape: this.params.edgeShapeFactory(b.Edge)
2384
2456
  });
2385
- this.line.setAttribute("d", c.path);
2386
- let g = null;
2387
- this.sourceArrow && (g = oe({
2388
- diagonalDistance: c.diagonalDistance,
2389
- to: d,
2390
- offset: this.sourceOffset,
2391
- flip: 1,
2392
- shift: w,
2393
- arrowWidth: this.arrowWidth,
2394
- arrowLength: this.arrowLength
2395
- }), this.sourceArrow.setAttribute("d", g));
2396
- let l = null;
2397
- this.targetArrow && (l = oe({
2398
- diagonalDistance: c.diagonalDistance,
2399
- to: d,
2400
- offset: this.targetOffset,
2401
- flip: -1,
2402
- shift: d,
2403
- arrowWidth: this.arrowWidth,
2404
- arrowLength: this.arrowLength
2405
- }), this.targetArrow.setAttribute("d", l)), this.afterRenderEmitter.emit({
2406
- edgePath: c,
2407
- sourceArrowPath: g,
2408
- targetArrowPath: l
2457
+ }
2458
+ resetDragState() {
2459
+ this.staticPortId = null, this.isTargetDragging = !0, this.overlayCanvas.clear();
2460
+ }
2461
+ tryCreateConnection(e) {
2462
+ const t = ve(this.canvas.graph, e);
2463
+ if (t === null) {
2464
+ this.params.onEdgeCreationInterrupted(
2465
+ this.staticPortId,
2466
+ this.isTargetDragging
2467
+ );
2468
+ return;
2469
+ }
2470
+ const s = this.isTargetDragging ? this.staticPortId : t, i = this.isTargetDragging ? t : this.staticPortId, n = { from: s, to: i }, a = this.params.connectionPreprocessor(n);
2471
+ a !== null ? (this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated), this.canvas.addEdge(a), this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)) : this.params.onEdgeCreationPrevented(n);
2472
+ }
2473
+ moveDraggingPort(e) {
2474
+ const t = this.overlayLayer.getBoundingClientRect(), s = {
2475
+ x: e.x - t.x,
2476
+ y: e.y - t.y
2477
+ }, i = this.canvas.viewport.getViewportMatrix(), n = T(i, s);
2478
+ this.overlayCanvas.updateNode(b.Dragging, {
2479
+ x: n.x,
2480
+ y: n.y
2409
2481
  });
2410
2482
  }
2411
2483
  }
2412
- const et = () => {
2413
- const r = document.createElementNS("http://www.w3.org/2000/svg", "g");
2414
- return r.style.pointerEvents = "auto", r.style.cursor = "pointer", r;
2415
- }, tt = (r) => {
2416
- const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
2417
- return e.setAttribute("stroke", "transparent"), e.setAttribute("stroke-width", `${r}`), e.setAttribute("fill", "none"), e.setAttribute("stroke-linecap", "round"), e;
2418
- }, se = (r) => {
2419
- const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
2420
- return e.setAttribute("stroke-linejoin", "round"), e.setAttribute("stroke-width", `${r}`), e.setAttribute("fill", "transparent"), e.setAttribute("stroke", "transparent"), e;
2421
- };
2422
- class rt extends Error {
2423
- constructor(e) {
2424
- super(e), this.name = "InteractiveEdgeError";
2484
+ class _ {
2485
+ constructor(e, t, s, i, n) {
2486
+ o(this, "overlayCanvas");
2487
+ o(this, "staticPortId", null);
2488
+ o(this, "isTargetDragging", !0);
2489
+ o(this, "draggingEdgePayload", null);
2490
+ o(this, "onEdgeReattached", (e) => {
2491
+ this.params.onAfterEdgeReattached(e);
2492
+ });
2493
+ this.canvas = e, this.overlayLayer = t, this.viewportStore = s, this.window = i, this.params = n, this.overlayCanvas = De(
2494
+ this.overlayLayer,
2495
+ this.viewportStore
2496
+ ), F.configure(
2497
+ this.canvas,
2498
+ this.overlayLayer,
2499
+ this.window,
2500
+ {
2501
+ mouseDownEventVerifier: this.params.mouseDownEventVerifier,
2502
+ mouseUpEventVerifier: this.params.mouseUpEventVerifier,
2503
+ onStopDrag: () => {
2504
+ this.resetDragState();
2505
+ },
2506
+ onPortPointerDown: (a, h) => this.tryStartEdgeDragging(a, h),
2507
+ onPointerMove: (a) => {
2508
+ this.moveDraggingPort(a);
2509
+ },
2510
+ onPointerUp: (a) => {
2511
+ this.tryCreateConnection(a);
2512
+ }
2513
+ }
2514
+ );
2425
2515
  }
2426
- }
2427
- class me {
2428
- constructor(e, t) {
2429
- o(this, "svg");
2430
- o(this, "group");
2431
- o(this, "line");
2432
- o(this, "sourceArrow");
2433
- o(this, "targetArrow");
2434
- o(this, "handle", et());
2435
- o(this, "onAfterRender");
2436
- o(this, "interactiveLine");
2437
- o(this, "interactiveSourceArrow", null);
2438
- o(this, "interactiveTargetArrow", null);
2439
- if (this.baseEdge = e, e instanceof me)
2440
- throw new rt(
2441
- "interactive edge can be configured only once"
2442
- );
2443
- this.svg = this.baseEdge.svg, this.group = this.baseEdge.group, this.line = this.baseEdge.line, this.sourceArrow = this.baseEdge.sourceArrow, this.targetArrow = this.baseEdge.targetArrow, this.onAfterRender = this.baseEdge.onAfterRender;
2444
- const s = (t == null ? void 0 : t.width) ?? u.interactiveWidth;
2445
- this.interactiveLine = tt(s), this.handle.appendChild(this.interactiveLine), this.sourceArrow && (this.interactiveSourceArrow = se(s), this.handle.appendChild(this.interactiveSourceArrow)), this.targetArrow && (this.interactiveTargetArrow = se(s), this.handle.appendChild(this.interactiveTargetArrow)), this.group.appendChild(this.handle), this.baseEdge.onAfterRender.subscribe((i) => {
2446
- this.interactiveLine.setAttribute("d", i.edgePath.path), this.interactiveSourceArrow && this.interactiveSourceArrow.setAttribute("d", i.sourceArrowPath), this.interactiveTargetArrow && this.interactiveTargetArrow.setAttribute("d", i.targetArrowPath);
2516
+ static configure(e, t, s, i, n) {
2517
+ new _(
2518
+ e,
2519
+ t,
2520
+ s,
2521
+ i,
2522
+ n
2523
+ );
2524
+ }
2525
+ tryStartEdgeDragging(e, t) {
2526
+ const s = this.params.draggingEdgeResolver(e);
2527
+ if (s === null)
2528
+ return !1;
2529
+ const i = this.canvas.graph.getEdge(s);
2530
+ if (i === null)
2531
+ return !1;
2532
+ const n = e === i.from, a = e === i.to, h = n ? i.to : i.from;
2533
+ this.staticPortId = h, this.isTargetDragging = a;
2534
+ const d = this.canvas.graph.getPort(e), c = this.canvas.graph.getPort(h), l = c.element.getBoundingClientRect(), g = {
2535
+ x: l.x + l.width / 2,
2536
+ y: l.y + l.height / 2
2537
+ }, p = this.canvas.viewport.getViewportMatrix(), f = this.overlayLayer.getBoundingClientRect(), v = T(p, {
2538
+ x: g.x - f.x,
2539
+ y: g.y - f.y
2540
+ }), y = T(p, {
2541
+ x: t.x - f.x,
2542
+ y: t.y - f.y
2543
+ });
2544
+ this.draggingEdgePayload = {
2545
+ id: s,
2546
+ from: i.from,
2547
+ to: i.to,
2548
+ shape: i.shape,
2549
+ priority: i.priority
2550
+ }, this.canvas.removeEdge(s);
2551
+ const E = {
2552
+ overlayId: b.Static,
2553
+ portCoords: v,
2554
+ portDirection: c.direction
2555
+ }, x = {
2556
+ overlayId: b.Dragging,
2557
+ portCoords: y,
2558
+ portDirection: d.direction
2559
+ }, [P, D] = this.isTargetDragging ? [E, x] : [x, E];
2560
+ this.overlayCanvas.addNode(V(P)), this.overlayCanvas.addNode(V(D));
2561
+ const N = this.params.draggingEdgeShapeFactory !== null ? this.params.draggingEdgeShapeFactory(b.Edge) : i.shape;
2562
+ return this.overlayCanvas.addEdge({
2563
+ id: b.Edge,
2564
+ from: P.overlayId,
2565
+ to: D.overlayId,
2566
+ shape: N
2567
+ }), !0;
2568
+ }
2569
+ resetDragState() {
2570
+ this.draggingEdgePayload = null, this.staticPortId = null, this.isTargetDragging = !0, this.overlayCanvas.clear();
2571
+ }
2572
+ moveDraggingPort(e) {
2573
+ const t = this.overlayLayer.getBoundingClientRect(), s = {
2574
+ x: e.x - t.x,
2575
+ y: e.y - t.y
2576
+ }, i = this.canvas.viewport.getViewportMatrix(), n = T(i, s);
2577
+ this.overlayCanvas.updateNode(b.Dragging, {
2578
+ x: n.x,
2579
+ y: n.y
2447
2580
  });
2448
2581
  }
2449
- render(e) {
2450
- this.baseEdge.render(e);
2582
+ tryCreateConnection(e) {
2583
+ const t = ve(this.canvas.graph, e);
2584
+ if (this.overlayCanvas.removeEdge(b.Edge), t === null) {
2585
+ const h = this.draggingEdgePayload;
2586
+ this.params.onEdgeReattachInterrupted({
2587
+ id: h.id,
2588
+ from: h.from,
2589
+ to: h.to,
2590
+ shape: h.shape,
2591
+ priority: h.priority
2592
+ });
2593
+ return;
2594
+ }
2595
+ const [s, i] = this.isTargetDragging ? [this.staticPortId, t] : [t, this.staticPortId], n = {
2596
+ from: s,
2597
+ to: i,
2598
+ shape: this.draggingEdgePayload.shape,
2599
+ priority: this.draggingEdgePayload.priority
2600
+ }, a = this.params.connectionPreprocessor(n);
2601
+ if (a !== null)
2602
+ this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached), this.canvas.addEdge(a), this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeReattached);
2603
+ else {
2604
+ const h = this.draggingEdgePayload;
2605
+ this.params.onEdgeReattachPrevented({
2606
+ id: h.id,
2607
+ from: h.from,
2608
+ to: h.to,
2609
+ shape: h.shape,
2610
+ priority: h.priority
2611
+ });
2612
+ }
2451
2613
  }
2452
2614
  }
2453
- class ut {
2454
- constructor(e, t) {
2455
- o(this, "group");
2456
- o(this, "line");
2457
- o(this, "sourceArrow");
2458
- o(this, "targetArrow");
2459
- o(this, "onAfterRender");
2460
- o(this, "svg");
2461
- /**
2462
- * @deprecated
2463
- * use midpointElement instead
2464
- */
2465
- o(this, "medianElement");
2466
- this.baseShape = e, this.midpointElement = t, this.medianElement = this.midpointElement, this.svg = this.baseShape.svg, this.group = this.baseShape.group, this.line = this.baseShape.line, this.sourceArrow = this.baseShape.sourceArrow, this.targetArrow = this.baseShape.targetArrow, this.onAfterRender = this.baseShape.onAfterRender, this.svg.append(this.midpointElement), this.baseShape.onAfterRender.subscribe((s) => {
2467
- const i = s.edgePath.midpoint, n = `translate(${i.x}px, ${i.y}px)`;
2468
- this.midpointElement.style.setProperty("transform", n);
2469
- });
2615
+ const ht = () => {
2616
+ const r = document.createElement("div");
2617
+ return r.style.width = "100%", r.style.height = "100%", r.style.position = "relative", r;
2618
+ }, z = () => {
2619
+ const r = document.createElement("div");
2620
+ return r.style.position = "absolute", r.style.inset = "0", r;
2621
+ }, de = () => {
2622
+ const r = z();
2623
+ return r.style.pointerEvents = "none", r;
2624
+ };
2625
+ class at {
2626
+ constructor(e) {
2627
+ o(this, "background", z());
2628
+ o(this, "main", z());
2629
+ o(this, "overlayConnectablePorts", de());
2630
+ o(this, "overlayDraggableEdges", de());
2631
+ o(this, "host", ht());
2632
+ this.element = e, this.element.appendChild(this.host), this.host.appendChild(this.background), this.host.appendChild(this.main), this.host.appendChild(this.overlayConnectablePorts), this.host.appendChild(this.overlayDraggableEdges);
2470
2633
  }
2471
- render(e) {
2472
- this.baseShape.render(e);
2634
+ destroy() {
2635
+ this.host.removeChild(this.background), this.host.removeChild(this.main), this.host.removeChild(this.overlayConnectablePorts), this.host.removeChild(this.overlayDraggableEdges), this.element.removeChild(this.host);
2473
2636
  }
2474
2637
  }
2475
- const ye = (r) => {
2638
+ const X = (r) => () => r, ce = X(0), dt = () => {
2639
+ let r = 0;
2640
+ return () => r++;
2641
+ }, ct = (r, e) => {
2642
+ let t = ce, s = ce;
2643
+ const i = dt();
2644
+ return r === "incremental" && (t = i), e === "incremental" && (s = i), typeof r == "number" && (t = X(r)), typeof e == "number" && (s = X(e)), typeof r == "function" && (t = r), typeof e == "function" && (s = e), {
2645
+ nodesPriorityFn: t,
2646
+ edgesPriorityFn: s
2647
+ };
2648
+ }, q = (r) => {
2476
2649
  if (typeof r == "function")
2477
2650
  return r;
2478
2651
  switch (r == null ? void 0 : r.type) {
@@ -2491,7 +2664,7 @@ const ye = (r) => {
2491
2664
  detourDirection: r.detourDirection
2492
2665
  });
2493
2666
  case "horizontal":
2494
- return () => new Ke({
2667
+ return () => new Je({
2495
2668
  color: r.color,
2496
2669
  width: r.width,
2497
2670
  arrowLength: r.arrowLength,
@@ -2519,7 +2692,7 @@ const ye = (r) => {
2519
2692
  detourDirection: r.detourDirection
2520
2693
  });
2521
2694
  case "direct":
2522
- return () => new qe({
2695
+ return () => new Pe({
2523
2696
  color: r.color,
2524
2697
  width: r.width,
2525
2698
  arrowLength: r.arrowLength,
@@ -2530,7 +2703,7 @@ const ye = (r) => {
2530
2703
  targetOffset: r.targetOffset
2531
2704
  });
2532
2705
  default:
2533
- return () => new Je({
2706
+ return () => new Ze({
2534
2707
  color: r.color,
2535
2708
  width: r.width,
2536
2709
  arrowLength: r.arrowLength,
@@ -2544,72 +2717,72 @@ const ye = (r) => {
2544
2717
  detourDirection: r.detourDirection
2545
2718
  });
2546
2719
  }
2547
- }, ot = (r) => {
2548
- var t, s, i, n, h;
2549
- const e = ke(
2720
+ }, gt = (r) => {
2721
+ var t, s, i, n, a;
2722
+ const e = ct(
2550
2723
  (t = r.nodes) == null ? void 0 : t.priority,
2551
2724
  (s = r.edges) == null ? void 0 : s.priority
2552
2725
  );
2553
2726
  return {
2554
2727
  nodes: {
2555
- centerFn: ((i = r.nodes) == null ? void 0 : i.centerFn) ?? le,
2728
+ centerFn: ((i = r.nodes) == null ? void 0 : i.centerFn) ?? me,
2556
2729
  priorityFn: e.nodesPriorityFn
2557
2730
  },
2558
2731
  ports: {
2559
2732
  direction: ((n = r.ports) == null ? void 0 : n.direction) ?? 0
2560
2733
  },
2561
2734
  edges: {
2562
- shapeFactory: ye(((h = r.edges) == null ? void 0 : h.shape) ?? {}),
2735
+ shapeFactory: q(((a = r.edges) == null ? void 0 : a.shape) ?? {}),
2563
2736
  priorityFn: e.edgesPriorityFn
2564
2737
  }
2565
2738
  };
2566
- }, st = (r) => {
2567
- var p, f, v, E, A, S;
2739
+ }, lt = (r) => {
2740
+ var p, f, v, y, E, x;
2568
2741
  const e = ((p = r == null ? void 0 : r.events) == null ? void 0 : p.onNodeDrag) ?? (() => {
2569
2742
  }), t = ((f = r == null ? void 0 : r.events) == null ? void 0 : f.onBeforeNodeDrag) ?? (() => !0), s = ((v = r == null ? void 0 : r.events) == null ? void 0 : v.onNodeDragFinished) ?? (() => {
2570
- }), i = (r == null ? void 0 : r.moveOnTop) !== !1, n = (r == null ? void 0 : r.moveEdgesOnTop) !== !1 && i, h = (E = r == null ? void 0 : r.mouse) == null ? void 0 : E.dragCursor, a = h !== void 0 ? h : "grab", d = (A = r == null ? void 0 : r.mouse) == null ? void 0 : A.mouseDownEventVerifier, c = d !== void 0 ? d : (b) => b.button === 0, g = (S = r == null ? void 0 : r.mouse) == null ? void 0 : S.mouseUpEventVerifier;
2743
+ }), i = (r == null ? void 0 : r.moveOnTop) !== !1, n = (r == null ? void 0 : r.moveEdgesOnTop) !== !1 && i, a = (y = r == null ? void 0 : r.mouse) == null ? void 0 : y.dragCursor, h = a !== void 0 ? a : "grab", d = (E = r == null ? void 0 : r.mouse) == null ? void 0 : E.mouseDownEventVerifier, c = d !== void 0 ? d : (P) => P.button === 0, l = (x = r == null ? void 0 : r.mouse) == null ? void 0 : x.mouseUpEventVerifier;
2571
2744
  return {
2572
2745
  moveOnTop: i,
2573
2746
  moveEdgesOnTop: n,
2574
- dragCursor: a,
2747
+ dragCursor: h,
2575
2748
  mouseDownEventVerifier: c,
2576
- mouseUpEventVerifier: g !== void 0 ? g : (b) => b.button === 0,
2749
+ mouseUpEventVerifier: l !== void 0 ? l : (P) => P.button === 0,
2577
2750
  onNodeDrag: e,
2578
2751
  onBeforeNodeDrag: t,
2579
2752
  onNodeDragFinished: s
2580
2753
  };
2581
- }, it = (r) => {
2754
+ }, ut = (r) => {
2582
2755
  const e = r.minX !== null ? r.minX : -1 / 0, t = r.maxX !== null ? r.maxX : 1 / 0, s = r.minY !== null ? r.minY : -1 / 0, i = r.maxY !== null ? r.maxY : 1 / 0;
2583
2756
  return (n) => {
2584
- let h = n.nextTransform.x, a = n.nextTransform.y;
2585
- h < e && h < n.prevTransform.x && (h = Math.min(n.prevTransform.x, e));
2757
+ let a = n.nextTransform.x, h = n.nextTransform.y;
2758
+ a < e && a < n.prevTransform.x && (a = Math.min(n.prevTransform.x, e));
2586
2759
  const d = n.canvasWidth * n.prevTransform.scale, c = t - d;
2587
- h > c && h > n.prevTransform.x && (h = Math.max(n.prevTransform.x, c)), a < s && a < n.prevTransform.y && (a = Math.min(n.prevTransform.y, s));
2588
- const g = n.canvasHeight * n.prevTransform.scale, l = i - g;
2589
- return a > l && a > n.prevTransform.y && (a = Math.max(n.prevTransform.y, l)), { scale: n.nextTransform.scale, x: h, y: a };
2760
+ a > c && a > n.prevTransform.x && (a = Math.max(n.prevTransform.x, c)), h < s && h < n.prevTransform.y && (h = Math.min(n.prevTransform.y, s));
2761
+ const l = n.canvasHeight * n.prevTransform.scale, g = i - l;
2762
+ return h > g && h > n.prevTransform.y && (h = Math.max(n.prevTransform.y, g)), { scale: n.nextTransform.scale, x: a, y: h };
2590
2763
  };
2591
- }, nt = (r) => {
2764
+ }, pt = (r) => {
2592
2765
  const e = r.maxContentScale, t = r.minContentScale, s = e !== null ? 1 / e : 0, i = t !== null ? 1 / t : 1 / 0;
2593
2766
  return (n) => {
2594
- const h = n.prevTransform, a = n.nextTransform;
2595
- let d = a.scale, c = a.x, g = a.y;
2596
- if (a.scale > i && a.scale > h.scale) {
2597
- d = Math.max(h.scale, i), c = h.x, g = h.y;
2598
- const l = (d - h.scale) / (a.scale - h.scale);
2599
- c = h.x + (a.x - h.x) * l, g = h.y + (a.y - h.y) * l;
2767
+ const a = n.prevTransform, h = n.nextTransform;
2768
+ let d = h.scale, c = h.x, l = h.y;
2769
+ if (h.scale > i && h.scale > a.scale) {
2770
+ d = Math.max(a.scale, i), c = a.x, l = a.y;
2771
+ const g = (d - a.scale) / (h.scale - a.scale);
2772
+ c = a.x + (h.x - a.x) * g, l = a.y + (h.y - a.y) * g;
2600
2773
  }
2601
- if (a.scale < s && a.scale < h.scale) {
2602
- d = Math.min(h.scale, s), c = h.x, g = h.y;
2603
- const l = (d - h.scale) / (a.scale - h.scale);
2604
- c = h.x + (a.x - h.x) * l, g = h.y + (a.y - h.y) * l;
2774
+ if (h.scale < s && h.scale < a.scale) {
2775
+ d = Math.min(a.scale, s), c = a.x, l = a.y;
2776
+ const g = (d - a.scale) / (h.scale - a.scale);
2777
+ c = a.x + (h.x - a.x) * g, l = a.y + (h.y - a.y) * g;
2605
2778
  }
2606
2779
  return {
2607
2780
  scale: d,
2608
2781
  x: c,
2609
- y: g
2782
+ y: l
2610
2783
  };
2611
2784
  };
2612
- }, ht = (r) => (e) => r.reduce(
2785
+ }, wt = (r) => (e) => r.reduce(
2613
2786
  (t, s) => s({
2614
2787
  prevTransform: e.prevTransform,
2615
2788
  nextTransform: t,
@@ -2617,75 +2790,75 @@ const ye = (r) => {
2617
2790
  canvasHeight: e.canvasHeight
2618
2791
  }),
2619
2792
  e.nextTransform
2620
- ), ie = (r) => {
2793
+ ), ge = (r) => {
2621
2794
  if (typeof r == "function")
2622
2795
  return r;
2623
2796
  switch (r.type) {
2624
2797
  case "scale-limit":
2625
- return nt({
2798
+ return pt({
2626
2799
  minContentScale: r.minContentScale ?? 0,
2627
2800
  maxContentScale: r.maxContentScale ?? 1 / 0
2628
2801
  });
2629
2802
  case "shift-limit":
2630
- return it({
2803
+ return ut({
2631
2804
  minX: r.minX ?? -1 / 0,
2632
2805
  maxX: r.maxX ?? 1 / 0,
2633
2806
  minY: r.minY ?? -1 / 0,
2634
2807
  maxY: r.maxY ?? 1 / 0
2635
2808
  });
2636
2809
  }
2637
- }, ne = (r) => {
2638
- var v, E, A, S, b, N, M, L, J, K, Q, _;
2810
+ }, le = (r) => {
2811
+ var v, y, E, x, P, D, N, R, ee, te, re, oe;
2639
2812
  const e = (v = r == null ? void 0 : r.scale) == null ? void 0 : v.mouseWheelSensitivity, t = e !== void 0 ? e : 1.2, s = r == null ? void 0 : r.transformPreprocessor;
2640
2813
  let i;
2641
- s !== void 0 ? Array.isArray(s) ? i = ht(
2814
+ s !== void 0 ? Array.isArray(s) ? i = wt(
2642
2815
  s.map(
2643
- (P) => ie(P)
2816
+ (M) => ge(M)
2644
2817
  )
2645
- ) : i = ie(s) : i = (P) => P.nextTransform;
2646
- const n = ((E = r == null ? void 0 : r.shift) == null ? void 0 : E.cursor) !== void 0 ? r.shift.cursor : "grab", h = ((A = r == null ? void 0 : r.events) == null ? void 0 : A.onBeforeTransformChange) ?? (() => {
2647
- }), a = ((S = r == null ? void 0 : r.events) == null ? void 0 : S.onTransformChange) ?? (() => {
2648
- }), d = (b = r == null ? void 0 : r.shift) == null ? void 0 : b.mouseDownEventVerifier, c = d !== void 0 ? d : (P) => P.button === 0, g = (N = r == null ? void 0 : r.shift) == null ? void 0 : N.mouseUpEventVerifier, l = g !== void 0 ? g : (P) => P.button === 0, p = (M = r == null ? void 0 : r.scale) == null ? void 0 : M.mouseWheelEventVerifier, f = p !== void 0 ? p : () => !0;
2818
+ ) : i = ge(s) : i = (M) => M.nextTransform;
2819
+ const n = ((y = r == null ? void 0 : r.shift) == null ? void 0 : y.cursor) !== void 0 ? r.shift.cursor : "grab", a = ((E = r == null ? void 0 : r.events) == null ? void 0 : E.onBeforeTransformChange) ?? (() => {
2820
+ }), h = ((x = r == null ? void 0 : r.events) == null ? void 0 : x.onTransformChange) ?? (() => {
2821
+ }), d = (P = r == null ? void 0 : r.shift) == null ? void 0 : P.mouseDownEventVerifier, c = d !== void 0 ? d : (M) => M.button === 0, l = (D = r == null ? void 0 : r.shift) == null ? void 0 : D.mouseUpEventVerifier, g = l !== void 0 ? l : (M) => M.button === 0, p = (N = r == null ? void 0 : r.scale) == null ? void 0 : N.mouseWheelEventVerifier, f = p !== void 0 ? p : () => !0;
2649
2822
  return {
2650
2823
  wheelSensitivity: t,
2651
- onTransformStarted: ((L = r == null ? void 0 : r.events) == null ? void 0 : L.onTransformStarted) ?? (() => {
2824
+ onTransformStarted: ((R = r == null ? void 0 : r.events) == null ? void 0 : R.onTransformStarted) ?? (() => {
2652
2825
  }),
2653
- onTransformFinished: ((J = r == null ? void 0 : r.events) == null ? void 0 : J.onTransformFinished) ?? (() => {
2826
+ onTransformFinished: ((ee = r == null ? void 0 : r.events) == null ? void 0 : ee.onTransformFinished) ?? (() => {
2654
2827
  }),
2655
- onBeforeTransformChange: h,
2656
- onTransformChange: a,
2828
+ onBeforeTransformChange: a,
2829
+ onTransformChange: h,
2657
2830
  transformPreprocessor: i,
2658
2831
  shiftCursor: n,
2659
2832
  mouseDownEventVerifier: c,
2660
- mouseUpEventVerifier: l,
2833
+ mouseUpEventVerifier: g,
2661
2834
  mouseWheelEventVerifier: f,
2662
- scaleWheelFinishTimeout: ((K = r == null ? void 0 : r.scale) == null ? void 0 : K.wheelFinishTimeout) ?? 500,
2663
- onResizeTransformStarted: ((Q = r == null ? void 0 : r.events) == null ? void 0 : Q.onResizeTransformStarted) ?? (() => {
2835
+ scaleWheelFinishTimeout: ((te = r == null ? void 0 : r.scale) == null ? void 0 : te.wheelFinishTimeout) ?? 500,
2836
+ onResizeTransformStarted: ((re = r == null ? void 0 : r.events) == null ? void 0 : re.onResizeTransformStarted) ?? (() => {
2664
2837
  }),
2665
- onResizeTransformFinished: ((_ = r == null ? void 0 : r.events) == null ? void 0 : _.onResizeTransformFinished) ?? (() => {
2838
+ onResizeTransformFinished: ((oe = r == null ? void 0 : r.events) == null ? void 0 : oe.onResizeTransformFinished) ?? (() => {
2666
2839
  })
2667
2840
  };
2668
- }, at = (r, e) => {
2841
+ }, ft = (r, e) => {
2669
2842
  const t = document.createElementNS(
2670
2843
  "http://www.w3.org/2000/svg",
2671
2844
  "circle"
2672
2845
  );
2673
2846
  return t.setAttribute("cx", "0"), t.setAttribute("cy", "0"), t.setAttribute("r", `${r}`), t.setAttribute("fill", `${e}`), t;
2674
- }, dt = (r) => r instanceof SVGElement ? r : at(
2847
+ }, vt = (r) => r instanceof SVGElement ? r : ft(
2675
2848
  (r == null ? void 0 : r.radius) ?? 1.5,
2676
2849
  (r == null ? void 0 : r.color) ?? "#d8d8d8"
2677
- ), ct = (r) => {
2678
- const e = r.tileDimensions, t = (e == null ? void 0 : e.width) ?? 25, s = (e == null ? void 0 : e.height) ?? 25, i = dt(r.renderer ?? {});
2850
+ ), mt = (r) => {
2851
+ const e = r.tileDimensions, t = (e == null ? void 0 : e.width) ?? 25, s = (e == null ? void 0 : e.height) ?? 25, i = vt(r.renderer ?? {});
2679
2852
  return {
2680
2853
  tileWidth: t,
2681
2854
  tileHeight: s,
2682
2855
  renderer: i,
2683
2856
  maxViewportScale: r.maxViewportScale ?? 10
2684
2857
  };
2685
- }, lt = (r, e, t) => {
2686
- var c, g, l;
2687
- const s = () => "direct", i = (p) => p, n = (p) => p.button === 0, h = () => {
2688
- }, a = () => {
2858
+ }, yt = (r, e, t) => {
2859
+ var c, l, g;
2860
+ const s = () => "direct", i = (p) => p, n = (p) => p.button === 0, a = () => {
2861
+ }, h = () => {
2689
2862
  }, d = () => {
2690
2863
  };
2691
2864
  return {
@@ -2693,14 +2866,33 @@ const ye = (r) => {
2693
2866
  connectionPreprocessor: r.connectionPreprocessor ?? i,
2694
2867
  mouseDownEventVerifier: r.mouseDownEventVerifier ?? n,
2695
2868
  mouseUpEventVerifier: r.mouseUpEventVerifier ?? n,
2696
- onAfterEdgeCreated: ((c = r.events) == null ? void 0 : c.onAfterEdgeCreated) ?? h,
2697
- onEdgeCreationInterrupted: ((g = r.events) == null ? void 0 : g.onEdgeCreationInterrupted) ?? d,
2698
- onEdgeCreationPrevented: ((l = r.events) == null ? void 0 : l.onEdgeCreationPrevented) ?? a,
2869
+ onAfterEdgeCreated: ((c = r.events) == null ? void 0 : c.onAfterEdgeCreated) ?? a,
2870
+ onEdgeCreationInterrupted: ((l = r.events) == null ? void 0 : l.onEdgeCreationInterrupted) ?? d,
2871
+ onEdgeCreationPrevented: ((g = r.events) == null ? void 0 : g.onEdgeCreationPrevented) ?? h,
2699
2872
  dragPortDirection: r.dragPortDirection ?? t,
2700
- edgeShapeFactory: r.edgeShape !== void 0 ? ye(r.edgeShape) : e
2873
+ edgeShapeFactory: r.edgeShape !== void 0 ? q(r.edgeShape) : e
2874
+ };
2875
+ }, Et = (r, e) => {
2876
+ var c, l, g;
2877
+ const t = (p) => p, s = (p) => p.button === 0 && p.ctrlKey, i = (p) => p.button === 0, n = (p) => {
2878
+ const f = e.getPortAdjacentEdgeIds(p);
2879
+ return f.length > 0 ? f[f.length - 1] : null;
2880
+ }, a = () => {
2881
+ }, h = () => {
2882
+ }, d = () => {
2883
+ };
2884
+ return {
2885
+ connectionPreprocessor: r.connectionPreprocessor ?? t,
2886
+ mouseDownEventVerifier: r.mouseDownEventVerifier ?? s,
2887
+ mouseUpEventVerifier: r.mouseUpEventVerifier ?? i,
2888
+ draggingEdgeResolver: r.draggingEdgeResolver ?? n,
2889
+ draggingEdgeShapeFactory: r.draggingEdgeShape !== void 0 ? q(r.draggingEdgeShape) : null,
2890
+ onAfterEdgeReattached: ((c = r.events) == null ? void 0 : c.onAfterEdgeReattached) ?? a,
2891
+ onEdgeReattachInterrupted: ((l = r.events) == null ? void 0 : l.onEdgeReattachInterrupted) ?? d,
2892
+ onEdgeReattachPrevented: ((g = r.events) == null ? void 0 : g.onEdgeReattachPrevented) ?? h
2701
2893
  };
2702
2894
  };
2703
- class wt {
2895
+ class St {
2704
2896
  constructor(e) {
2705
2897
  o(this, "element", null);
2706
2898
  o(this, "canvasDefaults", {});
@@ -2708,12 +2900,14 @@ class wt {
2708
2900
  o(this, "transformConfig", {});
2709
2901
  o(this, "backgroundConfig", {});
2710
2902
  o(this, "connectablePortsConfig", {});
2903
+ o(this, "draggableEdgesConfig", {});
2711
2904
  o(this, "virtualScrollConfig");
2712
2905
  o(this, "hasDraggableNode", !1);
2713
2906
  o(this, "hasTransformableViewport", !1);
2714
2907
  o(this, "hasResizeReactiveNodes", !1);
2715
2908
  o(this, "hasBackground", !1);
2716
2909
  o(this, "hasUserConnectablePorts", !1);
2910
+ o(this, "hasUserDraggableEdges", !1);
2717
2911
  o(this, "boxRenderingTrigger");
2718
2912
  o(this, "window", window);
2719
2913
  e !== void 0 && (this.element = e);
@@ -2774,70 +2968,86 @@ class wt {
2774
2968
  enableUserConnectablePorts(e) {
2775
2969
  return this.connectablePortsConfig = e ?? {}, this.hasUserConnectablePorts = !0, this;
2776
2970
  }
2971
+ enableUserDraggableEdges(e) {
2972
+ return this.hasUserDraggableEdges = !0, this.draggableEdgesConfig = e ?? {}, this;
2973
+ }
2777
2974
  /**
2778
2975
  * builds final canvas
2779
2976
  */
2780
2977
  build() {
2781
2978
  if (this.element === null)
2782
- throw new x(
2979
+ throw new S(
2783
2980
  "unable to build canvas when no attach element specified"
2784
2981
  );
2785
2982
  let e = this.boxRenderingTrigger;
2786
- this.virtualScrollConfig !== void 0 && e === void 0 && (e = new ae());
2787
- const t = new ce(), s = new Le(), i = new Oe(this.element);
2788
- let n = new he(
2983
+ this.virtualScrollConfig !== void 0 && e === void 0 && (e = new pe());
2984
+ const t = new fe(), s = new $e(), i = new at(this.element);
2985
+ let n = new ue(
2789
2986
  t,
2790
2987
  s,
2791
2988
  i.main
2792
2989
  );
2793
- e !== void 0 && (n = new Te(n, t, e));
2794
- const h = ot(this.canvasDefaults), a = new de(
2990
+ e !== void 0 && (n = new Ue(n, t, e));
2991
+ const a = gt(this.canvasDefaults), h = new we(
2795
2992
  this.element,
2796
2993
  t,
2797
2994
  s,
2798
2995
  n,
2799
- h
2996
+ a
2800
2997
  );
2801
- if (this.hasBackground && Y.configure(
2802
- a,
2803
- ct(this.backgroundConfig),
2998
+ if (this.hasBackground && J.configure(
2999
+ h,
3000
+ mt(this.backgroundConfig),
2804
3001
  i.background
2805
- ), this.hasResizeReactiveNodes && k.configure(a), this.hasDraggableNode && z.configure(
2806
- a,
3002
+ ), this.hasResizeReactiveNodes && Y.configure(h), this.hasDraggableNode && K.configure(
3003
+ h,
2807
3004
  i.main,
2808
3005
  this.window,
2809
- st(this.dragConfig)
3006
+ lt(this.dragConfig)
2810
3007
  ), this.hasUserConnectablePorts) {
2811
- const c = lt(
3008
+ const c = yt(
2812
3009
  this.connectablePortsConfig,
2813
- h.edges.shapeFactory,
2814
- h.ports.direction
3010
+ a.edges.shapeFactory,
3011
+ a.ports.direction
2815
3012
  );
2816
- H.configure(
2817
- a,
2818
- i.overlay,
3013
+ Q.configure(
3014
+ h,
3015
+ i.overlayConnectablePorts,
2819
3016
  s,
2820
3017
  this.window,
2821
3018
  c
2822
3019
  );
2823
3020
  }
2824
- this.virtualScrollConfig !== void 0 ? X.configure(
2825
- a,
3021
+ if (this.hasUserDraggableEdges) {
3022
+ const c = Et(
3023
+ this.draggableEdgesConfig,
3024
+ h.graph
3025
+ );
3026
+ _.configure(
3027
+ h,
3028
+ i.overlayDraggableEdges,
3029
+ s,
3030
+ this.window,
3031
+ c
3032
+ );
3033
+ }
3034
+ this.virtualScrollConfig !== void 0 ? Z.configure(
3035
+ h,
2826
3036
  i.main,
2827
3037
  this.window,
2828
- ne(this.transformConfig),
3038
+ le(this.transformConfig),
2829
3039
  e,
2830
3040
  this.virtualScrollConfig
2831
- ) : this.hasTransformableViewport && U.configure(
2832
- a,
3041
+ ) : this.hasTransformableViewport && $.configure(
3042
+ h,
2833
3043
  i.main,
2834
3044
  this.window,
2835
- ne(this.transformConfig)
3045
+ le(this.transformConfig)
2836
3046
  ), this.reset();
2837
3047
  const d = () => {
2838
- i.destroy(), a.onBeforeDestroy.unsubscribe(d);
3048
+ i.destroy(), h.onBeforeDestroy.unsubscribe(d);
2839
3049
  };
2840
- return a.onBeforeDestroy.subscribe(d), a;
3050
+ return h.onBeforeDestroy.subscribe(d), h;
2841
3051
  }
2842
3052
  /**
2843
3053
  * @deprecated
@@ -2848,17 +3058,17 @@ class wt {
2848
3058
  }
2849
3059
  }
2850
3060
  export {
2851
- Je as BezierEdgeShape,
2852
- wt as CanvasBuilder,
2853
- qe as DirectEdgeShape,
2854
- ae as EventSubject,
2855
- Ke as HorizontalEdgeShape,
2856
- x as HtmlGraphError,
2857
- rt as InteractiveEdgeError,
2858
- me as InteractiveEdgeShape,
2859
- C as LineEdgeShape,
2860
- ut as MedianEdgeShape,
2861
- ut as MidpointEdgeShape,
3061
+ Ze as BezierEdgeShape,
3062
+ St as CanvasBuilder,
3063
+ Pe as DirectEdgeShape,
3064
+ pe as EventSubject,
3065
+ Je as HorizontalEdgeShape,
3066
+ S as HtmlGraphError,
3067
+ tt as InteractiveEdgeError,
3068
+ Te as InteractiveEdgeShape,
3069
+ W as LineEdgeShape,
3070
+ xt as MedianEdgeShape,
3071
+ xt as MidpointEdgeShape,
2862
3072
  Qe as StraightEdgeShape,
2863
3073
  _e as VerticalEdgeShape
2864
3074
  };