@html-graph/html-graph 0.0.61 → 0.1.1
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 +28 -41
- package/dist/main.d.ts +204 -217
- package/dist/main.js +1604 -1484
- package/dist/main.umd.cjs +1 -1
- package/package.json +2 -1
package/dist/main.js
CHANGED
|
@@ -1,764 +1,1076 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
var U = Object.defineProperty;
|
|
2
|
+
var K = (e, t, o) => t in e ? U(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
|
|
3
|
+
var s = (e, t, o) => K(e, typeof t != "symbol" ? t + "" : t, o);
|
|
4
|
+
const _ = (e, t) => ({
|
|
5
|
+
x: e / 2,
|
|
6
|
+
y: t / 2
|
|
7
|
+
}), f = (e, t, o) => ({
|
|
8
|
+
x: t.x * e.x - t.y * e.y + ((1 - t.x) * o.x + t.y * o.y),
|
|
9
|
+
y: t.y * e.x + t.x * e.y + ((1 - t.x) * o.y - t.y * o.x)
|
|
10
|
+
}), A = (e, t, o) => ({ x: t * Math.cos(e), y: o * Math.sin(e) }), u = {
|
|
11
|
+
x: 0,
|
|
12
|
+
y: 0
|
|
13
|
+
}, E = (e, t, o, r) => {
|
|
14
|
+
const n = [
|
|
15
|
+
u,
|
|
16
|
+
{ x: o, y: r },
|
|
17
|
+
{ x: o, y: -r }
|
|
18
|
+
].map((l) => f(l, e, u)).map((l) => ({ x: l.x + t.x, y: l.y + t.y })), d = `M ${n[0].x} ${n[0].y}`, c = `L ${n[1].x} ${n[1].y}`, h = `L ${n[2].x} ${n[2].y}`;
|
|
19
|
+
return `${d} ${c} ${h}`;
|
|
20
|
+
}, N = (e, t) => {
|
|
21
|
+
const o = [];
|
|
22
|
+
if (e.length > 0 && o.push(`M ${e[0].x} ${e[0].y}`), e.length === 2 && o.push(`L ${e[1].x} ${e[1].y}`), e.length > 2) {
|
|
23
|
+
const r = e.length - 1;
|
|
24
|
+
let i = 0, n = 0, d = 0;
|
|
25
|
+
e.forEach((c, h) => {
|
|
26
|
+
let l = 0, a = 0, w = 0;
|
|
27
|
+
const y = h > 0, x = h < r, v = y && x;
|
|
28
|
+
if (y && (l = -i, a = -n, w = d), x) {
|
|
29
|
+
const z = e[h + 1];
|
|
30
|
+
i = z.x - c.x, n = z.y - c.y, d = Math.sqrt(i * i + n * n);
|
|
31
|
+
}
|
|
32
|
+
const M = d !== 0 ? Math.min((v ? t : 0) / d, h < r - 1 ? 0.5 : 1) : 0, X = v ? { x: c.x + i * M, y: c.y + n * M } : c, k = w !== 0 ? Math.min((v ? t : 0) / w, h > 1 ? 0.5 : 1) : 0, B = v ? { x: c.x + l * k, y: c.y + a * k } : c;
|
|
33
|
+
h > 0 && o.push(`L ${B.x} ${B.y}`), v && o.push(
|
|
34
|
+
`C ${c.x} ${c.y} ${c.x} ${c.y} ${X.x} ${X.y}`
|
|
35
|
+
);
|
|
36
|
+
});
|
|
30
37
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
return o.join(" ");
|
|
39
|
+
}, I = () => {
|
|
40
|
+
const e = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
41
|
+
return e.style.pointerEvents = "none", e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.overflow = "visible", e;
|
|
42
|
+
}, $ = () => {
|
|
43
|
+
const e = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
44
|
+
return e.style.transformOrigin = "50% 50%", e;
|
|
45
|
+
}, m = (e, t) => {
|
|
46
|
+
const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
47
|
+
return o.setAttribute("stroke", e), o.setAttribute("stroke-width", `${t}`), o.setAttribute("fill", "none"), o;
|
|
48
|
+
}, T = (e) => {
|
|
49
|
+
const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
50
|
+
return t.setAttribute("fill", e), t;
|
|
51
|
+
}, p = (e, t) => {
|
|
52
|
+
const o = {
|
|
53
|
+
x: e.x + e.width / 2,
|
|
54
|
+
y: e.y + e.height / 2
|
|
55
|
+
}, r = {
|
|
56
|
+
x: t.x + t.width / 2,
|
|
57
|
+
y: t.y + t.height / 2
|
|
58
|
+
}, i = Math.min(o.x, r.x), n = Math.min(o.y, r.y), d = Math.abs(r.x - o.x), c = Math.abs(r.y - o.y), h = o.x <= r.x ? 1 : -1, l = o.y <= r.y ? 1 : -1;
|
|
59
|
+
return {
|
|
60
|
+
x: i,
|
|
61
|
+
y: n,
|
|
62
|
+
width: d,
|
|
63
|
+
height: c,
|
|
64
|
+
flipX: h,
|
|
65
|
+
flipY: l
|
|
66
|
+
};
|
|
67
|
+
}, J = (e) => {
|
|
68
|
+
const t = f(
|
|
69
|
+
{ x: e.arrowLength, y: u.y },
|
|
70
|
+
e.fromVect,
|
|
71
|
+
u
|
|
72
|
+
), o = f(
|
|
73
|
+
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
74
|
+
e.toVect,
|
|
75
|
+
e.to
|
|
76
|
+
), r = {
|
|
77
|
+
x: t.x + e.fromVect.x * e.curvature,
|
|
78
|
+
y: t.y + e.fromVect.y * e.curvature
|
|
79
|
+
}, i = {
|
|
80
|
+
x: o.x - e.toVect.x * e.curvature,
|
|
81
|
+
y: o.y - e.toVect.y * e.curvature
|
|
82
|
+
}, n = `M ${t.x} ${t.y} C ${r.x} ${r.y}, ${i.x} ${i.y}, ${o.x} ${o.y}`, d = e.hasSourceArrow ? "" : `M ${u.x} ${u.y} L ${t.x} ${t.y} `, c = e.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${e.to.x} ${e.to.y}`;
|
|
83
|
+
return `${d}${n}${c}`;
|
|
84
|
+
}, Q = (e) => {
|
|
85
|
+
const t = e.hasSourceArrow ? f(
|
|
86
|
+
{ x: e.arrowLength, y: u.y },
|
|
87
|
+
e.fromVect,
|
|
88
|
+
u
|
|
89
|
+
) : u, o = e.hasTargetArrow ? f(
|
|
90
|
+
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
91
|
+
e.toVect,
|
|
92
|
+
e.to
|
|
93
|
+
) : e.to, r = e.arrowLength, i = Math.cos(e.detourDirection) * e.detourDistance, n = Math.sin(e.detourDirection) * e.detourDistance, d = i * e.flipX, c = n * e.flipY, h = f(
|
|
94
|
+
{ x: r, y: u.y },
|
|
95
|
+
e.fromVect,
|
|
96
|
+
u
|
|
97
|
+
), l = {
|
|
98
|
+
x: h.x + d,
|
|
99
|
+
y: h.y + c
|
|
100
|
+
}, a = f(
|
|
101
|
+
{ x: e.to.x - r, y: e.to.y },
|
|
102
|
+
e.toVect,
|
|
103
|
+
e.to
|
|
104
|
+
), w = {
|
|
105
|
+
x: a.x + d,
|
|
106
|
+
y: a.y + c
|
|
107
|
+
}, y = { x: (l.x + w.x) / 2, y: (l.y + w.y) / 2 }, x = {
|
|
108
|
+
x: h.x + e.curvature * e.fromVect.x,
|
|
109
|
+
y: h.y + e.curvature * e.fromVect.y
|
|
110
|
+
}, v = {
|
|
111
|
+
x: a.x - e.curvature * e.toVect.x,
|
|
112
|
+
y: a.y - e.curvature * e.toVect.y
|
|
113
|
+
}, b = {
|
|
114
|
+
x: h.x + d,
|
|
115
|
+
y: h.y + c
|
|
116
|
+
}, M = {
|
|
117
|
+
x: a.x + d,
|
|
118
|
+
y: a.y + c
|
|
119
|
+
};
|
|
120
|
+
return [
|
|
121
|
+
`M ${t.x} ${t.y}`,
|
|
122
|
+
`L ${h.x} ${h.y}`,
|
|
123
|
+
`C ${x.x} ${x.y} ${b.x} ${b.y} ${y.x} ${y.y}`,
|
|
124
|
+
`C ${M.x} ${M.y} ${v.x} ${v.y} ${a.x} ${a.y}`,
|
|
125
|
+
`L ${o.x} ${o.y}`
|
|
126
|
+
].join(" ");
|
|
127
|
+
}, Z = (e) => {
|
|
128
|
+
const t = e.hasSourceArrow ? f(
|
|
129
|
+
{ x: e.arrowLength, y: u.y },
|
|
130
|
+
e.fromVect,
|
|
131
|
+
u
|
|
132
|
+
) : u, o = e.hasTargetArrow ? f(
|
|
133
|
+
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
134
|
+
e.toVect,
|
|
135
|
+
e.to
|
|
136
|
+
) : e.to, r = e.arrowLength + e.arrowOffset, i = r - e.roundness, n = f({ x: i, y: u.y }, e.fromVect, u), d = f(
|
|
137
|
+
{ x: e.to.x - i, y: e.to.y },
|
|
138
|
+
e.toVect,
|
|
139
|
+
e.to
|
|
140
|
+
), c = Math.max((n.x + d.x) / 2, r), h = e.to.y / 2, l = { x: e.flipX > 0 ? c : -r, y: n.y }, a = { x: l.x, y: h }, w = {
|
|
141
|
+
x: e.flipX > 0 ? e.to.x - c : e.to.x + r,
|
|
142
|
+
y: d.y
|
|
143
|
+
}, y = { x: w.x, y: h };
|
|
144
|
+
return N(
|
|
145
|
+
[t, n, l, a, y, w, d, o],
|
|
146
|
+
e.roundness
|
|
147
|
+
);
|
|
148
|
+
}, R = (e) => {
|
|
149
|
+
const t = e.hasSourceArrow ? f(
|
|
150
|
+
{ x: e.arrowLength, y: u.y },
|
|
151
|
+
e.fromVect,
|
|
152
|
+
u
|
|
153
|
+
) : u, o = e.hasTargetArrow ? f(
|
|
154
|
+
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
155
|
+
e.toVect,
|
|
156
|
+
e.to
|
|
157
|
+
) : e.to, r = e.arrowLength + e.arrowOffset, i = f(
|
|
158
|
+
{ x: r, y: u.y },
|
|
159
|
+
e.fromVect,
|
|
160
|
+
u
|
|
161
|
+
), n = Math.cos(e.detourDirection) * e.detourDistance, d = Math.sin(e.detourDirection) * e.detourDistance, c = n * e.flipX, h = d * e.flipY, l = { x: i.x + c, y: i.y + h }, a = f(
|
|
162
|
+
{ x: e.to.x - r, y: e.to.y },
|
|
163
|
+
e.toVect,
|
|
164
|
+
e.to
|
|
165
|
+
), w = { x: a.x + c, y: a.y + h };
|
|
166
|
+
return N(
|
|
167
|
+
[t, i, l, w, a, o],
|
|
168
|
+
e.roundness
|
|
169
|
+
);
|
|
170
|
+
}, q = (e) => {
|
|
171
|
+
const t = e.hasSourceArrow ? f(
|
|
172
|
+
{ x: e.arrowLength, y: u.y },
|
|
173
|
+
e.fromVect,
|
|
174
|
+
u
|
|
175
|
+
) : u, o = e.hasTargetArrow ? f(
|
|
176
|
+
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
177
|
+
e.toVect,
|
|
178
|
+
e.to
|
|
179
|
+
) : e.to, r = e.arrowLength + e.arrowOffset, i = f({ x: r, y: u.y }, e.fromVect, u), n = f(
|
|
180
|
+
{ x: e.to.x - r, y: e.to.y },
|
|
181
|
+
e.toVect,
|
|
182
|
+
e.to
|
|
183
|
+
);
|
|
184
|
+
return N([t, i, n, o], e.roundness);
|
|
185
|
+
}, tt = (e) => {
|
|
186
|
+
const t = e.hasSourceArrow ? f(
|
|
187
|
+
{ x: e.arrowLength, y: u.y },
|
|
188
|
+
e.fromVect,
|
|
189
|
+
u
|
|
190
|
+
) : u, o = e.hasTargetArrow ? f(
|
|
191
|
+
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
192
|
+
e.toVect,
|
|
193
|
+
e.to
|
|
194
|
+
) : e.to, r = e.arrowLength + e.arrowOffset, i = r - e.roundness, n = f({ x: i, y: u.y }, e.fromVect, u), d = f(
|
|
195
|
+
{ x: e.to.x - i, y: e.to.y },
|
|
196
|
+
e.toVect,
|
|
197
|
+
e.to
|
|
198
|
+
), c = Math.max((n.y + d.y) / 2, r), h = e.to.x / 2, l = { x: n.x, y: e.flipY > 0 ? c : -r }, a = { x: h, y: l.y }, w = {
|
|
199
|
+
x: d.x,
|
|
200
|
+
y: e.flipY > 0 ? e.to.y - c : e.to.y + r
|
|
201
|
+
}, y = { x: h, y: w.y };
|
|
202
|
+
return N(
|
|
203
|
+
[t, n, l, a, y, w, d, o],
|
|
204
|
+
e.roundness
|
|
205
|
+
);
|
|
206
|
+
}, Y = (e) => {
|
|
207
|
+
const t = e.arrowOffset, o = e.side, r = e.arrowLength + t, i = r + 2 * o, d = [
|
|
208
|
+
{ x: e.arrowLength, y: u.y },
|
|
209
|
+
{ x: r, y: u.y },
|
|
210
|
+
{ x: r, y: e.side },
|
|
211
|
+
{ x: i, y: e.side },
|
|
212
|
+
{ x: i, y: -e.side },
|
|
213
|
+
{ x: r, y: -e.side },
|
|
214
|
+
{ x: r, y: u.y },
|
|
215
|
+
{ x: e.arrowLength, y: u.y }
|
|
216
|
+
].map(
|
|
217
|
+
(h) => f(h, e.fromVect, u)
|
|
218
|
+
), c = `M ${u.x} ${u.y} L ${d[0].x} ${d[0].y} `;
|
|
219
|
+
return `${e.hasSourceArrow || e.hasTargetArrow ? "" : c}${N(d, e.roundness)}`;
|
|
220
|
+
}, et = (e) => {
|
|
221
|
+
const t = e.smallRadius, o = e.radius, r = Math.sqrt(t * t + o * o), i = t + o, n = e.arrowLength + r * (1 - o / i), d = t * o / i, h = [
|
|
222
|
+
{ x: e.arrowLength, y: u.y },
|
|
223
|
+
{ x: n, y: d },
|
|
224
|
+
{ x: n, y: -d }
|
|
225
|
+
].map((w) => f(w, e.fromVect, u)), l = [
|
|
226
|
+
`M ${h[0].x} ${h[0].y}`,
|
|
227
|
+
`A ${t} ${t} 0 0 1 ${h[1].x} ${h[1].y}`,
|
|
228
|
+
`A ${o} ${o} 0 1 0 ${h[2].x} ${h[2].y}`,
|
|
229
|
+
`A ${t} ${t} 0 0 1 ${h[0].x} ${h[0].y}`
|
|
230
|
+
].join(" "), a = `M 0 0 L ${h[0].x} ${h[0].y} `;
|
|
231
|
+
return `${e.hasSourceArrow || e.hasTargetArrow ? "" : a}${l}`;
|
|
232
|
+
}, g = Object.freeze({
|
|
233
|
+
color: "#5c5c5c",
|
|
234
|
+
width: 1,
|
|
235
|
+
arrowLength: 15,
|
|
236
|
+
arrowWidth: 4,
|
|
237
|
+
arrowOffset: 15,
|
|
238
|
+
hasSourceArrow: !1,
|
|
239
|
+
hasTargetArrow: !1,
|
|
240
|
+
cycleRadius: 30,
|
|
241
|
+
cycleSquareSide: 30,
|
|
242
|
+
roundness: 10,
|
|
243
|
+
detourDistance: 100,
|
|
244
|
+
detourDirection: -Math.PI / 2,
|
|
245
|
+
smallCycleRadius: 15,
|
|
246
|
+
curvature: 90
|
|
247
|
+
});
|
|
248
|
+
class ot {
|
|
249
|
+
constructor(t) {
|
|
250
|
+
s(this, "svg", I());
|
|
251
|
+
s(this, "group", $());
|
|
252
|
+
s(this, "line");
|
|
253
|
+
s(this, "sourceArrow", null);
|
|
254
|
+
s(this, "targetArrow", null);
|
|
255
|
+
s(this, "arrowLength");
|
|
256
|
+
s(this, "arrowWidth");
|
|
257
|
+
s(this, "curvature");
|
|
258
|
+
s(this, "portCycleRadius");
|
|
259
|
+
s(this, "portCycleSmallRadius");
|
|
260
|
+
s(this, "detourDirection");
|
|
261
|
+
s(this, "detourDistance");
|
|
262
|
+
s(this, "hasSourceArrow");
|
|
263
|
+
s(this, "hasTargetArrow");
|
|
264
|
+
this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? g.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? g.arrowWidth, this.curvature = (t == null ? void 0 : t.curvature) ?? g.curvature, this.portCycleRadius = (t == null ? void 0 : t.cycleRadius) ?? g.cycleRadius, this.portCycleSmallRadius = (t == null ? void 0 : t.smallCycleRadius) ?? g.smallCycleRadius, this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? g.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? g.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? g.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? g.hasTargetArrow;
|
|
265
|
+
const o = (t == null ? void 0 : t.color) ?? g.color, r = (t == null ? void 0 : t.width) ?? g.width;
|
|
266
|
+
this.svg.appendChild(this.group), this.line = m(o, r), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = T(o), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = T(o), this.group.appendChild(this.targetArrow));
|
|
267
|
+
}
|
|
268
|
+
render(t) {
|
|
269
|
+
const { x: o, y: r, width: i, height: n, flipX: d, flipY: c } = p(
|
|
270
|
+
t.source,
|
|
271
|
+
t.target
|
|
272
|
+
);
|
|
273
|
+
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${n}px`, this.group.style.transform = `scale(${d}, ${c})`;
|
|
274
|
+
const h = A(
|
|
275
|
+
t.source.direction,
|
|
276
|
+
d,
|
|
277
|
+
c
|
|
278
|
+
), l = A(
|
|
279
|
+
t.target.direction,
|
|
280
|
+
d,
|
|
281
|
+
c
|
|
282
|
+
), a = {
|
|
283
|
+
x: i,
|
|
284
|
+
y: n
|
|
285
|
+
};
|
|
286
|
+
let w, y = l, x = -this.arrowLength;
|
|
287
|
+
if (t.source.portId === t.target.portId ? (w = et({
|
|
288
|
+
fromVect: h,
|
|
289
|
+
radius: this.portCycleRadius,
|
|
290
|
+
smallRadius: this.portCycleSmallRadius,
|
|
291
|
+
arrowLength: this.arrowLength,
|
|
292
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
293
|
+
hasTargetArrow: this.hasTargetArrow
|
|
294
|
+
}), y = h, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? w = Q({
|
|
295
|
+
to: a,
|
|
296
|
+
fromVect: h,
|
|
297
|
+
toVect: l,
|
|
298
|
+
flipX: d,
|
|
299
|
+
flipY: c,
|
|
300
|
+
arrowLength: this.arrowLength,
|
|
301
|
+
detourDirection: this.detourDirection,
|
|
302
|
+
detourDistance: this.detourDistance,
|
|
303
|
+
curvature: this.curvature,
|
|
304
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
305
|
+
hasTargetArrow: this.hasTargetArrow
|
|
306
|
+
}) : w = J({
|
|
307
|
+
to: a,
|
|
308
|
+
fromVect: h,
|
|
309
|
+
toVect: l,
|
|
310
|
+
arrowLength: this.arrowLength,
|
|
311
|
+
curvature: this.curvature,
|
|
312
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
313
|
+
hasTargetArrow: this.hasTargetArrow
|
|
314
|
+
}), this.line.setAttribute("d", w), this.sourceArrow) {
|
|
315
|
+
const v = E(
|
|
316
|
+
h,
|
|
317
|
+
u,
|
|
318
|
+
this.arrowLength,
|
|
319
|
+
this.arrowWidth
|
|
320
|
+
);
|
|
321
|
+
this.sourceArrow.setAttribute("d", v);
|
|
322
|
+
}
|
|
323
|
+
if (this.targetArrow) {
|
|
324
|
+
const v = E(
|
|
325
|
+
y,
|
|
326
|
+
a,
|
|
327
|
+
x,
|
|
328
|
+
this.arrowWidth
|
|
329
|
+
);
|
|
330
|
+
this.targetArrow.setAttribute("d", v);
|
|
331
|
+
}
|
|
37
332
|
}
|
|
38
333
|
}
|
|
39
|
-
class
|
|
40
|
-
constructor(
|
|
41
|
-
this
|
|
334
|
+
class rt {
|
|
335
|
+
constructor(t) {
|
|
336
|
+
s(this, "svg", I());
|
|
337
|
+
s(this, "group", $());
|
|
338
|
+
s(this, "line");
|
|
339
|
+
s(this, "sourceArrow", null);
|
|
340
|
+
s(this, "targetArrow", null);
|
|
341
|
+
s(this, "arrowLength");
|
|
342
|
+
s(this, "arrowWidth");
|
|
343
|
+
s(this, "arrowOffset");
|
|
344
|
+
s(this, "roundness");
|
|
345
|
+
s(this, "cycleSquareSide");
|
|
346
|
+
s(this, "detourDirection");
|
|
347
|
+
s(this, "detourDistance");
|
|
348
|
+
s(this, "hasSourceArrow");
|
|
349
|
+
s(this, "hasTargetArrow");
|
|
350
|
+
this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? g.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? g.arrowWidth, this.arrowOffset = (t == null ? void 0 : t.arrowOffset) ?? g.arrowOffset, this.cycleSquareSide = (t == null ? void 0 : t.cycleSquareSide) ?? g.cycleSquareSide;
|
|
351
|
+
const o = (t == null ? void 0 : t.roundness) ?? g.roundness;
|
|
352
|
+
this.roundness = Math.min(
|
|
353
|
+
o,
|
|
354
|
+
this.arrowOffset,
|
|
355
|
+
this.cycleSquareSide / 2
|
|
356
|
+
), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? g.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? g.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? g.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? g.hasTargetArrow;
|
|
357
|
+
const r = (t == null ? void 0 : t.color) ?? g.color, i = (t == null ? void 0 : t.width) ?? g.width;
|
|
358
|
+
this.svg.appendChild(this.group), this.line = m(r, i), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = T(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = T(r), this.group.appendChild(this.targetArrow));
|
|
359
|
+
}
|
|
360
|
+
render(t) {
|
|
361
|
+
const { x: o, y: r, width: i, height: n, flipX: d, flipY: c } = p(
|
|
362
|
+
t.source,
|
|
363
|
+
t.target
|
|
364
|
+
);
|
|
365
|
+
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${n}px`, this.group.style.transform = `scale(${d}, ${c})`;
|
|
366
|
+
const h = A(
|
|
367
|
+
t.source.direction,
|
|
368
|
+
d,
|
|
369
|
+
c
|
|
370
|
+
), l = A(
|
|
371
|
+
t.target.direction,
|
|
372
|
+
d,
|
|
373
|
+
c
|
|
374
|
+
), a = {
|
|
375
|
+
x: i,
|
|
376
|
+
y: n
|
|
377
|
+
};
|
|
378
|
+
let w, y = l, x = -this.arrowLength;
|
|
379
|
+
if (t.source.portId === t.target.portId ? (w = Y({
|
|
380
|
+
fromVect: h,
|
|
381
|
+
arrowLength: this.arrowLength,
|
|
382
|
+
side: this.cycleSquareSide,
|
|
383
|
+
arrowOffset: this.arrowOffset,
|
|
384
|
+
roundness: this.roundness,
|
|
385
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
386
|
+
hasTargetArrow: this.hasTargetArrow
|
|
387
|
+
}), y = h, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? w = R({
|
|
388
|
+
to: a,
|
|
389
|
+
fromVect: h,
|
|
390
|
+
toVect: l,
|
|
391
|
+
flipX: d,
|
|
392
|
+
flipY: c,
|
|
393
|
+
arrowLength: this.arrowLength,
|
|
394
|
+
arrowOffset: this.arrowOffset,
|
|
395
|
+
roundness: this.roundness,
|
|
396
|
+
detourDirection: this.detourDirection,
|
|
397
|
+
detourDistance: this.detourDistance,
|
|
398
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
399
|
+
hasTargetArrow: this.hasTargetArrow
|
|
400
|
+
}) : w = Z({
|
|
401
|
+
to: a,
|
|
402
|
+
fromVect: h,
|
|
403
|
+
toVect: l,
|
|
404
|
+
flipX: d,
|
|
405
|
+
arrowLength: this.arrowLength,
|
|
406
|
+
arrowOffset: this.arrowOffset,
|
|
407
|
+
roundness: this.roundness,
|
|
408
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
409
|
+
hasTargetArrow: this.hasTargetArrow
|
|
410
|
+
}), this.line.setAttribute("d", w), this.sourceArrow) {
|
|
411
|
+
const v = E(
|
|
412
|
+
h,
|
|
413
|
+
u,
|
|
414
|
+
this.arrowLength,
|
|
415
|
+
this.arrowWidth
|
|
416
|
+
);
|
|
417
|
+
this.sourceArrow.setAttribute("d", v);
|
|
418
|
+
}
|
|
419
|
+
if (this.targetArrow) {
|
|
420
|
+
const v = E(
|
|
421
|
+
y,
|
|
422
|
+
a,
|
|
423
|
+
x,
|
|
424
|
+
this.arrowWidth
|
|
425
|
+
);
|
|
426
|
+
this.targetArrow.setAttribute("d", v);
|
|
427
|
+
}
|
|
42
428
|
}
|
|
43
|
-
|
|
44
|
-
|
|
429
|
+
}
|
|
430
|
+
class it {
|
|
431
|
+
constructor(t) {
|
|
432
|
+
s(this, "svg", I());
|
|
433
|
+
s(this, "group", $());
|
|
434
|
+
s(this, "line");
|
|
435
|
+
s(this, "sourceArrow", null);
|
|
436
|
+
s(this, "targetArrow", null);
|
|
437
|
+
s(this, "arrowLength");
|
|
438
|
+
s(this, "arrowWidth");
|
|
439
|
+
s(this, "arrowOffset");
|
|
440
|
+
s(this, "roundness");
|
|
441
|
+
s(this, "cycleSquareSide");
|
|
442
|
+
s(this, "detourDirection");
|
|
443
|
+
s(this, "detourDistance");
|
|
444
|
+
s(this, "hasSourceArrow");
|
|
445
|
+
s(this, "hasTargetArrow");
|
|
446
|
+
this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? g.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? g.arrowWidth, this.arrowOffset = (t == null ? void 0 : t.arrowOffset) ?? g.arrowOffset, this.cycleSquareSide = (t == null ? void 0 : t.cycleSquareSide) ?? g.cycleSquareSide;
|
|
447
|
+
const o = (t == null ? void 0 : t.roundness) ?? g.roundness;
|
|
448
|
+
this.roundness = Math.min(
|
|
449
|
+
o,
|
|
450
|
+
this.arrowOffset,
|
|
451
|
+
this.cycleSquareSide / 2
|
|
452
|
+
), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? g.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? g.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? g.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? g.hasTargetArrow;
|
|
453
|
+
const r = (t == null ? void 0 : t.color) ?? g.color, i = (t == null ? void 0 : t.width) ?? g.width;
|
|
454
|
+
this.svg.appendChild(this.group), this.line = m(r, i), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = T(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = T(r), this.group.appendChild(this.targetArrow));
|
|
455
|
+
}
|
|
456
|
+
render(t) {
|
|
457
|
+
const { x: o, y: r, width: i, height: n, flipX: d, flipY: c } = p(
|
|
458
|
+
t.source,
|
|
459
|
+
t.target
|
|
460
|
+
);
|
|
461
|
+
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${n}px`, this.group.style.transform = `scale(${d}, ${c})`;
|
|
462
|
+
const h = A(
|
|
463
|
+
t.source.direction,
|
|
464
|
+
d,
|
|
465
|
+
c
|
|
466
|
+
), l = A(
|
|
467
|
+
t.target.direction,
|
|
468
|
+
d,
|
|
469
|
+
c
|
|
470
|
+
), a = {
|
|
471
|
+
x: i,
|
|
472
|
+
y: n
|
|
473
|
+
};
|
|
474
|
+
let w, y = l, x = -this.arrowLength;
|
|
475
|
+
if (t.source.portId === t.target.portId ? (w = Y({
|
|
476
|
+
fromVect: h,
|
|
477
|
+
arrowLength: this.arrowLength,
|
|
478
|
+
side: this.cycleSquareSide,
|
|
479
|
+
arrowOffset: this.arrowOffset,
|
|
480
|
+
roundness: this.roundness,
|
|
481
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
482
|
+
hasTargetArrow: this.hasTargetArrow
|
|
483
|
+
}), y = h, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? w = R({
|
|
484
|
+
to: a,
|
|
485
|
+
fromVect: h,
|
|
486
|
+
toVect: l,
|
|
487
|
+
flipX: d,
|
|
488
|
+
flipY: c,
|
|
489
|
+
arrowLength: this.arrowLength,
|
|
490
|
+
arrowOffset: this.arrowOffset,
|
|
491
|
+
roundness: this.roundness,
|
|
492
|
+
detourDirection: this.detourDirection,
|
|
493
|
+
detourDistance: this.detourDistance,
|
|
494
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
495
|
+
hasTargetArrow: this.hasTargetArrow
|
|
496
|
+
}) : w = q({
|
|
497
|
+
to: a,
|
|
498
|
+
fromVect: h,
|
|
499
|
+
toVect: l,
|
|
500
|
+
arrowLength: this.arrowLength,
|
|
501
|
+
arrowOffset: this.arrowOffset,
|
|
502
|
+
roundness: this.roundness,
|
|
503
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
504
|
+
hasTargetArrow: this.hasTargetArrow
|
|
505
|
+
}), this.line.setAttribute("d", w), this.sourceArrow) {
|
|
506
|
+
const v = E(
|
|
507
|
+
h,
|
|
508
|
+
u,
|
|
509
|
+
this.arrowLength,
|
|
510
|
+
this.arrowWidth
|
|
511
|
+
);
|
|
512
|
+
this.sourceArrow.setAttribute("d", v);
|
|
513
|
+
}
|
|
514
|
+
if (this.targetArrow) {
|
|
515
|
+
const v = E(
|
|
516
|
+
y,
|
|
517
|
+
a,
|
|
518
|
+
x,
|
|
519
|
+
this.arrowWidth
|
|
520
|
+
);
|
|
521
|
+
this.targetArrow.setAttribute("d", v);
|
|
522
|
+
}
|
|
45
523
|
}
|
|
46
|
-
|
|
47
|
-
|
|
524
|
+
}
|
|
525
|
+
class nt {
|
|
526
|
+
constructor(t) {
|
|
527
|
+
s(this, "svg", I());
|
|
528
|
+
s(this, "group", $());
|
|
529
|
+
s(this, "line");
|
|
530
|
+
s(this, "sourceArrow", null);
|
|
531
|
+
s(this, "targetArrow", null);
|
|
532
|
+
s(this, "arrowLength");
|
|
533
|
+
s(this, "arrowWidth");
|
|
534
|
+
s(this, "arrowOffset");
|
|
535
|
+
s(this, "roundness");
|
|
536
|
+
s(this, "cycleSquareSide");
|
|
537
|
+
s(this, "detourDirection");
|
|
538
|
+
s(this, "detourDistance");
|
|
539
|
+
s(this, "hasSourceArrow");
|
|
540
|
+
s(this, "hasTargetArrow");
|
|
541
|
+
this.arrowLength = (t == null ? void 0 : t.arrowLength) ?? g.arrowLength, this.arrowWidth = (t == null ? void 0 : t.arrowWidth) ?? g.arrowWidth, this.arrowOffset = (t == null ? void 0 : t.arrowOffset) ?? g.arrowOffset, this.cycleSquareSide = (t == null ? void 0 : t.cycleSquareSide) ?? g.cycleSquareSide;
|
|
542
|
+
const o = (t == null ? void 0 : t.roundness) ?? g.roundness;
|
|
543
|
+
this.roundness = Math.min(
|
|
544
|
+
o,
|
|
545
|
+
this.arrowOffset,
|
|
546
|
+
this.cycleSquareSide / 2
|
|
547
|
+
), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? g.detourDirection, this.detourDistance = (t == null ? void 0 : t.detourDistance) ?? g.detourDistance, this.hasSourceArrow = (t == null ? void 0 : t.hasSourceArrow) ?? g.hasSourceArrow, this.hasTargetArrow = (t == null ? void 0 : t.hasTargetArrow) ?? g.hasTargetArrow;
|
|
548
|
+
const r = (t == null ? void 0 : t.color) ?? g.color, i = (t == null ? void 0 : t.width) ?? g.width;
|
|
549
|
+
this.svg.appendChild(this.group), this.line = m(r, i), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = T(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = T(r), this.group.appendChild(this.targetArrow));
|
|
550
|
+
}
|
|
551
|
+
render(t) {
|
|
552
|
+
const { x: o, y: r, width: i, height: n, flipX: d, flipY: c } = p(
|
|
553
|
+
t.source,
|
|
554
|
+
t.target
|
|
555
|
+
);
|
|
556
|
+
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${i}px`, this.svg.style.height = `${n}px`, this.group.style.transform = `scale(${d}, ${c})`;
|
|
557
|
+
const h = A(
|
|
558
|
+
t.source.direction,
|
|
559
|
+
d,
|
|
560
|
+
c
|
|
561
|
+
), l = A(
|
|
562
|
+
t.target.direction,
|
|
563
|
+
d,
|
|
564
|
+
c
|
|
565
|
+
), a = {
|
|
566
|
+
x: i,
|
|
567
|
+
y: n
|
|
568
|
+
};
|
|
569
|
+
let w, y = l, x = -this.arrowLength;
|
|
570
|
+
if (t.source.portId === t.target.portId ? (w = Y({
|
|
571
|
+
fromVect: h,
|
|
572
|
+
arrowLength: this.arrowLength,
|
|
573
|
+
side: this.cycleSquareSide,
|
|
574
|
+
arrowOffset: this.arrowOffset,
|
|
575
|
+
roundness: this.roundness,
|
|
576
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
577
|
+
hasTargetArrow: this.hasTargetArrow
|
|
578
|
+
}), y = h, x = this.arrowLength) : t.source.nodeId === t.target.nodeId ? w = R({
|
|
579
|
+
to: a,
|
|
580
|
+
fromVect: h,
|
|
581
|
+
toVect: l,
|
|
582
|
+
flipX: d,
|
|
583
|
+
flipY: c,
|
|
584
|
+
arrowLength: this.arrowLength,
|
|
585
|
+
arrowOffset: this.arrowOffset,
|
|
586
|
+
roundness: this.roundness,
|
|
587
|
+
detourDirection: this.detourDirection,
|
|
588
|
+
detourDistance: this.detourDistance,
|
|
589
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
590
|
+
hasTargetArrow: this.hasTargetArrow
|
|
591
|
+
}) : w = tt({
|
|
592
|
+
to: a,
|
|
593
|
+
fromVect: h,
|
|
594
|
+
toVect: l,
|
|
595
|
+
flipY: c,
|
|
596
|
+
arrowLength: this.arrowLength,
|
|
597
|
+
arrowOffset: this.arrowOffset,
|
|
598
|
+
roundness: this.roundness,
|
|
599
|
+
hasSourceArrow: this.hasSourceArrow,
|
|
600
|
+
hasTargetArrow: this.hasTargetArrow
|
|
601
|
+
}), this.line.setAttribute("d", w), this.sourceArrow) {
|
|
602
|
+
const v = E(
|
|
603
|
+
h,
|
|
604
|
+
u,
|
|
605
|
+
this.arrowLength,
|
|
606
|
+
this.arrowWidth
|
|
607
|
+
);
|
|
608
|
+
this.sourceArrow.setAttribute("d", v);
|
|
609
|
+
}
|
|
610
|
+
if (this.targetArrow) {
|
|
611
|
+
const v = E(
|
|
612
|
+
y,
|
|
613
|
+
a,
|
|
614
|
+
x,
|
|
615
|
+
this.arrowWidth
|
|
616
|
+
);
|
|
617
|
+
this.targetArrow.setAttribute("d", v);
|
|
618
|
+
}
|
|
48
619
|
}
|
|
49
620
|
}
|
|
50
|
-
|
|
621
|
+
const st = (e) => {
|
|
622
|
+
if (typeof e == "function")
|
|
623
|
+
return e;
|
|
624
|
+
switch (e == null ? void 0 : e.type) {
|
|
625
|
+
case "straight":
|
|
626
|
+
return () => new it({
|
|
627
|
+
color: e.color,
|
|
628
|
+
width: e.width,
|
|
629
|
+
arrowLength: e.arrowLength,
|
|
630
|
+
arrowWidth: e.arrowWidth,
|
|
631
|
+
arrowOffset: e.arrowOffset,
|
|
632
|
+
hasSourceArrow: e.hasSourceArrow,
|
|
633
|
+
hasTargetArrow: e.hasTargetArrow,
|
|
634
|
+
cycleSquareSide: e.cycleSquareSide,
|
|
635
|
+
roundness: e.roundness,
|
|
636
|
+
detourDistance: e.detourDistance,
|
|
637
|
+
detourDirection: e.detourDirection
|
|
638
|
+
});
|
|
639
|
+
case "horizontal":
|
|
640
|
+
return () => new rt({
|
|
641
|
+
color: e.color,
|
|
642
|
+
width: e.width,
|
|
643
|
+
arrowLength: e.arrowLength,
|
|
644
|
+
arrowWidth: e.arrowWidth,
|
|
645
|
+
arrowOffset: e.arrowOffset,
|
|
646
|
+
hasSourceArrow: e.hasSourceArrow,
|
|
647
|
+
hasTargetArrow: e.hasTargetArrow,
|
|
648
|
+
cycleSquareSide: e.cycleSquareSide,
|
|
649
|
+
roundness: e.roundness,
|
|
650
|
+
detourDistance: e.detourDistance,
|
|
651
|
+
detourDirection: e.detourDirection
|
|
652
|
+
});
|
|
653
|
+
case "vertical":
|
|
654
|
+
return () => new nt({
|
|
655
|
+
color: e.color,
|
|
656
|
+
width: e.width,
|
|
657
|
+
arrowLength: e.arrowLength,
|
|
658
|
+
arrowWidth: e.arrowWidth,
|
|
659
|
+
arrowOffset: e.arrowOffset,
|
|
660
|
+
hasSourceArrow: e.hasSourceArrow,
|
|
661
|
+
hasTargetArrow: e.hasTargetArrow,
|
|
662
|
+
cycleSquareSide: e.cycleSquareSide,
|
|
663
|
+
roundness: e.roundness,
|
|
664
|
+
detourDistance: e.detourDistance,
|
|
665
|
+
detourDirection: e.detourDirection
|
|
666
|
+
});
|
|
667
|
+
default:
|
|
668
|
+
return () => new ot({
|
|
669
|
+
color: e.color,
|
|
670
|
+
width: e.width,
|
|
671
|
+
arrowLength: e.arrowLength,
|
|
672
|
+
arrowWidth: e.arrowWidth,
|
|
673
|
+
hasSourceArrow: e.hasSourceArrow,
|
|
674
|
+
hasTargetArrow: e.hasTargetArrow,
|
|
675
|
+
cycleRadius: e.cycleRadius,
|
|
676
|
+
smallCycleRadius: e.smallCycleRadius,
|
|
677
|
+
curvature: e.curvature,
|
|
678
|
+
detourDistance: e.detourDistance,
|
|
679
|
+
detourDirection: e.detourDirection
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
}, F = (e) => () => e, G = F(0), V = () => {
|
|
683
|
+
let e = 0;
|
|
684
|
+
return () => e++;
|
|
685
|
+
}, ht = (e, t) => {
|
|
686
|
+
let o = G, r = G;
|
|
687
|
+
e === "incremental" && (o = V()), t === "incremental" && (r = V());
|
|
688
|
+
const i = V();
|
|
689
|
+
return e === "shared-incremental" && (o = i), t === "shared-incremental" && (r = i), typeof e == "number" && (o = F(e)), typeof t == "number" && (r = F(t)), typeof e == "function" && (o = e), typeof t == "function" && (r = t), {
|
|
690
|
+
nodesPriorityFn: o,
|
|
691
|
+
edgesPriorityFn: r
|
|
692
|
+
};
|
|
693
|
+
}, ct = (e) => {
|
|
694
|
+
var o, r, i, n, d;
|
|
695
|
+
const t = ht(
|
|
696
|
+
(o = e == null ? void 0 : e.nodes) == null ? void 0 : o.priority,
|
|
697
|
+
(r = e == null ? void 0 : e.edges) == null ? void 0 : r.priority
|
|
698
|
+
);
|
|
699
|
+
return {
|
|
700
|
+
nodes: {
|
|
701
|
+
centerFn: ((i = e == null ? void 0 : e.nodes) == null ? void 0 : i.centerFn) ?? _,
|
|
702
|
+
priorityFn: t.nodesPriorityFn
|
|
703
|
+
},
|
|
704
|
+
ports: {
|
|
705
|
+
direction: ((n = e == null ? void 0 : e.ports) == null ? void 0 : n.direction) ?? 0
|
|
706
|
+
},
|
|
707
|
+
edges: {
|
|
708
|
+
shapeFactory: st(((d = e == null ? void 0 : e.edges) == null ? void 0 : d.shape) ?? {}),
|
|
709
|
+
priorityFn: t.edgesPriorityFn
|
|
710
|
+
}
|
|
711
|
+
};
|
|
712
|
+
};
|
|
713
|
+
class dt {
|
|
51
714
|
constructor() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
addNode(
|
|
62
|
-
this.nodes.set(
|
|
63
|
-
element:
|
|
64
|
-
x:
|
|
65
|
-
y:
|
|
66
|
-
centerFn:
|
|
67
|
-
priority:
|
|
68
|
-
}), this.nodePorts.set(
|
|
715
|
+
s(this, "nodes", /* @__PURE__ */ new Map());
|
|
716
|
+
s(this, "ports", /* @__PURE__ */ new Map());
|
|
717
|
+
s(this, "nodePorts", /* @__PURE__ */ new Map());
|
|
718
|
+
s(this, "portNodeId", /* @__PURE__ */ new Map());
|
|
719
|
+
s(this, "edges", /* @__PURE__ */ new Map());
|
|
720
|
+
s(this, "incommingEdges", /* @__PURE__ */ new Map());
|
|
721
|
+
s(this, "outcommingEdges", /* @__PURE__ */ new Map());
|
|
722
|
+
s(this, "cycleEdges", /* @__PURE__ */ new Map());
|
|
723
|
+
}
|
|
724
|
+
addNode(t) {
|
|
725
|
+
this.nodes.set(t.nodeId, {
|
|
726
|
+
element: t.element,
|
|
727
|
+
x: t.x,
|
|
728
|
+
y: t.y,
|
|
729
|
+
centerFn: t.centerFn,
|
|
730
|
+
priority: t.priority
|
|
731
|
+
}), this.nodePorts.set(t.nodeId, /* @__PURE__ */ new Map());
|
|
69
732
|
}
|
|
70
733
|
getAllNodeIds() {
|
|
71
734
|
return Array.from(this.nodes.keys());
|
|
72
735
|
}
|
|
73
|
-
getNode(
|
|
74
|
-
return this.nodes.get(
|
|
736
|
+
getNode(t) {
|
|
737
|
+
return this.nodes.get(t);
|
|
75
738
|
}
|
|
76
|
-
removeNode(
|
|
77
|
-
this.nodes.delete(
|
|
739
|
+
removeNode(t) {
|
|
740
|
+
this.nodes.delete(t), this.nodePorts.delete(t);
|
|
78
741
|
}
|
|
79
|
-
addPort(
|
|
80
|
-
this.ports.set(
|
|
81
|
-
element:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}), this.cycleEdges.set(e.portId, /* @__PURE__ */ new Set()), this.incommingEdges.set(e.portId, /* @__PURE__ */ new Set()), this.outcommingEdges.set(e.portId, /* @__PURE__ */ new Set()), this.portNodeId.set(e.portId, e.nodeId), this.nodePorts.get(e.nodeId).set(e.portId, e.element);
|
|
742
|
+
addPort(t) {
|
|
743
|
+
this.ports.set(t.portId, {
|
|
744
|
+
element: t.element,
|
|
745
|
+
direction: t.direction
|
|
746
|
+
}), this.cycleEdges.set(t.portId, /* @__PURE__ */ new Set()), this.incommingEdges.set(t.portId, /* @__PURE__ */ new Set()), this.outcommingEdges.set(t.portId, /* @__PURE__ */ new Set()), this.portNodeId.set(t.portId, t.nodeId), this.nodePorts.get(t.nodeId).set(t.portId, t.element);
|
|
85
747
|
}
|
|
86
|
-
getPort(
|
|
87
|
-
return this.ports.get(
|
|
748
|
+
getPort(t) {
|
|
749
|
+
return this.ports.get(t);
|
|
88
750
|
}
|
|
89
751
|
getAllPortIds() {
|
|
90
752
|
return Array.from(this.ports.keys());
|
|
91
753
|
}
|
|
92
|
-
getNodePortIds(
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
return Array.from(
|
|
754
|
+
getNodePortIds(t) {
|
|
755
|
+
const o = this.nodePorts.get(t);
|
|
756
|
+
if (o !== void 0)
|
|
757
|
+
return Array.from(o.keys());
|
|
96
758
|
}
|
|
97
|
-
getPortNodeId(
|
|
98
|
-
return this.portNodeId.get(
|
|
759
|
+
getPortNodeId(t) {
|
|
760
|
+
return this.portNodeId.get(t);
|
|
99
761
|
}
|
|
100
|
-
removePort(
|
|
101
|
-
const
|
|
102
|
-
this.portNodeId.delete(
|
|
762
|
+
removePort(t) {
|
|
763
|
+
const o = this.portNodeId.get(t);
|
|
764
|
+
this.portNodeId.delete(t), this.nodePorts.get(o).delete(t), this.ports.delete(t);
|
|
103
765
|
}
|
|
104
|
-
addEdge(
|
|
105
|
-
this.edges.set(
|
|
106
|
-
from:
|
|
107
|
-
to:
|
|
108
|
-
shape:
|
|
109
|
-
priority:
|
|
110
|
-
}),
|
|
766
|
+
addEdge(t) {
|
|
767
|
+
this.edges.set(t.edgeId, {
|
|
768
|
+
from: t.from,
|
|
769
|
+
to: t.to,
|
|
770
|
+
shape: t.shape,
|
|
771
|
+
priority: t.priority
|
|
772
|
+
}), t.from !== t.to ? (this.outcommingEdges.get(t.from).add(t.edgeId), this.incommingEdges.get(t.to).add(t.edgeId)) : this.cycleEdges.get(t.from).add(t.edgeId);
|
|
773
|
+
}
|
|
774
|
+
updateEdgeFrom(t, o) {
|
|
775
|
+
const r = this.edges.get(t);
|
|
776
|
+
this.removeEdge(t), this.addEdge({
|
|
777
|
+
edgeId: t,
|
|
778
|
+
from: o,
|
|
779
|
+
to: r.to,
|
|
780
|
+
shape: r.shape,
|
|
781
|
+
priority: r.priority
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
updateEdgeTo(t, o) {
|
|
785
|
+
const r = this.edges.get(t);
|
|
786
|
+
this.removeEdge(t), this.addEdge({
|
|
787
|
+
edgeId: t,
|
|
788
|
+
from: r.from,
|
|
789
|
+
to: o,
|
|
790
|
+
shape: r.shape,
|
|
791
|
+
priority: r.priority
|
|
792
|
+
});
|
|
111
793
|
}
|
|
112
794
|
getAllEdgeIds() {
|
|
113
795
|
return Array.from(this.edges.keys());
|
|
114
796
|
}
|
|
115
|
-
getEdge(
|
|
116
|
-
return this.edges.get(
|
|
797
|
+
getEdge(t) {
|
|
798
|
+
return this.edges.get(t);
|
|
117
799
|
}
|
|
118
|
-
removeEdge(
|
|
119
|
-
const
|
|
120
|
-
this.cycleEdges.get(
|
|
800
|
+
removeEdge(t) {
|
|
801
|
+
const o = this.edges.get(t), r = o.from, i = o.to;
|
|
802
|
+
this.cycleEdges.get(r).delete(t), this.cycleEdges.get(i).delete(t), this.incommingEdges.get(r).delete(t), this.incommingEdges.get(i).delete(t), this.outcommingEdges.get(r).delete(t), this.outcommingEdges.get(i).delete(t), this.edges.delete(t);
|
|
121
803
|
}
|
|
122
804
|
clear() {
|
|
123
805
|
this.nodes.clear(), this.ports.clear(), this.nodePorts.clear(), this.portNodeId.clear(), this.edges.clear(), this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear();
|
|
124
806
|
}
|
|
125
|
-
getPortIncomingEdgeIds(
|
|
126
|
-
return Array.from(this.incommingEdges.get(
|
|
807
|
+
getPortIncomingEdgeIds(t) {
|
|
808
|
+
return Array.from(this.incommingEdges.get(t));
|
|
127
809
|
}
|
|
128
|
-
getPortOutcomingEdgeIds(
|
|
129
|
-
return Array.from(this.outcommingEdges.get(
|
|
810
|
+
getPortOutcomingEdgeIds(t) {
|
|
811
|
+
return Array.from(this.outcommingEdges.get(t));
|
|
130
812
|
}
|
|
131
|
-
getPortCycleEdgeIds(
|
|
132
|
-
return Array.from(this.cycleEdges.get(
|
|
813
|
+
getPortCycleEdgeIds(t) {
|
|
814
|
+
return Array.from(this.cycleEdges.get(t));
|
|
133
815
|
}
|
|
134
|
-
getPortAdjacentEdgeIds(
|
|
816
|
+
getPortAdjacentEdgeIds(t) {
|
|
135
817
|
return [
|
|
136
|
-
...this.getPortIncomingEdgeIds(
|
|
137
|
-
...this.getPortOutcomingEdgeIds(
|
|
138
|
-
...this.getPortCycleEdgeIds(
|
|
818
|
+
...this.getPortIncomingEdgeIds(t),
|
|
819
|
+
...this.getPortOutcomingEdgeIds(t),
|
|
820
|
+
...this.getPortCycleEdgeIds(t)
|
|
139
821
|
];
|
|
140
822
|
}
|
|
141
|
-
getNodeIncomingEdgeIds(
|
|
142
|
-
const
|
|
143
|
-
let
|
|
144
|
-
return
|
|
145
|
-
|
|
146
|
-
}),
|
|
147
|
-
}
|
|
148
|
-
getNodeOutcomingEdgeIds(
|
|
149
|
-
const
|
|
150
|
-
let
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
}),
|
|
154
|
-
}
|
|
155
|
-
getNodeCycleEdgeIds(
|
|
156
|
-
const
|
|
157
|
-
let
|
|
158
|
-
return
|
|
159
|
-
|
|
160
|
-
}),
|
|
161
|
-
}
|
|
162
|
-
getNodeAdjacentEdgeIds(
|
|
823
|
+
getNodeIncomingEdgeIds(t) {
|
|
824
|
+
const o = Array.from(this.nodePorts.get(t).keys());
|
|
825
|
+
let r = [];
|
|
826
|
+
return o.forEach((i) => {
|
|
827
|
+
r = [...r, ...this.getPortIncomingEdgeIds(i)];
|
|
828
|
+
}), r;
|
|
829
|
+
}
|
|
830
|
+
getNodeOutcomingEdgeIds(t) {
|
|
831
|
+
const o = Array.from(this.nodePorts.get(t).keys());
|
|
832
|
+
let r = [];
|
|
833
|
+
return o.forEach((i) => {
|
|
834
|
+
r = [...r, ...this.getPortOutcomingEdgeIds(i)];
|
|
835
|
+
}), r;
|
|
836
|
+
}
|
|
837
|
+
getNodeCycleEdgeIds(t) {
|
|
838
|
+
const o = Array.from(this.nodePorts.get(t).keys());
|
|
839
|
+
let r = [];
|
|
840
|
+
return o.forEach((i) => {
|
|
841
|
+
r = [...r, ...this.getPortCycleEdgeIds(i)];
|
|
842
|
+
}), r;
|
|
843
|
+
}
|
|
844
|
+
getNodeAdjacentEdgeIds(t) {
|
|
163
845
|
return [
|
|
164
|
-
...this.getNodeIncomingEdgeIds(
|
|
165
|
-
...this.getNodeOutcomingEdgeIds(
|
|
166
|
-
...this.getNodeCycleEdgeIds(
|
|
846
|
+
...this.getNodeIncomingEdgeIds(t),
|
|
847
|
+
...this.getNodeOutcomingEdgeIds(t),
|
|
848
|
+
...this.getNodeCycleEdgeIds(t)
|
|
167
849
|
];
|
|
168
850
|
}
|
|
169
851
|
}
|
|
170
|
-
class
|
|
171
|
-
constructor(
|
|
172
|
-
this.graphStore =
|
|
852
|
+
class lt {
|
|
853
|
+
constructor(t) {
|
|
854
|
+
this.graphStore = t;
|
|
173
855
|
}
|
|
174
|
-
getNode(
|
|
175
|
-
const
|
|
176
|
-
return
|
|
177
|
-
element:
|
|
178
|
-
x:
|
|
179
|
-
y:
|
|
180
|
-
centerFn:
|
|
181
|
-
priority:
|
|
856
|
+
getNode(t) {
|
|
857
|
+
const o = this.graphStore.getNode(t);
|
|
858
|
+
return o === void 0 ? null : {
|
|
859
|
+
element: o.element,
|
|
860
|
+
x: o.x,
|
|
861
|
+
y: o.y,
|
|
862
|
+
centerFn: o.centerFn,
|
|
863
|
+
priority: o.priority
|
|
182
864
|
};
|
|
183
865
|
}
|
|
184
866
|
getAllNodeIds() {
|
|
185
867
|
return this.graphStore.getAllNodeIds();
|
|
186
868
|
}
|
|
187
|
-
getPort(
|
|
188
|
-
const
|
|
189
|
-
return
|
|
190
|
-
element:
|
|
191
|
-
|
|
192
|
-
direction: t.direction
|
|
869
|
+
getPort(t) {
|
|
870
|
+
const o = this.graphStore.getPort(t);
|
|
871
|
+
return o === void 0 ? null : {
|
|
872
|
+
element: o.element,
|
|
873
|
+
direction: o.direction
|
|
193
874
|
};
|
|
194
875
|
}
|
|
195
876
|
getAllPortIds() {
|
|
196
877
|
return this.graphStore.getAllPortIds();
|
|
197
878
|
}
|
|
198
|
-
getNodePortIds(
|
|
199
|
-
return this.graphStore.getNodePortIds(
|
|
879
|
+
getNodePortIds(t) {
|
|
880
|
+
return this.graphStore.getNodePortIds(t);
|
|
200
881
|
}
|
|
201
|
-
getPortNodeId(
|
|
202
|
-
return this.graphStore.getPortNodeId(
|
|
882
|
+
getPortNodeId(t) {
|
|
883
|
+
return this.graphStore.getPortNodeId(t) ?? null;
|
|
203
884
|
}
|
|
204
885
|
getAllEdgeIds() {
|
|
205
886
|
return this.graphStore.getAllEdgeIds();
|
|
206
887
|
}
|
|
207
|
-
getEdge(
|
|
208
|
-
const
|
|
209
|
-
return
|
|
888
|
+
getEdge(t) {
|
|
889
|
+
const o = this.graphStore.getEdge(t);
|
|
890
|
+
return o === void 0 ? null : { from: o.from, to: o.to, priority: o.priority };
|
|
210
891
|
}
|
|
211
|
-
getPortIncomingEdgeIds(
|
|
212
|
-
return this.graphStore.getPortIncomingEdgeIds(
|
|
892
|
+
getPortIncomingEdgeIds(t) {
|
|
893
|
+
return this.graphStore.getPortIncomingEdgeIds(t);
|
|
213
894
|
}
|
|
214
|
-
getPortOutcomingEdgeIds(
|
|
215
|
-
return this.graphStore.getPortOutcomingEdgeIds(
|
|
895
|
+
getPortOutcomingEdgeIds(t) {
|
|
896
|
+
return this.graphStore.getPortOutcomingEdgeIds(t);
|
|
216
897
|
}
|
|
217
|
-
getPortCycleEdgeIds(
|
|
218
|
-
return this.graphStore.getPortCycleEdgeIds(
|
|
898
|
+
getPortCycleEdgeIds(t) {
|
|
899
|
+
return this.graphStore.getPortCycleEdgeIds(t);
|
|
219
900
|
}
|
|
220
|
-
getPortAdjacentEdgeIds(
|
|
221
|
-
return this.graphStore.getPortAdjacentEdgeIds(
|
|
901
|
+
getPortAdjacentEdgeIds(t) {
|
|
902
|
+
return this.graphStore.getPortAdjacentEdgeIds(t);
|
|
222
903
|
}
|
|
223
|
-
getNodeIncomingEdgeIds(
|
|
224
|
-
return this.graphStore.getNodeIncomingEdgeIds(
|
|
904
|
+
getNodeIncomingEdgeIds(t) {
|
|
905
|
+
return this.graphStore.getNodeIncomingEdgeIds(t);
|
|
225
906
|
}
|
|
226
|
-
getNodeOutcomingEdgeIds(
|
|
227
|
-
return this.graphStore.getNodeOutcomingEdgeIds(
|
|
907
|
+
getNodeOutcomingEdgeIds(t) {
|
|
908
|
+
return this.graphStore.getNodeOutcomingEdgeIds(t);
|
|
228
909
|
}
|
|
229
|
-
getNodeCycleEdgeIds(
|
|
230
|
-
return this.graphStore.getNodeCycleEdgeIds(
|
|
910
|
+
getNodeCycleEdgeIds(t) {
|
|
911
|
+
return this.graphStore.getNodeCycleEdgeIds(t);
|
|
231
912
|
}
|
|
232
|
-
getNodeAdjacentEdgeIds(
|
|
233
|
-
return this.graphStore.getNodeAdjacentEdgeIds(
|
|
913
|
+
getNodeAdjacentEdgeIds(t) {
|
|
914
|
+
return this.graphStore.getNodeAdjacentEdgeIds(t);
|
|
234
915
|
}
|
|
235
916
|
}
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
l,
|
|
245
|
-
{ x: t, y: s },
|
|
246
|
-
{ x: t, y: -s }
|
|
247
|
-
].map((c) => p(c, r, l)).map((c) => ({ x: c.x + e.x, y: c.y + e.y })), h = `M ${i[0].x} ${i[0].y}`, a = `L ${i[1].x} ${i[1].y}`, d = `L ${i[2].x} ${i[2].y}`;
|
|
248
|
-
return `${h} ${a} ${d}`;
|
|
249
|
-
}, D = (r, e) => {
|
|
250
|
-
const t = [];
|
|
251
|
-
if (r.length > 0 && t.push(`M ${r[0].x} ${r[0].y}`), r.length === 2 && t.push(`L ${r[1].x} ${r[1].y}`), r.length > 2) {
|
|
252
|
-
const s = r.length - 1;
|
|
253
|
-
let o = 0, i = 0, h = 0;
|
|
254
|
-
r.forEach((a, d) => {
|
|
255
|
-
let c = 0, u = 0, w = 0;
|
|
256
|
-
const m = d > 0, y = d < s, v = m && y;
|
|
257
|
-
if (m && (c = -o, u = -i, w = h), y) {
|
|
258
|
-
const j = r[d + 1];
|
|
259
|
-
o = j.x - a.x, i = j.y - a.y, h = Math.sqrt(o * o + i * i);
|
|
260
|
-
}
|
|
261
|
-
const S = h !== 0 ? Math.min((v ? e : 0) / h, d < s - 1 ? 0.5 : 1) : 0, M = v ? { x: a.x + o * S, y: a.y + i * S } : a, T = w !== 0 ? Math.min((v ? e : 0) / w, d > 1 ? 0.5 : 1) : 0, F = v ? { x: a.x + c * T, y: a.y + u * T } : a;
|
|
262
|
-
d > 0 && t.push(`L ${F.x} ${F.y}`), v && t.push(
|
|
263
|
-
`C ${a.x} ${a.y} ${a.x} ${a.y} ${M.x} ${M.y}`
|
|
264
|
-
);
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
return t.join(" ");
|
|
268
|
-
}, N = () => {
|
|
269
|
-
const r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
270
|
-
return r.style.pointerEvents = "none", r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.overflow = "visible", r;
|
|
271
|
-
}, $ = () => {
|
|
272
|
-
const r = document.createElementNS("http://www.w3.org/2000/svg", "g");
|
|
273
|
-
return r.style.transformOrigin = "50% 50%", r;
|
|
274
|
-
}, L = (r, e) => {
|
|
275
|
-
const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
276
|
-
return t.setAttribute("stroke", r), t.setAttribute("stroke-width", `${e}`), t.setAttribute("fill", "none"), t;
|
|
277
|
-
}, A = (r) => {
|
|
278
|
-
const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
279
|
-
return e.setAttribute("fill", r), e;
|
|
917
|
+
const j = (e) => ({
|
|
918
|
+
scale: 1 / e.scale,
|
|
919
|
+
dx: -e.dx / e.scale,
|
|
920
|
+
dy: -e.dy / e.scale
|
|
921
|
+
}), H = {
|
|
922
|
+
scale: 1,
|
|
923
|
+
dx: 0,
|
|
924
|
+
dy: 0
|
|
280
925
|
};
|
|
281
|
-
class
|
|
282
|
-
constructor(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
n(this, "line");
|
|
286
|
-
n(this, "sourceArrow", null);
|
|
287
|
-
n(this, "targetArrow", null);
|
|
288
|
-
this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
|
|
289
|
-
}
|
|
290
|
-
update(e, t, s, o, i) {
|
|
291
|
-
this.group.style.transform = `scale(${t}, ${s})`;
|
|
292
|
-
const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a);
|
|
293
|
-
if (this.line.setAttribute("d", d), this.sourceArrow) {
|
|
294
|
-
const c = E(
|
|
295
|
-
h,
|
|
296
|
-
l,
|
|
297
|
-
this.arrowLength,
|
|
298
|
-
this.arrowWidth
|
|
299
|
-
);
|
|
300
|
-
this.sourceArrow.setAttribute("d", c);
|
|
301
|
-
}
|
|
302
|
-
if (this.targetArrow) {
|
|
303
|
-
const c = E(
|
|
304
|
-
a,
|
|
305
|
-
e,
|
|
306
|
-
-this.arrowLength,
|
|
307
|
-
this.arrowWidth
|
|
308
|
-
);
|
|
309
|
-
this.targetArrow.setAttribute("d", c);
|
|
310
|
-
}
|
|
926
|
+
class at {
|
|
927
|
+
constructor() {
|
|
928
|
+
s(this, "viewportMatrix", H);
|
|
929
|
+
s(this, "contentMatrix", H);
|
|
311
930
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
{ x: this.arrowLength, y: l.y },
|
|
315
|
-
t,
|
|
316
|
-
l
|
|
317
|
-
), i = p(
|
|
318
|
-
{ x: e.x - this.arrowLength, y: e.y },
|
|
319
|
-
s,
|
|
320
|
-
e
|
|
321
|
-
), h = {
|
|
322
|
-
x: o.x + t.x * this.curvature,
|
|
323
|
-
y: o.y + t.y * this.curvature
|
|
324
|
-
}, a = {
|
|
325
|
-
x: i.x - s.x * this.curvature,
|
|
326
|
-
y: i.y - s.y * this.curvature
|
|
327
|
-
}, d = `M ${o.x} ${o.y} C ${h.x} ${h.y}, ${a.x} ${a.y}, ${i.x} ${i.y}`, c = this.sourceArrow ? "" : `M ${l.x} ${l.y} L ${o.x} ${o.y} `, u = this.targetArrow ? "" : ` M ${i.x} ${i.y} L ${e.x} ${e.y}`;
|
|
328
|
-
return `${c}${d}${u}`;
|
|
931
|
+
getViewportMatrix() {
|
|
932
|
+
return this.viewportMatrix;
|
|
329
933
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
constructor(e, t, s, o, i, h, a, d) {
|
|
333
|
-
n(this, "svg", N());
|
|
334
|
-
n(this, "group", $());
|
|
335
|
-
n(this, "line");
|
|
336
|
-
n(this, "sourceArrow", null);
|
|
337
|
-
n(this, "targetArrow", null);
|
|
338
|
-
this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = d, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
|
|
339
|
-
}
|
|
340
|
-
update(e, t, s, o, i) {
|
|
341
|
-
this.group.style.transform = `scale(${t}, ${s})`;
|
|
342
|
-
const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a);
|
|
343
|
-
if (this.line.setAttribute("d", d), this.sourceArrow) {
|
|
344
|
-
const c = E(
|
|
345
|
-
h,
|
|
346
|
-
l,
|
|
347
|
-
this.arrowLength,
|
|
348
|
-
this.arrowWidth
|
|
349
|
-
);
|
|
350
|
-
this.sourceArrow.setAttribute("d", c);
|
|
351
|
-
}
|
|
352
|
-
if (this.targetArrow) {
|
|
353
|
-
const c = E(
|
|
354
|
-
a,
|
|
355
|
-
e,
|
|
356
|
-
-this.arrowLength,
|
|
357
|
-
this.arrowWidth
|
|
358
|
-
);
|
|
359
|
-
this.targetArrow.setAttribute("d", c);
|
|
360
|
-
}
|
|
934
|
+
getContentMatrix() {
|
|
935
|
+
return this.contentMatrix;
|
|
361
936
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
937
|
+
patchViewportMatrix(t) {
|
|
938
|
+
this.viewportMatrix = {
|
|
939
|
+
scale: t.scale ?? this.viewportMatrix.scale,
|
|
940
|
+
dx: t.dx ?? this.viewportMatrix.dx,
|
|
941
|
+
dy: t.dy ?? this.viewportMatrix.dy
|
|
942
|
+
}, this.contentMatrix = j(this.viewportMatrix);
|
|
943
|
+
}
|
|
944
|
+
patchContentMatrix(t) {
|
|
945
|
+
this.contentMatrix = {
|
|
946
|
+
scale: t.scale ?? this.contentMatrix.scale,
|
|
947
|
+
dx: t.dx ?? this.contentMatrix.dx,
|
|
948
|
+
dy: t.dy ?? this.contentMatrix.dy
|
|
949
|
+
}, this.viewportMatrix = j(this.contentMatrix);
|
|
365
950
|
}
|
|
366
951
|
}
|
|
367
|
-
class
|
|
368
|
-
constructor(
|
|
369
|
-
|
|
370
|
-
n(this, "group", $());
|
|
371
|
-
n(this, "line");
|
|
372
|
-
n(this, "sourceArrow", null);
|
|
373
|
-
n(this, "targetArrow", null);
|
|
374
|
-
this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = d, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
|
|
375
|
-
}
|
|
376
|
-
update(e, t, s, o, i) {
|
|
377
|
-
this.group.style.transform = `scale(${t}, ${s})`;
|
|
378
|
-
const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t);
|
|
379
|
-
if (this.line.setAttribute("d", d), this.sourceArrow) {
|
|
380
|
-
const c = E(
|
|
381
|
-
h,
|
|
382
|
-
l,
|
|
383
|
-
this.arrowLength,
|
|
384
|
-
this.arrowWidth
|
|
385
|
-
);
|
|
386
|
-
this.sourceArrow.setAttribute("d", c);
|
|
387
|
-
}
|
|
388
|
-
if (this.targetArrow) {
|
|
389
|
-
const c = E(
|
|
390
|
-
a,
|
|
391
|
-
e,
|
|
392
|
-
-this.arrowLength,
|
|
393
|
-
this.arrowWidth
|
|
394
|
-
);
|
|
395
|
-
this.targetArrow.setAttribute("d", c);
|
|
396
|
-
}
|
|
952
|
+
class gt {
|
|
953
|
+
constructor(t) {
|
|
954
|
+
this.transformer = t;
|
|
397
955
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
);
|
|
956
|
+
getViewportMatrix() {
|
|
957
|
+
return { ...this.transformer.getViewportMatrix() };
|
|
958
|
+
}
|
|
959
|
+
getContentMatrix() {
|
|
960
|
+
return { ...this.transformer.getContentMatrix() };
|
|
404
961
|
}
|
|
405
962
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (this.targetArrow) {
|
|
428
|
-
const c = E(
|
|
429
|
-
a,
|
|
430
|
-
e,
|
|
431
|
-
-this.arrowLength,
|
|
432
|
-
this.arrowWidth
|
|
433
|
-
);
|
|
434
|
-
this.targetArrow.setAttribute("d", c);
|
|
435
|
-
}
|
|
963
|
+
const ut = () => {
|
|
964
|
+
const e = document.createElement("div");
|
|
965
|
+
return e.style.width = "100%", e.style.height = "100%", e.style.position = "relative", e.style.overflow = "hidden", e;
|
|
966
|
+
}, wt = () => {
|
|
967
|
+
const e = document.createElement("div");
|
|
968
|
+
return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.width = "0", e.style.height = "0", e;
|
|
969
|
+
}, yt = () => {
|
|
970
|
+
const e = document.createElement("div");
|
|
971
|
+
return e.style.position = "absolute", e.style.top = "0", e.style.left = "0", e.style.visibility = "hidden", e;
|
|
972
|
+
};
|
|
973
|
+
class ft {
|
|
974
|
+
constructor(t, o) {
|
|
975
|
+
s(this, "canvasWrapper", null);
|
|
976
|
+
s(this, "host", ut());
|
|
977
|
+
s(this, "container", wt());
|
|
978
|
+
s(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
|
|
979
|
+
s(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
|
|
980
|
+
this.graphStore = t, this.viewportTransformer = o, this.host.appendChild(this.container);
|
|
981
|
+
}
|
|
982
|
+
attach(t) {
|
|
983
|
+
this.detach(), this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
|
|
436
984
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
x: u.x,
|
|
440
|
-
y: o > 0 ? e.y - w : e.y + a
|
|
441
|
-
}, S = { x: m, y: P.y };
|
|
442
|
-
return D(
|
|
443
|
-
[i, c, y, v, S, P, u, h],
|
|
444
|
-
this.roundness
|
|
445
|
-
);
|
|
985
|
+
detach() {
|
|
986
|
+
this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
|
|
446
987
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
n(this, "svg", N());
|
|
451
|
-
n(this, "line");
|
|
452
|
-
n(this, "arrow", null);
|
|
453
|
-
this.arrowLength = s, this.arrowWidth = o, this.radius = h, this.smallRadius = a, this.line = L(e, t), this.svg.appendChild(this.line), i && (this.arrow = A(e), this.svg.appendChild(this.arrow));
|
|
454
|
-
}
|
|
455
|
-
update(e, t, s, o) {
|
|
456
|
-
const i = x(o, t, s), h = this.createLinePath(i);
|
|
457
|
-
if (this.line.setAttribute("d", h), this.arrow) {
|
|
458
|
-
const a = E(
|
|
459
|
-
i,
|
|
460
|
-
l,
|
|
461
|
-
this.arrowLength,
|
|
462
|
-
this.arrowWidth
|
|
463
|
-
);
|
|
464
|
-
this.arrow.setAttribute("d", a);
|
|
465
|
-
}
|
|
988
|
+
applyTransform() {
|
|
989
|
+
const t = this.viewportTransformer.getContentMatrix();
|
|
990
|
+
this.container.style.transform = `matrix(${t.scale}, 0, 0, ${t.scale}, ${t.dx}, ${t.dy})`;
|
|
466
991
|
}
|
|
467
|
-
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
{ x: h, y: a },
|
|
471
|
-
{ x: h, y: -a }
|
|
472
|
-
].map((m) => p(m, e, l)), u = [
|
|
473
|
-
`M ${c[0].x} ${c[0].y}`,
|
|
474
|
-
`A ${t} ${t} 0 0 1 ${c[1].x} ${c[1].y}`,
|
|
475
|
-
`A ${s} ${s} 0 1 0 ${c[2].x} ${c[2].y}`,
|
|
476
|
-
`A ${t} ${t} 0 0 1 ${c[0].x} ${c[0].y}`
|
|
477
|
-
].join(" "), w = `M 0 0 L ${c[0].x} ${c[0].y} `;
|
|
478
|
-
return `${this.arrow !== null ? "" : w}${u}`;
|
|
992
|
+
attachNode(t) {
|
|
993
|
+
const o = this.graphStore.getNode(t), r = yt();
|
|
994
|
+
r.appendChild(o.element), this.container.appendChild(r), this.nodeIdToWrapperElementMap.set(t, r), this.updateNodeCoordinates(t), this.updateNodePriority(t), r.style.visibility = "visible";
|
|
479
995
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
n(this, "svg", N());
|
|
484
|
-
n(this, "line");
|
|
485
|
-
n(this, "arrow", null);
|
|
486
|
-
n(this, "roundness");
|
|
487
|
-
n(this, "linePoints");
|
|
488
|
-
this.arrowLength = s, this.arrowWidth = o, this.side = h, this.minPortOffset = a, this.roundness = Math.min(d, this.minPortOffset, this.side / 2), this.line = L(e, t), this.svg.appendChild(this.line), i && (this.arrow = A(e), this.svg.appendChild(this.arrow));
|
|
489
|
-
const c = this.minPortOffset, u = this.side, w = this.arrowLength + c, m = w + 2 * u;
|
|
490
|
-
this.linePoints = [
|
|
491
|
-
{ x: this.arrowLength, y: l.y },
|
|
492
|
-
{ x: w, y: l.y },
|
|
493
|
-
{ x: w, y: this.side },
|
|
494
|
-
{ x: m, y: this.side },
|
|
495
|
-
{ x: m, y: -this.side },
|
|
496
|
-
{ x: w, y: -this.side },
|
|
497
|
-
{ x: w, y: l.y },
|
|
498
|
-
{ x: this.arrowLength, y: l.y }
|
|
499
|
-
];
|
|
996
|
+
detachNode(t) {
|
|
997
|
+
const o = this.graphStore.getNode(t), r = this.nodeIdToWrapperElementMap.get(t);
|
|
998
|
+
r.removeChild(o.element), this.container.removeChild(r), this.nodeIdToWrapperElementMap.delete(t);
|
|
500
999
|
}
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
const a = E(
|
|
505
|
-
i,
|
|
506
|
-
l,
|
|
507
|
-
this.arrowLength,
|
|
508
|
-
this.arrowWidth
|
|
509
|
-
);
|
|
510
|
-
this.arrow.setAttribute("d", a);
|
|
511
|
-
}
|
|
1000
|
+
attachEdge(t) {
|
|
1001
|
+
const o = this.graphStore.getEdge(t);
|
|
1002
|
+
this.edgeIdToElementMap.set(t, o.shape.svg), this.container.appendChild(o.shape.svg), this.renderEdge(t), this.updateEdgePriority(t);
|
|
512
1003
|
}
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
), s = `M ${l.x} ${l.y} L ${t[0].x} ${t[0].y} `;
|
|
517
|
-
return `${this.arrow ? "" : s}${D(t, this.roundness)}`;
|
|
1004
|
+
detachEdge(t) {
|
|
1005
|
+
const o = this.graphStore.getEdge(t);
|
|
1006
|
+
this.container.removeChild(o.shape.svg), this.edgeIdToElementMap.delete(t);
|
|
518
1007
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
n(this, "sourceArrow", null);
|
|
526
|
-
n(this, "targetArrow", null);
|
|
527
|
-
n(this, "detourX");
|
|
528
|
-
n(this, "detourY");
|
|
529
|
-
this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.detourX = Math.cos(c) * d, this.detourY = Math.sin(c) * d, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
|
|
530
|
-
}
|
|
531
|
-
update(e, t, s, o, i) {
|
|
532
|
-
this.group.style.transform = `scale(${t}, ${s})`;
|
|
533
|
-
const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t, s);
|
|
534
|
-
if (this.line.setAttribute("d", d), this.sourceArrow) {
|
|
535
|
-
const c = E(
|
|
536
|
-
h,
|
|
537
|
-
l,
|
|
538
|
-
this.arrowLength,
|
|
539
|
-
this.arrowWidth
|
|
540
|
-
);
|
|
541
|
-
this.sourceArrow.setAttribute("d", c);
|
|
542
|
-
}
|
|
543
|
-
if (this.targetArrow) {
|
|
544
|
-
const c = E(
|
|
545
|
-
a,
|
|
546
|
-
e,
|
|
547
|
-
-this.arrowLength,
|
|
548
|
-
this.arrowWidth
|
|
549
|
-
);
|
|
550
|
-
this.targetArrow.setAttribute("d", c);
|
|
551
|
-
}
|
|
1008
|
+
clear() {
|
|
1009
|
+
this.edgeIdToElementMap.forEach((t, o) => {
|
|
1010
|
+
this.detachEdge(o);
|
|
1011
|
+
}), this.nodeIdToWrapperElementMap.forEach((t, o) => {
|
|
1012
|
+
this.detachNode(o);
|
|
1013
|
+
});
|
|
552
1014
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
{ x: d, y: l.y },
|
|
556
|
-
t,
|
|
557
|
-
l
|
|
558
|
-
), m = {
|
|
559
|
-
x: w.x + c,
|
|
560
|
-
y: w.y + u
|
|
561
|
-
}, y = p(
|
|
562
|
-
{ x: e.x - d, y: e.y },
|
|
563
|
-
s,
|
|
564
|
-
e
|
|
565
|
-
), v = {
|
|
566
|
-
x: y.x + c,
|
|
567
|
-
y: y.y + u
|
|
568
|
-
}, P = { x: (m.x + v.x) / 2, y: (m.y + v.y) / 2 }, S = {
|
|
569
|
-
x: w.x + this.curvature * t.x,
|
|
570
|
-
y: w.y + this.curvature * t.y
|
|
571
|
-
}, M = {
|
|
572
|
-
x: y.x - this.curvature * s.x,
|
|
573
|
-
y: y.y - this.curvature * s.y
|
|
574
|
-
}, b = {
|
|
575
|
-
x: w.x + c,
|
|
576
|
-
y: w.y + u
|
|
577
|
-
}, T = {
|
|
578
|
-
x: y.x + c,
|
|
579
|
-
y: y.y + u
|
|
580
|
-
};
|
|
581
|
-
return [
|
|
582
|
-
`M ${h.x} ${h.y}`,
|
|
583
|
-
`L ${w.x} ${w.y}`,
|
|
584
|
-
`C ${S.x} ${S.y} ${b.x} ${b.y} ${P.x} ${P.y}`,
|
|
585
|
-
`C ${T.x} ${T.y} ${M.x} ${M.y} ${y.x} ${y.y}`,
|
|
586
|
-
`L ${a.x} ${a.y}`
|
|
587
|
-
].join(" ");
|
|
1015
|
+
destroy() {
|
|
1016
|
+
this.clear(), this.detach(), this.host.removeChild(this.container);
|
|
588
1017
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
n(this, "svg", N());
|
|
593
|
-
n(this, "group", $());
|
|
594
|
-
n(this, "line");
|
|
595
|
-
n(this, "sourceArrow", null);
|
|
596
|
-
n(this, "targetArrow", null);
|
|
597
|
-
n(this, "detourX");
|
|
598
|
-
n(this, "detourY");
|
|
599
|
-
this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness = d, this.detourX = Math.cos(u) * c, this.detourY = Math.sin(u) * c, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line), h && (this.sourceArrow = A(e), this.group.appendChild(this.sourceArrow)), a && (this.targetArrow = A(e), this.group.appendChild(this.targetArrow));
|
|
600
|
-
}
|
|
601
|
-
update(e, t, s, o, i) {
|
|
602
|
-
this.group.style.transform = `scale(${t}, ${s})`;
|
|
603
|
-
const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, t, s);
|
|
604
|
-
if (this.line.setAttribute("d", d), this.sourceArrow) {
|
|
605
|
-
const c = E(
|
|
606
|
-
h,
|
|
607
|
-
l,
|
|
608
|
-
this.arrowLength,
|
|
609
|
-
this.arrowWidth
|
|
610
|
-
);
|
|
611
|
-
this.sourceArrow.setAttribute("d", c);
|
|
612
|
-
}
|
|
613
|
-
if (this.targetArrow) {
|
|
614
|
-
const c = E(
|
|
615
|
-
a,
|
|
616
|
-
e,
|
|
617
|
-
-this.arrowLength,
|
|
618
|
-
this.arrowWidth
|
|
619
|
-
);
|
|
620
|
-
this.targetArrow.setAttribute("d", c);
|
|
621
|
-
}
|
|
1018
|
+
updateNodeCoordinates(t) {
|
|
1019
|
+
const o = this.nodeIdToWrapperElementMap.get(t), r = this.graphStore.getNode(t), { width: i, height: n } = r.element.getBoundingClientRect(), d = this.viewportTransformer.getViewportMatrix().scale, c = r.centerFn(i, n), h = r.x - d * c.x, l = r.y - d * c.y;
|
|
1020
|
+
o.style.transform = `translate(${h}px, ${l}px)`;
|
|
622
1021
|
}
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
1022
|
+
updateNodePriority(t) {
|
|
1023
|
+
const o = this.graphStore.getNode(t), r = this.nodeIdToWrapperElementMap.get(t);
|
|
1024
|
+
r.style.zIndex = `${o.priority}`;
|
|
1025
|
+
}
|
|
1026
|
+
updateEdgeShape(t) {
|
|
1027
|
+
const o = this.edgeIdToElementMap.get(t);
|
|
1028
|
+
this.container.removeChild(o);
|
|
1029
|
+
const r = this.graphStore.getEdge(t);
|
|
1030
|
+
this.edgeIdToElementMap.set(t, r.shape.svg), this.container.appendChild(r.shape.svg);
|
|
1031
|
+
}
|
|
1032
|
+
renderEdge(t) {
|
|
1033
|
+
const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from), i = this.graphStore.getPort(o.to), n = r.element.getBoundingClientRect(), d = i.element.getBoundingClientRect(), c = this.host.getBoundingClientRect(), h = this.viewportTransformer.getViewportMatrix(), l = {
|
|
1034
|
+
x: h.scale * (n.left - c.left) + h.dx,
|
|
1035
|
+
y: h.scale * (n.top - c.top) + h.dy
|
|
1036
|
+
}, a = {
|
|
1037
|
+
x: h.scale * (d.left - c.left) + h.dx,
|
|
1038
|
+
y: h.scale * (d.top - c.top) + h.dy
|
|
1039
|
+
}, w = {
|
|
1040
|
+
x: l.x,
|
|
1041
|
+
y: l.y,
|
|
1042
|
+
width: n.width * h.scale,
|
|
1043
|
+
height: n.height * h.scale,
|
|
1044
|
+
direction: r.direction,
|
|
1045
|
+
portId: o.from,
|
|
1046
|
+
nodeId: this.graphStore.getPortNodeId(o.from)
|
|
1047
|
+
}, y = {
|
|
1048
|
+
x: a.x,
|
|
1049
|
+
y: a.y,
|
|
1050
|
+
width: d.width * h.scale,
|
|
1051
|
+
height: d.height * h.scale,
|
|
1052
|
+
direction: i.direction,
|
|
1053
|
+
portId: o.to,
|
|
1054
|
+
nodeId: this.graphStore.getPortNodeId(o.to)
|
|
1055
|
+
};
|
|
1056
|
+
o.shape.render({
|
|
1057
|
+
source: w,
|
|
1058
|
+
target: y
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
updateEdgePriority(t) {
|
|
1062
|
+
const o = this.graphStore.getEdge(t);
|
|
1063
|
+
o.shape.svg.style.zIndex = `${o.priority}`;
|
|
637
1064
|
}
|
|
638
1065
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
r.smallCycleRadius
|
|
648
|
-
) : e === C.NodeCycle ? new ne(
|
|
649
|
-
r.color,
|
|
650
|
-
r.width,
|
|
651
|
-
r.curvature,
|
|
652
|
-
r.arrowLength,
|
|
653
|
-
r.arrowWidth,
|
|
654
|
-
r.hasSourceArrow,
|
|
655
|
-
r.hasTargetArrow,
|
|
656
|
-
r.detourDistance,
|
|
657
|
-
r.detourDirection
|
|
658
|
-
) : new te(
|
|
659
|
-
r.color,
|
|
660
|
-
r.width,
|
|
661
|
-
r.curvature,
|
|
662
|
-
r.arrowLength,
|
|
663
|
-
r.arrowWidth,
|
|
664
|
-
r.hasSourceArrow,
|
|
665
|
-
r.hasTargetArrow
|
|
666
|
-
), he = (r) => (e) => e === C.PortCycle ? new B(
|
|
667
|
-
r.color,
|
|
668
|
-
r.width,
|
|
669
|
-
r.arrowLength,
|
|
670
|
-
r.arrowWidth,
|
|
671
|
-
r.hasSourceArrow || r.hasTargetArrow,
|
|
672
|
-
r.cycleSquareSide,
|
|
673
|
-
r.arrowOffset,
|
|
674
|
-
r.roundness
|
|
675
|
-
) : e === C.NodeCycle ? new G(
|
|
676
|
-
r.color,
|
|
677
|
-
r.width,
|
|
678
|
-
r.arrowLength,
|
|
679
|
-
r.arrowWidth,
|
|
680
|
-
r.arrowOffset,
|
|
681
|
-
r.hasSourceArrow,
|
|
682
|
-
r.hasTargetArrow,
|
|
683
|
-
r.roundness,
|
|
684
|
-
r.detourDistance,
|
|
685
|
-
r.detourDirection
|
|
686
|
-
) : new re(
|
|
687
|
-
r.color,
|
|
688
|
-
r.width,
|
|
689
|
-
r.arrowLength,
|
|
690
|
-
r.arrowWidth,
|
|
691
|
-
r.arrowOffset,
|
|
692
|
-
r.hasSourceArrow,
|
|
693
|
-
r.hasTargetArrow,
|
|
694
|
-
r.roundness
|
|
695
|
-
), de = (r) => (e) => e === C.PortCycle ? new B(
|
|
696
|
-
r.color,
|
|
697
|
-
r.width,
|
|
698
|
-
r.arrowLength,
|
|
699
|
-
r.arrowWidth,
|
|
700
|
-
r.hasSourceArrow || r.hasTargetArrow,
|
|
701
|
-
r.cycleSquareSide,
|
|
702
|
-
r.arrowOffset,
|
|
703
|
-
r.roundness
|
|
704
|
-
) : e === C.NodeCycle ? new G(
|
|
705
|
-
r.color,
|
|
706
|
-
r.width,
|
|
707
|
-
r.arrowLength,
|
|
708
|
-
r.arrowWidth,
|
|
709
|
-
r.arrowOffset,
|
|
710
|
-
r.hasSourceArrow,
|
|
711
|
-
r.hasTargetArrow,
|
|
712
|
-
r.roundness,
|
|
713
|
-
r.detourDistance,
|
|
714
|
-
r.detourDirection
|
|
715
|
-
) : new oe(
|
|
716
|
-
r.color,
|
|
717
|
-
r.width,
|
|
718
|
-
r.arrowLength,
|
|
719
|
-
r.arrowWidth,
|
|
720
|
-
r.arrowOffset,
|
|
721
|
-
r.hasSourceArrow,
|
|
722
|
-
r.hasTargetArrow,
|
|
723
|
-
r.roundness
|
|
724
|
-
), ce = (r) => (e) => e === C.PortCycle ? new B(
|
|
725
|
-
r.color,
|
|
726
|
-
r.width,
|
|
727
|
-
r.arrowLength,
|
|
728
|
-
r.arrowWidth,
|
|
729
|
-
r.hasSourceArrow || r.hasTargetArrow,
|
|
730
|
-
r.cycleSquareSide,
|
|
731
|
-
r.arrowOffset,
|
|
732
|
-
r.roundness
|
|
733
|
-
) : e === C.NodeCycle ? new G(
|
|
734
|
-
r.color,
|
|
735
|
-
r.width,
|
|
736
|
-
r.arrowLength,
|
|
737
|
-
r.arrowWidth,
|
|
738
|
-
r.arrowOffset,
|
|
739
|
-
r.hasSourceArrow,
|
|
740
|
-
r.hasTargetArrow,
|
|
741
|
-
r.roundness,
|
|
742
|
-
r.detourDistance,
|
|
743
|
-
r.detourDirection
|
|
744
|
-
) : new se(
|
|
745
|
-
r.color,
|
|
746
|
-
r.width,
|
|
747
|
-
r.arrowLength,
|
|
748
|
-
r.arrowWidth,
|
|
749
|
-
r.arrowOffset,
|
|
750
|
-
r.hasSourceArrow,
|
|
751
|
-
r.hasTargetArrow,
|
|
752
|
-
r.roundness
|
|
753
|
-
);
|
|
754
|
-
class I {
|
|
755
|
-
constructor(e) {
|
|
756
|
-
n(this, "counter", 0);
|
|
757
|
-
this.checkExists = e;
|
|
758
|
-
}
|
|
759
|
-
create(e) {
|
|
760
|
-
if (e !== void 0)
|
|
761
|
-
return e;
|
|
1066
|
+
class C {
|
|
1067
|
+
constructor(t) {
|
|
1068
|
+
s(this, "counter", 0);
|
|
1069
|
+
this.checkExists = t;
|
|
1070
|
+
}
|
|
1071
|
+
create(t) {
|
|
1072
|
+
if (t !== void 0)
|
|
1073
|
+
return t;
|
|
762
1074
|
for (; this.checkExists(this.counter); )
|
|
763
1075
|
this.counter++;
|
|
764
1076
|
return this.counter;
|
|
@@ -767,133 +1079,126 @@ class I {
|
|
|
767
1079
|
this.counter = 0;
|
|
768
1080
|
}
|
|
769
1081
|
}
|
|
770
|
-
class
|
|
1082
|
+
class S extends Error {
|
|
771
1083
|
constructor() {
|
|
772
1084
|
super(...arguments);
|
|
773
|
-
|
|
1085
|
+
s(this, "name", "HtmlGraphError");
|
|
774
1086
|
}
|
|
775
1087
|
}
|
|
776
|
-
class
|
|
777
|
-
constructor(
|
|
778
|
-
|
|
779
|
-
(
|
|
1088
|
+
class vt {
|
|
1089
|
+
constructor(t, o, r, i, n, d, c) {
|
|
1090
|
+
s(this, "nodeIdGenerator", new C(
|
|
1091
|
+
(t) => this.graphStore.getNode(t) !== void 0
|
|
780
1092
|
));
|
|
781
|
-
|
|
782
|
-
(
|
|
1093
|
+
s(this, "portIdGenerator", new C(
|
|
1094
|
+
(t) => this.graphStore.getPort(t) !== void 0
|
|
783
1095
|
));
|
|
784
|
-
|
|
785
|
-
(
|
|
1096
|
+
s(this, "edgeIdGenerator", new C(
|
|
1097
|
+
(t) => this.graphStore.getEdge(t) !== void 0
|
|
786
1098
|
));
|
|
787
|
-
this.graphStore =
|
|
1099
|
+
this.graphStore = t, this.htmlController = o, this.viewportTransformer = r, this.defaultNodesCenterFn = i, this.defaultPortsDirection = n, this.defaultNodesPriorityFn = d, this.defaultEdgesPriorityFn = c;
|
|
788
1100
|
}
|
|
789
|
-
attach(
|
|
790
|
-
this.htmlController.attach(
|
|
1101
|
+
attach(t) {
|
|
1102
|
+
this.htmlController.attach(t);
|
|
791
1103
|
}
|
|
792
1104
|
detach() {
|
|
793
1105
|
this.htmlController.detach();
|
|
794
1106
|
}
|
|
795
|
-
addNode(
|
|
796
|
-
const
|
|
797
|
-
if (this.graphStore.getNode(
|
|
798
|
-
throw new
|
|
1107
|
+
addNode(t) {
|
|
1108
|
+
const o = this.nodeIdGenerator.create(t.nodeId);
|
|
1109
|
+
if (this.graphStore.getNode(o) !== void 0)
|
|
1110
|
+
throw new S("failed to add node with existing id");
|
|
799
1111
|
this.graphStore.addNode({
|
|
800
|
-
nodeId:
|
|
801
|
-
element:
|
|
802
|
-
x:
|
|
803
|
-
y:
|
|
804
|
-
centerFn:
|
|
805
|
-
priority:
|
|
806
|
-
}), this.htmlController.attachNode(
|
|
1112
|
+
nodeId: o,
|
|
1113
|
+
element: t.element,
|
|
1114
|
+
x: t.x,
|
|
1115
|
+
y: t.y,
|
|
1116
|
+
centerFn: t.centerFn ?? this.defaultNodesCenterFn,
|
|
1117
|
+
priority: t.priority ?? this.defaultNodesPriorityFn()
|
|
1118
|
+
}), this.htmlController.attachNode(o), Array.from(t.ports ?? []).forEach((r) => {
|
|
807
1119
|
this.markPort({
|
|
808
|
-
portId:
|
|
809
|
-
element:
|
|
810
|
-
nodeId:
|
|
811
|
-
|
|
812
|
-
direction: s.direction
|
|
1120
|
+
portId: r.id,
|
|
1121
|
+
element: r.element,
|
|
1122
|
+
nodeId: o,
|
|
1123
|
+
direction: r.direction
|
|
813
1124
|
});
|
|
814
1125
|
});
|
|
815
1126
|
}
|
|
816
|
-
markPort(
|
|
817
|
-
const
|
|
818
|
-
if (this.graphStore.getPort(
|
|
819
|
-
throw new
|
|
820
|
-
if (this.graphStore.getNode(
|
|
821
|
-
throw new
|
|
1127
|
+
markPort(t) {
|
|
1128
|
+
const o = this.portIdGenerator.create(t.portId);
|
|
1129
|
+
if (this.graphStore.getPort(o) !== void 0)
|
|
1130
|
+
throw new S("failed to add port with existing id");
|
|
1131
|
+
if (this.graphStore.getNode(t.nodeId) === void 0)
|
|
1132
|
+
throw new S("failed to set port on nonexisting node");
|
|
822
1133
|
this.graphStore.addPort({
|
|
823
|
-
portId:
|
|
824
|
-
element:
|
|
825
|
-
nodeId:
|
|
826
|
-
|
|
827
|
-
direction: e.direction ?? this.defaultPortsDirection
|
|
1134
|
+
portId: o,
|
|
1135
|
+
element: t.element,
|
|
1136
|
+
nodeId: t.nodeId,
|
|
1137
|
+
direction: t.direction ?? this.defaultPortsDirection
|
|
828
1138
|
});
|
|
829
1139
|
}
|
|
830
|
-
addEdge(
|
|
831
|
-
const
|
|
832
|
-
if (this.graphStore.getEdge(
|
|
833
|
-
throw new
|
|
834
|
-
if (this.graphStore.getPort(
|
|
835
|
-
throw new
|
|
836
|
-
if (this.graphStore.getPort(
|
|
837
|
-
throw new
|
|
838
|
-
const s = this.resolveEdgeType(e.from, e.to);
|
|
1140
|
+
addEdge(t) {
|
|
1141
|
+
const o = this.edgeIdGenerator.create(t.edgeId);
|
|
1142
|
+
if (this.graphStore.getEdge(o) !== void 0)
|
|
1143
|
+
throw new S("failed to add edge with existing id");
|
|
1144
|
+
if (this.graphStore.getPort(t.from) === void 0)
|
|
1145
|
+
throw new S("failed to add edge from nonexisting port");
|
|
1146
|
+
if (this.graphStore.getPort(t.to) === void 0)
|
|
1147
|
+
throw new S("failed to add edge to nonexisting port");
|
|
839
1148
|
this.graphStore.addEdge({
|
|
840
|
-
edgeId:
|
|
841
|
-
from:
|
|
842
|
-
to:
|
|
843
|
-
shape:
|
|
844
|
-
priority:
|
|
845
|
-
}), this.htmlController.attachEdge(
|
|
846
|
-
}
|
|
847
|
-
updateEdge(
|
|
848
|
-
const
|
|
849
|
-
if (
|
|
850
|
-
throw new
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
if (s === void 0)
|
|
860
|
-
throw new f("failed to unset nonexisting port");
|
|
861
|
-
s.direction = t.direction ?? s.direction, s.centerFn = t.centerFn ?? s.centerFn, this.graphStore.getPortAdjacentEdgeIds(e).forEach((i) => {
|
|
862
|
-
this.htmlController.updateEdge(i);
|
|
1149
|
+
edgeId: o,
|
|
1150
|
+
from: t.from,
|
|
1151
|
+
to: t.to,
|
|
1152
|
+
shape: t.shape,
|
|
1153
|
+
priority: t.priority ?? this.defaultEdgesPriorityFn()
|
|
1154
|
+
}), this.htmlController.attachEdge(o);
|
|
1155
|
+
}
|
|
1156
|
+
updateEdge(t) {
|
|
1157
|
+
const o = this.graphStore.getEdge(t.edgeId);
|
|
1158
|
+
if (o === void 0)
|
|
1159
|
+
throw new S("failed to update nonexisting edge");
|
|
1160
|
+
t.shape !== void 0 && (o.shape = t.shape, this.htmlController.updateEdgeShape(t.edgeId)), t.priority !== void 0 && (o.priority = t.priority, this.htmlController.updateEdgePriority(t.edgeId)), t.from !== void 0 && this.graphStore.updateEdgeFrom(t.edgeId, t.from), t.to !== void 0 && this.graphStore.updateEdgeTo(t.edgeId, t.to), this.htmlController.renderEdge(t.edgeId);
|
|
1161
|
+
}
|
|
1162
|
+
updatePort(t, o) {
|
|
1163
|
+
const r = this.graphStore.getPort(t);
|
|
1164
|
+
if (r === void 0)
|
|
1165
|
+
throw new S("failed to unset nonexisting port");
|
|
1166
|
+
r.direction = o.direction ?? r.direction, this.graphStore.getPortAdjacentEdgeIds(t).forEach((n) => {
|
|
1167
|
+
this.htmlController.renderEdge(n);
|
|
863
1168
|
});
|
|
864
1169
|
}
|
|
865
|
-
updateNode(
|
|
866
|
-
const
|
|
867
|
-
if (
|
|
868
|
-
throw new
|
|
869
|
-
|
|
870
|
-
this.htmlController.
|
|
1170
|
+
updateNode(t, o) {
|
|
1171
|
+
const r = this.graphStore.getNode(t);
|
|
1172
|
+
if (r === void 0)
|
|
1173
|
+
throw new S("failed to update nonexisting node");
|
|
1174
|
+
r.x = (o == null ? void 0 : o.x) ?? r.x, r.y = (o == null ? void 0 : o.y) ?? r.y, r.centerFn = (o == null ? void 0 : o.centerFn) ?? r.centerFn, r.priority = (o == null ? void 0 : o.priority) ?? r.priority, this.htmlController.updateNodeCoordinates(t), this.htmlController.updateNodePriority(t), this.graphStore.getNodeAdjacentEdgeIds(t).forEach((n) => {
|
|
1175
|
+
this.htmlController.renderEdge(n);
|
|
871
1176
|
});
|
|
872
1177
|
}
|
|
873
|
-
removeEdge(
|
|
874
|
-
if (this.graphStore.getEdge(
|
|
875
|
-
throw new
|
|
876
|
-
this.htmlController.detachEdge(
|
|
1178
|
+
removeEdge(t) {
|
|
1179
|
+
if (this.graphStore.getEdge(t) === void 0)
|
|
1180
|
+
throw new S("failed to remove nonexisting edge");
|
|
1181
|
+
this.htmlController.detachEdge(t), this.graphStore.removeEdge(t);
|
|
877
1182
|
}
|
|
878
|
-
unmarkPort(
|
|
879
|
-
if (this.graphStore.getPort(
|
|
880
|
-
throw new
|
|
881
|
-
this.graphStore.getPortAdjacentEdgeIds(
|
|
882
|
-
this.removeEdge(
|
|
883
|
-
}), this.graphStore.removePort(
|
|
1183
|
+
unmarkPort(t) {
|
|
1184
|
+
if (this.graphStore.getPort(t) === void 0)
|
|
1185
|
+
throw new S("failed to unset nonexisting port");
|
|
1186
|
+
this.graphStore.getPortAdjacentEdgeIds(t).forEach((o) => {
|
|
1187
|
+
this.removeEdge(o);
|
|
1188
|
+
}), this.graphStore.removePort(t);
|
|
884
1189
|
}
|
|
885
|
-
removeNode(
|
|
886
|
-
if (this.graphStore.getNode(
|
|
887
|
-
throw new
|
|
888
|
-
this.graphStore.getNodePortIds(
|
|
889
|
-
this.unmarkPort(
|
|
890
|
-
}), this.htmlController.detachNode(
|
|
1190
|
+
removeNode(t) {
|
|
1191
|
+
if (this.graphStore.getNode(t) === void 0)
|
|
1192
|
+
throw new S("failed to remove nonexisting node");
|
|
1193
|
+
this.graphStore.getNodePortIds(t).forEach((o) => {
|
|
1194
|
+
this.unmarkPort(o);
|
|
1195
|
+
}), this.htmlController.detachNode(t), this.graphStore.removeNode(t);
|
|
891
1196
|
}
|
|
892
|
-
patchViewportMatrix(
|
|
893
|
-
this.viewportTransformer.patchViewportMatrix(
|
|
1197
|
+
patchViewportMatrix(t) {
|
|
1198
|
+
this.viewportTransformer.patchViewportMatrix(t), this.htmlController.applyTransform();
|
|
894
1199
|
}
|
|
895
|
-
patchContentMatrix(
|
|
896
|
-
this.viewportTransformer.patchContentMatrix(
|
|
1200
|
+
patchContentMatrix(t) {
|
|
1201
|
+
this.viewportTransformer.patchContentMatrix(t), this.htmlController.applyTransform();
|
|
897
1202
|
}
|
|
898
1203
|
clear() {
|
|
899
1204
|
this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset();
|
|
@@ -901,844 +1206,659 @@ class le {
|
|
|
901
1206
|
destroy() {
|
|
902
1207
|
this.clear(), this.htmlController.destroy();
|
|
903
1208
|
}
|
|
904
|
-
resolveEdgeType(e, t) {
|
|
905
|
-
if (e === t)
|
|
906
|
-
return C.PortCycle;
|
|
907
|
-
const s = this.graphStore.getPortNodeId(e), o = this.graphStore.getPortNodeId(t);
|
|
908
|
-
return s === o ? C.NodeCycle : C.Regular;
|
|
909
|
-
}
|
|
910
1209
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
attach(e) {
|
|
931
|
-
this.detach(), this.canvasWrapper = e, this.canvasWrapper.appendChild(this.host);
|
|
932
|
-
}
|
|
933
|
-
detach() {
|
|
934
|
-
this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
|
|
935
|
-
}
|
|
936
|
-
applyTransform() {
|
|
937
|
-
const e = this.viewportTransformer.getContentMatrix();
|
|
938
|
-
this.container.style.transform = `matrix(${e.scale}, 0, 0, ${e.scale}, ${e.dx}, ${e.dy})`;
|
|
939
|
-
}
|
|
940
|
-
attachNode(e) {
|
|
941
|
-
const t = this.graphStore.getNode(e), s = we();
|
|
942
|
-
s.appendChild(t.element), this.container.appendChild(s), this.nodeIdToWrapperElementMap.set(e, s), this.updateNodeCoordinates(e), this.updateNodePriority(e), s.style.visibility = "visible";
|
|
943
|
-
}
|
|
944
|
-
detachNode(e) {
|
|
945
|
-
const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.get(e);
|
|
946
|
-
s.removeChild(t.element), this.container.removeChild(s), this.nodeIdToWrapperElementMap.delete(e);
|
|
947
|
-
}
|
|
948
|
-
attachEdge(e) {
|
|
949
|
-
const t = this.graphStore.getEdge(e);
|
|
950
|
-
this.edgeIdToElementMap.set(e, t.shape.svg), this.container.appendChild(t.shape.svg), this.updateEdge(e), this.updateEdgePriority(e);
|
|
951
|
-
}
|
|
952
|
-
detachEdge(e) {
|
|
953
|
-
const t = this.graphStore.getEdge(e);
|
|
954
|
-
this.container.removeChild(t.shape.svg), this.edgeIdToElementMap.delete(e);
|
|
955
|
-
}
|
|
956
|
-
clear() {
|
|
957
|
-
this.edgeIdToElementMap.forEach((e, t) => {
|
|
958
|
-
this.detachEdge(t);
|
|
959
|
-
}), this.nodeIdToWrapperElementMap.forEach((e, t) => {
|
|
960
|
-
this.detachNode(t);
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
destroy() {
|
|
964
|
-
this.clear(), this.detach(), this.host.removeChild(this.container);
|
|
965
|
-
}
|
|
966
|
-
updateNodeCoordinates(e) {
|
|
967
|
-
const t = this.nodeIdToWrapperElementMap.get(e), s = this.graphStore.getNode(e), { width: o, height: i } = s.element.getBoundingClientRect(), h = this.viewportTransformer.getViewportMatrix().scale, a = s.centerFn(o, i), d = s.x - h * a.x, c = s.y - h * a.y;
|
|
968
|
-
t.style.transform = `translate(${d}px, ${c}px)`;
|
|
969
|
-
}
|
|
970
|
-
updateNodePriority(e) {
|
|
971
|
-
const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.get(e);
|
|
972
|
-
s.style.zIndex = `${t.priority}`;
|
|
973
|
-
}
|
|
974
|
-
updateEdgeShape(e) {
|
|
975
|
-
const t = this.edgeIdToElementMap.get(e);
|
|
976
|
-
this.container.removeChild(t);
|
|
977
|
-
const s = this.graphStore.getEdge(e);
|
|
978
|
-
this.edgeIdToElementMap.set(e, s.shape.svg), this.container.appendChild(s.shape.svg);
|
|
979
|
-
}
|
|
980
|
-
updateEdge(e) {
|
|
981
|
-
const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from), o = this.graphStore.getPort(t.to), i = s.element.getBoundingClientRect(), h = o.element.getBoundingClientRect(), a = this.host.getBoundingClientRect(), d = this.viewportTransformer.getViewportMatrix(), c = {
|
|
982
|
-
x: d.scale * (i.left - a.left) + d.dx,
|
|
983
|
-
y: d.scale * (i.top - a.top) + d.dy
|
|
984
|
-
}, u = {
|
|
985
|
-
x: d.scale * (h.left - a.left) + d.dx,
|
|
986
|
-
y: d.scale * (h.top - a.top) + d.dy
|
|
987
|
-
}, w = s.centerFn(
|
|
988
|
-
i.width * d.scale,
|
|
989
|
-
i.height * d.scale
|
|
990
|
-
), m = o.centerFn(
|
|
991
|
-
h.width * d.scale,
|
|
992
|
-
h.height * d.scale
|
|
993
|
-
), y = {
|
|
994
|
-
x: c.x + w.x,
|
|
995
|
-
y: c.y + w.y
|
|
996
|
-
}, v = {
|
|
997
|
-
x: u.x + m.x,
|
|
998
|
-
y: u.y + m.y
|
|
999
|
-
}, P = Math.min(y.x, v.x), S = Math.min(y.y, v.y), M = Math.abs(v.x - y.x), b = Math.abs(v.y - y.y);
|
|
1000
|
-
t.shape.svg.style.width = `${M}px`, t.shape.svg.style.height = `${b}px`, t.shape.svg.style.transform = `translate(${P}px, ${S}px)`;
|
|
1001
|
-
const T = y.x <= v.x ? 1 : -1, F = y.y <= v.y ? 1 : -1;
|
|
1002
|
-
t.shape.update(
|
|
1003
|
-
{ x: M, y: b },
|
|
1004
|
-
T,
|
|
1005
|
-
F,
|
|
1006
|
-
s.direction,
|
|
1007
|
-
o.direction
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
updateEdgePriority(e) {
|
|
1011
|
-
const t = this.graphStore.getEdge(e);
|
|
1012
|
-
t.shape.svg.style.zIndex = `${t.priority}`;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
class me {
|
|
1016
|
-
constructor(e) {
|
|
1017
|
-
n(this, "publicViewportTransformer");
|
|
1018
|
-
n(this, "publicGraphStore");
|
|
1019
|
-
n(this, "canvasController");
|
|
1020
|
-
const t = new Q(), s = new q();
|
|
1021
|
-
this.publicGraphStore = new ee(s), this.publicViewportTransformer = new Z(
|
|
1022
|
-
t
|
|
1023
|
-
);
|
|
1024
|
-
const o = new ye(s, t);
|
|
1025
|
-
this.canvasController = new le(
|
|
1026
|
-
s,
|
|
1027
|
-
o,
|
|
1028
|
-
t,
|
|
1029
|
-
e.nodesCenterFn,
|
|
1030
|
-
e.portsCenterFn,
|
|
1031
|
-
e.portsDirection,
|
|
1032
|
-
e.nodesPriorityFn,
|
|
1033
|
-
e.edgesPriorityFn
|
|
1034
|
-
);
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
const H = (r, e) => ({
|
|
1038
|
-
x: r / 2,
|
|
1039
|
-
y: e / 2
|
|
1040
|
-
}), g = {
|
|
1041
|
-
edgeColor: "#5c5c5c",
|
|
1042
|
-
edgeWidth: 1,
|
|
1043
|
-
edgeArrowLength: 15,
|
|
1044
|
-
edgeArrowWidth: 4,
|
|
1045
|
-
edgeArrowOffset: 15,
|
|
1046
|
-
hasSourceArrow: !1,
|
|
1047
|
-
hasTargetArrow: !1,
|
|
1048
|
-
cycleSize: 30,
|
|
1049
|
-
roundness: 10,
|
|
1050
|
-
detourDistance: 100,
|
|
1051
|
-
detourDirection: -Math.PI / 2,
|
|
1052
|
-
smallCycleSize: 15,
|
|
1053
|
-
curvature: 90
|
|
1054
|
-
}, R = (r) => {
|
|
1055
|
-
switch (r == null ? void 0 : r.type) {
|
|
1056
|
-
case "custom":
|
|
1057
|
-
return r.factory;
|
|
1058
|
-
case "straight":
|
|
1059
|
-
return he({
|
|
1060
|
-
color: r.color ?? g.edgeColor,
|
|
1061
|
-
width: r.width ?? g.edgeWidth,
|
|
1062
|
-
arrowLength: r.arrowLength ?? g.edgeArrowLength,
|
|
1063
|
-
arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
|
|
1064
|
-
arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
|
|
1065
|
-
hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
|
|
1066
|
-
hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
|
|
1067
|
-
cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
|
|
1068
|
-
roundness: r.roundness ?? g.roundness,
|
|
1069
|
-
detourDistance: r.detourDistance ?? g.detourDistance,
|
|
1070
|
-
detourDirection: r.detourDirection ?? g.detourDirection
|
|
1071
|
-
});
|
|
1072
|
-
case "horizontal":
|
|
1073
|
-
return ce({
|
|
1074
|
-
color: r.color ?? g.edgeColor,
|
|
1075
|
-
width: r.width ?? g.edgeWidth,
|
|
1076
|
-
arrowLength: r.arrowLength ?? g.edgeArrowLength,
|
|
1077
|
-
arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
|
|
1078
|
-
arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
|
|
1079
|
-
hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
|
|
1080
|
-
hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
|
|
1081
|
-
cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
|
|
1082
|
-
roundness: r.roundness ?? g.roundness,
|
|
1083
|
-
detourDistance: r.detourDistance ?? g.detourDistance,
|
|
1084
|
-
detourDirection: r.detourDirection ?? g.detourDirection
|
|
1085
|
-
});
|
|
1086
|
-
case "vertical":
|
|
1087
|
-
return de({
|
|
1088
|
-
color: r.color ?? g.edgeColor,
|
|
1089
|
-
width: r.width ?? g.edgeWidth,
|
|
1090
|
-
arrowLength: r.arrowLength ?? g.edgeArrowLength,
|
|
1091
|
-
arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
|
|
1092
|
-
arrowOffset: r.arrowOffset ?? g.edgeArrowOffset,
|
|
1093
|
-
hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
|
|
1094
|
-
hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
|
|
1095
|
-
cycleSquareSide: r.cycleSquareSide ?? g.cycleSize,
|
|
1096
|
-
roundness: r.roundness ?? g.roundness,
|
|
1097
|
-
detourDistance: r.detourDistance ?? g.detourDistance,
|
|
1098
|
-
detourDirection: r.detourDirection ?? g.detourDirection
|
|
1099
|
-
});
|
|
1100
|
-
default:
|
|
1101
|
-
return ae({
|
|
1102
|
-
color: r.color ?? g.edgeColor,
|
|
1103
|
-
width: r.width ?? g.edgeWidth,
|
|
1104
|
-
arrowLength: r.arrowLength ?? g.edgeArrowLength,
|
|
1105
|
-
arrowWidth: r.arrowWidth ?? g.edgeArrowWidth,
|
|
1106
|
-
hasSourceArrow: r.hasSourceArrow ?? g.hasSourceArrow,
|
|
1107
|
-
hasTargetArrow: r.hasTargetArrow ?? g.hasTargetArrow,
|
|
1108
|
-
cycleRadius: r.cycleRadius ?? g.cycleSize,
|
|
1109
|
-
detourDistance: r.detourDistance ?? g.detourDistance,
|
|
1110
|
-
detourDirection: r.detourDirection ?? g.detourDirection,
|
|
1111
|
-
smallCycleRadius: r.smallCycleRadius ?? g.smallCycleSize,
|
|
1112
|
-
curvature: r.curvature ?? g.curvature
|
|
1113
|
-
});
|
|
1114
|
-
}
|
|
1115
|
-
}, z = (r) => () => r, U = z(0), k = () => {
|
|
1116
|
-
let r = 0;
|
|
1117
|
-
return () => r++;
|
|
1118
|
-
}, pe = (r, e) => {
|
|
1119
|
-
const t = [
|
|
1120
|
-
U,
|
|
1121
|
-
U
|
|
1122
|
-
];
|
|
1123
|
-
r === "incremental" && (t[0] = k()), e === "incremental" && (t[1] = k());
|
|
1124
|
-
const s = k();
|
|
1125
|
-
return r === "shared-incremental" && (t[0] = s), e === "shared-incremental" && (t[1] = s), typeof r == "number" && (t[0] = z(r)), typeof e == "number" && (t[1] = z(e)), typeof r == "function" && (t[0] = r), typeof e == "function" && (t[1] = e), t;
|
|
1126
|
-
}, ve = (r) => {
|
|
1127
|
-
var s, o, i, h, a, d;
|
|
1128
|
-
const [e, t] = pe(
|
|
1129
|
-
(s = r.nodes) == null ? void 0 : s.priority,
|
|
1130
|
-
(o = r.edges) == null ? void 0 : o.priority
|
|
1131
|
-
);
|
|
1132
|
-
return {
|
|
1133
|
-
nodes: {
|
|
1134
|
-
centerFn: ((i = r.nodes) == null ? void 0 : i.centerFn) ?? H,
|
|
1135
|
-
priorityFn: e
|
|
1136
|
-
},
|
|
1137
|
-
ports: {
|
|
1138
|
-
centerFn: ((h = r.ports) == null ? void 0 : h.centerFn) ?? H,
|
|
1139
|
-
direction: ((a = r.ports) == null ? void 0 : a.direction) ?? 0
|
|
1140
|
-
},
|
|
1141
|
-
edges: {
|
|
1142
|
-
shapeFactory: R(((d = r.edges) == null ? void 0 : d.shape) ?? {}),
|
|
1143
|
-
priorityFn: t
|
|
1144
|
-
}
|
|
1145
|
-
};
|
|
1146
|
-
};
|
|
1147
|
-
class fe {
|
|
1148
|
-
constructor() {
|
|
1149
|
-
n(this, "keyMap", /* @__PURE__ */ new Map());
|
|
1150
|
-
n(this, "valueMap", /* @__PURE__ */ new Map());
|
|
1151
|
-
}
|
|
1152
|
-
set(e, t) {
|
|
1153
|
-
this.keyMap.set(e, t), this.valueMap.set(t, e);
|
|
1154
|
-
}
|
|
1155
|
-
hasKey(e) {
|
|
1156
|
-
return this.keyMap.has(e);
|
|
1157
|
-
}
|
|
1158
|
-
hasValue(e) {
|
|
1159
|
-
return this.valueMap.has(e);
|
|
1160
|
-
}
|
|
1161
|
-
getByKey(e) {
|
|
1162
|
-
return this.keyMap.get(e);
|
|
1210
|
+
class xt {
|
|
1211
|
+
constructor(t) {
|
|
1212
|
+
s(this, "transformation");
|
|
1213
|
+
s(this, "model");
|
|
1214
|
+
s(this, "canvasController");
|
|
1215
|
+
s(this, "edgeShapeFactory");
|
|
1216
|
+
this.apiOptions = t;
|
|
1217
|
+
const o = ct(this.apiOptions), r = new at(), i = new dt();
|
|
1218
|
+
this.model = new lt(i), this.transformation = new gt(r);
|
|
1219
|
+
const n = new ft(i, r);
|
|
1220
|
+
this.canvasController = new vt(
|
|
1221
|
+
i,
|
|
1222
|
+
n,
|
|
1223
|
+
r,
|
|
1224
|
+
o.nodes.centerFn,
|
|
1225
|
+
o.ports.direction,
|
|
1226
|
+
o.nodes.priorityFn,
|
|
1227
|
+
o.edges.priorityFn
|
|
1228
|
+
), this.edgeShapeFactory = o.edges.shapeFactory;
|
|
1163
1229
|
}
|
|
1164
|
-
|
|
1165
|
-
return this.
|
|
1230
|
+
attach(t) {
|
|
1231
|
+
return this.canvasController.attach(t), this;
|
|
1166
1232
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
t !== void 0 && this.valueMap.delete(t), this.keyMap.delete(e);
|
|
1233
|
+
detach() {
|
|
1234
|
+
return this.canvasController.detach(), this;
|
|
1170
1235
|
}
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1236
|
+
addNode(t) {
|
|
1237
|
+
return this.canvasController.addNode({
|
|
1238
|
+
nodeId: t.id,
|
|
1239
|
+
element: t.element,
|
|
1240
|
+
x: t.x,
|
|
1241
|
+
y: t.y,
|
|
1242
|
+
ports: t.ports,
|
|
1243
|
+
centerFn: t.centerFn,
|
|
1244
|
+
priority: t.priority
|
|
1245
|
+
}), this;
|
|
1174
1246
|
}
|
|
1175
|
-
|
|
1176
|
-
this.
|
|
1177
|
-
|
|
1178
|
-
|
|
1247
|
+
updateNode(t, o) {
|
|
1248
|
+
return this.canvasController.updateNode(t, {
|
|
1249
|
+
x: o == null ? void 0 : o.x,
|
|
1250
|
+
y: o == null ? void 0 : o.y,
|
|
1251
|
+
priority: o == null ? void 0 : o.priority,
|
|
1252
|
+
centerFn: o == null ? void 0 : o.centerFn
|
|
1253
|
+
}), this;
|
|
1179
1254
|
}
|
|
1180
|
-
|
|
1181
|
-
this.
|
|
1255
|
+
removeNode(t) {
|
|
1256
|
+
return this.canvasController.removeNode(t), this;
|
|
1182
1257
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
n(this, "nodes", new fe());
|
|
1191
|
-
n(this, "nodeIdGenerator", new I(
|
|
1192
|
-
(e) => this.nodes.hasKey(e)
|
|
1193
|
-
));
|
|
1194
|
-
n(this, "nodesResizeObserver");
|
|
1195
|
-
this.apiOptions = e, this.nodesResizeObserver = new window.ResizeObserver((s) => {
|
|
1196
|
-
s.forEach((o) => {
|
|
1197
|
-
const i = o.target, h = this.nodes.getByValue(i);
|
|
1198
|
-
this.updateNode(h), this.model.getNodeAdjacentEdgeIds(h).forEach((d) => {
|
|
1199
|
-
this.updateEdge(d);
|
|
1200
|
-
});
|
|
1201
|
-
});
|
|
1202
|
-
});
|
|
1203
|
-
const t = ve(this.apiOptions ?? {});
|
|
1204
|
-
this.di = new me({
|
|
1205
|
-
nodesCenterFn: t.nodes.centerFn,
|
|
1206
|
-
nodesPriorityFn: t.nodes.priorityFn,
|
|
1207
|
-
portsCenterFn: t.ports.centerFn,
|
|
1208
|
-
portsDirection: t.ports.direction,
|
|
1209
|
-
edgesPriorityFn: t.edges.priorityFn
|
|
1210
|
-
}), this.transformation = this.di.publicViewportTransformer, this.model = this.di.publicGraphStore, this.edgeShapeFactory = t.edges.shapeFactory;
|
|
1211
|
-
}
|
|
1212
|
-
addNode(e) {
|
|
1213
|
-
const t = this.nodeIdGenerator.create(e.id);
|
|
1214
|
-
return this.di.canvasController.addNode({
|
|
1215
|
-
nodeId: t,
|
|
1216
|
-
element: e.element,
|
|
1217
|
-
x: e.x,
|
|
1218
|
-
y: e.y,
|
|
1219
|
-
ports: e.ports,
|
|
1220
|
-
centerFn: e.centerFn,
|
|
1221
|
-
priority: e.priority
|
|
1222
|
-
}), this.nodes.set(t, e.element), this.nodesResizeObserver.observe(e.element), this;
|
|
1223
|
-
}
|
|
1224
|
-
updateNode(e, t) {
|
|
1225
|
-
return this.di.canvasController.updateNode(e, {
|
|
1226
|
-
x: t == null ? void 0 : t.x,
|
|
1227
|
-
y: t == null ? void 0 : t.y,
|
|
1228
|
-
priority: t == null ? void 0 : t.priority,
|
|
1229
|
-
centerFn: t == null ? void 0 : t.centerFn
|
|
1258
|
+
addEdge(t) {
|
|
1259
|
+
return this.canvasController.addEdge({
|
|
1260
|
+
edgeId: t.id,
|
|
1261
|
+
from: t.from,
|
|
1262
|
+
to: t.to,
|
|
1263
|
+
shape: t.shape ?? this.edgeShapeFactory(),
|
|
1264
|
+
priority: t.priority
|
|
1230
1265
|
}), this;
|
|
1231
1266
|
}
|
|
1232
|
-
|
|
1233
|
-
this.
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
markPort(e) {
|
|
1240
|
-
return this.di.canvasController.markPort({
|
|
1241
|
-
portId: e.id,
|
|
1242
|
-
element: e.element,
|
|
1243
|
-
nodeId: e.nodeId,
|
|
1244
|
-
centerFn: e.centerFn,
|
|
1245
|
-
direction: e.direction
|
|
1267
|
+
updateEdge(t, o) {
|
|
1268
|
+
return this.canvasController.updateEdge({
|
|
1269
|
+
edgeId: t,
|
|
1270
|
+
shape: o == null ? void 0 : o.shape,
|
|
1271
|
+
priority: o == null ? void 0 : o.priority,
|
|
1272
|
+
from: o == null ? void 0 : o.from,
|
|
1273
|
+
to: o == null ? void 0 : o.to
|
|
1246
1274
|
}), this;
|
|
1247
1275
|
}
|
|
1248
|
-
|
|
1249
|
-
return this.
|
|
1250
|
-
direction: t == null ? void 0 : t.direction,
|
|
1251
|
-
centerFn: t == null ? void 0 : t.centerFn
|
|
1252
|
-
}), this;
|
|
1276
|
+
removeEdge(t) {
|
|
1277
|
+
return this.canvasController.removeEdge(t), this;
|
|
1253
1278
|
}
|
|
1254
|
-
|
|
1255
|
-
return this.
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
edgeId: e.id,
|
|
1261
|
-
from: e.from,
|
|
1262
|
-
to: e.to,
|
|
1263
|
-
shapeFactory: t,
|
|
1264
|
-
priority: e.priority
|
|
1279
|
+
markPort(t) {
|
|
1280
|
+
return this.canvasController.markPort({
|
|
1281
|
+
portId: t.id,
|
|
1282
|
+
element: t.element,
|
|
1283
|
+
nodeId: t.nodeId,
|
|
1284
|
+
direction: t.direction
|
|
1265
1285
|
}), this;
|
|
1266
1286
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
edgeId: e,
|
|
1271
|
-
shape: s,
|
|
1272
|
-
priority: t == null ? void 0 : t.priority
|
|
1287
|
+
updatePort(t, o) {
|
|
1288
|
+
return this.canvasController.updatePort(t, {
|
|
1289
|
+
direction: o == null ? void 0 : o.direction
|
|
1273
1290
|
}), this;
|
|
1274
1291
|
}
|
|
1275
|
-
|
|
1276
|
-
return this.
|
|
1292
|
+
unmarkPort(t) {
|
|
1293
|
+
return this.canvasController.unmarkPort(t), this;
|
|
1277
1294
|
}
|
|
1278
|
-
patchViewportMatrix(
|
|
1279
|
-
return this.
|
|
1295
|
+
patchViewportMatrix(t) {
|
|
1296
|
+
return this.canvasController.patchViewportMatrix(t), this;
|
|
1280
1297
|
}
|
|
1281
|
-
patchContentMatrix(
|
|
1282
|
-
return this.
|
|
1298
|
+
patchContentMatrix(t) {
|
|
1299
|
+
return this.canvasController.patchContentMatrix(t), this;
|
|
1283
1300
|
}
|
|
1284
1301
|
clear() {
|
|
1285
|
-
return this.
|
|
1286
|
-
}
|
|
1287
|
-
attach(e) {
|
|
1288
|
-
return this.di.canvasController.attach(e), this;
|
|
1289
|
-
}
|
|
1290
|
-
detach() {
|
|
1291
|
-
return this.di.canvasController.detach(), this;
|
|
1302
|
+
return this.canvasController.clear(), this;
|
|
1292
1303
|
}
|
|
1293
1304
|
destroy() {
|
|
1294
|
-
this.clear(), this.
|
|
1305
|
+
this.clear(), this.canvasController.destroy();
|
|
1295
1306
|
}
|
|
1296
1307
|
}
|
|
1297
|
-
const
|
|
1298
|
-
const { x:
|
|
1299
|
-
return
|
|
1300
|
-
},
|
|
1301
|
-
|
|
1308
|
+
const P = (e, t, o) => {
|
|
1309
|
+
const { x: r, y: i, width: n, height: d } = e.getBoundingClientRect();
|
|
1310
|
+
return t >= r && t <= r + n && o >= i && o <= i + d;
|
|
1311
|
+
}, L = (e, t, o) => t >= 0 && t <= e.innerWidth && o >= 0 && o <= e.innerHeight, D = (e, t) => {
|
|
1312
|
+
t !== null ? e.style.cursor = t : e.style.removeProperty("cursor");
|
|
1302
1313
|
};
|
|
1303
|
-
class
|
|
1304
|
-
constructor(
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
(
|
|
1314
|
+
class St {
|
|
1315
|
+
constructor(t, o) {
|
|
1316
|
+
s(this, "model");
|
|
1317
|
+
s(this, "transformation");
|
|
1318
|
+
s(this, "maxNodePriority", 0);
|
|
1319
|
+
s(this, "nodes", /* @__PURE__ */ new Map());
|
|
1320
|
+
s(this, "grabbedNodeId", null);
|
|
1321
|
+
s(this, "onNodeDrag");
|
|
1322
|
+
s(this, "onBeforeNodeDrag");
|
|
1323
|
+
s(this, "nodeIdGenerator", new C(
|
|
1324
|
+
(t) => this.nodes.has(t)
|
|
1314
1325
|
));
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
this.
|
|
1318
|
-
});
|
|
1319
|
-
n(this, "onCanvasMouseMove", (e) => {
|
|
1320
|
-
if (this.element !== null && (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY))) {
|
|
1326
|
+
s(this, "element", null);
|
|
1327
|
+
s(this, "onWindowMouseMove", (t) => {
|
|
1328
|
+
if (this.element !== null && (!P(this.element, t.clientX, t.clientY) || !L(this.window, t.clientX, t.clientY))) {
|
|
1321
1329
|
this.cancelMouseDrag();
|
|
1322
1330
|
return;
|
|
1323
1331
|
}
|
|
1324
|
-
this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId,
|
|
1332
|
+
this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, t.movementX, t.movementY);
|
|
1325
1333
|
});
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
e.touches[0].clientX,
|
|
1329
|
-
e.touches[0].clientY
|
|
1330
|
-
];
|
|
1334
|
+
s(this, "onWindowMouseUp", (t) => {
|
|
1335
|
+
t.button === 0 && this.cancelMouseDrag();
|
|
1331
1336
|
});
|
|
1332
|
-
|
|
1333
|
-
if (
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
}
|
|
1337
|
+
s(this, "onWindowTouchMove", (t) => {
|
|
1338
|
+
if (t.touches.length !== 1)
|
|
1339
|
+
return;
|
|
1340
|
+
const o = t.touches[0];
|
|
1341
|
+
if (this.element !== null && (!P(this.element, o.clientX, o.clientY) || !L(this.window, o.clientX, o.clientY))) {
|
|
1342
|
+
this.cancelTouchDrag();
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
if (this.grabbedNodeId !== null && this.previousTouchCoords !== null) {
|
|
1346
|
+
const r = o.clientX - this.previousTouchCoords.x, i = o.clientY - this.previousTouchCoords.y;
|
|
1347
|
+
this.dragNode(this.grabbedNodeId, r, i), this.previousTouchCoords = {
|
|
1348
|
+
x: t.touches[0].clientX,
|
|
1349
|
+
y: t.touches[0].clientY
|
|
1350
|
+
};
|
|
1347
1351
|
}
|
|
1348
1352
|
});
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1353
|
+
s(this, "onWindowTouchFinish", (t) => {
|
|
1354
|
+
t.touches.length > 0 ? this.previousTouchCoords = {
|
|
1355
|
+
x: t.touches[0].clientX,
|
|
1356
|
+
y: t.touches[0].clientY
|
|
1357
|
+
} : this.cancelTouchDrag();
|
|
1354
1358
|
});
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
var
|
|
1360
|
-
this.canvas =
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1359
|
+
s(this, "previousTouchCoords", null);
|
|
1360
|
+
s(this, "freezePriority");
|
|
1361
|
+
s(this, "window", window);
|
|
1362
|
+
s(this, "dragCursor");
|
|
1363
|
+
var r, i;
|
|
1364
|
+
this.canvas = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.onNodeDrag = ((r = o == null ? void 0 : o.events) == null ? void 0 : r.onNodeDrag) ?? (() => {
|
|
1365
|
+
}), this.onBeforeNodeDrag = ((i = o == null ? void 0 : o.events) == null ? void 0 : i.onBeforeNodeDrag) ?? (() => !0), this.freezePriority = (o == null ? void 0 : o.moveOnTop) === !1, this.dragCursor = (o == null ? void 0 : o.dragCursor) !== void 0 ? o.dragCursor : "grab";
|
|
1366
|
+
}
|
|
1367
|
+
attach(t) {
|
|
1368
|
+
return this.detach(), this.element = t, this.canvas.attach(this.element), this;
|
|
1369
|
+
}
|
|
1370
|
+
detach() {
|
|
1371
|
+
return this.canvas.detach(), this.element !== null && (this.element = null), this;
|
|
1372
|
+
}
|
|
1373
|
+
addNode(t) {
|
|
1374
|
+
const o = this.nodeIdGenerator.create(t.id);
|
|
1375
|
+
this.canvas.addNode({ ...t, id: o }), this.updateMaxNodePriority(o);
|
|
1376
|
+
const r = (n) => {
|
|
1377
|
+
if (this.element === null || n.button !== 0)
|
|
1372
1378
|
return;
|
|
1373
|
-
const
|
|
1379
|
+
const d = this.model.getNode(o);
|
|
1374
1380
|
this.onBeforeNodeDrag({
|
|
1375
|
-
nodeId:
|
|
1376
|
-
element:
|
|
1377
|
-
x:
|
|
1378
|
-
y:
|
|
1379
|
-
}) && (
|
|
1380
|
-
},
|
|
1381
|
-
|
|
1381
|
+
nodeId: o,
|
|
1382
|
+
element: t.element,
|
|
1383
|
+
x: d.x,
|
|
1384
|
+
y: d.y
|
|
1385
|
+
}) && (n.stopImmediatePropagation(), this.grabbedNodeId = o, D(this.element, this.dragCursor), this.moveNodeOnTop(o), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
|
|
1386
|
+
}, i = (n) => {
|
|
1387
|
+
n.stopImmediatePropagation(), this.previousTouchCoords = {
|
|
1388
|
+
x: n.touches[0].clientX,
|
|
1389
|
+
y: n.touches[0].clientY
|
|
1390
|
+
};
|
|
1391
|
+
const d = this.model.getNode(o);
|
|
1382
1392
|
this.onBeforeNodeDrag({
|
|
1383
|
-
nodeId:
|
|
1384
|
-
element:
|
|
1385
|
-
x:
|
|
1386
|
-
y:
|
|
1387
|
-
}) &&
|
|
1393
|
+
nodeId: o,
|
|
1394
|
+
element: t.element,
|
|
1395
|
+
x: d.x,
|
|
1396
|
+
y: d.y
|
|
1397
|
+
}) && n.touches.length === 1 && (this.grabbedNodeId = o, this.moveNodeOnTop(o), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish));
|
|
1388
1398
|
};
|
|
1389
|
-
return this.nodes.set(
|
|
1390
|
-
element:
|
|
1391
|
-
onMouseDown:
|
|
1392
|
-
onTouchStart:
|
|
1393
|
-
}),
|
|
1399
|
+
return this.nodes.set(o, {
|
|
1400
|
+
element: t.element,
|
|
1401
|
+
onMouseDown: r,
|
|
1402
|
+
onTouchStart: i
|
|
1403
|
+
}), t.element.addEventListener("mousedown", r), t.element.addEventListener("touchstart", i), this;
|
|
1394
1404
|
}
|
|
1395
|
-
updateNode(
|
|
1396
|
-
return this.canvas.updateNode(
|
|
1405
|
+
updateNode(t, o) {
|
|
1406
|
+
return this.canvas.updateNode(t, o), this.updateMaxNodePriority(t), this;
|
|
1397
1407
|
}
|
|
1398
|
-
removeNode(
|
|
1399
|
-
const
|
|
1400
|
-
return
|
|
1408
|
+
removeNode(t) {
|
|
1409
|
+
const o = this.nodes.get(t);
|
|
1410
|
+
return o !== void 0 && (o.element.removeEventListener("mousedown", o.onMouseDown), o.element.removeEventListener("touchstart", o.onTouchStart)), this.nodes.delete(t), this.canvas.removeNode(t), this;
|
|
1401
1411
|
}
|
|
1402
|
-
markPort(
|
|
1403
|
-
return this.canvas.markPort(
|
|
1412
|
+
markPort(t) {
|
|
1413
|
+
return this.canvas.markPort(t), this;
|
|
1404
1414
|
}
|
|
1405
|
-
updatePort(
|
|
1406
|
-
return this.canvas.updatePort(
|
|
1415
|
+
updatePort(t, o) {
|
|
1416
|
+
return this.canvas.updatePort(t, o), this;
|
|
1407
1417
|
}
|
|
1408
|
-
unmarkPort(
|
|
1409
|
-
return this.canvas.unmarkPort(
|
|
1418
|
+
unmarkPort(t) {
|
|
1419
|
+
return this.canvas.unmarkPort(t), this;
|
|
1410
1420
|
}
|
|
1411
|
-
addEdge(
|
|
1412
|
-
return this.canvas.addEdge(
|
|
1421
|
+
addEdge(t) {
|
|
1422
|
+
return this.canvas.addEdge(t), this;
|
|
1413
1423
|
}
|
|
1414
|
-
updateEdge(
|
|
1415
|
-
return this.canvas.updateEdge(
|
|
1424
|
+
updateEdge(t, o) {
|
|
1425
|
+
return this.canvas.updateEdge(t, o), this;
|
|
1416
1426
|
}
|
|
1417
|
-
removeEdge(
|
|
1418
|
-
return this.canvas.removeEdge(
|
|
1427
|
+
removeEdge(t) {
|
|
1428
|
+
return this.canvas.removeEdge(t), this;
|
|
1419
1429
|
}
|
|
1420
|
-
patchViewportMatrix(
|
|
1421
|
-
return this.canvas.patchViewportMatrix(
|
|
1430
|
+
patchViewportMatrix(t) {
|
|
1431
|
+
return this.canvas.patchViewportMatrix(t), this;
|
|
1422
1432
|
}
|
|
1423
|
-
patchContentMatrix(
|
|
1424
|
-
return this.canvas.patchContentMatrix(
|
|
1433
|
+
patchContentMatrix(t) {
|
|
1434
|
+
return this.canvas.patchContentMatrix(t), this;
|
|
1425
1435
|
}
|
|
1426
1436
|
clear() {
|
|
1427
|
-
return this.canvas.clear(), this.nodes.forEach((
|
|
1428
|
-
|
|
1437
|
+
return this.canvas.clear(), this.nodes.forEach((t) => {
|
|
1438
|
+
t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart);
|
|
1429
1439
|
}), this.nodes.clear(), this.maxNodePriority = 0, this;
|
|
1430
1440
|
}
|
|
1431
|
-
attach(e) {
|
|
1432
|
-
return this.detach(), this.element = e, this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.canvas.attach(this.element), this;
|
|
1433
|
-
}
|
|
1434
|
-
detach() {
|
|
1435
|
-
return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("touchstart", this.onCanvasTouchStart), this.element = null), this;
|
|
1436
|
-
}
|
|
1437
1441
|
destroy() {
|
|
1438
|
-
this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
x: o.x,
|
|
1451
|
-
y: o.y
|
|
1442
|
+
this.detach(), this.clear(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
|
|
1443
|
+
}
|
|
1444
|
+
dragNode(t, o, r) {
|
|
1445
|
+
const i = this.model.getNode(t);
|
|
1446
|
+
if (i === null)
|
|
1447
|
+
return;
|
|
1448
|
+
const n = this.canvas.transformation.getContentMatrix(), d = n.scale * i.x + n.dx, c = n.scale * i.y + n.dy, h = d + o, l = c + r, a = this.canvas.transformation.getViewportMatrix(), w = a.scale * h + a.dx, y = a.scale * l + a.dy;
|
|
1449
|
+
this.canvas.updateNode(t, { x: w, y }), this.onNodeDrag({
|
|
1450
|
+
nodeId: t,
|
|
1451
|
+
element: i.element,
|
|
1452
|
+
x: i.x,
|
|
1453
|
+
y: i.y
|
|
1452
1454
|
});
|
|
1453
1455
|
}
|
|
1454
|
-
updateMaxNodePriority(
|
|
1455
|
-
const
|
|
1456
|
-
this.maxNodePriority = Math.max(this.maxNodePriority,
|
|
1456
|
+
updateMaxNodePriority(t) {
|
|
1457
|
+
const o = this.model.getNode(t).priority;
|
|
1458
|
+
this.maxNodePriority = Math.max(this.maxNodePriority, o);
|
|
1457
1459
|
}
|
|
1458
|
-
moveNodeOnTop(
|
|
1460
|
+
moveNodeOnTop(t) {
|
|
1459
1461
|
if (this.freezePriority)
|
|
1460
1462
|
return;
|
|
1461
|
-
this.maxNodePriority += 2, this.updateNode(
|
|
1462
|
-
const
|
|
1463
|
-
this.model.getNodeAdjacentEdgeIds(
|
|
1464
|
-
this.updateEdge(
|
|
1463
|
+
this.maxNodePriority += 2, this.updateNode(t, { priority: this.maxNodePriority });
|
|
1464
|
+
const o = this.maxNodePriority - 1;
|
|
1465
|
+
this.model.getNodeAdjacentEdgeIds(t).forEach((i) => {
|
|
1466
|
+
this.updateEdge(i, { priority: o });
|
|
1465
1467
|
});
|
|
1466
1468
|
}
|
|
1467
1469
|
cancelMouseDrag() {
|
|
1468
|
-
this.grabbedNodeId = null, this.element !== null &&
|
|
1470
|
+
this.grabbedNodeId = null, this.element !== null && D(this.element, null), this.removeMouseDragListeners();
|
|
1469
1471
|
}
|
|
1470
1472
|
removeMouseDragListeners() {
|
|
1471
|
-
this.window.removeEventListener("mouseup", this.
|
|
1473
|
+
this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
1472
1474
|
}
|
|
1473
1475
|
cancelTouchDrag() {
|
|
1474
1476
|
this.previousTouchCoords = null, this.grabbedNodeId = null, this.removeTouchDragListeners();
|
|
1475
1477
|
}
|
|
1476
1478
|
removeTouchDragListeners() {
|
|
1477
|
-
this.window.removeEventListener("touchmove", this.
|
|
1479
|
+
this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
|
|
1478
1480
|
}
|
|
1479
1481
|
}
|
|
1480
|
-
const
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1482
|
+
const At = (e) => {
|
|
1483
|
+
const t = e.minX !== null ? e.minX : -1 / 0, o = e.maxX !== null ? e.maxX : 1 / 0, r = e.minY !== null ? e.minY : -1 / 0, i = e.maxY !== null ? e.maxY : 1 / 0;
|
|
1484
|
+
return (n) => {
|
|
1485
|
+
let d = n.nextTransform.dx, c = n.nextTransform.dy;
|
|
1486
|
+
d < t && d < n.prevTransform.dx && (d = Math.min(n.prevTransform.dx, t));
|
|
1487
|
+
const h = n.canvasWidth * n.prevTransform.scale;
|
|
1488
|
+
d > o - h && d > n.prevTransform.dx && (d = Math.max(n.prevTransform.dx, o - h)), c < r && c < n.prevTransform.dy && (c = Math.min(n.prevTransform.dy, r));
|
|
1489
|
+
const l = n.canvasHeight * n.prevTransform.scale;
|
|
1490
|
+
return c > i - l && c > n.prevTransform.dy && (c = Math.max(n.prevTransform.dy, i - l)), { scale: n.nextTransform.scale, dx: d, dy: c };
|
|
1491
|
+
};
|
|
1492
|
+
}, Et = (e) => {
|
|
1493
|
+
const t = e.maxContentScale, o = e.minContentScale, r = t !== null ? 1 / t : 0, i = o !== null ? 1 / o : 1 / 0;
|
|
1494
|
+
return (n) => {
|
|
1495
|
+
let d = n.nextTransform.scale, c = n.nextTransform.dx, h = n.nextTransform.dy;
|
|
1496
|
+
return n.nextTransform.scale > i && n.nextTransform.scale > n.prevTransform.scale && (d = Math.max(n.prevTransform.scale, i), c = n.prevTransform.dx, h = n.prevTransform.dy), n.nextTransform.scale < r && n.nextTransform.scale < n.prevTransform.scale && (d = Math.min(n.prevTransform.scale, r), c = n.prevTransform.dx, h = n.prevTransform.dy), {
|
|
1497
|
+
scale: d,
|
|
1498
|
+
dx: c,
|
|
1499
|
+
dy: h
|
|
1500
|
+
};
|
|
1501
|
+
};
|
|
1502
|
+
}, Tt = (e) => (t) => e.reduce(
|
|
1503
|
+
(o, r) => r({
|
|
1504
|
+
prevTransform: t.prevTransform,
|
|
1505
|
+
nextTransform: o,
|
|
1506
|
+
canvasWidth: t.canvasWidth,
|
|
1507
|
+
canvasHeight: t.canvasHeight
|
|
1508
|
+
}),
|
|
1509
|
+
t.nextTransform
|
|
1510
|
+
), O = (e) => {
|
|
1511
|
+
if (typeof e == "function")
|
|
1512
|
+
return e;
|
|
1513
|
+
switch (e.type) {
|
|
1493
1514
|
case "scale-limit":
|
|
1494
|
-
return
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
);
|
|
1515
|
+
return Et({
|
|
1516
|
+
minContentScale: e.minContentScale ?? 0,
|
|
1517
|
+
maxContentScale: e.maxContentScale ?? 1 / 0
|
|
1518
|
+
});
|
|
1498
1519
|
case "shift-limit":
|
|
1499
|
-
return
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
);
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
n
|
|
1524
|
-
|
|
1525
|
-
|
|
1520
|
+
return At({
|
|
1521
|
+
minX: e.minX ?? -1 / 0,
|
|
1522
|
+
maxX: e.maxX ?? 1 / 0,
|
|
1523
|
+
minY: e.minY ?? -1 / 0,
|
|
1524
|
+
maxY: e.maxY ?? 1 / 0
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
}, Mt = (e) => {
|
|
1528
|
+
var h, l, a, w;
|
|
1529
|
+
const t = (h = e == null ? void 0 : e.scale) == null ? void 0 : h.wheelSensitivity, o = t !== void 0 ? t : 1.2, r = e == null ? void 0 : e.transformPreprocessor;
|
|
1530
|
+
let i;
|
|
1531
|
+
r !== void 0 ? Array.isArray(r) ? i = Tt(
|
|
1532
|
+
r.map(
|
|
1533
|
+
(y) => O(y)
|
|
1534
|
+
)
|
|
1535
|
+
) : i = O(r) : i = (y) => y.nextTransform;
|
|
1536
|
+
const n = ((l = e == null ? void 0 : e.shift) == null ? void 0 : l.cursor) !== void 0 ? e.shift.cursor : "grab", d = ((a = e == null ? void 0 : e.events) == null ? void 0 : a.onBeforeTransformStarted) ?? (() => {
|
|
1537
|
+
}), c = ((w = e == null ? void 0 : e.events) == null ? void 0 : w.onTransformFinished) ?? (() => {
|
|
1538
|
+
});
|
|
1539
|
+
return {
|
|
1540
|
+
wheelSensitivity: o,
|
|
1541
|
+
onBeforeTransformStarted: d,
|
|
1542
|
+
onTransformFinished: c,
|
|
1543
|
+
transformPreprocessor: i,
|
|
1544
|
+
shiftCursor: n
|
|
1545
|
+
};
|
|
1546
|
+
}, W = (e) => {
|
|
1547
|
+
const t = [], o = e.touches.length;
|
|
1548
|
+
for (let c = 0; c < o; c++)
|
|
1549
|
+
t.push([e.touches[c].clientX, e.touches[c].clientY]);
|
|
1550
|
+
const r = t.reduce(
|
|
1551
|
+
(c, h) => [c[0] + h[0], c[1] + h[1]],
|
|
1552
|
+
[0, 0]
|
|
1553
|
+
), i = [r[0] / o, r[1] / o], d = t.map((c) => [c[0] - i[0], c[1] - i[1]]).reduce(
|
|
1554
|
+
(c, h) => c + Math.sqrt(h[0] * h[0] + h[1] * h[1]),
|
|
1555
|
+
0
|
|
1556
|
+
);
|
|
1557
|
+
return {
|
|
1558
|
+
x: i[0],
|
|
1559
|
+
y: i[1],
|
|
1560
|
+
scale: d / o,
|
|
1561
|
+
touchesCnt: o,
|
|
1562
|
+
touches: t
|
|
1563
|
+
};
|
|
1564
|
+
}, Ct = (e, t, o) => ({
|
|
1565
|
+
scale: e.scale,
|
|
1566
|
+
dx: e.dx + e.scale * t,
|
|
1567
|
+
dy: e.dy + e.scale * o
|
|
1568
|
+
}), Nt = (e, t, o, r) => ({
|
|
1569
|
+
scale: e.scale * t,
|
|
1570
|
+
dx: e.scale * (1 - t) * o + e.dx,
|
|
1571
|
+
dy: e.scale * (1 - t) * r + e.dy
|
|
1572
|
+
});
|
|
1573
|
+
class Pt {
|
|
1574
|
+
constructor(t, o) {
|
|
1575
|
+
s(this, "model");
|
|
1576
|
+
s(this, "transformation");
|
|
1577
|
+
s(this, "element", null);
|
|
1578
|
+
s(this, "prevTouches", null);
|
|
1579
|
+
s(this, "window", window);
|
|
1580
|
+
s(this, "onMouseDown", (t) => {
|
|
1581
|
+
this.element === null || t.button !== 0 || (D(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp));
|
|
1526
1582
|
});
|
|
1527
|
-
|
|
1528
|
-
if (
|
|
1529
|
-
return;
|
|
1530
|
-
if (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY)) {
|
|
1583
|
+
s(this, "onWindowMouseMove", (t) => {
|
|
1584
|
+
if (this.element === null || !P(this.element, t.clientX, t.clientY) || !L(this.window, t.clientX, t.clientY)) {
|
|
1531
1585
|
this.stopMouseDrag();
|
|
1532
1586
|
return;
|
|
1533
1587
|
}
|
|
1534
|
-
const
|
|
1535
|
-
this.moveViewport(
|
|
1588
|
+
const o = -t.movementX, r = -t.movementY;
|
|
1589
|
+
this.moveViewport(this.element, o, r);
|
|
1536
1590
|
});
|
|
1537
|
-
|
|
1538
|
-
this.stopMouseDrag();
|
|
1591
|
+
s(this, "onWindowMouseUp", (t) => {
|
|
1592
|
+
this.element === null || t.button !== 0 || this.stopMouseDrag();
|
|
1539
1593
|
});
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
const { left: t, top: s } = this.element.getBoundingClientRect(), o = e.clientX - t, i = e.clientY - s, a = 1 / (e.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
|
|
1545
|
-
this.scaleViewport(a, o, i);
|
|
1594
|
+
s(this, "onWheelScroll", (t) => {
|
|
1595
|
+
t.preventDefault();
|
|
1596
|
+
const { left: o, top: r } = this.element.getBoundingClientRect(), i = t.clientX - o, n = t.clientY - r, c = 1 / (t.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
|
|
1597
|
+
this.scaleViewport(this.element, c, i, n);
|
|
1546
1598
|
});
|
|
1547
|
-
|
|
1548
|
-
this.prevTouches =
|
|
1599
|
+
s(this, "onTouchStart", (t) => {
|
|
1600
|
+
this.prevTouches = W(t), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish);
|
|
1549
1601
|
});
|
|
1550
|
-
|
|
1551
|
-
|
|
1602
|
+
s(this, "onWindowTouchMove", (t) => {
|
|
1603
|
+
const o = this.element;
|
|
1604
|
+
if (o === null)
|
|
1552
1605
|
return;
|
|
1553
|
-
const
|
|
1554
|
-
if (!
|
|
1555
|
-
(
|
|
1606
|
+
const r = W(t);
|
|
1607
|
+
if (!r.touches.every(
|
|
1608
|
+
(n) => P(o, n[0], n[1]) && L(this.window, n[0], n[1])
|
|
1556
1609
|
)) {
|
|
1557
1610
|
this.stopTouchDrag();
|
|
1558
1611
|
return;
|
|
1559
1612
|
}
|
|
1560
|
-
if ((
|
|
1561
|
-
|
|
1562
|
-
-(
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1613
|
+
if ((r.touchesCnt === 1 || r.touchesCnt === 2) && this.moveViewport(
|
|
1614
|
+
o,
|
|
1615
|
+
-(r.x - this.prevTouches.x),
|
|
1616
|
+
-(r.y - this.prevTouches.y)
|
|
1617
|
+
), r.touchesCnt === 2) {
|
|
1618
|
+
const { left: n, top: d } = o.getBoundingClientRect(), c = this.prevTouches.x - n, h = this.prevTouches.y - d, a = 1 / (r.scale / this.prevTouches.scale);
|
|
1619
|
+
this.scaleViewport(o, a, c, h);
|
|
1566
1620
|
}
|
|
1567
|
-
this.prevTouches =
|
|
1621
|
+
this.prevTouches = r;
|
|
1568
1622
|
});
|
|
1569
|
-
|
|
1570
|
-
|
|
1623
|
+
s(this, "onWindowTouchFinish", (t) => {
|
|
1624
|
+
t.touches.length > 0 ? this.prevTouches = W(t) : this.stopTouchDrag();
|
|
1571
1625
|
});
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
this.canvas.patchViewportMatrix(o), this.onTransformFinished();
|
|
1581
|
-
}
|
|
1626
|
+
s(this, "observer", new ResizeObserver(() => {
|
|
1627
|
+
const t = this.canvas.transformation.getViewportMatrix(), { width: o, height: r } = this.element.getBoundingClientRect(), i = this.options.transformPreprocessor({
|
|
1628
|
+
prevTransform: t,
|
|
1629
|
+
nextTransform: t,
|
|
1630
|
+
canvasWidth: o,
|
|
1631
|
+
canvasHeight: r
|
|
1632
|
+
});
|
|
1633
|
+
this.canvas.patchViewportMatrix(i), this.options.onTransformFinished();
|
|
1582
1634
|
}));
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
this.canvas = e, this.options = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((h = (i = this.options) == null ? void 0 : i.scale) == null ? void 0 : h.enabled) !== !1, this.isShiftable = ((d = (a = this.options) == null ? void 0 : a.shift) == null ? void 0 : d.enabled) !== !1;
|
|
1586
|
-
const s = (u = (c = this.options) == null ? void 0 : c.scale) == null ? void 0 : u.wheelSensitivity;
|
|
1587
|
-
this.wheelSensitivity = s !== void 0 ? s : 1.2, this.onTransformFinished = ((w = t == null ? void 0 : t.events) == null ? void 0 : w.onTransformFinished) ?? Ae;
|
|
1588
|
-
const o = t == null ? void 0 : t.transformPreprocessor;
|
|
1589
|
-
o !== void 0 ? Array.isArray(o) ? this.transformPreprocessor = Me(
|
|
1590
|
-
o.map(
|
|
1591
|
-
(y) => K(y)
|
|
1592
|
-
)
|
|
1593
|
-
) : this.transformPreprocessor = K(o) : this.transformPreprocessor = Ce, this.shiftCursor = ((m = t == null ? void 0 : t.shift) == null ? void 0 : m.cursor) !== void 0 ? t.shift.cursor : "grab";
|
|
1635
|
+
s(this, "options");
|
|
1636
|
+
this.canvas = t, this.options = Mt(o), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
|
|
1594
1637
|
}
|
|
1595
|
-
|
|
1596
|
-
return this.canvas.
|
|
1638
|
+
attach(t) {
|
|
1639
|
+
return this.detach(), this.element = t, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.canvas.attach(this.element), this;
|
|
1597
1640
|
}
|
|
1598
|
-
|
|
1599
|
-
return this.canvas.
|
|
1641
|
+
detach() {
|
|
1642
|
+
return this.canvas.detach(), this.element !== null && (this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element = null), this;
|
|
1600
1643
|
}
|
|
1601
|
-
|
|
1602
|
-
return this.canvas.
|
|
1644
|
+
addNode(t) {
|
|
1645
|
+
return this.canvas.addNode(t), this;
|
|
1603
1646
|
}
|
|
1604
|
-
|
|
1605
|
-
return this.canvas.
|
|
1647
|
+
updateNode(t, o) {
|
|
1648
|
+
return this.canvas.updateNode(t, o), this;
|
|
1606
1649
|
}
|
|
1607
|
-
|
|
1608
|
-
return this.canvas.
|
|
1650
|
+
removeNode(t) {
|
|
1651
|
+
return this.canvas.removeNode(t), this;
|
|
1609
1652
|
}
|
|
1610
|
-
|
|
1611
|
-
return this.canvas.
|
|
1653
|
+
markPort(t) {
|
|
1654
|
+
return this.canvas.markPort(t), this;
|
|
1612
1655
|
}
|
|
1613
|
-
|
|
1614
|
-
return this.canvas.
|
|
1656
|
+
updatePort(t, o) {
|
|
1657
|
+
return this.canvas.updatePort(t, o), this;
|
|
1615
1658
|
}
|
|
1616
|
-
|
|
1617
|
-
return this.canvas.
|
|
1659
|
+
unmarkPort(t) {
|
|
1660
|
+
return this.canvas.unmarkPort(t), this;
|
|
1618
1661
|
}
|
|
1619
|
-
|
|
1620
|
-
return this.canvas.
|
|
1662
|
+
addEdge(t) {
|
|
1663
|
+
return this.canvas.addEdge(t), this;
|
|
1621
1664
|
}
|
|
1622
|
-
|
|
1623
|
-
return this.canvas.
|
|
1665
|
+
updateEdge(t, o) {
|
|
1666
|
+
return this.canvas.updateEdge(t, o), this;
|
|
1624
1667
|
}
|
|
1625
|
-
|
|
1626
|
-
return this.canvas.
|
|
1668
|
+
removeEdge(t) {
|
|
1669
|
+
return this.canvas.removeEdge(t), this;
|
|
1627
1670
|
}
|
|
1628
|
-
|
|
1629
|
-
return this.canvas.
|
|
1671
|
+
patchViewportMatrix(t) {
|
|
1672
|
+
return this.canvas.patchViewportMatrix(t), this;
|
|
1630
1673
|
}
|
|
1631
|
-
|
|
1632
|
-
return this.
|
|
1674
|
+
patchContentMatrix(t) {
|
|
1675
|
+
return this.canvas.patchContentMatrix(t), this;
|
|
1633
1676
|
}
|
|
1634
|
-
|
|
1635
|
-
return this.canvas.
|
|
1677
|
+
clear() {
|
|
1678
|
+
return this.canvas.clear(), this;
|
|
1636
1679
|
}
|
|
1637
1680
|
destroy() {
|
|
1638
1681
|
this.detach(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
|
|
1639
1682
|
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
)
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
};
|
|
1658
|
-
|
|
1659
|
-
moveViewport(e, t) {
|
|
1660
|
-
const s = this.transformation.getViewportMatrix(), o = {
|
|
1661
|
-
scale: s.scale,
|
|
1662
|
-
dx: s.dx + s.scale * e,
|
|
1663
|
-
dy: s.dy + s.scale * t
|
|
1664
|
-
};
|
|
1665
|
-
if (this.element !== null) {
|
|
1666
|
-
const { width: i, height: h } = this.element.getBoundingClientRect(), a = this.transformPreprocessor(
|
|
1667
|
-
s,
|
|
1668
|
-
o,
|
|
1669
|
-
i,
|
|
1670
|
-
h
|
|
1671
|
-
);
|
|
1672
|
-
this.canvas.patchViewportMatrix(a), this.onTransformFinished();
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
scaleViewport(e, t, s) {
|
|
1676
|
-
if (this.element === null)
|
|
1677
|
-
return;
|
|
1678
|
-
const o = this.canvas.transformation.getViewportMatrix(), i = {
|
|
1679
|
-
scale: o.scale * e,
|
|
1680
|
-
dx: o.scale * (1 - e) * t + o.dx,
|
|
1681
|
-
dy: o.scale * (1 - e) * s + o.dy
|
|
1682
|
-
}, { width: h, height: a } = this.element.getBoundingClientRect(), d = this.transformPreprocessor(
|
|
1683
|
-
o,
|
|
1684
|
-
i,
|
|
1685
|
-
h,
|
|
1686
|
-
a
|
|
1687
|
-
);
|
|
1688
|
-
this.canvas.patchViewportMatrix(d), this.onTransformFinished();
|
|
1683
|
+
moveViewport(t, o, r) {
|
|
1684
|
+
this.options.onBeforeTransformStarted();
|
|
1685
|
+
const i = this.transformation.getViewportMatrix(), n = Ct(i, o, r), { width: d, height: c } = t.getBoundingClientRect(), h = this.options.transformPreprocessor({
|
|
1686
|
+
prevTransform: i,
|
|
1687
|
+
nextTransform: n,
|
|
1688
|
+
canvasWidth: d,
|
|
1689
|
+
canvasHeight: c
|
|
1690
|
+
});
|
|
1691
|
+
this.canvas.patchViewportMatrix(h), this.options.onTransformFinished();
|
|
1692
|
+
}
|
|
1693
|
+
scaleViewport(t, o, r, i) {
|
|
1694
|
+
this.options.onBeforeTransformStarted();
|
|
1695
|
+
const n = this.canvas.transformation.getViewportMatrix(), d = Nt(n, o, r, i), { width: c, height: h } = t.getBoundingClientRect(), l = this.options.transformPreprocessor({
|
|
1696
|
+
prevTransform: n,
|
|
1697
|
+
nextTransform: d,
|
|
1698
|
+
canvasWidth: c,
|
|
1699
|
+
canvasHeight: h
|
|
1700
|
+
});
|
|
1701
|
+
this.canvas.patchViewportMatrix(l), this.options.onTransformFinished();
|
|
1689
1702
|
}
|
|
1690
1703
|
stopMouseDrag() {
|
|
1691
|
-
this.element !== null &&
|
|
1704
|
+
this.element !== null && D(this.element, null), this.removeMouseDragListeners();
|
|
1692
1705
|
}
|
|
1693
1706
|
removeMouseDragListeners() {
|
|
1694
|
-
this.window.removeEventListener("mousemove", this.
|
|
1707
|
+
this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
|
|
1695
1708
|
}
|
|
1696
1709
|
stopTouchDrag() {
|
|
1697
1710
|
this.prevTouches = null, this.removeTouchDragListeners();
|
|
1698
1711
|
}
|
|
1699
1712
|
removeTouchDragListeners() {
|
|
1700
|
-
this.window.removeEventListener("touchmove", this.
|
|
1713
|
+
this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
|
|
1701
1714
|
}
|
|
1702
1715
|
}
|
|
1703
|
-
class
|
|
1716
|
+
class Lt {
|
|
1704
1717
|
constructor() {
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1718
|
+
s(this, "keyMap", /* @__PURE__ */ new Map());
|
|
1719
|
+
s(this, "valueMap", /* @__PURE__ */ new Map());
|
|
1720
|
+
}
|
|
1721
|
+
set(t, o) {
|
|
1722
|
+
this.keyMap.set(t, o), this.valueMap.set(o, t);
|
|
1723
|
+
}
|
|
1724
|
+
hasKey(t) {
|
|
1725
|
+
return this.keyMap.has(t);
|
|
1726
|
+
}
|
|
1727
|
+
hasValue(t) {
|
|
1728
|
+
return this.valueMap.has(t);
|
|
1729
|
+
}
|
|
1730
|
+
getByKey(t) {
|
|
1731
|
+
return this.keyMap.get(t);
|
|
1732
|
+
}
|
|
1733
|
+
getByValue(t) {
|
|
1734
|
+
return this.valueMap.get(t);
|
|
1735
|
+
}
|
|
1736
|
+
deleteByKey(t) {
|
|
1737
|
+
const o = this.keyMap.get(t);
|
|
1738
|
+
o !== void 0 && this.valueMap.delete(o), this.keyMap.delete(t);
|
|
1739
|
+
}
|
|
1740
|
+
deleteByValue(t) {
|
|
1741
|
+
const o = this.valueMap.get(t);
|
|
1742
|
+
o !== void 0 && this.keyMap.delete(o), this.valueMap.delete(t);
|
|
1743
|
+
}
|
|
1744
|
+
forEach(t) {
|
|
1745
|
+
this.keyMap.forEach((o, r) => {
|
|
1746
|
+
t(o, r);
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
clear() {
|
|
1750
|
+
this.keyMap.clear(), this.valueMap.clear();
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
class Dt {
|
|
1754
|
+
constructor(t) {
|
|
1755
|
+
s(this, "transformation");
|
|
1756
|
+
s(this, "model");
|
|
1757
|
+
s(this, "nodes", new Lt());
|
|
1758
|
+
s(this, "nodeIdGenerator", new C(
|
|
1759
|
+
(t) => this.nodes.hasKey(t)
|
|
1760
|
+
));
|
|
1761
|
+
s(this, "nodesResizeObserver");
|
|
1762
|
+
this.canvas = t, this.nodesResizeObserver = new window.ResizeObserver((o) => {
|
|
1763
|
+
o.forEach((r) => {
|
|
1764
|
+
const i = r.target;
|
|
1765
|
+
this.reactNodeChange(i);
|
|
1766
|
+
});
|
|
1767
|
+
}), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
|
|
1768
|
+
}
|
|
1769
|
+
attach(t) {
|
|
1770
|
+
return this.canvas.attach(t), this;
|
|
1771
|
+
}
|
|
1772
|
+
detach() {
|
|
1773
|
+
return this.canvas.detach(), this;
|
|
1774
|
+
}
|
|
1775
|
+
addNode(t) {
|
|
1776
|
+
const o = this.nodeIdGenerator.create(t.id);
|
|
1777
|
+
return this.canvas.addNode({
|
|
1778
|
+
...t,
|
|
1779
|
+
id: o
|
|
1780
|
+
}), this.nodes.set(o, t.element), this.nodesResizeObserver.observe(t.element), this;
|
|
1781
|
+
}
|
|
1782
|
+
updateNode(t, o) {
|
|
1783
|
+
return this.canvas.updateNode(t, o), this;
|
|
1784
|
+
}
|
|
1785
|
+
removeNode(t) {
|
|
1786
|
+
this.canvas.removeNode(t);
|
|
1787
|
+
const o = this.nodes.getByKey(t);
|
|
1788
|
+
return this.nodes.deleteByKey(t), this.nodesResizeObserver.unobserve(o), this;
|
|
1789
|
+
}
|
|
1790
|
+
markPort(t) {
|
|
1791
|
+
return this.canvas.markPort(t), this;
|
|
1792
|
+
}
|
|
1793
|
+
updatePort(t, o) {
|
|
1794
|
+
return this.canvas.updatePort(t, o), this;
|
|
1795
|
+
}
|
|
1796
|
+
unmarkPort(t) {
|
|
1797
|
+
return this.canvas.unmarkPort(t), this;
|
|
1798
|
+
}
|
|
1799
|
+
addEdge(t) {
|
|
1800
|
+
return this.canvas.addEdge(t), this;
|
|
1801
|
+
}
|
|
1802
|
+
updateEdge(t, o) {
|
|
1803
|
+
return this.canvas.updateEdge(t, o), this;
|
|
1804
|
+
}
|
|
1805
|
+
removeEdge(t) {
|
|
1806
|
+
return this.canvas.removeEdge(t), this;
|
|
1807
|
+
}
|
|
1808
|
+
patchViewportMatrix(t) {
|
|
1809
|
+
return this.canvas.patchViewportMatrix(t), this;
|
|
1810
|
+
}
|
|
1811
|
+
patchContentMatrix(t) {
|
|
1812
|
+
return this.canvas.patchContentMatrix(t), this;
|
|
1813
|
+
}
|
|
1814
|
+
clear() {
|
|
1815
|
+
return this.canvas.clear(), this.nodesResizeObserver.disconnect(), this.nodes.clear(), this;
|
|
1816
|
+
}
|
|
1817
|
+
destroy() {
|
|
1818
|
+
this.clear(), this.canvas.destroy();
|
|
1819
|
+
}
|
|
1820
|
+
reactNodeChange(t) {
|
|
1821
|
+
const o = this.nodes.getByValue(t);
|
|
1822
|
+
this.canvas.updateNode(o), this.model.getNodeAdjacentEdgeIds(o).forEach((i) => {
|
|
1823
|
+
this.canvas.updateEdge(i);
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
class mt {
|
|
1828
|
+
constructor() {
|
|
1829
|
+
s(this, "coreOptions");
|
|
1830
|
+
s(this, "dragOptions");
|
|
1831
|
+
s(this, "transformOptions");
|
|
1832
|
+
s(this, "isDraggable", !1);
|
|
1833
|
+
s(this, "isTransformable", !1);
|
|
1834
|
+
s(this, "hasResizeReactiveNodes", !1);
|
|
1835
|
+
}
|
|
1836
|
+
setOptions(t) {
|
|
1837
|
+
return this.coreOptions = t, this;
|
|
1710
1838
|
}
|
|
1711
|
-
|
|
1712
|
-
return this.
|
|
1839
|
+
setUserDraggableNodes(t) {
|
|
1840
|
+
return this.isDraggable = !0, this.dragOptions = t, this;
|
|
1713
1841
|
}
|
|
1714
|
-
|
|
1715
|
-
return this.
|
|
1842
|
+
setUserTransformableCanvas(t) {
|
|
1843
|
+
return this.isTransformable = !0, this.transformOptions = t, this;
|
|
1716
1844
|
}
|
|
1717
|
-
|
|
1718
|
-
return this.
|
|
1845
|
+
setResizeReactiveNodes() {
|
|
1846
|
+
return this.hasResizeReactiveNodes = !0, this;
|
|
1719
1847
|
}
|
|
1720
1848
|
build() {
|
|
1721
|
-
let
|
|
1722
|
-
return this.isDraggable && (
|
|
1849
|
+
let t = new xt(this.coreOptions);
|
|
1850
|
+
return this.hasResizeReactiveNodes && (t = new Dt(t)), this.isDraggable && (t = new St(t, this.dragOptions)), this.isTransformable && (t = new Pt(t, this.transformOptions)), t;
|
|
1723
1851
|
}
|
|
1724
1852
|
}
|
|
1725
1853
|
export {
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
re as StraightEdgeShape,
|
|
1737
|
-
Ee as UserDraggableNodesCanvas,
|
|
1738
|
-
Ne as UserTransformableCanvas,
|
|
1739
|
-
oe as VerticalEdgeShape,
|
|
1740
|
-
ae as createBezierEdgeShapeFactory,
|
|
1741
|
-
ce as createHorizontalEdgeShapeFactory,
|
|
1742
|
-
he as createStraightEdgeShareFactory,
|
|
1743
|
-
de as createVerticalEdgeShapeFactory
|
|
1854
|
+
ot as BezierEdgeShape,
|
|
1855
|
+
xt as CanvasCore,
|
|
1856
|
+
rt as HorizontalEdgeShape,
|
|
1857
|
+
mt as HtmlGraphBuilder,
|
|
1858
|
+
S as HtmlGraphError,
|
|
1859
|
+
Dt as ResizeReactiveNodesCanvas,
|
|
1860
|
+
it as StraightEdgeShape,
|
|
1861
|
+
St as UserDraggableNodesCanvas,
|
|
1862
|
+
Pt as UserTransformableCanvas,
|
|
1863
|
+
nt as VerticalEdgeShape
|
|
1744
1864
|
};
|