dishui 0.0.56 → 0.0.57

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