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