@ankhzet/graph 0.1.0 → 0.3.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/CHANGELOG.md +20 -0
- package/dist/index.d.ts +676 -0
- package/dist/index.js +2283 -0
- package/dist/index.js.map +1 -0
- package/package.json +6 -6
- package/src/{CircuitGroups.tsx → GraphGroups.tsx} +5 -5
- package/src/LoadNodes.ts +5 -5
- package/src/{CircuitGraph.tsx → ManagedGraph.tsx} +22 -23
- package/src/{CircuitNode.ts → ManagedGraphNode.ts} +3 -3
- package/src/createGraphHandlers.ts +2 -2
- package/src/index.ts +3 -1
- package/src/useNodeSelection.ts +2 -2
- package/src/useNodes.tsx +4 -4
- package/src/utils.ts +3 -5
package/dist/index.js
ADDED
|
@@ -0,0 +1,2283 @@
|
|
|
1
|
+
import { DisposableEventSource as e } from "@ankhzet/gcl";
|
|
2
|
+
import { debounce as t, isLike as n, matchId as r } from "@ankhzet/utils";
|
|
3
|
+
import { forwardRef as i, useEffect as a, useImperativeHandle as o, useLayoutEffect as s, useMemo as c, useRef as l, useState as u } from "react";
|
|
4
|
+
import { Styles as d, handleAsNoop as f, useDrag as p, useIsomorphicLayoutEffect as m, useLastCallback as h, useMeasure as g, usePrevious as _, useSyncStore as v } from "@ankhzet/ui";
|
|
5
|
+
import { observer as y } from "mobx-react-lite";
|
|
6
|
+
import { jsx as b, jsxs as x } from "react/jsx-runtime";
|
|
7
|
+
import { reaction as S } from "mobx";
|
|
8
|
+
//#region \0rolldown/runtime.js
|
|
9
|
+
var C = Object.defineProperty, w = Object.getOwnPropertyDescriptor, ee = Object.getOwnPropertyNames, te = Object.prototype.hasOwnProperty, ne = (e, t) => {
|
|
10
|
+
let n = {};
|
|
11
|
+
for (var r in e) C(n, r, {
|
|
12
|
+
get: e[r],
|
|
13
|
+
enumerable: !0
|
|
14
|
+
});
|
|
15
|
+
return t || C(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
16
|
+
}, re = (e, t, n, r) => {
|
|
17
|
+
if (t && typeof t == "object" || typeof t == "function") for (var i = ee(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !te.call(e, s) && s !== n && C(e, s, {
|
|
18
|
+
get: ((e) => t[e]).bind(null, s),
|
|
19
|
+
enumerable: !(r = w(t, s)) || r.enumerable
|
|
20
|
+
});
|
|
21
|
+
return e;
|
|
22
|
+
}, T = (e, t, n) => (re(e, t, "default"), n && re(n, t, "default")), E = (e, t, n = 1) => ({
|
|
23
|
+
x: ~~(e.x + t.x * n),
|
|
24
|
+
y: ~~(e.y + t.y * n)
|
|
25
|
+
}), D = (e, t) => (n) => n.node === e && n.port === t, ie = (e) => (t) => t.node === e, O = (e, t, n) => {
|
|
26
|
+
if (n) for (let r of n) {
|
|
27
|
+
let n = t.nodes.findIndex(D(r.node, r.port));
|
|
28
|
+
n >= 0 !== e && (e ? t.nodes.push(r) : t.nodes.splice(n, 1));
|
|
29
|
+
}
|
|
30
|
+
else e || (t.nodes = []);
|
|
31
|
+
}, ae = (e, t, n, r, i, a, o, s) => {
|
|
32
|
+
if (e === n && t === r || i === o && a === s) return !1;
|
|
33
|
+
let c = (s - a) * (n - e) - (o - i) * (r - t);
|
|
34
|
+
if (c === 0) return !1;
|
|
35
|
+
let l = ((o - i) * (t - a) - (s - a) * (e - i)) / c, u = ((n - e) * (t - a) - (r - t) * (e - i)) / c;
|
|
36
|
+
return l < 0 || l > 1 || u < 0 || u > 1 ? !1 : {
|
|
37
|
+
x: e + l * (n - e),
|
|
38
|
+
y: t + l * (r - t)
|
|
39
|
+
};
|
|
40
|
+
}, k = class {
|
|
41
|
+
joints = /* @__PURE__ */ new Map();
|
|
42
|
+
parentId;
|
|
43
|
+
constructor(e, t) {
|
|
44
|
+
this.parentId = e;
|
|
45
|
+
for (let e of t) this.joints.set(e.port, e);
|
|
46
|
+
}
|
|
47
|
+
[Symbol.iterator]() {
|
|
48
|
+
return this.joints.values();
|
|
49
|
+
}
|
|
50
|
+
get connected() {
|
|
51
|
+
let e = [];
|
|
52
|
+
for (let t of this.joints.values()) t.nodes.length && e.push(t);
|
|
53
|
+
return e;
|
|
54
|
+
}
|
|
55
|
+
find(e) {
|
|
56
|
+
for (let t of this.joints.values()) if (e(t)) return t;
|
|
57
|
+
}
|
|
58
|
+
map(e) {
|
|
59
|
+
let t = Array(this.joints.size), n = 0;
|
|
60
|
+
for (let r of this.joints.values()) t[n] = e(r, n), n++;
|
|
61
|
+
return t;
|
|
62
|
+
}
|
|
63
|
+
has(e, t) {
|
|
64
|
+
return !!this.getPort(e, t);
|
|
65
|
+
}
|
|
66
|
+
hasAtPort(e, t, n) {
|
|
67
|
+
return !!this.joints.get(e)?.nodes.some(D(t, n));
|
|
68
|
+
}
|
|
69
|
+
getPort(e, t) {
|
|
70
|
+
let n = this.find(t === void 0 ? (t) => t.nodes.some(ie(e)) : (n) => n.nodes.some(D(e, t)));
|
|
71
|
+
if (n) return n.port;
|
|
72
|
+
}
|
|
73
|
+
connect({ port: e, target: t, connect: n }) {
|
|
74
|
+
let r = this.joints.get(e);
|
|
75
|
+
if (!r) throw Error(`Node ${this.parentId} does not have joint "${e}"`);
|
|
76
|
+
return O(n, r, t), r;
|
|
77
|
+
}
|
|
78
|
+
getNodes(e) {
|
|
79
|
+
return this.joints.get(e)?.nodes;
|
|
80
|
+
}
|
|
81
|
+
get ids() {
|
|
82
|
+
let e = /* @__PURE__ */ new Set();
|
|
83
|
+
for (let { nodes: t } of this.joints.values()) for (let { node: n } of t) e.add(n);
|
|
84
|
+
return [...e];
|
|
85
|
+
}
|
|
86
|
+
get count() {
|
|
87
|
+
return this.joints.size;
|
|
88
|
+
}
|
|
89
|
+
}, oe = Symbol("E_CONNECT"), se = Symbol("E_MOVE"), ce = class extends e {
|
|
90
|
+
id;
|
|
91
|
+
description;
|
|
92
|
+
inputs;
|
|
93
|
+
outputs;
|
|
94
|
+
coordinator;
|
|
95
|
+
#e = {
|
|
96
|
+
x: 0,
|
|
97
|
+
y: 0
|
|
98
|
+
};
|
|
99
|
+
constructor({ id: e, coordinator: t, inputs: n = [], outputs: r = [], ...i }) {
|
|
100
|
+
super(), this.id = e, this.coordinator = t, this.description = i, this.inputs = new k(e, n), this.outputs = new k(e, r);
|
|
101
|
+
}
|
|
102
|
+
get title() {
|
|
103
|
+
return this.description.title;
|
|
104
|
+
}
|
|
105
|
+
get width() {
|
|
106
|
+
return this.coordinator.sizes.lane * 2 + this.coordinator.sizes.space;
|
|
107
|
+
}
|
|
108
|
+
get height() {
|
|
109
|
+
return this.coordinator.sizes.lane * Math.max(1, this.inputs.count, this.outputs.count);
|
|
110
|
+
}
|
|
111
|
+
get position() {
|
|
112
|
+
return this.#e;
|
|
113
|
+
}
|
|
114
|
+
set position({ x: e, y: t }) {
|
|
115
|
+
e = this.coordinator.snap(e), t = this.coordinator.snap(t), !(this.#e.x === e && this.#e.y === t) && (this.#e.x = e, this.#e.y = t, this.dispatchEvent(se, this.#e));
|
|
116
|
+
}
|
|
117
|
+
isInput(e, t, n) {
|
|
118
|
+
return this.inputs.hasAtPort(e, t, n);
|
|
119
|
+
}
|
|
120
|
+
isOutput(e, t, n) {
|
|
121
|
+
return this.outputs.hasAtPort(e, t, n);
|
|
122
|
+
}
|
|
123
|
+
isConnected(e, t, n) {
|
|
124
|
+
return t ? this.inputs.hasAtPort(e, n.node, n.port) : this.outputs.hasAtPort(e, n.node, n.port);
|
|
125
|
+
}
|
|
126
|
+
getNodes(e, t) {
|
|
127
|
+
return t ? this.inputs.getNodes(e) : this.outputs.getNodes(e);
|
|
128
|
+
}
|
|
129
|
+
connect({ input: e, connect: t, port: n, nodes: r }) {
|
|
130
|
+
let i = {
|
|
131
|
+
node: this.id,
|
|
132
|
+
port: n
|
|
133
|
+
}, a = r ? r.map(({ node: e, port: t }) => ({
|
|
134
|
+
node: e.id,
|
|
135
|
+
port: t
|
|
136
|
+
})) : this.getNodes(n, e);
|
|
137
|
+
if (e ? this.inputs.connect({
|
|
138
|
+
connect: t,
|
|
139
|
+
port: n,
|
|
140
|
+
target: a
|
|
141
|
+
}) : this.outputs.connect({
|
|
142
|
+
connect: t,
|
|
143
|
+
port: n,
|
|
144
|
+
target: a
|
|
145
|
+
}), r) {
|
|
146
|
+
let a = [{
|
|
147
|
+
node: this,
|
|
148
|
+
port: n
|
|
149
|
+
}];
|
|
150
|
+
for (let { node: n, port: o } of r) t !== n.isConnected(o, !e, i) && n.connect({
|
|
151
|
+
connect: t,
|
|
152
|
+
input: !e,
|
|
153
|
+
port: o,
|
|
154
|
+
nodes: a
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
this.dispatchEvent(oe, {
|
|
158
|
+
connect: t,
|
|
159
|
+
input: e,
|
|
160
|
+
source: i,
|
|
161
|
+
target: a
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
move(e) {
|
|
165
|
+
return this.position = e, this.position;
|
|
166
|
+
}
|
|
167
|
+
onConnect(e) {
|
|
168
|
+
return this.handleEvent(oe, e);
|
|
169
|
+
}
|
|
170
|
+
onMove(e) {
|
|
171
|
+
return this.handleEvent(se, e);
|
|
172
|
+
}
|
|
173
|
+
}, A = class {
|
|
174
|
+
_barriers = {};
|
|
175
|
+
_isBarrier;
|
|
176
|
+
map;
|
|
177
|
+
nodes;
|
|
178
|
+
constructor(e, t) {
|
|
179
|
+
this.nodes = e, this.map = Object.fromEntries(e.map((e) => [e.id, e])), this._isBarrier = t;
|
|
180
|
+
}
|
|
181
|
+
isBarrier(e) {
|
|
182
|
+
let t = this._barriers[e];
|
|
183
|
+
return t === void 0 ? this._barriers[e] = this._isBarrier(this.map[e]) : t;
|
|
184
|
+
}
|
|
185
|
+
getSubGraphs(e) {
|
|
186
|
+
let t = [...e || Object.keys(this.map)], n = [], r;
|
|
187
|
+
for (; r = t.pop();) {
|
|
188
|
+
if (this.isBarrier(r)) continue;
|
|
189
|
+
let i = this.map[r], a = i && this.getConnectedNodes(i, e);
|
|
190
|
+
if (a) {
|
|
191
|
+
for (let e of a) {
|
|
192
|
+
let n = t.indexOf(e);
|
|
193
|
+
n >= 0 && t.splice(n, 1);
|
|
194
|
+
}
|
|
195
|
+
n.push(a);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return n;
|
|
199
|
+
}
|
|
200
|
+
inputs(e) {
|
|
201
|
+
return this.map[e].inputs.ids;
|
|
202
|
+
}
|
|
203
|
+
outputs(e) {
|
|
204
|
+
return this.map[e].outputs.ids;
|
|
205
|
+
}
|
|
206
|
+
getConnectedNodes(e, t, n = [e.id]) {
|
|
207
|
+
for (let r of [e.inputs.ids, e.outputs.ids]) for (let e of r) {
|
|
208
|
+
if (n.includes(e) || t && !t.includes(e)) continue;
|
|
209
|
+
let r = this.map[e];
|
|
210
|
+
r && (n.push(e), this.isBarrier(e) || this.getConnectedNodes(r, t, n));
|
|
211
|
+
}
|
|
212
|
+
return n;
|
|
213
|
+
}
|
|
214
|
+
getCenter(e) {
|
|
215
|
+
let t = this.nodes.map(e).filter(n);
|
|
216
|
+
if (!t.length) return {
|
|
217
|
+
x: 0,
|
|
218
|
+
y: 0
|
|
219
|
+
};
|
|
220
|
+
let r = {
|
|
221
|
+
x: Infinity,
|
|
222
|
+
y: Infinity
|
|
223
|
+
}, i = {
|
|
224
|
+
x: -Infinity,
|
|
225
|
+
y: -Infinity
|
|
226
|
+
};
|
|
227
|
+
for (let { x: e, y: n } of t) e < r.x && (r.x = e), e > i.x && (i.x = e), n < r.y && (r.y = n), n > i.y && (i.y = n);
|
|
228
|
+
for (let e of t) e.x -= r.x, e.y -= r.y;
|
|
229
|
+
return {
|
|
230
|
+
x: (i.x - r.x) / 2,
|
|
231
|
+
y: (i.y - r.y) / 2
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}, le = class extends A {
|
|
235
|
+
layers = [];
|
|
236
|
+
hash = null;
|
|
237
|
+
get center() {
|
|
238
|
+
return this.hash ||= this.getCenter((e) => e.position), this.hash;
|
|
239
|
+
}
|
|
240
|
+
spread(e, t) {
|
|
241
|
+
let n = [], r = 0;
|
|
242
|
+
for (let i of t) {
|
|
243
|
+
let t = this.map[i], a = this.shift(t, this.findLayer(t), e, n);
|
|
244
|
+
r = Math.max(r, a);
|
|
245
|
+
}
|
|
246
|
+
return r;
|
|
247
|
+
}
|
|
248
|
+
findMax(e) {
|
|
249
|
+
let t = this.findLayers(this.get(e.inputs.ids)), n = 0;
|
|
250
|
+
for (let e of Object.values(t)) {
|
|
251
|
+
let t = +e;
|
|
252
|
+
t > n && (n = t);
|
|
253
|
+
}
|
|
254
|
+
return n || 0;
|
|
255
|
+
}
|
|
256
|
+
dependants({ id: e }) {
|
|
257
|
+
let t = [];
|
|
258
|
+
for (let n of this.nodes) n.id !== e && n.inputs.has(e) && t.push(n);
|
|
259
|
+
return t;
|
|
260
|
+
}
|
|
261
|
+
get(e) {
|
|
262
|
+
return e.map((e) => this.map[e]).filter(n);
|
|
263
|
+
}
|
|
264
|
+
remove(e, t) {
|
|
265
|
+
return this.layers[t] ? delete this.layers[t][e.id] : !1;
|
|
266
|
+
}
|
|
267
|
+
put(e, t) {
|
|
268
|
+
let n = this.layers[t] || (this.layers[t] = {});
|
|
269
|
+
n[e.id] = e;
|
|
270
|
+
}
|
|
271
|
+
findLayer(e) {
|
|
272
|
+
for (let [t, n] of Object.entries(this.layers)) if (n[e.id]) return +t;
|
|
273
|
+
return 0;
|
|
274
|
+
}
|
|
275
|
+
findLayers(e) {
|
|
276
|
+
let t = {};
|
|
277
|
+
for (let n in this.layers) {
|
|
278
|
+
let r = this.layers[n], i = [];
|
|
279
|
+
for (let a of e) r[a.id] && (t[a.id] = +n, i.push(a));
|
|
280
|
+
e = e.filter((e) => i.indexOf(e) < 0);
|
|
281
|
+
}
|
|
282
|
+
return t;
|
|
283
|
+
}
|
|
284
|
+
shift(e, t, n, r = []) {
|
|
285
|
+
if (r.includes(e)) return 0;
|
|
286
|
+
r.push(e);
|
|
287
|
+
let i = t + n, a = this.dependants(e), o = i, s = i;
|
|
288
|
+
t && this.remove(e, t), this.put(e, i);
|
|
289
|
+
for (let e of a) {
|
|
290
|
+
let t = this.findLayer(e), n = i - t + 1;
|
|
291
|
+
s = Math.min(s, t + n), o = Math.max(o, t + n), t && n > 0 && this.shift(e, t, n, r);
|
|
292
|
+
}
|
|
293
|
+
return o - s + 1;
|
|
294
|
+
}
|
|
295
|
+
all(e) {
|
|
296
|
+
let t = e.concat([]);
|
|
297
|
+
return this.walk(e, (e) => {
|
|
298
|
+
t.push(e), t.concat(this.all(this.get(e.inputs.ids)));
|
|
299
|
+
}), t;
|
|
300
|
+
}
|
|
301
|
+
walk(e, t) {
|
|
302
|
+
for (let n of e) for (let e of n.inputs.ids) {
|
|
303
|
+
let n = this.map[e];
|
|
304
|
+
if (n && !1 === t(n)) break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}, ue = class extends A {
|
|
308
|
+
cache = {};
|
|
309
|
+
hash = null;
|
|
310
|
+
get center() {
|
|
311
|
+
return this.hash ||= this.getCenter((e) => e.position), this.hash;
|
|
312
|
+
}
|
|
313
|
+
splice(e, t, n, r = []) {
|
|
314
|
+
for (let i of e) r.includes(i) || (n(i, t), this.isBarrier(i) || (this.splice(this.inputs(i), t - 1, n, r), this.splice(this.outputs(i), t + 1, n, r)));
|
|
315
|
+
}
|
|
316
|
+
align(e, t) {
|
|
317
|
+
let n = e - t.length;
|
|
318
|
+
if (n <= 0) return t.map((e, t) => [e, t]);
|
|
319
|
+
let r = [], i = ~~(n / 2);
|
|
320
|
+
for (let e of t) r.push([e, i++]);
|
|
321
|
+
return r;
|
|
322
|
+
}
|
|
323
|
+
spread(e, t) {
|
|
324
|
+
let n = [], r = [];
|
|
325
|
+
this.splice(t, t.length, (e, t) => {
|
|
326
|
+
let i = n[t];
|
|
327
|
+
i ? i.push(e) : n[t] = [e], r.push(e);
|
|
328
|
+
}, r);
|
|
329
|
+
let i = [], a = 1, o = 0;
|
|
330
|
+
for (let e of n) e && (a = Math.max(a, e.length), i.push(e));
|
|
331
|
+
for (let t of i) {
|
|
332
|
+
for (let [n, r] of this.align(a, t)) this.cache[n] = {
|
|
333
|
+
x: o,
|
|
334
|
+
y: e + r
|
|
335
|
+
};
|
|
336
|
+
o++;
|
|
337
|
+
}
|
|
338
|
+
return this.hash = null, a;
|
|
339
|
+
}
|
|
340
|
+
}, de = class {
|
|
341
|
+
sort(e) {
|
|
342
|
+
let t = {}, n = {}, r = [];
|
|
343
|
+
for (let i of e) {
|
|
344
|
+
let a = [], o = i.id;
|
|
345
|
+
for (let t of e) t.inputs.ids.indexOf(o) >= 0 && a.push(t.id);
|
|
346
|
+
r.push(o), a.length && (n[o] = a), i.inputs.ids.length && (t[o] = i.inputs.ids);
|
|
347
|
+
}
|
|
348
|
+
return this.walk(r, n, t);
|
|
349
|
+
}
|
|
350
|
+
walk(e, t, n) {
|
|
351
|
+
let r = Object.keys(t), i = Object.keys(n), { roots: a, joint: o, leafs: s } = this.split(e, i, r), c = [];
|
|
352
|
+
if (o.length === e.length) return [o];
|
|
353
|
+
switch (o.length) {
|
|
354
|
+
case 0: break;
|
|
355
|
+
case 1:
|
|
356
|
+
case 2:
|
|
357
|
+
c.push(o);
|
|
358
|
+
break;
|
|
359
|
+
default:
|
|
360
|
+
let e = {}, a = {};
|
|
361
|
+
for (let n of r) {
|
|
362
|
+
let r = t[n];
|
|
363
|
+
if (!r || o.indexOf(n) < 0) continue;
|
|
364
|
+
let i = r.filter((e) => o.indexOf(e) >= 0);
|
|
365
|
+
i.length && (e[n] = i);
|
|
366
|
+
}
|
|
367
|
+
for (let e of i) {
|
|
368
|
+
let t = n[e];
|
|
369
|
+
if (!t || o.indexOf(e) < 0) continue;
|
|
370
|
+
let r = t.filter((e) => o.indexOf(e) >= 0);
|
|
371
|
+
r.length && (a[e] = r);
|
|
372
|
+
}
|
|
373
|
+
Object.keys(e).length && Object.keys(a).length ? c.push(...this.walk(o, e, a)) : c.push(o);
|
|
374
|
+
}
|
|
375
|
+
return c.unshift(a), c.push(s), c;
|
|
376
|
+
}
|
|
377
|
+
split(e, t, n) {
|
|
378
|
+
let r = n.filter((e) => t.indexOf(e) < 0), i = t.filter((e) => n.indexOf(e) < 0), a = r.concat(i), o = e.filter((e) => a.indexOf(e) < 0);
|
|
379
|
+
return o.length > 1 && console.log("left", e, {
|
|
380
|
+
dependants: t,
|
|
381
|
+
dependencies: n
|
|
382
|
+
}, {
|
|
383
|
+
roots: i,
|
|
384
|
+
leafs: r,
|
|
385
|
+
joint: o
|
|
386
|
+
}), {
|
|
387
|
+
roots: i,
|
|
388
|
+
joint: o,
|
|
389
|
+
leafs: r
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
}, fe = class {
|
|
393
|
+
sort(e, t, n) {
|
|
394
|
+
let r = n.pop();
|
|
395
|
+
for (let e of r);
|
|
396
|
+
}
|
|
397
|
+
mutate(e, t) {
|
|
398
|
+
let n = [];
|
|
399
|
+
for (let r = 0; r < t.length; r++) {
|
|
400
|
+
let i = [...t];
|
|
401
|
+
i.splice(r, 0, e), n.push(i);
|
|
402
|
+
}
|
|
403
|
+
return n;
|
|
404
|
+
}
|
|
405
|
+
}, pe = class {
|
|
406
|
+
isBarrier;
|
|
407
|
+
klass;
|
|
408
|
+
constructor(e, t) {
|
|
409
|
+
this.klass = e, this.isBarrier = t;
|
|
410
|
+
}
|
|
411
|
+
layout(e, t) {
|
|
412
|
+
return new this.klass(e, this.isBarrier);
|
|
413
|
+
}
|
|
414
|
+
getSubGraphs(e) {
|
|
415
|
+
return new this.klass(e, this.isBarrier).getSubGraphs();
|
|
416
|
+
}
|
|
417
|
+
}, j = Symbol("changed"), M = class extends e {
|
|
418
|
+
all;
|
|
419
|
+
map = {};
|
|
420
|
+
constructor(e = []) {
|
|
421
|
+
super(), this.all = e;
|
|
422
|
+
}
|
|
423
|
+
clear() {
|
|
424
|
+
let e = this.all;
|
|
425
|
+
this.all = [], this.map = {}, this.dispatchEvent(j, {
|
|
426
|
+
diff: e,
|
|
427
|
+
added: !1
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
find(e) {
|
|
431
|
+
return this.all.find(e);
|
|
432
|
+
}
|
|
433
|
+
filter(e) {
|
|
434
|
+
return this.all.filter(e);
|
|
435
|
+
}
|
|
436
|
+
get(e) {
|
|
437
|
+
return this.map[e];
|
|
438
|
+
}
|
|
439
|
+
add(e) {
|
|
440
|
+
let t = Array.isArray(e) ? e : [e], n = [];
|
|
441
|
+
for (let e of t) this.all.includes(e) || (n.push(e), this.map[e.id] = e);
|
|
442
|
+
return n.length && (this.all = this.all.concat(n), this.dispatchEvent(j)), e;
|
|
443
|
+
}
|
|
444
|
+
remove(e) {
|
|
445
|
+
Array.isArray(e) || (e = [e]);
|
|
446
|
+
let t = this.all.filter((t) => !e.includes(t.id));
|
|
447
|
+
if (t.length !== this.all.length) {
|
|
448
|
+
for (let t of e) delete this.map[t];
|
|
449
|
+
this.all = t, this.dispatchEvent(j);
|
|
450
|
+
}
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
onChange(e) {
|
|
454
|
+
return this.handleEvent(j, e);
|
|
455
|
+
}
|
|
456
|
+
}, N = (e, t) => e === t ? !0 : e.length === t.length ? e.every((e, n) => e.id === t[n]?.id) : !1;
|
|
457
|
+
function me(e) {
|
|
458
|
+
let [[t, n]] = u(() => {
|
|
459
|
+
let t = e();
|
|
460
|
+
return [t, [
|
|
461
|
+
(e) => t.onChange(e),
|
|
462
|
+
() => t.all,
|
|
463
|
+
() => t.all,
|
|
464
|
+
(e) => e,
|
|
465
|
+
N
|
|
466
|
+
]];
|
|
467
|
+
});
|
|
468
|
+
return s(() => () => {
|
|
469
|
+
for (let e of t.all) e.dispose();
|
|
470
|
+
}, []), [t, v(...n)];
|
|
471
|
+
}
|
|
472
|
+
//#endregion
|
|
473
|
+
//#region src/graph/useDraggable.tsx
|
|
474
|
+
var P = (e) => {
|
|
475
|
+
let t = e.position, [n, r] = u(() => ({
|
|
476
|
+
x: t.x,
|
|
477
|
+
y: t.y
|
|
478
|
+
})), { isDragging: i, bind: a } = p(({ isDragging: t, offset: i, pos: a, move: o, up: s, down: c, context: l, e: u }) => {
|
|
479
|
+
let { x: d, y: f } = e.position;
|
|
480
|
+
s ? (r({
|
|
481
|
+
x: d,
|
|
482
|
+
y: f
|
|
483
|
+
}), e.onUp({
|
|
484
|
+
x: n.x + a.x,
|
|
485
|
+
y: n.y + a.y
|
|
486
|
+
})) : o ? t ? e.onDrag({
|
|
487
|
+
x: n.x + i.x,
|
|
488
|
+
y: n.y + i.y
|
|
489
|
+
}) : e.onPointer({
|
|
490
|
+
x: d + a.x,
|
|
491
|
+
y: f + a.y
|
|
492
|
+
}) : c && (l ? e.onContext({
|
|
493
|
+
x: n.x + a.x,
|
|
494
|
+
y: n.y + a.y
|
|
495
|
+
}) : e.onClick({
|
|
496
|
+
x: n.x + a.x,
|
|
497
|
+
y: n.y + a.y
|
|
498
|
+
}, u));
|
|
499
|
+
});
|
|
500
|
+
return {
|
|
501
|
+
isDragging: i,
|
|
502
|
+
bind: a,
|
|
503
|
+
anchor: n,
|
|
504
|
+
reset: h((t) => {
|
|
505
|
+
e.onDrag(t), r(t);
|
|
506
|
+
})
|
|
507
|
+
};
|
|
508
|
+
}, F = /* @__PURE__ */ ne({});
|
|
509
|
+
import * as he from "@pixi/core";
|
|
510
|
+
T(F, he);
|
|
511
|
+
import * as ge from "@pixi/display";
|
|
512
|
+
T(F, ge);
|
|
513
|
+
import * as _e from "@pixi/sprite";
|
|
514
|
+
T(F, _e);
|
|
515
|
+
import * as ve from "@pixi/graphics";
|
|
516
|
+
T(F, ve);
|
|
517
|
+
import * as ye from "@pixi/text";
|
|
518
|
+
T(F, ye);
|
|
519
|
+
import * as be from "@pixi/text-bitmap";
|
|
520
|
+
T(F, be);
|
|
521
|
+
import * as xe from "@pixi/events";
|
|
522
|
+
T(F, xe);
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/graph/render/Batch.ts
|
|
525
|
+
var I = class extends e {
|
|
526
|
+
counter;
|
|
527
|
+
constructor() {
|
|
528
|
+
super(), this.counter = 0;
|
|
529
|
+
}
|
|
530
|
+
batch(e) {
|
|
531
|
+
try {
|
|
532
|
+
this.begin(), e();
|
|
533
|
+
} finally {
|
|
534
|
+
this.end();
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
begin() {
|
|
538
|
+
this.counter++;
|
|
539
|
+
}
|
|
540
|
+
end() {
|
|
541
|
+
--this.counter <= 0 && (this.counter = 0, this.dispatchEvent(".", this));
|
|
542
|
+
}
|
|
543
|
+
and(e) {
|
|
544
|
+
return this.handleEvent(".", e);
|
|
545
|
+
}
|
|
546
|
+
}, Se = [
|
|
547
|
+
[0, -1],
|
|
548
|
+
[-1, 0],
|
|
549
|
+
[0, 1],
|
|
550
|
+
[1, 0]
|
|
551
|
+
], L = Math.PI * 2, R = Math.PI / 2, z = class extends F.Graphics {
|
|
552
|
+
sizeX;
|
|
553
|
+
sizeY;
|
|
554
|
+
lineSize;
|
|
555
|
+
color;
|
|
556
|
+
progress;
|
|
557
|
+
active = !1;
|
|
558
|
+
#e;
|
|
559
|
+
#t;
|
|
560
|
+
#n;
|
|
561
|
+
#r;
|
|
562
|
+
constructor(e, { lineSize: t, sizeX: n, sizeY: r, radius: i, color: a }) {
|
|
563
|
+
super(), this.lineSize = t, this.color = a, this.sizeX = n, this.sizeY = r, this.#t = new F.Graphics().lineStyle({
|
|
564
|
+
width: t,
|
|
565
|
+
color: a
|
|
566
|
+
}).drawRoundedRect(0, 0, n, r, i), this.#e = new F.Graphics(), this.#e.position.set(n / 2, r / 2), this.#t.mask = this.#e, this.addChild(e), this.addChild(this.#t), this.addChild(this.#e), this.progress = 0;
|
|
567
|
+
let o = this.sizeX / 2, s = this.sizeY / 2, c = -o + this.lineSize, l = -s + this.lineSize, u = +o - this.lineSize, d = +s - this.lineSize, f = [
|
|
568
|
+
[
|
|
569
|
+
c,
|
|
570
|
+
l,
|
|
571
|
+
u,
|
|
572
|
+
l
|
|
573
|
+
],
|
|
574
|
+
[
|
|
575
|
+
c,
|
|
576
|
+
l,
|
|
577
|
+
c,
|
|
578
|
+
d
|
|
579
|
+
],
|
|
580
|
+
[
|
|
581
|
+
c,
|
|
582
|
+
d,
|
|
583
|
+
u,
|
|
584
|
+
d
|
|
585
|
+
],
|
|
586
|
+
[
|
|
587
|
+
u,
|
|
588
|
+
l,
|
|
589
|
+
u,
|
|
590
|
+
d
|
|
591
|
+
]
|
|
592
|
+
], p = [
|
|
593
|
+
+o + this.lineSize,
|
|
594
|
+
-s - this.lineSize,
|
|
595
|
+
+o + this.lineSize,
|
|
596
|
+
+s + this.lineSize,
|
|
597
|
+
-o - this.lineSize,
|
|
598
|
+
+s + this.lineSize,
|
|
599
|
+
-o - this.lineSize,
|
|
600
|
+
-s - this.lineSize
|
|
601
|
+
];
|
|
602
|
+
this.#r = {
|
|
603
|
+
segments: f,
|
|
604
|
+
corners: p
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
setActive(e) {
|
|
608
|
+
e !== this.active && (this.update(0), this.#n &&= (clearInterval(this.#n), 0), this.active = e, e && (this.#n = setInterval(() => this.update(this.progress + .005), 10)));
|
|
609
|
+
}
|
|
610
|
+
destroy(e) {
|
|
611
|
+
super.destroy(e), this.removeFromParent(), clearInterval(this.#n);
|
|
612
|
+
}
|
|
613
|
+
hotSwap(e) {
|
|
614
|
+
this.removeChildren(), this.addChild(e), this.addChild(this.#t), this.addChild(this.#e);
|
|
615
|
+
}
|
|
616
|
+
update(e) {
|
|
617
|
+
this.progress = e;
|
|
618
|
+
let t = e * L % L, n = Math.cos(t - R) * this.sizeX * 2, r = Math.sin(t - R) * this.sizeY * 2, i, a = null, o = 0;
|
|
619
|
+
for (let e = 0; e < this.#r.segments.length; e++) {
|
|
620
|
+
let t = this.#r.segments[e], s = ae(0, 0, n, r, t[0], t[1], t[2], t[3]);
|
|
621
|
+
if (s) {
|
|
622
|
+
a = s, o = e === 0 ? s.x > 0 ? 0 : 4 : 4 - e, i = Se[e];
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (a && i) {
|
|
627
|
+
this.#e.clear().beginFill().moveTo(0, 0).moveTo(0, -(this.sizeX / 2) - this.lineSize);
|
|
628
|
+
for (let e = 0; e < o; e++) this.#e.lineTo(this.#r.corners[e * 2], this.#r.corners[e * 2 + 1]);
|
|
629
|
+
this.#e.lineTo(a.x + i[0] * this.lineSize * 2, a.y + i[1] * this.lineSize * 2).lineTo(a.x, a.y).lineTo(0, 0).endFill();
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}, B = class extends F.Graphics {
|
|
633
|
+
from;
|
|
634
|
+
to;
|
|
635
|
+
angled = !1;
|
|
636
|
+
color = 5592405;
|
|
637
|
+
#e;
|
|
638
|
+
#t = 2;
|
|
639
|
+
constructor(e, t, n, r, i = 2) {
|
|
640
|
+
super(), this.#e = i, this.from = new F.ObservablePoint(() => this.update(), 0, e, t), this.to = new F.ObservablePoint(() => this.update(), 0, n, r), this.eventMode = "none";
|
|
641
|
+
}
|
|
642
|
+
moveFromPoint(e) {
|
|
643
|
+
let t = this.from.x !== e.x || this.from.y !== e.y;
|
|
644
|
+
return t && this.from.copyFrom(e), t;
|
|
645
|
+
}
|
|
646
|
+
moveToPoint(e) {
|
|
647
|
+
let t = this.to.x !== e.x || this.to.y !== e.y;
|
|
648
|
+
return t && this.to.copyFrom(e), t;
|
|
649
|
+
}
|
|
650
|
+
setColor(e) {
|
|
651
|
+
return this.color = e, this;
|
|
652
|
+
}
|
|
653
|
+
setWidth(e) {
|
|
654
|
+
return this.#t = e, this;
|
|
655
|
+
}
|
|
656
|
+
update() {
|
|
657
|
+
let { x: e, y: t } = this.from, { x: n, y: r } = this.to, i = n - e, a = r - t, o = i / 2, s = a / 2;
|
|
658
|
+
return this.clear(), this.lineStyle(this.#t, this.color, this.alpha), this.x = n - o, this.y = r - s, this.angled ? (this.moveTo(-o, -s), this.lineTo(0, -s), this.lineTo(0, s), this.lineTo(o, s)) : (this.moveTo(-o, -s), this.lineTo(o, s)), this.#e && (this.beginFill(this.color, this.alpha), this.drawCircle(-o, -s, this.#e / 2), this.drawCircle(o, s, this.#e / 2), this.endFill()), this;
|
|
659
|
+
}
|
|
660
|
+
}, V = class extends F.Graphics {
|
|
661
|
+
from;
|
|
662
|
+
to;
|
|
663
|
+
constructor(e, t) {
|
|
664
|
+
super(), this.from = new F.Point(e, t), this.to = {};
|
|
665
|
+
for (let e of Object.values(this.to)) this.addChild(e);
|
|
666
|
+
}
|
|
667
|
+
addTarget(e, t) {
|
|
668
|
+
let n = `${e}-${t}`;
|
|
669
|
+
return this.to[n] || (this.to[n] = this.addChild(new B(this.from.x, this.from.y, 0, 0)));
|
|
670
|
+
}
|
|
671
|
+
moveTargetTo(e, t, n) {
|
|
672
|
+
return this.addTarget(e, t).moveToPoint(n);
|
|
673
|
+
}
|
|
674
|
+
removeTarget(e, t) {
|
|
675
|
+
let n = `${e}-${t}`, r = this.to[n];
|
|
676
|
+
r && (delete this.to[n], this.removeChild(r));
|
|
677
|
+
}
|
|
678
|
+
move(e) {
|
|
679
|
+
let t = this.from.x !== e.x || this.from.y !== e.y;
|
|
680
|
+
if (t) {
|
|
681
|
+
this.from.copyFrom(e);
|
|
682
|
+
for (let t of Object.values(this.to)) t.moveFromPoint(e);
|
|
683
|
+
}
|
|
684
|
+
return t;
|
|
685
|
+
}
|
|
686
|
+
}, Ce = {
|
|
687
|
+
0: 6710886,
|
|
688
|
+
2: 16737894,
|
|
689
|
+
1: 6750054
|
|
690
|
+
}, we = {
|
|
691
|
+
0: 6710886,
|
|
692
|
+
2: 11167334,
|
|
693
|
+
1: 16724787
|
|
694
|
+
}, Te = (e, t, n) => {
|
|
695
|
+
let { point: { parent: r, input: i } } = e;
|
|
696
|
+
if (t.hover) {
|
|
697
|
+
let a = r === t.point.parent || i === t.point.input ? 2 : 1;
|
|
698
|
+
if (a && n) {
|
|
699
|
+
let n = e.point.nodes.some(D(t.point.parent, t.point.port)), r = t.point.nodes.some(D(e.point.parent, e.point.port));
|
|
700
|
+
return n && r ? 1 : 0;
|
|
701
|
+
}
|
|
702
|
+
return a;
|
|
703
|
+
}
|
|
704
|
+
return 0;
|
|
705
|
+
}, Ee = (e, t) => e.parent === t.parent && e.port === t.port, De = class extends F.Graphics {
|
|
706
|
+
line1;
|
|
707
|
+
line2;
|
|
708
|
+
line12;
|
|
709
|
+
line22;
|
|
710
|
+
constructor(e, t = 0, n = 1118481) {
|
|
711
|
+
super();
|
|
712
|
+
let r = e / 2, i = e / 2 + 2;
|
|
713
|
+
this.line12 = new B(-i, -i, i, i, 0).setWidth(6).setColor(n).update(), this.line22 = new B(i, -i, -i, i, 0).setWidth(6).setColor(n).update(), this.line1 = new B(-r, -r, r, r, 0), this.line2 = new B(r, -r, -r, r, 0), this.setColor(t), this.addChild(this.line12, this.line22, this.line2, this.line1);
|
|
714
|
+
}
|
|
715
|
+
show() {
|
|
716
|
+
return this.visible = !0, this;
|
|
717
|
+
}
|
|
718
|
+
hide() {
|
|
719
|
+
return this.visible = !1, this;
|
|
720
|
+
}
|
|
721
|
+
setColor(e) {
|
|
722
|
+
return this.line1.setColor(e).update(), this.line2.setColor(e).update(), this;
|
|
723
|
+
}
|
|
724
|
+
setAngle(e) {
|
|
725
|
+
return this.angle === e ? this : (this.angle = e, this.rotation = e, this);
|
|
726
|
+
}
|
|
727
|
+
setPosition(e) {
|
|
728
|
+
return this.x = e.x, this.y = e.y, this;
|
|
729
|
+
}
|
|
730
|
+
}, Oe = class extends V {
|
|
731
|
+
start;
|
|
732
|
+
finish;
|
|
733
|
+
viable;
|
|
734
|
+
#e;
|
|
735
|
+
#t;
|
|
736
|
+
constructor(e) {
|
|
737
|
+
super(e.pos.x, e.pos.y), this.start = e, this.viable = 0, this.#e = this.addTarget(0, 0), this.#t = new De(10, 16724787).hide(), this.addChild(this.#t);
|
|
738
|
+
}
|
|
739
|
+
get isRemoving() {
|
|
740
|
+
return this.start.remove || !!this.finish?.remove;
|
|
741
|
+
}
|
|
742
|
+
setLine(e) {
|
|
743
|
+
this.#e.visible = !0;
|
|
744
|
+
let { x: t, y: n } = this.start.pos, { x: r, y: i } = e, a = r - t, o = i - n, s = a ? Math.atan(o / a) : 0;
|
|
745
|
+
if (this.isRemoving) {
|
|
746
|
+
let e = {
|
|
747
|
+
x: t + a / 2,
|
|
748
|
+
y: n + o / 2
|
|
749
|
+
};
|
|
750
|
+
this.#t.setColor(we[this.viable]).setPosition(e).setAngle(s).show(), this.viable === 0 && (this.#e.visible = !1, this.#t.hide());
|
|
751
|
+
} else this.#t.hide();
|
|
752
|
+
this.#e.setColor(this.isRemoving ? we[this.viable] : Ce[this.viable]).moveToPoint(e);
|
|
753
|
+
}
|
|
754
|
+
flail(e) {
|
|
755
|
+
this.finish || this.setLine(e);
|
|
756
|
+
}
|
|
757
|
+
hoverPort(e) {
|
|
758
|
+
this.viable = Te(this.start, e, this.isRemoving), this.finish = this.viable === 1 ? e : void 0, this.setLine(e.pos);
|
|
759
|
+
}
|
|
760
|
+
connect({ point: e }) {
|
|
761
|
+
if (this.finish && Ee(this.finish.point, e)) {
|
|
762
|
+
let { start: { remove: e, point: t }, finish: { remove: n, point: r } } = this, i = t.input ? t : r, a = t.input ? r : t;
|
|
763
|
+
return {
|
|
764
|
+
connect: !(e || n),
|
|
765
|
+
output: a,
|
|
766
|
+
input: i
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
return !1;
|
|
770
|
+
}
|
|
771
|
+
}, H = class extends F.Container {
|
|
772
|
+
static makeFont = (e, t, n) => typeof document < "u" && F.BitmapFont.from(e, t, {
|
|
773
|
+
chars: [
|
|
774
|
+
["a", "z"],
|
|
775
|
+
["A", "Z"],
|
|
776
|
+
["а", "я"],
|
|
777
|
+
["А", "Я"],
|
|
778
|
+
["0", "9"],
|
|
779
|
+
"!@#$%^&*?()~{}[]<>\\/|_+-=.,\n:;'\"` ",
|
|
780
|
+
"←↑→↓"
|
|
781
|
+
],
|
|
782
|
+
...n
|
|
783
|
+
});
|
|
784
|
+
#e;
|
|
785
|
+
static factory = (e, t, n) => (this.makeFont(e, t, n), (t, n) => new this(t, {
|
|
786
|
+
...n,
|
|
787
|
+
fontName: e
|
|
788
|
+
}));
|
|
789
|
+
constructor(e, t) {
|
|
790
|
+
super(), this.#e = this.addChild(new F.BitmapText(String(e), t));
|
|
791
|
+
}
|
|
792
|
+
set text(e) {
|
|
793
|
+
this.#e.text = String(e);
|
|
794
|
+
}
|
|
795
|
+
get text() {
|
|
796
|
+
return this.#e.text;
|
|
797
|
+
}
|
|
798
|
+
set tint(e) {
|
|
799
|
+
this.#e.tint = e;
|
|
800
|
+
}
|
|
801
|
+
}, U = Symbol.for("E_PORT_CLICK"), W = Symbol.for("E_PORT_HOVER"), ke = class t extends F.Graphics {
|
|
802
|
+
connectorPoint;
|
|
803
|
+
hasBothLanes;
|
|
804
|
+
static port = H.factory("nodePort", {
|
|
805
|
+
fontFamily: ["Menlo", "monospace"],
|
|
806
|
+
fontSize: 16,
|
|
807
|
+
lineHeight: 20,
|
|
808
|
+
align: "center"
|
|
809
|
+
});
|
|
810
|
+
#e = new e();
|
|
811
|
+
#t;
|
|
812
|
+
constructor(e, n) {
|
|
813
|
+
super(), this.connectorPoint = e, this.hasBothLanes = n, this.#t = !!e.nodes.length, this.x = e.x, this.y = e.y;
|
|
814
|
+
let r = e.input ? 1 : -1, i = this.addChild(t.port(this.label, { fontSize: 8 }));
|
|
815
|
+
i.y = -4, i.x = r * 12 - (e.input ? 0 : i.width), i.eventMode = "none", this.lineStyle(1, 3355443, 1), this.beginFill(this.#t ? 11184810 : 16777215), this.drawCircle(0, 0, 8 / 2), this.endFill(), this.eventMode = "static", this.cursor = "pointer", this.addEventListener("pointerdown", (e) => {
|
|
816
|
+
e.preventDefault(), e.stopPropagation(), this.#e.dispatchEvent(U, e);
|
|
817
|
+
}), this.addEventListener("pointerenter", (e) => {
|
|
818
|
+
e.preventDefault(), e.stopPropagation(), this.#e.dispatchEvent(W, !0);
|
|
819
|
+
}), this.addEventListener("pointerleave", (e) => {
|
|
820
|
+
e.preventDefault(), e.stopPropagation(), this.#e.dispatchEvent(W, !1);
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
get label() {
|
|
824
|
+
return String(this.connectorPoint.name).slice(0, this.hasBothLanes ? 2 : 8);
|
|
825
|
+
}
|
|
826
|
+
dispose() {
|
|
827
|
+
this.#e.dispose(), this.removeFromParent();
|
|
828
|
+
}
|
|
829
|
+
get active() {
|
|
830
|
+
return this.#t;
|
|
831
|
+
}
|
|
832
|
+
setActive(e) {
|
|
833
|
+
this.#t = e, this.update();
|
|
834
|
+
}
|
|
835
|
+
update() {
|
|
836
|
+
this.beginFill(this.active ? 11184810 : 16777215), this.drawCircle(0, 0, 8 / 2), this.endFill();
|
|
837
|
+
}
|
|
838
|
+
onClick(e) {
|
|
839
|
+
return this.#e.handleEvent(U, e);
|
|
840
|
+
}
|
|
841
|
+
onHover(e) {
|
|
842
|
+
return this.#e.handleEvent(W, e);
|
|
843
|
+
}
|
|
844
|
+
}, Ae = Symbol.for("E_MOVE_NODE"), G = Symbol.for("E_CAPTURE_NODE"), K = (e, t) => {
|
|
845
|
+
let n = e.global;
|
|
846
|
+
return t ? (t.x = n.x, t.y = n.y, t) : {
|
|
847
|
+
x: n.x,
|
|
848
|
+
y: n.y
|
|
849
|
+
};
|
|
850
|
+
}, q = (e) => e.__drag_root ? e : e.parent && q(e.parent);
|
|
851
|
+
function je(e) {
|
|
852
|
+
return function(t) {
|
|
853
|
+
if (e.dispatchEvent(G, !0), t.buttons & 2) return;
|
|
854
|
+
let n = this._drag_meta = {
|
|
855
|
+
root: q(this.parent) || (() => {
|
|
856
|
+
throw Error("Can't find scene root");
|
|
857
|
+
})(),
|
|
858
|
+
emitter: e,
|
|
859
|
+
dragging: !0,
|
|
860
|
+
anchor: this.position.clone(),
|
|
861
|
+
lastPosition: K(t),
|
|
862
|
+
newPosition: K(t),
|
|
863
|
+
onDragEnd: Ne(this),
|
|
864
|
+
onDragMove: Me(this)
|
|
865
|
+
};
|
|
866
|
+
n.root.addEventListener("pointerup", n.onDragEnd, {
|
|
867
|
+
capture: !0,
|
|
868
|
+
passive: !0
|
|
869
|
+
}), n.root.addEventListener("pointerupoutside", n.onDragEnd, {
|
|
870
|
+
capture: !0,
|
|
871
|
+
passive: !0
|
|
872
|
+
}), n.root.addEventListener("pointermove", n.onDragMove, {
|
|
873
|
+
capture: !0,
|
|
874
|
+
passive: !0
|
|
875
|
+
});
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
var Me = (e) => (t) => {
|
|
879
|
+
if (!e._drag_meta?.dragging) return;
|
|
880
|
+
let { newPosition: n, lastPosition: r, anchor: i, emitter: a } = e._drag_meta;
|
|
881
|
+
K(t, n), n.x -= r.x, n.y -= r.y, a.dispatchEvent(Ae, {
|
|
882
|
+
x: i.x + n.x,
|
|
883
|
+
y: i.y + n.y
|
|
884
|
+
});
|
|
885
|
+
}, Ne = (e) => () => {
|
|
886
|
+
if (!e._drag_meta) return;
|
|
887
|
+
let { root: t, emitter: n, onDragEnd: r, onDragMove: i } = e._drag_meta;
|
|
888
|
+
t.removeEventListener("pointerup", r), t.removeEventListener("pointerupoutside", r), t.removeEventListener("pointermove", i), n.dispatchEvent(G, !1), delete e._drag_meta;
|
|
889
|
+
}, J = Symbol.for("E_NODE_CONTEXT"), Y = Symbol.for("E_CONNECTORS_UPDATE"), Pe = class t extends e {
|
|
890
|
+
static label = H.factory("nodeLabel", {
|
|
891
|
+
fontSize: 24,
|
|
892
|
+
align: "center",
|
|
893
|
+
fill: "#efefef",
|
|
894
|
+
dropShadow: !0,
|
|
895
|
+
dropShadowDistance: 2
|
|
896
|
+
});
|
|
897
|
+
#e;
|
|
898
|
+
#t;
|
|
899
|
+
#n;
|
|
900
|
+
#r = je(this);
|
|
901
|
+
data;
|
|
902
|
+
find;
|
|
903
|
+
ports = /* @__PURE__ */ new Map();
|
|
904
|
+
constructor(e, n) {
|
|
905
|
+
super(), this.data = e, this.find = n, this.data.onConnect(this.#i.bind(this)), this.#e = t.label(this.label, { fontSize: 11 });
|
|
906
|
+
}
|
|
907
|
+
get id() {
|
|
908
|
+
return this.data.id;
|
|
909
|
+
}
|
|
910
|
+
get label() {
|
|
911
|
+
return this.data.title;
|
|
912
|
+
}
|
|
913
|
+
dispose() {
|
|
914
|
+
for (let e of this.ports.values()) e.dispose();
|
|
915
|
+
if (this.#n) {
|
|
916
|
+
let e = this.#n.map(({ port: e }) => `${this.id}-${e}`);
|
|
917
|
+
e.length && this.dispatchEvent(Y, { remove: e });
|
|
918
|
+
}
|
|
919
|
+
this.#t &&= (this.#t.removeFromParent(), void 0), super.dispose();
|
|
920
|
+
}
|
|
921
|
+
move(e) {
|
|
922
|
+
this.renderable.position.copyFrom(this.data.move(e)), this.placeConnectors();
|
|
923
|
+
}
|
|
924
|
+
hitTest({ x: e, y: t }) {
|
|
925
|
+
let { x: n, y: r } = this.renderable;
|
|
926
|
+
return e < n || t < r ? !1 : e - n <= this.width && t - r <= this.height;
|
|
927
|
+
}
|
|
928
|
+
get width() {
|
|
929
|
+
return this.data.width;
|
|
930
|
+
}
|
|
931
|
+
get height() {
|
|
932
|
+
return this.data.height + 16;
|
|
933
|
+
}
|
|
934
|
+
#i({ connect: e, input: t, source: { port: n }, target: r }) {
|
|
935
|
+
let i = this.connectors.find((e) => e.port === n && e.input === t);
|
|
936
|
+
if (!i) return;
|
|
937
|
+
O(e, i, r);
|
|
938
|
+
let a = this.ports.get(n);
|
|
939
|
+
a && a.setActive(!!i.nodes.length);
|
|
940
|
+
}
|
|
941
|
+
connectedAt(e, t, n) {
|
|
942
|
+
return this.connectors.find(({ nodes: r, connector: i }) => n !== !i && r.length && r.some(D(e, t)));
|
|
943
|
+
}
|
|
944
|
+
get connectors() {
|
|
945
|
+
if (this.#n) return this.#n;
|
|
946
|
+
let e = [], t = 1, n = 1;
|
|
947
|
+
for (let n of this.data.inputs) {
|
|
948
|
+
let r = {
|
|
949
|
+
x: 16 / 2,
|
|
950
|
+
y: t * 16 + 16 / 2
|
|
951
|
+
}, i = E(this.data.position, r);
|
|
952
|
+
e.push({
|
|
953
|
+
parent: this.data.id,
|
|
954
|
+
port: n.port,
|
|
955
|
+
name: n.name,
|
|
956
|
+
nodes: n.nodes,
|
|
957
|
+
input: !0,
|
|
958
|
+
x: r.x,
|
|
959
|
+
y: r.y,
|
|
960
|
+
connector: new V(i.x, i.y)
|
|
961
|
+
}), t++;
|
|
962
|
+
}
|
|
963
|
+
for (let t of this.data.outputs) e.push({
|
|
964
|
+
parent: this.data.id,
|
|
965
|
+
port: t.port,
|
|
966
|
+
name: t.name,
|
|
967
|
+
nodes: t.nodes,
|
|
968
|
+
input: !1,
|
|
969
|
+
x: 64 - 16 / 2,
|
|
970
|
+
y: n * 16 + 16 / 2
|
|
971
|
+
}), n++;
|
|
972
|
+
return this.#n = e;
|
|
973
|
+
}
|
|
974
|
+
placeConnectors(e = !0) {
|
|
975
|
+
let t = /* @__PURE__ */ new Map(), n = [];
|
|
976
|
+
for (let r of this.connectors) {
|
|
977
|
+
let { connector: i, nodes: a, port: o } = r, s = `${this.id}-${o}`;
|
|
978
|
+
if (i) if (i.move(E(this.renderable, r)), a.length) {
|
|
979
|
+
let e = 0;
|
|
980
|
+
for (let { node: t, port: n } of a) {
|
|
981
|
+
let r = this.find(t), a = r?.connectedAt(this.id, o);
|
|
982
|
+
r && a ? (i.moveTargetTo(t, n, E(r.renderable, a)), e++) : i.removeTarget(t, n);
|
|
983
|
+
}
|
|
984
|
+
e && t.set(s, i);
|
|
985
|
+
} else n.push(s);
|
|
986
|
+
else if (e && a.length) for (let { node: e } of a) this.find(e)?.placeConnectors(!1);
|
|
987
|
+
}
|
|
988
|
+
(t.size || n.length) && this.dispatchEvent(Y, {
|
|
989
|
+
add: t.size ? [...t.entries()].map(([e, t]) => ({
|
|
990
|
+
uid: e,
|
|
991
|
+
connector: t
|
|
992
|
+
})) : void 0,
|
|
993
|
+
remove: n.length ? n : void 0
|
|
994
|
+
});
|
|
995
|
+
}
|
|
996
|
+
get renderable() {
|
|
997
|
+
if (this.#t) return this.#t;
|
|
998
|
+
let e = this.width, t = this.height, n = this.makeRoundRect({
|
|
999
|
+
width: e,
|
|
1000
|
+
height: t,
|
|
1001
|
+
stroke: 14671855,
|
|
1002
|
+
fill: 16645629
|
|
1003
|
+
});
|
|
1004
|
+
this.#e.y = (16 - this.#e.height) / 2, this.#e.x = (e - this.#e.width) / 2, n.addChild(this.makeLane({
|
|
1005
|
+
x: 0,
|
|
1006
|
+
y: 0,
|
|
1007
|
+
width: e,
|
|
1008
|
+
height: 16,
|
|
1009
|
+
fill: 8224125
|
|
1010
|
+
})).addChild(this.#e);
|
|
1011
|
+
let r = this.data.inputs.count, i = this.data.outputs.count;
|
|
1012
|
+
r && n.addChild(this.makeLane({
|
|
1013
|
+
x: 0,
|
|
1014
|
+
y: 16,
|
|
1015
|
+
height: t - 16
|
|
1016
|
+
})), i && n.addChild(this.makeLane({
|
|
1017
|
+
x: e - 16,
|
|
1018
|
+
y: 16,
|
|
1019
|
+
height: t - 16
|
|
1020
|
+
}));
|
|
1021
|
+
let a = !!(r && i);
|
|
1022
|
+
for (let e of this.connectors) n.addChild(this.makePort(e, a));
|
|
1023
|
+
let o = this.data.render(n);
|
|
1024
|
+
return o.eventMode = "static", o.addEventListener("pointerdown", (e) => this.handleClick(e)), o.x = this.data.position.x, o.y = this.data.position.y, this.#t = o;
|
|
1025
|
+
}
|
|
1026
|
+
makeRoundRect({ stroke: e, fill: t, x: n = 0, y: r = 0, width: i, height: a, thickness: o = 1, radius: s = 4 }) {
|
|
1027
|
+
let c = new F.Graphics();
|
|
1028
|
+
return c.lineStyle(o, e), c.beginFill(t), c.drawRoundedRect(0, 0, i, a, s), c.endFill(), c.x = n, c.y = r, c;
|
|
1029
|
+
}
|
|
1030
|
+
makeLane(e) {
|
|
1031
|
+
return this.makeRoundRect(Object.assign({
|
|
1032
|
+
width: 16,
|
|
1033
|
+
height: 16,
|
|
1034
|
+
stroke: 14737632,
|
|
1035
|
+
fill: 15592941
|
|
1036
|
+
}, e));
|
|
1037
|
+
}
|
|
1038
|
+
makePort(e, t) {
|
|
1039
|
+
let { port: n, x: r, y: i } = e, a = new ke(e, t);
|
|
1040
|
+
return this.ports.set(n, a), a.onClick((t) => {
|
|
1041
|
+
if (t.buttons & 2) return this.dispatchEvent(J, {
|
|
1042
|
+
event: t,
|
|
1043
|
+
tag: {
|
|
1044
|
+
type: "port",
|
|
1045
|
+
id: n
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
this.dispatchEvent(U, {
|
|
1049
|
+
remove: t.ctrlKey || t.metaKey,
|
|
1050
|
+
point: e,
|
|
1051
|
+
pos: {
|
|
1052
|
+
x: this.renderable.x + r,
|
|
1053
|
+
y: this.renderable.y + i
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
}), a.onHover((t) => this.dispatchEvent(W, {
|
|
1057
|
+
point: e,
|
|
1058
|
+
hover: t,
|
|
1059
|
+
pos: {
|
|
1060
|
+
x: this.renderable.x + r,
|
|
1061
|
+
y: this.renderable.y + i
|
|
1062
|
+
}
|
|
1063
|
+
})), a;
|
|
1064
|
+
}
|
|
1065
|
+
handleClick(e) {
|
|
1066
|
+
e.buttons & 2 ? (e.stopPropagation(), e.preventDefault(), this.dispatchEvent(J, {
|
|
1067
|
+
event: e,
|
|
1068
|
+
tag: {
|
|
1069
|
+
type: "node",
|
|
1070
|
+
id: this.data.id
|
|
1071
|
+
}
|
|
1072
|
+
})) : this.#r.call(this.renderable, e);
|
|
1073
|
+
}
|
|
1074
|
+
onContext(e) {
|
|
1075
|
+
return this.handleEvent(J, e);
|
|
1076
|
+
}
|
|
1077
|
+
onPortClick(e) {
|
|
1078
|
+
return this.handleEvent(U, e);
|
|
1079
|
+
}
|
|
1080
|
+
onPortHover(e) {
|
|
1081
|
+
return this.handleEvent(W, e);
|
|
1082
|
+
}
|
|
1083
|
+
onCapture(e) {
|
|
1084
|
+
return this.handleEvent(G, e);
|
|
1085
|
+
}
|
|
1086
|
+
onMove(e) {
|
|
1087
|
+
return this.handleEvent(Ae, e);
|
|
1088
|
+
}
|
|
1089
|
+
onConnectorsUpdate(e) {
|
|
1090
|
+
return this.handleEvent(Y, e);
|
|
1091
|
+
}
|
|
1092
|
+
update() {
|
|
1093
|
+
let e = this.connectors.reduce((e, t) => (e[t.port] = t, e), {});
|
|
1094
|
+
for (let t of this.data.inputs) {
|
|
1095
|
+
let n = e[t.port];
|
|
1096
|
+
n && (n.nodes = t.nodes);
|
|
1097
|
+
}
|
|
1098
|
+
for (let t of this.data.outputs) {
|
|
1099
|
+
let n = e[t.port];
|
|
1100
|
+
n && (n.nodes = t.nodes);
|
|
1101
|
+
}
|
|
1102
|
+
this.placeConnectors();
|
|
1103
|
+
}
|
|
1104
|
+
}, Fe = {
|
|
1105
|
+
x: 0,
|
|
1106
|
+
y: 0
|
|
1107
|
+
}, Ie = (e, t) => e.cell.x === t.cell.x && e.cell.y === t.cell.y && e.count.x === t.count.x && e.count.y === t.count.y && e.size.width === t.size.width && e.size.height === t.size.height, X = (e, t, n) => e > t ? e < n ? e : n : t, Z = (e, t, n, r, i) => X(e - t / 2, n + i, r - t - i), Le = (e) => {
|
|
1108
|
+
let t = Math.ceil(e);
|
|
1109
|
+
return t % 2 ? t + 1 : t;
|
|
1110
|
+
}, Re = class e extends F.Graphics {
|
|
1111
|
+
static text = H.factory("GridBoundary", {
|
|
1112
|
+
fontSize: 24,
|
|
1113
|
+
fill: 16777215,
|
|
1114
|
+
stroke: 0,
|
|
1115
|
+
dropShadow: !0,
|
|
1116
|
+
dropShadowDistance: 2
|
|
1117
|
+
}, { chars: [["0", "9"], "+-."] });
|
|
1118
|
+
cellSize;
|
|
1119
|
+
colors;
|
|
1120
|
+
#e;
|
|
1121
|
+
#t;
|
|
1122
|
+
#n;
|
|
1123
|
+
#r;
|
|
1124
|
+
#i;
|
|
1125
|
+
#a = new F.Rectangle(0, 0, 0, 0);
|
|
1126
|
+
#o = {
|
|
1127
|
+
cell: Fe,
|
|
1128
|
+
count: Fe,
|
|
1129
|
+
size: {
|
|
1130
|
+
width: 0,
|
|
1131
|
+
height: 0
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
#s;
|
|
1135
|
+
#c;
|
|
1136
|
+
constructor(t, n, r = 5) {
|
|
1137
|
+
super(), this.cellSize = t, this.colors = n, this.#e = r, this.#s = this.addChild(new F.Container()), this.#c = this.addChild(new F.Container()), this.#n = e.text("", { fontSize: 12 }), this.#t = e.text("", { fontSize: 12 }), this.#i = e.text("", { fontSize: 12 }), this.#r = e.text("", { fontSize: 12 });
|
|
1138
|
+
}
|
|
1139
|
+
get lods() {
|
|
1140
|
+
return this.colors.length;
|
|
1141
|
+
}
|
|
1142
|
+
snapSize({ width: e, height: t }, n) {
|
|
1143
|
+
let { x: r, y: i } = this.cellSize, a = n ? 2 ** (n - 1) * this.#e : 1, o = a * r, s = a * i, c = Le(e / o), l = Le(t / s);
|
|
1144
|
+
return {
|
|
1145
|
+
cell: {
|
|
1146
|
+
x: o,
|
|
1147
|
+
y: s
|
|
1148
|
+
},
|
|
1149
|
+
count: {
|
|
1150
|
+
x: c,
|
|
1151
|
+
y: l
|
|
1152
|
+
},
|
|
1153
|
+
size: {
|
|
1154
|
+
width: o * c,
|
|
1155
|
+
height: s * l
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
toMaxSnap(e) {
|
|
1160
|
+
return this.snapSize(e, this.lods - 1);
|
|
1161
|
+
}
|
|
1162
|
+
viewport(e) {
|
|
1163
|
+
this.makeRullers(e);
|
|
1164
|
+
let t = this.toMaxSnap(this.#a), n = this.toMaxSnap(e);
|
|
1165
|
+
this.#s.x = (e.left + e.width) % n.cell.x, this.#s.y = (e.top + e.height) % n.cell.y, !Ie(t, n) && (this.#a.copyFrom(e), this.#o = n, this.update());
|
|
1166
|
+
}
|
|
1167
|
+
makeRullers(e) {
|
|
1168
|
+
this.#c.removeChildren();
|
|
1169
|
+
let t = this.#c.addChild(new F.Graphics()), { left: n, top: r, width: i, height: a } = e, o = n + i, s = r + a, c = X(o, 1, i - 1), l = X(s, 1, a - 1);
|
|
1170
|
+
t.lineStyle(2, 16711680, 1), t.moveTo(0, l), t.lineTo(i, l), t.moveTo(c, 0), t.lineTo(c, a), this.#c.addChild(this.#n, this.#t, this.#i, this.#r), this.#n.text = ~~(-(i + n) / this.cellSize.x), this.#i.text = ~~(-(a + r) / this.cellSize.y), this.#t.text = ~~(-n / this.cellSize.x), this.#r.text = ~~(-r / this.cellSize.y);
|
|
1171
|
+
let u = this.#n.height, d = this.#n.width, f = this.#t.width, p = this.#i.width, m = this.#r.width, h = Z(l, u, 0, a, 2), g = Z(c, p, d + 5, i - f - 5, 2), _ = Z(c, m, d + 5, i - f - 5, 2);
|
|
1172
|
+
this.#n.x = 2, this.#n.y = h, this.#t.x = i - f - 2, this.#t.y = h, this.#i.x = g, this.#i.y = 2, this.#r.x = _, this.#r.y = a - u - 2;
|
|
1173
|
+
}
|
|
1174
|
+
makeLOD(e) {
|
|
1175
|
+
let t = this.colors[e], { cell: { x: n, y: r }, count: { x: i, y: a }, size: { width: o, height: s } } = this.snapSize(this.#o.size, e), c = new F.Graphics();
|
|
1176
|
+
c.lineStyle(.25 * (e + 1), t, 1);
|
|
1177
|
+
for (let e = 0; e < i; e++) c.moveTo(n * e, 0), c.lineTo(n * e, s);
|
|
1178
|
+
for (let e = 0; e < a; e++) c.moveTo(0, r * e), c.lineTo(o, r * e);
|
|
1179
|
+
return c;
|
|
1180
|
+
}
|
|
1181
|
+
makeGrid() {
|
|
1182
|
+
let e = new F.Container();
|
|
1183
|
+
for (let t of this.colors.keys()) e.addChild(this.makeLOD(t));
|
|
1184
|
+
return e;
|
|
1185
|
+
}
|
|
1186
|
+
update() {
|
|
1187
|
+
let { width: e, height: t } = this.#o.size;
|
|
1188
|
+
this.#s.removeChildren();
|
|
1189
|
+
for (let n = -1; n <= 1; n++) for (let r = -1; r <= 1; r++) {
|
|
1190
|
+
let i = this.makeGrid();
|
|
1191
|
+
i.x = n * e, i.y = r * t, this.#s.addChild(i);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}, ze = 24, Q = 12, Be = class e extends F.Container {
|
|
1195
|
+
static label = H.factory("menuItem", {
|
|
1196
|
+
fontSize: 24,
|
|
1197
|
+
align: "center",
|
|
1198
|
+
fill: 16777215
|
|
1199
|
+
});
|
|
1200
|
+
#e;
|
|
1201
|
+
#t;
|
|
1202
|
+
#n;
|
|
1203
|
+
#r;
|
|
1204
|
+
#i = 0;
|
|
1205
|
+
#a = ze;
|
|
1206
|
+
#o = !1;
|
|
1207
|
+
#s = !1;
|
|
1208
|
+
#c = !1;
|
|
1209
|
+
index;
|
|
1210
|
+
constructor(t, n, r) {
|
|
1211
|
+
super(), this.index = t, this.#n = n, this.#s = !!n.separator, this.#r = !!n.group, this.#c = !!n.disabled || this.#r, this.#e = this.addChild(new F.Graphics()), this.#t = this.addChild(e.label(this.label, { fontSize: 12 })), this.eventMode = "static", this.addEventListener("pointerdown", (e) => {
|
|
1212
|
+
this.#c || (e.stopPropagation(), e.preventDefault(), r());
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
resize(e) {
|
|
1216
|
+
this.#i = e, this.update();
|
|
1217
|
+
}
|
|
1218
|
+
get separator() {
|
|
1219
|
+
return this.#s;
|
|
1220
|
+
}
|
|
1221
|
+
set separator(e) {
|
|
1222
|
+
this.#s !== e && (this.#s = e, this.update());
|
|
1223
|
+
}
|
|
1224
|
+
get hover() {
|
|
1225
|
+
return this.#o;
|
|
1226
|
+
}
|
|
1227
|
+
set hover(e) {
|
|
1228
|
+
e &&= !this.#c, this.#o !== e && (this.#o = e, this.update());
|
|
1229
|
+
}
|
|
1230
|
+
get label() {
|
|
1231
|
+
return this.#n.label;
|
|
1232
|
+
}
|
|
1233
|
+
get labelWidth() {
|
|
1234
|
+
return this.#t.width + Q * 2;
|
|
1235
|
+
}
|
|
1236
|
+
get width() {
|
|
1237
|
+
return this.#i;
|
|
1238
|
+
}
|
|
1239
|
+
get height() {
|
|
1240
|
+
return this.#s ? 2 : this.#a;
|
|
1241
|
+
}
|
|
1242
|
+
get disabled() {
|
|
1243
|
+
return this.#c;
|
|
1244
|
+
}
|
|
1245
|
+
set disabled(e) {
|
|
1246
|
+
this.#c === e && (this.#c = e, this.update());
|
|
1247
|
+
}
|
|
1248
|
+
update() {
|
|
1249
|
+
let e = this.width, t = this.height, n = this.#e;
|
|
1250
|
+
this.separator ? (n.lineStyle(1, 1638, 1), n.moveTo(Q, 1), n.lineTo(e - Q, 1)) : this.#r ? (n.lineStyle(0, 0, 1), n.beginFill(3355443), n.drawRect(-1, 1, e + 2, t - 2), n.endFill()) : this.hover ? (n.lineStyle(0, 0, 1), n.beginFill(4473924), n.drawRoundedRect(0, 0, e, t, 4), n.endFill()) : n.clear(), this.#t.text = this.#n.label, this.#t.x = Q, this.#t.y = (t - this.#t.height) / 2, this.#t.alpha = this.#c && !this.#r ? .3 : 1, this.#t.tint = this.#r || this.hover ? 16777215 : 0;
|
|
1251
|
+
}
|
|
1252
|
+
}, Ve = Symbol.for("E_ITEM_SELECT"), He = Symbol.for("E_CLOSE_MENU"), Ue = new F.Point(), We = class extends F.Container {
|
|
1253
|
+
#e;
|
|
1254
|
+
#t;
|
|
1255
|
+
#n;
|
|
1256
|
+
#r;
|
|
1257
|
+
#i;
|
|
1258
|
+
#a = -1;
|
|
1259
|
+
constructor(t) {
|
|
1260
|
+
super(), this.#i = new e(), this.#n = this.addChild(new F.Graphics()), this.#e = this.addChild(new F.Graphics()), this.#t = this.addChild(new F.Container()), this.#r = t.items.map((e, t) => this.#t.addChild(new Be(t, e, () => this.handleSelect(e)))), this.#t.mask = this.#n, this.eventMode = "static", this.addEventListener("pointermove", (e) => {
|
|
1261
|
+
this.hoverIndex = this.getItemAtY(e.getLocalPosition(this, Ue).y);
|
|
1262
|
+
}), this.addEventListener("pointerleave", () => {
|
|
1263
|
+
this.hoverIndex = -1;
|
|
1264
|
+
}), this.update();
|
|
1265
|
+
}
|
|
1266
|
+
getItemAtY(e) {
|
|
1267
|
+
if (e >= 0) {
|
|
1268
|
+
for (let t of this.#r) if (e -= t.height, e <= 2) return t.index;
|
|
1269
|
+
}
|
|
1270
|
+
return -1;
|
|
1271
|
+
}
|
|
1272
|
+
get hoverIndex() {
|
|
1273
|
+
return this.#a;
|
|
1274
|
+
}
|
|
1275
|
+
set hoverIndex(e) {
|
|
1276
|
+
this.#a !== e && (this.changeHover(this.#a, !1), this.changeHover(e, !0), this.#a = e);
|
|
1277
|
+
}
|
|
1278
|
+
changeHover(e, t) {
|
|
1279
|
+
let n = e >= 0 && this.#r[e];
|
|
1280
|
+
n && (n.hover = t);
|
|
1281
|
+
}
|
|
1282
|
+
handleSelect(e) {
|
|
1283
|
+
this.#i.dispatchEvent(Ve, e);
|
|
1284
|
+
}
|
|
1285
|
+
close() {
|
|
1286
|
+
this.visible = !1, this.#i.dispatchEvent(He);
|
|
1287
|
+
}
|
|
1288
|
+
onSelect(e) {
|
|
1289
|
+
return this.#i.handleEvent(Ve, e);
|
|
1290
|
+
}
|
|
1291
|
+
onClose(e) {
|
|
1292
|
+
return this.#i.handleEvent(He, e);
|
|
1293
|
+
}
|
|
1294
|
+
get width() {
|
|
1295
|
+
return Math.max(...this.#r.map((e) => e.labelWidth));
|
|
1296
|
+
}
|
|
1297
|
+
get height() {
|
|
1298
|
+
return this.#r.reduce((e, t) => e + t.height, 0);
|
|
1299
|
+
}
|
|
1300
|
+
update() {
|
|
1301
|
+
let e = this.width, t = this.height, n = this.#e;
|
|
1302
|
+
n.lineStyle(0, 0, 1), n.beginFill(0, .3), n.drawRoundedRect(2, 2, e + 2, t + 2, 4), n.endFill(), n.lineStyle(1, 3355443, 1), n.beginFill(16645629), n.drawRoundedRect(-1, -1, e + 2, t + 2, 4), n.endFill();
|
|
1303
|
+
let r = this.#n;
|
|
1304
|
+
r.clear(), r.beginFill(16777215), r.drawRoundedRect(-1, -1, e + 2, t + 2, 4), r.endFill();
|
|
1305
|
+
let i = 0;
|
|
1306
|
+
for (let t of this.#r) t.y = i, t.resize(e), i += t.height;
|
|
1307
|
+
}
|
|
1308
|
+
}, Ge = class {
|
|
1309
|
+
ticker;
|
|
1310
|
+
nodes = /* @__PURE__ */ new Map();
|
|
1311
|
+
connectors = /* @__PURE__ */ new Map();
|
|
1312
|
+
_pending = null;
|
|
1313
|
+
_renderer = null;
|
|
1314
|
+
menu;
|
|
1315
|
+
gui;
|
|
1316
|
+
world;
|
|
1317
|
+
root;
|
|
1318
|
+
overlay;
|
|
1319
|
+
grid;
|
|
1320
|
+
capturing;
|
|
1321
|
+
options = { viewport: {
|
|
1322
|
+
width: 1,
|
|
1323
|
+
height: 1,
|
|
1324
|
+
resolution: window.devicePixelRatio,
|
|
1325
|
+
backgroundColor: 2368548,
|
|
1326
|
+
antialias: !0,
|
|
1327
|
+
transparent: !1
|
|
1328
|
+
} };
|
|
1329
|
+
#e = t(() => this.ticker.speed = .05, 1e3);
|
|
1330
|
+
#t = (e) => this.nodes.get(e);
|
|
1331
|
+
constructor({ maxFPS: e, grid: t, gui: n = [] }) {
|
|
1332
|
+
this.ticker = new F.Ticker(), this.world = new F.Container(), this.root = new F.Container(), this.overlay = new F.Container(), this.grid = new Re(t.cellSize, t.colors), this.world.sortableChildren = !0, this.ticker.maxFPS = e, this.world.__drag_root = !0, this.gui = n, this.root.addChild(this.grid), this.root.addChild(this.world), this.root.addChild(this.overlay), this.root.addChild(...n), this.ticker.add(this.render.bind(this)), this.world.eventMode = "static", this.world.hitArea = { contains: () => !0 }, this.world.addEventListener("pointermove", (e) => {
|
|
1333
|
+
this.handlePointerMove(this.fromGlobal(e.global));
|
|
1334
|
+
}), this.world.addEventListener("pointerdown", (e) => {
|
|
1335
|
+
this.handlePointerDown(this.fromGlobal(e.global), e);
|
|
1336
|
+
}), this.fullSpeed();
|
|
1337
|
+
}
|
|
1338
|
+
fullSpeed() {
|
|
1339
|
+
this.ticker.speed = 1, this.#e();
|
|
1340
|
+
}
|
|
1341
|
+
get renderer() {
|
|
1342
|
+
if (!this._renderer) {
|
|
1343
|
+
let { viewport: e } = this.options;
|
|
1344
|
+
this._renderer = (0, F.autoDetectRenderer)({
|
|
1345
|
+
width: e.width,
|
|
1346
|
+
height: e.height,
|
|
1347
|
+
antialias: e.antialias,
|
|
1348
|
+
backgroundColor: e.backgroundColor,
|
|
1349
|
+
backgroundAlpha: +!e.transparent,
|
|
1350
|
+
resolution: e.resolution,
|
|
1351
|
+
autoDensity: !0
|
|
1352
|
+
}), this.ticker.start();
|
|
1353
|
+
}
|
|
1354
|
+
return this._renderer;
|
|
1355
|
+
}
|
|
1356
|
+
set renderer(e) {
|
|
1357
|
+
this._renderer !== e && (this._renderer && (this.ticker.stop(), this._renderer.destroy(!0)), this._renderer = e, e && this.ticker.start());
|
|
1358
|
+
}
|
|
1359
|
+
get width() {
|
|
1360
|
+
return this.renderer.width / this.options.viewport.resolution;
|
|
1361
|
+
}
|
|
1362
|
+
get height() {
|
|
1363
|
+
return this.renderer.height / this.options.viewport.resolution;
|
|
1364
|
+
}
|
|
1365
|
+
get center() {
|
|
1366
|
+
let { width: e, height: t } = this;
|
|
1367
|
+
return {
|
|
1368
|
+
x: e / 2,
|
|
1369
|
+
y: t / 2
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
get translation() {
|
|
1373
|
+
let { x: e, y: t } = this.center, { x: n, y: r } = this.world.transform.position;
|
|
1374
|
+
return {
|
|
1375
|
+
x: ~~(n - e),
|
|
1376
|
+
y: ~~(r - t)
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
fromGlobal(e) {
|
|
1380
|
+
return E(e, this.world.transform.position, -1);
|
|
1381
|
+
}
|
|
1382
|
+
fromLocal(e) {
|
|
1383
|
+
return E(E(e, this.world.transform.position, -2), this.center);
|
|
1384
|
+
}
|
|
1385
|
+
offsetPos(e, t = 1) {
|
|
1386
|
+
return E(e, this.center, t);
|
|
1387
|
+
}
|
|
1388
|
+
translate(e) {
|
|
1389
|
+
this.world.transform.position.copyFrom(this.offsetPos(e)), this.overlay.transform.position.copyFrom(this.offsetPos(e)), this.updateViewport();
|
|
1390
|
+
}
|
|
1391
|
+
closeMenu() {
|
|
1392
|
+
this.menu?.close();
|
|
1393
|
+
}
|
|
1394
|
+
showMenu(e, t, n) {
|
|
1395
|
+
this.closeMenu();
|
|
1396
|
+
let r = e.getMenu(t, n);
|
|
1397
|
+
if (r) {
|
|
1398
|
+
let t = this.overlay.addChild(Object.assign(new We(r), n));
|
|
1399
|
+
return t.onSelect((t) => {
|
|
1400
|
+
!1 !== e.handleMenu(t.data) && this.closeMenu();
|
|
1401
|
+
}), t.onClose(() => {
|
|
1402
|
+
this.menu === t && (this.menu = null), t.removeFromParent();
|
|
1403
|
+
}), this.menu = t;
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
addNode(e) {
|
|
1407
|
+
if (this.#t(e.id)) return;
|
|
1408
|
+
let t = new Pe(e, this.#t);
|
|
1409
|
+
t.onMove((t) => {
|
|
1410
|
+
this._pending || this.moveNodeTo(e.id, t);
|
|
1411
|
+
}), t.onCapture((t) => {
|
|
1412
|
+
if (t) {
|
|
1413
|
+
if (this.capturing = e, !this._pending) {
|
|
1414
|
+
this.moveToForeground(e);
|
|
1415
|
+
return;
|
|
1416
|
+
}
|
|
1417
|
+
} else this.capturing = void 0;
|
|
1418
|
+
}), t.onContext(({ event: t, tag: n }) => this.showMenu(e, n, this.fromGlobal(t.global))), t.onPortClick((e) => {
|
|
1419
|
+
if (!(e.remove && !e.point.nodes.length)) {
|
|
1420
|
+
if (this.pending) {
|
|
1421
|
+
let t = this.pending.connect(e);
|
|
1422
|
+
t && (this.connectNodes(t), this.pending = null);
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
this.pending = new Oe(e);
|
|
1426
|
+
}
|
|
1427
|
+
}), t.onPortHover((e) => this.pending?.hoverPort(e)), t.onConnectorsUpdate(({ add: e, remove: t }) => {
|
|
1428
|
+
if (e) for (let { uid: t, connector: n } of e) this.addConnector(t, n);
|
|
1429
|
+
if (t) for (let e of t) this.removeConnector(e);
|
|
1430
|
+
}), t.onDispose(() => {
|
|
1431
|
+
this.nodes.delete(e.id);
|
|
1432
|
+
}), this.nodes.set(e.id, t), this.world.addChild(t.renderable);
|
|
1433
|
+
}
|
|
1434
|
+
removeNode(e) {
|
|
1435
|
+
let t = this.nodes.get(e.id);
|
|
1436
|
+
t && t.dispose();
|
|
1437
|
+
}
|
|
1438
|
+
clear() {
|
|
1439
|
+
let e = [...this.nodes.values()];
|
|
1440
|
+
this.connectors.clear(), this.nodes.clear(), this.world.removeChildren();
|
|
1441
|
+
for (let t of e) t.dispose();
|
|
1442
|
+
}
|
|
1443
|
+
get pending() {
|
|
1444
|
+
return this._pending;
|
|
1445
|
+
}
|
|
1446
|
+
set pending(e) {
|
|
1447
|
+
!e && this._pending && this._pending.removeFromParent(), this._pending = e, e && this.overlay.addChild(e);
|
|
1448
|
+
}
|
|
1449
|
+
handlePointerMove(e) {
|
|
1450
|
+
this.fullSpeed(), !(this.capturing || !this.pending) && this.pending.flail(e);
|
|
1451
|
+
}
|
|
1452
|
+
handlePointerDown(e, t) {
|
|
1453
|
+
if (this.pending && !t.shiftKey && (this.pending = null), this.closeMenu(), t.buttons & 2) {
|
|
1454
|
+
for (let n of this.gui) if (this.showMenu(n, void 0, e)) {
|
|
1455
|
+
t.stopPropagation(), t.preventDefault();
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
connectNodes({ connect: e, output: { port: t, parent: n }, input: { port: r, parent: i } }) {
|
|
1461
|
+
let a = this.#t(n), o = this.#t(i);
|
|
1462
|
+
a.data.connect({
|
|
1463
|
+
connect: e,
|
|
1464
|
+
input: !1,
|
|
1465
|
+
port: t,
|
|
1466
|
+
nodes: [{
|
|
1467
|
+
node: o.data,
|
|
1468
|
+
port: r
|
|
1469
|
+
}]
|
|
1470
|
+
}), o.placeConnectors();
|
|
1471
|
+
}
|
|
1472
|
+
buildConnectors() {
|
|
1473
|
+
for (let e of this.nodes.values()) e.placeConnectors();
|
|
1474
|
+
}
|
|
1475
|
+
addConnector(e, t) {
|
|
1476
|
+
if (this.connectors.has(e)) return;
|
|
1477
|
+
let n = t;
|
|
1478
|
+
n.zIndex++, this.world.addChild(n), this.connectors.set(e, n);
|
|
1479
|
+
}
|
|
1480
|
+
removeConnector(e) {
|
|
1481
|
+
let t = this.connectors.get(e);
|
|
1482
|
+
t && (this.connectors.delete(e), this.world.removeChild(t));
|
|
1483
|
+
}
|
|
1484
|
+
moveToForeground(e) {
|
|
1485
|
+
let t = this.nodes.get(e.id);
|
|
1486
|
+
t && this.world.setChildIndex(t.renderable, this.world.children.length - 1);
|
|
1487
|
+
}
|
|
1488
|
+
hitTest({ x: e, y: t }) {
|
|
1489
|
+
let n = {
|
|
1490
|
+
x: e - this.translation.x,
|
|
1491
|
+
y: t - this.translation.y
|
|
1492
|
+
};
|
|
1493
|
+
for (let e of this.nodes.values()) if (e.hitTest(n)) return {
|
|
1494
|
+
node: e.data,
|
|
1495
|
+
x: e.renderable.x,
|
|
1496
|
+
y: e.renderable.y,
|
|
1497
|
+
width: e.width,
|
|
1498
|
+
height: e.height
|
|
1499
|
+
};
|
|
1500
|
+
}
|
|
1501
|
+
getNodePos(e) {
|
|
1502
|
+
return e.position;
|
|
1503
|
+
}
|
|
1504
|
+
moveNodeTo(e, t) {
|
|
1505
|
+
let n = this.nodes.get(e);
|
|
1506
|
+
n && n.move(t);
|
|
1507
|
+
}
|
|
1508
|
+
layout() {
|
|
1509
|
+
this.buildConnectors();
|
|
1510
|
+
}
|
|
1511
|
+
mount(e, t) {
|
|
1512
|
+
return this.options = t, this.renderer = null, this.renderer.resize(t.viewport.width, t.viewport.height), this.translate({
|
|
1513
|
+
x: 0,
|
|
1514
|
+
y: 0
|
|
1515
|
+
}), e.appendChild(this.renderer.view), () => {
|
|
1516
|
+
this.unmount();
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
unmount() {
|
|
1520
|
+
this.renderer = null;
|
|
1521
|
+
}
|
|
1522
|
+
resize(e, t) {
|
|
1523
|
+
this.renderer.resize(e, t), this.updateViewport();
|
|
1524
|
+
}
|
|
1525
|
+
updateViewport() {
|
|
1526
|
+
let { width: e, height: t, translation: { x: n, y: r } } = this;
|
|
1527
|
+
e && t && this.grid.viewport(new F.Rectangle(n - e / 2, r - t / 2, e, t));
|
|
1528
|
+
}
|
|
1529
|
+
render() {
|
|
1530
|
+
this.renderer?.render(this.root);
|
|
1531
|
+
}
|
|
1532
|
+
update() {
|
|
1533
|
+
this.ticker.update();
|
|
1534
|
+
}
|
|
1535
|
+
}, Ke = "\nPort:\n LMB - start connecting\n LMB + (Meta | Ctrl) - start disconnecting\nCanvas:\n LMB + Shift - drag while connecting/disconnecting", $ = class e extends F.Container {
|
|
1536
|
+
static text = H.factory("GUIText", {
|
|
1537
|
+
fontSize: 16,
|
|
1538
|
+
align: "left",
|
|
1539
|
+
fill: "#efefef",
|
|
1540
|
+
dropShadow: !0,
|
|
1541
|
+
dropShadowDistance: 1
|
|
1542
|
+
}, { chars: [
|
|
1543
|
+
["a", "z"],
|
|
1544
|
+
["A", "Z"],
|
|
1545
|
+
["0", "9"],
|
|
1546
|
+
" \n+-|()/:;."
|
|
1547
|
+
] });
|
|
1548
|
+
static makeText = (e) => this.text(e, { fontSize: 8 });
|
|
1549
|
+
#e;
|
|
1550
|
+
#t = new F.Text("ℹ️", {
|
|
1551
|
+
fontSize: 8,
|
|
1552
|
+
lineHeight: 14
|
|
1553
|
+
});
|
|
1554
|
+
#n = e.makeText("");
|
|
1555
|
+
#r = !1;
|
|
1556
|
+
#i = "";
|
|
1557
|
+
#a;
|
|
1558
|
+
constructor(e, t = Ke) {
|
|
1559
|
+
super(), this.#a = t, this.addChild(this.#t), this.addChild(this.#n), this.#t.eventMode = "static", this.#t.addEventListener("pointerdown", () => this.legend = !this.legend), this.#n.x = 8, this.#n.y = 8, this.#e = e;
|
|
1560
|
+
}
|
|
1561
|
+
getMenu(e, t) {
|
|
1562
|
+
return this.#e.getMenu(e, t);
|
|
1563
|
+
}
|
|
1564
|
+
handleMenu(e) {
|
|
1565
|
+
return this.#e.handleMenu(e);
|
|
1566
|
+
}
|
|
1567
|
+
get legendText() {
|
|
1568
|
+
return this.#a;
|
|
1569
|
+
}
|
|
1570
|
+
set legendText(e) {
|
|
1571
|
+
this.#a = e;
|
|
1572
|
+
}
|
|
1573
|
+
set text(e) {
|
|
1574
|
+
this.#i = e, this.#n.text = e + (this.#r ? this.#a : "");
|
|
1575
|
+
}
|
|
1576
|
+
get legend() {
|
|
1577
|
+
return this.#r;
|
|
1578
|
+
}
|
|
1579
|
+
set legend(e) {
|
|
1580
|
+
this.#r = e, this.#n.text = this.#i + (this.#r ? this.#a : "");
|
|
1581
|
+
}
|
|
1582
|
+
}, qe = class extends F.Container {
|
|
1583
|
+
first;
|
|
1584
|
+
constructor(e, ...t) {
|
|
1585
|
+
super(), this.first = e, this.addChild(e, ...t);
|
|
1586
|
+
}
|
|
1587
|
+
hotSwap(...e) {
|
|
1588
|
+
this.removeChildren(), this.addChild(this.first, ...e);
|
|
1589
|
+
}
|
|
1590
|
+
}, Je = class extends F.Graphics {
|
|
1591
|
+
#e;
|
|
1592
|
+
#t;
|
|
1593
|
+
constructor(e) {
|
|
1594
|
+
super(), this.#e = e;
|
|
1595
|
+
}
|
|
1596
|
+
get active() {
|
|
1597
|
+
return !!this.#t;
|
|
1598
|
+
}
|
|
1599
|
+
set active(e) {
|
|
1600
|
+
if (e !== !!this.#t && (this.#t = e, this.clear(), e)) {
|
|
1601
|
+
let { lineSize: e, color: t, x: n = 0, y: r = 0, width: i, height: a, radius: o } = this.#e;
|
|
1602
|
+
this.lineStyle({
|
|
1603
|
+
width: e,
|
|
1604
|
+
color: t
|
|
1605
|
+
}).drawRoundedRect(n - 2, r - 2, i + 4, a + 4, o);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
T(/* @__PURE__ */ ne({
|
|
1610
|
+
Batch: () => I,
|
|
1611
|
+
E_CONNECTORS_UPDATE: () => Y,
|
|
1612
|
+
E_NODE_CONTEXT: () => J,
|
|
1613
|
+
LANE_HEIGHT: () => 16,
|
|
1614
|
+
LANE_WIDTH: () => 16,
|
|
1615
|
+
NODE_WIDTH: () => 64,
|
|
1616
|
+
PIXIGUI: () => $,
|
|
1617
|
+
PIXINode: () => Pe,
|
|
1618
|
+
PIXIOutlined: () => Je,
|
|
1619
|
+
PIXIRenderer: () => Ge,
|
|
1620
|
+
PIXIStacked: () => qe,
|
|
1621
|
+
PORT_SIZE: () => 8,
|
|
1622
|
+
RectSpinner: () => z
|
|
1623
|
+
}), F);
|
|
1624
|
+
//#endregion
|
|
1625
|
+
//#region src/graph/GraphAdapter.ts
|
|
1626
|
+
var Ye = class extends I {
|
|
1627
|
+
renderer;
|
|
1628
|
+
nodes = [];
|
|
1629
|
+
constructor(e) {
|
|
1630
|
+
super(), this.renderer = new Ge(e), this.and(() => this.renderer.render());
|
|
1631
|
+
}
|
|
1632
|
+
[Symbol.iterator]() {
|
|
1633
|
+
return this.nodes[Symbol.iterator]();
|
|
1634
|
+
}
|
|
1635
|
+
clear() {
|
|
1636
|
+
this.renderer.clear(), this.nodes.splice(0);
|
|
1637
|
+
}
|
|
1638
|
+
update() {
|
|
1639
|
+
this.renderer.update();
|
|
1640
|
+
}
|
|
1641
|
+
moveToForeground(e) {
|
|
1642
|
+
this.renderer.moveToForeground(e);
|
|
1643
|
+
}
|
|
1644
|
+
hitTest(e) {
|
|
1645
|
+
return this.renderer.hitTest(e);
|
|
1646
|
+
}
|
|
1647
|
+
getNodePos(e) {
|
|
1648
|
+
return this.renderer.getNodePos(e);
|
|
1649
|
+
}
|
|
1650
|
+
moveNodeTo(e, t) {
|
|
1651
|
+
e.position = t;
|
|
1652
|
+
}
|
|
1653
|
+
addNode(e) {
|
|
1654
|
+
return this.nodes.indexOf(e) < 0 && (this.nodes.push(e), this.renderer.addNode(e)), e;
|
|
1655
|
+
}
|
|
1656
|
+
removeNode(e) {
|
|
1657
|
+
let t = this.nodes.indexOf(e);
|
|
1658
|
+
return t >= 0 && (this.nodes.splice(t, 1), this.renderer.removeNode(e)), e;
|
|
1659
|
+
}
|
|
1660
|
+
get capturing() {
|
|
1661
|
+
return this.renderer.capturing;
|
|
1662
|
+
}
|
|
1663
|
+
releaseNode() {
|
|
1664
|
+
this.renderer.capturing = void 0;
|
|
1665
|
+
}
|
|
1666
|
+
get translation() {
|
|
1667
|
+
return this.renderer.translation;
|
|
1668
|
+
}
|
|
1669
|
+
translate(e) {
|
|
1670
|
+
this.renderer.translate(e);
|
|
1671
|
+
}
|
|
1672
|
+
resize(e, t) {
|
|
1673
|
+
this.renderer.resize(e, t);
|
|
1674
|
+
}
|
|
1675
|
+
fromGlobal(e) {
|
|
1676
|
+
return this.renderer.fromGlobal(e);
|
|
1677
|
+
}
|
|
1678
|
+
fromLocal(e) {
|
|
1679
|
+
return this.renderer.fromLocal(e);
|
|
1680
|
+
}
|
|
1681
|
+
mount(e, t) {
|
|
1682
|
+
return this.renderer.mount(e, t);
|
|
1683
|
+
}
|
|
1684
|
+
unmount() {
|
|
1685
|
+
this.renderer.unmount();
|
|
1686
|
+
}
|
|
1687
|
+
layout() {
|
|
1688
|
+
this.renderer.layout();
|
|
1689
|
+
}
|
|
1690
|
+
};
|
|
1691
|
+
//#endregion
|
|
1692
|
+
//#region src/graph/NodeGroups.tsx
|
|
1693
|
+
function Xe(e, t) {
|
|
1694
|
+
let n = [];
|
|
1695
|
+
for (let r of e) {
|
|
1696
|
+
let e = t(r);
|
|
1697
|
+
e && n.push(e);
|
|
1698
|
+
}
|
|
1699
|
+
return n.sort((e, t) => e.label.localeCompare(t.label)).concat([{
|
|
1700
|
+
value: "all",
|
|
1701
|
+
ids: e.map(({ id: e }) => e),
|
|
1702
|
+
label: `All nodes (${e.length})`
|
|
1703
|
+
}]);
|
|
1704
|
+
}
|
|
1705
|
+
var Ze = (e, t) => {
|
|
1706
|
+
let n = e.length;
|
|
1707
|
+
if (n !== t.length) return !1;
|
|
1708
|
+
for (let r = 0; r < n; r++) if (e[r] !== t[r]) return !1;
|
|
1709
|
+
return !0;
|
|
1710
|
+
}, Qe = (e) => {
|
|
1711
|
+
let t = String(e);
|
|
1712
|
+
return (e) => String(e.value) === t;
|
|
1713
|
+
}, $e = y(function({ items: e, resolver: t, onSelect: n, children: r, ...i }) {
|
|
1714
|
+
let o = c(() => Xe(e, t), [e, t]), [l, d] = u(o.find(({ value: e }) => e === "all")), f = String(l.value), p = h(({ target: { value: e } }) => {
|
|
1715
|
+
let t = o.find(Qe(e));
|
|
1716
|
+
t && d(t);
|
|
1717
|
+
});
|
|
1718
|
+
return a(() => void n(l), [l, n]), s(() => {
|
|
1719
|
+
let e = o.find(Qe(l.value));
|
|
1720
|
+
if (e) {
|
|
1721
|
+
if (e === l) return;
|
|
1722
|
+
(e.label !== l.label || !Ze(e.ids, l.ids)) && d(e);
|
|
1723
|
+
} else d(o[0]);
|
|
1724
|
+
}, [o, l]), /* @__PURE__ */ x("select", {
|
|
1725
|
+
multiple: !0,
|
|
1726
|
+
size: o.length,
|
|
1727
|
+
onChange: p,
|
|
1728
|
+
...i,
|
|
1729
|
+
children: [r, o.map(({ value: e, label: t }) => /* @__PURE__ */ b("option", {
|
|
1730
|
+
value: String(e),
|
|
1731
|
+
selected: String(e) === f,
|
|
1732
|
+
children: t
|
|
1733
|
+
}, String(e)))]
|
|
1734
|
+
});
|
|
1735
|
+
}), et = i(y(({ handlers: e, onResize: t, ...n }, r) => {
|
|
1736
|
+
let [i, s] = g(), { bind: c, reset: l } = P(e);
|
|
1737
|
+
return o(r, () => ({
|
|
1738
|
+
reset: l,
|
|
1739
|
+
get element() {
|
|
1740
|
+
return c.ref.current;
|
|
1741
|
+
}
|
|
1742
|
+
})), a(() => {
|
|
1743
|
+
i && t({
|
|
1744
|
+
width: ~~i.width,
|
|
1745
|
+
height: ~~i.height
|
|
1746
|
+
});
|
|
1747
|
+
}, [i, t]), /* @__PURE__ */ b("div", {
|
|
1748
|
+
ref: s,
|
|
1749
|
+
style: tt.root,
|
|
1750
|
+
children: /* @__PURE__ */ b("div", {
|
|
1751
|
+
style: tt.root,
|
|
1752
|
+
...c,
|
|
1753
|
+
...n
|
|
1754
|
+
})
|
|
1755
|
+
});
|
|
1756
|
+
})), tt = d.of({ root: {
|
|
1757
|
+
flex: 1,
|
|
1758
|
+
display: "flex",
|
|
1759
|
+
minWidth: 0,
|
|
1760
|
+
minHeight: 0
|
|
1761
|
+
} }), nt = y(({ onSelect: e, ...t }) => /* @__PURE__ */ b($e, {
|
|
1762
|
+
resolver: rt,
|
|
1763
|
+
onSelect: h((t) => e(t.ids)),
|
|
1764
|
+
...t
|
|
1765
|
+
})), rt = (e) => {
|
|
1766
|
+
if (!e.item.isolator) return;
|
|
1767
|
+
let t = [e.id];
|
|
1768
|
+
return {
|
|
1769
|
+
value: e.id,
|
|
1770
|
+
label: e.title,
|
|
1771
|
+
ids: t
|
|
1772
|
+
};
|
|
1773
|
+
}, it = (e, t, { onEdit: n, onConnect: r, onMove: i, onAddPort: a, onDisconnectPort: o, onDeletePort: s, onDelete: c, onSelect: l, onContextMenu: u } = {}) => ({
|
|
1774
|
+
canvas: {
|
|
1775
|
+
onSelectNode: (t, n) => l?.(t?.item || null, e.toData(n)),
|
|
1776
|
+
onContextMenu: (t, n) => u?.(t?.item || null, e.toData(n))
|
|
1777
|
+
},
|
|
1778
|
+
loader: {
|
|
1779
|
+
onEdit: (e) => n?.(e.item),
|
|
1780
|
+
onConnect: async ({ connect: e, input: n, source: i, target: a }) => {
|
|
1781
|
+
if (r) return r({
|
|
1782
|
+
connect: e,
|
|
1783
|
+
input: n,
|
|
1784
|
+
source: {
|
|
1785
|
+
node: t.get(i.node).item,
|
|
1786
|
+
port: i.port
|
|
1787
|
+
},
|
|
1788
|
+
target: a?.map(({ node: e, port: n }) => {
|
|
1789
|
+
let r = t.get(e);
|
|
1790
|
+
if (r) return {
|
|
1791
|
+
node: r.item,
|
|
1792
|
+
port: n
|
|
1793
|
+
};
|
|
1794
|
+
}).filter((e) => !!e)
|
|
1795
|
+
});
|
|
1796
|
+
},
|
|
1797
|
+
onMove: async (t, n) => i?.(t.item, e.toData(n)),
|
|
1798
|
+
onAddPort: async (e, t) => a?.(e.item, t),
|
|
1799
|
+
onDisconnectPort: async (e, t) => o?.(e.item, t),
|
|
1800
|
+
onDeletePort: async (e, t) => s?.(e.item, t),
|
|
1801
|
+
onDelete: async (e) => c?.(e.item)
|
|
1802
|
+
}
|
|
1803
|
+
}), at = {
|
|
1804
|
+
x: 0,
|
|
1805
|
+
y: 0
|
|
1806
|
+
}, ot = y(function({ innerRef: e, nodes: t, subset: n, coordinator: r, menu: i, onSelectNode: u, onContextMenu: d, ...f }) {
|
|
1807
|
+
let p = l(at), m = l(null), g = c(() => new $(i), [i]), _ = c(() => new Ye({
|
|
1808
|
+
maxFPS: 120,
|
|
1809
|
+
grid: {
|
|
1810
|
+
cellSize: r.gridSize,
|
|
1811
|
+
colors: [
|
|
1812
|
+
2236962,
|
|
1813
|
+
3355443,
|
|
1814
|
+
6710886,
|
|
1815
|
+
10066329
|
|
1816
|
+
]
|
|
1817
|
+
},
|
|
1818
|
+
gui: [g]
|
|
1819
|
+
}), [r]);
|
|
1820
|
+
o(e, () => ({
|
|
1821
|
+
graph: _,
|
|
1822
|
+
get element() {
|
|
1823
|
+
return m.current?.element;
|
|
1824
|
+
}
|
|
1825
|
+
}));
|
|
1826
|
+
let v = h(({ width: e, height: t }) => _.resize(e, t)), y = h(() => {
|
|
1827
|
+
let { x: e, y: t } = r.toData(_.translation), { x: n, y: i } = r.toData(p.current);
|
|
1828
|
+
g.text = `Pos: ${-(e - 1)} x ${-(t - 1)}\nCursor: ${~~(n - 1)} x ${~~(i - 1)}`;
|
|
1829
|
+
}), x = h((e) => {
|
|
1830
|
+
p.current = _.fromLocal(e), y();
|
|
1831
|
+
}), S = h((e) => {
|
|
1832
|
+
p.current = _.fromLocal(e), _.releaseNode(), y();
|
|
1833
|
+
}), C = h((e, t) => {
|
|
1834
|
+
if (x(e), _.capturing && !t?.shiftKey && u(null, r.toData(p.current)), !1 === u(_.capturing || null, r.toData(p.current))) return _.releaseNode(), !1;
|
|
1835
|
+
}), w = h((e) => {
|
|
1836
|
+
_.capturing || (_.translate(e), y());
|
|
1837
|
+
}), ee = h((e) => {
|
|
1838
|
+
if (!1 === C(e)) return !1;
|
|
1839
|
+
if (!1 === d(_.capturing || null, r.toData(p.current))) return _.releaseNode(), !1;
|
|
1840
|
+
}), te = c(() => ({
|
|
1841
|
+
get position() {
|
|
1842
|
+
return _.translation;
|
|
1843
|
+
},
|
|
1844
|
+
onDrag: w,
|
|
1845
|
+
onPointer: x,
|
|
1846
|
+
onClick: C,
|
|
1847
|
+
onUp: S,
|
|
1848
|
+
onContext: ee
|
|
1849
|
+
}), [_]);
|
|
1850
|
+
return a(() => {
|
|
1851
|
+
if (!m.current) return;
|
|
1852
|
+
let e = n || t.map(({ id: e }) => e);
|
|
1853
|
+
_.batch(() => {
|
|
1854
|
+
for (let t of _) e.includes(t.id) || _.removeNode(t);
|
|
1855
|
+
for (let n of t) e.includes(n.id) && (_.addNode(n), _.moveNodeTo(n, n.position));
|
|
1856
|
+
_.layout();
|
|
1857
|
+
});
|
|
1858
|
+
}, [n, t]), s(() => {
|
|
1859
|
+
let e = m.current?.element;
|
|
1860
|
+
if (e) return _.mount(e, { viewport: {
|
|
1861
|
+
width: e.clientWidth,
|
|
1862
|
+
height: e.clientHeight,
|
|
1863
|
+
resolution: window.devicePixelRatio,
|
|
1864
|
+
backgroundColor: 1315860,
|
|
1865
|
+
antialias: !0,
|
|
1866
|
+
transparent: !1
|
|
1867
|
+
} });
|
|
1868
|
+
}, [_]), /* @__PURE__ */ b(et, {
|
|
1869
|
+
ref: m,
|
|
1870
|
+
handlers: te,
|
|
1871
|
+
onResize: v,
|
|
1872
|
+
...f
|
|
1873
|
+
});
|
|
1874
|
+
}), st = (e, { onEdit: t, onMove: n, onConnect: r, onDelete: i, onAddPort: a, onDisconnectPort: o, onDeletePort: s }) => {
|
|
1875
|
+
e.onConnect(r), e.onMove((t) => n(e, t)), e.onEditAction(() => t(e)), e.onDeleteAction(() => i(e)), e.onAddPortAction((t) => a(e, t)), e.onDisconnectPortAction(({ port: t }) => o(e, t)), e.onDeletePortAction(({ port: t }) => s(e, t));
|
|
1876
|
+
}, ct = (e, t, { added: n, removed: r }) => {
|
|
1877
|
+
if (n.length) {
|
|
1878
|
+
let r = n.reduce((e, t) => (e[t.id] = t, e), {}), i = (t) => r[t] || e.find((e) => e.id === t);
|
|
1879
|
+
for (let e of n) {
|
|
1880
|
+
let t = e.item.ports;
|
|
1881
|
+
if (!t.length) continue;
|
|
1882
|
+
let n = e.item.id;
|
|
1883
|
+
for (let { id: r, to: a, port: o, input: s } of t) {
|
|
1884
|
+
if (!a) continue;
|
|
1885
|
+
let t = i(a.id);
|
|
1886
|
+
if (t) {
|
|
1887
|
+
let i = t.getItemPort(({ to: e, name: t }) => e?.id === n && t === o);
|
|
1888
|
+
i && e.connect({
|
|
1889
|
+
connect: !0,
|
|
1890
|
+
input: s,
|
|
1891
|
+
port: r,
|
|
1892
|
+
nodes: [{
|
|
1893
|
+
node: t,
|
|
1894
|
+
port: i.id
|
|
1895
|
+
}]
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
if (t) for (let e of n) st(e, t);
|
|
1901
|
+
e.add(n);
|
|
1902
|
+
}
|
|
1903
|
+
if (r.length) for (let t of r) e.remove(t);
|
|
1904
|
+
}, lt = () => [{
|
|
1905
|
+
label: "Add node",
|
|
1906
|
+
items: [{
|
|
1907
|
+
label: "+ Call",
|
|
1908
|
+
data: {
|
|
1909
|
+
title: "Call",
|
|
1910
|
+
args: {
|
|
1911
|
+
ports: JSON.stringify({
|
|
1912
|
+
in: ["input"],
|
|
1913
|
+
out: ["output"]
|
|
1914
|
+
}),
|
|
1915
|
+
system: "You are helpful assistant",
|
|
1916
|
+
instructions: "Summarize following input:\n{|input|}",
|
|
1917
|
+
llm: "Result:\n"
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
}]
|
|
1921
|
+
}, {
|
|
1922
|
+
label: "Add specific node",
|
|
1923
|
+
items: [
|
|
1924
|
+
{
|
|
1925
|
+
label: "+ Splitter (2)",
|
|
1926
|
+
data: {
|
|
1927
|
+
title: "Splitter",
|
|
1928
|
+
args: {
|
|
1929
|
+
ports: JSON.stringify({
|
|
1930
|
+
in: ["i"],
|
|
1931
|
+
out: ["o1", "o2"]
|
|
1932
|
+
}),
|
|
1933
|
+
js: "const value = get($i);\nset($o1, value);\nset($o2, value);\n"
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
},
|
|
1937
|
+
{
|
|
1938
|
+
label: "",
|
|
1939
|
+
separator: !0
|
|
1940
|
+
},
|
|
1941
|
+
{
|
|
1942
|
+
label: "+ JSON → Ports",
|
|
1943
|
+
data: {
|
|
1944
|
+
title: "From JSON",
|
|
1945
|
+
args: {
|
|
1946
|
+
ports: JSON.stringify({
|
|
1947
|
+
in: ["json"],
|
|
1948
|
+
out: [
|
|
1949
|
+
"o1",
|
|
1950
|
+
"o2",
|
|
1951
|
+
"o3"
|
|
1952
|
+
]
|
|
1953
|
+
}),
|
|
1954
|
+
js: "const value = get($json);\ntry {\n set(JSON.parse(value));\n} catch (e) {\nset({}); // default\n}\n"
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
]
|
|
1959
|
+
}], ut = (e, t) => ({
|
|
1960
|
+
getMenu(t, n) {
|
|
1961
|
+
let r = {
|
|
1962
|
+
action: "add",
|
|
1963
|
+
...e.toData(n)
|
|
1964
|
+
};
|
|
1965
|
+
return { items: lt().map(({ label: e, items: t }) => [{
|
|
1966
|
+
label: e,
|
|
1967
|
+
group: !0
|
|
1968
|
+
}, ...t.map(({ label: e, data: t, ...n }) => ({
|
|
1969
|
+
label: e,
|
|
1970
|
+
data: t && {
|
|
1971
|
+
...r,
|
|
1972
|
+
...t
|
|
1973
|
+
},
|
|
1974
|
+
...n
|
|
1975
|
+
}))]).flat() };
|
|
1976
|
+
},
|
|
1977
|
+
handleMenu({ action: e, ...n }) {
|
|
1978
|
+
switch (e) {
|
|
1979
|
+
case "add":
|
|
1980
|
+
t?.(n);
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
}), dt = (e, t) => {
|
|
1985
|
+
let n = l([]);
|
|
1986
|
+
m(() => {
|
|
1987
|
+
let i = t?.filter((e) => !n.current.some(r(e.id))), a = n.current.filter((e) => !t?.some(r(e.id)));
|
|
1988
|
+
if (a) for (let { id: t } of a) e.find(r(t))?.setSelected(!1);
|
|
1989
|
+
if (i) for (let { id: t } of i) e.find(r(t))?.setSelected(!0);
|
|
1990
|
+
n.current = t || [];
|
|
1991
|
+
}, [t, e]);
|
|
1992
|
+
}, ft = (e) => e.startsWith("channel_"), pt = (e) => ft(e) ? e.slice(8) : "", mt = (e) => ({ id: t, name: n, input: r, to: i, port: a }) => {
|
|
1993
|
+
let o = pt(n);
|
|
1994
|
+
o && (n = `${r ? "> " : ""}@${o}${r ? "" : " >"}`);
|
|
1995
|
+
let s = [];
|
|
1996
|
+
if (i) {
|
|
1997
|
+
let t = e(i.id)?.ports.find(({ name: e }) => e === a);
|
|
1998
|
+
t && s.push({
|
|
1999
|
+
node: i.id,
|
|
2000
|
+
port: t.id
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
return {
|
|
2004
|
+
port: t,
|
|
2005
|
+
name: n,
|
|
2006
|
+
nodes: s
|
|
2007
|
+
};
|
|
2008
|
+
}, ht = /* @__PURE__ */ function(e) {
|
|
2009
|
+
return e[e.Idle = 1] = "Idle", e[e.Processing = 2] = "Processing", e[e.Done = 4] = "Done", e[e.Error = 8] = "Error", e[e.Selected = 16] = "Selected", e;
|
|
2010
|
+
}({}), gt = /* @__PURE__ */ function(e) {
|
|
2011
|
+
return e[e.EDIT_NODE = 1] = "EDIT_NODE", e[e.ADD_PORT = 2] = "ADD_PORT", e[e.DISCONNECT_PORT = 3] = "DISCONNECT_PORT", e[e.DELETE_PORT = 4] = "DELETE_PORT", e[e.DELETE_NODE = 5] = "DELETE_NODE", e;
|
|
2012
|
+
}({}), _t = class extends ce {
|
|
2013
|
+
#e;
|
|
2014
|
+
#t;
|
|
2015
|
+
constructor({ finder: e, item: t, coordinator: n, toTitle: r }) {
|
|
2016
|
+
super({
|
|
2017
|
+
coordinator: n,
|
|
2018
|
+
item: t,
|
|
2019
|
+
status: 1,
|
|
2020
|
+
progress: 0,
|
|
2021
|
+
id: t.id,
|
|
2022
|
+
title: r(t),
|
|
2023
|
+
inputs: t.ports.filter(({ input: e }) => !!e).map(mt(e)),
|
|
2024
|
+
outputs: t.ports.filter(({ input: e }) => !e).map(mt(e))
|
|
2025
|
+
}), this.position = this.coordinator.toGraph(t);
|
|
2026
|
+
}
|
|
2027
|
+
dispose() {
|
|
2028
|
+
super.dispose(), this.#t &&= (this.#t.destroy({}), void 0), this.#e &&= (this.#e.destroy({}), void 0);
|
|
2029
|
+
}
|
|
2030
|
+
getMenu(e) {
|
|
2031
|
+
switch (e?.type) {
|
|
2032
|
+
case "node": return { items: [
|
|
2033
|
+
{
|
|
2034
|
+
label: this.title,
|
|
2035
|
+
group: !0
|
|
2036
|
+
},
|
|
2037
|
+
{
|
|
2038
|
+
label: "Edit",
|
|
2039
|
+
data: { action: 1 }
|
|
2040
|
+
},
|
|
2041
|
+
{
|
|
2042
|
+
label: "",
|
|
2043
|
+
separator: !0
|
|
2044
|
+
},
|
|
2045
|
+
{
|
|
2046
|
+
label: "Add input port",
|
|
2047
|
+
data: {
|
|
2048
|
+
action: 2,
|
|
2049
|
+
input: !0
|
|
2050
|
+
}
|
|
2051
|
+
},
|
|
2052
|
+
{
|
|
2053
|
+
label: "Add output port",
|
|
2054
|
+
data: {
|
|
2055
|
+
action: 2,
|
|
2056
|
+
input: !1
|
|
2057
|
+
}
|
|
2058
|
+
},
|
|
2059
|
+
{
|
|
2060
|
+
label: "",
|
|
2061
|
+
separator: !0
|
|
2062
|
+
},
|
|
2063
|
+
{
|
|
2064
|
+
label: "Delete node",
|
|
2065
|
+
data: { action: 5 }
|
|
2066
|
+
}
|
|
2067
|
+
] };
|
|
2068
|
+
case "port":
|
|
2069
|
+
let t = this.inputs.find((t) => t.port === e.id), n = this.outputs.find((t) => t.port === e.id), r = t || n, i = !!(r && r.nodes.length);
|
|
2070
|
+
return { items: [
|
|
2071
|
+
{
|
|
2072
|
+
label: `Port "${r?.name || "<?>"}"`,
|
|
2073
|
+
group: !0
|
|
2074
|
+
},
|
|
2075
|
+
{
|
|
2076
|
+
label: "Disconnect",
|
|
2077
|
+
disabled: !i,
|
|
2078
|
+
data: {
|
|
2079
|
+
action: 3,
|
|
2080
|
+
port: r
|
|
2081
|
+
}
|
|
2082
|
+
},
|
|
2083
|
+
{
|
|
2084
|
+
label: "",
|
|
2085
|
+
separator: !0
|
|
2086
|
+
},
|
|
2087
|
+
{
|
|
2088
|
+
label: "Delete",
|
|
2089
|
+
disabled: !r,
|
|
2090
|
+
data: {
|
|
2091
|
+
action: 4,
|
|
2092
|
+
port: r
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
] };
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
handleMenu(e) {
|
|
2099
|
+
switch (e?.action) {
|
|
2100
|
+
case 2: return this.dispatchEvent(e?.action, e.input);
|
|
2101
|
+
case 3:
|
|
2102
|
+
case 4: return e.port && this.dispatchEvent(e?.action, e.port);
|
|
2103
|
+
case 1:
|
|
2104
|
+
case 5: return this.dispatchEvent(e?.action, this.id);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
onAddPortAction(e) {
|
|
2108
|
+
return this.handleEvent(2, e);
|
|
2109
|
+
}
|
|
2110
|
+
onDisconnectPortAction(e) {
|
|
2111
|
+
return this.handleEvent(3, e);
|
|
2112
|
+
}
|
|
2113
|
+
onDeletePortAction(e) {
|
|
2114
|
+
return this.handleEvent(4, e);
|
|
2115
|
+
}
|
|
2116
|
+
onEditAction(e) {
|
|
2117
|
+
return this.handleEvent(1, e);
|
|
2118
|
+
}
|
|
2119
|
+
onDeleteAction(e) {
|
|
2120
|
+
return this.handleEvent(5, e);
|
|
2121
|
+
}
|
|
2122
|
+
setStatus(e) {
|
|
2123
|
+
this.description.status = e, e !== 2 && this.setProgress(0);
|
|
2124
|
+
}
|
|
2125
|
+
setProgress(e) {
|
|
2126
|
+
this.description.progress = e, this.#e?.setActive(this.isInProgress);
|
|
2127
|
+
}
|
|
2128
|
+
setSelected(e) {
|
|
2129
|
+
e !== this.isSelected && (this.description.status = e ? this.description.status | 16 : this.description.status ^ 16, this.#t && (this.#t.first.active = e));
|
|
2130
|
+
}
|
|
2131
|
+
get item() {
|
|
2132
|
+
return this.description.item;
|
|
2133
|
+
}
|
|
2134
|
+
getItemPort(e) {
|
|
2135
|
+
return this.item.ports.find(e);
|
|
2136
|
+
}
|
|
2137
|
+
get isSelected() {
|
|
2138
|
+
return !!(this.description.status & 16);
|
|
2139
|
+
}
|
|
2140
|
+
get isInProgress() {
|
|
2141
|
+
return !!(this.description.status & 2) || this.description.progress > 0;
|
|
2142
|
+
}
|
|
2143
|
+
render(e) {
|
|
2144
|
+
let t = ~~e.width - 1, n = ~~e.height - 2;
|
|
2145
|
+
return this.#t ? this.#t.hotSwap(e) : this.#t = new qe(new Je({
|
|
2146
|
+
width: t,
|
|
2147
|
+
height: n,
|
|
2148
|
+
color: 3407871,
|
|
2149
|
+
lineSize: 1,
|
|
2150
|
+
radius: 4
|
|
2151
|
+
}), e), this.#t.first.active = this.isSelected, this.#e ? this.#e.hotSwap(this.#t) : this.#e = new z(this.#t, {
|
|
2152
|
+
sizeX: t,
|
|
2153
|
+
sizeY: n,
|
|
2154
|
+
color: 3355647,
|
|
2155
|
+
lineSize: 3,
|
|
2156
|
+
radius: 4
|
|
2157
|
+
}), this.#e.setActive(this.isInProgress), this.#e;
|
|
2158
|
+
}
|
|
2159
|
+
}, vt = ({ coordinator: e, sync: t, onUpdate: n, store: r, toTitle: i }) => {
|
|
2160
|
+
let a = l(t), o = c(() => ({
|
|
2161
|
+
subscribe: (e) => r.onChange(e),
|
|
2162
|
+
getSnapshot: () => r.get(),
|
|
2163
|
+
selector: (e) => e.sort((e, t) => e.id.localeCompare(t.id)),
|
|
2164
|
+
is: N
|
|
2165
|
+
}), [r]), s = v(o.subscribe, o.getSnapshot, o.getSnapshot, o.selector, o.is), u = _(s), d = h((e) => s.find((t) => t.id === e));
|
|
2166
|
+
a.current = t, m(() => {
|
|
2167
|
+
let t = (t) => new _t({
|
|
2168
|
+
finder: d,
|
|
2169
|
+
item: t,
|
|
2170
|
+
coordinator: e,
|
|
2171
|
+
toTitle: i
|
|
2172
|
+
});
|
|
2173
|
+
if (u) {
|
|
2174
|
+
let e = u.reduce((e, { id: t }) => (e[t] = !0, e), {}), n = s.filter((t) => !e[t.id]).map(t), r = Object.keys(e).filter((e) => !d(e));
|
|
2175
|
+
(n.length || r.length) && a.current({
|
|
2176
|
+
added: n,
|
|
2177
|
+
removed: r
|
|
2178
|
+
});
|
|
2179
|
+
} else a.current({
|
|
2180
|
+
added: s.map(t),
|
|
2181
|
+
removed: []
|
|
2182
|
+
});
|
|
2183
|
+
}, [s, i]), m(() => S(() => s, n), []);
|
|
2184
|
+
}, yt = class {
|
|
2185
|
+
grid;
|
|
2186
|
+
gridSize;
|
|
2187
|
+
sizes;
|
|
2188
|
+
constructor(e) {
|
|
2189
|
+
this.grid = e, this.gridSize = {
|
|
2190
|
+
x: e,
|
|
2191
|
+
y: e
|
|
2192
|
+
}, this.sizes = {
|
|
2193
|
+
grid: this.gridSize,
|
|
2194
|
+
port: 8,
|
|
2195
|
+
lane: 16,
|
|
2196
|
+
space: 32
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
snap(e) {
|
|
2200
|
+
let t = e < 0 ? -1 : 1;
|
|
2201
|
+
return t * (Math.round(t * e / this.grid + .5) - .5) * this.grid;
|
|
2202
|
+
}
|
|
2203
|
+
toGraph({ x: e, y: t }) {
|
|
2204
|
+
return {
|
|
2205
|
+
x: (e - .5) * this.grid,
|
|
2206
|
+
y: (t - .5) * this.grid
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
toData({ x: e, y: t }) {
|
|
2210
|
+
return {
|
|
2211
|
+
x: ~~(this.snap(e) / this.grid + .5),
|
|
2212
|
+
y: ~~(this.snap(t) / this.grid + .5)
|
|
2213
|
+
};
|
|
2214
|
+
}
|
|
2215
|
+
}, bt = y(({ innerRef: e, graph: t, selected: n, handlers: r, children: i, onExport: a, ...s }) => {
|
|
2216
|
+
let d = l(null), p = c(() => new yt(16), []), m = ut(p, r?.onCreate), [g, _] = me(() => new M()), [v, y] = u(), { canvas: S, loader: C } = it(p, g, r), w = h(() => a?.(t));
|
|
2217
|
+
return o(e, () => ({
|
|
2218
|
+
get graph() {
|
|
2219
|
+
return d.current?.graph;
|
|
2220
|
+
},
|
|
2221
|
+
get element() {
|
|
2222
|
+
return d.current?.element;
|
|
2223
|
+
}
|
|
2224
|
+
})), vt({
|
|
2225
|
+
store: c(() => {
|
|
2226
|
+
let e = new M(t.items);
|
|
2227
|
+
return {
|
|
2228
|
+
items: e,
|
|
2229
|
+
get: () => e.all,
|
|
2230
|
+
onChange: (t) => e.onChange(t)
|
|
2231
|
+
};
|
|
2232
|
+
}, [t.items]),
|
|
2233
|
+
coordinator: p,
|
|
2234
|
+
toTitle: (e) => e.title,
|
|
2235
|
+
sync: (e) => ct(g, C, e),
|
|
2236
|
+
onUpdate: () => e?.current?.graph.layout()
|
|
2237
|
+
}), dt(_, n), /* @__PURE__ */ x("div", {
|
|
2238
|
+
onContextMenu: f,
|
|
2239
|
+
style: xt.root,
|
|
2240
|
+
...s,
|
|
2241
|
+
children: [/* @__PURE__ */ x("div", {
|
|
2242
|
+
style: xt.selector,
|
|
2243
|
+
children: [
|
|
2244
|
+
i,
|
|
2245
|
+
/* @__PURE__ */ b(nt, {
|
|
2246
|
+
items: _,
|
|
2247
|
+
onSelect: y
|
|
2248
|
+
}),
|
|
2249
|
+
/* @__PURE__ */ b("button", {
|
|
2250
|
+
onClick: () => y(void 0),
|
|
2251
|
+
children: "Update"
|
|
2252
|
+
}),
|
|
2253
|
+
a && /* @__PURE__ */ b("button", {
|
|
2254
|
+
onClick: w,
|
|
2255
|
+
children: "Export"
|
|
2256
|
+
})
|
|
2257
|
+
]
|
|
2258
|
+
}), /* @__PURE__ */ b(ot, {
|
|
2259
|
+
innerRef: d,
|
|
2260
|
+
coordinator: p,
|
|
2261
|
+
nodes: _,
|
|
2262
|
+
subset: v,
|
|
2263
|
+
menu: m,
|
|
2264
|
+
...S
|
|
2265
|
+
})]
|
|
2266
|
+
});
|
|
2267
|
+
}), xt = d.of({
|
|
2268
|
+
root: {
|
|
2269
|
+
flex: 1,
|
|
2270
|
+
display: "flex",
|
|
2271
|
+
alignSelf: "stretch",
|
|
2272
|
+
gap: 10
|
|
2273
|
+
},
|
|
2274
|
+
selector: {
|
|
2275
|
+
display: "flex",
|
|
2276
|
+
flexDirection: "column",
|
|
2277
|
+
gap: 10
|
|
2278
|
+
}
|
|
2279
|
+
});
|
|
2280
|
+
//#endregion
|
|
2281
|
+
export { ue as ClusteredLayout, fe as EdgesSort, Ye as GraphAdapter, ot as GraphCanvas, ce as GraphNode, k as GraphNodeJoints, le as LayeredLayout, pe as Layouter, bt as ManagedGraph, _t as ManagedGraphNode, gt as MenuActions, $e as NodeGroups, ht as NodeStatus, A as NodesGraph, de as NodesSort, $ as PIXIGUI, M as Store, et as Viewport, pt as getChannelName, ft as isChannelName, N as isEqualIdentifiables, P as useDraggable, me as useStore };
|
|
2282
|
+
|
|
2283
|
+
//# sourceMappingURL=index.js.map
|