dishui 0.0.46 → 0.0.48

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