dishui 0.0.59 → 0.0.60

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.
Files changed (36) hide show
  1. package/dist/components/pro/Flow/Flow.js +517 -543
  2. package/dist/components/pro/Flow/Flow.js.map +1 -1
  3. package/dist/components/pro/Flow/FlowCanvas.js +1092 -947
  4. package/dist/components/pro/Flow/FlowCanvas.js.map +1 -1
  5. package/dist/components/pro/Flow/context/FlowUIContext.d.ts +3 -0
  6. package/dist/components/pro/Flow/context/FlowUIContext.js +67 -64
  7. package/dist/components/pro/Flow/context/FlowUIContext.js.map +1 -1
  8. package/dist/components/pro/Flow/edges/EdgeRenderer.js +1 -1
  9. package/dist/components/pro/Flow/edges/edgePaths.js +170 -159
  10. package/dist/components/pro/Flow/edges/edgePaths.js.map +1 -1
  11. package/dist/components/pro/Flow/hooks/useDeleteSelection.d.ts +8 -0
  12. package/dist/components/pro/Flow/hooks/useDeleteSelection.js +43 -0
  13. package/dist/components/pro/Flow/hooks/useDeleteSelection.js.map +1 -0
  14. package/dist/components/pro/Flow/hooks/useMindMap.js +19 -17
  15. package/dist/components/pro/Flow/hooks/useMindMap.js.map +1 -1
  16. package/dist/components/pro/Flow/lines/LineRenderer.js +1 -1
  17. package/dist/components/pro/Flow/nodes/NodeRenderer.d.ts +2 -0
  18. package/dist/components/pro/Flow/nodes/NodeRenderer.js +174 -145
  19. package/dist/components/pro/Flow/nodes/NodeRenderer.js.map +1 -1
  20. package/dist/components/pro/Flow/nodes/shapes.d.ts +20 -0
  21. package/dist/components/pro/Flow/nodes/shapes.js +438 -203
  22. package/dist/components/pro/Flow/nodes/shapes.js.map +1 -1
  23. package/dist/components/pro/Flow/nodes/svgIconTexture.d.ts +4 -0
  24. package/dist/components/pro/Flow/nodes/svgIconTexture.js.map +1 -1
  25. package/dist/components/pro/Flow/panels/FlowToolbar.d.ts +4 -1
  26. package/dist/components/pro/Flow/panels/FlowToolbar.js +106 -100
  27. package/dist/components/pro/Flow/panels/FlowToolbar.js.map +1 -1
  28. package/dist/components/pro/Flow/panels/InspectorPanel.js +739 -476
  29. package/dist/components/pro/Flow/panels/InspectorPanel.js.map +1 -1
  30. package/dist/components/pro/Flow/panels/toolbarIcons.d.ts +2 -0
  31. package/dist/components/pro/Flow/panels/toolbarIcons.js +30 -25
  32. package/dist/components/pro/Flow/panels/toolbarIcons.js.map +1 -1
  33. package/dist/components/pro/Flow/types.d.ts +32 -0
  34. package/dist/components/pro/Flow/types.js.map +1 -1
  35. package/dist/dishui.css +1 -1
  36. package/package.json +1 -1
@@ -1,16 +1,17 @@
1
- import ge from "../../Select/index.js";
2
- import we from "../CodeEditor/editors/CodeEditor.js";
3
- import { DEFAULT_NODE_DATA as se, ROOT_CANVAS_ID as Ie, createEmptyDocument as ve } from "./constants.js";
4
- import { FlowProvider as ye, useFlowContext as ee } from "./context/FlowContext.js";
5
- import { FlowUIProvider as be, useFlowUI as Y } from "./context/FlowUIContext.js";
6
- import { FlowAIProvider as xe } from "./context/FlowAIContext.js";
1
+ import he from "../../Select/index.js";
2
+ import ge from "../CodeEditor/editors/CodeEditor.js";
3
+ import { DEFAULT_NODE_DATA as se, ROOT_CANVAS_ID as we, createEmptyDocument as Ie } from "./constants.js";
4
+ import { FlowProvider as ve, useFlowContext as ee } from "./context/FlowContext.js";
5
+ import { FlowUIProvider as ye, useFlowUI as Y } from "./context/FlowUIContext.js";
6
+ import { FlowAIProvider as be } from "./context/FlowAIContext.js";
7
7
  import { generateId as Q } from "./nodes/nodeUtils.js";
8
- import { normalizeEdgeHandles as Se } from "./edges/edgePaths.js";
8
+ import { normalizeEdgeHandles as xe } from "./edges/edgePaths.js";
9
+ import { useDeleteSelection as Se } from "./hooks/useDeleteSelection.js";
9
10
  import Ce from "./FlowCanvas.js";
10
11
  import { downloadDataURL as Me, safeFileBaseName as Pe } from "./hooks/useFlowImportExport.js";
11
12
  import Ne, { FlowZoomControls as ke } from "./panels/FlowToolbar.js";
12
- import { MediaStampContent as De, ShapePaletteContent as ze, SvgStampContent as Ee } from "./panels/ShapePalette.js";
13
- import { InspectorPanelContent as Ae } from "./panels/InspectorPanel.js";
13
+ import { MediaStampContent as De, ShapePaletteContent as Ee, SvgStampContent as Ae } from "./panels/ShapePalette.js";
14
+ import { InspectorPanelContent as ze } from "./panels/InspectorPanel.js";
14
15
  import { OutlinePanelContent as Te } from "./panels/OutlinePanel.js";
15
16
  import { AIPanelContent as Re } from "./panels/AIPanel.js";
16
17
  import { PresentationMode as Le } from "./panels/PresentationMode.js";
@@ -23,122 +24,94 @@ import { useUndoRedo as He } from "./hooks/useUndoRedo.js";
23
24
  import { useClipboard as ae } from "./hooks/useClipboard.js";
24
25
  import { useCompactMode as Ue } from "./hooks/useCompactMode.js";
25
26
  import { usePdfExport as Ze } from "./hooks/usePdfExport.js";
26
- import { useKeyboardShortcuts as $e } from "./hooks/useKeyboardShortcuts.js";
27
- import { useMindMap as Je } from "./hooks/useMindMap.js";
27
+ import { useKeyboardShortcuts as Je } from "./hooks/useKeyboardShortcuts.js";
28
+ import { useMindMap as Oe } from "./hooks/useMindMap.js";
28
29
  /* empty css */
29
- import { forwardRef as Oe, useCallback as D, useEffect as X, useImperativeHandle as _e, useMemo as le, useRef as R, useState as j } from "react";
30
- import { jsx as a, jsxs as O } from "react/jsx-runtime";
30
+ import { forwardRef as _e, useCallback as D, useEffect as X, useImperativeHandle as $e, useMemo as le, useRef as R, useState as j } from "react";
31
+ import { jsx as r, jsxs as _ } from "react/jsx-runtime";
31
32
  import { EditorView as Be } from "@codemirror/view";
