@html-graph/html-graph 0.0.46 → 0.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/main.d.ts +56 -52
- package/dist/main.js +263 -246
- package/dist/main.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var r = (n, t, e) =>
|
|
4
|
-
class
|
|
5
|
-
constructor(t) {
|
|
1
|
+
var F = Object.defineProperty;
|
|
2
|
+
var k = (n, t, e) => t in n ? F(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var r = (n, t, e) => k(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
class j {
|
|
5
|
+
constructor(t, e, o, s, i) {
|
|
6
6
|
r(this, "canvasWrapper", null);
|
|
7
7
|
r(this, "host");
|
|
8
8
|
r(this, "nodesContainer");
|
|
@@ -39,7 +39,7 @@ class F {
|
|
|
39
39
|
},
|
|
40
40
|
moveOnTop: (t) => {
|
|
41
41
|
const e = this.nodeIdToWrapperElementMap.get(t);
|
|
42
|
-
this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.
|
|
42
|
+
this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.graphStore.getNodeAdjacentConnections(t).forEach((s) => {
|
|
43
43
|
this.connectionIdToElementMap.get(s).style.zIndex = `${this.currentZIndex - 1}`;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -58,13 +58,11 @@ class F {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
this.
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
61
|
+
this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer = o, this.layersMode = s, this.backgroundDrawingFn = i, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.connectionsContainer = this.createConnectionsContainer();
|
|
62
|
+
const h = this.canvas.getContext("2d");
|
|
63
|
+
if (h === null)
|
|
64
64
|
throw new Error("unable to get canvas context");
|
|
65
|
-
this.canvasCtx =
|
|
66
|
-
const o = this.di.options.layers.mode;
|
|
67
|
-
this.layers[o].create(), this.hostResizeObserver = this.createHostResizeObserver(), this.hostResizeObserver.observe(this.host), this.nodesResizeObserver = this.createNodesResizeObserver();
|
|
65
|
+
this.canvasCtx = h, this.host.appendChild(this.canvas), this.layers[this.layersMode].create(), this.hostResizeObserver = this.createHostResizeObserver(), this.hostResizeObserver.observe(this.host), this.nodesResizeObserver = this.createNodesResizeObserver();
|
|
68
66
|
}
|
|
69
67
|
clear() {
|
|
70
68
|
Array.from(this.connectionIdToElementMap.keys()).forEach((t) => {
|
|
@@ -83,30 +81,22 @@ class F {
|
|
|
83
81
|
this.hostResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.connectionsContainer), this.host.removeChild(this.nodesContainer), this.canvasWrapper !== null && this.canvasWrapper.removeChild(this.host);
|
|
84
82
|
}
|
|
85
83
|
applyTransform() {
|
|
86
|
-
this.canvasCtx.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.canvasCtx.canvas.width,
|
|
90
|
-
this.canvasCtx.canvas.height
|
|
91
|
-
), this.canvasCtx.save(), this.di.options.background.drawingFn(
|
|
92
|
-
this.canvasCtx,
|
|
93
|
-
this.di.publicViewportTransformer
|
|
94
|
-
), this.canvasCtx.restore();
|
|
95
|
-
const [t, e] = this.di.viewportTransformer.getViewCoords(0, 0), o = this.di.viewportTransformer.getViewScale();
|
|
96
|
-
this.layers[this.di.options.layers.mode].update(o, t, e);
|
|
84
|
+
this.backgroundDrawingFn(this.canvasCtx, this.publicViewportTransformer);
|
|
85
|
+
const [t, e] = this.viewportTransformer.getViewCoords(0, 0), o = this.viewportTransformer.getViewScale();
|
|
86
|
+
this.layers[this.layersMode].update(o, t, e);
|
|
97
87
|
}
|
|
98
88
|
attachNode(t) {
|
|
99
|
-
const e = this.
|
|
89
|
+
const e = this.graphStore.getNode(t), o = document.createElement("div");
|
|
100
90
|
o.appendChild(e.element), o.style.position = "absolute", o.style.top = "0", o.style.left = "0", o.style.zIndex = `${this.currentZIndex}`, this.currentZIndex += 1, o.style.visibility = "hidden", this.nodesContainer.appendChild(o), this.nodeElementToIdMap.set(e.element, t), this.nodeWrapperElementToIdMap.set(o, t), this.nodeIdToWrapperElementMap.set(t, o), this.updateNodeCoords(t, e.x, e.y), this.nodesResizeObserver.observe(o), o.style.visibility = "visible";
|
|
101
91
|
}
|
|
102
92
|
detachNode(t) {
|
|
103
|
-
const e = this.
|
|
93
|
+
const e = this.graphStore.getNode(t);
|
|
104
94
|
this.nodesResizeObserver.unobserve(e.element), this.nodesContainer.removeChild(e.element);
|
|
105
95
|
const o = this.nodeIdToWrapperElementMap.get(t);
|
|
106
96
|
o.removeChild(e.element), this.nodeElementToIdMap.delete(e.element), this.nodeWrapperElementToIdMap.delete(o), this.nodeIdToWrapperElementMap.delete(t);
|
|
107
97
|
}
|
|
108
98
|
attachConnection(t) {
|
|
109
|
-
const o = this.
|
|
99
|
+
const o = this.graphStore.getConnection(t).controller.svg;
|
|
110
100
|
o.style.transformOrigin = "50% 50%", o.style.position = "absolute", o.style.top = "0", o.style.left = "0", o.style.zIndex = `${this.currentZIndex}`, this.currentZIndex += 1, this.connectionIdToElementMap.set(t, o), this.updateConnectionCoords(t), this.connectionsContainer.appendChild(o);
|
|
111
101
|
}
|
|
112
102
|
detachConnection(t) {
|
|
@@ -114,16 +104,16 @@ class F {
|
|
|
114
104
|
this.connectionIdToElementMap.delete(t), this.connectionsContainer.removeChild(e);
|
|
115
105
|
}
|
|
116
106
|
moveNodeOnTop(t) {
|
|
117
|
-
this.layers[this.
|
|
107
|
+
this.layers[this.layersMode].moveOnTop(t);
|
|
118
108
|
}
|
|
119
109
|
updateNodePosition(t) {
|
|
120
|
-
const e = this.
|
|
110
|
+
const e = this.graphStore.getNode(t), o = this.graphStore.getNodeAdjacentConnections(t);
|
|
121
111
|
this.updateNodeCoords(t, e.x, e.y), o.forEach((s) => {
|
|
122
112
|
this.updateConnectionCoords(s);
|
|
123
113
|
});
|
|
124
114
|
}
|
|
125
115
|
updatePortConnections(t) {
|
|
126
|
-
this.
|
|
116
|
+
this.graphStore.getPortAdjacentConnections(t).forEach((o) => {
|
|
127
117
|
this.updateConnectionCoords(o);
|
|
128
118
|
});
|
|
129
119
|
}
|
|
@@ -155,8 +145,8 @@ class F {
|
|
|
155
145
|
createNodesResizeObserver() {
|
|
156
146
|
return new ResizeObserver((t) => {
|
|
157
147
|
t.forEach((e) => {
|
|
158
|
-
const o = e.target, s = this.nodeWrapperElementToIdMap.get(o), i = this.
|
|
159
|
-
this.updateNodeCoords(s, i.x, i.y), this.
|
|
148
|
+
const o = e.target, s = this.nodeWrapperElementToIdMap.get(o), i = this.graphStore.getNode(s);
|
|
149
|
+
this.updateNodeCoords(s, i.x, i.y), this.graphStore.getNodeAdjacentConnections(s).forEach((a) => {
|
|
160
150
|
this.updateConnectionCoords(a);
|
|
161
151
|
});
|
|
162
152
|
});
|
|
@@ -167,27 +157,27 @@ class F {
|
|
|
167
157
|
this.canvas.width = t, this.canvas.height = e;
|
|
168
158
|
}
|
|
169
159
|
updateNodeCoords(t, e, o) {
|
|
170
|
-
const s = this.nodeIdToWrapperElementMap.get(t), { width: i, height:
|
|
171
|
-
s.style.transform = `matrix(1, 0, 0, 1, ${e - a * l}, ${o - a *
|
|
160
|
+
const s = this.nodeIdToWrapperElementMap.get(t), { width: i, height: h } = s.getBoundingClientRect(), a = this.viewportTransformer.getAbsScale(), c = this.graphStore.getNode(t), [l, g] = c.centerFn(i, h);
|
|
161
|
+
s.style.transform = `matrix(1, 0, 0, 1, ${e - a * l}, ${o - a * g})`;
|
|
172
162
|
}
|
|
173
163
|
updateConnectionCoords(t) {
|
|
174
|
-
const e = this.
|
|
164
|
+
const e = this.graphStore.getConnection(t), o = this.graphStore.getPort(e.from), s = this.graphStore.getPort(e.to), i = o.element.getBoundingClientRect(), h = s.element.getBoundingClientRect(), a = this.host.getBoundingClientRect(), [c, l] = this.viewportTransformer.getAbsCoords(
|
|
175
165
|
i.left - a.left,
|
|
176
166
|
i.top - a.top
|
|
177
|
-
), [
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
),
|
|
181
|
-
i.width *
|
|
182
|
-
i.height *
|
|
167
|
+
), [g, d] = this.viewportTransformer.getAbsCoords(
|
|
168
|
+
h.left - a.left,
|
|
169
|
+
h.top - a.top
|
|
170
|
+
), m = this.viewportTransformer.getAbsScale(), [u, p] = o.centerFn(
|
|
171
|
+
i.width * m,
|
|
172
|
+
i.height * m
|
|
183
173
|
), [f, y] = s.centerFn(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
),
|
|
187
|
-
M.style.transform = `matrix(${L ? 1 : -1}, 0, 0, ${V ? 1 : -1}, ${w}, ${T})`, e.controller.update(w, T, E,
|
|
174
|
+
h.width * m,
|
|
175
|
+
h.height * m
|
|
176
|
+
), S = u + c, b = p + l, N = f + g, C = y + d, w = Math.min(S, N), T = Math.min(b, C), E = Math.abs(N - S), x = Math.abs(C - b), M = this.connectionIdToElementMap.get(t), L = S <= N, V = b <= C;
|
|
177
|
+
M.style.transform = `matrix(${L ? 1 : -1}, 0, 0, ${V ? 1 : -1}, ${w}, ${T})`, e.controller.update(w, T, E, x, o, s);
|
|
188
178
|
}
|
|
189
179
|
}
|
|
190
|
-
class
|
|
180
|
+
class D {
|
|
191
181
|
constructor() {
|
|
192
182
|
r(this, "state", {
|
|
193
183
|
scale: 1,
|
|
@@ -257,7 +247,7 @@ class W {
|
|
|
257
247
|
};
|
|
258
248
|
}
|
|
259
249
|
}
|
|
260
|
-
class
|
|
250
|
+
class W {
|
|
261
251
|
constructor(t) {
|
|
262
252
|
this.transformer = t;
|
|
263
253
|
}
|
|
@@ -336,8 +326,8 @@ class R {
|
|
|
336
326
|
}
|
|
337
327
|
addPort(t, e, o, s, i) {
|
|
338
328
|
this.ports[t] = { element: e, centerFn: s, direction: i }, this.cycleConnections[t] = {}, this.incommingConnections[t] = {}, this.outcommingConnections[t] = {}, this.portNodeId[t] = o;
|
|
339
|
-
const
|
|
340
|
-
|
|
329
|
+
const h = this.nodePorts[o];
|
|
330
|
+
h !== void 0 && (h[t] = e);
|
|
341
331
|
}
|
|
342
332
|
getPort(t) {
|
|
343
333
|
return this.ports[t];
|
|
@@ -485,22 +475,10 @@ class z {
|
|
|
485
475
|
return this.graphStore.getNodeAdjacentConnections(t);
|
|
486
476
|
}
|
|
487
477
|
}
|
|
488
|
-
class
|
|
489
|
-
constructor() {
|
|
490
|
-
r(this, "counter", 0);
|
|
491
|
-
}
|
|
492
|
-
next() {
|
|
493
|
-
const t = `${this.counter}`;
|
|
494
|
-
return this.counter++, t;
|
|
495
|
-
}
|
|
496
|
-
reset() {
|
|
497
|
-
this.counter = 0;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
class C {
|
|
478
|
+
class v {
|
|
501
479
|
static getPortCenter(t) {
|
|
502
|
-
const { top: e, left: o, width: s, height: i } = t.element.getBoundingClientRect(),
|
|
503
|
-
return [o +
|
|
480
|
+
const { top: e, left: o, width: s, height: i } = t.element.getBoundingClientRect(), h = t.centerFn(s, i);
|
|
481
|
+
return [o + h[0], e + h[1]];
|
|
504
482
|
}
|
|
505
483
|
static rotate(t, e, o) {
|
|
506
484
|
return [
|
|
@@ -516,25 +494,25 @@ class C {
|
|
|
516
494
|
[0, 0],
|
|
517
495
|
[s, i],
|
|
518
496
|
[s, -i]
|
|
519
|
-
].map((d) => this.rotate(d, t, [0, 0])).map((d) => [d[0] + e, d[1] + o]),
|
|
520
|
-
return `${
|
|
497
|
+
].map((d) => this.rotate(d, t, [0, 0])).map((d) => [d[0] + e, d[1] + o]), c = `M ${a[0][0]} ${a[0][1]}`, l = `L ${a[1][0]} ${a[1][1]}`, g = `L ${a[2][0]} ${a[2][1]}`;
|
|
498
|
+
return `${c} ${l} ${g}`;
|
|
521
499
|
}
|
|
522
500
|
static getArrowOffsetPath(t, e, o, s, i) {
|
|
523
501
|
const a = [
|
|
524
502
|
[s, 0],
|
|
525
503
|
[s + i, 0]
|
|
526
|
-
].map((
|
|
504
|
+
].map((c) => this.rotate(c, t, [0, 0])).map((c) => [c[0] + e, c[1] + o]);
|
|
527
505
|
return `M ${a[0][0]} ${a[0][1]} L ${a[1][0]} ${a[1][1]}`;
|
|
528
506
|
}
|
|
529
507
|
}
|
|
530
508
|
class G {
|
|
531
|
-
constructor(t, e, o, s, i,
|
|
509
|
+
constructor(t, e, o, s, i, h, a) {
|
|
532
510
|
r(this, "svg");
|
|
533
511
|
r(this, "group");
|
|
534
512
|
r(this, "line");
|
|
535
513
|
r(this, "sourceArrow", null);
|
|
536
514
|
r(this, "targetArrow", null);
|
|
537
|
-
this.color = t, this.width = e, this.curvature = o, this.arrowLength = s, this.arrowWidth = i, this.hasSourceArrow =
|
|
515
|
+
this.color = t, this.width = e, this.curvature = o, this.arrowLength = s, this.arrowWidth = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
|
|
538
516
|
"http://www.w3.org/2000/svg",
|
|
539
517
|
"path"
|
|
540
518
|
), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = document.createElementNS(
|
|
@@ -542,35 +520,35 @@ class G {
|
|
|
542
520
|
"path"
|
|
543
521
|
), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
|
|
544
522
|
}
|
|
545
|
-
update(t, e, o, s, i,
|
|
523
|
+
update(t, e, o, s, i, h) {
|
|
546
524
|
this.svg.style.width = `${o}px`, this.svg.style.height = `${s}px`;
|
|
547
|
-
const a =
|
|
548
|
-
this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${
|
|
549
|
-
const d =
|
|
525
|
+
const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
|
|
526
|
+
this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
|
|
527
|
+
const d = v.getDirectionVector(
|
|
550
528
|
i.direction,
|
|
551
529
|
l,
|
|
552
|
-
|
|
553
|
-
),
|
|
554
|
-
|
|
530
|
+
g
|
|
531
|
+
), m = v.getDirectionVector(
|
|
532
|
+
h.direction,
|
|
555
533
|
l,
|
|
556
|
-
|
|
557
|
-
), u =
|
|
534
|
+
g
|
|
535
|
+
), u = v.rotate(
|
|
558
536
|
[this.arrowLength, 0],
|
|
559
537
|
d,
|
|
560
538
|
[0, 0]
|
|
561
|
-
), p =
|
|
539
|
+
), p = v.rotate(
|
|
562
540
|
[o - this.arrowLength, s],
|
|
563
|
-
|
|
541
|
+
m,
|
|
564
542
|
[o, s]
|
|
565
543
|
), f = [
|
|
566
544
|
u[0] + d[0] * this.curvature,
|
|
567
545
|
u[1] + d[1] * this.curvature
|
|
568
546
|
], y = [
|
|
569
|
-
p[0] -
|
|
570
|
-
p[1] -
|
|
571
|
-
],
|
|
547
|
+
p[0] - m[0] * this.curvature,
|
|
548
|
+
p[1] - m[1] * this.curvature
|
|
549
|
+
], S = `M ${u[0]} ${u[1]}`, b = `C ${f[0]} ${f[1]}, ${y[0]} ${y[1]}, ${p[0]} ${p[1]}`, N = `M 0 0 L ${u[0]} ${u[1]} `, C = ` M ${p[0]} ${p[1]} L ${o} ${s}`, w = `${this.sourceArrow ? "" : N}${S} ${b}${this.targetArrow ? "" : C}`;
|
|
572
550
|
if (this.line.setAttribute("d", w), this.sourceArrow) {
|
|
573
|
-
const T =
|
|
551
|
+
const T = v.getArrowPath(
|
|
574
552
|
d,
|
|
575
553
|
0,
|
|
576
554
|
0,
|
|
@@ -580,8 +558,8 @@ class G {
|
|
|
580
558
|
this.sourceArrow.setAttribute("d", T);
|
|
581
559
|
}
|
|
582
560
|
if (this.targetArrow) {
|
|
583
|
-
const T =
|
|
584
|
-
|
|
561
|
+
const T = v.getArrowPath(
|
|
562
|
+
m,
|
|
585
563
|
o,
|
|
586
564
|
s,
|
|
587
565
|
-this.arrowLength,
|
|
@@ -601,13 +579,13 @@ const B = (n) => () => new G(
|
|
|
601
579
|
n.hasTargetArrow ?? !1
|
|
602
580
|
);
|
|
603
581
|
class Y {
|
|
604
|
-
constructor(t, e, o, s, i,
|
|
582
|
+
constructor(t, e, o, s, i, h, a) {
|
|
605
583
|
r(this, "svg");
|
|
606
584
|
r(this, "group");
|
|
607
585
|
r(this, "line");
|
|
608
586
|
r(this, "sourceArrow", null);
|
|
609
587
|
r(this, "targetArrow", null);
|
|
610
|
-
this.color = t, this.width = e, this.arrowLength = o, this.arrowWidth = s, this.minPortOffset = i, this.hasSourceArrow =
|
|
588
|
+
this.color = t, this.width = e, this.arrowLength = o, this.arrowWidth = s, this.minPortOffset = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
|
|
611
589
|
"http://www.w3.org/2000/svg",
|
|
612
590
|
"path"
|
|
613
591
|
), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = document.createElementNS(
|
|
@@ -615,41 +593,41 @@ class Y {
|
|
|
615
593
|
"path"
|
|
616
594
|
), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
|
|
617
595
|
}
|
|
618
|
-
update(t, e, o, s, i,
|
|
596
|
+
update(t, e, o, s, i, h) {
|
|
619
597
|
this.svg.style.width = `${o}px`, this.svg.style.height = `${s}px`;
|
|
620
|
-
const a =
|
|
621
|
-
this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${
|
|
622
|
-
const d =
|
|
598
|
+
const a = v.getPortCenter(i), c = v.getPortCenter(h), l = a[0] <= c[0] ? 1 : -1, g = a[1] <= c[1] ? 1 : -1;
|
|
599
|
+
this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${l}, ${g})`;
|
|
600
|
+
const d = v.getDirectionVector(
|
|
623
601
|
i.direction,
|
|
624
602
|
l,
|
|
625
|
-
|
|
626
|
-
),
|
|
627
|
-
|
|
603
|
+
g
|
|
604
|
+
), m = v.getDirectionVector(
|
|
605
|
+
h.direction,
|
|
628
606
|
l,
|
|
629
|
-
|
|
630
|
-
), u =
|
|
607
|
+
g
|
|
608
|
+
), u = v.rotate(
|
|
631
609
|
[this.arrowLength + this.minPortOffset, 0],
|
|
632
610
|
d,
|
|
633
611
|
[0, 0]
|
|
634
|
-
), p =
|
|
612
|
+
), p = v.rotate(
|
|
635
613
|
[o - this.arrowLength - this.minPortOffset, s],
|
|
636
|
-
|
|
614
|
+
m,
|
|
637
615
|
[o, s]
|
|
638
|
-
), [f, y] = [o / 2, s / 2],
|
|
616
|
+
), [f, y] = [o / 2, s / 2], S = l * (p[0] - u[0]) > 0 ? `M ${u[0]} ${u[1]} L ${f} ${u[1]} L ${f} ${p[1]} L ${p[0]} ${p[1]}` : `M ${u[0]} ${u[1]} L ${u[0]} ${y} L ${p[0]} ${y} L ${p[0]} ${p[1]}`, b = `M 0 0 L ${u[0]} ${u[1]} `, N = ` M ${p[0]} ${p[1]} L ${o} ${s}`, C = v.getArrowOffsetPath(
|
|
639
617
|
d,
|
|
640
618
|
0,
|
|
641
619
|
0,
|
|
642
620
|
this.arrowLength,
|
|
643
621
|
this.minPortOffset
|
|
644
|
-
), w =
|
|
645
|
-
|
|
622
|
+
), w = v.getArrowOffsetPath(
|
|
623
|
+
m,
|
|
646
624
|
o,
|
|
647
625
|
s,
|
|
648
626
|
-this.arrowLength,
|
|
649
627
|
-this.minPortOffset
|
|
650
|
-
), T = `${this.sourceArrow ?
|
|
628
|
+
), T = `${this.sourceArrow ? C : b}${S}${this.targetArrow ? w : N}`;
|
|
651
629
|
if (this.line.setAttribute("d", T), this.sourceArrow) {
|
|
652
|
-
const E =
|
|
630
|
+
const E = v.getArrowPath(
|
|
653
631
|
d,
|
|
654
632
|
0,
|
|
655
633
|
0,
|
|
@@ -659,8 +637,8 @@ class Y {
|
|
|
659
637
|
this.sourceArrow.setAttribute("d", E);
|
|
660
638
|
}
|
|
661
639
|
if (this.targetArrow) {
|
|
662
|
-
const E =
|
|
663
|
-
|
|
640
|
+
const E = v.getArrowPath(
|
|
641
|
+
m,
|
|
664
642
|
o,
|
|
665
643
|
s,
|
|
666
644
|
-this.arrowLength,
|
|
@@ -680,157 +658,181 @@ const X = (n) => () => new Y(
|
|
|
680
658
|
n.hasTargetArrow
|
|
681
659
|
);
|
|
682
660
|
var $ = /* @__PURE__ */ ((n) => (n.Regular = "regular", n.Cycle = "cycle", n))($ || {});
|
|
661
|
+
class A {
|
|
662
|
+
constructor() {
|
|
663
|
+
r(this, "counter", 0);
|
|
664
|
+
}
|
|
665
|
+
next() {
|
|
666
|
+
const t = `${this.counter}`;
|
|
667
|
+
return this.counter++, t;
|
|
668
|
+
}
|
|
669
|
+
reset() {
|
|
670
|
+
this.counter = 0;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
683
673
|
class Z {
|
|
684
|
-
constructor(t) {
|
|
685
|
-
this
|
|
674
|
+
constructor(t, e, o, s, i) {
|
|
675
|
+
r(this, "nodeIdGenerator", new A());
|
|
676
|
+
r(this, "portIdGenerator", new A());
|
|
677
|
+
r(this, "connectionIdGenerator", new A());
|
|
678
|
+
this.graphStore = t, this.htmlController = e, this.viewportTransformer = o, this.nodesCenterFn = s, this.portsCenterFn = i;
|
|
686
679
|
}
|
|
687
680
|
moveNodeOnTop(t) {
|
|
688
|
-
if (!this.
|
|
681
|
+
if (!this.graphStore.hasNode(t))
|
|
689
682
|
throw new Error("failed to move on top nonexisting node");
|
|
690
|
-
this.
|
|
683
|
+
this.htmlController.moveNodeOnTop(t);
|
|
691
684
|
}
|
|
692
685
|
dragNode(t, e, o) {
|
|
693
|
-
if (!this.
|
|
686
|
+
if (!this.graphStore.hasNode(t))
|
|
694
687
|
throw new Error("failed to drag nonexisting node");
|
|
695
|
-
const s = this.
|
|
696
|
-
this.
|
|
688
|
+
const s = this.graphStore.getNode(t), [i, h] = this.viewportTransformer.getViewCoords(s.x, s.y), a = i + e, c = h + o, [l, g] = this.viewportTransformer.getAbsCoords(a, c);
|
|
689
|
+
this.graphStore.updateNodeCoords(t, l, g), this.htmlController.updateNodePosition(t);
|
|
697
690
|
}
|
|
698
|
-
addNode(t, e, o, s, i,
|
|
691
|
+
addNode(t, e, o, s, i, h) {
|
|
699
692
|
if (t === void 0)
|
|
700
693
|
do
|
|
701
|
-
t = this.
|
|
702
|
-
while (this.
|
|
703
|
-
if (this.
|
|
694
|
+
t = this.nodeIdGenerator.next();
|
|
695
|
+
while (this.graphStore.hasNode(t));
|
|
696
|
+
if (this.graphStore.hasNode(t))
|
|
704
697
|
throw new Error("failed to add node with existing id");
|
|
705
|
-
this.
|
|
698
|
+
this.graphStore.addNode(
|
|
706
699
|
t,
|
|
707
700
|
e,
|
|
708
701
|
o,
|
|
709
702
|
s,
|
|
710
|
-
|
|
711
|
-
), this.
|
|
712
|
-
|
|
713
|
-
a,
|
|
714
|
-
h,
|
|
715
|
-
t,
|
|
716
|
-
this.di.options.ports.centerFn,
|
|
717
|
-
null
|
|
718
|
-
) : this.di.controller.markPort(
|
|
703
|
+
h ?? this.nodesCenterFn
|
|
704
|
+
), this.htmlController.attachNode(t), i !== void 0 && Object.entries(i).forEach(([a, c]) => {
|
|
705
|
+
c instanceof HTMLElement ? this.markPort(a, c, t, this.portsCenterFn, null) : this.markPort(
|
|
719
706
|
a,
|
|
720
|
-
|
|
707
|
+
c.element,
|
|
721
708
|
t,
|
|
722
|
-
|
|
723
|
-
|
|
709
|
+
c.centerFn ?? this.portsCenterFn,
|
|
710
|
+
c.direction ?? null
|
|
724
711
|
);
|
|
725
712
|
});
|
|
726
713
|
}
|
|
727
714
|
markPort(t, e, o, s, i) {
|
|
728
715
|
if (t === void 0)
|
|
729
716
|
do
|
|
730
|
-
t = this.
|
|
731
|
-
while (this.
|
|
732
|
-
if (!this.
|
|
717
|
+
t = this.portIdGenerator.next();
|
|
718
|
+
while (this.graphStore.hasPort(t));
|
|
719
|
+
if (!this.graphStore.hasNode(o))
|
|
733
720
|
throw new Error("failed to set port on nonexisting node");
|
|
734
|
-
if (this.
|
|
721
|
+
if (this.graphStore.hasPort(t))
|
|
735
722
|
throw new Error("failed to add port with existing id");
|
|
736
|
-
this.
|
|
723
|
+
this.graphStore.addPort(
|
|
737
724
|
t,
|
|
738
725
|
e,
|
|
739
726
|
o,
|
|
740
|
-
s ?? this.
|
|
727
|
+
s ?? this.portsCenterFn,
|
|
741
728
|
i ?? null
|
|
742
729
|
);
|
|
743
730
|
}
|
|
744
731
|
updatePortConnections(t) {
|
|
745
|
-
if (!this.
|
|
732
|
+
if (!this.graphStore.hasPort(t))
|
|
746
733
|
throw new Error("failed to unset nonexisting port");
|
|
747
|
-
this.
|
|
734
|
+
this.htmlController.updatePortConnections(t);
|
|
748
735
|
}
|
|
749
736
|
unmarkPort(t) {
|
|
750
|
-
if (!this.
|
|
737
|
+
if (!this.graphStore.hasPort(t))
|
|
751
738
|
throw new Error("failed to unset nonexisting port");
|
|
752
|
-
this.
|
|
739
|
+
this.graphStore.getPortAdjacentConnections(t).forEach((e) => {
|
|
753
740
|
this.removeConnection(e);
|
|
754
|
-
}), this.
|
|
741
|
+
}), this.graphStore.removePort(t);
|
|
755
742
|
}
|
|
756
743
|
addConnection(t, e, o, s) {
|
|
757
744
|
if (t === void 0)
|
|
758
745
|
do
|
|
759
|
-
t = this.
|
|
760
|
-
while (this.
|
|
761
|
-
if (!this.
|
|
746
|
+
t = this.connectionIdGenerator.next();
|
|
747
|
+
while (this.graphStore.hasConnection(t));
|
|
748
|
+
if (!this.graphStore.hasPort(e))
|
|
762
749
|
throw new Error("failed to add connection from nonexisting port");
|
|
763
|
-
if (!this.
|
|
750
|
+
if (!this.graphStore.hasPort(o))
|
|
764
751
|
throw new Error("failed to add connection to nonexisting port");
|
|
765
|
-
this.
|
|
752
|
+
this.graphStore.addConnection(
|
|
766
753
|
t,
|
|
767
754
|
e,
|
|
768
755
|
o,
|
|
769
756
|
s($.Regular)
|
|
770
|
-
), this.
|
|
757
|
+
), this.htmlController.attachConnection(t);
|
|
771
758
|
}
|
|
772
759
|
removeConnection(t) {
|
|
773
|
-
if (!this.
|
|
760
|
+
if (!this.graphStore.hasConnection(t))
|
|
774
761
|
throw new Error("failed to remove nonexisting connection");
|
|
775
|
-
this.
|
|
762
|
+
this.htmlController.detachConnection(t), this.graphStore.removeConnection(t);
|
|
776
763
|
}
|
|
777
764
|
removeNode(t) {
|
|
778
|
-
if (!this.
|
|
765
|
+
if (!this.graphStore.hasNode(t))
|
|
779
766
|
throw new Error("failed to remove nonexisting node");
|
|
780
|
-
this.
|
|
767
|
+
this.htmlController.detachNode(t), this.graphStore.removeNode(t);
|
|
781
768
|
}
|
|
782
|
-
|
|
783
|
-
this.
|
|
769
|
+
patchViewportState(t, e, o) {
|
|
770
|
+
this.viewportTransformer.patchState(t, e, o), this.htmlController.applyTransform();
|
|
784
771
|
}
|
|
785
|
-
|
|
786
|
-
this.
|
|
772
|
+
moveViewport(t, e) {
|
|
773
|
+
this.viewportTransformer.applyShift(t, e), this.htmlController.applyTransform();
|
|
787
774
|
}
|
|
788
775
|
scaleContent(t, e, o) {
|
|
789
|
-
this.
|
|
776
|
+
this.viewportTransformer.applyScale(t, e, o), this.htmlController.applyTransform();
|
|
790
777
|
}
|
|
791
778
|
moveToNodes(t) {
|
|
792
779
|
if (t.length === 0)
|
|
793
780
|
return;
|
|
794
|
-
const e = t.map((
|
|
781
|
+
const e = t.map((m) => this.graphStore.getNode(m)).filter((m) => m !== void 0);
|
|
795
782
|
if (e.length < t.length)
|
|
796
783
|
throw new Error("failed to move to nonexisting node");
|
|
797
784
|
const [o, s] = e.reduce(
|
|
798
|
-
(
|
|
785
|
+
(m, u) => [m[0] + u.x, m[1] + u.y],
|
|
799
786
|
[0, 0]
|
|
800
|
-
), i = o / e.length,
|
|
801
|
-
this.
|
|
787
|
+
), i = o / e.length, h = s / e.length, [a, c] = this.htmlController.getViewportDimensions(), l = this.viewportTransformer.getAbsScale(), g = i - l * a / 2, d = h - l * c / 2;
|
|
788
|
+
this.patchViewportState(null, g, d);
|
|
802
789
|
}
|
|
803
790
|
updateNodeCoords(t, e, o) {
|
|
804
|
-
if (!this.
|
|
791
|
+
if (!this.graphStore.hasNode(t))
|
|
805
792
|
throw new Error("failed to update coordinates of nonexisting node");
|
|
806
|
-
this.
|
|
793
|
+
this.graphStore.updateNodeCoords(t, e, o), this.htmlController.updateNodePosition(t);
|
|
807
794
|
}
|
|
808
|
-
|
|
809
|
-
if (!this.
|
|
795
|
+
updateConnectionController(t, e) {
|
|
796
|
+
if (!this.graphStore.hasConnection(t))
|
|
810
797
|
throw new Error("failed to update nonexisting connection");
|
|
811
|
-
this.
|
|
798
|
+
this.htmlController.detachConnection(t), this.graphStore.updateConnectionController(t, e), this.htmlController.attachConnection(t);
|
|
799
|
+
}
|
|
800
|
+
attach(t) {
|
|
801
|
+
this.htmlController.attach(t);
|
|
802
|
+
}
|
|
803
|
+
detach() {
|
|
804
|
+
this.htmlController.detach();
|
|
812
805
|
}
|
|
813
806
|
clear() {
|
|
814
|
-
this.
|
|
807
|
+
this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.connectionIdGenerator.reset();
|
|
815
808
|
}
|
|
816
809
|
destroy() {
|
|
817
|
-
this.
|
|
810
|
+
this.htmlController.destroy();
|
|
818
811
|
}
|
|
819
812
|
}
|
|
820
813
|
class H {
|
|
821
|
-
constructor(t) {
|
|
814
|
+
constructor(t, e, o, s) {
|
|
822
815
|
r(this, "htmlController");
|
|
823
816
|
r(this, "viewportTransformer");
|
|
824
|
-
r(this, "publicViewportTransformer");
|
|
825
|
-
r(this, "controller");
|
|
826
817
|
r(this, "graphStore");
|
|
818
|
+
r(this, "publicViewportTransformer");
|
|
827
819
|
r(this, "publicGraphStore");
|
|
828
|
-
r(this, "
|
|
829
|
-
|
|
830
|
-
r(this, "connectionIdGenerator");
|
|
831
|
-
this.options = t, this.htmlController = new F(this), this.viewportTransformer = new W(), this.publicViewportTransformer = new D(
|
|
820
|
+
r(this, "canvasController");
|
|
821
|
+
this.viewportTransformer = new D(), this.publicViewportTransformer = new W(
|
|
832
822
|
this.viewportTransformer
|
|
833
|
-
), this.
|
|
823
|
+
), this.graphStore = new R(), this.publicGraphStore = new z(this.graphStore), this.htmlController = new j(
|
|
824
|
+
this.graphStore,
|
|
825
|
+
this.viewportTransformer,
|
|
826
|
+
this.publicViewportTransformer,
|
|
827
|
+
t,
|
|
828
|
+
e
|
|
829
|
+
), this.canvasController = new Z(
|
|
830
|
+
this.graphStore,
|
|
831
|
+
this.htmlController,
|
|
832
|
+
this.viewportTransformer,
|
|
833
|
+
o,
|
|
834
|
+
s
|
|
835
|
+
);
|
|
834
836
|
}
|
|
835
837
|
}
|
|
836
838
|
const P = (n, t) => [
|
|
@@ -838,17 +840,18 @@ const P = (n, t) => [
|
|
|
838
840
|
t / 2
|
|
839
841
|
], U = () => () => {
|
|
840
842
|
}, q = (n, t, e, o, s, i) => {
|
|
841
|
-
n.fillStyle = i, n.fillRect(0, 0, n.canvas.width, n.canvas.height);
|
|
842
|
-
const
|
|
843
|
-
let l = 0,
|
|
843
|
+
n.clearRect(0, 0, n.canvas.width, n.canvas.height), n.save(), n.fillStyle = i, n.fillRect(0, 0, n.canvas.width, n.canvas.height);
|
|
844
|
+
const h = t.getViewCoords(0, 0), a = t.getViewScale(), c = o * a;
|
|
845
|
+
let l = 0, g = 0, d = c / 2;
|
|
844
846
|
do
|
|
845
|
-
d *= 2, l = n.canvas.width / d,
|
|
846
|
-
while (l *
|
|
847
|
-
const
|
|
847
|
+
d *= 2, l = n.canvas.width / d, g = n.canvas.height / d;
|
|
848
|
+
while (l * g > 1e4);
|
|
849
|
+
const m = h[0] - Math.floor(h[0] / d) * d, u = h[1] - Math.floor(h[1] / d) * d, p = s * a, f = 2 * Math.PI, y = m - d, S = u - d, b = n.canvas.width + m, N = n.canvas.height + u;
|
|
848
850
|
n.fillStyle = e;
|
|
849
|
-
for (let
|
|
850
|
-
for (let w =
|
|
851
|
-
n.beginPath(), n.arc(
|
|
851
|
+
for (let C = y; C <= b; C += d)
|
|
852
|
+
for (let w = S; w <= N; w += d)
|
|
853
|
+
n.beginPath(), n.arc(C, w, p, 0, f), n.closePath(), n.fill();
|
|
854
|
+
n.restore();
|
|
852
855
|
}, J = (n, t, e, o) => (s, i) => {
|
|
853
856
|
q(
|
|
854
857
|
s,
|
|
@@ -878,7 +881,7 @@ const P = (n, t) => [
|
|
|
878
881
|
default:
|
|
879
882
|
return U();
|
|
880
883
|
}
|
|
881
|
-
},
|
|
884
|
+
}, O = (n) => {
|
|
882
885
|
switch (n == null ? void 0 : n.type) {
|
|
883
886
|
case "custom":
|
|
884
887
|
return n.controllerFactory;
|
|
@@ -918,7 +921,7 @@ const P = (n, t) => [
|
|
|
918
921
|
centerFn: ((e = n.ports) == null ? void 0 : e.centerFn) ?? P
|
|
919
922
|
},
|
|
920
923
|
connections: {
|
|
921
|
-
controllerFactory:
|
|
924
|
+
controllerFactory: O(
|
|
922
925
|
n.connections ?? {}
|
|
923
926
|
)
|
|
924
927
|
},
|
|
@@ -931,12 +934,19 @@ class tt {
|
|
|
931
934
|
constructor(t) {
|
|
932
935
|
r(this, "transformation");
|
|
933
936
|
r(this, "model");
|
|
934
|
-
r(this, "options");
|
|
935
937
|
r(this, "di");
|
|
936
|
-
|
|
938
|
+
r(this, "connectionControllerFactory");
|
|
939
|
+
this.apiOptions = t;
|
|
940
|
+
const e = I(this.apiOptions ?? {});
|
|
941
|
+
this.di = new H(
|
|
942
|
+
e.layers.mode,
|
|
943
|
+
e.background.drawingFn,
|
|
944
|
+
e.nodes.centerFn,
|
|
945
|
+
e.ports.centerFn
|
|
946
|
+
), this.transformation = this.di.publicViewportTransformer, this.model = this.di.publicGraphStore, this.connectionControllerFactory = e.connections.controllerFactory;
|
|
937
947
|
}
|
|
938
948
|
addNode(t) {
|
|
939
|
-
return this.di.
|
|
949
|
+
return this.di.canvasController.addNode(
|
|
940
950
|
t.id,
|
|
941
951
|
t.element,
|
|
942
952
|
t.x,
|
|
@@ -946,13 +956,13 @@ class tt {
|
|
|
946
956
|
), this;
|
|
947
957
|
}
|
|
948
958
|
moveNodeOnTop(t) {
|
|
949
|
-
return this.di.
|
|
959
|
+
return this.di.canvasController.moveNodeOnTop(t), this;
|
|
950
960
|
}
|
|
951
961
|
removeNode(t) {
|
|
952
|
-
return this.di.
|
|
962
|
+
return this.di.canvasController.removeNode(t), this;
|
|
953
963
|
}
|
|
954
964
|
markPort(t) {
|
|
955
|
-
return this.di.
|
|
965
|
+
return this.di.canvasController.markPort(
|
|
956
966
|
t.id,
|
|
957
967
|
t.element,
|
|
958
968
|
t.nodeId,
|
|
@@ -961,14 +971,14 @@ class tt {
|
|
|
961
971
|
), this;
|
|
962
972
|
}
|
|
963
973
|
updatePortConnections(t) {
|
|
964
|
-
return this.di.
|
|
974
|
+
return this.di.canvasController.updatePortConnections(t), this;
|
|
965
975
|
}
|
|
966
976
|
unmarkPort(t) {
|
|
967
|
-
return this.di.
|
|
977
|
+
return this.di.canvasController.unmarkPort(t), this;
|
|
968
978
|
}
|
|
969
979
|
addConnection(t) {
|
|
970
|
-
const e = t.options !== void 0 ?
|
|
971
|
-
return this.di.
|
|
980
|
+
const e = t.options !== void 0 ? O(t.options) : this.connectionControllerFactory;
|
|
981
|
+
return this.di.canvasController.addConnection(
|
|
972
982
|
t.id,
|
|
973
983
|
t.from,
|
|
974
984
|
t.to,
|
|
@@ -976,48 +986,54 @@ class tt {
|
|
|
976
986
|
), this;
|
|
977
987
|
}
|
|
978
988
|
removeConnection(t) {
|
|
979
|
-
return this.di.
|
|
989
|
+
return this.di.canvasController.removeConnection(t), this;
|
|
980
990
|
}
|
|
981
|
-
|
|
982
|
-
return this.di.
|
|
991
|
+
patchViewportState(t) {
|
|
992
|
+
return this.di.canvasController.patchViewportState(
|
|
983
993
|
t.scale ?? null,
|
|
984
994
|
t.x ?? null,
|
|
985
995
|
t.y ?? null
|
|
986
996
|
), this;
|
|
987
997
|
}
|
|
988
|
-
|
|
989
|
-
return this.di.
|
|
998
|
+
moveViewport(t) {
|
|
999
|
+
return this.di.canvasController.moveViewport(
|
|
1000
|
+
t.x ?? 0,
|
|
1001
|
+
t.y ?? 0
|
|
1002
|
+
), this;
|
|
990
1003
|
}
|
|
991
|
-
|
|
992
|
-
return this.di.
|
|
1004
|
+
scaleViewport(t) {
|
|
1005
|
+
return this.di.canvasController.scaleContent(
|
|
993
1006
|
t.scale,
|
|
994
1007
|
t.x ?? 0,
|
|
995
1008
|
t.y ?? 0
|
|
996
1009
|
), this;
|
|
997
1010
|
}
|
|
998
1011
|
moveToNodes(t) {
|
|
999
|
-
return this.di.
|
|
1012
|
+
return this.di.canvasController.moveToNodes(t), this;
|
|
1000
1013
|
}
|
|
1001
1014
|
updateNodeCoords(t, e, o) {
|
|
1002
|
-
return this.di.
|
|
1015
|
+
return this.di.canvasController.updateNodeCoords(t, e, o), this;
|
|
1003
1016
|
}
|
|
1004
|
-
|
|
1005
|
-
return this.di.
|
|
1017
|
+
updateConnection(t, e) {
|
|
1018
|
+
return e.controller !== void 0 && this.di.canvasController.updateConnectionController(
|
|
1019
|
+
t,
|
|
1020
|
+
e.controller
|
|
1021
|
+
), this;
|
|
1006
1022
|
}
|
|
1007
1023
|
dragNode(t, e, o) {
|
|
1008
|
-
return this.di.
|
|
1024
|
+
return this.di.canvasController.dragNode(t, e, o), this;
|
|
1009
1025
|
}
|
|
1010
1026
|
clear() {
|
|
1011
|
-
return this.di.
|
|
1027
|
+
return this.di.canvasController.clear(), this;
|
|
1012
1028
|
}
|
|
1013
1029
|
attach(t) {
|
|
1014
|
-
return this.di.
|
|
1030
|
+
return this.di.canvasController.attach(t), this;
|
|
1015
1031
|
}
|
|
1016
1032
|
detach() {
|
|
1017
|
-
return this.di.
|
|
1033
|
+
return this.di.canvasController.detach(), this;
|
|
1018
1034
|
}
|
|
1019
1035
|
destroy() {
|
|
1020
|
-
this.di.
|
|
1036
|
+
this.di.canvasController.destroy();
|
|
1021
1037
|
}
|
|
1022
1038
|
}
|
|
1023
1039
|
class et {
|
|
@@ -1100,14 +1116,14 @@ class et {
|
|
|
1100
1116
|
removeConnection(t) {
|
|
1101
1117
|
return this.canvas.removeConnection(t), this;
|
|
1102
1118
|
}
|
|
1103
|
-
|
|
1104
|
-
return this.canvas.
|
|
1119
|
+
patchViewportState(t) {
|
|
1120
|
+
return this.canvas.patchViewportState(t), this;
|
|
1105
1121
|
}
|
|
1106
|
-
|
|
1107
|
-
return this.canvas.
|
|
1122
|
+
moveViewport(t) {
|
|
1123
|
+
return this.canvas.moveViewport(t), this;
|
|
1108
1124
|
}
|
|
1109
|
-
|
|
1110
|
-
return this.canvas.
|
|
1125
|
+
scaleViewport(t) {
|
|
1126
|
+
return this.canvas.scaleViewport(t), this;
|
|
1111
1127
|
}
|
|
1112
1128
|
moveToNodes(t) {
|
|
1113
1129
|
return this.canvas.moveToNodes(t), this;
|
|
@@ -1115,8 +1131,8 @@ class et {
|
|
|
1115
1131
|
updateNodeCoords(t, e, o) {
|
|
1116
1132
|
return this.canvas.updateNodeCoords(t, e, o), this;
|
|
1117
1133
|
}
|
|
1118
|
-
|
|
1119
|
-
return this.canvas.
|
|
1134
|
+
updateConnection(t, e) {
|
|
1135
|
+
return this.canvas.updateConnection(t, e), this;
|
|
1120
1136
|
}
|
|
1121
1137
|
dragNode(t, e, o) {
|
|
1122
1138
|
return this.canvas.dragNode(t, e, o), this;
|
|
@@ -1130,7 +1146,7 @@ class et {
|
|
|
1130
1146
|
}), this.nodes.clear(), this;
|
|
1131
1147
|
}
|
|
1132
1148
|
attach(t) {
|
|
1133
|
-
return this.canvas.attach(t), this.element = t,
|
|
1149
|
+
return this.canvas.attach(t), this.element = t, this.element.addEventListener("mouseup", this.onCanvasMouseUp), this.element.addEventListener("mousemove", this.onCanvasMouseMove), this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.element.addEventListener("touchmove", this.onCanvasTouchMove), this.element.addEventListener("touchend", this.onCanvasTouchEnd), this.element.addEventListener("touchcancel", this.onCanvasTouchEnd), this;
|
|
1134
1150
|
}
|
|
1135
1151
|
detach() {
|
|
1136
1152
|
return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mouseup", this.onCanvasMouseUp), this.element.removeEventListener("mousemove", this.onCanvasMouseMove), this.element.removeEventListener("touchstart", this.onCanvasTouchStart), this.element.removeEventListener("touchmove", this.onCanvasTouchMove), this.element.removeEventListener("touchend", this.onCanvasTouchEnd), this.element.removeEventListener("touchcancel", this.onCanvasTouchEnd), this.element = null), this;
|
|
@@ -1160,7 +1176,7 @@ class ot {
|
|
|
1160
1176
|
this.setCursor("grab"), this.isMoving = !0;
|
|
1161
1177
|
});
|
|
1162
1178
|
r(this, "onMouseMove", (t) => {
|
|
1163
|
-
!this.isMoving || !this.isShiftable || this.canvas.
|
|
1179
|
+
!this.isMoving || !this.isShiftable || this.canvas.moveViewport({ x: -t.movementX, y: -t.movementY });
|
|
1164
1180
|
});
|
|
1165
1181
|
r(this, "onMouseUp", () => {
|
|
1166
1182
|
this.setCursor(null), this.isMoving = !1;
|
|
@@ -1169,8 +1185,8 @@ class ot {
|
|
|
1169
1185
|
if (this.element === null || this.isScalable === !1)
|
|
1170
1186
|
return;
|
|
1171
1187
|
t.preventDefault();
|
|
1172
|
-
const { left: e, top: o } = this.element.getBoundingClientRect(), s = t.clientX - e, i = t.clientY - o,
|
|
1173
|
-
this.checkNextScaleValid(a) && this.canvas.
|
|
1188
|
+
const { left: e, top: o } = this.element.getBoundingClientRect(), s = t.clientX - e, i = t.clientY - o, h = t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity, a = this.canvas.transformation.getViewScale() * h;
|
|
1189
|
+
this.checkNextScaleValid(a) && this.canvas.scaleViewport({ scale: 1 / h, x: s, y: i });
|
|
1174
1190
|
});
|
|
1175
1191
|
r(this, "onTouchStart", (t) => {
|
|
1176
1192
|
this.prevTouches = this.getAverageTouch(t);
|
|
@@ -1179,21 +1195,21 @@ class ot {
|
|
|
1179
1195
|
if (this.prevTouches === null || this.element === null || !this.isShiftable)
|
|
1180
1196
|
return;
|
|
1181
1197
|
const e = this.getAverageTouch(t);
|
|
1182
|
-
if ((e.touchesCnt === 1 || e.touchesCnt === 2) && this.canvas.
|
|
1183
|
-
x: e.x - this.prevTouches.x,
|
|
1184
|
-
y: e.y - this.prevTouches.y
|
|
1198
|
+
if ((e.touchesCnt === 1 || e.touchesCnt === 2) && this.canvas.moveViewport({
|
|
1199
|
+
x: -(e.x - this.prevTouches.x),
|
|
1200
|
+
y: -(e.y - this.prevTouches.y)
|
|
1185
1201
|
}), e.touchesCnt === 2 && this.isScalable) {
|
|
1186
|
-
const { left: o, top: s } = this.element.getBoundingClientRect(), i = this.prevTouches.x - o,
|
|
1187
|
-
this.checkNextScaleValid(
|
|
1202
|
+
const { left: o, top: s } = this.element.getBoundingClientRect(), i = this.prevTouches.x - o, h = this.prevTouches.y - s, a = e.scale / this.prevTouches.scale, c = this.canvas.transformation.getViewScale() * a;
|
|
1203
|
+
this.checkNextScaleValid(c) && this.canvas.scaleViewport({ scale: 1 / a, x: i, y: h });
|
|
1188
1204
|
}
|
|
1189
1205
|
this.prevTouches = e, t.preventDefault();
|
|
1190
1206
|
});
|
|
1191
1207
|
r(this, "onTouchEnd", () => {
|
|
1192
1208
|
this.prevTouches = null;
|
|
1193
1209
|
});
|
|
1194
|
-
var s, i,
|
|
1195
|
-
this.canvas = t, this.options = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((i = (s = this.options) == null ? void 0 : s.scale) == null ? void 0 : i.enabled) !== !1, this.minContentScale = ((a = (
|
|
1196
|
-
const o = (u = (
|
|
1210
|
+
var s, i, h, a, c, l, g, d, m, u;
|
|
1211
|
+
this.canvas = t, this.options = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((i = (s = this.options) == null ? void 0 : s.scale) == null ? void 0 : i.enabled) !== !1, this.minContentScale = ((a = (h = this.options) == null ? void 0 : h.scale) == null ? void 0 : a.minContent) ?? null, this.maxContentScale = ((l = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : l.maxContent) ?? null, this.isShiftable = ((d = (g = this.options) == null ? void 0 : g.shift) == null ? void 0 : d.enabled) !== !1;
|
|
1212
|
+
const o = (u = (m = this.options) == null ? void 0 : m.scale) == null ? void 0 : u.wheelSensitivity;
|
|
1197
1213
|
this.wheelSensitivity = o !== void 0 ? o : 1.2;
|
|
1198
1214
|
}
|
|
1199
1215
|
addNode(t) {
|
|
@@ -1217,14 +1233,14 @@ class ot {
|
|
|
1217
1233
|
removeConnection(t) {
|
|
1218
1234
|
return this.canvas.removeConnection(t), this;
|
|
1219
1235
|
}
|
|
1220
|
-
|
|
1221
|
-
return this.canvas.
|
|
1236
|
+
patchViewportState(t) {
|
|
1237
|
+
return this.canvas.patchViewportState(t), this;
|
|
1222
1238
|
}
|
|
1223
|
-
|
|
1224
|
-
return this.canvas.
|
|
1239
|
+
moveViewport(t) {
|
|
1240
|
+
return this.canvas.moveViewport(t), this;
|
|
1225
1241
|
}
|
|
1226
|
-
|
|
1227
|
-
return this.canvas.
|
|
1242
|
+
scaleViewport(t) {
|
|
1243
|
+
return this.canvas.scaleViewport(t), this;
|
|
1228
1244
|
}
|
|
1229
1245
|
moveToNodes(t) {
|
|
1230
1246
|
return this.canvas.moveToNodes(t), this;
|
|
@@ -1232,8 +1248,8 @@ class ot {
|
|
|
1232
1248
|
updateNodeCoords(t, e, o) {
|
|
1233
1249
|
return this.canvas.updateNodeCoords(t, e, o), this;
|
|
1234
1250
|
}
|
|
1235
|
-
|
|
1236
|
-
return this.canvas.
|
|
1251
|
+
updateConnection(t, e) {
|
|
1252
|
+
return this.canvas.updateConnection(t, e), this;
|
|
1237
1253
|
}
|
|
1238
1254
|
dragNode(t, e, o) {
|
|
1239
1255
|
return this.canvas.dragNode(t, e, o), this;
|
|
@@ -1245,7 +1261,7 @@ class ot {
|
|
|
1245
1261
|
return this.canvas.clear(), this;
|
|
1246
1262
|
}
|
|
1247
1263
|
attach(t) {
|
|
1248
|
-
return this.canvas.attach(t), this.element = t,
|
|
1264
|
+
return this.canvas.attach(t), this.element = t, this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("mousemove", this.onMouseMove), this.element.addEventListener("mouseup", this.onMouseUp), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.element.addEventListener("touchmove", this.onTouchMove), this.element.addEventListener("touchend", this.onTouchEnd), this.element.addEventListener("touchcancel", this.onTouchEnd), this;
|
|
1249
1265
|
}
|
|
1250
1266
|
detach() {
|
|
1251
1267
|
return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("mousemove", this.onMouseMove), this.element.removeEventListener("mouseup", this.onMouseUp), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("touchmove", this.onTouchMove), this.element.removeEventListener("touchend", this.onTouchEnd), this.element.removeEventListener("touchcancel", this.onTouchEnd)), this.element = null, this;
|
|
@@ -1255,13 +1271,13 @@ class ot {
|
|
|
1255
1271
|
}
|
|
1256
1272
|
getAverageTouch(t) {
|
|
1257
1273
|
const e = [], o = t.touches.length;
|
|
1258
|
-
for (let
|
|
1259
|
-
e.push([t.touches[
|
|
1274
|
+
for (let c = 0; c < o; c++)
|
|
1275
|
+
e.push([t.touches[c].clientX, t.touches[c].clientY]);
|
|
1260
1276
|
const s = e.reduce(
|
|
1261
|
-
(
|
|
1277
|
+
(c, l) => [c[0] + l[0], c[1] + l[1]],
|
|
1262
1278
|
[0, 0]
|
|
1263
|
-
), i = [s[0] / o, s[1] / o], a = e.map((
|
|
1264
|
-
(
|
|
1279
|
+
), i = [s[0] / o, s[1] / o], a = e.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
|
|
1280
|
+
(c, l) => c + Math.sqrt(l[0] * l[0] + l[1] * l[1]),
|
|
1265
1281
|
0
|
|
1266
1282
|
);
|
|
1267
1283
|
return { x: i[0], y: i[1], scale: a / o, touchesCnt: o };
|
|
@@ -1298,7 +1314,8 @@ class st {
|
|
|
1298
1314
|
export {
|
|
1299
1315
|
G as BezierConnectionController,
|
|
1300
1316
|
tt as CanvasCore,
|
|
1301
|
-
|
|
1317
|
+
$ as ConnectionType,
|
|
1318
|
+
v as ConnectionUtils,
|
|
1302
1319
|
et as DraggableNodesCanvas,
|
|
1303
1320
|
st as HtmlGraphBuilder,
|
|
1304
1321
|
Y as StraightConnectionController,
|