@html-graph/html-graph 0.0.48 → 0.0.50
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 +8 -8
- package/dist/main.d.ts +185 -193
- package/dist/main.js +693 -606
- package/dist/main.umd.cjs +1 -1
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
class
|
|
5
|
-
constructor(t, e,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
1
|
+
var j = Object.defineProperty;
|
|
2
|
+
var R = (r, t, e) => t in r ? j(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var n = (r, t, e) => R(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
class W {
|
|
5
|
+
constructor(t, e, s, o, a) {
|
|
6
|
+
n(this, "canvasWrapper", null);
|
|
7
|
+
n(this, "host");
|
|
8
|
+
n(this, "nodesContainer");
|
|
9
|
+
n(this, "edgesContainer");
|
|
10
|
+
n(this, "canvas");
|
|
11
|
+
n(this, "canvasCtx");
|
|
12
|
+
n(this, "hostResizeObserver");
|
|
13
|
+
n(this, "nodesResizeObserver");
|
|
14
|
+
n(this, "nodeElementToIdMap", /* @__PURE__ */ new Map());
|
|
15
|
+
n(this, "nodeWrapperElementToIdMap", /* @__PURE__ */ new Map());
|
|
16
|
+
n(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
|
|
17
|
+
n(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
|
|
18
|
+
n(this, "currentZIndex", 0);
|
|
19
|
+
n(this, "layers", {
|
|
20
|
+
"edges-on-top": {
|
|
21
21
|
create: () => {
|
|
22
|
-
this.host.appendChild(this.nodesContainer), this.host.appendChild(this.
|
|
22
|
+
this.host.appendChild(this.nodesContainer), this.host.appendChild(this.edgesContainer);
|
|
23
23
|
},
|
|
24
|
-
update: (t, e,
|
|
25
|
-
this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${
|
|
24
|
+
update: (t, e, s) => {
|
|
25
|
+
this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`, this.edgesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`;
|
|
26
26
|
},
|
|
27
27
|
moveOnTop: (t) => {
|
|
28
28
|
this.currentZIndex += 1;
|
|
@@ -30,26 +30,26 @@ class j {
|
|
|
30
30
|
e.style.zIndex = `${this.currentZIndex}`;
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"
|
|
33
|
+
"edges-follow-node": {
|
|
34
34
|
create: () => {
|
|
35
|
-
this.host.appendChild(this.nodesContainer), this.
|
|
35
|
+
this.host.appendChild(this.nodesContainer), this.edgesContainer = this.nodesContainer;
|
|
36
36
|
},
|
|
37
|
-
update: (t, e,
|
|
38
|
-
this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${
|
|
37
|
+
update: (t, e, s) => {
|
|
38
|
+
this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`;
|
|
39
39
|
},
|
|
40
40
|
moveOnTop: (t) => {
|
|
41
41
|
const e = this.nodeIdToWrapperElementMap.get(t);
|
|
42
|
-
this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.graphStore.
|
|
43
|
-
this.
|
|
42
|
+
this.currentZIndex += 2, e.style.zIndex = `${this.currentZIndex}`, this.graphStore.getNodeAdjacentEdges(t).forEach((o) => {
|
|
43
|
+
this.edgeIdToElementMap.get(o).style.zIndex = `${this.currentZIndex - 1}`;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"nodes-on-top": {
|
|
48
48
|
create: () => {
|
|
49
|
-
this.host.appendChild(this.
|
|
49
|
+
this.host.appendChild(this.edgesContainer), this.host.appendChild(this.nodesContainer);
|
|
50
50
|
},
|
|
51
|
-
update: (t, e,
|
|
52
|
-
this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${
|
|
51
|
+
update: (t, e, s) => {
|
|
52
|
+
this.nodesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`, this.edgesContainer.style.transform = `matrix(${t}, 0, 0, ${t}, ${e}, ${s})`;
|
|
53
53
|
},
|
|
54
54
|
moveOnTop: (t) => {
|
|
55
55
|
this.currentZIndex += 1;
|
|
@@ -58,63 +58,63 @@ class j {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer =
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
61
|
+
this.graphStore = t, this.viewportTransformer = e, this.publicViewportTransformer = s, this.layersMode = o, this.backgroundDrawingFn = a, this.host = this.createHost(), this.canvas = this.createCanvas(), this.nodesContainer = this.createNodesContainer(), this.edgesContainer = this.createEdgesContainer();
|
|
62
|
+
const c = this.canvas.getContext("2d");
|
|
63
|
+
if (c === null)
|
|
64
64
|
throw new Error("unable to get canvas context");
|
|
65
|
-
this.canvasCtx =
|
|
65
|
+
this.canvasCtx = c, this.host.appendChild(this.canvas), this.layers[this.layersMode].create(), this.hostResizeObserver = this.createHostResizeObserver(), this.hostResizeObserver.observe(this.host), this.nodesResizeObserver = this.createNodesResizeObserver();
|
|
66
66
|
}
|
|
67
67
|
clear() {
|
|
68
|
-
Array.from(this.
|
|
69
|
-
this.
|
|
68
|
+
Array.from(this.edgeIdToElementMap.keys()).forEach((t) => {
|
|
69
|
+
this.detachEdge(t);
|
|
70
70
|
}), Array.from(this.nodeElementToIdMap.values()).forEach((t) => {
|
|
71
71
|
this.detachNode(t);
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
attach(t) {
|
|
75
|
-
this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
|
|
75
|
+
this.detach(), this.canvasWrapper = t, this.canvasWrapper.appendChild(this.host);
|
|
76
76
|
}
|
|
77
77
|
detach() {
|
|
78
78
|
this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
|
|
79
79
|
}
|
|
80
80
|
destroy() {
|
|
81
|
-
this.hostResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.
|
|
81
|
+
this.hostResizeObserver.disconnect(), this.nodesResizeObserver.disconnect(), this.host.removeChild(this.canvas), this.host.removeChild(this.edgesContainer), this.host.removeChild(this.nodesContainer), this.canvasWrapper !== null && (this.canvasWrapper.removeChild(this.host), this.canvasWrapper = null);
|
|
82
82
|
}
|
|
83
83
|
applyTransform() {
|
|
84
84
|
this.backgroundDrawingFn(this.canvasCtx, this.publicViewportTransformer);
|
|
85
|
-
const [t, e] = this.viewportTransformer.getViewCoords(0, 0),
|
|
86
|
-
this.layers[this.layersMode].update(
|
|
85
|
+
const [t, e] = this.viewportTransformer.getViewCoords(0, 0), s = this.viewportTransformer.getViewScale();
|
|
86
|
+
this.layers[this.layersMode].update(s, t, e);
|
|
87
87
|
}
|
|
88
88
|
attachNode(t) {
|
|
89
|
-
const e = this.graphStore.getNode(t),
|
|
90
|
-
|
|
89
|
+
const e = this.graphStore.getNode(t), s = document.createElement("div");
|
|
90
|
+
s.appendChild(e.element), s.style.position = "absolute", s.style.top = "0", s.style.left = "0", s.style.zIndex = `${this.currentZIndex}`, this.currentZIndex += 1, s.style.visibility = "hidden", this.nodesContainer.appendChild(s), this.nodeElementToIdMap.set(e.element, t), this.nodeWrapperElementToIdMap.set(s, t), this.nodeIdToWrapperElementMap.set(t, s), this.updateNodeCoords(t, e.x, e.y), this.nodesResizeObserver.observe(s), s.style.visibility = "visible";
|
|
91
91
|
}
|
|
92
92
|
detachNode(t) {
|
|
93
93
|
const e = this.graphStore.getNode(t);
|
|
94
94
|
this.nodesResizeObserver.unobserve(e.element), this.nodesContainer.removeChild(e.element);
|
|
95
|
-
const
|
|
96
|
-
|
|
95
|
+
const s = this.nodeIdToWrapperElementMap.get(t);
|
|
96
|
+
s.removeChild(e.element), this.nodeElementToIdMap.delete(e.element), this.nodeWrapperElementToIdMap.delete(s), this.nodeIdToWrapperElementMap.delete(t);
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
98
|
+
attachEdge(t) {
|
|
99
|
+
const s = this.graphStore.getEdge(t).controller.svg;
|
|
100
|
+
s.style.transformOrigin = "50% 50%", s.style.position = "absolute", s.style.top = "0", s.style.left = "0", s.style.zIndex = `${this.currentZIndex}`, this.currentZIndex += 1, this.edgeIdToElementMap.set(t, s), this.updateEdgeCoords(t), this.edgesContainer.appendChild(s);
|
|
101
101
|
}
|
|
102
|
-
|
|
103
|
-
const e = this.
|
|
104
|
-
this.
|
|
102
|
+
detachEdge(t) {
|
|
103
|
+
const e = this.edgeIdToElementMap.get(t);
|
|
104
|
+
this.edgeIdToElementMap.delete(t), this.edgesContainer.removeChild(e);
|
|
105
105
|
}
|
|
106
106
|
moveNodeOnTop(t) {
|
|
107
107
|
this.layers[this.layersMode].moveOnTop(t);
|
|
108
108
|
}
|
|
109
109
|
updateNodeCoordinates(t) {
|
|
110
|
-
const e = this.graphStore.getNode(t),
|
|
111
|
-
this.updateNodeCoords(t, e.x, e.y),
|
|
112
|
-
this.
|
|
110
|
+
const e = this.graphStore.getNode(t), s = this.graphStore.getNodeAdjacentEdges(t);
|
|
111
|
+
this.updateNodeCoords(t, e.x, e.y), s.forEach((o) => {
|
|
112
|
+
this.updateEdgeCoords(o);
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
this.graphStore.
|
|
117
|
-
this.
|
|
115
|
+
updatePortEdges(t) {
|
|
116
|
+
this.graphStore.getPortAdjacentEdges(t).forEach((s) => {
|
|
117
|
+
this.updateEdgeCoords(s);
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
getViewportDimensions() {
|
|
@@ -133,7 +133,7 @@ class j {
|
|
|
133
133
|
const t = document.createElement("div");
|
|
134
134
|
return t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.width = "0", t.style.height = "0", t;
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
createEdgesContainer() {
|
|
137
137
|
const t = document.createElement("div");
|
|
138
138
|
return t.style.position = "absolute", t.style.pointerEvents = "none", t.style.top = "0", t.style.left = "0", t.style.width = "0", t.style.height = "0", t;
|
|
139
139
|
}
|
|
@@ -145,9 +145,9 @@ class j {
|
|
|
145
145
|
createNodesResizeObserver() {
|
|
146
146
|
return new ResizeObserver((t) => {
|
|
147
147
|
t.forEach((e) => {
|
|
148
|
-
const
|
|
149
|
-
this.updateNodeCoords(
|
|
150
|
-
this.
|
|
148
|
+
const s = e.target, o = this.nodeWrapperElementToIdMap.get(s), a = this.graphStore.getNode(o);
|
|
149
|
+
this.updateNodeCoords(o, a.x, a.y), this.graphStore.getNodeAdjacentEdges(o).forEach((h) => {
|
|
150
|
+
this.updateEdgeCoords(h);
|
|
151
151
|
});
|
|
152
152
|
});
|
|
153
153
|
});
|
|
@@ -156,30 +156,30 @@ class j {
|
|
|
156
156
|
const { width: t, height: e } = this.host.getBoundingClientRect();
|
|
157
157
|
this.canvas.width = t, this.canvas.height = e;
|
|
158
158
|
}
|
|
159
|
-
updateNodeCoords(t, e,
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const e = this.graphStore.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
), [g,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
),
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
), [
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
),
|
|
177
|
-
|
|
159
|
+
updateNodeCoords(t, e, s) {
|
|
160
|
+
const o = this.nodeIdToWrapperElementMap.get(t), { width: a, height: c } = o.getBoundingClientRect(), h = this.viewportTransformer.getAbsScale(), i = this.graphStore.getNode(t), [d, g] = i.centerFn(a, c);
|
|
161
|
+
o.style.transform = `matrix(1, 0, 0, 1, ${e - h * d}, ${s - h * g})`;
|
|
162
|
+
}
|
|
163
|
+
updateEdgeCoords(t) {
|
|
164
|
+
const e = this.graphStore.getEdge(t), s = this.graphStore.getPort(e.from), o = this.graphStore.getPort(e.to), a = s.element.getBoundingClientRect(), c = o.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), [i, d] = this.viewportTransformer.getAbsCoords(
|
|
165
|
+
a.left - h.left,
|
|
166
|
+
a.top - h.top
|
|
167
|
+
), [g, l] = this.viewportTransformer.getAbsCoords(
|
|
168
|
+
c.left - h.left,
|
|
169
|
+
c.top - h.top
|
|
170
|
+
), u = this.viewportTransformer.getAbsScale(), [v, m] = s.centerFn(
|
|
171
|
+
a.width * u,
|
|
172
|
+
a.height * u
|
|
173
|
+
), [w, f] = o.centerFn(
|
|
174
|
+
c.width * u,
|
|
175
|
+
c.height * u
|
|
176
|
+
), C = v + i, E = m + d, b = w + g, $ = f + l, y = Math.min(C, b), T = Math.min(E, $), S = Math.abs(b - C), N = Math.abs($ - E);
|
|
177
|
+
e.controller.update(y, T, S, N, s, o);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
class
|
|
180
|
+
class B {
|
|
181
181
|
constructor() {
|
|
182
|
-
|
|
182
|
+
n(this, "state", {
|
|
183
183
|
scale: 1,
|
|
184
184
|
x: 0,
|
|
185
185
|
y: 0
|
|
@@ -203,15 +203,15 @@ class D {
|
|
|
203
203
|
getAbsScale() {
|
|
204
204
|
return this.state.scale;
|
|
205
205
|
}
|
|
206
|
-
patchState(t, e,
|
|
206
|
+
patchState(t, e, s) {
|
|
207
207
|
this.state = {
|
|
208
208
|
scale: t ?? this.state.scale,
|
|
209
209
|
x: e ?? this.state.x,
|
|
210
|
-
y:
|
|
210
|
+
y: s ?? this.state.y
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
|
-
class
|
|
214
|
+
class z {
|
|
215
215
|
constructor(t) {
|
|
216
216
|
this.transformer = t;
|
|
217
217
|
}
|
|
@@ -244,22 +244,19 @@ class W {
|
|
|
244
244
|
return this.transformer.getAbsScale();
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
-
class
|
|
247
|
+
class Y {
|
|
248
248
|
constructor() {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
261
|
-
addNode(t, e, o, n, i) {
|
|
262
|
-
this.nodes[t] = { element: e, x: o, y: n, centerFn: i }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
|
|
249
|
+
n(this, "nodes", /* @__PURE__ */ Object.create(null));
|
|
250
|
+
n(this, "ports", /* @__PURE__ */ Object.create(null));
|
|
251
|
+
n(this, "nodePorts", /* @__PURE__ */ Object.create(null));
|
|
252
|
+
n(this, "portNodeId", /* @__PURE__ */ Object.create(null));
|
|
253
|
+
n(this, "edges", /* @__PURE__ */ Object.create(null));
|
|
254
|
+
n(this, "incommingEdges", /* @__PURE__ */ Object.create(null));
|
|
255
|
+
n(this, "outcommingEdges", /* @__PURE__ */ Object.create(null));
|
|
256
|
+
n(this, "cycleEdges", /* @__PURE__ */ Object.create(null));
|
|
257
|
+
}
|
|
258
|
+
addNode(t, e, s, o, a) {
|
|
259
|
+
this.nodes[t] = { element: e, x: s, y: o, centerFn: a }, this.nodePorts[t] = /* @__PURE__ */ Object.create(null);
|
|
263
260
|
}
|
|
264
261
|
hasNode(t) {
|
|
265
262
|
return this.nodes[t] !== void 0;
|
|
@@ -267,25 +264,25 @@ class R {
|
|
|
267
264
|
getNode(t) {
|
|
268
265
|
return this.nodes[t];
|
|
269
266
|
}
|
|
270
|
-
updateNodeCoords(t, e,
|
|
271
|
-
this.nodes[t].x = e, this.nodes[t].y =
|
|
267
|
+
updateNodeCoords(t, e, s) {
|
|
268
|
+
this.nodes[t].x = e, this.nodes[t].y = s;
|
|
272
269
|
}
|
|
273
|
-
|
|
274
|
-
this.
|
|
270
|
+
updateEdgeController(t, e) {
|
|
271
|
+
this.edges[t].controller = e;
|
|
275
272
|
}
|
|
276
273
|
removeNode(t) {
|
|
277
|
-
this.
|
|
278
|
-
this.
|
|
274
|
+
this.getNodeAdjacentEdges(t).forEach((o) => {
|
|
275
|
+
this.removeEdge(o);
|
|
279
276
|
}), delete this.nodes[t];
|
|
280
|
-
const
|
|
281
|
-
Object.keys(
|
|
282
|
-
delete this.portNodeId[
|
|
277
|
+
const s = this.nodePorts[t];
|
|
278
|
+
Object.keys(s).forEach((o) => {
|
|
279
|
+
delete this.portNodeId[o];
|
|
283
280
|
}), delete this.nodePorts[t];
|
|
284
281
|
}
|
|
285
|
-
addPort(t, e,
|
|
286
|
-
this.ports[t] = { element: e, centerFn:
|
|
287
|
-
const
|
|
288
|
-
|
|
282
|
+
addPort(t, e, s, o, a) {
|
|
283
|
+
this.ports[t] = { element: e, centerFn: o, direction: a }, this.cycleEdges[t] = {}, this.incommingEdges[t] = {}, this.outcommingEdges[t] = {}, this.portNodeId[t] = s;
|
|
284
|
+
const c = this.nodePorts[s];
|
|
285
|
+
c !== void 0 && (c[t] = e);
|
|
289
286
|
}
|
|
290
287
|
getPort(t) {
|
|
291
288
|
return this.ports[t];
|
|
@@ -297,295 +294,357 @@ class R {
|
|
|
297
294
|
return this.portNodeId[t] !== void 0;
|
|
298
295
|
}
|
|
299
296
|
removePort(t) {
|
|
300
|
-
Object.keys(this.
|
|
301
|
-
this.
|
|
302
|
-
}), delete this.
|
|
303
|
-
this.
|
|
304
|
-
}), delete this.
|
|
305
|
-
this.
|
|
306
|
-
}), delete this.
|
|
297
|
+
Object.keys(this.cycleEdges[t]).forEach((o) => {
|
|
298
|
+
this.removeEdge(o);
|
|
299
|
+
}), delete this.cycleEdges[t], Object.keys(this.incommingEdges[t]).forEach((o) => {
|
|
300
|
+
this.removeEdge(o);
|
|
301
|
+
}), delete this.incommingEdges[t], Object.keys(this.outcommingEdges[t]).forEach((o) => {
|
|
302
|
+
this.removeEdge(o);
|
|
303
|
+
}), delete this.outcommingEdges[t];
|
|
307
304
|
const e = this.portNodeId[t];
|
|
308
305
|
delete this.portNodeId[t];
|
|
309
|
-
const
|
|
310
|
-
delete
|
|
306
|
+
const s = this.nodePorts[e];
|
|
307
|
+
delete s[t], delete this.ports[t];
|
|
311
308
|
}
|
|
312
|
-
|
|
313
|
-
this.
|
|
309
|
+
addEdge(t, e, s, o) {
|
|
310
|
+
this.edges[t] = {
|
|
314
311
|
from: e,
|
|
315
|
-
to:
|
|
316
|
-
controller:
|
|
317
|
-
}, e !==
|
|
312
|
+
to: s,
|
|
313
|
+
controller: o
|
|
314
|
+
}, e !== s ? (this.outcommingEdges[e][t] = !0, this.incommingEdges[s][t] = !0) : this.cycleEdges[e][t] = !0;
|
|
318
315
|
}
|
|
319
|
-
|
|
320
|
-
return this.
|
|
316
|
+
getEdge(t) {
|
|
317
|
+
return this.edges[t];
|
|
321
318
|
}
|
|
322
|
-
|
|
323
|
-
return this.
|
|
319
|
+
hasEdge(t) {
|
|
320
|
+
return this.edges[t] !== void 0;
|
|
324
321
|
}
|
|
325
|
-
|
|
326
|
-
const e = this.
|
|
327
|
-
delete this.
|
|
322
|
+
removeEdge(t) {
|
|
323
|
+
const e = this.edges[t], s = e.from, o = e.to;
|
|
324
|
+
delete this.cycleEdges[s][t], delete this.cycleEdges[o][t], delete this.incommingEdges[s][t], delete this.incommingEdges[o][t], delete this.outcommingEdges[s][t], delete this.outcommingEdges[o][t], delete this.edges[t];
|
|
328
325
|
}
|
|
329
|
-
|
|
326
|
+
getPortAdjacentEdges(t) {
|
|
330
327
|
return [
|
|
331
|
-
...this.
|
|
332
|
-
...this.
|
|
333
|
-
...this.
|
|
328
|
+
...this.getPortIncomingEdges(t),
|
|
329
|
+
...this.getPortOutcomingEdges(t),
|
|
330
|
+
...this.getPortCycleEdges(t)
|
|
334
331
|
];
|
|
335
332
|
}
|
|
336
|
-
|
|
333
|
+
getNodeAdjacentEdges(t) {
|
|
337
334
|
return [
|
|
338
|
-
...this.
|
|
339
|
-
...this.
|
|
340
|
-
...this.
|
|
335
|
+
...this.getNodeIncomingEdges(t),
|
|
336
|
+
...this.getNodeOutcomingEdges(t),
|
|
337
|
+
...this.getNodeCycleEdges(t)
|
|
341
338
|
];
|
|
342
339
|
}
|
|
343
340
|
clear() {
|
|
344
|
-
this.nodes = /* @__PURE__ */ Object.create(null), this.ports = /* @__PURE__ */ Object.create(null), this.nodePorts = /* @__PURE__ */ Object.create(null), this.portNodeId = /* @__PURE__ */ Object.create(null), this.
|
|
341
|
+
this.nodes = /* @__PURE__ */ Object.create(null), this.ports = /* @__PURE__ */ Object.create(null), this.nodePorts = /* @__PURE__ */ Object.create(null), this.portNodeId = /* @__PURE__ */ Object.create(null), this.edges = /* @__PURE__ */ Object.create(null), this.incommingEdges = /* @__PURE__ */ Object.create(null), this.outcommingEdges = /* @__PURE__ */ Object.create(null), this.cycleEdges = /* @__PURE__ */ Object.create(null);
|
|
345
342
|
}
|
|
346
|
-
|
|
347
|
-
return Object.keys(this.
|
|
343
|
+
getPortIncomingEdges(t) {
|
|
344
|
+
return Object.keys(this.incommingEdges[t] ?? {});
|
|
348
345
|
}
|
|
349
|
-
|
|
350
|
-
return Object.keys(this.
|
|
346
|
+
getPortOutcomingEdges(t) {
|
|
347
|
+
return Object.keys(this.outcommingEdges[t] ?? {});
|
|
351
348
|
}
|
|
352
|
-
|
|
353
|
-
return Object.keys(this.
|
|
349
|
+
getPortCycleEdges(t) {
|
|
350
|
+
return Object.keys(this.cycleEdges[t] ?? {});
|
|
354
351
|
}
|
|
355
|
-
|
|
352
|
+
getNodeIncomingEdges(t) {
|
|
356
353
|
const e = Object.keys(this.nodePorts[t]);
|
|
357
|
-
let
|
|
358
|
-
return e.forEach((
|
|
359
|
-
|
|
360
|
-
}),
|
|
354
|
+
let s = [];
|
|
355
|
+
return e.forEach((o) => {
|
|
356
|
+
s = [...s, ...this.getPortIncomingEdges(o)];
|
|
357
|
+
}), s;
|
|
361
358
|
}
|
|
362
|
-
|
|
359
|
+
getNodeOutcomingEdges(t) {
|
|
363
360
|
const e = Object.keys(this.nodePorts[t]);
|
|
364
|
-
let
|
|
365
|
-
return e.forEach((
|
|
366
|
-
|
|
367
|
-
}),
|
|
361
|
+
let s = [];
|
|
362
|
+
return e.forEach((o) => {
|
|
363
|
+
s = [...s, ...this.getPortOutcomingEdges(o)];
|
|
364
|
+
}), s;
|
|
368
365
|
}
|
|
369
|
-
|
|
366
|
+
getNodeCycleEdges(t) {
|
|
370
367
|
const e = Object.keys(this.nodePorts[t]);
|
|
371
|
-
let
|
|
372
|
-
return e.forEach((
|
|
373
|
-
|
|
374
|
-
}),
|
|
368
|
+
let s = [];
|
|
369
|
+
return e.forEach((o) => {
|
|
370
|
+
s = [...s, ...this.getPortCycleEdges(o)];
|
|
371
|
+
}), s;
|
|
375
372
|
}
|
|
376
373
|
}
|
|
377
|
-
class
|
|
378
|
-
constructor(t) {
|
|
379
|
-
this.graphStore = t;
|
|
380
|
-
}
|
|
381
|
-
getNode(t) {
|
|
382
|
-
const e = this.graphStore.getNode(t);
|
|
383
|
-
return e === void 0 ? null : { x: e.x, y: e.y, element: e.element };
|
|
384
|
-
}
|
|
385
|
-
getNodes(t) {
|
|
386
|
-
const e = Object.entries(this.graphStore.getAllNodes()).map(
|
|
387
|
-
([o, n]) => ({
|
|
388
|
-
id: o,
|
|
389
|
-
x: n.x,
|
|
390
|
-
y: n.y,
|
|
391
|
-
element: n.element
|
|
392
|
-
})
|
|
393
|
-
);
|
|
394
|
-
if (t !== void 0) {
|
|
395
|
-
const o = /* @__PURE__ */ new Set();
|
|
396
|
-
return t.forEach((n) => {
|
|
397
|
-
o.add(n);
|
|
398
|
-
}), e.filter((n) => o.has(n.id));
|
|
399
|
-
}
|
|
400
|
-
return e;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
class v {
|
|
374
|
+
class p {
|
|
404
375
|
static getPortCenter(t) {
|
|
405
|
-
const { top: e, left:
|
|
406
|
-
return [
|
|
376
|
+
const { top: e, left: s, width: o, height: a } = t.element.getBoundingClientRect(), c = t.centerFn(o, a);
|
|
377
|
+
return [s + c[0], e + c[1]];
|
|
407
378
|
}
|
|
408
|
-
static rotate(t, e,
|
|
379
|
+
static rotate(t, e, s) {
|
|
409
380
|
return [
|
|
410
|
-
e[0] * t[0] - e[1] * t[1] + ((1 - e[0]) *
|
|
411
|
-
e[1] * t[0] + e[0] * t[1] + ((1 - e[0]) *
|
|
381
|
+
e[0] * t[0] - e[1] * t[1] + ((1 - e[0]) * s[0] + e[1] * s[1]),
|
|
382
|
+
e[1] * t[0] + e[0] * t[1] + ((1 - e[0]) * s[1] - e[1] * s[0])
|
|
412
383
|
];
|
|
413
384
|
}
|
|
414
|
-
static getDirectionVector(t, e,
|
|
415
|
-
return [e * Math.cos(t ?? 0),
|
|
385
|
+
static getDirectionVector(t, e, s) {
|
|
386
|
+
return [e * Math.cos(t ?? 0), s * Math.sin(t ?? 0)];
|
|
416
387
|
}
|
|
417
|
-
static getArrowPath(t, e,
|
|
418
|
-
const
|
|
388
|
+
static getArrowPath(t, e, s, o, a) {
|
|
389
|
+
const h = [
|
|
419
390
|
[0, 0],
|
|
420
|
-
[
|
|
421
|
-
[
|
|
422
|
-
].map((
|
|
423
|
-
return `${
|
|
424
|
-
}
|
|
425
|
-
static getArrowOffsetPath(t, e,
|
|
426
|
-
const
|
|
427
|
-
[
|
|
428
|
-
[
|
|
429
|
-
].map((
|
|
430
|
-
return `M ${
|
|
391
|
+
[o, a],
|
|
392
|
+
[o, -a]
|
|
393
|
+
].map((l) => this.rotate(l, t, [0, 0])).map((l) => [l[0] + e, l[1] + s]), i = `M ${h[0][0]} ${h[0][1]}`, d = `L ${h[1][0]} ${h[1][1]}`, g = `L ${h[2][0]} ${h[2][1]}`;
|
|
394
|
+
return `${i} ${d} ${g}`;
|
|
395
|
+
}
|
|
396
|
+
static getArrowOffsetPath(t, e, s, o, a) {
|
|
397
|
+
const h = [
|
|
398
|
+
[o, 0],
|
|
399
|
+
[o + a, 0]
|
|
400
|
+
].map((i) => this.rotate(i, t, [0, 0])).map((i) => [i[0] + e, i[1] + s]);
|
|
401
|
+
return `M ${h[0][0]} ${h[0][1]} L ${h[1][0]} ${h[1][1]}`;
|
|
402
|
+
}
|
|
403
|
+
static createStraightPath(t) {
|
|
404
|
+
return t.map((e, s) => `${s === 0 ? "M" : "L"} ${e[0]} ${e[1]}`).join(" ");
|
|
431
405
|
}
|
|
432
406
|
}
|
|
433
407
|
class G {
|
|
434
|
-
constructor(t, e, o,
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
this.color = t, this.width = e, this.curvature =
|
|
408
|
+
constructor(t, e, s, o, a, c, h) {
|
|
409
|
+
n(this, "svg");
|
|
410
|
+
n(this, "group");
|
|
411
|
+
n(this, "line");
|
|
412
|
+
n(this, "sourceArrow", null);
|
|
413
|
+
n(this, "targetArrow", null);
|
|
414
|
+
this.color = t, this.width = e, this.curvature = s, this.arrowLength = o, this.arrowWidth = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", c && (this.sourceArrow = document.createElementNS(
|
|
441
415
|
"http://www.w3.org/2000/svg",
|
|
442
416
|
"path"
|
|
443
|
-
), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)),
|
|
417
|
+
), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = document.createElementNS(
|
|
444
418
|
"http://www.w3.org/2000/svg",
|
|
445
419
|
"path"
|
|
446
420
|
), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
|
|
447
421
|
}
|
|
448
|
-
update(t, e,
|
|
449
|
-
this.svg.style.width = `${
|
|
450
|
-
const
|
|
451
|
-
this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${
|
|
452
|
-
const d =
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
[o - this.arrowLength, n],
|
|
466
|
-
m,
|
|
467
|
-
[o, n]
|
|
468
|
-
), C = [
|
|
469
|
-
u[0] + d[0] * this.curvature,
|
|
470
|
-
u[1] + d[1] * this.curvature
|
|
471
|
-
], w = [
|
|
472
|
-
p[0] - m[0] * this.curvature,
|
|
473
|
-
p[1] - m[1] * this.curvature
|
|
474
|
-
], b = `M ${u[0]} ${u[1]}`, T = `C ${C[0]} ${C[1]}, ${w[0]} ${w[1]}, ${p[0]} ${p[1]}`, S = `M 0 0 L ${u[0]} ${u[1]} `, f = ` M ${p[0]} ${p[1]} L ${o} ${n}`, y = `${this.sourceArrow ? "" : S}${b} ${T}${this.targetArrow ? "" : f}`;
|
|
475
|
-
if (this.line.setAttribute("d", y), this.sourceArrow) {
|
|
476
|
-
const N = v.getArrowPath(
|
|
477
|
-
d,
|
|
422
|
+
update(t, e, s, o, a, c) {
|
|
423
|
+
this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`;
|
|
424
|
+
const h = p.getPortCenter(a), i = p.getPortCenter(c), d = h[0] <= i[0] ? 1 : -1, g = h[1] <= i[1] ? 1 : -1;
|
|
425
|
+
this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${d}, ${g})`;
|
|
426
|
+
const l = p.getDirectionVector(a.direction, d, g), u = p.getDirectionVector(c.direction, d, g), v = p.rotate([this.arrowLength, 0], l, [0, 0]), m = p.rotate([s - this.arrowLength, o], u, [
|
|
427
|
+
s,
|
|
428
|
+
o
|
|
429
|
+
]), w = [
|
|
430
|
+
v[0] + l[0] * this.curvature,
|
|
431
|
+
v[1] + l[1] * this.curvature
|
|
432
|
+
], f = [
|
|
433
|
+
m[0] - u[0] * this.curvature,
|
|
434
|
+
m[1] - u[1] * this.curvature
|
|
435
|
+
], C = `M ${v[0]} ${v[1]} C ${w[0]} ${w[1]}, ${f[0]} ${f[1]}, ${m[0]} ${m[1]}`, E = this.sourceArrow ? "" : `M 0 0 L ${v[0]} ${v[1]} `, b = this.targetArrow ? "" : ` M ${m[0]} ${m[1]} L ${s} ${o}`, $ = `${E}${C}${b}`;
|
|
436
|
+
if (this.line.setAttribute("d", $), this.sourceArrow) {
|
|
437
|
+
const y = p.getArrowPath(
|
|
438
|
+
l,
|
|
478
439
|
0,
|
|
479
440
|
0,
|
|
480
441
|
this.arrowLength,
|
|
481
442
|
this.arrowWidth
|
|
482
443
|
);
|
|
483
|
-
this.sourceArrow.setAttribute("d",
|
|
444
|
+
this.sourceArrow.setAttribute("d", y);
|
|
484
445
|
}
|
|
485
446
|
if (this.targetArrow) {
|
|
486
|
-
const
|
|
487
|
-
|
|
447
|
+
const y = p.getArrowPath(
|
|
448
|
+
u,
|
|
449
|
+
s,
|
|
488
450
|
o,
|
|
489
|
-
n,
|
|
490
451
|
-this.arrowLength,
|
|
491
452
|
this.arrowWidth
|
|
492
453
|
);
|
|
493
|
-
this.targetArrow.setAttribute("d",
|
|
454
|
+
this.targetArrow.setAttribute("d", y);
|
|
494
455
|
}
|
|
495
456
|
}
|
|
496
457
|
}
|
|
497
|
-
|
|
498
|
-
s
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
)
|
|
506
|
-
class Y {
|
|
507
|
-
constructor(t, e, o, n, i, h, a) {
|
|
508
|
-
r(this, "svg");
|
|
509
|
-
r(this, "group");
|
|
510
|
-
r(this, "line");
|
|
511
|
-
r(this, "sourceArrow", null);
|
|
512
|
-
r(this, "targetArrow", null);
|
|
513
|
-
this.color = t, this.width = e, this.arrowLength = o, this.arrowWidth = n, this.minPortOffset = i, this.hasSourceArrow = h, this.hasTargetArrow = a, this.svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"), this.svg.style.pointerEvents = "none", this.group = document.createElementNS("http://www.w3.org/2000/svg", "g"), this.svg.appendChild(this.group), this.line = document.createElementNS("http://www.w3.org/2000/svg", "path"), this.line.setAttribute("stroke", this.color), this.line.setAttribute("stroke-width", `${this.width}`), this.line.setAttribute("fill", "none"), this.group.appendChild(this.line), this.group.style.transformOrigin = "50% 50%", this.hasSourceArrow && (this.sourceArrow = document.createElementNS(
|
|
458
|
+
class X {
|
|
459
|
+
constructor(t, e, s, o, a, c, h, i) {
|
|
460
|
+
n(this, "svg");
|
|
461
|
+
n(this, "group");
|
|
462
|
+
n(this, "line");
|
|
463
|
+
n(this, "sourceArrow", null);
|
|
464
|
+
n(this, "targetArrow", null);
|
|
465
|
+
n(this, "roundness");
|
|
466
|
+
this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.arrowOffset = a, this.roundness = Math.min(this.arrowOffset, 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%", c && (this.sourceArrow = document.createElementNS(
|
|
514
467
|
"http://www.w3.org/2000/svg",
|
|
515
468
|
"path"
|
|
516
|
-
), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)),
|
|
469
|
+
), this.sourceArrow.setAttribute("fill", this.color), this.group.appendChild(this.sourceArrow)), h && (this.targetArrow = document.createElementNS(
|
|
517
470
|
"http://www.w3.org/2000/svg",
|
|
518
471
|
"path"
|
|
519
472
|
), this.targetArrow.setAttribute("fill", this.color), this.group.appendChild(this.targetArrow)), this.svg.style.overflow = "visible";
|
|
520
473
|
}
|
|
521
|
-
update(t, e,
|
|
522
|
-
this.svg.style.width = `${
|
|
523
|
-
const
|
|
524
|
-
this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${
|
|
525
|
-
const d =
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
[0
|
|
537
|
-
|
|
538
|
-
[
|
|
539
|
-
|
|
540
|
-
[
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
this.arrowLength,
|
|
546
|
-
this.minPortOffset
|
|
547
|
-
), y = v.getArrowOffsetPath(
|
|
548
|
-
m,
|
|
549
|
-
o,
|
|
550
|
-
n,
|
|
551
|
-
-this.arrowLength,
|
|
552
|
-
-this.minPortOffset
|
|
553
|
-
), N = `${this.sourceArrow ? f : T}${b}${this.targetArrow ? y : S}`;
|
|
554
|
-
if (this.line.setAttribute("d", N), this.sourceArrow) {
|
|
555
|
-
const E = v.getArrowPath(
|
|
556
|
-
d,
|
|
474
|
+
update(t, e, s, o, a, c) {
|
|
475
|
+
this.svg.style.width = `${s}px`, this.svg.style.height = `${o}px`;
|
|
476
|
+
const h = p.getPortCenter(a), i = p.getPortCenter(c), d = h[0] <= i[0] ? 1 : -1, g = h[1] <= i[1] ? 1 : -1;
|
|
477
|
+
this.svg.style.transform = `translate(${t}px, ${e}px)`, this.group.style.transform = `scale(${d}, ${g})`;
|
|
478
|
+
const l = p.getDirectionVector(a.direction, d, g), u = p.getDirectionVector(c.direction, d, g), v = this.sourceArrow ? p.rotate([this.arrowLength, 0], l, [0, 0]) : [0, 0], m = this.targetArrow ? p.rotate([s - this.arrowLength, o], u, [
|
|
479
|
+
s,
|
|
480
|
+
o
|
|
481
|
+
]) : [s, o], w = this.arrowLength + this.arrowOffset, f = w - this.roundness, C = s - w * 2 * d, E = Math.sqrt(C * C + o * o) / 2, b = Math.min(this.roundness, E), $ = p.rotate([f, 0], l, [0, 0]), y = p.rotate([s - f, o], u, [
|
|
482
|
+
s,
|
|
483
|
+
o
|
|
484
|
+
]), T = p.rotate([w, 0], l, [0, 0]), S = p.rotate([s - w, o], u, [
|
|
485
|
+
s,
|
|
486
|
+
o
|
|
487
|
+
]), N = (S[0] - T[0]) / 2, L = (S[1] - T[1]) / 2, A = b / E, O = [T[0] + N * A, T[1] + L * A], V = [S[0] - N * A, S[1] - L * A], k = [
|
|
488
|
+
`M ${v[0]} ${v[1]}`,
|
|
489
|
+
`L ${$[0]} ${$[1]}`,
|
|
490
|
+
`C ${T[0]} ${T[1]} ${T[0]} ${T[1]} ${O[0]} ${O[1]}`,
|
|
491
|
+
`L ${V[0]} ${V[1]}`,
|
|
492
|
+
`C ${S[0]} ${S[1]} ${S[0]} ${S[1]} ${y[0]} ${y[1]}`,
|
|
493
|
+
`L ${m[0]} ${m[1]}`
|
|
494
|
+
].join(" ");
|
|
495
|
+
if (this.line.setAttribute("d", k), this.sourceArrow) {
|
|
496
|
+
const P = p.getArrowPath(
|
|
497
|
+
l,
|
|
557
498
|
0,
|
|
558
499
|
0,
|
|
559
500
|
this.arrowLength,
|
|
560
501
|
this.arrowWidth
|
|
561
502
|
);
|
|
562
|
-
this.sourceArrow.setAttribute("d",
|
|
503
|
+
this.sourceArrow.setAttribute("d", P);
|
|
563
504
|
}
|
|
564
505
|
if (this.targetArrow) {
|
|
565
|
-
const
|
|
566
|
-
|
|
506
|
+
const P = p.getArrowPath(
|
|
507
|
+
u,
|
|
508
|
+
s,
|
|
567
509
|
o,
|
|
568
|
-
n,
|
|
569
510
|
-this.arrowLength,
|
|
570
511
|
this.arrowWidth
|
|
571
512
|
);
|
|
572
|
-
this.targetArrow.setAttribute("d",
|
|
513
|
+
this.targetArrow.setAttribute("d", P);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
class Z {
|
|
518
|
+
constructor(t, e, s, o, a, c, h) {
|
|
519
|
+
n(this, "svg");
|
|
520
|
+
n(this, "group");
|
|
521
|
+
n(this, "line");
|
|
522
|
+
n(this, "arrow", null);
|
|
523
|
+
this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.radius = c, this.smallRadius = 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.arrow = document.createElementNS(
|
|
524
|
+
"http://www.w3.org/2000/svg",
|
|
525
|
+
"path"
|
|
526
|
+
), 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";
|
|
527
|
+
}
|
|
528
|
+
update(t, e, s, o, a) {
|
|
529
|
+
this.svg.style.transform = `translate(${t}px, ${e}px)`;
|
|
530
|
+
const c = p.getDirectionVector(a.direction, 1, 1), h = this.smallRadius, i = this.radius, d = Math.sqrt(h * h + i * i), g = h + i, l = this.arrowLength + d * (1 - i / g), u = h * i / g, m = [
|
|
531
|
+
[this.arrowLength, 0],
|
|
532
|
+
[l, u],
|
|
533
|
+
[l, -u]
|
|
534
|
+
].map((E) => p.rotate(E, c, [0, 0])), w = [
|
|
535
|
+
`M ${m[0][0]} ${m[0][1]}`,
|
|
536
|
+
`A ${h} ${h} 0 0 1 ${m[1][0]} ${m[1][1]}`,
|
|
537
|
+
`A ${i} ${i} 0 1 0 ${m[2][0]} ${m[2][1]}`,
|
|
538
|
+
`A ${h} ${h} 0 0 1 ${m[0][0]} ${m[0][1]}`
|
|
539
|
+
].join(" "), f = `M 0 0 L ${m[0][0]} ${m[0][1]} `, C = `${this.arrow !== null ? "" : f}${w}`;
|
|
540
|
+
if (this.line.setAttribute("d", C), this.arrow) {
|
|
541
|
+
const E = p.getArrowPath(
|
|
542
|
+
c,
|
|
543
|
+
0,
|
|
544
|
+
0,
|
|
545
|
+
this.arrowLength,
|
|
546
|
+
this.arrowWidth
|
|
547
|
+
);
|
|
548
|
+
this.arrow.setAttribute("d", E);
|
|
573
549
|
}
|
|
574
550
|
}
|
|
575
551
|
}
|
|
576
|
-
|
|
577
|
-
s
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
552
|
+
class U {
|
|
553
|
+
constructor(t, e, s, o, a, c, h, i) {
|
|
554
|
+
n(this, "svg");
|
|
555
|
+
n(this, "group");
|
|
556
|
+
n(this, "line");
|
|
557
|
+
n(this, "arrow", null);
|
|
558
|
+
n(this, "roundness");
|
|
559
|
+
n(this, "points");
|
|
560
|
+
this.color = t, this.width = e, this.arrowLength = s, this.arrowWidth = o, this.side = c, this.minPortOffset = h, this.roundness = Math.min(i, this.minPortOffset, this.side / 2), 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.arrow = document.createElementNS(
|
|
561
|
+
"http://www.w3.org/2000/svg",
|
|
562
|
+
"path"
|
|
563
|
+
), 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";
|
|
564
|
+
const d = this.minPortOffset, g = this.side, l = this.arrowLength + d, u = this.roundness, v = l - u, m = l + u, w = g - u, f = l + 2 * g, C = f - u;
|
|
565
|
+
console.log(u), this.points = [
|
|
566
|
+
[this.arrowLength, 0],
|
|
567
|
+
[v, 0],
|
|
568
|
+
[l, u],
|
|
569
|
+
[l, w],
|
|
570
|
+
[m, g],
|
|
571
|
+
[C, g],
|
|
572
|
+
[f, w],
|
|
573
|
+
[f, -w],
|
|
574
|
+
[C, -g],
|
|
575
|
+
[m, -g],
|
|
576
|
+
[l, -w],
|
|
577
|
+
[l, -u]
|
|
578
|
+
];
|
|
579
|
+
}
|
|
580
|
+
update(t, e, s, o, a) {
|
|
581
|
+
this.svg.style.transform = `translate(${t}px, ${e}px)`;
|
|
582
|
+
const c = p.getDirectionVector(a.direction, 1, 1), h = this.roundness, i = this.points.map((u) => p.rotate(u, c, [0, 0])), d = [
|
|
583
|
+
`M ${i[0][0]} ${i[0][1]}`,
|
|
584
|
+
`L ${i[1][0]} ${i[1][1]}`,
|
|
585
|
+
`A ${h} ${h} 0 0 1 ${i[2][0]} ${i[2][1]}`,
|
|
586
|
+
`L ${i[3][0]} ${i[3][1]}`,
|
|
587
|
+
`A ${h} ${h} 0 0 0 ${i[4][0]} ${i[4][1]}`,
|
|
588
|
+
`L ${i[5][0]} ${i[5][1]}`,
|
|
589
|
+
`A ${h} ${h} 0 0 0 ${i[6][0]} ${i[6][1]}`,
|
|
590
|
+
`L ${i[7][0]} ${i[7][1]}`,
|
|
591
|
+
`A ${h} ${h} 0 0 0 ${i[8][0]} ${i[8][1]}`,
|
|
592
|
+
`L ${i[9][0]} ${i[9][1]}`,
|
|
593
|
+
`A ${h} ${h} 0 0 0 ${i[10][0]} ${i[10][1]}`,
|
|
594
|
+
`L ${i[11][0]} ${i[11][1]}`,
|
|
595
|
+
`A ${h} ${h} 0 0 1 ${i[1][0]} ${i[1][1]}`
|
|
596
|
+
].join(" "), g = `M 0 0 L ${i[0][0]} ${i[0][1]} `, l = `${this.arrow ? "" : g}${d}`;
|
|
597
|
+
if (this.line.setAttribute("d", l), this.arrow) {
|
|
598
|
+
const u = p.getArrowPath(
|
|
599
|
+
c,
|
|
600
|
+
0,
|
|
601
|
+
0,
|
|
602
|
+
this.arrowLength,
|
|
603
|
+
this.arrowWidth
|
|
604
|
+
);
|
|
605
|
+
this.arrow.setAttribute("d", u);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
var M = /* @__PURE__ */ ((r) => (r.Regular = "regular", r.Cycle = "cycle", r))(M || {});
|
|
610
|
+
const H = (r) => (t) => t === "cycle" ? new Z(
|
|
611
|
+
r.color,
|
|
612
|
+
r.width,
|
|
613
|
+
r.arrowLength,
|
|
614
|
+
r.arrowWidth,
|
|
615
|
+
r.hasSourceArrow || r.hasTargetArrow,
|
|
616
|
+
r.cycleRadius,
|
|
617
|
+
r.smallCycleRadius
|
|
618
|
+
) : new G(
|
|
619
|
+
r.color,
|
|
620
|
+
r.width,
|
|
621
|
+
r.curvature,
|
|
622
|
+
r.arrowLength,
|
|
623
|
+
r.arrowWidth,
|
|
624
|
+
r.hasSourceArrow,
|
|
625
|
+
r.hasTargetArrow
|
|
626
|
+
), q = (r) => (t) => t === M.Cycle && t === "cycle" ? new U(
|
|
627
|
+
r.color,
|
|
628
|
+
r.width,
|
|
629
|
+
r.arrowLength,
|
|
630
|
+
r.arrowWidth,
|
|
631
|
+
r.hasSourceArrow || r.hasTargetArrow,
|
|
632
|
+
r.cycleSquareSide,
|
|
633
|
+
r.arrowOffset,
|
|
634
|
+
r.roundness
|
|
635
|
+
) : new X(
|
|
636
|
+
r.color,
|
|
637
|
+
r.width,
|
|
638
|
+
r.arrowLength,
|
|
639
|
+
r.arrowWidth,
|
|
640
|
+
r.arrowOffset,
|
|
641
|
+
r.hasSourceArrow,
|
|
642
|
+
r.hasTargetArrow,
|
|
643
|
+
r.roundness
|
|
584
644
|
);
|
|
585
|
-
|
|
586
|
-
class A {
|
|
645
|
+
class x {
|
|
587
646
|
constructor() {
|
|
588
|
-
|
|
647
|
+
n(this, "counter", 0);
|
|
589
648
|
}
|
|
590
649
|
next() {
|
|
591
650
|
const t = `${this.counter}`;
|
|
@@ -595,19 +654,19 @@ class A {
|
|
|
595
654
|
this.counter = 0;
|
|
596
655
|
}
|
|
597
656
|
}
|
|
598
|
-
class
|
|
599
|
-
constructor(t, e,
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
this.graphStore = t, this.htmlController = e, this.viewportTransformer =
|
|
657
|
+
class _ {
|
|
658
|
+
constructor(t, e, s, o, a) {
|
|
659
|
+
n(this, "nodeIdGenerator", new x());
|
|
660
|
+
n(this, "portIdGenerator", new x());
|
|
661
|
+
n(this, "edgeIdGenerator", new x());
|
|
662
|
+
this.graphStore = t, this.htmlController = e, this.viewportTransformer = s, this.nodesCenterFn = o, this.portsCenterFn = a;
|
|
604
663
|
}
|
|
605
664
|
moveNodeOnTop(t) {
|
|
606
665
|
if (!this.graphStore.hasNode(t))
|
|
607
666
|
throw new Error("failed to move on top nonexisting node");
|
|
608
667
|
this.htmlController.moveNodeOnTop(t);
|
|
609
668
|
}
|
|
610
|
-
addNode(t, e,
|
|
669
|
+
addNode(t, e, s, o, a, c) {
|
|
611
670
|
if (t === void 0)
|
|
612
671
|
do
|
|
613
672
|
t = this.nodeIdGenerator.next();
|
|
@@ -617,98 +676,99 @@ class Z {
|
|
|
617
676
|
this.graphStore.addNode(
|
|
618
677
|
t,
|
|
619
678
|
e,
|
|
679
|
+
s,
|
|
620
680
|
o,
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
c.element,
|
|
681
|
+
c ?? this.nodesCenterFn
|
|
682
|
+
), this.htmlController.attachNode(t), a !== void 0 && Object.entries(a).forEach(([h, i]) => {
|
|
683
|
+
i instanceof HTMLElement ? this.markPort(h, i, t, this.portsCenterFn, null) : this.markPort(
|
|
684
|
+
h,
|
|
685
|
+
i.element,
|
|
627
686
|
t,
|
|
628
|
-
|
|
629
|
-
|
|
687
|
+
i.centerFn ?? this.portsCenterFn,
|
|
688
|
+
i.direction ?? null
|
|
630
689
|
);
|
|
631
690
|
});
|
|
632
691
|
}
|
|
633
|
-
markPort(t, e,
|
|
692
|
+
markPort(t, e, s, o, a) {
|
|
634
693
|
if (t === void 0)
|
|
635
694
|
do
|
|
636
695
|
t = this.portIdGenerator.next();
|
|
637
696
|
while (this.graphStore.hasPort(t));
|
|
638
|
-
if (!this.graphStore.hasNode(
|
|
697
|
+
if (!this.graphStore.hasNode(s))
|
|
639
698
|
throw new Error("failed to set port on nonexisting node");
|
|
640
699
|
if (this.graphStore.hasPort(t))
|
|
641
700
|
throw new Error("failed to add port with existing id");
|
|
642
701
|
this.graphStore.addPort(
|
|
643
702
|
t,
|
|
644
703
|
e,
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
704
|
+
s,
|
|
705
|
+
o ?? this.portsCenterFn,
|
|
706
|
+
a ?? null
|
|
648
707
|
);
|
|
649
708
|
}
|
|
650
|
-
|
|
709
|
+
updatePortEdges(t) {
|
|
651
710
|
if (!this.graphStore.hasPort(t))
|
|
652
711
|
throw new Error("failed to unset nonexisting port");
|
|
653
|
-
this.htmlController.
|
|
712
|
+
this.htmlController.updatePortEdges(t);
|
|
654
713
|
}
|
|
655
714
|
unmarkPort(t) {
|
|
656
715
|
if (!this.graphStore.hasPort(t))
|
|
657
716
|
throw new Error("failed to unset nonexisting port");
|
|
658
|
-
this.graphStore.
|
|
659
|
-
this.
|
|
717
|
+
this.graphStore.getPortAdjacentEdges(t).forEach((e) => {
|
|
718
|
+
this.removeEdge(e);
|
|
660
719
|
}), this.graphStore.removePort(t);
|
|
661
720
|
}
|
|
662
|
-
|
|
721
|
+
addEdge(t, e, s, o) {
|
|
663
722
|
if (t === void 0)
|
|
664
723
|
do
|
|
665
|
-
t = this.
|
|
666
|
-
while (this.graphStore.
|
|
724
|
+
t = this.edgeIdGenerator.next();
|
|
725
|
+
while (this.graphStore.hasEdge(t));
|
|
667
726
|
if (!this.graphStore.hasPort(e))
|
|
668
|
-
throw new Error("failed to add
|
|
669
|
-
if (!this.graphStore.hasPort(
|
|
670
|
-
throw new Error("failed to add
|
|
671
|
-
|
|
727
|
+
throw new Error("failed to add edge from nonexisting port");
|
|
728
|
+
if (!this.graphStore.hasPort(s))
|
|
729
|
+
throw new Error("failed to add edge to nonexisting port");
|
|
730
|
+
let a = M.Regular;
|
|
731
|
+
e === s && (a = M.Cycle), this.graphStore.addEdge(
|
|
672
732
|
t,
|
|
673
733
|
e,
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
), this.htmlController.
|
|
734
|
+
s,
|
|
735
|
+
o(a)
|
|
736
|
+
), this.htmlController.attachEdge(t);
|
|
677
737
|
}
|
|
678
|
-
|
|
679
|
-
if (!this.graphStore.
|
|
680
|
-
throw new Error("failed to remove nonexisting
|
|
681
|
-
this.htmlController.
|
|
738
|
+
removeEdge(t) {
|
|
739
|
+
if (!this.graphStore.hasEdge(t))
|
|
740
|
+
throw new Error("failed to remove nonexisting edge");
|
|
741
|
+
this.htmlController.detachEdge(t), this.graphStore.removeEdge(t);
|
|
682
742
|
}
|
|
683
743
|
removeNode(t) {
|
|
684
744
|
if (!this.graphStore.hasNode(t))
|
|
685
745
|
throw new Error("failed to remove nonexisting node");
|
|
686
746
|
this.htmlController.detachNode(t), this.graphStore.removeNode(t);
|
|
687
747
|
}
|
|
688
|
-
patchViewportState(t, e,
|
|
689
|
-
this.viewportTransformer.patchState(t, e,
|
|
748
|
+
patchViewportState(t, e, s) {
|
|
749
|
+
this.viewportTransformer.patchState(t, e, s), this.htmlController.applyTransform();
|
|
690
750
|
}
|
|
691
751
|
moveToNodes(t) {
|
|
692
752
|
if (t.length === 0)
|
|
693
753
|
return;
|
|
694
|
-
const e = t.map((
|
|
754
|
+
const e = t.map((u) => this.graphStore.getNode(u)).filter((u) => u !== void 0);
|
|
695
755
|
if (e.length < t.length)
|
|
696
756
|
throw new Error("failed to move to nonexisting node");
|
|
697
|
-
const [
|
|
698
|
-
(
|
|
757
|
+
const [s, o] = e.reduce(
|
|
758
|
+
(u, v) => [u[0] + v.x, u[1] + v.y],
|
|
699
759
|
[0, 0]
|
|
700
|
-
),
|
|
701
|
-
this.patchViewportState(null, g,
|
|
760
|
+
), a = s / e.length, c = o / e.length, [h, i] = this.htmlController.getViewportDimensions(), d = this.viewportTransformer.getAbsScale(), g = a - d * h / 2, l = c - d * i / 2;
|
|
761
|
+
this.patchViewportState(null, g, l);
|
|
702
762
|
}
|
|
703
|
-
updateNodeCoordinates(t, e,
|
|
763
|
+
updateNodeCoordinates(t, e, s) {
|
|
704
764
|
if (!this.graphStore.hasNode(t))
|
|
705
765
|
throw new Error("failed to update coordinates of nonexisting node");
|
|
706
|
-
this.graphStore.updateNodeCoords(t, e,
|
|
766
|
+
this.graphStore.updateNodeCoords(t, e, s), this.htmlController.updateNodeCoordinates(t);
|
|
707
767
|
}
|
|
708
|
-
|
|
709
|
-
if (!this.graphStore.
|
|
710
|
-
throw new Error("failed to update nonexisting
|
|
711
|
-
this.htmlController.
|
|
768
|
+
updateEdgeController(t, e) {
|
|
769
|
+
if (!this.graphStore.hasEdge(t))
|
|
770
|
+
throw new Error("failed to update nonexisting edge");
|
|
771
|
+
this.htmlController.detachEdge(t), this.graphStore.updateEdgeController(t, e), this.htmlController.attachEdge(t);
|
|
712
772
|
}
|
|
713
773
|
attach(t) {
|
|
714
774
|
this.htmlController.attach(t);
|
|
@@ -717,145 +777,145 @@ class Z {
|
|
|
717
777
|
this.htmlController.detach();
|
|
718
778
|
}
|
|
719
779
|
clear() {
|
|
720
|
-
this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.
|
|
780
|
+
this.htmlController.clear(), this.graphStore.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset();
|
|
721
781
|
}
|
|
722
782
|
destroy() {
|
|
723
783
|
this.htmlController.destroy();
|
|
724
784
|
}
|
|
725
785
|
}
|
|
726
|
-
class
|
|
727
|
-
constructor(t, e,
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
i,
|
|
786
|
+
class J {
|
|
787
|
+
constructor(t, e, s, o) {
|
|
788
|
+
n(this, "publicViewportTransformer");
|
|
789
|
+
n(this, "canvasController");
|
|
790
|
+
const a = new B(), c = new Y();
|
|
791
|
+
this.publicViewportTransformer = new z(
|
|
792
|
+
a
|
|
793
|
+
);
|
|
794
|
+
const h = new W(
|
|
795
|
+
c,
|
|
796
|
+
a,
|
|
738
797
|
this.publicViewportTransformer,
|
|
739
798
|
t,
|
|
740
799
|
e
|
|
741
800
|
);
|
|
742
|
-
this.canvasController = new
|
|
801
|
+
this.canvasController = new _(
|
|
802
|
+
c,
|
|
743
803
|
h,
|
|
744
804
|
a,
|
|
745
|
-
|
|
746
|
-
o
|
|
747
|
-
n
|
|
805
|
+
s,
|
|
806
|
+
o
|
|
748
807
|
);
|
|
749
808
|
}
|
|
750
809
|
}
|
|
751
|
-
const
|
|
752
|
-
|
|
810
|
+
const D = (r, t) => [
|
|
811
|
+
r / 2,
|
|
753
812
|
t / 2
|
|
754
|
-
],
|
|
755
|
-
},
|
|
756
|
-
|
|
757
|
-
const
|
|
758
|
-
let
|
|
813
|
+
], K = () => () => {
|
|
814
|
+
}, Q = (r, t, e, s, o, a) => {
|
|
815
|
+
r.clearRect(0, 0, r.canvas.width, r.canvas.height), r.fillStyle = a, r.fillRect(0, 0, r.canvas.width, r.canvas.height);
|
|
816
|
+
const c = t.getViewCoords(0, 0), h = t.getViewScale(), i = s * h;
|
|
817
|
+
let d = 0, g = 0, l = i / 2;
|
|
759
818
|
do
|
|
760
|
-
|
|
761
|
-
while (
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
for (let
|
|
765
|
-
for (let y =
|
|
766
|
-
|
|
767
|
-
},
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
819
|
+
l *= 2, d = r.canvas.width / l, g = r.canvas.height / l;
|
|
820
|
+
while (d * g > 1e4);
|
|
821
|
+
const u = c[0] - Math.floor(c[0] / l) * l, v = c[1] - Math.floor(c[1] / l) * l, m = o * h, w = 2 * Math.PI, f = u - l, C = v - l, E = r.canvas.width + u, b = r.canvas.height + v;
|
|
822
|
+
r.fillStyle = e;
|
|
823
|
+
for (let $ = f; $ <= E; $ += l)
|
|
824
|
+
for (let y = C; y <= b; y += l)
|
|
825
|
+
r.beginPath(), r.arc($, y, m, 0, w), r.closePath(), r.fill();
|
|
826
|
+
}, I = (r, t, e, s) => (o, a) => {
|
|
827
|
+
Q(
|
|
828
|
+
o,
|
|
829
|
+
a,
|
|
830
|
+
r,
|
|
772
831
|
t,
|
|
773
832
|
e,
|
|
774
|
-
|
|
833
|
+
s
|
|
775
834
|
);
|
|
776
|
-
},
|
|
777
|
-
|
|
778
|
-
},
|
|
779
|
-
|
|
780
|
-
},
|
|
781
|
-
switch (
|
|
835
|
+
}, tt = (r, t) => {
|
|
836
|
+
r.fillStyle = t, r.fillRect(0, 0, r.canvas.width, r.canvas.height);
|
|
837
|
+
}, et = (r) => (t) => {
|
|
838
|
+
tt(t, r);
|
|
839
|
+
}, st = (r) => {
|
|
840
|
+
switch (r == null ? void 0 : r.type) {
|
|
782
841
|
case "custom":
|
|
783
|
-
return
|
|
842
|
+
return r.drawingFn;
|
|
784
843
|
case "dots":
|
|
785
|
-
return
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
844
|
+
return I(
|
|
845
|
+
r.dotColor ?? "#d8d8d8",
|
|
846
|
+
r.dotGap ?? 25,
|
|
847
|
+
r.dotRadius ?? 1.5,
|
|
848
|
+
r.color ?? "#ffffff"
|
|
790
849
|
);
|
|
791
850
|
case "color":
|
|
792
|
-
return
|
|
851
|
+
return et(r.color ?? "#ffffff");
|
|
793
852
|
default:
|
|
794
|
-
return
|
|
853
|
+
return K();
|
|
795
854
|
}
|
|
796
|
-
},
|
|
797
|
-
switch (
|
|
855
|
+
}, F = (r) => {
|
|
856
|
+
switch (r == null ? void 0 : r.type) {
|
|
798
857
|
case "custom":
|
|
799
|
-
return
|
|
858
|
+
return r.controllerFactory;
|
|
800
859
|
case "straight":
|
|
801
|
-
return
|
|
802
|
-
color:
|
|
803
|
-
width:
|
|
804
|
-
arrowLength:
|
|
805
|
-
arrowWidth:
|
|
806
|
-
|
|
807
|
-
hasSourceArrow:
|
|
808
|
-
hasTargetArrow:
|
|
860
|
+
return q({
|
|
861
|
+
color: r.color ?? "#5c5c5c",
|
|
862
|
+
width: r.width ?? 1,
|
|
863
|
+
arrowLength: r.arrowLength ?? 15,
|
|
864
|
+
arrowWidth: r.arrowWidth ?? 4,
|
|
865
|
+
arrowOffset: r.arrowOffset ?? 15,
|
|
866
|
+
hasSourceArrow: r.hasSourceArrow ?? !1,
|
|
867
|
+
hasTargetArrow: r.hasTargetArrow ?? !1,
|
|
868
|
+
cycleSquareSide: r.cycleSquareSide ?? 30,
|
|
869
|
+
roundness: r.roundness ?? 5
|
|
809
870
|
});
|
|
810
871
|
default:
|
|
811
|
-
return
|
|
812
|
-
color:
|
|
813
|
-
width:
|
|
814
|
-
curvature:
|
|
815
|
-
arrowLength:
|
|
816
|
-
arrowWidth:
|
|
817
|
-
hasSourceArrow:
|
|
818
|
-
hasTargetArrow:
|
|
872
|
+
return H({
|
|
873
|
+
color: r.color ?? "#5c5c5c",
|
|
874
|
+
width: r.width ?? 1,
|
|
875
|
+
curvature: r.curvature ?? 90,
|
|
876
|
+
arrowLength: r.arrowLength ?? 15,
|
|
877
|
+
arrowWidth: r.arrowWidth ?? 4,
|
|
878
|
+
hasSourceArrow: r.hasSourceArrow ?? !1,
|
|
879
|
+
hasTargetArrow: r.hasTargetArrow ?? !1,
|
|
880
|
+
cycleRadius: r.cycleRadius ?? 30,
|
|
881
|
+
smallCycleRadius: r.smallCycleRadius ?? 15
|
|
819
882
|
});
|
|
820
883
|
}
|
|
821
|
-
},
|
|
822
|
-
var t, e,
|
|
884
|
+
}, rt = (r) => {
|
|
885
|
+
var t, e, s;
|
|
823
886
|
return {
|
|
824
887
|
background: {
|
|
825
|
-
drawingFn:
|
|
826
|
-
|
|
888
|
+
drawingFn: st(
|
|
889
|
+
r.background ?? { type: "none" }
|
|
827
890
|
)
|
|
828
891
|
},
|
|
829
892
|
nodes: {
|
|
830
|
-
centerFn: ((t =
|
|
893
|
+
centerFn: ((t = r.nodes) == null ? void 0 : t.centerFn) ?? D
|
|
831
894
|
},
|
|
832
895
|
ports: {
|
|
833
|
-
centerFn: ((e =
|
|
896
|
+
centerFn: ((e = r.ports) == null ? void 0 : e.centerFn) ?? D
|
|
834
897
|
},
|
|
835
|
-
|
|
836
|
-
controllerFactory:
|
|
837
|
-
s.connections ?? {}
|
|
838
|
-
)
|
|
898
|
+
edges: {
|
|
899
|
+
controllerFactory: F(r.edges ?? {})
|
|
839
900
|
},
|
|
840
901
|
layers: {
|
|
841
|
-
mode: ((
|
|
902
|
+
mode: ((s = r.layers) == null ? void 0 : s.mode) ?? "edges-follow-node"
|
|
842
903
|
}
|
|
843
904
|
};
|
|
844
905
|
};
|
|
845
|
-
class
|
|
906
|
+
class ot {
|
|
846
907
|
constructor(t) {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
r(this, "connectionControllerFactory");
|
|
908
|
+
n(this, "transformation");
|
|
909
|
+
n(this, "di");
|
|
910
|
+
n(this, "edgeControllerFactory");
|
|
851
911
|
this.apiOptions = t;
|
|
852
|
-
const e =
|
|
853
|
-
this.di = new
|
|
912
|
+
const e = rt(this.apiOptions ?? {});
|
|
913
|
+
this.di = new J(
|
|
854
914
|
e.layers.mode,
|
|
855
915
|
e.background.drawingFn,
|
|
856
916
|
e.nodes.centerFn,
|
|
857
917
|
e.ports.centerFn
|
|
858
|
-
), this.transformation = this.di.publicViewportTransformer, this.
|
|
918
|
+
), this.transformation = this.di.publicViewportTransformer, this.edgeControllerFactory = e.edges.controllerFactory;
|
|
859
919
|
}
|
|
860
920
|
addNode(t) {
|
|
861
921
|
return this.di.canvasController.addNode(
|
|
@@ -882,23 +942,23 @@ class tt {
|
|
|
882
942
|
t.direction
|
|
883
943
|
), this;
|
|
884
944
|
}
|
|
885
|
-
|
|
886
|
-
return this.di.canvasController.
|
|
945
|
+
updatePortEdges(t) {
|
|
946
|
+
return this.di.canvasController.updatePortEdges(t), this;
|
|
887
947
|
}
|
|
888
948
|
unmarkPort(t) {
|
|
889
949
|
return this.di.canvasController.unmarkPort(t), this;
|
|
890
950
|
}
|
|
891
|
-
|
|
892
|
-
const e = t.options !== void 0 ?
|
|
893
|
-
return this.di.canvasController.
|
|
951
|
+
addEdge(t) {
|
|
952
|
+
const e = t.options !== void 0 ? F(t.options) : this.edgeControllerFactory;
|
|
953
|
+
return this.di.canvasController.addEdge(
|
|
894
954
|
t.id,
|
|
895
955
|
t.from,
|
|
896
956
|
t.to,
|
|
897
957
|
e
|
|
898
958
|
), this;
|
|
899
959
|
}
|
|
900
|
-
|
|
901
|
-
return this.di.canvasController.
|
|
960
|
+
removeEdge(t) {
|
|
961
|
+
return this.di.canvasController.removeEdge(t), this;
|
|
902
962
|
}
|
|
903
963
|
patchViewportState(t) {
|
|
904
964
|
return this.di.canvasController.patchViewportState(
|
|
@@ -910,14 +970,11 @@ class tt {
|
|
|
910
970
|
moveToNodes(t) {
|
|
911
971
|
return this.di.canvasController.moveToNodes(t), this;
|
|
912
972
|
}
|
|
913
|
-
updateNodeCoordinates(t, e,
|
|
914
|
-
return this.di.canvasController.updateNodeCoordinates(t, e,
|
|
973
|
+
updateNodeCoordinates(t, e, s) {
|
|
974
|
+
return this.di.canvasController.updateNodeCoordinates(t, e, s), this;
|
|
915
975
|
}
|
|
916
|
-
|
|
917
|
-
return e.controller !== void 0 && this.di.canvasController.
|
|
918
|
-
t,
|
|
919
|
-
e.controller
|
|
920
|
-
), this;
|
|
976
|
+
updateEdge(t, e) {
|
|
977
|
+
return e.controller !== void 0 && this.di.canvasController.updateEdgeController(t, e.controller), this;
|
|
921
978
|
}
|
|
922
979
|
clear() {
|
|
923
980
|
return this.di.canvasController.clear(), this;
|
|
@@ -932,50 +989,54 @@ class tt {
|
|
|
932
989
|
this.di.canvasController.destroy();
|
|
933
990
|
}
|
|
934
991
|
}
|
|
935
|
-
class
|
|
992
|
+
class nt {
|
|
936
993
|
constructor(t, e) {
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
994
|
+
n(this, "transformation");
|
|
995
|
+
n(this, "nodes", /* @__PURE__ */ new Map());
|
|
996
|
+
n(this, "grabbedNodeId", null);
|
|
997
|
+
n(this, "onNodeDrag");
|
|
998
|
+
n(this, "onBeforeNodeDrag");
|
|
999
|
+
n(this, "nodeIdGenerator", new x());
|
|
1000
|
+
n(this, "element", null);
|
|
1001
|
+
n(this, "onCanvasMouseUp", () => {
|
|
945
1002
|
this.setCursor(null), this.grabbedNodeId = null;
|
|
946
1003
|
});
|
|
947
|
-
|
|
1004
|
+
n(this, "onCanvasMouseMove", (t) => {
|
|
948
1005
|
this.grabbedNodeId !== null && (t.stopPropagation(), this.dragNode(this.grabbedNodeId, t.movementX, t.movementY));
|
|
949
1006
|
});
|
|
950
|
-
|
|
1007
|
+
n(this, "onCanvasTouchStart", (t) => {
|
|
951
1008
|
this.previousTouchCoords = [
|
|
952
1009
|
t.touches[0].clientX,
|
|
953
1010
|
t.touches[0].clientY
|
|
954
1011
|
];
|
|
955
1012
|
});
|
|
956
|
-
|
|
1013
|
+
n(this, "onCanvasTouchMove", (t) => {
|
|
957
1014
|
if (this.grabbedNodeId === null || t.touches.length !== 1 || this.previousTouchCoords === null)
|
|
958
1015
|
return;
|
|
959
1016
|
t.stopImmediatePropagation();
|
|
960
|
-
const [e,
|
|
1017
|
+
const [e, s] = [
|
|
961
1018
|
t.touches[0].clientX - this.previousTouchCoords[0],
|
|
962
1019
|
t.touches[0].clientY - this.previousTouchCoords[1]
|
|
963
1020
|
];
|
|
964
|
-
this.dragNode(this.grabbedNodeId, e,
|
|
1021
|
+
this.dragNode(this.grabbedNodeId, e, s), this.previousTouchCoords = [
|
|
965
1022
|
t.touches[0].clientX,
|
|
966
1023
|
t.touches[0].clientY
|
|
967
1024
|
];
|
|
968
1025
|
});
|
|
969
|
-
|
|
1026
|
+
n(this, "onCanvasTouchEnd", (t) => {
|
|
970
1027
|
t.touches.length > 0 ? this.previousTouchCoords = [
|
|
971
1028
|
t.touches[0].clientX,
|
|
972
1029
|
t.touches[0].clientY
|
|
973
1030
|
] : (this.previousTouchCoords = null, this.grabbedNodeId = null);
|
|
974
1031
|
});
|
|
975
|
-
|
|
976
|
-
var
|
|
977
|
-
this.canvas = t, this.transformation = this.canvas.transformation
|
|
978
|
-
|
|
1032
|
+
n(this, "previousTouchCoords", null);
|
|
1033
|
+
var a, c;
|
|
1034
|
+
this.canvas = t, this.transformation = this.canvas.transformation;
|
|
1035
|
+
const s = () => {
|
|
1036
|
+
};
|
|
1037
|
+
this.onNodeDrag = ((a = e == null ? void 0 : e.events) == null ? void 0 : a.onNodeDrag) ?? s;
|
|
1038
|
+
const o = () => !0;
|
|
1039
|
+
this.onBeforeNodeDrag = ((c = e == null ? void 0 : e.events) == null ? void 0 : c.onBeforeNodeDrag) ?? o;
|
|
979
1040
|
}
|
|
980
1041
|
addNode(t) {
|
|
981
1042
|
let e = t.id;
|
|
@@ -984,35 +1045,47 @@ class et {
|
|
|
984
1045
|
e = this.nodeIdGenerator.next();
|
|
985
1046
|
while (this.nodes.has(e));
|
|
986
1047
|
this.canvas.addNode(t);
|
|
987
|
-
const
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1048
|
+
const s = (a) => {
|
|
1049
|
+
this.onBeforeNodeDrag({
|
|
1050
|
+
nodeId: e,
|
|
1051
|
+
element: t.element,
|
|
1052
|
+
x: t.x,
|
|
1053
|
+
y: t.y
|
|
1054
|
+
}) && (a.stopImmediatePropagation(), this.grabbedNodeId = e, this.setCursor("grab"), this.canvas.moveNodeOnTop(e));
|
|
1055
|
+
}, o = (a) => {
|
|
1056
|
+
this.onBeforeNodeDrag({
|
|
1057
|
+
nodeId: e,
|
|
1058
|
+
element: t.element,
|
|
1059
|
+
x: t.x,
|
|
1060
|
+
y: t.y
|
|
1061
|
+
}) && a.touches.length === 1 && (this.grabbedNodeId = e, this.canvas.moveNodeOnTop(e));
|
|
991
1062
|
};
|
|
992
1063
|
return this.nodes.set(e, {
|
|
993
|
-
|
|
994
|
-
onMouseDown:
|
|
995
|
-
onTouchStart:
|
|
996
|
-
|
|
1064
|
+
element: t.element,
|
|
1065
|
+
onMouseDown: s,
|
|
1066
|
+
onTouchStart: o,
|
|
1067
|
+
x: t.x,
|
|
1068
|
+
y: t.y
|
|
1069
|
+
}), t.element.addEventListener("mousedown", s), t.element.addEventListener("touchstart", o), this;
|
|
997
1070
|
}
|
|
998
1071
|
removeNode(t) {
|
|
999
1072
|
const e = this.nodes.get(t);
|
|
1000
|
-
return e !== void 0 && (e.
|
|
1073
|
+
return e !== void 0 && (e.element.removeEventListener("mousedown", e.onMouseDown), e.element.removeEventListener("touchstart", e.onTouchStart)), this.canvas.removeNode(t), this.nodes.delete(t), this;
|
|
1001
1074
|
}
|
|
1002
1075
|
markPort(t) {
|
|
1003
1076
|
return this.canvas.markPort(t), this;
|
|
1004
1077
|
}
|
|
1005
|
-
|
|
1006
|
-
return this.canvas.
|
|
1078
|
+
updatePortEdges(t) {
|
|
1079
|
+
return this.canvas.updatePortEdges(t), this;
|
|
1007
1080
|
}
|
|
1008
1081
|
unmarkPort(t) {
|
|
1009
1082
|
return this.canvas.unmarkPort(t), this;
|
|
1010
1083
|
}
|
|
1011
|
-
|
|
1012
|
-
return this.canvas.
|
|
1084
|
+
addEdge(t) {
|
|
1085
|
+
return this.canvas.addEdge(t), this;
|
|
1013
1086
|
}
|
|
1014
|
-
|
|
1015
|
-
return this.canvas.
|
|
1087
|
+
removeEdge(t) {
|
|
1088
|
+
return this.canvas.removeEdge(t), this;
|
|
1016
1089
|
}
|
|
1017
1090
|
patchViewportState(t) {
|
|
1018
1091
|
return this.canvas.patchViewportState(t), this;
|
|
@@ -1020,78 +1093,83 @@ class et {
|
|
|
1020
1093
|
moveToNodes(t) {
|
|
1021
1094
|
return this.canvas.moveToNodes(t), this;
|
|
1022
1095
|
}
|
|
1023
|
-
updateNodeCoordinates(t, e,
|
|
1024
|
-
return this.canvas.updateNodeCoordinates(t, e,
|
|
1096
|
+
updateNodeCoordinates(t, e, s) {
|
|
1097
|
+
return this.canvas.updateNodeCoordinates(t, e, s), this;
|
|
1025
1098
|
}
|
|
1026
|
-
|
|
1027
|
-
return this.canvas.
|
|
1099
|
+
updateEdge(t, e) {
|
|
1100
|
+
return this.canvas.updateEdge(t, e), this;
|
|
1028
1101
|
}
|
|
1029
1102
|
moveNodeOnTop(t) {
|
|
1030
1103
|
return this.canvas.moveNodeOnTop(t), this;
|
|
1031
1104
|
}
|
|
1032
1105
|
clear() {
|
|
1033
1106
|
return this.canvas.clear(), this.nodes.forEach((t) => {
|
|
1034
|
-
t.
|
|
1107
|
+
t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart);
|
|
1035
1108
|
}), this.nodes.clear(), this;
|
|
1036
1109
|
}
|
|
1037
1110
|
attach(t) {
|
|
1038
|
-
return this.
|
|
1111
|
+
return this.detach(), this.element = t, this.canvas.attach(this.element), this.element.addEventListener("mouseup", this.onCanvasMouseUp), this.element.addEventListener("mousemove", this.onCanvasMouseMove), this.element.addEventListener("touchstart", this.onCanvasTouchStart), this.element.addEventListener("touchmove", this.onCanvasTouchMove), this.element.addEventListener("touchend", this.onCanvasTouchEnd), this.element.addEventListener("touchcancel", this.onCanvasTouchEnd), this;
|
|
1039
1112
|
}
|
|
1040
1113
|
detach() {
|
|
1041
1114
|
return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mouseup", this.onCanvasMouseUp), this.element.removeEventListener("mousemove", this.onCanvasMouseMove), this.element.removeEventListener("touchstart", this.onCanvasTouchStart), this.element.removeEventListener("touchmove", this.onCanvasTouchMove), this.element.removeEventListener("touchend", this.onCanvasTouchEnd), this.element.removeEventListener("touchcancel", this.onCanvasTouchEnd), this.element = null), this;
|
|
1042
1115
|
}
|
|
1043
1116
|
destroy() {
|
|
1044
1117
|
this.detach(), this.nodes.forEach((t) => {
|
|
1045
|
-
t.
|
|
1118
|
+
t.element.removeEventListener("mousedown", t.onMouseDown), t.element.removeEventListener("touchstart", t.onTouchStart);
|
|
1046
1119
|
}), this.nodes.clear(), this.canvas.destroy();
|
|
1047
1120
|
}
|
|
1048
1121
|
setCursor(t) {
|
|
1049
1122
|
this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
|
|
1050
1123
|
}
|
|
1051
|
-
dragNode(t, e,
|
|
1052
|
-
const
|
|
1053
|
-
if (
|
|
1124
|
+
dragNode(t, e, s) {
|
|
1125
|
+
const o = this.nodes.get(t);
|
|
1126
|
+
if (o === void 0)
|
|
1054
1127
|
throw new Error("failed to drag nonexisting node");
|
|
1055
|
-
const [
|
|
1056
|
-
this.canvas.updateNodeCoordinates(t,
|
|
1128
|
+
const [a, c] = this.transformation.getViewCoords(o.x, o.y), h = a + e, i = c + s, [d, g] = this.transformation.getAbsCoords(h, i);
|
|
1129
|
+
o.x = d, o.y = g, this.canvas.updateNodeCoordinates(t, d, g), this.onNodeDrag({
|
|
1130
|
+
nodeId: t,
|
|
1131
|
+
element: o.element,
|
|
1132
|
+
x: o.x,
|
|
1133
|
+
y: o.y
|
|
1134
|
+
});
|
|
1057
1135
|
}
|
|
1058
1136
|
}
|
|
1059
|
-
class
|
|
1137
|
+
class it {
|
|
1060
1138
|
constructor(t, e) {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1139
|
+
n(this, "transformation");
|
|
1140
|
+
n(this, "element", null);
|
|
1141
|
+
n(this, "isMoving", !1);
|
|
1142
|
+
n(this, "prevTouches", null);
|
|
1143
|
+
n(this, "onTransform");
|
|
1144
|
+
n(this, "onBeforeTransform");
|
|
1145
|
+
n(this, "isScalable");
|
|
1146
|
+
n(this, "isShiftable");
|
|
1147
|
+
n(this, "minViewScale");
|
|
1148
|
+
n(this, "maxViewScale");
|
|
1149
|
+
n(this, "wheelSensitivity");
|
|
1150
|
+
n(this, "onMouseDown", () => {
|
|
1073
1151
|
this.setCursor("grab"), this.isMoving = !0;
|
|
1074
1152
|
});
|
|
1075
|
-
|
|
1153
|
+
n(this, "onMouseMove", (t) => {
|
|
1076
1154
|
if (!this.isMoving || !this.isShiftable)
|
|
1077
1155
|
return;
|
|
1078
|
-
const e = -t.movementX,
|
|
1079
|
-
this.moveViewport(e,
|
|
1156
|
+
const e = -t.movementX, s = -t.movementY;
|
|
1157
|
+
this.moveViewport(e, s);
|
|
1080
1158
|
});
|
|
1081
|
-
|
|
1159
|
+
n(this, "onMouseUp", () => {
|
|
1082
1160
|
this.setCursor(null), this.isMoving = !1;
|
|
1083
1161
|
});
|
|
1084
|
-
|
|
1162
|
+
n(this, "onWheelScroll", (t) => {
|
|
1085
1163
|
if (this.element === null || this.isScalable === !1)
|
|
1086
1164
|
return;
|
|
1087
1165
|
t.preventDefault();
|
|
1088
|
-
const { left: e, top:
|
|
1089
|
-
this.scaleViewport(
|
|
1166
|
+
const { left: e, top: s } = this.element.getBoundingClientRect(), o = t.clientX - e, a = t.clientY - s, h = 1 / (t.deltaY < 0 ? this.wheelSensitivity : 1 / this.wheelSensitivity);
|
|
1167
|
+
this.scaleViewport(h, o, a);
|
|
1090
1168
|
});
|
|
1091
|
-
|
|
1169
|
+
n(this, "onTouchStart", (t) => {
|
|
1092
1170
|
this.prevTouches = this.getAverageTouch(t);
|
|
1093
1171
|
});
|
|
1094
|
-
|
|
1172
|
+
n(this, "onTouchMove", (t) => {
|
|
1095
1173
|
if (this.prevTouches === null || this.element === null || !this.isShiftable)
|
|
1096
1174
|
return;
|
|
1097
1175
|
const e = this.getAverageTouch(t);
|
|
@@ -1099,21 +1177,25 @@ class ot {
|
|
|
1099
1177
|
-(e.x - this.prevTouches.x),
|
|
1100
1178
|
-(e.y - this.prevTouches.y)
|
|
1101
1179
|
), e.touchesCnt === 2 && this.isScalable) {
|
|
1102
|
-
const { left:
|
|
1103
|
-
this.scaleViewport(
|
|
1180
|
+
const { left: s, top: o } = this.element.getBoundingClientRect(), a = this.prevTouches.x - s, c = this.prevTouches.y - o, i = 1 / (e.scale / this.prevTouches.scale);
|
|
1181
|
+
this.scaleViewport(i, a, c);
|
|
1104
1182
|
}
|
|
1105
1183
|
this.prevTouches = e, t.preventDefault();
|
|
1106
1184
|
});
|
|
1107
|
-
|
|
1185
|
+
n(this, "onTouchEnd", (t) => {
|
|
1108
1186
|
t.touches.length > 0 ? this.prevTouches = this.getAverageTouch(t) : this.prevTouches = null;
|
|
1109
1187
|
});
|
|
1110
|
-
var
|
|
1111
|
-
this.canvas = t, this.options = e, this.transformation = this.canvas.transformation
|
|
1112
|
-
const
|
|
1113
|
-
this.isScalable = ((
|
|
1114
|
-
const
|
|
1115
|
-
this.wheelSensitivity =
|
|
1116
|
-
|
|
1188
|
+
var i, d, g, l, u, v, m, w, f, C, E, b;
|
|
1189
|
+
this.canvas = t, this.options = e, this.transformation = this.canvas.transformation;
|
|
1190
|
+
const s = ((d = (i = this.options) == null ? void 0 : i.scale) == null ? void 0 : d.min) ?? null, o = ((l = (g = this.options) == null ? void 0 : g.scale) == null ? void 0 : l.max) ?? null;
|
|
1191
|
+
this.isScalable = ((v = (u = this.options) == null ? void 0 : u.scale) == null ? void 0 : v.enabled) !== !1, this.minViewScale = o !== null ? 1 / o : null, this.maxViewScale = s !== null ? 1 / s : null, this.isShiftable = ((w = (m = this.options) == null ? void 0 : m.shift) == null ? void 0 : w.enabled) !== !1;
|
|
1192
|
+
const a = (C = (f = this.options) == null ? void 0 : f.scale) == null ? void 0 : C.wheelSensitivity;
|
|
1193
|
+
this.wheelSensitivity = a !== void 0 ? a : 1.2;
|
|
1194
|
+
const c = () => {
|
|
1195
|
+
};
|
|
1196
|
+
this.onTransform = ((E = e == null ? void 0 : e.events) == null ? void 0 : E.onTransform) ?? c;
|
|
1197
|
+
const h = () => !0;
|
|
1198
|
+
this.onBeforeTransform = ((b = e == null ? void 0 : e.events) == null ? void 0 : b.onBeforeTransform) ?? h;
|
|
1117
1199
|
}
|
|
1118
1200
|
addNode(t) {
|
|
1119
1201
|
return this.canvas.addNode(t), this;
|
|
@@ -1124,17 +1206,17 @@ class ot {
|
|
|
1124
1206
|
markPort(t) {
|
|
1125
1207
|
return this.canvas.markPort(t), this;
|
|
1126
1208
|
}
|
|
1127
|
-
|
|
1128
|
-
return this.canvas.
|
|
1209
|
+
updatePortEdges(t) {
|
|
1210
|
+
return this.canvas.updatePortEdges(t), this;
|
|
1129
1211
|
}
|
|
1130
1212
|
unmarkPort(t) {
|
|
1131
1213
|
return this.canvas.unmarkPort(t), this;
|
|
1132
1214
|
}
|
|
1133
|
-
|
|
1134
|
-
return this.canvas.
|
|
1215
|
+
addEdge(t) {
|
|
1216
|
+
return this.canvas.addEdge(t), this;
|
|
1135
1217
|
}
|
|
1136
|
-
|
|
1137
|
-
return this.canvas.
|
|
1218
|
+
removeEdge(t) {
|
|
1219
|
+
return this.canvas.removeEdge(t), this;
|
|
1138
1220
|
}
|
|
1139
1221
|
patchViewportState(t) {
|
|
1140
1222
|
return this.canvas.patchViewportState(t), this;
|
|
@@ -1142,11 +1224,11 @@ class ot {
|
|
|
1142
1224
|
moveToNodes(t) {
|
|
1143
1225
|
return this.canvas.moveToNodes(t), this;
|
|
1144
1226
|
}
|
|
1145
|
-
updateNodeCoordinates(t, e,
|
|
1146
|
-
return this.canvas.updateNodeCoordinates(t, e,
|
|
1227
|
+
updateNodeCoordinates(t, e, s) {
|
|
1228
|
+
return this.canvas.updateNodeCoordinates(t, e, s), this;
|
|
1147
1229
|
}
|
|
1148
|
-
|
|
1149
|
-
return this.canvas.
|
|
1230
|
+
updateEdge(t, e) {
|
|
1231
|
+
return this.canvas.updateEdge(t, e), this;
|
|
1150
1232
|
}
|
|
1151
1233
|
moveNodeOnTop(t) {
|
|
1152
1234
|
return this.canvas.moveNodeOnTop(t), this;
|
|
@@ -1155,74 +1237,79 @@ class ot {
|
|
|
1155
1237
|
return this.canvas.clear(), this;
|
|
1156
1238
|
}
|
|
1157
1239
|
attach(t) {
|
|
1158
|
-
return this.
|
|
1240
|
+
return this.detach(), this.element = t, this.canvas.attach(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("mousemove", this.onMouseMove), this.element.addEventListener("mouseup", this.onMouseUp), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), this.element.addEventListener("touchmove", this.onTouchMove), this.element.addEventListener("touchend", this.onTouchEnd), this.element.addEventListener("touchcancel", this.onTouchEnd), this;
|
|
1159
1241
|
}
|
|
1160
1242
|
detach() {
|
|
1161
|
-
return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("mousemove", this.onMouseMove), this.element.removeEventListener("mouseup", this.onMouseUp), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("touchmove", this.onTouchMove), this.element.removeEventListener("touchend", this.onTouchEnd), this.element.removeEventListener("touchcancel", this.onTouchEnd)
|
|
1243
|
+
return this.canvas.detach(), this.element !== null && (this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("mousemove", this.onMouseMove), this.element.removeEventListener("mouseup", this.onMouseUp), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.element.removeEventListener("touchmove", this.onTouchMove), this.element.removeEventListener("touchend", this.onTouchEnd), this.element.removeEventListener("touchcancel", this.onTouchEnd), this.element = null), this;
|
|
1162
1244
|
}
|
|
1163
1245
|
destroy() {
|
|
1164
1246
|
this.detach(), this.canvas.destroy();
|
|
1165
1247
|
}
|
|
1166
1248
|
getAverageTouch(t) {
|
|
1167
|
-
const e = [],
|
|
1168
|
-
for (let
|
|
1169
|
-
e.push([t.touches[
|
|
1170
|
-
const
|
|
1171
|
-
(
|
|
1249
|
+
const e = [], s = t.touches.length;
|
|
1250
|
+
for (let i = 0; i < s; i++)
|
|
1251
|
+
e.push([t.touches[i].clientX, t.touches[i].clientY]);
|
|
1252
|
+
const o = e.reduce(
|
|
1253
|
+
(i, d) => [i[0] + d[0], i[1] + d[1]],
|
|
1172
1254
|
[0, 0]
|
|
1173
|
-
),
|
|
1174
|
-
(
|
|
1255
|
+
), a = [o[0] / s, o[1] / s], h = e.map((i) => [i[0] - a[0], i[1] - a[1]]).reduce(
|
|
1256
|
+
(i, d) => i + Math.sqrt(d[0] * d[0] + d[1] * d[1]),
|
|
1175
1257
|
0
|
|
1176
1258
|
);
|
|
1177
|
-
return { x:
|
|
1259
|
+
return { x: a[0], y: a[1], scale: h / s, touchesCnt: s };
|
|
1178
1260
|
}
|
|
1179
1261
|
setCursor(t) {
|
|
1180
1262
|
this.element !== null && (t !== null ? this.element.style.cursor = t : this.element.style.removeProperty("cursor"));
|
|
1181
1263
|
}
|
|
1182
1264
|
moveViewport(t, e) {
|
|
1183
|
-
const [
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
}), this.onTransform();
|
|
1265
|
+
const [s, o] = this.transformation.getAbsCoords(0, 0), a = this.canvas.transformation.getAbsScale(), c = {
|
|
1266
|
+
scale: a,
|
|
1267
|
+
x: s + a * t,
|
|
1268
|
+
y: o + a * e
|
|
1269
|
+
};
|
|
1270
|
+
this.onBeforeTransform({ ...c }) && (this.canvas.patchViewportState(c), this.onTransform(c));
|
|
1189
1271
|
}
|
|
1190
|
-
scaleViewport(t, e,
|
|
1191
|
-
const [
|
|
1192
|
-
this.maxViewScale !== null &&
|
|
1272
|
+
scaleViewport(t, e, s) {
|
|
1273
|
+
const [o, a] = this.canvas.transformation.getAbsCoords(0, 0), c = this.canvas.transformation.getAbsScale(), h = c * t, i = c * (1 - t) * e + o, d = c * (1 - t) * s + a;
|
|
1274
|
+
if (this.maxViewScale !== null && h > this.maxViewScale && h > c || this.minViewScale !== null && h < this.minViewScale && h < c)
|
|
1275
|
+
return;
|
|
1276
|
+
const g = { scale: h, x: i, y: d };
|
|
1277
|
+
this.onBeforeTransform({ ...g }) && (this.canvas.patchViewportState(g), this.onTransform(g));
|
|
1193
1278
|
}
|
|
1194
1279
|
}
|
|
1195
|
-
class
|
|
1280
|
+
class ht {
|
|
1196
1281
|
constructor() {
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1282
|
+
n(this, "coreOptions");
|
|
1283
|
+
n(this, "dragOptions");
|
|
1284
|
+
n(this, "transformOptions");
|
|
1285
|
+
n(this, "isDraggable", !1);
|
|
1286
|
+
n(this, "isTransformable", !1);
|
|
1202
1287
|
}
|
|
1203
1288
|
setOptions(t) {
|
|
1204
1289
|
return this.coreOptions = t, this;
|
|
1205
1290
|
}
|
|
1206
|
-
|
|
1291
|
+
setUserDraggableNodes(t) {
|
|
1207
1292
|
return this.isDraggable = !0, this.dragOptions = t, this;
|
|
1208
1293
|
}
|
|
1209
|
-
|
|
1294
|
+
setUserTransformableCanvas(t) {
|
|
1210
1295
|
return this.isTransformable = !0, this.transformOptions = t, this;
|
|
1211
1296
|
}
|
|
1212
1297
|
build() {
|
|
1213
|
-
let t = new
|
|
1214
|
-
return this.isDraggable && (t = new
|
|
1298
|
+
let t = new ot(this.coreOptions);
|
|
1299
|
+
return this.isDraggable && (t = new nt(t, this.dragOptions)), this.isTransformable && (t = new it(t, this.transformOptions)), t;
|
|
1215
1300
|
}
|
|
1216
1301
|
}
|
|
1217
1302
|
export {
|
|
1218
|
-
G as
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1303
|
+
G as BezierEdgeController,
|
|
1304
|
+
ot as CanvasCore,
|
|
1305
|
+
Z as CycleCircleEdgeController,
|
|
1306
|
+
U as CycleSquareEdgeController,
|
|
1307
|
+
M as EdgeType,
|
|
1308
|
+
p as EdgeUtils,
|
|
1309
|
+
ht as HtmlGraphBuilder,
|
|
1310
|
+
X as StraightEdgeController,
|
|
1311
|
+
nt as UserDraggableNodesCanvas,
|
|
1312
|
+
it as UserTransformableCanvas,
|
|
1313
|
+
H as createBezierEdgeControllerFactory,
|
|
1314
|
+
q as createStraightEdgeControllerFactory
|
|
1228
1315
|
};
|