@yh7iku/vue-tree-flow 0.1.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.
@@ -0,0 +1,1344 @@
1
+ import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createVNode as o, defineComponent as s, normalizeClass as c, normalizeStyle as l, onMounted as u, onUnmounted as d, openBlock as f, reactive as p, ref as m, renderList as h, toDisplayString as g, unref as _, vModelText as v, watch as y, withDirectives as b, withModifiers as x } from "vue";
2
+ //#region src/components/FlowDesigner/SingleLineCanvas.vue?vue&type=script&setup=true&lang.ts
3
+ var S = ["id"], C = ["id"], w = /* @__PURE__ */ s({
4
+ __name: "SingleLineCanvas",
5
+ props: {
6
+ lineId: {},
7
+ fromAnchor: {},
8
+ toAnchor: {},
9
+ scale: { default: 1 },
10
+ isSelected: {
11
+ type: Boolean,
12
+ default: !1
13
+ },
14
+ animated: {
15
+ type: Boolean,
16
+ default: !1
17
+ },
18
+ theme: { default: "dark" }
19
+ },
20
+ setup(e) {
21
+ let t = e, n = m(null), r = m(null), o = null, s = {
22
+ position: "absolute",
23
+ pointerEvents: "none",
24
+ zIndex: 5,
25
+ overflow: "hidden"
26
+ }, c = {
27
+ display: "block",
28
+ position: "absolute",
29
+ top: 0,
30
+ left: 0,
31
+ pointerEvents: "none"
32
+ }, l = () => {
33
+ if (!n.value || !r.value) return;
34
+ let { cp1X: e, cp1Y: i, cp2X: a, cp2Y: o } = h(t.fromAnchor.type, t.toAnchor.type, t.fromAnchor.x, t.fromAnchor.y, t.toAnchor.x, t.toAnchor.y), s = [
35
+ t.fromAnchor.x,
36
+ t.toAnchor.x,
37
+ e,
38
+ a
39
+ ], c = [
40
+ t.fromAnchor.y,
41
+ t.toAnchor.y,
42
+ i,
43
+ o
44
+ ], l = Math.min(...s) - 30, u = Math.min(...c) - 30, d = Math.max(...s) + 30, f = Math.max(...c) + 30, p = d - l, m = f - u;
45
+ n.value.style.left = `${l}px`, n.value.style.top = `${u}px`, n.value.style.width = `${p}px`, n.value.style.height = `${m}px`;
46
+ let g = window.devicePixelRatio || 1;
47
+ r.value.width = Math.round(p * t.scale * g), r.value.height = Math.round(m * t.scale * g), r.value.style.width = `${p}px`, r.value.style.height = `${m}px`;
48
+ }, p = (e, t, r, i, a) => {
49
+ if (!n.value) return;
50
+ e.save();
51
+ let o = t - n.value.offsetLeft, s = r - n.value.offsetTop;
52
+ e.translate(o, s), e.rotate(i), e.fillStyle = a, e.beginPath(), e.moveTo(0, 0), e.lineTo(-15, -8), e.lineTo(-15, 8), e.closePath(), e.fill(), e.restore();
53
+ }, h = (e, t, n, r, i, a) => {
54
+ let o = Math.hypot(i - n, a - r), s = Math.min(100, o / 2), c = n, l = r, u = i, d = a;
55
+ switch (e) {
56
+ case "top":
57
+ l = r - s;
58
+ break;
59
+ case "bottom":
60
+ l = r + s;
61
+ break;
62
+ case "left":
63
+ c = n - s;
64
+ break;
65
+ case "right": c = n + s;
66
+ }
67
+ switch (t) {
68
+ case "top":
69
+ d = a - s;
70
+ break;
71
+ case "bottom":
72
+ d = a + s;
73
+ break;
74
+ case "left":
75
+ u = i - s;
76
+ break;
77
+ case "right": u = i + s;
78
+ }
79
+ return {
80
+ cp1X: c,
81
+ cp1Y: l,
82
+ cp2X: u,
83
+ cp2Y: d
84
+ };
85
+ }, g = () => {
86
+ if (!r.value) return;
87
+ let e = r.value, i = e.getContext("2d");
88
+ if (!i) return;
89
+ let a = window.devicePixelRatio || 1;
90
+ i.setTransform(a, 0, 0, a, 0, 0), i.clearRect(0, 0, e.width, e.height), i.scale(t.scale, t.scale);
91
+ let o = t.theme === "light" ? "#3182ce" : "#4299e1", s = t.isSelected ? "#ff6b6b" : o, c = t.isSelected ? 4 : 3, l = t.isSelected ? 1 : 3;
92
+ if (!n.value) return;
93
+ let u = t.fromAnchor.x - n.value.offsetLeft, d = t.fromAnchor.y - n.value.offsetTop, f = t.toAnchor.x - n.value.offsetLeft, m = t.toAnchor.y - n.value.offsetTop, { cp1X: g, cp1Y: _, cp2X: v, cp2Y: y } = h(t.fromAnchor.type, t.toAnchor.type, u, d, f, m);
94
+ i.strokeStyle = s, i.lineWidth = c, i.lineCap = "round", t.animated ? (i.setLineDash([15, 10]), i.lineDashOffset = -(Date.now() / 50) * l % 100) : (i.setLineDash([]), i.lineDashOffset = 0), i.beginPath(), i.moveTo(u, d), i.bezierCurveTo(g, _, v, y, f, m), i.stroke();
95
+ let b = f - v, x = m - y, S = Math.atan2(x, b);
96
+ p(i, t.toAnchor.x, t.toAnchor.y, S, s);
97
+ }, _ = () => {
98
+ g(), o = requestAnimationFrame(_);
99
+ }, v = () => {
100
+ o || _();
101
+ }, b = () => {
102
+ o &&= (cancelAnimationFrame(o), null);
103
+ }, x = () => {
104
+ l(), g();
105
+ };
106
+ return y(() => [
107
+ t.fromAnchor,
108
+ t.toAnchor,
109
+ t.scale,
110
+ t.isSelected,
111
+ t.animated,
112
+ t.theme
113
+ ], () => {
114
+ l(), t.animated ? v() : (b(), g());
115
+ }, { deep: !0 }), u(() => {
116
+ l(), window.addEventListener("resize", x), t.animated ? v() : g();
117
+ }), d(() => {
118
+ window.removeEventListener("resize", x), b();
119
+ }), (t, o) => (f(), i("div", {
120
+ ref_key: "containerRef",
121
+ ref: n,
122
+ id: `linker_${e.lineId}`,
123
+ class: "shape_box linker_box",
124
+ style: s
125
+ }, [a("canvas", {
126
+ ref_key: "canvasRef",
127
+ ref: r,
128
+ id: `linker_canvas_${e.lineId}`,
129
+ class: "shape_canvas",
130
+ style: c
131
+ }, null, 8, C)], 8, S));
132
+ }
133
+ }), T = /* @__PURE__ */ s({
134
+ __name: "TempLineCanvas",
135
+ props: {
136
+ visible: {
137
+ type: Boolean,
138
+ default: !1
139
+ },
140
+ startX: { default: 0 },
141
+ startY: { default: 0 },
142
+ endX: { default: 0 },
143
+ endY: { default: 0 },
144
+ scale: { default: 1 },
145
+ startType: { default: "right" },
146
+ endType: { default: "left" },
147
+ theme: { default: "dark" }
148
+ },
149
+ setup(e) {
150
+ let t = e, n = () => t.theme === "light" ? "#3182ce" : "#4299e1", o = m(null), s = m(null), c = null, l = {
151
+ position: "absolute",
152
+ pointerEvents: "none",
153
+ zIndex: 5,
154
+ overflow: "hidden"
155
+ }, p = {
156
+ display: "block",
157
+ position: "absolute",
158
+ top: 0,
159
+ left: 0,
160
+ pointerEvents: "none"
161
+ }, h = (e, t, n, r, i, a) => {
162
+ let o = Math.hypot(i - n, a - r), s = Math.min(100, o / 2), c = n, l = r, u = i, d = a;
163
+ switch (e) {
164
+ case "top":
165
+ l = r - s;
166
+ break;
167
+ case "bottom":
168
+ l = r + s;
169
+ break;
170
+ case "left":
171
+ c = n - s;
172
+ break;
173
+ case "right": c = n + s;
174
+ }
175
+ let f = t;
176
+ if (!f) {
177
+ let e = i - n, t = a - r;
178
+ f = Math.abs(e) > Math.abs(t) ? e > 0 ? "left" : "right" : t > 0 ? "top" : "bottom";
179
+ }
180
+ switch (f) {
181
+ case "top":
182
+ d = a - s;
183
+ break;
184
+ case "bottom":
185
+ d = a + s;
186
+ break;
187
+ case "left":
188
+ u = i - s;
189
+ break;
190
+ case "right": u = i + s;
191
+ }
192
+ return {
193
+ cp1X: c,
194
+ cp1Y: l,
195
+ cp2X: u,
196
+ cp2Y: d
197
+ };
198
+ }, g = () => {
199
+ if (!t.visible || !o.value || !s.value) return;
200
+ let { cp1X: e, cp1Y: n, cp2X: r, cp2Y: i } = h(t.startType || "right", t.endType, t.startX, t.startY, t.endX, t.endY), a = [
201
+ t.startX,
202
+ t.endX,
203
+ e,
204
+ r
205
+ ], c = [
206
+ t.startY,
207
+ t.endY,
208
+ n,
209
+ i
210
+ ], l = Math.min(...a) - 30, u = Math.min(...c) - 30, d = Math.max(...a) + 30, f = Math.max(...c) + 30, p = d - l, m = f - u;
211
+ o.value.style.left = `${l}px`, o.value.style.top = `${u}px`, o.value.style.width = `${p}px`, o.value.style.height = `${m}px`;
212
+ let g = window.devicePixelRatio || 1;
213
+ s.value.width = Math.round(p * t.scale * g), s.value.height = Math.round(m * t.scale * g), s.value.style.width = `${p}px`, s.value.style.height = `${m}px`;
214
+ }, _ = () => {
215
+ if (!t.visible || !s.value || !o.value) return;
216
+ let e = s.value, r = e.getContext("2d");
217
+ if (!r) return;
218
+ let i = window.devicePixelRatio || 1;
219
+ r.setTransform(i, 0, 0, i, 0, 0), r.clearRect(0, 0, e.width, e.height), r.scale(t.scale, t.scale), r.strokeStyle = n(), r.lineWidth = 2, r.lineCap = "round", r.setLineDash([10, 8]);
220
+ let a = parseFloat(o.value.style.left || "0"), c = parseFloat(o.value.style.top || "0"), l = t.startX - a, u = t.startY - c, d = t.endX - a, f = t.endY - c, { cp1X: p, cp1Y: m, cp2X: g, cp2Y: _ } = h(t.startType || "right", t.endType || "left", t.startX, t.startY, t.endX, t.endY), v = p - a, y = m - c, b = g - a, x = _ - c;
221
+ r.beginPath(), r.moveTo(l, u), r.bezierCurveTo(v, y, b, x, d, f), r.stroke();
222
+ let S = d - b, C = f - x, w = Math.atan2(C, S);
223
+ r.save(), r.translate(d, f), r.rotate(w), r.fillStyle = n(), r.beginPath(), r.moveTo(0, 0), r.lineTo(-15, -8), r.lineTo(-15, 8), r.closePath(), r.fill(), r.restore();
224
+ }, v = () => {
225
+ _(), c = requestAnimationFrame(v);
226
+ }, b = () => {
227
+ c || v();
228
+ }, x = () => {
229
+ c &&= (cancelAnimationFrame(c), null);
230
+ };
231
+ return y(() => [
232
+ t.visible,
233
+ t.startX,
234
+ t.startY,
235
+ t.endX,
236
+ t.endY,
237
+ t.scale
238
+ ], () => {
239
+ t.visible ? (g(), b()) : x();
240
+ }, { immediate: !0 }), u(() => {
241
+ t.visible && (g(), b());
242
+ }), d(() => {
243
+ x();
244
+ }), (t, n) => e.visible ? (f(), i("div", {
245
+ key: 0,
246
+ ref_key: "containerRef",
247
+ ref: o,
248
+ style: l
249
+ }, [a("canvas", {
250
+ ref_key: "canvasRef",
251
+ ref: s,
252
+ style: p
253
+ }, null, 512)], 512)) : r("", !0);
254
+ }
255
+ }), E = (e, t) => {
256
+ switch (e.type) {
257
+ case "top": return {
258
+ x: t.x + t.width / 2,
259
+ y: t.y - 6
260
+ };
261
+ case "bottom": return {
262
+ x: t.x + t.width / 2,
263
+ y: t.y + t.height - 6
264
+ };
265
+ case "left": return {
266
+ x: t.x - 6,
267
+ y: t.y + t.height / 2
268
+ };
269
+ case "right": return {
270
+ x: t.x + t.width - 6,
271
+ y: t.y + t.height / 2
272
+ };
273
+ }
274
+ }, D = (e, t) => {
275
+ switch (e.type) {
276
+ case "top": return {
277
+ x: t.x + t.width / 2,
278
+ y: t.y
279
+ };
280
+ case "bottom": return {
281
+ x: t.x + t.width / 2,
282
+ y: t.y + t.height
283
+ };
284
+ case "left": return {
285
+ x: t.x,
286
+ y: t.y + t.height / 2
287
+ };
288
+ case "right": return {
289
+ x: t.x + t.width,
290
+ y: t.y + t.height / 2
291
+ };
292
+ }
293
+ }, ee = (e, t, n, r, i, a) => {
294
+ let o = (e - a.left - r.x) / i, s = (t - a.top - r.y) / i;
295
+ for (let e of n) for (let t of e.anchors) {
296
+ let n = E(t, e);
297
+ if (Math.hypot(o - n.x, s - n.y) < 15) return {
298
+ ...t,
299
+ x: n.x,
300
+ y: n.y
301
+ };
302
+ }
303
+ return null;
304
+ }, O = () => `line_${Date.now()}_${Math.floor(Math.random() * 1e3)}`, k = (e) => {
305
+ e.stopPropagation(), e.preventDefault();
306
+ }, te = (e, t, n, r, i, a) => {
307
+ let o = Math.hypot(i - n, a - r), s = Math.min(100, o / 2), c = n, l = r, u = i, d = a;
308
+ switch (e) {
309
+ case "top":
310
+ l = r - s;
311
+ break;
312
+ case "bottom":
313
+ l = r + s;
314
+ break;
315
+ case "left":
316
+ c = n - s;
317
+ break;
318
+ case "right": c = n + s;
319
+ }
320
+ switch (t) {
321
+ case "top":
322
+ d = a - s;
323
+ break;
324
+ case "bottom":
325
+ d = a + s;
326
+ break;
327
+ case "left":
328
+ u = i - s;
329
+ break;
330
+ case "right": u = i + s;
331
+ }
332
+ return {
333
+ cp1X: c,
334
+ cp1Y: l,
335
+ cp2X: u,
336
+ cp2Y: d
337
+ };
338
+ }, ne = (e, t, n, r, i, a, o, s = 8, c) => {
339
+ let l, u, d, f;
340
+ if (c) {
341
+ let t = c.get(e.fromAnchorId), n = c.get(e.toAnchorId);
342
+ t && (l = t.anchor, d = t.node), n && (u = n.anchor, f = n.node);
343
+ } else {
344
+ if (l = t.flatMap((e) => e.anchors).find((t) => t.id === e.fromAnchorId), u = t.flatMap((e) => e.anchors).find((t) => t.id === e.toAnchorId), l) {
345
+ let e = l.nodeId;
346
+ d = t.find((t) => t.id === e);
347
+ }
348
+ if (u) {
349
+ let e = u.nodeId;
350
+ f = t.find((t) => t.id === e);
351
+ }
352
+ }
353
+ if (!l || !u || !d || !f) return !1;
354
+ let p = D(l, d), m = D(u, f), h = (n - o.left - i.x) / a, g = (r - o.top - i.y) / a, { cp1X: _, cp1Y: v, cp2X: y, cp2Y: b } = te(l.type, u.type, p.x, p.y, m.x, m.y), x = Math.min(p.x, m.x, _, y) - s, S = Math.max(p.x, m.x, _, y) + s, C = Math.min(p.y, m.y, v, b) - s, w = Math.max(p.y, m.y, v, b) + s;
355
+ if (h < x || h > S || g < C || g > w) return !1;
356
+ for (let e = 0; e <= 1; e += .005) {
357
+ let t = 1 - e, n = p.x * t * t * t + 3 * _ * t * t * e + 3 * y * t * e * e + m.x * e * e * e, r = p.y * t * t * t + 3 * v * t * t * e + 3 * b * t * e * e + m.y * e * e * e;
358
+ if (Math.hypot(h - n, g - r) < s) return !0;
359
+ }
360
+ return !1;
361
+ }, re = (e) => {
362
+ let t = /* @__PURE__ */ new Map();
363
+ for (let n of e) for (let e of n.anchors) t.set(e.id, {
364
+ anchor: e,
365
+ node: n
366
+ });
367
+ return t;
368
+ }, ie = (e, t, n) => t.length === 0 ? "" : t[(t.findIndex((e) => e.id === n) + 1) % t.length].id, ae = (e, t, n) => e.some((e) => e.fromAnchorId === t && e.toAnchorId === n), A = (e) => {
369
+ let t = e.lastIndexOf("-");
370
+ return t === -1 ? e : e.slice(0, t);
371
+ }, oe = (e, t) => {
372
+ if (e.length === 0) return null;
373
+ let n = e[0].width || 140, r = e[0].height || 200, i = Math.max(20, Math.round(n * .3)), a = Math.max(30, Math.round(r * .5)), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
374
+ for (let e of t) {
375
+ let t = A(e.fromAnchorId), n = A(e.toAnchorId);
376
+ t !== n && (o.has(t) || o.set(t, []), o.get(t).includes(n) || o.get(t).push(n), s.add(n));
377
+ }
378
+ let c = (e) => {
379
+ let t = /* @__PURE__ */ new Set(), n = (e) => {
380
+ if (!t.has(e)) {
381
+ t.add(e);
382
+ for (let t of o.get(e) ?? []) n(t);
383
+ }
384
+ };
385
+ return n(e), t;
386
+ }, l = e.filter((e) => !s.has(e.id));
387
+ if (l.length === 0) return null;
388
+ let u = l[0], d = c(u.id);
389
+ for (let e of l) {
390
+ let t = c(e.id);
391
+ t.size > d.size && (u = e, d = t);
392
+ }
393
+ let f = /* @__PURE__ */ new Map(), p = (e, t) => {
394
+ if (t.has(e)) return 1;
395
+ t.add(e);
396
+ let n = o.get(e) ?? [];
397
+ return n.length === 0 ? 1 : n.reduce((e, n) => e + p(n, new Set(t)), 0);
398
+ };
399
+ for (let e of d) f.set(e, p(e, /* @__PURE__ */ new Set()));
400
+ let m = /* @__PURE__ */ new Map(), h = (e, t, s, c) => {
401
+ if (c.has(e)) return;
402
+ c.add(e);
403
+ let l = f.get(e) ?? 1, u = s + (l * n + (l - 1) * i) / 2;
404
+ m.set(e, {
405
+ x: u - n / 2,
406
+ y: t * (r + a)
407
+ });
408
+ let d = s;
409
+ for (let r of o.get(e) ?? []) {
410
+ let e = f.get(r) ?? 1, a = e * n + (e - 1) * i;
411
+ h(r, t + 1, d, c), d += a + i;
412
+ }
413
+ };
414
+ h(u.id, 0, 0, /* @__PURE__ */ new Set());
415
+ let g = m.get(u.id);
416
+ if (!g) return null;
417
+ let _ = u.x - g.x, v = u.y - g.y;
418
+ return e.map((e) => {
419
+ let t = m.get(e.id);
420
+ if (!t) return e;
421
+ let n = t.x + _, r = t.y + v, i = e.anchors.map((t) => {
422
+ let i = D(t, {
423
+ ...e,
424
+ x: n,
425
+ y: r
426
+ });
427
+ return {
428
+ ...t,
429
+ x: i.x,
430
+ y: i.y
431
+ };
432
+ });
433
+ return {
434
+ ...e,
435
+ x: n,
436
+ y: r,
437
+ anchors: i
438
+ };
439
+ });
440
+ }, se = /* @__PURE__ */ s({
441
+ __name: "FlowLinesCanvas",
442
+ props: {
443
+ nodes: {},
444
+ lines: {},
445
+ scale: {},
446
+ tempLine: {},
447
+ selectedLineId: { default: "" },
448
+ animated: {
449
+ type: Boolean,
450
+ default: !1
451
+ },
452
+ theme: { default: "dark" }
453
+ },
454
+ setup(t) {
455
+ let a = t, s = (e) => {
456
+ for (let t of a.nodes) {
457
+ let n = t.anchors.find((t) => t.id === e);
458
+ if (n) {
459
+ let e = D(n, t);
460
+ return {
461
+ ...n,
462
+ x: e.x,
463
+ y: e.y
464
+ };
465
+ }
466
+ }
467
+ return null;
468
+ }, c = {
469
+ position: "absolute",
470
+ top: 0,
471
+ left: 0,
472
+ width: "100%",
473
+ height: "100%",
474
+ pointerEvents: "none",
475
+ zIndex: 5
476
+ };
477
+ return (a, l) => (f(), i("div", { style: c }, [(f(!0), i(e, null, h(t.lines, (a) => (f(), i(e, { key: a.id }, [s(a.fromAnchorId) && s(a.toAnchorId) ? (f(), n(w, {
478
+ key: 0,
479
+ "line-id": a.id,
480
+ "from-anchor": s(a.fromAnchorId),
481
+ "to-anchor": s(a.toAnchorId),
482
+ scale: t.scale,
483
+ "is-selected": t.selectedLineId === a.id,
484
+ animated: t.animated,
485
+ theme: t.theme
486
+ }, null, 8, [
487
+ "line-id",
488
+ "from-anchor",
489
+ "to-anchor",
490
+ "scale",
491
+ "is-selected",
492
+ "animated",
493
+ "theme"
494
+ ])) : r("", !0)], 64))), 128)), o(T, {
495
+ visible: t.tempLine.visible,
496
+ "start-x": t.tempLine.startX,
497
+ "start-y": t.tempLine.startY,
498
+ "end-x": t.tempLine.endX,
499
+ "end-y": t.tempLine.endY,
500
+ scale: t.scale,
501
+ "start-type": t.tempLine.startType,
502
+ "end-type": t.tempLine.endType,
503
+ theme: t.theme
504
+ }, null, 8, [
505
+ "visible",
506
+ "start-x",
507
+ "start-y",
508
+ "end-x",
509
+ "end-y",
510
+ "scale",
511
+ "start-type",
512
+ "end-type",
513
+ "theme"
514
+ ])]));
515
+ }
516
+ }), j = ["src"], ce = { class: "node-name" }, le = /*@__PURE__*/ s({
517
+ __name: "FlowNode",
518
+ props: {
519
+ id: {},
520
+ name: {},
521
+ desc: {},
522
+ x: {},
523
+ y: {},
524
+ width: { default: 300 },
525
+ height: { default: 200 },
526
+ pic: {},
527
+ isDragging: {
528
+ type: Boolean,
529
+ default: !1
530
+ }
531
+ },
532
+ emits: [
533
+ "dragStart",
534
+ "anchorClick",
535
+ "contextMenu",
536
+ "anchorHover",
537
+ "anchorLeave"
538
+ ],
539
+ setup(e, { emit: n }) {
540
+ let o = e, s = n, u = m(!1), d = t(() => ({
541
+ id: `${o.id}-top`,
542
+ nodeId: o.id,
543
+ type: "top",
544
+ x: o.x + o.width / 2,
545
+ y: o.y - 6
546
+ })), p = t(() => ({
547
+ id: `${o.id}-bottom`,
548
+ nodeId: o.id,
549
+ type: "bottom",
550
+ x: o.x + o.width / 2,
551
+ y: o.y + o.height - 6
552
+ })), h = t(() => ({
553
+ id: `${o.id}-left`,
554
+ nodeId: o.id,
555
+ type: "left",
556
+ x: o.x - 6,
557
+ y: o.y + o.height / 2
558
+ })), _ = t(() => ({
559
+ id: `${o.id}-right`,
560
+ nodeId: o.id,
561
+ type: "right",
562
+ x: o.x + o.width - 6,
563
+ y: o.y + o.height / 2
564
+ })), v = t(() => ({
565
+ position: "absolute",
566
+ left: `${o.x}px`,
567
+ top: `${o.y}px`,
568
+ width: `${o.width}px`,
569
+ height: `${o.height}px`,
570
+ backgroundColor: "var(--fd-node-bg)",
571
+ border: "1px solid var(--fd-node-border)",
572
+ borderRadius: "8px",
573
+ color: "var(--fd-node-text)",
574
+ display: "flex",
575
+ flexDirection: "column",
576
+ alignItems: "center",
577
+ justifyContent: o.pic ? "flex-start" : "center",
578
+ fontFamily: "Arial, sans-serif",
579
+ fontSize: "14px",
580
+ boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
581
+ cursor: o.isDragging ? "grabbing" : "grab",
582
+ zIndex: 6,
583
+ userSelect: "none",
584
+ transition: "border-color 0.2s ease",
585
+ borderColor: u.value ? "var(--fd-node-border-hover)" : "var(--fd-node-border)"
586
+ })), y = (e) => {
587
+ let t = {
588
+ position: "absolute",
589
+ width: "12px",
590
+ height: "12px",
591
+ borderRadius: "50%",
592
+ backgroundColor: "rgba(66, 153, 225, 0.6)",
593
+ border: "2px solid #fff",
594
+ cursor: "crosshair",
595
+ zIndex: 6,
596
+ opacity: +!!u.value,
597
+ visibility: u.value ? "visible" : "hidden",
598
+ transition: "all 0.2s ease",
599
+ pointerEvents: u.value ? "auto" : "none",
600
+ boxShadow: "0 0 0 3px rgba(66, 153, 225, 0.2), 0 0 0 7px rgba(66, 153, 225, 0.12), 0 0 0 12px rgba(66, 153, 225, 0.05), 0 0 0 18px rgba(66, 153, 225, 0.02)",
601
+ touchAction: "none"
602
+ };
603
+ switch (e) {
604
+ case "top":
605
+ t.top = "-6px", t.left = "50%", t.transform = "translateX(-50%)";
606
+ break;
607
+ case "bottom":
608
+ t.bottom = "-6px", t.left = "50%", t.transform = "translateX(-50%)";
609
+ break;
610
+ case "left":
611
+ t.left = "-6px", t.top = "50%", t.transform = "translateY(-50%)";
612
+ break;
613
+ case "right": t.right = "-6px", t.top = "50%", t.transform = "translateY(-50%)";
614
+ }
615
+ return t;
616
+ }, b = (e) => {
617
+ e.target.classList.contains("node-anchor") || (k(e), s("dragStart", o.id, e, o.x, o.y));
618
+ }, S = (e, t) => {
619
+ k(t), s("anchorClick", e, t);
620
+ }, C = (e) => {
621
+ k(e), s("contextMenu", o.id, e);
622
+ }, w = (e, t) => {
623
+ let n = e.target;
624
+ n.style.opacity = "1", t === "top" || t === "bottom" ? n.style.transform = "translateX(-50%) scale(1.2)" : n.style.transform = "translateY(-50%) scale(1.2)", n.style.backgroundColor = "#4299e1", n.style.boxShadow = "0 0 0 3px rgba(66, 153, 225, 0.3), 0 0 0 6px rgba(66, 153, 225, 0.18), 0 0 0 10px rgba(66, 153, 225, 0.08)", s("anchorHover", t);
625
+ }, T = (e, t) => {
626
+ let n = e.target;
627
+ n.style.opacity = "0.9", t === "top" || t === "bottom" ? n.style.transform = "translateX(-50%) scale(1)" : n.style.transform = "translateY(-50%) scale(1)", n.style.backgroundColor = "rgba(66, 153, 225, 0.6)", n.style.boxShadow = "0 0 0 3px rgba(66, 153, 225, 0.2), 0 0 0 7px rgba(66, 153, 225, 0.12), 0 0 0 12px rgba(66, 153, 225, 0.05), 0 0 0 18px rgba(66, 153, 225, 0.02)", s("anchorLeave");
628
+ };
629
+ return (t, n) => (f(), i("div", {
630
+ class: c(["node", { "node--with-pic": !!e.pic }]),
631
+ style: l(v.value),
632
+ onMousedown: b,
633
+ onContextmenu: x(C, ["prevent"]),
634
+ onMouseenter: n[12] ||= (e) => u.value = !0,
635
+ onMouseleave: n[13] ||= (e) => u.value = !1
636
+ }, [
637
+ e.pic ? (f(), i("img", {
638
+ key: 0,
639
+ class: "node-pic",
640
+ src: e.pic,
641
+ alt: ""
642
+ }, null, 8, j)) : r("", !0),
643
+ a("span", ce, g(e.name), 1),
644
+ a("div", {
645
+ class: "node-anchor anchor-top",
646
+ style: l(y("top")),
647
+ onMousedown: n[0] ||= x((e) => S(d.value, e), ["stop"]),
648
+ onMouseenter: n[1] ||= (e) => w(e, "top"),
649
+ onMouseleave: n[2] ||= (e) => T(e, "top")
650
+ }, null, 36),
651
+ a("div", {
652
+ class: "node-anchor anchor-bottom",
653
+ style: l(y("bottom")),
654
+ onMousedown: n[3] ||= x((e) => S(p.value, e), ["stop"]),
655
+ onMouseenter: n[4] ||= (e) => w(e, "bottom"),
656
+ onMouseleave: n[5] ||= (e) => T(e, "bottom")
657
+ }, null, 36),
658
+ a("div", {
659
+ class: "node-anchor anchor-left",
660
+ style: l(y("left")),
661
+ onMousedown: n[6] ||= x((e) => S(h.value, e), ["stop"]),
662
+ onMouseenter: n[7] ||= (e) => w(e, "left"),
663
+ onMouseleave: n[8] ||= (e) => T(e, "left")
664
+ }, null, 36),
665
+ a("div", {
666
+ class: "node-anchor anchor-right",
667
+ style: l(y("right")),
668
+ onMousedown: n[9] ||= x((e) => S(_.value, e), ["stop"]),
669
+ onMouseenter: n[10] ||= (e) => w(e, "right"),
670
+ onMouseleave: n[11] ||= (e) => T(e, "right")
671
+ }, null, 36)
672
+ ], 38));
673
+ }
674
+ }), M = (e, t) => {
675
+ let n = e.__vccOpts || e;
676
+ for (let [e, r] of t) n[e] = r;
677
+ return n;
678
+ }, ue = /*#__PURE__*/ M(le, [["__scopeId", "data-v-2dead940"]]), de = { class: "nodes-container" }, fe = { class: "edit-panel-field" }, pe = { class: "edit-panel-field" }, N = /*#__PURE__*/ M(/* @__PURE__ */ s({
679
+ __name: "FlowDesigner",
680
+ props: {
681
+ nodes: {},
682
+ lines: {},
683
+ theme: { default: "dark" }
684
+ },
685
+ emits: [
686
+ "update:nodes",
687
+ "update:lines",
688
+ "beforeDeleteNode",
689
+ "beforeDeleteLine",
690
+ "beforeAddNode"
691
+ ],
692
+ setup(s, { expose: S, emit: C }) {
693
+ let w = s, T = C, E = [
694
+ {
695
+ id: "1",
696
+ name: "Reference",
697
+ x: 0,
698
+ y: 0,
699
+ width: 140,
700
+ height: 200,
701
+ anchors: [
702
+ {
703
+ id: "1-top",
704
+ nodeId: "1",
705
+ type: "top",
706
+ x: 70,
707
+ y: 0
708
+ },
709
+ {
710
+ id: "1-bottom",
711
+ nodeId: "1",
712
+ type: "bottom",
713
+ x: 70,
714
+ y: 200
715
+ },
716
+ {
717
+ id: "1-left",
718
+ nodeId: "1",
719
+ type: "left",
720
+ x: 0,
721
+ y: 100
722
+ },
723
+ {
724
+ id: "1-right",
725
+ nodeId: "1",
726
+ type: "right",
727
+ x: 140,
728
+ y: 100
729
+ }
730
+ ]
731
+ },
732
+ {
733
+ id: "2",
734
+ name: "Image Generation",
735
+ x: 400,
736
+ y: 0,
737
+ width: 140,
738
+ height: 200,
739
+ anchors: [
740
+ {
741
+ id: "2-top",
742
+ nodeId: "2",
743
+ type: "top",
744
+ x: 470,
745
+ y: 0
746
+ },
747
+ {
748
+ id: "2-bottom",
749
+ nodeId: "2",
750
+ type: "bottom",
751
+ x: 470,
752
+ y: 200
753
+ },
754
+ {
755
+ id: "2-left",
756
+ nodeId: "2",
757
+ type: "left",
758
+ x: 400,
759
+ y: 100
760
+ },
761
+ {
762
+ id: "2-right",
763
+ nodeId: "2",
764
+ type: "right",
765
+ x: 540,
766
+ y: 100
767
+ }
768
+ ]
769
+ },
770
+ {
771
+ id: "3",
772
+ name: "Video Generation",
773
+ x: 400,
774
+ y: 250,
775
+ width: 140,
776
+ height: 200,
777
+ anchors: [
778
+ {
779
+ id: "3-top",
780
+ nodeId: "3",
781
+ type: "top",
782
+ x: 470,
783
+ y: 250
784
+ },
785
+ {
786
+ id: "3-bottom",
787
+ nodeId: "3",
788
+ type: "bottom",
789
+ x: 470,
790
+ y: 450
791
+ },
792
+ {
793
+ id: "3-left",
794
+ nodeId: "3",
795
+ type: "left",
796
+ x: 400,
797
+ y: 350
798
+ },
799
+ {
800
+ id: "3-right",
801
+ nodeId: "3",
802
+ type: "right",
803
+ x: 540,
804
+ y: 350
805
+ }
806
+ ]
807
+ }
808
+ ], te = [{
809
+ id: "1",
810
+ fromAnchorId: "1-right",
811
+ toAnchorId: "2-left"
812
+ }, {
813
+ id: "2",
814
+ fromAnchorId: "1-right",
815
+ toAnchorId: "3-left"
816
+ }], A = m(w.nodes ?? E), j = m(w.lines ?? te);
817
+ y(() => w.nodes, (e) => {
818
+ e && (A.value = e);
819
+ }, { deep: !0 }), y(() => w.lines, (e) => {
820
+ e && (j.value = e);
821
+ }, { deep: !0 });
822
+ let ce = (e) => {
823
+ let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = !1, i = (a) => {
824
+ if (n.has(a)) {
825
+ a === e && (r = !0);
826
+ return;
827
+ }
828
+ n.add(a);
829
+ let o = A.value.find((e) => e.id === a);
830
+ if (!o) return;
831
+ let s = new Set(o.anchors.map((e) => e.id));
832
+ for (let e of j.value) {
833
+ if (!s.has(e.fromAnchorId)) continue;
834
+ let n = A.value.flatMap((e) => e.anchors).find((t) => t.id === e.toAnchorId);
835
+ !n || n.nodeId === a || (t.add(n.nodeId), i(n.nodeId));
836
+ }
837
+ };
838
+ return i(e), r ? /* @__PURE__ */ new Set() : t;
839
+ }, le = t(() => {
840
+ let e = /* @__PURE__ */ new Set();
841
+ for (let t of A.value) if (t.collapsed) for (let n of ce(t.id)) e.add(n);
842
+ return e;
843
+ }), M = t(() => A.value.filter((e) => !le.value.has(e.id))), N = t(() => {
844
+ let e = new Set(M.value.map((e) => e.id));
845
+ return j.value.filter((t) => {
846
+ let n = A.value.flatMap((e) => e.anchors).find((e) => e.id === t.fromAnchorId), r = A.value.flatMap((e) => e.anchors).find((e) => e.id === t.toAnchorId);
847
+ return n && r && e.has(n.nodeId) && e.has(r.nodeId);
848
+ });
849
+ }), me = (e) => {
850
+ let t = A.value.find((t) => t.id === e);
851
+ if (!t) return !1;
852
+ let n = new Set(t.anchors.map((e) => e.id));
853
+ return j.value.some((t) => {
854
+ if (!n.has(t.fromAnchorId)) return !1;
855
+ let r = A.value.flatMap((e) => e.anchors).find((e) => e.id === t.toAnchorId);
856
+ return !!r && r.nodeId !== e;
857
+ });
858
+ }, he = t(() => !!Y.targetId && me(Y.targetId)), ge = t(() => !!A.value.find((e) => e.id === Y.targetId)?.collapsed), _e = () => {
859
+ let e = Y.targetId;
860
+ if (!e) return;
861
+ let t = A.value.find((t) => t.id === e);
862
+ if (!t) return;
863
+ t.collapsed = !t.collapsed;
864
+ let n = oe(M.value, N.value);
865
+ if (n) {
866
+ let e = new Map(n.map((e) => [e.id, e]));
867
+ A.value = A.value.map((t) => {
868
+ let n = e.get(t.id);
869
+ return n ? {
870
+ ...t,
871
+ ...n
872
+ } : t;
873
+ });
874
+ }
875
+ T("update:nodes", A.value), $();
876
+ }, P = p({
877
+ visible: !1,
878
+ startX: 0,
879
+ startY: 0,
880
+ endX: 0,
881
+ endY: 0
882
+ }), F = m(1), I = p({
883
+ x: 100,
884
+ y: 100
885
+ }), L = m(!1), R = p({
886
+ x: 0,
887
+ y: 0
888
+ }), z = m("none"), B = p({
889
+ x: 0,
890
+ y: 0
891
+ }), V = p({
892
+ startDist: 0,
893
+ startScale: 1,
894
+ startX: 0,
895
+ startY: 0,
896
+ midX: 0,
897
+ midY: 0,
898
+ rectLeft: 0,
899
+ rectTop: 0
900
+ }), H = m(null), U = p({
901
+ x: 0,
902
+ y: 0,
903
+ initialX: 0,
904
+ initialY: 0
905
+ }), W = m(!1), G = m(null), K = m(""), ve = !1, q = !1, J = m(!1), ye = () => (J.value = !J.value, J.value), be = () => {
906
+ let e = Z.value;
907
+ if (!e) return;
908
+ let t = M.value;
909
+ if (t.length === 0) return;
910
+ let n = Infinity, r = Infinity, i = -Infinity, a = -Infinity;
911
+ for (let e of t) e.x < n && (n = e.x), e.y < r && (r = e.y), e.x + e.width > i && (i = e.x + e.width), e.y + e.height > a && (a = e.y + e.height);
912
+ let o = (n + i) / 2, s = (r + a) / 2, c = e.getBoundingClientRect();
913
+ I.x = c.width / 2 - o * F.value, I.y = c.height / 2 - s * F.value;
914
+ }, Y = p({
915
+ type: "none",
916
+ x: 0,
917
+ y: 0,
918
+ targetId: null
919
+ }), X = p({
920
+ visible: !1,
921
+ nodeId: null,
922
+ x: 0,
923
+ y: 0,
924
+ name: "",
925
+ desc: ""
926
+ }), Z = m(null), xe = t(() => ({
927
+ position: "absolute",
928
+ top: `${I.y}px`,
929
+ left: `${I.x}px`,
930
+ transformOrigin: "0 0",
931
+ transform: `scale(${F.value})`,
932
+ width: "60px",
933
+ height: "60px"
934
+ })), Se = t(() => ({
935
+ position: "absolute",
936
+ left: `${Y.x}px`,
937
+ top: `${Y.y}px`
938
+ })), Ce = t(() => ({
939
+ position: "absolute",
940
+ left: `${X.x}px`,
941
+ top: `${X.y}px`
942
+ })), we = (e) => Math.max(.5, Math.min(2, e)), Te = (e, t) => Math.hypot(e.clientX - t.clientX, e.clientY - t.clientY), Ee = (e) => {
943
+ if (e.touches.length === 1) z.value = "pan", B.x = e.touches[0].clientX, B.y = e.touches[0].clientY, H.value = null, L.value = !1, Q();
944
+ else if (e.touches.length === 2) {
945
+ z.value = "pinch";
946
+ let t = Z.value?.getBoundingClientRect();
947
+ V.startDist = Te(e.touches[0], e.touches[1]), V.startScale = F.value, V.startX = I.x, V.startY = I.y, V.midX = (e.touches[0].clientX + e.touches[1].clientX) / 2, V.midY = (e.touches[0].clientY + e.touches[1].clientY) / 2, V.rectLeft = t?.left ?? 0, V.rectTop = t?.top ?? 0;
948
+ }
949
+ k(e);
950
+ }, De = (e) => {
951
+ if (z.value === "pan" && e.touches.length === 1) {
952
+ let t = e.touches[0].clientX - B.x, n = e.touches[0].clientY - B.y;
953
+ I.x += t, I.y += n, B.x = e.touches[0].clientX, B.y = e.touches[0].clientY;
954
+ } else if (z.value === "pinch" && e.touches.length === 2) {
955
+ let t = Te(e.touches[0], e.touches[1]), n = (e.touches[0].clientX + e.touches[1].clientX) / 2, r = (e.touches[0].clientY + e.touches[1].clientY) / 2;
956
+ if (V.startDist > 0) {
957
+ let e = we(V.startScale * (t / V.startDist)), i = (V.midX - V.rectLeft - V.startX) / V.startScale, a = (V.midY - V.rectTop - V.startY) / V.startScale;
958
+ F.value = e, I.x = n - V.rectLeft - i * e, I.y = r - V.rectTop - a * e;
959
+ }
960
+ }
961
+ k(e);
962
+ }, Oe = (e) => {
963
+ e.touches.length === 0 ? z.value = "none" : e.touches.length === 1 && z.value === "pinch" && (z.value = "pan", B.x = e.touches[0].clientX, B.y = e.touches[0].clientY);
964
+ }, ke = (e) => {
965
+ e.button === 0 && !H.value && !W.value && (L.value = !0, R.x = e.clientX, R.y = e.clientY, k(e));
966
+ }, Ae = (e, t, n, r) => {
967
+ $(), H.value = e, U.x = t.clientX, U.y = t.clientY, U.initialX = n, U.initialY = r, L.value = !1, k(t);
968
+ }, je = (e) => {
969
+ W.value && (P.endType = e);
970
+ }, Me = () => {
971
+ W.value && (P.endType = void 0);
972
+ }, Ne = (e, t) => {
973
+ if (k(t), W.value && G.value && G.value.nodeId !== e.nodeId) {
974
+ if (ae(j.value, G.value.id, e.id)) {
975
+ Q(), alert("该锚点之间已存在连线,禁止重复创建!");
976
+ return;
977
+ }
978
+ let t = {
979
+ id: O(),
980
+ fromAnchorId: G.value.id,
981
+ toAnchorId: e.id
982
+ };
983
+ j.value.push(t), T("update:lines", j.value), Q();
984
+ return;
985
+ }
986
+ if (!W.value) {
987
+ $(), W.value = !0, G.value = e, L.value = !1;
988
+ let t = A.value.find((t) => t.id === e.nodeId);
989
+ if (!t) return;
990
+ let n = D(e, t);
991
+ switch (P.visible = !0, P.startX = n.x, P.startY = n.y, P.startType = e.type, e.type) {
992
+ case "top":
993
+ P.endX = n.x, P.endY = n.y - 50;
994
+ break;
995
+ case "bottom":
996
+ P.endX = n.x, P.endY = n.y + 50;
997
+ break;
998
+ case "left":
999
+ P.endX = n.x - 50, P.endY = n.y;
1000
+ break;
1001
+ case "right": P.endX = n.x + 50, P.endY = n.y;
1002
+ }
1003
+ }
1004
+ }, Pe = (e) => {
1005
+ if (H.value) {
1006
+ if (!A.value.find((e) => e.id === H.value)) return;
1007
+ let t = (e.clientX - U.x) / F.value, n = (e.clientY - U.y) / F.value, r = U.initialX + t, i = U.initialY + n, a = A.value.findIndex((e) => e.id === H.value);
1008
+ if (a !== -1) {
1009
+ let e = A.value[a].anchors.map((e) => {
1010
+ let t = D(e, {
1011
+ ...A.value[a],
1012
+ x: r,
1013
+ y: i
1014
+ });
1015
+ return {
1016
+ ...e,
1017
+ x: t.x,
1018
+ y: t.y
1019
+ };
1020
+ });
1021
+ A.value[a] = {
1022
+ ...A.value[a],
1023
+ x: r,
1024
+ y: i,
1025
+ anchors: e
1026
+ };
1027
+ }
1028
+ } else if (W.value && G.value) {
1029
+ let t = Z.value?.getBoundingClientRect();
1030
+ if (!t) return;
1031
+ let n = (e.clientX - t.left - I.x) / F.value, r = (e.clientY - t.top - I.y) / F.value;
1032
+ P.endX = n, P.endY = r;
1033
+ } else if (L.value) {
1034
+ let t = e.clientX - R.x, n = e.clientY - R.y;
1035
+ I.x += t, I.y += n, R.x = e.clientX, R.y = e.clientY;
1036
+ }
1037
+ }, Fe = (e) => {
1038
+ if (L.value) L.value = !1;
1039
+ else if (H.value) H.value = null, T("update:nodes", A.value);
1040
+ else if (W.value && G.value) {
1041
+ let t = Z.value?.getBoundingClientRect();
1042
+ if (!t) {
1043
+ Q();
1044
+ return;
1045
+ }
1046
+ let n = ee(e.clientX, e.clientY, M.value, I, F.value, t);
1047
+ if (n && n.nodeId !== G.value.nodeId && !ae(j.value, G.value.id, n.id)) {
1048
+ let e = {
1049
+ id: O(),
1050
+ fromAnchorId: G.value.id,
1051
+ toAnchorId: n.id
1052
+ };
1053
+ j.value.push(e), T("update:lines", j.value);
1054
+ }
1055
+ Q();
1056
+ }
1057
+ }, Q = () => {
1058
+ W.value = !1, G.value = null, P.visible = !1, P.startX = 0, P.startY = 0, P.endX = 0, P.endY = 0, P.startType = void 0, P.endType = void 0;
1059
+ }, Ie = (e) => {
1060
+ if (e.altKey) {
1061
+ k(e);
1062
+ let t = F.value + (e.deltaY < 0 ? .1 : -.1);
1063
+ F.value = we(t);
1064
+ }
1065
+ }, Le = (e, t) => {
1066
+ k(t), ve = !0, q = !0;
1067
+ let n = A.value.find((t) => t.id === e);
1068
+ if (!n) return;
1069
+ let r = Z.value?.getBoundingClientRect();
1070
+ r && (Y.type = "node", Y.x = t.clientX - r.left, Y.y = t.clientY - r.top, Y.targetId = e, X.nodeId = e, X.name = n.name, X.desc = n.desc || "", setTimeout(() => {
1071
+ q = !1;
1072
+ }, 100));
1073
+ }, Re = (e) => {
1074
+ T("beforeDeleteNode", e);
1075
+ let t = /* @__PURE__ */ new Map();
1076
+ for (let e of A.value) for (let n of e.anchors) t.set(n.id, e.id);
1077
+ A.value = A.value.filter((t) => t.id !== e), T("update:nodes", A.value), j.value = j.value.filter((n) => t.get(n.fromAnchorId) !== e && t.get(n.toAnchorId) !== e), T("update:lines", j.value), K.value = "";
1078
+ }, ze = (e) => {
1079
+ T("beforeDeleteLine", e), j.value = j.value.filter((t) => t.id !== e), T("update:lines", j.value), K.value = "", $();
1080
+ }, Be = () => {
1081
+ Y.targetId && (Re(Y.targetId), $());
1082
+ }, Ve = (e = {}) => {
1083
+ T("beforeAddNode", e);
1084
+ let t = e.width ?? 140, n = e.height ?? 200, r = e.x ?? 100, i = e.y ?? 100, a = `node_${Date.now()}_${Math.random().toString(36).slice(2, 7)}`, o = {
1085
+ id: a,
1086
+ name: e.name ?? "新节点",
1087
+ desc: e.desc,
1088
+ pic: e.pic,
1089
+ x: r,
1090
+ y: i,
1091
+ width: t,
1092
+ height: n,
1093
+ anchors: [
1094
+ {
1095
+ id: `${a}-top`,
1096
+ nodeId: a,
1097
+ type: "top",
1098
+ x: r + t / 2,
1099
+ y: i
1100
+ },
1101
+ {
1102
+ id: `${a}-bottom`,
1103
+ nodeId: a,
1104
+ type: "bottom",
1105
+ x: r + t / 2,
1106
+ y: i + n
1107
+ },
1108
+ {
1109
+ id: `${a}-left`,
1110
+ nodeId: a,
1111
+ type: "left",
1112
+ x: r,
1113
+ y: i + n / 2
1114
+ },
1115
+ {
1116
+ id: `${a}-right`,
1117
+ nodeId: a,
1118
+ type: "right",
1119
+ x: r + t,
1120
+ y: i + n / 2
1121
+ }
1122
+ ]
1123
+ };
1124
+ return A.value.push(o), T("update:nodes", A.value), o;
1125
+ }, He = () => {
1126
+ if (!Y.x || !Y.y) return;
1127
+ let e = (Y.x - I.x) / F.value + 50, t = (Y.y - I.y) / F.value + 50, n = Y.targetId ? A.value.find((e) => e.id === Y.targetId) : void 0;
1128
+ Ve({
1129
+ x: e,
1130
+ y: t,
1131
+ width: n?.width,
1132
+ height: n?.height
1133
+ }), $();
1134
+ }, Ue = () => {
1135
+ if (!Y.targetId) return;
1136
+ let e = A.value.find((e) => e.id === Y.targetId);
1137
+ e && (X.visible = !0, X.nodeId = Y.targetId, X.x = Y.x, X.y = Y.y, X.name = e.name, X.desc = e.desc || "", Y.type = "none", q = !0, setTimeout(() => {
1138
+ q = !1;
1139
+ }, 100));
1140
+ }, We = () => {
1141
+ if (!X.nodeId) return;
1142
+ let e = A.value.findIndex((e) => e.id === X.nodeId);
1143
+ e !== -1 && (A.value[e] = {
1144
+ ...A.value[e],
1145
+ name: X.name || "未命名节点",
1146
+ desc: X.desc
1147
+ }, T("update:nodes", A.value)), X.visible = !1;
1148
+ }, Ge = (e, t) => {
1149
+ let n = Z.value?.getBoundingClientRect();
1150
+ if (!n) return null;
1151
+ let r = (e - n.left - I.x) / F.value, i = (t - n.top - I.y) / F.value;
1152
+ for (let e = M.value.length - 1; e >= 0; e--) {
1153
+ let t = M.value[e];
1154
+ if (r >= t.x && r <= t.x + t.width && i >= t.y && i <= t.y + t.height) return t;
1155
+ }
1156
+ return null;
1157
+ }, Ke = (e) => {
1158
+ let t = Z.value?.getBoundingClientRect();
1159
+ if (!t) return;
1160
+ if (Ge(e.clientX, e.clientY)) {
1161
+ K.value = "";
1162
+ return;
1163
+ }
1164
+ let n = re(M.value), r = N.value.filter((r) => ne(r, M.value, e.clientX, e.clientY, I, F.value, t, 8, n));
1165
+ if (r.length) {
1166
+ let e = ie(N.value, r, K.value);
1167
+ K.value = e;
1168
+ } else K.value = "";
1169
+ }, qe = (e) => {
1170
+ if (ve) {
1171
+ ve = !1;
1172
+ return;
1173
+ }
1174
+ let t = Z.value?.getBoundingClientRect();
1175
+ if (!t) return;
1176
+ k(e), $(), q = !0;
1177
+ let n = Ge(e.clientX, e.clientY);
1178
+ if (n) {
1179
+ Y.type = "node", Y.x = e.clientX - t.left, Y.y = e.clientY - t.top, Y.targetId = n.id, X.nodeId = n.id, X.name = n.name, X.desc = n.desc || "", K.value = "", setTimeout(() => {
1180
+ q = !1;
1181
+ }, 100);
1182
+ return;
1183
+ }
1184
+ let r = re(M.value), i = N.value.filter((n) => ne(n, M.value, e.clientX, e.clientY, I, F.value, t, 8, r));
1185
+ if (i.length) {
1186
+ let n = ie(N.value, i, K.value);
1187
+ K.value = n, Y.type = "line", Y.x = e.clientX - t.left, Y.y = e.clientY - t.top, Y.targetId = n;
1188
+ }
1189
+ setTimeout(() => {
1190
+ q = !1;
1191
+ }, 100);
1192
+ }, $ = () => {
1193
+ Y.type = "none", Y.x = 0, Y.y = 0, Y.targetId = null, X.visible = !1, q = !1;
1194
+ }, Je = (e) => {
1195
+ if (q) return;
1196
+ let t = e.target, n = t.closest(".context-menu"), r = t.closest(".edit-panel"), i = t.closest(".toolbar");
1197
+ !n && !r && !i && $();
1198
+ }, Ye = (e) => {
1199
+ e.key === "Escape" && $();
1200
+ };
1201
+ return u(() => {
1202
+ document.addEventListener("click", Je), document.addEventListener("keydown", Ye);
1203
+ }), d(() => {
1204
+ document.removeEventListener("click", Je), document.removeEventListener("keydown", Ye);
1205
+ }), S({
1206
+ getNodes: () => A.value,
1207
+ getLines: () => j.value,
1208
+ exportData: () => ({
1209
+ nodes: A.value,
1210
+ lines: j.value
1211
+ }),
1212
+ addNode: Ve,
1213
+ deleteNode: Re,
1214
+ deleteLine: ze,
1215
+ toggleAnimation: ye,
1216
+ centerView: be
1217
+ }), (t, u) => (f(), i("div", {
1218
+ class: c(["flow-designer", { "flow-designer--light": s.theme === "light" }]),
1219
+ onContextmenu: u[3] ||= x((e) => _(k)(e), ["prevent"])
1220
+ }, [
1221
+ a("div", {
1222
+ ref_key: "canvasContainerRef",
1223
+ ref: Z,
1224
+ class: c(["canvas-container", { "is-dragging": !!H.value || L.value }]),
1225
+ onMousedown: ke,
1226
+ onMousemove: Pe,
1227
+ onMouseup: Fe,
1228
+ onMouseleave: Fe,
1229
+ onWheel: Ie,
1230
+ onClick: Ke,
1231
+ onContextmenu: x(qe, ["prevent"]),
1232
+ onTouchstart: Ee,
1233
+ onTouchmove: x(De, ["prevent"]),
1234
+ onTouchend: Oe,
1235
+ onTouchcancel: Oe
1236
+ }, [a("div", {
1237
+ class: "canvas-content",
1238
+ style: l(xe.value)
1239
+ }, [o(se, {
1240
+ nodes: M.value,
1241
+ lines: N.value,
1242
+ scale: F.value,
1243
+ "temp-line": P,
1244
+ "selected-line-id": K.value,
1245
+ animated: J.value,
1246
+ theme: s.theme
1247
+ }, null, 8, [
1248
+ "nodes",
1249
+ "lines",
1250
+ "scale",
1251
+ "temp-line",
1252
+ "selected-line-id",
1253
+ "animated",
1254
+ "theme"
1255
+ ]), a("div", de, [(f(!0), i(e, null, h(M.value, (e) => (f(), n(ue, {
1256
+ key: e.id,
1257
+ id: e.id,
1258
+ name: e.name,
1259
+ desc: e.desc,
1260
+ x: e.x,
1261
+ y: e.y,
1262
+ width: e.width,
1263
+ height: e.height,
1264
+ pic: e.pic,
1265
+ "is-dragging": H.value === e.id,
1266
+ onDragStart: Ae,
1267
+ onAnchorClick: Ne,
1268
+ onContextMenu: Le,
1269
+ onAnchorHover: je,
1270
+ onAnchorLeave: Me
1271
+ }, null, 8, [
1272
+ "id",
1273
+ "name",
1274
+ "desc",
1275
+ "x",
1276
+ "y",
1277
+ "width",
1278
+ "height",
1279
+ "pic",
1280
+ "is-dragging"
1281
+ ]))), 128))])], 4)], 34),
1282
+ Y.type === "node" ? (f(), i("div", {
1283
+ key: 0,
1284
+ class: "context-menu",
1285
+ style: l(Se.value)
1286
+ }, [
1287
+ a("div", {
1288
+ class: "context-menu-item",
1289
+ onClick: Ue
1290
+ }, "编辑节点"),
1291
+ a("div", {
1292
+ class: "context-menu-item",
1293
+ onClick: He
1294
+ }, "新增节点"),
1295
+ he.value ? (f(), i("div", {
1296
+ key: 0,
1297
+ class: "context-menu-item",
1298
+ onClick: _e
1299
+ }, g(ge.value ? "显示子节点" : "折叠子节点"), 1)) : r("", !0),
1300
+ u[4] ||= a("div", { class: "context-menu-divider" }, null, -1),
1301
+ a("div", {
1302
+ class: "context-menu-item danger",
1303
+ onClick: Be
1304
+ }, "删除节点")
1305
+ ], 4)) : r("", !0),
1306
+ Y.type === "line" && Y.targetId ? (f(), i("div", {
1307
+ key: 1,
1308
+ class: "context-menu",
1309
+ style: l(Se.value)
1310
+ }, [a("div", {
1311
+ class: "context-menu-item danger",
1312
+ onClick: u[0] ||= (e) => ze(Y.targetId)
1313
+ }, "删除连线")], 4)) : r("", !0),
1314
+ X.visible ? (f(), i("div", {
1315
+ key: 2,
1316
+ class: "edit-panel",
1317
+ style: l(Ce.value)
1318
+ }, [
1319
+ u[7] ||= a("h3", { class: "edit-panel-title" }, "编辑节点", -1),
1320
+ a("div", fe, [u[5] ||= a("label", { class: "edit-panel-label" }, "节点名称", -1), b(a("input", {
1321
+ "onUpdate:modelValue": u[1] ||= (e) => X.name = e,
1322
+ type: "text",
1323
+ class: "edit-panel-input",
1324
+ placeholder: "请输入节点名称"
1325
+ }, null, 512), [[v, X.name]])]),
1326
+ a("div", pe, [u[6] ||= a("label", { class: "edit-panel-label" }, "节点描述", -1), b(a("input", {
1327
+ "onUpdate:modelValue": u[2] ||= (e) => X.desc = e,
1328
+ type: "text",
1329
+ class: "edit-panel-input",
1330
+ placeholder: "可选:输入节点描述信息"
1331
+ }, null, 512), [[v, X.desc]])]),
1332
+ a("div", { class: "edit-panel-actions" }, [a("button", {
1333
+ class: "edit-panel-btn cancel",
1334
+ onClick: $
1335
+ }, "取消"), a("button", {
1336
+ class: "edit-panel-btn save",
1337
+ onClick: We
1338
+ }, "保存")])
1339
+ ], 4)) : r("", !0)
1340
+ ], 34));
1341
+ }
1342
+ }), [["__scopeId", "data-v-0545e5a3"]]);
1343
+ //#endregion
1344
+ export { N as FlowDesigner, se as FlowLinesCanvas, ue as FlowNode, w as SingleLineCanvas, T as TempLineCanvas, re as buildAnchorMap, O as generateLineId, E as getAnchorPosition, D as getLineEndpoint, ee as hitTestAnchor, ae as isDuplicateLine, ne as isHit, oe as relayoutTree, k as stopEvent, ie as toggleSelectedLine };