dishui 0.0.47 → 0.0.49

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