@html-graph/html-graph 3.0.0 → 3.2.0
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 +1 -0
- package/dist/html-graph.d.ts +113 -90
- package/dist/html-graph.js +1414 -1386
- package/dist/html-graph.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/html-graph.js
CHANGED
|
@@ -1,7 +1,234 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var i = (t, e, o) =>
|
|
4
|
-
|
|
1
|
+
var ne = Object.defineProperty;
|
|
2
|
+
var he = (t, e, o) => e in t ? ne(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
|
|
3
|
+
var i = (t, e, o) => he(t, typeof e != "symbol" ? e + "" : e, o);
|
|
4
|
+
const de = () => {
|
|
5
|
+
const t = document.createElement("div");
|
|
6
|
+
return t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.width = "0", t.style.height = "0", t;
|
|
7
|
+
}, ce = () => {
|
|
8
|
+
const t = document.createElement("div");
|
|
9
|
+
return t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.visibility = "hidden", t;
|
|
10
|
+
}, ae = () => {
|
|
11
|
+
const t = document.createElement("div");
|
|
12
|
+
return t.style.width = "100%", t.style.height = "100%", t.style.position = "relative", t.style.overflow = "hidden", t;
|
|
13
|
+
};
|
|
14
|
+
class le {
|
|
15
|
+
constructor(e, o, r) {
|
|
16
|
+
i(this, "host", ae());
|
|
17
|
+
i(this, "container", de());
|
|
18
|
+
i(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
|
|
19
|
+
i(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
|
|
20
|
+
i(this, "applyTransform", () => {
|
|
21
|
+
const e = this.viewportStore.getContentMatrix();
|
|
22
|
+
this.container.style.transform = `matrix(${e.scale}, 0, 0, ${e.scale}, ${e.x}, ${e.y})`;
|
|
23
|
+
});
|
|
24
|
+
this.graphStore = e, this.viewportStore = o, this.element = r, this.element.appendChild(this.host), this.host.appendChild(this.container), this.viewportStore.onAfterUpdated.subscribe(this.applyTransform);
|
|
25
|
+
}
|
|
26
|
+
attachNode(e) {
|
|
27
|
+
const o = this.graphStore.getNode(e), r = ce();
|
|
28
|
+
r.appendChild(o.element), this.container.appendChild(r), this.nodeIdToWrapperElementMap.set(e, r), this.updateNodePosition(e), this.updateNodePriority(e), r.style.visibility = "visible";
|
|
29
|
+
}
|
|
30
|
+
detachNode(e) {
|
|
31
|
+
const o = this.nodeIdToWrapperElementMap.get(e);
|
|
32
|
+
o.removeChild(o.firstChild), this.container.removeChild(o), this.nodeIdToWrapperElementMap.delete(e);
|
|
33
|
+
}
|
|
34
|
+
attachEdge(e) {
|
|
35
|
+
const o = this.graphStore.getEdge(e).shape.svg;
|
|
36
|
+
this.edgeIdToElementMap.set(e, o), this.container.appendChild(o), this.renderEdge(e), this.updateEdgePriority(e);
|
|
37
|
+
}
|
|
38
|
+
detachEdge(e) {
|
|
39
|
+
const o = this.edgeIdToElementMap.get(e);
|
|
40
|
+
this.container.removeChild(o), this.edgeIdToElementMap.delete(e);
|
|
41
|
+
}
|
|
42
|
+
clear() {
|
|
43
|
+
this.edgeIdToElementMap.forEach((e, o) => {
|
|
44
|
+
this.detachEdge(o);
|
|
45
|
+
}), this.nodeIdToWrapperElementMap.forEach((e, o) => {
|
|
46
|
+
this.detachNode(o);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
destroy() {
|
|
50
|
+
this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform), this.clear(), this.element.removeChild(this.host), this.host.removeChild(this.container);
|
|
51
|
+
}
|
|
52
|
+
updateNodePosition(e) {
|
|
53
|
+
const o = this.nodeIdToWrapperElementMap.get(e), r = this.graphStore.getNode(e), { width: s, height: d } = r.element.getBoundingClientRect(), n = this.viewportStore.getViewportMatrix().scale, h = r.centerFn(s, d), c = r.x - n * h.x, a = r.y - n * h.y;
|
|
54
|
+
o.style.transform = `translate(${c}px, ${a}px)`;
|
|
55
|
+
}
|
|
56
|
+
updateNodePriority(e) {
|
|
57
|
+
const o = this.graphStore.getNode(e), r = this.nodeIdToWrapperElementMap.get(e);
|
|
58
|
+
r.style.zIndex = `${o.priority}`;
|
|
59
|
+
}
|
|
60
|
+
updateEdgeShape(e) {
|
|
61
|
+
const o = this.edgeIdToElementMap.get(e);
|
|
62
|
+
this.container.removeChild(o);
|
|
63
|
+
const r = this.graphStore.getEdge(e);
|
|
64
|
+
this.edgeIdToElementMap.set(e, r.shape.svg), this.container.appendChild(r.shape.svg);
|
|
65
|
+
}
|
|
66
|
+
renderEdge(e) {
|
|
67
|
+
const o = this.graphStore.getEdge(e), r = this.graphStore.getPort(o.from), s = this.graphStore.getPort(o.to), d = r.element.getBoundingClientRect(), n = s.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), c = this.viewportStore.getViewportMatrix(), a = {
|
|
68
|
+
x: c.scale * (d.left - h.left) + c.x,
|
|
69
|
+
y: c.scale * (d.top - h.top) + c.y
|
|
70
|
+
}, l = {
|
|
71
|
+
x: c.scale * (n.left - h.left) + c.x,
|
|
72
|
+
y: c.scale * (n.top - h.top) + c.y
|
|
73
|
+
}, g = {
|
|
74
|
+
x: a.x,
|
|
75
|
+
y: a.y,
|
|
76
|
+
width: d.width * c.scale,
|
|
77
|
+
height: d.height * c.scale,
|
|
78
|
+
direction: r.direction,
|
|
79
|
+
portId: o.from,
|
|
80
|
+
nodeId: r.nodeId
|
|
81
|
+
}, f = {
|
|
82
|
+
x: l.x,
|
|
83
|
+
y: l.y,
|
|
84
|
+
width: n.width * c.scale,
|
|
85
|
+
height: n.height * c.scale,
|
|
86
|
+
direction: s.direction,
|
|
87
|
+
portId: o.to,
|
|
88
|
+
nodeId: s.nodeId
|
|
89
|
+
};
|
|
90
|
+
o.shape.render({
|
|
91
|
+
from: g,
|
|
92
|
+
to: f
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
updateEdgePriority(e) {
|
|
96
|
+
const o = this.graphStore.getEdge(e);
|
|
97
|
+
o.shape.svg.style.zIndex = `${o.priority}`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
class ge {
|
|
101
|
+
constructor(e) {
|
|
102
|
+
i(this, "xFrom", 1 / 0);
|
|
103
|
+
i(this, "yFrom", 1 / 0);
|
|
104
|
+
i(this, "xTo", 1 / 0);
|
|
105
|
+
i(this, "yTo", 1 / 0);
|
|
106
|
+
this.graphStore = e;
|
|
107
|
+
}
|
|
108
|
+
setRenderingBox(e) {
|
|
109
|
+
this.xFrom = e.x, this.xTo = e.x + e.width, this.yFrom = e.y, this.yTo = e.y + e.height;
|
|
110
|
+
}
|
|
111
|
+
hasNode(e) {
|
|
112
|
+
const o = this.graphStore.getNode(e);
|
|
113
|
+
return o.x >= this.xFrom && o.x <= this.xTo && o.y >= this.yFrom && o.y <= this.yTo;
|
|
114
|
+
}
|
|
115
|
+
hasEdge(e) {
|
|
116
|
+
const o = this.graphStore.getEdge(e), r = this.graphStore.getPort(o.from).nodeId, s = this.graphStore.getPort(o.to).nodeId, d = this.graphStore.getNode(r), n = this.graphStore.getNode(s), h = Math.min(d.x, n.x), c = Math.max(d.x, n.x), a = Math.min(d.y, n.y), l = Math.max(d.y, n.y);
|
|
117
|
+
return h <= this.xTo && c >= this.xFrom && a <= this.yTo && l >= this.yFrom;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class ue {
|
|
121
|
+
constructor(e, o, r) {
|
|
122
|
+
i(this, "attachedNodes", /* @__PURE__ */ new Set());
|
|
123
|
+
i(this, "attachedEdges", /* @__PURE__ */ new Set());
|
|
124
|
+
i(this, "renderingBox");
|
|
125
|
+
i(this, "updateViewport", (e) => {
|
|
126
|
+
this.renderingBox.setRenderingBox(e);
|
|
127
|
+
const o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
|
|
128
|
+
this.graphStore.getAllNodeIds().forEach((n) => {
|
|
129
|
+
const h = this.renderingBox.hasNode(n), c = this.attachedNodes.has(n);
|
|
130
|
+
h && !c ? o.add(n) : !h && c && r.add(n);
|
|
131
|
+
}), this.graphStore.getAllEdgeIds().forEach((n) => {
|
|
132
|
+
const h = this.renderingBox.hasEdge(n), c = this.attachedEdges.has(n), a = this.graphStore.getEdge(n), l = this.graphStore.getPort(a.from).nodeId, g = this.graphStore.getPort(a.to).nodeId;
|
|
133
|
+
h && (this.renderingBox.hasNode(l) || (o.add(l), r.delete(l)), this.renderingBox.hasNode(g) || (o.add(g), r.delete(g))), h && !c ? s.add(n) : !h && c && d.add(n);
|
|
134
|
+
}), d.forEach((n) => {
|
|
135
|
+
this.handleDetachEdge(n);
|
|
136
|
+
}), r.forEach((n) => {
|
|
137
|
+
this.handleDetachNode(n);
|
|
138
|
+
}), o.forEach((n) => {
|
|
139
|
+
this.attachedNodes.has(n) || this.handleAttachNode(n);
|
|
140
|
+
}), s.forEach((n) => {
|
|
141
|
+
this.handleAttachEdge(n);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
this.htmlView = e, this.graphStore = o, this.trigger = r, this.renderingBox = new ge(this.graphStore), this.trigger.subscribe(this.updateViewport);
|
|
145
|
+
}
|
|
146
|
+
attachNode(e) {
|
|
147
|
+
this.renderingBox.hasNode(e) && this.handleAttachNode(e);
|
|
148
|
+
}
|
|
149
|
+
detachNode(e) {
|
|
150
|
+
this.attachedNodes.has(e) && this.handleDetachNode(e);
|
|
151
|
+
}
|
|
152
|
+
attachEdge(e) {
|
|
153
|
+
this.renderingBox.hasEdge(e) && this.attachEdgeEntities(e);
|
|
154
|
+
}
|
|
155
|
+
detachEdge(e) {
|
|
156
|
+
this.attachedEdges.has(e) && this.handleDetachEdge(e);
|
|
157
|
+
}
|
|
158
|
+
updateNodePosition(e) {
|
|
159
|
+
this.attachedNodes.has(e) ? this.htmlView.updateNodePosition(e) : this.renderingBox.hasNode(e) && (this.handleAttachNode(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((o) => {
|
|
160
|
+
this.attachEdgeEntities(o);
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
updateNodePriority(e) {
|
|
164
|
+
this.attachedNodes.has(e) && this.htmlView.updateNodePriority(e);
|
|
165
|
+
}
|
|
166
|
+
updateEdgeShape(e) {
|
|
167
|
+
this.attachedEdges.has(e) && this.htmlView.updateEdgeShape(e);
|
|
168
|
+
}
|
|
169
|
+
renderEdge(e) {
|
|
170
|
+
this.attachedEdges.has(e) && this.htmlView.renderEdge(e);
|
|
171
|
+
}
|
|
172
|
+
updateEdgePriority(e) {
|
|
173
|
+
this.attachedEdges.has(e) && this.htmlView.updateEdgePriority(e);
|
|
174
|
+
}
|
|
175
|
+
clear() {
|
|
176
|
+
this.htmlView.clear(), this.attachedNodes.clear(), this.attachedEdges.clear();
|
|
177
|
+
}
|
|
178
|
+
destroy() {
|
|
179
|
+
this.clear(), this.htmlView.destroy(), this.trigger.unsubscribe(this.updateViewport);
|
|
180
|
+
}
|
|
181
|
+
attachEdgeEntities(e) {
|
|
182
|
+
const o = this.graphStore.getEdge(e), r = this.graphStore.getPort(o.from).nodeId, s = this.graphStore.getPort(o.to).nodeId;
|
|
183
|
+
this.attachedNodes.has(r) || this.handleAttachNode(r), this.attachedNodes.has(s) || this.handleAttachNode(s), this.handleAttachEdge(e);
|
|
184
|
+
}
|
|
185
|
+
handleAttachNode(e) {
|
|
186
|
+
this.attachedNodes.add(e), this.htmlView.attachNode(e);
|
|
187
|
+
}
|
|
188
|
+
handleDetachNode(e) {
|
|
189
|
+
this.htmlView.detachNode(e), this.attachedNodes.delete(e);
|
|
190
|
+
}
|
|
191
|
+
handleAttachEdge(e) {
|
|
192
|
+
this.attachedEdges.add(e), this.htmlView.attachEdge(e);
|
|
193
|
+
}
|
|
194
|
+
handleDetachEdge(e) {
|
|
195
|
+
this.htmlView.detachEdge(e), this.attachedEdges.delete(e);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
class se {
|
|
199
|
+
constructor() {
|
|
200
|
+
i(this, "callbacks", /* @__PURE__ */ new Set());
|
|
201
|
+
}
|
|
202
|
+
subscribe(e) {
|
|
203
|
+
this.callbacks.add(e);
|
|
204
|
+
}
|
|
205
|
+
unsubscribe(e) {
|
|
206
|
+
this.callbacks.delete(e);
|
|
207
|
+
}
|
|
208
|
+
emit(e) {
|
|
209
|
+
this.callbacks.forEach((o) => {
|
|
210
|
+
o(e);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const A = () => {
|
|
215
|
+
const t = new se();
|
|
216
|
+
return [t, t];
|
|
217
|
+
};
|
|
218
|
+
class we {
|
|
219
|
+
constructor(e) {
|
|
220
|
+
i(this, "onBeforeUpdated");
|
|
221
|
+
i(this, "onAfterUpdated");
|
|
222
|
+
this.transformer = e, this.onBeforeUpdated = this.transformer.onBeforeUpdated, this.onAfterUpdated = this.transformer.onAfterUpdated;
|
|
223
|
+
}
|
|
224
|
+
getViewportMatrix() {
|
|
225
|
+
return { ...this.transformer.getViewportMatrix() };
|
|
226
|
+
}
|
|
227
|
+
getContentMatrix() {
|
|
228
|
+
return { ...this.transformer.getContentMatrix() };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
class fe {
|
|
5
232
|
constructor(e) {
|
|
6
233
|
i(this, "onAfterNodeAdded");
|
|
7
234
|
i(this, "onAfterNodeUpdated");
|
|
@@ -77,916 +304,42 @@ class ie {
|
|
|
77
304
|
return this.graphStore.getNode(e) === void 0 ? null : this.graphStore.getNodeAdjacentEdgeIds(e);
|
|
78
305
|
}
|
|
79
306
|
}
|
|
80
|
-
class
|
|
307
|
+
class X {
|
|
81
308
|
constructor(e) {
|
|
82
|
-
i(this, "
|
|
83
|
-
|
|
84
|
-
this.transformer = e, this.onBeforeUpdated = this.transformer.onBeforeUpdated, this.onAfterUpdated = this.transformer.onAfterUpdated;
|
|
309
|
+
i(this, "counter", 0);
|
|
310
|
+
this.checkExists = e;
|
|
85
311
|
}
|
|
86
|
-
|
|
87
|
-
|
|
312
|
+
create(e) {
|
|
313
|
+
if (e !== void 0)
|
|
314
|
+
return e;
|
|
315
|
+
for (; this.checkExists(this.counter); )
|
|
316
|
+
this.counter++;
|
|
317
|
+
return this.counter;
|
|
88
318
|
}
|
|
89
|
-
|
|
90
|
-
|
|
319
|
+
reset() {
|
|
320
|
+
this.counter = 0;
|
|
91
321
|
}
|
|
92
322
|
}
|
|
93
|
-
class
|
|
94
|
-
constructor(e, o, r) {
|
|
95
|
-
i(this, "viewport");
|
|
96
|
-
i(this, "graph");
|
|
97
|
-
i(this, "onAfterNodeAdded", (e) => {
|
|
98
|
-
this.htmlView.attachNode(e);
|
|
99
|
-
});
|
|
100
|
-
i(this, "onAfterNodeUpdated", (e) => {
|
|
101
|
-
this.htmlView.updateNodePosition(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((r) => {
|
|
102
|
-
this.htmlView.renderEdge(r);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
i(this, "onAfterNodePriorityUpdated", (e) => {
|
|
106
|
-
this.htmlView.updateNodePriority(e);
|
|
107
|
-
});
|
|
108
|
-
i(this, "onBeforeNodeRemoved", (e) => {
|
|
109
|
-
this.graphStore.getNodePortIds(e).forEach((o) => {
|
|
110
|
-
this.unmarkPort(o);
|
|
111
|
-
}), this.htmlView.detachNode(e);
|
|
112
|
-
});
|
|
113
|
-
i(this, "onAfterPortUpdated", (e) => {
|
|
114
|
-
this.graphStore.getPortAdjacentEdgeIds(e).forEach((r) => {
|
|
115
|
-
this.htmlView.renderEdge(r);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
i(this, "onBeforePortUnmarked", (e) => {
|
|
119
|
-
this.graphStore.getPortAdjacentEdgeIds(e).forEach((o) => {
|
|
120
|
-
this.removeEdge(o);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
i(this, "onAfterEdgeAdded", (e) => {
|
|
124
|
-
this.htmlView.attachEdge(e);
|
|
125
|
-
});
|
|
126
|
-
i(this, "onAfterEdgeShapeUpdated", (e) => {
|
|
127
|
-
this.htmlView.updateEdgeShape(e);
|
|
128
|
-
});
|
|
129
|
-
i(this, "onAfterEdgeUpdated", (e) => {
|
|
130
|
-
this.htmlView.renderEdge(e);
|
|
131
|
-
});
|
|
132
|
-
i(this, "onAfterEdgePriorityUpdated", (e) => {
|
|
133
|
-
this.htmlView.updateEdgePriority(e);
|
|
134
|
-
});
|
|
135
|
-
i(this, "onBeforeEdgeRemoved", (e) => {
|
|
136
|
-
this.htmlView.detachEdge(e);
|
|
137
|
-
});
|
|
138
|
-
i(this, "onBeforeClear", () => {
|
|
139
|
-
this.htmlView.clear();
|
|
140
|
-
});
|
|
141
|
-
this.graphStore = e, this.viewportStore = o, this.htmlView = r, this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.subscribe(
|
|
142
|
-
this.onAfterNodePriorityUpdated
|
|
143
|
-
), this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated), this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked), this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded), this.graphStore.onAfterEdgeShapeUpdated.subscribe(
|
|
144
|
-
this.onAfterEdgeShapeUpdated
|
|
145
|
-
), this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.subscribe(
|
|
146
|
-
this.onAfterEdgePriorityUpdated
|
|
147
|
-
), this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.subscribe(this.onBeforeClear), this.graph = new ie(this.graphStore), this.viewport = new se(this.viewportStore);
|
|
148
|
-
}
|
|
149
|
-
addNode(e) {
|
|
150
|
-
this.graphStore.addNode(e);
|
|
151
|
-
}
|
|
152
|
-
updateNode(e, o) {
|
|
153
|
-
this.graphStore.updateNode(e, o);
|
|
154
|
-
}
|
|
155
|
-
removeNode(e) {
|
|
156
|
-
this.graphStore.removeNode(e);
|
|
157
|
-
}
|
|
158
|
-
markPort(e) {
|
|
159
|
-
this.graphStore.addPort(e);
|
|
160
|
-
}
|
|
161
|
-
updatePort(e, o) {
|
|
162
|
-
this.graphStore.updatePort(e, o);
|
|
163
|
-
}
|
|
164
|
-
unmarkPort(e) {
|
|
165
|
-
this.graphStore.removePort(e);
|
|
166
|
-
}
|
|
167
|
-
addEdge(e) {
|
|
168
|
-
this.graphStore.addEdge(e);
|
|
169
|
-
}
|
|
170
|
-
updateEdge(e, o) {
|
|
171
|
-
this.graphStore.updateEdge(e, o);
|
|
172
|
-
}
|
|
173
|
-
removeEdge(e) {
|
|
174
|
-
this.graphStore.removeEdge(e);
|
|
175
|
-
}
|
|
176
|
-
patchViewportMatrix(e) {
|
|
177
|
-
this.viewportStore.patchViewportMatrix(e);
|
|
178
|
-
}
|
|
179
|
-
patchContentMatrix(e) {
|
|
180
|
-
this.viewportStore.patchContentMatrix(e);
|
|
181
|
-
}
|
|
182
|
-
clear() {
|
|
183
|
-
this.graphStore.clear();
|
|
184
|
-
}
|
|
185
|
-
destroy() {
|
|
186
|
-
this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.unsubscribe(
|
|
187
|
-
this.onAfterNodePriorityUpdated
|
|
188
|
-
), this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved), this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated), this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked), this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded), this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(
|
|
189
|
-
this.onAfterEdgeShapeUpdated
|
|
190
|
-
), this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(
|
|
191
|
-
this.onAfterEdgePriorityUpdated
|
|
192
|
-
), this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear), this.clear(), this.htmlView.destroy();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
const U = (t, e, o) => {
|
|
196
|
-
const { x: r, y: s, width: d, height: n } = t.getBoundingClientRect();
|
|
197
|
-
return e >= r && e <= r + d && o >= s && o <= s + n;
|
|
198
|
-
}, $ = (t, e, o) => e >= 0 && e <= t.innerWidth && o >= 0 && o <= t.innerHeight, R = (t, e) => {
|
|
199
|
-
e !== null ? t.style.cursor = e : t.style.removeProperty("cursor");
|
|
200
|
-
}, he = (t) => {
|
|
201
|
-
var g, f, x, y, p, S;
|
|
202
|
-
const e = ((g = t == null ? void 0 : t.events) == null ? void 0 : g.onNodeDrag) ?? (() => {
|
|
203
|
-
}), o = ((f = t == null ? void 0 : t.events) == null ? void 0 : f.onBeforeNodeDrag) ?? (() => !0), r = ((x = t == null ? void 0 : t.events) == null ? void 0 : x.onNodeDragFinished) ?? (() => {
|
|
204
|
-
}), s = (t == null ? void 0 : t.moveOnTop) === !1, d = (y = t == null ? void 0 : t.mouse) == null ? void 0 : y.dragCursor, n = d !== void 0 ? d : "grab", h = (p = t == null ? void 0 : t.mouse) == null ? void 0 : p.mouseDownEventVerifier, c = h !== void 0 ? h : (N) => N.button === 0, a = (S = t == null ? void 0 : t.mouse) == null ? void 0 : S.mouseUpEventVerifier;
|
|
205
|
-
return {
|
|
206
|
-
freezePriority: s,
|
|
207
|
-
dragCursor: n,
|
|
208
|
-
mouseDownEventVerifier: c,
|
|
209
|
-
mouseUpEventVerifier: a !== void 0 ? a : (N) => N.button === 0,
|
|
210
|
-
onNodeDrag: e,
|
|
211
|
-
onBeforeNodeDrag: o,
|
|
212
|
-
onNodeDragFinished: r
|
|
213
|
-
};
|
|
214
|
-
};
|
|
215
|
-
class de {
|
|
216
|
-
constructor(e, o, r) {
|
|
217
|
-
i(this, "graph");
|
|
218
|
-
i(this, "viewport");
|
|
219
|
-
i(this, "maxNodePriority", 0);
|
|
220
|
-
i(this, "nodes", /* @__PURE__ */ new Map());
|
|
221
|
-
i(this, "grabbedNodeId", null);
|
|
222
|
-
i(this, "onWindowMouseMove", (e) => {
|
|
223
|
-
if (!U(this.element, e.clientX, e.clientY) || !$(this.window, e.clientX, e.clientY)) {
|
|
224
|
-
this.cancelMouseDrag();
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
|
|
228
|
-
});
|
|
229
|
-
i(this, "onWindowMouseUp", (e) => {
|
|
230
|
-
this.options.mouseUpEventVerifier(e) && this.cancelMouseDrag();
|
|
231
|
-
});
|
|
232
|
-
i(this, "onWindowTouchMove", (e) => {
|
|
233
|
-
if (e.touches.length !== 1)
|
|
234
|
-
return;
|
|
235
|
-
const o = e.touches[0];
|
|
236
|
-
if (!U(this.element, o.clientX, o.clientY) || !$(this.window, o.clientX, o.clientY)) {
|
|
237
|
-
this.cancelTouchDrag();
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if (this.grabbedNodeId !== null && this.previousTouchCoords !== null) {
|
|
241
|
-
const r = o.clientX - this.previousTouchCoords.x, s = o.clientY - this.previousTouchCoords.y;
|
|
242
|
-
this.dragNode(this.grabbedNodeId, r, s), this.previousTouchCoords = {
|
|
243
|
-
x: e.touches[0].clientX,
|
|
244
|
-
y: e.touches[0].clientY
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
i(this, "onWindowTouchFinish", () => {
|
|
249
|
-
this.previousTouchCoords = null, this.cancelTouchDrag();
|
|
250
|
-
});
|
|
251
|
-
i(this, "previousTouchCoords", null);
|
|
252
|
-
i(this, "window", window);
|
|
253
|
-
i(this, "options");
|
|
254
|
-
this.canvas = e, this.element = o, this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.options = he(r ?? {});
|
|
255
|
-
}
|
|
256
|
-
addNode(e) {
|
|
257
|
-
this.canvas.addNode(e), this.updateMaxNodePriority(e.id);
|
|
258
|
-
const o = (s) => {
|
|
259
|
-
if (!this.options.mouseDownEventVerifier(s))
|
|
260
|
-
return;
|
|
261
|
-
const d = this.graph.getNode(e.id);
|
|
262
|
-
this.options.onBeforeNodeDrag({
|
|
263
|
-
nodeId: e.id,
|
|
264
|
-
element: e.element,
|
|
265
|
-
x: d.x,
|
|
266
|
-
y: d.y
|
|
267
|
-
}) && (s.stopImmediatePropagation(), this.grabbedNodeId = e.id, R(this.element, this.options.dragCursor), this.moveNodeOnTop(e.id), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
|
|
268
|
-
}, r = (s) => {
|
|
269
|
-
if (s.touches.length !== 1)
|
|
270
|
-
return;
|
|
271
|
-
s.stopImmediatePropagation(), this.previousTouchCoords = {
|
|
272
|
-
x: s.touches[0].clientX,
|
|
273
|
-
y: s.touches[0].clientY
|
|
274
|
-
};
|
|
275
|
-
const d = this.graph.getNode(e.id);
|
|
276
|
-
this.options.onBeforeNodeDrag({
|
|
277
|
-
nodeId: e.id,
|
|
278
|
-
element: e.element,
|
|
279
|
-
x: d.x,
|
|
280
|
-
y: d.y
|
|
281
|
-
}) && (this.grabbedNodeId = e.id, this.moveNodeOnTop(e.id), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish));
|
|
282
|
-
};
|
|
283
|
-
this.nodes.set(e.id, {
|
|
284
|
-
element: e.element,
|
|
285
|
-
onMouseDown: o,
|
|
286
|
-
onTouchStart: r
|
|
287
|
-
}), e.element.addEventListener("mousedown", o), e.element.addEventListener("touchstart", r);
|
|
288
|
-
}
|
|
289
|
-
updateNode(e, o) {
|
|
290
|
-
this.canvas.updateNode(e, o), this.updateMaxNodePriority(e);
|
|
291
|
-
}
|
|
292
|
-
removeNode(e) {
|
|
293
|
-
const o = this.nodes.get(e);
|
|
294
|
-
o !== void 0 && (o.element.removeEventListener("mousedown", o.onMouseDown), o.element.removeEventListener("touchstart", o.onTouchStart)), this.nodes.delete(e), this.canvas.removeNode(e);
|
|
295
|
-
}
|
|
296
|
-
markPort(e) {
|
|
297
|
-
this.canvas.markPort(e);
|
|
298
|
-
}
|
|
299
|
-
updatePort(e, o) {
|
|
300
|
-
this.canvas.updatePort(e, o);
|
|
301
|
-
}
|
|
302
|
-
unmarkPort(e) {
|
|
303
|
-
this.canvas.unmarkPort(e);
|
|
304
|
-
}
|
|
305
|
-
addEdge(e) {
|
|
306
|
-
this.canvas.addEdge(e);
|
|
307
|
-
}
|
|
308
|
-
updateEdge(e, o) {
|
|
309
|
-
this.canvas.updateEdge(e, o);
|
|
310
|
-
}
|
|
311
|
-
removeEdge(e) {
|
|
312
|
-
this.canvas.removeEdge(e);
|
|
313
|
-
}
|
|
314
|
-
patchViewportMatrix(e) {
|
|
315
|
-
this.canvas.patchViewportMatrix(e);
|
|
316
|
-
}
|
|
317
|
-
patchContentMatrix(e) {
|
|
318
|
-
this.canvas.patchContentMatrix(e);
|
|
319
|
-
}
|
|
320
|
-
clear() {
|
|
321
|
-
this.canvas.clear(), this.nodes.forEach((e) => {
|
|
322
|
-
e.element.removeEventListener("mousedown", e.onMouseDown), e.element.removeEventListener("touchstart", e.onTouchStart);
|
|
323
|
-
}), this.nodes.clear(), this.maxNodePriority = 0;
|
|
324
|
-
}
|
|
325
|
-
destroy() {
|
|
326
|
-
this.clear(), this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.canvas.destroy();
|
|
327
|
-
}
|
|
328
|
-
dragNode(e, o, r) {
|
|
329
|
-
const s = this.graph.getNode(e);
|
|
330
|
-
if (s === null)
|
|
331
|
-
return;
|
|
332
|
-
const d = this.canvas.viewport.getContentMatrix(), n = d.scale * s.x + d.x, h = d.scale * s.y + d.y, c = n + o, a = h + r, l = this.canvas.viewport.getViewportMatrix(), g = l.scale * c + l.x, f = l.scale * a + l.y;
|
|
333
|
-
this.canvas.updateNode(e, { x: g, y: f }), this.options.onNodeDrag({
|
|
334
|
-
nodeId: e,
|
|
335
|
-
element: s.element,
|
|
336
|
-
x: g,
|
|
337
|
-
y: f
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
updateMaxNodePriority(e) {
|
|
341
|
-
const o = this.graph.getNode(e).priority;
|
|
342
|
-
this.maxNodePriority = Math.max(this.maxNodePriority, o);
|
|
343
|
-
}
|
|
344
|
-
moveNodeOnTop(e) {
|
|
345
|
-
if (this.options.freezePriority)
|
|
346
|
-
return;
|
|
347
|
-
this.maxNodePriority += 2, this.updateNode(e, { priority: this.maxNodePriority });
|
|
348
|
-
const o = this.maxNodePriority - 1;
|
|
349
|
-
this.graph.getNodeAdjacentEdgeIds(e).forEach((s) => {
|
|
350
|
-
this.updateEdge(s, { priority: o });
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
cancelMouseDrag() {
|
|
354
|
-
const e = this.graph.getNode(this.grabbedNodeId);
|
|
355
|
-
e !== null && this.options.onNodeDragFinished({
|
|
356
|
-
nodeId: this.grabbedNodeId,
|
|
357
|
-
element: e.element,
|
|
358
|
-
x: e.x,
|
|
359
|
-
y: e.y
|
|
360
|
-
}), this.grabbedNodeId = null, R(this.element, null), this.removeMouseDragListeners();
|
|
361
|
-
}
|
|
362
|
-
removeMouseDragListeners() {
|
|
363
|
-
this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
364
|
-
}
|
|
365
|
-
cancelTouchDrag() {
|
|
366
|
-
this.previousTouchCoords = null;
|
|
367
|
-
const e = this.graph.getNode(this.grabbedNodeId);
|
|
368
|
-
e !== null && this.options.onNodeDragFinished({
|
|
369
|
-
nodeId: this.grabbedNodeId,
|
|
370
|
-
element: e.element,
|
|
371
|
-
x: e.x,
|
|
372
|
-
y: e.y
|
|
373
|
-
}), this.grabbedNodeId = null, this.removeTouchDragListeners();
|
|
374
|
-
}
|
|
375
|
-
removeTouchDragListeners() {
|
|
376
|
-
this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
const ce = (t) => {
|
|
380
|
-
const e = t.minX !== null ? t.minX : -1 / 0, o = t.maxX !== null ? t.maxX : 1 / 0, r = t.minY !== null ? t.minY : -1 / 0, s = t.maxY !== null ? t.maxY : 1 / 0;
|
|
381
|
-
return (d) => {
|
|
382
|
-
let n = d.nextTransform.x, h = d.nextTransform.y;
|
|
383
|
-
n < e && n < d.prevTransform.x && (n = Math.min(d.prevTransform.x, e));
|
|
384
|
-
const c = d.canvasWidth * d.prevTransform.scale, a = o - c;
|
|
385
|
-
n > a && n > d.prevTransform.x && (n = Math.max(d.prevTransform.x, a)), h < r && h < d.prevTransform.y && (h = Math.min(d.prevTransform.y, r));
|
|
386
|
-
const l = d.canvasHeight * d.prevTransform.scale, g = s - l;
|
|
387
|
-
return h > g && h > d.prevTransform.y && (h = Math.max(d.prevTransform.y, g)), { scale: d.nextTransform.scale, x: n, y: h };
|
|
388
|
-
};
|
|
389
|
-
}, ae = (t) => {
|
|
390
|
-
const e = t.maxContentScale, o = t.minContentScale, r = e !== null ? 1 / e : 0, s = o !== null ? 1 / o : 1 / 0;
|
|
391
|
-
return (d) => {
|
|
392
|
-
const n = d.prevTransform, h = d.nextTransform;
|
|
393
|
-
let c = h.scale, a = h.x, l = h.y;
|
|
394
|
-
if (h.scale > s && h.scale > n.scale) {
|
|
395
|
-
c = Math.max(n.scale, s), a = n.x, l = n.y;
|
|
396
|
-
const g = (c - n.scale) / (h.scale - n.scale);
|
|
397
|
-
a = n.x + (h.x - n.x) * g, l = n.y + (h.y - n.y) * g;
|
|
398
|
-
}
|
|
399
|
-
if (h.scale < r && h.scale < n.scale) {
|
|
400
|
-
c = Math.min(n.scale, r), a = n.x, l = n.y;
|
|
401
|
-
const g = (c - n.scale) / (h.scale - n.scale);
|
|
402
|
-
a = n.x + (h.x - n.x) * g, l = n.y + (h.y - n.y) * g;
|
|
403
|
-
}
|
|
404
|
-
return {
|
|
405
|
-
scale: c,
|
|
406
|
-
x: a,
|
|
407
|
-
y: l
|
|
408
|
-
};
|
|
409
|
-
};
|
|
410
|
-
}, le = (t) => (e) => t.reduce(
|
|
411
|
-
(o, r) => r({
|
|
412
|
-
prevTransform: e.prevTransform,
|
|
413
|
-
nextTransform: o,
|
|
414
|
-
canvasWidth: e.canvasWidth,
|
|
415
|
-
canvasHeight: e.canvasHeight
|
|
416
|
-
}),
|
|
417
|
-
e.nextTransform
|
|
418
|
-
), Q = (t) => {
|
|
419
|
-
if (typeof t == "function")
|
|
420
|
-
return t;
|
|
421
|
-
switch (t.type) {
|
|
422
|
-
case "scale-limit":
|
|
423
|
-
return ae({
|
|
424
|
-
minContentScale: t.minContentScale ?? 0,
|
|
425
|
-
maxContentScale: t.maxContentScale ?? 1 / 0
|
|
426
|
-
});
|
|
427
|
-
case "shift-limit":
|
|
428
|
-
return ce({
|
|
429
|
-
minX: t.minX ?? -1 / 0,
|
|
430
|
-
maxX: t.maxX ?? 1 / 0,
|
|
431
|
-
minY: t.minY ?? -1 / 0,
|
|
432
|
-
maxY: t.maxY ?? 1 / 0
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
}, ge = (t) => {
|
|
436
|
-
var y, p, S, N, z, M, V, L, G, _, J, K;
|
|
437
|
-
const e = (y = t == null ? void 0 : t.scale) == null ? void 0 : y.mouseWheelSensitivity, o = e !== void 0 ? e : 1.2, r = t == null ? void 0 : t.transformPreprocessor;
|
|
438
|
-
let s;
|
|
439
|
-
r !== void 0 ? Array.isArray(r) ? s = le(
|
|
440
|
-
r.map(
|
|
441
|
-
(P) => Q(P)
|
|
442
|
-
)
|
|
443
|
-
) : s = Q(r) : s = (P) => P.nextTransform;
|
|
444
|
-
const d = ((p = t == null ? void 0 : t.shift) == null ? void 0 : p.cursor) !== void 0 ? t.shift.cursor : "grab", n = ((S = t == null ? void 0 : t.events) == null ? void 0 : S.onBeforeTransformChange) ?? (() => {
|
|
445
|
-
}), h = ((N = t == null ? void 0 : t.events) == null ? void 0 : N.onTransformChange) ?? (() => {
|
|
446
|
-
}), c = (z = t == null ? void 0 : t.shift) == null ? void 0 : z.mouseDownEventVerifier, a = c !== void 0 ? c : (P) => P.button === 0, l = (M = t == null ? void 0 : t.shift) == null ? void 0 : M.mouseUpEventVerifier, g = l !== void 0 ? l : (P) => P.button === 0, f = (V = t == null ? void 0 : t.scale) == null ? void 0 : V.mouseWheelEventVerifier, x = f !== void 0 ? f : () => !0;
|
|
447
|
-
return {
|
|
448
|
-
wheelSensitivity: o,
|
|
449
|
-
onTransformStarted: ((L = t == null ? void 0 : t.events) == null ? void 0 : L.onTransformStarted) ?? (() => {
|
|
450
|
-
}),
|
|
451
|
-
onTransformFinished: ((G = t == null ? void 0 : t.events) == null ? void 0 : G.onTransformFinished) ?? (() => {
|
|
452
|
-
}),
|
|
453
|
-
onBeforeTransformChange: n,
|
|
454
|
-
onTransformChange: h,
|
|
455
|
-
transformPreprocessor: s,
|
|
456
|
-
shiftCursor: d,
|
|
457
|
-
mouseDownEventVerifier: a,
|
|
458
|
-
mouseUpEventVerifier: g,
|
|
459
|
-
mouseWheelEventVerifier: x,
|
|
460
|
-
scaleWheelFinishTimeout: ((_ = t == null ? void 0 : t.scale) == null ? void 0 : _.wheelFinishTimeout) ?? 500,
|
|
461
|
-
onResizeTransformStarted: ((J = t == null ? void 0 : t.events) == null ? void 0 : J.onResizeTransformStarted) ?? (() => {
|
|
462
|
-
}),
|
|
463
|
-
onResizeTransformFinished: ((K = t == null ? void 0 : t.events) == null ? void 0 : K.onResizeTransformFinished) ?? (() => {
|
|
464
|
-
})
|
|
465
|
-
};
|
|
466
|
-
}, C = (t) => {
|
|
467
|
-
const e = [], o = t.touches.length;
|
|
468
|
-
for (let h = 0; h < o; h++)
|
|
469
|
-
e.push([t.touches[h].clientX, t.touches[h].clientY]);
|
|
470
|
-
const r = e.reduce(
|
|
471
|
-
(h, c) => [h[0] + c[0], h[1] + c[1]],
|
|
472
|
-
[0, 0]
|
|
473
|
-
), s = [r[0] / o, r[1] / o], n = e.map((h) => [h[0] - s[0], h[1] - s[1]]).reduce(
|
|
474
|
-
(h, c) => h + Math.sqrt(c[0] * c[0] + c[1] * c[1]),
|
|
475
|
-
0
|
|
476
|
-
);
|
|
477
|
-
return {
|
|
478
|
-
x: s[0],
|
|
479
|
-
y: s[1],
|
|
480
|
-
scale: n / o,
|
|
481
|
-
touchesCnt: o,
|
|
482
|
-
touches: e
|
|
483
|
-
};
|
|
484
|
-
}, ue = (t, e, o) => ({
|
|
485
|
-
scale: t.scale,
|
|
486
|
-
x: t.x + t.scale * e,
|
|
487
|
-
y: t.y + t.scale * o
|
|
488
|
-
}), we = (t, e, o, r) => ({
|
|
489
|
-
scale: t.scale * e,
|
|
490
|
-
x: t.scale * (1 - e) * o + t.x,
|
|
491
|
-
y: t.scale * (1 - e) * r + t.y
|
|
492
|
-
});
|
|
493
|
-
class ee {
|
|
494
|
-
constructor(e, o, r) {
|
|
495
|
-
i(this, "graph");
|
|
496
|
-
i(this, "viewport");
|
|
497
|
-
i(this, "prevTouches", null);
|
|
498
|
-
i(this, "window", window);
|
|
499
|
-
i(this, "wheelFinishTimer", null);
|
|
500
|
-
i(this, "onMouseDown", (e) => {
|
|
501
|
-
this.element === null || !this.options.mouseDownEventVerifier(e) || (R(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.options.onTransformStarted());
|
|
502
|
-
});
|
|
503
|
-
i(this, "onWindowMouseMove", (e) => {
|
|
504
|
-
if (this.element === null || !U(this.element, e.clientX, e.clientY) || !$(this.window, e.clientX, e.clientY)) {
|
|
505
|
-
this.stopMouseDrag();
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
const o = -e.movementX, r = -e.movementY;
|
|
509
|
-
this.moveViewport(o, r);
|
|
510
|
-
});
|
|
511
|
-
i(this, "onWindowMouseUp", (e) => {
|
|
512
|
-
this.element === null || !this.options.mouseUpEventVerifier(e) || this.stopMouseDrag();
|
|
513
|
-
});
|
|
514
|
-
i(this, "onWheelScroll", (e) => {
|
|
515
|
-
if (!this.options.mouseWheelEventVerifier(e))
|
|
516
|
-
return;
|
|
517
|
-
e.preventDefault();
|
|
518
|
-
const { left: o, top: r } = this.element.getBoundingClientRect(), s = e.clientX - o, d = e.clientY - r, h = 1 / (e.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
|
|
519
|
-
this.wheelFinishTimer === null && this.options.onTransformStarted(), this.scaleViewport(h, s, d), this.wheelFinishTimer !== null && clearTimeout(this.wheelFinishTimer), this.wheelFinishTimer = setTimeout(() => {
|
|
520
|
-
this.options.onTransformFinished(), this.wheelFinishTimer = null;
|
|
521
|
-
}, this.options.scaleWheelFinishTimeout);
|
|
522
|
-
});
|
|
523
|
-
i(this, "onTouchStart", (e) => {
|
|
524
|
-
if (this.prevTouches !== null) {
|
|
525
|
-
this.prevTouches = C(e);
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
this.prevTouches = C(e), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish), this.options.onTransformStarted();
|
|
529
|
-
});
|
|
530
|
-
i(this, "onWindowTouchMove", (e) => {
|
|
531
|
-
const o = C(e);
|
|
532
|
-
if (!o.touches.every(
|
|
533
|
-
(s) => U(this.element, s[0], s[1]) && $(this.window, s[0], s[1])
|
|
534
|
-
)) {
|
|
535
|
-
this.stopTouchDrag();
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
if ((o.touchesCnt === 1 || o.touchesCnt === 2) && this.moveViewport(
|
|
539
|
-
-(o.x - this.prevTouches.x),
|
|
540
|
-
-(o.y - this.prevTouches.y)
|
|
541
|
-
), o.touchesCnt === 2) {
|
|
542
|
-
const { left: s, top: d } = this.element.getBoundingClientRect(), n = this.prevTouches.x - s, h = this.prevTouches.y - d, a = 1 / (o.scale / this.prevTouches.scale);
|
|
543
|
-
this.scaleViewport(a, n, h);
|
|
544
|
-
}
|
|
545
|
-
this.prevTouches = o;
|
|
546
|
-
});
|
|
547
|
-
i(this, "onWindowTouchFinish", (e) => {
|
|
548
|
-
e.touches.length > 0 ? this.prevTouches = C(e) : this.stopTouchDrag();
|
|
549
|
-
});
|
|
550
|
-
i(this, "observer", new ResizeObserver(() => {
|
|
551
|
-
const e = this.canvas.viewport.getViewportMatrix(), { width: o, height: r } = this.element.getBoundingClientRect(), s = this.options.transformPreprocessor({
|
|
552
|
-
prevTransform: e,
|
|
553
|
-
nextTransform: e,
|
|
554
|
-
canvasWidth: o,
|
|
555
|
-
canvasHeight: r
|
|
556
|
-
});
|
|
557
|
-
this.options.onResizeTransformStarted(), this.canvas.patchViewportMatrix(s), this.options.onResizeTransformFinished();
|
|
558
|
-
}));
|
|
559
|
-
i(this, "options");
|
|
560
|
-
this.canvas = e, this.element = o, this.options = ge(r), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart);
|
|
561
|
-
}
|
|
562
|
-
addNode(e) {
|
|
563
|
-
this.canvas.addNode(e);
|
|
564
|
-
}
|
|
565
|
-
updateNode(e, o) {
|
|
566
|
-
this.canvas.updateNode(e, o);
|
|
567
|
-
}
|
|
568
|
-
removeNode(e) {
|
|
569
|
-
this.canvas.removeNode(e);
|
|
570
|
-
}
|
|
571
|
-
markPort(e) {
|
|
572
|
-
this.canvas.markPort(e);
|
|
573
|
-
}
|
|
574
|
-
updatePort(e, o) {
|
|
575
|
-
this.canvas.updatePort(e, o);
|
|
576
|
-
}
|
|
577
|
-
unmarkPort(e) {
|
|
578
|
-
this.canvas.unmarkPort(e);
|
|
579
|
-
}
|
|
580
|
-
addEdge(e) {
|
|
581
|
-
this.canvas.addEdge(e);
|
|
582
|
-
}
|
|
583
|
-
updateEdge(e, o) {
|
|
584
|
-
this.canvas.updateEdge(e, o);
|
|
585
|
-
}
|
|
586
|
-
removeEdge(e) {
|
|
587
|
-
this.canvas.removeEdge(e);
|
|
588
|
-
}
|
|
589
|
-
patchViewportMatrix(e) {
|
|
590
|
-
this.canvas.patchViewportMatrix(e);
|
|
591
|
-
}
|
|
592
|
-
patchContentMatrix(e) {
|
|
593
|
-
this.canvas.patchContentMatrix(e);
|
|
594
|
-
}
|
|
595
|
-
clear() {
|
|
596
|
-
this.canvas.clear();
|
|
597
|
-
}
|
|
598
|
-
destroy() {
|
|
599
|
-
this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.canvas.destroy();
|
|
600
|
-
}
|
|
601
|
-
moveViewport(e, o) {
|
|
602
|
-
const r = this.viewport.getViewportMatrix(), s = ue(r, e, o), { width: d, height: n } = this.element.getBoundingClientRect(), h = this.options.transformPreprocessor({
|
|
603
|
-
prevTransform: r,
|
|
604
|
-
nextTransform: s,
|
|
605
|
-
canvasWidth: d,
|
|
606
|
-
canvasHeight: n
|
|
607
|
-
});
|
|
608
|
-
this.performTransform(h);
|
|
609
|
-
}
|
|
610
|
-
scaleViewport(e, o, r) {
|
|
611
|
-
const s = this.canvas.viewport.getViewportMatrix(), d = we(s, e, o, r), { width: n, height: h } = this.element.getBoundingClientRect(), c = this.options.transformPreprocessor({
|
|
612
|
-
prevTransform: s,
|
|
613
|
-
nextTransform: d,
|
|
614
|
-
canvasWidth: n,
|
|
615
|
-
canvasHeight: h
|
|
616
|
-
});
|
|
617
|
-
this.performTransform(c);
|
|
618
|
-
}
|
|
619
|
-
stopMouseDrag() {
|
|
620
|
-
R(this.element, null), this.removeMouseDragListeners(), this.options.onTransformFinished();
|
|
621
|
-
}
|
|
622
|
-
removeMouseDragListeners() {
|
|
623
|
-
this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
|
|
624
|
-
}
|
|
625
|
-
stopTouchDrag() {
|
|
626
|
-
this.prevTouches = null, this.removeTouchDragListeners(), this.options.onTransformFinished();
|
|
627
|
-
}
|
|
628
|
-
removeTouchDragListeners() {
|
|
629
|
-
this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
|
|
630
|
-
}
|
|
631
|
-
performTransform(e) {
|
|
632
|
-
this.options.onBeforeTransformChange(), this.canvas.patchViewportMatrix(e), this.options.onTransformChange();
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
class fe {
|
|
636
|
-
constructor(e, o, r, s, d) {
|
|
637
|
-
i(this, "graph");
|
|
638
|
-
i(this, "viewport");
|
|
639
|
-
i(this, "canvas");
|
|
640
|
-
i(this, "canvasResizeObserver");
|
|
641
|
-
i(this, "window", window);
|
|
642
|
-
i(this, "nodeHorizontal");
|
|
643
|
-
i(this, "nodeVertical");
|
|
644
|
-
i(this, "viewportWidth", 0);
|
|
645
|
-
i(this, "viewportHeight", 0);
|
|
646
|
-
i(this, "viewportMatrix");
|
|
647
|
-
i(this, "loadedArea", {
|
|
648
|
-
xFrom: 1 / 0,
|
|
649
|
-
xTo: 1 / 0,
|
|
650
|
-
yFrom: 1 / 0,
|
|
651
|
-
yTo: 1 / 0
|
|
652
|
-
});
|
|
653
|
-
i(this, "updateLoadedArea", (e) => {
|
|
654
|
-
this.loadedArea = {
|
|
655
|
-
xFrom: e.x,
|
|
656
|
-
xTo: e.x + e.width,
|
|
657
|
-
yFrom: e.y,
|
|
658
|
-
yTo: e.y + e.height
|
|
659
|
-
};
|
|
660
|
-
});
|
|
661
|
-
var a, l;
|
|
662
|
-
this.trigger = o, this.virtualScrollOptions = s, this.element = d, this.nodeHorizontal = this.virtualScrollOptions.nodeContainingRadius.horizontal, this.nodeVertical = this.virtualScrollOptions.nodeContainingRadius.vertical, this.canvasResizeObserver = new this.window.ResizeObserver((g) => {
|
|
663
|
-
const f = g[0];
|
|
664
|
-
this.viewportWidth = f.contentRect.width, this.viewportHeight = f.contentRect.height, this.scheduleLoadAreaAroundViewport();
|
|
665
|
-
});
|
|
666
|
-
const n = ((a = r == null ? void 0 : r.events) == null ? void 0 : a.onTransformFinished) ?? (() => {
|
|
667
|
-
}), h = ((l = r == null ? void 0 : r.events) == null ? void 0 : l.onTransformChange) ?? (() => {
|
|
668
|
-
}), c = {
|
|
669
|
-
...r,
|
|
670
|
-
events: {
|
|
671
|
-
...r == null ? void 0 : r.events,
|
|
672
|
-
onTransformChange: () => {
|
|
673
|
-
const g = this.viewportMatrix;
|
|
674
|
-
this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), g.scale !== this.viewportMatrix.scale && this.scheduleEnsureViewportAreaLoaded(), h();
|
|
675
|
-
},
|
|
676
|
-
onTransformFinished: () => {
|
|
677
|
-
this.scheduleLoadAreaAroundViewport(), n();
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
this.canvas = new ee(
|
|
682
|
-
e,
|
|
683
|
-
this.element,
|
|
684
|
-
c
|
|
685
|
-
), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.viewport = this.canvas.viewport, this.graph = this.canvas.graph, this.trigger.subscribe(this.updateLoadedArea), this.canvasResizeObserver.observe(this.element);
|
|
686
|
-
}
|
|
687
|
-
addNode(e) {
|
|
688
|
-
this.canvas.addNode(e);
|
|
689
|
-
}
|
|
690
|
-
updateNode(e, o) {
|
|
691
|
-
this.canvas.updateNode(e, o);
|
|
692
|
-
}
|
|
693
|
-
removeNode(e) {
|
|
694
|
-
this.canvas.removeNode(e);
|
|
695
|
-
}
|
|
696
|
-
markPort(e) {
|
|
697
|
-
this.canvas.markPort(e);
|
|
698
|
-
}
|
|
699
|
-
updatePort(e, o) {
|
|
700
|
-
this.canvas.updatePort(e, o);
|
|
701
|
-
}
|
|
702
|
-
unmarkPort(e) {
|
|
703
|
-
this.canvas.unmarkPort(e);
|
|
704
|
-
}
|
|
705
|
-
addEdge(e) {
|
|
706
|
-
this.canvas.addEdge(e);
|
|
707
|
-
}
|
|
708
|
-
updateEdge(e, o) {
|
|
709
|
-
this.canvas.updateEdge(e, o);
|
|
710
|
-
}
|
|
711
|
-
removeEdge(e) {
|
|
712
|
-
this.canvas.removeEdge(e);
|
|
713
|
-
}
|
|
714
|
-
patchViewportMatrix(e) {
|
|
715
|
-
this.canvas.patchViewportMatrix(e), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.loadAreaAroundViewport();
|
|
716
|
-
}
|
|
717
|
-
patchContentMatrix(e) {
|
|
718
|
-
this.canvas.patchContentMatrix(e), this.viewportMatrix = this.canvas.viewport.getViewportMatrix(), this.loadAreaAroundViewport();
|
|
719
|
-
}
|
|
720
|
-
clear() {
|
|
721
|
-
this.canvas.clear();
|
|
722
|
-
}
|
|
723
|
-
destroy() {
|
|
724
|
-
this.trigger.unsubscribe(this.updateLoadedArea), this.canvasResizeObserver.unobserve(this.element), this.canvas.destroy();
|
|
725
|
-
}
|
|
726
|
-
scheduleLoadAreaAroundViewport() {
|
|
727
|
-
setTimeout(() => {
|
|
728
|
-
this.loadAreaAroundViewport();
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
scheduleEnsureViewportAreaLoaded() {
|
|
732
|
-
const e = this.viewportWidth * this.viewportMatrix.scale, o = this.viewportHeight * this.viewportMatrix.scale, r = this.viewportMatrix.x - this.nodeHorizontal, s = this.viewportMatrix.y - this.nodeVertical, d = this.viewportMatrix.x + e + this.nodeHorizontal, n = this.viewportMatrix.y + o + this.nodeVertical;
|
|
733
|
-
this.loadedArea.xFrom < r && this.loadedArea.xTo > d && this.loadedArea.yFrom < s && this.loadedArea.yTo > n || this.scheduleLoadAreaAroundViewport();
|
|
734
|
-
}
|
|
735
|
-
loadAreaAroundViewport() {
|
|
736
|
-
const e = this.viewportWidth * this.viewportMatrix.scale, o = this.viewportHeight * this.viewportMatrix.scale, r = this.viewportMatrix.x - e - this.nodeHorizontal, s = this.viewportMatrix.y - o - this.nodeVertical, d = 3 * e + 2 * this.nodeHorizontal, n = 3 * o + 2 * this.nodeVertical;
|
|
737
|
-
this.trigger.emit({ x: r, y: s, width: d, height: n });
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
const ye = () => {
|
|
741
|
-
const t = document.createElement("div");
|
|
742
|
-
return t.style.width = "100%", t.style.height = "100%", t.style.position = "relative", t.style.overflow = "hidden", t;
|
|
743
|
-
}, ve = () => {
|
|
744
|
-
const t = document.createElement("div");
|
|
745
|
-
return t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.width = "0", t.style.height = "0", t;
|
|
746
|
-
}, xe = () => {
|
|
747
|
-
const t = document.createElement("div");
|
|
748
|
-
return t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.visibility = "hidden", t;
|
|
749
|
-
};
|
|
750
|
-
class Ee {
|
|
751
|
-
constructor(e, o, r) {
|
|
752
|
-
i(this, "host", ye());
|
|
753
|
-
i(this, "container", ve());
|
|
754
|
-
i(this, "nodeIdToWrapperElementMap", /* @__PURE__ */ new Map());
|
|
755
|
-
i(this, "edgeIdToElementMap", /* @__PURE__ */ new Map());
|
|
756
|
-
i(this, "applyTransform", () => {
|
|
757
|
-
const e = this.viewportStore.getContentMatrix();
|
|
758
|
-
this.container.style.transform = `matrix(${e.scale}, 0, 0, ${e.scale}, ${e.x}, ${e.y})`;
|
|
759
|
-
});
|
|
760
|
-
this.graphStore = e, this.viewportStore = o, this.element = r, this.element.appendChild(this.host), this.host.appendChild(this.container), this.viewportStore.onAfterUpdated.subscribe(this.applyTransform);
|
|
761
|
-
}
|
|
762
|
-
attachNode(e) {
|
|
763
|
-
const o = this.graphStore.getNode(e), r = xe();
|
|
764
|
-
r.appendChild(o.element), this.container.appendChild(r), this.nodeIdToWrapperElementMap.set(e, r), this.updateNodePosition(e), this.updateNodePriority(e), r.style.visibility = "visible";
|
|
765
|
-
}
|
|
766
|
-
detachNode(e) {
|
|
767
|
-
const o = this.nodeIdToWrapperElementMap.get(e);
|
|
768
|
-
o.removeChild(o.firstChild), this.container.removeChild(o), this.nodeIdToWrapperElementMap.delete(e);
|
|
769
|
-
}
|
|
770
|
-
attachEdge(e) {
|
|
771
|
-
const o = this.graphStore.getEdge(e).shape.svg;
|
|
772
|
-
this.edgeIdToElementMap.set(e, o), this.container.appendChild(o), this.renderEdge(e), this.updateEdgePriority(e);
|
|
773
|
-
}
|
|
774
|
-
detachEdge(e) {
|
|
775
|
-
const o = this.edgeIdToElementMap.get(e);
|
|
776
|
-
this.container.removeChild(o), this.edgeIdToElementMap.delete(e);
|
|
777
|
-
}
|
|
778
|
-
clear() {
|
|
779
|
-
this.edgeIdToElementMap.forEach((e, o) => {
|
|
780
|
-
this.detachEdge(o);
|
|
781
|
-
}), this.nodeIdToWrapperElementMap.forEach((e, o) => {
|
|
782
|
-
this.detachNode(o);
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
destroy() {
|
|
786
|
-
this.viewportStore.onAfterUpdated.unsubscribe(this.applyTransform), this.clear(), this.element.removeChild(this.host), this.host.removeChild(this.container);
|
|
787
|
-
}
|
|
788
|
-
updateNodePosition(e) {
|
|
789
|
-
const o = this.nodeIdToWrapperElementMap.get(e), r = this.graphStore.getNode(e), { width: s, height: d } = r.element.getBoundingClientRect(), n = this.viewportStore.getViewportMatrix().scale, h = r.centerFn(s, d), c = r.x - n * h.x, a = r.y - n * h.y;
|
|
790
|
-
o.style.transform = `translate(${c}px, ${a}px)`;
|
|
791
|
-
}
|
|
792
|
-
updateNodePriority(e) {
|
|
793
|
-
const o = this.graphStore.getNode(e), r = this.nodeIdToWrapperElementMap.get(e);
|
|
794
|
-
r.style.zIndex = `${o.priority}`;
|
|
795
|
-
}
|
|
796
|
-
updateEdgeShape(e) {
|
|
797
|
-
const o = this.edgeIdToElementMap.get(e);
|
|
798
|
-
this.container.removeChild(o);
|
|
799
|
-
const r = this.graphStore.getEdge(e);
|
|
800
|
-
this.edgeIdToElementMap.set(e, r.shape.svg), this.container.appendChild(r.shape.svg);
|
|
801
|
-
}
|
|
802
|
-
renderEdge(e) {
|
|
803
|
-
const o = this.graphStore.getEdge(e), r = this.graphStore.getPort(o.from), s = this.graphStore.getPort(o.to), d = r.element.getBoundingClientRect(), n = s.element.getBoundingClientRect(), h = this.host.getBoundingClientRect(), c = this.viewportStore.getViewportMatrix(), a = {
|
|
804
|
-
x: c.scale * (d.left - h.left) + c.x,
|
|
805
|
-
y: c.scale * (d.top - h.top) + c.y
|
|
806
|
-
}, l = {
|
|
807
|
-
x: c.scale * (n.left - h.left) + c.x,
|
|
808
|
-
y: c.scale * (n.top - h.top) + c.y
|
|
809
|
-
}, g = {
|
|
810
|
-
x: a.x,
|
|
811
|
-
y: a.y,
|
|
812
|
-
width: d.width * c.scale,
|
|
813
|
-
height: d.height * c.scale,
|
|
814
|
-
direction: r.direction,
|
|
815
|
-
portId: o.from,
|
|
816
|
-
nodeId: r.nodeId
|
|
817
|
-
}, f = {
|
|
818
|
-
x: l.x,
|
|
819
|
-
y: l.y,
|
|
820
|
-
width: n.width * c.scale,
|
|
821
|
-
height: n.height * c.scale,
|
|
822
|
-
direction: s.direction,
|
|
823
|
-
portId: o.to,
|
|
824
|
-
nodeId: s.nodeId
|
|
825
|
-
};
|
|
826
|
-
o.shape.render({
|
|
827
|
-
from: g,
|
|
828
|
-
to: f
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
updateEdgePriority(e) {
|
|
832
|
-
const o = this.graphStore.getEdge(e);
|
|
833
|
-
o.shape.svg.style.zIndex = `${o.priority}`;
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
class Ae {
|
|
837
|
-
constructor(e) {
|
|
838
|
-
i(this, "xFrom", 1 / 0);
|
|
839
|
-
i(this, "yFrom", 1 / 0);
|
|
840
|
-
i(this, "xTo", 1 / 0);
|
|
841
|
-
i(this, "yTo", 1 / 0);
|
|
842
|
-
this.graphStore = e;
|
|
843
|
-
}
|
|
844
|
-
setRenderingBox(e) {
|
|
845
|
-
this.xFrom = e.x, this.xTo = e.x + e.width, this.yFrom = e.y, this.yTo = e.y + e.height;
|
|
846
|
-
}
|
|
847
|
-
hasNode(e) {
|
|
848
|
-
const o = this.graphStore.getNode(e);
|
|
849
|
-
return o.x >= this.xFrom && o.x <= this.xTo && o.y >= this.yFrom && o.y <= this.yTo;
|
|
850
|
-
}
|
|
851
|
-
hasEdge(e) {
|
|
852
|
-
const o = this.graphStore.getEdge(e), r = this.graphStore.getPort(o.from).nodeId, s = this.graphStore.getPort(o.to).nodeId, d = this.graphStore.getNode(r), n = this.graphStore.getNode(s), h = Math.min(d.x, n.x), c = Math.max(d.x, n.x), a = Math.min(d.y, n.y), l = Math.max(d.y, n.y);
|
|
853
|
-
return h <= this.xTo && c >= this.xFrom && a <= this.yTo && l >= this.yFrom;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
class Se {
|
|
857
|
-
constructor(e, o, r) {
|
|
858
|
-
i(this, "attachedNodes", /* @__PURE__ */ new Set());
|
|
859
|
-
i(this, "attachedEdges", /* @__PURE__ */ new Set());
|
|
860
|
-
i(this, "renderingBox");
|
|
861
|
-
i(this, "updateViewport", (e) => {
|
|
862
|
-
this.renderingBox.setRenderingBox(e);
|
|
863
|
-
const o = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
|
|
864
|
-
this.graphStore.getAllNodeIds().forEach((n) => {
|
|
865
|
-
const h = this.renderingBox.hasNode(n), c = this.attachedNodes.has(n);
|
|
866
|
-
h && !c ? o.add(n) : !h && c && r.add(n);
|
|
867
|
-
}), this.graphStore.getAllEdgeIds().forEach((n) => {
|
|
868
|
-
const h = this.renderingBox.hasEdge(n), c = this.attachedEdges.has(n), a = this.graphStore.getEdge(n), l = this.graphStore.getPort(a.from).nodeId, g = this.graphStore.getPort(a.to).nodeId;
|
|
869
|
-
h && (this.renderingBox.hasNode(l) || (o.add(l), r.delete(l)), this.renderingBox.hasNode(g) || (o.add(g), r.delete(g))), h && !c ? s.add(n) : !h && c && d.add(n);
|
|
870
|
-
}), d.forEach((n) => {
|
|
871
|
-
this.handleDetachEdge(n);
|
|
872
|
-
}), r.forEach((n) => {
|
|
873
|
-
this.handleDetachNode(n);
|
|
874
|
-
}), o.forEach((n) => {
|
|
875
|
-
this.attachedNodes.has(n) || this.handleAttachNode(n);
|
|
876
|
-
}), s.forEach((n) => {
|
|
877
|
-
this.handleAttachEdge(n);
|
|
878
|
-
});
|
|
879
|
-
});
|
|
880
|
-
this.htmlView = e, this.graphStore = o, this.trigger = r, this.renderingBox = new Ae(this.graphStore), this.trigger.subscribe(this.updateViewport);
|
|
881
|
-
}
|
|
882
|
-
attachNode(e) {
|
|
883
|
-
this.renderingBox.hasNode(e) && this.handleAttachNode(e);
|
|
884
|
-
}
|
|
885
|
-
detachNode(e) {
|
|
886
|
-
this.attachedNodes.has(e) && this.handleDetachNode(e);
|
|
887
|
-
}
|
|
888
|
-
attachEdge(e) {
|
|
889
|
-
this.renderingBox.hasEdge(e) && this.attachEdgeEntities(e);
|
|
890
|
-
}
|
|
891
|
-
detachEdge(e) {
|
|
892
|
-
this.attachedEdges.has(e) && this.handleDetachEdge(e);
|
|
893
|
-
}
|
|
894
|
-
updateNodePosition(e) {
|
|
895
|
-
this.attachedNodes.has(e) ? this.htmlView.updateNodePosition(e) : this.renderingBox.hasNode(e) && (this.handleAttachNode(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((o) => {
|
|
896
|
-
this.attachEdgeEntities(o);
|
|
897
|
-
}));
|
|
898
|
-
}
|
|
899
|
-
updateNodePriority(e) {
|
|
900
|
-
this.attachedNodes.has(e) && this.htmlView.updateNodePriority(e);
|
|
901
|
-
}
|
|
902
|
-
updateEdgeShape(e) {
|
|
903
|
-
this.attachedEdges.has(e) && this.htmlView.updateEdgeShape(e);
|
|
904
|
-
}
|
|
905
|
-
renderEdge(e) {
|
|
906
|
-
this.attachedEdges.has(e) && this.htmlView.renderEdge(e);
|
|
907
|
-
}
|
|
908
|
-
updateEdgePriority(e) {
|
|
909
|
-
this.attachedEdges.has(e) && this.htmlView.updateEdgePriority(e);
|
|
910
|
-
}
|
|
911
|
-
clear() {
|
|
912
|
-
this.htmlView.clear(), this.attachedNodes.clear(), this.attachedEdges.clear();
|
|
913
|
-
}
|
|
914
|
-
destroy() {
|
|
915
|
-
this.clear(), this.htmlView.destroy(), this.trigger.unsubscribe(this.updateViewport);
|
|
916
|
-
}
|
|
917
|
-
attachEdgeEntities(e) {
|
|
918
|
-
const o = this.graphStore.getEdge(e), r = this.graphStore.getPort(o.from).nodeId, s = this.graphStore.getPort(o.to).nodeId;
|
|
919
|
-
this.attachedNodes.has(r) || this.handleAttachNode(r), this.attachedNodes.has(s) || this.handleAttachNode(s), this.handleAttachEdge(e);
|
|
920
|
-
}
|
|
921
|
-
handleAttachNode(e) {
|
|
922
|
-
this.attachedNodes.add(e), this.htmlView.attachNode(e);
|
|
923
|
-
}
|
|
924
|
-
handleDetachNode(e) {
|
|
925
|
-
this.htmlView.detachNode(e), this.attachedNodes.delete(e);
|
|
926
|
-
}
|
|
927
|
-
handleAttachEdge(e) {
|
|
928
|
-
this.attachedEdges.add(e), this.htmlView.attachEdge(e);
|
|
929
|
-
}
|
|
930
|
-
handleDetachEdge(e) {
|
|
931
|
-
this.htmlView.detachEdge(e), this.attachedEdges.delete(e);
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
class te {
|
|
935
|
-
constructor() {
|
|
936
|
-
i(this, "callbacks", /* @__PURE__ */ new Set());
|
|
937
|
-
}
|
|
938
|
-
subscribe(e) {
|
|
939
|
-
this.callbacks.add(e);
|
|
940
|
-
}
|
|
941
|
-
unsubscribe(e) {
|
|
942
|
-
this.callbacks.delete(e);
|
|
943
|
-
}
|
|
944
|
-
emit(e) {
|
|
945
|
-
this.callbacks.forEach((o) => {
|
|
946
|
-
o(e);
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
}
|
|
950
|
-
const E = () => {
|
|
951
|
-
const t = new te();
|
|
952
|
-
return [t, t];
|
|
953
|
-
};
|
|
954
|
-
class Y {
|
|
955
|
-
constructor(e) {
|
|
956
|
-
i(this, "counter", 0);
|
|
957
|
-
this.checkExists = e;
|
|
958
|
-
}
|
|
959
|
-
create(e) {
|
|
960
|
-
if (e !== void 0)
|
|
961
|
-
return e;
|
|
962
|
-
for (; this.checkExists(this.counter); )
|
|
963
|
-
this.counter++;
|
|
964
|
-
return this.counter;
|
|
965
|
-
}
|
|
966
|
-
reset() {
|
|
967
|
-
this.counter = 0;
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
class A extends Error {
|
|
323
|
+
class b extends Error {
|
|
971
324
|
constructor() {
|
|
972
325
|
super(...arguments);
|
|
973
326
|
i(this, "name", "HtmlGraphError");
|
|
974
327
|
}
|
|
975
328
|
}
|
|
976
|
-
const
|
|
329
|
+
const ye = (t, e) => ({
|
|
977
330
|
x: t / 2,
|
|
978
331
|
y: e / 2
|
|
979
|
-
}),
|
|
332
|
+
}), H = (t) => () => t, ee = H(0), ve = () => {
|
|
980
333
|
let t = 0;
|
|
981
334
|
return () => t++;
|
|
982
|
-
},
|
|
983
|
-
let o =
|
|
984
|
-
const s =
|
|
985
|
-
return t === "incremental" && (o = s), e === "incremental" && (r = s), typeof t == "number" && (o =
|
|
335
|
+
}, xe = (t, e) => {
|
|
336
|
+
let o = ee, r = ee;
|
|
337
|
+
const s = ve();
|
|
338
|
+
return t === "incremental" && (o = s), e === "incremental" && (r = s), typeof t == "number" && (o = H(t)), typeof e == "number" && (r = H(e)), typeof t == "function" && (o = t), typeof e == "function" && (r = e), {
|
|
986
339
|
nodesPriorityFn: o,
|
|
987
340
|
edgesPriorityFn: r
|
|
988
341
|
};
|
|
989
|
-
},
|
|
342
|
+
}, x = (t, e, o) => ({
|
|
990
343
|
x: e.x * t.x - e.y * t.y + ((1 - e.x) * o.x + e.y * o.y),
|
|
991
344
|
y: e.y * t.x + e.x * t.y + ((1 - e.x) * o.y - e.y * o.x)
|
|
992
345
|
}), T = (t, e, o) => ({ x: e * Math.cos(t), y: o * Math.sin(t) }), w = {
|
|
@@ -997,23 +350,23 @@ const pe = (t, e) => ({
|
|
|
997
350
|
w,
|
|
998
351
|
{ x: o, y: r },
|
|
999
352
|
{ x: o, y: -r }
|
|
1000
|
-
].map((a) =>
|
|
353
|
+
].map((a) => x(a, t, w)).map((a) => ({ x: a.x + e.x, y: a.y + e.y })), n = `M ${d[0].x} ${d[0].y}`, h = `L ${d[1].x} ${d[1].y}`, c = `L ${d[2].x} ${d[2].y}`;
|
|
1001
354
|
return `${n} ${h} ${c}`;
|
|
1002
|
-
},
|
|
355
|
+
}, C = (t, e) => {
|
|
1003
356
|
const o = [];
|
|
1004
357
|
if (t.length > 0 && o.push(`M ${t[0].x} ${t[0].y}`), t.length === 2 && o.push(`L ${t[1].x} ${t[1].y}`), t.length > 2) {
|
|
1005
358
|
const r = t.length - 1;
|
|
1006
359
|
let s = 0, d = 0, n = 0;
|
|
1007
360
|
t.forEach((h, c) => {
|
|
1008
361
|
let a = 0, l = 0, g = 0;
|
|
1009
|
-
const f = c > 0,
|
|
1010
|
-
if (f && (a = -s, l = -d, g = n),
|
|
362
|
+
const f = c > 0, v = c < r, y = f && v;
|
|
363
|
+
if (f && (a = -s, l = -d, g = n), v) {
|
|
1011
364
|
const L = t[c + 1];
|
|
1012
365
|
s = L.x - h.x, d = L.y - h.y, n = Math.sqrt(s * s + d * d);
|
|
1013
366
|
}
|
|
1014
|
-
const
|
|
1015
|
-
c > 0 && o.push(`L ${
|
|
1016
|
-
`C ${h.x} ${h.y} ${h.x} ${h.y} ${
|
|
367
|
+
const E = n !== 0 ? Math.min((y ? e : 0) / n, c < r - 1 ? 0.5 : 1) : 0, S = y ? { x: h.x + s * E, y: h.y + d * E } : h, D = g !== 0 ? Math.min((y ? e : 0) / g, c > 1 ? 0.5 : 1) : 0, M = y ? { x: h.x + a * D, y: h.y + l * D } : h;
|
|
368
|
+
c > 0 && o.push(`L ${M.x} ${M.y}`), y && o.push(
|
|
369
|
+
`C ${h.x} ${h.y} ${h.x} ${h.y} ${S.x} ${S.y}`
|
|
1017
370
|
);
|
|
1018
371
|
});
|
|
1019
372
|
}
|
|
@@ -1027,10 +380,10 @@ const pe = (t, e) => ({
|
|
|
1027
380
|
}, F = (t, e) => {
|
|
1028
381
|
const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1029
382
|
return o.setAttribute("stroke", t), o.setAttribute("stroke-width", `${e}`), o.setAttribute("fill", "none"), o;
|
|
1030
|
-
},
|
|
383
|
+
}, N = (t) => {
|
|
1031
384
|
const e = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1032
385
|
return e.setAttribute("fill", t), e;
|
|
1033
|
-
},
|
|
386
|
+
}, z = (t, e) => {
|
|
1034
387
|
const o = {
|
|
1035
388
|
x: t.x + t.width / 2,
|
|
1036
389
|
y: t.y + t.height / 2
|
|
@@ -1046,146 +399,164 @@ const pe = (t, e) => ({
|
|
|
1046
399
|
flipX: c,
|
|
1047
400
|
flipY: a
|
|
1048
401
|
};
|
|
1049
|
-
},
|
|
1050
|
-
const e =
|
|
402
|
+
}, Ae = (t) => {
|
|
403
|
+
const e = x(
|
|
1051
404
|
{ x: t.arrowLength, y: w.y },
|
|
1052
|
-
t.
|
|
405
|
+
t.fromVector,
|
|
1053
406
|
w
|
|
1054
|
-
), o =
|
|
407
|
+
), o = x(
|
|
1055
408
|
{ x: t.to.x - t.arrowLength, y: t.to.y },
|
|
1056
|
-
t.
|
|
409
|
+
t.toVector,
|
|
1057
410
|
t.to
|
|
1058
411
|
), r = {
|
|
1059
|
-
x: e.x + t.
|
|
1060
|
-
y: e.y + t.
|
|
412
|
+
x: e.x + t.fromVector.x * t.curvature,
|
|
413
|
+
y: e.y + t.fromVector.y * t.curvature
|
|
1061
414
|
}, s = {
|
|
1062
|
-
x: o.x - t.
|
|
1063
|
-
y: o.y - t.
|
|
415
|
+
x: o.x - t.toVector.x * t.curvature,
|
|
416
|
+
y: o.y - t.toVector.y * t.curvature
|
|
1064
417
|
}, d = `M ${e.x} ${e.y} C ${r.x} ${r.y}, ${s.x} ${s.y}, ${o.x} ${o.y}`, n = t.hasSourceArrow ? "" : `M ${w.x} ${w.y} L ${e.x} ${e.y} `, h = t.hasTargetArrow ? "" : ` M ${o.x} ${o.y} L ${t.to.x} ${t.to.y}`;
|
|
1065
418
|
return `${n}${d}${h}`;
|
|
1066
|
-
},
|
|
1067
|
-
const e = t.hasSourceArrow ?
|
|
419
|
+
}, Ee = (t) => {
|
|
420
|
+
const e = t.hasSourceArrow ? x(
|
|
1068
421
|
{ x: t.arrowLength, y: w.y },
|
|
1069
|
-
t.
|
|
422
|
+
t.fromVector,
|
|
1070
423
|
w
|
|
1071
|
-
) : w, o = t.hasTargetArrow ?
|
|
424
|
+
) : w, o = t.hasTargetArrow ? x(
|
|
1072
425
|
{ x: t.to.x - t.arrowLength, y: t.to.y },
|
|
1073
|
-
t.
|
|
426
|
+
t.toVector,
|
|
1074
427
|
t.to
|
|
1075
|
-
) : t.to, r = t.arrowLength, s = Math.cos(t.detourDirection) * t.detourDistance, d = Math.sin(t.detourDirection) * t.detourDistance, n = s * t.flipX, h = d * t.flipY, c =
|
|
428
|
+
) : t.to, r = t.arrowLength, s = Math.cos(t.detourDirection) * t.detourDistance, d = Math.sin(t.detourDirection) * t.detourDistance, n = s * t.flipX, h = d * t.flipY, c = x(
|
|
1076
429
|
{ x: r, y: w.y },
|
|
1077
|
-
t.
|
|
430
|
+
t.fromVector,
|
|
1078
431
|
w
|
|
1079
432
|
), a = {
|
|
1080
433
|
x: c.x + n,
|
|
1081
434
|
y: c.y + h
|
|
1082
|
-
}, l =
|
|
435
|
+
}, l = x(
|
|
1083
436
|
{ x: t.to.x - r, y: t.to.y },
|
|
1084
|
-
t.
|
|
437
|
+
t.toVector,
|
|
1085
438
|
t.to
|
|
1086
439
|
), g = {
|
|
1087
440
|
x: l.x + n,
|
|
1088
441
|
y: l.y + h
|
|
1089
|
-
}, f = { x: (a.x + g.x) / 2, y: (a.y + g.y) / 2 },
|
|
1090
|
-
x: c.x + t.curvature * t.
|
|
1091
|
-
y: c.y + t.curvature * t.
|
|
442
|
+
}, f = { x: (a.x + g.x) / 2, y: (a.y + g.y) / 2 }, v = {
|
|
443
|
+
x: c.x + t.curvature * t.fromVector.x,
|
|
444
|
+
y: c.y + t.curvature * t.fromVector.y
|
|
1092
445
|
}, y = {
|
|
1093
|
-
x: l.x - t.curvature * t.
|
|
1094
|
-
y: l.y - t.curvature * t.
|
|
446
|
+
x: l.x - t.curvature * t.toVector.x,
|
|
447
|
+
y: l.y - t.curvature * t.toVector.y
|
|
1095
448
|
}, p = {
|
|
1096
449
|
x: c.x + n,
|
|
1097
450
|
y: c.y + h
|
|
1098
|
-
},
|
|
451
|
+
}, E = {
|
|
1099
452
|
x: l.x + n,
|
|
1100
453
|
y: l.y + h
|
|
1101
454
|
};
|
|
1102
455
|
return [
|
|
1103
456
|
`M ${e.x} ${e.y}`,
|
|
1104
457
|
`L ${c.x} ${c.y}`,
|
|
1105
|
-
`C ${
|
|
1106
|
-
`C ${
|
|
458
|
+
`C ${v.x} ${v.y} ${p.x} ${p.y} ${f.x} ${f.y}`,
|
|
459
|
+
`C ${E.x} ${E.y} ${y.x} ${y.y} ${l.x} ${l.y}`,
|
|
1107
460
|
`L ${o.x} ${o.y}`
|
|
1108
461
|
].join(" ");
|
|
1109
|
-
},
|
|
1110
|
-
const e = t.hasSourceArrow ?
|
|
462
|
+
}, Se = (t) => {
|
|
463
|
+
const e = t.hasSourceArrow ? x(
|
|
1111
464
|
{ x: t.arrowLength, y: w.y },
|
|
1112
|
-
t.
|
|
465
|
+
t.fromVector,
|
|
1113
466
|
w
|
|
1114
|
-
) : w, o = t.hasTargetArrow ?
|
|
467
|
+
) : w, o = t.hasTargetArrow ? x(
|
|
1115
468
|
{ x: t.to.x - t.arrowLength, y: t.to.y },
|
|
1116
|
-
t.
|
|
469
|
+
t.toVector,
|
|
1117
470
|
t.to
|
|
1118
|
-
) : t.to, r = t.arrowLength + t.arrowOffset, s = r - t.roundness, d =
|
|
471
|
+
) : t.to, r = t.arrowLength + t.arrowOffset, s = r - t.roundness, d = x(
|
|
472
|
+
{ x: s, y: w.y },
|
|
473
|
+
t.fromVector,
|
|
474
|
+
w
|
|
475
|
+
), n = x(
|
|
1119
476
|
{ x: t.to.x - s, y: t.to.y },
|
|
1120
|
-
t.
|
|
477
|
+
t.toVector,
|
|
1121
478
|
t.to
|
|
1122
|
-
), h = Math.max((d.x + n.x) / 2, r), c = t.to.y / 2, a = {
|
|
479
|
+
), h = Math.max((d.x + n.x) / 2, r), c = t.to.y / 2, a = {
|
|
480
|
+
x: t.flipX > 0 ? h : -r,
|
|
481
|
+
y: d.y
|
|
482
|
+
}, l = { x: a.x, y: c }, g = {
|
|
1123
483
|
x: t.flipX > 0 ? t.to.x - h : t.to.x + r,
|
|
1124
484
|
y: n.y
|
|
1125
485
|
}, f = { x: g.x, y: c };
|
|
1126
|
-
return
|
|
486
|
+
return C(
|
|
1127
487
|
[e, d, a, l, f, g, n, o],
|
|
1128
488
|
t.roundness
|
|
1129
489
|
);
|
|
1130
|
-
},
|
|
1131
|
-
const e = t.hasSourceArrow ?
|
|
490
|
+
}, k = (t) => {
|
|
491
|
+
const e = t.hasSourceArrow ? x(
|
|
1132
492
|
{ x: t.arrowLength, y: w.y },
|
|
1133
|
-
t.
|
|
493
|
+
t.fromVector,
|
|
1134
494
|
w
|
|
1135
|
-
) : w, o = t.hasTargetArrow ?
|
|
495
|
+
) : w, o = t.hasTargetArrow ? x(
|
|
1136
496
|
{ x: t.to.x - t.arrowLength, y: t.to.y },
|
|
1137
|
-
t.
|
|
497
|
+
t.toVector,
|
|
1138
498
|
t.to
|
|
1139
|
-
) : t.to, r = t.arrowLength + t.arrowOffset, s =
|
|
499
|
+
) : t.to, r = t.arrowLength + t.arrowOffset, s = x(
|
|
1140
500
|
{ x: r, y: w.y },
|
|
1141
|
-
t.
|
|
501
|
+
t.fromVector,
|
|
1142
502
|
w
|
|
1143
|
-
), d = Math.cos(t.detourDirection) * t.detourDistance, n = Math.sin(t.detourDirection) * t.detourDistance, h = d * t.flipX, c = n * t.flipY, a = { x: s.x + h, y: s.y + c }, l =
|
|
503
|
+
), d = Math.cos(t.detourDirection) * t.detourDistance, n = Math.sin(t.detourDirection) * t.detourDistance, h = d * t.flipX, c = n * t.flipY, a = { x: s.x + h, y: s.y + c }, l = x(
|
|
1144
504
|
{ x: t.to.x - r, y: t.to.y },
|
|
1145
|
-
t.
|
|
505
|
+
t.toVector,
|
|
1146
506
|
t.to
|
|
1147
507
|
), g = { x: l.x + h, y: l.y + c };
|
|
1148
|
-
return
|
|
508
|
+
return C(
|
|
1149
509
|
[e, s, a, g, l, o],
|
|
1150
510
|
t.roundness
|
|
1151
511
|
);
|
|
1152
|
-
},
|
|
1153
|
-
const e = t.hasSourceArrow ?
|
|
512
|
+
}, be = (t) => {
|
|
513
|
+
const e = t.hasSourceArrow ? x(
|
|
1154
514
|
{ x: t.arrowLength, y: w.y },
|
|
1155
|
-
t.
|
|
515
|
+
t.fromVector,
|
|
1156
516
|
w
|
|
1157
|
-
) : w, o = t.hasTargetArrow ?
|
|
517
|
+
) : w, o = t.hasTargetArrow ? x(
|
|
1158
518
|
{ x: t.to.x - t.arrowLength, y: t.to.y },
|
|
1159
|
-
t.
|
|
519
|
+
t.toVector,
|
|
1160
520
|
t.to
|
|
1161
|
-
) : t.to, r = t.arrowLength + t.arrowOffset, s =
|
|
521
|
+
) : t.to, r = t.arrowLength + t.arrowOffset, s = x(
|
|
522
|
+
{ x: r, y: w.y },
|
|
523
|
+
t.fromVector,
|
|
524
|
+
w
|
|
525
|
+
), d = x(
|
|
1162
526
|
{ x: t.to.x - r, y: t.to.y },
|
|
1163
|
-
t.
|
|
527
|
+
t.toVector,
|
|
1164
528
|
t.to
|
|
1165
529
|
);
|
|
1166
|
-
return
|
|
1167
|
-
},
|
|
1168
|
-
const e = t.hasSourceArrow ?
|
|
530
|
+
return C([e, s, d, o], t.roundness);
|
|
531
|
+
}, pe = (t) => {
|
|
532
|
+
const e = t.hasSourceArrow ? x(
|
|
1169
533
|
{ x: t.arrowLength, y: w.y },
|
|
1170
|
-
t.
|
|
534
|
+
t.fromVector,
|
|
1171
535
|
w
|
|
1172
|
-
) : w, o = t.hasTargetArrow ?
|
|
536
|
+
) : w, o = t.hasTargetArrow ? x(
|
|
1173
537
|
{ x: t.to.x - t.arrowLength, y: t.to.y },
|
|
1174
|
-
t.
|
|
538
|
+
t.toVector,
|
|
1175
539
|
t.to
|
|
1176
|
-
) : t.to, r = t.arrowLength + t.arrowOffset, s = r - t.roundness, d =
|
|
540
|
+
) : t.to, r = t.arrowLength + t.arrowOffset, s = r - t.roundness, d = x(
|
|
541
|
+
{ x: s, y: w.y },
|
|
542
|
+
t.fromVector,
|
|
543
|
+
w
|
|
544
|
+
), n = x(
|
|
1177
545
|
{ x: t.to.x - s, y: t.to.y },
|
|
1178
|
-
t.
|
|
546
|
+
t.toVector,
|
|
1179
547
|
t.to
|
|
1180
|
-
), h = Math.max((d.y + n.y) / 2, r), c = t.to.x / 2, a = {
|
|
548
|
+
), h = Math.max((d.y + n.y) / 2, r), c = t.to.x / 2, a = {
|
|
549
|
+
x: d.x,
|
|
550
|
+
y: t.flipY > 0 ? h : -r
|
|
551
|
+
}, l = { x: c, y: a.y }, g = {
|
|
1181
552
|
x: n.x,
|
|
1182
553
|
y: t.flipY > 0 ? t.to.y - h : t.to.y + r
|
|
1183
554
|
}, f = { x: c, y: g.y };
|
|
1184
|
-
return
|
|
555
|
+
return C(
|
|
1185
556
|
[e, d, a, l, f, g, n, o],
|
|
1186
557
|
t.roundness
|
|
1187
558
|
);
|
|
1188
|
-
},
|
|
559
|
+
}, j = (t) => {
|
|
1189
560
|
const e = t.arrowOffset, o = t.side, r = t.arrowLength + e, s = r + 2 * o, n = [
|
|
1190
561
|
{ x: t.arrowLength, y: w.y },
|
|
1191
562
|
{ x: r, y: w.y },
|
|
@@ -1196,15 +567,17 @@ const pe = (t, e) => ({
|
|
|
1196
567
|
{ x: r, y: w.y },
|
|
1197
568
|
{ x: t.arrowLength, y: w.y }
|
|
1198
569
|
].map(
|
|
1199
|
-
(c) =>
|
|
570
|
+
(c) => x(c, t.fromVector, w)
|
|
1200
571
|
), h = `M ${w.x} ${w.y} L ${n[0].x} ${n[0].y} `;
|
|
1201
|
-
return `${t.hasSourceArrow || t.hasTargetArrow ? "" : h}${
|
|
1202
|
-
},
|
|
572
|
+
return `${t.hasSourceArrow || t.hasTargetArrow ? "" : h}${C(n, t.roundness)}`;
|
|
573
|
+
}, Te = (t) => {
|
|
1203
574
|
const e = t.smallRadius, o = t.radius, r = Math.sqrt(e * e + o * o), s = e + o, d = t.arrowLength + r * (1 - o / s), n = e * o / s, c = [
|
|
1204
575
|
{ x: t.arrowLength, y: w.y },
|
|
1205
576
|
{ x: d, y: n },
|
|
1206
577
|
{ x: d, y: -n }
|
|
1207
|
-
].map(
|
|
578
|
+
].map(
|
|
579
|
+
(g) => x(g, t.fromVector, w)
|
|
580
|
+
), a = [
|
|
1208
581
|
`M ${c[0].x} ${c[0].y}`,
|
|
1209
582
|
`A ${e} ${e} 0 0 1 ${c[1].x} ${c[1].y}`,
|
|
1210
583
|
`A ${o} ${o} 0 1 0 ${c[2].x} ${c[2].y}`,
|
|
@@ -1228,7 +601,7 @@ const pe = (t, e) => ({
|
|
|
1228
601
|
smallCycleRadius: 15,
|
|
1229
602
|
curvature: 90
|
|
1230
603
|
});
|
|
1231
|
-
class
|
|
604
|
+
class me {
|
|
1232
605
|
constructor(e) {
|
|
1233
606
|
i(this, "svg", I());
|
|
1234
607
|
i(this, "group", W());
|
|
@@ -1246,10 +619,10 @@ class De {
|
|
|
1246
619
|
i(this, "hasTargetArrow");
|
|
1247
620
|
this.arrowLength = (e == null ? void 0 : e.arrowLength) ?? u.arrowLength, this.arrowWidth = (e == null ? void 0 : e.arrowWidth) ?? u.arrowWidth, this.curvature = (e == null ? void 0 : e.curvature) ?? u.curvature, this.portCycleRadius = (e == null ? void 0 : e.cycleRadius) ?? u.cycleRadius, this.portCycleSmallRadius = (e == null ? void 0 : e.smallCycleRadius) ?? u.smallCycleRadius, this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow;
|
|
1248
621
|
const o = (e == null ? void 0 : e.color) ?? u.color, r = (e == null ? void 0 : e.width) ?? u.width;
|
|
1249
|
-
this.svg.appendChild(this.group), this.line = F(o, r), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow =
|
|
622
|
+
this.svg.appendChild(this.group), this.line = F(o, r), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(o), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(o), this.group.appendChild(this.targetArrow));
|
|
1250
623
|
}
|
|
1251
624
|
render(e) {
|
|
1252
|
-
const { x: o, y: r, width: s, height: d, flipX: n, flipY: h } =
|
|
625
|
+
const { x: o, y: r, width: s, height: d, flipX: n, flipY: h } = z(
|
|
1253
626
|
e.from,
|
|
1254
627
|
e.to
|
|
1255
628
|
);
|
|
@@ -1262,18 +635,18 @@ class De {
|
|
|
1262
635
|
x: s,
|
|
1263
636
|
y: d
|
|
1264
637
|
};
|
|
1265
|
-
let g, f = a,
|
|
1266
|
-
if (e.from.portId === e.to.portId ? (g =
|
|
1267
|
-
|
|
638
|
+
let g, f = a, v = -this.arrowLength;
|
|
639
|
+
if (e.from.portId === e.to.portId ? (g = Te({
|
|
640
|
+
fromVector: c,
|
|
1268
641
|
radius: this.portCycleRadius,
|
|
1269
642
|
smallRadius: this.portCycleSmallRadius,
|
|
1270
643
|
arrowLength: this.arrowLength,
|
|
1271
644
|
hasSourceArrow: this.hasSourceArrow,
|
|
1272
645
|
hasTargetArrow: this.hasTargetArrow
|
|
1273
|
-
}), f = c,
|
|
646
|
+
}), f = c, v = this.arrowLength) : e.from.nodeId === e.to.nodeId ? g = Ee({
|
|
1274
647
|
to: l,
|
|
1275
|
-
|
|
1276
|
-
|
|
648
|
+
fromVector: c,
|
|
649
|
+
toVector: a,
|
|
1277
650
|
flipX: n,
|
|
1278
651
|
flipY: h,
|
|
1279
652
|
arrowLength: this.arrowLength,
|
|
@@ -1282,10 +655,10 @@ class De {
|
|
|
1282
655
|
curvature: this.curvature,
|
|
1283
656
|
hasSourceArrow: this.hasSourceArrow,
|
|
1284
657
|
hasTargetArrow: this.hasTargetArrow
|
|
1285
|
-
}) : g =
|
|
658
|
+
}) : g = Ae({
|
|
1286
659
|
to: l,
|
|
1287
|
-
|
|
1288
|
-
|
|
660
|
+
fromVector: c,
|
|
661
|
+
toVector: a,
|
|
1289
662
|
arrowLength: this.arrowLength,
|
|
1290
663
|
curvature: this.curvature,
|
|
1291
664
|
hasSourceArrow: this.hasSourceArrow,
|
|
@@ -1303,14 +676,14 @@ class De {
|
|
|
1303
676
|
const y = m(
|
|
1304
677
|
f,
|
|
1305
678
|
l,
|
|
1306
|
-
|
|
679
|
+
v,
|
|
1307
680
|
this.arrowWidth
|
|
1308
681
|
);
|
|
1309
682
|
this.targetArrow.setAttribute("d", y);
|
|
1310
683
|
}
|
|
1311
684
|
}
|
|
1312
685
|
}
|
|
1313
|
-
class
|
|
686
|
+
class Ne {
|
|
1314
687
|
constructor(e) {
|
|
1315
688
|
i(this, "svg", I());
|
|
1316
689
|
i(this, "group", W());
|
|
@@ -1334,10 +707,10 @@ class Ce {
|
|
|
1334
707
|
this.cycleSquareSide / 2
|
|
1335
708
|
), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow;
|
|
1336
709
|
const r = (e == null ? void 0 : e.color) ?? u.color, s = (e == null ? void 0 : e.width) ?? u.width;
|
|
1337
|
-
this.svg.appendChild(this.group), this.line = F(r, s), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow =
|
|
710
|
+
this.svg.appendChild(this.group), this.line = F(r, s), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
|
|
1338
711
|
}
|
|
1339
712
|
render(e) {
|
|
1340
|
-
const { x: o, y: r, width: s, height: d, flipX: n, flipY: h } =
|
|
713
|
+
const { x: o, y: r, width: s, height: d, flipX: n, flipY: h } = z(
|
|
1341
714
|
e.from,
|
|
1342
715
|
e.to
|
|
1343
716
|
);
|
|
@@ -1350,19 +723,19 @@ class Ce {
|
|
|
1350
723
|
x: s,
|
|
1351
724
|
y: d
|
|
1352
725
|
};
|
|
1353
|
-
let g, f = a,
|
|
1354
|
-
if (e.from.portId === e.to.portId ? (g =
|
|
1355
|
-
|
|
726
|
+
let g, f = a, v = -this.arrowLength;
|
|
727
|
+
if (e.from.portId === e.to.portId ? (g = j({
|
|
728
|
+
fromVector: c,
|
|
1356
729
|
arrowLength: this.arrowLength,
|
|
1357
730
|
side: this.cycleSquareSide,
|
|
1358
731
|
arrowOffset: this.arrowOffset,
|
|
1359
732
|
roundness: this.roundness,
|
|
1360
733
|
hasSourceArrow: this.hasSourceArrow,
|
|
1361
734
|
hasTargetArrow: this.hasTargetArrow
|
|
1362
|
-
}), f = c,
|
|
735
|
+
}), f = c, v = this.arrowLength) : e.from.nodeId === e.to.nodeId ? g = k({
|
|
1363
736
|
to: l,
|
|
1364
|
-
|
|
1365
|
-
|
|
737
|
+
fromVector: c,
|
|
738
|
+
toVector: a,
|
|
1366
739
|
flipX: n,
|
|
1367
740
|
flipY: h,
|
|
1368
741
|
arrowLength: this.arrowLength,
|
|
@@ -1372,10 +745,10 @@ class Ce {
|
|
|
1372
745
|
detourDistance: this.detourDistance,
|
|
1373
746
|
hasSourceArrow: this.hasSourceArrow,
|
|
1374
747
|
hasTargetArrow: this.hasTargetArrow
|
|
1375
|
-
}) : g =
|
|
748
|
+
}) : g = Se({
|
|
1376
749
|
to: l,
|
|
1377
|
-
|
|
1378
|
-
|
|
750
|
+
fromVector: c,
|
|
751
|
+
toVector: a,
|
|
1379
752
|
flipX: n,
|
|
1380
753
|
arrowLength: this.arrowLength,
|
|
1381
754
|
arrowOffset: this.arrowOffset,
|
|
@@ -1395,14 +768,14 @@ class Ce {
|
|
|
1395
768
|
const y = m(
|
|
1396
769
|
f,
|
|
1397
770
|
l,
|
|
1398
|
-
|
|
771
|
+
v,
|
|
1399
772
|
this.arrowWidth
|
|
1400
773
|
);
|
|
1401
774
|
this.targetArrow.setAttribute("d", y);
|
|
1402
775
|
}
|
|
1403
776
|
}
|
|
1404
777
|
}
|
|
1405
|
-
class
|
|
778
|
+
class Pe {
|
|
1406
779
|
constructor(e) {
|
|
1407
780
|
i(this, "svg", I());
|
|
1408
781
|
i(this, "group", W());
|
|
@@ -1426,10 +799,10 @@ class Ue {
|
|
|
1426
799
|
this.cycleSquareSide / 2
|
|
1427
800
|
), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirection, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow;
|
|
1428
801
|
const r = (e == null ? void 0 : e.color) ?? u.color, s = (e == null ? void 0 : e.width) ?? u.width;
|
|
1429
|
-
this.svg.appendChild(this.group), this.line = F(r, s), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow =
|
|
802
|
+
this.svg.appendChild(this.group), this.line = F(r, s), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
|
|
1430
803
|
}
|
|
1431
804
|
render(e) {
|
|
1432
|
-
const { x: o, y: r, width: s, height: d, flipX: n, flipY: h } =
|
|
805
|
+
const { x: o, y: r, width: s, height: d, flipX: n, flipY: h } = z(
|
|
1433
806
|
e.from,
|
|
1434
807
|
e.to
|
|
1435
808
|
);
|
|
@@ -1442,19 +815,19 @@ class Ue {
|
|
|
1442
815
|
x: s,
|
|
1443
816
|
y: d
|
|
1444
817
|
};
|
|
1445
|
-
let g, f = a,
|
|
1446
|
-
if (e.from.portId === e.to.portId ? (g =
|
|
1447
|
-
|
|
818
|
+
let g, f = a, v = -this.arrowLength;
|
|
819
|
+
if (e.from.portId === e.to.portId ? (g = j({
|
|
820
|
+
fromVector: c,
|
|
1448
821
|
arrowLength: this.arrowLength,
|
|
1449
822
|
side: this.cycleSquareSide,
|
|
1450
823
|
arrowOffset: this.arrowOffset,
|
|
1451
824
|
roundness: this.roundness,
|
|
1452
825
|
hasSourceArrow: this.hasSourceArrow,
|
|
1453
826
|
hasTargetArrow: this.hasTargetArrow
|
|
1454
|
-
}), f = c,
|
|
827
|
+
}), f = c, v = this.arrowLength) : e.from.nodeId === e.to.nodeId ? g = k({
|
|
1455
828
|
to: l,
|
|
1456
|
-
|
|
1457
|
-
|
|
829
|
+
fromVector: c,
|
|
830
|
+
toVector: a,
|
|
1458
831
|
flipX: n,
|
|
1459
832
|
flipY: h,
|
|
1460
833
|
arrowLength: this.arrowLength,
|
|
@@ -1464,10 +837,10 @@ class Ue {
|
|
|
1464
837
|
detourDistance: this.detourDistance,
|
|
1465
838
|
hasSourceArrow: this.hasSourceArrow,
|
|
1466
839
|
hasTargetArrow: this.hasTargetArrow
|
|
1467
|
-
}) : g =
|
|
840
|
+
}) : g = be({
|
|
1468
841
|
to: l,
|
|
1469
|
-
|
|
1470
|
-
|
|
842
|
+
fromVector: c,
|
|
843
|
+
toVector: a,
|
|
1471
844
|
arrowLength: this.arrowLength,
|
|
1472
845
|
arrowOffset: this.arrowOffset,
|
|
1473
846
|
roundness: this.roundness,
|
|
@@ -1486,14 +859,14 @@ class Ue {
|
|
|
1486
859
|
const y = m(
|
|
1487
860
|
f,
|
|
1488
861
|
l,
|
|
1489
|
-
|
|
862
|
+
v,
|
|
1490
863
|
this.arrowWidth
|
|
1491
864
|
);
|
|
1492
865
|
this.targetArrow.setAttribute("d", y);
|
|
1493
866
|
}
|
|
1494
867
|
}
|
|
1495
868
|
}
|
|
1496
|
-
class
|
|
869
|
+
class Ve {
|
|
1497
870
|
constructor(e) {
|
|
1498
871
|
i(this, "svg", I());
|
|
1499
872
|
i(this, "group", W());
|
|
@@ -1517,10 +890,10 @@ class $e {
|
|
|
1517
890
|
this.cycleSquareSide / 2
|
|
1518
891
|
), this.detourDirection = (e == null ? void 0 : e.detourDirection) ?? u.detourDirectionVertical, this.detourDistance = (e == null ? void 0 : e.detourDistance) ?? u.detourDistance, this.hasSourceArrow = (e == null ? void 0 : e.hasSourceArrow) ?? u.hasSourceArrow, this.hasTargetArrow = (e == null ? void 0 : e.hasTargetArrow) ?? u.hasTargetArrow;
|
|
1519
892
|
const r = (e == null ? void 0 : e.color) ?? u.color, s = (e == null ? void 0 : e.width) ?? u.width;
|
|
1520
|
-
this.svg.appendChild(this.group), this.line = F(r, s), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow =
|
|
893
|
+
this.svg.appendChild(this.group), this.line = F(r, s), this.group.appendChild(this.line), this.hasSourceArrow && (this.sourceArrow = N(r), this.group.appendChild(this.sourceArrow)), this.hasTargetArrow && (this.targetArrow = N(r), this.group.appendChild(this.targetArrow));
|
|
1521
894
|
}
|
|
1522
895
|
render(e) {
|
|
1523
|
-
const { x: o, y: r, width: s, height: d, flipX: n, flipY: h } =
|
|
896
|
+
const { x: o, y: r, width: s, height: d, flipX: n, flipY: h } = z(
|
|
1524
897
|
e.from,
|
|
1525
898
|
e.to
|
|
1526
899
|
);
|
|
@@ -1533,19 +906,19 @@ class $e {
|
|
|
1533
906
|
x: s,
|
|
1534
907
|
y: d
|
|
1535
908
|
};
|
|
1536
|
-
let g, f = a,
|
|
1537
|
-
if (e.from.portId === e.to.portId ? (g =
|
|
1538
|
-
|
|
909
|
+
let g, f = a, v = -this.arrowLength;
|
|
910
|
+
if (e.from.portId === e.to.portId ? (g = j({
|
|
911
|
+
fromVector: c,
|
|
1539
912
|
arrowLength: this.arrowLength,
|
|
1540
913
|
side: this.cycleSquareSide,
|
|
1541
914
|
arrowOffset: this.arrowOffset,
|
|
1542
915
|
roundness: this.roundness,
|
|
1543
916
|
hasSourceArrow: this.hasSourceArrow,
|
|
1544
917
|
hasTargetArrow: this.hasTargetArrow
|
|
1545
|
-
}), f = c,
|
|
918
|
+
}), f = c, v = this.arrowLength) : e.from.nodeId === e.to.nodeId ? g = k({
|
|
1546
919
|
to: l,
|
|
1547
|
-
|
|
1548
|
-
|
|
920
|
+
fromVector: c,
|
|
921
|
+
toVector: a,
|
|
1549
922
|
flipX: n,
|
|
1550
923
|
flipY: h,
|
|
1551
924
|
arrowLength: this.arrowLength,
|
|
@@ -1555,10 +928,10 @@ class $e {
|
|
|
1555
928
|
detourDistance: this.detourDistance,
|
|
1556
929
|
hasSourceArrow: this.hasSourceArrow,
|
|
1557
930
|
hasTargetArrow: this.hasTargetArrow
|
|
1558
|
-
}) : g =
|
|
931
|
+
}) : g = pe({
|
|
1559
932
|
to: l,
|
|
1560
|
-
|
|
1561
|
-
|
|
933
|
+
fromVector: c,
|
|
934
|
+
toVector: a,
|
|
1562
935
|
flipY: h,
|
|
1563
936
|
arrowLength: this.arrowLength,
|
|
1564
937
|
arrowOffset: this.arrowOffset,
|
|
@@ -1578,19 +951,19 @@ class $e {
|
|
|
1578
951
|
const y = m(
|
|
1579
952
|
f,
|
|
1580
953
|
l,
|
|
1581
|
-
|
|
954
|
+
v,
|
|
1582
955
|
this.arrowWidth
|
|
1583
956
|
);
|
|
1584
957
|
this.targetArrow.setAttribute("d", y);
|
|
1585
958
|
}
|
|
1586
959
|
}
|
|
1587
960
|
}
|
|
1588
|
-
const
|
|
961
|
+
const De = (t) => {
|
|
1589
962
|
if (typeof t == "function")
|
|
1590
963
|
return t;
|
|
1591
964
|
switch (t == null ? void 0 : t.type) {
|
|
1592
965
|
case "straight":
|
|
1593
|
-
return () => new
|
|
966
|
+
return () => new Pe({
|
|
1594
967
|
color: t.color,
|
|
1595
968
|
width: t.width,
|
|
1596
969
|
arrowLength: t.arrowLength,
|
|
@@ -1604,7 +977,7 @@ const Re = (t) => {
|
|
|
1604
977
|
detourDirection: t.detourDirection
|
|
1605
978
|
});
|
|
1606
979
|
case "horizontal":
|
|
1607
|
-
return () => new
|
|
980
|
+
return () => new Ne({
|
|
1608
981
|
color: t.color,
|
|
1609
982
|
width: t.width,
|
|
1610
983
|
arrowLength: t.arrowLength,
|
|
@@ -1618,7 +991,7 @@ const Re = (t) => {
|
|
|
1618
991
|
detourDirection: t.detourDirection
|
|
1619
992
|
});
|
|
1620
993
|
case "vertical":
|
|
1621
|
-
return () => new
|
|
994
|
+
return () => new Ve({
|
|
1622
995
|
color: t.color,
|
|
1623
996
|
width: t.width,
|
|
1624
997
|
arrowLength: t.arrowLength,
|
|
@@ -1632,7 +1005,7 @@ const Re = (t) => {
|
|
|
1632
1005
|
detourDirection: t.detourDirection
|
|
1633
1006
|
});
|
|
1634
1007
|
default:
|
|
1635
|
-
return () => new
|
|
1008
|
+
return () => new me({
|
|
1636
1009
|
color: t.color,
|
|
1637
1010
|
width: t.width,
|
|
1638
1011
|
arrowLength: t.arrowLength,
|
|
@@ -1646,56 +1019,108 @@ const Re = (t) => {
|
|
|
1646
1019
|
detourDirection: t.detourDirection
|
|
1647
1020
|
});
|
|
1648
1021
|
}
|
|
1649
|
-
},
|
|
1022
|
+
}, Me = (t) => {
|
|
1650
1023
|
var o, r, s, d, n;
|
|
1651
|
-
const e =
|
|
1024
|
+
const e = xe(
|
|
1652
1025
|
(o = t == null ? void 0 : t.nodes) == null ? void 0 : o.priority,
|
|
1653
1026
|
(r = t == null ? void 0 : t.edges) == null ? void 0 : r.priority
|
|
1654
1027
|
);
|
|
1655
1028
|
return {
|
|
1656
1029
|
nodes: {
|
|
1657
|
-
centerFn: ((s = t == null ? void 0 : t.nodes) == null ? void 0 : s.centerFn) ??
|
|
1030
|
+
centerFn: ((s = t == null ? void 0 : t.nodes) == null ? void 0 : s.centerFn) ?? ye,
|
|
1658
1031
|
priorityFn: e.nodesPriorityFn
|
|
1659
1032
|
},
|
|
1660
1033
|
ports: {
|
|
1661
1034
|
direction: ((d = t == null ? void 0 : t.ports) == null ? void 0 : d.direction) ?? 0
|
|
1662
1035
|
},
|
|
1663
1036
|
edges: {
|
|
1664
|
-
shapeFactory:
|
|
1037
|
+
shapeFactory: De(((n = t == null ? void 0 : t.edges) == null ? void 0 : n.shape) ?? {}),
|
|
1665
1038
|
priorityFn: e.edgesPriorityFn
|
|
1666
1039
|
}
|
|
1667
1040
|
};
|
|
1668
1041
|
};
|
|
1669
|
-
class
|
|
1670
|
-
constructor(e, o, r) {
|
|
1671
|
-
i(this, "nodeIdGenerator", new Y(
|
|
1672
|
-
(e) => this.graph.getNode(e) !== null
|
|
1673
|
-
));
|
|
1674
|
-
i(this, "portIdGenerator", new Y(
|
|
1675
|
-
(e) => this.graph.getPort(e) !== null
|
|
1676
|
-
));
|
|
1677
|
-
i(this, "edgeIdGenerator", new Y(
|
|
1678
|
-
(e) => this.graph.getEdge(e) !== null
|
|
1679
|
-
));
|
|
1680
|
-
i(this, "defaults");
|
|
1042
|
+
class Le {
|
|
1043
|
+
constructor(e, o, r, s, d) {
|
|
1681
1044
|
/**
|
|
1682
|
-
* provides api for accessing graph
|
|
1045
|
+
* provides api for accessing model of rendered graph
|
|
1683
1046
|
*/
|
|
1684
1047
|
i(this, "graph");
|
|
1685
1048
|
/**
|
|
1686
1049
|
* provides api for accessing viewport state
|
|
1687
1050
|
*/
|
|
1688
1051
|
i(this, "viewport");
|
|
1689
|
-
this
|
|
1052
|
+
i(this, "defaults");
|
|
1053
|
+
i(this, "nodeIdGenerator", new X(
|
|
1054
|
+
(e) => this.graph.getNode(e) !== null
|
|
1055
|
+
));
|
|
1056
|
+
i(this, "portIdGenerator", new X(
|
|
1057
|
+
(e) => this.graph.getPort(e) !== null
|
|
1058
|
+
));
|
|
1059
|
+
i(this, "edgeIdGenerator", new X(
|
|
1060
|
+
(e) => this.graph.getEdge(e) !== null
|
|
1061
|
+
));
|
|
1062
|
+
i(this, "onAfterNodeAdded", (e) => {
|
|
1063
|
+
this.htmlView.attachNode(e);
|
|
1064
|
+
});
|
|
1065
|
+
i(this, "onAfterNodeUpdated", (e) => {
|
|
1066
|
+
this.htmlView.updateNodePosition(e), this.graphStore.getNodeAdjacentEdgeIds(e).forEach((r) => {
|
|
1067
|
+
this.htmlView.renderEdge(r);
|
|
1068
|
+
});
|
|
1069
|
+
});
|
|
1070
|
+
i(this, "onAfterNodePriorityUpdated", (e) => {
|
|
1071
|
+
this.htmlView.updateNodePriority(e);
|
|
1072
|
+
});
|
|
1073
|
+
i(this, "onBeforeNodeRemoved", (e) => {
|
|
1074
|
+
this.graphStore.getNodePortIds(e).forEach((o) => {
|
|
1075
|
+
this.unmarkPort(o);
|
|
1076
|
+
}), this.htmlView.detachNode(e);
|
|
1077
|
+
});
|
|
1078
|
+
i(this, "onAfterPortUpdated", (e) => {
|
|
1079
|
+
this.graphStore.getPortAdjacentEdgeIds(e).forEach((r) => {
|
|
1080
|
+
this.htmlView.renderEdge(r);
|
|
1081
|
+
});
|
|
1082
|
+
});
|
|
1083
|
+
i(this, "onBeforePortUnmarked", (e) => {
|
|
1084
|
+
this.graphStore.getPortAdjacentEdgeIds(e).forEach((o) => {
|
|
1085
|
+
this.removeEdge(o);
|
|
1086
|
+
});
|
|
1087
|
+
});
|
|
1088
|
+
i(this, "onAfterEdgeAdded", (e) => {
|
|
1089
|
+
this.htmlView.attachEdge(e);
|
|
1090
|
+
});
|
|
1091
|
+
i(this, "onAfterEdgeShapeUpdated", (e) => {
|
|
1092
|
+
this.htmlView.updateEdgeShape(e);
|
|
1093
|
+
});
|
|
1094
|
+
i(this, "onAfterEdgeUpdated", (e) => {
|
|
1095
|
+
this.htmlView.renderEdge(e);
|
|
1096
|
+
});
|
|
1097
|
+
i(this, "onAfterEdgePriorityUpdated", (e) => {
|
|
1098
|
+
this.htmlView.updateEdgePriority(e);
|
|
1099
|
+
});
|
|
1100
|
+
i(this, "onBeforeEdgeRemoved", (e) => {
|
|
1101
|
+
this.htmlView.detachEdge(e);
|
|
1102
|
+
});
|
|
1103
|
+
i(this, "onBeforeClear", () => {
|
|
1104
|
+
this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset(), this.htmlView.clear();
|
|
1105
|
+
});
|
|
1106
|
+
i(this, "onBeforeDestroyEmitter");
|
|
1107
|
+
i(this, "onBeforeDestroy");
|
|
1108
|
+
this.element = e, this.graphStore = o, this.viewportStore = r, this.htmlView = s, this.defaults = Me(d), this.graph = new fe(this.graphStore), this.viewport = new we(this.viewportStore), this.graphStore.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.subscribe(
|
|
1109
|
+
this.onAfterNodePriorityUpdated
|
|
1110
|
+
), this.graphStore.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.graphStore.onAfterPortUpdated.subscribe(this.onAfterPortUpdated), this.graphStore.onBeforePortRemoved.subscribe(this.onBeforePortUnmarked), this.graphStore.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded), this.graphStore.onAfterEdgeShapeUpdated.subscribe(
|
|
1111
|
+
this.onAfterEdgeShapeUpdated
|
|
1112
|
+
), this.graphStore.onAfterEdgeUpdated.subscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.subscribe(
|
|
1113
|
+
this.onAfterEdgePriorityUpdated
|
|
1114
|
+
), this.graphStore.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.subscribe(this.onBeforeClear), [this.onBeforeDestroyEmitter, this.onBeforeDestroy] = A();
|
|
1690
1115
|
}
|
|
1691
1116
|
/**
|
|
1692
|
-
* adds node
|
|
1117
|
+
* adds new node
|
|
1693
1118
|
*/
|
|
1694
1119
|
addNode(e) {
|
|
1695
1120
|
const o = this.nodeIdGenerator.create(e.id);
|
|
1696
1121
|
if (this.graph.getNode(o) !== null)
|
|
1697
|
-
throw new
|
|
1698
|
-
if (this.
|
|
1122
|
+
throw new b("failed to add node with existing id");
|
|
1123
|
+
if (this.graphStore.addNode({
|
|
1699
1124
|
id: o,
|
|
1700
1125
|
element: e.element,
|
|
1701
1126
|
x: e.x,
|
|
@@ -1712,373 +1137,963 @@ class We {
|
|
|
1712
1137
|
});
|
|
1713
1138
|
return this;
|
|
1714
1139
|
}
|
|
1715
|
-
/**
|
|
1716
|
-
* updates node parameters
|
|
1717
|
-
*/
|
|
1140
|
+
/**
|
|
1141
|
+
* updates node parameters
|
|
1142
|
+
*/
|
|
1143
|
+
updateNode(e, o) {
|
|
1144
|
+
if (this.graph.getNode(e) === null)
|
|
1145
|
+
throw new b("failed to update non existing node");
|
|
1146
|
+
return this.graphStore.updateNode(e, o ?? {}), this;
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* removes specified node
|
|
1150
|
+
* all the ports of node get unmarked
|
|
1151
|
+
* all the edges adjacent to node get removed
|
|
1152
|
+
*/
|
|
1153
|
+
removeNode(e) {
|
|
1154
|
+
if (this.graph.getNode(e) === null)
|
|
1155
|
+
throw new b("failed to remove non existing node");
|
|
1156
|
+
return this.graphStore.removeNode(e), this;
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* marks specified element as a port for specified node
|
|
1160
|
+
*/
|
|
1161
|
+
markPort(e) {
|
|
1162
|
+
const o = this.portIdGenerator.create(e.id);
|
|
1163
|
+
if (this.graph.getPort(o) !== null)
|
|
1164
|
+
throw new b("failed to add port with existing id");
|
|
1165
|
+
if (this.graph.getNode(e.nodeId) === null)
|
|
1166
|
+
throw new b("failed to mark port for nonexistent node");
|
|
1167
|
+
return this.graphStore.addPort({
|
|
1168
|
+
id: o,
|
|
1169
|
+
element: e.element,
|
|
1170
|
+
nodeId: e.nodeId,
|
|
1171
|
+
direction: e.direction ?? this.defaults.ports.direction
|
|
1172
|
+
}), this;
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* updates port and edges attached to it
|
|
1176
|
+
*/
|
|
1177
|
+
updatePort(e, o) {
|
|
1178
|
+
if (this.graph.getPort(e) === null)
|
|
1179
|
+
throw new b("failed to update nonexistent port");
|
|
1180
|
+
return this.graphStore.updatePort(e, o ?? {}), this;
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* unmarks specified port
|
|
1184
|
+
* all the edges adjacent to the port get removed
|
|
1185
|
+
*/
|
|
1186
|
+
unmarkPort(e) {
|
|
1187
|
+
if (this.graph.getPort(e) === null)
|
|
1188
|
+
throw new b("failed to unmark non existing port");
|
|
1189
|
+
return this.graphStore.removePort(e), this;
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* adds new edge
|
|
1193
|
+
*/
|
|
1194
|
+
addEdge(e) {
|
|
1195
|
+
const o = this.edgeIdGenerator.create(e.id);
|
|
1196
|
+
if (this.graph.getEdge(o) !== null)
|
|
1197
|
+
throw new b("failed to add edge with existing id");
|
|
1198
|
+
if (this.graph.getPort(e.from) === null)
|
|
1199
|
+
throw new b("failed to add edge from nonexistent port");
|
|
1200
|
+
if (this.graph.getPort(e.to) === null)
|
|
1201
|
+
throw new b("failed to add edge to nonexistent port");
|
|
1202
|
+
return this.graphStore.addEdge({
|
|
1203
|
+
id: o,
|
|
1204
|
+
from: e.from,
|
|
1205
|
+
to: e.to,
|
|
1206
|
+
shape: e.shape ?? this.defaults.edges.shapeFactory(),
|
|
1207
|
+
priority: e.priority ?? this.defaults.edges.priorityFn()
|
|
1208
|
+
}), this;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* updates specified edge
|
|
1212
|
+
*/
|
|
1213
|
+
updateEdge(e, o) {
|
|
1214
|
+
if (this.graph.getEdge(e) === null)
|
|
1215
|
+
throw new b("failed to update nonexistent edge");
|
|
1216
|
+
return this.graphStore.updateEdge(e, o ?? {}), this;
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* removes specified edge
|
|
1220
|
+
*/
|
|
1221
|
+
removeEdge(e) {
|
|
1222
|
+
if (this.graph.getEdge(e) === null)
|
|
1223
|
+
throw new b("failed to remove nonexistent edge");
|
|
1224
|
+
return this.graphStore.removeEdge(e), this;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* applies transformation for viewport matrix
|
|
1228
|
+
*/
|
|
1229
|
+
patchViewportMatrix(e) {
|
|
1230
|
+
return this.viewportStore.patchViewportMatrix(e), this;
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* applies transformation for content matrix
|
|
1234
|
+
*/
|
|
1235
|
+
patchContentMatrix(e) {
|
|
1236
|
+
return this.viewportStore.patchContentMatrix(e), this;
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* clears canvas from nodes and edges
|
|
1240
|
+
* canvas gets rolled back to initial state and can be reused
|
|
1241
|
+
*/
|
|
1242
|
+
clear() {
|
|
1243
|
+
return this.graphStore.clear(), this;
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* destroys canvas
|
|
1247
|
+
* canvas element gets rolled back to initial state, and can not be reused
|
|
1248
|
+
*/
|
|
1249
|
+
destroy() {
|
|
1250
|
+
this.onBeforeDestroyEmitter.emit(), this.graphStore.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded), this.graphStore.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated), this.graphStore.onAfterNodePriorityUpdated.unsubscribe(
|
|
1251
|
+
this.onAfterNodePriorityUpdated
|
|
1252
|
+
), this.graphStore.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved), this.graphStore.onAfterPortUpdated.unsubscribe(this.onAfterPortUpdated), this.graphStore.onBeforePortRemoved.unsubscribe(this.onBeforePortUnmarked), this.graphStore.onAfterEdgeAdded.unsubscribe(this.onAfterEdgeAdded), this.graphStore.onAfterEdgeShapeUpdated.unsubscribe(
|
|
1253
|
+
this.onAfterEdgeShapeUpdated
|
|
1254
|
+
), this.graphStore.onAfterEdgeUpdated.unsubscribe(this.onAfterEdgeUpdated), this.graphStore.onAfterEdgePriorityUpdated.unsubscribe(
|
|
1255
|
+
this.onAfterEdgePriorityUpdated
|
|
1256
|
+
), this.graphStore.onBeforeEdgeRemoved.unsubscribe(this.onBeforeEdgeRemoved), this.graphStore.onBeforeClear.unsubscribe(this.onBeforeClear), this.clear(), this.htmlView.destroy();
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
class Ce {
|
|
1260
|
+
constructor() {
|
|
1261
|
+
i(this, "nodes", /* @__PURE__ */ new Map());
|
|
1262
|
+
i(this, "ports", /* @__PURE__ */ new Map());
|
|
1263
|
+
i(this, "edges", /* @__PURE__ */ new Map());
|
|
1264
|
+
i(this, "incomingEdges", /* @__PURE__ */ new Map());
|
|
1265
|
+
i(this, "outcomingEdges", /* @__PURE__ */ new Map());
|
|
1266
|
+
i(this, "cycleEdges", /* @__PURE__ */ new Map());
|
|
1267
|
+
i(this, "afterNodeAddedEmitter");
|
|
1268
|
+
i(this, "onAfterNodeAdded");
|
|
1269
|
+
i(this, "afterNodeUpdatedEmitter");
|
|
1270
|
+
i(this, "onAfterNodeUpdated");
|
|
1271
|
+
i(this, "afterNodePriorityUpdatedEmitter");
|
|
1272
|
+
i(this, "onAfterNodePriorityUpdated");
|
|
1273
|
+
i(this, "beforeNodeRemovedEmitter");
|
|
1274
|
+
i(this, "onBeforeNodeRemoved");
|
|
1275
|
+
i(this, "afterPortAddedEmitter");
|
|
1276
|
+
i(this, "onAfterPortAdded");
|
|
1277
|
+
i(this, "afterPortUpdatedEmitter");
|
|
1278
|
+
i(this, "onAfterPortUpdated");
|
|
1279
|
+
i(this, "beforePortRemovedEmitter");
|
|
1280
|
+
i(this, "onBeforePortRemoved");
|
|
1281
|
+
i(this, "afterEdgeAddedEmitter");
|
|
1282
|
+
i(this, "onAfterEdgeAdded");
|
|
1283
|
+
i(this, "afterEdgeShapeUpdatedEmitter");
|
|
1284
|
+
i(this, "onAfterEdgeShapeUpdated");
|
|
1285
|
+
i(this, "afterEdgeUpdatedEmitter");
|
|
1286
|
+
i(this, "onAfterEdgeUpdated");
|
|
1287
|
+
i(this, "afterEdgePriorityUpdatedEmitter");
|
|
1288
|
+
i(this, "onAfterEdgePriorityUpdated");
|
|
1289
|
+
i(this, "beforeEdgeRemovedEmitter");
|
|
1290
|
+
i(this, "onBeforeEdgeRemoved");
|
|
1291
|
+
i(this, "beforeClearEmitter");
|
|
1292
|
+
i(this, "onBeforeClear");
|
|
1293
|
+
[this.afterNodeAddedEmitter, this.onAfterNodeAdded] = A(), [this.afterNodeUpdatedEmitter, this.onAfterNodeUpdated] = A(), [this.afterNodePriorityUpdatedEmitter, this.onAfterNodePriorityUpdated] = A(), [this.beforeNodeRemovedEmitter, this.onBeforeNodeRemoved] = A(), [this.afterPortAddedEmitter, this.onAfterPortAdded] = A(), [this.afterPortUpdatedEmitter, this.onAfterPortUpdated] = A(), [this.beforePortRemovedEmitter, this.onBeforePortRemoved] = A(), [this.afterEdgeAddedEmitter, this.onAfterEdgeAdded] = A(), [this.afterEdgeShapeUpdatedEmitter, this.onAfterEdgeShapeUpdated] = A(), [this.afterEdgeUpdatedEmitter, this.onAfterEdgeUpdated] = A(), [this.afterEdgePriorityUpdatedEmitter, this.onAfterEdgePriorityUpdated] = A(), [this.beforeEdgeRemovedEmitter, this.onBeforeEdgeRemoved] = A(), [this.beforeClearEmitter, this.onBeforeClear] = A();
|
|
1294
|
+
}
|
|
1295
|
+
addNode(e) {
|
|
1296
|
+
const o = /* @__PURE__ */ new Map(), r = {
|
|
1297
|
+
element: e.element,
|
|
1298
|
+
x: e.x,
|
|
1299
|
+
y: e.y,
|
|
1300
|
+
centerFn: e.centerFn,
|
|
1301
|
+
priority: e.priority,
|
|
1302
|
+
ports: o
|
|
1303
|
+
};
|
|
1304
|
+
this.nodes.set(e.id, r), this.afterNodeAddedEmitter.emit(e.id);
|
|
1305
|
+
}
|
|
1306
|
+
getAllNodeIds() {
|
|
1307
|
+
return Array.from(this.nodes.keys());
|
|
1308
|
+
}
|
|
1309
|
+
getNode(e) {
|
|
1310
|
+
return this.nodes.get(e);
|
|
1311
|
+
}
|
|
1718
1312
|
updateNode(e, o) {
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
return this.controller.updateNode(e, o ?? {}), this;
|
|
1313
|
+
const r = this.nodes.get(e);
|
|
1314
|
+
r.x = o.x ?? r.x, r.y = o.y ?? r.y, r.centerFn = o.centerFn ?? r.centerFn, o.priority !== void 0 && (r.priority = o.priority, this.afterNodePriorityUpdatedEmitter.emit(e)), this.afterNodeUpdatedEmitter.emit(e);
|
|
1722
1315
|
}
|
|
1723
|
-
/**
|
|
1724
|
-
* removes node from graph
|
|
1725
|
-
* all the ports of node get unmarked
|
|
1726
|
-
* all the edges adjacent to node get removed
|
|
1727
|
-
*/
|
|
1728
1316
|
removeNode(e) {
|
|
1729
|
-
|
|
1730
|
-
throw new A("failed to remove nonexisting node");
|
|
1731
|
-
return this.controller.removeNode(e), this;
|
|
1317
|
+
this.beforeNodeRemovedEmitter.emit(e), this.nodes.delete(e);
|
|
1732
1318
|
}
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
*/
|
|
1736
|
-
markPort(e) {
|
|
1737
|
-
const o = this.portIdGenerator.create(e.id);
|
|
1738
|
-
if (this.graph.getPort(o) !== null)
|
|
1739
|
-
throw new A("failed to add port with existing id");
|
|
1740
|
-
if (this.graph.getNode(e.nodeId) === null)
|
|
1741
|
-
throw new A("failed to set port on nonexisting node");
|
|
1742
|
-
return this.controller.markPort({
|
|
1743
|
-
id: o,
|
|
1319
|
+
addPort(e) {
|
|
1320
|
+
this.ports.set(e.id, {
|
|
1744
1321
|
element: e.element,
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
}), this;
|
|
1322
|
+
direction: e.direction,
|
|
1323
|
+
nodeId: e.nodeId
|
|
1324
|
+
}), this.cycleEdges.set(e.id, /* @__PURE__ */ new Set()), this.incomingEdges.set(e.id, /* @__PURE__ */ new Set()), this.outcomingEdges.set(e.id, /* @__PURE__ */ new Set()), this.nodes.get(e.nodeId).ports.set(e.id, e.element), this.afterPortAddedEmitter.emit(e.id);
|
|
1325
|
+
}
|
|
1326
|
+
getPort(e) {
|
|
1327
|
+
return this.ports.get(e);
|
|
1748
1328
|
}
|
|
1749
|
-
/**
|
|
1750
|
-
* updates port and attached edges
|
|
1751
|
-
*/
|
|
1752
1329
|
updatePort(e, o) {
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
return this.controller.updatePort(e, o ?? {}), this;
|
|
1330
|
+
const r = this.ports.get(e);
|
|
1331
|
+
r.direction = o.direction ?? r.direction, this.afterPortUpdatedEmitter.emit(e);
|
|
1756
1332
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
if (
|
|
1763
|
-
|
|
1764
|
-
|
|
1333
|
+
getAllPortIds() {
|
|
1334
|
+
return Array.from(this.ports.keys());
|
|
1335
|
+
}
|
|
1336
|
+
getNodePortIds(e) {
|
|
1337
|
+
const o = this.nodes.get(e);
|
|
1338
|
+
if (o !== void 0)
|
|
1339
|
+
return Array.from(o.ports.keys());
|
|
1340
|
+
}
|
|
1341
|
+
removePort(e) {
|
|
1342
|
+
const o = this.ports.get(e).nodeId;
|
|
1343
|
+
this.beforePortRemovedEmitter.emit(e), this.nodes.get(o).ports.delete(e), this.ports.delete(e);
|
|
1765
1344
|
}
|
|
1766
|
-
/**
|
|
1767
|
-
* adds edge to graph
|
|
1768
|
-
*/
|
|
1769
1345
|
addEdge(e) {
|
|
1770
|
-
|
|
1771
|
-
if (this.graph.getEdge(o) !== null)
|
|
1772
|
-
throw new A("failed to add edge with existing id");
|
|
1773
|
-
if (this.graph.getPort(e.from) === null)
|
|
1774
|
-
throw new A("failed to add edge from nonexisting port");
|
|
1775
|
-
if (this.graph.getPort(e.to) === null)
|
|
1776
|
-
throw new A("failed to add edge to nonexisting port");
|
|
1777
|
-
return this.controller.addEdge({
|
|
1778
|
-
id: o,
|
|
1779
|
-
from: e.from,
|
|
1780
|
-
to: e.to,
|
|
1781
|
-
shape: e.shape ?? this.defaults.edges.shapeFactory(),
|
|
1782
|
-
priority: e.priority ?? this.defaults.edges.priorityFn()
|
|
1783
|
-
}), this;
|
|
1346
|
+
this.addEdgeInternal(e), this.afterEdgeAddedEmitter.emit(e.id);
|
|
1784
1347
|
}
|
|
1785
|
-
/**
|
|
1786
|
-
* updates edge
|
|
1787
|
-
*/
|
|
1788
1348
|
updateEdge(e, o) {
|
|
1789
|
-
if (
|
|
1790
|
-
|
|
1791
|
-
|
|
1349
|
+
if (o.from !== void 0 || o.to !== void 0) {
|
|
1350
|
+
const s = this.edges.get(e);
|
|
1351
|
+
this.removeEdgeInternal(e), this.addEdgeInternal({
|
|
1352
|
+
id: e,
|
|
1353
|
+
from: o.from ?? s.from,
|
|
1354
|
+
to: o.to ?? s.to,
|
|
1355
|
+
shape: s.shape,
|
|
1356
|
+
priority: s.priority
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
const r = this.edges.get(e);
|
|
1360
|
+
o.shape !== void 0 && (r.shape = o.shape, this.afterEdgeShapeUpdatedEmitter.emit(e)), o.priority !== void 0 && (r.priority = o.priority, this.afterEdgePriorityUpdatedEmitter.emit(e)), this.afterEdgeUpdatedEmitter.emit(e);
|
|
1361
|
+
}
|
|
1362
|
+
getAllEdgeIds() {
|
|
1363
|
+
return Array.from(this.edges.keys());
|
|
1364
|
+
}
|
|
1365
|
+
getEdge(e) {
|
|
1366
|
+
return this.edges.get(e);
|
|
1792
1367
|
}
|
|
1793
|
-
/**
|
|
1794
|
-
* removes edge from graph
|
|
1795
|
-
*/
|
|
1796
1368
|
removeEdge(e) {
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1369
|
+
this.beforeEdgeRemovedEmitter.emit(e), this.removeEdgeInternal(e);
|
|
1370
|
+
}
|
|
1371
|
+
clear() {
|
|
1372
|
+
this.beforeClearEmitter.emit(), this.incomingEdges.clear(), this.outcomingEdges.clear(), this.cycleEdges.clear(), this.edges.clear(), this.ports.clear(), this.nodes.clear();
|
|
1373
|
+
}
|
|
1374
|
+
getPortIncomingEdgeIds(e) {
|
|
1375
|
+
return Array.from(this.incomingEdges.get(e));
|
|
1376
|
+
}
|
|
1377
|
+
getPortOutcomingEdgeIds(e) {
|
|
1378
|
+
return Array.from(this.outcomingEdges.get(e));
|
|
1379
|
+
}
|
|
1380
|
+
getPortCycleEdgeIds(e) {
|
|
1381
|
+
return Array.from(this.cycleEdges.get(e));
|
|
1382
|
+
}
|
|
1383
|
+
getPortAdjacentEdgeIds(e) {
|
|
1384
|
+
return [
|
|
1385
|
+
...this.getPortIncomingEdgeIds(e),
|
|
1386
|
+
...this.getPortOutcomingEdgeIds(e),
|
|
1387
|
+
...this.getPortCycleEdgeIds(e)
|
|
1388
|
+
];
|
|
1389
|
+
}
|
|
1390
|
+
getNodeIncomingEdgeIds(e) {
|
|
1391
|
+
const o = Array.from(this.nodes.get(e).ports.keys());
|
|
1392
|
+
let r = [];
|
|
1393
|
+
return o.forEach((s) => {
|
|
1394
|
+
r = [...r, ...this.getPortIncomingEdgeIds(s)];
|
|
1395
|
+
}), r;
|
|
1396
|
+
}
|
|
1397
|
+
getNodeOutcomingEdgeIds(e) {
|
|
1398
|
+
const o = Array.from(this.nodes.get(e).ports.keys());
|
|
1399
|
+
let r = [];
|
|
1400
|
+
return o.forEach((s) => {
|
|
1401
|
+
r = [...r, ...this.getPortOutcomingEdgeIds(s)];
|
|
1402
|
+
}), r;
|
|
1403
|
+
}
|
|
1404
|
+
getNodeCycleEdgeIds(e) {
|
|
1405
|
+
const o = Array.from(this.nodes.get(e).ports.keys());
|
|
1406
|
+
let r = [];
|
|
1407
|
+
return o.forEach((s) => {
|
|
1408
|
+
r = [...r, ...this.getPortCycleEdgeIds(s)];
|
|
1409
|
+
}), r;
|
|
1410
|
+
}
|
|
1411
|
+
getNodeAdjacentEdgeIds(e) {
|
|
1412
|
+
return [
|
|
1413
|
+
...this.getNodeIncomingEdgeIds(e),
|
|
1414
|
+
...this.getNodeOutcomingEdgeIds(e),
|
|
1415
|
+
...this.getNodeCycleEdgeIds(e)
|
|
1416
|
+
];
|
|
1417
|
+
}
|
|
1418
|
+
addEdgeInternal(e) {
|
|
1419
|
+
this.edges.set(e.id, {
|
|
1420
|
+
from: e.from,
|
|
1421
|
+
to: e.to,
|
|
1422
|
+
shape: e.shape,
|
|
1423
|
+
priority: e.priority
|
|
1424
|
+
}), e.from !== e.to ? (this.outcomingEdges.get(e.from).add(e.id), this.incomingEdges.get(e.to).add(e.id)) : this.cycleEdges.get(e.from).add(e.id);
|
|
1425
|
+
}
|
|
1426
|
+
removeEdgeInternal(e) {
|
|
1427
|
+
const o = this.edges.get(e), r = o.from, s = o.to;
|
|
1428
|
+
this.cycleEdges.get(r).delete(e), this.cycleEdges.get(s).delete(e), this.incomingEdges.get(r).delete(e), this.incomingEdges.get(s).delete(e), this.outcomingEdges.get(r).delete(e), this.outcomingEdges.get(s).delete(e), this.edges.delete(e);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const te = (t) => ({
|
|
1432
|
+
scale: 1 / t.scale,
|
|
1433
|
+
x: -t.x / t.scale,
|
|
1434
|
+
y: -t.y / t.scale
|
|
1435
|
+
}), oe = {
|
|
1436
|
+
scale: 1,
|
|
1437
|
+
x: 0,
|
|
1438
|
+
y: 0
|
|
1439
|
+
};
|
|
1440
|
+
class Re {
|
|
1441
|
+
constructor() {
|
|
1442
|
+
i(this, "viewportMatrix", oe);
|
|
1443
|
+
i(this, "contentMatrix", oe);
|
|
1444
|
+
i(this, "afterUpdateEmitter");
|
|
1445
|
+
i(this, "onAfterUpdated");
|
|
1446
|
+
i(this, "beforeUpdateEmitter");
|
|
1447
|
+
i(this, "onBeforeUpdated");
|
|
1448
|
+
[this.afterUpdateEmitter, this.onAfterUpdated] = A(), [this.beforeUpdateEmitter, this.onBeforeUpdated] = A();
|
|
1449
|
+
}
|
|
1450
|
+
getViewportMatrix() {
|
|
1451
|
+
return this.viewportMatrix;
|
|
1452
|
+
}
|
|
1453
|
+
getContentMatrix() {
|
|
1454
|
+
return this.contentMatrix;
|
|
1800
1455
|
}
|
|
1801
|
-
/**
|
|
1802
|
-
* applies transformation for viewport
|
|
1803
|
-
*/
|
|
1804
1456
|
patchViewportMatrix(e) {
|
|
1805
|
-
|
|
1457
|
+
this.beforeUpdateEmitter.emit(), this.viewportMatrix = {
|
|
1458
|
+
scale: e.scale ?? this.viewportMatrix.scale,
|
|
1459
|
+
x: e.x ?? this.viewportMatrix.x,
|
|
1460
|
+
y: e.y ?? this.viewportMatrix.y
|
|
1461
|
+
}, this.contentMatrix = te(this.viewportMatrix), this.afterUpdateEmitter.emit();
|
|
1806
1462
|
}
|
|
1807
|
-
/**
|
|
1808
|
-
* applies transformation for content
|
|
1809
|
-
*/
|
|
1810
1463
|
patchContentMatrix(e) {
|
|
1811
|
-
|
|
1464
|
+
this.beforeUpdateEmitter.emit(), this.contentMatrix = {
|
|
1465
|
+
scale: e.scale ?? this.contentMatrix.scale,
|
|
1466
|
+
x: e.x ?? this.contentMatrix.x,
|
|
1467
|
+
y: e.y ?? this.contentMatrix.y
|
|
1468
|
+
}, this.viewportMatrix = te(this.contentMatrix), this.afterUpdateEmitter.emit();
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
class G {
|
|
1472
|
+
constructor(e) {
|
|
1473
|
+
i(this, "elementToNodeId", /* @__PURE__ */ new Map());
|
|
1474
|
+
i(this, "nodesResizeObserver");
|
|
1475
|
+
i(this, "onAfterNodeAdded", (e) => {
|
|
1476
|
+
const o = this.canvas.graph.getNode(e);
|
|
1477
|
+
this.elementToNodeId.set(o.element, e), this.nodesResizeObserver.observe(o.element);
|
|
1478
|
+
});
|
|
1479
|
+
i(this, "onBeforeNodeRemoved", (e) => {
|
|
1480
|
+
const o = this.canvas.graph.getNode(e);
|
|
1481
|
+
this.elementToNodeId.delete(o.element), this.nodesResizeObserver.unobserve(o.element);
|
|
1482
|
+
});
|
|
1483
|
+
i(this, "onBeforeClear", () => {
|
|
1484
|
+
this.nodesResizeObserver.disconnect(), this.elementToNodeId.clear();
|
|
1485
|
+
});
|
|
1486
|
+
i(this, "onBeforeDestroy", () => {
|
|
1487
|
+
this.canvas.graph.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded), this.canvas.graph.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved), this.canvas.graph.onBeforeClear.unsubscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
|
|
1488
|
+
});
|
|
1489
|
+
this.canvas = e, this.nodesResizeObserver = new ResizeObserver((o) => {
|
|
1490
|
+
o.forEach((r) => {
|
|
1491
|
+
const s = r.target;
|
|
1492
|
+
this.handleNodeResize(s);
|
|
1493
|
+
});
|
|
1494
|
+
}), this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
|
|
1495
|
+
}
|
|
1496
|
+
static configure(e) {
|
|
1497
|
+
new G(e);
|
|
1498
|
+
}
|
|
1499
|
+
handleNodeResize(e) {
|
|
1500
|
+
const o = this.elementToNodeId.get(e);
|
|
1501
|
+
this.canvas.updateNode(o), this.canvas.graph.getNodeAdjacentEdgeIds(o).forEach((s) => {
|
|
1502
|
+
this.canvas.updateEdge(s);
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
const Ue = (t) => {
|
|
1507
|
+
var g, f, v, y, p, E;
|
|
1508
|
+
const e = ((g = t == null ? void 0 : t.events) == null ? void 0 : g.onNodeDrag) ?? (() => {
|
|
1509
|
+
}), o = ((f = t == null ? void 0 : t.events) == null ? void 0 : f.onBeforeNodeDrag) ?? (() => !0), r = ((v = t == null ? void 0 : t.events) == null ? void 0 : v.onNodeDragFinished) ?? (() => {
|
|
1510
|
+
}), s = (t == null ? void 0 : t.moveOnTop) === !1, d = (y = t == null ? void 0 : t.mouse) == null ? void 0 : y.dragCursor, n = d !== void 0 ? d : "grab", h = (p = t == null ? void 0 : t.mouse) == null ? void 0 : p.mouseDownEventVerifier, c = h !== void 0 ? h : (S) => S.button === 0, a = (E = t == null ? void 0 : t.mouse) == null ? void 0 : E.mouseUpEventVerifier;
|
|
1511
|
+
return {
|
|
1512
|
+
freezePriority: s,
|
|
1513
|
+
dragCursor: n,
|
|
1514
|
+
mouseDownEventVerifier: c,
|
|
1515
|
+
mouseUpEventVerifier: a !== void 0 ? a : (S) => S.button === 0,
|
|
1516
|
+
onNodeDrag: e,
|
|
1517
|
+
onBeforeNodeDrag: o,
|
|
1518
|
+
onNodeDragFinished: r
|
|
1519
|
+
};
|
|
1520
|
+
}, U = (t, e, o) => {
|
|
1521
|
+
const { x: r, y: s, width: d, height: n } = t.getBoundingClientRect();
|
|
1522
|
+
return e >= r && e <= r + d && o >= s && o <= s + n;
|
|
1523
|
+
}, B = (t, e, o) => e >= 0 && e <= t.innerWidth && o >= 0 && o <= t.innerHeight, $ = (t, e) => {
|
|
1524
|
+
e !== null ? t.style.cursor = e : t.style.removeProperty("cursor");
|
|
1525
|
+
};
|
|
1526
|
+
class J {
|
|
1527
|
+
constructor(e, o, r) {
|
|
1528
|
+
i(this, "grabbedNodeId", null);
|
|
1529
|
+
i(this, "maxNodePriority", 0);
|
|
1530
|
+
i(this, "previousTouchCoordinates", null);
|
|
1531
|
+
i(this, "nodeIds", /* @__PURE__ */ new Map());
|
|
1532
|
+
i(this, "window", window);
|
|
1533
|
+
i(this, "graph");
|
|
1534
|
+
i(this, "onAfterNodeAdded", (e) => {
|
|
1535
|
+
this.updateMaxNodePriority(e);
|
|
1536
|
+
const o = this.graph.getNode(e);
|
|
1537
|
+
this.nodeIds.set(o.element, e), o.element.addEventListener("mousedown", this.onMouseDown), o.element.addEventListener("touchstart", this.onTouchStart);
|
|
1538
|
+
});
|
|
1539
|
+
i(this, "onAfterNodeUpdated", (e) => {
|
|
1540
|
+
this.updateMaxNodePriority(e);
|
|
1541
|
+
});
|
|
1542
|
+
i(this, "onBeforeNodeRemoved", (e) => {
|
|
1543
|
+
const o = this.graph.getNode(e);
|
|
1544
|
+
this.nodeIds.delete(o.element), o.element.removeEventListener("mousedown", this.onMouseDown), o.element.removeEventListener("touchstart", this.onTouchStart);
|
|
1545
|
+
});
|
|
1546
|
+
i(this, "onBeforeDestroy", () => {
|
|
1547
|
+
this.graph.onAfterNodeAdded.unsubscribe(this.onAfterNodeAdded), this.graph.onAfterNodeUpdated.unsubscribe(this.onAfterNodeUpdated), this.graph.onBeforeNodeRemoved.unsubscribe(this.onBeforeNodeRemoved), this.graph.onBeforeClear.unsubscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy), this.removeMouseDragListeners(), this.removeTouchDragListeners();
|
|
1548
|
+
});
|
|
1549
|
+
i(this, "onBeforeClear", () => {
|
|
1550
|
+
this.nodeIds.forEach((e, o) => {
|
|
1551
|
+
o.removeEventListener("mousedown", this.onMouseDown), o.removeEventListener("touchstart", this.onTouchStart);
|
|
1552
|
+
}), this.nodeIds.clear(), this.maxNodePriority = 0;
|
|
1553
|
+
});
|
|
1554
|
+
i(this, "onMouseDown", (e) => {
|
|
1555
|
+
if (!this.options.mouseDownEventVerifier(e))
|
|
1556
|
+
return;
|
|
1557
|
+
const o = e.currentTarget, r = this.nodeIds.get(o), s = this.graph.getNode(r);
|
|
1558
|
+
this.options.onBeforeNodeDrag({
|
|
1559
|
+
nodeId: r,
|
|
1560
|
+
element: s.element,
|
|
1561
|
+
x: s.x,
|
|
1562
|
+
y: s.y
|
|
1563
|
+
}) && (e.stopImmediatePropagation(), this.grabbedNodeId = r, $(this.element, this.options.dragCursor), this.moveNodeOnTop(r), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.window.addEventListener("mousemove", this.onWindowMouseMove));
|
|
1564
|
+
});
|
|
1565
|
+
i(this, "onTouchStart", (e) => {
|
|
1566
|
+
if (e.touches.length !== 1)
|
|
1567
|
+
return;
|
|
1568
|
+
e.stopImmediatePropagation(), this.previousTouchCoordinates = {
|
|
1569
|
+
x: e.touches[0].clientX,
|
|
1570
|
+
y: e.touches[0].clientY
|
|
1571
|
+
};
|
|
1572
|
+
const o = e.currentTarget, r = this.nodeIds.get(o), s = this.graph.getNode(r);
|
|
1573
|
+
this.options.onBeforeNodeDrag({
|
|
1574
|
+
nodeId: r,
|
|
1575
|
+
element: s.element,
|
|
1576
|
+
x: s.x,
|
|
1577
|
+
y: s.y
|
|
1578
|
+
}) && (this.grabbedNodeId = r, this.moveNodeOnTop(r), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish));
|
|
1579
|
+
});
|
|
1580
|
+
i(this, "onWindowMouseMove", (e) => {
|
|
1581
|
+
if (!U(this.element, e.clientX, e.clientY) || !B(this.window, e.clientX, e.clientY)) {
|
|
1582
|
+
this.cancelMouseDrag();
|
|
1583
|
+
return;
|
|
1584
|
+
}
|
|
1585
|
+
this.grabbedNodeId !== null && this.dragNode(this.grabbedNodeId, e.movementX, e.movementY);
|
|
1586
|
+
});
|
|
1587
|
+
i(this, "onWindowMouseUp", (e) => {
|
|
1588
|
+
this.options.mouseUpEventVerifier(e) && this.cancelMouseDrag();
|
|
1589
|
+
});
|
|
1590
|
+
i(this, "onWindowTouchMove", (e) => {
|
|
1591
|
+
if (e.touches.length !== 1)
|
|
1592
|
+
return;
|
|
1593
|
+
const o = e.touches[0];
|
|
1594
|
+
if (!U(this.element, o.clientX, o.clientY) || !B(this.window, o.clientX, o.clientY)) {
|
|
1595
|
+
this.cancelTouchDrag();
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
if (this.grabbedNodeId !== null && this.previousTouchCoordinates !== null) {
|
|
1599
|
+
const r = o.clientX - this.previousTouchCoordinates.x, s = o.clientY - this.previousTouchCoordinates.y;
|
|
1600
|
+
this.dragNode(this.grabbedNodeId, r, s), this.previousTouchCoordinates = {
|
|
1601
|
+
x: e.touches[0].clientX,
|
|
1602
|
+
y: e.touches[0].clientY
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
i(this, "onWindowTouchFinish", () => {
|
|
1607
|
+
this.previousTouchCoordinates = null, this.cancelTouchDrag();
|
|
1608
|
+
});
|
|
1609
|
+
i(this, "options");
|
|
1610
|
+
this.canvas = e, this.element = o, this.options = Ue(r), this.graph = e.graph, this.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.graph.onAfterNodeUpdated.subscribe(this.onAfterNodeUpdated), this.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.graph.onBeforeClear.subscribe(this.onBeforeClear), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
|
|
1812
1611
|
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
* canvas gets rolled back to initial state and can be reused
|
|
1816
|
-
*/
|
|
1817
|
-
clear() {
|
|
1818
|
-
return this.controller.clear(), this.nodeIdGenerator.reset(), this.portIdGenerator.reset(), this.edgeIdGenerator.reset(), this;
|
|
1612
|
+
static configure(e, o, r) {
|
|
1613
|
+
new J(e, o, r);
|
|
1819
1614
|
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
this.
|
|
1615
|
+
dragNode(e, o, r) {
|
|
1616
|
+
const s = this.graph.getNode(e);
|
|
1617
|
+
if (s === null)
|
|
1618
|
+
return;
|
|
1619
|
+
const d = this.canvas.viewport.getContentMatrix(), n = d.scale * s.x + d.x, h = d.scale * s.y + d.y, c = n + o, a = h + r, l = this.canvas.viewport.getViewportMatrix(), g = l.scale * c + l.x, f = l.scale * a + l.y;
|
|
1620
|
+
this.canvas.updateNode(e, { x: g, y: f }), this.options.onNodeDrag({
|
|
1621
|
+
nodeId: e,
|
|
1622
|
+
element: s.element,
|
|
1623
|
+
x: g,
|
|
1624
|
+
y: f
|
|
1625
|
+
});
|
|
1826
1626
|
}
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
i(this, "cycleEdges", /* @__PURE__ */ new Map());
|
|
1836
|
-
i(this, "afterNodeAddedEmitter");
|
|
1837
|
-
i(this, "onAfterNodeAdded");
|
|
1838
|
-
i(this, "afterNodeUpdatedEmitter");
|
|
1839
|
-
i(this, "onAfterNodeUpdated");
|
|
1840
|
-
i(this, "afterNodePriorityUpdatedEmitter");
|
|
1841
|
-
i(this, "onAfterNodePriorityUpdated");
|
|
1842
|
-
i(this, "beforeNodeRemovedEmitter");
|
|
1843
|
-
i(this, "onBeforeNodeRemoved");
|
|
1844
|
-
i(this, "afterPortAddedEmitter");
|
|
1845
|
-
i(this, "onAfterPortAdded");
|
|
1846
|
-
i(this, "afterPortUpdatedEmitter");
|
|
1847
|
-
i(this, "onAfterPortUpdated");
|
|
1848
|
-
i(this, "beforePortRemovedEmitter");
|
|
1849
|
-
i(this, "onBeforePortRemoved");
|
|
1850
|
-
i(this, "afterEdgeAddedEmitter");
|
|
1851
|
-
i(this, "onAfterEdgeAdded");
|
|
1852
|
-
i(this, "afterEdgeShapeUpdatedEmitter");
|
|
1853
|
-
i(this, "onAfterEdgeShapeUpdated");
|
|
1854
|
-
i(this, "afterEdgeUpdatedEmitter");
|
|
1855
|
-
i(this, "onAfterEdgeUpdated");
|
|
1856
|
-
i(this, "afterEdgePriorityUpdatedEmitter");
|
|
1857
|
-
i(this, "onAfterEdgePriorityUpdated");
|
|
1858
|
-
i(this, "beforeEdgeRemovedEmitter");
|
|
1859
|
-
i(this, "onBeforeEdgeRemoved");
|
|
1860
|
-
i(this, "beforeClearEmitter");
|
|
1861
|
-
i(this, "onBeforeClear");
|
|
1862
|
-
[this.afterNodeAddedEmitter, this.onAfterNodeAdded] = E(), [this.afterNodeUpdatedEmitter, this.onAfterNodeUpdated] = E(), [this.afterNodePriorityUpdatedEmitter, this.onAfterNodePriorityUpdated] = E(), [this.beforeNodeRemovedEmitter, this.onBeforeNodeRemoved] = E(), [this.afterPortAddedEmitter, this.onAfterPortAdded] = E(), [this.afterPortUpdatedEmitter, this.onAfterPortUpdated] = E(), [this.beforePortRemovedEmitter, this.onBeforePortRemoved] = E(), [this.afterEdgeAddedEmitter, this.onAfterEdgeAdded] = E(), [this.afterEdgeShapeUpdatedEmitter, this.onAfterEdgeShapeUpdated] = E(), [this.afterEdgeUpdatedEmitter, this.onAfterEdgeUpdated] = E(), [this.afterEdgePriorityUpdatedEmitter, this.onAfterEdgePriorityUpdated] = E(), [this.beforeEdgeRemovedEmitter, this.onBeforeEdgeRemoved] = E(), [this.beforeClearEmitter, this.onBeforeClear] = E();
|
|
1627
|
+
moveNodeOnTop(e) {
|
|
1628
|
+
if (this.options.freezePriority)
|
|
1629
|
+
return;
|
|
1630
|
+
this.maxNodePriority += 2, this.canvas.updateNode(e, { priority: this.maxNodePriority });
|
|
1631
|
+
const o = this.maxNodePriority - 1;
|
|
1632
|
+
this.graph.getNodeAdjacentEdgeIds(e).forEach((s) => {
|
|
1633
|
+
this.canvas.updateEdge(s, { priority: o });
|
|
1634
|
+
});
|
|
1863
1635
|
}
|
|
1864
|
-
|
|
1865
|
-
const
|
|
1636
|
+
cancelMouseDrag() {
|
|
1637
|
+
const e = this.graph.getNode(this.grabbedNodeId);
|
|
1638
|
+
e !== null && this.options.onNodeDragFinished({
|
|
1639
|
+
nodeId: this.grabbedNodeId,
|
|
1866
1640
|
element: e.element,
|
|
1867
1641
|
x: e.x,
|
|
1868
|
-
y: e.y
|
|
1869
|
-
|
|
1870
|
-
priority: e.priority,
|
|
1871
|
-
ports: o
|
|
1872
|
-
};
|
|
1873
|
-
this.nodes.set(e.id, r), this.afterNodeAddedEmitter.emit(e.id);
|
|
1874
|
-
}
|
|
1875
|
-
getAllNodeIds() {
|
|
1876
|
-
return Array.from(this.nodes.keys());
|
|
1877
|
-
}
|
|
1878
|
-
getNode(e) {
|
|
1879
|
-
return this.nodes.get(e);
|
|
1880
|
-
}
|
|
1881
|
-
updateNode(e, o) {
|
|
1882
|
-
const r = this.nodes.get(e);
|
|
1883
|
-
r.x = o.x ?? r.x, r.y = o.y ?? r.y, r.centerFn = o.centerFn ?? r.centerFn, o.priority !== void 0 && (r.priority = o.priority, this.afterNodePriorityUpdatedEmitter.emit(e)), this.afterNodeUpdatedEmitter.emit(e);
|
|
1642
|
+
y: e.y
|
|
1643
|
+
}), this.grabbedNodeId = null, $(this.element, null), this.removeMouseDragListeners();
|
|
1884
1644
|
}
|
|
1885
|
-
|
|
1886
|
-
this.
|
|
1645
|
+
removeMouseDragListeners() {
|
|
1646
|
+
this.window.removeEventListener("mouseup", this.onWindowMouseUp), this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
1887
1647
|
}
|
|
1888
|
-
|
|
1889
|
-
this.
|
|
1648
|
+
cancelTouchDrag() {
|
|
1649
|
+
this.previousTouchCoordinates = null;
|
|
1650
|
+
const e = this.graph.getNode(this.grabbedNodeId);
|
|
1651
|
+
e !== null && this.options.onNodeDragFinished({
|
|
1652
|
+
nodeId: this.grabbedNodeId,
|
|
1890
1653
|
element: e.element,
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
}), this.
|
|
1894
|
-
}
|
|
1895
|
-
getPort(e) {
|
|
1896
|
-
return this.ports.get(e);
|
|
1897
|
-
}
|
|
1898
|
-
updatePort(e, o) {
|
|
1899
|
-
const r = this.ports.get(e);
|
|
1900
|
-
r.direction = o.direction ?? r.direction, this.afterPortUpdatedEmitter.emit(e);
|
|
1901
|
-
}
|
|
1902
|
-
getAllPortIds() {
|
|
1903
|
-
return Array.from(this.ports.keys());
|
|
1654
|
+
x: e.x,
|
|
1655
|
+
y: e.y
|
|
1656
|
+
}), this.grabbedNodeId = null, this.removeTouchDragListeners();
|
|
1904
1657
|
}
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
if (o !== void 0)
|
|
1908
|
-
return Array.from(o.ports.keys());
|
|
1658
|
+
removeTouchDragListeners() {
|
|
1659
|
+
this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
|
|
1909
1660
|
}
|
|
1910
|
-
|
|
1911
|
-
const o = this.
|
|
1912
|
-
this.
|
|
1661
|
+
updateMaxNodePriority(e) {
|
|
1662
|
+
const o = this.graph.getNode(e).priority;
|
|
1663
|
+
this.maxNodePriority = Math.max(this.maxNodePriority, o);
|
|
1913
1664
|
}
|
|
1914
|
-
|
|
1915
|
-
|
|
1665
|
+
}
|
|
1666
|
+
const Be = (t) => {
|
|
1667
|
+
const e = t.minX !== null ? t.minX : -1 / 0, o = t.maxX !== null ? t.maxX : 1 / 0, r = t.minY !== null ? t.minY : -1 / 0, s = t.maxY !== null ? t.maxY : 1 / 0;
|
|
1668
|
+
return (d) => {
|
|
1669
|
+
let n = d.nextTransform.x, h = d.nextTransform.y;
|
|
1670
|
+
n < e && n < d.prevTransform.x && (n = Math.min(d.prevTransform.x, e));
|
|
1671
|
+
const c = d.canvasWidth * d.prevTransform.scale, a = o - c;
|
|
1672
|
+
n > a && n > d.prevTransform.x && (n = Math.max(d.prevTransform.x, a)), h < r && h < d.prevTransform.y && (h = Math.min(d.prevTransform.y, r));
|
|
1673
|
+
const l = d.canvasHeight * d.prevTransform.scale, g = s - l;
|
|
1674
|
+
return h > g && h > d.prevTransform.y && (h = Math.max(d.prevTransform.y, g)), { scale: d.nextTransform.scale, x: n, y: h };
|
|
1675
|
+
};
|
|
1676
|
+
}, $e = (t) => {
|
|
1677
|
+
const e = t.maxContentScale, o = t.minContentScale, r = e !== null ? 1 / e : 0, s = o !== null ? 1 / o : 1 / 0;
|
|
1678
|
+
return (d) => {
|
|
1679
|
+
const n = d.prevTransform, h = d.nextTransform;
|
|
1680
|
+
let c = h.scale, a = h.x, l = h.y;
|
|
1681
|
+
if (h.scale > s && h.scale > n.scale) {
|
|
1682
|
+
c = Math.max(n.scale, s), a = n.x, l = n.y;
|
|
1683
|
+
const g = (c - n.scale) / (h.scale - n.scale);
|
|
1684
|
+
a = n.x + (h.x - n.x) * g, l = n.y + (h.y - n.y) * g;
|
|
1685
|
+
}
|
|
1686
|
+
if (h.scale < r && h.scale < n.scale) {
|
|
1687
|
+
c = Math.min(n.scale, r), a = n.x, l = n.y;
|
|
1688
|
+
const g = (c - n.scale) / (h.scale - n.scale);
|
|
1689
|
+
a = n.x + (h.x - n.x) * g, l = n.y + (h.y - n.y) * g;
|
|
1690
|
+
}
|
|
1691
|
+
return {
|
|
1692
|
+
scale: c,
|
|
1693
|
+
x: a,
|
|
1694
|
+
y: l
|
|
1695
|
+
};
|
|
1696
|
+
};
|
|
1697
|
+
}, Ie = (t) => (e) => t.reduce(
|
|
1698
|
+
(o, r) => r({
|
|
1699
|
+
prevTransform: e.prevTransform,
|
|
1700
|
+
nextTransform: o,
|
|
1701
|
+
canvasWidth: e.canvasWidth,
|
|
1702
|
+
canvasHeight: e.canvasHeight
|
|
1703
|
+
}),
|
|
1704
|
+
e.nextTransform
|
|
1705
|
+
), re = (t) => {
|
|
1706
|
+
if (typeof t == "function")
|
|
1707
|
+
return t;
|
|
1708
|
+
switch (t.type) {
|
|
1709
|
+
case "scale-limit":
|
|
1710
|
+
return $e({
|
|
1711
|
+
minContentScale: t.minContentScale ?? 0,
|
|
1712
|
+
maxContentScale: t.maxContentScale ?? 1 / 0
|
|
1713
|
+
});
|
|
1714
|
+
case "shift-limit":
|
|
1715
|
+
return Be({
|
|
1716
|
+
minX: t.minX ?? -1 / 0,
|
|
1717
|
+
maxX: t.maxX ?? 1 / 0,
|
|
1718
|
+
minY: t.minY ?? -1 / 0,
|
|
1719
|
+
maxY: t.maxY ?? 1 / 0
|
|
1720
|
+
});
|
|
1916
1721
|
}
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1722
|
+
}, We = (t) => {
|
|
1723
|
+
var y, p, E, S, V, D, M, L, Z, _, q, O;
|
|
1724
|
+
const e = (y = t == null ? void 0 : t.scale) == null ? void 0 : y.mouseWheelSensitivity, o = e !== void 0 ? e : 1.2, r = t == null ? void 0 : t.transformPreprocessor;
|
|
1725
|
+
let s;
|
|
1726
|
+
r !== void 0 ? Array.isArray(r) ? s = Ie(
|
|
1727
|
+
r.map(
|
|
1728
|
+
(P) => re(P)
|
|
1729
|
+
)
|
|
1730
|
+
) : s = re(r) : s = (P) => P.nextTransform;
|
|
1731
|
+
const d = ((p = t == null ? void 0 : t.shift) == null ? void 0 : p.cursor) !== void 0 ? t.shift.cursor : "grab", n = ((E = t == null ? void 0 : t.events) == null ? void 0 : E.onBeforeTransformChange) ?? (() => {
|
|
1732
|
+
}), h = ((S = t == null ? void 0 : t.events) == null ? void 0 : S.onTransformChange) ?? (() => {
|
|
1733
|
+
}), c = (V = t == null ? void 0 : t.shift) == null ? void 0 : V.mouseDownEventVerifier, a = c !== void 0 ? c : (P) => P.button === 0, l = (D = t == null ? void 0 : t.shift) == null ? void 0 : D.mouseUpEventVerifier, g = l !== void 0 ? l : (P) => P.button === 0, f = (M = t == null ? void 0 : t.scale) == null ? void 0 : M.mouseWheelEventVerifier, v = f !== void 0 ? f : () => !0;
|
|
1734
|
+
return {
|
|
1735
|
+
wheelSensitivity: o,
|
|
1736
|
+
onTransformStarted: ((L = t == null ? void 0 : t.events) == null ? void 0 : L.onTransformStarted) ?? (() => {
|
|
1737
|
+
}),
|
|
1738
|
+
onTransformFinished: ((Z = t == null ? void 0 : t.events) == null ? void 0 : Z.onTransformFinished) ?? (() => {
|
|
1739
|
+
}),
|
|
1740
|
+
onBeforeTransformChange: n,
|
|
1741
|
+
onTransformChange: h,
|
|
1742
|
+
transformPreprocessor: s,
|
|
1743
|
+
shiftCursor: d,
|
|
1744
|
+
mouseDownEventVerifier: a,
|
|
1745
|
+
mouseUpEventVerifier: g,
|
|
1746
|
+
mouseWheelEventVerifier: v,
|
|
1747
|
+
scaleWheelFinishTimeout: ((_ = t == null ? void 0 : t.scale) == null ? void 0 : _.wheelFinishTimeout) ?? 500,
|
|
1748
|
+
onResizeTransformStarted: ((q = t == null ? void 0 : t.events) == null ? void 0 : q.onResizeTransformStarted) ?? (() => {
|
|
1749
|
+
}),
|
|
1750
|
+
onResizeTransformFinished: ((O = t == null ? void 0 : t.events) == null ? void 0 : O.onResizeTransformFinished) ?? (() => {
|
|
1751
|
+
})
|
|
1752
|
+
};
|
|
1753
|
+
}, Fe = (t, e, o) => ({
|
|
1754
|
+
scale: t.scale,
|
|
1755
|
+
x: t.x + t.scale * e,
|
|
1756
|
+
y: t.y + t.scale * o
|
|
1757
|
+
}), ze = (t, e, o, r) => ({
|
|
1758
|
+
scale: t.scale * e,
|
|
1759
|
+
x: t.scale * (1 - e) * o + t.x,
|
|
1760
|
+
y: t.scale * (1 - e) * r + t.y
|
|
1761
|
+
}), R = (t) => {
|
|
1762
|
+
const e = [], o = t.touches.length;
|
|
1763
|
+
for (let h = 0; h < o; h++)
|
|
1764
|
+
e.push([t.touches[h].clientX, t.touches[h].clientY]);
|
|
1765
|
+
const r = e.reduce(
|
|
1766
|
+
(h, c) => [h[0] + c[0], h[1] + c[1]],
|
|
1767
|
+
[0, 0]
|
|
1768
|
+
), s = [r[0] / o, r[1] / o], n = e.map((h) => [h[0] - s[0], h[1] - s[1]]).reduce(
|
|
1769
|
+
(h, c) => h + Math.sqrt(c[0] * c[0] + c[1] * c[1]),
|
|
1770
|
+
0
|
|
1771
|
+
);
|
|
1772
|
+
return {
|
|
1773
|
+
x: s[0],
|
|
1774
|
+
y: s[1],
|
|
1775
|
+
scale: n / o,
|
|
1776
|
+
touchesCnt: o,
|
|
1777
|
+
touches: e
|
|
1778
|
+
};
|
|
1779
|
+
};
|
|
1780
|
+
class Y {
|
|
1781
|
+
constructor(e, o, r) {
|
|
1782
|
+
i(this, "window", window);
|
|
1783
|
+
i(this, "viewport");
|
|
1784
|
+
i(this, "prevTouches", null);
|
|
1785
|
+
i(this, "wheelFinishTimer", null);
|
|
1786
|
+
i(this, "transformInProgress", !1);
|
|
1787
|
+
i(this, "onBeforeDestroy", () => {
|
|
1788
|
+
this.removeMouseDragListeners(), this.removeTouchDragListeners(), this.observer.unobserve(this.element), this.element.removeEventListener("mousedown", this.onMouseDown), this.element.removeEventListener("wheel", this.onWheelScroll), this.element.removeEventListener("touchstart", this.onTouchStart), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
|
|
1789
|
+
});
|
|
1790
|
+
i(this, "onMouseDown", (e) => {
|
|
1791
|
+
this.element === null || !this.options.mouseDownEventVerifier(e) || ($(this.element, this.options.shiftCursor), this.window.addEventListener("mousemove", this.onWindowMouseMove), this.window.addEventListener("mouseup", this.onWindowMouseUp), this.startRegisteredTransform());
|
|
1792
|
+
});
|
|
1793
|
+
i(this, "onWindowMouseMove", (e) => {
|
|
1794
|
+
if (this.element === null || !U(this.element, e.clientX, e.clientY) || !B(this.window, e.clientX, e.clientY)) {
|
|
1795
|
+
this.stopMouseDrag();
|
|
1796
|
+
return;
|
|
1797
|
+
}
|
|
1798
|
+
const o = -e.movementX, r = -e.movementY;
|
|
1799
|
+
this.moveViewport(o, r);
|
|
1800
|
+
});
|
|
1801
|
+
i(this, "onWindowMouseUp", (e) => {
|
|
1802
|
+
this.element === null || !this.options.mouseUpEventVerifier(e) || this.stopMouseDrag();
|
|
1803
|
+
});
|
|
1804
|
+
i(this, "onWheelScroll", (e) => {
|
|
1805
|
+
if (!this.options.mouseWheelEventVerifier(e))
|
|
1806
|
+
return;
|
|
1807
|
+
e.preventDefault();
|
|
1808
|
+
const { left: o, top: r } = this.element.getBoundingClientRect(), s = e.clientX - o, d = e.clientY - r, h = 1 / (e.deltaY < 0 ? this.options.wheelSensitivity : 1 / this.options.wheelSensitivity);
|
|
1809
|
+
this.wheelFinishTimer === null && this.options.onTransformStarted(), this.scaleViewport(h, s, d), this.wheelFinishTimer !== null && clearTimeout(this.wheelFinishTimer), this.wheelFinishTimer = setTimeout(() => {
|
|
1810
|
+
this.transformInProgress || this.options.onTransformFinished(), this.wheelFinishTimer = null;
|
|
1811
|
+
}, this.options.scaleWheelFinishTimeout);
|
|
1812
|
+
});
|
|
1813
|
+
i(this, "onTouchStart", (e) => {
|
|
1814
|
+
if (this.prevTouches !== null) {
|
|
1815
|
+
this.prevTouches = R(e);
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
this.prevTouches = R(e), this.window.addEventListener("touchmove", this.onWindowTouchMove), this.window.addEventListener("touchend", this.onWindowTouchFinish), this.window.addEventListener("touchcancel", this.onWindowTouchFinish), this.startRegisteredTransform();
|
|
1819
|
+
});
|
|
1820
|
+
i(this, "onWindowTouchMove", (e) => {
|
|
1821
|
+
const o = R(e);
|
|
1822
|
+
if (!o.touches.every(
|
|
1823
|
+
(s) => U(this.element, s[0], s[1]) && B(this.window, s[0], s[1])
|
|
1824
|
+
)) {
|
|
1825
|
+
this.stopTouchDrag();
|
|
1826
|
+
return;
|
|
1827
|
+
}
|
|
1828
|
+
if ((o.touchesCnt === 1 || o.touchesCnt === 2) && this.moveViewport(
|
|
1829
|
+
-(o.x - this.prevTouches.x),
|
|
1830
|
+
-(o.y - this.prevTouches.y)
|
|
1831
|
+
), o.touchesCnt === 2) {
|
|
1832
|
+
const { left: s, top: d } = this.element.getBoundingClientRect(), n = this.prevTouches.x - s, h = this.prevTouches.y - d, a = 1 / (o.scale / this.prevTouches.scale);
|
|
1833
|
+
this.scaleViewport(a, n, h);
|
|
1834
|
+
}
|
|
1835
|
+
this.prevTouches = o;
|
|
1836
|
+
});
|
|
1837
|
+
i(this, "onWindowTouchFinish", (e) => {
|
|
1838
|
+
e.touches.length > 0 ? this.prevTouches = R(e) : this.stopTouchDrag();
|
|
1839
|
+
});
|
|
1840
|
+
i(this, "observer", new ResizeObserver(() => {
|
|
1841
|
+
const e = this.viewport.getViewportMatrix(), { width: o, height: r } = this.element.getBoundingClientRect(), s = this.options.transformPreprocessor({
|
|
1842
|
+
prevTransform: e,
|
|
1843
|
+
nextTransform: e,
|
|
1844
|
+
canvasWidth: o,
|
|
1845
|
+
canvasHeight: r
|
|
1926
1846
|
});
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1847
|
+
this.options.onResizeTransformStarted(), this.canvas.patchViewportMatrix(s), this.options.onResizeTransformFinished();
|
|
1848
|
+
}));
|
|
1849
|
+
i(this, "options");
|
|
1850
|
+
this.canvas = e, this.element = o, this.options = We(r), this.viewport = e.viewport, this.observer.observe(this.element), this.element.addEventListener("mousedown", this.onMouseDown), this.element.addEventListener("wheel", this.onWheelScroll), this.element.addEventListener("touchstart", this.onTouchStart), e.onBeforeDestroy.subscribe(this.onBeforeDestroy);
|
|
1930
1851
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1852
|
+
static configure(e, o, r) {
|
|
1853
|
+
new Y(
|
|
1854
|
+
e,
|
|
1855
|
+
o,
|
|
1856
|
+
r
|
|
1857
|
+
);
|
|
1933
1858
|
}
|
|
1934
|
-
|
|
1935
|
-
|
|
1859
|
+
moveViewport(e, o) {
|
|
1860
|
+
const r = this.viewport.getViewportMatrix(), s = Fe(r, e, o), { width: d, height: n } = this.element.getBoundingClientRect(), h = this.options.transformPreprocessor({
|
|
1861
|
+
prevTransform: r,
|
|
1862
|
+
nextTransform: s,
|
|
1863
|
+
canvasWidth: d,
|
|
1864
|
+
canvasHeight: n
|
|
1865
|
+
});
|
|
1866
|
+
this.performTransform(h);
|
|
1936
1867
|
}
|
|
1937
|
-
|
|
1938
|
-
this.
|
|
1868
|
+
scaleViewport(e, o, r) {
|
|
1869
|
+
const s = this.canvas.viewport.getViewportMatrix(), d = ze(s, e, o, r), { width: n, height: h } = this.element.getBoundingClientRect(), c = this.options.transformPreprocessor({
|
|
1870
|
+
prevTransform: s,
|
|
1871
|
+
nextTransform: d,
|
|
1872
|
+
canvasWidth: n,
|
|
1873
|
+
canvasHeight: h
|
|
1874
|
+
});
|
|
1875
|
+
this.performTransform(c);
|
|
1939
1876
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1877
|
+
stopMouseDrag() {
|
|
1878
|
+
$(this.element, null), this.removeMouseDragListeners(), this.finishRegisteredTransform();
|
|
1942
1879
|
}
|
|
1943
|
-
|
|
1944
|
-
|
|
1880
|
+
removeMouseDragListeners() {
|
|
1881
|
+
this.window.removeEventListener("mousemove", this.onWindowMouseMove), this.window.removeEventListener("mouseup", this.onWindowMouseUp);
|
|
1945
1882
|
}
|
|
1946
|
-
|
|
1947
|
-
|
|
1883
|
+
stopTouchDrag() {
|
|
1884
|
+
this.prevTouches = null, this.removeTouchDragListeners(), this.finishRegisteredTransform();
|
|
1948
1885
|
}
|
|
1949
|
-
|
|
1950
|
-
|
|
1886
|
+
removeTouchDragListeners() {
|
|
1887
|
+
this.window.removeEventListener("touchmove", this.onWindowTouchMove), this.window.removeEventListener("touchend", this.onWindowTouchFinish), this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
|
|
1951
1888
|
}
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
...this.getPortIncomingEdgeIds(e),
|
|
1955
|
-
...this.getPortOutcomingEdgeIds(e),
|
|
1956
|
-
...this.getPortCycleEdgeIds(e)
|
|
1957
|
-
];
|
|
1889
|
+
performTransform(e) {
|
|
1890
|
+
this.options.onBeforeTransformChange(), this.canvas.patchViewportMatrix(e), this.options.onTransformChange();
|
|
1958
1891
|
}
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
let r = [];
|
|
1962
|
-
return o.forEach((s) => {
|
|
1963
|
-
r = [...r, ...this.getPortIncomingEdgeIds(s)];
|
|
1964
|
-
}), r;
|
|
1892
|
+
startRegisteredTransform() {
|
|
1893
|
+
this.transformInProgress = !0, this.options.onTransformStarted();
|
|
1965
1894
|
}
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
let r = [];
|
|
1969
|
-
return o.forEach((s) => {
|
|
1970
|
-
r = [...r, ...this.getPortOutcomingEdgeIds(s)];
|
|
1971
|
-
}), r;
|
|
1895
|
+
finishRegisteredTransform() {
|
|
1896
|
+
this.transformInProgress = !1, this.options.onTransformFinished();
|
|
1972
1897
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1898
|
+
}
|
|
1899
|
+
class K {
|
|
1900
|
+
constructor(e, o, r, s, d) {
|
|
1901
|
+
i(this, "canvasResizeObserver");
|
|
1902
|
+
i(this, "window", window);
|
|
1903
|
+
i(this, "nodeHorizontal");
|
|
1904
|
+
i(this, "nodeVertical");
|
|
1905
|
+
i(this, "viewport");
|
|
1906
|
+
i(this, "viewportWidth", 0);
|
|
1907
|
+
i(this, "viewportHeight", 0);
|
|
1908
|
+
i(this, "viewportMatrix");
|
|
1909
|
+
i(this, "loadedArea", {
|
|
1910
|
+
xFrom: 1 / 0,
|
|
1911
|
+
xTo: 1 / 0,
|
|
1912
|
+
yFrom: 1 / 0,
|
|
1913
|
+
yTo: 1 / 0
|
|
1914
|
+
});
|
|
1915
|
+
i(this, "updateLoadedArea", (e) => {
|
|
1916
|
+
this.loadedArea = {
|
|
1917
|
+
xFrom: e.x,
|
|
1918
|
+
xTo: e.x + e.width,
|
|
1919
|
+
yFrom: e.y,
|
|
1920
|
+
yTo: e.y + e.height
|
|
1921
|
+
};
|
|
1922
|
+
});
|
|
1923
|
+
i(this, "onBeforeDestroy", () => {
|
|
1924
|
+
this.trigger.unsubscribe(this.updateLoadedArea), this.canvasResizeObserver.unobserve(this.element), this.canvas.viewport.onAfterUpdated.unsubscribe(
|
|
1925
|
+
this.onAfterViewportUpdated
|
|
1926
|
+
), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
|
|
1927
|
+
});
|
|
1928
|
+
i(this, "onAfterViewportUpdated", () => {
|
|
1929
|
+
this.userTransformInProgress || (this.viewportMatrix = this.viewport.getViewportMatrix(), this.loadAreaAroundViewport());
|
|
1930
|
+
});
|
|
1931
|
+
i(this, "userTransformInProgress", !1);
|
|
1932
|
+
var f, v, y, p, E;
|
|
1933
|
+
this.canvas = e, this.element = o, this.trigger = s, this.virtualScrollOptions = d, this.nodeHorizontal = this.virtualScrollOptions.nodeContainingRadius.horizontal, this.nodeVertical = this.virtualScrollOptions.nodeContainingRadius.vertical, this.canvasResizeObserver = new this.window.ResizeObserver((S) => {
|
|
1934
|
+
const V = S[0];
|
|
1935
|
+
this.viewportWidth = V.contentRect.width, this.viewportHeight = V.contentRect.height, this.scheduleLoadAreaAroundViewport();
|
|
1936
|
+
}), this.viewport = e.viewport;
|
|
1937
|
+
const n = ((f = r == null ? void 0 : r.events) == null ? void 0 : f.onResizeTransformStarted) ?? (() => {
|
|
1938
|
+
}), h = ((v = r == null ? void 0 : r.events) == null ? void 0 : v.onResizeTransformFinished) ?? (() => {
|
|
1939
|
+
}), c = ((y = r == null ? void 0 : r.events) == null ? void 0 : y.onTransformChange) ?? (() => {
|
|
1940
|
+
}), a = ((p = r == null ? void 0 : r.events) == null ? void 0 : p.onBeforeTransformChange) ?? (() => {
|
|
1941
|
+
}), l = ((E = r == null ? void 0 : r.events) == null ? void 0 : E.onTransformFinished) ?? (() => {
|
|
1942
|
+
}), g = {
|
|
1943
|
+
...r,
|
|
1944
|
+
events: {
|
|
1945
|
+
...r == null ? void 0 : r.events,
|
|
1946
|
+
onResizeTransformStarted: () => {
|
|
1947
|
+
this.userTransformInProgress = !0, n();
|
|
1948
|
+
},
|
|
1949
|
+
onResizeTransformFinished: () => {
|
|
1950
|
+
this.userTransformInProgress = !1, h();
|
|
1951
|
+
},
|
|
1952
|
+
onBeforeTransformChange: () => {
|
|
1953
|
+
this.userTransformInProgress = !0, a();
|
|
1954
|
+
},
|
|
1955
|
+
onTransformChange: () => {
|
|
1956
|
+
this.userTransformInProgress = !1;
|
|
1957
|
+
const S = this.viewportMatrix;
|
|
1958
|
+
this.viewportMatrix = this.viewport.getViewportMatrix(), S.scale !== this.viewportMatrix.scale && this.scheduleEnsureViewportAreaLoaded(), c();
|
|
1959
|
+
},
|
|
1960
|
+
onTransformFinished: () => {
|
|
1961
|
+
this.scheduleLoadAreaAroundViewport(), l();
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
};
|
|
1965
|
+
Y.configure(
|
|
1966
|
+
e,
|
|
1967
|
+
this.element,
|
|
1968
|
+
g
|
|
1969
|
+
), this.viewportMatrix = this.viewport.getViewportMatrix(), this.trigger.subscribe(this.updateLoadedArea), this.canvasResizeObserver.observe(this.element), this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterViewportUpdated), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
|
|
1979
1970
|
}
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1971
|
+
static configure(e, o, r, s, d) {
|
|
1972
|
+
new K(
|
|
1973
|
+
e,
|
|
1974
|
+
o,
|
|
1975
|
+
r,
|
|
1976
|
+
s,
|
|
1977
|
+
d
|
|
1978
|
+
);
|
|
1986
1979
|
}
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
shape: e.shape,
|
|
1992
|
-
priority: e.priority
|
|
1993
|
-
}), e.from !== e.to ? (this.outcommingEdges.get(e.from).add(e.id), this.incommingEdges.get(e.to).add(e.id)) : this.cycleEdges.get(e.from).add(e.id);
|
|
1980
|
+
scheduleLoadAreaAroundViewport() {
|
|
1981
|
+
setTimeout(() => {
|
|
1982
|
+
this.loadAreaAroundViewport();
|
|
1983
|
+
});
|
|
1994
1984
|
}
|
|
1995
|
-
|
|
1996
|
-
const o = this.
|
|
1997
|
-
this.
|
|
1985
|
+
scheduleEnsureViewportAreaLoaded() {
|
|
1986
|
+
const e = this.viewportWidth * this.viewportMatrix.scale, o = this.viewportHeight * this.viewportMatrix.scale, r = this.viewportMatrix.x - this.nodeHorizontal, s = this.viewportMatrix.y - this.nodeVertical, d = this.viewportMatrix.x + e + this.nodeHorizontal, n = this.viewportMatrix.y + o + this.nodeVertical;
|
|
1987
|
+
this.loadedArea.xFrom < r && this.loadedArea.xTo > d && this.loadedArea.yFrom < s && this.loadedArea.yTo > n || this.scheduleLoadAreaAroundViewport();
|
|
1988
|
+
}
|
|
1989
|
+
loadAreaAroundViewport() {
|
|
1990
|
+
const e = this.viewportWidth * this.viewportMatrix.scale, o = this.viewportHeight * this.viewportMatrix.scale, r = this.viewportMatrix.x - e - this.nodeHorizontal, s = this.viewportMatrix.y - o - this.nodeVertical, d = 3 * e + 2 * this.nodeHorizontal, n = 3 * o + 2 * this.nodeVertical;
|
|
1991
|
+
this.trigger.emit({ x: r, y: s, width: d, height: n });
|
|
1998
1992
|
}
|
|
1999
1993
|
}
|
|
2000
|
-
const
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
1994
|
+
const Ye = () => {
|
|
1995
|
+
const t = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
1996
|
+
return t.style.position = "absolute", t.style.inset = "0", t;
|
|
1997
|
+
}, Xe = () => {
|
|
1998
|
+
const t = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
1999
|
+
return t.setAttribute("fill", "url(#pattern)"), t;
|
|
2000
|
+
}, He = () => {
|
|
2001
|
+
const t = document.createElementNS(
|
|
2002
|
+
"http://www.w3.org/2000/svg",
|
|
2003
|
+
"pattern"
|
|
2004
|
+
);
|
|
2005
|
+
return t.setAttribute("id", "pattern"), t;
|
|
2006
|
+
}, ke = (t, e) => {
|
|
2007
|
+
const o = document.createElementNS(
|
|
2008
|
+
"http://www.w3.org/2000/svg",
|
|
2009
|
+
"circle"
|
|
2010
|
+
);
|
|
2011
|
+
return o.setAttribute("cx", "0"), o.setAttribute("cy", "0"), o.setAttribute("r", `${t}`), o.setAttribute("fill", `${e}`), o;
|
|
2012
|
+
}, je = (t) => t instanceof SVGElement ? t : ke(
|
|
2013
|
+
(t == null ? void 0 : t.radius) ?? 1.5,
|
|
2014
|
+
(t == null ? void 0 : t.color) ?? "#d8d8d8"
|
|
2015
|
+
), Ge = (t) => {
|
|
2016
|
+
const e = t.tileDimensions, o = (e == null ? void 0 : e.width) ?? 25, r = (e == null ? void 0 : e.height) ?? 25, s = je(t.renderer ?? {});
|
|
2017
|
+
return {
|
|
2018
|
+
tileWidth: o,
|
|
2019
|
+
tileHeight: r,
|
|
2020
|
+
renderer: s,
|
|
2021
|
+
maxViewportScale: t.maxViewportScale ?? 10
|
|
2022
|
+
};
|
|
2008
2023
|
};
|
|
2009
|
-
class
|
|
2010
|
-
constructor() {
|
|
2011
|
-
i(this, "
|
|
2012
|
-
i(this, "
|
|
2013
|
-
i(this, "
|
|
2014
|
-
i(this, "
|
|
2015
|
-
i(this, "
|
|
2016
|
-
i(this, "
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
+
class Q {
|
|
2025
|
+
constructor(e, o, r) {
|
|
2026
|
+
i(this, "svg", Ye());
|
|
2027
|
+
i(this, "patternRenderingRectangle", Xe());
|
|
2028
|
+
i(this, "pattern", He());
|
|
2029
|
+
i(this, "patternContent");
|
|
2030
|
+
i(this, "tileWidth");
|
|
2031
|
+
i(this, "tileHeight");
|
|
2032
|
+
i(this, "halfTileWidth");
|
|
2033
|
+
i(this, "halfTileHeight");
|
|
2034
|
+
i(this, "maxViewportScale");
|
|
2035
|
+
i(this, "visible", !1);
|
|
2036
|
+
i(this, "resizeObserver", new ResizeObserver((e) => {
|
|
2037
|
+
const o = e[0], { width: r, height: s } = o.contentRect;
|
|
2038
|
+
this.svg.setAttribute("width", `${r}`), this.svg.setAttribute("height", `${s}`), this.patternRenderingRectangle.setAttribute("width", `${r}`), this.patternRenderingRectangle.setAttribute("height", `${s}`);
|
|
2039
|
+
const d = this.tileWidth / r, n = this.tileHeight / s;
|
|
2040
|
+
this.pattern.setAttribute("width", `${d}`), this.pattern.setAttribute("height", `${n}`);
|
|
2041
|
+
}));
|
|
2042
|
+
i(this, "onAfterTransformUpdated", () => {
|
|
2043
|
+
const e = this.canvas.viewport.getContentMatrix(), o = e.x - this.halfTileWidth * e.scale, r = e.y - this.halfTileHeight * e.scale, s = `matrix(${e.scale}, 0, 0, ${e.scale}, ${o}, ${r})`;
|
|
2044
|
+
this.pattern.setAttribute("patternTransform", s), this.updateVisibility();
|
|
2045
|
+
});
|
|
2046
|
+
i(this, "onBeforeDestroy", () => {
|
|
2047
|
+
this.resizeObserver.unobserve(this.host), this.host.removeChild(this.svg), this.canvas.viewport.onAfterUpdated.unsubscribe(
|
|
2048
|
+
this.onAfterTransformUpdated
|
|
2049
|
+
), this.canvas.onBeforeDestroy.unsubscribe(this.onBeforeDestroy);
|
|
2050
|
+
});
|
|
2051
|
+
this.canvas = e, this.host = r;
|
|
2052
|
+
const s = Ge(o);
|
|
2053
|
+
this.tileWidth = s.tileWidth, this.tileHeight = s.tileHeight, this.halfTileWidth = this.tileWidth / 2, this.halfTileHeight = this.tileHeight / 2, this.patternContent = s.renderer, this.maxViewportScale = s.maxViewportScale;
|
|
2054
|
+
const d = `translate(${this.halfTileWidth}, ${this.halfTileHeight})`;
|
|
2055
|
+
this.patternContent.setAttribute("transform", d), this.pattern.appendChild(this.patternContent);
|
|
2056
|
+
const n = document.createElementNS("http://www.w3.org/2000/svg", "defs");
|
|
2057
|
+
n.appendChild(this.pattern), this.svg.appendChild(n), this.svg.appendChild(this.patternRenderingRectangle), this.resizeObserver.observe(this.host), this.canvas.viewport.onAfterUpdated.subscribe(this.onAfterTransformUpdated), this.onAfterTransformUpdated(), this.canvas.onBeforeDestroy.subscribe(this.onBeforeDestroy);
|
|
2024
2058
|
}
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
scale: e.scale ?? this.viewportMatrix.scale,
|
|
2028
|
-
x: e.x ?? this.viewportMatrix.x,
|
|
2029
|
-
y: e.y ?? this.viewportMatrix.y
|
|
2030
|
-
}, this.contentMatrix = q(this.viewportMatrix), this.afterUpdateEmitter.emit();
|
|
2059
|
+
static configure(e, o, r) {
|
|
2060
|
+
new Q(e, o, r);
|
|
2031
2061
|
}
|
|
2032
|
-
|
|
2033
|
-
this.
|
|
2034
|
-
|
|
2035
|
-
x: e.x ?? this.contentMatrix.x,
|
|
2036
|
-
y: e.y ?? this.contentMatrix.y
|
|
2037
|
-
}, this.viewportMatrix = q(this.contentMatrix), this.afterUpdateEmitter.emit();
|
|
2062
|
+
updateVisibility() {
|
|
2063
|
+
const o = this.canvas.viewport.getViewportMatrix().scale > this.maxViewportScale;
|
|
2064
|
+
o && this.visible ? (this.visible = !1, this.host.removeChild(this.svg)) : !o && !this.visible && (this.visible = !0, this.host.appendChild(this.svg));
|
|
2038
2065
|
}
|
|
2039
2066
|
}
|
|
2040
|
-
|
|
2067
|
+
const Je = () => {
|
|
2068
|
+
const t = document.createElement("div");
|
|
2069
|
+
return t.style.width = "100%", t.style.height = "100%", t.style.position = "relative", t;
|
|
2070
|
+
}, ie = () => {
|
|
2071
|
+
const t = document.createElement("div");
|
|
2072
|
+
return t.style.position = "absolute", t.style.inset = "0", t;
|
|
2073
|
+
};
|
|
2074
|
+
class Ke {
|
|
2041
2075
|
constructor(e) {
|
|
2042
|
-
i(this, "
|
|
2043
|
-
i(this, "
|
|
2044
|
-
i(this, "
|
|
2045
|
-
|
|
2046
|
-
this.elementToNodeId.set(o.element, e), this.nodesResizeObserver.observe(o.element);
|
|
2047
|
-
});
|
|
2048
|
-
i(this, "onBeforeNodeRemoved", (e) => {
|
|
2049
|
-
const o = this.canvas.graph.getNode(e);
|
|
2050
|
-
this.elementToNodeId.delete(o.element), this.nodesResizeObserver.unobserve(o.element);
|
|
2051
|
-
});
|
|
2052
|
-
i(this, "onBeforeClear", () => {
|
|
2053
|
-
this.nodesResizeObserver.disconnect(), this.elementToNodeId.clear();
|
|
2054
|
-
});
|
|
2055
|
-
this.canvas = e, this.nodesResizeObserver = new ResizeObserver((o) => {
|
|
2056
|
-
o.forEach((r) => {
|
|
2057
|
-
const s = r.target;
|
|
2058
|
-
this.handleNodeResize(s);
|
|
2059
|
-
});
|
|
2060
|
-
}), this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded), this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved), this.canvas.graph.onBeforeClear.subscribe(this.onBeforeClear);
|
|
2061
|
-
}
|
|
2062
|
-
static configure(e) {
|
|
2063
|
-
new j(e);
|
|
2076
|
+
i(this, "background", ie());
|
|
2077
|
+
i(this, "main", ie());
|
|
2078
|
+
i(this, "host", Je());
|
|
2079
|
+
this.element = e, this.element.appendChild(this.host), this.host.appendChild(this.background), this.host.appendChild(this.main);
|
|
2064
2080
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
this.canvas.updateNode(o), this.canvas.graph.getNodeAdjacentEdgeIds(o).forEach((s) => {
|
|
2068
|
-
this.canvas.updateEdge(s);
|
|
2069
|
-
});
|
|
2081
|
+
destroy() {
|
|
2082
|
+
this.host.removeChild(this.main), this.host.removeChild(this.background), this.element.removeChild(this.host);
|
|
2070
2083
|
}
|
|
2071
2084
|
}
|
|
2072
|
-
class
|
|
2085
|
+
class Ze {
|
|
2073
2086
|
constructor() {
|
|
2074
2087
|
i(this, "element", null);
|
|
2075
2088
|
i(this, "canvasDefaults", {});
|
|
2076
|
-
i(this, "dragOptions");
|
|
2077
|
-
i(this, "transformOptions");
|
|
2089
|
+
i(this, "dragOptions", {});
|
|
2090
|
+
i(this, "transformOptions", {});
|
|
2091
|
+
i(this, "backgroundOptions", {});
|
|
2078
2092
|
i(this, "virtualScrollOptions");
|
|
2079
2093
|
i(this, "hasDraggableNode", !1);
|
|
2080
2094
|
i(this, "hasTransformableViewport", !1);
|
|
2081
2095
|
i(this, "hasResizeReactiveNodes", !1);
|
|
2096
|
+
i(this, "hasBackground", !1);
|
|
2082
2097
|
i(this, "boxRenderingTrigger");
|
|
2083
2098
|
}
|
|
2084
2099
|
setElement(e) {
|
|
@@ -2094,13 +2109,13 @@ class Ye {
|
|
|
2094
2109
|
* enables nodes draggable by user
|
|
2095
2110
|
*/
|
|
2096
2111
|
enableUserDraggableNodes(e) {
|
|
2097
|
-
return this.hasDraggableNode = !0, this.dragOptions = e, this;
|
|
2112
|
+
return this.hasDraggableNode = !0, this.dragOptions = e ?? {}, this;
|
|
2098
2113
|
}
|
|
2099
2114
|
/**
|
|
2100
2115
|
* enables viewport transformable by user
|
|
2101
2116
|
*/
|
|
2102
2117
|
enableUserTransformableViewport(e) {
|
|
2103
|
-
return this.hasTransformableViewport = !0, this.transformOptions = e, this;
|
|
2118
|
+
return this.hasTransformableViewport = !0, this.transformOptions = e ?? {}, this;
|
|
2104
2119
|
}
|
|
2105
2120
|
/**
|
|
2106
2121
|
* enables automatic edges update on node resize
|
|
@@ -2117,56 +2132,69 @@ class Ye {
|
|
|
2117
2132
|
enableVirtualScroll(e) {
|
|
2118
2133
|
return this.virtualScrollOptions = e, this;
|
|
2119
2134
|
}
|
|
2135
|
+
enableBackground(e) {
|
|
2136
|
+
return this.hasBackground = !0, this.backgroundOptions = e ?? {}, this;
|
|
2137
|
+
}
|
|
2120
2138
|
/**
|
|
2121
2139
|
* builds final canvas
|
|
2122
2140
|
*/
|
|
2123
2141
|
build() {
|
|
2124
2142
|
if (this.element === null)
|
|
2125
|
-
throw new
|
|
2143
|
+
throw new b(
|
|
2126
2144
|
"unable to build canvas when no attach element specified"
|
|
2127
2145
|
);
|
|
2128
2146
|
let e = this.boxRenderingTrigger;
|
|
2129
|
-
this.virtualScrollOptions !== void 0 && e === void 0 && (e = new
|
|
2130
|
-
const o = new
|
|
2131
|
-
let
|
|
2147
|
+
this.virtualScrollOptions !== void 0 && e === void 0 && (e = new se());
|
|
2148
|
+
const o = new Ce(), r = new Re(), s = new Ke(this.element);
|
|
2149
|
+
let d = new le(
|
|
2132
2150
|
o,
|
|
2133
2151
|
r,
|
|
2134
|
-
|
|
2152
|
+
s.main
|
|
2135
2153
|
);
|
|
2136
|
-
e !== void 0 && (
|
|
2137
|
-
|
|
2154
|
+
e !== void 0 && (d = new ue(d, o, e));
|
|
2155
|
+
const n = new Le(
|
|
2156
|
+
this.element,
|
|
2138
2157
|
o,
|
|
2139
2158
|
r,
|
|
2140
|
-
s
|
|
2141
|
-
);
|
|
2142
|
-
this.hasDraggableNode && (d = new de(
|
|
2143
2159
|
d,
|
|
2144
|
-
this.
|
|
2160
|
+
this.canvasDefaults
|
|
2161
|
+
), h = () => {
|
|
2162
|
+
s.destroy(), n.onBeforeDestroy.unsubscribe(h);
|
|
2163
|
+
};
|
|
2164
|
+
return n.onBeforeDestroy.subscribe(h), this.hasBackground && Q.configure(
|
|
2165
|
+
n,
|
|
2166
|
+
this.backgroundOptions,
|
|
2167
|
+
s.background
|
|
2168
|
+
), this.hasResizeReactiveNodes && G.configure(n), this.hasDraggableNode && J.configure(
|
|
2169
|
+
n,
|
|
2170
|
+
s.main,
|
|
2145
2171
|
this.dragOptions
|
|
2146
|
-
)
|
|
2147
|
-
|
|
2148
|
-
|
|
2172
|
+
), this.virtualScrollOptions !== void 0 ? K.configure(
|
|
2173
|
+
n,
|
|
2174
|
+
s.main,
|
|
2149
2175
|
this.transformOptions,
|
|
2150
|
-
|
|
2151
|
-
this.
|
|
2152
|
-
) : this.hasTransformableViewport && (
|
|
2153
|
-
|
|
2154
|
-
|
|
2176
|
+
e,
|
|
2177
|
+
this.virtualScrollOptions
|
|
2178
|
+
) : this.hasTransformableViewport && Y.configure(
|
|
2179
|
+
n,
|
|
2180
|
+
s.main,
|
|
2155
2181
|
this.transformOptions
|
|
2156
|
-
));
|
|
2157
|
-
const n = new We(this.element, d, this.canvasDefaults);
|
|
2158
|
-
return this.hasResizeReactiveNodes && j.configure(n), this.reset(), n;
|
|
2182
|
+
), this.reset(), n;
|
|
2159
2183
|
}
|
|
2184
|
+
/**
|
|
2185
|
+
* @deprecated
|
|
2186
|
+
* CanvasBuilder should be single use object
|
|
2187
|
+
*/
|
|
2160
2188
|
reset() {
|
|
2161
|
-
this.element = null, this.canvasDefaults = {}, this.dragOptions =
|
|
2189
|
+
this.element = null, this.canvasDefaults = {}, this.dragOptions = {}, this.transformOptions = {}, this.backgroundOptions = {}, this.virtualScrollOptions = void 0, this.hasDraggableNode = !1, this.hasTransformableViewport = !1, this.hasResizeReactiveNodes = !1, this.hasBackground = !1, this.boxRenderingTrigger = void 0;
|
|
2162
2190
|
}
|
|
2163
2191
|
}
|
|
2164
2192
|
export {
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2193
|
+
me as BezierEdgeShape,
|
|
2194
|
+
Ze as CanvasBuilder,
|
|
2195
|
+
se as EventSubject,
|
|
2196
|
+
Ne as HorizontalEdgeShape,
|
|
2197
|
+
b as HtmlGraphError,
|
|
2198
|
+
Pe as StraightEdgeShape,
|
|
2199
|
+
Ve as VerticalEdgeShape
|
|
2172
2200
|
};
|