32
- function Ve(s) {
33
- let m = !1;
34
- const d = { ...s.canvases };
35
- for (const [I, f] of Object.entries(d)) {
36
- const i = f.nodes.map((t) => {
37
- if (t.type !== "shapeSvg") return t;
38
- const g = t.data.labelPlacement, u = g === "above" ? "top" : g === "center" ? "middle" : g === "below" ? "bottom" : t.data.labelPlacement;
39
- return u === t.data.labelPlacement ? t : (m = !0, {
40
- ...t,
33
+ function Ve(o) {
34
+ let p = !1;
35
+ const a = { ...o.canvases };
36
+ for (const [w, u] of Object.entries(a)) {
37
+ const s = u.nodes.map((e) => {
38
+ if (e.type !== "shapeSvg") return e;
39
+ const h = e.data.labelPlacement, c = h === "above" ? "top" : h === "center" ? "middle" : h === "below" ? "bottom" : e.data.labelPlacement;
40
+ return c === e.data.labelPlacement ? e : (p = !0, {
41
+ ...e,
41
42
  data: {
42
- ...t.data,
43
- labelPlacement: u
43
+ ...e.data,
44
+ labelPlacement: c
44
45
  }
45
46
  });
46
47
  });
47
48
  let l = !1;
48
- const o = i.map((t) => {
49
- if (!t.data.isMindMapNode) return t;
50
- const g = t.data.fill === "#ffffff" || t.data.fill === "#eef2ff" ? "theme:base-100" : t.data.fill, u = t.data.stroke === "#6366f1" ? "theme:base-content" : t.data.stroke === "#4f46e5" ? "theme:primary" : t.data.stroke;
51
- return g === t.data.fill && u === t.data.stroke ? t : (l = !0, {
52
- ...t,
49
+ const n = s.map((e) => {
50
+ if (!e.data.isMindMapNode) return e;
51
+ const h = e.data.fill === "#ffffff" || e.data.fill === "#eef2ff" ? "theme:base-100" : e.data.fill, c = e.data.stroke === "#6366f1" ? "theme:base-content" : e.data.stroke === "#4f46e5" ? "theme:primary" : e.data.stroke;
52
+ return h === e.data.fill && c === e.data.stroke ? e : (l = !0, {
53
+ ...e,
53
54
  data: {
54
- ...t.data,
55
- fill: g,
56
- stroke: u
55
+ ...e.data,
56
+ fill: h,
57
+ stroke: c
57
58
  }
58
59
  });
59
- }), h = /* @__PURE__ */ new Map();
60
- for (const t of o) h.set(t.id, t);
61
- let c = !1;
62
- const v = Se(f.edges, h).map((t) => {
63
- if (t.data.strokeColor !== "#94a3b8") return t;
64
- const g = h.get(t.source), u = h.get(t.target);
65
- return !g?.data.isMindMapNode || !u?.data.isMindMapNode ? t : (c = !0, {
66
- ...t,
60
+ }), y = /* @__PURE__ */ new Map();
61
+ for (const e of n) y.set(e.id, e);
62
+ let d = !1;
63
+ const I = xe(u.edges, y).map((e) => {
64
+ if (e.data.strokeColor !== "#94a3b8") return e;
65
+ const h = y.get(e.source), c = y.get(e.target);
66
+ return !h?.data.isMindMapNode || !c?.data.isMindMapNode ? e : (d = !0, {
67
+ ...e,
67
68
  data: {
68
- ...t.data,
69
+ ...e.data,
69
70
  strokeColor: "theme:base-content"
70
71
  }
71
72
  });
72
73
  });
73
- (l || c) && (m = !0), (o !== i || v !== f.edges) && (d[I] = {
74
- ...f,
75
- nodes: o,
76
- edges: v
74
+ (l || d) && (p = !0), (n !== s || I !== u.edges) && (a[w] = {
75
+ ...u,
76
+ nodes: n,
77
+ edges: I
77
78
  });
78
79
  }
79
- return m ? {
80
- ...s,
81
- canvases: d
82
- } : s;
80
+ return p ? {
81
+ ...o,
82
+ canvases: a
83
+ } : o;
83
84
  }
84
- var ce = {
85
+ var je = {
85
86
  nodeIds: /* @__PURE__ */ new Set(),
86
87
  edgeIds: /* @__PURE__ */ new Set(),
87
88
  lineIds: /* @__PURE__ */ new Set()
88
89
  };
89
- function je({ onUndo: s, onRedo: m, groupRef: d, geoGroupRef: I, ungroupRef: f }) {
90
- const { selection: i, setSelection: l, currentCanvas: o, setDoc: h, currentCanvasId: c } = ee(), { viewport: v } = Y(), { copy: t, cut: g, paste: u, duplicate: y } = ae(), b = D(() => {
91
- const { nodeIds: r, edgeIds: p, lineIds: S } = i;
92
- r.size === 0 && p.size === 0 && S.size === 0 || r.size > 1 && !window.confirm(`确定要删除选中的 ${r.size} 个节点吗?`) || (h((k) => {
93
- const e = k.canvases[c];
94
- return e ? {
95
- ...k,
96
- canvases: {
97
- ...k.canvases,
98
- [c]: {
99
- ...e,
100
- nodes: e.nodes.filter((n) => !r.has(n.id)).map((n) => n.parentId && r.has(n.parentId) ? {
101
- ...n,
102
- parentId: void 0
103
- } : n),
104
- edges: e.edges.filter((n) => !p.has(n.id) && !r.has(n.source) && !r.has(n.target)),
105
- lines: e.lines.filter((n) => !S.has(n.id)).map((n) => n.parentId && r.has(n.parentId) ? {
106
- ...n,
107
- parentId: void 0
108
- } : n)
109
- }
110
- }
111
- } : k;
112
- }), l(ce));
113
- }, [
114
- i,
115
- h,
116
- c,
117
- l
118
- ]), w = D(() => {
90
+ function Xe({ onUndo: o, onRedo: p, groupRef: a, geoGroupRef: w, ungroupRef: u }) {
91
+ const { selection: s, setSelection: l, currentCanvas: n, setDoc: y, currentCanvasId: d } = ee(), { viewport: I } = Y(), { copy: e, cut: h, paste: c, duplicate: v } = ae(), b = Se(), g = D(() => {
119
92
  l({
120
- nodeIds: new Set(o.nodes.map((r) => r.id)),
121
- edgeIds: new Set(o.edges.map((r) => r.id)),
122
- lineIds: new Set(o.lines.map((r) => r.id))
93
+ nodeIds: new Set(n.nodes.map((f) => f.id)),
94
+ edgeIds: new Set(n.edges.map((f) => f.id)),
95
+ lineIds: new Set(n.lines.map((f) => f.id))
123
96
  });
124
- }, [o, l]), C = D((r) => {
125
- const p = i.nodeIds, S = i.lineIds;
126
- if (p.size + S.size < 2) return;
127
- const k = o.nodes.filter((N) => p.has(N.id)), e = o.lines.filter((N) => S.has(N.id)), n = 20;
97
+ }, [n, l]), S = D((f) => {
98
+ const m = s.nodeIds, N = s.lineIds;
99
+ if (m.size + N.size < 2) return;
100
+ const E = n.nodes.filter((P) => m.has(P.id)), t = n.lines.filter((P) => N.has(P.id)), i = 20;
128
101
  let x = 1 / 0, W = 1 / 0, T = -1 / 0, H = -1 / 0;
129
- for (const N of k)
130
- x = Math.min(x, N.position.x), W = Math.min(W, N.position.y), T = Math.max(T, N.position.x + N.width), H = Math.max(H, N.position.y + N.height);
131
- for (const N of e) for (const z of N.points)
132
- x = Math.min(x, z.x), W = Math.min(W, z.y), T = Math.max(T, z.x), H = Math.max(H, z.y);
133
- const U = r === "geometryGroup", Z = Q("group"), P = {
102
+ for (const P of E)
103
+ x = Math.min(x, P.position.x), W = Math.min(W, P.position.y), T = Math.max(T, P.position.x + P.width), H = Math.max(H, P.position.y + P.height);
104
+ for (const P of t) for (const k of P.points)
105
+ x = Math.min(x, k.x), W = Math.min(W, k.y), T = Math.max(T, k.x), H = Math.max(H, k.y);
106
+ const U = f === "geometryGroup", Z = Q("group"), M = {
134
107
  id: Z,
135
- type: r,
108
+ type: f,
136
109
  position: {
137
- x: x - n,
138
- y: W - n
110
+ x: x - i,
111
+ y: W - i
139
112
  },
140
- width: T - x + n * 2,
141
- height: H - W + n * 2,
113
+ width: T - x + i * 2,
114
+ height: H - W + i * 2,
142
115
  data: {
143
116
  ...se,
144
117
  label: U ? "Geo Group" : "Group",
@@ -149,157 +122,157 @@ function je({ onUndo: s, onRedo: m, groupRef: d, geoGroupRef: I, ungroupRef: f }
149
122
  isGroup: !0
150
123
  }
151
124
  };
152
- h((N) => {
153
- const z = N.canvases[c];
154
- return z ? {
155
- ...N,
125
+ y((P) => {
126
+ const k = P.canvases[d];
127
+ return k ? {
128
+ ...P,
156
129
  canvases: {
157
- ...N.canvases,
158
- [c]: {
159
- ...z,
160
- nodes: U ? [P, ...z.nodes] : [P, ...z.nodes.map((J) => p.has(J.id) ? {
161
- ...J,
130
+ ...P.canvases,
131
+ [d]: {
132
+ ...k,
133
+ nodes: U ? [M, ...k.nodes] : [M, ...k.nodes.map((O) => m.has(O.id) ? {
134
+ ...O,
162
135
  parentId: Z
163
- } : J)],
164
- lines: U ? z.lines : z.lines.map((J) => S.has(J.id) ? {
165
- ...J,
136
+ } : O)],
137
+ lines: U ? k.lines : k.lines.map((O) => N.has(O.id) ? {
138
+ ...O,
166
139
  parentId: Z
167
- } : J)
140
+ } : O)
168
141
  }
169
142
  }
170
- } : N;
143
+ } : P;
171
144
  }), l({
172
145
  nodeIds: /* @__PURE__ */ new Set([Z]),
173
146
  edgeIds: /* @__PURE__ */ new Set(),
174
147
  lineIds: /* @__PURE__ */ new Set()
175
148
  });
176
149
  }, [
177
- i,
178
- o,
179
- h,
180
- c,
150
+ s,
151
+ n,
152
+ y,
153
+ d,
181
154
  l
182
- ]), G = D(() => C("flowGroup"), [C]), L = D(() => C("geometryGroup"), [C]), K = D(() => {
183
- const r = i.nodeIds;
184
- if (r.size === 0) return;
185
- const p = /* @__PURE__ */ new Set(), S = /* @__PURE__ */ new Set(), k = /* @__PURE__ */ new Set();
186
- for (const e of o.nodes) r.has(e.id) && (e.type === "flowGroup" || e.type === "geometryGroup" || e.data.isGroup) && p.add(e.id);
187
- if (p.size !== 0) {
188
- for (const e of o.nodes) e.parentId && p.has(e.parentId) && S.add(e.id);
189
- for (const e of o.lines) e.parentId && p.has(e.parentId) && k.add(e.id);
190
- h((e) => {
191
- const n = e.canvases[c];
192
- return n ? {
193
- ...e,
155
+ ]), G = D(() => S("flowGroup"), [S]), L = D(() => S("geometryGroup"), [S]), K = D(() => {
156
+ const f = s.nodeIds;
157
+ if (f.size === 0) return;
158
+ const m = /* @__PURE__ */ new Set(), N = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Set();
159
+ for (const t of n.nodes) f.has(t.id) && (t.type === "flowGroup" || t.type === "geometryGroup" || t.data.isGroup) && m.add(t.id);
160
+ if (m.size !== 0) {
161
+ for (const t of n.nodes) t.parentId && m.has(t.parentId) && N.add(t.id);
162
+ for (const t of n.lines) t.parentId && m.has(t.parentId) && E.add(t.id);
163
+ y((t) => {
164
+ const i = t.canvases[d];
165
+ return i ? {
166
+ ...t,
194
167
  canvases: {
195
- ...e.canvases,
196
- [c]: {
197
- ...n,
198
- nodes: n.nodes.filter((x) => !p.has(x.id)).map((x) => S.has(x.id) ? {
168
+ ...t.canvases,
169
+ [d]: {
170
+ ...i,
171
+ nodes: i.nodes.filter((x) => !m.has(x.id)).map((x) => N.has(x.id) ? {
199
172
  ...x,
200
173
  parentId: void 0
201
174
  } : x),
202
- lines: n.lines.map((x) => k.has(x.id) ? {
175
+ lines: i.lines.map((x) => E.has(x.id) ? {
203
176
  ...x,
204
177
  parentId: void 0
205
178
  } : x)
206
179
  }
207
180
  }
208
- } : e;
181
+ } : t;
209
182
  }), l({
210
- nodeIds: S,
183
+ nodeIds: N,
211
184
  edgeIds: /* @__PURE__ */ new Set(),
212
- lineIds: k
185
+ lineIds: E
213
186
  });
214
187
  }
215
188
  }, [
216
- i,
217
- o,
218
- h,
219
- c,
189
+ s,
190
+ n,
191
+ y,
192
+ d,
220
193
  l
221
194
  ]);
222
- d.current = G, I.current = L, f.current = K;
223
- const M = D((r) => {
224
- const p = i.nodeIds, S = i.lineIds;
225
- p.size === 0 && S.size === 0 || h((k) => {
226
- const e = k.canvases[c];
227
- if (!e) return k;
228
- const n = e.nodes.map((P) => P.zIndex ?? 0), x = n.length > 0 ? Math.max(...n) : 0, W = n.length > 0 ? Math.min(...n) : 0, T = e.lines.map((P) => P.zIndex ?? 0), H = T.length > 0 ? Math.max(...T) : 0, U = T.length > 0 ? Math.min(...T) : 0, Z = (P, N, z) => r === "front" ? N + 1 : r === "back" ? z - 1 : r === "up" ? P + 1 : P - 1;
195
+ a.current = G, w.current = L, u.current = K;
196
+ const C = D((f) => {
197
+ const m = s.nodeIds, N = s.lineIds;
198
+ m.size === 0 && N.size === 0 || y((E) => {
199
+ const t = E.canvases[d];
200
+ if (!t) return E;
201
+ const i = t.nodes.map((M) => M.zIndex ?? 0), x = i.length > 0 ? Math.max(...i) : 0, W = i.length > 0 ? Math.min(...i) : 0, T = t.lines.map((M) => M.zIndex ?? 0), H = T.length > 0 ? Math.max(...T) : 0, U = T.length > 0 ? Math.min(...T) : 0, Z = (M, P, k) => f === "front" ? P + 1 : f === "back" ? k - 1 : f === "up" ? M + 1 : M - 1;
229
202
  return {
230
- ...k,
203
+ ...E,
231
204
  canvases: {
232
- ...k.canvases,
233
- [c]: {
234
- ...e,
235
- nodes: e.nodes.map((P) => p.has(P.id) ? {
236
- ...P,
237
- zIndex: Z(P.zIndex ?? 0, x, W)
238
- } : P),
239
- lines: e.lines.map((P) => S.has(P.id) ? {
240
- ...P,
241
- zIndex: Z(P.zIndex ?? 0, H, U)
242
- } : P)
205
+ ...E.canvases,
206
+ [d]: {
207
+ ...t,
208
+ nodes: t.nodes.map((M) => m.has(M.id) ? {
209
+ ...M,
210
+ zIndex: Z(M.zIndex ?? 0, x, W)
211
+ } : M),
212
+ lines: t.lines.map((M) => N.has(M.id) ? {
213
+ ...M,
214
+ zIndex: Z(M.zIndex ?? 0, H, U)
215
+ } : M)
243
216
  }
244
217
  }
245
218
  };
246
219
  });
247
220
  }, [
248
- i,
249
- h,
250
- c
221
+ s,
222
+ y,
223
+ d
251
224
  ]);
252
225
  return X(() => {
253
- const r = (p) => {
254
- const S = p.target;
255
- if (S?.tagName === "INPUT" || S?.tagName === "TEXTAREA" || S?.isContentEditable) return;
256
- const k = Array.from(p.clipboardData?.items ?? []).find((x) => x.type.startsWith("image/"));
257
- if (!k) {
258
- p.preventDefault(), u();
226
+ const f = (m) => {
227
+ const N = m.target;
228
+ if (N?.tagName === "INPUT" || N?.tagName === "TEXTAREA" || N?.isContentEditable) return;
229
+ const E = Array.from(m.clipboardData?.items ?? []).find((x) => x.type.startsWith("image/"));
230
+ if (!E) {
231
+ m.preventDefault(), c();
259
232
  return;
260
233
  }
261
- const e = k.getAsFile();
262
- if (!e) return;
263
- p.preventDefault();
264
- const n = new FileReader();
265
- n.onload = () => {
266
- if (typeof n.result != "string") return;
267
- const x = i.nodeIds.size === 1 ? o.nodes.find((E) => i.nodeIds.has(E.id) && E.type === "mediaNode" && E.data.mediaKind === "image") : void 0;
234
+ const t = E.getAsFile();
235
+ if (!t) return;
236
+ m.preventDefault();
237
+ const i = new FileReader();
238
+ i.onload = () => {
239
+ if (typeof i.result != "string") return;
240
+ const x = s.nodeIds.size === 1 ? n.nodes.find((A) => s.nodeIds.has(A.id) && A.type === "mediaNode" && A.data.mediaKind === "image") : void 0;
268
241
  if (x) {
269
- h((E) => {
270
- const _ = E.canvases[c];
271
- return _ ? {
272
- ...E,
242
+ y((A) => {
243
+ const $ = A.canvases[d];
244
+ return $ ? {
245
+ ...A,
273
246
  canvases: {
274
- ...E.canvases,
275
- [c]: {
276
- ..._,
277
- nodes: _.nodes.map((V) => V.id === x.id ? {
247
+ ...A.canvases,
248
+ [d]: {
249
+ ...$,
250
+ nodes: $.nodes.map((V) => V.id === x.id ? {
278
251
  ...V,
279
252
  data: {
280
253
  ...V.data,
281
- mediaContent: n.result
254
+ mediaContent: i.result
282
255
  }
283
256
  } : V)
284
257
  }
285
258
  }
286
- } : E;
259
+ } : A;
287
260
  });
288
261
  return;
289
262
  }
290
- const W = Q("node"), T = 320, H = 220, U = window.innerWidth, Z = window.innerHeight, P = (U / 2 - v.x) / v.zoom, N = (Z / 2 - v.y) / v.zoom, z = Math.max(0, ...o.nodes.map((E) => E.zIndex ?? 0)), J = {
263
+ const W = Q("node"), T = 320, H = 220, U = window.innerWidth, Z = window.innerHeight, M = (U / 2 - I.x) / I.zoom, P = (Z / 2 - I.y) / I.zoom, k = Math.max(0, ...n.nodes.map((A) => A.zIndex ?? 0)), O = {
291
264
  id: W,
292
265
  type: "mediaNode",
293
266
  position: {
294
- x: P - T / 2,
295
- y: N - H / 2
267
+ x: M - T / 2,
268
+ y: P - H / 2
296
269
  },
297
270
  width: T,
298
271
  height: H,
299
- zIndex: z + 1,
272
+ zIndex: k + 1,
300
273
  data: {
301
274
  ...se,
302
- label: e.name || "Image",
275
+ label: t.name || "Image",
303
276
  fill: "theme:base-100",
304
277
  stroke: "theme:base-content",
305
278
  strokeWidth: 1.5,
@@ -307,182 +280,183 @@ function je({ onUndo: s, onRedo: m, groupRef: d, geoGroupRef: I, ungroupRef: f }
307
280
  fontSize: 13,
308
281
  borderStyle: "solid",
309
282
  mediaKind: "image",
310
- mediaContent: n.result
283
+ mediaContent: i.result
311
284
  }
312
285
  };
313
- h((E) => {
314
- const _ = E.canvases[c];
315
- return _ ? {
316
- ...E,
286
+ y((A) => {
287
+ const $ = A.canvases[d];
288
+ return $ ? {
289
+ ...A,
317
290
  canvases: {
318
- ...E.canvases,
319
- [c]: {
320
- ..._,
321
- nodes: [..._.nodes, J]
291
+ ...A.canvases,
292
+ [d]: {
293
+ ...$,
294
+ nodes: [...$.nodes, O]
322
295
  }
323
296
  }
324
- } : E;
297
+ } : A;
325
298
  }), l({
326
299
  nodeIds: /* @__PURE__ */ new Set([W]),
327
300
  edgeIds: /* @__PURE__ */ new Set(),
328
301
  lineIds: /* @__PURE__ */ new Set()
329
302
  });
330
- }, n.readAsDataURL(e);
303
+ }, i.readAsDataURL(t);
331
304
  };
332
- return window.addEventListener("paste", r), () => window.removeEventListener("paste", r);
305
+ return window.addEventListener("paste", f), () => window.removeEventListener("paste", f);
333
306
  }, [
334
- o,
307
+ n,
308
+ d,
335
309
  c,
336
- u,
337
- i,
338
- h,
310
+ s,
311
+ y,
339
312
  l,
340
- v
341
- ]), $e(le(() => ({
342
- undo: s,
343
- redo: m,
344
- copy: t,
345
- cut: g,
346
- paste: u,
347
- duplicate: y,
313
+ I
314
+ ]), Je(le(() => ({
315
+ undo: o,
316
+ redo: p,
317
+ copy: e,
318
+ cut: h,
319
+ paste: c,
320
+ duplicate: v,
348
321
  deleteSelected: b,
349
- selectAll: w,
322
+ selectAll: g,
350
323
  group: G,
351
324
  geoGroup: L,
352
325
  ungroup: K,
353
- bringToFront: () => M("front"),
354
- bringForward: () => M("up"),
355
- sendBackward: () => M("down"),
356
- sendToBack: () => M("back")
326
+ bringToFront: () => C("front"),
327
+ bringForward: () => C("up"),
328
+ sendBackward: () => C("down"),
329
+ sendToBack: () => C("back")
357
330
  }), [
358
- s,
359
- m,
360
- t,
361
- g,
362
- u,
363
- y,
331
+ o,
332
+ p,
333
+ e,
334
+ h,
335
+ c,
336
+ v,
364
337
  b,
365
- w,
338
+ g,
366
339
  G,
367
340
  L,
368
341
  K,
369
- M
370
- ])), Je(), null;
342
+ C
343
+ ])), Oe(), null;
371
344
  }
372
- function Xe({ pixiRef: s, exportPdfRef: m }) {
373
- return m.current = Ze(s), null;
345
+ function Ye({ pixiRef: o, exportPdfRef: p }) {
346
+ return p.current = Ze(o), null;
374
347
  }
375
- var Kt = Oe(function({ initialDocument: m, onChange: d, width: I, height: f, readOnly: i = !1, onBack: l, onExportPNG: o, onPublish: h, showMiniMap: c = !0, showGrid: v = !0, gridSize: t = 20, className: g, showAI: u = !0, showAIConfig: y = !0, aiConfig: b }, w) {
376
- const [C, G] = j(() => Ve(m ?? ve())), [L, K] = j(ce), M = R(null), r = R(null), p = R(null), S = R(null), k = Ue(S), { wrappedSetDoc: e, undo: n, redo: x, canUndo: W, canRedo: T } = He(C, G), H = R(null), U = R(null), Z = R(null), P = R(null), N = R(d);
377
- N.current = d;
378
- const z = R(C);
379
- z.current = C, _e(w, () => ({
348
+ var Ht = _e(function({ initialDocument: p, onChange: a, width: w, height: u, readOnly: s = !1, onBack: l, onExportPNG: n, onPublish: y, showMiniMap: d = !0, showGrid: I = !0, gridSize: e = 20, className: h, showAI: c = !0, showAIConfig: v = !0, aiConfig: b }, g) {
349
+ const [S, G] = j(() => Ve(p ?? Ie())), [L, K] = j(je), C = R(null), f = R(null), m = R(null), N = R(null), E = Ue(N), { wrappedSetDoc: t, undo: i, redo: x, canUndo: W, canRedo: T } = He(S, G), H = R(null), U = R(null), Z = R(null), M = R(null), P = R(a);
350
+ P.current = a;
351
+ const k = R(S);
352
+ k.current = S, $e(g, () => ({
380
353
  exportPNG: async (F) => {
381
- const A = M.current;
382
- return !A || A.destroyed ? null : A.exportPNG(F);
354
+ const z = C.current;
355
+ return !z || z.destroyed ? null : z.exportPNG(F);
383
356
  },
384
- getDocument: () => z.current
357
+ getDocument: () => k.current
385
358
  }), []);
386
- const J = D((F) => {
387
- e((A) => {
388
- const B = typeof F == "function" ? F(A) : F;
389
- return i ? B.canvases === A.canvases && B.title === A.title ? B : A : (queueMicrotask(() => N.current?.(B)), B);
359
+ const O = D((F) => {
360
+ t((z) => {
361
+ const B = typeof F == "function" ? F(z) : F;
362
+ return s ? B.canvases === z.canvases && B.title === z.title ? B : z : (queueMicrotask(() => P.current?.(B)), B);
390
363
  });
391
- }, [e, i]), E = D(() => {
392
- i || n();
393
- }, [i, n]), _ = D(() => {
394
- i || x();
395
- }, [i, x]), V = D((F) => {
396
- M.current = F, r.current && !p.current && (p.current = new We(r.current));
397
- }, []), ue = D(async () => {
398
- if (o) return void o();
399
- const F = M.current;
364
+ }, [t, s]), A = D(() => {
365
+ s || i();
366
+ }, [s, i]), $ = D(() => {
367
+ s || x();
368
+ }, [s, x]), V = D((F) => {
369
+ C.current = F, f.current && !m.current && (m.current = new We(f.current));
370
+ }, []), de = D(async () => {
371
+ if (n) return void n();
372
+ const F = C.current;
400
373
  if (!F || F.destroyed) return;
401
- const A = await F.exportPNG(16777215);
402
- A && Me(A, `${Pe(z.current.title)}.png`);
403
- }, [o]), fe = D(async () => {
404
- await P.current?.();
374
+ const z = await F.exportPNG(16777215);
375
+ z && Me(z, `${Pe(k.current.title)}.png`);
376
+ }, [n]), ue = D(async () => {
377
+ await M.current?.();
405
378
  }, []);
406
379
  X(() => {
407
- let F = !1, A = null;
380
+ let F = !1, z = null;
408
381
  const B = () => {
409
- const $ = M.current, ne = p.current;
410
- if (!$ || $.destroyed || !ne) return;
411
- const me = {
412
- x: $.world.position.x,
413
- y: $.world.position.y,
414
- zoom: $.world.scale.x
415
- }, he = C.stack[C.stack.length - 1] ?? "root", oe = C.canvases[he];
416
- oe && ne.update(oe.nodes, me, $.app.screen.width, $.app.screen.height);
382
+ const J = C.current, ne = m.current;
383
+ if (!J || J.destroyed || !ne) return;
384
+ const pe = {
385
+ x: J.world.position.x,
386
+ y: J.world.position.y,
387
+ zoom: J.world.scale.x
388
+ }, me = S.stack[S.stack.length - 1] ?? "root", oe = S.canvases[me];
389
+ oe && ne.update(oe.nodes, pe, J.app.screen.width, J.app.screen.height);
417
390
  }, te = () => {
418
391
  if (F) return;
419
- const $ = M.current;
420
- $ && !$.destroyed && p.current ? ($.app.ticker.add(B), A = $) : requestAnimationFrame(te);
392
+ const J = C.current;
393
+ J && !J.destroyed && m.current ? (J.app.ticker.add(B), z = J) : requestAnimationFrame(te);
421
394
  };
422
395
  return te(), () => {
423
- F = !0, A && !A.destroyed && A.app.ticker.remove(B);
396
+ F = !0, z && !z.destroyed && z.app.ticker.remove(B);
424
397
  };
425
- }, [C]);
426
- const pe = {
427
- width: I ?? "100%",
428
- height: f ?? "100%"
398
+ }, [S]);
399
+ const fe = {
400
+ width: w ?? "100%",
401
+ height: u ?? "100%"
429
402
  };
430
- return /* @__PURE__ */ a("div", {
431
- ref: S,
432
- className: `flow-container ${g ?? ""}`,
433
- style: pe,
434
- children: /* @__PURE__ */ a(ye, {
435
- doc: C,
436
- setDoc: J,
403
+ return /* @__PURE__ */ r("div", {
404
+ ref: N,
405
+ className: `flow-container ${h ?? ""}`,
406
+ style: fe,
407
+ children: /* @__PURE__ */ r(ve, {
408
+ doc: S,
409
+ setDoc: O,
437
410
  selection: L,
438
411
  setSelection: K,
439
- children: /* @__PURE__ */ a(be, {
440
- showMiniMap: c,
441
- showGrid: v,
442
- gridSize: t,
443
- showAI: u,
444
- readOnly: i,
445
- children: /* @__PURE__ */ O(xe, {
412
+ children: /* @__PURE__ */ r(ye, {
413
+ showMiniMap: d,
414
+ showGrid: I,
415
+ gridSize: e,
416
+ showAI: c,
417
+ readOnly: s,
418
+ children: /* @__PURE__ */ _(be, {
446
419
  initialConfig: b,
447
- showAIConfig: y,
420
+ showAIConfig: v,
448
421
  children: [
449
- /* @__PURE__ */ a(je, {
450
- onUndo: E,
451
- onRedo: _,
422
+ /* @__PURE__ */ r(Xe, {
423
+ onUndo: A,
424
+ onRedo: $,
452
425
  groupRef: H,
453
426
  geoGroupRef: U,
454
427
  ungroupRef: Z
455
428
  }),
456
- /* @__PURE__ */ a(Xe, {
457
- pixiRef: M,
458
- exportPdfRef: P
429
+ /* @__PURE__ */ r(Ye, {
430
+ pixiRef: C,
431
+ exportPdfRef: M
459
432
  }),
460
- /* @__PURE__ */ O(et, {
461
- compact: k,
462
- toolbar: i ? null : /* @__PURE__ */ a(Ne, {
433
+ /* @__PURE__ */ _(tt, {
434
+ compact: E,
435
+ toolbar: s ? null : /* @__PURE__ */ r(Ne, {
436
+ compact: E,
463
437
  onBack: l,
464
- onUndo: E,
465
- onRedo: _,
438
+ onUndo: A,
439
+ onRedo: $,
466
440
  canUndo: W,
467
441
  canRedo: T,
468
442
  onGroup: () => H.current?.(),
469
443
  onGeoGroup: () => U.current?.(),
470
444
  onUngroup: () => Z.current?.(),
471
- onExportPNG: ue,
472
- onExportPDF: fe,
473
- onPublish: h
445
+ onExportPNG: de,
446
+ onExportPDF: ue,
447
+ onPublish: y
474
448
  }),
475
449
  children: [
476
- /* @__PURE__ */ a(Ce, { onPixiReady: V }),
477
- /* @__PURE__ */ a(Fe, {}),
478
- /* @__PURE__ */ O(Ye, { children: [!i && /* @__PURE__ */ a(ke, {}), /* @__PURE__ */ a(Ge, {})] }),
479
- !i && /* @__PURE__ */ a(it, {}),
480
- /* @__PURE__ */ a(tt, {
481
- canvasRef: r,
482
- pixiRef: M,
483
- miniMapRef: p
450
+ /* @__PURE__ */ r(Ce, { onPixiReady: V }),
451
+ /* @__PURE__ */ r(Fe, {}),
452
+ /* @__PURE__ */ _(qe, { children: [!s && /* @__PURE__ */ r(ke, {}), /* @__PURE__ */ r(Ge, {})] }),
453
+ !s && /* @__PURE__ */ r(it, {}),
454
+ /* @__PURE__ */ r(nt, {
455
+ canvasRef: f,
456
+ pixiRef: C,
457
+ miniMapRef: m
484
458
  }),
485
- /* @__PURE__ */ a(Le, {})
459
+ /* @__PURE__ */ r(Le, {})
486
460
  ]
487
461
  })
488
462
  ]
@@ -491,15 +465,15 @@ var Kt = Oe(function({ initialDocument: m, onChange: d, width: I, height: f, rea
491
465
  })
492
466
  });
493
467
  });
494
- function Ye({ children: s }) {
495
- const { presentation: m } = Y();
496
- return /* @__PURE__ */ a("div", {
468
+ function qe({ children: o }) {
469
+ const { presentation: p } = Y();
470
+ return /* @__PURE__ */ r("div", {
497
471
  className: "flow-overlay",
498
- style: { display: m ? "none" : void 0 },
499
- children: s
472
+ style: { display: p ? "none" : void 0 },
473
+ children: o
500
474
  });
501
475
  }
502
- var qe = [
476
+ var Qe = [
503
477
  {
504
478
  id: "shapes",
505
479
  label: "Shapes",
@@ -543,199 +517,199 @@ var qe = [
543
517
  showKey: "showAI"
544
518
  }
545
519
  ];
546
- function ie(s) {
547
- switch (s) {
520
+ function re(o) {
521
+ switch (o) {
548
522
  case "shapes":
549
- return /* @__PURE__ */ a(ze, {});
523
+ return /* @__PURE__ */ r(Ee, {});
550
524
  case "icons":
551
- return /* @__PURE__ */ a(Ee, {});
525
+ return /* @__PURE__ */ r(Ae, {});
552
526
  case "media":
553
- return /* @__PURE__ */ a(De, {});
527
+ return /* @__PURE__ */ r(De, {});
554
528
  case "inspector":
555
- return /* @__PURE__ */ a(Ae, {});
529
+ return /* @__PURE__ */ r(ze, {});
556
530
  case "outline":
557
- return /* @__PURE__ */ a(Te, {});
531
+ return /* @__PURE__ */ r(Te, {});
558
532
  case "json":
559
- return /* @__PURE__ */ a(st, {});
533
+ return /* @__PURE__ */ r(rt, {});
560
534
  case "ai":
561
- return /* @__PURE__ */ a(Re, {});
535
+ return /* @__PURE__ */ r(Re, {});
562
536
  default:
563
537
  return null;
564
538
  }
565
539
  }
566
- var Qe = /* @__PURE__ */ new Set([
540
+ var et = /* @__PURE__ */ new Set([
567
541
  "shapes",
568
542
  "icons",
569
543
  "media"
570
544
  ]);
571
- function et({ children: s, toolbar: m, compact: d }) {
572
- const I = Y(), { panelDocks: f, setPanelDock: i, presentation: l, readOnly: o } = I, { setShowPalette: h, setShowInspector: c, setShowOutline: v, setShowJson: t, setShowAI: g } = I, u = o ? [] : qe.filter((e) => !e.showKey || I[e.showKey]), y = (e) => ({
573
- id: e.id,
574
- label: e.label,
575
- icon: e.icon,
576
- content: ie(e.id)
577
- }), [b, w] = j(null), C = R(null);
545
+ function tt({ children: o, toolbar: p, compact: a }) {
546
+ const w = Y(), { panelDocks: u, setPanelDock: s, presentation: l, readOnly: n } = w, { setShowPalette: y, setShowInspector: d, setShowOutline: I, setShowJson: e, setShowAI: h } = w, c = n ? [] : Qe.filter((t) => !t.showKey || w[t.showKey]), v = (t) => ({
547
+ id: t.id,
548
+ label: t.label,
549
+ icon: t.icon,
550
+ content: re(t.id)
551
+ }), [b, g] = j(null), S = R(null);
578
552
  X(() => {
579
- if (!d) {
580
- C.current = null;
553
+ if (!a) {
554
+ S.current = null;
581
555
  return;
582
556
  }
583
- const e = I.pendingPlacement, n = e ? `${e.type}:${e.data?.svgId ?? ""}:${e.data?.mediaKind ?? ""}` : null, x = C.current;
584
- C.current = n, n && n !== x && b && Qe.has(b) && w(null);
557
+ const t = w.pendingPlacement, i = t ? `${t.type}:${t.data?.svgId ?? ""}:${t.data?.mediaKind ?? ""}` : null, x = S.current;
558
+ S.current = i, i && i !== x && b && et.has(b) && g(null);
585
559
  }, [
586
- I.pendingPlacement,
587
- d,
560
+ w.pendingPlacement,
561
+ a,
588
562
  b
589
563
  ]);
590
- const [G, L] = j(null), K = D((e, n) => i(e, n), [i]), M = D((e) => {
591
- e === "inspector" ? c(!1) : e === "outline" ? v(!1) : e === "json" ? t(!1) : e === "ai" ? g(!1) : h(!1);
564
+ const [G, L] = j(null), K = D((t, i) => s(t, i), [s]), C = D((t) => {
565
+ t === "inspector" ? d(!1) : t === "outline" ? I(!1) : t === "json" ? e(!1) : t === "ai" ? h(!1) : y(!1);
592
566
  }, [
593
- c,
594
- v,
595
- t,
596
- g,
597
- h
567
+ d,
568
+ I,
569
+ e,
570
+ h,
571
+ y
598
572
  ]);
599
- if (d && !l) {
600
- const e = u.find((n) => n.id === b) ?? null;
601
- return /* @__PURE__ */ O("div", {
573
+ if (a && !l) {
574
+ const t = c.find((i) => i.id === b) ?? null;
575
+ return /* @__PURE__ */ _("div", {
602
576
  className: "flow-workspace",
603
577
  children: [
604
- m,
605
- u.length > 0 && /* @__PURE__ */ a("div", {
578
+ p,
579
+ c.length > 0 && /* @__PURE__ */ r("div", {
606
580
  className: "flow-mobile-panel-bar",
607
- children: /* @__PURE__ */ a(ge, {
581
+ children: /* @__PURE__ */ r(he, {
608
582
  placeholder: "选择面板…",
609
- options: u.map((n) => ({
610
- value: n.id,
611
- label: n.label
583
+ options: c.map((i) => ({
584
+ value: i.id,
585
+ label: i.label
612
586
  })),
613
587
  value: b ?? void 0,
614
- onChange: (n) => w(String(n))
588
+ onChange: (i) => g(String(i))
615
589
  })
616
590
  }),
617
- /* @__PURE__ */ O("div", {
591
+ /* @__PURE__ */ _("div", {
618
592
  className: "flow-workspace-main",
619
- children: [/* @__PURE__ */ a("div", {
593
+ children: [/* @__PURE__ */ r("div", {
620
594
  className: "flow-stage",
621
- children: s
622
- }), e && /* @__PURE__ */ O("div", {
595
+ children: o
596
+ }), t && /* @__PURE__ */ _("div", {
623
597
  className: "flow-mobile-panel",
624
- children: [/* @__PURE__ */ O("div", {
598
+ children: [/* @__PURE__ */ _("div", {
625
599
  className: "flow-mobile-panel-header",
626
- children: [/* @__PURE__ */ O("span", {
600
+ children: [/* @__PURE__ */ _("span", {
627
601
  className: "flow-mobile-panel-title",
628
- children: [e.icon && /* @__PURE__ */ a("span", {
602
+ children: [t.icon && /* @__PURE__ */ r("span", {
629
603
  className: "flow-panel-tab-icon",
630
- children: e.icon
631
- }), e.label]
632
- }), /* @__PURE__ */ a("button", {
604
+ children: t.icon
605
+ }), t.label]
606
+ }), /* @__PURE__ */ r("button", {
633
607
  type: "button",
634
608
  className: "flow-mobile-panel-close",
635
609
  "aria-label": "关闭面板",
636
- onClick: () => w(null),
610
+ onClick: () => g(null),
637
611
  children: "✕"
638
612
  })]
639
- }), /* @__PURE__ */ a("div", {
613
+ }), /* @__PURE__ */ r("div", {
640
614
  className: "flow-mobile-panel-body",
641
- children: ie(e.id)
615
+ children: re(t.id)
642
616
  })]
643
617
  })]
644
618
  })
645
619
  ]
646
620
  });
647
621
  }
648
- const r = (e) => f[e] ?? "left", p = u.filter((e) => r(e.id) === "left").map(y), S = u.filter((e) => r(e.id) === "right").map(y), k = u.filter((e) => r(e.id) === "float");
649
- return /* @__PURE__ */ O("div", {
622
+ const f = (t) => u[t] ?? "left", m = c.filter((t) => f(t.id) === "left").map(v), N = c.filter((t) => f(t.id) === "right").map(v), E = c.filter((t) => f(t.id) === "float");
623
+ return /* @__PURE__ */ _("div", {
650
624
  className: "flow-workspace",
651
- children: [!l && m, /* @__PURE__ */ O("div", {
625
+ children: [!l && p, /* @__PURE__ */ _("div", {
652
626
  className: "flow-workspace-main",
653
627
  children: [
654
- !l && p.length > 0 && /* @__PURE__ */ a(q, {
655
- tabs: p,
656
- defaultTab: p[0]?.id,
628
+ !l && m.length > 0 && /* @__PURE__ */ r(q, {
629
+ tabs: m,
630
+ defaultTab: m[0]?.id,
657
631
  resizeEdge: "right",
658
632
  defaultWidth: 220,
659
633
  dock: "left",
660
634
  onDock: K,
661
- onClose: M
635
+ onClose: C
662
636
  }),
663
- /* @__PURE__ */ a("div", {
637
+ /* @__PURE__ */ r("div", {
664
638
  className: "flow-stage",
665
- children: s
639
+ children: o
666
640
  }),
667
- !l && S.length > 0 && /* @__PURE__ */ a(q, {
668
- tabs: S,
669
- defaultTab: S[0]?.id,
641
+ !l && N.length > 0 && /* @__PURE__ */ r(q, {
642
+ tabs: N,
643
+ defaultTab: N[0]?.id,
670
644
  resizeEdge: "left",
671
645
  defaultWidth: 220,
672
646
  dock: "right",
673
647
  onDock: K,
674
- onClose: M
648
+ onClose: C
675
649
  }),
676
- !l && k.map((e, n) => /* @__PURE__ */ a(q, {
677
- tabs: [y(e)],
650
+ !l && E.map((t, i) => /* @__PURE__ */ r(q, {
651
+ tabs: [v(t)],
678
652
  resizeEdge: "right",
679
653
  defaultWidth: 220,
680
654
  dock: "float",
681
655
  style: {
682
- top: 48 + n * 40,
683
- left: 24 + n * 30
656
+ top: 48 + i * 40,
657
+ left: 24 + i * 30
684
658
  },
685
659
  onDock: K,
686
- onClose: M,
660
+ onClose: C,
687
661
  onDragHintChange: L
688
- }, e.id)),
689
- !l && G && /* @__PURE__ */ a("div", {
662
+ }, t.id)),
663
+ !l && G && /* @__PURE__ */ r("div", {
690
664
  className: `flow-dock-dropzone flow-dock-dropzone--${G}`,
691
- children: /* @__PURE__ */ a("span", { children: G === "left" ? "⇤ 停靠左侧" : "停靠右侧 ⇥" })
665
+ children: /* @__PURE__ */ r("span", { children: G === "left" ? "⇤ 停靠左侧" : "停靠右侧 ⇥" })
692
666
  })
693
667
  ]
694
668
  })]
695
669
  });
696
670
  }
697
- function tt({ canvasRef: s, pixiRef: m, miniMapRef: d }) {
698
- const { showMiniMap: I, setViewport: f, presentation: i } = Y(), l = R(!1), o = D((t, g) => {
699
- const u = s.current, y = m.current, b = d.current;
700
- if (!u || !y || y.destroyed || !b) return;
701
- const w = u.getBoundingClientRect();
702
- if (w.width === 0 || w.height === 0) return;
703
- const { width: C, height: G } = b.size, L = (t - w.left) / w.width * C, K = (g - w.top) / w.height * G, M = b.minimapToWorld(L, K);
704
- if (!M) return;
705
- const r = y.world.scale.x || 1, p = y.app.screen.width, S = y.app.screen.height;
706
- f({
707
- x: p / 2 - M.x * r,
708
- y: S / 2 - M.y * r,
709
- zoom: r
671
+ function nt({ canvasRef: o, pixiRef: p, miniMapRef: a }) {
672
+ const { showMiniMap: w, setViewport: u, presentation: s } = Y(), l = R(!1), n = D((e, h) => {
673
+ const c = o.current, v = p.current, b = a.current;
674
+ if (!c || !v || v.destroyed || !b) return;
675
+ const g = c.getBoundingClientRect();
676
+ if (g.width === 0 || g.height === 0) return;
677
+ const { width: S, height: G } = b.size, L = (e - g.left) / g.width * S, K = (h - g.top) / g.height * G, C = b.minimapToWorld(L, K);
678
+ if (!C) return;
679
+ const f = v.world.scale.x || 1, m = v.app.screen.width, N = v.app.screen.height;
680
+ u({
681
+ x: m / 2 - C.x * f,
682
+ y: N / 2 - C.y * f,
683
+ zoom: f
710
684
  });
711
685
  }, [
712
- s,
713
- m,
714
- d,
715
- f
716
- ]), h = D((t) => {
717
- t.preventDefault(), t.currentTarget.setPointerCapture(t.pointerId), l.current = !0, o(t.clientX, t.clientY);
718
- }, [o]), c = D((t) => {
719
- l.current && o(t.clientX, t.clientY);
720
- }, [o]), v = D((t) => {
686
+ o,
687
+ p,
688
+ a,
689
+ u
690
+ ]), y = D((e) => {
691
+ e.preventDefault(), e.currentTarget.setPointerCapture(e.pointerId), l.current = !0, n(e.clientX, e.clientY);
692
+ }, [n]), d = D((e) => {
693
+ l.current && n(e.clientX, e.clientY);
694
+ }, [n]), I = D((e) => {
721
695
  l.current = !1;
722
696
  try {
723
- t.currentTarget.releasePointerCapture(t.pointerId);
697
+ e.currentTarget.releasePointerCapture(e.pointerId);
724
698
  } catch {
725
699
  }
726
700
  }, []);
727
- return /* @__PURE__ */ a("div", {
701
+ return /* @__PURE__ */ r("div", {
728
702
  className: "flow-minimap",
729
703
  style: {
730
- display: I && !i ? void 0 : "none",
704
+ display: w && !s ? void 0 : "none",
731
705
  cursor: "pointer"
732
706
  },
733
- onPointerDown: h,
734
- onPointerMove: c,
735
- onPointerUp: v,
707
+ onPointerDown: y,
708
+ onPointerMove: d,
709
+ onPointerUp: I,
736
710
  title: "点击或拖动以移动画布",
737
- children: /* @__PURE__ */ a("canvas", {
738
- ref: s,
711
+ children: /* @__PURE__ */ r("canvas", {
712
+ ref: o,
739
713
  width: 180,
740
714
  height: 120,
741
715
  style: {
@@ -746,97 +720,97 @@ function tt({ canvasRef: s, pixiRef: m, miniMapRef: d }) {
746
720
  })
747
721
  });
748
722
  }
749
- function nt(s, m) {
750
- const d = `"id": "${m}"`, I = s.indexOf(d);
751
- if (I === -1) return null;
752
- let f = 0, i = -1;
753
- for (let o = I; o >= 0; o--)
754
- if (s[o] === "}" && f++, s[o] === "{") {
755
- if (f === 0) {
756
- i = o;
723
+ function ot(o, p) {
724
+ const a = `"id": "${p}"`, w = o.indexOf(a);
725
+ if (w === -1) return null;
726
+ let u = 0, s = -1;
727
+ for (let n = w; n >= 0; n--)
728
+ if (o[n] === "}" && u++, o[n] === "{") {
729
+ if (u === 0) {
730
+ s = n;
757
731
  break;
758
732
  }
759
- f--;
733
+ u--;
760
734
  }
761
- if (i === -1) return null;
762
- f = 0;
735
+ if (s === -1) return null;
736
+ u = 0;
763
737
  let l = -1;
764
- for (let o = i; o < s.length; o++)
765
- if (s[o] === "{" && f++, s[o] === "}" && (f--, f === 0)) {
766
- l = o;
738
+ for (let n = s; n < o.length; n++)
739
+ if (o[n] === "{" && u++, o[n] === "}" && (u--, u === 0)) {
740
+ l = n;
767
741
  break;
768
742
  }
769
743
  return l === -1 ? null : {
770
- startLine: s.slice(0, i).split(`
744
+ startLine: o.slice(0, s).split(`
771
745
  `).length,
772
- endLine: s.slice(0, l + 1).split(`
746
+ endLine: o.slice(0, l + 1).split(`
773
747
  `).length
774
748
  };
775
749
  }
776
- function re(s) {
777
- s.querySelectorAll(".cm-line.flow-json-hl").forEach((m) => m.classList.remove("flow-json-hl"));
750
+ function ie(o) {
751
+ o.querySelectorAll(".cm-line.flow-json-hl").forEach((p) => p.classList.remove("flow-json-hl"));
778
752
  }
779
- function ot(s, m, d) {
780
- const I = s.getView();
781
- if (I)
782
- for (let f = m; f <= d; f++) try {
783
- const i = I.state.doc.line(f), l = I.domAtPos(i.from), o = l.node instanceof HTMLElement ? l.node.closest(".cm-line") : l.node.parentElement?.closest(".cm-line");
784
- o && o.classList.add("flow-json-hl");
753
+ function st(o, p, a) {
754
+ const w = o.getView();
755
+ if (w)
756
+ for (let u = p; u <= a; u++) try {
757
+ const s = w.state.doc.line(u), l = w.domAtPos(s.from), n = l.node instanceof HTMLElement ? l.node.closest(".cm-line") : l.node.parentElement?.closest(".cm-line");
758
+ n && n.classList.add("flow-json-hl");
785
759
  } catch {
786
760
  }
787
761
  }
788
- function st() {
789
- const { setDoc: s, currentCanvasId: m, selection: d, currentCanvas: I } = ee(), [f, i] = j(""), [l, o] = j(null), h = R(!1), c = R(null), v = R(null), t = le(() => d.nodeIds.size + d.edgeIds.size + d.lineIds.size !== 1 ? null : d.nodeIds.size === 1 ? [...d.nodeIds][0] : d.edgeIds.size === 1 ? [...d.edgeIds][0] : d.lineIds.size === 1 ? [...d.lineIds][0] : null, [d]);
762
+ function rt() {
763
+ const { setDoc: o, currentCanvasId: p, selection: a, currentCanvas: w } = ee(), [u, s] = j(""), [l, n] = j(null), y = R(!1), d = R(null), I = R(null), e = le(() => a.nodeIds.size + a.edgeIds.size + a.lineIds.size !== 1 ? null : a.nodeIds.size === 1 ? [...a.nodeIds][0] : a.edgeIds.size === 1 ? [...a.edgeIds][0] : a.lineIds.size === 1 ? [...a.lineIds][0] : null, [a]);
790
764
  X(() => {
791
- if (h.current) {
792
- h.current = !1;
765
+ if (y.current) {
766
+ y.current = !1;
793
767
  return;
794
768
  }
795
- i(JSON.stringify(I, null, 2)), o(null);
796
- }, [I]), X(() => {
797
- const y = v.current;
798
- if (y && re(y), !t) return;
769
+ s(JSON.stringify(w, null, 2)), n(null);
770
+ }, [w]), X(() => {
771
+ const v = I.current;
772
+ if (v && ie(v), !e) return;
799
773
  const b = setTimeout(() => {
800
- const w = nt(f, t);
801
- if (!w || !v.current) return;
802
- const C = c.current?.getView();
803
- if (!C) return;
804
- const G = v.current, L = C.scrollDOM;
774
+ const g = ot(u, e);
775
+ if (!g || !I.current) return;
776
+ const S = d.current?.getView();
777
+ if (!S) return;
778
+ const G = I.current, L = S.scrollDOM;
805
779
  L.style.scrollBehavior = "smooth";
806
- const K = C.state.doc.line(w.startLine);
807
- C.dispatch({ effects: Be.scrollIntoView(K.from, {
780
+ const K = S.state.doc.line(g.startLine);
781
+ S.dispatch({ effects: Be.scrollIntoView(K.from, {
808
782
  y: "start",
809
783
  yMargin: 0
810
784
  }) });
811
- const M = () => {
812
- L.style.scrollBehavior = "", re(G), ot(c.current, w.startLine, w.endLine);
785
+ const C = () => {
786
+ L.style.scrollBehavior = "", ie(G), st(d.current, g.startLine, g.endLine);
813
787
  };
814
- let r;
815
- const p = () => {
816
- clearTimeout(r), r = setTimeout(M, 100);
788
+ let f;
789
+ const m = () => {
790
+ clearTimeout(f), f = setTimeout(C, 100);
817
791
  };
818
- L.addEventListener("scroll", p), r = setTimeout(() => {
819
- L.removeEventListener("scroll", p), M();
792
+ L.addEventListener("scroll", m), f = setTimeout(() => {
793
+ L.removeEventListener("scroll", m), C();
820
794
  }, 800);
821
795
  }, 120);
822
796
  return () => clearTimeout(b);
823
- }, [t, f]);
824
- const g = D((y) => {
825
- i(y);
797
+ }, [e, u]);
798
+ const h = D((v) => {
799
+ s(v);
826
800
  try {
827
- const b = JSON.parse(y);
828
- b && Array.isArray(b.nodes) && Array.isArray(b.edges) && Array.isArray(b.lines) ? (o(null), h.current = !0, s((w) => ({
829
- ...w,
801
+ const b = JSON.parse(v);
802
+ b && Array.isArray(b.nodes) && Array.isArray(b.edges) && Array.isArray(b.lines) ? (n(null), y.current = !0, o((g) => ({
803
+ ...g,
830
804
  canvases: {
831
- ...w.canvases,
832
- [m]: b
805
+ ...g.canvases,
806
+ [p]: b
833
807
  }
834
- }))) : o("JSON must have nodes, edges, lines arrays");
808
+ }))) : n("JSON must have nodes, edges, lines arrays");
835
809
  } catch (b) {
836
- o(b.message?.slice(0, 60) ?? "Invalid JSON");
810
+ n(b.message?.slice(0, 60) ?? "Invalid JSON");
837
811
  }
838
- }, [s, m]), u = t ? d.nodeIds.has(t) ? "Node" : d.edgeIds.has(t) ? "Edge" : "Line" : null;
839
- return /* @__PURE__ */ O("div", {
812
+ }, [o, p]), c = e ? a.nodeIds.has(e) ? "Node" : a.edgeIds.has(e) ? "Edge" : "Line" : null;
813
+ return /* @__PURE__ */ _("div", {
840
814
  style: {
841
815
  display: "flex",
842
816
  flexDirection: "column",
@@ -844,14 +818,14 @@ function st() {
844
818
  minHeight: 0
845
819
  },
846
820
  children: [
847
- /* @__PURE__ */ a("div", {
821
+ /* @__PURE__ */ r("div", {
848
822
  className: "flow-json-header",
849
- children: /* @__PURE__ */ a("span", {
823
+ children: /* @__PURE__ */ r("span", {
850
824
  className: "flow-json-scope",
851
- children: u ? `${u}: ${t.slice(0, 8)}` : "Canvas"
825
+ children: c ? `${c}: ${e.slice(0, 8)}` : "Canvas"
852
826
  })
853
827
  }),
854
- l && /* @__PURE__ */ a("div", {
828
+ l && /* @__PURE__ */ r("div", {
855
829
  style: {
856
830
  fontSize: 11,
857
831
  color: "oklch(var(--er))",
@@ -860,16 +834,16 @@ function st() {
860
834
  },
861
835
  children: l
862
836
  }),
863
- /* @__PURE__ */ a("div", {
864
- ref: v,
837
+ /* @__PURE__ */ r("div", {
838
+ ref: I,
865
839
  style: {
866
840
  flex: 1,
867
841
  minHeight: 0
868
842
  },
869
- children: /* @__PURE__ */ a(we, {
870
- ref: c,
871
- value: f,
872
- onChange: g,
843
+ children: /* @__PURE__ */ r(ge, {
844
+ ref: d,
845
+ value: u,
846
+ onChange: h,
873
847
  language: "json",
874
848
  lineNumbers: !1,
875
849
  height: "100%",
@@ -880,111 +854,111 @@ function st() {
880
854
  });
881
855
  }
882
856
  function it() {
883
- const { contextMenu: s, setContextMenu: m } = Y(), { doc: d, setDoc: I, currentCanvasId: f, pushCanvas: i, setSelection: l } = ee(), { duplicate: o } = ae();
884
- if (!s) return null;
885
- const h = d.canvases[f];
886
- if (!h)
887
- return m(null), null;
888
- const c = s.nodeId ? h.nodes.find((t) => t.id === s.nodeId) : null, v = [];
889
- return c && (v.push({
857
+ const { contextMenu: o, setContextMenu: p } = Y(), { doc: a, setDoc: w, currentCanvasId: u, pushCanvas: s, setSelection: l } = ee(), { duplicate: n } = ae();
858
+ if (!o) return null;
859
+ const y = a.canvases[u];
860
+ if (!y)
861
+ return p(null), null;
862
+ const d = o.nodeId ? y.nodes.find((e) => e.id === o.nodeId) : null, I = [];
863
+ return d && (I.push({
890
864
  label: "Duplicate",
891
865
  icon: "⧉",
892
866
  action: () => {
893
- o(24, 24, { nodeIds: /* @__PURE__ */ new Set([c.id]) });
867
+ n(24, 24, { nodeIds: /* @__PURE__ */ new Set([d.id]) });
894
868
  }
895
- }), v.push({
869
+ }), I.push({
896
870
  label: "---",
897
871
  action: () => {
898
872
  }
899
- }), c.data.childCanvasId ? (v.push({
873
+ }), d.data.childCanvasId ? (I.push({
900
874
  label: "Enter Sub-canvas",
901
875
  icon: "↓",
902
876
  action: () => {
903
- i(c.data.childCanvasId), l({
877
+ s(d.data.childCanvasId), l({
904
878
  nodeIds: /* @__PURE__ */ new Set(),
905
879
  edgeIds: /* @__PURE__ */ new Set(),
906
880
  lineIds: /* @__PURE__ */ new Set()
907
881
  });
908
882
  }
909
- }), v.push({
883
+ }), I.push({
910
884
  label: "---",
911
885
  action: () => {
912
886
  }
913
- }), v.push({
887
+ }), I.push({
914
888
  label: "Delete Sub-canvas",
915
889
  icon: "🗑",
916
890
  danger: !0,
917
891
  action: () => {
918
- const t = c.data.childCanvasId;
919
- I((g) => {
920
- const u = { ...g.canvases };
921
- de(u, t);
922
- const y = u[f];
923
- if (!y) return g;
924
- u[f] = {
925
- ...y,
926
- nodes: y.nodes.map((w) => w.id === c.id ? {
927
- ...w,
892
+ const e = d.data.childCanvasId;
893
+ w((h) => {
894
+ const c = { ...h.canvases };
895
+ ce(c, e);
896
+ const v = c[u];
897
+ if (!v) return h;
898
+ c[u] = {
899
+ ...v,
900
+ nodes: v.nodes.map((g) => g.id === d.id ? {
901
+ ...g,
928
902
  data: {
929
- ...w.data,
903
+ ...g.data,
930
904
  childCanvasId: void 0
931
905
  }
932
- } : w)
906
+ } : g)
933
907
  };
934
- const b = g.stack.filter((w) => u[w]);
935
- return b.length === 0 && b.push(Ie), {
936
- ...g,
937
- canvases: u,
908
+ const b = h.stack.filter((g) => c[g]);
909
+ return b.length === 0 && b.push(we), {
910
+ ...h,
911
+ canvases: c,
938
912
  stack: b
939
913
  };
940
914
  });
941
915
  }
942
- })) : v.push({
916
+ })) : I.push({
943
917
  label: "Create Sub-canvas",
944
918
  icon: "⊞",
945
919
  action: () => {
946
- const t = Q("canvas");
947
- I((g) => {
948
- const u = g.canvases[f];
949
- return u ? {
950
- ...g,
920
+ const e = Q("canvas");
921
+ w((h) => {
922
+ const c = h.canvases[u];
923
+ return c ? {
924
+ ...h,
951
925
  canvases: {
952
- ...g.canvases,
953
- [f]: {
954
- ...u,
955
- nodes: u.nodes.map((y) => y.id === c.id ? {
956
- ...y,
926
+ ...h.canvases,
927
+ [u]: {
928
+ ...c,
929
+ nodes: c.nodes.map((v) => v.id === d.id ? {
930
+ ...v,
957
931
  data: {
958
- ...y.data,
959
- childCanvasId: t
932
+ ...v.data,
933
+ childCanvasId: e
960
934
  }
961
- } : y)
935
+ } : v)
962
936
  },
963
- [t]: {
937
+ [e]: {
964
938
  nodes: [],
965
939
  edges: [],
966
940
  lines: []
967
941
  }
968
942
  }
969
- } : g;
970
- }), i(t);
943
+ } : h;
944
+ }), s(e);
971
945
  }
972
- })), v.length === 0 ? null : /* @__PURE__ */ a(Ke, {
973
- x: s.x,
974
- y: s.y,
975
- items: v,
976
- onClose: () => m(null)
946
+ })), I.length === 0 ? null : /* @__PURE__ */ r(Ke, {
947
+ x: o.x,
948
+ y: o.y,
949
+ items: I,
950
+ onClose: () => p(null)
977
951
  });
978
952
  }
979
- function de(s, m) {
980
- const d = s[m];
981
- if (d) {
982
- for (const I of d.nodes) I.data.childCanvasId && de(s, I.data.childCanvasId);
983
- delete s[m];
953
+ function ce(o, p) {
954
+ const a = o[p];
955
+ if (a) {
956
+ for (const w of a.nodes) w.data.childCanvasId && ce(o, w.data.childCanvasId);
957
+ delete o[p];
984
958
  }
985
959
  }
986
960
  export {
987
- Kt as default
961
+ Ht as default
988
962
  };
989
963
 
990
964
  //# sourceMappingURL=Flow.js.map