dishui 0.0.64 → 0.0.66

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 (504) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +10 -11
  2. package/dist/chart.js +12 -46
  3. package/dist/code-editor.js +16 -43
  4. package/dist/components/Badge/index.js +11 -13
  5. package/dist/components/Badge/index.js.map +1 -1
  6. package/dist/components/Button/index.js +62 -86
  7. package/dist/components/Button/index.js.map +1 -1
  8. package/dist/components/Card/index.d.ts +87 -0
  9. package/dist/components/Card/index.js +178 -44
  10. package/dist/components/Card/index.js.map +1 -1
  11. package/dist/components/Chart/Chart.js +25 -25
  12. package/dist/components/Chart/Chart.js.map +1 -1
  13. package/dist/components/Checkbox/index.js +57 -63
  14. package/dist/components/Checkbox/index.js.map +1 -1
  15. package/dist/components/ChoicePicker/index.d.ts +44 -0
  16. package/dist/components/ChoicePicker/index.js +81 -0
  17. package/dist/components/ChoicePicker/index.js.map +1 -0
  18. package/dist/components/Column/index.d.ts +28 -0
  19. package/dist/components/Column/index.js +30 -0
  20. package/dist/components/Column/index.js.map +1 -0
  21. package/dist/components/DateTimeInput/index.d.ts +44 -0
  22. package/dist/components/DateTimeInput/index.js +48 -0
  23. package/dist/components/DateTimeInput/index.js.map +1 -0
  24. package/dist/components/Demo/index.js +107 -107
  25. package/dist/components/Demo/index.js.map +1 -1
  26. package/dist/components/Divider/index.d.ts +20 -0
  27. package/dist/components/Divider/index.js +30 -0
  28. package/dist/components/Divider/index.js.map +1 -0
  29. package/dist/components/EmptyState/index.d.ts +4 -1
  30. package/dist/components/EmptyState/index.js +24 -24
  31. package/dist/components/EmptyState/index.js.map +1 -1
  32. package/dist/components/FileUploader/DropZone.js +134 -136
  33. package/dist/components/FileUploader/DropZone.js.map +1 -1
  34. package/dist/components/FileUploader/FileItem.js +159 -163
  35. package/dist/components/FileUploader/FileItem.js.map +1 -1
  36. package/dist/components/FileUploader/FileUploader.js +126 -127
  37. package/dist/components/FileUploader/FileUploader.js.map +1 -1
  38. package/dist/components/FileUploader/UploadQueue.js +62 -62
  39. package/dist/components/FileUploader/UploadQueue.js.map +1 -1
  40. package/dist/components/FloatWindow/index.d.ts +28 -0
  41. package/dist/components/GridLayout/index.d.ts +42 -0
  42. package/dist/components/Icon/index.d.ts +24 -0
  43. package/dist/components/Icon/index.js +26 -0
  44. package/dist/components/Icon/index.js.map +1 -0
  45. package/dist/components/Image/index.d.ts +33 -0
  46. package/dist/components/Image/index.js +44 -0
  47. package/dist/components/Image/index.js.map +1 -0
  48. package/dist/components/Input/index.js +196 -197
  49. package/dist/components/Input/index.js.map +1 -1
  50. package/dist/components/Label/index.js +62 -73
  51. package/dist/components/Label/index.js.map +1 -1
  52. package/dist/components/Layout/index.js +134 -139
  53. package/dist/components/Layout/index.js.map +1 -1
  54. package/dist/components/List/index.js +45 -43
  55. package/dist/components/List/index.js.map +1 -1
  56. package/dist/components/Markdown/Markdown.js +106 -103
  57. package/dist/components/Markdown/Markdown.js.map +1 -1
  58. package/dist/components/Markdown/codeThemes.js +24 -33
  59. package/dist/components/Markdown/codeThemes.js.map +1 -1
  60. package/dist/components/Markdown/markdownComponents.js +203 -208
  61. package/dist/components/Markdown/markdownComponents.js.map +1 -1
  62. package/dist/components/Markdown/parseCodeBlockMeta.js +22 -22
  63. package/dist/components/Markdown/parseCodeBlockMeta.js.map +1 -1
  64. package/dist/components/Markdown/useMarkdownSource.js +46 -46
  65. package/dist/components/Markdown/useMarkdownSource.js.map +1 -1
  66. package/dist/components/Markdown/useMarkmapRenderer.js +35 -36
  67. package/dist/components/Markdown/useMarkmapRenderer.js.map +1 -1
  68. package/dist/components/Markdown/useMermaidRenderer.js +41 -42
  69. package/dist/components/Markdown/useMermaidRenderer.js.map +1 -1
  70. package/dist/components/Modal/index.d.ts +7 -3
  71. package/dist/components/Modal/index.js +82 -70
  72. package/dist/components/Modal/index.js.map +1 -1
  73. package/dist/components/MultipleChoice/index.d.ts +44 -0
  74. package/dist/components/MultipleChoice/index.js +52 -0
  75. package/dist/components/MultipleChoice/index.js.map +1 -0
  76. package/dist/components/Notification/index.d.ts +17 -0
  77. package/dist/components/Page/index.d.ts +58 -0
  78. package/dist/components/Page/index.js +43 -0
  79. package/dist/components/Page/index.js.map +1 -0
  80. package/dist/components/PageHeader/index.js +28 -28
  81. package/dist/components/PageHeader/index.js.map +1 -1
  82. package/dist/components/ProtectedRoute/index.js +8 -9
  83. package/dist/components/ProtectedRoute/index.js.map +1 -1
  84. package/dist/components/Row/index.d.ts +28 -0
  85. package/dist/components/Row/index.js +30 -0
  86. package/dist/components/Row/index.js.map +1 -0
  87. package/dist/components/Select/index.js +251 -257
  88. package/dist/components/Select/index.js.map +1 -1
  89. package/dist/components/SidebarToggleButton/index.js +56 -59
  90. package/dist/components/SidebarToggleButton/index.js.map +1 -1
  91. package/dist/components/Slider/index.d.ts +39 -0
  92. package/dist/components/Slider/index.js +52 -0
  93. package/dist/components/Slider/index.js.map +1 -0
  94. package/dist/components/StatCard/index.d.ts +31 -1
  95. package/dist/components/StatCard/index.js +189 -58
  96. package/dist/components/StatCard/index.js.map +1 -1
  97. package/dist/components/Switch/index.d.ts +34 -0
  98. package/dist/components/Switch/index.js +55 -0
  99. package/dist/components/Switch/index.js.map +1 -0
  100. package/dist/components/Tab/index.d.ts +40 -0
  101. package/dist/components/Table/index.js +109 -103
  102. package/dist/components/Table/index.js.map +1 -1
  103. package/dist/components/Tabs/index.d.ts +19 -5
  104. package/dist/components/Tabs/index.js +30 -21
  105. package/dist/components/Tabs/index.js.map +1 -1
  106. package/dist/components/Text/index.d.ts +43 -0
  107. package/dist/components/Text/index.js +55 -0
  108. package/dist/components/Text/index.js.map +1 -0
  109. package/dist/components/Tooltip/index.d.ts +23 -0
  110. package/dist/components/Tooltip/index.js +34 -0
  111. package/dist/components/Tooltip/index.js.map +1 -0
  112. package/dist/components/Tree/Tree.js +205 -205
  113. package/dist/components/Tree/Tree.js.map +1 -1
  114. package/dist/components/pro/ArticleContextMenu/index.js +86 -87
  115. package/dist/components/pro/ArticleContextMenu/index.js.map +1 -1
  116. package/dist/components/pro/ArticleControl/ArticleControl2.js +250 -250
  117. package/dist/components/pro/ArticleControl/ArticleControl2.js.map +1 -1
  118. package/dist/components/pro/ArticleControl/buildHeadingTree.js +31 -32
  119. package/dist/components/pro/ArticleControl/buildHeadingTree.js.map +1 -1
  120. package/dist/components/pro/ArticleControl/useArticleToc.js +100 -102
  121. package/dist/components/pro/ArticleControl/useArticleToc.js.map +1 -1
  122. package/dist/components/pro/Calendar/Calendar.d.ts +10 -0
  123. package/dist/components/pro/Calendar/hooks/useCalendarDrag.d.ts +47 -0
  124. package/dist/components/pro/Calendar/hooks/useCalendarState.d.ts +56 -0
  125. package/dist/components/pro/Calendar/index.d.ts +7 -0
  126. package/dist/components/pro/Calendar/types.d.ts +151 -0
  127. package/dist/components/pro/Calendar/utils.d.ts +94 -0
  128. package/dist/components/pro/Chat/Chat.d.ts +6 -0
  129. package/dist/components/pro/Chat/index.d.ts +2 -0
  130. package/dist/components/pro/Chat/types.d.ts +84 -0
  131. package/dist/components/pro/CodeEditor/editors/CodeEditor.js +287 -320
  132. package/dist/components/pro/CodeEditor/editors/CodeEditor.js.map +1 -1
  133. package/dist/components/pro/CodeEditor/editors/MarkdownEditor.js +167 -221
  134. package/dist/components/pro/CodeEditor/editors/MarkdownEditor.js.map +1 -1
  135. package/dist/components/pro/CodeEditor/editors/markdownExtensions.js +594 -613
  136. package/dist/components/pro/CodeEditor/editors/markdownExtensions.js.map +1 -1
  137. package/dist/components/pro/CodeEditor/extensions/contextMenu.js +54 -55
  138. package/dist/components/pro/CodeEditor/extensions/contextMenu.js.map +1 -1
  139. package/dist/components/pro/CodeEditor/extensions/index.js +152 -160
  140. package/dist/components/pro/CodeEditor/extensions/index.js.map +1 -1
  141. package/dist/components/pro/CodeEditor/langs/index.js +7 -15
  142. package/dist/components/pro/CodeEditor/langs/index.js.map +1 -1
  143. package/dist/components/pro/CodeEditor/langs/javascript.js +11 -48
  144. package/dist/components/pro/CodeEditor/langs/javascript.js.map +1 -1
  145. package/dist/components/pro/CodeEditor/langs/python.js +4 -40
  146. package/dist/components/pro/CodeEditor/langs/python.js.map +1 -1
  147. package/dist/components/pro/CodeEditor/langs/snippets.js +118 -147
  148. package/dist/components/pro/CodeEditor/langs/snippets.js.map +1 -1
  149. package/dist/components/pro/CodeEditor/panels/FootnotePanel.js +153 -153
  150. package/dist/components/pro/CodeEditor/panels/FootnotePanel.js.map +1 -1
  151. package/dist/components/pro/CodeEditor/panels/HistoryPanel.js +180 -190
  152. package/dist/components/pro/CodeEditor/panels/HistoryPanel.js.map +1 -1
  153. package/dist/components/pro/CodeEditor/panels/OutlinePanel.js +130 -137
  154. package/dist/components/pro/CodeEditor/panels/OutlinePanel.js.map +1 -1
  155. package/dist/components/pro/CodeEditor/panels/TableOfContentsPanel.js +228 -242
  156. package/dist/components/pro/CodeEditor/panels/TableOfContentsPanel.js.map +1 -1
  157. package/dist/components/pro/CodeEditor/panels/VariablePanel.js +208 -248
  158. package/dist/components/pro/CodeEditor/panels/VariablePanel.js.map +1 -1
  159. package/dist/components/pro/CodeEditor/themes.js +513 -483
  160. package/dist/components/pro/CodeEditor/themes.js.map +1 -1
  161. package/dist/components/pro/CodeEditor/types.d.ts +1 -1
  162. package/dist/components/pro/CodeEditor/utils.js +171 -175
  163. package/dist/components/pro/CodeEditor/utils.js.map +1 -1
  164. package/dist/components/pro/DataTable/DataTable.js +305 -305
  165. package/dist/components/pro/DataTable/DataTable.js.map +1 -1
  166. package/dist/components/pro/DataTable/Filters.js +299 -314
  167. package/dist/components/pro/DataTable/Filters.js.map +1 -1
  168. package/dist/components/pro/DataTable/PivotPanel.js +203 -204
  169. package/dist/components/pro/DataTable/PivotPanel.js.map +1 -1
  170. package/dist/components/pro/DataTable/PivotView.js +142 -141
  171. package/dist/components/pro/DataTable/PivotView.js.map +1 -1
  172. package/dist/components/pro/DataTable/components/BulkActions.js +42 -42
  173. package/dist/components/pro/DataTable/components/BulkActions.js.map +1 -1
  174. package/dist/components/pro/DataTable/components/ColumnSelector.js +84 -84
  175. package/dist/components/pro/DataTable/components/ColumnSelector.js.map +1 -1
  176. package/dist/components/pro/DataTable/components/FilterBar.js +58 -58
  177. package/dist/components/pro/DataTable/components/FilterBar.js.map +1 -1
  178. package/dist/components/pro/DataTable/components/TableBody.js +93 -94
  179. package/dist/components/pro/DataTable/components/TableBody.js.map +1 -1
  180. package/dist/components/pro/DataTable/components/TableHeader.js +78 -78
  181. package/dist/components/pro/DataTable/components/TableHeader.js.map +1 -1
  182. package/dist/components/pro/DataTable/components/TablePagination.js +77 -77
  183. package/dist/components/pro/DataTable/components/TablePagination.js.map +1 -1
  184. package/dist/components/pro/DataTable/components/TableToolbar.js +40 -40
  185. package/dist/components/pro/DataTable/components/TableToolbar.js.map +1 -1
  186. package/dist/components/pro/DataTable/extension.js +5 -5
  187. package/dist/components/pro/DataTable/extension.js.map +1 -1
  188. package/dist/components/pro/DataTable/pivotEngine.js +84 -92
  189. package/dist/components/pro/DataTable/pivotEngine.js.map +1 -1
  190. package/dist/components/pro/DataTable/pivotExtension.js +93 -93
  191. package/dist/components/pro/DataTable/pivotExtension.js.map +1 -1
  192. package/dist/components/pro/DataTable/rowDetailExtension.js +30 -30
  193. package/dist/components/pro/DataTable/rowDetailExtension.js.map +1 -1
  194. package/dist/components/pro/DataTable/tanstack-table.js +45 -62
  195. package/dist/components/pro/DataTable/tanstack-table.js.map +1 -1
  196. package/dist/components/pro/DataTable/treeDataUtils.js +37 -48
  197. package/dist/components/pro/DataTable/treeDataUtils.js.map +1 -1
  198. package/dist/components/pro/DataTable/useColumnDragReorder.js +68 -68
  199. package/dist/components/pro/DataTable/useColumnDragReorder.js.map +1 -1
  200. package/dist/components/pro/DataTable/utils.js +156 -168
  201. package/dist/components/pro/DataTable/utils.js.map +1 -1
  202. package/dist/components/pro/FileExplorer/Breadcrumb.js +180 -180
  203. package/dist/components/pro/FileExplorer/Breadcrumb.js.map +1 -1
  204. package/dist/components/pro/FileExplorer/CreateDialog.js +78 -78
  205. package/dist/components/pro/FileExplorer/CreateDialog.js.map +1 -1
  206. package/dist/components/pro/FileExplorer/FileExplorer.js +202 -205
  207. package/dist/components/pro/FileExplorer/FileExplorer.js.map +1 -1
  208. package/dist/components/pro/FileExplorer/FileIcon.js +190 -190
  209. package/dist/components/pro/FileExplorer/FileIcon.js.map +1 -1
  210. package/dist/components/pro/FileExplorer/GridView.js +100 -100
  211. package/dist/components/pro/FileExplorer/GridView.js.map +1 -1
  212. package/dist/components/pro/FileExplorer/ListView.js +209 -209
  213. package/dist/components/pro/FileExplorer/ListView.js.map +1 -1
  214. package/dist/components/pro/FileExplorer/Toolbar.js +199 -199
  215. package/dist/components/pro/FileExplorer/Toolbar.js.map +1 -1
  216. package/dist/components/pro/Flow/Flow.js +920 -946
  217. package/dist/components/pro/Flow/Flow.js.map +1 -1
  218. package/dist/components/pro/Flow/FlowCanvas.js +1626 -1663
  219. package/dist/components/pro/Flow/FlowCanvas.js.map +1 -1
  220. package/dist/components/pro/Flow/archify/build.js +85 -94
  221. package/dist/components/pro/Flow/archify/build.js.map +1 -1
  222. package/dist/components/pro/Flow/archify/convert.js +512 -519
  223. package/dist/components/pro/Flow/archify/convert.js.map +1 -1
  224. package/dist/components/pro/Flow/archify/palette.js +87 -104
  225. package/dist/components/pro/Flow/archify/palette.js.map +1 -1
  226. package/dist/components/pro/Flow/archify/presets.js +34 -37
  227. package/dist/components/pro/Flow/archify/presets.js.map +1 -1
  228. package/dist/components/pro/Flow/archify/spec.js +7 -7
  229. package/dist/components/pro/Flow/archify/spec.js.map +1 -1
  230. package/dist/components/pro/Flow/canvas/AlignmentGuides.js +25 -25
  231. package/dist/components/pro/Flow/canvas/AlignmentGuides.js.map +1 -1
  232. package/dist/components/pro/Flow/canvas/GridRenderer.js +54 -55
  233. package/dist/components/pro/Flow/canvas/GridRenderer.js.map +1 -1
  234. package/dist/components/pro/Flow/canvas/MiniMapRenderer.js +54 -58
  235. package/dist/components/pro/Flow/canvas/MiniMapRenderer.js.map +1 -1
  236. package/dist/components/pro/Flow/canvas/PixiApp.js +105 -102
  237. package/dist/components/pro/Flow/canvas/PixiApp.js.map +1 -1
  238. package/dist/components/pro/Flow/canvas/SelectionOverlay.js +38 -38
  239. package/dist/components/pro/Flow/canvas/SelectionOverlay.js.map +1 -1
  240. package/dist/components/pro/Flow/canvas/ViewportContainer.js +117 -117
  241. package/dist/components/pro/Flow/canvas/ViewportContainer.js.map +1 -1
  242. package/dist/components/pro/Flow/constants.js +266 -278
  243. package/dist/components/pro/Flow/constants.js.map +1 -1
  244. package/dist/components/pro/Flow/context/FlowAIContext.js +27 -28
  245. package/dist/components/pro/Flow/context/FlowAIContext.js.map +1 -1
  246. package/dist/components/pro/Flow/context/FlowContext.js +60 -61
  247. package/dist/components/pro/Flow/context/FlowContext.js.map +1 -1
  248. package/dist/components/pro/Flow/context/FlowUIContext.js +115 -117
  249. package/dist/components/pro/Flow/context/FlowUIContext.js.map +1 -1
  250. package/dist/components/pro/Flow/edges/EdgeRenderer.js +135 -138
  251. package/dist/components/pro/Flow/edges/EdgeRenderer.js.map +1 -1
  252. package/dist/components/pro/Flow/edges/edgeMarkers.js +11 -14
  253. package/dist/components/pro/Flow/edges/edgeMarkers.js.map +1 -1
  254. package/dist/components/pro/Flow/edges/edgePaths.js +351 -367
  255. package/dist/components/pro/Flow/edges/edgePaths.js.map +1 -1
  256. package/dist/components/pro/Flow/hooks/useAlignmentGuides.js +49 -52
  257. package/dist/components/pro/Flow/hooks/useAlignmentGuides.js.map +1 -1
  258. package/dist/components/pro/Flow/hooks/useClipboard.js +154 -154
  259. package/dist/components/pro/Flow/hooks/useClipboard.js.map +1 -1
  260. package/dist/components/pro/Flow/hooks/useCompactMode.js +17 -17
  261. package/dist/components/pro/Flow/hooks/useCompactMode.js.map +1 -1
  262. package/dist/components/pro/Flow/hooks/useDeleteSelection.js +40 -40
  263. package/dist/components/pro/Flow/hooks/useDeleteSelection.js.map +1 -1
  264. package/dist/components/pro/Flow/hooks/useDraggablePanel.js +51 -51
  265. package/dist/components/pro/Flow/hooks/useDraggablePanel.js.map +1 -1
  266. package/dist/components/pro/Flow/hooks/useEdgeMutations.js +157 -157
  267. package/dist/components/pro/Flow/hooks/useEdgeMutations.js.map +1 -1
  268. package/dist/components/pro/Flow/hooks/useFlowImportExport.js +190 -201
  269. package/dist/components/pro/Flow/hooks/useFlowImportExport.js.map +1 -1
  270. package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.js +32 -38
  271. package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.js.map +1 -1
  272. package/dist/components/pro/Flow/hooks/useLayoutActions.js +172 -182
  273. package/dist/components/pro/Flow/hooks/useLayoutActions.js.map +1 -1
  274. package/dist/components/pro/Flow/hooks/useLineMutations.js +57 -57
  275. package/dist/components/pro/Flow/hooks/useLineMutations.js.map +1 -1
  276. package/dist/components/pro/Flow/hooks/useMindMap.js +229 -238
  277. package/dist/components/pro/Flow/hooks/useMindMap.js.map +1 -1
  278. package/dist/components/pro/Flow/hooks/useNodeMutations.js +102 -102
  279. package/dist/components/pro/Flow/hooks/useNodeMutations.js.map +1 -1
  280. package/dist/components/pro/Flow/hooks/usePdfExport.js +55 -56
  281. package/dist/components/pro/Flow/hooks/usePdfExport.js.map +1 -1
  282. package/dist/components/pro/Flow/hooks/usePixiApp.js +55 -57
  283. package/dist/components/pro/Flow/hooks/usePixiApp.js.map +1 -1
  284. package/dist/components/pro/Flow/hooks/useResizablePanel.js +31 -31
  285. package/dist/components/pro/Flow/hooks/useResizablePanel.js.map +1 -1
  286. package/dist/components/pro/Flow/hooks/useSelection.js +69 -69
  287. package/dist/components/pro/Flow/hooks/useSelection.js.map +1 -1
  288. package/dist/components/pro/Flow/hooks/useUndoRedo.js +27 -27
  289. package/dist/components/pro/Flow/hooks/useUndoRedo.js.map +1 -1
  290. package/dist/components/pro/Flow/hooks/useViewport.js +28 -28
  291. package/dist/components/pro/Flow/hooks/useViewport.js.map +1 -1
  292. package/dist/components/pro/Flow/lines/FreehandTool.js +63 -63
  293. package/dist/components/pro/Flow/lines/FreehandTool.js.map +1 -1
  294. package/dist/components/pro/Flow/lines/GeometricLineTool.js +80 -80
  295. package/dist/components/pro/Flow/lines/GeometricLineTool.js.map +1 -1
  296. package/dist/components/pro/Flow/lines/LineRenderer.js +88 -88
  297. package/dist/components/pro/Flow/lines/LineRenderer.js.map +1 -1
  298. package/dist/components/pro/Flow/lines/lineSmoothing.js +32 -34
  299. package/dist/components/pro/Flow/lines/lineSmoothing.js.map +1 -1
  300. package/dist/components/pro/Flow/nodes/DataNodeView.js +236 -222
  301. package/dist/components/pro/Flow/nodes/DataNodeView.js.map +1 -1
  302. package/dist/components/pro/Flow/nodes/MediaContent.js +236 -246
  303. package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
  304. package/dist/components/pro/Flow/nodes/MediaOverlay.js +63 -63
  305. package/dist/components/pro/Flow/nodes/MediaOverlay.js.map +1 -1
  306. package/dist/components/pro/Flow/nodes/Model3DView.js +111 -113
  307. package/dist/components/pro/Flow/nodes/Model3DView.js.map +1 -1
  308. package/dist/components/pro/Flow/nodes/NodeHandles.js +74 -80
  309. package/dist/components/pro/Flow/nodes/NodeHandles.js.map +1 -1
  310. package/dist/components/pro/Flow/nodes/NodeRenderer.js +303 -314
  311. package/dist/components/pro/Flow/nodes/NodeRenderer.js.map +1 -1
  312. package/dist/components/pro/Flow/nodes/NodeText.js +25 -29
  313. package/dist/components/pro/Flow/nodes/NodeText.js.map +1 -1
  314. package/dist/components/pro/Flow/nodes/aiClient.js +124 -137
  315. package/dist/components/pro/Flow/nodes/aiClient.js.map +1 -1
  316. package/dist/components/pro/Flow/nodes/animAnchors.js +42 -49
  317. package/dist/components/pro/Flow/nodes/animAnchors.js.map +1 -1
  318. package/dist/components/pro/Flow/nodes/dataUtils.js +246 -267
  319. package/dist/components/pro/Flow/nodes/dataUtils.js.map +1 -1
  320. package/dist/components/pro/Flow/nodes/nodeUtils.js +23 -28
  321. package/dist/components/pro/Flow/nodes/nodeUtils.js.map +1 -1
  322. package/dist/components/pro/Flow/nodes/shapes.js +556 -591
  323. package/dist/components/pro/Flow/nodes/shapes.js.map +1 -1
  324. package/dist/components/pro/Flow/nodes/svgIconTexture.js +37 -39
  325. package/dist/components/pro/Flow/nodes/svgIconTexture.js.map +1 -1
  326. package/dist/components/pro/Flow/nodes/svgIcons.js +684 -689
  327. package/dist/components/pro/Flow/nodes/svgIcons.js.map +1 -1
  328. package/dist/components/pro/Flow/panels/AIPanel.js +464 -491
  329. package/dist/components/pro/Flow/panels/AIPanel.js.map +1 -1
  330. package/dist/components/pro/Flow/panels/Breadcrumb.js +41 -41
  331. package/dist/components/pro/Flow/panels/Breadcrumb.js.map +1 -1
  332. package/dist/components/pro/Flow/panels/ContextMenu.js +37 -37
  333. package/dist/components/pro/Flow/panels/ContextMenu.js.map +1 -1
  334. package/dist/components/pro/Flow/panels/DataInspectorSection.js +428 -432
  335. package/dist/components/pro/Flow/panels/DataInspectorSection.js.map +1 -1
  336. package/dist/components/pro/Flow/panels/ExpandableTextarea.js +61 -62
  337. package/dist/components/pro/Flow/panels/ExpandableTextarea.js.map +1 -1
  338. package/dist/components/pro/Flow/panels/FlowPanelGroup.js +114 -114
  339. package/dist/components/pro/Flow/panels/FlowPanelGroup.js.map +1 -1
  340. package/dist/components/pro/Flow/panels/FlowToolbar.js +347 -391
  341. package/dist/components/pro/Flow/panels/FlowToolbar.js.map +1 -1
  342. package/dist/components/pro/Flow/panels/InspectorPanel.js +1792 -1798
  343. package/dist/components/pro/Flow/panels/InspectorPanel.js.map +1 -1
  344. package/dist/components/pro/Flow/panels/OutlinePanel.js +242 -244
  345. package/dist/components/pro/Flow/panels/OutlinePanel.js.map +1 -1
  346. package/dist/components/pro/Flow/panels/PresentationMode.js +137 -138
  347. package/dist/components/pro/Flow/panels/PresentationMode.js.map +1 -1
  348. package/dist/components/pro/Flow/panels/ProjectTitle.js +46 -46
  349. package/dist/components/pro/Flow/panels/ProjectTitle.js.map +1 -1
  350. package/dist/components/pro/Flow/panels/ShapePalette.js +557 -567
  351. package/dist/components/pro/Flow/panels/ShapePalette.js.map +1 -1
  352. package/dist/components/pro/Flow/panels/toolbarIcons.d.ts +0 -1
  353. package/dist/components/pro/Flow/panels/toolbarIcons.js +508 -557
  354. package/dist/components/pro/Flow/panels/toolbarIcons.js.map +1 -1
  355. package/dist/components/pro/Flow/types.js +26 -26
  356. package/dist/components/pro/Flow/types.js.map +1 -1
  357. package/dist/components/pro/Flow/utils/dashedLine.js +113 -117
  358. package/dist/components/pro/Flow/utils/dashedLine.js.map +1 -1
  359. package/dist/components/pro/Flow/utils/gradient.js +55 -55
  360. package/dist/components/pro/Flow/utils/gradient.js.map +1 -1
  361. package/dist/components/pro/Flow/utils/pdfExport.js +50 -89
  362. package/dist/components/pro/Flow/utils/pdfExport.js.map +1 -1
  363. package/dist/components/pro/Flow/utils/themeColor.js +185 -195
  364. package/dist/components/pro/Flow/utils/themeColor.js.map +1 -1
  365. package/dist/components/pro/Gantt/Gantt.d.ts +7 -0
  366. package/dist/components/pro/Gantt/hooks/useGanttDrag.d.ts +31 -0
  367. package/dist/components/pro/Gantt/hooks/useGanttState.d.ts +58 -0
  368. package/dist/components/pro/Gantt/index.d.ts +6 -0
  369. package/dist/components/pro/Gantt/types.d.ts +478 -0
  370. package/dist/components/pro/Gantt/utils.d.ts +124 -0
  371. package/dist/components/pro/Resizable/Resizable.d.ts +30 -0
  372. package/dist/components/pro/Resizable/index.d.ts +2 -0
  373. package/dist/components/pro/RichTextEditor/AIRewrite.js +323 -334
  374. package/dist/components/pro/RichTextEditor/AIRewrite.js.map +1 -1
  375. package/dist/components/pro/RichTextEditor/BlockHandle.js +314 -316
  376. package/dist/components/pro/RichTextEditor/BlockHandle.js.map +1 -1
  377. package/dist/components/pro/RichTextEditor/BubbleToolbar.js +97 -97
  378. package/dist/components/pro/RichTextEditor/BubbleToolbar.js.map +1 -1
  379. package/dist/components/pro/RichTextEditor/CommentDialog.js +88 -88
  380. package/dist/components/pro/RichTextEditor/CommentDialog.js.map +1 -1
  381. package/dist/components/pro/RichTextEditor/CommentPanel.js +240 -240
  382. package/dist/components/pro/RichTextEditor/CommentPanel.js.map +1 -1
  383. package/dist/components/pro/RichTextEditor/CommentPopover.js +234 -234
  384. package/dist/components/pro/RichTextEditor/CommentPopover.js.map +1 -1
  385. package/dist/components/pro/RichTextEditor/ContextMenu.js +251 -252
  386. package/dist/components/pro/RichTextEditor/ContextMenu.js.map +1 -1
  387. package/dist/components/pro/RichTextEditor/RichTextEditor.js +267 -271
  388. package/dist/components/pro/RichTextEditor/RichTextEditor.js.map +1 -1
  389. package/dist/components/pro/RichTextEditor/SlashMenu.js +214 -214
  390. package/dist/components/pro/RichTextEditor/SlashMenu.js.map +1 -1
  391. package/dist/components/pro/RichTextEditor/Toolbar/ColorPicker.js +44 -75
  392. package/dist/components/pro/RichTextEditor/Toolbar/ColorPicker.js.map +1 -1
  393. package/dist/components/pro/RichTextEditor/Toolbar/FloatingDialogMenu.js +261 -261
  394. package/dist/components/pro/RichTextEditor/Toolbar/FloatingDialogMenu.js.map +1 -1
  395. package/dist/components/pro/RichTextEditor/Toolbar/MarkdownTemplates.js +172 -526
  396. package/dist/components/pro/RichTextEditor/Toolbar/MarkdownTemplates.js.map +1 -1
  397. package/dist/components/pro/RichTextEditor/Toolbar/SelectDropdown.js +112 -114
  398. package/dist/components/pro/RichTextEditor/Toolbar/SelectDropdown.js.map +1 -1
  399. package/dist/components/pro/RichTextEditor/Toolbar/TableOpsMenu.js +194 -194
  400. package/dist/components/pro/RichTextEditor/Toolbar/TableOpsMenu.js.map +1 -1
  401. package/dist/components/pro/RichTextEditor/Toolbar/Toolbar.js +970 -973
  402. package/dist/components/pro/RichTextEditor/Toolbar/Toolbar.js.map +1 -1
  403. package/dist/components/pro/RichTextEditor/Toolbar/ToolbarButton.js +11 -12
  404. package/dist/components/pro/RichTextEditor/Toolbar/ToolbarButton.js.map +1 -1
  405. package/dist/components/pro/RichTextEditor/extensions/CodeBlockView.js +310 -344
  406. package/dist/components/pro/RichTextEditor/extensions/CodeBlockView.js.map +1 -1
  407. package/dist/components/pro/RichTextEditor/extensions/CommentMark.js +38 -39
  408. package/dist/components/pro/RichTextEditor/extensions/CommentMark.js.map +1 -1
  409. package/dist/components/pro/RichTextEditor/extensions/FloatingDialog.js +620 -625
  410. package/dist/components/pro/RichTextEditor/extensions/FloatingDialog.js.map +1 -1
  411. package/dist/components/pro/RichTextEditor/extensions/FontSize.js +25 -25
  412. package/dist/components/pro/RichTextEditor/extensions/FontSize.js.map +1 -1
  413. package/dist/components/pro/RichTextEditor/extensions/MarkdownBlock.js +167 -176
  414. package/dist/components/pro/RichTextEditor/extensions/MarkdownBlock.js.map +1 -1
  415. package/dist/components/pro/RichTextEditor/types.js +75 -75
  416. package/dist/components/pro/RichTextEditor/types.js.map +1 -1
  417. package/dist/contexts/AppContext.d.ts +1 -1
  418. package/dist/contexts/AppContext.js +216 -221
  419. package/dist/contexts/AppContext.js.map +1 -1
  420. package/dist/data-table.js +15 -41
  421. package/dist/data-table.js.map +1 -1
  422. package/dist/dishui.css +1 -1
  423. package/dist/flow.js +27 -83
  424. package/dist/hooks/useClickOutside.js +18 -18
  425. package/dist/hooks/useClickOutside.js.map +1 -1
  426. package/dist/hooks/useContainerElement.js +9 -9
  427. package/dist/hooks/useContainerElement.js.map +1 -1
  428. package/dist/hooks/useControllableState.js +33 -35
  429. package/dist/hooks/useControllableState.js.map +1 -1
  430. package/dist/hooks/useCopyToClipboard.js +16 -16
  431. package/dist/hooks/useCopyToClipboard.js.map +1 -1
  432. package/dist/hooks/useDebounce.js +14 -14
  433. package/dist/hooks/useDebounce.js.map +1 -1
  434. package/dist/hooks/useDraggable.js +50 -50
  435. package/dist/hooks/useDraggable.js.map +1 -1
  436. package/dist/hooks/useTableColumns.js +39 -42
  437. package/dist/hooks/useTableColumns.js.map +1 -1
  438. package/dist/hooks/useTableData.js +67 -68
  439. package/dist/hooks/useTableData.js.map +1 -1
  440. package/dist/index-nostyled.d.ts +8 -0
  441. package/dist/index.d.ts +29 -1
  442. package/dist/index.js +106 -236
  443. package/dist/layouts/MainLayout.js +56 -56
  444. package/dist/layouts/MainLayout.js.map +1 -1
  445. package/dist/layouts/Navbar.js +214 -214
  446. package/dist/layouts/Navbar.js.map +1 -1
  447. package/dist/layouts/Sidebar.js +184 -165
  448. package/dist/layouts/Sidebar.js.map +1 -1
  449. package/dist/layouts/headbar/Headbar.js +25 -25
  450. package/dist/layouts/headbar/Headbar.js.map +1 -1
  451. package/dist/layouts/headbar/HeadbarLangSwitcher.js +39 -39
  452. package/dist/layouts/headbar/HeadbarLangSwitcher.js.map +1 -1
  453. package/dist/layouts/headbar/HeadbarSearch.js +120 -120
  454. package/dist/layouts/headbar/HeadbarSearch.js.map +1 -1
  455. package/dist/layouts/headbar/HeadbarThemeSwitcher.js +27 -27
  456. package/dist/layouts/headbar/HeadbarThemeSwitcher.js.map +1 -1
  457. package/dist/layouts/headbar/HeadbarTitle.js +26 -26
  458. package/dist/layouts/headbar/HeadbarTitle.js.map +1 -1
  459. package/dist/lite.js +9 -24
  460. package/dist/markdown.js +4 -9
  461. package/dist/pages/components/Calendar/index.d.ts +3 -0
  462. package/dist/pages/components/Calendar/index.en.d.ts +3 -0
  463. package/dist/pages/components/Calendar/index.zh.d.ts +3 -0
  464. package/dist/pages/components/Chat/index.d.ts +3 -0
  465. package/dist/pages/components/Chat/index.en.d.ts +3 -0
  466. package/dist/pages/components/Chat/index.zh.d.ts +3 -0
  467. package/dist/pages/components/FloatWindow/index.d.ts +3 -0
  468. package/dist/pages/components/FloatWindow/index.en.d.ts +3 -0
  469. package/dist/pages/components/FloatWindow/index.zh.d.ts +3 -0
  470. package/dist/pages/components/Gantt/index.d.ts +3 -0
  471. package/dist/pages/components/Gantt/index.en.d.ts +3 -0
  472. package/dist/pages/components/Gantt/index.zh.d.ts +3 -0
  473. package/dist/pages/components/GridLayout/index.d.ts +3 -0
  474. package/dist/pages/components/GridLayout/index.en.d.ts +3 -0
  475. package/dist/pages/components/GridLayout/index.zh.d.ts +3 -0
  476. package/dist/pages/components/Notification/index.d.ts +3 -0
  477. package/dist/pages/components/Notification/index.en.d.ts +3 -0
  478. package/dist/pages/components/Notification/index.zh.d.ts +3 -0
  479. package/dist/pages/components/Resizable/index.d.ts +3 -0
  480. package/dist/pages/components/Resizable/index.en.d.ts +3 -0
  481. package/dist/pages/components/Resizable/index.zh.d.ts +3 -0
  482. package/dist/pages/components/Tab/index.d.ts +3 -0
  483. package/dist/pages/components/Tab/index.en.d.ts +3 -0
  484. package/dist/pages/components/Tab/index.zh.d.ts +3 -0
  485. package/dist/styles/themeStyles.js +87 -86
  486. package/dist/styles/themeStyles.js.map +1 -1
  487. package/dist/utils/cn.d.ts +13 -0
  488. package/dist/utils/cn.js +16 -0
  489. package/dist/utils/cn.js.map +1 -0
  490. package/dist/utils/i18n.js +690 -602
  491. package/dist/utils/i18n.js.map +1 -1
  492. package/dist/utils/menu.js +94 -94
  493. package/dist/utils/menu.js.map +1 -1
  494. package/dist/utils/rehype-code-meta.js +14 -14
  495. package/dist/utils/rehype-code-meta.js.map +1 -1
  496. package/dist/utils/remark-code-meta.js +9 -9
  497. package/dist/utils/remark-code-meta.js.map +1 -1
  498. package/dist/utils/routerBuilder.js +59 -58
  499. package/dist/utils/routerBuilder.js.map +1 -1
  500. package/dist/utils/selection.js +28 -29
  501. package/dist/utils/selection.js.map +1 -1
  502. package/dist/utils/themes.js +275 -255
  503. package/dist/utils/themes.js.map +1 -1
  504. package/package.json +23 -10
