@html-graph/html-graph 0.0.59 → 0.0.61
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 +2 -2
- package/dist/main.d.ts +118 -16
- package/dist/main.js +652 -641
- package/dist/main.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _ = Object.defineProperty;
|
|
2
2
|
var J = (r, e, t) => e in r ? _(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
-
var
|
|
3
|
+
var n = (r, e, t) => J(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
const Y = (r) => ({
|
|
5
5
|
scale: 1 / r.scale,
|
|
6
6
|
dx: -r.dx / r.scale,
|
|
@@ -12,8 +12,8 @@ const Y = (r) => ({
|
|
|
12
12
|
};
|
|
13
13
|
class Q {
|
|
14
14
|
constructor() {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
n(this, "viewportMatrix", X);
|
|
16
|
+
n(this, "contentMatrix", X);
|
|
17
17
|
}
|
|
18
18
|
getViewportMatrix() {
|
|
19
19
|
return this.viewportMatrix;
|
|
@@ -21,18 +21,18 @@ class Q {
|
|
|
21
21
|
getContentMatrix() {
|
|
22
22
|
return this.contentMatrix;
|
|
23
23
|
}
|
|
24
|
-
patchViewportMatrix(e
|
|
24
|
+
patchViewportMatrix(e) {
|
|
25
25
|
this.viewportMatrix = {
|
|
26
|
-
scale: e ?? this.viewportMatrix.scale,
|
|
27
|
-
dx:
|
|
28
|
-
dy:
|
|
26
|
+
scale: e.scale ?? this.viewportMatrix.scale,
|
|
27
|
+
dx: e.dx ?? this.viewportMatrix.dx,
|
|
28
|
+
dy: e.dy ?? this.viewportMatrix.dy
|
|
29
29
|
}, this.contentMatrix = Y(this.viewportMatrix);
|
|
30
30
|
}
|
|
31
|
-
patchContentMatrix(e
|
|
31
|
+
patchContentMatrix(e) {
|
|
32
32
|
this.contentMatrix = {
|
|
33
|
-
scale: e ?? this.contentMatrix.scale,
|
|
34
|
-
dx:
|
|
35
|
-
dy:
|
|
33
|
+
scale: e.scale ?? this.contentMatrix.scale,
|
|
34
|
+
dx: e.dx ?? this.contentMatrix.dx,
|
|
35
|
+
dy: e.dy ?? this.contentMatrix.dy
|
|
36
36
|
}, this.viewportMatrix = Y(this.contentMatrix);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -49,17 +49,23 @@ class Z {
|
|
|
49
49
|
}
|
|
50
50
|
class q {
|
|
51
51
|
constructor() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
addNode(e
|
|
62
|
-
this.nodes.set(e, {
|
|
52
|
+
n(this, "nodes", /* @__PURE__ */ new Map());
|
|
53
|
+
n(this, "ports", /* @__PURE__ */ new Map());
|
|
54
|
+
n(this, "nodePorts", /* @__PURE__ */ new Map());
|
|
55
|
+
n(this, "portNodeId", /* @__PURE__ */ new Map());
|
|
56
|
+
n(this, "edges", /* @__PURE__ */ new Map());
|
|
57
|
+
n(this, "incommingEdges", /* @__PURE__ */ new Map());
|
|
58
|
+
n(this, "outcommingEdges", /* @__PURE__ */ new Map());
|
|
59
|
+
n(this, "cycleEdges", /* @__PURE__ */ new Map());
|
|
60
|
+
}
|
|
61
|
+
addNode(e) {
|
|
62
|
+
this.nodes.set(e.nodeId, {
|
|
63
|
+
element: e.element,
|
|
64
|
+
x: e.x,
|
|
65
|
+
y: e.y,
|
|
66
|
+
centerFn: e.centerFn,
|
|
67
|
+
priority: e.priority
|
|
68
|
+
}), this.nodePorts.set(e.nodeId, /* @__PURE__ */ new Map());
|
|
63
69
|
}
|
|
64
70
|
getAllNodeIds() {
|
|
65
71
|
return Array.from(this.nodes.keys());
|
|
@@ -70,8 +76,12 @@ class q {
|
|
|
70
76
|
removeNode(e) {
|
|
71
77
|
this.nodes.delete(e), this.nodePorts.delete(e);
|
|
72
78
|
}
|
|
73
|
-
addPort(e
|
|
74
|
-
this.ports.set(e, {
|
|
79
|
+
addPort(e) {
|
|
80
|
+
this.ports.set(e.portId, {
|
|
81
|
+
element: e.element,
|
|
82
|
+
centerFn: e.centerFn,
|
|
83
|
+
direction: e.direction
|
|
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);
|
|
75
85
|
}
|
|
76
86
|
getPort(e) {
|
|
77
87
|
return this.ports.get(e);
|
|
@@ -91,13 +101,13 @@ class q {
|
|
|
91
101
|
const t = this.portNodeId.get(e);
|
|
92
102
|
this.portNodeId.delete(e), this.nodePorts.get(t).delete(e), this.ports.delete(e);
|
|
93
103
|
}
|
|
94
|
-
addEdge(e
|
|
95
|
-
this.edges.set(e, {
|
|
96
|
-
from:
|
|
97
|
-
to:
|
|
98
|
-
shape:
|
|
99
|
-
priority:
|
|
100
|
-
}),
|
|
104
|
+
addEdge(e) {
|
|
105
|
+
this.edges.set(e.edgeId, {
|
|
106
|
+
from: e.from,
|
|
107
|
+
to: e.to,
|
|
108
|
+
shape: e.shape,
|
|
109
|
+
priority: e.priority
|
|
110
|
+
}), e.from !== e.to ? (this.outcommingEdges.get(e.from).add(e.edgeId), this.incommingEdges.get(e.to).add(e.edgeId)) : this.cycleEdges.get(e.from).add(e.edgeId);
|
|
101
111
|
}
|
|
102
112
|
getAllEdgeIds() {
|
|
103
113
|
return Array.from(this.edges.keys());
|
|
@@ -229,28 +239,28 @@ const l = {
|
|
|
229
239
|
}, p = (r, e, t) => ({
|
|
230
240
|
x: e.x * r.x - e.y * r.y + ((1 - e.x) * t.x + e.y * t.y),
|
|
231
241
|
y: e.y * r.x + e.x * r.y + ((1 - e.x) * t.y - e.y * t.x)
|
|
232
|
-
}),
|
|
242
|
+
}), x = (r, e, t) => ({ x: e * Math.cos(r), y: t * Math.sin(r) }), E = (r, e, t, s) => {
|
|
233
243
|
const i = [
|
|
234
244
|
l,
|
|
235
245
|
{ x: t, y: s },
|
|
236
246
|
{ x: t, y: -s }
|
|
237
|
-
].map((
|
|
238
|
-
return `${
|
|
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}`;
|
|
239
249
|
}, D = (r, e) => {
|
|
240
250
|
const t = [];
|
|
241
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) {
|
|
242
252
|
const s = r.length - 1;
|
|
243
|
-
let o = 0, i = 0,
|
|
244
|
-
r.forEach((
|
|
245
|
-
let
|
|
246
|
-
const m =
|
|
247
|
-
if (m && (
|
|
248
|
-
const j = r[
|
|
249
|
-
o = j.x -
|
|
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);
|
|
250
260
|
}
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
`C ${
|
|
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}`
|
|
254
264
|
);
|
|
255
265
|
});
|
|
256
266
|
}
|
|
@@ -264,39 +274,39 @@ const l = {
|
|
|
264
274
|
}, L = (r, e) => {
|
|
265
275
|
const t = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
266
276
|
return t.setAttribute("stroke", r), t.setAttribute("stroke-width", `${e}`), t.setAttribute("fill", "none"), t;
|
|
267
|
-
},
|
|
277
|
+
}, A = (r) => {
|
|
268
278
|
const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
269
279
|
return e.setAttribute("fill", r), e;
|
|
270
280
|
};
|
|
271
281
|
class te {
|
|
272
|
-
constructor(e, t, s, o, i,
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.svg.appendChild(this.group), this.line = L(e, t), this.group.appendChild(this.line),
|
|
282
|
+
constructor(e, t, s, o, i, h, a) {
|
|
283
|
+
n(this, "svg", N());
|
|
284
|
+
n(this, "group", $());
|
|
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));
|
|
279
289
|
}
|
|
280
290
|
update(e, t, s, o, i) {
|
|
281
291
|
this.group.style.transform = `scale(${t}, ${s})`;
|
|
282
|
-
const
|
|
283
|
-
if (this.line.setAttribute("d",
|
|
284
|
-
const
|
|
285
|
-
|
|
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,
|
|
286
296
|
l,
|
|
287
297
|
this.arrowLength,
|
|
288
298
|
this.arrowWidth
|
|
289
299
|
);
|
|
290
|
-
this.sourceArrow.setAttribute("d",
|
|
300
|
+
this.sourceArrow.setAttribute("d", c);
|
|
291
301
|
}
|
|
292
302
|
if (this.targetArrow) {
|
|
293
|
-
const
|
|
294
|
-
|
|
303
|
+
const c = E(
|
|
304
|
+
a,
|
|
295
305
|
e,
|
|
296
306
|
-this.arrowLength,
|
|
297
307
|
this.arrowWidth
|
|
298
308
|
);
|
|
299
|
-
this.targetArrow.setAttribute("d",
|
|
309
|
+
this.targetArrow.setAttribute("d", c);
|
|
300
310
|
}
|
|
301
311
|
}
|
|
302
312
|
createLinePath(e, t, s) {
|
|
@@ -308,175 +318,175 @@ class te {
|
|
|
308
318
|
{ x: e.x - this.arrowLength, y: e.y },
|
|
309
319
|
s,
|
|
310
320
|
e
|
|
311
|
-
),
|
|
321
|
+
), h = {
|
|
312
322
|
x: o.x + t.x * this.curvature,
|
|
313
323
|
y: o.y + t.y * this.curvature
|
|
314
|
-
},
|
|
324
|
+
}, a = {
|
|
315
325
|
x: i.x - s.x * this.curvature,
|
|
316
326
|
y: i.y - s.y * this.curvature
|
|
317
|
-
},
|
|
318
|
-
return `${
|
|
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}`;
|
|
319
329
|
}
|
|
320
330
|
}
|
|
321
331
|
class re {
|
|
322
|
-
constructor(e, t, s, o, i,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness =
|
|
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));
|
|
329
339
|
}
|
|
330
340
|
update(e, t, s, o, i) {
|
|
331
341
|
this.group.style.transform = `scale(${t}, ${s})`;
|
|
332
|
-
const
|
|
333
|
-
if (this.line.setAttribute("d",
|
|
334
|
-
const
|
|
335
|
-
|
|
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,
|
|
336
346
|
l,
|
|
337
347
|
this.arrowLength,
|
|
338
348
|
this.arrowWidth
|
|
339
349
|
);
|
|
340
|
-
this.sourceArrow.setAttribute("d",
|
|
350
|
+
this.sourceArrow.setAttribute("d", c);
|
|
341
351
|
}
|
|
342
352
|
if (this.targetArrow) {
|
|
343
|
-
const
|
|
344
|
-
|
|
353
|
+
const c = E(
|
|
354
|
+
a,
|
|
345
355
|
e,
|
|
346
356
|
-this.arrowLength,
|
|
347
357
|
this.arrowWidth
|
|
348
358
|
);
|
|
349
|
-
this.targetArrow.setAttribute("d",
|
|
359
|
+
this.targetArrow.setAttribute("d", c);
|
|
350
360
|
}
|
|
351
361
|
}
|
|
352
362
|
createLinePath(e, t, s) {
|
|
353
|
-
const o = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, i = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e,
|
|
354
|
-
return D([o,
|
|
363
|
+
const o = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, i = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, h = this.arrowLength + this.arrowOffset, a = p({ x: h, y: l.y }, t, l), d = p({ x: e.x - h, y: e.y }, s, e);
|
|
364
|
+
return D([o, a, d, i], this.roundness);
|
|
355
365
|
}
|
|
356
366
|
}
|
|
357
367
|
class se {
|
|
358
|
-
constructor(e, t, s, o, i,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness =
|
|
368
|
+
constructor(e, t, s, o, i, h, a, d) {
|
|
369
|
+
n(this, "svg", N());
|
|
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));
|
|
365
375
|
}
|
|
366
376
|
update(e, t, s, o, i) {
|
|
367
377
|
this.group.style.transform = `scale(${t}, ${s})`;
|
|
368
|
-
const
|
|
369
|
-
if (this.line.setAttribute("d",
|
|
370
|
-
const
|
|
371
|
-
|
|
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,
|
|
372
382
|
l,
|
|
373
383
|
this.arrowLength,
|
|
374
384
|
this.arrowWidth
|
|
375
385
|
);
|
|
376
|
-
this.sourceArrow.setAttribute("d",
|
|
386
|
+
this.sourceArrow.setAttribute("d", c);
|
|
377
387
|
}
|
|
378
388
|
if (this.targetArrow) {
|
|
379
|
-
const
|
|
380
|
-
|
|
389
|
+
const c = E(
|
|
390
|
+
a,
|
|
381
391
|
e,
|
|
382
392
|
-this.arrowLength,
|
|
383
393
|
this.arrowWidth
|
|
384
394
|
);
|
|
385
|
-
this.targetArrow.setAttribute("d",
|
|
395
|
+
this.targetArrow.setAttribute("d", c);
|
|
386
396
|
}
|
|
387
397
|
}
|
|
388
398
|
createLinePath(e, t, s, o) {
|
|
389
|
-
const i = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l,
|
|
399
|
+
const i = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, h = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, a = this.arrowLength + this.arrowOffset, d = a - this.roundness, c = p({ x: d, y: l.y }, t, l), u = p({ x: e.x - d, y: e.y }, s, e), w = Math.max((c.x + u.x) / 2, a), m = e.y / 2, y = { x: o > 0 ? w : -a, y: c.y }, v = { x: y.x, y: m }, P = { x: o > 0 ? e.x - w : e.x + a, y: u.y }, S = { x: P.x, y: m };
|
|
390
400
|
return D(
|
|
391
|
-
[i,
|
|
401
|
+
[i, c, y, v, S, P, u, h],
|
|
392
402
|
this.roundness
|
|
393
403
|
);
|
|
394
404
|
}
|
|
395
405
|
}
|
|
396
406
|
class oe {
|
|
397
|
-
constructor(e, t, s, o, i,
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness =
|
|
407
|
+
constructor(e, t, s, o, i, h, a, d) {
|
|
408
|
+
n(this, "svg", N());
|
|
409
|
+
n(this, "group", $());
|
|
410
|
+
n(this, "line");
|
|
411
|
+
n(this, "sourceArrow", null);
|
|
412
|
+
n(this, "targetArrow", null);
|
|
413
|
+
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));
|
|
404
414
|
}
|
|
405
415
|
update(e, t, s, o, i) {
|
|
406
416
|
this.group.style.transform = `scale(${t}, ${s})`;
|
|
407
|
-
const
|
|
408
|
-
if (this.line.setAttribute("d",
|
|
409
|
-
const
|
|
410
|
-
|
|
417
|
+
const h = x(o, t, s), a = x(i, t, s), d = this.createLinePath(e, h, a, s);
|
|
418
|
+
if (this.line.setAttribute("d", d), this.sourceArrow) {
|
|
419
|
+
const c = E(
|
|
420
|
+
h,
|
|
411
421
|
l,
|
|
412
422
|
this.arrowLength,
|
|
413
423
|
this.arrowWidth
|
|
414
424
|
);
|
|
415
|
-
this.sourceArrow.setAttribute("d",
|
|
425
|
+
this.sourceArrow.setAttribute("d", c);
|
|
416
426
|
}
|
|
417
427
|
if (this.targetArrow) {
|
|
418
|
-
const
|
|
419
|
-
|
|
428
|
+
const c = E(
|
|
429
|
+
a,
|
|
420
430
|
e,
|
|
421
431
|
-this.arrowLength,
|
|
422
432
|
this.arrowWidth
|
|
423
433
|
);
|
|
424
|
-
this.targetArrow.setAttribute("d",
|
|
434
|
+
this.targetArrow.setAttribute("d", c);
|
|
425
435
|
}
|
|
426
436
|
}
|
|
427
437
|
createLinePath(e, t, s, o) {
|
|
428
|
-
const i = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l,
|
|
429
|
-
x:
|
|
430
|
-
y: o > 0 ? e.y - w : e.y +
|
|
431
|
-
},
|
|
438
|
+
const i = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, h = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, a = this.arrowLength + this.arrowOffset, d = a - this.roundness, c = p({ x: d, y: l.y }, t, l), u = p({ x: e.x - d, y: e.y }, s, e), w = Math.max((c.y + u.y) / 2, a), m = e.x / 2, y = { x: c.x, y: o > 0 ? w : -a }, v = { x: m, y: y.y }, P = {
|
|
439
|
+
x: u.x,
|
|
440
|
+
y: o > 0 ? e.y - w : e.y + a
|
|
441
|
+
}, S = { x: m, y: P.y };
|
|
432
442
|
return D(
|
|
433
|
-
[i,
|
|
443
|
+
[i, c, y, v, S, P, u, h],
|
|
434
444
|
this.roundness
|
|
435
445
|
);
|
|
436
446
|
}
|
|
437
447
|
}
|
|
438
448
|
class ie {
|
|
439
|
-
constructor(e, t, s, o, i,
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
this.arrowLength = s, this.arrowWidth = o, this.radius =
|
|
449
|
+
constructor(e, t, s, o, i, h, a) {
|
|
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));
|
|
444
454
|
}
|
|
445
455
|
update(e, t, s, o) {
|
|
446
|
-
const i =
|
|
447
|
-
if (this.line.setAttribute("d",
|
|
448
|
-
const
|
|
456
|
+
const i = x(o, t, s), h = this.createLinePath(i);
|
|
457
|
+
if (this.line.setAttribute("d", h), this.arrow) {
|
|
458
|
+
const a = E(
|
|
449
459
|
i,
|
|
450
460
|
l,
|
|
451
461
|
this.arrowLength,
|
|
452
462
|
this.arrowWidth
|
|
453
463
|
);
|
|
454
|
-
this.arrow.setAttribute("d",
|
|
464
|
+
this.arrow.setAttribute("d", a);
|
|
455
465
|
}
|
|
456
466
|
}
|
|
457
467
|
createLinePath(e) {
|
|
458
|
-
const t = this.smallRadius, s = this.radius, o = Math.sqrt(t * t + s * s), i = t + s,
|
|
468
|
+
const t = this.smallRadius, s = this.radius, o = Math.sqrt(t * t + s * s), i = t + s, h = this.arrowLength + o * (1 - s / i), a = t * s / i, c = [
|
|
459
469
|
{ x: this.arrowLength, y: l.y },
|
|
460
|
-
{ x:
|
|
461
|
-
{ x:
|
|
462
|
-
].map((m) => p(m, e, l)),
|
|
463
|
-
`M ${
|
|
464
|
-
`A ${t} ${t} 0 0 1 ${
|
|
465
|
-
`A ${s} ${s} 0 1 0 ${
|
|
466
|
-
`A ${t} ${t} 0 0 1 ${
|
|
467
|
-
].join(" "), w = `M 0 0 L ${
|
|
468
|
-
return `${this.arrow !== null ? "" : w}${
|
|
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}`;
|
|
469
479
|
}
|
|
470
480
|
}
|
|
471
481
|
class B {
|
|
472
|
-
constructor(e, t, s, o, i,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
this.arrowLength = s, this.arrowWidth = o, this.side =
|
|
479
|
-
const
|
|
482
|
+
constructor(e, t, s, o, i, h, a, d) {
|
|
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;
|
|
480
490
|
this.linePoints = [
|
|
481
491
|
{ x: this.arrowLength, y: l.y },
|
|
482
492
|
{ x: w, y: l.y },
|
|
@@ -489,15 +499,15 @@ class B {
|
|
|
489
499
|
];
|
|
490
500
|
}
|
|
491
501
|
update(e, t, s, o) {
|
|
492
|
-
const i =
|
|
493
|
-
if (this.line.setAttribute("d",
|
|
494
|
-
const
|
|
502
|
+
const i = x(o, t, s), h = this.createLinePath(i);
|
|
503
|
+
if (this.line.setAttribute("d", h), this.arrow) {
|
|
504
|
+
const a = E(
|
|
495
505
|
i,
|
|
496
506
|
l,
|
|
497
507
|
this.arrowLength,
|
|
498
508
|
this.arrowWidth
|
|
499
509
|
);
|
|
500
|
-
this.arrow.setAttribute("d",
|
|
510
|
+
this.arrow.setAttribute("d", a);
|
|
501
511
|
}
|
|
502
512
|
}
|
|
503
513
|
createLinePath(e) {
|
|
@@ -508,126 +518,126 @@ class B {
|
|
|
508
518
|
}
|
|
509
519
|
}
|
|
510
520
|
class ne {
|
|
511
|
-
constructor(e, t, s, o, i,
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
this.curvature = s, this.arrowLength = o, this.arrowWidth = i, this.detourX = Math.cos(
|
|
521
|
+
constructor(e, t, s, o, i, h, a, d, c) {
|
|
522
|
+
n(this, "svg", N());
|
|
523
|
+
n(this, "group", $());
|
|
524
|
+
n(this, "line");
|
|
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));
|
|
520
530
|
}
|
|
521
531
|
update(e, t, s, o, i) {
|
|
522
532
|
this.group.style.transform = `scale(${t}, ${s})`;
|
|
523
|
-
const
|
|
524
|
-
if (this.line.setAttribute("d",
|
|
525
|
-
const
|
|
526
|
-
|
|
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,
|
|
527
537
|
l,
|
|
528
538
|
this.arrowLength,
|
|
529
539
|
this.arrowWidth
|
|
530
540
|
);
|
|
531
|
-
this.sourceArrow.setAttribute("d",
|
|
541
|
+
this.sourceArrow.setAttribute("d", c);
|
|
532
542
|
}
|
|
533
543
|
if (this.targetArrow) {
|
|
534
|
-
const
|
|
535
|
-
|
|
544
|
+
const c = E(
|
|
545
|
+
a,
|
|
536
546
|
e,
|
|
537
547
|
-this.arrowLength,
|
|
538
548
|
this.arrowWidth
|
|
539
549
|
);
|
|
540
|
-
this.targetArrow.setAttribute("d",
|
|
550
|
+
this.targetArrow.setAttribute("d", c);
|
|
541
551
|
}
|
|
542
552
|
}
|
|
543
553
|
createLinePath(e, t, s, o, i) {
|
|
544
|
-
const
|
|
545
|
-
{ x:
|
|
554
|
+
const h = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, a = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, d = this.arrowLength, c = this.detourX * o, u = this.detourY * i, w = p(
|
|
555
|
+
{ x: d, y: l.y },
|
|
546
556
|
t,
|
|
547
557
|
l
|
|
548
558
|
), m = {
|
|
549
|
-
x: w.x +
|
|
550
|
-
y: w.y +
|
|
559
|
+
x: w.x + c,
|
|
560
|
+
y: w.y + u
|
|
551
561
|
}, y = p(
|
|
552
|
-
{ x: e.x -
|
|
562
|
+
{ x: e.x - d, y: e.y },
|
|
553
563
|
s,
|
|
554
564
|
e
|
|
555
565
|
), v = {
|
|
556
|
-
x: y.x +
|
|
557
|
-
y: y.y +
|
|
558
|
-
},
|
|
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 = {
|
|
559
569
|
x: w.x + this.curvature * t.x,
|
|
560
570
|
y: w.y + this.curvature * t.y
|
|
561
571
|
}, M = {
|
|
562
572
|
x: y.x - this.curvature * s.x,
|
|
563
573
|
y: y.y - this.curvature * s.y
|
|
564
574
|
}, b = {
|
|
565
|
-
x: w.x +
|
|
566
|
-
y: w.y +
|
|
575
|
+
x: w.x + c,
|
|
576
|
+
y: w.y + u
|
|
567
577
|
}, T = {
|
|
568
|
-
x: y.x +
|
|
569
|
-
y: y.y +
|
|
578
|
+
x: y.x + c,
|
|
579
|
+
y: y.y + u
|
|
570
580
|
};
|
|
571
581
|
return [
|
|
572
|
-
`M ${
|
|
582
|
+
`M ${h.x} ${h.y}`,
|
|
573
583
|
`L ${w.x} ${w.y}`,
|
|
574
|
-
`C ${
|
|
584
|
+
`C ${S.x} ${S.y} ${b.x} ${b.y} ${P.x} ${P.y}`,
|
|
575
585
|
`C ${T.x} ${T.y} ${M.x} ${M.y} ${y.x} ${y.y}`,
|
|
576
|
-
`L ${
|
|
586
|
+
`L ${a.x} ${a.y}`
|
|
577
587
|
].join(" ");
|
|
578
588
|
}
|
|
579
589
|
}
|
|
580
590
|
class G {
|
|
581
|
-
constructor(e, t, s, o, i,
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = i, this.roundness =
|
|
591
|
+
constructor(e, t, s, o, i, h, a, d, c, u) {
|
|
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));
|
|
590
600
|
}
|
|
591
601
|
update(e, t, s, o, i) {
|
|
592
602
|
this.group.style.transform = `scale(${t}, ${s})`;
|
|
593
|
-
const
|
|
594
|
-
if (this.line.setAttribute("d",
|
|
595
|
-
const
|
|
596
|
-
|
|
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,
|
|
597
607
|
l,
|
|
598
608
|
this.arrowLength,
|
|
599
609
|
this.arrowWidth
|
|
600
610
|
);
|
|
601
|
-
this.sourceArrow.setAttribute("d",
|
|
611
|
+
this.sourceArrow.setAttribute("d", c);
|
|
602
612
|
}
|
|
603
613
|
if (this.targetArrow) {
|
|
604
|
-
const
|
|
605
|
-
|
|
614
|
+
const c = E(
|
|
615
|
+
a,
|
|
606
616
|
e,
|
|
607
617
|
-this.arrowLength,
|
|
608
618
|
this.arrowWidth
|
|
609
619
|
);
|
|
610
|
-
this.targetArrow.setAttribute("d",
|
|
620
|
+
this.targetArrow.setAttribute("d", c);
|
|
611
621
|
}
|
|
612
622
|
}
|
|
613
623
|
createLinePath(e, t, s, o, i) {
|
|
614
|
-
const
|
|
615
|
-
{ x:
|
|
624
|
+
const h = this.sourceArrow ? p({ x: this.arrowLength, y: l.y }, t, l) : l, a = this.targetArrow ? p({ x: e.x - this.arrowLength, y: e.y }, s, e) : e, d = this.arrowLength + this.arrowOffset, c = p(
|
|
625
|
+
{ x: d, y: l.y },
|
|
616
626
|
t,
|
|
617
627
|
l
|
|
618
|
-
),
|
|
619
|
-
{ x: e.x -
|
|
628
|
+
), u = this.detourX * o, w = this.detourY * i, m = { x: c.x + u, y: c.y + w }, y = p(
|
|
629
|
+
{ x: e.x - d, y: e.y },
|
|
620
630
|
s,
|
|
621
631
|
e
|
|
622
|
-
), v = { x: y.x +
|
|
632
|
+
), v = { x: y.x + u, y: y.y + w };
|
|
623
633
|
return D(
|
|
624
|
-
[
|
|
634
|
+
[h, c, m, v, y, a],
|
|
625
635
|
this.roundness
|
|
626
636
|
);
|
|
627
637
|
}
|
|
628
638
|
}
|
|
629
|
-
var
|
|
630
|
-
const ae = (r) => (e) => e ===
|
|
639
|
+
var C = /* @__PURE__ */ ((r) => (r.Regular = "regular", r.PortCycle = "port-cycle", r.NodeCycle = "node-cycle", r))(C || {});
|
|
640
|
+
const ae = (r) => (e) => e === C.PortCycle ? new ie(
|
|
631
641
|
r.color,
|
|
632
642
|
r.width,
|
|
633
643
|
r.arrowLength,
|
|
@@ -635,7 +645,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
|
|
|
635
645
|
r.hasSourceArrow || r.hasTargetArrow,
|
|
636
646
|
r.cycleRadius,
|
|
637
647
|
r.smallCycleRadius
|
|
638
|
-
) : e ===
|
|
648
|
+
) : e === C.NodeCycle ? new ne(
|
|
639
649
|
r.color,
|
|
640
650
|
r.width,
|
|
641
651
|
r.curvature,
|
|
@@ -653,7 +663,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
|
|
|
653
663
|
r.arrowWidth,
|
|
654
664
|
r.hasSourceArrow,
|
|
655
665
|
r.hasTargetArrow
|
|
656
|
-
), he = (r) => (e) => e ===
|
|
666
|
+
), he = (r) => (e) => e === C.PortCycle ? new B(
|
|
657
667
|
r.color,
|
|
658
668
|
r.width,
|
|
659
669
|
r.arrowLength,
|
|
@@ -662,7 +672,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
|
|
|
662
672
|
r.cycleSquareSide,
|
|
663
673
|
r.arrowOffset,
|
|
664
674
|
r.roundness
|
|
665
|
-
) : e ===
|
|
675
|
+
) : e === C.NodeCycle ? new G(
|
|
666
676
|
r.color,
|
|
667
677
|
r.width,
|
|
668
678
|
r.arrowLength,
|
|
@@ -682,7 +692,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
|
|
|
682
692
|
r.hasSourceArrow,
|
|
683
693
|
r.hasTargetArrow,
|
|
684
694
|
r.roundness
|
|
685
|
-
),
|
|
695
|
+
), de = (r) => (e) => e === C.PortCycle ? new B(
|
|
686
696
|
r.color,
|
|
687
697
|
r.width,
|
|
688
698
|
r.arrowLength,
|
|
@@ -691,7 +701,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
|
|
|
691
701
|
r.cycleSquareSide,
|
|
692
702
|
r.arrowOffset,
|
|
693
703
|
r.roundness
|
|
694
|
-
) : e ===
|
|
704
|
+
) : e === C.NodeCycle ? new G(
|
|
695
705
|
r.color,
|
|
696
706
|
r.width,
|
|
697
707
|
r.arrowLength,
|
|
@@ -711,7 +721,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
|
|
|
711
721
|
r.hasSourceArrow,
|
|
712
722
|
r.hasTargetArrow,
|
|
713
723
|
r.roundness
|
|
714
|
-
),
|
|
724
|
+
), ce = (r) => (e) => e === C.PortCycle ? new B(
|
|
715
725
|
r.color,
|
|
716
726
|
r.width,
|
|
717
727
|
r.arrowLength,
|
|
@@ -720,7 +730,7 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
|
|
|
720
730
|
r.cycleSquareSide,
|
|
721
731
|
r.arrowOffset,
|
|
722
732
|
r.roundness
|
|
723
|
-
) : e ===
|
|
733
|
+
) : e === C.NodeCycle ? new G(
|
|
724
734
|
r.color,
|
|
725
735
|
r.width,
|
|
726
736
|
r.arrowLength,
|
|
@@ -741,9 +751,9 @@ const ae = (r) => (e) => e === A.PortCycle ? new ie(
|
|
|
741
751
|
r.hasTargetArrow,
|
|
742
752
|
r.roundness
|
|
743
753
|
);
|
|
744
|
-
class
|
|
754
|
+
class I {
|
|
745
755
|
constructor(e) {
|
|
746
|
-
|
|
756
|
+
n(this, "counter", 0);
|
|
747
757
|
this.checkExists = e;
|
|
748
758
|
}
|
|
749
759
|
create(e) {
|
|
@@ -757,144 +767,151 @@ class F {
|
|
|
757
767
|
this.counter = 0;
|
|
758
768
|
}
|
|
759
769
|
}
|
|
760
|
-
class
|
|
770
|
+
class f extends Error {
|
|
761
771
|
constructor() {
|
|
762
772
|
super(...arguments);
|
|
763
|
-
|
|
773
|
+
n(this, "name", "HtmlGraphError");
|
|
764
774
|
}
|
|
765
775
|
}
|
|
766
776
|
class le {
|
|
767
|
-
constructor(e, t, s, o, i,
|
|
768
|
-
|
|
777
|
+
constructor(e, t, s, o, i, h, a, d) {
|
|
778
|
+
n(this, "nodeIdGenerator", new I(
|
|
769
779
|
(e) => this.graphStore.getNode(e) !== void 0
|
|
770
780
|
));
|
|
771
|
-
|
|
781
|
+
n(this, "portIdGenerator", new I(
|
|
772
782
|
(e) => this.graphStore.getPort(e) !== void 0
|
|
773
783
|
));
|
|
774
|
-
|
|
784
|
+
n(this, "edgeIdGenerator", new I(
|
|
775
785
|
(e) => this.graphStore.getEdge(e) !== void 0
|
|
776
786
|
));
|
|
777
|
-
this.graphStore = e, this.htmlController = t, this.viewportTransformer = s, this.defaultNodesCenterFn = o, this.defaultPortsCenterFn = i, this.defaultPortsDirection =
|
|
787
|
+
this.graphStore = e, this.htmlController = t, this.viewportTransformer = s, this.defaultNodesCenterFn = o, this.defaultPortsCenterFn = i, this.defaultPortsDirection = h, this.defaultNodesPriorityFn = a, this.defaultEdgesPriorityFn = d;
|
|
778
788
|
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
throw new C("failed to add node with existing id");
|
|
782
|
-
this.graphStore.addNode(
|
|
783
|
-
e,
|
|
784
|
-
t,
|
|
785
|
-
s,
|
|
786
|
-
o,
|
|
787
|
-
n ?? this.defaultNodesCenterFn,
|
|
788
|
-
h ?? this.defaultNodesPriorityFn()
|
|
789
|
-
), this.htmlController.attachNode(e), Array.from(i ?? []).forEach((c) => {
|
|
790
|
-
this.markPort(
|
|
791
|
-
c.id,
|
|
792
|
-
c.element,
|
|
793
|
-
e,
|
|
794
|
-
c.centerFn ?? this.defaultPortsCenterFn,
|
|
795
|
-
c.direction ?? this.defaultPortsDirection
|
|
796
|
-
);
|
|
797
|
-
});
|
|
789
|
+
attach(e) {
|
|
790
|
+
this.htmlController.attach(e);
|
|
798
791
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
if (n === void 0)
|
|
802
|
-
throw new C("failed to update nonexisting node");
|
|
803
|
-
n.x = t ?? n.x, n.y = s ?? n.y, n.centerFn = i ?? n.centerFn, this.htmlController.updateNodeCoordinates(e), o !== void 0 && (n.priority = o, this.htmlController.updateNodePriority(e));
|
|
792
|
+
detach() {
|
|
793
|
+
this.htmlController.detach();
|
|
804
794
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
795
|
+
addNode(e) {
|
|
796
|
+
const t = this.nodeIdGenerator.create(e.nodeId);
|
|
797
|
+
if (this.graphStore.getNode(t) !== void 0)
|
|
798
|
+
throw new f("failed to add node with existing id");
|
|
799
|
+
this.graphStore.addNode({
|
|
800
|
+
nodeId: t,
|
|
801
|
+
element: e.element,
|
|
802
|
+
x: e.x,
|
|
803
|
+
y: e.y,
|
|
804
|
+
centerFn: e.centerFn ?? this.defaultNodesCenterFn,
|
|
805
|
+
priority: e.priority ?? this.defaultNodesPriorityFn()
|
|
806
|
+
}), this.htmlController.attachNode(t), Array.from(e.ports ?? []).forEach((s) => {
|
|
807
|
+
this.markPort({
|
|
808
|
+
portId: s.id,
|
|
809
|
+
element: s.element,
|
|
810
|
+
nodeId: t,
|
|
811
|
+
centerFn: s.centerFn,
|
|
812
|
+
direction: s.direction
|
|
813
|
+
});
|
|
814
|
+
});
|
|
811
815
|
}
|
|
812
|
-
markPort(e
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
t,
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
816
|
+
markPort(e) {
|
|
817
|
+
const t = this.portIdGenerator.create(e.portId);
|
|
818
|
+
if (this.graphStore.getPort(t) !== void 0)
|
|
819
|
+
throw new f("failed to add port with existing id");
|
|
820
|
+
if (this.graphStore.getNode(e.nodeId) === void 0)
|
|
821
|
+
throw new f("failed to set port on nonexisting node");
|
|
822
|
+
this.graphStore.addPort({
|
|
823
|
+
portId: t,
|
|
824
|
+
element: e.element,
|
|
825
|
+
nodeId: e.nodeId,
|
|
826
|
+
centerFn: e.centerFn ?? this.defaultPortsCenterFn,
|
|
827
|
+
direction: e.direction ?? this.defaultPortsDirection
|
|
828
|
+
});
|
|
824
829
|
}
|
|
825
|
-
|
|
826
|
-
const
|
|
827
|
-
if (
|
|
828
|
-
throw new
|
|
829
|
-
|
|
830
|
+
addEdge(e) {
|
|
831
|
+
const t = this.edgeIdGenerator.create(e.edgeId);
|
|
832
|
+
if (this.graphStore.getEdge(t) !== void 0)
|
|
833
|
+
throw new f("failed to add edge with existing id");
|
|
834
|
+
if (this.graphStore.getPort(e.from) === void 0)
|
|
835
|
+
throw new f("failed to add edge from nonexisting port");
|
|
836
|
+
if (this.graphStore.getPort(e.to) === void 0)
|
|
837
|
+
throw new f("failed to add edge to nonexisting port");
|
|
838
|
+
const s = this.resolveEdgeType(e.from, e.to);
|
|
839
|
+
this.graphStore.addEdge({
|
|
840
|
+
edgeId: t,
|
|
841
|
+
from: e.from,
|
|
842
|
+
to: e.to,
|
|
843
|
+
shape: e.shapeFactory(s),
|
|
844
|
+
priority: e.priority ?? this.defaultEdgesPriorityFn()
|
|
845
|
+
}), this.htmlController.attachEdge(t);
|
|
846
|
+
}
|
|
847
|
+
updateEdge(e) {
|
|
848
|
+
const t = this.graphStore.getEdge(e.edgeId);
|
|
849
|
+
if (t === void 0)
|
|
850
|
+
throw new f("failed to update nonexisting edge");
|
|
851
|
+
if (e.shape !== void 0) {
|
|
852
|
+
const s = this.resolveEdgeType(t.from, t.to);
|
|
853
|
+
t.shape = e.shape(s), this.htmlController.updateEdgeShape(e.edgeId);
|
|
854
|
+
}
|
|
855
|
+
e.priority !== void 0 && (t.priority = e.priority, this.htmlController.updateEdgePriority(e.edgeId)), this.htmlController.updateEdge(e.edgeId);
|
|
830
856
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
857
|
+
updatePort(e, t) {
|
|
858
|
+
const s = this.graphStore.getPort(e);
|
|
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);
|
|
863
|
+
});
|
|
837
864
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
const n = this.resolveEdgeType(t, s);
|
|
846
|
-
this.graphStore.addEdge(
|
|
847
|
-
e,
|
|
848
|
-
t,
|
|
849
|
-
s,
|
|
850
|
-
o(n),
|
|
851
|
-
i ?? this.defaultEdgesPriorityFn()
|
|
852
|
-
), this.htmlController.attachEdge(e);
|
|
853
|
-
}
|
|
854
|
-
updateEdge(e, t, s) {
|
|
855
|
-
const o = this.graphStore.getEdge(e);
|
|
856
|
-
if (o === void 0)
|
|
857
|
-
throw new C("failed to update nonexisting edge");
|
|
858
|
-
if (t !== void 0) {
|
|
859
|
-
const i = this.resolveEdgeType(o.from, o.to);
|
|
860
|
-
o.shape = t(i), this.htmlController.updateEdgeShape(e);
|
|
861
|
-
}
|
|
862
|
-
s !== void 0 && (o.priority = s, this.htmlController.updateEdgePriority(e));
|
|
865
|
+
updateNode(e, t) {
|
|
866
|
+
const s = this.graphStore.getNode(e);
|
|
867
|
+
if (s === void 0)
|
|
868
|
+
throw new f("failed to update nonexisting node");
|
|
869
|
+
s.x = (t == null ? void 0 : t.x) ?? s.x, s.y = (t == null ? void 0 : t.y) ?? s.y, s.centerFn = (t == null ? void 0 : t.centerFn) ?? s.centerFn, s.priority = (t == null ? void 0 : t.priority) ?? s.priority, this.htmlController.updateNodeCoordinates(e), this.htmlController.updateNodePriority(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((i) => {
|
|
870
|
+
this.htmlController.updateEdge(i);
|
|
871
|
+
});
|
|
863
872
|
}
|
|
864
873
|
removeEdge(e) {
|
|
865
874
|
if (this.graphStore.getEdge(e) === void 0)
|
|
866
|
-
throw new
|
|
875
|
+
throw new f("failed to remove nonexisting edge");
|
|
867
876
|
this.htmlController.detachEdge(e), this.graphStore.removeEdge(e);
|
|
868
877
|
}
|
|
869
|
-
|
|
870
|
-
this.
|
|
878
|
+
unmarkPort(e) {
|
|
879
|
+
if (this.graphStore.getPort(e) === void 0)
|
|
880
|
+
throw new f("failed to unset nonexisting port");
|
|
881
|
+
this.graphStore.getPortAdjacentEdgeIds(e).forEach((t) => {
|
|
882
|
+
this.removeEdge(t);
|
|
883
|
+
}), this.graphStore.removePort(e);
|
|
871
884
|
}
|
|
872
|
-
|
|
873
|
-
this.
|
|
885
|
+
removeNode(e) {
|
|
886
|
+
if (this.graphStore.getNode(e) === void 0)
|
|
887
|
+
throw new f("failed to remove nonexisting node");
|
|
888
|
+
this.graphStore.getNodePortIds(e).forEach((t) => {
|
|
889
|
+
this.unmarkPort(t);
|
|
890
|
+
}), this.htmlController.detachNode(e), this.graphStore.removeNode(e);
|
|
874
891
|
}
|
|
875
|
-
|
|
876
|
-
this.
|
|
892
|
+
patchViewportMatrix(e) {
|
|
893
|
+
this.viewportTransformer.patchViewportMatrix(e), this.htmlController.applyTransform();
|
|
877
894
|
}
|
|
878
|
-
|
|
879
|
-
this.htmlController.
|
|
895
|
+
patchContentMatrix(e) {
|
|
896
|
+
this.viewportTransformer.patchContentMatrix(e), this.htmlController.applyTransform();
|
|
880
897
|
}
|
|
881
898
|
clear() {
|
|
882
899
|
this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset();
|
|
883
900
|
}
|
|
884
901
|
destroy() {
|
|
885
|
-
this.htmlController.destroy();
|
|
902
|
+
this.clear(), this.htmlController.destroy();
|
|
886
903
|
}
|
|
887
904
|
resolveEdgeType(e, t) {
|
|
888
905
|
if (e === t)
|
|
889
|
-
return
|
|
906
|
+
return C.PortCycle;
|
|
890
907
|
const s = this.graphStore.getPortNodeId(e), o = this.graphStore.getPortNodeId(t);
|
|
891
|
-
return s === o ?
|
|
908
|
+
return s === o ? C.NodeCycle : C.Regular;
|
|
892
909
|
}
|
|
893
910
|
}
|
|
894
|
-
const
|
|
911
|
+
const ge = () => {
|
|
895
912
|
const r = document.createElement("div");
|
|
896
913
|
return r.style.width = "100%", r.style.height = "100%", r.style.position = "relative", r.style.overflow = "hidden", r;
|
|
897
|
-
},
|
|
914
|
+
}, ue = () => {
|
|
898
915
|
const r = document.createElement("div");
|
|
899
916
|
return r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.width = "0", r.style.height = "0", r;
|
|
900
917
|
}, we = () => {
|
|
@@ -902,46 +919,13 @@ const ue = () => {
|
|
|
902
919
|
return r.style.position = "absolute", r.style.top = "0", r.style.left = "0", r.style.visibility = "hidden", r;
|
|
903
920
|
};
|
|
904
921
|
class ye {
|
|
905
|
-
constructor() {
|
|
906
|
-
a(this, "keyMap", /* @__PURE__ */ new Map());
|
|
907
|
-
a(this, "valueMap", /* @__PURE__ */ new Map());
|
|
908
|
-
}
|
|
909
|
-
set(e, t) {
|
|
910
|
-
this.keyMap.set(e, t), this.valueMap.set(t, e);
|
|
911
|
-
}
|
|
912
|
-
getByKey(e) {
|
|
913
|
-
return this.keyMap.get(e);
|
|
914
|
-
}
|
|
915
|
-
getByValue(e) {
|
|
916
|
-
return this.valueMap.get(e);
|
|
917
|
-
}
|
|
918
|
-
deleteByKey(e) {
|
|
919
|
-
const t = this.keyMap.get(e);
|
|
920
|
-
t !== void 0 && this.valueMap.delete(t), this.keyMap.delete(e);
|
|
921
|
-
}
|
|
922
|
-
deleteByValue(e) {
|
|
923
|
-
const t = this.valueMap.get(e);
|
|
924
|
-
t !== void 0 && this.keyMap.delete(t), this.valueMap.delete(e);
|
|
925
|
-
}
|
|
926
|
-
forEach(e) {
|
|
927
|
-
this.keyMap.forEach((t, s) => {
|
|
928
|
-
e(t, s);
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
clear() {
|
|
932
|
-
this.keyMap.clear(), this.valueMap.clear();
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
class me {
|
|
936
922
|
constructor(e, t) {
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
a(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
|
|
944
|
-
this.graphStore = e, this.viewportTransformer = t, this.host.appendChild(this.container), this.nodesResizeObserver = this.createNodesResizeObserver();
|
|
923
|
+
n(this, "canvasWrapper", null);
|
|
924
|
+
n(this, "host", ge());
|
|
925
|
+
n(this, "container", ue());
|
|
926
|
+
n(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
|
|
927
|
+
n(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
|
|
928
|
+
this.graphStore = e, this.viewportTransformer = t, this.host.appendChild(this.container);
|
|
945
929
|
}
|
|
946
930
|
attach(e) {
|
|
947
931
|
this.detach(), this.canvasWrapper = e, this.canvasWrapper.appendChild(this.host);
|
|
@@ -955,15 +939,15 @@ class me {
|
|
|
955
939
|
}
|
|
956
940
|
attachNode(e) {
|
|
957
941
|
const t = this.graphStore.getNode(e), s = we();
|
|
958
|
-
s.appendChild(t.element), this.container.appendChild(s), this.
|
|
942
|
+
s.appendChild(t.element), this.container.appendChild(s), this.nodeIdToWrapperElementMap.set(e, s), this.updateNodeCoordinates(e), this.updateNodePriority(e), s.style.visibility = "visible";
|
|
959
943
|
}
|
|
960
944
|
detachNode(e) {
|
|
961
|
-
const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.
|
|
962
|
-
|
|
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);
|
|
963
947
|
}
|
|
964
948
|
attachEdge(e) {
|
|
965
949
|
const t = this.graphStore.getEdge(e);
|
|
966
|
-
this.edgeIdToElementMap.set(e, t.shape.svg), this.container.appendChild(t.shape.svg), this.
|
|
950
|
+
this.edgeIdToElementMap.set(e, t.shape.svg), this.container.appendChild(t.shape.svg), this.updateEdge(e), this.updateEdgePriority(e);
|
|
967
951
|
}
|
|
968
952
|
detachEdge(e) {
|
|
969
953
|
const t = this.graphStore.getEdge(e);
|
|
@@ -977,104 +961,83 @@ class me {
|
|
|
977
961
|
});
|
|
978
962
|
}
|
|
979
963
|
destroy() {
|
|
980
|
-
this.
|
|
964
|
+
this.clear(), this.detach(), this.host.removeChild(this.container);
|
|
981
965
|
}
|
|
982
966
|
updateNodeCoordinates(e) {
|
|
983
|
-
const t = this.graphStore.
|
|
984
|
-
|
|
985
|
-
this.updateEdgeCoordinates(s);
|
|
986
|
-
});
|
|
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)`;
|
|
987
969
|
}
|
|
988
970
|
updateNodePriority(e) {
|
|
989
|
-
const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.
|
|
971
|
+
const t = this.graphStore.getNode(e), s = this.nodeIdToWrapperElementMap.get(e);
|
|
990
972
|
s.style.zIndex = `${t.priority}`;
|
|
991
973
|
}
|
|
992
974
|
updateEdgeShape(e) {
|
|
993
975
|
const t = this.edgeIdToElementMap.get(e);
|
|
994
976
|
this.container.removeChild(t);
|
|
995
977
|
const s = this.graphStore.getEdge(e);
|
|
996
|
-
this.edgeIdToElementMap.set(e, s.shape.svg), this.container.appendChild(s.shape.svg)
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
const t = this.graphStore.getEdge(e)
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
createNodesResizeObserver() {
|
|
1008
|
-
return new ResizeObserver((e) => {
|
|
1009
|
-
e.forEach((t) => {
|
|
1010
|
-
const s = t.target, o = this.nodeIdToWrapperElementMap.getByValue(s);
|
|
1011
|
-
this.updateNodeCoordinatesInternal(o), this.graphStore.getNodeAdjacentEdgeIds(o).forEach((n) => {
|
|
1012
|
-
this.updateEdgeCoordinates(n);
|
|
1013
|
-
});
|
|
1014
|
-
});
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1017
|
-
updateNodeCoordinatesInternal(e) {
|
|
1018
|
-
const t = this.nodeIdToWrapperElementMap.getByKey(e), { width: s, height: o } = t.getBoundingClientRect(), i = this.viewportTransformer.getViewportMatrix().scale, n = this.graphStore.getNode(e), { x: h, y: c } = n.centerFn(s, o), d = n.x - i * h, g = n.y - i * c;
|
|
1019
|
-
t.style.transform = `matrix(1, 0, 0, 1, ${d}, ${g})`;
|
|
1020
|
-
}
|
|
1021
|
-
updateEdgeCoordinates(e) {
|
|
1022
|
-
const t = this.graphStore.getEdge(e), s = this.graphStore.getPort(t.from), o = this.graphStore.getPort(t.to), i = s.element.getBoundingClientRect(), n = o.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), c = this.viewportTransformer.getViewportMatrix(), d = {
|
|
1023
|
-
x: c.scale * (i.left - h.left) + c.dx,
|
|
1024
|
-
y: c.scale * (i.top - h.top) + c.dy
|
|
1025
|
-
}, g = {
|
|
1026
|
-
x: c.scale * (n.left - h.left) + c.dx,
|
|
1027
|
-
y: c.scale * (n.top - h.top) + c.dy
|
|
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
|
|
1028
987
|
}, w = s.centerFn(
|
|
1029
|
-
i.width *
|
|
1030
|
-
i.height *
|
|
988
|
+
i.width * d.scale,
|
|
989
|
+
i.height * d.scale
|
|
1031
990
|
), m = o.centerFn(
|
|
1032
|
-
|
|
1033
|
-
|
|
991
|
+
h.width * d.scale,
|
|
992
|
+
h.height * d.scale
|
|
1034
993
|
), y = {
|
|
1035
|
-
x:
|
|
1036
|
-
y:
|
|
994
|
+
x: c.x + w.x,
|
|
995
|
+
y: c.y + w.y
|
|
1037
996
|
}, v = {
|
|
1038
|
-
x:
|
|
1039
|
-
y:
|
|
1040
|
-
},
|
|
1041
|
-
t.shape.svg.style.width = `${M}px`, t.shape.svg.style.height = `${b}px`, t.shape.svg.style.transform = `translate(${
|
|
1042
|
-
const T = y.x <= v.x ? 1 : -1,
|
|
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;
|
|
1043
1002
|
t.shape.update(
|
|
1044
1003
|
{ x: M, y: b },
|
|
1045
1004
|
T,
|
|
1046
|
-
|
|
1005
|
+
F,
|
|
1047
1006
|
s.direction,
|
|
1048
1007
|
o.direction
|
|
1049
1008
|
);
|
|
1050
1009
|
}
|
|
1010
|
+
updateEdgePriority(e) {
|
|
1011
|
+
const t = this.graphStore.getEdge(e);
|
|
1012
|
+
t.shape.svg.style.zIndex = `${t.priority}`;
|
|
1013
|
+
}
|
|
1051
1014
|
}
|
|
1052
|
-
class
|
|
1053
|
-
constructor(e
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
const
|
|
1058
|
-
this.publicGraphStore = new ee(
|
|
1059
|
-
|
|
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
|
|
1060
1023
|
);
|
|
1061
|
-
const
|
|
1024
|
+
const o = new ye(s, t);
|
|
1062
1025
|
this.canvasController = new le(
|
|
1063
|
-
h,
|
|
1064
|
-
c,
|
|
1065
|
-
n,
|
|
1066
|
-
e,
|
|
1067
|
-
t,
|
|
1068
1026
|
s,
|
|
1069
1027
|
o,
|
|
1070
|
-
|
|
1028
|
+
t,
|
|
1029
|
+
e.nodesCenterFn,
|
|
1030
|
+
e.portsCenterFn,
|
|
1031
|
+
e.portsDirection,
|
|
1032
|
+
e.nodesPriorityFn,
|
|
1033
|
+
e.edgesPriorityFn
|
|
1071
1034
|
);
|
|
1072
1035
|
}
|
|
1073
1036
|
}
|
|
1074
1037
|
const H = (r, e) => ({
|
|
1075
1038
|
x: r / 2,
|
|
1076
1039
|
y: e / 2
|
|
1077
|
-
}),
|
|
1040
|
+
}), g = {
|
|
1078
1041
|
edgeColor: "#5c5c5c",
|
|
1079
1042
|
edgeWidth: 1,
|
|
1080
1043
|
edgeArrowLength: 15,
|
|
@@ -1094,65 +1057,65 @@ const H = (r, e) => ({
|
|
|
1094
1057
|
return r.factory;
|
|
1095
1058
|
case "straight":
|
|
1096
1059
|
return he({
|
|
1097
|
-
color: r.color ??
|
|
1098
|
-
width: r.width ??
|
|
1099
|
-
arrowLength: r.arrowLength ??
|
|
1100
|
-
arrowWidth: r.arrowWidth ??
|
|
1101
|
-
arrowOffset: r.arrowOffset ??
|
|
1102
|
-
hasSourceArrow: r.hasSourceArrow ??
|
|
1103
|
-
hasTargetArrow: r.hasTargetArrow ??
|
|
1104
|
-
cycleSquareSide: r.cycleSquareSide ??
|
|
1105
|
-
roundness: r.roundness ??
|
|
1106
|
-
detourDistance: r.detourDistance ??
|
|
1107
|
-
detourDirection: r.detourDirection ??
|
|
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
|
|
1108
1071
|
});
|
|
1109
1072
|
case "horizontal":
|
|
1110
|
-
return
|
|
1111
|
-
color: r.color ??
|
|
1112
|
-
width: r.width ??
|
|
1113
|
-
arrowLength: r.arrowLength ??
|
|
1114
|
-
arrowWidth: r.arrowWidth ??
|
|
1115
|
-
arrowOffset: r.arrowOffset ??
|
|
1116
|
-
hasSourceArrow: r.hasSourceArrow ??
|
|
1117
|
-
hasTargetArrow: r.hasTargetArrow ??
|
|
1118
|
-
cycleSquareSide: r.cycleSquareSide ??
|
|
1119
|
-
roundness: r.roundness ??
|
|
1120
|
-
detourDistance: r.detourDistance ??
|
|
1121
|
-
detourDirection: r.detourDirection ??
|
|
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
|
|
1122
1085
|
});
|
|
1123
1086
|
case "vertical":
|
|
1124
|
-
return
|
|
1125
|
-
color: r.color ??
|
|
1126
|
-
width: r.width ??
|
|
1127
|
-
arrowLength: r.arrowLength ??
|
|
1128
|
-
arrowWidth: r.arrowWidth ??
|
|
1129
|
-
arrowOffset: r.arrowOffset ??
|
|
1130
|
-
hasSourceArrow: r.hasSourceArrow ??
|
|
1131
|
-
hasTargetArrow: r.hasTargetArrow ??
|
|
1132
|
-
cycleSquareSide: r.cycleSquareSide ??
|
|
1133
|
-
roundness: r.roundness ??
|
|
1134
|
-
detourDistance: r.detourDistance ??
|
|
1135
|
-
detourDirection: r.detourDirection ??
|
|
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
|
|
1136
1099
|
});
|
|
1137
1100
|
default:
|
|
1138
1101
|
return ae({
|
|
1139
|
-
color: r.color ??
|
|
1140
|
-
width: r.width ??
|
|
1141
|
-
arrowLength: r.arrowLength ??
|
|
1142
|
-
arrowWidth: r.arrowWidth ??
|
|
1143
|
-
hasSourceArrow: r.hasSourceArrow ??
|
|
1144
|
-
hasTargetArrow: r.hasTargetArrow ??
|
|
1145
|
-
cycleRadius: r.cycleRadius ??
|
|
1146
|
-
detourDistance: r.detourDistance ??
|
|
1147
|
-
detourDirection: r.detourDirection ??
|
|
1148
|
-
smallCycleRadius: r.smallCycleRadius ??
|
|
1149
|
-
curvature: r.curvature ??
|
|
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
|
|
1150
1113
|
});
|
|
1151
1114
|
}
|
|
1152
1115
|
}, z = (r) => () => r, U = z(0), k = () => {
|
|
1153
1116
|
let r = 0;
|
|
1154
1117
|
return () => r++;
|
|
1155
|
-
},
|
|
1118
|
+
}, pe = (r, e) => {
|
|
1156
1119
|
const t = [
|
|
1157
1120
|
U,
|
|
1158
1121
|
U
|
|
@@ -1160,9 +1123,9 @@ const H = (r, e) => ({
|
|
|
1160
1123
|
r === "incremental" && (t[0] = k()), e === "incremental" && (t[1] = k());
|
|
1161
1124
|
const s = k();
|
|
1162
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;
|
|
1163
|
-
},
|
|
1164
|
-
var s, o, i,
|
|
1165
|
-
const [e, t] =
|
|
1126
|
+
}, ve = (r) => {
|
|
1127
|
+
var s, o, i, h, a, d;
|
|
1128
|
+
const [e, t] = pe(
|
|
1166
1129
|
(s = r.nodes) == null ? void 0 : s.priority,
|
|
1167
1130
|
(o = r.edges) == null ? void 0 : o.priority
|
|
1168
1131
|
);
|
|
@@ -1172,106 +1135,154 @@ const H = (r, e) => ({
|
|
|
1172
1135
|
priorityFn: e
|
|
1173
1136
|
},
|
|
1174
1137
|
ports: {
|
|
1175
|
-
centerFn: ((
|
|
1176
|
-
direction: ((
|
|
1138
|
+
centerFn: ((h = r.ports) == null ? void 0 : h.centerFn) ?? H,
|
|
1139
|
+
direction: ((a = r.ports) == null ? void 0 : a.direction) ?? 0
|
|
1177
1140
|
},
|
|
1178
1141
|
edges: {
|
|
1179
|
-
shapeFactory: R(((
|
|
1142
|
+
shapeFactory: R(((d = r.edges) == null ? void 0 : d.shape) ?? {}),
|
|
1180
1143
|
priorityFn: t
|
|
1181
1144
|
}
|
|
1182
1145
|
};
|
|
1183
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);
|
|
1163
|
+
}
|
|
1164
|
+
getByValue(e) {
|
|
1165
|
+
return this.valueMap.get(e);
|
|
1166
|
+
}
|
|
1167
|
+
deleteByKey(e) {
|
|
1168
|
+
const t = this.keyMap.get(e);
|
|
1169
|
+
t !== void 0 && this.valueMap.delete(t), this.keyMap.delete(e);
|
|
1170
|
+
}
|
|
1171
|
+
deleteByValue(e) {
|
|
1172
|
+
const t = this.valueMap.get(e);
|
|
1173
|
+
t !== void 0 && this.keyMap.delete(t), this.valueMap.delete(e);
|
|
1174
|
+
}
|
|
1175
|
+
forEach(e) {
|
|
1176
|
+
this.keyMap.forEach((t, s) => {
|
|
1177
|
+
e(t, s);
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
clear() {
|
|
1181
|
+
this.keyMap.clear(), this.valueMap.clear();
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
1184
|
class xe {
|
|
1185
1185
|
constructor(e) {
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
this
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1186
|
+
n(this, "transformation");
|
|
1187
|
+
n(this, "model");
|
|
1188
|
+
n(this, "di");
|
|
1189
|
+
n(this, "edgeShapeFactory");
|
|
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;
|
|
1199
1211
|
}
|
|
1200
1212
|
addNode(e) {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
e.
|
|
1205
|
-
e.
|
|
1206
|
-
e.
|
|
1207
|
-
e.
|
|
1208
|
-
e.
|
|
1209
|
-
|
|
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;
|
|
1210
1223
|
}
|
|
1211
1224
|
updateNode(e, t) {
|
|
1212
|
-
return this.di.canvasController.updateNode(
|
|
1213
|
-
|
|
1214
|
-
t.
|
|
1215
|
-
t.
|
|
1216
|
-
t.
|
|
1217
|
-
|
|
1218
|
-
), this;
|
|
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
|
|
1230
|
+
}), this;
|
|
1219
1231
|
}
|
|
1220
1232
|
removeNode(e) {
|
|
1221
|
-
|
|
1233
|
+
this.di.canvasController.removeNode(e);
|
|
1234
|
+
const t = this.nodes.getByKey(e);
|
|
1235
|
+
if (this.nodes.deleteByKey(e), t === void 0)
|
|
1236
|
+
throw new f("failed to remove non existing node");
|
|
1237
|
+
return this.nodesResizeObserver.unobserve(t), this;
|
|
1222
1238
|
}
|
|
1223
1239
|
markPort(e) {
|
|
1224
|
-
return this.di.canvasController.markPort(
|
|
1225
|
-
e.id,
|
|
1226
|
-
e.element,
|
|
1227
|
-
e.nodeId,
|
|
1228
|
-
e.centerFn,
|
|
1229
|
-
e.direction
|
|
1230
|
-
), this;
|
|
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
|
|
1246
|
+
}), this;
|
|
1231
1247
|
}
|
|
1232
1248
|
updatePort(e, t) {
|
|
1233
|
-
return this.di.canvasController.updatePort(
|
|
1234
|
-
|
|
1235
|
-
t == null ? void 0 : t.
|
|
1236
|
-
|
|
1237
|
-
), this;
|
|
1249
|
+
return this.di.canvasController.updatePort(e, {
|
|
1250
|
+
direction: t == null ? void 0 : t.direction,
|
|
1251
|
+
centerFn: t == null ? void 0 : t.centerFn
|
|
1252
|
+
}), this;
|
|
1238
1253
|
}
|
|
1239
1254
|
unmarkPort(e) {
|
|
1240
1255
|
return this.di.canvasController.unmarkPort(e), this;
|
|
1241
1256
|
}
|
|
1242
1257
|
addEdge(e) {
|
|
1243
1258
|
const t = e.shape !== void 0 ? R(e.shape) : this.edgeShapeFactory;
|
|
1244
|
-
return this.di.canvasController.addEdge(
|
|
1245
|
-
e.id,
|
|
1246
|
-
e.from,
|
|
1247
|
-
e.to,
|
|
1248
|
-
t,
|
|
1249
|
-
e.priority
|
|
1250
|
-
), this;
|
|
1259
|
+
return this.di.canvasController.addEdge({
|
|
1260
|
+
edgeId: e.id,
|
|
1261
|
+
from: e.from,
|
|
1262
|
+
to: e.to,
|
|
1263
|
+
shapeFactory: t,
|
|
1264
|
+
priority: e.priority
|
|
1265
|
+
}), this;
|
|
1251
1266
|
}
|
|
1252
1267
|
updateEdge(e, t) {
|
|
1253
|
-
const s = t.shape !== void 0 ? R(t.shape) : void 0;
|
|
1254
|
-
return this.di.canvasController.updateEdge(
|
|
1268
|
+
const s = (t == null ? void 0 : t.shape) !== void 0 ? R(t.shape) : void 0;
|
|
1269
|
+
return this.di.canvasController.updateEdge({
|
|
1270
|
+
edgeId: e,
|
|
1271
|
+
shape: s,
|
|
1272
|
+
priority: t == null ? void 0 : t.priority
|
|
1273
|
+
}), this;
|
|
1255
1274
|
}
|
|
1256
1275
|
removeEdge(e) {
|
|
1257
1276
|
return this.di.canvasController.removeEdge(e), this;
|
|
1258
1277
|
}
|
|
1259
1278
|
patchViewportMatrix(e) {
|
|
1260
|
-
return this.di.canvasController.patchViewportMatrix(
|
|
1261
|
-
e.scale ?? null,
|
|
1262
|
-
e.dx ?? null,
|
|
1263
|
-
e.dy ?? null
|
|
1264
|
-
), this;
|
|
1279
|
+
return this.di.canvasController.patchViewportMatrix(e), this;
|
|
1265
1280
|
}
|
|
1266
1281
|
patchContentMatrix(e) {
|
|
1267
|
-
return this.di.canvasController.patchContentMatrix(
|
|
1268
|
-
e.scale ?? null,
|
|
1269
|
-
e.dx ?? null,
|
|
1270
|
-
e.dy ?? null
|
|
1271
|
-
), this;
|
|
1282
|
+
return this.di.canvasController.patchContentMatrix(e), this;
|
|
1272
1283
|
}
|
|
1273
1284
|
clear() {
|
|
1274
|
-
return this.di.canvasController.clear(), this;
|
|
1285
|
+
return this.di.canvasController.clear(), this.nodes.clear(), this;
|
|
1275
1286
|
}
|
|
1276
1287
|
attach(e) {
|
|
1277
1288
|
return this.di.canvasController.attach(e), this;
|
|
@@ -1280,48 +1291,48 @@ class xe {
|
|
|
1280
1291
|
return this.di.canvasController.detach(), this;
|
|
1281
1292
|
}
|
|
1282
1293
|
destroy() {
|
|
1283
|
-
this.di.canvasController.destroy();
|
|
1294
|
+
this.clear(), this.di.canvasController.destroy(), this.nodesResizeObserver.disconnect();
|
|
1284
1295
|
}
|
|
1285
1296
|
}
|
|
1286
|
-
const
|
|
1287
|
-
const { x: s, y: o, width: i, height:
|
|
1288
|
-
return e >= s && e < s + i && t >= o && t <= o +
|
|
1289
|
-
},
|
|
1297
|
+
const W = (r, e, t) => {
|
|
1298
|
+
const { x: s, y: o, width: i, height: h } = r.getBoundingClientRect();
|
|
1299
|
+
return e >= s && e < s + i && t >= o && t <= o + h;
|
|
1300
|
+
}, V = (r, e, t) => e >= 0 && e < r.innerWidth && t >= 0 && t <= r.innerHeight, O = (r, e) => {
|
|
1290
1301
|
e !== null ? r.style.cursor = e : r.style.removeProperty("cursor");
|
|
1291
1302
|
};
|
|
1292
1303
|
class Ee {
|
|
1293
1304
|
constructor(e, t) {
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1305
|
+
n(this, "model");
|
|
1306
|
+
n(this, "transformation");
|
|
1307
|
+
n(this, "maxNodePriority", 0);
|
|
1308
|
+
n(this, "nodes", /* @__PURE__ */ new Map());
|
|
1309
|
+
n(this, "grabbedNodeId", null);
|
|
1310
|
+
n(this, "onNodeDrag");
|
|
1311
|
+
n(this, "onBeforeNodeDrag");
|
|
1312
|
+
n(this, "nodeIdGenerator", new I(
|
|
1302
1313
|
(e) => this.nodes.has(e)
|
|
1303
1314
|
));
|
|
1304
|
-
|
|
1305
|
-
|
|
1315
|
+
n(this, "element", null);
|
|
1316
|
+
n(this, "onCanvasMouseUp", () => {
|
|
1306
1317
|
this.cancelMouseDrag();
|
|
1307
1318
|
});
|
|
1308
|
-
|
|
1309
|
-
if (this.element !== null && (!
|
|
1319
|
+
n(this, "onCanvasMouseMove", (e) => {
|
|
1320
|
+
if (this.element !== null && (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY))) {
|
|
1310
1321
|
this.cancelMouseDrag();
|
|
1311
1322
|
return;
|
|
1312
1323
|
}
|
|
1313
1324
|
this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
|
|
1314
1325
|
});
|
|
1315
|
-
|
|
1326
|
+
n(this, "onCanvasTouchStart", (e) => {
|
|
1316
1327
|
this.previousTouchCoords = [
|
|
1317
1328
|
e.touches[0].clientX,
|
|
1318
1329
|
e.touches[0].clientY
|
|
1319
1330
|
];
|
|
1320
1331
|
});
|
|
1321
|
-
|
|
1332
|
+
n(this, "onCanvasTouchMove", (e) => {
|
|
1322
1333
|
if (e.touches.length === 1) {
|
|
1323
1334
|
const t = e.touches[0];
|
|
1324
|
-
if (this.element !== null && (!
|
|
1335
|
+
if (this.element !== null && (!W(this.element, t.clientX, t.clientY) || !V(this.window, t.clientX, t.clientY))) {
|
|
1325
1336
|
this.cancelTouchDrag();
|
|
1326
1337
|
return;
|
|
1327
1338
|
}
|
|
@@ -1335,23 +1346,23 @@ class Ee {
|
|
|
1335
1346
|
}
|
|
1336
1347
|
}
|
|
1337
1348
|
});
|
|
1338
|
-
|
|
1349
|
+
n(this, "onCanvasTouchEnd", (e) => {
|
|
1339
1350
|
e.touches.length > 0 ? this.previousTouchCoords = [
|
|
1340
1351
|
e.touches[0].clientX,
|
|
1341
1352
|
e.touches[0].clientY
|
|
1342
1353
|
] : this.cancelTouchDrag();
|
|
1343
1354
|
});
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
var i,
|
|
1355
|
+
n(this, "previousTouchCoords", null);
|
|
1356
|
+
n(this, "freezePriority");
|
|
1357
|
+
n(this, "window", window);
|
|
1358
|
+
n(this, "dragCursor");
|
|
1359
|
+
var i, h;
|
|
1349
1360
|
this.canvas = e, this.transformation = this.canvas.transformation, this.model = this.canvas.model;
|
|
1350
1361
|
const s = () => {
|
|
1351
1362
|
};
|
|
1352
1363
|
this.onNodeDrag = ((i = t == null ? void 0 : t.events) == null ? void 0 : i.onNodeDrag) ?? s;
|
|
1353
1364
|
const o = () => !0;
|
|
1354
|
-
this.onBeforeNodeDrag = ((
|
|
1365
|
+
this.onBeforeNodeDrag = ((h = t == null ? void 0 : t.events) == null ? void 0 : h.onBeforeNodeDrag) ?? o, this.freezePriority = (t == null ? void 0 : t.grabPriorityStrategy) === "freeze", this.dragCursor = (t == null ? void 0 : t.dragCursor) !== void 0 ? t.dragCursor : "grab";
|
|
1355
1366
|
}
|
|
1356
1367
|
addNode(e) {
|
|
1357
1368
|
const t = this.nodeIdGenerator.create(e.id);
|
|
@@ -1359,20 +1370,20 @@ class Ee {
|
|
|
1359
1370
|
const s = (i) => {
|
|
1360
1371
|
if (this.element === null)
|
|
1361
1372
|
return;
|
|
1362
|
-
const
|
|
1373
|
+
const h = this.model.getNode(t);
|
|
1363
1374
|
this.onBeforeNodeDrag({
|
|
1364
1375
|
nodeId: t,
|
|
1365
1376
|
element: e.element,
|
|
1366
|
-
x:
|
|
1367
|
-
y:
|
|
1368
|
-
}) && (i.stopImmediatePropagation(), this.grabbedNodeId = t,
|
|
1377
|
+
x: h.x,
|
|
1378
|
+
y: h.y
|
|
1379
|
+
}) && (i.stopImmediatePropagation(), this.grabbedNodeId = t, O(this.element, this.dragCursor), this.moveNodeOnTop(t), this.window.addEventListener("mouseup", this.onCanvasMouseUp), this.window.addEventListener("mousemove", this.onCanvasMouseMove));
|
|
1369
1380
|
}, o = (i) => {
|
|
1370
|
-
const
|
|
1381
|
+
const h = this.model.getNode(t);
|
|
1371
1382
|
this.onBeforeNodeDrag({
|
|
1372
1383
|
nodeId: t,
|
|
1373
1384
|
element: e.element,
|
|
1374
|
-
x:
|
|
1375
|
-
y:
|
|
1385
|
+
x: h.x,
|
|
1386
|
+
y: h.y
|
|
1376
1387
|
}) && i.touches.length === 1 && (this.grabbedNodeId = t, this.moveNodeOnTop(t), this.window.addEventListener("touchmove", this.onCanvasTouchMove), this.window.addEventListener("touchend", this.onCanvasTouchEnd), this.window.addEventListener("touchcancel", this.onCanvasTouchEnd));
|
|
1377
1388
|
};
|
|
1378
1389
|
return this.nodes.set(t, {
|
|
@@ -1431,8 +1442,8 @@ class Ee {
|
|
|
1431
1442
|
dragNode(e, t, s) {
|
|
1432
1443
|
const o = this.model.getNode(e);
|
|
1433
1444
|
if (o === null)
|
|
1434
|
-
throw new
|
|
1435
|
-
const i = this.canvas.transformation.getContentMatrix(),
|
|
1445
|
+
throw new f("failed to drag nonexisting node");
|
|
1446
|
+
const i = this.canvas.transformation.getContentMatrix(), h = i.scale * o.x + i.dx, a = i.scale * o.y + i.dy, d = h + t, c = a + s, u = this.canvas.transformation.getViewportMatrix(), w = u.scale * d + u.dx, m = u.scale * c + u.dy;
|
|
1436
1447
|
this.canvas.updateNode(e, { x: w, y: m }), this.onNodeDrag({
|
|
1437
1448
|
nodeId: e,
|
|
1438
1449
|
element: o.element,
|
|
@@ -1454,7 +1465,7 @@ class Ee {
|
|
|
1454
1465
|
});
|
|
1455
1466
|
}
|
|
1456
1467
|
cancelMouseDrag() {
|
|
1457
|
-
this.grabbedNodeId = null, this.element !== null &&
|
|
1468
|
+
this.grabbedNodeId = null, this.element !== null && O(this.element, null), this.removeMouseDragListeners();
|
|
1458
1469
|
}
|
|
1459
1470
|
removeMouseDragListeners() {
|
|
1460
1471
|
this.window.removeEventListener("mouseup", this.onCanvasMouseUp), this.window.removeEventListener("mousemove", this.onCanvasMouseMove);
|
|
@@ -1466,26 +1477,26 @@ class Ee {
|
|
|
1466
1477
|
this.window.removeEventListener("touchmove", this.onCanvasTouchMove), this.window.removeEventListener("touchend", this.onCanvasTouchEnd), this.window.removeEventListener("touchcancel", this.onCanvasTouchEnd);
|
|
1467
1478
|
}
|
|
1468
1479
|
}
|
|
1469
|
-
const
|
|
1470
|
-
},
|
|
1480
|
+
const Ae = () => {
|
|
1481
|
+
}, Ce = (r, e) => e, Pe = (r, e) => {
|
|
1471
1482
|
const t = e !== null ? 1 / e : null, s = r !== null ? 1 / r : null;
|
|
1472
1483
|
return (o, i) => s !== null && i.scale > s && i.scale > o.scale || t !== null && i.scale < t && i.scale < o.scale ? o : i;
|
|
1473
|
-
},
|
|
1474
|
-
let
|
|
1475
|
-
r !== null &&
|
|
1476
|
-
const
|
|
1477
|
-
e !== null &&
|
|
1478
|
-
const w =
|
|
1479
|
-
return s !== null &&
|
|
1484
|
+
}, Se = (r, e, t, s) => (o, i, h, a) => {
|
|
1485
|
+
let d = i.dx, c = i.dy;
|
|
1486
|
+
r !== null && d < r && d < o.dx && (d = o.dx);
|
|
1487
|
+
const u = h * o.scale;
|
|
1488
|
+
e !== null && d > e - u && d > o.dx && (d = o.dx), t !== null && c < t && c < o.dy && (c = o.dy);
|
|
1489
|
+
const w = a * o.scale;
|
|
1490
|
+
return s !== null && c > s - w && c > o.dy && (c = o.dy), { scale: i.scale, dx: d, dy: c };
|
|
1480
1491
|
}, K = (r) => {
|
|
1481
1492
|
switch (r.type) {
|
|
1482
1493
|
case "scale-limit":
|
|
1483
|
-
return
|
|
1494
|
+
return Pe(
|
|
1484
1495
|
r.minContentScale ?? null,
|
|
1485
1496
|
r.maxContentScale ?? null
|
|
1486
1497
|
);
|
|
1487
1498
|
case "shift-limit":
|
|
1488
|
-
return
|
|
1499
|
+
return Se(
|
|
1489
1500
|
r.minX ?? null,
|
|
1490
1501
|
r.maxX ?? null,
|
|
1491
1502
|
r.minY ?? null,
|
|
@@ -1495,53 +1506,53 @@ const Ce = () => {
|
|
|
1495
1506
|
return r.preprocessorFn;
|
|
1496
1507
|
}
|
|
1497
1508
|
}, Me = (r) => (e, t, s, o) => r.reduce(
|
|
1498
|
-
(i,
|
|
1509
|
+
(i, h) => h(e, i, s, o),
|
|
1499
1510
|
t
|
|
1500
1511
|
);
|
|
1501
1512
|
class Ne {
|
|
1502
1513
|
constructor(e, t) {
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
this.element !== null && (
|
|
1514
|
+
n(this, "model");
|
|
1515
|
+
n(this, "transformation");
|
|
1516
|
+
n(this, "element", null);
|
|
1517
|
+
n(this, "prevTouches", null);
|
|
1518
|
+
n(this, "onTransformFinished");
|
|
1519
|
+
n(this, "transformPreprocessor");
|
|
1520
|
+
n(this, "isScalable");
|
|
1521
|
+
n(this, "isShiftable");
|
|
1522
|
+
n(this, "wheelSensitivity");
|
|
1523
|
+
n(this, "window", window);
|
|
1524
|
+
n(this, "onMouseDown", () => {
|
|
1525
|
+
this.element !== null && (O(this.element, this.shiftCursor), this.window.addEventListener("mousemove", this.onMouseMove), this.window.addEventListener("mouseup", this.onMouseUp));
|
|
1515
1526
|
});
|
|
1516
|
-
|
|
1527
|
+
n(this, "onMouseMove", (e) => {
|
|
1517
1528
|
if (!this.isShiftable || this.element === null)
|
|
1518
1529
|
return;
|
|
1519
|
-
if (!
|
|
1530
|
+
if (!W(this.element, e.clientX, e.clientY) || !V(this.window, e.clientX, e.clientY)) {
|
|
1520
1531
|
this.stopMouseDrag();
|
|
1521
1532
|
return;
|
|
1522
1533
|
}
|
|
1523
1534
|
const t = -e.movementX, s = -e.movementY;
|
|
1524
1535
|
this.moveViewport(t, s);
|
|
1525
1536
|
});
|
|
1526
|
-
|
|
1537
|
+
n(this, "onMouseUp", () => {
|
|
1527
1538
|
this.stopMouseDrag();
|
|
1528
1539
|
});
|
|
1529
|
-
|
|
1540
|
+
n(this, "onWheelScroll", (e) => {
|
|
1530
1541
|
if (this.element === null || this.isScalable === !1)
|
|
1531
1542
|
return;
|
|
1532
1543
|
e.preventDefault();
|
|
1533
|
-
const { left: t, top: s } = this.element.getBoundingClientRect(), o = e.clientX - t, i = e.clientY - s,
|
|
1534
|
-
this.scaleViewport(
|
|
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);
|
|
1535
1546
|
});
|
|
1536
|
-
|
|
1547
|
+
n(this, "onTouchStart", (e) => {
|
|
1537
1548
|
this.prevTouches = this.getAverageTouch(e), this.window.addEventListener("touchmove", this.onTouchMove), this.window.addEventListener("touchend", this.onTouchEnd), this.window.addEventListener("touchcancel", this.onTouchEnd);
|
|
1538
1549
|
});
|
|
1539
|
-
|
|
1550
|
+
n(this, "onTouchMove", (e) => {
|
|
1540
1551
|
if (this.prevTouches === null || !this.isShiftable || this.element === null)
|
|
1541
1552
|
return;
|
|
1542
1553
|
const t = this.getAverageTouch(e);
|
|
1543
1554
|
if (!t.touches.every(
|
|
1544
|
-
(o) =>
|
|
1555
|
+
(o) => W(this.element, o[0], o[1]) && V(this.window, o[0], o[1])
|
|
1545
1556
|
)) {
|
|
1546
1557
|
this.stopTouchDrag();
|
|
1547
1558
|
return;
|
|
@@ -1550,15 +1561,15 @@ class Ne {
|
|
|
1550
1561
|
-(t.x - this.prevTouches.x),
|
|
1551
1562
|
-(t.y - this.prevTouches.y)
|
|
1552
1563
|
), t.touchesCnt === 2 && this.isScalable) {
|
|
1553
|
-
const { left: o, top: i } = this.element.getBoundingClientRect(),
|
|
1554
|
-
this.scaleViewport(
|
|
1564
|
+
const { left: o, top: i } = this.element.getBoundingClientRect(), h = this.prevTouches.x - o, a = this.prevTouches.y - i, c = 1 / (t.scale / this.prevTouches.scale);
|
|
1565
|
+
this.scaleViewport(c, h, a);
|
|
1555
1566
|
}
|
|
1556
1567
|
this.prevTouches = t;
|
|
1557
1568
|
});
|
|
1558
|
-
|
|
1569
|
+
n(this, "onTouchEnd", (e) => {
|
|
1559
1570
|
e.touches.length > 0 ? this.prevTouches = this.getAverageTouch(e) : this.stopTouchDrag();
|
|
1560
1571
|
});
|
|
1561
|
-
|
|
1572
|
+
n(this, "observer", new ResizeObserver(() => {
|
|
1562
1573
|
if (this.element !== null) {
|
|
1563
1574
|
const e = this.canvas.transformation.getViewportMatrix(), { width: t, height: s } = this.element.getBoundingClientRect(), o = this.transformPreprocessor(
|
|
1564
1575
|
e,
|
|
@@ -1569,17 +1580,17 @@ class Ne {
|
|
|
1569
1580
|
this.canvas.patchViewportMatrix(o), this.onTransformFinished();
|
|
1570
1581
|
}
|
|
1571
1582
|
}));
|
|
1572
|
-
|
|
1573
|
-
var i,
|
|
1574
|
-
this.canvas = e, this.options = t, this.transformation = this.canvas.transformation, this.model = this.canvas.model, this.isScalable = ((
|
|
1575
|
-
const s = (
|
|
1576
|
-
this.wheelSensitivity = s !== void 0 ? s : 1.2, this.onTransformFinished = ((w = t == null ? void 0 : t.events) == null ? void 0 : w.onTransformFinished) ??
|
|
1583
|
+
n(this, "shiftCursor");
|
|
1584
|
+
var i, h, a, d, c, u, w, m;
|
|
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;
|
|
1577
1588
|
const o = t == null ? void 0 : t.transformPreprocessor;
|
|
1578
1589
|
o !== void 0 ? Array.isArray(o) ? this.transformPreprocessor = Me(
|
|
1579
1590
|
o.map(
|
|
1580
1591
|
(y) => K(y)
|
|
1581
1592
|
)
|
|
1582
|
-
) : this.transformPreprocessor = K(o) : this.transformPreprocessor =
|
|
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";
|
|
1583
1594
|
}
|
|
1584
1595
|
addNode(e) {
|
|
1585
1596
|
return this.canvas.addNode(e), this;
|
|
@@ -1628,19 +1639,19 @@ class Ne {
|
|
|
1628
1639
|
}
|
|
1629
1640
|
getAverageTouch(e) {
|
|
1630
1641
|
const t = [], s = e.touches.length;
|
|
1631
|
-
for (let
|
|
1632
|
-
t.push([e.touches[
|
|
1642
|
+
for (let d = 0; d < s; d++)
|
|
1643
|
+
t.push([e.touches[d].clientX, e.touches[d].clientY]);
|
|
1633
1644
|
const o = t.reduce(
|
|
1634
|
-
(
|
|
1645
|
+
(d, c) => [d[0] + c[0], d[1] + c[1]],
|
|
1635
1646
|
[0, 0]
|
|
1636
|
-
), i = [o[0] / s, o[1] / s],
|
|
1637
|
-
(
|
|
1647
|
+
), i = [o[0] / s, o[1] / s], a = t.map((d) => [d[0] - i[0], d[1] - i[1]]).reduce(
|
|
1648
|
+
(d, c) => d + Math.sqrt(c[0] * c[0] + c[1] * c[1]),
|
|
1638
1649
|
0
|
|
1639
1650
|
);
|
|
1640
1651
|
return {
|
|
1641
1652
|
x: i[0],
|
|
1642
1653
|
y: i[1],
|
|
1643
|
-
scale:
|
|
1654
|
+
scale: a / s,
|
|
1644
1655
|
touchesCnt: s,
|
|
1645
1656
|
touches: t
|
|
1646
1657
|
};
|
|
@@ -1652,13 +1663,13 @@ class Ne {
|
|
|
1652
1663
|
dy: s.dy + s.scale * t
|
|
1653
1664
|
};
|
|
1654
1665
|
if (this.element !== null) {
|
|
1655
|
-
const { width: i, height:
|
|
1666
|
+
const { width: i, height: h } = this.element.getBoundingClientRect(), a = this.transformPreprocessor(
|
|
1656
1667
|
s,
|
|
1657
1668
|
o,
|
|
1658
1669
|
i,
|
|
1659
|
-
|
|
1670
|
+
h
|
|
1660
1671
|
);
|
|
1661
|
-
this.canvas.patchViewportMatrix(
|
|
1672
|
+
this.canvas.patchViewportMatrix(a), this.onTransformFinished();
|
|
1662
1673
|
}
|
|
1663
1674
|
}
|
|
1664
1675
|
scaleViewport(e, t, s) {
|
|
@@ -1668,16 +1679,16 @@ class Ne {
|
|
|
1668
1679
|
scale: o.scale * e,
|
|
1669
1680
|
dx: o.scale * (1 - e) * t + o.dx,
|
|
1670
1681
|
dy: o.scale * (1 - e) * s + o.dy
|
|
1671
|
-
}, { width:
|
|
1682
|
+
}, { width: h, height: a } = this.element.getBoundingClientRect(), d = this.transformPreprocessor(
|
|
1672
1683
|
o,
|
|
1673
1684
|
i,
|
|
1674
|
-
|
|
1675
|
-
|
|
1685
|
+
h,
|
|
1686
|
+
a
|
|
1676
1687
|
);
|
|
1677
|
-
this.canvas.patchViewportMatrix(
|
|
1688
|
+
this.canvas.patchViewportMatrix(d), this.onTransformFinished();
|
|
1678
1689
|
}
|
|
1679
1690
|
stopMouseDrag() {
|
|
1680
|
-
this.element !== null &&
|
|
1691
|
+
this.element !== null && O(this.element, null), this.removeMouseDragListeners();
|
|
1681
1692
|
}
|
|
1682
1693
|
removeMouseDragListeners() {
|
|
1683
1694
|
this.window.removeEventListener("mousemove", this.onMouseMove), this.window.removeEventListener("mouseup", this.onMouseUp);
|
|
@@ -1691,11 +1702,11 @@ class Ne {
|
|
|
1691
1702
|
}
|
|
1692
1703
|
class Te {
|
|
1693
1704
|
constructor() {
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1705
|
+
n(this, "coreOptions");
|
|
1706
|
+
n(this, "dragOptions");
|
|
1707
|
+
n(this, "transformOptions");
|
|
1708
|
+
n(this, "isDraggable", !1);
|
|
1709
|
+
n(this, "isTransformable", !1);
|
|
1699
1710
|
}
|
|
1700
1711
|
setOptions(e) {
|
|
1701
1712
|
return this.coreOptions = e, this;
|
|
@@ -1718,16 +1729,16 @@ export {
|
|
|
1718
1729
|
B as CycleSquareEdgeShape,
|
|
1719
1730
|
ne as DetourBezierEdgeShape,
|
|
1720
1731
|
G as DetourStraightEdgeShape,
|
|
1721
|
-
|
|
1732
|
+
C as EdgeType,
|
|
1722
1733
|
se as HorizontalEdgeShape,
|
|
1723
1734
|
Te as HtmlGraphBuilder,
|
|
1724
|
-
|
|
1735
|
+
f as HtmlGraphError,
|
|
1725
1736
|
re as StraightEdgeShape,
|
|
1726
1737
|
Ee as UserDraggableNodesCanvas,
|
|
1727
1738
|
Ne as UserTransformableCanvas,
|
|
1728
1739
|
oe as VerticalEdgeShape,
|
|
1729
1740
|
ae as createBezierEdgeShapeFactory,
|
|
1730
|
-
|
|
1741
|
+
ce as createHorizontalEdgeShapeFactory,
|
|
1731
1742
|
he as createStraightEdgeShareFactory,
|
|
1732
|
-
|
|
1743
|
+
de as createVerticalEdgeShapeFactory
|
|
1733
1744
|
};
|