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