@html-graph/html-graph 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.d.ts +4 -2
- package/dist/main.js +258 -242
- package/dist/main.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
var K = (e, t, o) => t in e ?
|
|
1
|
+
var O = Object.defineProperty;
|
|
2
|
+
var K = (e, t, o) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
|
|
3
3
|
var s = (e, t, o) => K(e, typeof t != "symbol" ? t + "" : t, o);
|
|
4
4
|
const _ = (e, t) => ({
|
|
5
5
|
x: e / 2,
|
|
@@ -11,27 +11,27 @@ const _ = (e, t) => ({
|
|
|
11
11
|
x: 0,
|
|
12
12
|
y: 0
|
|
13
13
|
}, E = (e, t, o, r) => {
|
|
14
|
-
const
|
|
14
|
+
const i = [
|
|
15
15
|
u,
|
|
16
16
|
{ x: o, y: r },
|
|
17
17
|
{ x: o, y: -r }
|
|
18
|
-
].map((l) => f(l, e, u)).map((l) => ({ x: l.x + t.x, y: l.y + t.y })),
|
|
19
|
-
return `${
|
|
20
|
-
},
|
|
18
|
+
].map((l) => f(l, e, u)).map((l) => ({ x: l.x + t.x, y: l.y + t.y })), c = `M ${i[0].x} ${i[0].y}`, d = `L ${i[1].x} ${i[1].y}`, h = `L ${i[2].x} ${i[2].y}`;
|
|
19
|
+
return `${c} ${d} ${h}`;
|
|
20
|
+
}, C = (e, t) => {
|
|
21
21
|
const o = [];
|
|
22
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
23
|
const r = e.length - 1;
|
|
24
|
-
let
|
|
25
|
-
e.forEach((
|
|
24
|
+
let n = 0, i = 0, c = 0;
|
|
25
|
+
e.forEach((d, h) => {
|
|
26
26
|
let l = 0, a = 0, w = 0;
|
|
27
27
|
const y = h > 0, x = h < r, v = y && x;
|
|
28
|
-
if (y && (l = -
|
|
28
|
+
if (y && (l = -n, a = -i, w = c), x) {
|
|
29
29
|
const z = e[h + 1];
|
|
30
|
-
|
|
30
|
+
n = z.x - d.x, i = z.y - d.y, c = Math.sqrt(n * n + i * i);
|
|
31
31
|
}
|
|
32
|
-
const M =
|
|
32
|
+
const M = c !== 0 ? Math.min((v ? t : 0) / c, h < r - 1 ? 0.5 : 1) : 0, X = v ? { x: d.x + n * M, y: d.y + i * M } : d, k = w !== 0 ? Math.min((v ? t : 0) / w, h > 1 ? 0.5 : 1) : 0, B = v ? { x: d.x + l * k, y: d.y + a * k } : d;
|
|
33
33
|
h > 0 && o.push(`L ${B.x} ${B.y}`), v && o.push(
|
|
34
|
-
`C ${
|
|
34
|
+
`C ${d.x} ${d.y} ${d.x} ${d.y} ${X.x} ${X.y}`
|
|
35
35
|
);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -48,19 +48,19 @@ const _ = (e, t) => ({
|
|
|
48
48
|
}, T = (e) => {
|
|
49
49
|
const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
50
50
|
return t.setAttribute("fill", e), t;
|
|
51
|
-
},
|
|
51
|
+
}, b = (e, t) => {
|
|
52
52
|
const o = {
|
|
53
53
|
x: e.x + e.width / 2,
|
|
54
54
|
y: e.y + e.height / 2
|
|
55
55
|
}, r = {
|
|
56
56
|
x: t.x + t.width / 2,
|
|
57
57
|
y: t.y + t.height / 2
|
|
58
|
-
},
|
|
58
|
+
}, n = Math.min(o.x, r.x), i = Math.min(o.y, r.y), c = Math.abs(r.x - o.x), d = Math.abs(r.y - o.y), h = o.x <= r.x ? 1 : -1, l = o.y <= r.y ? 1 : -1;
|
|
59
59
|
return {
|
|
60
|
-
x:
|
|
61
|
-
y:
|
|
62
|
-
width:
|
|
63
|
-
height:
|
|
60
|
+
x: n,
|
|
61
|
+
y: i,
|
|
62
|
+
width: c,
|
|
63
|
+
height: d,
|
|
64
64
|
flipX: h,
|
|
65
65
|
flipY: l
|
|
66
66
|
};
|
|
@@ -76,11 +76,11 @@ const _ = (e, t) => ({
|
|
|
76
76
|
), r = {
|
|
77
77
|
x: t.x + e.fromVect.x * e.curvature,
|
|
78
78
|
y: t.y + e.fromVect.y * e.curvature
|
|
79
|
-
},
|
|
79
|
+
}, n = {
|
|
80
80
|
x: o.x - e.toVect.x * e.curvature,
|
|
81
81
|
y: o.y - e.toVect.y * e.curvature
|
|
82
|
-
},
|
|
83
|
-
return `${
|
|
82
|
+
}, i = `M ${t.x} ${t.y} C ${r.x} ${r.y}, ${n.x} ${n.y}, ${o.x} ${o.y}`, c = e.hasSourceArrow ? "" : `M ${u.x} ${u.y} L ${t.x} ${t.y} `, d = e.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${e.to.x} ${e.to.y}`;
|
|
83
|
+
return `${c}${i}${d}`;
|
|
84
84
|
}, Q = (e) => {
|
|
85
85
|
const t = e.hasSourceArrow ? f(
|
|
86
86
|
{ x: e.arrowLength, y: u.y },
|
|
@@ -90,37 +90,37 @@ const _ = (e, t) => ({
|
|
|
90
90
|
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
91
91
|
e.toVect,
|
|
92
92
|
e.to
|
|
93
|
-
) : e.to, r = e.arrowLength,
|
|
93
|
+
) : e.to, r = e.arrowLength, n = Math.cos(e.detourDirection) * e.detourDistance, i = Math.sin(e.detourDirection) * e.detourDistance, c = n * e.flipX, d = i * e.flipY, h = f(
|
|
94
94
|
{ x: r, y: u.y },
|
|
95
95
|
e.fromVect,
|
|
96
96
|
u
|
|
97
97
|
), l = {
|
|
98
|
-
x: h.x +
|
|
99
|
-
y: h.y +
|
|
98
|
+
x: h.x + c,
|
|
99
|
+
y: h.y + d
|
|
100
100
|
}, a = f(
|
|
101
101
|
{ x: e.to.x - r, y: e.to.y },
|
|
102
102
|
e.toVect,
|
|
103
103
|
e.to
|
|
104
104
|
), w = {
|
|
105
|
-
x: a.x +
|
|
106
|
-
y: a.y +
|
|
105
|
+
x: a.x + c,
|
|
106
|
+
y: a.y + d
|
|
107
107
|
}, y = { x: (l.x + w.x) / 2, y: (l.y + w.y) / 2 }, x = {
|
|
108
108
|
x: h.x + e.curvature * e.fromVect.x,
|
|
109
109
|
y: h.y + e.curvature * e.fromVect.y
|
|
110
110
|
}, v = {
|
|
111
111
|
x: a.x - e.curvature * e.toVect.x,
|
|
112
112
|
y: a.y - e.curvature * e.toVect.y
|
|
113
|
-
},
|
|
114
|
-
x: h.x +
|
|
115
|
-
y: h.y +
|
|
113
|
+
}, p = {
|
|
114
|
+
x: h.x + c,
|
|
115
|
+
y: h.y + d
|
|
116
116
|
}, M = {
|
|
117
|
-
x: a.x +
|
|
118
|
-
y: a.y +
|
|
117
|
+
x: a.x + c,
|
|
118
|
+
y: a.y + d
|
|
119
119
|
};
|
|
120
120
|
return [
|
|
121
121
|
`M ${t.x} ${t.y}`,
|
|
122
122
|
`L ${h.x} ${h.y}`,
|
|
123
|
-
`C ${x.x} ${x.y} ${
|
|
123
|
+
`C ${x.x} ${x.y} ${p.x} ${p.y} ${y.x} ${y.y}`,
|
|
124
124
|
`C ${M.x} ${M.y} ${v.x} ${v.y} ${a.x} ${a.y}`,
|
|
125
125
|
`L ${o.x} ${o.y}`
|
|
126
126
|
].join(" ");
|
|
@@ -133,16 +133,16 @@ const _ = (e, t) => ({
|
|
|
133
133
|
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
134
134
|
e.toVect,
|
|
135
135
|
e.to
|
|
136
|
-
) : e.to, r = e.arrowLength + e.arrowOffset,
|
|
137
|
-
{ x: e.to.x -
|
|
136
|
+
) : e.to, r = e.arrowLength + e.arrowOffset, n = r - e.roundness, i = f({ x: n, y: u.y }, e.fromVect, u), c = f(
|
|
137
|
+
{ x: e.to.x - n, y: e.to.y },
|
|
138
138
|
e.toVect,
|
|
139
139
|
e.to
|
|
140
|
-
),
|
|
141
|
-
x: e.flipX > 0 ? e.to.x -
|
|
142
|
-
y:
|
|
140
|
+
), d = Math.max((i.x + c.x) / 2, r), h = e.to.y / 2, l = { x: e.flipX > 0 ? d : -r, y: i.y }, a = { x: l.x, y: h }, w = {
|
|
141
|
+
x: e.flipX > 0 ? e.to.x - d : e.to.x + r,
|
|
142
|
+
y: c.y
|
|
143
143
|
}, y = { x: w.x, y: h };
|
|
144
|
-
return
|
|
145
|
-
[t,
|
|
144
|
+
return C(
|
|
145
|
+
[t, i, l, a, y, w, c, o],
|
|
146
146
|
e.roundness
|
|
147
147
|
);
|
|
148
148
|
}, R = (e) => {
|
|
@@ -154,17 +154,17 @@ const _ = (e, t) => ({
|
|
|
154
154
|
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
155
155
|
e.toVect,
|
|
156
156
|
e.to
|
|
157
|
-
) : e.to, r = e.arrowLength + e.arrowOffset,
|
|
157
|
+
) : e.to, r = e.arrowLength + e.arrowOffset, n = f(
|
|
158
158
|
{ x: r, y: u.y },
|
|
159
159
|
e.fromVect,
|
|
160
160
|
u
|
|
161
|
-
),
|
|
161
|
+
), i = Math.cos(e.detourDirection) * e.detourDistance, c = Math.sin(e.detourDirection) * e.detourDistance, d = i * e.flipX, h = c * e.flipY, l = { x: n.x + d, y: n.y + h }, a = f(
|
|
162
162
|
{ x: e.to.x - r, y: e.to.y },
|
|
163
163
|
e.toVect,
|
|
164
164
|
e.to
|
|
165
|
-
), w = { x: a.x +
|
|
166
|
-
return
|
|
167
|
-
[t,
|
|
165
|
+
), w = { x: a.x + d, y: a.y + h };
|
|
166
|
+
return C(
|
|
167
|
+
[t, n, l, w, a, o],
|
|
168
168
|
e.roundness
|
|
169
169
|
);
|
|
170
170
|
}, q = (e) => {
|
|
@@ -176,12 +176,12 @@ const _ = (e, t) => ({
|
|
|
176
176
|
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
177
177
|
e.toVect,
|
|
178
178
|
e.to
|
|
179
|
-
) : e.to, r = e.arrowLength + e.arrowOffset,
|
|
179
|
+
) : e.to, r = e.arrowLength + e.arrowOffset, n = f({ x: r, y: u.y }, e.fromVect, u), i = f(
|
|
180
180
|
{ x: e.to.x - r, y: e.to.y },
|
|
181
181
|
e.toVect,
|
|
182
182
|
e.to
|
|
183
183
|
);
|
|
184
|
-
return
|
|
184
|
+
return C([t, n, i, o], e.roundness);
|
|
185
185
|
}, tt = (e) => {
|
|
186
186
|
const t = e.hasSourceArrow ? f(
|
|
187
187
|
{ x: e.arrowLength, y: u.y },
|
|
@@ -191,37 +191,37 @@ const _ = (e, t) => ({
|
|
|
191
191
|
{ x: e.to.x - e.arrowLength, y: e.to.y },
|
|
192
192
|
e.toVect,
|
|
193
193
|
e.to
|
|
194
|
-
) : e.to, r = e.arrowLength + e.arrowOffset,
|
|
195
|
-
{ x: e.to.x -
|
|
194
|
+
) : e.to, r = e.arrowLength + e.arrowOffset, n = r - e.roundness, i = f({ x: n, y: u.y }, e.fromVect, u), c = f(
|
|
195
|
+
{ x: e.to.x - n, y: e.to.y },
|
|
196
196
|
e.toVect,
|
|
197
197
|
e.to
|
|
198
|
-
),
|
|
199
|
-
x:
|
|
200
|
-
y: e.flipY > 0 ? e.to.y -
|
|
198
|
+
), d = Math.max((i.y + c.y) / 2, r), h = e.to.x / 2, l = { x: i.x, y: e.flipY > 0 ? d : -r }, a = { x: h, y: l.y }, w = {
|
|
199
|
+
x: c.x,
|
|
200
|
+
y: e.flipY > 0 ? e.to.y - d : e.to.y + r
|
|
201
201
|
}, y = { x: h, y: w.y };
|
|
202
|
-
return
|
|
203
|
-
[t,
|
|
202
|
+
return C(
|
|
203
|
+
[t, i, l, a, y, w, c, o],
|
|
204
204
|
e.roundness
|
|
205
205
|
);
|
|
206
206
|
}, Y = (e) => {
|
|
207
|
-
const t = e.arrowOffset, o = e.side, r = e.arrowLength + t,
|
|
207
|
+
const t = e.arrowOffset, o = e.side, r = e.arrowLength + t, n = r + 2 * o, c = [
|
|
208
208
|
{ x: e.arrowLength, y: u.y },
|
|
209
209
|
{ x: r, y: u.y },
|
|
210
210
|
{ x: r, y: e.side },
|
|
211
|
-
{ x:
|
|
212
|
-
{ x:
|
|
211
|
+
{ x: n, y: e.side },
|
|
212
|
+
{ x: n, y: -e.side },
|
|
213
213
|
{ x: r, y: -e.side },
|
|
214
214
|
{ x: r, y: u.y },
|
|
215
215
|
{ x: e.arrowLength, y: u.y }
|
|
216
216
|
].map(
|
|
217
217
|
(h) => f(h, e.fromVect, u)
|
|
218
|
-
),
|
|
219
|
-
return `${e.hasSourceArrow || e.hasTargetArrow ? "" :
|
|
218
|
+
), d = `M ${u.x} ${u.y} L ${c[0].x} ${c[0].y} `;
|
|
219
|
+
return `${e.hasSourceArrow || e.hasTargetArrow ? "" : d}${C(c, e.roundness)}`;
|
|
220
220
|
}, et = (e) => {
|
|
221
|
-
const t = e.smallRadius, o = e.radius, r = Math.sqrt(t * t + o * o),
|
|
221
|
+
const t = e.smallRadius, o = e.radius, r = Math.sqrt(t * t + o * o), n = t + o, i = e.arrowLength + r * (1 - o / n), c = t * o / n, h = [
|
|
222
222
|
{ x: e.arrowLength, y: u.y },
|
|
223
|
-
{ x:
|
|
224
|
-
{ x:
|
|
223
|
+
{ x: i, y: c },
|
|
224
|
+
{ x: i, y: -c }
|
|
225
225
|
].map((w) => f(w, e.fromVect, u)), l = [
|
|
226
226
|
`M ${h[0].x} ${h[0].y}`,
|
|
227
227
|
`A ${t} ${t} 0 0 1 ${h[1].x} ${h[1].y}`,
|
|
@@ -242,6 +242,7 @@ const _ = (e, t) => ({
|
|
|
242
242
|
roundness: 10,
|
|
243
243
|
detourDistance: 100,
|
|
244
244
|
detourDirection: -Math.PI / 2,
|
|
245
|
+
detourDirectionVertical: 0,
|
|
245
246
|
smallCycleRadius: 15,
|
|
246
247
|
curvature: 90
|
|
247
248
|
});
|
|
@@ -266,22 +267,22 @@ class ot {
|
|
|
266
267
|
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
|
}
|
|
268
269
|
render(t) {
|
|
269
|
-
const { x: o, y: r, width:
|
|
270
|
+
const { x: o, y: r, width: n, height: i, flipX: c, flipY: d } = b(
|
|
270
271
|
t.source,
|
|
271
272
|
t.target
|
|
272
273
|
);
|
|
273
|
-
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${
|
|
274
|
+
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${i}px`, this.group.style.transform = `scale(${c}, ${d})`;
|
|
274
275
|
const h = A(
|
|
275
276
|
t.source.direction,
|
|
276
|
-
|
|
277
|
-
|
|
277
|
+
c,
|
|
278
|
+
d
|
|
278
279
|
), l = A(
|
|
279
280
|
t.target.direction,
|
|
280
|
-
|
|
281
|
-
|
|
281
|
+
c,
|
|
282
|
+
d
|
|
282
283
|
), a = {
|
|
283
|
-
x:
|
|
284
|
-
y:
|
|
284
|
+
x: n,
|
|
285
|
+
y: i
|
|
285
286
|
};
|
|
286
287
|
let w, y = l, x = -this.arrowLength;
|
|
287
288
|
if (t.source.portId === t.target.portId ? (w = et({
|
|
@@ -295,8 +296,8 @@ class ot {
|
|
|
295
296
|
to: a,
|
|
296
297
|
fromVect: h,
|
|
297
298
|
toVect: l,
|
|
298
|
-
flipX:
|
|
299
|
-
flipY:
|
|
299
|
+
flipX: c,
|
|
300
|
+
flipY: d,
|
|
300
301
|
arrowLength: this.arrowLength,
|
|
301
302
|
detourDirection: this.detourDirection,
|
|
302
303
|
detourDistance: this.detourDistance,
|
|
@@ -354,26 +355,26 @@ class rt {
|
|
|
354
355
|
this.arrowOffset,
|
|
355
356
|
this.cycleSquareSide / 2
|
|
356
357
|
), 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,
|
|
358
|
-
this.svg.appendChild(this.group), this.line = m(r,
|
|
358
|
+
const r = (t == null ? void 0 : t.color) ?? g.color, n = (t == null ? void 0 : t.width) ?? g.width;
|
|
359
|
+
this.svg.appendChild(this.group), this.line = m(r, n), 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
|
}
|
|
360
361
|
render(t) {
|
|
361
|
-
const { x: o, y: r, width:
|
|
362
|
+
const { x: o, y: r, width: n, height: i, flipX: c, flipY: d } = b(
|
|
362
363
|
t.source,
|
|
363
364
|
t.target
|
|
364
365
|
);
|
|
365
|
-
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${
|
|
366
|
+
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${i}px`, this.group.style.transform = `scale(${c}, ${d})`;
|
|
366
367
|
const h = A(
|
|
367
368
|
t.source.direction,
|
|
368
|
-
|
|
369
|
-
|
|
369
|
+
c,
|
|
370
|
+
d
|
|
370
371
|
), l = A(
|
|
371
372
|
t.target.direction,
|
|
372
|
-
|
|
373
|
-
|
|
373
|
+
c,
|
|
374
|
+
d
|
|
374
375
|
), a = {
|
|
375
|
-
x:
|
|
376
|
-
y:
|
|
376
|
+
x: n,
|
|
377
|
+
y: i
|
|
377
378
|
};
|
|
378
379
|
let w, y = l, x = -this.arrowLength;
|
|
379
380
|
if (t.source.portId === t.target.portId ? (w = Y({
|
|
@@ -388,8 +389,8 @@ class rt {
|
|
|
388
389
|
to: a,
|
|
389
390
|
fromVect: h,
|
|
390
391
|
toVect: l,
|
|
391
|
-
flipX:
|
|
392
|
-
flipY:
|
|
392
|
+
flipX: c,
|
|
393
|
+
flipY: d,
|
|
393
394
|
arrowLength: this.arrowLength,
|
|
394
395
|
arrowOffset: this.arrowOffset,
|
|
395
396
|
roundness: this.roundness,
|
|
@@ -401,7 +402,7 @@ class rt {
|
|
|
401
402
|
to: a,
|
|
402
403
|
fromVect: h,
|
|
403
404
|
toVect: l,
|
|
404
|
-
flipX:
|
|
405
|
+
flipX: c,
|
|
405
406
|
arrowLength: this.arrowLength,
|
|
406
407
|
arrowOffset: this.arrowOffset,
|
|
407
408
|
roundness: this.roundness,
|
|
@@ -450,26 +451,26 @@ class it {
|
|
|
450
451
|
this.arrowOffset,
|
|
451
452
|
this.cycleSquareSide / 2
|
|
452
453
|
), 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,
|
|
454
|
-
this.svg.appendChild(this.group), this.line = m(r,
|
|
454
|
+
const r = (t == null ? void 0 : t.color) ?? g.color, n = (t == null ? void 0 : t.width) ?? g.width;
|
|
455
|
+
this.svg.appendChild(this.group), this.line = m(r, n), 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
|
}
|
|
456
457
|
render(t) {
|
|
457
|
-
const { x: o, y: r, width:
|
|
458
|
+
const { x: o, y: r, width: n, height: i, flipX: c, flipY: d } = b(
|
|
458
459
|
t.source,
|
|
459
460
|
t.target
|
|
460
461
|
);
|
|
461
|
-
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${
|
|
462
|
+
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${i}px`, this.group.style.transform = `scale(${c}, ${d})`;
|
|
462
463
|
const h = A(
|
|
463
464
|
t.source.direction,
|
|
464
|
-
|
|
465
|
-
|
|
465
|
+
c,
|
|
466
|
+
d
|
|
466
467
|
), l = A(
|
|
467
468
|
t.target.direction,
|
|
468
|
-
|
|
469
|
-
|
|
469
|
+
c,
|
|
470
|
+
d
|
|
470
471
|
), a = {
|
|
471
|
-
x:
|
|
472
|
-
y:
|
|
472
|
+
x: n,
|
|
473
|
+
y: i
|
|
473
474
|
};
|
|
474
475
|
let w, y = l, x = -this.arrowLength;
|
|
475
476
|
if (t.source.portId === t.target.portId ? (w = Y({
|
|
@@ -484,8 +485,8 @@ class it {
|
|
|
484
485
|
to: a,
|
|
485
486
|
fromVect: h,
|
|
486
487
|
toVect: l,
|
|
487
|
-
flipX:
|
|
488
|
-
flipY:
|
|
488
|
+
flipX: c,
|
|
489
|
+
flipY: d,
|
|
489
490
|
arrowLength: this.arrowLength,
|
|
490
491
|
arrowOffset: this.arrowOffset,
|
|
491
492
|
roundness: this.roundness,
|
|
@@ -544,27 +545,27 @@ class nt {
|
|
|
544
545
|
o,
|
|
545
546
|
this.arrowOffset,
|
|
546
547
|
this.cycleSquareSide / 2
|
|
547
|
-
), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? g.
|
|
548
|
-
const r = (t == null ? void 0 : t.color) ?? g.color,
|
|
549
|
-
this.svg.appendChild(this.group), this.line = m(r,
|
|
548
|
+
), this.detourDirection = (t == null ? void 0 : t.detourDirection) ?? g.detourDirectionVertical, 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;
|
|
549
|
+
const r = (t == null ? void 0 : t.color) ?? g.color, n = (t == null ? void 0 : t.width) ?? g.width;
|
|
550
|
+
this.svg.appendChild(this.group), this.line = m(r, n), 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
|
}
|
|
551
552
|
render(t) {
|
|
552
|
-
const { x: o, y: r, width:
|
|
553
|
+
const { x: o, y: r, width: n, height: i, flipX: c, flipY: d } = b(
|
|
553
554
|
t.source,
|
|
554
555
|
t.target
|
|
555
556
|
);
|
|
556
|
-
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${
|
|
557
|
+
this.svg.style.transform = `translate(${o}px, ${r}px)`, this.svg.style.width = `${n}px`, this.svg.style.height = `${i}px`, this.group.style.transform = `scale(${c}, ${d})`;
|
|
557
558
|
const h = A(
|
|
558
559
|
t.source.direction,
|
|
559
|
-
|
|
560
|
-
|
|
560
|
+
c,
|
|
561
|
+
d
|
|
561
562
|
), l = A(
|
|
562
563
|
t.target.direction,
|
|
563
|
-
|
|
564
|
-
|
|
564
|
+
c,
|
|
565
|
+
d
|
|
565
566
|
), a = {
|
|
566
|
-
x:
|
|
567
|
-
y:
|
|
567
|
+
x: n,
|
|
568
|
+
y: i
|
|
568
569
|
};
|
|
569
570
|
let w, y = l, x = -this.arrowLength;
|
|
570
571
|
if (t.source.portId === t.target.portId ? (w = Y({
|
|
@@ -579,8 +580,8 @@ class nt {
|
|
|
579
580
|
to: a,
|
|
580
581
|
fromVect: h,
|
|
581
582
|
toVect: l,
|
|
582
|
-
flipX:
|
|
583
|
-
flipY:
|
|
583
|
+
flipX: c,
|
|
584
|
+
flipY: d,
|
|
584
585
|
arrowLength: this.arrowLength,
|
|
585
586
|
arrowOffset: this.arrowOffset,
|
|
586
587
|
roundness: this.roundness,
|
|
@@ -592,7 +593,7 @@ class nt {
|
|
|
592
593
|
to: a,
|
|
593
594
|
fromVect: h,
|
|
594
595
|
toVect: l,
|
|
595
|
-
flipY:
|
|
596
|
+
flipY: d,
|
|
596
597
|
arrowLength: this.arrowLength,
|
|
597
598
|
arrowOffset: this.arrowOffset,
|
|
598
599
|
roundness: this.roundness,
|
|
@@ -685,32 +686,32 @@ const st = (e) => {
|
|
|
685
686
|
}, ht = (e, t) => {
|
|
686
687
|
let o = G, r = G;
|
|
687
688
|
e === "incremental" && (o = V()), t === "incremental" && (r = V());
|
|
688
|
-
const
|
|
689
|
-
return e === "shared-incremental" && (o =
|
|
689
|
+
const n = V();
|
|
690
|
+
return e === "shared-incremental" && (o = n), t === "shared-incremental" && (r = n), typeof e == "number" && (o = F(e)), typeof t == "number" && (r = F(t)), typeof e == "function" && (o = e), typeof t == "function" && (r = t), {
|
|
690
691
|
nodesPriorityFn: o,
|
|
691
692
|
edgesPriorityFn: r
|
|
692
693
|
};
|
|
693
|
-
},
|
|
694
|
-
var o, r,
|
|
694
|
+
}, dt = (e) => {
|
|
695
|
+
var o, r, n, i, c;
|
|
695
696
|
const t = ht(
|
|
696
697
|
(o = e == null ? void 0 : e.nodes) == null ? void 0 : o.priority,
|
|
697
698
|
(r = e == null ? void 0 : e.edges) == null ? void 0 : r.priority
|
|
698
699
|
);
|
|
699
700
|
return {
|
|
700
701
|
nodes: {
|
|
701
|
-
centerFn: ((
|
|
702
|
+
centerFn: ((n = e == null ? void 0 : e.nodes) == null ? void 0 : n.centerFn) ?? _,
|
|
702
703
|
priorityFn: t.nodesPriorityFn
|
|
703
704
|
},
|
|
704
705
|
ports: {
|
|
705
|
-
direction: ((
|
|
706
|
+
direction: ((i = e == null ? void 0 : e.ports) == null ? void 0 : i.direction) ?? 0
|
|
706
707
|
},
|
|
707
708
|
edges: {
|
|
708
|
-
shapeFactory: st(((
|
|
709
|
+
shapeFactory: st(((c = e == null ? void 0 : e.edges) == null ? void 0 : c.shape) ?? {}),
|
|
709
710
|
priorityFn: t.edgesPriorityFn
|
|
710
711
|
}
|
|
711
712
|
};
|
|
712
713
|
};
|
|
713
|
-
class
|
|
714
|
+
class ct {
|
|
714
715
|
constructor() {
|
|
715
716
|
s(this, "nodes", /* @__PURE__ */ new Map());
|
|
716
717
|
s(this, "ports", /* @__PURE__ */ new Map());
|
|
@@ -798,8 +799,8 @@ class dt {
|
|
|
798
799
|
return this.edges.get(t);
|
|
799
800
|
}
|
|
800
801
|
removeEdge(t) {
|
|
801
|
-
const o = this.edges.get(t), r = o.from,
|
|
802
|
-
this.cycleEdges.get(r).delete(t), this.cycleEdges.get(
|
|
802
|
+
const o = this.edges.get(t), r = o.from, n = o.to;
|
|
803
|
+
this.cycleEdges.get(r).delete(t), this.cycleEdges.get(n).delete(t), this.incommingEdges.get(r).delete(t), this.incommingEdges.get(n).delete(t), this.outcommingEdges.get(r).delete(t), this.outcommingEdges.get(n).delete(t), this.edges.delete(t);
|
|
803
804
|
}
|
|
804
805
|
clear() {
|
|
805
806
|
this.nodes.clear(), this.ports.clear(), this.nodePorts.clear(), this.portNodeId.clear(), this.edges.clear(), this.incommingEdges.clear(), this.outcommingEdges.clear(), this.cycleEdges.clear();
|
|
@@ -823,22 +824,22 @@ class dt {
|
|
|
823
824
|
getNodeIncomingEdgeIds(t) {
|
|
824
825
|
const o = Array.from(this.nodePorts.get(t).keys());
|
|
825
826
|
let r = [];
|
|
826
|
-
return o.forEach((
|
|
827
|
-
r = [...r, ...this.getPortIncomingEdgeIds(
|
|
827
|
+
return o.forEach((n) => {
|
|
828
|
+
r = [...r, ...this.getPortIncomingEdgeIds(n)];
|
|
828
829
|
}), r;
|
|
829
830
|
}
|
|
830
831
|
getNodeOutcomingEdgeIds(t) {
|
|
831
832
|
const o = Array.from(this.nodePorts.get(t).keys());
|
|
832
833
|
let r = [];
|
|
833
|
-
return o.forEach((
|
|
834
|
-
r = [...r, ...this.getPortOutcomingEdgeIds(
|
|
834
|
+
return o.forEach((n) => {
|
|
835
|
+
r = [...r, ...this.getPortOutcomingEdgeIds(n)];
|
|
835
836
|
}), r;
|
|
836
837
|
}
|
|
837
838
|
getNodeCycleEdgeIds(t) {
|
|
838
839
|
const o = Array.from(this.nodePorts.get(t).keys());
|
|
839
840
|
let r = [];
|
|
840
|
-
return o.forEach((
|
|
841
|
-
r = [...r, ...this.getPortCycleEdgeIds(
|
|
841
|
+
return o.forEach((n) => {
|
|
842
|
+
r = [...r, ...this.getPortCycleEdgeIds(n)];
|
|
842
843
|
}), r;
|
|
843
844
|
}
|
|
844
845
|
getNodeAdjacentEdgeIds(t) {
|
|
@@ -1016,7 +1017,7 @@ class ft {
|
|
|
1016
1017
|
this.clear(), this.detach(), this.host.removeChild(this.container);
|
|
1017
1018
|
}
|
|
1018
1019
|
updateNodeCoordinates(t) {
|
|
1019
|
-
const o = this.nodeIdToWrapperElementMap.get(t), r = this.graphStore.getNode(t), { width:
|
|
1020
|
+
const o = this.nodeIdToWrapperElementMap.get(t), r = this.graphStore.getNode(t), { width: n, height: i } = r.element.getBoundingClientRect(), c = this.viewportTransformer.getViewportMatrix().scale, d = r.centerFn(n, i), h = r.x - c * d.x, l = r.y - c * d.y;
|
|
1020
1021
|
o.style.transform = `translate(${h}px, ${l}px)`;
|
|
1021
1022
|
}
|
|
1022
1023
|
updateNodePriority(t) {
|
|
@@ -1030,26 +1031,26 @@ class ft {
|
|
|
1030
1031
|
this.edgeIdToElementMap.set(t, r.shape.svg), this.container.appendChild(r.shape.svg);
|
|
1031
1032
|
}
|
|
1032
1033
|
renderEdge(t) {
|
|
1033
|
-
const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from),
|
|
1034
|
-
x: h.scale * (
|
|
1035
|
-
y: h.scale * (
|
|
1034
|
+
const o = this.graphStore.getEdge(t), r = this.graphStore.getPort(o.from), n = this.graphStore.getPort(o.to), i = r.element.getBoundingClientRect(), c = n.element.getBoundingClientRect(), d = this.host.getBoundingClientRect(), h = this.viewportTransformer.getViewportMatrix(), l = {
|
|
1035
|
+
x: h.scale * (i.left - d.left) + h.dx,
|
|
1036
|
+
y: h.scale * (i.top - d.top) + h.dy
|
|
1036
1037
|
}, a = {
|
|
1037
|
-
x: h.scale * (
|
|
1038
|
-
y: h.scale * (
|
|
1038
|
+
x: h.scale * (c.left - d.left) + h.dx,
|
|
1039
|
+
y: h.scale * (c.top - d.top) + h.dy
|
|
1039
1040
|
}, w = {
|
|
1040
1041
|
x: l.x,
|
|
1041
1042
|
y: l.y,
|
|
1042
|
-
width:
|
|
1043
|
-
height:
|
|
1043
|
+
width: i.width * h.scale,
|
|
1044
|
+
height: i.height * h.scale,
|
|
1044
1045
|
direction: r.direction,
|
|
1045
1046
|
portId: o.from,
|
|
1046
1047
|
nodeId: this.graphStore.getPortNodeId(o.from)
|
|
1047
1048
|
}, y = {
|
|
1048
1049
|
x: a.x,
|
|
1049
1050
|
y: a.y,
|
|
1050
|
-
width:
|
|
1051
|
-
height:
|
|
1052
|
-
direction:
|
|
1051
|
+
width: c.width * h.scale,
|
|
1052
|
+
height: c.height * h.scale,
|
|
1053
|
+
direction: n.direction,
|
|
1053
1054
|
portId: o.to,
|
|
1054
1055
|
nodeId: this.graphStore.getPortNodeId(o.to)
|
|
1055
1056
|
};
|
|
@@ -1063,7 +1064,7 @@ class ft {
|
|
|
1063
1064
|
o.shape.svg.style.zIndex = `${o.priority}`;
|
|
1064
1065
|
}
|
|
1065
1066
|
}
|
|
1066
|
-
class
|
|
1067
|
+
class N {
|
|
1067
1068
|
constructor(t) {
|
|
1068
1069
|
s(this, "counter", 0);
|
|
1069
1070
|
this.checkExists = t;
|
|
@@ -1086,17 +1087,17 @@ class S extends Error {
|
|
|
1086
1087
|
}
|
|
1087
1088
|
}
|
|
1088
1089
|
class vt {
|
|
1089
|
-
constructor(t, o, r, i,
|
|
1090
|
-
s(this, "nodeIdGenerator", new
|
|
1090
|
+
constructor(t, o, r, n, i, c, d) {
|
|
1091
|
+
s(this, "nodeIdGenerator", new N(
|
|
1091
1092
|
(t) => this.graphStore.getNode(t) !== void 0
|
|
1092
1093
|
));
|
|
1093
|
-
s(this, "portIdGenerator", new
|
|
1094
|
+
s(this, "portIdGenerator", new N(
|
|
1094
1095
|
(t) => this.graphStore.getPort(t) !== void 0
|
|
1095
1096
|
));
|
|
1096
|
-
s(this, "edgeIdGenerator", new
|
|
1097
|
+
s(this, "edgeIdGenerator", new N(
|
|
1097
1098
|
(t) => this.graphStore.getEdge(t) !== void 0
|
|
1098
1099
|
));
|
|
1099
|
-
this.graphStore = t, this.htmlController = o, this.viewportTransformer = r, this.defaultNodesCenterFn =
|
|
1100
|
+
this.graphStore = t, this.htmlController = o, this.viewportTransformer = r, this.defaultNodesCenterFn = n, this.defaultPortsDirection = i, this.defaultNodesPriorityFn = c, this.defaultEdgesPriorityFn = d;
|
|
1100
1101
|
}
|
|
1101
1102
|
attach(t) {
|
|
1102
1103
|
this.htmlController.attach(t);
|
|
@@ -1163,16 +1164,16 @@ class vt {
|
|
|
1163
1164
|
const r = this.graphStore.getPort(t);
|
|
1164
1165
|
if (r === void 0)
|
|
1165
1166
|
throw new S("failed to unset nonexisting port");
|
|
1166
|
-
r.direction = o.direction ?? r.direction, this.graphStore.getPortAdjacentEdgeIds(t).forEach((
|
|
1167
|
-
this.htmlController.renderEdge(
|
|
1167
|
+
r.direction = o.direction ?? r.direction, this.graphStore.getPortAdjacentEdgeIds(t).forEach((i) => {
|
|
1168
|
+
this.htmlController.renderEdge(i);
|
|
1168
1169
|
});
|
|
1169
1170
|
}
|
|
1170
1171
|
updateNode(t, o) {
|
|
1171
1172
|
const r = this.graphStore.getNode(t);
|
|
1172
1173
|
if (r === void 0)
|
|
1173
1174
|
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((
|
|
1175
|
-
this.htmlController.renderEdge(
|
|
1175
|
+
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((i) => {
|
|
1176
|
+
this.htmlController.renderEdge(i);
|
|
1176
1177
|
});
|
|
1177
1178
|
}
|
|
1178
1179
|
removeEdge(t) {
|
|
@@ -1214,12 +1215,12 @@ class xt {
|
|
|
1214
1215
|
s(this, "canvasController");
|
|
1215
1216
|
s(this, "edgeShapeFactory");
|
|
1216
1217
|
this.apiOptions = t;
|
|
1217
|
-
const o =
|
|
1218
|
-
this.model = new lt(
|
|
1219
|
-
const
|
|
1218
|
+
const o = dt(this.apiOptions), r = new at(), n = new ct();
|
|
1219
|
+
this.model = new lt(n), this.transformation = new gt(r);
|
|
1220
|
+
const i = new ft(n, r);
|
|
1220
1221
|
this.canvasController = new vt(
|
|
1221
|
-
i,
|
|
1222
1222
|
n,
|
|
1223
|
+
i,
|
|
1223
1224
|
r,
|
|
1224
1225
|
o.nodes.centerFn,
|
|
1225
1226
|
o.ports.direction,
|
|
@@ -1306,8 +1307,8 @@ class xt {
|
|
|
1306
1307
|
}
|
|
1307
1308
|
}
|
|
1308
1309
|
const P = (e, t, o) => {
|
|
1309
|
-
const { x: r, y:
|
|
1310
|
-
return t >= r && t <= r +
|
|
1310
|
+
const { x: r, y: n, width: i, height: c } = e.getBoundingClientRect();
|
|
1311
|
+
return t >= r && t <= r + i && o >= n && o <= n + c;
|
|
1311
1312
|
}, L = (e, t, o) => t >= 0 && t <= e.innerWidth && o >= 0 && o <= e.innerHeight, D = (e, t) => {
|
|
1312
1313
|
t !== null ? e.style.cursor = t : e.style.removeProperty("cursor");
|
|
1313
1314
|
};
|
|
@@ -1320,7 +1321,8 @@ class St {
|
|
|
1320
1321
|
s(this, "grabbedNodeId", null);
|
|
1321
1322
|
s(this, "onNodeDrag");
|
|
1322
1323
|
s(this, "onBeforeNodeDrag");
|
|
1323
|
-
s(this, "
|
|
1324
|
+
s(this, "onNodeDragFinished");
|
|
1325
|
+
s(this, "nodeIdGenerator", new N(
|
|
1324
1326
|
(t) => this.nodes.has(t)
|
|
1325
1327
|
));
|
|
1326
1328
|
s(this, "element", null);
|
|
@@ -1343,8 +1345,8 @@ class St {
|
|
|
1343
1345
|
return;
|
|
1344
1346
|
}
|
|
1345
1347
|
if (this.grabbedNodeId !== null && this.previousTouchCoords !== null) {
|
|
1346
|
-
const r = o.clientX - this.previousTouchCoords.x,
|
|
1347
|
-
this.dragNode(this.grabbedNodeId, r,
|
|
1348
|
+
const r = o.clientX - this.previousTouchCoords.x, n = o.clientY - this.previousTouchCoords.y;
|
|
1349
|
+
this.dragNode(this.grabbedNodeId, r, n), this.previousTouchCoords = {
|
|
1348
1350
|
x: t.touches[0].clientX,
|
|
1349
1351
|
y: t.touches[0].clientY
|
|
1350
1352
|
};
|
|
@@ -1360,9 +1362,10 @@ class St {
|
|
|
1360
1362
|
s(this, "freezePriority");
|
|
1361
1363
|
s(this, "window", window);
|
|
1362
1364
|
s(this, "dragCursor");
|
|
1363
|
-
var r, i;
|
|
1365
|
+
var r, n, i;
|
|
1364
1366
|
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 = ((
|
|
1367
|
+
}), this.onBeforeNodeDrag = ((n = o == null ? void 0 : o.events) == null ? void 0 : n.onBeforeNodeDrag) ?? (() => !0), this.onNodeDragFinished = ((i = o == null ? void 0 : o.events) == null ? void 0 : i.onNodeDragFinished) ?? (() => {
|
|
1368
|
+
}), this.freezePriority = (o == null ? void 0 : o.moveOnTop) === !1, this.dragCursor = (o == null ? void 0 : o.dragCursor) !== void 0 ? o.dragCursor : "grab";
|
|
1366
1369
|
}
|
|
1367
1370
|
attach(t) {
|
|
1368
1371
|
return this.detach(), this.element = t, this.canvas.attach(this.element), this;
|
|
@@ -1373,34 +1376,34 @@ class St {
|
|
|
1373
1376
|
addNode(t) {
|
|
1374
1377
|
const o = this.nodeIdGenerator.create(t.id);
|
|
1375
1378
|
this.canvas.addNode({ ...t, id: o }), this.updateMaxNodePriority(o);
|
|
1376
|
-
const r = (
|
|
1377
|
-
if (this.element === null ||
|
|
1379
|
+
const r = (i) => {
|
|
1380
|
+
if (this.element === null || i.button !== 0)
|
|
1378
1381
|
return;
|
|
1379
|
-
const
|
|
1382
|
+
const c = this.model.getNode(o);
|
|
1380
1383
|
this.onBeforeNodeDrag({
|
|
1381
1384
|
nodeId: o,
|
|
1382
1385
|
element: t.element,
|
|
1383
|
-
x:
|
|
1384
|
-
y:
|
|
1385
|
-
}) && (
|
|
1386
|
-
},
|
|
1387
|
-
|
|
1388
|
-
x:
|
|
1389
|
-
y:
|
|
1386
|
+
x: c.x,
|
|
1387
|
+
y: c.y
|
|
1388
|
+
}) && (i.stopImmediatePropagation(), this.grabbedNodeId = o, D(this.element, this.dragCursor), this.moveNodeOnTop(o), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
|
|
1389
|
+
}, n = (i) => {
|
|
1390
|
+
i.stopImmediatePropagation(), this.previousTouchCoords = {
|
|
1391
|
+
x: i.touches[0].clientX,
|
|
1392
|
+
y: i.touches[0].clientY
|
|
1390
1393
|
};
|
|
1391
|
-
const
|
|
1394
|
+
const c = this.model.getNode(o);
|
|
1392
1395
|
this.onBeforeNodeDrag({
|
|
1393
1396
|
nodeId: o,
|
|
1394
1397
|
element: t.element,
|
|
1395
|
-
x:
|
|
1396
|
-
y:
|
|
1397
|
-
}) &&
|
|
1398
|
+
x: c.x,
|
|
1399
|
+
y: c.y
|
|
1400
|
+
}) && i.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));
|
|
1398
1401
|
};
|
|
1399
1402
|
return this.nodes.set(o, {
|
|
1400
1403
|
element: t.element,
|
|
1401
1404
|
onMouseDown: r,
|
|
1402
|
-
onTouchStart:
|
|
1403
|
-
}), t.element.addEventListener("mousedown", r), t.element.addEventListener("touchstart",
|
|
1405
|
+
onTouchStart: n
|
|
1406
|
+
}), t.element.addEventListener("mousedown", r), t.element.addEventListener("touchstart", n), this;
|
|
1404
1407
|
}
|
|
1405
1408
|
updateNode(t, o) {
|
|
1406
1409
|
return this.canvas.updateNode(t, o), this.updateMaxNodePriority(t), this;
|
|
@@ -1442,15 +1445,15 @@ class St {
|
|
|
1442
1445
|
this.detach(), this.clear(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
|
|
1443
1446
|
}
|
|
1444
1447
|
dragNode(t, o, r) {
|
|
1445
|
-
const
|
|
1446
|
-
if (
|
|
1448
|
+
const n = this.model.getNode(t);
|
|
1449
|
+
if (n === null)
|
|
1447
1450
|
return;
|
|
1448
|
-
const
|
|
1451
|
+
const i = this.canvas.transformation.getContentMatrix(), c = i.scale * n.x + i.dx, d = i.scale * n.y + i.dy, h = c + o, l = d + r, a = this.canvas.transformation.getViewportMatrix(), w = a.scale * h + a.dx, y = a.scale * l + a.dy;
|
|
1449
1452
|
this.canvas.updateNode(t, { x: w, y }), this.onNodeDrag({
|
|
1450
1453
|
nodeId: t,
|
|
1451
|
-
element:
|
|
1452
|
-
x:
|
|
1453
|
-
y:
|
|
1454
|
+
element: n.element,
|
|
1455
|
+
x: n.x,
|
|
1456
|
+
y: n.y
|
|
1454
1457
|
});
|
|
1455
1458
|
}
|
|
1456
1459
|
updateMaxNodePriority(t) {
|
|
@@ -1462,40 +1465,53 @@ class St {
|
|
|
1462
1465
|
return;
|
|
1463
1466
|
this.maxNodePriority += 2, this.updateNode(t, { priority: this.maxNodePriority });
|
|
1464
1467
|
const o = this.maxNodePriority - 1;
|
|
1465
|
-
this.model.getNodeAdjacentEdgeIds(t).forEach((
|
|
1466
|
-
this.updateEdge(
|
|
1468
|
+
this.model.getNodeAdjacentEdgeIds(t).forEach((n) => {
|
|
1469
|
+
this.updateEdge(n, { priority: o });
|
|
1467
1470
|
});
|
|
1468
1471
|
}
|
|
1469
1472
|
cancelMouseDrag() {
|
|
1470
|
-
|
|
1473
|
+
const t = this.model.getNode(this.grabbedNodeId);
|
|
1474
|
+
t !== null && this.onNodeDragFinished({
|
|
1475
|
+
nodeId: this.grabbedNodeId,
|
|
1476
|
+
element: t.element,
|
|
1477
|
+
x: t.x,
|
|
1478
|
+
y: t.y
|
|
1479
|
+
}), this.grabbedNodeId = null, this.element !== null && D(this.element, null), this.removeMouseDragListeners();
|
|
1471
1480
|
}
|
|
1472
1481
|
removeMouseDragListeners() {
|
|
1473
1482
|
this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
1474
1483
|
}
|
|
1475
1484
|
cancelTouchDrag() {
|
|
1476
|
-
this.previousTouchCoords = null
|
|
1485
|
+
this.previousTouchCoords = null;
|
|
1486
|
+
const t = this.model.getNode(this.grabbedNodeId);
|
|
1487
|
+
t !== null && this.onNodeDragFinished({
|
|
1488
|
+
nodeId: this.grabbedNodeId,
|
|
1489
|
+
element: t.element,
|
|
1490
|
+
x: t.x,
|
|
1491
|
+
y: t.y
|
|
1492
|
+
}), this.grabbedNodeId = null, this.removeTouchDragListeners();
|
|
1477
1493
|
}
|
|
1478
1494
|
removeTouchDragListeners() {
|
|
1479
1495
|
this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
|
|
1480
1496
|
}
|
|
1481
1497
|
}
|
|
1482
1498
|
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,
|
|
1484
|
-
return (
|
|
1485
|
-
let
|
|
1486
|
-
|
|
1487
|
-
const h =
|
|
1488
|
-
|
|
1489
|
-
const l =
|
|
1490
|
-
return
|
|
1499
|
+
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, n = e.maxY !== null ? e.maxY : 1 / 0;
|
|
1500
|
+
return (i) => {
|
|
1501
|
+
let c = i.nextTransform.dx, d = i.nextTransform.dy;
|
|
1502
|
+
c < t && c < i.prevTransform.dx && (c = Math.min(i.prevTransform.dx, t));
|
|
1503
|
+
const h = i.canvasWidth * i.prevTransform.scale;
|
|
1504
|
+
c > o - h && c > i.prevTransform.dx && (c = Math.max(i.prevTransform.dx, o - h)), d < r && d < i.prevTransform.dy && (d = Math.min(i.prevTransform.dy, r));
|
|
1505
|
+
const l = i.canvasHeight * i.prevTransform.scale;
|
|
1506
|
+
return d > n - l && d > i.prevTransform.dy && (d = Math.max(i.prevTransform.dy, n - l)), { scale: i.nextTransform.scale, dx: c, dy: d };
|
|
1491
1507
|
};
|
|
1492
1508
|
}, Et = (e) => {
|
|
1493
|
-
const t = e.maxContentScale, o = e.minContentScale, r = t !== null ? 1 / t : 0,
|
|
1494
|
-
return (
|
|
1495
|
-
let
|
|
1496
|
-
return
|
|
1497
|
-
scale:
|
|
1498
|
-
dx:
|
|
1509
|
+
const t = e.maxContentScale, o = e.minContentScale, r = t !== null ? 1 / t : 0, n = o !== null ? 1 / o : 1 / 0;
|
|
1510
|
+
return (i) => {
|
|
1511
|
+
let c = i.nextTransform.scale, d = i.nextTransform.dx, h = i.nextTransform.dy;
|
|
1512
|
+
return i.nextTransform.scale > n && i.nextTransform.scale > i.prevTransform.scale && (c = Math.max(i.prevTransform.scale, n), d = i.prevTransform.dx, h = i.prevTransform.dy), i.nextTransform.scale < r && i.nextTransform.scale < i.prevTransform.scale && (c = Math.min(i.prevTransform.scale, r), d = i.prevTransform.dx, h = i.prevTransform.dy), {
|
|
1513
|
+
scale: c,
|
|
1514
|
+
dx: d,
|
|
1499
1515
|
dy: h
|
|
1500
1516
|
};
|
|
1501
1517
|
};
|
|
@@ -1507,7 +1523,7 @@ const At = (e) => {
|
|
|
1507
1523
|
canvasHeight: t.canvasHeight
|
|
1508
1524
|
}),
|
|
1509
1525
|
t.nextTransform
|
|
1510
|
-
),
|
|
1526
|
+
), U = (e) => {
|
|
1511
1527
|
if (typeof e == "function")
|
|
1512
1528
|
return e;
|
|
1513
1529
|
switch (e.type) {
|
|
@@ -1526,46 +1542,46 @@ const At = (e) => {
|
|
|
1526
1542
|
}
|
|
1527
1543
|
}, Mt = (e) => {
|
|
1528
1544
|
var h, l, a, w;
|
|
1529
|
-
const t = (h = e == null ? void 0 : e.scale) == null ? void 0 : h.
|
|
1530
|
-
let
|
|
1531
|
-
r !== void 0 ? Array.isArray(r) ?
|
|
1545
|
+
const t = (h = e == null ? void 0 : e.scale) == null ? void 0 : h.mouseWheelSensitivity, o = t !== void 0 ? t : 1.2, r = e == null ? void 0 : e.transformPreprocessor;
|
|
1546
|
+
let n;
|
|
1547
|
+
r !== void 0 ? Array.isArray(r) ? n = Tt(
|
|
1532
1548
|
r.map(
|
|
1533
|
-
(y) =>
|
|
1549
|
+
(y) => U(y)
|
|
1534
1550
|
)
|
|
1535
|
-
) :
|
|
1536
|
-
const
|
|
1537
|
-
}),
|
|
1551
|
+
) : n = U(r) : n = (y) => y.nextTransform;
|
|
1552
|
+
const i = ((l = e == null ? void 0 : e.shift) == null ? void 0 : l.cursor) !== void 0 ? e.shift.cursor : "grab", c = ((a = e == null ? void 0 : e.events) == null ? void 0 : a.onBeforeTransformStarted) ?? (() => {
|
|
1553
|
+
}), d = ((w = e == null ? void 0 : e.events) == null ? void 0 : w.onTransformFinished) ?? (() => {
|
|
1538
1554
|
});
|
|
1539
1555
|
return {
|
|
1540
1556
|
wheelSensitivity: o,
|
|
1541
|
-
onBeforeTransformStarted:
|
|
1542
|
-
onTransformFinished:
|
|
1543
|
-
transformPreprocessor:
|
|
1544
|
-
shiftCursor:
|
|
1557
|
+
onBeforeTransformStarted: c,
|
|
1558
|
+
onTransformFinished: d,
|
|
1559
|
+
transformPreprocessor: n,
|
|
1560
|
+
shiftCursor: i
|
|
1545
1561
|
};
|
|
1546
1562
|
}, W = (e) => {
|
|
1547
1563
|
const t = [], o = e.touches.length;
|
|
1548
|
-
for (let
|
|
1549
|
-
t.push([e.touches[
|
|
1564
|
+
for (let d = 0; d < o; d++)
|
|
1565
|
+
t.push([e.touches[d].clientX, e.touches[d].clientY]);
|
|
1550
1566
|
const r = t.reduce(
|
|
1551
|
-
(
|
|
1567
|
+
(d, h) => [d[0] + h[0], d[1] + h[1]],
|
|
1552
1568
|
[0, 0]
|
|
1553
|
-
),
|
|
1554
|
-
(
|
|
1569
|
+
), n = [r[0] / o, r[1] / o], c = t.map((d) => [d[0] - n[0], d[1] - n[1]]).reduce(
|
|
1570
|
+
(d, h) => d + Math.sqrt(h[0] * h[0] + h[1] * h[1]),
|
|
1555
1571
|
0
|
|
1556
1572
|
);
|
|
1557
1573
|
return {
|
|
1558
|
-
x:
|
|
1559
|
-
y:
|
|
1560
|
-
scale:
|
|
1574
|
+
x: n[0],
|
|
1575
|
+
y: n[1],
|
|
1576
|
+
scale: c / o,
|
|
1561
1577
|
touchesCnt: o,
|
|
1562
1578
|
touches: t
|
|
1563
1579
|
};
|
|
1564
|
-
},
|
|
1580
|
+
}, Nt = (e, t, o) => ({
|
|
1565
1581
|
scale: e.scale,
|
|
1566
1582
|
dx: e.dx + e.scale * t,
|
|
1567
1583
|
dy: e.dy + e.scale * o
|
|
1568
|
-
}),
|
|
1584
|
+
}), Ct = (e, t, o, r) => ({
|
|
1569
1585
|
scale: e.scale * t,
|
|
1570
1586
|
dx: e.scale * (1 - t) * o + e.dx,
|
|
1571
1587
|
dy: e.scale * (1 - t) * r + e.dy
|
|
@@ -1593,8 +1609,8 @@ class Pt {
|
|
|
1593
1609
|
});
|
|
1594
1610
|
s(this, "onWheelScroll", (t) => {
|
|
1595
1611
|
t.preventDefault();
|
|
1596
|
-
const { left: o, top: r } = this.element.getBoundingClientRect(),
|
|
1597
|
-
this.scaleViewport(this.element,
|
|
1612
|
+
const { left: o, top: r } = this.element.getBoundingClientRect(), n = t.clientX - o, i = t.clientY - r, d = 1 / (t.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
|
|
1613
|
+
this.scaleViewport(this.element, d, n, i);
|
|
1598
1614
|
});
|
|
1599
1615
|
s(this, "onTouchStart", (t) => {
|
|
1600
1616
|
this.prevTouches = W(t), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish);
|
|
@@ -1605,7 +1621,7 @@ class Pt {
|
|
|
1605
1621
|
return;
|
|
1606
1622
|
const r = W(t);
|
|
1607
1623
|
if (!r.touches.every(
|
|
1608
|
-
(
|
|
1624
|
+
(i) => P(o, i[0], i[1]) && L(this.window, i[0], i[1])
|
|
1609
1625
|
)) {
|
|
1610
1626
|
this.stopTouchDrag();
|
|
1611
1627
|
return;
|
|
@@ -1615,8 +1631,8 @@ class Pt {
|
|
|
1615
1631
|
-(r.x - this.prevTouches.x),
|
|
1616
1632
|
-(r.y - this.prevTouches.y)
|
|
1617
1633
|
), r.touchesCnt === 2) {
|
|
1618
|
-
const { left:
|
|
1619
|
-
this.scaleViewport(o, a,
|
|
1634
|
+
const { left: i, top: c } = o.getBoundingClientRect(), d = this.prevTouches.x - i, h = this.prevTouches.y - c, a = 1 / (r.scale / this.prevTouches.scale);
|
|
1635
|
+
this.scaleViewport(o, a, d, h);
|
|
1620
1636
|
}
|
|
1621
1637
|
this.prevTouches = r;
|
|
1622
1638
|
});
|
|
@@ -1624,13 +1640,13 @@ class Pt {
|
|
|
1624
1640
|
t.touches.length > 0 ? this.prevTouches = W(t) : this.stopTouchDrag();
|
|
1625
1641
|
});
|
|
1626
1642
|
s(this, "observer", new ResizeObserver(() => {
|
|
1627
|
-
const t = this.canvas.transformation.getViewportMatrix(), { width: o, height: r } = this.element.getBoundingClientRect(),
|
|
1643
|
+
const t = this.canvas.transformation.getViewportMatrix(), { width: o, height: r } = this.element.getBoundingClientRect(), n = this.options.transformPreprocessor({
|
|
1628
1644
|
prevTransform: t,
|
|
1629
1645
|
nextTransform: t,
|
|
1630
1646
|
canvasWidth: o,
|
|
1631
1647
|
canvasHeight: r
|
|
1632
1648
|
});
|
|
1633
|
-
this.canvas.patchViewportMatrix(
|
|
1649
|
+
this.canvas.patchViewportMatrix(n), this.options.onTransformFinished();
|
|
1634
1650
|
}));
|
|
1635
1651
|
s(this, "options");
|
|
1636
1652
|
this.canvas = t, this.options = Mt(o), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
|
|
@@ -1682,20 +1698,20 @@ class Pt {
|
|
|
1682
1698
|
}
|
|
1683
1699
|
moveViewport(t, o, r) {
|
|
1684
1700
|
this.options.onBeforeTransformStarted();
|
|
1685
|
-
const
|
|
1686
|
-
prevTransform:
|
|
1687
|
-
nextTransform:
|
|
1688
|
-
canvasWidth:
|
|
1689
|
-
canvasHeight:
|
|
1701
|
+
const n = this.transformation.getViewportMatrix(), i = Nt(n, o, r), { width: c, height: d } = t.getBoundingClientRect(), h = this.options.transformPreprocessor({
|
|
1702
|
+
prevTransform: n,
|
|
1703
|
+
nextTransform: i,
|
|
1704
|
+
canvasWidth: c,
|
|
1705
|
+
canvasHeight: d
|
|
1690
1706
|
});
|
|
1691
1707
|
this.canvas.patchViewportMatrix(h), this.options.onTransformFinished();
|
|
1692
1708
|
}
|
|
1693
|
-
scaleViewport(t, o, r,
|
|
1709
|
+
scaleViewport(t, o, r, n) {
|
|
1694
1710
|
this.options.onBeforeTransformStarted();
|
|
1695
|
-
const
|
|
1696
|
-
prevTransform:
|
|
1697
|
-
nextTransform:
|
|
1698
|
-
canvasWidth:
|
|
1711
|
+
const i = this.canvas.transformation.getViewportMatrix(), c = Ct(i, o, r, n), { width: d, height: h } = t.getBoundingClientRect(), l = this.options.transformPreprocessor({
|
|
1712
|
+
prevTransform: i,
|
|
1713
|
+
nextTransform: c,
|
|
1714
|
+
canvasWidth: d,
|
|
1699
1715
|
canvasHeight: h
|
|
1700
1716
|
});
|
|
1701
1717
|
this.canvas.patchViewportMatrix(l), this.options.onTransformFinished();
|
|
@@ -1755,14 +1771,14 @@ class Dt {
|
|
|
1755
1771
|
s(this, "transformation");
|
|
1756
1772
|
s(this, "model");
|
|
1757
1773
|
s(this, "nodes", new Lt());
|
|
1758
|
-
s(this, "nodeIdGenerator", new
|
|
1774
|
+
s(this, "nodeIdGenerator", new N(
|
|
1759
1775
|
(t) => this.nodes.hasKey(t)
|
|
1760
1776
|
));
|
|
1761
1777
|
s(this, "nodesResizeObserver");
|
|
1762
1778
|
this.canvas = t, this.nodesResizeObserver = new window.ResizeObserver((o) => {
|
|
1763
1779
|
o.forEach((r) => {
|
|
1764
|
-
const
|
|
1765
|
-
this.reactNodeChange(
|
|
1780
|
+
const n = r.target;
|
|
1781
|
+
this.reactNodeChange(n);
|
|
1766
1782
|
});
|
|
1767
1783
|
}), this.transformation = this.canvas.transformation, this.model = this.canvas.model;
|
|
1768
1784
|
}
|
|
@@ -1819,8 +1835,8 @@ class Dt {
|
|
|
1819
1835
|
}
|
|
1820
1836
|
reactNodeChange(t) {
|
|
1821
1837
|
const o = this.nodes.getByValue(t);
|
|
1822
|
-
this.canvas.updateNode(o), this.model.getNodeAdjacentEdgeIds(o).forEach((
|
|
1823
|
-
this.canvas.updateEdge(
|
|
1838
|
+
this.canvas.updateNode(o), this.model.getNodeAdjacentEdgeIds(o).forEach((n) => {
|
|
1839
|
+
this.canvas.updateEdge(n);
|
|
1824
1840
|
});
|
|
1825
1841
|
}
|
|
1826
1842
|
}
|