@m3ui-vue/m3ui-vue 1.2.2 → 1.3.1

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 (241) hide show
  1. package/dist/API.md +3010 -376
  2. package/dist/MButton-Bl_BSUep.js +172 -0
  3. package/dist/MButton-Bl_BSUep.js.map +1 -0
  4. package/dist/MDialog-D_Yik8ou.js +173 -0
  5. package/dist/MDialog-D_Yik8ou.js.map +1 -0
  6. package/dist/MIconButton-DoNotQ9v.js +282 -0
  7. package/dist/MIconButton-DoNotQ9v.js.map +1 -0
  8. package/dist/MListItem-BxifHJdU.js +824 -0
  9. package/dist/MListItem-BxifHJdU.js.map +1 -0
  10. package/dist/MLoadingIndicator-BxbFhSX6.js +115 -0
  11. package/dist/MLoadingIndicator-BxbFhSX6.js.map +1 -0
  12. package/dist/MMenuItem-Bih0h4-n.js +604 -0
  13. package/dist/MMenuItem-Bih0h4-n.js.map +1 -0
  14. package/dist/MProgressBar-BCoruxA-.js +184 -0
  15. package/dist/MProgressBar-BCoruxA-.js.map +1 -0
  16. package/dist/MSeekBar-BeN9QcB3.js +435 -0
  17. package/dist/MSeekBar-BeN9QcB3.js.map +1 -0
  18. package/dist/MSegmentedButton-DL9JtJFX.js +65 -0
  19. package/dist/MSegmentedButton-DL9JtJFX.js.map +1 -0
  20. package/dist/MSlider-BVSbJlGS.js +691 -0
  21. package/dist/MSlider-BVSbJlGS.js.map +1 -0
  22. package/dist/MSpinner-C2SUnWk4.js +65 -0
  23. package/dist/MSpinner-C2SUnWk4.js.map +1 -0
  24. package/dist/MTextField-CEkWSZ2v.js +296 -0
  25. package/dist/MTextField-CEkWSZ2v.js.map +1 -0
  26. package/dist/MTooltip-CodJGEO-.js +756 -0
  27. package/dist/MTooltip-CodJGEO-.js.map +1 -0
  28. package/dist/_storageKeys-CYXsUBwK.js +18 -0
  29. package/dist/_storageKeys-CYXsUBwK.js.map +1 -0
  30. package/dist/_useEscapeStack-CjndQhqg.js +19 -0
  31. package/dist/_useEscapeStack-CjndQhqg.js.map +1 -0
  32. package/dist/api.json +1 -1
  33. package/dist/chart.js +1 -1
  34. package/dist/code-editor.js +1 -1
  35. package/dist/components/MAudioPlayer.vue.d.ts +115 -0
  36. package/dist/components/MBadge.vue.d.ts +1 -1
  37. package/dist/components/MBottomSheetScaffold.vue.d.ts +1 -1
  38. package/dist/components/MBox.vue.d.ts +1 -1
  39. package/dist/components/MButton.vue.d.ts +1 -1
  40. package/dist/components/MConfirmDialog.vue.d.ts +1 -1
  41. package/dist/components/MCopyButton.vue.d.ts +2 -2
  42. package/dist/components/MDataTable.vue.d.ts +2 -2
  43. package/dist/components/MDialog.vue.d.ts +2 -2
  44. package/dist/components/MDivider.vue.d.ts +1 -1
  45. package/dist/components/MDragHandle.vue.d.ts +1 -1
  46. package/dist/components/MDrawCanvas.vue.d.ts +150 -0
  47. package/dist/components/MDrawLayers.vue.d.ts +3 -0
  48. package/dist/components/MDrawToolbar.vue.d.ts +34 -0
  49. package/dist/components/MExportButton.vue.d.ts +1 -1
  50. package/dist/components/MFab.vue.d.ts +2 -2
  51. package/dist/components/MFabMenu.vue.d.ts +2 -2
  52. package/dist/components/MFixed.vue.d.ts +1 -1
  53. package/dist/components/MFlex.vue.d.ts +2 -2
  54. package/dist/components/MFloorPlan.vue.d.ts +248 -0
  55. package/dist/components/MFloorPlanInspector.vue.d.ts +56 -0
  56. package/dist/components/MFloorPlanToolbar.vue.d.ts +51 -0
  57. package/dist/components/MFlow.vue.d.ts +318 -0
  58. package/dist/components/MFlowControls.vue.d.ts +33 -0
  59. package/dist/components/MFlowHandle.vue.d.ts +16 -0
  60. package/dist/components/MFlowMinimap.vue.d.ts +22 -0
  61. package/dist/components/MFlowNode.vue.d.ts +35 -0
  62. package/dist/components/MGantt.vue.d.ts +141 -0
  63. package/dist/components/MGanttControls.vue.d.ts +32 -0
  64. package/dist/components/MIconButton.vue.d.ts +3 -1
  65. package/dist/components/MImageCropper.vue.d.ts +110 -0
  66. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  67. package/dist/components/MLightbox.vue.d.ts +2 -2
  68. package/dist/components/MList.vue.d.ts +1 -1
  69. package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
  70. package/dist/components/MMapControl.vue.d.ts +1 -1
  71. package/dist/components/MMapSearch.vue.d.ts +1 -1
  72. package/dist/components/MMaskField.vue.d.ts +12 -1
  73. package/dist/components/MMenu.vue.d.ts +1 -1
  74. package/dist/components/MNavigationDrawer.vue.d.ts +1 -1
  75. package/dist/components/MNumberField.vue.d.ts +11 -2
  76. package/dist/components/MPdfViewer.vue.d.ts +174 -0
  77. package/dist/components/MPullToRefresh.vue.d.ts +1 -1
  78. package/dist/components/MResourceTimeline.vue.d.ts +149 -0
  79. package/dist/components/MScheduler.vue.d.ts +3 -3
  80. package/dist/components/MScheme.vue.d.ts +1 -1
  81. package/dist/components/MSearchField.vue.d.ts +1 -1
  82. package/dist/components/MSeekBar.vue.d.ts +1 -1
  83. package/dist/components/MSimpleCarousel.vue.d.ts +1 -1
  84. package/dist/components/MSkeleton.vue.d.ts +1 -1
  85. package/dist/components/MSlider.vue.d.ts +2 -2
  86. package/dist/components/MSparkline.vue.d.ts +1 -1
  87. package/dist/components/MSplitter.vue.d.ts +1 -1
  88. package/dist/components/MStack.vue.d.ts +2 -2
  89. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  90. package/dist/components/MSwitch.vue.d.ts +1 -1
  91. package/dist/components/MTable.vue.d.ts +1 -1
  92. package/dist/components/MTagInput.vue.d.ts +12 -1
  93. package/dist/components/MTextField.vue.d.ts +13 -2
  94. package/dist/components/MToolbar.vue.d.ts +1 -1
  95. package/dist/components/MTree.vue.d.ts +2 -2
  96. package/dist/components/MVideoPlayer.vue.d.ts +253 -0
  97. package/dist/components/MVirtualTable.vue.d.ts +1 -1
  98. package/dist/components/MWindow.vue.d.ts +3 -3
  99. package/dist/components/_MFlowEdge.vue.d.ts +9 -0
  100. package/dist/components/_MFlowEdgeLabel.vue.d.ts +9 -0
  101. package/dist/components/_MFlowNodeShell.vue.d.ts +9 -0
  102. package/dist/components/_MPdfPage.vue.d.ts +76 -0
  103. package/dist/components/_MTimeBackground.vue.d.ts +14 -0
  104. package/dist/components/_MTimeHeader.vue.d.ts +20 -0
  105. package/dist/composables/_flowPanel.d.ts +2 -0
  106. package/dist/composables/_flowSlot.d.ts +5 -0
  107. package/dist/composables/_ganttTime.d.ts +41 -0
  108. package/dist/composables/_useTimeAxis.d.ts +90 -0
  109. package/dist/composables/drawGeometry.d.ts +119 -0
  110. package/dist/composables/flowFormats.d.ts +79 -0
  111. package/dist/composables/flowLayout.d.ts +45 -0
  112. package/dist/composables/flowPaths.d.ts +53 -0
  113. package/dist/composables/ganttFormats.d.ts +52 -0
  114. package/dist/composables/ganttSchedule.d.ts +99 -0
  115. package/dist/composables/useDrawing.d.ts +44 -0
  116. package/dist/composables/useFloorPlan.d.ts +58 -0
  117. package/dist/composables/useFlow.d.ts +266 -0
  118. package/dist/composables/useGantt.d.ts +87 -0
  119. package/dist/composables/useLocale.d.ts +204 -0
  120. package/dist/composables/useMediaPlayer.d.ts +101 -0
  121. package/dist/composables/usePdf.d.ts +119 -0
  122. package/dist/composables/useResourceTimeline.d.ts +70 -0
  123. package/dist/draw.d.ts +7 -0
  124. package/dist/draw.js +1702 -0
  125. package/dist/draw.js.map +1 -0
  126. package/dist/flow.d.ts +14 -0
  127. package/dist/flow.js +3547 -0
  128. package/dist/flow.js.map +1 -0
  129. package/dist/flowPaths-CUc6X373.js +161 -0
  130. package/dist/flowPaths-CUc6X373.js.map +1 -0
  131. package/dist/gantt.d.ts +12 -0
  132. package/dist/gantt.js +3575 -0
  133. package/dist/gantt.js.map +1 -0
  134. package/dist/index.d.ts +9 -0
  135. package/dist/locales/index.js +1435 -7
  136. package/dist/locales/index.js.map +1 -1
  137. package/dist/m3ui-vue.css +1 -1
  138. package/dist/m3ui.js +8248 -7637
  139. package/dist/m3ui.js.map +1 -1
  140. package/dist/map.js +113 -108
  141. package/dist/map.js.map +1 -1
  142. package/dist/media.d.ts +5 -0
  143. package/dist/media.js +1311 -0
  144. package/dist/media.js.map +1 -0
  145. package/dist/pdf.d.ts +4 -0
  146. package/dist/pdf.js +1871 -0
  147. package/dist/pdf.js.map +1 -0
  148. package/dist/rich-text-editor.js +28 -26
  149. package/dist/rich-text-editor.js.map +1 -1
  150. package/dist/styles.css +1 -1
  151. package/dist/{useLocale-JYxDDeXC.js → useLocale-CaWwi-b6.js} +206 -2
  152. package/dist/useLocale-CaWwi-b6.js.map +1 -0
  153. package/dist/{useThemeTokens-y0HZpyhL.js → useThemeTokens-DQQcaWbE.js} +40 -54
  154. package/dist/useThemeTokens-DQQcaWbE.js.map +1 -0
  155. package/package.json +29 -5
  156. package/src/__tests__/MAudioPlayer.test.ts +75 -0
  157. package/src/__tests__/MDrawCanvas.test.ts +118 -0
  158. package/src/__tests__/MFloorPlan.test.ts +299 -0
  159. package/src/__tests__/MFlow.test.ts +590 -0
  160. package/src/__tests__/MGantt.test.ts +130 -0
  161. package/src/__tests__/MImageCropper.test.ts +89 -0
  162. package/src/__tests__/MPdfViewer.test.ts +235 -0
  163. package/src/__tests__/MResourceTimeline.test.ts +102 -0
  164. package/src/__tests__/MVideoPlayer.test.ts +201 -0
  165. package/src/__tests__/drawGeometry.test.ts +58 -0
  166. package/src/__tests__/fieldExpose.test.ts +30 -0
  167. package/src/__tests__/flowFormats.test.ts +185 -0
  168. package/src/__tests__/flowLayout.test.ts +113 -0
  169. package/src/__tests__/ganttFormats.test.ts +76 -0
  170. package/src/__tests__/ganttSchedule.test.ts +136 -0
  171. package/src/__tests__/pdfMock.ts +83 -0
  172. package/src/__tests__/useMediaPlayer.test.ts +182 -0
  173. package/src/__tests__/usePdf.test.ts +102 -0
  174. package/src/components/MAudioPlayer.vue +319 -0
  175. package/src/components/MDrawCanvas.vue +819 -0
  176. package/src/components/MDrawLayers.vue +114 -0
  177. package/src/components/MDrawToolbar.vue +171 -0
  178. package/src/components/MFloorPlan.vue +1080 -0
  179. package/src/components/MFloorPlanInspector.vue +169 -0
  180. package/src/components/MFloorPlanToolbar.vue +128 -0
  181. package/src/components/MFlow.vue +2060 -0
  182. package/src/components/MFlowControls.vue +110 -0
  183. package/src/components/MFlowHandle.vue +60 -0
  184. package/src/components/MFlowMinimap.vue +134 -0
  185. package/src/components/MFlowNode.vue +98 -0
  186. package/src/components/MGantt.vue +1609 -0
  187. package/src/components/MGanttControls.vue +77 -0
  188. package/src/components/MIconButton.vue +3 -1
  189. package/src/components/MImageCropper.vue +507 -0
  190. package/src/components/MMaskField.vue +13 -0
  191. package/src/components/MNumberField.vue +13 -0
  192. package/src/components/MPdfViewer.vue +1270 -0
  193. package/src/components/MResourceTimeline.vue +1020 -0
  194. package/src/components/MTagInput.vue +13 -0
  195. package/src/components/MTextField.vue +16 -0
  196. package/src/components/MVideoPlayer.vue +839 -0
  197. package/src/components/_MFlowEdge.vue +100 -0
  198. package/src/components/_MFlowEdgeLabel.vue +56 -0
  199. package/src/components/_MFlowNodeShell.vue +111 -0
  200. package/src/components/_MPdfPage.vue +456 -0
  201. package/src/components/_MTimeBackground.vue +16 -0
  202. package/src/components/_MTimeHeader.vue +31 -0
  203. package/src/composables/_flowPanel.ts +13 -0
  204. package/src/composables/_flowSlot.ts +6 -0
  205. package/src/composables/_ganttTime.ts +200 -0
  206. package/src/composables/_useTimeAxis.ts +224 -0
  207. package/src/composables/drawGeometry.ts +405 -0
  208. package/src/composables/flowFormats.ts +916 -0
  209. package/src/composables/flowLayout.ts +297 -0
  210. package/src/composables/flowPaths.ts +239 -0
  211. package/src/composables/ganttFormats.ts +366 -0
  212. package/src/composables/ganttSchedule.ts +403 -0
  213. package/src/composables/useDrawing.ts +53 -0
  214. package/src/composables/useFloorPlan.ts +73 -0
  215. package/src/composables/useFlow.ts +250 -0
  216. package/src/composables/useGantt.ts +92 -0
  217. package/src/composables/useLocale.ts +410 -0
  218. package/src/composables/useMediaPlayer.ts +406 -0
  219. package/src/composables/usePdf.ts +456 -0
  220. package/src/composables/useResourceTimeline.ts +76 -0
  221. package/src/draw.ts +25 -0
  222. package/src/flow.ts +26 -0
  223. package/src/gantt.ts +12 -0
  224. package/src/index.ts +9 -0
  225. package/src/locales/de.ts +204 -0
  226. package/src/locales/es.ts +204 -0
  227. package/src/locales/fr.ts +204 -0
  228. package/src/locales/ja.ts +204 -0
  229. package/src/locales/ko.ts +204 -0
  230. package/src/locales/pt.ts +204 -0
  231. package/src/locales/zh.ts +204 -0
  232. package/src/media.ts +5 -0
  233. package/src/pdf.ts +15 -0
  234. package/dist/MMenuItem-D4Gx_l3F.js +0 -929
  235. package/dist/MMenuItem-D4Gx_l3F.js.map +0 -1
  236. package/dist/MSlider-Dx_S3vJ9.js +0 -1506
  237. package/dist/MSlider-Dx_S3vJ9.js.map +0 -1
  238. package/dist/MTextField-Bz8JIsnl.js +0 -633
  239. package/dist/MTextField-Bz8JIsnl.js.map +0 -1
  240. package/dist/useLocale-JYxDDeXC.js.map +0 -1
  241. package/dist/useThemeTokens-y0HZpyhL.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow.js","names":["$slots","$attrs","$slots"],"sources":["../src/composables/useFlow.ts","../src/composables/flowLayout.ts","../src/composables/_flowSlot.ts","../src/components/MFlowHandle.vue","../src/components/MFlowHandle.vue","../src/components/MFlowNode.vue","../src/components/MFlowNode.vue","../src/components/_MFlowNodeShell.vue","../src/components/_MFlowNodeShell.vue","../src/components/_MFlowEdge.vue","../src/components/_MFlowEdge.vue","../src/components/_MFlowEdgeLabel.vue","../src/components/_MFlowEdgeLabel.vue","../src/components/MFlow.vue","../src/components/MFlow.vue","../src/composables/_flowPanel.ts","../src/components/MFlowControls.vue","../src/components/MFlowControls.vue","../src/components/MFlowMinimap.vue","../src/components/MFlowMinimap.vue","../src/composables/flowFormats.ts"],"sourcesContent":["import { inject, type ComputedRef, type InjectionKey, type Ref } from 'vue'\nimport type { FlowEdgePath, FlowPosition } from './flowPaths'\nimport type { FlowLayout, FlowLayoutOptions } from './flowLayout'\n\nexport type { FlowPosition }\n\n/** A point in flow coordinates */\nexport interface FlowXY { x: number; y: number }\n\n/**\n * A node. Treat nodes as immutable: MFlow emits new arrays with new objects for whatever changed (`v-model:nodes`),\n * and the history (undo) keeps the old ones.\n */\nexport interface FlowNode<D = any> {\n id: string\n /**\n * How it's drawn: `default` (an MFlowNode with a handle each side), `input` (only a source), `output` (only a\n * target), `circle` (a round vertex, see `FlowCircleData`), `group` (a container for nodes whose `parentId` is this\n * one), or any name you give a `#node-<type>` slot\n */\n type?: string\n /** Its top left corner, in flow coordinates (relative to the parent's corner when it has a `parentId`) */\n position: FlowXY\n /** Anything; the default node shows `label`, `subtitle` and `icon` */\n data?: D\n /** A fixed size; otherwise it's measured. A `group` without one wraps its children */\n width?: number\n height?: number\n /** The group this node sits in: it moves with it */\n parentId?: string\n /** `'parent'` keeps it inside its group */\n extent?: 'parent'\n /** Where the default node's handles go; default from MFlow's `direction` */\n sourcePosition?: FlowPosition\n targetPosition?: FlowPosition\n hidden?: boolean\n draggable?: boolean\n selectable?: boolean\n connectable?: boolean\n deletable?: boolean\n /** `false` keeps it from splicing into an edge when dropped onto one */\n insertable?: boolean\n class?: string\n}\n\n/** What a `circle` node shows */\nexport interface FlowCircleData {\n label?: string\n /** Its fill: a container role (default a neutral surface) */\n color?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'neutral' | 'inverse'\n /** A small count or tag on its top right (a level, an excess) */\n badge?: string | number\n /** A soft halo around it, in a role's color */\n ring?: 'primary' | 'secondary' | 'tertiary' | 'error'\n /** Diameter in px (default 56) */\n size?: number\n}\n\nexport type FlowMarker = 'arrow' | 'arrow-closed' | 'none'\n\nexport interface FlowEdge<D = any> {\n id: string\n source: string\n target: string\n /** The handle's `id` when its node has several */\n sourceHandle?: string | null\n targetHandle?: string | null\n /** `bezier` (default), `smoothstep`, `step`, `straight`, or a `#edge-<type>` slot */\n type?: string\n /**\n * For a `#edge-<type>` slot: how it's routed, which is the `path` the slot gets and where the edge is hit\n * (default `bezier`)\n */\n pathType?: 'bezier' | 'smoothstep' | 'step' | 'straight'\n label?: string\n /** The label chip's color (default a neutral chip) */\n labelTone?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'neutral'\n /** Dashes that flow from source to target (`'reverse'`: from target to source) */\n animated?: boolean | 'reverse'\n /** The line's (and arrowhead's) color: an M3 role (`primary`, `tertiary`, `error`, `outline`…) or any CSS color. Changes animate */\n color?: string\n /** The line's width in px (default 2). Changes animate */\n width?: number\n /** A dashed line, standing still */\n dashed?: boolean\n /** Default `arrow-closed` */\n markerEnd?: FlowMarker\n markerStart?: FlowMarker\n data?: D\n hidden?: boolean\n selectable?: boolean\n deletable?: boolean\n /** Its ends can be dragged to other handles once selected; default MFlow's `edgesReconnectable` */\n reconnectable?: boolean\n class?: string\n}\n\n/** The view: `x`/`y` in px, where the flow's origin is on the canvas, and the zoom */\nexport interface FlowViewport { x: number; y: number; zoom: number }\n\n/** A connection being made or checked */\nexport interface FlowConnection {\n source: string\n sourceHandle: string | null\n target: string\n targetHandle: string | null\n}\n\nexport interface FlowSelection { nodes: string[]; edges: string[] }\n\n/** A handle as measured: its center relative to its node's corner, in flow units */\nexport interface FlowHandleBounds {\n id: string | null\n type: 'source' | 'target'\n position: FlowPosition\n x: number\n y: number\n connectable: boolean\n}\n\nexport interface FlowFitOptions {\n /** Room around the nodes, a fraction of the view (default 0.1) */\n padding?: number\n /** Only these nodes */\n nodes?: string[]\n maxZoom?: number\n minZoom?: number\n /** Default true */\n animate?: boolean\n}\n\n/** What MFlow provides to everything inside it, and `useFlow()` returns */\nexport interface FlowContext {\n nodes: ComputedRef<FlowNode[]>\n edges: ComputedRef<FlowEdge[]>\n viewport: Readonly<Ref<FlowViewport>>\n selection: ComputedRef<FlowSelection>\n minZoom: ComputedRef<number>\n maxZoom: ComputedRef<number>\n /** Canvas size in px */\n size: Readonly<Ref<{ width: number; height: number }>>\n /** Interaction switched off by the lock button (or MFlow's `locked`) */\n locked: Ref<boolean>\n getNode(id: string): FlowNode | undefined\n /** A node's top left corner in flow coordinates, its parents added, where it's drawn right now */\n getAbsolutePosition(id: string): FlowXY\n /** A node's measured (or set) size */\n getSize(id: string): { width: number; height: number }\n /** Nodes overlapping this one (or a rectangle in flow coordinates), groups and its own family left out */\n getIntersectingNodes(node: string | { x: number; y: number; width: number; height: number }): FlowNode[]\n /** Page (client) coordinates → flow coordinates */\n screenToFlow(p: { x: number; y: number }): FlowXY\n flowToScreen(p: FlowXY): { x: number; y: number }\n setViewport(v: Partial<FlowViewport>, opts?: { animate?: boolean }): void\n fitView(opts?: FlowFitOptions): void\n /** Centers the view on a flow point, at `zoom` or the current zoom */\n setCenter(x: number, y: number, opts?: { zoom?: number; animate?: boolean }): void\n zoomIn(): void\n zoomOut(): void\n zoomTo(zoom: number, opts?: { animate?: boolean }): void\n addNodes(nodes: FlowNode | FlowNode[]): void\n addEdges(edges: FlowEdge | FlowEdge[]): void\n updateNode(id: string, patch: Partial<FlowNode> | ((n: FlowNode) => FlowNode)): void\n updateEdge(id: string, patch: Partial<FlowEdge> | ((e: FlowEdge) => FlowEdge)): void\n /** Deletes nodes (with their edges and children) and edges by id */\n remove(ids: { nodes?: string[]; edges?: string[] }): void\n setSelection(sel: Partial<FlowSelection>): void\n /** Runs a layout over the nodes' measured sizes; default MFlow's `layout` (or the tree layout). Animated and undoable */\n layout(fn?: 'tree' | 'layered' | FlowLayout, options?: FlowLayoutOptions): Promise<void>\n undo(): void\n redo(): void\n canUndo: ComputedRef<boolean>\n canRedo: ComputedRef<boolean>\n copy(): void\n cut(): void\n /** Pastes what was copied, at a flow point (default a step from the originals) */\n paste(at?: FlowXY): void\n /**\n * Drags a node with a pointer that's already down, e.g. one just added from a palette outside the canvas: it\n * follows the pointer from there (guides, splicing into an edge) until it's let go. With a finger, the page\n * doesn't scroll under it meanwhile (start the drag from a long press, so a swipe still scrolls your palette)\n */\n startDrag(id: string, e: PointerEvent): void\n}\n\n// Internal: what nodes and handles inside MFlow reach\nexport interface FlowInternals extends FlowContext {\n registerHandle(nodeId: string, el: HTMLElement, info: () => Omit<FlowHandleBounds, 'x' | 'y'>): () => void\n measureNode(nodeId: string): void\n startConnection(e: PointerEvent, nodeId: string, handleId: string | null, type: 'source' | 'target'): void\n /** The handle a connection being dragged would snap to (`nodeId:handleId:type`), and whether it's valid */\n connectionTarget: Readonly<Ref<{ key: string; valid: boolean } | null>>\n connecting: Readonly<Ref<boolean>>\n /** The edge a dragged node would splice into if dropped now */\n insertEdge: Readonly<Ref<string | null>>\n /** Dragging an edge draws a branch from its source (edgeBranching) */\n branching: ComputedRef<boolean>\n nodesConnectable: ComputedRef<boolean>\n direction: ComputedRef<'horizontal' | 'vertical'>\n registerNodeEl(id: string, el: HTMLElement | null): void\n selectedNodes: ComputedRef<Set<string>>\n selectedEdges: ComputedRef<Set<string>>\n dragging: Readonly<Ref<Set<string>>>\n isLifted(id: string): boolean\n zIndexOf(id: string): number\n edgeGeometry(e: FlowEdge): FlowEdgeGeometry | null\n isReconnectable(e: FlowEdge): boolean\n sidePositions(n: FlowNode): { source: FlowPosition; target: FlowPosition }\n onNodeKey(e: KeyboardEvent, id: string): void\n onEdgeKey(e: KeyboardEvent, id: string): void\n}\n\n// Internal: an edge's ends and path\nexport interface FlowEdgeGeometry extends FlowEdgePath {\n sourceX: number\n sourceY: number\n targetX: number\n targetY: number\n sourcePosition: FlowPosition\n targetPosition: FlowPosition\n /** How far the end sits inside a handle (0 at a node's side) */\n sourceInset: number\n targetInset: number\n}\n\nexport const FLOW_KEY: InjectionKey<FlowInternals> = Symbol('m3-flow')\n\n// Internal: provided by each node's shell to the node (and its handles) inside\nexport interface FlowNodeState {\n id: string\n node: ComputedRef<FlowNode>\n selected: ComputedRef<boolean>\n dragging: ComputedRef<boolean>\n}\nexport const FLOW_NODE_KEY: InjectionKey<FlowNodeState> = Symbol('m3-flow-node')\n\n/**\n * The enclosing `<MFlow>`'s state and controls, from any component rendered inside it (a `#node-<type>` slot, a\n * panel of your own). Outside one, use MFlow's template ref, which exposes the same.\n */\nexport function useFlow(): FlowContext {\n const ctx = inject(FLOW_KEY, null)\n if (!ctx) throw new Error('useFlow() must be called inside <MFlow>')\n return ctx\n}\n\n/** The node a component is rendered in (inside a `#node-<type>` slot), or null */\nexport function useFlowNode() {\n return inject(FLOW_NODE_KEY, null)\n}\n","// Automatic layouts for MFlow, without dependencies: a tidy tree (org charts, mind maps) and a layered layout for\n// directed graphs (workflows, pipelines; the Sugiyama method, simplified). Pure functions over nodes, edges and\n// sizes that return positions, so a layout of your own (dagre, elkjs) can take their place: anything with the\n// `FlowLayout` signature.\nimport type { FlowEdge, FlowNode, FlowXY } from './useFlow'\n\nexport type FlowLayoutDirection = 'TB' | 'BT' | 'LR' | 'RL'\n\nexport interface FlowLayoutOptions {\n /** TB (top to bottom, the default for a vertical MFlow), BT, LR (default for a horizontal one) or RL */\n direction?: FlowLayoutDirection\n /** Space between neighbors in a level, px (default 40) */\n gap?: number\n /** Space between levels, px (default 80) */\n levelGap?: number\n /** Node sizes; MFlow passes the measured ones */\n sizes?: Map<string, { width: number; height: number }> | Record<string, { width: number; height: number }>\n /** Size of a node missing from `sizes` (default 180 × 60) */\n defaultSize?: { width: number; height: number }\n}\n\n/** Top left corners by node id */\nexport type FlowLayoutResult = Record<string, FlowXY>\n\n/** A layout: MFlow's `layout` prop and `layout()` take one */\nexport type FlowLayout = (\n nodes: FlowNode[],\n edges: FlowEdge[],\n options: FlowLayoutOptions & { sizes: Map<string, { width: number; height: number }>; direction: FlowLayoutDirection },\n) => FlowLayoutResult | Promise<FlowLayoutResult>\n\ninterface Prepared {\n ids: string[]\n size: (id: string) => { breadth: number; depth: number; width: number; height: number }\n out: Map<string, string[]>\n inc: Map<string, string[]>\n horizontal: boolean\n reversed: boolean\n gap: number\n levelGap: number\n}\n\n// Top-level, visible nodes only; edges into a group's children count as edges into the group\nfunction prepare(nodes: FlowNode[], edges: FlowEdge[], o: FlowLayoutOptions): Prepared {\n const byId = new Map(nodes.map((n) => [n.id, n]))\n const top = (id: string) => {\n let n = byId.get(id)\n for (let i = 0; n?.parentId && i < 100; i++) n = byId.get(n.parentId)\n return n\n }\n const ids = nodes.filter((n) => !n.parentId && !n.hidden).map((n) => n.id)\n const keep = new Set(ids)\n const out = new Map<string, string[]>(ids.map((id) => [id, []]))\n const inc = new Map<string, string[]>(ids.map((id) => [id, []]))\n for (const e of edges) {\n if (e.hidden) continue\n const s = top(e.source)?.id\n const t = top(e.target)?.id\n if (!s || !t || s === t || !keep.has(s) || !keep.has(t)) continue\n if (out.get(s)!.includes(t)) continue\n out.get(s)!.push(t)\n inc.get(t)!.push(s)\n }\n const dir = o.direction ?? 'TB'\n const horizontal = dir === 'LR' || dir === 'RL'\n const sizes = o.sizes instanceof Map ? o.sizes : new Map(Object.entries(o.sizes ?? {}))\n const def = o.defaultSize ?? { width: 180, height: 60 }\n return {\n ids,\n size: (id) => {\n const s = sizes.get(id) ?? (byId.get(id)?.width && byId.get(id)?.height ? { width: byId.get(id)!.width!, height: byId.get(id)!.height! } : def)\n return { ...s, breadth: horizontal ? s.height : s.width, depth: horizontal ? s.width : s.height }\n },\n out,\n inc,\n horizontal,\n reversed: dir === 'BT' || dir === 'RL',\n gap: o.gap ?? 40,\n levelGap: o.levelGap ?? 80,\n }\n}\n\n// Breadth/depth coordinates (centers along the level, the level's start) → top left corners\nfunction place(p: Prepared, along: Map<string, number>, level: Map<string, number>): FlowLayoutResult {\n const levels = Math.max(0, ...level.values()) + 1\n const depthOf = Array<number>(levels).fill(0)\n for (const id of p.ids) depthOf[level.get(id)!] = Math.max(depthOf[level.get(id)!]!, p.size(id).depth)\n const start: number[] = []\n let acc = 0\n for (let l = 0; l < levels; l++) {\n start.push(acc)\n acc += depthOf[l]! + p.levelGap\n }\n const total = acc - p.levelGap\n const res: FlowLayoutResult = {}\n for (const id of p.ids) {\n const s = p.size(id)\n const l = level.get(id)!\n // Centered within its level's band\n let d = start[l]! + (depthOf[l]! - s.depth) / 2\n if (p.reversed) d = total - d - s.depth\n const b = along.get(id)! - s.breadth / 2\n res[id] = p.horizontal ? { x: d, y: b } : { x: b, y: d }\n }\n return res\n}\n\n/**\n * A tidy tree: each parent centered over its children, every subtree side by side without overlapping, levels\n * aligned. Roots are the nodes nothing points to (in the nodes' order); a child's place among its siblings\n * follows the edges' order. Extra parents and cycles are ignored (a node goes under the first parent reached).\n */\nexport function layoutTree(nodes: FlowNode[], edges: FlowEdge[], options: FlowLayoutOptions = {}): FlowLayoutResult {\n const p = prepare(nodes, edges, options)\n const children = new Map<string, string[]>()\n const seen = new Set<string>()\n const roots = p.ids.filter((id) => !p.inc.get(id)!.length)\n // A graph that's all cycles still needs a root\n if (!roots.length && p.ids.length) roots.push(p.ids[0]!)\n const level = new Map<string, number>()\n const queue: string[] = []\n const visit = (r: string) => {\n if (seen.has(r)) return\n seen.add(r)\n level.set(r, 0)\n queue.push(r)\n while (queue.length) {\n const id = queue.shift()!\n const kids: string[] = []\n for (const c of p.out.get(id)!) {\n if (seen.has(c)) continue\n seen.add(c)\n level.set(c, level.get(id)! + 1)\n kids.push(c)\n queue.push(c)\n }\n children.set(id, kids)\n }\n }\n roots.forEach(visit)\n // Whatever only a cycle reaches becomes a root of its own\n for (const id of p.ids) if (!seen.has(id)) { roots.push(id); visit(id) }\n\n const width = new Map<string, number>()\n const measure = (id: string): number => {\n const kids = children.get(id)!\n const kidsW = kids.reduce((s, c) => s + measure(c), 0) + Math.max(0, kids.length - 1) * p.gap\n const w = Math.max(p.size(id).breadth, kidsW)\n width.set(id, w)\n return w\n }\n const along = new Map<string, number>()\n const assign = (id: string, left: number) => {\n const w = width.get(id)!\n along.set(id, left + w / 2)\n const kids = children.get(id)!\n const kidsW = kids.reduce((s, c) => s + width.get(c)!, 0) + Math.max(0, kids.length - 1) * p.gap\n let x = left + (w - kidsW) / 2\n for (const c of kids) {\n assign(c, x)\n x += width.get(c)! + p.gap\n }\n }\n let x = 0\n for (const r of roots) {\n measure(r)\n assign(r, x)\n x += width.get(r)! + p.gap * 2\n }\n return place(p, along, level)\n}\n\n/**\n * A layered layout for directed graphs: every edge points one level onwards where it can (longest path from the\n * sources), the order within a level reduces crossings (barycenter sweeps), and nodes line up with what they're\n * connected to without overlapping. Edges that close a cycle are laid out as if reversed.\n */\nexport function layoutLayered(nodes: FlowNode[], edges: FlowEdge[], options: FlowLayoutOptions = {}): FlowLayoutResult {\n const p = prepare(nodes, edges, options)\n // Break cycles: drop edges back to a node still on the DFS stack\n const state = new Map<string, 0 | 1 | 2>()\n const fwd = new Map<string, string[]>(p.ids.map((id) => [id, []]))\n const dfs = (id: string) => {\n state.set(id, 1)\n for (const t of p.out.get(id)!) {\n if (state.get(t) === 1) continue\n fwd.get(id)!.push(t)\n if (!state.get(t)) dfs(t)\n }\n state.set(id, 2)\n }\n const sources = p.ids.filter((id) => !p.inc.get(id)!.length)\n for (const id of [...sources, ...p.ids]) if (!state.get(id)) dfs(id)\n const back = new Map<string, string[]>(p.ids.map((id) => [id, []]))\n for (const [s, ts] of fwd) for (const t of ts) back.get(t)!.push(s)\n\n // Longest path layering, in topological order\n const level = new Map<string, number>()\n const indeg = new Map(p.ids.map((id) => [id, back.get(id)!.length]))\n const queue = p.ids.filter((id) => !indeg.get(id))\n while (queue.length) {\n const id = queue.shift()!\n if (!level.has(id)) level.set(id, 0)\n for (const t of fwd.get(id)!) {\n level.set(t, Math.max(level.get(t) ?? 0, level.get(id)! + 1))\n indeg.set(t, indeg.get(t)! - 1)\n if (!indeg.get(t)) queue.push(t)\n }\n }\n // Pull sources down next to what they feed (a lone input right before its consumer)\n for (const id of p.ids) {\n if (back.get(id)!.length || !fwd.get(id)!.length) continue\n level.set(id, Math.min(...fwd.get(id)!.map((t) => level.get(t)!)) - 1)\n }\n const levels: string[][] = []\n for (const id of p.ids) (levels[level.get(id)!] ??= []).push(id)\n for (let l = 0; l < levels.length; l++) levels[l] ??= []\n\n // An edge across several levels gets a placeholder in each level between, so the ordering and the spacing\n // keep a lane open for it instead of running it underneath the nodes in between\n const dummies = new Set<string>()\n for (const [s, ts] of [...fwd]) {\n for (const t of [...ts]) {\n const ls = level.get(s)!\n const lt = level.get(t)!\n if (lt - ls <= 1) continue\n ts.splice(ts.indexOf(t), 1)\n let prev = s\n for (let l = ls + 1; l < lt; l++) {\n const d = `\\u0000${s}>${t}#${l}`\n dummies.add(d)\n level.set(d, l)\n levels[l]!.push(d)\n fwd.set(d, [])\n back.set(d, [prev])\n fwd.get(prev)!.push(d)\n prev = d\n }\n fwd.get(prev)!.push(t)\n back.set(t, back.get(t)!.map((x) => (x === s ? prev : x)))\n }\n }\n const LANE = 8\n const sizeOf = (id: string) => (dummies.has(id) ? { breadth: LANE, depth: 0 } : p.size(id))\n\n // Crossing reduction: order each level by the mean position of its neighbors in the previous one\n const pos = new Map<string, number>()\n const index = () => levels.forEach((ids) => ids.forEach((id, i) => pos.set(id, i)))\n index()\n const sweep = (down: boolean) => {\n const range = down ? levels.map((_, i) => i).slice(1) : levels.map((_, i) => i).reverse().slice(1)\n for (const l of range) {\n const nb = down ? back : fwd\n const bary = new Map(levels[l]!.map((id) => {\n const ns = nb.get(id)!\n return [id, ns.length ? ns.reduce((s, n) => s + pos.get(n)!, 0) / ns.length : pos.get(id)!]\n }))\n levels[l]!.sort((a, b) => bary.get(a)! - bary.get(b)!)\n levels[l]!.forEach((id, i) => pos.set(id, i))\n }\n }\n for (let i = 0; i < 4; i++) { sweep(true); sweep(false) }\n\n // Coordinates along the level: packed first, then pulled toward their neighbors' centers, keeping the order\n const along = new Map<string, number>()\n for (const ids of levels) {\n let x = 0\n for (const id of ids) {\n const b = sizeOf(id).breadth\n along.set(id, x + b / 2)\n x += b + p.gap\n }\n }\n const relax = (ids: string[], nb: Map<string, string[]>) => {\n const want = ids.map((id) => {\n const ns = nb.get(id)!\n return ns.length ? ns.reduce((s, n) => s + along.get(n)!, 0) / ns.length : along.get(id)!\n })\n // Where each wants to be, never closer than the gap to its neighbor: pushed rightwards in one pass and\n // leftwards in another, then averaged (both keep the spacing, so their mean does too, without drifting)\n const space = (i: number) => sizeOf(ids[i]!).breadth / 2 + p.gap + sizeOf(ids[i + 1]!).breadth / 2\n const right = [...want]\n for (let i = 1; i < ids.length; i++) right[i] = Math.max(right[i]!, right[i - 1]! + space(i - 1))\n const left = [...want]\n for (let i = ids.length - 2; i >= 0; i--) left[i] = Math.min(left[i]!, left[i + 1]! - space(i))\n ids.forEach((id, i) => along.set(id, (right[i]! + left[i]!) / 2))\n }\n for (let it = 0; it < 3; it++) {\n for (let l = 1; l < levels.length; l++) relax(levels[l]!, back)\n for (let l = levels.length - 2; l >= 0; l--) relax(levels[l]!, fwd)\n }\n // Start at 0\n let min = Infinity\n for (const id of p.ids) min = Math.min(min, along.get(id)! - p.size(id).breadth / 2)\n if (Number.isFinite(min)) for (const id of p.ids) along.set(id, along.get(id)! - min)\n return place(p, along, level)\n}\n","// Renders a slot function handed down as a prop (MFlow passes its `#node-<type>`/`#edge-<type>` slots to the\n// internal components that draw each node and edge)\nimport type { FunctionalComponent, Slot } from 'vue'\n\nexport const SlotOutlet: FunctionalComponent<{ fn: Slot; scope: Record<string, unknown> }> = (p) => p.fn(p.scope)\nSlotOutlet.props = ['fn', 'scope']\n","<script setup lang=\"ts\">\n/**\n * A connection point on a node in MFlow: drag from it to another node's handle to connect them. Sits centered on\n * its node's side (`position`); move it with your own classes or style (it's measured where it ends up). Give\n * each an `id` when a node has several of a type. Only inside a node (MFlowNode, or a `#node-<type>` slot).\n */\nimport { computed, inject, onBeforeUnmount, onMounted, ref } from 'vue'\nimport { FLOW_KEY, FLOW_NODE_KEY, type FlowPosition } from '../composables/useFlow'\n\nconst props = withDefaults(defineProps<{\n /** `source`: edges leave from it; `target`: they arrive */\n type?: 'source' | 'target'\n position?: FlowPosition\n id?: string\n connectable?: boolean\n}>(), {\n type: 'source',\n position: undefined,\n id: undefined,\n connectable: true,\n})\n\nconst flow = inject(FLOW_KEY, null)\nconst state = inject(FLOW_NODE_KEY, null)\nconst el = ref<HTMLElement>()\nconst side = computed<FlowPosition>(() => props.position ?? (props.type === 'source' ? (flow?.direction.value === 'vertical' ? 'bottom' : 'right') : (flow?.direction.value === 'vertical' ? 'top' : 'left')))\nconst canConnect = computed(() => props.connectable && !!flow?.nodesConnectable.value && state?.node.value.connectable !== false)\nconst key = computed(() => `${state?.id}:${props.id ?? ''}:${props.type}`)\nconst candidate = computed(() => flow?.connectionTarget.value?.key === key.value ? flow.connectionTarget.value : null)\n\nconst PLACE: Record<FlowPosition, string> = {\n top: 'top-0 left-1/2 -translate-x-1/2 -translate-y-1/2',\n right: 'top-1/2 right-0 translate-x-1/2 -translate-y-1/2',\n bottom: 'bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2',\n left: 'top-1/2 left-0 -translate-x-1/2 -translate-y-1/2',\n}\n\nlet unregister: (() => void) | undefined\nonMounted(() => {\n if (!flow || !state) return\n unregister = flow.registerHandle(state.id, el.value!, () => ({ id: props.id ?? null, type: props.type, position: side.value, connectable: canConnect.value }))\n})\nonBeforeUnmount(() => unregister?.())\n</script>\n\n<template>\n <div\n ref=\"el\"\n class=\"m3-flow-handle absolute z-10 size-2.5 rounded-full border-2 transition-[background-color,border-color,scale,opacity] duration-150 before:absolute before:-inset-2.5 before:rounded-full\"\n :class=\"[\n PLACE[side],\n candidate ? (candidate.valid ? 'scale-150 border-primary bg-primary' : 'scale-125 border-error bg-error-container') : 'border-outline bg-surface',\n canConnect ? 'cursor-crosshair hover:scale-125 hover:border-primary' : 'opacity-0',\n ]\"\n :data-flow-handle=\"type\"\n :data-handle-id=\"id\"\n :data-flow-connectable=\"canConnect\"\n aria-hidden=\"true\"\n />\n</template>\n","<script setup lang=\"ts\">\n/**\n * A connection point on a node in MFlow: drag from it to another node's handle to connect them. Sits centered on\n * its node's side (`position`); move it with your own classes or style (it's measured where it ends up). Give\n * each an `id` when a node has several of a type. Only inside a node (MFlowNode, or a `#node-<type>` slot).\n */\nimport { computed, inject, onBeforeUnmount, onMounted, ref } from 'vue'\nimport { FLOW_KEY, FLOW_NODE_KEY, type FlowPosition } from '../composables/useFlow'\n\nconst props = withDefaults(defineProps<{\n /** `source`: edges leave from it; `target`: they arrive */\n type?: 'source' | 'target'\n position?: FlowPosition\n id?: string\n connectable?: boolean\n}>(), {\n type: 'source',\n position: undefined,\n id: undefined,\n connectable: true,\n})\n\nconst flow = inject(FLOW_KEY, null)\nconst state = inject(FLOW_NODE_KEY, null)\nconst el = ref<HTMLElement>()\nconst side = computed<FlowPosition>(() => props.position ?? (props.type === 'source' ? (flow?.direction.value === 'vertical' ? 'bottom' : 'right') : (flow?.direction.value === 'vertical' ? 'top' : 'left')))\nconst canConnect = computed(() => props.connectable && !!flow?.nodesConnectable.value && state?.node.value.connectable !== false)\nconst key = computed(() => `${state?.id}:${props.id ?? ''}:${props.type}`)\nconst candidate = computed(() => flow?.connectionTarget.value?.key === key.value ? flow.connectionTarget.value : null)\n\nconst PLACE: Record<FlowPosition, string> = {\n top: 'top-0 left-1/2 -translate-x-1/2 -translate-y-1/2',\n right: 'top-1/2 right-0 translate-x-1/2 -translate-y-1/2',\n bottom: 'bottom-0 left-1/2 -translate-x-1/2 translate-y-1/2',\n left: 'top-1/2 left-0 -translate-x-1/2 -translate-y-1/2',\n}\n\nlet unregister: (() => void) | undefined\nonMounted(() => {\n if (!flow || !state) return\n unregister = flow.registerHandle(state.id, el.value!, () => ({ id: props.id ?? null, type: props.type, position: side.value, connectable: canConnect.value }))\n})\nonBeforeUnmount(() => unregister?.())\n</script>\n\n<template>\n <div\n ref=\"el\"\n class=\"m3-flow-handle absolute z-10 size-2.5 rounded-full border-2 transition-[background-color,border-color,scale,opacity] duration-150 before:absolute before:-inset-2.5 before:rounded-full\"\n :class=\"[\n PLACE[side],\n candidate ? (candidate.valid ? 'scale-150 border-primary bg-primary' : 'scale-125 border-error bg-error-container') : 'border-outline bg-surface',\n canConnect ? 'cursor-crosshair hover:scale-125 hover:border-primary' : 'opacity-0',\n ]\"\n :data-flow-handle=\"type\"\n :data-handle-id=\"id\"\n :data-flow-connectable=\"canConnect\"\n aria-hidden=\"true\"\n />\n</template>\n","<script setup lang=\"ts\">\n/**\n * MFlow's default node, also for `#node-<type>` slots of your own: an M3 card with an icon, a label and a\n * subtitle, and a handle on each side edges run through (target where they arrive, source where they leave; the\n * sides follow MFlow's `direction` or the node's `sourcePosition`/`targetPosition`). Selected it gets a primary\n * outline; lifted while dragged (elevation level 4, like MKanban's cards). Not an M3 spec component.\n *\n * @slot default Below the header, inside the card\n * @slot icon Instead of the `icon`\n * @slot trailing At the end of the header (a status, a menu button). Controls in it don't start a drag\n */\nimport { computed, inject } from 'vue'\nimport { FLOW_KEY, FLOW_NODE_KEY, type FlowPosition } from '../composables/useFlow'\nimport MFlowHandle from './MFlowHandle.vue'\n\nconst props = withDefaults(defineProps<{\n label?: string\n subtitle?: string\n /** Material Symbol */\n icon?: string\n variant?: 'outlined' | 'filled' | 'elevated'\n /** The icon container's color role */\n color?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'neutral'\n /** Which handles it draws */\n handles?: 'both' | 'source' | 'target' | 'none'\n sourcePosition?: FlowPosition\n targetPosition?: FlowPosition\n}>(), {\n variant: 'outlined',\n color: 'primary',\n handles: 'both',\n})\n\nconst flow = inject(FLOW_KEY, null)\nconst state = inject(FLOW_NODE_KEY, null)\nconst selected = computed(() => state?.selected.value ?? false)\nconst dragging = computed(() => state?.dragging.value ?? false)\nconst sides = computed(() => {\n const n = state?.node.value\n const d = n && flow ? flow.sidePositions(n) : { source: 'right' as FlowPosition, target: 'left' as FlowPosition }\n return { source: props.sourcePosition ?? d.source, target: props.targetPosition ?? d.target }\n})\n\nconst VARIANT = {\n outlined: 'bg-surface border-outline-variant',\n filled: 'bg-surface-container-highest border-transparent',\n elevated: 'bg-surface-container-low border-transparent shadow-elevation-1',\n}\nconst ICON = {\n primary: 'bg-primary-container text-on-primary-container',\n secondary: 'bg-secondary-container text-on-secondary-container',\n tertiary: 'bg-tertiary-container text-on-tertiary-container',\n error: 'bg-error-container text-on-error-container',\n neutral: 'bg-surface-container-highest text-on-surface-variant',\n}\n</script>\n\n<template>\n <div\n class=\"m3-flow-card rounded-md border text-on-surface transition-[box-shadow,border-color] duration-200\"\n :class=\"[\n VARIANT[variant],\n selected && 'border-primary! ring-1 ring-primary',\n dragging ? 'shadow-elevation-4!' : variant === 'elevated' ? 'hover:shadow-elevation-2' : 'hover:shadow-elevation-1',\n ]\"\n >\n <div class=\"flex items-center gap-3 p-3\">\n <slot name=\"icon\">\n <span v-if=\"icon\" class=\"flex size-10 shrink-0 items-center justify-center rounded-sm\" :class=\"ICON[color]\">\n <span class=\"material-symbols-outlined text-[24px]\" aria-hidden=\"true\">{{ icon }}</span>\n </span>\n </slot>\n <div class=\"min-w-0 flex-1\">\n <div v-if=\"label\" class=\"truncate text-title-small\">{{ label }}</div>\n <div v-if=\"subtitle\" class=\"truncate text-body-small text-on-surface-variant\">{{ subtitle }}</div>\n </div>\n <div v-if=\"$slots.trailing\" class=\"shrink-0\" data-flow-nodrag>\n <slot name=\"trailing\" />\n </div>\n </div>\n <div v-if=\"$slots.default\" class=\"px-3 pb-3\">\n <slot />\n </div>\n <MFlowHandle v-if=\"state && (handles === 'both' || handles === 'target')\" type=\"target\" :position=\"sides.target\" />\n <MFlowHandle v-if=\"state && (handles === 'both' || handles === 'source')\" type=\"source\" :position=\"sides.source\" />\n </div>\n</template>\n\n<style>\n/* Defaults in the base layer, so a width or position class of yours on the node wins */\n@layer base {\n .m3-flow-card {\n position: relative;\n min-width: 11rem;\n max-width: 18rem;\n }\n}\n</style>\n","<script setup lang=\"ts\">\n/**\n * MFlow's default node, also for `#node-<type>` slots of your own: an M3 card with an icon, a label and a\n * subtitle, and a handle on each side edges run through (target where they arrive, source where they leave; the\n * sides follow MFlow's `direction` or the node's `sourcePosition`/`targetPosition`). Selected it gets a primary\n * outline; lifted while dragged (elevation level 4, like MKanban's cards). Not an M3 spec component.\n *\n * @slot default Below the header, inside the card\n * @slot icon Instead of the `icon`\n * @slot trailing At the end of the header (a status, a menu button). Controls in it don't start a drag\n */\nimport { computed, inject } from 'vue'\nimport { FLOW_KEY, FLOW_NODE_KEY, type FlowPosition } from '../composables/useFlow'\nimport MFlowHandle from './MFlowHandle.vue'\n\nconst props = withDefaults(defineProps<{\n label?: string\n subtitle?: string\n /** Material Symbol */\n icon?: string\n variant?: 'outlined' | 'filled' | 'elevated'\n /** The icon container's color role */\n color?: 'primary' | 'secondary' | 'tertiary' | 'error' | 'neutral'\n /** Which handles it draws */\n handles?: 'both' | 'source' | 'target' | 'none'\n sourcePosition?: FlowPosition\n targetPosition?: FlowPosition\n}>(), {\n variant: 'outlined',\n color: 'primary',\n handles: 'both',\n})\n\nconst flow = inject(FLOW_KEY, null)\nconst state = inject(FLOW_NODE_KEY, null)\nconst selected = computed(() => state?.selected.value ?? false)\nconst dragging = computed(() => state?.dragging.value ?? false)\nconst sides = computed(() => {\n const n = state?.node.value\n const d = n && flow ? flow.sidePositions(n) : { source: 'right' as FlowPosition, target: 'left' as FlowPosition }\n return { source: props.sourcePosition ?? d.source, target: props.targetPosition ?? d.target }\n})\n\nconst VARIANT = {\n outlined: 'bg-surface border-outline-variant',\n filled: 'bg-surface-container-highest border-transparent',\n elevated: 'bg-surface-container-low border-transparent shadow-elevation-1',\n}\nconst ICON = {\n primary: 'bg-primary-container text-on-primary-container',\n secondary: 'bg-secondary-container text-on-secondary-container',\n tertiary: 'bg-tertiary-container text-on-tertiary-container',\n error: 'bg-error-container text-on-error-container',\n neutral: 'bg-surface-container-highest text-on-surface-variant',\n}\n</script>\n\n<template>\n <div\n class=\"m3-flow-card rounded-md border text-on-surface transition-[box-shadow,border-color] duration-200\"\n :class=\"[\n VARIANT[variant],\n selected && 'border-primary! ring-1 ring-primary',\n dragging ? 'shadow-elevation-4!' : variant === 'elevated' ? 'hover:shadow-elevation-2' : 'hover:shadow-elevation-1',\n ]\"\n >\n <div class=\"flex items-center gap-3 p-3\">\n <slot name=\"icon\">\n <span v-if=\"icon\" class=\"flex size-10 shrink-0 items-center justify-center rounded-sm\" :class=\"ICON[color]\">\n <span class=\"material-symbols-outlined text-[24px]\" aria-hidden=\"true\">{{ icon }}</span>\n </span>\n </slot>\n <div class=\"min-w-0 flex-1\">\n <div v-if=\"label\" class=\"truncate text-title-small\">{{ label }}</div>\n <div v-if=\"subtitle\" class=\"truncate text-body-small text-on-surface-variant\">{{ subtitle }}</div>\n </div>\n <div v-if=\"$slots.trailing\" class=\"shrink-0\" data-flow-nodrag>\n <slot name=\"trailing\" />\n </div>\n </div>\n <div v-if=\"$slots.default\" class=\"px-3 pb-3\">\n <slot />\n </div>\n <MFlowHandle v-if=\"state && (handles === 'both' || handles === 'target')\" type=\"target\" :position=\"sides.target\" />\n <MFlowHandle v-if=\"state && (handles === 'both' || handles === 'source')\" type=\"source\" :position=\"sides.source\" />\n </div>\n</template>\n\n<style>\n/* Defaults in the base layer, so a width or position class of yours on the node wins */\n@layer base {\n .m3-flow-card {\n position: relative;\n min-width: 11rem;\n max-width: 18rem;\n }\n}\n</style>\n","<script setup lang=\"ts\">\n// One node on MFlow's canvas: positions it, reports its size, and draws it (a `#node-<type>` slot, a group box or\n// an MFlowNode). Pointer gestures are MFlow's, found through `data-flow-node`.\nimport { computed, inject, onBeforeUnmount, onMounted, provide, ref, type Slot } from 'vue'\nimport { FLOW_KEY, FLOW_NODE_KEY, type FlowNode } from '../composables/useFlow'\nimport { SlotOutlet } from '../composables/_flowSlot'\nimport { useLocale } from '../composables/useLocale'\nimport MFlowNode from './MFlowNode.vue'\nimport MFlowHandle from './MFlowHandle.vue'\nimport type { FlowCircleData } from '../composables/useFlow'\n\nconst props = defineProps<{ node: FlowNode; render?: Slot }>()\n\nconst flow = inject(FLOW_KEY)!\nconst locale = useLocale()\nconst el = ref<HTMLElement>()\nconst id = props.node.id\n\nconst node = computed(() => props.node)\nconst selected = computed(() => flow.selectedNodes.value.has(id))\nconst dragging = computed(() => flow.isLifted(id))\nprovide(FLOW_NODE_KEY, { id, node, selected, dragging })\n\nconst isGroup = computed(() => props.node.type === 'group')\nconst data = computed(() => (props.node.data ?? {}) as { label?: string; subtitle?: string; icon?: string })\nconst pos = computed(() => flow.getAbsolutePosition(id))\nconst box = computed(() => {\n // A group without a size follows its children; other nodes take a size only when given one\n if (isGroup.value) return flow.getSize(id)\n return { width: props.node.width, height: props.node.height }\n})\nconst handlesFor = computed(() => {\n switch (props.node.type) {\n case 'input': return 'source'\n case 'output': return 'target'\n default: return 'both'\n }\n})\n// A circle node's look\nconst circle = computed(() => {\n const d = (props.node.data ?? {}) as FlowCircleData\n return { size: d.size ?? 56, color: d.color ?? 'neutral', badge: d.badge, ring: d.ring }\n})\nconst CIRCLE_TONE = {\n primary: 'bg-primary-container text-on-primary-container',\n secondary: 'bg-secondary-container text-on-secondary-container',\n tertiary: 'bg-tertiary-container text-on-tertiary-container',\n error: 'bg-error-container text-on-error-container',\n neutral: 'bg-surface-container-highest text-on-surface',\n inverse: 'bg-inverse-surface text-inverse-on-surface',\n}\nconst RING = {\n primary: 'ring-4 ring-primary/35',\n secondary: 'ring-4 ring-secondary/35',\n tertiary: 'ring-4 ring-tertiary/35',\n error: 'ring-4 ring-error/35',\n}\nconst draggable = computed(() => props.node.draggable !== false && !flow.locked.value)\n\nonMounted(() => flow.registerNodeEl(id, el.value!))\nonBeforeUnmount(() => flow.registerNodeEl(id, null))\n</script>\n\n<template>\n <div\n ref=\"el\"\n class=\"m3-flow-node absolute top-0 left-0 rounded-md outline-none focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-secondary\"\n :class=\"[node.class, draggable && (dragging ? 'cursor-grabbing' : 'cursor-grab')]\"\n :style=\"{\n transform: `translate(${pos.x}px, ${pos.y}px)`,\n zIndex: flow.zIndexOf(id),\n width: box.width ? `${box.width}px` : undefined,\n height: box.height ? `${box.height}px` : undefined,\n }\"\n :data-flow-node=\"id\"\n :data-selected=\"selected || undefined\"\n :data-dragging=\"dragging || undefined\"\n tabindex=\"0\"\n role=\"group\"\n :aria-roledescription=\"locale.flowNode\"\n :aria-label=\"data.label ?? id\"\n @keydown=\"flow.onNodeKey($event, id)\"\n >\n <SlotOutlet v-if=\"render\" :fn=\"render\" :scope=\"{ node, data: node.data, selected, dragging }\" />\n <div\n v-else-if=\"isGroup\"\n class=\"size-full rounded-lg border bg-surface-container-low/70 transition-colors\"\n :class=\"selected ? 'border-primary' : 'border-outline-variant'\"\n >\n <div v-if=\"data.label\" class=\"flex h-9 items-center gap-2 px-3 text-label-large text-on-surface-variant\">\n <span v-if=\"data.icon\" class=\"material-symbols-outlined text-[18px]\">{{ data.icon }}</span>\n {{ data.label }}\n </div>\n </div>\n <div v-else-if=\"node.type === 'circle'\" class=\"relative\" :style=\"{ width: `${circle.size}px`, height: `${circle.size}px` }\">\n <div\n class=\"m3-flow-circle flex size-full items-center justify-center rounded-full border-2 text-title-small\"\n :class=\"[CIRCLE_TONE[circle.color], selected ? 'border-primary' : 'border-transparent', circle.ring && RING[circle.ring]]\"\n >\n <span class=\"truncate px-1\">{{ data.label }}</span>\n </div>\n <span\n v-if=\"circle.badge !== undefined && circle.badge !== null && circle.badge !== ''\"\n class=\"absolute -top-1.5 -right-1.5 flex h-6 min-w-6 items-center justify-center rounded-full bg-tertiary px-1.5 text-label-small text-on-tertiary shadow-elevation-1\"\n >{{ circle.badge }}</span>\n <!-- Edges leave from the rim's handle; they arrive anywhere on the circle (drop a connection on it) -->\n <MFlowHandle type=\"source\" position=\"right\" />\n </div>\n <MFlowNode v-else :label=\"data.label ?? id\" :subtitle=\"data.subtitle\" :icon=\"data.icon\" :handles=\"handlesFor\" />\n </div>\n</template>\n","<script setup lang=\"ts\">\n// One node on MFlow's canvas: positions it, reports its size, and draws it (a `#node-<type>` slot, a group box or\n// an MFlowNode). Pointer gestures are MFlow's, found through `data-flow-node`.\nimport { computed, inject, onBeforeUnmount, onMounted, provide, ref, type Slot } from 'vue'\nimport { FLOW_KEY, FLOW_NODE_KEY, type FlowNode } from '../composables/useFlow'\nimport { SlotOutlet } from '../composables/_flowSlot'\nimport { useLocale } from '../composables/useLocale'\nimport MFlowNode from './MFlowNode.vue'\nimport MFlowHandle from './MFlowHandle.vue'\nimport type { FlowCircleData } from '../composables/useFlow'\n\nconst props = defineProps<{ node: FlowNode; render?: Slot }>()\n\nconst flow = inject(FLOW_KEY)!\nconst locale = useLocale()\nconst el = ref<HTMLElement>()\nconst id = props.node.id\n\nconst node = computed(() => props.node)\nconst selected = computed(() => flow.selectedNodes.value.has(id))\nconst dragging = computed(() => flow.isLifted(id))\nprovide(FLOW_NODE_KEY, { id, node, selected, dragging })\n\nconst isGroup = computed(() => props.node.type === 'group')\nconst data = computed(() => (props.node.data ?? {}) as { label?: string; subtitle?: string; icon?: string })\nconst pos = computed(() => flow.getAbsolutePosition(id))\nconst box = computed(() => {\n // A group without a size follows its children; other nodes take a size only when given one\n if (isGroup.value) return flow.getSize(id)\n return { width: props.node.width, height: props.node.height }\n})\nconst handlesFor = computed(() => {\n switch (props.node.type) {\n case 'input': return 'source'\n case 'output': return 'target'\n default: return 'both'\n }\n})\n// A circle node's look\nconst circle = computed(() => {\n const d = (props.node.data ?? {}) as FlowCircleData\n return { size: d.size ?? 56, color: d.color ?? 'neutral', badge: d.badge, ring: d.ring }\n})\nconst CIRCLE_TONE = {\n primary: 'bg-primary-container text-on-primary-container',\n secondary: 'bg-secondary-container text-on-secondary-container',\n tertiary: 'bg-tertiary-container text-on-tertiary-container',\n error: 'bg-error-container text-on-error-container',\n neutral: 'bg-surface-container-highest text-on-surface',\n inverse: 'bg-inverse-surface text-inverse-on-surface',\n}\nconst RING = {\n primary: 'ring-4 ring-primary/35',\n secondary: 'ring-4 ring-secondary/35',\n tertiary: 'ring-4 ring-tertiary/35',\n error: 'ring-4 ring-error/35',\n}\nconst draggable = computed(() => props.node.draggable !== false && !flow.locked.value)\n\nonMounted(() => flow.registerNodeEl(id, el.value!))\nonBeforeUnmount(() => flow.registerNodeEl(id, null))\n</script>\n\n<template>\n <div\n ref=\"el\"\n class=\"m3-flow-node absolute top-0 left-0 rounded-md outline-none focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-secondary\"\n :class=\"[node.class, draggable && (dragging ? 'cursor-grabbing' : 'cursor-grab')]\"\n :style=\"{\n transform: `translate(${pos.x}px, ${pos.y}px)`,\n zIndex: flow.zIndexOf(id),\n width: box.width ? `${box.width}px` : undefined,\n height: box.height ? `${box.height}px` : undefined,\n }\"\n :data-flow-node=\"id\"\n :data-selected=\"selected || undefined\"\n :data-dragging=\"dragging || undefined\"\n tabindex=\"0\"\n role=\"group\"\n :aria-roledescription=\"locale.flowNode\"\n :aria-label=\"data.label ?? id\"\n @keydown=\"flow.onNodeKey($event, id)\"\n >\n <SlotOutlet v-if=\"render\" :fn=\"render\" :scope=\"{ node, data: node.data, selected, dragging }\" />\n <div\n v-else-if=\"isGroup\"\n class=\"size-full rounded-lg border bg-surface-container-low/70 transition-colors\"\n :class=\"selected ? 'border-primary' : 'border-outline-variant'\"\n >\n <div v-if=\"data.label\" class=\"flex h-9 items-center gap-2 px-3 text-label-large text-on-surface-variant\">\n <span v-if=\"data.icon\" class=\"material-symbols-outlined text-[18px]\">{{ data.icon }}</span>\n {{ data.label }}\n </div>\n </div>\n <div v-else-if=\"node.type === 'circle'\" class=\"relative\" :style=\"{ width: `${circle.size}px`, height: `${circle.size}px` }\">\n <div\n class=\"m3-flow-circle flex size-full items-center justify-center rounded-full border-2 text-title-small\"\n :class=\"[CIRCLE_TONE[circle.color], selected ? 'border-primary' : 'border-transparent', circle.ring && RING[circle.ring]]\"\n >\n <span class=\"truncate px-1\">{{ data.label }}</span>\n </div>\n <span\n v-if=\"circle.badge !== undefined && circle.badge !== null && circle.badge !== ''\"\n class=\"absolute -top-1.5 -right-1.5 flex h-6 min-w-6 items-center justify-center rounded-full bg-tertiary px-1.5 text-label-small text-on-tertiary shadow-elevation-1\"\n >{{ circle.badge }}</span>\n <!-- Edges leave from the rim's handle; they arrive anywhere on the circle (drop a connection on it) -->\n <MFlowHandle type=\"source\" position=\"right\" />\n </div>\n <MFlowNode v-else :label=\"data.label ?? id\" :subtitle=\"data.subtitle\" :icon=\"data.icon\" :handles=\"handlesFor\" />\n </div>\n</template>\n","<script setup lang=\"ts\">\n// One edge on MFlow's canvas, inside its shared <svg>: a wide invisible stroke to hit, the path (or an\n// `#edge-<type>` slot), arrowheads, and once selected the ends to drag elsewhere. Gestures are MFlow's, found\n// through `data-flow-edge` / `data-flow-reconnect`.\nimport { computed, inject, type Slot } from 'vue'\nimport { FLOW_KEY, type FlowEdge, type FlowMarker } from '../composables/useFlow'\nimport { arrowPath } from '../composables/flowPaths'\nimport { SlotOutlet } from '../composables/_flowSlot'\nimport { useLocale } from '../composables/useLocale'\n\nconst props = defineProps<{ edge: FlowEdge; render?: Slot }>()\n\nconst flow = inject(FLOW_KEY)!\nconst locale = useLocale()\nconst geo = computed(() => flow.edgeGeometry(props.edge))\nconst selected = computed(() => flow.selectedEdges.value.has(props.edge.id))\n// A dragged node would splice into it if dropped now\nconst highlighted = computed(() => flow.insertEdge.value === props.edge.id)\nconst selectable = computed(() => props.edge.selectable !== false && !flow.locked.value)\nconst reconnectable = computed(() => selected.value && flow.isReconnectable(props.edge))\n\nfunction marker(kind: FlowMarker | undefined, x: number, y: number, angle: number, inset: number) {\n if (!kind || kind === 'none') return ''\n return arrowPath(x - inset * Math.cos(angle), y - inset * Math.sin(angle), angle, 9, kind === 'arrow-closed')\n}\nconst markerEnd = computed(() => {\n const g = geo.value\n return g ? marker(props.edge.markerEnd ?? 'arrow-closed', g.targetX, g.targetY, g.targetAngle, g.targetInset) : ''\n})\nconst markerStart = computed(() => {\n const g = geo.value\n return g ? marker(props.edge.markerStart, g.sourceX, g.sourceY, g.sourceAngle + Math.PI, g.sourceInset) : ''\n})\nconst label = computed(() => {\n const name = (id: string) => String((flow.getNode(id)?.data as { label?: unknown } | undefined)?.label ?? id)\n return locale.flowEdge.replace('{source}', name(props.edge.source)).replace('{target}', name(props.edge.target))\n})\n// Declarative look: an M3 role reads its token, anything else is a CSS color\nconst ROLE = /^(primary|secondary|tertiary|error|outline|outline-variant|on-surface|on-surface-variant|inverse-surface|inverse-primary)(-container)?$/\nconst stroke = computed(() => {\n if (selected.value || highlighted.value) return 'var(--color-primary)'\n const c = props.edge.color\n return c ? (ROLE.test(c) ? `var(--color-${c})` : c) : 'var(--color-outline)'\n})\nconst width = computed(() => (props.edge.width ?? 2) + (highlighted.value ? 2 : 0))\nconst scope = computed(() => ({ edge: props.edge, selected: selected.value, highlighted: highlighted.value, ...geo.value }))\n</script>\n\n<template>\n <g\n v-if=\"geo\"\n class=\"m3-flow-edge outline-none\"\n :class=\"[edge.class, selected && 'm3-flow-edge-selected']\"\n :data-flow-edge=\"edge.id\"\n :tabindex=\"selectable ? 0 : undefined\"\n :aria-label=\"label\"\n role=\"img\"\n @keydown=\"flow.onEdgeKey($event, edge.id)\"\n >\n <path :d=\"geo.path\" fill=\"none\" stroke=\"transparent\" stroke-width=\"16\" :style=\"{ pointerEvents: 'stroke' }\" :class=\"flow.branching.value ? 'cursor-crosshair' : selectable && 'cursor-pointer'\" />\n <!-- A dragged node would splice in here: a halo around it -->\n <path v-if=\"highlighted\" :d=\"geo.path\" fill=\"none\" stroke-width=\"14\" stroke-linecap=\"round\" class=\"m3-flow-edge-halo stroke-primary/25\" />\n <SlotOutlet v-if=\"render\" :fn=\"render\" :scope=\"scope\" />\n <template v-else>\n <path\n :d=\"geo.path\"\n fill=\"none\"\n :stroke-width=\"width\"\n stroke-linecap=\"round\"\n class=\"m3-flow-edge-line\"\n :class=\"[edge.animated === 'reverse' ? 'm3-flow-edge-animated m3-flow-edge-reverse' : edge.animated && 'm3-flow-edge-animated', edge.dashed && !edge.animated && 'm3-flow-edge-dashed']\"\n :style=\"{ stroke, strokeWidth: `${width}px` }\"\n />\n <path\n v-for=\"(m, i) in [markerEnd, markerStart]\"\n v-show=\"m\"\n :key=\"i\"\n :d=\"m\"\n stroke-width=\"2\"\n stroke-linejoin=\"round\"\n stroke-linecap=\"round\"\n class=\"m3-flow-edge-line\"\n :style=\"{ stroke, fill: (i === 0 ? edge.markerEnd ?? 'arrow-closed' : edge.markerStart) === 'arrow-closed' ? stroke : 'none' }\"\n />\n </template>\n <template v-if=\"reconnectable\">\n <circle\n v-for=\"end in (['source', 'target'] as const)\"\n :key=\"end\"\n :data-flow-reconnect=\"end\"\n :cx=\"end === 'source' ? geo.sourceX : geo.targetX\"\n :cy=\"end === 'source' ? geo.sourceY : geo.targetY\"\n r=\"6\"\n stroke-width=\"2\"\n class=\"cursor-move fill-surface stroke-primary\"\n :style=\"{ pointerEvents: 'all' }\"\n />\n </template>\n </g>\n</template>\n","<script setup lang=\"ts\">\n// One edge on MFlow's canvas, inside its shared <svg>: a wide invisible stroke to hit, the path (or an\n// `#edge-<type>` slot), arrowheads, and once selected the ends to drag elsewhere. Gestures are MFlow's, found\n// through `data-flow-edge` / `data-flow-reconnect`.\nimport { computed, inject, type Slot } from 'vue'\nimport { FLOW_KEY, type FlowEdge, type FlowMarker } from '../composables/useFlow'\nimport { arrowPath } from '../composables/flowPaths'\nimport { SlotOutlet } from '../composables/_flowSlot'\nimport { useLocale } from '../composables/useLocale'\n\nconst props = defineProps<{ edge: FlowEdge; render?: Slot }>()\n\nconst flow = inject(FLOW_KEY)!\nconst locale = useLocale()\nconst geo = computed(() => flow.edgeGeometry(props.edge))\nconst selected = computed(() => flow.selectedEdges.value.has(props.edge.id))\n// A dragged node would splice into it if dropped now\nconst highlighted = computed(() => flow.insertEdge.value === props.edge.id)\nconst selectable = computed(() => props.edge.selectable !== false && !flow.locked.value)\nconst reconnectable = computed(() => selected.value && flow.isReconnectable(props.edge))\n\nfunction marker(kind: FlowMarker | undefined, x: number, y: number, angle: number, inset: number) {\n if (!kind || kind === 'none') return ''\n return arrowPath(x - inset * Math.cos(angle), y - inset * Math.sin(angle), angle, 9, kind === 'arrow-closed')\n}\nconst markerEnd = computed(() => {\n const g = geo.value\n return g ? marker(props.edge.markerEnd ?? 'arrow-closed', g.targetX, g.targetY, g.targetAngle, g.targetInset) : ''\n})\nconst markerStart = computed(() => {\n const g = geo.value\n return g ? marker(props.edge.markerStart, g.sourceX, g.sourceY, g.sourceAngle + Math.PI, g.sourceInset) : ''\n})\nconst label = computed(() => {\n const name = (id: string) => String((flow.getNode(id)?.data as { label?: unknown } | undefined)?.label ?? id)\n return locale.flowEdge.replace('{source}', name(props.edge.source)).replace('{target}', name(props.edge.target))\n})\n// Declarative look: an M3 role reads its token, anything else is a CSS color\nconst ROLE = /^(primary|secondary|tertiary|error|outline|outline-variant|on-surface|on-surface-variant|inverse-surface|inverse-primary)(-container)?$/\nconst stroke = computed(() => {\n if (selected.value || highlighted.value) return 'var(--color-primary)'\n const c = props.edge.color\n return c ? (ROLE.test(c) ? `var(--color-${c})` : c) : 'var(--color-outline)'\n})\nconst width = computed(() => (props.edge.width ?? 2) + (highlighted.value ? 2 : 0))\nconst scope = computed(() => ({ edge: props.edge, selected: selected.value, highlighted: highlighted.value, ...geo.value }))\n</script>\n\n<template>\n <g\n v-if=\"geo\"\n class=\"m3-flow-edge outline-none\"\n :class=\"[edge.class, selected && 'm3-flow-edge-selected']\"\n :data-flow-edge=\"edge.id\"\n :tabindex=\"selectable ? 0 : undefined\"\n :aria-label=\"label\"\n role=\"img\"\n @keydown=\"flow.onEdgeKey($event, edge.id)\"\n >\n <path :d=\"geo.path\" fill=\"none\" stroke=\"transparent\" stroke-width=\"16\" :style=\"{ pointerEvents: 'stroke' }\" :class=\"flow.branching.value ? 'cursor-crosshair' : selectable && 'cursor-pointer'\" />\n <!-- A dragged node would splice in here: a halo around it -->\n <path v-if=\"highlighted\" :d=\"geo.path\" fill=\"none\" stroke-width=\"14\" stroke-linecap=\"round\" class=\"m3-flow-edge-halo stroke-primary/25\" />\n <SlotOutlet v-if=\"render\" :fn=\"render\" :scope=\"scope\" />\n <template v-else>\n <path\n :d=\"geo.path\"\n fill=\"none\"\n :stroke-width=\"width\"\n stroke-linecap=\"round\"\n class=\"m3-flow-edge-line\"\n :class=\"[edge.animated === 'reverse' ? 'm3-flow-edge-animated m3-flow-edge-reverse' : edge.animated && 'm3-flow-edge-animated', edge.dashed && !edge.animated && 'm3-flow-edge-dashed']\"\n :style=\"{ stroke, strokeWidth: `${width}px` }\"\n />\n <path\n v-for=\"(m, i) in [markerEnd, markerStart]\"\n v-show=\"m\"\n :key=\"i\"\n :d=\"m\"\n stroke-width=\"2\"\n stroke-linejoin=\"round\"\n stroke-linecap=\"round\"\n class=\"m3-flow-edge-line\"\n :style=\"{ stroke, fill: (i === 0 ? edge.markerEnd ?? 'arrow-closed' : edge.markerStart) === 'arrow-closed' ? stroke : 'none' }\"\n />\n </template>\n <template v-if=\"reconnectable\">\n <circle\n v-for=\"end in (['source', 'target'] as const)\"\n :key=\"end\"\n :data-flow-reconnect=\"end\"\n :cx=\"end === 'source' ? geo.sourceX : geo.targetX\"\n :cy=\"end === 'source' ? geo.sourceY : geo.targetY\"\n r=\"6\"\n stroke-width=\"2\"\n class=\"cursor-move fill-surface stroke-primary\"\n :style=\"{ pointerEvents: 'all' }\"\n />\n </template>\n </g>\n</template>\n","<script setup lang=\"ts\">\n// An edge's label, in an HTML layer over the edges: a small chip at the path's middle (or MFlow's #edge-label)\nimport { computed, inject, type Slot } from 'vue'\nimport { FLOW_KEY, type FlowEdge } from '../composables/useFlow'\nimport { SlotOutlet } from '../composables/_flowSlot'\nimport { useLocale } from '../composables/useLocale'\n\nconst props = defineProps<{ edge: FlowEdge; render?: Slot }>()\n\nconst flow = inject(FLOW_KEY)!\nconst geo = computed(() => flow.edgeGeometry(props.edge))\nconst selected = computed(() => flow.selectedEdges.value.has(props.edge.id))\n// A selected edge offers a delete button beside its label (or alone): the way to disconnect on touch\nconst deletable = computed(() => selected.value && props.edge.deletable !== false && !flow.locked.value)\nconst locale = useLocale()\n// A press on it deletes through MFlow's own pointerdown; its click is only for the keyboard (detail 0). The tap that\n// selects the edge makes it appear right under the finger, and that touch's click lands on it when it lifts\nfunction onClick(e: MouseEvent) {\n if (e.detail === 0) flow.remove({ edges: [props.edge.id] })\n}\nconst TONES = {\n primary: 'bg-primary-container text-on-primary-container',\n secondary: 'bg-secondary-container text-on-secondary-container',\n tertiary: 'bg-tertiary-container text-on-tertiary-container',\n error: 'bg-error-container text-on-error-container',\n neutral: 'bg-surface-container-high text-on-surface-variant',\n}\n</script>\n\n<template>\n <div\n v-if=\"geo\"\n class=\"m3-flow-edge-label absolute top-0 left-0 cursor-pointer\"\n :style=\"{ transform: `translate(${geo.labelX}px, ${geo.labelY}px) translate(-50%, -50%)` }\"\n :data-flow-edge=\"edge.id\"\n >\n <div class=\"flex items-center gap-1\">\n <SlotOutlet v-if=\"render\" :fn=\"render\" :scope=\"{ edge, selected }\" />\n <span\n v-else-if=\"edge.label\"\n class=\"block rounded-sm px-2 py-0.5 text-label-medium whitespace-nowrap transition-colors\"\n :class=\"selected ? 'bg-secondary-container text-on-secondary-container' : TONES[edge.labelTone ?? 'neutral']\"\n >{{ edge.label }}</span>\n <button\n v-if=\"deletable\"\n type=\"button\"\n class=\"m3-flow-edge-delete relative flex size-6 cursor-pointer items-center justify-center rounded-full bg-surface-container-highest text-on-surface-variant shadow-elevation-1 transition-colors outline-none before:absolute before:-inset-2 hover:bg-error-container hover:text-on-error-container focus-visible:ring-2 focus-visible:ring-secondary\"\n :data-flow-edge-delete=\"edge.id\"\n :aria-label=\"locale.flowDeleteEdge\"\n @click=\"onClick\"\n >\n <span class=\"material-symbols-outlined text-[16px]\" aria-hidden=\"true\">close</span>\n </button>\n </div>\n </div>\n</template>\n","<script setup lang=\"ts\">\n// An edge's label, in an HTML layer over the edges: a small chip at the path's middle (or MFlow's #edge-label)\nimport { computed, inject, type Slot } from 'vue'\nimport { FLOW_KEY, type FlowEdge } from '../composables/useFlow'\nimport { SlotOutlet } from '../composables/_flowSlot'\nimport { useLocale } from '../composables/useLocale'\n\nconst props = defineProps<{ edge: FlowEdge; render?: Slot }>()\n\nconst flow = inject(FLOW_KEY)!\nconst geo = computed(() => flow.edgeGeometry(props.edge))\nconst selected = computed(() => flow.selectedEdges.value.has(props.edge.id))\n// A selected edge offers a delete button beside its label (or alone): the way to disconnect on touch\nconst deletable = computed(() => selected.value && props.edge.deletable !== false && !flow.locked.value)\nconst locale = useLocale()\n// A press on it deletes through MFlow's own pointerdown; its click is only for the keyboard (detail 0). The tap that\n// selects the edge makes it appear right under the finger, and that touch's click lands on it when it lifts\nfunction onClick(e: MouseEvent) {\n if (e.detail === 0) flow.remove({ edges: [props.edge.id] })\n}\nconst TONES = {\n primary: 'bg-primary-container text-on-primary-container',\n secondary: 'bg-secondary-container text-on-secondary-container',\n tertiary: 'bg-tertiary-container text-on-tertiary-container',\n error: 'bg-error-container text-on-error-container',\n neutral: 'bg-surface-container-high text-on-surface-variant',\n}\n</script>\n\n<template>\n <div\n v-if=\"geo\"\n class=\"m3-flow-edge-label absolute top-0 left-0 cursor-pointer\"\n :style=\"{ transform: `translate(${geo.labelX}px, ${geo.labelY}px) translate(-50%, -50%)` }\"\n :data-flow-edge=\"edge.id\"\n >\n <div class=\"flex items-center gap-1\">\n <SlotOutlet v-if=\"render\" :fn=\"render\" :scope=\"{ edge, selected }\" />\n <span\n v-else-if=\"edge.label\"\n class=\"block rounded-sm px-2 py-0.5 text-label-medium whitespace-nowrap transition-colors\"\n :class=\"selected ? 'bg-secondary-container text-on-secondary-container' : TONES[edge.labelTone ?? 'neutral']\"\n >{{ edge.label }}</span>\n <button\n v-if=\"deletable\"\n type=\"button\"\n class=\"m3-flow-edge-delete relative flex size-6 cursor-pointer items-center justify-center rounded-full bg-surface-container-highest text-on-surface-variant shadow-elevation-1 transition-colors outline-none before:absolute before:-inset-2 hover:bg-error-container hover:text-on-error-container focus-visible:ring-2 focus-visible:ring-secondary\"\n :data-flow-edge-delete=\"edge.id\"\n :aria-label=\"locale.flowDeleteEdge\"\n @click=\"onClick\"\n >\n <span class=\"material-symbols-outlined text-[16px]\" aria-hidden=\"true\">close</span>\n </button>\n </div>\n </div>\n</template>\n","<script lang=\"ts\">\nimport type { FlowEdge, FlowNode, FlowSelection } from '../composables/useFlow'\n\n// Copied nodes and edges, shared by every MFlow on the page (copy in one, paste in another)\nlet clipboard: { nodes: FlowNode[]; edges: FlowEdge[] } | null = null\nlet pasteCount = 0\n\nconst randomId = (prefix: string) => `${prefix}-${Math.random().toString(36).slice(2, 9)}`\nconst emptySelection = (): FlowSelection => ({ nodes: [], edges: [] })\n</script>\n\n<script setup lang=\"ts\">\n/**\n * A node editor (not an M3 spec component): nodes you drag around on a canvas that pans and zooms, joined by edges\n * drawn from handle to handle. Built from M3 pieces (nodes are cards, the controls a floating toolbar) with the\n * API shape of Vue Flow / React Flow. Nodes and edges are `v-model`s of plain objects; the view, the selection\n * and the lock are too. Pan by dragging the background (or the wheel, or two fingers), zoom with Ctrl + wheel, a\n * trackpad or touch pinch, or a double click. Shift + drag (or `selectionOnDrag`; on touch, a long press on the\n * background) draws a selection box; Delete\n * removes what's selected, Ctrl+Z/Ctrl+Shift+Z undo and redo, Ctrl+C/X/V/A copy, cut, paste and select all, and\n * the arrows move the selected nodes. A drag from a handle to another connects them; dropped on nothing it fires\n * `connect-end` with the spot, to offer a new node there. To disconnect: the × on a selected edge, Delete, dragging\n * an edge's end (or a connected input) away and dropping it on nothing. Alignment guides show while dragging one node.\n *\n * Nodes are drawn by type: `default`/`input`/`output` (an MFlowNode), `circle` (a vertex: `data.label`, `color`,\n * `badge`, `ring`, `size`; its edges run center to center in any direction), `group` (a box its children move with), or\n * a `#node-<type>` slot of your own with MFlowHandles in it; edges are `bezier`, `smoothstep`, `step`, `straight`\n * or a `#edge-<type>` slot (with `getBezierPath` and friends); `color`, `width`, `dashed`, `animated` and\n * `labelTone` restyle one without a slot, with a transition. `layout` lays them out (`'tree'`, `'layered'` or a\n * function, e.g. one calling dagre) whenever the graph's shape changes. Put `MFlowControls`, `MFlowMinimap` or\n * anything of yours in the default slot: it's drawn over the canvas, the canvas's gestures and wheel leave it alone,\n * and `useFlow()` works inside it. Inside a node, controls (buttons, inputs, links) never start a drag; mark anything\n * else that shouldn't with `data-flow-nodrag`, and an area that scrolls on its own with `data-flow-nowheel`.\n * `startDrag(id, event)` hands a pointer that's already down to a node, to drag something in from outside (a palette).\n *\n * Positions spring to their new place when they change from outside (a layout, an undo); the view springs on\n * `fitView()`/zoom buttons. Nodes are rendered by small components of their own so moving one only redraws it\n * and its edges.\n *\n * @slot default Drawn over the canvas: MFlowControls, MFlowMinimap, panels of yours. Props: `{ flow }`\n * @slot node-<type> A node of that type. Props: `{ node, data, selected, dragging }`\n * @slot edge-<type> An edge of that type, SVG inside a `<g>`. Props: `{ edge, path, labelX, labelY, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, targetAngle, targetInset, selected, highlighted }` (`highlighted`: a dragged node would splice into it)\n * @slot edge-label An edge's label, instead of the default chip. Props: `{ edge, selected }`\n * @slot empty Shown while there are no nodes\n * @event connect A connection was made (it's also added to `edges` with `autoConnect`)\n * @event connect-start A connection drag started from a handle\n * @event connect-end A connection drag ended: `{ connection }` when it connected, else the flow `position` it was dropped at and where it came from\n * @event reconnect An edge's end was moved to another handle: `{ edge, connection }`\n * @event insert A lone node was dropped onto an edge and spliced in: `{ node, edge, connections }` (with `autoConnect`\n * the edge is replaced by the two connections, keeping its type and look)\n * @event node-click / node-dblclick / node-contextmenu `(node, event)`\n * @event node-drag-start / node-drag `(nodes, event)`\n * @event node-drag-stop `{ nodes, intersecting, event }`: `intersecting` are the nodes under the dragged one\n * @event edge-click / edge-dblclick / edge-contextmenu `(edge, event)`\n * @event pane-click / pane-dblclick / pane-contextmenu `(position, event)` with the flow position (turn\n * `zoomOnDoubleClick` off to use the double click yourself, e.g. to add a node there)\n * @event delete Nodes and edges were deleted: `{ nodes, edges }`\n * @event init The canvas measured its nodes (and laid out / fitted them): the flow context\n */\nimport { computed, nextTick, onBeforeUnmount, onMounted, provide, reactive, ref, shallowReactive, shallowRef, toRaw, useSlots, watch } from 'vue'\nimport {\n FLOW_KEY,\n type FlowConnection,\n type FlowContext,\n type FlowEdgeGeometry as EdgeGeometry,\n type FlowFitOptions,\n type FlowHandleBounds,\n type FlowInternals,\n type FlowPosition,\n type FlowViewport,\n type FlowXY,\n} from '../composables/useFlow'\nimport { layoutLayered, layoutTree, type FlowLayout, type FlowLayoutDirection, type FlowLayoutOptions } from '../composables/flowLayout'\nimport { distanceToPoints, edgePathPoints, getBezierPath, getSmoothStepPath, getStepPath, getStraightPath, type FlowEdgePath } from '../composables/flowPaths'\nimport { DEFAULT_SPATIAL } from '../composables/_useSpring'\nimport { prefersReducedMotion } from '../composables/_springAnimation'\nimport { useLocale } from '../composables/useLocale'\nimport NodeShell from './_MFlowNodeShell.vue'\nimport EdgeView from './_MFlowEdge.vue'\nimport EdgeLabel from './_MFlowEdgeLabel.vue'\n\ndefineOptions({ inheritAttrs: false })\n\nconst props = withDefaults(defineProps<{\n nodes?: FlowNode[]\n edges?: FlowEdge[]\n /** The view (v-model) */\n viewport?: FlowViewport\n /** Selected node and edge ids (v-model) */\n selection?: FlowSelection\n /** Switches off moving, connecting, selecting and deleting; the view still pans and zooms (v-model) */\n locked?: boolean\n /** Which way edges run by default: where the default node's handles go and the layout's direction */\n direction?: 'horizontal' | 'vertical'\n background?: 'dots' | 'grid' | 'none'\n /** The background's spacing, and the grid nodes snap to, px */\n gridSize?: number\n snapToGrid?: boolean\n minZoom?: number\n maxZoom?: number\n /** Fits the nodes in view once they're measured, and again after each automatic `layout` */\n fitView?: boolean\n /** What the plain wheel does (Ctrl + wheel always zooms) */\n wheel?: 'pan' | 'zoom'\n /** A double click on the background zooms in */\n zoomOnDoubleClick?: boolean\n /** Dragging the background pans; off, it draws a selection box */\n panOnDrag?: boolean\n /** Dragging the background draws a selection box (Shift + drag always does) */\n selectionOnDrag?: boolean\n nodesDraggable?: boolean\n nodesConnectable?: boolean\n elementsSelectable?: boolean\n edgesReconnectable?: boolean\n /** Merged into edges made by connecting (`type`, `animated`, `markerEnd`…) */\n defaultEdgeOptions?: Partial<FlowEdge>\n /** Adds an edge to `edges` when a connection is made; off, only `connect` fires */\n autoConnect?: boolean\n /** Whether a connection may be made (no duplicates or same-node loops are offered either way) */\n isValidConnection?: (c: FlowConnection) => boolean\n /** How close to a handle a connection snaps to it, px */\n connectionRadius?: number\n /**\n * Asked before anything is deleted (the keyboard, an edge's ×, an edge dropped on nothing, `remove()`), with what\n * would go: return false to keep it, or a Promise (a confirm dialog) that resolves to whether to delete\n */\n beforeDelete?: (items: { nodes: FlowNode[]; edges: FlowEdge[] }) => boolean | Promise<boolean>\n /** Keys that delete the selection; `null` turns deleting off */\n deleteKeys?: string[] | null\n /** Undo and redo (Ctrl+Z, Ctrl+Shift+Z / Ctrl+Y), over every change to nodes and edges */\n history?: boolean\n historySize?: number\n /** Alignment guides while dragging one node */\n guides?: boolean\n /** Lays the nodes out when the graph's shape changes (nodes or edges added, removed, hidden) */\n layout?: 'tree' | 'layered' | FlowLayout | null\n layoutOptions?: FlowLayoutOptions\n /**\n * A node with no connections dropped onto an edge splices into it: A → C becomes A → B → C (the edge lights up\n * while it's over one). Only when both new connections are valid. Without room between A and C, the node moves\n * to sit after A and C moves on (with everything after it) along the flow's `direction`\n */\n insertOnEdge?: boolean\n /** Nodes dropped onto a `group` join it (and leave it when dropped outside) */\n dropIntoGroups?: boolean\n /** Positions spring to their new place when they change from outside */\n animate?: boolean\n /** Makes ids for pasted nodes and new edges */\n getId?: (kind: 'node' | 'edge') => string\n /**\n * A drag that starts on an edge draws a new edge from the same source, a branch, as in a circuit editor (the\n * preview leaves from where you grabbed it). A click still selects the edge; with a finger, only a selected edge\n * branches, so a swipe across one still pans\n */\n edgeBranching?: boolean\n /**\n * Let the browser's own context menu open on the canvas (right click, or a long press on a phone). Off by default:\n * the `*-contextmenu` events still fire, for a menu of your own (MContextMenu's `showAt`). Text fields inside\n * nodes always keep it, for copy and paste\n */\n nativeContextMenu?: boolean\n /** The canvas's accessible name */\n label?: string\n}>(), {\n nodes: () => [],\n edges: () => [],\n viewport: undefined,\n selection: undefined,\n locked: false,\n direction: 'horizontal',\n background: 'dots',\n gridSize: 20,\n snapToGrid: false,\n minZoom: 0.2,\n maxZoom: 4,\n fitView: false,\n wheel: 'pan',\n zoomOnDoubleClick: true,\n panOnDrag: true,\n selectionOnDrag: false,\n nodesDraggable: true,\n nodesConnectable: true,\n elementsSelectable: true,\n edgesReconnectable: true,\n autoConnect: true,\n connectionRadius: 24,\n deleteKeys: () => ['Delete', 'Backspace'],\n history: true,\n historySize: 100,\n guides: true,\n layout: null,\n dropIntoGroups: false,\n insertOnEdge: true,\n edgeBranching: false,\n nativeContextMenu: false,\n animate: true,\n})\n\nconst emit = defineEmits<{\n 'update:nodes': [FlowNode[]]\n 'update:edges': [FlowEdge[]]\n 'update:viewport': [FlowViewport]\n 'update:selection': [FlowSelection]\n 'update:locked': [boolean]\n connect: [FlowConnection]\n 'connect-start': [{ nodeId: string; handleId: string | null; type: 'source' | 'target' }]\n 'connect-end': [{ connection: FlowConnection | null; position: FlowXY; from: { nodeId: string; handleId: string | null; type: 'source' | 'target' } }]\n reconnect: [{ edge: FlowEdge; connection: FlowConnection }]\n insert: [{ node: FlowNode; edge: FlowEdge; connections: [FlowConnection, FlowConnection] }]\n 'node-click': [FlowNode, MouseEvent]\n 'node-dblclick': [FlowNode, MouseEvent]\n 'node-contextmenu': [FlowNode, MouseEvent]\n 'node-drag-start': [FlowNode[], PointerEvent]\n 'node-drag': [FlowNode[], PointerEvent]\n 'node-drag-stop': [{ nodes: FlowNode[]; intersecting: FlowNode[]; event: PointerEvent }]\n 'edge-click': [FlowEdge, MouseEvent]\n 'edge-dblclick': [FlowEdge, MouseEvent]\n 'edge-contextmenu': [FlowEdge, MouseEvent]\n 'pane-click': [FlowXY, MouseEvent]\n 'pane-contextmenu': [FlowXY, MouseEvent]\n 'pane-dblclick': [FlowXY, MouseEvent]\n delete: [{ nodes: FlowNode[]; edges: FlowEdge[] }]\n init: [FlowContext]\n}>()\n\nconst slots = useSlots()\nconst locale = useLocale()\nconst root = ref<HTMLElement>()\nconst layer = ref<HTMLElement>()\n// What's in the default slot (controls, a minimap, panels of yours) sits over the canvas: the canvas's gestures and\n// wheel leave it alone, so it needs no marking\nconst onOverlay = (t: EventTarget | null) => !!t && t !== root.value && !layer.value?.contains(t as Node)\nconst size = ref({ width: 0, height: 0 })\nconst ready = ref(false)\nconst announcement = ref('')\nconst announce = (m: string) => {\n announcement.value = ''\n nextTick(() => (announcement.value = m))\n}\nconst makeId = (kind: 'node' | 'edge') => props.getId?.(kind) ?? randomId(kind === 'node' ? 'n' : 'e')\n\n// ── Nodes, edges, selection, lock: local copies of the v-models (they work unbound too) ──────────────────\nconst nodesLocal = shallowRef<FlowNode[]>(props.nodes)\nconst edgesLocal = shallowRef<FlowEdge[]>(props.edges)\nconst selLocal = shallowRef<FlowSelection>(props.selection ?? emptySelection())\nconst lockedLocal = ref(props.locked)\nwatch(() => props.selection, (s) => { if (s && !same(s, selLocal.value)) selLocal.value = s })\nwatch(() => props.locked, (l) => { lockedLocal.value = l })\nconst locked = computed({\n get: () => lockedLocal.value,\n set: (v: boolean) => {\n lockedLocal.value = v\n emit('update:locked', v)\n },\n})\n\nconst nodeById = computed(() => new Map(nodesLocal.value.map((n) => [n.id, n])))\nconst edgeById = computed(() => new Map(edgesLocal.value.map((e) => [e.id, e])))\nconst getNode = (id: string) => nodeById.value.get(id)\nconst parentOf = (id: string) => {\n const p = nodeById.value.get(id)?.parentId\n return p && nodeById.value.has(p) ? p : undefined\n}\nfunction ancestors(id: string): string[] {\n const out: string[] = []\n for (let p = parentOf(id); p && out.length < 50; p = parentOf(p)) out.push(p)\n return out\n}\nconst depthOf = (id: string) => ancestors(id).length\nfunction isHidden(id: string) {\n const n = nodeById.value.get(id)\n return !n || !!n.hidden || ancestors(id).some((a) => nodeById.value.get(a)?.hidden)\n}\nconst childrenOf = computed(() => {\n const m = new Map<string, string[]>()\n for (const n of nodesLocal.value) if (n.parentId && nodeById.value.has(n.parentId)) (m.get(n.parentId) ?? m.set(n.parentId, []).get(n.parentId)!).push(n.id)\n return m\n})\nfunction descendants(id: string): string[] {\n const out: string[] = []\n const walk = (i: string) => (childrenOf.value.get(i) ?? []).forEach((c) => { out.push(c); walk(c) })\n walk(id)\n return out\n}\n\nconst selectedNodes = computed(() => new Set(selLocal.value.nodes))\nconst selectedEdges = computed(() => new Set(selLocal.value.edges))\n// Edges branch when dragged (edgeBranching)\nconst branching = computed(() => props.edgeBranching && nodesConnectable.value && !locked.value)\nfunction setSelection(s: Partial<FlowSelection>) {\n const next = { nodes: s.nodes ?? selLocal.value.nodes, edges: s.edges ?? selLocal.value.edges }\n if (sameIds(next.nodes, selLocal.value.nodes) && sameIds(next.edges, selLocal.value.edges)) return\n selLocal.value = next\n emit('update:selection', next)\n}\nconst sameIds = (a: string[], b: string[]) => a.length === b.length && a.every((x, i) => x === b[i])\nconst canSelect = computed(() => props.elementsSelectable && !locked.value)\nconst canDrag = computed(() => props.nodesDraggable && !locked.value)\nconst nodesConnectable = computed(() => props.nodesConnectable && !locked.value)\n\n// ── History: every change to nodes/edges, ours or the parent's, is a step ────────────────────────────────\ntype Snapshot = { nodes: FlowNode[]; edges: FlowEdge[] }\nconst past = shallowRef<Snapshot[]>([])\nconst future = shallowRef<Snapshot[]>([])\nlet lastCoalesce: { key: string; at: number } | null = null\nconst snapshot = (): Snapshot => ({ nodes: nodesLocal.value, edges: edgesLocal.value })\nfunction pushHistory(s: Snapshot, coalesce?: string) {\n if (!props.history) return\n const now = performance.now()\n // Repeated steps of one gesture (arrow-key nudges) make one undo step\n if (coalesce && lastCoalesce?.key === coalesce && now - lastCoalesce.at < 800) {\n lastCoalesce.at = now\n future.value = []\n return\n }\n lastCoalesce = coalesce ? { key: coalesce, at: now } : null\n past.value = [...past.value, s].slice(-props.historySize)\n future.value = []\n}\nlet pendingExternal: Snapshot | null = null\n// What the parent hands back in the same tick as an emit of ours is that change coming back (maybe copied or\n// normalized), not a new step\nlet echo = false\nfunction externalChange() {\n if (echo || pendingExternal) return\n pendingExternal = snapshot()\n queueMicrotask(() => {\n if (pendingExternal) pushHistory(pendingExternal)\n pendingExternal = null\n })\n}\n// What comes back through v-model is often our own array behind a reactive proxy (a parent's `ref([])`)\nconst same = (a: unknown, b: unknown) => toRaw(a) === toRaw(b)\nwatch(() => props.nodes, (n) => {\n if (same(n, nodesLocal.value)) return\n externalChange()\n nodesLocal.value = n\n})\nwatch(() => props.edges, (e) => {\n if (same(e, edgesLocal.value)) return\n externalChange()\n edgesLocal.value = e\n})\n\nfunction commit(next: Partial<Snapshot>, opts: { history?: boolean; coalesce?: string } = {}) {\n if (opts.history !== false) pushHistory(snapshot(), opts.coalesce)\n if (!echo) {\n echo = true\n nextTick(() => (echo = false))\n }\n if (next.nodes && !same(next.nodes, nodesLocal.value)) {\n nodesLocal.value = next.nodes\n emit('update:nodes', next.nodes)\n }\n if (next.edges && !same(next.edges, edgesLocal.value)) {\n edgesLocal.value = next.edges\n emit('update:edges', next.edges)\n }\n}\nfunction applySnapshot(s: Snapshot) {\n commit(s, { history: false })\n const ids = new Set(s.nodes.map((n) => n.id))\n const eids = new Set(s.edges.map((e) => e.id))\n setSelection({ nodes: selLocal.value.nodes.filter((i) => ids.has(i)), edges: selLocal.value.edges.filter((i) => eids.has(i)) })\n}\nfunction undo() {\n const s = past.value[past.value.length - 1]\n if (!s) return\n future.value = [...future.value, snapshot()]\n past.value = past.value.slice(0, -1)\n lastCoalesce = null\n applySnapshot(s)\n}\nfunction redo() {\n const s = future.value[future.value.length - 1]\n if (!s) return\n past.value = [...past.value, snapshot()]\n future.value = future.value.slice(0, -1)\n lastCoalesce = null\n applySnapshot(s)\n}\nconst canUndo = computed(() => past.value.length > 0)\nconst canRedo = computed(() => future.value.length > 0)\n\n// ── Where nodes are drawn: their position, sprung when it changes from outside ──────────────────────────\n// `disp` is reactive (edges and slots read it); the springs are plain and step in one rAF loop that writes\n// each moving node's `disp` once per frame (the library's spring convention, see CLAUDE.md)\ntype Spring2 = { x: number; y: number; vx: number; vy: number; tx: number; ty: number }\nconst disp = shallowReactive(new Map<string, { x: number; y: number }>())\nconst springs = new Map<string, Spring2>()\nconst dragging = shallowRef(new Set<string>())\nlet instantNext = false\n\n// Nodes hidden last time: one that shows again appears at its position instead of sliding in from where it was hidden\nlet wasHidden = new Set<string>()\nfunction syncPositions() {\n const seen = new Set<string>()\n const hiddenNow = new Set<string>()\n const animate = props.animate && ready.value && !instantNext && !prefersReducedMotion()\n for (const n of nodesLocal.value) {\n seen.add(n.id)\n if (isHidden(n.id)) hiddenNow.add(n.id)\n const reappears = wasHidden.has(n.id) && !hiddenNow.has(n.id)\n const d = disp.get(n.id)\n const { x, y } = n.position\n if (!d) {\n disp.set(n.id, reactive({ x, y }))\n springs.set(n.id, { x, y, vx: 0, vy: 0, tx: x, ty: y })\n continue\n }\n const s = springs.get(n.id)!\n if (s.tx === x && s.ty === y && !reappears) continue\n s.tx = x\n s.ty = y\n if (!animate || reappears || dragging.value.has(n.id)) {\n s.x = x\n s.y = y\n s.vx = s.vy = 0\n d.x = x\n d.y = y\n } else kick()\n }\n for (const id of [...disp.keys()]) if (!seen.has(id)) { disp.delete(id); springs.delete(id) }\n wasHidden = hiddenNow\n instantNext = false\n}\nwatch(nodesLocal, syncPositions, { immediate: true })\n\nconst STIFF = DEFAULT_SPATIAL.stiffness\nconst DAMP = 2 * DEFAULT_SPATIAL.dampingRatio * Math.sqrt(STIFF)\nconst SUBSTEP = 0.004\nlet raf = 0\nlet last = 0\nfunction kick() {\n if (raf || typeof requestAnimationFrame === 'undefined') return\n last = performance.now()\n raf = requestAnimationFrame(frame)\n}\nfunction frame(now: number) {\n raf = 0\n const dt = Math.min((now - last) / 1000, 1 / 20)\n last = now\n let moving = false\n for (const [id, s] of springs) {\n if (s.x === s.tx && s.y === s.ty && !s.vx && !s.vy) continue\n for (let t = 0; t < dt; t += SUBSTEP) {\n const h = Math.min(SUBSTEP, dt - t)\n s.vx += (-STIFF * (s.x - s.tx) - DAMP * s.vx) * h\n s.vy += (-STIFF * (s.y - s.ty) - DAMP * s.vy) * h\n s.x += s.vx * h\n s.y += s.vy * h\n }\n if (Math.abs(s.x - s.tx) < 0.1 && Math.abs(s.y - s.ty) < 0.1 && Math.abs(s.vx) < 2 && Math.abs(s.vy) < 2) {\n s.x = s.tx\n s.y = s.ty\n s.vx = s.vy = 0\n } else moving = true\n const d = disp.get(id)\n if (d) { d.x = s.x; d.y = s.y }\n }\n if (stepViewport(dt)) moving = true\n if (autoPan(dt)) moving = true\n if (moving) raf = requestAnimationFrame(frame)\n}\n\nfunction getAbsolutePosition(id: string): FlowXY {\n let x = 0\n let y = 0\n let cur: string | undefined = id\n for (let i = 0; cur && i < 50; i++) {\n const d = disp.get(cur)\n const n = nodeById.value.get(cur)\n x += d?.x ?? n?.position.x ?? 0\n y += d?.y ?? n?.position.y ?? 0\n cur = parentOf(cur)\n }\n return { x, y }\n}\n\n// ── Sizes and handles, measured by the node shells ───────────────────────────────────────────────────────\nconst dims = shallowReactive(new Map<string, { width: number; height: number }>())\nconst handles = shallowReactive(new Map<string, FlowHandleBounds[]>())\nconst nodeEls = new Map<string, HTMLElement>()\ntype HandleReg = { el: HTMLElement; info: () => Omit<FlowHandleBounds, 'x' | 'y'> }\nconst handleRegs = new Map<string, Set<HandleReg>>()\n\nconst GROUP_PAD = 24\nconst GROUP_HEAD = 36\n// Groups around nodes being dragged keep their size until the drop: growing after the child would never let it\n// leave (the pointer would always be inside)\nconst frozenGroups = shallowReactive(new Map<string, { width: number; height: number }>())\nfunction getSize(id: string): { width: number; height: number } {\n const n = nodeById.value.get(id)\n if (!n) return { width: 0, height: 0 }\n if (n.width && n.height) return { width: n.width, height: n.height }\n if (n.type === 'group' && !n.width) {\n const frozen = frozenGroups.get(id)\n if (frozen) return frozen\n // A group without a size wraps its children\n let w = 200\n let h = 120\n for (const c of childrenOf.value.get(id) ?? []) {\n if (isHidden(c)) continue\n const d = disp.get(c)\n const s = getSize(c)\n w = Math.max(w, (d?.x ?? 0) + s.width + GROUP_PAD)\n h = Math.max(h, (d?.y ?? 0) + s.height + GROUP_PAD)\n }\n return { width: n.width ?? w, height: n.height ?? Math.max(h, GROUP_HEAD + GROUP_PAD) }\n }\n const m = dims.get(id)\n return { width: n.width ?? m?.width ?? 0, height: n.height ?? m?.height ?? 0 }\n}\n\nfunction measureNode(id: string) {\n const el = nodeEls.get(id)\n if (!el) return\n const w = el.offsetWidth\n const h = el.offsetHeight\n const prev = dims.get(id)\n if (!prev || prev.width !== w || prev.height !== h) dims.set(id, { width: w, height: h })\n const regs = handleRegs.get(id)\n if (!regs?.size) {\n if (handles.has(id)) handles.delete(id)\n return\n }\n // Handle centers relative to the node's corner, back in flow units (the layer is scaled by the zoom)\n const r = el.getBoundingClientRect()\n const z = vp.value.zoom || 1\n const list: FlowHandleBounds[] = []\n for (const reg of regs) {\n const hr = reg.el.getBoundingClientRect()\n list.push({ ...reg.info(), x: (hr.left + hr.width / 2 - r.left) / z, y: (hr.top + hr.height / 2 - r.top) / z })\n }\n handles.set(id, list)\n}\nlet measureQueued = new Set<string>()\nfunction queueMeasure(id: string) {\n measureQueued.add(id)\n if (measureQueued.size > 1) return\n nextTick(() => {\n const ids = measureQueued\n measureQueued = new Set()\n ids.forEach(measureNode)\n })\n}\nfunction registerHandle(nodeId: string, el: HTMLElement, info: HandleReg['info']) {\n const reg = { el, info }\n ;(handleRegs.get(nodeId) ?? handleRegs.set(nodeId, new Set()).get(nodeId)!).add(reg)\n queueMeasure(nodeId)\n return () => {\n handleRegs.get(nodeId)?.delete(reg)\n queueMeasure(nodeId)\n }\n}\nfunction registerNodeEl(id: string, el: HTMLElement | null) {\n if (el) {\n nodeEls.set(id, el)\n measureNode(id)\n ro?.observe(el)\n } else {\n const old = nodeEls.get(id)\n if (old) ro?.unobserve(old)\n nodeEls.delete(id)\n dims.delete(id)\n handles.delete(id)\n }\n}\n\n// Where an edge's ends are: its handles, else the middle of the node's side\nconst sidePositions = (n: FlowNode) => {\n const v = props.direction === 'vertical'\n return {\n source: n.sourcePosition ?? (v ? 'bottom' : 'right') as FlowPosition,\n target: n.targetPosition ?? (v ? 'top' : 'left') as FlowPosition,\n }\n}\nfunction sidePoint(id: string, pos: FlowPosition): FlowXY {\n const a = getAbsolutePosition(id)\n const s = getSize(id)\n switch (pos) {\n case 'top': return { x: a.x + s.width / 2, y: a.y }\n case 'bottom': return { x: a.x + s.width / 2, y: a.y + s.height }\n case 'left': return { x: a.x, y: a.y + s.height / 2 }\n default: return { x: a.x + s.width, y: a.y + s.height / 2 }\n }\n}\nfunction handlePoint(nodeId: string, type: 'source' | 'target', handleId?: string | null): { x: number; y: number; position: FlowPosition; inset: number } | null {\n const n = nodeById.value.get(nodeId)\n if (!n) return null\n const list = handles.get(nodeId)?.filter((h) => h.type === type)\n const h = list?.length ? (handleId != null ? list.find((x) => x.id === handleId) : list[0]) ?? list[0] : undefined\n if (h) {\n const a = getAbsolutePosition(nodeId)\n return { x: a.x + h.x, y: a.y + h.y, position: h.position, inset: HANDLE_RADIUS }\n }\n const position = sidePositions(n)[type]\n return { ...sidePoint(nodeId, position), position, inset: 0 }\n}\n// Arrowheads stop at a handle's rim instead of under it\nconst HANDLE_RADIUS = 5\n\nfunction pathFor(type: string | undefined, p: Omit<EdgeGeometry, keyof FlowEdgePath | 'sourceInset' | 'targetInset'>): FlowEdgePath {\n switch (type) {\n case 'smoothstep': return getSmoothStepPath(p)\n case 'step': return getStepPath(p)\n case 'straight': return getStraightPath(p)\n default: return getBezierPath(p)\n }\n}\nconst edgeType = (e: FlowEdge) => e.type ?? props.defaultEdgeOptions?.type ?? 'bezier'\n// How it's routed: its own type, or for an `#edge-<type>` slot its `pathType` (default bezier)\nconst edgeRoute = (e: Partial<FlowEdge>) => e.pathType ?? props.defaultEdgeOptions?.pathType ?? edgeType(e as FlowEdge)\n// Opposite edges between two circles sit side by side\nconst pairKeys = computed(() => new Set(edgesLocal.value.map((e) => `${e.source}>${e.target}`)))\nfunction circleOf(id: string) {\n const a = getAbsolutePosition(id)\n const s = getSize(id)\n return { x: a.x + s.width / 2, y: a.y + s.height / 2, r: Math.min(s.width, s.height) / 2 }\n}\n// An edge touching a circle runs between the centers (a straight line unless it has a type), cut at the rims\nfunction circleGeometry(e: FlowEdge): EdgeGeometry | null {\n const sc = nodeById.value.get(e.source)?.type === 'circle'\n const tc = nodeById.value.get(e.target)?.type === 'circle'\n const s = sc ? circleOf(e.source) : handlePoint(e.source, 'source', e.sourceHandle)\n const t = tc ? circleOf(e.target) : handlePoint(e.target, 'target', e.targetHandle)\n if (!s || !t) return null\n const dx = t.x - s.x\n const dy = t.y - s.y\n const len = Math.hypot(dx, dy) || 1\n const ux = dx / len\n const uy = dy / len\n const off = pairKeys.value.has(`${e.target}>${e.source}`) ? 6 : 0\n const ox = -uy * off\n const oy = ux * off\n const rs = sc ? (s as { r: number }).r : 0\n const rt = tc ? (t as { r: number }).r + 2 : 0\n const horizontal = Math.abs(dx) >= Math.abs(dy)\n const ends = {\n sourceX: s.x + ux * rs + ox,\n sourceY: s.y + uy * rs + oy,\n sourcePosition: (horizontal ? (dx >= 0 ? 'right' : 'left') : dy >= 0 ? 'bottom' : 'top') as FlowPosition,\n targetX: t.x - ux * rt + ox,\n targetY: t.y - uy * rt + oy,\n targetPosition: (horizontal ? (dx >= 0 ? 'left' : 'right') : dy >= 0 ? 'top' : 'bottom') as FlowPosition,\n }\n return { ...ends, ...pathFor(e.type ?? props.defaultEdgeOptions?.type ?? 'straight', ends), sourceInset: 0, targetInset: 0 }\n}\nfunction edgeGeometry(e: FlowEdge): EdgeGeometry | null {\n if (nodeById.value.get(e.source)?.type === 'circle' || nodeById.value.get(e.target)?.type === 'circle') return circleGeometry(e)\n const s = handlePoint(e.source, 'source', e.sourceHandle)\n const t = handlePoint(e.target, 'target', e.targetHandle)\n if (!s || !t) return null\n const ends = { sourceX: s.x, sourceY: s.y, sourcePosition: s.position, targetX: t.x, targetY: t.y, targetPosition: t.position }\n return { ...ends, ...pathFor(edgeRoute(e), ends), sourceInset: s.inset, targetInset: t.inset }\n}\n\n// What's drawn: groups under the edges, other nodes over them; children over their parents\nconst visibleNodes = computed(() => nodesLocal.value.filter((n) => !isHidden(n.id)))\nconst groupNodes = computed(() => visibleNodes.value.filter((n) => n.type === 'group').sort((a, b) => depthOf(a.id) - depthOf(b.id)))\nconst plainNodes = computed(() => visibleNodes.value.filter((n) => n.type !== 'group'))\nconst visibleEdges = computed(() => edgesLocal.value.filter((e) => !e.hidden && !isHidden(e.source) && !isHidden(e.target)))\nconst isLifted = (id: string) => dragging.value.has(id) || ancestors(id).some((a) => dragging.value.has(a))\nconst zIndexOf = (id: string) => (isLifted(id) ? 1000 : 0) + depthOf(id) * 10 + (selectedNodes.value.has(id) ? 3 : 0)\nconst nodeRenderer = (n: FlowNode) => slots[`node-${n.type ?? 'default'}`]\nconst edgeRenderer = (e: FlowEdge) => slots[`edge-${edgeType(e)}`]\nconst isReconnectable = (e: FlowEdge) => !locked.value && (e.reconnectable ?? props.edgesReconnectable)\n\n// ── The view ──────────────────────────────────────────────────────────────────────────────────────────────\nconst vp = ref<FlowViewport>({ x: 0, y: 0, zoom: 1, ...props.viewport })\nwatch(() => props.viewport, (v) => {\n if (!v || (v.x === vp.value.x && v.y === vp.value.y && v.zoom === vp.value.zoom)) return\n vpAnim = null\n vp.value = { ...v }\n})\nconst clampZoom = (z: number) => Math.min(props.maxZoom, Math.max(props.minZoom, z))\nfunction writeViewport(v: FlowViewport) {\n if (v.x === vp.value.x && v.y === vp.value.y && v.zoom === vp.value.zoom) return\n vp.value = v\n emit('update:viewport', v)\n}\ntype Spring1 = { p: number; v: number; t: number }\nlet vpAnim: { x: Spring1; y: Spring1; z: Spring1 } | null = null\nfunction setViewport(v: Partial<FlowViewport>, opts: { animate?: boolean } = {}) {\n const target = { x: v.x ?? vp.value.x, y: v.y ?? vp.value.y, zoom: clampZoom(v.zoom ?? vp.value.zoom) }\n if (opts.animate === false || !ready.value || prefersReducedMotion() || typeof requestAnimationFrame === 'undefined') {\n vpAnim = null\n writeViewport(target)\n return\n }\n const cur = vpAnim\n vpAnim = {\n x: { p: vp.value.x, v: cur?.x.v ?? 0, t: target.x },\n y: { p: vp.value.y, v: cur?.y.v ?? 0, t: target.y },\n z: { p: vp.value.zoom, v: cur?.z.v ?? 0, t: target.zoom },\n }\n kick()\n}\nfunction stepViewport(dt: number) {\n const a = vpAnim\n if (!a) return false\n let done = true\n for (const s of [a.x, a.y, a.z]) {\n for (let t = 0; t < dt; t += SUBSTEP) {\n const h = Math.min(SUBSTEP, dt - t)\n s.v += (-STIFF * (s.p - s.t) - DAMP * s.v) * h\n s.p += s.v * h\n }\n const eps = s === a.z ? 0.0005 : 0.1\n if (Math.abs(s.p - s.t) < eps && Math.abs(s.v) < eps * 10) { s.p = s.t; s.v = 0 } else done = false\n }\n writeViewport({ x: a.x.p, y: a.y.p, zoom: a.z.p })\n if (done) vpAnim = null\n return !done\n}\n\nfunction rootRect() {\n return root.value?.getBoundingClientRect() ?? ({ left: 0, top: 0, width: size.value.width, height: size.value.height } as DOMRect)\n}\nfunction screenToFlow(p: { x: number; y: number }): FlowXY {\n const r = rootRect()\n return { x: (p.x - r.left - vp.value.x) / vp.value.zoom, y: (p.y - r.top - vp.value.y) / vp.value.zoom }\n}\nfunction flowToScreen(p: FlowXY) {\n const r = rootRect()\n return { x: p.x * vp.value.zoom + vp.value.x + r.left, y: p.y * vp.value.zoom + vp.value.y + r.top }\n}\n/** Zoom to `zoom` keeping the canvas point (px from its corner) still */\nfunction zoomAt(zoom: number, px: number, py: number, animate = false) {\n const z = clampZoom(zoom)\n const base = vpAnim && animate ? { x: vpAnim.x.t, y: vpAnim.y.t, zoom: vpAnim.z.t } : vp.value\n const fx = (px - base.x) / base.zoom\n const fy = (py - base.y) / base.zoom\n setViewport({ x: px - fx * z, y: py - fy * z, zoom: z }, { animate })\n}\nconst targetZoom = () => vpAnim?.z.t ?? vp.value.zoom\nconst zoomIn = () => zoomAt(targetZoom() * 1.25, size.value.width / 2, size.value.height / 2, true)\nconst zoomOut = () => zoomAt(targetZoom() / 1.25, size.value.width / 2, size.value.height / 2, true)\nconst zoomTo = (z: number, opts: { animate?: boolean } = {}) => zoomAt(z, size.value.width / 2, size.value.height / 2, opts.animate ?? true)\nfunction setCenter(x: number, y: number, opts: { zoom?: number; animate?: boolean } = {}) {\n const z = clampZoom(opts.zoom ?? targetZoom())\n setViewport({ x: size.value.width / 2 - x * z, y: size.value.height / 2 - y * z, zoom: z }, { animate: opts.animate ?? true })\n}\nfunction boundsOf(ids: string[]) {\n let x1 = Infinity\n let y1 = Infinity\n let x2 = -Infinity\n let y2 = -Infinity\n for (const id of ids) {\n if (isHidden(id)) continue\n const a = getAbsolutePosition(id)\n const s = getSize(id)\n x1 = Math.min(x1, a.x)\n y1 = Math.min(y1, a.y)\n x2 = Math.max(x2, a.x + s.width)\n y2 = Math.max(y2, a.y + s.height)\n }\n return Number.isFinite(x1) ? { x: x1, y: y1, width: x2 - x1, height: y2 - y1 } : null\n}\nfunction fitView(opts: FlowFitOptions = {}) {\n // Fit where the nodes are going, not where a spring has them right now\n const ids = opts.nodes ?? nodesLocal.value.map((n) => n.id)\n const saved = new Map<string, { x: number; y: number }>()\n for (const [id, s] of springs) {\n const d = disp.get(id)\n if (d && (d.x !== s.tx || d.y !== s.ty)) { saved.set(id, { x: d.x, y: d.y }); d.x = s.tx; d.y = s.ty }\n }\n const b = boundsOf(ids)\n for (const [id, p] of saved) { const d = disp.get(id)!; d.x = p.x; d.y = p.y }\n if (!b || !size.value.width || !size.value.height) return\n const pad = opts.padding ?? 0.1\n const w = size.value.width * (1 - 2 * pad)\n const h = size.value.height * (1 - 2 * pad)\n const z = Math.min(opts.maxZoom ?? 1.5, Math.max(opts.minZoom ?? props.minZoom, Math.min(w / Math.max(1, b.width), h / Math.max(1, b.height))))\n setCenter(b.x + b.width / 2, b.y + b.height / 2, { zoom: clampZoom(z), animate: opts.animate ?? true })\n}\n\n// ── Editing API ───────────────────────────────────────────────────────────────────────────────────────────\nconst asArray = <T,>(x: T | T[]) => (Array.isArray(x) ? x : [x])\nfunction addNodes(ns: FlowNode | FlowNode[]) {\n commit({ nodes: [...nodesLocal.value, ...asArray(ns)] })\n}\nfunction addEdges(es: FlowEdge | FlowEdge[]) {\n commit({ edges: [...edgesLocal.value, ...asArray(es)] })\n}\nfunction updateNode(id: string, patch: Partial<FlowNode> | ((n: FlowNode) => FlowNode)) {\n commit({ nodes: nodesLocal.value.map((n) => (n.id !== id ? n : typeof patch === 'function' ? patch(n) : { ...n, ...patch })) })\n}\nfunction updateEdge(id: string, patch: Partial<FlowEdge> | ((e: FlowEdge) => FlowEdge)) {\n commit({ edges: edgesLocal.value.map((e) => (e.id !== id ? e : typeof patch === 'function' ? patch(e) : { ...e, ...patch })) })\n}\nfunction remove(ids: { nodes?: string[]; edges?: string[] }) {\n const goneNodes = new Set<string>()\n for (const id of ids.nodes ?? []) {\n if (!nodeById.value.has(id)) continue\n goneNodes.add(id)\n descendants(id).forEach((d) => goneNodes.add(d))\n }\n const goneEdgeIds = new Set(ids.edges ?? [])\n const nodes = nodesLocal.value.filter((n) => goneNodes.has(n.id))\n const edges = edgesLocal.value.filter((e) => goneEdgeIds.has(e.id) || goneNodes.has(e.source) || goneNodes.has(e.target))\n if (!nodes.length && !edges.length) return\n if (props.beforeDelete) {\n const ok = props.beforeDelete({ nodes, edges })\n if (ok instanceof Promise) {\n // Applied once confirmed, against whatever the nodes and edges are by then\n ok.then((yes) => { if (yes) applyRemove(goneNodes, new Set(edges.map((e) => e.id))) })\n return\n }\n if (!ok) return\n }\n applyRemove(goneNodes, new Set(edges.map((e) => e.id)))\n}\nfunction applyRemove(goneNodes: Set<string>, goneEdgeIds: Set<string>) {\n const nodes = nodesLocal.value.filter((n) => goneNodes.has(n.id))\n const edges = edgesLocal.value.filter((e) => goneEdgeIds.has(e.id) || goneNodes.has(e.source) || goneNodes.has(e.target))\n if (!nodes.length && !edges.length) return\n const goneEdges = new Set(edges)\n commit({\n nodes: nodes.length ? nodesLocal.value.filter((n) => !goneNodes.has(n.id)) : undefined,\n edges: edges.length ? edgesLocal.value.filter((e) => !goneEdges.has(e)) : undefined,\n })\n setSelection({ nodes: selLocal.value.nodes.filter((i) => !goneNodes.has(i)), edges: selLocal.value.edges.filter((i) => !goneEdges.has(edgeById.value.get(i)!)) })\n emit('delete', { nodes, edges })\n announce(locale.flowDeleted.replace('{count}', String(nodes.length + edges.length)))\n}\nfunction deleteSelection() {\n if (locked.value) return\n const nodes = selLocal.value.nodes.filter((id) => nodeById.value.get(id)?.deletable !== false)\n const edges = selLocal.value.edges.filter((id) => edgeById.value.get(id)?.deletable !== false)\n remove({ nodes, edges })\n}\nfunction selectAll() {\n if (!canSelect.value) return\n setSelection({\n nodes: visibleNodes.value.filter((n) => n.selectable !== false).map((n) => n.id),\n edges: visibleEdges.value.filter((e) => e.selectable !== false).map((e) => e.id),\n })\n}\n\nfunction copy() {\n const ids = new Set(selLocal.value.nodes)\n for (const id of [...ids]) descendants(id).forEach((d) => ids.add(d))\n if (!ids.size) return\n clipboard = {\n nodes: nodesLocal.value.filter((n) => ids.has(n.id)).map((n) => {\n // A node copied without its group keeps its place on the canvas\n if (n.parentId && !ids.has(n.parentId)) {\n const { parentId: _p, extent: _e, ...rest } = n\n return { ...rest, position: getAbsolutePosition(n.id) }\n }\n return n\n }),\n edges: edgesLocal.value.filter((e) => ids.has(e.source) && ids.has(e.target)),\n }\n pasteCount = 0\n}\nfunction cut() {\n if (locked.value) return\n copy()\n deleteSelection()\n}\nfunction paste(at?: FlowXY) {\n if (!clipboard?.nodes.length || locked.value) return\n pasteCount++\n const tops = clipboard.nodes.filter((n) => !n.parentId || !clipboard!.nodes.some((m) => m.id === n.parentId))\n const minX = Math.min(...tops.map((n) => n.position.x))\n const minY = Math.min(...tops.map((n) => n.position.y))\n const step = props.gridSize * 2 * pasteCount\n const dx = at ? at.x - minX : step\n const dy = at ? at.y - minY : step\n const idMap = new Map(clipboard.nodes.map((n) => [n.id, makeId('node')]))\n const topIds = new Set(tops.map((n) => n.id))\n const nodes = clipboard.nodes.map((n) => ({\n ...n,\n id: idMap.get(n.id)!,\n parentId: n.parentId ? idMap.get(n.parentId) ?? n.parentId : undefined,\n position: topIds.has(n.id) ? { x: n.position.x + dx, y: n.position.y + dy } : n.position,\n }))\n const edges = clipboard.edges.map((e) => ({ ...e, id: makeId('edge'), source: idMap.get(e.source)!, target: idMap.get(e.target)! }))\n instantNext = true\n commit({ nodes: [...nodesLocal.value, ...nodes], edges: edges.length ? [...edgesLocal.value, ...edges] : undefined })\n setSelection({ nodes: nodes.map((n) => n.id), edges: edges.map((e) => e.id) })\n}\n\n// ── Layout ────────────────────────────────────────────────────────────────────────────────────────────────\nconst layoutDirection = (): FlowLayoutDirection => props.layoutOptions?.direction ?? (props.direction === 'vertical' ? 'TB' : 'LR')\nasync function runLayout(fn?: 'tree' | 'layered' | FlowLayout | null, options?: FlowLayoutOptions, opts: { history?: boolean } = {}) {\n const f = fn ?? props.layout ?? 'tree'\n const impl: FlowLayout = f === 'tree' ? layoutTree : f === 'layered' ? layoutLayered : f\n const sizes = new Map(nodesLocal.value.filter((n) => !n.parentId).map((n) => [n.id, getSize(n.id)]))\n const o = { ...props.layoutOptions, ...options }\n const result = await impl(nodesLocal.value, edgesLocal.value, { ...o, sizes, direction: o.direction ?? layoutDirection() })\n let changed = false\n const nodes = nodesLocal.value.map((n) => {\n const p = result[n.id]\n if (!p || (Math.abs(p.x - n.position.x) < 0.5 && Math.abs(p.y - n.position.y) < 0.5)) return n\n changed = true\n return { ...n, position: { x: Math.round(p.x), y: Math.round(p.y) } }\n })\n if (changed) commit({ nodes }, { history: opts.history })\n}\n// The graph's shape: which nodes show and how they're joined (not where they are)\nconst structureKey = computed(() =>\n visibleNodes.value.map((n) => n.id).join(',') + '|' + visibleEdges.value.map((e) => `${e.source}>${e.target}`).join(','))\nwatch([structureKey, () => props.direction, () => JSON.stringify(props.layoutOptions ?? {})], () => {\n if (!props.layout || !ready.value) return\n // After the new nodes mount and measure; with fitView the view follows the graph as it grows\n nextTick(async () => {\n await runLayout(null, undefined, { history: false })\n if (props.fitView) fitView()\n })\n})\n\n// ── Pointer gestures, all dispatched from the canvas ──────────────────────────────────────────────────────\nconst DRAG_SLOP_MOUSE = 4\nconst DRAG_SLOP_TOUCH = 6\nconst NO_DRAG = 'input, textarea, select, button, a, label, [contenteditable], [data-flow-nodrag]'\n\ntype Gesture =\n | { kind: 'pan'; id: number; sx: number; sy: number; vx: number; vy: number; moved: boolean; target: 'pane'; touch?: boolean; branch?: FlowEdge }\n | { kind: 'marquee'; id: number; sx: number; sy: number; x: number; y: number; additive: string[]; moved: boolean }\n | { kind: 'node'; id: number; nodeId: string; sx: number; sy: number; touch: boolean; active: boolean; starts: Map<string, FlowXY>; moved: boolean; reselect: boolean }\n | { kind: 'connect'; id: number; from: { nodeId: string; handleId: string | null; type: 'source' | 'target' }; reconnect?: { edge: FlowEdge; end: 'source' | 'target' }; moved: boolean }\n | { kind: 'pinch' }\nlet gesture: Gesture | null = null\n// What the gesture's pointerdown landed on: a click is resolved against it, not the pointerup's target\nlet downTarget: HTMLElement | null = null\nconst touches = new Map<number, { x: number; y: number }>()\nlet pinch: { dist: number; cx: number; cy: number; zoom: number; fx: number; fy: number } | null = null\nconst pointer = { x: 0, y: 0, inside: false }\n\nconst marquee = ref<{ x: number; y: number; width: number; height: number } | null>(null)\nconst connection = shallowRef<{ from: { x: number; y: number; position: FlowPosition }; to: FlowXY; toPosition: FlowPosition | null; type: 'source' | 'target'; edgeType: string } | null>(null)\nconst connectionTarget = ref<{ key: string; valid: boolean } | null>(null)\nconst connecting = computed(() => !!connection.value)\nconst guideLines = shallowRef<{ x?: number; y?: number; from: number; to: number }[]>([])\nconst panning = ref(false)\n\nfunction addWindowListeners() {\n window.addEventListener('pointermove', onWindowMove)\n window.addEventListener('pointerup', onWindowUp)\n window.addEventListener('pointercancel', onWindowCancel)\n}\nfunction removeWindowListeners() {\n window.removeEventListener('pointermove', onWindowMove)\n window.removeEventListener('pointerup', onWindowUp)\n window.removeEventListener('pointercancel', onWindowCancel)\n unblockTouchScroll()\n}\n\n// A touch handed over by startDrag began outside the canvas (a palette, a sheet), so its touch-action is that\n// element's and the browser would scroll or cancel it. Its touchmoves go to where it began, even once that's\n// gone from the page, so they're cancelled there (and on window) until the drag ends\nlet touchBlocked: EventTarget[] = []\nfunction preventTouch(e: TouchEvent) {\n if (e.cancelable) e.preventDefault()\n}\nfunction blockTouchScroll(target: EventTarget | null) {\n unblockTouchScroll()\n touchBlocked = target && target !== window ? [target, window] : [window]\n for (const t of touchBlocked) t.addEventListener('touchmove', preventTouch as EventListener, { passive: false })\n}\nfunction unblockTouchScroll() {\n for (const t of touchBlocked) t.removeEventListener('touchmove', preventTouch as EventListener)\n touchBlocked = []\n}\n\nfunction onPointerDown(e: PointerEvent) {\n const t = e.target as HTMLElement\n if (onOverlay(t)) return\n if (e.pointerType === 'touch') {\n // With no gesture running nothing listens for fingers lifting: whatever is left in the map is stale\n if (!gesture) touches.clear()\n touches.set(e.pointerId, { x: e.clientX, y: e.clientY })\n if (touches.size === 2) {\n // A second finger: whatever the first one started becomes a pinch\n cancelGesture()\n startPinch()\n return\n }\n if (touches.size > 2) return\n }\n if (gesture) return\n if (e.button === 2) return\n downTarget = t\n root.value?.focus({ preventScroll: true })\n\n const handle = t.closest<HTMLElement>('[data-flow-handle]')\n const reconnect = t.closest<HTMLElement>('[data-flow-reconnect]')\n const nodeEl = t.closest<HTMLElement>('[data-flow-node]')\n const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')\n if (e.button === 1) return startPan(e)\n\n const deleteButton = t.closest<HTMLElement>('[data-flow-edge-delete]')\n if (deleteButton) {\n e.preventDefault()\n remove({ edges: [deleteButton.dataset.flowEdgeDelete!] })\n return\n }\n if (reconnect && edgeEl) {\n const edge = edgeById.value.get(edgeEl.dataset.flowEdge!)\n if (edge && isReconnectable(edge)) {\n e.preventDefault()\n return startReconnect(e, edge, reconnect.dataset.flowReconnect as 'source' | 'target')\n }\n }\n if (handle && nodeEl && handle.dataset.flowConnectable === 'true' && nodesConnectable.value) {\n e.preventDefault()\n e.stopPropagation()\n // A connected input pulls its (last) edge off instead: drop it on another node, or on nothing to disconnect\n if (handle.dataset.flowHandle === 'target') {\n const nodeId = nodeEl.dataset.flowNode!\n const hid = handle.dataset.handleId || null\n const attached = visibleEdges.value.filter((ed) => ed.target === nodeId && (ed.targetHandle ?? null) === hid && isReconnectable(ed))\n const edge = attached[attached.length - 1]\n if (edge) return startReconnect(e, edge, 'target')\n }\n return startConnection(e, nodeEl.dataset.flowNode!, handle.dataset.handleId || null, handle.dataset.flowHandle as 'source' | 'target')\n }\n if (nodeEl) {\n if (t.closest(NO_DRAG) && t.closest(NO_DRAG) !== nodeEl) return\n return startNode(e, nodeEl.dataset.flowNode!)\n }\n if (edgeEl) {\n // Edges select on the click (pointerup) so a drag across them still pans, or branches (edgeBranching)\n const touch = e.pointerType === 'touch'\n const edge = edgeById.value.get(edgeEl.dataset.flowEdge!)\n const branch = edge && branching.value && (!touch || selectedEdges.value.has(edge.id)) ? edge : undefined\n if (branch) e.preventDefault()\n gesture = { kind: 'pan', id: e.pointerId, sx: e.clientX, sy: e.clientY, vx: vp.value.x, vy: vp.value.y, moved: false, target: 'pane', touch, branch }\n addWindowListeners()\n return\n }\n if (e.shiftKey || (props.selectionOnDrag && e.pointerType !== 'touch') || !props.panOnDrag) {\n if (canSelect.value) return startMarquee(e)\n }\n startPan(e)\n}\n\n// On touch there's no Shift: holding a finger still on the background starts a selection box instead\nconst LONG_PRESS = 450\nlet longPress: ReturnType<typeof setTimeout> | undefined\nfunction startPan(e: PointerEvent) {\n const touch = e.pointerType === 'touch'\n const g: Gesture = { kind: 'pan', id: e.pointerId, sx: e.clientX, sy: e.clientY, vx: vp.value.x, vy: vp.value.y, moved: false, target: 'pane', touch }\n gesture = g\n vpAnim = null\n addWindowListeners()\n clearTimeout(longPress)\n if (touch && canSelect.value) {\n longPress = setTimeout(() => {\n if (gesture !== g || g.moved) return\n const r = rootRect()\n const x = g.sx - r.left\n const y = g.sy - r.top\n gesture = { kind: 'marquee', id: g.id, sx: x, sy: y, x, y, additive: [...selLocal.value.nodes], moved: true }\n marquee.value = { x, y, width: 0, height: 0 }\n navigator.vibrate?.(10)\n }, LONG_PRESS)\n }\n}\nfunction startMarquee(e: PointerEvent) {\n const r = rootRect()\n gesture = { kind: 'marquee', id: e.pointerId, sx: e.clientX - r.left, sy: e.clientY - r.top, x: e.clientX - r.left, y: e.clientY - r.top, additive: e.shiftKey ? [...selLocal.value.nodes] : [], moved: false }\n addWindowListeners()\n}\nfunction startNode(e: PointerEvent, nodeId: string) {\n const n = nodeById.value.get(nodeId)\n if (!n) return\n let reselect = false\n if (canSelect.value && n.selectable !== false) {\n if (e.shiftKey || e.metaKey || e.ctrlKey) {\n const has = selectedNodes.value.has(nodeId)\n setSelection({ nodes: has ? selLocal.value.nodes.filter((i) => i !== nodeId) : [...selLocal.value.nodes, nodeId] })\n if (has) return\n } else if (!selectedNodes.value.has(nodeId)) {\n setSelection({ nodes: [nodeId], edges: [] })\n } else reselect = true\n }\n gesture = { kind: 'node', id: e.pointerId, nodeId, sx: e.clientX, sy: e.clientY, touch: e.pointerType === 'touch', active: false, starts: new Map(), moved: false, reselect }\n addWindowListeners()\n}\n\nfunction onWindowMove(e: PointerEvent) {\n pointer.x = e.clientX\n pointer.y = e.clientY\n if (e.pointerType === 'touch' && touches.has(e.pointerId)) {\n touches.set(e.pointerId, { x: e.clientX, y: e.clientY })\n if (pinch) return movePinch()\n }\n const g = gesture\n if (!g || g.kind === 'pinch' || g.id !== e.pointerId) return\n if (g.kind === 'pan') {\n const dx = e.clientX - g.sx\n const dy = e.clientY - g.sy\n if (!g.moved && Math.hypot(dx, dy) < (g.touch ? DRAG_SLOP_TOUCH : DRAG_SLOP_MOUSE)) return\n if (g.branch && !g.moved) return startBranch(g, g.branch, e)\n g.moved = true\n clearTimeout(longPress)\n panning.value = true\n writeViewport({ x: g.vx + dx, y: g.vy + dy, zoom: vp.value.zoom })\n } else if (g.kind === 'marquee') {\n const r = rootRect()\n g.x = e.clientX - r.left\n g.y = e.clientY - r.top\n if (!g.moved && Math.hypot(g.x - g.sx, g.y - g.sy) < DRAG_SLOP_MOUSE) return\n g.moved = true\n updateMarquee(g)\n } else if (g.kind === 'node') {\n if (!g.active) {\n if (Math.hypot(e.clientX - g.sx, e.clientY - g.sy) < (g.touch ? DRAG_SLOP_TOUCH : DRAG_SLOP_MOUSE)) return\n if (!canDrag.value || !beginNodeDrag(g, e)) {\n // Not draggable: the gesture pans instead\n gesture = { kind: 'pan', id: g.id, sx: e.clientX, sy: e.clientY, vx: vp.value.x, vy: vp.value.y, moved: true, target: 'pane' }\n return\n }\n }\n g.moved = true\n moveNodes(g, e.clientX, e.clientY)\n updateInsertTarget(g)\n emit('node-drag', [...g.starts.keys()].map((id) => nodeById.value.get(id)!), e)\n kick()\n } else if (g.kind === 'connect') {\n g.moved = true\n moveConnection(g, e.clientX, e.clientY)\n kick()\n }\n}\n\nfunction onWindowUp(e: PointerEvent) {\n touches.delete(e.pointerId)\n if (pinch) {\n if (touches.size < 2) endPinch()\n return\n }\n const g = gesture\n if (!g || g.kind === 'pinch' || g.id !== e.pointerId) return\n gesture = null\n clearTimeout(longPress)\n removeWindowListeners()\n panning.value = false\n if (g.kind === 'pan') {\n if (!g.moved) clickAt(e)\n } else if (g.kind === 'marquee') {\n marquee.value = null\n if (!g.moved) clickAt(e)\n } else if (g.kind === 'node') {\n if (g.active) endNodeDrag(g, e)\n else {\n if (g.reselect && !e.shiftKey) setSelection({ nodes: [g.nodeId], edges: [] })\n const n = nodeById.value.get(g.nodeId)\n if (n) emit('node-click', n, e)\n }\n } else if (g.kind === 'connect') {\n endConnection(g, e)\n }\n}\nfunction onWindowCancel(e: PointerEvent) {\n clearTimeout(longPress)\n touches.delete(e.pointerId)\n if (pinch) {\n if (touches.size < 2) endPinch()\n return\n }\n cancelGesture()\n}\nfunction cancelGesture() {\n const g = gesture\n gesture = null\n removeWindowListeners()\n panning.value = false\n marquee.value = null\n if (g?.kind === 'node' && g.active) {\n // Back where they were\n for (const [id, p] of g.starts) {\n const s = springs.get(id)\n if (s) { s.tx = p.x; s.ty = p.y }\n }\n dragging.value = new Set()\n frozenGroups.clear()\n guideLines.value = []\n insertEdge.value = null\n insertPlan = null\n kick()\n }\n if (g?.kind === 'connect') {\n connection.value = null\n connectionTarget.value = null\n }\n}\n\n// What the click (a pointerup that didn't move) landed on\nfunction clickAt(e: PointerEvent) {\n const t = downTarget ?? (e.target as HTMLElement)\n const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')\n const edge = edgeEl ? edgeById.value.get(edgeEl.dataset.flowEdge!) : undefined\n if (edge) {\n if (canSelect.value && edge.selectable !== false) {\n if (e.shiftKey) {\n const has = selectedEdges.value.has(edge.id)\n setSelection({ edges: has ? selLocal.value.edges.filter((i) => i !== edge.id) : [...selLocal.value.edges, edge.id] })\n } else setSelection({ nodes: [], edges: [edge.id] })\n }\n emit('edge-click', edge, e)\n return\n }\n if (!e.shiftKey) setSelection(emptySelection())\n emit('pane-click', screenToFlow({ x: e.clientX, y: e.clientY }), e)\n}\n\n// ── Pinch (two fingers on touch) ──────────────────────────────────────────────────────────────────────────\nfunction pinchInfo() {\n const [a, b] = [...touches.values()]\n const r = rootRect()\n return { dist: Math.hypot(a!.x - b!.x, a!.y - b!.y) || 1, cx: (a!.x + b!.x) / 2 - r.left, cy: (a!.y + b!.y) / 2 - r.top }\n}\nfunction startPinch() {\n clearTimeout(longPress)\n const p = pinchInfo()\n vpAnim = null\n gesture = { kind: 'pinch' }\n pinch = { ...p, zoom: vp.value.zoom, fx: (p.cx - vp.value.x) / vp.value.zoom, fy: (p.cy - vp.value.y) / vp.value.zoom }\n addWindowListeners()\n}\n// One finger lifted: the one left on keeps panning (and its pointerup still ends the gesture)\nfunction endPinch() {\n pinch = null\n const rest = [...touches][0]\n if (!rest) { gesture = null; removeWindowListeners(); return }\n const [id, p] = rest\n gesture = { kind: 'pan', id, sx: p.x, sy: p.y, vx: vp.value.x, vy: vp.value.y, moved: true, target: 'pane', touch: true }\n}\nfunction movePinch() {\n if (!pinch || touches.size < 2) return\n const p = pinchInfo()\n const z = clampZoom((pinch.zoom * p.dist) / pinch.dist)\n // The flow point first under the fingers' middle stays under it, wherever the fingers go\n writeViewport({ x: p.cx - pinch.fx * z, y: p.cy - pinch.fy * z, zoom: z })\n}\n\n// ── Wheel and double click ────────────────────────────────────────────────────────────────────────────────\nfunction onWheel(e: WheelEvent) {\n const t = e.target as HTMLElement\n // Over a panel, or content inside a node marked to scroll on its own: the wheel is theirs\n if (onOverlay(t) || t.closest('[data-flow-nowheel]')) return\n e.preventDefault()\n const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? size.value.height : 1\n const r = rootRect()\n if (e.ctrlKey || e.metaKey || props.wheel === 'zoom') {\n const d = Math.max(-50, Math.min(50, e.deltaY * unit))\n zoomAt(vp.value.zoom * Math.exp(-d * 0.01), e.clientX - r.left, e.clientY - r.top)\n vpAnim = null\n return\n }\n const dx = (e.shiftKey && !e.deltaX ? e.deltaY : e.deltaX) * unit\n const dy = (e.shiftKey && !e.deltaX ? 0 : e.deltaY) * unit\n vpAnim = null\n writeViewport({ x: vp.value.x - dx, y: vp.value.y - dy, zoom: vp.value.zoom })\n}\nfunction onDblClick(e: MouseEvent) {\n const t = e.target as HTMLElement\n if (onOverlay(t)) return\n const nodeEl = t.closest<HTMLElement>('[data-flow-node]')\n const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')\n if (nodeEl) {\n const n = nodeById.value.get(nodeEl.dataset.flowNode!)\n if (n) emit('node-dblclick', n, e)\n } else if (edgeEl) {\n const ed = edgeById.value.get(edgeEl.dataset.flowEdge!)\n if (ed) emit('edge-dblclick', ed, e)\n } else {\n emit('pane-dblclick', screenToFlow({ x: e.clientX, y: e.clientY }), e)\n if (props.zoomOnDoubleClick) {\n const r = rootRect()\n zoomAt(targetZoom() * 2, e.clientX - r.left, e.clientY - r.top, true)\n }\n }\n}\nfunction onContextMenu(e: MouseEvent) {\n const t = e.target as HTMLElement\n if (onOverlay(t)) return\n // The browser's menu (and a phone's long-press menu) stays closed on the canvas, except in text fields\n if (!props.nativeContextMenu && !t.closest('input, textarea, select, [contenteditable]')) e.preventDefault()\n const nodeEl = t.closest<HTMLElement>('[data-flow-node]')\n const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')\n const n = nodeEl ? nodeById.value.get(nodeEl.dataset.flowNode!) : undefined\n const ed = edgeEl ? edgeById.value.get(edgeEl.dataset.flowEdge!) : undefined\n if (n) emit('node-contextmenu', n, e)\n else if (ed) emit('edge-contextmenu', ed, e)\n else emit('pane-contextmenu', screenToFlow({ x: e.clientX, y: e.clientY }), e)\n}\n\n// ── Selection box ─────────────────────────────────────────────────────────────────────────────────────────\nfunction updateMarquee(g: Extract<Gesture, { kind: 'marquee' }>) {\n const x = Math.min(g.sx, g.x)\n const y = Math.min(g.sy, g.y)\n const w = Math.abs(g.x - g.sx)\n const h = Math.abs(g.y - g.sy)\n marquee.value = { x, y, width: w, height: h }\n const z = vp.value.zoom\n const fx1 = (x - vp.value.x) / z\n const fy1 = (y - vp.value.y) / z\n const fx2 = fx1 + w / z\n const fy2 = fy1 + h / z\n const inside = visibleNodes.value.filter((n) => {\n if (n.selectable === false) return false\n const a = getAbsolutePosition(n.id)\n const s = getSize(n.id)\n return a.x < fx2 && a.x + s.width > fx1 && a.y < fy2 && a.y + s.height > fy1\n }).map((n) => n.id)\n const nodes = [...new Set([...g.additive, ...inside])]\n const set = new Set(nodes)\n setSelection({ nodes, edges: visibleEdges.value.filter((e) => e.selectable !== false && set.has(e.source) && set.has(e.target)).map((e) => e.id) })\n}\n\n// ── Dragging nodes ────────────────────────────────────────────────────────────────────────────────────────\nfunction beginNodeDrag(g: Extract<Gesture, { kind: 'node' }>, e: PointerEvent) {\n const sel = selectedNodes.value.has(g.nodeId) ? selLocal.value.nodes : [g.nodeId]\n // A node whose group moves too comes along by itself\n const ids = sel.filter((id) => {\n const n = nodeById.value.get(id)\n return n && n.draggable !== false && !isHidden(id) && !ancestors(id).some((a) => sel.includes(a))\n })\n if (!ids.includes(g.nodeId) && nodeById.value.get(g.nodeId)?.draggable === false) return false\n if (!ids.length) return false\n for (const id of ids) {\n const s = springs.get(id)!\n g.starts.set(id, { x: s.tx, y: s.ty })\n }\n g.active = true\n for (const id of ids) for (const a of ancestors(id)) if (!frozenGroups.has(a)) frozenGroups.set(a, getSize(a))\n dragging.value = new Set(ids)\n document.body.style.userSelect = 'none'\n emit('node-drag-start', ids.map((id) => nodeById.value.get(id)!), e)\n return true\n}\n\n/**\n * Drags a node with a pointer that's already down (from a palette outside the canvas: add the node under the\n * pointer, then hand it the event). It follows the pointer from there, with the guides and splicing into edges\n */\nfunction startDrag(id: string, e: PointerEvent) {\n if (!nodeById.value.has(id) || locked.value) return\n if (gesture) cancelGesture()\n // A node added this tick has no spring yet\n if (!springs.has(id)) syncPositions()\n if (canSelect.value) setSelection({ nodes: [id], edges: [] })\n const g: Extract<Gesture, { kind: 'node' }> = { kind: 'node', id: e.pointerId, nodeId: id, sx: e.clientX, sy: e.clientY, touch: e.pointerType === 'touch', active: false, starts: new Map(), moved: true, reselect: false }\n gesture = g\n pointer.x = e.clientX\n pointer.y = e.clientY\n addWindowListeners()\n if (g.touch) blockTouchScroll(e.target)\n if (!beginNodeDrag(g, e)) {\n gesture = null\n removeWindowListeners()\n }\n}\n\nconst GUIDE_SNAP = 6\nfunction moveNodes(g: Extract<Gesture, { kind: 'node' }>, cx: number, cy: number) {\n const z = vp.value.zoom\n let dx = (cx - g.sx) / z\n let dy = (cy - g.sy) / z\n const lead = g.starts.get(g.nodeId) ?? [...g.starts.values()][0]!\n const leadId = g.starts.has(g.nodeId) ? g.nodeId : [...g.starts.keys()][0]!\n if (props.snapToGrid) {\n const gs = props.gridSize\n dx = Math.round((lead.x + dx) / gs) * gs - lead.x\n dy = Math.round((lead.y + dy) / gs) * gs - lead.y\n guideLines.value = []\n } else if (props.guides && g.starts.size === 1) {\n const snapped = snapToGuides(leadId, lead, dx, dy)\n dx = snapped.dx\n dy = snapped.dy\n }\n for (const [id, p] of g.starts) {\n let x = p.x + dx\n let y = p.y + dy\n const n = nodeById.value.get(id)!\n const parent = parentOf(id)\n if (n.extent === 'parent' && parent) {\n const ps = getSize(parent)\n const s = getSize(id)\n x = Math.max(0, Math.min(ps.width - s.width, x))\n y = Math.max(0, Math.min(ps.height - s.height, y))\n }\n const s = springs.get(id)!\n s.x = s.tx = x\n s.y = s.ty = y\n s.vx = s.vy = 0\n const d = disp.get(id)!\n d.x = x\n d.y = y\n }\n}\n// Snaps the dragged node's edges and center to other nodes' within a few px, and draws the lines it lines up on\nfunction snapToGuides(id: string, start: FlowXY, dx: number, dy: number) {\n const parentAbs = parentOf(id) ? getAbsolutePosition(parentOf(id)!) : { x: 0, y: 0 }\n const s = getSize(id)\n const ax = parentAbs.x + start.x + dx\n const ay = parentAbs.y + start.y + dy\n const xs = [ax, ax + s.width / 2, ax + s.width]\n const ys = [ay, ay + s.height / 2, ay + s.height]\n const tol = GUIDE_SNAP / vp.value.zoom\n let bestX: { d: number; to: number; box: { y1: number; y2: number } } | null = null\n let bestY: { d: number; to: number; box: { x1: number; x2: number } } | null = null\n const skip = new Set([id, ...descendants(id), ...ancestors(id)])\n for (const n of visibleNodes.value) {\n if (skip.has(n.id)) continue\n const a = getAbsolutePosition(n.id)\n const ns = getSize(n.id)\n const oxs = [a.x, a.x + ns.width / 2, a.x + ns.width]\n const oys = [a.y, a.y + ns.height / 2, a.y + ns.height]\n for (const x of xs) for (const o of oxs) {\n const d = o - x\n if (Math.abs(d) <= tol && (!bestX || Math.abs(d) < Math.abs(bestX.d))) bestX = { d, to: o, box: { y1: a.y, y2: a.y + ns.height } }\n }\n for (const y of ys) for (const o of oys) {\n const d = o - y\n if (Math.abs(d) <= tol && (!bestY || Math.abs(d) < Math.abs(bestY.d))) bestY = { d, to: o, box: { x1: a.x, x2: a.x + ns.width } }\n }\n }\n const lines: { x?: number; y?: number; from: number; to: number }[] = []\n if (bestX) {\n dx += bestX.d\n lines.push({ x: bestX.to, from: Math.min(ay, bestX.box.y1), to: Math.max(ay + s.height, bestX.box.y2) })\n }\n if (bestY) {\n dy += bestY.d\n const nx = parentAbs.x + start.x + dx\n lines.push({ y: bestY.to, from: Math.min(nx, bestY.box.x1), to: Math.max(nx + s.width, bestY.box.x2) })\n }\n guideLines.value = lines\n return { dx, dy }\n}\n\nfunction getIntersectingNodes(target: string | { x: number; y: number; width: number; height: number }) {\n let box: { x: number; y: number; width: number; height: number }\n const skip = new Set<string>()\n if (typeof target === 'string') {\n box = { ...getAbsolutePosition(target), ...getSize(target) }\n skip.add(target)\n descendants(target).forEach((d) => skip.add(d))\n ancestors(target).forEach((a) => skip.add(a))\n } else box = target\n return visibleNodes.value.filter((n) => {\n if (skip.has(n.id) || n.type === 'group') return false\n const a = getAbsolutePosition(n.id)\n const s = getSize(n.id)\n return a.x < box.x + box.width && a.x + s.width > box.x && a.y < box.y + box.height && a.y + s.height > box.y\n })\n}\n\n// ── A lone node dropped onto an edge splices into it ─────────────────────────────────────────────────────\nconst insertEdge = ref<string | null>(null)\nlet insertPlan: { node: string; edge: FlowEdge; connections: [FlowConnection, FlowConnection] } | null = null\nfunction updateInsertTarget(g: Extract<Gesture, { kind: 'node' }>) {\n insertPlan = null\n const found = findInsert(g)\n insertPlan = found\n insertEdge.value = found?.edge.id ?? null\n}\nfunction findInsert(g: Extract<Gesture, { kind: 'node' }>): typeof insertPlan {\n if (!props.insertOnEdge || g.starts.size !== 1 || !nodesConnectable.value) return null\n const id = [...g.starts.keys()][0]!\n const n = nodeById.value.get(id)\n if (!n || n.type === 'group' || n.connectable === false || n.insertable === false) return null\n if (edgesLocal.value.some((e) => e.source === id || e.target === id)) return null\n // It needs a way in and a way out (or no handles at all: then edges meet its sides; a circle's meet the circle)\n let target: string | null = null\n let source: string | null = null\n const list = handles.get(id)\n if (list?.length) {\n const t = list.find((h) => h.type === 'target' && h.connectable)\n const s = list.find((h) => h.type === 'source' && h.connectable)\n if ((!t && n.type !== 'circle') || (!s && n.type !== 'circle')) return null\n target = t?.id ?? null\n source = s?.id ?? null\n }\n // The node's center over the edge, within half its height\n const a = getAbsolutePosition(id)\n const size = getSize(id)\n const cx = a.x + size.width / 2\n const cy = a.y + size.height / 2\n const reach = Math.max(8 / vp.value.zoom, Math.min(size.width, size.height) / 2)\n let best: { edge: FlowEdge; d: number } | null = null\n for (const e of visibleEdges.value) {\n if (e.deletable === false) continue\n const geo = edgeGeometry(e)\n if (!geo) continue\n const d = distanceToPoints(cx, cy, edgePathPoints(edgeType(e), geo))\n if (d <= reach && (!best || d < best.d)) best = { edge: e, d }\n }\n if (!best) return null\n const e = best.edge\n const c1: FlowConnection = { source: e.source, sourceHandle: e.sourceHandle ?? null, target: id, targetHandle: target }\n const c2: FlowConnection = { source: id, sourceHandle: source, target: e.target, targetHandle: e.targetHandle ?? null }\n if (!isValid(c1) || !isValid(c2)) return null\n return { node: id, edge: e, connections: [c1, c2] }\n}\n\n// Room between spliced-in nodes, along the flow's direction\nconst SPLICE_GAP = 48\nfunction makeRoom(nodes: FlowNode[], plan: NonNullable<typeof insertPlan>): FlowNode[] {\n const byId = new Map(nodes.map((n) => [n.id, n]))\n const a = byId.get(plan.edge.source)\n const b = byId.get(plan.node)\n const c = byId.get(plan.edge.target)\n // Only among siblings: positions are relative to the same parent\n if (!a || !b || !c || a.parentId !== b.parentId || b.parentId !== c.parentId) return nodes\n const horizontal = props.direction !== 'vertical'\n const k = horizontal ? 'x' : 'y'\n const len = (id: string) => (horizontal ? getSize(id).width : getSize(id).height)\n const aEnd = a.position[k] + len(a.id)\n // C must come after A for \"after\" to mean anything (a loop back or a sideways edge is left alone)\n if (c.position[k] < aEnd) return nodes\n const bStart = Math.max(b.position[k], aEnd + SPLICE_GAP)\n const push = Math.max(0, bStart + len(b.id) + SPLICE_GAP - c.position[k])\n // C and everything downstream of it (A, B and A's own ancestors stay put)\n const moving = new Set<string>()\n if (push > 0) {\n const out = new Map<string, string[]>()\n for (const e of edgesLocal.value) if (e !== plan.edge) (out.get(e.source) ?? out.set(e.source, []).get(e.source)!).push(e.target)\n const queue = [c.id]\n while (queue.length) {\n const id = queue.shift()!\n if (moving.has(id) || id === a.id || id === b.id) continue\n const n = byId.get(id)\n if (!n || n.parentId !== c.parentId) continue\n moving.add(id)\n queue.push(...(out.get(id) ?? []))\n }\n }\n if (bStart === b.position[k] && !moving.size) return nodes\n return nodes.map((n) => {\n if (n.id === b.id) return { ...n, position: { ...n.position, [k]: bStart } }\n if (moving.has(n.id)) return { ...n, position: { ...n.position, [k]: n.position[k] + push } }\n return n\n })\n}\n\nfunction endNodeDrag(g: Extract<Gesture, { kind: 'node' }>, e: PointerEvent) {\n document.body.style.userSelect = ''\n const plan = insertPlan\n insertPlan = null\n insertEdge.value = null\n // The two edges that take the old one's place, with its look (not its label)\n let spliced: FlowEdge[] | undefined\n if (plan && props.autoConnect) {\n const { id: _id, label: _label, source: _s, target: _t, sourceHandle: _sh, targetHandle: _th, ...look } = plan.edge\n spliced = plan.connections.map((c) => ({ ...look, id: makeId('edge'), ...c }))\n }\n guideLines.value = []\n const moved = [...g.starts.keys()].filter((id) => {\n const s = springs.get(id)!\n const p = g.starts.get(id)!\n return s.tx !== p.x || s.ty !== p.y\n })\n // Reparent into the group under the pointer\n const reparent = new Map<string, string | undefined>()\n if (props.dropIntoGroups) {\n const at = screenToFlow({ x: e.clientX, y: e.clientY })\n for (const id of g.starts.keys()) {\n const n = nodeById.value.get(id)!\n if (n.type === 'group') continue\n const skip = new Set([id, ...descendants(id)])\n const group = groupNodes.value\n .filter((gn) => !skip.has(gn.id))\n .filter((gn) => {\n const a = getAbsolutePosition(gn.id)\n const s = getSize(gn.id)\n return at.x >= a.x && at.x <= a.x + s.width && at.y >= a.y && at.y <= a.y + s.height\n })\n .sort((a, b) => depthOf(b.id) - depthOf(a.id))[0]\n if ((group?.id ?? undefined) !== (n.parentId ?? undefined)) reparent.set(id, group?.id)\n }\n }\n if (moved.length || reparent.size) {\n const movedSet = new Set(moved)\n const nodes = nodesLocal.value.map((n) => {\n if (!movedSet.has(n.id) && !reparent.has(n.id)) return n\n const s = springs.get(n.id)!\n let position = { x: s.tx, y: s.ty }\n let parentId = n.parentId\n if (reparent.has(n.id)) {\n const abs = getAbsolutePosition(n.id)\n parentId = reparent.get(n.id)\n const pa = parentId ? getAbsolutePosition(parentId) : { x: 0, y: 0 }\n position = { x: abs.x - pa.x, y: abs.y - pa.y }\n const sp = springs.get(n.id)!\n sp.x = sp.tx = position.x\n sp.y = sp.ty = position.y\n const d = disp.get(n.id)!\n d.x = position.x\n d.y = position.y\n }\n const out: FlowNode = { ...n, position }\n if (parentId) out.parentId = parentId\n else delete out.parentId\n return out\n })\n // Spliced in without room: it moves to sit after A, and C with everything after it moves on to make room\n const placed = spliced && plan ? makeRoom(nodes, plan) : nodes\n // Let go first, so the spliced node springs to its place too\n if (spliced) dragging.value = new Set()\n commit({ nodes: placed, edges: spliced ? [...edgesLocal.value.filter((x) => x !== plan!.edge), ...spliced] : undefined })\n const first = nodeById.value.get(g.nodeId)\n if (first) announce(locale.flowMoved.replace('{label}', nodeLabel(first)))\n }\n dragging.value = new Set()\n frozenGroups.clear()\n const draggedNodes = [...g.starts.keys()].map((id) => nodeById.value.get(id)!).filter(Boolean)\n if (plan) emit('insert', { node: nodeById.value.get(plan.node)!, edge: plan.edge, connections: plan.connections })\n emit('node-drag-stop', { nodes: draggedNodes, intersecting: getIntersectingNodes(g.nodeId), event: e })\n}\n\n// Near the edges while dragging, the view scrolls (and what's dragged comes along)\nconst EDGE_ZONE = 40\nfunction autoPan(dt: number) {\n const g = gesture\n if (!g || (g.kind !== 'node' && g.kind !== 'connect') || !g.moved) return false\n const r = rootRect()\n const px = pointer.x - r.left\n const py = pointer.y - r.top\n const speed = 600\n const vx = px < EDGE_ZONE ? 1 - px / EDGE_ZONE : px > r.width - EDGE_ZONE ? -(1 - (r.width - px) / EDGE_ZONE) : 0\n const vy = py < EDGE_ZONE ? 1 - py / EDGE_ZONE : py > r.height - EDGE_ZONE ? -(1 - (r.height - py) / EDGE_ZONE) : 0\n if (!vx && !vy) return false\n const mx = Math.max(-1, Math.min(1, vx)) * speed * dt\n const my = Math.max(-1, Math.min(1, vy)) * speed * dt\n writeViewport({ x: vp.value.x + mx, y: vp.value.y + my, zoom: vp.value.zoom })\n if (g.kind === 'node') {\n // The drag's start shifts with the view so the nodes stay under the pointer\n g.sx += mx\n g.sy += my\n moveNodes(g, pointer.x, pointer.y)\n } else moveConnection(g, pointer.x, pointer.y)\n return true\n}\n\n// ── Connecting ────────────────────────────────────────────────────────────────────────────────────────────\nfunction startConnection(e: PointerEvent, nodeId: string, handleId: string | null, type: 'source' | 'target') {\n const from = handlePoint(nodeId, type, handleId)\n if (!from) return\n gesture = { kind: 'connect', id: e.pointerId, from: { nodeId, handleId, type }, moved: false }\n connection.value = { from, to: { x: from.x, y: from.y }, toPosition: null, type, edgeType: edgeRoute({ ...props.defaultEdgeOptions }) }\n pointer.x = e.clientX\n pointer.y = e.clientY\n emit('connect-start', { nodeId, handleId, type })\n addWindowListeners()\n}\n// A branch: a new connection from the edge's source, its preview leaving from where the edge was grabbed\nfunction startBranch(pan: { id: number; sx: number; sy: number }, edge: FlowEdge, e: PointerEvent) {\n const src = handlePoint(edge.source, 'source', edge.sourceHandle)\n if (!src) return\n const handleId = edge.sourceHandle ?? null\n const g: Gesture = { kind: 'connect', id: pan.id, from: { nodeId: edge.source, handleId, type: 'source' }, moved: true }\n gesture = g\n const at = screenToFlow({ x: pan.sx, y: pan.sy })\n connection.value = { from: { x: at.x, y: at.y, position: src.position }, to: at, toPosition: null, type: 'source', edgeType: edgeRoute(edge) }\n emit('connect-start', { nodeId: edge.source, handleId, type: 'source' })\n moveConnection(g, e.clientX, e.clientY)\n kick()\n}\nfunction startReconnect(e: PointerEvent, edge: FlowEdge, end: 'source' | 'target') {\n // Dragging the target end: the connection runs from the source, and the other way round\n const fixed = end === 'target' ? { nodeId: edge.source, handleId: edge.sourceHandle ?? null, type: 'source' as const } : { nodeId: edge.target, handleId: edge.targetHandle ?? null, type: 'target' as const }\n const from = handlePoint(fixed.nodeId, fixed.type, fixed.handleId)\n if (!from) return\n gesture = { kind: 'connect', id: e.pointerId, from: fixed, reconnect: { edge, end }, moved: false }\n const to = screenToFlow({ x: e.clientX, y: e.clientY })\n connection.value = { from, to, toPosition: null, type: fixed.type, edgeType: edgeRoute(edge) }\n pointer.x = e.clientX\n pointer.y = e.clientY\n addWindowListeners()\n}\nconst handleKey = (nodeId: string, h: { id: string | null; type: string }) => `${nodeId}:${h.id ?? ''}:${h.type}`\nfunction connectionFor(from: { nodeId: string; handleId: string | null; type: 'source' | 'target' }, nodeId: string, handleId: string | null): FlowConnection {\n return from.type === 'source'\n ? { source: from.nodeId, sourceHandle: from.handleId, target: nodeId, targetHandle: handleId }\n : { source: nodeId, sourceHandle: handleId, target: from.nodeId, targetHandle: from.handleId }\n}\nfunction isValid(c: FlowConnection, ignore?: FlowEdge) {\n if (c.source === c.target) return false\n const dup = edgesLocal.value.some((e) => e !== ignore && e.source === c.source && e.target === c.target && (e.sourceHandle ?? null) === c.sourceHandle && (e.targetHandle ?? null) === c.targetHandle)\n if (dup) return false\n return props.isValidConnection ? props.isValidConnection(c) : true\n}\nlet connectionCandidate: { nodeId: string; handleId: string | null; valid: boolean } | null = null\nfunction moveConnection(g: Extract<Gesture, { kind: 'connect' }>, cx: number, cy: number) {\n const p = screenToFlow({ x: cx, y: cy })\n const want = g.from.type === 'source' ? 'target' : 'source'\n const radius = props.connectionRadius / vp.value.zoom\n let best: { nodeId: string; h: FlowHandleBounds | null; d: number; x: number; y: number; position: FlowPosition } | null = null\n for (const n of visibleNodes.value) {\n if (n.connectable === false) continue\n const a = getAbsolutePosition(n.id)\n const s = getSize(n.id)\n const over = p.x >= a.x && p.x <= a.x + s.width && p.y >= a.y && p.y <= a.y + s.height\n const list = (handles.get(n.id) ?? []).filter((h) => h.type === want && h.connectable)\n if (list.length) {\n for (const h of list) {\n const x = a.x + h.x\n const y = a.y + h.y\n const d = Math.hypot(x - p.x, y - p.y)\n // Over the node's body, its nearest handle counts too (easier on touch)\n if ((d <= radius || over) && (!best || d < best.d)) best = { nodeId: n.id, h, d: over && d > radius ? d + radius : d, x, y, position: h.position }\n }\n } else if (over) {\n // A node without a handle of that kind connects at its side (a circle, at its center)\n const position = sidePositions(n)[want]\n const sp = sidePoint(n.id, position)\n const d = Math.hypot(sp.x - p.x, sp.y - p.y)\n if (!best || d < best.d) best = { nodeId: n.id, h: null, d, x: sp.x, y: sp.y, position }\n }\n }\n if (best && best.nodeId === g.from.nodeId) best = null\n const cur = connection.value!\n if (best) {\n const c = connectionFor(g.from, best.nodeId, best.h?.id ?? null)\n const valid = isValid(c, g.reconnect?.edge)\n connectionCandidate = { nodeId: best.nodeId, handleId: best.h?.id ?? null, valid }\n connectionTarget.value = { key: handleKey(best.nodeId, { id: best.h?.id ?? null, type: want }), valid }\n connection.value = { ...cur, to: valid ? { x: best.x, y: best.y } : p, toPosition: valid ? best.position : null }\n } else {\n connectionCandidate = null\n connectionTarget.value = null\n connection.value = { ...cur, to: p, toPosition: null }\n }\n}\nfunction endConnection(g: Extract<Gesture, { kind: 'connect' }>, e: PointerEvent) {\n const cand = connectionCandidate\n connectionCandidate = null\n connection.value = null\n connectionTarget.value = null\n const position = screenToFlow({ x: e.clientX, y: e.clientY })\n const c = cand?.valid ? connectionFor(g.from, cand.nodeId, cand.handleId) : null\n if (g.reconnect) {\n const edge = g.reconnect.edge\n if (c) {\n emit('reconnect', { edge, connection: c })\n if (props.autoConnect) updateEdge(edge.id, { source: c.source, target: c.target, sourceHandle: c.sourceHandle, targetHandle: c.targetHandle })\n } else if (g.moved && !cand && edge.deletable !== false) {\n // Pulled off and dropped on nothing: disconnected (dropped on a handle it can't join, it stays)\n remove({ edges: [edge.id] })\n }\n return\n }\n if (c) {\n emit('connect', c)\n if (props.autoConnect) {\n addEdges({ ...props.defaultEdgeOptions, id: makeId('edge'), ...c })\n const s = nodeById.value.get(c.source)\n const t = nodeById.value.get(c.target)\n if (s && t) announce(locale.flowConnected.replace('{source}', nodeLabel(s)).replace('{target}', nodeLabel(t)))\n }\n }\n emit('connect-end', { connection: c, position, from: g.from })\n}\nconst connectionPath = computed(() => {\n const c = connection.value\n if (!c) return ''\n const flip = c.type === 'target'\n const opposite: Record<FlowPosition, FlowPosition> = { top: 'bottom', bottom: 'top', left: 'right', right: 'left' }\n const toPos = c.toPosition ?? opposite[c.from.position]\n const ends = flip\n ? { sourceX: c.to.x, sourceY: c.to.y, sourcePosition: toPos, targetX: c.from.x, targetY: c.from.y, targetPosition: c.from.position }\n : { sourceX: c.from.x, sourceY: c.from.y, sourcePosition: c.from.position, targetX: c.to.x, targetY: c.to.y, targetPosition: toPos }\n return pathFor(c.edgeType, ends).path\n})\n\n// ── Keyboard ──────────────────────────────────────────────────────────────────────────────────────────────\nconst nodeLabel = (n: FlowNode) => String((n.data as { label?: unknown } | undefined)?.label ?? n.id)\nfunction isTyping(t: EventTarget | null) {\n const el = t as HTMLElement | null\n return !!el?.closest?.('input, textarea, select, [contenteditable]:not([contenteditable=\"false\"])')\n}\nfunction onKeyDown(e: KeyboardEvent) {\n if (isTyping(e.target)) return\n const mod = e.ctrlKey || e.metaKey\n const key = e.key.toLowerCase()\n if (e.key === 'Escape') {\n if (gesture) cancelGesture()\n else if (selLocal.value.nodes.length || selLocal.value.edges.length) setSelection(emptySelection())\n else return\n e.preventDefault()\n e.stopPropagation()\n return\n }\n if (mod && key === 'z' && !e.shiftKey) { e.preventDefault(); undo(); return }\n if (mod && ((key === 'z' && e.shiftKey) || key === 'y')) { e.preventDefault(); redo(); return }\n if (mod && key === 'a') { e.preventDefault(); selectAll(); return }\n if (mod && key === 'c') { copy(); return }\n if (mod && key === 'x') { e.preventDefault(); cut(); return }\n if (mod && key === 'v') {\n e.preventDefault()\n paste(pointer.inside ? screenToFlow(pointer) : undefined)\n return\n }\n if (props.deleteKeys?.includes(e.key)) { e.preventDefault(); deleteSelection(); return }\n if (!mod && (e.key === '+' || e.key === '=')) { e.preventDefault(); zoomIn(); return }\n if (!mod && (e.key === '-' || e.key === '_')) { e.preventDefault(); zoomOut(); return }\n if (e.key === '!' || (e.shiftKey && e.code === 'Digit1')) { e.preventDefault(); fitView(); return }\n const arrows: Record<string, [number, number]> = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }\n const dir = arrows[e.key]\n if (dir && selLocal.value.nodes.length && canDrag.value) {\n e.preventDefault()\n const step = props.snapToGrid ? props.gridSize : e.shiftKey ? 50 : 10\n const sel = selLocal.value.nodes\n const ids = new Set(sel.filter((id) => nodeById.value.get(id)?.draggable !== false && !ancestors(id).some((a) => sel.includes(a))))\n if (!ids.size) return\n instantNext = true\n commit({ nodes: nodesLocal.value.map((n) => (ids.has(n.id) ? { ...n, position: { x: n.position.x + dir[0] * step, y: n.position.y + dir[1] * step } } : n)) }, { coalesce: `move:${[...ids].join(',')}` })\n const first = nodeById.value.get([...ids][0]!)\n if (first) announce(locale.flowMoved.replace('{label}', nodeLabel(first)))\n } else if (dir && !selLocal.value.nodes.length) {\n e.preventDefault()\n writeViewport({ x: vp.value.x - dir[0] * 40, y: vp.value.y - dir[1] * 40, zoom: vp.value.zoom })\n }\n}\n// Focusing a node (Tab) and Enter/Space on it select it\nfunction onNodeKey(e: KeyboardEvent, id: string) {\n if (isTyping(e.target) || (e.target as HTMLElement).dataset.flowNode !== id) return\n if ((e.key === 'Enter' || e.key === ' ') && canSelect.value) {\n e.preventDefault()\n if (e.shiftKey) setSelection({ nodes: selectedNodes.value.has(id) ? selLocal.value.nodes.filter((i) => i !== id) : [...selLocal.value.nodes, id] })\n else setSelection({ nodes: [id], edges: [] })\n }\n}\nfunction onEdgeKey(e: KeyboardEvent, id: string) {\n if ((e.key === 'Enter' || e.key === ' ') && canSelect.value) {\n e.preventDefault()\n setSelection({ nodes: [], edges: [id] })\n }\n}\n\n// ── Background ────────────────────────────────────────────────────────────────────────────────────────────\nconst patternId = `m3-flow-bg-${Math.random().toString(36).slice(2, 8)}`\nconst pattern = computed(() => {\n let gap = props.gridSize * vp.value.zoom\n // Coarser when zoomed out, so the dots don't turn into a gray haze\n while (gap < 10) gap *= 2\n return { gap, x: ((vp.value.x % gap) + gap) % gap, y: ((vp.value.y % gap) + gap) % gap, r: Math.max(0.6, Math.min(1.4, vp.value.zoom)) }\n})\n\n// ── Context ───────────────────────────────────────────────────────────────────────────────────────────────\nconst context: FlowInternals = {\n nodes: computed(() => nodesLocal.value),\n edges: computed(() => edgesLocal.value),\n viewport: vp,\n minZoom: computed(() => props.minZoom),\n maxZoom: computed(() => props.maxZoom),\n selection: computed(() => selLocal.value),\n size,\n locked,\n getNode,\n getAbsolutePosition,\n getSize,\n getIntersectingNodes,\n screenToFlow,\n flowToScreen,\n setViewport,\n fitView,\n setCenter,\n zoomIn,\n zoomOut,\n zoomTo,\n addNodes,\n addEdges,\n updateNode,\n updateEdge,\n remove,\n setSelection,\n layout: (fn, options) => runLayout(fn, options),\n undo,\n redo,\n canUndo,\n canRedo,\n copy,\n cut,\n paste,\n startDrag,\n registerHandle,\n measureNode: queueMeasure,\n startConnection,\n connectionTarget,\n connecting,\n insertEdge,\n branching,\n nodesConnectable,\n direction: computed(() => props.direction),\n // For the internal node shells and edges\n registerNodeEl,\n selectedNodes,\n selectedEdges,\n dragging,\n isLifted,\n zIndexOf,\n edgeGeometry,\n isReconnectable,\n sidePositions,\n onNodeKey,\n onEdgeKey,\n}\nprovide(FLOW_KEY, context)\n\n// ── Mount ─────────────────────────────────────────────────────────────────────────────────────────────────\nlet ro: ResizeObserver | undefined\nonMounted(async () => {\n const el = root.value!\n el.addEventListener('wheel', onWheel, { passive: false })\n const sizeRo = new ResizeObserver(() => { size.value = { width: el.clientWidth, height: el.clientHeight } })\n sizeRo.observe(el)\n onBeforeUnmount(() => sizeRo.disconnect())\n size.value = { width: el.clientWidth, height: el.clientHeight }\n ro = new ResizeObserver((entries) => {\n for (const en of entries) {\n const id = (en.target as HTMLElement).dataset.flowNode\n if (id) measureNode(id)\n }\n })\n for (const [id, n] of nodeEls) { ro.observe(n); measureNode(id) }\n await nextTick()\n if (props.layout) await runLayout(null, undefined, { history: false })\n await nextTick()\n if (props.fitView) fitView({ animate: false })\n ready.value = true\n emit('init', context)\n})\nonBeforeUnmount(() => {\n root.value?.removeEventListener('wheel', onWheel)\n removeWindowListeners()\n ro?.disconnect()\n if (raf) cancelAnimationFrame(raf)\n clearTimeout(longPress)\n document.body.style.userSelect = ''\n})\n\ndefineExpose(context as FlowContext)\n</script>\n\n<template>\n <div\n ref=\"root\"\n v-bind=\"$attrs\"\n class=\"m3-flow overflow-hidden bg-surface outline-none select-none\"\n :class=\"[panning && 'cursor-grabbing', locked && 'm3-flow-locked']\"\n tabindex=\"0\"\n role=\"application\"\n :aria-label=\"label ?? locale.flowCanvas\"\n aria-roledescription=\"flow\"\n @pointerdown=\"onPointerDown\"\n @pointerenter=\"pointer.inside = true\"\n @pointerleave=\"pointer.inside = false\"\n @dblclick=\"onDblClick\"\n @contextmenu=\"onContextMenu\"\n @keydown=\"onKeyDown\"\n >\n <svg v-if=\"background !== 'none'\" class=\"pointer-events-none absolute inset-0 size-full\" aria-hidden=\"true\">\n <defs>\n <pattern :id=\"patternId\" :x=\"pattern.x\" :y=\"pattern.y\" :width=\"pattern.gap\" :height=\"pattern.gap\" patternUnits=\"userSpaceOnUse\">\n <circle v-if=\"background === 'dots'\" :cx=\"pattern.r\" :cy=\"pattern.r\" :r=\"pattern.r\" class=\"fill-outline-variant\" />\n <path v-else :d=\"`M${pattern.gap} 0 L0 0 0 ${pattern.gap}`\" fill=\"none\" class=\"stroke-outline-variant\" stroke-width=\"1\" />\n </pattern>\n </defs>\n <rect width=\"100%\" height=\"100%\" :fill=\"`url(#${patternId})`\" />\n </svg>\n\n <div\n ref=\"layer\"\n class=\"m3-flow-viewport absolute top-0 left-0 origin-top-left\"\n :style=\"{ transform: `translate(${vp.x}px, ${vp.y}px) scale(${vp.zoom})`, visibility: ready ? undefined : 'hidden' }\"\n >\n <NodeShell v-for=\"n in groupNodes\" :key=\"n.id\" :node=\"n\" :render=\"nodeRenderer(n)\" />\n <svg class=\"m3-flow-edges pointer-events-none absolute top-0 left-0 size-px overflow-visible\" aria-hidden=\"false\">\n <EdgeView v-for=\"e in visibleEdges\" :key=\"e.id\" :edge=\"e\" :render=\"edgeRenderer(e)\" />\n <path\n v-if=\"connection\"\n class=\"m3-flow-connection-line fill-none stroke-primary\"\n :d=\"connectionPath\"\n stroke-width=\"2\"\n :stroke-dasharray=\"connectionTarget?.valid ? undefined : '6 4'\"\n />\n </svg>\n <div class=\"m3-flow-edge-labels absolute top-0 left-0\">\n <template v-for=\"e in visibleEdges\" :key=\"e.id\">\n <EdgeLabel v-if=\"e.label || $slots['edge-label'] || selectedEdges.has(e.id)\" :edge=\"e\" :render=\"$slots['edge-label']\" />\n </template>\n </div>\n <NodeShell v-for=\"n in plainNodes\" :key=\"n.id\" :node=\"n\" :render=\"nodeRenderer(n)\" />\n <svg v-if=\"guideLines.length\" class=\"pointer-events-none absolute top-0 left-0 size-px overflow-visible\" aria-hidden=\"true\">\n <line\n v-for=\"(g, i) in guideLines\"\n :key=\"i\"\n class=\"stroke-primary\"\n stroke-width=\"1\"\n vector-effect=\"non-scaling-stroke\"\n :x1=\"g.x ?? g.from\"\n :x2=\"g.x ?? g.to\"\n :y1=\"g.y ?? g.from\"\n :y2=\"g.y ?? g.to\"\n />\n </svg>\n </div>\n\n <div\n v-if=\"marquee\"\n class=\"m3-flow-marquee pointer-events-none absolute rounded-xs border border-primary bg-primary/8\"\n :style=\"{ left: `${marquee.x}px`, top: `${marquee.y}px`, width: `${marquee.width}px`, height: `${marquee.height}px` }\"\n />\n\n <div v-if=\"!nodesLocal.length && $slots.empty\" class=\"pointer-events-none absolute inset-0 flex items-center justify-center\">\n <div class=\"pointer-events-auto\">\n <slot name=\"empty\" />\n </div>\n </div>\n\n <slot :flow=\"context\" />\n\n <div class=\"sr-only\" aria-live=\"polite\">{{ announcement }}</div>\n </div>\n</template>\n\n<style>\n@layer base {\n .m3-flow {\n position: relative;\n display: block;\n touch-action: none;\n /* No callout (save image, copy) on a long press: a long press there selects */\n -webkit-touch-callout: none;\n }\n}\n.m3-flow-circle {\n transition: background-color 250ms cubic-bezier(0.2, 0, 0, 1), color 250ms cubic-bezier(0.2, 0, 0, 1), border-color 200ms, box-shadow 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.m3-flow-edge-line {\n transition: stroke 250ms cubic-bezier(0.2, 0, 0, 1), stroke-width 250ms cubic-bezier(0.2, 0, 0, 1), fill 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.m3-flow-edge-animated {\n stroke-dasharray: 6 4;\n animation: m3-flow-dash 400ms linear infinite;\n}\n.m3-flow-edge-reverse {\n animation-direction: reverse;\n}\n.m3-flow-edge-dashed {\n stroke-dasharray: 6 4;\n}\n@keyframes m3-flow-dash {\n from { stroke-dashoffset: 10; }\n to { stroke-dashoffset: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n .m3-flow-edge-animated { animation: none; }\n .m3-flow-edge-line { transition: none; }\n}\n</style>\n","<script lang=\"ts\">\nimport type { FlowEdge, FlowNode, FlowSelection } from '../composables/useFlow'\n\n// Copied nodes and edges, shared by every MFlow on the page (copy in one, paste in another)\nlet clipboard: { nodes: FlowNode[]; edges: FlowEdge[] } | null = null\nlet pasteCount = 0\n\nconst randomId = (prefix: string) => `${prefix}-${Math.random().toString(36).slice(2, 9)}`\nconst emptySelection = (): FlowSelection => ({ nodes: [], edges: [] })\n</script>\n\n<script setup lang=\"ts\">\n/**\n * A node editor (not an M3 spec component): nodes you drag around on a canvas that pans and zooms, joined by edges\n * drawn from handle to handle. Built from M3 pieces (nodes are cards, the controls a floating toolbar) with the\n * API shape of Vue Flow / React Flow. Nodes and edges are `v-model`s of plain objects; the view, the selection\n * and the lock are too. Pan by dragging the background (or the wheel, or two fingers), zoom with Ctrl + wheel, a\n * trackpad or touch pinch, or a double click. Shift + drag (or `selectionOnDrag`; on touch, a long press on the\n * background) draws a selection box; Delete\n * removes what's selected, Ctrl+Z/Ctrl+Shift+Z undo and redo, Ctrl+C/X/V/A copy, cut, paste and select all, and\n * the arrows move the selected nodes. A drag from a handle to another connects them; dropped on nothing it fires\n * `connect-end` with the spot, to offer a new node there. To disconnect: the × on a selected edge, Delete, dragging\n * an edge's end (or a connected input) away and dropping it on nothing. Alignment guides show while dragging one node.\n *\n * Nodes are drawn by type: `default`/`input`/`output` (an MFlowNode), `circle` (a vertex: `data.label`, `color`,\n * `badge`, `ring`, `size`; its edges run center to center in any direction), `group` (a box its children move with), or\n * a `#node-<type>` slot of your own with MFlowHandles in it; edges are `bezier`, `smoothstep`, `step`, `straight`\n * or a `#edge-<type>` slot (with `getBezierPath` and friends); `color`, `width`, `dashed`, `animated` and\n * `labelTone` restyle one without a slot, with a transition. `layout` lays them out (`'tree'`, `'layered'` or a\n * function, e.g. one calling dagre) whenever the graph's shape changes. Put `MFlowControls`, `MFlowMinimap` or\n * anything of yours in the default slot: it's drawn over the canvas, the canvas's gestures and wheel leave it alone,\n * and `useFlow()` works inside it. Inside a node, controls (buttons, inputs, links) never start a drag; mark anything\n * else that shouldn't with `data-flow-nodrag`, and an area that scrolls on its own with `data-flow-nowheel`.\n * `startDrag(id, event)` hands a pointer that's already down to a node, to drag something in from outside (a palette).\n *\n * Positions spring to their new place when they change from outside (a layout, an undo); the view springs on\n * `fitView()`/zoom buttons. Nodes are rendered by small components of their own so moving one only redraws it\n * and its edges.\n *\n * @slot default Drawn over the canvas: MFlowControls, MFlowMinimap, panels of yours. Props: `{ flow }`\n * @slot node-<type> A node of that type. Props: `{ node, data, selected, dragging }`\n * @slot edge-<type> An edge of that type, SVG inside a `<g>`. Props: `{ edge, path, labelX, labelY, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, targetAngle, targetInset, selected, highlighted }` (`highlighted`: a dragged node would splice into it)\n * @slot edge-label An edge's label, instead of the default chip. Props: `{ edge, selected }`\n * @slot empty Shown while there are no nodes\n * @event connect A connection was made (it's also added to `edges` with `autoConnect`)\n * @event connect-start A connection drag started from a handle\n * @event connect-end A connection drag ended: `{ connection }` when it connected, else the flow `position` it was dropped at and where it came from\n * @event reconnect An edge's end was moved to another handle: `{ edge, connection }`\n * @event insert A lone node was dropped onto an edge and spliced in: `{ node, edge, connections }` (with `autoConnect`\n * the edge is replaced by the two connections, keeping its type and look)\n * @event node-click / node-dblclick / node-contextmenu `(node, event)`\n * @event node-drag-start / node-drag `(nodes, event)`\n * @event node-drag-stop `{ nodes, intersecting, event }`: `intersecting` are the nodes under the dragged one\n * @event edge-click / edge-dblclick / edge-contextmenu `(edge, event)`\n * @event pane-click / pane-dblclick / pane-contextmenu `(position, event)` with the flow position (turn\n * `zoomOnDoubleClick` off to use the double click yourself, e.g. to add a node there)\n * @event delete Nodes and edges were deleted: `{ nodes, edges }`\n * @event init The canvas measured its nodes (and laid out / fitted them): the flow context\n */\nimport { computed, nextTick, onBeforeUnmount, onMounted, provide, reactive, ref, shallowReactive, shallowRef, toRaw, useSlots, watch } from 'vue'\nimport {\n FLOW_KEY,\n type FlowConnection,\n type FlowContext,\n type FlowEdgeGeometry as EdgeGeometry,\n type FlowFitOptions,\n type FlowHandleBounds,\n type FlowInternals,\n type FlowPosition,\n type FlowViewport,\n type FlowXY,\n} from '../composables/useFlow'\nimport { layoutLayered, layoutTree, type FlowLayout, type FlowLayoutDirection, type FlowLayoutOptions } from '../composables/flowLayout'\nimport { distanceToPoints, edgePathPoints, getBezierPath, getSmoothStepPath, getStepPath, getStraightPath, type FlowEdgePath } from '../composables/flowPaths'\nimport { DEFAULT_SPATIAL } from '../composables/_useSpring'\nimport { prefersReducedMotion } from '../composables/_springAnimation'\nimport { useLocale } from '../composables/useLocale'\nimport NodeShell from './_MFlowNodeShell.vue'\nimport EdgeView from './_MFlowEdge.vue'\nimport EdgeLabel from './_MFlowEdgeLabel.vue'\n\ndefineOptions({ inheritAttrs: false })\n\nconst props = withDefaults(defineProps<{\n nodes?: FlowNode[]\n edges?: FlowEdge[]\n /** The view (v-model) */\n viewport?: FlowViewport\n /** Selected node and edge ids (v-model) */\n selection?: FlowSelection\n /** Switches off moving, connecting, selecting and deleting; the view still pans and zooms (v-model) */\n locked?: boolean\n /** Which way edges run by default: where the default node's handles go and the layout's direction */\n direction?: 'horizontal' | 'vertical'\n background?: 'dots' | 'grid' | 'none'\n /** The background's spacing, and the grid nodes snap to, px */\n gridSize?: number\n snapToGrid?: boolean\n minZoom?: number\n maxZoom?: number\n /** Fits the nodes in view once they're measured, and again after each automatic `layout` */\n fitView?: boolean\n /** What the plain wheel does (Ctrl + wheel always zooms) */\n wheel?: 'pan' | 'zoom'\n /** A double click on the background zooms in */\n zoomOnDoubleClick?: boolean\n /** Dragging the background pans; off, it draws a selection box */\n panOnDrag?: boolean\n /** Dragging the background draws a selection box (Shift + drag always does) */\n selectionOnDrag?: boolean\n nodesDraggable?: boolean\n nodesConnectable?: boolean\n elementsSelectable?: boolean\n edgesReconnectable?: boolean\n /** Merged into edges made by connecting (`type`, `animated`, `markerEnd`…) */\n defaultEdgeOptions?: Partial<FlowEdge>\n /** Adds an edge to `edges` when a connection is made; off, only `connect` fires */\n autoConnect?: boolean\n /** Whether a connection may be made (no duplicates or same-node loops are offered either way) */\n isValidConnection?: (c: FlowConnection) => boolean\n /** How close to a handle a connection snaps to it, px */\n connectionRadius?: number\n /**\n * Asked before anything is deleted (the keyboard, an edge's ×, an edge dropped on nothing, `remove()`), with what\n * would go: return false to keep it, or a Promise (a confirm dialog) that resolves to whether to delete\n */\n beforeDelete?: (items: { nodes: FlowNode[]; edges: FlowEdge[] }) => boolean | Promise<boolean>\n /** Keys that delete the selection; `null` turns deleting off */\n deleteKeys?: string[] | null\n /** Undo and redo (Ctrl+Z, Ctrl+Shift+Z / Ctrl+Y), over every change to nodes and edges */\n history?: boolean\n historySize?: number\n /** Alignment guides while dragging one node */\n guides?: boolean\n /** Lays the nodes out when the graph's shape changes (nodes or edges added, removed, hidden) */\n layout?: 'tree' | 'layered' | FlowLayout | null\n layoutOptions?: FlowLayoutOptions\n /**\n * A node with no connections dropped onto an edge splices into it: A → C becomes A → B → C (the edge lights up\n * while it's over one). Only when both new connections are valid. Without room between A and C, the node moves\n * to sit after A and C moves on (with everything after it) along the flow's `direction`\n */\n insertOnEdge?: boolean\n /** Nodes dropped onto a `group` join it (and leave it when dropped outside) */\n dropIntoGroups?: boolean\n /** Positions spring to their new place when they change from outside */\n animate?: boolean\n /** Makes ids for pasted nodes and new edges */\n getId?: (kind: 'node' | 'edge') => string\n /**\n * A drag that starts on an edge draws a new edge from the same source, a branch, as in a circuit editor (the\n * preview leaves from where you grabbed it). A click still selects the edge; with a finger, only a selected edge\n * branches, so a swipe across one still pans\n */\n edgeBranching?: boolean\n /**\n * Let the browser's own context menu open on the canvas (right click, or a long press on a phone). Off by default:\n * the `*-contextmenu` events still fire, for a menu of your own (MContextMenu's `showAt`). Text fields inside\n * nodes always keep it, for copy and paste\n */\n nativeContextMenu?: boolean\n /** The canvas's accessible name */\n label?: string\n}>(), {\n nodes: () => [],\n edges: () => [],\n viewport: undefined,\n selection: undefined,\n locked: false,\n direction: 'horizontal',\n background: 'dots',\n gridSize: 20,\n snapToGrid: false,\n minZoom: 0.2,\n maxZoom: 4,\n fitView: false,\n wheel: 'pan',\n zoomOnDoubleClick: true,\n panOnDrag: true,\n selectionOnDrag: false,\n nodesDraggable: true,\n nodesConnectable: true,\n elementsSelectable: true,\n edgesReconnectable: true,\n autoConnect: true,\n connectionRadius: 24,\n deleteKeys: () => ['Delete', 'Backspace'],\n history: true,\n historySize: 100,\n guides: true,\n layout: null,\n dropIntoGroups: false,\n insertOnEdge: true,\n edgeBranching: false,\n nativeContextMenu: false,\n animate: true,\n})\n\nconst emit = defineEmits<{\n 'update:nodes': [FlowNode[]]\n 'update:edges': [FlowEdge[]]\n 'update:viewport': [FlowViewport]\n 'update:selection': [FlowSelection]\n 'update:locked': [boolean]\n connect: [FlowConnection]\n 'connect-start': [{ nodeId: string; handleId: string | null; type: 'source' | 'target' }]\n 'connect-end': [{ connection: FlowConnection | null; position: FlowXY; from: { nodeId: string; handleId: string | null; type: 'source' | 'target' } }]\n reconnect: [{ edge: FlowEdge; connection: FlowConnection }]\n insert: [{ node: FlowNode; edge: FlowEdge; connections: [FlowConnection, FlowConnection] }]\n 'node-click': [FlowNode, MouseEvent]\n 'node-dblclick': [FlowNode, MouseEvent]\n 'node-contextmenu': [FlowNode, MouseEvent]\n 'node-drag-start': [FlowNode[], PointerEvent]\n 'node-drag': [FlowNode[], PointerEvent]\n 'node-drag-stop': [{ nodes: FlowNode[]; intersecting: FlowNode[]; event: PointerEvent }]\n 'edge-click': [FlowEdge, MouseEvent]\n 'edge-dblclick': [FlowEdge, MouseEvent]\n 'edge-contextmenu': [FlowEdge, MouseEvent]\n 'pane-click': [FlowXY, MouseEvent]\n 'pane-contextmenu': [FlowXY, MouseEvent]\n 'pane-dblclick': [FlowXY, MouseEvent]\n delete: [{ nodes: FlowNode[]; edges: FlowEdge[] }]\n init: [FlowContext]\n}>()\n\nconst slots = useSlots()\nconst locale = useLocale()\nconst root = ref<HTMLElement>()\nconst layer = ref<HTMLElement>()\n// What's in the default slot (controls, a minimap, panels of yours) sits over the canvas: the canvas's gestures and\n// wheel leave it alone, so it needs no marking\nconst onOverlay = (t: EventTarget | null) => !!t && t !== root.value && !layer.value?.contains(t as Node)\nconst size = ref({ width: 0, height: 0 })\nconst ready = ref(false)\nconst announcement = ref('')\nconst announce = (m: string) => {\n announcement.value = ''\n nextTick(() => (announcement.value = m))\n}\nconst makeId = (kind: 'node' | 'edge') => props.getId?.(kind) ?? randomId(kind === 'node' ? 'n' : 'e')\n\n// ── Nodes, edges, selection, lock: local copies of the v-models (they work unbound too) ──────────────────\nconst nodesLocal = shallowRef<FlowNode[]>(props.nodes)\nconst edgesLocal = shallowRef<FlowEdge[]>(props.edges)\nconst selLocal = shallowRef<FlowSelection>(props.selection ?? emptySelection())\nconst lockedLocal = ref(props.locked)\nwatch(() => props.selection, (s) => { if (s && !same(s, selLocal.value)) selLocal.value = s })\nwatch(() => props.locked, (l) => { lockedLocal.value = l })\nconst locked = computed({\n get: () => lockedLocal.value,\n set: (v: boolean) => {\n lockedLocal.value = v\n emit('update:locked', v)\n },\n})\n\nconst nodeById = computed(() => new Map(nodesLocal.value.map((n) => [n.id, n])))\nconst edgeById = computed(() => new Map(edgesLocal.value.map((e) => [e.id, e])))\nconst getNode = (id: string) => nodeById.value.get(id)\nconst parentOf = (id: string) => {\n const p = nodeById.value.get(id)?.parentId\n return p && nodeById.value.has(p) ? p : undefined\n}\nfunction ancestors(id: string): string[] {\n const out: string[] = []\n for (let p = parentOf(id); p && out.length < 50; p = parentOf(p)) out.push(p)\n return out\n}\nconst depthOf = (id: string) => ancestors(id).length\nfunction isHidden(id: string) {\n const n = nodeById.value.get(id)\n return !n || !!n.hidden || ancestors(id).some((a) => nodeById.value.get(a)?.hidden)\n}\nconst childrenOf = computed(() => {\n const m = new Map<string, string[]>()\n for (const n of nodesLocal.value) if (n.parentId && nodeById.value.has(n.parentId)) (m.get(n.parentId) ?? m.set(n.parentId, []).get(n.parentId)!).push(n.id)\n return m\n})\nfunction descendants(id: string): string[] {\n const out: string[] = []\n const walk = (i: string) => (childrenOf.value.get(i) ?? []).forEach((c) => { out.push(c); walk(c) })\n walk(id)\n return out\n}\n\nconst selectedNodes = computed(() => new Set(selLocal.value.nodes))\nconst selectedEdges = computed(() => new Set(selLocal.value.edges))\n// Edges branch when dragged (edgeBranching)\nconst branching = computed(() => props.edgeBranching && nodesConnectable.value && !locked.value)\nfunction setSelection(s: Partial<FlowSelection>) {\n const next = { nodes: s.nodes ?? selLocal.value.nodes, edges: s.edges ?? selLocal.value.edges }\n if (sameIds(next.nodes, selLocal.value.nodes) && sameIds(next.edges, selLocal.value.edges)) return\n selLocal.value = next\n emit('update:selection', next)\n}\nconst sameIds = (a: string[], b: string[]) => a.length === b.length && a.every((x, i) => x === b[i])\nconst canSelect = computed(() => props.elementsSelectable && !locked.value)\nconst canDrag = computed(() => props.nodesDraggable && !locked.value)\nconst nodesConnectable = computed(() => props.nodesConnectable && !locked.value)\n\n// ── History: every change to nodes/edges, ours or the parent's, is a step ────────────────────────────────\ntype Snapshot = { nodes: FlowNode[]; edges: FlowEdge[] }\nconst past = shallowRef<Snapshot[]>([])\nconst future = shallowRef<Snapshot[]>([])\nlet lastCoalesce: { key: string; at: number } | null = null\nconst snapshot = (): Snapshot => ({ nodes: nodesLocal.value, edges: edgesLocal.value })\nfunction pushHistory(s: Snapshot, coalesce?: string) {\n if (!props.history) return\n const now = performance.now()\n // Repeated steps of one gesture (arrow-key nudges) make one undo step\n if (coalesce && lastCoalesce?.key === coalesce && now - lastCoalesce.at < 800) {\n lastCoalesce.at = now\n future.value = []\n return\n }\n lastCoalesce = coalesce ? { key: coalesce, at: now } : null\n past.value = [...past.value, s].slice(-props.historySize)\n future.value = []\n}\nlet pendingExternal: Snapshot | null = null\n// What the parent hands back in the same tick as an emit of ours is that change coming back (maybe copied or\n// normalized), not a new step\nlet echo = false\nfunction externalChange() {\n if (echo || pendingExternal) return\n pendingExternal = snapshot()\n queueMicrotask(() => {\n if (pendingExternal) pushHistory(pendingExternal)\n pendingExternal = null\n })\n}\n// What comes back through v-model is often our own array behind a reactive proxy (a parent's `ref([])`)\nconst same = (a: unknown, b: unknown) => toRaw(a) === toRaw(b)\nwatch(() => props.nodes, (n) => {\n if (same(n, nodesLocal.value)) return\n externalChange()\n nodesLocal.value = n\n})\nwatch(() => props.edges, (e) => {\n if (same(e, edgesLocal.value)) return\n externalChange()\n edgesLocal.value = e\n})\n\nfunction commit(next: Partial<Snapshot>, opts: { history?: boolean; coalesce?: string } = {}) {\n if (opts.history !== false) pushHistory(snapshot(), opts.coalesce)\n if (!echo) {\n echo = true\n nextTick(() => (echo = false))\n }\n if (next.nodes && !same(next.nodes, nodesLocal.value)) {\n nodesLocal.value = next.nodes\n emit('update:nodes', next.nodes)\n }\n if (next.edges && !same(next.edges, edgesLocal.value)) {\n edgesLocal.value = next.edges\n emit('update:edges', next.edges)\n }\n}\nfunction applySnapshot(s: Snapshot) {\n commit(s, { history: false })\n const ids = new Set(s.nodes.map((n) => n.id))\n const eids = new Set(s.edges.map((e) => e.id))\n setSelection({ nodes: selLocal.value.nodes.filter((i) => ids.has(i)), edges: selLocal.value.edges.filter((i) => eids.has(i)) })\n}\nfunction undo() {\n const s = past.value[past.value.length - 1]\n if (!s) return\n future.value = [...future.value, snapshot()]\n past.value = past.value.slice(0, -1)\n lastCoalesce = null\n applySnapshot(s)\n}\nfunction redo() {\n const s = future.value[future.value.length - 1]\n if (!s) return\n past.value = [...past.value, snapshot()]\n future.value = future.value.slice(0, -1)\n lastCoalesce = null\n applySnapshot(s)\n}\nconst canUndo = computed(() => past.value.length > 0)\nconst canRedo = computed(() => future.value.length > 0)\n\n// ── Where nodes are drawn: their position, sprung when it changes from outside ──────────────────────────\n// `disp` is reactive (edges and slots read it); the springs are plain and step in one rAF loop that writes\n// each moving node's `disp` once per frame (the library's spring convention, see CLAUDE.md)\ntype Spring2 = { x: number; y: number; vx: number; vy: number; tx: number; ty: number }\nconst disp = shallowReactive(new Map<string, { x: number; y: number }>())\nconst springs = new Map<string, Spring2>()\nconst dragging = shallowRef(new Set<string>())\nlet instantNext = false\n\n// Nodes hidden last time: one that shows again appears at its position instead of sliding in from where it was hidden\nlet wasHidden = new Set<string>()\nfunction syncPositions() {\n const seen = new Set<string>()\n const hiddenNow = new Set<string>()\n const animate = props.animate && ready.value && !instantNext && !prefersReducedMotion()\n for (const n of nodesLocal.value) {\n seen.add(n.id)\n if (isHidden(n.id)) hiddenNow.add(n.id)\n const reappears = wasHidden.has(n.id) && !hiddenNow.has(n.id)\n const d = disp.get(n.id)\n const { x, y } = n.position\n if (!d) {\n disp.set(n.id, reactive({ x, y }))\n springs.set(n.id, { x, y, vx: 0, vy: 0, tx: x, ty: y })\n continue\n }\n const s = springs.get(n.id)!\n if (s.tx === x && s.ty === y && !reappears) continue\n s.tx = x\n s.ty = y\n if (!animate || reappears || dragging.value.has(n.id)) {\n s.x = x\n s.y = y\n s.vx = s.vy = 0\n d.x = x\n d.y = y\n } else kick()\n }\n for (const id of [...disp.keys()]) if (!seen.has(id)) { disp.delete(id); springs.delete(id) }\n wasHidden = hiddenNow\n instantNext = false\n}\nwatch(nodesLocal, syncPositions, { immediate: true })\n\nconst STIFF = DEFAULT_SPATIAL.stiffness\nconst DAMP = 2 * DEFAULT_SPATIAL.dampingRatio * Math.sqrt(STIFF)\nconst SUBSTEP = 0.004\nlet raf = 0\nlet last = 0\nfunction kick() {\n if (raf || typeof requestAnimationFrame === 'undefined') return\n last = performance.now()\n raf = requestAnimationFrame(frame)\n}\nfunction frame(now: number) {\n raf = 0\n const dt = Math.min((now - last) / 1000, 1 / 20)\n last = now\n let moving = false\n for (const [id, s] of springs) {\n if (s.x === s.tx && s.y === s.ty && !s.vx && !s.vy) continue\n for (let t = 0; t < dt; t += SUBSTEP) {\n const h = Math.min(SUBSTEP, dt - t)\n s.vx += (-STIFF * (s.x - s.tx) - DAMP * s.vx) * h\n s.vy += (-STIFF * (s.y - s.ty) - DAMP * s.vy) * h\n s.x += s.vx * h\n s.y += s.vy * h\n }\n if (Math.abs(s.x - s.tx) < 0.1 && Math.abs(s.y - s.ty) < 0.1 && Math.abs(s.vx) < 2 && Math.abs(s.vy) < 2) {\n s.x = s.tx\n s.y = s.ty\n s.vx = s.vy = 0\n } else moving = true\n const d = disp.get(id)\n if (d) { d.x = s.x; d.y = s.y }\n }\n if (stepViewport(dt)) moving = true\n if (autoPan(dt)) moving = true\n if (moving) raf = requestAnimationFrame(frame)\n}\n\nfunction getAbsolutePosition(id: string): FlowXY {\n let x = 0\n let y = 0\n let cur: string | undefined = id\n for (let i = 0; cur && i < 50; i++) {\n const d = disp.get(cur)\n const n = nodeById.value.get(cur)\n x += d?.x ?? n?.position.x ?? 0\n y += d?.y ?? n?.position.y ?? 0\n cur = parentOf(cur)\n }\n return { x, y }\n}\n\n// ── Sizes and handles, measured by the node shells ───────────────────────────────────────────────────────\nconst dims = shallowReactive(new Map<string, { width: number; height: number }>())\nconst handles = shallowReactive(new Map<string, FlowHandleBounds[]>())\nconst nodeEls = new Map<string, HTMLElement>()\ntype HandleReg = { el: HTMLElement; info: () => Omit<FlowHandleBounds, 'x' | 'y'> }\nconst handleRegs = new Map<string, Set<HandleReg>>()\n\nconst GROUP_PAD = 24\nconst GROUP_HEAD = 36\n// Groups around nodes being dragged keep their size until the drop: growing after the child would never let it\n// leave (the pointer would always be inside)\nconst frozenGroups = shallowReactive(new Map<string, { width: number; height: number }>())\nfunction getSize(id: string): { width: number; height: number } {\n const n = nodeById.value.get(id)\n if (!n) return { width: 0, height: 0 }\n if (n.width && n.height) return { width: n.width, height: n.height }\n if (n.type === 'group' && !n.width) {\n const frozen = frozenGroups.get(id)\n if (frozen) return frozen\n // A group without a size wraps its children\n let w = 200\n let h = 120\n for (const c of childrenOf.value.get(id) ?? []) {\n if (isHidden(c)) continue\n const d = disp.get(c)\n const s = getSize(c)\n w = Math.max(w, (d?.x ?? 0) + s.width + GROUP_PAD)\n h = Math.max(h, (d?.y ?? 0) + s.height + GROUP_PAD)\n }\n return { width: n.width ?? w, height: n.height ?? Math.max(h, GROUP_HEAD + GROUP_PAD) }\n }\n const m = dims.get(id)\n return { width: n.width ?? m?.width ?? 0, height: n.height ?? m?.height ?? 0 }\n}\n\nfunction measureNode(id: string) {\n const el = nodeEls.get(id)\n if (!el) return\n const w = el.offsetWidth\n const h = el.offsetHeight\n const prev = dims.get(id)\n if (!prev || prev.width !== w || prev.height !== h) dims.set(id, { width: w, height: h })\n const regs = handleRegs.get(id)\n if (!regs?.size) {\n if (handles.has(id)) handles.delete(id)\n return\n }\n // Handle centers relative to the node's corner, back in flow units (the layer is scaled by the zoom)\n const r = el.getBoundingClientRect()\n const z = vp.value.zoom || 1\n const list: FlowHandleBounds[] = []\n for (const reg of regs) {\n const hr = reg.el.getBoundingClientRect()\n list.push({ ...reg.info(), x: (hr.left + hr.width / 2 - r.left) / z, y: (hr.top + hr.height / 2 - r.top) / z })\n }\n handles.set(id, list)\n}\nlet measureQueued = new Set<string>()\nfunction queueMeasure(id: string) {\n measureQueued.add(id)\n if (measureQueued.size > 1) return\n nextTick(() => {\n const ids = measureQueued\n measureQueued = new Set()\n ids.forEach(measureNode)\n })\n}\nfunction registerHandle(nodeId: string, el: HTMLElement, info: HandleReg['info']) {\n const reg = { el, info }\n ;(handleRegs.get(nodeId) ?? handleRegs.set(nodeId, new Set()).get(nodeId)!).add(reg)\n queueMeasure(nodeId)\n return () => {\n handleRegs.get(nodeId)?.delete(reg)\n queueMeasure(nodeId)\n }\n}\nfunction registerNodeEl(id: string, el: HTMLElement | null) {\n if (el) {\n nodeEls.set(id, el)\n measureNode(id)\n ro?.observe(el)\n } else {\n const old = nodeEls.get(id)\n if (old) ro?.unobserve(old)\n nodeEls.delete(id)\n dims.delete(id)\n handles.delete(id)\n }\n}\n\n// Where an edge's ends are: its handles, else the middle of the node's side\nconst sidePositions = (n: FlowNode) => {\n const v = props.direction === 'vertical'\n return {\n source: n.sourcePosition ?? (v ? 'bottom' : 'right') as FlowPosition,\n target: n.targetPosition ?? (v ? 'top' : 'left') as FlowPosition,\n }\n}\nfunction sidePoint(id: string, pos: FlowPosition): FlowXY {\n const a = getAbsolutePosition(id)\n const s = getSize(id)\n switch (pos) {\n case 'top': return { x: a.x + s.width / 2, y: a.y }\n case 'bottom': return { x: a.x + s.width / 2, y: a.y + s.height }\n case 'left': return { x: a.x, y: a.y + s.height / 2 }\n default: return { x: a.x + s.width, y: a.y + s.height / 2 }\n }\n}\nfunction handlePoint(nodeId: string, type: 'source' | 'target', handleId?: string | null): { x: number; y: number; position: FlowPosition; inset: number } | null {\n const n = nodeById.value.get(nodeId)\n if (!n) return null\n const list = handles.get(nodeId)?.filter((h) => h.type === type)\n const h = list?.length ? (handleId != null ? list.find((x) => x.id === handleId) : list[0]) ?? list[0] : undefined\n if (h) {\n const a = getAbsolutePosition(nodeId)\n return { x: a.x + h.x, y: a.y + h.y, position: h.position, inset: HANDLE_RADIUS }\n }\n const position = sidePositions(n)[type]\n return { ...sidePoint(nodeId, position), position, inset: 0 }\n}\n// Arrowheads stop at a handle's rim instead of under it\nconst HANDLE_RADIUS = 5\n\nfunction pathFor(type: string | undefined, p: Omit<EdgeGeometry, keyof FlowEdgePath | 'sourceInset' | 'targetInset'>): FlowEdgePath {\n switch (type) {\n case 'smoothstep': return getSmoothStepPath(p)\n case 'step': return getStepPath(p)\n case 'straight': return getStraightPath(p)\n default: return getBezierPath(p)\n }\n}\nconst edgeType = (e: FlowEdge) => e.type ?? props.defaultEdgeOptions?.type ?? 'bezier'\n// How it's routed: its own type, or for an `#edge-<type>` slot its `pathType` (default bezier)\nconst edgeRoute = (e: Partial<FlowEdge>) => e.pathType ?? props.defaultEdgeOptions?.pathType ?? edgeType(e as FlowEdge)\n// Opposite edges between two circles sit side by side\nconst pairKeys = computed(() => new Set(edgesLocal.value.map((e) => `${e.source}>${e.target}`)))\nfunction circleOf(id: string) {\n const a = getAbsolutePosition(id)\n const s = getSize(id)\n return { x: a.x + s.width / 2, y: a.y + s.height / 2, r: Math.min(s.width, s.height) / 2 }\n}\n// An edge touching a circle runs between the centers (a straight line unless it has a type), cut at the rims\nfunction circleGeometry(e: FlowEdge): EdgeGeometry | null {\n const sc = nodeById.value.get(e.source)?.type === 'circle'\n const tc = nodeById.value.get(e.target)?.type === 'circle'\n const s = sc ? circleOf(e.source) : handlePoint(e.source, 'source', e.sourceHandle)\n const t = tc ? circleOf(e.target) : handlePoint(e.target, 'target', e.targetHandle)\n if (!s || !t) return null\n const dx = t.x - s.x\n const dy = t.y - s.y\n const len = Math.hypot(dx, dy) || 1\n const ux = dx / len\n const uy = dy / len\n const off = pairKeys.value.has(`${e.target}>${e.source}`) ? 6 : 0\n const ox = -uy * off\n const oy = ux * off\n const rs = sc ? (s as { r: number }).r : 0\n const rt = tc ? (t as { r: number }).r + 2 : 0\n const horizontal = Math.abs(dx) >= Math.abs(dy)\n const ends = {\n sourceX: s.x + ux * rs + ox,\n sourceY: s.y + uy * rs + oy,\n sourcePosition: (horizontal ? (dx >= 0 ? 'right' : 'left') : dy >= 0 ? 'bottom' : 'top') as FlowPosition,\n targetX: t.x - ux * rt + ox,\n targetY: t.y - uy * rt + oy,\n targetPosition: (horizontal ? (dx >= 0 ? 'left' : 'right') : dy >= 0 ? 'top' : 'bottom') as FlowPosition,\n }\n return { ...ends, ...pathFor(e.type ?? props.defaultEdgeOptions?.type ?? 'straight', ends), sourceInset: 0, targetInset: 0 }\n}\nfunction edgeGeometry(e: FlowEdge): EdgeGeometry | null {\n if (nodeById.value.get(e.source)?.type === 'circle' || nodeById.value.get(e.target)?.type === 'circle') return circleGeometry(e)\n const s = handlePoint(e.source, 'source', e.sourceHandle)\n const t = handlePoint(e.target, 'target', e.targetHandle)\n if (!s || !t) return null\n const ends = { sourceX: s.x, sourceY: s.y, sourcePosition: s.position, targetX: t.x, targetY: t.y, targetPosition: t.position }\n return { ...ends, ...pathFor(edgeRoute(e), ends), sourceInset: s.inset, targetInset: t.inset }\n}\n\n// What's drawn: groups under the edges, other nodes over them; children over their parents\nconst visibleNodes = computed(() => nodesLocal.value.filter((n) => !isHidden(n.id)))\nconst groupNodes = computed(() => visibleNodes.value.filter((n) => n.type === 'group').sort((a, b) => depthOf(a.id) - depthOf(b.id)))\nconst plainNodes = computed(() => visibleNodes.value.filter((n) => n.type !== 'group'))\nconst visibleEdges = computed(() => edgesLocal.value.filter((e) => !e.hidden && !isHidden(e.source) && !isHidden(e.target)))\nconst isLifted = (id: string) => dragging.value.has(id) || ancestors(id).some((a) => dragging.value.has(a))\nconst zIndexOf = (id: string) => (isLifted(id) ? 1000 : 0) + depthOf(id) * 10 + (selectedNodes.value.has(id) ? 3 : 0)\nconst nodeRenderer = (n: FlowNode) => slots[`node-${n.type ?? 'default'}`]\nconst edgeRenderer = (e: FlowEdge) => slots[`edge-${edgeType(e)}`]\nconst isReconnectable = (e: FlowEdge) => !locked.value && (e.reconnectable ?? props.edgesReconnectable)\n\n// ── The view ──────────────────────────────────────────────────────────────────────────────────────────────\nconst vp = ref<FlowViewport>({ x: 0, y: 0, zoom: 1, ...props.viewport })\nwatch(() => props.viewport, (v) => {\n if (!v || (v.x === vp.value.x && v.y === vp.value.y && v.zoom === vp.value.zoom)) return\n vpAnim = null\n vp.value = { ...v }\n})\nconst clampZoom = (z: number) => Math.min(props.maxZoom, Math.max(props.minZoom, z))\nfunction writeViewport(v: FlowViewport) {\n if (v.x === vp.value.x && v.y === vp.value.y && v.zoom === vp.value.zoom) return\n vp.value = v\n emit('update:viewport', v)\n}\ntype Spring1 = { p: number; v: number; t: number }\nlet vpAnim: { x: Spring1; y: Spring1; z: Spring1 } | null = null\nfunction setViewport(v: Partial<FlowViewport>, opts: { animate?: boolean } = {}) {\n const target = { x: v.x ?? vp.value.x, y: v.y ?? vp.value.y, zoom: clampZoom(v.zoom ?? vp.value.zoom) }\n if (opts.animate === false || !ready.value || prefersReducedMotion() || typeof requestAnimationFrame === 'undefined') {\n vpAnim = null\n writeViewport(target)\n return\n }\n const cur = vpAnim\n vpAnim = {\n x: { p: vp.value.x, v: cur?.x.v ?? 0, t: target.x },\n y: { p: vp.value.y, v: cur?.y.v ?? 0, t: target.y },\n z: { p: vp.value.zoom, v: cur?.z.v ?? 0, t: target.zoom },\n }\n kick()\n}\nfunction stepViewport(dt: number) {\n const a = vpAnim\n if (!a) return false\n let done = true\n for (const s of [a.x, a.y, a.z]) {\n for (let t = 0; t < dt; t += SUBSTEP) {\n const h = Math.min(SUBSTEP, dt - t)\n s.v += (-STIFF * (s.p - s.t) - DAMP * s.v) * h\n s.p += s.v * h\n }\n const eps = s === a.z ? 0.0005 : 0.1\n if (Math.abs(s.p - s.t) < eps && Math.abs(s.v) < eps * 10) { s.p = s.t; s.v = 0 } else done = false\n }\n writeViewport({ x: a.x.p, y: a.y.p, zoom: a.z.p })\n if (done) vpAnim = null\n return !done\n}\n\nfunction rootRect() {\n return root.value?.getBoundingClientRect() ?? ({ left: 0, top: 0, width: size.value.width, height: size.value.height } as DOMRect)\n}\nfunction screenToFlow(p: { x: number; y: number }): FlowXY {\n const r = rootRect()\n return { x: (p.x - r.left - vp.value.x) / vp.value.zoom, y: (p.y - r.top - vp.value.y) / vp.value.zoom }\n}\nfunction flowToScreen(p: FlowXY) {\n const r = rootRect()\n return { x: p.x * vp.value.zoom + vp.value.x + r.left, y: p.y * vp.value.zoom + vp.value.y + r.top }\n}\n/** Zoom to `zoom` keeping the canvas point (px from its corner) still */\nfunction zoomAt(zoom: number, px: number, py: number, animate = false) {\n const z = clampZoom(zoom)\n const base = vpAnim && animate ? { x: vpAnim.x.t, y: vpAnim.y.t, zoom: vpAnim.z.t } : vp.value\n const fx = (px - base.x) / base.zoom\n const fy = (py - base.y) / base.zoom\n setViewport({ x: px - fx * z, y: py - fy * z, zoom: z }, { animate })\n}\nconst targetZoom = () => vpAnim?.z.t ?? vp.value.zoom\nconst zoomIn = () => zoomAt(targetZoom() * 1.25, size.value.width / 2, size.value.height / 2, true)\nconst zoomOut = () => zoomAt(targetZoom() / 1.25, size.value.width / 2, size.value.height / 2, true)\nconst zoomTo = (z: number, opts: { animate?: boolean } = {}) => zoomAt(z, size.value.width / 2, size.value.height / 2, opts.animate ?? true)\nfunction setCenter(x: number, y: number, opts: { zoom?: number; animate?: boolean } = {}) {\n const z = clampZoom(opts.zoom ?? targetZoom())\n setViewport({ x: size.value.width / 2 - x * z, y: size.value.height / 2 - y * z, zoom: z }, { animate: opts.animate ?? true })\n}\nfunction boundsOf(ids: string[]) {\n let x1 = Infinity\n let y1 = Infinity\n let x2 = -Infinity\n let y2 = -Infinity\n for (const id of ids) {\n if (isHidden(id)) continue\n const a = getAbsolutePosition(id)\n const s = getSize(id)\n x1 = Math.min(x1, a.x)\n y1 = Math.min(y1, a.y)\n x2 = Math.max(x2, a.x + s.width)\n y2 = Math.max(y2, a.y + s.height)\n }\n return Number.isFinite(x1) ? { x: x1, y: y1, width: x2 - x1, height: y2 - y1 } : null\n}\nfunction fitView(opts: FlowFitOptions = {}) {\n // Fit where the nodes are going, not where a spring has them right now\n const ids = opts.nodes ?? nodesLocal.value.map((n) => n.id)\n const saved = new Map<string, { x: number; y: number }>()\n for (const [id, s] of springs) {\n const d = disp.get(id)\n if (d && (d.x !== s.tx || d.y !== s.ty)) { saved.set(id, { x: d.x, y: d.y }); d.x = s.tx; d.y = s.ty }\n }\n const b = boundsOf(ids)\n for (const [id, p] of saved) { const d = disp.get(id)!; d.x = p.x; d.y = p.y }\n if (!b || !size.value.width || !size.value.height) return\n const pad = opts.padding ?? 0.1\n const w = size.value.width * (1 - 2 * pad)\n const h = size.value.height * (1 - 2 * pad)\n const z = Math.min(opts.maxZoom ?? 1.5, Math.max(opts.minZoom ?? props.minZoom, Math.min(w / Math.max(1, b.width), h / Math.max(1, b.height))))\n setCenter(b.x + b.width / 2, b.y + b.height / 2, { zoom: clampZoom(z), animate: opts.animate ?? true })\n}\n\n// ── Editing API ───────────────────────────────────────────────────────────────────────────────────────────\nconst asArray = <T,>(x: T | T[]) => (Array.isArray(x) ? x : [x])\nfunction addNodes(ns: FlowNode | FlowNode[]) {\n commit({ nodes: [...nodesLocal.value, ...asArray(ns)] })\n}\nfunction addEdges(es: FlowEdge | FlowEdge[]) {\n commit({ edges: [...edgesLocal.value, ...asArray(es)] })\n}\nfunction updateNode(id: string, patch: Partial<FlowNode> | ((n: FlowNode) => FlowNode)) {\n commit({ nodes: nodesLocal.value.map((n) => (n.id !== id ? n : typeof patch === 'function' ? patch(n) : { ...n, ...patch })) })\n}\nfunction updateEdge(id: string, patch: Partial<FlowEdge> | ((e: FlowEdge) => FlowEdge)) {\n commit({ edges: edgesLocal.value.map((e) => (e.id !== id ? e : typeof patch === 'function' ? patch(e) : { ...e, ...patch })) })\n}\nfunction remove(ids: { nodes?: string[]; edges?: string[] }) {\n const goneNodes = new Set<string>()\n for (const id of ids.nodes ?? []) {\n if (!nodeById.value.has(id)) continue\n goneNodes.add(id)\n descendants(id).forEach((d) => goneNodes.add(d))\n }\n const goneEdgeIds = new Set(ids.edges ?? [])\n const nodes = nodesLocal.value.filter((n) => goneNodes.has(n.id))\n const edges = edgesLocal.value.filter((e) => goneEdgeIds.has(e.id) || goneNodes.has(e.source) || goneNodes.has(e.target))\n if (!nodes.length && !edges.length) return\n if (props.beforeDelete) {\n const ok = props.beforeDelete({ nodes, edges })\n if (ok instanceof Promise) {\n // Applied once confirmed, against whatever the nodes and edges are by then\n ok.then((yes) => { if (yes) applyRemove(goneNodes, new Set(edges.map((e) => e.id))) })\n return\n }\n if (!ok) return\n }\n applyRemove(goneNodes, new Set(edges.map((e) => e.id)))\n}\nfunction applyRemove(goneNodes: Set<string>, goneEdgeIds: Set<string>) {\n const nodes = nodesLocal.value.filter((n) => goneNodes.has(n.id))\n const edges = edgesLocal.value.filter((e) => goneEdgeIds.has(e.id) || goneNodes.has(e.source) || goneNodes.has(e.target))\n if (!nodes.length && !edges.length) return\n const goneEdges = new Set(edges)\n commit({\n nodes: nodes.length ? nodesLocal.value.filter((n) => !goneNodes.has(n.id)) : undefined,\n edges: edges.length ? edgesLocal.value.filter((e) => !goneEdges.has(e)) : undefined,\n })\n setSelection({ nodes: selLocal.value.nodes.filter((i) => !goneNodes.has(i)), edges: selLocal.value.edges.filter((i) => !goneEdges.has(edgeById.value.get(i)!)) })\n emit('delete', { nodes, edges })\n announce(locale.flowDeleted.replace('{count}', String(nodes.length + edges.length)))\n}\nfunction deleteSelection() {\n if (locked.value) return\n const nodes = selLocal.value.nodes.filter((id) => nodeById.value.get(id)?.deletable !== false)\n const edges = selLocal.value.edges.filter((id) => edgeById.value.get(id)?.deletable !== false)\n remove({ nodes, edges })\n}\nfunction selectAll() {\n if (!canSelect.value) return\n setSelection({\n nodes: visibleNodes.value.filter((n) => n.selectable !== false).map((n) => n.id),\n edges: visibleEdges.value.filter((e) => e.selectable !== false).map((e) => e.id),\n })\n}\n\nfunction copy() {\n const ids = new Set(selLocal.value.nodes)\n for (const id of [...ids]) descendants(id).forEach((d) => ids.add(d))\n if (!ids.size) return\n clipboard = {\n nodes: nodesLocal.value.filter((n) => ids.has(n.id)).map((n) => {\n // A node copied without its group keeps its place on the canvas\n if (n.parentId && !ids.has(n.parentId)) {\n const { parentId: _p, extent: _e, ...rest } = n\n return { ...rest, position: getAbsolutePosition(n.id) }\n }\n return n\n }),\n edges: edgesLocal.value.filter((e) => ids.has(e.source) && ids.has(e.target)),\n }\n pasteCount = 0\n}\nfunction cut() {\n if (locked.value) return\n copy()\n deleteSelection()\n}\nfunction paste(at?: FlowXY) {\n if (!clipboard?.nodes.length || locked.value) return\n pasteCount++\n const tops = clipboard.nodes.filter((n) => !n.parentId || !clipboard!.nodes.some((m) => m.id === n.parentId))\n const minX = Math.min(...tops.map((n) => n.position.x))\n const minY = Math.min(...tops.map((n) => n.position.y))\n const step = props.gridSize * 2 * pasteCount\n const dx = at ? at.x - minX : step\n const dy = at ? at.y - minY : step\n const idMap = new Map(clipboard.nodes.map((n) => [n.id, makeId('node')]))\n const topIds = new Set(tops.map((n) => n.id))\n const nodes = clipboard.nodes.map((n) => ({\n ...n,\n id: idMap.get(n.id)!,\n parentId: n.parentId ? idMap.get(n.parentId) ?? n.parentId : undefined,\n position: topIds.has(n.id) ? { x: n.position.x + dx, y: n.position.y + dy } : n.position,\n }))\n const edges = clipboard.edges.map((e) => ({ ...e, id: makeId('edge'), source: idMap.get(e.source)!, target: idMap.get(e.target)! }))\n instantNext = true\n commit({ nodes: [...nodesLocal.value, ...nodes], edges: edges.length ? [...edgesLocal.value, ...edges] : undefined })\n setSelection({ nodes: nodes.map((n) => n.id), edges: edges.map((e) => e.id) })\n}\n\n// ── Layout ────────────────────────────────────────────────────────────────────────────────────────────────\nconst layoutDirection = (): FlowLayoutDirection => props.layoutOptions?.direction ?? (props.direction === 'vertical' ? 'TB' : 'LR')\nasync function runLayout(fn?: 'tree' | 'layered' | FlowLayout | null, options?: FlowLayoutOptions, opts: { history?: boolean } = {}) {\n const f = fn ?? props.layout ?? 'tree'\n const impl: FlowLayout = f === 'tree' ? layoutTree : f === 'layered' ? layoutLayered : f\n const sizes = new Map(nodesLocal.value.filter((n) => !n.parentId).map((n) => [n.id, getSize(n.id)]))\n const o = { ...props.layoutOptions, ...options }\n const result = await impl(nodesLocal.value, edgesLocal.value, { ...o, sizes, direction: o.direction ?? layoutDirection() })\n let changed = false\n const nodes = nodesLocal.value.map((n) => {\n const p = result[n.id]\n if (!p || (Math.abs(p.x - n.position.x) < 0.5 && Math.abs(p.y - n.position.y) < 0.5)) return n\n changed = true\n return { ...n, position: { x: Math.round(p.x), y: Math.round(p.y) } }\n })\n if (changed) commit({ nodes }, { history: opts.history })\n}\n// The graph's shape: which nodes show and how they're joined (not where they are)\nconst structureKey = computed(() =>\n visibleNodes.value.map((n) => n.id).join(',') + '|' + visibleEdges.value.map((e) => `${e.source}>${e.target}`).join(','))\nwatch([structureKey, () => props.direction, () => JSON.stringify(props.layoutOptions ?? {})], () => {\n if (!props.layout || !ready.value) return\n // After the new nodes mount and measure; with fitView the view follows the graph as it grows\n nextTick(async () => {\n await runLayout(null, undefined, { history: false })\n if (props.fitView) fitView()\n })\n})\n\n// ── Pointer gestures, all dispatched from the canvas ──────────────────────────────────────────────────────\nconst DRAG_SLOP_MOUSE = 4\nconst DRAG_SLOP_TOUCH = 6\nconst NO_DRAG = 'input, textarea, select, button, a, label, [contenteditable], [data-flow-nodrag]'\n\ntype Gesture =\n | { kind: 'pan'; id: number; sx: number; sy: number; vx: number; vy: number; moved: boolean; target: 'pane'; touch?: boolean; branch?: FlowEdge }\n | { kind: 'marquee'; id: number; sx: number; sy: number; x: number; y: number; additive: string[]; moved: boolean }\n | { kind: 'node'; id: number; nodeId: string; sx: number; sy: number; touch: boolean; active: boolean; starts: Map<string, FlowXY>; moved: boolean; reselect: boolean }\n | { kind: 'connect'; id: number; from: { nodeId: string; handleId: string | null; type: 'source' | 'target' }; reconnect?: { edge: FlowEdge; end: 'source' | 'target' }; moved: boolean }\n | { kind: 'pinch' }\nlet gesture: Gesture | null = null\n// What the gesture's pointerdown landed on: a click is resolved against it, not the pointerup's target\nlet downTarget: HTMLElement | null = null\nconst touches = new Map<number, { x: number; y: number }>()\nlet pinch: { dist: number; cx: number; cy: number; zoom: number; fx: number; fy: number } | null = null\nconst pointer = { x: 0, y: 0, inside: false }\n\nconst marquee = ref<{ x: number; y: number; width: number; height: number } | null>(null)\nconst connection = shallowRef<{ from: { x: number; y: number; position: FlowPosition }; to: FlowXY; toPosition: FlowPosition | null; type: 'source' | 'target'; edgeType: string } | null>(null)\nconst connectionTarget = ref<{ key: string; valid: boolean } | null>(null)\nconst connecting = computed(() => !!connection.value)\nconst guideLines = shallowRef<{ x?: number; y?: number; from: number; to: number }[]>([])\nconst panning = ref(false)\n\nfunction addWindowListeners() {\n window.addEventListener('pointermove', onWindowMove)\n window.addEventListener('pointerup', onWindowUp)\n window.addEventListener('pointercancel', onWindowCancel)\n}\nfunction removeWindowListeners() {\n window.removeEventListener('pointermove', onWindowMove)\n window.removeEventListener('pointerup', onWindowUp)\n window.removeEventListener('pointercancel', onWindowCancel)\n unblockTouchScroll()\n}\n\n// A touch handed over by startDrag began outside the canvas (a palette, a sheet), so its touch-action is that\n// element's and the browser would scroll or cancel it. Its touchmoves go to where it began, even once that's\n// gone from the page, so they're cancelled there (and on window) until the drag ends\nlet touchBlocked: EventTarget[] = []\nfunction preventTouch(e: TouchEvent) {\n if (e.cancelable) e.preventDefault()\n}\nfunction blockTouchScroll(target: EventTarget | null) {\n unblockTouchScroll()\n touchBlocked = target && target !== window ? [target, window] : [window]\n for (const t of touchBlocked) t.addEventListener('touchmove', preventTouch as EventListener, { passive: false })\n}\nfunction unblockTouchScroll() {\n for (const t of touchBlocked) t.removeEventListener('touchmove', preventTouch as EventListener)\n touchBlocked = []\n}\n\nfunction onPointerDown(e: PointerEvent) {\n const t = e.target as HTMLElement\n if (onOverlay(t)) return\n if (e.pointerType === 'touch') {\n // With no gesture running nothing listens for fingers lifting: whatever is left in the map is stale\n if (!gesture) touches.clear()\n touches.set(e.pointerId, { x: e.clientX, y: e.clientY })\n if (touches.size === 2) {\n // A second finger: whatever the first one started becomes a pinch\n cancelGesture()\n startPinch()\n return\n }\n if (touches.size > 2) return\n }\n if (gesture) return\n if (e.button === 2) return\n downTarget = t\n root.value?.focus({ preventScroll: true })\n\n const handle = t.closest<HTMLElement>('[data-flow-handle]')\n const reconnect = t.closest<HTMLElement>('[data-flow-reconnect]')\n const nodeEl = t.closest<HTMLElement>('[data-flow-node]')\n const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')\n if (e.button === 1) return startPan(e)\n\n const deleteButton = t.closest<HTMLElement>('[data-flow-edge-delete]')\n if (deleteButton) {\n e.preventDefault()\n remove({ edges: [deleteButton.dataset.flowEdgeDelete!] })\n return\n }\n if (reconnect && edgeEl) {\n const edge = edgeById.value.get(edgeEl.dataset.flowEdge!)\n if (edge && isReconnectable(edge)) {\n e.preventDefault()\n return startReconnect(e, edge, reconnect.dataset.flowReconnect as 'source' | 'target')\n }\n }\n if (handle && nodeEl && handle.dataset.flowConnectable === 'true' && nodesConnectable.value) {\n e.preventDefault()\n e.stopPropagation()\n // A connected input pulls its (last) edge off instead: drop it on another node, or on nothing to disconnect\n if (handle.dataset.flowHandle === 'target') {\n const nodeId = nodeEl.dataset.flowNode!\n const hid = handle.dataset.handleId || null\n const attached = visibleEdges.value.filter((ed) => ed.target === nodeId && (ed.targetHandle ?? null) === hid && isReconnectable(ed))\n const edge = attached[attached.length - 1]\n if (edge) return startReconnect(e, edge, 'target')\n }\n return startConnection(e, nodeEl.dataset.flowNode!, handle.dataset.handleId || null, handle.dataset.flowHandle as 'source' | 'target')\n }\n if (nodeEl) {\n if (t.closest(NO_DRAG) && t.closest(NO_DRAG) !== nodeEl) return\n return startNode(e, nodeEl.dataset.flowNode!)\n }\n if (edgeEl) {\n // Edges select on the click (pointerup) so a drag across them still pans, or branches (edgeBranching)\n const touch = e.pointerType === 'touch'\n const edge = edgeById.value.get(edgeEl.dataset.flowEdge!)\n const branch = edge && branching.value && (!touch || selectedEdges.value.has(edge.id)) ? edge : undefined\n if (branch) e.preventDefault()\n gesture = { kind: 'pan', id: e.pointerId, sx: e.clientX, sy: e.clientY, vx: vp.value.x, vy: vp.value.y, moved: false, target: 'pane', touch, branch }\n addWindowListeners()\n return\n }\n if (e.shiftKey || (props.selectionOnDrag && e.pointerType !== 'touch') || !props.panOnDrag) {\n if (canSelect.value) return startMarquee(e)\n }\n startPan(e)\n}\n\n// On touch there's no Shift: holding a finger still on the background starts a selection box instead\nconst LONG_PRESS = 450\nlet longPress: ReturnType<typeof setTimeout> | undefined\nfunction startPan(e: PointerEvent) {\n const touch = e.pointerType === 'touch'\n const g: Gesture = { kind: 'pan', id: e.pointerId, sx: e.clientX, sy: e.clientY, vx: vp.value.x, vy: vp.value.y, moved: false, target: 'pane', touch }\n gesture = g\n vpAnim = null\n addWindowListeners()\n clearTimeout(longPress)\n if (touch && canSelect.value) {\n longPress = setTimeout(() => {\n if (gesture !== g || g.moved) return\n const r = rootRect()\n const x = g.sx - r.left\n const y = g.sy - r.top\n gesture = { kind: 'marquee', id: g.id, sx: x, sy: y, x, y, additive: [...selLocal.value.nodes], moved: true }\n marquee.value = { x, y, width: 0, height: 0 }\n navigator.vibrate?.(10)\n }, LONG_PRESS)\n }\n}\nfunction startMarquee(e: PointerEvent) {\n const r = rootRect()\n gesture = { kind: 'marquee', id: e.pointerId, sx: e.clientX - r.left, sy: e.clientY - r.top, x: e.clientX - r.left, y: e.clientY - r.top, additive: e.shiftKey ? [...selLocal.value.nodes] : [], moved: false }\n addWindowListeners()\n}\nfunction startNode(e: PointerEvent, nodeId: string) {\n const n = nodeById.value.get(nodeId)\n if (!n) return\n let reselect = false\n if (canSelect.value && n.selectable !== false) {\n if (e.shiftKey || e.metaKey || e.ctrlKey) {\n const has = selectedNodes.value.has(nodeId)\n setSelection({ nodes: has ? selLocal.value.nodes.filter((i) => i !== nodeId) : [...selLocal.value.nodes, nodeId] })\n if (has) return\n } else if (!selectedNodes.value.has(nodeId)) {\n setSelection({ nodes: [nodeId], edges: [] })\n } else reselect = true\n }\n gesture = { kind: 'node', id: e.pointerId, nodeId, sx: e.clientX, sy: e.clientY, touch: e.pointerType === 'touch', active: false, starts: new Map(), moved: false, reselect }\n addWindowListeners()\n}\n\nfunction onWindowMove(e: PointerEvent) {\n pointer.x = e.clientX\n pointer.y = e.clientY\n if (e.pointerType === 'touch' && touches.has(e.pointerId)) {\n touches.set(e.pointerId, { x: e.clientX, y: e.clientY })\n if (pinch) return movePinch()\n }\n const g = gesture\n if (!g || g.kind === 'pinch' || g.id !== e.pointerId) return\n if (g.kind === 'pan') {\n const dx = e.clientX - g.sx\n const dy = e.clientY - g.sy\n if (!g.moved && Math.hypot(dx, dy) < (g.touch ? DRAG_SLOP_TOUCH : DRAG_SLOP_MOUSE)) return\n if (g.branch && !g.moved) return startBranch(g, g.branch, e)\n g.moved = true\n clearTimeout(longPress)\n panning.value = true\n writeViewport({ x: g.vx + dx, y: g.vy + dy, zoom: vp.value.zoom })\n } else if (g.kind === 'marquee') {\n const r = rootRect()\n g.x = e.clientX - r.left\n g.y = e.clientY - r.top\n if (!g.moved && Math.hypot(g.x - g.sx, g.y - g.sy) < DRAG_SLOP_MOUSE) return\n g.moved = true\n updateMarquee(g)\n } else if (g.kind === 'node') {\n if (!g.active) {\n if (Math.hypot(e.clientX - g.sx, e.clientY - g.sy) < (g.touch ? DRAG_SLOP_TOUCH : DRAG_SLOP_MOUSE)) return\n if (!canDrag.value || !beginNodeDrag(g, e)) {\n // Not draggable: the gesture pans instead\n gesture = { kind: 'pan', id: g.id, sx: e.clientX, sy: e.clientY, vx: vp.value.x, vy: vp.value.y, moved: true, target: 'pane' }\n return\n }\n }\n g.moved = true\n moveNodes(g, e.clientX, e.clientY)\n updateInsertTarget(g)\n emit('node-drag', [...g.starts.keys()].map((id) => nodeById.value.get(id)!), e)\n kick()\n } else if (g.kind === 'connect') {\n g.moved = true\n moveConnection(g, e.clientX, e.clientY)\n kick()\n }\n}\n\nfunction onWindowUp(e: PointerEvent) {\n touches.delete(e.pointerId)\n if (pinch) {\n if (touches.size < 2) endPinch()\n return\n }\n const g = gesture\n if (!g || g.kind === 'pinch' || g.id !== e.pointerId) return\n gesture = null\n clearTimeout(longPress)\n removeWindowListeners()\n panning.value = false\n if (g.kind === 'pan') {\n if (!g.moved) clickAt(e)\n } else if (g.kind === 'marquee') {\n marquee.value = null\n if (!g.moved) clickAt(e)\n } else if (g.kind === 'node') {\n if (g.active) endNodeDrag(g, e)\n else {\n if (g.reselect && !e.shiftKey) setSelection({ nodes: [g.nodeId], edges: [] })\n const n = nodeById.value.get(g.nodeId)\n if (n) emit('node-click', n, e)\n }\n } else if (g.kind === 'connect') {\n endConnection(g, e)\n }\n}\nfunction onWindowCancel(e: PointerEvent) {\n clearTimeout(longPress)\n touches.delete(e.pointerId)\n if (pinch) {\n if (touches.size < 2) endPinch()\n return\n }\n cancelGesture()\n}\nfunction cancelGesture() {\n const g = gesture\n gesture = null\n removeWindowListeners()\n panning.value = false\n marquee.value = null\n if (g?.kind === 'node' && g.active) {\n // Back where they were\n for (const [id, p] of g.starts) {\n const s = springs.get(id)\n if (s) { s.tx = p.x; s.ty = p.y }\n }\n dragging.value = new Set()\n frozenGroups.clear()\n guideLines.value = []\n insertEdge.value = null\n insertPlan = null\n kick()\n }\n if (g?.kind === 'connect') {\n connection.value = null\n connectionTarget.value = null\n }\n}\n\n// What the click (a pointerup that didn't move) landed on\nfunction clickAt(e: PointerEvent) {\n const t = downTarget ?? (e.target as HTMLElement)\n const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')\n const edge = edgeEl ? edgeById.value.get(edgeEl.dataset.flowEdge!) : undefined\n if (edge) {\n if (canSelect.value && edge.selectable !== false) {\n if (e.shiftKey) {\n const has = selectedEdges.value.has(edge.id)\n setSelection({ edges: has ? selLocal.value.edges.filter((i) => i !== edge.id) : [...selLocal.value.edges, edge.id] })\n } else setSelection({ nodes: [], edges: [edge.id] })\n }\n emit('edge-click', edge, e)\n return\n }\n if (!e.shiftKey) setSelection(emptySelection())\n emit('pane-click', screenToFlow({ x: e.clientX, y: e.clientY }), e)\n}\n\n// ── Pinch (two fingers on touch) ──────────────────────────────────────────────────────────────────────────\nfunction pinchInfo() {\n const [a, b] = [...touches.values()]\n const r = rootRect()\n return { dist: Math.hypot(a!.x - b!.x, a!.y - b!.y) || 1, cx: (a!.x + b!.x) / 2 - r.left, cy: (a!.y + b!.y) / 2 - r.top }\n}\nfunction startPinch() {\n clearTimeout(longPress)\n const p = pinchInfo()\n vpAnim = null\n gesture = { kind: 'pinch' }\n pinch = { ...p, zoom: vp.value.zoom, fx: (p.cx - vp.value.x) / vp.value.zoom, fy: (p.cy - vp.value.y) / vp.value.zoom }\n addWindowListeners()\n}\n// One finger lifted: the one left on keeps panning (and its pointerup still ends the gesture)\nfunction endPinch() {\n pinch = null\n const rest = [...touches][0]\n if (!rest) { gesture = null; removeWindowListeners(); return }\n const [id, p] = rest\n gesture = { kind: 'pan', id, sx: p.x, sy: p.y, vx: vp.value.x, vy: vp.value.y, moved: true, target: 'pane', touch: true }\n}\nfunction movePinch() {\n if (!pinch || touches.size < 2) return\n const p = pinchInfo()\n const z = clampZoom((pinch.zoom * p.dist) / pinch.dist)\n // The flow point first under the fingers' middle stays under it, wherever the fingers go\n writeViewport({ x: p.cx - pinch.fx * z, y: p.cy - pinch.fy * z, zoom: z })\n}\n\n// ── Wheel and double click ────────────────────────────────────────────────────────────────────────────────\nfunction onWheel(e: WheelEvent) {\n const t = e.target as HTMLElement\n // Over a panel, or content inside a node marked to scroll on its own: the wheel is theirs\n if (onOverlay(t) || t.closest('[data-flow-nowheel]')) return\n e.preventDefault()\n const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? size.value.height : 1\n const r = rootRect()\n if (e.ctrlKey || e.metaKey || props.wheel === 'zoom') {\n const d = Math.max(-50, Math.min(50, e.deltaY * unit))\n zoomAt(vp.value.zoom * Math.exp(-d * 0.01), e.clientX - r.left, e.clientY - r.top)\n vpAnim = null\n return\n }\n const dx = (e.shiftKey && !e.deltaX ? e.deltaY : e.deltaX) * unit\n const dy = (e.shiftKey && !e.deltaX ? 0 : e.deltaY) * unit\n vpAnim = null\n writeViewport({ x: vp.value.x - dx, y: vp.value.y - dy, zoom: vp.value.zoom })\n}\nfunction onDblClick(e: MouseEvent) {\n const t = e.target as HTMLElement\n if (onOverlay(t)) return\n const nodeEl = t.closest<HTMLElement>('[data-flow-node]')\n const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')\n if (nodeEl) {\n const n = nodeById.value.get(nodeEl.dataset.flowNode!)\n if (n) emit('node-dblclick', n, e)\n } else if (edgeEl) {\n const ed = edgeById.value.get(edgeEl.dataset.flowEdge!)\n if (ed) emit('edge-dblclick', ed, e)\n } else {\n emit('pane-dblclick', screenToFlow({ x: e.clientX, y: e.clientY }), e)\n if (props.zoomOnDoubleClick) {\n const r = rootRect()\n zoomAt(targetZoom() * 2, e.clientX - r.left, e.clientY - r.top, true)\n }\n }\n}\nfunction onContextMenu(e: MouseEvent) {\n const t = e.target as HTMLElement\n if (onOverlay(t)) return\n // The browser's menu (and a phone's long-press menu) stays closed on the canvas, except in text fields\n if (!props.nativeContextMenu && !t.closest('input, textarea, select, [contenteditable]')) e.preventDefault()\n const nodeEl = t.closest<HTMLElement>('[data-flow-node]')\n const edgeEl = t.closest<HTMLElement>('[data-flow-edge]')\n const n = nodeEl ? nodeById.value.get(nodeEl.dataset.flowNode!) : undefined\n const ed = edgeEl ? edgeById.value.get(edgeEl.dataset.flowEdge!) : undefined\n if (n) emit('node-contextmenu', n, e)\n else if (ed) emit('edge-contextmenu', ed, e)\n else emit('pane-contextmenu', screenToFlow({ x: e.clientX, y: e.clientY }), e)\n}\n\n// ── Selection box ─────────────────────────────────────────────────────────────────────────────────────────\nfunction updateMarquee(g: Extract<Gesture, { kind: 'marquee' }>) {\n const x = Math.min(g.sx, g.x)\n const y = Math.min(g.sy, g.y)\n const w = Math.abs(g.x - g.sx)\n const h = Math.abs(g.y - g.sy)\n marquee.value = { x, y, width: w, height: h }\n const z = vp.value.zoom\n const fx1 = (x - vp.value.x) / z\n const fy1 = (y - vp.value.y) / z\n const fx2 = fx1 + w / z\n const fy2 = fy1 + h / z\n const inside = visibleNodes.value.filter((n) => {\n if (n.selectable === false) return false\n const a = getAbsolutePosition(n.id)\n const s = getSize(n.id)\n return a.x < fx2 && a.x + s.width > fx1 && a.y < fy2 && a.y + s.height > fy1\n }).map((n) => n.id)\n const nodes = [...new Set([...g.additive, ...inside])]\n const set = new Set(nodes)\n setSelection({ nodes, edges: visibleEdges.value.filter((e) => e.selectable !== false && set.has(e.source) && set.has(e.target)).map((e) => e.id) })\n}\n\n// ── Dragging nodes ────────────────────────────────────────────────────────────────────────────────────────\nfunction beginNodeDrag(g: Extract<Gesture, { kind: 'node' }>, e: PointerEvent) {\n const sel = selectedNodes.value.has(g.nodeId) ? selLocal.value.nodes : [g.nodeId]\n // A node whose group moves too comes along by itself\n const ids = sel.filter((id) => {\n const n = nodeById.value.get(id)\n return n && n.draggable !== false && !isHidden(id) && !ancestors(id).some((a) => sel.includes(a))\n })\n if (!ids.includes(g.nodeId) && nodeById.value.get(g.nodeId)?.draggable === false) return false\n if (!ids.length) return false\n for (const id of ids) {\n const s = springs.get(id)!\n g.starts.set(id, { x: s.tx, y: s.ty })\n }\n g.active = true\n for (const id of ids) for (const a of ancestors(id)) if (!frozenGroups.has(a)) frozenGroups.set(a, getSize(a))\n dragging.value = new Set(ids)\n document.body.style.userSelect = 'none'\n emit('node-drag-start', ids.map((id) => nodeById.value.get(id)!), e)\n return true\n}\n\n/**\n * Drags a node with a pointer that's already down (from a palette outside the canvas: add the node under the\n * pointer, then hand it the event). It follows the pointer from there, with the guides and splicing into edges\n */\nfunction startDrag(id: string, e: PointerEvent) {\n if (!nodeById.value.has(id) || locked.value) return\n if (gesture) cancelGesture()\n // A node added this tick has no spring yet\n if (!springs.has(id)) syncPositions()\n if (canSelect.value) setSelection({ nodes: [id], edges: [] })\n const g: Extract<Gesture, { kind: 'node' }> = { kind: 'node', id: e.pointerId, nodeId: id, sx: e.clientX, sy: e.clientY, touch: e.pointerType === 'touch', active: false, starts: new Map(), moved: true, reselect: false }\n gesture = g\n pointer.x = e.clientX\n pointer.y = e.clientY\n addWindowListeners()\n if (g.touch) blockTouchScroll(e.target)\n if (!beginNodeDrag(g, e)) {\n gesture = null\n removeWindowListeners()\n }\n}\n\nconst GUIDE_SNAP = 6\nfunction moveNodes(g: Extract<Gesture, { kind: 'node' }>, cx: number, cy: number) {\n const z = vp.value.zoom\n let dx = (cx - g.sx) / z\n let dy = (cy - g.sy) / z\n const lead = g.starts.get(g.nodeId) ?? [...g.starts.values()][0]!\n const leadId = g.starts.has(g.nodeId) ? g.nodeId : [...g.starts.keys()][0]!\n if (props.snapToGrid) {\n const gs = props.gridSize\n dx = Math.round((lead.x + dx) / gs) * gs - lead.x\n dy = Math.round((lead.y + dy) / gs) * gs - lead.y\n guideLines.value = []\n } else if (props.guides && g.starts.size === 1) {\n const snapped = snapToGuides(leadId, lead, dx, dy)\n dx = snapped.dx\n dy = snapped.dy\n }\n for (const [id, p] of g.starts) {\n let x = p.x + dx\n let y = p.y + dy\n const n = nodeById.value.get(id)!\n const parent = parentOf(id)\n if (n.extent === 'parent' && parent) {\n const ps = getSize(parent)\n const s = getSize(id)\n x = Math.max(0, Math.min(ps.width - s.width, x))\n y = Math.max(0, Math.min(ps.height - s.height, y))\n }\n const s = springs.get(id)!\n s.x = s.tx = x\n s.y = s.ty = y\n s.vx = s.vy = 0\n const d = disp.get(id)!\n d.x = x\n d.y = y\n }\n}\n// Snaps the dragged node's edges and center to other nodes' within a few px, and draws the lines it lines up on\nfunction snapToGuides(id: string, start: FlowXY, dx: number, dy: number) {\n const parentAbs = parentOf(id) ? getAbsolutePosition(parentOf(id)!) : { x: 0, y: 0 }\n const s = getSize(id)\n const ax = parentAbs.x + start.x + dx\n const ay = parentAbs.y + start.y + dy\n const xs = [ax, ax + s.width / 2, ax + s.width]\n const ys = [ay, ay + s.height / 2, ay + s.height]\n const tol = GUIDE_SNAP / vp.value.zoom\n let bestX: { d: number; to: number; box: { y1: number; y2: number } } | null = null\n let bestY: { d: number; to: number; box: { x1: number; x2: number } } | null = null\n const skip = new Set([id, ...descendants(id), ...ancestors(id)])\n for (const n of visibleNodes.value) {\n if (skip.has(n.id)) continue\n const a = getAbsolutePosition(n.id)\n const ns = getSize(n.id)\n const oxs = [a.x, a.x + ns.width / 2, a.x + ns.width]\n const oys = [a.y, a.y + ns.height / 2, a.y + ns.height]\n for (const x of xs) for (const o of oxs) {\n const d = o - x\n if (Math.abs(d) <= tol && (!bestX || Math.abs(d) < Math.abs(bestX.d))) bestX = { d, to: o, box: { y1: a.y, y2: a.y + ns.height } }\n }\n for (const y of ys) for (const o of oys) {\n const d = o - y\n if (Math.abs(d) <= tol && (!bestY || Math.abs(d) < Math.abs(bestY.d))) bestY = { d, to: o, box: { x1: a.x, x2: a.x + ns.width } }\n }\n }\n const lines: { x?: number; y?: number; from: number; to: number }[] = []\n if (bestX) {\n dx += bestX.d\n lines.push({ x: bestX.to, from: Math.min(ay, bestX.box.y1), to: Math.max(ay + s.height, bestX.box.y2) })\n }\n if (bestY) {\n dy += bestY.d\n const nx = parentAbs.x + start.x + dx\n lines.push({ y: bestY.to, from: Math.min(nx, bestY.box.x1), to: Math.max(nx + s.width, bestY.box.x2) })\n }\n guideLines.value = lines\n return { dx, dy }\n}\n\nfunction getIntersectingNodes(target: string | { x: number; y: number; width: number; height: number }) {\n let box: { x: number; y: number; width: number; height: number }\n const skip = new Set<string>()\n if (typeof target === 'string') {\n box = { ...getAbsolutePosition(target), ...getSize(target) }\n skip.add(target)\n descendants(target).forEach((d) => skip.add(d))\n ancestors(target).forEach((a) => skip.add(a))\n } else box = target\n return visibleNodes.value.filter((n) => {\n if (skip.has(n.id) || n.type === 'group') return false\n const a = getAbsolutePosition(n.id)\n const s = getSize(n.id)\n return a.x < box.x + box.width && a.x + s.width > box.x && a.y < box.y + box.height && a.y + s.height > box.y\n })\n}\n\n// ── A lone node dropped onto an edge splices into it ─────────────────────────────────────────────────────\nconst insertEdge = ref<string | null>(null)\nlet insertPlan: { node: string; edge: FlowEdge; connections: [FlowConnection, FlowConnection] } | null = null\nfunction updateInsertTarget(g: Extract<Gesture, { kind: 'node' }>) {\n insertPlan = null\n const found = findInsert(g)\n insertPlan = found\n insertEdge.value = found?.edge.id ?? null\n}\nfunction findInsert(g: Extract<Gesture, { kind: 'node' }>): typeof insertPlan {\n if (!props.insertOnEdge || g.starts.size !== 1 || !nodesConnectable.value) return null\n const id = [...g.starts.keys()][0]!\n const n = nodeById.value.get(id)\n if (!n || n.type === 'group' || n.connectable === false || n.insertable === false) return null\n if (edgesLocal.value.some((e) => e.source === id || e.target === id)) return null\n // It needs a way in and a way out (or no handles at all: then edges meet its sides; a circle's meet the circle)\n let target: string | null = null\n let source: string | null = null\n const list = handles.get(id)\n if (list?.length) {\n const t = list.find((h) => h.type === 'target' && h.connectable)\n const s = list.find((h) => h.type === 'source' && h.connectable)\n if ((!t && n.type !== 'circle') || (!s && n.type !== 'circle')) return null\n target = t?.id ?? null\n source = s?.id ?? null\n }\n // The node's center over the edge, within half its height\n const a = getAbsolutePosition(id)\n const size = getSize(id)\n const cx = a.x + size.width / 2\n const cy = a.y + size.height / 2\n const reach = Math.max(8 / vp.value.zoom, Math.min(size.width, size.height) / 2)\n let best: { edge: FlowEdge; d: number } | null = null\n for (const e of visibleEdges.value) {\n if (e.deletable === false) continue\n const geo = edgeGeometry(e)\n if (!geo) continue\n const d = distanceToPoints(cx, cy, edgePathPoints(edgeType(e), geo))\n if (d <= reach && (!best || d < best.d)) best = { edge: e, d }\n }\n if (!best) return null\n const e = best.edge\n const c1: FlowConnection = { source: e.source, sourceHandle: e.sourceHandle ?? null, target: id, targetHandle: target }\n const c2: FlowConnection = { source: id, sourceHandle: source, target: e.target, targetHandle: e.targetHandle ?? null }\n if (!isValid(c1) || !isValid(c2)) return null\n return { node: id, edge: e, connections: [c1, c2] }\n}\n\n// Room between spliced-in nodes, along the flow's direction\nconst SPLICE_GAP = 48\nfunction makeRoom(nodes: FlowNode[], plan: NonNullable<typeof insertPlan>): FlowNode[] {\n const byId = new Map(nodes.map((n) => [n.id, n]))\n const a = byId.get(plan.edge.source)\n const b = byId.get(plan.node)\n const c = byId.get(plan.edge.target)\n // Only among siblings: positions are relative to the same parent\n if (!a || !b || !c || a.parentId !== b.parentId || b.parentId !== c.parentId) return nodes\n const horizontal = props.direction !== 'vertical'\n const k = horizontal ? 'x' : 'y'\n const len = (id: string) => (horizontal ? getSize(id).width : getSize(id).height)\n const aEnd = a.position[k] + len(a.id)\n // C must come after A for \"after\" to mean anything (a loop back or a sideways edge is left alone)\n if (c.position[k] < aEnd) return nodes\n const bStart = Math.max(b.position[k], aEnd + SPLICE_GAP)\n const push = Math.max(0, bStart + len(b.id) + SPLICE_GAP - c.position[k])\n // C and everything downstream of it (A, B and A's own ancestors stay put)\n const moving = new Set<string>()\n if (push > 0) {\n const out = new Map<string, string[]>()\n for (const e of edgesLocal.value) if (e !== plan.edge) (out.get(e.source) ?? out.set(e.source, []).get(e.source)!).push(e.target)\n const queue = [c.id]\n while (queue.length) {\n const id = queue.shift()!\n if (moving.has(id) || id === a.id || id === b.id) continue\n const n = byId.get(id)\n if (!n || n.parentId !== c.parentId) continue\n moving.add(id)\n queue.push(...(out.get(id) ?? []))\n }\n }\n if (bStart === b.position[k] && !moving.size) return nodes\n return nodes.map((n) => {\n if (n.id === b.id) return { ...n, position: { ...n.position, [k]: bStart } }\n if (moving.has(n.id)) return { ...n, position: { ...n.position, [k]: n.position[k] + push } }\n return n\n })\n}\n\nfunction endNodeDrag(g: Extract<Gesture, { kind: 'node' }>, e: PointerEvent) {\n document.body.style.userSelect = ''\n const plan = insertPlan\n insertPlan = null\n insertEdge.value = null\n // The two edges that take the old one's place, with its look (not its label)\n let spliced: FlowEdge[] | undefined\n if (plan && props.autoConnect) {\n const { id: _id, label: _label, source: _s, target: _t, sourceHandle: _sh, targetHandle: _th, ...look } = plan.edge\n spliced = plan.connections.map((c) => ({ ...look, id: makeId('edge'), ...c }))\n }\n guideLines.value = []\n const moved = [...g.starts.keys()].filter((id) => {\n const s = springs.get(id)!\n const p = g.starts.get(id)!\n return s.tx !== p.x || s.ty !== p.y\n })\n // Reparent into the group under the pointer\n const reparent = new Map<string, string | undefined>()\n if (props.dropIntoGroups) {\n const at = screenToFlow({ x: e.clientX, y: e.clientY })\n for (const id of g.starts.keys()) {\n const n = nodeById.value.get(id)!\n if (n.type === 'group') continue\n const skip = new Set([id, ...descendants(id)])\n const group = groupNodes.value\n .filter((gn) => !skip.has(gn.id))\n .filter((gn) => {\n const a = getAbsolutePosition(gn.id)\n const s = getSize(gn.id)\n return at.x >= a.x && at.x <= a.x + s.width && at.y >= a.y && at.y <= a.y + s.height\n })\n .sort((a, b) => depthOf(b.id) - depthOf(a.id))[0]\n if ((group?.id ?? undefined) !== (n.parentId ?? undefined)) reparent.set(id, group?.id)\n }\n }\n if (moved.length || reparent.size) {\n const movedSet = new Set(moved)\n const nodes = nodesLocal.value.map((n) => {\n if (!movedSet.has(n.id) && !reparent.has(n.id)) return n\n const s = springs.get(n.id)!\n let position = { x: s.tx, y: s.ty }\n let parentId = n.parentId\n if (reparent.has(n.id)) {\n const abs = getAbsolutePosition(n.id)\n parentId = reparent.get(n.id)\n const pa = parentId ? getAbsolutePosition(parentId) : { x: 0, y: 0 }\n position = { x: abs.x - pa.x, y: abs.y - pa.y }\n const sp = springs.get(n.id)!\n sp.x = sp.tx = position.x\n sp.y = sp.ty = position.y\n const d = disp.get(n.id)!\n d.x = position.x\n d.y = position.y\n }\n const out: FlowNode = { ...n, position }\n if (parentId) out.parentId = parentId\n else delete out.parentId\n return out\n })\n // Spliced in without room: it moves to sit after A, and C with everything after it moves on to make room\n const placed = spliced && plan ? makeRoom(nodes, plan) : nodes\n // Let go first, so the spliced node springs to its place too\n if (spliced) dragging.value = new Set()\n commit({ nodes: placed, edges: spliced ? [...edgesLocal.value.filter((x) => x !== plan!.edge), ...spliced] : undefined })\n const first = nodeById.value.get(g.nodeId)\n if (first) announce(locale.flowMoved.replace('{label}', nodeLabel(first)))\n }\n dragging.value = new Set()\n frozenGroups.clear()\n const draggedNodes = [...g.starts.keys()].map((id) => nodeById.value.get(id)!).filter(Boolean)\n if (plan) emit('insert', { node: nodeById.value.get(plan.node)!, edge: plan.edge, connections: plan.connections })\n emit('node-drag-stop', { nodes: draggedNodes, intersecting: getIntersectingNodes(g.nodeId), event: e })\n}\n\n// Near the edges while dragging, the view scrolls (and what's dragged comes along)\nconst EDGE_ZONE = 40\nfunction autoPan(dt: number) {\n const g = gesture\n if (!g || (g.kind !== 'node' && g.kind !== 'connect') || !g.moved) return false\n const r = rootRect()\n const px = pointer.x - r.left\n const py = pointer.y - r.top\n const speed = 600\n const vx = px < EDGE_ZONE ? 1 - px / EDGE_ZONE : px > r.width - EDGE_ZONE ? -(1 - (r.width - px) / EDGE_ZONE) : 0\n const vy = py < EDGE_ZONE ? 1 - py / EDGE_ZONE : py > r.height - EDGE_ZONE ? -(1 - (r.height - py) / EDGE_ZONE) : 0\n if (!vx && !vy) return false\n const mx = Math.max(-1, Math.min(1, vx)) * speed * dt\n const my = Math.max(-1, Math.min(1, vy)) * speed * dt\n writeViewport({ x: vp.value.x + mx, y: vp.value.y + my, zoom: vp.value.zoom })\n if (g.kind === 'node') {\n // The drag's start shifts with the view so the nodes stay under the pointer\n g.sx += mx\n g.sy += my\n moveNodes(g, pointer.x, pointer.y)\n } else moveConnection(g, pointer.x, pointer.y)\n return true\n}\n\n// ── Connecting ────────────────────────────────────────────────────────────────────────────────────────────\nfunction startConnection(e: PointerEvent, nodeId: string, handleId: string | null, type: 'source' | 'target') {\n const from = handlePoint(nodeId, type, handleId)\n if (!from) return\n gesture = { kind: 'connect', id: e.pointerId, from: { nodeId, handleId, type }, moved: false }\n connection.value = { from, to: { x: from.x, y: from.y }, toPosition: null, type, edgeType: edgeRoute({ ...props.defaultEdgeOptions }) }\n pointer.x = e.clientX\n pointer.y = e.clientY\n emit('connect-start', { nodeId, handleId, type })\n addWindowListeners()\n}\n// A branch: a new connection from the edge's source, its preview leaving from where the edge was grabbed\nfunction startBranch(pan: { id: number; sx: number; sy: number }, edge: FlowEdge, e: PointerEvent) {\n const src = handlePoint(edge.source, 'source', edge.sourceHandle)\n if (!src) return\n const handleId = edge.sourceHandle ?? null\n const g: Gesture = { kind: 'connect', id: pan.id, from: { nodeId: edge.source, handleId, type: 'source' }, moved: true }\n gesture = g\n const at = screenToFlow({ x: pan.sx, y: pan.sy })\n connection.value = { from: { x: at.x, y: at.y, position: src.position }, to: at, toPosition: null, type: 'source', edgeType: edgeRoute(edge) }\n emit('connect-start', { nodeId: edge.source, handleId, type: 'source' })\n moveConnection(g, e.clientX, e.clientY)\n kick()\n}\nfunction startReconnect(e: PointerEvent, edge: FlowEdge, end: 'source' | 'target') {\n // Dragging the target end: the connection runs from the source, and the other way round\n const fixed = end === 'target' ? { nodeId: edge.source, handleId: edge.sourceHandle ?? null, type: 'source' as const } : { nodeId: edge.target, handleId: edge.targetHandle ?? null, type: 'target' as const }\n const from = handlePoint(fixed.nodeId, fixed.type, fixed.handleId)\n if (!from) return\n gesture = { kind: 'connect', id: e.pointerId, from: fixed, reconnect: { edge, end }, moved: false }\n const to = screenToFlow({ x: e.clientX, y: e.clientY })\n connection.value = { from, to, toPosition: null, type: fixed.type, edgeType: edgeRoute(edge) }\n pointer.x = e.clientX\n pointer.y = e.clientY\n addWindowListeners()\n}\nconst handleKey = (nodeId: string, h: { id: string | null; type: string }) => `${nodeId}:${h.id ?? ''}:${h.type}`\nfunction connectionFor(from: { nodeId: string; handleId: string | null; type: 'source' | 'target' }, nodeId: string, handleId: string | null): FlowConnection {\n return from.type === 'source'\n ? { source: from.nodeId, sourceHandle: from.handleId, target: nodeId, targetHandle: handleId }\n : { source: nodeId, sourceHandle: handleId, target: from.nodeId, targetHandle: from.handleId }\n}\nfunction isValid(c: FlowConnection, ignore?: FlowEdge) {\n if (c.source === c.target) return false\n const dup = edgesLocal.value.some((e) => e !== ignore && e.source === c.source && e.target === c.target && (e.sourceHandle ?? null) === c.sourceHandle && (e.targetHandle ?? null) === c.targetHandle)\n if (dup) return false\n return props.isValidConnection ? props.isValidConnection(c) : true\n}\nlet connectionCandidate: { nodeId: string; handleId: string | null; valid: boolean } | null = null\nfunction moveConnection(g: Extract<Gesture, { kind: 'connect' }>, cx: number, cy: number) {\n const p = screenToFlow({ x: cx, y: cy })\n const want = g.from.type === 'source' ? 'target' : 'source'\n const radius = props.connectionRadius / vp.value.zoom\n let best: { nodeId: string; h: FlowHandleBounds | null; d: number; x: number; y: number; position: FlowPosition } | null = null\n for (const n of visibleNodes.value) {\n if (n.connectable === false) continue\n const a = getAbsolutePosition(n.id)\n const s = getSize(n.id)\n const over = p.x >= a.x && p.x <= a.x + s.width && p.y >= a.y && p.y <= a.y + s.height\n const list = (handles.get(n.id) ?? []).filter((h) => h.type === want && h.connectable)\n if (list.length) {\n for (const h of list) {\n const x = a.x + h.x\n const y = a.y + h.y\n const d = Math.hypot(x - p.x, y - p.y)\n // Over the node's body, its nearest handle counts too (easier on touch)\n if ((d <= radius || over) && (!best || d < best.d)) best = { nodeId: n.id, h, d: over && d > radius ? d + radius : d, x, y, position: h.position }\n }\n } else if (over) {\n // A node without a handle of that kind connects at its side (a circle, at its center)\n const position = sidePositions(n)[want]\n const sp = sidePoint(n.id, position)\n const d = Math.hypot(sp.x - p.x, sp.y - p.y)\n if (!best || d < best.d) best = { nodeId: n.id, h: null, d, x: sp.x, y: sp.y, position }\n }\n }\n if (best && best.nodeId === g.from.nodeId) best = null\n const cur = connection.value!\n if (best) {\n const c = connectionFor(g.from, best.nodeId, best.h?.id ?? null)\n const valid = isValid(c, g.reconnect?.edge)\n connectionCandidate = { nodeId: best.nodeId, handleId: best.h?.id ?? null, valid }\n connectionTarget.value = { key: handleKey(best.nodeId, { id: best.h?.id ?? null, type: want }), valid }\n connection.value = { ...cur, to: valid ? { x: best.x, y: best.y } : p, toPosition: valid ? best.position : null }\n } else {\n connectionCandidate = null\n connectionTarget.value = null\n connection.value = { ...cur, to: p, toPosition: null }\n }\n}\nfunction endConnection(g: Extract<Gesture, { kind: 'connect' }>, e: PointerEvent) {\n const cand = connectionCandidate\n connectionCandidate = null\n connection.value = null\n connectionTarget.value = null\n const position = screenToFlow({ x: e.clientX, y: e.clientY })\n const c = cand?.valid ? connectionFor(g.from, cand.nodeId, cand.handleId) : null\n if (g.reconnect) {\n const edge = g.reconnect.edge\n if (c) {\n emit('reconnect', { edge, connection: c })\n if (props.autoConnect) updateEdge(edge.id, { source: c.source, target: c.target, sourceHandle: c.sourceHandle, targetHandle: c.targetHandle })\n } else if (g.moved && !cand && edge.deletable !== false) {\n // Pulled off and dropped on nothing: disconnected (dropped on a handle it can't join, it stays)\n remove({ edges: [edge.id] })\n }\n return\n }\n if (c) {\n emit('connect', c)\n if (props.autoConnect) {\n addEdges({ ...props.defaultEdgeOptions, id: makeId('edge'), ...c })\n const s = nodeById.value.get(c.source)\n const t = nodeById.value.get(c.target)\n if (s && t) announce(locale.flowConnected.replace('{source}', nodeLabel(s)).replace('{target}', nodeLabel(t)))\n }\n }\n emit('connect-end', { connection: c, position, from: g.from })\n}\nconst connectionPath = computed(() => {\n const c = connection.value\n if (!c) return ''\n const flip = c.type === 'target'\n const opposite: Record<FlowPosition, FlowPosition> = { top: 'bottom', bottom: 'top', left: 'right', right: 'left' }\n const toPos = c.toPosition ?? opposite[c.from.position]\n const ends = flip\n ? { sourceX: c.to.x, sourceY: c.to.y, sourcePosition: toPos, targetX: c.from.x, targetY: c.from.y, targetPosition: c.from.position }\n : { sourceX: c.from.x, sourceY: c.from.y, sourcePosition: c.from.position, targetX: c.to.x, targetY: c.to.y, targetPosition: toPos }\n return pathFor(c.edgeType, ends).path\n})\n\n// ── Keyboard ──────────────────────────────────────────────────────────────────────────────────────────────\nconst nodeLabel = (n: FlowNode) => String((n.data as { label?: unknown } | undefined)?.label ?? n.id)\nfunction isTyping(t: EventTarget | null) {\n const el = t as HTMLElement | null\n return !!el?.closest?.('input, textarea, select, [contenteditable]:not([contenteditable=\"false\"])')\n}\nfunction onKeyDown(e: KeyboardEvent) {\n if (isTyping(e.target)) return\n const mod = e.ctrlKey || e.metaKey\n const key = e.key.toLowerCase()\n if (e.key === 'Escape') {\n if (gesture) cancelGesture()\n else if (selLocal.value.nodes.length || selLocal.value.edges.length) setSelection(emptySelection())\n else return\n e.preventDefault()\n e.stopPropagation()\n return\n }\n if (mod && key === 'z' && !e.shiftKey) { e.preventDefault(); undo(); return }\n if (mod && ((key === 'z' && e.shiftKey) || key === 'y')) { e.preventDefault(); redo(); return }\n if (mod && key === 'a') { e.preventDefault(); selectAll(); return }\n if (mod && key === 'c') { copy(); return }\n if (mod && key === 'x') { e.preventDefault(); cut(); return }\n if (mod && key === 'v') {\n e.preventDefault()\n paste(pointer.inside ? screenToFlow(pointer) : undefined)\n return\n }\n if (props.deleteKeys?.includes(e.key)) { e.preventDefault(); deleteSelection(); return }\n if (!mod && (e.key === '+' || e.key === '=')) { e.preventDefault(); zoomIn(); return }\n if (!mod && (e.key === '-' || e.key === '_')) { e.preventDefault(); zoomOut(); return }\n if (e.key === '!' || (e.shiftKey && e.code === 'Digit1')) { e.preventDefault(); fitView(); return }\n const arrows: Record<string, [number, number]> = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }\n const dir = arrows[e.key]\n if (dir && selLocal.value.nodes.length && canDrag.value) {\n e.preventDefault()\n const step = props.snapToGrid ? props.gridSize : e.shiftKey ? 50 : 10\n const sel = selLocal.value.nodes\n const ids = new Set(sel.filter((id) => nodeById.value.get(id)?.draggable !== false && !ancestors(id).some((a) => sel.includes(a))))\n if (!ids.size) return\n instantNext = true\n commit({ nodes: nodesLocal.value.map((n) => (ids.has(n.id) ? { ...n, position: { x: n.position.x + dir[0] * step, y: n.position.y + dir[1] * step } } : n)) }, { coalesce: `move:${[...ids].join(',')}` })\n const first = nodeById.value.get([...ids][0]!)\n if (first) announce(locale.flowMoved.replace('{label}', nodeLabel(first)))\n } else if (dir && !selLocal.value.nodes.length) {\n e.preventDefault()\n writeViewport({ x: vp.value.x - dir[0] * 40, y: vp.value.y - dir[1] * 40, zoom: vp.value.zoom })\n }\n}\n// Focusing a node (Tab) and Enter/Space on it select it\nfunction onNodeKey(e: KeyboardEvent, id: string) {\n if (isTyping(e.target) || (e.target as HTMLElement).dataset.flowNode !== id) return\n if ((e.key === 'Enter' || e.key === ' ') && canSelect.value) {\n e.preventDefault()\n if (e.shiftKey) setSelection({ nodes: selectedNodes.value.has(id) ? selLocal.value.nodes.filter((i) => i !== id) : [...selLocal.value.nodes, id] })\n else setSelection({ nodes: [id], edges: [] })\n }\n}\nfunction onEdgeKey(e: KeyboardEvent, id: string) {\n if ((e.key === 'Enter' || e.key === ' ') && canSelect.value) {\n e.preventDefault()\n setSelection({ nodes: [], edges: [id] })\n }\n}\n\n// ── Background ────────────────────────────────────────────────────────────────────────────────────────────\nconst patternId = `m3-flow-bg-${Math.random().toString(36).slice(2, 8)}`\nconst pattern = computed(() => {\n let gap = props.gridSize * vp.value.zoom\n // Coarser when zoomed out, so the dots don't turn into a gray haze\n while (gap < 10) gap *= 2\n return { gap, x: ((vp.value.x % gap) + gap) % gap, y: ((vp.value.y % gap) + gap) % gap, r: Math.max(0.6, Math.min(1.4, vp.value.zoom)) }\n})\n\n// ── Context ───────────────────────────────────────────────────────────────────────────────────────────────\nconst context: FlowInternals = {\n nodes: computed(() => nodesLocal.value),\n edges: computed(() => edgesLocal.value),\n viewport: vp,\n minZoom: computed(() => props.minZoom),\n maxZoom: computed(() => props.maxZoom),\n selection: computed(() => selLocal.value),\n size,\n locked,\n getNode,\n getAbsolutePosition,\n getSize,\n getIntersectingNodes,\n screenToFlow,\n flowToScreen,\n setViewport,\n fitView,\n setCenter,\n zoomIn,\n zoomOut,\n zoomTo,\n addNodes,\n addEdges,\n updateNode,\n updateEdge,\n remove,\n setSelection,\n layout: (fn, options) => runLayout(fn, options),\n undo,\n redo,\n canUndo,\n canRedo,\n copy,\n cut,\n paste,\n startDrag,\n registerHandle,\n measureNode: queueMeasure,\n startConnection,\n connectionTarget,\n connecting,\n insertEdge,\n branching,\n nodesConnectable,\n direction: computed(() => props.direction),\n // For the internal node shells and edges\n registerNodeEl,\n selectedNodes,\n selectedEdges,\n dragging,\n isLifted,\n zIndexOf,\n edgeGeometry,\n isReconnectable,\n sidePositions,\n onNodeKey,\n onEdgeKey,\n}\nprovide(FLOW_KEY, context)\n\n// ── Mount ─────────────────────────────────────────────────────────────────────────────────────────────────\nlet ro: ResizeObserver | undefined\nonMounted(async () => {\n const el = root.value!\n el.addEventListener('wheel', onWheel, { passive: false })\n const sizeRo = new ResizeObserver(() => { size.value = { width: el.clientWidth, height: el.clientHeight } })\n sizeRo.observe(el)\n onBeforeUnmount(() => sizeRo.disconnect())\n size.value = { width: el.clientWidth, height: el.clientHeight }\n ro = new ResizeObserver((entries) => {\n for (const en of entries) {\n const id = (en.target as HTMLElement).dataset.flowNode\n if (id) measureNode(id)\n }\n })\n for (const [id, n] of nodeEls) { ro.observe(n); measureNode(id) }\n await nextTick()\n if (props.layout) await runLayout(null, undefined, { history: false })\n await nextTick()\n if (props.fitView) fitView({ animate: false })\n ready.value = true\n emit('init', context)\n})\nonBeforeUnmount(() => {\n root.value?.removeEventListener('wheel', onWheel)\n removeWindowListeners()\n ro?.disconnect()\n if (raf) cancelAnimationFrame(raf)\n clearTimeout(longPress)\n document.body.style.userSelect = ''\n})\n\ndefineExpose(context as FlowContext)\n</script>\n\n<template>\n <div\n ref=\"root\"\n v-bind=\"$attrs\"\n class=\"m3-flow overflow-hidden bg-surface outline-none select-none\"\n :class=\"[panning && 'cursor-grabbing', locked && 'm3-flow-locked']\"\n tabindex=\"0\"\n role=\"application\"\n :aria-label=\"label ?? locale.flowCanvas\"\n aria-roledescription=\"flow\"\n @pointerdown=\"onPointerDown\"\n @pointerenter=\"pointer.inside = true\"\n @pointerleave=\"pointer.inside = false\"\n @dblclick=\"onDblClick\"\n @contextmenu=\"onContextMenu\"\n @keydown=\"onKeyDown\"\n >\n <svg v-if=\"background !== 'none'\" class=\"pointer-events-none absolute inset-0 size-full\" aria-hidden=\"true\">\n <defs>\n <pattern :id=\"patternId\" :x=\"pattern.x\" :y=\"pattern.y\" :width=\"pattern.gap\" :height=\"pattern.gap\" patternUnits=\"userSpaceOnUse\">\n <circle v-if=\"background === 'dots'\" :cx=\"pattern.r\" :cy=\"pattern.r\" :r=\"pattern.r\" class=\"fill-outline-variant\" />\n <path v-else :d=\"`M${pattern.gap} 0 L0 0 0 ${pattern.gap}`\" fill=\"none\" class=\"stroke-outline-variant\" stroke-width=\"1\" />\n </pattern>\n </defs>\n <rect width=\"100%\" height=\"100%\" :fill=\"`url(#${patternId})`\" />\n </svg>\n\n <div\n ref=\"layer\"\n class=\"m3-flow-viewport absolute top-0 left-0 origin-top-left\"\n :style=\"{ transform: `translate(${vp.x}px, ${vp.y}px) scale(${vp.zoom})`, visibility: ready ? undefined : 'hidden' }\"\n >\n <NodeShell v-for=\"n in groupNodes\" :key=\"n.id\" :node=\"n\" :render=\"nodeRenderer(n)\" />\n <svg class=\"m3-flow-edges pointer-events-none absolute top-0 left-0 size-px overflow-visible\" aria-hidden=\"false\">\n <EdgeView v-for=\"e in visibleEdges\" :key=\"e.id\" :edge=\"e\" :render=\"edgeRenderer(e)\" />\n <path\n v-if=\"connection\"\n class=\"m3-flow-connection-line fill-none stroke-primary\"\n :d=\"connectionPath\"\n stroke-width=\"2\"\n :stroke-dasharray=\"connectionTarget?.valid ? undefined : '6 4'\"\n />\n </svg>\n <div class=\"m3-flow-edge-labels absolute top-0 left-0\">\n <template v-for=\"e in visibleEdges\" :key=\"e.id\">\n <EdgeLabel v-if=\"e.label || $slots['edge-label'] || selectedEdges.has(e.id)\" :edge=\"e\" :render=\"$slots['edge-label']\" />\n </template>\n </div>\n <NodeShell v-for=\"n in plainNodes\" :key=\"n.id\" :node=\"n\" :render=\"nodeRenderer(n)\" />\n <svg v-if=\"guideLines.length\" class=\"pointer-events-none absolute top-0 left-0 size-px overflow-visible\" aria-hidden=\"true\">\n <line\n v-for=\"(g, i) in guideLines\"\n :key=\"i\"\n class=\"stroke-primary\"\n stroke-width=\"1\"\n vector-effect=\"non-scaling-stroke\"\n :x1=\"g.x ?? g.from\"\n :x2=\"g.x ?? g.to\"\n :y1=\"g.y ?? g.from\"\n :y2=\"g.y ?? g.to\"\n />\n </svg>\n </div>\n\n <div\n v-if=\"marquee\"\n class=\"m3-flow-marquee pointer-events-none absolute rounded-xs border border-primary bg-primary/8\"\n :style=\"{ left: `${marquee.x}px`, top: `${marquee.y}px`, width: `${marquee.width}px`, height: `${marquee.height}px` }\"\n />\n\n <div v-if=\"!nodesLocal.length && $slots.empty\" class=\"pointer-events-none absolute inset-0 flex items-center justify-center\">\n <div class=\"pointer-events-auto\">\n <slot name=\"empty\" />\n </div>\n </div>\n\n <slot :flow=\"context\" />\n\n <div class=\"sr-only\" aria-live=\"polite\">{{ announcement }}</div>\n </div>\n</template>\n\n<style>\n@layer base {\n .m3-flow {\n position: relative;\n display: block;\n touch-action: none;\n /* No callout (save image, copy) on a long press: a long press there selects */\n -webkit-touch-callout: none;\n }\n}\n.m3-flow-circle {\n transition: background-color 250ms cubic-bezier(0.2, 0, 0, 1), color 250ms cubic-bezier(0.2, 0, 0, 1), border-color 200ms, box-shadow 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.m3-flow-edge-line {\n transition: stroke 250ms cubic-bezier(0.2, 0, 0, 1), stroke-width 250ms cubic-bezier(0.2, 0, 0, 1), fill 250ms cubic-bezier(0.2, 0, 0, 1);\n}\n.m3-flow-edge-animated {\n stroke-dasharray: 6 4;\n animation: m3-flow-dash 400ms linear infinite;\n}\n.m3-flow-edge-reverse {\n animation-direction: reverse;\n}\n.m3-flow-edge-dashed {\n stroke-dasharray: 6 4;\n}\n@keyframes m3-flow-dash {\n from { stroke-dashoffset: 10; }\n to { stroke-dashoffset: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n .m3-flow-edge-animated { animation: none; }\n .m3-flow-edge-line { transition: none; }\n}\n</style>\n","// Where MFlowControls / MFlowMinimap (or a panel of yours) sit over MFlow's canvas\nexport type FlowPanelPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center-left' | 'center-right'\n\nexport const panelPositionClass: Record<FlowPanelPosition, string> = {\n 'top-left': 'top-0 left-0',\n 'top-center': 'top-0 left-1/2 -translate-x-1/2',\n 'top-right': 'top-0 right-0',\n 'bottom-left': 'bottom-0 left-0',\n 'bottom-center': 'bottom-0 left-1/2 -translate-x-1/2',\n 'bottom-right': 'bottom-0 right-0',\n 'center-left': 'top-1/2 left-0 -translate-y-1/2',\n 'center-right': 'top-1/2 right-0 -translate-y-1/2',\n}\n","<script setup lang=\"ts\">\n/**\n * Zoom, fit and lock buttons over an MFlow, as an M3 floating toolbar (put it in MFlow's default slot). Undo and\n * redo with `history`; a delete button shows while something deletable is selected (`delete`). Not an M3 spec component.\n *\n * @slot default More buttons at the end\n */\nimport { computed } from 'vue'\nimport { useFlow } from '../composables/useFlow'\nimport { panelPositionClass, type FlowPanelPosition } from '../composables/_flowPanel'\nimport { useLocale } from '../composables/useLocale'\nimport MIconButton from './MIconButton.vue'\n\nconst props = withDefaults(defineProps<{\n position?: FlowPanelPosition\n orientation?: 'vertical' | 'horizontal'\n zoom?: boolean\n fit?: boolean\n lock?: boolean\n /** Undo and redo buttons */\n history?: boolean\n /** A delete button while something deletable is selected (touch has no Delete key) */\n delete?: boolean\n}>(), {\n position: 'bottom-left',\n orientation: 'vertical',\n zoom: true,\n fit: true,\n lock: true,\n history: false,\n delete: true,\n})\n\nconst flow = useFlow()\nconst locale = useLocale()\nconst vertical = computed(() => props.orientation === 'vertical')\nconst deletable = computed(() => {\n const s = flow.selection.value\n return {\n nodes: s.nodes.filter((id) => flow.getNode(id)?.deletable !== false),\n edges: s.edges.filter((id) => flow.edges.value.find((e) => e.id === id)?.deletable !== false),\n }\n})\nconst canDelete = computed(() => props.delete && !flow.locked.value && (deletable.value.nodes.length + deletable.value.edges.length > 0))\n</script>\n\n<template>\n <div\n class=\"m3-flow-controls absolute z-20 m-4 flex gap-1 rounded-full bg-surface-container p-1 shadow-elevation-3\"\n :class=\"[panelPositionClass[position], vertical ? 'flex-col' : 'flex-row']\"\n role=\"toolbar\"\n :aria-orientation=\"orientation\"\n >\n <template v-if=\"zoom\">\n <MIconButton icon=\"add\" :label=\"locale.flowZoomIn\" :disabled=\"flow.viewport.value.zoom >= flow.maxZoom.value - 0.001\" @click=\"flow.zoomIn()\" />\n <MIconButton icon=\"remove\" :label=\"locale.flowZoomOut\" :disabled=\"flow.viewport.value.zoom <= flow.minZoom.value + 0.001\" @click=\"flow.zoomOut()\" />\n </template>\n <MIconButton v-if=\"fit\" icon=\"fit_screen\" :label=\"locale.flowFitView\" @click=\"flow.fitView()\" />\n <template v-if=\"history\">\n <MIconButton icon=\"undo\" :label=\"locale.flowUndo\" :disabled=\"!flow.canUndo.value\" @click=\"flow.undo()\" />\n <MIconButton icon=\"redo\" :label=\"locale.flowRedo\" :disabled=\"!flow.canRedo.value\" @click=\"flow.redo()\" />\n </template>\n <!-- The toolbar grows to make room for it instead of jumping -->\n <Transition :name=\"vertical ? 'm3-flow-ctl-v' : 'm3-flow-ctl-h'\">\n <MIconButton v-if=\"canDelete\" icon=\"delete\" :label=\"locale.flowDelete\" color=\"error\" @click=\"flow.remove(deletable)\" />\n </Transition>\n <MIconButton\n v-if=\"lock\"\n :icon=\"flow.locked.value ? 'lock' : 'lock_open'\"\n :label=\"flow.locked.value ? locale.flowUnlock : locale.flowLock\"\n @click=\"flow.locked.value = !flow.locked.value\"\n />\n <slot />\n </div>\n</template>\n\n<style>\n.m3-flow-ctl-v-enter-active,\n.m3-flow-ctl-v-leave-active,\n.m3-flow-ctl-h-enter-active,\n.m3-flow-ctl-h-leave-active {\n overflow: hidden;\n transition: max-height 300ms cubic-bezier(0.2, 0, 0, 1), max-width 300ms cubic-bezier(0.2, 0, 0, 1), margin 300ms cubic-bezier(0.2, 0, 0, 1), scale 300ms cubic-bezier(0.2, 0, 0, 1), opacity 200ms linear;\n}\n.m3-flow-ctl-v-enter-from,\n.m3-flow-ctl-v-leave-to {\n max-height: 0;\n margin-top: -0.25rem;\n scale: 0.5;\n opacity: 0;\n}\n.m3-flow-ctl-v-enter-to,\n.m3-flow-ctl-v-leave-from {\n max-height: 2.5rem;\n}\n.m3-flow-ctl-h-enter-from,\n.m3-flow-ctl-h-leave-to {\n max-width: 0;\n margin-left: -0.25rem;\n scale: 0.5;\n opacity: 0;\n}\n.m3-flow-ctl-h-enter-to,\n.m3-flow-ctl-h-leave-from {\n max-width: 2.5rem;\n}\n@media (prefers-reduced-motion: reduce) {\n .m3-flow-ctl-v-enter-active, .m3-flow-ctl-v-leave-active, .m3-flow-ctl-h-enter-active, .m3-flow-ctl-h-leave-active { transition: none; }\n}\n</style>\n","<script setup lang=\"ts\">\n/**\n * Zoom, fit and lock buttons over an MFlow, as an M3 floating toolbar (put it in MFlow's default slot). Undo and\n * redo with `history`; a delete button shows while something deletable is selected (`delete`). Not an M3 spec component.\n *\n * @slot default More buttons at the end\n */\nimport { computed } from 'vue'\nimport { useFlow } from '../composables/useFlow'\nimport { panelPositionClass, type FlowPanelPosition } from '../composables/_flowPanel'\nimport { useLocale } from '../composables/useLocale'\nimport MIconButton from './MIconButton.vue'\n\nconst props = withDefaults(defineProps<{\n position?: FlowPanelPosition\n orientation?: 'vertical' | 'horizontal'\n zoom?: boolean\n fit?: boolean\n lock?: boolean\n /** Undo and redo buttons */\n history?: boolean\n /** A delete button while something deletable is selected (touch has no Delete key) */\n delete?: boolean\n}>(), {\n position: 'bottom-left',\n orientation: 'vertical',\n zoom: true,\n fit: true,\n lock: true,\n history: false,\n delete: true,\n})\n\nconst flow = useFlow()\nconst locale = useLocale()\nconst vertical = computed(() => props.orientation === 'vertical')\nconst deletable = computed(() => {\n const s = flow.selection.value\n return {\n nodes: s.nodes.filter((id) => flow.getNode(id)?.deletable !== false),\n edges: s.edges.filter((id) => flow.edges.value.find((e) => e.id === id)?.deletable !== false),\n }\n})\nconst canDelete = computed(() => props.delete && !flow.locked.value && (deletable.value.nodes.length + deletable.value.edges.length > 0))\n</script>\n\n<template>\n <div\n class=\"m3-flow-controls absolute z-20 m-4 flex gap-1 rounded-full bg-surface-container p-1 shadow-elevation-3\"\n :class=\"[panelPositionClass[position], vertical ? 'flex-col' : 'flex-row']\"\n role=\"toolbar\"\n :aria-orientation=\"orientation\"\n >\n <template v-if=\"zoom\">\n <MIconButton icon=\"add\" :label=\"locale.flowZoomIn\" :disabled=\"flow.viewport.value.zoom >= flow.maxZoom.value - 0.001\" @click=\"flow.zoomIn()\" />\n <MIconButton icon=\"remove\" :label=\"locale.flowZoomOut\" :disabled=\"flow.viewport.value.zoom <= flow.minZoom.value + 0.001\" @click=\"flow.zoomOut()\" />\n </template>\n <MIconButton v-if=\"fit\" icon=\"fit_screen\" :label=\"locale.flowFitView\" @click=\"flow.fitView()\" />\n <template v-if=\"history\">\n <MIconButton icon=\"undo\" :label=\"locale.flowUndo\" :disabled=\"!flow.canUndo.value\" @click=\"flow.undo()\" />\n <MIconButton icon=\"redo\" :label=\"locale.flowRedo\" :disabled=\"!flow.canRedo.value\" @click=\"flow.redo()\" />\n </template>\n <!-- The toolbar grows to make room for it instead of jumping -->\n <Transition :name=\"vertical ? 'm3-flow-ctl-v' : 'm3-flow-ctl-h'\">\n <MIconButton v-if=\"canDelete\" icon=\"delete\" :label=\"locale.flowDelete\" color=\"error\" @click=\"flow.remove(deletable)\" />\n </Transition>\n <MIconButton\n v-if=\"lock\"\n :icon=\"flow.locked.value ? 'lock' : 'lock_open'\"\n :label=\"flow.locked.value ? locale.flowUnlock : locale.flowLock\"\n @click=\"flow.locked.value = !flow.locked.value\"\n />\n <slot />\n </div>\n</template>\n\n<style>\n.m3-flow-ctl-v-enter-active,\n.m3-flow-ctl-v-leave-active,\n.m3-flow-ctl-h-enter-active,\n.m3-flow-ctl-h-leave-active {\n overflow: hidden;\n transition: max-height 300ms cubic-bezier(0.2, 0, 0, 1), max-width 300ms cubic-bezier(0.2, 0, 0, 1), margin 300ms cubic-bezier(0.2, 0, 0, 1), scale 300ms cubic-bezier(0.2, 0, 0, 1), opacity 200ms linear;\n}\n.m3-flow-ctl-v-enter-from,\n.m3-flow-ctl-v-leave-to {\n max-height: 0;\n margin-top: -0.25rem;\n scale: 0.5;\n opacity: 0;\n}\n.m3-flow-ctl-v-enter-to,\n.m3-flow-ctl-v-leave-from {\n max-height: 2.5rem;\n}\n.m3-flow-ctl-h-enter-from,\n.m3-flow-ctl-h-leave-to {\n max-width: 0;\n margin-left: -0.25rem;\n scale: 0.5;\n opacity: 0;\n}\n.m3-flow-ctl-h-enter-to,\n.m3-flow-ctl-h-leave-from {\n max-width: 2.5rem;\n}\n@media (prefers-reduced-motion: reduce) {\n .m3-flow-ctl-v-enter-active, .m3-flow-ctl-v-leave-active, .m3-flow-ctl-h-enter-active, .m3-flow-ctl-h-leave-active { transition: none; }\n}\n</style>\n","<script setup lang=\"ts\">\n/**\n * A small overview of an MFlow (put it in MFlow's default slot): every node as a block, the part in view\n * outlined. Drag or click in it to move the view there; the wheel zooms. Not an M3 spec component.\n */\nimport { computed, ref } from 'vue'\nimport { useFlow, type FlowNode } from '../composables/useFlow'\nimport { panelPositionClass, type FlowPanelPosition } from '../composables/_flowPanel'\nimport { useLocale } from '../composables/useLocale'\n\nconst props = withDefaults(defineProps<{\n position?: FlowPanelPosition\n width?: number\n height?: number\n /** A node's fill (any CSS color); default outline-variant, primary when selected */\n nodeColor?: (node: FlowNode) => string | undefined\n /** Drag and click move the view */\n pannable?: boolean\n /** The wheel zooms */\n zoomable?: boolean\n}>(), {\n position: 'bottom-right',\n width: 200,\n height: 140,\n pannable: true,\n zoomable: true,\n})\n\nconst flow = useFlow()\nconst locale = useLocale()\nconst svg = ref<SVGSVGElement>()\n\nconst blocks = computed(() => flow.nodes.value\n .filter((n) => !n.hidden)\n .map((n) => ({ node: n, ...flow.getAbsolutePosition(n.id), ...flow.getSize(n.id) }))\n .filter((b) => b.width > 0 && b.height > 0))\nconst view = computed(() => {\n const v = flow.viewport.value\n const s = flow.size.value\n return { x: -v.x / v.zoom, y: -v.y / v.zoom, width: s.width / v.zoom, height: s.height / v.zoom }\n})\nlet frozen: { x: number; y: number; width: number; height: number } | null = null\nconst box = computed(() => {\n if (frozen) return frozen\n let x1 = view.value.x\n let y1 = view.value.y\n let x2 = x1 + view.value.width\n let y2 = y1 + view.value.height\n for (const b of blocks.value) {\n x1 = Math.min(x1, b.x)\n y1 = Math.min(y1, b.y)\n x2 = Math.max(x2, b.x + b.width)\n y2 = Math.max(y2, b.y + b.height)\n }\n // The minimap's own aspect, centered on everything, with a margin\n const w = Math.max(1, x2 - x1)\n const h = Math.max(1, y2 - y1)\n const scale = Math.max(w / props.width, h / props.height) * 1.1\n const vw = props.width * scale\n const vh = props.height * scale\n return { x: x1 + w / 2 - vw / 2, y: y1 + h / 2 - vh / 2, width: vw, height: vh }\n})\nconst mask = computed(() => {\n const b = box.value\n const v = view.value\n return `M${b.x},${b.y}h${b.width}v${b.height}h${-b.width}Z M${v.x},${v.y}v${v.height}h${v.width}v${-v.height}Z`\n})\n\nfunction toFlow(e: PointerEvent | WheelEvent) {\n const r = svg.value!.getBoundingClientRect()\n const b = box.value\n return { x: b.x + ((e.clientX - r.left) / r.width) * b.width, y: b.y + ((e.clientY - r.top) / r.height) * b.height }\n}\nfunction onPointerDown(e: PointerEvent) {\n if (!props.pannable) return\n e.preventDefault()\n frozen = { ...box.value }\n svg.value!.setPointerCapture?.(e.pointerId)\n const p = toFlow(e)\n flow.setCenter(p.x, p.y, { animate: true })\n}\nfunction onPointerMove(e: PointerEvent) {\n if (!frozen) return\n const p = toFlow(e)\n flow.setCenter(p.x, p.y, { animate: false })\n}\nfunction onPointerUp() {\n frozen = null\n}\nfunction onWheel(e: WheelEvent) {\n if (!props.zoomable) return\n flow.zoomTo(flow.viewport.value.zoom * Math.exp(-Math.max(-50, Math.min(50, e.deltaY)) * 0.01), { animate: false })\n}\n</script>\n\n<template>\n <div\n class=\"m3-flow-minimap absolute z-20 m-4 overflow-hidden rounded-lg bg-surface-container shadow-elevation-3\"\n :class=\"panelPositionClass[position]\"\n @wheel.stop.prevent=\"onWheel\"\n >\n <svg\n ref=\"svg\"\n :width=\"width\"\n :height=\"height\"\n :viewBox=\"`${box.x} ${box.y} ${box.width} ${box.height}`\"\n class=\"block touch-none\"\n :class=\"pannable && 'cursor-pointer'\"\n role=\"img\"\n :aria-label=\"locale.flowMinimap\"\n @pointerdown=\"onPointerDown\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerUp\"\n >\n <rect\n v-for=\"b in blocks\"\n :key=\"b.node.id\"\n :x=\"b.x\"\n :y=\"b.y\"\n :width=\"b.width\"\n :height=\"b.height\"\n :rx=\"Math.min(b.width, b.height) * 0.1\"\n :class=\"b.node.type === 'group'\n ? 'fill-none stroke-outline-variant'\n : !nodeColor?.(b.node) && (flow.selection.value.nodes.includes(b.node.id) ? 'fill-primary' : 'fill-outline-variant')\"\n :style=\"b.node.type !== 'group' && nodeColor?.(b.node) ? { fill: nodeColor(b.node) } : undefined\"\n vector-effect=\"non-scaling-stroke\"\n />\n <path :d=\"mask\" fill-rule=\"evenodd\" class=\"fill-on-surface/8\" />\n <rect :x=\"view.x\" :y=\"view.y\" :width=\"view.width\" :height=\"view.height\" fill=\"none\" class=\"stroke-primary\" stroke-width=\"1.5\" vector-effect=\"non-scaling-stroke\" />\n </svg>\n </div>\n</template>\n","<script setup lang=\"ts\">\n/**\n * A small overview of an MFlow (put it in MFlow's default slot): every node as a block, the part in view\n * outlined. Drag or click in it to move the view there; the wheel zooms. Not an M3 spec component.\n */\nimport { computed, ref } from 'vue'\nimport { useFlow, type FlowNode } from '../composables/useFlow'\nimport { panelPositionClass, type FlowPanelPosition } from '../composables/_flowPanel'\nimport { useLocale } from '../composables/useLocale'\n\nconst props = withDefaults(defineProps<{\n position?: FlowPanelPosition\n width?: number\n height?: number\n /** A node's fill (any CSS color); default outline-variant, primary when selected */\n nodeColor?: (node: FlowNode) => string | undefined\n /** Drag and click move the view */\n pannable?: boolean\n /** The wheel zooms */\n zoomable?: boolean\n}>(), {\n position: 'bottom-right',\n width: 200,\n height: 140,\n pannable: true,\n zoomable: true,\n})\n\nconst flow = useFlow()\nconst locale = useLocale()\nconst svg = ref<SVGSVGElement>()\n\nconst blocks = computed(() => flow.nodes.value\n .filter((n) => !n.hidden)\n .map((n) => ({ node: n, ...flow.getAbsolutePosition(n.id), ...flow.getSize(n.id) }))\n .filter((b) => b.width > 0 && b.height > 0))\nconst view = computed(() => {\n const v = flow.viewport.value\n const s = flow.size.value\n return { x: -v.x / v.zoom, y: -v.y / v.zoom, width: s.width / v.zoom, height: s.height / v.zoom }\n})\nlet frozen: { x: number; y: number; width: number; height: number } | null = null\nconst box = computed(() => {\n if (frozen) return frozen\n let x1 = view.value.x\n let y1 = view.value.y\n let x2 = x1 + view.value.width\n let y2 = y1 + view.value.height\n for (const b of blocks.value) {\n x1 = Math.min(x1, b.x)\n y1 = Math.min(y1, b.y)\n x2 = Math.max(x2, b.x + b.width)\n y2 = Math.max(y2, b.y + b.height)\n }\n // The minimap's own aspect, centered on everything, with a margin\n const w = Math.max(1, x2 - x1)\n const h = Math.max(1, y2 - y1)\n const scale = Math.max(w / props.width, h / props.height) * 1.1\n const vw = props.width * scale\n const vh = props.height * scale\n return { x: x1 + w / 2 - vw / 2, y: y1 + h / 2 - vh / 2, width: vw, height: vh }\n})\nconst mask = computed(() => {\n const b = box.value\n const v = view.value\n return `M${b.x},${b.y}h${b.width}v${b.height}h${-b.width}Z M${v.x},${v.y}v${v.height}h${v.width}v${-v.height}Z`\n})\n\nfunction toFlow(e: PointerEvent | WheelEvent) {\n const r = svg.value!.getBoundingClientRect()\n const b = box.value\n return { x: b.x + ((e.clientX - r.left) / r.width) * b.width, y: b.y + ((e.clientY - r.top) / r.height) * b.height }\n}\nfunction onPointerDown(e: PointerEvent) {\n if (!props.pannable) return\n e.preventDefault()\n frozen = { ...box.value }\n svg.value!.setPointerCapture?.(e.pointerId)\n const p = toFlow(e)\n flow.setCenter(p.x, p.y, { animate: true })\n}\nfunction onPointerMove(e: PointerEvent) {\n if (!frozen) return\n const p = toFlow(e)\n flow.setCenter(p.x, p.y, { animate: false })\n}\nfunction onPointerUp() {\n frozen = null\n}\nfunction onWheel(e: WheelEvent) {\n if (!props.zoomable) return\n flow.zoomTo(flow.viewport.value.zoom * Math.exp(-Math.max(-50, Math.min(50, e.deltaY)) * 0.01), { animate: false })\n}\n</script>\n\n<template>\n <div\n class=\"m3-flow-minimap absolute z-20 m-4 overflow-hidden rounded-lg bg-surface-container shadow-elevation-3\"\n :class=\"panelPositionClass[position]\"\n @wheel.stop.prevent=\"onWheel\"\n >\n <svg\n ref=\"svg\"\n :width=\"width\"\n :height=\"height\"\n :viewBox=\"`${box.x} ${box.y} ${box.width} ${box.height}`\"\n class=\"block touch-none\"\n :class=\"pannable && 'cursor-pointer'\"\n role=\"img\"\n :aria-label=\"locale.flowMinimap\"\n @pointerdown=\"onPointerDown\"\n @pointermove=\"onPointerMove\"\n @pointerup=\"onPointerUp\"\n @pointercancel=\"onPointerUp\"\n >\n <rect\n v-for=\"b in blocks\"\n :key=\"b.node.id\"\n :x=\"b.x\"\n :y=\"b.y\"\n :width=\"b.width\"\n :height=\"b.height\"\n :rx=\"Math.min(b.width, b.height) * 0.1\"\n :class=\"b.node.type === 'group'\n ? 'fill-none stroke-outline-variant'\n : !nodeColor?.(b.node) && (flow.selection.value.nodes.includes(b.node.id) ? 'fill-primary' : 'fill-outline-variant')\"\n :style=\"b.node.type !== 'group' && nodeColor?.(b.node) ? { fill: nodeColor(b.node) } : undefined\"\n vector-effect=\"non-scaling-stroke\"\n />\n <path :d=\"mask\" fill-rule=\"evenodd\" class=\"fill-on-surface/8\" />\n <rect :x=\"view.x\" :y=\"view.y\" :width=\"view.width\" :height=\"view.height\" fill=\"none\" class=\"stroke-primary\" stroke-width=\"1.5\" vector-effect=\"non-scaling-stroke\" />\n </svg>\n </div>\n</template>\n","// Graphs as text for MFlow: Graphviz DOT and Mermaid flowcharts, read into nodes and edges and written back. Pure\n// functions without dependencies. Text formats carry no positions (DOT's `pos` aside), so what's read is laid out\n// with layoutLayered (or layoutTree), clusters and subgraphs becoming groups laid out from the inside out.\nimport type { FlowEdge, FlowMarker, FlowNode, FlowXY } from './useFlow'\nimport { layoutLayered, layoutTree, type FlowLayoutDirection, type FlowLayoutOptions } from './flowLayout'\n\n/** A graph read from text */\nexport interface FlowGraph {\n nodes: FlowNode[]\n edges: FlowEdge[]\n /** The graph's own direction (DOT `rankdir`, Mermaid `flowchart LR`) */\n rankdir: FlowLayoutDirection\n /** The same, as MFlow's `direction` prop */\n direction: 'horizontal' | 'vertical'\n /** False for a DOT `graph` (edges without arrows) */\n directed: boolean\n /** The DOT graph's name */\n name?: string\n /** The DOT graph's `label` */\n label?: string\n /** Every graph-level DOT attribute, as written */\n attrs: Record<string, string>\n}\n\nexport interface FlowImportOptions {\n /** How to place the nodes: `'layered'` (default), `'tree'`, or `false` to leave them at 0,0 (for MFlow's `layout` prop, which measures them first) */\n layout?: 'layered' | 'tree' | false\n /** Gaps, sizes and direction for the layout (the direction defaults to the graph's own) */\n layoutOptions?: FlowLayoutOptions\n /** The type given to plain nodes (default none: MFlow's default node) */\n nodeType?: string\n /** The type given to every edge (e.g. `'smoothstep'`; default none: a bezier) */\n edgeType?: string\n}\n\nexport interface FlowExportOptions {\n /** The direction written (`rankdir` / `flowchart XX`): a layout direction or MFlow's `direction` (default TB) */\n direction?: FlowLayoutDirection | 'horizontal' | 'vertical'\n /** Node sizes, for `positions` (default each node's `width`/`height`, else 180 × 60) */\n sizes?: Map<string, { width: number; height: number }> | Record<string, { width: number; height: number }>\n}\n\nexport interface FlowDotExportOptions extends FlowExportOptions {\n /** The graph's name */\n name?: string\n /** `digraph` (default) or `graph`, whose edges have no direction */\n directed?: boolean\n /** Writes each node's place as `pos` (in points, y up), for `neato -n` */\n positions?: boolean\n}\n\nconst ROLES = new Set(['primary', 'secondary', 'tertiary', 'error', 'neutral', 'inverse', 'outline', 'outline-variant', 'success', 'on-surface', 'on-surface-variant'])\nconst GROUP_PAD = 24\nconst GROUP_HEAD = 36\nconst CIRCLE = 56\n\nfunction toRankdir(d: FlowExportOptions['direction']): FlowLayoutDirection {\n if (d === 'horizontal') return 'LR'\n if (d === 'vertical' || !d) return 'TB'\n return d\n}\nfunction asDirection(r: FlowLayoutDirection): 'horizontal' | 'vertical' {\n return r === 'LR' || r === 'RL' ? 'horizontal' : 'vertical'\n}\n\n// A guess at the default node's size before it's measured (min 11rem, max 18rem wide)\nfunction estimateSize(n: FlowNode): { width: number; height: number } {\n if (n.width && n.height) return { width: n.width, height: n.height }\n if (n.type === 'circle') {\n const s = (n.data as { size?: number } | undefined)?.size ?? CIRCLE\n return { width: s, height: s }\n }\n const label = String((n.data as { label?: unknown } | undefined)?.label ?? n.id)\n const lines = label.split('\\n')\n const longest = Math.max(...lines.map((l) => l.length))\n const width = Math.min(288, Math.max(176, 40 + longest * 8))\n const wraps = lines.reduce((sum, l) => sum + Math.max(1, Math.ceil((l.length * 8) / (width - 40))), 0)\n return { width, height: 36 + wraps * 20 }\n}\n\n// Lays out each group's children inside it (deepest first), then each level with the groups at their wrapped size.\n// Positions of children come out relative to their group, as MFlow wants them\nfunction place(nodes: FlowNode[], edges: FlowEdge[], how: 'layered' | 'tree', options: FlowLayoutOptions) {\n const byId = new Map(nodes.map((n) => [n.id, n]))\n const children = new Map<string | undefined, FlowNode[]>()\n for (const n of nodes) {\n const p = n.parentId && byId.has(n.parentId) ? n.parentId : undefined\n if (!children.has(p)) children.set(p, [])\n children.get(p)!.push(n)\n }\n const given = options.sizes instanceof Map ? options.sizes : new Map(Object.entries(options.sizes ?? {}))\n const sizes = new Map<string, { width: number; height: number }>()\n const fn = how === 'tree' ? layoutTree : layoutLayered\n // The ancestor of `id` that sits in the level under `parent`\n const lift = (id: string, parent: string | undefined) => {\n let n = byId.get(id)\n for (let i = 0; n && i < 100; i++) {\n const p = n.parentId && byId.has(n.parentId) ? n.parentId : undefined\n if (p === parent) return n.id\n n = p ? byId.get(p) : undefined\n }\n return undefined\n }\n const level = (parent: string | undefined): { width: number; height: number } => {\n const members = children.get(parent) ?? []\n for (const m of members) {\n if (children.has(m.id)) {\n const inner = level(m.id)\n sizes.set(m.id, { width: Math.max(200, inner.width + GROUP_PAD * 2), height: Math.max(120, inner.height + GROUP_HEAD + GROUP_PAD) })\n } else sizes.set(m.id, given.get(m.id) ?? estimateSize(m))\n }\n const flat = members.map((m) => ({ ...m, parentId: undefined }))\n const lifted: FlowEdge[] = []\n for (const e of edges) {\n const s = lift(e.source, parent)\n const t = lift(e.target, parent)\n if (s && t && s !== t) lifted.push({ ...e, source: s, target: t })\n }\n const pos = fn(flat, lifted, { ...options, sizes })\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity\n for (const m of members) {\n const p = pos[m.id] ?? { x: 0, y: 0 }\n const s = sizes.get(m.id)!\n minX = Math.min(minX, p.x)\n minY = Math.min(minY, p.y)\n maxX = Math.max(maxX, p.x + s.width)\n maxY = Math.max(maxY, p.y + s.height)\n }\n if (!members.length) return { width: 0, height: 0 }\n // Inside a group: from its padding and header; at the top: from 0,0\n const ox = parent === undefined ? -minX : GROUP_PAD - minX\n const oy = parent === undefined ? -minY : GROUP_HEAD - minY\n for (const m of members) {\n const p = pos[m.id] ?? { x: 0, y: 0 }\n m.position = { x: Math.round(p.x + ox), y: Math.round(p.y + oy) }\n }\n return { width: maxX - minX, height: maxY - minY }\n }\n level(undefined)\n}\n\nfunction finish(graph: FlowGraph, opts: FlowImportOptions, positioned: boolean) {\n if (positioned || opts.layout === false) return graph\n place(graph.nodes, graph.edges, opts.layout ?? 'layered', { direction: graph.rankdir, ...opts.layoutOptions })\n return graph\n}\n\nclass FlowSyntaxError extends SyntaxError {\n constructor(message: string, src: string, at: number) {\n const before = src.slice(0, at).split('\\n')\n super(`${message} (line ${before.length}, column ${before.at(-1)!.length + 1})`)\n }\n}\n\n// ── DOT ──────────────────────────────────────────────────────────────────────────────────────────────────\n\ntype Tok = { t: 'id'; v: string; quoted: boolean; html: boolean; at: number } | { t: 'p'; v: string; at: number }\n\nfunction tokenizeDot(src: string): Tok[] {\n const toks: Tok[] = []\n let i = 0\n const n = src.length\n while (i < n) {\n const c = src[i]!\n if (/\\s/.test(c)) { i++; continue }\n if (c === '/' && src[i + 1] === '/') { while (i < n && src[i] !== '\\n') i++; continue }\n if (c === '/' && src[i + 1] === '*') {\n const end = src.indexOf('*/', i + 2)\n i = end < 0 ? n : end + 2\n continue\n }\n // Preprocessor output lines\n if (c === '#' && (i === 0 || src[i - 1] === '\\n')) { while (i < n && src[i] !== '\\n') i++; continue }\n if (c === '-' && (src[i + 1] === '>' || src[i + 1] === '-')) { toks.push({ t: 'p', v: src.slice(i, i + 2), at: i }); i += 2; continue }\n if ('{}[];,=:'.includes(c)) { toks.push({ t: 'p', v: c, at: i }); i++; continue }\n if (c === '\"') {\n const at = i\n let v = ''\n i++\n for (;;) {\n if (i >= n) throw new FlowSyntaxError('Unterminated string', src, at)\n const ch = src[i]!\n if (ch === '\\\\' && src[i + 1] === '\"') { v += '\"'; i += 2; continue }\n if (ch === '\\\\' && src[i + 1] === '\\n') { i += 2; continue }\n if (ch === '\"') { i++; break }\n v += ch\n i++\n }\n // \"a\" + \"b\" concatenates\n const last = toks.at(-1)\n if (last && last.t === 'p' && last.v === '+' && toks.at(-2)?.t === 'id' && (toks.at(-2) as { quoted: boolean }).quoted) {\n toks.pop()\n ;(toks.at(-1) as { v: string }).v += v\n } else toks.push({ t: 'id', v, quoted: true, html: false, at })\n continue\n }\n if (c === '+') { toks.push({ t: 'p', v: '+', at: i }); i++; continue }\n if (c === '<') {\n const at = i\n let depth = 0\n let j = i\n for (; j < n; j++) {\n if (src[j] === '<') depth++\n else if (src[j] === '>' && --depth === 0) break\n }\n if (j >= n) throw new FlowSyntaxError('Unterminated HTML label', src, at)\n toks.push({ t: 'id', v: src.slice(i + 1, j), quoted: true, html: true, at })\n i = j + 1\n continue\n }\n const num = /^-?(?:\\.\\d+|\\d+(?:\\.\\d*)?)/.exec(src.slice(i, i + 40))\n if (num) { toks.push({ t: 'id', v: num[0], quoted: false, html: false, at: i }); i += num[0].length; continue }\n const word = /^[A-Za-z_\\u0080-￿][\\w\\u0080-￿]*/.exec(src.slice(i, i + 4096))\n if (word) { toks.push({ t: 'id', v: word[0], quoted: false, html: false, at: i }); i += word[0].length; continue }\n throw new FlowSyntaxError(`Unexpected \"${c}\"`, src, i)\n }\n return toks\n}\n\nfunction htmlToText(html: string) {\n return html\n .replace(/<br\\s*\\/?>/gi, '\\n')\n .replace(/<[^>]*>/g, '')\n .replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '\"').replace(/&#39;|&apos;/g, \"'\").replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&')\n .trim()\n}\n\n// DOT's escapes in labels: \\N the node's id, \\G the graph's name, \\n \\l \\r line breaks\nfunction dotLabel(v: string, id: string, graph: string) {\n return v\n .replace(/\\\\N/g, id)\n .replace(/\\\\G/g, graph)\n .replace(/\\\\[nlr]/g, '\\n')\n .replace(/\\\\(.)/g, '$1')\n .replace(/\\n$/, '')\n}\n\nfunction dotColor(v: string | undefined) {\n if (!v) return undefined\n // A color list (\"red:blue;0.3\") takes the first; a scheme (\"/x11/red\") is dropped\n const first = v.split(':')[0]!.split(';')[0]!.trim().replace(/^\\/[^/]*\\//, '')\n if (/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(first)) return first.slice(0, 7) + (first.length > 7 ? first.slice(7) : '')\n return /^[a-z]+$/i.test(first) ? first.toLowerCase() : undefined\n}\n\nfunction dotMarkers(attrs: Record<string, string>, directed: boolean): { markerEnd?: FlowMarker; markerStart?: FlowMarker } {\n const dir = attrs.dir ?? (directed ? 'forward' : 'none')\n const head = (a: string | undefined): FlowMarker => (a === 'none' ? 'none' : a && /vee|open|empty|normal-o|o/.test(a) && a !== 'normal' ? 'arrow' : 'arrow-closed')\n const end = dir === 'forward' || dir === 'both' ? head(attrs.arrowhead) : 'none'\n const start = dir === 'back' || dir === 'both' ? head(attrs.arrowtail) : 'none'\n const m: { markerEnd?: FlowMarker; markerStart?: FlowMarker } = {}\n if (end !== 'arrow-closed') m.markerEnd = end\n if (start !== 'none') m.markerStart = start\n return m\n}\n\ninterface DotScope { node: Record<string, string>; edge: Record<string, string>; graph: Record<string, string>; cluster?: string; members: Set<string> }\n\n/**\n * Reads a Graphviz DOT graph (`digraph`/`graph`, `strict`, subgraphs, defaults, ports, HTML labels): nodes take\n * their `label` (default the id), `shape=circle`/`doublecircle`/`point` makes a `circle` node, `style=invis` hides;\n * edges take `label`, `color`, `penwidth`, `style=dashed`/`dotted`/`bold`/`invis` and `dir`/`arrowhead`/`arrowtail`;\n * `cluster` subgraphs become groups. Every attribute as written is kept in each node's and edge's `data.attrs`\n * (ports as `tailport`/`headport`), to map the rest yourself. Laid out in layers along `rankdir`, unless every node\n * has a `pos`. Throws a SyntaxError (with line and column) on what isn't DOT.\n */\nexport function parseDot(source: string, options: FlowImportOptions = {}): FlowGraph {\n const toks = tokenizeDot(source)\n let k = 0\n const peek = (o = 0) => toks[k + o]\n const isP = (v: string, o = 0) => { const t = peek(o); return !!t && t.t === 'p' && t.v === v }\n const isKw = (v: string, o = 0) => { const t = peek(o); return !!t && t.t === 'id' && !t.quoted && t.v.toLowerCase() === v }\n const fail = (msg: string): never => {\n throw new FlowSyntaxError(msg, source, peek()?.at ?? source.length)\n }\n const expect = (v: string) => (isP(v) ? toks[k++] : fail(`Expected \"${v}\"`))\n const id = (): string => {\n const t = peek()\n if (!t || t.t !== 'id') return fail('Expected an id')\n k++\n return t.html ? htmlToText(t.v) : t.v\n }\n\n let strict = false\n if (isKw('strict')) { strict = true; k++ }\n let directed: boolean\n if (isKw('digraph')) directed = true\n else if (isKw('graph')) directed = false\n else return fail('Expected \"graph\" or \"digraph\"')\n k++\n const name = peek()?.t === 'id' ? id() : undefined\n\n const nodes: FlowNode[] = []\n const nodeAttrs = new Map<string, Record<string, string>>()\n const nodeScope = new Map<string, string | undefined>()\n const edges: FlowEdge[] = []\n const groupLabels = new Map<string, Record<string, string>>()\n const edgeKeys = new Set<string>()\n let anon = 0\n\n const attrList = () => {\n const a: Record<string, string> = {}\n while (isP('[')) {\n k++\n while (!isP(']')) {\n if (!peek()) fail('Expected \"]\"')\n const key = id()\n if (isP('=')) { k++; a[key] = id() } else a[key] = 'true'\n if (isP(';') || isP(',')) k++\n }\n k++\n }\n return a\n }\n const touchNode = (nid: string, scope: DotScope, attrs?: Record<string, string>) => {\n for (let s: DotScope | undefined = scope; s; s = parents.get(s)) s.members.add(nid)\n if (!nodeAttrs.has(nid)) {\n nodeAttrs.set(nid, { ...scope.node })\n nodeScope.set(nid, scope.cluster)\n nodes.push({ id: nid, position: { x: 0, y: 0 } })\n }\n if (attrs) Object.assign(nodeAttrs.get(nid)!, attrs)\n }\n const parents = new Map<DotScope, DotScope | undefined>()\n\n type Operand = { ids: string[]; port?: string }\n const operand = (scope: DotScope): Operand => {\n if (isKw('subgraph') || isP('{')) return { ids: [...subgraph(scope).members] }\n const nid = id()\n let port: string | undefined\n if (isP(':')) {\n k++\n port = id()\n if (isP(':')) { k++; port += ':' + id() }\n }\n touchNode(nid, scope)\n return { ids: [nid], port }\n }\n const subgraph = (outer: DotScope): DotScope => {\n let sname: string | undefined\n if (isKw('subgraph')) {\n k++\n if (peek()?.t === 'id') sname = id()\n }\n const scope: DotScope = { node: { ...outer.node }, edge: { ...outer.edge }, graph: {}, cluster: outer.cluster, members: new Set() }\n parents.set(scope, outer)\n if (sname && /^cluster/i.test(sname)) {\n let gid = sname\n while (nodeAttrs.has(gid) || groupLabels.has(gid)) gid = `${sname}_${++anon}`\n groupLabels.set(gid, scope.graph)\n nodes.push({ id: gid, type: 'group', position: { x: 0, y: 0 }, ...(outer.cluster ? { parentId: outer.cluster } : {}) })\n scope.cluster = gid\n }\n expect('{')\n stmts(scope)\n expect('}')\n return scope\n }\n const stmts = (scope: DotScope) => {\n while (peek() && !isP('}')) {\n stmt(scope)\n if (isP(';') || isP(',')) k++\n }\n }\n const stmt = (scope: DotScope) => {\n if ((isKw('graph') || isKw('node') || isKw('edge')) && isP('[', 1)) {\n const which = (peek() as { v: string }).v.toLowerCase() as 'graph' | 'node' | 'edge'\n k++\n Object.assign(scope[which], attrList())\n return\n }\n if (peek()?.t === 'id' && !isKw('subgraph') && isP('=', 1)) {\n const key = id()\n k++\n scope.graph[key] = id()\n return\n }\n const first = operand(scope)\n if (!isP('->') && !isP('--')) {\n if (isP('[')) {\n const a = attrList()\n for (const nid of first.ids) touchNode(nid, scope, a)\n }\n return\n }\n const chain: Operand[] = [first]\n while (isP('->') || isP('--')) {\n k++\n chain.push(operand(scope))\n }\n const a = { ...scope.edge, ...attrList() }\n for (let c = 0; c < chain.length - 1; c++) {\n const from = chain[c]!\n const to = chain[c + 1]!\n for (const s of from.ids) {\n for (const t of to.ids) {\n const key = directed ? `${s}\\u0000${t}` : [s, t].sort().join('\\u0000')\n if (strict && edgeKeys.has(key)) continue\n edgeKeys.add(key)\n const attrs = { ...a }\n if (from.port) attrs.tailport = from.port\n if (to.port) attrs.headport = to.port\n edges.push(dotEdge(s, t, attrs, edges.length, directed, options))\n }\n }\n }\n }\n\n const root: DotScope = { node: {}, edge: {}, graph: {}, members: new Set() }\n expect('{')\n stmts(root)\n expect('}')\n if (peek()) fail('Unexpected text after the graph')\n\n // Ids given with `id=` must stay unique\n const seen = new Set<string>()\n for (const e of edges) {\n while (seen.has(e.id)) e.id = `${e.id}_`\n seen.add(e.id)\n }\n\n let positioned = nodes.some((n) => n.type !== 'group')\n for (const n of nodes) {\n if (n.type === 'group') {\n const g = groupLabels.get(n.id)!\n n.data = { label: g.label !== undefined ? dotLabel(g.label, n.id, name ?? '') : undefined, attrs: { ...g } }\n continue\n }\n const attrs = nodeAttrs.get(n.id)!\n const parent = nodeScope.get(n.id)\n if (parent) n.parentId = parent\n const label = attrs.label !== undefined ? dotLabel(attrs.label, n.id, name ?? '') : n.id\n const shape = attrs.shape?.toLowerCase()\n if (shape === 'circle' || shape === 'doublecircle' || shape === 'point' || shape === 'mcircle') {\n n.type = 'circle'\n n.data = { label: shape === 'point' ? '' : label, ...(shape === 'doublecircle' ? { ring: 'primary' } : {}), attrs }\n if (shape === 'point') n.data.size = 16\n } else {\n if (options.nodeType) n.type = options.nodeType\n n.data = { label, attrs }\n }\n if (/\\binvis\\b/.test(attrs.style ?? '')) n.hidden = true\n const pos = /^\\s*(-?[\\d.]+)\\s*,\\s*(-?[\\d.]+)/.exec(attrs.pos ?? '')\n if (pos) {\n // Points, y up, the node's center\n const s = estimateSize(n)\n n.position = { x: (Number(pos[1]) * 4) / 3 - s.width / 2, y: (-Number(pos[2]) * 4) / 3 - s.height / 2 }\n } else positioned = false\n }\n if (positioned) {\n // Children's `pos` are absolute: make them relative to their group, and the whole from 0,0\n const top = nodes.filter((n) => n.type !== 'group')\n const minX = Math.min(...top.map((n) => n.position.x))\n const minY = Math.min(...top.map((n) => n.position.y))\n for (const n of top) n.position = { x: Math.round(n.position.x - minX), y: Math.round(n.position.y - minY) }\n if (nodes.some((n) => n.type === 'group')) place(nodes.filter((n) => n.type === 'group' || n.parentId), [], 'layered', {})\n }\n\n const rd = (root.graph.rankdir ?? '').toUpperCase()\n const rankdir: FlowLayoutDirection = rd === 'LR' || rd === 'RL' || rd === 'BT' ? rd : 'TB'\n const graph: FlowGraph = {\n nodes,\n edges,\n rankdir,\n direction: asDirection(rankdir),\n directed,\n attrs: { ...root.graph },\n ...(name !== undefined ? { name } : {}),\n ...(root.graph.label !== undefined ? { label: dotLabel(root.graph.label, '', name ?? '') } : {}),\n }\n return finish(graph, options, positioned && !nodes.some((n) => n.type === 'group'))\n}\n\nfunction dotEdge(source: string, target: string, attrs: Record<string, string>, index: number, directed: boolean, options: FlowImportOptions): FlowEdge {\n const e: FlowEdge = { id: attrs.id ?? `e${index + 1}`, source, target }\n if (options.edgeType) e.type = options.edgeType\n if (attrs.label !== undefined) e.label = dotLabel(attrs.label, '', '')\n const style = attrs.style ?? ''\n if (/\\b(dashed|dotted)\\b/.test(style)) e.dashed = true\n if (/\\binvis\\b/.test(style)) e.hidden = true\n const color = dotColor(attrs.color)\n if (color) e.color = color\n if (attrs.penwidth && Number(attrs.penwidth) > 0) e.width = Number(attrs.penwidth) * 2\n else if (/\\bbold\\b/.test(style)) e.width = 4\n Object.assign(e, dotMarkers(attrs, directed))\n e.data = { attrs }\n return e\n}\n\nconst DOT_KEYWORDS = new Set(['strict', 'graph', 'digraph', 'node', 'edge', 'subgraph'])\nfunction dotId(v: string) {\n if (/^[A-Za-z_][\\w]*$/.test(v) && !DOT_KEYWORDS.has(v.toLowerCase())) return v\n if (/^-?(?:\\.\\d+|\\d+(?:\\.\\d*)?)$/.test(v)) return v\n return `\"${v.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"').replace(/\\n/g, '\\\\n')}\"`\n}\nfunction dotAttrs(a: Record<string, string>) {\n const parts = Object.entries(a).map(([key, v]) => `${dotId(key)}=${dotId(v)}`)\n return parts.length ? ` [${parts.join(', ')}]` : ''\n}\n// What's kept from an imported `data.attrs`: the rest is written from the node's or edge's current state\nconst DOT_NODE_OWN = new Set(['label', 'pos', 'shape', 'style'])\nconst DOT_EDGE_OWN = new Set(['label', 'color', 'penwidth', 'style', 'dir', 'arrowhead', 'arrowtail', 'id', 'tailport', 'headport'])\nfunction keptAttrs(data: unknown, own: Set<string>) {\n const a = (data as { attrs?: unknown } | undefined)?.attrs\n const out: Record<string, string> = {}\n if (a && typeof a === 'object') for (const [key, v] of Object.entries(a)) if (!own.has(key) && typeof v === 'string') out[key] = v\n return out\n}\nfunction labelOf(n: { id: string; data?: unknown }) {\n const l = (n.data as { label?: unknown } | undefined)?.label\n return l === undefined || l === null ? undefined : String(l)\n}\nfunction absolute(nodes: FlowNode[]) {\n const byId = new Map(nodes.map((n) => [n.id, n]))\n const memo = new Map<string, FlowXY>()\n const at = (n: FlowNode, depth = 0): FlowXY => {\n if (memo.has(n.id)) return memo.get(n.id)!\n const p = n.parentId && byId.has(n.parentId) && depth < 100 ? at(byId.get(n.parentId)!, depth + 1) : { x: 0, y: 0 }\n const r = { x: p.x + n.position.x, y: p.y + n.position.y }\n memo.set(n.id, r)\n return r\n }\n return at\n}\n// Groups first, children inside them, depth first\nfunction tree(nodes: FlowNode[]) {\n const ids = new Set(nodes.map((n) => n.id))\n const kids = new Map<string | undefined, FlowNode[]>()\n for (const n of nodes) {\n const p = n.parentId && ids.has(n.parentId) ? n.parentId : undefined\n if (!kids.has(p)) kids.set(p, [])\n kids.get(p)!.push(n)\n }\n return kids\n}\n\n/**\n * Writes nodes and edges as a Graphviz DOT graph: labels, `circle` nodes as `shape=circle` (`doublecircle` with a\n * ring), groups as `cluster` subgraphs, edge labels, colors (CSS ones; M3 roles are left out), widths, dashes,\n * arrows and hidden ones. Attributes kept in `data.attrs` (as `parseDot` leaves them) are written back too.\n */\nexport function toDot(nodes: FlowNode[], edges: FlowEdge[], options: FlowDotExportOptions = {}): string {\n const directed = options.directed ?? true\n const out: string[] = [`${directed ? 'digraph' : 'graph'}${options.name ? ` ${dotId(options.name)}` : ''} {`]\n const rankdir = toRankdir(options.direction)\n if (rankdir !== 'TB') out.push(` rankdir=${rankdir};`)\n const kids = tree(nodes)\n const at = absolute(nodes)\n const given = options.sizes instanceof Map ? options.sizes : new Map(Object.entries(options.sizes ?? {}))\n const write = (parent: string | undefined, indent: string) => {\n for (const n of kids.get(parent) ?? []) {\n const label = labelOf(n)\n if (n.type === 'group') {\n const gid = /^cluster/i.test(n.id) ? n.id : `cluster_${n.id}`\n out.push(`${indent}subgraph ${dotId(gid)} {`)\n const ga = keptAttrs(n.data, DOT_NODE_OWN)\n if (label) ga.label = label\n for (const [key, v] of Object.entries(ga)) out.push(`${indent} ${dotId(key)}=${dotId(v)};`)\n write(n.id, indent + ' ')\n out.push(`${indent}}`)\n continue\n }\n const a = keptAttrs(n.data, DOT_NODE_OWN)\n if (label !== undefined && label !== n.id) a.label = label\n if (n.type === 'circle') a.shape = (n.data as { ring?: unknown } | undefined)?.ring ? 'doublecircle' : 'circle'\n else if ((n.data as { attrs?: { shape?: string } } | undefined)?.attrs?.shape) a.shape = (n.data as { attrs: { shape: string } }).attrs.shape\n if (n.hidden) a.style = 'invis'\n if (options.positions) {\n const p = at(n)\n const s = given.get(n.id) ?? estimateSize(n)\n a.pos = `${round((p.x + s.width / 2) * 0.75)},${round(-(p.y + s.height / 2) * 0.75)}`\n }\n out.push(`${indent}${dotId(n.id)}${dotAttrs(a)};`)\n }\n }\n write(undefined, ' ')\n const op = directed ? '->' : '--'\n for (const e of edges) {\n const a = keptAttrs(e.data, DOT_EDGE_OWN)\n if (e.label) a.label = e.label\n if (e.color && !ROLES.has(e.color) && !e.color.startsWith('var(')) a.color = e.color\n if (e.width && e.width !== 2) a.penwidth = String(round(e.width / 2))\n const style = [e.dashed ? 'dashed' : '', e.hidden ? 'invis' : ''].filter(Boolean).join(',')\n if (style) a.style = style\n const end = e.markerEnd ?? 'arrow-closed'\n const start = e.markerStart ?? 'none'\n if (directed) {\n if (end === 'none' && start === 'none') a.dir = 'none'\n else if (end === 'none') a.dir = 'back'\n else if (start !== 'none') a.dir = 'both'\n if (end === 'arrow') a.arrowhead = 'vee'\n if (start === 'arrow') a.arrowtail = 'vee'\n }\n const tail = (e.data as { attrs?: { tailport?: string } } | undefined)?.attrs?.tailport\n const head = (e.data as { attrs?: { headport?: string } } | undefined)?.attrs?.headport\n const port = (p?: string) => (p ? ':' + p.split(':').map(dotId).join(':') : '')\n out.push(` ${dotId(e.source)}${port(tail)} ${op} ${dotId(e.target)}${port(head)}${dotAttrs(a)};`)\n }\n out.push('}')\n return out.join('\\n') + '\\n'\n}\n\nfunction round(v: number) {\n return Math.round(v * 100) / 100\n}\n\n// ── Mermaid ──────────────────────────────────────────────────────────────────────────────────────────────\n\n// Node shapes, longest delimiters first\nconst SHAPES: { open: string; close: string; shape: string }[] = [\n { open: '(((', close: ')))', shape: 'doublecircle' },\n { open: '((', close: '))', shape: 'circle' },\n { open: '([', close: '])', shape: 'stadium' },\n { open: '[[', close: ']]', shape: 'subroutine' },\n { open: '[(', close: ')]', shape: 'cylinder' },\n { open: '{{', close: '}}', shape: 'hexagon' },\n { open: '[/', close: '/]', shape: 'lean-right' },\n { open: '[\\\\', close: '\\\\]', shape: 'lean-left' },\n { open: '[/', close: '\\\\]', shape: 'trapezoid' },\n { open: '[\\\\', close: '/]', shape: 'inv-trapezoid' },\n { open: '>', close: ']', shape: 'odd' },\n { open: '(', close: ')', shape: 'rounded' },\n { open: '[', close: ']', shape: 'rect' },\n { open: '{', close: '}', shape: 'diamond' },\n]\nconst MERMAID_SKIP = /^(classDef|class|style|linkStyle|click|accTitle|accDescr|direction)\\b/\nconst MERMAID_RESERVED = new Set(['end', 'graph', 'flowchart', 'subgraph', 'style', 'class', 'classdef', 'linkstyle', 'click', 'direction'])\n\nfunction mermaidText(v: string) {\n let t = v.trim()\n if (t.startsWith('\"') && t.endsWith('\"') && t.length > 1) t = t.slice(1, -1)\n // Markdown strings (\"`**bold**`\")\n if (t.startsWith('`') && t.endsWith('`') && t.length > 1) t = t.slice(1, -1).replace(/\\*\\*|__|\\*|_/g, '')\n return t\n .replace(/<br\\s*\\/?>/gi, '\\n')\n .replace(/#quot;/g, '\"')\n .replace(/#(\\d+);/g, (_, d) => String.fromCodePoint(Number(d)))\n .replace(/#([a-z]+);/gi, (m, name) => ({ amp: '&', lt: '<', gt: '>', nbsp: ' ', apos: \"'\" })[name.toLowerCase() as 'amp'] ?? m)\n}\n\n// Splits on newlines and on `;` outside quotes and brackets\nfunction mermaidStatements(src: string): { text: string; at: number }[] {\n const out: { text: string; at: number }[] = []\n let depth = 0\n let quote = false\n let start = 0\n for (let i = 0; i <= src.length; i++) {\n const c = src[i]\n if (c === '\"') quote = !quote\n else if (!quote && (c === '[' || c === '(' || c === '{')) depth++\n else if (!quote && (c === ']' || c === ')' || c === '}')) depth = Math.max(0, depth - 1)\n if (c === undefined || c === '\\n' || (c === ';' && !quote && depth === 0)) {\n const raw = src.slice(start, i)\n const lead = raw.length - raw.trimStart().length\n const text = raw.trim()\n if (text && !text.startsWith('%%')) out.push({ text, at: start + lead })\n if (c === '\\n') { quote = false; depth = 0 }\n start = i + 1\n }\n }\n return out\n}\n\ninterface MermaidLink { line: 'solid' | 'dotted' | 'thick' | 'invisible'; start: string; end: string; label?: string; raw: string }\n\n/**\n * Reads a Mermaid flowchart (`flowchart`/`graph` with TB/TD/BT/LR/RL): node shapes (`(( ))` makes a `circle` node,\n * `((( )))` one with a ring; every other shape is kept as `data.shape`), the `@{ shape, label }` syntax, chains and\n * `&`, links `-->` `---` `-.->` `==>` `~~~` `<-->` `--o` `--x` with `|labels|` or `-- labels -->`, and subgraphs as\n * groups. `classDef`, `style`, `click` and the like are skipped. Laid out in layers along its direction. Throws a\n * SyntaxError (with line and column) on what it can't read.\n */\nexport function parseMermaid(source: string, options: FlowImportOptions = {}): FlowGraph {\n const stmts = mermaidStatements(source.replace(/^\\s*---\\n[\\s\\S]*?\\n---\\s*\\n/, (m) => '\\n'.repeat(m.split('\\n').length - 1)))\n const head = stmts.shift()\n const hm = head && /^(flowchart|graph)(?:\\s+(TB|TD|BT|RL|LR))?\\s*(.*)$/i.exec(head.text)\n if (!head || !hm) throw new FlowSyntaxError('Expected \"flowchart\" or \"graph\"', source, head?.at ?? 0)\n const d = (hm[2] ?? 'TB').toUpperCase()\n const rankdir: FlowLayoutDirection = d === 'TD' ? 'TB' : (d as FlowLayoutDirection)\n // `graph TD; A-->B` on one line\n if (hm[3]) stmts.unshift({ text: hm[3], at: head.at + head.text.length - hm[3].length })\n\n const nodes: FlowNode[] = []\n const byId = new Map<string, FlowNode>()\n const edges: FlowEdge[] = []\n const groups: string[] = []\n\n const touch = (id: string, label?: string, shape?: string) => {\n let n = byId.get(id)\n if (!n) {\n n = { id, position: { x: 0, y: 0 }, data: { label: id } }\n if (groups.length) n.parentId = groups.at(-1)\n if (options.nodeType) n.type = options.nodeType\n byId.set(id, n)\n nodes.push(n)\n } else if (groups.length && !n.parentId && n.id !== groups.at(-1)) {\n // Named again inside a subgraph, a node from outside any moves into it, as in Mermaid\n n.parentId = groups.at(-1)\n }\n if (n.type === 'group') return n\n if (label !== undefined) n.data.label = label\n if (shape) {\n n.data.shape = shape\n if (shape === 'circle' || shape === 'doublecircle' || shape === 'sm-circ' || shape === 'dbl-circ') {\n n.type = 'circle'\n if (shape === 'doublecircle' || shape === 'dbl-circ') n.data.ring = 'primary'\n } else if (n.type === 'circle') n.type = options.nodeType\n }\n return n\n }\n\n for (const { text, at } of stmts) {\n const fail = (msg: string, off = 0): never => {\n throw new FlowSyntaxError(msg, source, at + off)\n }\n if (/^end$/i.test(text)) {\n if (!groups.length) fail('\"end\" without a subgraph')\n groups.pop()\n continue\n }\n const sg = /^subgraph\\s+(.+)$/i.exec(text)\n if (sg) {\n const rest = sg[1]!.trim()\n const m = /^([\\w-]+)\\s*\\[(.*)\\]$/.exec(rest)\n const gid = m ? m[1]! : /^[\\w-]+$/.test(rest) ? rest : rest.replace(/^\"|\"$/g, '')\n const label = m ? mermaidText(m[2]!) : mermaidText(rest)\n const g: FlowNode = byId.get(gid) ?? { id: gid, position: { x: 0, y: 0 } }\n g.type = 'group'\n g.data = { label }\n if (groups.length) g.parentId = groups.at(-1)\n else delete g.parentId\n if (!byId.has(gid)) { byId.set(gid, g); nodes.push(g) }\n groups.push(gid)\n continue\n }\n if (MERMAID_SKIP.test(text)) continue\n\n let i = 0\n const ws = () => { while (i < text.length && /\\s/.test(text[i]!)) i++ }\n const nodeRef = (): string => {\n ws()\n const m = /^[\\w$À-￿](?:[\\w$.À-￿]|-(?=[\\wÀ-￿]))*/.exec(text.slice(i))\n if (!m) return fail(`Expected a node at \"${text.slice(i, i + 12)}\"`, i)\n const id = m[0]\n i += id.length\n let label: string | undefined\n let shape: string | undefined\n if (text.startsWith('@{', i)) {\n const end = text.indexOf('}', i)\n if (end < 0) fail('Unclosed \"@{\"', i)\n const body = text.slice(i + 2, end)\n const sm = /\\bshape\\s*:\\s*([\\w-]+)/.exec(body)\n const lm = /\\blabel\\s*:\\s*(\"(?:[^\"\\\\]|\\\\.)*\"|[^,}]+)/.exec(body)\n if (sm) shape = sm[1]!.toLowerCase()\n if (lm) label = mermaidText(lm[1]!)\n i = end + 1\n } else {\n for (const s of SHAPES) {\n if (!text.startsWith(s.open, i)) continue\n const from = i + s.open.length\n const inner = text[from] === '\"' ? text.indexOf('\"', from + 1) + 1 : from\n const end = text.indexOf(s.close, inner)\n if (inner === 0 || end < 0) continue\n label = mermaidText(text.slice(from, end))\n shape = s.shape\n i = end + s.close.length\n break\n }\n }\n // `:::className`\n const cls = /^:::[\\w-]+/.exec(text.slice(i))\n if (cls) i += cls[0].length\n touch(id, label, shape)\n return id\n }\n const group = () => {\n const ids = [nodeRef()]\n for (;;) {\n ws()\n if (text[i] !== '&') return ids\n i++\n ids.push(nodeRef())\n }\n }\n const link = (): MermaidLink | null => {\n ws()\n const rest = text.slice(i)\n // `-- text -->`, `== text ==>`, `-. text .->`\n const inline = /^(<|o|x)?(--|==|-\\.)(?![-.>=|~])(?![ox](?:\\s|$))\\s*(.+?)\\s*(-{2,}[->ox]|={2,}[=>ox]|\\.+-[>ox]?|-\\.+-[>ox]?)(?=\\s|[\\w\"]|$)/.exec(rest)\n const plain = /^(<|o(?=[-=.])|x(?=[-=.]))?(~{3,}|-\\.+-|-{2,}|={2,})(>|o(?![\\w])|x(?![\\w]))?/.exec(rest)\n let m: MermaidLink\n // `-- text -->` starts with exactly two dashes (or `==`, `-.`) and text: `--- B`, `--x B` and `-->|x| B` are plain\n if (inline) {\n const startsDot = inline[2] === '-.'\n const end = inline[4]!\n const arrow = /[>ox]$/.test(end) && !/^-+-$|^=+=$/.test(end) ? end.slice(-1) : ''\n m = { line: startsDot ? 'dotted' : inline[2] === '==' ? 'thick' : 'solid', start: inline[1] ?? '', end: arrow === '-' || arrow === '=' ? '' : arrow, label: mermaidText(inline[3]!), raw: inline[0] }\n i += inline[0].length\n } else if (plain) {\n const body = plain[2]!\n m = { line: body.startsWith('~') ? 'invisible' : body.includes('.') ? 'dotted' : body.startsWith('=') ? 'thick' : 'solid', start: plain[1] ?? '', end: plain[3] ?? '', raw: plain[0] }\n i += plain[0].length\n ws()\n if (text[i] === '|') {\n const end = text.indexOf('|', i + 1)\n if (end < 0) fail('Unclosed \"|\"', i)\n m.label = mermaidText(text.slice(i + 1, end))\n i = end + 1\n }\n } else return null\n return m\n }\n\n let from = group()\n for (;;) {\n ws()\n if (i >= text.length) break\n const l = link()\n if (!l) fail(`Unexpected \"${text.slice(i, i + 12)}\"`, i)\n const to = group()\n for (const s of from) for (const t of to) edges.push(mermaidEdge(s, t, l!, edges.length, options))\n from = to\n }\n }\n if (groups.length) throw new FlowSyntaxError(`Subgraph \"${groups.at(-1)}\" has no \"end\"`, source, source.length)\n\n // Parents before children\n const ordered: FlowNode[] = []\n const kids = tree(nodes)\n const walk = (p: string | undefined) => {\n for (const n of kids.get(p) ?? []) {\n ordered.push(n)\n walk(n.id)\n }\n }\n walk(undefined)\n const graph: FlowGraph = { nodes: ordered, edges, rankdir, direction: asDirection(rankdir), directed: true, attrs: {} }\n return finish(graph, options, false)\n}\n\nfunction mermaidMarker(c: string): FlowMarker {\n return c === '>' || c === '<' ? 'arrow-closed' : c === 'o' || c === 'x' ? 'arrow' : 'none'\n}\nfunction mermaidEdge(source: string, target: string, l: MermaidLink, index: number, options: FlowImportOptions): FlowEdge {\n const e: FlowEdge = { id: `e${index + 1}`, source, target }\n if (options.edgeType) e.type = options.edgeType\n if (l.label) e.label = l.label\n if (l.line === 'dotted') e.dashed = true\n if (l.line === 'thick') e.width = 4\n if (l.line === 'invisible') e.hidden = true\n const end = mermaidMarker(l.end)\n if (end !== 'arrow-closed') e.markerEnd = end\n if (l.start) e.markerStart = mermaidMarker(l.start)\n e.data = { link: l.raw.replace(/\\s+/g, ' ') }\n return e\n}\n\nfunction mermaidQuote(v: string) {\n return `\"${v.replace(/\"/g, '#quot;').replace(/\\n/g, '<br>')}\"`\n}\nconst MERMAID_OPEN = new Map(SHAPES.map((s) => [s.shape, s]))\n\n/**\n * Writes nodes and edges as a Mermaid flowchart: labels, `circle` nodes as `(( ))` (`((( )))` with a ring), the\n * shape kept in `data.shape` (as `parseMermaid` leaves it), groups as subgraphs, and edges as `-->`, `---` (no\n * arrow), `-.->` (dashed), `==>` (3px or wider), `~~~` (hidden) or `<-->`, with their labels. Ids Mermaid can't take\n * are renamed (`n1`, `n2`…).\n */\nexport function toMermaid(nodes: FlowNode[], edges: FlowEdge[], options: FlowExportOptions = {}): string {\n const out = [`flowchart ${toRankdir(options.direction)}`]\n const names = new Map<string, string>()\n let next = 0\n const used = new Set<string>()\n for (const n of nodes) {\n const ok = /^[A-Za-z_][\\w-]*$/.test(n.id) && !n.id.endsWith('-') && !MERMAID_RESERVED.has(n.id.toLowerCase())\n let name = ok ? n.id : ''\n while (!name || used.has(name)) name = `n${++next}`\n used.add(name)\n names.set(n.id, name)\n }\n const kids = tree(nodes)\n const write = (parent: string | undefined, indent: string) => {\n for (const n of kids.get(parent) ?? []) {\n const name = names.get(n.id)!\n const label = labelOf(n)\n if (n.type === 'group') {\n out.push(`${indent}subgraph ${name}[${mermaidQuote(label ?? n.id)}]`)\n write(n.id, indent + ' ')\n out.push(`${indent}end`)\n continue\n }\n const data = (n.data ?? {}) as { shape?: string; ring?: unknown }\n const shape = n.type === 'circle' ? (data.ring ? 'doublecircle' : 'circle') : data.shape && MERMAID_OPEN.has(data.shape) ? data.shape : label !== undefined && label !== n.id ? 'rect' : ''\n const s = shape ? MERMAID_OPEN.get(shape) : undefined\n out.push(`${indent}${name}${s ? `${s.open}${mermaidQuote(label ?? n.id)}${s.close}` : ''}`)\n }\n }\n write(undefined, ' ')\n for (const e of edges) {\n const s = names.get(e.source) ?? e.source\n const t = names.get(e.target) ?? e.target\n const end = e.markerEnd ?? 'arrow-closed'\n const start = e.markerStart ?? 'none'\n let l: string\n if (e.hidden) l = '~~~'\n else {\n const head = end !== 'none'\n const tail = start === 'none' ? '' : '<'\n if (e.dashed) l = `${tail}-.${head ? '->' : '-'}`\n else if ((e.width ?? 2) >= 3) l = `${tail}==${head ? '>' : '='}`\n else l = `${tail}--${head ? '>' : '-'}`\n }\n out.push(` ${s} ${l}${e.label && !e.hidden ? `|${mermaidQuote(e.label)}|` : ''} ${t}`)\n }\n return out.join('\\n') + '\\n'\n}\n"],"mappings":";;;;;AAiOA,IAAa,KAAwC,OAAO,SAAS,GASxD,KAA6C,OAAO,cAAc;AAM/E,SAAgB,KAAuB;CACrC,IAAM,IAAM,EAAO,IAAU,IAAI;CACjC,IAAI,CAAC,GAAK,MAAU,MAAM,yCAAyC;CACnE,OAAO;AACT;AAGA,SAAgB,IAAc;CAC5B,OAAO,EAAO,IAAe,IA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