@excalidraw/element 0.18.0-91c7748 → 0.18.0-a52cd20

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 (360) hide show
  1. package/dist/dev/index.js +15101 -8988
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +20 -19
  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 +81 -39
  8. package/dist/types/common/src/constants.d.ts +89 -34
  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 +5 -1
  13. package/dist/types/common/src/points.d.ts +1 -1
  14. package/dist/types/common/src/random.d.ts +7 -0
  15. package/dist/types/common/src/utility-types.d.ts +0 -1
  16. package/dist/types/common/src/utils.d.ts +52 -78
  17. package/dist/types/common/src/versionedSnapshotStore.d.ts +17 -0
  18. package/dist/types/element/src/Scene.d.ts +12 -8
  19. package/dist/types/element/src/align.d.ts +2 -2
  20. package/dist/types/element/src/arrowEndpointText.d.ts +49 -0
  21. package/dist/types/element/src/arrowheads.d.ts +3 -0
  22. package/dist/types/element/src/arrows/focus.d.ts +30 -0
  23. package/dist/types/element/src/arrows/helpers.d.ts +5 -0
  24. package/dist/types/element/src/binding.d.ts +85 -51
  25. package/dist/types/element/src/bounds.d.ts +25 -18
  26. package/dist/types/element/src/bucketFill.d.ts +110 -0
  27. package/dist/types/element/src/collision.d.ts +11 -3
  28. package/dist/types/element/src/comparisons.d.ts +10 -7
  29. package/dist/types/element/src/convertToShape.d.ts +23 -0
  30. package/dist/types/element/src/delta.d.ts +23 -1
  31. package/dist/types/element/src/distribute.d.ts +3 -2
  32. package/dist/types/element/src/dragElements.d.ts +30 -3
  33. package/dist/types/element/src/duplicate.d.ts +67 -6
  34. package/dist/types/element/src/elbowArrow.d.ts +2 -0
  35. package/dist/types/element/src/embeddable.d.ts +2 -2
  36. package/dist/types/element/src/flowchart.d.ts +11 -7
  37. package/dist/types/element/src/fractionalIndex.d.ts +4 -4
  38. package/dist/types/element/src/frame.d.ts +16 -11
  39. package/dist/types/element/src/groups.d.ts +9 -9
  40. package/dist/types/element/src/heading.d.ts +2 -1
  41. package/dist/types/element/src/image.d.ts +1 -11
  42. package/dist/types/element/src/index.d.ts +9 -4
  43. package/dist/types/element/src/linearElementEditor.d.ts +48 -30
  44. package/dist/types/element/src/mutateElement.d.ts +6 -2
  45. package/dist/types/element/src/newElement.d.ts +59 -9
  46. package/dist/types/element/src/renderElement.d.ts +21 -13
  47. package/dist/types/element/src/resizeElements.d.ts +12 -12
  48. package/dist/types/element/src/resizeTest.d.ts +6 -5
  49. package/dist/types/element/src/selection.d.ts +14 -14
  50. package/dist/types/element/src/shape.d.ts +36 -9
  51. package/dist/types/element/src/sizeHelpers.d.ts +6 -0
  52. package/dist/types/element/src/sortElements.d.ts +10 -0
  53. package/dist/types/element/src/stickyNote.d.ts +183 -0
  54. package/dist/types/element/src/textElement.d.ts +21 -10
  55. package/dist/types/element/src/textMeasurements.d.ts +1 -3
  56. package/dist/types/element/src/textWrapping.d.ts +26 -0
  57. package/dist/types/{excalidraw/data → element/src}/transform.d.ts +27 -8
  58. package/dist/types/element/src/transformHandles.d.ts +8 -27
  59. package/dist/types/element/src/typeChecks.d.ts +30 -31
  60. package/dist/types/element/src/types.d.ts +55 -20
  61. package/dist/types/element/src/utils.d.ts +22 -6
  62. package/dist/types/element/src/visualdebug.d.ts +58 -0
  63. package/dist/types/element/src/zindex.d.ts +7 -1
  64. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +215 -189
  65. package/dist/types/excalidraw/actions/actionAlign.d.ts +12 -13
  66. package/dist/types/excalidraw/actions/actionBoundText.d.ts +150 -133
  67. package/dist/types/excalidraw/actions/actionCanvas.d.ts +543 -1576
  68. package/dist/types/excalidraw/actions/actionClipboard.d.ts +152 -880
  69. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +73 -65
  70. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +237 -214
  71. package/dist/types/excalidraw/actions/actionDeselect.d.ts +182 -0
  72. package/dist/types/excalidraw/actions/actionDistribute.d.ts +4 -6
  73. package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -3
  74. package/dist/types/excalidraw/actions/actionElementLink.d.ts +65 -63
  75. package/dist/types/excalidraw/actions/actionElementLock.d.ts +149 -132
  76. package/dist/types/excalidraw/actions/actionExport.d.ts +228 -1423
  77. package/dist/types/excalidraw/actions/actionFinalize.d.ts +11 -396
  78. package/dist/types/excalidraw/actions/actionFlip.d.ts +2 -3
  79. package/dist/types/excalidraw/actions/actionFrame.d.ts +373 -521
  80. package/dist/types/excalidraw/actions/actionGroup.d.ts +160 -151
  81. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +236 -214
  82. package/dist/types/excalidraw/actions/actionLink.d.ts +72 -64
  83. package/dist/types/excalidraw/actions/actionMenu.d.ts +64 -430
  84. package/dist/types/excalidraw/actions/actionNavigate.d.ts +18 -361
  85. package/dist/types/excalidraw/actions/actionProperties.d.ts +241 -2560
  86. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +80 -76
  87. package/dist/types/excalidraw/actions/actionStyles.d.ts +74 -65
  88. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
  89. package/dist/types/excalidraw/actions/{actionEmbeddable.d.ts → actionToggleArrowBinding.d.ts} +88 -79
  90. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +77 -70
  91. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +195 -0
  92. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +74 -66
  93. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +65 -64
  94. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +2 -2
  95. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +74 -66
  96. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +75 -67
  97. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +75 -67
  98. package/dist/types/excalidraw/actions/actionZindex.d.ts +2 -3
  99. package/dist/types/excalidraw/actions/colorTargets.d.ts +39 -0
  100. package/dist/types/excalidraw/actions/index.d.ts +5 -3
  101. package/dist/types/excalidraw/actions/manager.d.ts +1 -0
  102. package/dist/types/excalidraw/actions/register.d.ts +2 -2
  103. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  104. package/dist/types/excalidraw/actions/types.d.ts +11 -7
  105. package/dist/types/excalidraw/{animated-trail.d.ts → animatedTrail.d.ts} +4 -3
  106. package/dist/types/excalidraw/appState.d.ts +50 -20
  107. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
  108. package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
  109. package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
  110. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
  111. package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
  112. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
  113. package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
  114. package/dist/types/excalidraw/charts/index.d.ts +7 -0
  115. package/dist/types/excalidraw/clipboard.d.ts +13 -38
  116. package/dist/types/excalidraw/components/Actions.d.ts +26 -11
  117. package/dist/types/excalidraw/components/ActiveConfirmDialog.d.ts +1 -1
  118. package/dist/types/excalidraw/components/App.arrowText.d.ts +70 -0
  119. package/dist/types/excalidraw/components/App.bucketFill.d.ts +48 -0
  120. package/dist/types/excalidraw/components/App.cursor.d.ts +38 -0
  121. package/dist/types/excalidraw/components/App.d.ts +646 -132
  122. package/dist/types/excalidraw/components/App.drawshape.d.ts +55 -0
  123. package/dist/types/excalidraw/components/App.duplicate.d.ts +51 -0
  124. package/dist/types/excalidraw/components/App.flowchart.d.ts +21 -0
  125. package/dist/types/excalidraw/components/App.pan.d.ts +62 -0
  126. package/dist/types/excalidraw/components/App.textTool.d.ts +140 -0
  127. package/dist/types/excalidraw/components/App.toolDrag.d.ts +63 -0
  128. package/dist/types/excalidraw/components/App.viewport.d.ts +113 -0
  129. package/dist/types/excalidraw/components/App.wheel.d.ts +26 -0
  130. package/dist/types/excalidraw/components/AppStateObserver.d.ts +37 -0
  131. package/dist/types/excalidraw/components/Card.d.ts +1 -3
  132. package/dist/types/excalidraw/components/ColorPicker/ColorInput.d.ts +2 -4
  133. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +9 -5
  134. package/dist/types/excalidraw/components/ColorPicker/CustomColorList.d.ts +3 -1
  135. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +7 -1
  136. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +10 -2
  137. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +5 -2
  138. package/dist/types/excalidraw/components/ColorPicker/TopPicks.d.ts +8 -1
  139. package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +1 -2
  140. package/dist/types/excalidraw/components/ColorPicker/colorTopPicksDnD.d.ts +11 -0
  141. package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +2 -2
  142. package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
  143. package/dist/types/excalidraw/components/CommandPalette/defaultCommandPaletteItems.d.ts +1 -2
  144. package/dist/types/excalidraw/components/CommandPalette/types.d.ts +2 -4
  145. package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +4 -4
  146. package/dist/types/excalidraw/components/CursorHint.d.ts +46 -0
  147. package/dist/types/excalidraw/components/DarkModeToggle.d.ts +1 -1
  148. package/dist/types/excalidraw/components/DefaultSidebar.d.ts +9 -13
  149. package/dist/types/excalidraw/components/ElementLinkDialog.d.ts +1 -1
  150. package/dist/types/excalidraw/components/Ellipsify.d.ts +1 -2
  151. package/dist/types/excalidraw/components/ErrorDialog.d.ts +1 -1
  152. package/dist/types/excalidraw/components/EyeDropper.d.ts +1 -2
  153. package/dist/types/excalidraw/components/FileDropOverlay.d.ts +2 -0
  154. package/dist/types/excalidraw/components/FilledButton.d.ts +2 -1
  155. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +4 -1
  156. package/dist/types/excalidraw/components/FontPicker/FontPickerList.d.ts +6 -1
  157. package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +2 -1
  158. package/dist/types/excalidraw/components/FontPicker/fontTopPicksDnD.d.ts +12 -0
  159. package/dist/types/excalidraw/components/FontPicker/keyboardNavHandlers.d.ts +0 -1
  160. package/dist/types/excalidraw/components/HelpDialog.d.ts +1 -1
  161. package/dist/types/excalidraw/components/HintViewer.d.ts +4 -3
  162. package/dist/types/excalidraw/components/IconButton.d.ts +48 -0
  163. package/dist/types/excalidraw/components/IconPicker.d.ts +14 -9
  164. package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
  165. package/dist/types/excalidraw/components/Island.d.ts +7 -0
  166. package/dist/types/excalidraw/components/LaserPointerButton.d.ts +2 -4
  167. package/dist/types/excalidraw/components/LayerUI.d.ts +6 -2
  168. package/dist/types/excalidraw/components/LibraryMenu.d.ts +1 -1
  169. package/dist/types/excalidraw/components/LibraryMenuControlButtons.d.ts +1 -1
  170. package/dist/types/excalidraw/components/LibraryMenuHeaderContent.d.ts +1 -2
  171. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +7 -3
  172. package/dist/types/excalidraw/components/LibraryUnit.d.ts +9 -5
  173. package/dist/types/excalidraw/components/LoadingMessage.d.ts +0 -1
  174. package/dist/types/excalidraw/components/LockButton.d.ts +3 -4
  175. package/dist/types/excalidraw/components/MagicButton.d.ts +0 -2
  176. package/dist/types/excalidraw/components/MobileMenu.d.ts +5 -7
  177. package/dist/types/excalidraw/components/MobileToolbar.d.ts +9 -0
  178. package/dist/types/excalidraw/components/Modal.d.ts +0 -1
  179. package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirm.d.ts +1 -1
  180. package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirmState.d.ts +1 -1
  181. package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
  182. package/dist/types/excalidraw/components/PenModeButton.d.ts +2 -5
  183. package/dist/types/excalidraw/components/Popover.d.ts +2 -3
  184. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -1
  185. package/dist/types/excalidraw/components/{ButtonIcon.d.ts → RadioButton.d.ts} +2 -5
  186. package/dist/types/excalidraw/components/RadioGroup.d.ts +0 -1
  187. package/dist/types/excalidraw/components/RadioSelection.d.ts +4 -4
  188. package/dist/types/excalidraw/components/Range.d.ts +10 -4
  189. package/dist/types/excalidraw/components/SVGLayer.d.ts +1 -1
  190. package/dist/types/excalidraw/components/ScrollableList.d.ts +0 -1
  191. package/dist/types/excalidraw/components/SearchMenu.d.ts +1 -1
  192. package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +16 -22
  193. package/dist/types/excalidraw/components/Sidebar/SidebarHeader.d.ts +1 -1
  194. package/dist/types/excalidraw/components/Sidebar/SidebarTab.d.ts +1 -2
  195. package/dist/types/excalidraw/components/Sidebar/SidebarTabTrigger.d.ts +1 -2
  196. package/dist/types/excalidraw/components/Sidebar/SidebarTabTriggers.d.ts +1 -2
  197. package/dist/types/excalidraw/components/Sidebar/SidebarTabs.d.ts +1 -2
  198. package/dist/types/excalidraw/components/Spinner.d.ts +4 -4
  199. package/dist/types/excalidraw/components/Stats/Angle.d.ts +2 -2
  200. package/dist/types/excalidraw/components/Stats/CanvasGrid.d.ts +0 -1
  201. package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +0 -1
  202. package/dist/types/excalidraw/components/Stats/Dimension.d.ts +2 -2
  203. package/dist/types/excalidraw/components/Stats/DragInput.d.ts +2 -3
  204. package/dist/types/excalidraw/components/Stats/MultiAngle.d.ts +2 -2
  205. package/dist/types/excalidraw/components/Stats/MultiDimension.d.ts +2 -2
  206. package/dist/types/excalidraw/components/Stats/MultiPosition.d.ts +2 -2
  207. package/dist/types/excalidraw/components/Stats/Position.d.ts +3 -3
  208. package/dist/types/excalidraw/components/Stats/index.d.ts +7 -8
  209. package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
  210. package/dist/types/excalidraw/components/TTDDialog/Chat/ChatHistoryMenu.d.ts +15 -0
  211. package/dist/types/excalidraw/components/TTDDialog/Chat/ChatInterface.d.ts +23 -0
  212. package/dist/types/excalidraw/components/TTDDialog/Chat/ChatMessage.d.ts +14 -0
  213. package/dist/types/excalidraw/components/TTDDialog/Chat/TTDChatPanel.d.ts +27 -0
  214. package/dist/types/excalidraw/components/TTDDialog/Chat/index.d.ts +3 -0
  215. package/dist/types/excalidraw/components/TTDDialog/Chat/useChatAgent.d.ts +8 -0
  216. package/dist/types/excalidraw/components/TTDDialog/CodeMirrorEditor.d.ts +11 -0
  217. package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +3 -2
  218. package/dist/types/excalidraw/components/TTDDialog/TTDContext.d.ts +13 -0
  219. package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +12 -29
  220. package/dist/types/excalidraw/components/TTDDialog/TTDDialogInput.d.ts +3 -3
  221. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +5 -2
  222. package/dist/types/excalidraw/components/TTDDialog/TTDDialogPanel.d.ts +13 -9
  223. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTab.d.ts +1 -2
  224. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTrigger.d.ts +1 -2
  225. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTriggers.d.ts +1 -2
  226. package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +9 -0
  227. package/dist/types/excalidraw/components/TTDDialog/TTDWelcomeMessage.d.ts +1 -0
  228. package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +9 -0
  229. package/dist/types/excalidraw/components/TTDDialog/common.d.ts +16 -16
  230. package/dist/types/excalidraw/components/TTDDialog/hooks/useChatManagement.d.ts +13 -0
  231. package/dist/types/excalidraw/components/TTDDialog/hooks/useMermaidRenderer.d.ts +14 -0
  232. package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +7 -0
  233. package/dist/types/excalidraw/components/TTDDialog/mermaid-lang-lite.d.ts +2 -0
  234. package/dist/types/excalidraw/components/TTDDialog/types.d.ts +95 -0
  235. package/dist/types/excalidraw/components/TTDDialog/useTTDChatStorage.d.ts +22 -0
  236. package/dist/types/excalidraw/components/TTDDialog/utils/chat.d.ts +10 -0
  237. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidAutoFix.d.ts +1 -0
  238. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +10 -0
  239. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidValidation.d.ts +1 -0
  240. package/dist/types/excalidraw/components/TextField.d.ts +1 -0
  241. package/dist/types/excalidraw/components/Toast.d.ts +11 -7
  242. package/dist/types/excalidraw/components/ToolPopover.d.ts +22 -0
  243. package/dist/types/excalidraw/components/Toolbar.d.ts +11 -0
  244. package/dist/types/excalidraw/components/Tools.d.ts +151 -0
  245. package/dist/types/excalidraw/components/Tooltip.d.ts +15 -1
  246. package/dist/types/excalidraw/components/TopPicksDnD/TopPicksContextMenu.d.ts +14 -0
  247. package/dist/types/excalidraw/components/TopPicksDnD/TopPicksTip.d.ts +11 -0
  248. package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +58 -0
  249. package/dist/types/excalidraw/components/Trans.d.ts +2 -2
  250. package/dist/types/excalidraw/components/UserList.d.ts +3 -2
  251. package/dist/types/excalidraw/components/ViewportStatusFrame/ViewportStatusFrame.d.ts +11 -0
  252. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +10 -4
  253. package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +3 -0
  254. package/dist/types/excalidraw/components/canvases/StaticCanvas.d.ts +1 -1
  255. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +47 -35
  256. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +7 -5
  257. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuGroup.d.ts +3 -3
  258. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +13 -22
  259. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCheckbox.d.ts +5 -0
  260. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContent.d.ts +5 -4
  261. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +2 -2
  262. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCustom.d.ts +2 -2
  263. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemLink.d.ts +6 -6
  264. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSub.d.ts +23 -0
  265. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubContent.d.ts +8 -0
  266. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubTrigger.d.ts +12 -0
  267. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuTrigger.d.ts +3 -4
  268. package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +2 -2
  269. package/dist/types/excalidraw/components/dropdownMenu/dropdownMenuUtils.d.ts +2 -0
  270. package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
  271. package/dist/types/excalidraw/components/hoc/withInternalFallback.d.ts +1 -1
  272. package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +3 -3
  273. package/dist/types/excalidraw/components/icons.d.ts +51 -23
  274. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +26 -3
  275. package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +39 -35
  276. package/dist/types/excalidraw/components/positionElementBesideCursor.d.ts +26 -0
  277. package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +39 -0
  278. package/dist/types/excalidraw/data/blob.d.ts +373 -8
  279. package/dist/types/excalidraw/data/encode.d.ts +4 -4
  280. package/dist/types/excalidraw/data/encryption.d.ts +5 -5
  281. package/dist/types/excalidraw/data/filesystem.d.ts +5 -7
  282. package/dist/types/excalidraw/data/index.d.ts +8 -9
  283. package/dist/types/excalidraw/data/json.d.ts +192 -3
  284. package/dist/types/excalidraw/data/library.d.ts +25 -10
  285. package/dist/types/excalidraw/data/resave.d.ts +7 -2
  286. package/dist/types/excalidraw/data/restore.d.ts +25 -10
  287. package/dist/types/excalidraw/drawShapeTrail.d.ts +16 -0
  288. package/dist/types/excalidraw/editor-jotai.d.ts +11 -11
  289. package/dist/types/excalidraw/eraser/index.d.ts +2 -3
  290. package/dist/types/excalidraw/errors.d.ts +14 -0
  291. package/dist/types/excalidraw/fonts/Fonts.d.ts +3 -2
  292. package/dist/types/excalidraw/hooks/useAppStateValue.d.ts +29 -0
  293. package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +2 -2
  294. package/dist/types/excalidraw/hooks/useOutsideClick.d.ts +4 -3
  295. package/dist/types/excalidraw/hooks/useScrollPosition.d.ts +1 -2
  296. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +5 -5
  297. package/dist/types/excalidraw/i18n.d.ts +2 -2
  298. package/dist/types/excalidraw/{laser-trails.d.ts → laserTrails.d.ts} +5 -7
  299. package/dist/types/excalidraw/lasso/index.d.ts +2 -3
  300. package/dist/types/excalidraw/lasso/utils.d.ts +2 -0
  301. package/dist/types/excalidraw/renderOverrides.d.ts +9 -0
  302. package/dist/types/excalidraw/renderer/animation.d.ts +16 -0
  303. package/dist/types/excalidraw/renderer/helpers.d.ts +31 -8
  304. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +7 -15
  305. package/dist/types/excalidraw/scene/Renderer.d.ts +491 -19
  306. package/dist/types/excalidraw/scene/export.d.ts +4 -4
  307. package/dist/types/excalidraw/scene/index.d.ts +2 -2
  308. package/dist/types/excalidraw/scene/types.d.ts +28 -8
  309. package/dist/types/excalidraw/shortcut.d.ts +1 -0
  310. package/dist/types/excalidraw/snapping.d.ts +12 -12
  311. package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-bindings.d.ts +1 -1
  312. package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-loader.d.ts +1 -1
  313. package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-wasm.d.ts +1 -1
  314. package/dist/types/excalidraw/subset/woff2/woff2-loader.d.ts +2 -2
  315. package/dist/types/excalidraw/subset/woff2/woff2-wasm.d.ts +1 -1
  316. package/dist/types/excalidraw/textAutoResizeHandle.d.ts +15 -0
  317. package/dist/types/excalidraw/types.d.ts +644 -60
  318. package/dist/types/excalidraw/viewport.d.ts +302 -0
  319. package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +14 -5
  320. package/dist/types/fractional-indexing/src/index.d.ts +29 -0
  321. package/dist/types/laser-pointer/src/index.d.ts +2 -0
  322. package/dist/types/laser-pointer/src/math.d.ts +16 -0
  323. package/dist/types/laser-pointer/src/simplify.d.ts +2 -0
  324. package/dist/types/laser-pointer/src/state.d.ts +36 -0
  325. package/dist/types/math/src/constants.d.ts +0 -1
  326. package/dist/types/math/src/curve.d.ts +23 -13
  327. package/dist/types/math/src/index.d.ts +1 -0
  328. package/dist/types/math/src/pca.d.ts +79 -0
  329. package/dist/types/math/src/point.d.ts +8 -2
  330. package/dist/types/math/src/polygon.d.ts +26 -2
  331. package/dist/types/math/src/range.d.ts +1 -3
  332. package/dist/types/math/src/segment.d.ts +9 -3
  333. package/dist/types/math/src/types.d.ts +25 -1
  334. package/dist/types/utils/src/export.d.ts +9 -8
  335. package/dist/types/utils/src/index.d.ts +1 -2
  336. package/dist/types/utils/src/shape.d.ts +8 -8
  337. package/package.json +10 -3
  338. package/dist/types/excalidraw/animation-frame-handler.d.ts +0 -16
  339. package/dist/types/excalidraw/charts.d.ts +0 -27
  340. package/dist/types/excalidraw/components/DiagramToCodePlugin/DiagramToCodePlugin.d.ts +0 -4
  341. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -16
  342. package/dist/types/excalidraw/components/FollowMode/FollowMode.d.ts +0 -10
  343. package/dist/types/excalidraw/components/HandButton.d.ts +0 -10
  344. package/dist/types/excalidraw/components/InitializeApp.d.ts +0 -10
  345. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +0 -9
  346. package/dist/types/excalidraw/components/ToolButton.d.ts +0 -49
  347. package/dist/types/excalidraw/components/footer/FooterCenter.d.ts +0 -8
  348. package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -10
  349. package/dist/types/excalidraw/components/shapes.d.ts +0 -190
  350. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -58
  351. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Hints.d.ts +0 -19
  352. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +0 -85
  353. package/dist/types/excalidraw/cursor.d.ts +0 -5
  354. package/dist/types/excalidraw/data/reconcile.d.ts +0 -7
  355. package/dist/types/excalidraw/index.d.ts +0 -47
  356. package/dist/types/excalidraw/polyfill.d.ts +0 -2
  357. package/dist/types/excalidraw/scene/scroll.d.ts +0 -23
  358. package/dist/types/excalidraw/scene/zoom.d.ts +0 -12
  359. package/dist/types/utils/src/bbox.d.ts +0 -9
  360. package/dist/types/utils/src/withinBounds.d.ts +0 -19
@@ -1,27 +1,28 @@
1
- var mc=Object.create;var Ss=Object.defineProperty;var fc=Object.getOwnPropertyDescriptor;var hc=Object.getOwnPropertyNames;var Ec=Object.getPrototypeOf,gc=Object.prototype.hasOwnProperty;var xc=(e,t)=>()=>(e&&(t=e(e=0)),t);var wc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var yc=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of hc(t))!gc.call(e,o)&&o!==n&&Ss(e,o,{get:()=>t[o],enumerable:!(i=fc(t,o))||i.enumerable});return e};var bc=(e,t,n)=>(n=e!=null?mc(Ec(e)):{},yc(t||!e||!e.__esModule?Ss(n,"default",{value:e,enumerable:!0}):n,e));var A,P=xc(()=>{A={PROD:!0}});var Pd=wc((H1,bd)=>{P();var yd="Expected a function",xd=NaN,Wf="[object Symbol]",Vf=/^\s+|\s+$/g,$f=/^[-+]0x[0-9a-f]+$/i,Zf=/^0b[01]+$/i,qf=/^0o[0-7]+$/i,Kf=parseInt,Qf=typeof global=="object"&&global&&global.Object===Object&&global,Jf=typeof self=="object"&&self&&self.Object===Object&&self,eh=Qf||Jf||Function("return this")(),th=Object.prototype,nh=th.toString,ih=Math.max,oh=Math.min,os=function(){return eh.Date.now()};function rh(e,t,n){var i,o,r,s,a,l,d=0,c=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(yd);t=wd(t)||0,So(n)&&(c=!!n.leading,u="maxWait"in n,r=u?ih(wd(n.maxWait)||0,t):r,p="trailing"in n?!!n.trailing:p);function m(I){var M=i,D=o;return i=o=void 0,d=I,s=e.apply(D,M),s}function f(I){return d=I,a=setTimeout(g,t),c?m(I):s}function E(I){var M=I-l,D=I-d,T=t-M;return u?oh(T,r-D):T}function h(I){var M=I-l,D=I-d;return l===void 0||M>=t||M<0||u&&D>=r}function g(){var I=os();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),d=0,i=l=o=a=void 0}function b(){return a===void 0?s:x(os())}function w(){var I=os(),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 sh(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(yd);return So(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),rh(e,t,{leading:i,maxWait:t,trailing:o})}function So(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function ah(e){return!!e&&typeof e=="object"}function lh(e){return typeof e=="symbol"||ah(e)&&nh.call(e)==Wf}function wd(e){if(typeof e=="number")return e;if(lh(e))return xd;if(So(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=So(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Vf,"");var n=Zf.test(e);return n||qf.test(e)?Kf(e.slice(2),n?2:8):$f.test(e)?xd:+e}bd.exports=sh});P();import{toIterable as bE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Gt,viewportCoordsToSceneCoords as yo}from"@excalidraw/common";import{normalizeRadians as Jl,radiansBetweenAngles as bf,radiansDifference as Pf}from"@excalidraw/math";import{pointsEqual as If}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function Fo(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 Ic(e,t,n){let i=[];e.forEach(o=>i.push(...o)),Fo(i,t,n)}function Sc(e,t){return e[0]===t[0]&&e[1]===t[1]}function Ms(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)Fo(d,a,o);let l=Mc(s,r,i);if(o){for(let d of s)Fo(d,a,-o);Ic(l,a,-o)}return l}function Mc(e,t,n){let i=[];for(let d of e){let c=[...d];Sc(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],p=d[c+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((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,p=s[c].edge;o.push([[Math.round(u.x),a],[Math.round(p.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.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),Ms(e,o,i,r||1)}var Ot=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 hi=class extends Ot{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),d=i*.5*Math.sin(s);for(let[u,p]of r)Rt([u,p])&&a.push([[u[0]-l,u[1]+d],[...p]],[[u[0]+l,u[1]-d],[...p]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var Ei=class extends Ot{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 gi=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),d=l/o,c=Math.ceil(d)-1,u=l-c*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<c;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 xi=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)),d=(a+o-l*(i+o))/2,c=s[0],u=s[1];c[0]>u[0]&&(c=s[1],u=s[0]);let p=Math.atan((u[1]-c[1])/(u[0]-c[0]));for(let m=0;m<l;m++){let f=m*(i+o),E=f+i,h=[c[0]+f*Math.cos(p)+d*Math.cos(p),c[1]+f*Math.sin(p)+d*Math.sin(p)],g=[c[0]+E*Math.cos(p)+d*Math.cos(p),c[1]+E*Math.sin(p)+d*Math.sin(p)];r.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],n))}}),r}};P();var wi=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],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 p=u*2*n,m=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),E=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],h=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],g=[E[0]+f*Math.cos(c+Math.PI/4),E[1]+f*Math.sin(c+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 ve={};function Ts(e,t){let n=e.fillStyle||"hachure";if(!ve[n])switch(n){case"zigzag":ve[n]||(ve[n]=new hi(t));break;case"cross-hatch":ve[n]||(ve[n]=new Ei(t));break;case"dots":ve[n]||(ve[n]=new gi(t));break;case"dashed":ve[n]||(ve[n]=new xi(t));break;case"zigzag-line":ve[n]||(ve[n]=new wi(t));break;case"hachure":default:n="hachure",ve[n]||(ve[n]=new Ot(t));break}return ve[n]}P();function As(){return Math.floor(Math.random()*2**31)}var yi=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 bi={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 Tc(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 No(e,t){return e.type===t}function yn(e){let t=[],n=Tc(e),i="BOD",o=0,r=n[o];for(;!No(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=bi[r.text],i=r.text;else return yn("M0,0"+e);else No(r,1)?s=bi[i]:(o++,s=bi[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(No(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof bi[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 zn(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 Yn(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,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,...c]}),a=c[0],l=c[1],i=c[2],o=c[3];break}case"T":{let[u,p]=c,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]=c,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(c[0]),p=Math.abs(c[1]),m=c[2],f=c[3],E=c[4],h=c[5],g=c[6];u===0||p===0?(t.push({key:"C",data:[i,o,h,g,h,g]}),i=h,o=g):(i!==h||o!==g)&&(Ds(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=d}return t}function Ac(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 Ds(e,t,n,i,o,r,s,a,l,d){let c=Ac(s),u=[],p=0,m=0,f=0,E=0;if(d)[p,m,f,E]=d;else{[e,t]=_n(e,t,-c),[n,i]=_n(n,i,-c);let R=(e-n)/2,L=(t-i)/2,V=R*R/(o*o)+L*L/(r*r);V>1&&(V=Math.sqrt(V),o=V*o,r=V*r);let H=a===l?-1:1,te=o*o,S=r*r,Q=te*S-te*L*L-S*R*R,$=te*L*L+S*R*R,ne=H*Math.sqrt(Math.abs(Q/$));f=ne*o*L/r+(e+n)/2,E=ne*-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,V=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=Ds(n,i,L,V,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,D=[e,t],T=[e+I*x,t-M*g],N=[n+I*b,i-M*y],C=[n,i];if(T[0]=2*D[0]-T[0],T[1]=2*D[1]-T[1],d)return[T,N,C].concat(u);{u=[T,N,C].concat(u);let R=[];for(let L=0;L<u.length;L+=3){let V=_n(u[L][0],u[L][1],c),H=_n(u[L+1][0],u[L+1][1],c),te=_n(u[L+2][0],u[L+2][1],c);R.push([V[0],V[1],H[0],H[1],te[0],te[1]])}return R}}var Dc={randOffset:Cc,randOffsetWithRange:Gc,ellipse:Lc,doubleLineOps:Bc};function Ho(e,t,n,i,o){return{type:"path",ops:ht(e,t,n,i,o)}}function Un(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 Ho(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function vc(e,t){return Un(e,!0,t)}function Bs(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return vc(r,o)}function zo(e,t){let n=Ls(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=Ls(e,1.5*(1+t.roughness*.22),kc(t));n=n.concat(i)}return{type:"path",ops:n}}function Lc(e,t,n,i,o){let r=_o(n,i,o);return Si(e,t,o,r).opset}function _o(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+=k(s*l,n),a+=k(a*l,n),{increment:r,rx:s,ry:a}}function Si(e,t,n,i){let[o,r]=Cs(i.increment,e,t,i.rx,i.ry,1,i.increment*Pi(.1,Pi(.4,1,n),n),n),s=Ii(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=Cs(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Ii(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Yo(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),p=Math.abs(i/2);u+=k(u*.01,l),p+=k(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=Gs(h,d,c,u,p,m,f,1,l);if(!l.disableMultiStroke){let x=Gs(h,d,c,u,p,m,f,1.5,l);g.push(...x)}return s&&(a?g.push(...ht(d,c,d+u*Math.cos(m),c+p*Math.sin(m),l),...ht(d,c,d+u*Math.cos(f),c+p*Math.sin(f),l)):g.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(m),c+p*Math.sin(m)]})),{type:"path",ops:g}}function Uo(e,t){let n=Yn(zn(yn(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,d,c,u,p,m]=a;i.push(...Oc(l,d,c,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 Mi(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]+k(o,t),i[0][1]+k(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+k(o,t),i[s][1]+k(o,t)]})}}return{type:"fillPath",ops:n}}function dn(e,t){return Ts(t,Dc).fillPolygons(e,t)}function ks(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=k(d*.01,s),c+=k(c*.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+d*Math.cos(E),l+c*Math.sin(E)]);return f.push([a+d*Math.cos(p),l+c*Math.sin(p)]),f.push([a,l]),dn([f],s)}function Cc(e,t){return k(e,t)}function Gc(e,t,n){return Pi(e,t,n)}function Bc(e,t,n,i,o){return ht(e,t,n,i,o,!0)}function kc(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Os(e){return e.randomizer||(e.randomizer=new yi(e.seed||0)),e.randomizer.next()}function Pi(e,t,n,i=1){return n.roughness*i*(Os(n)*(t-e)+e)}function k(e,t,n=1){return Pi(-e,e,t,n)}function ht(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=vs(e,t,n,i,o,!0,!1);if(s)return a;let l=vs(e,t,n,i,o,!0,!0);return a.concat(l)}function vs(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,p=.2+Os(o)*.2,m=o.bowing*o.maxRandomnessOffset*(i-t)/200,f=o.bowing*o.maxRandomnessOffset*(e-n)/200;m=k(m,o,d),f=k(f,o,d);let E=[],h=()=>k(u,o,d),g=()=>k(c,o,d),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:k(c,o,d)),t+(x?0:k(c,o,d))]})),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 Ls(e,t,n){let i=[];i.push([e[0][0]+k(t,n),e[0][1]+k(t,n)]),i.push([e[0][0]+k(t,n),e[0][1]+k(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+k(t,n),e[o][1]+k(t,n)]),o===e.length-1&&i.push([e[o][0]+k(t,n),e[o][1]+k(t,n)]);return Ii(i,null,n)}function Ii(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]+k(a,n),t[1]+k(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 Cs(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 p=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(p),c.push(p)}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=k(.5,a)-Math.PI/2;c.push([k(r,a)+t+.9*i*Math.cos(u-e),k(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=[k(r,a)+t+i*Math.cos(m),k(r,a)+n+o*Math.sin(m)];d.push(f),c.push(f)}c.push([k(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),k(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([k(r,a)+t+.98*i*Math.cos(u+s),k(r,a)+n+.98*o*Math.sin(u+s)]),c.push([k(r,a)+t+.9*i*Math.cos(u+s*.5),k(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function Gs(e,t,n,i,o,r,s,a,l){let d=r+k(.1,l),c=[];c.push([k(a,l)+t+.9*i*Math.cos(d-e),k(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([k(a,l)+t+i*Math.cos(u),k(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)]),Ii(c,null,l)}function Oc(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,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:k(d[0],a)),s[1]+(p?0:k(d[0],a))]}),c=p?[o,r]:[o+k(d[m],a),r+k(d[m],a)],l.push({op:"bcurveTo",data:[e+k(d[m],a),t+k(d[m],a),n+k(d[m],a),i+k(d[m],a),c[0],c[1]]});return l}P();function Xn(e){return[...e]}function Rs(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(Xn(e[0]),Xn(e[1]),Xn(e[2]),Xn(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(Xn(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 Rc(e,t){return Math.sqrt(Ti(e,t))}function Ti(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Fc(e,t,n){let i=Ti(t,n);if(i===0)return Ti(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)),Ti(e,cn(t,n,o))}function cn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Nc(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 Xo(e,t,n,i){let o=i||[];if(Nc(e,t)<n){let r=e[t+0];o.length?Rc(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=cn(s,a,.5),u=cn(a,l,.5),p=cn(l,d,.5),m=cn(c,u,.5),f=cn(u,p,.5),E=cn(m,f,.5);Xo([s,c,m,E],0,n,o),Xo([E,f,p,d],0,n,o)}return o}function jn(e,t){return Ai(e,0,e.length,t)}function Ai(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=Fc(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(Ai(e,t,d+1,i,r),Ai(e,d,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;Xo(e,s,t,i)}return n&&n>0?Ai(i,0,i.length,n):i}P();function Fs(e,t,n){let i=yn(e),o=Yn(zn(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Et(l,t)),l=[]},c=()=>{d(),s.length&&(r.push(s),s=[])};for(let{key:p,data:m}of o)switch(p){case"M":c(),a=[m[0],m[1]],s.push(a);break;case"L":d(),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":d(),s.push([a[0],a[1]]);break}if(c(),!n)return r;let u=[];for(let p of r){let m=jn(p,n);m.length&&u.push(m)}return u}var Ne="none",je=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 As()}_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",[Ho(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=Bs(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(Mi([d],s)):a.push(dn([d],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=_o(i,o,s),d=Si(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Si(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(dn([d.estimatedPoints],s));return s.stroke!==Ne&&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",[Un(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=Yo(t,n,i,o,r,s,a,!0,d);if(a&&d.fill)if(d.fillStyle==="solid"){let p=Object.assign({},d);p.disableMultiStroke=!0;let m=Yo(t,n,i,o,r,s,!0,!1,p);m.type="fillPath",c.push(m)}else c.push(ks(t,n,i,o,r,s,d));return d.stroke!==Ne&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=zo(t,i);if(i.fill&&i.fill!==Ne&&t.length>=3)if(i.fillStyle==="solid"){let s=zo(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=Rs(t),a=Et(s,10,(1+i.roughness)/2);o.push(dn([a],i))}return i.stroke!==Ne&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=Un(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(Mi([t],i)):o.push(dn([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,d=Fs(t,1,l),c=Uo(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=Uo(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(Mi(d,i));else o.push(dn(d,i));return s&&(a?d.forEach(u=>{o.push(Un(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: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 Di=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new je(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 Wn="http://www.w3.org/2000/svg";var vi=class{constructor(t,n){this.svg=t,this.gen=new je(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(Wn,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(Wn,"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(Wn,"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(Wn,"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 un={canvas(e,t){return new Di(e,t)},svg(e,t){return new vi(e,t)},generator(e){return new je(e)},newSeed(){return je.newSeed()}};import{arrayToMap as Kl,invariant as jr,rescalePoints as Wl,sizeOf as pf}from"@excalidraw/common";import{degreesToRadians as Xr,lineSegment as ge,pointDistance as mf,pointFrom as v,pointFromArray as Ql,pointRotateRads as se}from"@excalidraw/math";P();import{invariant as Hc}from"@excalidraw/common";import{curve as zc,lineSegment as _c,pointFrom as le,pointDistance as sx,pointFromArray as Yc,pointFromVector as Uc,pointRotateRads as qe,polygon as Ns,polygonFromPoints as jo,PRECISION as ax,segmentsIntersectAt as lx,vector as Xc,vectorAdd as jc,vectorFromPoint as Wc,vectorScale as dx}from"@excalidraw/math";import{getElementAbsoluteCoords as ux}from"@excalidraw/element";var Hs=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=Ns(qe(le(s,r),l,t),qe(le(o+n,a),l,t),qe(le(s,r+i),l,t),qe(le(o,a),l,t)):d=Ns(qe(le(o,r),l,t),qe(le(o+n,r),l,t),qe(le(o+n,r+i),l,t),qe(le(o,r+i),l,t)),{type:"polygon",data:d}};var zs=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},_s=(e,t=le(0,0),n,i)=>{let o=l=>qe(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 d=Yc(l.data);Hc(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(zc(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Vc=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(_c(t,o)),t=o}return n},Ys=(e,t,n=!1)=>{let i=r=>qe(Uc(jc(Wc(r),Xc(e.x,e.y))),t,e.angle),o=Vc(e.points.map(r=>i(r)));return n?{type:"polygon",data:jo(o.flat())}:{type:"polyline",data:o}},Us=(e,t,n=le(0,0),i,o)=>{let r=c=>qe(le(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:jo(e.points.map(c=>r(c)))};let s=gt(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=Et(a,10,5).map(c=>r(c));return{type:"polygon",data:jo(d)}};P();import{pointFrom as de,pointDistance as zl,pointRotateRads as Lt}from"@excalidraw/math";import{ROUGHNESS as rf,isTransparent as li,assertNever as sf,COLOR_PALETTE as af,LINE_POLYGON_POINT_MERGE_DISTANCE as lf}from"@excalidraw/common";P();P();function Xs(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function $c(e){return[-e[0],-e[1]]}function Qe(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 Ke(e,t){return[e[0]*t,e[1]*t]}function Zc(e,t){return[e[0]/t,e[1]/t]}function Vn(e){return[e[1],-e[0]]}function js(e,t){return e[0]*t[0]+e[1]*t[1]}function qc(e,t){return e[0]===t[0]&&e[1]===t[1]}function Kc(e){return Math.hypot(e[0],e[1])}function Qc(e){return e[0]*e[0]+e[1]*e[1]}function Ws(e,t){return Qc(We(e,t))}function Zs(e){return Zc(e,Kc(e))}function Jc(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 Wo(e,t,n){return Qe(e,Ke(We(t,e),n))}function Vs(e,t,n){return Qe(e,Ke(t,n))}var{min:bn,PI:eu}=Math,$s=.275,Zn=eu+1e-4;function tu(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=S=>S,start:a={},end:l={},last:d=!1}=t,{cap:c=!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,Q)=>{let $=Q.pressure;if(r){let ne=bn(1,Q.distance/n),sn=bn(1,1-ne);$=bn(1,S+(sn-S)*(ne*$s))}return(S+$)/2},e[0].pressure),w=Xs(n,o,e[e.length-1].pressure,s),I,M=e[0].vector,D=e[0].point,T=D,N=D,C=T,R=!1;for(let S=0;S<e.length;S++){let{pressure:Q}=e[S],{point:$,vector:ne,distance:sn,runningLength:ot}=e[S];if(S<e.length-1&&f-ot<3)continue;if(o){if(r){let xe=bn(1,sn/n),ln=bn(1,1-xe);Q=bn(1,b+(ln-b)*(xe*$s))}w=Xs(n,o,Q,s)}else w=n/2;I===void 0&&(I=w);let wn=ot<E?u(ot/E):1,Oo=f-ot<h?m((f-ot)/h):1;w=Math.max(.01,w*Math.min(wn,Oo));let mi=(S<e.length-1?e[S+1]:e[S]).vector,Hn=S<e.length-1?js(ne,mi):1,Ro=js(ne,M)<0&&!R,fi=Hn!==null&&Hn<0;if(Ro||fi){let xe=Ke(Vn(M),w);for(let ln=1/13,De=0;De<=1;De+=ln)N=$n(We($,xe),$,Zn*De),x.push(N),C=$n(Qe($,xe),$,Zn*-De),y.push(C);D=N,T=C,fi&&(R=!0);continue}if(R=!1,S===e.length-1){let xe=Ke(Vn(ne),w);x.push(We($,xe)),y.push(Qe($,xe));continue}let an=Ke(Vn(Wo(mi,ne,Hn)),w);N=We($,an),(S<=1||Ws(D,N)>g)&&(x.push(N),D=N),C=Qe($,an),(S<=1||Ws(T,C)>g)&&(y.push(C),T=C),b=Q,M=ne}let L=e[0].point.slice(0,2),V=e.length>1?e[e.length-1].point.slice(0,2):Qe(e[0].point,[1,1]),H=[],te=[];if(e.length===1){if(!(E||h)||d){let S=Vs(L,Zs(Vn(We(L,V))),-(I||w)),Q=[];for(let $=1/13,ne=$;ne<=1;ne+=$)Q.push($n(S,L,Zn*2*ne));return Q}}else{if(!(E||h&&e.length===1))if(c)for(let Q=1/13,$=Q;$<=1;$+=Q){let ne=$n(y[0],L,Zn*$);H.push(ne)}else{let Q=We(x[0],y[0]),$=Ke(Q,.5),ne=Ke(Q,.51);H.push(We(L,$),We(L,ne),Qe(L,ne),Qe(L,$))}let S=Vn($c(e[e.length-1].vector));if(h||E&&e.length===1)te.push(V);else if(p){let Q=Vs(V,S,w);for(let $=1/29,ne=$;ne<1;ne+=$)te.push($n(Q,V,Zn*3*ne))}else te.push(Qe(V,Ke(S,w)),Qe(V,Ke(S,w*.99)),We(V,Ke(S,w*.99)),We(V,Ke(S,w)))}return x.concat(te,y.reverse(),H)}function nu(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(Wo(a[0],m,f/4))}a.length===1&&(a=[...a,[...Qe(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],p=a.length-1;for(let m=1;m<a.length;m++){let f=r&&m===p?a[m].slice(0,2):Wo(u.point,a[m],s);if(qc(u.point,f))continue;let E=Jc(f,u.point);if(c+=E,m<p&&!d){if(c<o)continue;d=!0}u={point:f,pressure:a[m][2]>=0?a[m][2]:.5,vector:Zs(We(u.point,f)),distance:E,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function qs(e,t={}){return tu(nu(e,t),t)}import{isRightAngleRads as Ym,lineSegment as Dl,pointFrom as fo,pointRotateRads as zr}from"@excalidraw/math";import{BOUND_TEXT_PADDING as ho,DEFAULT_REDUCED_GLOBAL_ALPHA as Um,ELEMENT_READY_TO_ERASE_OPACITY as Xm,FRAME_STYLE as Eo,MIME_TYPES as Yr,THEME as Cl,distance as Qt,getFontString as jm,isRTL as Wm,getVerticalOffset as Vm,invariant as $m}from"@excalidraw/common";P();import{pointFrom as xt,pointCenter as iu,pointRotateRads as Ft,vectorFromPoint as Vo,vectorNormalize as Ks,vectorSubtract as Qs,vectorAdd as Li,vectorScale as Ci,pointFromVector as Js,clamp as Ie,isCloseTo as ea}from"@excalidraw/math";var Se=10,xx=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=$o(e),c=i/l,u=o/d,p=(e.crop?.x??0)/c,m=(e.crop?.y??0)/u,f=Ft(xt(r,s),he(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=Ie(e.height-I,Se,w?d-m:e.height+m)),n.includes("s")&&(I=s-e.y-e.height,h=Ie(e.height+I,Se,w?e.height+m:d-m)),n.includes("e")&&(M=r-e.x-e.width,E=Ie(e.width+M,Se,b?e.width+p:l-p)),n.includes("w")&&(E=Ie(e.width-M,Se,b?l-p:e.width+p));let D=C=>{C.height=h*u,C.width=E*c};D(g);let T=(C,R)=>{D(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=Ie(h*a,Se,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=Ie(h*a,Se,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=d-m-e.height/2,L=Math.min(C,R)*2;h=Ie(E/a,Se,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=d-m-e.height/2,L=Math.min(C,R)*2;h=Ie(E/a,Se,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?d-m:m+e.height;h=Ie(E/a,Se,C),E=h*a}else{let C=b?p+e.width:l-p;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"nw":{if(a)if(M<I){let C=w?d-m:m+e.height;h=Ie(E/a,Se,C),E=h*a}else{let C=b?l-p:p+e.width;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"se":{if(a)if(M>I){let C=w?m+e.height:d-m;h=Ie(E/a,Se,C),E=h*a}else{let C=b?p+e.width:l-p;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"sw":{if(a)if(-M>I){let C=w?m+e.height:d-m;h=Ie(E/a,Se,C),E=h*a}else{let C=b?l-p:p+e.width;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}default:break}let N=ou(e,n,E,h,!!a);return ea(g.width,g.naturalWidth)&&ea(g.height,g.naturalHeight)&&(g=null),{x:N[0],y:N[1],width:E,height:h,crop:g}},ou=(e,t,n,i,o)=>{let[r,s,a,l]=Nt(e,e.width,e.height,!0),d=xt(r,s),c=xt(a,l),u=iu(d,c),[p,m,f,E]=Nt(e,n,i,!0),h=f-p,g=E-m,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(h),c[1]-Math.abs(g)]),t==="ne"){let D=[d[0],c[1]];x=[D[0],D[1]-Math.abs(g)]}if(t==="sw"){let D=[c[0],d[1]];x=[D[0]-Math.abs(h),D[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},ta=(e,t)=>{if(e.crop){let{width:n,height:i}=$o(e),[o,r,s,a,l,d]=_(e,t),c=Vo(Ft(xt(o,r),xt(l,d),e.angle)),u=Vo(Ft(xt(s,r),xt(l,d),e.angle)),p=Ks(Qs(u,c)),m=Vo(Ft(xt(o,a),xt(l,d),e.angle)),f=Qs(m,c),E=Ks(f),{cropX:h,cropY:g}=ru(e.crop,e.scale),x=Li(Li(c,Ci(p,-h*n/e.crop.naturalWidth)),Ci(E,-g*i/e.crop.naturalHeight)),y=Js(Li(Li(x,Ci(p,n/2)),Ci(E,i/2))),b=Ft(Js(x),y,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:i,crop:null}}return e},$o=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}},ru=(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}},wx=(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}=$o(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as el,pointFrom as G,pointRotateRads as Te,pointsEqual as tl,pointDistance as Cn,vectorFromPoint as rm,curveLength as sm,curvePointAtLength as am}from"@excalidraw/math";import{DRAGGING_THRESHOLD as lm,KEYS as Gn,shouldRotateWithDiscreteAngle as nl,getGridPoint as il,invariant as At,tupleToCoors as Lr,viewportCoordsToSceneCoords as dm}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as ol,isPathALoop as cm}from"@excalidraw/element";P();import{KEYS as Bp,arrayToMap as Ua,isBindingFallthroughEnabled as no,tupleToCoors as kp,invariant as Op,isDevEnv as Rp,isTestEnv as Fp}from"@excalidraw/common";import{lineSegment as Ye,pointFrom as O,pointRotateRads as ae,vectorFromPoint as q,pointDistanceSq as Wt,clamp as Ha,pointDistance as ut,pointFromVector as vn,vectorScale as Ln,vectorNormalize as si,vectorCross as _e,pointsEqual as Np,lineSegmentIntersectionPoints as za,PRECISION as Hp}from"@excalidraw/math";P();import{isTransparent as Zu}from"@excalidraw/common";import{curveIntersectLineSegment as Ia,isPointWithinBounds as Ui,lineSegment as Xi,lineSegmentIntersectionPoints as Sa,pointFrom as St,pointFromVector as qu,pointRotateRads as lt,pointsEqual as Ku,vectorFromPoint as Qu,vectorNormalize as Ju,vectorScale as ep}from"@excalidraw/math";import{ellipse as tp,ellipseSegmentInterceptPoints as np}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as su,DEFAULT_PROPORTIONAL_RADIUS as Zo,LINE_CONFIRM_THRESHOLD as au,ROUNDNESS as qo}from"@excalidraw/common";import{curve as wt,curveCatmullRomCubicApproxPoints as na,curveOffsetPoints as ia,lineSegment as He,pointDistance as lu,pointFrom as X,pointFromArray as du,rectangle as cu}from"@excalidraw/math";var qn=new WeakMap,Ko=(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 Gi(e){let t=Ko(e,0);if(t)return t;let n=oa(e),i=[],o=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&du(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");i.push(He(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 Pn(e,t=0){let n=Ko(e,t);if(n)return n;let i=yt(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=cu(X(e.x,e.y),X(e.x+e.width,e.y+e.height)),r=He(X(o[0][0]+i,o[0][1]),X(o[1][0]-i,o[0][1])),s=He(X(o[1][0],o[0][1]+i),X(o[1][0],o[1][1]-i)),a=He(X(o[0][0]+i,o[1][1]),X(o[1][0]-i,o[1][1])),l=He(X(o[0][0],o[1][1]-i),X(o[0][0],o[0][1]+i)),d=[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])],c=t>0?d.map(m=>na(ia(m,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],p=[[He(c[0][c[0].length-1][3],c[1][0][0]),He(c[1][c[1].length-1][3],c[2][0][0]),He(c[2][c[2].length-1][3],c[3][0][0]),He(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Qo(e,p,t),p}function In(e,t=0){let n=Ko(e,t);if(n)return n;let[i,o,r,s,a,l,d,c]=Bi(e),u=e.roundness?yt(Math.abs(i-d),e):(i-d)*.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+d,e.y+c)],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=>na(ia(w,t))):[[g[0]],[g[1]],[g[2]],[g[3]]],b=[[He(x[0][x[0].length-1][3],x[1][0][0]),He(x[1][x[1].length-1][3],x[2][0][0]),He(x[2][x[2].length-1][3],x[3][0][0]),He(x[3][x[3].length-1][3],x[0][0][0])],x.flat()];return Qo(e,b,t),b}var pn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return lu(n,i)<=au/t}return!1},yt=(e,t)=>{if(t.roundness?.type===qo.PROPORTIONAL_RADIUS||t.roundness?.type===qo.LEGACY)return e*Zo;if(t.roundness?.type===qo.ADAPTIVE_RADIUS){let n=t.roundness?.value??su,i=n/Zo;return e<=i?e*Zo:n}return 0};P();import{ROUNDNESS as Kn,assertNever as uu}from"@excalidraw/common";import{pointsEqual as ra}from"@excalidraw/math";var Ht=e=>!!e&&e.type==="image"&&!!e.fileId,we=e=>!!e&&e.type==="image",sa=e=>!!e&&e.type==="embeddable",ki=e=>!!e&&e.type==="iframe",Oi=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),ie=e=>e!=null&&e.type==="text",Ri=e=>e!=null&&e.type==="frame",aa=e=>e!=null&&e.type==="magicframe",Z=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Me=e=>e!=null&&pu(e.type),pu=e=>e==="freedraw",j=e=>e!=null&&Jo(e.type),mn=e=>e!=null&&e.type==="line",Y=e=>e!=null&&e.type==="arrow",B=e=>Y(e)&&e.elbowed,Lx=e=>Y(e)&&!e.elbowed,mu=e=>Y(e)&&!e.elbowed&&!e.roundness,fu=e=>Y(e)&&!e.elbowed&&e.roundness!==null,Jo=e=>e==="arrow"||e==="line",er=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&hu(e.type),hu=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),la=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),Cx=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"),Eu=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||Y(e)),Gx=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 uu(t,null),!1}},tr=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",st=e=>Eu(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),ce=e=>e!==null&&"containerId"in e&&e.containerId!==null&&ie(e),Bx=e=>!!e.startBinding||!!e.endBinding,da=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",ca=e=>e==="line"||e==="arrow"||e==="diamond",kx=(e,t)=>!!((e===Kn.ADAPTIVE_RADIUS||e===Kn.LEGACY)&&da(t.type)||e===Kn.PROPORTIONAL_RADIUS&&ca(t.type)),Ox=e=>ca(e.type)?{type:Kn.PROPORTIONAL_RADIUS}:da(e.type)?{type:Kn.ADAPTIVE_RADIUS}:null,Qn=e=>Object.hasOwn(e,"fixedPoint")&&e.fixedPoint!=null,Rx=e=>Array.isArray(e)&&e.length===4&&typeof e[0]=="number"&&typeof e[1]=="number"&&typeof e[2]=="number"&&typeof e[3]=="number",Fx=e=>mu(e)?"sharpArrow":fu(e)?"curvedArrow":B(e)?"elbowArrow":"line",Nx=e=>e.length>3&&ra(e[0],e[e.length-1]),ua=e=>e.length>3||e.length===3&&!ra(e[0],e[e.length-1]);P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Ru,ARROW_LABEL_WIDTH_FRACTION as Fu,BOUND_TEXT_PADDING as at,DEFAULT_FONT_SIZE as Nu,TEXT_ALIGN as xa,VERTICAL_ALIGN as wa,getFontString as Yi,isProdEnv as Hu,invariant as zu}from"@excalidraw/common";import{pointFrom as ya,pointRotateRads as _u}from"@excalidraw/math";P();var Jn={},pa=(e,t)=>{let n=Jn[e]||(Jn[e]={height:t});return n.height=t,n},ma=e=>{Jn[e]&&delete Jn[e]},_x=e=>Jn[e]?.height??null;P();import{BOUND_TEXT_PADDING as Ni,DEFAULT_FONT_SIZE as gu,DEFAULT_FONT_FAMILY as xu,getFontString as wu,isTestEnv as yu,normalizeEOL as bu}from"@excalidraw/common";var Je=(e,t,n)=>{let i=e.split(`
1
+ var up=Object.create;var Pl=Object.defineProperty;var mp=Object.getOwnPropertyDescriptor;var pp=Object.getOwnPropertyNames;var fp=Object.getPrototypeOf,hp=Object.prototype.hasOwnProperty;var gp=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ep=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var xp=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of pp(t))!hp.call(e,o)&&o!==n&&Pl(e,o,{get:()=>t[o],enumerable:!(i=mp(t,o))||i.enumerable});return e};var bp=(e,t,n)=>(n=e!=null?up(fp(e)):{},xp(t||!e||!e.__esModule?Pl(n,"default",{value:e,enumerable:!0}):n,e));var G,M=gp(()=>{G={PROD:!0}});var mm=Ep((vD,um)=>{M();var cm="Expected a function",lm=NaN,gb="[object Symbol]",Eb=/^\s+|\s+$/g,xb=/^[-+]0x[0-9a-f]+$/i,bb=/^0b[01]+$/i,yb=/^0o[0-7]+$/i,wb=parseInt,Pb=typeof global=="object"&&global&&global.Object===Object&&global,Sb=typeof self=="object"&&self&&self.Object===Object&&self,Ib=Pb||Sb||Function("return this")(),Mb=Object.prototype,Tb=Mb.toString,Ab=Math.max,Db=Math.min,Qa=function(){return Ib.Date.now()};function vb(e,t,n){var i,o,r,s,a,l,d=0,c=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(cm);t=dm(t)||0,Fr(n)&&(c=!!n.leading,u="maxWait"in n,r=u?Ab(dm(n.maxWait)||0,t):r,p="trailing"in n?!!n.trailing:p);function m(S){var I=i,A=o;return i=o=void 0,d=S,s=e.apply(A,I),s}function h(S){return d=S,a=setTimeout(E,t),c?m(S):s}function f(S){var I=S-l,A=S-d,T=t-I;return u?Db(T,r-A):T}function g(S){var I=S-l,A=S-d;return l===void 0||I>=t||I<0||u&&A>=r}function E(){var S=Qa();if(g(S))return x(S);a=setTimeout(E,f(S))}function x(S){return a=void 0,p&&i?m(S):(i=o=void 0,s)}function b(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function y(){return a===void 0?s:x(Qa())}function w(){var S=Qa(),I=g(S);if(i=arguments,o=this,l=S,I){if(a===void 0)return h(l);if(u)return a=setTimeout(E,t),m(l)}return a===void 0&&(a=setTimeout(E,t)),s}return w.cancel=b,w.flush=y,w}function Bb(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(cm);return Fr(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),vb(e,t,{leading:i,maxWait:t,trailing:o})}function Fr(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Lb(e){return!!e&&typeof e=="object"}function Cb(e){return typeof e=="symbol"||Lb(e)&&Tb.call(e)==gb}function dm(e){if(typeof e=="number")return e;if(Cb(e))return lm;if(Fr(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Fr(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Eb,"");var n=bb.test(e);return n||yb.test(e)?wb(e.slice(2),n?2:8):xb.test(e)?lm:+e}um.exports=Bb});M();import{toIterable as _w}from"@excalidraw/common";M();import{SHIFT_LOCKING_ANGLE as fn,viewportCoordsToSceneCoords as vr}from"@excalidraw/common";import{normalizeRadians as vu,radiansBetweenAngles as mx,radiansDifference as px}from"@excalidraw/math";import{pointsEqual as fx}from"@excalidraw/math";M();M();M();M();M();M();M();M();M();function qr(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 wp(e,t,n){let i=[];e.forEach(o=>i.push(...o)),qr(i,t,n)}function Pp(e,t){return e[0]===t[0]&&e[1]===t[1]}function Sl(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)qr(d,a,o);let l=Sp(s,r,i);if(o){for(let d of s)qr(d,a,-o);wp(l,a,-o)}return l}function Sp(e,t,n){let i=[];for(let d of e){let c=[...d];Pp(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],p=d[c+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((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,p=s[c].edge;o.push([[Math.round(u.x),a],[Math.round(p.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.edge.islope}),l++}return o}function Ut(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),Sl(e,o,i,r||1)}var yn=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=Ut(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}};M();M();function wn(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 To=class extends yn{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=Ut(t,o),s=Math.PI/180*n.hachureAngle,a=[],l=i*.5*Math.cos(s),d=i*.5*Math.sin(s);for(let[u,p]of r)wn([u,p])&&a.push([[u[0]-l,u[1]+d],[...p]],[[u[0]+l,u[1]-d],[...p]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};M();var Ao=class extends yn{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}};M();var Do=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=Ut(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=wn(a),d=l/o,c=Math.ceil(d)-1,u=l-c*o,p=(a[0][0]+a[1][0])/2-o/4,m=Math.min(a[0][1],a[1][1]);for(let h=0;h<c;h++){let f=m+u+h*o,g=p-s+Math.random()*2*s,E=f-s+Math.random()*2*s,x=this.helper.ellipse(g,E,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};M();var vo=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=Ut(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=wn(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 p=Math.atan((u[1]-c[1])/(u[0]-c[0]));for(let m=0;m<l;m++){let h=m*(i+o),f=h+i,g=[c[0]+h*Math.cos(p)+d*Math.cos(p),c[1]+h*Math.sin(p)+d*Math.sin(p)],E=[c[0]+f*Math.cos(p)+d*Math.cos(p),c[1]+f*Math.sin(p)+d*Math.sin(p)];r.push(...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],n))}}),r}};M();var Bo=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=Ut(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=wn(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 p=u*2*n,m=(u+1)*2*n,h=Math.sqrt(2*Math.pow(n,2)),f=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],g=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],E=[f[0]+h*Math.cos(c+Math.PI/4),f[1]+h*Math.sin(c+Math.PI/4)];o.push(...this.helper.doubleLineOps(f[0],f[1],E[0],E[1],i),...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],i))}}),o}};var at={};function Il(e,t){let n=e.fillStyle||"hachure";if(!at[n])switch(n){case"zigzag":at[n]||(at[n]=new To(t));break;case"cross-hatch":at[n]||(at[n]=new Ao(t));break;case"dots":at[n]||(at[n]=new Do(t));break;case"dashed":at[n]||(at[n]=new vo(t));break;case"zigzag-line":at[n]||(at[n]=new Bo(t));break;case"hachure":default:n="hachure",at[n]||(at[n]=new yn(t));break}return at[n]}M();function Ml(){return Math.floor(Math.random()*2**31)}var Lo=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};M();M();var Co={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 Ip(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 Qr(e,t){return e.type===t}function Ei(e){let t=[],n=Ip(e),i="BOD",o=0,r=n[o];for(;!Qr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=Co[r.text],i=r.text;else return Ei("M0,0"+e);else Qr(r,1)?s=Co[i]:(o++,s=Co[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(Qr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof Co[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}M();function Wi(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}M();function Xi(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,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,...c]}),a=c[0],l=c[1],i=c[2],o=c[3];break}case"T":{let[u,p]=c,m=0,h=0;n==="Q"||n==="T"?(m=i+(i-a),h=o+(o-l)):(m=i,h=o);let f=i+2*(m-i)/3,g=o+2*(h-o)/3,E=u+2*(m-u)/3,x=p+2*(h-p)/3;t.push({key:"C",data:[f,g,E,x,u,p]}),a=m,l=h,i=u,o=p;break}case"Q":{let[u,p,m,h]=c,f=i+2*(u-i)/3,g=o+2*(p-o)/3,E=m+2*(u-m)/3,x=h+2*(p-h)/3;t.push({key:"C",data:[f,g,E,x,m,h]}),a=u,l=p,i=m,o=h;break}case"A":{let u=Math.abs(c[0]),p=Math.abs(c[1]),m=c[2],h=c[3],f=c[4],g=c[5],E=c[6];u===0||p===0?(t.push({key:"C",data:[i,o,g,E,g,E]}),i=g,o=E):(i!==g||o!==E)&&(Tl(i,o,g,E,u,p,m,h,f).forEach(function(b){t.push({key:"C",data:b})}),i=g,o=E);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function Mp(e){return Math.PI*e/180}function Yi(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 Tl(e,t,n,i,o,r,s,a,l,d){let c=Mp(s),u=[],p=0,m=0,h=0,f=0;if(d)[p,m,h,f]=d;else{[e,t]=Yi(e,t,-c),[n,i]=Yi(n,i,-c);let N=(e-n)/2,k=(t-i)/2,z=N*N/(o*o)+k*k/(r*r);z>1&&(z=Math.sqrt(z),o=z*o,r=z*r);let U=a===l?-1:1,D=o*o,B=r*r,P=D*B-D*k*k-B*N*N,L=D*k*k+B*N*N,C=U*Math.sqrt(Math.abs(P/L));h=C*o*k/r+(e+n)/2,f=C*-r*N/o+(t+i)/2,p=Math.asin(parseFloat(((t-f)/r).toFixed(9))),m=Math.asin(parseFloat(((i-f)/r).toFixed(9))),e<h&&(p=Math.PI-p),n<h&&(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 g=m-p;if(Math.abs(g)>Math.PI*120/180){let N=m,k=n,z=i;l&&m>p?m=p+Math.PI*120/180*1:m=p+Math.PI*120/180*-1,n=h+o*Math.cos(m),i=f+r*Math.sin(m),u=Tl(n,i,k,z,o,r,s,0,l,[m,N,h,f])}g=m-p;let E=Math.cos(p),x=Math.sin(p),b=Math.cos(m),y=Math.sin(m),w=Math.tan(g/4),S=4/3*o*w,I=4/3*r*w,A=[e,t],T=[e+S*x,t-I*E],O=[n+S*y,i-I*b],v=[n,i];if(T[0]=2*A[0]-T[0],T[1]=2*A[1]-T[1],d)return[T,O,v].concat(u);{u=[T,O,v].concat(u);let N=[];for(let k=0;k<u.length;k+=3){let z=Yi(u[k][0],u[k][1],c),U=Yi(u[k+1][0],u[k+1][1],c),D=Yi(u[k+2][0],u[k+2][1],c);N.push([z[0],z[1],U[0],U[1],D[0],D[1]])}return N}}var Tp={randOffset:vp,randOffsetWithRange:Bp,ellipse:Dp,doubleLineOps:Lp};function Jr(e,t,n,i,o){return{type:"path",ops:Qt(e,t,n,i,o)}}function ji(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Qt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Qt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return Jr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Ap(e,t){return ji(e,!0,t)}function Ll(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Ap(r,o)}function es(e,t){let n=Dl(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=Dl(e,1.5*(1+t.roughness*.22),Cp(t));n=n.concat(i)}return{type:"path",ops:n}}function Dp(e,t,n,i,o){let r=ts(n,i,o);return Oo(e,t,o,r).opset}function ts(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+=j(s*l,n),a+=j(a*l,n),{increment:r,rx:s,ry:a}}function Oo(e,t,n,i){let[o,r]=vl(i.increment,e,t,i.rx,i.ry,1,i.increment*ko(.1,ko(.4,1,n),n),n),s=No(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=vl(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=No(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function ns(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),p=Math.abs(i/2);u+=j(u*.01,l),p+=j(p*.01,l);let m=o,h=r;for(;m<0;)m+=Math.PI*2,h+=Math.PI*2;h-m>Math.PI*2&&(m=0,h=Math.PI*2);let f=Math.PI*2/l.curveStepCount,g=Math.min(f/2,(h-m)/2),E=Bl(g,d,c,u,p,m,h,1,l);if(!l.disableMultiStroke){let x=Bl(g,d,c,u,p,m,h,1.5,l);E.push(...x)}return s&&(a?E.push(...Qt(d,c,d+u*Math.cos(m),c+p*Math.sin(m),l),...Qt(d,c,d+u*Math.cos(h),c+p*Math.sin(h),l)):E.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(m),c+p*Math.sin(m)]})),{type:"path",ops:E}}function is(e,t){let n=Xi(Wi(Ei(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(...Qt(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,d,c,u,p,m]=a;i.push(...kp(l,d,c,u,p,m,r,t)),r=[p,m];break}case"Z":i.push(...Qt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function Go(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]+j(o,t),i[0][1]+j(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+j(o,t),i[s][1]+j(o,t)]})}}return{type:"fillPath",ops:n}}function Zn(e,t){return Il(t,Tp).fillPolygons(e,t)}function Cl(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=j(d*.01,s),c+=j(c*.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,h=[];for(let f=u;f<=p;f=f+m)h.push([a+d*Math.cos(f),l+c*Math.sin(f)]);return h.push([a+d*Math.cos(p),l+c*Math.sin(p)]),h.push([a,l]),Zn([h],s)}function vp(e,t){return j(e,t)}function Bp(e,t,n){return ko(e,t,n)}function Lp(e,t,n,i,o){return Qt(e,t,n,i,o,!0)}function Cp(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function kl(e){return e.randomizer||(e.randomizer=new Lo(e.seed||0)),e.randomizer.next()}function ko(e,t,n,i=1){return n.roughness*i*(kl(n)*(t-e)+e)}function j(e,t,n=1){return ko(-e,e,t,n)}function Qt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=Al(e,t,n,i,o,!0,!1);if(s)return a;let l=Al(e,t,n,i,o,!0,!0);return a.concat(l)}function Al(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,p=.2+kl(o)*.2,m=o.bowing*o.maxRandomnessOffset*(i-t)/200,h=o.bowing*o.maxRandomnessOffset*(e-n)/200;m=j(m,o,d),h=j(h,o,d);let f=[],g=()=>j(u,o,d),E=()=>j(c,o,d),x=o.preserveVertices;return r&&(s?f.push({op:"move",data:[e+(x?0:g()),t+(x?0:g())]}):f.push({op:"move",data:[e+(x?0:j(c,o,d)),t+(x?0:j(c,o,d))]})),s?f.push({op:"bcurveTo",data:[m+e+(n-e)*p+g(),h+t+(i-t)*p+g(),m+e+2*(n-e)*p+g(),h+t+2*(i-t)*p+g(),n+(x?0:g()),i+(x?0:g())]}):f.push({op:"bcurveTo",data:[m+e+(n-e)*p+E(),h+t+(i-t)*p+E(),m+e+2*(n-e)*p+E(),h+t+2*(i-t)*p+E(),n+(x?0:E()),i+(x?0:E())]}),f}function Dl(e,t,n){let i=[];i.push([e[0][0]+j(t,n),e[0][1]+j(t,n)]),i.push([e[0][0]+j(t,n),e[0][1]+j(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+j(t,n),e[o][1]+j(t,n)]),o===e.length-1&&i.push([e[o][0]+j(t,n),e[o][1]+j(t,n)]);return No(i,null,n)}function No(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]+j(a,n),t[1]+j(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(...Qt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function vl(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 p=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(p),c.push(p)}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=j(.5,a)-Math.PI/2;c.push([j(r,a)+t+.9*i*Math.cos(u-e),j(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 h=[j(r,a)+t+i*Math.cos(m),j(r,a)+n+o*Math.sin(m)];d.push(h),c.push(h)}c.push([j(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),j(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([j(r,a)+t+.98*i*Math.cos(u+s),j(r,a)+n+.98*o*Math.sin(u+s)]),c.push([j(r,a)+t+.9*i*Math.cos(u+s*.5),j(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function Bl(e,t,n,i,o,r,s,a,l){let d=r+j(.1,l),c=[];c.push([j(a,l)+t+.9*i*Math.cos(d-e),j(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([j(a,l)+t+i*Math.cos(u),j(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)]),No(c,null,l)}function kp(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,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:j(d[0],a)),s[1]+(p?0:j(d[0],a))]}),c=p?[o,r]:[o+j(d[m],a),r+j(d[m],a)],l.push({op:"bcurveTo",data:[e+j(d[m],a),t+j(d[m],a),n+j(d[m],a),i+j(d[m],a),c[0],c[1]]});return l}M();function $i(e){return[...e]}function Fo(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($i(e[0]),$i(e[1]),$i(e[2]),$i(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($i(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}M();function Np(e,t){return Math.sqrt(Ro(e,t))}function Ro(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Op(e,t,n){let i=Ro(t,n);if(i===0)return Ro(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)),Ro(e,qn(t,n,o))}function qn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Gp(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 os(e,t,n,i){let o=i||[];if(Gp(e,t)<n){let r=e[t+0];o.length?Np(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=qn(s,a,.5),u=qn(a,l,.5),p=qn(l,d,.5),m=qn(c,u,.5),h=qn(u,p,.5),f=qn(m,h,.5);os([s,c,m,f],0,n,o),os([f,h,p,d],0,n,o)}return o}function Pn(e,t){return zo(e,0,e.length,t)}function zo(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=Op(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(zo(e,t,d+1,i,r),zo(e,d,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;os(e,s,t,i)}return n&&n>0?zo(i,0,i.length,n):i}M();function Nl(e,t,n){let i=Ei(e),o=Xi(Wi(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Et(l,t)),l=[]},c=()=>{d(),s.length&&(r.push(s),s=[])};for(let{key:p,data:m}of o)switch(p){case"M":c(),a=[m[0],m[1]],s.push(a);break;case"L":d(),s.push([m[0],m[1]]);break;case"C":if(!l.length){let h=s.length?s[s.length-1]:a;l.push([h[0],h[1]])}l.push([m[0],m[1]]),l.push([m[2],m[3]]),l.push([m[4],m[5]]);break;case"Z":d(),s.push([a[0],a[1]]);break}if(c(),!n)return r;let u=[];for(let p of r){let m=Pn(p,n);m.length&&u.push(m)}return u}var xt="none",bt=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 Ml()}_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",[Jr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=Ll(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(Go([d],s)):a.push(Zn([d],s))}return s.stroke!==xt&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=ts(i,o,s),d=Oo(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Oo(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(Zn([d.estimatedPoints],s));return s.stroke!==xt&&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",[ji(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=ns(t,n,i,o,r,s,a,!0,d);if(a&&d.fill)if(d.fillStyle==="solid"){let p=Object.assign({},d);p.disableMultiStroke=!0;let m=ns(t,n,i,o,r,s,!0,!1,p);m.type="fillPath",c.push(m)}else c.push(Cl(t,n,i,o,r,s,d));return d.stroke!==xt&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=es(t,i);if(i.fill&&i.fill!==xt&&t.length>=3)if(i.fillStyle==="solid"){let s=es(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=Fo(t),a=Et(s,10,(1+i.roughness)/2);o.push(Zn([a],i))}return i.stroke!==xt&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=ji(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(Go([t],i)):o.push(Zn([t],i))),i.stroke!==xt&&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!==xt,s=i.stroke!==xt,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=Nl(t,1,l),c=is(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=is(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(Go(d,i));else o.push(Zn(d,i));return s&&(a?d.forEach(u=>{o.push(ji(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:xt};break;case"fillPath":s={d:this.opsToPath(r),stroke:xt,strokeWidth:0,fill:i.fill||xt};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||xt,strokeWidth:i,fill:xt}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var _o=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new bt(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}};M();M();var Vi="http://www.w3.org/2000/svg";var Ho=class{constructor(t,n){this.svg=t,this.gen=new bt(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(Vi,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(Vi,"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(Vi,"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(Vi,"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 xi={canvas(e,t){return new _o(e,t)},svg(e,t){return new Ho(e,t)},generator(e){return new bt(e)},newSeed(){return bt.newSeed()}};import{arrayToMap as Au,invariant as Fa,rescalePoints as Pu,sizeOf as tx}from"@excalidraw/common";import{degreesToRadians as Ga,lineSegment as we,pointFrom as F,pointFromArray as Du,pointRotateRads as le}from"@excalidraw/math";M();import{invariant as Fp}from"@excalidraw/common";import{curve as Rp,lineSegment as zp,pointFrom as xe,pointDistance as IP,pointFromArray as _p,pointFromVector as Hp,pointRotateRads as At,polygon as Ol,polygonFromPoints as rs,PRECISION as MP,segmentsIntersectAt as TP,vector as Up,vectorAdd as Wp,vectorFromPoint as Yp,vectorScale as AP}from"@excalidraw/math";import{getElementAbsoluteCoords as vP}from"@excalidraw/element";var Gl=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=xe(s,a),d;return e.type==="diamond"?d=Ol(At(xe(s,r),l,t),At(xe(o+n,a),l,t),At(xe(s,r+i),l,t),At(xe(o,a),l,t)):d=Ol(At(xe(o,r),l,t),At(xe(o+n,r),l,t),At(xe(o+n,r+i),l,t),At(xe(o,r+i),l,t)),{type:"polygon",data:d}};var Fl=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:xe(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},Jt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},Rl=(e,t=xe(0,0),n,i)=>{let o=l=>At(xe(l[0]+t[0],l[1]+t[1]),i,n),r=Jt(e),s=[],a=xe(0,0);for(let l of r){if(l.op==="move"){let d=_p(l.data);Fp(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(xe(l.data[0],l.data[1])),c=o(xe(l.data[2],l.data[3])),u=o(xe(l.data[4],l.data[5]));s.push(Rp(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Xp=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(zp(t,o)),t=o}return n},zl=(e,t,n=!1)=>{let i=r=>At(Hp(Wp(Yp(r),Up(e.x,e.y))),t,e.angle),o=Xp(e.points.map(r=>i(r)));return n?{type:"polygon",data:rs(o.flat())}:{type:"polyline",data:o}},_l=(e,t,n=xe(0,0),i,o)=>{let r=c=>At(xe(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:rs(e.points.map(c=>r(c)))};let s=Jt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(xe(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(xe(c.data[0],c.data[1])),a.push(xe(c.data[2],c.data[3])),a.push(xe(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(xe(c.data[0],c.data[1]));let d=Et(a,10,5).map(c=>r(c));return{type:"polygon",data:rs(d)}};M();M();function Hl(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function jp(e){return[-e[0],-e[1]]}function vt(e,t){return[e[0]+t[0],e[1]+t[1]]}function wt(e,t){return[e[0]-t[0],e[1]-t[1]]}function Dt(e,t){return[e[0]*t,e[1]*t]}function $p(e,t){return[e[0]/t,e[1]/t]}function Ki(e){return[e[1],-e[0]]}function Ul(e,t){return e[0]*t[0]+e[1]*t[1]}function Vp(e,t){return e[0]===t[0]&&e[1]===t[1]}function Kp(e){return Math.hypot(e[0],e[1])}function Zp(e){return e[0]*e[0]+e[1]*e[1]}function Wl(e,t){return Zp(wt(e,t))}function jl(e){return $p(e,Kp(e))}function qp(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function Zi(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 ss(e,t,n){return vt(e,Dt(wt(t,e),n))}function Yl(e,t,n){return vt(e,Dt(t,n))}var{min:bi,PI:Qp}=Math,Xl=.275,qi=Qp+1e-4;function Jp(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=B=>B,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=B=>B*(2-B)}=a,{cap:p=!0,easing:m=B=>--B*B*B+1}=l;if(e.length===0||n<=0)return[];let h=e[e.length-1].runningLength,f=a.taper===!1?0:a.taper===!0?Math.max(n,h):a.taper,g=l.taper===!1?0:l.taper===!0?Math.max(n,h):l.taper,E=Math.pow(n*i,2),x=[],b=[],y=e.slice(0,10).reduce((B,P)=>{let L=P.pressure;if(r){let C=bi(1,P.distance/n),_=bi(1,1-C);L=bi(1,B+(_-B)*(C*Xl))}return(B+L)/2},e[0].pressure),w=Hl(n,o,e[e.length-1].pressure,s),S,I=e[0].vector,A=e[0].point,T=A,O=A,v=T,N=!1;for(let B=0;B<e.length;B++){let{pressure:P}=e[B],{point:L,vector:C,distance:_,runningLength:K}=e[B];if(B<e.length-1&&h-K<3)continue;if(o){if(r){let pe=bi(1,_/n),oe=bi(1,1-pe);P=bi(1,y+(oe-y)*(pe*Xl))}w=Hl(n,o,P,s)}else w=n/2;S===void 0&&(S=w);let te=K<f?u(K/f):1,ne=h-K<g?m((h-K)/g):1;w=Math.max(.01,w*Math.min(te,ne));let ie=(B<e.length-1?e[B+1]:e[B]).vector,Ae=B<e.length-1?Ul(C,ie):1,_t=Ul(C,I)<0&&!N,Ht=Ae!==null&&Ae<0;if(_t||Ht){let pe=Dt(Ki(I),w);for(let oe=1/13,ke=0;ke<=1;ke+=oe)O=Zi(wt(L,pe),L,qi*ke),x.push(O),v=Zi(vt(L,pe),L,qi*-ke),b.push(v);A=O,T=v,Ht&&(N=!0);continue}if(N=!1,B===e.length-1){let pe=Dt(Ki(C),w);x.push(wt(L,pe)),b.push(vt(L,pe));continue}let bn=Dt(Ki(ss(ie,C,Ae)),w);O=wt(L,bn),(B<=1||Wl(A,O)>E)&&(x.push(O),A=O),v=vt(L,bn),(B<=1||Wl(T,v)>E)&&(b.push(v),T=v),y=P,I=C}let k=e[0].point.slice(0,2),z=e.length>1?e[e.length-1].point.slice(0,2):vt(e[0].point,[1,1]),U=[],D=[];if(e.length===1){if(!(f||g)||d){let B=Yl(k,jl(Ki(wt(k,z))),-(S||w)),P=[];for(let L=1/13,C=L;C<=1;C+=L)P.push(Zi(B,k,qi*2*C));return P}}else{if(!(f||g&&e.length===1))if(c)for(let P=1/13,L=P;L<=1;L+=P){let C=Zi(b[0],k,qi*L);U.push(C)}else{let P=wt(x[0],b[0]),L=Dt(P,.5),C=Dt(P,.51);U.push(wt(k,L),wt(k,C),vt(k,C),vt(k,L))}let B=Ki(jp(e[e.length-1].vector));if(g||f&&e.length===1)D.push(z);else if(p){let P=Yl(z,B,w);for(let L=1/29,C=L;C<1;C+=L)D.push(Zi(P,z,qi*3*C))}else D.push(vt(z,Dt(B,w)),vt(z,Dt(B,w*.99)),wt(z,Dt(B,w*.99)),wt(z,Dt(B,w)))}return x.concat(D,b.reverse(),U)}function as(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:h,pressure:f=.5})=>[m,h,f]);if(a.length===2){let m=a[1];a=a.slice(0,-1);for(let h=1;h<5;h++)a.push(ss(a[0],m,h/4))}a.length===1&&(a=[...a,[...vt(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],p=a.length-1;for(let m=1;m<a.length;m++){let h=r&&m===p?a[m].slice(0,2):ss(u.point,a[m],s);if(Vp(u.point,h))continue;let f=qp(h,u.point);if(c+=f,m<p&&!d){if(c<o)continue;d=!0}u={point:h,pressure:a[m][2]>=0?a[m][2]:.5,vector:jl(wt(u.point,h)),distance:f,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function $l(e,t={}){return Jp(as(e,t),t)}M();M();M();function be([e,t,n],[i,o,r]){return[e+i,t+o,n+r]}function yi([e,t,n],[i,o,r]){return[e-i,t-o,n-r]}function Ie([e,t,n],i){return[e*i,t*i,n*i]}function Jn([e,t,n]){return[e/Math.sqrt(e**2+t**2),t/Math.sqrt(e**2+t**2),n]}function Fe([e,t,n],i){return[Math.cos(i)*e-Math.sin(i)*t,Math.sin(i)*e+Math.cos(i)*t,n]}function Vl(e,t,n){return be(e,Ie(yi(t,e),n))}function ls(e,t,n){return Math.atan2(n[1]-e[1],n[0]-e[0])-Math.atan2(t[1]-e[1],t[0]-e[0])}function ds(e){return Math.atan2(Math.sin(e),Math.cos(e))}function cs([e,t]){return Math.sqrt(e**2+t**2)}function Qn([e,t],[n,i]){return Math.sqrt((n-e)**2+(i-t)**2)}function Kl(e){if(e.length<2)return 0;let t=0;for(let n=1;n<=e.length-1;n++)t+=Qn(e[n-1],e[n]);return t+=Qn(e[e.length-2],e[e.length-1]),t}var ef=(e,t,n)=>Math.max(t,Math.min(n,e));function Zl(e,t,n){let i=Qn(t,n);if(i===0)return Qn(e,t);let o=ef(((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i**2,0,1),r=[t[0]+o*(n[0]-t[0]),t[1]+o*(n[1]-t[1]),e[2]];return Qn(r,e)}M();function Qi(e,t){if(t===0||e.length<=2)return e;let n=e[0],i=e[e.length-1],[o,r]=e.reduce(([s,a],l,d)=>{let c=Zl(l,n,i);return c>s?[c,d]:[s,a]},[0,-1]);if(o>=t){let s=e[r];return[...Qi([n,...e.slice(1,r),s],t).slice(0,-1),s,...Qi([s,...e.slice(r,-1),i],t).slice(1)]}return[n,i]}var Uo=class e{static defaults={size:2,streamline:.45,simplify:.1,simplifyPhase:"output",keepHead:!1,sizeMapping:()=>1};static constants={cornerDetectionMaxAngle:75,cornerDetectionVariance:t=>t>35?.5:1,maxTailLength:50};options;constructor(t){this.options=Object.assign({},e.defaults,t)}originalPoints=[];stablePoints=[];tailPoints=[];isFresh=!0;get lastPoint(){return this.tailPoints[this.tailPoints.length-1]??this.stablePoints[this.stablePoints.length-1]}addPoint(t){let n=this.originalPoints[this.originalPoints.length-1];if(!(n&&n[0]===t[0]&&n[1]===t[1])){if(this.originalPoints.push(t),this.isFresh){this.isFresh=!1,this.stablePoints.push(t);return}this.options.streamline>0&&(t=Vl(this.lastPoint,t,1-this.options.streamline)),this.tailPoints.push(t),Kl(this.tailPoints)>e.constants.maxTailLength&&this.stabilizeTail()}}close(){this.stabilizeTail()}stabilizeTail(){if(this.options.simplify>0&&this.options.simplifyPhase==="tail")throw new Error("Not implemented yet");this.stablePoints.push(...this.tailPoints),this.tailPoints=[]}getSize(t,n,i,o,r){return(t??this.options.size)*this.options.sizeMapping({pressure:n,runningLength:r,currentIndex:i,totalLength:o})}getStrokeOutline(t){if(this.isFresh)return[];let n=[...this.stablePoints,...this.tailPoints];this.options.simplify>0&&this.options.simplifyPhase==="input"&&(n=Qi(n,this.options.simplify));let i=n.length;if(i===0)return[];if(i===1){let I=n[0],A=this.getSize(t,I[2],0,i,0);if(A<.5)return[];let T=[];for(let O=0;O<=Math.PI*2;O+=Math.PI/16)T.push(be(I,Ie(Fe([1,0,0],O),A)));return T.push(be(I,Ie([1,0,0],this.getSize(t,I[2],0,i,0)))),T}if(i===2){let I=n[0],A=n[1],T=this.getSize(t,I[2],0,i,0),O=this.getSize(t,A[2],0,i,0);if(T<.5||O<.5)return[];let v=[],N=ls(I,[I[0],I[1]-100,I[2]],A);for(let k=N;k<=Math.PI+N;k+=Math.PI/16)v.push(be(I,Ie(Fe([1,0,0],k),T)));for(let k=Math.PI+N;k<=Math.PI*2+N;k+=Math.PI/16)v.push(be(A,Ie(Fe([1,0,0],k),O)));return v.push(v[0]),v}let o=[],r=[],s=0,a=0,l=0,d=0;for(let I=1;I<i-1;I++){let A=n[I-1],T=n[I],O=n[I+1],v=T[2],N=Qn(A,T);d+=N,s=a+(N-a)*.2;let k=this.getSize(t,v,I,i,d);if(k===0){l=I+1;continue}let z=Jn(yi(A,T)),U=Jn(yi(O,T)),D=Fe(z,Math.PI/2),B=Fe(z,-Math.PI/2),P=Fe(U,Math.PI/2),L=Fe(U,-Math.PI/2),C=be(T,Ie(D,k)),_=be(T,Ie(B,k)),K=be(T,Ie(P,k)),te=be(T,Ie(L,k)),ne=be(D,L),ie=be(B,P),Ae=be(T,Ie(cs(ne)===0?z:Jn(ne),k)),_t=be(T,Ie(cs(ie)===0?U:Jn(ie),k)),Ht=ds(ls(T,A,O)),bn=e.constants.cornerDetectionMaxAngle/180*Math.PI*e.constants.cornerDetectionVariance(s);if(Math.abs(Ht)<bn){let pe=Math.abs(ds(Math.PI-Ht));if(pe===0)continue;if(Ht<0){r.push(_,_t);for(let oe=0;oe<=pe;oe+=pe/4)o.push(be(T,Fe(Ie(D,k),oe)));for(let oe=pe;oe>=0;oe-=pe/4)r.push(be(T,Fe(Ie(D,k),oe)));r.push(_t,K)}else{o.push(C,Ae);for(let oe=0;oe<=pe;oe+=pe/4)r.push(be(T,Fe(Ie(D,-k),-oe)));for(let oe=pe;oe>=0;oe-=pe/4)o.push(be(T,Fe(Ie(D,-k),-oe)));o.push(Ae,te)}}else o.push(Ae),r.push(_t);a=s}if(l>=i-2){if(this.options.keepHead){let I=n[i-1],A=[];for(let T=0;T<=Math.PI*2;T+=Math.PI/16)A.push(be(I,Ie(Fe([1,0,0],T),this.options.size)));return A.push(be(I,Ie([1,0,0],this.options.size))),A}return[]}let c=n[l],u=n[l+1],p=n[i-2],m=n[i-1],h=Jn(yi(u,c)),f=Jn(yi(p,m)),g=Fe(h,-Math.PI/2),E=Fe(f,Math.PI/2),x=this.getSize(t,c[2],0,i,0),b=[],y=this.options.keepHead?this.options.size:this.getSize(t,p[2],i-2,i,d),w=[];if(x>.1){for(let I=0;I<=Math.PI;I+=Math.PI/16)b.unshift(be(c,Fe(Ie(g,x),-I)));b.unshift(be(c,Ie(g,-x)))}else b.push(c);for(let I=0;I<=Math.PI*3;I+=Math.PI/16)w.push(be(m,Fe(Ie(E,-y),-I)));let S=[...b,...o,...w.reverse(),...r.reverse()];return b.length>0&&S.push(b[0]),this.options.simplify>0&&this.options.simplifyPhase==="output"?Qi(S,this.options.simplify):S}};import{pointFrom as Ce,pointDistance as uu,pointRotateRads as ki,polygonFromPoints as _E}from"@excalidraw/math";import{ROUGHNESS as HE,THEME as ka,isTransparent as xo,assertNever as UE,COLOR_PALETTE as WE,LINE_POLYGON_POINT_MERGE_DISTANCE as YE,applyDarkModeFilter as bo,DEFAULT_STROKE_STREAMLINE as XE}from"@excalidraw/common";M();import{clamp as tu,isRightAngleRads as yE,lineSegment as nu,pointFrom as Mr,pointRotateRads as Aa}from"@excalidraw/math";import{BOUND_TEXT_PADDING as Wn,DEFAULT_REDUCED_GLOBAL_ALPHA as wE,ELEMENT_READY_TO_ERASE_OPACITY as PE,FRAME_STYLE as Tr,DARK_THEME_FILTER as SE,MIME_TYPES as La,THEME as mn,distance as Yn,getFontString as IE,isRTL as ME,getVerticalOffset as TE,invariant as AE,applyDarkModeFilter as ci,isSafari as DE,STICKY_NOTE_EDGE_SHADOW_OPACITY as vE,STICKY_NOTE_EDGE_SHADOW_WIDTH as BE,STICKY_NOTE_FOOTER as Da,STICKY_NOTE_SHADOW_OPACITY as LE,DEFAULT_ZOOM as CE}from"@excalidraw/common";M();import{pointFrom as en,pointCenter as nf,pointRotateRads as Sn,vectorFromPoint as us,vectorNormalize as ql,vectorSubtract as Ql,vectorAdd as Wo,vectorScale as Yo,pointFromVector as Jl,clamp as We,isCloseTo as ed}from"@excalidraw/math";var Ye=10,jP=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=ms(e),c=i/l,u=o/d,p=(e.crop?.x??0)/c,m=(e.crop?.y??0)/u,h=Sn(en(r,s),re(e,t),-e.angle);r=h[0],s=h[1];let f=e.width,g=e.height,E=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=E.height,b=E.width,y=e.scale[0]===-1,w=e.scale[1]===-1,S=s-e.y,I=r-e.x;n.includes("n")&&(g=We(e.height-S,Ye,w?d-m:e.height+m)),n.includes("s")&&(S=s-e.y-e.height,g=We(e.height+S,Ye,w?e.height+m:d-m)),n.includes("e")&&(I=r-e.x-e.width,f=We(e.width+I,Ye,y?e.width+p:l-p)),n.includes("w")&&(f=We(e.width-I,Ye,y?l-p:e.width+p));let A=v=>{v.height=g*u,v.width=f*c};A(E);let T=(v,N)=>{A(N),v.includes("n")&&(w||(N.y+=x-N.height)),v.includes("s")&&w&&(N.y+=x-N.height),v.includes("e")&&y&&(N.x+=b-N.width),v.includes("w")&&(y||(N.x+=b-N.width))};switch(n){case"n":{if(a){let v=p+e.width/2,N=l-p-e.width/2,k=Math.min(v,N)*2;f=We(g*a,Ye,k),g=f/a}T(n,E),a&&(E.x+=(b-E.width)/2);break}case"s":{if(a){let v=p+e.width/2,N=l-p-e.width/2,k=Math.min(v,N)*2;f=We(g*a,Ye,k),g=f/a}T(n,E),a&&(E.x+=(b-E.width)/2);break}case"w":{if(a){let v=m+e.height/2,N=d-m-e.height/2,k=Math.min(v,N)*2;g=We(f/a,Ye,k),f=g*a}T(n,E),a&&(E.y+=(x-E.height)/2);break}case"e":{if(a){let v=m+e.height/2,N=d-m-e.height/2,k=Math.min(v,N)*2;g=We(f/a,Ye,k),f=g*a}T(n,E),a&&(E.y+=(x-E.height)/2);break}case"ne":{if(a)if(I>-S){let v=w?d-m:m+e.height;g=We(f/a,Ye,v),f=g*a}else{let v=y?p+e.width:l-p;f=We(g*a,Ye,v),g=f/a}T(n,E);break}case"nw":{if(a)if(I<S){let v=w?d-m:m+e.height;g=We(f/a,Ye,v),f=g*a}else{let v=y?l-p:p+e.width;f=We(g*a,Ye,v),g=f/a}T(n,E);break}case"se":{if(a)if(I>S){let v=w?m+e.height:d-m;g=We(f/a,Ye,v),f=g*a}else{let v=y?p+e.width:l-p;f=We(g*a,Ye,v),g=f/a}T(n,E);break}case"sw":{if(a)if(-I>S){let v=w?m+e.height:d-m;g=We(f/a,Ye,v),f=g*a}else{let v=y?l-p:p+e.width;f=We(g*a,Ye,v),g=f/a}T(n,E);break}default:break}let O=of(e,n,f,g,!!a);return ed(E.width,E.naturalWidth)&&ed(E.height,E.naturalHeight)&&(E=null),{x:O[0],y:O[1],width:f,height:g,crop:E}},of=(e,t,n,i,o)=>{let[r,s,a,l]=In(e,e.width,e.height,!0),d=en(r,s),c=en(a,l),u=nf(d,c),[p,m,h,f]=In(e,n,i,!0),g=h-p,E=f-m,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(g),c[1]-Math.abs(E)]),t==="ne"){let A=[d[0],c[1]];x=[A[0],A[1]-Math.abs(E)]}if(t==="sw"){let A=[c[0],d[1]];x=[A[0]-Math.abs(g),A[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-g/2),["e","w"].includes(t)&&(x[1]=u[1]-E/2));let b=e.angle,y=Sn(x,u,b),w=[x[0]+Math.abs(g)/2,x[1]+Math.abs(E)/2],S=Sn(w,u,b);x=Sn(y,S,-b);let I=[...x];return I[0]+=e.x-p,I[1]+=e.y-m,I},td=(e,t)=>{if(e.crop){let{width:n,height:i}=ms(e),[o,r,s,a,l,d]=q(e,t),c=us(Sn(en(o,r),en(l,d),e.angle)),u=us(Sn(en(s,r),en(l,d),e.angle)),p=ql(Ql(u,c)),m=us(Sn(en(o,a),en(l,d),e.angle)),h=Ql(m,c),f=ql(h),{cropX:g,cropY:E}=rf(e.crop,e.scale),x=Wo(Wo(c,Yo(p,-g*n/e.crop.naturalWidth)),Yo(f,-E*i/e.crop.naturalHeight)),b=Jl(Wo(Wo(x,Yo(p,n/2)),Yo(f,i/2))),y=Sn(Jl(x),b,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},ms=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}},rf=(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}},$P=(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}=ms(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};M();import{pointCenter as Sc,pointFrom as H,pointRotateRads as nt,pointsEqual as Ic,pointDistance as Vt,vectorFromPoint as Ng,curveLength as kc,curveLengthAtParameter as Og,curvePointAtLength as Nc,lineSegmentClosestParameter as Gg,lineSegmentPointAt as Oc,curveClosestParameter as Fg,clamp as ma,bezierEquation as Rg,isCurve as wr}from"@excalidraw/math";import{DRAGGING_THRESHOLD as zg,KEYS as ai,shouldRotateWithDiscreteAngle as li,getGridPoint as Mc,invariant as ft,isShallowEqual as _g,getFeatureFlag as vi}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as Tc,getSnapOutlineMidPoint as pa,isPathALoop as Hg,moveArrowAboveBindable as Ac,projectFixedPointOntoDiagonal as Dc,getLinearElementPathSegments as Ug}from"@excalidraw/element";M();import{arrayToMap as fc,getFeatureFlag as fg,getGridPoint as la,invariant as un,isTransparent as hg}from"@excalidraw/common";import{PRECISION as gg,clamp as hc,lineSegment as ri,pointDistance as da,pointDistanceSq as tt,pointFrom as ue,pointFromArray as Eg,pointFromVector as lo,pointRotateRads as et,pointsEqual as xg,vectorFromPoint as Gn,vectorNormalize as xr,vectorScale as co}from"@excalidraw/math";M();import{invariant as qh,isTransparent as Qd}from"@excalidraw/common";import{curveIntersectLineSegment as Jd,isPointWithinBounds as ra,lineSegment as hr,lineSegmentIntersectionPoints as ec,pointFrom as Te,pointFromVector as Qh,pointRotateRads as mt,pointsEqual as tc,polygonIncludesPoint as Jh,vectorFromPoint as eg,vectorNormalize as tg,vectorScale as ng}from"@excalidraw/math";import{ellipse as ig,ellipseSegmentInterceptPoints as og}from"@excalidraw/math/ellipse";M();import{DEFAULT_ADAPTIVE_RADIUS as Rh,DEFAULT_PROPORTIONAL_RADIUS as Vs,invariant as zh,LINE_CONFIRM_THRESHOLD as _h,ROUNDNESS as Ks}from"@excalidraw/common";import{bezierEquation as Hh,clamp as Rd,curve as dn,curveCatmullRomCubicApproxPoints as Hd,curveOffsetPoints as Ud,lineSegment as Le,lineSegmentIntersectionPoints as zd,pointDistance as ln,pointFrom as Y,pointFromArray as Uh,pointFromVector as Wh,pointRotateRads as It,pointTranslate as _d,rectangle as Yh,vectorFromPoint as Wd,vectorNormalize as Xh,vectorScale as Zs}from"@excalidraw/math";M();import{ROUNDNESS as Ji,assertNever as sf}from"@excalidraw/common";import{pointsEqual as nd}from"@excalidraw/math";var ei=e=>!!e&&e.type==="image"&&!!e.fileId,Ne=e=>!!e&&e.type==="image",id=e=>!!e&&e.type==="embeddable",Xo=e=>!!e&&e.type==="iframe",jo=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),$=e=>e!=null&&e.type==="text",ye=e=>e!=null&&e.type==="stickynote",$o=e=>e!=null&&e.type==="frame",od=e=>e!=null&&e.type==="magicframe",Q=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),he=e=>e!=null&&af(e.type),af=e=>e==="freedraw",ee=e=>e!=null&&cf(e.type),Re=e=>e!=null&&e.type==="line",W=e=>e!=null&&e.type==="arrow",X=e=>W(e)&&e.elbowed,QP=e=>W(e)&&!e.elbowed,lf=e=>W(e)&&!e.elbowed&&!e.roundness,df=e=>W(e)&&!e.elbowed&&e.roundness!==null,cf=e=>e==="arrow"||e==="line",Xe=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&uf(e.type),uf=e=>e==="arrow",Pe=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="stickynote"||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),rd=e=>e!=null&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="diamond"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),eo=e=>e!=null&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="image"||e.type==="text"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="freedraw"),mf=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="diamond"||e.type==="ellipse"||W(e)),sd=e=>{let t=e?.type;if(!t)return!1;switch(t){case"text":case"diamond":case"rectangle":case"stickynote":case"iframe":case"embeddable":case"ellipse":case"arrow":case"freedraw":case"line":case"frame":case"magicframe":case"image":case"selection":return!0;default:return sf(t,null),!1}},ad=e=>e.type==="rectangle"||e.type==="stickynote"||e.type==="ellipse"||e.type==="diamond",Wt=e=>mf(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),ge=e=>e!==null&&"containerId"in e&&e.containerId!==null&&$(e),JP=e=>!!e.startBinding||!!e.endBinding,Vo=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",ld=e=>e==="line"||e==="arrow"||e==="diamond"||e==="stickynote",e1=(e,t)=>!!((e===Ji.ADAPTIVE_RADIUS||e===Ji.LEGACY)&&Vo(t.type)||e===Ji.PROPORTIONAL_RADIUS&&ld(t.type)),t1=e=>ld(e.type)?{type:Ji.PROPORTIONAL_RADIUS}:Vo(e.type)?{type:Ji.ADAPTIVE_RADIUS}:null,n1=e=>lf(e)?"sharpArrow":df(e)?"curvedArrow":X(e)?"elbowArrow":"line",ps=e=>e.length>3&&nd(e[0],e[e.length-1]),dd=e=>e.length>3||e.length===3&&!nd(e[0],e[e.length-1]),i1=e=>{switch(e){case"rectangle":case"stickynote":case"diamond":case"ellipse":case"arrow":case"line":case"freedraw":case"text":case"image":case"frame":case"embeddable":return!0;default:return!1}};M();import{DEFAULT_ELEMENT_PROPS as yh,DEFAULT_STICKY_NOTE_BG as wh,MIN_FONT_SIZE as Ph,arrayToMap as kd,STICKY_NOTE_BODY_INSET_Y as Us,STICKY_NOTE_FALLBACK_FONT_SIZE as Sh,STICKY_NOTE_FOOTER as vd,STICKY_NOTE_FONT_STEP as Hs,STICKY_NOTE_MAX_FONT_SIZE as Ih,STICKY_NOTE_MIN_SIZE as Ai,STICKY_NOTE_MIN_FONT_SIZE as Mh,STICKY_NOTE_PADDING as ur,STICKY_NOTE_SHADOW_OFFSET as Bd,getFontString as Ld,getLineHeight as Th,isTransparent as mr,seededRandom as Nd}from"@excalidraw/common";import{clamp as Ah}from"@excalidraw/math";M();import{getSizeFromPoints as Wf,randomInteger as Ds,getUpdatedTimestamp as vs}from"@excalidraw/common";M();import{clamp as er,pointDistance as ys,pointFrom as Z,pointScaleFromOrigin as Mf,pointsEqual as no,pointTranslate as bs,vector as Yt,vectorCross as tr,vectorFromPoint as ws,vectorScale as Tf}from"@excalidraw/math";import{BinaryHeap as Af,invariant as Si,isAnyTrue as Df,getSizeFromPoints as ud,isDevEnv as vf,arrayToMap as Bf,DEFAULT_ZOOM as Lf}from"@excalidraw/common";M();import{curvePointDistance as fs,distanceToLineSegment as Ko,pointRotateRads as hs,polygonIncludesPointNonZero as pf}from"@excalidraw/math";import{ellipse as ff,ellipseDistanceFromPoint as hf}from"@excalidraw/math/ellipse";var tn=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"stickynote":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return gf(e,t,n);case"diamond":return Ef(e,t,n);case"ellipse":return xf(e,t,n);case"line":case"arrow":return bf(e,t,n);case"freedraw":return yf(e,t,n)}},gf=(e,t,n)=>{let i=re(e,t),o=hs(n,i,-e.angle),[r,s]=Mn(e);return Math.min(...r.map(a=>Ko(o,a)),...s.map(a=>fs(a,o)))},Ef=(e,t,n)=>{let i=re(e,t),o=hs(n,i,-e.angle),[r,s]=Tn(e);return Math.min(...r.map(a=>Ko(o,a)),...s.map(a=>fs(a,o)))},xf=(e,t,n)=>{let i=re(e,t);return hf(hs(n,i,-e.angle),ff(i,e.width/2,e.height/2))},bf=(e,t,n)=>{let[i,o]=wi(e,t);return Math.min(...i.map(r=>Ko(n,r)),...o.map(r=>fs(r,n)))},yf=(e,t,n)=>{let[i]=wi(e,t);if(i.length===0)return 1/0;let o=i.map(r=>r[0]);return pf(n,o)?0:Math.min(...i.map(r=>Ko(n,r)))};M();import{invariant as cd,isDevEnv as wf,isTestEnv as Pf}from"@excalidraw/common";import{pointFrom as An,pointFromVector as Zo,pointRotateRads as qo,pointScaleFromOrigin as Qo,pointsEqual as Sf,triangleIncludesPoint as gs,vectorCross as lt,vectorFromPoint as se,vectorScale as Jo}from"@excalidraw/math";var Ee=[1,0],ve=[0,1],ze=[-1,0],qe=[0,-1],Bt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?Ee:t<=-o?ze:n>i?ve:qe},dt=(e,t)=>Bt(se(e,t)),Lt=(e,t)=>ct(dt(e,t)),fe=(e,t)=>e[0]===t[0]&&e[1]===t[1],ct=e=>fe(e,Ee)||fe(e,ze),h1=e=>!ct(e),If=(e,t,n)=>{let i=nn(t);(wf()||Pf())&&(cd(e.width>0&&e.height>0,"Diamond element has no width or height"),cd(!Sf(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Zo(Jo(se(qo(An(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Zo(Jo(se(qo(An(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Zo(Jo(se(qo(An(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Zo(Jo(se(qo(An(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(lt(se(n,r),se(r,s))<=0&&lt(se(n,r),se(r,l))>0)return dt(r,i);if(lt(se(n,s),se(s,a))<=0&&lt(se(n,s),se(s,r))>0)return dt(s,i);if(lt(se(n,a),se(a,l))<=0&&lt(se(n,a),se(a,s))>0)return dt(a,i);if(lt(se(n,l),se(l,r))<=0&&lt(se(n,l),se(l,a))>0)return dt(l,i);if(lt(se(n,i),se(r,i))<=0&&lt(se(n,i),se(s,i))>0){let c=e.width>e.height?r:s;return dt(c,i)}else if(lt(se(n,i),se(s,i))<=0&&lt(se(n,i),se(a,i))>0){let c=e.width>e.height?a:s;return dt(c,i)}else if(lt(se(n,i),se(a,i))<=0&&lt(se(n,i),se(l,i))>0){let c=e.width>e.height?a:l;return dt(c,i)}let d=e.width>e.height?r:l;return dt(d,i)},Pi=(e,t,n)=>{let o=nn(t);if(e.type==="diamond")return If(e,t,n);let r=Qo(An(t[0],t[1]),o,2),s=Qo(An(t[2],t[1]),o,2),a=Qo(An(t[0],t[3]),o,2),l=Qo(An(t[2],t[3]),o,2);return gs([r,s,o],n)?qe:gs([s,l,o],n)?Ee:gs([l,a,o],n)?ve:ze},Es=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];var Ps=1,ce=40,Cf=(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 d=dt(s,l[a-1]),c=dt(l[a-1],l[a-2]);if(fe(d,c)){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(ys(l[a-2],l[a-1])<Ps){let d=n?.findIndex(p=>p.index===a-2)??-1,c=n?.findIndex(p=>p.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),o.splice(-2,2),n.forEach(p=>{p.index>a-2&&(p.index-=2)});let u=Lt(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?on(Ms(Ts(Is(e,Ss(e,t,o.map(s=>Z(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(vf()&&Si(xd(o),"Invalid elbow points with fixed segments"),on(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}},kf=(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],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,p=l?null:e.endBinding,{startHeading:m,endHeading:h,startGlobalPoint:f,endGlobalPoint:g,hoveredStartElement:E,hoveredEndElement:x,...b}=Ss({x:d,y:c,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])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:y}=on(Ms(Ts(Is(e,{startHeading:m,endHeading:h,startGlobalPoint:f,endGlobalPoint:g,hoveredStartElement:E,hoveredEndElement:x,...b})??[])),t,null,null);if(!y||y.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let 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(y.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 S=(l?.index??e.points.length)-(a?.index??0)-1,I=t.map(T=>T.index>s?{...T,index:T.index-S+(y.length-1)}:T),A=w.flatMap((T,O)=>{let v=w[O-1],N=w[O+1];if(v&&N){let k=dt(T,v),z=dt(N,T);if(fe(k,z))return I.forEach(U=>{U.index>O&&(U.index-=1)}),[];if(fe(k,Es(z)))return I.forEach(U=>{U.index>O&&(U.index+=1)}),[T,T]}return[T]});return on(A,I,!1,!1)},Nf=(e,t,n,i,o,r)=>{let s=t.map((w,S)=>e.fixedSegments==null||e.fixedSegments[S]===void 0||e.fixedSegments[S].index!==w.index||(w.start[0]!==e.fixedSegments[S].start[0]&&w.end[0]!==e.fixedSegments[S].end[0])!=(w.start[1]!==e.fixedSegments[S].start[1]&&w.end[1]!==e.fixedSegments[S].end[1])?S: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,d=ys(t[s].start,t[s].end),c=d<ce+5;if(a===-1&&t[s].index===1&&o){let w=ct(n),I=(w?fe(n,Ee):fe(n,ve))?c?d/2:ce:c?-d/2:-ce;t[s].start=Z(t[s].start[0]+(w?I:0),t[s].start[1]+(w?0:I))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=ct(i),I=(w?fe(i,Ee):fe(i,ve))?c?d/2:ce:c?-d/2:-ce;t[s].end=Z(t[s].end[0]+(w?I:0),t[s].end[1]+(w?0:I))}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,S)=>Z(e.x+w[0],e.y+w[1])),m=u[s].index-1,h=u[s].index,f=u[s].start,g=u[s].end,E=p[m-1]&&!no(p[m],p[m-1])?Lt(p[m-1],p[m]):void 0,x=p[h+1]&&!no(p[h],p[h+1])?Lt(p[h+1],p[h]):void 0;if(E!==void 0){let w=E?1:0;p[m-1][w]=f[w]}if(p[m]=f,p[h]=g,x!==void 0){let w=x?1:0;p[h+1][w]=g[w]}let b=u.findIndex(w=>w.index===m);if(b!==-1){let w=Lt(u[b].end,u[b].start)?1:0;u[b].start[w]=f[w],u[b].end=f}let y=u.findIndex(w=>w.index===h+1);if(y!==-1){let w=Lt(u[y].end,u[y].start)?1:0;u[y].end[w]=g[w],u[y].start=g}if(a===-1&&m===0){let w=o?ct(n):Lt(p[1],p[0]);p.unshift(Z(w?f[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:f[1])),o&&p.unshift(Z(e.x+e.points[0][0],e.y+e.points[0][1]));for(let S of u)S.index+=o?2:1}if(l===-1&&h===e.points.length-1){let w=ct(i);p.push(Z(w?g[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:g[1])),r&&p.push(Z(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return on(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)},Of=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((g,E)=>E===0?Z(e.x+g[0],e.y+g[1]):E===t.length-1?Z(e.x+g[0],e.y+g[1]):Z(e.x+e.points[E][0],e.y+e.points[E][1])),p=n.map(g=>({...g,start:Z(e.x+(g.start[0]-t[0][0]),e.y+(g.start[1]-t[0][1])),end:Z(e.x+(g.end[0]-t[0][0]),e.y+(g.end[1]-t[0][1]))})),m=[],h=2+(d?1:0),f=2+(c?1:0);for(;m.length+h<u.length-f;)m.push(u[m.length+h]);{let g=u.at(d?2:1),E=u.at(d?3:2);if(!g||!E)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=ct(i),b=ct(Bt(ws(g,E)));if(a&&x===b){let y=x?fe(i,Ee):fe(i,ve);if(m.unshift(Z(b?r[0]+(y?ce:-ce):E[0],b?E[1]:r[1]+(y?ce:-ce))),m.unshift(Z(x?r[0]+(y?ce:-ce):r[0],x?r[1]:r[1]+(y?ce:-ce))),!d){d=!0;for(let w of p)w.index>1&&(w.index+=1)}}else if(m.unshift(Z(b?r[0]:g[0],b?g[1]:r[1])),d){d=!1;for(let y of p)y.index>1&&(y.index-=1)}m.unshift(r)}{let g=u.at(u.length-(c?3:2)),E=u.at(u.length-(c?4:3));if(!g||!E)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=ct(o),b=Lt(E,g);if(l&&x===b){let y=x?fe(o,Ee):fe(o,ve);m.push(Z(b?s[0]+(y?ce:-ce):E[0],b?E[1]:s[1]+(y?ce:-ce))),m.push(Z(x?s[0]+(y?ce:-ce):s[0],x?s[1]:s[1]+(y?ce:-ce))),c||(c=!0)}else m.push(Z(b?s[0]:g[0],b?g[1]:s[1])),c&&(c=!1)}return m.push(s),on(m,p.map(({index:g})=>({index:g,start:m[g-1],end:m[g]})).map(g=>({...g,start:Z(g.start[0]-r[0],g.start[1]-r[1]),end:Z(g.end[0]-r[0],g.end[1]-r[1])})),d,c)},Dn=1e6,Ii=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};G.PROD||(Si(!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)"),Si(!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"),Si(!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"),Si(e.points.slice(1).map((w,S)=>w[0]===e.points[S][0]||w[1]===e.points[S][1]),"Elbow arrow segments must be either horizontal or vertical"),Si(n.fixedSegments?.find(w=>w.index===1&&no(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&no(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,S)=>S===0?n.points[0]:S===e.points.length-1?n.points[1]:w):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&&ir(d.elementId,t),p=c&&ir(c.elementId,t),m=xd(r);if(d&&!u&&m||c&&!p&&m||t.size===0&&m||Object.keys(l).length===0&&(u?.id!==d?.elementId||p?.id!==c?.elementId))return on(r.map(w=>Z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y}=Ss({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&&m?on(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?Cf(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,S)=>no(w,e.points[S]??Z(1/0,1/0)))&&m?{}:o.length===0?on(Ms(Ts(Is(e,{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?kf(e,o,t):n.points?n.points&&n.fixedSegments?n:Of(e,r,o,h,f,g,E,x,b):Nf(e,o,h,f,x,b)},Ss=(e,t,n,i)=>{let o=bs(n[0],Yt(e.x,e.y)),r=bs(n[n.length-1],Yt(e.x,e.y)),s=i?.zoom??Lf,a=null,l=null;if(i?.isDragging&&i?.isBindingEnabled!==!1){let S=Array.from(t.values());a=hd(o,t,S,s)||null,l=hd(r,t,S,s)||null}else a=e.startBinding&&ir(e.startBinding.elementId,t)||null,l=e.endBinding&&ir(e.endBinding.elementId,t)||null;let d=pd({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=pd({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,s,l,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),u=fd(d,c,a,o,t,s),p=fd(c,d,l,r,t,s),m=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],h=[c[0]-2,c[1]-2,c[0]+2,c[1]+2],f=a?ut(a,t,vn(u,e.startArrowhead?Be(a)*6:Be(a)*2,1)):m,g=l?ut(l,t,vn(p,e.endArrowhead?Be(l)*6:Be(l)*2,1)):h,E=Xt(d,l?ut(l,t,vn(p,ce,ce)):h)||Xt(c,a?ut(a,t,vn(u,ce,ce)):m),x=Ed(E?[m,h]:[f,g]),b=Rf(E?m:f,E?h:g,x,E?vn(u,!a&&!l?0:ce,0):vn(u,!a&&!l?0:ce-(e.startArrowhead?Bn*6:Bn*2),ce),E?vn(p,!a&&!l?0:ce,0):vn(p,!a&&!l?0:ce-(e.endArrowhead?Bn*6:Bn*2),ce),E,a&&ut(a,t),l&&ut(l,t)),y=md(b[0],u,d),w=md(b[1],p,c);return{dynamicAABBs:b,startDonglePosition:y,startGlobalPoint:d,startHeading:u,endDonglePosition:w,endGlobalPoint:c,endHeading:p,commonBounds:x,hoveredStartElement:a,hoveredEndElement:l,boundsOverlap:E,startElementBounds:f,endElementBounds:g}},Is=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=zf(n,i||o,r,s||a,l,d),p=i&&nr(i,u),m=s&&nr(s,u),h=nr(a,u);h&&c&&(h.closed=!0);let f=nr(o,u);f&&e.startBinding&&(f.closed=!0);let g=p&&m&&(Xt(p.pos,n[1])||Xt(m.pos,n[0])),E=Gf(p||f,m||h,u,r||Ee,l||Ee,g?[]:n);if(E){let x=E.map(b=>[b.pos[0],b.pos[1]]);return p&&x.unshift(o),m&&x.push(a),x}return null},vn=(e,t,n)=>{switch(e){case qe:return[t,n,n,n];case Ee:return[n,t,n,n];case ve:return[n,n,t,n]}return[n,n,n,t]},Gf=(e,t,n,i,o,r)=>{let s=xs(e.pos,t.pos),a=new Af(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Ff(e,l);l.closed=!0;let d=Hf(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let p=Mf(u.pos,l.pos,.5);if(Df(...r.map(y=>Xt(p,y))))continue;let m=Uf(c),h=l.parent?Bt(ws(l.pos,l.parent.pos)):i,f=Es(h);if(fe(f,m)||gd(e.addr,u.addr)&&fe(m,i)||gd(t.addr,u.addr)&&fe(m,o))continue;let E=h!==m,x=l.g+xs(u.pos,l.pos)+(E?Math.pow(s,3):0),b=u.visited;if(!b||x<u.g){let y=_f(u,t,m,o);u.visited=!0,u.parent=l,u.h=xs(t.pos,u.pos)+y*Math.pow(s,2),u.g=x,u.f=u.g+u.h,b?a.rescoreElement(u):a.push(u)}}}return null},Ff=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},xs=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Rf=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,p,m]=i??[0,0,0,0],[h,f,g,E]=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]-m):(l[0]+d[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]+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]+p):(l[3]+d[1])/2:e[3]<t[3]?e[3]+p:n[3]+p],b=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-E):(d[0]+l[2])/2:t[0]>e[0]?t[0]-E:n[0]-E,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-h):(d[1]+l[3])/2:t[1]>e[1]?t[1]-h:n[1]-h,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+f):(d[2]+l[0])/2:t[2]<e[2]?t[2]+f:n[2]+f,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+g):(d[3]+l[1])/2:t[3]<e[3]?t[3]+g:n[3]+g],y=Ed([x,b]);if(!r&&x[2]-x[0]+b[2]-b[0]>y[2]-y[0]+1e-11&&x[3]-x[1]+b[3]-b[1]>y[3]-y[1]+1e-11){let[w,S]=[(b[0]+b[2])/2,(b[1]+b[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let I=x[2]+(b[0]-x[2])/2,A=b[3]+(x[1]-b[3])/2;return tr(Yt(e[2]-w,e[1]-S),Yt(e[0]-w,e[3]-S))>0?[[x[0],x[1],I,x[3]],[I,b[1],b[2],b[3]]]:[[x[0],A,x[2],x[3]],[b[0],b[1],b[2],A]]}else if(e[2]<t[0]&&e[3]<t[1]){let I=x[2]+(b[0]-x[2])/2,A=x[3]+(b[1]-x[3])/2;return tr(Yt(e[0]-w,e[1]-S),Yt(e[2]-w,e[3]-S))>0?[[x[0],x[1],x[2],A],[b[0],A,b[2],b[3]]]:[[x[0],x[1],I,x[3]],[I,b[1],b[2],b[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let I=b[2]+(x[0]-b[2])/2,A=x[3]+(b[1]-x[3])/2;return tr(Yt(e[2]-w,e[1]-S),Yt(e[0]-w,e[3]-S))>0?[[I,x[1],x[2],x[3]],[b[0],b[1],I,b[3]]]:[[x[0],x[1],x[2],A],[b[0],A,b[2],b[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let I=b[2]+(x[0]-b[2])/2,A=b[3]+(x[1]-b[3])/2;return tr(Yt(e[0]-w,e[1]-S),Yt(e[2]-w,e[3]-S))>0?[[I,x[1],x[2],x[3]],[b[0],b[1],I,b[3]]]:[[x[0],A,x[2],x[3]],[b[0],b[1],b[2],A]]}}return[x,b]},zf=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===ze||n===Ee?a.add(t[1]):s.add(t[0]),o===ze||o===Ee?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((p,m)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[m,u],pos:[p,c]})))}},md=(e,t,n)=>{switch(t){case qe:return Z(n[0],e[1]);case Ee:return Z(e[2],n[1]);case ve:return Z(n[0],e[3])}return Z(e[0],n[1])},_f=(e,t,n,i)=>{if(i===Ee)switch(n){case Ee: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 ve:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ze:return e.pos[1]===t.pos[1]?4:2}else if(i===ze)switch(n){case Ee: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 ve:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ze:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===qe)switch(n){case Ee: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 ve:return e.pos[0]===t.pos[0]?4:2;case ze:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===ve)switch(n){case Ee: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 ve:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ze:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Hf=([e,t],n)=>[to([e,t-1],n),to([e+1,t],n),to([e,t+1],n),to([e-1,t],n)],to=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,nr=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=to([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Ed=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]))],ir=(e,t)=>{let n=t.get(e);return n&&Pe(n)?n:null},on=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>bs(a,Tf(ws(e[0]),-1)));return(o<-Dn||o>Dn||r<-Dn||r>Dn||o+s[s.length-1][0]<-Dn||o+s[s.length-1][0]>Dn||r+s[s.length-1][1]<-Dn||r+s[s.length-1][1]>Dn)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...ud(s)}),s=s.map(([a,l])=>Z(er(a,-1e6,1e6),er(l,-1e6,1e6))),{points:s,x:er(o,-1e6,1e6),y:er(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...ud(s),startIsSpecial:n,endIsSpecial:i}},Ms=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},Ts=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return ys(i,t)>Ps}):e,Uf=e=>{switch(e){case 0:return qe;case 1:return Ee;case 2:return ve}return ze},pd=(e,t,n,i,o,r,s,a,l=!0,d=!0)=>a?l&&r&&s?As(e,r,t,s,o,void 0,d):i:r?_e(n||[0,0],r,s??Bf([r])):i,fd=(e,t,n,i,o,r)=>bd(e,t,n,n&&ut(n,o,Array(4).fill(tn(n,o,e))),i,o,r),hd=(e,t,n,i)=>rn(e,n,t,i),gd=(e,t)=>e[0]===t[0]&&e[1]===t[1],xd=(e,t=Ps)=>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 He=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;X(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...Ii({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Wf(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 p=!1,m=c.length;for(;--m;){let h=c[m],f=u[m];if(h[0]!==f[0]||h[1]!==f[1]){p=!0;break}}if(!p)continue}}e[l]=d,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof a<"u"||typeof r<"u")&&Qe.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Ds(),e.updated=vs()),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??Ds(),updated:vs()}},Bs=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Ds(),e.updated=vs(),e);M();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as mh,ARROW_LABEL_WIDTH_FRACTION as ph,BOUND_TEXT_PADDING as an,DEFAULT_FONT_SIZE as fh,STICKY_NOTE_BODY_INSET_Y as hh,STICKY_NOTE_PADDING as Rs,TEXT_ALIGN as Td,VERTICAL_ALIGN as Ad,getFontString as dr,isProdEnv as gh,invariant as Eh}from"@excalidraw/common";import{pointFrom as Gs,pointRotateRads as xh}from"@excalidraw/math";M();var io={},yd=(e,t)=>{let n=io[e]||(io[e]={height:t});return n.height=t,n},wd=e=>{io[e]&&delete io[e]},N1=e=>io[e]?.height??null;M();import{BOUND_TEXT_PADDING as rr,DEFAULT_FONT_SIZE as Yf,DEFAULT_FONT_FAMILY as Xf,getFontString as jf,isTestEnv as $f,normalizeEOL as Vf}from"@excalidraw/common";var Ue=(e,t,n)=>{let i=e.split(`
2
2
  `).map(a=>a||" ").join(`
3
- `),o=parseFloat(t),r=Pu(i,o,n);return{width:ga(i,t),height:r}},fa="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),ha=(e,t)=>{let n=Iu(e);return n===0?Je(fa.split("").join(`
4
- `),e,t).width+Ni*2:n+Ni*2},Hi=(e,t)=>Je("",e,t).width+Ni*2,jx=()=>ga(fa,wu({fontSize:gu,fontFamily:xu}))>0,ir=e=>bu(e).replace(/\t/g," "),or=e=>ir(e).split(`
5
- `),Wx=e=>{let t=or(e.text).length;return e.height/t/e.fontSize},zi=(e,t)=>e*t,Ea=(e,t)=>zi(e,t)+Ni*2,Fi,Vx=e=>{Fi=e},nr=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 yu()?r*10:r}},zt=(e,t)=>(Fi||(Fi=new nr),Fi.getLineWidth(e,t)),ga=(e,t)=>{let n=or(e),i=0;return n.forEach(o=>{i=Math.max(i,zt(o,t))}),i},Pu=(e,t,n)=>{let i=or(e).length;return zi(t,n)*i},Sn=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=zt(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),$x=e=>{let t=Sn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},Iu=e=>{let t=Sn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as Su,isTestEnv as Mu}from"@excalidraw/common";var rr,_i,sr,Jx=e=>(rr||(rr=J.class(...Object.values(bt))),rr.test(e)),Tu=()=>{if(!_i)try{_i=Du()}catch{_i=Au()}return _i},ar=()=>(sr||(sr=vu()),sr),Ve={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},fn={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},Au=()=>J.or(ar(),ue.On(Ve.HYPHEN,Ve.WHITESPACE,bt.CHAR)),Du=()=>J.or(ar(),ue.Before(Ve.WHITESPACE).Build(),ue.After(Ve.WHITESPACE,Ve.HYPHEN).Build(),ue.Before(bt.CHAR,bt.CURRENCY).NotPrecededBy(Ve.OPENING,bt.OPENING).Build(),ue.After(bt.CHAR).NotFollowedBy(Ve.HYPHEN,Ve.CLOSING,bt.CLOSING).Build(),ue.BeforeMany(bt.OPENING).NotPrecededBy(Ve.OPENING).Build(),ue.AfterMany(bt.CLOSING).NotFollowedBy(Ve.CLOSING).Build(),ue.AfterMany(Ve.CLOSING).FollowedBy(Ve.OPENING).Build()),vu=()=>J.group(J.or(fn.FLAG,J.and(fn.MOST,fn.JOINER,J.build(`(?:${fn.ZWJ.source}(?:${fn.FLAG.source}|${fn.ANY.source}${fn.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)}]`)},ue={On:(...e)=>{let t=J.join(...e);return J.build(`([${t}])`)},Before:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?=[${t}])`);return ue.Chain(n)},After:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<=[${t}])`);return ue.Chain(n)},BeforeMany:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<![${t}])(?=[${t}])`);return ue.Chain(n)},AfterMany:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<=[${t}])(?![${t}])`);return ue.Chain(n)},NotBefore:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?![${t}])`);return ue.Chain(n)},NotAfter:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<![${t}])`);return ue.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=ue.After(...t).Build(),o=()=>J.and(i,n);return ue.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=ue.Before(...t).Build(),o=()=>J.and(n,i);return ue.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=ue.NotAfter(...t).Build(),o=()=>J.and(i,n);return ue.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=ue.NotBefore(...t).Build(),o=()=>J.and(n,i);return ue.Chain(o)}})},Lu=e=>{let t=Tu();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(zt(r,t)<=n){i.push(r);continue}let a=Cu(r,t,n);i.push(...a)}return i.join(`
7
- `)},Cu=(e,t,n)=>{let i=[],r=Lu(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let d=l.value,c=s+d,u=ku(d)?a+Sn.calculate(d,t):zt(c,t);if(/\s/.test(d)||u<=n){s=c,a=u,l=r.next();continue}if(s)i.push(s.trimEnd()),s="",a=0;else{let p=Gu(d,t,n),m=p[p.length-1]??"",f=p.slice(0,-1);i.push(...f),s=m,a=zt(m,t),l=r.next()}}if(s){let d=Bu(s,t,n);i.push(d)}return i},Gu=(e,t,n)=>{if(ar().test(e))return[e];Ou(e);let i=[],o=Array.from(e),r="",s=0;for(let a of o){let l=Sn.calculate(a,t),d=s+l;if(d<=n){r=r+a,s=d;continue}r&&i.push(r),r=a,s=l}return r&&i.push(r),i},Bu=(e,t,n)=>{if(!(zt(e,t)>n))return e;let[,o,r]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],s=zt(o,t);for(let a of Array.from(r)){let l=Sn.calculate(a,t),d=s+l;if(d>n)break;o=o+a,s=d}return o},ku=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Ou=e=>{if((Mu()||Su())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var ba=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;Hu()||zu(!t||!Y(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?Y(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?et(t,e):e.width,r.text=Pt(e.originalText,Yi(e),o));let s=Je(r.text,Yi(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=ti(t,e),l=et(t,e);if(!Y(t)&&s.height>a){let p=lr(s.height,t.type);n.mutateElement(t,{height:p}),pa(t.id,p)}if(s.width>l){let p=lr(s.width,t.type);n.mutateElement(t,{width:p})}let d={...e,...r},{x:c,y:u}=ei(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},hn=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!It(e))return;ma(e.id);let s=W(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=et(e,s),u=ti(e,s),p=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=Pt(s.originalText,Yi(s),c));let m=Je(a,Yi(s),s.lineHeight);l=m.height,d=m.width}if(l>u){p=lr(l,e.type);let m=p-e.height,f=!Y(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:d,height:l}),Y(e)||t.mutateElement(s,ei(e,s,o))}},ei=(e,t,n)=>{if(Y(e))return U.getBoundTextElementPosition(e,t,n);let i=dr(e),o=ti(e,t),r=et(e,t),s,a;t.verticalAlign===wa.TOP?a=i.y:t.verticalAlign===wa.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===xa.LEFT?s=i.x:t.textAlign===xa.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=ya(i.x+r/2,i.y+o/2),c=ya(s+t.width/2,a+t.height/2),[u,p]=_u(c,d,l);return{x:u-t.width/2,y:p-t.height/2}}return{x:s,y:a}},It=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,W=(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,dw=(e,t,n)=>{if(!Y(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(U.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=U.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=U.getEditorMidPoints(e,n,t)[o];return r||(r=U.getSegmentMidPoint(e,o+1)),{x:r[0],y:r[1]}},dr=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}},cw=(e,t)=>Y(t)?0:t?t.angle:e.angle,uw=(e,t,n)=>{if(Y(e))return U.getBoundTextElementPosition(e,t,n)},pw=(e,t)=>e.some(n=>{if(ce(n)){let i=Ce(n,t);return!Y(i)}return!1}),mw=(e,t)=>e.some(n=>{if(ce(n)){let i=Ce(n,t);return!Y(i)}return ie(n)}),Yu=new Set(["rectangle","ellipse","diamond","arrow"]),fw=e=>Yu.has(e.type),lr=(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},et=(e,t)=>{let{width:n}=e;if(Y(e)){let i=(t?.fontSize??Nu)*Ru;return Math.max(Fu*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},ti=(e,t)=>{let{height:n}=e;return Y(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},hw=(e,t=`
3
+ `),o=parseFloat(t),r=Kf(i,o,n);return{width:Md(i,t),height:r}},Pd="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),Sd=(e,t)=>{let n=Zf(e);return n===0?Ue(Pd.split("").join(`
4
+ `),e,t).width+rr*2:n+rr*2},sr=(e,t)=>Ue("",e,t).width+rr*2,R1=()=>Md(Pd,jf({fontSize:Yf,fontFamily:Xf}))>0,oo=e=>Vf(e).replace(/\t/g," "),Cs=e=>oo(e).split(`
5
+ `),z1=e=>{let t=Cs(e.text).length;return e.height/t/e.fontSize},ar=(e,t)=>e*t,Id=(e,t)=>ar(e,t)+rr*2,or,_1=e=>{or=e},Ls=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 $f()?r*10:r}},Ln=(e,t)=>(or||(or=new Ls),or.getLineWidth(e,t)),Md=(e,t)=>{let n=Cs(e),i=0;return n.forEach(o=>{i=Math.max(i,Ln(o,t))}),i},Kf=(e,t,n)=>{let i=Cs(e).length;return ar(t,n)*i},Mi=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=Ln(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),H1=e=>{let t=Mi.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},Zf=e=>{let t=Mi.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};M();import{isDevEnv as qf,isTestEnv as Qf}from"@excalidraw/common";var ks,lr,Ns,j1=e=>(ks||(ks=de.class(...Object.values(sn))),ks.test(e)),Jf=()=>{if(!lr)try{lr=th()}catch{lr=eh()}return lr},Os=()=>(Ns||(Ns=nh()),Ns),Pt={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},sn={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},ti={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},eh=()=>de.or(Os(),Se.On(Pt.HYPHEN,Pt.WHITESPACE,sn.CHAR)),th=()=>de.or(Os(),Se.Before(Pt.WHITESPACE).Build(),Se.After(Pt.WHITESPACE,Pt.HYPHEN).Build(),Se.Before(sn.CHAR,sn.CURRENCY).NotPrecededBy(Pt.OPENING,sn.OPENING).Build(),Se.After(sn.CHAR).NotFollowedBy(Pt.HYPHEN,Pt.CLOSING,sn.CLOSING).Build(),Se.BeforeMany(sn.OPENING).NotPrecededBy(Pt.OPENING).Build(),Se.AfterMany(sn.CLOSING).NotFollowedBy(Pt.CLOSING).Build(),Se.AfterMany(Pt.CLOSING).FollowedBy(Pt.OPENING).Build()),nh=()=>de.group(de.or(ti.FLAG,de.and(ti.MOST,ti.JOINER,de.build(`(?:${ti.ZWJ.source}(?:${ti.FLAG.source}|${ti.ANY.source}${ti.JOINER.source}))*`)))),de={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>de.build(de.join(...e)),or:(...e)=>de.build(e.map(t=>t.source).join("|")),group:(...e)=>de.build(`(${de.join(...e)})`),class:(...e)=>de.build(`[${de.join(...e)}]`)},Se={On:(...e)=>{let t=de.join(...e);return de.build(`([${t}])`)},Before:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?=[${t}])`);return Se.Chain(n)},After:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<=[${t}])`);return Se.Chain(n)},BeforeMany:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<![${t}])(?=[${t}])`);return Se.Chain(n)},AfterMany:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<=[${t}])(?![${t}])`);return Se.Chain(n)},NotBefore:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?![${t}])`);return Se.Chain(n)},NotAfter:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<![${t}])`);return Se.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=Se.After(...t).Build(),o=()=>de.and(i,n);return Se.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=Se.Before(...t).Build(),o=()=>de.and(n,i);return Se.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=Se.NotAfter(...t).Build(),o=()=>de.and(i,n);return Se.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=Se.NotBefore(...t).Build(),o=()=>de.and(n,i);return Se.Chain(o)}})},ih=e=>{let t=Jf();return e.normalize("NFC").split(t).filter(Boolean)},St=(e,t,n)=>rh(e,t,n).map(i=>i.text).join(`
6
+ `),oh=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}})},rh=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return oh(e);let i=[],o=0;for(let r of e.split(`
8
+ `))Ln(r,t)<=n?i.push({text:r,start:o,end:o+r.length}):i.push(...sh(r,t,n,o)),o+=r.length+1;return i},sh=(e,t,n,i)=>{let o=[],r=ih(e),s="",a=i,l=i,d=0,c=i,u=0;for(;u<r.length;){let p=r[u],m=c,h=m+p.length,f=s+p,g=ch(p)?d+Mi.calculate(p,t):Ln(f,t);if(/\s/.test(p)||g<=n){s||(a=m),s=f,l=h,d=g,c=h,u++;continue}if(s)o.push(dh(s,a,l)),s="",a=m,l=m,d=0;else{let E=ah(p,t,n,m),x=E[E.length-1]??{text:"",start:m,end:m},b=E.slice(0,-1);o.push(...b),s=x.text,a=x.start,l=x.end,d=Ln(x.text,t),c=h,u++}}if(s){let p=lh(s,a,l,t,n);o.push(p)}return o},ah=(e,t,n,i)=>{if(Os().test(e))return[{text:e,start:i,end:i+e.length}];uh(e);let o=[],r=Array.from(e),s="",a=i,l=i,d=0,c=i;for(let u of r){let p=c,m=p+u.length,h=Mi.calculate(u,t),f=d+h;if(f<=n){s||(a=p),s=s+u,l=m,d=f,c=m;continue}s&&o.push({text:s,start:a,end:l}),s=u,a=p,l=m,d=h,c=m}return s&&o.push({text:s,start:a,end:l}),o},lh=(e,t,n,i,o)=>{if(!(Ln(e,i)>o))return{text:e,start:t,end:n};let[,s,a]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],l=Ln(s,i);for(let d of Array.from(a)){let c=Mi.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)}},dh=(e,t,n)=>{let i=e.trimEnd();return{text:i,start:t,end:n-(e.length-i.length)}},ch=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,uh=e=>{if((Qf()||qf())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var cr=(e,t,n)=>{let i=n.getNonDeletedElementsMap();if(t&&ye(t)){Ti(t,n,{text:e});return}let o;gh()||Eh(!t||!W(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?W(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?Ct(t,e):e.width,r.text=St(e.originalText,dr(e),o));let s=Ue(r.text,dr(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=ro(t,e),l=Ct(t,e);if(!W(t)&&s.height>a){let p=Fs(s.height,t.type);n.mutateElement(t,{height:p}),yd(t.id,p)}if(s.width>l){let p=Fs(s.width,t.type);n.mutateElement(t,{width:p})}let d={...e,...r},{x:c,y:u}=ii(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},ni=(e,t,n,i=!1,o=!1,r=!1)=>{if(ye(e)){Ti(e,t,{bindings:!1});return}let s=t.getNonDeletedElementsMap();if(!kt(e))return;wd(e.id);let l=J(e,s);if(l&&l.text){if(!e)return;let d=l.text,c=l.height,u=l.width,p=Ct(e,l),m=ro(e,l),h=e.height;if(i||n!=="n"&&n!=="s"){d&&(d=St(l.originalText,dr(l),p));let f=Ue(d,dr(l),l.lineHeight);c=f.height,u=f.width}if(c>m){h=Fs(c,e.type);let f=(n==="n"||n==="ne"||n==="nw")!==r;t.mutateElement(e,{height:h,...!W(e)&&so(e,h,o?"center":f?"bottom":"top")})}t.mutateElement(l,{text:d,width:u,height:c}),W(e)||t.mutateElement(l,ii(e,l,s))}},ii=(e,t,n)=>{if(W(e))return R.getBoundTextElementPosition(e,t,n);let i=zs(e),o=ro(e,t),r=Ct(e,t),s,a;if(t.verticalAlign===Ad.TOP)a=i.y;else if(t.verticalAlign===Ad.BOTTOM)a=i.y+(o-t.height);else if(ye(e)){let d=e.height-Rs*2;a=i.y+Math.min((d-t.height)/2,o-t.height)}else a=i.y+(o/2-t.height/2);t.textAlign===Td.LEFT?s=i.x:t.textAlign===Td.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=ye(e)?Gs(e.x+e.width/2,e.y+e.height/2):Gs(i.x+r/2,i.y+o/2),c=Gs(s+t.width/2,a+t.height/2),[u,p]=xh(c,d,l);return{x:u-t.width/2,y:p-t.height/2}}return{x:s,y:a}},kt=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,J=(e,t)=>{if(!e)return null;let n=kt(e);if(n){let i=t.get(n)||null;return i&&!je(i)&&console.error("[NONDELETED][INVARIANT] Bound text element `isDeleted: true` which is not expected."),i}return null},Oe=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,rS=(e,t)=>{if(!W(e))return{x:e.x+e.width/2,y:e.y+e.height/2};let n=R.getBoundTextElementCenter(e,t);return{x:n[0],y:n[1]}},zs=e=>{let t=ye(e)?Rs:an,n=t,i=t;return e.type==="ellipse"&&(n+=e.width/2*(1-Math.sqrt(2)/2),i+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(n+=e.width/4,i+=e.height/4),{x:e.x+n,y:e.y+i}},sS=(e,t)=>W(t)?0:t?t.angle:e.angle,aS=(e,t,n)=>{if(W(e))return R.getBoundTextElementPosition(e,t,n)},_s=(e,t)=>{if(!e.containerId)return e;let n=t.get(e.containerId);return!n||!W(n)?e:{...e,...R.getBoundTextElementPosition(n,e,t)}},lS=(e,t)=>e.some(n=>{if(ge(n)){let i=Oe(n,t);return!W(i)}return!1}),dS=(e,t)=>e.some(n=>{if(ge(n)){let i=Oe(n,t);return!W(i)}return $(n)}),bh=new Set(["rectangle","stickynote","ellipse","diamond","arrow"]),cS=e=>bh.has(e.type),Fs=(e,t)=>{e=Math.ceil(e);let n=an*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(W(e)){let i=(t?.fontSize??fh)*mh;return Math.max(ph*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-an*2:e.type==="diamond"?Math.round(n/2)-an*2:n-(ye(e)?Rs:an)*2},ro=(e,t)=>{let{height:n}=e;return ye(e)?Math.max(0,n-hh):W(e)?n-an*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-an*2:e.type==="diamond"?Math.round(n/2)-an*2:n-an*2},uS=(e,t=`
8
9
 
9
- `)=>e.reduce((i,o)=>(ie(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as cr,distanceToLineSegment as ur,pointRotateRads as pr}from"@excalidraw/math";import{ellipse as Uu,ellipseDistanceFromPoint as Xu}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 ju(e,t,n);case"diamond":return Wu(e,t,n);case"ellipse":return Vu(e,t,n);case"line":case"arrow":case"freedraw":return $u(e,n)}},ju=(e,t,n)=>{let i=he(e,t),o=pr(n,i,-e.angle),[r,s]=Pn(e);return Math.min(...r.map(a=>ur(o,a)),...s.map(a=>cr(a,o)).filter(a=>a!==null))},Wu=(e,t,n)=>{let i=he(e,t),o=pr(n,i,-e.angle),[r,s]=In(e);return Math.min(...r.map(a=>ur(o,a)),...s.map(a=>cr(a,o)).filter(a=>a!==null))},Vu=(e,t,n)=>{let i=he(e,t);return Xu(pr(n,i,-e.angle),Uu(i,e.width/2,e.height/2))},$u=(e,t)=>{let[n,i]=Gi(e);return Math.min(...n.map(o=>ur(t,o)),...i.map(o=>cr(o,t)))};var ji=e=>{if(e.type==="arrow")return!1;let t=!Zu(e.backgroundColor)||st(e)||Oi(e)||ie(e);return e.type==="line"?t&&pn(e.points):e.type==="freedraw"?t&&pn(e.points):t||we(e)},ip=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null})=>{let r=o?Ui(St(o.x-n,o.y-n),e,St(o.x+o.width+n,o.y+o.height+n)):!1,s=pe(t,i,!0);return!Ui(St(s[0]-n,s[1]-n),lt(e,dt(s),-t.angle),St(s[2]+n,s[3]+n))&&!r?!1:ji(t)&&Aa(e,t,i)||Pa(e,t,i,n)||r},op=(e,t,n,i=0)=>{let[o,r,s,a]=pe(t,n);return o-=i,r-=i,s+=i,a+=i,Ui(St(o,r),e,St(s,a))},kw=(e,t)=>!ip(e)&&!rp(e.point,e.element,t)&&op(e.point,e.element,t),rp=(e,t,n)=>{let i=W(t,n);if(!i)return!1;let o=j(t)?{...i,...U.getBoundTextElementPosition(t,i,n)}:i;return Aa(e,o,n)},Mn=(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=pe(e,t);if(!En(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return ap(e,t,n,i,o);case"diamond":return lp(e,t,n,i,o);case"ellipse":return dp(e,t,n,i);case"line":case"freedraw":case"arrow":return sp(e,n,o)}},Ma=(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(!En(a,l))continue;let d=Ia(s,t);if(d.length>0){for(let c of d)n.push(lt(c,i,o));if(r)return n}}return n},Ta=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Sa(s,t);if(a&&(n.push(lt(a,i,o)),r))return n}return n},sp=(e,t,n=!1)=>{let[i,o]=Gi(e),r=[];for(let s of i){let a=Sa(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(!En(a,l))continue;let d=Ia(s,t);if(d.length>0&&(r.push(...d),n))return r}return r},ap=(e,t,n,i=0,o=!1)=>{let r=he(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Xi(s,a),[d,c]=Pn(e,i),u=[];return Ta(d,l,u,r,e.angle,o),o&&u.length>0||Ma(c,l,u,r,e.angle,o),u},lp=(e,t,n,i=0,o=!1)=>{let r=he(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Xi(s,a),[d,c]=In(e,i),u=[];return Ta(d,l,u,r,e.angle,o),o&&u.length>0||Ma(c,l,u,r,e.angle,o),u},dp=(e,t,n,i=0)=>{let o=he(e,t),r=lt(n[0],o,-e.angle),s=lt(n[1],o,-e.angle);return np(tp(o,e.width/2+i,e.height/2+i),Xi(r,s)).map(a=>lt(a,o,e.angle))},Pa=(e,t,n,i=1)=>_t(t,n,e)<=i,Aa=(e,t,n)=>{if((j(t)||Me(t))&&!pn(t.points))return!1;let[i,o,r,s]=pe(t,n);if(!Ui(St(i,o),e,St(r,s)))return!1;let a=St((i+r)/2,(o+s)/2),l=qu(ep(Ju(Qu(e,a,.1)),Math.max(t.width,t.height)*2),a),d=Xi(e,l);return Mn(t,n,d).filter((u,p,m)=>m.findIndex(f=>Ku(f,u))===p).length%2===1};P();import{invariant as Da,isDevEnv as cp,isTestEnv as up}from"@excalidraw/common";import{pointFrom as Yt,pointFromVector as Vi,pointRotateRads as $i,pointScaleFromOrigin as Zi,pointsEqual as pp,triangleIncludesPoint as mr,vectorCross as Ge,vectorFromPoint as K,vectorScale as qi}from"@excalidraw/math";var fe=[1,0],ye=[0,1],ke=[-1,0],ze=[0,-1],Mt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?fe:t<=-o?ke:n>i?ye:ze},Be=(e,t)=>Mt(K(e,t)),tt=(e,t)=>Oe(Be(e,t)),me=(e,t)=>e[0]===t[0]&&e[1]===t[1],Oe=e=>me(e,fe)||me(e,ke),zw=e=>!Oe(e),mp=(e,t,n)=>{let i=dt(t);(cp()||up())&&(Da(e.width>0&&e.height>0,"Diamond element has no width or height"),Da(!pp(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Vi(qi(K($i(Yt(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Vi(qi(K($i(Yt(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Vi(qi(K($i(Yt(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Vi(qi(K($i(Yt(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Ge(K(n,r),K(r,s))<=0&&Ge(K(n,r),K(r,l))>0)return Be(r,i);if(Ge(K(n,s),K(s,a))<=0&&Ge(K(n,s),K(s,r))>0)return Be(s,i);if(Ge(K(n,a),K(a,l))<=0&&Ge(K(n,a),K(a,s))>0)return Be(a,i);if(Ge(K(n,l),K(l,r))<=0&&Ge(K(n,l),K(l,a))>0)return Be(l,i);if(Ge(K(n,i),K(r,i))<=0&&Ge(K(n,i),K(s,i))>0){let c=e.width>e.height?r:s;return Be(c,i)}else if(Ge(K(n,i),K(s,i))<=0&&Ge(K(n,i),K(a,i))>0){let c=e.width>e.height?a:s;return Be(c,i)}else if(Ge(K(n,i),K(a,i))<=0&&Ge(K(n,i),K(l,i))>0){let c=e.width>e.height?a:l;return Be(c,i)}let d=e.width>e.height?r:l;return Be(d,i)},ni=(e,t,n)=>{let o=dt(t);if(e.type==="diamond")return mp(e,t,n);let r=Zi(Yt(t[0],t[1]),o,2),s=Zi(Yt(t[2],t[1]),o,2),a=Zi(Yt(t[0],t[3]),o,2),l=Zi(Yt(t[2],t[3]),o,2);return mr([r,s,o],n)?ze:mr([s,l,o],n)?fe:mr([l,a,o],n)?ye:ke},fr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Gp,randomInteger as Mr,getUpdatedTimestamp as Tr}from"@excalidraw/common";P();import{clamp as Ki,pointDistance as gr,pointFrom as z,pointScaleFromOrigin as fp,pointsEqual as oi,pointTranslate as Er,vector as ct,vectorCross as Qi,vectorFromPoint as xr,vectorScale as hp}from"@excalidraw/math";import{BinaryHeap as Ep,invariant as Tn,isAnyTrue as gp,tupleToCoors as xp,getSizeFromPoints as va,isDevEnv as wp,arrayToMap as yp}from"@excalidraw/common";var wr=1,ee=40,bp=(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 d=Be(s,l[a-1]),c=Be(l[a-1],l[a-2]);if(me(d,c)){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(gr(l[a-2],l[a-1])<wr){let d=n?.findIndex(p=>p.index===a-2)??-1,c=n?.findIndex(p=>p.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),o.splice(-2,2),n.forEach(p=>{p.index>a-2&&(p.index-=2)});let u=tt(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(Pr(Ir(br(e,yr(e,t,o.map(s=>z(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(wp()&&Tn(Ra(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}},Pp=(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],d=e.x+(a?a.end[0]:0),c=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}=yr({x:d,y:c,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])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:b}=Tt(Pr(Ir(br(e,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y})??[])),t,null,null);if(!b||b.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let 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),D=w.flatMap((T,N)=>{let C=w[N-1],R=w[N+1];if(C&&R){let L=Be(T,C),V=Be(R,T);if(me(L,V))return M.forEach(H=>{H.index>N&&(H.index-=1)}),[];if(me(L,fr(V)))return M.forEach(H=>{H.index>N&&(H.index+=1)}),[T,T]}return[T]});return Tt(D,M,!1,!1)},Ip=(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,d=gr(t[s].start,t[s].end),c=d<ee+5;if(a===-1&&t[s].index===1&&o){let w=Oe(n),M=(w?me(n,fe):me(n,ye))?c?d/2:ee:c?-d/2:-ee;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=Oe(i),M=(w?me(i,fe):me(i,ye))?c?d/2:ee:c?-d/2:-ee;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]&&!oi(p[m],p[m-1])?tt(p[m-1],p[m]):void 0,x=p[f+1]&&!oi(p[f],p[f+1])?tt(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=tt(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=tt(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?Oe(n):tt(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=Oe(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)},Sp=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=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+(d?1:0),E=2+(c?1:0);for(;m.length+f<u.length-E;)m.push(u[m.length+f]);{let h=u.at(d?2:1),g=u.at(d?3:2);if(!h||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=Oe(i),y=Oe(Mt(xr(h,g)));if(a&&x===y){let b=x?me(i,fe):me(i,ye);if(m.unshift(z(y?r[0]+(b?ee:-ee):g[0],y?g[1]:r[1]+(b?ee:-ee))),m.unshift(z(x?r[0]+(b?ee:-ee):r[0],x?r[1]:r[1]+(b?ee:-ee))),!d){d=!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])),d){d=!1;for(let b of p)b.index>1&&(b.index-=1)}m.unshift(r)}{let h=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!h||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=Oe(o),y=tt(g,h);if(l&&x===y){let b=x?me(o,fe):me(o,ye);m.push(z(y?s[0]+(b?ee:-ee):g[0],y?g[1]:s[1]+(b?ee:-ee))),m.push(z(x?s[0]+(b?ee:-ee):s[0],x?s[1]:s[1]+(b?ee:-ee))),c||(c=!0)}else m.push(z(y?s[0]:h[0],y?h[1]:s[1])),c&&(c=!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])})),d,c)},Ut=1e6,Dn=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};A.PROD||(Tn(!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)"),Tn(!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"),Tn(!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"),Tn(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"),Tn(n.fixedSegments?.find(w=>w.index===1&&oi(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&oi(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,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&eo(d.elementId,t),p=c&&eo(c.elementId,t),m=Ra(r);if(d&&!u&&m||c&&!p&&m||t.size===0&&m||Object.keys(l).length===0&&(u?.id!==d?.elementId||p?.id!==c?.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}=yr({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&&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?bp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,I)=>oi(w,e.points[I]??z(1/0,1/0)))&&m?{}:o.length===0?Tt(Pr(Ir(br(e,{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?Pp(e,o,t):n.points?n.points&&n.fixedSegments?n:Sp(e,r,o,f,E,h,g,x,y):Ip(e,o,f,E,x,y)},yr=(e,t,n,i)=>{let o=Er(n[0],ct(e.x,e.y)),r=Er(n[n.length-1],ct(e.x,e.y)),s=null,a=null;if(i?.isDragging){let w=Array.from(t.values());s=Ba(o,t,w,i?.zoom)||null,a=Ba(r,t,w,i?.zoom)||null}else s=e.startBinding&&eo(e.startBinding.elementId,t)||null,a=e.endBinding&&eo(e.endBinding.elementId,t)||null;let l=Ca({...e,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging),d=Ca({...e,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging),c=Ga(l,d,s,o,t),u=Ga(d,l,a,r,t),p=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],m=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],f=s?$e(s,t,Xt(c,e.startArrowhead?oe*6:oe*2,1)):p,E=a?$e(a,t,Xt(u,e.endArrowhead?oe*6:oe*2,1)):m,h=An(l,a?$e(a,t,Xt(u,ee,ee)):m)||An(d,s?$e(s,t,Xt(c,ee,ee)):p),g=Oa(h?[p,m]:[f,E]),x=Ap(h?p:f,h?m:E,g,h?Xt(c,!s&&!a?0:ee,0):Xt(c,!s&&!a?0:ee-(e.startArrowhead?oe*6:oe*2),ee),h?Xt(u,!s&&!a?0:ee,0):Xt(u,!s&&!a?0:ee-(e.endArrowhead?oe*6:oe*2),ee),h,s&&$e(s,t),a&&$e(a,t)),y=La(x[0],c,l),b=La(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:y,startGlobalPoint:l,startHeading:c,endDonglePosition:b,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:h,startElementBounds:f,endElementBounds:E}},br=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Dp(n,i||o,r,s||a,l,d),p=i&&Ji(i,u),m=s&&Ji(s,u),f=Ji(a,u);f&&c&&(f.closed=!0);let E=Ji(o,u);E&&e.startBinding&&(E.closed=!0);let h=p&&m&&(An(p.pos,n[1])||An(m.pos,n[0])),g=Mp(p||E,m||f,u,r||fe,l||fe,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},Xt=(e,t,n)=>{switch(e){case ze:return[t,n,n,n];case fe:return[n,t,n,n];case ye:return[n,n,t,n]}return[n,n,n,t]},Mp=(e,t,n,i,o,r)=>{let s=hr(e.pos,t.pos),a=new Ep(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Tp(e,l);l.closed=!0;let d=Lp(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let p=fp(u.pos,l.pos,.5);if(gp(...r.map(b=>An(p,b))))continue;let m=Cp(c),f=l.parent?Mt(xr(l.pos,l.parent.pos)):i,E=fr(f);if(me(E,m)||ka(e.addr,u.addr)&&me(m,i)||ka(t.addr,u.addr)&&me(m,o))continue;let g=f!==m,x=l.g+hr(u.pos,l.pos)+(g?Math.pow(s,3):0),y=u.visited;if(!y||x<u.g){let b=vp(u,t,m,o);u.visited=!0,u.parent=l,u.h=hr(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},Tp=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},hr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Ap=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,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]+d[2])/2,e[0]-m):(l[0]+d[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]+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]+p):(l[3]+d[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((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]+E):(d[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((d[3]+l[1])/2,t[3]+h):(d[3]+l[1])/2:t[3]<e[3]?t[3]+h:n[3]+h],b=Oa([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,D=y[3]+(x[1]-y[3])/2;return Qi(ct(e[2]-w,e[1]-I),ct(e[0]-w,e[3]-I))>0?[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}else if(e[2]<t[0]&&e[3]<t[1]){let M=x[2]+(y[0]-x[2])/2,D=x[3]+(y[1]-x[3])/2;return Qi(ct(e[0]-w,e[1]-I),ct(e[2]-w,e[3]-I))>0?[[x[0],x[1],x[2],D],[y[0],D,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,D=x[3]+(y[1]-x[3])/2;return Qi(ct(e[2]-w,e[1]-I),ct(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],D],[y[0],D,y[2],y[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let M=y[2]+(x[0]-y[2])/2,D=y[3]+(x[1]-y[3])/2;return Qi(ct(e[0]-w,e[1]-I),ct(e[2]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}}return[x,y]},Dp=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===ke||n===fe?a.add(t[1]):s.add(t[0]),o===ke||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((p,m)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[m,u],pos:[p,c]})))}},La=(e,t,n)=>{switch(t){case ze:return z(n[0],e[1]);case fe:return z(e[2],n[1]);case ye:return z(n[0],e[3])}return z(e[0],n[1])},vp=(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 ze: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 ke:return e.pos[1]===t.pos[1]?4:2}else if(i===ke)switch(n){case fe:return e.pos[1]===t.pos[1]?4:2;case ze: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 ke:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===ze)switch(n){case fe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ze: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 ke: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 ze: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 ke:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Lp=([e,t],n)=>[ii([e,t-1],n),ii([e+1,t],n),ii([e,t+1],n),ii([e-1,t],n)],ii=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Ji=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=ii([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Oa=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]))],eo=(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=>Er(a,hp(xr(e[0]),-1)));return(o<-Ut||o>Ut||r<-Ut||r>Ut||o+s[s.length-1][0]<-Ut||r+s[s.length-1][0]>Ut||o+s[s.length-1][1]<-Ut||r+s[s.length-1][1]>Ut)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...va(s)}),s=s.map(([a,l])=>z(Ki(a,-1e6,1e6),Ki(l,-1e6,1e6))),{points:s,x:Ki(o,-1e6,1e6),y:Ki(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...va(s),startIsSpecial:n,endIsSpecial:i}},Pr=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},Ir=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return gr(i,t)>wr}):e,Cp=e=>{switch(e){case 0:return ze;case 1:return fe;case 2:return ye}return ke},Ca=(e,t,n,i,o,r,s)=>s?o&&r?Sr(e,o,t,r):i:o?to(n||[0,0],o,r??yp([o])):i,Ga=(e,t,n,i,o)=>Fa(e,t,n,n&&$e(n,o,Array(4).fill(_t(n,o,e))),i,o),Ba=(e,t,n,i)=>jt(xp(e),n,t,i,!0,!0),ka=(e,t)=>e[0]===t[0]&&e[1]===t[1],Ra=(e,t=wr)=>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 be=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,startBinding:a,endBinding:l,fileId:d}=n;B(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u"||typeof a<"u"||typeof l<"u")?n={...n,angle:0,...Dn({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Gp(r),...n});for(let c in n){let u=n[c];if(typeof u<"u"){if(e[c]===u&&(typeof u!="object"||u===null||c==="groupIds"||c==="scale"))continue;if(c==="scale"){let p=e[c],m=u;if(p[0]===m[0]&&p[1]===m[1])continue}else if(c==="points"){let p=e[c],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[c]=u,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof d<"u"||typeof r<"u")&&Pe.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Mr(),e.updated=Tr()),e},Ee=(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??Mr(),updated:Tr()}},Na=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Mr(),e.updated=Tr(),e);var Ey=e=>!e[Bp.CTRL_OR_CMD],Ar=e=>e.isBindingEnabled,oe=5,zp=10,_p=(e,t)=>{let n=[];return t.forEach(i=>{let o=e.getNonDeletedElement(i);o!=null&&n.push(o)}),n},Dr=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=new Set,s=new Set;_a(e,t,n,"start",r,s,i,o),_a(e,n,t,"end",r,s,i,o);let a=Array.from(s).filter(l=>!r.has(l));_p(i,a).forEach(l=>{i.mutateElement(l,{boundElements:l.boundElements?.filter(d=>d.type!=="arrow"||d.id!==e.id)})})},_a=(e,t,n,i,o,r,s,a)=>{if(t!=="keep"){if(t===null){let l=Wp(e,i,s);l!=null&&r.add(l);return}$a(e)?(n==null||(n==="keep"?!Wa(e,t,i):i==="start"||n.id!==t.id))&&(gn(e,t,i,s),o.add(t.id)):(gn(e,t,i,s),o.add(t.id))}},Xa=(e,t,n)=>["start","end"].map(i=>{let o=qa(e,i,t),r=i==="start"?e.startBinding?.elementId:e.endBinding?.elementId;if(r){let s=t.get(r);if(Le(s)&&io(s,o,t,n))return s}return null}),Yp=(e,t,n,i,o,r)=>{let a=e.points.length-1,l=n.findIndex(p=>p===0)>-1,d=n.findIndex(p=>p===a)>-1,c=l?t?oo(e,"start",i,o,r):null:"keep",u=d?t?oo(e,"end",i,o,r):null:"keep";return[c,u]},Up=(e,t,n,i,o)=>{if(B(e))return["keep","keep"];let[r,s]=Xa(e,t,o),a=r&&i?oo(e,"start",t,n,o):null,l=s&&i?oo(e,"end",t,n,o):null;return[a,l]},Xp=(e,t,n,i,o)=>{e.forEach(r=>{let[s,a]=n?.length?Yp(r,t,n??[],i.getNonDeletedElementsMap(),i.getNonDeletedElements(),o):Up(r,i.getNonDeletedElementsMap(),i.getNonDeletedElements(),t,o);Dr(r,s,a,i)})},gy=(e,t,n)=>e.length>50?[]:e.filter(j).flatMap(i=>Xa(i,t,n)).filter(i=>i!==null).filter(i=>e.filter(o=>o.id===i?.id).length===0),ja=(e,t,n,i,o)=>Array.from(t.reduce((r,s)=>{let a=jt(s,n.getNonDeletedElements(),n.getNonDeletedElementsMap(),i,B(e),B(e));return a!=null&&!Va(e,o?.id,a)&&r.add(a),r},new Set)),xy=(e,t,n,i)=>{let o=i.getNonDeletedElements(),r=i.getNonDeletedElementsMap();t.startBoundElement!=null&&gn(e,t.startBoundElement,"start",i);let s=jt(n,o,r,t.zoom,B(e),B(e));s!==null&&(Wa(e,s,"end")||gn(e,s,"end",i))},jp=(e,t)=>({...e,gap:Math.min(e.gap,ao(t,t.width,t.height))}),gn=(e,t,n,i)=>{if(!Y(e))return;let o={elementId:t.id,...jp(Zp(e,t,n,i.getNonDeletedElementsMap()),t)};B(e)&&(o={...o,...Za(e,t,n,i.getNonDeletedElementsMap())}),i.mutateElement(e,{[n==="start"?"startBinding":"endBinding"]:o}),Ua(t.boundElements||[]).has(e.id)||i.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Wa=(e,t,n)=>{let i=e[n==="start"?"endBinding":"startBinding"];return Va(e,i?.elementId,t)},Va=(e,t,n)=>t===n.id&&$a(e),$a=e=>e.points.length<3&&!B(e),Wp=(e,t,n)=>{let i=t==="start"?"startBinding":"endBinding",o=e[i];return o==null?null:(n.mutateElement(e,{[i]:null}),o.elementId)},jt=(e,t,n,i,o,r)=>{if(r){let a=!1,l=$p(t,c=>Le(c,!1)&&io(c,e,n,i,(o||!no(c))&&!Z(c))).filter(c=>a?!1:(no(c)||(a=!0),!0));if(!l||l.length===0)return null;if(l.length===1)return l[0];let d=l.filter(c=>io(c,e,n,i,!1));return d.length===1?d[0]:l.sort((c,u)=>u.width**2+u.height**2-(c.width**2+c.height**2)).pop()}return Vp(t,a=>Le(a,!1)&&io(a,e,n,i,(o||!no(a))&&!Z(a)))},Vp=(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},$p=(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},Zp=(e,t,n,i)=>{let o=n==="start"?-1:1,r=o===-1?0:e.points.length-1,s=r-o,a=U.getPointAtIndexGlobalCoordinates(e,r,i),l=U.getPointAtIndexGlobalCoordinates(e,s,i);return{focus:nm(t,i,l,a),gap:Math.max(1,_t(t,i,a))}},Ue=(e,t,n)=>{if(!Le(e))return;let{newSize:i,simultaneouslyUpdated:o}=n??{},r=Kp(o),s=t.getNonDeletedElementsMap();n?.changedElements&&(s=new Map(s),n.changedElements.forEach(a=>{s.set(a.id,a)})),ro(s,e,a=>{if(!j(a)||a.isDeleted||!qp(a,e))return;let l=a.startBinding?s.get(a.startBinding.elementId):null,d=a.endBinding?s.get(a.endBinding.elementId):null,c=null,u=null;l&&d&&(c=pe(l,s),u=pe(d,s));let p={startBinding:Ya(e,a.startBinding,i),endBinding:Ya(e,a.endBinding,i)};if(r.has(a.id)){t.mutateElement(a,p);return}let m=so(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&&!En(c,u))){let g=tm(a,h,p[h],E,s);if(g)return[h==="startBinding"?0:a.points.length-1,{point:g}]}return null}).filter(E=>E!==null);U.movePoints(a,t,new Map(m),{...e.id===a.startBinding?.elementId?{startBinding:p.startBinding}:{},...e.id===a.endBinding?.elementId?{endBinding:p.endBinding}:{}});let f=W(a,s);f&&!f.isDeleted&&hn(a,t,!1)})},wy=(e,t,n)=>{j(e)?Xp([e],!0,[],t,n?.zoom):Ue(e,t,{...n,changedElements:new Map([[e.id,e]])})},qp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,Kp=e=>new Set((e||[]).map(t=>t.id)),Fa=(e,t,n,i,o,r,s)=>{let a=Mt(q(t,e));return!n||!i?a:Qp(o,n,r,s)?ni(n,i,e):Mt(q(e,he(n,r)))},Qp=(e,t,n,i)=>{let o=_t(t,n,e),r=ao(t,t.width,t.height,i);return o>r?null:o},Sr=(e,t,n,i)=>{(Rp()||Fp())&&Op(e.points.length>1,"Arrow should have at least 2 points");let o=$e(t,i),r=e.points[n==="start"?0:e.points.length-1],s=O(e.x+r[0],e.y+r[1]),a=la(t)?Jp(t,i,s):s,l=B(e),d=dt(o),c=n==="start"?1:e.points.length-2,u=ae(O(e.x+e.points[c][0],e.y+e.points[c][1]),d,e.angle??0),p=null;if(l){let m=Oe(ni(t,o,s)),f=em(t,i,a),E=O(m?d[0]:f[0],m?f[1]:d[1]),h=Ye(E,vn(Ln(si(q(f,E)),Math.max(t.width,t.height)*2),E));p=Mn(t,i,h,oe).sort(Wt)[0]}else p=Mn(t,i,Ye(u,vn(Ln(si(q(a,u)),ut(a,u)+Math.max(t.width,t.height)*2),u)),oe).sort((m,f)=>Wt(m,u)-Wt(f,u))[0];return!p||Wt(a,p)<Hp?a:l?p:a},Jp=(e,t,n)=>{let i=he(e,t),o=ae(n,i,-e.angle);return o[0]<e.x&&o[1]<e.y?o[1]-e.y>-oe?ae(O(e.x-oe,e.y),i,e.angle):ae(O(e.x,e.y-oe),i,e.angle):o[0]<e.x&&o[1]>e.y+e.height?o[0]-e.x>-oe?ae(O(e.x,e.y+e.height+oe),i,e.angle):ae(O(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(O(e.x+e.width,e.y+e.height+oe),i,e.angle):ae(O(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(O(e.x+e.width,e.y-oe),i,e.angle):ae(O(e.x+e.width+oe,e.y),i,e.angle):n},em=(e,t,n,i=.05)=>{let{x:o,y:r,width:s,height:a,angle:l}=e,d=he(e,t,-.1,-.1),c=ae(n,d,-l),u=Ha(i*a,5,80),p=Ha(i*s,5,80);if(c[0]<=o+s/2&&c[1]>d[1]-u&&c[1]<d[1]+u)return ae(O(o-oe,d[1]),d,l);if(c[1]<=r+a/2&&c[0]>d[0]-p&&c[0]<d[0]+p)return ae(O(d[0],r-oe),d,l);if(c[0]>=o+s/2&&c[1]>d[1]-u&&c[1]<d[1]+u)return ae(O(o+s+oe,d[1]),d,l);if(c[1]>=r+a/2&&c[0]>d[0]-p&&c[0]<d[0]+p)return ae(O(d[0],r+a+oe),d,l);if(e.type==="diamond"){let m=oe,f=O(o+s/4-m,r+a/4-m),E=O(o+3*s/4+m,r+a/4-m),h=O(o+s/4-m,r+3*a/4+m),g=O(o+3*s/4+m,r+3*a/4+m);if(ut(f,c)<Math.max(p,u))return ae(f,d,l);if(ut(E,c)<Math.max(p,u))return ae(E,d,l);if(ut(h,c)<Math.max(p,u))return ae(h,d,l);if(ut(g,c)<Math.max(p,u))return ae(g,d,l)}return n},tm=(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(B(e)&&Qn(n)){let u=vr(n.fixedPoint)??Za(e,i,t==="startBinding"?"start":"end",o).fixedPoint,p=he(i,o),m=O(i.x+u[0]*i.width,i.y+u[1]*i.height),f=ae(m,p,i.angle);return U.pointFromAbsoluteCoords(e,f,o)}let a=s-r,l=U.getPointAtIndexGlobalCoordinates(e,a,o),d=im(i,o,n.focus,l),c;if(n.gap===0)c=d;else{let u=U.getPointAtIndexGlobalCoordinates(e,s,o),p=he(i,o),m=ut(l,u)+ut(l,p)+Math.max(i.width,i.height)*2,f=[...Mn(i,o,Ye(l,vn(Ln(si(q(d,l)),m),l)),n.gap).sort((E,h)=>Wt(E,l)-Wt(h,l)),vn(Ln(si(q(d,l)),ut(l,u)),l)];f.length>1?c=f[0]:f.length===1?c=d:c=u}return U.pointFromAbsoluteCoords(e,c,o)},Za=(e,t,n,i)=>{let o=[t.x,t.y,t.x+t.width,t.y+t.height],r=Sr(e,t,n,i),s=O(o[0]+(o[2]-o[0])/2,o[1]+(o[3]-o[1])/2),a=ae(r,s,-t.angle);return{fixedPoint:vr([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},Ya=(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(ao(e,i,o),t.gap*(i<o?i/r:o/s)));return{...t,gap:a}},oo=(e,t,n,i,o)=>jt(qa(e,t,n),i,n,o,B(e),B(e)),qa=(e,t,n)=>{let i=t==="start"?0:-1;return kp(U.getPointAtIndexGlobalCoordinates(e,i,n))},Ka=(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})}B(i)&&Object.assign(i,Dn(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},yy=(e,t)=>{let n=Ua(e);for(let i of t)Vt.unbindAffected(n,i,(o,r)=>be(o,n,r)),$t.unbindAffected(n,i,(o,r)=>be(o,n,r))},ri=(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},io=(e,{x:t,y:n},i,o,r)=>{let s=O(t,n),a=ao(e,e.width,e.height,o),l=(r||!no(e))&&!Z(e),d=[t-a,n-a,t+a,n+a],c=pe(e,i);if(!En(d,c))return!1;let u=Mn(e,i,Ye(he(e,i),s)),p=_t(e,i,s);return l?u.length===0||p<=a:u.length>0&&p<=a},ao=(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),zp/o+oe)},nm=(e,t,n,i)=>{let o=he(e,t);if(Np(n,i))return 0;let r=ae(n,o,-e.angle),s=ae(i,o,-e.angle),a=Math.sign(_e(q(s,n),q(s,o)))*-1,l=Ye(s,vn(Ln(si(q(s,r)),Math.max(e.width*2,e.height*2)),s)),d=e.type==="diamond"?[Ye(O(e.x+e.width/2,e.y),O(e.x+e.width/2,e.y+e.height)),Ye(O(e.x,e.y+e.height/2),O(e.x+e.width,e.y+e.height/2))]:[Ye(O(e.x,e.y),O(e.x+e.width,e.y+e.height)),Ye(O(e.x+e.width,e.y),O(e.x,e.y+e.height))],c=e.type==="diamond"?[Ye(O(e.x+e.width/2,e.y-e.height),O(e.x+e.width/2,e.y+e.height*2)),Ye(O(e.x-e.width,e.y+e.height/2),O(e.x+e.width*2,e.y+e.height/2))]:[Ye(O(e.x-e.width,e.y-e.height),O(e.x+e.width*2,e.y+e.height*2)),Ye(O(e.x+e.width*2,e.y-e.height),O(e.x-e.width,e.y+e.height*2))];return[za(l,c[0]),za(l,c[1])].filter(m=>m!==null).sort((m,f)=>Wt(m,i)-Wt(f,i)).map((m,f)=>a*ut(o,m)/(e.type==="diamond"?ut(d[f][0],d[f][1])/2:Math.sqrt(e.width**2+e.height**2)/2)).sort((m,f)=>Math.abs(m)-Math.abs(f))[0]??0},im=(e,t,n,i)=>{let o=he(e,t);if(n===0)return o;let r=(e.type==="diamond"?[O(e.x,e.y+e.height/2),O(e.x+e.width/2,e.y),O(e.x+e.width,e.y+e.height/2),O(e.x+e.width/2,e.y+e.height)]:[O(e.x,e.y),O(e.x+e.width,e.y),O(e.x+e.width,e.y+e.height),O(e.x,e.y+e.height)]).map(l=>vn(Ln(q(l,o),Math.abs(n)),o)).map(l=>ae(l,o,e.angle)),s=[_e(q(i,r[0]),q(r[1],r[0]))>0&&(n>0?_e(q(i,r[1]),q(r[2],r[1]))<0:_e(q(i,r[3]),q(r[0],r[3]))<0),_e(q(i,r[1]),q(r[2],r[1]))>0&&(n>0?_e(q(i,r[2]),q(r[3],r[2]))<0:_e(q(i,r[0]),q(r[1],r[0]))<0),_e(q(i,r[2]),q(r[3],r[2]))>0&&(n>0?_e(q(i,r[3]),q(r[0],r[3]))<0:_e(q(i,r[1]),q(r[2],r[1]))<0),_e(q(i,r[3]),q(r[0],r[3]))>0&&(n>0?_e(q(i,r[0]),q(r[1],r[0]))<0:_e(q(i,r[2]),q(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]},Qa=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),ro=(e,t,n)=>{Le(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},so=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(ce(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(Y(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&&so(t,n,o=>{!o||o.isDeleted||ro(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:ri(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||so(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(Y(n)&&i(o,{boundElements:ri(o.boundElements,new Set,new Array(n))}),ie(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:ri(o.boundElements,new Set,new Array(n))}))))})}},$t=class{static unbindAffected(t,n,i){n&&ro(t,n,o=>{!o||o.isDeleted||so(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||ro(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:ri(n.boundElements,new Set([s]))});return}ie(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:ri(n.boundElements,new Set([o.id]))})))})}},to=(e,t,n)=>{let[i,o]=vr(e);return ae(O(t.x+t.width*i,t.y+t.height*o),he(t,n),t.angle)},om=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?to(e.startBinding.fixedPoint,n,t):O(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?to(e.endBinding.fixedPoint,i,t):O(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},Ja=(e,t)=>{let[n,i]=om(e,t);return[U.pointFromAbsoluteCoords(e,n,t),U.pointFromAbsoluteCoords(e,i,t)]},vr=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 Cr=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>G(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},U=class e{elementId;selectedPointsIndices;pointerDownState;isDragging;lastUncommittedPoint;pointerOffset;startBindingElement;endBindingElement;hoverPointIndex;segmentMidPointHoveredCoords;elbowed;customLineAngle;isEditing;constructor(t,n,i=!1){this.elementId=t.id,tl(t.points[0],G(0,0))||(console.error("Linear element is not normalized",Error().stack),be(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=B(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,p]=_(n.selectionElement,o),f=e.getPointsGlobalCoordinates(l,o).reduce((E,h,g)=>((h[0]>=d&&h[0]<=u&&h[1]>=c&&h[1]<=p||t.shiftKey&&s?.includes(g))&&E.push(g),E),[]).filter(E=>!(B(l)&&E!==0&&E!==l.points.length-1));i({selectedLinearElement:{...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),d=r.customLineAngle;if(!l||B(l)&&!r.pointerDownState.lastClickedIsEndPoint&&r.pointerDownState.lastClickedPoint!==0)return null;let c=B(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=B(l)?r.pointerDownState.lastClickedPoint>0?l.points.length-1:0:r.pointerDownState.lastClickedPoint,p=l.points[u];if(c&&p){if(nl(t)&&c.length===1&&l.points.length>1){let h=c[0],g=l.points[h===0?1:h-1];d=r.customLineAngle??Math.atan2(l.points[h][1]-g[1],l.points[h][0]-g[0]);let[x,y]=e._getShiftLockedDelta(l,a,g,G(i,o),t[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),d);e.movePoints(l,n.scene,new Map([[h,{point:G(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[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize()),g=h[0]-p[0],x=h[1]-p[1];e.movePoints(l,n.scene,new Map(c.map(y=>{let b=y===u?e.createPointAt(l,a,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize()):G(l.points[y][0]+g,l.points[y][1]+x);return[y,{point:b,isDragging:y===u}]})))}W(l,a)&&hn(l,n.scene,!1);let f=[];if(er(l,!1)){let h=c[0]===0,g=c[c.length-1]===l.points.length-1,x=[];!h!=!g?x.push({x:i,y:o}):(h&&x.push(Lr(e.getPointGlobalCoordinates(l,l.points[0],a))),g&&x.push(Lr(e.getPointGlobalCoordinates(l,l.points[c[c.length-1]],a)))),x.length&&(f=ja(l,x,n.scene,n.state.zoom))}let E={...r,selectedPointsIndices:c,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:d};return{...n.state,selectedLinearElement:E,suggestedBindings:f}}return null}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),s=o.getNonDeletedElements(),a=dm(t,i),{elementId:l,selectedPointsIndices:d,isDragging:c,pointerDownState:u}=n,p=e.getElement(l,r);if(!p)return n;let m={};if(c&&d){for(let f of d)if(f===0||f===p.points.length-1){cm(p.points,i.zoom.value)&&(mn(p)&&o.mutateElement(p,{...rl(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=Ar(i)?jt((d?.length??0)>1?Lr(e.getPointAtIndexGlobalCoordinates(p,f,r)):a,s,r,i.zoom,B(p),B(p)):null;m[f===0?"startBindingElement":"endBindingElement"]=E}}return{...n,...m,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:c||t.shiftKey?!c&&t.shiftKey&&u.prevSelectedPointsIndices?.includes(u.lastClickedPoint)?d&&d.filter(f=>f!==u.lastClickedPoint):d:d?.includes(u.lastClickedPoint)?[u.lastClickedPoint]:d,isDragging:!1,pointerOffset:{x:0,y:0},customLineAngle:null}}static getEditorMidPoints=(t,n,i)=>{let o=W(t,n);if(!B(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)){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(!B(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!B(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Cn(G(c[0],c[1]),G(n.x,n.y))<=d)return c;let u=0,p=e.getEditorMidPoints(s,o,i);for(;u<p.length;){if(p[u]!==null&&Cn(p[u],G(n.x,n.y))<=d)return p[u];u++}return null};static isSegmentTooShort(t,n,i,o,r){if(B(t))return o>=0&&o<t.points.length?Cn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=Cn(n,i);if(t.points.length>2&&t.roundness){let[a,l]=ol(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=sm(l[o])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(B(t)){At(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=el(t.points[n-1],t.points[n]);return G(t.x+r[0],t.y+r[1])}let[i,o]=ol(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 el(r[0],r[1])}if(o.length){let r=o[n-1];return am(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(),d=s.getNonDeletedElements(),c={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return c;let{elementId:u}=r,p=e.getElement(u,l);if(!p)return c;let m=e.getSegmentMidpointHitCoords(r,o,a,l),f=null;if(m)f=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(p,{points:[...p.points,e.createPointAt(p,l,o.x,o.y,t[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),c.didAddPoint=!0),i.scheduleCapture(),c.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:jt(o,d,l,n.state.zoom,r.elbowed)},c.didAddPoint=!0,c;let E=e.getPointIndexUnderCursor(p,l,a.zoom,o.x,o.y);if(E>=0||m)c.hitElement=p;else{let{startBindingElement:D,endBindingElement:T}=r;Ar(a)&&er(p)&&Dr(p,D,T,s)}let[h,g,x,y]=_(p,l),b=(h+x)/2,w=(g+y)/2,I=E>-1&&Te(G(p.x+p.points[E][0],p.y+p.points[E][1]),G(b,w),p.angle),M=E>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(E)?um([...r.selectedPointsIndices||[],E]):[E]:null;return c.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}},c}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:tl(t,n)}static handlePointerMove(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 p;if(nl(t)&&c.length>=2){let m=c[c.length-2],[f,E]=e._getShiftLockedDelta(d,l,m,G(n,i),t[Gn.CTRL_OR_CMD]?null:o.getEffectiveGridSize());p=G(f+m[0],E+m[1])}else p=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[Gn.CTRL_OR_CMD]||B(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:p}]])):e.addPoints(d,o.scene,[p]),{...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 Te(G(c+n[0],u+n[1]),G(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 Te(G(c+d[0],u+d[1]),G(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[r,s,a,l]=_(t,i),d=(r+a)/2,c=(s+l)/2,u=t.points[o],{x:p,y:m}=t;return u?Te(G(p+u[0],m+u[1]),G(d,c),t.angle):Te(G(p,m),G(d,c),t.angle)}static pointFromAbsoluteCoords(t,n,i){if(B(t))return G(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]=Te(G(n[0],n[1]),G(l,d),-t.angle);return G(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(Cn(G(o,r),G(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=il(i,o,r),[a,l,d,c]=_(t,n),u=(a+d)/2,p=(l+c)/2,[m,f]=Te(G(s[0],s[1]),G(u,p),-t.angle);return G(m-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=Cr(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){At(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,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=[],d=!1,c=-1,u=a.reduce((p,m,f)=>{if(++c,p.push(m),o.includes(f)){let h=a[f+1];h||(d=!0),p.push(h?G((m[0]+h[0])/2,(m[1]+h[1])/2):G(m[0],m[1])),l.push(c+1),++c}return p},[]);if(n.mutateElement(s,{points:u}),d){let p=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:G(p[0]+30,p[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));mn(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=G(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=Cr({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];mn(t)&&t.polygon&&(o[0]=G(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=Cr({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o){let{points:r}=t;if(mn(t)&&t.polygon){let c=i.get(0),u=i.get(r.length-1);c?i.set(r.length-1,{point:G(c.point[0],c.point[1]),isDragging:c.isDragging}):u&&i.set(0,{point:G(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=i.get(0)?.point??G(0,0),[a,l]=s,d=B(t)?[i.get(0)?.point??r[0],i.get(r.length-1)?.point??r[r.length-1]]:r.map((c,u)=>{let p=i.get(u)?.point??c;return G(p[0]-a,p[1]-l)});e._updatePoints(t,n,d,a,l,o,{isDragging:Array.from(i.values()).some(c=>c.isDragging)})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&B(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=Cn(G(a.x,a.y),G(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<lm/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,d={pointerDownState:t.pointerDownState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!B(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.pointerDownState,segmentMidpoint:{...t.pointerDownState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,i,o,r,s,a){if(B(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=Gr(t,i),d=Gr(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,p=(d[0]+d[2])/2,m=(d[1]+d[3])/2,f=p-c,E=m-u,h=Te(G(o,r),G(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(B(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=il(o[0],o[1],r),{width:c,height:u}=sl(a[0],a[1],l,d,s);return Te(G(c,u),G(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&be(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,d=(r+a)/2,c=(s+l)/2,{x:u,y:p}=e.getBoundTextElementPosition(t,o,n),m=u+o.width,f=p+o.height,E=G(d,c),h=Te(G(r,s),E,t.angle),g=Te(G(a,s),E,t.angle),x=Te(G(u,p),E,-t.angle),y=Te(G(m,p),E,-t.angle),b=Te(G(u,f),E,-t.angle),w=Te(G(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,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o,r,s,a,l;if(t.points.length<2||!Pe.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=Pe.generateElementShape(t,null),m=gt(p[0]),[f,E,h,g]=ai(m);r=f+t.x,s=E+t.y,a=h+t.x,l=g+t.y}let d=(r+a)/2,c=(s+l)/2;if(o=[r,s,a,l,d,c],!i)return o;let u=W(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||!B(a))return t;if(n&&n>0&&n<a.points.length){let l=Oe(Mt(rm(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((m,f)=>(m[f.index]=f,m),{});d[n]={index:n,start:G(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:G(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((m,f)=>m.index-f.index),u=c.map(m=>m.index).reduce((m,f)=>f<n?m+1:m,0);r.mutateElement(a,{fixedSegments:c});let p=G(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)})}},um=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 Bm,pointFrom as Fr}from"@excalidraw/math";P();import{vectorCross as cl,vectorFromPoint as lo}from"@excalidraw/math";function al(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 pm(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var mm=1e-6;function ll(e,t){let n=lo(e[1],e[0]),i=lo(t,e[0]),o=cl(n,i);return Math.abs(o)<mm}function Br(e,t){let n=lo(e[1],e[0]),i=lo(t,e[0]);return cl(n,i)<0}function dl(e,t){return ll(e,t[0])||ll(e,t[1])||(Br(e,t[0])?!Br(e,t[1]):Br(e,t[1]))}function ul(e,t){return pm(al(e),al(t))&&dl(e,t)&&dl(t,e)}P();import{arrayToMap as fm}from"@excalidraw/common";import{getElementBounds as hm}from"@excalidraw/element";import{isArrowElement as Em,isExcalidrawElement as gm,isFreeDrawElement as xm,isLinearElement as wm,isTextElement as ym}from"@excalidraw/element";import{rangeIncludesValue as co,pointFrom as Dt,pointRotateRads as bm,rangeInclusive as uo}from"@excalidraw/math";var Pm=e=>e.type==="diamond"?[Dt(e.width/2,0),Dt(e.width,e.height/2),Dt(e.width/2,e.height),Dt(0,e.height/2)]:[Dt(0,0),Dt(0+e.width,0),Dt(0+e.width,e.height),Dt(0,e.height)],Im=e=>wm(e)||xm(e)?e.points:Pm(e),pl=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},fl=e=>{let t=Im(e),{cx:n,cy:i}=pl(t),o=Dt(n,i),r=t.map(c=>bm(c,o,e.angle)),{minX:s,minY:a,maxX:l,maxY:d}=pl(r);return[s+e.x,a+e.y,l+e.x,d+e.y]},ml=(e,t,n=!1)=>{let i=fl(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},Sm=(e,t)=>{let n=fl(e);return(co(n[0],uo(t[0],t[2]))||co(t[0],uo(n[0],n[2])))&&(co(n[1],uo(t[1],t[3]))||co(t[1],uo(n[1],n[3])))},hl=({elements:e,bounds:t,type:n,errorMargin:i=0})=>{gm(t)&&(t=hm(t,fm(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"?Sm(s,o):n==="inside"?ml(s,o):ml(s,o,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);ym(s)&&s.containerId&&r.add(s.containerId),Em(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 Lm,isShallowEqual as Cm}from"@excalidraw/common";P();var Mm=(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}}},El=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 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];d[f]=!0}}let c={},u=s.reduce((p,m)=>{if(m.isDeleted)return p;let f=m.groupIds.find(E=>d[E]);return f&&(p[m.id]=!0,Array.isArray(c[f])?c[f].push(m.id):c[f]=[m.id]),p},{});for(let p of Object.keys(c))c[p].length<2&&d[p]&&(d[p]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:kr({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):pt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:kr(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),Tm=(e,t)=>Or(e,t)!=null,Or=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Am=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),gl=(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,...Mm(r,n,e)}}}return n.selectedGroupIds},qy=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Dm=(e,t)=>e.groupIds.includes(t),Ae=(e,t)=>{let n=[];for(let i of e.values())Dm(i,t)&&n.push(i);return n},vm=(e,t)=>e.groupIds.find(n=>t[n]),Ky=(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},Qy=(e,t)=>e.filter(n=>!t[n]),Jy=(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=W(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},xl=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},wl=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},yl=e=>e.groupIds.length>0,bl=(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},po=(e,t,n)=>{let i=Am(n),o=e.filter(u=>!ce(u)),r=new Map,s=new Map,a=u=>{let p=s.get(u.id)||[],m=W(u,t);m&&p.push(m),s.set(u.id,[...p,u])},l=(u,p)=>{let m=r.get(p)||[],f=W(u,t);f&&m.push(f),r.set(p,[...m,u])},d=(u,p)=>{let m=u.groupIds.indexOf(p,0);return u.groupIds.slice(0,m).length>0?l(u,u.groupIds[m-1]):a(u)},c=e.every(u=>Tm(n,u));return o.forEach(u=>{let p=vm(u,n.selectedGroupIds);p?i.length===1&&c?d(u,p):l(u,p):a(u)}),Array.from(r.values()).concat(Array.from(s.values()))};var Pl=e=>{let t=new Set;return e.forEach(n=>{Z(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},Rr=(e,t,n,i=!0)=>{let[o,r,s,a]=_(t,n),l=e.filter(d=>{let[c,u,p,m]=pe(d,n),f=vt(d,n);if(f){let[E,h,g,x]=pe(f,n);c=Math.max(E,c),u=Math.max(h,u),p=Math.min(g,p),m=Math.min(x,m)}return d.locked===!1&&d.type!=="selection"&&!ce(d)&&o<=c&&r<=u&&s>=p&&a>=m});return l=i?Pl(l):l,l=l.filter(d=>{let c=vt(d,n);return c?Zt(d,c,n):!0}),l},db=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=Il(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},cb=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&&ce(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{Z(s)&&qt(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},ub=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:pt(e,t,{includeBoundTextElement:!0}),kr=(e,t)=>Cm(t.selectedElementIds,e)?t.selectedElementIds:e,Gm=(e,t)=>{let n=e.filter(j);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 U(i,Lm(t))}return null},pb=(e,t,n)=>({selectedLinearElement:Gm(e,t),...El({editingGroupId:n.editingGroupId,selectedElementIds:Pl(e).reduce((i,o)=>(ce(o)||(i[o.id]=!0),i),{})},t,n,null)});var Sl=(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&&be(a,i,{frameId:s??null})}};function Bn(e,t,n){let i=Nr(t,n),o=Nr(e,n);return i.some(s=>o.some(a=>ul(s,a)))}var Ml=(e,t,n)=>mo(Rr(e,t,n,!1)).filter(i=>!Z(i)&&!i.frameId||i.frameId===t.id),Hr=(e,t,n)=>Rr([t],e,n).some(i=>i.id===t.id),Mb=(e,t)=>{let n=mt(e);return e.filter(i=>Bn(i,t,n))},Kt=(e,t,n)=>{let[i,o,r,s]=_(t,n),[a,l,d,c]=Xe(e);return i<=a&&o<=l&&r>=d&&s>=c},Zt=(e,t,n)=>Kt([e],t,n)||Bn(e,t,n)||Hr(e,t,n),Tb=(e,t,n)=>{let[i,o,r,s]=_(t,n);return Bm(Fr(i,o),Fr(e.x,e.y),Fr(r,s))},Ab=(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)||Bn(r,n,i))},Db=(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)||Bn(r,n,i))===void 0},vb=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,qt(e,i))}return t},qt=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},km=e=>e.filter(t=>Z(t)),Lb=e=>{let t=mt(km(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},Cb=(e,t,n,i)=>{let o=qt(e,t.id),r=new Set(o),s=new Set([...Ml(e,t,i),...o.filter(p=>Hr(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(!Bn(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 d=Array.from(s).filter(p=>p.groupIds.length===0);for(let p of d)r.add(p);let c=Array.from(s).filter(p=>p.groupIds.length>0),u=gl(c,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=>!(ie(p)&&p.containerId))},Gb=(e,t,n)=>Om(mo(e,Ml(e,t,n)),t,n),Om=(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},vt=(e,t)=>e.frameId&&t.get(e.frameId)||null,Bb=(e,t)=>{let n=new Set,i=mt(e);e=mo(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=Ae(e,a);if(l.some(d=>Zt(d,t,i)))for(let d of l)r.push(d)}}else Zt(s,t,i)&&r.push(s);return r},Rm=(e,t,n,i)=>{let o=mt(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 mo(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=W(d,o);c&&!s.has(c.id)&&!r.has(c.id)&&a.push(c)}for(let d of a)be(d,o,{frameId:n.id});return e},Tl=(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=W(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)be(o,t,{frameId:null})},Fm=(e,t)=>{let n=qt(e,t.id);return Tl(n,mt(e)),e},kb=(e,t,n,i)=>Rm(Fm(e,n),t,n,i.state).slice(),Ob=(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&&!Z(a)&&!Al(a,s,t)&&r.add(a)}),r.size>0&&Tl(r,s),e},mo=(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=>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},Nm=(e,t,n)=>{let i=ie(e)&&Ce(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?vt(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:vt(i,t)},Al=(e,t,n,i)=>{let o=i?.targetFrame??Nm(e,t,n);if(!o)return!1;let r=ie(e)&&Ce(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 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(c=>{a.delete(c)})}for(let l of a)if(Z(l))return s(!1),!1;for(let l of a)if(Zt(l,o,t))return s(!0),!0;return!1},Rb=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Bn(e,t,i)||Hr(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=Al(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},Hm="Frame",zm="AI Frame",_m=e=>Ri(e)?Hm:zm,Fb=e=>e.name===null?_m(e):e.name,Nb=(e,t)=>hl({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),Hb=e=>{let t=mt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Zm="invert(100%) hue-rotate(180deg) saturate(1.25)",Gl=(e,t)=>Ht(e)&&!t.imageCache.has(e.fileId),Bl=(e,t,n)=>n.theme===Cl.DARK&&Ht(e)&&!Gl(e,t)&&t.imageCache.get(e.fileId)?.mimeType!==Yr.svg,wo=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}},qm=(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*=Xm/100),r},Km=(e,t,n)=>{let r=wo(e),[s,a,l,d]=_(e,t),c=j(e)||Me(e)?Qt(s,l):e.width,u=j(e)||Me(e)?Qt(a,d):e.height,p=c*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}},kl=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=wo(e),{width:l,height:d,scale:c}=Km(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,p=0;if(j(e)||Me(e)){let[g,x]=_(e,t);u=e.x>g?Qt(e.x,g)*window.devicePixelRatio*c:0,p=e.y>x?Qt(e.y,x)*window.devicePixelRatio*c:0,s.translate(u,p)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let m=un.canvas(r);Bl(e,i,o)&&(s.filter=Zm),go(e,m,s,i,o),s.restore();let f=W(e,t),E=document.createElement("canvas"),h=E.getContext("2d");if(Y(e)&&f){let[g,x,y,b]=_(e,t),w=Math.max(Qt(g,y),Qt(x,b));E.width=w*window.devicePixelRatio*c+a*c*10,E.height=w*window.devicePixelRatio*c+a*c*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]=_(f,t);h.rotate(-e.angle);let D=(E.width-r.width)/2,T=(E.height-r.height)/2,N=E.width/2-(I-g)*window.devicePixelRatio*c-D-a*c,C=E.height/2-(M-x)*window.devicePixelRatio*c-T-a*c;h.translate(-N,-C),h.clearRect(-(f.width/2+ho)*window.devicePixelRatio*c,-(f.height/2+ho)*window.devicePixelRatio*c,(f.width+ho*2)*window.devicePixelRatio*c,(f.height+ho*2)*window.devicePixelRatio*c)}return{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:p,boundTextElementVersion:W(e,t)?.version||null,containingFrameOpacity:vt(e,t)?.opacity||100,boundTextCanvas:E,angle:e.angle,imageCrop:we(e)?e.crop:null}},t0=14,Ol=typeof document<"u"?document.createElement("img"):{src:""};Ol.src=`data:${Yr.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 Rl=typeof document<"u"?document.createElement("img"):{src:""};Rl.src=`data:${Yr.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 Qm=(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"?Rl:Ol,e.width/2-i/2,e.height/2-i/2,i,i)},go=(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(Pe.get(e));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Pe.get(e).forEach(r=>{t.draw(r)});break}case"freedraw":{n.save(),n.fillStyle=e.strokeColor;let r=Jm(e),s=Pe.get(e);s&&t.draw(s),n.fillStyle=e.strokeColor,n.fill(r),n.restore();break}case"image":{let r=Ht(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:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight};n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else Qm(e,n);break}default:if(ie(e)){let r=Wm(e.text),s=r&&!n.canvas.isConnected;s&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",r?"rtl":"ltr"),n.save(),n.font=jm(e),n.fillStyle=e.strokeColor,n.textAlign=e.textAlign;let a=e.text.replace(/\r\n?/g,`
10
- `).split(`
11
- `),l=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,d=zi(e.fontSize,e.lineHeight),c=Vm(e.fontFamily,e.fontSize,d);for(let u=0;u<a.length;u++)n.fillText(a[u],l,u*d+c);n.restore(),s&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},xo=new WeakMap,vl=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=xo.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=W(e,t),l=a?.version||null,d=we(e)?e.crop:null,c=vt(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.boundTextElementVersion!==l||r.imageCrop!==d||r.containingFrameOpacity!==c||Y(e)&&a&&e.angle!==r.angle){let u=kl(e,t,o,n,i);return u?(xo.set(e,u),u):null}return r},_r=(e,t,n,i,o)=>{let r=e.element,s=wo(r),a=e.scale,[l,d,c,u]=_(r,o),p=((l+c)/2+i.scrollX)*window.devicePixelRatio,m=((d+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=W(r,o);if(Y(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,-(c-l)/2*window.devicePixelRatio-E/a-s,-(u-d)/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&&!Gl(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,(d+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=W(r,o),h=dr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((h.x+i.scrollX)*window.devicePixelRatio,(h.y+i.scrollY)*window.devicePixelRatio,et(r,E)*window.devicePixelRatio,ti(r,E)*window.devicePixelRatio)}t.restore()},n0=(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()},i0=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=qm(e,vt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Um: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=Eo.strokeWidth/s.zoom.value,o.strokeStyle=Eo.strokeColor,aa(e)&&(o.strokeStyle=s.theme===Cl.LIGHT?"#7affd7":"#1d8264"),Eo.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Eo.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(Pe.generateElementShape(e,null),r.isExporting){let[l,d,c,u]=_(e,t),p=(l+c)/2+s.scrollX,m=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);o.save(),o.translate(p,m),o.rotate(e.angle),o.translate(-f,-E),go(e,i,o,r,s),o.restore()}else{let l=vl(e,n,r,s);if(!l)return;_r(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(Pe.generateElementShape(e,r),r.isExporting){let[l,d,c,u]=_(e,t),p=(l+c)/2+s.scrollX,m=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);if(ie(e)){let g=Ce(e,t);if(Y(g)){let x=U.getBoundTextElementPosition(g,e,t);f=(c-l)/2-(x.x-l),E=(u-d)/2-(x.y-d)}}o.save(),o.translate(p,m),Bl(e,r,s)&&(o.filter="none");let h=W(e,t);if(Y(e)&&h){let g=document.createElement("canvas"),x=g.getContext("2d"),y=Math.max(Qt(l,c),Qt(d,u)),b=wo(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-d),x.rotate(e.angle);let w=un.canvas(g);x.translate(-f,-E),go(e,w,x,r,s),x.translate(f,E),x.rotate(-e.angle);let[,,,,I,M]=_(h,t),D=(l+c)/2-I,T=(d+u)/2-M;x.translate(-D,-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),go(e,i,o,r,s);o.restore()}else{let l=vl(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Ym(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&we(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=kl(ta(l.element,t),n,s.zoom,r,s);c&&_r(c,o,r,s,n),o.restore()}_r(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1},Fl=new WeakMap([]);function Nl(e){let t=ef(e),n=new Path2D(t);return Fl.set(e,n),n}function Jm(e){return Fl.get(e)}function ef(e){return of(tf(e))}function o0(e,t,n){let i=pe({...e,angle:0},n),o=fo((i[0]+i[2])/2,(i[1]+i[3])/2);return $m(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(Dl(r[r.length-1][1],zr(fo(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[Dl(zr(fo(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),zr(fo(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}function tf(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 qs(t,n)}function Ll(e,t){return[(e[0]+t[0])/2,(e[1]+t[1])/2]}var nf=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;function of(e){if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Ll(i,r[0]),"L",r[0],"Z"):n.push(i,Ll(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(nf,"$1")}P();var a0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",l0=e=>e!=="image"&&e!=="frame"&&e!=="magicframe",d0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",c0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Hl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",u0=e=>e==="arrow",p0=e=>e==="arrow";var Pe=class e{static rg=new je;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;xo.delete(t);let o=uf(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:af.white,embedsValidationStatus:null});return e.cache.set(t,o),o}},df=e=>[8,8+e],Ul=e=>[1.5,6+e];function cf(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&&Hl(e.type)||j(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"?df(e.strokeWidth):e.strokeStyle==="dotted"?Ul(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:cf(e),stroke:e.strokeColor,preserveVertices:t||e.roughness<rf.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=li(e.backgroundColor)?void 0:e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return pn(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}`)}},_l=(e,t,n)=>Oi(e)&&(t||sa(e)&&n?.get(e.id)!==!0)&&li(e.backgroundColor)&&li(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:ki(e)?{...e,strokeColor:li(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:li(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Yl=(e,t,n,i,o,r,s)=>{let a=Ur(e,t,n,i);if(a===null)return[];let l=(d,c)=>{if(d===null)return[];let[,,u,p,m,f]=d;return[o.line(u,p,m,f,c)]};switch(i){case"dot":case"circle":case"circle_outline":{let[d,c,u]=a;return delete r.strokeLineDash,[o.circle(d,c,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[d,c,u,p,m,f]=a;return delete r.strokeLineDash,[o.polygon([[d,c],[u,p],[m,f],[d,c]],{...r,fill:i==="triangle_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[d,c,u,p,m,f,E,h]=a;return delete r.strokeLineDash,[o.polygon([[d,c],[u,p],[m,f],[E,h],[d,c]],{...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[d,c,u,p,m,f]=a;if(e.strokeStyle==="dotted"){let E=Ul(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,d,c,r),o.line(m,f,d,c,r),...i==="crowfoot_one_or_many"?l(Ur(e,t,n,"crowfoot_one"),r):[]]}}},oa=e=>{let t=new je,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=dt(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:[de(0,0)];return B(e)?t.path(Xl(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(de(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:de(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(de(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Lt(de(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Lt(de(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>de(a[0]-e.x,a[1]-e.y)).flat()}}):o.map((r,s)=>{let a=Lt(de(e.x+r[0],e.y+r[1]),i,e.angle);return{op:s===0?"move":"lineTo",data:de(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let o=jn(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(de(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:de(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(de(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Lt(de(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Lt(de(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>de(a[0]-e.x,a[1]-e.y)).flat()}})}}},uf=(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(_l(e,n,o),!0))}else r=t.rectangle(0,0,e.width,e.height,Re(_l(e,n,o),!1));return r}case"diamond":{let r,[s,a,l,d,c,u,p,m]=Bi(e);if(e.roundness){let f=yt(Math.abs(s-p),e),E=yt(Math.abs(d-a),e);r=t.path(`M ${s+f} ${a+E} L ${l-f} ${d-E}
12
- C ${l} ${d}, ${l} ${d}, ${l-f} ${d+E}
13
- L ${c+f} ${u-E}
14
- C ${c} ${u}, ${c} ${u}, ${c-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,d],[c,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:[de(0,0)];if(B(e)?a.every(l=>Math.abs(l[0])<=1e6&&Math.abs(l[1])<=1e6)?r=[t.path(Xl(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:d="arrow"}=e;if(l!==null){let c=Yl(e,r,"start",l,t,s,i);r.push(...c)}if(d!==null){let c=Yl(e,r,"end",d,t,s,i);r.push(...c)}}return r}case"freedraw":{let r;if(Nl(e),pn(e.points)){let s=jn(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 sf(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Xl=(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=tt(a,r),d=tt(s,a),c=Math.min(t,zl(e[o],s)/2,zl(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(" ")},jl=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Hs(e);case"arrow":case"line":{let n=Pe.get(e)?.[0]??Pe.generateElementShape(e,null)[0],[,,,,i,o]=_(e,t);return ji(e)?Us(e,n,de(e.x,e.y),e.angle,de(i,o)):_s(n,de(e.x,e.y),e.angle,de(i,o))}case"ellipse":return zs(e);case"freedraw":{let[,,,,n,i]=_(e,t);return Ys(e,de(n,i),ji(e))}}},rl=(e,t)=>{let n=[...e.points];if(t){if(!ua(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>lf||n.length<4?n.push(de(o[0],o[1])):n[n.length-1]=de(o[0],o[1])}return{polygon:t,points:n}};var Wr=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&&!ce(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(Me(t)){let[c,u,p,m]=Vr(t.points.map(([f,E])=>se(v(f,E),v(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,p+t.x,m+t.y]}else if(j(t))i=yf(t,l,d,n);else if(t.type==="diamond"){let[c,u]=se(v(l,r),v(l,d),t.angle),[p,m]=se(v(l,a),v(l,d),t.angle),[f,E]=se(v(o,d),v(l,d),t.angle),[h,g]=se(v(s,d),v(l,d),t.angle),x=Math.min(c,p,f,h),y=Math.min(u,m,E,g),b=Math.max(c,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(c*p,u*m),E=Math.hypot(u*p,c*m);i=[l-f,d-E,l+f,d+E]}else{let[c,u]=se(v(o,r),v(l,d),t.angle),[p,m]=se(v(o,a),v(l,d),t.angle),[f,E]=se(v(s,a),v(l,d),t.angle),[h,g]=se(v(s,r),v(l,d),t.angle),x=Math.min(c,p,f,h),y=Math.min(u,m,E,g),b=Math.max(c,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}return i}},_=(e,t,n=!1)=>{if(Me(e))return Ef(e);if(j(e))return U.getElementAbsoluteCoords(e,t,n);if(ie(e)){let i=t?Ce(e,t):null;if(Y(i)){let{x:o,y:r}=U.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]},Nr=(e,t)=>{let n=jl(e,t),[i,o,r,s,a,l]=_(e,t),d=v(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(ge(v(g[x][0],g[x][1]),v(g[x+1][0],g[x+1][1]))),x++;return y}else{if(n.type==="polyline")return n.data;if(ff(e)){let[h,g]=Pn(e),x=g.map(b=>$l(b,d,e.angle)).flat();return[...Vl(h,d,e.angle),...x]}else if(e.type==="diamond"){let[h,g]=In(e),x=g.map(b=>$l(b,d,e.angle)).flat();return[...Vl(h,d,e.angle),...x]}else if(n.type==="polygon"){if(ie(e)){let x=Ce(e,t);if(x&&j(x))return[ge(v(i,o),v(r,o)),ge(v(r,o),v(r,s)),ge(v(r,s),v(i,s)),ge(v(i,s),v(i,o))]}let h=n.data,g=[];for(let x=0;x<h.length-1;x++)g.push(ge(h[x],h[x+1]));return g}else if(n.type==="ellipse")return hf(e)}let[c,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,d,e.angle));return[ge(c,u),ge(p,m),ge(c,p),ge(u,m),ge(c,E),ge(p,E),ge(u,f),ge(m,f)]},ff=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),Vl=(e,t,n)=>e.map(i=>ge(se(i[0],t,n),se(i[1],t,n))),$l=(e,t,n)=>{let i=Et(e,10),o=0,r=[];for(;o<i.length-1;)r.push(ge(se(v(i[o][0],i[o][1]),t,n),se(v(i[o+1][0],i[o+1][1]),t,n))),o++;return r},hf=e=>{let t=v(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(se(v(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(ge(r[l],r[l+1]));return o.push(ge(r[r.length-1],r[0])),o},Y0=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]},Zl=(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},ql=(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 p=null,m=null,f=1/0,E=1/0;return a===0?f=E=-d/l:(f=(-l+Math.sqrt(c))/(2*a),E=(-l-Math.sqrt(c))/(2*a)),f>=0&&f<=1&&(p=Zl(f,e,t,n,i)),E>=0&&E<=1&&(m=Zl(E,e,t,n,i)),[p,m]},Wi=(e,t,n,i)=>{let o=ql(e[0],t[0],n[0],i[0]),r=ql(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]},ai=(e,t)=>{let n=v(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=Ql(d);jr(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=v(d[0],d[1]),u=v(d[2],d[3]),p=v(d[4],d[5]),m=t?t(c):c,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]},Vr=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]},Ef=e=>{let[t,n,i,o]=Vr(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]},gf=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}},xf=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},Ur=(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;jr(s.length===6,"Op data length is not 6");let a=v(s[4],s[5]),l=v(s[2],s[3]),d=v(s[0],s[1]),c=o[r-1],u=v(0,0);if(c.op==="move"){let H=Ql(c.data);jr(H!=null,"Op data is not a point"),u=H}else c.op==="bcurveTo"&&(u=v(c.data[4],c.data[5]));let p=(H,te)=>Math.pow(1-H,3)*a[te]+3*H*Math.pow(1-H,2)*l[te]+3*Math.pow(H,2)*(1-H)*d[te]+u[te]*Math.pow(H,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=gf(i),w=0;{let[H,te]=n==="end"?e.points[e.points.length-1]:e.points[0],[S,Q]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];w=Math.hypot(H-S,te-Q)}let M=Math.min(b,w*(i==="diamond"||i==="diamond_outline"?.25:.5)),D=m-x*M,T=f-y*M;if(i==="dot"||i==="circle"||i==="circle_outline"){let H=Math.hypot(T-f,D-m)+e.strokeWidth-2;return[m,f,H]}let N=xf(i);if(i==="crowfoot_many"||i==="crowfoot_one_or_many"){let[H,te]=se(v(m,f),v(D,T),Xr(-N)),[S,Q]=se(v(m,f),v(D,T),Xr(N));return[D,T,H,te,S,Q]}let[C,R]=se(v(D,T),v(m,f),-N*Math.PI/180),[L,V]=se(v(D,T),v(m,f),Xr(N));if(i==="diamond"||i==="diamond_outline"){let H,te;if(n==="start"){let[S,Q]=e.points.length>1?e.points[1]:[0,0];[H,te]=se(v(m+M*2,f),v(m,f),Math.atan2(Q-f,S-m))}else{let[S,Q]=e.points.length>1?e.points[e.points.length-2]:[0,0];[H,te]=se(v(m-M*2,f),v(m,f),Math.atan2(f-Q,m-S))}return[m,f,C,R,H,te,L,V]}return[m,f,C,R,L,V]},wf=e=>{let t=un.generator(),n=Re(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},yf=(e,t,n,i)=>{let o=W(e,i);if(e.points.length<2){let[u,p]=e.points[0],[m,f]=se(v(e.x+u,e.y+p),v(t,n),e.angle),E=[m,f,m,f];if(o){let h=U.getMinMaxXYWithBoundText(e,i,[m,f,m,f],o);E=[h[0],h[1],h[2],h[3]]}return E}let s=Pe.get(e)?.[0]??wf(e),a=gt(s),d=ai(a,([u,p])=>se(v(e.x+u,e.y+p),v(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=U.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},pe=(e,t,n=!1)=>Wr.getBounds(e,t,n),Xe=(e,t)=>{if(!pf(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Kl(e);return e.forEach(a=>{let[l,d,c,u]=pe(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]},U0=(e,t)=>{let[n,i,o,r]=Xe(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},Nt=(e,t,n,i)=>{if(!(j(e)||Me(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Wl(0,t,Wl(1,n,e.points,i),i),r;if(Me(e))r=Vr(o);else{let c=un.generator(),u=e.roundness?c.curve(o,Re(e)):c.linearPath(o,Re(e)),p=gt(u);r=ai(p)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Gr=(e,t)=>{let n=un.generator(),i=e.roundness==null?n.linearPath(t,Re(e)):n.curve(t,Re(e)),o=gt(i),[r,s,a,l]=ai(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},X0=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=Kl(e);return e.forEach(r=>{let[s,a,l,d]=pe(r,o),c=mf(v((s+l)/2,(a+d)/2),v(t.x,t.y));c<n&&(n=c,i=r)}),pe(i,o)},Ct=e=>{let[t,n,i,o]=Xe(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},j0=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],dt=e=>v(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),$e=(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=he(e,t),[r,s]=se(v(i.minX,i.minY),o,e.angle),[a,l]=se(v(i.maxX,i.minY),o,e.angle),[d,c]=se(v(i.maxX,i.maxY),o,e.angle),[u,p]=se(v(i.minX,i.maxY),o,e.angle),m=[Math.min(r,a,d,u),Math.min(s,l,c,p),Math.max(r,a,d,u),Math.max(s,l,c,p)];if(n){let[f,E,h,g]=n;return[m[0]-g,m[1]-f,m[2]+E,m[3]+h]}return m},An=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],En=(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},he=(e,t,n=0,i=0)=>{let[o,r]=dt(pe(e,t));return v(o+n,r+i)};var Sf=.1,ed=e=>j(e)||Me(e)?e.points.length<2||e.points.length===2&&Y(e)&&If(e.points[0],e.points[e.points.length-1],Sf):e.width===0&&e.height===0,Il=(e,t,n,i,o)=>{let[r,s,a,l]=pe(e,o),d=yo({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=yo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},J0=(e,t,n,i,o,r)=>{let[s,a,l,d]=Xe(e,o),c=yo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=yo({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},$r=(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)/Gt)*Gt;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}},sl=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Gt)*Gt;if(o){let d=Math.floor(o/Gt)*Gt;bf(a,d,d+Gt)&&(Pf(a,o)<Gt/6?l=o:Jl(a)>Jl(o)?l=d+Gt: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,p=-1/d,m=-1,f=i-p*n,E=(c*f-m*u)/(d*m-p*c),h=(u*p-f*d)/(d*m-p*c);r=E-e,s=h-t}return{width:r,height:s}},e1=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 s1=(e,t,n,i)=>{let o=po(e,n.getNonDeletedElementsMap(),i),r=Ct(e);return o.flatMap(s=>{let a=Mf(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ue(l,n,{simultaneouslyUpdated:s}),d})})},Mf=(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 yh,arrayToObject as Bt,assertNever as Cd,isDevEnv as nn,isShallowEqual as Gd,isTestEnv as on,randomInteger as Ld}from"@excalidraw/common";P();import{assertNever as Rf,COLOR_PALETTE as Ff,isDevEnv as Nf,isTestEnv as Hf,randomId as zf,Emitter as id,toIterable as kn}from"@excalidraw/common";P();import{ORIG_ID as vf,randomId as nd,randomInteger as Lf,arrayToMap as Cf,castArray as Zr,findLastIndex as di,getUpdatedTimestamp as Gf,isTestEnv as Bf}from"@excalidraw/common";P();import{arrayToMapWithIndex as Tf}from"@excalidraw/common";var Af=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]},Df=e=>{let t=Tf(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]},td=e=>Df(Af(e));var kf=(e,t,n,i)=>{let o=Kr(n);return Bf()&&Of(o,n.id),o.id=nd(),o.updated=Gf(),i&&(o.seed=Lf(),Na(o)),o.groupIds=bl(o.groupIds,e,r=>(t.has(r)||t.set(r,nd()),t.get(r))),o},y1=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=Cf(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=td(t);let p=t.slice(),m=h=>{let x=Zr(h).reduce((y,b)=>{if(i.has(b.id))return y;i.set(b.id,!0);let w=kf(n.editingGroupId,o,b,e.randomizeSeed);return i.set(w.id,!0),d.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(...Zr(g));return}p.splice(h+1,0,...Zr(g))}},E=new Set(t.filter(h=>u.has(h.id)&&Z(h)).map(h=>h.id));for(let h of t){if(i.has(h.id)||!u.has(h.id))continue;let g=Or(n,h);if(g){let x=Ae(t,g).flatMap(b=>Z(b)?[...qt(t,b.id),b]:[b]),y=di(p,b=>b.groupIds?.includes(g));f(y,m(x));continue}if(!(h.frameId&&E.has(h.frameId))){if(Z(h)){let x=h.id,y=qt(t,x),b=di(p,w=>w.frameId===x||w.id===x);f(b,m([...y,h]));continue}if(st(h)){let x=W(h,c),y=di(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(ce(h)){let x=Ce(h,c),y=di(p,b=>b.id===h.id||b.id===x?.id);x?f(y,m([x,h])):f(y,m(h));continue}f(di(p,x=>x.id===h.id),m(h))}}if(Ka(r,a,d),Sl(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:d,elementsWithDuplicates:p,origIdToDuplicateId:a}},qr=(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]=qr(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=qr(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},Kr=e=>qr(e),Of=(e,t)=>{Object.defineProperty(e,vf,{value:t,writable:!1,enumerable:!1})};var Fe={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},od=class{constructor(t){this.app=t}onDurableIncrementEmitter=new id;onStoreIncrementEmitter=new id;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=tn.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=tn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?ad(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=tn.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=es.calculate(o,t),!s.isEmpty()){let a=new Qr(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 Jr(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:Rf(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()),Hf()||Nf())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)}},bo=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Qr=class extends bo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},Jr=class extends bo{constructor(n){super("ephemeral",n);this.change=n}},es=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:zf()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?en.calculate(t.elements,n.elements):en.empty(),o=n.metadata.didAppStateChange?Jt.calculate(t.appState,n.appState):Jt.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,en.restore(i),Jt.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=en.create(n,i,o),a=Jt.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,tn.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(en.empty(),Jt.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},tn=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,rd(n)?n:On(n),i)}static empty(){return new e(new Map,_f(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of kn(t.elements))this.elements.get(i.id)||(n[i.id]=Ee(i,{isDeleted:!0}));for(let i of kn(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return F.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=On({...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=rd(t)?t:On(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=F.isRightDifferent(this.appState,t);if(!i)return;let o=dd(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 kn(this.elements))t.get(r.id)||i.set(r.id,Ee(r,{isDeleted:!0}));for(let r of kn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(we(r)&&!Ht(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=ld(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of kn(this.elements))n.set(i.id,i);for(let i of kn(t))n.set(i.id,Kr(i));return n}},sd="__observedAppState",_f=()=>({name:null,editingGroupId:null,viewBackgroundColor:Ff.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),On=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,sd,{value:!0,enumerable:!1}),t},rd=e=>!!Reflect.get(e,sd);P();P();var pd="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Fn(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)+Fn(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]+Fn(e.slice(1),null,n)}function md(e){if(e.length!==fd(e[0]))throw new Error("invalid integer part of order key: "+e)}function fd(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 ui(e){let t=fd(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function cd(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=ui(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function ud(e,t){md(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 Yf(e,t){md(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 Rn(e,t,n=pd){if(e!=null&&cd(e,n),t!=null&&cd(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=ui(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Fn("",d,n);if(l<t)return l;let c=Yf(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=ui(e),d=e.slice(l.length),c=ud(l,n);return c??l+Fn(d,null,n)}let i=ui(e),o=e.slice(i.length),r=ui(t),s=t.slice(r.length);if(i===r)return i+Fn(o,s,n);let a=ud(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+Fn(o,null,n)}function Po(e,t,n,i=pd){if(n===0)return[];if(n===1)return[Rn(e,t,i)];if(t==null){let s=Rn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Rn(s,t,i),a.push(s);return a}if(e==null){let s=Rn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Rn(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=Rn(e,t,i);return[...Po(e,r,o,i),r,...Po(r,t,n-o-1,i)]}import{arrayToMap as Io}from"@excalidraw/common";var ts=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Uf=(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(ns(d,c,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=W(p,Io(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 ts,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(`
10
+ `)=>e.reduce((i,o)=>($(o)&&i.push(o.text),i),[]).join(t),Dd=.5;var Dh=[0,1.5,8],vh=.04,Bh=16,Nn=e=>!e||mr(e)?yh.strokeColor:e,Ws=e=>!e||mr(e)?wh:e,SS=(e,t,n)=>t==="backgroundColor"&&$(e)&&pr(e,n)?n.get(e.containerId)??e:e,IS=(e,t,n,i)=>{if(ye(e))return t==="backgroundColor"?{backgroundColor:Ws(n)}:{strokeColor:Nn(n)};if(t==="strokeColor"&&$(e)&&pr(e,i)){let o=i.get(e.containerId);return{strokeColor:mr(n)?Nn(o?.strokeColor):n}}return t==="backgroundColor"?{backgroundColor:n}:{strokeColor:n}},MS=(e,t)=>{let n=kd(e),i=new Map;for(let o of e){if(!ye(o)||o.isDeleted)continue;let r=J(o,n);if(!r||r.strokeColor===o.strokeColor)continue;let s=t.get(o.id)?.strokeColor!==o.strokeColor,a=t.get(r.id)?.strokeColor!==r.strokeColor;mr(r.strokeColor)||s&&!a?i.set(r.id,Nn(o.strokeColor)):i.set(o.id,Nn(r.strokeColor))}return i.size?e.map(o=>{let r=i.get(o.id);return r===void 0?o:Me(o,{strokeColor:r})}):e},Cn=(e,t)=>(e()*2-1)*t,kn=(e,t,n)=>{let i=t.x-e.x,o=t.y-e.y,r=Math.hypot(i,o);if(!r)return e;let s=Math.min(n/r,1);return{x:e.x+i*s,y:e.y+o*s}},Ys=e=>e.roundness?Math.min(Math.min(e.width,e.height)*vh,Bh):0,Lh=(e,{offsetX:t=0,offsetY:n=0,seedOffset:i=0}={})=>{let o=Math.max(0,Math.min(2,Math.round(e.roughness))),r=Math.min(Dh[o],Math.min(e.width,e.height)*.012);if(!r)return[{x:t,y:n},{x:t+e.width,y:n},{x:t+e.width,y:n+e.height},{x:t,y:n+e.height}];let s=Nd(e.seed+i);return[{x:t+Cn(s,r),y:n+Cn(s,r)},{x:t+e.width+Cn(s,r),y:n+Cn(s,r)},{x:t+e.width+Cn(s,r),y:n+e.height+Cn(s,r)},{x:t+Cn(s,r),y:n+e.height+Cn(s,r)}]},Xs=(e,{shadow:t=!1}={})=>{let n=Lh(e,t?{offsetX:Bd,offsetY:Bd,seedOffset:1}:void 0),i=Ys(e),o=e.roughness===2?Math.floor(Nd(e.seed)()*n.length):-1;if(!i&&o===-1)return[{type:"move",point:n[0]},...n.slice(1).map(a=>({type:"line",point:a}))];let r=n.map((a,l)=>{let d=n[(l+n.length-1)%n.length],c=n[(l+1)%n.length],u=Math.min(i,Math.hypot(a.x-d.x,a.y-d.y)/2,Math.hypot(a.x-c.x,a.y-c.y)/2);if(l===o){let p=Math.min(e.width,e.height),m=Math.min(p*.18,40),h=Math.min(p*.02,5)*(t?.5:1),f={x:a.x+(l===1||l===2?-h:h),y:a.y+(l>=2?-h:h)},g=kn(a,d,m),E=kn(a,c,m);return[{type:"line",point:g},{type:"quadratic",control:kn(a,d,m/2),point:kn(f,g,u)},{type:"quadratic",control:f,point:kn(f,E,u)},{type:"quadratic",control:kn(a,c,m/2),point:E}]}return[{type:"line",point:kn(a,d,u)},{type:"quadratic",control:a,point:kn(a,c,u)}]}),s=[{type:"move",point:r[0][r[0].length-1].point}];for(let a=1;a<=r.length;a++)s.push(...r[a%r.length]);return s},js=e=>Number.isFinite(e)?Math.min(Ih,Math.max(Ph,e)):Sh,pr=(e,t)=>!!e.containerId&&ye(t.get(e.containerId)),TS=(e,t)=>pr(e,t)?e.baseFontSize??e.fontSize:e.fontSize,AS=(e,t,n)=>pr(e,n)?{baseFontSize:js(t)}:{fontSize:t},Ch=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],kh=(e,{short:t=!1,now:n=Date.now()}={})=>{if(e===null||!Number.isFinite(e))return null;let i=new Date(e);if(Number.isNaN(i.getTime()))return null;let o=`${i.getDate()} ${Ch[i.getMonth()]}`,r=i.getFullYear();return t||r===new Date(n).getFullYear()?o:`${o} ${r}`},Od=(e,t=Date.now())=>{if(e.width<Ai||e.height<Ai)return null;let n=kh(e.created,{short:e.width-ur*2<vd.minBodyWidthForYear,now:t});return n?{text:n,x:e.width-ur,y:e.height-vd.baselineFromBottom}:null},Gd=({fontSize:e,fontFamily:t})=>{let n=Math.ceil(js(e)*Th(t));return{width:Math.max(Ai,n+ur*2),height:Math.max(Ai,n+Us)}},Nh=new Map,Oh=e=>Math.max(e.width,Ai),Gh=(e,{baseFontSize:t,fontSizeMin:n,maxWidth:i,maxHeight:o,warmStart:r})=>{let s=Math.max(0,Math.ceil((t-n)/Hs)),a=h=>h>=s?n:t-h*Hs,l=new Map,d=h=>{let f=l.get(h);return f||(f=e(a(h)),l.set(h,f)),f},c=h=>{let f=d(h);return f.width<=i&&f.height<=o};if(s===0)return d(0);let u=Ah(Math.round((t-r)/Hs),0,s),p,m;if(c(u)){if(u===0||!c(u-1))return d(u);p=0,m=u-1}else{if(u===s)return d(s);p=u+1,m=s}for(;p<m;){let h=p+m>>1;c(h)?m=h:p=h+1}return d(p)},Fd=(e,t,n={})=>{let i=Oh(e),o=Math.max(n.baseHeight??(e.baseHeight||e.height),Ai),r=n.anchor??"top";if(!t)return{container:{...so(e,o,r),width:i,height:o,baseHeight:o},text:null};let s=n.originalText??t.originalText,a=js(n.baseFontSize??t.baseFontSize??t.fontSize),l=Math.min(Mh,a),d=Math.max(i-ur*2,1),c=Math.max(o-Us,0),{fontFamily:u,lineHeight:p}=t,m=y=>{let w=Ld({fontFamily:u,fontSize:y}),S=St(s,w,d);return{text:S,fontSize:y,...Ue(S,w,p)}},h=!s.trim(),f=h?{text:"",fontSize:a,...Ue("",Ld({fontFamily:u,fontSize:a}),p)}:Gh(m,{baseFontSize:a,fontSizeMin:l,maxWidth:d,maxHeight:c,warmStart:t.fontSize}),g=h?o:Math.max(o,f.height+Us),E={...so(e,g,r),width:i,height:g,baseHeight:o},{x,y:b}=ii({...e,...E},{...t,text:f.text,fontSize:f.fontSize,width:f.width,height:f.height},Nh);return{container:E,text:{text:f.text,fontSize:f.fontSize,baseFontSize:a,width:f.width,height:f.height,x,y:b,angle:e.angle}}},$s=(e,t,n,{proportional:i,fromCenter:o,flip:r=!1})=>{let s=t.get(e.id),a=ye(s)?s:e,l=J(a,t),d=l?l.baseFontSize??l.fontSize:void 0;if(r)return{baseHeight:a.baseHeight,baseFontSize:d};let c=i||n.includes("n")||n.includes("s"),u=i&&a.width?e.width/a.width:1,p=n.length===1;return{baseHeight:c?e.height:a.baseHeight,baseFontSize:d===void 0?void 0:d*u,anchor:o?"center":n.includes("n")?"bottom":i&&p&&(n==="e"||n==="w")?"center":"top"}},Ti=(e,t,{text:n,bindings:i,...o}={})=>{let r=t.getNonDeletedElementsMap(),s=n===void 0?J(e,r):n,a=Fd(e,s,o);return t.mutateElement(e,a.container),s&&a.text&&t.mutateElement(s,a.text),i!==!1&&!e.isDeleted&&Ge(e,t,i||void 0),a},Cd={container:["x","y","width","baseHeight","angle"],text:["originalText","baseFontSize","fontFamily","lineHeight","textAlign","verticalAlign"]},Fh=(e,t,n)=>{let i=n.get(e.id),o=t?n.get(t.id):null;return!i||t&&!o||!t&&i.boundElements?.some(({type:r})=>r==="text")?!0:Cd.container.some(r=>i[r]!==e[r])||!!t&&Cd.text.some(r=>o[r]!==t[r])},DS=(e,t,n)=>{if(!t.size)return e;let i=kd(e),o=new Set;for(let s of t){let a=i.get(s);if(!(!a||a.isDeleted)){if(ye(a))o.add(a.id);else if($(a)&&a.containerId){let l=i.get(a.containerId);l&&!l.isDeleted&&ye(l)&&o.add(l.id)}}}if(!o.size)return e;let r=new Map;for(let s of o){let a=i.get(s),l=J(a,i);if(n?.prevElementsMap&&!Fh(a,l,n.prevElementsMap))continue;let d=Fd(a,l),c=Me(a,d.container);if(c!==a&&r.set(s,c),l&&d.text){let u=Me(l,d.text);u!==l&&r.set(l.id,u)}}return r.size?e.map(s=>r.get(s.id)??s):e};var ao=new WeakMap,qs=(e,t)=>{let n=ao.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){ao.delete(e);return}return o.get(t)},Qs=(e,t,n)=>{let i=ao.get(e);if(!i){ao.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){ao.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function wi(e,t){let n=qs(e,0);if(n)return n;let i=Xd(e,t),o=[],r=[];for(let a=0;a<i.length;a+=1){let l=i[a],d=i[a-1]&&Uh(i[a-1].data.slice(-2));switch(l.op){case"move":continue;case"lineTo":if(!d)throw new Error("prevPoint is undefined");o.push(Le(Y(e.x+d[0],e.y+d[1]),Y(e.x+l.data[0],e.y+l.data[1])));continue;case"bcurveTo":if(!d)throw new Error("prevPoint is undefined");r.push(dn(Y(e.x+d[0],e.y+d[1]),Y(e.x+l.data[0],e.y+l.data[1]),Y(e.x+l.data[2],e.y+l.data[3]),Y(e.x+l.data[4],e.y+l.data[5])));continue;default:console.error("Unknown op type",l.op)}}let s=[o,r];return Qs(e,s,0),s}function HS(e,t){if(X(e))return e.points.slice(1).map((o,r)=>Le(Y(e.x+e.points[r][0],e.y+e.points[r][1]),Y(e.x+o[0],e.y+o[1])));let[n,i]=wi(e,t);return i.length>0?i:n}function Mn(e,t=0){let n=qs(e,t);if(n)return n;let i=e.type==="stickynote"?Ys(e):cn(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=Yh(Y(e.x,e.y),Y(e.x+e.width,e.y+e.height)),r=Le(Y(o[0][0]+i,o[0][1]),Y(o[1][0]-i,o[0][1])),s=Le(Y(o[1][0],o[0][1]+i),Y(o[1][0],o[1][1]-i)),a=Le(Y(o[0][0]+i,o[1][1]),Y(o[1][0]-i,o[1][1])),l=Le(Y(o[0][0],o[1][1]-i),Y(o[0][0],o[0][1]+i)),d=[dn(l[1],Y(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),Y(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),dn(r[1],Y(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),Y(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),dn(s[1],Y(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),Y(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),dn(a[0],Y(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),Y(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(m=>Hd(Ud(m,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],p=[[Le(c[0][c[0].length-1][3],c[1][0][0]),Le(c[1][c[1].length-1][3],c[2][0][0]),Le(c[2][c[2].length-1][3],c[3][0][0]),Le(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Qs(e,p,t),p}function Yd(e,t=0){let[n,i,o,r,s,a,l,d]=Di(e),c=e.roundness?cn(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?cn(Math.abs(r-i),e):(r-i)*.01,[p,m,h,f]=[Y(e.x+n,e.y+i),Y(e.x+o,e.y+r),Y(e.x+s,e.y+a),Y(e.x+l,e.y+d)];return[dn(Y(m[0]-c,m[1]-u),m,m,Y(m[0]-c,m[1]+u)),dn(Y(h[0]+c,h[1]-u),h,h,Y(h[0]-c,h[1]-u)),dn(Y(f[0]+c,f[1]+u),f,f,Y(f[0]+c,f[1]-u)),dn(Y(p[0]-c,p[1]+u),p,p,Y(p[0]+c,p[1]+u))]}function Tn(e,t=0){let n=qs(e,t);if(n)return n;let i=Yd(e,t),o=t>0?i.map(a=>Hd(Ud(a,t))):[[i[0]],[i[1]],[i[2]],[i[3]]],s=[[Le(o[0][o[0].length-1][3],o[1][0][0]),Le(o[1][o[1].length-1][3],o[2][0][0]),Le(o[2][o[2].length-1][3],o[3][0][0]),Le(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return Qs(e,s,t),s}var Nt=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return ln(n,i)<=_h/t}return!1},cn=(e,t)=>{if(t.roundness?.type===Ks.PROPORTIONAL_RADIUS||t.roundness?.type===Ks.LEGACY)return e*Vs;if(t.roundness?.type===Ks.ADAPTIVE_RADIUS){let n=t.roundness?.value??Rh,i=n/Vs;return e<=i?e*Vs:n}return 0},jh=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=Xh(Wd(a[1],a[0])),d=Zs(l,n);return Le(_d(a[0],d),_d(a[1],Zs(d,-1)))},o=re(e,t),r=i(eo(e)?Le(It(Y(e.x,e.y),o,e.angle),It(Y(e.x+e.width,e.y+e.height),o,e.angle)):Le(It(Y(e.x+e.width/2,e.y),o,e.angle),It(Y(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(eo(e)?Le(It(Y(e.x+e.width,e.y),o,e.angle),It(Y(e.x,e.y+e.height),o,e.angle)):Le(It(Y(e.x,e.y+e.height/2),o,e.angle),It(Y(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},$h=(e,t,n,i,o,r)=>{let{x:s,y:a,width:l,height:d,angle:c}=e,u=It(t,i,-c),p=Be(e);if(ln(i,u)<p)return;let[m,h,f,g]=Js(e,n);if(u[0]<=s+l/2&&u[1]>i[1]-r&&u[1]<i[1]+r)return{point:f,onAxis:!0};if(u[1]<=a+d/2&&u[0]>i[0]-o&&u[0]<i[0]+o)return{point:g,onAxis:!0};if(u[0]>=s+l/2&&u[1]>i[1]-r&&u[1]<i[1]+r)return{point:m,onAxis:!0};if(u[1]>=a+d/2&&u[0]>i[0]-o&&u[0]<i[0]+o)return{point:h,onAxis:!0};if(e.type==="diamond"){let E=Math.max(o,r),x=[[s+l/4,a+d/4,-1,-1],[s+3*l/4,a+d/4,1,-1],[s+l/4,a+3*d/4,-1,1],[s+3*l/4,a+3*d/4,1,1]];for(let[b,y,w,S]of x){let I=Y(b+w*p,y+S*p);if(ln(I,u)<E)return{point:It(Y(b,y),i,c),onAxis:!1}}}},Vh=(e,t,n,i)=>{let o=Js(e,n);for(let r=0;r<o.length;r++)if(ln(o[r],t)<=i&&!Ot({point:t,element:e,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))return r;return-1},Js=(e,t)=>{let n=re(e,t);return e.type==="diamond"?Yd(e).map(i=>It(Hh(i,.5),n,e.angle)):[Y(e.width,e.height/2),Y(e.width/2,e.height),Y(0,e.height/2),Y(e.width/2,0)].map(([i,o])=>It(Y(e.x+i,e.y+o),n,e.angle))},ea=(e,t,n,i)=>{let r=On(i)+t.strokeWidth/2;return $h(t,e,n,re(t,n),Rd(.05*t.width,5,r),Rd(.05*t.height,5,r))},Kh=(e,t,n,i,o)=>{if(o.elbowed)return ea(e,t,n,i)?.point;let r=On(i)+t.strokeWidth/2,s=Vh(t,e,n,r);return s===-1?void 0:Js(t,n)[s]},ta=(e,t,n,i,o,r,s=!0)=>{if(zh(e.points.length>=2,"Arrow must have at least two points"),s){let E=Kh(t,n,o,r,e);if(E)return E}if(e.width<3&&e.height<3)return null;let[a,l]=jh(n,o),d=R.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o);if(e.points.length===2){let E=i==="start"?e.endBinding:e.startBinding,x=E&&o.get(E.elementId),b=E&&x&&_e($e(E.fixedPoint),x,o);b&&(d=b)}let c=Wh(Zs(Wd(t,d),2*ln(d,t)+Math.max(ln(a[0],a[1]),ln(l[0],l[1]))),d),u=Le(c,d),p=zd(a,u),m=zd(l,u),h=p&&ln(d,p),f=m&&ln(d,m),g=null;return h!=null&&f!=null?g=h<f?p:m:g=p||m||null,g&&Je(g,n,o)?g:null};M();var oi=e=>e==="rectangle"||e==="stickynote"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw"||e==="autoshape"||e==="bucketfill",YS=e=>oi(e)&&e!=="stickynote",XS=e=>e==="rectangle"||e==="stickynote"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable"||e==="autoshape",jS=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="autoshape",Zh=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line"||e==="autoshape",$S=e=>Zh(e)||e==="stickynote",VS=e=>e==="freedraw",jd=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="stickynote"||e==="image",KS=e=>e==="arrow",ZS=e=>e==="arrow";var gr=e=>{if(e.type==="arrow")return!1;let t=oi(e.type)&&!Qd(e.backgroundColor)||Wt(e)||jo(e)||$(e);return e.type==="line"?t&&Nt(e.points):e.type==="freedraw"?t&&Nt(e.points):t||Ne(e)},na=null,$d=null,ia=1/0,oa=!1,Vd=!1,Kd=null,rg=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,Ot=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(!ge(t)&&na&&tc(e,na)&&(oa?ia<=n:ia>=n)&&r===Vd&&rg(o,Kd)){let u=$d?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return oa}let s=o?ra(Te(o.x-n,o.y-n),e,Te(o.x+o.width+n,o.y+o.height+n)):!1,a=ae(t,i,!0);if(!nc(e,a,t.angle,he(t)?n+ac(t):n)&&!s)return!1;$(t)&&(t=_s(t,i));let c=(r||gr(t))&&Je(e,t,i)||qd(e,t,i,n)||s;return na=e,$d=new WeakRef(t),ia=n,Vd=r,Kd=o,oa=c,c},nc=(e,t,n,i=0)=>{let o=n===0?e:mt(e,nn(t),-n);return ra(Te(t[0]-i,t[1]-i),o,Te(t[2]+i,t[3]+i))},sg=(e,t,n,i=0)=>{let o=ae(t,n,!0);return nc(e,o,t.angle,i)},uI=(e,t)=>!Ot(e)&&!ag(e.point,e.element,t)&&sg(e.point,e.element,t),ag=(e,t,n)=>{let i=J(t,n);if(!i)return!1;let o=_s(i,n);return Je(e,o,n)},lg=(e,t,n)=>{if(!e.frameId)return!1;let i=n.get(e.frameId);return!!i&&Q(i)&&!Xt(t,ae(i,n))},dg=(e,t,n,i=0)=>{let[o,r]=t,s=Math.max(1,i),a=[o-s,r-s,o+s,r+s],l=ae(e,n);if(!yt(a,l)||lg(e,t,n))return-1/0;let d=Je(t,e,n);if(d&&Q(e))return-1/0;let c=tn(e,n,t);return d?c:c>i?-1/0:-c},Zd=e=>Ne(e)||oi(e.type)&&!Qd(e.backgroundColor),ic=(e,t,n,i)=>{let o=On(i),r=[],s=null;for(let a=t.length-1;a>=0;--a){let l=t[a];if(qh(!l.isDeleted,"Elements passed to binding hit tests should not contain deleted elements"),s&&l.frameId!==s||!Pe(l))continue;Q(l)&&Zd(l)&&Je(e,l,n)&&(s=l.id);let d=dg(l,e,n,o);if(d>-o&&(l.locked||r.push({element:l,distance:d}),d>=0&&Zd(l)))break}return r},sa=(e,t,n,i)=>ic(e,t,n,i).map(({element:o})=>o),rn=(e,t,n,i)=>{let o=ic(e,t,n,i);if(o.length===0)return null;if(o.length===1)return o[0].element;let r=o.sort((m,h)=>Math.abs(m.distance)-Math.abs(h.distance)),s=r[0],[a,l,d,c]=ae(s.element,n),u=Math.max(1e-5,Math.abs(d-a)*Math.abs(c-l)),p=r.filter(m=>m.element!==s.element&&m.distance>=0).map(m=>{let[h,f,g,E]=ae(m.element,n),x=Math.max(0,Math.min(g,d)-Math.max(h,a)),b=Math.max(0,Math.min(E,c)-Math.max(f,l)),y=Math.max(1e-5,Math.abs(g-h)*Math.abs(E-f));return{...m,overlapPercent:b*x/y,relativeArea:y/u}}).filter(m=>m.overlapPercent>.25&&m.relativeArea<.75);return s.distance>=0&&p.length>0?p[0].element:s.element},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=ae(e,t);if(!yt(r,s))return[];switch(e.type){case"rectangle":case"stickynote":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return ug(e,t,n,i,o);case"diamond":return mg(e,t,n,i,o);case"ellipse":return pg(e,t,n,i);case"line":case"freedraw":case"arrow":return cg(e,n,t,o)}},fr=1e-6,oc=(e,t,n,i,o,r=!1)=>{let s=[Math.min(t[0][0],t[1][0])-fr,Math.min(t[0][1],t[1][1])-fr,Math.max(t[0][0],t[1][0])+fr,Math.max(t[0][1],t[1][1])+fr];for(let a of e){let l=Er(a[0],a[1],a[2],a[3]);if(!yt(l,s))continue;let d=Jd(a,t);if(d.length>0){for(let c of d)n.push(mt(c,i,o));if(r)return n}}return n},rc=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=ec(s,t);if(a&&(n.push(mt(a,i,o)),r))return n}return n},cg=(e,t,n,i=!1)=>{let[o,r]=wi(e,n),s=[];for(let a of o){let l=ec(a,t);if(l&&(s.push(l),i))return s}for(let a of r){let l=Er(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(!yt(l,d))continue;let c=Jd(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),i))return s}return s},ug=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=mt(n[0],r,-e.angle),a=mt(n[1],r,-e.angle),l=hr(s,a),[d,c]=Mn(e,i),u=[];return rc(d,l,u,r,e.angle,o),o&&u.length>0||oc(c,l,u,r,e.angle,o),u},mg=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=mt(n[0],r,-e.angle),a=mt(n[1],r,-e.angle),l=hr(s,a),[d,c]=Tn(e,i),u=[];return rc(d,l,u,r,e.angle,o),o&&u.length>0||oc(c,l,u,r,e.angle,o),u},pg=(e,t,n,i=0)=>{let o=re(e,t),r=mt(n[0],o,-e.angle),s=mt(n[1],o,-e.angle);return og(ig(o,e.width/2+i,e.height/2+i),hr(r,s)).map(a=>mt(a,o,e.angle))},qd=(e,t,n,i=1)=>tn(t,n,e)<=i,Je=(e,t,n)=>{if((ee(t)||he(t))&&!Nt(t.points))return!1;if(he(t)){let[u,p,m,h]=ae(t,n,!0),[f,g]=mt(e,Te((u+m)/2,(p+h)/2),-t.angle);return Jh(Te(f-t.x,g-t.y),sc(t))}let[i,o,r,s]=ae(t,n);if(!ra(Te(i,o),e,Te(r,s)))return!1;let a=Te((i+r)/2,(o+s)/2),l=Qh(ng(tg(eg(e,a,.1)),Math.max(t.width,t.height)*2),a),d=hr(e,l);return pt(t,n,d).filter((u,p,m)=>m.findIndex(h=>tc(h,u))===p).length%2===1},aa=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:p}=s,m=re(s,n);if(s.type==="diamond"){let[f,g,E,x,b,y,w,S]=Di(s);return[Te(l+f,d+g-a),Te(l+E+a,d+x),Te(l+b,d+y+a),Te(l+w-a,d+S)].map(A=>mt(A,m,p))}if(s.type==="ellipse"){let f=l+c/2,g=d+u/2,E=c/2,x=u/2;return[Te(f,g-x-a),Te(f+E+a,g),Te(f,g+x+a),Te(f-E-a,g)].map(y=>mt(y,m,p))}return[Te(l-a,d-a),Te(l+c+a,d-a),Te(l+c+a,d+u+a),Te(l-a,d+u+a)].map(f=>mt(f,m,p))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Je(s,t,n))};var Bn=5,bg=10,po=10/1.5,br=1,Be=e=>Bn+e.strokeWidth/2,On=e=>{let t=Math.max(Bn,15),n=e?.value&&e.value<1?e.value:1;return hc(t/(n*1.5),t,t*2)},jt=e=>e.isBindingEnabled,yg=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=ca(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0}),d=r.isMidpointSnappingEnabled&&!s?.angleLocked&&!r.gridModeEnabled;if(lc(e,a,"start",o,r.zoom,r.isBindingEnabled,d),lc(e,l,"end",o,r.zoom,r.isBindingEnabled,d),a.focusPoint||l.focusPoint){let c=new Map;a.focusPoint&&c.set(0,{point:Gt(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&c.set(e.points.length-1,{point:Gt(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),R.movePoints(e,o,c)}return{start:a,end:l}},lc=(e,{mode:t,element:n,focusPoint:i},o,r,s,a=!0,l=!0)=>{t===null?Ke(e,o,r):t!==void 0&&$t(e,n,t,o,r,s,i,a,l)},gc=(e,t,n,i,o)=>{un(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;un(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=R.getPointGlobalCoordinates(e,a,n),d=rn(l,i,n,o),c=d?{element:d,mode:"orbit",focusPoint:R.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},wg=(e,t,n,i,o,r,s,a,l,d,c)=>{let u={mode:void 0},p={mode:void 0},m=e.points.length>2,h=R.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),f=rn(h,i,n,l.zoom);if(o)return f?u={element:f,mode:"inside",focusPoint:h}:u={mode:null},{start:u,end:p};if(r){let g=l?.selectedLinearElement?.initialState.origin;if(f&&e.startBinding?.elementId===f.id){let E=ue(f.x+f.width/2,f.y+f.height/2);return{start:m?{mode:void 0}:{mode:"inside",element:f,focusPoint:g??E},end:m?{mode:"orbit",element:f,focusPoint:h}:{mode:"inside",element:f,focusPoint:h}}}if(f&&e.startBinding){let E=e.startBinding;if(sa(h,i,n,l.zoom).find(b=>b.id===E.elementId)){let b=n.get(e.startBinding.elementId);return un(b,"Other element must be in the elements map"),{start:m?{mode:void 0}:{mode:b.id!==f.id?"orbit":"inside",element:b,focusPoint:g??ue(e.x,e.y)},end:{mode:"orbit",element:f,focusPoint:h}}}}if(e.startBinding&&e.startBinding.elementId!==f?.id){let E=n.get(e.startBinding.elementId);un(E,"Other element must be in the elements map");let b={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:E,focusPoint:c?re(E,n):g??ue(e.x,e.y)},y=f&&aa(E,f,n),w;if(f){let S=d==="inside"||d==="skip";w={mode:S&&!y?"inside":"orbit",element:f,focusPoint:h}}else w={mode:null};return{start:m?{mode:void 0}:b,end:w}}if(!e.startBinding)return f?p={mode:d==="inside"||d==="skip"?"inside":"orbit",element:f,focusPoint:h}:p={mode:null},{start:u,end:p}}un(!1,"New arrow creation should not reach here")},dc=(e,t,n,i,o,r,s,a,l)=>{let d={mode:void 0},c={mode:void 0},u=s.points.length>2,p=rn(e,o,i,a),m=n?sa(e,o,i,a).some(E=>E.id===n.elementId):!1,h=n?i.get(n.elementId):null,f=m&&h?hg(h.backgroundColor):!1,g=p&&h&&aa(h,p,i);return r==="inside"||r==="skip"?(d=p?{element:!m||!h||f?p:h,focusPoint:e,mode:"inside"}:{mode:null},c=l&&p&&p.id===n?.elementId?{mode:null}:c,{current:d,other:c}):p?p.id===t?.elementId&&t.mode==="inside"?{current:{mode:"inside",focusPoint:e,element:p},other:c}:n?n.elementId===p.id?n.mode==="orbit"?(d={element:p,mode:"orbit",focusPoint:e},c={mode:l?null:void 0},{current:d,other:u?{mode:void 0}:c}):(d={element:p,mode:"inside",focusPoint:e},{current:d,other:u?{mode:void 0}:c}):(m&&h&&!f?d={element:h,mode:"inside",focusPoint:e}:d={element:p,mode:"orbit",focusPoint:e},{current:d,other:u?{mode:void 0}:c}):(d={element:p,mode:"orbit",focusPoint:e},{current:d,other:u?{mode:void 0}:c}):{current:{mode:null},other:c}},ca=(e,t,n,i,o,r,s,a)=>fg("COMPLEX_BINDINGS")?Pg(e,t,o,r,s,a):Ec(e,t,n,i,o,r,s,a),Ec=(e,t,n,i,o,r,s,a)=>{let d=e.points.length-1,c=t.has(0),u=t.has(d),p={mode:void 0},m={mode:void 0};if(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!c&&!u)return{start:p,end:m};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!jt(s))return p=c?{mode:null}:p,m=u?{mode:null}:m,{start:p,end:m};if(X(e))return gc(e,t,o,r,s.zoom);let h=c?e.endBinding:e.startBinding,f=t.get(c?0:d)?.point;un(f,`Local point must be defined for ${c?"start":"end"} dragging`);let g=R.getPointGlobalCoordinates(e,f,o),E=rn(a?.angleLocked||s.gridModeEnabled?ue(n,i):g,r,o,s.zoom),x=E&&(a?.angleLocked?Je(ue(n,i),E,o):Je(g,E,o)),b=h?o.get(h.elementId):void 0,y=h&&b&&_e(h.fixedPoint,b,o),w=b&&y&&Ot({point:y,element:b,elementsMap:o,threshold:0,overrideShouldTestInside:!0}),S=s.selectedLinearElement?.initialState.arrowOtherEndpointInitialBinding;if(h&&h.elementId===E?.id&&(!a?.newArrow||s.selectedLinearElement?.initialState.origin))return{start:{mode:"inside",element:E,focusPoint:c?g:a?.newArrow?Eg(la(s.selectedLinearElement.initialState.origin[0],s.selectedLinearElement.initialState.origin[1],a.gridSize)):b?_e(h.fixedPoint,b,o):R.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:E,focusPoint:u?g:b?_e(h.fixedPoint,b,o):R.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?E?{mode:"inside",element:E,focusPoint:g}:{mode:null}:p,end:u?E?{mode:"inside",element:E,focusPoint:g}:{mode:null}:m};let I=E?x?{mode:"inside",element:E,focusPoint:g}:{mode:"orbit",element:E,focusPoint:ta(e,a?.angleLocked?g:s.gridModeEnabled?Ag(ue(n,i),E,o,s.gridSize,e,R.getPointAtIndexGlobalCoordinates(e,c?1:-2,o)):g,E,c?"start":"end",o,s.zoom,s.isMidpointSnappingEnabled&&!a?.angleLocked&&!s.gridModeEnabled)||g}:{mode:null},A=R.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),T=y&&b&&Ot({point:g,element:b,elementsMap:o,threshold:On(s.zoom),overrideShouldTestInside:!0}),O=S?.mode==="inside",v=a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:h?.mode==="inside"&&O,N={mode:void 0};return v||(h?.mode==="inside"&&!O&&b&&!a?.newArrow?N={mode:"orbit",element:b,focusPoint:y||A}:b&&!w&&!T&&s.selectedLinearElement?.initialState.altFocusPoint?N={mode:"orbit",element:b,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&b&&(N={mode:"orbit",element:b,focusPoint:ta(e,A,b,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||A})),{start:c?I:N,end:u?I:N}},Pg=(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},p={mode:void 0};if(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!d&&!c)return{start:u,end:p};if(d&&c)return{start:{mode:null},end:{mode:null}};if(!jt(o))return u=d?{mode:null}:u,p=c?{mode:null}:p,{start:u,end:p};if(X(e))return gc(e,t,n,i,o.zoom);if(r?.newArrow){let{start:m,end:h}=wg(e,t,n,i,d,c,a,l,o,s,r?.shiftKey);return{start:m,end:h}}if(d){let m=t.get(a)?.point;un(m,"Local point must be defined for start dragging");let h=R.getPointGlobalCoordinates(e,m,n),{current:f,other:g}=dc(h,e.startBinding,e.endBinding,n,i,s,e,o.zoom,r?.finalize);return{start:f,end:g}}if(c){let m=t.get(l)?.point;un(m,"Local point must be defined for end dragging");let h=R.getPointGlobalCoordinates(e,m,n),{current:f,other:g}=dc(h,e.endBinding,e.startBinding,n,i,s,e,o.zoom,r?.finalize);return{start:g,end:f}}return{start:u,end:p}},DI=(e,t,n)=>{e.forEach(i=>{yg(i,new Map,1/0,1/0,t,n)})},xc=(e,t,n,i,o)=>{o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:n}),fc(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},$t=(e,t,n,i,o,r,s,a=!0,l=!0)=>{let d=o.getNonDeletedElementsMap(),c;X(e)?c={elementId:t.id,mode:"orbit",...bc(e,t,i,d,r,a,l)}:c={elementId:t.id,mode:n,...si(e,t,i,d,s)},xc(e,t,c,i,o)},Ke=(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},vI=(e,t,n)=>{let i=t.getNonDeletedElementsMap(),o=re(e,i),r=Math.max(e.width,e.height)*2;mo(i,e,s=>{if(!W(s)||!je(s))return;let a={};for(let l of["startBinding","endBinding"]){let d=s[l];if(d?.elementId!==e.id)continue;let c=l==="startBinding"?"start":"end";if(X(s)){a[l]={...d,...bc(s,e,c,i,n)};continue}let u=_e(d.fixedPoint,e,i);if(Ot({element:e,point:u,elementsMap:i,threshold:Be(e),overrideShouldTestInside:!0}))continue;let p=Gn(u,o);if(p[0]===0&&p[1]===0)continue;let m=pt(e,i,ri(o,lo(co(xr(p),r),o))).sort((h,f)=>tt(h,u)-tt(f,u))[0];m&&(a[l]={...d,...si(s,e,c,i,m)})}(a.startBinding||a.endBinding)&&He(s,i,a)})},Ge=(e,t,n)=>{if(!Pe(e))return;let{simultaneouslyUpdated:i}=n??{},o=ua(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),mo(r,e,a=>{if(a&&!je(a)&&console.error("[NONDELETED][INVARIANT] updateBoundElements(): `isDeleted: true` in visitor"),!W(a)||!je(a)||!Sg(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=yr(r,a,(p,m)=>{if(p&&Pe(p)&&(m==="startBinding"||m==="endBinding")&&(e.id===a[m]?.elementId||e.id===a[m==="startBinding"?"endBinding":"startBinding"]?.elementId)){let h=Gt(a,m,a[m],p,r);if(h)return[m==="startBinding"?0:a.points.length-1,{point:h}]}return null}).filter(p=>p!==null);R.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=J(a,r);u&&!u.isDeleted&&ni(a,t,!1)})},cc=(e,t,n,i,o)=>{un(!X(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=R.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&Ot({element:s,point:a,elementsMap:n,threshold:On(o.zoom)}),d=t==="startBinding"?"start":"end";if(Ke(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],p=Ec(e,new Map([[c,{point:u}]]),a[0],a[1],n,i.getNonDeletedElements(),o);p[d]&&p[d].element?.id===s.id&&p[d].mode&&$t(e,s,p[d].mode,d,i,o.zoom,p[d].focusPoint)}},BI=(e,t,n,i)=>{if(W(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&cc(e,"startBinding",o,t,n),e.endBinding&&cc(e,"endBinding",o,t,n)}else Ge(e,t,{...i,changedElements:new Map([[e.id,e]])})},Sg=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,uc=new WeakMap,ua=e=>{if(!e)return new Set;let t=uc.get(e);return t||(t=new Set(e.map(n=>n.id)),uc.set(e,t)),t},bd=(e,t,n,i,o,r,s)=>{let a=Bt(Gn(t,e));return!n||!i?a:Ig(o,n,r,s)?Pi(n,i,e):Bt(Gn(e,re(n,r)))},Ig=(e,t,n,i)=>{let o=tn(t,n,e),r=On(i);return o>r?null:o},As=(e,t,n,i,o,r,s=!0)=>{let a=X(e),l=R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return l;let d=rd(t)&&a?Mg(e,t,i,l):l,c=r&&!a?r[1]:R.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),u=Be(t),p=ut(t,i),m=nn(p),h=null;if(a){let f=s?ea(d,t,i,o):void 0,g=f?.point??l,E=ct(f?.onAxis?Bt(Gn(f.point,m)):Pi(t,p,l)),x=ue(E?m[0]:g[0],E?g[1]:m[1]),b=r??ri(x,lo(co(xr(Gn(g,x)),Math.max(t.width,t.height)*2),x)),y=(w,S)=>tt(w,g)-tt(S,g);if(h=pt(t,i,b,u).sort(y)[0],!h){let w=ue(E?g[0]:m[0],E?m[1]:g[1]),S=ri(w,lo(co(xr(Gn(g,w)),Math.max(t.width,t.height)*2),w));h=pt(t,i,S,Bn).sort(y)[0]}}else{let f=r;if(!f){let g=co(xr(Gn(d,c)),da(d,c)+Math.max(t.width,t.height)+u*2);f=r??ri(lo(g,c),lo(co(g,-1),c))}h=da(d,c)<1?d:pt(t,i,f,u).sort((g,E)=>tt(g,c)-tt(E,c))[0]}return!h||tt(d,h)<gg?d:h},Mg=(e,t,n,i)=>{let o=re(t,n),r=et(i,o,-t.angle),s=Be(t);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?et(ue(t.x-s,t.y),o,t.angle):et(ue(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?et(ue(t.x,t.y+t.height+s),o,t.angle):et(ue(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?et(ue(t.x+t.width,t.y+t.height+s),o,t.angle):et(ue(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?et(ue(t.x+t.width,t.y-s),o,t.angle):et(ue(t.x+t.width+s,t.y),o,t.angle):i},Tg=(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:_e($e(i.fixedPoint),o,n),binding:i,mode:i.mode}},Ag=(e,t,n,i,o,r)=>{if(!i)return e;let s=ut(t,n),a=r&&(t.type==="ellipse"||t.type==="diamond")?Bt(Gn(r,e)):Pi(t,s,e),l=Be(t),d=Math.max(t.width,t.height)+l*2,c=nn(s),u=Math.abs(a[0]),p=Math.abs(a[1]);if(u>=p){let[,g]=la(e[0],e[1],i),E=ri(ue(c[0]-d,g),ue(c[0]+d,g));return pt(t,n,E,l).sort((b,y)=>tt(b,e)-tt(y,e))[0]??ue(e[0],g)}let[m]=la(e[0],e[1],i),h=ri(ue(m,c[1]-d),ue(m,c[1]+d));return pt(t,n,h,l).sort((g,E)=>tt(g,e)-tt(E,e))[0]??ue(m,e[1])},mc=e=>e.width*e.height,Gt=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||xg(e.points[e.points.length-1],ue(0,0)))return null;let s=_e($e(n.fixedPoint),i,o);if(n.mode==="inside")return R.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=Tg(e,t==="startBinding"?"endBinding":"startBinding",o),d=R.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&ri(s,c),p=a&&u&&pt(a,o,u,Be(a)).sort((b,y)=>tt(b,s)-tt(y,s))[0],m=u&&pt(i,o,u,Be(i)).sort((b,y)=>tt(b,c)-tt(y,c))[0],h=e.startArrowhead!==null,f=e.endArrowhead!==null,g=!h&&!f||t==="startBinding"&&h||t==="endBinding"&&f?s:m||s;if(a&&m&&!r&&mc(a)<mc(i)*2&&Ot({element:a,point:m,elementsMap:o,threshold:Be(a),overrideShouldTestInside:!0}))return R.createPointAt(e,o,g[0],g[1],null);let x=da(a&&(p||l)||d,m||s)<=bg;return a?x?R.createPointAt(e,o,g?.[0]||s[0],g?.[1]||s[1],null):R.createPointAt(e,o,m?.[0]||s[0],m?.[1]||s[1],null):R.createPointAt(e,o,x?s[0]:m?.[0]??s[0],x?s[1]:m?.[1]??s[1],null)},bc=(e,t,n,i,o,r=!0,s=!0)=>{let a=[t.x,t.y,t.x+t.width,t.y+t.height],l=r?As(e,t,n,i,o,void 0,s):R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),d=ue(a[0]+(a[2]-a[0])/2,a[1]+(a[3]-a[1])/2),c=et(l,d,-t.angle);if(t.width<br||t.height<br)return{fixedPoint:$e([.5,.5])};let u=Be(t);return{fixedPoint:$e([(c[0]-t.x)/Math.max(t.width,u),(c[1]-t.y)/Math.max(t.height,u)])}},si=(e,t,n,i,o)=>{let r=o||R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=re(t,i),a=et(r,s,-t.angle);if(t.width<br||t.height<br)return{fixedPoint:$e([.5,.5])};let l=Be(t),d=(a[0]-t.x)/Math.max(t.width,l),c=(a[1]-t.y)/Math.max(t.height,l);return{fixedPoint:$e([d,c])}},yc=(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})}X(i)&&Object.assign(i,Ii(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},LI=(e,t)=>{let n=fc(e);for(let i of t)Fn.unbindAffected(n,i,(o,r)=>He(o,n,r)),Rn.unbindAffected(n,i,(o,r)=>He(o,n,r))},uo=(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},wc=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),mo=(e,t,n)=>{Pe(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},yr=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(ge(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(W(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},Fn=class{static unbindAffected(t,n,i){n&&yr(t,n,o=>{!o||o.isDeleted||mo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:uo(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||yr(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(W(n)&&i(o,{boundElements:uo(o.boundElements,new Set,new Array(n))}),$(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:uo(o.boundElements,new Set,new Array(n))}))))})}},Rn=class{static unbindAffected(t,n,i){n&&mo(t,n,o=>{!o||o.isDeleted||yr(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||mo(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:uo(n.boundElements,new Set([s]))});return}$(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:uo(n.boundElements,new Set([o.id]))})))})}},_e=(e,t,n)=>{let[i,o]=$e(e);return et(ue(t.x+t.width*i,t.y+t.height*o),re(t,n),t.angle)},Dg=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?_e(e.startBinding.fixedPoint,n,t):ue(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?_e(e.endBinding.fixedPoint,i,t):ue(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},Pc=(e,t)=>{let[n,i]=Dg(e,t);return[R.pointFromAbsoluteCoords(e,n,t),R.pointFromAbsoluteCoords(e,i,t)]},vg=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),pc=10,$e=e=>{if(!vg(e))return[.5001,.5001];let t=1e-4,n=e.map(i=>hc(i,-pc,pc));return Math.abs(n[0]-.5)<t||Math.abs(n[1]-.5)<t?n.map(i=>Math.abs(i-.5)<t?.5001:i):n},Bg=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",Lg={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"}]},Cg=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}}),kg=(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=Lg[t],d=Cg(l);for(let p of d)if(p.start<=p.end){if(a>=p.start&&a<=p.end)return p.side}else if(a>=p.start||a<=p.end)return p.side;let c=1/0,u=l[0].side;for(let p of l){let m=Math.abs(a-p.centerAngle);m>180&&(m=360-m),m<c&&(c=m,u=p.side)}return u},CI=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!Pe(n))return null;let i=re(n,t),o=Bg(n),r=kg($e(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=Tn(n),[d,c,u,p]=a,m,h;switch(r){case"left":{if(l.length>=3){let g=l[2][1];m=g[0]-s,h=g[1]}else{let f=Ve(c[1],u[0]);m=f[0]-s,h=f[1]}break}case"right":{if(l.length>=1){let g=l[0][1];m=g[0]+s,h=g[1]}else{let f=Ve(p[1],d[0]);m=f[0]+s,h=f[1]}break}case"top":{if(l.length>=4){let g=l[3][1];m=g[0],h=g[1]-s}else{let f=Ve(u[1],p[0]);m=f[0],h=f[1]-s}break}case"bottom":{if(l.length>=2){let g=l[1][1];m=g[0],h=g[1]+s}else{let f=Ve(d[1],c[0]);m=f[0],h=f[1]+s}break}case"top-right":{let f=Ve(p[0],p[1]);m=f[0]+s*.707,h=f[1]-s*.707;break}case"bottom-right":{let f=Ve(d[0],d[1]);m=f[0]+s*.707,h=f[1]+s*.707;break}case"bottom-left":{let f=Ve(c[0],c[1]);m=f[0]-s*.707,h=f[1]+s*.707;break}case"top-left":{let f=Ve(u[0],u[1]);m=f[0]-s*.707,h=f[1]-s*.707;break}default:return null}return et(ue(m,h),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,p;switch(r){case"top":{u=a,p=l-c-s;break}case"right":{u=a+d+s,p=l;break}case"bottom":{u=a,p=l+c+s;break}case"left":{u=a-d-s,p=l;break}case"top-right":{let m=-Math.PI/4,h=d*Math.cos(m),f=c*Math.sin(m);u=a+h+s*.707,p=l+f-s*.707;break}case"bottom-right":{let m=Math.PI/4,h=d*Math.cos(m),f=c*Math.sin(m);u=a+h+s*.707,p=l+f+s*.707;break}case"bottom-left":{let m=3*Math.PI/4,h=d*Math.cos(m),f=c*Math.sin(m);u=a+h-s*.707,p=l+f+s*.707;break}case"top-left":{let m=-3*Math.PI/4,h=d*Math.cos(m),f=c*Math.sin(m);u=a+h-s*.707,p=l+f-s*.707;break}default:return null}return et(ue(u,p),i,n.angle)}if(eo(n)){let[a,l]=Mn(n),[d,c,u,p]=a,m,h;switch(r){case"top":{let f=Ve(d[0],d[1]);m=f[0],h=f[1]-s;break}case"right":{let f=Ve(c[0],c[1]);m=f[0]+s,h=f[1];break}case"bottom":{let f=Ve(u[0],u[1]);m=f[0],h=f[1]+s;break}case"left":{let f=Ve(p[0],p[1]);m=f[0]-s,h=f[1];break}case"top-left":{if(l.length>=1){let f=l[0],g=f[0],E=f[3],x=Ve(g,E);m=x[0]-s*.707,h=x[1]-s*.707}else m=n.x-s,h=n.y-s;break}case"top-right":{if(l.length>=2){let f=l[1],g=f[0],E=f[3],x=Ve(g,E);m=x[0]+s*.707,h=x[1]-s*.707}else m=n.x+n.width+s,h=n.y-s;break}case"bottom-right":{if(l.length>=3){let f=l[2],g=f[0],E=f[3],x=Ve(g,E);m=x[0]+s*.707,h=x[1]+s*.707}else m=n.x+n.width+s,h=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let f=l[3],g=f[0],E=f[3],x=Ve(g,E);m=x[0]-s*.707,h=x[1]+s*.707}else m=n.x-s,h=n.y+n.height+s;break}default:return null}return et(ue(m,h),i,n.angle)}return null},Ve=(e,t)=>ue((e[0]+t[0])/2,(e[1]+t[1])/2),kI=(e,t,n,i,o)=>{xc(e,t,{elementId:t.id,fixedPoint:$e(i),mode:"orbit"},n,o)};var fa=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>H(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},vc=new WeakMap,R=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,Ic(t.points[0],H(0,0))||(console.error("Linear element is not normalized",Error().stack),He(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,arrowOtherEndpointInitialBinding:null,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=X(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,p]=q(n.selectionElement,o),h=e.getPointsGlobalCoordinates(l,o).reduce((f,g,E)=>((g[0]>=d&&g[0]<=u&&g[1]>=c&&g[1]<=p||t.shiftKey&&s?.includes(E))&&f.push(E),f),[]).filter(f=>!(X(l)&&f!==0&&f!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:h.length?h: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);ft(d,"Element being dragged must exist in the scene"),ft(d.points.length>1,"Element must have at least 2 points");let c=d.points.length-1,u=d.points[c],p=d.points[c-1],m=r.customLineAngle??Lc(p,d.points[c]),h=0,f=0;if(li(t)){let[I,A]=e._getShiftLockedDelta(d,s,p,H(i,o),t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),m),T=H(I+p[0],A+p[1]);h=T[0]-u[0],f=T[1]-u[1]}else{let I=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize());h=I[0]-u[0],f=I[1]-u[1]}let g=null,{positions:E,updates:x,hit:b}=Bc([c],h,f,i,o,s,d,a,n,li(t),t.altKey,r),y=li(t);if(e.movePoints(d,n.scene,E,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!y&&!n.state.gridModeEnabled}),Xe(d,!1)&&jt(n.state)&&(g=x?.suggestedBinding??null),Xe(d)&&b&&Ac(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene,b),n.state.selectedLinearElement?.customLineAngle===m&&r.initialState.altFocusPoint&&(!g||_g(n.state.suggestedBinding??[],g)))return null;let w=Xe(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:m,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&w&&x?.suggestedBinding?.element.id!==w.id?Dc(d,H(d.x,d.y),w,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!y&&!n.state.gridModeEnabled):r.initialState.altFocusPoint}},suggestedBinding:g}}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:p}=c,m=e.getElement(d,s);ft(m,"Element being dragged must exist in the scene"),ft(m.points.length>1,"Element must have at least 2 points"),ft(u,"There must be selected points in order to drag them"),l&&u.some((C,_)=>C>0&&C!==m.points.length-1?(u[_]=m.points.length-1,p=m.points.length-1,!0):!1),(p<0||!u.includes(p)||!m.points[p])&&(console.error(`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${m.points.length-1}) lastClickedPoint(${p}) isElbowArrow: ${l}`),p=m.points.length-1);let h=m.points[p],f=m.points[p===0?1:p-1],g=u.length===1,E=r.customLineAngle??Lc(f,m.points[p]),x=u.includes(0),b=u.includes(m.points.length-1),y=0,w=0;if(li(t)&&g){let[C,_]=e._getShiftLockedDelta(m,s,f,H(i,o),t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),E),K=H(C+f[0],_+f[1]);y=K[0]-h[0],w=K[1]-h[1]}else{let C=e.createPointAt(m,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=C[0]-h[0],w=C[1]-h[1]}let S=null,{positions:I,updates:A,hit:T}=Bc(u,y,w,i,o,s,m,a,n,li(t)&&g,t.altKey,r),O=li(t)&&g;e.movePoints(m,n.scene,I,{startBinding:A?.startBinding,endBinding:A?.endBinding,moveMidPointsWithElement:A?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!O&&!n.state.gridModeEnabled}),Xe(m,!1)&&jt(n.state)&&(x||b)&&(S=A?.suggestedBinding??null),Xe(m)&&x!==b&&T&&Ac(e.getPointGlobalCoordinates(m,x?m.points[0]:m.points[m.points.length-1],s),m,a,s,n.scene,T),J(m,s)&&ni(m,n.scene,!1);let N=l?b?[m.points.length-1]:[0]:u,k=l?N[0]:p,z=!x&&!b?e.getPointGlobalCoordinates(m,h,s):null,U=k,D=Xe(m)&&m.startBinding&&s.get(m.startBinding.elementId),B=Xe(m)&&m.endBinding&&s.get(m.endBinding.elementId),P=b&&D&&A?.suggestedBinding?.element.id!==D.id?D:x&&B&&A?.suggestedBinding?.element.id!==B.id?B:null;return{selectedLinearElement:{...r,selectedPointsIndices:N,initialState:{...r.initialState,lastClickedPoint:k,altFocusPoint:!r.initialState.altFocusPoint&&Xe(m)&&P?Dc(m,H(m.x,m.y),P,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!O&&!n.state.gridModeEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:z,hoverPointIndex:U,isDragging:!0,customLineAngle:E},suggestedBinding:S}}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)&&Hg(c.points,i.zoom.value)&&(Re(c)&&o.mutateElement(c,{...Gc(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,arrowOtherEndpointInitialBinding:null}}}static getEditorMidPoints=(t,n,i)=>{let o=J(t,n);if(!X(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(!X(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!X(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Vt(H(c[0],c[1]),H(n.x,n.y))<=d)return c;let u=0,p=e.getEditorMidPoints(s,o,i);for(;u<p.length;){if(p[u]!==null&&Vt(p[u],H(n.x,n.y))<=d)return p[u];u++}return null};static isSegmentTooShort(t,n,i,o,r,s){if(X(t))return o>=0&&o<t.points.length?Vt(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=Vt(n,i);if(t.points.length>2&&t.roundness){let[l,d]=Tc(t,s);ft(l.length===0&&d.length>0,"Only linears built out of curves are supported"),ft(l.length+d.length>=o,"Invalid segment index while calculating mid point"),a=kc(d[o])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,i){if(X(t)){ft(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=Sc(t.points[n-1],t.points[n]);return H(t.x+s[0],t.y+s[1])}let[o,r]=Tc(t,i);if(ft(o.length===0&&r.length>0||o.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),ft(o.length+r.length>=n,"Invalid segment index while calculating mid point"),o.length){let s=o[n-1];return Sc(s[0],s[1])}if(r.length){let s=r[n-1];return Nc(s,.5)}ft(!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,hitBoundText:!1,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let p=e.getSegmentMidpointHitCoords(r,o,a,l),m=H(o.x,o.y),h=null;if(p)h=e.getSegmentMidPointIndex(r,a,p,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[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:m,segmentMidpoint:{value:p,index:h,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:u.startBinding},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let f=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y),g=e.isPointHandle(u,f),E=J(u,l),x=null;if(!g&&!p&&E&&W(u)&&n.arrowText.isBoundTextGrabbable(u,o.x,o.y)){let{x:N,y:k}=e.getBoundTextElementPosition(u,E,l);x={x:o.x-(N+E.width/2),y:o.y-(k+E.height/2)}}let b=x?-1:f;d.hitBoundText=!!x,(b>=0||p||x)&&(d.hitElement=u);let[y,w,S,I]=q(u,l),A=(y+S)/2,T=(w+I)/2,O=b>-1&&nt(H(u.x+u.points[b][0],u.y+u.points[b][1]),H(A,T),u.angle),v=b>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(b)?Wg([...r.selectedPointsIndices||[],b]):[b]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:b,origin:m,segmentMidpoint:{value:p,index:h,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:v?.includes(0)?u.endBinding:u.startBinding},selectedPointsIndices:v,pointerOffset:O?{x:o.x-O[0],y:o.y-O[1]}:x??{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Ic(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 p;if(li(t)&&c.length>=2){let m=c[c.length-2],[h,f]=e._getShiftLockedDelta(d,l,m,H(n,i),t[ai.CTRL_OR_CMD]?null:o.getEffectiveGridSize());p=H(h+m[0],f+m[1])}else p=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[ai.CTRL_OR_CMD]||X(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:p}]])):e.addPoints(d,o.scene,[p]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=q(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return nt(H(c+n[0],u+n[1]),H(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=q(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return nt(H(c+d[0],u+d[1]),H(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=q(t,i),a=H(r,s),l=t.points[o],{x:d,y:c}=t;return l?nt(H(d+l[0],c+l[1]),a,t.angle):nt(H(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(X(t))return H(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=q(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=nt(H(n[0],n[1]),H(l,d),-t.angle);return H(c-t.x,u-t.y)}static isPointHandle(t,n){return n>=0&&(!X(t)||n===0||n===t.points.length-1)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Vt(H(o,r),H(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=Mc(i,o,r),[a,l,d,c]=q(t,n),u=(a+d)/2,p=(l+c)/2,[m,h]=nt(H(s[0],s[1]),H(u,p),-t.angle);return H(m-t.x,h-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=fa(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){ft(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);ft(s,"The linear element does not exist in the provided Scene"),ft(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((p,m,h)=>{if(++c,p.push(m),o.includes(h)){let g=a[h+1];g||(d=!0),p.push(g?H((m[0]+g[0])/2,(m[1]+g[1])/2):H(m[0],m[1])),l.push(c+1),++c}return p},[]);if(n.mutateElement(s,{points:u}),d){let p=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:H(p[0]+30,p[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));Re(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=H(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=fa({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];Re(t)&&t.polygon&&(o[0]=H(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=fa({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o,r){let{points:s}=t;if(Re(t)&&t.polygon){let u=i.get(0),p=i.get(s.length-1);u?i.set(s.length-1,{point:H(u.point[0],u.point[1]),isDragging:u.isDragging}):p&&i.set(0,{point:H(p.point[0],p.point[1]),isDragging:p.isDragging})}let a=i.get(0)?.point??H(0,0),[l,d]=a,c=X(t)?[i.get(0)?.point??s[0],i.get(s.length-1)?.point??s[s.length-1]]:s.map((u,p)=>{let m=i.get(p)?.point??u;return o?.moveMidPointsWithElement&&p!==0&&p!==s.length-1&&!i.has(p)?m:H(m[0]-l,m[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&&X(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=Vt(a,H(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<zg/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&&!X(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(X(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=ga(t,i),d=ga(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,p=(d[0]+d[2])/2,m=(d[1]+d[3])/2,h=p-c,f=m-u,g=nt(H(o,r),H(h,f),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+g[0],y:t.y+g[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(X(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=Mc(o[0],o[1],r),{width:c,height:u}=Fc(a[0],a[1],l,d,s);return nt(H(c,u),H(0,0),-t.angle)}static getBoundTextElementCenter=(t,n)=>{if(t.points.length%2===1){let o=Math.floor(t.points.length/2);return e.getPointGlobalCoordinates(t,t.points[o],n)}let i=t.points.length/2-1;return e.getSegmentMidPoint(t,i+1,n)};static handleBoundTextDragging(t,n,i,o){let r=n.getNonDeletedElementsMap(),s=e.getElement(t.elementId,r),a=J(s,r);if(!s||!W(s)||!a)return null;let l=H(i-t.pointerOffset.x,o-t.pointerOffset.y),{segments:d,lengths:c,prefixSums:u,totalLength:p}=Cc(s,r);if(d.length===0||p===0)return null;let m=1/0,h=0,f=0;for(let b=0;b<d.length;b++){let{t:y,distance:w}=Xg(d[b],l);w<m&&(m=w,h=b,f=y)}let g=jg(d[h],f,c[h]),E=ma((u[h]+g)/p,0,1),x=e.getPointAtPathParameter(s,E,r);return x?(n.mutateElement(a,{labelPosition:E,x:x[0]-a.width/2,y:x[1]-a.height/2}),{...t,isDragging:!0}):null}static getPointAtPathParameter(t,n,i){if(!Number.isFinite(n))return null;let{segments:o,lengths:r,prefixSums:s,totalLength:a}=Cc(t,i);if(o.length===0)return null;let l=ma(n,0,1)*a,d=o.findIndex((p,m)=>l<=s[m+1]),c=d===-1?o.length-1:d,u=r[c]===0?0:ma((l-s[c])/r[c],0,1);return $g(o[c],u,r[c])}static getBoundTextElementPosition=(t,n,i)=>{let o=vc.get(n);if(o&&o.containerVersion===t.version&&o.textVersion===n.version)return o.position;let r=e.computeBoundTextElementPosition(t,n,i);return vc.set(n,{containerVersion:t.version,textVersion:n.version,position:r}),r};static computeBoundTextElementPosition=(t,n,i)=>{if(t.points.length<2)return{x:n.x,y:n.y};if(W(t)&&n.labelPosition!=null){let r=e.getPointAtPathParameter(t,n.labelPosition,i);if(r)return{x:r[0]-n.width/2,y:r[1]-n.height/2}}let o=e.getBoundTextElementCenter(t,i);return{x:o[0]-n.width/2,y:o[1]-n.height/2}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:p}=e.getBoundTextElementPosition(t,o,n),m=u+o.width,h=p+o.height,f=H(d,c),g=nt(H(r,s),f,t.angle),E=nt(H(a,s),f,t.angle),x=nt(H(u,p),f,-t.angle),b=nt(H(m,p),f,-t.angle),y=nt(H(u,h),f,-t.angle),w=nt(H(m,h),f,-t.angle);return g[0]<E[0]&&g[1]>=E[1]?(r=Math.min(r,y[0]),a=Math.max(a,Math.max(b[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):g[0]>=E[0]&&g[1]>E[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],b[0])),s=Math.min(s,y[1]),l=Math.max(l,b[1])):g[0]>=E[0]?(r=Math.min(r,b[0]),a=Math.max(a,y[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):g[1]<=E[1]&&(r=Math.min(r,Math.min(b[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,b[1]),l=Math.max(l,y[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=Qe.generateElementShape(t,null),r=Jt(o[0]),[s,a,l,d]=fo(r),c=s+t.x,u=a+t.y,p=l+t.x,m=d+t.y,h=(c+p)/2,f=(u+m)/2,g=i&&J(t,n);return g?e.getMinMaxXYWithBoundText(t,n,[c,u,p,m],g):[c,u,p,m,h,f]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!X(a))return t;if(n&&n>0&&n<a.points.length){let l=ct(Bt(Ng(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((m,h)=>(m[h.index]=h,m),{});d[n]={index:n,start:H(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:H(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((m,h)=>m.index-h.index),u=c.map(m=>m.index).reduce((m,h)=>h<n?m+1:m,0);r.mutateElement(a,{fixedSegments:c});let p=H(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,initialState:{...t.initialState,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)})}},Wg=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},Bc=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let p=new Map(e.map(U=>{let D=s.points[U]??s.points.at(-1);return[U,{point:H(D[0]+t,D[1]+n),isDragging:!0}]}));if(!W(s))return{positions:p};let m=e.includes(0),h=e.includes(s.points.length-1),{start:f,end:g}=ca(s,p,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c,gridSize:l.getEffectiveGridSize()});if(X(s)){let U=m?f.element:h?g.element:null;return{positions:p,updates:{suggestedBinding:U?{element:U,midPoint:l.state.isMidpointSnappingEnabled?pa(H(i-u.pointerOffset.x,o-u.pointerOffset.y),U,r,l.state.zoom,s):void 0}:null},hit:U}}if(!m&&!h){let U={...s,points:s.points.map((B,P)=>p.get(P)?.point??B)},D=new Map(p);if(s.startBinding){let B=r.get(s.startBinding.elementId);if(B){let P=Gt(U,"startBinding",s.startBinding,B,r)??null;P&&D.set(0,{point:P,isDragging:!0})}}if(s.endBinding){let B=r.get(s.endBinding.elementId);if(B){let P=Gt(U,"endBinding",s.endBinding,B,r)??null;P&&D.set(s.points.length-1,{point:P,isDragging:!0})}}return{positions:D}}if(m===h)return{positions:p};let E={suggestedBinding:null};f.mode===null?E.startBinding=null:f.mode?(E.startBinding={elementId:f.element.id,mode:f.mode,...si(s,f.element,"start",r,f.focusPoint)},m&&(E.startBinding.mode==="orbit"||!vi("COMPLEX_BINDINGS"))&&(E.suggestedBinding=f.element?{element:f.element,midPoint:pa(H(i-u.pointerOffset.x,o-u.pointerOffset.y),f.element,r,l.state.zoom,s)}:null)):m&&(E.suggestedBinding=l.state.suggestedBinding),g.mode===null?E.endBinding=null:g.mode?(E.endBinding={elementId:g.element.id,mode:g.mode,...si(s,g.element,"end",r,g.focusPoint)},h&&(E.endBinding.mode==="orbit"||!vi("COMPLEX_BINDINGS"))&&(E.suggestedBinding=g.element?{element:g.element,midPoint:pa(H(i-u.pointerOffset.x,o-u.pointerOffset.y),g.element,r,l.state.zoom,s)}:null)):h&&(E.suggestedBinding=l.state.suggestedBinding);let x=m?H(s.points[0][0]+t,s.points[0][1]+n):s.points[0],b=h?H(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],y={...s,points:[x,...s.points.slice(1,-1),b],startBinding:E.startBinding===void 0?s.startBinding:E.startBinding===null?null:E.startBinding,endBinding:E.endBinding===void 0?s.endBinding:E.endBinding===null?null:E.endBinding},w=s.endBinding&&y.startBinding&&m&&y.startBinding.elementId===s.endBinding.elementId,S=s.startBinding&&y.endBinding&&h&&s.startBinding.elementId===y.endBinding.elementId,I=y.endBinding?g.element??r.get(y.endBinding.elementId):null,A=S&&l.state.bindMode!=="inside"&&vi("COMPLEX_BINDINGS")?y.points[0]:I&&Gt(y,"endBinding",y.endBinding,I,r,h)||y.points[y.points.length-1];y.points[y.points.length-1]=A;let T=y.startBinding?f.element??r.get(y.startBinding.elementId):null,O=S&&vi("COMPLEX_BINDINGS")?y.points[0]:w&&l.state.bindMode!=="inside"&&vi("COMPLEX_BINDINGS")?A:T&&Gt(y,"startBinding",y.startBinding,T,r,m)||y.points[0],v=!(S&&l.state.bindMode!=="inside"&&vi("COMPLEX_BINDINGS"))&&!!I,N=Vt(O,y.points[0])!==0,k=new Set(e);T&&N&&k.add(0),I&&v&&k.add(s.points.length-1);let z=Array.from(k);return{updates:E,positions:new Map(z.map(U=>[U,U===0?{point:O,isDragging:!0}:U===s.points.length-1?{point:A,isDragging:!0}:p.get(U)])),hit:m?f.element:g.element}},Lc=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]),ha=new WeakMap;function Cc(e,t){let n=ha.get(e);if(n){if(n.version===e.version)return n.metrics;ha.delete(e)}let i=Ug(e,t),o=i.map(Yg),r=new Array(o.length+1);r[0]=0;for(let a=0;a<o.length;a++)r[a+1]=r[a]+o[a];let s={segments:i,lengths:o,prefixSums:r,totalLength:r[o.length]};return ha.set(e,{version:e.version,metrics:s}),s}var Yg=e=>wr(e)?kc(e):Vt(e[0],e[1]),Xg=(e,t)=>{if(wr(e)){let i=Fg(e,t);return{t:i,distance:Vt(t,Rg(e,i))}}let n=Gg(t,e);return{t:n,distance:Vt(t,Oc(e,n))}},jg=(e,t,n)=>wr(e)?Og(e,t):t*n,$g=(e,t,n)=>wr(e)?Nc(e,t,n):Oc(e,t);M();import{arrayToMap as Ft}from"@excalidraw/common";import{isPointWithinBounds as dE,pointFrom as Sa,segmentsIntersectAt as cE}from"@excalidraw/math";M();import{arrayToMap as Jg,isShallowEqual as eE}from"@excalidraw/common";M();var Vg=(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}}},Rc=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 p of r){let m=p.groupIds;if(a.editingGroupId){let h=m.indexOf(a.editingGroupId);h>-1&&(m=m.slice(0,h))}if(m.length>0){let h=m[m.length-1];d[h]=!0}}let c={},u=s.reduce((p,m)=>{if(m.isDeleted)return p;let h=m.groupIds.find(f=>d[f]);return h&&(p[m.id]=!0,Array.isArray(c[h])?c[h].push(m.id):c[h]=[m.id]),p},{});for(let p of Object.keys(c))c[p].length<2&&d[p]&&(d[p]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:Ea({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):Kt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Ea(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),Kg=(e,t)=>xa(e,t)!=null,xa=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Zg=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),zc=(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,...Vg(r,n,e)}}}return n.selectedGroupIds},eM=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),qg=(e,t)=>e.groupIds.includes(t),it=(e,t)=>{let n=[];for(let i of e.values())qg(i,t)&&n.push(i);return n},Qg=(e,t)=>e.groupIds.find(n=>t[n]),tM=(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},nM=(e,t)=>e.filter(n=>!t[n]),iM=(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=J(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},_c=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},Hc=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},Uc=e=>e.groupIds.length>0,Wc=(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},Pr=(e,t,n)=>{let i=new Map,r=Zg(n).length===1&&e.every(s=>Kg(n,s));return e.forEach(s=>{if(ge(s))return;let a,l=Qg(s,n.selectedGroupIds);if(!l)a=`${s.id}_element`;else{let u=r?s.groupIds.indexOf(l)-1:s.groupIds.indexOf(l);a=u<0?`${s.id}_element`:`${s.groupIds[u]}_group`}let d=i.get(a)??[],c=J(s,t);i.set(a,[...d,s,...c?[c]:[]])}),[...i.values()]};var tE=e=>e.locked||ge(e),nE=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),iE=e=>{let t=new Set;return e.forEach(n=>{Q(n)&&t.add(n.id)}),nE(e,t)},Yc=(e,t,n,i=!0,o="contain")=>{let[r,s,a,l]=q(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),p=Math.max(s,l);return Xc({elements:e,bounds:[d,c,u,p],elementsMap:n,type:o,shouldIgnoreElementFromSelection:tE,excludeElementsInFrames:i})},fM=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=jc(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},hM=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}(),Kt=(e,t,n)=>{let i=new Set,o=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){je(r)?(o.push(r),i.add(r.id)):console.error("[NONDELETED][INVARIANT] getSelectedElements skipping deleted selected element which should not be in the selection");continue}if(n?.includeBoundTextElement&&ge(r)&&je(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{Q(s)&&zn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},gM=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement&&t.activeTool.type!=="autoshape"?[t.newElement]:Kt(e,t,{includeBoundTextElement:!0}),Ea=(e,t)=>eE(t.selectedElementIds,e)?t.selectedElementIds:e,oE=(e,t)=>{let n=e.filter(ee);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 R(i,Jg(t))}return null},EM=(e,t,n)=>({selectedLinearElement:oE(e,t),...Rc({editingGroupId:n.editingGroupId,selectedElementIds:iE(e).reduce((i,o)=>(ge(o)||(i[o.id]=!0),i),{})},t,n,null)}),xM=(e,t)=>t.editingTextElement||e.length===1&&$(e[0])&&e[0]||null;M();import{arrayToMap as Sr}from"@excalidraw/common";import{validateOrderKey as rE,generateNKeysBetween as sE}from"@excalidraw/fractional-indexing";var ba=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},aE=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=d=>`${d?.index}:${d?.id}:${d?.type}:${d?.isDeleted}:${d?.version}:${d?.versionNonce}`,a=n?Sr(e):null,l=e.map(d=>d.index);for(let[d,c]of l.entries()){let u=l[d-1],p=l[d+1];if(ya(c,u,p)||r.push(`Fractional indices invariant has been compromised: "${s(e[d-1])}", "${s(e[d])}", "${s(e[d+1])}"`),n&&a&&Wt(e[d])&&je(e[d])){let m=e[d],h=kt(m),f=h?a.get(h):null;f&&je(f)&&f.index<=m.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(f)}", "${s(m)}"`)}}if(r.length){let d=new ba,c=[];if(o&&(c.push("Additional reconciliation context:"),c.push(o.localElements.map(u=>s(u))),c.push(o.remoteElements.map(u=>s(u)))),i||console.error(r.join(`
19
11
 
20
- `),l.stack,e.map(c=>s(c)),...d),t)throw l}},Ed=e=>e.sort((t,n)=>hd(t)&&hd(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),pi=(e,t)=>{try{let n=Io(e),i=jf(e,t),o=is(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Uf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)be(s,n,{index:a})}catch{Xf(e)}return e},Xf=e=>{let t=Io(e),n=gd(e),i=is(e,n);for(let[o,{index:r}]of i)be(o,t,{index:r});return e},ad=e=>{let t=Io(e),n=gd(e),i=is(e,n);for(let[o,{index:r}]of i)t.set(o.id,Ee(o,{index:r}));return t},jf=(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},gd=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 p=e[u]?.index;if(!c&&p||c&&p&&p>c)return[p,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),ns(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[f,E]=a(l);if(ns(u,p,f))break;[n,o]=[p,m],[i,r]=[f,E],c.push(l)}c.push(r),t.push(c)}}return t},ns=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,is=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=Po(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},hd=e=>!!e.index;P();var vd=bc(Pd(),1);import{randomInteger as dh,arrayToMap as Id,toBrandedType as Sd,isDevEnv as Md,isTestEnv as Td,toArray as ch}from"@excalidraw/common";import{isNonDeletedElement as uh}from"@excalidraw/element";import{isFrameLikeElement as ph}from"@excalidraw/element";import{getElementsInGroup as mh}from"@excalidraw/element";import{syncInvalidIndices as fh,syncMovedIndices as Ad,validateFractionalIndices as hh}from"@excalidraw/element";import{getSelectedElements as Eh}from"@excalidraw/element";import{mutateElement as gh}from"@excalidraw/element";var Dd=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}},xh=(0,vd.default)(e=>{(Md()||Td()||window?.DEBUG_FRACTIONAL_INDICES)&&hh(e,{shouldThrow:Md()||Td(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),wh=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Mo=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=Sd(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=Sd(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=wh(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=Eh(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&&uh(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=ch(t),o=[];n?.skipValidation||xh(i),this.elements=fh(i),this.elementsMap.clear(),this.elements.forEach(s=>{ph(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=Dd(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=Dd(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=dh();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)];Ad(i,Id([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)];Ad(i,Id(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]:mh(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=gh(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var F=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(Bt(t??[],o),Bt(n??[],o),Bt(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,p)=>(u[p]=o(a[p]),u),{}),c=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=o(l[p]),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=Bt(e.getLeftDifferences(Bt(r,o),Bt(s,o)),d=>d),l=Bt(e.getRightDifferences(Bt(r,o),Bt(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)])):Cd(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&&Gd(a,l))continue;yield s}}}},Jt=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=F.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(F.create({},{}))}inverse(){let t=F.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=F.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=F.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=F.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=F.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=F.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=F.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=F.merge(this.delta,t.delta,F.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=F.mergeObjects(t.selectedElementIds,s,i),p=F.mergeObjects(t.selectedGroupIds,a,o),m=F.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new U(n.get(d.elementId),n,d.isEditing):null,E={...t,...c,selectedElementIds:u,selectedGroupIds:p,lockedMultiSelections:m,selectedLinearElement:typeof d<"u"?f:t.selectedLinearElement},h=this.filterInvisibleChanges(t,E,n);return[E,h]}catch(i){if(console.error("Couldn't apply appstate change",i),on()||nn())throw i;return[t,!1]}}isEmpty(){return F.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=On(t),r=On(n),s=F.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=F.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=F.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=xl(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 y=i.get(x);y&&!y.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?c.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=i.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},E=n[u]||{};Gd(f,E)||(l.value=!0);break;case"activeLockedId":let h=t[u]||null,g=n[u]||null;h!==g&&(l.value=!0);break;default:Cd(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{F.diffObjects(t,n,"selectedElementIds",i=>!0),F.diffObjects(t,n,"selectedGroupIds",i=>i??!1),F.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),on()||nn())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}},en=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(on()||nn())&&(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:Ld()},c=F.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:Ld()},d={...s},c=F.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=F.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]=F.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,p)=>{let m;switch(p){case"deleted":m=d;break;case"inserted":m=c;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=d=>{let c={};for(let[u,p]of Object.entries(d)){let m=t.get(u),f=n.get(u),E=null;m||f?E=F.create(p.deleted,p.inserted,o(m,f),i):E=p,F.isInnerDifferent(E.deleted,E.inserted)&&(c[u]=E)}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=tn.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),on()||nn())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),on()||nn())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=F.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=F.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return F.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]=F.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]=F.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=F.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(on()||nn())&&(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 p=e.applyDelta(u,c,o,r);if(n.set(p.id,p),l.set(p.id,p),!o.applyDirection){let m=t.get(d);m&&(o.applyDirection=m.version>p.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=Ee({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=F.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),Ee(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:F.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,p=l,m;c===d?m=Ee(d,{...p,version:u},!0):m=be(d,n,{...p,version:c?.version!==d.version?d.version:u}),o.set(m.id,m),n.set(m.id,m)};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=>Qa.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);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)=>{ie(a)&&o(a,l)}),$t.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Mo(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),on()||nn())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(ce(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||ba(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Le(i)&&Ue(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=Ed([...o]),s=F.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),yh(pi(r,s))}static postProcess(t,n){try{F.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];F.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),on()||nn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var pP=(e,t,n,i)=>{let[o,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Ct(e),d=po(e,t,i).map(m=>[m,Ct(m)]).sort((m,f)=>m[1][r]-f[1][r]),c=0;for(let m of d)c+=m[1][a];let u=(l[a]-c)/(d.length-1);if(u<0){let m=d.findIndex(g=>g[1][o]===l[o]),f=d.findIndex(g=>g[1][s]===l[s]),E=(d[f][1][r]-d[m][1][r])/(d.length-1),h=d[m][1][r];return d.flatMap(([g,x],y)=>{let b={x:0,y:0};return y!==m&&y!==f&&(h+=E,b[n.axis]=h-x[r]),g.map(w=>Ee(w,{x:w.x+b.x,y:w.y+b.y}))})}let p=l[o];return d.flatMap(([m,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[o],p+=u,p+=f[a],m.map(h=>Ee(h,{x:h.x+E.x,y:h.y+E.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as bh,getGridPoint as Ph,getFontString as Ih}from"@excalidraw/common";var PP=(e,t,n,i,o,r)=>{if(t.length===1&&B(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(u=>{if(B(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=>Z(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 d=[];for(let u of a){let p=e.originalElements.get(u.id);if(!p)return;d.push(p)}let c=Sh(Xe(d),n,o,r);a.forEach(u=>{if(Bd(e,u,i,c),!Y(u)){let p=W(u,i.getNonDeletedElementsMap());p&&Bd(e,p,i,c),Ue(u,i,{simultaneouslyUpdated:Array.from(a)})}})},Sh=(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]=Ph(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Bd=(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})},IP=(e,t,n)=>{let[i,o]=Xe(e);return[t-i,n-o]},SP=({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: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}=$r(t,a,o<n?-s:s):{width:s,height:a}=$r(t,s,r<i?-a:a),a<0&&(a=-a)));let E=o<n?n-s:n,h=r<i?i-a:i;d&&(s+=s,a+=a,E=n-s/2,h=i-a/2);let g=null;if(ie(e)){a=e.height;let x=Hi(Ih({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>bh/c&&(g={autoResize:!1}),h=i,d&&(E=n-s/2)}if(s!==0&&a!==0){let x=null;we(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 To,normalizeLink as kd}from"@excalidraw/common";var vP=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(To,e),kd(i.toString())}catch(i){console.error(i)}return kd(n)},LP=(e,t)=>{if(e.length>0&&Mh(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},Mh=e=>!!(e.length===1||e.length>1&&wl(e)),CP=e=>{try{let t=new URL(e);return t.searchParams.has(To)&&t.host===window.location.host}catch{return!1}},GP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(To))return t.get(To)}catch{}return null};P();import{FONT_FAMILY as Fh,VERTICAL_ALIGN as Nh,escapeDoubleQuotes as ss,getFontString as Hh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as rn,DEFAULT_FONT_FAMILY as Th,DEFAULT_FONT_SIZE as Ah,DEFAULT_TEXT_ALIGN as Dh,DEFAULT_VERTICAL_ALIGN as vh,VERTICAL_ALIGN as Lh,randomInteger as Ch,randomId as Gh,getFontString as Ao,getUpdatedTimestamp as Bh,getLineHeight as kh}from"@excalidraw/common";var nt=(e,{x:t,y:n,strokeColor:i=rn.strokeColor,backgroundColor:o=rn.backgroundColor,fillStyle:r=rn.fillStyle,strokeWidth:s=rn.strokeWidth,strokeStyle:a=rn.strokeStyle,roughness:l=rn.roughness,opacity:d=rn.opacity,width:c=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=rn.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||Gh(),type:e,x:t,y:n,width:c,height:u,angle:p,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:m,frameId:f,index:E,roundness:h,seed:b.seed??Ch(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Bh(),link:x,locked:y,customData:b.customData}),rs=e=>nt(e.type,e),YP=e=>nt("embeddable",e),UP=e=>({...nt("iframe",e)}),XP=e=>Ee({...nt("frame",e),type:"frame",name:e?.name||null},{}),jP=e=>Ee({...nt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Od=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Rd=e=>{let t=e.fontFamily||Th,n=e.fontSize||Ah,i=e.lineHeight||kh(t),o=ir(e.text),r=Je(o,Ao({fontFamily:t,fontSize:n}),i),s=e.textAlign||Dh,a=e.verticalAlign||vh,l=Od({textAlign:s,verticalAlign:a},r),d={...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 Ee(d,{})},Oh=(e,t,n)=>{let{width:i,height:o}=Je(n,Ao(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Lh.MIDDLE&&!e.containerId&&e.autoResize){let d=Je(e.text,Ao(e),e.lineHeight),c=Od(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,p]=_(e,t),[m,f,E,h]=Nt(e,i,o,!1),g=(d-m)/2,x=(c-f)/2,y=(u-E)/2,b=(p-h)/2;[a,l]=Rh({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}},Rh=(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]},WP=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Pt(i,Ao(e),t?et(t,e):e.width));let o=Oh(e,n,i);return{text:i,...o}},VP=e=>({...nt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,lastCommittedPoint:null}),$P=e=>{let t={...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return mn(t)?{...t,polygon:e.polygon??!1}:t},Fd=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},ZP=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,zh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,_h=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Yh=/^https:\/\/(?:www\.)?figma\.com/,Nd=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Uh=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Xh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Hd=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,jh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,Wh=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Vh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,zd=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,_d=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,$h=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Zh=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)},ls=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"]),Yd=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"]),as=e=>`<html><body>${e}</body></html>`,nI=e=>{if(!e)return null;if(ft.has(e))return ft.get(e);let t=e,n=Yd.has(ds(e,Yd)||""),i="generic",o={w:560,h:840},r=e.match(zh);if(r?.[2]){let d=Zh(t),c=d>0?`&start=${d}`:"",u=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=u?{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(_h);if(s?.[1]){let d=s?.[1],c=/^\d+$/.test(d)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${d}?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:c,sandbox:{allowSameOrigin:n}}}if(e.match(Yh))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(Wh);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(Xh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Hd.test(e)){let d=e.match(Hd)[1],c=ss(`https://twitter.com/x/status/${d}`),u={type:"document",srcdoc:p=>as(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${c}"></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(_d.test(e)){let[,d,c,u]=e.match(_d),p=ss(`https://reddit.com/r/${d}/comments/${c}/${u}`),m={type:"document",srcdoc:f=>as(`<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(Nd.test(e)){let[,d,c]=e.match(Nd),u=ss(`https://gist.github.com/${d}/${c}`),p={type:"document",srcdoc:()=>as(`
21
- <script src="${u}.js"><\/script>
12
+ `),d.stack,e.map(u=>s(u)),...c),t)throw d}},Vc=e=>e.sort((t,n)=>$c(t)&&$c(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),di=(e,t)=>{try{let n=Sr(e),i=lE(e,t),o=Pa(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});aE(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)He(s,n,{index:a})}catch{wa(e)}return e},wa=e=>{let t=Sr(e),n=Zc(e),i=Pa(e,n);for(let[o,{index:r}]of i)He(o,t,{index:r});return e},Kc=e=>{let t=Sr(e),n=Zc(e),i=Pa(e,n);for(let[o,{index:r}]of i)t.set(o.id,Me(o,{index:r}));return t},lE=(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},Zc=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 p=e[u]?.index;if(!c&&p||c&&p&&p>c)return[p,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),ya(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[h,f]=a(l);if(ya(u,p,h))break;[n,o]=[p,m],[i,r]=[h,f],c.push(l)}c.push(r),t.push(c)}}return t},ya=(e,t,n)=>{if(!e)return!1;try{rE(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},Pa=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=sE(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},$c=e=>!!e.index;var qc=(e,t,n)=>{let i=Ft(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&&He(a,i,{frameId:s??null})}};function Li(e,t,n){let i=Bi(t,n),o=Bi(e,n);return i.some(s=>o.some(a=>cE(s,a)))}var Qc=(e,t,n)=>Ir(Yc(e,t,n,!1)).filter(i=>!Q(i)&&!i.frameId||i.frameId===t.id),Ia=(e,t,n)=>Ta(ae(e,n),ae(t,n)),zM=(e,t)=>{let n=Ft(e);return e.filter(i=>Li(i,t,n))},Un=(e,t,n)=>{let[i,o,r,s]=q(t,n),[a,l,d,c]=ot(e);return i<=a&&o<=l&&r>=d&&s>=c},_n=(e,t,n)=>Un([e],t,n)||Li(e,t,n)||Ia(e,t,n),_M=(e,t,n)=>{let[i,o,r,s]=q(t,n);return dE(Sa(i,o),Sa(e.x,e.y),Sa(r,s))},HM=(e,t,n)=>{let i=Ft(e),o=t.flatMap(r=>it(e,r));return o.length===0?!0:!!o.find(r=>Un([r],n,i)||Li(r,n,i))},UM=(e,t,n)=>{let i=Ft(e),o=t.flatMap(r=>it(e,r));return o.length===0?!0:o.find(r=>Un([r],n,i)||Li(r,n,i))===void 0},WM=e=>{let t=new Map;for(let n of e){let i=Q(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,zn(e,i))}return t},zn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Ma=e=>e.filter(t=>Q(t)),YM=e=>{let t=Ft(Ma(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},XM=(e,t,n,i)=>{let o=zn(e,t.id),r=new Set(o),s=new Set([...Qc(e,t,i),...o.filter(m=>Ia(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(!Li(m,t,i))m.groupIds.length===0&&r.delete(m);else if(m.groupIds.length>0)for(let h of m.groupIds)l.add(h);for(let m of a)if(m.groupIds.length>0){let h=!0;for(let f of m.groupIds)l.has(f)&&(h=!1);h&&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=Ci(c),p=zc(u,n);for(let[m,h]of Object.entries(p))if(h){let f=it(e,m);if(Un(f,t,i))for(let g of f)r.add(g)}return[...r].filter(m=>!($(m)&&m.containerId))},jM=(e,t,n)=>uE(Ir(e,Qc(e,t,n)),t,n),uE=(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=>it(n,l)));s=!Un(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Hn=(e,t)=>e.frameId&&t.get(e.frameId)||null,$M=(e,t)=>{let n=new Set,i=Ft(e);e=Ir(e);for(let s of e)Q(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(Q(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=it(e,a);if(l.some(d=>_n(d,t,i)))for(let d of l)r.push(d)}}else _n(s,t,i)&&r.push(s);return r},mE=e=>{let t;for(let n of e){if(Q(n)||!n.frameId)return null;if(t===void 0)t=n.frameId;else if(t!==n.frameId)return null}return t??null},pE=(e,t)=>{for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.id===t)return n;if(i.frameId===t)return n+1}return null},fE=(e,t,n)=>{let i=Ft(e),o=mE(t),r=new Set,s=new Set;for(let c of t)Q(c)&&c.id!==n.id&&s.add(c.id);for(let c of Ir(e,t)){if(Q(c)||c.frameId&&s.has(c.frameId))continue;r.add(c);let u=J(c,i);u&&!r.has(u)&&r.add(u)}for(let c of r)c.frameId!==n.id&&He(c,i,{frameId:n.id});if(!r.size||o===n.id)return e;let a=Array.from(e.values()).filter(c=>!r.has(c)),l=pE(a,n.id);if(l===null)return e;let d=[...a.slice(0,l),...r,...a.slice(l)];return di(d,Ft([...r])),Array.isArray(e)?d:new Map(d.map(c=>[c.id,c]))},Jc=(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=J(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)He(o,t,{frameId:null})},hE=(e,t)=>{let n=zn(e,t.id);return Jc(n,Ft(e)),e},VM=(e,t,n)=>fE(hE(e,n),t,n).slice(),KM=(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=>it(e,l)).forEach(l=>o.add(l));let r=new Set,s=Ft(e);return o.forEach(a=>{a.frameId&&!Q(a)&&!eu(a,s,t)&&r.add(a)}),r.size>0&&Jc(r,s),e},Ir=(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)it(e,s).some(a=>Q(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},gE=(e,t,n)=>{let i=$(e)&&Oe(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Hn(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Hn(i,t)},eu=(e,t,n,i)=>{let o=i?.targetFrame??gE(e,t,n);if(!o)return!1;let r=$(e)&&Oe(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 _n(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=>it(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(Kt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(Q(l))return s(!1),!1;for(let l of a)if(_n(l,o,t))return s(!0),!0;return!1},ZM=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Li(e,t,i)||Ia(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Un([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=eu(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},EE="Frame",xE="AI Frame",bE=e=>$o(e)?EE:xE,qM=e=>e.name===null?bE(e):e.name,QM=(e,t,n)=>e.filter(i=>(!i.frameId||i.frameId===t.id)&&yt(ae(i,n),ae(t,n))),JM=e=>{let t=Ft(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var kE=(e,t)=>ei(e)&&!t.imageCache.has(e.fileId),ho=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}},su={x:0,y:0},NE=(e,t,n)=>{let i=$(e)?Oe(e,t):null;return n?.get((i??e).id)?.offset},hT=(e,t)=>t.x===0&&t.y===0?e:{...e,x:e.x+t.x,y:e.y+t.y},OE=(e,t,n,i=t)=>{let{elementRenderOverrides:o,elementsPendingErasure:r,pendingFlowchartNodes:s}=n,a=o?.get(e.id),l=Hn(e,t),c=(l?tu(o?.get(l.id)?.opacity??l.opacity,0,100):100)*tu(a?.opacity??e.opacity,0,100)/1e4;(r.has(e.id)||s?.some(p=>p.id===e.id)||l&&r.has(l.id))&&(c*=PE/100);let u=NE(e,i,o);return{opacity:c,offset:u??su}},GE=(e,t,n)=>{let r=ho(e),[s,a,l,d]=q(e,t),c=ee(e)||he(e)?Yn(s,l):e.width,u=ee(e)||he(e)?Yn(a,d):e.height,p=c*window.devicePixelRatio+r*2,m=u*window.devicePixelRatio+r*2,h=n.value;return(p*h>32767||m*h>32767)&&(h=Math.min(32767/p,32767/m)),p*m*h*h>16777216&&(h=Math.sqrt(16777216/(p*m))),p=Math.floor(p*h),m=Math.floor(m*h),{width:p,height:m,scale:h}},au=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=ho(e),{width:l,height:d,scale:c}=GE(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,p=0;if(ee(e)||he(e)){let[h,f]=q(e,t);u=e.x>h?Yn(e.x,h)*window.devicePixelRatio*c:0,p=e.y>f?Yn(e.y,f)*window.devicePixelRatio*c:0,s.translate(u,p)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let m=xi.canvas(r);return Ar(e,m,s,i),s.restore(),{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:p,containingFrameOpacity:Hn(e,t)?.opacity||100,imageCrop:Ne(e)?e.crop:null}},gT=14,lu=typeof document<"u"?document.createElement("img"):{src:""};lu.src=`data:${La.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 du=typeof document<"u"?document.createElement("img"):{src:""};du.src=`data:${La.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 FE=(e,t,n)=>{t.fillStyle=n===mn.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"?du:lu,e.width/2-o/2,e.height/2-o/2,o,o)},Ba=(e,t)=>{e.beginPath();for(let n of t)n.type==="move"?e.moveTo(n.point.x,n.point.y):n.type==="line"?e.lineTo(n.point.x,n.point.y):e.quadraticCurveTo(n.control.x,n.control.y,n.point.x,n.point.y);e.closePath()},iu=(e,t)=>{Ba(e,t),e.fill()},RE=(e,t)=>{e.save(),Ba(e,t),e.clip(),e.lineWidth=BE*2,e.strokeStyle=`rgba(0, 0, 0, ${vE})`,Ba(e,t),e.stroke(),e.restore()},Ar=(e,t,n,i)=>{switch(e.type){case"stickynote":{n.save(),n.fillStyle=`rgba(0, 0, 0, ${LE})`,iu(n,Xs(e,{shadow:!0}));let o=Xs(e);n.fillStyle=ci(e.backgroundColor,i.theme===mn.DARK),iu(n,o),RE(n,o);let r=Od(e);r&&(n.font=`${Da.fontSize}px ${Da.fontFamily}`,n.textAlign="right",n.textBaseline="alphabetic",n.fillStyle=ci(e.strokeColor,i.theme===mn.DARK),n.globalAlpha*=Da.opacity,n.fillText(r.text,r.x,r.y)),n.restore();break}case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(Qe.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Qe.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=Qe.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=ci(e.strokeColor,i.theme===mn.DARK),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=ei(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,cn(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===mn.DARK&&o?.mimeType===La.svg;if(c&&DE){let u=window.devicePixelRatio||1,p=document.createElement("canvas");p.width=e.width*u,p.height=e.height*u;let m=p.getContext("2d");if(m){m.scale(u,u),m.drawImage(r,s,a,l,d,0,0,e.width,e.height);let h=m.getImageData(0,0,p.width,p.height),f=h.data;for(let g=0;g<f.length;g+=4)f[g]=255-f[g],f[g+1]=255-f[g+1],f[g+2]=255-f[g+2];m.putImageData(h,0,0),n.drawImage(p,0,0,p.width,p.height,0,0,e.width,e.height)}}else c&&(n.filter=SE),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else FE(e,n,i.theme);n.restore();break}default:if($(e)){let o=ME(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=IE(e),n.fillStyle=ci(e.strokeColor,i.theme===mn.DARK),n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
13
+ `).split(`
14
+ `),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=ar(e.fontSize,e.lineHeight),d=TE(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}`)}},go=new WeakMap,ou=(e,t,n,i)=>{let o=n?i.zoom:CE,r=go.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=Ne(e)?e.crop:null,l=Hn(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.imageCrop!==a||r.containingFrameOpacity!==l){let d=au(e,t,o,n,i);return d?(go.set(e,d),d):null}return r},cu=(e,t)=>!t?.shouldCacheIgnoreZoom&&(!e.angle||yE(e.angle)),ru=1e-6,va=(e,t,n,i,o,r)=>{let s=e.element,a=window.devicePixelRatio,l=ho(s),[d,c,u,p]=q(s,o),m=((d+u)/2+r.x+i.scrollX)*a,h=((c+p)/2+r.y+i.scrollY)*a;t.save(),t.scale(1/a,1/a);let f=J(s,o);if(W(s)&&f){let[,,,,b,y]=q(f,o),w=Math.max(Yn(d,u),Yn(c,p))*a+l*10;t.beginPath(),t.rect(m-w,h-w,w*2,w*2),t.rect((b-f.width/2-Wn+r.x+i.scrollX)*a,(y-f.height/2-Wn+r.y+i.scrollY)*a,(f.width+Wn*2)*a,(f.height+Wn*2)*a),t.clip("evenodd")}t.translate(m,h),t.rotate(s.angle),"scale"in e.element&&!kE(s,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-m,-h);let g=(d+r.x+i.scrollX)*a-l,E=(c+r.y+i.scrollY)*a-l,x=t.getTransform();if(cu(s,i)){let{a:b,b:y,c:w,d:S,e:I,f:A}=x,T=$(s)?Oe(s,o):null,O=T&&!T.angle?T:s,v=O===s?null:q(O,o),N=v?.[0]??d,k=v?.[1]??c,z=O===s?l:ho(O),U=(N+r.x+i.scrollX)*a-z,D=(k+r.y+i.scrollY)*a-z,B=(d-N)*a+z-l,P=(c-k)*a+z-l;t.setTransform(b,y,w,S,Math.round(b*U+w*D+I)+Math.round(b*B+w*P+ru),Math.round(y*U+S*D+A)+Math.round(y*B+S*P+ru)),g=0,E=0}if(t.drawImage(e.canvas,g,E,e.canvas.width/e.scale,e.canvas.height/e.scale),t.setTransform(x),G.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&Wt(s)){let b=J(s,o),y=zs(s);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((y.x+r.x+i.scrollX)*a,(y.y+r.y+i.scrollY)*a,Ct(s,b)*a,ro(s,b)*a)}t.restore()},ET=(e,t,n,i)=>{t.save(),t.translate(e.x+n.scrollX,e.y+n.scrollY),t.fillStyle=ci("rgba(0, 0, 200, 0.04)",n.theme===mn.DARK);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()},xT=(e,t,n,i,o,r,s,a=OE(e,t,r,n))=>{let l=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];o.save(),o.globalAlpha=a.opacity*(l?wE:1),(r.isExporting||Q(e))&&(a.offset.x||a.offset.y)&&o.translate(a.offset.x,a.offset.y);try{zE(e,t,n,i,o,r,s,a)}finally{o.restore()}},zE=(e,t,n,i,o,r,s,a)=>{switch(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=Tr.strokeWidth/s.zoom.value,o.strokeStyle=ci(Tr.strokeColor,s.theme===mn.DARK),od(e)&&(o.strokeStyle=s.theme===mn.LIGHT?"#7affd7":ci("#1d8264")),Tr.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Tr.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]=q(e,t),p=(l+c)/2+s.scrollX,m=(d+u)/2+s.scrollY,h=(c-l)/2-(e.x-l),f=(u-d)/2-(e.y-d);o.save(),o.translate(p,m),o.rotate(e.angle),o.translate(-h,-f),Ar(e,i,o,r),o.restore()}else{let l=ou(e,n,r,s);if(!l)return;va(l,o,r,s,n,a.offset)}break}case"rectangle":case"stickynote":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=q(e,t),p=(l+c)/2,m=(d+u)/2,h=p+s.scrollX,f=m+s.scrollY,g=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);if($(e)){let b=Oe(e,t);if(W(b)){let y=R.getBoundTextElementPosition(b,e,t);g=(c-l)/2-(y.x-l),E=(u-d)/2-(y.y-d)}}o.save(),o.translate(h,f);let x=J(e,t);if(W(e)&&x){g=e.width/2-(e.x-l),E=e.height/2-(e.y-d);let[,,,,b,y]=q(x,t),w=b-p-x.width/2-Wn,S=y-m-x.height/2-Wn,I=x.width+Wn*2,A=x.height+Wn*2,T=Math.max(Yn(l,c),Yn(d,u))+ho(e)*10;o.save(),o.beginPath(),o.rect(-T,-T,T*2,T*2),o.rect(w,S,I,A),o.clip("evenodd"),o.rotate(e.angle),o.translate(-g,-E),Ar(e,i,o,r),o.restore()}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-g,-E),Ar(e,i,o,r);o.restore()}else{let l=ou(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(cu(e,s)&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&Ne(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=au(td(l.element,t),n,s.zoom,r,s);c&&va(c,o,r,s,n,su),o.restore()}va(l,o,r,s,n,a.offset),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}};function bT(e,t,n){let i=ae({...e,angle:0},n),o=Mr((i[0]+i[2])/2,(i[1]+i[3])/2);return AE(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(nu(r[r.length-1][1],Aa(Mr(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[nu(Aa(Mr(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),Aa(Mr(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}var Qe=class e{static rg=new bt;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),go.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;go.delete(t);let o=VE(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:WE.white,embedsValidationStatus:null,theme:ka.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||ka.LIGHT}),o}},jE=e=>[8,8+e],gu=e=>[1.5,6+e];function $E(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&&jd(e.type)||ee(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var ht=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?jE(e.strokeWidth):e.strokeStyle==="dotted"?gu(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:$E(e),stroke:bo(e.strokeColor,n),preserveVertices:t||e.roughness<HE.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=xo(e.backgroundColor)?void 0:bo(e.backgroundColor,n),e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return Nt(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:bo(e.backgroundColor,n)),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},mu=(e,t,n)=>jo(e)&&(t||id(e)&&n?.get(e.id)!==!0)&&xo(e.backgroundColor)&&xo(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:Xo(e)?{...e,strokeColor:xo(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:xo(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Eo=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},Dr=(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)]},ui=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=gu(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},Ca=(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)]},pu=(e,t,n,i,o,r,s,a)=>{if(i===null)return[];let l=bo(e.strokeColor,a),d=bo(s,a),c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return Ca(o,r,l,rt(e,t,n,i),i==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let p=rt(e,t,n,i);if(p===null)return[];let[m,h,f,g,E,x]=p,b={...r,fill:i==="triangle_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete b.strokeLineDash,[o.polygon([[m,h],[f,g],[E,x],[m,h]],b)]}case"diamond":case"diamond_outline":{let p=rt(e,t,n,i);if(p===null)return[];let[m,h,f,g,E,x,b,y]=p,w={...r,fill:i==="diamond_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete w.strokeLineDash,[o.polygon([[m,h],[f,g],[E,x],[b,y],[m,h]],w)]}case"cardinality_one":return Eo(o,rt(e,t,n,i),ui(e,r));case"cardinality_many":return Dr(o,rt(e,t,n,i),ui(e,r));case"cardinality_one_or_many":{let p=ui(e,r);return[...Dr(o,rt(e,t,n,"cardinality_many"),p),...Eo(o,rt(e,t,n,"cardinality_one",c),p)]}case"cardinality_exactly_one":{let p=ui(e,r);return[...Eo(o,rt(e,t,n,"cardinality_one",-.5),p),...Eo(o,rt(e,t,n,"cardinality_one"),p)]}case"cardinality_zero_or_one":{let p=ui(e,r);return[...Ca(o,r,l,rt(e,t,n,"circle_outline",1.5),d,u),...Eo(o,rt(e,t,n,"cardinality_one",-.5),p)]}case"cardinality_zero_or_many":{let p=ui(e,r);return[...Dr(o,rt(e,t,n,"cardinality_many"),p),...Ca(o,r,l,rt(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return Dr(o,rt(e,t,n,i),ui(e,r))}},Eu=e=>Pn(e.points,.75),fu=new WeakMap,sc=e=>{let t=fu.get(e);if(t?.version===e.version)return t.polygon;let n=new bt().curve(Eu(e),{roughness:0,disableMultiStroke:!0}).sets[0].ops,i=[];for(let{data:r}of n)for(let s=0;s<r.length;s+=2)i.push(Ce(r[s],r[s+1]));let o=_E(Et(i,.5));return fu.set(e,{version:e.version,polygon:o}),o},Xd=(e,t)=>{let n=new bt,i={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=re(e,t);switch(e.type){case"line":case"arrow":{let r=e.points.length?e.points:[Ce(0,0)];return X(e)?n.path(xu(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=ki(Ce(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:Ce(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[ki(Ce(e.x+s.data[0],e.y+s.data[1]),o,e.angle),ki(Ce(e.x+s.data[2],e.y+s.data[3]),o,e.angle),ki(Ce(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>Ce(l[0]-e.x,l[1]-e.y)).flat()}}):r.map((s,a)=>{let l=ki(Ce(e.x+s[0],e.y+s[1]),o,e.angle);return{op:a===0?"move":"lineTo",data:Ce(l[0]-e.x,l[1]-e.y)}})}case"freedraw":{let r=yu(e);if(r.length<2)return[];let s=e.strokeOptions?.variability==="constant"?Pn(r,Na.COLLISION_SIMPLIFY_TOLERANCE):r;if(s.length<2)return[];let[a,l]=s[0],[d,c]=s[s.length-1];return(a===d&&l===c?s:[...s,s[0]]).map((p,m)=>{let h=ki(Ce(e.x+p[0],e.y+p[1]),o,e.angle);return{op:m===0?"move":"lineTo",data:Ce(h[0]-e.x,h[1]-e.y)}})}}},VE=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===ka.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=cn(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`,ht(mu(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,ht(mu(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,p,m,h,f]=Di(e);if(e.roundness){let g=cn(Math.abs(l-h),e),E=cn(Math.abs(u-d),e);a=t.path(`M ${l+g} ${d+E} L ${c-g} ${u-E}
15
+ C ${c} ${u}, ${c} ${u}, ${c-g} ${u+E}
16
+ L ${p+g} ${m-E}
17
+ C ${p} ${m}, ${p} ${m}, ${p-g} ${m-E}
18
+ L ${h+g} ${f+E}
19
+ C ${h} ${f}, ${h} ${f}, ${h+g} ${f-E}
20
+ L ${l-g} ${d+E}
21
+ C ${l} ${d}, ${l} ${d}, ${l+g} ${d+E}`,ht(e,!0,s))}else a=t.polygon([[l,d],[c,u],[p,m],[h,f]],ht(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,ht(e,!1,s));case"line":case"arrow":{let a,l=ht(e,!1,s),d=e.points.length?e.points:[Ce(0,0)];if(X(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(xu(d,16),ht(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 p=pu(e,a,"start",c,t,l,i,s);a.push(...p)}if(u!==null){let p=pu(e,a,"end",u,t,l,i,s);a.push(...p)}}return a}case"freedraw":{let a=[];return Nt(e.points)&&a.push(t.curve(Eu(e),{...ht(e,!1,s),stroke:"none"})),a.push(KE(e)),a}case"stickynote":case"frame":case"magicframe":case"text":case"image":return null;default:return UE(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},xu=(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=Lt(a,r),d=Lt(s,a),c=Math.min(t,uu(e[o],s)/2,uu(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(" ")},bu=(e,t)=>{switch(e.type){case"rectangle":case"stickynote":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Gl(e);case"arrow":case"line":{let n=Qe.generateElementShape(e,null)[0],[,,,,i,o]=q(e,t);return gr(e)?_l(e,n,Ce(e.x,e.y),e.angle,Ce(i,o)):Rl(n,Ce(e.x,e.y),e.angle,Ce(i,o))}case"ellipse":return Fl(e);case"freedraw":{let[,,,,n,i]=q(e,t);return zl(e,Ce(n,i),gr(e))}}},Gc=(e,t)=>{let n=[...e.points];if(t){if(!dd(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>YE||n.length<4?n.push(Ce(o[0],o[1])):n[n.length-1]=Ce(o[0],o[1])}return{polygon:t,points:n}},KE=e=>ex(yu(e)),yo={SIZE_FACTOR:4.25,THINNING:.6,SMOOTHING:.5},Na={SIZE_FACTOR:1.4,COLLISION_SIMPLIFY_TOLERANCE:.2},Oa=e=>e.strokeOptions?.streamline??XE,ZE=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 $l(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*yo.SIZE_FACTOR,thinning:yo.THINNING,smoothing:yo.SMOOTHING,streamline:Oa(e),easing:n=>Math.sin(n*Math.PI/2),last:!0})},qE=e=>new Uo({size:e.strokeWidth*Na.SIZE_FACTOR,streamline:Oa(e),simplify:0,sizeMapping:t=>Math.max(.1,t.pressure)}),QE=e=>{let t=qE(e);return e.points.map(([n,i])=>t.addPoint([n,i,1])),t.getStrokeOutline().map(([n,i])=>[n,i])},yu=e=>e.strokeOptions?.variability==="constant"?QE(e):ZE(e),ac=e=>e.strokeOptions?.variability==="constant"?e.strokeWidth*Na.SIZE_FACTOR:e.strokeWidth*yo.SIZE_FACTOR+3,wu=e=>as(e.points,{size:e.strokeWidth*yo.SIZE_FACTOR,streamline:Oa(e),last:!0}).map(t=>t.point),hu=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],JE=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,ex=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,hu(i,r[0]),"L",r[0],"Z"):n.push(i,hu(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(JE,"$1")};var Ra=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&&!ge(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]=q(t,n);if(he(t)){let[c,u,p,m]=mi(t.points.map(([h,f])=>le(F(h,f),F(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,p+t.x,m+t.y]}else if(ee(t))i=cx(t,l,d,n);else if(t.type==="diamond"){let[c,u]=le(F(l,r),F(l,d),t.angle),[p,m]=le(F(l,a),F(l,d),t.angle),[h,f]=le(F(o,d),F(l,d),t.angle),[g,E]=le(F(s,d),F(l,d),t.angle),x=Math.min(c,p,h,g),b=Math.min(u,m,f,E),y=Math.max(c,p,h,g),w=Math.max(u,m,f,E);i=[x,b,y,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),h=Math.hypot(c*p,u*m),f=Math.hypot(u*p,c*m);i=[l-h,d-f,l+h,d+f]}else{let[c,u]=le(F(o,r),F(l,d),t.angle),[p,m]=le(F(o,a),F(l,d),t.angle),[h,f]=le(F(s,a),F(l,d),t.angle),[g,E]=le(F(s,r),F(l,d),t.angle),x=Math.min(c,p,h,g),b=Math.min(u,m,f,E),y=Math.max(c,p,h,g),w=Math.max(u,m,f,E);i=[x,b,y,w]}return i}},q=(e,t,n=!1)=>{if(he(e))return ox(e);if(ee(e))return R.getElementAbsoluteCoords(e,t,n);if($(e)){let i=t?Oe(e,t):null;if(W(i)){let{x:o,y:r}=R.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]},Bi=(e,t)=>{let n=bu(e,t),[i,o,r,s,a,l]=q(e,t),d=F(a,l);if(n.type==="polycurve"){let E=n.data.map(b=>Et(b,10)),x=[];if(Re(e)&&!e.polygon||W(e))for(let b of E){let y=0;for(;y<b.length-1;)x.push(we(F(b[y][0],b[y][1]),F(b[y+1][0],b[y+1][1]))),y++}else{let b=E.flat(),y=0;for(;y<b.length-1;)x.push(we(F(b[y][0],b[y][1]),F(b[y+1][0],b[y+1][1]))),y++}return x}else{if(n.type==="polyline")return n.data;if(nx(e)){let[g,E]=Mn(e),x=E.map(y=>Iu(y,d,e.angle)).flat();return[...Su(g,d,e.angle),...x]}else if(e.type==="diamond"){let[g,E]=Tn(e),x=E.map(y=>Iu(y,d,e.angle)).flat();return[...Su(g,d,e.angle),...x]}else if(n.type==="polygon"){if($(e)){let x=Oe(e,t);if(x&&ee(x))return[we(F(i,o),F(r,o)),we(F(r,o),F(r,s)),we(F(r,s),F(i,s)),we(F(i,s),F(i,o))]}let g=n.data,E=[];for(let x=0;x<g.length-1;x++)E.push(we(g[x],g[x+1]));return E}else if(n.type==="ellipse")return ix(e)}let[c,u,p,m,,,h,f]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(g=>le(g,d,e.angle));return[we(c,u),we(p,m),we(c,p),we(u,m),we(c,f),we(p,f),we(u,h),we(m,h)]},nx=e=>e!=null&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),Su=(e,t,n)=>e.map(i=>we(le(i[0],t,n),le(i[1],t,n))),Iu=(e,t,n)=>{let i=Et(e,10),o=0,r=[];for(;o<i.length-1;)r.push(we(le(F(i[o][0],i[o][1]),t,n),le(F(i[o+1][0],i[o+1][1]),t,n))),o++;return r},ix=e=>{let t=F(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(le(F(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(we(r[l],r[l+1]));return o.push(we(r[r.length-1],r[0])),o},QT=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Di=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]},Mu=(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},Tu=(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 p=null,m=null,h=1/0,f=1/0;return a===0?h=f=-d/l:(h=(-l+Math.sqrt(c))/(2*a),f=(-l-Math.sqrt(c))/(2*a)),h>=0&&h<=1&&(p=Mu(h,e,t,n,i)),f>=0&&f<=1&&(m=Mu(f,e,t,n,i)),[p,m]},Er=(e,t,n,i)=>{let o=Tu(e[0],t[0],n[0],i[0]),r=Tu(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]},fo=(e,t)=>{let n=F(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=Du(d);Fa(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=F(d[0],d[1]),u=F(d[2],d[3]),p=F(d[4],d[5]),m=t?t(c):c,h=t?t(u):u,f=t?t(p):p,g=t?t(n):n;n=p;let[E,x,b,y]=Er(g,m,h,f);a.minX=Math.min(a.minX,E),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,b),a.maxY=Math.max(a.maxY,y)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},mi=(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]},ox=e=>{let[t,n,i,o]=mi(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]},rx=20,sx=15,ax=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 sx;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return rx;default:return 15}},lx=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},rt=(e,t,n,i,o=0)=>{if(i===null||t.length<1)return null;let r=Jt(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;Fa(a.length===6,"Op data length is not 6");let l=F(a[4],a[5]),d=F(a[2],a[3]),c=F(a[0],a[1]),u=r[s-1],p=F(0,0);if(u.op==="move"){let P=Du(u.data);Fa(P!=null,"Op data is not a point"),p=P}else u.op==="bcurveTo"&&(p=F(u.data[4],u.data[5]));let m=(P,L)=>Math.pow(1-P,3)*l[L]+3*P*Math.pow(1-P,2)*d[L]+3*Math.pow(P,2)*(1-P)*c[L]+p[L]*Math.pow(P,3),[h,f]=n==="start"?p:l,[g,E]=[m(.3,0),m(.3,1)],x=Math.hypot(h-g,f-E),b=(h-g)/x,y=(f-E)/x,w=ax(i),S=0;{let[P,L]=n==="end"?e.points[e.points.length-1]:e.points[0],[C,_]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];S=Math.hypot(P-C,L-_)}let A=Math.min(w,S*(i==="diamond"||i==="diamond_outline"?.25:.5)),T=h-b*A*o,O=f-y*A*o,v=T-b*A,N=O-y*A;if(i==="circle"||i==="circle_outline"){let P=Math.hypot(N-O,v-T)+e.strokeWidth-2;return[T,O,P]}let k=lx(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[P,L]=le(F(T,O),F(v,N),Ga(-k)),[C,_]=le(F(T,O),F(v,N),Ga(k));return[v,N,P,L,C,_]}let[z,U]=le(F(v,N),F(T,O),-k*Math.PI/180),[D,B]=le(F(v,N),F(T,O),Ga(k));if(i==="diamond"||i==="diamond_outline"){let P,L;if(n==="start"){let[C,_]=e.points.length>1?e.points[1]:[0,0];[P,L]=le(F(T+A*2,O),F(T,O),Math.atan2(_-O,C-T))}else{let[C,_]=e.points.length>1?e.points[e.points.length-2]:[0,0];[P,L]=le(F(T-A*2,O),F(T,O),Math.atan2(O-_,T-C))}return[T,O,z,U,P,L,D,B]}return[T,O,z,U,D,B]},dx=e=>{let t=xi.generator(),n=ht(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},cx=(e,t,n,i)=>{let o=J(e,i);if(e.points.length<2){let[u,p]=e.points[0],[m,h]=le(F(e.x+u,e.y+p),F(t,n),e.angle),f=[m,h,m,h];if(o){let g=R.getMinMaxXYWithBoundText(e,i,[m,h,m,h],o);f=[g[0],g[1],g[2],g[3]]}return f}let s=Qe.get(e,null)?.[0]??dx(e),a=Jt(s),d=fo(a,([u,p])=>le(F(e.x+u,e.y+p),F(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=R.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},ae=(e,t,n=!1)=>Ra.getBounds(e,t,n),ot=(e,t)=>{if(!tx(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Au(e);return e.forEach(a=>{let[l,d,c,u]=ae(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]},JT=(e,t)=>{let[n,i,o,r]=ot(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},In=(e,t,n,i)=>{if(!(ee(e)||he(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Pu(0,t,Pu(1,n,e.points,i),i),r;if(he(e))r=mi(o);else{let c=xi.generator(),u=e.roundness?c.curve(o,ht(e)):c.linearPath(o,ht(e)),p=Jt(u);r=fo(p)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},ga=(e,t)=>{let n=xi.generator(),i=e.roundness==null?n.linearPath(t,ht(e)):n.curve(t,ht(e)),o=Jt(i),[r,s,a,l]=fo(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},pn=e=>{let[t,n,i,o]=ot(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},eA=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],nn=e=>F(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),ut=(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=re(e,t),[r,s]=le(F(i.minX,i.minY),o,e.angle),[a,l]=le(F(i.maxX,i.minY),o,e.angle),[d,c]=le(F(i.maxX,i.maxY),o,e.angle),[u,p]=le(F(i.minX,i.maxY),o,e.angle),m=[Math.min(r,a,d,u),Math.min(s,l,c,p),Math.max(r,a,d,u),Math.max(s,l,c,p)];if(n){let[h,f,g,E]=n;return[m[0]-E,m[1]-h,m[2]+f,m[3]+g]}return m},Xt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],ux=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],yt=(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},Ta=(e,t)=>[F(t[0],t[1]),F(t[0],t[3]),F(t[2],t[1]),F(t[2],t[3])].every(n=>ux(n,e)),Xc=({elements:e,elementsMap:t,bounds:n,type:i,excludeElementsInFrames:o,shouldIgnoreElementFromSelection:r})=>{t||(t=Au(e));let s=sd(n)?ae(n,t):n,[a,l,d,c]=s,u=[we(F(a,l),F(d,l)),we(F(d,l),F(d,c)),we(F(d,c),F(a,c)),we(F(a,c),F(a,l))],p=o?new Set:null,m={},h=new Set;for(let f of e){if(r?.(f))continue;let g=f.groupIds.at(-1);g&&(m[g]||(m[g]=[]),m[g].push(f));let E=f.strokeWidth,x=null,b=ae(f,t);b=[b[0]-E/2,b[1]-E/2,b[2]+E/2,b[3]+E/2];let y=W(f)&&J(f,t);if(y){let{x:I,y:A}=R.getBoundTextElementPosition(f,y,t);x=[I,A,I+y.width,A+y.height]}let w=Hn(f,t);if(w&&_n(f,w,t)){let I=ae(w,t);b=[Math.max(b[0],I[0]),Math.max(b[1],I[1]),Math.min(b[2],I[2]),Math.min(b[3],I[3])],x=x?[Math.max(x[0],I[0]),Math.max(x[1],I[1]),Math.min(x[2],I[2]),Math.min(x[3],I[3])]:null}let S=x?[Math.min(x[0],b[0]),Math.min(x[1],b[1]),Math.max(x[2],b[2]),Math.max(x[3],b[3])]:b;if(Ta(s,S)){p&&Q(f)&&p.add(f.id),h.add(f);continue}if(i==="overlap"&&x&&yt(s,x)){h.add(f);continue}if(i==="overlap"&&yt(s,b)){let I=!1;if(ee(f)||he(f)){let A=re(f,t);I=f.points.some(T=>{let O=le(F(f.x+T[0],f.y+T[1]),A,f.angle);return Xt(O,s)})}else{let A=ae(f,t,!0),T=re(f,t);I=[le(F((A[0]+A[2])/2,A[1]),T,f.angle),le(F(A[2],(A[1]+A[3])/2),T,f.angle),le(F((A[0]+A[2])/2,A[3]),T,f.angle),le(F(A[0],(A[1]+A[3])/2),T,f.angle)].some(O=>Xt(le(O,T,f.angle),s))}if(I||(I=u.some(A=>pt(f,t,A,E/2,!0).length>0)),I){p&&Q(f)&&p.add(f.id),h.add(f);continue}}}return p&&h.forEach(f=>{f.frameId&&p.has(f.frameId)&&h.delete(f)}),i==="overlap"?Array.from(h).forEach(f=>{let g=f.groupIds.at(-1);(g?m[g]:null)?.forEach(x=>h.add(x))}):i==="contain"&&h.forEach(f=>{let g=f.groupIds.at(-1),E=g?m[g]:null;E&&!E.every(x=>h.has(x))&&h.delete(f)}),e.filter(f=>h.has(f))},re=(e,t,n=0,i=0)=>{if(ee(e)||he(e)){let[s,a,l,d]=q(e,t),[c,u]=F((s+l)/2,(a+d)/2);return F(c+n,u+i)}let[o,r]=nn(ae(e,t));return F(o+n,r+i)};var so=(e,t,n="top")=>{let i=(e.height-t)/2;if(n==="center")return{x:e.x,y:e.y+i};let o=Math.sin(e.angle),r=Math.cos(e.angle);return n==="bottom"?{x:e.x-i*o,y:e.y+i*(1+r)}:{x:e.x+i*o,y:e.y+i*(1-r)}},hx=.1,Bu=e=>ee(e)||he(e)?e.points.length<2||e.points.length===2&&W(e)&&fx(e.points[0],e.points[e.points.length-1],hx):e.width===0&&e.height===0,jc=(e,t,n,i,o)=>{let[r,s,a,l]=ae(e,o),d=vr({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=vr({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},lA=(e,t,n,i,o,r)=>{let[s,a,l,d]=ot(e,o),c=vr({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=vr({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},za=(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)/fn)*fn;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}},Fc=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/fn)*fn;if(o){let d=Math.floor(o/fn)*fn;mx(a,d,d+fn)&&(px(a,o)<fn/6?l=o:vu(a)>vu(o)?l=d+fn: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,p=-1/d,m=-1,h=i-p*n,f=(c*h-m*u)/(d*m-p*c),g=(u*p-h*d)/(d*m-p*c);r=f-e,s=g-t}return{width:r,height:s}},dA=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};M();var gA=(e,t,n,i)=>{let o=Pr(e,n.getNonDeletedElementsMap(),i).map(Ci),r=pn(e);return o.flatMap(s=>{let a=gx(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ge(l,n,{simultaneouslyUpdated:s}),d})})},gx=(e,t,{axis:n,position:i})=>{let o=pn(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}};M();import{TEXT_ALIGN as Cr,VERTICAL_ALIGN as kr}from"@excalidraw/common";import{pointDistance as Dx,pointFromVector as vx,pointsEqual as Wu,vector as Bx,vectorDot as Lx,vectorFromPoint as Uu,vectorNormalize as Cx,vectorScale as kx}from"@excalidraw/math";M();import{DEFAULT_ELEMENT_PROPS as Xn,DEFAULT_FONT_FAMILY as Ex,DEFAULT_FONT_SIZE as xx,DEFAULT_TEXT_ALIGN as bx,DEFAULT_STICKY_NOTE_SIZE as yx,STICKY_NOTE_MIN_SIZE as Lu,DEFAULT_VERTICAL_ALIGN as wx,DEFAULT_STROKE_STREAMLINE as Px,VERTICAL_ALIGN as pi,randomInteger as Sx,randomId as Ix,getFontString as wo,getUpdatedTimestamp as Mx,getLineHeight as Tx}from"@excalidraw/common";var Mt=(e,{x:t,y:n,strokeColor:i=Xn.strokeColor,backgroundColor:o=Xn.backgroundColor,fillStyle:r=Xn.fillStyle,strokeWidth:s=Xn.strokeWidth,strokeStyle:a=Xn.strokeStyle,roughness:l=Xn.roughness,opacity:d=Xn.opacity,width:c=0,height:u=0,angle:p=0,groupIds:m=[],frameId:h=null,index:f=null,roundness:g=null,boundElements:E=null,link:x=null,locked:b=Xn.locked,...y})=>{(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:y.points});let w=Mx();return{id:y.id||Ix(),type:e,x:t,y:n,width:c,height:u,angle:p,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:m,frameId:h,index:f,roundness:g,seed:y.seed??Sx(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:E,updated:w,created:y.created===void 0?w:y.created,link:x,locked:b,customData:y.customData}},Ni=e=>Mt(e.type,e),ku=e=>Me(e,{backgroundColor:Ws(e.backgroundColor),strokeColor:Nn(e.strokeColor),fillStyle:"solid"}),_a=e=>{let t=Math.max(e.width,Lu),n=Math.max(e.baseHeight||e.height||yx,Lu);return Me(e,{width:t,height:Math.max(e.height,n),baseHeight:n})},AA=e=>_a(ku(e)),Br=e=>{let t=Mt("stickynote",e);return ku({...t,baseHeight:e.baseHeight??t.height})},Nu=e=>Mt("embeddable",e),Ou=e=>({...Mt("iframe",e)}),Gu=e=>Me({...Mt("frame",e),type:"frame",name:e?.name||null},{}),Fu=e=>Me({...Mt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Ha=e=>({x:e.textAlign==="center"?.5:e.textAlign==="right"?1:0,y:e.verticalAlign===pi.MIDDLE?.5:e.verticalAlign===pi.BOTTOM?1:0}),Ru=(e,t)=>{let n=Ha(e);return{x:t.width*n.x,y:t.height*n.y}},fi=e=>{let t=e.fontFamily||Ex,n=e.fontSize||xx,i=e.lineHeight||Tx(t),o=oo(e.text),r=Ue(o,wo({fontFamily:t,fontSize:n}),i),s=e.textAlign||bx,a=e.verticalAlign||wx,l=Ru({textAlign:s,verticalAlign:a},r),d={...Mt("text",e),text:o,fontSize:n,baseFontSize:e.baseFontSize??null,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,labelPosition:e.labelPosition??null};return Me(d,{})},Cu=(e,t,n,i)=>{let{width:o,height:r}=Ue(n,wo(e),e.lineHeight);i!==void 0?o=i:e.autoResize||(o=e.width);let{textAlign:s,verticalAlign:a}=e,l,d;if(s==="center"&&a===pi.MIDDLE&&!e.containerId&&e.autoResize){let c=Ue(e.text,wo(e),e.lineHeight),u=Ru(e,{width:o-c.width,height:r-c.height});l=e.x-u.x,d=e.y-u.y}else{let[c,u,p,m]=q(e,t),[h,f,g,E]=In(e,o,r,!1),x=(c-h)/2,b=(u-f)/2,y=(p-g)/2,w=(m-E)/2;[l,d]=Ax({n:a===pi.MIDDLE||a===pi.BOTTOM,s:a===pi.MIDDLE||a===pi.TOP,e:s==="center"||s==="left",w:s==="center"||s==="right"},e.x,e.y,e.angle,x,b,y,w)}return{width:o,height:r,x:Number.isFinite(l)?l:e.x,y:Number.isFinite(d)?d:e.y}},Ax=(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]},DA=(e,t,n,i=e.text,o)=>{if(e.isDeleted)return;if(o!==void 0&&!t&&e.autoResize&&e.width<=o){let s=wo(e);if(Ue(i,s,e.lineHeight).width>o){let a=St(i,s,o);return{text:a,autoResize:!1,...Cu(e,n,a,o)}}}(t||!e.autoResize)&&(i=St(i,wo(e),t?Ct(t,e):e.width));let r=Cu(e,n,i);return{text:i,...r}},zu=e=>({...Mt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,strokeOptions:e.strokeOptions??{variability:"variable",streamline:Px}}),_u=e=>{let t={...Mt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Re(t)?{...t,polygon:e.polygon??!1}:t},Lr=e=>e.elbowed?{...Mt(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}:{...Mt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},Hu=e=>({...Mt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var RA=(e,t,n,i)=>{for(let o=t.length-1;o>=0;o--){let r=t[o];if(!(!W(r)||r.locked||r.points.length<2))for(let s of["end","start"]){if(r[s==="start"?"startBinding":"endBinding"]||Wu(r.points[s==="start"?0:r.points.length-1],r.points[s==="start"?1:r.points.length-2]))continue;let a=R.getPointAtIndexGlobalCoordinates(r,s==="start"?0:-1,n);if(Dx(e,a)*i.value<R.POINT_HANDLE_SIZE+1)return{arrow:r,startOrEnd:s}}}return null},zA=(e,t,n,i)=>{let o=R.getPointAtIndexGlobalCoordinates(e,t==="start"?0:-1,n),r=R.getPointAtIndexGlobalCoordinates(e,t==="start"?1:-2,n);if(Wu(o,r))return null;let s=Uu(o,r),a=Math.abs(s[0])>=Math.abs(s[1])?s[0]>=0?Ee:ze:s[1]>=0?ve:qe,l=X(e)?0:Be({strokeWidth:i}),d=Cx(Uu(r,o)),c=Math.abs(Lx(d,Bx(a[0],a[1]))),u=vx(kx(d,-l/c),o);return fe(a,Ee)?{fixedPoint:$e([0,.5]),anchor:u,textAlign:Cr.LEFT,verticalAlign:kr.MIDDLE}:fe(a,ze)?{fixedPoint:$e([1,.5]),anchor:u,textAlign:Cr.RIGHT,verticalAlign:kr.MIDDLE}:fe(a,ve)?{fixedPoint:$e([.5,0]),anchor:u,textAlign:Cr.CENTER,verticalAlign:kr.TOP}:{fixedPoint:$e([.5,1]),anchor:u,textAlign:Cr.CENTER,verticalAlign:kr.BOTTOM}},_A=(e,t)=>!!e.boundElements?.some(({id:n,type:i})=>{if(i!=="arrow")return!1;let o=t.get(n);return W(o)&&(o.startBinding?.elementId===e.id||o.endBinding?.elementId===e.id)}),HA=e=>{let t=Ha(e).x;return{anchorRatio:t,anchorX:e.x+e.width*t}};M();import{distanceToLineSegment as Yu,lineSegment as hi,lineSegmentIntersectionPoints as Nx,pointDistance as Zt,pointFrom as Gi,pointRotateRads as Or,polygonArea as So,polygonIncludesPoint as Xu,polygonIncludesPointNonZero as Nr,polygonSignedArea as Wa}from"@excalidraw/math";import{isOpaqueColor as Ox,isTransparent as Io}from"@excalidraw/common";var Gx=6,Fx=2,Rx=2,zx=.5,_x={snapEpsilon:.5,gapTolerance:Gx,minArea:4,maxBoundarySegments:2560,maxGeneratedPoints:1536,fallbackSearchRadius:512},Ku=([e,t,n,i],o)=>[e-o,t-o,n+o,i+o],Hx=e=>Zt(e[0],e[1]),Po=(e,t,n)=>{let i=t[0]-e[0],o=t[1]-e[1],r=i*i+o*o;return r===0?0:((n[0]-e[0])*i+(n[1]-e[1])*o)/r},ju=(e,t,n,i,o)=>{let r=Math.min(e[0],t[0]),s=Math.max(e[0],t[0]),a=t[0]-e[0],l=t[1]-e[1],d=Math.floor((r-n)/i),c=Math.floor((s+n)/i);for(let u=d;u<=c;u++){let p=e[1],m=t[1];if(a!==0){let g=(Math.max(r,u*i-n)-e[0])/a,E=(Math.min(s,(u+1)*i+n)-e[0])/a;p=e[1]+g*l,m=e[1]+E*l}let h=Math.floor((Math.min(p,m)-n)/i),f=Math.floor((Math.max(p,m)+n)/i);for(let g=h;g<=f;g++)o(u,g)}},Ux=(e,t,n)=>{let i=n[0]-t[0],o=n[1]-t[1],r=Math.hypot(i,o);return r===0?Zt(e,t):Math.abs((e[0]-t[0])*o-(e[1]-t[1])*i)/r},Oi=(e,t,n)=>Gi(e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n),Wx=(e,t)=>{let n=e;for(let[i,o]of t){let r=[];for(let[s,a]of n){if(o<=s||i>=a){r.push([s,a]);continue}i>s&&r.push([s,i]),o<a&&r.push([o,a])}n=r}return n},Yx=(e,t)=>{let n=re(e,t),o=(e.roundness&&e.points.length>2?Et(Fo(e.points),.15,zx):e.points).map(s=>Or(Gi(e.x+s[0],e.y+s[1]),n,e.angle)),r=[];for(let s=0;s<o.length-1;s++)r.push(hi(o[s],o[s+1]));return r},Xx=(e,t)=>{let n=re(e,t),i=wu(e).map(r=>Or(Gi(e.x+r[0],e.y+r[1]),n,e.angle)),o=[];for(let r=0;r<i.length-1;r++)o.push(hi(i[r],i[r+1]));return o},jx=(e,t,n,i,o,r)=>{let s=[[0,1]];for(let a of n){if(s.length===0)break;let d=[0,...pt(a,i,hi(e,t)).map(u=>Po(e,t,u)).filter(u=>u>0&&u<1).sort((u,p)=>u-p),1],c=[];for(let u=0;u<d.length-1;u++){let p=d[u],m=d[u+1];if(m-p<1e-9)continue;let h=Oi(e,t,(p+m)/2);Je(h,a,i)&&tn(a,i,h)>r&&c.push([p,m])}c.length&&(s=Wx(s,c))}return s.filter(([a,l])=>Zt(Oi(e,t,a),Oi(e,t,l))>=o).map(([a,l])=>[Oi(e,t,a),Oi(e,t,l)])},Ya=class{constructor(t){this.eps=t;this.cellSize=Math.max(t,1)}nodes=[];cells=new Map;cellSize;cellKey(t,n){return`${t}:${n}`}getOrCreate(t){let n=Math.floor(t[0]/this.cellSize),i=Math.floor(t[1]/this.cellSize);for(let a=-1;a<=1;a++)for(let l=-1;l<=1;l++){let d=this.cells.get(this.cellKey(n+a,i+l));if(d){for(let c of d)if(Zt(this.nodes[c],t)<=this.eps)return c}}let o=this.nodes.length;this.nodes.push(t);let r=this.cellKey(n,i),s=this.cells.get(r);return s?s.push(o):this.cells.set(r,[o]),o}forEachInRadius(t,n,i){let o=Math.floor((t[0]-n)/this.cellSize),r=Math.floor((t[0]+n)/this.cellSize),s=Math.floor((t[1]-n)/this.cellSize),a=Math.floor((t[1]+n)/this.cellSize);for(let l=o;l<=r;l++)for(let d=s;d<=a;d++){let c=this.cells.get(this.cellKey(l,d));if(c)for(let u of c)i(u)}}},$u=e=>!(!oi(e.type)||e.fillStyle!=="solid"||e.opacity<100||!Ox(e.backgroundColor)||(Re(e)||he(e))&&!Nt(e.points)),Zu=new Set(["rectangle","diamond","ellipse","frame","magicframe","line","freedraw"]),Xa=e=>e.opacity<=0,qu=e=>!Xa(e)&&(e.type==="image"||!Io(e.strokeColor)||oi(e.type)&&!Io(e.backgroundColor)),Qu=e=>Re(e)&&e.polygon&&ps(e.points)&&!Xa(e)&&!Io(e.backgroundColor)&&Io(e.strokeColor),$x=e=>Zu.has(e.type)?Re(e)?e.polygon&&ps(e.points):he(e)?Nt(e.points):!0:!1,Ua=e=>!Xa(e)&&Zu.has(e.type)&&!Io(e.strokeColor),Vx=(e,t,n)=>{for(let i=t.length-1;i>=0;i--){let o=t[i];if(!(!qu(o)||Qu(o))&&$x(o)&&Je(e,o,n))return o}return null},Kx=(e,t)=>{let n=t.snapEpsilon,i=new Ya(n),o=[],r=new Map;for(let{segment:D,elementId:B}of e){let P=i.getOrCreate(D[0]),L=i.getOrCreate(D[1]);if(r.has(P)||r.set(P,B),r.has(L)||r.set(L,B),P===L)continue;let C=i.nodes[P],_=i.nodes[L];o.push({a:P,b:L,pa:C,pb:_,elementId:B,box:[Math.min(C[0],_[0]),Math.min(C[1],_[1]),Math.max(C[0],_[0]),Math.max(C[1],_[1])],splits:[{node:P,t:0},{node:L,t:1}]})}let s=o.map(D=>hi(D.pa,D.pb)),a=o.map((D,B)=>B).sort((D,B)=>o[D].box[0]-o[B].box[0]);for(let D=0;D<a.length;D++){let B=a[D],P=o[B],L=P.box[2]+n;for(let C=D+1;C<a.length;C++){let _=a[C],K=o[_];if(K.box[0]>L)break;if(!yt(Ku(P.box,n),K.box))continue;let te=Nx(s[B],s[_],n);if(!te)continue;let ne=i.getOrCreate(te);r.has(ne)||r.set(ne,P.elementId),P.splits.push({node:ne,t:Po(P.pa,P.pb,i.nodes[ne])}),K.splits.push({node:ne,t:Po(K.pa,K.pb,i.nodes[ne])})}}if(i.nodes.length>t.maxBoundarySegments*4)return null;let l=1/0,d=1/0,c=-1/0,u=-1/0;for(let D of o)l=Math.min(l,D.box[0]),d=Math.min(d,D.box[1]),c=Math.max(c,D.box[2]),u=Math.max(u,D.box[3]);let p=Math.max(c-l,u-d,0),m=Math.max(n*2,p/128),h=new Map;o.forEach((D,B)=>{ju(D.pa,D.pb,n,m,(P,L)=>{let C=`${P}:${L}`,_=h.get(C);_?_.push(B):h.set(C,[B])})});for(let D=0;D<i.nodes.length;D++){let B=i.nodes[D],P=h.get(`${Math.floor(B[0]/m)}:${Math.floor(B[1]/m)}`);if(P)for(let L of P){let C=o[L];if(D===C.a||D===C.b)continue;let _=Po(C.pa,C.pb,B);_<=0||_>=1||Yu(B,s[L])<=n&&C.splits.push({node:D,t:_})}}let f=new Set,g=new Map,E=new Map,x=(D,B)=>D<B?`${D}-${B}`:`${B}-${D}`,b=(D,B)=>{let P=g.get(D);P?P.push(B):g.set(D,[B])},y=(D,B,P)=>{if(D===B||Zt(i.nodes[D],i.nodes[B])<n)return;let L=x(D,B),C=E.get(L);C?C.add(P):E.set(L,new Set([P])),!f.has(L)&&(f.add(L),b(D,B),b(B,D))};for(let D of o){let B=new Map;for(let L of D.splits)B.has(L.node)||B.set(L.node,L.t);let P=[...B.entries()].map(([L,C])=>({node:L,t:C})).sort((L,C)=>L.t-C.t);for(let L=0;L<P.length-1;L++)y(P[L].node,P[L+1].node,D.elementId)}if(f.size===0)return[];let w=Math.max(n,t.gapTolerance),S=D=>new Set(g.get(D)??[]).size===1,I=[];for(let D of g.keys())S(D)&&I.push(D);if(I.length>0){let D=Math.max(w,p/128,1),B=new Map,P=(C,_)=>{let K={u:C,v:_};ju(i.nodes[C],i.nodes[_],0,D,(te,ne)=>{let ie=`${te}:${ne}`,Ae=B.get(ie);Ae?Ae.push(K):B.set(ie,[K])})};for(let C of f){let[_,K]=C.split("-").map(Number);P(_,K)}let L=(C,_)=>{let K=x(C,_);f.delete(K);let te=E.get(K);E.delete(K);let ne=g.get(C),ie=g.get(_);return ne?.splice(ne.indexOf(_),1),ie?.splice(ie.indexOf(C),1),te};for(let C of I){if(!S(C))continue;let _=i.nodes[C],K=g.get(C)??[],te=-1,ne=1/0;i.forEachInRadius(_,w,ke=>{if(ke===C||K.includes(ke))return;let De=Zt(_,i.nodes[ke]);De>=n&&De<=w&&De<ne&&(ne=De,te=ke)});let ie=null,Ae=1/0,_t=0,Ht=Math.floor(_[0]/D),bn=Math.floor(_[1]/D),pe=new Set;for(let ke=-1;ke<=1;ke++)for(let De=-1;De<=1;De++){let Ze=B.get(`${Ht+ke}:${bn+De}`);if(Ze)for(let qt of Ze){let gi=x(qt.u,qt.v);if(pe.has(gi)||(pe.add(gi),!f.has(gi)||qt.u===C||qt.v===C))continue;let yl=i.nodes[qt.u],wl=i.nodes[qt.v],Kr=Po(yl,wl,_);if(Kr<=0||Kr>=1)continue;let Zr=Yu(_,hi(yl,wl));Zr<=w&&Zr<Ae&&(Ae=Zr,ie=qt,_t=Kr)}}let oe=r.get(C)??o[0].elementId;if(ie&&Ae<ne){let ke=i.nodes[ie.u],De=i.nodes[ie.v],Ze=i.getOrCreate(Oi(ke,De,_t));if(Ze===ie.u||Ze===ie.v)y(C,Ze,oe),P(C,Ze);else{r.has(Ze)||r.set(Ze,E.get(x(ie.u,ie.v))?.values().next().value??oe);let qt=L(ie.u,ie.v)??new Set([oe]);for(let gi of qt)y(ie.u,Ze,gi),y(Ze,ie.v,gi);P(ie.u,Ze),P(Ze,ie.v),y(C,Ze,oe),P(C,Ze)}}else te>=0&&(y(C,te,oe),P(C,te))}}let A=new Map,T=0;for(let D of g.keys()){if(A.has(D))continue;let B=[D];for(A.set(D,T);B.length;){let P=B.pop();for(let L of g.get(P)??[])A.has(L)||(A.set(L,T),B.push(L))}T++}let O=(D,B)=>Math.atan2(i.nodes[B][1]-i.nodes[D][1],i.nodes[B][0]-i.nodes[D][0]),v=new Map,N=new Map;for(let[D,B]of g){let P=Array.from(new Set(B));P.sort((C,_)=>O(D,C)-O(D,_)),v.set(D,P);let L=new Map;P.forEach((C,_)=>L.set(C,_)),N.set(D,L)}let k=new Set,z=[],U=f.size*2+4;for(let[D,B]of g)for(let P of B){if(k.has(`${D}->${P}`))continue;let L=[],C=D,_=P,K=0;for(;K++<=U;){k.add(`${C}->${_}`),L.push(C);let te=v.get(_),ie=(N.get(_).get(C)-1+te.length)%te.length,Ae=te[ie];if(C=_,_=Ae,C===D&&_===P)break}if(L.length>=3){let te=new Set;for(let ne=0;ne<L.length;ne++){let ie=E.get(x(L[ne],L[(ne+1)%L.length]));if(ie)for(let Ae of ie)te.add(Ae)}z.push({ring:L.map(ne=>i.nodes[ne]),contributors:te,componentId:A.get(D)??-1})}}return z},Zx=(e,t,n)=>{if(e.length===0)return null;let i=1,o=new Map;for(let c of e)o.set(c,-Wa(c.ring,0));let r=null,s=1/0;for(let c of e){let u=o.get(c);if(Math.sign(u)===i)continue;let p=Math.abs(u);p<n.minArea||Nr(t,c.ring)&&p<s&&(s=p,r=c)}if(!r)return null;let a=r,l=e.filter(c=>c.componentId!==a.componentId&&Math.sign(o.get(c))===i&&Math.abs(o.get(c))>=n.minArea&&!Nr(t,c.ring)&&Nr(c.ring[0],a.ring)),d=l.filter(c=>!l.some(u=>u!==c&&Nr(c.ring[0],u.ring)));return{face:a,holes:d}},qx=(e,t)=>{let n=[];for(let i of e)(n.length===0||Zt(n[n.length-1],i)>=t)&&n.push(i);for(;n.length>1&&Zt(n[0],n[n.length-1])<t;)n.pop();return n},Qx=(e,t)=>{if(e.length<=3)return e;let n=[];for(let i=0;i<e.length;i++){let o=n[n.length-1]??e[e.length-1],r=e[(i+1)%e.length];Ux(e[i],o,r)>=t&&n.push(e[i])}return n.length>=3?n:e},Vu=(e,t,n)=>{let i=qx(e,t.snapEpsilon);if(i.length<3)return null;let o=.75,r=Pn(i,o);for(;r.length>n&&o<1e6;)o*=2,r=Pn(i,o);return r.length>n?null:(r=Qx(r,.05),r.length>=3?r:null)},Jx=(e,t)=>{let n=Math.sign(Wa(t,0))===Math.sign(Wa(e,0))?[...t].reverse():t,i=0,o=0,r=1/0;for(let a=0;a<e.length;a++)for(let l=0;l<n.length;l++){let d=Zt(e[a],n[l]);d<r&&(r=d,i=a,o=l)}let s=e.slice(0,i+1);for(let a=0;a<=n.length;a++)s.push(n[(o+a)%n.length]);return s.push(e[i]),s.push(...e.slice(i+1)),s},eb=(e,t,n)=>{let i=Vu(e,n,n.maxGeneratedPoints);if(!i)return null;let o=t.map((s,a)=>({holeRing:s,index:a})).sort((s,a)=>So(a.holeRing,0)-So(s.holeRing,0)),r=[];for(let{holeRing:s,index:a}of o){let l=n.maxGeneratedPoints-i.length-2;if(l<3)break;let d=Vu(s,n,l);d&&(i=Jx(i,d),r.push(a))}return{scenePoints:[...i,i[0]],splicedHoleIndices:r}},tD=e=>{let t={..._x,...e.options},{point:n,elements:i,elementsMap:o}=e,r=Vx(n,i,o),s=new Map;i.forEach((v,N)=>s.set(v.id,N));let a=(v,N)=>{let k=P=>yt(v,ae(P,o)),z=i.filter(P=>P.id!==N?.id&&Ua(P)&&k(P)),U=i.filter(P=>$u(P)&&k(P)),D=[],B=P=>{let L=s.get(P.id)??0,C=U.filter(te=>te.id!==P.id&&(s.get(te.id)??0)>L),_=Math.max(t.snapEpsilon,P.strokeWidth/2,Rx),K=Re(P)?Yx(P,o):he(P)?Xx(P,o):Bi(P,o);if((P.type==="freedraw"||Re(P)&&!P.polygon)&&Nt(P.points)&&K.length>0){let te=K[0][0],ne=K[K.length-1][1];Zt(te,ne)>=t.snapEpsilon&&K.push(hi(ne,te))}for(let te of K){if(D.length>t.maxBoundarySegments)return;if(Hx(te)!==0){if(C.length===0){D.push({segment:te,elementId:P.id});continue}for(let[ne,ie]of jx(te[0],te[1],C,o,t.snapEpsilon,_))D.push({segment:hi(ne,ie),elementId:P.id})}}};for(let P of N?[N,...z]:z){if(D.length>t.maxBoundarySegments)break;B(P)}return D.length>t.maxBoundarySegments?null:D},l=v=>{let N=Kx(v,t);return N?Zx(N,n,t):"too_complex"},d=null;if(r){let v=t.gapTolerance+2+Math.max(r.strokeWidth??1,1),N=Ku(ae(r,o),v),k=a(N,r);if(!k)return{ok:!1,reason:"too_complex"};let z=l(k);if(z==="too_complex")return{ok:!1,reason:"too_complex"};if(!z)return{ok:!1,reason:"open_region"};d=z}else{let v=i.reduce((k,z)=>k+(Ua(z)?1:0),0);if(v===0)return{ok:!1,reason:"no_owner"};let N=t.fallbackSearchRadius;for(let k=0;k<4&&!d;k++,N*=2){let z=[n[0]-N,n[1]-N,n[0]+N,n[1]+N],U=i.reduce((L,C)=>L+(Ua(C)&&yt(z,ae(C,o))?1:0),0),D=k===3||U===v;if(U===0)continue;let B=a(z,null);if(!B)return{ok:!1,reason:"no_owner"};let P=l(B);if(P==="too_complex")return{ok:!1,reason:"no_owner"};if(P&&(D||P.face.ring.every(L=>L[0]>z[0]+t.gapTolerance&&L[1]>z[1]+t.gapTolerance&&L[0]<z[2]-t.gapTolerance&&L[1]<z[3]-t.gapTolerance))&&(d=P),!d&&D)break}if(!d)return{ok:!1,reason:"no_owner"}}let{face:c,holes:u}=d,p=eb(c.ring,u.map(v=>v.ring),t);if(!p)return{ok:!1,reason:"invalid_polygon"};let{scenePoints:m,splicedHoleIndices:h}=p;if(So(m,0)<t.minArea)return{ok:!1,reason:"too_small"};let f=new Set(c.contributors);for(let v of h)for(let N of u[v].contributors)f.add(N);let g=new Set(r?[r.id,...f]:f);for(let v of u)for(let N of v.contributors)g.add(N);let E=m,[x,b,y,w]=mi(m),S=v=>{let[N,k,z,U]=ae(v,o);if(z<x||N>y||U<b||k>w)return!1;let D=[Gi((N+z)/2,(k+U)/2)];if(ee(v)||he(v)){let B=re(v,o),P=Math.max(1,Math.floor(v.points.length/8));for(let L=0;L<v.points.length;L+=P)D.push(Or(Gi(v.x+v.points[L][0],v.y+v.points[L][1]),B,v.angle))}return D.some(B=>Xu(B,E))},I=v=>{let[N,k,z,U]=ae(v,o);if(z<x||N>y||U<b||k>w)return!1;if(Je(n,v,o))return!0;let D=Bi(v,o),B=Math.max(1,Math.floor(D.length/16));for(let L=0;L<D.length;L+=B)if(Xu(D[L][0],E))return!0;let P=Math.max(1,Math.floor(m.length/16));for(let L=0;L<m.length;L+=P)if(Je(m[L],v,o))return!0;return!1},A=null,T=null;for(let v of i)$u(v)&&I(v)&&(T=v),(g.has(v.id)||qu(v)&&S(v))&&(A=A??v);let O=T?{placement:"above",elementId:T.id}:{placement:"below",elementId:(A??i[i.length-1]).id};return{ok:!0,ownerId:r?.id??null,boundaryElementIds:[...f].filter(v=>v!==r?.id),scenePoints:m,insertion:O}},nD=e=>{let{hitElement:t,scenePoints:n,elementsMap:i}=e;if(!Qu(t))return!1;let o=re(t,i),r=t.points.map(b=>Or(Gi(t.x+b[0],t.y+b[1]),o,t.angle)),s=So(r,0),a=So(n,0),l=Math.abs(s-a)<=.05*Math.max(s,a),[d,c,u,p]=mi(r),[m,h,f,g]=mi(n),E=Fx,x=Math.abs(d-m)<=E&&Math.abs(c-h)<=E&&Math.abs(u-f)<=E&&Math.abs(p-g)<=E;return l&&x};M();import{arrayToMap as jb,arrayToObject as hn,assertNever as bm,isDevEnv as gn,isShallowEqual as Ja,isTestEnv as En,randomInteger as xm}from"@excalidraw/common";M();import{assertNever as cb,COLOR_PALETTE as ub,isDevEnv as mb,isTestEnv as pb,randomId as fb,Emitter as nm,toIterable as Ri}from"@excalidraw/common";M();import{ORIG_ID as ob,randomId as em,randomInteger as rb,arrayToMap as tm,castArray as ja,findLastIndex as Fi,getUpdatedTimestamp as sb,isTestEnv as ab}from"@excalidraw/common";M();import{arrayToMap as tb}from"@excalidraw/common";var nb=e=>{let t=(o,r)=>o.groupIds[o.groupIds.length-r-1],n=(o,r)=>{let s=new Map,a=[];for(let l of o){let d=t(l,r);if(d===void 0){a.push(l);continue}let c=s.get(d);c||(c=[],s.set(d,c),a.push(d)),c.push(l)}return a.flatMap(l=>typeof l=="string"?n(s.get(l),r+1):[l])},i=n(e,0);return i.length!==e.length?(console.error("defragmentGroups: lost some elements... bailing!"),e):i},ib=e=>{let t=tb(e),n=new Set;for(let i of e)if(!n.has(i)){if(i.boundElements?.length){n.add(i);for(let o of i.boundElements){let r=t.get(o.id);r&&o.type==="text"&&n.add(r)}continue}i.type==="text"&&i.containerId&&t.get(i.containerId)?.boundElements?.some(o=>o.id===i.id)||n.add(i)}return n.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...n]},Ju=e=>ib(nb(e));var lb=(e,t,n,i)=>{let o=Va(n);return ab()&&db(o,n.id),o.id=em(),o.updated=sb(),o.created=o.updated,i&&(o.seed=rb(),Bs(o)),o.groupIds=Wc(o.groupIds,e,r=>(t.has(r)||t.set(r,em()),t.get(r))),o},xD=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=new Map,u=tm(t),p=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(x=>[x.id,x])),m=e.type==="everything"&&e.preserveFrameChildrenOrder;if(e.type==="in-place")for(let x of Object.keys(e.appState.selectedGroupIds))t.filter(b=>b.groupIds?.includes(x)).forEach(b=>p.set(b.id,b));t=Ju(t);let h=t.slice(),f=x=>{let y=ja(x).reduce((w,S)=>{if(i.has(S.id))return w;i.set(S.id,!0),je(S)||console.error("[NONDELETED][INVARIANT] Element to duplicate should be non-deleted");let I=lb(n.editingGroupId,o,S,e.randomizeSeed);return i.set(I.id,!0),d.set(I.id,I),c.set(S.id,S),a.set(S.id,I.id),l.set(I.id,S.id),s.push(S),r.push(I),w.push(I),w},[]);return Array.isArray(x)?y:y[0]||null},g=(x,b)=>{if(b){if(x>h.length-1){h.push(...ja(b));return}h.splice(x+1,0,...ja(b))}},E=new Set(t.filter(x=>p.has(x.id)&&Q(x)).map(x=>x.id));for(let x of t){if(i.has(x.id)||!p.has(x.id))continue;let b=xa(n,x);if(b){let y=it(t,b).flatMap(S=>Q(S)&&!m?[...zn(t,S.id),S]:[S]),w=Fi(h,S=>S.groupIds?.includes(b));g(w,f(y));continue}if(!(!m&&x.frameId&&E.has(x.frameId))){if(Q(x)){let y=x.id;if(m){g(Fi(h,I=>I.id===y),f(x));continue}let w=zn(t,y),S=Fi(h,I=>I.frameId===y||I.id===y);g(S,f([...w,x]));continue}if(Wt(x)){let y=J(x,u),w=Fi(h,S=>S.id===x.id||"containerId"in S&&S.containerId===x.id);y?g(w,f([x,y])):g(w,f(x));continue}if(ge(x)){let y=Oe(x,u),w=Fi(h,S=>S.id===x.id||S.id===y?.id);y?g(w,f([y,x])):g(w,f(x));continue}g(Fi(h,y=>y.id===x.id),f(x))}}if(yc(r,a,d),qc(h,s,a),e.overrides)for(let x of r){let b=c.get(l.get(x.id));b&&Object.assign(x,e.overrides({duplicateElement:x,origElement:b,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,origElementsMap:c,elementsWithDuplicates:h,origIdToDuplicateId:a,duplicateIdToOrigId:l}},bD=(e,t,n)=>{if(e===!1)return{elements:t,duplicatedElements:[]};if(!e)return{elements:t,duplicatedElements:n};let i=tm(n),o=new Map;for(let d of e)i.has(d.id)&&o.set(d.id,d);let r=new Set;for(let[d,c]of o){let u=i.get(d);c!==u&&(Object.assign(u,c),Qe.delete(u),Bs(u)),u.isDeleted||r.add(d)}let s=d=>i.has(d)&&!r.has(d);for(let d of r){let c=i.get(d);ge(c)&&s(c.containerId)&&r.delete(d)}let a=[];for(let d of e){let c=i.get(d.id);c?r.has(d.id)&&o.get(d.id)===d&&a.push(c):a.push(d)}if(r.size===n.length)return{elements:a,duplicatedElements:n};let l=n.filter(d=>r.has(d.id));for(let d of l){let c={};d.boundElements?.some(u=>s(u.id))&&(c.boundElements=d.boundElements.filter(u=>!s(u.id))),d.frameId&&s(d.frameId)&&(c.frameId=null),W(d)&&(d.startBinding&&s(d.startBinding.elementId)&&(c.startBinding=null),d.endBinding&&s(d.endBinding.elementId)&&(c.endBinding=null)),Object.assign(d,c)}return{elements:a,duplicatedElements:l}},$a=(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]=$a(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=$a(e[i],t+1);return o}return G.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},Va=e=>$a(e),db=(e,t)=>{Object.defineProperty(e,ob,{value:t,writable:!1,enumerable:!1})};var gt={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},im=class{constructor(t){this.app=t}onDurableIncrementEmitter=new nm;onStoreIncrementEmitter=new nm;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Vn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(gt.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=Vn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?Kc(t.elements):void 0,t.appState);i=Mo.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=Vn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=Mo.create(o,t),i?s=i:s=qa.calculate(o,t),!s.isEmpty()){let a=new Ka(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=Mo.create(r,t)}let o=new Za(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===gt.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 gt.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case gt.NEVER:case gt.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:cb(n,"Unknown store action")}}finally{switch(n){case gt.IMMEDIATELY:case gt.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(gt.IMMEDIATELY)?t=gt.IMMEDIATELY:this.scheduledMacroActions.has(gt.NEVER)?t=gt.NEVER:t=gt.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(gt).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()),pb()||mb())throw new Error(t)}}},Mo=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)}},Gr=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Ka=class extends Gr{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},Za=class extends Gr{constructor(n){super("ephemeral",n);this.change=n}},qa=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:fb()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?$n.calculate(t.elements,n.elements):$n.empty(),o=n.metadata.didAppStateChange?jn.calculate(t.appState,n.appState):jn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,$n.restore(i),jn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=$n.create(n,i,o),a=jn.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,Vn.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($n.empty(),jn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Vn=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,om(n)?n:zi(n),i)}static empty(){return new e(new Map,hb(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of Ri(t.elements))this.elements.get(i.id)||(n[i.id]=Me(i,{isDeleted:!0}));for(let i of Ri(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return V.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=zi({...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===gt.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=om(t)?t:zi(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=V.isRightDifferent(this.appState,t);if(!i)return;let o=am(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 Ri(this.elements))t.get(r.id)||i.set(r.id,Me(r,{isDeleted:!0}));for(let r of Ri(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(Ne(r)&&!ei(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=sm(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of Ri(this.elements))n.set(i.id,i);for(let i of Ri(t))n.set(i.id,Va(i));return n}},rm="__observedAppState",hb=()=>({name:null,editingGroupId:null,viewBackgroundColor:ub.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),zi=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,rm,{value:!0,enumerable:!1}),t},om=e=>!!Reflect.get(e,rm);M();var Em=bp(mm(),1);import{randomInteger as kb,arrayToMap as Nb,toBrandedType as pm,isDevEnv as fm,isTestEnv as hm,toArray as Ob}from"@excalidraw/common";import{isNonDeletedElement as Gb}from"@excalidraw/element";import{isFrameLikeElement as Fb}from"@excalidraw/element";import{getElementsInGroup as Rb}from"@excalidraw/element";import{syncInvalidIndices as zb,syncMovedIndices as _b,validateFractionalIndices as Hb}from"@excalidraw/element";import{getSelectedElements as Ub}from"@excalidraw/element";import{mutateElement as Wb}from"@excalidraw/element";var gm=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}},Yb=(0,Em.default)(e=>{(fm()||hm()||window?.DEBUG_FRACTIONAL_INDICES)&&Hb(e,{shouldThrow:fm()||hm(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),Xb=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},_i=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=pm(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=pm(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=Xb(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=Ub(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&&Gb(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=Ob(t),o=[];n?.skipValidation||Yb(i),this.elements=zb(i),this.elementsMap.clear(),this.elements.forEach(s=>{Fb(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=gm(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=gm(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=kb();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()}insertElementsAtIndex(t,n){if(!t.length)return;if(n===null&&(n=this.elements.length),!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)];_b(i,Nb(t)),this.replaceAllElements(i)}insertElement=t=>{this.insertElementsAtIndex([t],null)};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]:Rb(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=Wb(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var V=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(hn(t??[],o),hn(n??[],o),hn(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,p)=>(u[p]=o(a[p]),u),{}),c=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=o(l[p]),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=hn(e.getLeftDifferences(hn(r,o),hn(s,o)),d=>d),l=hn(e.getRightDifferences(hn(r,o),hn(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)])):bm(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&&Ja(a,l))continue;yield s}}}},jn=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=V.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(V.create({},{}))}inverse(){let t=V.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=V.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=V.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=V.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=V.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=V.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=V.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=V.merge(this.delta,t.delta,V.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=V.mergeObjects(t.selectedElementIds,s,i),p=V.mergeObjects(t.selectedGroupIds,a,o),m=V.mergeObjects(t.lockedMultiSelections,l,r),h=d&&n.has(d.elementId)?new R(n.get(d.elementId),n,d.isEditing):null,f={...t,...c,selectedElementIds:u,selectedGroupIds:p,lockedMultiSelections:m,selectedLinearElement:typeof d<"u"?h:t.selectedLinearElement},g=this.filterInvisibleChanges(t,f,n);return[f,g]}catch(i){if(console.error("Couldn't apply appstate change",i),En()||gn())throw i;return[t,!1]}}isEmpty(){return V.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=zi(t),r=zi(n),s=V.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=V.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=V.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=_c(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 b=i.get(x);b&&!b.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?c.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=i.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let h=t[u]||{},f=n[u]||{};Ja(h,f)||(l.value=!0);break;case"activeLockedId":let g=t[u]||null,E=n[u]||null;g!==E&&(l.value=!0);break;default:bm(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{V.diffObjects(t,n,"selectedElementIds",i=>!0),V.diffObjects(t,n,"selectedGroupIds",i=>i??!1),V.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),En()||gn())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}},$n=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(En()||gn())&&(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:xm()},c=V.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:xm()},d={...s},c=V.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=V.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]=V.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,p)=>{let m;switch(p){case"deleted":m=d;break;case"inserted":m=c;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let h={};for(let f of Object.keys(u))switch(f){case"boundElements":h[f]=u[f];break;default:h[f]=m[f]}return h},r=d=>{let c={};for(let[u,p]of Object.entries(d)){let m=t.get(u),h=n.get(u),f=null;m||h?f=V.create(p.deleted,p.inserted,o(m,h),i):f=p,V.isInnerDifferent(f.deleted,f.inserted)&&(c[u]=f)}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=Vn.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),En()||gn())throw a;return[t,!0]}try{let a=new Set(r.keys()),l=new Map;for(let c of a){let u=t.get(c),p=o.get(c);for(let m of[u,p])if(m){$(m)&&m.containerId&&a.add(m.containerId);for(let h of m.boundElements??[])a.add(h.id)}u&&l.set(c,u===p?{...u}:u)}o=e.reorderElements(o,r,s);let d=En()||gn()?new Map(Array.from(o,([c,u])=>[c,u.version])):void 0;if(e.redrawElements(o,r),d){for(let[c,u]of o)if(d.get(c)!==u.version&&!a.has(c))throw new Error(`Redrawn element "${c}" is missing from idsToCheck`)}if(!s.containsVisibleDifference){for(let c of a)if(e.checkForVisibleDifference(l.get(c),o.get(c),l,o)){s.containsVisibleDifference=!0;break}}}catch(a){if(s.containsVisibleDifference=!0,console.error("Couldn't mutate elements after applying elements change",a),En()||gn())throw a}return[o,s.containsVisibleDifference]}squash(t){if(t.isEmpty())return this;let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=V.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=V.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return V.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]=V.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]=V.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=V.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(En()||gn())&&(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 p=e.applyDelta(u,c,o,r);if(n.set(p.id,p),l.set(p.id,p),!o.applyDirection){let m=t.get(d);m&&(o.applyDirection=m.version>p.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: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"||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=V.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Me(t,r,!0)}static checkForVisibleDifference(t,n,i,o){let r=(d,c)=>!d||d.isDeleted||$(d)&&!d.text.trim()&&!d.boundElements?.length&&!W(c.get(d.containerId??""))?null:d,s=r(t,i),a=r(n,o);if(!s||!a)return s!==a;let l=(d,c)=>(d.boundElements??[]).filter(u=>{let p=c.get(u.id);return u.type!=="text"||W(d)||!p||!$(p)||!!p.text.trim()}).map(({id:u,type:p})=>`${p}:${u}`);return V.getDifferences(s,a).some(d=>{switch(d){case"index":case"version":case"versionNonce":case"updated":case"created":return!1;case"boundElements":return!Ja(l(s,i),l(a,o));default:return!0}})}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,p=l,m;c===d?m=Me(d,{...p,version:u},!0):m=He(d,n,{...p,version:c?.version!==d.version?d.version:u}),o.set(m.id,m),n.set(m.id,m)};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=>wc.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);Fn.unbindAffected(n,r(),o),Fn.unbindAffected(n,s(),o),Rn.unbindAffected(n,r(),o),Rn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Fn.unbindAffected(n,r(),o),Fn.rebindAffected(n,s(),o),Rn.unbindAffected(n,r(),(a,l)=>{$(a)&&o(a,l)}),Rn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new _i(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),En()||gn())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(ge(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=kt(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||cr(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Pe(i)&&Ge(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=Vc([...o]),s=V.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),jb(di(r,s))}static postProcess(t,n){try{V.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];V.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),En()||gn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};M();var iv=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=pn(e),c=Pr(e,t,i).map(Ci).map(h=>[h,pn(h)]).sort((h,f)=>h[1][s]-f[1][s]),u=0;for(let h of c)u+=h[1][l];let p=(d[l]-u)/(c.length-1);if(p<0){let h=c.findIndex(x=>x[1][r]===d[r]),f=c.findIndex(x=>x[1][a]===d[a]),g=(c[f][1][s]-c[h][1][s])/(c.length-1),E=c[h][1][s];return c.flatMap(([x,b],y)=>{let w={x:0,y:0};return y!==h&&y!==f&&(E+=g,w[n.axis]=E-b[s]),x.map(S=>{let I=o.mutateElement(S,{x:S.x+w.x,y:S.y+w.y});return Ge(S,o,{simultaneouslyUpdated:x}),I})})}let m=d[r];return c.flatMap(([h,f])=>{let g={x:0,y:0};return g[n.axis]=m-f[r],m+=p,m+=f[l],h.map(E=>{let x=o.mutateElement(E,{x:E.x+g.x,y:E.y+g.y});return Ge(E,o,{simultaneouslyUpdated:h}),x})})};M();import{TEXT_AUTOWRAP_THRESHOLD as $b,getGridPoint as Vb,getFontString as Kb,DRAGGING_THRESHOLD as Zb}from"@excalidraw/common";var pv=(e,t,n,i,o,r)=>{if(t.length===1&&X(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(X(m)&&m.startBinding&&m.endBinding){let h=t.find(g=>g.id===m.startBinding?.elementId),f=t.find(g=>g.id===m.endBinding?.elementId);return h&&f}return!0}),a=new Set(s),l=s.filter(m=>Q(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 h=e.originalElements.get(m.id);if(!h)return;d.push(h)}let c=qb(ot(d),n,o,r),u=Array.from(a),p=ua(u);a.forEach(m=>{if(W(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>Zb||!m.startBinding&&!m.endBinding){el(e,m,i,c);let h=m.startBinding?!p.has(m.startBinding.elementId):!0,f=m.endBinding?!p.has(m.endBinding.elementId):!0;(h||f)&&(h&&Ke(m,"start",i),f&&Ke(m,"end",i))}}else{el(e,m,i,c);let h=J(m,i.getNonDeletedElementsMap());h&&el(e,h,i,c),Ge(m,i,{simultaneouslyUpdated:u})}})},qb=(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]=Vb(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},el=(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})},fv=(e,t,n)=>{let[i,o]=ot(e);return[t-i,n-o]},Qb=({newElement:e,anchorX:t,anchorRatio:n,pointerX:i,nextY:o,zoom:r,scene:s,informMutation:a=!0})=>{let l=i-t,d=n===0?l:n===1?-l:Math.abs(l),c=Math.max(n===.5?d*2:d,sr(Kb({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight));s.mutateElement(e,{x:t-c*n,...o===void 0?{}:{y:o},width:c,...d>$b/r?{autoResize:!1}:{}},{informMutation:a,isDragging:!1})},hv=({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:p=null,originOffset:m=null,informMutation:h=!0})=>{if(l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=za(t,a,o<n?-s:s):{width:s,height:a}=za(t,s,r<i?-a:a),a<0&&(a=-a))),$(e)){Qb({newElement:e,anchorX:n+(m?.x??0),anchorRatio:d?.5:o<n?1:0,pointerX:o,nextY:i+(m?.y??0),zoom:c,scene:u,informMutation:h});return}let f=o<n?n-s:n,g=r<i?i-a:i;if(d&&(s+=s,a+=a,f=n-s/2,g=i-a/2),s!==0&&a!==0){let E=null;Ne(e)&&(E={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:f+(m?.x??0),y:g+(m?.y??0),width:s,height:a,...E},{informMutation:h,isDragging:!1})}};M();import{ELEMENT_LINK_KEY as Rr,normalizeLink as ym}from"@excalidraw/common";var yv=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Rr,e),ym(i.toString())}catch(i){console.error(i)}return ym(n)},wv=(e,t)=>{if(e.length>0&&Jb(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},Jb=e=>!!(e.length===1||e.length>1&&Hc(e)),Pv=e=>{try{let t=new URL(e);return t.searchParams.has(Rr)&&t.host===window.location.host}catch{return!1}},Sv=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Rr))return t.get(Rr)}catch{}return null};M();import{FONT_FAMILY as ey,VERTICAL_ALIGN as ty,escapeDoubleQuotes as tl,getFontString as ny}from"@excalidraw/common";var Rt=new Map,iy=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|live\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,oy=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,ry=/^https:\/\/(?:www\.)?figma\.com/,wm=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,sy=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,ay=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Pm=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,ly=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,dy=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,cy=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Sm=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Im=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,uy=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Tm=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)},my=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=Tm(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}},il=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"]),Mm=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"]),nl=e=>`<html><body>${e}</body></html>`,Bv=e=>{if(!e)return null;if(Rt.has(e))return Rt.get(e);let t=e,n=Mm.has(ol(e,Mm)||""),i="generic",o={w:560,h:840},r=e.match(iy);if(r?.[2]){let c=Tm(t),u=c>0?`&start=${c}`:"",p=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=p?{w:315,h:560}:{w:560,h:315},Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(oy);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},Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=my(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},Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(ry))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(dy);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(ay.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Pm.test(e)){let c=e.match(Pm)[1],u=tl(`https://twitter.com/x/status/${c}`),p={type:"document",srcdoc:m=>nl(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${m}"><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 Rt.set(t,p),p}if(Im.test(e)){let[,c,u,p]=e.match(Im),m=tl(`https://reddit.com/r/${c}/comments/${u}/${p}`),h={type:"document",srcdoc:f=>nl(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${m}"></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 Rt.set(t,h),h}if(wm.test(e)){let[,c,u]=e.match(wm),p=tl(`https://gist.github.com/${c}/${u}`),m={type:"document",srcdoc:()=>nl(`
22
+ <script src="${p}.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}}},iI=e=>{let t;ki(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=Fh.Helvetica,o=Hh({fontSize:n,fontFamily:i});return Rd({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:Nh.MIDDLE,angle:e.angle??0})},ds=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(ls.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return ls.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},oI=e=>{let t=e.match(jh);if(t&&t.length===2)return t[1];let n=e.match($h);if(n&&n.length===2)return n[1];let i=e.match(Uh);if(i&&i.length===2)return i[1];if(zd.test(e))return`https://giphy.com/embed/${zd.exec(e)[1]}`;let o=e.match(Vh);return o&&o.length===2?o[1]:e},rI=(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(ds(e,n))return!0;return!1}}return!!ds(e,ls)};P();import{KEYS as Do,invariant as vo,toBrandedType as qh}from"@excalidraw/common";import{pointFrom as Ud}from"@excalidraw/math";var Nn=100,xn=100,wI=e=>{switch(e){case Do.ARROW_UP:return"up";case Do.ARROW_DOWN:return"down";case Do.ARROW_RIGHT:return"right";case Do.ARROW_LEFT:return"left";default:return"right"}},Wd=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(B(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;vo(Le(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=ni(t,$e(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=>me(r.heading,ze)).map(r=>r.relative);case"down":return o.filter(r=>me(r.heading,ye)).map(r=>r.relative);case"right":return o.filter(r=>me(r.heading,fe)).map(r=>r.relative);case"left":return o.filter(r=>me(r.heading,ke)).map(r=>r.relative)}},cs=(e,t,n)=>Wd("successors",e,t,n),us=(e,t,n)=>Wd("predecessors",e,t,n),Kh=(e,t,n)=>{let i=xn+e.width;if(n==="up"||n==="down"){let a=Nn+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:(xn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Nn+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=Nn+e.height,r=(t.length===0,xn+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}},Qh=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=cs(e,o,n),s=us(e,o,n),a=Kh(e,[...r,...s],n),l=rs({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});vo(tr(l),"not an ExcalidrawFlowchartNodeElement");let d=Vd(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},Jh=(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=xn+e.width;n==="left"&&(m*=-1),a=e.x+m;let f=(Nn+e.height)*s;l=p+f}else{let u=xn*(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=(xn+e.width)*s;a=p+f}let d=rs({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});vo(tr(d),"not an ExcalidrawFlowchartNodeElement");let c=Vd(e,d,n,t,i);r.push(d),r.push(c)}return r},Vd=(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=Fd({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:[Ud(0,0),Ud(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();gn(c,e,"start",o),gn(c,t,"end",o);let p=new Map;p.set(e.id,e),p.set(t.id,t),p.set(c.id,c),U.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let m=Dn(c,qh(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...m}},Xd=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=[...cs(t,n,i),...us(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=>[...cs(t,n,a),...us(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}},jd=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}=Qh(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=Jh(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);vo(s&&Ri(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>Kt([a],s,r)||Zt(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>be(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},yI=(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 $d,SVG_NS as eE}from"@excalidraw/common";var tE=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===$d.binary)throw new Error("Only images can be added to ImageCache");let l=tE(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}},TI=e=>e.filter(t=>Ht(t)),nE=e=>e?.nodeName.toLowerCase()==="svg",AI=e=>{let t=new DOMParser().parseFromString(e,$d.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!nE(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",eE);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 GI=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(m=>[m]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let m=0;m<s;m+=a)l.push(r.slice(m,m+a));let d=0,c=l.map(m=>{let f=0,E=0,h=m.map(g=>{let[x,y,b,w]=Xe(g);return{elements:g,bounds:[x,y,b,w],width:b-x,height:w-y}});return h.forEach((g,x)=>{f+=g.width,x<h.length-1&&(f+=i),g.height>E&&(E=g.height)}),d+=E,{unitBounds:h,width:f,maxHeight:E}}),u=d+Math.max(0,l.length-1)*i,p=n-u/2;return c.forEach(m=>{let{unitBounds:f,width:E,maxHeight:h}=m,g=t-E/2;f.forEach(x=>{let[y,b]=x.bounds,w=g-y,I=p-b;x.elements.forEach(M=>{o.push(Ee(M,{x:M.x+w,y:M.y+I}))}),g+=x.width+i}),p+=h+i}),o};P();import{pointCenter as iE,normalizeRadians as Co,pointFrom as re,pointRotateRads as it}from"@excalidraw/math";import{MIN_FONT_SIZE as ms,SHIFT_LOCKING_ANGLE as Go,rescalePoints as Zd,getFontString as Lo}from"@excalidraw/common";var jI=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[p]=n;if(t==="rotation")B(p)||(oE(p,i,a,l,o),Ue(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}=dE(f,E,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});lE(h,g,f,E,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return ie(p)&&Ue(p,i),!0}else if(n.length>1){if(t==="rotation")return sE(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:p,nextHeight:m,flipByX:f,flipByY:E,originalBoundingBox:h}=cE(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return uE(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:E,nextWidth:p,nextHeight:m,originalBoundingBox:h}),!0}}return!1},oE=(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+Go/2,u=u-u%Go),u=Co(u));let p=It(e);if(t.mutateElement(e,{angle:u}),p){let m=t.getElement(p);if(m&&!Y(e)){let{x:f,y:E}=ei(e,m,t.getNonDeletedElementsMap());t.mutateElement(m,{angle:u,x:f,y:E})}}},qd=(e,t,n,i)=>j(e)||Me(e)?{points:Zd(0,t,Zd(1,n,e.points,i),i)}:{},fs=(e,t,n)=>{let i=e.width;if(ce(e)){let s=Ce(e,t);s&&(i=et(s,e))}let r=e.fontSize*(n/i);return r<ms?null:{size:r}},rE=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=fs(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=re(e.x,e.y),u=ps(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=Hi(Lo({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),p=Pt(t.originalText,Lo(t),Math.abs(u)),m=Je(p,Lo(t),t.lineHeight),f=m.height,E=re(e.x,e.y),h=ps(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)}}},sE=(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+=Go/2,d-=d%Go);for(let c of t)if(!Z(c)){let[u,p,m,f]=_(c,l),E=(u+m)/2,h=(p+f)/2,g=e.get(c.id)?.angle??c.angle,[x,y]=it(re(E,h),re(s,a),d+g-c.angle),b=B(c)?{points:Ja(c,l)}:{x:c.x+(x-E),y:c.y+(y-h),angle:Co(d+g)};n.mutateElement(c,b),Ue(c,n,{simultaneouslyUpdated:t});let w=W(c,l);if(w&&!Y(c)){let{x:I,y:M}=ei(c,w,l);n.mutateElement(w,{x:I,y:M,angle:Co(d+g)})}}n.triggerUpdate()},WI=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?_(t[0],n):Xe(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=it(re(i,o),re(d,c),-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]}},VI=(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"},aE=(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"},ps=(e,t,n,i,o,r,s,a,l)=>{let d=aE(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)}}},lE=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(ie(n)&&ie(i))return rE(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),p=W(n,u);if(p){let h=o.get(p.id);if(h&&(c={fontSize:h.fontSize}),l){let g={...n,width:e,height:t},x=fs(p,u,et(g,p));if(x===null)return;c={fontSize:x.size}}else{let g=ha(Lo(p),p.lineHeight),x=Ea(p.fontSize,p.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let m=qd(i,e,t,!0),f=re(i.x,i.y);if(j(i)){let[h,g]=pe(i,o);f=re(h,g)}let E=ps(f,i.width,i.height,e,t,i.angle,s,l,d);if(j(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]]}),Y(n)&&p&&l){let h=e/n.width*p.fontSize;if(h<ms)return;c.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&&c!=null&&r.mutateElement(p,{fontSize:c.fontSize}),hn(n,r,s,l),Ue(n,r,{newSize:{width:e,height:t}})}},dE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=Nt(t,t.width,t.height,!0),u=re(a,l),p=re(d,c),m=iE(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,D=I/b;n.includes("e")&&(M=(f[0]-u[0])/y),n.includes("s")&&(D=(f[1]-u[1])/b),n.includes("w")&&(M=(p[0]-f[0])/y),n.includes("n")&&(D=(p[1]-f[1])/b);let T=e.width*M,N=e.height*D;if(s&&(T=2*T-t.width,N=2*N-t.height),r){let C=Math.abs(T)/t.width,R=Math.abs(N)/t.height;if(n.length===1&&(N*=C,T*=R),n.length===2){let L=Math.max(C,R);T=t.width*L*Math.sign(T),N=t.height*L*Math.sign(N)}}return{nextWidth:T,nextHeight:N}},cE=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(L=>t.get(L.id)),d=l.reduce((L,V)=>{if(!j(V))return L;let H=It(V);if(!H)return L;let te=t.get(H)??null;return ce(te)?[...L,{...te,...U.getBoundTextElementPosition(V,te,n)}]:L},[]),c=Ct(l.map(L=>L).concat(d)),{minX:u,minY:p,maxX:m,maxY:f,midX:E,midY:h}=c,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,D=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&&(D=g*M*Math.sign(o-b),T=x*M*Math.sign(r-w));let N={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]=N[i].map(L=>L);return{originalBoundingBox:c,nextWidth:D,nextHeight:T,flipByX:C,flipByY:R}},uE=(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 p=e.reduce((I,M)=>{let D=o.get(M.id);return D&&I.push({orig:D,latest:M}),I},[]),m;if(u)m=u;else{let I=p.reduce((M,{orig:D})=>{if(!j(D))return M;let T=It(D);if(!T)return M;let N=o.get(T)??null;return ce(N)?[...M,{...N,...U.getBoundTextElementPosition(D,N,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(c===void 0&&d===void 0&&(c=b,d=w),r&&(c===void 0?c=d*(b/w):d===void 0?d=c*(w/b):Math.abs(c/d-b/w)>.001&&(c=d*(b/w))),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)/w:1,D;n.length===1?D=n.includes("e")||n.includes("w")?I:M:D=Math.max(Math.abs(c)/b||0,Math.abs(d)/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]},[N,C]=s?[x,y]:T[n],R=r||p.some(S=>S.latest.angle!==0||ie(S.latest)||yl(S.latest));R&&(I=D,M=D);let[L,V]=[a?-1:1,l?-1:1],H=[];for(let{orig:S,latest:Q}of p){if(ie(S)&&ce(S))continue;let $=S.width*I,ne=S.height*M,sn=Co(S.angle*L*V),ot=j(S)||Me(S),wn=S.x-N,Oo=S.y-C,mi=a&&!ot?$:0,Hn=l&&!ot?ne:0,Ro=N+L*(wn*I+mi),fi=C+V*(Oo*M+Hn),an=qd(S,$*L,ne*V,!1),xe={x:Ro,y:fi,width:$,height:ne,angle:sn,...an};if(B(S)&&(S.startBinding&&(xe.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&&(xe.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&&an.points&&(xe.fixedSegments=S.fixedSegments.map(De=>({...De,start:an.points[De.index-1],end:an.points[De.index]})))),we(S)&&(xe.scale=[S.scale[0]*L,S.scale[1]*V]),ie(S)){let De=fs(S,t,$);if(!De)return;xe.fontSize=De.size}let ln=o.get(It(S)??"");if(ln)if(R){let De=ln.fontSize*D;if(De<ms)return;xe.boundTextFontSize=De}else xe.boundTextFontSize=ln.fontSize;H.push({element:Q,update:xe})}let te=H.map(({element:S})=>S);for(let{element:S,update:{boundTextFontSize:Q,...$}}of H){let{width:ne,height:sn,angle:ot}=$;i.mutateElement(S,$),Ue(S,i,{simultaneouslyUpdated:te,newSize:{width:ne,height:sn}});let wn=W(S,t);wn&&Q&&(i.mutateElement(wn,{fontSize:Q,angle:j(S)?void 0:ot}),hn(S,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as Ze,pointOnLineSegment as nc,pointRotateRads as ko}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as ys}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as Es,isAndroid as pE,isIOS as mE}from"@excalidraw/common";import{pointFrom as Kd,pointRotateRads as fE}from"@excalidraw/math";var Qd={mouse:8,pen:16,touch:28},hE=16,ec={e:!0,s:!0,n:!0,w:!0},eS={e:!0,s:!0,n:!0,w:!0},tS={e:!0,s:!0,n:!0,w:!0,rotation:!0},Jd={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},hs={e:!0,s:!0,n:!0,w:!0},kt=(e,t,n,i,o,r,s)=>{let[a,l]=fE(Kd(e+n/2,t+i/2),Kd(o,r),s);return[a-n/2,l-i/2,n,i]},Bo=e=>!(e.viewport.isMobile||e.isTouchScreen&&(pE||mE)),gs=e=>Bo(e)?ec:{},xs=([e,t,n,i,o,r],s,a,l,d={},c=4,u=Es)=>{let p=Qd[l],m=p/a.value,f=p/a.value,E=p/a.value,h=p/a.value,g=n-e,x=i-t,y=c/a.value,b=(p-u*2)/(2*a.value),w={nw:d.nw?void 0:kt(e-y-E+b,t-y-h+b,m,f,o,r,s),ne:d.ne?void 0:kt(n+y-b,t-y-h+b,m,f,o,r,s),sw:d.sw?void 0:kt(e-y-E+b,i+y-b,m,f,o,r,s),se:d.se?void 0:kt(n+y-b,i+y-b,m,f,o,r,s),rotation:d.rotation?void 0:kt(e+g/2-m/2,t-y-h+b-hE/a.value,m,f,o,r,s)},I=5*Qd.mouse/a.value;return Math.abs(g)>I&&(d.n||(w.n=kt(e+g/2-m/2,t-y-h+b,m,f,o,r,s)),d.s||(w.s=kt(e+g/2-m/2,i+y-b,m,f,o,r,s))),Math.abs(x)>I&&(d.w||(w.w=kt(e-y-E+b,t+x/2-f/2,m,f,o,r,s)),d.e||(w.e=kt(n+y-b,t+x/2-f/2,m,f,o,r,s))),w},tc=(e,t,n,i="mouse",o=ec)=>{if(e.locked||B(e))return{};if(e.type==="freedraw"||j(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=hs:s[0]>0&&s[1]<0?o=Jd:s[0]>0&&s[1]>0?o=hs:s[0]<0&&s[1]>0?o=Jd:s[0]<0&&s[1]<0&&(o=hs)}}else Z(e)&&(o={...o,rotation:!0});let r=j(e)?Es+8:we(e)?0:Es;return xs(_(e,n,!0),e.angle,t,i,o,r,we(e)?0:void 0)},nS=(e,t)=>{if(t.selectedLinearElement?.isEditing)return!1;if(e.length>1)return!0;let n=e[0];return B(n)?!1:j(n)?n.points.length>2:!0};var bs=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],EE=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=tc(e,r,t,s,gs(a));if(l&&bs(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let p=d[u];return p?bs(p,i,o):!1});if(c.length>0)return c[0];if(Bo(a)){let[u,p,m,f,E,h]=_(e,t);if(!(j(e)&&e.points.length<=2)){let g=we(e)?0:ys/r.value,x=ys/r.value,y=ic(Ze(u-g,p-g),Ze(m+g,f+g),Ze(E,h),e.angle);for(let[b,w]of Object.entries(y))if(nc(Ze(i,o),w,x))return b}}return!1},cS=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=EE(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),uS=([e,t,n,i],o,r,s,a,l)=>{let d=xs([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,gs(l)),c=Object.keys(d).find(u=>{let p=d[u];return p&&bs(p,o,r)});if(c)return c;if(Bo(l)){let u=(e+n)/2,p=(t+i)/2,m=ys/s.value,f=ic(Ze(e-m,t-m),Ze(n+m,i+m),Ze(u,p),0);for(let[E,h]of Object.entries(f))if(nc(Ze(o,r),h,m))return E}return!1},ws=["ns","nesw","ew","nwse"],gE=(e,t)=>{let n=ws.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=ws[(n+i)%ws.length]}return e},pS=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=gE(o,t.angle)),o?`${o}-resize`:""},ic=([e,t],[n,i],o,r)=>{let s=ko(Ze(e,t),o,r),a=ko(Ze(n,t),o,r),l=ko(Ze(e,i),o,r),d=ko(Ze(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var ES=(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 rc,findIndex as sc,findLastIndex as ac}from"@excalidraw/common";var Ps=(e,t)=>e.frameId===t||e.id===t,lc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=rc(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},xE=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),[])},oc=(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))}}},wE=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{Ps(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},yE=(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"?ac(t,p=>a(p),Math.max(0,n-1)):sc(t,p=>a(p),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return oc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||Z(d))){let p=wE(t,d.frameId||d.id);return i==="left"?t.indexOf(p[0]):t.indexOf(p[p.length-1])}if(!d.groupIds.length)return oc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Ae(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},dc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),cc=(e,t,n,i)=>{let o=lc(e,t),r=dc(e,o),s=xE(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],p=n==="left"?c:u,m=l.some(y=>{let b=e[y];return b.frameId&&a.has(b.frameId)})?null:e[p]?.frameId,f=yE(t,e,p,n,m,i);if(f===-1||p===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,c),h=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"?[...E,...h,...g,...x]:[...E,...g,...h,...x]}),pi(e,r),e},uc=(e,t,n,i,o)=>{let r=lc(e,t,o),s=dc(e,r),a=[],l,d;if(n==="left"){if(i)l=sc(e,f=>Ps(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;d=r[r.length-1]}else{if(i)d=ac(e,f=>Ps(f,i));else if(t.editingGroupId){let f=Ae(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),p=e.slice(d+1),m=n==="left"?[...u,...c,...a,...p]:[...u,...a,...c,...p];return pi(m,s),m};function pc(e,t,n,i){let o=rc(pt(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)=>cc(e,t,"left",n),MS=(e,t,n)=>cc(e,t,"right",n),TS=(e,t)=>pc(e,t,"left",uc),AS=(e,t)=>pc(e,t,"right",uc);var BS=e=>e.reduce((t,n)=>t+n.version,0),ld=e=>{let t=5381;for(let n of bE(e))t=(t<<5)+t+n.versionNonce;return t>>>0},dd=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},kS=e=>e.filter(t=>!t.isDeleted&&!ed(t)),PE=e=>e.filter(t=>!t.isDeleted),OS=e=>!e.isDeleted,Is=e=>PE(e).map(t=>Jo(t.type)?{...t,lastCommittedPoint:null}:t),RS=e=>Is(e),FS=e=>Is(e),NS=e=>Is(e);export{Jt as AppStateDelta,ee as BASE_PADDING,zp as BINDING_HIGHLIGHT_THICKNESS,$t as BindableElement,Vt as BoundElement,Fe as CaptureUpdateAction,t0 as DEFAULT_LINK_SIZE,ec as DEFAULT_OMIT_SIDES,F as Delta,Qr as DurableIncrement,Wr as ElementBounds,en as ElementsDelta,Jr as EphemeralIncrement,oe as FIXED_BINDING_DISTANCE,jd as FlowChartCreator,Xd as FlowChartNavigator,ye as HEADING_DOWN,ke as HEADING_LEFT,fe as HEADING_RIGHT,ze as HEADING_UP,Zm as IMAGE_INVERT_FILTER,Sf as INVISIBLY_SMALL_ELEMENT_SIZE,ts as InvalidFractionalIndexError,U as LinearElementEditor,Se as MINIMAL_CROP_SIZE,tS as OMIT_SIDES_FOR_FRAME,eS as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Mo as Scene,Pe as ShapeCache,od as Store,ci as StoreChange,es as StoreDelta,bo as StoreIncrement,tn as StoreSnapshot,$e as aabbForElement,Rm as addElementsToFrame,Jh as addNewNodes,Ky as addToGroup,s1 as alignElements,Jp as avoidRectangularCorner,Sl as bindElementsToFramesAfterDuplication,gn as bindLinearElement,Dr as bindOrUnbindLinearElement,Xp as bindOrUnbindLinearElements,Sr as bindPointToSnapToElementOutline,io as bindingBorderTest,Qa as bindingProperties,Na as bumpVersion,Za as calculateFixedPointForElbowArrowBinding,kx as canApplyRoundnessTypeToElement,ua as canBecomePolygon,Hl as canChangeRoundness,Mh as canCreateLinkFromElements,p0 as canHaveArrowheads,Bo as canResizeFromSides,Sn as charWidth,RS as clearElementsForDatabase,FS as clearElementsForExport,NS as clearElementsForLocalStorage,me as compareHeading,ei as computeBoundTextPosition,lr as computeContainerDimensionForBoundText,Jx as containsCJK,iI as createPlaceholderEmbeddableLabel,as as createSrcDoc,xx as cropElement,In as deconstructDiamondElement,Gi as deconstructLinearOrFreeDrawElement,Pn as deconstructRectanguloidElement,Kr as deepCopyElement,vP as defaultGetElementLinkFromSelection,Wx as detectLineHeight,_t as distanceToElement,pP as distributeElements,En as doBoundsIntersect,SP as dragNewElement,PP as dragSelectedElements,kf as duplicateElement,y1 as duplicateElements,qy as editGroupForSelectedElement,he as elementCenterPoint,Zt as elementOverlapsWithFrame,xo as elementWithCanvasCache,Kt as elementsAreInFrameBounds,wl as elementsAreInSameGroup,rI as embeddableURLValidator,Pl as excludeElementsInFramesFromSelection,Bb as filterElementsEligibleAsFrameChildren,yy as fixBindingsAfterDeletion,Ka as fixDuplicatedBindingsAfterDuplication,fr as flipHeading,Hb as frameAndChildrenSelectedTogether,Nl as generateFreeDrawShape,oa as generateLinearCollisionShape,Re as generateRoughOptions,Ea as getApproxMinLineHeight,ha as getApproxMinLineWidth,Ja as getArrowLocalFixedPoints,xf as getArrowheadAngle,Ur as getArrowheadPoints,gf as getArrowheadSize,W as getBoundTextElement,It as getBoundTextElementId,uw as getBoundTextElementPosition,ti as getBoundTextMaxHeight,et as getBoundTextMaxWidth,Vr as getBoundsFromPoints,dt as getCenterForBounds,X0 as getClosestElementBounds,Ct as getCommonBoundingBox,Xe as getCommonBounds,dw as getContainerCenter,dr as getContainerCoords,Ce as getContainerElement,vt as getContainingFrame,yt as getCornerRadius,Wi as getCubicBezierCurveBound,pS as getCursorForResizingElement,_m as getDefaultFrameName,Ox as getDefaultRoundnessTypeForElement,Bi as getDiamondPoints,IP as getDragOffsetXY,U0 as getDraggedElementsBounds,_ as getElementAbsoluteCoords,pe as getElementBounds,Nr as getElementLineSegments,Gr as getElementPointsCoords,jl as getElementShape,cS as getElementWithTransformHandleType,Ml as getElementsCompletelyInFrame,Ae as getElementsInGroup,Gb as getElementsInNewFrame,Cb as getElementsInResizingFrame,Mb as getElementsIntersectingFrame,Nb as getElementsOverlappingFrame,Rr as getElementsWithinSelection,nI as getEmbedLink,wx as getFlipAdjustedCropPosition,qt as getFrameChildren,km as getFrameLikeElements,Fb as getFrameLikeTitle,Jm as getFreeDrawPath2D,ef as getFreeDrawSvgPath,o0 as getFreedrawOutlineAsSegments,tf as getFreedrawOutlinePoints,to as getGlobalFixedPointForBindableElement,om as getGlobalFixedPoints,Fa as getHeadingForElbowArrowSnap,jt as getHoveredElementForBinding,TI as getInitializedImageElements,zi as getLineHeightInPx,zt as getLineWidth,Fx as getLinearElementSubType,wI as getLinkDirectionFromKey,LP as getLinkIdAndTypeFromSelection,sl as getLockedLinearCursorAlignSize,Iu as getMaxCharWidth,Jy as getMaximumGroups,$x as getMinCharWidth,ai as getMinMaxXYFromCurvePathOps,Hi as getMinTextElementWidth,bl as getNewGroupIdsForDuplication,PE as getNonDeletedElements,xl as getNonDeletedGroupIds,e1 as getNormalizedDimensions,On as getObservedAppState,gs as getOmitSidesForDevice,_x as getOriginalContainerHeightFromCache,$r as getPerfectElementSize,us as getPredecessors,Y0 as getRectangleBoxAbsoluteCoords,qm as getRenderOpacity,VI as getResizeArrowDirection,WI as getResizeOffsetXY,Nt as getResizedElementAbsoluteCoords,Lb as getRootElements,BS as getSceneVersion,pt as getSelectedElements,po as getSelectedElementsByGroup,Or as getSelectedGroupForElement,vm as getSelectedGroupIdForElement,Am as getSelectedGroupIds,pb as getSelectionStateForElements,gy as getSuggestedBindingsForArrows,ub as getTargetElements,Nm as getTargetFrame,cw as getTextElementAngle,hw as getTextFromElements,Pu as getTextHeight,ga as getTextWidth,uS as getTransformHandleTypeFromCoords,tc as getTransformHandles,xs as getTransformHandlesFromCoords,ta as getUncroppedImageElement,$o as getUncroppedWidthAndHeight,db as getVisibleAndNonSelectedElements,kS as getVisibleElements,j0 as getVisibleSceneBounds,vb as groupByFrameLikes,Ab as groupsAreAtLeastIntersectingTheFrame,Db as groupsAreCompletelyOutOfFrame,hn as handleBindTextResize,a0 as hasBackground,st as hasBoundTextElement,l0 as hasStrokeColor,c0 as hasStrokeStyle,d0 as hasStrokeWidth,ld as hashElementsVersion,dd as hashString,Be as headingForPoint,ni as headingForPointFromElement,tt as headingForPointIsHorizontal,Oe as headingIsHorizontal,zw as headingIsVertical,rp as hitElementBoundText,op as hitElementBoundingBox,kw as hitElementBoundingBoxOnly,ip as hitElementItself,Mn as intersectElementWithLineSegment,Bx as isArrowBoundToElement,Y as isArrowElement,Le as isBindableElement,er as isBindingElement,hu as isBindingElementType,Ar as isBindingEnabled,ce as isBoundToContainer,Rx as isBounds,Tb as isCursorInFrame,fu as isCurvedArrow,B as isElbowArrow,J0 as isElementCompletelyInViewport,Hr as isElementContainingFrame,Al as isElementInFrame,Dm as isElementInGroup,Il as isElementInViewport,Bn as isElementIntersectingFrame,CP as isElementLink,sa as isEmbeddableElement,Gx as isExcalidrawElement,Qn as isFixedPointBinding,tr as isFlowchartNodeElement,Ri as isFrameElement,Z as isFrameLikeElement,Me as isFreeDrawElement,pu as isFreeDrawElementType,nE as isHTMLSVGElement,ki as isIframeElement,Oi as isIframeLikeElement,we as isImageElement,yl as isInGroup,Ht as isInitializedImageElement,ed as isInvisiblySmallElement,mn as isLineElement,j as isLinearElement,Va as isLinearElementSimpleAndAlreadyBound,Jo as isLinearElementType,aa as isMagicFrameElement,jx as isMeasureTextSupported,yI as isNodeInFlowchart,OS as isNonDeletedElement,pn as isPathALoop,Aa as isPointInElement,Cx as isRectangularElement,la as isRectanguloidElement,Tm as isSelectedViaGroup,mu as isSharpArrow,Lx as isSimpleArrow,cb as isSomeElementSelected,Eu as isTextBindableContainer,ie as isTextElement,da as isUsingAdaptiveRadius,ca as isUsingProportionalRadius,Nx as isValidPolygon,fw as isValidTextContainer,tE as loadHTMLImageElement,kr as makeNextSelectedElementIds,ao as maxBindingGap,xy as maybeBindLinearElement,oI as maybeParseEmbedSrc,ja as maybeSuggestBindingsForLinearElementAtCoords,fs as measureFontSizeFromWidth,Je as measureText,TS as moveAllLeft,AS as moveAllRight,SS as moveOneLeft,MS as moveOneRight,be as mutateElement,Fd as newArrowElement,rs as newElement,Ee as newElementWith,YP as newEmbeddableElement,XP as newFrameElement,VP as newFreeDrawElement,UP as newIframeElement,ZP as newImageElement,$P as newLinearElement,jP as newMagicFrameElement,Rd as newTextElement,td as normalizeElementOrder,vr as normalizeFixedPoint,AI as normalizeSVG,ir as normalizeText,mo as omitGroupsContainingFrameLikes,Om as omitPartialGroups,Ed as orderByFractionalIndex,Jn as originalContainerCache,GP as parseElementLinkFromURL,Lu as parseTokens,Fl as pathsCache,An as pointInsideBounds,GI as positionElementsOnGrid,ba as redrawTextBoundingBox,WP as refreshTextDimensions,Fm as removeAllElementsFromFrame,Tl as removeElementsFromFrame,Qy as removeFromSelectedGroups,i0 as renderElement,n0 as renderSelectionElement,kb as replaceAllElementsInFrame,qd as rescalePointsInElement,ma as resetOriginalContainerCache,uE as resizeMultipleElements,lE as resizeSingleElement,rE as resizeSingleTextElement,EE as resizeTest,Mm as selectGroup,El as selectGroupsForSelectedElements,gl as selectGroupsFromGivenElements,Vx as setCustomTextMetricsProvider,pw as shouldAllowVerticalAlign,Rb as shouldApplyFrameClip,Ey as shouldEnableBindingForPointerEvent,nS as shouldShowBoundingBox,ji as shouldTestInside,ES as showSelectedShapeActions,em as snapToMid,mw as suppportsHorizontalAlign,Xf as syncInvalidIndices,ad as syncInvalidIndicesImmutable,pi as syncMovedIndices,rl as toggleLinePolygonState,u0 as toolIsArrow,jI as transformElements,wy as updateBindings,Ue as updateBoundElements,Dn as updateElbowArrowPoints,Ob as updateFrameMembershipOfSelectedElements,MI as updateImageCache,pa as updateOriginalContainerCache,Ra as validateElbowPoints,Uf as validateFractionalIndices,Mt as vectorToHeading,Pt as wrapText};
28
+ `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return Rt.set(e,m),m}return Rt.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},Lv=e=>{let t;Xo(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=ey.Helvetica,o=ny({fontSize:n,fontFamily:i});return fi({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:St(t,o,e.width-20),textAlign:"center",verticalAlign:ty.MIDDLE,angle:e.angle??0})},ol=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(il.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return il.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},Cv=e=>{let t=e.match(ly);if(t&&t.length===2)return t[1];let n=e.match(uy);if(n&&n.length===2)return n[1];let i=e.match(sy);if(i&&i.length===2)return i[1];if(Sm.test(e))return`https://giphy.com/embed/${Sm.exec(e)[1]}`;let o=e.match(cy);return o&&o.length===2?o[1]:e},kv=(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(ol(e,n))return!0;return!1}}return!!ol(e,il)};M();import{invariant as rl,toBrandedType as py}from"@excalidraw/common";import{clamp as fy,pointFrom as Am}from"@excalidraw/math";var Dm=100,vm=100,hy=e=>{let t=[...e].sort((i,o)=>i.start-o.start),n=[];for(let i of t){let o=n[n.length-1];o&&i.start<=o.end?o.end=Math.max(o.end,i.end):n.push({...i})}return n},Cm=(e,t,n)=>n.every(i=>e+t<=i.start||e>=i.end),gy=(e,t,n)=>{if(Cm(e,t,n))return e;let i=[-1/0,...n.map(a=>a.end)],o=[...n.map(a=>a.start),1/0],r=e,s=1/0;for(let a=0;a<i.length;a++){if(o[a]-i[a]<t)continue;let l=fy(e,i[a],o[a]-t),d=Math.abs(l-e);d<=s&&(r=l,s=d)}return r},Ey=(e,t)=>{let n=[...t.values()].filter(X),i=new Set([e.id]),o=[e.id],r=[];for(;o.length>0;){let s=o.shift();for(let a of n){let l=a.startBinding?.elementId,d=a.endBinding?.elementId,c;if(l===s?c=d:d===s&&(c=l),!c||i.has(c))continue;i.add(c);let u=t.get(c);u&&Pe(u)&&(r.push(u),o.push(c))}}return r},xy=(e,t,n,i,o)=>{let r=t==="left"||t==="right",s=r?e.width:e.height,a=r?e.height:e.width,l=r?vm:Dm,d=r?Dm:vm,c=r?e.x:e.y,u=r?e.y+e.height/2:e.x+e.width/2,p=t==="right"||t==="down"?c+s+l:c-l-s,m=hy(i.filter(b=>{let y=r?b[0]:b[1],w=r?b[2]:b[3];return y<p+s&&w>p}).map(b=>({start:(r?b[1]:b[0])-d,end:(r?b[3]:b[2])+d}))),h=a+d,f=n*a+(n-1)*d,E=(o===null?null:[o,o-h].filter(b=>Cm(b,f,m)).sort((b,y)=>Math.abs(b+f/2-u)-Math.abs(y+f/2-u))[0]??null)??gy(u-f/2,f,m);return{positions:Array.from({length:n},(b,y)=>{let w=E+y*h;return r?{x:p,y:w}:{x:w,y:p}}),crossStart:E}},by=(e,t,n)=>{let i={x:t,y:n,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},o=e.type==="stickynote"?Br({type:"stickynote",...i,baseHeight:e.baseHeight}):Ni({type:e.type,...i});return rl(ad(o),"not an ExcalidrawFlowchartNodeElement"),o},yy=(e,t,n,i,o,r=null)=>{let s=i.getNonDeletedElementsMap(),a=Ey(e,s).map(u=>ut(u,s)),{positions:l,crossStart:d}=xy(e,n,o,a,r),c=[];for(let u of l){let p=by(e,u.x,u.y),m=wy(e,p,n,t,i);c.push(p,m)}return{nodes:c,crossStart:d}},wy=(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=Lr({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:[Am(0,0),Am(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();$t(c,e,"orbit","start",o,i.zoom),$t(c,t,"orbit","end",o,i.zoom);let p=new Map;p.set(e.id,e),p.set(t.id,t),p.set(c.id,c),R.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let m=Ii(c,py(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...m,isDeleted:c.isDeleted}},Bm=class e{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(!Pe(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=[...e.getSuccessors(t,n,i),...e.getPredecessors(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=>[...e.getSuccessors(t,n,a),...e.getPredecessors(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}static getNodeRelatives(t,n,i,o){let r=[...i.values()].reduce((s,a)=>{let l;if(X(a)&&(l=a[t==="predecessors"?"startBinding":"endBinding"])&&a[t==="predecessors"?"endBinding":"startBinding"]?.elementId===n.id){let d=i.get(l.elementId);if(!d)return s;rl(Pe(d),"not an ExcalidrawBindableElement");let c=t==="predecessors"?a.points[a.points.length-1]:[0,0],u=Pi(n,ut(n,i),[c[0]+a.x,c[1]+a.y]);s.push({relative:d,heading:u})}return s},[]);switch(o){case"up":return r.filter(s=>fe(s.heading,qe)).map(s=>s.relative);case"down":return r.filter(s=>fe(s.heading,ve)).map(s=>s.relative);case"right":return r.filter(s=>fe(s.heading,Ee)).map(s=>s.relative);case"left":return r.filter(s=>fe(s.heading,ze)).map(s=>s.relative)}}static getSuccessors(t,n,i){return e.getNodeRelatives("successors",t,n,i)}static getPredecessors(t,n,i){return e.getNodeRelatives("predecessors",t,n,i)}},Lm=class{isCreatingChart=!1;numberOfNodes=0;direction=null;clusterCrossStart=null;pendingNodes=null;createNodes(t,n,i,o){let r=o.getNonDeletedElementsMap();i!==this.direction?(this.numberOfNodes=1,this.clusterCrossStart=null):this.numberOfNodes+=1;let{nodes:s,crossStart:a}=yy(t,n,i,o,this.numberOfNodes,this.clusterCrossStart);if(this.isCreatingChart=!0,this.direction=i,this.clusterCrossStart=a,this.pendingNodes=s,t.frameId){let l=r.get(t.frameId);rl(l&&$o(l),"not an ExcalidrawFrameElement"),l&&this.pendingNodes.every(d=>Un([d],l,r)||_n(d,l,r))&&(this.pendingNodes=this.pendingNodes.map(d=>He(d,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0,this.clusterCrossStart=null}},$v=(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};M();import{pointDistance as Hi,pointFrom as al}from"@excalidraw/math";import{invariant as Ym}from"@excalidraw/common";M();import{arrayToMap as Nm,findIndex as Om,findLastIndex as Gm}from"@excalidraw/common";import{isFiniteNumber as Py}from"@excalidraw/math";var sl=(e,t)=>e.frameId===t||e.id===t,Fm=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Nm(n||Kt(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},Sy=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),[])},km=(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))}}},Iy=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{sl(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},Rm=(e,t,n,i,o,r)=>{if(!r)return n;let s=J(r,i),a=$(r)?Oe(r,i):null,l=[r.id,s?.id,a?.id].filter(u=>!!u),d=n.findIndex(u=>l.includes(u.id)),c=n.findIndex(u=>u.id===t.id);if(c!==-1&&d!==-1&&c<d){let u=Array.from(n),p=u.splice(c,1)[0];u.splice(d,0,p),o.replaceAllElements(u)}return n},My=(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"?Gm(t,p=>a(p),Math.max(0,n-1)):Om(t,p=>a(p),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return km(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||Q(d))){let p=Iy(t,d.frameId||d.id);return i==="left"?t.indexOf(p[0]):t.indexOf(p[p.length-1])}if(!d.groupIds.length)return km(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=it(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},zm=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),_m=(e,t)=>{if(e.length!==t.length)return console.error("z-index reordering failed: resulting array have different lengths"),!1;let n=new Map;for(let i of e)n.set(i.id,(n.get(i.id)||0)+1);for(let i of t){let o=n.get(i.id);if(!o)return console.error("z-index reordering failed: element id mismatch / duplicate ids"),!1;n.set(i.id,o-1)}return!0},Hm=(e,t,n,i)=>{let o=e,r=Fm(e,t),s=zm(e,r),a=Sy(r);n==="right"&&(a=a.reverse());let l=new Set(r.filter(d=>Q(e[d])).map(d=>e[d].id));return a.forEach((d,c)=>{let u=d[0],p=d[d.length-1],m=n==="left"?u:p,h=d.some(y=>{let w=e[y];return w.frameId&&l.has(w.frameId)})?null:e[m]?.frameId,f=My(t,e,m,n,h,i);if(f===-1||m===f)return;let g=n==="left"?e.slice(0,f):e.slice(0,u),E=e.slice(u,p+1),x=n==="left"?e.slice(f,u):e.slice(p+1,f+1),b=n==="left"?e.slice(p+1):e.slice(f+1);e=n==="left"?[...g,...E,...x,...b]:[...g,...x,...E,...b]}),_m(o,e)?(di(e,s),e):o},Um=(e,t,n,i,o)=>{let r=Fm(e,t,o);if(r.length===0)return e;let s=zm(e,r),a=[],l,d;if(n==="left"){if(i)l=Om(e,f=>sl(f,i));else if(t.editingGroupId){let f=it(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=Gm(e,f=>sl(f,i));else if(t.editingGroupId){let f=it(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);let c=f=>Py(f)&&f>=0;if(!c(l)||!c(d)||l>d||r.some(f=>f<l||f>d))return e;for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let u=Array.from(s.values()),p=e.slice(0,l),m=e.slice(d+1),h=n==="left"?[...p,...u,...a,...m]:[...p,...a,...u,...m];return _m(e,h)?(di(h,s),h):e};function Wm(e,t,n,i){let o=Nm(Kt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)o.has(d.id)&&Q(d)&&s.add(d.id);for(let d of e)if(o.has(d.id))if(Q(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(a,t,n,d,c);return i(a,t,n,null,r.regularElements)}var iB=(e,t,n)=>Hm(e,t,"left",n),oB=(e,t,n)=>Hm(e,t,"right",n),rB=(e,t)=>Wm(e,t,"left",Um),sB=(e,t)=>Wm(e,t,"right",Um);var zr=(e,t,n,i,o,r,s=!1)=>{if(X(t)||!jt(o)||t.points.length!==2)return!1;if(!s){let l=t.startBinding?.elementId===n.id?0:t.points.length-1,d=R.getPointAtIndexGlobalCoordinates(t,l,i);if(Hi(e,d)<po*1.5/o.zoom.value)return!1}let a=R.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return Hi(e,a)>=po*1.5/o.zoom.value&&Ot({element:n,elementsMap:i,point:e,threshold:Be(n),overrideShouldTestInside:!0})},Ty=(e,t,n,i,o,r,s)=>{let a=new Map,l=r.selectedLinearElement?.initialState.arrowOtherEndpointInitialBinding,d=n?"startBinding":"endBinding",c=n?"endBinding":"startBinding",u=e[d],p=l?.mode==="orbit"&&e[c]?.mode==="inside"?l:e[c];if(u&&t){let m=t&&p&&u.elementId===p.elementId;s||m?u={...u,mode:"inside"}:u={...u,mode:"orbit"};let h=n?0:e.points.length-1,f=Gt(e,d,u,t,i,!0);f&&a.set(h,{point:f})}if(p&&p.mode==="orbit"){let m=i.get(p.elementId);if(m&&Pe(m)&&jt(r)){t&&p.elementId===t.id?p={...p,mode:"inside"}:p={...p,mode:"orbit"};let f=n?e.points.length-1:0,g=Gt(e,c,p,m,i);g&&a.set(f,{point:g})}}a.size>0&&R.movePoints(e,o,a,{[d]:u,[c]:p})},Xm=(e,t,n,i,o,r,s)=>{let a=R.getElement(e.elementId,t);if(!a||!Xe(a)||X(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,p=al(n.x-c,n.y-u),m=l?"startBinding":"endBinding",h=rn(p,i.getNonDeletedElements(),t,o.zoom);if(h&&jt(o)){a[m]&&h.id!==d?.elementId&&Ke(a,e.draggedFocusPointBinding,i);let f=s&&a[m]?.mode==="orbit"?"inside":!s&&a[m]?.mode==="inside"?"orbit":null;(!a[m]||f)&&$t(a,h,f||"orbit",e.draggedFocusPointBinding,i,o.zoom,p),i.mutateElement(a,{[m]:{...a[m],elementId:h.id,mode:f||a[m]?.mode||"orbit",...si(a,h,e.draggedFocusPointBinding,t,p)}})}else{let f=new Map,g=l?0:a.points.length-1;f.set(g,{point:R.createPointAt(a,t,p[0],p[1],r)}),R.movePoints(a,i,f),a[m]&&Ke(a,l?"start":"end",i)}Ty(a,h,l,t,i,o,s),h&&jt(o)&&Rm(p,a,i.getElementsIncludingDeleted(),t,i,h)},gB=(e,t,n,i)=>{let o=al(t.origin.x,t.origin.y),r=po*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&Pe(s)&&!s.isDeleted){let a=_e(e.startBinding.fixedPoint,s,n);if(zr(a,e,s,n,i,"start")&&Hi(o,a)<=r)return{hitFocusPoint:"start",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]},arrowOtherEndpointInitialBinding:e.endBinding}}}if(e.endBinding?.elementId){let s=n.get(e.endBinding.elementId);if(s&&Pe(s)&&!s.isDeleted){let a=_e(e.endBinding.fixedPoint,s,n);if(zr(a,e,s,n,i,"end")&&Hi(o,a)<=r)return{hitFocusPoint:"end",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]},arrowOtherEndpointInitialBinding:e.startBinding}}}return{hitFocusPoint:null,pointerOffset:{x:0,y:0},arrowOtherEndpointInitialBinding:null}},EB=(e,t)=>{Ym(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=R.getElement(e.elementId,t.getNonDeletedElementsMap());Ym(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&&Pe(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);return l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]}),{arrowOtherEndpointInitialBinding:null}},xB=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=al(t,n),a=po*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&Pe(l)&&!l.isDeleted){let d=_e(e.startBinding.fixedPoint,l,r);if(zr(d,e,l,r,o,"start")&&Hi(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&Pe(l)&&!l.isDeleted){let d=_e(e.endBinding.fixedPoint,l,r);if(zr(d,e,l,r,o,"end")&&Hi(s,d)<=a)return"end"}}return null};M();import{MIME_TYPES as jm,SVG_NS as Ay}from"@excalidraw/common";var Dy=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),SB=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===jm.binary)throw new Error("Only images can be added to ImageCache");let l=Dy(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}},IB=e=>e.filter(t=>ei(t)),vy=e=>e?.nodeName.toLowerCase()==="svg",MB=e=>{let t=new DOMParser().parseFromString(e,jm.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!vy(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Ay);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}};M();var BB=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(m=>[m]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let m=0;m<s;m+=a)l.push(r.slice(m,m+a));let d=0,c=l.map(m=>{let h=0,f=0,g=m.map(E=>{let[x,b,y,w]=ot(E);return{elements:E,bounds:[x,b,y,w],width:y-x,height:w-b}});return g.forEach((E,x)=>{h+=E.width,x<g.length-1&&(h+=i),E.height>f&&(f=E.height)}),d+=f,{unitBounds:g,width:h,maxHeight:f}}),u=d+Math.max(0,l.length-1)*i,p=n-u/2;return c.forEach(m=>{let{unitBounds:h,width:f,maxHeight:g}=m,E=t-f/2;h.forEach(x=>{let[b,y]=x.bounds,w=E-b,S=p-y;x.elements.forEach(I=>{o.push(Me(I,{x:I.x+w,y:I.y+S}))}),E+=x.width+i}),p+=g+i}),o};M();import{pointCenter as By,normalizeRadians as Hr,pointFrom as me,pointRotateRads as zt}from"@excalidraw/math";import{MIN_FONT_SIZE as dl,SHIFT_LOCKING_ANGLE as Ur,STICKY_NOTE_MIN_SIZE as $m,rescalePoints as Vm,getFontString as _r}from"@excalidraw/common";var YB=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[p]=n;if(t==="rotation")X(p)||(Ly(p,i,a,l,o),Ge(p,i));else if(t){let m=n[0].id,h=u.get(m),f=e.get(m);if(h&&f){let{nextWidth:g,nextHeight:E}=Gy(h,f,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});Oy(g,E,h,f,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return $(p)&&Ge(p,i),!0}else if(n.length>1){if(t==="rotation")return ky(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:p,nextHeight:m,flipByX:h,flipByY:f,originalBoundingBox:g}=Fy(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return Ry(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:h,flipByY:f,nextWidth:p,nextHeight:m,originalBoundingBox:g}),!0}}return!1},Ly=(e,t,n,i,o)=>{let[r,s,a,l]=q(e,t.getNonDeletedElementsMap()),d=(r+a)/2,c=(s+l)/2,u;Q(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-c,n-d),o&&(u=u+Ur/2,u=u-u%Ur),u=Hr(u));let p=kt(e),m={angle:u};if(Xe(e)&&(m={...m},e.startBinding&&Ke(e,"start",t),e.endBinding&&Ke(e,"end",t)),t.mutateElement(e,m),p){let h=t.getElement(p);if(h&&!W(e)){let{x:f,y:g}=ii(e,h,t.getNonDeletedElementsMap());t.mutateElement(h,{angle:u,x:f,y:g})}}},Km=(e,t,n,i)=>ee(e)||he(e)?{points:Vm(0,t,Vm(1,n,e.points,i),i)}:{},cl=(e,t,n)=>{let i=e.width;if(ge(e)){let s=Oe(e,t);s&&(i=Ct(s,e))}let r=e.fontSize*(n/i);return r<dl?null:{size:r}},Cy=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=cl(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=me(e.x,e.y),u=ll(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=sr(_r({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),p=St(t.originalText,_r(t),Math.abs(u)),m=Ue(p,_r(t),t.lineHeight),h=m.height,f=me(e.x,e.y),g=ll(f,e.width,e.height,u,h,t.angle,i,!1,o),E={width:Math.abs(u),height:Math.abs(m.height),x:g.x,y:g.y,text:p,autoResize:!1};n.mutateElement(t,E)}}},ky=(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+=Ur/2,d-=d%Ur);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!Q(u)){let[p,m,h,f]=q(u,l),g=(p+h)/2,E=(m+f)/2,x=e.get(u.id)?.angle??u.angle,[b,y]=zt(me(g,E),me(s,a),d+x-u.angle),w=X(u)?{points:Pc(u,l)}:{x:u.x+(b-g),y:u.y+(y-E),angle:Hr(d+x)};n.mutateElement(u,w),Ge(u,n,{simultaneouslyUpdated:t}),Xe(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||Ke(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||Ke(u,"end",n)));let S=J(u,l);if(S&&!W(u)){let{x:I,y:A}=ii(u,S,l);n.mutateElement(S,{x:I,y:A,angle:Hr(d+x)})}}n.triggerUpdate()},XB=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?q(t[0],n):ot(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=zt(me(i,o),me(d,c),-u),e){case"n":return zt(me(i-(r+a)/2,o-s),me(0,0),u);case"s":return zt(me(i-(r+a)/2,o-l),me(0,0),u);case"w":return zt(me(i-r,o-(s+l)/2),me(0,0),u);case"e":return zt(me(i-a,o-(s+l)/2),me(0,0),u);case"nw":return zt(me(i-r,o-s),me(0,0),u);case"ne":return zt(me(i-a,o-s),me(0,0),u);case"sw":return zt(me(i-r,o-l),me(0,0),u);case"se":return zt(me(i-a,o-l),me(0,0),u);default:return[0,0]}},jB=(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"},Ny=(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"},ll=(e,t,n,i,o,r,s,a,l)=>{let d=Ny(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)}}},Oy=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if($(n)&&$(i))return Cy(i,n,r,s,d,e,t);let c=e<0?-1:1,u=t<0?-1:1;e=Math.abs(e),t=Math.abs(t);let p=r.getNonDeletedElementsMap(),m=J(n,p),h=ye(n),f;if(h?f=m?Gd({fontSize:m.baseFontSize??m.fontSize,fontFamily:m.fontFamily}):{width:$m,height:$m}:m&&!l&&(f={width:Sd(_r(m),m.lineHeight),height:Id(m.fontSize,m.lineHeight)}),f&&(e=Math.max(e,f.width),t=Math.max(t,f.height),l)){let y=Math.max(e/i.width,t/i.height);e=i.width*y,t=i.height*y}let g={};if(m&&!h){let y=o.get(m.id);if(y&&(g={fontSize:y.fontSize}),l){let w={...n,width:e,height:t},S=cl(m,p,Ct(w,m));if(S===null)return;g={fontSize:S.size}}}e*=c,t*=u;let E=Km(i,e,t,!0),x=me(i.x,i.y);if(ee(i)){let[y,w]=ae(i,o);x=me(y,w)}let b=ll(x,i.width,i.height,e,t,i.angle,s,l,d);if(ee(i)&&E.points){let y=i.x-x[0],w=i.y-x[1];b.x+=y,b.y+=w;let S=E.points[0][0],I=E.points[0][1];b.x+=S,b.y+=I,E.points=E.points.map(A=>me(A[0]-S,A[1]-I))}if(e<0&&(b.x=b.x+e),t<0&&(b.y=b.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]]}),W(n)&&m&&l){let y=Math.abs(e)/n.width*m.fontSize;if(y<dl)return;g.fontSize=y}if(e!==0&&t!==0&&Number.isFinite(b.x)&&Number.isFinite(b.y)){let y={...b,width:Math.abs(e),height:Math.abs(t),...E};Xe(n)&&(n.startBinding&&(y={...y},n.startBinding&&Ke(n,"start",r)),n.endBinding&&(y={...y,endBinding:null})),r.mutateElement(n,y,{informMutation:a,isDragging:!1}),ye(n)?Ti(n,r,{...$s(n,o,s,{proportional:l,fromCenter:d}),bindings:!1}):(m&&g!=null&&r.mutateElement(m,{fontSize:g.fontSize}),ni(n,r,s,l,d,u<0)),Ge(n,r)}},Gy=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=In(t,t.width,t.height,!0),u=me(a,l),p=me(d,c),m=By(u,p),h=zt(me(i,o),m,-t.angle),[f,g,E,x]=In(e,e.width,e.height,!0),b=E-f,y=x-g,w=p[0]-u[0],S=p[1]-u[1],I=w/b,A=S/y;n.includes("e")&&(I=(h[0]-u[0])/b),n.includes("s")&&(A=(h[1]-u[1])/y),n.includes("w")&&(I=(p[0]-h[0])/b),n.includes("n")&&(A=(p[1]-h[1])/y);let T=e.width*I,O=e.height*A;if(s&&(T=2*T-t.width,O=2*O-t.height),r){let v=Math.abs(T)/t.width,N=Math.abs(O)/t.height;if(n.length===1&&(O*=v,T*=N),n.length===2){let k=Math.max(v,N);T=t.width*k*Math.sign(T),O=t.height*k*Math.sign(O)}}return{nextWidth:T,nextHeight:O}},Fy=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(k=>t.get(k.id)),d=l.reduce((k,z)=>{if(!ee(z))return k;let U=kt(z);if(!U)return k;let D=t.get(U)??null;return ge(D)?[...k,{...D,...R.getBoundTextElementPosition(z,D,n)}]:k},[]),c=pn(l.map(k=>k).concat(d)),{minX:u,minY:p,maxX:m,maxY:h,midX:f,midY:g}=c,E=m-u,x=h-p,b={ne:[u,h],se:[u,p],sw:[m,p],nw:[m,h],e:[u,p+x/2],w:[m,p+x/2],n:[u+E/2,h],s:[u+E/2,p]},[y,w]=a?[f,g]:b[i],S=a?2:1,I=Math.max(Math.abs(o-y)/E||0,Math.abs(r-w)/x||0)*S,A=i.includes("e")||i.includes("w")?Math.abs(o-y)*S:E,T=i.includes("n")||i.includes("s")?Math.abs(r-w)*S:x;s&&(A=E*I*Math.sign(o-y),T=x*I*Math.sign(r-w));let O={ne:[o<y,r>w],se:[o<y,r<w],sw:[o>y,r<w],nw:[o>y,r>w],e:[o<y,!1],w:[o>y,!1],n:[!1,r>w],s:[!1,r<w]},[v,N]=O[i].map(k=>k);return{originalBoundingBox:c,nextWidth:A,nextHeight:T,flipByX:v,flipByY:N}},Ry=(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 p=e.reduce((S,I)=>{let A=o.get(I.id);return A&&S.push({orig:A,latest:I}),S},[]),m;if(u)m=u;else{let S=p.reduce((I,{orig:A})=>{if(!ee(A))return I;let T=kt(A);if(!T)return I;let O=o.get(T)??null;return ge(O)?[...I,{...O,...R.getBoundTextElementPosition(A,O,t)}]:I},[]);m=pn([...p.map(({orig:I})=>I),...S])}let{minX:h,minY:f,maxX:g,maxY:E,midX:x,midY:b}=m,y=g-h,w=E-f;if(c===void 0&&d===void 0&&(c=y,d=w),r&&(c===void 0?c=d*(y/w):d===void 0?d=c*(w/y):Math.abs(c/d-y/w)>.001&&(c=d*(y/w))),c&&d){let S=n.includes("e")||n.includes("w")?Math.abs(c)/y:1,I=n.includes("n")||n.includes("s")?Math.abs(d)/w:1,A;n.length===1?A=n.includes("e")||n.includes("w")?S:I:A=Math.max(Math.abs(c)/y||0,Math.abs(d)/w||0);let T={ne:[h,E],se:[h,f],sw:[g,f],nw:[g,E],e:[h,f+w/2],w:[g,f+w/2],n:[h+y/2,E],s:[h+y/2,f]},[O,v]=s?[x,b]:T[n],N=r||p.some(P=>P.latest.angle!==0||$(P.latest)||Uc(P.latest));N&&(S=A,I=A);let[k,z]=[a?-1:1,l?-1:1],U=[];for(let{orig:P,latest:L}of p){if($(P)&&ge(P))continue;let C=P.width*S,_=P.height*I,K=Hr(P.angle*k*z),te=ee(P)||he(P),ne=P.x-O,ie=P.y-v,Ae=a&&!te?C:0,_t=l&&!te?_:0,Ht=O+k*(ne*S+Ae),bn=v+z*(ie*I+_t),pe=Km(P,C*k,_*z,!1),oe={x:Ht,y:bn,width:C,height:_,angle:K,...pe};if(X(P)&&(P.startBinding&&(oe.startBinding={...P.startBinding,fixedPoint:[a?-P.startBinding.fixedPoint[0]+1:P.startBinding.fixedPoint[0],l?-P.startBinding.fixedPoint[1]+1:P.startBinding.fixedPoint[1]]}),P.endBinding&&(oe.endBinding={...P.endBinding,fixedPoint:[a?-P.endBinding.fixedPoint[0]+1:P.endBinding.fixedPoint[0],l?-P.endBinding.fixedPoint[1]+1:P.endBinding.fixedPoint[1]]}),P.fixedSegments&&pe.points&&(oe.fixedSegments=P.fixedSegments.map(De=>({...De,start:pe.points[De.index-1],end:pe.points[De.index]})))),Ne(P)&&(oe.scale=[P.scale[0]*k,P.scale[1]*z]),$(P)){let De=cl(P,t,C);if(!De)return;oe.fontSize=De.size}let ke=o.get(kt(P)??"");if(ke&&!ye(P))if(N){let De=ke.fontSize*A;if(De<dl)return;oe.boundTextFontSize=De}else oe.boundTextFontSize=ke.fontSize;U.push({element:L,update:oe})}let D=U.map(({element:P})=>P),B=new Map(U.map(({element:P})=>[P.id,P]));for(let{element:P,update:{boundTextFontSize:L,...C}}of U){let{angle:_}=C;i.mutateElement(P,C),ye(P)?Ti(P,i,{...$s(P,o,n,{proportional:N,fromCenter:s,flip:a||l}),bindings:{simultaneouslyUpdated:D}}):Ge(P,i,{simultaneouslyUpdated:D}),Xe(P)&&(P.startBinding&&(B.has(P.startBinding.elementId)||Ke(P,"start",i)),P.endBinding&&(B.has(P.endBinding.elementId)||Ke(P,"end",i)));let K=J(P,t);K&&L&&!ye(P)&&(i.mutateElement(K,{fontSize:L,angle:ee(P)?void 0:_}),ni(P,i,n,!0,s,l))}i.triggerUpdate()}};M();import{pointFrom as Tt,pointOnLineSegment as tp,pointRotateRads as Yr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as gl}from"@excalidraw/common";M();import{DEFAULT_TRANSFORM_HANDLE_SPACING as ml}from"@excalidraw/common";import{pointFrom as Zm,pointRotateRads as zy}from"@excalidraw/math";var qm={mouse:8,pen:16,touch:28},_y=16,Jm={e:!0,s:!0,n:!0,w:!0},JB={e:!0,s:!0,n:!0,w:!0},eL={e:!0,s:!0,n:!0,w:!0,rotation:!0},Qm={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},ul={e:!0,s:!0,n:!0,w:!0},xn=(e,t,n,i,o,r,s)=>{let[a,l]=zy(Zm(e+n/2,t+i/2),Zm(o,r),s);return[a-n/2,l-i/2,n,i]},Wr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),pl=e=>Wr(e)?Jm:{},fl=([e,t,n,i,o,r],s,a,l,d={},c=4,u=ml)=>{let p=qm[l],m=p/a.value,h=p/a.value,f=p/a.value,g=p/a.value,E=n-e,x=i-t,b=c/a.value,y=(p-u*2)/(2*a.value),w={nw:d.nw?void 0:xn(e-b-f+y,t-b-g+y,m,h,o,r,s),ne:d.ne?void 0:xn(n+b-y,t-b-g+y,m,h,o,r,s),sw:d.sw?void 0:xn(e-b-f+y,i+b-y,m,h,o,r,s),se:d.se?void 0:xn(n+b-y,i+b-y,m,h,o,r,s),rotation:d.rotation?void 0:xn(e+E/2-m/2,t-b-g+y-_y/a.value,m,h,o,r,s)},S=5*qm.mouse/a.value;return Math.abs(E)>S&&(d.n||(w.n=xn(e+E/2-m/2,t-b-g+y,m,h,o,r,s)),d.s||(w.s=xn(e+E/2-m/2,i+b-y,m,h,o,r,s))),Math.abs(x)>S&&(d.w||(w.w=xn(e-b-f+y,t+x/2-h/2,m,h,o,r,s)),d.e||(w.e=xn(n+b-y,t+x/2-h/2,m,h,o,r,s))),w},ep=(e,t,n,i="mouse",o=Jm)=>{if(e.locked||X(e))return{};if(e.type==="freedraw"||ee(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=ul:s[0]>0&&s[1]<0?o=Qm:s[0]>0&&s[1]>0?o=ul:s[0]<0&&s[1]>0?o=Qm:s[0]<0&&s[1]<0&&(o=ul)}}else Q(e)&&(o={...o,rotation:!0});let r=ee(e)?ml+8:Ne(e)?0:ml;return fl(q(e,n,!0),e.angle,t,i,o,r,Ne(e)?0:void 0)},tL=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return X(i)?!1:ee(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var El=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],Hy=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=ep(e,r,t,s,pl(a));if(l&&El(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let p=d[u];return p?El(p,i,o):!1});if(c.length>0)return c[0];if(Wr(a)){let[u,p,m,h,f,g]=q(e,t);if(!(ee(e)&&e.points.length<=2)){let E=Ne(e)?0:gl/r.value,x=gl/r.value,b=np(Tt(u-E,p-E),Tt(m+E,h+E),Tt(f,g),e.angle);for(let[y,w]of Object.entries(b))if(tp(Tt(i,o),w,x))return y}}return!1},dL=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=Hy(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),cL=([e,t,n,i],o,r,s,a,l)=>{let d=fl([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,pl(l)),c=Object.keys(d).find(u=>{let p=d[u];return p&&El(p,o,r)});if(c)return c;if(Wr(l)){let u=(e+n)/2,p=(t+i)/2,m=gl/s.value,h=np(Tt(e-m,t-m),Tt(n+m,i+m),Tt(u,p),0);for(let[f,g]of Object.entries(h))if(tp(Tt(o,r),g,m))return f}return!1},hl=["ns","nesw","ew","nwse"],Uy=(e,t)=>{let n=hl.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=hl[(n+i)%hl.length]}return e},uL=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=Uy(o,t.angle)),o?`${o}-resize`:""},np=([e,t],[n,i],o,r)=>{let s=Yr(Tt(e,t),o,r),a=Yr(Tt(n,t),o,r),l=Yr(Tt(e,i),o,r),d=Yr(Tt(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};M();var hL=(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")||Kt(t,e).length));M();import{pointFrom as Xr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as Wy,DEFAULT_FONT_SIZE as Yy,TEXT_ALIGN as Xy,VERTICAL_ALIGN as jy,getSizeFromPoints as $y,randomId as Vy,arrayToMap as Ky,assertNever as xl,cloneJSON as sp,getFontString as Zy,getUpdatedTimestamp as qy,isDevEnv as Qy,toBrandedType as Jy,getLineHeight as ew,DEFAULT_STICKY_NOTE_SIZE as ip,isTransparent as tw,DEFAULT_ZOOM as op}from"@excalidraw/common";var jr={width:100,height:0},Kn=100,nw=(e,t,n)=>{let i=ye(e)?Nn(t.strokeColor&&!tw(t.strokeColor)?t.strokeColor:e.strokeColor):null,o=fi({x:0,y:0,textAlign:Xy.CENTER,verticalAlign:jy.MIDDLE,...t,containerId:e.id,strokeColor:i??(t.strokeColor||e.strokeColor),labelPosition:W(e)?Dd:null});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:o.id}),...i&&i!==e.strokeColor?{strokeColor:i}:null}),cr(o,e,n),[e,o]},rp=(e,t,n,i,o,r)=>{let s,a;if(Object.assign(e,{startBinding:e?.startBinding||null,endBinding:e.endBinding||null}),t){let u=t?.width??Kn,p=t?.height??Kn,m;t.id&&(m=i.getElement(t.id),m||console.error(`No element for start binding with id ${t.id} found`));let h=t.x||e.x-u,f=t.y||e.y-p/2,g=m?m.type:t.type;if(g){if(g==="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}`),s=fi({x:h,y:f,type:"text",...m,...t,text:E}),Object.assign(s,{x:t.x||e.x-s.width,y:t.y||e.y-s.height/2})}else switch(g){case"rectangle":case"ellipse":case"diamond":{s=Ni({x:h,y:f,width:u,height:p,...m,...t,type:g});break}default:xl(e,`Unhandled element start type "${t.type}"`,!0)}$t(e,s,"orbit","start",o,r)}}if(n){let u=n?.height??Kn,p=n?.width??Kn,m;n.id&&(m=i.getElement(n.id),m||console.error(`No element for end binding with id ${n.id} found`));let h=n.x||e.x+e.width,f=n.y||e.y-u/2,g=m?m.type:n.type;if(g){if(g==="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}`),a=fi({x:h,y:f,type:"text",...m,...n,text:E}),Object.assign(a,{y:n.y||e.y-a.height/2})}else switch(g){case"rectangle":case"ellipse":case"diamond":{a=Ni({x:h,y:f,width:p,height:u,...m,...n,type:g});break}default:xl(e,`Unhandled element end type "${g}"`,!0)}$t(e,a,"orbit","end",o,r)}}if(e.points.length<2)return{linearElement:e,startBoundElement:s,endBoundElement:a};let l=e.points.length-1,d=.5,c=sp(e.points);return e.points[l][0]>e.points[l-1][0]&&(c[0][0]=d,c[l][0]-=d),e.points[l][0]<e.points[l-1][0]&&(c[0][0]=-d,c[l][0]+=d),e.points[l][1]>e.points[l-1][1]&&(c[0][1]=d,c[l][1]-=d),e.points[l][1]<e.points[l-1][1]&&(c[0][1]=-d,c[l][1]+=d),Object.assign(e,R.getNormalizeElementPointsAndCoords({...e,points:c})),{linearElement:e,startBoundElement:s,endBoundElement:a}},bl=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>wa(Array.from(this.excalidrawElements.values()));getElementsMap=()=>Jy(Ky(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},BL=(e,t)=>{if(!e)return[];let n=sp(e),i=new bl,o=new Map,r=new Map,s=qy();for(let d of n){let c,u=d.id;switch(t?.regenerateIds!==!1&&Object.assign(d,{id:Vy(),created:s}),d.type){case"rectangle":case"ellipse":case"diamond":{let m=d?.label?.text&&d.width===void 0?0:d?.width||Kn,h=d?.label?.text&&d.height===void 0?0:d?.height||Kn;c=Ni({...d,width:m,height:h});break}case"line":{let m=d.width||jr.width,h=d.height||jr.height;c=_u({width:m,height:h,points:[Xr(0,0),Xr(m,h)],...d});break}case"arrow":{let m=d.width||jr.width,h=d.height||jr.height;c=Lr({width:m,height:h,endArrowhead:"arrow",points:[Xr(0,0),Xr(m,h)],...d,type:"arrow"}),Object.assign(c,$y(c.points));break}case"text":{let m=d?.fontFamily||Wy,h=d?.fontSize||Yy,f=d?.lineHeight||ew(m),g=d.text??"",E=oo(g),x=Ue(E,Zy({fontFamily:m,fontSize:h}),f);c=fi({width:x.width,height:x.height,fontFamily:m,fontSize:h,...d});break}case"image":{c=Hu({width:d?.width||Kn,height:d?.height||Kn,...d});break}case"frame":{c=Gu({x:0,y:0,...d});break}case"magicframe":{c=Fu({x:0,y:0,...d});break}case"freedraw":{c=zu({...d});break}case"iframe":{c=Ou({...d});break}case"stickynote":{let m=d.width||ip,h=d.height||ip;c=_a(Br({...d,type:"stickynote",width:m,height:h,baseHeight:d.baseHeight??h}));break}case"embeddable":{c=Nu({...d});break}default:c=d,xl(d,`Unhandled element type "${d.type}"`,!0)}i.getElement(c.id)?console.error(`Duplicate id found for ${c.id}`):(i.add(c),o.set(c.id,d),u&&r.set(u,c.id))}let a=i.getElementsMap(),l=new _i(a);for(let[d,c]of o){let u=i.getElement(d);switch(c.type){case"rectangle":case"ellipse":case"diamond":case"stickynote":case"arrow":{if(c.label?.text){let[p,m]=nw(u,c?.label,l);if(i.add(p),i.add(m),W(p)){let h=c.type==="arrow"?c?.start:void 0,f=c.type==="arrow"?c?.end:void 0;if(h&&h.id){let b=r.get(h.id);b&&Object.assign(h,{id:b})}if(f&&f.id){let b=r.get(f.id);b&&Object.assign(f,{id:b})}let{linearElement:g,startBoundElement:E,endBoundElement:x}=rp(p,h,f,i,l,op);p=g,i.add(g),i.add(E),i.add(x)}}else switch(c.type){case"arrow":{let{start:p,end:m}=c;if(p&&p.id){let E=r.get(p.id);Object.assign(p,{id:E})}if(m&&m.id){let E=r.get(m.id);Object.assign(m,{id:E})}let{linearElement:h,startBoundElement:f,endBoundElement:g}=rp(u,p,m,i,l,op);i.add(h),i.add(f),i.add(g);break}}break}}}for(let[d,c]of o){if(c.type!=="frame"&&c.type!=="magicframe")continue;let u=i.getElement(d);if(!u)throw new Error(`Excalidraw element with id ${d} doesn't exist`);let p=[];c.children.forEach(S=>{let I=r.get(S);if(!I)throw new Error(`Element with ${S} wasn't mapped correctly`);let A=i.getElement(I);if(!A)throw new Error(`Frame element with id ${I} doesn't exist`);Object.assign(A,{frameId:u.id}),A?.boundElements?.forEach(T=>{let O=i.getElement(T.id);if(!O)throw new Error(`Bound element with id ${T.id} doesn't exist`);Object.assign(O,{frameId:u.id}),p.push(O)}),p.push(A)});let[m,h,f,g]=ot(p),E=10;m=m-E,h=h-E,f=f+E,g=g+E;let x=u?.x||m,b=u?.y||h,y=u?.width||f-m,w=u?.height||g-h;Object.assign(u,{x,y:b,width:y,height:w}),Qy()&&c.children.length&&(u?.x||u?.y||u?.width||u?.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()};M();var OL=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return Xm(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 R.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};M();var iw=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}},RL=e=>{let t=iw(e);return t===null?null:t};M();import{getBoundsFromPoints as cp,getElementAbsoluteCoords as ow}from"@excalidraw/element/bounds";import{newArrowElement as ap,newElement as rw,newLinearElement as $r}from"@excalidraw/element/newElement";import{ELEMENT_PENDING_DRAW_SHAPE_OPACITY as sw,getStrokeWidthByKey as Vr,ROUNDNESS as lp}from"@excalidraw/common";import{convexHull as aw,distanceToLineSegment as lw,elongation as dw,kurtosis as dp,lineSegment as cw,orientPrincipalAxes as uw,pointFrom as st,polygonArea as mw,principalAxes as pw,principalCoords as fw,skewness as hw}from"@excalidraw/math";var gw=64,Ew=25,xw=.15,bw=.25,yw=.5,ww=.15,Pw=.3,Sw=1.5,Ui=3;function Iw(e,t){let n=0;for(let a=1;a<e.length;a++)n+=Math.hypot(e[a][0]-e[a-1][0],e[a][1]-e[a-1][1]);let i=n/(t-1),o=0,r=[e[0]],s=e[0];for(let a=1;a<e.length;a++){let l=e[a],d=Math.hypot(l[0]-s[0],l[1]-s[1]);if(o+d>=i){let c=i-o;for(;c<=d+1e-10;){let u=c/d,p=[s[0]+u*(l[0]-s[0]),s[1]+u*(l[1]-s[1])];if(r.push(p),r.length===t)return r;s=p,o=0,c+=i}o=d-(c-i)}else o+=d;s=l}for(;r.length<t;)r.push(e[e.length-1]);return r}function Mw(e){let t=e[0],n=t,i=0;for(let s of e){let a=Math.hypot(s[0]-t[0],s[1]-t[1]);a>i&&(i=a,n=s)}if(i===0)return 0;let o=cw(t,n),r=0;for(let s of e)Math.hypot(s[0]-n[0],s[1]-n[1])<=yw*i||(r=Math.max(r,lw(s,o)));return r/i}function Tw(e){let t=[];for(let n=Ui;n<e.length-Ui;n++){let[i,o]=e[n-Ui],[r,s]=e[n],[a,l]=e[n+Ui],d=r-i,c=s-o,u=a-r,p=l-s;t.push(Math.abs(Math.atan2(d*p-c*u,d*u+c*p)))}return t}function Aw(e){let t=Tw(e),n=t.reduce((r,s)=>r+s,0);if(n===0)return 0;let i=new Array(t.length).fill(!1),o=0;for(let r=0;r<4;r++){let s=-1,a=0;for(let l=0;l<t.length;l++)!i[l]&&t[l]>a&&(a=t[l],s=l);if(s<0)break;for(let l=s-Ui;l<=s+Ui;l++)l>=0&&l<t.length&&!i[l]&&(o+=t[l],i[l]=!0)}return o/n}function Dw(e){let t=Iw(e,gw),n=0;for(let p=1;p<t.length;p++)n+=Math.hypot(t[p][0]-t[p-1][0],t[p][1]-t[p-1][1]);let i=Math.hypot(t[t.length-1][0]-t[0][0],t[t.length-1][1]-t[0][1]),o=uw(t,pw(t)),r=fw(t,o).map(([p])=>p),s=aw(t),[a,l,d,c]=cp(t),u=(d-a)*(c-l);return{gapRatio:n>0?i/n:0,elongation:dw(o),majorSkew:hw(r),hullFillRatio:u>0?mw(s)/u:0,cornerTurnShare:Aw(t),kurtosisProduct:dp(t.map(([p])=>p))*dp(t.map(([,p])=>p)),shaftDeviationRatio:Mw(t)}}var vw=[{type:"rectangle",hullFillRatio:1,cornerTurnShare:.95,kurtosisProduct:1.83},{type:"diamond",hullFillRatio:.5,cornerTurnShare:.95,kurtosisProduct:3.24},{type:"ellipse",hullFillRatio:Math.PI/4,cornerTurnShare:.55,kurtosisProduct:2.25}],Bw=.2,Lw=.2,Cw=.7;function kw(e){let t="freedraw",n=Sw;for(let i of vw){let o=Math.hypot((e.hullFillRatio-i.hullFillRatio)/Bw,(e.cornerTurnShare-i.cornerTurnShare)/Lw,(e.kurtosisProduct-i.kurtosisProduct)/Cw);o<n&&(n=o,t=i.type)}return t}function Nw(e){return e.elongation>bw||e.shaftDeviationRatio>ww?"freedraw":Math.abs(e.majorSkew)>=Pw?"arrow":"line"}function Ow(e){return e.gapRatio>xw?Nw(e):kw(e)}function Gw(e,t,n){let[i,o,r,s]=t,a=r-i,l=s-o;if(a===0&&l===0)return e[e.length-1];let d=[st(i,o),st((i+r)/2,o),st(r,o),st(r,(o+s)/2),st(r,s),st((i+r)/2,s),st(i,s),st(i,(o+s)/2)],c=-1,u=st(r,s);for(let h of d){let f=Math.hypot(h[0]-n[0],h[1]-n[1]);f>c&&(c=f,u=h)}let p=1/0,m=e[e.length-1];for(let h of e){let f=Math.hypot(h[0]-u[0],h[1]-u[1]);f<p&&(p=f,m=h)}return m}var Fw=(e,t,n=1)=>{typeof window<"u"&&(window.LAST_POINTS=e.map(([u,p])=>st(u,p)));let i=cp(e),[o,r,s,a]=i,l=Math.max(s-o,a-r);if(e.length<3||l*n<Ew)return{type:"freedraw",points:e,boundingBox:i};let d=Ow(Dw(e));return{type:t?.type==="arrow"&&d!=="arrow"?"freedraw":d,points:e,boundingBox:i}},Rw=(e,t,n,i,o)=>{let r=Fw(e,i,t.zoom.value),s=r.boundingBox,[a,l,d,c]=s,p=(o??Ma([...n.values()])).find(h=>{let[f,g,E,x]=ow(h,n);return f<=a&&g<=l&&E>=d&&x>=c})?.id??null,m=t.currentItemRoundness==="round"?{type:Vo(r.type)?lp.ADAPTIVE_RADIUS:lp.PROPORTIONAL_RADIUS}:null;switch(r.type){case"rectangle":case"diamond":case"ellipse":return rw({type:r.type,x:r.boundingBox[0],y:r.boundingBox[1],width:r.boundingBox[2]-r.boundingBox[0],height:r.boundingBox[3]-r.boundingBox[1],groupIds:[],angle:0,frameId:p,roundness:m,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Vr(r.type,t.currentItemStrokeWidthKey)});case"arrow":{let[h,f]=r.points[0],[g,E]=Gw(r.points,r.boundingBox,r.points[0]),x=st(g-h,E-f);if(Math.hypot(g-r.points[0][0],E-r.points[0][1])<60){let S=$r({type:"line",x:h,y:f,points:[st(r.points[0][0]-h,r.points[0][1]-f),x],groupIds:[],frameId:p,locked:!1,angle:0,roundness:m,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Vr(r.type,t.currentItemStrokeWidthKey)}),I=R.getNormalizeElementPointsAndCoords(S);return $r({...S,...I})}let y=ap({type:"arrow",x:h,y:f,startArrowhead:t.currentItemStartArrowhead,endArrowhead:t.currentItemEndArrowhead,points:[st(r.points[0][0]-h,r.points[0][1]-f),x],groupIds:[],frameId:p,locked:!1,angle:0,roundness:m,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Vr(r.type,t.currentItemStrokeWidthKey)}),w=R.getNormalizeElementPointsAndCoords(y);return ap({...y,...w})}case"line":{let[h,f]=r.points[0],g=r.points[r.points.length-1],E=$r({type:r.type,x:h,y:f,points:[st(r.points[0][0]-h,r.points[0][1]-f),st(g[0]-h,g[1]-f)],groupIds:[],frameId:p,locked:!1,angle:0,roundness:m,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Vr(r.type,t.currentItemStrokeWidthKey)}),x=R.getNormalizeElementPointsAndCoords(E);return $r({...E,...x})}}},zw=(e,t)=>{if(!e||e.type!==t.type||e.x!==t.x||e.y!==t.y||e.width!==t.width||e.height!==t.height||e.angle!==t.angle)return!1;if(ee(e)&&ee(t)){if(e.points.length!==t.points.length)return!1;for(let n=0;n<e.points.length;n++)if(e.points[n][0]!==t.points[n][0]||e.points[n][1]!==t.points[n][1])return!1}return!0},VL=(e,t)=>{if(e.state.activeTool.type==="autoshape"){e.drawShape.trail.addPointToPath(t.x,t.y);let n=e.drawShape.trail.getCurrentPoints();if(n.length>=3){let i=Rw(n,e.state,e.scene.getNonDeletedElementsMap(),e.state.newElement,e.scene.getNonDeletedFramesLikes());if(i&&!Re(i)){let o=e.state.newElement,r={...i,id:o?.type===i.type?o.id:i.id,created:o?.type===i.type?o.created:i.created,seed:1,opacity:sw,isDeleted:!1};zw(o,r)||e.setState({newElement:r})}else e.state.newElement!==null&&e.setState({newElement:null})}return!0}return!1};var JL=e=>e.reduce((t,n)=>t+n.version,0),sm=e=>{let t=5381;for(let n of _w(e))t=(t<<5)+t+n.versionNonce;return t>>>0},am=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},je=e=>!e.isDeleted,e2=e=>e.filter(t=>je(t)&&!Bu(t)),Ci=e=>e.filter(je);export{jn as AppStateDelta,bg as BASE_ARROW_MIN_LENGTH,Bn as BASE_BINDING_GAP,ce as BASE_PADDING,Rn as BindableElement,Fn as BoundElement,gt as CaptureUpdateAction,Dd as DEFAULT_BOUND_TEXT_LABEL_POSITION,_x as DEFAULT_BUCKET_FILL_OPTIONS,gT as DEFAULT_LINK_SIZE,Jm as DEFAULT_OMIT_SIDES,V as Delta,Ka as DurableIncrement,Ra as ElementBounds,$n as ElementsDelta,Za as EphemeralIncrement,po as FOCUS_POINT_SIZE,Lm as FlowChartCreator,Bm as FlowChartNavigator,ve as HEADING_DOWN,ze as HEADING_LEFT,Ee as HEADING_RIGHT,qe as HEADING_UP,hx as INVISIBLY_SMALL_ELEMENT_SIZE,ba as InvalidFractionalIndexError,R as LinearElementEditor,Ye as MINIMAL_CROP_SIZE,eL as OMIT_SIDES_FOR_FRAME,JB as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,_i as Scene,Qe as ShapeCache,im as Store,Mo as StoreChange,qa as StoreDelta,Gr as StoreIncrement,Vn as StoreSnapshot,ut as aabbForElement,fE as addElementsToFrame,yy as addNewNodes,tM as addToGroup,gA as alignElements,Mg as avoidRectangularCorner,$t as bindBindingElement,kI as bindBindingElementToFixedPoint,qc as bindElementsToFramesAfterDuplication,yg as bindOrUnbindBindingElement,DI as bindOrUnbindBindingElements,As as bindPointToSnapToElementOutline,wc as bindingProperties,Ta as boundsContainBounds,Bs as bumpVersion,bc as calculateFixedPointForElbowArrowBinding,si as calculateFixedPointForNonElbowArrowBinding,e1 as canApplyRoundnessTypeToElement,dd as canBecomePolygon,jd as canChangeRoundness,Jb as canCreateLinkFromElements,ZS as canHaveArrowheads,Wr as canResizeFromSides,Mi as charWidth,fe as compareHeading,ii as computeBoundTextPosition,tD as computeBucketFillPolygon,Fs as computeContainerDimensionForBoundText,j1 as containsCJK,BL as convertToExcalidrawElements,Rw as convertToShape,VL as convertToShapeHandlePointerMoveFromPointerDown,Lv as createPlaceholderEmbeddableLabel,nl as createSrcDoc,jP as cropElement,Tn as deconstructDiamondElement,wi as deconstructLinearOrFreeDrawElement,Mn as deconstructRectanguloidElement,Va as deepCopyElement,yv as defaultGetElementLinkFromSelection,z1 as detectLineHeight,tn as distanceToElement,iv as distributeElements,yt as doBoundsIntersect,hv as dragNewElement,Qb as dragNewTextElement,pv as dragSelectedElements,lb as duplicateElement,xD as duplicateElements,eM as editGroupForSelectedElement,re as elementCenterPoint,_n as elementOverlapsWithFrame,go as elementWithCanvasCache,Un as elementsAreInFrameBounds,Hc as elementsAreInSameGroup,Xc as elementsOverlappingBBox,kv as embeddableURLValidator,iE as excludeElementsInFramesFromSelection,$M as filterElementsEligibleAsFrameChildren,LI as fixBindingsAfterDeletion,yc as fixDuplicatedBindingsAfterDuplication,Es as flipHeading,JM as frameAndChildrenSelectedTogether,Xd as generateLinearCollisionShape,ht as generateRoughOptions,xM as getActiveTextElement,sa as getAllHoveredElementAtPoint,Js as getAllMidpoints,Id as getApproxMinLineHeight,Sd as getApproxMinLineWidth,Pc as getArrowLocalFixedPoints,lx as getArrowheadAngle,RL as getArrowheadForPicker,rt as getArrowheadPoints,ax as getArrowheadSize,TS as getBaseFontSize,AS as getBaseFontSizeUpdate,Be as getBindingGap,CI as getBindingSideMidPoint,ca as getBindingStrategyForDraggingBindingElementEndpoints,J as getBoundTextElement,kt as getBoundTextElementId,aS as getBoundTextElementPosition,ro as getBoundTextMaxHeight,Ct as getBoundTextMaxWidth,mi as getBoundsFromPoints,nn as getCenterForBounds,SS as getColorTargetElement,IS as getColorUpdate,pn as getCommonBoundingBox,ot as getCommonBounds,mE as getCommonFrameId,rS as getContainerCenter,zs as getContainerCoords,Oe as getContainerElement,Hn as getContainingFrame,cn as getCornerRadius,Er as getCubicBezierCurveBound,uL as getCursorForResizingElement,bE as getDefaultFrameName,t1 as getDefaultRoundnessTypeForElement,Yd as getDiamondBaseCorners,Di as getDiamondPoints,fv as getDragOffsetXY,JT as getDraggedElementsBounds,ea as getElbowArrowSnapMidPoint,q as getElementAbsoluteCoords,ae as getElementBounds,Bi as getElementLineSegments,ga as getElementPointsCoords,NE as getElementRenderOffset,bu as getElementShape,dL as getElementWithTransformHandleType,Qc as getElementsCompletelyInFrame,it as getElementsInGroup,jM as getElementsInNewFrame,XM as getElementsInResizingFrame,zM as getElementsIntersectingFrame,QM as getElementsOverlappingFrame,Yc as getElementsWithinSelection,Bv as getEmbedLink,HA as getEndpointBoundTextDragAnchor,$P as getFlipAdjustedCropPosition,zn as getFrameChildren,pE as getFrameChildrenInsertionIndex,Ma as getFrameLikeElements,qM as getFrameLikeTitle,sc as getFreedrawFillPolygon,ac as getFreedrawMaxStrokeRadius,bT as getFreedrawOutlineAsSegments,yu as getFreedrawOutlinePoints,wu as getFreedrawStrokeCenterPoints,_e as getGlobalFixedPointForBindableElement,Dg as getGlobalFixedPoints,bd as getHeadingForElbowArrowSnap,rn as getHoveredElementForBinding,IB as getInitializedImageElements,ar as getLineHeightInPx,Ln as getLineWidth,HS as getLinearElementPathSegments,n1 as getLinearElementSubType,wv as getLinkIdAndTypeFromSelection,Fc as getLockedLinearCursorAlignSize,Zf as getMaxCharWidth,iM as getMaximumGroups,H1 as getMinCharWidth,fo as getMinMaxXYFromCurvePathOps,sr as getMinTextElementWidth,Wc as getNewGroupIdsForDuplication,Ci as getNonDeletedElements,_c as getNonDeletedGroupIds,dA as getNormalizedDimensions,zi as getObservedAppState,pl as getOmitSidesForEditorInterface,N1 as getOriginalContainerHeightFromCache,za as getPerfectElementSize,so as getPositionAfterHeightChange,QT as getRectangleBoxAbsoluteCoords,hT as getRenderElementWithPositionOverride,jB as getResizeArrowDirection,XB as getResizeOffsetXY,In as getResizedElementAbsoluteCoords,YM as getRootElements,JL as getSceneVersion,Kt as getSelectedElements,Pr as getSelectedElementsByGroup,xa as getSelectedGroupForElement,Qg as getSelectedGroupIdForElement,Zg as getSelectedGroupIds,EM as getSelectionStateForElements,ua as getSimultaneouslyUpdatedElementIds,Kh as getSnapOutlineMidPoint,Ys as getStickyNoteCornerRadius,kh as getStickyNoteDateLabel,Od as getStickyNoteFooter,Fd as getStickyNoteLayout,Gd as getStickyNoteMinSize,Xs as getStickyNotePathCommands,Lh as getStickyNoteRenderPoints,$s as getStickyNoteResizeIntent,gM as getTargetElements,gE as getTargetFrame,Ha as getTextAnchorRatios,zA as getTextBindingForArrowEndpoint,sS as getTextElementAngle,_s as getTextElementWithAccuratePosition,uS as getTextFromElements,Kf as getTextHeight,Md as getTextWidth,cL as getTransformHandleTypeFromCoords,ep as getTransformHandles,fl as getTransformHandlesFromCoords,RA as getUnboundArrowEndpointAtPoint,td as getUncroppedImageElement,ms as getUncroppedWidthAndHeight,fM as getVisibleAndNonSelectedElements,e2 as getVisibleElements,eA as getVisibleSceneBounds,rh as getWrappedTextLines,WM as groupByFrameLikes,HM as groupsAreAtLeastIntersectingTheFrame,UM as groupsAreCompletelyOutOfFrame,ni as handleBindTextResize,Xm as handleFocusPointDrag,xB as handleFocusPointHover,gB as handleFocusPointPointerDown,EB as handleFocusPointPointerUp,oi as hasBackground,Wt as hasBoundTextElement,tL as hasBoundingBox,YS as hasFillStyle,VS as hasFreedrawMode,$S as hasRoughness,XS as hasStrokeColor,Zh as hasStrokeStyle,jS as hasStrokeWidth,sm as hashElementsVersion,am as hashString,dt as headingForPoint,Pi as headingForPointFromElement,Lt as headingForPointIsHorizontal,ct as headingIsHorizontal,h1 as headingIsVertical,ag as hitElementBoundText,sg as hitElementBoundingBox,uI as hitElementBoundingBoxOnly,Ot as hitElementItself,pt as intersectElementWithLineSegment,JP as isArrowBoundToElement,W as isArrowElement,Pe as isBindableElement,aa as isBindableElementInsideOtherBindable,Xe as isBindingElement,uf as isBindingElementType,jt as isBindingEnabled,ge as isBoundToContainer,Qu as isBucketFillCompatible,_M as isCursorInFrame,df as isCurvedArrow,X as isElbowArrow,lA as isElementCompletelyInViewport,Ia as isElementContainingFrame,eu as isElementInFrame,qg as isElementInGroup,jc as isElementInViewport,Li as isElementIntersectingFrame,Pv as isElementLink,i1 as isEligibleFrameChildType,id as isEmbeddableElement,_A as isEndpointBoundText,sd as isExcalidrawElement,vg as isFixedPoint,ad as isFlowchartNodeElement,zr as isFocusPointVisible,$o as isFrameElement,Q as isFrameLikeElement,he as isFreeDrawElement,af as isFreeDrawElementType,vy as isHTMLSVGElement,Xo as isIframeElement,jo as isIframeLikeElement,Ne as isImageElement,Uc as isInGroup,ei as isInitializedImageElement,Bu as isInvisiblySmallElement,Re as isLineElement,ee as isLinearElement,cf as isLinearElementType,od as isMagicFrameElement,R1 as isMeasureTextSupported,$v as isNodeInFlowchart,je as isNonDeletedElement,Nt as isPathALoop,Je as isPointInElement,eo as isRectangularElement,rd as isRectanguloidElement,nD as isRestylableFill,Kg as isSelectedViaGroup,lf as isSharpArrow,QP as isSimpleArrow,hM as isSomeElementSelected,pr as isStickyNoteBoundText,ye as isStickyNoteElement,mf as isTextBindableContainer,$ as isTextElement,Vo as isUsingAdaptiveRadius,ld as isUsingProportionalRadius,ps as isValidPolygon,cS as isValidTextContainer,Dy as loadHTMLImageElement,Ea as makeNextSelectedElementIds,On as maxBindingDistance_simple,OL as maybeHandleArrowPointlikeDrag,Cv as maybeParseEmbedSrc,cl as measureFontSizeFromWidth,Ue as measureText,rB as moveAllLeft,sB as moveAllRight,Rm as moveArrowAboveBindable,iB as moveOneLeft,oB as moveOneRight,He as mutateElement,Lr as newArrowElement,Ni as newElement,Me as newElementWith,Nu as newEmbeddableElement,Gu as newFrameElement,zu as newFreeDrawElement,Ou as newIframeElement,Hu as newImageElement,_u as newLinearElement,Fu as newMagicFrameElement,Br as newStickyNoteElement,fi as newTextElement,iw as normalizeArrowhead,ib as normalizeBoundElementsOrder,Ju as normalizeElementOrder,$e as normalizeFixedPoint,MB as normalizeSVG,AA as normalizeStickyNote,Ws as normalizeStickyNoteBackgroundColor,js as normalizeStickyNoteFontSize,_a as normalizeStickyNoteGeometry,Nn as normalizeStickyNoteStrokeColor,ku as normalizeStickyNoteStyle,oo as normalizeText,Ir as omitGroupsContainingFrameLikes,uE as omitPartialGroups,Vc as orderByFractionalIndex,io as originalContainerCache,Sv as parseElementLinkFromURL,ih as parseTokens,Xt as pointInsideBounds,ux as pointInsideBoundsInclusive,BB as positionElementsOnGrid,ta as projectFixedPointOntoDiagonal,vI as reanchorBindingsToOutline,Fw as recognizeShape,bD as reconcileDuplicatedElements,cr as redrawTextBoundingBox,DA as refreshTextDimensions,DS as relayoutStickyNotes,hE as removeAllElementsFromFrame,Jc as removeElementsFromFrame,nM as removeFromSelectedGroups,xT as renderElement,ET as renderSelectionElement,$u as rendersOpaqueFill,VM as replaceAllElementsInFrame,Km as rescalePointsInElement,wd as resetOriginalContainerCache,Ry as resizeMultipleElements,Oy as resizeSingleElement,Cy as resizeSingleTextElement,Hy as resizeTest,OE as resolveElementRenderState,Vg as selectGroup,Rc as selectGroupsForSelectedElements,zc as selectGroupsFromGivenElements,_1 as setCustomTextMetricsProvider,lS as shouldAllowVerticalAlign,ZM as shouldApplyFrameClip,gr as shouldTestInside,hL as showSelectedShapeActions,dS as suppportsHorizontalAlign,wa as syncInvalidIndices,Kc as syncInvalidIndicesImmutable,di as syncMovedIndices,MS as syncStickyNoteInk,Gc as toggleLinePolygonState,KS as toolIsArrow,YB as transformElements,Ke as unbindBindingElement,BI as updateBindings,Ge as updateBoundElements,Gt as updateBoundPoint,Ii as updateElbowArrowPoints,KM as updateFrameMembershipOfSelectedElements,SB as updateImageCache,yd as updateOriginalContainerCache,Ti as updateStickyNoteLayout,xd as validateElbowPoints,aE as validateFractionalIndices,Bt as vectorToHeading,St as wrapText};