@html-graph/html-graph 3.7.0 → 3.8.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.
@@ -252,6 +252,9 @@ class pe {
252
252
  priority: o.priority
253
253
  };
254
254
  }
255
+ getElementNodeId(e) {
256
+ return this.graphStore.getElementNodeId(e) ?? null;
257
+ }
255
258
  // TODO: use Set in v4
256
259
  getAllNodeIds() {
257
260
  return this.graphStore.getAllNodeIds();
@@ -339,991 +342,249 @@ class S extends Error {
339
342
  r(this, "name", "HtmlGraphError");
340
343
  }
341
344
  }
342
- const Ae = (t, e) => ({
343
- x: t / 2,
344
- y: e / 2
345
- }), $ = (t) => () => t, K = $(0), Ee = () => {
346
- let t = 0;
347
- return () => t++;
348
- }, xe = (t, e) => {
349
- let o = K, i = K;
350
- const s = Ee();
351
- return t === "incremental" && (o = s), e === "incremental" && (i = s), typeof t == "number" && (o = $(t)), typeof e == "number" && (i = $(e)), typeof t == "function" && (o = t), typeof e == "function" && (i = e), {
352
- nodesPriorityFn: o,
353
- edgesPriorityFn: i
354
- };
355
- }, v = (t, e, o) => ({
356
- x: e.x * t.x - e.y * t.y + ((1 - e.x) * o.x + e.y * o.y),
357
- y: e.y * t.x + e.x * t.y + ((1 - e.x) * o.y - e.y * o.x)
358
- }), w = {
359
- x: 0,
360
- y: 0
361
- }, Se = (t) => {
362
- const e = v(
363
- { x: t.arrowLength, y: w.y },
364
- t.fromVector,
365
- w
366
- ), o = v(
367
- { x: t.to.x - t.arrowLength, y: t.to.y },
368
- t.toVector,
369
- t.to
370
- ), i = {
371
- x: e.x + t.fromVector.x * t.curvature,
372
- y: e.y + t.fromVector.y * t.curvature
373
- }, s = {
374
- x: o.x - t.toVector.x * t.curvature,
375
- y: o.y - t.toVector.y * t.curvature
376
- }, h = `M ${e.x} ${e.y} C ${i.x} ${i.y}, ${s.x} ${s.y}, ${o.x} ${o.y}`, n = t.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${e.x} ${e.y} `, d = t.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${t.to.x} ${t.to.y}`;
377
- return `${n}${h}${d}`;
378
- }, be = (t) => {
379
- const e = t.hasSourceArrow ? v(
380
- { x: t.arrowLength, y: w.y },
381
- t.fromVector,
382
- w
383
- ) : w, o = t.hasTargetArrow ? v(
384
- { x: t.to.x - t.arrowLength, y: t.to.y },
385
- t.toVector,
386
- t.to
387
- ) : t.to, i = t.arrowLength, s = Math.cos(t.detourDirection) * t.detourDistance, h = Math.sin(t.detourDirection) * t.detourDistance, n = s * t.flipX, d = h * t.flipY, c = v(
388
- { x: i, y: w.y },
389
- t.fromVector,
390
- w
391
- ), a = {
392
- x: c.x + n,
393
- y: c.y + d
394
- }, l = v(
395
- { x: t.to.x - i, y: t.to.y },
396
- t.toVector,
397
- t.to
398
- ), g = {
399
- x: l.x + n,
400
- y: l.y + d
401
- }, y = { x: (a.x + g.x) / 2, y: (a.y + g.y) / 2 }, p = {
402
- x: c.x + t.curvature * t.fromVector.x,
403
- y: c.y + t.curvature * t.fromVector.y
404
- }, f = {
405
- x: l.x - t.curvature * t.toVector.x,
406
- y: l.y - t.curvature * t.toVector.y
407
- }, A = {
408
- x: c.x + n,
409
- y: c.y + d
410
- }, E = {
411
- x: l.x + n,
412
- y: l.y + d
413
- };
414
- return [
415
- `M ${e.x} ${e.y}`,
416
- `L ${c.x} ${c.y}`,
417
- `C ${p.x} ${p.y} ${A.x} ${A.y} ${y.x} ${y.y}`,
418
- `C ${E.x} ${E.y} ${f.x} ${f.y} ${l.x} ${l.y}`,
419
- `L ${o.x} ${o.y}`
420
- ].join(" ");
421
- }, V = (t, e) => {
422
- const o = [];
423
- if (t.length > 0 && o.push(`M ${t[0].x} ${t[0].y}`), t.length === 2 && o.push(`L ${t[1].x} ${t[1].y}`), t.length > 2) {
424
- const i = t.length - 1;
425
- let s = 0, h = 0, n = 0;
426
- t.forEach((d, c) => {
427
- let a = 0, l = 0, g = 0;
428
- const y = c > 0, p = c < i, f = y && p;
429
- if (y && (a = -s, l = -h, g = n), p) {
430
- const L = t[c + 1];
431
- s = L.x - d.x, h = L.y - d.y, n = Math.sqrt(s * s + h * h);
432
- }
433
- const E = n !== 0 ? Math.min((f ? e : 0) / n, c < i - 1 ? 0.5 : 1) : 0, b = f ? { x: d.x + s * E, y: d.y + h * E } : d, m = g !== 0 ? Math.min((f ? e : 0) / g, c > 1 ? 0.5 : 1) : 0, D = f ? { x: d.x + a * m, y: d.y + l * m } : d;
434
- c > 0 && o.push(`L ${D.x} ${D.y}`), f && o.push(
435
- `C ${d.x} ${d.y} ${d.x} ${d.y} ${b.x} ${b.y}`
436
- );
345
+ class ne {
346
+ constructor(e, o, i, s, h) {
347
+ /**
348
+ * provides api for accessing model of rendered graph
349
+ */
350
+ r(this, "graph");
351
+ /**
352
+ * provides api for accessing viewport state
353
+ */
354
+ r(this, "viewport");
355
+ r(this, "nodeIdGenerator", new C(
356
+ (e) => this.graph.getNode(e) !== null
357
+ ));
358
+ r(this, "portIdGenerator", new C(
359
+ (e) => this.graph.getPort(e) !== null
360
+ ));
361
+ r(this, "edgeIdGenerator", new C(
362
+ (e) => this.graph.getEdge(e) !== null
363
+ ));
364
+ r(this, "onAfterNodeAdded", (e) => {
365
+ this.htmlView.attachNode(e);
366
+ });
367
+ r(this, "onAfterNodeUpdated", (e) => {
368
+ this.htmlView.updateNodePosition(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((i) => {
369
+ this.htmlView.renderEdge(i);
370
+ });
371
+ });
372
+ r(this, "onAfterNodePriorityUpdated", (e) => {
373
+ this.htmlView.updateNodePriority(e);
374
+ });
375
+ r(this, "onBeforeNodeRemoved", (e) => {
376
+ this.graphStore.getNodePortIds(e).forEach((o) => {
377
+ this.unmarkPort(o);
378
+ }), this.htmlView.detachNode(e);
379
+ });
380
+ r(this, "onAfterPortUpdated", (e) => {
381
+ this.graphStore.getPortAdjacentEdgeIds(e).forEach((i) => {
382
+ this.htmlView.renderEdge(i);
383
+ });
384
+ });
385
+ r(this, "onBeforePortUnmarked", (e) => {
386
+ this.graphStore.getPortAdjacentEdgeIds(e).forEach((o) => {
387
+ this.removeEdge(o);
388
+ });
389
+ });
390
+ r(this, "onAfterEdgeAdded", (e) => {
391
+ this.htmlView.attachEdge(e);
392
+ });
393
+ r(this, "onAfterEdgeShapeUpdated", (e) => {
394
+ this.htmlView.updateEdgeShape(e);
395
+ });
396
+ r(this, "onAfterEdgeUpdated", (e) => {
397
+ this.htmlView.renderEdge(e);
398
+ });
399
+ r(this, "onAfterEdgePriorityUpdated", (e) => {
400
+ this.htmlView.updateEdgePriority(e);
437
401
  });
402
+ r(this, "onBeforeEdgeRemoved", (e) => {
403
+ this.htmlView.detachEdge(e);
404
+ });
405
+ r(this, "onBeforeClear", () => {
406
+ this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset(), this.htmlView.clear();
407
+ });
408
+ r(this, "onBeforeDestroyEmitter");
409
+ /**
410
+ * emits event just before destruction of canvas
411
+ */
412
+ r(this, "onBeforeDestroy");
413
+ this.element = e, this.graphStore = o, this.viewportStore = i, this.htmlView = s, this.defaults = h, this.graph = new pe(this.graphStore), this.viewport = new ye(this.viewportStore), this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.subscribe(
414
+ this.onAfterNodePriorityUpdated
415
+ ), 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(
416
+ this.onAfterEdgeShapeUpdated
417
+ ), this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.subscribe(
418
+ this.onAfterEdgePriorityUpdated
419
+ ), this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.subscribe(this.onBeforeClear), [this.onBeforeDestroyEmitter, this.onBeforeDestroy] = x();
438
420
  }
439
- return o.join(" ");
440
- }, me = (t) => {
441
- const e = t.hasSourceArrow ? v(
442
- { x: t.arrowLength, y: w.y },
443
- t.fromVector,
444
- w
445
- ) : w, o = t.hasTargetArrow ? v(
446
- { x: t.to.x - t.arrowLength, y: t.to.y },
447
- t.toVector,
448
- t.to
449
- ) : t.to, i = t.arrowLength + t.arrowOffset, s = i - t.roundness, h = v(
450
- { x: s, y: w.y },
451
- t.fromVector,
452
- w
453
- ), n = v(
454
- { x: t.to.x - s, y: t.to.y },
455
- t.toVector,
456
- t.to
457
- ), d = Math.max((h.x + n.x) / 2, i), c = t.to.y / 2, a = {
458
- x: t.flipX > 0 ? d : -i,
459
- y: h.y
460
- }, l = { x: a.x, y: c }, g = {
461
- x: t.flipX > 0 ? t.to.x - d : t.to.x + i,
462
- y: n.y
463
- }, y = { x: g.x, y: c };
464
- return V(
465
- [e, h, a, l, y, g, n, o],
466
- t.roundness
467
- );
468
- }, F = (t) => {
469
- const e = t.hasSourceArrow ? v(
470
- { x: t.arrowLength, y: w.y },
471
- t.fromVector,
472
- w
473
- ) : w, o = t.hasTargetArrow ? v(
474
- { x: t.to.x - t.arrowLength, y: t.to.y },
475
- t.toVector,
476
- t.to
477
- ) : t.to, i = t.arrowLength + t.arrowOffset, s = v(
478
- { x: i, y: w.y },
479
- t.fromVector,
480
- w
481
- ), h = Math.cos(t.detourDirection) * t.detourDistance, n = Math.sin(t.detourDirection) * t.detourDistance, d = h * t.flipX, c = n * t.flipY, a = { x: s.x + d, y: s.y + c }, l = v(
482
- { x: t.to.x - i, y: t.to.y },
483
- t.toVector,
484
- t.to
485
- ), g = { x: l.x + d, y: l.y + c };
486
- return V(
487
- [e, s, a, g, l, o],
488
- t.roundness
489
- );
490
- }, Te = (t) => {
491
- const e = t.hasSourceArrow ? v(
492
- { x: t.arrowLength, y: w.y },
493
- t.fromVector,
494
- w
495
- ) : w, o = t.hasTargetArrow ? v(
496
- { x: t.to.x - t.arrowLength, y: t.to.y },
497
- t.toVector,
498
- t.to
499
- ) : t.to, i = t.arrowLength + t.arrowOffset, s = v(
500
- { x: i, y: w.y },
501
- t.fromVector,
502
- w
503
- ), h = v(
504
- { x: t.to.x - i, y: t.to.y },
505
- t.toVector,
506
- t.to
507
- );
508
- return V([e, s, h, o], t.roundness);
509
- }, Pe = (t) => {
510
- const e = t.hasSourceArrow ? v(
511
- { x: t.arrowLength, y: w.y },
512
- t.fromVector,
513
- w
514
- ) : w, o = t.hasTargetArrow ? v(
515
- { x: t.to.x - t.arrowLength, y: t.to.y },
516
- t.toVector,
517
- t.to
518
- ) : t.to, i = t.arrowLength + t.arrowOffset, s = i - t.roundness, h = v(
519
- { x: s, y: w.y },
520
- t.fromVector,
521
- w
522
- ), n = v(
523
- { x: t.to.x - s, y: t.to.y },
524
- t.toVector,
525
- t.to
526
- ), d = Math.max((h.y + n.y) / 2, i), c = t.to.x / 2, a = {
527
- x: h.x,
528
- y: t.flipY > 0 ? d : -i
529
- }, l = { x: c, y: a.y }, g = {
530
- x: n.x,
531
- y: t.flipY > 0 ? t.to.y - d : t.to.y + i
532
- }, y = { x: c, y: g.y };
533
- return V(
534
- [e, h, a, l, y, g, n, o],
535
- t.roundness
536
- );
537
- }, k = (t) => {
538
- const e = t.arrowOffset, o = t.side, i = t.arrowLength + e, s = i + 2 * o, n = [
539
- { x: t.arrowLength, y: w.y },
540
- { x: i, y: w.y },
541
- { x: i, y: t.side },
542
- { x: s, y: t.side },
543
- { x: s, y: -t.side },
544
- { x: i, y: -t.side },
545
- { x: i, y: w.y },
546
- { x: t.arrowLength, y: w.y }
547
- ].map(
548
- (c) => v(c, t.fromVector, w)
549
- ), d = `M ${w.x} ${w.y} L ${n[0].x} ${n[0].y} `;
550
- return `${t.hasSourceArrow || t.hasTargetArrow ? "" : d}${V(n, t.roundness)}`;
551
- }, Ne = (t) => {
552
- const e = t.smallRadius, o = t.radius, i = Math.sqrt(e * e + o * o), s = e + o, h = t.arrowLength + i * (1 - o / s), n = e * o / s, c = [
553
- { x: t.arrowLength, y: w.y },
554
- { x: h, y: n },
555
- { x: h, y: -n }
556
- ].map(
557
- (g) => v(g, t.fromVector, w)
558
- ), a = [
559
- `M ${c[0].x} ${c[0].y}`,
560
- `A ${e} ${e} 0 0 1 ${c[1].x} ${c[1].y}`,
561
- `A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,
562
- `A ${e} ${e} 0 0 1 ${c[0].x} ${c[0].y}`
563
- ].join(" "), l = `M 0 0 L ${c[0].x} ${c[0].y} `;
564
- return `${t.hasSourceArrow || t.hasTargetArrow ? "" : l}${a}`;
565
- }, u = Object.freeze({
566
- color: "#777777",
567
- width: 1,
568
- arrowLength: 15,
569
- arrowWidth: 4,
570
- arrowOffset: 15,
571
- hasSourceArrow: !1,
572
- hasTargetArrow: !1,
573
- cycleRadius: 30,
574
- cycleSquareSide: 30,
575
- roundness: 10,
576
- detourDistance: 100,
577
- detourDirection: -Math.PI / 2,
578
- detourDirectionVertical: 0,
579
- smallCycleRadius: 15,
580
- curvature: 90,
581
- interactiveWidth: 10
582
- }), Q = (t, e, o, i) => {
583
- const h = [
584
- w,
585
- { x: o, y: i },
586
- { x: o, y: -i }
587
- ].map((a) => v(a, t, w)).map((a) => ({ x: a.x + e.x, y: a.y + e.y })), n = `M ${h[0].x} ${h[0].y}`, d = `L ${h[1].x} ${h[1].y}`, c = `L ${h[2].x} ${h[2].y}`;
588
- return `${n} ${d} ${c} Z`;
589
- }, _ = (t) => {
590
- const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
591
- return e.setAttribute("fill", t), e;
592
- }, Me = () => {
593
- const t = document.createElementNS("http://www.w3.org/2000/svg", "g");
594
- return t.style.transformOrigin = "50% 50%", t;
595
- }, De = (t, e) => {
596
- const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
597
- return o.setAttribute("stroke", t), o.setAttribute("stroke-width", `${e}`), o.setAttribute("fill", "none"), o;
598
- }, Le = (t, e) => {
599
- const o = {
600
- x: t.x + t.width / 2,
601
- y: t.y + t.height / 2
602
- }, i = {
603
- x: e.x + e.width / 2,
604
- y: e.y + e.height / 2
605
- }, s = Math.min(o.x, i.x), h = Math.min(o.y, i.y), n = Math.abs(i.x - o.x), d = Math.abs(i.y - o.y), c = o.x <= i.x ? 1 : -1, a = o.y <= i.y ? 1 : -1;
606
- return {
607
- x: s,
608
- y: h,
609
- width: n,
610
- height: d,
611
- flipX: c,
612
- flipY: a
613
- };
614
- }, Ve = () => {
615
- const t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
616
- return t.style.pointerEvents = "none", t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.overflow = "visible", t;
617
- }, q = (t, e, o) => ({ x: e * Math.cos(t), y: o * Math.sin(t) });
618
- class I {
619
- constructor(e) {
620
- r(this, "svg", Ve());
621
- r(this, "group", Me());
622
- r(this, "line");
623
- r(this, "sourceArrow", null);
624
- r(this, "targetArrow", null);
625
- this.params = e, this.svg.appendChild(this.group), this.line = De(e.color, e.width), this.group.appendChild(this.line), e.hasSourceArrow && (this.sourceArrow = _(e.color), this.group.appendChild(this.sourceArrow)), e.hasTargetArrow && (this.targetArrow = _(e.color), this.group.appendChild(this.targetArrow));
421
+ /**
422
+ * adds new node
423
+ */
424
+ addNode(e) {
425
+ const o = this.nodeIdGenerator.create(e.id);
426
+ if (this.graph.getNode(o) !== null)
427
+ throw new S("failed to add node with existing id");
428
+ if (this.graphStore.addNode({
429
+ id: o,
430
+ element: e.element,
431
+ x: e.x,
432
+ y: e.y,
433
+ centerFn: e.centerFn ?? this.defaults.nodes.centerFn,
434
+ priority: e.priority ?? this.defaults.nodes.priorityFn()
435
+ }), e.ports !== void 0)
436
+ for (const i of e.ports)
437
+ this.markPort({
438
+ id: i.id,
439
+ element: i.element,
440
+ nodeId: o,
441
+ direction: i.direction
442
+ });
443
+ return this;
626
444
  }
627
- render(e) {
628
- const { x: o, y: i, width: s, height: h, flipX: n, flipY: d } = Le(
629
- e.from,
630
- e.to
631
- );
632
- this.svg.style.transform = `translate(${o}px, ${i}px)`, this.svg.style.width = `${Math.max(s, 1)}px`, this.svg.style.height = `${Math.max(h, 1)}px`, this.group.style.transform = `scale(${n}, ${d})`;
633
- const c = q(
634
- e.from.direction,
635
- n,
636
- d
637
- ), a = q(
638
- e.to.direction,
639
- n,
640
- d
641
- ), l = {
642
- x: s,
643
- y: h
644
- };
645
- let g = a, y = -this.params.arrowLength, p;
646
- e.from.portId === e.to.portId ? (p = this.params.createCyclePath, g = c, y = this.params.arrowLength) : e.from.nodeId === e.to.nodeId ? p = this.params.createDetourPath : p = this.params.createLinePath;
647
- const f = p(
648
- c,
649
- a,
650
- l,
651
- n,
652
- d
653
- );
654
- if (this.line.setAttribute("d", f), this.sourceArrow) {
655
- const A = Q(
656
- c,
657
- w,
658
- this.params.arrowLength,
659
- this.params.arrowWidth
660
- );
661
- this.sourceArrow.setAttribute("d", A);
662
- }
663
- if (this.targetArrow) {
664
- const A = Q(
665
- g,
666
- l,
667
- y,
668
- this.params.arrowWidth
669
- );
670
- this.targetArrow.setAttribute("d", A);
671
- }
445
+ /**
446
+ * updates node parameters
447
+ */
448
+ updateNode(e, o) {
449
+ if (this.graph.getNode(e) === null)
450
+ throw new S("failed to update non existing node");
451
+ return this.graphStore.updateNode(e, o ?? {}), this;
672
452
  }
673
- }
674
- class Re {
675
- constructor(e) {
676
- r(this, "svg");
677
- r(this, "group");
678
- r(this, "line");
679
- r(this, "sourceArrow");
680
- r(this, "targetArrow");
681
- r(this, "arrowLength");
682
- r(this, "arrowWidth");
683
- r(this, "curvature");
684
- r(this, "portCycleRadius");
685
- r(this, "portCycleSmallRadius");
686
- r(this, "detourDirection");
687
- r(this, "detourDistance");
688
- r(this, "hasSourceArrow");
689
- r(this, "hasTargetArrow");
690
- r(this, "lineShape");
691
- r(this, "createCyclePath", (e) => Ne({
692
- fromVector: e,
693
- radius: this.portCycleRadius,
694
- smallRadius: this.portCycleSmallRadius,
695
- arrowLength: this.arrowLength,
696
- hasSourceArrow: this.hasSourceArrow,
697
- hasTargetArrow: this.hasTargetArrow
698
- }));
699
- r(this, "createDetourPath", (e, o, i, s, h) => be({
700
- to: i,
701
- fromVector: e,
702
- toVector: o,
703
- flipX: s,
704
- flipY: h,
705
- arrowLength: this.arrowLength,
706
- detourDirection: this.detourDirection,
707
- detourDistance: this.detourDistance,
708
- curvature: this.curvature,
709
- hasSourceArrow: this.hasSourceArrow,
710
- hasTargetArrow: this.hasTargetArrow
711
- }));
712
- r(this, "createLinePath", (e, o, i) => Se({
713
- to: i,
714
- fromVector: e,
715
- toVector: o,
716
- arrowLength: this.arrowLength,
717
- curvature: this.curvature,
718
- hasSourceArrow: this.hasSourceArrow,
719
- hasTargetArrow: this.hasTargetArrow
720
- }));
721
- 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.lineShape = new I({
722
- color: (e == null ? void 0 : e.color) ?? u.color,
723
- width: (e == null ? void 0 : e.width) ?? u.width,
724
- arrowLength: this.arrowLength,
725
- arrowWidth: this.arrowWidth,
726
- hasSourceArrow: this.hasSourceArrow,
727
- hasTargetArrow: this.hasTargetArrow,
728
- createCyclePath: this.createCyclePath,
729
- createDetourPath: this.createDetourPath,
730
- createLinePath: this.createLinePath
731
- }), this.svg = this.lineShape.svg, this.group = this.lineShape.group, this.line = this.lineShape.line, this.sourceArrow = this.lineShape.sourceArrow, this.targetArrow = this.lineShape.targetArrow;
453
+ /**
454
+ * removes specified node
455
+ * all the ports of node get unmarked
456
+ * all the edges adjacent to node get removed
457
+ */
458
+ removeNode(e) {
459
+ if (this.graph.getNode(e) === null)
460
+ throw new S("failed to remove non existing node");
461
+ return this.graphStore.removeNode(e), this;
732
462
  }
733
- render(e) {
734
- this.lineShape.render(e);
463
+ /**
464
+ * marks specified element as a port for specified node
465
+ */
466
+ markPort(e) {
467
+ const o = this.portIdGenerator.create(e.id);
468
+ if (this.graph.getPort(o) !== null)
469
+ throw new S("failed to add port with existing id");
470
+ if (this.graph.getNode(e.nodeId) === null)
471
+ throw new S("failed to mark port for nonexistent node");
472
+ return this.graphStore.addPort({
473
+ id: o,
474
+ element: e.element,
475
+ nodeId: e.nodeId,
476
+ direction: e.direction ?? this.defaults.ports.direction
477
+ }), this;
735
478
  }
736
- }
737
- class Be {
738
- constructor(e) {
739
- r(this, "svg");
740
- r(this, "group");
741
- r(this, "line");
742
- r(this, "sourceArrow");
743
- r(this, "targetArrow");
744
- r(this, "arrowLength");
745
- r(this, "arrowWidth");
746
- r(this, "arrowOffset");
747
- r(this, "roundness");
748
- r(this, "cycleSquareSide");
749
- r(this, "detourDirection");
750
- r(this, "detourDistance");
751
- r(this, "hasSourceArrow");
752
- r(this, "hasTargetArrow");
753
- r(this, "lineShape");
754
- r(this, "createCyclePath", (e) => k({
755
- fromVector: e,
756
- arrowLength: this.arrowLength,
757
- side: this.cycleSquareSide,
758
- arrowOffset: this.arrowOffset,
759
- roundness: this.roundness,
760
- hasSourceArrow: this.hasSourceArrow,
761
- hasTargetArrow: this.hasTargetArrow
762
- }));
763
- r(this, "createDetourPath", (e, o, i, s, h) => F({
764
- to: i,
765
- fromVector: e,
766
- toVector: o,
767
- flipX: s,
768
- flipY: h,
769
- arrowLength: this.arrowLength,
770
- arrowOffset: this.arrowOffset,
771
- roundness: this.roundness,
772
- detourDirection: this.detourDirection,
773
- detourDistance: this.detourDistance,
774
- hasSourceArrow: this.hasSourceArrow,
775
- hasTargetArrow: this.hasTargetArrow
776
- }));
777
- r(this, "createLinePath", (e, o, i, s) => me({
778
- to: i,
779
- fromVector: e,
780
- toVector: o,
781
- flipX: s,
782
- arrowLength: this.arrowLength,
783
- arrowOffset: this.arrowOffset,
784
- roundness: this.roundness,
785
- hasSourceArrow: this.hasSourceArrow,
786
- hasTargetArrow: this.hasTargetArrow
787
- }));
788
- 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;
789
- const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
790
- this.roundness = Math.min(
791
- o,
792
- this.arrowOffset,
793
- this.cycleSquareSide / 2
794
- ), 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.lineShape = new I({
795
- color: (e == null ? void 0 : e.color) ?? u.color,
796
- width: (e == null ? void 0 : e.width) ?? u.width,
797
- arrowLength: this.arrowLength,
798
- arrowWidth: this.arrowWidth,
799
- hasSourceArrow: this.hasSourceArrow,
800
- hasTargetArrow: this.hasTargetArrow,
801
- createCyclePath: this.createCyclePath,
802
- createDetourPath: this.createDetourPath,
803
- createLinePath: this.createLinePath
804
- }), this.svg = this.lineShape.svg, this.group = this.lineShape.group, this.line = this.lineShape.line, this.sourceArrow = this.lineShape.sourceArrow, this.targetArrow = this.lineShape.targetArrow;
805
- }
806
- render(e) {
807
- this.lineShape.render(e);
479
+ /**
480
+ * updates port and edges attached to it
481
+ */
482
+ updatePort(e, o) {
483
+ if (this.graph.getPort(e) === null)
484
+ throw new S("failed to update nonexistent port");
485
+ return this.graphStore.updatePort(e, o ?? {}), this;
808
486
  }
809
- }
810
- class Ie {
811
- constructor(e) {
812
- r(this, "svg");
813
- r(this, "group");
814
- r(this, "line");
815
- r(this, "sourceArrow");
816
- r(this, "targetArrow");
817
- r(this, "arrowLength");
818
- r(this, "arrowWidth");
819
- r(this, "arrowOffset");
820
- r(this, "roundness");
821
- r(this, "cycleSquareSide");
822
- r(this, "detourDirection");
823
- r(this, "detourDistance");
824
- r(this, "hasSourceArrow");
825
- r(this, "hasTargetArrow");
826
- r(this, "lineShape");
827
- r(this, "createCyclePath", (e) => k({
828
- fromVector: e,
829
- arrowLength: this.arrowLength,
830
- side: this.cycleSquareSide,
831
- arrowOffset: this.arrowOffset,
832
- roundness: this.roundness,
833
- hasSourceArrow: this.hasSourceArrow,
834
- hasTargetArrow: this.hasTargetArrow
835
- }));
836
- r(this, "createDetourPath", (e, o, i, s, h) => F({
837
- to: i,
838
- fromVector: e,
839
- toVector: o,
840
- flipX: s,
841
- flipY: h,
842
- arrowLength: this.arrowLength,
843
- arrowOffset: this.arrowOffset,
844
- roundness: this.roundness,
845
- detourDirection: this.detourDirection,
846
- detourDistance: this.detourDistance,
847
- hasSourceArrow: this.hasSourceArrow,
848
- hasTargetArrow: this.hasTargetArrow
849
- }));
850
- r(this, "createLinePath", (e, o, i) => Te({
851
- to: i,
852
- fromVector: e,
853
- toVector: o,
854
- arrowLength: this.arrowLength,
855
- arrowOffset: this.arrowOffset,
856
- roundness: this.roundness,
857
- hasSourceArrow: this.hasSourceArrow,
858
- hasTargetArrow: this.hasTargetArrow
859
- }));
860
- 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;
861
- const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
862
- this.roundness = Math.min(
863
- o,
864
- this.arrowOffset,
865
- this.cycleSquareSide / 2
866
- ), 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.lineShape = new I({
867
- color: (e == null ? void 0 : e.color) ?? u.color,
868
- width: (e == null ? void 0 : e.width) ?? u.width,
869
- arrowLength: this.arrowLength,
870
- arrowWidth: this.arrowWidth,
871
- hasSourceArrow: this.hasSourceArrow,
872
- hasTargetArrow: this.hasTargetArrow,
873
- createCyclePath: this.createCyclePath,
874
- createDetourPath: this.createDetourPath,
875
- createLinePath: this.createLinePath
876
- }), this.svg = this.lineShape.svg, this.group = this.lineShape.group, this.line = this.lineShape.line, this.sourceArrow = this.lineShape.sourceArrow, this.targetArrow = this.lineShape.targetArrow;
487
+ /**
488
+ * unmarks specified port
489
+ * all the edges adjacent to the port get removed
490
+ */
491
+ unmarkPort(e) {
492
+ if (this.graph.getPort(e) === null)
493
+ throw new S("failed to unmark non existing port");
494
+ return this.graphStore.removePort(e), this;
877
495
  }
878
- render(e) {
879
- this.lineShape.render(e);
496
+ /**
497
+ * adds new edge
498
+ */
499
+ addEdge(e) {
500
+ const o = this.edgeIdGenerator.create(e.id);
501
+ if (this.graph.getEdge(o) !== null)
502
+ throw new S("failed to add edge with existing id");
503
+ if (this.graph.getPort(e.from) === null)
504
+ throw new S("failed to add edge from nonexistent port");
505
+ if (this.graph.getPort(e.to) === null)
506
+ throw new S("failed to add edge to nonexistent port");
507
+ return this.graphStore.addEdge({
508
+ id: o,
509
+ from: e.from,
510
+ to: e.to,
511
+ shape: e.shape ?? this.defaults.edges.shapeFactory(o),
512
+ priority: e.priority ?? this.defaults.edges.priorityFn()
513
+ }), this;
880
514
  }
881
- }
882
- class Ue {
883
- constructor(e) {
884
- r(this, "svg");
885
- r(this, "group");
886
- r(this, "line");
887
- r(this, "sourceArrow");
888
- r(this, "targetArrow");
889
- r(this, "arrowLength");
890
- r(this, "arrowWidth");
891
- r(this, "arrowOffset");
892
- r(this, "roundness");
893
- r(this, "cycleSquareSide");
894
- r(this, "detourDirection");
895
- r(this, "detourDistance");
896
- r(this, "hasSourceArrow");
897
- r(this, "hasTargetArrow");
898
- r(this, "lineShape");
899
- r(this, "createCyclePath", (e) => k({
900
- fromVector: e,
901
- arrowLength: this.arrowLength,
902
- side: this.cycleSquareSide,
903
- arrowOffset: this.arrowOffset,
904
- roundness: this.roundness,
905
- hasSourceArrow: this.hasSourceArrow,
906
- hasTargetArrow: this.hasTargetArrow
907
- }));
908
- r(this, "createDetourPath", (e, o, i, s, h) => F({
909
- to: i,
910
- fromVector: e,
911
- toVector: o,
912
- flipX: s,
913
- flipY: h,
914
- arrowLength: this.arrowLength,
915
- arrowOffset: this.arrowOffset,
916
- roundness: this.roundness,
917
- detourDirection: this.detourDirection,
918
- detourDistance: this.detourDistance,
919
- hasSourceArrow: this.hasSourceArrow,
920
- hasTargetArrow: this.hasTargetArrow
921
- }));
922
- r(this, "createLinePath", (e, o, i, s, h) => Pe({
923
- to: i,
924
- fromVector: e,
925
- toVector: o,
926
- flipY: h,
927
- arrowLength: this.arrowLength,
928
- arrowOffset: this.arrowOffset,
929
- roundness: this.roundness,
930
- hasSourceArrow: this.hasSourceArrow,
931
- hasTargetArrow: this.hasTargetArrow
932
- }));
933
- 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;
934
- const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
935
- this.roundness = Math.min(
936
- o,
937
- this.arrowOffset,
938
- this.cycleSquareSide / 2
939
- ), 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.lineShape = new I({
940
- color: (e == null ? void 0 : e.color) ?? u.color,
941
- width: (e == null ? void 0 : e.width) ?? u.width,
942
- arrowLength: this.arrowLength,
943
- arrowWidth: this.arrowWidth,
944
- hasSourceArrow: this.hasSourceArrow,
945
- hasTargetArrow: this.hasTargetArrow,
946
- createCyclePath: this.createCyclePath,
947
- createDetourPath: this.createDetourPath,
948
- createLinePath: this.createLinePath
949
- }), this.svg = this.lineShape.svg, this.group = this.lineShape.group, this.line = this.lineShape.line, this.sourceArrow = this.lineShape.sourceArrow, this.targetArrow = this.lineShape.targetArrow;
515
+ /**
516
+ * updates specified edge
517
+ */
518
+ updateEdge(e, o) {
519
+ if (this.graph.getEdge(e) === null)
520
+ throw new S("failed to update nonexistent edge");
521
+ return this.graphStore.updateEdge(e, o ?? {}), this;
950
522
  }
951
- render(e) {
952
- this.lineShape.render(e);
523
+ /**
524
+ * removes specified edge
525
+ */
526
+ removeEdge(e) {
527
+ if (this.graph.getEdge(e) === null)
528
+ throw new S("failed to remove nonexistent edge");
529
+ return this.graphStore.removeEdge(e), this;
953
530
  }
954
- }
955
- const Ce = () => {
956
- const t = document.createElementNS("http://www.w3.org/2000/svg", "g");
957
- return t.style.pointerEvents = "auto", t.style.cursor = "pointer", t;
958
- }, We = (t) => {
959
- const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
960
- return e.setAttribute("stroke", "transparent"), e.setAttribute("stroke-width", `${t}`), e.setAttribute("fill", "none"), e.setAttribute("stroke-linecap", "round"), e;
961
- }, ee = (t) => {
962
- const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
963
- return e.setAttribute("stroke-linejoin", "round"), e.setAttribute("stroke-width", `${t}`), e.setAttribute("fill", "transparent"), e.setAttribute("stroke", "transparent"), e;
964
- };
965
- class $e extends Error {
966
- constructor(e) {
967
- super(e), this.name = "InteractiveEdgeError";
531
+ /**
532
+ * applies transformation for viewport matrix
533
+ */
534
+ patchViewportMatrix(e) {
535
+ return this.viewportStore.patchViewportMatrix(e), this;
968
536
  }
969
- }
970
- class ne {
971
- constructor(e, o) {
972
- r(this, "svg");
973
- r(this, "group");
974
- r(this, "line");
975
- r(this, "sourceArrow");
976
- r(this, "targetArrow");
977
- r(this, "handle", Ce());
978
- r(this, "interactiveLine");
979
- r(this, "interactiveSourceArrow", null);
980
- r(this, "interactiveTargetArrow", null);
981
- if (this.structuredEdge = e, e instanceof ne)
982
- throw new $e(
983
- "interactive edge can be configured only once"
984
- );
985
- this.svg = this.structuredEdge.svg, this.group = this.structuredEdge.group, this.line = this.structuredEdge.line, this.sourceArrow = this.structuredEdge.sourceArrow, this.targetArrow = this.structuredEdge.targetArrow;
986
- const i = (o == null ? void 0 : o.width) ?? u.interactiveWidth;
987
- this.interactiveLine = We(i), this.handle.appendChild(this.interactiveLine), this.sourceArrow && (this.interactiveSourceArrow = ee(i), this.handle.appendChild(this.interactiveSourceArrow)), this.targetArrow && (this.interactiveTargetArrow = ee(i), this.handle.appendChild(this.interactiveTargetArrow)), this.group.appendChild(this.handle);
537
+ /**
538
+ * applies transformation for content matrix
539
+ */
540
+ patchContentMatrix(e) {
541
+ return this.viewportStore.patchContentMatrix(e), this;
988
542
  }
989
- render(e) {
990
- this.structuredEdge.render(e);
991
- const o = this.line.getAttribute("d");
992
- if (this.interactiveLine.setAttribute("d", o), this.sourceArrow) {
993
- const i = this.sourceArrow.getAttribute("d");
994
- this.interactiveSourceArrow.setAttribute("d", i);
995
- }
996
- if (this.targetArrow) {
997
- const i = this.targetArrow.getAttribute("d");
998
- this.interactiveTargetArrow.setAttribute("d", i);
999
- }
1000
- }
1001
- }
1002
- const Fe = (t) => {
1003
- if (typeof t == "function")
1004
- return t;
1005
- switch (t == null ? void 0 : t.type) {
1006
- case "straight":
1007
- return () => new Ie({
1008
- color: t.color,
1009
- width: t.width,
1010
- arrowLength: t.arrowLength,
1011
- arrowWidth: t.arrowWidth,
1012
- arrowOffset: t.arrowOffset,
1013
- hasSourceArrow: t.hasSourceArrow,
1014
- hasTargetArrow: t.hasTargetArrow,
1015
- cycleSquareSide: t.cycleSquareSide,
1016
- roundness: t.roundness,
1017
- detourDistance: t.detourDistance,
1018
- detourDirection: t.detourDirection
1019
- });
1020
- case "horizontal":
1021
- return () => new Be({
1022
- color: t.color,
1023
- width: t.width,
1024
- arrowLength: t.arrowLength,
1025
- arrowWidth: t.arrowWidth,
1026
- arrowOffset: t.arrowOffset,
1027
- hasSourceArrow: t.hasSourceArrow,
1028
- hasTargetArrow: t.hasTargetArrow,
1029
- cycleSquareSide: t.cycleSquareSide,
1030
- roundness: t.roundness,
1031
- detourDistance: t.detourDistance,
1032
- detourDirection: t.detourDirection
1033
- });
1034
- case "vertical":
1035
- return () => new Ue({
1036
- color: t.color,
1037
- width: t.width,
1038
- arrowLength: t.arrowLength,
1039
- arrowWidth: t.arrowWidth,
1040
- arrowOffset: t.arrowOffset,
1041
- hasSourceArrow: t.hasSourceArrow,
1042
- hasTargetArrow: t.hasTargetArrow,
1043
- cycleSquareSide: t.cycleSquareSide,
1044
- roundness: t.roundness,
1045
- detourDistance: t.detourDistance,
1046
- detourDirection: t.detourDirection
1047
- });
1048
- default:
1049
- return () => new Re({
1050
- color: t.color,
1051
- width: t.width,
1052
- arrowLength: t.arrowLength,
1053
- arrowWidth: t.arrowWidth,
1054
- hasSourceArrow: t.hasSourceArrow,
1055
- hasTargetArrow: t.hasTargetArrow,
1056
- cycleRadius: t.cycleRadius,
1057
- smallCycleRadius: t.smallCycleRadius,
1058
- curvature: t.curvature,
1059
- detourDistance: t.detourDistance,
1060
- detourDirection: t.detourDirection
1061
- });
543
+ /**
544
+ * clears canvas from nodes and edges
545
+ * canvas gets rolled back to initial state and can be reused
546
+ */
547
+ clear() {
548
+ return this.graphStore.clear(), this;
1062
549
  }
1063
- }, ke = (t) => {
1064
- var o, i, s, h, n;
1065
- const e = xe(
1066
- (o = t == null ? void 0 : t.nodes) == null ? void 0 : o.priority,
1067
- (i = t == null ? void 0 : t.edges) == null ? void 0 : i.priority
1068
- );
1069
- return {
1070
- nodes: {
1071
- centerFn: ((s = t == null ? void 0 : t.nodes) == null ? void 0 : s.centerFn) ?? Ae,
1072
- priorityFn: e.nodesPriorityFn
1073
- },
1074
- ports: {
1075
- direction: ((h = t == null ? void 0 : t.ports) == null ? void 0 : h.direction) ?? 0
1076
- },
1077
- edges: {
1078
- shapeFactory: Fe(((n = t == null ? void 0 : t.edges) == null ? void 0 : n.shape) ?? {}),
1079
- priorityFn: e.edgesPriorityFn
1080
- }
1081
- };
1082
- };
1083
- class he {
1084
- constructor(e, o, i, s, h) {
1085
- /**
1086
- * provides api for accessing model of rendered graph
1087
- */
1088
- r(this, "graph");
1089
- /**
1090
- * provides api for accessing viewport state
1091
- */
1092
- r(this, "viewport");
1093
- r(this, "defaults");
1094
- r(this, "nodeIdGenerator", new C(
1095
- (e) => this.graph.getNode(e) !== null
1096
- ));
1097
- r(this, "portIdGenerator", new C(
1098
- (e) => this.graph.getPort(e) !== null
1099
- ));
1100
- r(this, "edgeIdGenerator", new C(
1101
- (e) => this.graph.getEdge(e) !== null
1102
- ));
1103
- r(this, "onAfterNodeAdded", (e) => {
1104
- this.htmlView.attachNode(e);
1105
- });
1106
- r(this, "onAfterNodeUpdated", (e) => {
1107
- this.htmlView.updateNodePosition(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((i) => {
1108
- this.htmlView.renderEdge(i);
1109
- });
1110
- });
1111
- r(this, "onAfterNodePriorityUpdated", (e) => {
1112
- this.htmlView.updateNodePriority(e);
1113
- });
1114
- r(this, "onBeforeNodeRemoved", (e) => {
1115
- this.graphStore.getNodePortIds(e).forEach((o) => {
1116
- this.unmarkPort(o);
1117
- }), this.htmlView.detachNode(e);
1118
- });
1119
- r(this, "onAfterPortUpdated", (e) => {
1120
- this.graphStore.getPortAdjacentEdgeIds(e).forEach((i) => {
1121
- this.htmlView.renderEdge(i);
1122
- });
1123
- });
1124
- r(this, "onBeforePortUnmarked", (e) => {
1125
- this.graphStore.getPortAdjacentEdgeIds(e).forEach((o) => {
1126
- this.removeEdge(o);
1127
- });
1128
- });
1129
- r(this, "onAfterEdgeAdded", (e) => {
1130
- this.htmlView.attachEdge(e);
1131
- });
1132
- r(this, "onAfterEdgeShapeUpdated", (e) => {
1133
- this.htmlView.updateEdgeShape(e);
1134
- });
1135
- r(this, "onAfterEdgeUpdated", (e) => {
1136
- this.htmlView.renderEdge(e);
1137
- });
1138
- r(this, "onAfterEdgePriorityUpdated", (e) => {
1139
- this.htmlView.updateEdgePriority(e);
1140
- });
1141
- r(this, "onBeforeEdgeRemoved", (e) => {
1142
- this.htmlView.detachEdge(e);
1143
- });
1144
- r(this, "onBeforeClear", () => {
1145
- this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset(), this.htmlView.clear();
1146
- });
1147
- r(this, "onBeforeDestroyEmitter");
1148
- /**
1149
- * emits event just before destruction of canvas
1150
- */
1151
- r(this, "onBeforeDestroy");
1152
- this.element = e, this.graphStore = o, this.viewportStore = i, this.htmlView = s, this.defaults = ke(h), this.graph = new pe(this.graphStore), this.viewport = new ye(this.viewportStore), this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.subscribe(
550
+ /**
551
+ * destroys canvas
552
+ * canvas element gets rolled back to initial state, and can not be reused
553
+ */
554
+ destroy() {
555
+ this.clear(), this.onBeforeDestroyEmitter.emit(), this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.unsubscribe(
1153
556
  this.onAfterNodePriorityUpdated
1154
- ), 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(
557
+ ), this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved), this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated), this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked), this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded), this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(
1155
558
  this.onAfterEdgeShapeUpdated
1156
- ), this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.subscribe(
559
+ ), this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(
1157
560
  this.onAfterEdgePriorityUpdated
1158
- ), this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.subscribe(this.onBeforeClear), [this.onBeforeDestroyEmitter, this.onBeforeDestroy] = x();
561
+ ), this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear), this.htmlView.destroy();
1159
562
  }
1160
- /**
1161
- * adds new node
1162
- */
1163
- addNode(e) {
1164
- const o = this.nodeIdGenerator.create(e.id);
1165
- if (this.graph.getNode(o) !== null)
1166
- throw new S("failed to add node with existing id");
1167
- if (this.graphStore.addNode({
1168
- id: o,
1169
- element: e.element,
1170
- x: e.x,
1171
- y: e.y,
1172
- centerFn: e.centerFn ?? this.defaults.nodes.centerFn,
1173
- priority: e.priority ?? this.defaults.nodes.priorityFn()
1174
- }), e.ports !== void 0)
1175
- for (const i of e.ports)
1176
- this.markPort({
1177
- id: i.id,
1178
- element: i.element,
1179
- nodeId: o,
1180
- direction: i.direction
1181
- });
1182
- return this;
563
+ }
564
+ class he {
565
+ constructor() {
566
+ r(this, "singleToMultiMap", /* @__PURE__ */ new Map());
567
+ r(this, "multiToSingleMap", /* @__PURE__ */ new Map());
1183
568
  }
1184
- /**
1185
- * updates node parameters
1186
- */
1187
- updateNode(e, o) {
1188
- if (this.graph.getNode(e) === null)
1189
- throw new S("failed to update non existing node");
1190
- return this.graphStore.updateNode(e, o ?? {}), this;
569
+ addRecord(e, o) {
570
+ const i = this.singleToMultiMap.get(e);
571
+ i === void 0 ? this.singleToMultiMap.set(e, /* @__PURE__ */ new Set([o])) : i.add(o), this.multiToSingleMap.set(o, e);
1191
572
  }
1192
- /**
1193
- * removes specified node
1194
- * all the ports of node get unmarked
1195
- * all the edges adjacent to node get removed
1196
- */
1197
- removeNode(e) {
1198
- if (this.graph.getNode(e) === null)
1199
- throw new S("failed to remove non existing node");
1200
- return this.graphStore.removeNode(e), this;
573
+ getMultiBySingle(e) {
574
+ const o = this.singleToMultiMap.get(e) ?? /* @__PURE__ */ new Set();
575
+ return Array.from(o.values());
1201
576
  }
1202
- /**
1203
- * marks specified element as a port for specified node
1204
- */
1205
- markPort(e) {
1206
- const o = this.portIdGenerator.create(e.id);
1207
- if (this.graph.getPort(o) !== null)
1208
- throw new S("failed to add port with existing id");
1209
- if (this.graph.getNode(e.nodeId) === null)
1210
- throw new S("failed to mark port for nonexistent node");
1211
- return this.graphStore.addPort({
1212
- id: o,
1213
- element: e.element,
1214
- nodeId: e.nodeId,
1215
- direction: e.direction ?? this.defaults.ports.direction
1216
- }), this;
577
+ removeByMulti(e) {
578
+ const o = this.multiToSingleMap.get(e), i = this.singleToMultiMap.get(o);
579
+ i.delete(e), i.size === 0 && this.singleToMultiMap.delete(o), this.multiToSingleMap.delete(e);
1217
580
  }
1218
- /**
1219
- * updates port and edges attached to it
1220
- */
1221
- updatePort(e, o) {
1222
- if (this.graph.getPort(e) === null)
1223
- throw new S("failed to update nonexistent port");
1224
- return this.graphStore.updatePort(e, o ?? {}), this;
581
+ getByMulti(e) {
582
+ return this.multiToSingleMap.get(e);
1225
583
  }
1226
- /**
1227
- * unmarks specified port
1228
- * all the edges adjacent to the port get removed
1229
- */
1230
- unmarkPort(e) {
1231
- if (this.graph.getPort(e) === null)
1232
- throw new S("failed to unmark non existing port");
1233
- return this.graphStore.removePort(e), this;
1234
- }
1235
- /**
1236
- * adds new edge
1237
- */
1238
- addEdge(e) {
1239
- const o = this.edgeIdGenerator.create(e.id);
1240
- if (this.graph.getEdge(o) !== null)
1241
- throw new S("failed to add edge with existing id");
1242
- if (this.graph.getPort(e.from) === null)
1243
- throw new S("failed to add edge from nonexistent port");
1244
- if (this.graph.getPort(e.to) === null)
1245
- throw new S("failed to add edge to nonexistent port");
1246
- return this.graphStore.addEdge({
1247
- id: o,
1248
- from: e.from,
1249
- to: e.to,
1250
- shape: e.shape ?? this.defaults.edges.shapeFactory(o),
1251
- priority: e.priority ?? this.defaults.edges.priorityFn()
1252
- }), this;
1253
- }
1254
- /**
1255
- * updates specified edge
1256
- */
1257
- updateEdge(e, o) {
1258
- if (this.graph.getEdge(e) === null)
1259
- throw new S("failed to update nonexistent edge");
1260
- return this.graphStore.updateEdge(e, o ?? {}), this;
1261
- }
1262
- /**
1263
- * removes specified edge
1264
- */
1265
- removeEdge(e) {
1266
- if (this.graph.getEdge(e) === null)
1267
- throw new S("failed to remove nonexistent edge");
1268
- return this.graphStore.removeEdge(e), this;
1269
- }
1270
- /**
1271
- * applies transformation for viewport matrix
1272
- */
1273
- patchViewportMatrix(e) {
1274
- return this.viewportStore.patchViewportMatrix(e), this;
1275
- }
1276
- /**
1277
- * applies transformation for content matrix
1278
- */
1279
- patchContentMatrix(e) {
1280
- return this.viewportStore.patchContentMatrix(e), this;
1281
- }
1282
- /**
1283
- * clears canvas from nodes and edges
1284
- * canvas gets rolled back to initial state and can be reused
1285
- */
1286
- clear() {
1287
- return this.graphStore.clear(), this;
1288
- }
1289
- /**
1290
- * destroys canvas
1291
- * canvas element gets rolled back to initial state, and can not be reused
1292
- */
1293
- destroy() {
1294
- this.clear(), this.onBeforeDestroyEmitter.emit(), this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.unsubscribe(
1295
- this.onAfterNodePriorityUpdated
1296
- ), this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved), this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated), this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked), this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded), this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(
1297
- this.onAfterEdgeShapeUpdated
1298
- ), this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(
1299
- this.onAfterEdgePriorityUpdated
1300
- ), this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear), this.htmlView.destroy();
1301
- }
1302
- }
1303
- class de {
1304
- constructor() {
1305
- r(this, "singleToMultiMap", /* @__PURE__ */ new Map());
1306
- r(this, "multiToSingleMap", /* @__PURE__ */ new Map());
1307
- }
1308
- addRecord(e, o) {
1309
- const i = this.singleToMultiMap.get(e);
1310
- i === void 0 ? this.singleToMultiMap.set(e, /* @__PURE__ */ new Set([o])) : i.add(o), this.multiToSingleMap.set(o, e);
1311
- }
1312
- getMultiBySingle(e) {
1313
- const o = this.singleToMultiMap.get(e) ?? /* @__PURE__ */ new Set();
1314
- return Array.from(o.values());
1315
- }
1316
- removeByMulti(e) {
1317
- const o = this.multiToSingleMap.get(e), i = this.singleToMultiMap.get(o);
1318
- i.delete(e), i.size === 0 && this.singleToMultiMap.delete(o), this.multiToSingleMap.delete(e);
1319
- }
1320
- getByMulti(e) {
1321
- return this.multiToSingleMap.get(e);
1322
- }
1323
- removeBySingle(e) {
1324
- this.singleToMultiMap.get(e).forEach((i) => {
1325
- this.multiToSingleMap.delete(i);
1326
- }), this.singleToMultiMap.delete(e);
584
+ removeBySingle(e) {
585
+ this.singleToMultiMap.get(e).forEach((i) => {
586
+ this.multiToSingleMap.delete(i);
587
+ }), this.singleToMultiMap.delete(e);
1327
588
  }
1328
589
  clear() {
1329
590
  this.singleToMultiMap.clear(), this.multiToSingleMap.clear();
@@ -1340,15 +601,16 @@ class de {
1340
601
  return this.multiToSingleMap.get(e) !== void 0;
1341
602
  }
1342
603
  }
1343
- class ce {
604
+ class de {
1344
605
  constructor() {
1345
606
  r(this, "nodes", /* @__PURE__ */ new Map());
1346
607
  r(this, "ports", /* @__PURE__ */ new Map());
1347
608
  r(this, "edges", /* @__PURE__ */ new Map());
609
+ r(this, "nodesElementsMap", /* @__PURE__ */ new Map());
1348
610
  r(this, "incomingEdges", /* @__PURE__ */ new Map());
1349
611
  r(this, "outcomingEdges", /* @__PURE__ */ new Map());
1350
612
  r(this, "cycleEdges", /* @__PURE__ */ new Map());
1351
- r(this, "elementPorts", new de());
613
+ r(this, "elementPorts", new he());
1352
614
  r(this, "afterNodeAddedEmitter");
1353
615
  r(this, "onAfterNodeAdded");
1354
616
  r(this, "afterNodeUpdatedEmitter");
@@ -1386,7 +648,7 @@ class ce {
1386
648
  priority: e.priority,
1387
649
  ports: o
1388
650
  };
1389
- this.nodes.set(e.id, i), this.afterNodeAddedEmitter.emit(e.id);
651
+ this.nodes.set(e.id, i), this.nodesElementsMap.set(e.element, e.id), this.afterNodeAddedEmitter.emit(e.id);
1390
652
  }
1391
653
  getAllNodeIds() {
1392
654
  return Array.from(this.nodes.keys());
@@ -1394,12 +656,17 @@ class ce {
1394
656
  getNode(e) {
1395
657
  return this.nodes.get(e);
1396
658
  }
659
+ getElementNodeId(e) {
660
+ return this.nodesElementsMap.get(e);
661
+ }
1397
662
  updateNode(e, o) {
1398
663
  const i = this.nodes.get(e);
1399
664
  i.x = o.x ?? i.x, i.y = o.y ?? i.y, i.centerFn = o.centerFn ?? i.centerFn, o.priority !== void 0 && (i.priority = o.priority, this.afterNodePriorityUpdatedEmitter.emit(e)), this.afterNodeUpdatedEmitter.emit(e);
1400
665
  }
1401
666
  removeNode(e) {
1402
- this.beforeNodeRemovedEmitter.emit(e), this.nodes.delete(e);
667
+ this.beforeNodeRemovedEmitter.emit(e);
668
+ const o = this.nodes.get(e);
669
+ this.nodesElementsMap.delete(o.element), this.nodes.delete(e);
1403
670
  }
1404
671
  addPort(e) {
1405
672
  this.ports.set(e.id, {
@@ -1457,7 +724,7 @@ class ce {
1457
724
  this.beforeEdgeRemovedEmitter.emit(e), this.removeEdgeInternal(e);
1458
725
  }
1459
726
  clear() {
1460
- this.beforeClearEmitter.emit(), this.incomingEdges.clear(), this.outcomingEdges.clear(), this.cycleEdges.clear(), this.edges.clear(), this.ports.clear(), this.nodes.clear();
727
+ this.beforeClearEmitter.emit(), this.incomingEdges.clear(), this.outcomingEdges.clear(), this.cycleEdges.clear(), this.elementPorts.clear(), this.nodesElementsMap.clear(), this.edges.clear(), this.ports.clear(), this.nodes.clear();
1461
728
  }
1462
729
  getPortIncomingEdgeIds(e) {
1463
730
  return Array.from(this.incomingEdges.get(e));
@@ -1516,19 +783,19 @@ class ce {
1516
783
  this.cycleEdges.get(i).delete(e), this.cycleEdges.get(s).delete(e), this.incomingEdges.get(i).delete(e), this.incomingEdges.get(s).delete(e), this.outcomingEdges.get(i).delete(e), this.outcomingEdges.get(s).delete(e), this.edges.delete(e);
1517
784
  }
1518
785
  }
1519
- const te = (t) => ({
786
+ const K = (t) => ({
1520
787
  scale: 1 / t.scale,
1521
788
  x: -t.x / t.scale,
1522
789
  y: -t.y / t.scale
1523
- }), oe = {
790
+ }), Q = {
1524
791
  scale: 1,
1525
792
  x: 0,
1526
793
  y: 0
1527
794
  };
1528
- class ze {
795
+ class Ae {
1529
796
  constructor() {
1530
- r(this, "viewportMatrix", oe);
1531
- r(this, "contentMatrix", oe);
797
+ r(this, "viewportMatrix", Q);
798
+ r(this, "contentMatrix", Q);
1532
799
  r(this, "afterUpdateEmitter");
1533
800
  r(this, "onAfterUpdated");
1534
801
  r(this, "beforeUpdateEmitter");
@@ -1546,17 +813,17 @@ class ze {
1546
813
  scale: e.scale ?? this.viewportMatrix.scale,
1547
814
  x: e.x ?? this.viewportMatrix.x,
1548
815
  y: e.y ?? this.viewportMatrix.y
1549
- }, this.contentMatrix = te(this.viewportMatrix), this.afterUpdateEmitter.emit();
816
+ }, this.contentMatrix = K(this.viewportMatrix), this.afterUpdateEmitter.emit();
1550
817
  }
1551
818
  patchContentMatrix(e) {
1552
819
  this.beforeUpdateEmitter.emit(), this.contentMatrix = {
1553
820
  scale: e.scale ?? this.contentMatrix.scale,
1554
821
  x: e.x ?? this.contentMatrix.x,
1555
822
  y: e.y ?? this.contentMatrix.y
1556
- }, this.viewportMatrix = te(this.contentMatrix), this.afterUpdateEmitter.emit();
823
+ }, this.viewportMatrix = K(this.contentMatrix), this.afterUpdateEmitter.emit();
1557
824
  }
1558
825
  }
1559
- class z {
826
+ class F {
1560
827
  constructor(e) {
1561
828
  r(this, "elementToNodeId", /* @__PURE__ */ new Map());
1562
829
  r(this, "nodesResizeObserver");
@@ -1582,37 +849,37 @@ class z {
1582
849
  }), 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);
1583
850
  }
1584
851
  static configure(e) {
1585
- new z(e);
852
+ new F(e);
1586
853
  }
1587
854
  handleNodeResize(e) {
1588
855
  const o = this.elementToNodeId.get(e);
1589
856
  this.canvas.updateNode(o);
1590
857
  }
1591
858
  }
1592
- const Oe = (t) => {
859
+ const Ee = (t) => {
1593
860
  var g, y, p, f, A, E;
1594
861
  const e = ((g = t == null ? void 0 : t.events) == null ? void 0 : g.onNodeDrag) ?? (() => {
1595
862
  }), o = ((y = t == null ? void 0 : t.events) == null ? void 0 : y.onBeforeNodeDrag) ?? (() => !0), i = ((p = t == null ? void 0 : t.events) == null ? void 0 : p.onNodeDragFinished) ?? (() => {
1596
- }), s = (t == null ? void 0 : t.moveOnTop) === !1, h = (f = t == null ? void 0 : t.mouse) == null ? void 0 : f.dragCursor, n = h !== void 0 ? h : "grab", d = (A = t == null ? void 0 : t.mouse) == null ? void 0 : A.mouseDownEventVerifier, c = d !== void 0 ? d : (b) => b.button === 0, a = (E = t == null ? void 0 : t.mouse) == null ? void 0 : E.mouseUpEventVerifier;
863
+ }), s = (t == null ? void 0 : t.moveOnTop) === !1, h = (f = t == null ? void 0 : t.mouse) == null ? void 0 : f.dragCursor, n = h !== void 0 ? h : "grab", d = (A = t == null ? void 0 : t.mouse) == null ? void 0 : A.mouseDownEventVerifier, c = d !== void 0 ? d : (m) => m.button === 0, a = (E = t == null ? void 0 : t.mouse) == null ? void 0 : E.mouseUpEventVerifier;
1597
864
  return {
1598
865
  freezePriority: s,
1599
866
  dragCursor: n,
1600
867
  mouseDownEventVerifier: c,
1601
- mouseUpEventVerifier: a !== void 0 ? a : (b) => b.button === 0,
868
+ mouseUpEventVerifier: a !== void 0 ? a : (m) => m.button === 0,
1602
869
  onNodeDrag: e,
1603
870
  onBeforeNodeDrag: o,
1604
871
  onNodeDragFinished: i
1605
872
  };
1606
- }, Xe = (t, e, o) => {
873
+ }, xe = (t, e, o) => {
1607
874
  const { x: i, y: s, width: h, height: n } = t.getBoundingClientRect();
1608
875
  return e >= i && e <= i + h && o >= s && o <= s + n;
1609
- }, Ye = (t, e, o) => e >= 0 && e <= t.innerWidth && o >= 0 && o <= t.innerHeight, M = (t, e, o, i) => Xe(e, o, i) && Ye(t, o, i), B = (t, e) => {
876
+ }, Se = (t, e, o) => e >= 0 && e <= t.innerWidth && o >= 0 && o <= t.innerHeight, M = (t, e, o, i) => xe(e, o, i) && Se(t, o, i), B = (t, e) => {
1610
877
  e !== null ? t.style.cursor = e : t.style.removeProperty("cursor");
1611
878
  }, N = (t, e) => ({
1612
879
  x: t.scale * e.x + t.x,
1613
880
  y: t.scale * e.y + t.y
1614
881
  });
1615
- class O {
882
+ class k {
1616
883
  constructor(e, o, i, s) {
1617
884
  r(this, "grabbedNodeId", null);
1618
885
  r(this, "maxNodePriority", 0);
@@ -1719,10 +986,10 @@ class O {
1719
986
  this.previousTouchCoordinates = null, this.cancelTouchDrag();
1720
987
  });
1721
988
  r(this, "config");
1722
- this.canvas = e, this.element = o, this.window = i, this.config = Oe(s), 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);
989
+ this.canvas = e, this.element = o, this.window = i, this.config = Ee(s), 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);
1723
990
  }
1724
991
  static configure(e, o, i, s) {
1725
- new O(e, o, i, s);
992
+ new k(e, o, i, s);
1726
993
  }
1727
994
  dragNode(e, o, i) {
1728
995
  const s = this.graph.getNode(e);
@@ -1781,7 +1048,7 @@ class O {
1781
1048
  this.maxNodePriority = Math.max(this.maxNodePriority, o);
1782
1049
  }
1783
1050
  }
1784
- const He = (t) => {
1051
+ const me = (t) => {
1785
1052
  const e = t.minX !== null ? t.minX : -1 / 0, o = t.maxX !== null ? t.maxX : 1 / 0, i = t.minY !== null ? t.minY : -1 / 0, s = t.maxY !== null ? t.maxY : 1 / 0;
1786
1053
  return (h) => {
1787
1054
  let n = h.nextTransform.x, d = h.nextTransform.y;
@@ -1791,7 +1058,7 @@ const He = (t) => {
1791
1058
  const l = h.canvasHeight * h.prevTransform.scale, g = s - l;
1792
1059
  return d > g && d > h.prevTransform.y && (d = Math.max(h.prevTransform.y, g)), { scale: h.nextTransform.scale, x: n, y: d };
1793
1060
  };
1794
- }, je = (t) => {
1061
+ }, be = (t) => {
1795
1062
  const e = t.maxContentScale, o = t.minContentScale, i = e !== null ? 1 / e : 0, s = o !== null ? 1 / o : 1 / 0;
1796
1063
  return (h) => {
1797
1064
  const n = h.prevTransform, d = h.nextTransform;
@@ -1812,7 +1079,7 @@ const He = (t) => {
1812
1079
  y: l
1813
1080
  };
1814
1081
  };
1815
- }, Ge = (t) => (e) => t.reduce(
1082
+ }, Te = (t) => (e) => t.reduce(
1816
1083
  (o, i) => i({
1817
1084
  prevTransform: e.prevTransform,
1818
1085
  nextTransform: o,
@@ -1820,35 +1087,35 @@ const He = (t) => {
1820
1087
  canvasHeight: e.canvasHeight
1821
1088
  }),
1822
1089
  e.nextTransform
1823
- ), re = (t) => {
1090
+ ), _ = (t) => {
1824
1091
  if (typeof t == "function")
1825
1092
  return t;
1826
1093
  switch (t.type) {
1827
1094
  case "scale-limit":
1828
- return je({
1095
+ return be({
1829
1096
  minContentScale: t.minContentScale ?? 0,
1830
1097
  maxContentScale: t.maxContentScale ?? 1 / 0
1831
1098
  });
1832
1099
  case "shift-limit":
1833
- return He({
1100
+ return me({
1834
1101
  minX: t.minX ?? -1 / 0,
1835
1102
  maxX: t.maxX ?? 1 / 0,
1836
1103
  minY: t.minY ?? -1 / 0,
1837
1104
  maxY: t.maxY ?? 1 / 0
1838
1105
  });
1839
1106
  }
1840
- }, Ze = (t) => {
1841
- var f, A, E, b, T, m, D, L, j, G, Z, J;
1107
+ }, Pe = (t) => {
1108
+ var f, A, E, m, T, b, D, L, j, G, Z, J;
1842
1109
  const e = (f = t == null ? void 0 : t.scale) == null ? void 0 : f.mouseWheelSensitivity, o = e !== void 0 ? e : 1.2, i = t == null ? void 0 : t.transformPreprocessor;
1843
1110
  let s;
1844
- i !== void 0 ? Array.isArray(i) ? s = Ge(
1111
+ i !== void 0 ? Array.isArray(i) ? s = Te(
1845
1112
  i.map(
1846
- (P) => re(P)
1113
+ (P) => _(P)
1847
1114
  )
1848
- ) : s = re(i) : s = (P) => P.nextTransform;
1115
+ ) : s = _(i) : s = (P) => P.nextTransform;
1849
1116
  const h = ((A = t == null ? void 0 : t.shift) == null ? void 0 : A.cursor) !== void 0 ? t.shift.cursor : "grab", n = ((E = t == null ? void 0 : t.events) == null ? void 0 : E.onBeforeTransformChange) ?? (() => {
1850
- }), d = ((b = t == null ? void 0 : t.events) == null ? void 0 : b.onTransformChange) ?? (() => {
1851
- }), c = (T = t == null ? void 0 : t.shift) == null ? void 0 : T.mouseDownEventVerifier, a = c !== void 0 ? c : (P) => P.button === 0, l = (m = t == null ? void 0 : t.shift) == null ? void 0 : m.mouseUpEventVerifier, g = l !== void 0 ? l : (P) => P.button === 0, y = (D = t == null ? void 0 : t.scale) == null ? void 0 : D.mouseWheelEventVerifier, p = y !== void 0 ? y : () => !0;
1117
+ }), d = ((m = t == null ? void 0 : t.events) == null ? void 0 : m.onTransformChange) ?? (() => {
1118
+ }), c = (T = t == null ? void 0 : t.shift) == null ? void 0 : T.mouseDownEventVerifier, a = c !== void 0 ? c : (P) => P.button === 0, l = (b = t == null ? void 0 : t.shift) == null ? void 0 : b.mouseUpEventVerifier, g = l !== void 0 ? l : (P) => P.button === 0, y = (D = t == null ? void 0 : t.scale) == null ? void 0 : D.mouseWheelEventVerifier, p = y !== void 0 ? y : () => !0;
1852
1119
  return {
1853
1120
  wheelSensitivity: o,
1854
1121
  onTransformStarted: ((L = t == null ? void 0 : t.events) == null ? void 0 : L.onTransformStarted) ?? (() => {
@@ -1868,11 +1135,11 @@ const He = (t) => {
1868
1135
  onResizeTransformFinished: ((J = t == null ? void 0 : t.events) == null ? void 0 : J.onResizeTransformFinished) ?? (() => {
1869
1136
  })
1870
1137
  };
1871
- }, Je = (t, e, o) => ({
1138
+ }, Ne = (t, e, o) => ({
1872
1139
  scale: t.scale,
1873
1140
  x: t.x + t.scale * e,
1874
1141
  y: t.y + t.scale * o
1875
- }), Ke = (t, e, o, i) => ({
1142
+ }), Me = (t, e, o, i) => ({
1876
1143
  scale: t.scale * e,
1877
1144
  x: t.scale * (1 - e) * o + t.x,
1878
1145
  y: t.scale * (1 - e) * i + t.y
@@ -1895,7 +1162,7 @@ const He = (t) => {
1895
1162
  touches: e
1896
1163
  };
1897
1164
  };
1898
- class U {
1165
+ class I {
1899
1166
  constructor(e, o, i, s) {
1900
1167
  r(this, "viewport");
1901
1168
  r(this, "prevTouches", null);
@@ -1984,7 +1251,7 @@ class U {
1984
1251
  });
1985
1252
  this.canvas = e, this.element = o, this.window = i, this.element.addEventListener("wheel", this.preventWheelScaleListener, {
1986
1253
  passive: !1
1987
- }), this.config = Ze(s), this.viewport = e.viewport, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown, {
1254
+ }), this.config = Pe(s), this.viewport = e.viewport, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown, {
1988
1255
  passive: !0
1989
1256
  }), this.element.addEventListener("wheel", this.onWheelScroll, {
1990
1257
  passive: !0
@@ -1993,7 +1260,7 @@ class U {
1993
1260
  }), e.onBeforeDestroy.subscribe(this.onBeforeDestroy);
1994
1261
  }
1995
1262
  static configure(e, o, i, s) {
1996
- new U(
1263
+ new I(
1997
1264
  e,
1998
1265
  o,
1999
1266
  i,
@@ -2001,7 +1268,7 @@ class U {
2001
1268
  );
2002
1269
  }
2003
1270
  moveViewport(e, o) {
2004
- const i = this.viewport.getViewportMatrix(), s = Je(i, e, o), { width: h, height: n } = this.element.getBoundingClientRect(), d = this.config.transformPreprocessor({
1271
+ const i = this.viewport.getViewportMatrix(), s = Ne(i, e, o), { width: h, height: n } = this.element.getBoundingClientRect(), d = this.config.transformPreprocessor({
2005
1272
  prevTransform: i,
2006
1273
  nextTransform: s,
2007
1274
  canvasWidth: h,
@@ -2010,7 +1277,7 @@ class U {
2010
1277
  this.performTransform(d);
2011
1278
  }
2012
1279
  scaleViewport(e, o, i) {
2013
- const s = this.canvas.viewport.getViewportMatrix(), h = Ke(s, e, o, i), { width: n, height: d } = this.element.getBoundingClientRect(), c = this.config.transformPreprocessor({
1280
+ const s = this.canvas.viewport.getViewportMatrix(), h = Me(s, e, o, i), { width: n, height: d } = this.element.getBoundingClientRect(), c = this.config.transformPreprocessor({
2014
1281
  prevTransform: s,
2015
1282
  nextTransform: h,
2016
1283
  canvasWidth: n,
@@ -2040,7 +1307,7 @@ class U {
2040
1307
  this.transformInProgress = !1, this.config.onTransformFinished();
2041
1308
  }
2042
1309
  }
2043
- class X {
1310
+ class z {
2044
1311
  constructor(e, o, i, s, h, n) {
2045
1312
  r(this, "canvasResizeObserver");
2046
1313
  r(this, "nodeHorizontal");
@@ -2072,16 +1339,16 @@ class X {
2072
1339
  this.userTransformInProgress || (this.viewportMatrix = this.viewport.getViewportMatrix(), this.loadAreaAroundViewport());
2073
1340
  });
2074
1341
  r(this, "userTransformInProgress", !1);
2075
- var p, f, A, E, b;
1342
+ var p, f, A, E, m;
2076
1343
  this.canvas = e, this.element = o, this.window = i, this.trigger = h, this.virtualScrollOptions = n, this.nodeHorizontal = this.virtualScrollOptions.nodeContainingRadius.horizontal, this.nodeVertical = this.virtualScrollOptions.nodeContainingRadius.vertical, this.canvasResizeObserver = new ResizeObserver((T) => {
2077
- const m = T[0];
2078
- this.viewportWidth = m.contentRect.width, this.viewportHeight = m.contentRect.height, this.scheduleLoadAreaAroundViewport();
1344
+ const b = T[0];
1345
+ this.viewportWidth = b.contentRect.width, this.viewportHeight = b.contentRect.height, this.scheduleLoadAreaAroundViewport();
2079
1346
  }), this.viewport = e.viewport;
2080
1347
  const d = ((p = s == null ? void 0 : s.events) == null ? void 0 : p.onResizeTransformStarted) ?? (() => {
2081
1348
  }), c = ((f = s == null ? void 0 : s.events) == null ? void 0 : f.onResizeTransformFinished) ?? (() => {
2082
1349
  }), a = ((A = s == null ? void 0 : s.events) == null ? void 0 : A.onTransformChange) ?? (() => {
2083
1350
  }), l = ((E = s == null ? void 0 : s.events) == null ? void 0 : E.onBeforeTransformChange) ?? (() => {
2084
- }), g = ((b = s == null ? void 0 : s.events) == null ? void 0 : b.onTransformFinished) ?? (() => {
1351
+ }), g = ((m = s == null ? void 0 : s.events) == null ? void 0 : m.onTransformFinished) ?? (() => {
2085
1352
  }), y = {
2086
1353
  ...s,
2087
1354
  events: {
@@ -2105,7 +1372,7 @@ class X {
2105
1372
  }
2106
1373
  }
2107
1374
  };
2108
- U.configure(
1375
+ I.configure(
2109
1376
  e,
2110
1377
  this.element,
2111
1378
  this.window,
@@ -2113,7 +1380,7 @@ class X {
2113
1380
  ), 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);
2114
1381
  }
2115
1382
  static configure(e, o, i, s, h, n) {
2116
- new X(
1383
+ new z(
2117
1384
  e,
2118
1385
  o,
2119
1386
  i,
@@ -2136,29 +1403,29 @@ class X {
2136
1403
  this.trigger.emit({ x: i, y: s, width: h, height: n });
2137
1404
  }
2138
1405
  }
2139
- const Qe = () => {
1406
+ const De = () => {
2140
1407
  const t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2141
1408
  return t.style.position = "absolute", t.style.inset = "0", t;
2142
- }, _e = () => {
1409
+ }, Le = () => {
2143
1410
  const t = document.createElementNS("http://www.w3.org/2000/svg", "rect");
2144
1411
  return t.setAttribute("fill", "url(#pattern)"), t;
2145
- }, qe = () => {
1412
+ }, Ve = () => {
2146
1413
  const t = document.createElementNS(
2147
1414
  "http://www.w3.org/2000/svg",
2148
1415
  "pattern"
2149
1416
  );
2150
1417
  return t.setAttribute("id", "pattern"), t;
2151
- }, et = (t, e) => {
1418
+ }, Re = (t, e) => {
2152
1419
  const o = document.createElementNS(
2153
1420
  "http://www.w3.org/2000/svg",
2154
1421
  "circle"
2155
1422
  );
2156
1423
  return o.setAttribute("cx", "0"), o.setAttribute("cy", "0"), o.setAttribute("r", `${t}`), o.setAttribute("fill", `${e}`), o;
2157
- }, tt = (t) => t instanceof SVGElement ? t : et(
1424
+ }, Be = (t) => t instanceof SVGElement ? t : Re(
2158
1425
  (t == null ? void 0 : t.radius) ?? 1.5,
2159
1426
  (t == null ? void 0 : t.color) ?? "#d8d8d8"
2160
- ), ot = (t) => {
2161
- const e = t.tileDimensions, o = (e == null ? void 0 : e.width) ?? 25, i = (e == null ? void 0 : e.height) ?? 25, s = tt(t.renderer ?? {});
1427
+ ), Ie = (t) => {
1428
+ const e = t.tileDimensions, o = (e == null ? void 0 : e.width) ?? 25, i = (e == null ? void 0 : e.height) ?? 25, s = Be(t.renderer ?? {});
2162
1429
  return {
2163
1430
  tileWidth: o,
2164
1431
  tileHeight: i,
@@ -2166,11 +1433,11 @@ const Qe = () => {
2166
1433
  maxViewportScale: t.maxViewportScale ?? 10
2167
1434
  };
2168
1435
  };
2169
- class Y {
1436
+ class O {
2170
1437
  constructor(e, o, i) {
2171
- r(this, "svg", Qe());
2172
- r(this, "patternRenderingRectangle", _e());
2173
- r(this, "pattern", qe());
1438
+ r(this, "svg", De());
1439
+ r(this, "patternRenderingRectangle", Le());
1440
+ r(this, "pattern", Ve());
2174
1441
  r(this, "patternContent");
2175
1442
  r(this, "tileWidth");
2176
1443
  r(this, "tileHeight");
@@ -2194,7 +1461,7 @@ class Y {
2194
1461
  ), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
2195
1462
  });
2196
1463
  this.canvas = e, this.host = i;
2197
- const s = ot(o);
1464
+ const s = Ie(o);
2198
1465
  this.tileWidth = s.tileWidth, this.tileHeight = s.tileHeight, this.halfTileWidth = this.tileWidth / 2, this.halfTileHeight = this.tileHeight / 2, this.patternContent = s.renderer, this.maxViewportScale = s.maxViewportScale;
2199
1466
  const h = `translate(${this.halfTileWidth}, ${this.halfTileHeight})`;
2200
1467
  this.patternContent.setAttribute("transform", h), this.pattern.appendChild(this.patternContent);
@@ -2202,14 +1469,14 @@ class Y {
2202
1469
  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);
2203
1470
  }
2204
1471
  static configure(e, o, i) {
2205
- new Y(e, o, i);
1472
+ new O(e, o, i);
2206
1473
  }
2207
1474
  updateVisibility() {
2208
1475
  const o = this.canvas.viewport.getViewportMatrix().scale > this.maxViewportScale;
2209
1476
  o && this.visible ? (this.visible = !1, this.host.removeChild(this.svg)) : !o && !this.visible && (this.visible = !0, this.host.appendChild(this.svg));
2210
1477
  }
2211
1478
  }
2212
- const rt = (t) => {
1479
+ const Ue = (t) => {
2213
1480
  var d, c, a;
2214
1481
  const e = () => "direct", o = (l) => l, i = (l) => l.button === 0, s = () => {
2215
1482
  }, h = () => {
@@ -2226,11 +1493,11 @@ const rt = (t) => {
2226
1493
  dragPortDirection: t.dragPortDirection ?? void 0
2227
1494
  };
2228
1495
  };
2229
- class H {
1496
+ class X {
2230
1497
  constructor(e, o, i, s, h, n) {
2231
1498
  r(this, "config");
2232
1499
  r(this, "overlayCanvas");
2233
- r(this, "ports", new de());
1500
+ r(this, "ports", new he());
2234
1501
  r(this, "staticOverlayPortId", "static");
2235
1502
  r(this, "draggingOverlayPortId", "dragging");
2236
1503
  r(this, "staticPortId", null);
@@ -2310,13 +1577,13 @@ class H {
2310
1577
  r(this, "onEdgeCreated", (e) => {
2311
1578
  this.config.onAfterEdgeCreated(e);
2312
1579
  });
2313
- this.canvas = e, this.overlayLayer = o, this.viewportStore = i, this.window = s, this.config = rt(n);
2314
- const d = new ce(), c = new ie(
1580
+ this.canvas = e, this.overlayLayer = o, this.viewportStore = i, this.window = s, this.config = Ue(n);
1581
+ const d = new de(), c = new ie(
2315
1582
  d,
2316
1583
  this.viewportStore,
2317
1584
  this.overlayLayer
2318
1585
  );
2319
- this.overlayCanvas = new he(
1586
+ this.overlayCanvas = new ne(
2320
1587
  this.overlayLayer,
2321
1588
  d,
2322
1589
  this.viewportStore,
@@ -2325,7 +1592,7 @@ class H {
2325
1592
  ), 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);
2326
1593
  }
2327
1594
  static configure(e, o, i, s, h, n) {
2328
- new H(
1595
+ new X(
2329
1596
  e,
2330
1597
  o,
2331
1598
  i,
@@ -2334,130 +1601,871 @@ class H {
2334
1601
  n
2335
1602
  );
2336
1603
  }
2337
- grabPort(e, o) {
2338
- const i = this.ports.getMultiBySingle(e)[0], s = this.canvas.graph.getPort(i);
2339
- this.staticPortId = i;
2340
- const h = this.config.connectionTypeResolver(this.staticPortId), n = e.getBoundingClientRect(), d = n.x + n.width / 2, c = n.y + n.height / 2, a = this.overlayLayer.getBoundingClientRect(), l = this.canvas.viewport.getViewportMatrix(), g = N(l, {
2341
- x: d - a.x,
2342
- y: c - a.y
2343
- }), y = N(l, {
2344
- x: o.x - a.x,
2345
- y: o.y - a.y
2346
- }), p = {
2347
- overlayId: this.staticOverlayPortId,
2348
- portCoords: g,
2349
- portDirection: s.direction
2350
- }, f = {
2351
- overlayId: this.draggingOverlayPortId,
2352
- portCoords: y,
2353
- portDirection: this.config.dragPortDirection
1604
+ grabPort(e, o) {
1605
+ const i = this.ports.getMultiBySingle(e)[0], s = this.canvas.graph.getPort(i);
1606
+ this.staticPortId = i;
1607
+ const h = this.config.connectionTypeResolver(this.staticPortId), n = e.getBoundingClientRect(), d = n.x + n.width / 2, c = n.y + n.height / 2, a = this.overlayLayer.getBoundingClientRect(), l = this.canvas.viewport.getViewportMatrix(), g = N(l, {
1608
+ x: d - a.x,
1609
+ y: c - a.y
1610
+ }), y = N(l, {
1611
+ x: o.x - a.x,
1612
+ y: o.y - a.y
1613
+ }), p = {
1614
+ overlayId: this.staticOverlayPortId,
1615
+ portCoords: g,
1616
+ portDirection: s.direction
1617
+ }, f = {
1618
+ overlayId: this.draggingOverlayPortId,
1619
+ portCoords: y,
1620
+ portDirection: this.config.dragPortDirection
1621
+ };
1622
+ this.isDirect = h === "direct";
1623
+ const A = this.isDirect ? p : f, E = this.isDirect ? f : p;
1624
+ this.createOverlayGraph(A, E);
1625
+ }
1626
+ hookPortEvents(e) {
1627
+ e.addEventListener("mousedown", this.onPortMouseDown, {
1628
+ passive: !0
1629
+ }), e.addEventListener("touchstart", this.onPortTouchStart, {
1630
+ passive: !0
1631
+ });
1632
+ }
1633
+ unhookPortEvents(e) {
1634
+ e.removeEventListener("mousedown", this.onPortMouseDown), e.removeEventListener("touchstart", this.onPortTouchStart);
1635
+ }
1636
+ stopMouseDrag() {
1637
+ this.resetDragState(), this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
1638
+ }
1639
+ stopTouchDrag() {
1640
+ this.resetDragState(), this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
1641
+ }
1642
+ resetDragState() {
1643
+ this.staticPortId = null, this.isDirect = !0, this.overlayCanvas.clear();
1644
+ }
1645
+ createOverlayGraph(e, o) {
1646
+ const i = this.createAddNodeRequest(e);
1647
+ this.overlayCanvas.addNode(i);
1648
+ const s = this.createAddNodeRequest(o);
1649
+ this.overlayCanvas.addNode(s), this.overlayCanvas.addEdge({
1650
+ from: e.overlayId,
1651
+ to: o.overlayId
1652
+ });
1653
+ }
1654
+ createAddNodeRequest(e) {
1655
+ const o = document.createElement("div");
1656
+ return {
1657
+ id: e.overlayId,
1658
+ element: o,
1659
+ x: e.portCoords.x,
1660
+ y: e.portCoords.y,
1661
+ ports: [
1662
+ {
1663
+ id: e.overlayId,
1664
+ element: o,
1665
+ direction: e.portDirection
1666
+ }
1667
+ ]
1668
+ };
1669
+ }
1670
+ tryCreateConnection(e) {
1671
+ const o = this.findPortAtPoint(e);
1672
+ if (o === null) {
1673
+ this.config.onEdgeCreationInterrupted(this.staticPortId, this.isDirect);
1674
+ return;
1675
+ }
1676
+ const i = this.isDirect ? this.staticPortId : o, s = this.isDirect ? o : this.staticPortId, h = { from: i, to: s }, n = this.config.connectionPreprocessor(h);
1677
+ n !== null ? (this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated), this.canvas.addEdge(n), this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)) : this.config.onEdgeCreationPrevented(h);
1678
+ }
1679
+ moveDraggingNode(e) {
1680
+ const o = this.overlayLayer.getBoundingClientRect(), i = {
1681
+ x: e.x - o.x,
1682
+ y: e.y - o.y
1683
+ }, s = this.canvas.viewport.getViewportMatrix(), h = N(s, i);
1684
+ this.overlayCanvas.updateNode(this.draggingOverlayPortId, {
1685
+ x: h.x,
1686
+ y: h.y
1687
+ });
1688
+ }
1689
+ findPortAtPoint(e) {
1690
+ const o = document.elementsFromPoint(e.x, e.y);
1691
+ for (const i of o) {
1692
+ const s = this.findPortAtElement(i);
1693
+ if (s !== null)
1694
+ return s;
1695
+ }
1696
+ return null;
1697
+ }
1698
+ findPortAtElement(e) {
1699
+ let o = e, i = null;
1700
+ for (; o !== null && (i = this.ports.getMultiBySingle(o)[0] ?? null, i === null); )
1701
+ o = o.parentElement;
1702
+ return i;
1703
+ }
1704
+ isPortConnectionAllowed(e) {
1705
+ const o = this.ports.getMultiBySingle(e)[0];
1706
+ return this.config.connectionTypeResolver(o) !== null;
1707
+ }
1708
+ }
1709
+ const Ce = () => {
1710
+ const t = document.createElement("div");
1711
+ return t.style.width = "100%", t.style.height = "100%", t.style.position = "relative", t;
1712
+ }, W = () => {
1713
+ const t = document.createElement("div");
1714
+ return t.style.position = "absolute", t.style.inset = "0", t;
1715
+ };
1716
+ class We {
1717
+ constructor(e) {
1718
+ r(this, "background", W());
1719
+ r(this, "main", W());
1720
+ r(this, "overlay", W());
1721
+ r(this, "host", Ce());
1722
+ 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);
1723
+ }
1724
+ destroy() {
1725
+ this.host.removeChild(this.background), this.host.removeChild(this.main), this.host.removeChild(this.overlay), this.element.removeChild(this.host);
1726
+ }
1727
+ }
1728
+ const $e = (t, e) => ({
1729
+ x: t / 2,
1730
+ y: e / 2
1731
+ }), $ = (t) => () => t, q = $(0), Fe = () => {
1732
+ let t = 0;
1733
+ return () => t++;
1734
+ }, ke = (t, e) => {
1735
+ let o = q, i = q;
1736
+ const s = Fe();
1737
+ return t === "incremental" && (o = s), e === "incremental" && (i = s), typeof t == "number" && (o = $(t)), typeof e == "number" && (i = $(e)), typeof t == "function" && (o = t), typeof e == "function" && (i = e), {
1738
+ nodesPriorityFn: o,
1739
+ edgesPriorityFn: i
1740
+ };
1741
+ }, v = (t, e, o) => ({
1742
+ x: e.x * t.x - e.y * t.y + ((1 - e.x) * o.x + e.y * o.y),
1743
+ y: e.y * t.x + e.x * t.y + ((1 - e.x) * o.y - e.y * o.x)
1744
+ }), w = {
1745
+ x: 0,
1746
+ y: 0
1747
+ }, ze = (t) => {
1748
+ const e = v(
1749
+ { x: t.arrowLength, y: w.y },
1750
+ t.fromVector,
1751
+ w
1752
+ ), o = v(
1753
+ { x: t.to.x - t.arrowLength, y: t.to.y },
1754
+ t.toVector,
1755
+ t.to
1756
+ ), i = {
1757
+ x: e.x + t.fromVector.x * t.curvature,
1758
+ y: e.y + t.fromVector.y * t.curvature
1759
+ }, s = {
1760
+ x: o.x - t.toVector.x * t.curvature,
1761
+ y: o.y - t.toVector.y * t.curvature
1762
+ }, h = `M ${e.x} ${e.y} C ${i.x} ${i.y}, ${s.x} ${s.y}, ${o.x} ${o.y}`, n = t.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${e.x} ${e.y} `, d = t.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${t.to.x} ${t.to.y}`;
1763
+ return `${n}${h}${d}`;
1764
+ }, Oe = (t) => {
1765
+ const e = t.hasSourceArrow ? v(
1766
+ { x: t.arrowLength, y: w.y },
1767
+ t.fromVector,
1768
+ w
1769
+ ) : w, o = t.hasTargetArrow ? v(
1770
+ { x: t.to.x - t.arrowLength, y: t.to.y },
1771
+ t.toVector,
1772
+ t.to
1773
+ ) : t.to, i = t.arrowLength, s = Math.cos(t.detourDirection) * t.detourDistance, h = Math.sin(t.detourDirection) * t.detourDistance, n = s * t.flipX, d = h * t.flipY, c = v(
1774
+ { x: i, y: w.y },
1775
+ t.fromVector,
1776
+ w
1777
+ ), a = {
1778
+ x: c.x + n,
1779
+ y: c.y + d
1780
+ }, l = v(
1781
+ { x: t.to.x - i, y: t.to.y },
1782
+ t.toVector,
1783
+ t.to
1784
+ ), g = {
1785
+ x: l.x + n,
1786
+ y: l.y + d
1787
+ }, y = { x: (a.x + g.x) / 2, y: (a.y + g.y) / 2 }, p = {
1788
+ x: c.x + t.curvature * t.fromVector.x,
1789
+ y: c.y + t.curvature * t.fromVector.y
1790
+ }, f = {
1791
+ x: l.x - t.curvature * t.toVector.x,
1792
+ y: l.y - t.curvature * t.toVector.y
1793
+ }, A = {
1794
+ x: c.x + n,
1795
+ y: c.y + d
1796
+ }, E = {
1797
+ x: l.x + n,
1798
+ y: l.y + d
1799
+ };
1800
+ return [
1801
+ `M ${e.x} ${e.y}`,
1802
+ `L ${c.x} ${c.y}`,
1803
+ `C ${p.x} ${p.y} ${A.x} ${A.y} ${y.x} ${y.y}`,
1804
+ `C ${E.x} ${E.y} ${f.x} ${f.y} ${l.x} ${l.y}`,
1805
+ `L ${o.x} ${o.y}`
1806
+ ].join(" ");
1807
+ }, V = (t, e) => {
1808
+ const o = [];
1809
+ if (t.length > 0 && o.push(`M ${t[0].x} ${t[0].y}`), t.length === 2 && o.push(`L ${t[1].x} ${t[1].y}`), t.length > 2) {
1810
+ const i = t.length - 1;
1811
+ let s = 0, h = 0, n = 0;
1812
+ t.forEach((d, c) => {
1813
+ let a = 0, l = 0, g = 0;
1814
+ const y = c > 0, p = c < i, f = y && p;
1815
+ if (y && (a = -s, l = -h, g = n), p) {
1816
+ const L = t[c + 1];
1817
+ s = L.x - d.x, h = L.y - d.y, n = Math.sqrt(s * s + h * h);
1818
+ }
1819
+ const E = n !== 0 ? Math.min((f ? e : 0) / n, c < i - 1 ? 0.5 : 1) : 0, m = f ? { x: d.x + s * E, y: d.y + h * E } : d, b = g !== 0 ? Math.min((f ? e : 0) / g, c > 1 ? 0.5 : 1) : 0, D = f ? { x: d.x + a * b, y: d.y + l * b } : d;
1820
+ c > 0 && o.push(`L ${D.x} ${D.y}`), f && o.push(
1821
+ `C ${d.x} ${d.y} ${d.x} ${d.y} ${m.x} ${m.y}`
1822
+ );
1823
+ });
1824
+ }
1825
+ return o.join(" ");
1826
+ }, Xe = (t) => {
1827
+ const e = t.hasSourceArrow ? v(
1828
+ { x: t.arrowLength, y: w.y },
1829
+ t.fromVector,
1830
+ w
1831
+ ) : w, o = t.hasTargetArrow ? v(
1832
+ { x: t.to.x - t.arrowLength, y: t.to.y },
1833
+ t.toVector,
1834
+ t.to
1835
+ ) : t.to, i = t.arrowLength + t.arrowOffset, s = i - t.roundness, h = v(
1836
+ { x: s, y: w.y },
1837
+ t.fromVector,
1838
+ w
1839
+ ), n = v(
1840
+ { x: t.to.x - s, y: t.to.y },
1841
+ t.toVector,
1842
+ t.to
1843
+ ), d = Math.max((h.x + n.x) / 2, i), c = t.to.y / 2, a = {
1844
+ x: t.flipX > 0 ? d : -i,
1845
+ y: h.y
1846
+ }, l = { x: a.x, y: c }, g = {
1847
+ x: t.flipX > 0 ? t.to.x - d : t.to.x + i,
1848
+ y: n.y
1849
+ }, y = { x: g.x, y: c };
1850
+ return V(
1851
+ [e, h, a, l, y, g, n, o],
1852
+ t.roundness
1853
+ );
1854
+ }, Y = (t) => {
1855
+ const e = t.hasSourceArrow ? v(
1856
+ { x: t.arrowLength, y: w.y },
1857
+ t.fromVector,
1858
+ w
1859
+ ) : w, o = t.hasTargetArrow ? v(
1860
+ { x: t.to.x - t.arrowLength, y: t.to.y },
1861
+ t.toVector,
1862
+ t.to
1863
+ ) : t.to, i = t.arrowLength + t.arrowOffset, s = v(
1864
+ { x: i, y: w.y },
1865
+ t.fromVector,
1866
+ w
1867
+ ), h = Math.cos(t.detourDirection) * t.detourDistance, n = Math.sin(t.detourDirection) * t.detourDistance, d = h * t.flipX, c = n * t.flipY, a = { x: s.x + d, y: s.y + c }, l = v(
1868
+ { x: t.to.x - i, y: t.to.y },
1869
+ t.toVector,
1870
+ t.to
1871
+ ), g = { x: l.x + d, y: l.y + c };
1872
+ return V(
1873
+ [e, s, a, g, l, o],
1874
+ t.roundness
1875
+ );
1876
+ }, Ye = (t) => {
1877
+ const e = t.hasSourceArrow ? v(
1878
+ { x: t.arrowLength, y: w.y },
1879
+ t.fromVector,
1880
+ w
1881
+ ) : w, o = t.hasTargetArrow ? v(
1882
+ { x: t.to.x - t.arrowLength, y: t.to.y },
1883
+ t.toVector,
1884
+ t.to
1885
+ ) : t.to, i = t.arrowLength + t.arrowOffset, s = v(
1886
+ { x: i, y: w.y },
1887
+ t.fromVector,
1888
+ w
1889
+ ), h = v(
1890
+ { x: t.to.x - i, y: t.to.y },
1891
+ t.toVector,
1892
+ t.to
1893
+ );
1894
+ return V([e, s, h, o], t.roundness);
1895
+ }, He = (t) => {
1896
+ const e = t.hasSourceArrow ? v(
1897
+ { x: t.arrowLength, y: w.y },
1898
+ t.fromVector,
1899
+ w
1900
+ ) : w, o = t.hasTargetArrow ? v(
1901
+ { x: t.to.x - t.arrowLength, y: t.to.y },
1902
+ t.toVector,
1903
+ t.to
1904
+ ) : t.to, i = t.arrowLength + t.arrowOffset, s = i - t.roundness, h = v(
1905
+ { x: s, y: w.y },
1906
+ t.fromVector,
1907
+ w
1908
+ ), n = v(
1909
+ { x: t.to.x - s, y: t.to.y },
1910
+ t.toVector,
1911
+ t.to
1912
+ ), d = Math.max((h.y + n.y) / 2, i), c = t.to.x / 2, a = {
1913
+ x: h.x,
1914
+ y: t.flipY > 0 ? d : -i
1915
+ }, l = { x: c, y: a.y }, g = {
1916
+ x: n.x,
1917
+ y: t.flipY > 0 ? t.to.y - d : t.to.y + i
1918
+ }, y = { x: c, y: g.y };
1919
+ return V(
1920
+ [e, h, a, l, y, g, n, o],
1921
+ t.roundness
1922
+ );
1923
+ }, H = (t) => {
1924
+ const e = t.arrowOffset, o = t.side, i = t.arrowLength + e, s = i + 2 * o, n = [
1925
+ { x: t.arrowLength, y: w.y },
1926
+ { x: i, y: w.y },
1927
+ { x: i, y: t.side },
1928
+ { x: s, y: t.side },
1929
+ { x: s, y: -t.side },
1930
+ { x: i, y: -t.side },
1931
+ { x: i, y: w.y },
1932
+ { x: t.arrowLength, y: w.y }
1933
+ ].map(
1934
+ (c) => v(c, t.fromVector, w)
1935
+ ), d = `M ${w.x} ${w.y} L ${n[0].x} ${n[0].y} `;
1936
+ return `${t.hasSourceArrow || t.hasTargetArrow ? "" : d}${V(n, t.roundness)}`;
1937
+ }, je = (t) => {
1938
+ const e = t.smallRadius, o = t.radius, i = Math.sqrt(e * e + o * o), s = e + o, h = t.arrowLength + i * (1 - o / s), n = e * o / s, c = [
1939
+ { x: t.arrowLength, y: w.y },
1940
+ { x: h, y: n },
1941
+ { x: h, y: -n }
1942
+ ].map(
1943
+ (g) => v(g, t.fromVector, w)
1944
+ ), a = [
1945
+ `M ${c[0].x} ${c[0].y}`,
1946
+ `A ${e} ${e} 0 0 1 ${c[1].x} ${c[1].y}`,
1947
+ `A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,
1948
+ `A ${e} ${e} 0 0 1 ${c[0].x} ${c[0].y}`
1949
+ ].join(" "), l = `M 0 0 L ${c[0].x} ${c[0].y} `;
1950
+ return `${t.hasSourceArrow || t.hasTargetArrow ? "" : l}${a}`;
1951
+ }, u = Object.freeze({
1952
+ color: "#777777",
1953
+ width: 1,
1954
+ arrowLength: 15,
1955
+ arrowWidth: 4,
1956
+ arrowOffset: 15,
1957
+ hasSourceArrow: !1,
1958
+ hasTargetArrow: !1,
1959
+ cycleRadius: 30,
1960
+ cycleSquareSide: 30,
1961
+ roundness: 10,
1962
+ detourDistance: 100,
1963
+ detourDirection: -Math.PI / 2,
1964
+ detourDirectionVertical: 0,
1965
+ smallCycleRadius: 15,
1966
+ curvature: 90,
1967
+ interactiveWidth: 10
1968
+ }), ee = (t, e, o, i) => {
1969
+ const h = [
1970
+ w,
1971
+ { x: o, y: i },
1972
+ { x: o, y: -i }
1973
+ ].map((a) => v(a, t, w)).map((a) => ({ x: a.x + e.x, y: a.y + e.y })), n = `M ${h[0].x} ${h[0].y}`, d = `L ${h[1].x} ${h[1].y}`, c = `L ${h[2].x} ${h[2].y}`;
1974
+ return `${n} ${d} ${c} Z`;
1975
+ }, te = (t) => {
1976
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
1977
+ return e.setAttribute("fill", t), e;
1978
+ }, Ge = () => {
1979
+ const t = document.createElementNS("http://www.w3.org/2000/svg", "g");
1980
+ return t.style.transformOrigin = "50% 50%", t;
1981
+ }, Ze = (t, e) => {
1982
+ const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1983
+ return o.setAttribute("stroke", t), o.setAttribute("stroke-width", `${e}`), o.setAttribute("fill", "none"), o;
1984
+ }, Je = (t, e) => {
1985
+ const o = {
1986
+ x: t.x + t.width / 2,
1987
+ y: t.y + t.height / 2
1988
+ }, i = {
1989
+ x: e.x + e.width / 2,
1990
+ y: e.y + e.height / 2
1991
+ }, s = Math.min(o.x, i.x), h = Math.min(o.y, i.y), n = Math.abs(i.x - o.x), d = Math.abs(i.y - o.y), c = o.x <= i.x ? 1 : -1, a = o.y <= i.y ? 1 : -1;
1992
+ return {
1993
+ x: s,
1994
+ y: h,
1995
+ width: n,
1996
+ height: d,
1997
+ flipX: c,
1998
+ flipY: a
1999
+ };
2000
+ }, Ke = () => {
2001
+ const t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
2002
+ return t.style.pointerEvents = "none", t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.overflow = "visible", t;
2003
+ }, oe = (t, e, o) => ({ x: e * Math.cos(t), y: o * Math.sin(t) });
2004
+ class U {
2005
+ constructor(e) {
2006
+ r(this, "svg", Ke());
2007
+ r(this, "group", Ge());
2008
+ r(this, "line");
2009
+ r(this, "sourceArrow", null);
2010
+ r(this, "targetArrow", null);
2011
+ this.params = e, this.svg.appendChild(this.group), this.line = Ze(e.color, e.width), this.group.appendChild(this.line), e.hasSourceArrow && (this.sourceArrow = te(e.color), this.group.appendChild(this.sourceArrow)), e.hasTargetArrow && (this.targetArrow = te(e.color), this.group.appendChild(this.targetArrow));
2012
+ }
2013
+ render(e) {
2014
+ const { x: o, y: i, width: s, height: h, flipX: n, flipY: d } = Je(
2015
+ e.from,
2016
+ e.to
2017
+ );
2018
+ this.svg.style.transform = `translate(${o}px, ${i}px)`, this.svg.style.width = `${Math.max(s, 1)}px`, this.svg.style.height = `${Math.max(h, 1)}px`, this.group.style.transform = `scale(${n}, ${d})`;
2019
+ const c = oe(
2020
+ e.from.direction,
2021
+ n,
2022
+ d
2023
+ ), a = oe(
2024
+ e.to.direction,
2025
+ n,
2026
+ d
2027
+ ), l = {
2028
+ x: s,
2029
+ y: h
2354
2030
  };
2355
- this.isDirect = h === "direct";
2356
- const A = this.isDirect ? p : f, E = this.isDirect ? f : p;
2357
- this.createOverlayGraph(A, E);
2358
- }
2359
- hookPortEvents(e) {
2360
- e.addEventListener("mousedown", this.onPortMouseDown, {
2361
- passive: !0
2362
- }), e.addEventListener("touchstart", this.onPortTouchStart, {
2363
- passive: !0
2364
- });
2365
- }
2366
- unhookPortEvents(e) {
2367
- e.removeEventListener("mousedown", this.onPortMouseDown), e.removeEventListener("touchstart", this.onPortTouchStart);
2368
- }
2369
- stopMouseDrag() {
2370
- this.resetDragState(), this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
2371
- }
2372
- stopTouchDrag() {
2373
- this.resetDragState(), this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
2031
+ let g = a, y = -this.params.arrowLength, p;
2032
+ e.from.portId === e.to.portId ? (p = this.params.createCyclePath, g = c, y = this.params.arrowLength) : e.from.nodeId === e.to.nodeId ? p = this.params.createDetourPath : p = this.params.createLinePath;
2033
+ const f = p(
2034
+ c,
2035
+ a,
2036
+ l,
2037
+ n,
2038
+ d
2039
+ );
2040
+ if (this.line.setAttribute("d", f), this.sourceArrow) {
2041
+ const A = ee(
2042
+ c,
2043
+ w,
2044
+ this.params.arrowLength,
2045
+ this.params.arrowWidth
2046
+ );
2047
+ this.sourceArrow.setAttribute("d", A);
2048
+ }
2049
+ if (this.targetArrow) {
2050
+ const A = ee(
2051
+ g,
2052
+ l,
2053
+ y,
2054
+ this.params.arrowWidth
2055
+ );
2056
+ this.targetArrow.setAttribute("d", A);
2057
+ }
2374
2058
  }
2375
- resetDragState() {
2376
- this.staticPortId = null, this.isDirect = !0, this.overlayCanvas.clear();
2059
+ }
2060
+ class Qe {
2061
+ constructor(e) {
2062
+ r(this, "svg");
2063
+ r(this, "group");
2064
+ r(this, "line");
2065
+ r(this, "sourceArrow");
2066
+ r(this, "targetArrow");
2067
+ r(this, "arrowLength");
2068
+ r(this, "arrowWidth");
2069
+ r(this, "curvature");
2070
+ r(this, "portCycleRadius");
2071
+ r(this, "portCycleSmallRadius");
2072
+ r(this, "detourDirection");
2073
+ r(this, "detourDistance");
2074
+ r(this, "hasSourceArrow");
2075
+ r(this, "hasTargetArrow");
2076
+ r(this, "lineShape");
2077
+ r(this, "createCyclePath", (e) => je({
2078
+ fromVector: e,
2079
+ radius: this.portCycleRadius,
2080
+ smallRadius: this.portCycleSmallRadius,
2081
+ arrowLength: this.arrowLength,
2082
+ hasSourceArrow: this.hasSourceArrow,
2083
+ hasTargetArrow: this.hasTargetArrow
2084
+ }));
2085
+ r(this, "createDetourPath", (e, o, i, s, h) => Oe({
2086
+ to: i,
2087
+ fromVector: e,
2088
+ toVector: o,
2089
+ flipX: s,
2090
+ flipY: h,
2091
+ arrowLength: this.arrowLength,
2092
+ detourDirection: this.detourDirection,
2093
+ detourDistance: this.detourDistance,
2094
+ curvature: this.curvature,
2095
+ hasSourceArrow: this.hasSourceArrow,
2096
+ hasTargetArrow: this.hasTargetArrow
2097
+ }));
2098
+ r(this, "createLinePath", (e, o, i) => ze({
2099
+ to: i,
2100
+ fromVector: e,
2101
+ toVector: o,
2102
+ arrowLength: this.arrowLength,
2103
+ curvature: this.curvature,
2104
+ hasSourceArrow: this.hasSourceArrow,
2105
+ hasTargetArrow: this.hasTargetArrow
2106
+ }));
2107
+ 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.lineShape = new U({
2108
+ color: (e == null ? void 0 : e.color) ?? u.color,
2109
+ width: (e == null ? void 0 : e.width) ?? u.width,
2110
+ arrowLength: this.arrowLength,
2111
+ arrowWidth: this.arrowWidth,
2112
+ hasSourceArrow: this.hasSourceArrow,
2113
+ hasTargetArrow: this.hasTargetArrow,
2114
+ createCyclePath: this.createCyclePath,
2115
+ createDetourPath: this.createDetourPath,
2116
+ createLinePath: this.createLinePath
2117
+ }), this.svg = this.lineShape.svg, this.group = this.lineShape.group, this.line = this.lineShape.line, this.sourceArrow = this.lineShape.sourceArrow, this.targetArrow = this.lineShape.targetArrow;
2377
2118
  }
2378
- createOverlayGraph(e, o) {
2379
- const i = this.createAddNodeRequest(e);
2380
- this.overlayCanvas.addNode(i);
2381
- const s = this.createAddNodeRequest(o);
2382
- this.overlayCanvas.addNode(s), this.overlayCanvas.addEdge({
2383
- from: e.overlayId,
2384
- to: o.overlayId
2385
- });
2119
+ render(e) {
2120
+ this.lineShape.render(e);
2386
2121
  }
2387
- createAddNodeRequest(e) {
2388
- const o = document.createElement("div");
2389
- return {
2390
- id: e.overlayId,
2391
- element: o,
2392
- x: e.portCoords.x,
2393
- y: e.portCoords.y,
2394
- ports: [
2395
- {
2396
- id: e.overlayId,
2397
- element: o,
2398
- direction: e.portDirection
2399
- }
2400
- ]
2401
- };
2122
+ }
2123
+ class _e {
2124
+ constructor(e) {
2125
+ r(this, "svg");
2126
+ r(this, "group");
2127
+ r(this, "line");
2128
+ r(this, "sourceArrow");
2129
+ r(this, "targetArrow");
2130
+ r(this, "arrowLength");
2131
+ r(this, "arrowWidth");
2132
+ r(this, "arrowOffset");
2133
+ r(this, "roundness");
2134
+ r(this, "cycleSquareSide");
2135
+ r(this, "detourDirection");
2136
+ r(this, "detourDistance");
2137
+ r(this, "hasSourceArrow");
2138
+ r(this, "hasTargetArrow");
2139
+ r(this, "lineShape");
2140
+ r(this, "createCyclePath", (e) => H({
2141
+ fromVector: e,
2142
+ arrowLength: this.arrowLength,
2143
+ side: this.cycleSquareSide,
2144
+ arrowOffset: this.arrowOffset,
2145
+ roundness: this.roundness,
2146
+ hasSourceArrow: this.hasSourceArrow,
2147
+ hasTargetArrow: this.hasTargetArrow
2148
+ }));
2149
+ r(this, "createDetourPath", (e, o, i, s, h) => Y({
2150
+ to: i,
2151
+ fromVector: e,
2152
+ toVector: o,
2153
+ flipX: s,
2154
+ flipY: h,
2155
+ arrowLength: this.arrowLength,
2156
+ arrowOffset: this.arrowOffset,
2157
+ roundness: this.roundness,
2158
+ detourDirection: this.detourDirection,
2159
+ detourDistance: this.detourDistance,
2160
+ hasSourceArrow: this.hasSourceArrow,
2161
+ hasTargetArrow: this.hasTargetArrow
2162
+ }));
2163
+ r(this, "createLinePath", (e, o, i, s) => Xe({
2164
+ to: i,
2165
+ fromVector: e,
2166
+ toVector: o,
2167
+ flipX: s,
2168
+ arrowLength: this.arrowLength,
2169
+ arrowOffset: this.arrowOffset,
2170
+ roundness: this.roundness,
2171
+ hasSourceArrow: this.hasSourceArrow,
2172
+ hasTargetArrow: this.hasTargetArrow
2173
+ }));
2174
+ 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;
2175
+ const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
2176
+ this.roundness = Math.min(
2177
+ o,
2178
+ this.arrowOffset,
2179
+ this.cycleSquareSide / 2
2180
+ ), 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.lineShape = new U({
2181
+ color: (e == null ? void 0 : e.color) ?? u.color,
2182
+ width: (e == null ? void 0 : e.width) ?? u.width,
2183
+ arrowLength: this.arrowLength,
2184
+ arrowWidth: this.arrowWidth,
2185
+ hasSourceArrow: this.hasSourceArrow,
2186
+ hasTargetArrow: this.hasTargetArrow,
2187
+ createCyclePath: this.createCyclePath,
2188
+ createDetourPath: this.createDetourPath,
2189
+ createLinePath: this.createLinePath
2190
+ }), this.svg = this.lineShape.svg, this.group = this.lineShape.group, this.line = this.lineShape.line, this.sourceArrow = this.lineShape.sourceArrow, this.targetArrow = this.lineShape.targetArrow;
2402
2191
  }
2403
- tryCreateConnection(e) {
2404
- const o = this.findPortAtPoint(e);
2405
- if (o === null) {
2406
- this.config.onEdgeCreationInterrupted(this.staticPortId, this.isDirect);
2407
- return;
2408
- }
2409
- const i = this.isDirect ? this.staticPortId : o, s = this.isDirect ? o : this.staticPortId, h = { from: i, to: s }, n = this.config.connectionPreprocessor(h);
2410
- n !== null ? (this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated), this.canvas.addEdge(n), this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated)) : this.config.onEdgeCreationPrevented(h);
2192
+ render(e) {
2193
+ this.lineShape.render(e);
2411
2194
  }
2412
- moveDraggingNode(e) {
2413
- const o = this.overlayLayer.getBoundingClientRect(), i = {
2414
- x: e.x - o.x,
2415
- y: e.y - o.y
2416
- }, s = this.canvas.viewport.getViewportMatrix(), h = N(s, i);
2417
- this.overlayCanvas.updateNode(this.draggingOverlayPortId, {
2418
- x: h.x,
2419
- y: h.y
2420
- });
2195
+ }
2196
+ class qe {
2197
+ constructor(e) {
2198
+ r(this, "svg");
2199
+ r(this, "group");
2200
+ r(this, "line");
2201
+ r(this, "sourceArrow");
2202
+ r(this, "targetArrow");
2203
+ r(this, "arrowLength");
2204
+ r(this, "arrowWidth");
2205
+ r(this, "arrowOffset");
2206
+ r(this, "roundness");
2207
+ r(this, "cycleSquareSide");
2208
+ r(this, "detourDirection");
2209
+ r(this, "detourDistance");
2210
+ r(this, "hasSourceArrow");
2211
+ r(this, "hasTargetArrow");
2212
+ r(this, "lineShape");
2213
+ r(this, "createCyclePath", (e) => H({
2214
+ fromVector: e,
2215
+ arrowLength: this.arrowLength,
2216
+ side: this.cycleSquareSide,
2217
+ arrowOffset: this.arrowOffset,
2218
+ roundness: this.roundness,
2219
+ hasSourceArrow: this.hasSourceArrow,
2220
+ hasTargetArrow: this.hasTargetArrow
2221
+ }));
2222
+ r(this, "createDetourPath", (e, o, i, s, h) => Y({
2223
+ to: i,
2224
+ fromVector: e,
2225
+ toVector: o,
2226
+ flipX: s,
2227
+ flipY: h,
2228
+ arrowLength: this.arrowLength,
2229
+ arrowOffset: this.arrowOffset,
2230
+ roundness: this.roundness,
2231
+ detourDirection: this.detourDirection,
2232
+ detourDistance: this.detourDistance,
2233
+ hasSourceArrow: this.hasSourceArrow,
2234
+ hasTargetArrow: this.hasTargetArrow
2235
+ }));
2236
+ r(this, "createLinePath", (e, o, i) => Ye({
2237
+ to: i,
2238
+ fromVector: e,
2239
+ toVector: o,
2240
+ arrowLength: this.arrowLength,
2241
+ arrowOffset: this.arrowOffset,
2242
+ roundness: this.roundness,
2243
+ hasSourceArrow: this.hasSourceArrow,
2244
+ hasTargetArrow: this.hasTargetArrow
2245
+ }));
2246
+ 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;
2247
+ const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
2248
+ this.roundness = Math.min(
2249
+ o,
2250
+ this.arrowOffset,
2251
+ this.cycleSquareSide / 2
2252
+ ), 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.lineShape = new U({
2253
+ color: (e == null ? void 0 : e.color) ?? u.color,
2254
+ width: (e == null ? void 0 : e.width) ?? u.width,
2255
+ arrowLength: this.arrowLength,
2256
+ arrowWidth: this.arrowWidth,
2257
+ hasSourceArrow: this.hasSourceArrow,
2258
+ hasTargetArrow: this.hasTargetArrow,
2259
+ createCyclePath: this.createCyclePath,
2260
+ createDetourPath: this.createDetourPath,
2261
+ createLinePath: this.createLinePath
2262
+ }), this.svg = this.lineShape.svg, this.group = this.lineShape.group, this.line = this.lineShape.line, this.sourceArrow = this.lineShape.sourceArrow, this.targetArrow = this.lineShape.targetArrow;
2421
2263
  }
2422
- findPortAtPoint(e) {
2423
- const o = document.elementsFromPoint(e.x, e.y);
2424
- for (const i of o) {
2425
- const s = this.findPortAtElement(i);
2426
- if (s !== null)
2427
- return s;
2428
- }
2429
- return null;
2264
+ render(e) {
2265
+ this.lineShape.render(e);
2430
2266
  }
2431
- findPortAtElement(e) {
2432
- let o = e, i = null;
2433
- for (; o !== null && (i = this.ports.getMultiBySingle(o)[0] ?? null, i === null); )
2434
- o = o.parentElement;
2435
- return i;
2267
+ }
2268
+ class et {
2269
+ constructor(e) {
2270
+ r(this, "svg");
2271
+ r(this, "group");
2272
+ r(this, "line");
2273
+ r(this, "sourceArrow");
2274
+ r(this, "targetArrow");
2275
+ r(this, "arrowLength");
2276
+ r(this, "arrowWidth");
2277
+ r(this, "arrowOffset");
2278
+ r(this, "roundness");
2279
+ r(this, "cycleSquareSide");
2280
+ r(this, "detourDirection");
2281
+ r(this, "detourDistance");
2282
+ r(this, "hasSourceArrow");
2283
+ r(this, "hasTargetArrow");
2284
+ r(this, "lineShape");
2285
+ r(this, "createCyclePath", (e) => H({
2286
+ fromVector: e,
2287
+ arrowLength: this.arrowLength,
2288
+ side: this.cycleSquareSide,
2289
+ arrowOffset: this.arrowOffset,
2290
+ roundness: this.roundness,
2291
+ hasSourceArrow: this.hasSourceArrow,
2292
+ hasTargetArrow: this.hasTargetArrow
2293
+ }));
2294
+ r(this, "createDetourPath", (e, o, i, s, h) => Y({
2295
+ to: i,
2296
+ fromVector: e,
2297
+ toVector: o,
2298
+ flipX: s,
2299
+ flipY: h,
2300
+ arrowLength: this.arrowLength,
2301
+ arrowOffset: this.arrowOffset,
2302
+ roundness: this.roundness,
2303
+ detourDirection: this.detourDirection,
2304
+ detourDistance: this.detourDistance,
2305
+ hasSourceArrow: this.hasSourceArrow,
2306
+ hasTargetArrow: this.hasTargetArrow
2307
+ }));
2308
+ r(this, "createLinePath", (e, o, i, s, h) => He({
2309
+ to: i,
2310
+ fromVector: e,
2311
+ toVector: o,
2312
+ flipY: h,
2313
+ arrowLength: this.arrowLength,
2314
+ arrowOffset: this.arrowOffset,
2315
+ roundness: this.roundness,
2316
+ hasSourceArrow: this.hasSourceArrow,
2317
+ hasTargetArrow: this.hasTargetArrow
2318
+ }));
2319
+ 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;
2320
+ const o = (e == null ? void 0 : e.roundness) ?? u.roundness;
2321
+ this.roundness = Math.min(
2322
+ o,
2323
+ this.arrowOffset,
2324
+ this.cycleSquareSide / 2
2325
+ ), 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.lineShape = new U({
2326
+ color: (e == null ? void 0 : e.color) ?? u.color,
2327
+ width: (e == null ? void 0 : e.width) ?? u.width,
2328
+ arrowLength: this.arrowLength,
2329
+ arrowWidth: this.arrowWidth,
2330
+ hasSourceArrow: this.hasSourceArrow,
2331
+ hasTargetArrow: this.hasTargetArrow,
2332
+ createCyclePath: this.createCyclePath,
2333
+ createDetourPath: this.createDetourPath,
2334
+ createLinePath: this.createLinePath
2335
+ }), this.svg = this.lineShape.svg, this.group = this.lineShape.group, this.line = this.lineShape.line, this.sourceArrow = this.lineShape.sourceArrow, this.targetArrow = this.lineShape.targetArrow;
2436
2336
  }
2437
- isPortConnectionAllowed(e) {
2438
- const o = this.ports.getMultiBySingle(e)[0];
2439
- return this.config.connectionTypeResolver(o) !== null;
2337
+ render(e) {
2338
+ this.lineShape.render(e);
2440
2339
  }
2441
2340
  }
2442
- const it = () => {
2443
- const t = document.createElement("div");
2444
- return t.style.width = "100%", t.style.height = "100%", t.style.position = "relative", t;
2445
- }, W = () => {
2446
- const t = document.createElement("div");
2447
- return t.style.position = "absolute", t.style.inset = "0", t;
2341
+ const tt = () => {
2342
+ const t = document.createElementNS("http://www.w3.org/2000/svg", "g");
2343
+ return t.style.pointerEvents = "auto", t.style.cursor = "pointer", t;
2344
+ }, ot = (t) => {
2345
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
2346
+ return e.setAttribute("stroke", "transparent"), e.setAttribute("stroke-width", `${t}`), e.setAttribute("fill", "none"), e.setAttribute("stroke-linecap", "round"), e;
2347
+ }, re = (t) => {
2348
+ const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
2349
+ return e.setAttribute("stroke-linejoin", "round"), e.setAttribute("stroke-width", `${t}`), e.setAttribute("fill", "transparent"), e.setAttribute("stroke", "transparent"), e;
2448
2350
  };
2449
- class st {
2351
+ class rt extends Error {
2450
2352
  constructor(e) {
2451
- r(this, "background", W());
2452
- r(this, "main", W());
2453
- r(this, "overlay", W());
2454
- r(this, "host", it());
2455
- 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);
2353
+ super(e), this.name = "InteractiveEdgeError";
2456
2354
  }
2457
- destroy() {
2458
- this.host.removeChild(this.background), this.host.removeChild(this.main), this.host.removeChild(this.overlay), this.element.removeChild(this.host);
2355
+ }
2356
+ class ce {
2357
+ constructor(e, o) {
2358
+ r(this, "svg");
2359
+ r(this, "group");
2360
+ r(this, "line");
2361
+ r(this, "sourceArrow");
2362
+ r(this, "targetArrow");
2363
+ r(this, "handle", tt());
2364
+ r(this, "interactiveLine");
2365
+ r(this, "interactiveSourceArrow", null);
2366
+ r(this, "interactiveTargetArrow", null);
2367
+ if (this.structuredEdge = e, e instanceof ce)
2368
+ throw new rt(
2369
+ "interactive edge can be configured only once"
2370
+ );
2371
+ this.svg = this.structuredEdge.svg, this.group = this.structuredEdge.group, this.line = this.structuredEdge.line, this.sourceArrow = this.structuredEdge.sourceArrow, this.targetArrow = this.structuredEdge.targetArrow;
2372
+ const i = (o == null ? void 0 : o.width) ?? u.interactiveWidth;
2373
+ this.interactiveLine = ot(i), this.handle.appendChild(this.interactiveLine), this.sourceArrow && (this.interactiveSourceArrow = re(i), this.handle.appendChild(this.interactiveSourceArrow)), this.targetArrow && (this.interactiveTargetArrow = re(i), this.handle.appendChild(this.interactiveTargetArrow)), this.group.appendChild(this.handle);
2374
+ }
2375
+ render(e) {
2376
+ this.structuredEdge.render(e);
2377
+ const o = this.line.getAttribute("d");
2378
+ if (this.interactiveLine.setAttribute("d", o), this.sourceArrow) {
2379
+ const i = this.sourceArrow.getAttribute("d");
2380
+ this.interactiveSourceArrow.setAttribute("d", i);
2381
+ }
2382
+ if (this.targetArrow) {
2383
+ const i = this.targetArrow.getAttribute("d");
2384
+ this.interactiveTargetArrow.setAttribute("d", i);
2385
+ }
2459
2386
  }
2460
2387
  }
2388
+ const it = (t) => {
2389
+ if (typeof t == "function")
2390
+ return t;
2391
+ switch (t == null ? void 0 : t.type) {
2392
+ case "straight":
2393
+ return () => new qe({
2394
+ color: t.color,
2395
+ width: t.width,
2396
+ arrowLength: t.arrowLength,
2397
+ arrowWidth: t.arrowWidth,
2398
+ arrowOffset: t.arrowOffset,
2399
+ hasSourceArrow: t.hasSourceArrow,
2400
+ hasTargetArrow: t.hasTargetArrow,
2401
+ cycleSquareSide: t.cycleSquareSide,
2402
+ roundness: t.roundness,
2403
+ detourDistance: t.detourDistance,
2404
+ detourDirection: t.detourDirection
2405
+ });
2406
+ case "horizontal":
2407
+ return () => new _e({
2408
+ color: t.color,
2409
+ width: t.width,
2410
+ arrowLength: t.arrowLength,
2411
+ arrowWidth: t.arrowWidth,
2412
+ arrowOffset: t.arrowOffset,
2413
+ hasSourceArrow: t.hasSourceArrow,
2414
+ hasTargetArrow: t.hasTargetArrow,
2415
+ cycleSquareSide: t.cycleSquareSide,
2416
+ roundness: t.roundness,
2417
+ detourDistance: t.detourDistance,
2418
+ detourDirection: t.detourDirection
2419
+ });
2420
+ case "vertical":
2421
+ return () => new et({
2422
+ color: t.color,
2423
+ width: t.width,
2424
+ arrowLength: t.arrowLength,
2425
+ arrowWidth: t.arrowWidth,
2426
+ arrowOffset: t.arrowOffset,
2427
+ hasSourceArrow: t.hasSourceArrow,
2428
+ hasTargetArrow: t.hasTargetArrow,
2429
+ cycleSquareSide: t.cycleSquareSide,
2430
+ roundness: t.roundness,
2431
+ detourDistance: t.detourDistance,
2432
+ detourDirection: t.detourDirection
2433
+ });
2434
+ default:
2435
+ return () => new Qe({
2436
+ color: t.color,
2437
+ width: t.width,
2438
+ arrowLength: t.arrowLength,
2439
+ arrowWidth: t.arrowWidth,
2440
+ hasSourceArrow: t.hasSourceArrow,
2441
+ hasTargetArrow: t.hasTargetArrow,
2442
+ cycleRadius: t.cycleRadius,
2443
+ smallCycleRadius: t.smallCycleRadius,
2444
+ curvature: t.curvature,
2445
+ detourDistance: t.detourDistance,
2446
+ detourDirection: t.detourDirection
2447
+ });
2448
+ }
2449
+ }, st = (t) => {
2450
+ var o, i, s, h, n;
2451
+ const e = ke(
2452
+ (o = t.nodes) == null ? void 0 : o.priority,
2453
+ (i = t.edges) == null ? void 0 : i.priority
2454
+ );
2455
+ return {
2456
+ nodes: {
2457
+ centerFn: ((s = t.nodes) == null ? void 0 : s.centerFn) ?? $e,
2458
+ priorityFn: e.nodesPriorityFn
2459
+ },
2460
+ ports: {
2461
+ direction: ((h = t.ports) == null ? void 0 : h.direction) ?? 0
2462
+ },
2463
+ edges: {
2464
+ shapeFactory: it(((n = t.edges) == null ? void 0 : n.shape) ?? {}),
2465
+ priorityFn: e.edgesPriorityFn
2466
+ }
2467
+ };
2468
+ };
2461
2469
  class ht {
2462
2470
  constructor(e) {
2463
2471
  r(this, "element", null);
@@ -2542,51 +2550,51 @@ class ht {
2542
2550
  );
2543
2551
  let e = this.boxRenderingTrigger;
2544
2552
  this.virtualScrollConfig !== void 0 && e === void 0 && (e = new se());
2545
- const o = new ce(), i = new ze(), s = new st(this.element);
2553
+ const o = new de(), i = new Ae(), s = new We(this.element);
2546
2554
  let h = new ie(
2547
2555
  o,
2548
2556
  i,
2549
2557
  s.main
2550
2558
  );
2551
2559
  e !== void 0 && (h = new ve(h, o, e));
2552
- const n = new he(
2560
+ const n = st(this.canvasDefaults), d = new ne(
2553
2561
  this.element,
2554
2562
  o,
2555
2563
  i,
2556
2564
  h,
2557
- this.canvasDefaults
2558
- ), d = () => {
2559
- s.destroy(), n.onBeforeDestroy.unsubscribe(d);
2565
+ n
2566
+ ), c = () => {
2567
+ s.destroy(), d.onBeforeDestroy.unsubscribe(c);
2560
2568
  };
2561
- return n.onBeforeDestroy.subscribe(d), this.hasBackground && Y.configure(
2562
- n,
2569
+ return d.onBeforeDestroy.subscribe(c), this.hasBackground && O.configure(
2570
+ d,
2563
2571
  this.backgroundConfig,
2564
2572
  s.background
2565
- ), this.hasResizeReactiveNodes && z.configure(n), this.hasDraggableNode && O.configure(
2566
- n,
2573
+ ), this.hasResizeReactiveNodes && F.configure(d), this.hasDraggableNode && k.configure(
2574
+ d,
2567
2575
  s.main,
2568
2576
  this.window,
2569
2577
  this.dragConfig
2570
- ), this.hasUserConnectablePorts && H.configure(
2571
- n,
2578
+ ), this.hasUserConnectablePorts && X.configure(
2579
+ d,
2572
2580
  s.overlay,
2573
2581
  i,
2574
2582
  this.window,
2575
- this.canvasDefaults,
2576
- this.connectablePortsConfig
2577
- ), this.virtualScrollConfig !== void 0 ? X.configure(
2578
2583
  n,
2584
+ this.connectablePortsConfig
2585
+ ), this.virtualScrollConfig !== void 0 ? z.configure(
2586
+ d,
2579
2587
  s.main,
2580
2588
  this.window,
2581
2589
  this.transformConfig,
2582
2590
  e,
2583
2591
  this.virtualScrollConfig
2584
- ) : this.hasTransformableViewport && U.configure(
2585
- n,
2592
+ ) : this.hasTransformableViewport && I.configure(
2593
+ d,
2586
2594
  s.main,
2587
2595
  this.window,
2588
2596
  this.transformConfig
2589
- ), this.reset(), n;
2597
+ ), this.reset(), d;
2590
2598
  }
2591
2599
  /**
2592
2600
  * @deprecated
@@ -2597,14 +2605,14 @@ class ht {
2597
2605
  }
2598
2606
  }
2599
2607
  export {
2600
- Re as BezierEdgeShape,
2608
+ Qe as BezierEdgeShape,
2601
2609
  ht as CanvasBuilder,
2602
2610
  se as EventSubject,
2603
- Be as HorizontalEdgeShape,
2611
+ _e as HorizontalEdgeShape,
2604
2612
  S as HtmlGraphError,
2605
- $e as InteractiveEdgeError,
2606
- ne as InteractiveEdgeShape,
2607
- I as LineEdgeShape,
2608
- Ie as StraightEdgeShape,
2609
- Ue as VerticalEdgeShape
2613
+ rt as InteractiveEdgeError,
2614
+ ce as InteractiveEdgeShape,
2615
+ U as LineEdgeShape,
2616
+ qe as StraightEdgeShape,
2617
+ et as VerticalEdgeShape
2610
2618
  };