@excalidraw/element 0.18.0-d2463f87d → 0.18.0-d9e8a33

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 (277) hide show
  1. package/dist/dev/index.js +6064 -3063
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +19 -18
  4. package/dist/types/common/debug.d.ts +21 -0
  5. package/dist/types/common/src/appEventBus.d.ts +27 -0
  6. package/dist/types/common/src/bounds.d.ts +10 -0
  7. package/dist/types/common/src/colors.d.ts +59 -39
  8. package/dist/types/common/src/constants.d.ts +38 -26
  9. package/dist/types/common/src/editorInterface.d.ts +34 -0
  10. package/dist/types/common/src/font-metadata.d.ts +1 -3
  11. package/dist/types/common/src/index.d.ts +5 -0
  12. package/dist/types/common/src/keys.d.ts +1 -1
  13. package/dist/types/common/src/utility-types.d.ts +0 -1
  14. package/dist/types/common/src/utils.d.ts +53 -41
  15. package/dist/types/common/src/versionedSnapshotStore.d.ts +17 -0
  16. package/dist/types/element/src/Scene.d.ts +11 -5
  17. package/dist/types/element/src/align.d.ts +2 -1
  18. package/dist/types/element/src/arrowheads.d.ts +3 -0
  19. package/dist/types/element/src/arrows/focus.d.ts +27 -0
  20. package/dist/types/element/src/arrows/helpers.d.ts +5 -0
  21. package/dist/types/element/src/binding.d.ts +67 -48
  22. package/dist/types/element/src/bounds.d.ts +8 -14
  23. package/dist/types/element/src/collision.d.ts +7 -2
  24. package/dist/types/element/src/comparisons.d.ts +7 -7
  25. package/dist/types/element/src/delta.d.ts +16 -4
  26. package/dist/types/element/src/distribute.d.ts +3 -1
  27. package/dist/types/element/src/dragElements.d.ts +3 -3
  28. package/dist/types/element/src/duplicate.d.ts +3 -3
  29. package/dist/types/element/src/elbowArrow.d.ts +2 -0
  30. package/dist/types/element/src/fractionalIndex.d.ts +2 -2
  31. package/dist/types/element/src/frame.d.ts +6 -2
  32. package/dist/types/element/src/groups.d.ts +1 -0
  33. package/dist/types/element/src/heading.d.ts +2 -1
  34. package/dist/types/element/src/image.d.ts +1 -11
  35. package/dist/types/element/src/index.d.ts +5 -3
  36. package/dist/types/element/src/linearElementEditor.d.ts +25 -23
  37. package/dist/types/element/src/mutateElement.d.ts +5 -1
  38. package/dist/types/element/src/newElement.d.ts +6 -6
  39. package/dist/types/element/src/positionElementsOnGrid.d.ts +2 -0
  40. package/dist/types/element/src/renderElement.d.ts +4 -7
  41. package/dist/types/element/src/resizeElements.d.ts +10 -10
  42. package/dist/types/element/src/resizeTest.d.ts +6 -5
  43. package/dist/types/element/src/selection.d.ts +10 -10
  44. package/dist/types/element/src/shape.d.ts +9 -8
  45. package/dist/types/element/src/store.d.ts +8 -2
  46. package/dist/types/element/src/textElement.d.ts +2 -2
  47. package/dist/types/element/src/textMeasurements.d.ts +1 -3
  48. package/dist/types/element/src/textWrapping.d.ts +26 -0
  49. package/dist/types/{excalidraw/data → element/src}/transform.d.ts +3 -3
  50. package/dist/types/element/src/transformHandles.d.ts +8 -27
  51. package/dist/types/element/src/typeChecks.d.ts +4 -7
  52. package/dist/types/element/src/types.d.ts +12 -13
  53. package/dist/types/element/src/utils.d.ts +9 -4
  54. package/dist/types/element/src/visualdebug.d.ts +59 -0
  55. package/dist/types/element/src/zindex.d.ts +7 -1
  56. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +131 -171
  57. package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -7
  58. package/dist/types/excalidraw/actions/actionBoundText.d.ts +94 -121
  59. package/dist/types/excalidraw/actions/actionCanvas.d.ts +557 -902
  60. package/dist/types/excalidraw/actions/actionClipboard.d.ts +111 -882
  61. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +45 -59
  62. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +154 -198
  63. package/dist/types/excalidraw/actions/actionDeselect.d.ts +160 -0
  64. package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -3
  65. package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -3
  66. package/dist/types/excalidraw/actions/actionElementLink.d.ts +37 -57
  67. package/dist/types/excalidraw/actions/actionElementLock.d.ts +92 -119
  68. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +46 -60
  69. package/dist/types/excalidraw/actions/actionExport.d.ts +173 -1412
  70. package/dist/types/excalidraw/actions/actionFinalize.d.ts +10 -395
  71. package/dist/types/excalidraw/actions/actionFlip.d.ts +2 -3
  72. package/dist/types/excalidraw/actions/actionFrame.d.ts +279 -370
  73. package/dist/types/excalidraw/actions/actionGroup.d.ts +97 -132
  74. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +176 -197
  75. package/dist/types/excalidraw/actions/actionLink.d.ts +43 -57
  76. package/dist/types/excalidraw/actions/actionMenu.d.ts +36 -424
  77. package/dist/types/excalidraw/actions/actionNavigate.d.ts +18 -361
  78. package/dist/types/excalidraw/actions/actionProperties.d.ts +152 -2522
  79. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +48 -66
  80. package/dist/types/excalidraw/actions/actionStyles.d.ts +45 -58
  81. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
  82. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +173 -0
  83. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +45 -59
  84. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +173 -0
  85. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +45 -59
  86. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +34 -54
  87. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
  88. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +45 -59
  89. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +45 -59
  90. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +46 -60
  91. package/dist/types/excalidraw/actions/actionZindex.d.ts +2 -3
  92. package/dist/types/excalidraw/actions/index.d.ts +5 -2
  93. package/dist/types/excalidraw/actions/register.d.ts +2 -2
  94. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  95. package/dist/types/excalidraw/actions/types.d.ts +4 -4
  96. package/dist/types/excalidraw/appState.d.ts +22 -14
  97. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
  98. package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
  99. package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
  100. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
  101. package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
  102. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
  103. package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
  104. package/dist/types/excalidraw/charts/index.d.ts +7 -0
  105. package/dist/types/excalidraw/clipboard.d.ts +57 -19
  106. package/dist/types/excalidraw/components/Actions.d.ts +21 -8
  107. package/dist/types/excalidraw/components/App.d.ts +118 -75
  108. package/dist/types/excalidraw/components/AppStateObserver.d.ts +37 -0
  109. package/dist/types/excalidraw/components/Card.d.ts +1 -3
  110. package/dist/types/excalidraw/components/ColorPicker/ColorInput.d.ts +2 -4
  111. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +0 -1
  112. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -0
  113. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -1
  114. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -1
  115. package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +0 -1
  116. package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +0 -1
  117. package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
  118. package/dist/types/excalidraw/components/CommandPalette/types.d.ts +2 -4
  119. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -2
  120. package/dist/types/excalidraw/components/DarkModeToggle.d.ts +1 -1
  121. package/dist/types/excalidraw/components/DefaultSidebar.d.ts +9 -13
  122. package/dist/types/excalidraw/components/ElementLinkDialog.d.ts +1 -1
  123. package/dist/types/excalidraw/components/Ellipsify.d.ts +3 -0
  124. package/dist/types/excalidraw/components/ErrorDialog.d.ts +1 -1
  125. package/dist/types/excalidraw/components/EyeDropper.d.ts +0 -1
  126. package/dist/types/excalidraw/components/FilledButton.d.ts +2 -1
  127. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +2 -1
  128. package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +3 -1
  129. package/dist/types/excalidraw/components/FontPicker/keyboardNavHandlers.d.ts +0 -1
  130. package/dist/types/excalidraw/components/HelpDialog.d.ts +1 -1
  131. package/dist/types/excalidraw/components/HintViewer.d.ts +4 -3
  132. package/dist/types/excalidraw/components/IconPicker.d.ts +14 -9
  133. package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
  134. package/dist/types/excalidraw/components/LayerUI.d.ts +2 -1
  135. package/dist/types/excalidraw/components/LibraryMenuControlButtons.d.ts +1 -1
  136. package/dist/types/excalidraw/components/LibraryMenuHeaderContent.d.ts +1 -2
  137. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
  138. package/dist/types/excalidraw/components/LibraryUnit.d.ts +2 -3
  139. package/dist/types/excalidraw/components/LoadingMessage.d.ts +0 -1
  140. package/dist/types/excalidraw/components/MobileMenu.d.ts +3 -5
  141. package/dist/types/excalidraw/components/MobileToolBar.d.ts +10 -0
  142. package/dist/types/excalidraw/components/Modal.d.ts +0 -1
  143. package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirm.d.ts +1 -1
  144. package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
  145. package/dist/types/excalidraw/components/Popover.d.ts +2 -1
  146. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +2 -1
  147. package/dist/types/excalidraw/components/RadioGroup.d.ts +0 -1
  148. package/dist/types/excalidraw/components/RadioSelection.d.ts +4 -4
  149. package/dist/types/excalidraw/components/Range.d.ts +10 -4
  150. package/dist/types/excalidraw/components/ScrollableList.d.ts +0 -1
  151. package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +15 -21
  152. package/dist/types/excalidraw/components/Sidebar/SidebarHeader.d.ts +1 -1
  153. package/dist/types/excalidraw/components/Sidebar/SidebarTab.d.ts +1 -2
  154. package/dist/types/excalidraw/components/Sidebar/SidebarTabTrigger.d.ts +1 -2
  155. package/dist/types/excalidraw/components/Sidebar/SidebarTabTriggers.d.ts +1 -2
  156. package/dist/types/excalidraw/components/Sidebar/SidebarTabs.d.ts +1 -2
  157. package/dist/types/excalidraw/components/Spinner.d.ts +4 -4
  158. package/dist/types/excalidraw/components/Stats/CanvasGrid.d.ts +0 -1
  159. package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +0 -1
  160. package/dist/types/excalidraw/components/Stats/DragInput.d.ts +0 -1
  161. package/dist/types/excalidraw/components/Stats/index.d.ts +7 -8
  162. package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
  163. package/dist/types/excalidraw/components/TTDDialog/Chat/ChatHistoryMenu.d.ts +15 -0
  164. package/dist/types/excalidraw/components/TTDDialog/Chat/ChatInterface.d.ts +23 -0
  165. package/dist/types/excalidraw/components/TTDDialog/Chat/ChatMessage.d.ts +14 -0
  166. package/dist/types/excalidraw/components/TTDDialog/Chat/TTDChatPanel.d.ts +27 -0
  167. package/dist/types/excalidraw/components/TTDDialog/Chat/index.d.ts +3 -0
  168. package/dist/types/excalidraw/components/TTDDialog/Chat/useChatAgent.d.ts +8 -0
  169. package/dist/types/excalidraw/components/TTDDialog/CodeMirrorEditor.d.ts +11 -0
  170. package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +3 -2
  171. package/dist/types/excalidraw/components/TTDDialog/TTDContext.d.ts +13 -0
  172. package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +12 -29
  173. package/dist/types/excalidraw/components/TTDDialog/TTDDialogInput.d.ts +3 -3
  174. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +5 -2
  175. package/dist/types/excalidraw/components/TTDDialog/TTDDialogPanel.d.ts +13 -9
  176. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTab.d.ts +1 -2
  177. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTrigger.d.ts +1 -2
  178. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTriggers.d.ts +1 -2
  179. package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +9 -0
  180. package/dist/types/excalidraw/components/TTDDialog/TTDWelcomeMessage.d.ts +1 -0
  181. package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +9 -0
  182. package/dist/types/excalidraw/components/TTDDialog/common.d.ts +16 -16
  183. package/dist/types/excalidraw/components/TTDDialog/hooks/useChatManagement.d.ts +13 -0
  184. package/dist/types/excalidraw/components/TTDDialog/hooks/useMermaidRenderer.d.ts +14 -0
  185. package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +7 -0
  186. package/dist/types/excalidraw/components/TTDDialog/mermaid-lang-lite.d.ts +2 -0
  187. package/dist/types/excalidraw/components/TTDDialog/types.d.ts +95 -0
  188. package/dist/types/excalidraw/components/TTDDialog/useTTDChatStorage.d.ts +22 -0
  189. package/dist/types/excalidraw/components/TTDDialog/utils/chat.d.ts +10 -0
  190. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidAutoFix.d.ts +1 -0
  191. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +10 -0
  192. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidValidation.d.ts +1 -0
  193. package/dist/types/excalidraw/components/TextField.d.ts +1 -0
  194. package/dist/types/excalidraw/components/Toast.d.ts +11 -7
  195. package/dist/types/excalidraw/components/ToolPopover.d.ts +25 -0
  196. package/dist/types/excalidraw/components/Trans.d.ts +2 -2
  197. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +7 -3
  198. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +47 -35
  199. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +7 -5
  200. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuGroup.d.ts +3 -3
  201. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +13 -22
  202. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCheckbox.d.ts +5 -0
  203. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContent.d.ts +5 -4
  204. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +2 -2
  205. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCustom.d.ts +2 -2
  206. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemLink.d.ts +6 -6
  207. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSub.d.ts +23 -0
  208. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubContent.d.ts +8 -0
  209. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubTrigger.d.ts +12 -0
  210. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuTrigger.d.ts +3 -4
  211. package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +2 -2
  212. package/dist/types/excalidraw/components/dropdownMenu/dropdownMenuUtils.d.ts +2 -0
  213. package/dist/types/excalidraw/components/hoc/withInternalFallback.d.ts +1 -1
  214. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +1 -1
  215. package/dist/types/excalidraw/components/icons.d.ts +49 -21
  216. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +20 -2
  217. package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +39 -35
  218. package/dist/types/excalidraw/components/shapes.d.ts +202 -1
  219. package/dist/types/excalidraw/data/blob.d.ts +329 -12
  220. package/dist/types/excalidraw/data/encode.d.ts +4 -4
  221. package/dist/types/excalidraw/data/encryption.d.ts +5 -5
  222. package/dist/types/excalidraw/data/filesystem.d.ts +5 -7
  223. package/dist/types/excalidraw/data/index.d.ts +4 -5
  224. package/dist/types/excalidraw/data/json.d.ts +171 -4
  225. package/dist/types/excalidraw/data/library.d.ts +24 -9
  226. package/dist/types/excalidraw/data/resave.d.ts +7 -2
  227. package/dist/types/excalidraw/data/restore.d.ts +27 -7
  228. package/dist/types/excalidraw/data/types.d.ts +4 -1
  229. package/dist/types/excalidraw/editor-jotai.d.ts +11 -11
  230. package/dist/types/excalidraw/errors.d.ts +14 -0
  231. package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
  232. package/dist/types/excalidraw/hooks/useOutsideClick.d.ts +4 -3
  233. package/dist/types/excalidraw/hooks/useScrollPosition.d.ts +1 -2
  234. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +14 -0
  235. package/dist/types/excalidraw/i18n.d.ts +2 -2
  236. package/dist/types/excalidraw/renderer/animation.d.ts +12 -0
  237. package/dist/types/excalidraw/renderer/helpers.d.ts +6 -8
  238. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +8 -14
  239. package/dist/types/excalidraw/renderer/staticScene.d.ts +4 -1
  240. package/dist/types/excalidraw/scene/Renderer.d.ts +5 -2
  241. package/dist/types/excalidraw/scene/export.d.ts +2 -2
  242. package/dist/types/excalidraw/scene/scroll.d.ts +1 -6
  243. package/dist/types/excalidraw/scene/types.d.ts +22 -5
  244. package/dist/types/excalidraw/shortcut.d.ts +1 -0
  245. package/dist/types/excalidraw/snapping.d.ts +5 -5
  246. package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-bindings.d.ts +1 -1
  247. package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-loader.d.ts +1 -1
  248. package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-wasm.d.ts +1 -1
  249. package/dist/types/excalidraw/subset/woff2/woff2-loader.d.ts +2 -2
  250. package/dist/types/excalidraw/subset/woff2/woff2-wasm.d.ts +1 -1
  251. package/dist/types/excalidraw/textAutoResizeHandle.d.ts +15 -0
  252. package/dist/types/excalidraw/types.d.ts +130 -38
  253. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +7 -3
  254. package/dist/types/math/src/curve.d.ts +4 -1
  255. package/dist/types/math/src/point.d.ts +7 -2
  256. package/dist/types/math/src/polygon.d.ts +2 -2
  257. package/dist/types/math/src/range.d.ts +1 -3
  258. package/dist/types/math/src/segment.d.ts +4 -3
  259. package/dist/types/math/src/types.d.ts +25 -1
  260. package/dist/types/utils/src/bbox.d.ts +1 -1
  261. package/dist/types/utils/src/export.d.ts +5 -5
  262. package/dist/types/utils/src/shape.d.ts +6 -6
  263. package/dist/types/utils/src/withinBounds.d.ts +2 -2
  264. package/package.json +9 -3
  265. package/dist/types/excalidraw/charts.d.ts +0 -27
  266. package/dist/types/excalidraw/components/DiagramToCodePlugin/DiagramToCodePlugin.d.ts +0 -4
  267. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -16
  268. package/dist/types/excalidraw/components/InitializeApp.d.ts +0 -10
  269. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +0 -9
  270. package/dist/types/excalidraw/components/footer/FooterCenter.d.ts +0 -8
  271. package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -10
  272. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -58
  273. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Hints.d.ts +0 -19
  274. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +0 -85
  275. package/dist/types/excalidraw/data/reconcile.d.ts +0 -6
  276. package/dist/types/excalidraw/index.d.ts +0 -46
  277. package/dist/types/excalidraw/polyfill.d.ts +0 -2
@@ -1,27 +1,28 @@
1
- var cd=Object.create;var bs=Object.defineProperty;var dd=Object.getOwnPropertyDescriptor;var ud=Object.getOwnPropertyNames;var pd=Object.getPrototypeOf,md=Object.prototype.hasOwnProperty;var fd=(e,t)=>()=>(e&&(t=e(e=0)),t);var hd=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ed=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ud(t))!md.call(e,o)&&o!==n&&bs(e,o,{get:()=>t[o],enumerable:!(i=dd(t,o))||i.enumerable});return e};var gd=(e,t,n)=>(n=e!=null?cd(pd(e)):{},Ed(t||!e||!e.__esModule?bs(n,"default",{value:e,enumerable:!0}):n,e));var A,P=fd(()=>{A={PROD:!0}});var xc=hd((A1,gc)=>{P();var Ec="Expected a function",fc=NaN,Rf="[object Symbol]",Ff=/^\s+|\s+$/g,Nf=/^[-+]0x[0-9a-f]+$/i,zf=/^0b[01]+$/i,Hf=/^0o[0-7]+$/i,_f=parseInt,Yf=typeof global=="object"&&global&&global.Object===Object&&global,Xf=typeof self=="object"&&self&&self.Object===Object&&self,Uf=Yf||Xf||Function("return this")(),Wf=Object.prototype,jf=Wf.toString,Vf=Math.max,$f=Math.min,ts=function(){return Uf.Date.now()};function Zf(e,t,n){var i,o,r,s,a,l,c=0,d=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(Ec);t=hc(t)||0,Po(n)&&(d=!!n.leading,u="maxWait"in n,r=u?Vf(hc(n.maxWait)||0,t):r,p="trailing"in n?!!n.trailing:p);function m(I){var M=i,v=o;return i=o=void 0,c=I,s=e.apply(v,M),s}function f(I){return c=I,a=setTimeout(g,t),d?m(I):s}function E(I){var M=I-l,v=I-c,T=t-M;return u?$f(T,r-v):T}function h(I){var M=I-l,v=I-c;return l===void 0||M>=t||M<0||u&&v>=r}function g(){var I=ts();if(h(I))return x(I);a=setTimeout(g,E(I))}function x(I){return a=void 0,p&&i?m(I):(i=o=void 0,s)}function y(){a!==void 0&&clearTimeout(a),c=0,i=l=o=a=void 0}function b(){return a===void 0?s:x(ts())}function w(){var I=ts(),M=h(I);if(i=arguments,o=this,l=I,M){if(a===void 0)return f(l);if(u)return a=setTimeout(g,t),m(l)}return a===void 0&&(a=setTimeout(g,t)),s}return w.cancel=y,w.flush=b,w}function qf(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(Ec);return Po(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),Zf(e,t,{leading:i,maxWait:t,trailing:o})}function Po(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Kf(e){return!!e&&typeof e=="object"}function Qf(e){return typeof e=="symbol"||Kf(e)&&jf.call(e)==Rf}function hc(e){if(typeof e=="number")return e;if(Qf(e))return fc;if(Po(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Po(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Ff,"");var n=zf.test(e);return n||Hf.test(e)?_f(e.slice(2),n?2:8):Nf.test(e)?fc:+e}gc.exports=qf});P();import{toIterable as dE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Bt,viewportCoordsToSceneCoords as xo}from"@excalidraw/common";import{normalizeRadians as Zl,radiansBetweenAngles as uf,radiansDifference as pf}from"@excalidraw/math";import{pointsEqual as mf}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function ko(e,t,n){if(e&&e.length){let[i,o]=t,r=Math.PI/180*n,s=Math.cos(r),a=Math.sin(r);for(let l of e){let[c,d]=l;l[0]=(c-i)*s-(d-o)*a+i,l[1]=(c-i)*a+(d-o)*s+o}}}function wd(e,t,n){let i=[];e.forEach(o=>i.push(...o)),ko(i,t,n)}function yd(e,t){return e[0]===t[0]&&e[1]===t[1]}function Ps(e,t,n,i=1){let o=n,r=Math.max(t,.1),s=e[0]&&e[0][0]&&typeof e[0][0]=="number"?[e]:e,a=[0,0];if(o)for(let c of s)ko(c,a,o);let l=bd(s,r,i);if(o){for(let c of s)ko(c,a,-o);wd(l,a,-o)}return l}function bd(e,t,n){let i=[];for(let c of e){let d=[...c];yd(d[0],d[d.length-1])||d.push([d[0][0],d[0][1]]),d.length>2&&i.push(d)}let o=[];t=Math.max(t,.1);let r=[];for(let c of i)for(let d=0;d<c.length-1;d++){let u=c[d],p=c[d+1];if(u[1]!==p[1]){let m=Math.min(u[1],p[1]);r.push({ymin:m,ymax:Math.max(u[1],p[1]),x:m===u[1]?u[0]:p[0],islope:(p[0]-u[0])/(p[1]-u[1])})}}if(r.sort((c,d)=>c.ymin<d.ymin?-1:c.ymin>d.ymin?1:c.x<d.x?-1:c.x>d.x?1:c.ymax===d.ymax?0:(c.ymax-d.ymax)/Math.abs(c.ymax-d.ymax)),!r.length)return o;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let c=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)c=u;r.splice(0,c+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(c=>!(c.edge.ymax<=a)),s.sort((c,d)=>c.edge.x===d.edge.x?0:(c.edge.x-d.edge.x)/Math.abs(c.edge.x-d.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let c=0;c<s.length;c=c+2){let d=c+1;if(d>=s.length)break;let u=s[c].edge,p=s[d].edge;o.push([[Math.round(u.x),a],[Math.round(p.x),a]])}a+=n,s.forEach(c=>{c.edge.x=c.edge.x+n*c.edge.islope}),l++}return o}function rt(e,t){var n;let i=t.hachureAngle+90,o=t.hachureGap;o<0&&(o=t.strokeWidth*4),o=Math.max(o,.1);let r=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(r=o),Ps(e,o,i,r||1)}var kt=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=rt(t,n);return{type:"fillSketch",ops:this.renderLines(i,n)}}renderLines(t,n){let i=[];for(let o of t)i.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return i}};P();P();function Rt(e){let t=e[0],n=e[1];return Math.sqrt(Math.pow(t[0]-n[0],2)+Math.pow(t[1]-n[1],2))}var fi=class extends kt{fillPolygons(t,n){let i=n.hachureGap;i<0&&(i=n.strokeWidth*4),i=Math.max(i,.1);let o=Object.assign({},n,{hachureGap:i}),r=rt(t,o),s=Math.PI/180*n.hachureAngle,a=[],l=i*.5*Math.cos(s),c=i*.5*Math.sin(s);for(let[u,p]of r)Rt([u,p])&&a.push([[u[0]-l,u[1]+c],[...p]],[[u[0]+l,u[1]-c],[...p]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var hi=class extends kt{fillPolygons(t,n){let i=this._fillPolygons(t,n),o=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),r=this._fillPolygons(t,o);return i.ops=i.ops.concat(r.ops),i}};P();var Ei=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=rt(t,n);return this.dotsOnLines(i,n)}dotsOnLines(t,n){let i=[],o=n.hachureGap;o<0&&(o=n.strokeWidth*4),o=Math.max(o,.1);let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let s=o/4;for(let a of t){let l=Rt(a),c=l/o,d=Math.ceil(c)-1,u=l-d*o,p=(a[0][0]+a[1][0])/2-o/4,m=Math.min(a[0][1],a[1][1]);for(let f=0;f<d;f++){let E=m+u+f*o,h=p-s+Math.random()*2*s,g=E-s+Math.random()*2*s,x=this.helper.ellipse(h,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var gi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=rt(t,n);return{type:"fillSketch",ops:this.dashedLine(i,n)}}dashedLine(t,n){let i=n.dashOffset<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashOffset,o=n.dashGap<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashGap,r=[];return t.forEach(s=>{let a=Rt(s),l=Math.floor(a/(i+o)),c=(a+o-l*(i+o))/2,d=s[0],u=s[1];d[0]>u[0]&&(d=s[1],u=s[0]);let p=Math.atan((u[1]-d[1])/(u[0]-d[0]));for(let m=0;m<l;m++){let f=m*(i+o),E=f+i,h=[d[0]+f*Math.cos(p)+c*Math.cos(p),d[1]+f*Math.sin(p)+c*Math.sin(p)],g=[d[0]+E*Math.cos(p)+c*Math.cos(p),d[1]+E*Math.sin(p)+c*Math.sin(p)];r.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],n))}}),r}};P();var xi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,o=n.zigzagOffset<0?i:n.zigzagOffset;n=Object.assign({},n,{hachureGap:i+o});let r=rt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=Rt(r),a=Math.round(s/(2*n)),l=r[0],c=r[1];l[0]>c[0]&&(l=r[1],c=r[0]);let d=Math.atan((c[1]-l[1])/(c[0]-l[0]));for(let u=0;u<a;u++){let p=u*2*n,m=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),E=[l[0]+p*Math.cos(d),l[1]+p*Math.sin(d)],h=[l[0]+m*Math.cos(d),l[1]+m*Math.sin(d)],g=[E[0]+f*Math.cos(d+Math.PI/4),E[1]+f*Math.sin(d+Math.PI/4)];o.push(...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],i),...this.helper.doubleLineOps(g[0],g[1],h[0],h[1],i))}}),o}};var De={};function Is(e,t){let n=e.fillStyle||"hachure";if(!De[n])switch(n){case"zigzag":De[n]||(De[n]=new fi(t));break;case"cross-hatch":De[n]||(De[n]=new hi(t));break;case"dots":De[n]||(De[n]=new Ei(t));break;case"dashed":De[n]||(De[n]=new gi(t));break;case"zigzag-line":De[n]||(De[n]=new xi(t));break;case"hachure":default:n="hachure",De[n]||(De[n]=new kt(t));break}return De[n]}P();function Ss(){return Math.floor(Math.random()*2**31)}var wi=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};P();P();var yi={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Pd(e){let t=new Array;for(;e!=="";)if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([aAcChHlLmMqQsStTvVzZ])/))t[t.length]={type:0,text:RegExp.$1},e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))t[t.length]={type:1,text:`${parseFloat(RegExp.$1)}`},e=e.substr(RegExp.$1.length);else return[];return t[t.length]={type:2,text:""},t}function Ro(e,t){return e.type===t}function xn(e){let t=[],n=Pd(e),i="BOD",o=0,r=n[o];for(;!Ro(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=yi[r.text],i=r.text;else return xn("M0,0"+e);else Ro(r,1)?s=yi[i]:(o++,s=yi[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let c=n[l];if(Ro(c,1))a[a.length]=+c.text;else throw new Error("Param not a number: "+i+","+c.text)}if(typeof yi[i]=="number"){let l={key:i,data:a};t.push(l),o+=s,r=n[o],i==="M"&&(i="L"),i==="m"&&(i="l")}else throw new Error("Bad segment: "+i)}else throw new Error("Path data ended short")}return t}P();function Hn(e){let t=0,n=0,i=0,o=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[i,o]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),i=t,o=n;break;case"L":r.push({key:"L",data:[...a]}),[t,n]=a;break;case"l":t+=a[0],n+=a[1],r.push({key:"L",data:[t,n]});break;case"C":r.push({key:"C",data:[...a]}),t=a[4],n=a[5];break;case"c":{let l=a.map((c,d)=>d%2?c+n:c+t);r.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":r.push({key:"Q",data:[...a]}),t=a[2],n=a[3];break;case"q":{let l=a.map((c,d)=>d%2?c+n:c+t);r.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":r.push({key:"A",data:[...a]}),t=a[5],n=a[6];break;case"a":t+=a[5],n+=a[6],r.push({key:"A",data:[a[0],a[1],a[2],a[3],a[4],t,n]});break;case"H":r.push({key:"H",data:[...a]}),t=a[0];break;case"h":t+=a[0],r.push({key:"H",data:[t]});break;case"V":r.push({key:"V",data:[...a]}),n=a[0];break;case"v":n+=a[0],r.push({key:"V",data:[n]});break;case"S":r.push({key:"S",data:[...a]}),t=a[2],n=a[3];break;case"s":{let l=a.map((c,d)=>d%2?c+n:c+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=i,n=o;break}return r}P();function Yn(e){let t=[],n="",i=0,o=0,r=0,s=0,a=0,l=0;for(let{key:c,data:d}of e){switch(c){case"M":t.push({key:"M",data:[...d]}),[i,o]=d,[r,s]=d;break;case"C":t.push({key:"C",data:[...d]}),i=d[4],o=d[5],a=d[2],l=d[3];break;case"L":t.push({key:"L",data:[...d]}),[i,o]=d;break;case"H":i=d[0],t.push({key:"L",data:[i,o]});break;case"V":o=d[0],t.push({key:"L",data:[i,o]});break;case"S":{let u=0,p=0;n==="C"||n==="S"?(u=i+(i-a),p=o+(o-l)):(u=i,p=o),t.push({key:"C",data:[u,p,...d]}),a=d[0],l=d[1],i=d[2],o=d[3];break}case"T":{let[u,p]=d,m=0,f=0;n==="Q"||n==="T"?(m=i+(i-a),f=o+(o-l)):(m=i,f=o);let E=i+2*(m-i)/3,h=o+2*(f-o)/3,g=u+2*(m-u)/3,x=p+2*(f-p)/3;t.push({key:"C",data:[E,h,g,x,u,p]}),a=m,l=f,i=u,o=p;break}case"Q":{let[u,p,m,f]=d,E=i+2*(u-i)/3,h=o+2*(p-o)/3,g=m+2*(u-m)/3,x=f+2*(p-f)/3;t.push({key:"C",data:[E,h,g,x,m,f]}),a=u,l=p,i=m,o=f;break}case"A":{let u=Math.abs(d[0]),p=Math.abs(d[1]),m=d[2],f=d[3],E=d[4],h=d[5],g=d[6];u===0||p===0?(t.push({key:"C",data:[i,o,h,g,h,g]}),i=h,o=g):(i!==h||o!==g)&&(Ms(i,o,h,g,u,p,m,f,E).forEach(function(y){t.push({key:"C",data:y})}),i=h,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=c}return t}function Id(e){return Math.PI*e/180}function _n(e,t,n){let i=e*Math.cos(n)-t*Math.sin(n),o=e*Math.sin(n)+t*Math.cos(n);return[i,o]}function Ms(e,t,n,i,o,r,s,a,l,c){let d=Id(s),u=[],p=0,m=0,f=0,E=0;if(c)[p,m,f,E]=c;else{[e,t]=_n(e,t,-d),[n,i]=_n(n,i,-d);let R=(e-n)/2,L=(t-i)/2,W=R*R/(o*o)+L*L/(r*r);W>1&&(W=Math.sqrt(W),o=W*o,r=W*r);let N=a===l?-1:1,ee=o*o,S=r*r,K=ee*S-ee*L*L-S*R*R,j=ee*L*L+S*R*R,te=N*Math.sqrt(Math.abs(K/j));f=te*o*L/r+(e+n)/2,E=te*-r*R/o+(t+i)/2,p=Math.asin(parseFloat(((t-E)/r).toFixed(9))),m=Math.asin(parseFloat(((i-E)/r).toFixed(9))),e<f&&(p=Math.PI-p),n<f&&(m=Math.PI-m),p<0&&(p=Math.PI*2+p),m<0&&(m=Math.PI*2+m),l&&p>m&&(p=p-Math.PI*2),!l&&m>p&&(m=m-Math.PI*2)}let h=m-p;if(Math.abs(h)>Math.PI*120/180){let R=m,L=n,W=i;l&&m>p?m=p+Math.PI*120/180*1:m=p+Math.PI*120/180*-1,n=f+o*Math.cos(m),i=E+r*Math.sin(m),u=Ms(n,i,L,W,o,r,s,0,l,[m,R,f,E])}h=m-p;let g=Math.cos(p),x=Math.sin(p),y=Math.cos(m),b=Math.sin(m),w=Math.tan(h/4),I=4/3*o*w,M=4/3*r*w,v=[e,t],T=[e+I*x,t-M*g],F=[n+I*b,i-M*y],C=[n,i];if(T[0]=2*v[0]-T[0],T[1]=2*v[1]-T[1],c)return[T,F,C].concat(u);{u=[T,F,C].concat(u);let R=[];for(let L=0;L<u.length;L+=3){let W=_n(u[L][0],u[L][1],d),N=_n(u[L+1][0],u[L+1][1],d),ee=_n(u[L+2][0],u[L+2][1],d);R.push([W[0],W[1],N[0],N[1],ee[0],ee[1]])}return R}}var Sd={randOffset:Ad,randOffsetWithRange:vd,ellipse:Td,doubleLineOps:Dd};function Fo(e,t,n,i,o){return{type:"path",ops:ht(e,t,n,i,o)}}function Xn(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...ht(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...ht(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return Fo(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Md(e,t){return Xn(e,!0,t)}function Ls(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Md(r,o)}function No(e,t){let n=As(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=As(e,1.5*(1+t.roughness*.22),Ld(t));n=n.concat(i)}return{type:"path",ops:n}}function Td(e,t,n,i,o){let r=zo(n,i,o);return Ii(e,t,o,r).opset}function zo(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=O(s*l,n),a+=O(a*l,n),{increment:r,rx:s,ry:a}}function Ii(e,t,n,i){let[o,r]=vs(i.increment,e,t,i.rx,i.ry,1,i.increment*bi(.1,bi(.4,1,n),n),n),s=Pi(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=vs(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Pi(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Ho(e,t,n,i,o,r,s,a,l){let c=e,d=t,u=Math.abs(n/2),p=Math.abs(i/2);u+=O(u*.01,l),p+=O(p*.01,l);let m=o,f=r;for(;m<0;)m+=Math.PI*2,f+=Math.PI*2;f-m>Math.PI*2&&(m=0,f=Math.PI*2);let E=Math.PI*2/l.curveStepCount,h=Math.min(E/2,(f-m)/2),g=Ds(h,c,d,u,p,m,f,1,l);if(!l.disableMultiStroke){let x=Ds(h,c,d,u,p,m,f,1.5,l);g.push(...x)}return s&&(a?g.push(...ht(c,d,c+u*Math.cos(m),d+p*Math.sin(m),l),...ht(c,d,c+u*Math.cos(f),d+p*Math.sin(f),l)):g.push({op:"lineTo",data:[c,d]},{op:"lineTo",data:[c+u*Math.cos(m),d+p*Math.sin(m)]})),{type:"path",ops:g}}function _o(e,t){let n=Yn(Hn(xn(e))),i=[],o=[0,0],r=[0,0];for(let{key:s,data:a}of n)switch(s){case"M":{r=[a[0],a[1]],o=[a[0],a[1]];break}case"L":i.push(...ht(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,c,d,u,p,m]=a;i.push(...Cd(l,c,d,u,p,m,r,t)),r=[p,m];break}case"Z":i.push(...ht(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function Si(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+O(o,t),i[0][1]+O(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+O(o,t),i[s][1]+O(o,t)]})}}return{type:"fillPath",ops:n}}function on(e,t){return Is(t,Sd).fillPolygons(e,t)}function Cs(e,t,n,i,o,r,s){let a=e,l=t,c=Math.abs(n/2),d=Math.abs(i/2);c+=O(c*.01,s),d+=O(d*.01,s);let u=o,p=r;for(;u<0;)u+=Math.PI*2,p+=Math.PI*2;p-u>Math.PI*2&&(u=0,p=Math.PI*2);let m=(p-u)/s.curveStepCount,f=[];for(let E=u;E<=p;E=E+m)f.push([a+c*Math.cos(E),l+d*Math.sin(E)]);return f.push([a+c*Math.cos(p),l+d*Math.sin(p)]),f.push([a,l]),on([f],s)}function Ad(e,t){return O(e,t)}function vd(e,t,n){return bi(e,t,n)}function Dd(e,t,n,i,o){return ht(e,t,n,i,o,!0)}function Ld(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Bs(e){return e.randomizer||(e.randomizer=new wi(e.seed||0)),e.randomizer.next()}function bi(e,t,n,i=1){return n.roughness*i*(Bs(n)*(t-e)+e)}function O(e,t,n=1){return bi(-e,e,t,n)}function ht(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=Ts(e,t,n,i,o,!0,!1);if(s)return a;let l=Ts(e,t,n,i,o,!0,!0);return a.concat(l)}function Ts(e,t,n,i,o,r,s){let a=Math.pow(e-n,2)+Math.pow(t-i,2),l=Math.sqrt(a),c=1;l<200?c=1:l>500?c=.4:c=-.0016668*l+1.233334;let d=o.maxRandomnessOffset||0;d*d*100>a&&(d=l/10);let u=d/2,p=.2+Bs(o)*.2,m=o.bowing*o.maxRandomnessOffset*(i-t)/200,f=o.bowing*o.maxRandomnessOffset*(e-n)/200;m=O(m,o,c),f=O(f,o,c);let E=[],h=()=>O(u,o,c),g=()=>O(d,o,c),x=o.preserveVertices;return r&&(s?E.push({op:"move",data:[e+(x?0:h()),t+(x?0:h())]}):E.push({op:"move",data:[e+(x?0:O(d,o,c)),t+(x?0:O(d,o,c))]})),s?E.push({op:"bcurveTo",data:[m+e+(n-e)*p+h(),f+t+(i-t)*p+h(),m+e+2*(n-e)*p+h(),f+t+2*(i-t)*p+h(),n+(x?0:h()),i+(x?0:h())]}):E.push({op:"bcurveTo",data:[m+e+(n-e)*p+g(),f+t+(i-t)*p+g(),m+e+2*(n-e)*p+g(),f+t+2*(i-t)*p+g(),n+(x?0:g()),i+(x?0:g())]}),E}function As(e,t,n){let i=[];i.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]),i.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+O(t,n),e[o][1]+O(t,n)]),o===e.length-1&&i.push([e[o][0]+O(t,n),e[o][1]+O(t,n)]);return Pi(i,null,n)}function Pi(e,t,n){let i=e.length,o=[];if(i>3){let r=[],s=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<i;a++){let l=e[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*e[a+1][0]-s*e[a-1][0])/6,l[1]+(s*e[a+1][1]-s*e[a-1][1])/6],r[2]=[e[a+1][0]+(s*e[a][0]-s*e[a+2][0])/6,e[a+1][1]+(s*e[a][1]-s*e[a+2][1])/6],r[3]=[e[a+1][0],e[a+1][1]],o.push({op:"bcurveTo",data:[r[1][0],r[1][1],r[2][0],r[2][1],r[3][0],r[3][1]]})}if(t&&t.length===2){let a=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+O(a,n),t[1]+O(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...ht(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function vs(e,t,n,i,o,r,s,a){let l=a.roughness===0,c=[],d=[];if(l){e=e/4,d.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let p=[t+i*Math.cos(u),n+o*Math.sin(u)];c.push(p),d.push(p)}d.push([t+i*Math.cos(0),n+o*Math.sin(0)]),d.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=O(.5,a)-Math.PI/2;d.push([O(r,a)+t+.9*i*Math.cos(u-e),O(r,a)+n+.9*o*Math.sin(u-e)]);let p=Math.PI*2+u-.01;for(let m=u;m<p;m=m+e){let f=[O(r,a)+t+i*Math.cos(m),O(r,a)+n+o*Math.sin(m)];c.push(f),d.push(f)}d.push([O(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),O(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),d.push([O(r,a)+t+.98*i*Math.cos(u+s),O(r,a)+n+.98*o*Math.sin(u+s)]),d.push([O(r,a)+t+.9*i*Math.cos(u+s*.5),O(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[d,c]}function Ds(e,t,n,i,o,r,s,a,l){let c=r+O(.1,l),d=[];d.push([O(a,l)+t+.9*i*Math.cos(c-e),O(a,l)+n+.9*o*Math.sin(c-e)]);for(let u=c;u<=s;u=u+e)d.push([O(a,l)+t+i*Math.cos(u),O(a,l)+n+o*Math.sin(u)]);return d.push([t+i*Math.cos(s),n+o*Math.sin(s)]),d.push([t+i*Math.cos(s),n+o*Math.sin(s)]),Pi(d,null,l)}function Cd(e,t,n,i,o,r,s,a){let l=[],c=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],d=[0,0],u=a.disableMultiStroke?1:2,p=a.preserveVertices;for(let m=0;m<u;m++)m===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(p?0:O(c[0],a)),s[1]+(p?0:O(c[0],a))]}),d=p?[o,r]:[o+O(c[m],a),r+O(c[m],a)],l.push({op:"bcurveTo",data:[e+O(c[m],a),t+O(c[m],a),n+O(c[m],a),i+O(c[m],a),d[0],d[1]]});return l}P();function Un(e){return[...e]}function Gs(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let i=[];if(n===3)i.push(Un(e[0]),Un(e[1]),Un(e[2]),Un(e[2]));else{let o=[];o.push(e[0],e[0]);for(let a=1;a<e.length;a++)o.push(e[a]),a===e.length-1&&o.push(e[a]);let r=[],s=1-t;i.push(Un(o[0]));for(let a=1;a+2<o.length;a++){let l=o[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*o[a+1][0]-s*o[a-1][0])/6,l[1]+(s*o[a+1][1]-s*o[a-1][1])/6],r[2]=[o[a+1][0]+(s*o[a][0]-s*o[a+2][0])/6,o[a+1][1]+(s*o[a][1]-s*o[a+2][1])/6],r[3]=[o[a+1][0],o[a+1][1]],i.push(r[1],r[2],r[3])}}return i}P();function Bd(e,t){return Math.sqrt(Mi(e,t))}function Mi(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Gd(e,t,n){let i=Mi(t,n);if(i===0)return Mi(e,t);let o=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i;return o=Math.max(0,Math.min(1,o)),Mi(e,rn(t,n,o))}function rn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Od(e,t){let n=e[t+0],i=e[t+1],o=e[t+2],r=e[t+3],s=3*i[0]-2*n[0]-r[0];s*=s;let a=3*i[1]-2*n[1]-r[1];a*=a;let l=3*o[0]-2*r[0]-n[0];l*=l;let c=3*o[1]-2*r[1]-n[1];return c*=c,s<l&&(s=l),a<c&&(a=c),s+a}function Yo(e,t,n,i){let o=i||[];if(Od(e,t)<n){let r=e[t+0];o.length?Bd(o[o.length-1],r)>1&&o.push(r):o.push(r),o.push(e[t+3])}else{let s=e[t+0],a=e[t+1],l=e[t+2],c=e[t+3],d=rn(s,a,.5),u=rn(a,l,.5),p=rn(l,c,.5),m=rn(d,u,.5),f=rn(u,p,.5),E=rn(m,f,.5);Yo([s,d,m,E],0,n,o),Yo([E,f,p,c],0,n,o)}return o}function Wn(e,t){return Ti(e,0,e.length,t)}function Ti(e,t,n,i,o){let r=o||[],s=e[t],a=e[n-1],l=0,c=1;for(let d=t+1;d<n-1;++d){let u=Gd(e[d],s,a);u>l&&(l=u,c=d)}return Math.sqrt(l)>i?(Ti(e,t,c+1,i,r),Ti(e,c,n,i,r)):(r.length||r.push(s),r.push(a)),r}function Et(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;Yo(e,s,t,i)}return n&&n>0?Ti(i,0,i.length,n):i}P();function Os(e,t,n){let i=xn(e),o=Yn(Hn(i)),r=[],s=[],a=[0,0],l=[],c=()=>{l.length>=4&&s.push(...Et(l,t)),l=[]},d=()=>{c(),s.length&&(r.push(s),s=[])};for(let{key:p,data:m}of o)switch(p){case"M":d(),a=[m[0],m[1]],s.push(a);break;case"L":c(),s.push([m[0],m[1]]);break;case"C":if(!l.length){let f=s.length?s[s.length-1]:a;l.push([f[0],f[1]])}l.push([m[0],m[1]]),l.push([m[2],m[3]]),l.push([m[4],m[5]]);break;case"Z":c(),s.push([a[0],a[1]]);break}if(d(),!n)return r;let u=[];for(let p of r){let m=Wn(p,n);m.length&&u.push(m)}return u}var Ne="none",Ue=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Ss()}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,i){return{shape:t,sets:n||[],options:i||this.defaultOptions}}line(t,n,i,o,r){let s=this._o(r);return this._d("line",[Fo(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=Ls(t,n,i,o,s);if(s.fill){let c=[[t,n],[t+i,n],[t+i,n+o],[t,n+o]];s.fillStyle==="solid"?a.push(Si([c],s)):a.push(on([c],s))}return s.stroke!==Ne&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=zo(i,o,s),c=Ii(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let d=Ii(t,n,s,l).opset;d.type="fillPath",a.push(d)}else a.push(on([c.estimatedPoints],s));return s.stroke!==Ne&&a.push(c.opset),this._d("ellipse",a,s)}circle(t,n,i,o){let r=this.ellipse(t,n,i,i,o);return r.shape="circle",r}linearPath(t,n){let i=this._o(n);return this._d("linearPath",[Xn(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let c=this._o(l),d=[],u=Ho(t,n,i,o,r,s,a,!0,c);if(a&&c.fill)if(c.fillStyle==="solid"){let p=Object.assign({},c);p.disableMultiStroke=!0;let m=Ho(t,n,i,o,r,s,!0,!1,p);m.type="fillPath",d.push(m)}else d.push(Cs(t,n,i,o,r,s,c));return c.stroke!==Ne&&d.push(u),this._d("arc",d,c)}curve(t,n){let i=this._o(n),o=[],r=No(t,i);if(i.fill&&i.fill!==Ne&&t.length>=3)if(i.fillStyle==="solid"){let s=No(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(s.ops)})}else{let s=Gs(t),a=Et(s,10,(1+i.roughness)/2);o.push(on([a],i))}return i.stroke!==Ne&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=Xn(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(Si([t],i)):o.push(on([t],i))),i.stroke!==Ne&&o.push(r),this._d("polygon",o,i)}path(t,n){let i=this._o(n),o=[];if(!t)return this._d("path",o,i);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=i.fill&&i.fill!=="transparent"&&i.fill!==Ne,s=i.stroke!==Ne,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,c=Os(t,1,l),d=_o(t,i);if(r)if(i.fillStyle==="solid")if(c.length===1){let u=_o(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else o.push(Si(c,i));else o.push(on(c,i));return s&&(a?c.forEach(u=>{o.push(Xn(u,!1,i))}):o.push(d)),this._d("path",o,i)}opsToPath(t,n){let i="";for(let o of t.ops){let r=typeof n=="number"&&n>=0?o.data.map(s=>+s.toFixed(n)):o.data;switch(o.op){case"move":i+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":i+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":i+=`L${r[0]} ${r[1]} `;break}}return i.trim()}toPaths(t){let n=t.sets||[],i=t.options||this.defaultOptions,o=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:Ne};break;case"fillPath":s={d:this.opsToPath(r),stroke:Ne,strokeWidth:0,fill:i.fill||Ne};break;case"fillSketch":s=this.fillSketch(r,i);break}s&&o.push(s)}return o}fillSketch(t,n){let i=n.fillWeight;return i<0&&(i=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||Ne,strokeWidth:i,fill:Ne}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var Ai=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new Ue(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":o.save(),o.strokeStyle=i.stroke==="none"?"transparent":i.stroke,o.lineWidth=i.strokeWidth,i.strokeLineDash&&o.setLineDash(i.strokeLineDash),i.strokeLineDashOffset&&(o.lineDashOffset=i.strokeLineDashOffset),this._drawToContext(o,s,r),o.restore();break;case"fillPath":{o.save(),o.fillStyle=i.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,s,r,a),o.restore();break}case"fillSketch":this.fillSketch(o,s,i);break}}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2),t.save(),i.fillLineDash&&t.setLineDash(i.fillLineDash),i.fillLineDashOffset&&(t.lineDashOffset=i.fillLineDashOffset),t.strokeStyle=i.fill||"",t.lineWidth=o,this._drawToContext(t,n,i.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,i,o="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof i=="number"&&i>=0?r.data.map(a=>+a.toFixed(i)):r.data;switch(r.op){case"move":t.moveTo(s[0],s[1]);break;case"bcurveTo":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"lineTo":t.lineTo(s[0],s[1]);break}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s),s}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s),s}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s),s}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r),r}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i),i}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i),i}arc(t,n,i,o,r,s,a=!1,l){let c=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(c),c}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i),i}path(t,n){let i=this.gen.path(t,n);return this.draw(i),i}};P();P();var jn="http://www.w3.org/2000/svg";var vi=class{constructor(t,n){this.svg=t,this.gen=new Ue(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(jn,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(jn,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke",i.stroke),l.setAttribute("stroke-width",i.strokeWidth+""),l.setAttribute("fill","none"),i.strokeLineDash&&l.setAttribute("stroke-dasharray",i.strokeLineDash.join(" ").trim()),i.strokeLineDashOffset&&l.setAttribute("stroke-dashoffset",`${i.strokeLineDashOffset}`);break}case"fillPath":{l=o.createElementNS(jn,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke","none"),l.setAttribute("stroke-width","0"),l.setAttribute("fill",i.fill||""),(t.shape==="curve"||t.shape==="polygon")&&l.setAttribute("fill-rule","evenodd");break}case"fillSketch":{l=this.fillSketch(o,a,i);break}}l&&r.appendChild(l)}return r}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2);let r=t.createElementNS(jn,"path");return r.setAttribute("d",this.opsToPath(n,i.fixedDecimalPlaceDigits)),r.setAttribute("stroke",i.fill||""),r.setAttribute("stroke-width",o+""),r.setAttribute("fill","none"),i.fillLineDash&&r.setAttribute("stroke-dasharray",i.fillLineDash.join(" ").trim()),i.fillLineDashOffset&&r.setAttribute("stroke-dashoffset",`${i.fillLineDashOffset}`),r}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,n){return this.gen.opsToPath(t,n)}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s)}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s)}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s)}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r)}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i)}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i)}arc(t,n,i,o,r,s,a=!1,l){let c=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(c)}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i)}path(t,n){let i=this.gen.path(t,n);return this.draw(i)}};var sn={canvas(e,t){return new Ai(e,t)},svg(e,t){return new vi(e,t)},generator(e){return new Ue(e)},newSeed(){return Ue.newSeed()}};import{arrayToMap as Vl,invariant as Yr,rescalePoints as Yl,sizeOf as tf}from"@excalidraw/common";import{degreesToRadians as _r,lineSegment as Ee,pointDistance as nf,pointFrom as D,pointFromArray as $l,pointRotateRads as se}from"@excalidraw/math";P();import{invariant as kd}from"@excalidraw/common";import{curve as Rd,lineSegment as Fd,pointFrom as le,pointDistance as Zg,pointFromArray as Nd,pointFromVector as zd,pointRotateRads as Ze,polygon as ks,polygonFromPoints as Xo,PRECISION as qg,segmentsIntersectAt as Kg,vector as Hd,vectorAdd as _d,vectorFromPoint as Yd,vectorScale as Qg}from"@excalidraw/math";import{getElementAbsoluteCoords as ex}from"@excalidraw/element";var Rs=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=le(s,a),c;return e.type==="diamond"?c=ks(Ze(le(s,r),l,t),Ze(le(o+n,a),l,t),Ze(le(s,r+i),l,t),Ze(le(o,a),l,t)):c=ks(Ze(le(o,r),l,t),Ze(le(o+n,r),l,t),Ze(le(o+n,r+i),l,t),Ze(le(o,r+i),l,t)),{type:"polygon",data:c}};var Fs=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:le(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},gt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},Ns=(e,t=le(0,0),n,i)=>{let o=l=>Ze(le(l[0]+t[0],l[1]+t[1]),i,n),r=gt(e),s=[],a=le(0,0);for(let l of r){if(l.op==="move"){let c=Nd(l.data);kd(c!=null,"Ops data is not a point"),a=o(c)}if(l.op==="bcurveTo"){let c=o(le(l.data[0],l.data[1])),d=o(le(l.data[2],l.data[3])),u=o(le(l.data[4],l.data[5]));s.push(Rd(a,c,d,u)),a=u}}return{type:"polycurve",data:s}},Xd=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Fd(t,o)),t=o}return n},zs=(e,t,n=!1)=>{let i=r=>Ze(zd(_d(Yd(r),Hd(e.x,e.y))),t,e.angle),o=Xd(e.points.map(r=>i(r)));return n?{type:"polygon",data:Xo(o.flat())}:{type:"polyline",data:o}},Hs=(e,t,n=le(0,0),i,o)=>{let r=d=>Ze(le(d[0]+n[0],d[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:Xo(e.points.map(d=>r(d)))};let s=gt(t),a=[],l=!1;for(let d of s)d.op==="move"?(l=!l,l&&a.push(le(d.data[0],d.data[1]))):d.op==="bcurveTo"?l&&(a.push(le(d.data[0],d.data[1])),a.push(le(d.data[2],d.data[3])),a.push(le(d.data[4],d.data[5]))):d.op==="lineTo"&&l&&a.push(le(d.data[0],d.data[1]));let c=Et(a,10,5).map(d=>r(d));return{type:"polygon",data:Xo(c)}};P();import{pointFrom as ce,pointDistance as Rl,pointRotateRads as Lt}from"@excalidraw/math";import{ROUGHNESS as $m,isTransparent as ai,assertNever as Zm,COLOR_PALETTE as qm,LINE_POLYGON_POINT_MERGE_DISTANCE as Km}from"@excalidraw/common";P();P();function _s(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function Ud(e){return[-e[0],-e[1]]}function Ke(e,t){return[e[0]+t[0],e[1]+t[1]]}function We(e,t){return[e[0]-t[0],e[1]-t[1]]}function qe(e,t){return[e[0]*t,e[1]*t]}function Wd(e,t){return[e[0]/t,e[1]/t]}function Vn(e){return[e[1],-e[0]]}function Ys(e,t){return e[0]*t[0]+e[1]*t[1]}function jd(e,t){return e[0]===t[0]&&e[1]===t[1]}function Vd(e){return Math.hypot(e[0],e[1])}function $d(e){return e[0]*e[0]+e[1]*e[1]}function Xs(e,t){return $d(We(e,t))}function js(e){return Wd(e,Vd(e))}function Zd(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function $n(e,t,n){let i=Math.sin(n),o=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*o-s*i,l=r*i+s*o;return[a+t[0],l+t[1]]}function Uo(e,t,n){return Ke(e,qe(We(t,e),n))}function Us(e,t,n){return Ke(e,qe(t,n))}var{min:wn,PI:qd}=Math,Ws=.275,Zn=qd+1e-4;function Kd(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=S=>S,start:a={},end:l={},last:c=!1}=t,{cap:d=!0,easing:u=S=>S*(2-S)}=a,{cap:p=!0,easing:m=S=>--S*S*S+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,E=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,h=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*i,2),x=[],y=[],b=e.slice(0,10).reduce((S,K)=>{let j=K.pressure;if(r){let te=wn(1,K.distance/n),en=wn(1,1-te);j=wn(1,S+(en-S)*(te*Ws))}return(S+j)/2},e[0].pressure),w=_s(n,o,e[e.length-1].pressure,s),I,M=e[0].vector,v=e[0].point,T=v,F=v,C=T,R=!1;for(let S=0;S<e.length;S++){let{pressure:K}=e[S],{point:j,vector:te,distance:en,runningLength:ot}=e[S];if(S<e.length-1&&f-ot<3)continue;if(o){if(r){let ge=wn(1,en/n),nn=wn(1,1-ge);K=wn(1,b+(nn-b)*(ge*Ws))}w=_s(n,o,K,s)}else w=n/2;I===void 0&&(I=w);let gn=ot<E?u(ot/E):1,Go=f-ot<h?m((f-ot)/h):1;w=Math.max(.01,w*Math.min(gn,Go));let pi=(S<e.length-1?e[S+1]:e[S]).vector,zn=S<e.length-1?Ys(te,pi):1,Oo=Ys(te,M)<0&&!R,mi=zn!==null&&zn<0;if(Oo||mi){let ge=qe(Vn(M),w);for(let nn=1/13,ve=0;ve<=1;ve+=nn)F=$n(We(j,ge),j,Zn*ve),x.push(F),C=$n(Ke(j,ge),j,Zn*-ve),y.push(C);v=F,T=C,mi&&(R=!0);continue}if(R=!1,S===e.length-1){let ge=qe(Vn(te),w);x.push(We(j,ge)),y.push(Ke(j,ge));continue}let tn=qe(Vn(Uo(pi,te,zn)),w);F=We(j,tn),(S<=1||Xs(v,F)>g)&&(x.push(F),v=F),C=Ke(j,tn),(S<=1||Xs(T,C)>g)&&(y.push(C),T=C),b=K,M=te}let L=e[0].point.slice(0,2),W=e.length>1?e[e.length-1].point.slice(0,2):Ke(e[0].point,[1,1]),N=[],ee=[];if(e.length===1){if(!(E||h)||c){let S=Us(L,js(Vn(We(L,W))),-(I||w)),K=[];for(let j=1/13,te=j;te<=1;te+=j)K.push($n(S,L,Zn*2*te));return K}}else{if(!(E||h&&e.length===1))if(d)for(let K=1/13,j=K;j<=1;j+=K){let te=$n(y[0],L,Zn*j);N.push(te)}else{let K=We(x[0],y[0]),j=qe(K,.5),te=qe(K,.51);N.push(We(L,j),We(L,te),Ke(L,te),Ke(L,j))}let S=Vn(Ud(e[e.length-1].vector));if(h||E&&e.length===1)ee.push(W);else if(p){let K=Us(W,S,w);for(let j=1/29,te=j;te<1;te+=j)ee.push($n(K,W,Zn*3*te))}else ee.push(Ke(W,qe(S,w)),Ke(W,qe(S,w*.99)),We(W,qe(S,w*.99)),We(W,qe(S,w)))}return x.concat(ee,y.reverse(),N)}function Qd(e,t={}){var n;let{streamline:i=.5,size:o=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-i)*.85,a=Array.isArray(e[0])?e:e.map(({x:m,y:f,pressure:E=.5})=>[m,f,E]);if(a.length===2){let m=a[1];a=a.slice(0,-1);for(let f=1;f<5;f++)a.push(Uo(a[0],m,f/4))}a.length===1&&(a=[...a,[...Ke(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],c=!1,d=0,u=l[0],p=a.length-1;for(let m=1;m<a.length;m++){let f=r&&m===p?a[m].slice(0,2):Uo(u.point,a[m],s);if(jd(u.point,f))continue;let E=Zd(f,u.point);if(d+=E,m<p&&!c){if(d<o)continue;c=!0}u={point:f,pressure:a[m][2]>=0?a[m][2]:.5,vector:js(We(u.point,f)),distance:E,runningLength:d},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function Vs(e,t={}){return Kd(Qd(e,t),t)}import{isRightAngleRads as Om}from"@excalidraw/math";import{BOUND_TEXT_PADDING as mo,DEFAULT_REDUCED_GLOBAL_ALPHA as km,ELEMENT_READY_TO_ERASE_OPACITY as Rm,FRAME_STYLE as fo,MIME_TYPES as zr,THEME as Al,distance as Qt,getFontString as Fm,isRTL as Nm,getVerticalOffset as zm}from"@excalidraw/common";P();import{pointFrom as xt,pointCenter as Jd,pointRotateRads as Ft,vectorFromPoint as Wo,vectorNormalize as $s,vectorSubtract as Zs,vectorAdd as Di,vectorScale as Li,pointFromVector as qs,clamp as Pe,isCloseTo as Ks}from"@excalidraw/math";var Ie=10,ax=(e,t,n,i,o,r,s,a)=>{let{width:l,height:c}=jo(e),d=i/l,u=o/c,p=(e.crop?.x??0)/d,m=(e.crop?.y??0)/u,f=Ft(xt(r,s),me(e,t),-e.angle);r=f[0],s=f[1];let E=e.width,h=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,y=g.width,b=e.scale[0]===-1,w=e.scale[1]===-1,I=s-e.y,M=r-e.x;n.includes("n")&&(h=Pe(e.height-I,Ie,w?c-m:e.height+m)),n.includes("s")&&(I=s-e.y-e.height,h=Pe(e.height+I,Ie,w?e.height+m:c-m)),n.includes("e")&&(M=r-e.x-e.width,E=Pe(e.width+M,Ie,b?e.width+p:l-p)),n.includes("w")&&(E=Pe(e.width-M,Ie,b?l-p:e.width+p));let v=C=>{C.height=h*u,C.width=E*d};v(g);let T=(C,R)=>{v(R),C.includes("n")&&(w||(R.y+=x-R.height)),C.includes("s")&&w&&(R.y+=x-R.height),C.includes("e")&&b&&(R.x+=y-R.width),C.includes("w")&&(b||(R.x+=y-R.width))};switch(n){case"n":{if(a){let C=p+e.width/2,R=l-p-e.width/2,L=Math.min(C,R)*2;E=Pe(h*a,Ie,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"s":{if(a){let C=p+e.width/2,R=l-p-e.width/2,L=Math.min(C,R)*2;E=Pe(h*a,Ie,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"w":{if(a){let C=m+e.height/2,R=c-m-e.height/2,L=Math.min(C,R)*2;h=Pe(E/a,Ie,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let C=m+e.height/2,R=c-m-e.height/2,L=Math.min(C,R)*2;h=Pe(E/a,Ie,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(M>-I){let C=w?c-m:m+e.height;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?p+e.width:l-p;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"nw":{if(a)if(M<I){let C=w?c-m:m+e.height;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?l-p:p+e.width;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"se":{if(a)if(M>I){let C=w?m+e.height:c-m;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?p+e.width:l-p;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"sw":{if(a)if(-M>I){let C=w?m+e.height:c-m;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?l-p:p+e.width;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}default:break}let F=eu(e,n,E,h,!!a);return Ks(g.width,g.naturalWidth)&&Ks(g.height,g.naturalHeight)&&(g=null),{x:F[0],y:F[1],width:E,height:h,crop:g}},eu=(e,t,n,i,o)=>{let[r,s,a,l]=Nt(e,e.width,e.height,!0),c=xt(r,s),d=xt(a,l),u=Jd(c,d),[p,m,f,E]=Nt(e,n,i,!0),h=f-p,g=E-m,x=[...c];if(["n","w","nw"].includes(t)&&(x=[d[0]-Math.abs(h),d[1]-Math.abs(g)]),t==="ne"){let v=[c[0],d[1]];x=[v[0],v[1]-Math.abs(g)]}if(t==="sw"){let v=[d[0],c[1]];x=[v[0]-Math.abs(h),v[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-h/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let y=e.angle,b=Ft(x,u,y),w=[x[0]+Math.abs(h)/2,x[1]+Math.abs(g)/2],I=Ft(w,u,y);x=Ft(b,I,-y);let M=[...x];return M[0]+=e.x-p,M[1]+=e.y-m,M},Qs=(e,t)=>{if(e.crop){let{width:n,height:i}=jo(e),[o,r,s,a,l,c]=H(e,t),d=Wo(Ft(xt(o,r),xt(l,c),e.angle)),u=Wo(Ft(xt(s,r),xt(l,c),e.angle)),p=$s(Zs(u,d)),m=Wo(Ft(xt(o,a),xt(l,c),e.angle)),f=Zs(m,d),E=$s(f),{cropX:h,cropY:g}=tu(e.crop,e.scale),x=Di(Di(d,Li(p,-h*n/e.crop.naturalWidth)),Li(E,-g*i/e.crop.naturalHeight)),y=qs(Di(Di(x,Li(p,n/2)),Li(E,i/2))),b=Ft(qs(x),y,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:i,crop:null}}return e},jo=e=>{if(e.crop){let t=e.width/(e.crop.width/e.crop.naturalWidth),n=e.height/(e.crop.height/e.crop.naturalHeight);return{width:t,height:n}}return{width:e.width,height:e.height}},tu=(e,t)=>{let n=e.x,i=e.y,o=t[0]===-1,r=t[1]===-1;return o&&(n=e.naturalWidth-Math.abs(n)-e.width),r&&(i=e.naturalHeight-Math.abs(i)-e.height),{cropX:n,cropY:i}},lx=(e,t=!1)=>{let n=e.crop;if(!n)return null;let i=e.scale[0]===-1,o=e.scale[1]===-1,r=n.x,s=n.y;if(i&&(r=n.naturalWidth-n.width-n.x),o&&(s=n.naturalHeight-n.height-n.y),t)return{x:r,y:s};let{width:a,height:l}=jo(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as Ka,pointFrom as B,pointRotateRads as Te,pointsEqual as Qa,pointDistance as Dn,vectorFromPoint as em,curveLength as tm,curvePointAtLength as nm}from"@excalidraw/math";import{DRAGGING_THRESHOLD as im,KEYS as Ln,shouldRotateWithDiscreteAngle as Ja,getGridPoint as el,invariant as At,tupleToCoors as vr,viewportCoordsToSceneCoords as om}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as tl,isPathALoop as rm}from"@excalidraw/element";P();import{KEYS as vp,arrayToMap as Ha,isBindingFallthroughEnabled as to,tupleToCoors as Dp,invariant as Lp,isDevEnv as Cp,isTestEnv as Bp}from"@excalidraw/common";import{lineSegment as Ye,pointFrom as k,pointRotateRads as ae,vectorFromPoint as $,pointDistanceSq as jt,clamp as Ra,pointDistance as ut,pointFromVector as An,vectorScale as vn,vectorNormalize as ri,vectorCross as _e,pointsEqual as Gp,lineSegmentIntersectionPoints as Fa,PRECISION as Op}from"@excalidraw/math";P();import{isTransparent as Uu}from"@excalidraw/common";import{curveIntersectLineSegment as ya,isPointWithinBounds as Yi,lineSegment as Xi,lineSegmentIntersectionPoints as ba,pointFrom as St,pointFromVector as Wu,pointRotateRads as lt,pointsEqual as ju,vectorFromPoint as Vu,vectorNormalize as $u,vectorScale as Zu}from"@excalidraw/math";import{ellipse as qu,ellipseSegmentInterceptPoints as Ku}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as nu,DEFAULT_PROPORTIONAL_RADIUS as Vo,LINE_CONFIRM_THRESHOLD as iu,ROUNDNESS as $o}from"@excalidraw/common";import{curve as wt,curveCatmullRomCubicApproxPoints as Js,curveOffsetPoints as ea,lineSegment as ze,pointDistance as ou,pointFrom as X,pointFromArray as ru,rectangle as su}from"@excalidraw/math";var qn=new WeakMap,Zo=(e,t)=>{let n=qn.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){qn.delete(e);return}return o.get(t)},qo=(e,t,n)=>{let i=qn.get(e);if(!i){qn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){qn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function Ci(e){let t=Zo(e,0);if(t)return t;let n=ta(e),i=[],o=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&ru(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");i.push(ze(X(e.x+l[0],e.y+l[1]),X(e.x+a.data[0],e.y+a.data[1])));continue;case"bcurveTo":if(!l)throw new Error("prevPoint is undefined");o.push(wt(X(e.x+l[0],e.y+l[1]),X(e.x+a.data[0],e.y+a.data[1]),X(e.x+a.data[2],e.y+a.data[3]),X(e.x+a.data[4],e.y+a.data[5])));continue;default:console.error("Unknown op type",a.op)}}let r=[i,o];return qo(e,r,0),r}function yn(e,t=0){let n=Zo(e,t);if(n)return n;let i=yt(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=su(X(e.x,e.y),X(e.x+e.width,e.y+e.height)),r=ze(X(o[0][0]+i,o[0][1]),X(o[1][0]-i,o[0][1])),s=ze(X(o[1][0],o[0][1]+i),X(o[1][0],o[1][1]-i)),a=ze(X(o[0][0]+i,o[1][1]),X(o[1][0]-i,o[1][1])),l=ze(X(o[0][0],o[1][1]-i),X(o[0][0],o[0][1]+i)),c=[wt(l[1],X(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),X(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),wt(r[1],X(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),X(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),wt(s[1],X(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),X(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),wt(a[0],X(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),X(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],d=t>0?c.map(m=>Js(ea(m,t))):[[c[0]],[c[1]],[c[2]],[c[3]]],p=[[ze(d[0][d[0].length-1][3],d[1][0][0]),ze(d[1][d[1].length-1][3],d[2][0][0]),ze(d[2][d[2].length-1][3],d[3][0][0]),ze(d[3][d[3].length-1][3],d[0][0][0])],d.flat()];return qo(e,p,t),p}function bn(e,t=0){let n=Zo(e,t);if(n)return n;let[i,o,r,s,a,l,c,d]=Bi(e),u=e.roundness?yt(Math.abs(i-c),e):(i-c)*.01,p=e.roundness?yt(Math.abs(s-o),e):(s-o)*.01,[m,f,E,h]=[X(e.x+i,e.y+o),X(e.x+r,e.y+s),X(e.x+a,e.y+l),X(e.x+c,e.y+d)],g=[wt(X(f[0]-u,f[1]-p),f,f,X(f[0]-u,f[1]+p)),wt(X(E[0]+u,E[1]-p),E,E,X(E[0]-u,E[1]-p)),wt(X(h[0]+u,h[1]+p),h,h,X(h[0]+u,h[1]-p)),wt(X(m[0]-u,m[1]+p),m,m,X(m[0]+u,m[1]+p))],x=t>0?g.map(w=>Js(ea(w,t))):[[g[0]],[g[1]],[g[2]],[g[3]]],b=[[ze(x[0][x[0].length-1][3],x[1][0][0]),ze(x[1][x[1].length-1][3],x[2][0][0]),ze(x[2][x[2].length-1][3],x[3][0][0]),ze(x[3][x[3].length-1][3],x[0][0][0])],x.flat()];return qo(e,b,t),b}var an=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return ou(n,i)<=iu/t}return!1},yt=(e,t)=>{if(t.roundness?.type===$o.PROPORTIONAL_RADIUS||t.roundness?.type===$o.LEGACY)return e*Vo;if(t.roundness?.type===$o.ADAPTIVE_RADIUS){let n=t.roundness?.value??nu,i=n/Vo;return e<=i?e*Vo:n}return 0};P();import{ROUNDNESS as Kn,assertNever as au}from"@excalidraw/common";import{pointsEqual as na}from"@excalidraw/math";var zt=e=>!!e&&e.type==="image"&&!!e.fileId,xe=e=>!!e&&e.type==="image",ia=e=>!!e&&e.type==="embeddable",Gi=e=>!!e&&e.type==="iframe",Oi=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),ne=e=>e!=null&&e.type==="text",ki=e=>e!=null&&e.type==="frame",oa=e=>e!=null&&e.type==="magicframe",V=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Se=e=>e!=null&&lu(e.type),lu=e=>e==="freedraw",U=e=>e!=null&&Ko(e.type),ln=e=>e!=null&&e.type==="line",_=e=>e!=null&&e.type==="arrow",G=e=>_(e)&&e.elbowed,wx=e=>_(e)&&!e.elbowed,cu=e=>_(e)&&!e.elbowed&&!e.roundness,du=e=>_(e)&&!e.elbowed&&e.roundness!==null,Ko=e=>e==="arrow"||e==="line",Qo=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&uu(e.type),uu=e=>e==="arrow",Le=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),ra=e=>e!=null&&(e.type==="rectangle"||e.type==="diamond"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),yx=e=>e!=null&&(e.type==="rectangle"||e.type==="image"||e.type==="text"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="freedraw"),pu=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||_(e)),bx=e=>{let t=e?.type;if(!t)return!1;switch(t){case"text":case"diamond":case"rectangle":case"iframe":case"embeddable":case"ellipse":case"arrow":case"freedraw":case"line":case"frame":case"magicframe":case"image":case"selection":return!0;default:return au(t,null),!1}},Jo=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",st=e=>pu(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),fe=e=>e!==null&&"containerId"in e&&e.containerId!==null&&ne(e),Px=e=>!!e.startBinding||!!e.endBinding,sa=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",aa=e=>e==="line"||e==="arrow"||e==="diamond",Ix=(e,t)=>!!((e===Kn.ADAPTIVE_RADIUS||e===Kn.LEGACY)&&sa(t.type)||e===Kn.PROPORTIONAL_RADIUS&&aa(t.type)),Sx=e=>aa(e.type)?{type:Kn.PROPORTIONAL_RADIUS}:sa(e.type)?{type:Kn.ADAPTIVE_RADIUS}:null,Qn=e=>Object.hasOwn(e,"fixedPoint")&&e.fixedPoint!=null,Mx=e=>Array.isArray(e)&&e.length===4&&typeof e[0]=="number"&&typeof e[1]=="number"&&typeof e[2]=="number"&&typeof e[3]=="number",Tx=e=>cu(e)?"sharpArrow":du(e)?"curvedArrow":G(e)?"elbowArrow":"line",Ax=e=>e.length>3&&na(e[0],e[e.length-1]),la=e=>e.length>3||e.length===3&&!na(e[0],e[e.length-1]);P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Bu,ARROW_LABEL_WIDTH_FRACTION as Gu,BOUND_TEXT_PADDING as at,DEFAULT_FONT_SIZE as Ou,TEXT_ALIGN as ha,VERTICAL_ALIGN as Ea,getFontString as _i,isProdEnv as ku,invariant as Ru}from"@excalidraw/common";P();var Jn={},ca=(e,t)=>{let n=Jn[e]||(Jn[e]={height:t});return n.height=t,n},da=e=>{Jn[e]&&delete Jn[e]},Lx=e=>Jn[e]?.height??null;P();import{BOUND_TEXT_PADDING as Fi,DEFAULT_FONT_SIZE as mu,DEFAULT_FONT_FAMILY as fu,getFontString as hu,isTestEnv as Eu,normalizeEOL as gu}from"@excalidraw/common";var Qe=(e,t,n)=>{let i=e.split(`
1
+ var ru=Object.create;var ra=Object.defineProperty;var su=Object.getOwnPropertyDescriptor;var au=Object.getOwnPropertyNames;var lu=Object.getPrototypeOf,du=Object.prototype.hasOwnProperty;var cu=(e,t)=>()=>(e&&(t=e(e=0)),t);var uu=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var mu=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of au(t))!du.call(e,o)&&o!==n&&ra(e,o,{get:()=>t[o],enumerable:!(i=su(t,o))||i.enumerable});return e};var pu=(e,t,n)=>(n=e!=null?ru(lu(e)):{},mu(t||!e||!e.__esModule?ra(n,"default",{value:e,enumerable:!0}):n,e));var v,P=cu(()=>{v={PROD:!0}});var ac=uu((RP,sc)=>{P();var rc="Expected a function",ic=NaN,Lh="[object Symbol]",Ch=/^\s+|\s+$/g,Gh=/^[-+]0x[0-9a-f]+$/i,Oh=/^0b[01]+$/i,kh=/^0o[0-7]+$/i,Fh=parseInt,Rh=typeof global=="object"&&global&&global.Object===Object&&global,Nh=typeof self=="object"&&self&&self.Object===Object&&self,zh=Rh||Nh||Function("return this")(),Hh=Object.prototype,_h=Hh.toString,Uh=Math.max,Wh=Math.min,Rs=function(){return zh.Date.now()};function jh(e,t,n){var i,o,r,s,a,l,d=0,c=!1,u=!1,m=!0;if(typeof e!="function")throw new TypeError(rc);t=oc(t)||0,qo(n)&&(c=!!n.leading,u="maxWait"in n,r=u?Uh(oc(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(I){var M=i,T=o;return i=o=void 0,d=I,s=e.apply(T,M),s}function f(I){return d=I,a=setTimeout(g,t),c?p(I):s}function h(I){var M=I-l,T=I-d,S=t-M;return u?Wh(S,r-T):S}function E(I){var M=I-l,T=I-d;return l===void 0||M>=t||M<0||u&&T>=r}function g(){var I=Rs();if(E(I))return x(I);a=setTimeout(g,h(I))}function x(I){return a=void 0,m&&i?p(I):(i=o=void 0,s)}function w(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function b(){return a===void 0?s:x(Rs())}function y(){var I=Rs(),M=E(I);if(i=arguments,o=this,l=I,M){if(a===void 0)return f(l);if(u)return a=setTimeout(g,t),p(l)}return a===void 0&&(a=setTimeout(g,t)),s}return y.cancel=w,y.flush=b,y}function Yh(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(rc);return qo(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),jh(e,t,{leading:i,maxWait:t,trailing:o})}function qo(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Xh(e){return!!e&&typeof e=="object"}function $h(e){return typeof e=="symbol"||Xh(e)&&_h.call(e)==Lh}function oc(e){if(typeof e=="number")return e;if($h(e))return ic;if(qo(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=qo(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Ch,"");var n=Oh.test(e);return n||kh.test(e)?Fh(e.slice(2),n?2:8):Gh.test(e)?ic:+e}sc.exports=Yh});P();import{toIterable as wg}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Vt,viewportCoordsToSceneCoords as Xo}from"@excalidraw/common";import{normalizeRadians as Nd,radiansBetweenAngles as ah,radiansDifference as lh}from"@excalidraw/math";import{pointsEqual as dh}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function mr(e,t,n){if(e&&e.length){let[i,o]=t,r=Math.PI/180*n,s=Math.cos(r),a=Math.sin(r);for(let l of e){let[d,c]=l;l[0]=(d-i)*s-(c-o)*a+i,l[1]=(d-i)*a+(c-o)*s+o}}}function hu(e,t,n){let i=[];e.forEach(o=>i.push(...o)),mr(i,t,n)}function Eu(e,t){return e[0]===t[0]&&e[1]===t[1]}function sa(e,t,n,i=1){let o=n,r=Math.max(t,.1),s=e[0]&&e[0][0]&&typeof e[0][0]=="number"?[e]:e,a=[0,0];if(o)for(let d of s)mr(d,a,o);let l=gu(s,r,i);if(o){for(let d of s)mr(d,a,-o);hu(l,a,-o)}return l}function gu(e,t,n){let i=[];for(let d of e){let c=[...d];Eu(c[0],c[c.length-1])||c.push([c[0][0],c[0][1]]),c.length>2&&i.push(c)}let o=[];t=Math.max(t,.1);let r=[];for(let d of i)for(let c=0;c<d.length-1;c++){let u=d[c],m=d[c+1];if(u[1]!==m[1]){let p=Math.min(u[1],m[1]);r.push({ymin:p,ymax:Math.max(u[1],m[1]),x:p===u[1]?u[0]:m[0],islope:(m[0]-u[0])/(m[1]-u[1])})}}if(r.sort((d,c)=>d.ymin<c.ymin?-1:d.ymin>c.ymin?1:d.x<c.x?-1:d.x>c.x?1:d.ymax===c.ymax?0:(d.ymax-c.ymax)/Math.abs(d.ymax-c.ymax)),!r.length)return o;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let d=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)d=u;r.splice(0,d+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(d=>!(d.edge.ymax<=a)),s.sort((d,c)=>d.edge.x===c.edge.x?0:(d.edge.x-c.edge.x)/Math.abs(d.edge.x-c.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let d=0;d<s.length;d=d+2){let c=d+1;if(c>=s.length)break;let u=s[d].edge,m=s[c].edge;o.push([[Math.round(u.x),a],[Math.round(m.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.edge.islope}),l++}return o}function xt(e,t){var n;let i=t.hachureAngle+90,o=t.hachureGap;o<0&&(o=t.strokeWidth*4),o=Math.max(o,.1);let r=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(r=o),sa(e,o,i,r||1)}var Qt=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=xt(t,n);return{type:"fillSketch",ops:this.renderLines(i,n)}}renderLines(t,n){let i=[];for(let o of t)i.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return i}};P();P();function Jt(e){let t=e[0],n=e[1];return Math.sqrt(Math.pow(t[0]-n[0],2)+Math.pow(t[1]-n[1],2))}var Yi=class extends Qt{fillPolygons(t,n){let i=n.hachureGap;i<0&&(i=n.strokeWidth*4),i=Math.max(i,.1);let o=Object.assign({},n,{hachureGap:i}),r=xt(t,o),s=Math.PI/180*n.hachureAngle,a=[],l=i*.5*Math.cos(s),d=i*.5*Math.sin(s);for(let[u,m]of r)Jt([u,m])&&a.push([[u[0]-l,u[1]+d],[...m]],[[u[0]+l,u[1]-d],[...m]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var Xi=class extends Qt{fillPolygons(t,n){let i=this._fillPolygons(t,n),o=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),r=this._fillPolygons(t,o);return i.ops=i.ops.concat(r.ops),i}};P();var $i=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=xt(t,n);return this.dotsOnLines(i,n)}dotsOnLines(t,n){let i=[],o=n.hachureGap;o<0&&(o=n.strokeWidth*4),o=Math.max(o,.1);let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let s=o/4;for(let a of t){let l=Jt(a),d=l/o,c=Math.ceil(d)-1,u=l-c*o,m=(a[0][0]+a[1][0])/2-o/4,p=Math.min(a[0][1],a[1][1]);for(let f=0;f<c;f++){let h=p+u+f*o,E=m-s+Math.random()*2*s,g=h-s+Math.random()*2*s,x=this.helper.ellipse(E,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var Vi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=xt(t,n);return{type:"fillSketch",ops:this.dashedLine(i,n)}}dashedLine(t,n){let i=n.dashOffset<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashOffset,o=n.dashGap<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashGap,r=[];return t.forEach(s=>{let a=Jt(s),l=Math.floor(a/(i+o)),d=(a+o-l*(i+o))/2,c=s[0],u=s[1];c[0]>u[0]&&(c=s[1],u=s[0]);let m=Math.atan((u[1]-c[1])/(u[0]-c[0]));for(let p=0;p<l;p++){let f=p*(i+o),h=f+i,E=[c[0]+f*Math.cos(m)+d*Math.cos(m),c[1]+f*Math.sin(m)+d*Math.sin(m)],g=[c[0]+h*Math.cos(m)+d*Math.cos(m),c[1]+h*Math.sin(m)+d*Math.sin(m)];r.push(...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],n))}}),r}};P();var Zi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,o=n.zigzagOffset<0?i:n.zigzagOffset;n=Object.assign({},n,{hachureGap:i+o});let r=xt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=Jt(r),a=Math.round(s/(2*n)),l=r[0],d=r[1];l[0]>d[0]&&(l=r[1],d=r[0]);let c=Math.atan((d[1]-l[1])/(d[0]-l[0]));for(let u=0;u<a;u++){let m=u*2*n,p=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),h=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],E=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],g=[h[0]+f*Math.cos(c+Math.PI/4),h[1]+f*Math.sin(c+Math.PI/4)];o.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],i),...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],i))}}),o}};var Fe={};function aa(e,t){let n=e.fillStyle||"hachure";if(!Fe[n])switch(n){case"zigzag":Fe[n]||(Fe[n]=new Yi(t));break;case"cross-hatch":Fe[n]||(Fe[n]=new Xi(t));break;case"dots":Fe[n]||(Fe[n]=new $i(t));break;case"dashed":Fe[n]||(Fe[n]=new Vi(t));break;case"zigzag-line":Fe[n]||(Fe[n]=new Zi(t));break;case"hachure":default:n="hachure",Fe[n]||(Fe[n]=new Qt(t));break}return Fe[n]}P();function la(){return Math.floor(Math.random()*2**31)}var qi=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};P();P();var Ki={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function xu(e){let t=new Array;for(;e!=="";)if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([aAcChHlLmMqQsStTvVzZ])/))t[t.length]={type:0,text:RegExp.$1},e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))t[t.length]={type:1,text:`${parseFloat(RegExp.$1)}`},e=e.substr(RegExp.$1.length);else return[];return t[t.length]={type:2,text:""},t}function pr(e,t){return e.type===t}function Un(e){let t=[],n=xu(e),i="BOD",o=0,r=n[o];for(;!pr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=Ki[r.text],i=r.text;else return Un("M0,0"+e);else pr(r,1)?s=Ki[i]:(o++,s=Ki[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(pr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof Ki[i]=="number"){let l={key:i,data:a};t.push(l),o+=s,r=n[o],i==="M"&&(i="L"),i==="m"&&(i="l")}else throw new Error("Bad segment: "+i)}else throw new Error("Path data ended short")}return t}P();function si(e){let t=0,n=0,i=0,o=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[i,o]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),i=t,o=n;break;case"L":r.push({key:"L",data:[...a]}),[t,n]=a;break;case"l":t+=a[0],n+=a[1],r.push({key:"L",data:[t,n]});break;case"C":r.push({key:"C",data:[...a]}),t=a[4],n=a[5];break;case"c":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":r.push({key:"Q",data:[...a]}),t=a[2],n=a[3];break;case"q":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":r.push({key:"A",data:[...a]}),t=a[5],n=a[6];break;case"a":t+=a[5],n+=a[6],r.push({key:"A",data:[a[0],a[1],a[2],a[3],a[4],t,n]});break;case"H":r.push({key:"H",data:[...a]}),t=a[0];break;case"h":t+=a[0],r.push({key:"H",data:[t]});break;case"V":r.push({key:"V",data:[...a]}),n=a[0];break;case"v":n+=a[0],r.push({key:"V",data:[n]});break;case"S":r.push({key:"S",data:[...a]}),t=a[2],n=a[3];break;case"s":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=i,n=o;break}return r}P();function li(e){let t=[],n="",i=0,o=0,r=0,s=0,a=0,l=0;for(let{key:d,data:c}of e){switch(d){case"M":t.push({key:"M",data:[...c]}),[i,o]=c,[r,s]=c;break;case"C":t.push({key:"C",data:[...c]}),i=c[4],o=c[5],a=c[2],l=c[3];break;case"L":t.push({key:"L",data:[...c]}),[i,o]=c;break;case"H":i=c[0],t.push({key:"L",data:[i,o]});break;case"V":o=c[0],t.push({key:"L",data:[i,o]});break;case"S":{let u=0,m=0;n==="C"||n==="S"?(u=i+(i-a),m=o+(o-l)):(u=i,m=o),t.push({key:"C",data:[u,m,...c]}),a=c[0],l=c[1],i=c[2],o=c[3];break}case"T":{let[u,m]=c,p=0,f=0;n==="Q"||n==="T"?(p=i+(i-a),f=o+(o-l)):(p=i,f=o);let h=i+2*(p-i)/3,E=o+2*(f-o)/3,g=u+2*(p-u)/3,x=m+2*(f-m)/3;t.push({key:"C",data:[h,E,g,x,u,m]}),a=p,l=f,i=u,o=m;break}case"Q":{let[u,m,p,f]=c,h=i+2*(u-i)/3,E=o+2*(m-o)/3,g=p+2*(u-p)/3,x=f+2*(m-f)/3;t.push({key:"C",data:[h,E,g,x,p,f]}),a=u,l=m,i=p,o=f;break}case"A":{let u=Math.abs(c[0]),m=Math.abs(c[1]),p=c[2],f=c[3],h=c[4],E=c[5],g=c[6];u===0||m===0?(t.push({key:"C",data:[i,o,E,g,E,g]}),i=E,o=g):(i!==E||o!==g)&&(da(i,o,E,g,u,m,p,f,h).forEach(function(w){t.push({key:"C",data:w})}),i=E,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function wu(e){return Math.PI*e/180}function ai(e,t,n){let i=e*Math.cos(n)-t*Math.sin(n),o=e*Math.sin(n)+t*Math.cos(n);return[i,o]}function da(e,t,n,i,o,r,s,a,l,d){let c=wu(s),u=[],m=0,p=0,f=0,h=0;if(d)[m,p,f,h]=d;else{[e,t]=ai(e,t,-c),[n,i]=ai(n,i,-c);let k=(e-n)/2,C=(t-i)/2,X=k*k/(o*o)+C*C/(r*r);X>1&&(X=Math.sqrt(X),o=X*o,r=X*r);let _=a===l?-1:1,oe=o*o,F=r*r,A=oe*F-oe*C*C-F*k*k,z=oe*C*C+F*k*k,W=_*Math.sqrt(Math.abs(A/z));f=W*o*C/r+(e+n)/2,h=W*-r*k/o+(t+i)/2,m=Math.asin(parseFloat(((t-h)/r).toFixed(9))),p=Math.asin(parseFloat(((i-h)/r).toFixed(9))),e<f&&(m=Math.PI-m),n<f&&(p=Math.PI-p),m<0&&(m=Math.PI*2+m),p<0&&(p=Math.PI*2+p),l&&m>p&&(m=m-Math.PI*2),!l&&p>m&&(p=p-Math.PI*2)}let E=p-m;if(Math.abs(E)>Math.PI*120/180){let k=p,C=n,X=i;l&&p>m?p=m+Math.PI*120/180*1:p=m+Math.PI*120/180*-1,n=f+o*Math.cos(p),i=h+r*Math.sin(p),u=da(n,i,C,X,o,r,s,0,l,[p,k,f,h])}E=p-m;let g=Math.cos(m),x=Math.sin(m),w=Math.cos(p),b=Math.sin(p),y=Math.tan(E/4),I=4/3*o*y,M=4/3*r*y,T=[e,t],S=[e+I*x,t-M*g],B=[n+I*b,i-M*w],L=[n,i];if(S[0]=2*T[0]-S[0],S[1]=2*T[1]-S[1],d)return[S,B,L].concat(u);{u=[S,B,L].concat(u);let k=[];for(let C=0;C<u.length;C+=3){let X=ai(u[C][0],u[C][1],c),_=ai(u[C+1][0],u[C+1][1],c),oe=ai(u[C+2][0],u[C+2][1],c);k.push([X[0],X[1],_[0],_[1],oe[0],oe[1]])}return k}}var bu={randOffset:Iu,randOffsetWithRange:Su,ellipse:Pu,doubleLineOps:Au};function fr(e,t,n,i,o){return{type:"path",ops:Bt(e,t,n,i,o)}}function di(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Bt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Bt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return fr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function yu(e,t){return di(e,!0,t)}function fa(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return yu(r,o)}function hr(e,t){let n=ua(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=ua(e,1.5*(1+t.roughness*.22),Mu(t));n=n.concat(i)}return{type:"path",ops:n}}function Pu(e,t,n,i,o){let r=Er(n,i,o);return eo(e,t,o,r).opset}function Er(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=R(s*l,n),a+=R(a*l,n),{increment:r,rx:s,ry:a}}function eo(e,t,n,i){let[o,r]=ma(i.increment,e,t,i.rx,i.ry,1,i.increment*Qi(.1,Qi(.4,1,n),n),n),s=Ji(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=ma(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Ji(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function gr(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),m=Math.abs(i/2);u+=R(u*.01,l),m+=R(m*.01,l);let p=o,f=r;for(;p<0;)p+=Math.PI*2,f+=Math.PI*2;f-p>Math.PI*2&&(p=0,f=Math.PI*2);let h=Math.PI*2/l.curveStepCount,E=Math.min(h/2,(f-p)/2),g=pa(E,d,c,u,m,p,f,1,l);if(!l.disableMultiStroke){let x=pa(E,d,c,u,m,p,f,1.5,l);g.push(...x)}return s&&(a?g.push(...Bt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...Bt(d,c,d+u*Math.cos(f),c+m*Math.sin(f),l)):g.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(p),c+m*Math.sin(p)]})),{type:"path",ops:g}}function xr(e,t){let n=li(si(Un(e))),i=[],o=[0,0],r=[0,0];for(let{key:s,data:a}of n)switch(s){case"M":{r=[a[0],a[1]],o=[a[0],a[1]];break}case"L":i.push(...Bt(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,d,c,u,m,p]=a;i.push(...Tu(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...Bt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function to(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+R(o,t),i[0][1]+R(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+R(o,t),i[s][1]+R(o,t)]})}}return{type:"fillPath",ops:n}}function Tn(e,t){return aa(t,bu).fillPolygons(e,t)}function ha(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=R(d*.01,s),c+=R(c*.01,s);let u=o,m=r;for(;u<0;)u+=Math.PI*2,m+=Math.PI*2;m-u>Math.PI*2&&(u=0,m=Math.PI*2);let p=(m-u)/s.curveStepCount,f=[];for(let h=u;h<=m;h=h+p)f.push([a+d*Math.cos(h),l+c*Math.sin(h)]);return f.push([a+d*Math.cos(m),l+c*Math.sin(m)]),f.push([a,l]),Tn([f],s)}function Iu(e,t){return R(e,t)}function Su(e,t,n){return Qi(e,t,n)}function Au(e,t,n,i,o){return Bt(e,t,n,i,o,!0)}function Mu(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Ea(e){return e.randomizer||(e.randomizer=new qi(e.seed||0)),e.randomizer.next()}function Qi(e,t,n,i=1){return n.roughness*i*(Ea(n)*(t-e)+e)}function R(e,t,n=1){return Qi(-e,e,t,n)}function Bt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=ca(e,t,n,i,o,!0,!1);if(s)return a;let l=ca(e,t,n,i,o,!0,!0);return a.concat(l)}function ca(e,t,n,i,o,r,s){let a=Math.pow(e-n,2)+Math.pow(t-i,2),l=Math.sqrt(a),d=1;l<200?d=1:l>500?d=.4:d=-.0016668*l+1.233334;let c=o.maxRandomnessOffset||0;c*c*100>a&&(c=l/10);let u=c/2,m=.2+Ea(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,f=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=R(p,o,d),f=R(f,o,d);let h=[],E=()=>R(u,o,d),g=()=>R(c,o,d),x=o.preserveVertices;return r&&(s?h.push({op:"move",data:[e+(x?0:E()),t+(x?0:E())]}):h.push({op:"move",data:[e+(x?0:R(c,o,d)),t+(x?0:R(c,o,d))]})),s?h.push({op:"bcurveTo",data:[p+e+(n-e)*m+E(),f+t+(i-t)*m+E(),p+e+2*(n-e)*m+E(),f+t+2*(i-t)*m+E(),n+(x?0:E()),i+(x?0:E())]}):h.push({op:"bcurveTo",data:[p+e+(n-e)*m+g(),f+t+(i-t)*m+g(),p+e+2*(n-e)*m+g(),f+t+2*(i-t)*m+g(),n+(x?0:g()),i+(x?0:g())]}),h}function ua(e,t,n){let i=[];i.push([e[0][0]+R(t,n),e[0][1]+R(t,n)]),i.push([e[0][0]+R(t,n),e[0][1]+R(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+R(t,n),e[o][1]+R(t,n)]),o===e.length-1&&i.push([e[o][0]+R(t,n),e[o][1]+R(t,n)]);return Ji(i,null,n)}function Ji(e,t,n){let i=e.length,o=[];if(i>3){let r=[],s=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<i;a++){let l=e[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*e[a+1][0]-s*e[a-1][0])/6,l[1]+(s*e[a+1][1]-s*e[a-1][1])/6],r[2]=[e[a+1][0]+(s*e[a][0]-s*e[a+2][0])/6,e[a+1][1]+(s*e[a][1]-s*e[a+2][1])/6],r[3]=[e[a+1][0],e[a+1][1]],o.push({op:"bcurveTo",data:[r[1][0],r[1][1],r[2][0],r[2][1],r[3][0],r[3][1]]})}if(t&&t.length===2){let a=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+R(a,n),t[1]+R(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...Bt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function ma(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let m=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(m),c.push(m)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=R(.5,a)-Math.PI/2;c.push([R(r,a)+t+.9*i*Math.cos(u-e),R(r,a)+n+.9*o*Math.sin(u-e)]);let m=Math.PI*2+u-.01;for(let p=u;p<m;p=p+e){let f=[R(r,a)+t+i*Math.cos(p),R(r,a)+n+o*Math.sin(p)];d.push(f),c.push(f)}c.push([R(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),R(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([R(r,a)+t+.98*i*Math.cos(u+s),R(r,a)+n+.98*o*Math.sin(u+s)]),c.push([R(r,a)+t+.9*i*Math.cos(u+s*.5),R(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function pa(e,t,n,i,o,r,s,a,l){let d=r+R(.1,l),c=[];c.push([R(a,l)+t+.9*i*Math.cos(d-e),R(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([R(a,l)+t+i*Math.cos(u),R(a,l)+n+o*Math.sin(u)]);return c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),Ji(c,null,l)}function Tu(e,t,n,i,o,r,s,a){let l=[],d=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],c=[0,0],u=a.disableMultiStroke?1:2,m=a.preserveVertices;for(let p=0;p<u;p++)p===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(m?0:R(d[0],a)),s[1]+(m?0:R(d[0],a))]}),c=m?[o,r]:[o+R(d[p],a),r+R(d[p],a)],l.push({op:"bcurveTo",data:[e+R(d[p],a),t+R(d[p],a),n+R(d[p],a),i+R(d[p],a),c[0],c[1]]});return l}P();function ci(e){return[...e]}function ga(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let i=[];if(n===3)i.push(ci(e[0]),ci(e[1]),ci(e[2]),ci(e[2]));else{let o=[];o.push(e[0],e[0]);for(let a=1;a<e.length;a++)o.push(e[a]),a===e.length-1&&o.push(e[a]);let r=[],s=1-t;i.push(ci(o[0]));for(let a=1;a+2<o.length;a++){let l=o[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*o[a+1][0]-s*o[a-1][0])/6,l[1]+(s*o[a+1][1]-s*o[a-1][1])/6],r[2]=[o[a+1][0]+(s*o[a][0]-s*o[a+2][0])/6,o[a+1][1]+(s*o[a][1]-s*o[a+2][1])/6],r[3]=[o[a+1][0],o[a+1][1]],i.push(r[1],r[2],r[3])}}return i}P();function vu(e,t){return Math.sqrt(no(e,t))}function no(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Du(e,t,n){let i=no(t,n);if(i===0)return no(e,t);let o=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i;return o=Math.max(0,Math.min(1,o)),no(e,vn(t,n,o))}function vn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Bu(e,t){let n=e[t+0],i=e[t+1],o=e[t+2],r=e[t+3],s=3*i[0]-2*n[0]-r[0];s*=s;let a=3*i[1]-2*n[1]-r[1];a*=a;let l=3*o[0]-2*r[0]-n[0];l*=l;let d=3*o[1]-2*r[1]-n[1];return d*=d,s<l&&(s=l),a<d&&(a=d),s+a}function wr(e,t,n,i){let o=i||[];if(Bu(e,t)<n){let r=e[t+0];o.length?vu(o[o.length-1],r)>1&&o.push(r):o.push(r),o.push(e[t+3])}else{let s=e[t+0],a=e[t+1],l=e[t+2],d=e[t+3],c=vn(s,a,.5),u=vn(a,l,.5),m=vn(l,d,.5),p=vn(c,u,.5),f=vn(u,m,.5),h=vn(p,f,.5);wr([s,c,p,h],0,n,o),wr([h,f,m,d],0,n,o)}return o}function ui(e,t){return io(e,0,e.length,t)}function io(e,t,n,i,o){let r=o||[],s=e[t],a=e[n-1],l=0,d=1;for(let c=t+1;c<n-1;++c){let u=Du(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(io(e,t,d+1,i,r),io(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function Lt(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;wr(e,s,t,i)}return n&&n>0?io(i,0,i.length,n):i}P();function xa(e,t,n){let i=Un(e),o=li(si(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Lt(l,t)),l=[]},c=()=>{d(),s.length&&(r.push(s),s=[])};for(let{key:m,data:p}of o)switch(m){case"M":c(),a=[p[0],p[1]],s.push(a);break;case"L":d(),s.push([p[0],p[1]]);break;case"C":if(!l.length){let f=s.length?s[s.length-1]:a;l.push([f[0],f[1]])}l.push([p[0],p[1]]),l.push([p[2],p[3]]),l.push([p[4],p[5]]);break;case"Z":d(),s.push([a[0],a[1]]);break}if(c(),!n)return r;let u=[];for(let m of r){let p=ui(m,n);p.length&&u.push(p)}return u}var Xe="none",et=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return la()}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,i){return{shape:t,sets:n||[],options:i||this.defaultOptions}}line(t,n,i,o,r){let s=this._o(r);return this._d("line",[fr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=fa(t,n,i,o,s);if(s.fill){let d=[[t,n],[t+i,n],[t+i,n+o],[t,n+o]];s.fillStyle==="solid"?a.push(to([d],s)):a.push(Tn([d],s))}return s.stroke!==Xe&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=Er(i,o,s),d=eo(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=eo(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(Tn([d.estimatedPoints],s));return s.stroke!==Xe&&a.push(d.opset),this._d("ellipse",a,s)}circle(t,n,i,o){let r=this.ellipse(t,n,i,i,o);return r.shape="circle",r}linearPath(t,n){let i=this._o(n);return this._d("linearPath",[di(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=gr(t,n,i,o,r,s,a,!0,d);if(a&&d.fill)if(d.fillStyle==="solid"){let m=Object.assign({},d);m.disableMultiStroke=!0;let p=gr(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(ha(t,n,i,o,r,s,d));return d.stroke!==Xe&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=hr(t,i);if(i.fill&&i.fill!==Xe&&t.length>=3)if(i.fillStyle==="solid"){let s=hr(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(s.ops)})}else{let s=ga(t),a=Lt(s,10,(1+i.roughness)/2);o.push(Tn([a],i))}return i.stroke!==Xe&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=di(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(to([t],i)):o.push(Tn([t],i))),i.stroke!==Xe&&o.push(r),this._d("polygon",o,i)}path(t,n){let i=this._o(n),o=[];if(!t)return this._d("path",o,i);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=i.fill&&i.fill!=="transparent"&&i.fill!==Xe,s=i.stroke!==Xe,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=xa(t,1,l),c=xr(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=xr(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else o.push(to(d,i));else o.push(Tn(d,i));return s&&(a?d.forEach(u=>{o.push(di(u,!1,i))}):o.push(c)),this._d("path",o,i)}opsToPath(t,n){let i="";for(let o of t.ops){let r=typeof n=="number"&&n>=0?o.data.map(s=>+s.toFixed(n)):o.data;switch(o.op){case"move":i+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":i+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":i+=`L${r[0]} ${r[1]} `;break}}return i.trim()}toPaths(t){let n=t.sets||[],i=t.options||this.defaultOptions,o=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:Xe};break;case"fillPath":s={d:this.opsToPath(r),stroke:Xe,strokeWidth:0,fill:i.fill||Xe};break;case"fillSketch":s=this.fillSketch(r,i);break}s&&o.push(s)}return o}fillSketch(t,n){let i=n.fillWeight;return i<0&&(i=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||Xe,strokeWidth:i,fill:Xe}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var oo=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new et(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":o.save(),o.strokeStyle=i.stroke==="none"?"transparent":i.stroke,o.lineWidth=i.strokeWidth,i.strokeLineDash&&o.setLineDash(i.strokeLineDash),i.strokeLineDashOffset&&(o.lineDashOffset=i.strokeLineDashOffset),this._drawToContext(o,s,r),o.restore();break;case"fillPath":{o.save(),o.fillStyle=i.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,s,r,a),o.restore();break}case"fillSketch":this.fillSketch(o,s,i);break}}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2),t.save(),i.fillLineDash&&t.setLineDash(i.fillLineDash),i.fillLineDashOffset&&(t.lineDashOffset=i.fillLineDashOffset),t.strokeStyle=i.fill||"",t.lineWidth=o,this._drawToContext(t,n,i.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,i,o="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof i=="number"&&i>=0?r.data.map(a=>+a.toFixed(i)):r.data;switch(r.op){case"move":t.moveTo(s[0],s[1]);break;case"bcurveTo":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"lineTo":t.lineTo(s[0],s[1]);break}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s),s}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s),s}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s),s}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r),r}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i),i}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i),i}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d),d}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i),i}path(t,n){let i=this.gen.path(t,n);return this.draw(i),i}};P();P();var mi="http://www.w3.org/2000/svg";var ro=class{constructor(t,n){this.svg=t,this.gen=new et(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(mi,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(mi,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke",i.stroke),l.setAttribute("stroke-width",i.strokeWidth+""),l.setAttribute("fill","none"),i.strokeLineDash&&l.setAttribute("stroke-dasharray",i.strokeLineDash.join(" ").trim()),i.strokeLineDashOffset&&l.setAttribute("stroke-dashoffset",`${i.strokeLineDashOffset}`);break}case"fillPath":{l=o.createElementNS(mi,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke","none"),l.setAttribute("stroke-width","0"),l.setAttribute("fill",i.fill||""),(t.shape==="curve"||t.shape==="polygon")&&l.setAttribute("fill-rule","evenodd");break}case"fillSketch":{l=this.fillSketch(o,a,i);break}}l&&r.appendChild(l)}return r}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2);let r=t.createElementNS(mi,"path");return r.setAttribute("d",this.opsToPath(n,i.fixedDecimalPlaceDigits)),r.setAttribute("stroke",i.fill||""),r.setAttribute("stroke-width",o+""),r.setAttribute("fill","none"),i.fillLineDash&&r.setAttribute("stroke-dasharray",i.fillLineDash.join(" ").trim()),i.fillLineDashOffset&&r.setAttribute("stroke-dashoffset",`${i.fillLineDashOffset}`),r}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,n){return this.gen.opsToPath(t,n)}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s)}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s)}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s)}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r)}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i)}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i)}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d)}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i)}path(t,n){let i=this.gen.path(t,n);return this.draw(i)}};var Dn={canvas(e,t){return new oo(e,t)},svg(e,t){return new ro(e,t)},generator(e){return new et(e)},newSeed(){return et.newSeed()}};import{arrayToMap as Fd,invariant as Is,rescalePoints as Ld,sizeOf as Zf}from"@excalidraw/common";import{degreesToRadians as Ps,lineSegment as xe,pointDistance as qf,pointFrom as D,pointFromArray as Rd,pointRotateRads as re}from"@excalidraw/math";P();import{invariant as Lu}from"@excalidraw/common";import{curve as Cu,lineSegment as Gu,pointFrom as le,pointDistance as iw,pointFromArray as Ou,pointFromVector as ku,pointRotateRads as st,polygon as wa,polygonFromPoints as br,PRECISION as ow,segmentsIntersectAt as rw,vector as Fu,vectorAdd as Ru,vectorFromPoint as Nu,vectorScale as sw}from"@excalidraw/math";import{getElementAbsoluteCoords as lw}from"@excalidraw/element";var ba=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=le(s,a),d;return e.type==="diamond"?d=wa(st(le(s,r),l,t),st(le(o+n,a),l,t),st(le(s,r+i),l,t),st(le(o,a),l,t)):d=wa(st(le(o,r),l,t),st(le(o+n,r),l,t),st(le(o+n,r+i),l,t),st(le(o,r+i),l,t)),{type:"polygon",data:d}};var ya=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:le(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},Ct=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},Pa=(e,t=le(0,0),n,i)=>{let o=l=>st(le(l[0]+t[0],l[1]+t[1]),i,n),r=Ct(e),s=[],a=le(0,0);for(let l of r){if(l.op==="move"){let d=Ou(l.data);Lu(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(le(l.data[0],l.data[1])),c=o(le(l.data[2],l.data[3])),u=o(le(l.data[4],l.data[5]));s.push(Cu(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},zu=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Gu(t,o)),t=o}return n},Ia=(e,t,n=!1)=>{let i=r=>st(ku(Ru(Nu(r),Fu(e.x,e.y))),t,e.angle),o=zu(e.points.map(r=>i(r)));return n?{type:"polygon",data:br(o.flat())}:{type:"polyline",data:o}},Sa=(e,t,n=le(0,0),i,o)=>{let r=c=>st(le(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:br(e.points.map(c=>r(c)))};let s=Ct(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(le(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(le(c.data[0],c.data[1])),a.push(le(c.data[2],c.data[3])),a.push(le(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(le(c.data[0],c.data[1]));let d=Lt(a,10,5).map(c=>r(c));return{type:"polygon",data:br(d)}};P();P();function Aa(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function Hu(e){return[-e[0],-e[1]]}function lt(e,t){return[e[0]+t[0],e[1]+t[1]]}function tt(e,t){return[e[0]-t[0],e[1]-t[1]]}function at(e,t){return[e[0]*t,e[1]*t]}function _u(e,t){return[e[0]/t,e[1]/t]}function pi(e){return[e[1],-e[0]]}function Ma(e,t){return e[0]*t[0]+e[1]*t[1]}function Uu(e,t){return e[0]===t[0]&&e[1]===t[1]}function Wu(e){return Math.hypot(e[0],e[1])}function ju(e){return e[0]*e[0]+e[1]*e[1]}function Ta(e,t){return ju(tt(e,t))}function Ba(e){return _u(e,Wu(e))}function Yu(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function fi(e,t,n){let i=Math.sin(n),o=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*o-s*i,l=r*i+s*o;return[a+t[0],l+t[1]]}function yr(e,t,n){return lt(e,at(tt(t,e),n))}function va(e,t,n){return lt(e,at(t,n))}var{min:Wn,PI:Xu}=Math,Da=.275,hi=Xu+1e-4;function $u(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=F=>F,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=F=>F*(2-F)}=a,{cap:m=!0,easing:p=F=>--F*F*F+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,h=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,E=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*i,2),x=[],w=[],b=e.slice(0,10).reduce((F,A)=>{let z=A.pressure;if(r){let W=Wn(1,A.distance/n),we=Wn(1,1-W);z=Wn(1,F+(we-F)*(W*Da))}return(F+z)/2},e[0].pressure),y=Aa(n,o,e[e.length-1].pressure,s),I,M=e[0].vector,T=e[0].point,S=T,B=T,L=S,k=!1;for(let F=0;F<e.length;F++){let{pressure:A}=e[F],{point:z,vector:W,distance:we,runningLength:gt}=e[F];if(F<e.length-1&&f-gt<3)continue;if(o){if(r){let Ye=Wn(1,we/n),Je=Wn(1,1-Ye);A=Wn(1,b+(Je-b)*(Ye*Da))}y=Aa(n,o,A,s)}else y=n/2;I===void 0&&(I=y);let _i=gt<h?u(gt/h):1,cr=f-gt<E?p((f-gt)/E):1;y=Math.max(.01,y*Math.min(_i,cr));let Ui=(F<e.length-1?e[F+1]:e[F]).vector,ri=F<e.length-1?Ma(W,Ui):1,ur=Ma(W,M)<0&&!k,Wi=ri!==null&&ri<0;if(ur||Wi){let Ye=at(pi(M),y);for(let Je=1/13,Kt=0;Kt<=1;Kt+=Je)B=fi(tt(z,Ye),z,hi*Kt),x.push(B),L=fi(lt(z,Ye),z,hi*-Kt),w.push(L);T=B,S=L,Wi&&(k=!0);continue}if(k=!1,F===e.length-1){let Ye=at(pi(W),y);x.push(tt(z,Ye)),w.push(lt(z,Ye));continue}let ji=at(pi(yr(Ui,W,ri)),y);B=tt(z,ji),(F<=1||Ta(T,B)>g)&&(x.push(B),T=B),L=lt(z,ji),(F<=1||Ta(S,L)>g)&&(w.push(L),S=L),b=A,M=W}let C=e[0].point.slice(0,2),X=e.length>1?e[e.length-1].point.slice(0,2):lt(e[0].point,[1,1]),_=[],oe=[];if(e.length===1){if(!(h||E)||d){let F=va(C,Ba(pi(tt(C,X))),-(I||y)),A=[];for(let z=1/13,W=z;W<=1;W+=z)A.push(fi(F,C,hi*2*W));return A}}else{if(!(h||E&&e.length===1))if(c)for(let A=1/13,z=A;z<=1;z+=A){let W=fi(w[0],C,hi*z);_.push(W)}else{let A=tt(x[0],w[0]),z=at(A,.5),W=at(A,.51);_.push(tt(C,z),tt(C,W),lt(C,W),lt(C,z))}let F=pi(Hu(e[e.length-1].vector));if(E||h&&e.length===1)oe.push(X);else if(m){let A=va(X,F,y);for(let z=1/29,W=z;W<1;W+=z)oe.push(fi(A,X,hi*3*W))}else oe.push(lt(X,at(F,y)),lt(X,at(F,y*.99)),tt(X,at(F,y*.99)),tt(X,at(F,y)))}return x.concat(oe,w.reverse(),_)}function Vu(e,t={}){var n;let{streamline:i=.5,size:o=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-i)*.85,a=Array.isArray(e[0])?e:e.map(({x:p,y:f,pressure:h=.5})=>[p,f,h]);if(a.length===2){let p=a[1];a=a.slice(0,-1);for(let f=1;f<5;f++)a.push(yr(a[0],p,f/4))}a.length===1&&(a=[...a,[...lt(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=!1,c=0,u=l[0],m=a.length-1;for(let p=1;p<a.length;p++){let f=r&&p===m?a[p].slice(0,2):yr(u.point,a[p],s);if(Uu(u.point,f))continue;let h=Yu(f,u.point);if(c+=h,p<m&&!d){if(c<o)continue;d=!0}u={point:f,pressure:a[p][2]>=0?a[p][2]:.5,vector:Ba(tt(u.point,f)),distance:h,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function La(e,t={}){return $u(Vu(e,t),t)}import{pointFrom as de,pointDistance as Sd,pointRotateRads as Xt}from"@excalidraw/math";import{ROUGHNESS as Nf,THEME as ys,isTransparent as ki,assertNever as zf,COLOR_PALETTE as Hf,LINE_POLYGON_POINT_MERGE_DISTANCE as _f,applyDarkModeFilter as Fi}from"@excalidraw/common";P();import{isRightAngleRads as Af,lineSegment as xd,pointFrom as Ho,pointRotateRads as gs}from"@excalidraw/math";import{BOUND_TEXT_PADDING as _o,DEFAULT_REDUCED_GLOBAL_ALPHA as Mf,ELEMENT_READY_TO_ERASE_OPACITY as Tf,FRAME_STYLE as Ci,DARK_THEME_FILTER as vf,MIME_TYPES as ws,THEME as Kn,distance as wn,getFontString as Df,isRTL as Bf,getVerticalOffset as Lf,invariant as Cf,applyDarkModeFilter as Wo,isSafari as Gf}from"@excalidraw/common";P();import{pointFrom as Gt,pointCenter as Zu,pointRotateRads as en,vectorFromPoint as Pr,vectorNormalize as Ca,vectorSubtract as Ga,vectorAdd as so,vectorScale as ao,pointFromVector as Oa,clamp as Ie,isCloseTo as ka}from"@excalidraw/math";var Se=10,hw=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=Ir(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,f=en(Gt(r,s),ne(e,t),-e.angle);r=f[0],s=f[1];let h=e.width,E=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,w=g.width,b=e.scale[0]===-1,y=e.scale[1]===-1,I=s-e.y,M=r-e.x;n.includes("n")&&(E=Ie(e.height-I,Se,y?d-p:e.height+p)),n.includes("s")&&(I=s-e.y-e.height,E=Ie(e.height+I,Se,y?e.height+p:d-p)),n.includes("e")&&(M=r-e.x-e.width,h=Ie(e.width+M,Se,b?e.width+m:l-m)),n.includes("w")&&(h=Ie(e.width-M,Se,b?l-m:e.width+m));let T=L=>{L.height=E*u,L.width=h*c};T(g);let S=(L,k)=>{T(k),L.includes("n")&&(y||(k.y+=x-k.height)),L.includes("s")&&y&&(k.y+=x-k.height),L.includes("e")&&b&&(k.x+=w-k.width),L.includes("w")&&(b||(k.x+=w-k.width))};switch(n){case"n":{if(a){let L=m+e.width/2,k=l-m-e.width/2,C=Math.min(L,k)*2;h=Ie(E*a,Se,C),E=h/a}S(n,g),a&&(g.x+=(w-g.width)/2);break}case"s":{if(a){let L=m+e.width/2,k=l-m-e.width/2,C=Math.min(L,k)*2;h=Ie(E*a,Se,C),E=h/a}S(n,g),a&&(g.x+=(w-g.width)/2);break}case"w":{if(a){let L=p+e.height/2,k=d-p-e.height/2,C=Math.min(L,k)*2;E=Ie(h/a,Se,C),h=E*a}S(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let L=p+e.height/2,k=d-p-e.height/2,C=Math.min(L,k)*2;E=Ie(h/a,Se,C),h=E*a}S(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(M>-I){let L=y?d-p:p+e.height;E=Ie(h/a,Se,L),h=E*a}else{let L=b?m+e.width:l-m;h=Ie(E*a,Se,L),E=h/a}S(n,g);break}case"nw":{if(a)if(M<I){let L=y?d-p:p+e.height;E=Ie(h/a,Se,L),h=E*a}else{let L=b?l-m:m+e.width;h=Ie(E*a,Se,L),E=h/a}S(n,g);break}case"se":{if(a)if(M>I){let L=y?p+e.height:d-p;E=Ie(h/a,Se,L),h=E*a}else{let L=b?m+e.width:l-m;h=Ie(E*a,Se,L),E=h/a}S(n,g);break}case"sw":{if(a)if(-M>I){let L=y?p+e.height:d-p;E=Ie(h/a,Se,L),h=E*a}else{let L=b?l-m:m+e.width;h=Ie(E*a,Se,L),E=h/a}S(n,g);break}default:break}let B=qu(e,n,h,E,!!a);return ka(g.width,g.naturalWidth)&&ka(g.height,g.naturalHeight)&&(g=null),{x:B[0],y:B[1],width:h,height:E,crop:g}},qu=(e,t,n,i,o)=>{let[r,s,a,l]=tn(e,e.width,e.height,!0),d=Gt(r,s),c=Gt(a,l),u=Zu(d,c),[m,p,f,h]=tn(e,n,i,!0),E=f-m,g=h-p,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(E),c[1]-Math.abs(g)]),t==="ne"){let T=[d[0],c[1]];x=[T[0],T[1]-Math.abs(g)]}if(t==="sw"){let T=[c[0],d[1]];x=[T[0]-Math.abs(E),T[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-E/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let w=e.angle,b=en(x,u,w),y=[x[0]+Math.abs(E)/2,x[1]+Math.abs(g)/2],I=en(y,u,w);x=en(b,I,-w);let M=[...x];return M[0]+=e.x-m,M[1]+=e.y-p,M},Fa=(e,t)=>{if(e.crop){let{width:n,height:i}=Ir(e),[o,r,s,a,l,d]=$(e,t),c=Pr(en(Gt(o,r),Gt(l,d),e.angle)),u=Pr(en(Gt(s,r),Gt(l,d),e.angle)),m=Ca(Ga(u,c)),p=Pr(en(Gt(o,a),Gt(l,d),e.angle)),f=Ga(p,c),h=Ca(f),{cropX:E,cropY:g}=Ku(e.crop,e.scale),x=so(so(c,ao(m,-E*n/e.crop.naturalWidth)),ao(h,-g*i/e.crop.naturalHeight)),w=Oa(so(so(x,ao(m,n/2)),ao(h,i/2))),b=en(Oa(x),w,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:i,crop:null}}return e},Ir=e=>{if(e.crop){let t=e.width/(e.crop.width/e.crop.naturalWidth),n=e.height/(e.crop.height/e.crop.naturalHeight);return{width:t,height:n}}return{width:e.width,height:e.height}},Ku=(e,t)=>{let n=e.x,i=e.y,o=t[0]===-1,r=t[1]===-1;return o&&(n=e.naturalWidth-Math.abs(n)-e.width),r&&(i=e.naturalHeight-Math.abs(i)-e.height),{cropX:n,cropY:i}},Ew=(e,t=!1)=>{let n=e.crop;if(!n)return null;let i=e.scale[0]===-1,o=e.scale[1]===-1,r=n.x,s=n.y;if(i&&(r=n.naturalWidth-n.width-n.x),o&&(s=n.naturalHeight-n.height-n.y),t)return{x:r,y:s};let{width:a,height:l}=Ir(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as Wl,pointFrom as O,pointRotateRads as Ce,pointsEqual as jl,pointDistance as Rn,vectorFromPoint as qp,curveLength as Kp,curvePointAtLength as Qp}from"@excalidraw/math";import{DRAGGING_THRESHOLD as Jp,KEYS as Fn,shouldRotateWithDiscreteAngle as Bi,getGridPoint as Yl,invariant as Ue,isShallowEqual as ef,getFeatureFlag as Zn}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as Xl,getSnapOutlineMidPoint as $l,isPathALoop as tf,moveArrowAboveBindable as Vl,projectFixedPointOntoDiagonal as Zl}from"@excalidraw/element";P();import{arrayToMap as Fl,getFeatureFlag as Bp,invariant as ot,isTransparent as Lp}from"@excalidraw/common";import{PRECISION as Cp,clamp as rs,lineSegment as Go,pointDistance as mn,pointDistanceSq as jt,pointFrom as te,pointFromVector as Lo,pointRotateRads as ae,pointsEqual as Gp,vectorFromPoint as Ti,vectorNormalize as os,vectorScale as Co}from"@excalidraw/math";P();import{invariant as ul,isTransparent as ml}from"@excalidraw/common";import{curveIntersectLineSegment as pl,isPointWithinBounds as Ur,lineSegment as Ii,lineSegmentIntersectionPoints as fl,pointFrom as he,pointFromVector as qm,pointRotateRads as Ze,pointsEqual as hl,vectorFromPoint as Km,vectorNormalize as Qm,vectorScale as Jm}from"@excalidraw/math";import{ellipse as ep,ellipseSegmentInterceptPoints as tp}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as rm,DEFAULT_PROPORTIONAL_RADIUS as Ar,invariant as sm,LINE_CONFIRM_THRESHOLD as am,ROUNDNESS as Mr}from"@excalidraw/common";import{bezierEquation as lm,curve as kt,curveCatmullRomCubicApproxPoints as Xa,curveOffsetPoints as $a,lineSegment as ge,lineSegmentIntersectionPoints as ja,pointDistance as Ln,pointFrom as N,pointFromArray as dm,pointFromVector as cm,pointRotateRads as $e,pointTranslate as Ya,rectangle as um,vectorFromPoint as Va,vectorNormalize as mm,vectorScale as Tr}from"@excalidraw/math";P();import{ROUNDNESS as Ei,assertNever as Qu}from"@excalidraw/common";import{pointsEqual as Ra}from"@excalidraw/math";var Bn=e=>!!e&&e.type==="image"&&!!e.fileId,be=e=>!!e&&e.type==="image",Na=e=>!!e&&e.type==="embeddable",lo=e=>!!e&&e.type==="iframe",co=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),q=e=>e!=null&&e.type==="text",uo=e=>e!=null&&e.type==="frame",za=e=>e!=null&&e.type==="magicframe",Z=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Ee=e=>e!=null&&Ju(e.type),Ju=e=>e==="freedraw",K=e=>e!=null&&nm(e.type),Ot=e=>e!=null&&e.type==="line",H=e=>e!=null&&e.type==="arrow",U=e=>H(e)&&e.elbowed,yw=e=>H(e)&&!e.elbowed,em=e=>H(e)&&!e.elbowed&&!e.roundness,tm=e=>H(e)&&!e.elbowed&&e.roundness!==null,nm=e=>e==="arrow"||e==="line",Ae=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&im(e.type),im=e=>e==="arrow",ce=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),Ha=e=>e!=null&&(e.type==="rectangle"||e.type==="diamond"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),gi=e=>e!=null&&(e.type==="rectangle"||e.type==="image"||e.type==="text"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="freedraw"),om=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||H(e)),Pw=e=>{let t=e?.type;if(!t)return!1;switch(t){case"text":case"diamond":case"rectangle":case"iframe":case"embeddable":case"ellipse":case"arrow":case"freedraw":case"line":case"frame":case"magicframe":case"image":case"selection":return!0;default:return Qu(t,null),!1}},Sr=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",wt=e=>om(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),ue=e=>e!==null&&"containerId"in e&&e.containerId!==null&&q(e),Iw=e=>!!e.startBinding||!!e.endBinding,_a=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",Ua=e=>e==="line"||e==="arrow"||e==="diamond",Sw=(e,t)=>!!((e===Ei.ADAPTIVE_RADIUS||e===Ei.LEGACY)&&_a(t.type)||e===Ei.PROPORTIONAL_RADIUS&&Ua(t.type)),Aw=e=>Ua(e.type)?{type:Ei.PROPORTIONAL_RADIUS}:_a(e.type)?{type:Ei.ADAPTIVE_RADIUS}:null,Mw=e=>em(e)?"sharpArrow":tm(e)?"curvedArrow":U(e)?"elbowArrow":"line",Tw=e=>e.length>3&&Ra(e[0],e[e.length-1]),Wa=e=>e.length>3||e.length===3&&!Ra(e[0],e[e.length-1]);var xi=new WeakMap,vr=(e,t)=>{let n=xi.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){xi.delete(e);return}return o.get(t)},Dr=(e,t,n)=>{let i=xi.get(e);if(!i){xi.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){xi.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function mo(e,t){let n=vr(e,0);if(n)return n;let i=qa(e,t),o=[],r=[];for(let a=0;a<i.length;a+=1){let l=i[a],d=i[a-1]&&dm(i[a-1].data.slice(-2));switch(l.op){case"move":continue;case"lineTo":if(!d)throw new Error("prevPoint is undefined");o.push(ge(N(e.x+d[0],e.y+d[1]),N(e.x+l.data[0],e.y+l.data[1])));continue;case"bcurveTo":if(!d)throw new Error("prevPoint is undefined");r.push(kt(N(e.x+d[0],e.y+d[1]),N(e.x+l.data[0],e.y+l.data[1]),N(e.x+l.data[2],e.y+l.data[3]),N(e.x+l.data[4],e.y+l.data[5])));continue;default:console.error("Unknown op type",l.op)}}let s=[o,r];return Dr(e,s,0),s}function nn(e,t=0){let n=vr(e,t);if(n)return n;let i=Ft(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=um(N(e.x,e.y),N(e.x+e.width,e.y+e.height)),r=ge(N(o[0][0]+i,o[0][1]),N(o[1][0]-i,o[0][1])),s=ge(N(o[1][0],o[0][1]+i),N(o[1][0],o[1][1]-i)),a=ge(N(o[0][0]+i,o[1][1]),N(o[1][0]-i,o[1][1])),l=ge(N(o[0][0],o[1][1]-i),N(o[0][0],o[0][1]+i)),d=[kt(l[1],N(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),N(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),kt(r[1],N(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),N(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),kt(s[1],N(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),N(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),kt(a[0],N(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),N(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],c=t>0?d.map(p=>Xa($a(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[ge(c[0][c[0].length-1][3],c[1][0][0]),ge(c[1][c[1].length-1][3],c[2][0][0]),ge(c[2][c[2].length-1][3],c[3][0][0]),ge(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Dr(e,m,t),m}function Za(e,t=0){let[n,i,o,r,s,a,l,d]=jn(e),c=e.roundness?Ft(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?Ft(Math.abs(r-i),e):(r-i)*.01,[m,p,f,h]=[N(e.x+n,e.y+i),N(e.x+o,e.y+r),N(e.x+s,e.y+a),N(e.x+l,e.y+d)];return[kt(N(p[0]-c,p[1]-u),p,p,N(p[0]-c,p[1]+u)),kt(N(f[0]+c,f[1]-u),f,f,N(f[0]-c,f[1]-u)),kt(N(h[0]+c,h[1]+u),h,h,N(h[0]+c,h[1]-u)),kt(N(m[0]-c,m[1]+u),m,m,N(m[0]+c,m[1]+u))]}function on(e,t=0){let n=vr(e,t);if(n)return n;let o=Za(e,t).map(a=>Xa($a(a,t))),s=[[ge(o[0][o[0].length-1][3],o[1][0][0]),ge(o[1][o[1].length-1][3],o[2][0][0]),ge(o[2][o[2].length-1][3],o[3][0][0]),ge(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return Dr(e,s,t),s}var Cn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return Ln(n,i)<=am/t}return!1},Ft=(e,t)=>{if(t.roundness?.type===Mr.PROPORTIONAL_RADIUS||t.roundness?.type===Mr.LEGACY)return e*Ar;if(t.roundness?.type===Mr.ADAPTIVE_RADIUS){let n=t.roundness?.value??rm,i=n/Ar;return e<=i?e*Ar:n}return 0},pm=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=mm(Va(a[1],a[0])),d=Tr(l,n);return ge(Ya(a[0],d),Ya(a[1],Tr(d,-1)))},o=ne(e,t),r=i(gi(e)?ge($e(N(e.x,e.y),o,e.angle),$e(N(e.x+e.width,e.y+e.height),o,e.angle)):ge($e(N(e.x+e.width/2,e.y),o,e.angle),$e(N(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(gi(e)?ge($e(N(e.x+e.width,e.y),o,e.angle),$e(N(e.x,e.y+e.height),o,e.angle)):ge($e(N(e.x,e.y+e.height/2),o,e.angle),$e(N(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},fm=(e,t,n,i)=>{let o=ne(t,n);return(t.type==="diamond"?Za(t).map(a=>{let l=lm(a,.5),d=$e(l,o,t.angle);return N(d[0],d[1])}):[$e(N(t.x+t.width,t.y+t.height/2),o,t.angle),$e(N(t.x+t.width/2,t.y+t.height),o,t.angle),$e(N(t.x,t.y+t.height/2),o,t.angle),$e(N(t.x+t.width/2,t.y),o,t.angle)]).find(a=>Ln(e,a)<=dt(i)+t.strokeWidth/2&&!bt({point:e,element:t,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))},Br=(e,t,n,i,o,r,s=!0)=>{if(sm(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;if(s){let g=fm(t,n,o,r);if(g)return g}let[a,l]=pm(n,o),d=G.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o);if(e.points.length===2){let g=i==="start"?e.endBinding:e.startBinding,x=g&&o.get(g.elementId),w=g&&x&&Re(rn(g.fixedPoint),x,o);w&&(d=w)}let c=cm(Tr(Va(t,d),2*Ln(d,t)+Math.max(Ln(a[0],a[1]),Ln(l[0],l[1]))),d),u=ge(c,d),m=ja(a,u),p=ja(l,u),f=m&&Ln(d,m),h=p&&Ln(d,p),E=null;return f!=null&&h!=null?E=f<h?m:p:E=m||p||null,E&&Rt(E,n,o)?E:null};P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Rm,ARROW_LABEL_WIDTH_FRACTION as Nm,BOUND_TEXT_PADDING as yt,DEFAULT_FONT_SIZE as zm,TEXT_ALIGN as il,VERTICAL_ALIGN as ol,getFontString as xo,isProdEnv as Hm,invariant as _m}from"@excalidraw/common";import{pointFrom as rl,pointRotateRads as Um}from"@excalidraw/math";P();var wi={},Ka=(e,t)=>{let n=wi[e]||(wi[e]={height:t});return n.height=t,n},Qa=e=>{wi[e]&&delete wi[e]},_w=e=>wi[e]?.height??null;P();import{BOUND_TEXT_PADDING as fo,DEFAULT_FONT_SIZE as hm,DEFAULT_FONT_FAMILY as Em,getFontString as gm,isTestEnv as xm,normalizeEOL as wm}from"@excalidraw/common";var Ve=(e,t,n)=>{let i=e.split(`
2
2
  `).map(a=>a||" ").join(`
3
- `),o=parseFloat(t),r=xu(i,o,n);return{width:fa(i,t),height:r}},ua="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),pa=(e,t)=>{let n=wu(e);return n===0?Qe(ua.split("").join(`
4
- `),e,t).width+Fi*2:n+Fi*2},Ni=(e,t)=>Qe("",e,t).width+Fi*2,Ox=()=>fa(ua,hu({fontSize:mu,fontFamily:fu}))>0,tr=e=>gu(e).replace(/\t/g," "),nr=e=>tr(e).split(`
5
- `),kx=e=>{let t=nr(e.text).length;return e.height/t/e.fontSize},zi=(e,t)=>e*t,ma=(e,t)=>zi(e,t)+Fi*2,Ri,Rx=e=>{Ri=e},er=class{canvas;constructor(){this.canvas=document.createElement("canvas")}getLineWidth(t,n){let i=this.canvas.getContext("2d");i.font=n;let r=i.measureText(t).width;return Eu()?r*10:r}},Ht=(e,t)=>(Ri||(Ri=new er),Ri.getLineWidth(e,t)),fa=(e,t)=>{let n=nr(e),i=0;return n.forEach(o=>{i=Math.max(i,Ht(o,t))}),i},xu=(e,t,n)=>{let i=nr(e).length;return zi(t,n)*i},Pn=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=Ht(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),Fx=e=>{let t=Pn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},wu=e=>{let t=Pn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as yu,isTestEnv as bu}from"@excalidraw/common";var ir,Hi,or,Yx=e=>(ir||(ir=Q.class(...Object.values(bt))),ir.test(e)),Pu=()=>{if(!Hi)try{Hi=Su()}catch{Hi=Iu()}return Hi},rr=()=>(or||(or=Mu()),or),je={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},bt={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},cn={FLAG:/\p{RI}\p{RI}/u,JOINER:/(?:\p{Emoji_Modifier}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?/u,ZWJ:/\u200D/u,ANY:/[\p{Emoji}]/u,MOST:/[\p{Extended_Pictographic}\p{Emoji_Presentation}]/u},Iu=()=>Q.or(rr(),de.On(je.HYPHEN,je.WHITESPACE,bt.CHAR)),Su=()=>Q.or(rr(),de.Before(je.WHITESPACE).Build(),de.After(je.WHITESPACE,je.HYPHEN).Build(),de.Before(bt.CHAR,bt.CURRENCY).NotPrecededBy(je.OPENING,bt.OPENING).Build(),de.After(bt.CHAR).NotFollowedBy(je.HYPHEN,je.CLOSING,bt.CLOSING).Build(),de.BeforeMany(bt.OPENING).NotPrecededBy(je.OPENING).Build(),de.AfterMany(bt.CLOSING).NotFollowedBy(je.CLOSING).Build(),de.AfterMany(je.CLOSING).FollowedBy(je.OPENING).Build()),Mu=()=>Q.group(Q.or(cn.FLAG,Q.and(cn.MOST,cn.JOINER,Q.build(`(?:${cn.ZWJ.source}(?:${cn.FLAG.source}|${cn.ANY.source}${cn.JOINER.source}))*`)))),Q={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>Q.build(Q.join(...e)),or:(...e)=>Q.build(e.map(t=>t.source).join("|")),group:(...e)=>Q.build(`(${Q.join(...e)})`),class:(...e)=>Q.build(`[${Q.join(...e)}]`)},de={On:(...e)=>{let t=Q.join(...e);return Q.build(`([${t}])`)},Before:(...e)=>{let t=Q.join(...e),n=()=>Q.build(`(?=[${t}])`);return de.Chain(n)},After:(...e)=>{let t=Q.join(...e),n=()=>Q.build(`(?<=[${t}])`);return de.Chain(n)},BeforeMany:(...e)=>{let t=Q.join(...e),n=()=>Q.build(`(?<![${t}])(?=[${t}])`);return de.Chain(n)},AfterMany:(...e)=>{let t=Q.join(...e),n=()=>Q.build(`(?<=[${t}])(?![${t}])`);return de.Chain(n)},NotBefore:(...e)=>{let t=Q.join(...e),n=()=>Q.build(`(?![${t}])`);return de.Chain(n)},NotAfter:(...e)=>{let t=Q.join(...e),n=()=>Q.build(`(?<![${t}])`);return de.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=de.After(...t).Build(),o=()=>Q.and(i,n);return de.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=de.Before(...t).Build(),o=()=>Q.and(n,i);return de.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=de.NotAfter(...t).Build(),o=()=>Q.and(i,n);return de.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=de.NotBefore(...t).Build(),o=()=>Q.and(n,i);return de.Chain(o)}})},Tu=e=>{let t=Pu();return e.normalize("NFC").split(t).filter(Boolean)},Pt=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return e;let i=[],o=e.split(`
6
- `);for(let r of o){if(Ht(r,t)<=n){i.push(r);continue}let a=Au(r,t,n);i.push(...a)}return i.join(`
7
- `)},Au=(e,t,n)=>{let i=[],r=Tu(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let c=l.value,d=s+c,u=Lu(c)?a+Pn.calculate(c,t):Ht(d,t);if(/\s/.test(c)||u<=n){s=d,a=u,l=r.next();continue}if(s)i.push(s.trimEnd()),s="",a=0;else{let p=vu(c,t,n),m=p[p.length-1]??"",f=p.slice(0,-1);i.push(...f),s=m,a=Ht(m,t),l=r.next()}}if(s){let c=Du(s,t,n);i.push(c)}return i},vu=(e,t,n)=>{if(rr().test(e))return[e];Cu(e);let i=[],o=Array.from(e),r="",s=0;for(let a of o){let l=Pn.calculate(a,t),c=s+l;if(c<=n){r=r+a,s=c;continue}r&&i.push(r),r=a,s=l}return r&&i.push(r),i},Du=(e,t,n)=>{if(!(Ht(e,t)>n))return e;let[,o,r]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],s=Ht(o,t);for(let a of Array.from(r)){let l=Pn.calculate(a,t),c=s+l;if(c>n)break;o=o+a,s=c}return o},Lu=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Cu=e=>{if((bu()||yu())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var ga=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;ku()||Ru(!t||!_(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?_(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?Je(t,e):e.width,r.text=Pt(e.originalText,_i(e),o));let s=Qe(r.text,_i(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=ei(t,e),l=Je(t,e);if(!_(t)&&s.height>a){let p=sr(s.height,t.type);n.mutateElement(t,{height:p}),ca(t.id,p)}if(s.width>l){let p=sr(s.width,t.type);n.mutateElement(t,{width:p})}let c={...e,...r},{x:d,y:u}=xa(t,c,i);r.x=d,r.y=u}n.mutateElement(e,r)},dn=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!It(e))return;da(e.id);let s=Z(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,c=s.width,d=Je(e,s),u=ei(e,s),p=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=Pt(s.originalText,_i(s),d));let m=Qe(a,_i(s),s.lineHeight);l=m.height,c=m.width}if(l>u){p=sr(l,e.type);let m=p-e.height,f=!_(e)&&(n==="ne"||n==="nw"||n==="n")?e.y-m:e.y;t.mutateElement(e,{height:p,y:f})}t.mutateElement(s,{text:a,width:c,height:l}),_(e)||t.mutateElement(s,xa(e,s,o))}},xa=(e,t,n)=>{if(_(e))return Y.getBoundTextElementPosition(e,t,n);let i=ar(e),o=ei(e,t),r=Je(e,t),s,a;return t.verticalAlign===Ea.TOP?a=i.y:t.verticalAlign===Ea.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===ha.LEFT?s=i.x:t.textAlign===ha.RIGHT?s=i.x+(r-t.width):s=i.x+(r/2-t.width/2),{x:s,y:a}},It=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,Z=(e,t)=>{if(!e)return null;let n=It(e);return n&&t.get(n)||null},Ce=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,Kx=(e,t,n)=>{if(!_(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(Y.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=Y.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=Y.getEditorMidPoints(e,n,t)[o];return r||(r=Y.getSegmentMidPoint(e,o+1)),{x:r[0],y:r[1]}},ar=e=>{let t=at,n=at;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},Qx=(e,t)=>_(t)?0:t?t.angle:e.angle,Jx=(e,t,n)=>{if(_(e))return Y.getBoundTextElementPosition(e,t,n)},ew=(e,t)=>e.some(n=>{if(fe(n)){let i=Ce(n,t);return!_(i)}return!1}),tw=(e,t)=>e.some(n=>{if(fe(n)){let i=Ce(n,t);return!_(i)}return ne(n)}),Fu=new Set(["rectangle","ellipse","diamond","arrow"]),nw=e=>Fu.has(e.type),sr=(e,t)=>{e=Math.ceil(e);let n=at*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},Je=(e,t)=>{let{width:n}=e;if(_(e)){let i=(t?.fontSize??Ou)*Bu;return Math.max(Gu*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-at*2:e.type==="diamond"?Math.round(n/2)-at*2:n-at*2},ei=(e,t)=>{let{height:n}=e;return _(e)?n-at*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-at*2:e.type==="diamond"?Math.round(n/2)-at*2:n-at*2},iw=(e,t=`
3
+ `),o=parseFloat(t),r=bm(i,o,n);return{width:nl(i,t),height:r}},Ja="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),el=(e,t)=>{let n=ym(e);return n===0?Ve(Ja.split("").join(`
4
+ `),e,t).width+fo*2:n+fo*2},ho=(e,t)=>Ve("",e,t).width+fo*2,Yw=()=>nl(Ja,gm({fontSize:hm,fontFamily:Em}))>0,bi=e=>wm(e).replace(/\t/g," "),Cr=e=>bi(e).split(`
5
+ `),Xw=e=>{let t=Cr(e.text).length;return e.height/t/e.fontSize},Eo=(e,t)=>e*t,tl=(e,t)=>Eo(e,t)+fo*2,po,$w=e=>{po=e},Lr=class{canvas;constructor(){this.canvas=document.createElement("canvas")}getLineWidth(t,n){let i=this.canvas.getContext("2d");i.font=n;let r=i.measureText(t).width;return xm()?r*10:r}},sn=(e,t)=>(po||(po=new Lr),po.getLineWidth(e,t)),nl=(e,t)=>{let n=Cr(e),i=0;return n.forEach(o=>{i=Math.max(i,sn(o,t))}),i},bm=(e,t,n)=>{let i=Cr(e).length;return Eo(t,n)*i},Yn=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=sn(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),Vw=e=>{let t=Yn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},ym=e=>{let t=Yn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as Pm,isTestEnv as Im}from"@excalidraw/common";var Gr,go,Or,Jw=e=>(Gr||(Gr=J.class(...Object.values(Nt))),Gr.test(e)),Sm=()=>{if(!go)try{go=Mm()}catch{go=Am()}return go},kr=()=>(Or||(Or=Tm()),Or),nt={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},Nt={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},Gn={FLAG:/\p{RI}\p{RI}/u,JOINER:/(?:\p{Emoji_Modifier}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?/u,ZWJ:/\u200D/u,ANY:/[\p{Emoji}]/u,MOST:/[\p{Extended_Pictographic}\p{Emoji_Presentation}]/u},Am=()=>J.or(kr(),me.On(nt.HYPHEN,nt.WHITESPACE,Nt.CHAR)),Mm=()=>J.or(kr(),me.Before(nt.WHITESPACE).Build(),me.After(nt.WHITESPACE,nt.HYPHEN).Build(),me.Before(Nt.CHAR,Nt.CURRENCY).NotPrecededBy(nt.OPENING,Nt.OPENING).Build(),me.After(Nt.CHAR).NotFollowedBy(nt.HYPHEN,nt.CLOSING,Nt.CLOSING).Build(),me.BeforeMany(Nt.OPENING).NotPrecededBy(nt.OPENING).Build(),me.AfterMany(Nt.CLOSING).NotFollowedBy(nt.CLOSING).Build(),me.AfterMany(nt.CLOSING).FollowedBy(nt.OPENING).Build()),Tm=()=>J.group(J.or(Gn.FLAG,J.and(Gn.MOST,Gn.JOINER,J.build(`(?:${Gn.ZWJ.source}(?:${Gn.FLAG.source}|${Gn.ANY.source}${Gn.JOINER.source}))*`)))),J={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>J.build(J.join(...e)),or:(...e)=>J.build(e.map(t=>t.source).join("|")),group:(...e)=>J.build(`(${J.join(...e)})`),class:(...e)=>J.build(`[${J.join(...e)}]`)},me={On:(...e)=>{let t=J.join(...e);return J.build(`([${t}])`)},Before:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?=[${t}])`);return me.Chain(n)},After:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<=[${t}])`);return me.Chain(n)},BeforeMany:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<![${t}])(?=[${t}])`);return me.Chain(n)},AfterMany:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<=[${t}])(?![${t}])`);return me.Chain(n)},NotBefore:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?![${t}])`);return me.Chain(n)},NotAfter:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<![${t}])`);return me.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=me.After(...t).Build(),o=()=>J.and(i,n);return me.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=me.Before(...t).Build(),o=()=>J.and(n,i);return me.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=me.NotAfter(...t).Build(),o=()=>J.and(i,n);return me.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=me.NotBefore(...t).Build(),o=()=>J.and(n,i);return me.Chain(o)}})},vm=e=>{let t=Sm();return e.normalize("NFC").split(t).filter(Boolean)},zt=(e,t,n)=>Bm(e,t,n).map(i=>i.text).join(`
6
+ `),Dm=e=>{let t=0;return e.split(`
7
+ `).map(n=>{let i=t,o=i+n.length;return t=o+1,{text:n,start:i,end:o}})},Bm=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return Dm(e);let i=[],o=0;for(let r of e.split(`
8
+ `))sn(r,t)<=n?i.push({text:r,start:o,end:o+r.length}):i.push(...Lm(r,t,n,o)),o+=r.length+1;return i},Lm=(e,t,n,i)=>{let o=[],r=vm(e),s="",a=i,l=i,d=0,c=i,u=0;for(;u<r.length;){let m=r[u],p=c,f=p+m.length,h=s+m,E=km(m)?d+Yn.calculate(m,t):sn(h,t);if(/\s/.test(m)||E<=n){s||(a=p),s=h,l=f,d=E,c=f,u++;continue}if(s)o.push(Om(s,a,l)),s="",a=p,l=p,d=0;else{let g=Cm(m,t,n,p),x=g[g.length-1]??{text:"",start:p,end:p},w=g.slice(0,-1);o.push(...w),s=x.text,a=x.start,l=x.end,d=sn(x.text,t),c=f,u++}}if(s){let m=Gm(s,a,l,t,n);o.push(m)}return o},Cm=(e,t,n,i)=>{if(kr().test(e))return[{text:e,start:i,end:i+e.length}];Fm(e);let o=[],r=Array.from(e),s="",a=i,l=i,d=0,c=i;for(let u of r){let m=c,p=m+u.length,f=Yn.calculate(u,t),h=d+f;if(h<=n){s||(a=m),s=s+u,l=p,d=h,c=p;continue}s&&o.push({text:s,start:a,end:l}),s=u,a=m,l=p,d=f,c=p}return s&&o.push({text:s,start:a,end:l}),o},Gm=(e,t,n,i,o)=>{if(!(sn(e,i)>o))return{text:e,start:t,end:n};let[,s,a]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],l=sn(s,i);for(let d of Array.from(a)){let c=Yn.calculate(d,i),u=l+c;if(u>o)break;s=s+d,l=u}return{text:s,start:t,end:n-(e.length-s.length)}},Om=(e,t,n)=>{let i=e.trimEnd();return{text:i,start:t,end:n-(e.length-i.length)}},km=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Fm=e=>{if((Im()||Pm())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var wo=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;Hm()||_m(!t||!H(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?H(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?ct(t,e):e.width,r.text=zt(e.originalText,xo(e),o));let s=Ve(r.text,xo(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=Pi(t,e),l=ct(t,e);if(!H(t)&&s.height>a){let m=Fr(s.height,t.type);n.mutateElement(t,{height:m}),Ka(t.id,m)}if(s.width>l){let m=Fr(s.width,t.type);n.mutateElement(t,{width:m})}let d={...e,...r},{x:c,y:u}=yi(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},On=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!Ht(e))return;Qa(e.id);let s=V(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=ct(e,s),u=Pi(e,s),m=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=zt(s.originalText,xo(s),c));let p=Ve(a,xo(s),s.lineHeight);l=p.height,d=p.width}if(l>u){m=Fr(l,e.type);let p=m-e.height,f=!H(e)&&(n==="ne"||n==="nw"||n==="n")?e.y-p:e.y;t.mutateElement(e,{height:m,y:f})}t.mutateElement(s,{text:a,width:d,height:l}),H(e)||t.mutateElement(s,yi(e,s,o))}},yi=(e,t,n)=>{if(H(e))return G.getBoundTextElementPosition(e,t,n);let i=Rr(e),o=Pi(e,t),r=ct(e,t),s,a;t.verticalAlign===ol.TOP?a=i.y:t.verticalAlign===ol.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===il.LEFT?s=i.x:t.textAlign===il.RIGHT?s=i.x+(r-t.width):s=i.x+(r/2-t.width/2);let l=e.angle??0;if(l!==0){let d=rl(i.x+r/2,i.y+o/2),c=rl(s+t.width/2,a+t.height/2),[u,m]=Um(c,d,l);return{x:u-t.width/2,y:m-t.height/2}}return{x:s,y:a}},Ht=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,V=(e,t)=>{if(!e)return null;let n=Ht(e);return n&&t.get(n)||null},Me=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,db=(e,t,n)=>{if(!H(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(G.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=G.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=G.getEditorMidPoints(e,n,t)[o];return r||(r=G.getSegmentMidPoint(e,o+1,n)),{x:r[0],y:r[1]}},Rr=e=>{let t=yt,n=yt;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},cb=(e,t)=>H(t)?0:t?t.angle:e.angle,ub=(e,t,n)=>{if(H(e))return G.getBoundTextElementPosition(e,t,n)},mb=(e,t)=>e.some(n=>{if(ue(n)){let i=Me(n,t);return!H(i)}return!1}),pb=(e,t)=>e.some(n=>{if(ue(n)){let i=Me(n,t);return!H(i)}return q(n)}),Wm=new Set(["rectangle","ellipse","diamond","arrow"]),fb=e=>Wm.has(e.type),Fr=(e,t)=>{e=Math.ceil(e);let n=yt*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},ct=(e,t)=>{let{width:n}=e;if(H(e)){let i=(t?.fontSize??zm)*Rm;return Math.max(Nm*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-yt*2:e.type==="diamond"?Math.round(n/2)-yt*2:n-yt*2},Pi=(e,t)=>{let{height:n}=e;return H(e)?n-yt*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-yt*2:e.type==="diamond"?Math.round(n/2)-yt*2:n-yt*2},hb=(e,t=`
8
9
 
9
- `)=>e.reduce((i,o)=>(ne(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as lr,distanceToLineSegment as cr,pointRotateRads as dr}from"@excalidraw/math";import{ellipse as Nu,ellipseDistanceFromPoint as zu}from"@excalidraw/math/ellipse";var _t=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return Hu(e,t,n);case"diamond":return _u(e,t,n);case"ellipse":return Yu(e,t,n);case"line":case"arrow":case"freedraw":return Xu(e,n)}},Hu=(e,t,n)=>{let i=me(e,t),o=dr(n,i,-e.angle),[r,s]=yn(e);return Math.min(...r.map(a=>cr(o,a)),...s.map(a=>lr(a,o)).filter(a=>a!==null))},_u=(e,t,n)=>{let i=me(e,t),o=dr(n,i,-e.angle),[r,s]=bn(e);return Math.min(...r.map(a=>cr(o,a)),...s.map(a=>lr(a,o)).filter(a=>a!==null))},Yu=(e,t,n)=>{let i=me(e,t);return zu(dr(n,i,-e.angle),Nu(i,e.width/2,e.height/2))},Xu=(e,t)=>{let[n,i]=Ci(e);return Math.min(...n.map(o=>cr(t,o)),...i.map(o=>lr(o,t)))};var Ui=e=>{if(e.type==="arrow")return!1;let t=!Uu(e.backgroundColor)||st(e)||Oi(e)||ne(e);return e.type==="line"?t&&an(e.points):e.type==="freedraw"?t&&an(e.points):t||xe(e)},Qu=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null})=>{let r=o?Yi(St(o.x-n,o.y-n),e,St(o.x+o.width+n,o.y+o.height+n)):!1,s=he(t,i,!0);return!Yi(St(s[0]-n,s[1]-n),lt(e,ct(s),-t.angle),St(s[2]+n,s[3]+n))&&!r?!1:Ui(t)&&Sa(e,t,i)||wa(e,t,i,n)||r},Ju=(e,t,n,i=0)=>{let[o,r,s,a]=he(t,n);return o-=i,r-=i,s+=i,a+=i,Yi(St(o,r),e,St(s,a))},Pw=(e,t)=>!Qu(e)&&!ep(e.point,e.element,t)&&Ju(e.point,e.element,t),ep=(e,t,n)=>{let i=Z(t,n);if(!i)return!1;let o=U(t)?{...i,...Y.getBoundTextElementPosition(t,i,n)}:i;return Sa(e,o,n)},In=(e,t,n,i=0,o=!1)=>{let r=[Math.min(n[0][0]-i,n[1][0]-i),Math.min(n[0][1]-i,n[1][1]-i),Math.max(n[0][0]+i,n[1][0]+i),Math.max(n[0][1]+i,n[1][1]+i)],s=he(e,t);if(!un(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return np(e,t,n,i,o);case"diamond":return ip(e,t,n,i,o);case"ellipse":return op(e,t,n,i);case"line":case"freedraw":case"arrow":return tp(e,n,o)}},Pa=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Wi(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!un(a,l))continue;let c=ya(s,t);if(c.length>0){for(let d of c)n.push(lt(d,i,o));if(r)return n}}return n},Ia=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=ba(s,t);if(a&&(n.push(lt(a,i,o)),r))return n}return n},tp=(e,t,n=!1)=>{let[i,o]=Ci(e),r=[];for(let s of i){let a=ba(s,t);if(a&&(r.push(a),n))return r}for(let s of o){let a=Wi(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!un(a,l))continue;let c=ya(s,t);if(c.length>0&&(r.push(...c),n))return r}return r},np=(e,t,n,i=0,o=!1)=>{let r=me(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Xi(s,a),[c,d]=yn(e,i),u=[];return Ia(c,l,u,r,e.angle,o),o&&u.length>0||Pa(d,l,u,r,e.angle,o),u},ip=(e,t,n,i=0,o=!1)=>{let r=me(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Xi(s,a),[c,d]=bn(e,i),u=[];return Ia(c,l,u,r,e.angle,o),o&&u.length>0||Pa(d,l,u,r,e.angle,o),u},op=(e,t,n,i=0)=>{let o=me(e,t),r=lt(n[0],o,-e.angle),s=lt(n[1],o,-e.angle);return Ku(qu(o,e.width/2+i,e.height/2+i),Xi(r,s)).map(a=>lt(a,o,e.angle))},wa=(e,t,n,i=1)=>_t(t,n,e)<=i,Sa=(e,t,n)=>{if((U(t)||Se(t))&&!an(t.points))return!1;let[i,o,r,s]=he(t,n);if(!Yi(St(i,o),e,St(r,s)))return!1;let a=St((i+r)/2,(o+s)/2),l=Wu(Zu($u(Vu(e,a,.1)),Math.max(t.width,t.height)*2),a),c=Xi(e,l);return In(t,n,c).filter((u,p,m)=>m.findIndex(f=>ju(f,u))===p).length%2===1};P();import{invariant as Ma,isDevEnv as rp,isTestEnv as sp}from"@excalidraw/common";import{pointFrom as Yt,pointFromVector as ji,pointRotateRads as Vi,pointScaleFromOrigin as $i,pointsEqual as ap,triangleIncludesPoint as ur,vectorCross as Be,vectorFromPoint as q,vectorScale as Zi}from"@excalidraw/math";var pe=[1,0],we=[0,1],Oe=[-1,0],He=[0,-1],Mt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?pe:t<=-o?Oe:n>i?we:He},Ge=(e,t)=>Mt(q(e,t)),et=(e,t)=>ke(Ge(e,t)),ue=(e,t)=>e[0]===t[0]&&e[1]===t[1],ke=e=>ue(e,pe)||ue(e,Oe),vw=e=>!ke(e),lp=(e,t,n)=>{let i=ct(t);(rp()||sp())&&(Ma(e.width>0&&e.height>0,"Diamond element has no width or height"),Ma(!ap(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=ji(Zi(q(Vi(Yt(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=ji(Zi(q(Vi(Yt(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=ji(Zi(q(Vi(Yt(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=ji(Zi(q(Vi(Yt(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Be(q(n,r),q(r,s))<=0&&Be(q(n,r),q(r,l))>0)return Ge(r,i);if(Be(q(n,s),q(s,a))<=0&&Be(q(n,s),q(s,r))>0)return Ge(s,i);if(Be(q(n,a),q(a,l))<=0&&Be(q(n,a),q(a,s))>0)return Ge(a,i);if(Be(q(n,l),q(l,r))<=0&&Be(q(n,l),q(l,a))>0)return Ge(l,i);if(Be(q(n,i),q(r,i))<=0&&Be(q(n,i),q(s,i))>0){let d=e.width>e.height?r:s;return Ge(d,i)}else if(Be(q(n,i),q(s,i))<=0&&Be(q(n,i),q(a,i))>0){let d=e.width>e.height?a:s;return Ge(d,i)}else if(Be(q(n,i),q(a,i))<=0&&Be(q(n,i),q(l,i))>0){let d=e.width>e.height?a:l;return Ge(d,i)}let c=e.width>e.height?r:l;return Ge(c,i)},ti=(e,t,n)=>{let o=ct(t);if(e.type==="diamond")return lp(e,t,n);let r=$i(Yt(t[0],t[1]),o,2),s=$i(Yt(t[2],t[1]),o,2),a=$i(Yt(t[0],t[3]),o,2),l=$i(Yt(t[2],t[3]),o,2);return ur([r,s,o],n)?He:ur([s,l,o],n)?pe:ur([l,a,o],n)?we:Oe},pr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Ap,randomInteger as Ir,getUpdatedTimestamp as Sr}from"@excalidraw/common";P();import{clamp as qi,pointDistance as hr,pointFrom as z,pointScaleFromOrigin as cp,pointsEqual as ii,pointTranslate as fr,vector as dt,vectorCross as Ki,vectorFromPoint as Er,vectorScale as dp}from"@excalidraw/math";import{BinaryHeap as up,invariant as Sn,isAnyTrue as pp,tupleToCoors as mp,getSizeFromPoints as Ta,isDevEnv as fp,arrayToMap as hp}from"@excalidraw/common";var gr=1,J=40,Ep=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>z(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let c=Ge(s,l[a-1]),d=Ge(l[a-1],l[a-2]);if(ue(c,d)){let u=n?.findIndex(m=>m.index===a-1)??-1,p=n?.findIndex(m=>m.index===a)??-1;p!==-1&&(n[p].start=z(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(m=>{m.index>a-1&&(m.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(hr(l[a-2],l[a-1])<gr){let c=n?.findIndex(p=>p.index===a-2)??-1,d=n?.findIndex(p=>p.index===a-1)??-1;d!==-1&&n.splice(d,1),c!==-1&&n.splice(c,1),o.splice(-2,2),n.forEach(p=>{p.index>a-2&&(p.index-=2)});let u=et(s,l[a-1]);return o.push(z(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}o.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==o.length-1);return r.length===0?Tt(yr(br(wr(e,xr(e,t,o.map(s=>z(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(fp()&&Sn(Ga(o),"Invalid elbow points with fixed segments"),Tt(o,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},gp=(e,t,n)=>{let i=t.map(T=>T.index),r=(e.fixedSegments?.map(T=>T.index)??[]).findIndex(T=>!i.includes(T));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],c=e.x+(a?a.end[0]:0),d=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,p=l?null:e.endBinding,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y}=xr({x:c,y:d,startBinding:u,endBinding:p,startArrowhead:null,endArrowhead:null,points:e.points},n,[z(0,0),z(e.x+(l?.start[0]??e.points[e.points.length-1][0])-c,e.y+(l?.start[1]??e.points[e.points.length-1][1])-d)],{isDragging:!1}),{points:b}=Tt(yr(br(wr(e,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y})??[])),t,null,null),w=[];if(a)for(let T=0;T<a.index;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));if(b.forEach(T=>{w.push(z(e.x+(a?a.end[0]:0)+T[0],e.y+(a?a.end[1]:0)+T[1]))}),l)for(let T=l.index;T<e.points.length;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,M=t.map(T=>T.index>s?{...T,index:T.index-I+(b.length-1)}:T),v=w.flatMap((T,F)=>{let C=w[F-1],R=w[F+1];if(C&&R){let L=Ge(T,C),W=Ge(R,T);if(ue(L,W))return M.forEach(N=>{N.index>F&&(N.index-=1)}),[];if(ue(L,pr(W)))return M.forEach(N=>{N.index>F&&(N.index+=1)}),[T,T]}return[T]});return Tt(v,M,!1,!1)},xp=(e,t,n,i,o,r)=>{let s=t.map((w,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==w.index||(w.start[0]!==e.fixedSegments[I].start[0]&&w.end[0]!==e.fixedSegments[I].end[0])!=(w.start[1]!==e.fixedSegments[I].start[1]&&w.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,c=hr(t[s].start,t[s].end),d=c<J+5;if(a===-1&&t[s].index===1&&o){let w=ke(n),M=(w?ue(n,pe):ue(n,we))?d?c/2:J:d?-c/2:-J;t[s].start=z(t[s].start[0]+(w?M:0),t[s].start[1]+(w?0:M))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=ke(i),M=(w?ue(i,pe):ue(i,we))?d?c/2:J:d?-c/2:-J;t[s].end=z(t[s].end[0]+(w?M:0),t[s].end[1]+(w?0:M))}let u=t.map(w=>({...w,start:z(e.x+w.start[0],e.y+w.start[1]),end:z(e.x+w.end[0],e.y+w.end[1])})),p=e.points.map((w,I)=>z(e.x+w[0],e.y+w[1])),m=u[s].index-1,f=u[s].index,E=u[s].start,h=u[s].end,g=p[m-1]&&!ii(p[m],p[m-1])?et(p[m-1],p[m]):void 0,x=p[f+1]&&!ii(p[f],p[f+1])?et(p[f+1],p[f]):void 0;if(g!==void 0){let w=g?1:0;p[m-1][w]=E[w]}if(p[m]=E,p[f]=h,x!==void 0){let w=x?1:0;p[f+1][w]=h[w]}let y=u.findIndex(w=>w.index===m);if(y!==-1){let w=et(u[y].end,u[y].start)?1:0;u[y].start[w]=E[w],u[y].end=E}let b=u.findIndex(w=>w.index===f+1);if(b!==-1){let w=et(u[b].end,u[b].start)?1:0;u[b].end[w]=h[w],u[b].start=h}if(a===-1&&m===0){let w=o?ke(n):et(p[1],p[0]);p.unshift(z(w?E[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:E[1])),o&&p.unshift(z(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=o?2:1}if(l===-1&&f===e.points.length-1){let w=ke(i);p.push(z(w?h[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:h[1])),r&&p.push(z(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return Tt(p,u.map(w=>({...w,start:z(w.start[0]-e.x,w.start[1]-e.y),end:z(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},wp=(e,t,n,i,o,r,s,a,l)=>{let c=e.startIsSpecial??null,d=e.endIsSpecial??null,u=t.map((h,g)=>g===0?z(e.x+h[0],e.y+h[1]):g===t.length-1?z(e.x+h[0],e.y+h[1]):z(e.x+e.points[g][0],e.y+e.points[g][1])),p=n.map(h=>({...h,start:z(e.x+(h.start[0]-t[0][0]),e.y+(h.start[1]-t[0][1])),end:z(e.x+(h.end[0]-t[0][0]),e.y+(h.end[1]-t[0][1]))})),m=[],f=2+(c?1:0),E=2+(d?1:0);for(;m.length+f<u.length-E;)m.push(u[m.length+f]);{let h=u[c?2:1],g=u[c?3:2],x=ke(i),y=ke(Mt(Er(h,g)));if(a&&x===y){let b=x?ue(i,pe):ue(i,we);if(m.unshift(z(y?r[0]+(b?J:-J):g[0],y?g[1]:r[1]+(b?J:-J))),m.unshift(z(x?r[0]+(b?J:-J):r[0],x?r[1]:r[1]+(b?J:-J))),!c){c=!0;for(let w of p)w.index>1&&(w.index+=1)}}else if(m.unshift(z(y?r[0]:h[0],y?h[1]:r[1])),c){c=!1;for(let b of p)b.index>1&&(b.index-=1)}m.unshift(r)}{let h=u[u.length-(d?3:2)],g=u[u.length-(d?4:3)],x=ke(o),y=et(g,h);if(l&&x===y){let b=x?ue(o,pe):ue(o,we);m.push(z(y?s[0]+(b?J:-J):g[0],y?g[1]:s[1]+(b?J:-J))),m.push(z(x?s[0]+(b?J:-J):s[0],x?s[1]:s[1]+(b?J:-J))),d||(d=!0)}else m.push(z(y?s[0]:h[0],y?h[1]:s[1])),d&&(d=!1)}return m.push(s),Tt(m,p.map(({index:h})=>({index:h,start:m[h-1],end:m[h]})).map(h=>({...h,start:z(h.start[0]-r[0],h.start[1]-r[1]),end:z(h.end[0]-r[0],h.end[1]-r[1])})),c,d)},Xt=1e6,Tn=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};A.PROD||(Sn(!n.points||n.points.length>=2,"Updated point array length must match the arrow point length, contain exactly the new start and end points or not be specified at all (i.e. you can't add new points between start and end manually to elbow arrows)"),Sn(!e.fixedSegments||e.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Sn(!n.fixedSegments||n.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Sn(e.points.slice(1).map((w,I)=>w[0]===e.points[I][0]||w[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Sn(n.fixedSegments?.find(w=>w.index===1&&ii(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&ii(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let o=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,c=typeof s<"u"?s:e.startBinding,d=typeof a<"u"?a:e.endBinding,u=c&&Ji(c.elementId,t),p=d&&Ji(d.elementId,t),m=Ga(r);if(c&&!u&&m||d&&!p&&m||t.size===0&&m||Object.keys(l).length===0&&(u?.id!==c?.elementId||p?.id!==d?.elementId))return Tt(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b}=xr({x:e.x,y:e.y,startBinding:c,endBinding:d,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,i);return t.size===0&&m?Tt(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?Ep(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,I)=>ii(w,e.points[I]??z(1/0,1/0)))&&m?{}:o.length===0?Tt(yr(br(wr(e,{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?gp(e,o,t):n.points?n.points&&n.fixedSegments?n:wp(e,r,o,f,E,h,g,x,y):xp(e,o,f,E,x,y)},xr=(e,t,n,i)=>{let o=fr(n[0],dt(e.x,e.y)),r=fr(n[n.length-1],dt(e.x,e.y)),s=null,a=null;if(i?.isDragging){let w=Array.from(t.values());s=La(o,t,w,i?.zoom)||null,a=La(r,t,w,i?.zoom)||null}else s=e.startBinding&&Ji(e.startBinding.elementId,t)||null,a=e.endBinding&&Ji(e.endBinding.elementId,t)||null;let l=va({...e,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging),c=va({...e,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging),d=Da(l,c,s,o,t),u=Da(c,l,a,r,t),p=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],m=[c[0]-2,c[1]-2,c[0]+2,c[1]+2],f=s?Ve(s,t,Ut(d,e.startArrowhead?oe*6:oe*2,1)):p,E=a?Ve(a,t,Ut(u,e.endArrowhead?oe*6:oe*2,1)):m,h=Mn(l,a?Ve(a,t,Ut(u,J,J)):m)||Mn(c,s?Ve(s,t,Ut(d,J,J)):p),g=Ba(h?[p,m]:[f,E]),x=Pp(h?p:f,h?m:E,g,h?Ut(d,!s&&!a?0:J,0):Ut(d,!s&&!a?0:J-(e.startArrowhead?oe*6:oe*2),J),h?Ut(u,!s&&!a?0:J,0):Ut(u,!s&&!a?0:J-(e.endArrowhead?oe*6:oe*2),J),h,s&&Ve(s,t),a&&Ve(a,t)),y=Aa(x[0],d,l),b=Aa(x[1],u,c);return{dynamicAABBs:x,startDonglePosition:y,startGlobalPoint:l,startHeading:d,endDonglePosition:b,endGlobalPoint:c,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:h,startElementBounds:f,endElementBounds:E}},wr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:c,hoveredEndElement:d}=t,u=Ip(n,i||o,r,s||a,l,c),p=i&&Qi(i,u),m=s&&Qi(s,u),f=Qi(a,u);f&&d&&(f.closed=!0);let E=Qi(o,u);E&&e.startBinding&&(E.closed=!0);let h=p&&m&&(Mn(p.pos,n[1])||Mn(m.pos,n[0])),g=yp(p||E,m||f,u,r||pe,l||pe,h?[]:n);if(g){let x=g.map(y=>[y.pos[0],y.pos[1]]);return p&&x.unshift(o),m&&x.push(a),x}return null},Ut=(e,t,n)=>{switch(e){case He:return[t,n,n,n];case pe:return[n,t,n,n];case we:return[n,n,t,n]}return[n,n,n,t]},yp=(e,t,n,i,o,r)=>{let s=mr(e.pos,t.pos),a=new up(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return bp(e,l);l.closed=!0;let c=Mp(l.addr,n);for(let d=0;d<4;d++){let u=c[d];if(!u||u.closed)continue;let p=cp(u.pos,l.pos,.5);if(pp(...r.map(b=>Mn(p,b))))continue;let m=Tp(d),f=l.parent?Mt(Er(l.pos,l.parent.pos)):i,E=pr(f);if(ue(E,m)||Ca(e.addr,u.addr)&&ue(m,i)||Ca(t.addr,u.addr)&&ue(m,o))continue;let g=f!==m,x=l.g+mr(u.pos,l.pos)+(g?Math.pow(s,3):0),y=u.visited;if(!y||x<u.g){let b=Sp(u,t,m,o);u.visited=!0,u.parent=l,u.h=mr(t.pos,u.pos)+b*Math.pow(s,2),u.g=x,u.f=u.g+u.h,y?a.rescoreElement(u):a.push(u)}}}return null},bp=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},mr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Pp=(e,t,n,i,o,r,s,a)=>{let l=s??e,c=a??t,[d,u,p,m]=i??[0,0,0,0],[f,E,h,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+c[2])/2,e[0]-m):(l[0]+c[2])/2:e[0]>t[0]?e[0]-m:n[0]-m,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+c[3])/2,e[1]-d):(l[1]+c[3])/2:e[1]>t[1]?e[1]-d:n[1]-d,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+c[0])/2,e[2]+u):(l[2]+c[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+c[1])/2,e[3]+p):(l[3]+c[1])/2:e[3]<t[3]?e[3]+p:n[3]+p],y=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((c[0]+l[2])/2,t[0]-g):(c[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((c[1]+l[3])/2,t[1]-f):(c[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((c[2]+l[0])/2,t[2]+E):(c[2]+l[0])/2:t[2]<e[2]?t[2]+E:n[2]+E,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((c[3]+l[1])/2,t[3]+h):(c[3]+l[1])/2:t[3]<e[3]?t[3]+h:n[3]+h],b=Ba([x,y]);if(!r&&x[2]-x[0]+y[2]-y[0]>b[2]-b[0]+1e-11&&x[3]-x[1]+y[3]-y[1]>b[3]-b[1]+1e-11){let[w,I]=[(y[0]+y[2])/2,(y[1]+y[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let M=x[2]+(y[0]-x[2])/2,v=y[3]+(x[1]-y[3])/2;return Ki(dt(e[2]-w,e[1]-I),dt(e[0]-w,e[3]-I))>0?[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]:[[x[0],v,x[2],x[3]],[y[0],y[1],y[2],v]]}else if(e[2]<t[0]&&e[3]<t[1]){let M=x[2]+(y[0]-x[2])/2,v=x[3]+(y[1]-x[3])/2;return Ki(dt(e[0]-w,e[1]-I),dt(e[2]-w,e[3]-I))>0?[[x[0],x[1],x[2],v],[y[0],v,y[2],y[3]]]:[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let M=y[2]+(x[0]-y[2])/2,v=x[3]+(y[1]-x[3])/2;return Ki(dt(e[2]-w,e[1]-I),dt(e[0]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],x[1],x[2],v],[y[0],v,y[2],y[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let M=y[2]+(x[0]-y[2])/2,v=y[3]+(x[1]-y[3])/2;return Ki(dt(e[0]-w,e[1]-I),dt(e[2]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],v,x[2],x[3]],[y[0],y[1],y[2],v]]}}return[x,y]},Ip=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===Oe||n===pe?a.add(t[1]):s.add(t[0]),o===Oe||o===pe?a.add(i[1]):s.add(i[0]),e.forEach(d=>{s.add(d[0]),s.add(d[2]),a.add(d[1]),a.add(d[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((d,u)=>d-u),c=Array.from(s).sort((d,u)=>d-u);return{row:l.length,col:c.length,data:l.flatMap((d,u)=>c.map((p,m)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[m,u],pos:[p,d]})))}},Aa=(e,t,n)=>{switch(t){case He:return z(n[0],e[1]);case pe:return z(e[2],n[1]);case we:return z(n[0],e[3])}return z(e[0],n[1])},Sp=(e,t,n,i)=>{if(i===pe)switch(n){case pe:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case He:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Oe:return e.pos[1]===t.pos[1]?4:2}else if(i===Oe)switch(n){case pe:return e.pos[1]===t.pos[1]?4:2;case He:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Oe:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===He)switch(n){case pe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case we:return e.pos[0]===t.pos[0]?4:2;case Oe:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===we)switch(n){case pe:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He:return e.pos[0]===t.pos[0]?4:2;case we:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Oe:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Mp=([e,t],n)=>[ni([e,t-1],n),ni([e+1,t],n),ni([e,t+1],n),ni([e-1,t],n)],ni=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Qi=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=ni([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Ba=e=>[Math.min(...e.map(t=>t[0])),Math.min(...e.map(t=>t[1])),Math.max(...e.map(t=>t[2])),Math.max(...e.map(t=>t[3]))],Ji=(e,t)=>{let n=t.get(e);return n&&Le(n)?n:null},Tt=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>fr(a,dp(Er(e[0]),-1)));return(o<-Xt||o>Xt||r<-Xt||r>Xt||o+s[s.length-1][0]<-Xt||r+s[s.length-1][0]>Xt||o+s[s.length-1][1]<-Xt||r+s[s.length-1][1]>Xt)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...Ta(s)}),s=s.map(([a,l])=>z(qi(a,-1e6,1e6),qi(l,-1e6,1e6))),{points:s,x:qi(o,-1e6,1e6),y:qi(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Ta(s),startIsSpecial:n,endIsSpecial:i}},yr=e=>{if(e.length>1){let t=Math.abs(e[0][1]-e[1][1])<Math.abs(e[0][0]-e[1][0]);return e.filter((n,i)=>{if(i===0||i===e.length-1)return!0;let o=e[i+1],r=Math.abs(n[1]-o[1])<Math.abs(n[0]-o[0]);return t===r?(t=r,!1):(t=r,!0)})}return e},br=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return hr(i,t)>gr}):e,Tp=e=>{switch(e){case 0:return He;case 1:return pe;case 2:return we}return Oe},va=(e,t,n,i,o,r,s)=>s?o&&r?Pr(e,o,t,r):i:o?eo(n||[0,0],o,r??hp([o])):i,Da=(e,t,n,i,o)=>Oa(e,t,n,n&&Ve(n,o,Array(4).fill(_t(n,o,e))),i,o),La=(e,t,n,i)=>Wt(mp(e),n,t,i,!0,!0),Ca=(e,t)=>e[0]===t[0]&&e[1]===t[1],Ga=(e,t=gr)=>e.slice(1).map((n,i)=>Math.abs(n[0]-e[i][0])<t||Math.abs(n[1]-e[i][1])<t).every(Boolean);var ye=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,startBinding:a,endBinding:l,fileId:c}=n;G(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u"||typeof a<"u"||typeof l<"u")?n={...n,angle:0,...Tn({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Ap(r),...n});for(let d in n){let u=n[d];if(typeof u<"u"){if(e[d]===u&&(typeof u!="object"||u===null||d==="groupIds"||d==="scale"))continue;if(d==="scale"){let p=e[d],m=u;if(p[0]===m[0]&&p[1]===m[1])continue}else if(d==="points"){let p=e[d],m=u;if(p.length===m.length){let f=!1,E=p.length;for(;--E;){let h=p[E],g=m[E];if(h[0]!==g[0]||h[1]!==g[1]){f=!0;break}}if(!f)continue}}e[d]=u,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof c<"u"||typeof r<"u")&&be.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Ir(),e.updated=Sr()),e},Me=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Ir(),updated:Sr()}},ka=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Ir(),e.updated=Sr(),e);var oy=e=>!e[vp.CTRL_OR_CMD],Mr=e=>e.isBindingEnabled,oe=5,kp=10,Rp=(e,t)=>{let n=[];return t.forEach(i=>{let o=e.getNonDeletedElement(i);o!=null&&n.push(o)}),n},Tr=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=new Set,s=new Set;Na(e,t,n,"start",r,s,i,o),Na(e,n,t,"end",r,s,i,o);let a=Array.from(s).filter(l=>!r.has(l));Rp(i,a).forEach(l=>{i.mutateElement(l,{boundElements:l.boundElements?.filter(c=>c.type!=="arrow"||c.id!==e.id)})})},Na=(e,t,n,i,o,r,s,a)=>{if(t!=="keep"){if(t===null){let l=_p(e,i,s);l!=null&&r.add(l);return}Wa(e)?(n==null||(n==="keep"?!Xa(e,t,i):i==="start"||n.id!==t.id))&&(pn(e,t,i,s),o.add(t.id)):(pn(e,t,i,s),o.add(t.id))}},_a=(e,t,n)=>["start","end"].map(i=>{let o=Va(e,i,t),r=i==="start"?e.startBinding?.elementId:e.endBinding?.elementId;if(r){let s=t.get(r);if(Le(s)&&no(s,o,t,n))return s}return null}),Fp=(e,t,n,i,o,r)=>{let a=e.points.length-1,l=n.findIndex(p=>p===0)>-1,c=n.findIndex(p=>p===a)>-1,d=l?t?io(e,"start",i,o,r):null:"keep",u=c?t?io(e,"end",i,o,r):null:"keep";return[d,u]},Np=(e,t,n,i,o)=>{if(G(e))return["keep","keep"];let[r,s]=_a(e,t,o),a=r&&i?io(e,"start",t,n,o):null,l=s&&i?io(e,"end",t,n,o):null;return[a,l]},zp=(e,t,n,i,o)=>{e.forEach(r=>{let[s,a]=n?.length?Fp(r,t,n??[],i.getNonDeletedElementsMap(),i.getNonDeletedElements(),o):Np(r,i.getNonDeletedElementsMap(),i.getNonDeletedElements(),t,o);Tr(r,s,a,i)})},ry=(e,t,n)=>e.length>50?[]:e.filter(U).flatMap(i=>_a(i,t,n)).filter(i=>i!==null).filter(i=>e.filter(o=>o.id===i?.id).length===0),Ya=(e,t,n,i,o)=>Array.from(t.reduce((r,s)=>{let a=Wt(s,n.getNonDeletedElements(),n.getNonDeletedElementsMap(),i,G(e),G(e));return a!=null&&!Ua(e,o?.id,a)&&r.add(a),r},new Set)),sy=(e,t,n,i)=>{let o=i.getNonDeletedElements(),r=i.getNonDeletedElementsMap();t.startBoundElement!=null&&pn(e,t.startBoundElement,"start",i);let s=Wt(n,o,r,t.zoom,G(e),G(e));s!==null&&(Xa(e,s,"end")||pn(e,s,"end",i))},Hp=(e,t)=>({...e,gap:Math.min(e.gap,so(t,t.width,t.height))}),pn=(e,t,n,i)=>{if(!_(e))return;let o={elementId:t.id,...Hp(Up(e,t,n,i.getNonDeletedElementsMap()),t)};G(e)&&(o={...o,...ja(e,t,n,i.getNonDeletedElementsMap())}),i.mutateElement(e,{[n==="start"?"startBinding":"endBinding"]:o}),Ha(t.boundElements||[]).has(e.id)||i.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Xa=(e,t,n)=>{let i=e[n==="start"?"endBinding":"startBinding"];return Ua(e,i?.elementId,t)},Ua=(e,t,n)=>t===n.id&&Wa(e),Wa=e=>e.points.length<3&&!G(e),_p=(e,t,n)=>{let i=t==="start"?"startBinding":"endBinding",o=e[i];return o==null?null:(n.mutateElement(e,{[i]:null}),o.elementId)},Wt=(e,t,n,i,o,r)=>{if(r){let a=!1,l=Xp(t,d=>Le(d,!1)&&no(d,e,n,i,(o||!to(d))&&!V(d))).filter(d=>a?!1:(to(d)||(a=!0),!0));if(!l||l.length===0)return null;if(l.length===1)return l[0];let c=l.filter(d=>no(d,e,n,i,!1));return c.length===1?c[0]:l.sort((d,u)=>u.width**2+u.height**2-(d.width**2+d.height**2)).pop()}return Yp(t,a=>Le(a,!1)&&no(a,e,n,i,(o||!to(a))&&!V(a)))},Yp=(e,t)=>{let n=null;for(let i=e.length-1;i>=0;--i){let o=e[i];if(!o.isDeleted&&t(o)){n=o;break}}return n},Xp=(e,t)=>{let n=[];for(let i=e.length-1;i>=0;--i){let o=e[i];o.isDeleted||t(o)&&n.push(o)}return n},Up=(e,t,n,i)=>{let o=n==="start"?-1:1,r=o===-1?0:e.points.length-1,s=r-o,a=Y.getPointAtIndexGlobalCoordinates(e,r,i),l=Y.getPointAtIndexGlobalCoordinates(e,s,i);return{focus:Kp(t,i,l,a),gap:Math.max(1,_t(t,i,a))}},Xe=(e,t,n)=>{if(!Le(e))return;let{newSize:i,simultaneouslyUpdated:o}=n??{},r=jp(o),s=t.getNonDeletedElementsMap();n?.changedElements&&(s=new Map(s),n.changedElements.forEach(a=>{s.set(a.id,a)})),oo(s,e,a=>{if(!U(a)||a.isDeleted||!Wp(a,e))return;let l=a.startBinding?s.get(a.startBinding.elementId):null,c=a.endBinding?s.get(a.endBinding.elementId):null,d=null,u=null;l&&c&&(d=he(l,s),u=he(c,s));let p={startBinding:za(e,a.startBinding,i),endBinding:za(e,a.endBinding,i)};if(r.has(a.id)){t.mutateElement(a,p);return}let m=ro(s,a,(E,h)=>{if(E&&Le(E)&&(h==="startBinding"||h==="endBinding")&&(e.id===a[h]?.elementId||e.id===a[h==="startBinding"?"endBinding":"startBinding"]?.elementId&&!un(d,u))){let g=qp(a,h,p[h],E,s);if(g)return[h==="startBinding"?0:a.points.length-1,{point:g}]}return null}).filter(E=>E!==null);Y.movePoints(a,t,new Map(m),{...e.id===a.startBinding?.elementId?{startBinding:p.startBinding}:{},...e.id===a.endBinding?.elementId?{endBinding:p.endBinding}:{}});let f=Z(a,s);f&&!f.isDeleted&&dn(a,t,!1)})},ay=(e,t,n)=>{U(e)?zp([e],!0,[],t,n?.zoom):Xe(e,t,{...n,changedElements:new Map([[e.id,e]])})},Wp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,jp=e=>new Set((e||[]).map(t=>t.id)),Oa=(e,t,n,i,o,r,s)=>{let a=Mt($(t,e));return!n||!i?a:Vp(o,n,r,s)?ti(n,i,e):Mt($(e,me(n,r)))},Vp=(e,t,n,i)=>{let o=_t(t,n,e),r=so(t,t.width,t.height,i);return o>r?null:o},Pr=(e,t,n,i)=>{(Cp()||Bp())&&Lp(e.points.length>1,"Arrow should have at least 2 points");let o=Ve(t,i),r=e.points[n==="start"?0:e.points.length-1],s=k(e.x+r[0],e.y+r[1]),a=ra(t)?$p(t,i,s):s,l=G(e),c=ct(o),d=n==="start"?1:e.points.length-2,u=ae(k(e.x+e.points[d][0],e.y+e.points[d][1]),c,e.angle??0),p=null;if(l){let m=ke(ti(t,o,s)),f=Zp(t,i,a),E=k(m?c[0]:f[0],m?f[1]:c[1]),h=Ye(E,An(vn(ri($(f,E)),Math.max(t.width,t.height)*2),E));p=In(t,i,h,oe).sort(jt)[0]}else p=In(t,i,Ye(u,An(vn(ri($(a,u)),ut(a,u)+Math.max(t.width,t.height)*2),u)),oe).sort((m,f)=>jt(m,u)-jt(f,u))[0];return!p||jt(a,p)<Op?a:l?p:a},$p=(e,t,n)=>{let i=me(e,t),o=ae(n,i,-e.angle);return o[0]<e.x&&o[1]<e.y?o[1]-e.y>-oe?ae(k(e.x-oe,e.y),i,e.angle):ae(k(e.x,e.y-oe),i,e.angle):o[0]<e.x&&o[1]>e.y+e.height?o[0]-e.x>-oe?ae(k(e.x,e.y+e.height+oe),i,e.angle):ae(k(e.x-oe,e.y+e.height),i,e.angle):o[0]>e.x+e.width&&o[1]>e.y+e.height?o[0]-e.x<e.width+oe?ae(k(e.x+e.width,e.y+e.height+oe),i,e.angle):ae(k(e.x+e.width+oe,e.y+e.height),i,e.angle):o[0]>e.x+e.width&&o[1]<e.y?o[0]-e.x<e.width+oe?ae(k(e.x+e.width,e.y-oe),i,e.angle):ae(k(e.x+e.width+oe,e.y),i,e.angle):n},Zp=(e,t,n,i=.05)=>{let{x:o,y:r,width:s,height:a,angle:l}=e,c=me(e,t,-.1,-.1),d=ae(n,c,-l),u=Ra(i*a,5,80),p=Ra(i*s,5,80);if(d[0]<=o+s/2&&d[1]>c[1]-u&&d[1]<c[1]+u)return ae(k(o-oe,c[1]),c,l);if(d[1]<=r+a/2&&d[0]>c[0]-p&&d[0]<c[0]+p)return ae(k(c[0],r-oe),c,l);if(d[0]>=o+s/2&&d[1]>c[1]-u&&d[1]<c[1]+u)return ae(k(o+s+oe,c[1]),c,l);if(d[1]>=r+a/2&&d[0]>c[0]-p&&d[0]<c[0]+p)return ae(k(c[0],r+a+oe),c,l);if(e.type==="diamond"){let m=oe,f=k(o+s/4-m,r+a/4-m),E=k(o+3*s/4+m,r+a/4-m),h=k(o+s/4-m,r+3*a/4+m),g=k(o+3*s/4+m,r+3*a/4+m);if(ut(f,d)<Math.max(p,u))return ae(f,c,l);if(ut(E,d)<Math.max(p,u))return ae(E,c,l);if(ut(h,d)<Math.max(p,u))return ae(h,c,l);if(ut(g,d)<Math.max(p,u))return ae(g,c,l)}return n},qp=(e,t,n,i,o)=>{if(n==null||n.elementId!==i.id&&e.points.length>2)return null;let r=t==="startBinding"?-1:1,s=r===-1?0:e.points.length-1;if(G(e)&&Qn(n)){let u=Ar(n.fixedPoint)??ja(e,i,t==="startBinding"?"start":"end",o).fixedPoint,p=me(i,o),m=k(i.x+u[0]*i.width,i.y+u[1]*i.height),f=ae(m,p,i.angle);return Y.pointFromAbsoluteCoords(e,f,o)}let a=s-r,l=Y.getPointAtIndexGlobalCoordinates(e,a,o),c=Qp(i,o,n.focus,l),d;if(n.gap===0)d=c;else{let u=Y.getPointAtIndexGlobalCoordinates(e,s,o),p=me(i,o),m=ut(l,u)+ut(l,p)+Math.max(i.width,i.height)*2,f=[...In(i,o,Ye(l,An(vn(ri($(c,l)),m),l)),n.gap).sort((E,h)=>jt(E,l)-jt(h,l)),An(vn(ri($(c,l)),ut(l,u)),l)];f.length>1?d=f[0]:f.length===1?d=c:d=u}return Y.pointFromAbsoluteCoords(e,d,o)},ja=(e,t,n,i)=>{let o=[t.x,t.y,t.x+t.width,t.y+t.height],r=Pr(e,t,n,i),s=k(o[0]+(o[2]-o[0])/2,o[1]+(o[3]-o[1])/2),a=ae(r,s,-t.angle);return{fixedPoint:Ar([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},za=(e,t,n)=>{if(t==null||n==null)return t;let{width:i,height:o}=n,{width:r,height:s}=e,a=Math.max(1,Math.min(so(e,i,o),t.gap*(i<o?i/r:o/s)));return{...t,gap:a}},io=(e,t,n,i,o)=>Wt(Va(e,t,n),i,n,o,G(e),G(e)),Va=(e,t,n)=>{let i=t==="start"?0:-1;return Dp(Y.getPointAtIndexGlobalCoordinates(e,i,n))},$a=(e,t,n)=>{for(let i of e){if("boundElements"in i&&i.boundElements&&Object.assign(i,{boundElements:i.boundElements.reduce((o,r)=>{let s=t.get(r.id);return s&&o.push({...r,id:s}),o},[])}),"containerId"in i&&i.containerId&&Object.assign(i,{containerId:t.get(i.containerId)??null}),"endBinding"in i&&i.endBinding){let o=t.get(i.endBinding.elementId);Object.assign(i,{endBinding:o?{...i.endBinding,elementId:o}:null})}if("startBinding"in i&&i.startBinding){let o=t.get(i.startBinding.elementId);Object.assign(i,{startBinding:o?{...i.startBinding,elementId:o}:null})}G(i)&&Object.assign(i,Tn(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},ly=(e,t)=>{let n=Ha(e);for(let i of t)Vt.unbindAffected(n,i,(o,r)=>ye(o,n,r)),$t.unbindAffected(n,i,(o,r)=>ye(o,n,r))},oi=(e,t,n=[])=>{if(!e)return null;let i=e.filter(o=>!t.has(o.id));return i.push(...n.map(o=>({id:o.id,type:o.type}))),i},no=(e,{x:t,y:n},i,o,r)=>{let s=k(t,n),a=so(e,e.width,e.height,o),l=(r||!to(e))&&!V(e),c=[t-a,n-a,t+a,n+a],d=he(e,i);if(!un(c,d))return!1;let u=In(e,i,Ye(me(e,i),s)),p=_t(e,i,s);return l?u.length===0||p<=a:u.length>0&&p<=a},so=(e,t,n,i)=>{let o=i?.value&&i.value<1?i.value:1,s=(e.type==="diamond"?1/Math.sqrt(2):1)*Math.min(t,n);return Math.max(16,Math.min(.25*s,32),kp/o+oe)},Kp=(e,t,n,i)=>{let o=me(e,t);if(Gp(n,i))return 0;let r=ae(n,o,-e.angle),s=ae(i,o,-e.angle),a=Math.sign(_e($(s,n),$(s,o)))*-1,l=Ye(s,An(vn(ri($(s,r)),Math.max(e.width*2,e.height*2)),s)),c=e.type==="diamond"?[Ye(k(e.x+e.width/2,e.y),k(e.x+e.width/2,e.y+e.height)),Ye(k(e.x,e.y+e.height/2),k(e.x+e.width,e.y+e.height/2))]:[Ye(k(e.x,e.y),k(e.x+e.width,e.y+e.height)),Ye(k(e.x+e.width,e.y),k(e.x,e.y+e.height))],d=e.type==="diamond"?[Ye(k(e.x+e.width/2,e.y-e.height),k(e.x+e.width/2,e.y+e.height*2)),Ye(k(e.x-e.width,e.y+e.height/2),k(e.x+e.width*2,e.y+e.height/2))]:[Ye(k(e.x-e.width,e.y-e.height),k(e.x+e.width*2,e.y+e.height*2)),Ye(k(e.x+e.width*2,e.y-e.height),k(e.x-e.width,e.y+e.height*2))];return[Fa(l,d[0]),Fa(l,d[1])].filter(m=>m!==null).sort((m,f)=>jt(m,i)-jt(f,i)).map((m,f)=>a*ut(o,m)/(e.type==="diamond"?ut(c[f][0],c[f][1])/2:Math.sqrt(e.width**2+e.height**2)/2)).sort((m,f)=>Math.abs(m)-Math.abs(f))[0]??0},Qp=(e,t,n,i)=>{let o=me(e,t);if(n===0)return o;let r=(e.type==="diamond"?[k(e.x,e.y+e.height/2),k(e.x+e.width/2,e.y),k(e.x+e.width,e.y+e.height/2),k(e.x+e.width/2,e.y+e.height)]:[k(e.x,e.y),k(e.x+e.width,e.y),k(e.x+e.width,e.y+e.height),k(e.x,e.y+e.height)]).map(l=>An(vn($(l,o),Math.abs(n)),o)).map(l=>ae(l,o,e.angle)),s=[_e($(i,r[0]),$(r[1],r[0]))>0&&(n>0?_e($(i,r[1]),$(r[2],r[1]))<0:_e($(i,r[3]),$(r[0],r[3]))<0),_e($(i,r[1]),$(r[2],r[1]))>0&&(n>0?_e($(i,r[2]),$(r[3],r[2]))<0:_e($(i,r[0]),$(r[1],r[0]))<0),_e($(i,r[2]),$(r[3],r[2]))>0&&(n>0?_e($(i,r[3]),$(r[0],r[3]))<0:_e($(i,r[1]),$(r[2],r[1]))<0),_e($(i,r[3]),$(r[0],r[3]))>0&&(n>0?_e($(i,r[0]),$(r[1],r[0]))<0:_e($(i,r[2]),$(r[3],r[2]))<0)];return s[0]?n>0?r[1]:r[0]:s[1]?n>0?r[2]:r[1]:s[2]?n>0?r[3]:r[2]:n>0?r[0]:r[3]},Za=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),oo=(e,t,n)=>{Le(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},ro=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(fe(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(_(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},Vt=class{static unbindAffected(t,n,i){n&&ro(t,n,o=>{!o||o.isDeleted||oo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:oi(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||ro(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(_(n)&&i(o,{boundElements:oi(o.boundElements,new Set,new Array(n))}),ne(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:oi(o.boundElements,new Set,new Array(n))}))))})}},$t=class{static unbindAffected(t,n,i){n&&oo(t,n,o=>{!o||o.isDeleted||ro(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||oo(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:oi(n.boundElements,new Set([s]))});return}ne(o)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===o.id?o.containerId!==n.id&&i(o,{containerId:n.id}):(o.containerId!==null&&i(o,{containerId:null}),i(n,{boundElements:oi(n.boundElements,new Set([o.id]))})))})}},eo=(e,t,n)=>{let[i,o]=Ar(e);return ae(k(t.x+t.width*i,t.y+t.height*o),me(t,n),t.angle)},Jp=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?eo(e.startBinding.fixedPoint,n,t):k(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?eo(e.endBinding.fixedPoint,i,t):k(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},qa=(e,t)=>{let[n,i]=Jp(e,t);return[Y.pointFromAbsoluteCoords(e,n,t),Y.pointFromAbsoluteCoords(e,i,t)]},Ar=e=>e&&(Math.abs(e[0]-.5)<1e-4||Math.abs(e[1]-.5)<1e-4)?e.map(t=>Math.abs(t-.5)<1e-4?.5001:t):e;var Dr=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>B(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},Y=class e{elementId;selectedPointsIndices;pointerDownState;isDragging;lastUncommittedPoint;pointerOffset;startBindingElement;endBindingElement;hoverPointIndex;segmentMidPointHoveredCoords;elbowed;customLineAngle;constructor(t,n){this.elementId=t.id,Qa(t.points[0],B(0,0))||(console.error("Linear element is not normalized",Error().stack),ye(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.startBindingElement="keep",this.endBindingElement="keep",this.pointerDownState={prevSelectedPointsIndices:null,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:null,segmentMidpoint:{value:null,index:null,added:!1}},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.elbowed=G(t)&&t.elbowed,this.customLineAngle=null}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.editingLinearElement||!n.selectionElement)return!1;let{editingLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[c,d,u,p]=H(n.selectionElement,o),f=e.getPointsGlobalCoordinates(l,o).reduce((E,h,g)=>((h[0]>=c&&h[0]<=u&&h[1]>=d&&h[1]<=p||t.shiftKey&&s?.includes(g))&&E.push(g),E),[]).filter(E=>!(G(l)&&E!==0&&E!==l.points.length-1));i({editingLinearElement:{...r,selectedPointsIndices:f.length?f:null}})}static handlePointDragging(t,n,i,o,r){if(!r)return null;let{elementId:s}=r,a=n.scene.getNonDeletedElementsMap(),l=e.getElement(s,a),c=r.customLineAngle;if(!l||G(l)&&!r.pointerDownState.lastClickedIsEndPoint&&r.pointerDownState.lastClickedPoint!==0)return null;let d=G(l)?[r.selectedPointsIndices?.includes(0)?0:void 0,r.selectedPointsIndices?.find(m=>m>0)?l.points.length-1:void 0].filter(m=>m!==void 0):r.selectedPointsIndices,u=G(l)?r.pointerDownState.lastClickedPoint>0?l.points.length-1:0:r.pointerDownState.lastClickedPoint,p=l.points[u];if(d&&p){if(Ja(t)&&d.length===1&&l.points.length>1){let h=d[0],g=l.points[h===0?1:h-1];c=r.customLineAngle??Math.atan2(l.points[h][1]-g[1],l.points[h][0]-g[0]);let[x,y]=e._getShiftLockedDelta(l,a,g,B(i,o),t[Ln.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),c);e.movePoints(l,n.scene,new Map([[h,{point:B(x+g[0],y+g[1]),isDragging:h===u}]]))}else{let h=e.createPointAt(l,a,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Ln.CTRL_OR_CMD]?null:n.getEffectiveGridSize()),g=h[0]-p[0],x=h[1]-p[1];e.movePoints(l,n.scene,new Map(d.map(y=>{let b=y===u?e.createPointAt(l,a,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Ln.CTRL_OR_CMD]?null:n.getEffectiveGridSize()):B(l.points[y][0]+g,l.points[y][1]+x);return[y,{point:b,isDragging:y===u}]})))}Z(l,a)&&dn(l,n.scene,!1);let f=[];if(Qo(l,!1)){let h=d[0]===0,g=d[d.length-1]===l.points.length-1,x=[];!h!=!g?x.push({x:i,y:o}):(h&&x.push(vr(e.getPointGlobalCoordinates(l,l.points[0],a))),g&&x.push(vr(e.getPointGlobalCoordinates(l,l.points[d[d.length-1]],a)))),x.length&&(f=Ya(l,x,n.scene,n.state.zoom))}let E={...r,selectedPointsIndices:d,segmentMidPointHoveredCoords:u!==0&&u!==l.points.length-1?this.getPointGlobalCoordinates(l,p,a):null,hoverPointIndex:u===0||u===l.points.length-1?u:-1,isDragging:!0,customLineAngle:c};return{...n.state,editingLinearElement:n.state.editingLinearElement?E:null,selectedLinearElement:E,suggestedBindings:f}}return null}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),s=o.getNonDeletedElements(),a=om(t,i),{elementId:l,selectedPointsIndices:c,isDragging:d,pointerDownState:u}=n,p=e.getElement(l,r);if(!p)return n;let m={};if(d&&c){for(let f of c)if(f===0||f===p.points.length-1){rm(p.points,i.zoom.value)&&(ln(p)&&o.mutateElement(p,{...nl(p,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(p,o,new Map([[f,{point:f===0?p.points[p.points.length-1]:p.points[0]}]])));let E=Mr(i)?Wt((c?.length??0)>1?vr(e.getPointAtIndexGlobalCoordinates(p,f,r)):a,s,r,i.zoom,G(p),G(p)):null;m[f===0?"startBindingElement":"endBindingElement"]=E}}return{...n,...m,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:d||t.shiftKey?!d&&t.shiftKey&&u.prevSelectedPointsIndices?.includes(u.lastClickedPoint)?c&&c.filter(f=>f!==u.lastClickedPoint):c:c?.includes(u.lastClickedPoint)?[u.lastClickedPoint]:c,isDragging:!1,pointerOffset:{x:0,y:0},customLineAngle:null}}static getEditorMidPoints=(t,n,i)=>{let o=Z(t,n);if(!G(t)&&!i.editingLinearElement&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!G(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.editingLinearElement&&!G(s))return null;let c=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,d=t.segmentMidPointHoveredCoords;if(d&&Dn(B(d[0],d[1]),B(n.x,n.y))<=c)return d;let u=0,p=e.getEditorMidPoints(s,o,i);for(;u<p.length;){if(p[u]!==null&&Dn(p[u],B(n.x,n.y))<=c)return p[u];u++}return null};static isSegmentTooShort(t,n,i,o,r){if(G(t))return o>=0&&o<t.points.length?Dn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=Dn(n,i);if(t.points.length>2&&t.roundness){let[a,l]=tl(t);At(a.length===0&&l.length>0,"Only linears built out of curves are supported"),At(a.length+l.length>=o,"Invalid segment index while calculating mid point"),s=tm(l[o])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(G(t)){At(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=Ka(t.points[n-1],t.points[n]);return B(t.x+r[0],t.y+r[1])}let[i,o]=tl(t);if(At(i.length===0&&o.length>0||i.length>0&&o.length===0,"Only linears built out of either segments or curves are supported"),At(i.length+o.length>=n,"Invalid segment index while calculating mid point"),i.length){let r=i[n-1];return Ka(r[0],r[1])}if(o.length){let r=o[n-1];return nm(r,.5)}At(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),c=s.getNonDeletedElements(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:u}=r,p=e.getElement(u,l);if(!p)return d;let m=e.getSegmentMidpointHitCoords(r,o,a,l),f=null;if(m)f=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.editingLinearElement)return r.lastUncommittedPoint==null&&(s.mutateElement(p,{points:[...p.points,e.createPointAt(p,l,o.x,o.y,t[Ln.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:{x:o.x,y:o.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:[p.points.length-1],lastUncommittedPoint:null,endBindingElement:Wt(o,c,l,n.state.zoom,r.elbowed)},d.didAddPoint=!0,d;let E=e.getPointIndexUnderCursor(p,l,a.zoom,o.x,o.y);if(E>=0||m)d.hitElement=p;else{let{startBindingElement:v,endBindingElement:T}=r;Mr(a)&&Qo(p)&&Tr(p,v,T,s)}let[h,g,x,y]=H(p,l),b=(h+x)/2,w=(g+y)/2,I=E>-1&&Te(B(p.x+p.points[E][0],p.y+p.points[E][1]),B(b,w),p.angle),M=E>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(E)?sm([...r.selectedPointsIndices||[],E]):[E]:null;return d.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:E,lastClickedIsEndPoint:E===p.points.length-1,origin:{x:o.x,y:o.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:M,pointerOffset:I?{x:o.x-I[0],y:o.y-I[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Qa(t,n)}static handlePointerMove(t,n,i,o){let r=o.state;if(!r.editingLinearElement)return null;let{elementId:s,lastUncommittedPoint:a}=r.editingLinearElement,l=o.scene.getNonDeletedElementsMap(),c=e.getElement(s,l);if(!c)return r.editingLinearElement;let{points:d}=c,u=d[d.length-1];if(!t.altKey)return u===a&&e.deletePoints(c,o,[d.length-1]),{...r.editingLinearElement,lastUncommittedPoint:null};let p;if(Ja(t)&&d.length>=2){let m=d[d.length-2],[f,E]=e._getShiftLockedDelta(c,l,m,B(n,i),t[Ln.CTRL_OR_CMD]?null:o.getEffectiveGridSize());p=B(f+m[0],E+m[1])}else p=e.createPointAt(c,l,n-r.editingLinearElement.pointerOffset.x,i-r.editingLinearElement.pointerOffset.y,t[Ln.CTRL_OR_CMD]||G(c)?null:o.getEffectiveGridSize());return u===a?e.movePoints(c,o.scene,new Map([[c.points.length-1,{point:p}]])):e.addPoints(c,o.scene,[p]),{...r.editingLinearElement,lastUncommittedPoint:c.points[c.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=H(t,i),l=(o+s)/2,c=(r+a)/2,{x:d,y:u}=t;return Te(B(d+n[0],u+n[1]),B(l,c),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=H(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(c=>{let{x:d,y:u}=t;return Te(B(d+c[0],u+c[1]),B(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[r,s,a,l]=H(t,i),c=(r+a)/2,d=(s+l)/2,u=t.points[o],{x:p,y:m}=t;return u?Te(B(p+u[0],m+u[1]),B(c,d),t.angle):Te(B(p,m),B(c,d),t.angle)}static pointFromAbsoluteCoords(t,n,i){if(G(t))return B(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=H(t,i),l=(o+s)/2,c=(r+a)/2,[d,u]=Te(B(n[0],n[1]),B(l,c),-t.angle);return B(d-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Dn(B(o,r),B(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=el(i,o,r),[a,l,c,d]=H(t,n),u=(a+c)/2,p=(l+d)/2,[m,f]=Te(B(s[0],s[1]),B(u,p),-t.angle);return B(m-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=Dr(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){At(t.editingLinearElement,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.editingLinearElement,s=e.getElement(r,i);At(s,"The linear element does not exist in the provided Scene"),At(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],c=!1,d=-1,u=a.reduce((p,m,f)=>{if(++d,p.push(m),o.includes(f)){let h=a[f+1];h||(c=!0),p.push(h?B((m[0]+h[0])/2,(m[1]+h[1])/2):B(m[0],m[1])),l.push(d+1),++d}return p},[]);if(n.mutateElement(s,{points:u}),c){let p=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:B(p[0]+30,p[1]+30)}]]))}return{...t,editingLinearElement:{...t.editingLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.editingLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((d,u)=>!i.includes(u));ln(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=B(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:c}=Dr({points:r});e._updatePoints(t,n.scene,a,l,c)}static addPoints(t,n,i){let o=[...t.points,...i];ln(t)&&t.polygon&&(o[0]=B(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=Dr({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o){let{points:r}=t;if(ln(t)&&t.polygon){let d=i.get(0),u=i.get(r.length-1);d?i.set(r.length-1,{point:B(d.point[0],d.point[1]),isDragging:d.isDragging}):u&&i.set(0,{point:B(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=i.get(0)?.point??B(0,0),[a,l]=s,c=G(t)?[i.get(0)?.point??r[0],i.get(r.length-1)?.point??r[r.length-1]]:r.map((d,u)=>{let p=i.get(u)?.point??d;return B(p[0]-a,p[1]-l)});e._updatePoints(t,n,c,a,l,o,{isDragging:Array.from(i.values()).some(d=>d.isDragging)})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&G(r)||!r)return!1;let{segmentMidpoint:s}=t.pointerDownState;if(s.added||s.value===null||s.index===null||t.pointerDownState.origin===null)return!1;let a=t.pointerDownState.origin,l=Dn(B(a.x,a.y),B(n.x,n.y));return!(!i.editingLinearElement&&l<im/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.pointerDownState,c={pointerDownState:t.pointerDownState,selectedPointsIndices:t.selectedPointsIndices},d=e.createPointAt(a,s,n.x,n.y,o&&!G(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),d,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),c.pointerDownState={...t.pointerDownState,segmentMidpoint:{...t.pointerDownState.segmentMidpoint,added:!0},lastClickedPoint:l.index},c.selectedPointsIndices=[l.index],c}static _updatePoints(t,n,i,o,r,s,a){if(G(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding!==null&&Qn(s.startBinding)?s.startBinding:null),s?.endBinding!==void 0&&(l.endBinding=s.endBinding!==null&&Qn(s.endBinding)?s.endBinding:null),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1})}else{let l=Lr(t,i),c=Lr(t,t.points),d=(l[0]+l[2])/2,u=(l[1]+l[3])/2,p=(c[0]+c[2])/2,m=(c[1]+c[3])/2,f=p-d,E=m-u,h=Te(B(o,r),B(f,E),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+h[0],y:t.y+h[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(G(t))return[o[0]-a[0],o[1]-a[1]];let[l,c]=el(o[0],o[1],r),{width:d,height:u}=il(a[0],a[1],l,c,s);return Te(B(d,u),B(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&ye(n,i,{isDeleted:!0});let r=0,s=0;if(t.points.length%2===1){let a=Math.floor(t.points.length/2),l=e.getPointGlobalCoordinates(t,t.points[a],i);r=l[0]-n.width/2,s=l[1]-n.height/2}else{let a=t.points.length/2-1,l=e.getSegmentMidPoint(t,a+1);r=l[0]-n.width/2,s=l[1]-n.height/2}return{x:r,y:s}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,c=(r+a)/2,d=(s+l)/2,{x:u,y:p}=e.getBoundTextElementPosition(t,o,n),m=u+o.width,f=p+o.height,E=B(c,d),h=Te(B(r,s),E,t.angle),g=Te(B(a,s),E,t.angle),x=Te(B(u,p),E,-t.angle),y=Te(B(m,p),E,-t.angle),b=Te(B(u,f),E,-t.angle),w=Te(B(m,f),E,-t.angle);return h[0]<g[0]&&h[1]>=g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(y[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):h[0]>=g[0]&&h[1]>g[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],y[0])),s=Math.min(s,b[1]),l=Math.max(l,y[1])):h[0]>=g[0]?(r=Math.min(r,y[0]),a=Math.max(a,b[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):h[1]<=g[1]&&(r=Math.min(r,Math.min(y[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,y[1]),l=Math.max(l,b[1])),[r,s,a,l,c,d]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o,r,s,a,l;if(t.points.length<2||!be.get(t)){let{minX:p,minY:m,maxX:f,maxY:E}=t.points.reduce((h,[g,x])=>(h.minY=Math.min(h.minY,x),h.minX=Math.min(h.minX,g),h.maxX=Math.max(h.maxX,g),h.maxY=Math.max(h.maxY,x),h),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});r=p+t.x,s=m+t.y,a=f+t.x,l=E+t.y}else{let p=be.generateElementShape(t,null),m=gt(p[0]),[f,E,h,g]=si(m);r=f+t.x,s=E+t.y,a=h+t.x,l=g+t.y}let c=(r+a)/2,d=(s+l)/2;if(o=[r,s,a,l,c,d],!i)return o;let u=Z(t,n);return u&&(o=e.getMinMaxXYWithBoundText(t,n,[r,s,a,l],u)),o};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!G(a))return t;if(n&&n>0&&n<a.points.length){let l=ke(Mt(em(a.points[n],a.points[n-1]))),c=(a.fixedSegments??[]).reduce((m,f)=>(m[f.index]=f,m),{});c[n]={index:n,start:B(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:B(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let d=Object.values(c).sort((m,f)=>m.index-f.index),u=d.map(m=>m.index).reduce((m,f)=>f<n?m+1:m,0);r.mutateElement(a,{fixedSegments:d});let p=B(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:p,pointerDownState:{...t.pointerDownState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:p}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},sm=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null};P();import{arrayToMap as mt}from"@excalidraw/common";import{isPointWithinBounds as Mm,pointFrom as kr}from"@excalidraw/math";P();import{vectorCross as al,vectorFromPoint as ao}from"@excalidraw/math";function ol(e){return[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])]}function am(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var lm=1e-6;function rl(e,t){let n=ao(e[1],e[0]),i=ao(t,e[0]),o=al(n,i);return Math.abs(o)<lm}function Cr(e,t){let n=ao(e[1],e[0]),i=ao(t,e[0]);return al(n,i)<0}function sl(e,t){return rl(e,t[0])||rl(e,t[1])||(Cr(e,t[0])?!Cr(e,t[1]):Cr(e,t[1]))}function ll(e,t){return am(ol(e),ol(t))&&sl(e,t)&&sl(t,e)}P();import{arrayToMap as cm}from"@excalidraw/common";import{getElementBounds as dm}from"@excalidraw/element";import{isArrowElement as um,isExcalidrawElement as pm,isFreeDrawElement as mm,isLinearElement as fm,isTextElement as hm}from"@excalidraw/element";import{rangeIncludesValue as lo,pointFrom as vt,pointRotateRads as Em,rangeInclusive as co}from"@excalidraw/math";var gm=e=>e.type==="diamond"?[vt(e.width/2,0),vt(e.width,e.height/2),vt(e.width/2,e.height),vt(0,e.height/2)]:[vt(0,0),vt(0+e.width,0),vt(0+e.width,e.height),vt(0,e.height)],xm=e=>fm(e)||mm(e)?e.points:gm(e),cl=e=>{let t=e.reduce((n,[i,o])=>(n.minY=Math.min(n.minY,o),n.minX=Math.min(n.minX,i),n.maxX=Math.max(n.maxX,i),n.maxY=Math.max(n.maxY,o),n),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},ul=e=>{let t=xm(e),{cx:n,cy:i}=cl(t),o=vt(n,i),r=t.map(d=>Em(d,o,e.angle)),{minX:s,minY:a,maxX:l,maxY:c}=cl(r);return[s+e.x,a+e.y,l+e.x,c+e.y]},dl=(e,t,n=!1)=>{let i=ul(e),o=t[0]<=i[0]&&t[2]>=i[2]&&t[1]<=i[1]&&t[3]>=i[3];return n?o?!0:i[0]<=t[0]&&i[2]>=t[2]&&i[1]<=t[1]&&i[3]>=t[3]:o},wm=(e,t)=>{let n=ul(e);return(lo(n[0],co(t[0],t[2]))||lo(t[0],co(n[0],n[2])))&&(lo(n[1],co(t[1],t[3]))||lo(t[1],co(n[1],n[3])))},pl=({elements:e,bounds:t,type:n,errorMargin:i=0})=>{pm(t)&&(t=dm(t,cm(e)));let o=[t[0]-i,t[1]-i,t[2]+i,t[3]+i],r=new Set;for(let s of e){if(r.has(s.id))continue;if(n==="overlap"?wm(s,o):n==="inside"?dl(s,o):dl(s,o,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);hm(s)&&s.containerId&&r.add(s.containerId),um(s)&&(s.startBinding&&r.add(s.startBinding.elementId),s.endBinding&&r.add(s.endBinding?.elementId))}}return e.filter(s=>r.has(s.id))};P();import{arrayToMap as Pm,isShallowEqual as Im}from"@excalidraw/common";P();var ym=(e,t,n)=>{let i=n.reduce((o,r)=>(r.groupIds.includes(e)&&(o[r.id]=!0),o),{});return Object.keys(i).length<2?t.selectedGroupIds[e]||t.editingGroupId===e?{selectedElementIds:t.selectedElementIds,selectedGroupIds:{...t.selectedGroupIds,[e]:!1},editingGroupId:null}:t:{editingGroupId:t.editingGroupId,selectedGroupIds:{...t.selectedGroupIds,[e]:!0},selectedElementIds:{...t.selectedElementIds,...i}}},ml=function(){let e=null,t=null,n=null,i=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let c={};for(let p of r){let m=p.groupIds;if(a.editingGroupId){let f=m.indexOf(a.editingGroupId);f>-1&&(m=m.slice(0,f))}if(m.length>0){let f=m[m.length-1];c[f]=!0}}let d={},u=s.reduce((p,m)=>{if(m.isDeleted)return p;let f=m.groupIds.find(E=>c[E]);return f&&(p[m.id]=!0,Array.isArray(d[f])?d[f].push(m.id):d[f]=[m.id]),p},{});for(let p of Object.keys(d))d[p].length<2&&c[p]&&(c[p]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:c,selectedElementIds:Br({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let c=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):pt(s,r);return c.length?i(c,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Br(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),Fy=(e,t)=>Gr(e,t)!=null,Gr=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Ny=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),fl=(e,t)=>{let n={...t,selectedGroupIds:{}};for(let i of e){let o=i.groupIds;if(t.editingGroupId){let r=o.indexOf(t.editingGroupId);r>-1&&(o=o.slice(0,r))}if(o.length>0){let r=o[o.length-1];n={...n,...ym(r,n,e)}}}return n.selectedGroupIds},zy=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),bm=(e,t)=>e.groupIds.includes(t),Ae=(e,t)=>{let n=[];for(let i of e.values())bm(i,t)&&n.push(i);return n},Hy=(e,t)=>e.groupIds.find(n=>t[n]),_y=(e,t,n)=>{let i=[...e],o=n?i.indexOf(n):-1,r=o>-1?o:i.length;return i.splice(r,0,t),i},Yy=(e,t)=>e.filter(n=>!t[n]),uo=(e,t)=>{let n=new Map;return e.forEach(i=>{let o=i.groupIds.length===0?i.id:i.groupIds[i.groupIds.length-1],r=n.get(o)||[],s=Z(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},hl=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},El=e=>{let t=e.flatMap(o=>o.groupIds),n=new Map,i=0;for(let o of t)n.set(o,(n.get(o)??0)+1),n.get(o)>i&&(i=n.get(o));return i===e.length},gl=e=>e.groupIds.length>0,xl=(e,t,n)=>{let i=[...e],o=t?e.indexOf(t):-1,r=o>-1?o:e.length;for(let s=0;s<r;s++)i[s]=n(i[s]);return i};var wl=e=>{let t=new Set;return e.forEach(n=>{V(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},Or=(e,t,n,i=!0)=>{let[o,r,s,a]=H(t,n),l=e.filter(c=>{let[d,u,p,m]=he(c,n),f=Dt(c,n);if(f){let[E,h,g,x]=he(f,n);d=Math.max(E,d),u=Math.max(h,u),p=Math.min(g,p),m=Math.min(x,m)}return c.locked===!1&&c.type!=="selection"&&!fe(c)&&o<=d&&r<=u&&s>=p&&a>=m});return l=i?wl(l):l,l=l.filter(c=>{let d=Dt(c,n);return d?Zt(c,d,n):!0}),l},Qy=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=yl(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},Jy=function(){let e=null,t=null,n=null,i=(o,r)=>(n!=null&&o===e&&r.selectedElementIds===t||(n=o.some(s=>r.selectedElementIds[s.id]),e=o,t=r.selectedElementIds),n);return i.clearCache=()=>{e=null,t=null,n=null},i}(),pt=(e,t,n)=>{let i=new Set,o=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){o.push(r),i.add(r.id);continue}if(n?.includeBoundTextElement&&fe(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{V(s)&&qt(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},eb=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:pt(e,t,{includeBoundTextElement:!0}),Br=(e,t)=>Im(t.selectedElementIds,e)?t.selectedElementIds:e,Sm=(e,t)=>{let n=e.filter(U);if(n.length===1){let i=n[0],o=i.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===i.id||o.includes(s.id)))return new Y(i,Pm(t))}return null},tb=(e,t,n)=>({selectedLinearElement:Sm(e,t),...ml({editingGroupId:n.editingGroupId,selectedElementIds:wl(e).reduce((i,o)=>(fe(o)||(i[o.id]=!0),i),{})},t,n,null)});var bl=(e,t,n)=>{let i=mt(e);for(let o of t)if(o.frameId){let r=n.get(o.id),s=n.get(o.frameId),a=r&&i.get(r);a&&ye(a,i,{frameId:s??null})}};function Cn(e,t,n){let i=Rr(t,n),o=Rr(e,n);return i.some(s=>o.some(a=>ll(s,a)))}var Pl=(e,t,n)=>po(Or(e,t,n,!1)).filter(i=>!V(i)&&!i.frameId||i.frameId===t.id),Fr=(e,t,n)=>Or([t],e,n).some(i=>i.id===t.id),fb=(e,t)=>{let n=mt(e);return e.filter(i=>Cn(i,t,n))},Kt=(e,t,n)=>{let[i,o,r,s]=H(t,n),[a,l,c,d]=tt(e);return i<=a&&o<=l&&r>=c&&s>=d},Zt=(e,t,n)=>Kt([e],t,n)||Cn(e,t,n)||Fr(e,t,n),hb=(e,t,n)=>{let[i,o,r,s]=H(t,n);return Mm(kr(i,o),kr(e.x,e.y),kr(r,s))},Eb=(e,t,n)=>{let i=mt(e),o=t.flatMap(r=>Ae(e,r));return o.length===0?!0:!!o.find(r=>Kt([r],n,i)||Cn(r,n,i))},gb=(e,t,n)=>{let i=mt(e),o=t.flatMap(r=>Ae(e,r));return o.length===0?!0:o.find(r=>Kt([r],n,i)||Cn(r,n,i))===void 0},xb=e=>{let t=new Map;for(let n of e){let i=V(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,qt(e,i))}return t},qt=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Tm=e=>e.filter(t=>V(t)),wb=e=>{let t=mt(Tm(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},yb=(e,t,n,i)=>{let o=qt(e,t.id),r=new Set(o),s=new Set([...Pl(e,t,i),...o.filter(p=>Fr(p,t,i))]),a=o.filter(p=>!s.has(p)),l=new Set(Array.from(s).flatMap(p=>p.groupIds));for(let p of a)if(!Cn(p,t,i))p.groupIds.length===0&&r.delete(p);else if(p.groupIds.length>0)for(let m of p.groupIds)l.add(m);for(let p of a)if(p.groupIds.length>0){let m=!0;for(let f of p.groupIds)l.has(f)&&(m=!1);m&&r.delete(p)}let c=Array.from(s).filter(p=>p.groupIds.length===0);for(let p of c)r.add(p);let d=Array.from(s).filter(p=>p.groupIds.length>0),u=fl(d,n);for(let[p,m]of Object.entries(u))if(m){let f=Ae(e,p);if(Kt(f,t,i))for(let E of f)r.add(E)}return[...r].filter(p=>!(ne(p)&&p.containerId))},bb=(e,t,n)=>Am(po(e,Pl(e,t,n)),t,n),Am=(e,t,n)=>{let i=[],o=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>o.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>Ae(n,l)));s=!Kt(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Dt=(e,t)=>e.frameId&&t.get(e.frameId)||null,Pb=(e,t)=>{let n=new Set,i=mt(e);e=po(e);for(let s of e)V(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(V(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!o.has(a)){o.add(a);let l=Ae(e,a);if(l.some(c=>Zt(c,t,i)))for(let c of l)r.push(c)}}else Zt(s,t,i)&&r.push(s);return r},vm=(e,t,n,i)=>{let o=mt(e),r=new Map;for(let c of e.values())c.frameId===n.id&&r.set(c.id,!0);let s=new Set(t.map(c=>c.id)),a=[],l=new Set;for(let c of t)V(c)&&c.id!==n.id&&l.add(c.id);for(let c of po(e,t)){if(V(c)||c.frameId&&l.has(c.frameId)||c.frameId&&i.selectedElementIds[c.id]&&i.selectedElementIds[c.frameId])continue;r.has(c.id)||a.push(c);let d=Z(c,o);d&&!s.has(d.id)&&!r.has(d.id)&&a.push(d)}for(let c of a)ye(c,o,{frameId:n.id});return e},Il=(e,t)=>{let n=new Map,i=new Map;for(let o of e)if(o.frameId){n.set(o.id,o);let r=i.get(o.frameId)||[];r.push(o);let s=Z(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)ye(o,t,{frameId:null})},Dm=(e,t)=>{let n=qt(e,t.id);return Il(n,mt(e)),e},Ib=(e,t,n,i)=>vm(Dm(e,n),t,n,i.state).slice(),Sb=(e,t,n)=>{let i=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),o=new Set(i);if(t.editingGroupId)for(let a of i)a.groupIds.length===0?o.add(a):a.groupIds.flatMap(l=>Ae(e,l)).forEach(l=>o.add(l));let r=new Set,s=mt(e);return o.forEach(a=>{a.frameId&&!V(a)&&!Sl(a,s,t)&&r.add(a)}),r.size>0&&Il(r,s),e},po=(e,t)=>{let n=new Set,i=t||e;for(let s of i.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let o=new Set;for(let s of n)Ae(e,s).some(a=>V(a))&&o.add(s);let r=[];for(let s of i.values())o.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},Lm=(e,t,n)=>{let i=ne(e)&&Ce(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Dt(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Dt(i,t)},Sl=(e,t,n,i)=>{let o=i?.targetFrame??Lm(e,t,n);if(!o)return!1;let r=ne(e)&&Ce(e,t)||e,s=l=>{i?.checkedGroups&&r.groupIds.forEach(c=>{i.checkedGroups?.set(c,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[o.id])return!0;if(r.groupIds.length===0)return Zt(r,o,t);for(let l of r.groupIds)if(i?.checkedGroups?.has(l))return i.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>i?.checkedGroups?!i.checkedGroups.has(l):!0).flatMap(l=>Ae(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(pt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(d=>{a.delete(d)})}for(let l of a)if(V(l))return s(!1),!1;for(let l of a)if(Zt(l,o,t))return s(!0),!0;return!1},Mb=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Cn(e,t,i)||Fr(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Kt([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=Sl(e,i,n,{targetFrame:t,checkedGroups:o});else{s=e.frameId===t.id;for(let a of e.groupIds)o?.set(a,s)}for(let a of e.groupIds)o?.set(a,s);return s}return!1},Cm="Frame",Bm="AI Frame",Gm=e=>ki(e)?Cm:Bm,Tb=e=>e.name===null?Gm(e):e.name,Ab=(e,t)=>pl({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),vb=e=>{let t=mt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Hm="invert(100%) hue-rotate(180deg) saturate(1.25)",vl=(e,t)=>zt(e)&&!t.imageCache.has(e.fileId),Dl=(e,t,n)=>n.theme===Al.DARK&&zt(e)&&!vl(e,t)&&t.imageCache.get(e.fileId)?.mimeType!==zr.svg,go=e=>{switch(e.type){case"freedraw":return e.strokeWidth*12;case"text":return e.fontSize/2;default:return 20}},_m=(e,t,n,i,o=1)=>{let r=(t?.opacity??100)*e.opacity/1e4*o;return(n.has(e.id)||i&&i.some(s=>s.id===e.id)||t&&n.has(t.id))&&(r*=Rm/100),r},Ym=(e,t,n)=>{let r=go(e),[s,a,l,c]=H(e,t),d=U(e)||Se(e)?Qt(s,l):e.width,u=U(e)||Se(e)?Qt(a,c):e.height,p=d*window.devicePixelRatio+r*2,m=u*window.devicePixelRatio+r*2,f=n.value;return(p*f>32767||m*f>32767)&&(f=Math.min(32767/p,32767/m)),p*m*f*f>16777216&&(f=Math.sqrt(16777216/(p*m))),p=Math.floor(p*f),m=Math.floor(m*f),{width:p,height:m,scale:f}},Ll=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=go(e),{width:l,height:c,scale:d}=Ym(e,t,n);if(!l||!c)return null;r.width=l,r.height=c;let u=-100,p=0;if(U(e)||Se(e)){let[g,x]=H(e,t);u=e.x>g?Qt(e.x,g)*window.devicePixelRatio*d:0,p=e.y>x?Qt(e.y,x)*window.devicePixelRatio*d:0,s.translate(u,p)}s.save(),s.translate(a*d,a*d),s.scale(window.devicePixelRatio*d,window.devicePixelRatio*d);let m=sn.canvas(r);Dl(e,i,o)&&(s.filter=Hm),ho(e,m,s,i,o),s.restore();let f=Z(e,t),E=document.createElement("canvas"),h=E.getContext("2d");if(_(e)&&f){let[g,x,y,b]=H(e,t),w=Math.max(Qt(g,y),Qt(x,b));E.width=w*window.devicePixelRatio*d+a*d*10,E.height=w*window.devicePixelRatio*d+a*d*10,h.translate(E.width/2,E.height/2),h.rotate(e.angle),h.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,I,M]=H(f,t);h.rotate(-e.angle);let v=(E.width-r.width)/2,T=(E.height-r.height)/2,F=E.width/2-(I-g)*window.devicePixelRatio*d-v-a*d,C=E.height/2-(M-x)*window.devicePixelRatio*d-T-a*d;h.translate(-F,-C),h.clearRect(-(f.width/2+mo)*window.devicePixelRatio*d,-(f.height/2+mo)*window.devicePixelRatio*d,(f.width+mo*2)*window.devicePixelRatio*d,(f.height+mo*2)*window.devicePixelRatio*d)}return{element:e,canvas:r,theme:o.theme,scale:d,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:p,boundTextElementVersion:Z(e,t)?.version||null,containingFrameOpacity:Dt(e,t)?.opacity||100,boundTextCanvas:E,angle:e.angle,imageCrop:xe(e)?e.crop:null}},Ub=14,Cl=typeof document<"u"?document.createElement("img"):{src:""};Cl.src=`data:${zr.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var Bl=typeof document<"u"?document.createElement("img"):{src:""};Bl.src=`data:${zr.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var Xm=(e,t)=>{t.fillStyle="#E7E7E7",t.fillRect(0,0,e.width,e.height);let n=Math.min(e.width,e.height),i=Math.min(n,Math.min(n*.4,100));t.drawImage(e.status==="error"?Bl:Cl,e.width/2-i/2,e.height/2-i/2,i,i)},ho=(e,t,n,i,o)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(be.get(e));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",be.get(e).forEach(r=>{t.draw(r)});break}case"freedraw":{n.save(),n.fillStyle=e.strokeColor;let r=Um(e),s=be.get(e);s&&t.draw(s),n.fillStyle=e.strokeColor,n.fill(r),n.restore();break}case"image":{let r=zt(e)?i.imageCache.get(e.fileId)?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,yt(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:c}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight};n.drawImage(r,s,a,l,c,0,0,e.width,e.height)}else Xm(e,n);break}default:if(ne(e)){let r=Nm(e.text),s=r&&!n.canvas.isConnected;s&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",r?"rtl":"ltr"),n.save(),n.font=Fm(e),n.fillStyle=e.strokeColor,n.textAlign=e.textAlign;let a=e.text.replace(/\r\n?/g,`
10
+ `)=>e.reduce((i,o)=>(q(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as Nr,distanceToLineSegment as zr,pointRotateRads as Hr}from"@excalidraw/math";import{ellipse as jm,ellipseDistanceFromPoint as Ym}from"@excalidraw/math/ellipse";var an=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return Xm(e,t,n);case"diamond":return $m(e,t,n);case"ellipse":return Vm(e,t,n);case"line":case"arrow":case"freedraw":return Zm(e,t,n)}},Xm=(e,t,n)=>{let i=ne(e,t),o=Hr(n,i,-e.angle),[r,s]=nn(e);return Math.min(...r.map(a=>zr(o,a)),...s.map(a=>Nr(a,o)).filter(a=>a!==null))},$m=(e,t,n)=>{let i=ne(e,t),o=Hr(n,i,-e.angle),[r,s]=on(e);return Math.min(...r.map(a=>zr(o,a)),...s.map(a=>Nr(a,o)).filter(a=>a!==null))},Vm=(e,t,n)=>{let i=ne(e,t);return Ym(Hr(n,i,-e.angle),jm(i,e.width/2,e.height/2))},Zm=(e,t,n)=>{let[i,o]=mo(e,t);return Math.min(...i.map(r=>zr(n,r)),...o.map(r=>Nr(r,n)))};var bo=e=>{if(e.type==="arrow")return!1;let t=!ml(e.backgroundColor)||wt(e)||co(e)||q(e);return e.type==="line"?t&&Cn(e.points):e.type==="freedraw"?t&&Cn(e.points):t||be(e)},_r=null,sl=null,al=1/0,ll=!1,dl=!1,bt=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(_r&&hl(e,_r)&&al<=n&&r===dl){let u=sl?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return ll}let s=o?Ur(he(o.x-n,o.y-n),e,he(o.x+o.width+n,o.y+o.height+n)):!1,a=se(t,i,!0);if(!El(e,a,t.angle,n)&&!s)return!1;let c=(r||bo(t))&&Rt(e,t,i)||cl(e,t,i,n)||s;return _r=e,sl=new WeakRef(t),al=n,dl=r,ll=c,c},El=(e,t,n,i=0)=>{let o=n===0?e:Ze(e,ln(t),-n);return Ur(he(t[0]-i,t[1]-i),o,he(t[2]+i,t[3]+i))},np=(e,t,n,i=0)=>{let o=se(t,n,!0);return El(e,o,t.angle,i)},kb=(e,t)=>!bt(e)&&!ip(e.point,e.element,t)&&np(e.point,e.element,t),ip=(e,t,n)=>{let i=V(t,n);if(!i)return!1;let o=K(t)?{...i,...G.getBoundTextElementPosition(t,i,n)}:i;return Rt(e,o,n)},gl=(e,[t,n],i,o=0)=>{let r=he(t,n),s=!Z(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=se(e,i);if(!It(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&Z(m)){let p=se(m,i);if(!ut(r,p))return!1}}let c=Pt(e,i,Ii(ne(e,i),r)),u=an(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},yo=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(ul(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),ce(s,!1)&&gl(s,e,n,i)&&(o.push(s),!ml(s.backgroundColor)))break}return o},_t=(e,t,n,i)=>{let o=yo(e,t,n,i);return!o||o.length===0?null:o.length===1?o[0]:o.sort((r,s)=>s.width**2+s.height**2-(r.width**2+r.height**2)).pop()},xl=(e,t,n,i,o)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];ul(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),ce(l,!1)&&gl(l,e,i,o)&&r.push(l)}if(!r||r.length===0)return null;if(r.length===1)return r[0];let s=r.filter(a=>an(a,i,e)<=Be(a,t)||Rt(e,a,i));return s.length===0?null:s[0]},Pt=(e,t,n,i=0,o=!1)=>{let r=[Math.min(n[0][0]-i,n[1][0]-i),Math.min(n[0][1]-i,n[1][1]-i),Math.max(n[0][0]+i,n[1][0]+i),Math.max(n[0][1]+i,n[1][1]+i)],s=se(e,t);if(!It(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return rp(e,t,n,i,o);case"diamond":return sp(e,t,n,i,o);case"ellipse":return ap(e,t,n,i);case"line":case"freedraw":case"arrow":return op(e,n,t,o)}},wl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Po(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!It(a,l))continue;let d=pl(s,t);if(d.length>0){for(let c of d)n.push(Ze(c,i,o));if(r)return n}}return n},bl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=fl(s,t);if(a&&(n.push(Ze(a,i,o)),r))return n}return n},op=(e,t,n,i=!1)=>{let[o,r]=mo(e,n),s=[];for(let a of o){let l=fl(a,t);if(l&&(s.push(l),i))return s}for(let a of r){let l=Po(a[0],a[1],a[2],a[3]),d=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!It(l,d))continue;let c=pl(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),i))return s}return s},rp=(e,t,n,i=0,o=!1)=>{let r=ne(e,t),s=Ze(n[0],r,-e.angle),a=Ze(n[1],r,-e.angle),l=Ii(s,a),[d,c]=nn(e,i),u=[];return bl(d,l,u,r,e.angle,o),o&&u.length>0||wl(c,l,u,r,e.angle,o),u},sp=(e,t,n,i=0,o=!1)=>{let r=ne(e,t),s=Ze(n[0],r,-e.angle),a=Ze(n[1],r,-e.angle),l=Ii(s,a),[d,c]=on(e,i),u=[];return bl(d,l,u,r,e.angle,o),o&&u.length>0||wl(c,l,u,r,e.angle,o),u},ap=(e,t,n,i=0)=>{let o=ne(e,t),r=Ze(n[0],o,-e.angle),s=Ze(n[1],o,-e.angle);return tp(ep(o,e.width/2+i,e.height/2+i),Ii(r,s)).map(a=>Ze(a,o,e.angle))},cl=(e,t,n,i=1)=>an(t,n,e)<=i,Rt=(e,t,n)=>{if((K(t)||Ee(t))&&!Cn(t.points))return!1;let[i,o,r,s]=se(t,n);if(!Ur(he(i,o),e,he(r,s)))return!1;let a=he((i+r)/2,(o+s)/2),l=qm(Jm(Qm(Km(e,a,.1)),Math.max(t.width,t.height)*2),a),d=Ii(e,l);return Pt(t,n,d).filter((u,m,p)=>p.findIndex(f=>hl(f,u))===m).length%2===1},Wr=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:m}=s,p=ne(s,n);if(s.type==="diamond"){let[h,E,g,x,w,b,y,I]=jn(s);return[he(l+h,d+E-a),he(l+g+a,d+x),he(l+w,d+b+a),he(l+y-a,d+I)].map(T=>Ze(T,p,m))}if(s.type==="ellipse"){let h=l+c/2,E=d+u/2,g=c/2,x=u/2;return[he(h,E-x-a),he(h+g+a,E),he(h,E+x+a),he(h-g-a,E)].map(b=>Ze(b,p,m))}return[he(l-a,d-a),he(l+c+a,d-a),he(l+c+a,d+u+a),he(l-a,d+u+a)].map(h=>Ze(h,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Rt(s,t,n))};P();import{invariant as yl,isDevEnv as lp,isTestEnv as dp}from"@excalidraw/common";import{pointFrom as dn,pointFromVector as Io,pointRotateRads as So,pointScaleFromOrigin as Ao,pointsEqual as cp,triangleIncludesPoint as jr,vectorCross as Ne,vectorFromPoint as Q,vectorScale as Mo}from"@excalidraw/math";var fe=[1,0],ye=[0,1],He=[-1,0],qe=[0,-1],Ut=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?fe:t<=-o?He:n>i?ye:qe},ze=(e,t)=>Ut(Q(e,t)),mt=(e,t)=>_e(ze(e,t)),pe=(e,t)=>e[0]===t[0]&&e[1]===t[1],_e=e=>pe(e,fe)||pe(e,He),_b=e=>!_e(e),up=(e,t,n)=>{let i=ln(t);(lp()||dp())&&(yl(e.width>0&&e.height>0,"Diamond element has no width or height"),yl(!cp(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Io(Mo(Q(So(dn(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Io(Mo(Q(So(dn(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Io(Mo(Q(So(dn(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Io(Mo(Q(So(dn(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Ne(Q(n,r),Q(r,s))<=0&&Ne(Q(n,r),Q(r,l))>0)return ze(r,i);if(Ne(Q(n,s),Q(s,a))<=0&&Ne(Q(n,s),Q(s,r))>0)return ze(s,i);if(Ne(Q(n,a),Q(a,l))<=0&&Ne(Q(n,a),Q(a,s))>0)return ze(a,i);if(Ne(Q(n,l),Q(l,r))<=0&&Ne(Q(n,l),Q(l,a))>0)return ze(l,i);if(Ne(Q(n,i),Q(r,i))<=0&&Ne(Q(n,i),Q(s,i))>0){let c=e.width>e.height?r:s;return ze(c,i)}else if(Ne(Q(n,i),Q(s,i))<=0&&Ne(Q(n,i),Q(a,i))>0){let c=e.width>e.height?a:s;return ze(c,i)}else if(Ne(Q(n,i),Q(a,i))<=0&&Ne(Q(n,i),Q(l,i))>0){let c=e.width>e.height?a:l;return ze(c,i)}let d=e.width>e.height?r:l;return ze(d,i)},Si=(e,t,n)=>{let o=ln(t);if(e.type==="diamond")return up(e,t,n);let r=Ao(dn(t[0],t[1]),o,2),s=Ao(dn(t[2],t[1]),o,2),a=Ao(dn(t[0],t[3]),o,2),l=Ao(dn(t[2],t[3]),o,2);return jr([r,s,o],n)?qe:jr([s,l,o],n)?fe:jr([l,a,o],n)?ye:He},Yr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Dp,randomInteger as ns,getUpdatedTimestamp as is}from"@excalidraw/common";P();import{clamp as To,pointDistance as Vr,pointFrom as Y,pointScaleFromOrigin as mp,pointsEqual as Mi,pointTranslate as $r,vector as St,vectorCross as vo,vectorFromPoint as Zr,vectorScale as pp}from"@excalidraw/math";import{BinaryHeap as fp,invariant as Xn,isAnyTrue as hp,getSizeFromPoints as Pl,isDevEnv as Ep,arrayToMap as gp}from"@excalidraw/common";var qr=1,ee=40,xp=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>Y(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=ze(s,l[a-1]),c=ze(l[a-1],l[a-2]);if(pe(d,c)){let u=n?.findIndex(p=>p.index===a-1)??-1,m=n?.findIndex(p=>p.index===a)??-1;m!==-1&&(n[m].start=Y(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(p=>{p.index>a-1&&(p.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(Vr(l[a-2],l[a-1])<qr){let d=n?.findIndex(m=>m.index===a-2)??-1,c=n?.findIndex(m=>m.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),o.splice(-2,2),n.forEach(m=>{m.index>a-2&&(m.index-=2)});let u=mt(s,l[a-1]);return o.push(Y(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}o.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==o.length-1);return r.length===0?Wt(Jr(es(Qr(e,Kr(e,t,o.map(s=>Y(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(Ep()&&Xn(Dl(o),"Invalid elbow points with fixed segments"),Wt(o,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},wp=(e,t,n)=>{let i=t.map(S=>S.index),r=(e.fixedSegments?.map(S=>S.index)??[]).findIndex(S=>!i.includes(S));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,m=l?null:e.endBinding,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...w}=Kr({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[Y(0,0),Y(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:b}=Wt(Jr(es(Qr(e,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...w})??[])),t,null,null);if(!b||b.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let y=[];if(a)for(let S=0;S<a.index;S++)y.push(Y(e.x+e.points[S][0],e.y+e.points[S][1]));if(b.forEach(S=>{y.push(Y(e.x+(a?a.end[0]:0)+S[0],e.y+(a?a.end[1]:0)+S[1]))}),l)for(let S=l.index;S<e.points.length;S++)y.push(Y(e.x+e.points[S][0],e.y+e.points[S][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,M=t.map(S=>S.index>s?{...S,index:S.index-I+(b.length-1)}:S),T=y.flatMap((S,B)=>{let L=y[B-1],k=y[B+1];if(L&&k){let C=ze(S,L),X=ze(k,S);if(pe(C,X))return M.forEach(_=>{_.index>B&&(_.index-=1)}),[];if(pe(C,Yr(X)))return M.forEach(_=>{_.index>B&&(_.index+=1)}),[S,S]}return[S]});return Wt(T,M,!1,!1)},bp=(e,t,n,i,o,r)=>{let s=t.map((y,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==y.index||(y.start[0]!==e.fixedSegments[I].start[0]&&y.end[0]!==e.fixedSegments[I].end[0])!=(y.start[1]!==e.fixedSegments[I].start[1]&&y.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(y=>y!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(y=>y.index===1)??-1,l=e.fixedSegments?.findIndex(y=>y.index===e.points.length-1)??-1,d=Vr(t[s].start,t[s].end),c=d<ee+5;if(a===-1&&t[s].index===1&&o){let y=_e(n),M=(y?pe(n,fe):pe(n,ye))?c?d/2:ee:c?-d/2:-ee;t[s].start=Y(t[s].start[0]+(y?M:0),t[s].start[1]+(y?0:M))}if(l===-1&&t[s].index===e.points.length-1&&r){let y=_e(i),M=(y?pe(i,fe):pe(i,ye))?c?d/2:ee:c?-d/2:-ee;t[s].end=Y(t[s].end[0]+(y?M:0),t[s].end[1]+(y?0:M))}let u=t.map(y=>({...y,start:Y(e.x+y.start[0],e.y+y.start[1]),end:Y(e.x+y.end[0],e.y+y.end[1])})),m=e.points.map((y,I)=>Y(e.x+y[0],e.y+y[1])),p=u[s].index-1,f=u[s].index,h=u[s].start,E=u[s].end,g=m[p-1]&&!Mi(m[p],m[p-1])?mt(m[p-1],m[p]):void 0,x=m[f+1]&&!Mi(m[f],m[f+1])?mt(m[f+1],m[f]):void 0;if(g!==void 0){let y=g?1:0;m[p-1][y]=h[y]}if(m[p]=h,m[f]=E,x!==void 0){let y=x?1:0;m[f+1][y]=E[y]}let w=u.findIndex(y=>y.index===p);if(w!==-1){let y=mt(u[w].end,u[w].start)?1:0;u[w].start[y]=h[y],u[w].end=h}let b=u.findIndex(y=>y.index===f+1);if(b!==-1){let y=mt(u[b].end,u[b].start)?1:0;u[b].end[y]=E[y],u[b].start=E}if(a===-1&&p===0){let y=o?_e(n):mt(m[1],m[0]);m.unshift(Y(y?h[0]:e.x+e.points[0][0],y?e.y+e.points[0][1]:h[1])),o&&m.unshift(Y(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=o?2:1}if(l===-1&&f===e.points.length-1){let y=_e(i);m.push(Y(y?E[0]:e.x+e.points[e.points.length-1][0],y?e.y+e.points[e.points.length-1][1]:E[1])),r&&m.push(Y(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return Wt(m,u.map(y=>({...y,start:Y(y.start[0]-e.x,y.start[1]-e.y),end:Y(y.end[0]-e.x,y.end[1]-e.y)})),!1,!1)},yp=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((E,g)=>g===0?Y(e.x+E[0],e.y+E[1]):g===t.length-1?Y(e.x+E[0],e.y+E[1]):Y(e.x+e.points[g][0],e.y+e.points[g][1])),m=n.map(E=>({...E,start:Y(e.x+(E.start[0]-t[0][0]),e.y+(E.start[1]-t[0][1])),end:Y(e.x+(E.end[0]-t[0][0]),e.y+(E.end[1]-t[0][1]))})),p=[],f=2+(d?1:0),h=2+(c?1:0);for(;p.length+f<u.length-h;)p.push(u[p.length+f]);{let E=u.at(d?2:1),g=u.at(d?3:2);if(!E||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=_e(i),w=_e(Ut(Zr(E,g)));if(a&&x===w){let b=x?pe(i,fe):pe(i,ye);if(p.unshift(Y(w?r[0]+(b?ee:-ee):g[0],w?g[1]:r[1]+(b?ee:-ee))),p.unshift(Y(x?r[0]+(b?ee:-ee):r[0],x?r[1]:r[1]+(b?ee:-ee))),!d){d=!0;for(let y of m)y.index>1&&(y.index+=1)}}else if(p.unshift(Y(w?r[0]:E[0],w?E[1]:r[1])),d){d=!1;for(let b of m)b.index>1&&(b.index-=1)}p.unshift(r)}{let E=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!E||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=_e(o),w=mt(g,E);if(l&&x===w){let b=x?pe(o,fe):pe(o,ye);p.push(Y(w?s[0]+(b?ee:-ee):g[0],w?g[1]:s[1]+(b?ee:-ee))),p.push(Y(x?s[0]+(b?ee:-ee):s[0],x?s[1]:s[1]+(b?ee:-ee))),c||(c=!0)}else p.push(Y(w?s[0]:E[0],w?E[1]:s[1])),c&&(c=!1)}return p.push(s),Wt(p,m.map(({index:E})=>({index:E,start:p[E-1],end:p[E]})).map(E=>({...E,start:Y(E.start[0]-r[0],E.start[1]-r[1]),end:Y(E.end[0]-r[0],E.end[1]-r[1])})),d,c)},cn=1e6,$n=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};v.PROD||(Xn(!n.points||n.points.length>=2,"Updated point array length must match the arrow point length, contain exactly the new start and end points or not be specified at all (i.e. you can't add new points between start and end manually to elbow arrows)"),Xn(!e.fixedSegments||e.fixedSegments.map(y=>y.start[0]===y.end[0]||y.start[1]===y.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Xn(!n.fixedSegments||n.fixedSegments.map(y=>y.start[0]===y.end[0]||y.start[1]===y.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Xn(e.points.slice(1).map((y,I)=>y[0]===e.points[I][0]||y[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Xn(n.fixedSegments?.find(y=>y.index===1&&Mi(y.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(y=>y.index===(n.points??e.points).length-1&&Mi(y.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let o=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((y,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:y):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&Bo(d.elementId,t),m=c&&Bo(c.elementId,t),p=Dl(r);if(d&&!u&&p||c&&!m&&p||t.size===0&&p||Object.keys(l).length===0&&(u?.id!==d?.elementId||m?.id!==c?.elementId))return Wt(r.map(y=>Y(e.x+y[0],e.y+y[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:w,...b}=Kr({x:e.x,y:e.y,startBinding:d,endBinding:c,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,i);return t.size===0&&p?Wt(r.map(y=>Y(e.x+y[0],e.y+y[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?xp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((y,I)=>Mi(y,e.points[I]??Y(1/0,1/0)))&&p?{}:o.length===0?Wt(Jr(es(Qr(e,{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:w,...b})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?wp(e,o,t):n.points?n.points&&n.fixedSegments?n:yp(e,r,o,f,h,E,g,x,w):bp(e,o,f,h,x,w)},Kr=(e,t,n,i)=>{let o=$r(n[0],St(e.x,e.y)),r=$r(n[n.length-1],St(e.x,e.y)),s=null,a=null;if(i?.isDragging&&i?.isBindingEnabled!==!1){let y=Array.from(t.values());s=Ml(o,t,y,i?.zoom)||null,a=Ml(r,t,y,i?.zoom)||null}else s=e.startBinding&&Bo(e.startBinding.elementId,t)||null,a=e.endBinding&&Bo(e.endBinding.elementId,t)||null;let l=Sl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),d=Sl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=Al(l,d,s,o,t,i?.zoom),u=Al(d,l,a,r,t,i?.zoom),m=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],p=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],f=s?it(s,t,un(c,e.startArrowhead?Be(s,{elbowed:!0})*6:Be(s,{elbowed:!0})*2,1)):m,h=a?it(a,t,un(u,e.endArrowhead?Be(a,{elbowed:!0})*6:Be(a,{elbowed:!0})*2,1)):p,E=ut(l,a?it(a,t,un(u,ee,ee)):p)||ut(d,s?it(s,t,un(c,ee,ee)):m),g=vl(E?[m,p]:[f,h]),x=Sp(E?m:f,E?p:h,g,E?un(c,!s&&!a?0:ee,0):un(c,!s&&!a?0:ee-(e.startArrowhead?kn*6:kn*2),ee),E?un(u,!s&&!a?0:ee,0):un(u,!s&&!a?0:ee-(e.endArrowhead?kn*6:kn*2),ee),E,s&&it(s,t),a&&it(a,t)),w=Il(x[0],c,l),b=Il(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:w,startGlobalPoint:l,startHeading:c,endDonglePosition:b,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:E,startElementBounds:f,endElementBounds:h}},Qr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Ap(n,i||o,r,s||a,l,d),m=i&&Do(i,u),p=s&&Do(s,u),f=Do(a,u);f&&c&&(f.closed=!0);let h=Do(o,u);h&&e.startBinding&&(h.closed=!0);let E=m&&p&&(ut(m.pos,n[1])||ut(p.pos,n[0])),g=Pp(m||h,p||f,u,r||fe,l||fe,E?[]:n);if(g){let x=g.map(w=>[w.pos[0],w.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},un=(e,t,n)=>{switch(e){case qe:return[t,n,n,n];case fe:return[n,t,n,n];case ye:return[n,n,t,n]}return[n,n,n,t]},Pp=(e,t,n,i,o,r)=>{let s=Xr(e.pos,t.pos),a=new fp(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Ip(e,l);l.closed=!0;let d=Tp(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=mp(u.pos,l.pos,.5);if(hp(...r.map(b=>ut(m,b))))continue;let p=vp(c),f=l.parent?Ut(Zr(l.pos,l.parent.pos)):i,h=Yr(f);if(pe(h,p)||Tl(e.addr,u.addr)&&pe(p,i)||Tl(t.addr,u.addr)&&pe(p,o))continue;let g=f!==p,x=l.g+Xr(u.pos,l.pos)+(g?Math.pow(s,3):0),w=u.visited;if(!w||x<u.g){let b=Mp(u,t,p,o);u.visited=!0,u.parent=l,u.h=Xr(t.pos,u.pos)+b*Math.pow(s,2),u.g=x,u.f=u.g+u.h,w?a.rescoreElement(u):a.push(u)}}}return null},Ip=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},Xr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Sp=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,m,p]=i??[0,0,0,0],[f,h,E,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-p):(l[0]+d[2])/2:e[0]>t[0]?e[0]-p:n[0]-p,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+m):(l[3]+d[1])/2:e[3]<t[3]?e[3]+m:n[3]+m],w=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-f):(d[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+h):(d[2]+l[0])/2:t[2]<e[2]?t[2]+h:n[2]+h,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+E):(d[3]+l[1])/2:t[3]<e[3]?t[3]+E:n[3]+E],b=vl([x,w]);if(!r&&x[2]-x[0]+w[2]-w[0]>b[2]-b[0]+1e-11&&x[3]-x[1]+w[3]-w[1]>b[3]-b[1]+1e-11){let[y,I]=[(w[0]+w[2])/2,(w[1]+w[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let M=x[2]+(w[0]-x[2])/2,T=w[3]+(x[1]-w[3])/2;return vo(St(e[2]-y,e[1]-I),St(e[0]-y,e[3]-I))>0?[[x[0],x[1],M,x[3]],[M,w[1],w[2],w[3]]]:[[x[0],T,x[2],x[3]],[w[0],w[1],w[2],T]]}else if(e[2]<t[0]&&e[3]<t[1]){let M=x[2]+(w[0]-x[2])/2,T=x[3]+(w[1]-x[3])/2;return vo(St(e[0]-y,e[1]-I),St(e[2]-y,e[3]-I))>0?[[x[0],x[1],x[2],T],[w[0],T,w[2],w[3]]]:[[x[0],x[1],M,x[3]],[M,w[1],w[2],w[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let M=w[2]+(x[0]-w[2])/2,T=x[3]+(w[1]-x[3])/2;return vo(St(e[2]-y,e[1]-I),St(e[0]-y,e[3]-I))>0?[[M,x[1],x[2],x[3]],[w[0],w[1],M,w[3]]]:[[x[0],x[1],x[2],T],[w[0],T,w[2],w[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let M=w[2]+(x[0]-w[2])/2,T=w[3]+(x[1]-w[3])/2;return vo(St(e[0]-y,e[1]-I),St(e[2]-y,e[3]-I))>0?[[M,x[1],x[2],x[3]],[w[0],w[1],M,w[3]]]:[[x[0],T,x[2],x[3]],[w[0],w[1],w[2],T]]}}return[x,w]},Ap=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===He||n===fe?a.add(t[1]):s.add(t[0]),o===He||o===fe?a.add(i[1]):s.add(i[0]),e.forEach(c=>{s.add(c[0]),s.add(c[2]),a.add(c[1]),a.add(c[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((c,u)=>c-u),d=Array.from(s).sort((c,u)=>c-u);return{row:l.length,col:d.length,data:l.flatMap((c,u)=>d.map((m,p)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[p,u],pos:[m,c]})))}},Il=(e,t,n)=>{switch(t){case qe:return Y(n[0],e[1]);case fe:return Y(e[2],n[1]);case ye:return Y(n[0],e[3])}return Y(e[0],n[1])},Mp=(e,t,n,i)=>{if(i===fe)switch(n){case fe:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case qe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ye:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He:return e.pos[1]===t.pos[1]?4:2}else if(i===He)switch(n){case fe:return e.pos[1]===t.pos[1]?4:2;case qe:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ye:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case He:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===qe)switch(n){case fe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case qe:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ye:return e.pos[0]===t.pos[0]?4:2;case He:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===ye)switch(n){case fe:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case qe:return e.pos[0]===t.pos[0]?4:2;case ye:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case He:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Tp=([e,t],n)=>[Ai([e,t-1],n),Ai([e+1,t],n),Ai([e,t+1],n),Ai([e-1,t],n)],Ai=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Do=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=Ai([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},vl=e=>[Math.min(...e.map(t=>t[0])),Math.min(...e.map(t=>t[1])),Math.max(...e.map(t=>t[2])),Math.max(...e.map(t=>t[3]))],Bo=(e,t)=>{let n=t.get(e);return n&&ce(n)?n:null},Wt=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>$r(a,pp(Zr(e[0]),-1)));return(o<-cn||o>cn||r<-cn||r>cn||o+s[s.length-1][0]<-cn||r+s[s.length-1][0]>cn||o+s[s.length-1][1]<-cn||r+s[s.length-1][1]>cn)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...Pl(s)}),s=s.map(([a,l])=>Y(To(a,-1e6,1e6),To(l,-1e6,1e6))),{points:s,x:To(o,-1e6,1e6),y:To(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Pl(s),startIsSpecial:n,endIsSpecial:i}},Jr=e=>{if(e.length>1){let t=Math.abs(e[0][1]-e[1][1])<Math.abs(e[0][0]-e[1][0]);return e.filter((n,i)=>{if(i===0||i===e.length-1)return!0;let o=e[i+1],r=Math.abs(n[1]-o[1])<Math.abs(n[0]-o[0]);return t===r?(t=r,!1):(t=r,!0)})}return e},es=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Vr(i,t)>qr}):e,vp=e=>{switch(e){case 0:return qe;case 1:return fe;case 2:return ye}return He},Sl=(e,t,n,i,o,r,s,a=!0,l=!0)=>s?a&&o&&r?ts(e,o,t,r,void 0,l):i:o?Re(n||[0,0],o,r??gp([o])):i,Al=(e,t,n,i,o,r)=>Bl(e,t,n,n&&it(n,o,Array(4).fill(an(n,o,e))),i,o,r),Ml=(e,t,n,i)=>_t(e,n,t,dt(i)),Tl=(e,t)=>e[0]===t[0]&&e[1]===t[1],Dl=(e,t=qr)=>e.slice(1).map((n,i)=>Math.abs(n[0]-e[i][0])<t||Math.abs(n[1]-e[i][1])<t).every(Boolean);var Pe=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;U(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...$n({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Dp(r),...n});for(let l in n){let d=n[l];if(typeof d<"u"){if(e[l]===d&&(typeof d!="object"||d===null||l==="groupIds"||l==="scale"))continue;if(l==="scale"){let c=e[l],u=d;if(c[0]===u[0]&&c[1]===u[1])continue}else if(l==="points"){let c=e[l],u=d;if(c.length===u.length){let m=!1,p=c.length;for(;--p;){let f=c[p],h=u[p];if(f[0]!==h[0]||f[1]!==h[1]){m=!0;break}}if(!m)continue}}e[l]=d,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof a<"u"||typeof r<"u")&&Ke.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??ns(),e.updated=is()),e},Le=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??ns(),updated:is()}},Ll=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=ns(),e.updated=is(),e);var Rl=5,kn=5,Op=10,Di=10/1.5,Be=(e,t)=>(t.elbowed?kn:Rl)+e.strokeWidth/2,dt=e=>{let t=Math.max(Rl,15),n=e?.value&&e.value<1?e.value:1;return rs(t/(n*1.5),t,t*2)},At=e=>e.isBindingEnabled,kp=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=ss(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0});if(Cl(e,a,"start",o,r.isBindingEnabled),Cl(e,l,"end",o,r.isBindingEnabled),a.focusPoint||l.focusPoint){let d=new Map;a.focusPoint&&d.set(0,{point:pt(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&d.set(e.points.length-1,{point:pt(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),G.movePoints(e,o,d)}return{start:a,end:l}},Cl=(e,{mode:t,element:n,focusPoint:i},o,r,s=!0)=>{t===null?ve(e,o,r):t!==void 0&&Mt(e,n,t,o,r,i,s)},Nl=(e,t,n,i,o)=>{ot(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;ot(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=G.getPointGlobalCoordinates(e,a,n),d=_t(l,i,n,dt(o)),c=d?{element:d,mode:"orbit",focusPoint:G.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},Fp=(e,t,n,i,o,r,s,a,l,d,c)=>{let u={mode:void 0},m={mode:void 0},p=e.points.length>2,f=G.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),h=_t(f,i,n);if(o)return h?u={element:h,mode:"inside",focusPoint:f}:u={mode:null},{start:u,end:m};if(r){let E=l?.selectedLinearElement?.initialState.origin;if(h&&e.startBinding?.elementId===h.id){let g=te(h.x+h.width/2,h.y+h.height/2);return{start:p?{mode:void 0}:{mode:"inside",element:h,focusPoint:E??g},end:p?{mode:"orbit",element:h,focusPoint:f}:{mode:"inside",element:h,focusPoint:f}}}if(h&&e.startBinding){let g=e.startBinding;if(yo(f,i,n).find(w=>w.id===g.elementId)){let w=n.get(e.startBinding.elementId);return ot(w,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:w.id!==h.id?"orbit":"inside",element:w,focusPoint:E??te(e.x,e.y)},end:{mode:"orbit",element:h,focusPoint:f}}}}if(e.startBinding&&e.startBinding.elementId!==h?.id){let g=n.get(e.startBinding.elementId);ot(g,"Other element must be in the elements map");let w={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:g,focusPoint:c?ne(g,n):E??te(e.x,e.y)},b=h&&Wr(g,h,n),y;if(h){let I=d==="inside"||d==="skip";y={mode:I&&!b?"inside":"orbit",element:h,focusPoint:f}}else y={mode:null};return{start:p?{mode:void 0}:w,end:y}}if(!e.startBinding)return h?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:h,focusPoint:f}:m={mode:null},{start:u,end:m}}ot(!1,"New arrow creation should not reach here")},Gl=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=_t(e,o,i),m=n?yo(e,o,i).some(E=>E.id===n.elementId):!1,p=n?i.get(n.elementId):null,f=m&&p?Lp(p.backgroundColor):!1,h=u&&p&&Wr(p,u,i);return r==="inside"||r==="skip"?(l=u?{element:!m||!p||f?u:p,focusPoint:e,mode:"inside"}:{mode:null},d=a&&u&&u.id===n?.elementId?{mode:null}:d,{current:l,other:d}):u?u.id===t?.elementId&&t.mode==="inside"?{current:{mode:"inside",focusPoint:e,element:u},other:d}:n?n.elementId===u.id?n.mode==="orbit"?(l={element:u,mode:"orbit",focusPoint:e},d={mode:a?null:void 0},{current:l,other:c?{mode:void 0}:d}):(l={element:u,mode:"inside",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):(m&&p&&!f?l={element:p,mode:"inside",focusPoint:e}:l={element:u,mode:"orbit",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):(l={element:u,mode:"orbit",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):{current:{mode:null},other:d}},ss=(e,t,n,i,o,r,s,a)=>Bp("COMPLEX_BINDINGS")?Rp(e,t,o,r,s,a):zl(e,t,n,i,o,r,s,a),zl=(e,t,n,i,o,r,s,a)=>{let d=e.points.length-1,c=t.has(0),u=t.has(d),m={mode:void 0},p={mode:void 0};if(ot(e.points.length>1,"Do not attempt to bind linear elements with a single point"),!c&&!u)return{start:m,end:p};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!At(s))return m=c?{mode:null}:m,p=u?{mode:null}:p,{start:m,end:p};if(U(e))return Nl(e,t,o,r,a?.zoom);let f=c?e.endBinding:e.startBinding,h=t.get(c?0:d)?.point;ot(h,`Local point must be defined for ${c?"start":"end"} dragging`);let E=G.getPointGlobalCoordinates(e,h,o),g=_t(E,r,o,dt(s.zoom)),x=g&&(a?.angleLocked?Rt(te(n,i),g,o):Rt(E,g,o)),w=f?o.get(f.elementId):void 0,b=f&&w&&Re(f.fixedPoint,w,o),y=w&&b&&bt({point:b,element:w,elementsMap:o,threshold:0,overrideShouldTestInside:!0});if(f&&f.elementId===g?.id)return ot(!a?.newArrow||s.selectedLinearElement?.initialState.origin,"appState.selectedLinearElement.initialState.origin must be defined for new arrows"),{start:{mode:"inside",element:g,focusPoint:c?E:a?.newArrow?s.selectedLinearElement.initialState.origin:G.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:g,focusPoint:u?E:G.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:m,end:u?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:p};let I=g?x?{mode:"inside",element:g,focusPoint:E}:{mode:"orbit",element:g,focusPoint:Br(e,E,g,c?"start":"end",o,s.zoom,s.isMidpointSnappingEnabled)||E}:{mode:null},M=G.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),T=b&&w&&bt({point:E,element:w,elementsMap:o,threshold:dt(s.zoom),overrideShouldTestInside:!0}),B=(a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:f?.mode==="inside")?{mode:void 0}:w&&!y&&!T&&s.selectedLinearElement?.initialState.altFocusPoint?{mode:"orbit",element:w,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&w?{mode:"orbit",element:w,focusPoint:Br(e,M,w,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||M}:{mode:void 0};return{start:c?I:B,end:u?I:B}},Rp=(e,t,n,i,o,r)=>{let s=o.bindMode||"orbit",a=0,l=e.points.length-1,d=t.has(a),c=t.has(l),u={mode:void 0},m={mode:void 0};if(ot(e.points.length>1,"Do not attempt to bind linear elements with a single point"),!d&&!c)return{start:u,end:m};if(d&&c)return{start:{mode:null},end:{mode:null}};if(!At(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(U(e))return Nl(e,t,n,i);if(r?.newArrow){let{start:p,end:f}=Fp(e,t,n,i,d,c,a,l,o,s,r?.shiftKey);return{start:p,end:f}}if(d){let p=t.get(a)?.point;ot(p,"Local point must be defined for start dragging");let f=G.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=Gl(f,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:h,end:E}}if(c){let p=t.get(l)?.point;ot(p,"Local point must be defined for end dragging");let f=G.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=Gl(f,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:E,end:h}}return{start:u,end:m}},wy=(e,t,n)=>{e.forEach(i=>{kp(i,new Map,1/0,1/0,t,n)})},Mt=(e,t,n,i,o,r,s=!0)=>{let a=o.getNonDeletedElementsMap(),l;U(e)?l={elementId:t.id,mode:"orbit",...Wp(e,t,i,a,s)}:l={elementId:t.id,mode:n,...Vn(e,t,i,a,r)},o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:l}),Fl(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},ve=(e,t,n)=>{let i=t==="start"?"startBinding":"endBinding",o=e[i];if(o==null)return null;let r=e[t==="start"?"endBinding":"startBinding"];if(!r||r.elementId!==o.elementId){let s=n.getNonDeletedElementsMap().get(o.elementId);n.mutateElement(s,{boundElements:s.boundElements?.filter(a=>a.id!==e.id)})}return n.mutateElement(e,{[i]:null}),o.elementId},De=(e,t,n)=>{if(!ce(e))return;let{simultaneouslyUpdated:i}=n??{},o=zp(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),Oo(r,e,a=>{if(!H(a)||a.isDeleted||!Np(a,e))return;let l=a.startBinding?r.get(a.startBinding.elementId):null,d=a.endBinding?l?.id===a.endBinding.elementId?l:r.get(a.endBinding.elementId):null;if(o.has(a.id))return;let c=ko(r,a,(m,p)=>{if(m&&ce(m)&&(p==="startBinding"||p==="endBinding")&&(e.id===a[p]?.elementId||e.id===a[p==="startBinding"?"endBinding":"startBinding"]?.elementId)){let f=pt(a,p,a[p],m,r);if(f)return[p==="startBinding"?0:a.points.length-1,{point:f}]}return null}).filter(m=>m!==null);G.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=V(a,r);u&&!u.isDeleted&&On(a,t,!1)})},Ol=(e,t,n,i,o)=>{ot(!U(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=G.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&bt({element:s,point:a,elementsMap:n,threshold:dt(o.zoom)}),d=t==="startBinding"?"start":"end";if(ve(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],m=zl(e,new Map([[c,{point:u}]]),a[0],a[1],n,i.getNonDeletedElements(),o);m[d]&&m[d].element?.id===s.id&&m[d].mode&&Mt(e,s,m[d].mode,d,i,m[d].focusPoint)}},by=(e,t,n,i)=>{if(H(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&Ol(e,"startBinding",o,t,n),e.endBinding&&Ol(e,"endBinding",o,t,n)}else De(e,t,{...i,changedElements:new Map([[e.id,e]])})},Np=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,zp=e=>new Set((e||[]).map(t=>t.id)),Bl=(e,t,n,i,o,r,s)=>{let a=Ut(Ti(t,e));return!n||!i?a:Hp(o,n,r,s)?Si(n,i,e):Ut(Ti(e,ne(n,r)))},Hp=(e,t,n,i)=>{let o=an(t,n,e),r=dt(i);return o>r?null:o},ts=(e,t,n,i,o,r=!0)=>{let s=U(e),a=G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return a;let l=Ha(t)&&s?_p(e,t,i,a):a,d=o&&!s?o[1]:G.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),c=Be(t,e),u=it(t,i),m=ln(u),p=null;if(s){let f=_e(Si(t,u,a)),E=(r?as(t,i,l,.05,e):void 0)||a,g=te(f?m[0]:E[0],f?E[1]:m[1]),x=o??Go(g,Lo(Co(os(Ti(E,g)),Math.max(t.width,t.height)*2),g));if(p=Pt(t,i,x,c).sort(jt)[0],!p){let w=te(f?E[0]:m[0],f?m[1]:E[1]),b=Go(w,Lo(Co(os(Ti(E,w)),Math.max(t.width,t.height)*2),w));p=Pt(t,i,b,kn).sort(jt)[0]}}else{let f=o;if(!f){let h=Co(os(Ti(l,d)),mn(l,d)+Math.max(t.width,t.height)+c*2);f=o??Go(Lo(h,d),Lo(Co(h,-1),d))}p=mn(l,d)<1?l:Pt(t,i,f,c).sort((h,E)=>jt(h,d)-jt(E,d))[0]}return!p||jt(l,p)<Cp?l:p},_p=(e,t,n,i)=>{let o=ne(t,n),r=ae(i,o,-t.angle),s=Be(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?ae(te(t.x-s,t.y),o,t.angle):ae(te(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?ae(te(t.x,t.y+t.height+s),o,t.angle):ae(te(t.x-s,t.y+t.height),o,t.angle):r[0]>t.x+t.width&&r[1]>t.y+t.height?r[0]-t.x<t.width+s?ae(te(t.x+t.width,t.y+t.height+s),o,t.angle):ae(te(t.x+t.width+s,t.y+t.height),o,t.angle):r[0]>t.x+t.width&&r[1]<t.y?r[0]-t.x<t.width+s?ae(te(t.x+t.width,t.y-s),o,t.angle):ae(te(t.x+t.width+s,t.y),o,t.angle):i},as=(e,t,n,i=.05,o)=>{let{x:r,y:s,width:a,height:l,angle:d}=e,c=ne(e,t,-.1,-.1),u=ae(n,c,-d),m=o?Be(e,o):0,p=rs(i*l,5,80),f=rs(i*a,5,80);if(!(mn(c,u)<m)){if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return ae(te(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return ae(te(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return ae(te(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return ae(te(c[0],s+l+m),c,d);if(e.type==="diamond"){let h=m,E=te(r+a/4-h,s+l/4-h),g=te(r+3*a/4+h,s+l/4-h),x=te(r+a/4-h,s+3*l/4+h),w=te(r+3*a/4+h,s+3*l/4+h);if(mn(E,u)<Math.max(f,p))return ae(E,c,d);if(mn(g,u)<Math.max(f,p))return ae(g,c,d);if(mn(x,u)<Math.max(f,p))return ae(x,c,d);if(mn(w,u)<Math.max(f,p))return ae(w,c,d)}}},Up=(e,t,n)=>{let i=e[t];if(!i)return{element:null,fixedPoint:null,focusPoint:null,binding:i,mode:null};let o=n.get(i.elementId);return{element:o,fixedPoint:i.fixedPoint,focusPoint:Re(rn(i.fixedPoint),o,n),binding:i,mode:i.mode}},kl=e=>e.width*e.height,pt=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||Gp(e.points[e.points.length-1],te(0,0)))return null;let s=Re(rn(n.fixedPoint),i,o);if(n.mode==="inside")return G.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=Up(e,t==="startBinding"?"endBinding":"startBinding",o),d=G.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&Go(s,c),m=a&&u&&Pt(a,o,u,Be(a,e)).sort((w,b)=>jt(w,s)-jt(b,s))[0],p=u&&Pt(i,o,u,Be(i,e)).sort((w,b)=>jt(w,c)-jt(b,c))[0],f=e.startArrowhead!==null,h=e.endArrowhead!==null,E=!f&&!h||t==="startBinding"&&f||t==="endBinding"&&h?s:p||s;if(a&&p&&!r&&kl(a)<kl(i)*2&&bt({element:a,point:p,elementsMap:o,threshold:Be(a,e),overrideShouldTestInside:!0}))return G.createPointAt(e,o,E[0],E[1],null);let x=mn(a&&(m||l)||d,p||s)<=Op;return a?x?G.createPointAt(e,o,E?.[0]||s[0],E?.[1]||s[1],null):G.createPointAt(e,o,p?.[0]||s[0],p?.[1]||s[1],null):G.createPointAt(e,o,x?s[0]:p?.[0]??s[0],x?s[1]:p?.[1]??s[1],null)},Wp=(e,t,n,i,o=!0,r=!0)=>{let s=[t.x,t.y,t.x+t.width,t.y+t.height],a=o?ts(e,t,n,i,void 0,r):G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),l=te(s[0]+(s[2]-s[0])/2,s[1]+(s[3]-s[1])/2),d=ae(a,l,-t.angle);return{fixedPoint:rn([(d[0]-t.x)/t.width,(d[1]-t.y)/t.height])}},Vn=(e,t,n,i,o)=>{let r=o||G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=ne(t,i),a=ae(r,s,-t.angle),l=(a[0]-t.x)/t.width,d=(a[1]-t.y)/t.height;return{fixedPoint:rn([l,d])}},Hl=(e,t,n)=>{for(let i of e){if("boundElements"in i&&i.boundElements&&Object.assign(i,{boundElements:i.boundElements.reduce((o,r)=>{let s=t.get(r.id);return s&&o.push({...r,id:s}),o},[])}),"containerId"in i&&i.containerId&&Object.assign(i,{containerId:t.get(i.containerId)??null}),"endBinding"in i&&i.endBinding){let o=t.get(i.endBinding.elementId);Object.assign(i,{endBinding:o?{...i.endBinding,elementId:o}:null})}if("startBinding"in i&&i.startBinding){let o=t.get(i.startBinding.elementId);Object.assign(i,{startBinding:o?{...i.startBinding,elementId:o}:null})}U(i)&&Object.assign(i,$n(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},yy=(e,t)=>{let n=Fl(e);for(let i of t)pn.unbindAffected(n,i,(o,r)=>Pe(o,n,r)),fn.unbindAffected(n,i,(o,r)=>Pe(o,n,r))},vi=(e,t,n=[])=>{if(!e)return null;let i=e.filter(o=>!t.has(o.id));return i.push(...n.map(o=>({id:o.id,type:o.type}))),i},_l=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),Oo=(e,t,n)=>{ce(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},ko=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(ue(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(H(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},pn=class{static unbindAffected(t,n,i){n&&ko(t,n,o=>{!o||o.isDeleted||Oo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:vi(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||ko(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(H(n)&&i(o,{boundElements:vi(o.boundElements,new Set,new Array(n))}),q(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:vi(o.boundElements,new Set,new Array(n))}))))})}},fn=class{static unbindAffected(t,n,i){n&&Oo(t,n,o=>{!o||o.isDeleted||ko(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||Oo(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:vi(n.boundElements,new Set([s]))});return}q(o)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===o.id?o.containerId!==n.id&&i(o,{containerId:n.id}):(o.containerId!==null&&i(o,{containerId:null}),i(n,{boundElements:vi(n.boundElements,new Set([o.id]))})))})}},Re=(e,t,n)=>{let[i,o]=rn(e);return ae(te(t.x+t.width*i,t.y+t.height*o),ne(t,n),t.angle)},jp=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?Re(e.startBinding.fixedPoint,n,t):te(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?Re(e.endBinding.fixedPoint,i,t):te(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},Ul=(e,t)=>{let[n,i]=jp(e,t);return[G.pointFromAbsoluteCoords(e,n,t),G.pointFromAbsoluteCoords(e,i,t)]},Yp=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),rn=e=>{if(!Yp(e))return[.5001,.5001];let t=1e-4;return Math.abs(e[0]-.5)<t||Math.abs(e[1]-.5)<t?e.map(n=>Math.abs(n-.5)<t?.5001:n):e},Xp=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",$p={rectangle:[{centerAngle:0,sectorWidth:75,side:"right"},{centerAngle:45,sectorWidth:15,side:"bottom-right"},{centerAngle:90,sectorWidth:75,side:"bottom"},{centerAngle:135,sectorWidth:15,side:"bottom-left"},{centerAngle:180,sectorWidth:75,side:"left"},{centerAngle:225,sectorWidth:15,side:"top-left"},{centerAngle:270,sectorWidth:75,side:"top"},{centerAngle:315,sectorWidth:15,side:"top-right"}],diamond:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}],ellipse:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}]},Vp=e=>e.map((t,n)=>{let i=t.sectorWidth/2,o=t.centerAngle-i,r=t.centerAngle+i;return o=(o%360+360)%360,r=(r%360+360)%360,{start:o,end:r,side:t.side}}),Zp=(e,t)=>{let[n,i]=e,o=n-.5,r=i-.5,s=Math.atan2(r,o);s<0&&(s+=2*Math.PI);let a=s*180/Math.PI,l=$p[t],d=Vp(l);for(let m of d)if(m.start<=m.end){if(a>=m.start&&a<=m.end)return m.side}else if(a>=m.start||a<=m.end)return m.side;let c=1/0,u=l[0].side;for(let m of l){let p=Math.abs(a-m.centerAngle);p>180&&(p=360-p),p<c&&(c=p,u=m.side)}return u},Py=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!ce(n))return null;let i=ne(n,t),o=Xp(n),r=Zp(rn(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=on(n),[d,c,u,m]=a,p,f;switch(r){case"left":{if(l.length>=3){let E=l[2][1];p=E[0]-s,f=E[1]}else{let h=Te(c[1],u[0]);p=h[0]-s,f=h[1]}break}case"right":{if(l.length>=1){let E=l[0][1];p=E[0]+s,f=E[1]}else{let h=Te(m[1],d[0]);p=h[0]+s,f=h[1]}break}case"top":{if(l.length>=4){let E=l[3][1];p=E[0],f=E[1]-s}else{let h=Te(u[1],m[0]);p=h[0],f=h[1]-s}break}case"bottom":{if(l.length>=2){let E=l[1][1];p=E[0],f=E[1]+s}else{let h=Te(d[1],c[0]);p=h[0],f=h[1]+s}break}case"top-right":{let h=Te(m[0],m[1]);p=h[0]+s*.707,f=h[1]-s*.707;break}case"bottom-right":{let h=Te(d[0],d[1]);p=h[0]+s*.707,f=h[1]+s*.707;break}case"bottom-left":{let h=Te(c[0],c[1]);p=h[0]-s*.707,f=h[1]+s*.707;break}case"top-left":{let h=Te(u[0],u[1]);p=h[0]-s*.707,f=h[1]-s*.707;break}default:return null}return ae(te(p,f),i,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,m;switch(r){case"top":{u=a,m=l-c-s;break}case"right":{u=a+d+s,m=l;break}case"bottom":{u=a,m=l+c+s;break}case"left":{u=a-d-s,m=l;break}case"top-right":{let p=-Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f+s*.707,m=l+h-s*.707;break}case"bottom-right":{let p=Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f+s*.707,m=l+h+s*.707;break}case"bottom-left":{let p=3*Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f-s*.707,m=l+h+s*.707;break}case"top-left":{let p=-3*Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f-s*.707,m=l+h-s*.707;break}default:return null}return ae(te(u,m),i,n.angle)}if(gi(n)){let[a,l]=nn(n),[d,c,u,m]=a,p,f;switch(r){case"top":{let h=Te(d[0],d[1]);p=h[0],f=h[1]-s;break}case"right":{let h=Te(c[0],c[1]);p=h[0]+s,f=h[1];break}case"bottom":{let h=Te(u[0],u[1]);p=h[0],f=h[1]+s;break}case"left":{let h=Te(m[0],m[1]);p=h[0]-s,f=h[1];break}case"top-left":{if(l.length>=1){let h=l[0],E=h[0],g=h[3],x=Te(E,g);p=x[0]-s*.707,f=x[1]-s*.707}else p=n.x-s,f=n.y-s;break}case"top-right":{if(l.length>=2){let h=l[1],E=h[0],g=h[3],x=Te(E,g);p=x[0]+s*.707,f=x[1]-s*.707}else p=n.x+n.width+s,f=n.y-s;break}case"bottom-right":{if(l.length>=3){let h=l[2],E=h[0],g=h[3],x=Te(E,g);p=x[0]+s*.707,f=x[1]+s*.707}else p=n.x+n.width+s,f=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let h=l[3],E=h[0],g=h[3],x=Te(E,g);p=x[0]-s*.707,f=x[1]+s*.707}else p=n.x-s,f=n.y+n.height+s;break}default:return null}return ae(te(p,f),i,n.angle)}return null},Te=(e,t)=>te((e[0]+t[0])/2,(e[1]+t[1])/2);var ls=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>O(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},G=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;hoveredFocusPointBinding;draggedFocusPointBinding;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,i=!1){this.elementId=t.id,jl(t.points[0],O(0,0))||(console.error("Linear element is not normalized",Error().stack),Pe(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=U(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,m]=$(n.selectionElement,o),f=e.getPointsGlobalCoordinates(l,o).reduce((h,E,g)=>((E[0]>=d&&E[0]<=u&&E[1]>=c&&E[1]<=m||t.shiftKey&&s?.includes(g))&&h.push(g),h),[]).filter(h=>!(U(l)&&h!==0&&h!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:f.length?f:null}})}static handlePointerMove(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);Ue(d,"Element being dragged must exist in the scene"),Ue(d.points.length>1,"Element must have at least 2 points");let c=d.points.length-1,u=d.points[c],m=d.points[c-1],p=r.customLineAngle??Kl(m,d.points[c]),f=0,h=0;if(Bi(t)){let[y,I]=e._getShiftLockedDelta(d,s,m,O(i,o),t[Fn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),M=O(y+m[0],I+m[1]);f=M[0]-u[0],h=M[1]-u[1]}else{let y=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Fn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());f=y[0]-u[0],h=y[1]-u[1]}let E=null,{positions:g,updates:x}=ql([c],f,h,i,o,s,d,a,n,Bi(t),t.altKey,r);if(e.movePoints(d,n.scene,g,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled}),Ae(d,!1)&&At(n.state)&&(E=x?.suggestedBinding??null),Ae(d)&&Vl(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!E||ef(n.state.suggestedBinding??[],E)))return null;let w=Ae(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:p,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&w&&x?.suggestedBinding?.element.id!==w.id?Zl(d,O(d.x,d.y),w,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled):r.initialState.altFocusPoint}},suggestedBinding:E}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);Ue(p,"Element being dragged must exist in the scene"),Ue(p.points.length>1,"Element must have at least 2 points"),Ue(u,"There must be selected points in order to drag them"),l&&u.some((A,z)=>A>0&&A!==p.points.length-1?(u[z]=p.points.length-1,m=p.points.length-1,!0):!1),(m<0||!u.includes(m)||!p.points[m])&&(console.error(`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${p.points.length-1}) lastClickedPoint(${m})`),m=p.points.length-1);let f=p.points[m],h=p.points[m===0?1:m-1],E=u.length===1,g=r.customLineAngle??Kl(h,p.points[m]),x=u.includes(0),w=u.includes(p.points.length-1),b=0,y=0;if(Bi(t)&&E){let[A,z]=e._getShiftLockedDelta(p,s,h,O(i,o),t[Fn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),g),W=O(A+h[0],z+h[1]);b=W[0]-f[0],y=W[1]-f[1]}else{let A=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Fn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());b=A[0]-f[0],y=A[1]-f[1]}let I=null,{positions:M,updates:T}=ql(u,b,y,i,o,s,p,a,n,Bi(t)&&E,t.altKey,r);e.movePoints(p,n.scene,M,{startBinding:T?.startBinding,endBinding:T?.endBinding,moveMidPointsWithElement:T?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled}),Ae(p,!1)&&At(n.state)&&(x||w)&&(I=T?.suggestedBinding??null),Ae(p)&&x!==w&&Vl(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),V(p,s)&&On(p,n.scene,!1);let B=l?w?[p.points.length-1]:[0]:u,L=l?B[0]:m,k=!x&&!w?e.getPointGlobalCoordinates(p,f,s):null,C=L,X=Ae(p)&&p.startBinding&&s.get(p.startBinding.elementId),_=Ae(p)&&p.endBinding&&s.get(p.endBinding.elementId),oe=w&&X&&T?.suggestedBinding?.element.id!==X.id?X:x&&_&&T?.suggestedBinding?.element.id!==_.id?_:null;return{selectedLinearElement:{...r,selectedPointsIndices:B,initialState:{...r.initialState,lastClickedPoint:L,altFocusPoint:!r.initialState.altFocusPoint&&Ae(p)&&oe?Zl(p,O(p.x,p.y),oe,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:k,hoverPointIndex:C,isDragging:!0,customLineAngle:g},suggestedBinding:I}}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),{elementId:s,selectedPointsIndices:a,isDragging:l,initialState:d}=n,c=e.getElement(s,r);if(!c)return n;if(l&&a)for(let u of a)(u===0||u===c.points.length-1)&&tf(c.points,i.zoom.value)&&(Ot(c)&&o.mutateElement(c,{...Ql(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,o,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1}}}static getEditorMidPoints=(t,n,i)=>{let o=V(t,n);if(!U(t)&&!i.selectedLinearElement?.isEditing&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom,n)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1,n);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!U(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!U(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Rn(O(c[0],c[1]),O(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&Rn(m[u],O(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r,s){if(U(t))return o>=0&&o<t.points.length?Rn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=Rn(n,i);if(t.points.length>2&&t.roundness){let[l,d]=Xl(t,s);Ue(l.length===0&&d.length>0,"Only linears built out of curves are supported"),Ue(l.length+d.length>=o,"Invalid segment index while calculating mid point"),a=Kp(d[o])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,i){if(U(t)){Ue(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=Wl(t.points[n-1],t.points[n]);return O(t.x+s[0],t.y+s[1])}let[o,r]=Xl(t,i);if(Ue(o.length===0&&r.length>0||o.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),Ue(o.length+r.length>=n,"Invalid segment index while calculating mid point"),o.length){let s=o[n-1];return Wl(s[0],s[1])}if(r.length){let s=r[n-1];return Qp(s,.5)}Ue(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let m=e.getSegmentMidpointHitCoords(r,o,a,l),p=O(o.x,o.y),f=null;if(m)f=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(u,{points:[...u.points,e.createPointAt(u,l,o.x,o.y,t[Fn.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:p,segmentMidpoint:{value:m,index:f,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let h=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y);(h>=0||m)&&(d.hitElement=u);let[E,g,x,w]=$(u,l),b=(E+x)/2,y=(g+w)/2,I=h>-1&&Ce(O(u.x+u.points[h][0],u.y+u.points[h][1]),O(b,y),u.angle),M=h>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(h)?nf([...r.selectedPointsIndices||[],h]):[h]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:h,origin:p,segmentMidpoint:{value:m,index:f,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:M,pointerOffset:I?{x:o.x-I[0],y:o.y-I[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:jl(t,n)}static handlePointerMoveInEditMode(t,n,i,o){let r=o.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=o.scene.getNonDeletedElementsMap(),d=e.getElement(s,l);if(!d)return r.selectedLinearElement;let{points:c}=d,u=c[c.length-1];if(!t.altKey)return u===a&&e.deletePoints(d,o,[c.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let m;if(Bi(t)&&c.length>=2){let p=c[c.length-2],[f,h]=e._getShiftLockedDelta(d,l,p,O(n,i),t[Fn.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=O(f+p[0],h+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[Fn.CTRL_OR_CMD]||U(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:m}]])):e.addPoints(d,o.scene,[m]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=$(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Ce(O(c+n[0],u+n[1]),O(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=$(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return Ce(O(c+d[0],u+d[1]),O(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=$(t,i),a=O(r,s),l=t.points[o],{x:d,y:c}=t;return l?Ce(O(d+l[0],c+l[1]),a,t.angle):Ce(O(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(U(t))return O(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=$(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=Ce(O(n[0],n[1]),O(l,d),-t.angle);return O(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Rn(O(o,r),O(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=Yl(i,o,r),[a,l,d,c]=$(t,n),u=(a+d)/2,m=(l+c)/2,[p,f]=Ce(O(s[0],s[1]),O(u,m),-t.angle);return O(p-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=ls(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){Ue(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);Ue(s,"The linear element does not exist in the provided Scene"),Ue(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((m,p,f)=>{if(++c,m.push(p),o.includes(f)){let E=a[f+1];E||(d=!0),m.push(E?O((p[0]+E[0])/2,(p[1]+E[1])/2):O(p[0],p[1])),l.push(c+1),++c}return m},[]);if(n.mutateElement(s,{points:u}),d){let m=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:O(m[0]+30,m[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!i.includes(u));Ot(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=O(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=ls({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];Ot(t)&&t.polygon&&(o[0]=O(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=ls({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o,r){let{points:s}=t;if(Ot(t)&&t.polygon){let u=i.get(0),m=i.get(s.length-1);u?i.set(s.length-1,{point:O(u.point[0],u.point[1]),isDragging:u.isDragging}):m&&i.set(0,{point:O(m.point[0],m.point[1]),isDragging:m.isDragging})}let a=i.get(0)?.point??O(0,0),[l,d]=a,c=U(t)?[i.get(0)?.point??s[0],i.get(s.length-1)?.point??s[s.length-1]]:s.map((u,m)=>{let p=i.get(m)?.point??u;return o?.moveMidPointsWithElement&&m!==0&&m!==s.length-1&&!i.has(m)?p:O(p[0]-l,p[1]-d)});e._updatePoints(t,n,c,l,d,o,{isDragging:Array.from(i.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&U(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=Rn(a,O(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<Jp/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!U(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.initialState,segmentMidpoint:{...t.initialState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,i,o,r,s,a){if(U(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=ds(t,i),d=ds(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,m=(d[0]+d[2])/2,p=(d[1]+d[3])/2,f=m-c,h=p-u,E=Ce(O(o,r),O(f,h),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+E[0],y:t.y+E[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(U(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=Yl(o[0],o[1],r),{width:c,height:u}=Jl(a[0],a[1],l,d,s);return Ce(O(c,u),O(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&Pe(n,i,{isDeleted:!0});let r=0,s=0;if(t.points.length%2===1){let a=Math.floor(t.points.length/2),l=e.getPointGlobalCoordinates(t,t.points[a],i);r=l[0]-n.width/2,s=l[1]-n.height/2}else{let a=t.points.length/2-1,l=e.getSegmentMidPoint(t,a+1,i);r=l[0]-n.width/2,s=l[1]-n.height/2}return{x:r,y:s}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:m}=e.getBoundTextElementPosition(t,o,n),p=u+o.width,f=m+o.height,h=O(d,c),E=Ce(O(r,s),h,t.angle),g=Ce(O(a,s),h,t.angle),x=Ce(O(u,m),h,-t.angle),w=Ce(O(p,m),h,-t.angle),b=Ce(O(u,f),h,-t.angle),y=Ce(O(p,f),h,-t.angle);return E[0]<g[0]&&E[1]>=g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(w[0],y[0])),s=Math.min(s,x[1]),l=Math.max(l,y[1])):E[0]>=g[0]&&E[1]>g[1]?(r=Math.min(r,y[0]),a=Math.max(a,Math.max(x[0],w[0])),s=Math.min(s,b[1]),l=Math.max(l,w[1])):E[0]>=g[0]?(r=Math.min(r,w[0]),a=Math.max(a,b[0]),s=Math.min(s,y[1]),l=Math.max(l,x[1])):E[1]<=g[1]&&(r=Math.min(r,Math.min(w[0],x[0])),a=Math.max(a,y[0]),s=Math.min(s,w[1]),l=Math.max(l,b[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=Ke.generateElementShape(t,null),r=Ct(o[0]),[s,a,l,d]=Li(r),c=s+t.x,u=a+t.y,m=l+t.x,p=d+t.y,f=(c+m)/2,h=(u+p)/2,E=i&&V(t,n);return E?e.getMinMaxXYWithBoundText(t,n,[c,u,m,p],E):[c,u,m,p,f,h]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!U(a))return t;if(n&&n>0&&n<a.points.length){let l=_e(Ut(qp(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,f)=>(p[f.index]=f,p),{});d[n]={index:n,start:O(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:O(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((p,f)=>p.index-f.index),u=c.map(p=>p.index).reduce((p,f)=>f<n?p+1:p,0);r.mutateElement(a,{fixedSegments:c});let m=O(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:m,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:m}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},nf=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},ql=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let m=new Map(e.map(_=>[_,{point:O(s.points[_][0]+t,s.points[_][1]+n),isDragging:!0}]));if(!H(s))return{positions:m};let p=e.includes(0),f=e.includes(s.points.length-1),{start:h,end:E}=ss(s,m,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c});if(U(s)){let _=p?h.element:f?E.element:null;return{positions:m,updates:{suggestedBinding:_?{element:_,midPoint:l.state.isMidpointSnappingEnabled?as(_,r,O(i-u.pointerOffset.x,o-u.pointerOffset.y)):void 0}:null}}}if(!p&&!f){let _={...s,points:s.points.map((F,A)=>m.get(A)?.point??F)},oe=new Map(m);if(s.startBinding){let F=r.get(s.startBinding.elementId);if(F){let A=pt(_,"startBinding",s.startBinding,F,r)??null;A&&oe.set(0,{point:A,isDragging:!0})}}if(s.endBinding){let F=r.get(s.endBinding.elementId);if(F){let A=pt(_,"endBinding",s.endBinding,F,r)??null;A&&oe.set(s.points.length-1,{point:A,isDragging:!0})}}return{positions:oe}}if(p===f)return{positions:m};let g={suggestedBinding:null};h.mode===null?g.startBinding=null:h.mode?(g.startBinding={elementId:h.element.id,mode:h.mode,...Vn(s,h.element,"start",r,h.focusPoint)},p&&(g.startBinding.mode==="orbit"||!Zn("COMPLEX_BINDINGS"))&&(g.suggestedBinding=h.element?{element:h.element,midPoint:$l(O(i-u.pointerOffset.x,o-u.pointerOffset.y),h.element,r,l.state.zoom)}:null)):p&&(g.suggestedBinding=l.state.suggestedBinding),E.mode===null?g.endBinding=null:E.mode?(g.endBinding={elementId:E.element.id,mode:E.mode,...Vn(s,E.element,"end",r,E.focusPoint)},f&&(g.endBinding.mode==="orbit"||!Zn("COMPLEX_BINDINGS"))&&(g.suggestedBinding=E.element?{element:E.element,midPoint:$l(O(i-u.pointerOffset.x,o-u.pointerOffset.y),E.element,r,l.state.zoom)}:null)):f&&(g.suggestedBinding=l.state.suggestedBinding);let x=p?O(s.points[0][0]+t,s.points[0][1]+n):s.points[0],w=f?O(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],b={...s,points:[x,...s.points.slice(1,-1),w],startBinding:g.startBinding===void 0?s.startBinding:g.startBinding===null?null:g.startBinding,endBinding:g.endBinding===void 0?s.endBinding:g.endBinding===null?null:g.endBinding},y=s.endBinding&&b.startBinding&&p&&b.startBinding.elementId===s.endBinding.elementId,I=s.startBinding&&b.endBinding&&f&&s.startBinding.elementId===b.endBinding.elementId,M=b.endBinding?E.element??r.get(b.endBinding.elementId):null,T=y?b.points[b.points.length-1]:I&&l.state.bindMode!=="inside"&&Zn("COMPLEX_BINDINGS")?b.points[0]:M&&pt(b,"endBinding",b.endBinding,M,r,f)||b.points[b.points.length-1];b.points[b.points.length-1]=T;let S=b.startBinding?h.element??r.get(b.startBinding.elementId):null,B=I&&Zn("COMPLEX_BINDINGS")?b.points[0]:y&&l.state.bindMode!=="inside"&&Zn("COMPLEX_BINDINGS")?T:S&&pt(b,"startBinding",b.startBinding,S,r,p)||b.points[0],L=!y&&!(I&&l.state.bindMode!=="inside"&&Zn("COMPLEX_BINDINGS"))&&!!M,k=Rn(B,b.points[0])!==0,C=new Set(e);S&&k&&C.add(0),M&&L&&C.add(s.points.length-1);let X=Array.from(C);return{updates:g,positions:new Map(X.map(_=>[_,_===0?{point:B,isDragging:!0}:_===s.points.length-1?{point:T,isDragging:!0}:m.get(_)]))}},Kl=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);P();import{arrayToMap as vt}from"@excalidraw/common";import{isPointWithinBounds as Ef,pointFrom as fs}from"@excalidraw/math";P();import{vectorCross as id,vectorFromPoint as Fo}from"@excalidraw/math";function ed(e){return[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])]}function of(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var rf=1e-6;function td(e,t){let n=Fo(e[1],e[0]),i=Fo(t,e[0]),o=id(n,i);return Math.abs(o)<rf}function cs(e,t){let n=Fo(e[1],e[0]),i=Fo(t,e[0]);return id(n,i)<0}function nd(e,t){return td(e,t[0])||td(e,t[1])||(cs(e,t[0])?!cs(e,t[1]):cs(e,t[1]))}function od(e,t){return of(ed(e),ed(t))&&nd(e,t)&&nd(t,e)}P();import{arrayToMap as uf,isShallowEqual as mf}from"@excalidraw/common";import{lineSegment as No,pointFrom as Qe,pointRotateRads as qn}from"@excalidraw/math";P();var sf=(e,t,n)=>{let i=n.reduce((o,r)=>(r.groupIds.includes(e)&&(o[r.id]=!0),o),{});return Object.keys(i).length<2?t.selectedGroupIds[e]||t.editingGroupId===e?{selectedElementIds:t.selectedElementIds,selectedGroupIds:{...t.selectedGroupIds,[e]:!1},editingGroupId:null}:t:{editingGroupId:t.editingGroupId,selectedGroupIds:{...t.selectedGroupIds,[e]:!0},selectedElementIds:{...t.selectedElementIds,...i}}},rd=function(){let e=null,t=null,n=null,i=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let d={};for(let m of r){let p=m.groupIds;if(a.editingGroupId){let f=p.indexOf(a.editingGroupId);f>-1&&(p=p.slice(0,f))}if(p.length>0){let f=p[p.length-1];d[f]=!0}}let c={},u=s.reduce((m,p)=>{if(p.isDeleted)return m;let f=p.groupIds.find(h=>d[h]);return f&&(m[p.id]=!0,Array.isArray(c[f])?c[f].push(p.id):c[f]=[p.id]),m},{});for(let m of Object.keys(c))c[m].length<2&&d[m]&&(d[m]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:us({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):Tt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:us(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),af=(e,t)=>ms(e,t)!=null,ms=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),lf=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),sd=(e,t)=>{let n={...t,selectedGroupIds:{}};for(let i of e){let o=i.groupIds;if(t.editingGroupId){let r=o.indexOf(t.editingGroupId);r>-1&&(o=o.slice(0,r))}if(o.length>0){let r=o[o.length-1];n={...n,...sf(r,n,e)}}}return n.selectedGroupIds},Xy=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),df=(e,t)=>e.groupIds.includes(t),Ge=(e,t)=>{let n=[];for(let i of e.values())df(i,t)&&n.push(i);return n},cf=(e,t)=>e.groupIds.find(n=>t[n]),$y=(e,t,n)=>{let i=[...e],o=n?i.indexOf(n):-1,r=o>-1?o:i.length;return i.splice(r,0,t),i},Vy=(e,t)=>e.filter(n=>!t[n]),Zy=(e,t)=>{let n=new Map;return e.forEach(i=>{let o=i.groupIds.length===0?i.id:i.groupIds[i.groupIds.length-1],r=n.get(o)||[],s=V(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},ad=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},ld=e=>{let t=e.flatMap(o=>o.groupIds),n=new Map,i=0;for(let o of t)n.set(o,(n.get(o)??0)+1),n.get(o)>i&&(i=n.get(o));return i===e.length},dd=e=>e.groupIds.length>0,cd=(e,t,n)=>{let i=[...e],o=t?e.indexOf(t):-1,r=o>-1?o:e.length;for(let s=0;s<r;s++)i[s]=n(i[s]);return i},Ro=(e,t,n)=>{let i=lf(n),o=e.filter(u=>!ue(u)),r=new Map,s=new Map,a=u=>{let m=s.get(u.id)||[],p=V(u,t);p&&m.push(p),s.set(u.id,[...m,u])},l=(u,m)=>{let p=r.get(m)||[],f=V(u,t);f&&p.push(f),r.set(m,[...p,u])},d=(u,m)=>{let p=u.groupIds.indexOf(m,0);return u.groupIds.slice(0,p).length>0?l(u,u.groupIds[p-1]):a(u)},c=e.every(u=>af(n,u));return o.forEach(u=>{let m=cf(u,n.selectedGroupIds);m?i.length===1&&c?d(u,m):l(u,m):a(u)}),Array.from(r.values()).concat(Array.from(s.values()))};var pf=e=>e.locked||ue(e),ud=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),ff=e=>{let t=new Set;return e.forEach(n=>{Z(n)&&t.add(n.id)}),ud(e,t)},ps=(e,t,n,i=!0,o="contain")=>{let[r,s,a,l]=$(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),m=Math.max(s,l),p=[d,c,u,m],f=[No(Qe(d,c),Qe(u,c)),No(Qe(u,c),Qe(u,m)),No(Qe(u,m),Qe(d,m)),No(Qe(d,m),Qe(d,c))],h=i?new Set:null,E=[];for(let g of e){if(pf(g))continue;let x=g.strokeWidth,w=null,b=se(g,n);b=[b[0]-x/2,b[1]-x/2,b[2]+x/2,b[3]+x/2];let y=H(g)&&V(g,n);if(y){let{x:T,y:S}=G.getBoundTextElementPosition(g,y,n);w=[T,S,T+y.width,S+y.height]}let I=Yt(g,n);if(I&&hn(g,I,n)){let T=se(I,n);b=[Math.max(b[0],T[0]),Math.max(b[1],T[1]),Math.min(b[2],T[2]),Math.min(b[3],T[3])],w=w?[Math.max(w[0],T[0]),Math.max(w[1],T[1]),Math.min(w[2],T[2]),Math.min(w[3],T[3])]:null}let M=w?[Math.min(w[0],b[0]),Math.min(w[1],b[1]),Math.max(w[2],b[2]),Math.max(w[3],b[3])]:b;if(md(p,M))if(h&&Z(g))h.add(g.id);else{E.push(g);continue}if(o==="overlap"&&w&&It(p,w)){E.push(g);continue}if(o==="overlap"&&It(p,b)){let T=!1;if(K(g)||Ee(g)){let S=ne(g,n);T=g.points.some(B=>{let L=qn(Qe(g.x+B[0],g.y+B[1]),S,g.angle);return ut(L,p)})}else{let S=se(g,n,!0),B=ne(g,n);T=[qn(Qe((S[0]+S[2])/2,S[1]),B,g.angle),qn(Qe(S[2],(S[1]+S[3])/2),B,g.angle),qn(Qe((S[0]+S[2])/2,S[3]),B,g.angle),qn(Qe(S[0],(S[1]+S[3])/2),B,g.angle)].some(L=>ut(qn(L,B,g.angle),p))}if(T||(T=f.some(S=>Pt(g,n,S,x/2,!0).length>0)),T){h&&Z(g)&&h.add(g.id),E.push(g);continue}}}return E=h?ud(E,h):E,E=E.filter(g=>{let x=Yt(g,n);return x?En(g,x,n):!0}),E},l0=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=pd(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},d0=function(){let e=null,t=null,n=null,i=(o,r)=>(n!=null&&o===e&&r.selectedElementIds===t||(n=o.some(s=>r.selectedElementIds[s.id]),e=o,t=r.selectedElementIds),n);return i.clearCache=()=>{e=null,t=null,n=null},i}(),Tt=(e,t,n)=>{let i=new Set,o=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){o.push(r),i.add(r.id);continue}if(n?.includeBoundTextElement&&ue(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{Z(s)&&gn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},c0=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:Tt(e,t,{includeBoundTextElement:!0}),us=(e,t)=>mf(t.selectedElementIds,e)?t.selectedElementIds:e,hf=(e,t)=>{let n=e.filter(K);if(n.length===1){let i=n[0],o=i.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===i.id||o.includes(s.id)))return new G(i,uf(t))}return null},u0=(e,t,n)=>({selectedLinearElement:hf(e,t),...rd({editingGroupId:n.editingGroupId,selectedElementIds:ff(e).reduce((i,o)=>(ue(o)||(i[o.id]=!0),i),{})},t,n,null)}),m0=(e,t)=>t.editingTextElement||e.length===1&&q(e[0])&&e[0]||null;var fd=(e,t,n)=>{let i=vt(e);for(let o of t)if(o.frameId){let r=n.get(o.id),s=n.get(o.frameId),a=r&&i.get(r);a&&Pe(a,i,{frameId:s??null})}};function hn(e,t,n){let i=hs(t,n),o=hs(e,n);return i.some(s=>o.some(a=>od(s,a)))}var hd=(e,t,n)=>zo(ps(e,t,n,!1)).filter(i=>!Z(i)&&!i.frameId||i.frameId===t.id),Es=(e,t,n)=>ps([t],e,n).some(i=>i.id===t.id),S0=(e,t)=>{let n=vt(e);return e.filter(i=>hn(i,t,n))},xn=(e,t,n)=>{let[i,o,r,s]=$(t,n),[a,l,d,c]=Oe(e);return i<=a&&o<=l&&r>=d&&s>=c},En=(e,t,n)=>xn([e],t,n)||hn(e,t,n)||Es(e,t,n),A0=(e,t,n)=>{let[i,o,r,s]=$(t,n);return Ef(fs(i,o),fs(e.x,e.y),fs(r,s))},M0=(e,t,n)=>{let i=vt(e),o=t.flatMap(r=>Ge(e,r));return o.length===0?!0:!!o.find(r=>xn([r],n,i)||hn(r,n,i))},T0=(e,t,n)=>{let i=vt(e),o=t.flatMap(r=>Ge(e,r));return o.length===0?!0:o.find(r=>xn([r],n,i)||hn(r,n,i))===void 0},v0=e=>{let t=new Map;for(let n of e){let i=Z(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,gn(e,i))}return t},gn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},gf=e=>e.filter(t=>Z(t)),D0=e=>{let t=vt(gf(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},B0=(e,t,n,i)=>{let o=gn(e,t.id),r=new Set(o),s=new Set([...hd(e,t,i),...o.filter(m=>Es(m,t,i))]),a=o.filter(m=>!s.has(m)),l=new Set(Array.from(s).flatMap(m=>m.groupIds));for(let m of a)if(!hn(m,t,i))m.groupIds.length===0&&r.delete(m);else if(m.groupIds.length>0)for(let p of m.groupIds)l.add(p);for(let m of a)if(m.groupIds.length>0){let p=!0;for(let f of m.groupIds)l.has(f)&&(p=!1);p&&r.delete(m)}let d=Array.from(s).filter(m=>m.groupIds.length===0);for(let m of d)r.add(m);let c=Array.from(s).filter(m=>m.groupIds.length>0),u=sd(c,n);for(let[m,p]of Object.entries(u))if(p){let f=Ge(e,m);if(xn(f,t,i))for(let h of f)r.add(h)}return[...r].filter(m=>!(q(m)&&m.containerId))},L0=(e,t,n)=>xf(zo(e,hd(e,t,n)),t,n),xf=(e,t,n)=>{let i=[],o=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>o.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>Ge(n,l)));s=!xn(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Yt=(e,t)=>e.frameId&&t.get(e.frameId)||null,C0=(e,t)=>{let n=new Set,i=vt(e);e=zo(e);for(let s of e)Z(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(Z(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!o.has(a)){o.add(a);let l=Ge(e,a);if(l.some(d=>En(d,t,i)))for(let d of l)r.push(d)}}else En(s,t,i)&&r.push(s);return r},wf=(e,t,n,i)=>{let o=vt(e),r=new Map;for(let d of e.values())d.frameId===n.id&&r.set(d.id,!0);let s=new Set(t.map(d=>d.id)),a=[],l=new Set;for(let d of t)Z(d)&&d.id!==n.id&&l.add(d.id);for(let d of zo(e,t)){if(Z(d)||d.frameId&&l.has(d.frameId)||d.frameId&&i.selectedElementIds[d.id]&&i.selectedElementIds[d.frameId])continue;r.has(d.id)||a.push(d);let c=V(d,o);c&&!s.has(c.id)&&!r.has(c.id)&&a.push(c)}for(let d of a)Pe(d,o,{frameId:n.id});return e},Ed=(e,t)=>{let n=new Map,i=new Map;for(let o of e)if(o.frameId){n.set(o.id,o);let r=i.get(o.frameId)||[];r.push(o);let s=V(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)Pe(o,t,{frameId:null})},bf=(e,t)=>{let n=gn(e,t.id);return Ed(n,vt(e)),e},G0=(e,t,n,i)=>wf(bf(e,n),t,n,i.state).slice(),O0=(e,t,n)=>{let i=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),o=new Set(i);if(t.editingGroupId)for(let a of i)a.groupIds.length===0?o.add(a):a.groupIds.flatMap(l=>Ge(e,l)).forEach(l=>o.add(l));let r=new Set,s=vt(e);return o.forEach(a=>{a.frameId&&!Z(a)&&!gd(a,s,t)&&r.add(a)}),r.size>0&&Ed(r,s),e},zo=(e,t)=>{let n=new Set,i=t||e;for(let s of i.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let o=new Set;for(let s of n)Ge(e,s).some(a=>Z(a))&&o.add(s);let r=[];for(let s of i.values())o.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},yf=(e,t,n)=>{let i=q(e)&&Me(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Yt(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Yt(i,t)},gd=(e,t,n,i)=>{let o=i?.targetFrame??yf(e,t,n);if(!o)return!1;let r=q(e)&&Me(e,t)||e,s=l=>{i?.checkedGroups&&r.groupIds.forEach(d=>{i.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[o.id])return!0;if(r.groupIds.length===0)return En(r,o,t);for(let l of r.groupIds)if(i?.checkedGroups?.has(l))return i.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>i?.checkedGroups?!i.checkedGroups.has(l):!0).flatMap(l=>Ge(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(Tt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(Z(l))return s(!1),!1;for(let l of a)if(En(l,o,t))return s(!0),!0;return!1},k0=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=hn(e,t,i)||Es(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!xn([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=gd(e,i,n,{targetFrame:t,checkedGroups:o});else{s=e.frameId===t.id;for(let a of e.groupIds)o?.set(a,s)}for(let a of e.groupIds)o?.set(a,s);return s}return!1},Pf="Frame",If="AI Frame",Sf=e=>uo(e)?Pf:If,F0=e=>e.name===null?Sf(e):e.name,R0=(e,t,n)=>e.filter(i=>(!i.frameId||i.frameId===t.id)&&It(se(i,n),se(t,n))),N0=e=>{let t=vt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Of=(e,t)=>Bn(e)&&!t.imageCache.has(e.fileId),jo=e=>{switch(e.type){case"freedraw":return e.strokeWidth*12;case"text":return e.fontSize/2;case"arrow":return e.endArrowhead||e.endArrowhead?40:20;default:return 20}},kf=(e,t,n,i,o=1)=>{let r=(t?.opacity??100)*e.opacity/1e4*o;return(n.has(e.id)||i&&i.some(s=>s.id===e.id)||t&&n.has(t.id))&&(r*=Tf/100),r},Ff=(e,t,n)=>{let r=jo(e),[s,a,l,d]=$(e,t),c=K(e)||Ee(e)?wn(s,l):e.width,u=K(e)||Ee(e)?wn(a,d):e.height,m=c*window.devicePixelRatio+r*2,p=u*window.devicePixelRatio+r*2,f=n.value;return(m*f>32767||p*f>32767)&&(f=Math.min(32767/m,32767/p)),m*p*f*f>16777216&&(f=Math.sqrt(16777216/(m*p))),m=Math.floor(m*f),p=Math.floor(p*f),{width:m,height:p,scale:f}},bd=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=jo(e),{width:l,height:d,scale:c}=Ff(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(K(e)||Ee(e)){let[g,x]=$(e,t);u=e.x>g?wn(e.x,g)*window.devicePixelRatio*c:0,m=e.y>x?wn(e.y,x)*window.devicePixelRatio*c:0,s.translate(u,m)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let p=Dn.canvas(r);Uo(e,p,s,i),s.restore();let f=V(e,t),h=document.createElement("canvas"),E=h.getContext("2d");if(H(e)&&f){let[g,x,w,b]=$(e,t),y=Math.max(wn(g,w),wn(x,b));h.width=y*window.devicePixelRatio*c+a*c*10,h.height=y*window.devicePixelRatio*c+a*c*10,E.translate(h.width/2,h.height/2),E.rotate(e.angle),E.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,I,M]=$(f,t);E.rotate(-e.angle);let T=(h.width-r.width)/2,S=(h.height-r.height)/2,B=h.width/2-(I-g)*window.devicePixelRatio*c-T-a*c,L=h.height/2-(M-x)*window.devicePixelRatio*c-S-a*c;E.translate(-B,-L),E.clearRect(-(f.width/2+_o)*window.devicePixelRatio*c,-(f.height/2+_o)*window.devicePixelRatio*c,(f.width+_o*2)*window.devicePixelRatio*c,(f.height+_o*2)*window.devicePixelRatio*c)}return{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,boundTextElementVersion:V(e,t)?.version||null,containingFrameOpacity:Yt(e,t)?.opacity||100,boundTextCanvas:h,angle:e.angle,imageCrop:be(e)?e.crop:null}},J0=14,yd=typeof document<"u"?document.createElement("img"):{src:""};yd.src=`data:${ws.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var Pd=typeof document<"u"?document.createElement("img"):{src:""};Pd.src=`data:${ws.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var Rf=(e,t,n)=>{t.fillStyle=n===Kn.DARK?"#2E2E2E":"#E7E7E7",t.fillRect(0,0,e.width,e.height);let i=Math.min(e.width,e.height),o=Math.min(i,Math.min(i*.4,100));t.drawImage(e.status==="error"?Pd:yd,e.width/2-o/2,e.height/2-o/2,o,o)},Uo=(e,t,n,i)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(Ke.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Ke.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=Ke.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=i.theme===Kn.DARK?Wo(e.strokeColor):e.strokeColor,n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{n.save();let o=e.fileId!==null?i.imageCache.get(e.fileId):null,r=Bn(e)?o?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,Ft(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight},c=i.theme===Kn.DARK&&o?.mimeType===ws.svg;if(c&&Gf){let u=window.devicePixelRatio||1,m=document.createElement("canvas");m.width=e.width*u,m.height=e.height*u;let p=m.getContext("2d");if(p){p.scale(u,u),p.drawImage(r,s,a,l,d,0,0,e.width,e.height);let f=p.getImageData(0,0,m.width,m.height),h=f.data;for(let E=0;E<h.length;E+=4)h[E]=255-h[E],h[E+1]=255-h[E+1],h[E+2]=255-h[E+2];p.putImageData(f,0,0),n.drawImage(m,0,0,m.width,m.height,0,0,e.width,e.height)}}else c&&(n.filter=vf),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else Rf(e,n,i.theme);n.restore();break}default:if(q(e)){let o=Bf(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=Df(e),n.fillStyle=i.theme===Kn.DARK?Wo(e.strokeColor):e.strokeColor,n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
10
11
  `).split(`
11
- `),l=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,c=zi(e.fontSize,e.lineHeight),d=zm(e.fontFamily,e.fontSize,c);for(let u=0;u<a.length;u++)n.fillText(a[u],l,u*c+d);n.restore(),s&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},Eo=new WeakMap,Ml=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=Eo.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=Z(e,t),l=a?.version||null,c=xe(e)?e.crop:null,d=Dt(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.boundTextElementVersion!==l||r.imageCrop!==c||r.containingFrameOpacity!==d||_(e)&&a&&e.angle!==r.angle){let u=Ll(e,t,o,n,i);return u?(Eo.set(e,u),u):null}return r},Nr=(e,t,n,i,o)=>{let r=e.element,s=go(r),a=e.scale,[l,c,d,u]=H(r,o),p=((l+d)/2+i.scrollX)*window.devicePixelRatio,m=((c+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=Z(r,o);if(_(r)&&f){let E=(e.boundTextCanvas.width-e.canvas.width)/2,h=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(p,m),t.drawImage(e.boundTextCanvas,-(d-l)/2*window.devicePixelRatio-E/a-s,-(u-c)/2*window.devicePixelRatio-h/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(p,m),t.rotate(r.angle),"scale"in e.element&&!vl(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-p,-m),t.drawImage(e.canvas,(l+i.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(c+i.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),A.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&st(r)){let E=Z(r,o),h=ar(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((h.x+i.scrollX)*window.devicePixelRatio,(h.y+i.scrollY)*window.devicePixelRatio,Je(r,E)*window.devicePixelRatio,ei(r,E)*window.devicePixelRatio)}t.restore()},Wb=(e,t,n,i)=>{t.save(),t.translate(e.x+n.scrollX,e.y+n.scrollY),t.fillStyle="rgba(0, 0, 200, 0.04)";let o=.5/n.zoom.value;t.fillRect(o,o,e.width,e.height),t.lineWidth=1/n.zoom.value,t.strokeStyle=i,t.strokeRect(o,o,e.width,e.height),t.restore()},jb=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=_m(e,Dt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?km:1),e.type){case"magicframe":case"frame":{s.frameRendering.enabled&&s.frameRendering.outline&&(o.save(),o.translate(e.x+s.scrollX,e.y+s.scrollY),o.fillStyle="rgba(0, 0, 200, 0.04)",o.lineWidth=fo.strokeWidth/s.zoom.value,o.strokeStyle=fo.strokeColor,oa(e)&&(o.strokeStyle=s.theme===Al.LIGHT?"#7affd7":"#1d8264"),fo.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,fo.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(be.generateElementShape(e,null),r.isExporting){let[l,c,d,u]=H(e,t),p=(l+d)/2+s.scrollX,m=(c+u)/2+s.scrollY,f=(d-l)/2-(e.x-l),E=(u-c)/2-(e.y-c);o.save(),o.translate(p,m),o.rotate(e.angle),o.translate(-f,-E),ho(e,i,o,r,s),o.restore()}else{let l=Ml(e,n,r,s);if(!l)return;Nr(l,o,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(be.generateElementShape(e,r),r.isExporting){let[l,c,d,u]=H(e,t),p=(l+d)/2+s.scrollX,m=(c+u)/2+s.scrollY,f=(d-l)/2-(e.x-l),E=(u-c)/2-(e.y-c);if(ne(e)){let g=Ce(e,t);if(_(g)){let x=Y.getBoundTextElementPosition(g,e,t);f=(d-l)/2-(x.x-l),E=(u-c)/2-(x.y-c)}}o.save(),o.translate(p,m),Dl(e,r,s)&&(o.filter="none");let h=Z(e,t);if(_(e)&&h){let g=document.createElement("canvas"),x=g.getContext("2d"),y=Math.max(Qt(l,d),Qt(c,u)),b=go(e);g.width=y*s.exportScale+b*10*s.exportScale,g.height=y*s.exportScale+b*10*s.exportScale,x.translate(g.width/2,g.height/2),x.scale(s.exportScale,s.exportScale),f=e.width/2-(e.x-l),E=e.height/2-(e.y-c),x.rotate(e.angle);let w=sn.canvas(g);x.translate(-f,-E),ho(e,w,x,r,s),x.translate(f,E),x.rotate(-e.angle);let[,,,,I,M]=H(h,t),v=(l+d)/2-I,T=(c+u)/2-M;x.translate(-v,-T),x.clearRect(-h.width/2,-h.height/2,h.width,h.height),o.scale(1/s.exportScale,1/s.exportScale),o.drawImage(g,-g.width/2,-g.height/2,g.width,g.height)}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-f,-E),ho(e,i,o,r,s);o.restore()}else{let l=Ml(e,n,r,s);if(!l)return;let c=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Om(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&xe(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let d=Ll(Qs(l.element,t),n,s.zoom,r,s);d&&Nr(d,o,r,s,n),o.restore()}Nr(l,o,r,s,n),o.imageSmoothingEnabled=c}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1},Gl=new WeakMap([]);function Ol(e){let t=Wm(e),n=new Path2D(t);return Gl.set(e,n),n}function Um(e){return Gl.get(e)}function Wm(e){let t=e.simulatePressure?e.points:e.points.length?e.points.map(([i,o],r)=>[i,o,e.pressures[r]]):[[0,0,.5]],n={simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:i=>Math.sin(i*Math.PI/2),last:!!e.lastCommittedPoint};return Vm(Vs(t,n))}function Tl(e,t){return[(e[0]+t[0])/2,(e[1]+t[1])/2]}var jm=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;function Vm(e){if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Tl(i,r[0]),"L",r[0],"Z"):n.push(i,Tl(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(jm,"$1")}P();var Zb=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",qb=e=>e!=="image"&&e!=="frame"&&e!=="magicframe",Kb=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",Qb=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",kl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",Jb=e=>e==="arrow",e0=e=>e==="arrow";var be=class e{static rg=new Ue;static cache=new WeakMap;static get=t=>e.cache.get(t);static set=(t,n)=>e.cache.set(t,n);static delete=t=>e.cache.delete(t);static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let i=n?.isExporting?void 0:e.get(t);if(i!==void 0)return i;Eo.delete(t);let o=ef(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:qm.white,embedsValidationStatus:null});return e.cache.set(t,o),o}},Qm=e=>[8,8+e],zl=e=>[1.5,6+e];function Jm(e){let t=e.roughness,n=Math.max(e.width,e.height),i=Math.min(e.width,e.height);return i>=20&&n>=50||i>=15&&e.roundness&&kl(e.type)||U(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Re=(e,t=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?Qm(e.strokeWidth):e.strokeStyle==="dotted"?zl(e.strokeWidth):void 0,disableMultiStroke:e.strokeStyle!=="solid",strokeWidth:e.strokeStyle!=="solid"?e.strokeWidth+.5:e.strokeWidth,fillWeight:e.strokeWidth/2,hachureGap:e.strokeWidth*4,roughness:Jm(e),stroke:e.strokeColor,preserveVertices:t||e.roughness<$m.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=ai(e.backgroundColor)?void 0:e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return an(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},Fl=(e,t,n)=>Oi(e)&&(t||ia(e)&&n?.get(e.id)!==!0)&&ai(e.backgroundColor)&&ai(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:Gi(e)?{...e,strokeColor:ai(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:ai(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Nl=(e,t,n,i,o,r,s)=>{let a=Hr(e,t,n,i);if(a===null)return[];let l=(c,d)=>{if(c===null)return[];let[,,u,p,m,f]=c;return[o.line(u,p,m,f,d)]};switch(i){case"dot":case"circle":case"circle_outline":{let[c,d,u]=a;return delete r.strokeLineDash,[o.circle(c,d,u,{...r,fill:i==="circle_outline"?s:e.strokeColor,fillStyle:"solid",stroke:e.strokeColor,roughness:Math.min(.5,r.roughness||0)})]}case"triangle":case"triangle_outline":{let[c,d,u,p,m,f]=a;return delete r.strokeLineDash,[o.polygon([[c,d],[u,p],[m,f],[c,d]],{...r,fill:i==="triangle_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[c,d,u,p,m,f,E,h]=a;return delete r.strokeLineDash,[o.polygon([[c,d],[u,p],[m,f],[E,h],[c,d]],{...r,fill:i==="diamond_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"crowfoot_one":return l(a,r);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[c,d,u,p,m,f]=a;if(e.strokeStyle==="dotted"){let E=zl(e.strokeWidth-1);r.strokeLineDash=[E[0],E[1]-1]}else delete r.strokeLineDash;return r.roughness=Math.min(1,r.roughness||0),[o.line(u,p,c,d,r),o.line(m,f,c,d,r),...i==="crowfoot_one_or_many"?l(Hr(e,t,n,"crowfoot_one"),r):[]]}}},ta=e=>{let t=new Ue,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=ct(e.points.reduce((o,r)=>[Math.min(e.x+r[0],o[0]),Math.min(e.y+r[1],o[1]),Math.max(e.x+r[0],o[2]),Math.max(e.y+r[1],o[3])],[1/0,1/0,-1/0,-1/0]));switch(e.type){case"line":case"arrow":{let o=e.points.length?e.points:[ce(0,0)];return G(e)?t.path(Hl(o,16),n).sets[0].ops:e.roundness?t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Lt(ce(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:ce(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(ce(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Lt(ce(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Lt(ce(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>ce(a[0]-e.x,a[1]-e.y)).flat()}}):o.map((r,s)=>{let a=Lt(ce(e.x+r[0],e.y+r[1]),i,e.angle);return{op:s===0?"move":"lineTo",data:ce(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let o=Wn(e.points,.75);return t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Lt(ce(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:ce(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(ce(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Lt(ce(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Lt(ce(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>ce(a[0]-e.x,a[1]-e.y)).flat()}})}}},ef=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o})=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":{let r;if(e.roundness){let s=e.width,a=e.height,l=yt(Math.min(s,a),e);r=t.path(`M ${l} 0 L ${s-l} 0 Q ${s} 0, ${s} ${l} L ${s} ${a-l} Q ${s} ${a}, ${s-l} ${a} L ${l} ${a} Q 0 ${a}, 0 ${a-l} L 0 ${l} Q 0 0, ${l} 0`,Re(Fl(e,n,o),!0))}else r=t.rectangle(0,0,e.width,e.height,Re(Fl(e,n,o),!1));return r}case"diamond":{let r,[s,a,l,c,d,u,p,m]=Bi(e);if(e.roundness){let f=yt(Math.abs(s-p),e),E=yt(Math.abs(c-a),e);r=t.path(`M ${s+f} ${a+E} L ${l-f} ${c-E}
12
- C ${l} ${c}, ${l} ${c}, ${l-f} ${c+E}
13
- L ${d+f} ${u-E}
14
- C ${d} ${u}, ${d} ${u}, ${d-f} ${u-E}
15
- L ${p+f} ${m+E}
16
- C ${p} ${m}, ${p} ${m}, ${p+f} ${m-E}
17
- L ${s-f} ${a+E}
18
- C ${s} ${a}, ${s} ${a}, ${s+f} ${a+E}`,Re(e,!0))}else r=t.polygon([[s,a],[l,c],[d,u],[p,m]],Re(e));return r}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Re(e));case"line":case"arrow":{let r,s=Re(e),a=e.points.length?e.points:[ce(0,0)];if(G(e)?a.every(l=>Math.abs(l[0])<=1e6&&Math.abs(l[1])<=1e6)?r=[t.path(Hl(a,16),Re(e,!0))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(a)),r=[]):e.roundness?r=[t.curve(a,s)]:s.fill?r=[t.polygon(a,s)]:r=[t.linearPath(a,s)],e.type==="arrow"){let{startArrowhead:l=null,endArrowhead:c="arrow"}=e;if(l!==null){let d=Nl(e,r,"start",l,t,s,i);r.push(...d)}if(c!==null){let d=Nl(e,r,"end",c,t,s,i);r.push(...d)}}return r}case"freedraw":{let r;if(Ol(e),an(e.points)){let s=Wn(e.points,.75);r=t.curve(s,{...Re(e),stroke:"none"})}else r=null;return r}case"frame":case"magicframe":case"text":case"image":return null;default:return Zm(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Hl=(e,t)=>{let n=[];for(let o=1;o<e.length-1;o+=1){let r=e[o-1],s=e[o+1],a=e[o],l=et(a,r),c=et(s,a),d=Math.min(t,Rl(e[o],s)/2,Rl(e[o],r)/2);l?r[0]<a[0]?n.push([e[o][0]-d,e[o][1]]):n.push([e[o][0]+d,e[o][1]]):r[1]<a[1]?n.push([e[o][0],e[o][1]-d]):n.push([e[o][0],e[o][1]+d]),n.push(e[o]),c?s[0]<a[0]?n.push([e[o][0]-d,e[o][1]]):n.push([e[o][0]+d,e[o][1]]):s[1]<a[1]?n.push([e[o][0],e[o][1]-d]):n.push([e[o][0],e[o][1]+d])}let i=[`M ${e[0][0]} ${e[0][1]}`];for(let o=0;o<n.length;o+=3)i.push(`L ${n[o][0]} ${n[o][1]}`),i.push(`Q ${n[o+1][0]} ${n[o+1][1]}, ${n[o+2][0]} ${n[o+2][1]}`);return i.push(`L ${e[e.length-1][0]} ${e[e.length-1][1]}`),i.join(" ")},_l=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Rs(e);case"arrow":case"line":{let n=be.get(e)?.[0]??be.generateElementShape(e,null)[0],[,,,,i,o]=H(e,t);return Ui(e)?Hs(e,n,ce(e.x,e.y),e.angle,ce(i,o)):Ns(n,ce(e.x,e.y),e.angle,ce(i,o))}case"ellipse":return Fs(e);case"freedraw":{let[,,,,n,i]=H(e,t);return zs(e,ce(n,i),Ui(e))}}},nl=(e,t)=>{let n=[...e.points];if(t){if(!la(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>Km||n.length<4?n.push(ce(o[0],o[1])):n[n.length-1]=ce(o[0],o[1])}return{polygon:t,points:n}};var Xr=class e{static boundsCache=new WeakMap;static nonRotatedBoundsCache=new WeakMap;static getBounds(t,n,i=!1){let o=i&&t.angle!==0?e.nonRotatedBoundsCache.get(t):e.boundsCache.get(t);if(o?.version&&o.version===t.version&&!fe(t))return o.bounds;if(i&&t.angle!==0){let s=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:s}),s}let r=e.calculateBounds(t,n);return e.boundsCache.set(t,{version:t.version,bounds:r}),r}static calculateBounds(t,n){let i,[o,r,s,a,l,c]=H(t,n);if(Se(t)){let[d,u,p,m]=Ur(t.points.map(([f,E])=>se(D(f,E),D(l-t.x,c-t.y),t.angle)));return[d+t.x,u+t.y,p+t.x,m+t.y]}else if(U(t))i=df(t,l,c,n);else if(t.type==="diamond"){let[d,u]=se(D(l,r),D(l,c),t.angle),[p,m]=se(D(l,a),D(l,c),t.angle),[f,E]=se(D(o,c),D(l,c),t.angle),[h,g]=se(D(s,c),D(l,c),t.angle),x=Math.min(d,p,f,h),y=Math.min(u,m,E,g),b=Math.max(d,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}else if(t.type==="ellipse"){let d=(s-o)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(d*p,u*m),E=Math.hypot(u*p,d*m);i=[l-f,c-E,l+f,c+E]}else{let[d,u]=se(D(o,r),D(l,c),t.angle),[p,m]=se(D(o,a),D(l,c),t.angle),[f,E]=se(D(s,a),D(l,c),t.angle),[h,g]=se(D(s,r),D(l,c),t.angle),x=Math.min(d,p,f,h),y=Math.min(u,m,E,g),b=Math.max(d,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}return i}},H=(e,t,n=!1)=>{if(Se(e))return sf(e);if(U(e))return Y.getElementAbsoluteCoords(e,t,n);if(ne(e)){let i=t?Ce(e,t):null;if(_(i)){let{x:o,y:r}=Y.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},Rr=(e,t)=>{let n=_l(e,t),[i,o,r,s,a,l]=H(e,t),c=D(a,l);if(n.type==="polycurve"){let g=n.data.map(b=>Et(b,10)).flat(),x=0,y=[];for(;x<g.length-1;)y.push(Ee(D(g[x][0],g[x][1]),D(g[x+1][0],g[x+1][1]))),x++;return y}else{if(n.type==="polyline")return n.data;if(of(e)){let[h,g]=yn(e),x=g.map(b=>Ul(b,c,e.angle)).flat();return[...Xl(h,c,e.angle),...x]}else if(e.type==="diamond"){let[h,g]=bn(e),x=g.map(b=>Ul(b,c,e.angle)).flat();return[...Xl(h,c,e.angle),...x]}else if(n.type==="polygon"){if(ne(e)){let x=Ce(e,t);if(x&&U(x))return[Ee(D(i,o),D(r,o)),Ee(D(r,o),D(r,s)),Ee(D(r,s),D(i,s)),Ee(D(i,s),D(i,o))]}let h=n.data,g=[];for(let x=0;x<h.length-1;x++)g.push(Ee(h[x],h[x+1]));return g}else if(n.type==="ellipse")return rf(e)}let[d,u,p,m,,,f,E]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(h=>se(h,c,e.angle));return[Ee(d,u),Ee(p,m),Ee(d,p),Ee(u,m),Ee(d,E),Ee(p,E),Ee(u,f),Ee(m,f)]},of=e=>e!=null&&(e.type==="rectangle"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),Xl=(e,t,n)=>e.map(i=>Ee(se(i[0],t,n),se(i[1],t,n))),Ul=(e,t,n)=>{let i=Et(e,10),o=0,r=[];for(;o<i.length-1;)r.push(Ee(se(D(i[o][0],i[o][1]),t,n),se(D(i[o+1][0],i[o+1][1]),t,n))),o++;return r},rf=e=>{let t=D(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let c=l*a,d=t[0]+n*Math.cos(c),u=t[1]+i*Math.sin(c);r.push(se(D(d,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(Ee(r[l],r[l+1]));return o.push(Ee(r[r.length-1],r[0])),o},L0=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Bi=e=>{let t=Math.floor(e.width/2)+1,n=0,i=e.width,o=Math.floor(e.height/2)+1,r=t,s=e.height;return[t,n,i,o,r,s,0,o]},Wl=(e,t,n,i,o)=>{let r=1-e;return Math.pow(r,3)*t+3*Math.pow(r,2)*e*n+3*r*Math.pow(e,2)*i+Math.pow(e,3)*o},jl=(e,t,n,i)=>{let o=t-e,r=n-t,s=i-n,a=3*o-6*r+3*s,l=6*r-6*o,c=3*o,d=l*l-4*a*c;if(!(d>=0))return!1;let p=null,m=null,f=1/0,E=1/0;return a===0?f=E=-c/l:(f=(-l+Math.sqrt(d))/(2*a),E=(-l-Math.sqrt(d))/(2*a)),f>=0&&f<=1&&(p=Wl(f,e,t,n,i)),E>=0&&E<=1&&(m=Wl(E,e,t,n,i)),[p,m]},Wi=(e,t,n,i)=>{let o=jl(e[0],t[0],n[0],i[0]),r=jl(e[1],t[1],n[1],i[1]),s=Math.min(e[0],i[0]),a=Math.max(e[0],i[0]);if(o){let d=o.filter(u=>u!==null);s=Math.min(s,...d),a=Math.max(a,...d)}let l=Math.min(e[1],i[1]),c=Math.max(e[1],i[1]);if(r){let d=r.filter(u=>u!==null);l=Math.min(l,...d),c=Math.max(c,...d)}return[s,l,a,c]},si=(e,t)=>{let n=D(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:c})=>{if(l==="move"){let d=$l(c);Yr(d!=null,"Op data is not a point"),n=d}else if(l==="bcurveTo"){let d=D(c[0],c[1]),u=D(c[2],c[3]),p=D(c[4],c[5]),m=t?t(d):d,f=t?t(u):u,E=t?t(p):p,h=t?t(n):n;n=p;let[g,x,y,b]=Wi(h,m,f,E);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,y),a.maxY=Math.max(a.maxY,b)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},Ur=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;for(let[r,s]of e)t=Math.min(t,r),n=Math.min(n,s),i=Math.max(i,r),o=Math.max(o,s);return[t,n,i,o]},sf=e=>{let[t,n,i,o]=Ur(e.points),r=t+e.x,s=n+e.y,a=i+e.x,l=o+e.y;return[r,s,a,l,(r+a)/2,(s+l)/2]},af=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"crowfoot_many":case"crowfoot_one":case"crowfoot_one_or_many":return 20;default:return 15}},lf=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},Hr=(e,t,n,i)=>{if(t.length<1)return null;let o=gt(t[0]);if(o.length<1)return null;let r=n==="start"?1:o.length-1,s=o[r].data;Yr(s.length===6,"Op data length is not 6");let a=D(s[4],s[5]),l=D(s[2],s[3]),c=D(s[0],s[1]),d=o[r-1],u=D(0,0);if(d.op==="move"){let N=$l(d.data);Yr(N!=null,"Op data is not a point"),u=N}else d.op==="bcurveTo"&&(u=D(d.data[4],d.data[5]));let p=(N,ee)=>Math.pow(1-N,3)*a[ee]+3*N*Math.pow(1-N,2)*l[ee]+3*Math.pow(N,2)*(1-N)*c[ee]+u[ee]*Math.pow(N,3),[m,f]=n==="start"?u:a,[E,h]=[p(.3,0),p(.3,1)],g=Math.hypot(m-E,f-h),x=(m-E)/g,y=(f-h)/g,b=af(i),w=0;{let[N,ee]=n==="end"?e.points[e.points.length-1]:e.points[0],[S,K]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];w=Math.hypot(N-S,ee-K)}let M=Math.min(b,w*(i==="diamond"||i==="diamond_outline"?.25:.5)),v=m-x*M,T=f-y*M;if(i==="dot"||i==="circle"||i==="circle_outline"){let N=Math.hypot(T-f,v-m)+e.strokeWidth-2;return[m,f,N]}let F=lf(i);if(i==="crowfoot_many"||i==="crowfoot_one_or_many"){let[N,ee]=se(D(m,f),D(v,T),_r(-F)),[S,K]=se(D(m,f),D(v,T),_r(F));return[v,T,N,ee,S,K]}let[C,R]=se(D(v,T),D(m,f),-F*Math.PI/180),[L,W]=se(D(v,T),D(m,f),_r(F));if(i==="diamond"||i==="diamond_outline"){let N,ee;if(n==="start"){let[S,K]=e.points.length>1?e.points[1]:[0,0];[N,ee]=se(D(m+M*2,f),D(m,f),Math.atan2(K-f,S-m))}else{let[S,K]=e.points.length>1?e.points[e.points.length-2]:[0,0];[N,ee]=se(D(m-M*2,f),D(m,f),Math.atan2(f-K,m-S))}return[m,f,C,R,N,ee,L,W]}return[m,f,C,R,L,W]},cf=e=>{let t=sn.generator(),n=Re(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},df=(e,t,n,i)=>{let o=Z(e,i);if(e.points.length<2){let[u,p]=e.points[0],[m,f]=se(D(e.x+u,e.y+p),D(t,n),e.angle),E=[m,f,m,f];if(o){let h=Y.getMinMaxXYWithBoundText(e,i,[m,f,m,f],o);E=[h[0],h[1],h[2],h[3]]}return E}let s=be.get(e)?.[0]??cf(e),a=gt(s),c=si(a,([u,p])=>se(D(e.x+u,e.y+p),D(t,n),e.angle)),d=[c[0],c[1],c[2],c[3]];if(o){let u=Y.getMinMaxXYWithBoundText(e,i,d,o);d=[u[0],u[1],u[2],u[3]]}return d},he=(e,t,n=!1)=>Xr.getBounds(e,t,n),tt=(e,t)=>{if(!tf(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Vl(e);return e.forEach(a=>{let[l,c,d,u]=he(a,s);n=Math.min(n,l),o=Math.min(o,c),i=Math.max(i,d),r=Math.max(r,u)}),[n,o,i,r]},C0=(e,t)=>{let[n,i,o,r]=tt(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},Nt=(e,t,n,i)=>{if(!(U(e)||Se(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Yl(0,t,Yl(1,n,e.points,i),i),r;if(Se(e))r=Ur(o);else{let d=sn.generator(),u=e.roundness?d.curve(o,Re(e)):d.linearPath(o,Re(e)),p=gt(u);r=si(p)}let[s,a,l,c]=r;return[s+e.x,a+e.y,l+e.x,c+e.y]},Lr=(e,t)=>{let n=sn.generator(),i=e.roundness==null?n.linearPath(t,Re(e)):n.curve(t,Re(e)),o=gt(i),[r,s,a,l]=si(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},B0=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=Vl(e);return e.forEach(r=>{let[s,a,l,c]=he(r,o),d=nf(D((s+l)/2,(a+c)/2),D(t.x,t.y));d<n&&(n=d,i=r)}),he(i,o)},Ct=e=>{let[t,n,i,o]=tt(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},G0=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],ct=e=>D(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),Ve=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=me(e,t),[r,s]=se(D(i.minX,i.minY),o,e.angle),[a,l]=se(D(i.maxX,i.minY),o,e.angle),[c,d]=se(D(i.maxX,i.maxY),o,e.angle),[u,p]=se(D(i.minX,i.maxY),o,e.angle),m=[Math.min(r,a,c,u),Math.min(s,l,d,p),Math.max(r,a,c,u),Math.max(s,l,d,p)];if(n){let[f,E,h,g]=n;return[m[0]-g,m[1]-f,m[2]+E,m[3]+h]}return m},Mn=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],un=(e,t)=>{if(e==null||t==null)return!1;let[n,i,o,r]=e,[s,a,l,c]=t;return n<l&&o>s&&i<c&&r>a},me=(e,t,n=0,i=0)=>{let[o,r]=ct(he(e,t));return D(o+n,r+i)};var ff=.1,ql=e=>U(e)||Se(e)?e.points.length<2||e.points.length===2&&_(e)&&mf(e.points[0],e.points[e.points.length-1],ff):e.width===0&&e.height===0,yl=(e,t,n,i,o)=>{let[r,s,a,l]=he(e,o),c=xo({clientX:i.offsetLeft,clientY:i.offsetTop},i),d=xo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return c.x<=a&&c.y<=l&&d.x>=r&&d.y>=s},_0=(e,t,n,i,o,r)=>{let[s,a,l,c]=tt(e,o),d=xo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=xo({clientX:i.offsetLeft+t-(r?.right||0),clientY:i.offsetTop+n-(r?.bottom||0)},i);return s>=d.x&&a>=d.y&&l<=u.x&&c<=u.y},Wr=(e,t,n)=>{let i=Math.abs(t),o=Math.abs(n);if(e==="line"||e==="arrow"||e==="freedraw"){let r=Math.round(Math.atan(o/i)/Bt)*Bt;r===0?n=0:r===Math.PI/2?t=0:n=i*Math.tan(r)*Math.sign(n)||n}else e!=="selection"&&(n=i*Math.sign(n));return{width:t,height:n}},il=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Bt)*Bt;if(o){let c=Math.floor(o/Bt)*Bt;uf(a,c,c+Bt)&&(pf(a,o)<Bt/6?l=o:Zl(a)>Zl(o)?l=c+Bt:l=c)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let c=Math.tan(l),d=-1,u=t-c*e,p=-1/c,m=-1,f=i-p*n,E=(d*f-m*u)/(c*m-p*d),h=(u*p-f*c)/(c*m-p*d);r=E-e,s=h-t}return{width:r,height:s}},Y0=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t};P();var $0=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o=uo(e,i),r=Ct(e);return o.flatMap(s=>{let a=hf(s,r,t);return s.map(l=>{let c=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Xe(l,n,{simultaneouslyUpdated:s}),c})})},hf=(e,t,{axis:n,position:i})=>{let o=Ct(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};P();import{arrayToMap as dh,arrayToObject as Gt,assertNever as Ac,isDevEnv as Rn,isShallowEqual as vc,isTestEnv as Fn,randomInteger as Tc}from"@excalidraw/common";P();import{assertNever as Tf,COLOR_PALETTE as Af,isDevEnv as vf,isTestEnv as Df,randomId as Lf,Emitter as Jl,toIterable as Bn}from"@excalidraw/common";P();import{ORIG_ID as wf,randomId as Ql,randomInteger as yf,arrayToMap as bf,castArray as jr,findLastIndex as li,getUpdatedTimestamp as Pf,isTestEnv as If}from"@excalidraw/common";P();import{arrayToMapWithIndex as Ef}from"@excalidraw/common";var gf=e=>{let t=e.slice(),n=new Set,i=r=>{let s=r[0]?.groupIds?.join(""),a=[r[0]],l=[];for(let c of r.slice(1))c.groupIds?.join("")===s?a.push(c):l.push(c);return l.length?[...a,...i(l)]:a},o=new Map;return t.forEach((r,s)=>{if(!o.has(r.id))if(r.groupIds?.length){let a=r.groupIds[r.groupIds.length-1],l=t.slice(s).filter(c=>{let d=c?.groupIds?.some(u=>u===a);return d&&o.set(c.id,!0),d});for(let c of i(l))n.add(c)}else n.add(r)}),n.size!==e.length?(console.error("normalizeGroupElementOrder: lost some elements... bailing!"),e):[...n]},xf=e=>{let t=Ef(e),n=e.slice(),i=new Set;return n.forEach((o,r)=>{o&&(o.boundElements?.length?(i.add(o),n[r]=null,o.boundElements.forEach(s=>{let a=t.get(s.id);a&&s.type==="text"&&(i.add(a[0]),n[a[1]]=null)})):o.type==="text"&&o.containerId&&t.get(o.containerId)?.[0].boundElements?.find(a=>a.id===o.id)||(i.add(o),n[r]=null))}),i.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...i]},Kl=e=>xf(gf(e));var Sf=(e,t,n,i)=>{let o=$r(n);return If()&&Mf(o,n.id),o.id=Ql(),o.updated=Pf(),i&&(o.seed=yf(),ka(o)),o.groupIds=xl(o.groupIds,e,r=>(t.has(r)||t.set(r,Ql()),t.get(r))),o},l1=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},i=new Map,o=new Map,r=[],s=[],a=new Map,l=new Map,c=new Map,d=bf(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(h=>[h.id,h]));if(e.type==="in-place")for(let h of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(h)).forEach(g=>u.set(g.id,g));t=Kl(t);let p=t.slice(),m=h=>{let x=jr(h).reduce((y,b)=>{if(i.has(b.id))return y;i.set(b.id,!0);let w=Sf(n.editingGroupId,o,b,e.randomizeSeed);return i.set(w.id,!0),c.set(w.id,w),a.set(b.id,w.id),l.set(w.id,b),s.push(b),r.push(w),y.push(w),y},[]);return Array.isArray(h)?x:x[0]||null},f=(h,g)=>{if(g){if(h>p.length-1){p.push(...jr(g));return}p.splice(h+1,0,...jr(g))}},E=new Set(t.filter(h=>u.has(h.id)&&V(h)).map(h=>h.id));for(let h of t){if(i.has(h.id)||!u.has(h.id))continue;let g=Gr(n,h);if(g){let x=Ae(t,g).flatMap(b=>V(b)?[...qt(t,b.id),b]:[b]),y=li(p,b=>b.groupIds?.includes(g));f(y,m(x));continue}if(!(h.frameId&&E.has(h.frameId))){if(V(h)){let x=h.id,y=qt(t,x),b=li(p,w=>w.frameId===x||w.id===x);f(b,m([...y,h]));continue}if(st(h)){let x=Z(h,d),y=li(p,b=>b.id===h.id||"containerId"in b&&b.containerId===h.id);x?f(y,m([h,x])):f(y,m(h));continue}if(fe(h)){let x=Ce(h,d),y=li(p,b=>b.id===h.id||b.id===x?.id);x?f(y,m([x,h])):f(y,m(h));continue}f(li(p,x=>x.id===h.id),m(h))}}if($a(r,a,c),bl(p,s,a),e.overrides)for(let h of r){let g=l.get(h.id);g&&Object.assign(h,e.overrides({duplicateElement:h,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:c,elementsWithDuplicates:p,origIdToDuplicateId:a}},Vr=(e,t=0)=>{if(e==null||typeof e!="object")return e;let n=Object.prototype.toString.call(e);if(n==="[object Object]"){let i=typeof e.constructor=="function"?Object.create(Object.getPrototypeOf(e)):{};for(let o in e)if(e.hasOwnProperty(o)){if(t===0&&(o==="shape"||o==="canvas"))continue;i[o]=Vr(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=Vr(e[i],t+1);return o}return A.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},$r=e=>Vr(e),Mf=(e,t)=>{Object.defineProperty(e,wf,{value:t,writable:!1,enumerable:!1})};var Fe={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},ec=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Jl;onStoreIncrementEmitter=new Jl;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=hn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Fe.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=hn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?ic(t.elements):void 0,t.appState);i=ci.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=hn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=ci.create(o,t),i?s=i:s=Kr.calculate(o,t),!s.isEmpty()){let a=new Zr(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=ci.create(r,t)}let o=new qr(i);this.onStoreIncrementEmitter.trigger(o)}applyChangeToSnapshot(t){let n=this.snapshot,i=this.snapshot.applyChange(t);return n===i?null:i}maybeCloneSnapshot(t,n,i){if(!n&&!i)return null;let o=this.snapshot,r=this.snapshot.maybeClone(t,n,i);return o===r?null:r}flushMicroActions(){for(let t of this.scheduledMicroActions)try{t()}catch(n){console.error("Failed to execute scheduled micro action",n)}this.scheduledMicroActions=[]}processAction(t){let{action:n}=t;if(n===Fe.EVENTUALLY&&!this.onStoreIncrementEmitter.subscribers.length)return;let i;if("change"in t?i=this.applyChangeToSnapshot(t.change):i=this.maybeCloneSnapshot(n,t.elements,t.appState),!i)return;let o="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case Fe.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Fe.NEVER:case Fe.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:Tf(n,"Unknown store action")}}finally{switch(n){case Fe.IMMEDIATELY:case Fe.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Fe.IMMEDIATELY)?t=Fe.IMMEDIATELY:this.scheduledMacroActions.has(Fe.NEVER)?t=Fe.NEVER:t=Fe.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Fe).length)){let t=`There can be at most three store actions scheduled at the same time, but there are "${this.scheduledMacroActions.size}".`;if(console.error(t,this.scheduledMacroActions.values()),Df()||vf())throw new Error(t)}}},ci=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},wo=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Zr=class extends wo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},qr=class extends wo{constructor(n){super("ephemeral",n);this.change=n}},Kr=class{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:Lf()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?fn.calculate(t.elements,n.elements):fn.empty(),o=n.metadata.didAppStateChange?mn.calculate(t.appState,n.appState):mn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,fn.restore(i),mn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o}}){let r=fn.create(n,i,o);return new this(t,r,mn.empty())}static inverse(t){return this.create(t.elements.inverse(),t.appState.inverse())}static applyTo(t,n,i){let[o,r]=t.elements.applyTo(n),[s,a]=t.appState.applyTo(i,o);return[o,s,r||a]}static applyLatestChanges(t,n,i,o){return this.create(t.elements.applyLatestChanges(n,i,o),t.appState,{id:t.id})}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},hn=class e{constructor(t,n,i={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=i}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,i={didElementsChange:!1,didAppStateChange:!1}){return new e(t,tc(n)?n:Gn(n),i)}static empty(){return new e(new Map,Cf(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of Bn(t.elements))this.elements.get(i.id)||(n[i.id]=Me(i,{isDeleted:!0}));for(let i of Bn(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return ie.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=Gn({...this.appState,...t.appState});return e.create(n,i,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,i){let o={shouldCompareHashes:!1};t===Fe.EVENTUALLY&&(o.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,o),s=this.maybeCreateAppStateSnapshot(i,o),a=!1,l=!1;return this.elements!==r&&(a=!0),this.appState!==s&&(l=!0),!a&&!l?this:new e(r,s,{didElementsChange:a,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let i=tc(t)?t:Gn(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=ie.isRightDifferent(this.appState,t);if(!i)return;let o=rc(JSON.stringify(t));if(!(n.shouldCompareHashes&&this._lastChangedAppStateHash===o))return this._lastChangedAppStateHash=o,i}detectChangedElements(t,n={shouldCompareHashes:!1}){if(this.elements===t)return;let i=new Map;for(let r of Bn(this.elements))t.get(r.id)||i.set(r.id,Me(r,{isDeleted:!0}));for(let r of Bn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(xe(r)&&!zt(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=oc(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of Bn(this.elements))n.set(i.id,i);for(let i of Bn(t))n.set(i.id,$r(i));return n}},nc="__observedAppState",Cf=()=>({name:null,editingGroupId:null,viewBackgroundColor:Af.white,selectedElementIds:{},selectedGroupIds:{},editingLinearElementId:null,selectedLinearElementId:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),Gn=e=>{let t={name:e.name,editingGroupId:e.editingGroupId,viewBackgroundColor:e.viewBackgroundColor,selectedElementIds:e.selectedElementIds,selectedGroupIds:e.selectedGroupIds,croppingElementId:e.croppingElementId,activeLockedId:e.activeLockedId,lockedMultiSelections:e.lockedMultiSelections,editingLinearElementId:e.editingLinearElement?.elementId??e.editingLinearElementId??null,selectedLinearElementId:e.selectedLinearElement?.elementId??e.selectedLinearElementId??null};return Reflect.defineProperty(t,nc,{value:!0,enumerable:!1}),t},tc=e=>!!Reflect.get(e,nc);P();P();var lc="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function kn(e,t,n){let i=n[0];if(t!=null&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)===i||t&&t.slice(-1)===i)throw new Error("trailing zero");if(t){let s=0;for(;(e[s]||i)===t[s];)s++;if(s>0)return t.slice(0,s)+kn(e.slice(s),t.slice(s),n)}let o=e?n.indexOf(e[0]):0,r=t!=null?n.indexOf(t[0]):n.length;if(r-o>1){let s=Math.round(.5*(o+r));return n[s]}else return t&&t.length>1?t.slice(0,1):n[o]+kn(e.slice(1),null,n)}function cc(e){if(e.length!==dc(e[0]))throw new Error("invalid integer part of order key: "+e)}function dc(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("invalid order key head: "+e)}function di(e){let t=dc(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function sc(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=di(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function ac(e,t){cc(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])+1;s===t.length?i[r]=t[0]:(i[r]=t[s],o=!1)}if(o){if(n==="Z")return"a"+t[0];if(n==="z")return null;let r=String.fromCharCode(n.charCodeAt(0)+1);return r>"a"?i.push(t[0]):i.pop(),r+i.join("")}else return n+i.join("")}function Bf(e,t){cc(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])-1;s===-1?i[r]=t.slice(-1):(i[r]=t[s],o=!1)}if(o){if(n==="a")return"Z"+t.slice(-1);if(n==="A")return null;let r=String.fromCharCode(n.charCodeAt(0)-1);return r<"Z"?i.push(t.slice(-1)):i.pop(),r+i.join("")}else return n+i.join("")}function On(e,t,n=lc){if(e!=null&&sc(e,n),t!=null&&sc(t,n),e!=null&&t!=null&&e>=t)throw new Error(e+" >= "+t);if(e==null){if(t==null)return"a"+n[0];let l=di(t),c=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+kn("",c,n);if(l<t)return l;let d=Bf(l,n);if(d==null)throw new Error("cannot decrement any more");return d}if(t==null){let l=di(e),c=e.slice(l.length),d=ac(l,n);return d??l+kn(c,null,n)}let i=di(e),o=e.slice(i.length),r=di(t),s=t.slice(r.length);if(i===r)return i+kn(o,s,n);let a=ac(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+kn(o,null,n)}function yo(e,t,n,i=lc){if(n===0)return[];if(n===1)return[On(e,t,i)];if(t==null){let s=On(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=On(s,t,i),a.push(s);return a}if(e==null){let s=On(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=On(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=On(e,t,i);return[...yo(e,r,o,i),r,...yo(r,t,n-o-1,i)]}import{arrayToMap as bo}from"@excalidraw/common";var Qr=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Gf=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=l=>`${l?.index}:${l?.id}:${l?.type}:${l?.isDeleted}:${l?.version}:${l?.versionNonce}`,a=e.map(l=>l.index);for(let[l,c]of a.entries()){let d=a[l-1],u=a[l+1];if(Jr(c,d,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&st(e[l])){let p=e[l],m=Z(p,bo(e));m&&m.index<=p.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(m)}", "${s(p)}"`)}}if(r.length){let l=new Qr,c=[];if(o&&(c.push("Additional reconciliation context:"),c.push(o.localElements.map(d=>s(d))),c.push(o.remoteElements.map(d=>s(d)))),i||console.error(r.join(`
12
+ `),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=Eo(e.fontSize,e.lineHeight),d=Lf(e.fontFamily,e.fontSize,l);for(let c=0;c<s.length;c++)n.fillText(s[c],a,c*l+d);n.restore(),r&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},Gi=new WeakMap,wd=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=Gi.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=V(e,t),l=a?.version||null,d=be(e)?e.crop:null,c=Yt(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.boundTextElementVersion!==l||r.imageCrop!==d||r.containingFrameOpacity!==c||H(e)&&a&&e.angle!==r.angle){let u=bd(e,t,o,n,i);return u?(Gi.set(e,u),u):null}return r},xs=(e,t,n,i,o)=>{let r=e.element,s=jo(r),a=e.scale,[l,d,c,u]=$(r,o),m=((l+c)/2+i.scrollX)*window.devicePixelRatio,p=((d+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=V(r,o);if(H(r)&&f){let h=(e.boundTextCanvas.width-e.canvas.width)/2,E=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(m,p),t.drawImage(e.boundTextCanvas,-(c-l)/2*window.devicePixelRatio-h/a-s,-(u-d)/2*window.devicePixelRatio-E/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(m,p),t.rotate(r.angle),"scale"in e.element&&!Of(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-m,-p),t.drawImage(e.canvas,(l+i.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(d+i.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),v.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&wt(r)){let h=V(r,o),E=Rr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((E.x+i.scrollX)*window.devicePixelRatio,(E.y+i.scrollY)*window.devicePixelRatio,ct(r,h)*window.devicePixelRatio,Pi(r,h)*window.devicePixelRatio)}t.restore()},e1=(e,t,n,i)=>{t.save(),t.translate(e.x+n.scrollX,e.y+n.scrollY),t.fillStyle="rgba(0, 0, 200, 0.04)";let o=.5/n.zoom.value;t.fillRect(o,o,e.width,e.height),t.lineWidth=1/n.zoom.value,t.strokeStyle=i,t.strokeRect(o,o,e.width,e.height),t.restore()},t1=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=kf(e,Yt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Mf:1),e.type){case"magicframe":case"frame":{s.frameRendering.enabled&&s.frameRendering.outline&&(o.save(),o.translate(e.x+s.scrollX,e.y+s.scrollY),o.fillStyle="rgba(0, 0, 200, 0.04)",o.lineWidth=Ci.strokeWidth/s.zoom.value,o.strokeStyle=s.theme===Kn.DARK?Wo(Ci.strokeColor):Ci.strokeColor,za(e)&&(o.strokeStyle=s.theme===Kn.LIGHT?"#7affd7":Wo("#1d8264")),Ci.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Ci.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(r.isExporting){let[l,d,c,u]=$(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),h=(u-d)/2-(e.y-d);o.save(),o.translate(m,p),o.rotate(e.angle),o.translate(-f,-h),Uo(e,i,o,r),o.restore()}else{let l=wd(e,n,r,s);if(!l)return;xs(l,o,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=$(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),h=(u-d)/2-(e.y-d);if(q(e)){let g=Me(e,t);if(H(g)){let x=G.getBoundTextElementPosition(g,e,t);f=(c-l)/2-(x.x-l),h=(u-d)/2-(x.y-d)}}o.save(),o.translate(m,p);let E=V(e,t);if(H(e)&&E){let g=document.createElement("canvas"),x=g.getContext("2d"),w=Math.max(wn(l,c),wn(d,u)),b=jo(e);g.width=w*s.exportScale+b*10*s.exportScale,g.height=w*s.exportScale+b*10*s.exportScale,x.translate(g.width/2,g.height/2),x.scale(s.exportScale,s.exportScale),f=e.width/2-(e.x-l),h=e.height/2-(e.y-d),x.rotate(e.angle);let y=Dn.canvas(g);x.translate(-f,-h),Uo(e,y,x,r),x.translate(f,h),x.rotate(-e.angle);let[,,,,I,M]=$(E,t),T=(l+c)/2-I,S=(d+u)/2-M;x.translate(-T,-S),x.clearRect(-E.width/2,-E.height/2,E.width,E.height),o.scale(1/s.exportScale,1/s.exportScale),o.drawImage(g,-g.width/2,-g.height/2,g.width,g.height)}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-f,-h),Uo(e,i,o,r);o.restore()}else{let l=wd(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Af(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&be(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=bd(Fa(l.element,t),n,s.zoom,r,s);c&&xs(c,o,r,s,n),o.restore()}xs(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function n1(e,t,n){let i=se({...e,angle:0},n),o=Ho((i[0]+i[2])/2,(i[1]+i[3])/2);return Cf(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(xd(r[r.length-1][1],gs(Ho(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[xd(gs(Ho(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),gs(Ho(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}P();var r1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",s1=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable",a1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",l1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Id=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",d1=e=>e==="arrow",c1=e=>e==="arrow";var Ke=class e{static rg=new et;static cache=new WeakMap;static get=(t,n)=>{let i=e.cache.get(t);if(i&&(n===null||i.theme===n))return i.shape};static delete=t=>{e.cache.delete(t),Gi.delete(t)};static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let i=n?.isExporting?void 0:e.get(t,n?n.theme:null);if(i!==void 0)return i;Gi.delete(t);let o=jf(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:Hf.white,embedsValidationStatus:null,theme:ys.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||ys.LIGHT}),o}},Uf=e=>[8,8+e],vd=e=>[1.5,6+e];function Wf(e){let t=e.roughness,n=Math.max(e.width,e.height),i=Math.min(e.width,e.height);return i>=20&&n>=50||i>=15&&e.roundness&&Id(e.type)||K(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var We=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?Uf(e.strokeWidth):e.strokeStyle==="dotted"?vd(e.strokeWidth):void 0,disableMultiStroke:e.strokeStyle!=="solid",strokeWidth:e.strokeStyle!=="solid"?e.strokeWidth+.5:e.strokeWidth,fillWeight:e.strokeWidth/2,hachureGap:e.strokeWidth*4,roughness:Wf(e),stroke:n?Fi(e.strokeColor):e.strokeColor,preserveVertices:t||e.roughness<Nf.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=ki(e.backgroundColor)?void 0:n?Fi(e.backgroundColor):e.backgroundColor,e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return Cn(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:n?Fi(e.backgroundColor):e.backgroundColor),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},Ad=(e,t,n)=>co(e)&&(t||Na(e)&&n?.get(e.id)!==!0)&&ki(e.backgroundColor)&&ki(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:lo(e)?{...e,strokeColor:ki(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:ki(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Oi=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},Yo=(e,t,n)=>{if(t===null)return[];let[i,o,r,s,a,l]=t;return[e.line(r,s,i,o,n),e.line(a,l,i,o,n)]},Nn=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=vd(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},bs=(e,t,n,i,o,r=1)=>{if(i===null)return[];let[s,a,l]=i,d={...t,fill:o,fillStyle:"solid",stroke:n,roughness:Math.min(.5,t.roughness||0)};return delete d.strokeLineDash,[e.circle(s,a,l*r,d)]},Md=(e,t,n,i,o,r,s,a)=>{if(i===null)return[];let l=a?Fi(e.strokeColor):e.strokeColor,d=a?Fi(s):s,c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return bs(o,r,l,ke(e,t,n,i),i==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let m=ke(e,t,n,i);if(m===null)return[];let[p,f,h,E,g,x]=m,w={...r,fill:i==="triangle_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete w.strokeLineDash,[o.polygon([[p,f],[h,E],[g,x],[p,f]],w)]}case"diamond":case"diamond_outline":{let m=ke(e,t,n,i);if(m===null)return[];let[p,f,h,E,g,x,w,b]=m,y={...r,fill:i==="diamond_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete y.strokeLineDash,[o.polygon([[p,f],[h,E],[g,x],[w,b],[p,f]],y)]}case"cardinality_one":return Oi(o,ke(e,t,n,i),Nn(e,r));case"cardinality_many":return Yo(o,ke(e,t,n,i),Nn(e,r));case"cardinality_one_or_many":{let m=Nn(e,r);return[...Yo(o,ke(e,t,n,"cardinality_many"),m),...Oi(o,ke(e,t,n,"cardinality_one",c),m)]}case"cardinality_exactly_one":{let m=Nn(e,r);return[...Oi(o,ke(e,t,n,"cardinality_one",-.5),m),...Oi(o,ke(e,t,n,"cardinality_one"),m)]}case"cardinality_zero_or_one":{let m=Nn(e,r);return[...bs(o,r,l,ke(e,t,n,"circle_outline",1.5),d,u),...Oi(o,ke(e,t,n,"cardinality_one",-.5),m)]}case"cardinality_zero_or_many":{let m=Nn(e,r);return[...Yo(o,ke(e,t,n,"cardinality_many"),m),...bs(o,r,l,ke(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return Yo(o,ke(e,t,n,i),Nn(e,r))}},qa=(e,t)=>{let n=new et,i={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=ne(e,t);switch(e.type){case"line":case"arrow":{let r=e.points.length?e.points:[de(0,0)];return U(e)?n.path(Dd(r,16),i).sets[0].ops:e.roundness?n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=Xt(de(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:de(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Xt(de(e.x+s.data[0],e.y+s.data[1]),o,e.angle),Xt(de(e.x+s.data[2],e.y+s.data[3]),o,e.angle),Xt(de(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>de(l[0]-e.x,l[1]-e.y)).flat()}}):r.map((s,a)=>{let l=Xt(de(e.x+s[0],e.y+s[1]),o,e.angle);return{op:a===0?"move":"lineTo",data:de(l[0]-e.x,l[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let r=ui(e.points,.75);return n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=Xt(de(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:de(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Xt(de(e.x+s.data[0],e.y+s.data[1]),o,e.angle),Xt(de(e.x+s.data[2],e.y+s.data[3]),o,e.angle),Xt(de(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>de(l[0]-e.x,l[1]-e.y)).flat()}})}}},jf=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===ys.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=Ft(Math.min(l,d),e);a=t.path(`M ${c} 0 L ${l-c} 0 Q ${l} 0, ${l} ${c} L ${l} ${d-c} Q ${l} ${d}, ${l-c} ${d} L ${c} ${d} Q 0 ${d}, 0 ${d-c} L 0 ${c} Q 0 0, ${c} 0`,We(Ad(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,We(Ad(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,f,h]=jn(e);if(e.roundness){let E=Ft(Math.abs(l-f),e),g=Ft(Math.abs(u-d),e);a=t.path(`M ${l+E} ${d+g} L ${c-E} ${u-g}
13
+ C ${c} ${u}, ${c} ${u}, ${c-E} ${u+g}
14
+ L ${m+E} ${p-g}
15
+ C ${m} ${p}, ${m} ${p}, ${m-E} ${p-g}
16
+ L ${f+E} ${h+g}
17
+ C ${f} ${h}, ${f} ${h}, ${f+E} ${h-g}
18
+ L ${l-E} ${d+g}
19
+ C ${l} ${d}, ${l} ${d}, ${l+E} ${d+g}`,We(e,!0,s))}else a=t.polygon([[l,d],[c,u],[m,p],[f,h]],We(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,We(e,!1,s));case"line":case"arrow":{let a,l=We(e,!1,s),d=e.points.length?e.points:[de(0,0)];if(U(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(Dd(d,16),We(e,!0,s))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(d)),a=[]):e.roundness?a=[t.curve(d,l)]:l.fill?a=[t.polygon(d,l)]:a=[t.linearPath(d,l)],e.type==="arrow"){let{startArrowhead:c=null,endArrowhead:u="arrow"}=e;if(c!==null){let m=Md(e,a,"start",c,t,l,i,s);a.push(...m)}if(u!==null){let m=Md(e,a,"end",u,t,l,i,s);a.push(...m)}}return a}case"freedraw":{let a=[];if(Cn(e.points)){let l=ui(e.points,.75);a.push(t.curve(l,{...We(e,!1,s),stroke:"none"}))}return a.push(Yf(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return zf(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Dd=(e,t)=>{let n=[];for(let o=1;o<e.length-1;o+=1){let r=e[o-1],s=e[o+1],a=e[o],l=mt(a,r),d=mt(s,a),c=Math.min(t,Sd(e[o],s)/2,Sd(e[o],r)/2);l?r[0]<a[0]?n.push([e[o][0]-c,e[o][1]]):n.push([e[o][0]+c,e[o][1]]):r[1]<a[1]?n.push([e[o][0],e[o][1]-c]):n.push([e[o][0],e[o][1]+c]),n.push(e[o]),d?s[0]<a[0]?n.push([e[o][0]-c,e[o][1]]):n.push([e[o][0]+c,e[o][1]]):s[1]<a[1]?n.push([e[o][0],e[o][1]-c]):n.push([e[o][0],e[o][1]+c])}let i=[`M ${e[0][0]} ${e[0][1]}`];for(let o=0;o<n.length;o+=3)i.push(`L ${n[o][0]} ${n[o][1]}`),i.push(`Q ${n[o+1][0]} ${n[o+1][1]}, ${n[o+2][0]} ${n[o+2][1]}`);return i.push(`L ${e[e.length-1][0]} ${e[e.length-1][1]}`),i.join(" ")},Bd=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return ba(e);case"arrow":case"line":{let n=Ke.generateElementShape(e,null)[0],[,,,,i,o]=$(e,t);return bo(e)?Sa(e,n,de(e.x,e.y),e.angle,de(i,o)):Pa(n,de(e.x,e.y),e.angle,de(i,o))}case"ellipse":return ya(e);case"freedraw":{let[,,,,n,i]=$(e,t);return Ia(e,de(n,i),bo(e))}}},Ql=(e,t)=>{let n=[...e.points];if(t){if(!Wa(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>_f||n.length<4?n.push(de(o[0],o[1])):n[n.length-1]=de(o[0],o[1])}return{polygon:t,points:n}},Yf=e=>Vf(Xf(e)),Xf=e=>{let t=e.simulatePressure?e.points:e.points.length?e.points.map(([n,i],o)=>[n,i,e.pressures[o]]):[[0,0,.5]];return La(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:n=>Math.sin(n*Math.PI/2),last:!0})},Td=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],$f=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,Vf=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Td(i,r[0]),"L",r[0],"Z"):n.push(i,Td(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace($f,"$1")};var Ss=class e{static boundsCache=new WeakMap;static nonRotatedBoundsCache=new WeakMap;static getBounds(t,n,i=!1){let o=i&&t.angle!==0?e.nonRotatedBoundsCache.get(t):e.boundsCache.get(t);if(o?.version&&o.version===t.version&&!ue(t))return o.bounds;if(i&&t.angle!==0){let s=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:s}),s}let r=e.calculateBounds(t,n);return e.boundsCache.set(t,{version:t.version,bounds:r}),r}static calculateBounds(t,n){let i,[o,r,s,a,l,d]=$(t,n);if(Ee(t)){let[c,u,m,p]=As(t.points.map(([f,h])=>re(D(f,h),D(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,m+t.x,p+t.y]}else if(K(t))i=rh(t,l,d,n);else if(t.type==="diamond"){let[c,u]=re(D(l,r),D(l,d),t.angle),[m,p]=re(D(l,a),D(l,d),t.angle),[f,h]=re(D(o,d),D(l,d),t.angle),[E,g]=re(D(s,d),D(l,d),t.angle),x=Math.min(c,m,f,E),w=Math.min(u,p,h,g),b=Math.max(c,m,f,E),y=Math.max(u,p,h,g);i=[x,w,b,y]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,m=Math.cos(t.angle),p=Math.sin(t.angle),f=Math.hypot(c*m,u*p),h=Math.hypot(u*m,c*p);i=[l-f,d-h,l+f,d+h]}else{let[c,u]=re(D(o,r),D(l,d),t.angle),[m,p]=re(D(o,a),D(l,d),t.angle),[f,h]=re(D(s,a),D(l,d),t.angle),[E,g]=re(D(s,r),D(l,d),t.angle),x=Math.min(c,m,f,E),w=Math.min(u,p,h,g),b=Math.max(c,m,f,E),y=Math.max(u,p,h,g);i=[x,w,b,y]}return i}},$=(e,t,n=!1)=>{if(Ee(e))return Jf(e);if(K(e))return G.getElementAbsoluteCoords(e,t,n);if(q(e)){let i=t?Me(e,t):null;if(H(i)){let{x:o,y:r}=G.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},hs=(e,t)=>{let n=Bd(e,t),[i,o,r,s,a,l]=$(e,t),d=D(a,l);if(n.type==="polycurve"){let g=n.data.map(w=>Lt(w,10)),x=[];if(Ot(e)&&!e.polygon||H(e))for(let w of g){let b=0;for(;b<w.length-1;)x.push(xe(D(w[b][0],w[b][1]),D(w[b+1][0],w[b+1][1]))),b++}else{let w=g.flat(),b=0;for(;b<w.length-1;)x.push(xe(D(w[b][0],w[b][1]),D(w[b+1][0],w[b+1][1]))),b++}return x}else{if(n.type==="polyline")return n.data;if(Kf(e)){let[E,g]=nn(e),x=g.map(b=>Gd(b,d,e.angle)).flat();return[...Cd(E,d,e.angle),...x]}else if(e.type==="diamond"){let[E,g]=on(e),x=g.map(b=>Gd(b,d,e.angle)).flat();return[...Cd(E,d,e.angle),...x]}else if(n.type==="polygon"){if(q(e)){let x=Me(e,t);if(x&&K(x))return[xe(D(i,o),D(r,o)),xe(D(r,o),D(r,s)),xe(D(r,s),D(i,s)),xe(D(i,s),D(i,o))]}let E=n.data,g=[];for(let x=0;x<E.length-1;x++)g.push(xe(E[x],E[x+1]));return g}else if(n.type==="ellipse")return Qf(e)}let[c,u,m,p,,,f,h]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(E=>re(E,d,e.angle));return[xe(c,u),xe(m,p),xe(c,m),xe(u,p),xe(c,h),xe(m,h),xe(u,f),xe(p,f)]},Kf=e=>e!=null&&(e.type==="rectangle"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),Cd=(e,t,n)=>e.map(i=>xe(re(i[0],t,n),re(i[1],t,n))),Gd=(e,t,n)=>{let i=Lt(e,10),o=0,r=[];for(;o<i.length-1;)r.push(xe(re(D(i[o][0],i[o][1]),t,n),re(D(i[o+1][0],i[o+1][1]),t,n))),o++;return r},Qf=e=>{let t=D(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(re(D(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(xe(r[l],r[l+1]));return o.push(xe(r[r.length-1],r[0])),o},H1=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],jn=e=>{let t=Math.floor(e.width/2)+1,n=0,i=e.width,o=Math.floor(e.height/2)+1,r=t,s=e.height;return[t,n,i,o,r,s,0,o]},Od=(e,t,n,i,o)=>{let r=1-e;return Math.pow(r,3)*t+3*Math.pow(r,2)*e*n+3*r*Math.pow(e,2)*i+Math.pow(e,3)*o},kd=(e,t,n,i)=>{let o=t-e,r=n-t,s=i-n,a=3*o-6*r+3*s,l=6*r-6*o,d=3*o,c=l*l-4*a*d;if(!(c>=0))return!1;let m=null,p=null,f=1/0,h=1/0;return a===0?f=h=-d/l:(f=(-l+Math.sqrt(c))/(2*a),h=(-l-Math.sqrt(c))/(2*a)),f>=0&&f<=1&&(m=Od(f,e,t,n,i)),h>=0&&h<=1&&(p=Od(h,e,t,n,i)),[m,p]},Po=(e,t,n,i)=>{let o=kd(e[0],t[0],n[0],i[0]),r=kd(e[1],t[1],n[1],i[1]),s=Math.min(e[0],i[0]),a=Math.max(e[0],i[0]);if(o){let c=o.filter(u=>u!==null);s=Math.min(s,...c),a=Math.max(a,...c)}let l=Math.min(e[1],i[1]),d=Math.max(e[1],i[1]);if(r){let c=r.filter(u=>u!==null);l=Math.min(l,...c),d=Math.max(d,...c)}return[s,l,a,d]},Li=(e,t)=>{let n=D(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=Rd(d);Is(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=D(d[0],d[1]),u=D(d[2],d[3]),m=D(d[4],d[5]),p=t?t(c):c,f=t?t(u):u,h=t?t(m):m,E=t?t(n):n;n=m;let[g,x,w,b]=Po(E,p,f,h);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,w),a.maxY=Math.max(a.maxY,b)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},As=(e,t=0)=>{let n=1/0,i=1/0,o=-1/0,r=-1/0;for(let[s,a]of e)n=Math.min(n,s),i=Math.min(i,a),o=Math.max(o,s),r=Math.max(r,a);return[n-t,i-t,o+t,r+t]},Jf=e=>{let[t,n,i,o]=As(e.points),r=t+e.x,s=n+e.y,a=i+e.x,l=o+e.y;return[r,s,a,l,(r+a)/2,(s+l)/2]},eh=20,th=15,nh=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"cardinality_many":case"cardinality_one_or_many":case"cardinality_zero_or_many":return th;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return eh;default:return 15}},ih=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},ke=(e,t,n,i,o=0)=>{if(i===null||t.length<1)return null;let r=Ct(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;Is(a.length===6,"Op data length is not 6");let l=D(a[4],a[5]),d=D(a[2],a[3]),c=D(a[0],a[1]),u=r[s-1],m=D(0,0);if(u.op==="move"){let A=Rd(u.data);Is(A!=null,"Op data is not a point"),m=A}else u.op==="bcurveTo"&&(m=D(u.data[4],u.data[5]));let p=(A,z)=>Math.pow(1-A,3)*l[z]+3*A*Math.pow(1-A,2)*d[z]+3*Math.pow(A,2)*(1-A)*c[z]+m[z]*Math.pow(A,3),[f,h]=n==="start"?m:l,[E,g]=[p(.3,0),p(.3,1)],x=Math.hypot(f-E,h-g),w=(f-E)/x,b=(h-g)/x,y=nh(i),I=0;{let[A,z]=n==="end"?e.points[e.points.length-1]:e.points[0],[W,we]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];I=Math.hypot(A-W,z-we)}let T=Math.min(y,I*(i==="diamond"||i==="diamond_outline"?.25:.5)),S=f-w*T*o,B=h-b*T*o,L=S-w*T,k=B-b*T;if(i==="circle"||i==="circle_outline"){let A=Math.hypot(k-B,L-S)+e.strokeWidth-2;return[S,B,A]}let C=ih(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[A,z]=re(D(S,B),D(L,k),Ps(-C)),[W,we]=re(D(S,B),D(L,k),Ps(C));return[L,k,A,z,W,we]}let[X,_]=re(D(L,k),D(S,B),-C*Math.PI/180),[oe,F]=re(D(L,k),D(S,B),Ps(C));if(i==="diamond"||i==="diamond_outline"){let A,z;if(n==="start"){let[W,we]=e.points.length>1?e.points[1]:[0,0];[A,z]=re(D(S+T*2,B),D(S,B),Math.atan2(we-B,W-S))}else{let[W,we]=e.points.length>1?e.points[e.points.length-2]:[0,0];[A,z]=re(D(S-T*2,B),D(S,B),Math.atan2(B-we,S-W))}return[S,B,X,_,A,z,oe,F]}return[S,B,X,_,oe,F]},oh=e=>{let t=Dn.generator(),n=We(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},rh=(e,t,n,i)=>{let o=V(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,f]=re(D(e.x+u,e.y+m),D(t,n),e.angle),h=[p,f,p,f];if(o){let E=G.getMinMaxXYWithBoundText(e,i,[p,f,p,f],o);h=[E[0],E[1],E[2],E[3]]}return h}let s=Ke.get(e,null)?.[0]??oh(e),a=Ct(s),d=Li(a,([u,m])=>re(D(e.x+u,e.y+m),D(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=G.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},se=(e,t,n=!1)=>Ss.getBounds(e,t,n),Oe=(e,t)=>{if(!Zf(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Fd(e);return e.forEach(a=>{let[l,d,c,u]=se(a,s);n=Math.min(n,l),o=Math.min(o,d),i=Math.max(i,c),r=Math.max(r,u)}),[n,o,i,r]},_1=(e,t)=>{let[n,i,o,r]=Oe(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},tn=(e,t,n,i)=>{if(!(K(e)||Ee(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Ld(0,t,Ld(1,n,e.points,i),i),r;if(Ee(e))r=As(o);else{let c=Dn.generator(),u=e.roundness?c.curve(o,We(e)):c.linearPath(o,We(e)),m=Ct(u);r=Li(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},ds=(e,t)=>{let n=Dn.generator(),i=e.roundness==null?n.linearPath(t,We(e)):n.curve(t,We(e)),o=Ct(i),[r,s,a,l]=Li(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},U1=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=Fd(e);return e.forEach(r=>{let[s,a,l,d]=se(r,o),c=qf(D((s+l)/2,(a+d)/2),D(t.x,t.y));c<n&&(n=c,i=r)}),se(i,o)},$t=e=>{let[t,n,i,o]=Oe(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},W1=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],ln=e=>D(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),it=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=ne(e,t),[r,s]=re(D(i.minX,i.minY),o,e.angle),[a,l]=re(D(i.maxX,i.minY),o,e.angle),[d,c]=re(D(i.maxX,i.maxY),o,e.angle),[u,m]=re(D(i.minX,i.maxY),o,e.angle),p=[Math.min(r,a,d,u),Math.min(s,l,c,m),Math.max(r,a,d,u),Math.max(s,l,c,m)];if(n){let[f,h,E,g]=n;return[p[0]-g,p[1]-f,p[2]+h,p[3]+E]}return p},ut=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],sh=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],It=(e,t)=>{if(e==null||t==null)return!1;let[n,i,o,r]=e,[s,a,l,d]=t;return n<l&&o>s&&i<d&&r>a},md=(e,t)=>[D(t[0],t[1]),D(t[0],t[3]),D(t[2],t[1]),D(t[2],t[3])].every(n=>sh(n,e)),ne=(e,t,n=0,i=0)=>{if(K(e)||Ee(e)){let[s,a,l,d]=$(e,t),[c,u]=D((s+l)/2,(a+d)/2);return D(c+n,u+i)}let[o,r]=ln(se(e,t));return D(o+n,r+i)};var ch=.1,zd=e=>K(e)||Ee(e)?e.points.length<2||e.points.length===2&&H(e)&&dh(e.points[0],e.points[e.points.length-1],ch):e.width===0&&e.height===0,pd=(e,t,n,i,o)=>{let[r,s,a,l]=se(e,o),d=Xo({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=Xo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},K1=(e,t,n,i,o,r)=>{let[s,a,l,d]=Oe(e,o),c=Xo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=Xo({clientX:i.offsetLeft+t-(r?.right||0),clientY:i.offsetTop+n-(r?.bottom||0)},i);return s>=c.x&&a>=c.y&&l<=u.x&&d<=u.y},Ms=(e,t,n)=>{let i=Math.abs(t),o=Math.abs(n);if(e==="line"||e==="arrow"||e==="freedraw"){let r=Math.round(Math.atan(o/i)/Vt)*Vt;r===0?n=0:r===Math.PI/2?t=0:n=i*Math.tan(r)*Math.sign(n)||n}else e!=="selection"&&(n=i*Math.sign(n));return{width:t,height:n}},Jl=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Vt)*Vt;if(o){let d=Math.floor(o/Vt)*Vt;ah(a,d,d+Vt)&&(lh(a,o)<Vt/6?l=o:Nd(a)>Nd(o)?l=d+Vt:l=d)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,m=-1/d,p=-1,f=i-m*n,h=(c*f-p*u)/(d*p-m*c),E=(u*m-f*d)/(d*p-m*c);r=h-e,s=E-t}return{width:r,height:s}},Q1=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t};P();var oP=(e,t,n,i)=>{let o=Ro(e,n.getNonDeletedElementsMap(),i),r=$t(e);return o.flatMap(s=>{let a=uh(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return De(l,n,{simultaneouslyUpdated:s}),d})})},uh=(e,t,{axis:n,position:i})=>{let o=$t(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};P();import{arrayToMap as rE,arrayToObject as Zt,assertNever as Ec,isDevEnv as In,isShallowEqual as gc,isTestEnv as Sn,randomInteger as hc}from"@excalidraw/common";P();import{assertNever as Ph,COLOR_PALETTE as Ih,isDevEnv as Sh,isTestEnv as Ah,randomId as Mh,Emitter as Ud,toIterable as Qn}from"@excalidraw/common";P();import{ORIG_ID as hh,randomId as _d,randomInteger as Eh,arrayToMap as gh,castArray as Ts,findLastIndex as Ri,getUpdatedTimestamp as xh,isTestEnv as wh}from"@excalidraw/common";P();import{arrayToMapWithIndex as mh}from"@excalidraw/common";var ph=e=>{let t=e.slice(),n=new Set,i=r=>{let s=r[0]?.groupIds?.join(""),a=[r[0]],l=[];for(let d of r.slice(1))d.groupIds?.join("")===s?a.push(d):l.push(d);return l.length?[...a,...i(l)]:a},o=new Map;return t.forEach((r,s)=>{if(!o.has(r.id))if(r.groupIds?.length){let a=r.groupIds[r.groupIds.length-1],l=t.slice(s).filter(d=>{let c=d?.groupIds?.some(u=>u===a);return c&&o.set(d.id,!0),c});for(let d of i(l))n.add(d)}else n.add(r)}),n.size!==e.length?(console.error("normalizeGroupElementOrder: lost some elements... bailing!"),e):[...n]},fh=e=>{let t=mh(e),n=e.slice(),i=new Set;return n.forEach((o,r)=>{o&&(o.boundElements?.length?(i.add(o),n[r]=null,o.boundElements.forEach(s=>{let a=t.get(s.id);a&&s.type==="text"&&(i.add(a[0]),n[a[1]]=null)})):o.type==="text"&&o.containerId&&t.get(o.containerId)?.[0].boundElements?.find(a=>a.id===o.id)||(i.add(o),n[r]=null))}),i.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...i]},Hd=e=>fh(ph(e));var bh=(e,t,n,i)=>{let o=Ds(n);return wh()&&yh(o,n.id),o.id=_d(),o.updated=xh(),i&&(o.seed=Eh(),Ll(o)),o.groupIds=cd(o.groupIds,e,r=>(t.has(r)||t.set(r,_d()),t.get(r))),o},xP=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},i=new Map,o=new Map,r=[],s=[],a=new Map,l=new Map,d=new Map,c=gh(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(E=>[E.id,E]));if(e.type==="in-place")for(let E of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(E)).forEach(g=>u.set(g.id,g));t=Hd(t);let m=t.slice(),p=E=>{let x=Ts(E).reduce((w,b)=>{if(i.has(b.id))return w;i.set(b.id,!0);let y=bh(n.editingGroupId,o,b,e.randomizeSeed);return i.set(y.id,!0),d.set(y.id,y),a.set(b.id,y.id),l.set(y.id,b),s.push(b),r.push(y),w.push(y),w},[]);return Array.isArray(E)?x:x[0]||null},f=(E,g)=>{if(g){if(E>m.length-1){m.push(...Ts(g));return}m.splice(E+1,0,...Ts(g))}},h=new Set(t.filter(E=>u.has(E.id)&&Z(E)).map(E=>E.id));for(let E of t){if(i.has(E.id)||!u.has(E.id))continue;let g=ms(n,E);if(g){let x=Ge(t,g).flatMap(b=>Z(b)?[...gn(t,b.id),b]:[b]),w=Ri(m,b=>b.groupIds?.includes(g));f(w,p(x));continue}if(!(E.frameId&&h.has(E.frameId))){if(Z(E)){let x=E.id,w=gn(t,x),b=Ri(m,y=>y.frameId===x||y.id===x);f(b,p([...w,E]));continue}if(wt(E)){let x=V(E,c),w=Ri(m,b=>b.id===E.id||"containerId"in b&&b.containerId===E.id);x?f(w,p([E,x])):f(w,p(E));continue}if(ue(E)){let x=Me(E,c),w=Ri(m,b=>b.id===E.id||b.id===x?.id);x?f(w,p([x,E])):f(w,p(E));continue}f(Ri(m,x=>x.id===E.id),p(E))}}if(Hl(r,a,d),fd(m,s,a),e.overrides)for(let E of r){let g=l.get(E.id);g&&Object.assign(E,e.overrides({duplicateElement:E,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:m,origIdToDuplicateId:a}},vs=(e,t=0)=>{if(e==null||typeof e!="object")return e;let n=Object.prototype.toString.call(e);if(n==="[object Object]"){let i=typeof e.constructor=="function"?Object.create(Object.getPrototypeOf(e)):{};for(let o in e)if(e.hasOwnProperty(o)){if(t===0&&(o==="shape"||o==="canvas"))continue;i[o]=vs(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=vs(e[i],t+1);return o}return v.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},Ds=e=>vs(e),yh=(e,t)=>{Object.defineProperty(e,hh,{value:t,writable:!1,enumerable:!1})};var je={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},Wd=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Ud;onStoreIncrementEmitter=new Ud;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Pn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(je.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=Pn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?Xd(t.elements):void 0,t.appState);i=Ni.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=Pn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=Ni.create(o,t),i?s=i:s=Cs.calculate(o,t),!s.isEmpty()){let a=new Bs(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=Ni.create(r,t)}let o=new Ls(i);this.onStoreIncrementEmitter.trigger(o)}applyChangeToSnapshot(t){let n=this.snapshot,i=this.snapshot.applyChange(t);return n===i?null:i}maybeCloneSnapshot(t,n,i){if(!n&&!i)return null;let o=this.snapshot,r=this.snapshot.maybeClone(t,n,i);return o===r?null:r}flushMicroActions(){for(let t of this.scheduledMicroActions)try{t()}catch(n){console.error("Failed to execute scheduled micro action",n)}this.scheduledMicroActions=[]}processAction(t){let{action:n}=t;if(n===je.EVENTUALLY&&!this.onStoreIncrementEmitter.subscribers.length)return;let i;if("change"in t?i=this.applyChangeToSnapshot(t.change):i=this.maybeCloneSnapshot(n,t.elements,t.appState),!i)return;let o="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case je.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case je.NEVER:case je.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:Ph(n,"Unknown store action")}}finally{switch(n){case je.IMMEDIATELY:case je.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(je.IMMEDIATELY)?t=je.IMMEDIATELY:this.scheduledMacroActions.has(je.NEVER)?t=je.NEVER:t=je.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(je).length)){let t=`There can be at most three store actions scheduled at the same time, but there are "${this.scheduledMacroActions.size}".`;if(console.error(t,this.scheduledMacroActions.values()),Ah()||Sh())throw new Error(t)}}},Ni=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},$o=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Bs=class extends $o{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},Ls=class extends $o{constructor(n){super("ephemeral",n);this.change=n}},Cs=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:Mh()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?yn.calculate(t.elements,n.elements):yn.empty(),o=n.metadata.didAppStateChange?bn.calculate(t.appState,n.appState):bn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,yn.restore(i),bn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=yn.create(n,i,o),a=bn.create(r);return new this(t,s,a)}static squash(...t){let n=e.empty();for(let i of t)n.elements.squash(i.elements),n.appState.squash(i.appState);return n}static inverse(t){return this.create(t.elements.inverse(),t.appState.inverse())}static applyTo(t,n,i,o){let[r,s]=t.elements.applyTo(n,Pn.empty().elements,o),[a,l]=t.appState.applyTo(i,r);return[r,a,s||l]}static applyLatestChanges(t,n,i,o){return this.create(t.elements.applyLatestChanges(n,i,o),t.appState,{id:t.id})}static empty(){return e.create(yn.empty(),bn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Pn=class e{constructor(t,n,i={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=i}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,i={didElementsChange:!1,didAppStateChange:!1}){return new e(t,jd(n)?n:Jn(n),i)}static empty(){return new e(new Map,Th(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of Qn(t.elements))this.elements.get(i.id)||(n[i.id]=Le(i,{isDeleted:!0}));for(let i of Qn(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return j.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=Jn({...this.appState,...t.appState});return e.create(n,i,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,i){let o={shouldCompareHashes:!1};t===je.EVENTUALLY&&(o.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,o),s=this.maybeCreateAppStateSnapshot(i,o),a=!1,l=!1;return this.elements!==r&&(a=!0),this.appState!==s&&(l=!0),!a&&!l?this:new e(r,s,{didElementsChange:a,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let i=jd(t)?t:Jn(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=j.isRightDifferent(this.appState,t);if(!i)return;let o=Vd(JSON.stringify(t));if(!(n.shouldCompareHashes&&this._lastChangedAppStateHash===o))return this._lastChangedAppStateHash=o,i}detectChangedElements(t,n={shouldCompareHashes:!1}){if(this.elements===t)return;let i=new Map;for(let r of Qn(this.elements))t.get(r.id)||i.set(r.id,Le(r,{isDeleted:!0}));for(let r of Qn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(be(r)&&!Bn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=$d(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of Qn(this.elements))n.set(i.id,i);for(let i of Qn(t))n.set(i.id,Ds(i));return n}},Yd="__observedAppState",Th=()=>({name:null,editingGroupId:null,viewBackgroundColor:Ih.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),Jn=e=>{let t={name:e.name,editingGroupId:e.editingGroupId,viewBackgroundColor:e.viewBackgroundColor,selectedElementIds:e.selectedElementIds,selectedGroupIds:e.selectedGroupIds,croppingElementId:e.croppingElementId,activeLockedId:e.activeLockedId,lockedMultiSelections:e.lockedMultiSelections,selectedLinearElement:e.selectedLinearElement?{elementId:e.selectedLinearElement.elementId,isEditing:!!e.selectedLinearElement.isEditing}:null};return Reflect.defineProperty(t,Yd,{value:!0,enumerable:!1}),t},jd=e=>!!Reflect.get(e,Yd);P();P();var Kd="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function ti(e,t,n){let i=n[0];if(t!=null&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)===i||t&&t.slice(-1)===i)throw new Error("trailing zero");if(t){let s=0;for(;(e[s]||i)===t[s];)s++;if(s>0)return t.slice(0,s)+ti(e.slice(s),t.slice(s),n)}let o=e?n.indexOf(e[0]):0,r=t!=null?n.indexOf(t[0]):n.length;if(r-o>1){let s=Math.round(.5*(o+r));return n[s]}else return t&&t.length>1?t.slice(0,1):n[o]+ti(e.slice(1),null,n)}function Qd(e){if(e.length!==Jd(e[0]))throw new Error("invalid integer part of order key: "+e)}function Jd(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("invalid order key head: "+e)}function zi(e){let t=Jd(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function Zd(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=zi(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function qd(e,t){Qd(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])+1;s===t.length?i[r]=t[0]:(i[r]=t[s],o=!1)}if(o){if(n==="Z")return"a"+t[0];if(n==="z")return null;let r=String.fromCharCode(n.charCodeAt(0)+1);return r>"a"?i.push(t[0]):i.pop(),r+i.join("")}else return n+i.join("")}function vh(e,t){Qd(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])-1;s===-1?i[r]=t.slice(-1):(i[r]=t[s],o=!1)}if(o){if(n==="a")return"Z"+t.slice(-1);if(n==="A")return null;let r=String.fromCharCode(n.charCodeAt(0)-1);return r<"Z"?i.push(t.slice(-1)):i.pop(),r+i.join("")}else return n+i.join("")}function ei(e,t,n=Kd){if(e!=null&&Zd(e,n),t!=null&&Zd(t,n),e!=null&&t!=null&&e>=t)throw new Error(e+" >= "+t);if(e==null){if(t==null)return"a"+n[0];let l=zi(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+ti("",d,n);if(l<t)return l;let c=vh(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=zi(e),d=e.slice(l.length),c=qd(l,n);return c??l+ti(d,null,n)}let i=zi(e),o=e.slice(i.length),r=zi(t),s=t.slice(r.length);if(i===r)return i+ti(o,s,n);let a=qd(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+ti(o,null,n)}function Vo(e,t,n,i=Kd){if(n===0)return[];if(n===1)return[ei(e,t,i)];if(t==null){let s=ei(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=ei(s,t,i),a.push(s);return a}if(e==null){let s=ei(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=ei(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=ei(e,t,i);return[...Vo(e,r,o,i),r,...Vo(r,t,n-o-1,i)]}import{arrayToMap as Zo}from"@excalidraw/common";var Gs=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Dh=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=l=>`${l?.index}:${l?.id}:${l?.type}:${l?.isDeleted}:${l?.version}:${l?.versionNonce}`,a=e.map(l=>l.index);for(let[l,d]of a.entries()){let c=a[l-1],u=a[l+1];if(Os(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&wt(e[l])){let m=e[l],p=V(m,Zo(e));p&&p.index<=m.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(p)}", "${s(m)}"`)}}if(r.length){let l=new Gs,d=[];if(o&&(d.push("Additional reconciliation context:"),d.push(o.localElements.map(c=>s(c))),d.push(o.remoteElements.map(c=>s(c)))),i||console.error(r.join(`
19
20
 
20
- `),l.stack,e.map(d=>s(d)),...c),t)throw l}},pc=e=>e.sort((t,n)=>uc(t)&&uc(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),ui=(e,t)=>{try{let n=bo(e),i=kf(e,t),o=es(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Gf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)ye(s,n,{index:a})}catch{Of(e)}return e},Of=e=>{let t=bo(e),n=mc(e),i=es(e,n);for(let[o,{index:r}]of i)ye(o,t,{index:r});return e},ic=e=>{let t=bo(e),n=mc(e),i=es(e,n);for(let[o,{index:r}]of i)t.set(o.id,Me(o,{index:r}));return t},kf=(e,t)=>{let n=[],i=0;for(;i<e.length;)if(t.has(e[i].id)){let o=[i-1,i];for(;++i<e.length&&t.has(e[i].id);)o.push(i);o.push(i),n.push(o)}else i++;return n},mc=e=>{let t=[],n,i,o=-1,r=0,s=c=>{let d=e[o]?e[o].index:void 0,u=e[c-1]?.index;return!d&&u||d&&u&&u>d?[u,c-1]:[d,o]},a=c=>{let d=e[r]?e[r].index:void 0;if(d&&c<r)return[d,r];let u=r;for(;++u<e.length;){let p=e[u]?.index;if(!d&&p||d&&p&&p>d)return[p,u]}return[void 0,u]},l=0;for(;l<e.length;){let c=e[l].index;if([n,o]=s(l),[i,r]=a(l),Jr(c,n,i))l++;else{let d=[o,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[f,E]=a(l);if(Jr(u,p,f))break;[n,o]=[p,m],[i,r]=[f,E],d.push(l)}d.push(r),t.push(d)}}return t},Jr=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,es=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=yo(e[o]?.index,e[r]?.index,i.length);for(let a=0;a<i.length;a++){let l=e[i[a]];n.set(l,{index:s[a]})}}return n},uc=e=>!!e.index;P();var Mc=gd(xc(),1);import{randomInteger as Jf,arrayToMap as wc,toBrandedType as yc,isDevEnv as bc,isTestEnv as Pc,toArray as eh}from"@excalidraw/common";import{isNonDeletedElement as th}from"@excalidraw/element";import{isFrameLikeElement as nh}from"@excalidraw/element";import{getElementsInGroup as ih}from"@excalidraw/element";import{syncInvalidIndices as oh,syncMovedIndices as Ic,validateFractionalIndices as rh}from"@excalidraw/element";import{getSelectedElements as sh}from"@excalidraw/element";import{mutateElement as ah}from"@excalidraw/element";var Sc=e=>{let t=new Map,n=[];for(let i of e)i.isDeleted||(n.push(i),t.set(i.id,i));return{elementsMap:t,elements:n}},lh=(0,Mc.default)(e=>{(bc()||Pc()||window?.DEBUG_FRACTIONAL_INDICES)&&rh(e,{shouldThrow:bc()||Pc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),ch=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Io=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=yc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=yc(new Map);selectedElementsCache={selectedElementIds:null,elements:null,cache:new Map};sceneNonce;getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}constructor(t=null){t&&this.replaceAllElements(t)}getSelectedElements(t){let n=ch(t),i=t?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===i&&this.selectedElementsCache.selectedElementIds===t.selectedElementIds){let r=this.selectedElementsCache.cache.get(n);if(r)return r}else t?.elements==null&&this.selectedElementsCache.cache.clear();let o=sh(i,{selectedElementIds:t.selectedElementIds},t);return t?.elements==null&&(this.selectedElementsCache.selectedElementIds=t.selectedElementIds,this.selectedElementsCache.elements=this.nonDeletedElements,this.selectedElementsCache.cache.set(n,o)),o}getNonDeletedFramesLikes(){return this.nonDeletedFramesLikes}getElement(t){return this.elementsMap.get(t)||null}getNonDeletedElement(t){let n=this.getElement(t);return n&&th(n)?n:null}mapElements(t){let n=!1,i=this.elements.map(o=>{let r=t(o);return r!==o&&(n=!0),r});return n&&this.replaceAllElements(i),n}replaceAllElements(t){let n=eh(t),i=[];lh(n),this.elements=oh(n),this.elementsMap.clear(),this.elements.forEach(r=>{nh(r)&&i.push(r),this.elementsMap.set(r.id,r)});let o=Sc(this.elements);this.nonDeletedElements=o.elements,this.nonDeletedElementsMap=o.elementsMap,this.frames=i,this.nonDeletedFramesLikes=Sc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=Jf();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementAtIndex(t,n){if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),t,...this.elements.slice(n)];Ic(i,wc([t])),this.replaceAllElements(i)}insertElementsAtIndex(t,n){if(!t.length)return;if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];Ic(i,wc(t)),this.replaceAllElements(i)}insertElement=t=>{let n=t.frameId?this.getElementIndex(t.frameId):this.elements.length;this.insertElementAtIndex(t,n)};insertElements=t=>{if(!t.length)return;let n=t[0]?.frameId?this.getElementIndex(t[0].frameId):this.elements.length;this.insertElementsAtIndex(t,n)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),i=n.get(t);return i?[i]:ih(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=ah(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var ie=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let c of this.getDifferences(t,n))r[c]=t[c],s[c]=n[c];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static mergeObjects(t,n,i){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Gt(t??[],o),Gt(n??[],o),Gt(i??[],o)))}static diffObjects(t,n,i,o){if(!t[i]&&!n[i])return;let r=t[i]!==null&&typeof t[i]=="object",s=n[i]!==null&&typeof n[i]=="object";if(r||s){let a=t[i]??{},l=n[i]??{},c=e.getLeftDifferences(a,l).reduce((u,p)=>(u[p]=o(a[p]),u),{}),d=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=o(l[p]),u),{});Object.keys(c).length||Object.keys(d).length?(Reflect.set(t,i,c),Reflect.set(n,i,d)):(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}else t[i]===n[i]&&(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}static diffArrays(t,n,i,o){if(!(!t[i]&&!n[i])&&(Array.isArray(t[i])||Array.isArray(n[i]))){let r=Array.isArray(t[i])?t[i]:[],s=Array.isArray(n[i])?n[i]:[],a=Gt(e.getLeftDifferences(Gt(r,o),Gt(s,o)),c=>c),l=Gt(e.getRightDifferences(Gt(r,o),Gt(s,o)),c=>c);if(Object.keys(a).length||Object.keys(l).length){let c=r.filter(u=>a[o?o(u):String(u)]),d=s.filter(u=>l[o?o(u):String(u)]);Reflect.set(t,i,c),Reflect.set(n,i,d)}else Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i)}}static isLeftDifferent(t,n,i=!1){return!!this.distinctKeysIterator("left",t,n,i).next().value}static isRightDifferent(t,n,i=!1){return!!this.distinctKeysIterator("right",t,n,i).next().value}static isInnerDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("inner",t,n,i).next().value}static isDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("full",t,n,i).next().value}static getLeftDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("left",t,n,i)).sort()}static getRightDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("right",t,n,i)).sort()}static getInnerDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("inner",t,n,i)).sort()}static getDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("full",t,n,i)).sort()}static*distinctKeysIterator(t,n,i,o=!1){if(n===i)return;let r=[];t==="left"?r=Object.keys(n):t==="right"?r=Object.keys(i):t==="inner"?r=Object.keys(n).filter(s=>s in i):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(i)])):Ac(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let s of r){let a=n[s],l=i[s];if(a!==l){if(!o&&typeof a=="object"&&typeof l=="object"&&a!==null&&l!==null&&vc(a,l))continue;yield s}}}},mn=class e{constructor(t){this.delta=t}static calculate(t,n){let i=ie.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(ie.create({},{}))}inverse(){let t=ie.create(this.delta.inserted,this.delta.deleted);return new e(t)}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={}}=this.delta.deleted,{selectedElementIds:r={},selectedGroupIds:s={},selectedLinearElementId:a,editingLinearElementId:l,...c}=this.delta.inserted,d=ie.mergeObjects(t.selectedElementIds,r,i),u=ie.mergeObjects(t.selectedGroupIds,s,o),p=a&&n.has(a)?new Y(n.get(a),n):null,m=l&&n.has(l)?new Y(n.get(l),n):null,f={...t,...c,selectedElementIds:d,selectedGroupIds:u,selectedLinearElement:typeof a<"u"?p:t.selectedLinearElement,editingLinearElement:typeof l<"u"?m:t.editingLinearElement},E=this.filterInvisibleChanges(t,f,n);return[f,E]}catch(i){if(console.error("Couldn't apply appstate change",i),Fn()||Rn())throw i;return[t,!1]}}isEmpty(){return ie.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=Gn(t),r=Gn(n),s=ie.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=ie.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let c=ie.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),d=new Set;(c.includes("editingGroupId")||c.includes("selectedGroupIds"))&&(d=hl(i));for(let u of c)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],d,l);break;case"croppingElementId":{let E=n[u];if(!E)l.value=!0;else{let h=i.get(E);h&&!h.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?d.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElementId":case"editingLinearElementId":let m=e.convertToAppStateKey(u),f=n[m];if(!f)l.value=!0;else{let E=i.get(f.elementId);E&&!E.isDeleted?l.value=!0:n[m]=null}break;case"lockedMultiSelections":{let E=t[u]||{},h=n[u]||{};vc(E,h)||(l.value=!0);break}case"activeLockedId":{let E=t[u]||null,h=n[u]||null;E!==h&&(l.value=!0);break}default:Ac(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static convertToAppStateKey(t){switch(t){case"selectedLinearElementId":return"selectedLinearElement";case"editingLinearElementId":return"editingLinearElement"}}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,editingLinearElementId:r,selectedLinearElementId:s,croppingElementId:a,lockedMultiSelections:l,activeLockedId:c,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{ie.diffObjects(t,n,"selectedElementIds",i=>!0),ie.diffObjects(t,n,"selectedGroupIds",i=>i??!1),ie.diffObjects(t,n,"lockedMultiSelections",i=>i??{}),ie.diffObjects(t,n,"activeLockedId",i=>i??null)}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),Fn()||Rn())throw i}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let i of Object.keys(t).sort())n[i]=t[i];return n}},fn=class e{constructor(t,n,i){this.added=t;this.removed=n;this.updated=i}static create(t,n,i,o={shouldRedistribute:!1}){let r;if(o.shouldRedistribute){let s={},a={},l={},c=[...Object.entries(t),...Object.entries(n),...Object.entries(i)];for(let[d,u]of c)this.satisfiesAddition(u)?s[d]=u:this.satisfiesRemoval(u)?a[d]=u:l[d]=u;r=new e(s,a,l)}else r=new e(t,n,i);return(Fn()||Rn())&&(e.validate(r,"added",this.satisfiesAddition),e.validate(r,"removed",this.satisfiesRemoval),e.validate(r,"updated",this.satisfiesUpdate)),r}static restore(t){let{added:n,removed:i,updated:o}=t;return e.create(n,i,o)}static satisfiesAddition=({deleted:t,inserted:n})=>t.isDeleted===!0&&!n.isDeleted;static satisfiesRemoval=({deleted:t,inserted:n})=>!t.isDeleted&&n.isDeleted===!0;static satisfiesUpdate=({deleted:t,inserted:n})=>!!t.isDeleted==!!n.isDeleted;static satisfiesCommmonInvariants=({deleted:t,inserted:n})=>!!(t.version&&n.version&&Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static validate(t,n,i){for(let[o,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!i(r))throw console.error(`Broken invariant for "${n}" delta, element "${o}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${o}".`)}static calculate(t,n){if(t===n)return e.empty();let i={},o={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s,isDeleted:!1},c={isDeleted:!0,version:s.version+1,versionNonce:Tc()},d=ie.create(l,c,e.stripIrrelevantProps);o[s.id]=d}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:Tc()},c={...s,isDeleted:!1},d=ie.create(l,c,e.stripIrrelevantProps);i[s.id]=d;continue}if(a.versionNonce!==s.versionNonce){let l=ie.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}ie.isEmpty(l)||(r[s.id]=l)}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,l]of Object.entries(r))s[a]=ie.create(l.inserted,l.deleted);return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(c,d)=>(u,p)=>{let m;switch(p){case"deleted":m=c;break;case"inserted":m=d;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let E of Object.keys(u))switch(E){case"boundElements":f[E]=u[E];break;default:f[E]=m[E]}return f},r=c=>{let d={};for(let[u,p]of Object.entries(c)){let m=t.get(u),f=n.get(u),E=null;m||f?E=ie.create(p.deleted,p.inserted,o(m,f),i):E=p,ie.isInnerDifferent(E.deleted,E.inserted)&&(d[u]=E)}return d},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=hn.empty().elements,i={excludedProperties:new Set}){let o=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1};try{let a=e.createApplier(o,n,i,s),l=a(this.added),c=a(this.removed),d=a(this.updated),u=this.resolveConflicts(t,o);r=new Map([...l,...c,...d,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),Fn()||Rn())throw a;return[t,!0]}try{o=e.reorderElements(o,r,s);let a=new Io(o);e.redrawTextBoundingBoxes(a,r),e.redrawBoundArrows(a,r)}catch(a){if(console.error("Couldn't mutate elements after applying elements change",a),Fn()||Rn())throw a}finally{return[o,s.containsVisibleDifference]}}static createApplier=(t,n,i,o)=>r=>{let s=e.createGetter(t,n,o);return Object.entries(r).reduce((a,[l,c])=>{let d=s(l,c.inserted);if(d){let u=e.applyDelta(d,c,i,o);t.set(u.id,u),a.set(u.id,u)}return a},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?(i.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(i.containsVisibleDifference=!0)):s=Me({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||i.excludedProperties.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=ie.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!o.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);o.containsVisibleDifference=l}return o.containsZindexDifference||(o.containsZindexDifference=n.deleted.index!==n.inserted.index),Me(t,r)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:ie.isRightDifferent(t,n)}resolveConflicts(t,n){let i=new Map,o=(c,d)=>{let u=n.get(c.id);if(!u)return;let p;t.get(c.id)===u?p=Me(u,d):p=ye(u,n,d),i.set(p.id,p),n.set(p.id,p)};for(let c of Object.keys(this.removed))e.unbindAffected(t,n,c,o);for(let c of Object.keys(this.added))e.rebindAffected(t,n,c,o);for(let[c]of Array.from(Object.entries(this.updated)).filter(([d,u])=>Object.keys({...u.deleted,...u.inserted}).find(p=>Za.has(p)))){let d=n.get(c);!d||d.isDeleted||e.rebindAffected(t,n,c,o)}let r=new Map(Array.from(t).filter(([c])=>i.has(c))),{added:s,removed:a,updated:l}=e.calculate(r,i);for(let[c,d]of Object.entries(s))this.added[c]=d;for(let[c,d]of Object.entries(a))this.removed[c]=d;for(let[c,d]of Object.entries(l))this.updated[c]=d;return i}static unbindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.unbindAffected(n,s(),o),$t.unbindAffected(n,r(),o),$t.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.rebindAffected(n,s(),o),$t.unbindAffected(n,r(),(a,l)=>{ne(a)&&o(a,l)}),$t.rebindAffected(n,s(),o)}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(fe(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(st(r)){let s=It(r),a=s?i.get(s):void 0;a&&o.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of o.values())r.isDeleted||s.isDeleted||ga(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Le(i)&&Xe(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=pc([...o]),s=ie.getRightDifferences(o,r,!0).reduce((a,l)=>{let c=o[Number(l)];return c&&n.has(c.id)&&a.set(c.id,c),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),dh(ui(r,s))}static postProcess(t,n){try{ie.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];ie.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),Fn()||Rn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var eP=(e,t,n)=>{let[i,o,r,s]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],a=Ct(e),l=uo(e,t).map(p=>[p,Ct(p)]).sort((p,m)=>p[1][o]-m[1][o]),c=0;for(let p of l)c+=p[1][s];let d=(a[s]-c)/(l.length-1);if(d<0){let p=l.findIndex(h=>h[1][i]===a[i]),m=l.findIndex(h=>h[1][r]===a[r]),f=(l[m][1][o]-l[p][1][o])/(l.length-1),E=l[p][1][o];return l.flatMap(([h,g],x)=>{let y={x:0,y:0};return x!==p&&x!==m&&(E+=f,y[n.axis]=E-g[o]),h.map(b=>Me(b,{x:b.x+y.x,y:b.y+y.y}))})}let u=a[i];return l.flatMap(([p,m])=>{let f={x:0,y:0};return f[n.axis]=u-m[i],u+=d,u+=m[s],p.map(E=>Me(E,{x:E.x+f.x,y:E.y+f.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as uh,getGridPoint as ph,getFontString as mh}from"@excalidraw/common";var dP=(e,t,n,i,o,r)=>{if(t.length===1&&G(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(u=>{if(G(u)&&u.startBinding&&u.endBinding){let p=t.find(f=>f.id===u.startBinding?.elementId),m=t.find(f=>f.id===u.endBinding?.elementId);return p&&m}return!0}),a=new Set(s),l=s.filter(u=>V(u)).map(u=>u.id);if(l.length>0)for(let u of i.getNonDeletedElements())u.frameId!==null&&l.includes(u.frameId)&&a.add(u);let c=[];for(let u of a){let p=e.originalElements.get(u.id);if(!p)return;c.push(p)}let d=fh(tt(c),n,o,r);a.forEach(u=>{if(Dc(e,u,i,d),!_(u)){let p=Z(u,i.getNonDeletedElementsMap());p&&Dc(e,p,i,d),Xe(u,i,{simultaneouslyUpdated:Array.from(a)})}})},fh=(e,t,n,i)=>{let[o,r]=e,s=o+t.x+n.x,a=r+t.y+n.y;if(n.x===0||n.y===0){let[l,c]=ph(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=c)}return{x:s-o,y:a-r}},Dc=(e,t,n,i)=>{let o=e.originalElements.get(t.id)??t,r=o.x+i.x,s=o.y+i.y;n.mutateElement(t,{x:r,y:s})},uP=(e,t,n)=>{let[i,o]=tt(e);return[t-i,n-o]},pP=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:c,zoom:d,scene:u,widthAspectRatio:p=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Wr(t,a,o<n?-s:s):{width:s,height:a}=Wr(t,s,r<i?-a:a),a<0&&(a=-a)));let E=o<n?n-s:n,h=r<i?i-a:i;c&&(s+=s,a+=a,E=n-s/2,h=i-a/2);let g=null;if(ne(e)){a=e.height;let x=Ni(mh({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>uh/d&&(g={autoResize:!1}),h=i,c&&(E=n-s/2)}if(s!==0&&a!==0){let x=null;xe(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:E+(m?.x??0),y:h+(m?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as So,normalizeLink as Lc}from"@excalidraw/common";var gP=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(So,e),Lc(i.toString())}catch(i){console.error(i)}return Lc(n)},xP=(e,t)=>{if(e.length>0&&hh(e)){if(e.length===1)return{id:e[0].id,type:"element"};if(e.length>1){let n=Object.keys(t.selectedGroupIds)[0];return n?{id:n,type:"group"}:{id:e[0].groupIds[0],type:"group"}}}return null},hh=e=>!!(e.length===1||e.length>1&&El(e)),wP=e=>{try{let t=new URL(e);return t.searchParams.has(So)&&t.host===window.location.host}catch{return!1}},yP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(So))return t.get(So)}catch{}return null};P();import{FONT_FAMILY as Ah,VERTICAL_ALIGN as vh,escapeDoubleQuotes as is,getFontString as Dh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as Jt,DEFAULT_FONT_FAMILY as Eh,DEFAULT_FONT_SIZE as gh,DEFAULT_TEXT_ALIGN as xh,DEFAULT_VERTICAL_ALIGN as wh,VERTICAL_ALIGN as yh,randomInteger as bh,randomId as Ph,getFontString as Mo,getUpdatedTimestamp as Ih,getLineHeight as Sh}from"@excalidraw/common";var nt=(e,{x:t,y:n,strokeColor:i=Jt.strokeColor,backgroundColor:o=Jt.backgroundColor,fillStyle:r=Jt.fillStyle,strokeWidth:s=Jt.strokeWidth,strokeStyle:a=Jt.strokeStyle,roughness:l=Jt.roughness,opacity:c=Jt.opacity,width:d=0,height:u=0,angle:p=0,groupIds:m=[],frameId:f=null,index:E=null,roundness:h=null,boundElements:g=null,link:x=null,locked:y=Jt.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||d<-1e6||d>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:d,height:u,points:b.points}),{id:b.id||Ph(),type:e,x:t,y:n,width:d,height:u,angle:p,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:c,groupIds:m,frameId:f,index:E,roundness:h,seed:b.seed??bh(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Ih(),link:x,locked:y,customData:b.customData}),ns=e=>nt(e.type,e),LP=e=>nt("embeddable",e),CP=e=>({...nt("iframe",e)}),BP=e=>Me({...nt("frame",e),type:"frame",name:e?.name||null},{}),GP=e=>Me({...nt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Cc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Bc=e=>{let t=e.fontFamily||Eh,n=e.fontSize||gh,i=e.lineHeight||Sh(t),o=tr(e.text),r=Qe(o,Mo({fontFamily:t,fontSize:n}),i),s=e.textAlign||xh,a=e.verticalAlign||wh,l=Cc({textAlign:s,verticalAlign:a},r),c={...nt("text",e),text:o,fontSize:n,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i};return Me(c,{})},Mh=(e,t,n)=>{let{width:i,height:o}=Qe(n,Mo(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===yh.MIDDLE&&!e.containerId&&e.autoResize){let c=Qe(e.text,Mo(e),e.lineHeight),d=Cc(e,{width:i-c.width,height:o-c.height});a=e.x-d.x,l=e.y-d.y}else{let[c,d,u,p]=H(e,t),[m,f,E,h]=Nt(e,i,o,!1),g=(c-m)/2,x=(d-f)/2,y=(u-E)/2,b=(p-h)/2;[a,l]=Th({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,y,b)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},Th=(e,t,n,i,o,r,s,a)=>{let l=Math.cos(i),c=Math.sin(i);return e.e&&e.w?t+=o+s:e.e?(t+=o*(1+l),n+=o*c,t+=s*(1-l),n+=s*-c):e.w&&(t+=o*(1-l),n+=o*-c,t+=s*(1+l),n+=s*c),e.n&&e.s?n+=r+a:e.n?(t+=r*c,n+=r*(1-l),t+=a*-c,n+=a*(1+l)):e.s&&(t+=r*-c,n+=r*(1+l),t+=a*c,n+=a*(1-l)),[t,n]},OP=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Pt(i,Mo(e),t?Je(t,e):e.width));let o=Mh(e,n,i);return{text:i,...o}},kP=e=>({...nt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,lastCommittedPoint:null}),RP=e=>{let t={...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return ln(t)?{...t,polygon:e.polygon??!1}:t},Gc=e=>e.elbowed?{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},FP=e=>({...nt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ft=new Map,Lh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)(?:\?t=|&t=|\?start=|&start=)?([a-zA-Z0-9_-]+)?[^\s]*$/,Ch=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Bh=/^https:\/\/(?:www\.)?figma\.com/,Oc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Gh=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Oh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,kc=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,kh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,Rh=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Fh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Rc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Fc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,Nh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,rs=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Nc=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),os=e=>`<html><body>${e}</body></html>`,UP=e=>{if(!e)return null;if(ft.has(e))return ft.get(e);let t=e,n=Nc.has(ss(e,Nc)||""),i="generic",o={w:560,h:840},r=e.match(Lh);if(r?.[2]){let c=r[3]?`&start=${r[3]}`:"",d=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${c}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break}return o=d?{w:315,h:560}:{w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(Ch);if(s?.[1]){let c=s?.[1],d=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${c}?api=1`,o={w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:d,sandbox:{allowSameOrigin:n}}}if(e.match(Bh))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let l=e.match(Rh);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(Oh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),kc.test(e)){let c=e.match(kc)[1],d=is(`https://twitter.com/x/status/${c}`),u={type:"document",srcdoc:p=>os(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${d}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,u),u}if(Fc.test(e)){let[,c,d,u]=e.match(Fc),p=is(`https://reddit.com/r/${c}/comments/${d}/${u}`),m={type:"document",srcdoc:f=>os(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${p}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,m),m}if(Oc.test(e)){let[,c,d]=e.match(Oc),u=is(`https://gist.github.com/${c}/${d}`),p={type:"document",srcdoc:()=>os(`
21
- <script src="${u}.js"><\/script>
21
+ `),l.stack,e.map(c=>s(c)),...d),t)throw l}},tc=e=>e.sort((t,n)=>ec(t)&&ec(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),Hi=(e,t)=>{try{let n=Zo(e),i=Bh(e,t),o=Fs(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Dh(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)Pe(s,n,{index:a})}catch{ks(e)}return e},ks=e=>{let t=Zo(e),n=nc(e),i=Fs(e,n);for(let[o,{index:r}]of i)Pe(o,t,{index:r});return e},Xd=e=>{let t=Zo(e),n=nc(e),i=Fs(e,n);for(let[o,{index:r}]of i)t.set(o.id,Le(o,{index:r}));return t},Bh=(e,t)=>{let n=[],i=0;for(;i<e.length;)if(t.has(e[i].id)){let o=[i-1,i];for(;++i<e.length&&t.has(e[i].id);)o.push(i);o.push(i),n.push(o)}else i++;return n},nc=e=>{let t=[],n,i,o=-1,r=0,s=d=>{let c=e[o]?e[o].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,o]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let m=e[u]?.index;if(!c&&m||c&&m&&m>c)return[m,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,o]=s(l),[i,r]=a(l),Os(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[m,p]=s(l),[f,h]=a(l);if(Os(u,m,f))break;[n,o]=[m,p],[i,r]=[f,h],c.push(l)}c.push(r),t.push(c)}}return t},Os=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,Fs=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=Vo(e[o]?.index,e[r]?.index,i.length);for(let a=0;a<i.length;a++){let l=e[i[a]];n.set(l,{index:s[a]})}}return n},ec=e=>!!e.index;P();var fc=pu(ac(),1);import{randomInteger as Vh,arrayToMap as lc,toBrandedType as dc,isDevEnv as cc,isTestEnv as uc,toArray as Zh}from"@excalidraw/common";import{isNonDeletedElement as qh}from"@excalidraw/element";import{isFrameLikeElement as Kh}from"@excalidraw/element";import{getElementsInGroup as Qh}from"@excalidraw/element";import{syncInvalidIndices as Jh,syncMovedIndices as mc,validateFractionalIndices as eE}from"@excalidraw/element";import{getSelectedElements as tE}from"@excalidraw/element";import{mutateElement as nE}from"@excalidraw/element";var pc=e=>{let t=new Map,n=[];for(let i of e)i.isDeleted||(n.push(i),t.set(i.id,i));return{elementsMap:t,elements:n}},iE=(0,fc.default)(e=>{(cc()||uc()||window?.DEBUG_FRACTIONAL_INDICES)&&eE(e,{shouldThrow:cc()||uc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),oE=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},ni=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=dc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=dc(new Map);selectedElementsCache={selectedElementIds:null,elements:null,cache:new Map};sceneNonce;getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}constructor(t=null,n){t&&this.replaceAllElements(t,n)}getSelectedElements(t){let n=oE(t),i=t?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===i&&this.selectedElementsCache.selectedElementIds===t.selectedElementIds){let r=this.selectedElementsCache.cache.get(n);if(r)return r}else t?.elements==null&&this.selectedElementsCache.cache.clear();let o=tE(i,{selectedElementIds:t.selectedElementIds},t);return t?.elements==null&&(this.selectedElementsCache.selectedElementIds=t.selectedElementIds,this.selectedElementsCache.elements=this.nonDeletedElements,this.selectedElementsCache.cache.set(n,o)),o}getNonDeletedFramesLikes(){return this.nonDeletedFramesLikes}getElement(t){return this.elementsMap.get(t)||null}getNonDeletedElement(t){let n=this.getElement(t);return n&&qh(n)?n:null}mapElements(t){let n=!1,i=this.elements.map(o=>{let r=t(o);return r!==o&&(n=!0),r});return n&&this.replaceAllElements(i),n}replaceAllElements(t,n){let i=Zh(t),o=[];n?.skipValidation||iE(i),this.elements=Jh(i),this.elementsMap.clear(),this.elements.forEach(s=>{Kh(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=pc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=pc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=Vh();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementAtIndex(t,n){if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),t,...this.elements.slice(n)];mc(i,lc([t])),this.replaceAllElements(i)}insertElementsAtIndex(t,n){if(!t.length)return;if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];mc(i,lc(t)),this.replaceAllElements(i)}insertElement=t=>{let n=t.frameId?this.getElementIndex(t.frameId):this.elements.length;this.insertElementAtIndex(t,n)};insertElements=t=>{if(!t.length)return;let n=t[0]?.frameId?this.getElementIndex(t[0].frameId):this.elements.length;this.insertElementsAtIndex(t,n)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),i=n.get(t);return i?[i]:Qh(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=nE(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var j=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i=e.empty()){return e.create({...t.deleted,...n.deleted,...i.deleted},{...t.inserted,...n.inserted,...i.inserted})}static mergeObjects(t,n,i={}){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Zt(t??[],o),Zt(n??[],o),Zt(i??[],o)))}static diffObjects(t,n,i,o){if(!t[i]&&!n[i])return;let r=t[i]!==null&&typeof t[i]=="object",s=n[i]!==null&&typeof n[i]=="object";if(r||s){let a=t[i]??{},l=n[i]??{},d=e.getLeftDifferences(a,l).reduce((u,m)=>(u[m]=o(a[m]),u),{}),c=e.getRightDifferences(a,l).reduce((u,m)=>(u[m]=o(l[m]),u),{});Object.keys(d).length||Object.keys(c).length?(Reflect.set(t,i,d),Reflect.set(n,i,c)):(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}else t[i]===n[i]&&(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}static diffArrays(t,n,i,o){if(!(!t[i]&&!n[i])&&(Array.isArray(t[i])||Array.isArray(n[i]))){let r=Array.isArray(t[i])?t[i]:[],s=Array.isArray(n[i])?n[i]:[],a=Zt(e.getLeftDifferences(Zt(r,o),Zt(s,o)),d=>d),l=Zt(e.getRightDifferences(Zt(r,o),Zt(s,o)),d=>d);if(Object.keys(a).length||Object.keys(l).length){let d=r.filter(u=>a[o?o(u):String(u)]),c=s.filter(u=>l[o?o(u):String(u)]);Reflect.set(t,i,d),Reflect.set(n,i,c)}else Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i)}}static isLeftDifferent(t,n,i=!1){return!!this.distinctKeysIterator("left",t,n,i).next().value}static isRightDifferent(t,n,i=!1){return!!this.distinctKeysIterator("right",t,n,i).next().value}static isInnerDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("inner",t,n,i).next().value}static isDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("full",t,n,i).next().value}static getLeftDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("left",t,n,i)).sort()}static getRightDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("right",t,n,i)).sort()}static getInnerDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("inner",t,n,i)).sort()}static getDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("full",t,n,i)).sort()}static*distinctKeysIterator(t,n,i,o=!1){if(n===i)return;let r=[];t==="left"?r=Object.keys(n):t==="right"?r=Object.keys(i):t==="inner"?r=Object.keys(n).filter(s=>s in i):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(i)])):Ec(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let s of r){let a=n[s],l=i[s];if(a!==l){if(!o&&typeof a=="object"&&typeof l=="object"&&a!==null&&l!==null&&gc(a,l))continue;yield s}}}},bn=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=j.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(j.create({},{}))}inverse(){let t=j.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=j.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=j.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=j.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=j.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=j.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=j.mergeObjects(this.delta.inserted.lockedMultiSelections??{},t.delta.inserted.lockedMultiSelections??{}),l={},d={};return(Object.keys(n).length||Object.keys(i).length)&&(d.selectedElementIds=n,l.selectedElementIds=i),(Object.keys(o).length||Object.keys(r).length)&&(d.selectedGroupIds=o,l.selectedGroupIds=r),(Object.keys(s).length||Object.keys(a).length)&&(d.lockedMultiSelections=s,l.lockedMultiSelections=a),this.delta=j.merge(this.delta,t.delta,j.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:s={},selectedGroupIds:a={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=j.mergeObjects(t.selectedElementIds,s,i),m=j.mergeObjects(t.selectedGroupIds,a,o),p=j.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new G(n.get(d.elementId),n,d.isEditing):null,h={...t,...c,selectedElementIds:u,selectedGroupIds:m,lockedMultiSelections:p,selectedLinearElement:typeof d<"u"?f:t.selectedLinearElement},E=this.filterInvisibleChanges(t,h,n);return[h,E]}catch(i){if(console.error("Couldn't apply appstate change",i),Sn()||In())throw i;return[t,!1]}}isEmpty(){return j.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=Jn(t),r=Jn(n),s=j.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=j.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=j.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=ad(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let w=i.get(x);w&&!w.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let m=n[u];m?c.has(m)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let p=n[u];if(!p)l.value=!0;else{let x=i.get(p.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},h=n[u]||{};gc(f,h)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,g=n[u]||null;E!==g&&(l.value=!0);break;default:Ec(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{j.diffObjects(t,n,"selectedElementIds",i=>!0),j.diffObjects(t,n,"selectedGroupIds",i=>i??!1),j.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),Sn()||In())throw i}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let i of Object.keys(t).sort())n[i]=t[i];return n}},yn=class e{constructor(t,n,i){this.added=t;this.removed=n;this.updated=i}static create(t,n,i,o={shouldRedistribute:!1}){let r;if(o.shouldRedistribute){let s={},a={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(i)];for(let[c,u]of d)this.satisfiesAddition(u)?s[c]=u:this.satisfiesRemoval(u)?a[c]=u:l[c]=u;r=new e(s,a,l)}else r=new e(t,n,i);return(Sn()||In())&&(e.validate(r,"added",this.satisfiesAddition),e.validate(r,"removed",this.satisfiesRemoval),e.validate(r,"updated",this.satisfiesUpdate)),r}static restore(t){let{added:n,removed:i,updated:o}=t;return e.create(n,i,o)}static satisfiesAddition=({deleted:t,inserted:n})=>t.isDeleted===!0&&!n.isDeleted;static satisfiesRemoval=({deleted:t,inserted:n})=>!t.isDeleted&&n.isDeleted===!0;static satisfiesUpdate=({deleted:t,inserted:n})=>!!t.isDeleted==!!n.isDeleted;static satisfiesCommmonInvariants=({deleted:t,inserted:n})=>!!(Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static satisfiesUniqueInvariants=(t,n)=>{let{added:i,removed:o,updated:r}=t;return[i[n],o[n],r[n]].filter(Boolean).length===1};static validate(t,n,i){for(let[o,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!this.satisfiesUniqueInvariants(t,o)||!i(r))throw console.error(`Broken invariant for "${n}" delta, element "${o}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${o}".`)}static calculate(t,n){if(t===n)return e.empty();let i={},o={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s},d={isDeleted:!0,version:s.version+1,versionNonce:hc()},c=j.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:hc()},d={...s},c=j.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=j.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}r[s.id]=l}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=j.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,m)=>{let p;switch(m){case"deleted":p=d;break;case"inserted":p=c;break}if(!p)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let h of Object.keys(u))switch(h){case"boundElements":f[h]=u[h];break;default:f[h]=p[h]}return f},r=d=>{let c={};for(let[u,m]of Object.entries(d)){let p=t.get(u),f=n.get(u),h=null;p||f?h=j.create(m.deleted,m.inserted,o(p,f),i):h=m,j.isInnerDifferent(h.deleted,h.inserted)&&(c[u]=h)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=Pn.empty().elements,i){let o=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let a=e.createApplier(t,o,n,s,i),l=a(this.added),d=a(this.removed),c=a(this.updated),u=this.resolveConflicts(t,o,s.applyDirection);r=new Map([...l,...d,...c,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),Sn()||In())throw a;return[t,!0]}try{o=e.reorderElements(o,r,s),e.redrawElements(o,r)}catch(a){if(console.error("Couldn't mutate elements after applying elements change",a),Sn()||In())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=j.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=j.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return j.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=j.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=j.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=j.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(Sn()||In())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,i,o,r)=>s=>{let a=e.createGetter(n,i,o);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let m=e.applyDelta(u,c,o,r);if(n.set(m.id,m),l.set(m.id,m),!o.applyDirection){let p=t.get(d);p&&(o.applyDirection=p.version>m.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?(i.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(i.containsVisibleDifference=!0)):s=Le({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=j.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!i.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);i.containsVisibleDifference=l}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Le(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:j.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,m=l,p;c===d?p=Le(d,{...m,version:u},!0):p=Pe(d,n,{...m,version:c?.version!==d.version?d.version:u}),o.set(p.id,p),n.set(p.id,p)};for(let a of Object.keys(this.removed))e.unbindAffected(t,n,a,r);for(let a of Object.keys(this.added))e.rebindAffected(t,n,a,r);for(let[a]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>_l.has(c)))){let l=n.get(a);!l||l.isDeleted||e.rebindAffected(t,n,a,r)}let s=new Map(Array.from(t).filter(([a])=>o.has(a)));return this.squash(e.calculate(s,o)),o}static unbindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);pn.unbindAffected(n,r(),o),pn.unbindAffected(n,s(),o),fn.unbindAffected(n,r(),o),fn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);pn.unbindAffected(n,r(),o),pn.rebindAffected(n,s(),o),fn.unbindAffected(n,r(),(a,l)=>{q(a)&&o(a,l)}),fn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new ni(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),Sn()||In())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(ue(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(wt(r)){let s=Ht(r),a=s?i.get(s):void 0;a&&o.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of o.values())r.isDeleted||s.isDeleted||wo(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&ce(i)&&De(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=tc([...o]),s=j.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),rE(Hi(r,s))}static postProcess(t,n){try{j.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];j.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),Sn()||In())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var cI=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=$t(e),c=Ro(e,t,i).map(f=>[f,$t(f)]).sort((f,h)=>f[1][s]-h[1][s]),u=0;for(let f of c)u+=f[1][l];let m=(d[l]-u)/(c.length-1);if(m<0){let f=c.findIndex(x=>x[1][r]===d[r]),h=c.findIndex(x=>x[1][a]===d[a]),E=(c[h][1][s]-c[f][1][s])/(c.length-1),g=c[f][1][s];return c.flatMap(([x,w],b)=>{let y={x:0,y:0};return b!==f&&b!==h&&(g+=E,y[n.axis]=g-w[s]),x.map(I=>{let M=o.mutateElement(I,{x:I.x+y.x,y:I.y+y.y});return De(I,o,{simultaneouslyUpdated:x}),M})})}let p=d[r];return c.flatMap(([f,h])=>{let E={x:0,y:0};return E[n.axis]=p-h[r],p+=m,p+=h[l],f.map(g=>{let x=o.mutateElement(g,{x:g.x+E.x,y:g.y+E.y});return De(g,o,{simultaneouslyUpdated:f}),x})})};P();import{TEXT_AUTOWRAP_THRESHOLD as sE,getGridPoint as aE,getFontString as lE,DRAGGING_THRESHOLD as dE}from"@excalidraw/common";var bI=(e,t,n,i,o,r)=>{if(t.length===1&&U(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(U(m)&&m.startBinding&&m.endBinding){let p=t.find(h=>h.id===m.startBinding?.elementId),f=t.find(h=>h.id===m.endBinding?.elementId);return p&&f}return!0}),a=new Set(s),l=s.filter(m=>Z(m)).map(m=>m.id);if(l.length>0)for(let m of i.getNonDeletedElements())m.frameId!==null&&l.includes(m.frameId)&&a.add(m);let d=[];for(let m of a){let p=e.originalElements.get(m.id);if(!p)return;d.push(p)}let c=cE(Oe(d),n,o,r),u=new Set(Array.from(a,m=>m.id));a.forEach(m=>{let p=!H(m),f=p||(m.startBinding?u.has(m.startBinding.elementId):!1),h=p||(m.endBinding?u.has(m.endBinding.elementId):!1);if(H(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>dE||!m.startBinding&&!m.endBinding){Ns(e,m,i,c);let E=m.startBinding&&!f,g=m.endBinding&&!h;(E||g)&&(E&&ve(m,"start",i),g&&ve(m,"end",i))}}else{Ns(e,m,i,c);let E=V(m,i.getNonDeletedElementsMap());E&&Ns(e,E,i,c),De(m,i,{simultaneouslyUpdated:Array.from(a)})}})},cE=(e,t,n,i)=>{let[o,r]=e,s=o+t.x+n.x,a=r+t.y+n.y;if(n.x===0||n.y===0){let[l,d]=aE(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Ns=(e,t,n,i)=>{let o=e.originalElements.get(t.id)??t,r=o.x+i.x,s=o.y+i.y;n.mutateElement(t,{x:r,y:s})},yI=(e,t,n)=>{let[i,o]=Oe(e);return[t-i,n-o]},PI=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:m=null,originOffset:p=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(m?a=s/m:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Ms(t,a,o<n?-s:s):{width:s,height:a}=Ms(t,s,r<i?-a:a),a<0&&(a=-a)));let h=o<n?n-s:n,E=r<i?i-a:i;d&&(s+=s,a+=a,h=n-s/2,E=i-a/2);let g=null;if(q(e)){a=e.height;let x=ho(lE({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>sE/c&&(g={autoResize:!1}),E=i,d&&(h=n-s/2)}if(s!==0&&a!==0){let x=null;be(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:h+(p?.x??0),y:E+(p?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as Ko,normalizeLink as xc}from"@excalidraw/common";var TI=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Ko,e),xc(i.toString())}catch(i){console.error(i)}return xc(n)},vI=(e,t)=>{if(e.length>0&&uE(e)){if(e.length===1)return{id:e[0].id,type:"element"};if(e.length>1){let n=Object.keys(t.selectedGroupIds)[0];return n?{id:n,type:"group"}:{id:e[0].groupIds[0],type:"group"}}}return null},uE=e=>!!(e.length===1||e.length>1&&ld(e)),DI=e=>{try{let t=new URL(e);return t.searchParams.has(Ko)&&t.host===window.location.host}catch{return!1}},BI=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Ko))return t.get(Ko)}catch{}return null};P();import{FONT_FAMILY as IE,VERTICAL_ALIGN as SE,escapeDoubleQuotes as zs,getFontString as AE}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as An,DEFAULT_FONT_FAMILY as mE,DEFAULT_FONT_SIZE as pE,DEFAULT_TEXT_ALIGN as fE,DEFAULT_VERTICAL_ALIGN as hE,VERTICAL_ALIGN as EE,randomInteger as gE,randomId as xE,getFontString as Qo,getUpdatedTimestamp as wE,getLineHeight as bE}from"@excalidraw/common";var ft=(e,{x:t,y:n,strokeColor:i=An.strokeColor,backgroundColor:o=An.backgroundColor,fillStyle:r=An.fillStyle,strokeWidth:s=An.strokeWidth,strokeStyle:a=An.strokeStyle,roughness:l=An.roughness,opacity:d=An.opacity,width:c=0,height:u=0,angle:m=0,groupIds:p=[],frameId:f=null,index:h=null,roundness:E=null,boundElements:g=null,link:x=null,locked:w=An.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:b.points}),{id:b.id||xE(),type:e,x:t,y:n,width:c,height:u,angle:m,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:p,frameId:f,index:h,roundness:E,seed:b.seed??gE(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:wE(),link:x,locked:w,customData:b.customData}),zn=e=>ft(e.type,e),HI=e=>ft("embeddable",e),_I=e=>({...ft("iframe",e)}),wc=e=>Le({...ft("frame",e),type:"frame",name:e?.name||null},{}),bc=e=>Le({...ft("magicframe",e),type:"magicframe",name:e?.name||null},{}),yc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Hn=e=>{let t=e.fontFamily||mE,n=e.fontSize||pE,i=e.lineHeight||bE(t),o=bi(e.text),r=Ve(o,Qo({fontFamily:t,fontSize:n}),i),s=e.textAlign||fE,a=e.verticalAlign||hE,l=yc({textAlign:s,verticalAlign:a},r),d={...ft("text",e),text:o,fontSize:n,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i};return Le(d,{})},yE=(e,t,n)=>{let{width:i,height:o}=Ve(n,Qo(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===EE.MIDDLE&&!e.containerId&&e.autoResize){let d=Ve(e.text,Qo(e),e.lineHeight),c=yc(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,m]=$(e,t),[p,f,h,E]=tn(e,i,o,!1),g=(d-p)/2,x=(c-f)/2,w=(u-h)/2,b=(m-E)/2;[a,l]=PE({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,w,b)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},PE=(e,t,n,i,o,r,s,a)=>{let l=Math.cos(i),d=Math.sin(i);return e.e&&e.w?t+=o+s:e.e?(t+=o*(1+l),n+=o*d,t+=s*(1-l),n+=s*-d):e.w&&(t+=o*(1-l),n+=o*-d,t+=s*(1+l),n+=s*d),e.n&&e.s?n+=r+a:e.n?(t+=r*d,n+=r*(1-l),t+=a*-d,n+=a*(1+l)):e.s&&(t+=r*-d,n+=r*(1+l),t+=a*d,n+=a*(1-l)),[t,n]},UI=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=zt(i,Qo(e),t?ct(t,e):e.width));let o=yE(e,n,i);return{text:i,...o}},WI=e=>({...ft(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure}),Pc=e=>{let t={...ft(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Ot(t)?{...t,polygon:e.polygon??!1}:t},Jo=e=>e.elbowed?{...ft(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...ft(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},Ic=e=>({...ft("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ht=new Map,ME=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,TE=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,vE=/^https:\/\/(?:www\.)?figma\.com/,Sc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,DE=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,BE=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Ac=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,LE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,CE=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,GE=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Mc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Tc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,OE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Dc=e=>{let t;try{let s=new URL(e.startsWith("http")?e:`https://${e}`);t=s.searchParams.get("t")||s.searchParams.get("start")}catch{t=e.match(/[?&#](?:t|start)=([^&#\s]+)/)?.[1]}if(!t)return 0;if(/^\d+$/.test(t))return parseInt(t,10);let n=t.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);if(!n)return 0;let[,i="0",o="0",r="0"]=n;return parseInt(i)*3600+parseInt(o)*60+parseInt(r)},kE=e=>{try{let t=new URL(e.startsWith("http")?e:`https://${e}`);if(t.hostname.replace(/^www\./,"")!=="drive.google.com")return null;let i=null,o=t.pathname.match(/^\/file\/d\/([^/]+)(?:\/|$)/);if(o?.[1]?i=o[1]:(t.pathname==="/open"||t.pathname==="/uc")&&(i=t.searchParams.get("id")),!i||!/^[a-zA-Z0-9_-]+$/.test(i))return null;let r=t.searchParams.get("resourcekey"),s=Dc(t.toString());return{fileId:i,resourceKey:r&&/^[a-zA-Z0-9_-]+$/.test(r)?r:void 0,timestamp:s>0?s:void 0}}catch{return null}},_s=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),vc=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),Hs=e=>`<html><body>${e}</body></html>`,qI=e=>{if(!e)return null;if(ht.has(e))return ht.get(e);let t=e,n=vc.has(Us(e,vc)||""),i="generic",o={w:560,h:840},r=e.match(ME);if(r?.[2]){let c=Dc(t),u=c>0?`&start=${c}`:"",m=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${u}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break}return o=m?{w:315,h:560}:{w:560,h:315},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(TE);if(s?.[1]){let c=s?.[1],u=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${c}?api=1`,o={w:560,h:315},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=kE(e);if(a){i="video";let c=new URLSearchParams;a.resourceKey&&c.set("resourcekey",a.resourceKey),a.timestamp&&c.set("t",`${a.timestamp}`);let u=c.toString();return e=`https://drive.google.com/file/d/${a.fileId}/preview${u?`?${u}`:""}`,o={w:560,h:315},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(vE))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(CE);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(BE.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Ac.test(e)){let c=e.match(Ac)[1],u=zs(`https://twitter.com/x/status/${c}`),m={type:"document",srcdoc:p=>Hs(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${u}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ht.set(t,m),m}if(Tc.test(e)){let[,c,u,m]=e.match(Tc),p=zs(`https://reddit.com/r/${c}/comments/${u}/${m}`),f={type:"document",srcdoc:h=>Hs(`<blockquote class="reddit-embed-bq" data-embed-theme="${h}"><a href="${p}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ht.set(t,f),f}if(Sc.test(e)){let[,c,u]=e.match(Sc),m=zs(`https://gist.github.com/${c}/${u}`),p={type:"document",srcdoc:()=>Hs(`
22
+ <script src="${m}.js"><\/script>
22
23
  <style type="text/css">
23
24
  * { margin: 0px; }
24
25
  table, .gist { height: 100%; }
25
26
  .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
26
27
  </style>
27
- `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return ft.set(e,p),p}return ft.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},WP=e=>{let t;Gi(e)?t="IFrame element":t=!e.link||e?.link===""?"Empty Web-Embed":e.link;let n=Math.max(Math.min(e.width/2,e.width/t.length),e.width/30),i=Ah.Helvetica,o=Dh({fontSize:n,fontFamily:i});return Bc({x:e.x+e.width/2,y:e.y+e.height/2,strokeColor:e.strokeColor!=="transparent"?e.strokeColor:"black",backgroundColor:"transparent",fontFamily:i,fontSize:n,text:Pt(t,o,e.width-20),textAlign:"center",verticalAlign:vh.MIDDLE,angle:e.angle??0})},ss=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(rs.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return rs.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},jP=e=>{let t=e.match(kh);if(t&&t.length===2)return t[1];let n=e.match(Nh);if(n&&n.length===2)return n[1];let i=e.match(Gh);if(i&&i.length===2)return i[1];if(Rc.test(e))return`https://giphy.com/embed/${Rc.exec(e)[1]}`;let o=e.match(Fh);return o&&o.length===2?o[1]:e},VP=(e,t)=>{if(!e)return!1;if(t!=null)if(typeof t=="function"){let n=t(e);if(typeof n=="boolean")return n}else{if(typeof t=="boolean")return t;if(t instanceof RegExp)return t.test(e);if(Array.isArray(t)){for(let n of t)if(n instanceof RegExp){if(e.match(n))return!0}else if(ss(e,n))return!0;return!1}}return!!ss(e,rs)};P();import{KEYS as To,invariant as Ao,toBrandedType as zh}from"@excalidraw/common";import{pointFrom as zc}from"@excalidraw/math";var Nn=100,En=100,aI=e=>{switch(e){case To.ARROW_UP:return"up";case To.ARROW_DOWN:return"down";case To.ARROW_RIGHT:return"right";case To.ARROW_LEFT:return"left";default:return"right"}},Yc=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(G(s)&&(a=s[e==="predecessors"?"startBinding":"endBinding"])&&s[e==="predecessors"?"endBinding":"startBinding"]?.elementId===t.id){let l=n.get(a.elementId);if(!l)return r;Ao(Le(l),"not an ExcalidrawBindableElement");let c=e==="predecessors"?s.points[s.points.length-1]:[0,0],d=ti(t,Ve(t,n),[c[0]+s.x,c[1]+s.y]);r.push({relative:l,heading:d})}return r},[]);switch(i){case"up":return o.filter(r=>ue(r.heading,He)).map(r=>r.relative);case"down":return o.filter(r=>ue(r.heading,we)).map(r=>r.relative);case"right":return o.filter(r=>ue(r.heading,pe)).map(r=>r.relative);case"left":return o.filter(r=>ue(r.heading,Oe)).map(r=>r.relative)}},as=(e,t,n)=>Yc("successors",e,t,n),ls=(e,t,n)=>Yc("predecessors",e,t,n),Hh=(e,t,n)=>{let i=En+e.width;if(n==="up"||n==="down"){let a=Nn+e.height,l=e.x,c=e.x+e.width;if(t.every(d=>d.x+d.width<l||d.x>c))return{x:0,y:a*(n==="up"?-1:1)}}else if(n==="right"||n==="left"){let a=e.y,l=e.y+e.height;if(t.every(c=>c.y+c.height<a||c.y>l))return{x:(En+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Nn+e.height,l=(t.length===0,a),c=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*i:t.length/2*i*-1;return n==="up"?{x:c,y:l*-1}:{x:c,y:l}}let o=Nn+e.height,r=(t.length===0,En+e.width),s=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*o:t.length/2*o*-1;return n==="left"?{x:r*-1,y:s}:{x:r,y:s}},_h=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=as(e,o,n),s=ls(e,o,n),a=Hh(e,[...r,...s],n),l=ns({type:e.type,x:e.x+a.x,y:e.y+a.y,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});Ao(Jo(l),"not an ExcalidrawFlowchartNodeElement");let c=Xc(e,l,n,t,i);return{nextNode:l,bindingArrow:c}},Yh=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=Nn*(o-1)+o*e.height,p=e.y+e.height/2-u/2,m=En+e.width;n==="left"&&(m*=-1),a=e.x+m;let f=(Nn+e.height)*s;l=p+f}else{let u=En*(o-1)+o*e.width,p=e.x+e.width/2-u/2,m=Nn+e.height;n==="up"&&(m*=-1),l=e.y+m;let f=(En+e.width)*s;a=p+f}let c=ns({type:e.type,x:a,y:l,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});Ao(Jo(c),"not an ExcalidrawFlowchartNodeElement");let d=Xc(e,c,n,t,i);r.push(c),r.push(d)}return r},Xc=(e,t,n,i,o)=>{let r,s;switch(n){case"up":{r=e.x+e.width/2,s=e.y-6;break}case"down":{r=e.x+e.width/2,s=e.y+e.height+6;break}case"right":{r=e.x+e.width+6,s=e.y+e.height/2;break}case"left":{r=e.x-6,s=e.y+e.height/2;break}}let l,c;switch(n){case"up":{l=t.x+t.width/2-r,c=t.y+t.height-s+6;break}case"down":{l=t.x+t.width/2-r,c=t.y-s-6;break}case"right":{l=t.x-r-6,c=t.y-s+t.height/2;break}case"left":{l=t.x+t.width-r+6,c=t.y-s+t.height/2;break}}let d=Gc({type:"arrow",x:r,y:s,startArrowhead:null,endArrowhead:i.currentItemEndArrowhead,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeWidth:e.strokeWidth,opacity:e.opacity,roughness:e.roughness,points:[zc(0,0),zc(l,c)],elbowed:!0}),u=o.getNonDeletedElementsMap();pn(d,e,"start",o),pn(d,t,"end",o);let p=new Map;p.set(e.id,e),p.set(t.id,t),p.set(d.id,d),Y.movePoints(d,o,new Map([[1,{point:d.points[1]}]]));let m=Tn(d,zh(new Map([...u.entries(),[e.id,e],[t.id,t],[d.id,d]])),{points:d.points});return{...d,...m}},Hc=class{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!Le(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...as(t,n,i),...ls(t,n,i)];if(o.length>0)return this.sameLevelIndex=0,this.isExploring=!0,this.sameLevelNodes=o,this.direction=i,this.visitedNodes.add(o[0].id),o[0].id;if(i===this.direction||!this.isExploring){this.isExploring||this.visitedNodes.add(t.id);let s=["up","right","down","left"].filter(a=>a!==i).map(a=>[...as(t,n,a),...ls(t,n,a)]).flat().filter(a=>!this.visitedNodes.has(a.id));for(let a of s)if(!this.visitedNodes.has(a.id))return this.visitedNodes.add(a.id),this.isExploring=!0,this.direction=i,a.id}return null}},_c=class{isCreatingChart=!1;numberOfNodes=0;direction="right";pendingNodes=null;createNodes(t,n,i,o){let r=o.getNonDeletedElementsMap();if(i!==this.direction){let{nextNode:s,bindingArrow:a}=_h(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=Yh(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);Ao(s&&ki(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>Kt([a],s,r)||Zt(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>ye(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},lI=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{MIME_TYPES as Uc,SVG_NS as Xh}from"@excalidraw/common";var Uh=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),mI=async({fileIds:e,files:t,imageCache:n})=>{let i=new Map,o=new Map;return await Promise.all(e.reduce((r,s)=>{let a=t[s];return a&&!i.has(s)?(i.set(s,!0),r.concat((async()=>{try{if(a.mimeType===Uc.binary)throw new Error("Only images can be added to ImageCache");let l=Uh(a.dataURL),c={image:l,mimeType:a.mimeType};n.set(s,c);let d=await l;n.set(s,{...c,image:d})}catch{o.set(s,!0)}})())):r},[])),{imageCache:n,updatedFiles:i,erroredFiles:o}},fI=e=>e.filter(t=>zt(t)),Wh=e=>e?.nodeName.toLowerCase()==="svg",hI=e=>{let t=new DOMParser().parseFromString(e,Uc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Wh(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Xh);let o=n.getAttribute("width"),r=n.getAttribute("height");(o?.includes("%")||o==="auto")&&(o=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!o||!r){if(o=o||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,o,r]=a)}n.setAttribute("width",o),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${o} ${r}`),n.outerHTML}};P();import{pointCenter as jh,normalizeRadians as Do,pointFrom as re,pointRotateRads as it}from"@excalidraw/math";import{MIN_FONT_SIZE as ds,SHIFT_LOCKING_ANGLE as Lo,rescalePoints as Wc,getFontString as vo}from"@excalidraw/common";var vI=(e,t,n,i,o,r,s,a,l,c,d)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[p]=n;if(t==="rotation")G(p)||(Vh(p,i,a,l,o),Xe(p,i));else if(t){let m=n[0].id,f=u.get(m),E=e.get(m);if(f&&E){let{nextWidth:h,nextHeight:g}=Qh(f,E,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});Kh(h,g,f,E,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return ne(p)&&Xe(p,i),!0}else if(n.length>1){if(t==="rotation")return Zh(e,n,i,a,l,o,c,d),!0;if(t){let{nextWidth:p,nextHeight:m,flipByX:f,flipByY:E,originalBoundingBox:h}=Jh(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return eE(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:E,nextWidth:p,nextHeight:m,originalBoundingBox:h}),!0}}return!1},Vh=(e,t,n,i,o)=>{let[r,s,a,l]=H(e,t.getNonDeletedElementsMap()),c=(r+a)/2,d=(s+l)/2,u;V(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-d,n-c),o&&(u=u+Lo/2,u=u-u%Lo),u=Do(u));let p=It(e);if(t.mutateElement(e,{angle:u}),p){let m=t.getElement(p);m&&!_(e)&&t.mutateElement(m,{angle:u})}},jc=(e,t,n,i)=>U(e)||Se(e)?{points:Wc(0,t,Wc(1,n,e.points,i),i)}:{},us=(e,t,n)=>{let i=e.width;if(fe(e)){let s=Ce(e,t);s&&(i=Je(s,e))}let r=e.fontSize*(n/i);return r<ds?null:{size:r}},$h=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),c=us(t,a,l);if(c!==null){if(i.includes("n")||i.includes("s")){let d=re(e.x,e.y),u=cs(d,e.width,e.height,l,s,e.angle,i,!1,o);n.mutateElement(t,{fontSize:c.size,width:l,height:s,x:u.x,y:u.y});return}if(i==="e"||i==="w"){let d=Ni(vo({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(d,r),p=Pt(t.originalText,vo(t),Math.abs(u)),m=Qe(p,vo(t),t.lineHeight),f=m.height,E=re(e.x,e.y),h=cs(E,e.width,e.height,u,f,t.angle,i,!1,o),g={width:Math.abs(u),height:Math.abs(m.height),x:h.x,y:h.y,text:p,autoResize:!1};n.mutateElement(t,g)}}},Zh=(e,t,n,i,o,r,s,a)=>{let l=n.getNonDeletedElementsMap(),c=5*Math.PI/2+Math.atan2(o-a,i-s);r&&(c+=Lo/2,c-=c%Lo);for(let d of t)if(!V(d)){let[u,p,m,f]=H(d,l),E=(u+m)/2,h=(p+f)/2,g=e.get(d.id)?.angle??d.angle,[x,y]=it(re(E,h),re(s,a),c+g-d.angle),b=G(d)?{points:qa(d,l)}:{x:d.x+(x-E),y:d.y+(y-h),angle:Do(c+g)};n.mutateElement(d,b),Xe(d,n,{simultaneouslyUpdated:t});let w=Z(d,l);w&&!_(d)&&n.mutateElement(w,{x:w.x+(x-E),y:w.y+(y-h),angle:Do(c+g)})}n.triggerUpdate()},DI=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?H(t[0],n):tt(t),c=(r+a)/2,d=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=it(re(i,o),re(c,d),-u),e){case"n":return it(re(i-(r+a)/2,o-s),re(0,0),u);case"s":return it(re(i-(r+a)/2,o-l),re(0,0),u);case"w":return it(re(i-r,o-(s+l)/2),re(0,0),u);case"e":return it(re(i-a,o-(s+l)/2),re(0,0),u);case"nw":return it(re(i-r,o-s),re(0,0),u);case"ne":return it(re(i-a,o-s),re(0,0),u);case"sw":return it(re(i-r,o-l),re(0,0),u);case"se":return it(re(i-a,o-l),re(0,0),u);default:return[0,0]}},LI=(e,t)=>{let[,[n,i]]=t.points;return e==="nw"&&(n<0||i<0)||e==="ne"&&n>=0||e==="sw"&&n<=0||e==="se"&&(n>0||i>0)?"end":"origin"},qh=(e,t,n)=>{if(n)return"center";if(t)switch(e){case"n":return"south-side";case"e":return"west-side";case"s":return"north-side";case"w":return"east-side";case"ne":return"bottom-left";case"nw":return"bottom-right";case"se":return"top-left";case"sw":return"top-right"}return["e","se","s"].includes(e)?"top-left":["n","nw","w"].includes(e)?"bottom-right":e==="ne"?"bottom-left":"top-right"},cs=(e,t,n,i,o,r,s,a,l)=>{let c=qh(s,a,l),[d,u]=e;switch(c){case"top-left":return{x:d+(t-i)/2+(i-t)/2*Math.cos(r)+(n-o)/2*Math.sin(r),y:u+(n-o)/2+(i-t)/2*Math.sin(r)+(o-n)/2*Math.cos(r)};case"top-right":return{x:d+(t-i)/2*(Math.cos(r)+1)+(n-o)/2*Math.sin(r),y:u+(n-o)/2+(t-i)/2*Math.sin(r)+(o-n)/2*Math.cos(r)};case"bottom-left":return{x:d+(t-i)/2*(1-Math.cos(r))+(o-n)/2*Math.sin(r),y:u+(n-o)/2*(Math.cos(r)+1)+(i-t)/2*Math.sin(r)};case"bottom-right":return{x:d+(t-i)/2*(Math.cos(r)+1)+(o-n)/2*Math.sin(r),y:u+(n-o)/2*(Math.cos(r)+1)+(t-i)/2*Math.sin(r)};case"center":return{x:d-(i-t)/2,y:u-(o-n)/2};case"east-side":return{x:d+(t-i)/2*(Math.cos(r)+1),y:u+(t-i)/2*Math.sin(r)+(n-o)/2};case"west-side":return{x:d+(t-i)/2*(1-Math.cos(r)),y:u+(i-t)/2*Math.sin(r)+(n-o)/2};case"north-side":return{x:d+(t-i)/2+(n-o)/2*Math.sin(r),y:u+(o-n)/2*(Math.cos(r)-1)};case"south-side":return{x:d+(t-i)/2+(o-n)/2*Math.sin(r),y:u+(n-o)/2*(Math.cos(r)+1)}}},Kh=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:c=!1}={})=>{if(ne(n)&&ne(i))return $h(i,n,r,s,c,e,t);let d={},u=r.getNonDeletedElementsMap(),p=Z(n,u);if(p){let h=o.get(p.id);if(h&&(d={fontSize:h.fontSize}),l){let g={...n,width:e,height:t},x=us(p,u,Je(g,p));if(x===null)return;d={fontSize:x.size}}else{let g=pa(vo(p),p.lineHeight),x=ma(p.fontSize,p.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let m=jc(i,e,t,!0),f=re(i.x,i.y);if(U(i)){let[h,g]=he(i,o);f=re(h,g)}let E=cs(f,i.width,i.height,e,t,i.angle,s,l,c);if(U(i)&&m.points){let h=i.x-f[0],g=i.y-f[1];E.x+=h,E.y+=g;let x=m.points[0][0],y=m.points[0][1];E.x+=x,E.y+=y,m.points=m.points.map(b=>re(b[0]-x,b[1]-y))}if(e<0&&(E.x=E.x+e),t<0&&(E.y=E.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),_(n)&&p&&l){let h=e/n.width*p.fontSize;if(h<ds)return;d.fontSize=h}if(e!==0&&t!==0&&Number.isFinite(E.x)&&Number.isFinite(E.y)){let h={...E,width:Math.abs(e),height:Math.abs(t),...m};r.mutateElement(n,h,{informMutation:a,isDragging:!1}),p&&d!=null&&r.mutateElement(p,{fontSize:d.fontSize}),dn(n,r,s,l),Xe(n,r,{newSize:{width:e,height:t}})}},Qh=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,c,d]=Nt(t,t.width,t.height,!0),u=re(a,l),p=re(c,d),m=jh(u,p),f=it(re(i,o),m,-t.angle),[E,h,g,x]=Nt(e,e.width,e.height,!0),y=g-E,b=x-h,w=p[0]-u[0],I=p[1]-u[1],M=w/y,v=I/b;n.includes("e")&&(M=(f[0]-u[0])/y),n.includes("s")&&(v=(f[1]-u[1])/b),n.includes("w")&&(M=(p[0]-f[0])/y),n.includes("n")&&(v=(p[1]-f[1])/b);let T=e.width*M,F=e.height*v;if(s&&(T=2*T-t.width,F=2*F-t.height),r){let C=Math.abs(T)/t.width,R=Math.abs(F)/t.height;if(n.length===1&&(F*=C,T*=R),n.length===2){let L=Math.max(C,R);T=t.width*L*Math.sign(T),F=t.height*L*Math.sign(F)}}return{nextWidth:T,nextHeight:F}},Jh=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(L=>t.get(L.id)),c=l.reduce((L,W)=>{if(!U(W))return L;let N=It(W);if(!N)return L;let ee=t.get(N)??null;return fe(ee)?[...L,{...ee,...Y.getBoundTextElementPosition(W,ee,n)}]:L},[]),d=Ct(l.map(L=>L).concat(c)),{minX:u,minY:p,maxX:m,maxY:f,midX:E,midY:h}=d,g=m-u,x=f-p,y={ne:[u,f],se:[u,p],sw:[m,p],nw:[m,f],e:[u,p+x/2],w:[m,p+x/2],n:[u+g/2,f],s:[u+g/2,p]},[b,w]=a?[E,h]:y[i],I=a?2:1,M=Math.max(Math.abs(o-b)/g||0,Math.abs(r-w)/x||0)*I,v=i.includes("e")||i.includes("w")?Math.abs(o-b)*I:g,T=i.includes("n")||i.includes("s")?Math.abs(r-w)*I:x;s&&(v=g*M*Math.sign(o-b),T=x*M*Math.sign(r-w));let F={ne:[o<b,r>w],se:[o<b,r<w],sw:[o>b,r<w],nw:[o>b,r>w],e:[o<b,!1],w:[o>b,!1],n:[!1,r>w],s:[!1,r<w]},[C,R]=F[i].map(L=>L);return{originalBoundingBox:d,nextWidth:v,nextHeight:T,flipByX:C,flipByY:R}},eE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:c,nextWidth:d,originalBoundingBox:u}={})=>{if(d===void 0&&c===void 0&&a===void 0&&l===void 0||c===0||d===0)return;o||(o=t);let p=e.reduce((I,M)=>{let v=o.get(M.id);return v&&I.push({orig:v,latest:M}),I},[]),m;if(u)m=u;else{let I=p.reduce((M,{orig:v})=>{if(!U(v))return M;let T=It(v);if(!T)return M;let F=o.get(T)??null;return fe(F)?[...M,{...F,...Y.getBoundTextElementPosition(v,F,t)}]:M},[]);m=Ct(p.map(({orig:M})=>M).concat(I))}let{minX:f,minY:E,maxX:h,maxY:g,midX:x,midY:y}=m,b=h-f,w=g-E;if(d===void 0&&c===void 0&&(d=b,c=w),r&&(d===void 0?d=c*(b/w):c===void 0?c=d*(w/b):Math.abs(d/c-b/w)>.001&&(d=c*(b/w))),d&&c){let I=n.includes("e")||n.includes("w")?Math.abs(d)/b:1,M=n.includes("n")||n.includes("s")?Math.abs(c)/w:1,v;n.length===1?v=n.includes("e")||n.includes("w")?I:M:v=Math.max(Math.abs(d)/b||0,Math.abs(c)/w||0);let T={ne:[f,g],se:[f,E],sw:[h,E],nw:[h,g],e:[f,E+w/2],w:[h,E+w/2],n:[f+b/2,g],s:[f+b/2,E]},[F,C]=s?[x,y]:T[n],R=r||p.some(S=>S.latest.angle!==0||ne(S.latest)||gl(S.latest));R&&(I=v,M=v);let[L,W]=[a?-1:1,l?-1:1],N=[];for(let{orig:S,latest:K}of p){if(ne(S)&&fe(S))continue;let j=S.width*I,te=S.height*M,en=Do(S.angle*L*W),ot=U(S)||Se(S),gn=S.x-F,Go=S.y-C,pi=a&&!ot?j:0,zn=l&&!ot?te:0,Oo=F+L*(gn*I+pi),mi=C+W*(Go*M+zn),tn=jc(S,j*L,te*W,!1),ge={x:Oo,y:mi,width:j,height:te,angle:en,...tn};if(G(S)&&(S.startBinding&&(ge.startBinding={...S.startBinding,fixedPoint:[a?-S.startBinding.fixedPoint[0]+1:S.startBinding.fixedPoint[0],l?-S.startBinding.fixedPoint[1]+1:S.startBinding.fixedPoint[1]]}),S.endBinding&&(ge.endBinding={...S.endBinding,fixedPoint:[a?-S.endBinding.fixedPoint[0]+1:S.endBinding.fixedPoint[0],l?-S.endBinding.fixedPoint[1]+1:S.endBinding.fixedPoint[1]]}),S.fixedSegments&&tn.points&&(ge.fixedSegments=S.fixedSegments.map(ve=>({...ve,start:tn.points[ve.index-1],end:tn.points[ve.index]})))),xe(S)&&(ge.scale=[S.scale[0]*L,S.scale[1]*W]),ne(S)){let ve=us(S,t,j);if(!ve)return;ge.fontSize=ve.size}let nn=o.get(It(S)??"");if(nn)if(R){let ve=nn.fontSize*v;if(ve<ds)return;ge.boundTextFontSize=ve}else ge.boundTextFontSize=nn.fontSize;N.push({element:K,update:ge})}let ee=N.map(({element:S})=>S);for(let{element:S,update:{boundTextFontSize:K,...j}}of N){let{width:te,height:en,angle:ot}=j;i.mutateElement(S,j),Xe(S,i,{simultaneouslyUpdated:ee,newSize:{width:te,height:en}});let gn=Z(S,t);gn&&K&&(i.mutateElement(gn,{fontSize:K,angle:U(S)?void 0:ot}),dn(S,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as $e,pointOnLineSegment as Qc,pointRotateRads as Bo}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as gs}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as ms,isAndroid as tE,isIOS as nE}from"@excalidraw/common";import{pointFrom as Vc,pointRotateRads as iE}from"@excalidraw/math";var $c={mouse:8,pen:16,touch:28},oE=16,qc={e:!0,s:!0,n:!0,w:!0},FI={e:!0,s:!0,n:!0,w:!0},NI={e:!0,s:!0,n:!0,w:!0,rotation:!0},Zc={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},ps={e:!0,s:!0,n:!0,w:!0},Ot=(e,t,n,i,o,r,s)=>{let[a,l]=iE(Vc(e+n/2,t+i/2),Vc(o,r),s);return[a-n/2,l-i/2,n,i]},Co=e=>!(e.viewport.isMobile||e.isTouchScreen&&(tE||nE)),fs=e=>Co(e)?qc:{},hs=([e,t,n,i,o,r],s,a,l,c={},d=4,u=ms)=>{let p=$c[l],m=p/a.value,f=p/a.value,E=p/a.value,h=p/a.value,g=n-e,x=i-t,y=d/a.value,b=(p-u*2)/(2*a.value),w={nw:c.nw?void 0:Ot(e-y-E+b,t-y-h+b,m,f,o,r,s),ne:c.ne?void 0:Ot(n+y-b,t-y-h+b,m,f,o,r,s),sw:c.sw?void 0:Ot(e-y-E+b,i+y-b,m,f,o,r,s),se:c.se?void 0:Ot(n+y-b,i+y-b,m,f,o,r,s),rotation:c.rotation?void 0:Ot(e+g/2-m/2,t-y-h+b-oE/a.value,m,f,o,r,s)},I=5*$c.mouse/a.value;return Math.abs(g)>I&&(c.n||(w.n=Ot(e+g/2-m/2,t-y-h+b,m,f,o,r,s)),c.s||(w.s=Ot(e+g/2-m/2,i+y-b,m,f,o,r,s))),Math.abs(x)>I&&(c.w||(w.w=Ot(e-y-E+b,t+x/2-f/2,m,f,o,r,s)),c.e||(w.e=Ot(n+y-b,t+x/2-f/2,m,f,o,r,s))),w},Kc=(e,t,n,i="mouse",o=qc)=>{if(e.locked||G(e))return{};if(e.type==="freedraw"||U(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=ps:s[0]>0&&s[1]<0?o=Zc:s[0]>0&&s[1]>0?o=ps:s[0]<0&&s[1]>0?o=Zc:s[0]<0&&s[1]<0&&(o=ps)}}else V(e)&&(o={...o,rotation:!0});let r=U(e)?ms+8:xe(e)?0:ms;return hs(H(e,n,!0),e.angle,t,i,o,r,xe(e)?0:void 0)},zI=(e,t)=>{if(t.editingLinearElement)return!1;if(e.length>1)return!0;let n=e[0];return G(n)?!1:U(n)?n.points.length>2:!0};var xs=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],rE=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...c}=Kc(e,r,t,s,fs(a));if(l&&xs(l,i,o))return"rotation";let d=Object.keys(c).filter(u=>{let p=c[u];return p?xs(p,i,o):!1});if(d.length>0)return d[0];if(Co(a)){let[u,p,m,f,E,h]=H(e,t);if(!(U(e)&&e.points.length<=2)){let g=xe(e)?0:gs/r.value,x=gs/r.value,y=Jc($e(u-g,p-g),$e(m+g,f+g),$e(E,h),e.angle);for(let[b,w]of Object.entries(y))if(Qc($e(i,o),w,x))return b}}return!1},VI=(e,t,n,i,o,r,s,a)=>e.reduce((l,c)=>{if(l)return l;let d=rE(c,s,t,n,i,o,r,a);return d?{element:c,transformHandleType:d}:null},null),$I=([e,t,n,i],o,r,s,a,l)=>{let c=hs([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,fs(l)),d=Object.keys(c).find(u=>{let p=c[u];return p&&xs(p,o,r)});if(d)return d;if(Co(l)){let u=(e+n)/2,p=(t+i)/2,m=gs/s.value,f=Jc($e(e-m,t-m),$e(n+m,i+m),$e(u,p),0);for(let[E,h]of Object.entries(f))if(Qc($e(o,r),h,m))return E}return!1},Es=["ns","nesw","ew","nwse"],sE=(e,t)=>{let n=Es.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=Es[(n+i)%Es.length]}return e},ZI=e=>{let{element:t,transformHandleType:n}=e,i=t&&Math.sign(t.height)*Math.sign(t.width)===-1,o=null;switch(n){case"n":case"s":o="ns";break;case"w":case"e":o="ew";break;case"nw":case"se":i?o="nesw":o="nwse";break;case"ne":case"sw":i?o="nwse":o="nesw";break;case"rotation":return"grab"}return o&&t&&(o=sE(o,t.angle)),o?`${o}-resize`:""},Jc=([e,t],[n,i],o,r)=>{let s=Bo($e(e,t),o,r),a=Bo($e(n,t),o,r),l=Bo($e(e,i),o,r),c=Bo($e(n,i),o,r);return{n:[s,a],e:[a,c],s:[c,l],w:[l,s]}};P();var JI=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||pt(t,e).length));P();import{arrayToMap as td,findIndex as nd,findLastIndex as id}from"@excalidraw/common";var ws=(e,t)=>e.frameId===t||e.id===t,od=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=td(n||pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(o.length&&(i=i.concat(o),o=[]),i.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,o.push(s)):o=[]}return i},aE=e=>{let t=0;return e.reduce((n,i,o)=>(o>0&&e[o-1]!==i-1&&(t=++t),(n[t]||(n[t]=[])).push(i),n),[])},ed=(e,t,n,i)=>{if("containerId"in e&&e.containerId){let o=i.getElement(e.containerId);if(o)return n==="left"?Math.min(t.indexOf(o),t.indexOf(e)):Math.max(t.indexOf(o),t.indexOf(e))}else{let o=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(o){let r=i.getElement(o);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},lE=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{ws(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},cE=(e,t,n,i,o,r)=>{let s=t[n],a=p=>p.isDeleted?!1:o?p.frameId===o:e.editingGroupId?p.groupIds.includes(e.editingGroupId):!0,l=i==="left"?id(t,p=>a(p),Math.max(0,n-1)):nd(t,p=>a(p),n+1),c=t[l];if(!c)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===c?.groupIds.join(""))return ed(c,t,i,r)??l;if(!c?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(c.frameId||V(c))){let p=lE(t,c.frameId||c.id);return i==="left"?t.indexOf(p[0]):t.indexOf(p[p.length-1])}if(!c.groupIds.length)return ed(c,t,i,r)??l;let d=e.editingGroupId?c.groupIds[c.groupIds.indexOf(e.editingGroupId)-1]:c.groupIds[c.groupIds.length-1],u=Ae(t,d);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},rd=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),sd=(e,t,n,i)=>{let o=od(e,t),r=rd(e,o),s=aE(o);n==="right"&&(s=s.reverse());let a=new Set(o.filter(l=>V(e[l])).map(l=>e[l].id));return s.forEach((l,c)=>{let d=l[0],u=l[l.length-1],p=n==="left"?d:u,m=l.some(y=>{let b=e[y];return b.frameId&&a.has(b.frameId)})?null:e[p]?.frameId,f=cE(t,e,p,n,m,i);if(f===-1||p===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,d),h=e.slice(d,u+1),g=n==="left"?e.slice(f,d):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...E,...h,...g,...x]:[...E,...g,...h,...x]}),ui(e,r),e},ad=(e,t,n,i,o)=>{let r=od(e,t,o),s=rd(e,r),a=[],l,c;if(n==="left"){if(i)l=nd(e,f=>ws(f,i));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;c=r[r.length-1]}else{if(i)c=id(e,f=>ws(f,i));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;c=e.indexOf(f[f.length-1])}else c=e.length-1;l=r[0]}l===-1&&(l=0);for(let f=l;f<c+1;f++)r.includes(f)||a.push(e[f]);let d=Array.from(s.values()),u=e.slice(0,l),p=e.slice(c+1),m=n==="left"?[...u,...d,...a,...p]:[...u,...a,...d,...p];return ui(m,s),m};function ld(e,t,n,i){let o=td(pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let c of e)o.has(c.id)&&V(c)&&s.add(c.id);for(let c of e)if(o.has(c.id))if(V(c)||c.frameId&&s.has(c.frameId))r.regularElements.push(c);else if(!c.frameId)r.regularElements.push(c);else{let d=r.frameChildren.get(c.frameId)||[];d.push(c),r.frameChildren.set(c.frameId,d)}let a=e,l=Array.from(r.frameChildren.entries());for(let[c,d]of l)a=i(e,t,n,c,d);return i(a,t,n,null,r.regularElements)}var aS=(e,t,n)=>sd(e,t,"left",n),lS=(e,t,n)=>sd(e,t,"right",n),cS=(e,t)=>ld(e,t,"left",ad),dS=(e,t)=>ld(e,t,"right",ad);var ES=e=>e.reduce((t,n)=>t+n.version,0),oc=e=>{let t=5381;for(let n of dE(e))t=(t<<5)+t+n.versionNonce;return t>>>0},rc=e=>{let t=5381;for(let n=0;n<e.length;n++){let i=e.charCodeAt(n);t=(t<<5)+t+i}return t>>>0},gS=e=>e.filter(t=>!t.isDeleted&&!ql(t)),uE=e=>e.filter(t=>!t.isDeleted),xS=e=>!e.isDeleted,ys=e=>uE(e).map(t=>Ko(t.type)?{...t,lastCommittedPoint:null}:t),wS=e=>ys(e),yS=e=>ys(e),bS=e=>ys(e);export{mn as AppStateDelta,J as BASE_PADDING,kp as BINDING_HIGHLIGHT_THICKNESS,$t as BindableElement,Vt as BoundElement,Fe as CaptureUpdateAction,Ub as DEFAULT_LINK_SIZE,qc as DEFAULT_OMIT_SIDES,ie as Delta,Zr as DurableIncrement,Xr as ElementBounds,fn as ElementsDelta,qr as EphemeralIncrement,oe as FIXED_BINDING_DISTANCE,_c as FlowChartCreator,Hc as FlowChartNavigator,we as HEADING_DOWN,Oe as HEADING_LEFT,pe as HEADING_RIGHT,He as HEADING_UP,Hm as IMAGE_INVERT_FILTER,ff as INVISIBLY_SMALL_ELEMENT_SIZE,Qr as InvalidFractionalIndexError,Y as LinearElementEditor,Ie as MINIMAL_CROP_SIZE,NI as OMIT_SIDES_FOR_FRAME,FI as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Io as Scene,be as ShapeCache,ec as Store,ci as StoreChange,Kr as StoreDelta,wo as StoreIncrement,hn as StoreSnapshot,Ve as aabbForElement,vm as addElementsToFrame,Yh as addNewNodes,_y as addToGroup,$0 as alignElements,$p as avoidRectangularCorner,bl as bindElementsToFramesAfterDuplication,pn as bindLinearElement,Tr as bindOrUnbindLinearElement,zp as bindOrUnbindLinearElements,Pr as bindPointToSnapToElementOutline,no as bindingBorderTest,Za as bindingProperties,ka as bumpVersion,ja as calculateFixedPointForElbowArrowBinding,Ix as canApplyRoundnessTypeToElement,la as canBecomePolygon,kl as canChangeRoundness,hh as canCreateLinkFromElements,e0 as canHaveArrowheads,Co as canResizeFromSides,Pn as charWidth,wS as clearElementsForDatabase,yS as clearElementsForExport,bS as clearElementsForLocalStorage,ue as compareHeading,xa as computeBoundTextPosition,sr as computeContainerDimensionForBoundText,Yx as containsCJK,WP as createPlaceholderEmbeddableLabel,os as createSrcDoc,ax as cropElement,bn as deconstructDiamondElement,Ci as deconstructLinearOrFreeDrawElement,yn as deconstructRectanguloidElement,$r as deepCopyElement,gP as defaultGetElementLinkFromSelection,kx as detectLineHeight,_t as distanceToElement,eP as distributeElements,un as doBoundsIntersect,pP as dragNewElement,dP as dragSelectedElements,Sf as duplicateElement,l1 as duplicateElements,zy as editGroupForSelectedElement,me as elementCenterPoint,Zt as elementOverlapsWithFrame,Eo as elementWithCanvasCache,Kt as elementsAreInFrameBounds,El as elementsAreInSameGroup,VP as embeddableURLValidator,wl as excludeElementsInFramesFromSelection,Pb as filterElementsEligibleAsFrameChildren,ly as fixBindingsAfterDeletion,$a as fixDuplicatedBindingsAfterDuplication,pr as flipHeading,vb as frameAndChildrenSelectedTogether,Ol as generateFreeDrawShape,ta as generateLinearCollisionShape,Re as generateRoughOptions,ma as getApproxMinLineHeight,pa as getApproxMinLineWidth,qa as getArrowLocalFixedPoints,lf as getArrowheadAngle,Hr as getArrowheadPoints,af as getArrowheadSize,Z as getBoundTextElement,It as getBoundTextElementId,Jx as getBoundTextElementPosition,ei as getBoundTextMaxHeight,Je as getBoundTextMaxWidth,Ur as getBoundsFromPoints,ct as getCenterForBounds,B0 as getClosestElementBounds,Ct as getCommonBoundingBox,tt as getCommonBounds,Kx as getContainerCenter,ar as getContainerCoords,Ce as getContainerElement,Dt as getContainingFrame,yt as getCornerRadius,Wi as getCubicBezierCurveBound,ZI as getCursorForResizingElement,Gm as getDefaultFrameName,Sx as getDefaultRoundnessTypeForElement,Bi as getDiamondPoints,uP as getDragOffsetXY,C0 as getDraggedElementsBounds,H as getElementAbsoluteCoords,he as getElementBounds,Rr as getElementLineSegments,Lr as getElementPointsCoords,_l as getElementShape,VI as getElementWithTransformHandleType,Pl as getElementsCompletelyInFrame,Ae as getElementsInGroup,bb as getElementsInNewFrame,yb as getElementsInResizingFrame,fb as getElementsIntersectingFrame,Ab as getElementsOverlappingFrame,Or as getElementsWithinSelection,UP as getEmbedLink,lx as getFlipAdjustedCropPosition,qt as getFrameChildren,Tm as getFrameLikeElements,Tb as getFrameLikeTitle,Um as getFreeDrawPath2D,Wm as getFreeDrawSvgPath,eo as getGlobalFixedPointForBindableElement,Jp as getGlobalFixedPoints,Oa as getHeadingForElbowArrowSnap,Wt as getHoveredElementForBinding,fI as getInitializedImageElements,zi as getLineHeightInPx,Ht as getLineWidth,Tx as getLinearElementSubType,aI as getLinkDirectionFromKey,xP as getLinkIdAndTypeFromSelection,il as getLockedLinearCursorAlignSize,wu as getMaxCharWidth,uo as getMaximumGroups,Fx as getMinCharWidth,si as getMinMaxXYFromCurvePathOps,Ni as getMinTextElementWidth,xl as getNewGroupIdsForDuplication,uE as getNonDeletedElements,hl as getNonDeletedGroupIds,Y0 as getNormalizedDimensions,Gn as getObservedAppState,fs as getOmitSidesForDevice,Lx as getOriginalContainerHeightFromCache,Wr as getPerfectElementSize,ls as getPredecessors,L0 as getRectangleBoxAbsoluteCoords,_m as getRenderOpacity,LI as getResizeArrowDirection,DI as getResizeOffsetXY,Nt as getResizedElementAbsoluteCoords,wb as getRootElements,ES as getSceneVersion,pt as getSelectedElements,Gr as getSelectedGroupForElement,Hy as getSelectedGroupIdForElement,Ny as getSelectedGroupIds,tb as getSelectionStateForElements,ry as getSuggestedBindingsForArrows,eb as getTargetElements,Lm as getTargetFrame,Qx as getTextElementAngle,iw as getTextFromElements,xu as getTextHeight,fa as getTextWidth,$I as getTransformHandleTypeFromCoords,Kc as getTransformHandles,hs as getTransformHandlesFromCoords,Qs as getUncroppedImageElement,jo as getUncroppedWidthAndHeight,Qy as getVisibleAndNonSelectedElements,gS as getVisibleElements,G0 as getVisibleSceneBounds,xb as groupByFrameLikes,Eb as groupsAreAtLeastIntersectingTheFrame,gb as groupsAreCompletelyOutOfFrame,dn as handleBindTextResize,Zb as hasBackground,st as hasBoundTextElement,qb as hasStrokeColor,Qb as hasStrokeStyle,Kb as hasStrokeWidth,oc as hashElementsVersion,rc as hashString,Ge as headingForPoint,ti as headingForPointFromElement,et as headingForPointIsHorizontal,ke as headingIsHorizontal,vw as headingIsVertical,ep as hitElementBoundText,Ju as hitElementBoundingBox,Pw as hitElementBoundingBoxOnly,Qu as hitElementItself,In as intersectElementWithLineSegment,Px as isArrowBoundToElement,_ as isArrowElement,Le as isBindableElement,Qo as isBindingElement,uu as isBindingElementType,Mr as isBindingEnabled,fe as isBoundToContainer,Mx as isBounds,hb as isCursorInFrame,du as isCurvedArrow,G as isElbowArrow,_0 as isElementCompletelyInViewport,Fr as isElementContainingFrame,Sl as isElementInFrame,bm as isElementInGroup,yl as isElementInViewport,Cn as isElementIntersectingFrame,wP as isElementLink,ia as isEmbeddableElement,bx as isExcalidrawElement,Qn as isFixedPointBinding,Jo as isFlowchartNodeElement,ki as isFrameElement,V as isFrameLikeElement,Se as isFreeDrawElement,lu as isFreeDrawElementType,Wh as isHTMLSVGElement,Gi as isIframeElement,Oi as isIframeLikeElement,xe as isImageElement,gl as isInGroup,zt as isInitializedImageElement,ql as isInvisiblySmallElement,ln as isLineElement,U as isLinearElement,Ua as isLinearElementSimpleAndAlreadyBound,Ko as isLinearElementType,oa as isMagicFrameElement,Ox as isMeasureTextSupported,lI as isNodeInFlowchart,xS as isNonDeletedElement,an as isPathALoop,Sa as isPointInElement,yx as isRectangularElement,ra as isRectanguloidElement,Fy as isSelectedViaGroup,cu as isSharpArrow,wx as isSimpleArrow,Jy as isSomeElementSelected,pu as isTextBindableContainer,ne as isTextElement,sa as isUsingAdaptiveRadius,aa as isUsingProportionalRadius,Ax as isValidPolygon,nw as isValidTextContainer,Uh as loadHTMLImageElement,Br as makeNextSelectedElementIds,so as maxBindingGap,sy as maybeBindLinearElement,jP as maybeParseEmbedSrc,Ya as maybeSuggestBindingsForLinearElementAtCoords,us as measureFontSizeFromWidth,Qe as measureText,cS as moveAllLeft,dS as moveAllRight,aS as moveOneLeft,lS as moveOneRight,ye as mutateElement,Gc as newArrowElement,ns as newElement,Me as newElementWith,LP as newEmbeddableElement,BP as newFrameElement,kP as newFreeDrawElement,CP as newIframeElement,FP as newImageElement,RP as newLinearElement,GP as newMagicFrameElement,Bc as newTextElement,Kl as normalizeElementOrder,Ar as normalizeFixedPoint,hI as normalizeSVG,tr as normalizeText,po as omitGroupsContainingFrameLikes,Am as omitPartialGroups,pc as orderByFractionalIndex,Jn as originalContainerCache,yP as parseElementLinkFromURL,Tu as parseTokens,Gl as pathsCache,Mn as pointInsideBounds,ga as redrawTextBoundingBox,OP as refreshTextDimensions,Dm as removeAllElementsFromFrame,Il as removeElementsFromFrame,Yy as removeFromSelectedGroups,jb as renderElement,Wb as renderSelectionElement,Ib as replaceAllElementsInFrame,jc as rescalePointsInElement,da as resetOriginalContainerCache,eE as resizeMultipleElements,Kh as resizeSingleElement,$h as resizeSingleTextElement,rE as resizeTest,ym as selectGroup,ml as selectGroupsForSelectedElements,fl as selectGroupsFromGivenElements,Rx as setCustomTextMetricsProvider,ew as shouldAllowVerticalAlign,Mb as shouldApplyFrameClip,oy as shouldEnableBindingForPointerEvent,zI as shouldShowBoundingBox,Ui as shouldTestInside,JI as showSelectedShapeActions,Zp as snapToMid,tw as suppportsHorizontalAlign,Of as syncInvalidIndices,ic as syncInvalidIndicesImmutable,ui as syncMovedIndices,nl as toggleLinePolygonState,Jb as toolIsArrow,vI as transformElements,ay as updateBindings,Xe as updateBoundElements,Tn as updateElbowArrowPoints,Sb as updateFrameMembershipOfSelectedElements,mI as updateImageCache,ca as updateOriginalContainerCache,Ga as validateElbowPoints,Gf as validateFractionalIndices,Mt as vectorToHeading,Pt as wrapText};
28
+ `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return ht.set(e,p),p}return ht.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},KI=e=>{let t;lo(e)?t="IFrame element":t=!e.link||e?.link===""?"Empty Web-Embed":e.link;let n=Math.max(Math.min(e.width/2,e.width/t.length),e.width/30),i=IE.Helvetica,o=AE({fontSize:n,fontFamily:i});return Hn({x:e.x+e.width/2,y:e.y+e.height/2,strokeColor:e.strokeColor!=="transparent"?e.strokeColor:"black",backgroundColor:"transparent",fontFamily:i,fontSize:n,text:zt(t,o,e.width-20),textAlign:"center",verticalAlign:SE.MIDDLE,angle:e.angle??0})},Us=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(_s.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return _s.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},QI=e=>{let t=e.match(LE);if(t&&t.length===2)return t[1];let n=e.match(OE);if(n&&n.length===2)return n[1];let i=e.match(DE);if(i&&i.length===2)return i[1];if(Mc.test(e))return`https://giphy.com/embed/${Mc.exec(e)[1]}`;let o=e.match(GE);return o&&o.length===2?o[1]:e},JI=(e,t)=>{if(!e)return!1;if(t!=null)if(typeof t=="function"){let n=t(e);if(typeof n=="boolean")return n}else{if(typeof t=="boolean")return t;if(t instanceof RegExp)return t.test(e);if(Array.isArray(t)){for(let n of t)if(n instanceof RegExp){if(e.match(n))return!0}else if(Us(e,n))return!0;return!1}}return!!Us(e,_s)};P();import{KEYS as er,invariant as tr,toBrandedType as FE}from"@excalidraw/common";import{pointFrom as Bc}from"@excalidraw/math";var ii=100,_n=100,pS=e=>{switch(e){case er.ARROW_UP:return"up";case er.ARROW_DOWN:return"down";case er.ARROW_RIGHT:return"right";case er.ARROW_LEFT:return"left";default:return"right"}},Gc=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(U(s)&&(a=s[e==="predecessors"?"startBinding":"endBinding"])&&s[e==="predecessors"?"endBinding":"startBinding"]?.elementId===t.id){let l=n.get(a.elementId);if(!l)return r;tr(ce(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=Si(t,it(t,n),[d[0]+s.x,d[1]+s.y]);r.push({relative:l,heading:c})}return r},[]);switch(i){case"up":return o.filter(r=>pe(r.heading,qe)).map(r=>r.relative);case"down":return o.filter(r=>pe(r.heading,ye)).map(r=>r.relative);case"right":return o.filter(r=>pe(r.heading,fe)).map(r=>r.relative);case"left":return o.filter(r=>pe(r.heading,He)).map(r=>r.relative)}},Ws=(e,t,n)=>Gc("successors",e,t,n),js=(e,t,n)=>Gc("predecessors",e,t,n),RE=(e,t,n)=>{let i=_n+e.width;if(n==="up"||n==="down"){let a=ii+e.height,l=e.x,d=e.x+e.width;if(t.every(c=>c.x+c.width<l||c.x>d))return{x:0,y:a*(n==="up"?-1:1)}}else if(n==="right"||n==="left"){let a=e.y,l=e.y+e.height;if(t.every(d=>d.y+d.height<a||d.y>l))return{x:(_n+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=ii+e.height,l=(t.length===0,a),d=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*i:t.length/2*i*-1;return n==="up"?{x:d,y:l*-1}:{x:d,y:l}}let o=ii+e.height,r=(t.length===0,_n+e.width),s=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*o:t.length/2*o*-1;return n==="left"?{x:r*-1,y:s}:{x:r,y:s}},NE=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=Ws(e,o,n),s=js(e,o,n),a=RE(e,[...r,...s],n),l=zn({type:e.type,x:e.x+a.x,y:e.y+a.y,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});tr(Sr(l),"not an ExcalidrawFlowchartNodeElement");let d=Oc(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},zE=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=ii*(o-1)+o*e.height,m=e.y+e.height/2-u/2,p=_n+e.width;n==="left"&&(p*=-1),a=e.x+p;let f=(ii+e.height)*s;l=m+f}else{let u=_n*(o-1)+o*e.width,m=e.x+e.width/2-u/2,p=ii+e.height;n==="up"&&(p*=-1),l=e.y+p;let f=(_n+e.width)*s;a=m+f}let d=zn({type:e.type,x:a,y:l,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});tr(Sr(d),"not an ExcalidrawFlowchartNodeElement");let c=Oc(e,d,n,t,i);r.push(d),r.push(c)}return r},Oc=(e,t,n,i,o)=>{let r,s;switch(n){case"up":{r=e.x+e.width/2,s=e.y-6;break}case"down":{r=e.x+e.width/2,s=e.y+e.height+6;break}case"right":{r=e.x+e.width+6,s=e.y+e.height/2;break}case"left":{r=e.x-6,s=e.y+e.height/2;break}}let l,d;switch(n){case"up":{l=t.x+t.width/2-r,d=t.y+t.height-s+6;break}case"down":{l=t.x+t.width/2-r,d=t.y-s-6;break}case"right":{l=t.x-r-6,d=t.y-s+t.height/2;break}case"left":{l=t.x+t.width-r+6,d=t.y-s+t.height/2;break}}let c=Jo({type:"arrow",x:r,y:s,startArrowhead:null,endArrowhead:i.currentItemEndArrowhead,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeWidth:e.strokeWidth,opacity:e.opacity,roughness:e.roughness,points:[Bc(0,0),Bc(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();Mt(c,e,"orbit","start",o),Mt(c,t,"orbit","end",o);let m=new Map;m.set(e.id,e),m.set(t.id,t),m.set(c.id,c),G.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=$n(c,FE(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p}},Lc=class{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!ce(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...Ws(t,n,i),...js(t,n,i)];if(o.length>0)return this.sameLevelIndex=0,this.isExploring=!0,this.sameLevelNodes=o,this.direction=i,this.visitedNodes.add(o[0].id),o[0].id;if(i===this.direction||!this.isExploring){this.isExploring||this.visitedNodes.add(t.id);let s=["up","right","down","left"].filter(a=>a!==i).map(a=>[...Ws(t,n,a),...js(t,n,a)]).flat().filter(a=>!this.visitedNodes.has(a.id));for(let a of s)if(!this.visitedNodes.has(a.id))return this.visitedNodes.add(a.id),this.isExploring=!0,this.direction=i,a.id}return null}},Cc=class{isCreatingChart=!1;numberOfNodes=0;direction="right";pendingNodes=null;createNodes(t,n,i,o){let r=o.getNonDeletedElementsMap();if(i!==this.direction){let{nextNode:s,bindingArrow:a}=NE(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=zE(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);tr(s&&uo(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>xn([a],s,r)||En(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>Pe(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},fS=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{pointDistance as oi,pointFrom as Xs}from"@excalidraw/math";import{invariant as Yc}from"@excalidraw/common";P();import{arrayToMap as Fc,findIndex as Rc,findLastIndex as Nc}from"@excalidraw/common";var Ys=(e,t)=>e.frameId===t||e.id===t,zc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Fc(n||Tt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(o.length&&(i=i.concat(o),o=[]),i.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,o.push(s)):o=[]}return i},HE=e=>{let t=0;return e.reduce((n,i,o)=>(o>0&&e[o-1]!==i-1&&(t=++t),(n[t]||(n[t]=[])).push(i),n),[])},kc=(e,t,n,i)=>{if("containerId"in e&&e.containerId){let o=i.getElement(e.containerId);if(o)return n==="left"?Math.min(t.indexOf(o),t.indexOf(e)):Math.max(t.indexOf(o),t.indexOf(e))}else{let o=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(o){let r=i.getElement(o);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},_E=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{Ys(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},Hc=(e,t,n,i,o,r)=>{let s=r||_t(e,n,i);if(!s)return n;let a=V(s,i),l=q(s)?Me(s,i):null,d=[s.id,a?.id,l?.id].filter(m=>!!m),c=n.findIndex(m=>d.includes(m.id)),u=n.findIndex(m=>m.id===t.id);if(u!==-1&&c!==-1&&u<c){let m=Array.from(n),p=m.splice(u,1)[0];m.splice(c,0,p),o.replaceAllElements(m)}return n},UE=(e,t,n,i,o,r)=>{let s=t[n],a=m=>m.isDeleted?!1:o?m.frameId===o:e.editingGroupId?m.groupIds.includes(e.editingGroupId):!0,l=i==="left"?Nc(t,m=>a(m),Math.max(0,n-1)):Rc(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return kc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||Z(d))){let m=_E(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return kc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Ge(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},_c=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Uc=(e,t,n,i)=>{let o=zc(e,t),r=_c(e,o),s=HE(o);n==="right"&&(s=s.reverse());let a=new Set(o.filter(l=>Z(e[l])).map(l=>e[l].id));return s.forEach((l,d)=>{let c=l[0],u=l[l.length-1],m=n==="left"?c:u,p=l.some(w=>{let b=e[w];return b.frameId&&a.has(b.frameId)})?null:e[m]?.frameId,f=UE(t,e,m,n,p,i);if(f===-1||m===f)return;let h=n==="left"?e.slice(0,f):e.slice(0,c),E=e.slice(c,u+1),g=n==="left"?e.slice(f,c):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...h,...E,...g,...x]:[...h,...g,...E,...x]}),Hi(e,r),e},Wc=(e,t,n,i,o)=>{let r=zc(e,t,o),s=_c(e,r),a=[],l,d;if(n==="left"){if(i)l=Rc(e,f=>Ys(f,i));else if(t.editingGroupId){let f=Ge(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;d=r[r.length-1]}else{if(i)d=Nc(e,f=>Ys(f,i));else if(t.editingGroupId){let f=Ge(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let c=Array.from(s.values()),u=e.slice(0,l),m=e.slice(d+1),p=n==="left"?[...u,...c,...a,...m]:[...u,...a,...c,...m];return Hi(p,s),p};function jc(e,t,n,i){let o=Fc(Tt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)o.has(d.id)&&Z(d)&&s.add(d.id);for(let d of e)if(o.has(d.id))if(Z(d)||d.frameId&&s.has(d.frameId))r.regularElements.push(d);else if(!d.frameId)r.regularElements.push(d);else{let c=r.frameChildren.get(d.frameId)||[];c.push(d),r.frameChildren.set(d.frameId,c)}let a=e,l=Array.from(r.frameChildren.entries());for(let[d,c]of l)a=i(e,t,n,d,c);return i(a,t,n,null,r.regularElements)}var SS=(e,t,n)=>Uc(e,t,"left",n),AS=(e,t,n)=>Uc(e,t,"right",n),MS=(e,t)=>jc(e,t,"left",Wc),TS=(e,t)=>jc(e,t,"right",Wc);var nr=(e,t,n,i,o,r,s=!1)=>{if(U(t)||!At(o)||t.points.length!==2)return!1;if(!s){let l=t.startBinding?.elementId===n.id?0:t.points.length-1,d=G.getPointAtIndexGlobalCoordinates(t,l,i);if(oi(e,d)<Di*1.5/o.zoom.value)return!1}let a=G.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return oi(e,a)>=Di*1.5/o.zoom.value&&bt({element:n,elementsMap:i,point:e,threshold:Be(n,t),overrideShouldTestInside:!0})},WE=(e,t,n,i,o,r,s)=>{let a=new Map,l=n?"startBinding":"endBinding",d=n?"endBinding":"startBinding",c=e[l],u=e[d];if(c&&t){let m=t&&u&&c.elementId===u.elementId;s||m?c={...c,mode:"inside"}:c={...c,mode:"orbit"};let p=n?0:e.points.length-1,f=pt(e,l,c,t,i,!0);f&&a.set(p,{point:f})}if(u&&u.mode==="orbit"){let m=i.get(u.elementId);if(m&&ce(m)&&At(r)){let p=t&&u.elementId===t.id;s||p?u={...u,mode:"inside"}:u={...u,mode:"orbit"};let f=n?e.points.length-1:0,h=pt(e,d,u,m,i);h&&a.set(f,{point:h})}}a.size>0&&G.movePoints(e,o,a,{[l]:c,[d]:u})},Xc=(e,t,n,i,o,r,s)=>{let a=G.getElement(e.elementId,t);if(!a||!Ae(a)||U(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,m=Xs(n.x-c,n.y-u),p=l?"startBinding":"endBinding",f=xl(m,a,i.getNonDeletedElements(),t,dt(o.zoom));if(f&&At(o)){a[p]&&f.id!==d?.elementId&&ve(a,e.draggedFocusPointBinding,i);let h=s&&a[p]?.mode==="orbit"?"inside":!s&&a[p]?.mode==="inside"?"orbit":null;(!a[p]||h)&&Mt(a,f,h||"orbit",e.draggedFocusPointBinding,i,m),i.mutateElement(a,{[p]:{...a[p],elementId:f.id,mode:h||a[p]?.mode||"orbit",...Vn(a,f,e.draggedFocusPointBinding,t,m)}})}else{let h=new Map,E=l?0:a.points.length-1;h.set(E,{point:G.createPointAt(a,t,m[0],m[1],r)}),G.movePoints(a,i,h),a[p]&&ve(a,l?"start":"end",i)}WE(a,f,l,t,i,o,s),f&&At(o)&&Hc(m,a,i.getElementsIncludingDeleted(),t,i,f)},RS=(e,t,n,i)=>{let o=Xs(t.origin.x,t.origin.y),r=Di*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&ce(s)&&!s.isDeleted){let a=Re(e.startBinding.fixedPoint,s,n);if(nr(a,e,s,n,i,"start")&&oi(o,a)<=r)return{hitFocusPoint:"start",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}if(e.endBinding?.elementId){let s=n.get(e.endBinding.elementId);if(s&&ce(s)&&!s.isDeleted){let a=Re(e.endBinding.fixedPoint,s,n);if(nr(a,e,s,n,i,"end")&&oi(o,a)<=r)return{hitFocusPoint:"end",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}return{hitFocusPoint:null,pointerOffset:{x:0,y:0}}},NS=(e,t)=>{Yc(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=G.getElement(e.elementId,t.getNonDeletedElementsMap());Yc(n,"Arrow must be in the scene");let i=e.draggedFocusPointBinding==="start"?"startBinding":"endBinding",o=e.draggedFocusPointBinding==="start"?"endBinding":"startBinding",r=n[i]?.elementId,s=n[o]?.elementId,a=r&&t.getNonDeletedElements().find(d=>d.id!==r&&d.id!==s&&ce(d)&&d.boundElements?.find(({id:c})=>c===n.id));a&&t.mutateElement(a,{boundElements:a.boundElements?.filter(({id:d})=>d!==n.id)});let l=r&&t.getNonDeletedElementsMap().get(r);l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]})},zS=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=Xs(t,n),a=Di*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&ce(l)&&!l.isDeleted){let d=Re(e.startBinding.fixedPoint,l,r);if(nr(d,e,l,r,o,"start")&&oi(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&ce(l)&&!l.isDeleted){let d=Re(e.endBinding.fixedPoint,l,r);if(nr(d,e,l,r,o,"end")&&oi(s,d)<=a)return"end"}}return null};P();import{MIME_TYPES as $c,SVG_NS as jE}from"@excalidraw/common";var YE=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),jS=async({fileIds:e,files:t,imageCache:n})=>{let i=new Map,o=new Map;return await Promise.all(e.reduce((r,s)=>{let a=t[s];return a&&!i.has(s)?(i.set(s,!0),r.concat((async()=>{try{if(a.mimeType===$c.binary)throw new Error("Only images can be added to ImageCache");let l=YE(a.dataURL),d={image:l,mimeType:a.mimeType};n.set(s,d);let c=await l;n.set(s,{...d,image:c})}catch{o.set(s,!0)}})())):r},[])),{imageCache:n,updatedFiles:i,erroredFiles:o}},YS=e=>e.filter(t=>Bn(t)),XE=e=>e?.nodeName.toLowerCase()==="svg",XS=e=>{let t=new DOMParser().parseFromString(e,$c.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!XE(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",jE);let o=n.getAttribute("width"),r=n.getAttribute("height");(o?.includes("%")||o==="auto")&&(o=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!o||!r){if(o=o||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,o,r]=a)}n.setAttribute("width",o),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${o} ${r}`),n.outerHTML}};P();var KS=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(p=>[p]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let p=0;p<s;p+=a)l.push(r.slice(p,p+a));let d=0,c=l.map(p=>{let f=0,h=0,E=p.map(g=>{let[x,w,b,y]=Oe(g);return{elements:g,bounds:[x,w,b,y],width:b-x,height:y-w}});return E.forEach((g,x)=>{f+=g.width,x<E.length-1&&(f+=i),g.height>h&&(h=g.height)}),d+=h,{unitBounds:E,width:f,maxHeight:h}}),u=d+Math.max(0,l.length-1)*i,m=n-u/2;return c.forEach(p=>{let{unitBounds:f,width:h,maxHeight:E}=p,g=t-h/2;f.forEach(x=>{let[w,b]=x.bounds,y=g-w,I=m-b;x.elements.forEach(M=>{o.push(Le(M,{x:M.x+y,y:M.y+I}))}),g+=x.width+i}),m+=E+i}),o};P();import{pointCenter as $E,normalizeRadians as or,pointFrom as ie,pointRotateRads as Et}from"@excalidraw/math";import{MIN_FONT_SIZE as Vs,SHIFT_LOCKING_ANGLE as rr,rescalePoints as Vc,getFontString as ir}from"@excalidraw/common";var cA=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[m]=n;if(t==="rotation")U(m)||(VE(m,i,a,l,o),De(m,i));else if(t){let p=n[0].id,f=u.get(p),h=e.get(p);if(f&&h){let{nextWidth:E,nextHeight:g}=JE(f,h,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});QE(E,g,f,h,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return q(m)&&De(m,i),!0}else if(n.length>1){if(t==="rotation")return qE(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:f,flipByY:h,originalBoundingBox:E}=eg(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return tg(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:h,nextWidth:m,nextHeight:p,originalBoundingBox:E}),!0}}return!1},VE=(e,t,n,i,o)=>{let[r,s,a,l]=$(e,t.getNonDeletedElementsMap()),d=(r+a)/2,c=(s+l)/2,u;Z(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-c,n-d),o&&(u=u+rr/2,u=u-u%rr),u=or(u));let m=Ht(e),p={angle:u};if(Ae(e)&&(p={...p},e.startBinding&&ve(e,"start",t),e.endBinding&&ve(e,"end",t)),t.mutateElement(e,p),m){let f=t.getElement(m);if(f&&!H(e)){let{x:h,y:E}=yi(e,f,t.getNonDeletedElementsMap());t.mutateElement(f,{angle:u,x:h,y:E})}}},Zc=(e,t,n,i)=>K(e)||Ee(e)?{points:Vc(0,t,Vc(1,n,e.points,i),i)}:{},Zs=(e,t,n)=>{let i=e.width;if(ue(e)){let s=Me(e,t);s&&(i=ct(s,e))}let r=e.fontSize*(n/i);return r<Vs?null:{size:r}},ZE=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=Zs(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=ie(e.x,e.y),u=$s(c,e.width,e.height,l,s,e.angle,i,!1,o);n.mutateElement(t,{fontSize:d.size,width:l,height:s,x:u.x,y:u.y});return}if(i==="e"||i==="w"){let c=ho(ir({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=zt(t.originalText,ir(t),Math.abs(u)),p=Ve(m,ir(t),t.lineHeight),f=p.height,h=ie(e.x,e.y),E=$s(h,e.width,e.height,u,f,t.angle,i,!1,o),g={width:Math.abs(u),height:Math.abs(p.height),x:E.x,y:E.y,text:m,autoResize:!1};n.mutateElement(t,g)}}},qE=(e,t,n,i,o,r,s,a)=>{let l=n.getNonDeletedElementsMap(),d=5*Math.PI/2+Math.atan2(o-a,i-s);r&&(d+=rr/2,d-=d%rr);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!Z(u)){let[m,p,f,h]=$(u,l),E=(m+f)/2,g=(p+h)/2,x=e.get(u.id)?.angle??u.angle,[w,b]=Et(ie(E,g),ie(s,a),d+x-u.angle),y=U(u)?{points:Ul(u,l)}:{x:u.x+(w-E),y:u.y+(b-g),angle:or(d+x)};n.mutateElement(u,y),De(u,n,{simultaneouslyUpdated:t}),Ae(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||ve(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||ve(u,"end",n)));let I=V(u,l);if(I&&!H(u)){let{x:M,y:T}=yi(u,I,l);n.mutateElement(I,{x:M,y:T,angle:or(d+x)})}}n.triggerUpdate()},uA=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?$(t[0],n):Oe(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=Et(ie(i,o),ie(d,c),-u),e){case"n":return Et(ie(i-(r+a)/2,o-s),ie(0,0),u);case"s":return Et(ie(i-(r+a)/2,o-l),ie(0,0),u);case"w":return Et(ie(i-r,o-(s+l)/2),ie(0,0),u);case"e":return Et(ie(i-a,o-(s+l)/2),ie(0,0),u);case"nw":return Et(ie(i-r,o-s),ie(0,0),u);case"ne":return Et(ie(i-a,o-s),ie(0,0),u);case"sw":return Et(ie(i-r,o-l),ie(0,0),u);case"se":return Et(ie(i-a,o-l),ie(0,0),u);default:return[0,0]}},mA=(e,t)=>{let[,[n,i]]=t.points;return e==="nw"&&(n<0||i<0)||e==="ne"&&n>=0||e==="sw"&&n<=0||e==="se"&&(n>0||i>0)?"end":"origin"},KE=(e,t,n)=>{if(n)return"center";if(t)switch(e){case"n":return"south-side";case"e":return"west-side";case"s":return"north-side";case"w":return"east-side";case"ne":return"bottom-left";case"nw":return"bottom-right";case"se":return"top-left";case"sw":return"top-right"}return["e","se","s"].includes(e)?"top-left":["n","nw","w"].includes(e)?"bottom-right":e==="ne"?"bottom-left":"top-right"},$s=(e,t,n,i,o,r,s,a,l)=>{let d=KE(s,a,l),[c,u]=e;switch(d){case"top-left":return{x:c+(t-i)/2+(i-t)/2*Math.cos(r)+(n-o)/2*Math.sin(r),y:u+(n-o)/2+(i-t)/2*Math.sin(r)+(o-n)/2*Math.cos(r)};case"top-right":return{x:c+(t-i)/2*(Math.cos(r)+1)+(n-o)/2*Math.sin(r),y:u+(n-o)/2+(t-i)/2*Math.sin(r)+(o-n)/2*Math.cos(r)};case"bottom-left":return{x:c+(t-i)/2*(1-Math.cos(r))+(o-n)/2*Math.sin(r),y:u+(n-o)/2*(Math.cos(r)+1)+(i-t)/2*Math.sin(r)};case"bottom-right":return{x:c+(t-i)/2*(Math.cos(r)+1)+(o-n)/2*Math.sin(r),y:u+(n-o)/2*(Math.cos(r)+1)+(t-i)/2*Math.sin(r)};case"center":return{x:c-(i-t)/2,y:u-(o-n)/2};case"east-side":return{x:c+(t-i)/2*(Math.cos(r)+1),y:u+(t-i)/2*Math.sin(r)+(n-o)/2};case"west-side":return{x:c+(t-i)/2*(1-Math.cos(r)),y:u+(i-t)/2*Math.sin(r)+(n-o)/2};case"north-side":return{x:c+(t-i)/2+(n-o)/2*Math.sin(r),y:u+(o-n)/2*(Math.cos(r)-1)};case"south-side":return{x:c+(t-i)/2+(o-n)/2*Math.sin(r),y:u+(n-o)/2*(Math.cos(r)+1)}}},QE=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(q(n)&&q(i))return ZE(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=V(n,u);if(m){let E=o.get(m.id);if(E&&(c={fontSize:E.fontSize}),l){let g={...n,width:e,height:t},x=Zs(m,u,ct(g,m));if(x===null)return;c={fontSize:x.size}}else{let g=el(ir(m),m.lineHeight),x=tl(m.fontSize,m.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let p=Zc(i,e,t,!0),f=ie(i.x,i.y);if(K(i)){let[E,g]=se(i,o);f=ie(E,g)}let h=$s(f,i.width,i.height,e,t,i.angle,s,l,d);if(K(i)&&p.points){let E=i.x-f[0],g=i.y-f[1];h.x+=E,h.y+=g;let x=p.points[0][0],w=p.points[0][1];h.x+=x,h.y+=w,p.points=p.points.map(b=>ie(b[0]-x,b[1]-w))}if(e<0&&(h.x=h.x+e),t<0&&(h.y=h.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),H(n)&&m&&l){let E=e/n.width*m.fontSize;if(E<Vs)return;c.fontSize=E}if(e!==0&&t!==0&&Number.isFinite(h.x)&&Number.isFinite(h.y)){let E={...h,width:Math.abs(e),height:Math.abs(t),...p};Ae(n)&&(n.startBinding&&(E={...E},n.startBinding&&ve(n,"start",r)),n.endBinding&&(E={...E,endBinding:null})),r.mutateElement(n,E,{informMutation:a,isDragging:!1}),m&&c!=null&&r.mutateElement(m,{fontSize:c.fontSize}),On(n,r,s,l),De(n,r)}},JE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=tn(t,t.width,t.height,!0),u=ie(a,l),m=ie(d,c),p=$E(u,m),f=Et(ie(i,o),p,-t.angle),[h,E,g,x]=tn(e,e.width,e.height,!0),w=g-h,b=x-E,y=m[0]-u[0],I=m[1]-u[1],M=y/w,T=I/b;n.includes("e")&&(M=(f[0]-u[0])/w),n.includes("s")&&(T=(f[1]-u[1])/b),n.includes("w")&&(M=(m[0]-f[0])/w),n.includes("n")&&(T=(m[1]-f[1])/b);let S=e.width*M,B=e.height*T;if(s&&(S=2*S-t.width,B=2*B-t.height),r){let L=Math.abs(S)/t.width,k=Math.abs(B)/t.height;if(n.length===1&&(B*=L,S*=k),n.length===2){let C=Math.max(L,k);S=t.width*C*Math.sign(S),B=t.height*C*Math.sign(B)}}return{nextWidth:S,nextHeight:B}},eg=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(C=>t.get(C.id)),d=l.reduce((C,X)=>{if(!K(X))return C;let _=Ht(X);if(!_)return C;let oe=t.get(_)??null;return ue(oe)?[...C,{...oe,...G.getBoundTextElementPosition(X,oe,n)}]:C},[]),c=$t(l.map(C=>C).concat(d)),{minX:u,minY:m,maxX:p,maxY:f,midX:h,midY:E}=c,g=p-u,x=f-m,w={ne:[u,f],se:[u,m],sw:[p,m],nw:[p,f],e:[u,m+x/2],w:[p,m+x/2],n:[u+g/2,f],s:[u+g/2,m]},[b,y]=a?[h,E]:w[i],I=a?2:1,M=Math.max(Math.abs(o-b)/g||0,Math.abs(r-y)/x||0)*I,T=i.includes("e")||i.includes("w")?Math.abs(o-b)*I:g,S=i.includes("n")||i.includes("s")?Math.abs(r-y)*I:x;s&&(T=g*M*Math.sign(o-b),S=x*M*Math.sign(r-y));let B={ne:[o<b,r>y],se:[o<b,r<y],sw:[o>b,r<y],nw:[o>b,r>y],e:[o<b,!1],w:[o>b,!1],n:[!1,r>y],s:[!1,r<y]},[L,k]=B[i].map(C=>C);return{originalBoundingBox:c,nextWidth:T,nextHeight:S,flipByX:L,flipByY:k}},tg=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:d,nextWidth:c,originalBoundingBox:u}={})=>{if(c===void 0&&d===void 0&&a===void 0&&l===void 0||d===0||c===0)return;o||(o=t);let m=e.reduce((I,M)=>{let T=o.get(M.id);return T&&I.push({orig:T,latest:M}),I},[]),p;if(u)p=u;else{let I=m.reduce((M,{orig:T})=>{if(!K(T))return M;let S=Ht(T);if(!S)return M;let B=o.get(S)??null;return ue(B)?[...M,{...B,...G.getBoundTextElementPosition(T,B,t)}]:M},[]);p=$t(m.map(({orig:M})=>M).concat(I))}let{minX:f,minY:h,maxX:E,maxY:g,midX:x,midY:w}=p,b=E-f,y=g-h;if(c===void 0&&d===void 0&&(c=b,d=y),r&&(c===void 0?c=d*(b/y):d===void 0?d=c*(y/b):Math.abs(c/d-b/y)>.001&&(c=d*(b/y))),c&&d){let I=n.includes("e")||n.includes("w")?Math.abs(c)/b:1,M=n.includes("n")||n.includes("s")?Math.abs(d)/y:1,T;n.length===1?T=n.includes("e")||n.includes("w")?I:M:T=Math.max(Math.abs(c)/b||0,Math.abs(d)/y||0);let S={ne:[f,g],se:[f,h],sw:[E,h],nw:[E,g],e:[f,h+y/2],w:[E,h+y/2],n:[f+b/2,g],s:[f+b/2,h]},[B,L]=s?[x,w]:S[n],k=r||m.some(A=>A.latest.angle!==0||q(A.latest)||dd(A.latest));k&&(I=T,M=T);let[C,X]=[a?-1:1,l?-1:1],_=[];for(let{orig:A,latest:z}of m){if(q(A)&&ue(A))continue;let W=A.width*I,we=A.height*M,gt=or(A.angle*C*X),_i=K(A)||Ee(A),cr=A.x-B,Ui=A.y-L,ri=a&&!_i?W:0,ur=l&&!_i?we:0,Wi=B+C*(cr*I+ri),ji=L+X*(Ui*M+ur),Ye=Zc(A,W*C,we*X,!1),Je={x:Wi,y:ji,width:W,height:we,angle:gt,...Ye};if(U(A)&&(A.startBinding&&(Je.startBinding={...A.startBinding,fixedPoint:[a?-A.startBinding.fixedPoint[0]+1:A.startBinding.fixedPoint[0],l?-A.startBinding.fixedPoint[1]+1:A.startBinding.fixedPoint[1]]}),A.endBinding&&(Je.endBinding={...A.endBinding,fixedPoint:[a?-A.endBinding.fixedPoint[0]+1:A.endBinding.fixedPoint[0],l?-A.endBinding.fixedPoint[1]+1:A.endBinding.fixedPoint[1]]}),A.fixedSegments&&Ye.points&&(Je.fixedSegments=A.fixedSegments.map(Dt=>({...Dt,start:Ye.points[Dt.index-1],end:Ye.points[Dt.index]})))),be(A)&&(Je.scale=[A.scale[0]*C,A.scale[1]*X]),q(A)){let Dt=Zs(A,t,W);if(!Dt)return;Je.fontSize=Dt.size}let Kt=o.get(Ht(A)??"");if(Kt)if(k){let Dt=Kt.fontSize*T;if(Dt<Vs)return;Je.boundTextFontSize=Dt}else Je.boundTextFontSize=Kt.fontSize;_.push({element:z,update:Je})}let oe=_.map(({element:A})=>A),F=new Map(_.map(({element:A})=>[A.id,A]));for(let{element:A,update:{boundTextFontSize:z,...W}}of _){let{angle:we}=W;i.mutateElement(A,W),De(A,i,{simultaneouslyUpdated:oe}),Ae(A)&&(A.startBinding&&(F.has(A.startBinding.elementId)||ve(A,"start",i)),A.endBinding&&(F.has(A.endBinding.elementId)||ve(A,"end",i)));let gt=V(A,t);gt&&z&&(i.mutateElement(gt,{fontSize:z,angle:K(A)?void 0:we}),On(A,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as rt,pointOnLineSegment as tu,pointRotateRads as ar}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as ta}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as Ks}from"@excalidraw/common";import{pointFrom as qc,pointRotateRads as ng}from"@excalidraw/math";var Kc={mouse:8,pen:16,touch:28},ig=16,Jc={e:!0,s:!0,n:!0,w:!0},wA={e:!0,s:!0,n:!0,w:!0},bA={e:!0,s:!0,n:!0,w:!0,rotation:!0},Qc={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},qs={e:!0,s:!0,n:!0,w:!0},qt=(e,t,n,i,o,r,s)=>{let[a,l]=ng(qc(e+n/2,t+i/2),qc(o,r),s);return[a-n/2,l-i/2,n,i]},sr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),Qs=e=>sr(e)?Jc:{},Js=([e,t,n,i,o,r],s,a,l,d={},c=4,u=Ks)=>{let m=Kc[l],p=m/a.value,f=m/a.value,h=m/a.value,E=m/a.value,g=n-e,x=i-t,w=c/a.value,b=(m-u*2)/(2*a.value),y={nw:d.nw?void 0:qt(e-w-h+b,t-w-E+b,p,f,o,r,s),ne:d.ne?void 0:qt(n+w-b,t-w-E+b,p,f,o,r,s),sw:d.sw?void 0:qt(e-w-h+b,i+w-b,p,f,o,r,s),se:d.se?void 0:qt(n+w-b,i+w-b,p,f,o,r,s),rotation:d.rotation?void 0:qt(e+g/2-p/2,t-w-E+b-ig/a.value,p,f,o,r,s)},I=5*Kc.mouse/a.value;return Math.abs(g)>I&&(d.n||(y.n=qt(e+g/2-p/2,t-w-E+b,p,f,o,r,s)),d.s||(y.s=qt(e+g/2-p/2,i+w-b,p,f,o,r,s))),Math.abs(x)>I&&(d.w||(y.w=qt(e-w-h+b,t+x/2-f/2,p,f,o,r,s)),d.e||(y.e=qt(n+w-b,t+x/2-f/2,p,f,o,r,s))),y},eu=(e,t,n,i="mouse",o=Jc)=>{if(e.locked||U(e))return{};if(e.type==="freedraw"||K(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=qs:s[0]>0&&s[1]<0?o=Qc:s[0]>0&&s[1]>0?o=qs:s[0]<0&&s[1]>0?o=Qc:s[0]<0&&s[1]<0&&(o=qs)}}else Z(e)&&(o={...o,rotation:!0});let r=K(e)?Ks+8:be(e)?0:Ks;return Js($(e,n,!0),e.angle,t,i,o,r,be(e)?0:void 0)},yA=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return U(i)?!1:K(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var na=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],og=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=eu(e,r,t,s,Qs(a));if(l&&na(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?na(m,i,o):!1});if(c.length>0)return c[0];if(sr(a)){let[u,m,p,f,h,E]=$(e,t);if(!(K(e)&&e.points.length<=2)){let g=be(e)?0:ta/r.value,x=ta/r.value,w=nu(rt(u-g,m-g),rt(p+g,f+g),rt(h,E),e.angle);for(let[b,y]of Object.entries(w))if(tu(rt(i,o),y,x))return b}}return!1},DA=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=og(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),BA=([e,t,n,i],o,r,s,a,l)=>{let d=Js([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,Qs(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&na(m,o,r)});if(c)return c;if(sr(l)){let u=(e+n)/2,m=(t+i)/2,p=ta/s.value,f=nu(rt(e-p,t-p),rt(n+p,i+p),rt(u,m),0);for(let[h,E]of Object.entries(f))if(tu(rt(o,r),E,p))return h}return!1},ea=["ns","nesw","ew","nwse"],rg=(e,t)=>{let n=ea.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=ea[(n+i)%ea.length]}return e},LA=e=>{let{element:t,transformHandleType:n}=e,i=t&&Math.sign(t.height)*Math.sign(t.width)===-1,o=null;switch(n){case"n":case"s":o="ns";break;case"w":case"e":o="ew";break;case"nw":case"se":i?o="nesw":o="nwse";break;case"ne":case"sw":i?o="nwse":o="nesw";break;case"rotation":return"grab"}return o&&t&&(o=rg(o,t.angle)),o?`${o}-resize`:""},nu=([e,t],[n,i],o,r)=>{let s=ar(rt(e,t),o,r),a=ar(rt(n,t),o,r),l=ar(rt(e,i),o,r),d=ar(rt(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var kA=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||Tt(t,e).length));P();import{pointFrom as lr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as sg,DEFAULT_FONT_SIZE as ag,TEXT_ALIGN as lg,VERTICAL_ALIGN as dg,getSizeFromPoints as cg,randomId as ug,arrayToMap as mg,assertNever as ia,cloneJSON as ou,getFontString as pg,isDevEnv as fg,toBrandedType as hg,getLineHeight as Eg}from"@excalidraw/common";var dr={width:100,height:0},Mn=100,gg=(e,t,n)=>{let i=Hn({x:0,y:0,textAlign:lg.CENTER,verticalAlign:dg.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),wo(i,e,n),[e,i]},iu=(e,t,n,i,o)=>{let r,s;if(Object.assign(e,{startBinding:e?.startBinding||null,endBinding:e.endBinding||null}),t){let c=t?.width??Mn,u=t?.height??Mn,m;t.id&&(m=i.getElement(t.id),m||console.error(`No element for start binding with id ${t.id} found`));let p=t.x||e.x-c,f=t.y||e.y-u/2,h=m?m.type:t.type;if(h){if(h==="text"){let E="";m&&m.type==="text"?E=m.text:t.type==="text"&&(E=t.text),E||console.error(`No text found for start binding text element for ${e.id}`),r=Hn({x:p,y:f,type:"text",...m,...t,text:E}),Object.assign(r,{x:t.x||e.x-r.width,y:t.y||e.y-r.height/2})}else switch(h){case"rectangle":case"ellipse":case"diamond":{r=zn({x:p,y:f,width:c,height:u,...m,...t,type:h});break}default:ia(e,`Unhandled element start type "${t.type}"`,!0)}Mt(e,r,"orbit","start",o)}}if(n){let c=n?.height??Mn,u=n?.width??Mn,m;n.id&&(m=i.getElement(n.id),m||console.error(`No element for end binding with id ${n.id} found`));let p=n.x||e.x+e.width,f=n.y||e.y-c/2,h=m?m.type:n.type;if(h){if(h==="text"){let E="";m&&m.type==="text"?E=m.text:n.type==="text"&&(E=n.text),E||console.error(`No text found for end binding text element for ${e.id}`),s=Hn({x:p,y:f,type:"text",...m,...n,text:E}),Object.assign(s,{y:n.y||e.y-s.height/2})}else switch(h){case"rectangle":case"ellipse":case"diamond":{s=zn({x:p,y:f,width:u,height:c,...m,...n,type:h});break}default:ia(e,`Unhandled element end type "${h}"`,!0)}Mt(e,s,"orbit","end",o)}}if(e.points.length<2)return{linearElement:e,startBoundElement:r,endBoundElement:s};let a=e.points.length-1,l=.5,d=ou(e.points);return e.points[a][0]>e.points[a-1][0]&&(d[0][0]=l,d[a][0]-=l),e.points[a][0]<e.points[a-1][0]&&(d[0][0]=-l,d[a][0]+=l),e.points[a][1]>e.points[a-1][1]&&(d[0][1]=l,d[a][1]-=l),e.points[a][1]<e.points[a-1][1]&&(d[0][1]=-l,d[a][1]+=l),Object.assign(e,G.getNormalizeElementPointsAndCoords({...e,points:d})),{linearElement:e,startBoundElement:r,endBoundElement:s}},oa=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>ks(Array.from(this.excalidrawElements.values()));getElementsMap=()=>hg(mg(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},ZA=(e,t)=>{if(!e)return[];let n=ou(e),i=new oa,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:ug()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||Mn,p=l?.label?.text&&l.height===void 0?0:l?.height||Mn;d=zn({...l,width:m,height:p});break}case"line":{let m=l.width||dr.width,p=l.height||dr.height;d=Pc({width:m,height:p,points:[lr(0,0),lr(m,p)],...l});break}case"arrow":{let m=l.width||dr.width,p=l.height||dr.height;d=Jo({width:m,height:p,endArrowhead:"arrow",points:[lr(0,0),lr(m,p)],...l,type:"arrow"}),Object.assign(d,cg(d.points));break}case"text":{let m=l?.fontFamily||sg,p=l?.fontSize||ag,f=l?.lineHeight||Eg(m),h=l.text??"",E=bi(h),g=Ve(E,pg({fontFamily:m,fontSize:p}),f);d=Hn({width:g.width,height:g.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=Ic({width:l?.width||Mn,height:l?.height||Mn,...l});break}case"frame":{d=wc({x:0,y:0,...l});break}case"magicframe":{d=bc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,ia(l,`Unhandled element type "${l.type}"`,!0)}i.getElement(d.id)?console.error(`Duplicate id found for ${d.id}`):(i.add(d),o.set(d.id,l),c&&r.set(c,d.id))}let s=i.getElementsMap(),a=new ni(s);for(let[l,d]of o){let c=i.getElement(l);switch(d.type){case"rectangle":case"ellipse":case"diamond":case"arrow":{if(d.label?.text){let[u,m]=gg(c,d?.label,a);if(i.add(u),i.add(m),H(u)){let p=d.type==="arrow"?d?.start:void 0,f=d.type==="arrow"?d?.end:void 0;if(p&&p.id){let x=r.get(p.id);x&&Object.assign(p,{id:x})}if(f&&f.id){let x=r.get(f.id);x&&Object.assign(f,{id:x})}let{linearElement:h,startBoundElement:E,endBoundElement:g}=iu(u,p,f,i,a);u=h,i.add(h),i.add(E),i.add(g)}}else switch(d.type){case"arrow":{let{start:u,end:m}=d;if(u&&u.id){let E=r.get(u.id);Object.assign(u,{id:E})}if(m&&m.id){let E=r.get(m.id);Object.assign(m,{id:E})}let{linearElement:p,startBoundElement:f,endBoundElement:h}=iu(c,u,m,i,a);i.add(p),i.add(f),i.add(h);break}}break}}}for(let[l,d]of o){if(d.type!=="frame"&&d.type!=="magicframe")continue;let c=i.getElement(l);if(!c)throw new Error(`Excalidraw element with id ${l} doesn't exist`);let u=[];d.children.forEach(y=>{let I=r.get(y);if(!I)throw new Error(`Element with ${y} wasn't mapped correctly`);let M=i.getElement(I);if(!M)throw new Error(`Frame element with id ${I} doesn't exist`);Object.assign(M,{frameId:c.id}),M?.boundElements?.forEach(T=>{let S=i.getElement(T.id);if(!S)throw new Error(`Bound element with id ${T.id} doesn't exist`);Object.assign(S,{frameId:c.id}),u.push(S)}),u.push(M)});let[m,p,f,h]=Oe(u),E=10;m=m-E,p=p-E,f=f+E,h=h+E;let g=c?.x||m,x=c?.y||p,w=c?.width||f-m,b=c?.height||h-p;Object.assign(c,{x:g,y:x,width:w,height:b}),fg()&&d.children.length&&(c?.x||c?.y||c?.width||c?.height)&&console.info("User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically")}return i.getElements()};P();var eM=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return Xc(n.selectedLinearElement,e.scene.getNonDeletedElementsMap(),e.lastPointerMoveCoords,e.scene,n,e.getEffectiveGridSize(),t.altKey),!0;if(n.selectedLinearElement.hoverPointIndex!==null&&e.lastPointerMoveEvent&&n.selectedLinearElement.initialState.lastClickedPoint>=0&&n.selectedLinearElement.isDragging)return G.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};P();var xg=e=>{switch(e){case void 0:case null:return null;case"dot":return"circle";case"crowfoot_one":return"cardinality_one";case"crowfoot_many":return"cardinality_many";case"crowfoot_one_or_many":return"cardinality_one_or_many";default:return e}},iM=e=>{let t=xg(e);return t===null?null:t};var lM=e=>e.reduce((t,n)=>t+n.version,0),$d=e=>{let t=5381;for(let n of wg(e))t=(t<<5)+t+n.versionNonce;return t>>>0},Vd=e=>{let t=5381;for(let n=0;n<e.length;n++){let i=e.charCodeAt(n);t=(t<<5)+t+i}return t>>>0},dM=e=>e.filter(t=>!t.isDeleted&&!zd(t)),cM=e=>e.filter(t=>!t.isDeleted),uM=e=>!e.isDeleted;export{bn as AppStateDelta,Op as BASE_ARROW_MIN_LENGTH,Rl as BASE_BINDING_GAP,kn as BASE_BINDING_GAP_ELBOW,ee as BASE_PADDING,fn as BindableElement,pn as BoundElement,je as CaptureUpdateAction,J0 as DEFAULT_LINK_SIZE,Jc as DEFAULT_OMIT_SIDES,j as Delta,Bs as DurableIncrement,Ss as ElementBounds,yn as ElementsDelta,Ls as EphemeralIncrement,Di as FOCUS_POINT_SIZE,Cc as FlowChartCreator,Lc as FlowChartNavigator,ye as HEADING_DOWN,He as HEADING_LEFT,fe as HEADING_RIGHT,qe as HEADING_UP,ch as INVISIBLY_SMALL_ELEMENT_SIZE,Gs as InvalidFractionalIndexError,G as LinearElementEditor,Se as MINIMAL_CROP_SIZE,bA as OMIT_SIDES_FOR_FRAME,wA as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,ni as Scene,Ke as ShapeCache,Wd as Store,Ni as StoreChange,Cs as StoreDelta,$o as StoreIncrement,Pn as StoreSnapshot,it as aabbForElement,wf as addElementsToFrame,zE as addNewNodes,$y as addToGroup,oP as alignElements,_p as avoidRectangularCorner,Mt as bindBindingElement,fd as bindElementsToFramesAfterDuplication,kp as bindOrUnbindBindingElement,wy as bindOrUnbindBindingElements,ts as bindPointToSnapToElementOutline,_l as bindingProperties,md as boundsContainBounds,Ll as bumpVersion,Wp as calculateFixedPointForElbowArrowBinding,Vn as calculateFixedPointForNonElbowArrowBinding,Sw as canApplyRoundnessTypeToElement,Wa as canBecomePolygon,Id as canChangeRoundness,uE as canCreateLinkFromElements,c1 as canHaveArrowheads,sr as canResizeFromSides,Yn as charWidth,pe as compareHeading,yi as computeBoundTextPosition,Fr as computeContainerDimensionForBoundText,Jw as containsCJK,ZA as convertToExcalidrawElements,KI as createPlaceholderEmbeddableLabel,Hs as createSrcDoc,hw as cropElement,on as deconstructDiamondElement,mo as deconstructLinearOrFreeDrawElement,nn as deconstructRectanguloidElement,Ds as deepCopyElement,TI as defaultGetElementLinkFromSelection,Xw as detectLineHeight,an as distanceToElement,cI as distributeElements,It as doBoundsIntersect,PI as dragNewElement,bI as dragSelectedElements,bh as duplicateElement,xP as duplicateElements,Xy as editGroupForSelectedElement,ne as elementCenterPoint,En as elementOverlapsWithFrame,Gi as elementWithCanvasCache,xn as elementsAreInFrameBounds,ld as elementsAreInSameGroup,JI as embeddableURLValidator,ff as excludeElementsInFramesFromSelection,C0 as filterElementsEligibleAsFrameChildren,yy as fixBindingsAfterDeletion,Hl as fixDuplicatedBindingsAfterDuplication,Yr as flipHeading,N0 as frameAndChildrenSelectedTogether,qa as generateLinearCollisionShape,We as generateRoughOptions,m0 as getActiveTextElement,yo as getAllHoveredElementAtPoint,tl as getApproxMinLineHeight,el as getApproxMinLineWidth,Ul as getArrowLocalFixedPoints,ih as getArrowheadAngle,iM as getArrowheadForPicker,ke as getArrowheadPoints,nh as getArrowheadSize,Be as getBindingGap,Py as getBindingSideMidPoint,ss as getBindingStrategyForDraggingBindingElementEndpoints,V as getBoundTextElement,Ht as getBoundTextElementId,ub as getBoundTextElementPosition,Pi as getBoundTextMaxHeight,ct as getBoundTextMaxWidth,As as getBoundsFromPoints,ln as getCenterForBounds,U1 as getClosestElementBounds,$t as getCommonBoundingBox,Oe as getCommonBounds,db as getContainerCenter,Rr as getContainerCoords,Me as getContainerElement,Yt as getContainingFrame,Ft as getCornerRadius,Po as getCubicBezierCurveBound,LA as getCursorForResizingElement,Sf as getDefaultFrameName,Aw as getDefaultRoundnessTypeForElement,Za as getDiamondBaseCorners,jn as getDiamondPoints,yI as getDragOffsetXY,_1 as getDraggedElementsBounds,$ as getElementAbsoluteCoords,se as getElementBounds,hs as getElementLineSegments,ds as getElementPointsCoords,Bd as getElementShape,DA as getElementWithTransformHandleType,hd as getElementsCompletelyInFrame,Ge as getElementsInGroup,L0 as getElementsInNewFrame,B0 as getElementsInResizingFrame,S0 as getElementsIntersectingFrame,R0 as getElementsOverlappingFrame,ps as getElementsWithinSelection,qI as getEmbedLink,Ew as getFlipAdjustedCropPosition,gn as getFrameChildren,gf as getFrameLikeElements,F0 as getFrameLikeTitle,n1 as getFreedrawOutlineAsSegments,Xf as getFreedrawOutlinePoints,Re as getGlobalFixedPointForBindableElement,jp as getGlobalFixedPoints,Bl as getHeadingForElbowArrowSnap,_t as getHoveredElementForBinding,xl as getHoveredElementForFocusPoint,YS as getInitializedImageElements,Eo as getLineHeightInPx,sn as getLineWidth,Mw as getLinearElementSubType,pS as getLinkDirectionFromKey,vI as getLinkIdAndTypeFromSelection,Jl as getLockedLinearCursorAlignSize,ym as getMaxCharWidth,Zy as getMaximumGroups,Vw as getMinCharWidth,Li as getMinMaxXYFromCurvePathOps,ho as getMinTextElementWidth,cd as getNewGroupIdsForDuplication,cM as getNonDeletedElements,ad as getNonDeletedGroupIds,Q1 as getNormalizedDimensions,Jn as getObservedAppState,Qs as getOmitSidesForEditorInterface,_w as getOriginalContainerHeightFromCache,Ms as getPerfectElementSize,js as getPredecessors,H1 as getRectangleBoxAbsoluteCoords,kf as getRenderOpacity,mA as getResizeArrowDirection,uA as getResizeOffsetXY,tn as getResizedElementAbsoluteCoords,D0 as getRootElements,lM as getSceneVersion,Tt as getSelectedElements,Ro as getSelectedElementsByGroup,ms as getSelectedGroupForElement,cf as getSelectedGroupIdForElement,lf as getSelectedGroupIds,u0 as getSelectionStateForElements,fm as getSnapOutlineMidPoint,c0 as getTargetElements,yf as getTargetFrame,cb as getTextElementAngle,hb as getTextFromElements,bm as getTextHeight,nl as getTextWidth,BA as getTransformHandleTypeFromCoords,eu as getTransformHandles,Js as getTransformHandlesFromCoords,Fa as getUncroppedImageElement,Ir as getUncroppedWidthAndHeight,l0 as getVisibleAndNonSelectedElements,dM as getVisibleElements,W1 as getVisibleSceneBounds,Bm as getWrappedTextLines,v0 as groupByFrameLikes,M0 as groupsAreAtLeastIntersectingTheFrame,T0 as groupsAreCompletelyOutOfFrame,On as handleBindTextResize,Xc as handleFocusPointDrag,zS as handleFocusPointHover,RS as handleFocusPointPointerDown,NS as handleFocusPointPointerUp,r1 as hasBackground,wt as hasBoundTextElement,yA as hasBoundingBox,s1 as hasStrokeColor,l1 as hasStrokeStyle,a1 as hasStrokeWidth,$d as hashElementsVersion,Vd as hashString,ze as headingForPoint,Si as headingForPointFromElement,mt as headingForPointIsHorizontal,_e as headingIsHorizontal,_b as headingIsVertical,ip as hitElementBoundText,np as hitElementBoundingBox,kb as hitElementBoundingBoxOnly,bt as hitElementItself,Pt as intersectElementWithLineSegment,Iw as isArrowBoundToElement,H as isArrowElement,ce as isBindableElement,Wr as isBindableElementInsideOtherBindable,Ae as isBindingElement,im as isBindingElementType,At as isBindingEnabled,ue as isBoundToContainer,A0 as isCursorInFrame,tm as isCurvedArrow,U as isElbowArrow,K1 as isElementCompletelyInViewport,Es as isElementContainingFrame,gd as isElementInFrame,df as isElementInGroup,pd as isElementInViewport,hn as isElementIntersectingFrame,DI as isElementLink,Na as isEmbeddableElement,Pw as isExcalidrawElement,Yp as isFixedPoint,Sr as isFlowchartNodeElement,nr as isFocusPointVisible,uo as isFrameElement,Z as isFrameLikeElement,Ee as isFreeDrawElement,Ju as isFreeDrawElementType,XE as isHTMLSVGElement,lo as isIframeElement,co as isIframeLikeElement,be as isImageElement,dd as isInGroup,Bn as isInitializedImageElement,zd as isInvisiblySmallElement,Ot as isLineElement,K as isLinearElement,nm as isLinearElementType,za as isMagicFrameElement,Yw as isMeasureTextSupported,fS as isNodeInFlowchart,uM as isNonDeletedElement,Cn as isPathALoop,Rt as isPointInElement,gi as isRectangularElement,Ha as isRectanguloidElement,af as isSelectedViaGroup,em as isSharpArrow,yw as isSimpleArrow,d0 as isSomeElementSelected,om as isTextBindableContainer,q as isTextElement,_a as isUsingAdaptiveRadius,Ua as isUsingProportionalRadius,Tw as isValidPolygon,fb as isValidTextContainer,YE as loadHTMLImageElement,us as makeNextSelectedElementIds,dt as maxBindingDistance_simple,eM as maybeHandleArrowPointlikeDrag,QI as maybeParseEmbedSrc,Zs as measureFontSizeFromWidth,Ve as measureText,MS as moveAllLeft,TS as moveAllRight,Hc as moveArrowAboveBindable,SS as moveOneLeft,AS as moveOneRight,Pe as mutateElement,Jo as newArrowElement,zn as newElement,Le as newElementWith,HI as newEmbeddableElement,wc as newFrameElement,WI as newFreeDrawElement,_I as newIframeElement,Ic as newImageElement,Pc as newLinearElement,bc as newMagicFrameElement,Hn as newTextElement,xg as normalizeArrowhead,Hd as normalizeElementOrder,rn as normalizeFixedPoint,XS as normalizeSVG,bi as normalizeText,zo as omitGroupsContainingFrameLikes,xf as omitPartialGroups,tc as orderByFractionalIndex,wi as originalContainerCache,BI as parseElementLinkFromURL,vm as parseTokens,ut as pointInsideBounds,sh as pointInsideBoundsInclusive,KS as positionElementsOnGrid,Br as projectFixedPointOntoDiagonal,wo as redrawTextBoundingBox,UI as refreshTextDimensions,bf as removeAllElementsFromFrame,Ed as removeElementsFromFrame,Vy as removeFromSelectedGroups,t1 as renderElement,e1 as renderSelectionElement,G0 as replaceAllElementsInFrame,Zc as rescalePointsInElement,Qa as resetOriginalContainerCache,tg as resizeMultipleElements,QE as resizeSingleElement,ZE as resizeSingleTextElement,og as resizeTest,sf as selectGroup,rd as selectGroupsForSelectedElements,sd as selectGroupsFromGivenElements,$w as setCustomTextMetricsProvider,mb as shouldAllowVerticalAlign,k0 as shouldApplyFrameClip,bo as shouldTestInside,kA as showSelectedShapeActions,as as snapToMid,pb as suppportsHorizontalAlign,ks as syncInvalidIndices,Xd as syncInvalidIndicesImmutable,Hi as syncMovedIndices,Ql as toggleLinePolygonState,d1 as toolIsArrow,cA as transformElements,ve as unbindBindingElement,by as updateBindings,De as updateBoundElements,pt as updateBoundPoint,$n as updateElbowArrowPoints,O0 as updateFrameMembershipOfSelectedElements,jS as updateImageCache,Ka as updateOriginalContainerCache,Dl as validateElbowPoints,Dh as validateFractionalIndices,Ut as vectorToHeading,zt as wrapText};