@@ -1,1677 +1,1640 @@
1
- import { useFlowContext as Mn } from "./context/FlowContext.js";
2
- import { useFlowUI as Rn } from "./context/FlowUIContext.js";
3
- import { usePixiApp as Sn } from "./hooks/usePixiApp.js";
4
- import { useViewport as zn } from "./hooks/useViewport.js";
5
- import { GridRenderer as En } from "./canvas/GridRenderer.js";
6
- import { SelectionOverlay as Cn } from "./canvas/SelectionOverlay.js";
7
- import { shapeDrawers as an } from "./nodes/shapes.js";
8
- import { findClosestHandleWorld as Bt, getHandlePositions as Mt, handleWorldPos as Vt } from "./nodes/NodeHandles.js";
9
- import { distToSegment as Le, generateId as Nn, isPointInNode as qt, rectsOverlap as kn } from "./nodes/nodeUtils.js";
10
- import { NodeRenderer as Tn } from "./nodes/NodeRenderer.js";
11
- import { buildEdgePath as wn, linearizeSegments as mn, resolveEdgeEndpoints as St } from "./edges/edgePaths.js";
12
- import { EdgeRenderer as Dn } from "./edges/EdgeRenderer.js";
13
- import { LineRenderer as Hn } from "./lines/LineRenderer.js";
14
- import { FreehandTool as Pn } from "./lines/FreehandTool.js";
15
- import { GeometricLineTool as An } from "./lines/GeometricLineTool.js";
16
- import { computeAlignmentSnap as me } from "./hooks/useAlignmentGuides.js";
17
- import { AlignmentGuidesRenderer as Ln } from "./canvas/AlignmentGuides.js";
18
- import { getDocumentSlides as Gn, nextAnimIndex as Wn } from "./nodes/animAnchors.js";
19
- import { useDeleteSelection as Yn } from "./hooks/useDeleteSelection.js";
20
- import { useCallback as le, useEffect as Rt, useRef as m, useState as ln } from "react";
21
- import { jsx as Zt, jsxs as ve } from "react/jsx-runtime";
22
- import { Graphics as ue } from "pixi.js";
23
- var Xn = {
24
- nw: "nwse-resize",
25
- ne: "nesw-resize",
26
- se: "nwse-resize",
27
- sw: "nesw-resize"
28
- }, fe = typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(pointer: coarse)").matches, un = fe ? 2 : 1;
29
- function Q(L, M, H) {
30
- return Math.min(M * un / L, H * un);
1
+ import { useFlowContext as e } from "./context/FlowContext.js";
2
+ import { useFlowUI as t } from "./context/FlowUIContext.js";
3
+ import { usePixiApp as n } from "./hooks/usePixiApp.js";
4
+ import { useViewport as r } from "./hooks/useViewport.js";
5
+ import { GridRenderer as i } from "./canvas/GridRenderer.js";
6
+ import { SelectionOverlay as a } from "./canvas/SelectionOverlay.js";
7
+ import { shapeDrawers as o } from "./nodes/shapes.js";
8
+ import { findClosestHandleWorld as s, getHandlePositions as c, handleWorldPos as l } from "./nodes/NodeHandles.js";
9
+ import { distToSegment as u, generateId as d, isPointInNode as f, rectsOverlap as p } from "./nodes/nodeUtils.js";
10
+ import { NodeRenderer as m } from "./nodes/NodeRenderer.js";
11
+ import { buildEdgePath as h, linearizeSegments as g, resolveEdgeEndpoints as _ } from "./edges/edgePaths.js";
12
+ import { EdgeRenderer as v } from "./edges/EdgeRenderer.js";
13
+ import { LineRenderer as ee } from "./lines/LineRenderer.js";
14
+ import { FreehandTool as te } from "./lines/FreehandTool.js";
15
+ import { GeometricLineTool as ne } from "./lines/GeometricLineTool.js";
16
+ import { computeAlignmentSnap as re } from "./hooks/useAlignmentGuides.js";
17
+ import { AlignmentGuidesRenderer as ie } from "./canvas/AlignmentGuides.js";
18
+ import { getDocumentSlides as ae, nextAnimIndex as oe } from "./nodes/animAnchors.js";
19
+ import { useDeleteSelection as se } from "./hooks/useDeleteSelection.js";
20
+ import { useCallback as y, useEffect as b, useRef as x, useState as S } from "react";
21
+ import { jsx as C, jsxs as w } from "react/jsx-runtime";
22
+ import { Graphics as ce } from "pixi.js";
23
+ //#region src/components/pro/Flow/FlowCanvas.tsx
24
+ var le = {
25
+ nw: "nwse-resize",
26
+ ne: "nesw-resize",
27
+ se: "nwse-resize",
28
+ sw: "nesw-resize"
29
+ }, ue = typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(pointer: coarse)").matches, T = ue ? 2 : 1;
30
+ function E(e, t, n) {
31
+ return Math.min(t * T / e, n * T);
31
32
  }
32
- var vn = 26;
33
- function fn(L, M) {
34
- return {
35
- x: L.position.x + L.width / 2,
36
- y: L.position.y - vn / M
37
- };
33
+ var de = 26;
34
+ function fe(e, t) {
35
+ return {
36
+ x: e.position.x + e.width / 2,
37
+ y: e.position.y - de / t
38
+ };
38
39
  }
39
- function Kt(L, M, H) {
40
- return !H || !(M > 0) ? L : Math.round(L / M) * M;
40
+ function pe(e, t, n) {
41
+ return !n || !(t > 0) ? e : Math.round(e / t) * t;
41
42
  }
42
- function hn(L, M, H) {
43
- const { x: U, y: D } = M.position, W = M.width, A = M.height, N = [
44
- [
45
- "nw",
46
- U,
47
- D
48
- ],
49
- [
50
- "ne",
51
- U + W,
52
- D
53
- ],
54
- [
55
- "se",
56
- U + W,
57
- D + A
58
- ],
59
- [
60
- "sw",
61
- U,
62
- D + A
63
- ]
64
- ];
65
- let E = null, q = H;
66
- for (const [j, lt, et] of N) {
67
- const $ = Math.hypot(L.x - lt, L.y - et);
68
- $ < q && (q = $, E = j);
69
- }
70
- return E;
43
+ function me(e, t, n) {
44
+ let { x: r, y: i } = t.position, a = t.width, o = t.height, s = [
45
+ [
46
+ "nw",
47
+ r,
48
+ i
49
+ ],
50
+ [
51
+ "ne",
52
+ r + a,
53
+ i
54
+ ],
55
+ [
56
+ "se",
57
+ r + a,
58
+ i + o
59
+ ],
60
+ [
61
+ "sw",
62
+ r,
63
+ i + o
64
+ ]
65
+ ], c = null, l = n;
66
+ for (let [t, n, r] of s) {
67
+ let i = Math.hypot(e.x - n, e.y - r);
68
+ i < l && (l = i, c = t);
69
+ }
70
+ return c;
71
71
  }
72
- function yn(L, M, H, U, D) {
73
- let W = null, A = D;
74
- for (const N of H) {
75
- const E = St(N, U);
76
- if (!E) continue;
77
- const q = Math.hypot(L - E.sx, M - E.sy);
78
- q < A && (A = q, W = {
79
- edgeId: N.id,
80
- end: "source",
81
- worldX: E.sx,
82
- worldY: E.sy
83
- });
84
- const j = Math.hypot(L - E.tx, M - E.ty);
85
- j < A && (A = j, W = {
86
- edgeId: N.id,
87
- end: "target",
88
- worldX: E.tx,
89
- worldY: E.ty
90
- });
91
- }
92
- return W;
72
+ function he(e, t, n, r, i) {
73
+ let a = null, o = i;
74
+ for (let i of n) {
75
+ let n = _(i, r);
76
+ if (!n) continue;
77
+ let s = Math.hypot(e - n.sx, t - n.sy);
78
+ s < o && (o = s, a = {
79
+ edgeId: i.id,
80
+ end: "source",
81
+ worldX: n.sx,
82
+ worldY: n.sy
83
+ });
84
+ let c = Math.hypot(e - n.tx, t - n.ty);
85
+ c < o && (o = c, a = {
86
+ edgeId: i.id,
87
+ end: "target",
88
+ worldX: n.tx,
89
+ worldY: n.ty
90
+ });
91
+ }
92
+ return a;
93
93
  }
94
- function pn(L, M, H, U) {
95
- let D = null, W = U;
96
- for (const A of H) {
97
- const N = A.data.waypoints;
98
- if (N)
99
- for (let E = 0; E < N.length; E++) {
100
- const q = Math.hypot(L - N[E].x, M - N[E].y);
101
- q < W && (W = q, D = {
102
- edgeId: A.id,
103
- waypointIndex: E,
104
- wx: N[E].x,
105
- wy: N[E].y
106
- });
107
- }
108
- }
109
- return D;
94
+ function ge(e, t, n, r) {
95
+ let i = null, a = r;
96
+ for (let r of n) {
97
+ let n = r.data.waypoints;
98
+ if (n) for (let o = 0; o < n.length; o++) {
99
+ let s = Math.hypot(e - n[o].x, t - n[o].y);
100
+ s < a && (a = s, i = {
101
+ edgeId: r.id,
102
+ waypointIndex: o,
103
+ wx: n[o].x,
104
+ wy: n[o].y
105
+ });
106
+ }
107
+ }
108
+ return i;
110
109
  }
111
- function xn(L, M, H, U, D) {
112
- let W = null, A = D;
113
- for (const N of H) {
114
- if (N.type !== "simplebezier") continue;
115
- const E = St(N, U);
116
- if (!E) continue;
117
- const q = N.data.waypoints ?? [], j = [
118
- {
119
- x: E.sx,
120
- y: E.sy
121
- },
122
- ...q,
123
- {
124
- x: E.tx,
125
- y: E.ty
126
- }
127
- ], lt = N.data.bezierControls, et = j.length - 2;
128
- for (let $ = 0; $ <= et; $++) {
129
- const ot = j[$], st = j[$ + 1], zt = lt?.[$], Ut = Math.hypot(st.x - ot.x, st.y - ot.y), Lt = Math.max(30, Ut * 0.3), he = zt?.c1x ?? ($ === 0 ? ot.x + E.snx * Lt : ot.x + (st.x - ot.x) * 0.4), $t = zt?.c1y ?? ($ === 0 ? ot.y + E.sny * Lt : ot.y), jt = zt?.c2x ?? ($ === et ? st.x + E.tnx * Lt : st.x - (st.x - ot.x) * 0.4), Et = zt?.c2y ?? ($ === et ? st.y + E.tny * Lt : st.y), Ct = Math.hypot(L - he, M - $t);
130
- Ct < A && (A = Ct, W = {
131
- edgeId: N.id,
132
- segmentIndex: $,
133
- controlEnd: "c1",
134
- wx: he,
135
- wy: $t
136
- });
137
- const gt = Math.hypot(L - jt, M - Et);
138
- gt < A && (A = gt, W = {
139
- edgeId: N.id,
140
- segmentIndex: $,
141
- controlEnd: "c2",
142
- wx: jt,
143
- wy: Et
144
- });
145
- }
146
- }
147
- return W;
110
+ function _e(e, t, n, r, i) {
111
+ let a = null, o = i;
112
+ for (let i of n) {
113
+ if (i.type !== "simplebezier") continue;
114
+ let n = _(i, r);
115
+ if (!n) continue;
116
+ let s = i.data.waypoints ?? [], c = [
117
+ {
118
+ x: n.sx,
119
+ y: n.sy
120
+ },
121
+ ...s,
122
+ {
123
+ x: n.tx,
124
+ y: n.ty
125
+ }
126
+ ], l = i.data.bezierControls, u = c.length - 2;
127
+ for (let r = 0; r <= u; r++) {
128
+ let s = c[r], d = c[r + 1], f = l?.[r], p = Math.hypot(d.x - s.x, d.y - s.y), m = Math.max(30, p * .3), h = f?.c1x ?? (r === 0 ? s.x + n.snx * m : s.x + (d.x - s.x) * .4), g = f?.c1y ?? (r === 0 ? s.y + n.sny * m : s.y), _ = f?.c2x ?? (r === u ? d.x + n.tnx * m : d.x - (d.x - s.x) * .4), v = f?.c2y ?? (r === u ? d.y + n.tny * m : d.y), ee = Math.hypot(e - h, t - g);
129
+ ee < o && (o = ee, a = {
130
+ edgeId: i.id,
131
+ segmentIndex: r,
132
+ controlEnd: "c1",
133
+ wx: h,
134
+ wy: g
135
+ });
136
+ let te = Math.hypot(e - _, t - v);
137
+ te < o && (o = te, a = {
138
+ edgeId: i.id,
139
+ segmentIndex: r,
140
+ controlEnd: "c2",
141
+ wx: _,
142
+ wy: v
143
+ });
144
+ }
145
+ }
146
+ return a;
148
147
  }
149
- function _n(L, M, H, U) {
150
- const D = St(H, U);
151
- if (!D) return 0;
152
- const W = H.data.waypoints ?? [], A = [
153
- {
154
- x: D.sx,
155
- y: D.sy
156
- },
157
- ...W,
158
- {
159
- x: D.tx,
160
- y: D.ty
161
- }
162
- ];
163
- let N = 1 / 0, E = 0;
164
- for (let q = 0; q < A.length - 1; q++) {
165
- const j = Le(L, M, A[q].x, A[q].y, A[q + 1].x, A[q + 1].y);
166
- j < N && (N = j, E = q);
167
- }
168
- return E;
148
+ function ve(e, t, n, r) {
149
+ let i = _(n, r);
150
+ if (!i) return 0;
151
+ let a = n.data.waypoints ?? [], o = [
152
+ {
153
+ x: i.sx,
154
+ y: i.sy
155
+ },
156
+ ...a,
157
+ {
158
+ x: i.tx,
159
+ y: i.ty
160
+ }
161
+ ], s = Infinity, c = 0;
162
+ for (let n = 0; n < o.length - 1; n++) {
163
+ let r = u(e, t, o[n].x, o[n].y, o[n + 1].x, o[n + 1].y);
164
+ r < s && (s = r, c = n);
165
+ }
166
+ return c;
169
167
  }
170
- function On(L, M, H, U, D = 24) {
171
- let { x: W, y: A, w: N, h: E } = { ...L };
172
- const q = M === "nw" || M === "sw", j = M === "ne" || M === "se", lt = M === "nw" || M === "ne", et = M === "sw" || M === "se";
173
- return q && (W += H, N -= H), j && (N += H), lt && (A += U, E -= U), et && (E += U), N < D && (q && (W = L.x + L.w - D), N = D), E < D && (lt && (A = L.y + L.h - D), E = D), {
174
- x: W,
175
- y: A,
176
- w: N,
177
- h: E
178
- };
168
+ function ye(e, t, n, r, i = 24) {
169
+ let { x: a, y: o, w: s, h: c } = { ...e }, l = t === "nw" || t === "sw", u = t === "ne" || t === "se", d = t === "nw" || t === "ne", f = t === "sw" || t === "se";
170
+ return l && (a += n, s -= n), u && (s += n), d && (o += r, c -= r), f && (c += r), s < i && (l && (a = e.x + e.w - i), s = i), c < i && (d && (o = e.y + e.h - i), c = i), {
171
+ x: a,
172
+ y: o,
173
+ w: s,
174
+ h: c
175
+ };
179
176
  }
180
- function Ae(L, M, H, U, D) {
181
- const W = St(H, U);
182
- if (!W) return !1;
183
- const A = mn(wn(H.type, W, H.data.waypoints, H.data.bezierControls));
184
- for (let N = 0; N < A.length - 1; N++) if (Le(L, M, A[N].x, A[N].y, A[N + 1].x, A[N + 1].y) < D) return !0;
185
- return !1;
177
+ function be(e, t, n, r, i) {
178
+ let a = _(n, r);
179
+ if (!a) return !1;
180
+ let o = h(n.type, a, n.data.waypoints, n.data.bezierControls), s = g(o);
181
+ for (let n = 0; n < s.length - 1; n++) if (u(e, t, s[n].x, s[n].y, s[n + 1].x, s[n + 1].y) < i) return !0;
182
+ return !1;
186
183
  }
187
- function gn(L, M, H, U) {
188
- const D = H.points;
189
- for (let W = 0; W < D.length - 1; W++) if (Le(L, M, D[W].x, D[W].y, D[W + 1].x, D[W + 1].y) < U) return !0;
190
- return !1;
184
+ function xe(e, t, n, r) {
185
+ let i = n.points;
186
+ for (let n = 0; n < i.length - 1; n++) if (u(e, t, i[n].x, i[n].y, i[n + 1].x, i[n + 1].y) < r) return !0;
187
+ return !1;
191
188
  }
192
- function fr({ onPixiReady: L }) {
193
- const M = m(null), H = m(null), U = m(13751771), { pixiRef: D, readyRef: W } = Sn(M, le((f) => {
194
- U.current = f.gridDot, H.current && (H.current.dotColor = f.gridDot);
195
- }, [])), { setViewportInternal: A, viewportReqRef: N, viewport: E, autoFocus: q, showGrid: j, showAnchors: lt, gridSize: et, toolMode: $, edgeType: ot, focusOnRect: st, setFocusOnRect: zt, pendingPlacement: Ut, setPendingPlacement: Lt, setContextMenu: he, beginNodeDrag: $t, endNodeDrag: jt, presentation: Et, editingNodeId: Ct, setEditingNodeId: gt, readOnly: Ge, placementSnap: We } = Rn(), { currentCanvas: Ie, selection: Ye, setSelection: pt, setDoc: tt, currentCanvasId: be, pushCanvas: In, doc: Xe } = Mn(), _e = Yn(), Oe = m(_e);
196
- Oe.current = _e;
197
- const Fe = m(null), Jt = m(Ge);
198
- Jt.current = Ge;
199
- const Qt = m(We);
200
- Qt.current = We;
201
- const Nt = m(et);
202
- Nt.current = et;
203
- const kt = m(null), ye = m(null), pe = m(null), xe = m(null), Me = m(null), Re = m(null), Tt = m(null), te = m(null), ee = m(null), ge = m(null), Gt = m([]), Wt = m(null), Yt = m(null), ut = m(null), ne = m(null), Be = m({
204
- time: 0,
205
- wx: 0,
206
- wy: 0
207
- }), Xt = m({
208
- time: 0,
209
- wx: 0,
210
- wy: 0
211
- }), Ve = m(0), re = m(null), qe = m({
212
- x: 0,
213
- y: 0
214
- }), Ze = lt || Et ? Ie : {
215
- ...Ie,
216
- nodes: Ie.nodes.filter((f) => f.type !== "animAnchor")
217
- }, X = m(Ze);
218
- X.current = Ze;
219
- const Z = m(be);
220
- Z.current = be;
221
- const oe = m(Ye);
222
- oe.current = Ye;
223
- const Ke = m(Xe);
224
- Ke.current = Xe;
225
- const se = m($);
226
- se.current = $;
227
- const ie = m(q);
228
- ie.current = q;
229
- const ce = m(st);
230
- ce.current = st;
231
- const Ue = m(ot);
232
- Ue.current = ot;
233
- const $e = m(lt);
234
- $e.current = lt;
235
- const Dt = m(Et);
236
- Dt.current = Et;
237
- const de = m(Ut);
238
- de.current = Ut;
239
- const Se = m($t);
240
- Se.current = $t;
241
- const Ht = m(jt);
242
- Ht.current = jt;
243
- const it = m(null), nt = m(null), rt = m(null), ft = m(null), ct = m(null), wt = m(null), xt = m(null), mt = m(null), ze = m(E), Ee = m(0), { vmRef: B, screenToWorld: je } = zn(D, le((f) => {
244
- ze.current = f, Ee.current || (Ee.current = requestAnimationFrame(() => {
245
- Ee.current = 0, A(ze.current);
246
- }));
247
- }, [A])), dt = m(je);
248
- dt.current = je;
249
- const [ht, Ce] = ln(null), [Ne, ke] = ln(null), Te = m(ht);
250
- Te.current = ht;
251
- const we = m(() => {
252
- });
253
- we.current = (f, G, F) => {
254
- gt(f === "node" ? G : null), Ce({
255
- kind: f,
256
- id: G,
257
- value: F
258
- });
259
- };
260
- const Je = le((f) => {
261
- const G = Te.current;
262
- G && (tt((F) => {
263
- const Y = Z.current, K = F.canvases[Y];
264
- if (!K) return F;
265
- let V = K;
266
- if (G.kind === "node") V = {
267
- ...K,
268
- nodes: K.nodes.map((O) => O.id === G.id ? {
269
- ...O,
270
- data: {
271
- ...O.data,
272
- label: f
273
- }
274
- } : O)
275
- };
276
- else if (G.kind === "edge") V = {
277
- ...K,
278
- edges: K.edges.map((O) => O.id === G.id ? {
279
- ...O,
280
- data: {
281
- ...O.data,
282
- labelText: f
283
- }
284
- } : O)
285
- };
286
- else return F;
287
- return {
288
- ...F,
289
- canvases: {
290
- ...F.canvases,
291
- [Y]: V
292
- }
293
- };
294
- }), Ce(null), gt(null), ke(null));
295
- }, [tt, gt]), bn = le(() => {
296
- Ce(null), gt(null), ke(null);
297
- }, [gt]);
298
- Rt(() => {
299
- if (!Ct || Te.current?.id === Ct) return;
300
- const f = X.current.nodes.find((G) => G.id === Ct);
301
- f && we.current("node", f.id, f.data.label);
302
- }, [Ct]), Rt(() => {
303
- if (!ht) return;
304
- const f = B.current;
305
- if (!f) return;
306
- const G = X.current;
307
- let F = null;
308
- if (ht.kind === "node") {
309
- const Y = G.nodes.find((K) => K.id === ht.id);
310
- Y && (F = {
311
- x: Y.position.x + Y.width / 2,
312
- y: Y.position.y + Y.height / 2
313
- });
314
- } else if (ht.kind === "edge") {
315
- const Y = G.edges.find((V) => V.id === ht.id), K = /* @__PURE__ */ new Map();
316
- for (const V of G.nodes) K.set(V.id, V);
317
- if (Y) {
318
- const V = St(Y, K);
319
- if (V) {
320
- const O = mn(wn(Y.type, V, Y.data.waypoints, Y.data.bezierControls)), at = O[Math.floor(O.length / 2)] ?? {
321
- x: (V.sx + V.tx) / 2,
322
- y: (V.sy + V.ty) / 2
323
- };
324
- F = {
325
- x: at.x,
326
- y: at.y
327
- };
328
- }
329
- }
330
- }
331
- if (F) {
332
- const Y = f.worldToScreen(F.x, F.y);
333
- ke({
334
- x: Y.x,
335
- y: Y.y
336
- });
337
- }
338
- }, [ht, B]);
339
- const Qe = m(0);
340
- Rt(() => {
341
- N.current !== Qe.current && (Qe.current = N.current, ze.current = E, B.current?.setState(E));
342
- }, [
343
- E,
344
- B,
345
- N
346
- ]), Rt(() => {
347
- zt((f, G, F, Y, K) => {
348
- const V = B.current, O = M.current;
349
- if (!V || !O) return;
350
- const at = O.clientWidth || 800, vt = O.clientHeight || 600, It = Math.max(0, K?.padding ?? 60), _t = Math.max(1, at - It * 2), bt = Math.max(1, vt - It * 2), Pt = K?.preserveZoom ? V.state.zoom : Math.min(_t / Math.max(F, 1), bt / Math.max(Y, 1), K?.maxZoom ?? 2), At = f + F / 2, yt = G + Y / 2, ae = at / 2 - At * Pt, He = vt / 2 - yt * Pt;
351
- V.animateTo({
352
- x: ae,
353
- y: He,
354
- zoom: Pt
355
- }, K?.duration ?? 350);
356
- });
357
- }, [zt, B]);
358
- const tn = le((f) => {
359
- tt((G) => {
360
- const F = G.canvases[Z.current];
361
- return F ? {
362
- ...G,
363
- canvases: {
364
- ...G.canvases,
365
- [Z.current]: {
366
- ...F,
367
- lines: [...F.lines, f]
368
- }
369
- }
370
- } : G;
371
- });
372
- }, [tt, be]), De = m(tn);
373
- return De.current = tn, Rt(() => {
374
- const f = D.current;
375
- if (!f || f.destroyed) return;
376
- let G = !1, F = null, Y = null, K = null;
377
- const V = () => {
378
- if (G) return;
379
- if (!W.current) {
380
- setTimeout(V, 30);
381
- return;
382
- }
383
- H.current = new En(f.app.stage, et, j), H.current.dotColor = U.current, kt.current = new Cn(f.app.stage), ye.current = new Tn(f.world), pe.current = new Dn(f.world), xe.current = new Hn(f.world);
384
- const O = new ue();
385
- O.label = "connect-line", O.visible = !1, f.world.addChild(O), wt.current = O;
386
- const at = new ue();
387
- at.label = "transform-handles", f.app.stage.addChild(at), te.current = at;
388
- const vt = new ue();
389
- vt.label = "handle-hover", f.world.addChild(vt), ee.current = vt;
390
- const It = new ue();
391
- It.label = "edge-edit-handles", f.world.addChild(It), ne.current = It;
392
- const _t = new ue();
393
- _t.label = "ghost-placement", _t.alpha = 0.5, f.world.addChild(_t), re.current = _t, ge.current = new Ln(f.world), Me.current = new Pn(f.app.stage, f.world, {
394
- onLineComplete: (x) => De.current(x),
395
- screenToWorld: (x, s) => dt.current(x, s)
396
- }), Re.current = new An(f.app.stage, f.world, {
397
- onLineComplete: (x) => De.current(x),
398
- screenToWorld: (x, s) => dt.current(x, s)
399
- }), L?.(f);
400
- const bt = f.app.stage;
401
- bt.on("pointerdown", (x) => {
402
- if (M.current?.focus({ preventScroll: !0 }), B.current?.multiTouchActive || B.current?.isPanning || B.current?.isSpaceHeld || x.button !== 0) return;
403
- const s = se.current;
404
- if (s === "pan") {
405
- B.current?.startPan(x.global.x, x.global.y);
406
- return;
407
- }
408
- if (s === "freehand" || s === "line" || s === "polyline" || s === "arrow") return;
409
- const c = dt.current(x.global.x, x.global.y), p = X.current.nodes, P = X.current.edges, k = X.current.lines, R = oe.current, S = x.metaKey || x.ctrlKey || x.shiftKey, T = B.current?.state.zoom ?? 1;
410
- if (de.current) return;
411
- const r = Date.now(), h = Be.current, l = r - h.time < 350 && Math.hypot(c.x - h.wx, c.y - h.wy) < 8 / T;
412
- if (Be.current = {
413
- time: r,
414
- wx: c.x,
415
- wy: c.y
416
- }, R.nodeIds.size === 1 && !S && s === "select" && !Jt.current) {
417
- const t = p.find((o) => o.id === [...R.nodeIds][0]);
418
- if (t) {
419
- const o = fn(t, T);
420
- if (Math.hypot(c.x - o.x, c.y - o.y) < Q(T, 12, 24)) {
421
- ft.current = {
422
- active: !0,
423
- nodeId: t.id,
424
- cx: t.position.x + t.width / 2,
425
- cy: t.position.y + t.height / 2,
426
- startPointerAngle: Math.atan2(c.y - (t.position.y + t.height / 2), c.x - (t.position.x + t.width / 2)),
427
- startRotation: t.data.rotation ?? 0
428
- }, Se.current();
429
- return;
430
- }
431
- }
432
- }
433
- if (R.nodeIds.size === 1 && !S && s === "select") {
434
- const t = p.find((o) => o.id === [...R.nodeIds][0]);
435
- if (t) {
436
- const o = hn(c, t, Q(T, 10, 16));
437
- if (o) {
438
- const a = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), n = t.type === "geometryGroup", d = n || t.type === "flowGroup" || t.data.isGroup, w = t.position.x, g = t.position.y, z = t.width, C = t.height;
439
- for (const u of p)
440
- u.id !== t.id && (u.parentId === t.id ? a.set(u.id, {
441
- x: u.position.x,
442
- y: u.position.y,
443
- w: u.width,
444
- h: u.height
445
- }) : n && u.position.x >= w && u.position.y >= g && u.position.x + u.width <= w + z && u.position.y + u.height <= g + C && a.set(u.id, {
446
- x: u.position.x,
447
- y: u.position.y,
448
- w: u.width,
449
- h: u.height
450
- }));
451
- if (d)
452
- for (const u of X.current.lines) u.parentId === t.id ? i.set(u.id, u.points.map((b) => ({ ...b }))) : n && u.points.length > 0 && u.points.every((b) => b.x >= w && b.x <= w + z && b.y >= g && b.y <= g + C) && i.set(u.id, u.points.map((b) => ({ ...b })));
453
- xt.current = {
454
- active: !0,
455
- nodeId: t.id,
456
- handle: o,
457
- startWorld: c,
458
- startBounds: {
459
- x: t.position.x,
460
- y: t.position.y,
461
- w: t.width,
462
- h: t.height
463
- },
464
- childStarts: a,
465
- childLineStarts: i.size > 0 ? i : void 0
466
- };
467
- return;
468
- }
469
- }
470
- }
471
- let e = null;
472
- for (let t = p.length - 1; t >= 0; t--) if (qt(c.x, c.y, p[t])) {
473
- e = p[t];
474
- break;
475
- }
476
- if (e?.parentId) {
477
- const t = p.find((o) => o.id === e.parentId);
478
- t && (e = t);
479
- }
480
- fe && (Tt.current = e ? e.parentId ? p.find((t) => t.id === e.parentId)?.id ?? e.id : e.id : null, Wt.current = null, Yt.current = null);
481
- let I = !1;
482
- if (e && s === "select" && (I = Math.min(c.x - e.position.x, e.position.x + e.width - c.x, c.y - e.position.y, e.position.y + e.height - c.y) > Math.min(14, Math.min(e.width, e.height) * 0.3)), (s === "select" || s === "connect") && (e || fe) && !I) {
483
- const t = e ? [e] : p, o = Q(T, 14, 20);
484
- let a = null, i = null, n = 1 / 0;
485
- for (const d of t) {
486
- const w = Bt(Mt(d.width, d.height), d, c.x, c.y, o);
487
- if (!w) continue;
488
- const g = Vt(w, d), z = Math.hypot(c.x - g.x, c.y - g.y);
489
- z < n && (n = z, a = d, i = w);
490
- }
491
- if (a && i) {
492
- rt.current = {
493
- active: !0,
494
- sourceNodeId: a.id,
495
- sourceHandleId: i.id
496
- };
497
- return;
498
- }
499
- }
500
- if ((s === "select" || s === "connect") && !S && R.edgeIds.size > 0) {
501
- const t = /* @__PURE__ */ new Map();
502
- for (const i of p) t.set(i.id, i);
503
- const o = P.filter((i) => R.edgeIds.has(i.id)), a = yn(c.x, c.y, o, t, Q(T, 14, 20));
504
- if (a) {
505
- const i = P.find((n) => n.id === a.edgeId);
506
- if (i) {
507
- const n = a.end === "source" ? "target" : "source";
508
- ct.current = {
509
- active: !0,
510
- edgeId: i.id,
511
- movingEnd: a.end,
512
- fixedNodeId: n === "source" ? i.source : i.target,
513
- fixedHandleId: n === "source" ? i.sourceHandle : i.targetHandle
514
- };
515
- return;
516
- }
517
- }
518
- }
519
- if (s === "select" && R.edgeIds.size > 0 && !e) {
520
- const t = /* @__PURE__ */ new Map();
521
- for (const d of p) t.set(d.id, d);
522
- const o = P.filter((d) => R.edgeIds.has(d.id)), a = Q(T, 10, 14), i = xn(c.x, c.y, o, t, a);
523
- if (i) {
524
- ut.current = {
525
- active: !0,
526
- edgeId: i.edgeId,
527
- type: i.controlEnd === "c1" ? "bezierC1" : "bezierC2",
528
- index: i.segmentIndex
529
- };
530
- return;
531
- }
532
- const n = pn(c.x, c.y, o, a);
533
- if (n) {
534
- if (l) {
535
- tt((d) => {
536
- const w = d.canvases[Z.current];
537
- return w ? {
538
- ...d,
539
- canvases: {
540
- ...d.canvases,
541
- [Z.current]: {
542
- ...w,
543
- edges: w.edges.map((g) => {
544
- if (g.id !== n.edgeId) return g;
545
- const z = [...g.data.waypoints ?? []];
546
- z.splice(n.waypointIndex, 1);
547
- const C = {
548
- ...g.data,
549
- waypoints: z.length > 0 ? z : void 0
550
- };
551
- if (g.type === "simplebezier" && g.data.bezierControls) {
552
- const u = [...g.data.bezierControls];
553
- u.splice(n.waypointIndex, 2, null), C.bezierControls = u.some((b) => b !== null) ? u : void 0;
554
- }
555
- return {
556
- ...g,
557
- data: C
558
- };
559
- })
560
- }
561
- }
562
- } : d;
563
- });
564
- return;
565
- }
566
- ut.current = {
567
- active: !0,
568
- edgeId: n.edgeId,
569
- type: "waypoint",
570
- index: n.waypointIndex
571
- };
572
- return;
573
- }
574
- if (l) {
575
- for (const d of o) if (Ae(c.x, c.y, d, t, Q(T, 8, 12))) {
576
- const w = _n(c.x, c.y, d, t), g = {
577
- x: c.x,
578
- y: c.y
579
- };
580
- tt((z) => {
581
- const C = z.canvases[Z.current];
582
- return C ? {
583
- ...z,
584
- canvases: {
585
- ...z.canvases,
586
- [Z.current]: {
587
- ...C,
588
- edges: C.edges.map((u) => {
589
- if (u.id !== d.id) return u;
590
- const b = [...u.data.waypoints ?? []];
591
- b.splice(w, 0, g);
592
- const _ = {
593
- ...u.data,
594
- waypoints: b
595
- };
596
- if (u.type === "simplebezier" && u.data.bezierControls) {
597
- const J = [...u.data.bezierControls];
598
- for (; J.length < (u.data.waypoints ?? []).length + 1; ) J.push(null);
599
- J.splice(w, 1, null, null), _.bezierControls = J;
600
- }
601
- return {
602
- ...u,
603
- data: _
604
- };
605
- })
606
- }
607
- }
608
- } : z;
609
- }), ut.current = {
610
- active: !0,
611
- edgeId: d.id,
612
- type: "waypoint",
613
- index: w
614
- };
615
- return;
616
- }
617
- }
618
- }
619
- if (e && (s === "select" || s === "connect")) {
620
- !S && !R.nodeIds.has(e.id) ? pt({
621
- nodeIds: /* @__PURE__ */ new Set([e.id]),
622
- edgeIds: /* @__PURE__ */ new Set(),
623
- lineIds: /* @__PURE__ */ new Set()
624
- }) : S && pt((n) => {
625
- const d = new Set(n.nodeIds);
626
- return d.has(e.id) ? d.delete(e.id) : d.add(e.id), {
627
- nodeIds: d,
628
- edgeIds: /* @__PURE__ */ new Set(),
629
- lineIds: /* @__PURE__ */ new Set()
630
- };
631
- }), ie.current && ce.current(e.position.x, e.position.y, e.width, e.height, {
632
- padding: 80,
633
- preserveZoom: !0,
634
- duration: 280
635
- });
636
- const t = R.nodeIds.has(e.id) ? new Set(R.nodeIds) : /* @__PURE__ */ new Set([e.id]);
637
- S && !R.nodeIds.has(e.id) && t.add(e.id);
638
- const o = /* @__PURE__ */ new Set();
639
- for (const n of [...t]) {
640
- const d = p.find((b) => b.id === n);
641
- if (!d || d.type !== "flowGroup" && d.type !== "geometryGroup" && !d.data.isGroup) continue;
642
- const w = d.type === "geometryGroup", g = d.position.x, z = d.position.y, C = d.width, u = d.height;
643
- for (const b of p)
644
- if (!(t.has(b.id) || b.id === n)) {
645
- if (b.parentId === n) {
646
- t.add(b.id);
647
- continue;
648
- }
649
- w && b.position.x >= g && b.position.y >= z && b.position.x + b.width <= g + C && b.position.y + b.height <= z + u && t.add(b.id);
650
- }
651
- for (const b of X.current.lines) b.parentId === n && o.add(b.id);
652
- if (w) for (const b of X.current.lines)
653
- o.has(b.id) || b.points.length > 0 && b.points.every((_) => _.x >= g && _.x <= g + C && _.y >= z && _.y <= z + u) && o.add(b.id);
654
- }
655
- const a = /* @__PURE__ */ new Map();
656
- for (const n of p) t.has(n.id) && a.set(n.id, { ...n.position });
657
- const i = /* @__PURE__ */ new Map();
658
- if (o.size > 0)
659
- for (const n of X.current.lines) o.has(n.id) && i.set(n.id, n.points.map((d) => ({ ...d })));
660
- it.current = {
661
- active: !0,
662
- nodeIds: t,
663
- lineIds: o.size > 0 ? o : void 0,
664
- startWorld: c,
665
- nodeStarts: a,
666
- linePointStarts: i.size > 0 ? i : void 0
667
- }, Se.current();
668
- return;
669
- }
670
- const y = /* @__PURE__ */ new Map();
671
- for (const t of p) y.set(t.id, t);
672
- const v = Q(T, 8, 12);
673
- for (const t of P) if (Ae(c.x, c.y, t, y, v)) {
674
- if (pt(S ? (o) => {
675
- const a = new Set(o.edgeIds);
676
- return a.has(t.id) ? a.delete(t.id) : a.add(t.id), {
677
- ...o,
678
- edgeIds: a
679
- };
680
- } : {
681
- nodeIds: /* @__PURE__ */ new Set(),
682
- edgeIds: /* @__PURE__ */ new Set([t.id]),
683
- lineIds: /* @__PURE__ */ new Set()
684
- }), ie.current) {
685
- const o = y.get(t.source), a = y.get(t.target);
686
- if (o && a) {
687
- const i = Math.min(o.position.x, a.position.x), n = Math.min(o.position.y, a.position.y), d = Math.max(o.position.x + o.width, a.position.x + a.width), w = Math.max(o.position.y + o.height, a.position.y + a.height);
688
- ce.current(i, n, d - i, w - n, {
689
- padding: 80,
690
- preserveZoom: !0,
691
- duration: 280
692
- });
693
- }
694
- }
695
- return;
696
- }
697
- for (const t of k) if (gn(c.x, c.y, t, v)) {
698
- const o = R.lineIds.has(t.id);
699
- if (S ? pt((n) => {
700
- const d = new Set(n.lineIds);
701
- return d.has(t.id) ? d.delete(t.id) : d.add(t.id), {
702
- ...n,
703
- lineIds: d
704
- };
705
- }) : o || pt({
706
- nodeIds: /* @__PURE__ */ new Set(),
707
- edgeIds: /* @__PURE__ */ new Set(),
708
- lineIds: /* @__PURE__ */ new Set([t.id])
709
- }), ie.current && t.points.length > 0) {
710
- const n = t.points.map((u) => u.x), d = t.points.map((u) => u.y), w = Math.min(...n), g = Math.min(...d), z = Math.max(...n), C = Math.max(...d);
711
- ce.current(w, g, Math.max(1, z - w), Math.max(1, C - g), {
712
- padding: 80,
713
- preserveZoom: !0,
714
- duration: 280
715
- });
716
- }
717
- const a = o ? new Set(R.lineIds) : /* @__PURE__ */ new Set([t.id]), i = /* @__PURE__ */ new Map();
718
- for (const n of k) a.has(n.id) && i.set(n.id, n.points.map((d) => ({ ...d })));
719
- mt.current = {
720
- active: !0,
721
- lineIds: a,
722
- startWorld: c,
723
- pointStarts: i
724
- };
725
- return;
726
- }
727
- S || pt({
728
- nodeIds: /* @__PURE__ */ new Set(),
729
- edgeIds: /* @__PURE__ */ new Set(),
730
- lineIds: /* @__PURE__ */ new Set()
731
- }), s === "select" && (nt.current = {
732
- active: !0,
733
- startScreen: {
734
- x: x.global.x,
735
- y: x.global.y
736
- }
737
- });
738
- }), bt.on("globalpointermove", (x) => {
739
- const s = dt.current(x.global.x, x.global.y);
740
- if (qe.current = s, B.current?.multiTouchActive) return;
741
- const c = se.current;
742
- if (c === "freehand" || c === "line" || c === "polyline" || c === "arrow") return;
743
- const p = X.current.nodes, P = X.current.edges, k = B.current?.state.zoom ?? 1, R = !it.current?.active && !rt.current?.active && !xt.current?.active && !ct.current?.active && !ut.current?.active && !mt.current?.active && !ft.current?.active;
744
- let S = null;
745
- for (let r = p.length - 1; r >= 0; r--) if (qt(s.x, s.y, p[r])) {
746
- const h = p[r];
747
- S = h.parentId ? p.find((l) => l.id === h.parentId)?.id ?? h.id : h.id;
748
- break;
749
- }
750
- if (Tt.current = S, R && (c === "select" || c === "connect")) {
751
- const r = /* @__PURE__ */ new Map();
752
- for (const y of p) r.set(y.id, y);
753
- const h = oe.current, l = h.edgeIds.size > 0 ? P.filter((y) => h.edgeIds.has(y.id)) : [], e = l.length > 0 ? yn(s.x, s.y, l, r, Q(k, 12, 18)) : null;
754
- Yt.current = e;
755
- let I = null;
756
- if (S) {
757
- const y = p.find((v) => v.id === S);
758
- if (y) {
759
- const v = Bt(Mt(y.width, y.height), y, s.x, s.y, Q(k, 14, 20));
760
- if (v) {
761
- const t = Vt(v, y);
762
- I = {
763
- nodeId: y.id,
764
- handleId: v.id,
765
- wx: t.x,
766
- wy: t.y
767
- };
768
- }
769
- }
770
- }
771
- Wt.current = I;
772
- }
773
- const T = M.current;
774
- if (T && R) {
775
- const r = oe.current;
776
- let h = "";
777
- if (Yt.current) h = "crosshair";
778
- else if (Wt.current) h = "crosshair";
779
- else if (r.edgeIds.size > 0 && c === "select") {
780
- const l = P.filter((y) => r.edgeIds.has(y.id)), e = /* @__PURE__ */ new Map();
781
- for (const y of p) e.set(y.id, y);
782
- const I = Q(k, 10, 14);
783
- (pn(s.x, s.y, l, I) || xn(s.x, s.y, l, e, I)) && (h = "grab");
784
- }
785
- if (!h && r.nodeIds.size === 1 && c === "select") {
786
- const l = p.find((e) => e.id === [...r.nodeIds][0]);
787
- if (l) {
788
- const e = hn(s, l, Q(k, 10, 16));
789
- if (e) h = Xn[e];
790
- else if (!Jt.current) {
791
- const I = fn(l, k);
792
- Math.hypot(s.x - I.x, s.y - I.y) < Q(k, 12, 24) && (h = "grab");
793
- }
794
- }
795
- }
796
- if (!h && c === "select") {
797
- const l = X.current.lines, e = Q(k, 8, 12);
798
- for (const I of l) if (gn(s.x, s.y, I, e)) {
799
- h = "move";
800
- break;
801
- }
802
- }
803
- T.style.cursor = h;
804
- }
805
- if (xt.current?.active) {
806
- const r = xt.current, h = s.x - r.startWorld.x, l = s.y - r.startWorld.y, e = On(r.startBounds, r.handle, h, l), I = X.current.nodes, y = me([{
807
- id: r.nodeId,
808
- type: "shapeRect",
809
- position: {
810
- x: e.x,
811
- y: e.y
812
- },
813
- width: e.w,
814
- height: e.h,
815
- data: {}
816
- }], I);
817
- if (e.x += y.dx, e.y += y.dy, (r.handle === "ne" || r.handle === "se") && (e.w += y.dx), (r.handle === "se" || r.handle === "sw") && (e.h += y.dy), Gt.current = y.guides, Qt.current && Nt.current > 0 && y.guides.length === 0) {
818
- const n = Nt.current;
819
- (r.handle === "nw" || r.handle === "sw") && (e.x = Math.round(e.x / n) * n), (r.handle === "nw" || r.handle === "ne") && (e.y = Math.round(e.y / n) * n), (r.handle === "ne" || r.handle === "se") && (e.w = Math.round((e.x + e.w) / n) * n - e.x), (r.handle === "se" || r.handle === "sw") && (e.h = Math.round((e.y + e.h) / n) * n - e.y);
820
- }
821
- const v = r.startBounds, t = Math.max(e.w, 24), o = Math.max(e.h, 24), a = v.w > 0 ? t / v.w : 1, i = v.h > 0 ? o / v.h : 1;
822
- tt((n) => {
823
- const d = n.canvases[Z.current];
824
- return d ? {
825
- ...n,
826
- canvases: {
827
- ...n.canvases,
828
- [Z.current]: {
829
- ...d,
830
- nodes: d.nodes.map((w) => {
831
- if (w.id === r.nodeId) return {
832
- ...w,
833
- position: {
834
- x: e.x,
835
- y: e.y
836
- },
837
- width: t,
838
- height: o
839
- };
840
- const g = r.childStarts.get(w.id);
841
- return g ? {
842
- ...w,
843
- position: {
844
- x: e.x + (g.x - v.x) * a,
845
- y: e.y + (g.y - v.y) * i
846
- },
847
- width: Math.max(g.w * a, 24),
848
- height: Math.max(g.h * i, 24)
849
- } : w;
850
- }),
851
- lines: r.childLineStarts ? d.lines.map((w) => {
852
- const g = r.childLineStarts.get(w.id);
853
- return g ? {
854
- ...w,
855
- points: g.map((z) => ({
856
- x: e.x + (z.x - v.x) * a,
857
- y: e.y + (z.y - v.y) * i
858
- }))
859
- } : w;
860
- }) : d.lines
861
- }
862
- }
863
- } : n;
864
- });
865
- return;
866
- }
867
- if (ft.current?.active) {
868
- const r = ft.current, h = (Math.atan2(s.y - r.cy, s.x - r.cx) - r.startPointerAngle) * 180 / Math.PI;
869
- let l = ((r.startRotation + h) % 360 + 360) % 360;
870
- if (x.shiftKey) l = Math.round(l / 15) * 15 % 360;
871
- else {
872
- const e = Math.round(l / 45) * 45;
873
- Math.abs(l - e) < 4 && (l = (e % 360 + 360) % 360);
874
- }
875
- tt((e) => {
876
- const I = e.canvases[Z.current];
877
- return I ? {
878
- ...e,
879
- canvases: {
880
- ...e.canvases,
881
- [Z.current]: {
882
- ...I,
883
- nodes: I.nodes.map((y) => y.id === r.nodeId ? {
884
- ...y,
885
- data: {
886
- ...y.data,
887
- rotation: l
888
- }
889
- } : y)
890
- }
891
- }
892
- } : e;
893
- }), M.current && (M.current.style.cursor = "grabbing");
894
- return;
895
- }
896
- if (ut.current?.active) {
897
- const r = ut.current, h = X.current.nodes, l = /* @__PURE__ */ new Map();
898
- for (const e of h) l.set(e.id, e);
899
- tt((e) => {
900
- const I = e.canvases[Z.current];
901
- return I ? {
902
- ...e,
903
- canvases: {
904
- ...e.canvases,
905
- [Z.current]: {
906
- ...I,
907
- edges: I.edges.map((y) => {
908
- if (y.id !== r.edgeId) return y;
909
- if (r.type === "waypoint") {
910
- const Ft = [...y.data.waypoints ?? []];
911
- return r.index < Ft.length && (Ft[r.index] = {
912
- x: s.x,
913
- y: s.y
914
- }), {
915
- ...y,
916
- data: {
917
- ...y.data,
918
- waypoints: Ft
919
- }
920
- };
921
- }
922
- const v = St(y, l);
923
- if (!v) return y;
924
- const t = y.data.waypoints ?? [], o = [
925
- {
926
- x: v.sx,
927
- y: v.sy
928
- },
929
- ...t,
930
- {
931
- x: v.tx,
932
- y: v.ty
933
- }
934
- ], a = o.length - 1, i = [...y.data.bezierControls ?? []];
935
- for (; i.length < a; ) i.push(null);
936
- const n = r.index;
937
- if (n >= a) return y;
938
- const d = o[n], w = o[n + 1], g = i[n], z = Math.hypot(w.x - d.x, w.y - d.y), C = Math.max(30, z * 0.3), u = a - 1, b = n === 0 ? d.x + v.snx * C : d.x + (w.x - d.x) * 0.4, _ = n === 0 ? d.y + v.sny * C : d.y, J = n === u ? w.x + v.tnx * C : w.x - (w.x - d.x) * 0.4, Ot = n === u ? w.y + v.tny * C : w.y;
939
- return r.type === "bezierC1" ? i[n] = {
940
- c1x: s.x,
941
- c1y: s.y,
942
- c2x: g?.c2x ?? J,
943
- c2y: g?.c2y ?? Ot
944
- } : i[n] = {
945
- c1x: g?.c1x ?? b,
946
- c1y: g?.c1y ?? _,
947
- c2x: s.x,
948
- c2y: s.y
949
- }, {
950
- ...y,
951
- data: {
952
- ...y.data,
953
- bezierControls: i
954
- }
955
- };
956
- })
957
- }
958
- }
959
- } : e;
960
- });
961
- return;
962
- }
963
- if (mt.current?.active) {
964
- const r = mt.current, h = s.x - r.startWorld.x, l = s.y - r.startWorld.y;
965
- tt((e) => {
966
- const I = e.canvases[Z.current];
967
- return I ? {
968
- ...e,
969
- canvases: {
970
- ...e.canvases,
971
- [Z.current]: {
972
- ...I,
973
- lines: I.lines.map((y) => {
974
- const v = r.pointStarts.get(y.id);
975
- return v ? {
976
- ...y,
977
- points: v.map((t) => ({
978
- x: t.x + h,
979
- y: t.y + l
980
- }))
981
- } : y;
982
- })
983
- }
984
- }
985
- } : e;
986
- });
987
- return;
988
- }
989
- if (it.current?.active) {
990
- const r = it.current, h = s.x - r.startWorld.x, l = s.y - r.startWorld.y;
991
- let e = h, I = l;
992
- if (Qt.current && Nt.current > 0 && r.nodeIds.size > 0) {
993
- const t = Nt.current, o = r.nodeStarts.values().next().value;
994
- o && (e = Kt(o.x + h, t, !0) - o.x, I = Kt(o.y + l, t, !0) - o.y);
995
- }
996
- const y = X.current.nodes, v = me(y.filter((t) => r.nodeIds.has(t.id)).map((t) => {
997
- const o = r.nodeStarts.get(t.id);
998
- return {
999
- ...t,
1000
- position: {
1001
- x: o.x + e,
1002
- y: o.y + I
1003
- }
1004
- };
1005
- }), y);
1006
- e += v.dx, I += v.dy, Gt.current = v.guides, tt((t) => {
1007
- const o = t.canvases[Z.current];
1008
- return o ? {
1009
- ...t,
1010
- canvases: {
1011
- ...t.canvases,
1012
- [Z.current]: {
1013
- ...o,
1014
- nodes: o.nodes.map((a) => {
1015
- const i = r.nodeStarts.get(a.id);
1016
- return i ? {
1017
- ...a,
1018
- position: {
1019
- x: i.x + e,
1020
- y: i.y + I
1021
- }
1022
- } : a;
1023
- }),
1024
- lines: r.linePointStarts ? o.lines.map((a) => {
1025
- const i = r.linePointStarts.get(a.id);
1026
- return i ? {
1027
- ...a,
1028
- points: i.map((n) => ({
1029
- x: n.x + e,
1030
- y: n.y + I
1031
- }))
1032
- } : a;
1033
- }) : o.lines
1034
- }
1035
- }
1036
- } : t;
1037
- });
1038
- return;
1039
- }
1040
- if (nt.current?.active && kt.current) {
1041
- const r = Math.min(nt.current.startScreen.x, x.global.x), h = Math.min(nt.current.startScreen.y, x.global.y), l = Math.abs(x.global.x - nt.current.startScreen.x), e = Math.abs(x.global.y - nt.current.startScreen.y);
1042
- kt.current.showMarquee(r, h, l, e);
1043
- }
1044
- if (rt.current?.active && wt.current) {
1045
- const r = X.current.nodes.find((h) => h.id === rt.current.sourceNodeId);
1046
- if (r) {
1047
- const h = Mt(r.width, r.height).find((l) => l.id === rt.current.sourceHandleId);
1048
- if (h) {
1049
- const l = Vt(h, r), e = l.x, I = l.y;
1050
- let y = s.x, v = s.y;
1051
- const t = Tt.current;
1052
- if (t && t !== rt.current.sourceNodeId) {
1053
- const a = X.current.nodes.find((i) => i.id === t);
1054
- if (a) {
1055
- const i = Bt(Mt(a.width, a.height), a, s.x, s.y, 1 / 0);
1056
- if (i) {
1057
- const n = Vt(i, a);
1058
- y = n.x, v = n.y;
1059
- }
1060
- }
1061
- }
1062
- const o = wt.current;
1063
- o.clear(), o.moveTo(e, I).lineTo(y, v).stroke({
1064
- color: 3900150,
1065
- width: 2,
1066
- alpha: 0.6
1067
- }), o.visible = !0;
1068
- }
1069
- }
1070
- }
1071
- if (ct.current?.active && wt.current && !wt.current.destroyed) {
1072
- const r = ct.current, h = X.current.nodes.find((l) => l.id === r.fixedNodeId);
1073
- if (h) {
1074
- const l = Mt(h.width, h.height).find((i) => i.id === r.fixedHandleId), e = l ? Vt(l, h) : {
1075
- x: h.position.x + h.width / 2,
1076
- y: h.position.y + h.height / 2
1077
- }, I = e.x, y = e.y;
1078
- let v = s.x, t = s.y;
1079
- const o = Tt.current;
1080
- if (o && o !== r.fixedNodeId) {
1081
- const i = X.current.nodes.find((n) => n.id === o);
1082
- if (i) {
1083
- const n = Bt(Mt(i.width, i.height), i, s.x, s.y, 1 / 0);
1084
- if (n) {
1085
- const d = Vt(n, i);
1086
- v = d.x, t = d.y;
1087
- }
1088
- }
1089
- }
1090
- const a = wt.current;
1091
- a.clear(), a.moveTo(I, y).lineTo(v, t).stroke({
1092
- color: 16347926,
1093
- width: 2,
1094
- alpha: 0.7
1095
- }), a.visible = !0;
1096
- }
1097
- }
1098
- });
1099
- const Pt = () => {
1100
- Gt.current = [];
1101
- try {
1102
- ge.current?.clear();
1103
- } catch {
1104
- }
1105
- try {
1106
- const x = wt.current;
1107
- x && !x.destroyed && (x.clear(), x.visible = !1);
1108
- } catch {
1109
- }
1110
- M.current && (M.current.style.cursor = "");
1111
- };
1112
- bt.on("pointerup", (x) => {
1113
- if (Pt(), ft.current?.active) {
1114
- ft.current = null, Ht.current();
1115
- return;
1116
- }
1117
- if (ut.current?.active) {
1118
- ut.current = null;
1119
- return;
1120
- }
1121
- if (xt.current?.active) {
1122
- xt.current = null;
1123
- return;
1124
- }
1125
- if (mt.current?.active) {
1126
- mt.current = null;
1127
- return;
1128
- }
1129
- if (it.current?.active && (it.current = null, Ht.current()), nt.current?.active) {
1130
- const s = dt.current(nt.current.startScreen.x, nt.current.startScreen.y), c = dt.current(x.global.x, x.global.y), p = Math.min(s.x, c.x), P = Math.min(s.y, c.y), k = Math.abs(c.x - s.x), R = Math.abs(c.y - s.y);
1131
- if (k > 4 && R > 4) {
1132
- const S = X.current.nodes.filter((r) => kn(p, P, k, R, r.position.x, r.position.y, r.width, r.height)), T = X.current.lines.filter((r) => r.points.length === 0 ? !1 : r.points.every((h) => h.x >= p && h.x <= p + k && h.y >= P && h.y <= P + R));
1133
- pt({
1134
- nodeIds: new Set(S.map((r) => r.id)),
1135
- edgeIds: /* @__PURE__ */ new Set(),
1136
- lineIds: new Set(T.map((r) => r.id))
1137
- });
1138
- }
1139
- nt.current = null, kt.current?.hideMarquee();
1140
- }
1141
- if (ct.current?.active) {
1142
- const s = ct.current.edgeId, c = ct.current.movingEnd, p = ct.current.fixedNodeId;
1143
- ct.current = null;
1144
- const P = dt.current(x.global.x, x.global.y), k = X.current.nodes, R = fe ? Q(B.current?.state.zoom ?? 1, 12, 24) : 0;
1145
- let S = null;
1146
- for (let T = k.length - 1; T >= 0; T--) if (qt(P.x, P.y, k[T], R) && k[T].id !== p) {
1147
- S = k[T];
1148
- break;
1149
- }
1150
- if (S) {
1151
- const T = S.id, r = Bt(Mt(S.width, S.height), S, P.x, P.y, 1 / 0)?.id;
1152
- tt((h) => {
1153
- const l = h.canvases[Z.current];
1154
- return l ? {
1155
- ...h,
1156
- canvases: {
1157
- ...h.canvases,
1158
- [Z.current]: {
1159
- ...l,
1160
- edges: l.edges.map((e) => e.id !== s ? e : c === "source" ? {
1161
- ...e,
1162
- source: T,
1163
- sourceHandle: r
1164
- } : {
1165
- ...e,
1166
- target: T,
1167
- targetHandle: r
1168
- })
1169
- }
1170
- }
1171
- } : h;
1172
- });
1173
- }
1174
- return;
1175
- }
1176
- if (rt.current?.active) {
1177
- const s = rt.current.sourceNodeId, c = rt.current.sourceHandleId;
1178
- rt.current = null;
1179
- const p = dt.current(x.global.x, x.global.y), P = X.current.nodes, k = fe ? Q(B.current?.state.zoom ?? 1, 12, 24) : 0;
1180
- let R = null;
1181
- for (let S = P.length - 1; S >= 0; S--) if (qt(p.x, p.y, P[S], k) && P[S].id !== s) {
1182
- R = P[S];
1183
- break;
1184
- }
1185
- if (R) {
1186
- const S = R.id, T = Bt(Mt(R.width, R.height), R, p.x, p.y, 1 / 0)?.id, r = `edge_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`, h = Ue.current;
1187
- tt((l) => {
1188
- const e = l.canvases[Z.current];
1189
- return !e || e.edges.some((I) => I.source === s && I.target === S && I.sourceHandle === c && I.targetHandle === T) ? l : {
1190
- ...l,
1191
- canvases: {
1192
- ...l.canvases,
1193
- [Z.current]: {
1194
- ...e,
1195
- edges: [...e.edges, {
1196
- id: r,
1197
- source: s,
1198
- target: S,
1199
- sourceHandle: c,
1200
- targetHandle: T,
1201
- type: h,
1202
- data: {
1203
- strokeColor: "theme:base-content",
1204
- strokeWidth: 2,
1205
- lineStyle: "solid",
1206
- markerEnd: "arrowclosed"
1207
- }
1208
- }]
1209
- }
1210
- }
1211
- };
1212
- });
1213
- }
1214
- }
1215
- }), bt.on("pointerupoutside", () => {
1216
- Pt(), it.current?.active && Ht.current(), ft.current?.active && Ht.current(), it.current = null, ft.current = null, xt.current = null, nt.current = null, ct.current = null, rt.current = null, ut.current = null, mt.current = null, Tt.current = null, Wt.current = null, Yt.current = null, kt.current?.hideMarquee();
1217
- });
1218
- const At = M.current;
1219
- let yt = null;
1220
- const ae = (x) => {
1221
- const s = At.getBoundingClientRect(), c = x[0].clientX, p = x[0].clientY, P = x[1].clientX, k = x[1].clientY;
1222
- return {
1223
- dist: Math.hypot(P - c, k - p),
1224
- midX: (c + P) / 2 - s.left,
1225
- midY: (p + k) / 2 - s.top
1226
- };
1227
- }, He = () => {
1228
- Pt(), it.current?.active && Ht.current(), ft.current?.active && Ht.current(), it.current = null, ft.current = null, xt.current = null, nt.current = null, ct.current = null, rt.current = null, ut.current = null, mt.current = null, Tt.current = null, Wt.current = null, Yt.current = null, kt.current?.hideMarquee(), B.current?.cancelPan();
1229
- }, en = (x) => {
1230
- if (x.touches.length < 2) return;
1231
- const s = B.current;
1232
- s && (s.multiTouchActive = !0, He(), yt = ae(x.touches), x.preventDefault());
1233
- }, nn = (x) => {
1234
- if (!yt || x.touches.length < 2) return;
1235
- x.preventDefault();
1236
- const s = B.current;
1237
- if (!s) return;
1238
- const c = ae(x.touches), p = c.dist / Math.max(1, yt.dist);
1239
- Number.isFinite(p) && p > 0 && s.zoomAt(c.midX, c.midY, p), s.setState({
1240
- x: s.state.x + (c.midX - yt.midX),
1241
- y: s.state.y + (c.midY - yt.midY)
1242
- }), yt = c;
1243
- }, Pe = (x) => {
1244
- if (x.touches.length >= 2) {
1245
- yt = ae(x.touches);
1246
- return;
1247
- }
1248
- if (yt = null, x.touches.length === 0) {
1249
- const s = B.current;
1250
- s && (s.multiTouchActive = !1), Ve.current = performance.now() + 350;
1251
- }
1252
- };
1253
- At?.addEventListener("touchstart", en, { passive: !1 }), At?.addEventListener("touchmove", nn, { passive: !1 }), At?.addEventListener("touchend", Pe), At?.addEventListener("touchcancel", Pe), F = en, Y = nn, K = Pe, bt.on("rightclick", (x) => {
1254
- if (x.preventDefault?.(), B.current?.didRightPan) return;
1255
- const s = dt.current(x.global.x, x.global.y), c = X.current.nodes;
1256
- let p = null;
1257
- for (let S = c.length - 1; S >= 0; S--) if (qt(s.x, s.y, c[S])) {
1258
- p = c[S].id;
1259
- break;
1260
- }
1261
- const P = x.nativeEvent, k = P?.clientX ?? x.global.x, R = P?.clientY ?? x.global.y;
1262
- he({
1263
- x: k,
1264
- y: R,
1265
- nodeId: p
1266
- });
1267
- }), bt.on("pointertap", (x) => {
1268
- if (B.current?.multiTouchActive || performance.now() < Ve.current || x.button !== 0) return;
1269
- const s = Date.now(), c = dt.current(x.global.x, x.global.y), p = de.current;
1270
- if (p) {
1271
- const S = Nn("node"), T = Nt.current, r = Qt.current, h = Kt(c.x - p.width / 2, T, r), l = Kt(c.y - p.height / 2, T, r), e = me([{
1272
- id: "__ghost__",
1273
- type: p.type,
1274
- position: {
1275
- x: h,
1276
- y: l
1277
- },
1278
- width: p.width,
1279
- height: p.height,
1280
- data: {}
1281
- }], X.current.nodes), I = h + e.dx, y = l + e.dy;
1282
- tt((v) => {
1283
- const t = v.canvases[Z.current];
1284
- if (!t) return v;
1285
- const o = {};
1286
- p.type === "animAnchor" && (o.animIndex = Wn(v));
1287
- const a = Math.max(0, ...t.nodes.map((i) => i.zIndex ?? 0), ...t.lines.map((i) => i.zIndex ?? 0));
1288
- return {
1289
- ...v,
1290
- canvases: {
1291
- ...v.canvases,
1292
- [Z.current]: {
1293
- ...t,
1294
- nodes: [...t.nodes, {
1295
- id: S,
1296
- type: p.type,
1297
- position: {
1298
- x: I,
1299
- y
1300
- },
1301
- width: p.width,
1302
- height: p.height,
1303
- zIndex: a + 1,
1304
- data: {
1305
- ...p.data,
1306
- ...o
1307
- }
1308
- }]
1309
- }
1310
- }
1311
- };
1312
- }), pt({
1313
- nodeIds: /* @__PURE__ */ new Set([S]),
1314
- edgeIds: /* @__PURE__ */ new Set(),
1315
- lineIds: /* @__PURE__ */ new Set()
1316
- }), ie.current && window.setTimeout(() => {
1317
- ce.current(I, y, p.width, p.height, {
1318
- padding: 80,
1319
- preserveZoom: !0,
1320
- duration: 280
1321
- });
1322
- }, 0), Xt.current = {
1323
- time: 0,
1324
- wx: 0,
1325
- wy: 0
1326
- };
1327
- return;
1328
- }
1329
- const P = Xt.current, k = c.x - P.wx, R = c.y - P.wy;
1330
- if (s - P.time < 400 && Math.abs(k) < 10 && Math.abs(R) < 10) {
1331
- const S = X.current.nodes;
1332
- for (let l = S.length - 1; l >= 0; l--) if (qt(c.x, c.y, S[l])) {
1333
- const e = S[l], I = e.data.childCanvasId;
1334
- if (I) {
1335
- In(I), Xt.current = {
1336
- time: 0,
1337
- wx: 0,
1338
- wy: 0
1339
- };
1340
- return;
1341
- }
1342
- we.current("node", e.id, e.data.label ?? ""), Xt.current = {
1343
- time: 0,
1344
- wx: 0,
1345
- wy: 0
1346
- };
1347
- return;
1348
- }
1349
- const T = X.current.edges, r = /* @__PURE__ */ new Map();
1350
- for (const l of S) r.set(l.id, l);
1351
- const h = B.current?.state.zoom ?? 1;
1352
- for (let l = T.length - 1; l >= 0; l--) if (Ae(c.x, c.y, T[l], r, Q(h, 8, 12))) {
1353
- we.current("edge", T[l].id, T[l].data.labelText ?? ""), Xt.current = {
1354
- time: 0,
1355
- wx: 0,
1356
- wy: 0
1357
- };
1358
- return;
1359
- }
1360
- }
1361
- Xt.current = {
1362
- time: s,
1363
- wx: c.x,
1364
- wy: c.y
1365
- };
1366
- });
1367
- let rn = !1;
1368
- f.app.ticker.add((x) => {
1369
- if (f.destroyed) return;
1370
- const s = x.deltaMS, c = f.app.screen, p = B.current?.state ?? {
1371
- x: 0,
1372
- y: 0,
1373
- zoom: 1
1374
- };
1375
- H.current?.update(p, c.width, c.height);
1376
- const P = B.current?.isPanning ?? !1;
1377
- P !== rn && (rn = P, M.current && (M.current.style.cursor = P ? "grabbing" : ""));
1378
- const k = X.current, R = oe.current, S = Gn(Ke.current), T = /* @__PURE__ */ new Map();
1379
- S.forEach((t, o) => T.set(t.node.id, o + 1)), ye.current?.advanceAnimation(s);
1380
- const r = Dt.current ? S[Dt.current.current] : void 0;
1381
- ye.current?.sync(k.nodes, R.nodeIds, Tt.current, T, {
1382
- showAnchors: $e.current,
1383
- presentation: Dt.current !== null,
1384
- presentationAnchorId: r?.node.id,
1385
- presentationAnchorVisible: Dt.current?.showAnchor ?? !1
1386
- });
1387
- const h = /* @__PURE__ */ new Map();
1388
- for (const t of k.nodes) h.set(t.id, t);
1389
- pe.current?.advanceAnimation(s), pe.current?.sync(k.edges, h, R.edgeIds, null, { presentation: Dt.current !== null }), xe.current?.advanceAnimation(s), xe.current?.sync(k.lines, R.lineIds), ge.current?.update(Gt.current, c.width, c.height, p);
1390
- const l = Fe.current;
1391
- if (l) {
1392
- const t = (R.nodeIds.size > 0 || R.edgeIds.size > 0 || R.lineIds.size > 0) && !Jt.current && !Dt.current && !de.current;
1393
- let o = !t;
1394
- if (t) {
1395
- let a = 1 / 0, i = 1 / 0, n = -1 / 0, d = -1 / 0;
1396
- const w = (g, z, C, u) => {
1397
- a = Math.min(a, g), i = Math.min(i, z), n = Math.max(n, g + C), d = Math.max(d, z + u);
1398
- };
1399
- for (const g of k.nodes) R.nodeIds.has(g.id) && w(g.position.x, g.position.y, g.width, g.height);
1400
- for (const g of k.edges) {
1401
- if (!R.edgeIds.has(g.id)) continue;
1402
- const z = h.get(g.source), C = h.get(g.target);
1403
- z && w(z.position.x, z.position.y, z.width, z.height), C && w(C.position.x, C.position.y, C.width, C.height);
1404
- }
1405
- for (const g of k.lines)
1406
- if (R.lineIds.has(g.id))
1407
- for (const z of g.points) w(z.x, z.y, 0, 0);
1408
- if (a === 1 / 0) o = !0;
1409
- else {
1410
- const g = p.zoom, z = 66, C = 30, u = 6;
1411
- let b = n * g + p.x + 8, _ = i * g + p.y - C - 6;
1412
- b + z > c.width - u && (b = Math.max(u, c.width - z - u)), _ < u && (_ = i * g + p.y + u), _ + C > c.height - u && (_ = Math.max(u, c.height - C - u)), l.style.display = "flex", l.style.left = `${Math.round(b)}px`, l.style.top = `${Math.round(_)}px`;
1413
- }
1414
- }
1415
- o && l.style.display !== "none" && (l.style.display = "none");
1416
- }
1417
- const e = ee.current;
1418
- if (e) {
1419
- e.clear();
1420
- const t = Wt.current;
1421
- t && (e.circle(t.wx, t.wy, 10).fill({
1422
- color: 3900150,
1423
- alpha: 0.12
1424
- }).stroke({
1425
- color: 3900150,
1426
- width: 1.5,
1427
- alpha: 0.5
1428
- }), e.circle(t.wx, t.wy, 4).fill({
1429
- color: 3900150,
1430
- alpha: 0.9
1431
- }));
1432
- const o = Yt.current;
1433
- o && !t && (e.circle(o.worldX, o.worldY, 10).fill({
1434
- color: 16347926,
1435
- alpha: 0.12
1436
- }).stroke({
1437
- color: 16347926,
1438
- width: 1.5,
1439
- alpha: 0.5
1440
- }), e.circle(o.worldX, o.worldY, 4).fill({
1441
- color: 16347926,
1442
- alpha: 0.9
1443
- }));
1444
- }
1445
- const I = re.current;
1446
- if (I) {
1447
- I.clear();
1448
- const t = de.current;
1449
- if (t) {
1450
- const o = qe.current, a = Nt.current, i = Qt.current, n = Kt(o.x - t.width / 2, a, i), d = Kt(o.y - t.height / 2, a, i), w = me([{
1451
- id: "__ghost__",
1452
- type: t.type,
1453
- position: {
1454
- x: n,
1455
- y: d
1456
- },
1457
- width: t.width,
1458
- height: t.height,
1459
- data: {}
1460
- }], k.nodes);
1461
- Gt.current = w.guides, I.position.set(n + w.dx, d + w.dy), (an[t.type] ?? an.shapeRect)(I, {
1462
- width: t.width,
1463
- height: t.height,
1464
- fill: "#3b82f6",
1465
- stroke: "#3b82f6",
1466
- strokeWidth: 1.5,
1467
- borderStyle: t.data.borderStyle
1468
- });
1469
- } else
1470
- I.position.set(0, 0), !it.current?.active && !xt.current?.active && (Gt.current = []);
1471
- }
1472
- const y = ne.current;
1473
- if (y && (y.clear(), R.edgeIds.size > 0 && se.current === "select")) {
1474
- const t = 1 / p.zoom;
1475
- for (const o of k.edges) {
1476
- if (!R.edgeIds.has(o.id)) continue;
1477
- const a = St(o, h);
1478
- a && (y.circle(a.sx, a.sy, 5 * t).fill({ color: 16777215 }).stroke({
1479
- color: 16347926,
1480
- width: 1.5 * t
1481
- }), y.circle(a.tx, a.ty, 5 * t).fill({ color: 16777215 }).stroke({
1482
- color: 16347926,
1483
- width: 1.5 * t
1484
- }));
1485
- const i = o.data.waypoints;
1486
- if (i) for (const n of i) y.circle(n.x, n.y, 5 * t).fill({ color: 16777215 }).stroke({
1487
- color: 3900150,
1488
- width: 1.5 * t
1489
- });
1490
- if (o.type === "simplebezier") {
1491
- const n = St(o, h);
1492
- if (!n) continue;
1493
- const d = i ?? [], w = [
1494
- {
1495
- x: n.sx,
1496
- y: n.sy
1497
- },
1498
- ...d,
1499
- {
1500
- x: n.tx,
1501
- y: n.ty
1502
- }
1503
- ], g = o.data.bezierControls, z = w.length - 2;
1504
- for (let C = 0; C <= z; C++) {
1505
- const u = w[C], b = w[C + 1], _ = g?.[C], J = Math.hypot(b.x - u.x, b.y - u.y), Ot = Math.max(30, J * 0.3), Ft = _?.c1x ?? (C === 0 ? u.x + n.snx * Ot : u.x + (b.x - u.x) * 0.4), on = _?.c1y ?? (C === 0 ? u.y + n.sny * Ot : u.y), sn = _?.c2x ?? (C === z ? b.x + n.tnx * Ot : b.x - (b.x - u.x) * 0.4), cn = _?.c2y ?? (C === z ? b.y + n.tny * Ot : b.y);
1506
- y.moveTo(u.x, u.y).lineTo(Ft, on).stroke({
1507
- color: 10265519,
1508
- width: 1 * t
1509
- }), y.moveTo(b.x, b.y).lineTo(sn, cn).stroke({
1510
- color: 10265519,
1511
- width: 1 * t
1512
- });
1513
- const dn = 4 * t;
1514
- y.circle(Ft, on, dn).fill({ color: 16777215 }).stroke({
1515
- color: 3900150,
1516
- width: 1.5 * t
1517
- }), y.circle(sn, cn, dn).fill({ color: 16777215 }).stroke({
1518
- color: 3900150,
1519
- width: 1.5 * t
1520
- });
1521
- }
1522
- }
1523
- }
1524
- }
1525
- const v = te.current;
1526
- if (v && (v.clear(), R.nodeIds.size === 1 && se.current === "select")) {
1527
- const t = [...R.nodeIds][0], o = k.nodes.find((a) => a.id === t);
1528
- if (o) {
1529
- const a = p.zoom, i = o.position.x * a + p.x, n = o.position.y * a + p.y, d = o.width * a, w = o.height * a;
1530
- v.rect(i, n, d, w).stroke({
1531
- color: 3900150,
1532
- width: 1.5
1533
- });
1534
- const g = 7, z = g / 2, C = [
1535
- [i, n],
1536
- [i + d, n],
1537
- [i + d, n + w],
1538
- [i, n + w]
1539
- ];
1540
- for (const [_, J] of C) v.rect(_ - z, J - z, g, g).fill({ color: 16777215 }).stroke({
1541
- color: 3900150,
1542
- width: 1.5
1543
- });
1544
- const u = 4, b = [
1545
- [i + d / 2, n],
1546
- [i + d, n + w / 2],
1547
- [i + d / 2, n + w],
1548
- [i, n + w / 2]
1549
- ];
1550
- for (const [_, J] of b) v.circle(_, J, u).fill({
1551
- color: 3900150,
1552
- alpha: 0.9
1553
- });
1554
- if (!Jt.current) {
1555
- const _ = i + d / 2, J = n - vn;
1556
- v.moveTo(_, n).lineTo(_, J).stroke({
1557
- color: 3900150,
1558
- width: 1.5,
1559
- alpha: 0.85
1560
- }), v.circle(_, J, 6).fill({ color: 16777215 }).stroke({
1561
- color: 3900150,
1562
- width: 1.5
1563
- }), v.circle(_, J, 2.5).fill({ color: 3900150 });
1564
- }
1565
- }
1566
- }
1567
- });
1568
- };
1569
- return V(), () => {
1570
- if (G = !0, f && !f.destroyed) try {
1571
- f.app.stage.removeAllListeners();
1572
- } catch {
1573
- }
1574
- const O = M.current;
1575
- F && O?.removeEventListener("touchstart", F), Y && O?.removeEventListener("touchmove", Y), K && (O?.removeEventListener("touchend", K), O?.removeEventListener("touchcancel", K)), H.current?.destroy(), kt.current?.destroy(), ye.current?.destroy(), pe.current?.destroy(), xe.current?.destroy(), Me.current?.destroy(), Re.current?.destroy(), wt.current?.destroy(), te.current && (te.current.destroy(), te.current = null), ee.current && (ee.current.destroy(), ee.current = null), ne.current && (ne.current.destroy(), ne.current = null), re.current && (re.current.destroy(), re.current = null), ge.current?.destroy();
1576
- };
1577
- }, [D.current]), Rt(() => {
1578
- const f = Me.current, G = Re.current;
1579
- if (!(!f || !G))
1580
- switch (f.deactivate(), G.deactivate(), $) {
1581
- case "freehand":
1582
- f.activate();
1583
- break;
1584
- case "line":
1585
- G.activate("straight");
1586
- break;
1587
- case "polyline":
1588
- G.activate("polyline");
1589
- break;
1590
- case "arrow":
1591
- G.activate("arrow");
1592
- break;
1593
- }
1594
- }, [$]), Rt(() => {
1595
- H.current && (H.current.visible = j, H.current.gridSize = et);
1596
- }, [j, et]), Rt(() => {
1597
- const f = M.current;
1598
- if (!f) return;
1599
- const G = 1e-3, F = (Y) => {
1600
- Y.preventDefault();
1601
- const K = B.current;
1602
- if (!K) return;
1603
- const V = f.getBoundingClientRect(), O = Y.clientX - V.left, at = Y.clientY - V.top, vt = Y.ctrlKey ? 3 : 1, It = -Y.deltaY * G * vt;
1604
- K.zoomAt(O, at, 1 + It);
1605
- };
1606
- return f.addEventListener("wheel", F, { passive: !1 }), () => f.removeEventListener("wheel", F);
1607
- }, [B]), /* @__PURE__ */ ve("div", {
1608
- style: {
1609
- position: "relative",
1610
- width: "100%",
1611
- height: "100%"
1612
- },
1613
- children: [
1614
- /* @__PURE__ */ Zt("div", {
1615
- ref: M,
1616
- className: "flow-canvas-wrapper",
1617
- tabIndex: -1,
1618
- onContextMenu: (f) => f.preventDefault()
1619
- }),
1620
- ht && Ne && /* @__PURE__ */ Zt("input", {
1621
- className: "flow-label-editor",
1622
- autoFocus: !0,
1623
- defaultValue: ht.value,
1624
- style: {
1625
- left: Ne.x,
1626
- top: Ne.y
1627
- },
1628
- onFocus: (f) => f.currentTarget.select(),
1629
- onKeyDown: (f) => {
1630
- f.key === "Enter" ? (f.preventDefault(), Je(f.target.value)) : f.key === "Escape" && (f.preventDefault(), bn()), f.stopPropagation();
1631
- },
1632
- onBlur: (f) => Je(f.target.value),
1633
- onPointerDown: (f) => f.stopPropagation()
1634
- }),
1635
- Ut && !Et && /* @__PURE__ */ ve("button", {
1636
- type: "button",
1637
- className: "flow-esc-button",
1638
- onClick: () => Lt(null),
1639
- title: "取消连续放置 (Esc)",
1640
- children: [/* @__PURE__ */ Zt("span", {
1641
- "aria-hidden": !0,
1642
- children: "⎋"
1643
- }), " 取消放置 (ESC)"]
1644
- }),
1645
- /* @__PURE__ */ ve("button", {
1646
- ref: Fe,
1647
- type: "button",
1648
- className: "flow-delete-button",
1649
- style: { display: "none" },
1650
- onClick: () => Oe.current(),
1651
- title: "删除所选 (Delete)",
1652
- "aria-label": "删除所选",
1653
- children: [/* @__PURE__ */ ve("svg", {
1654
- width: "12",
1655
- height: "12",
1656
- viewBox: "0 0 24 24",
1657
- fill: "none",
1658
- stroke: "currentColor",
1659
- strokeWidth: "2.5",
1660
- strokeLinecap: "round",
1661
- strokeLinejoin: "round",
1662
- "aria-hidden": !0,
1663
- children: [
1664
- /* @__PURE__ */ Zt("path", { d: "M3 6h18" }),
1665
- /* @__PURE__ */ Zt("path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" }),
1666
- /* @__PURE__ */ Zt("path", { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" })
1667
- ]
1668
- }), "删除"]
1669
- })
1670
- ]
1671
- });
189
+ function D({ onPixiReady: u }) {
190
+ let T = x(null), D = x(null), Se = x(13751771), Ce = y((e) => {
191
+ Se.current = e.gridDot, D.current && (D.current.dotColor = e.gridDot);
192
+ }, []), { pixiRef: O, readyRef: we } = n(T, Ce), { setViewportInternal: Te, viewportReqRef: Ee, viewport: k, autoFocus: De, showGrid: Oe, showAnchors: A, gridSize: ke, toolMode: j, edgeType: Ae, focusOnRect: je, setFocusOnRect: Me, pendingPlacement: Ne, setPendingPlacement: Pe, setContextMenu: Fe, beginNodeDrag: Ie, endNodeDrag: Le, presentation: Re, editingNodeId: ze, setEditingNodeId: Be, readOnly: Ve, placementSnap: He } = t(), { currentCanvas: Ue, selection: We, setSelection: M, setDoc: N, currentCanvasId: Ge, pushCanvas: Ke, doc: qe } = e(), Je = se(), Ye = x(Je);
193
+ Ye.current = Je;
194
+ let Xe = x(null), Ze = x(Ve);
195
+ Ze.current = Ve;
196
+ let Qe = x(He);
197
+ Qe.current = He;
198
+ let P = x(ke);
199
+ P.current = ke;
200
+ let F = x(null), $e = x(null), et = x(null), tt = x(null), nt = x(null), rt = x(null), I = x(null), it = x(null), at = x(null), ot = x(null), L = x([]), st = x(null), ct = x(null), R = x(null), lt = x(null), ut = x({
201
+ time: 0,
202
+ wx: 0,
203
+ wy: 0
204
+ }), dt = x({
205
+ time: 0,
206
+ wx: 0,
207
+ wy: 0
208
+ }), ft = x(0), pt = x(null), mt = x({
209
+ x: 0,
210
+ y: 0
211
+ }), ht = A || Re ? Ue : {
212
+ ...Ue,
213
+ nodes: Ue.nodes.filter((e) => e.type !== "animAnchor")
214
+ }, z = x(ht);
215
+ z.current = ht;
216
+ let B = x(Ge);
217
+ B.current = Ge;
218
+ let gt = x(We);
219
+ gt.current = We;
220
+ let _t = x(qe);
221
+ _t.current = qe;
222
+ let vt = x(j);
223
+ vt.current = j;
224
+ let yt = x(De);
225
+ yt.current = De;
226
+ let bt = x(je);
227
+ bt.current = je;
228
+ let xt = x(Ae);
229
+ xt.current = Ae;
230
+ let St = x(A);
231
+ St.current = A;
232
+ let V = x(Re);
233
+ V.current = Re;
234
+ let Ct = x(Ne);
235
+ Ct.current = Ne;
236
+ let wt = x(Ie);
237
+ wt.current = Ie;
238
+ let H = x(Le);
239
+ H.current = Le;
240
+ let U = x(null), W = x(null), G = x(null), K = x(null), q = x(null), J = x(null), Y = x(null), X = x(null), Tt = x(k), Et = x(0), Dt = y((e) => {
241
+ Tt.current = e, Et.current ||= requestAnimationFrame(() => {
242
+ Et.current = 0, Te(Tt.current);
243
+ });
244
+ }, [Te]), { vmRef: Z, screenToWorld: Ot } = r(O, Dt), Q = x(Ot);
245
+ Q.current = Ot;
246
+ let [$, kt] = S(null), [At, jt] = S(null), Mt = x($);
247
+ Mt.current = $;
248
+ let Nt = x(() => {});
249
+ Nt.current = (e, t, n) => {
250
+ Be(e === "node" ? t : null), kt({
251
+ kind: e,
252
+ id: t,
253
+ value: n
254
+ });
255
+ };
256
+ let Pt = y((e) => {
257
+ let t = Mt.current;
258
+ t && (N((n) => {
259
+ let r = B.current, i = n.canvases[r];
260
+ if (!i) return n;
261
+ let a = i;
262
+ if (t.kind === "node") a = {
263
+ ...i,
264
+ nodes: i.nodes.map((n) => n.id === t.id ? {
265
+ ...n,
266
+ data: {
267
+ ...n.data,
268
+ label: e
269
+ }
270
+ } : n)
271
+ };
272
+ else if (t.kind === "edge") a = {
273
+ ...i,
274
+ edges: i.edges.map((n) => n.id === t.id ? {
275
+ ...n,
276
+ data: {
277
+ ...n.data,
278
+ labelText: e
279
+ }
280
+ } : n)
281
+ };
282
+ else return n;
283
+ return {
284
+ ...n,
285
+ canvases: {
286
+ ...n.canvases,
287
+ [r]: a
288
+ }
289
+ };
290
+ }), kt(null), Be(null), jt(null));
291
+ }, [N, Be]), Ft = y(() => {
292
+ kt(null), Be(null), jt(null);
293
+ }, [Be]);
294
+ b(() => {
295
+ if (!ze || Mt.current?.id === ze) return;
296
+ let e = z.current.nodes.find((e) => e.id === ze);
297
+ e && Nt.current("node", e.id, e.data.label);
298
+ }, [ze]), b(() => {
299
+ if (!$) return;
300
+ let e = Z.current;
301
+ if (!e) return;
302
+ let t = z.current, n = null;
303
+ if ($.kind === "node") {
304
+ let e = t.nodes.find((e) => e.id === $.id);
305
+ e && (n = {
306
+ x: e.position.x + e.width / 2,
307
+ y: e.position.y + e.height / 2
308
+ });
309
+ } else if ($.kind === "edge") {
310
+ let e = t.edges.find((e) => e.id === $.id), r = /* @__PURE__ */ new Map();
311
+ for (let e of t.nodes) r.set(e.id, e);
312
+ if (e) {
313
+ let t = _(e, r);
314
+ if (t) {
315
+ let r = h(e.type, t, e.data.waypoints, e.data.bezierControls), i = g(r), a = i[Math.floor(i.length / 2)] ?? {
316
+ x: (t.sx + t.tx) / 2,
317
+ y: (t.sy + t.ty) / 2
318
+ };
319
+ n = {
320
+ x: a.x,
321
+ y: a.y
322
+ };
323
+ }
324
+ }
325
+ }
326
+ if (n) {
327
+ let t = e.worldToScreen(n.x, n.y);
328
+ jt({
329
+ x: t.x,
330
+ y: t.y
331
+ });
332
+ }
333
+ }, [$, Z]);
334
+ let It = x(0);
335
+ b(() => {
336
+ Ee.current !== It.current && (It.current = Ee.current, Tt.current = k, Z.current?.setState(k));
337
+ }, [
338
+ k,
339
+ Z,
340
+ Ee
341
+ ]), b(() => {
342
+ Me((e, t, n, r, i) => {
343
+ let a = Z.current, o = T.current;
344
+ if (!a || !o) return;
345
+ let s = o.clientWidth || 800, c = o.clientHeight || 600, l = Math.max(0, i?.padding ?? 60), u = Math.max(1, s - l * 2), d = Math.max(1, c - l * 2), f = i?.preserveZoom ? a.state.zoom : Math.min(u / Math.max(n, 1), d / Math.max(r, 1), i?.maxZoom ?? 2), p = e + n / 2, m = t + r / 2, h = s / 2 - p * f, g = c / 2 - m * f;
346
+ a.animateTo({
347
+ x: h,
348
+ y: g,
349
+ zoom: f
350
+ }, i?.duration ?? 350);
351
+ });
352
+ }, [Me, Z]);
353
+ let Lt = y((e) => {
354
+ N((t) => {
355
+ let n = t.canvases[B.current];
356
+ return n ? {
357
+ ...t,
358
+ canvases: {
359
+ ...t.canvases,
360
+ [B.current]: {
361
+ ...n,
362
+ lines: [...n.lines, e]
363
+ }
364
+ }
365
+ } : t;
366
+ });
367
+ }, [N, Ge]), Rt = x(Lt);
368
+ return Rt.current = Lt, b(() => {
369
+ let e = O.current;
370
+ if (!e || e.destroyed) return;
371
+ let t = !1, n = null, r = null, h = null, g = () => {
372
+ if (t) return;
373
+ if (!we.current) {
374
+ setTimeout(g, 30);
375
+ return;
376
+ }
377
+ D.current = new i(e.app.stage, ke, Oe), D.current.dotColor = Se.current, F.current = new a(e.app.stage), $e.current = new m(e.world), et.current = new v(e.world), tt.current = new ee(e.world);
378
+ let se = new ce();
379
+ se.label = "connect-line", se.visible = !1, e.world.addChild(se), J.current = se;
380
+ let y = new ce();
381
+ y.label = "transform-handles", e.app.stage.addChild(y), it.current = y;
382
+ let b = new ce();
383
+ b.label = "handle-hover", e.world.addChild(b), at.current = b;
384
+ let x = new ce();
385
+ x.label = "edge-edit-handles", e.world.addChild(x), lt.current = x;
386
+ let S = new ce();
387
+ S.label = "ghost-placement", S.alpha = .5, e.world.addChild(S), pt.current = S, ot.current = new ie(e.world), nt.current = new te(e.app.stage, e.world, {
388
+ onLineComplete: (e) => Rt.current(e),
389
+ screenToWorld: (e, t) => Q.current(e, t)
390
+ }), rt.current = new ne(e.app.stage, e.world, {
391
+ onLineComplete: (e) => Rt.current(e),
392
+ screenToWorld: (e, t) => Q.current(e, t)
393
+ }), u?.(e);
394
+ let C = e.app.stage;
395
+ C.on("pointerdown", (e) => {
396
+ if (T.current?.focus({ preventScroll: !0 }), Z.current?.multiTouchActive || Z.current?.isPanning || Z.current?.isSpaceHeld || e.button !== 0) return;
397
+ let t = vt.current;
398
+ if (t === "pan") {
399
+ Z.current?.startPan(e.global.x, e.global.y);
400
+ return;
401
+ }
402
+ if (t === "freehand" || t === "line" || t === "polyline" || t === "arrow") return;
403
+ let n = Q.current(e.global.x, e.global.y), r = z.current.nodes, i = z.current.edges, a = z.current.lines, o = gt.current, u = e.metaKey || e.ctrlKey || e.shiftKey, d = Z.current?.state.zoom ?? 1;
404
+ if (Ct.current) return;
405
+ let p = Date.now(), m = ut.current, h = p - m.time < 350 && Math.hypot(n.x - m.wx, n.y - m.wy) < 8 / d;
406
+ if (ut.current = {
407
+ time: p,
408
+ wx: n.x,
409
+ wy: n.y
410
+ }, o.nodeIds.size === 1 && !u && t === "select" && !Ze.current) {
411
+ let e = r.find((e) => e.id === [...o.nodeIds][0]);
412
+ if (e) {
413
+ let t = fe(e, d);
414
+ if (Math.hypot(n.x - t.x, n.y - t.y) < E(d, 12, 24)) {
415
+ K.current = {
416
+ active: !0,
417
+ nodeId: e.id,
418
+ cx: e.position.x + e.width / 2,
419
+ cy: e.position.y + e.height / 2,
420
+ startPointerAngle: Math.atan2(n.y - (e.position.y + e.height / 2), n.x - (e.position.x + e.width / 2)),
421
+ startRotation: e.data.rotation ?? 0
422
+ }, wt.current();
423
+ return;
424
+ }
425
+ }
426
+ }
427
+ if (o.nodeIds.size === 1 && !u && t === "select") {
428
+ let e = r.find((e) => e.id === [...o.nodeIds][0]);
429
+ if (e) {
430
+ let t = me(n, e, E(d, 10, 16));
431
+ if (t) {
432
+ let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = e.type === "geometryGroup", s = o || e.type === "flowGroup" || e.data.isGroup, c = e.position.x, l = e.position.y, u = e.width, d = e.height;
433
+ for (let t of r) t.id !== e.id && (t.parentId === e.id || o && t.position.x >= c && t.position.y >= l && t.position.x + t.width <= c + u && t.position.y + t.height <= l + d) && i.set(t.id, {
434
+ x: t.position.x,
435
+ y: t.position.y,
436
+ w: t.width,
437
+ h: t.height
438
+ });
439
+ if (s) for (let t of z.current.lines) (t.parentId === e.id || o && t.points.length > 0 && t.points.every((e) => e.x >= c && e.x <= c + u && e.y >= l && e.y <= l + d)) && a.set(t.id, t.points.map((e) => ({ ...e })));
440
+ Y.current = {
441
+ active: !0,
442
+ nodeId: e.id,
443
+ handle: t,
444
+ startWorld: n,
445
+ startBounds: {
446
+ x: e.position.x,
447
+ y: e.position.y,
448
+ w: e.width,
449
+ h: e.height
450
+ },
451
+ childStarts: i,
452
+ childLineStarts: a.size > 0 ? a : void 0
453
+ };
454
+ return;
455
+ }
456
+ }
457
+ }
458
+ let g = null;
459
+ for (let e = r.length - 1; e >= 0; e--) if (f(n.x, n.y, r[e])) {
460
+ g = r[e];
461
+ break;
462
+ }
463
+ if (g?.parentId) {
464
+ let e = r.find((e) => e.id === g.parentId);
465
+ e && (g = e);
466
+ }
467
+ ue && (I.current = g ? g.parentId ? r.find((e) => e.id === g.parentId)?.id ?? g.id : g.id : null, st.current = null, ct.current = null);
468
+ let _ = !1;
469
+ if (g && t === "select" && (_ = Math.min(n.x - g.position.x, g.position.x + g.width - n.x, n.y - g.position.y, g.position.y + g.height - n.y) > Math.min(14, Math.min(g.width, g.height) * .3)), (t === "select" || t === "connect") && (g || ue) && !_) {
470
+ let e = g ? [g] : r, t = E(d, 14, 20), i = null, a = null, o = Infinity;
471
+ for (let r of e) {
472
+ let e = c(r.width, r.height), u = s(e, r, n.x, n.y, t);
473
+ if (!u) continue;
474
+ let d = l(u, r), f = Math.hypot(n.x - d.x, n.y - d.y);
475
+ f < o && (o = f, i = r, a = u);
476
+ }
477
+ if (i && a) {
478
+ G.current = {
479
+ active: !0,
480
+ sourceNodeId: i.id,
481
+ sourceHandleId: a.id
482
+ };
483
+ return;
484
+ }
485
+ }
486
+ if ((t === "select" || t === "connect") && !u && o.edgeIds.size > 0) {
487
+ let e = /* @__PURE__ */ new Map();
488
+ for (let t of r) e.set(t.id, t);
489
+ let t = i.filter((e) => o.edgeIds.has(e.id)), a = he(n.x, n.y, t, e, E(d, 14, 20));
490
+ if (a) {
491
+ let e = i.find((e) => e.id === a.edgeId);
492
+ if (e) {
493
+ let t = a.end === "source" ? "target" : "source";
494
+ q.current = {
495
+ active: !0,
496
+ edgeId: e.id,
497
+ movingEnd: a.end,
498
+ fixedNodeId: t === "source" ? e.source : e.target,
499
+ fixedHandleId: t === "source" ? e.sourceHandle : e.targetHandle
500
+ };
501
+ return;
502
+ }
503
+ }
504
+ }
505
+ if (t === "select" && o.edgeIds.size > 0 && !g) {
506
+ let e = /* @__PURE__ */ new Map();
507
+ for (let t of r) e.set(t.id, t);
508
+ let t = i.filter((e) => o.edgeIds.has(e.id)), a = E(d, 10, 14), s = _e(n.x, n.y, t, e, a);
509
+ if (s) {
510
+ R.current = {
511
+ active: !0,
512
+ edgeId: s.edgeId,
513
+ type: s.controlEnd === "c1" ? "bezierC1" : "bezierC2",
514
+ index: s.segmentIndex
515
+ };
516
+ return;
517
+ }
518
+ let c = ge(n.x, n.y, t, a);
519
+ if (c) {
520
+ if (h) {
521
+ N((e) => {
522
+ let t = e.canvases[B.current];
523
+ return t ? {
524
+ ...e,
525
+ canvases: {
526
+ ...e.canvases,
527
+ [B.current]: {
528
+ ...t,
529
+ edges: t.edges.map((e) => {
530
+ if (e.id !== c.edgeId) return e;
531
+ let t = [...e.data.waypoints ?? []];
532
+ t.splice(c.waypointIndex, 1);
533
+ let n = {
534
+ ...e.data,
535
+ waypoints: t.length > 0 ? t : void 0
536
+ };
537
+ if (e.type === "simplebezier" && e.data.bezierControls) {
538
+ let t = [...e.data.bezierControls];
539
+ t.splice(c.waypointIndex, 2, null), n.bezierControls = t.some((e) => e !== null) ? t : void 0;
540
+ }
541
+ return {
542
+ ...e,
543
+ data: n
544
+ };
545
+ })
546
+ }
547
+ }
548
+ } : e;
549
+ });
550
+ return;
551
+ }
552
+ R.current = {
553
+ active: !0,
554
+ edgeId: c.edgeId,
555
+ type: "waypoint",
556
+ index: c.waypointIndex
557
+ };
558
+ return;
559
+ }
560
+ if (h) {
561
+ for (let r of t) if (be(n.x, n.y, r, e, E(d, 8, 12))) {
562
+ let t = ve(n.x, n.y, r, e), i = {
563
+ x: n.x,
564
+ y: n.y
565
+ };
566
+ N((e) => {
567
+ let n = e.canvases[B.current];
568
+ return n ? {
569
+ ...e,
570
+ canvases: {
571
+ ...e.canvases,
572
+ [B.current]: {
573
+ ...n,
574
+ edges: n.edges.map((e) => {
575
+ if (e.id !== r.id) return e;
576
+ let n = [...e.data.waypoints ?? []];
577
+ n.splice(t, 0, i);
578
+ let a = {
579
+ ...e.data,
580
+ waypoints: n
581
+ };
582
+ if (e.type === "simplebezier" && e.data.bezierControls) {
583
+ let n = [...e.data.bezierControls];
584
+ for (; n.length < (e.data.waypoints ?? []).length + 1;) n.push(null);
585
+ n.splice(t, 1, null, null), a.bezierControls = n;
586
+ }
587
+ return {
588
+ ...e,
589
+ data: a
590
+ };
591
+ })
592
+ }
593
+ }
594
+ } : e;
595
+ }), R.current = {
596
+ active: !0,
597
+ edgeId: r.id,
598
+ type: "waypoint",
599
+ index: t
600
+ };
601
+ return;
602
+ }
603
+ }
604
+ }
605
+ if (g && (t === "select" || t === "connect")) {
606
+ !u && !o.nodeIds.has(g.id) ? M({
607
+ nodeIds: /* @__PURE__ */ new Set([g.id]),
608
+ edgeIds: /* @__PURE__ */ new Set(),
609
+ lineIds: /* @__PURE__ */ new Set()
610
+ }) : u && M((e) => {
611
+ let t = new Set(e.nodeIds);
612
+ return t.has(g.id) ? t.delete(g.id) : t.add(g.id), {
613
+ nodeIds: t,
614
+ edgeIds: /* @__PURE__ */ new Set(),
615
+ lineIds: /* @__PURE__ */ new Set()
616
+ };
617
+ }), yt.current && bt.current(g.position.x, g.position.y, g.width, g.height, {
618
+ padding: 80,
619
+ preserveZoom: !0,
620
+ duration: 280
621
+ });
622
+ let e = o.nodeIds.has(g.id) ? new Set(o.nodeIds) : /* @__PURE__ */ new Set([g.id]);
623
+ u && !o.nodeIds.has(g.id) && e.add(g.id);
624
+ let t = /* @__PURE__ */ new Set();
625
+ for (let n of e) {
626
+ let i = r.find((e) => e.id === n);
627
+ if (!i || i.type !== "flowGroup" && i.type !== "geometryGroup" && !i.data.isGroup) continue;
628
+ let a = i.type === "geometryGroup", o = i.position.x, s = i.position.y, c = i.width, l = i.height;
629
+ for (let t of r) if (!(e.has(t.id) || t.id === n)) {
630
+ if (t.parentId === n) {
631
+ e.add(t.id);
632
+ continue;
633
+ }
634
+ a && t.position.x >= o && t.position.y >= s && t.position.x + t.width <= o + c && t.position.y + t.height <= s + l && e.add(t.id);
635
+ }
636
+ for (let e of z.current.lines) e.parentId === n && t.add(e.id);
637
+ if (a) for (let e of z.current.lines) t.has(e.id) || e.points.length > 0 && e.points.every((e) => e.x >= o && e.x <= o + c && e.y >= s && e.y <= s + l) && t.add(e.id);
638
+ }
639
+ let i = /* @__PURE__ */ new Map();
640
+ for (let t of r) e.has(t.id) && i.set(t.id, { ...t.position });
641
+ let a = /* @__PURE__ */ new Map();
642
+ if (t.size > 0) for (let e of z.current.lines) t.has(e.id) && a.set(e.id, e.points.map((e) => ({ ...e })));
643
+ U.current = {
644
+ active: !0,
645
+ nodeIds: e,
646
+ lineIds: t.size > 0 ? t : void 0,
647
+ startWorld: n,
648
+ nodeStarts: i,
649
+ linePointStarts: a.size > 0 ? a : void 0
650
+ }, wt.current();
651
+ return;
652
+ }
653
+ let v = /* @__PURE__ */ new Map();
654
+ for (let e of r) v.set(e.id, e);
655
+ let ee = E(d, 8, 12);
656
+ for (let e of i) if (be(n.x, n.y, e, v, ee)) {
657
+ if (M(u ? (t) => {
658
+ let n = new Set(t.edgeIds);
659
+ return n.has(e.id) ? n.delete(e.id) : n.add(e.id), {
660
+ ...t,
661
+ edgeIds: n
662
+ };
663
+ } : {
664
+ nodeIds: /* @__PURE__ */ new Set(),
665
+ edgeIds: /* @__PURE__ */ new Set([e.id]),
666
+ lineIds: /* @__PURE__ */ new Set()
667
+ }), yt.current) {
668
+ let t = v.get(e.source), n = v.get(e.target);
669
+ if (t && n) {
670
+ let e = Math.min(t.position.x, n.position.x), r = Math.min(t.position.y, n.position.y), i = Math.max(t.position.x + t.width, n.position.x + n.width), a = Math.max(t.position.y + t.height, n.position.y + n.height);
671
+ bt.current(e, r, i - e, a - r, {
672
+ padding: 80,
673
+ preserveZoom: !0,
674
+ duration: 280
675
+ });
676
+ }
677
+ }
678
+ return;
679
+ }
680
+ for (let e of a) if (xe(n.x, n.y, e, ee)) {
681
+ let t = o.lineIds.has(e.id);
682
+ if (u ? M((t) => {
683
+ let n = new Set(t.lineIds);
684
+ return n.has(e.id) ? n.delete(e.id) : n.add(e.id), {
685
+ ...t,
686
+ lineIds: n
687
+ };
688
+ }) : t || M({
689
+ nodeIds: /* @__PURE__ */ new Set(),
690
+ edgeIds: /* @__PURE__ */ new Set(),
691
+ lineIds: /* @__PURE__ */ new Set([e.id])
692
+ }), yt.current && e.points.length > 0) {
693
+ let t = e.points.map((e) => e.x), n = e.points.map((e) => e.y), r = Math.min(...t), i = Math.min(...n), a = Math.max(...t), o = Math.max(...n);
694
+ bt.current(r, i, Math.max(1, a - r), Math.max(1, o - i), {
695
+ padding: 80,
696
+ preserveZoom: !0,
697
+ duration: 280
698
+ });
699
+ }
700
+ let r = t ? new Set(o.lineIds) : /* @__PURE__ */ new Set([e.id]), i = /* @__PURE__ */ new Map();
701
+ for (let e of a) r.has(e.id) && i.set(e.id, e.points.map((e) => ({ ...e })));
702
+ X.current = {
703
+ active: !0,
704
+ lineIds: r,
705
+ startWorld: n,
706
+ pointStarts: i
707
+ };
708
+ return;
709
+ }
710
+ u || M({
711
+ nodeIds: /* @__PURE__ */ new Set(),
712
+ edgeIds: /* @__PURE__ */ new Set(),
713
+ lineIds: /* @__PURE__ */ new Set()
714
+ }), t === "select" && (W.current = {
715
+ active: !0,
716
+ startScreen: {
717
+ x: e.global.x,
718
+ y: e.global.y
719
+ }
720
+ });
721
+ }), C.on("globalpointermove", (e) => {
722
+ let t = Q.current(e.global.x, e.global.y);
723
+ if (mt.current = t, Z.current?.multiTouchActive) return;
724
+ let n = vt.current;
725
+ if (n === "freehand" || n === "line" || n === "polyline" || n === "arrow") return;
726
+ let r = z.current.nodes, i = z.current.edges, a = Z.current?.state.zoom ?? 1, o = !U.current?.active && !G.current?.active && !Y.current?.active && !q.current?.active && !R.current?.active && !X.current?.active && !K.current?.active, u = null;
727
+ for (let e = r.length - 1; e >= 0; e--) if (f(t.x, t.y, r[e])) {
728
+ let t = r[e];
729
+ u = t.parentId ? r.find((e) => e.id === t.parentId)?.id ?? t.id : t.id;
730
+ break;
731
+ }
732
+ if (I.current = u, o && (n === "select" || n === "connect")) {
733
+ let e = /* @__PURE__ */ new Map();
734
+ for (let t of r) e.set(t.id, t);
735
+ let n = gt.current, o = n.edgeIds.size > 0 ? i.filter((e) => n.edgeIds.has(e.id)) : [], d = o.length > 0 ? he(t.x, t.y, o, e, E(a, 12, 18)) : null;
736
+ ct.current = d;
737
+ let f = null;
738
+ if (u) {
739
+ let e = r.find((e) => e.id === u);
740
+ if (e) {
741
+ let n = c(e.width, e.height), r = s(n, e, t.x, t.y, E(a, 14, 20));
742
+ if (r) {
743
+ let t = l(r, e);
744
+ f = {
745
+ nodeId: e.id,
746
+ handleId: r.id,
747
+ wx: t.x,
748
+ wy: t.y
749
+ };
750
+ }
751
+ }
752
+ }
753
+ st.current = f;
754
+ }
755
+ let d = T.current;
756
+ if (d && o) {
757
+ let e = gt.current, o = "";
758
+ if (ct.current) o = "crosshair";
759
+ else if (st.current) o = "crosshair";
760
+ else if (e.edgeIds.size > 0 && n === "select") {
761
+ let n = i.filter((t) => e.edgeIds.has(t.id)), s = /* @__PURE__ */ new Map();
762
+ for (let e of r) s.set(e.id, e);
763
+ let c = E(a, 10, 14);
764
+ (ge(t.x, t.y, n, c) || _e(t.x, t.y, n, s, c)) && (o = "grab");
765
+ }
766
+ if (!o && e.nodeIds.size === 1 && n === "select") {
767
+ let n = r.find((t) => t.id === [...e.nodeIds][0]);
768
+ if (n) {
769
+ let e = me(t, n, E(a, 10, 16));
770
+ if (e) o = le[e];
771
+ else if (!Ze.current) {
772
+ let e = fe(n, a);
773
+ Math.hypot(t.x - e.x, t.y - e.y) < E(a, 12, 24) && (o = "grab");
774
+ }
775
+ }
776
+ }
777
+ if (!o && n === "select") {
778
+ let e = z.current.lines, n = E(a, 8, 12);
779
+ for (let r of e) if (xe(t.x, t.y, r, n)) {
780
+ o = "move";
781
+ break;
782
+ }
783
+ }
784
+ d.style.cursor = o;
785
+ }
786
+ if (Y.current?.active) {
787
+ let e = Y.current, n = t.x - e.startWorld.x, r = t.y - e.startWorld.y, i = ye(e.startBounds, e.handle, n, r), a = z.current.nodes, o = {
788
+ id: e.nodeId,
789
+ type: "shapeRect",
790
+ position: {
791
+ x: i.x,
792
+ y: i.y
793
+ },
794
+ width: i.w,
795
+ height: i.h,
796
+ data: {}
797
+ }, s = re([o], a);
798
+ if (i.x += s.dx, i.y += s.dy, (e.handle === "ne" || e.handle === "se") && (i.w += s.dx), (e.handle === "se" || e.handle === "sw") && (i.h += s.dy), L.current = s.guides, Qe.current && P.current > 0 && s.guides.length === 0) {
799
+ let t = P.current;
800
+ (e.handle === "nw" || e.handle === "sw") && (i.x = Math.round(i.x / t) * t), (e.handle === "nw" || e.handle === "ne") && (i.y = Math.round(i.y / t) * t), (e.handle === "ne" || e.handle === "se") && (i.w = Math.round((i.x + i.w) / t) * t - i.x), (e.handle === "se" || e.handle === "sw") && (i.h = Math.round((i.y + i.h) / t) * t - i.y);
801
+ }
802
+ let c = e.startBounds, l = Math.max(i.w, 24), u = Math.max(i.h, 24), d = c.w > 0 ? l / c.w : 1, f = c.h > 0 ? u / c.h : 1;
803
+ N((t) => {
804
+ let n = t.canvases[B.current];
805
+ return n ? {
806
+ ...t,
807
+ canvases: {
808
+ ...t.canvases,
809
+ [B.current]: {
810
+ ...n,
811
+ nodes: n.nodes.map((t) => {
812
+ if (t.id === e.nodeId) return {
813
+ ...t,
814
+ position: {
815
+ x: i.x,
816
+ y: i.y
817
+ },
818
+ width: l,
819
+ height: u
820
+ };
821
+ let n = e.childStarts.get(t.id);
822
+ return n ? {
823
+ ...t,
824
+ position: {
825
+ x: i.x + (n.x - c.x) * d,
826
+ y: i.y + (n.y - c.y) * f
827
+ },
828
+ width: Math.max(n.w * d, 24),
829
+ height: Math.max(n.h * f, 24)
830
+ } : t;
831
+ }),
832
+ lines: e.childLineStarts ? n.lines.map((t) => {
833
+ let n = e.childLineStarts.get(t.id);
834
+ return n ? {
835
+ ...t,
836
+ points: n.map((e) => ({
837
+ x: i.x + (e.x - c.x) * d,
838
+ y: i.y + (e.y - c.y) * f
839
+ }))
840
+ } : t;
841
+ }) : n.lines
842
+ }
843
+ }
844
+ } : t;
845
+ });
846
+ return;
847
+ }
848
+ if (K.current?.active) {
849
+ let n = K.current, r = (Math.atan2(t.y - n.cy, t.x - n.cx) - n.startPointerAngle) * 180 / Math.PI, i = ((n.startRotation + r) % 360 + 360) % 360;
850
+ if (e.shiftKey) i = Math.round(i / 15) * 15 % 360;
851
+ else {
852
+ let e = Math.round(i / 45) * 45;
853
+ Math.abs(i - e) < 4 && (i = (e % 360 + 360) % 360);
854
+ }
855
+ N((e) => {
856
+ let t = e.canvases[B.current];
857
+ return t ? {
858
+ ...e,
859
+ canvases: {
860
+ ...e.canvases,
861
+ [B.current]: {
862
+ ...t,
863
+ nodes: t.nodes.map((e) => e.id === n.nodeId ? {
864
+ ...e,
865
+ data: {
866
+ ...e.data,
867
+ rotation: i
868
+ }
869
+ } : e)
870
+ }
871
+ }
872
+ } : e;
873
+ }), T.current && (T.current.style.cursor = "grabbing");
874
+ return;
875
+ }
876
+ if (R.current?.active) {
877
+ let e = R.current, n = z.current.nodes, r = /* @__PURE__ */ new Map();
878
+ for (let e of n) r.set(e.id, e);
879
+ N((n) => {
880
+ let i = n.canvases[B.current];
881
+ return i ? {
882
+ ...n,
883
+ canvases: {
884
+ ...n.canvases,
885
+ [B.current]: {
886
+ ...i,
887
+ edges: i.edges.map((n) => {
888
+ if (n.id !== e.edgeId) return n;
889
+ if (e.type === "waypoint") {
890
+ let r = [...n.data.waypoints ?? []];
891
+ return e.index < r.length && (r[e.index] = {
892
+ x: t.x,
893
+ y: t.y
894
+ }), {
895
+ ...n,
896
+ data: {
897
+ ...n.data,
898
+ waypoints: r
899
+ }
900
+ };
901
+ }
902
+ let i = _(n, r);
903
+ if (!i) return n;
904
+ let a = n.data.waypoints ?? [], o = [
905
+ {
906
+ x: i.sx,
907
+ y: i.sy
908
+ },
909
+ ...a,
910
+ {
911
+ x: i.tx,
912
+ y: i.ty
913
+ }
914
+ ], s = o.length - 1, c = [...n.data.bezierControls ?? []];
915
+ for (; c.length < s;) c.push(null);
916
+ let l = e.index;
917
+ if (l >= s) return n;
918
+ let u = o[l], d = o[l + 1], f = c[l], p = Math.hypot(d.x - u.x, d.y - u.y), m = Math.max(30, p * .3), h = s - 1, g = l === 0 ? u.x + i.snx * m : u.x + (d.x - u.x) * .4, v = l === 0 ? u.y + i.sny * m : u.y, ee = l === h ? d.x + i.tnx * m : d.x - (d.x - u.x) * .4, te = l === h ? d.y + i.tny * m : d.y;
919
+ return c[l] = e.type === "bezierC1" ? {
920
+ c1x: t.x,
921
+ c1y: t.y,
922
+ c2x: f?.c2x ?? ee,
923
+ c2y: f?.c2y ?? te
924
+ } : {
925
+ c1x: f?.c1x ?? g,
926
+ c1y: f?.c1y ?? v,
927
+ c2x: t.x,
928
+ c2y: t.y
929
+ }, {
930
+ ...n,
931
+ data: {
932
+ ...n.data,
933
+ bezierControls: c
934
+ }
935
+ };
936
+ })
937
+ }
938
+ }
939
+ } : n;
940
+ });
941
+ return;
942
+ }
943
+ if (X.current?.active) {
944
+ let e = X.current, n = t.x - e.startWorld.x, r = t.y - e.startWorld.y;
945
+ N((t) => {
946
+ let i = t.canvases[B.current];
947
+ return i ? {
948
+ ...t,
949
+ canvases: {
950
+ ...t.canvases,
951
+ [B.current]: {
952
+ ...i,
953
+ lines: i.lines.map((t) => {
954
+ let i = e.pointStarts.get(t.id);
955
+ return i ? {
956
+ ...t,
957
+ points: i.map((e) => ({
958
+ x: e.x + n,
959
+ y: e.y + r
960
+ }))
961
+ } : t;
962
+ })
963
+ }
964
+ }
965
+ } : t;
966
+ });
967
+ return;
968
+ }
969
+ if (U.current?.active) {
970
+ let e = U.current, n = t.x - e.startWorld.x, r = t.y - e.startWorld.y, i = n, a = r;
971
+ if (Qe.current && P.current > 0 && e.nodeIds.size > 0) {
972
+ let t = P.current, o = e.nodeStarts.values().next().value;
973
+ o && (i = pe(o.x + n, t, !0) - o.x, a = pe(o.y + r, t, !0) - o.y);
974
+ }
975
+ let o = z.current.nodes, s = o.filter((t) => e.nodeIds.has(t.id)).map((t) => {
976
+ let n = e.nodeStarts.get(t.id);
977
+ return {
978
+ ...t,
979
+ position: {
980
+ x: n.x + i,
981
+ y: n.y + a
982
+ }
983
+ };
984
+ }), c = re(s, o);
985
+ i += c.dx, a += c.dy, L.current = c.guides, N((t) => {
986
+ let n = t.canvases[B.current];
987
+ return n ? {
988
+ ...t,
989
+ canvases: {
990
+ ...t.canvases,
991
+ [B.current]: {
992
+ ...n,
993
+ nodes: n.nodes.map((t) => {
994
+ let n = e.nodeStarts.get(t.id);
995
+ return n ? {
996
+ ...t,
997
+ position: {
998
+ x: n.x + i,
999
+ y: n.y + a
1000
+ }
1001
+ } : t;
1002
+ }),
1003
+ lines: e.linePointStarts ? n.lines.map((t) => {
1004
+ let n = e.linePointStarts.get(t.id);
1005
+ return n ? {
1006
+ ...t,
1007
+ points: n.map((e) => ({
1008
+ x: e.x + i,
1009
+ y: e.y + a
1010
+ }))
1011
+ } : t;
1012
+ }) : n.lines
1013
+ }
1014
+ }
1015
+ } : t;
1016
+ });
1017
+ return;
1018
+ }
1019
+ if (W.current?.active && F.current) {
1020
+ let t = Math.min(W.current.startScreen.x, e.global.x), n = Math.min(W.current.startScreen.y, e.global.y), r = Math.abs(e.global.x - W.current.startScreen.x), i = Math.abs(e.global.y - W.current.startScreen.y);
1021
+ F.current.showMarquee(t, n, r, i);
1022
+ }
1023
+ if (G.current?.active && J.current) {
1024
+ let e = z.current.nodes.find((e) => e.id === G.current.sourceNodeId);
1025
+ if (e) {
1026
+ let n = c(e.width, e.height).find((e) => e.id === G.current.sourceHandleId);
1027
+ if (n) {
1028
+ let r = l(n, e), i = r.x, a = r.y, o = t.x, u = t.y, d = I.current;
1029
+ if (d && d !== G.current.sourceNodeId) {
1030
+ let e = z.current.nodes.find((e) => e.id === d);
1031
+ if (e) {
1032
+ let n = c(e.width, e.height), r = s(n, e, t.x, t.y, Infinity);
1033
+ if (r) {
1034
+ let t = l(r, e);
1035
+ o = t.x, u = t.y;
1036
+ }
1037
+ }
1038
+ }
1039
+ let f = J.current;
1040
+ f.clear(), f.moveTo(i, a).lineTo(o, u).stroke({
1041
+ color: 3900150,
1042
+ width: 2,
1043
+ alpha: .6
1044
+ }), f.visible = !0;
1045
+ }
1046
+ }
1047
+ }
1048
+ if (q.current?.active && J.current && !J.current.destroyed) {
1049
+ let e = q.current, n = z.current.nodes.find((t) => t.id === e.fixedNodeId);
1050
+ if (n) {
1051
+ let r = c(n.width, n.height).find((t) => t.id === e.fixedHandleId), i = r ? l(r, n) : {
1052
+ x: n.position.x + n.width / 2,
1053
+ y: n.position.y + n.height / 2
1054
+ }, a = i.x, o = i.y, u = t.x, d = t.y, f = I.current;
1055
+ if (f && f !== e.fixedNodeId) {
1056
+ let e = z.current.nodes.find((e) => e.id === f);
1057
+ if (e) {
1058
+ let n = c(e.width, e.height), r = s(n, e, t.x, t.y, Infinity);
1059
+ if (r) {
1060
+ let t = l(r, e);
1061
+ u = t.x, d = t.y;
1062
+ }
1063
+ }
1064
+ }
1065
+ let p = J.current;
1066
+ p.clear(), p.moveTo(a, o).lineTo(u, d).stroke({
1067
+ color: 16347926,
1068
+ width: 2,
1069
+ alpha: .7
1070
+ }), p.visible = !0;
1071
+ }
1072
+ }
1073
+ });
1074
+ let w = () => {
1075
+ L.current = [];
1076
+ try {
1077
+ ot.current?.clear();
1078
+ } catch {}
1079
+ try {
1080
+ let e = J.current;
1081
+ e && !e.destroyed && (e.clear(), e.visible = !1);
1082
+ } catch {}
1083
+ T.current && (T.current.style.cursor = "");
1084
+ };
1085
+ C.on("pointerup", (e) => {
1086
+ if (w(), K.current?.active) {
1087
+ K.current = null, H.current();
1088
+ return;
1089
+ }
1090
+ if (R.current?.active) {
1091
+ R.current = null;
1092
+ return;
1093
+ }
1094
+ if (Y.current?.active) {
1095
+ Y.current = null;
1096
+ return;
1097
+ }
1098
+ if (X.current?.active) {
1099
+ X.current = null;
1100
+ return;
1101
+ }
1102
+ if (U.current?.active && (U.current = null, H.current()), W.current?.active) {
1103
+ let t = Q.current(W.current.startScreen.x, W.current.startScreen.y), n = Q.current(e.global.x, e.global.y), r = Math.min(t.x, n.x), i = Math.min(t.y, n.y), a = Math.abs(n.x - t.x), o = Math.abs(n.y - t.y);
1104
+ if (a > 4 && o > 4) {
1105
+ let e = z.current.nodes.filter((e) => p(r, i, a, o, e.position.x, e.position.y, e.width, e.height)), t = z.current.lines.filter((e) => e.points.length !== 0 && e.points.every((e) => e.x >= r && e.x <= r + a && e.y >= i && e.y <= i + o));
1106
+ M({
1107
+ nodeIds: new Set(e.map((e) => e.id)),
1108
+ edgeIds: /* @__PURE__ */ new Set(),
1109
+ lineIds: new Set(t.map((e) => e.id))
1110
+ });
1111
+ }
1112
+ W.current = null, F.current?.hideMarquee();
1113
+ }
1114
+ if (q.current?.active) {
1115
+ let t = q.current.edgeId, n = q.current.movingEnd, r = q.current.fixedNodeId;
1116
+ q.current = null;
1117
+ let i = Q.current(e.global.x, e.global.y), a = z.current.nodes, o = ue ? E(Z.current?.state.zoom ?? 1, 12, 24) : 0, l = null;
1118
+ for (let e = a.length - 1; e >= 0; e--) if (f(i.x, i.y, a[e], o) && a[e].id !== r) {
1119
+ l = a[e];
1120
+ break;
1121
+ }
1122
+ if (l) {
1123
+ let e = l.id, r = c(l.width, l.height), a = s(r, l, i.x, i.y, Infinity)?.id;
1124
+ N((r) => {
1125
+ let i = r.canvases[B.current];
1126
+ return i ? {
1127
+ ...r,
1128
+ canvases: {
1129
+ ...r.canvases,
1130
+ [B.current]: {
1131
+ ...i,
1132
+ edges: i.edges.map((r) => r.id === t ? n === "source" ? {
1133
+ ...r,
1134
+ source: e,
1135
+ sourceHandle: a
1136
+ } : {
1137
+ ...r,
1138
+ target: e,
1139
+ targetHandle: a
1140
+ } : r)
1141
+ }
1142
+ }
1143
+ } : r;
1144
+ });
1145
+ }
1146
+ return;
1147
+ }
1148
+ if (G.current?.active) {
1149
+ let t = G.current.sourceNodeId, n = G.current.sourceHandleId;
1150
+ G.current = null;
1151
+ let r = Q.current(e.global.x, e.global.y), i = z.current.nodes, a = ue ? E(Z.current?.state.zoom ?? 1, 12, 24) : 0, o = null;
1152
+ for (let e = i.length - 1; e >= 0; e--) if (f(r.x, r.y, i[e], a) && i[e].id !== t) {
1153
+ o = i[e];
1154
+ break;
1155
+ }
1156
+ if (o) {
1157
+ let e = o.id, i = c(o.width, o.height), a = s(i, o, r.x, r.y, Infinity)?.id, l = `edge_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 6)}`, u = xt.current;
1158
+ N((r) => {
1159
+ let i = r.canvases[B.current];
1160
+ return !i || i.edges.some((r) => r.source === t && r.target === e && r.sourceHandle === n && r.targetHandle === a) ? r : {
1161
+ ...r,
1162
+ canvases: {
1163
+ ...r.canvases,
1164
+ [B.current]: {
1165
+ ...i,
1166
+ edges: [...i.edges, {
1167
+ id: l,
1168
+ source: t,
1169
+ target: e,
1170
+ sourceHandle: n,
1171
+ targetHandle: a,
1172
+ type: u,
1173
+ data: {
1174
+ strokeColor: "theme:base-content",
1175
+ strokeWidth: 2,
1176
+ lineStyle: "solid",
1177
+ markerEnd: "arrowclosed"
1178
+ }
1179
+ }]
1180
+ }
1181
+ }
1182
+ };
1183
+ });
1184
+ }
1185
+ }
1186
+ }), C.on("pointerupoutside", () => {
1187
+ w(), U.current?.active && H.current(), K.current?.active && H.current(), U.current = null, K.current = null, Y.current = null, W.current = null, q.current = null, G.current = null, R.current = null, X.current = null, I.current = null, st.current = null, ct.current = null, F.current?.hideMarquee();
1188
+ });
1189
+ let Ce = T.current, O = null, Te = (e) => {
1190
+ let t = Ce.getBoundingClientRect(), n = e[0].clientX, r = e[0].clientY, i = e[1].clientX, a = e[1].clientY;
1191
+ return {
1192
+ dist: Math.hypot(i - n, a - r),
1193
+ midX: (n + i) / 2 - t.left,
1194
+ midY: (r + a) / 2 - t.top
1195
+ };
1196
+ }, Ee = () => {
1197
+ w(), U.current?.active && H.current(), K.current?.active && H.current(), U.current = null, K.current = null, Y.current = null, W.current = null, q.current = null, G.current = null, R.current = null, X.current = null, I.current = null, st.current = null, ct.current = null, F.current?.hideMarquee(), Z.current?.cancelPan();
1198
+ }, k = (e) => {
1199
+ if (e.touches.length < 2) return;
1200
+ let t = Z.current;
1201
+ t && (t.multiTouchActive = !0, Ee(), O = Te(e.touches), e.preventDefault());
1202
+ }, De = (e) => {
1203
+ if (!O || e.touches.length < 2) return;
1204
+ e.preventDefault();
1205
+ let t = Z.current;
1206
+ if (!t) return;
1207
+ let n = Te(e.touches), r = n.dist / Math.max(1, O.dist);
1208
+ Number.isFinite(r) && r > 0 && t.zoomAt(n.midX, n.midY, r), t.setState({
1209
+ x: t.state.x + (n.midX - O.midX),
1210
+ y: t.state.y + (n.midY - O.midY)
1211
+ }), O = n;
1212
+ }, A = (e) => {
1213
+ if (e.touches.length >= 2) {
1214
+ O = Te(e.touches);
1215
+ return;
1216
+ }
1217
+ if (O = null, e.touches.length === 0) {
1218
+ let e = Z.current;
1219
+ e && (e.multiTouchActive = !1), ft.current = performance.now() + 350;
1220
+ }
1221
+ };
1222
+ Ce?.addEventListener("touchstart", k, { passive: !1 }), Ce?.addEventListener("touchmove", De, { passive: !1 }), Ce?.addEventListener("touchend", A), Ce?.addEventListener("touchcancel", A), n = k, r = De, h = A, C.on("rightclick", (e) => {
1223
+ if (e.preventDefault?.(), Z.current?.didRightPan) return;
1224
+ let t = Q.current(e.global.x, e.global.y), n = z.current.nodes, r = null;
1225
+ for (let e = n.length - 1; e >= 0; e--) if (f(t.x, t.y, n[e])) {
1226
+ r = n[e].id;
1227
+ break;
1228
+ }
1229
+ let i = e.nativeEvent, a = i?.clientX ?? e.global.x, o = i?.clientY ?? e.global.y;
1230
+ Fe({
1231
+ x: a,
1232
+ y: o,
1233
+ nodeId: r
1234
+ });
1235
+ }), C.on("pointertap", (e) => {
1236
+ if (Z.current?.multiTouchActive || performance.now() < ft.current || e.button !== 0) return;
1237
+ let t = Date.now(), n = Q.current(e.global.x, e.global.y), r = Ct.current;
1238
+ if (r) {
1239
+ let e = d("node"), t = P.current, i = Qe.current, a = pe(n.x - r.width / 2, t, i), o = pe(n.y - r.height / 2, t, i), s = {
1240
+ id: "__ghost__",
1241
+ type: r.type,
1242
+ position: {
1243
+ x: a,
1244
+ y: o
1245
+ },
1246
+ width: r.width,
1247
+ height: r.height,
1248
+ data: {}
1249
+ }, c = re([s], z.current.nodes), l = a + c.dx, u = o + c.dy;
1250
+ N((t) => {
1251
+ let n = t.canvases[B.current];
1252
+ if (!n) return t;
1253
+ let i = {};
1254
+ r.type === "animAnchor" && (i.animIndex = oe(t));
1255
+ let a = Math.max(0, ...n.nodes.map((e) => e.zIndex ?? 0), ...n.lines.map((e) => e.zIndex ?? 0));
1256
+ return {
1257
+ ...t,
1258
+ canvases: {
1259
+ ...t.canvases,
1260
+ [B.current]: {
1261
+ ...n,
1262
+ nodes: [...n.nodes, {
1263
+ id: e,
1264
+ type: r.type,
1265
+ position: {
1266
+ x: l,
1267
+ y: u
1268
+ },
1269
+ width: r.width,
1270
+ height: r.height,
1271
+ zIndex: a + 1,
1272
+ data: {
1273
+ ...r.data,
1274
+ ...i
1275
+ }
1276
+ }]
1277
+ }
1278
+ }
1279
+ };
1280
+ }), M({
1281
+ nodeIds: /* @__PURE__ */ new Set([e]),
1282
+ edgeIds: /* @__PURE__ */ new Set(),
1283
+ lineIds: /* @__PURE__ */ new Set()
1284
+ }), yt.current && window.setTimeout(() => {
1285
+ bt.current(l, u, r.width, r.height, {
1286
+ padding: 80,
1287
+ preserveZoom: !0,
1288
+ duration: 280
1289
+ });
1290
+ }, 0), dt.current = {
1291
+ time: 0,
1292
+ wx: 0,
1293
+ wy: 0
1294
+ };
1295
+ return;
1296
+ }
1297
+ let i = dt.current, a = n.x - i.wx, o = n.y - i.wy;
1298
+ if (t - i.time < 400 && Math.abs(a) < 10 && Math.abs(o) < 10) {
1299
+ let e = z.current.nodes;
1300
+ for (let t = e.length - 1; t >= 0; t--) if (f(n.x, n.y, e[t])) {
1301
+ let n = e[t], r = n.data.childCanvasId;
1302
+ if (r) {
1303
+ Ke(r), dt.current = {
1304
+ time: 0,
1305
+ wx: 0,
1306
+ wy: 0
1307
+ };
1308
+ return;
1309
+ }
1310
+ Nt.current("node", n.id, n.data.label ?? ""), dt.current = {
1311
+ time: 0,
1312
+ wx: 0,
1313
+ wy: 0
1314
+ };
1315
+ return;
1316
+ }
1317
+ let t = z.current.edges, r = /* @__PURE__ */ new Map();
1318
+ for (let t of e) r.set(t.id, t);
1319
+ let i = Z.current?.state.zoom ?? 1;
1320
+ for (let e = t.length - 1; e >= 0; e--) if (be(n.x, n.y, t[e], r, E(i, 8, 12))) {
1321
+ Nt.current("edge", t[e].id, t[e].data.labelText ?? ""), dt.current = {
1322
+ time: 0,
1323
+ wx: 0,
1324
+ wy: 0
1325
+ };
1326
+ return;
1327
+ }
1328
+ }
1329
+ dt.current = {
1330
+ time: t,
1331
+ wx: n.x,
1332
+ wy: n.y
1333
+ };
1334
+ });
1335
+ let j = !1;
1336
+ e.app.ticker.add((t) => {
1337
+ if (e.destroyed) return;
1338
+ let n = t.deltaMS, r = e.app.screen, i = Z.current?.state ?? {
1339
+ x: 0,
1340
+ y: 0,
1341
+ zoom: 1
1342
+ };
1343
+ D.current?.update(i, r.width, r.height);
1344
+ let a = Z.current?.isPanning ?? !1;
1345
+ a !== j && (j = a, T.current && (T.current.style.cursor = a ? "grabbing" : ""));
1346
+ let s = z.current, c = gt.current, l = ae(_t.current), u = /* @__PURE__ */ new Map();
1347
+ l.forEach((e, t) => u.set(e.node.id, t + 1)), $e.current?.advanceAnimation(n);
1348
+ let d = V.current ? l[V.current.current] : void 0;
1349
+ $e.current?.sync(s.nodes, c.nodeIds, I.current, u, {
1350
+ showAnchors: St.current,
1351
+ presentation: V.current !== null,
1352
+ presentationAnchorId: d?.node.id,
1353
+ presentationAnchorVisible: V.current?.showAnchor ?? !1
1354
+ });
1355
+ let f = /* @__PURE__ */ new Map();
1356
+ for (let e of s.nodes) f.set(e.id, e);
1357
+ et.current?.advanceAnimation(n), et.current?.sync(s.edges, f, c.edgeIds, null, { presentation: V.current !== null }), tt.current?.advanceAnimation(n), tt.current?.sync(s.lines, c.lineIds), ot.current?.update(L.current, r.width, r.height, i);
1358
+ let p = Xe.current;
1359
+ if (p) {
1360
+ let e = (c.nodeIds.size > 0 || c.edgeIds.size > 0 || c.lineIds.size > 0) && !Ze.current && !V.current && !Ct.current, t = !e;
1361
+ if (e) {
1362
+ let e = Infinity, n = Infinity, a = -Infinity, o = -Infinity, l = (t, r, i, s) => {
1363
+ e = Math.min(e, t), n = Math.min(n, r), a = Math.max(a, t + i), o = Math.max(o, r + s);
1364
+ };
1365
+ for (let e of s.nodes) c.nodeIds.has(e.id) && l(e.position.x, e.position.y, e.width, e.height);
1366
+ for (let e of s.edges) {
1367
+ if (!c.edgeIds.has(e.id)) continue;
1368
+ let t = f.get(e.source), n = f.get(e.target);
1369
+ t && l(t.position.x, t.position.y, t.width, t.height), n && l(n.position.x, n.position.y, n.width, n.height);
1370
+ }
1371
+ for (let e of s.lines) if (c.lineIds.has(e.id)) for (let t of e.points) l(t.x, t.y, 0, 0);
1372
+ if (e === Infinity) t = !0;
1373
+ else {
1374
+ let e = i.zoom, t = a * e + i.x + 8, o = n * e + i.y - 30 - 6;
1375
+ t + 66 > r.width - 6 && (t = Math.max(6, r.width - 66 - 6)), o < 6 && (o = n * e + i.y + 6), o + 30 > r.height - 6 && (o = Math.max(6, r.height - 30 - 6)), p.style.display = "flex", p.style.left = `${Math.round(t)}px`, p.style.top = `${Math.round(o)}px`;
1376
+ }
1377
+ }
1378
+ t && p.style.display !== "none" && (p.style.display = "none");
1379
+ }
1380
+ let m = at.current;
1381
+ if (m) {
1382
+ m.clear();
1383
+ let e = st.current;
1384
+ e && (m.circle(e.wx, e.wy, 10).fill({
1385
+ color: 3900150,
1386
+ alpha: .12
1387
+ }).stroke({
1388
+ color: 3900150,
1389
+ width: 1.5,
1390
+ alpha: .5
1391
+ }), m.circle(e.wx, e.wy, 4).fill({
1392
+ color: 3900150,
1393
+ alpha: .9
1394
+ }));
1395
+ let t = ct.current;
1396
+ t && !e && (m.circle(t.worldX, t.worldY, 10).fill({
1397
+ color: 16347926,
1398
+ alpha: .12
1399
+ }).stroke({
1400
+ color: 16347926,
1401
+ width: 1.5,
1402
+ alpha: .5
1403
+ }), m.circle(t.worldX, t.worldY, 4).fill({
1404
+ color: 16347926,
1405
+ alpha: .9
1406
+ }));
1407
+ }
1408
+ let h = pt.current;
1409
+ if (h) {
1410
+ h.clear();
1411
+ let e = Ct.current;
1412
+ if (e) {
1413
+ let t = mt.current, n = P.current, r = Qe.current, i = pe(t.x - e.width / 2, n, r), a = pe(t.y - e.height / 2, n, r), c = {
1414
+ id: "__ghost__",
1415
+ type: e.type,
1416
+ position: {
1417
+ x: i,
1418
+ y: a
1419
+ },
1420
+ width: e.width,
1421
+ height: e.height,
1422
+ data: {}
1423
+ }, l = re([c], s.nodes);
1424
+ L.current = l.guides, h.position.set(i + l.dx, a + l.dy), (o[e.type] ?? o.shapeRect)(h, {
1425
+ width: e.width,
1426
+ height: e.height,
1427
+ fill: "#3b82f6",
1428
+ stroke: "#3b82f6",
1429
+ strokeWidth: 1.5,
1430
+ borderStyle: e.data.borderStyle
1431
+ });
1432
+ } else h.position.set(0, 0), !U.current?.active && !Y.current?.active && (L.current = []);
1433
+ }
1434
+ let g = lt.current;
1435
+ if (g && (g.clear(), c.edgeIds.size > 0 && vt.current === "select")) {
1436
+ let e = 1 / i.zoom;
1437
+ for (let t of s.edges) {
1438
+ if (!c.edgeIds.has(t.id)) continue;
1439
+ let n = _(t, f);
1440
+ n && (g.circle(n.sx, n.sy, 5 * e).fill({ color: 16777215 }).stroke({
1441
+ color: 16347926,
1442
+ width: 1.5 * e
1443
+ }), g.circle(n.tx, n.ty, 5 * e).fill({ color: 16777215 }).stroke({
1444
+ color: 16347926,
1445
+ width: 1.5 * e
1446
+ }));
1447
+ let r = t.data.waypoints;
1448
+ if (r) for (let t of r) g.circle(t.x, t.y, 5 * e).fill({ color: 16777215 }).stroke({
1449
+ color: 3900150,
1450
+ width: 1.5 * e
1451
+ });
1452
+ if (t.type === "simplebezier") {
1453
+ let n = _(t, f);
1454
+ if (!n) continue;
1455
+ let i = r ?? [], a = [
1456
+ {
1457
+ x: n.sx,
1458
+ y: n.sy
1459
+ },
1460
+ ...i,
1461
+ {
1462
+ x: n.tx,
1463
+ y: n.ty
1464
+ }
1465
+ ], o = t.data.bezierControls, s = a.length - 2;
1466
+ for (let t = 0; t <= s; t++) {
1467
+ let r = a[t], i = a[t + 1], c = o?.[t], l = Math.hypot(i.x - r.x, i.y - r.y), u = Math.max(30, l * .3), d = c?.c1x ?? (t === 0 ? r.x + n.snx * u : r.x + (i.x - r.x) * .4), f = c?.c1y ?? (t === 0 ? r.y + n.sny * u : r.y), p = c?.c2x ?? (t === s ? i.x + n.tnx * u : i.x - (i.x - r.x) * .4), m = c?.c2y ?? (t === s ? i.y + n.tny * u : i.y);
1468
+ g.moveTo(r.x, r.y).lineTo(d, f).stroke({
1469
+ color: 10265519,
1470
+ width: 1 * e
1471
+ }), g.moveTo(i.x, i.y).lineTo(p, m).stroke({
1472
+ color: 10265519,
1473
+ width: 1 * e
1474
+ });
1475
+ let h = 4 * e;
1476
+ g.circle(d, f, h).fill({ color: 16777215 }).stroke({
1477
+ color: 3900150,
1478
+ width: 1.5 * e
1479
+ }), g.circle(p, m, h).fill({ color: 16777215 }).stroke({
1480
+ color: 3900150,
1481
+ width: 1.5 * e
1482
+ });
1483
+ }
1484
+ }
1485
+ }
1486
+ }
1487
+ let v = it.current;
1488
+ if (v && (v.clear(), c.nodeIds.size === 1 && vt.current === "select")) {
1489
+ let e = [...c.nodeIds][0], t = s.nodes.find((t) => t.id === e);
1490
+ if (t) {
1491
+ let e = i.zoom, n = t.position.x * e + i.x, r = t.position.y * e + i.y, a = t.width * e, o = t.height * e;
1492
+ v.rect(n, r, a, o).stroke({
1493
+ color: 3900150,
1494
+ width: 1.5
1495
+ });
1496
+ let s = 7 / 2, c = [
1497
+ [n, r],
1498
+ [n + a, r],
1499
+ [n + a, r + o],
1500
+ [n, r + o]
1501
+ ];
1502
+ for (let [e, t] of c) v.rect(e - s, t - s, 7, 7).fill({ color: 16777215 }).stroke({
1503
+ color: 3900150,
1504
+ width: 1.5
1505
+ });
1506
+ let l = [
1507
+ [n + a / 2, r],
1508
+ [n + a, r + o / 2],
1509
+ [n + a / 2, r + o],
1510
+ [n, r + o / 2]
1511
+ ];
1512
+ for (let [e, t] of l) v.circle(e, t, 4).fill({
1513
+ color: 3900150,
1514
+ alpha: .9
1515
+ });
1516
+ if (!Ze.current) {
1517
+ let e = n + a / 2, t = r - de;
1518
+ v.moveTo(e, r).lineTo(e, t).stroke({
1519
+ color: 3900150,
1520
+ width: 1.5,
1521
+ alpha: .85
1522
+ }), v.circle(e, t, 6).fill({ color: 16777215 }).stroke({
1523
+ color: 3900150,
1524
+ width: 1.5
1525
+ }), v.circle(e, t, 2.5).fill({ color: 3900150 });
1526
+ }
1527
+ }
1528
+ }
1529
+ });
1530
+ };
1531
+ return g(), () => {
1532
+ if (t = !0, e && !e.destroyed) try {
1533
+ e.app.stage.removeAllListeners();
1534
+ } catch {}
1535
+ let i = T.current;
1536
+ n && i?.removeEventListener("touchstart", n), r && i?.removeEventListener("touchmove", r), h && (i?.removeEventListener("touchend", h), i?.removeEventListener("touchcancel", h));
1537
+ let a = (e) => {
1538
+ try {
1539
+ e?.destroy();
1540
+ } catch {}
1541
+ };
1542
+ a(D.current), a(F.current), a($e.current), a(et.current), a(tt.current), a(nt.current), a(rt.current), a(J.current), a(it.current), it.current = null, a(at.current), at.current = null, a(lt.current), lt.current = null, a(pt.current), pt.current = null, a(ot.current);
1543
+ };
1544
+ }, [O.current]), b(() => {
1545
+ let e = nt.current, t = rt.current;
1546
+ if (e && t) switch (e.deactivate(), t.deactivate(), j) {
1547
+ case "freehand":
1548
+ e.activate();
1549
+ break;
1550
+ case "line":
1551
+ t.activate("straight");
1552
+ break;
1553
+ case "polyline":
1554
+ t.activate("polyline");
1555
+ break;
1556
+ case "arrow": t.activate("arrow");
1557
+ }
1558
+ }, [j]), b(() => {
1559
+ D.current && (D.current.visible = Oe, D.current.gridSize = ke);
1560
+ }, [Oe, ke]), b(() => {
1561
+ let e = T.current;
1562
+ if (!e) return;
1563
+ let t = (t) => {
1564
+ t.preventDefault();
1565
+ let n = Z.current;
1566
+ if (!n) return;
1567
+ let r = e.getBoundingClientRect(), i = t.clientX - r.left, a = t.clientY - r.top, o = t.ctrlKey ? 3 : 1, s = -t.deltaY * .001 * o;
1568
+ n.zoomAt(i, a, 1 + s);
1569
+ };
1570
+ return e.addEventListener("wheel", t, { passive: !1 }), () => e.removeEventListener("wheel", t);
1571
+ }, [Z]), /* @__PURE__ */ w("div", {
1572
+ style: {
1573
+ position: "relative",
1574
+ width: "100%",
1575
+ height: "100%"
1576
+ },
1577
+ children: [
1578
+ /* @__PURE__ */ C("div", {
1579
+ ref: T,
1580
+ className: "flow-canvas-wrapper",
1581
+ tabIndex: -1,
1582
+ onContextMenu: (e) => e.preventDefault()
1583
+ }),
1584
+ $ && At && /* @__PURE__ */ C("input", {
1585
+ className: "flow-label-editor",
1586
+ autoFocus: !0,
1587
+ defaultValue: $.value,
1588
+ style: {
1589
+ left: At.x,
1590
+ top: At.y
1591
+ },
1592
+ onFocus: (e) => e.currentTarget.select(),
1593
+ onKeyDown: (e) => {
1594
+ e.key === "Enter" ? (e.preventDefault(), Pt(e.target.value)) : e.key === "Escape" && (e.preventDefault(), Ft()), e.stopPropagation();
1595
+ },
1596
+ onBlur: (e) => Pt(e.target.value),
1597
+ onPointerDown: (e) => e.stopPropagation()
1598
+ }),
1599
+ Ne && !Re && /* @__PURE__ */ w("button", {
1600
+ type: "button",
1601
+ className: "flow-esc-button",
1602
+ onClick: () => Pe(null),
1603
+ title: "取消连续放置 (Esc)",
1604
+ children: [/* @__PURE__ */ C("span", {
1605
+ "aria-hidden": !0,
1606
+ children: "⎋"
1607
+ }), " 取消放置 (ESC)"]
1608
+ }),
1609
+ /* @__PURE__ */ w("button", {
1610
+ ref: Xe,
1611
+ type: "button",
1612
+ className: "flow-delete-button",
1613
+ style: { display: "none" },
1614
+ onClick: () => Ye.current(),
1615
+ title: "删除所选 (Delete)",
1616
+ "aria-label": "删除所选",
1617
+ children: [/* @__PURE__ */ w("svg", {
1618
+ width: "12",
1619
+ height: "12",
1620
+ viewBox: "0 0 24 24",
1621
+ fill: "none",
1622
+ stroke: "currentColor",
1623
+ strokeWidth: "2.5",
1624
+ strokeLinecap: "round",
1625
+ strokeLinejoin: "round",
1626
+ "aria-hidden": !0,
1627
+ children: [
1628
+ /* @__PURE__ */ C("path", { d: "M3 6h18" }),
1629
+ /* @__PURE__ */ C("path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" }),
1630
+ /* @__PURE__ */ C("path", { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" })
1631
+ ]
1632
+ }), "删除"]
1633
+ })
1634
+ ]
1635
+ });
1672
1636
  }
1673
- export {
1674
- fr as default
1675
- };
1637
+ //#endregion
1638
+ export { D as default };
1676
1639
 
1677
1640
  //# sourceMappingURL=FlowCanvas.js.map