dishui 0.0.48 → 0.0.50

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