@excalidraw/element 0.18.0-9036812b6 → 0.18.0-9ba0f5d
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.
- package/dist/dev/index.js +3846 -2092
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +17 -17
- package/dist/types/common/src/bounds.d.ts +10 -0
- package/dist/types/common/src/colors.d.ts +59 -39
- package/dist/types/common/src/constants.d.ts +33 -26
- package/dist/types/common/src/editorInterface.d.ts +34 -0
- package/dist/types/common/src/font-metadata.d.ts +1 -3
- package/dist/types/common/src/index.d.ts +2 -0
- package/dist/types/common/src/keys.d.ts +1 -1
- package/dist/types/common/src/utility-types.d.ts +0 -1
- package/dist/types/common/src/utils.d.ts +49 -34
- package/dist/types/element/src/Scene.d.ts +9 -5
- package/dist/types/element/src/binding.d.ts +58 -44
- package/dist/types/element/src/bounds.d.ts +3 -11
- package/dist/types/element/src/collision.d.ts +6 -2
- package/dist/types/element/src/comparisons.d.ts +7 -7
- package/dist/types/element/src/delta.d.ts +6 -3
- package/dist/types/element/src/dragElements.d.ts +3 -3
- package/dist/types/element/src/duplicate.d.ts +3 -3
- package/dist/types/element/src/fractionalIndex.d.ts +2 -2
- package/dist/types/element/src/frame.d.ts +5 -1
- package/dist/types/element/src/heading.d.ts +2 -1
- package/dist/types/element/src/image.d.ts +1 -11
- package/dist/types/element/src/index.d.ts +2 -3
- package/dist/types/element/src/linearElementEditor.d.ts +16 -20
- package/dist/types/element/src/mutateElement.d.ts +3 -1
- package/dist/types/element/src/newElement.d.ts +6 -6
- package/dist/types/element/src/positionElementsOnGrid.d.ts +2 -0
- package/dist/types/element/src/renderElement.d.ts +4 -7
- package/dist/types/element/src/resizeElements.d.ts +10 -10
- package/dist/types/element/src/resizeTest.d.ts +6 -5
- package/dist/types/element/src/selection.d.ts +3 -7
- package/dist/types/element/src/shape.d.ts +8 -7
- package/dist/types/element/src/store.d.ts +6 -1
- package/dist/types/element/src/textElement.d.ts +1 -1
- package/dist/types/element/src/textMeasurements.d.ts +1 -3
- package/dist/types/{excalidraw/data → element/src}/transform.d.ts +3 -3
- package/dist/types/element/src/transformHandles.d.ts +8 -27
- package/dist/types/element/src/typeChecks.d.ts +4 -7
- package/dist/types/element/src/types.d.ts +7 -11
- package/dist/types/element/src/utils.d.ts +5 -2
- package/dist/types/element/src/visualdebug.d.ts +59 -0
- package/dist/types/element/src/zindex.d.ts +7 -1
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +93 -136
- package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -7
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +67 -96
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +402 -758
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +86 -856
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +32 -47
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +110 -159
- package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +28 -45
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +66 -95
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +33 -48
- package/dist/types/excalidraw/actions/actionExport.d.ts +144 -1104
- package/dist/types/excalidraw/actions/actionFinalize.d.ts +10 -394
- package/dist/types/excalidraw/actions/actionFlip.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionFrame.d.ts +227 -322
- package/dist/types/excalidraw/actions/actionGroup.d.ts +70 -107
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +140 -195
- package/dist/types/excalidraw/actions/actionLink.d.ts +30 -45
- package/dist/types/excalidraw/actions/actionMenu.d.ts +27 -410
- package/dist/types/excalidraw/actions/actionNavigate.d.ts +18 -359
- package/dist/types/excalidraw/actions/actionProperties.d.ts +129 -2488
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +35 -54
- package/dist/types/excalidraw/actions/actionStyles.d.ts +32 -47
- package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +32 -47
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +32 -47
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +25 -42
- package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +32 -47
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +32 -47
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +33 -48
- package/dist/types/excalidraw/actions/actionZindex.d.ts +2 -3
- package/dist/types/excalidraw/actions/index.d.ts +2 -2
- package/dist/types/excalidraw/actions/register.d.ts +2 -2
- package/dist/types/excalidraw/actions/types.d.ts +4 -4
- package/dist/types/excalidraw/appState.d.ts +12 -7
- package/dist/types/excalidraw/clipboard.d.ts +55 -16
- package/dist/types/excalidraw/components/Actions.d.ts +22 -5
- package/dist/types/excalidraw/components/App.d.ts +67 -65
- package/dist/types/excalidraw/components/Card.d.ts +1 -3
- package/dist/types/excalidraw/components/ColorPicker/ColorInput.d.ts +2 -4
- package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +0 -1
- package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -0
- package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -1
- package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -1
- package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +0 -1
- package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +0 -1
- package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
- package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -3
- package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -2
- package/dist/types/excalidraw/components/DarkModeToggle.d.ts +1 -1
- package/dist/types/excalidraw/components/DefaultSidebar.d.ts +9 -13
- package/dist/types/excalidraw/components/ElementLinkDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/Ellipsify.d.ts +1 -2
- package/dist/types/excalidraw/components/ErrorDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +1 -2
- package/dist/types/excalidraw/components/EyeDropper.d.ts +0 -1
- package/dist/types/excalidraw/components/FilledButton.d.ts +2 -1
- package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +2 -1
- package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +3 -1
- package/dist/types/excalidraw/components/FontPicker/keyboardNavHandlers.d.ts +0 -1
- package/dist/types/excalidraw/components/HelpDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/HintViewer.d.ts +4 -3
- package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
- package/dist/types/excalidraw/components/LayerUI.d.ts +2 -1
- package/dist/types/excalidraw/components/LibraryMenuControlButtons.d.ts +1 -1
- package/dist/types/excalidraw/components/LibraryMenuHeaderContent.d.ts +1 -2
- package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
- package/dist/types/excalidraw/components/LibraryUnit.d.ts +2 -3
- package/dist/types/excalidraw/components/LoadingMessage.d.ts +0 -1
- package/dist/types/excalidraw/components/MobileMenu.d.ts +3 -5
- package/dist/types/excalidraw/components/MobileToolBar.d.ts +10 -0
- package/dist/types/excalidraw/components/Modal.d.ts +0 -1
- package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirm.d.ts +1 -1
- package/dist/types/excalidraw/components/Popover.d.ts +2 -1
- package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -0
- package/dist/types/excalidraw/components/RadioGroup.d.ts +0 -1
- package/dist/types/excalidraw/components/RadioSelection.d.ts +4 -4
- package/dist/types/excalidraw/components/ScrollableList.d.ts +0 -1
- package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +15 -21
- package/dist/types/excalidraw/components/Sidebar/SidebarHeader.d.ts +1 -1
- package/dist/types/excalidraw/components/Sidebar/SidebarTab.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabTriggers.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabs.d.ts +1 -2
- package/dist/types/excalidraw/components/Spinner.d.ts +4 -4
- package/dist/types/excalidraw/components/Stats/CanvasGrid.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/DragInput.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/index.d.ts +7 -8
- package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatHistoryMenu.d.ts +15 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatInterface.d.ts +27 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatMessage.d.ts +14 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/TTDChatPanel.d.ts +26 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/index.d.ts +3 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/useChatAgent.d.ts +8 -0
- package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +3 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDContext.d.ts +13 -0
- package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +4 -25
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +2 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogPanel.d.ts +13 -9
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTab.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTriggers.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +2 -3
- package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +9 -0
- package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +8 -0
- package/dist/types/excalidraw/components/TTDDialog/common.d.ts +16 -16
- package/dist/types/excalidraw/components/TTDDialog/hooks/useChatManagement.d.ts +13 -0
- package/dist/types/excalidraw/components/TTDDialog/hooks/useMermaidRenderer.d.ts +14 -0
- package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +7 -0
- package/dist/types/excalidraw/components/TTDDialog/types.d.ts +91 -0
- package/dist/types/excalidraw/components/TTDDialog/useTTDChatStorage.d.ts +22 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/TTDStreamFetch.d.ts +24 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/chat.d.ts +10 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/mermaidValidation.d.ts +1 -0
- package/dist/types/excalidraw/components/TextField.d.ts +1 -0
- package/dist/types/excalidraw/components/Toast.d.ts +3 -3
- package/dist/types/excalidraw/components/ToolPopover.d.ts +25 -0
- package/dist/types/excalidraw/components/Trans.d.ts +2 -2
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +6 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +30 -32
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +6 -5
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuGroup.d.ts +3 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +10 -18
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContent.d.ts +3 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +0 -1
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCustom.d.ts +2 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemLink.d.ts +6 -6
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuTrigger.d.ts +3 -4
- package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
- package/dist/types/excalidraw/components/hoc/withInternalFallback.d.ts +1 -1
- package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +1 -1
- package/dist/types/excalidraw/components/icons.d.ts +26 -12
- package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +4 -3
- package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -2
- package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +25 -30
- package/dist/types/excalidraw/components/shapes.d.ts +129 -1
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +6 -6
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +15 -16
- package/dist/types/excalidraw/data/blob.d.ts +324 -10
- package/dist/types/excalidraw/data/encode.d.ts +4 -4
- package/dist/types/excalidraw/data/encryption.d.ts +5 -5
- package/dist/types/excalidraw/data/filesystem.d.ts +2 -2
- package/dist/types/excalidraw/data/index.d.ts +3 -3
- package/dist/types/excalidraw/data/json.d.ts +159 -2
- package/dist/types/excalidraw/data/library.d.ts +24 -9
- package/dist/types/excalidraw/data/restore.d.ts +27 -7
- package/dist/types/excalidraw/data/types.d.ts +4 -1
- package/dist/types/excalidraw/editor-jotai.d.ts +11 -11
- package/dist/types/excalidraw/errors.d.ts +14 -0
- package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
- package/dist/types/excalidraw/hooks/useOutsideClick.d.ts +4 -3
- package/dist/types/excalidraw/hooks/useScrollPosition.d.ts +1 -2
- package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +14 -0
- package/dist/types/excalidraw/i18n.d.ts +2 -2
- package/dist/types/excalidraw/index.d.ts +6 -7
- package/dist/types/excalidraw/renderer/animation.d.ts +12 -0
- package/dist/types/excalidraw/renderer/helpers.d.ts +6 -8
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +8 -14
- package/dist/types/excalidraw/scene/Renderer.d.ts +5 -2
- package/dist/types/excalidraw/scene/export.d.ts +2 -2
- package/dist/types/excalidraw/scene/scroll.d.ts +1 -6
- package/dist/types/excalidraw/scene/types.d.ts +22 -5
- package/dist/types/excalidraw/shortcut.d.ts +1 -0
- package/dist/types/excalidraw/snapping.d.ts +5 -5
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-bindings.d.ts +1 -1
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-loader.d.ts +1 -1
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-wasm.d.ts +1 -1
- package/dist/types/excalidraw/subset/woff2/woff2-loader.d.ts +2 -2
- package/dist/types/excalidraw/subset/woff2/woff2-wasm.d.ts +1 -1
- package/dist/types/excalidraw/types.d.ts +32 -20
- package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +2 -2
- package/dist/types/math/src/polygon.d.ts +2 -2
- package/dist/types/math/src/range.d.ts +1 -3
- package/dist/types/math/src/segment.d.ts +4 -3
- package/dist/types/utils/src/bbox.d.ts +1 -1
- package/dist/types/utils/src/export.d.ts +5 -5
- package/dist/types/utils/src/shape.d.ts +6 -6
- package/dist/types/utils/src/withinBounds.d.ts +2 -2
- package/package.json +9 -3
package/dist/prod/index.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
var cd=Object.create;var bs=Object.defineProperty;var dd=Object.getOwnPropertyDescriptor;var ud=Object.getOwnPropertyNames;var pd=Object.getPrototypeOf,md=Object.prototype.hasOwnProperty;var fd=(e,t)=>()=>(e&&(t=e(e=0)),t);var hd=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ed=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ud(t))!md.call(e,i)&&i!==n&&bs(e,i,{get:()=>t[i],enumerable:!(o=dd(t,i))||o.enumerable});return e};var gd=(e,t,n)=>(n=e!=null?cd(pd(e)):{},Ed(t||!e||!e.__esModule?bs(n,"default",{value:e,enumerable:!0}):n,e));var A,P=fd(()=>{A={PROD:!0}});var xc=hd((L1,gc)=>{P();var Ec="Expected a function",fc=NaN,zf="[object Symbol]",Hf=/^\s+|\s+$/g,_f=/^[-+]0x[0-9a-f]+$/i,Yf=/^0b[01]+$/i,Uf=/^0o[0-7]+$/i,Xf=parseInt,Wf=typeof global=="object"&&global&&global.Object===Object&&global,jf=typeof self=="object"&&self&&self.Object===Object&&self,Vf=Wf||jf||Function("return this")(),$f=Object.prototype,Zf=$f.toString,qf=Math.max,Kf=Math.min,ts=function(){return Vf.Date.now()};function Qf(e,t,n){var o,i,r,s,a,l,c=0,d=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(Ec);t=hc(t)||0,Pi(n)&&(d=!!n.leading,u="maxWait"in n,r=u?qf(hc(n.maxWait)||0,t):r,p="trailing"in n?!!n.trailing:p);function m(I){var M=o,D=i;return o=i=void 0,c=I,s=e.apply(D,M),s}function f(I){return c=I,a=setTimeout(g,t),d?m(I):s}function E(I){var M=I-l,D=I-c,T=t-M;return u?Kf(T,r-D):T}function h(I){var M=I-l,D=I-c;return l===void 0||M>=t||M<0||u&&D>=r}function g(){var I=ts();if(h(I))return x(I);a=setTimeout(g,E(I))}function x(I){return a=void 0,p&&o?m(I):(o=i=void 0,s)}function y(){a!==void 0&&clearTimeout(a),c=0,o=l=i=a=void 0}function b(){return a===void 0?s:x(ts())}function w(){var I=ts(),M=h(I);if(o=arguments,i=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 Jf(e,t,n){var o=!0,i=!0;if(typeof e!="function")throw new TypeError(Ec);return Pi(n)&&(o="leading"in n?!!n.leading:o,i="trailing"in n?!!n.trailing:i),Qf(e,t,{leading:o,maxWait:t,trailing:i})}function Pi(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function eh(e){return!!e&&typeof e=="object"}function th(e){return typeof e=="symbol"||eh(e)&&Zf.call(e)==zf}function hc(e){if(typeof e=="number")return e;if(th(e))return fc;if(Pi(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Pi(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Hf,"");var n=Yf.test(e);return n||Uf.test(e)?Xf(e.slice(2),n?2:8):_f.test(e)?fc:+e}gc.exports=Jf});P();import{toIterable as fE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Bt,viewportCoordsToSceneCoords as xi}from"@excalidraw/common";import{normalizeRadians as Zl,radiansBetweenAngles as ff,radiansDifference as hf}from"@excalidraw/math";import{pointsEqual as Ef}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function Ri(e,t,n){if(e&&e.length){let[o,i]=t,r=Math.PI/180*n,s=Math.cos(r),a=Math.sin(r);for(let l of e){let[c,d]=l;l[0]=(c-o)*s-(d-i)*a+o,l[1]=(c-o)*a+(d-i)*s+i}}}function wd(e,t,n){let o=[];e.forEach(i=>o.push(...i)),Ri(o,t,n)}function yd(e,t){return e[0]===t[0]&&e[1]===t[1]}function Ps(e,t,n,o=1){let i=n,r=Math.max(t,.1),s=e[0]&&e[0][0]&&typeof e[0][0]=="number"?[e]:e,a=[0,0];if(i)for(let c of s)Ri(c,a,i);let l=bd(s,r,o);if(i){for(let c of s)Ri(c,a,-i);wd(l,a,-i)}return l}function bd(e,t,n){let o=[];for(let c of e){let d=[...c];yd(d[0],d[d.length-1])||d.push([d[0][0],d[0][1]]),d.length>2&&o.push(d)}let i=[];t=Math.max(t,.1);let r=[];for(let c of o)for(let d=0;d<c.length-1;d++){let u=c[d],p=c[d+1];if(u[1]!==p[1]){let m=Math.min(u[1],p[1]);r.push({ymin:m,ymax:Math.max(u[1],p[1]),x:m===u[1]?u[0]:p[0],islope:(p[0]-u[0])/(p[1]-u[1])})}}if(r.sort((c,d)=>c.ymin<d.ymin?-1:c.ymin>d.ymin?1:c.x<d.x?-1:c.x>d.x?1:c.ymax===d.ymax?0:(c.ymax-d.ymax)/Math.abs(c.ymax-d.ymax)),!r.length)return i;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let c=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)c=u;r.splice(0,c+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(c=>!(c.edge.ymax<=a)),s.sort((c,d)=>c.edge.x===d.edge.x?0:(c.edge.x-d.edge.x)/Math.abs(c.edge.x-d.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let c=0;c<s.length;c=c+2){let d=c+1;if(d>=s.length)break;let u=s[c].edge,p=s[d].edge;i.push([[Math.round(u.x),a],[Math.round(p.x),a]])}a+=n,s.forEach(c=>{c.edge.x=c.edge.x+n*c.edge.islope}),l++}return i}function rt(e,t){var n;let o=t.hachureAngle+90,i=t.hachureGap;i<0&&(i=t.strokeWidth*4),i=Math.max(i,.1);let r=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(r=i),Ps(e,i,o,r||1)}var Rt=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let o=rt(t,n);return{type:"fillSketch",ops:this.renderLines(o,n)}}renderLines(t,n){let o=[];for(let i of t)o.push(...this.helper.doubleLineOps(i[0][0],i[0][1],i[1][0],i[1][1],n));return o}};P();P();function kt(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 ho=class extends Rt{fillPolygons(t,n){let o=n.hachureGap;o<0&&(o=n.strokeWidth*4),o=Math.max(o,.1);let i=Object.assign({},n,{hachureGap:o}),r=rt(t,i),s=Math.PI/180*n.hachureAngle,a=[],l=o*.5*Math.cos(s),c=o*.5*Math.sin(s);for(let[u,p]of r)kt([u,p])&&a.push([[u[0]-l,u[1]+c],[...p]],[[u[0]+l,u[1]-c],[...p]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var Eo=class extends Rt{fillPolygons(t,n){let o=this._fillPolygons(t,n),i=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),r=this._fillPolygons(t,i);return o.ops=o.ops.concat(r.ops),o}};P();var go=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let o=rt(t,n);return this.dotsOnLines(o,n)}dotsOnLines(t,n){let o=[],i=n.hachureGap;i<0&&(i=n.strokeWidth*4),i=Math.max(i,.1);let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let s=i/4;for(let a of t){let l=kt(a),c=l/i,d=Math.ceil(c)-1,u=l-d*i,p=(a[0][0]+a[1][0])/2-i/4,m=Math.min(a[0][1],a[1][1]);for(let f=0;f<d;f++){let E=m+u+f*i,h=p-s+Math.random()*2*s,g=E-s+Math.random()*2*s,x=this.helper.ellipse(h,g,r,r,n);o.push(...x.ops)}}return{type:"fillSketch",ops:o}}};P();var xo=class{constructor(t){this.helper=t}fillPolygons(t,n){let o=rt(t,n);return{type:"fillSketch",ops:this.dashedLine(o,n)}}dashedLine(t,n){let o=n.dashOffset<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashOffset,i=n.dashGap<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashGap,r=[];return t.forEach(s=>{let a=kt(s),l=Math.floor(a/(o+i)),c=(a+i-l*(o+i))/2,d=s[0],u=s[1];d[0]>u[0]&&(d=s[1],u=s[0]);let p=Math.atan((u[1]-d[1])/(u[0]-d[0]));for(let m=0;m<l;m++){let f=m*(o+i),E=f+o,h=[d[0]+f*Math.cos(p)+c*Math.cos(p),d[1]+f*Math.sin(p)+c*Math.sin(p)],g=[d[0]+E*Math.cos(p)+c*Math.cos(p),d[1]+E*Math.sin(p)+c*Math.sin(p)];r.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],n))}}),r}};P();var wo=class{constructor(t){this.helper=t}fillPolygons(t,n){let o=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,i=n.zigzagOffset<0?o:n.zigzagOffset;n=Object.assign({},n,{hachureGap:o+i});let r=rt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,i,n)}}zigzagLines(t,n,o){let i=[];return t.forEach(r=>{let s=kt(r),a=Math.round(s/(2*n)),l=r[0],c=r[1];l[0]>c[0]&&(l=r[1],c=r[0]);let d=Math.atan((c[1]-l[1])/(c[0]-l[0]));for(let u=0;u<a;u++){let p=u*2*n,m=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),E=[l[0]+p*Math.cos(d),l[1]+p*Math.sin(d)],h=[l[0]+m*Math.cos(d),l[1]+m*Math.sin(d)],g=[E[0]+f*Math.cos(d+Math.PI/4),E[1]+f*Math.sin(d+Math.PI/4)];i.push(...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],o),...this.helper.doubleLineOps(g[0],g[1],h[0],h[1],o))}}),i}};var ve={};function Is(e,t){let n=e.fillStyle||"hachure";if(!ve[n])switch(n){case"zigzag":ve[n]||(ve[n]=new ho(t));break;case"cross-hatch":ve[n]||(ve[n]=new Eo(t));break;case"dots":ve[n]||(ve[n]=new go(t));break;case"dashed":ve[n]||(ve[n]=new xo(t));break;case"zigzag-line":ve[n]||(ve[n]=new wo(t));break;case"hachure":default:n="hachure",ve[n]||(ve[n]=new Rt(t));break}return ve[n]}P();function Ss(){return Math.floor(Math.random()*2**31)}var yo=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 bo={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Pd(e){let t=new Array;for(;e!=="";)if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([aAcChHlLmMqQsStTvVzZ])/))t[t.length]={type:0,text:RegExp.$1},e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))t[t.length]={type:1,text:`${parseFloat(RegExp.$1)}`},e=e.substr(RegExp.$1.length);else return[];return t[t.length]={type:2,text:""},t}function ki(e,t){return e.type===t}function xn(e){let t=[],n=Pd(e),o="BOD",i=0,r=n[i];for(;!ki(r,2);){let s=0,a=[];if(o==="BOD")if(r.text==="M"||r.text==="m")i++,s=bo[r.text],o=r.text;else return xn("M0,0"+e);else ki(r,1)?s=bo[o]:(i++,s=bo[r.text],o=r.text);if(i+s<n.length){for(let l=i;l<i+s;l++){let c=n[l];if(ki(c,1))a[a.length]=+c.text;else throw new Error("Param not a number: "+o+","+c.text)}if(typeof bo[o]=="number"){let l={key:o,data:a};t.push(l),i+=s,r=n[i],o==="M"&&(o="L"),o==="m"&&(o="l")}else throw new Error("Bad segment: "+o)}else throw new Error("Path data ended short")}return t}P();function Hn(e){let t=0,n=0,o=0,i=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[o,i]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),o=t,i=n;break;case"L":r.push({key:"L",data:[...a]}),[t,n]=a;break;case"l":t+=a[0],n+=a[1],r.push({key:"L",data:[t,n]});break;case"C":r.push({key:"C",data:[...a]}),t=a[4],n=a[5];break;case"c":{let l=a.map((c,d)=>d%2?c+n:c+t);r.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":r.push({key:"Q",data:[...a]}),t=a[2],n=a[3];break;case"q":{let l=a.map((c,d)=>d%2?c+n:c+t);r.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":r.push({key:"A",data:[...a]}),t=a[5],n=a[6];break;case"a":t+=a[5],n+=a[6],r.push({key:"A",data:[a[0],a[1],a[2],a[3],a[4],t,n]});break;case"H":r.push({key:"H",data:[...a]}),t=a[0];break;case"h":t+=a[0],r.push({key:"H",data:[t]});break;case"V":r.push({key:"V",data:[...a]}),n=a[0];break;case"v":n+=a[0],r.push({key:"V",data:[n]});break;case"S":r.push({key:"S",data:[...a]}),t=a[2],n=a[3];break;case"s":{let l=a.map((c,d)=>d%2?c+n:c+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=o,n=i;break}return r}P();function Yn(e){let t=[],n="",o=0,i=0,r=0,s=0,a=0,l=0;for(let{key:c,data:d}of e){switch(c){case"M":t.push({key:"M",data:[...d]}),[o,i]=d,[r,s]=d;break;case"C":t.push({key:"C",data:[...d]}),o=d[4],i=d[5],a=d[2],l=d[3];break;case"L":t.push({key:"L",data:[...d]}),[o,i]=d;break;case"H":o=d[0],t.push({key:"L",data:[o,i]});break;case"V":i=d[0],t.push({key:"L",data:[o,i]});break;case"S":{let u=0,p=0;n==="C"||n==="S"?(u=o+(o-a),p=i+(i-l)):(u=o,p=i),t.push({key:"C",data:[u,p,...d]}),a=d[0],l=d[1],o=d[2],i=d[3];break}case"T":{let[u,p]=d,m=0,f=0;n==="Q"||n==="T"?(m=o+(o-a),f=i+(i-l)):(m=o,f=i);let E=o+2*(m-o)/3,h=i+2*(f-i)/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,o=u,i=p;break}case"Q":{let[u,p,m,f]=d,E=o+2*(u-o)/3,h=i+2*(p-i)/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,o=m,i=f;break}case"A":{let u=Math.abs(d[0]),p=Math.abs(d[1]),m=d[2],f=d[3],E=d[4],h=d[5],g=d[6];u===0||p===0?(t.push({key:"C",data:[o,i,h,g,h,g]}),o=h,i=g):(o!==h||i!==g)&&(Ms(o,i,h,g,u,p,m,f,E).forEach(function(y){t.push({key:"C",data:y})}),o=h,i=g);break}case"Z":t.push({key:"Z",data:[]}),o=r,i=s;break}n=c}return t}function Id(e){return Math.PI*e/180}function _n(e,t,n){let o=e*Math.cos(n)-t*Math.sin(n),i=e*Math.sin(n)+t*Math.cos(n);return[o,i]}function Ms(e,t,n,o,i,r,s,a,l,c){let d=Id(s),u=[],p=0,m=0,f=0,E=0;if(c)[p,m,f,E]=c;else{[e,t]=_n(e,t,-d),[n,o]=_n(n,o,-d);let k=(e-n)/2,L=(t-o)/2,j=k*k/(i*i)+L*L/(r*r);j>1&&(j=Math.sqrt(j),i=j*i,r=j*r);let N=a===l?-1:1,te=i*i,S=r*r,Q=te*S-te*L*L-S*k*k,V=te*L*L+S*k*k,ne=N*Math.sqrt(Math.abs(Q/V));f=ne*i*L/r+(e+n)/2,E=ne*-r*k/i+(t+o)/2,p=Math.asin(parseFloat(((t-E)/r).toFixed(9))),m=Math.asin(parseFloat(((o-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 k=m,L=n,j=o;l&&m>p?m=p+Math.PI*120/180*1:m=p+Math.PI*120/180*-1,n=f+i*Math.cos(m),o=E+r*Math.sin(m),u=Ms(n,o,L,j,i,r,s,0,l,[m,k,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*i*w,M=4/3*r*w,D=[e,t],T=[e+I*x,t-M*g],F=[n+I*b,o-M*y],C=[n,o];if(T[0]=2*D[0]-T[0],T[1]=2*D[1]-T[1],c)return[T,F,C].concat(u);{u=[T,F,C].concat(u);let k=[];for(let L=0;L<u.length;L+=3){let j=_n(u[L][0],u[L][1],d),N=_n(u[L+1][0],u[L+1][1],d),te=_n(u[L+2][0],u[L+2][1],d);k.push([j[0],j[1],N[0],N[1],te[0],te[1]])}return k}}var Sd={randOffset:Ad,randOffsetWithRange:Dd,ellipse:Td,doubleLineOps:vd};function Fi(e,t,n,o,i){return{type:"path",ops:ht(e,t,n,o,i)}}function Un(e,t,n){let o=(e||[]).length;if(o>2){let i=[];for(let r=0;r<o-1;r++)i.push(...ht(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&i.push(...ht(e[o-1][0],e[o-1][1],e[0][0],e[0][1],n)),{type:"path",ops:i}}else if(o===2)return Fi(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Md(e,t){return Un(e,!0,t)}function Ls(e,t,n,o,i){let r=[[e,t],[e+n,t],[e+n,t+o],[e,t+o]];return Md(r,i)}function Ni(e,t){let n=As(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let o=As(e,1.5*(1+t.roughness*.22),Ld(t));n=n.concat(o)}return{type:"path",ops:n}}function Td(e,t,n,o,i){let r=zi(n,o,i);return So(e,t,i,r).opset}function zi(e,t,n){let o=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),i=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*o)),r=Math.PI*2/i,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=O(s*l,n),a+=O(a*l,n),{increment:r,rx:s,ry:a}}function So(e,t,n,o){let[i,r]=Ds(o.increment,e,t,o.rx,o.ry,1,o.increment*Po(.1,Po(.4,1,n),n),n),s=Io(i,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=Ds(o.increment,e,t,o.rx,o.ry,1.5,0,n),l=Io(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Hi(e,t,n,o,i,r,s,a,l){let c=e,d=t,u=Math.abs(n/2),p=Math.abs(o/2);u+=O(u*.01,l),p+=O(p*.01,l);let m=i,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=vs(h,c,d,u,p,m,f,1,l);if(!l.disableMultiStroke){let x=vs(h,c,d,u,p,m,f,1.5,l);g.push(...x)}return s&&(a?g.push(...ht(c,d,c+u*Math.cos(m),d+p*Math.sin(m),l),...ht(c,d,c+u*Math.cos(f),d+p*Math.sin(f),l)):g.push({op:"lineTo",data:[c,d]},{op:"lineTo",data:[c+u*Math.cos(m),d+p*Math.sin(m)]})),{type:"path",ops:g}}function _i(e,t){let n=Yn(Hn(xn(e))),o=[],i=[0,0],r=[0,0];for(let{key:s,data:a}of n)switch(s){case"M":{r=[a[0],a[1]],i=[a[0],a[1]];break}case"L":o.push(...ht(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,c,d,u,p,m]=a;o.push(...Cd(l,c,d,u,p,m,r,t)),r=[p,m];break}case"Z":o.push(...ht(r[0],r[1],i[0],i[1],t)),r=[i[0],i[1]];break}return{type:"path",ops:o}}function Mo(e,t){let n=[];for(let o of e)if(o.length){let i=t.maxRandomnessOffset||0,r=o.length;if(r>2){n.push({op:"move",data:[o[0][0]+O(i,t),o[0][1]+O(i,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[o[s][0]+O(i,t),o[s][1]+O(i,t)]})}}return{type:"fillPath",ops:n}}function rn(e,t){return Is(t,Sd).fillPolygons(e,t)}function Cs(e,t,n,o,i,r,s){let a=e,l=t,c=Math.abs(n/2),d=Math.abs(o/2);c+=O(c*.01,s),d+=O(d*.01,s);let u=i,p=r;for(;u<0;)u+=Math.PI*2,p+=Math.PI*2;p-u>Math.PI*2&&(u=0,p=Math.PI*2);let m=(p-u)/s.curveStepCount,f=[];for(let E=u;E<=p;E=E+m)f.push([a+c*Math.cos(E),l+d*Math.sin(E)]);return f.push([a+c*Math.cos(p),l+d*Math.sin(p)]),f.push([a,l]),rn([f],s)}function Ad(e,t){return O(e,t)}function Dd(e,t,n){return Po(e,t,n)}function vd(e,t,n,o,i){return ht(e,t,n,o,i,!0)}function Ld(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Bs(e){return e.randomizer||(e.randomizer=new yo(e.seed||0)),e.randomizer.next()}function Po(e,t,n,o=1){return n.roughness*o*(Bs(n)*(t-e)+e)}function O(e,t,n=1){return Po(-e,e,t,n)}function ht(e,t,n,o,i,r=!1){let s=r?i.disableMultiStrokeFill:i.disableMultiStroke,a=Ts(e,t,n,o,i,!0,!1);if(s)return a;let l=Ts(e,t,n,o,i,!0,!0);return a.concat(l)}function Ts(e,t,n,o,i,r,s){let a=Math.pow(e-n,2)+Math.pow(t-o,2),l=Math.sqrt(a),c=1;l<200?c=1:l>500?c=.4:c=-.0016668*l+1.233334;let d=i.maxRandomnessOffset||0;d*d*100>a&&(d=l/10);let u=d/2,p=.2+Bs(i)*.2,m=i.bowing*i.maxRandomnessOffset*(o-t)/200,f=i.bowing*i.maxRandomnessOffset*(e-n)/200;m=O(m,i,c),f=O(f,i,c);let E=[],h=()=>O(u,i,c),g=()=>O(d,i,c),x=i.preserveVertices;return r&&(s?E.push({op:"move",data:[e+(x?0:h()),t+(x?0:h())]}):E.push({op:"move",data:[e+(x?0:O(d,i,c)),t+(x?0:O(d,i,c))]})),s?E.push({op:"bcurveTo",data:[m+e+(n-e)*p+h(),f+t+(o-t)*p+h(),m+e+2*(n-e)*p+h(),f+t+2*(o-t)*p+h(),n+(x?0:h()),o+(x?0:h())]}):E.push({op:"bcurveTo",data:[m+e+(n-e)*p+g(),f+t+(o-t)*p+g(),m+e+2*(n-e)*p+g(),f+t+2*(o-t)*p+g(),n+(x?0:g()),o+(x?0:g())]}),E}function As(e,t,n){let o=[];o.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]),o.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]);for(let i=1;i<e.length;i++)o.push([e[i][0]+O(t,n),e[i][1]+O(t,n)]),i===e.length-1&&o.push([e[i][0]+O(t,n),e[i][1]+O(t,n)]);return Io(o,null,n)}function Io(e,t,n){let o=e.length,i=[];if(o>3){let r=[],s=1-n.curveTightness;i.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<o;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]],i.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;i.push({op:"lineTo",data:[t[0]+O(a,n),t[1]+O(a,n)]})}}else o===3?(i.push({op:"move",data:[e[1][0],e[1][1]]}),i.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):o===2&&i.push(...ht(e[0][0],e[0][1],e[1][0],e[1][1],n));return i}function Ds(e,t,n,o,i,r,s,a){let l=a.roughness===0,c=[],d=[];if(l){e=e/4,d.push([t+o*Math.cos(-e),n+i*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let p=[t+o*Math.cos(u),n+i*Math.sin(u)];c.push(p),d.push(p)}d.push([t+o*Math.cos(0),n+i*Math.sin(0)]),d.push([t+o*Math.cos(e),n+i*Math.sin(e)])}else{let u=O(.5,a)-Math.PI/2;d.push([O(r,a)+t+.9*o*Math.cos(u-e),O(r,a)+n+.9*i*Math.sin(u-e)]);let p=Math.PI*2+u-.01;for(let m=u;m<p;m=m+e){let f=[O(r,a)+t+o*Math.cos(m),O(r,a)+n+i*Math.sin(m)];c.push(f),d.push(f)}d.push([O(r,a)+t+o*Math.cos(u+Math.PI*2+s*.5),O(r,a)+n+i*Math.sin(u+Math.PI*2+s*.5)]),d.push([O(r,a)+t+.98*o*Math.cos(u+s),O(r,a)+n+.98*i*Math.sin(u+s)]),d.push([O(r,a)+t+.9*o*Math.cos(u+s*.5),O(r,a)+n+.9*i*Math.sin(u+s*.5)])}return[d,c]}function vs(e,t,n,o,i,r,s,a,l){let c=r+O(.1,l),d=[];d.push([O(a,l)+t+.9*o*Math.cos(c-e),O(a,l)+n+.9*i*Math.sin(c-e)]);for(let u=c;u<=s;u=u+e)d.push([O(a,l)+t+o*Math.cos(u),O(a,l)+n+i*Math.sin(u)]);return d.push([t+o*Math.cos(s),n+i*Math.sin(s)]),d.push([t+o*Math.cos(s),n+i*Math.sin(s)]),Io(d,null,l)}function Cd(e,t,n,o,i,r,s,a){let l=[],c=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],d=[0,0],u=a.disableMultiStroke?1:2,p=a.preserveVertices;for(let m=0;m<u;m++)m===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(p?0:O(c[0],a)),s[1]+(p?0:O(c[0],a))]}),d=p?[i,r]:[i+O(c[m],a),r+O(c[m],a)],l.push({op:"bcurveTo",data:[e+O(c[m],a),t+O(c[m],a),n+O(c[m],a),o+O(c[m],a),d[0],d[1]]});return l}P();function Xn(e){return[...e]}function Gs(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let o=[];if(n===3)o.push(Xn(e[0]),Xn(e[1]),Xn(e[2]),Xn(e[2]));else{let i=[];i.push(e[0],e[0]);for(let a=1;a<e.length;a++)i.push(e[a]),a===e.length-1&&i.push(e[a]);let r=[],s=1-t;o.push(Xn(i[0]));for(let a=1;a+2<i.length;a++){let l=i[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*i[a+1][0]-s*i[a-1][0])/6,l[1]+(s*i[a+1][1]-s*i[a-1][1])/6],r[2]=[i[a+1][0]+(s*i[a][0]-s*i[a+2][0])/6,i[a+1][1]+(s*i[a][1]-s*i[a+2][1])/6],r[3]=[i[a+1][0],i[a+1][1]],o.push(r[1],r[2],r[3])}}return o}P();function Bd(e,t){return Math.sqrt(To(e,t))}function To(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Gd(e,t,n){let o=To(t,n);if(o===0)return To(e,t);let i=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/o;return i=Math.max(0,Math.min(1,i)),To(e,sn(t,n,i))}function sn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Od(e,t){let n=e[t+0],o=e[t+1],i=e[t+2],r=e[t+3],s=3*o[0]-2*n[0]-r[0];s*=s;let a=3*o[1]-2*n[1]-r[1];a*=a;let l=3*i[0]-2*r[0]-n[0];l*=l;let c=3*i[1]-2*r[1]-n[1];return c*=c,s<l&&(s=l),a<c&&(a=c),s+a}function Yi(e,t,n,o){let i=o||[];if(Od(e,t)<n){let r=e[t+0];i.length?Bd(i[i.length-1],r)>1&&i.push(r):i.push(r),i.push(e[t+3])}else{let s=e[t+0],a=e[t+1],l=e[t+2],c=e[t+3],d=sn(s,a,.5),u=sn(a,l,.5),p=sn(l,c,.5),m=sn(d,u,.5),f=sn(u,p,.5),E=sn(m,f,.5);Yi([s,d,m,E],0,n,i),Yi([E,f,p,c],0,n,i)}return i}function Wn(e,t){return Ao(e,0,e.length,t)}function Ao(e,t,n,o,i){let r=i||[],s=e[t],a=e[n-1],l=0,c=1;for(let d=t+1;d<n-1;++d){let u=Gd(e[d],s,a);u>l&&(l=u,c=d)}return Math.sqrt(l)>o?(Ao(e,t,c+1,o,r),Ao(e,c,n,o,r)):(r.length||r.push(s),r.push(a)),r}function Et(e,t=.15,n){let o=[],i=(e.length-1)/3;for(let r=0;r<i;r++){let s=r*3;Yi(e,s,t,o)}return n&&n>0?Ao(o,0,o.length,n):o}P();function Os(e,t,n){let o=xn(e),i=Yn(Hn(o)),r=[],s=[],a=[0,0],l=[],c=()=>{l.length>=4&&s.push(...Et(l,t)),l=[]},d=()=>{c(),s.length&&(r.push(s),s=[])};for(let{key:p,data:m}of i)switch(p){case"M":d(),a=[m[0],m[1]],s.push(a);break;case"L":c(),s.push([m[0],m[1]]);break;case"C":if(!l.length){let f=s.length?s[s.length-1]:a;l.push([f[0],f[1]])}l.push([m[0],m[1]]),l.push([m[2],m[3]]),l.push([m[4],m[5]]);break;case"Z":c(),s.push([a[0],a[1]]);break}if(d(),!n)return r;let u=[];for(let p of r){let m=Wn(p,n);m.length&&u.push(m)}return u}var Ne="none",Xe=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Ss()}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,o){return{shape:t,sets:n||[],options:o||this.defaultOptions}}line(t,n,o,i,r){let s=this._o(r);return this._d("line",[Fi(t,n,o,i,s)],s)}rectangle(t,n,o,i,r){let s=this._o(r),a=[],l=Ls(t,n,o,i,s);if(s.fill){let c=[[t,n],[t+o,n],[t+o,n+i],[t,n+i]];s.fillStyle==="solid"?a.push(Mo([c],s)):a.push(rn([c],s))}return s.stroke!==Ne&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,o,i,r){let s=this._o(r),a=[],l=zi(o,i,s),c=So(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let d=So(t,n,s,l).opset;d.type="fillPath",a.push(d)}else a.push(rn([c.estimatedPoints],s));return s.stroke!==Ne&&a.push(c.opset),this._d("ellipse",a,s)}circle(t,n,o,i){let r=this.ellipse(t,n,o,o,i);return r.shape="circle",r}linearPath(t,n){let o=this._o(n);return this._d("linearPath",[Un(t,!1,o)],o)}arc(t,n,o,i,r,s,a=!1,l){let c=this._o(l),d=[],u=Hi(t,n,o,i,r,s,a,!0,c);if(a&&c.fill)if(c.fillStyle==="solid"){let p=Object.assign({},c);p.disableMultiStroke=!0;let m=Hi(t,n,o,i,r,s,!0,!1,p);m.type="fillPath",d.push(m)}else d.push(Cs(t,n,o,i,r,s,c));return c.stroke!==Ne&&d.push(u),this._d("arc",d,c)}curve(t,n){let o=this._o(n),i=[],r=Ni(t,o);if(o.fill&&o.fill!==Ne&&t.length>=3)if(o.fillStyle==="solid"){let s=Ni(t,Object.assign(Object.assign({},o),{disableMultiStroke:!0,roughness:o.roughness?o.roughness+o.fillShapeRoughnessGain:0}));i.push({type:"fillPath",ops:this._mergedShape(s.ops)})}else{let s=Gs(t),a=Et(s,10,(1+o.roughness)/2);i.push(rn([a],o))}return o.stroke!==Ne&&i.push(r),this._d("curve",i,o)}polygon(t,n){let o=this._o(n),i=[],r=Un(t,!0,o);return o.fill&&(o.fillStyle==="solid"?i.push(Mo([t],o)):i.push(rn([t],o))),o.stroke!==Ne&&i.push(r),this._d("polygon",i,o)}path(t,n){let o=this._o(n),i=[];if(!t)return this._d("path",i,o);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=o.fill&&o.fill!=="transparent"&&o.fill!==Ne,s=o.stroke!==Ne,a=!!(o.simplification&&o.simplification<1),l=a?4-4*(o.simplification||1):(1+o.roughness)/2,c=Os(t,1,l),d=_i(t,o);if(r)if(o.fillStyle==="solid")if(c.length===1){let u=_i(t,Object.assign(Object.assign({},o),{disableMultiStroke:!0,roughness:o.roughness?o.roughness+o.fillShapeRoughnessGain:0}));i.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else i.push(Mo(c,o));else i.push(rn(c,o));return s&&(a?c.forEach(u=>{i.push(Un(u,!1,o))}):i.push(d)),this._d("path",i,o)}opsToPath(t,n){let o="";for(let i of t.ops){let r=typeof n=="number"&&n>=0?i.data.map(s=>+s.toFixed(n)):i.data;switch(i.op){case"move":o+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":o+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":o+=`L${r[0]} ${r[1]} `;break}}return o.trim()}toPaths(t){let n=t.sets||[],o=t.options||this.defaultOptions,i=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:o.stroke,strokeWidth:o.strokeWidth,fill:Ne};break;case"fillPath":s={d:this.opsToPath(r),stroke:Ne,strokeWidth:0,fill:o.fill||Ne};break;case"fillSketch":s=this.fillSketch(r,o);break}s&&i.push(s)}return i}fillSketch(t,n){let o=n.fillWeight;return o<0&&(o=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||Ne,strokeWidth:o,fill:Ne}}_mergedShape(t){return t.filter((n,o)=>o===0?!0:n.op!=="move")}};var Do=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new Xe(n)}draw(t){let n=t.sets||[],o=t.options||this.getDefaultOptions(),i=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":i.save(),i.strokeStyle=o.stroke==="none"?"transparent":o.stroke,i.lineWidth=o.strokeWidth,o.strokeLineDash&&i.setLineDash(o.strokeLineDash),o.strokeLineDashOffset&&(i.lineDashOffset=o.strokeLineDashOffset),this._drawToContext(i,s,r),i.restore();break;case"fillPath":{i.save(),i.fillStyle=o.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(i,s,r,a),i.restore();break}case"fillSketch":this.fillSketch(i,s,o);break}}fillSketch(t,n,o){let i=o.fillWeight;i<0&&(i=o.strokeWidth/2),t.save(),o.fillLineDash&&t.setLineDash(o.fillLineDash),o.fillLineDashOffset&&(t.lineDashOffset=o.fillLineDashOffset),t.strokeStyle=o.fill||"",t.lineWidth=i,this._drawToContext(t,n,o.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,o,i="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof o=="number"&&o>=0?r.data.map(a=>+a.toFixed(o)):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(i):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,o,i,r){let s=this.gen.line(t,n,o,i,r);return this.draw(s),s}rectangle(t,n,o,i,r){let s=this.gen.rectangle(t,n,o,i,r);return this.draw(s),s}ellipse(t,n,o,i,r){let s=this.gen.ellipse(t,n,o,i,r);return this.draw(s),s}circle(t,n,o,i){let r=this.gen.circle(t,n,o,i);return this.draw(r),r}linearPath(t,n){let o=this.gen.linearPath(t,n);return this.draw(o),o}polygon(t,n){let o=this.gen.polygon(t,n);return this.draw(o),o}arc(t,n,o,i,r,s,a=!1,l){let c=this.gen.arc(t,n,o,i,r,s,a,l);return this.draw(c),c}curve(t,n){let o=this.gen.curve(t,n);return this.draw(o),o}path(t,n){let o=this.gen.path(t,n);return this.draw(o),o}};P();P();var jn="http://www.w3.org/2000/svg";var vo=class{constructor(t,n){this.svg=t,this.gen=new Xe(n)}draw(t){let n=t.sets||[],o=t.options||this.getDefaultOptions(),i=this.svg.ownerDocument||window.document,r=i.createElementNS(jn,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=i.createElementNS(jn,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke",o.stroke),l.setAttribute("stroke-width",o.strokeWidth+""),l.setAttribute("fill","none"),o.strokeLineDash&&l.setAttribute("stroke-dasharray",o.strokeLineDash.join(" ").trim()),o.strokeLineDashOffset&&l.setAttribute("stroke-dashoffset",`${o.strokeLineDashOffset}`);break}case"fillPath":{l=i.createElementNS(jn,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke","none"),l.setAttribute("stroke-width","0"),l.setAttribute("fill",o.fill||""),(t.shape==="curve"||t.shape==="polygon")&&l.setAttribute("fill-rule","evenodd");break}case"fillSketch":{l=this.fillSketch(i,a,o);break}}l&&r.appendChild(l)}return r}fillSketch(t,n,o){let i=o.fillWeight;i<0&&(i=o.strokeWidth/2);let r=t.createElementNS(jn,"path");return r.setAttribute("d",this.opsToPath(n,o.fixedDecimalPlaceDigits)),r.setAttribute("stroke",o.fill||""),r.setAttribute("stroke-width",i+""),r.setAttribute("fill","none"),o.fillLineDash&&r.setAttribute("stroke-dasharray",o.fillLineDash.join(" ").trim()),o.fillLineDashOffset&&r.setAttribute("stroke-dashoffset",`${o.fillLineDashOffset}`),r}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,n){return this.gen.opsToPath(t,n)}line(t,n,o,i,r){let s=this.gen.line(t,n,o,i,r);return this.draw(s)}rectangle(t,n,o,i,r){let s=this.gen.rectangle(t,n,o,i,r);return this.draw(s)}ellipse(t,n,o,i,r){let s=this.gen.ellipse(t,n,o,i,r);return this.draw(s)}circle(t,n,o,i){let r=this.gen.circle(t,n,o,i);return this.draw(r)}linearPath(t,n){let o=this.gen.linearPath(t,n);return this.draw(o)}polygon(t,n){let o=this.gen.polygon(t,n);return this.draw(o)}arc(t,n,o,i,r,s,a=!1,l){let c=this.gen.arc(t,n,o,i,r,s,a,l);return this.draw(c)}curve(t,n){let o=this.gen.curve(t,n);return this.draw(o)}path(t,n){let o=this.gen.path(t,n);return this.draw(o)}};var an={canvas(e,t){return new Do(e,t)},svg(e,t){return new vo(e,t)},generator(e){return new Xe(e)},newSeed(){return Xe.newSeed()}};import{arrayToMap as Vl,invariant as Yr,rescalePoints as Yl,sizeOf as rf}from"@excalidraw/common";import{degreesToRadians as _r,lineSegment as Ee,pointDistance as sf,pointFrom as v,pointFromArray as $l,pointRotateRads as se}from"@excalidraw/math";P();import{invariant as Rd}from"@excalidraw/common";import{curve as kd,lineSegment as Fd,pointFrom as le,pointDistance as Jg,pointFromArray as Nd,pointFromVector as zd,pointRotateRads as Ze,polygon as Rs,polygonFromPoints as Ui,PRECISION as ex,segmentsIntersectAt as tx,vector as Hd,vectorAdd as _d,vectorFromPoint as Yd,vectorScale as nx}from"@excalidraw/math";import{getElementAbsoluteCoords as ix}from"@excalidraw/element";var ks=e=>{let{angle:t,width:n,height:o,x:i,y:r}=e,s=i+n/2,a=r+o/2,l=le(s,a),c;return e.type==="diamond"?c=Rs(Ze(le(s,r),l,t),Ze(le(i+n,a),l,t),Ze(le(s,r+o),l,t),Ze(le(i,a),l,t)):c=Rs(Ze(le(i,r),l,t),Ze(le(i+n,r),l,t),Ze(le(i+n,r+o),l,t),Ze(le(i,r+o),l,t)),{type:"polygon",data:c}};var Fs=e=>{let{width:t,height:n,angle:o,x:i,y:r}=e;return{type:"ellipse",data:{center:le(i+t/2,r+n/2),angle:o,halfWidth:t/2,halfHeight:n/2}}},gt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},Ns=(e,t=le(0,0),n,o)=>{let i=l=>Ze(le(l[0]+t[0],l[1]+t[1]),o,n),r=gt(e),s=[],a=le(0,0);for(let l of r){if(l.op==="move"){let c=Nd(l.data);Rd(c!=null,"Ops data is not a point"),a=i(c)}if(l.op==="bcurveTo"){let c=i(le(l.data[0],l.data[1])),d=i(le(l.data[2],l.data[3])),u=i(le(l.data[4],l.data[5]));s.push(kd(a,c,d,u)),a=u}}return{type:"polycurve",data:s}},Ud=e=>{let t=e[0],n=[];for(let o=1;o<e.length;o++){let i=e[o];n.push(Fd(t,i)),t=i}return n},zs=(e,t,n=!1)=>{let o=r=>Ze(zd(_d(Yd(r),Hd(e.x,e.y))),t,e.angle),i=Ud(e.points.map(r=>o(r)));return n?{type:"polygon",data:Ui(i.flat())}:{type:"polyline",data:i}},Hs=(e,t,n=le(0,0),o,i)=>{let r=d=>Ze(le(d[0]+n[0],d[1]+n[1]),i,o);if(e.roundness===null)return{type:"polygon",data:Ui(e.points.map(d=>r(d)))};let s=gt(t),a=[],l=!1;for(let d of s)d.op==="move"?(l=!l,l&&a.push(le(d.data[0],d.data[1]))):d.op==="bcurveTo"?l&&(a.push(le(d.data[0],d.data[1])),a.push(le(d.data[2],d.data[3])),a.push(le(d.data[4],d.data[5]))):d.op==="lineTo"&&l&&a.push(le(d.data[0],d.data[1]));let c=Et(a,10,5).map(d=>r(d));return{type:"polygon",data:Ui(c)}};P();import{pointFrom as ce,pointDistance as kl,pointRotateRads as Lt}from"@excalidraw/math";import{ROUGHNESS as Km,isTransparent as ao,assertNever as Qm,COLOR_PALETTE as Jm,LINE_POLYGON_POINT_MERGE_DISTANCE as ef}from"@excalidraw/common";P();P();function _s(e,t,n,o=i=>i){return e*o(.5-t*(.5-n))}function Xd(e){return[-e[0],-e[1]]}function Ke(e,t){return[e[0]+t[0],e[1]+t[1]]}function We(e,t){return[e[0]-t[0],e[1]-t[1]]}function qe(e,t){return[e[0]*t,e[1]*t]}function Wd(e,t){return[e[0]/t,e[1]/t]}function Vn(e){return[e[1],-e[0]]}function Ys(e,t){return e[0]*t[0]+e[1]*t[1]}function jd(e,t){return e[0]===t[0]&&e[1]===t[1]}function Vd(e){return Math.hypot(e[0],e[1])}function $d(e){return e[0]*e[0]+e[1]*e[1]}function Us(e,t){return $d(We(e,t))}function js(e){return Wd(e,Vd(e))}function Zd(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function $n(e,t,n){let o=Math.sin(n),i=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*i-s*o,l=r*o+s*i;return[a+t[0],l+t[1]]}function Xi(e,t,n){return Ke(e,qe(We(t,e),n))}function Xs(e,t,n){return Ke(e,qe(t,n))}var{min:wn,PI:qd}=Math,Ws=.275,Zn=qd+1e-4;function Kd(e,t={}){let{size:n=16,smoothing:o=.5,thinning:i=.5,simulatePressure:r=!0,easing:s=S=>S,start:a={},end:l={},last:c=!1}=t,{cap:d=!0,easing:u=S=>S*(2-S)}=a,{cap:p=!0,easing:m=S=>--S*S*S+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,E=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,h=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*o,2),x=[],y=[],b=e.slice(0,10).reduce((S,Q)=>{let V=Q.pressure;if(r){let ne=wn(1,Q.distance/n),tn=wn(1,1-ne);V=wn(1,S+(tn-S)*(ne*Ws))}return(S+V)/2},e[0].pressure),w=_s(n,i,e[e.length-1].pressure,s),I,M=e[0].vector,D=e[0].point,T=D,F=D,C=T,k=!1;for(let S=0;S<e.length;S++){let{pressure:Q}=e[S],{point:V,vector:ne,distance:tn,runningLength:it}=e[S];if(S<e.length-1&&f-it<3)continue;if(i){if(r){let ge=wn(1,tn/n),on=wn(1,1-ge);Q=wn(1,b+(on-b)*(ge*Ws))}w=_s(n,i,Q,s)}else w=n/2;I===void 0&&(I=w);let gn=it<E?u(it/E):1,Gi=f-it<h?m((f-it)/h):1;w=Math.max(.01,w*Math.min(gn,Gi));let mo=(S<e.length-1?e[S+1]:e[S]).vector,zn=S<e.length-1?Ys(ne,mo):1,Oi=Ys(ne,M)<0&&!k,fo=zn!==null&&zn<0;if(Oi||fo){let ge=qe(Vn(M),w);for(let on=1/13,De=0;De<=1;De+=on)F=$n(We(V,ge),V,Zn*De),x.push(F),C=$n(Ke(V,ge),V,Zn*-De),y.push(C);D=F,T=C,fo&&(k=!0);continue}if(k=!1,S===e.length-1){let ge=qe(Vn(ne),w);x.push(We(V,ge)),y.push(Ke(V,ge));continue}let nn=qe(Vn(Xi(mo,ne,zn)),w);F=We(V,nn),(S<=1||Us(D,F)>g)&&(x.push(F),D=F),C=Ke(V,nn),(S<=1||Us(T,C)>g)&&(y.push(C),T=C),b=Q,M=ne}let L=e[0].point.slice(0,2),j=e.length>1?e[e.length-1].point.slice(0,2):Ke(e[0].point,[1,1]),N=[],te=[];if(e.length===1){if(!(E||h)||c){let S=Xs(L,js(Vn(We(L,j))),-(I||w)),Q=[];for(let V=1/13,ne=V;ne<=1;ne+=V)Q.push($n(S,L,Zn*2*ne));return Q}}else{if(!(E||h&&e.length===1))if(d)for(let Q=1/13,V=Q;V<=1;V+=Q){let ne=$n(y[0],L,Zn*V);N.push(ne)}else{let Q=We(x[0],y[0]),V=qe(Q,.5),ne=qe(Q,.51);N.push(We(L,V),We(L,ne),Ke(L,ne),Ke(L,V))}let S=Vn(Xd(e[e.length-1].vector));if(h||E&&e.length===1)te.push(j);else if(p){let Q=Xs(j,S,w);for(let V=1/29,ne=V;ne<1;ne+=V)te.push($n(Q,j,Zn*3*ne))}else te.push(Ke(j,qe(S,w)),Ke(j,qe(S,w*.99)),We(j,qe(S,w*.99)),We(j,qe(S,w)))}return x.concat(te,y.reverse(),N)}function Qd(e,t={}){var n;let{streamline:o=.5,size:i=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-o)*.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(Xi(a[0],m,f/4))}a.length===1&&(a=[...a,[...Ke(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],c=!1,d=0,u=l[0],p=a.length-1;for(let m=1;m<a.length;m++){let f=r&&m===p?a[m].slice(0,2):Xi(u.point,a[m],s);if(jd(u.point,f))continue;let E=Zd(f,u.point);if(d+=E,m<p&&!c){if(d<i)continue;c=!0}u={point:f,pressure:a[m][2]>=0?a[m][2]:.5,vector:js(We(u.point,f)),distance:E,runningLength:d},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function Vs(e,t={}){return Kd(Qd(e,t),t)}import{isRightAngleRads as Fm}from"@excalidraw/math";import{BOUND_TEXT_PADDING as mi,DEFAULT_REDUCED_GLOBAL_ALPHA as Nm,ELEMENT_READY_TO_ERASE_OPACITY as zm,FRAME_STYLE as fi,MIME_TYPES as zr,THEME as Al,distance as Qt,getFontString as Hm,isRTL as _m,getVerticalOffset as Ym}from"@excalidraw/common";P();import{pointFrom as xt,pointCenter as Jd,pointRotateRads as Ft,vectorFromPoint as Wi,vectorNormalize as $s,vectorSubtract as Zs,vectorAdd as Lo,vectorScale as Co,pointFromVector as qs,clamp as Pe,isCloseTo as Ks}from"@excalidraw/math";var Ie=10,ux=(e,t,n,o,i,r,s,a)=>{let{width:l,height:c}=ji(e),d=o/l,u=i/c,p=(e.crop?.x??0)/d,m=(e.crop?.y??0)/u,f=Ft(xt(r,s),fe(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:o,height:i,naturalWidth:o,naturalHeight:i},x=g.height,y=g.width,b=e.scale[0]===-1,w=e.scale[1]===-1,I=s-e.y,M=r-e.x;n.includes("n")&&(h=Pe(e.height-I,Ie,w?c-m:e.height+m)),n.includes("s")&&(I=s-e.y-e.height,h=Pe(e.height+I,Ie,w?e.height+m:c-m)),n.includes("e")&&(M=r-e.x-e.width,E=Pe(e.width+M,Ie,b?e.width+p:l-p)),n.includes("w")&&(E=Pe(e.width-M,Ie,b?l-p:e.width+p));let D=C=>{C.height=h*u,C.width=E*d};D(g);let T=(C,k)=>{D(k),C.includes("n")&&(w||(k.y+=x-k.height)),C.includes("s")&&w&&(k.y+=x-k.height),C.includes("e")&&b&&(k.x+=y-k.width),C.includes("w")&&(b||(k.x+=y-k.width))};switch(n){case"n":{if(a){let C=p+e.width/2,k=l-p-e.width/2,L=Math.min(C,k)*2;E=Pe(h*a,Ie,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"s":{if(a){let C=p+e.width/2,k=l-p-e.width/2,L=Math.min(C,k)*2;E=Pe(h*a,Ie,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"w":{if(a){let C=m+e.height/2,k=c-m-e.height/2,L=Math.min(C,k)*2;h=Pe(E/a,Ie,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let C=m+e.height/2,k=c-m-e.height/2,L=Math.min(C,k)*2;h=Pe(E/a,Ie,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(M>-I){let C=w?c-m:m+e.height;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?p+e.width:l-p;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"nw":{if(a)if(M<I){let C=w?c-m:m+e.height;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?l-p:p+e.width;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"se":{if(a)if(M>I){let C=w?m+e.height:c-m;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?p+e.width:l-p;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"sw":{if(a)if(-M>I){let C=w?m+e.height:c-m;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?l-p:p+e.width;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}default:break}let F=eu(e,n,E,h,!!a);return Ks(g.width,g.naturalWidth)&&Ks(g.height,g.naturalHeight)&&(g=null),{x:F[0],y:F[1],width:E,height:h,crop:g}},eu=(e,t,n,o,i)=>{let[r,s,a,l]=Nt(e,e.width,e.height,!0),c=xt(r,s),d=xt(a,l),u=Jd(c,d),[p,m,f,E]=Nt(e,n,o,!0),h=f-p,g=E-m,x=[...c];if(["n","w","nw"].includes(t)&&(x=[d[0]-Math.abs(h),d[1]-Math.abs(g)]),t==="ne"){let D=[c[0],d[1]];x=[D[0],D[1]-Math.abs(g)]}if(t==="sw"){let D=[d[0],c[1]];x=[D[0]-Math.abs(h),D[1]]}i&&(["s","n"].includes(t)&&(x[0]=u[0]-h/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let y=e.angle,b=Ft(x,u,y),w=[x[0]+Math.abs(h)/2,x[1]+Math.abs(g)/2],I=Ft(w,u,y);x=Ft(b,I,-y);let M=[...x];return M[0]+=e.x-p,M[1]+=e.y-m,M},Qs=(e,t)=>{if(e.crop){let{width:n,height:o}=ji(e),[i,r,s,a,l,c]=H(e,t),d=Wi(Ft(xt(i,r),xt(l,c),e.angle)),u=Wi(Ft(xt(s,r),xt(l,c),e.angle)),p=$s(Zs(u,d)),m=Wi(Ft(xt(i,a),xt(l,c),e.angle)),f=Zs(m,d),E=$s(f),{cropX:h,cropY:g}=tu(e.crop,e.scale),x=Lo(Lo(d,Co(p,-h*n/e.crop.naturalWidth)),Co(E,-g*o/e.crop.naturalHeight)),y=qs(Lo(Lo(x,Co(p,n/2)),Co(E,o/2))),b=Ft(qs(x),y,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:o,crop:null}}return e},ji=e=>{if(e.crop){let t=e.width/(e.crop.width/e.crop.naturalWidth),n=e.height/(e.crop.height/e.crop.naturalHeight);return{width:t,height:n}}return{width:e.width,height:e.height}},tu=(e,t)=>{let n=e.x,o=e.y,i=t[0]===-1,r=t[1]===-1;return i&&(n=e.naturalWidth-Math.abs(n)-e.width),r&&(o=e.naturalHeight-Math.abs(o)-e.height),{cropX:n,cropY:o}},px=(e,t=!1)=>{let n=e.crop;if(!n)return null;let o=e.scale[0]===-1,i=e.scale[1]===-1,r=n.x,s=n.y;if(o&&(r=n.naturalWidth-n.width-n.x),i&&(s=n.naturalHeight-n.height-n.y),t)return{x:r,y:s};let{width:a,height:l}=ji(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as Ka,pointFrom as B,pointRotateRads as Te,pointsEqual as Qa,pointDistance as vn,vectorFromPoint as em,curveLength as tm,curvePointAtLength as nm}from"@excalidraw/math";import{DRAGGING_THRESHOLD as om,KEYS as Ln,shouldRotateWithDiscreteAngle as Ja,getGridPoint as el,invariant as At,tupleToCoors as Dr,viewportCoordsToSceneCoords as im}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as tl,isPathALoop as rm}from"@excalidraw/element";P();import{KEYS as Dp,arrayToMap as Ha,isBindingFallthroughEnabled as ni,tupleToCoors as vp,invariant as Lp,isDevEnv as Cp,isTestEnv as Bp}from"@excalidraw/common";import{lineSegment as Ye,pointFrom as R,pointRotateRads as ae,vectorFromPoint as Z,pointDistanceSq as jt,clamp as ka,pointDistance as ut,pointFromVector as An,vectorScale as Dn,vectorNormalize as ro,vectorCross as _e,pointsEqual as Gp,lineSegmentIntersectionPoints as Fa,PRECISION as Op}from"@excalidraw/math";P();import{isTransparent as Xu}from"@excalidraw/common";import{curveIntersectLineSegment as ya,isPointWithinBounds as Uo,lineSegment as Xo,lineSegmentIntersectionPoints as ba,pointFrom as St,pointFromVector as Wu,pointRotateRads as lt,pointsEqual as ju,vectorFromPoint as Vu,vectorNormalize as $u,vectorScale as Zu}from"@excalidraw/math";import{ellipse as qu,ellipseSegmentInterceptPoints as Ku}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as nu,DEFAULT_PROPORTIONAL_RADIUS as Vi,LINE_CONFIRM_THRESHOLD as ou,ROUNDNESS as $i}from"@excalidraw/common";import{curve as wt,curveCatmullRomCubicApproxPoints as Js,curveOffsetPoints as ea,lineSegment as ze,pointDistance as iu,pointFrom as U,pointFromArray as ru,rectangle as su}from"@excalidraw/math";var qn=new WeakMap,Zi=(e,t)=>{let n=qn.get(e);if(!n)return;let{version:o,shapes:i}=n;if(o!==e.version){qn.delete(e);return}return i.get(t)},qi=(e,t,n)=>{let o=qn.get(e);if(!o){qn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:i,shapes:r}=o;if(i!==e.version){qn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function Bo(e){let t=Zi(e,0);if(t)return t;let n=ta(e),o=[],i=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&ru(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");o.push(ze(U(e.x+l[0],e.y+l[1]),U(e.x+a.data[0],e.y+a.data[1])));continue;case"bcurveTo":if(!l)throw new Error("prevPoint is undefined");i.push(wt(U(e.x+l[0],e.y+l[1]),U(e.x+a.data[0],e.y+a.data[1]),U(e.x+a.data[2],e.y+a.data[3]),U(e.x+a.data[4],e.y+a.data[5])));continue;default:console.error("Unknown op type",a.op)}}let r=[o,i];return qi(e,r,0),r}function yn(e,t=0){let n=Zi(e,t);if(n)return n;let o=yt(Math.min(e.width,e.height),e);o===0&&(o=.01);let i=su(U(e.x,e.y),U(e.x+e.width,e.y+e.height)),r=ze(U(i[0][0]+o,i[0][1]),U(i[1][0]-o,i[0][1])),s=ze(U(i[1][0],i[0][1]+o),U(i[1][0],i[1][1]-o)),a=ze(U(i[0][0]+o,i[1][1]),U(i[1][0]-o,i[1][1])),l=ze(U(i[0][0],i[1][1]-o),U(i[0][0],i[0][1]+o)),c=[wt(l[1],U(l[1][0]+2/3*(i[0][0]-l[1][0]),l[1][1]+2/3*(i[0][1]-l[1][1])),U(r[0][0]+2/3*(i[0][0]-r[0][0]),r[0][1]+2/3*(i[0][1]-r[0][1])),r[0]),wt(r[1],U(r[1][0]+2/3*(i[1][0]-r[1][0]),r[1][1]+2/3*(i[0][1]-r[1][1])),U(s[0][0]+2/3*(i[1][0]-s[0][0]),s[0][1]+2/3*(i[0][1]-s[0][1])),s[0]),wt(s[1],U(s[1][0]+2/3*(i[1][0]-s[1][0]),s[1][1]+2/3*(i[1][1]-s[1][1])),U(a[1][0]+2/3*(i[1][0]-a[1][0]),a[1][1]+2/3*(i[1][1]-a[1][1])),a[1]),wt(a[0],U(a[0][0]+2/3*(i[0][0]-a[0][0]),a[0][1]+2/3*(i[1][1]-a[0][1])),U(l[0][0]+2/3*(i[0][0]-l[0][0]),l[0][1]+2/3*(i[1][1]-l[0][1])),l[0])],d=t>0?c.map(m=>Js(ea(m,t))):[[c[0]],[c[1]],[c[2]],[c[3]]],p=[[ze(d[0][d[0].length-1][3],d[1][0][0]),ze(d[1][d[1].length-1][3],d[2][0][0]),ze(d[2][d[2].length-1][3],d[3][0][0]),ze(d[3][d[3].length-1][3],d[0][0][0])],d.flat()];return qi(e,p,t),p}function bn(e,t=0){let n=Zi(e,t);if(n)return n;let[o,i,r,s,a,l,c,d]=Go(e),u=e.roundness?yt(Math.abs(o-c),e):(o-c)*.01,p=e.roundness?yt(Math.abs(s-i),e):(s-i)*.01,[m,f,E,h]=[U(e.x+o,e.y+i),U(e.x+r,e.y+s),U(e.x+a,e.y+l),U(e.x+c,e.y+d)],g=[wt(U(f[0]-u,f[1]-p),f,f,U(f[0]-u,f[1]+p)),wt(U(E[0]+u,E[1]-p),E,E,U(E[0]-u,E[1]-p)),wt(U(h[0]+u,h[1]+p),h,h,U(h[0]+u,h[1]-p)),wt(U(m[0]-u,m[1]+p),m,m,U(m[0]+u,m[1]+p))],x=t>0?g.map(w=>Js(ea(w,t))):[[g[0]],[g[1]],[g[2]],[g[3]]],b=[[ze(x[0][x[0].length-1][3],x[1][0][0]),ze(x[1][x[1].length-1][3],x[2][0][0]),ze(x[2][x[2].length-1][3],x[3][0][0]),ze(x[3][x[3].length-1][3],x[0][0][0])],x.flat()];return qi(e,b,t),b}var ln=(e,t=1)=>{if(e.length>=3){let[n,o]=[e[0],e[e.length-1]];return iu(n,o)<=ou/t}return!1},yt=(e,t)=>{if(t.roundness?.type===$i.PROPORTIONAL_RADIUS||t.roundness?.type===$i.LEGACY)return e*Vi;if(t.roundness?.type===$i.ADAPTIVE_RADIUS){let n=t.roundness?.value??nu,o=n/Vi;return e<=o?e*Vi:n}return 0};P();import{ROUNDNESS as Kn,assertNever as au}from"@excalidraw/common";import{pointsEqual as na}from"@excalidraw/math";var zt=e=>!!e&&e.type==="image"&&!!e.fileId,xe=e=>!!e&&e.type==="image",oa=e=>!!e&&e.type==="embeddable",Oo=e=>!!e&&e.type==="iframe",Ro=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),oe=e=>e!=null&&e.type==="text",ko=e=>e!=null&&e.type==="frame",ia=e=>e!=null&&e.type==="magicframe",$=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Se=e=>e!=null&&lu(e.type),lu=e=>e==="freedraw",X=e=>e!=null&&Ki(e.type),cn=e=>e!=null&&e.type==="line",_=e=>e!=null&&e.type==="arrow",G=e=>_(e)&&e.elbowed,Ix=e=>_(e)&&!e.elbowed,cu=e=>_(e)&&!e.elbowed&&!e.roundness,du=e=>_(e)&&!e.elbowed&&e.roundness!==null,Ki=e=>e==="arrow"||e==="line",Qi=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&uu(e.type),uu=e=>e==="arrow",Le=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),ra=e=>e!=null&&(e.type==="rectangle"||e.type==="diamond"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),Sx=e=>e!=null&&(e.type==="rectangle"||e.type==="image"||e.type==="text"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="freedraw"),pu=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||_(e)),Mx=e=>{let t=e?.type;if(!t)return!1;switch(t){case"text":case"diamond":case"rectangle":case"iframe":case"embeddable":case"ellipse":case"arrow":case"freedraw":case"line":case"frame":case"magicframe":case"image":case"selection":return!0;default:return au(t,null),!1}},Ji=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",st=e=>pu(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),de=e=>e!==null&&"containerId"in e&&e.containerId!==null&&oe(e),Tx=e=>!!e.startBinding||!!e.endBinding,sa=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",aa=e=>e==="line"||e==="arrow"||e==="diamond",Ax=(e,t)=>!!((e===Kn.ADAPTIVE_RADIUS||e===Kn.LEGACY)&&sa(t.type)||e===Kn.PROPORTIONAL_RADIUS&&aa(t.type)),Dx=e=>aa(e.type)?{type:Kn.PROPORTIONAL_RADIUS}:sa(e.type)?{type:Kn.ADAPTIVE_RADIUS}:null,Qn=e=>Object.hasOwn(e,"fixedPoint")&&e.fixedPoint!=null,vx=e=>Array.isArray(e)&&e.length===4&&typeof e[0]=="number"&&typeof e[1]=="number"&&typeof e[2]=="number"&&typeof e[3]=="number",Lx=e=>cu(e)?"sharpArrow":du(e)?"curvedArrow":G(e)?"elbowArrow":"line",Cx=e=>e.length>3&&na(e[0],e[e.length-1]),la=e=>e.length>3||e.length===3&&!na(e[0],e[e.length-1]);P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Bu,ARROW_LABEL_WIDTH_FRACTION as Gu,BOUND_TEXT_PADDING as at,DEFAULT_FONT_SIZE as Ou,TEXT_ALIGN as ha,VERTICAL_ALIGN as Ea,getFontString as Yo,isProdEnv as Ru,invariant as ku}from"@excalidraw/common";P();var Jn={},ca=(e,t)=>{let n=Jn[e]||(Jn[e]={height:t});return n.height=t,n},da=e=>{Jn[e]&&delete Jn[e]},Ox=e=>Jn[e]?.height??null;P();import{BOUND_TEXT_PADDING as No,DEFAULT_FONT_SIZE as mu,DEFAULT_FONT_FAMILY as fu,getFontString as hu,isTestEnv as Eu,normalizeEOL as gu}from"@excalidraw/common";var Qe=(e,t,n)=>{let o=e.split(`
|
|
1
|
+
var Rc=Object.create;var $s=Object.defineProperty;var Fc=Object.getOwnPropertyDescriptor;var Nc=Object.getOwnPropertyNames;var Hc=Object.getPrototypeOf,zc=Object.prototype.hasOwnProperty;var _c=(e,t)=>()=>(e&&(t=e(e=0)),t);var Uc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Wc=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Nc(t))!zc.call(e,o)&&o!==n&&$s(e,o,{get:()=>t[o],enumerable:!(i=Fc(t,o))||i.enumerable});return e};var Yc=(e,t,n)=>(n=e!=null?Rc(Hc(e)):{},Wc(t||!e||!e.__esModule?$s(n,"default",{value:e,enumerable:!0}):n,e));var v,P=_c(()=>{v={PROD:!0}});var Ud=Uc((hP,_d)=>{P();var zd="Expected a function",Nd=NaN,ch="[object Symbol]",uh=/^\s+|\s+$/g,mh=/^[-+]0x[0-9a-f]+$/i,ph=/^0b[01]+$/i,fh=/^0o[0-7]+$/i,hh=parseInt,Eh=typeof global=="object"&&global&&global.Object===Object&&global,gh=typeof self=="object"&&self&&self.Object===Object&&self,xh=Eh||gh||Function("return this")(),wh=Object.prototype,yh=wh.toString,bh=Math.max,Ph=Math.min,Ts=function(){return xh.Date.now()};function Ih(e,t,n){var i,o,r,s,a,l,d=0,c=!1,u=!1,m=!0;if(typeof e!="function")throw new TypeError(zd);t=Hd(t)||0,Xo(n)&&(c=!!n.leading,u="maxWait"in n,r=u?bh(Hd(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(I){var S=i,A=o;return i=o=void 0,d=I,s=e.apply(A,S),s}function f(I){return d=I,a=setTimeout(g,t),c?p(I):s}function h(I){var S=I-l,A=I-d,M=t-S;return u?Ph(M,r-A):M}function E(I){var S=I-l,A=I-d;return l===void 0||S>=t||S<0||u&&A>=r}function g(){var I=Ts();if(E(I))return x(I);a=setTimeout(g,h(I))}function x(I){return a=void 0,m&&i?p(I):(i=o=void 0,s)}function w(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function b(){return a===void 0?s:x(Ts())}function y(){var I=Ts(),S=E(I);if(i=arguments,o=this,l=I,S){if(a===void 0)return f(l);if(u)return a=setTimeout(g,t),p(l)}return a===void 0&&(a=setTimeout(g,t)),s}return y.cancel=w,y.flush=b,y}function Sh(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(zd);return Xo(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),Ih(e,t,{leading:i,maxWait:t,trailing:o})}function Xo(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Mh(e){return!!e&&typeof e=="object"}function Ah(e){return typeof e=="symbol"||Mh(e)&&yh.call(e)==ch}function Hd(e){if(typeof e=="number")return e;if(Ah(e))return Nd;if(Xo(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Xo(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(uh,"");var n=ph.test(e);return n||fh.test(e)?hh(e.slice(2),n?2:8):mh.test(e)?Nd:+e}_d.exports=Sh});P();import{toIterable as qE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Nt,viewportCoordsToSceneCoords as Uo}from"@excalidraw/common";import{normalizeRadians as wd,radiansBetweenAngles as zf,radiansDifference as _f}from"@excalidraw/math";import{pointsEqual as Uf}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function ar(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 Xc(e,t,n){let i=[];e.forEach(o=>i.push(...o)),ar(i,t,n)}function Vc(e,t){return e[0]===t[0]&&e[1]===t[1]}function Zs(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)ar(d,a,o);let l=$c(s,r,i);if(o){for(let d of s)ar(d,a,-o);Xc(l,a,-o)}return l}function $c(e,t,n){let i=[];for(let d of e){let c=[...d];Vc(c[0],c[c.length-1])||c.push([c[0][0],c[0][1]]),c.length>2&&i.push(c)}let o=[];t=Math.max(t,.1);let r=[];for(let d of i)for(let c=0;c<d.length-1;c++){let u=d[c],m=d[c+1];if(u[1]!==m[1]){let p=Math.min(u[1],m[1]);r.push({ymin:p,ymax:Math.max(u[1],m[1]),x:p===u[1]?u[0]:m[0],islope:(m[0]-u[0])/(m[1]-u[1])})}}if(r.sort((d,c)=>d.ymin<c.ymin?-1:d.ymin>c.ymin?1:d.x<c.x?-1:d.x>c.x?1:d.ymax===c.ymax?0:(d.ymax-c.ymax)/Math.abs(d.ymax-c.ymax)),!r.length)return o;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let d=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)d=u;r.splice(0,d+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(d=>!(d.edge.ymax<=a)),s.sort((d,c)=>d.edge.x===c.edge.x?0:(d.edge.x-c.edge.x)/Math.abs(d.edge.x-c.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let d=0;d<s.length;d=d+2){let c=d+1;if(c>=s.length)break;let u=s[d].edge,m=s[c].edge;o.push([[Math.round(u.x),a],[Math.round(m.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.edge.islope}),l++}return o}function lt(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),Zs(e,o,i,r||1)}var Ut=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=lt(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 Wt(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 Ni=class extends Ut{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=lt(t,o),s=Math.PI/180*n.hachureAngle,a=[],l=i*.5*Math.cos(s),d=i*.5*Math.sin(s);for(let[u,m]of r)Wt([u,m])&&a.push([[u[0]-l,u[1]+d],[...m]],[[u[0]+l,u[1]-d],[...m]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var Hi=class extends Ut{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 zi=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=lt(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=Wt(a),d=l/o,c=Math.ceil(d)-1,u=l-c*o,m=(a[0][0]+a[1][0])/2-o/4,p=Math.min(a[0][1],a[1][1]);for(let f=0;f<c;f++){let h=p+u+f*o,E=m-s+Math.random()*2*s,g=h-s+Math.random()*2*s,x=this.helper.ellipse(E,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var _i=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=lt(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=Wt(s),l=Math.floor(a/(i+o)),d=(a+o-l*(i+o))/2,c=s[0],u=s[1];c[0]>u[0]&&(c=s[1],u=s[0]);let m=Math.atan((u[1]-c[1])/(u[0]-c[0]));for(let p=0;p<l;p++){let f=p*(i+o),h=f+i,E=[c[0]+f*Math.cos(m)+d*Math.cos(m),c[1]+f*Math.sin(m)+d*Math.sin(m)],g=[c[0]+h*Math.cos(m)+d*Math.cos(m),c[1]+h*Math.sin(m)+d*Math.sin(m)];r.push(...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],n))}}),r}};P();var Ui=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=lt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=Wt(r),a=Math.round(s/(2*n)),l=r[0],d=r[1];l[0]>d[0]&&(l=r[1],d=r[0]);let c=Math.atan((d[1]-l[1])/(d[0]-l[0]));for(let u=0;u<a;u++){let m=u*2*n,p=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),h=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],E=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],g=[h[0]+f*Math.cos(c+Math.PI/4),h[1]+f*Math.sin(c+Math.PI/4)];o.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],i),...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],i))}}),o}};var Le={};function qs(e,t){let n=e.fillStyle||"hachure";if(!Le[n])switch(n){case"zigzag":Le[n]||(Le[n]=new Ni(t));break;case"cross-hatch":Le[n]||(Le[n]=new Hi(t));break;case"dots":Le[n]||(Le[n]=new zi(t));break;case"dashed":Le[n]||(Le[n]=new _i(t));break;case"zigzag-line":Le[n]||(Le[n]=new Ui(t));break;case"hachure":default:n="hachure",Le[n]||(Le[n]=new Ut(t));break}return Le[n]}P();function Ks(){return Math.floor(Math.random()*2**31)}var Wi=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};P();P();var Yi={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Zc(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 lr(e,t){return e.type===t}function Cn(e){let t=[],n=Zc(e),i="BOD",o=0,r=n[o];for(;!lr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=Yi[r.text],i=r.text;else return Cn("M0,0"+e);else lr(r,1)?s=Yi[i]:(o++,s=Yi[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(lr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof Yi[i]=="number"){let l={key:i,data:a};t.push(l),o+=s,r=n[o],i==="M"&&(i="L"),i==="m"&&(i="l")}else throw new Error("Bad segment: "+i)}else throw new Error("Path data ended short")}return t}P();function Kn(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 Jn(e){let t=[],n="",i=0,o=0,r=0,s=0,a=0,l=0;for(let{key:d,data:c}of e){switch(d){case"M":t.push({key:"M",data:[...c]}),[i,o]=c,[r,s]=c;break;case"C":t.push({key:"C",data:[...c]}),i=c[4],o=c[5],a=c[2],l=c[3];break;case"L":t.push({key:"L",data:[...c]}),[i,o]=c;break;case"H":i=c[0],t.push({key:"L",data:[i,o]});break;case"V":o=c[0],t.push({key:"L",data:[i,o]});break;case"S":{let u=0,m=0;n==="C"||n==="S"?(u=i+(i-a),m=o+(o-l)):(u=i,m=o),t.push({key:"C",data:[u,m,...c]}),a=c[0],l=c[1],i=c[2],o=c[3];break}case"T":{let[u,m]=c,p=0,f=0;n==="Q"||n==="T"?(p=i+(i-a),f=o+(o-l)):(p=i,f=o);let h=i+2*(p-i)/3,E=o+2*(f-o)/3,g=u+2*(p-u)/3,x=m+2*(f-m)/3;t.push({key:"C",data:[h,E,g,x,u,m]}),a=p,l=f,i=u,o=m;break}case"Q":{let[u,m,p,f]=c,h=i+2*(u-i)/3,E=o+2*(m-o)/3,g=p+2*(u-p)/3,x=f+2*(m-f)/3;t.push({key:"C",data:[h,E,g,x,p,f]}),a=u,l=m,i=p,o=f;break}case"A":{let u=Math.abs(c[0]),m=Math.abs(c[1]),p=c[2],f=c[3],h=c[4],E=c[5],g=c[6];u===0||m===0?(t.push({key:"C",data:[i,o,E,g,E,g]}),i=E,o=g):(i!==E||o!==g)&&(Qs(i,o,E,g,u,m,p,f,h).forEach(function(w){t.push({key:"C",data:w})}),i=E,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function qc(e){return Math.PI*e/180}function Qn(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 Qs(e,t,n,i,o,r,s,a,l,d){let c=qc(s),u=[],m=0,p=0,f=0,h=0;if(d)[m,p,f,h]=d;else{[e,t]=Qn(e,t,-c),[n,i]=Qn(n,i,-c);let G=(e-n)/2,B=(t-i)/2,U=G*G/(o*o)+B*B/(r*r);U>1&&(U=Math.sqrt(U),o=U*o,r=U*r);let N=a===l?-1:1,W=o*o,F=r*r,T=W*F-W*B*B-F*G*G,$=W*B*B+F*G*G,Z=N*Math.sqrt(Math.abs(T/$));f=Z*o*B/r+(e+n)/2,h=Z*-r*G/o+(t+i)/2,m=Math.asin(parseFloat(((t-h)/r).toFixed(9))),p=Math.asin(parseFloat(((i-h)/r).toFixed(9))),e<f&&(m=Math.PI-m),n<f&&(p=Math.PI-p),m<0&&(m=Math.PI*2+m),p<0&&(p=Math.PI*2+p),l&&m>p&&(m=m-Math.PI*2),!l&&p>m&&(p=p-Math.PI*2)}let E=p-m;if(Math.abs(E)>Math.PI*120/180){let G=p,B=n,U=i;l&&p>m?p=m+Math.PI*120/180*1:p=m+Math.PI*120/180*-1,n=f+o*Math.cos(p),i=h+r*Math.sin(p),u=Qs(n,i,B,U,o,r,s,0,l,[p,G,f,h])}E=p-m;let g=Math.cos(m),x=Math.sin(m),w=Math.cos(p),b=Math.sin(p),y=Math.tan(E/4),I=4/3*o*y,S=4/3*r*y,A=[e,t],M=[e+I*x,t-S*g],k=[n+I*b,i-S*w],L=[n,i];if(M[0]=2*A[0]-M[0],M[1]=2*A[1]-M[1],d)return[M,k,L].concat(u);{u=[M,k,L].concat(u);let G=[];for(let B=0;B<u.length;B+=3){let U=Qn(u[B][0],u[B][1],c),N=Qn(u[B+1][0],u[B+1][1],c),W=Qn(u[B+2][0],u[B+2][1],c);G.push([U[0],U[1],N[0],N[1],W[0],W[1]])}return G}}var Kc={randOffset:eu,randOffsetWithRange:tu,ellipse:Jc,doubleLineOps:nu};function dr(e,t,n,i,o){return{type:"path",ops:xt(e,t,n,i,o)}}function ei(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...xt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...xt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return dr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Qc(e,t){return ei(e,!0,t)}function ia(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Qc(r,o)}function cr(e,t){let n=ea(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=ea(e,1.5*(1+t.roughness*.22),iu(t));n=n.concat(i)}return{type:"path",ops:n}}function Jc(e,t,n,i,o){let r=ur(n,i,o);return Vi(e,t,o,r).opset}function ur(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=R(s*l,n),a+=R(a*l,n),{increment:r,rx:s,ry:a}}function Vi(e,t,n,i){let[o,r]=ta(i.increment,e,t,i.rx,i.ry,1,i.increment*ji(.1,ji(.4,1,n),n),n),s=Xi(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=ta(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Xi(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function mr(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),m=Math.abs(i/2);u+=R(u*.01,l),m+=R(m*.01,l);let p=o,f=r;for(;p<0;)p+=Math.PI*2,f+=Math.PI*2;f-p>Math.PI*2&&(p=0,f=Math.PI*2);let h=Math.PI*2/l.curveStepCount,E=Math.min(h/2,(f-p)/2),g=na(E,d,c,u,m,p,f,1,l);if(!l.disableMultiStroke){let x=na(E,d,c,u,m,p,f,1.5,l);g.push(...x)}return s&&(a?g.push(...xt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...xt(d,c,d+u*Math.cos(f),c+m*Math.sin(f),l)):g.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(p),c+m*Math.sin(p)]})),{type:"path",ops:g}}function pr(e,t){let n=Jn(Kn(Cn(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(...xt(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,d,c,u,m,p]=a;i.push(...ou(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...xt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function $i(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+R(o,t),i[0][1]+R(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+R(o,t),i[s][1]+R(o,t)]})}}return{type:"fillPath",ops:n}}function gn(e,t){return qs(t,Kc).fillPolygons(e,t)}function oa(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=R(d*.01,s),c+=R(c*.01,s);let u=o,m=r;for(;u<0;)u+=Math.PI*2,m+=Math.PI*2;m-u>Math.PI*2&&(u=0,m=Math.PI*2);let p=(m-u)/s.curveStepCount,f=[];for(let h=u;h<=m;h=h+p)f.push([a+d*Math.cos(h),l+c*Math.sin(h)]);return f.push([a+d*Math.cos(m),l+c*Math.sin(m)]),f.push([a,l]),gn([f],s)}function eu(e,t){return R(e,t)}function tu(e,t,n){return ji(e,t,n)}function nu(e,t,n,i,o){return xt(e,t,n,i,o,!0)}function iu(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function ra(e){return e.randomizer||(e.randomizer=new Wi(e.seed||0)),e.randomizer.next()}function ji(e,t,n,i=1){return n.roughness*i*(ra(n)*(t-e)+e)}function R(e,t,n=1){return ji(-e,e,t,n)}function xt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=Js(e,t,n,i,o,!0,!1);if(s)return a;let l=Js(e,t,n,i,o,!0,!0);return a.concat(l)}function Js(e,t,n,i,o,r,s){let a=Math.pow(e-n,2)+Math.pow(t-i,2),l=Math.sqrt(a),d=1;l<200?d=1:l>500?d=.4:d=-.0016668*l+1.233334;let c=o.maxRandomnessOffset||0;c*c*100>a&&(c=l/10);let u=c/2,m=.2+ra(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,f=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=R(p,o,d),f=R(f,o,d);let h=[],E=()=>R(u,o,d),g=()=>R(c,o,d),x=o.preserveVertices;return r&&(s?h.push({op:"move",data:[e+(x?0:E()),t+(x?0:E())]}):h.push({op:"move",data:[e+(x?0:R(c,o,d)),t+(x?0:R(c,o,d))]})),s?h.push({op:"bcurveTo",data:[p+e+(n-e)*m+E(),f+t+(i-t)*m+E(),p+e+2*(n-e)*m+E(),f+t+2*(i-t)*m+E(),n+(x?0:E()),i+(x?0:E())]}):h.push({op:"bcurveTo",data:[p+e+(n-e)*m+g(),f+t+(i-t)*m+g(),p+e+2*(n-e)*m+g(),f+t+2*(i-t)*m+g(),n+(x?0:g()),i+(x?0:g())]}),h}function ea(e,t,n){let i=[];i.push([e[0][0]+R(t,n),e[0][1]+R(t,n)]),i.push([e[0][0]+R(t,n),e[0][1]+R(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+R(t,n),e[o][1]+R(t,n)]),o===e.length-1&&i.push([e[o][0]+R(t,n),e[o][1]+R(t,n)]);return Xi(i,null,n)}function Xi(e,t,n){let i=e.length,o=[];if(i>3){let r=[],s=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<i;a++){let l=e[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*e[a+1][0]-s*e[a-1][0])/6,l[1]+(s*e[a+1][1]-s*e[a-1][1])/6],r[2]=[e[a+1][0]+(s*e[a][0]-s*e[a+2][0])/6,e[a+1][1]+(s*e[a][1]-s*e[a+2][1])/6],r[3]=[e[a+1][0],e[a+1][1]],o.push({op:"bcurveTo",data:[r[1][0],r[1][1],r[2][0],r[2][1],r[3][0],r[3][1]]})}if(t&&t.length===2){let a=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+R(a,n),t[1]+R(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...xt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function ta(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let m=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(m),c.push(m)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=R(.5,a)-Math.PI/2;c.push([R(r,a)+t+.9*i*Math.cos(u-e),R(r,a)+n+.9*o*Math.sin(u-e)]);let m=Math.PI*2+u-.01;for(let p=u;p<m;p=p+e){let f=[R(r,a)+t+i*Math.cos(p),R(r,a)+n+o*Math.sin(p)];d.push(f),c.push(f)}c.push([R(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),R(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([R(r,a)+t+.98*i*Math.cos(u+s),R(r,a)+n+.98*o*Math.sin(u+s)]),c.push([R(r,a)+t+.9*i*Math.cos(u+s*.5),R(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function na(e,t,n,i,o,r,s,a,l){let d=r+R(.1,l),c=[];c.push([R(a,l)+t+.9*i*Math.cos(d-e),R(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([R(a,l)+t+i*Math.cos(u),R(a,l)+n+o*Math.sin(u)]);return c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),Xi(c,null,l)}function ou(e,t,n,i,o,r,s,a){let l=[],d=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],c=[0,0],u=a.disableMultiStroke?1:2,m=a.preserveVertices;for(let p=0;p<u;p++)p===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(m?0:R(d[0],a)),s[1]+(m?0:R(d[0],a))]}),c=m?[o,r]:[o+R(d[p],a),r+R(d[p],a)],l.push({op:"bcurveTo",data:[e+R(d[p],a),t+R(d[p],a),n+R(d[p],a),i+R(d[p],a),c[0],c[1]]});return l}P();function ti(e){return[...e]}function sa(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(ti(e[0]),ti(e[1]),ti(e[2]),ti(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(ti(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 ru(e,t){return Math.sqrt(Zi(e,t))}function Zi(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function su(e,t,n){let i=Zi(t,n);if(i===0)return Zi(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)),Zi(e,xn(t,n,o))}function xn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function au(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 fr(e,t,n,i){let o=i||[];if(au(e,t)<n){let r=e[t+0];o.length?ru(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=xn(s,a,.5),u=xn(a,l,.5),m=xn(l,d,.5),p=xn(c,u,.5),f=xn(u,m,.5),h=xn(p,f,.5);fr([s,c,p,h],0,n,o),fr([h,f,m,d],0,n,o)}return o}function ni(e,t){return qi(e,0,e.length,t)}function qi(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=su(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(qi(e,t,d+1,i,r),qi(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function wt(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;fr(e,s,t,i)}return n&&n>0?qi(i,0,i.length,n):i}P();function aa(e,t,n){let i=Cn(e),o=Jn(Kn(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...wt(l,t)),l=[]},c=()=>{d(),s.length&&(r.push(s),s=[])};for(let{key:m,data:p}of o)switch(m){case"M":c(),a=[p[0],p[1]],s.push(a);break;case"L":d(),s.push([p[0],p[1]]);break;case"C":if(!l.length){let f=s.length?s[s.length-1]:a;l.push([f[0],f[1]])}l.push([p[0],p[1]]),l.push([p[2],p[3]]),l.push([p[4],p[5]]);break;case"Z":d(),s.push([a[0],a[1]]);break}if(c(),!n)return r;let u=[];for(let m of r){let p=ni(m,n);p.length&&u.push(p)}return u}var ze="none",Ve=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 Ks()}_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",[dr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=ia(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($i([d],s)):a.push(gn([d],s))}return s.stroke!==ze&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=ur(i,o,s),d=Vi(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Vi(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(gn([d.estimatedPoints],s));return s.stroke!==ze&&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",[ei(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=mr(t,n,i,o,r,s,a,!0,d);if(a&&d.fill)if(d.fillStyle==="solid"){let m=Object.assign({},d);m.disableMultiStroke=!0;let p=mr(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(oa(t,n,i,o,r,s,d));return d.stroke!==ze&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=cr(t,i);if(i.fill&&i.fill!==ze&&t.length>=3)if(i.fillStyle==="solid"){let s=cr(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=sa(t),a=wt(s,10,(1+i.roughness)/2);o.push(gn([a],i))}return i.stroke!==ze&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=ei(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push($i([t],i)):o.push(gn([t],i))),i.stroke!==ze&&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!==ze,s=i.stroke!==ze,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=aa(t,1,l),c=pr(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=pr(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($i(d,i));else o.push(gn(d,i));return s&&(a?d.forEach(u=>{o.push(ei(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:ze};break;case"fillPath":s={d:this.opsToPath(r),stroke:ze,strokeWidth:0,fill:i.fill||ze};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||ze,strokeWidth:i,fill:ze}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var Ki=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new Ve(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 ii="http://www.w3.org/2000/svg";var Qi=class{constructor(t,n){this.svg=t,this.gen=new Ve(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(ii,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(ii,"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(ii,"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(ii,"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 wn={canvas(e,t){return new Ki(e,t)},svg(e,t){return new Qi(e,t)},generator(e){return new Ve(e)},newSeed(){return Ve.newSeed()}};import{arrayToMap as gd,invariant as ps,rescalePoints as md,sizeOf as Bf}from"@excalidraw/common";import{degreesToRadians as ms,lineSegment as Ee,pointDistance as Cf,pointFrom as D,pointFromArray as xd,pointRotateRads as oe}from"@excalidraw/math";P();import{invariant as lu}from"@excalidraw/common";import{curve as du,lineSegment as cu,pointFrom as se,pointDistance as Ox,pointFromArray as uu,pointFromVector as mu,pointRotateRads as Je,polygon as la,polygonFromPoints as hr,PRECISION as kx,segmentsIntersectAt as Rx,vector as pu,vectorAdd as fu,vectorFromPoint as hu,vectorScale as Fx}from"@excalidraw/math";import{getElementAbsoluteCoords as Hx}from"@excalidraw/element";var da=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=se(s,a),d;return e.type==="diamond"?d=la(Je(se(s,r),l,t),Je(se(o+n,a),l,t),Je(se(s,r+i),l,t),Je(se(o,a),l,t)):d=la(Je(se(o,r),l,t),Je(se(o+n,r),l,t),Je(se(o+n,r+i),l,t),Je(se(o,r+i),l,t)),{type:"polygon",data:d}};var ca=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:se(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},yt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},ua=(e,t=se(0,0),n,i)=>{let o=l=>Je(se(l[0]+t[0],l[1]+t[1]),i,n),r=yt(e),s=[],a=se(0,0);for(let l of r){if(l.op==="move"){let d=uu(l.data);lu(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(se(l.data[0],l.data[1])),c=o(se(l.data[2],l.data[3])),u=o(se(l.data[4],l.data[5]));s.push(du(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Eu=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(cu(t,o)),t=o}return n},ma=(e,t,n=!1)=>{let i=r=>Je(mu(fu(hu(r),pu(e.x,e.y))),t,e.angle),o=Eu(e.points.map(r=>i(r)));return n?{type:"polygon",data:hr(o.flat())}:{type:"polyline",data:o}},pa=(e,t,n=se(0,0),i,o)=>{let r=c=>Je(se(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:hr(e.points.map(c=>r(c)))};let s=yt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(se(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(se(c.data[0],c.data[1])),a.push(se(c.data[2],c.data[3])),a.push(se(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(se(c.data[0],c.data[1]));let d=wt(a,10,5).map(c=>r(c));return{type:"polygon",data:hr(d)}};P();P();function fa(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function gu(e){return[-e[0],-e[1]]}function tt(e,t){return[e[0]+t[0],e[1]+t[1]]}function $e(e,t){return[e[0]-t[0],e[1]-t[1]]}function et(e,t){return[e[0]*t,e[1]*t]}function xu(e,t){return[e[0]/t,e[1]/t]}function oi(e){return[e[1],-e[0]]}function ha(e,t){return e[0]*t[0]+e[1]*t[1]}function wu(e,t){return e[0]===t[0]&&e[1]===t[1]}function yu(e){return Math.hypot(e[0],e[1])}function bu(e){return e[0]*e[0]+e[1]*e[1]}function Ea(e,t){return bu($e(e,t))}function wa(e){return xu(e,yu(e))}function Pu(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function ri(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 Er(e,t,n){return tt(e,et($e(t,e),n))}function ga(e,t,n){return tt(e,et(t,n))}var{min:Gn,PI:Iu}=Math,xa=.275,si=Iu+1e-4;function Su(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=F=>F,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=F=>F*(2-F)}=a,{cap:m=!0,easing:p=F=>--F*F*F+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,h=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,E=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*i,2),x=[],w=[],b=e.slice(0,10).reduce((F,T)=>{let $=T.pressure;if(r){let Z=Gn(1,T.distance/n),Et=Gn(1,1-Z);$=Gn(1,F+(Et-F)*(Z*xa))}return(F+$)/2},e[0].pressure),y=fa(n,o,e[e.length-1].pressure,s),I,S=e[0].vector,A=e[0].point,M=A,k=A,L=M,G=!1;for(let F=0;F<e.length;F++){let{pressure:T}=e[F],{point:$,vector:Z,distance:Et,runningLength:at}=e[F];if(F<e.length-1&&f-at<3)continue;if(o){if(r){let He=Gn(1,Et/n),Xe=Gn(1,1-He);T=Gn(1,b+(Xe-b)*(He*xa))}y=fa(n,o,T,s)}else y=n/2;I===void 0&&(I=y);let Oi=at<h?u(at/h):1,rr=f-at<E?p((f-at)/E):1;y=Math.max(.01,y*Math.min(Oi,rr));let ki=(F<e.length-1?e[F+1]:e[F]).vector,qn=F<e.length-1?ha(Z,ki):1,sr=ha(Z,S)<0&&!G,Ri=qn!==null&&qn<0;if(sr||Ri){let He=et(oi(S),y);for(let Xe=1/13,_t=0;_t<=1;_t+=Xe)k=ri($e($,He),$,si*_t),x.push(k),L=ri(tt($,He),$,si*-_t),w.push(L);A=k,M=L,Ri&&(G=!0);continue}if(G=!1,F===e.length-1){let He=et(oi(Z),y);x.push($e($,He)),w.push(tt($,He));continue}let Fi=et(oi(Er(ki,Z,qn)),y);k=$e($,Fi),(F<=1||Ea(A,k)>g)&&(x.push(k),A=k),L=tt($,Fi),(F<=1||Ea(M,L)>g)&&(w.push(L),M=L),b=T,S=Z}let B=e[0].point.slice(0,2),U=e.length>1?e[e.length-1].point.slice(0,2):tt(e[0].point,[1,1]),N=[],W=[];if(e.length===1){if(!(h||E)||d){let F=ga(B,wa(oi($e(B,U))),-(I||y)),T=[];for(let $=1/13,Z=$;Z<=1;Z+=$)T.push(ri(F,B,si*2*Z));return T}}else{if(!(h||E&&e.length===1))if(c)for(let T=1/13,$=T;$<=1;$+=T){let Z=ri(w[0],B,si*$);N.push(Z)}else{let T=$e(x[0],w[0]),$=et(T,.5),Z=et(T,.51);N.push($e(B,$),$e(B,Z),tt(B,Z),tt(B,$))}let F=oi(gu(e[e.length-1].vector));if(E||h&&e.length===1)W.push(U);else if(m){let T=ga(U,F,y);for(let $=1/29,Z=$;Z<1;Z+=$)W.push(ri(T,U,si*3*Z))}else W.push(tt(U,et(F,y)),tt(U,et(F,y*.99)),$e(U,et(F,y*.99)),$e(U,et(F,y)))}return x.concat(W,w.reverse(),N)}function Mu(e,t={}){var n;let{streamline:i=.5,size:o=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-i)*.85,a=Array.isArray(e[0])?e:e.map(({x:p,y:f,pressure:h=.5})=>[p,f,h]);if(a.length===2){let p=a[1];a=a.slice(0,-1);for(let f=1;f<5;f++)a.push(Er(a[0],p,f/4))}a.length===1&&(a=[...a,[...tt(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=!1,c=0,u=l[0],m=a.length-1;for(let p=1;p<a.length;p++){let f=r&&p===m?a[p].slice(0,2):Er(u.point,a[p],s);if(wu(u.point,f))continue;let h=Pu(f,u.point);if(c+=h,p<m&&!d){if(c<o)continue;d=!0}u={point:f,pressure:a[p][2]>=0?a[p][2]:.5,vector:wa($e(u.point,f)),distance:h,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function ya(e,t={}){return Su(Mu(e,t),t)}import{pointFrom as le,pointDistance as rd,pointRotateRads as Rt}from"@excalidraw/math";import{ROUGHNESS as yf,THEME as cs,isTransparent as Di,assertNever as bf,COLOR_PALETTE as Pf,LINE_POLYGON_POINT_MERGE_DISTANCE as If,applyDarkModeFilter as _o}from"@excalidraw/common";P();import{isRightAngleRads as df,lineSegment as Ql,pointFrom as ko,pointRotateRads as ls}from"@excalidraw/math";import{BOUND_TEXT_PADDING as Ro,DEFAULT_REDUCED_GLOBAL_ALPHA as cf,ELEMENT_READY_TO_ERASE_OPACITY as uf,FRAME_STYLE as Ti,MIME_TYPES as ed,THEME as No,distance as dn,getFontString as mf,isRTL as pf,getVerticalOffset as ff,invariant as hf,applyDarkModeFilter as Ho}from"@excalidraw/common";P();import{pointFrom as bt,pointCenter as Au,pointRotateRads as Yt,vectorFromPoint as gr,vectorNormalize as ba,vectorSubtract as Pa,vectorAdd as Ji,vectorScale as eo,pointFromVector as Ia,clamp as be,isCloseTo as Sa}from"@excalidraw/math";var Pe=10,Xx=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=xr(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,f=Yt(bt(r,s),de(e,t),-e.angle);r=f[0],s=f[1];let h=e.width,E=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,w=g.width,b=e.scale[0]===-1,y=e.scale[1]===-1,I=s-e.y,S=r-e.x;n.includes("n")&&(E=be(e.height-I,Pe,y?d-p:e.height+p)),n.includes("s")&&(I=s-e.y-e.height,E=be(e.height+I,Pe,y?e.height+p:d-p)),n.includes("e")&&(S=r-e.x-e.width,h=be(e.width+S,Pe,b?e.width+m:l-m)),n.includes("w")&&(h=be(e.width-S,Pe,b?l-m:e.width+m));let A=L=>{L.height=E*u,L.width=h*c};A(g);let M=(L,G)=>{A(G),L.includes("n")&&(y||(G.y+=x-G.height)),L.includes("s")&&y&&(G.y+=x-G.height),L.includes("e")&&b&&(G.x+=w-G.width),L.includes("w")&&(b||(G.x+=w-G.width))};switch(n){case"n":{if(a){let L=m+e.width/2,G=l-m-e.width/2,B=Math.min(L,G)*2;h=be(E*a,Pe,B),E=h/a}M(n,g),a&&(g.x+=(w-g.width)/2);break}case"s":{if(a){let L=m+e.width/2,G=l-m-e.width/2,B=Math.min(L,G)*2;h=be(E*a,Pe,B),E=h/a}M(n,g),a&&(g.x+=(w-g.width)/2);break}case"w":{if(a){let L=p+e.height/2,G=d-p-e.height/2,B=Math.min(L,G)*2;E=be(h/a,Pe,B),h=E*a}M(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let L=p+e.height/2,G=d-p-e.height/2,B=Math.min(L,G)*2;E=be(h/a,Pe,B),h=E*a}M(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(S>-I){let L=y?d-p:p+e.height;E=be(h/a,Pe,L),h=E*a}else{let L=b?m+e.width:l-m;h=be(E*a,Pe,L),E=h/a}M(n,g);break}case"nw":{if(a)if(S<I){let L=y?d-p:p+e.height;E=be(h/a,Pe,L),h=E*a}else{let L=b?l-m:m+e.width;h=be(E*a,Pe,L),E=h/a}M(n,g);break}case"se":{if(a)if(S>I){let L=y?p+e.height:d-p;E=be(h/a,Pe,L),h=E*a}else{let L=b?m+e.width:l-m;h=be(E*a,Pe,L),E=h/a}M(n,g);break}case"sw":{if(a)if(-S>I){let L=y?p+e.height:d-p;E=be(h/a,Pe,L),h=E*a}else{let L=b?l-m:m+e.width;h=be(E*a,Pe,L),E=h/a}M(n,g);break}default:break}let k=Tu(e,n,h,E,!!a);return Sa(g.width,g.naturalWidth)&&Sa(g.height,g.naturalHeight)&&(g=null),{x:k[0],y:k[1],width:h,height:E,crop:g}},Tu=(e,t,n,i,o)=>{let[r,s,a,l]=jt(e,e.width,e.height,!0),d=bt(r,s),c=bt(a,l),u=Au(d,c),[m,p,f,h]=jt(e,n,i,!0),E=f-m,g=h-p,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(E),c[1]-Math.abs(g)]),t==="ne"){let A=[d[0],c[1]];x=[A[0],A[1]-Math.abs(g)]}if(t==="sw"){let A=[c[0],d[1]];x=[A[0]-Math.abs(E),A[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-E/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let w=e.angle,b=Yt(x,u,w),y=[x[0]+Math.abs(E)/2,x[1]+Math.abs(g)/2],I=Yt(y,u,w);x=Yt(b,I,-w);let S=[...x];return S[0]+=e.x-m,S[1]+=e.y-p,S},Ma=(e,t)=>{if(e.crop){let{width:n,height:i}=xr(e),[o,r,s,a,l,d]=X(e,t),c=gr(Yt(bt(o,r),bt(l,d),e.angle)),u=gr(Yt(bt(s,r),bt(l,d),e.angle)),m=ba(Pa(u,c)),p=gr(Yt(bt(o,a),bt(l,d),e.angle)),f=Pa(p,c),h=ba(f),{cropX:E,cropY:g}=vu(e.crop,e.scale),x=Ji(Ji(c,eo(m,-E*n/e.crop.naturalWidth)),eo(h,-g*i/e.crop.naturalHeight)),w=Ia(Ji(Ji(x,eo(m,n/2)),eo(h,i/2))),b=Yt(Ia(x),w,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:i,crop:null}}return e},xr=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}},vu=(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}},Vx=(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}=xr(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as yl,pointFrom as C,pointRotateRads as Ae,pointsEqual as bl,pointDistance as rn,vectorFromPoint as Mp,curveLength as Ap,curvePointAtLength as Tp,lineSegment as Pl}from"@excalidraw/math";import{DRAGGING_THRESHOLD as vp,KEYS as vn,shouldRotateWithDiscreteAngle as Si,getGridPoint as Il,invariant as Te,isShallowEqual as Dp,getFeatureFlag as Mi}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as Sl,isPathALoop as Lp,moveArrowAboveBindable as Ml,projectFixedPointOntoDiagonal as Al}from"@excalidraw/element";P();import{KEYS as sp,arrayToMap as ml,getFeatureFlag as ap,invariant as ot,isTransparent as lp}from"@excalidraw/common";import{PRECISION as dp,clamp as Kr,lineSegment as yi,pointDistance as Gt,pointDistanceSq as wi,pointFrom as q,pointFromVector as Hn,pointRotateRads as re,pointsEqual as cp,vectorFromPoint as _n,vectorNormalize as Ao,vectorScale as zn}from"@excalidraw/math";P();import{invariant as Pm,isTransparent as $a}from"@excalidraw/common";import{curveIntersectLineSegment as Za,isPointWithinBounds as po,lineSegment as fi,lineSegmentIntersectionPoints as qa,pointFrom as me,pointFromVector as Im,pointRotateRads as Ue,pointsEqual as Sm,vectorFromPoint as Mm,vectorNormalize as Am,vectorScale as Tm}from"@excalidraw/math";import{ellipse as vm,ellipseSegmentInterceptPoints as Dm}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as Ru,DEFAULT_PROPORTIONAL_RADIUS as br,invariant as Fu,LINE_CONFIRM_THRESHOLD as Nu,ROUNDNESS as Pr}from"@excalidraw/common";import{curve as It,curveCatmullRomCubicApproxPoints as Oa,curveOffsetPoints as ka,lineSegment as he,lineSegmentIntersectionPoints as Ca,pointDistance as On,pointFrom as z,pointFromArray as Hu,pointFromVector as zu,pointRotateRads as Xt,pointTranslate as Ga,rectangle as _u,vectorFromPoint as Ra,vectorNormalize as Uu,vectorScale as Ir}from"@excalidraw/math";P();import{ROUNDNESS as ai,assertNever as Du}from"@excalidraw/common";import{pointsEqual as Aa}from"@excalidraw/math";var yn=e=>!!e&&e.type==="image"&&!!e.fileId,xe=e=>!!e&&e.type==="image",Ta=e=>!!e&&e.type==="embeddable",to=e=>!!e&&e.type==="iframe",no=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),ee=e=>e!=null&&e.type==="text",io=e=>e!=null&&e.type==="frame",va=e=>e!=null&&e.type==="magicframe",K=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Ie=e=>e!=null&&Lu(e.type),Lu=e=>e==="freedraw",Q=e=>e!=null&&Gu(e.type),Pt=e=>e!=null&&e.type==="line",H=e=>e!=null&&e.type==="arrow",Y=e=>H(e)&&e.elbowed,Qx=e=>H(e)&&!e.elbowed,Bu=e=>H(e)&&!e.elbowed&&!e.roundness,Cu=e=>H(e)&&!e.elbowed&&e.roundness!==null,Gu=e=>e==="arrow"||e==="line",Be=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&Ou(e.type),Ou=e=>e==="arrow",Ce=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),wr=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),li=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"),ku=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||H(e)),Jx=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 Du(t,null),!1}},yr=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",dt=e=>ku(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),ce=e=>e!==null&&"containerId"in e&&e.containerId!==null&&ee(e),ew=e=>!!e.startBinding||!!e.endBinding,Da=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",La=e=>e==="line"||e==="arrow"||e==="diamond",tw=(e,t)=>!!((e===ai.ADAPTIVE_RADIUS||e===ai.LEGACY)&&Da(t.type)||e===ai.PROPORTIONAL_RADIUS&&La(t.type)),nw=e=>La(e.type)?{type:ai.PROPORTIONAL_RADIUS}:Da(e.type)?{type:ai.ADAPTIVE_RADIUS}:null,iw=e=>Bu(e)?"sharpArrow":Cu(e)?"curvedArrow":Y(e)?"elbowArrow":"line",ow=e=>e.length>3&&Aa(e[0],e[e.length-1]),Ba=e=>e.length>3||e.length===3&&!Aa(e[0],e[e.length-1]);var di=new WeakMap,Sr=(e,t)=>{let n=di.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){di.delete(e);return}return o.get(t)},Mr=(e,t,n)=>{let i=di.get(e);if(!i){di.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){di.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function oo(e){let t=Sr(e,0);if(t)return t;let n=Fa(e),i=[],o=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&Hu(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(z(e.x+l[0],e.y+l[1]),z(e.x+a.data[0],e.y+a.data[1])));continue;case"bcurveTo":if(!l)throw new Error("prevPoint is undefined");o.push(It(z(e.x+l[0],e.y+l[1]),z(e.x+a.data[0],e.y+a.data[1]),z(e.x+a.data[2],e.y+a.data[3]),z(e.x+a.data[4],e.y+a.data[5])));continue;default:console.error("Unknown op type",a.op)}}let r=[i,o];return Mr(e,r,0),r}function Vt(e,t=0){let n=Sr(e,t);if(n)return n;let i=St(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=_u(z(e.x,e.y),z(e.x+e.width,e.y+e.height)),r=he(z(o[0][0]+i,o[0][1]),z(o[1][0]-i,o[0][1])),s=he(z(o[1][0],o[0][1]+i),z(o[1][0],o[1][1]-i)),a=he(z(o[0][0]+i,o[1][1]),z(o[1][0]-i,o[1][1])),l=he(z(o[0][0],o[1][1]-i),z(o[0][0],o[0][1]+i)),d=[It(l[1],z(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),z(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),It(r[1],z(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),z(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),It(s[1],z(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),z(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),It(a[0],z(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),z(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],c=t>0?d.map(p=>Oa(ka(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[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 Mr(e,m,t),m}function $t(e,t=0){let n=Sr(e,t);if(n)return n;let[i,o,r,s,a,l,d,c]=kn(e),u=e.roundness?St(Math.abs(i-d),e):(i-d)*.01,m=e.roundness?St(Math.abs(s-o),e):(s-o)*.01,[p,f,h,E]=[z(e.x+i,e.y+o),z(e.x+r,e.y+s),z(e.x+a,e.y+l),z(e.x+d,e.y+c)],x=[It(z(f[0]-u,f[1]-m),f,f,z(f[0]-u,f[1]+m)),It(z(h[0]+u,h[1]-m),h,h,z(h[0]-u,h[1]-m)),It(z(E[0]+u,E[1]+m),E,E,z(E[0]+u,E[1]-m)),It(z(p[0]-u,p[1]+m),p,p,z(p[0]+u,p[1]+m))].map(y=>Oa(ka(y,t))),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 Mr(e,b,t),b}var bn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return On(n,i)<=Nu/t}return!1},St=(e,t)=>{if(t.roundness?.type===Pr.PROPORTIONAL_RADIUS||t.roundness?.type===Pr.LEGACY)return e*br;if(t.roundness?.type===Pr.ADAPTIVE_RADIUS){let n=t.roundness?.value??Ru,i=n/br;return e<=i?e*br:n}return 0},Wu=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=Uu(Ra(a[1],a[0])),d=Ir(l,n);return he(Ga(a[0],d),Ga(a[1],Ir(d,-1)))},o=de(e,t),r=i(li(e)?he(Xt(z(e.x,e.y),o,e.angle),Xt(z(e.x+e.width,e.y+e.height),o,e.angle)):he(Xt(z(e.x+e.width/2,e.y),o,e.angle),Xt(z(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(li(e)?he(Xt(z(e.x+e.width,e.y),o,e.angle),Xt(z(e.x,e.y+e.height),o,e.angle)):he(Xt(z(e.x,e.y+e.height/2),o,e.angle),Xt(z(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},Ar=(e,t,n,i,o)=>{if(Fu(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;let[r,s]=Wu(n,o),a=O.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o),l=zu(Ir(Ra(t,a),2*On(a,t)+Math.max(On(r[0],r[1]),On(s[0],s[1]))),a),d=he(t,l),c=Ca(r,d),u=Ca(s,d),m=c&&On(a,c),p=u&&On(a,u),f=null;return m!=null&&p!=null?f=m<p?c:u:f=c||u||null,f&&Mt(f,n,o)?f:null};P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as dm,ARROW_LABEL_WIDTH_FRACTION as cm,BOUND_TEXT_PADDING as ct,DEFAULT_FONT_SIZE as um,TEXT_ALIGN as Ya,VERTICAL_ALIGN as ja,getFontString as uo,isProdEnv as mm,invariant as pm}from"@excalidraw/common";import{pointFrom as Xa,pointRotateRads as fm}from"@excalidraw/math";P();var ci={},Na=(e,t)=>{let n=ci[e]||(ci[e]={height:t});return n.height=t,n},Ha=e=>{ci[e]&&delete ci[e]},Ew=e=>ci[e]?.height??null;P();import{BOUND_TEXT_PADDING as so,DEFAULT_FONT_SIZE as Yu,DEFAULT_FONT_FAMILY as ju,getFontString as Xu,isTestEnv as Vu,normalizeEOL as $u}from"@excalidraw/common";var _e=(e,t,n)=>{let i=e.split(`
|
|
2
2
|
`).map(a=>a||" ").join(`
|
|
3
|
-
`),
|
|
4
|
-
`),e,t).width+
|
|
5
|
-
`),
|
|
6
|
-
`);for(let r of
|
|
7
|
-
`)},
|
|
3
|
+
`),o=parseFloat(t),r=Zu(i,o,n);return{width:Wa(i,t),height:r}},za="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),_a=(e,t)=>{let n=qu(e);return n===0?_e(za.split("").join(`
|
|
4
|
+
`),e,t).width+so*2:n+so*2},ao=(e,t)=>_e("",e,t).width+so*2,yw=()=>Wa(za,Xu({fontSize:Yu,fontFamily:ju}))>0,ui=e=>$u(e).replace(/\t/g," "),vr=e=>ui(e).split(`
|
|
5
|
+
`),bw=e=>{let t=vr(e.text).length;return e.height/t/e.fontSize},lo=(e,t)=>e*t,Ua=(e,t)=>lo(e,t)+so*2,ro,Pw=e=>{ro=e},Tr=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 Vu()?r*10:r}},Zt=(e,t)=>(ro||(ro=new Tr),ro.getLineWidth(e,t)),Wa=(e,t)=>{let n=vr(e),i=0;return n.forEach(o=>{i=Math.max(i,Zt(o,t))}),i},Zu=(e,t,n)=>{let i=vr(e).length;return lo(t,n)*i},Rn=(()=>{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]=[]}}})(),Iw=e=>{let t=Rn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},qu=e=>{let t=Rn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as Ku,isTestEnv as Qu}from"@excalidraw/common";var Dr,co,Lr,vw=e=>(Dr||(Dr=te.class(...Object.values(At))),Dr.test(e)),Ju=()=>{if(!co)try{co=tm()}catch{co=em()}return co},Br=()=>(Lr||(Lr=nm()),Lr),Ze={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},At={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},Pn={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},em=()=>te.or(Br(),ue.On(Ze.HYPHEN,Ze.WHITESPACE,At.CHAR)),tm=()=>te.or(Br(),ue.Before(Ze.WHITESPACE).Build(),ue.After(Ze.WHITESPACE,Ze.HYPHEN).Build(),ue.Before(At.CHAR,At.CURRENCY).NotPrecededBy(Ze.OPENING,At.OPENING).Build(),ue.After(At.CHAR).NotFollowedBy(Ze.HYPHEN,Ze.CLOSING,At.CLOSING).Build(),ue.BeforeMany(At.OPENING).NotPrecededBy(Ze.OPENING).Build(),ue.AfterMany(At.CLOSING).NotFollowedBy(Ze.CLOSING).Build(),ue.AfterMany(Ze.CLOSING).FollowedBy(Ze.OPENING).Build()),nm=()=>te.group(te.or(Pn.FLAG,te.and(Pn.MOST,Pn.JOINER,te.build(`(?:${Pn.ZWJ.source}(?:${Pn.FLAG.source}|${Pn.ANY.source}${Pn.JOINER.source}))*`)))),te={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>te.build(te.join(...e)),or:(...e)=>te.build(e.map(t=>t.source).join("|")),group:(...e)=>te.build(`(${te.join(...e)})`),class:(...e)=>te.build(`[${te.join(...e)}]`)},ue={On:(...e)=>{let t=te.join(...e);return te.build(`([${t}])`)},Before:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?=[${t}])`);return ue.Chain(n)},After:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<=[${t}])`);return ue.Chain(n)},BeforeMany:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<![${t}])(?=[${t}])`);return ue.Chain(n)},AfterMany:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<=[${t}])(?![${t}])`);return ue.Chain(n)},NotBefore:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?![${t}])`);return ue.Chain(n)},NotAfter:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<![${t}])`);return ue.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=ue.After(...t).Build(),o=()=>te.and(i,n);return ue.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=ue.Before(...t).Build(),o=()=>te.and(n,i);return ue.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=ue.NotAfter(...t).Build(),o=()=>te.and(i,n);return ue.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=ue.NotBefore(...t).Build(),o=()=>te.and(n,i);return ue.Chain(o)}})},im=e=>{let t=Ju();return e.normalize("NFC").split(t).filter(Boolean)},Tt=(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=om(r,t,n);i.push(...a)}return i.join(`
|
|
7
|
+
`)},om=(e,t,n)=>{let i=[],r=im(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let d=l.value,c=s+d,u=am(d)?a+Rn.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 m=rm(d,t,n),p=m[m.length-1]??"",f=m.slice(0,-1);i.push(...f),s=p,a=Zt(p,t),l=r.next()}}if(s){let d=sm(s,t,n);i.push(d)}return i},rm=(e,t,n)=>{if(Br().test(e))return[e];lm(e);let i=[],o=Array.from(e),r="",s=0;for(let a of o){let l=Rn.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},sm=(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=Rn.calculate(a,t),d=s+l;if(d>n)break;o=o+a,s=d}return o},am=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,lm=e=>{if((Qu()||Ku())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var mo=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;mm()||pm(!t||!H(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?H(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?nt(t,e):e.width,r.text=Tt(e.originalText,uo(e),o));let s=_e(r.text,uo(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=pi(t,e),l=nt(t,e);if(!H(t)&&s.height>a){let m=Cr(s.height,t.type);n.mutateElement(t,{height:m}),Na(t.id,m)}if(s.width>l){let m=Cr(s.width,t.type);n.mutateElement(t,{width:m})}let d={...e,...r},{x:c,y:u}=mi(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},In=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!vt(e))return;Ha(e.id);let s=V(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=nt(e,s),u=pi(e,s),m=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=Tt(s.originalText,uo(s),c));let p=_e(a,uo(s),s.lineHeight);l=p.height,d=p.width}if(l>u){m=Cr(l,e.type);let p=m-e.height,f=!H(e)&&(n==="ne"||n==="nw"||n==="n")?e.y-p:e.y;t.mutateElement(e,{height:m,y:f})}t.mutateElement(s,{text:a,width:d,height:l}),H(e)||t.mutateElement(s,mi(e,s,o))}},mi=(e,t,n)=>{if(H(e))return O.getBoundTextElementPosition(e,t,n);let i=Gr(e),o=pi(e,t),r=nt(e,t),s,a;t.verticalAlign===ja.TOP?a=i.y:t.verticalAlign===ja.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===Ya.LEFT?s=i.x:t.textAlign===Ya.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=Xa(i.x+r/2,i.y+o/2),c=Xa(s+t.width/2,a+t.height/2),[u,m]=fm(c,d,l);return{x:u-t.width/2,y:m-t.height/2}}return{x:s,y:a}},vt=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,V=(e,t)=>{if(!e)return null;let n=vt(e);return n&&t.get(n)||null},Se=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,Nw=(e,t,n)=>{if(!H(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(O.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=O.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=O.getEditorMidPoints(e,n,t)[o];return r||(r=O.getSegmentMidPoint(e,o+1)),{x:r[0],y:r[1]}},Gr=e=>{let t=ct,n=ct;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}},Hw=(e,t)=>H(t)?0:t?t.angle:e.angle,zw=(e,t,n)=>{if(H(e))return O.getBoundTextElementPosition(e,t,n)},_w=(e,t)=>e.some(n=>{if(ce(n)){let i=Se(n,t);return!H(i)}return!1}),Uw=(e,t)=>e.some(n=>{if(ce(n)){let i=Se(n,t);return!H(i)}return ee(n)}),hm=new Set(["rectangle","ellipse","diamond","arrow"]),Ww=e=>hm.has(e.type),Cr=(e,t)=>{e=Math.ceil(e);let n=ct*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},nt=(e,t)=>{let{width:n}=e;if(H(e)){let i=(t?.fontSize??um)*dm;return Math.max(cm*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-ct*2:e.type==="diamond"?Math.round(n/2)-ct*2:n-ct*2},pi=(e,t)=>{let{height:n}=e;return H(e)?n-ct*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-ct*2:e.type==="diamond"?Math.round(n/2)-ct*2:n-ct*2},Yw=(e,t=`
|
|
8
8
|
|
|
9
|
-
`)=>e.reduce((o,i)=>(oe(i)&&o.push(i.text),o),[]).join(t);P();import{curvePointDistance as lr,distanceToLineSegment as cr,pointRotateRads as dr}from"@excalidraw/math";import{ellipse as Nu,ellipseDistanceFromPoint as zu}from"@excalidraw/math/ellipse";var _t=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return Hu(e,t,n);case"diamond":return _u(e,t,n);case"ellipse":return Yu(e,t,n);case"line":case"arrow":case"freedraw":return Uu(e,n)}},Hu=(e,t,n)=>{let o=fe(e,t),i=dr(n,o,-e.angle),[r,s]=yn(e);return Math.min(...r.map(a=>cr(i,a)),...s.map(a=>lr(a,i)).filter(a=>a!==null))},_u=(e,t,n)=>{let o=fe(e,t),i=dr(n,o,-e.angle),[r,s]=bn(e);return Math.min(...r.map(a=>cr(i,a)),...s.map(a=>lr(a,i)).filter(a=>a!==null))},Yu=(e,t,n)=>{let o=fe(e,t);return zu(dr(n,o,-e.angle),Nu(o,e.width/2,e.height/2))},Uu=(e,t)=>{let[n,o]=Bo(e);return Math.min(...n.map(i=>cr(t,i)),...o.map(i=>lr(i,t)))};var Wo=e=>{if(e.type==="arrow")return!1;let t=!Xu(e.backgroundColor)||st(e)||Ro(e)||oe(e);return e.type==="line"?t&&ln(e.points):e.type==="freedraw"?t&&ln(e.points):t||xe(e)},Qu=({point:e,element:t,threshold:n,elementsMap:o,frameNameBound:i=null})=>{let r=i?Uo(St(i.x-n,i.y-n),e,St(i.x+i.width+n,i.y+i.height+n)):!1,s=he(t,o,!0);return!Uo(St(s[0]-n,s[1]-n),lt(e,ct(s),-t.angle),St(s[2]+n,s[3]+n))&&!r?!1:Wo(t)&&Sa(e,t,o)||wa(e,t,o,n)||r},Ju=(e,t,n,o=0)=>{let[i,r,s,a]=he(t,n);return i-=o,r-=o,s+=o,a+=o,Uo(St(i,r),e,St(s,a))},Tw=(e,t)=>!Qu(e)&&!ep(e.point,e.element,t)&&Ju(e.point,e.element,t),ep=(e,t,n)=>{let o=W(t,n);if(!o)return!1;let i=X(t)?{...o,...Y.getBoundTextElementPosition(t,o,n)}:o;return Sa(e,i,n)},In=(e,t,n,o=0,i=!1)=>{let r=[Math.min(n[0][0]-o,n[1][0]-o),Math.min(n[0][1]-o,n[1][1]-o),Math.max(n[0][0]+o,n[1][0]+o),Math.max(n[0][1]+o,n[1][1]+o)],s=he(e,t);if(!pn(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return np(e,t,n,o,i);case"diamond":return op(e,t,n,o,i);case"ellipse":return ip(e,t,n,o);case"line":case"freedraw":case"arrow":return tp(e,n,i)}},Pa=(e,t,n,o,i,r=!1)=>{for(let s of e){let a=jo(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(!pn(a,l))continue;let c=ya(s,t);if(c.length>0){for(let d of c)n.push(lt(d,o,i));if(r)return n}}return n},Ia=(e,t,n,o,i,r=!1)=>{for(let s of e){let a=ba(s,t);if(a&&(n.push(lt(a,o,i)),r))return n}return n},tp=(e,t,n=!1)=>{let[o,i]=Bo(e),r=[];for(let s of o){let a=ba(s,t);if(a&&(r.push(a),n))return r}for(let s of i){let a=jo(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(!pn(a,l))continue;let c=ya(s,t);if(c.length>0&&(r.push(...c),n))return r}return r},np=(e,t,n,o=0,i=!1)=>{let r=fe(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Xo(s,a),[c,d]=yn(e,o),u=[];return Ia(c,l,u,r,e.angle,i),i&&u.length>0||Pa(d,l,u,r,e.angle,i),u},op=(e,t,n,o=0,i=!1)=>{let r=fe(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Xo(s,a),[c,d]=bn(e,o),u=[];return Ia(c,l,u,r,e.angle,i),i&&u.length>0||Pa(d,l,u,r,e.angle,i),u},ip=(e,t,n,o=0)=>{let i=fe(e,t),r=lt(n[0],i,-e.angle),s=lt(n[1],i,-e.angle);return Ku(qu(i,e.width/2+o,e.height/2+o),Xo(r,s)).map(a=>lt(a,i,e.angle))},wa=(e,t,n,o=1)=>_t(t,n,e)<=o,Sa=(e,t,n)=>{if((X(t)||Se(t))&&!ln(t.points))return!1;let[o,i,r,s]=he(t,n);if(!Uo(St(o,i),e,St(r,s)))return!1;let a=St((o+r)/2,(i+s)/2),l=Wu(Zu($u(Vu(e,a,.1)),Math.max(t.width,t.height)*2),a),c=Xo(e,l);return In(t,n,c).filter((u,p,m)=>m.findIndex(f=>ju(f,u))===p).length%2===1};P();import{invariant as Ma,isDevEnv as rp,isTestEnv as sp}from"@excalidraw/common";import{pointFrom as Yt,pointFromVector as Vo,pointRotateRads as $o,pointScaleFromOrigin as Zo,pointsEqual as ap,triangleIncludesPoint as ur,vectorCross as Be,vectorFromPoint as K,vectorScale as qo}from"@excalidraw/math";var me=[1,0],we=[0,1],Oe=[-1,0],He=[0,-1],Mt=e=>{let[t,n]=e,o=Math.abs(t),i=Math.abs(n);return t>i?me:t<=-i?Oe:n>o?we:He},Ge=(e,t)=>Mt(K(e,t)),et=(e,t)=>Re(Ge(e,t)),pe=(e,t)=>e[0]===t[0]&&e[1]===t[1],Re=e=>pe(e,me)||pe(e,Oe),Bw=e=>!Re(e),lp=(e,t,n)=>{let o=ct(t);(rp()||sp())&&(Ma(e.width>0&&e.height>0,"Diamond element has no width or height"),Ma(!ap(o,n),"The point is too close to the element mid point to determine heading"));let i=.95,r=Vo(qo(K($o(Yt(e.x+e.width/2,e.y),o,e.angle),o),i),o),s=Vo(qo(K($o(Yt(e.x+e.width,e.y+e.height/2),o,e.angle),o),i),o),a=Vo(qo(K($o(Yt(e.x+e.width/2,e.y+e.height),o,e.angle),o),i),o),l=Vo(qo(K($o(Yt(e.x,e.y+e.height/2),o,e.angle),o),i),o);if(Be(K(n,r),K(r,s))<=0&&Be(K(n,r),K(r,l))>0)return Ge(r,o);if(Be(K(n,s),K(s,a))<=0&&Be(K(n,s),K(s,r))>0)return Ge(s,o);if(Be(K(n,a),K(a,l))<=0&&Be(K(n,a),K(a,s))>0)return Ge(a,o);if(Be(K(n,l),K(l,r))<=0&&Be(K(n,l),K(l,a))>0)return Ge(l,o);if(Be(K(n,o),K(r,o))<=0&&Be(K(n,o),K(s,o))>0){let d=e.width>e.height?r:s;return Ge(d,o)}else if(Be(K(n,o),K(s,o))<=0&&Be(K(n,o),K(a,o))>0){let d=e.width>e.height?a:s;return Ge(d,o)}else if(Be(K(n,o),K(a,o))<=0&&Be(K(n,o),K(l,o))>0){let d=e.width>e.height?a:l;return Ge(d,o)}let c=e.width>e.height?r:l;return Ge(c,o)},to=(e,t,n)=>{let i=ct(t);if(e.type==="diamond")return lp(e,t,n);let r=Zo(Yt(t[0],t[1]),i,2),s=Zo(Yt(t[2],t[1]),i,2),a=Zo(Yt(t[0],t[3]),i,2),l=Zo(Yt(t[2],t[3]),i,2);return ur([r,s,i],n)?He:ur([s,l,i],n)?me:ur([l,a,i],n)?we:Oe},pr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Ap,randomInteger as Ir,getUpdatedTimestamp as Sr}from"@excalidraw/common";P();import{clamp as Ko,pointDistance as hr,pointFrom as z,pointScaleFromOrigin as cp,pointsEqual as oo,pointTranslate as fr,vector as dt,vectorCross as Qo,vectorFromPoint as Er,vectorScale as dp}from"@excalidraw/math";import{BinaryHeap as up,invariant as Sn,isAnyTrue as pp,tupleToCoors as mp,getSizeFromPoints as Ta,isDevEnv as fp,arrayToMap as hp}from"@excalidraw/common";var gr=1,ee=40,Ep=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let o=[];e.points.map(s=>z(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return o.push(s);let c=Ge(s,l[a-1]),d=Ge(l[a-1],l[a-2]);if(pe(c,d)){let u=n?.findIndex(m=>m.index===a-1)??-1,p=n?.findIndex(m=>m.index===a)??-1;p!==-1&&(n[p].start=z(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),o.splice(-1,1),n.forEach(m=>{m.index>a-1&&(m.index-=1)})}return o.push(s)});let i=[];o.forEach((s,a,l)=>{if(a<3)return i.push(s);if(hr(l[a-2],l[a-1])<gr){let c=n?.findIndex(p=>p.index===a-2)??-1,d=n?.findIndex(p=>p.index===a-1)??-1;d!==-1&&n.splice(d,1),c!==-1&&n.splice(c,1),i.splice(-2,2),n.forEach(p=>{p.index>a-2&&(p.index-=2)});let u=et(s,l[a-1]);return i.push(z(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}i.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==i.length-1);return r.length===0?Tt(yr(br(wr(e,xr(e,t,i.map(s=>z(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(fp()&&Sn(Ga(i),"Invalid elbow points with fixed segments"),Tt(i,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},gp=(e,t,n)=>{let o=t.map(T=>T.index),r=(e.fixedSegments?.map(T=>T.index)??[]).findIndex(T=>!o.includes(T));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],c=e.x+(a?a.end[0]:0),d=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,p=l?null:e.endBinding,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y}=xr({x:c,y:d,startBinding:u,endBinding:p,startArrowhead:null,endArrowhead:null,points:e.points},n,[z(0,0),z(e.x+(l?.start[0]??e.points[e.points.length-1][0])-c,e.y+(l?.start[1]??e.points[e.points.length-1][1])-d)],{isDragging:!1}),{points:b}=Tt(yr(br(wr(e,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y})??[])),t,null,null),w=[];if(a)for(let T=0;T<a.index;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));if(b.forEach(T=>{w.push(z(e.x+(a?a.end[0]:0)+T[0],e.y+(a?a.end[1]:0)+T[1]))}),l)for(let T=l.index;T<e.points.length;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,M=t.map(T=>T.index>s?{...T,index:T.index-I+(b.length-1)}:T),D=w.flatMap((T,F)=>{let C=w[F-1],k=w[F+1];if(C&&k){let L=Ge(T,C),j=Ge(k,T);if(pe(L,j))return M.forEach(N=>{N.index>F&&(N.index-=1)}),[];if(pe(L,pr(j)))return M.forEach(N=>{N.index>F&&(N.index+=1)}),[T,T]}return[T]});return Tt(D,M,!1,!1)},xp=(e,t,n,o,i,r)=>{let s=t.map((w,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==w.index||(w.start[0]!==e.fixedSegments[I].start[0]&&w.end[0]!==e.fixedSegments[I].end[0])!=(w.start[1]!==e.fixedSegments[I].start[1]&&w.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,c=hr(t[s].start,t[s].end),d=c<ee+5;if(a===-1&&t[s].index===1&&i){let w=Re(n),M=(w?pe(n,me):pe(n,we))?d?c/2:ee:d?-c/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=Re(o),M=(w?pe(o,me):pe(o,we))?d?c/2:ee:d?-c/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]&&!oo(p[m],p[m-1])?et(p[m-1],p[m]):void 0,x=p[f+1]&&!oo(p[f],p[f+1])?et(p[f+1],p[f]):void 0;if(g!==void 0){let w=g?1:0;p[m-1][w]=E[w]}if(p[m]=E,p[f]=h,x!==void 0){let w=x?1:0;p[f+1][w]=h[w]}let y=u.findIndex(w=>w.index===m);if(y!==-1){let w=et(u[y].end,u[y].start)?1:0;u[y].start[w]=E[w],u[y].end=E}let b=u.findIndex(w=>w.index===f+1);if(b!==-1){let w=et(u[b].end,u[b].start)?1:0;u[b].end[w]=h[w],u[b].start=h}if(a===-1&&m===0){let w=i?Re(n):et(p[1],p[0]);p.unshift(z(w?E[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:E[1])),i&&p.unshift(z(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=i?2:1}if(l===-1&&f===e.points.length-1){let w=Re(o);p.push(z(w?h[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:h[1])),r&&p.push(z(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return Tt(p,u.map(w=>({...w,start:z(w.start[0]-e.x,w.start[1]-e.y),end:z(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},wp=(e,t,n,o,i,r,s,a,l)=>{let c=e.startIsSpecial??null,d=e.endIsSpecial??null,u=t.map((h,g)=>g===0?z(e.x+h[0],e.y+h[1]):g===t.length-1?z(e.x+h[0],e.y+h[1]):z(e.x+e.points[g][0],e.y+e.points[g][1])),p=n.map(h=>({...h,start:z(e.x+(h.start[0]-t[0][0]),e.y+(h.start[1]-t[0][1])),end:z(e.x+(h.end[0]-t[0][0]),e.y+(h.end[1]-t[0][1]))})),m=[],f=2+(c?1:0),E=2+(d?1:0);for(;m.length+f<u.length-E;)m.push(u[m.length+f]);{let h=u[c?2:1],g=u[c?3:2],x=Re(o),y=Re(Mt(Er(h,g)));if(a&&x===y){let b=x?pe(o,me):pe(o,we);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))),!c){c=!0;for(let w of p)w.index>1&&(w.index+=1)}}else if(m.unshift(z(y?r[0]:h[0],y?h[1]:r[1])),c){c=!1;for(let b of p)b.index>1&&(b.index-=1)}m.unshift(r)}{let h=u[u.length-(d?3:2)],g=u[u.length-(d?4:3)],x=Re(i),y=et(g,h);if(l&&x===y){let b=x?pe(i,me):pe(i,we);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))),d||(d=!0)}else m.push(z(y?s[0]:h[0],y?h[1]:s[1])),d&&(d=!1)}return m.push(s),Tt(m,p.map(({index:h})=>({index:h,start:m[h-1],end:m[h]})).map(h=>({...h,start:z(h.start[0]-r[0],h.start[1]-r[1]),end:z(h.end[0]-r[0],h.end[1]-r[1])})),c,d)},Ut=1e6,Tn=(e,t,n,o)=>{if(e.points.length<2)return{points:n.points??e.points};A.PROD||(Sn(!n.points||n.points.length>=2,"Updated point array length must match the arrow point length, contain exactly the new start and end points or not be specified at all (i.e. you can't add new points between start and end manually to elbow arrows)"),Sn(!e.fixedSegments||e.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Sn(!n.fixedSegments||n.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Sn(e.points.slice(1).map((w,I)=>w[0]===e.points[I][0]||w[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Sn(n.fixedSegments?.find(w=>w.index===1&&oo(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&oo(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let i=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,c=typeof s<"u"?s:e.startBinding,d=typeof a<"u"?a:e.endBinding,u=c&&ei(c.elementId,t),p=d&&ei(d.elementId,t),m=Ga(r);if(c&&!u&&m||d&&!p&&m||t.size===0&&m||Object.keys(l).length===0&&(u?.id!==c?.elementId||p?.id!==d?.elementId))return Tt(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b}=xr({x:e.x,y:e.y,startBinding:c,endBinding:d,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,o);return t.size===0&&m?Tt(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?Ep(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,I)=>oo(w,e.points[I]??z(1/0,1/0)))&&m?{}:i.length===0?Tt(yr(br(wr(e,{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b})??[])),i,null,null):(e.fixedSegments?.length??0)>i.length?gp(e,i,t):n.points?n.points&&n.fixedSegments?n:wp(e,r,i,f,E,h,g,x,y):xp(e,i,f,E,x,y)},xr=(e,t,n,o)=>{let i=fr(n[0],dt(e.x,e.y)),r=fr(n[n.length-1],dt(e.x,e.y)),s=null,a=null;if(o?.isDragging){let w=Array.from(t.values());s=La(i,t,w,o?.zoom)||null,a=La(r,t,w,o?.zoom)||null}else s=e.startBinding&&ei(e.startBinding.elementId,t)||null,a=e.endBinding&&ei(e.endBinding.elementId,t)||null;let l=Da({...e,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,i,s,t,o?.isDragging),c=Da({...e,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,o?.isDragging),d=va(l,c,s,i,t),u=va(c,l,a,r,t),p=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],m=[c[0]-2,c[1]-2,c[0]+2,c[1]+2],f=s?Ve(s,t,Xt(d,e.startArrowhead?ie*6:ie*2,1)):p,E=a?Ve(a,t,Xt(u,e.endArrowhead?ie*6:ie*2,1)):m,h=Mn(l,a?Ve(a,t,Xt(u,ee,ee)):m)||Mn(c,s?Ve(s,t,Xt(d,ee,ee)):p),g=Ba(h?[p,m]:[f,E]),x=Pp(h?p:f,h?m:E,g,h?Xt(d,!s&&!a?0:ee,0):Xt(d,!s&&!a?0:ee-(e.startArrowhead?ie*6:ie*2),ee),h?Xt(u,!s&&!a?0:ee,0):Xt(u,!s&&!a?0:ee-(e.endArrowhead?ie*6:ie*2),ee),h,s&&Ve(s,t),a&&Ve(a,t)),y=Aa(x[0],d,l),b=Aa(x[1],u,c);return{dynamicAABBs:x,startDonglePosition:y,startGlobalPoint:l,startHeading:d,endDonglePosition:b,endGlobalPoint:c,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:h,startElementBounds:f,endElementBounds:E}},wr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:o,startGlobalPoint:i,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:c,hoveredEndElement:d}=t,u=Ip(n,o||i,r,s||a,l,c),p=o&&Jo(o,u),m=s&&Jo(s,u),f=Jo(a,u);f&&d&&(f.closed=!0);let E=Jo(i,u);E&&e.startBinding&&(E.closed=!0);let h=p&&m&&(Mn(p.pos,n[1])||Mn(m.pos,n[0])),g=yp(p||E,m||f,u,r||me,l||me,h?[]:n);if(g){let x=g.map(y=>[y.pos[0],y.pos[1]]);return p&&x.unshift(i),m&&x.push(a),x}return null},Xt=(e,t,n)=>{switch(e){case He:return[t,n,n,n];case me:return[n,t,n,n];case we:return[n,n,t,n]}return[n,n,n,t]},yp=(e,t,n,o,i,r)=>{let s=mr(e.pos,t.pos),a=new up(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return bp(e,l);l.closed=!0;let c=Mp(l.addr,n);for(let d=0;d<4;d++){let u=c[d];if(!u||u.closed)continue;let p=cp(u.pos,l.pos,.5);if(pp(...r.map(b=>Mn(p,b))))continue;let m=Tp(d),f=l.parent?Mt(Er(l.pos,l.parent.pos)):o,E=pr(f);if(pe(E,m)||Ca(e.addr,u.addr)&&pe(m,o)||Ca(t.addr,u.addr)&&pe(m,i))continue;let g=f!==m,x=l.g+mr(u.pos,l.pos)+(g?Math.pow(s,3):0),y=u.visited;if(!y||x<u.g){let b=Sp(u,t,m,i);u.visited=!0,u.parent=l,u.h=mr(t.pos,u.pos)+b*Math.pow(s,2),u.g=x,u.f=u.g+u.h,y?a.rescoreElement(u):a.push(u)}}}return null},bp=(e,t)=>{let n=t,o=[];for(;n.parent;)o.unshift(n),n=n.parent;return o.unshift(e),o},mr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Pp=(e,t,n,o,i,r,s,a)=>{let l=s??e,c=a??t,[d,u,p,m]=o??[0,0,0,0],[f,E,h,g]=i??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+c[2])/2,e[0]-m):(l[0]+c[2])/2:e[0]>t[0]?e[0]-m:n[0]-m,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+c[3])/2,e[1]-d):(l[1]+c[3])/2:e[1]>t[1]?e[1]-d:n[1]-d,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+c[0])/2,e[2]+u):(l[2]+c[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+c[1])/2,e[3]+p):(l[3]+c[1])/2:e[3]<t[3]?e[3]+p:n[3]+p],y=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((c[0]+l[2])/2,t[0]-g):(c[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((c[1]+l[3])/2,t[1]-f):(c[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((c[2]+l[0])/2,t[2]+E):(c[2]+l[0])/2:t[2]<e[2]?t[2]+E:n[2]+E,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((c[3]+l[1])/2,t[3]+h):(c[3]+l[1])/2:t[3]<e[3]?t[3]+h:n[3]+h],b=Ba([x,y]);if(!r&&x[2]-x[0]+y[2]-y[0]>b[2]-b[0]+1e-11&&x[3]-x[1]+y[3]-y[1]>b[3]-b[1]+1e-11){let[w,I]=[(y[0]+y[2])/2,(y[1]+y[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let M=x[2]+(y[0]-x[2])/2,D=y[3]+(x[1]-y[3])/2;return Qo(dt(e[2]-w,e[1]-I),dt(e[0]-w,e[3]-I))>0?[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]:[[x[0],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 Qo(dt(e[0]-w,e[1]-I),dt(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 Qo(dt(e[2]-w,e[1]-I),dt(e[0]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],x[1],x[2],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 Qo(dt(e[0]-w,e[1]-I),dt(e[2]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}}return[x,y]},Ip=(e,t,n,o,i,r)=>{let s=new Set,a=new Set;n===Oe||n===me?a.add(t[1]):s.add(t[0]),i===Oe||i===me?a.add(o[1]):s.add(o[0]),e.forEach(d=>{s.add(d[0]),s.add(d[2]),a.add(d[1]),a.add(d[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((d,u)=>d-u),c=Array.from(s).sort((d,u)=>d-u);return{row:l.length,col:c.length,data:l.flatMap((d,u)=>c.map((p,m)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[m,u],pos:[p,d]})))}},Aa=(e,t,n)=>{switch(t){case He:return z(n[0],e[1]);case me:return z(e[2],n[1]);case we:return z(n[0],e[3])}return z(e[0],n[1])},Sp=(e,t,n,o)=>{if(o===me)switch(n){case me:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case He:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Oe:return e.pos[1]===t.pos[1]?4:2}else if(o===Oe)switch(n){case me:return e.pos[1]===t.pos[1]?4:2;case He:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Oe:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(o===He)switch(n){case me:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case we:return e.pos[0]===t.pos[0]?4:2;case Oe:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(o===we)switch(n){case me:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He:return e.pos[0]===t.pos[0]?4:2;case we:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Oe:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Mp=([e,t],n)=>[no([e,t-1],n),no([e+1,t],n),no([e,t+1],n),no([e-1,t],n)],no=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Jo=(e,t)=>{for(let n=0;n<t.col;n++)for(let o=0;o<t.row;o++){let i=no([n,o],t);if(i&&e[0]===i.pos[0]&&e[1]===i.pos[1])return i}return null},Ba=e=>[Math.min(...e.map(t=>t[0])),Math.min(...e.map(t=>t[1])),Math.max(...e.map(t=>t[2])),Math.max(...e.map(t=>t[3]))],ei=(e,t)=>{let n=t.get(e);return n&&Le(n)?n:null},Tt=(e,t,n,o)=>{let i=e[0][0],r=e[0][1],s=e.map(a=>fr(a,dp(Er(e[0]),-1)));return(i<-Ut||i>Ut||r<-Ut||r>Ut||i+s[s.length-1][0]<-Ut||r+s[s.length-1][0]>Ut||i+s[s.length-1][1]<-Ut||r+s[s.length-1][1]>Ut)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:i,y:r,points:s,...Ta(s)}),s=s.map(([a,l])=>z(Ko(a,-1e6,1e6),Ko(l,-1e6,1e6))),{points:s,x:Ko(i,-1e6,1e6),y:Ko(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Ta(s),startIsSpecial:n,endIsSpecial:o}},yr=e=>{if(e.length>1){let t=Math.abs(e[0][1]-e[1][1])<Math.abs(e[0][0]-e[1][0]);return e.filter((n,o)=>{if(o===0||o===e.length-1)return!0;let i=e[o+1],r=Math.abs(n[1]-i[1])<Math.abs(n[0]-i[0]);return t===r?(t=r,!1):(t=r,!0)})}return e},br=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let o=e[n-1];return hr(o,t)>gr}):e,Tp=e=>{switch(e){case 0:return He;case 1:return me;case 2:return we}return Oe},Da=(e,t,n,o,i,r,s)=>s?i&&r?Pr(e,i,t,r):o:i?ti(n||[0,0],i,r??hp([i])):o,va=(e,t,n,o,i)=>Oa(e,t,n,n&&Ve(n,i,Array(4).fill(_t(n,i,e))),o,i),La=(e,t,n,o)=>Wt(mp(e),n,t,o,!0,!0),Ca=(e,t)=>e[0]===t[0]&&e[1]===t[1],Ga=(e,t=gr)=>e.slice(1).map((n,o)=>Math.abs(n[0]-e[o][0])<t||Math.abs(n[1]-e[o][1])<t).every(Boolean);var ye=(e,t,n,o)=>{let i=!1,{points:r,fixedSegments:s,startBinding:a,endBinding:l,fileId:c}=n;G(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u"||typeof a<"u"||typeof l<"u")?n={...n,angle:0,...Tn({...e,x:n.x||e.x,y:n.y||e.y},t,n,o)}:typeof r<"u"&&(n={...Ap(r),...n});for(let d in n){let u=n[d];if(typeof u<"u"){if(e[d]===u&&(typeof u!="object"||u===null||d==="groupIds"||d==="scale"))continue;if(d==="scale"){let p=e[d],m=u;if(p[0]===m[0]&&p[1]===m[1])continue}else if(d==="points"){let p=e[d],m=u;if(p.length===m.length){let f=!1,E=p.length;for(;--E;){let h=p[E],g=m[E];if(h[0]!==g[0]||h[1]!==g[1]){f=!0;break}}if(!f)continue}}e[d]=u,i=!0}}return i&&((typeof n.height<"u"||typeof n.width<"u"||typeof c<"u"||typeof r<"u")&&be.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Ir(),e.updated=Sr()),e},Me=(e,t,n=!1)=>{let o=!1;for(let i in t){let r=t[i];if(typeof r<"u"){if(e[i]===r&&(typeof r!="object"||r===null))continue;o=!0}}return!o&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Ir(),updated:Sr()}},Ra=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Ir(),e.updated=Sr(),e);var ly=e=>!e[Dp.CTRL_OR_CMD],Mr=e=>e.isBindingEnabled,ie=5,Rp=10,kp=(e,t)=>{let n=[];return t.forEach(o=>{let i=e.getNonDeletedElement(o);i!=null&&n.push(i)}),n},Tr=(e,t,n,o)=>{let i=o.getNonDeletedElementsMap(),r=new Set,s=new Set;Na(e,t,n,"start",r,s,o,i),Na(e,n,t,"end",r,s,o,i);let a=Array.from(s).filter(l=>!r.has(l));kp(o,a).forEach(l=>{o.mutateElement(l,{boundElements:l.boundElements?.filter(c=>c.type!=="arrow"||c.id!==e.id)})})},Na=(e,t,n,o,i,r,s,a)=>{if(t!=="keep"){if(t===null){let l=_p(e,o,s);l!=null&&r.add(l);return}Wa(e)?(n==null||(n==="keep"?!Ua(e,t,o):o==="start"||n.id!==t.id))&&(mn(e,t,o,s),i.add(t.id)):(mn(e,t,o,s),i.add(t.id))}},_a=(e,t,n)=>["start","end"].map(o=>{let i=Va(e,o,t),r=o==="start"?e.startBinding?.elementId:e.endBinding?.elementId;if(r){let s=t.get(r);if(Le(s)&&oi(s,i,t,n))return s}return null}),Fp=(e,t,n,o,i,r)=>{let a=e.points.length-1,l=n.findIndex(p=>p===0)>-1,c=n.findIndex(p=>p===a)>-1,d=l?t?ii(e,"start",o,i,r):null:"keep",u=c?t?ii(e,"end",o,i,r):null:"keep";return[d,u]},Np=(e,t,n,o,i)=>{if(G(e))return["keep","keep"];let[r,s]=_a(e,t,i),a=r&&o?ii(e,"start",t,n,i):null,l=s&&o?ii(e,"end",t,n,i):null;return[a,l]},zp=(e,t,n,o,i)=>{e.forEach(r=>{let[s,a]=n?.length?Fp(r,t,n??[],o.getNonDeletedElementsMap(),o.getNonDeletedElements(),i):Np(r,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),t,i);Tr(r,s,a,o)})},cy=(e,t,n)=>e.length>50?[]:e.filter(X).flatMap(o=>_a(o,t,n)).filter(o=>o!==null).filter(o=>e.filter(i=>i.id===o?.id).length===0),Ya=(e,t,n,o,i)=>Array.from(t.reduce((r,s)=>{let a=Wt(s,n.getNonDeletedElements(),n.getNonDeletedElementsMap(),o,G(e),G(e));return a!=null&&!Xa(e,i?.id,a)&&r.add(a),r},new Set)),dy=(e,t,n,o)=>{let i=o.getNonDeletedElements(),r=o.getNonDeletedElementsMap();t.startBoundElement!=null&&mn(e,t.startBoundElement,"start",o);let s=Wt(n,i,r,t.zoom,G(e),G(e));s!==null&&(Ua(e,s,"end")||mn(e,s,"end",o))},Hp=(e,t)=>({...e,gap:Math.min(e.gap,ai(t,t.width,t.height))}),mn=(e,t,n,o)=>{if(!_(e))return;let i={elementId:t.id,...Hp(Xp(e,t,n,o.getNonDeletedElementsMap()),t)};G(e)&&(i={...i,...ja(e,t,n,o.getNonDeletedElementsMap())}),o.mutateElement(e,{[n==="start"?"startBinding":"endBinding"]:i}),Ha(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Ua=(e,t,n)=>{let o=e[n==="start"?"endBinding":"startBinding"];return Xa(e,o?.elementId,t)},Xa=(e,t,n)=>t===n.id&&Wa(e),Wa=e=>e.points.length<3&&!G(e),_p=(e,t,n)=>{let o=t==="start"?"startBinding":"endBinding",i=e[o];return i==null?null:(n.mutateElement(e,{[o]:null}),i.elementId)},Wt=(e,t,n,o,i,r)=>{if(r){let a=!1,l=Up(t,d=>Le(d,!1)&&oi(d,e,n,o,(i||!ni(d))&&!$(d))).filter(d=>a?!1:(ni(d)||(a=!0),!0));if(!l||l.length===0)return null;if(l.length===1)return l[0];let c=l.filter(d=>oi(d,e,n,o,!1));return c.length===1?c[0]:l.sort((d,u)=>u.width**2+u.height**2-(d.width**2+d.height**2)).pop()}return Yp(t,a=>Le(a,!1)&&oi(a,e,n,o,(i||!ni(a))&&!$(a)))},Yp=(e,t)=>{let n=null;for(let o=e.length-1;o>=0;--o){let i=e[o];if(!i.isDeleted&&t(i)){n=i;break}}return n},Up=(e,t)=>{let n=[];for(let o=e.length-1;o>=0;--o){let i=e[o];i.isDeleted||t(i)&&n.push(i)}return n},Xp=(e,t,n,o)=>{let i=n==="start"?-1:1,r=i===-1?0:e.points.length-1,s=r-i,a=Y.getPointAtIndexGlobalCoordinates(e,r,o),l=Y.getPointAtIndexGlobalCoordinates(e,s,o);return{focus:Kp(t,o,l,a),gap:Math.max(1,_t(t,o,a))}},Ue=(e,t,n)=>{if(!Le(e))return;let{newSize:o,simultaneouslyUpdated:i}=n??{},r=jp(i),s=t.getNonDeletedElementsMap();n?.changedElements&&(s=new Map(s),n.changedElements.forEach(a=>{s.set(a.id,a)})),ri(s,e,a=>{if(!X(a)||a.isDeleted||!Wp(a,e))return;let l=a.startBinding?s.get(a.startBinding.elementId):null,c=a.endBinding?s.get(a.endBinding.elementId):null,d=null,u=null;l&&c&&(d=he(l,s),u=he(c,s));let p={startBinding:za(e,a.startBinding,o),endBinding:za(e,a.endBinding,o)};if(r.has(a.id)){t.mutateElement(a,p);return}let m=si(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&&!pn(d,u))){let g=qp(a,h,p[h],E,s);if(g)return[h==="startBinding"?0:a.points.length-1,{point:g}]}return null}).filter(E=>E!==null);Y.movePoints(a,t,new Map(m),{...e.id===a.startBinding?.elementId?{startBinding:p.startBinding}:{},...e.id===a.endBinding?.elementId?{endBinding:p.endBinding}:{}});let f=W(a,s);f&&!f.isDeleted&&un(a,t,!1)})},uy=(e,t,n)=>{X(e)?zp([e],!0,[],t,n?.zoom):Ue(e,t,{...n,changedElements:new Map([[e.id,e]])})},Wp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,jp=e=>new Set((e||[]).map(t=>t.id)),Oa=(e,t,n,o,i,r,s)=>{let a=Mt(Z(t,e));return!n||!o?a:Vp(i,n,r,s)?to(n,o,e):Mt(Z(e,fe(n,r)))},Vp=(e,t,n,o)=>{let i=_t(t,n,e),r=ai(t,t.width,t.height,o);return i>r?null:i},Pr=(e,t,n,o)=>{(Cp()||Bp())&&Lp(e.points.length>1,"Arrow should have at least 2 points");let i=Ve(t,o),r=e.points[n==="start"?0:e.points.length-1],s=R(e.x+r[0],e.y+r[1]),a=ra(t)?$p(t,o,s):s,l=G(e),c=ct(i),d=n==="start"?1:e.points.length-2,u=ae(R(e.x+e.points[d][0],e.y+e.points[d][1]),c,e.angle??0),p=null;if(l){let m=Re(to(t,i,s)),f=Zp(t,o,a),E=R(m?c[0]:f[0],m?f[1]:c[1]),h=Ye(E,An(Dn(ro(Z(f,E)),Math.max(t.width,t.height)*2),E));p=In(t,o,h,ie).sort(jt)[0]}else p=In(t,o,Ye(u,An(Dn(ro(Z(a,u)),ut(a,u)+Math.max(t.width,t.height)*2),u)),ie).sort((m,f)=>jt(m,u)-jt(f,u))[0];return!p||jt(a,p)<Op?a:l?p:a},$p=(e,t,n)=>{let o=fe(e,t),i=ae(n,o,-e.angle);return i[0]<e.x&&i[1]<e.y?i[1]-e.y>-ie?ae(R(e.x-ie,e.y),o,e.angle):ae(R(e.x,e.y-ie),o,e.angle):i[0]<e.x&&i[1]>e.y+e.height?i[0]-e.x>-ie?ae(R(e.x,e.y+e.height+ie),o,e.angle):ae(R(e.x-ie,e.y+e.height),o,e.angle):i[0]>e.x+e.width&&i[1]>e.y+e.height?i[0]-e.x<e.width+ie?ae(R(e.x+e.width,e.y+e.height+ie),o,e.angle):ae(R(e.x+e.width+ie,e.y+e.height),o,e.angle):i[0]>e.x+e.width&&i[1]<e.y?i[0]-e.x<e.width+ie?ae(R(e.x+e.width,e.y-ie),o,e.angle):ae(R(e.x+e.width+ie,e.y),o,e.angle):n},Zp=(e,t,n,o=.05)=>{let{x:i,y:r,width:s,height:a,angle:l}=e,c=fe(e,t,-.1,-.1),d=ae(n,c,-l),u=ka(o*a,5,80),p=ka(o*s,5,80);if(d[0]<=i+s/2&&d[1]>c[1]-u&&d[1]<c[1]+u)return ae(R(i-ie,c[1]),c,l);if(d[1]<=r+a/2&&d[0]>c[0]-p&&d[0]<c[0]+p)return ae(R(c[0],r-ie),c,l);if(d[0]>=i+s/2&&d[1]>c[1]-u&&d[1]<c[1]+u)return ae(R(i+s+ie,c[1]),c,l);if(d[1]>=r+a/2&&d[0]>c[0]-p&&d[0]<c[0]+p)return ae(R(c[0],r+a+ie),c,l);if(e.type==="diamond"){let m=ie,f=R(i+s/4-m,r+a/4-m),E=R(i+3*s/4+m,r+a/4-m),h=R(i+s/4-m,r+3*a/4+m),g=R(i+3*s/4+m,r+3*a/4+m);if(ut(f,d)<Math.max(p,u))return ae(f,c,l);if(ut(E,d)<Math.max(p,u))return ae(E,c,l);if(ut(h,d)<Math.max(p,u))return ae(h,c,l);if(ut(g,d)<Math.max(p,u))return ae(g,c,l)}return n},qp=(e,t,n,o,i)=>{if(n==null||n.elementId!==o.id&&e.points.length>2)return null;let r=t==="startBinding"?-1:1,s=r===-1?0:e.points.length-1;if(G(e)&&Qn(n)){let u=Ar(n.fixedPoint)??ja(e,o,t==="startBinding"?"start":"end",i).fixedPoint,p=fe(o,i),m=R(o.x+u[0]*o.width,o.y+u[1]*o.height),f=ae(m,p,o.angle);return Y.pointFromAbsoluteCoords(e,f,i)}let a=s-r,l=Y.getPointAtIndexGlobalCoordinates(e,a,i),c=Qp(o,i,n.focus,l),d;if(n.gap===0)d=c;else{let u=Y.getPointAtIndexGlobalCoordinates(e,s,i),p=fe(o,i),m=ut(l,u)+ut(l,p)+Math.max(o.width,o.height)*2,f=[...In(o,i,Ye(l,An(Dn(ro(Z(c,l)),m),l)),n.gap).sort((E,h)=>jt(E,l)-jt(h,l)),An(Dn(ro(Z(c,l)),ut(l,u)),l)];f.length>1?d=f[0]:f.length===1?d=c:d=u}return Y.pointFromAbsoluteCoords(e,d,i)},ja=(e,t,n,o)=>{let i=[t.x,t.y,t.x+t.width,t.y+t.height],r=Pr(e,t,n,o),s=R(i[0]+(i[2]-i[0])/2,i[1]+(i[3]-i[1])/2),a=ae(r,s,-t.angle);return{fixedPoint:Ar([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},za=(e,t,n)=>{if(t==null||n==null)return t;let{width:o,height:i}=n,{width:r,height:s}=e,a=Math.max(1,Math.min(ai(e,o,i),t.gap*(o<i?o/r:i/s)));return{...t,gap:a}},ii=(e,t,n,o,i)=>Wt(Va(e,t,n),o,n,i,G(e),G(e)),Va=(e,t,n)=>{let o=t==="start"?0:-1;return vp(Y.getPointAtIndexGlobalCoordinates(e,o,n))},$a=(e,t,n)=>{for(let o of e){if("boundElements"in o&&o.boundElements&&Object.assign(o,{boundElements:o.boundElements.reduce((i,r)=>{let s=t.get(r.id);return s&&i.push({...r,id:s}),i},[])}),"containerId"in o&&o.containerId&&Object.assign(o,{containerId:t.get(o.containerId)??null}),"endBinding"in o&&o.endBinding){let i=t.get(o.endBinding.elementId);Object.assign(o,{endBinding:i?{...o.endBinding,elementId:i}:null})}if("startBinding"in o&&o.startBinding){let i=t.get(o.startBinding.elementId);Object.assign(o,{startBinding:i?{...o.startBinding,elementId:i}:null})}G(o)&&Object.assign(o,Tn(o,n,{points:[o.points[0],o.points[o.points.length-1]]}))}},py=(e,t)=>{let n=Ha(e);for(let o of t)Vt.unbindAffected(n,o,(i,r)=>ye(i,n,r)),$t.unbindAffected(n,o,(i,r)=>ye(i,n,r))},io=(e,t,n=[])=>{if(!e)return null;let o=e.filter(i=>!t.has(i.id));return o.push(...n.map(i=>({id:i.id,type:i.type}))),o},oi=(e,{x:t,y:n},o,i,r)=>{let s=R(t,n),a=ai(e,e.width,e.height,i),l=(r||!ni(e))&&!$(e),c=[t-a,n-a,t+a,n+a],d=he(e,o);if(!pn(c,d))return!1;let u=In(e,o,Ye(fe(e,o),s)),p=_t(e,o,s);return l?u.length===0||p<=a:u.length>0&&p<=a},ai=(e,t,n,o)=>{let i=o?.value&&o.value<1?o.value:1,s=(e.type==="diamond"?1/Math.sqrt(2):1)*Math.min(t,n);return Math.max(16,Math.min(.25*s,32),Rp/i+ie)},Kp=(e,t,n,o)=>{let i=fe(e,t);if(Gp(n,o))return 0;let r=ae(n,i,-e.angle),s=ae(o,i,-e.angle),a=Math.sign(_e(Z(s,n),Z(s,i)))*-1,l=Ye(s,An(Dn(ro(Z(s,r)),Math.max(e.width*2,e.height*2)),s)),c=e.type==="diamond"?[Ye(R(e.x+e.width/2,e.y),R(e.x+e.width/2,e.y+e.height)),Ye(R(e.x,e.y+e.height/2),R(e.x+e.width,e.y+e.height/2))]:[Ye(R(e.x,e.y),R(e.x+e.width,e.y+e.height)),Ye(R(e.x+e.width,e.y),R(e.x,e.y+e.height))],d=e.type==="diamond"?[Ye(R(e.x+e.width/2,e.y-e.height),R(e.x+e.width/2,e.y+e.height*2)),Ye(R(e.x-e.width,e.y+e.height/2),R(e.x+e.width*2,e.y+e.height/2))]:[Ye(R(e.x-e.width,e.y-e.height),R(e.x+e.width*2,e.y+e.height*2)),Ye(R(e.x+e.width*2,e.y-e.height),R(e.x-e.width,e.y+e.height*2))];return[Fa(l,d[0]),Fa(l,d[1])].filter(m=>m!==null).sort((m,f)=>jt(m,o)-jt(f,o)).map((m,f)=>a*ut(i,m)/(e.type==="diamond"?ut(c[f][0],c[f][1])/2:Math.sqrt(e.width**2+e.height**2)/2)).sort((m,f)=>Math.abs(m)-Math.abs(f))[0]??0},Qp=(e,t,n,o)=>{let i=fe(e,t);if(n===0)return i;let r=(e.type==="diamond"?[R(e.x,e.y+e.height/2),R(e.x+e.width/2,e.y),R(e.x+e.width,e.y+e.height/2),R(e.x+e.width/2,e.y+e.height)]:[R(e.x,e.y),R(e.x+e.width,e.y),R(e.x+e.width,e.y+e.height),R(e.x,e.y+e.height)]).map(l=>An(Dn(Z(l,i),Math.abs(n)),i)).map(l=>ae(l,i,e.angle)),s=[_e(Z(o,r[0]),Z(r[1],r[0]))>0&&(n>0?_e(Z(o,r[1]),Z(r[2],r[1]))<0:_e(Z(o,r[3]),Z(r[0],r[3]))<0),_e(Z(o,r[1]),Z(r[2],r[1]))>0&&(n>0?_e(Z(o,r[2]),Z(r[3],r[2]))<0:_e(Z(o,r[0]),Z(r[1],r[0]))<0),_e(Z(o,r[2]),Z(r[3],r[2]))>0&&(n>0?_e(Z(o,r[3]),Z(r[0],r[3]))<0:_e(Z(o,r[1]),Z(r[2],r[1]))<0),_e(Z(o,r[3]),Z(r[0],r[3]))>0&&(n>0?_e(Z(o,r[0]),Z(r[1],r[0]))<0:_e(Z(o,r[2]),Z(r[3],r[2]))<0)];return s[0]?n>0?r[1]:r[0]:s[1]?n>0?r[2]:r[1]:s[2]?n>0?r[3]:r[2]:n>0?r[0]:r[3]},Za=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),ri=(e,t,n)=>{Le(t)&&(t.boundElements?.slice()??[]).forEach(({id:i})=>{n(e.get(i),"boundElements",i)})},si=(e,t,n)=>{let o=[];if(t.frameId){let i=t.frameId;o.push(n(e.get(i),"frameId",i))}if(de(t)){let i=t.containerId;o.push(n(e.get(i),"containerId",i))}if(_(t)){if(t.startBinding){let i=t.startBinding.elementId;o.push(n(e.get(i),"startBinding",i))}if(t.endBinding){let i=t.endBinding.elementId;o.push(n(e.get(i),"endBinding",i))}}return o},Vt=class{static unbindAffected(t,n,o){n&&si(t,n,i=>{!i||i.isDeleted||ri(t,i,(r,s,a)=>{a===n.id&&o(i,{boundElements:io(i.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,o)=>{!n||n.isDeleted||si(t,n,(i,r)=>{if(!i||i.isDeleted){o(n,{[r]:null});return}r!=="frameId"&&(i.boundElements?.find(s=>s.id===n.id)||(_(n)&&o(i,{boundElements:io(i.boundElements,new Set,new Array(n))}),oe(n)&&(i.boundElements?.find(s=>s.type==="text")?o(n,{[r]:null}):o(i,{boundElements:io(i.boundElements,new Set,new Array(n))}))))})}},$t=class{static unbindAffected(t,n,o){n&&ri(t,n,i=>{!i||i.isDeleted||si(t,i,(r,s,a)=>{a===n.id&&o(i,{[s]:null})})})}static rebindAffected=(t,n,o)=>{!n||n.isDeleted||ri(t,n,(i,r,s)=>{if(!i||i.isDeleted){o(n,{boundElements:io(n.boundElements,new Set([s]))});return}oe(i)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===i.id?i.containerId!==n.id&&o(i,{containerId:n.id}):(i.containerId!==null&&o(i,{containerId:null}),o(n,{boundElements:io(n.boundElements,new Set([i.id]))})))})}},ti=(e,t,n)=>{let[o,i]=Ar(e);return ae(R(t.x+t.width*o,t.y+t.height*i),fe(t,n),t.angle)},Jp=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),o=e.endBinding&&t.get(e.endBinding.elementId),i=n&&e.startBinding?ti(e.startBinding.fixedPoint,n,t):R(e.x+e.points[0][0],e.y+e.points[0][1]),r=o&&e.endBinding?ti(e.endBinding.fixedPoint,o,t):R(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[i,r]},qa=(e,t)=>{let[n,o]=Jp(e,t);return[Y.pointFromAbsoluteCoords(e,n,t),Y.pointFromAbsoluteCoords(e,o,t)]},Ar=e=>e&&(Math.abs(e[0]-.5)<1e-4||Math.abs(e[1]-.5)<1e-4)?e.map(t=>Math.abs(t-.5)<1e-4?.5001:t):e;var vr=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(o=>B(o[0]-t,o[1]-n)),offsetX:t,offsetY:n}},Y=class e{elementId;selectedPointsIndices;pointerDownState;isDragging;lastUncommittedPoint;pointerOffset;startBindingElement;endBindingElement;hoverPointIndex;segmentMidPointHoveredCoords;elbowed;customLineAngle;isEditing;constructor(t,n,o=!1){this.elementId=t.id,Qa(t.points[0],B(0,0))||(console.error("Linear element is not normalized",Error().stack),ye(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.startBindingElement="keep",this.endBindingElement="keep",this.pointerDownState={prevSelectedPointsIndices:null,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:null,segmentMidpoint:{value:null,index:null,added:!1}},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.elbowed=G(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=o}static POINT_HANDLE_SIZE=10;static getElement(t,n){let o=n.get(t);return o||null}static handleBoxSelection(t,n,o,i){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,i);if(!l)return!1;let[c,d,u,p]=H(n.selectionElement,i),f=e.getPointsGlobalCoordinates(l,i).reduce((E,h,g)=>((h[0]>=c&&h[0]<=u&&h[1]>=d&&h[1]<=p||t.shiftKey&&s?.includes(g))&&E.push(g),E),[]).filter(E=>!(G(l)&&E!==0&&E!==l.points.length-1));o({selectedLinearElement:{...r,selectedPointsIndices:f.length?f:null}})}static handlePointDragging(t,n,o,i,r){if(!r)return null;let{elementId:s}=r,a=n.scene.getNonDeletedElementsMap(),l=e.getElement(s,a),c=r.customLineAngle;if(!l||G(l)&&!r.pointerDownState.lastClickedIsEndPoint&&r.pointerDownState.lastClickedPoint!==0)return null;let d=G(l)?[r.selectedPointsIndices?.includes(0)?0:void 0,r.selectedPointsIndices?.find(m=>m>0)?l.points.length-1:void 0].filter(m=>m!==void 0):r.selectedPointsIndices,u=G(l)?r.pointerDownState.lastClickedPoint>0?l.points.length-1:0:r.pointerDownState.lastClickedPoint,p=l.points[u];if(d&&p){if(Ja(t)&&d.length===1&&l.points.length>1){let h=d[0],g=l.points[h===0?1:h-1];c=r.customLineAngle??Math.atan2(l.points[h][1]-g[1],l.points[h][0]-g[0]);let[x,y]=e._getShiftLockedDelta(l,a,g,B(o,i),t[Ln.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),c);e.movePoints(l,n.scene,new Map([[h,{point:B(x+g[0],y+g[1]),isDragging:h===u}]]))}else{let h=e.createPointAt(l,a,o-r.pointerOffset.x,i-r.pointerOffset.y,t[Ln.CTRL_OR_CMD]?null:n.getEffectiveGridSize()),g=h[0]-p[0],x=h[1]-p[1];e.movePoints(l,n.scene,new Map(d.map(y=>{let b=y===u?e.createPointAt(l,a,o-r.pointerOffset.x,i-r.pointerOffset.y,t[Ln.CTRL_OR_CMD]?null:n.getEffectiveGridSize()):B(l.points[y][0]+g,l.points[y][1]+x);return[y,{point:b,isDragging:y===u}]})))}W(l,a)&&un(l,n.scene,!1);let f=[];if(Qi(l,!1)){let h=d[0]===0,g=d[d.length-1]===l.points.length-1,x=[];!h!=!g?x.push({x:o,y:i}):(h&&x.push(Dr(e.getPointGlobalCoordinates(l,l.points[0],a))),g&&x.push(Dr(e.getPointGlobalCoordinates(l,l.points[d[d.length-1]],a)))),x.length&&(f=Ya(l,x,n.scene,n.state.zoom))}let E={...r,selectedPointsIndices:d,segmentMidPointHoveredCoords:u!==0&&u!==l.points.length-1?this.getPointGlobalCoordinates(l,p,a):null,hoverPointIndex:u===0||u===l.points.length-1?u:-1,isDragging:!0,customLineAngle:c};return{...n.state,selectedLinearElement:E,suggestedBindings:f}}return null}static handlePointerUp(t,n,o,i){let r=i.getNonDeletedElementsMap(),s=i.getNonDeletedElements(),a=im(t,o),{elementId:l,selectedPointsIndices:c,isDragging:d,pointerDownState:u}=n,p=e.getElement(l,r);if(!p)return n;let m={};if(d&&c){for(let f of c)if(f===0||f===p.points.length-1){rm(p.points,o.zoom.value)&&(cn(p)&&i.mutateElement(p,{...nl(p,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(p,i,new Map([[f,{point:f===0?p.points[p.points.length-1]:p.points[0]}]])));let E=Mr(o)?Wt((c?.length??0)>1?Dr(e.getPointAtIndexGlobalCoordinates(p,f,r)):a,s,r,o.zoom,G(p),G(p)):null;m[f===0?"startBindingElement":"endBindingElement"]=E}}return{...n,...m,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:d||t.shiftKey?!d&&t.shiftKey&&u.prevSelectedPointsIndices?.includes(u.lastClickedPoint)?c&&c.filter(f=>f!==u.lastClickedPoint):c:c?.includes(u.lastClickedPoint)?[u.lastClickedPoint]:c,isDragging:!1,pointerOffset:{x:0,y:0},customLineAngle:null}}static getEditorMidPoints=(t,n,o)=>{let i=W(t,n);if(!G(t)&&!o.selectedLinearElement?.isEditing&&t.points.length>2&&!i)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,o.zoom)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,o,i)=>{let{elementId:r}=t,s=e.getElement(r,i);if(!s)return null;let a=e.getPointIndexUnderCursor(s,i,o.zoom,n.x,n.y);if(!G(s)&&a>=0||e.getPointsGlobalCoordinates(s,i).length>=3&&!o.selectedLinearElement?.isEditing&&!G(s))return null;let c=(e.POINT_HANDLE_SIZE+1)/o.zoom.value,d=t.segmentMidPointHoveredCoords;if(d&&vn(B(d[0],d[1]),B(n.x,n.y))<=c)return d;let u=0,p=e.getEditorMidPoints(s,i,o);for(;u<p.length;){if(p[u]!==null&&vn(p[u],B(n.x,n.y))<=c)return p[u];u++}return null};static isSegmentTooShort(t,n,o,i,r){if(G(t))return i>=0&&i<t.points.length?vn(n,o)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=vn(n,o);if(t.points.length>2&&t.roundness){let[a,l]=tl(t);At(a.length===0&&l.length>0,"Only linears built out of curves are supported"),At(a.length+l.length>=i,"Invalid segment index while calculating mid point"),s=tm(l[i])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(G(t)){At(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=Ka(t.points[n-1],t.points[n]);return B(t.x+r[0],t.y+r[1])}let[o,i]=tl(t);if(At(o.length===0&&i.length>0||o.length>0&&i.length===0,"Only linears built out of either segments or curves are supported"),At(o.length+i.length>=n,"Invalid segment index while calculating mid point"),o.length){let r=o[n-1];return Ka(r[0],r[1])}if(i.length){let r=i[n-1];return nm(r,.5)}At(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,o,i){let r=e.getElement(t.elementId,i);if(!r)return-1;let s=e.getEditorMidPoints(r,i,n),a=0;for(;a<s.length;){if(e.arePointsEqual(o,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,o,i,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),c=s.getNonDeletedElements(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:u}=r,p=e.getElement(u,l);if(!p)return d;let m=e.getSegmentMidpointHitCoords(r,i,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,i.x,i.y,t[Ln.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),o.scheduleCapture(),d.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:{x:i.x,y:i.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:[p.points.length-1],lastUncommittedPoint:null,endBindingElement:Wt(i,c,l,n.state.zoom,r.elbowed)},d.didAddPoint=!0,d;let E=e.getPointIndexUnderCursor(p,l,a.zoom,i.x,i.y);if(E>=0||m)d.hitElement=p;else{let{startBindingElement:D,endBindingElement:T}=r;Mr(a)&&Qi(p)&&Tr(p,D,T,s)}let[h,g,x,y]=H(p,l),b=(h+x)/2,w=(g+y)/2,I=E>-1&&Te(B(p.x+p.points[E][0],p.y+p.points[E][1]),B(b,w),p.angle),M=E>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(E)?sm([...r.selectedPointsIndices||[],E]):[E]:null;return d.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:E,lastClickedIsEndPoint:E===p.points.length-1,origin:{x:i.x,y:i.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:M,pointerOffset:I?{x:i.x-I[0],y:i.y-I[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Qa(t,n)}static handlePointerMove(t,n,o,i){let r=i.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=i.scene.getNonDeletedElementsMap(),c=e.getElement(s,l);if(!c)return r.selectedLinearElement;let{points:d}=c,u=d[d.length-1];if(!t.altKey)return u===a&&e.deletePoints(c,i,[d.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let p;if(Ja(t)&&d.length>=2){let m=d[d.length-2],[f,E]=e._getShiftLockedDelta(c,l,m,B(n,o),t[Ln.CTRL_OR_CMD]?null:i.getEffectiveGridSize());p=B(f+m[0],E+m[1])}else p=e.createPointAt(c,l,n-r.selectedLinearElement.pointerOffset.x,o-r.selectedLinearElement.pointerOffset.y,t[Ln.CTRL_OR_CMD]||G(c)?null:i.getEffectiveGridSize());return u===a?e.movePoints(c,i.scene,new Map([[c.points.length-1,{point:p}]])):e.addPoints(c,i.scene,[p]),{...r.selectedLinearElement,lastUncommittedPoint:c.points[c.points.length-1]}}static getPointGlobalCoordinates(t,n,o){let[i,r,s,a]=H(t,o),l=(i+s)/2,c=(r+a)/2,{x:d,y:u}=t;return Te(B(d+n[0],u+n[1]),B(l,c),t.angle)}static getPointsGlobalCoordinates(t,n){let[o,i,r,s]=H(t,n),a=(o+r)/2,l=(i+s)/2;return t.points.map(c=>{let{x:d,y:u}=t;return Te(B(d+c[0],u+c[1]),B(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,o){let i=n<0?t.points.length+n:n,[r,s,a,l]=H(t,o),c=(r+a)/2,d=(s+l)/2,u=t.points[i],{x:p,y:m}=t;return u?Te(B(p+u[0],m+u[1]),B(c,d),t.angle):Te(B(p,m),B(c,d),t.angle)}static pointFromAbsoluteCoords(t,n,o){if(G(t))return B(n[0]-t.x,n[1]-t.y);let[i,r,s,a]=H(t,o),l=(i+s)/2,c=(r+a)/2,[d,u]=Te(B(n[0],n[1]),B(l,c),-t.angle);return B(d-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,o,i,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(vn(B(i,r),B(l[0],l[1]))*o.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,o,i,r){let s=el(o,i,r),[a,l,c,d]=H(t,n),u=(a+c)/2,p=(l+d)/2,[m,f]=Te(B(s[0],s[1]),B(u,p),-t.angle);return B(m-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:o,offsetY:i}=vr(t);return{points:n,x:t.x+o,y:t.y+i}}static duplicateSelectedPoints(t,n){At(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let o=n.getNonDeletedElementsMap(),{selectedPointsIndices:i,elementId:r}=t.selectedLinearElement,s=e.getElement(r,o);At(s,"The linear element does not exist in the provided Scene"),At(i!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],c=!1,d=-1,u=a.reduce((p,m,f)=>{if(++d,p.push(m),i.includes(f)){let h=a[f+1];h||(c=!0),p.push(h?B((m[0]+h[0])/2,(m[1]+h[1])/2):B(m[0],m[1])),l.push(d+1),++d}return p},[]);if(n.mutateElement(s,{points:u}),c){let p=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:B(p[0]+30,p[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,o){let i=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((d,u)=>!o.includes(u));cn(t)&&t.polygon&&(i||o.includes(0)||o.includes(t.points.length-1))&&(r[0]=B(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:c}=vr({points:r});e._updatePoints(t,n.scene,a,l,c)}static addPoints(t,n,o){let i=[...t.points,...o];cn(t)&&t.polygon&&(i[0]=B(i[i.length-1][0],i[i.length-1][1]));let{points:r,offsetX:s,offsetY:a}=vr({points:i});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,o,i){let{points:r}=t;if(cn(t)&&t.polygon){let d=o.get(0),u=o.get(r.length-1);d?o.set(r.length-1,{point:B(d.point[0],d.point[1]),isDragging:d.isDragging}):u&&o.set(0,{point:B(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=o.get(0)?.point??B(0,0),[a,l]=s,c=G(t)?[o.get(0)?.point??r[0],o.get(r.length-1)?.point??r[r.length-1]]:r.map((d,u)=>{let p=o.get(u)?.point??d;return B(p[0]-a,p[1]-l)});e._updatePoints(t,n,c,a,l,i,{isDragging:Array.from(o.values()).some(d=>d.isDragging)})}static shouldAddMidpoint(t,n,o,i){let r=e.getElement(t.elementId,i);if(r&&G(r)||!r)return!1;let{segmentMidpoint:s}=t.pointerDownState;if(s.added||s.value===null||s.index===null||t.pointerDownState.origin===null)return!1;let a=t.pointerDownState.origin,l=vn(B(a.x,a.y),B(n.x,n.y));return!(!o.selectedLinearElement?.isEditing&&l<om/o.zoom.value)}static addMidpoint(t,n,o,i,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.pointerDownState,c={pointerDownState:t.pointerDownState,selectedPointsIndices:t.selectedPointsIndices},d=e.createPointAt(a,s,n.x,n.y,i&&!G(a)?o.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),d,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),c.pointerDownState={...t.pointerDownState,segmentMidpoint:{...t.pointerDownState.segmentMidpoint,added:!0},lastClickedPoint:l.index},c.selectedPointsIndices=[l.index],c}static _updatePoints(t,n,o,i,r,s,a){if(G(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding!==null&&Qn(s.startBinding)?s.startBinding:null),s?.endBinding!==void 0&&(l.endBinding=s.endBinding!==null&&Qn(s.endBinding)?s.endBinding:null),l.points=Array.from(o),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1})}else{let l=Lr(t,o),c=Lr(t,t.points),d=(l[0]+l[2])/2,u=(l[1]+l[3])/2,p=(c[0]+c[2])/2,m=(c[1]+c[3])/2,f=p-d,E=m-u,h=Te(B(i,r),B(f,E),t.angle);n.mutateElement(t,{...s,points:o,x:t.x+h[0],y:t.y+h[1]})}}static _getShiftLockedDelta(t,n,o,i,r,s){let a=e.getPointGlobalCoordinates(t,o,n);if(G(t))return[i[0]-a[0],i[1]-a[1]];let[l,c]=el(i[0],i[1],r),{width:d,height:u}=ol(a[0],a[1],l,c,s);return Te(B(d,u),B(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,o)=>{e.getPointsGlobalCoordinates(t,o).length<2&&ye(n,o,{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],o);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,o,i)=>{let[r,s,a,l]=o,c=(r+a)/2,d=(s+l)/2,{x:u,y:p}=e.getBoundTextElementPosition(t,i,n),m=u+i.width,f=p+i.height,E=B(c,d),h=Te(B(r,s),E,t.angle),g=Te(B(a,s),E,t.angle),x=Te(B(u,p),E,-t.angle),y=Te(B(m,p),E,-t.angle),b=Te(B(u,f),E,-t.angle),w=Te(B(m,f),E,-t.angle);return h[0]<g[0]&&h[1]>=g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(y[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):h[0]>=g[0]&&h[1]>g[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],y[0])),s=Math.min(s,b[1]),l=Math.max(l,y[1])):h[0]>=g[0]?(r=Math.min(r,y[0]),a=Math.max(a,b[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):h[1]<=g[1]&&(r=Math.min(r,Math.min(y[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,y[1]),l=Math.max(l,b[1])),[r,s,a,l,c,d]};static getElementAbsoluteCoords=(t,n,o=!1)=>{let i,r,s,a,l;if(t.points.length<2||!be.get(t)){let{minX:p,minY:m,maxX:f,maxY:E}=t.points.reduce((h,[g,x])=>(h.minY=Math.min(h.minY,x),h.minX=Math.min(h.minX,g),h.maxX=Math.max(h.maxX,g),h.maxY=Math.max(h.maxY,x),h),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});r=p+t.x,s=m+t.y,a=f+t.x,l=E+t.y}else{let p=be.generateElementShape(t,null),m=gt(p[0]),[f,E,h,g]=so(m);r=f+t.x,s=E+t.y,a=h+t.x,l=g+t.y}let c=(r+a)/2,d=(s+l)/2;if(i=[r,s,a,l,c,d],!o)return i;let u=W(t,n);return u&&(i=e.getMinMaxXYWithBoundText(t,n,[r,s,a,l],u)),i};static moveFixedSegment(t,n,o,i,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!G(a))return t;if(n&&n>0&&n<a.points.length){let l=Re(Mt(em(a.points[n],a.points[n-1]))),c=(a.fixedSegments??[]).reduce((m,f)=>(m[f.index]=f,m),{});c[n]={index:n,start:B(l?a.points[n-1][0]:o-a.x,l?i-a.y:a.points[n-1][1]),end:B(l?a.points[n][0]:o-a.x,l?i-a.y:a.points[n][1])};let d=Object.values(c).sort((m,f)=>m.index-f.index),u=d.map(m=>m.index).reduce((m,f)=>f<n?m+1:m,0);r.mutateElement(a,{fixedSegments:d});let p=B(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:p,pointerDownState:{...t.pointerDownState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:p}}}}return t}static deleteFixedSegment(t,n,o){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(i=>i.index!==o)})}},sm=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,o)=>n-o),t.length?t:null};P();import{arrayToMap as mt}from"@excalidraw/common";import{isPointWithinBounds as Dm,pointFrom as Rr}from"@excalidraw/math";P();import{vectorCross as al,vectorFromPoint as li}from"@excalidraw/math";function il(e){return[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])]}function am(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var lm=1e-6;function rl(e,t){let n=li(e[1],e[0]),o=li(t,e[0]),i=al(n,o);return Math.abs(i)<lm}function Cr(e,t){let n=li(e[1],e[0]),o=li(t,e[0]);return al(n,o)<0}function sl(e,t){return rl(e,t[0])||rl(e,t[1])||(Cr(e,t[0])?!Cr(e,t[1]):Cr(e,t[1]))}function ll(e,t){return am(il(e),il(t))&&sl(e,t)&&sl(t,e)}P();import{arrayToMap as cm}from"@excalidraw/common";import{getElementBounds as dm}from"@excalidraw/element";import{isArrowElement as um,isExcalidrawElement as pm,isFreeDrawElement as mm,isLinearElement as fm,isTextElement as hm}from"@excalidraw/element";import{rangeIncludesValue as ci,pointFrom as Dt,pointRotateRads as Em,rangeInclusive as di}from"@excalidraw/math";var gm=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)],xm=e=>fm(e)||mm(e)?e.points:gm(e),cl=e=>{let t=e.reduce((n,[o,i])=>(n.minY=Math.min(n.minY,i),n.minX=Math.min(n.minX,o),n.maxX=Math.max(n.maxX,o),n.maxY=Math.max(n.maxY,i),n),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},ul=e=>{let t=xm(e),{cx:n,cy:o}=cl(t),i=Dt(n,o),r=t.map(d=>Em(d,i,e.angle)),{minX:s,minY:a,maxX:l,maxY:c}=cl(r);return[s+e.x,a+e.y,l+e.x,c+e.y]},dl=(e,t,n=!1)=>{let o=ul(e),i=t[0]<=o[0]&&t[2]>=o[2]&&t[1]<=o[1]&&t[3]>=o[3];return n?i?!0:o[0]<=t[0]&&o[2]>=t[2]&&o[1]<=t[1]&&o[3]>=t[3]:i},wm=(e,t)=>{let n=ul(e);return(ci(n[0],di(t[0],t[2]))||ci(t[0],di(n[0],n[2])))&&(ci(n[1],di(t[1],t[3]))||ci(t[1],di(n[1],n[3])))},pl=({elements:e,bounds:t,type:n,errorMargin:o=0})=>{pm(t)&&(t=dm(t,cm(e)));let i=[t[0]-o,t[1]-o,t[2]+o,t[3]+o],r=new Set;for(let s of e){if(r.has(s.id))continue;if(n==="overlap"?wm(s,i):n==="inside"?dl(s,i):dl(s,i,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);hm(s)&&s.containerId&&r.add(s.containerId),um(s)&&(s.startBinding&&r.add(s.startBinding.elementId),s.endBinding&&r.add(s.endBinding?.elementId))}}return e.filter(s=>r.has(s.id))};P();import{arrayToMap as Mm,isShallowEqual as Tm}from"@excalidraw/common";P();var ym=(e,t,n)=>{let o=n.reduce((i,r)=>(r.groupIds.includes(e)&&(i[r.id]=!0),i),{});return Object.keys(o).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,...o}}},ml=function(){let e=null,t=null,n=null,o=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let c={};for(let p of r){let m=p.groupIds;if(a.editingGroupId){let f=m.indexOf(a.editingGroupId);f>-1&&(m=m.slice(0,f))}if(m.length>0){let f=m[m.length-1];c[f]=!0}}let d={},u=s.reduce((p,m)=>{if(m.isDeleted)return p;let f=m.groupIds.find(E=>c[E]);return f&&(p[m.id]=!0,Array.isArray(d[f])?d[f].push(m.id):d[f]=[m.id]),p},{});for(let p of Object.keys(d))d[p].length<2&&c[p]&&(c[p]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:c,selectedElementIds:Br({...a.selectedElementIds,...u},l)},n},i=(r,s,a,l)=>{let c=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):pt(s,r);return c.length?o(c,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Br(r.selectedElementIds,a)}};return i.clearCache=()=>{t=null,e=null,n=null},i}(),bm=(e,t)=>Gr(e,t)!=null,Gr=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Pm=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),fl=(e,t)=>{let n={...t,selectedGroupIds:{}};for(let o of e){let i=o.groupIds;if(t.editingGroupId){let r=i.indexOf(t.editingGroupId);r>-1&&(i=i.slice(0,r))}if(i.length>0){let r=i[i.length-1];n={...n,...ym(r,n,e)}}}return n.selectedGroupIds},Yy=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Im=(e,t)=>e.groupIds.includes(t),Ae=(e,t)=>{let n=[];for(let o of e.values())Im(o,t)&&n.push(o);return n},Sm=(e,t)=>e.groupIds.find(n=>t[n]),Uy=(e,t,n)=>{let o=[...e],i=n?o.indexOf(n):-1,r=i>-1?i:o.length;return o.splice(r,0,t),o},Xy=(e,t)=>e.filter(n=>!t[n]),Wy=(e,t)=>{let n=new Map;return e.forEach(o=>{let i=o.groupIds.length===0?o.id:o.groupIds[o.groupIds.length-1],r=n.get(i)||[],s=W(o,t);s&&r.push(s),n.set(i,[...r,o])}),Array.from(n.values())},hl=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let o of n.groupIds??[])t.add(o);return t},El=e=>{let t=e.flatMap(i=>i.groupIds),n=new Map,o=0;for(let i of t)n.set(i,(n.get(i)??0)+1),n.get(i)>o&&(o=n.get(i));return o===e.length},gl=e=>e.groupIds.length>0,xl=(e,t,n)=>{let o=[...e],i=t?e.indexOf(t):-1,r=i>-1?i:e.length;for(let s=0;s<r;s++)o[s]=n(o[s]);return o},ui=(e,t,n)=>{let o=Pm(n),i=e.filter(u=>!de(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])},c=(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)},d=e.every(u=>bm(n,u));return i.forEach(u=>{let p=Sm(u,n.selectedGroupIds);p?o.length===1&&d?c(u,p):l(u,p):a(u)}),Array.from(r.values()).concat(Array.from(s.values()))};var wl=e=>{let t=new Set;return e.forEach(n=>{$(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},Or=(e,t,n,o=!0)=>{let[i,r,s,a]=H(t,n),l=e.filter(c=>{let[d,u,p,m]=he(c,n),f=vt(c,n);if(f){let[E,h,g,x]=he(f,n);d=Math.max(E,d),u=Math.max(h,u),p=Math.min(g,p),m=Math.min(x,m)}return c.locked===!1&&c.type!=="selection"&&!de(c)&&i<=d&&r<=u&&s>=p&&a>=m});return l=o?wl(l):l,l=l.filter(c=>{let d=vt(c,n);return d?Zt(c,d,n):!0}),l},tb=(e,t,n,o)=>{let i=new Set(t.map(r=>r.id));return e.filter(r=>{let s=yl(r,n.width,n.height,n,o);return!i.has(r.id)&&s})},nb=function(){let e=null,t=null,n=null,o=(i,r)=>(n!=null&&i===e&&r.selectedElementIds===t||(n=i.some(s=>r.selectedElementIds[s.id]),e=i,t=r.selectedElementIds),n);return o.clearCache=()=>{e=null,t=null,n=null},o}(),pt=(e,t,n)=>{let o=new Set,i=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){i.push(r),o.add(r.id);continue}if(n?.includeBoundTextElement&&de(r)&&t.selectedElementIds[r?.containerId]){i.push(r),o.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return i.forEach(s=>{$(s)&&qt(e,s.id).forEach(a=>!o.has(a.id)&&r.push(a)),r.push(s)}),r}return i},ob=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:pt(e,t,{includeBoundTextElement:!0}),Br=(e,t)=>Tm(t.selectedElementIds,e)?t.selectedElementIds:e,Am=(e,t)=>{let n=e.filter(X);if(n.length===1){let o=n[0],i=o.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===o.id||i.includes(s.id)))return new Y(o,Mm(t))}return null},ib=(e,t,n)=>({selectedLinearElement:Am(e,t),...ml({editingGroupId:n.editingGroupId,selectedElementIds:wl(e).reduce((o,i)=>(de(i)||(o[i.id]=!0),o),{})},t,n,null)});var bl=(e,t,n)=>{let o=mt(e);for(let i of t)if(i.frameId){let r=n.get(i.id),s=n.get(i.frameId),a=r&&o.get(r);a&&ye(a,o,{frameId:s??null})}};function Cn(e,t,n){let o=kr(t,n),i=kr(e,n);return o.some(s=>i.some(a=>ll(s,a)))}var Pl=(e,t,n)=>pi(Or(e,t,n,!1)).filter(o=>!$(o)&&!o.frameId||o.frameId===t.id),Fr=(e,t,n)=>Or([t],e,n).some(o=>o.id===t.id),gb=(e,t)=>{let n=mt(e);return e.filter(o=>Cn(o,t,n))},Kt=(e,t,n)=>{let[o,i,r,s]=H(t,n),[a,l,c,d]=tt(e);return o<=a&&i<=l&&r>=c&&s>=d},Zt=(e,t,n)=>Kt([e],t,n)||Cn(e,t,n)||Fr(e,t,n),xb=(e,t,n)=>{let[o,i,r,s]=H(t,n);return Dm(Rr(o,i),Rr(e.x,e.y),Rr(r,s))},wb=(e,t,n)=>{let o=mt(e),i=t.flatMap(r=>Ae(e,r));return i.length===0?!0:!!i.find(r=>Kt([r],n,o)||Cn(r,n,o))},yb=(e,t,n)=>{let o=mt(e),i=t.flatMap(r=>Ae(e,r));return i.length===0?!0:i.find(r=>Kt([r],n,o)||Cn(r,n,o))===void 0},bb=e=>{let t=new Map;for(let n of e){let o=$(n)?n.id:n.frameId;o&&!t.has(o)&&t.set(o,qt(e,o))}return t},qt=(e,t)=>{let n=[];for(let o of e.values())o.frameId===t&&n.push(o);return n},vm=e=>e.filter(t=>$(t)),Pb=e=>{let t=mt(vm(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},Ib=(e,t,n,o)=>{let i=qt(e,t.id),r=new Set(i),s=new Set([...Pl(e,t,o),...i.filter(p=>Fr(p,t,o))]),a=i.filter(p=>!s.has(p)),l=new Set(Array.from(s).flatMap(p=>p.groupIds));for(let p of a)if(!Cn(p,t,o))p.groupIds.length===0&&r.delete(p);else if(p.groupIds.length>0)for(let m of p.groupIds)l.add(m);for(let p of a)if(p.groupIds.length>0){let m=!0;for(let f of p.groupIds)l.has(f)&&(m=!1);m&&r.delete(p)}let c=Array.from(s).filter(p=>p.groupIds.length===0);for(let p of c)r.add(p);let d=Array.from(s).filter(p=>p.groupIds.length>0),u=fl(d,n);for(let[p,m]of Object.entries(u))if(m){let f=Ae(e,p);if(Kt(f,t,o))for(let E of f)r.add(E)}return[...r].filter(p=>!(oe(p)&&p.containerId))},Sb=(e,t,n)=>Lm(pi(e,Pl(e,t,n)),t,n),Lm=(e,t,n)=>{let o=[],i=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>i.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=>{i.set(a,s)})}s||o.push(r)}return o},vt=(e,t)=>e.frameId&&t.get(e.frameId)||null,Mb=(e,t)=>{let n=new Set,o=mt(e);e=pi(e);for(let s of e)$(s)&&s.id!==t.id&&n.add(s.id);let i=new Set,r=[];for(let s of e)if(!($(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!i.has(a)){i.add(a);let l=Ae(e,a);if(l.some(c=>Zt(c,t,o)))for(let c of l)r.push(c)}}else Zt(s,t,o)&&r.push(s);return r},Cm=(e,t,n,o)=>{let i=mt(e),r=new Map;for(let c of e.values())c.frameId===n.id&&r.set(c.id,!0);let s=new Set(t.map(c=>c.id)),a=[],l=new Set;for(let c of t)$(c)&&c.id!==n.id&&l.add(c.id);for(let c of pi(e,t)){if($(c)||c.frameId&&l.has(c.frameId)||c.frameId&&o.selectedElementIds[c.id]&&o.selectedElementIds[c.frameId])continue;r.has(c.id)||a.push(c);let d=W(c,i);d&&!s.has(d.id)&&!r.has(d.id)&&a.push(d)}for(let c of a)ye(c,i,{frameId:n.id});return e},Il=(e,t)=>{let n=new Map,o=new Map;for(let i of e)if(i.frameId){n.set(i.id,i);let r=o.get(i.frameId)||[];r.push(i);let s=W(i,t);s&&(n.set(s.id,s),r.push(s)),o.set(i.frameId,r)}for(let[,i]of n)ye(i,t,{frameId:null})},Bm=(e,t)=>{let n=qt(e,t.id);return Il(n,mt(e)),e},Tb=(e,t,n,o)=>Cm(Bm(e,n),t,n,o.state).slice(),Ab=(e,t,n)=>{let o=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),i=new Set(o);if(t.editingGroupId)for(let a of o)a.groupIds.length===0?i.add(a):a.groupIds.flatMap(l=>Ae(e,l)).forEach(l=>i.add(l));let r=new Set,s=mt(e);return i.forEach(a=>{a.frameId&&!$(a)&&!Sl(a,s,t)&&r.add(a)}),r.size>0&&Il(r,s),e},pi=(e,t)=>{let n=new Set,o=t||e;for(let s of o.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let i=new Set;for(let s of n)Ae(e,s).some(a=>$(a))&&i.add(s);let r=[];for(let s of o.values())i.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},Gm=(e,t,n)=>{let o=oe(e)&&Ce(e,t)||e;return o.frameId&&n.selectedElementIds[o.id]&&n.selectedElementIds[o.frameId]?vt(o,t):n.selectedElementIds[o.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:vt(o,t)},Sl=(e,t,n,o)=>{let i=o?.targetFrame??Gm(e,t,n);if(!i)return!1;let r=oe(e)&&Ce(e,t)||e,s=l=>{o?.checkedGroups&&r.groupIds.forEach(c=>{o.checkedGroups?.set(c,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[i.id])return!0;if(r.groupIds.length===0)return Zt(r,i,t);for(let l of r.groupIds)if(o?.checkedGroups?.has(l))return o.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>o?.checkedGroups?!o.checkedGroups.has(l):!0).flatMap(l=>Ae(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(pt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(d=>{a.delete(d)})}for(let l of a)if($(l))return s(!1),!1;for(let l of a)if(Zt(l,i,t))return s(!0),!0;return!1},Db=(e,t,n,o,i)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Cn(e,t,o)||Fr(e,t,o);if(r){for(let s of e.groupIds)i?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Kt([e],t,o)){let s=!1;if(n.selectedElementsAreBeingDragged)s=Sl(e,o,n,{targetFrame:t,checkedGroups:i});else{s=e.frameId===t.id;for(let a of e.groupIds)i?.set(a,s)}for(let a of e.groupIds)i?.set(a,s);return s}return!1},Om="Frame",Rm="AI Frame",km=e=>ko(e)?Om:Rm,vb=e=>e.name===null?km(e):e.name,Lb=(e,t)=>pl({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),Cb=e=>{let t=mt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Um="invert(100%) hue-rotate(180deg) saturate(1.25)",Dl=(e,t)=>zt(e)&&!t.imageCache.has(e.fileId),vl=(e,t,n)=>n.theme===Al.DARK&&zt(e)&&!Dl(e,t)&&t.imageCache.get(e.fileId)?.mimeType!==zr.svg,gi=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}},Xm=(e,t,n,o,i=1)=>{let r=(t?.opacity??100)*e.opacity/1e4*i;return(n.has(e.id)||o&&o.some(s=>s.id===e.id)||t&&n.has(t.id))&&(r*=zm/100),r},Wm=(e,t,n)=>{let r=gi(e),[s,a,l,c]=H(e,t),d=X(e)||Se(e)?Qt(s,l):e.width,u=X(e)||Se(e)?Qt(a,c):e.height,p=d*window.devicePixelRatio+r*2,m=u*window.devicePixelRatio+r*2,f=n.value;return(p*f>32767||m*f>32767)&&(f=Math.min(32767/p,32767/m)),p*m*f*f>16777216&&(f=Math.sqrt(16777216/(p*m))),p=Math.floor(p*f),m=Math.floor(m*f),{width:p,height:m,scale:f}},Ll=(e,t,n,o,i)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=gi(e),{width:l,height:c,scale:d}=Wm(e,t,n);if(!l||!c)return null;r.width=l,r.height=c;let u=-100,p=0;if(X(e)||Se(e)){let[g,x]=H(e,t);u=e.x>g?Qt(e.x,g)*window.devicePixelRatio*d:0,p=e.y>x?Qt(e.y,x)*window.devicePixelRatio*d:0,s.translate(u,p)}s.save(),s.translate(a*d,a*d),s.scale(window.devicePixelRatio*d,window.devicePixelRatio*d);let m=an.canvas(r);vl(e,o,i)&&(s.filter=Um),hi(e,m,s,o,i),s.restore();let f=W(e,t),E=document.createElement("canvas"),h=E.getContext("2d");if(_(e)&&f){let[g,x,y,b]=H(e,t),w=Math.max(Qt(g,y),Qt(x,b));E.width=w*window.devicePixelRatio*d+a*d*10,E.height=w*window.devicePixelRatio*d+a*d*10,h.translate(E.width/2,E.height/2),h.rotate(e.angle),h.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,I,M]=H(f,t);h.rotate(-e.angle);let D=(E.width-r.width)/2,T=(E.height-r.height)/2,F=E.width/2-(I-g)*window.devicePixelRatio*d-D-a*d,C=E.height/2-(M-x)*window.devicePixelRatio*d-T-a*d;h.translate(-F,-C),h.clearRect(-(f.width/2+mi)*window.devicePixelRatio*d,-(f.height/2+mi)*window.devicePixelRatio*d,(f.width+mi*2)*window.devicePixelRatio*d,(f.height+mi*2)*window.devicePixelRatio*d)}return{element:e,canvas:r,theme:i.theme,scale:d,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:xe(e)?e.crop:null}},Vb=14,Cl=typeof document<"u"?document.createElement("img"):{src:""};Cl.src=`data:${zr.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var Bl=typeof document<"u"?document.createElement("img"):{src:""};Bl.src=`data:${zr.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var jm=(e,t)=>{t.fillStyle="#E7E7E7",t.fillRect(0,0,e.width,e.height);let n=Math.min(e.width,e.height),o=Math.min(n,Math.min(n*.4,100));t.drawImage(e.status==="error"?Bl:Cl,e.width/2-o/2,e.height/2-o/2,o,o)},hi=(e,t,n,o,i)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(be.get(e));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",be.get(e).forEach(r=>{t.draw(r)});break}case"freedraw":{n.save(),n.fillStyle=e.strokeColor;let r=Vm(e),s=be.get(e);s&&t.draw(s),n.fillStyle=e.strokeColor,n.fill(r),n.restore();break}case"image":{let r=zt(e)?o.imageCache.get(e.fileId)?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,yt(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:c}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight};n.drawImage(r,s,a,l,c,0,0,e.width,e.height)}else jm(e,n);break}default:if(oe(e)){let r=_m(e.text),s=r&&!n.canvas.isConnected;s&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",r?"rtl":"ltr"),n.save(),n.font=Hm(e),n.fillStyle=e.strokeColor,n.textAlign=e.textAlign;let a=e.text.replace(/\r\n?/g,`
|
|
9
|
+
`)=>e.reduce((i,o)=>(ee(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as Or,distanceToLineSegment as kr,pointRotateRads as Rr}from"@excalidraw/math";import{ellipse as Em,ellipseDistanceFromPoint as gm}from"@excalidraw/math/ellipse";var Sn=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return xm(e,t,n);case"diamond":return wm(e,t,n);case"ellipse":return ym(e,t,n);case"line":case"arrow":case"freedraw":return bm(e,n)}},xm=(e,t,n)=>{let i=de(e,t),o=Rr(n,i,-e.angle),[r,s]=Vt(e);return Math.min(...r.map(a=>kr(o,a)),...s.map(a=>Or(a,o)).filter(a=>a!==null))},wm=(e,t,n)=>{let i=de(e,t),o=Rr(n,i,-e.angle),[r,s]=$t(e);return Math.min(...r.map(a=>kr(o,a)),...s.map(a=>Or(a,o)).filter(a=>a!==null))},ym=(e,t,n)=>{let i=de(e,t);return gm(Rr(n,i,-e.angle),Em(i,e.width/2,e.height/2))},bm=(e,t)=>{let[n,i]=oo(e);return Math.min(...n.map(o=>kr(t,o)),...i.map(o=>Or(o,t)))};var fo=e=>{if(e.type==="arrow")return!1;let t=!$a(e.backgroundColor)||dt(e)||no(e)||ee(e);return e.type==="line"?t&&bn(e.points):e.type==="freedraw"?t&&bn(e.points):t||xe(e)},Lm=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{let s=o?po(me(o.x-n,o.y-n),e,me(o.x+o.width+n,o.y+o.height+n)):!1,a=ae(t,i,!0);return!po(me(a[0]-n,a[1]-n),Ue(e,ut(a),-t.angle),me(a[2]+n,a[3]+n))&&!s?!1:(r||fo(t))&&Mt(e,t,i)||Va(e,t,i,n)||s},Bm=(e,t,n,i=0)=>{let[o,r,s,a]=ae(t,n);return o-=i,r-=i,s+=i,a+=i,po(me(o,r),e,me(s,a))},dy=(e,t)=>!Lm(e)&&!Cm(e.point,e.element,t)&&Bm(e.point,e.element,t),Cm=(e,t,n)=>{let i=V(t,n);if(!i)return!1;let o=Q(t)?{...i,...O.getBoundTextElementPosition(t,i,n)}:i;return Mt(e,o,n)},Gm=(e,[t,n],i,o=0)=>{let r=me(t,n),s=!K(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=ae(e,i);if(!Mn(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&K(m)){let p=ae(m,i);if(!Kt(r,p))return!1}}let c=qt(e,i,fi(de(e,i),r)),u=Sn(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},ho=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(Pm(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),Ce(s,!1)&&Gm(s,e,n,i?.(s))&&(o.push(s),!$a(s.backgroundColor)))break}return o},Dt=(e,t,n,i)=>{let o=ho(e,t,n,i);return!o||o.length===0?null:o.length===1?o[0]:o.sort((r,s)=>s.width**2+s.height**2-(r.width**2+r.height**2)).pop()},qt=(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(!Mn(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return km(e,t,n,i,o);case"diamond":return Rm(e,t,n,i,o);case"ellipse":return Fm(e,t,n,i);case"line":case"freedraw":case"arrow":return Om(e,n,o)}},Ka=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Eo(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(!Mn(a,l))continue;let d=Za(s,t);if(d.length>0){for(let c of d)n.push(Ue(c,i,o));if(r)return n}}return n},Qa=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=qa(s,t);if(a&&(n.push(Ue(a,i,o)),r))return n}return n},Om=(e,t,n=!1)=>{let[i,o]=oo(e),r=[];for(let s of i){let a=qa(s,t);if(a&&(r.push(a),n))return r}for(let s of o){let a=Eo(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(!Mn(a,l))continue;let d=Za(s,t);if(d.length>0&&(r.push(...d),n))return r}return r},km=(e,t,n,i=0,o=!1)=>{let r=de(e,t),s=Ue(n[0],r,-e.angle),a=Ue(n[1],r,-e.angle),l=fi(s,a),[d,c]=Vt(e,i),u=[];return Qa(d,l,u,r,e.angle,o),o&&u.length>0||Ka(c,l,u,r,e.angle,o),u},Rm=(e,t,n,i=0,o=!1)=>{let r=de(e,t),s=Ue(n[0],r,-e.angle),a=Ue(n[1],r,-e.angle),l=fi(s,a),[d,c]=$t(e,i),u=[];return Qa(d,l,u,r,e.angle,o),o&&u.length>0||Ka(c,l,u,r,e.angle,o),u},Fm=(e,t,n,i=0)=>{let o=de(e,t),r=Ue(n[0],o,-e.angle),s=Ue(n[1],o,-e.angle);return Dm(vm(o,e.width/2+i,e.height/2+i),fi(r,s)).map(a=>Ue(a,o,e.angle))},Va=(e,t,n,i=1)=>Sn(t,n,e)<=i,Mt=(e,t,n)=>{if((Q(t)||Ie(t))&&!bn(t.points))return!1;let[i,o,r,s]=ae(t,n);if(!po(me(i,o),e,me(r,s)))return!1;let a=me((i+r)/2,(o+s)/2),l=Im(Tm(Am(Mm(e,a,.1)),Math.max(t.width,t.height)*2),a),d=fi(e,l);return qt(t,n,d).filter((u,m,p)=>p.findIndex(f=>Sm(f,u))===m).length%2===1},Fr=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:m}=s,p=de(s,n);if(s.type==="diamond"){let[h,E,g,x,w,b,y,I]=kn(s);return[me(l+h,d+E-a),me(l+g+a,d+x),me(l+w,d+b+a),me(l+y-a,d+I)].map(A=>Ue(A,p,m))}if(s.type==="ellipse"){let h=l+c/2,E=d+u/2,g=c/2,x=u/2;return[me(h,E-x-a),me(h+g+a,E),me(h,E+x+a),me(h-g-a,E)].map(b=>Ue(b,p,m))}return[me(l-a,d-a),me(l+c+a,d-a),me(l+c+a,d+u+a),me(l-a,d+u+a)].map(h=>Ue(h,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Mt(s,t,n))};P();import{invariant as Ja,isDevEnv as Nm,isTestEnv as Hm}from"@excalidraw/common";import{pointFrom as Qt,pointFromVector as go,pointRotateRads as xo,pointScaleFromOrigin as wo,pointsEqual as zm,triangleIncludesPoint as Nr,vectorCross as Ge,vectorFromPoint as J,vectorScale as yo}from"@excalidraw/math";var fe=[1,0],we=[0,1],ke=[-1,0],We=[0,-1],Lt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?fe:t<=-o?ke:n>i?we:We},Oe=(e,t)=>Lt(J(e,t)),it=(e,t)=>Re(Oe(e,t)),pe=(e,t)=>e[0]===t[0]&&e[1]===t[1],Re=e=>pe(e,fe)||pe(e,ke),hy=e=>!Re(e),_m=(e,t,n)=>{let i=ut(t);(Nm()||Hm())&&(Ja(e.width>0&&e.height>0,"Diamond element has no width or height"),Ja(!zm(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=go(yo(J(xo(Qt(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=go(yo(J(xo(Qt(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=go(yo(J(xo(Qt(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=go(yo(J(xo(Qt(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Ge(J(n,r),J(r,s))<=0&&Ge(J(n,r),J(r,l))>0)return Oe(r,i);if(Ge(J(n,s),J(s,a))<=0&&Ge(J(n,s),J(s,r))>0)return Oe(s,i);if(Ge(J(n,a),J(a,l))<=0&&Ge(J(n,a),J(a,s))>0)return Oe(a,i);if(Ge(J(n,l),J(l,r))<=0&&Ge(J(n,l),J(l,a))>0)return Oe(l,i);if(Ge(J(n,i),J(r,i))<=0&&Ge(J(n,i),J(s,i))>0){let c=e.width>e.height?r:s;return Oe(c,i)}else if(Ge(J(n,i),J(s,i))<=0&&Ge(J(n,i),J(a,i))>0){let c=e.width>e.height?a:s;return Oe(c,i)}else if(Ge(J(n,i),J(a,i))<=0&&Ge(J(n,i),J(l,i))>0){let c=e.width>e.height?a:l;return Oe(c,i)}let d=e.width>e.height?r:l;return Oe(d,i)},hi=(e,t,n)=>{let o=ut(t);if(e.type==="diamond")return _m(e,t,n);let r=wo(Qt(t[0],t[1]),o,2),s=wo(Qt(t[2],t[1]),o,2),a=wo(Qt(t[0],t[3]),o,2),l=wo(Qt(t[2],t[3]),o,2);return Nr([r,s,o],n)?We:Nr([s,l,o],n)?fe:Nr([l,a,o],n)?we:ke},Hr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as rp,randomInteger as Zr,getUpdatedTimestamp as qr}from"@excalidraw/common";P();import{clamp as bo,pointDistance as Ur,pointFrom as j,pointScaleFromOrigin as Um,pointsEqual as gi,pointTranslate as _r,vector as mt,vectorCross as Po,vectorFromPoint as Wr,vectorScale as Wm}from"@excalidraw/math";import{BinaryHeap as Ym,invariant as Fn,isAnyTrue as jm,getSizeFromPoints as el,isDevEnv as Xm,arrayToMap as Vm}from"@excalidraw/common";var Yr=1,ne=40,$m=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>j(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=Oe(s,l[a-1]),c=Oe(l[a-1],l[a-2]);if(pe(d,c)){let u=n?.findIndex(p=>p.index===a-1)??-1,m=n?.findIndex(p=>p.index===a)??-1;m!==-1&&(n[m].start=j(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(p=>{p.index>a-1&&(p.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(Ur(l[a-2],l[a-1])<Yr){let d=n?.findIndex(m=>m.index===a-2)??-1,c=n?.findIndex(m=>m.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),o.splice(-2,2),n.forEach(m=>{m.index>a-2&&(m.index-=2)});let u=it(s,l[a-1]);return o.push(j(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?Ct(Vr($r(Xr(e,jr(e,t,o.map(s=>j(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(Xm()&&Fn(al(o),"Invalid elbow points with fixed segments"),Ct(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}},Zm=(e,t,n)=>{let i=t.map(M=>M.index),r=(e.fixedSegments?.map(M=>M.index)??[]).findIndex(M=>!i.includes(M));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,m=l?null:e.endBinding,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...w}=jr({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[j(0,0),j(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}=Ct(Vr($r(Xr(e,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...w})??[])),t,null,null);if(!b||b.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let y=[];if(a)for(let M=0;M<a.index;M++)y.push(j(e.x+e.points[M][0],e.y+e.points[M][1]));if(b.forEach(M=>{y.push(j(e.x+(a?a.end[0]:0)+M[0],e.y+(a?a.end[1]:0)+M[1]))}),l)for(let M=l.index;M<e.points.length;M++)y.push(j(e.x+e.points[M][0],e.y+e.points[M][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,S=t.map(M=>M.index>s?{...M,index:M.index-I+(b.length-1)}:M),A=y.flatMap((M,k)=>{let L=y[k-1],G=y[k+1];if(L&&G){let B=Oe(M,L),U=Oe(G,M);if(pe(B,U))return S.forEach(N=>{N.index>k&&(N.index-=1)}),[];if(pe(B,Hr(U)))return S.forEach(N=>{N.index>k&&(N.index+=1)}),[M,M]}return[M]});return Ct(A,S,!1,!1)},qm=(e,t,n,i,o,r)=>{let s=t.map((y,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==y.index||(y.start[0]!==e.fixedSegments[I].start[0]&&y.end[0]!==e.fixedSegments[I].end[0])!=(y.start[1]!==e.fixedSegments[I].start[1]&&y.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(y=>y!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(y=>y.index===1)??-1,l=e.fixedSegments?.findIndex(y=>y.index===e.points.length-1)??-1,d=Ur(t[s].start,t[s].end),c=d<ne+5;if(a===-1&&t[s].index===1&&o){let y=Re(n),S=(y?pe(n,fe):pe(n,we))?c?d/2:ne:c?-d/2:-ne;t[s].start=j(t[s].start[0]+(y?S:0),t[s].start[1]+(y?0:S))}if(l===-1&&t[s].index===e.points.length-1&&r){let y=Re(i),S=(y?pe(i,fe):pe(i,we))?c?d/2:ne:c?-d/2:-ne;t[s].end=j(t[s].end[0]+(y?S:0),t[s].end[1]+(y?0:S))}let u=t.map(y=>({...y,start:j(e.x+y.start[0],e.y+y.start[1]),end:j(e.x+y.end[0],e.y+y.end[1])})),m=e.points.map((y,I)=>j(e.x+y[0],e.y+y[1])),p=u[s].index-1,f=u[s].index,h=u[s].start,E=u[s].end,g=m[p-1]&&!gi(m[p],m[p-1])?it(m[p-1],m[p]):void 0,x=m[f+1]&&!gi(m[f],m[f+1])?it(m[f+1],m[f]):void 0;if(g!==void 0){let y=g?1:0;m[p-1][y]=h[y]}if(m[p]=h,m[f]=E,x!==void 0){let y=x?1:0;m[f+1][y]=E[y]}let w=u.findIndex(y=>y.index===p);if(w!==-1){let y=it(u[w].end,u[w].start)?1:0;u[w].start[y]=h[y],u[w].end=h}let b=u.findIndex(y=>y.index===f+1);if(b!==-1){let y=it(u[b].end,u[b].start)?1:0;u[b].end[y]=E[y],u[b].start=E}if(a===-1&&p===0){let y=o?Re(n):it(m[1],m[0]);m.unshift(j(y?h[0]:e.x+e.points[0][0],y?e.y+e.points[0][1]:h[1])),o&&m.unshift(j(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=o?2:1}if(l===-1&&f===e.points.length-1){let y=Re(i);m.push(j(y?E[0]:e.x+e.points[e.points.length-1][0],y?e.y+e.points[e.points.length-1][1]:E[1])),r&&m.push(j(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return Ct(m,u.map(y=>({...y,start:j(y.start[0]-e.x,y.start[1]-e.y),end:j(y.end[0]-e.x,y.end[1]-e.y)})),!1,!1)},Km=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((E,g)=>g===0?j(e.x+E[0],e.y+E[1]):g===t.length-1?j(e.x+E[0],e.y+E[1]):j(e.x+e.points[g][0],e.y+e.points[g][1])),m=n.map(E=>({...E,start:j(e.x+(E.start[0]-t[0][0]),e.y+(E.start[1]-t[0][1])),end:j(e.x+(E.end[0]-t[0][0]),e.y+(E.end[1]-t[0][1]))})),p=[],f=2+(d?1:0),h=2+(c?1:0);for(;p.length+f<u.length-h;)p.push(u[p.length+f]);{let E=u.at(d?2:1),g=u.at(d?3:2);if(!E||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=Re(i),w=Re(Lt(Wr(E,g)));if(a&&x===w){let b=x?pe(i,fe):pe(i,we);if(p.unshift(j(w?r[0]+(b?ne:-ne):g[0],w?g[1]:r[1]+(b?ne:-ne))),p.unshift(j(x?r[0]+(b?ne:-ne):r[0],x?r[1]:r[1]+(b?ne:-ne))),!d){d=!0;for(let y of m)y.index>1&&(y.index+=1)}}else if(p.unshift(j(w?r[0]:E[0],w?E[1]:r[1])),d){d=!1;for(let b of m)b.index>1&&(b.index-=1)}p.unshift(r)}{let E=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!E||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=Re(o),w=it(g,E);if(l&&x===w){let b=x?pe(o,fe):pe(o,we);p.push(j(w?s[0]+(b?ne:-ne):g[0],w?g[1]:s[1]+(b?ne:-ne))),p.push(j(x?s[0]+(b?ne:-ne):s[0],x?s[1]:s[1]+(b?ne:-ne))),c||(c=!0)}else p.push(j(w?s[0]:E[0],w?E[1]:s[1])),c&&(c=!1)}return p.push(s),Ct(p,m.map(({index:E})=>({index:E,start:p[E-1],end:p[E]})).map(E=>({...E,start:j(E.start[0]-r[0],E.start[1]-r[1]),end:j(E.end[0]-r[0],E.end[1]-r[1])})),d,c)},Jt=1e6,Nn=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};v.PROD||(Fn(!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)"),Fn(!e.fixedSegments||e.fixedSegments.map(y=>y.start[0]===y.end[0]||y.start[1]===y.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Fn(!n.fixedSegments||n.fixedSegments.map(y=>y.start[0]===y.end[0]||y.start[1]===y.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Fn(e.points.slice(1).map((y,I)=>y[0]===e.points[I][0]||y[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Fn(n.fixedSegments?.find(y=>y.index===1&&gi(y.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(y=>y.index===(n.points??e.points).length-1&&gi(y.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let o=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((y,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:y):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&So(d.elementId,t),m=c&&So(c.elementId,t),p=al(r);if(d&&!u&&p||c&&!m&&p||t.size===0&&p||Object.keys(l).length===0&&(u?.id!==d?.elementId||m?.id!==c?.elementId))return Ct(r.map(y=>j(e.x+y[0],e.y+y[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:w,...b}=jr({x:e.x,y:e.y,startBinding:d,endBinding:c,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,i);return t.size===0&&p?Ct(r.map(y=>j(e.x+y[0],e.y+y[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?$m(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((y,I)=>gi(y,e.points[I]??j(1/0,1/0)))&&p?{}:o.length===0?Ct(Vr($r(Xr(e,{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:w,...b})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?Zm(e,o,t):n.points?n.points&&n.fixedSegments?n:Km(e,r,o,f,h,E,g,x,w):qm(e,o,f,h,x,w)},jr=(e,t,n,i)=>{let o=_r(n[0],mt(e.x,e.y)),r=_r(n[n.length-1],mt(e.x,e.y)),s=null,a=null;if(i?.isDragging){let y=Array.from(t.values());s=ol(o,t,y,i?.zoom)||null,a=ol(r,t,y,i?.zoom)||null}else s=e.startBinding&&So(e.startBinding.elementId,t)||null,a=e.endBinding&&So(e.endBinding.elementId,t)||null;let l=nl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging),d=nl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging),c=il(l,d,s,o,t,i?.zoom),u=il(d,l,a,r,t,i?.zoom),m=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],p=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],f=s?qe(s,t,en(c,e.startArrowhead?Bt(s,{elbowed:!0})*6:Bt(s,{elbowed:!0})*2,1)):m,h=a?qe(a,t,en(u,e.endArrowhead?Bt(a,{elbowed:!0})*6:Bt(a,{elbowed:!0})*2,1)):p,E=Kt(l,a?qe(a,t,en(u,ne,ne)):p)||Kt(d,s?qe(s,t,en(c,ne,ne)):m),g=sl(E?[m,p]:[f,h]),x=ep(E?m:f,E?p:h,g,E?en(c,!s&&!a?0:ne,0):en(c,!s&&!a?0:ne-(e.startArrowhead?An*6:An*2),ne),E?en(u,!s&&!a?0:ne,0):en(u,!s&&!a?0:ne-(e.endArrowhead?An*6:An*2),ne),E,s&&qe(s,t),a&&qe(a,t)),w=tl(x[0],c,l),b=tl(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:w,startGlobalPoint:l,startHeading:c,endDonglePosition:b,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:E,startElementBounds:f,endElementBounds:h}},Xr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=tp(n,i||o,r,s||a,l,d),m=i&&Io(i,u),p=s&&Io(s,u),f=Io(a,u);f&&c&&(f.closed=!0);let h=Io(o,u);h&&e.startBinding&&(h.closed=!0);let E=m&&p&&(Kt(m.pos,n[1])||Kt(p.pos,n[0])),g=Qm(m||h,p||f,u,r||fe,l||fe,E?[]:n);if(g){let x=g.map(w=>[w.pos[0],w.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},en=(e,t,n)=>{switch(e){case We:return[t,n,n,n];case fe:return[n,t,n,n];case we:return[n,n,t,n]}return[n,n,n,t]},Qm=(e,t,n,i,o,r)=>{let s=zr(e.pos,t.pos),a=new Ym(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Jm(e,l);l.closed=!0;let d=ip(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=Um(u.pos,l.pos,.5);if(jm(...r.map(b=>Kt(m,b))))continue;let p=op(c),f=l.parent?Lt(Wr(l.pos,l.parent.pos)):i,h=Hr(f);if(pe(h,p)||rl(e.addr,u.addr)&&pe(p,i)||rl(t.addr,u.addr)&&pe(p,o))continue;let g=f!==p,x=l.g+zr(u.pos,l.pos)+(g?Math.pow(s,3):0),w=u.visited;if(!w||x<u.g){let b=np(u,t,p,o);u.visited=!0,u.parent=l,u.h=zr(t.pos,u.pos)+b*Math.pow(s,2),u.g=x,u.f=u.g+u.h,w?a.rescoreElement(u):a.push(u)}}}return null},Jm=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},zr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),ep=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,m,p]=i??[0,0,0,0],[f,h,E,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-p):(l[0]+d[2])/2:e[0]>t[0]?e[0]-p:n[0]-p,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+m):(l[3]+d[1])/2:e[3]<t[3]?e[3]+m:n[3]+m],w=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-f):(d[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+h):(d[2]+l[0])/2:t[2]<e[2]?t[2]+h:n[2]+h,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+E):(d[3]+l[1])/2:t[3]<e[3]?t[3]+E:n[3]+E],b=sl([x,w]);if(!r&&x[2]-x[0]+w[2]-w[0]>b[2]-b[0]+1e-11&&x[3]-x[1]+w[3]-w[1]>b[3]-b[1]+1e-11){let[y,I]=[(w[0]+w[2])/2,(w[1]+w[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let S=x[2]+(w[0]-x[2])/2,A=w[3]+(x[1]-w[3])/2;return Po(mt(e[2]-y,e[1]-I),mt(e[0]-y,e[3]-I))>0?[[x[0],x[1],S,x[3]],[S,w[1],w[2],w[3]]]:[[x[0],A,x[2],x[3]],[w[0],w[1],w[2],A]]}else if(e[2]<t[0]&&e[3]<t[1]){let S=x[2]+(w[0]-x[2])/2,A=x[3]+(w[1]-x[3])/2;return Po(mt(e[0]-y,e[1]-I),mt(e[2]-y,e[3]-I))>0?[[x[0],x[1],x[2],A],[w[0],A,w[2],w[3]]]:[[x[0],x[1],S,x[3]],[S,w[1],w[2],w[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let S=w[2]+(x[0]-w[2])/2,A=x[3]+(w[1]-x[3])/2;return Po(mt(e[2]-y,e[1]-I),mt(e[0]-y,e[3]-I))>0?[[S,x[1],x[2],x[3]],[w[0],w[1],S,w[3]]]:[[x[0],x[1],x[2],A],[w[0],A,w[2],w[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let S=w[2]+(x[0]-w[2])/2,A=w[3]+(x[1]-w[3])/2;return Po(mt(e[0]-y,e[1]-I),mt(e[2]-y,e[3]-I))>0?[[S,x[1],x[2],x[3]],[w[0],w[1],S,w[3]]]:[[x[0],A,x[2],x[3]],[w[0],w[1],w[2],A]]}}return[x,w]},tp=(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((m,p)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[p,u],pos:[m,c]})))}},tl=(e,t,n)=>{switch(t){case We:return j(n[0],e[1]);case fe:return j(e[2],n[1]);case we:return j(n[0],e[3])}return j(e[0],n[1])},np=(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 We:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case 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 We:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ke:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===We)switch(n){case fe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case We:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case we:return e.pos[0]===t.pos[0]?4:2;case ke:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===we)switch(n){case fe:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case We:return e.pos[0]===t.pos[0]?4:2;case we:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ke:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},ip=([e,t],n)=>[Ei([e,t-1],n),Ei([e+1,t],n),Ei([e,t+1],n),Ei([e-1,t],n)],Ei=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Io=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=Ei([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},sl=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]))],So=(e,t)=>{let n=t.get(e);return n&&Ce(n)?n:null},Ct=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>_r(a,Wm(Wr(e[0]),-1)));return(o<-Jt||o>Jt||r<-Jt||r>Jt||o+s[s.length-1][0]<-Jt||r+s[s.length-1][0]>Jt||o+s[s.length-1][1]<-Jt||r+s[s.length-1][1]>Jt)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...el(s)}),s=s.map(([a,l])=>j(bo(a,-1e6,1e6),bo(l,-1e6,1e6))),{points:s,x:bo(o,-1e6,1e6),y:bo(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...el(s),startIsSpecial:n,endIsSpecial:i}},Vr=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},$r=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Ur(i,t)>Yr}):e,op=e=>{switch(e){case 0:return We;case 1:return fe;case 2:return we}return ke},nl=(e,t,n,i,o,r,s)=>s?o&&r?Mo(e,o,t,r):i:o?tn(n||[0,0],o,r??Vm([o])):i,il=(e,t,n,i,o,r)=>ll(e,t,n,n&&qe(n,o,Array(4).fill(Sn(n,o,e))),i,o,r),ol=(e,t,n,i)=>Dt(e,n,t,o=>xi(i)),rl=(e,t)=>e[0]===t[0]&&e[1]===t[1],al=(e,t=Yr)=>e.slice(1).map((n,i)=>Math.abs(n[0]-e[i][0])<t||Math.abs(n[1]-e[i][1])<t).every(Boolean);var ye=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;Y(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...Nn({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...rp(r),...n});for(let l in n){let d=n[l];if(typeof d<"u"){if(e[l]===d&&(typeof d!="object"||d===null||l==="groupIds"||l==="scale"))continue;if(l==="scale"){let c=e[l],u=d;if(c[0]===u[0]&&c[1]===u[1])continue}else if(l==="points"){let c=e[l],u=d;if(c.length===u.length){let m=!1,p=c.length;for(;--p;){let f=c[p],h=u[p];if(f[0]!==h[0]||f[1]!==h[1]){m=!0;break}}if(!m)continue}}e[l]=d,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof a<"u"||typeof r<"u")&&Ye.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Zr(),e.updated=qr()),e},ge=(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??Zr(),updated:qr()}},dl=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Zr(),e.updated=qr(),e);var pl=10,An=5,Bt=(e,t)=>(t.elbowed?An:pl)+e.strokeWidth/2,xi=e=>{let t=Math.max(pl,15),n=e?.value&&e.value<1?e.value:1;return Kr(t/(n*1.5),t,t*2)},Vy=e=>!e[sp.CTRL_OR_CMD],Pi=e=>e.isBindingEnabled,fl=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=Qr(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0});if(cl(e,a,"start",o),cl(e,l,"end",o),a.focusPoint||l.focusPoint){let d=new Map;a.focusPoint&&d.set(0,{point:Un(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&d.set(e.points.length-1,{point:Un(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),O.movePoints(e,o,d)}return{start:a,end:l}},cl=(e,{mode:t,element:n,focusPoint:i},o,r)=>{t===null?Ke(e,o,r):t!==void 0&&Tn(e,n,t,o,r,i)},hl=(e,t,n,i,o)=>{ot(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;ot(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=O.getPointGlobalCoordinates(e,a,n),d=Dt(l,i,n,m=>xi(o)),c=d?{element:d,mode:"orbit",focusPoint:O.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},up=(e,t,n,i,o,r,s,a,l,d,c)=>{let u={mode:void 0},m={mode:void 0},p=e.points.length>2,f=O.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),h=Dt(f,i,n);if(o)return h?u={element:h,mode:"inside",focusPoint:f}:u={mode:null},{start:u,end:m};if(r){let E=l?.selectedLinearElement?.initialState.origin;if(h&&e.startBinding?.elementId===h.id){let g=q(h.x+h.width/2,h.y+h.height/2);return{start:p?{mode:void 0}:{mode:"inside",element:h,focusPoint:E??g},end:p?{mode:"orbit",element:h,focusPoint:f}:{mode:"inside",element:h,focusPoint:f}}}if(h&&e.startBinding){let g=e.startBinding;if(ho(f,i,n).find(w=>w.id===g.elementId)){let w=n.get(e.startBinding.elementId);return ot(w,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:w.id!==h.id?"orbit":"inside",element:w,focusPoint:E??q(e.x,e.y)},end:{mode:"orbit",element:h,focusPoint:f}}}}if(e.startBinding&&e.startBinding.elementId!==h?.id){let g=n.get(e.startBinding.elementId);ot(g,"Other element must be in the elements map");let w={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:g,focusPoint:c?de(g,n):E??q(e.x,e.y)},b=h&&Fr(g,h,n),y;if(h){let I=d==="inside"||d==="skip";y={mode:I&&!b?"inside":"orbit",element:h,focusPoint:f}}else y={mode:null};return{start:p?{mode:void 0}:w,end:y}}if(!e.startBinding)return h?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:h,focusPoint:f}:m={mode:null},{start:u,end:m}}ot(!1,"New arrow creation should not reach here")},ul=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=Dt(e,o,i),m=n?ho(e,o,i).some(E=>E.id===n.elementId):!1,p=n?i.get(n.elementId):null,f=m&&p?lp(p.backgroundColor):!1,h=u&&p&&Fr(p,u,i);return r==="inside"||r==="skip"?(l=u?{element:!m||!p||f?u:p,focusPoint:e,mode:"inside"}:{mode:null},d=a&&u&&u.id===n?.elementId?{mode:null}:d,{current:l,other:d}):u?u.id===t?.elementId&&t.mode==="inside"?{current:{mode:"inside",focusPoint:e,element:u},other:d}:n?n.elementId===u.id?n.mode==="orbit"?(l={element:u,mode:"orbit",focusPoint:e},d={mode:a?null:void 0},{current:l,other:c?{mode:void 0}:d}):(l={element:u,mode:"inside",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):(m&&p&&!f?l={element:p,mode:"inside",focusPoint:e}:l={element:u,mode:"orbit",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):(l={element:u,mode:"orbit",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):{current:{mode:null},other:d}},Qr=(e,t,n,i,o,r,s,a)=>ap("COMPLEX_BINDINGS")?pp(e,t,o,r,s,a):mp(e,t,n,i,o,r,s,a),mp=(e,t,n,i,o,r,s,a)=>{let d=e.points.length-1,c=t.has(0),u=t.has(d),m={mode:void 0},p={mode:void 0};if(ot(e.points.length>1,"Do not attempt to bind linear elements with a single point"),!c&&!u)return{start:m,end:p};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!Pi(s))return m=c?{mode:null}:m,p=u?{mode:null}:p,{start:m,end:p};if(Y(e))return hl(e,t,o,r,a?.zoom);let f=c?e.endBinding:e.startBinding,h=t.get(c?0:d)?.point;ot(h,`Local point must be defined for ${c?"start":"end"} dragging`);let E=O.getPointGlobalCoordinates(e,h,o),g=Dt(E,r,o,M=>xi(s.zoom)),x=g&&(a?.angleLocked?Mt(q(n,i),g,o):Mt(E,g,o)),w=f?o.get(f.elementId):void 0,b=f&&w&&tn(f.fixedPoint,w,o),y=w&&b&&Mt(b,w,o);if(f&&f.elementId===g?.id)return ot(!a?.newArrow||s.selectedLinearElement?.initialState.origin,"appState.selectedLinearElement.initialState.origin must be defined for new arrows"),{start:{mode:"inside",element:g,focusPoint:c?E:a?.newArrow?s.selectedLinearElement.initialState.origin:O.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:g,focusPoint:u?E:O.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:m,end:u?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:p};let I=g?x?{mode:"inside",element:g,focusPoint:E}:{mode:"orbit",element:g,focusPoint:Ar(e,E,g,c?"start":"end",o)||E}:{mode:null},S=O.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),A=w&&!y&&s.selectedLinearElement?.initialState.altFocusPoint?{mode:"orbit",element:w,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&w?{mode:"orbit",element:w,focusPoint:Ar(e,S,w,c?"end":"start",o)||S}:{mode:void 0};return{start:c?I:A,end:u?I:A}},pp=(e,t,n,i,o,r)=>{let s=o.bindMode||"orbit",a=0,l=e.points.length-1,d=t.has(a),c=t.has(l),u={mode:void 0},m={mode:void 0};if(ot(e.points.length>1,"Do not attempt to bind linear elements with a single point"),!d&&!c)return{start:u,end:m};if(d&&c)return{start:{mode:null},end:{mode:null}};if(!Pi(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(Y(e))return hl(e,t,n,i);if(r?.newArrow){let{start:p,end:f}=up(e,t,n,i,d,c,a,l,o,s,r?.shiftKey);return{start:p,end:f}}if(d){let p=t.get(a)?.point;ot(p,"Local point must be defined for start dragging");let f=O.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=ul(f,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:h,end:E}}if(c){let p=t.get(l)?.point;ot(p,"Local point must be defined for end dragging");let f=O.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=ul(f,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:E,end:h}}return{start:u,end:m}},$y=(e,t,n)=>{e.forEach(i=>{fl(i,new Map,1/0,1/0,t,n)})},Tn=(e,t,n,i,o,r)=>{let s=o.getNonDeletedElementsMap(),a;Y(e)?a={elementId:t.id,mode:"orbit",...wp(e,t,i,s)}:a={elementId:t.id,mode:n,...Do(e,t,i,s,r)},o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:a}),ml(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},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},je=(e,t,n)=>{if(!Ce(e))return;let{simultaneouslyUpdated:i}=n??{},o=hp(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(s=>{r.set(s.id,s)})),To(r,e,s=>{if(!H(s)||s.isDeleted||!fp(s,e))return;let a=s.startBinding?r.get(s.startBinding.elementId):null,l=s.endBinding?a?.id===s.endBinding.elementId?a:r.get(s.endBinding.elementId):null;if(o.has(s.id))return;let d=vo(r,s,(u,m)=>{if(u&&Ce(u)&&(m==="startBinding"||m==="endBinding")&&(e.id===s[m]?.elementId||e.id===s[m==="startBinding"?"endBinding":"startBinding"]?.elementId)){let p=Un(s,m,s[m],u,r);if(p)return[m==="startBinding"?0:s.points.length-1,{point:p}]}return null}).filter(u=>u!==null);O.movePoints(s,t,new Map(d),{moveMidPointsWithElement:!!a&&a?.id===l?.id});let c=V(s,r);c&&!c.isDeleted&&In(s,t,!1)})},Zy=(e,t,n,i)=>{H(e)?fl(e,new Map,1/0,1/0,t,n):je(e,t,{...i,changedElements:new Map([[e.id,e]])})},fp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,hp=e=>new Set((e||[]).map(t=>t.id)),ll=(e,t,n,i,o,r,s)=>{let a=Lt(_n(t,e));return!n||!i?a:Ep(o,n,r,s)?hi(n,i,e):Lt(_n(e,de(n,r)))},Ep=(e,t,n,i)=>{let o=Sn(t,n,e),r=xi(i);return o>r?null:o},Mo=(e,t,n,i,o)=>{let r=Y(e),s=O.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return s;let a=wr(t)&&r?El(e,t,i,s):s,l=o&&!r?o[1]:O.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),d=Bt(t,e),c=qe(t,i),u=ut(c),m=null;if(r){let p=Re(hi(t,c,s)),f=gp(e,t,i,a),h=q(p?u[0]:f[0],p?f[1]:u[1]),E=o??yi(h,Hn(zn(Ao(_n(f,h)),Math.max(t.width,t.height)*2),h));if(m=qt(t,i,E,d).sort(wi)[0],!m){let g=q(p?f[0]:u[0],p?u[1]:f[1]),x=yi(g,Hn(zn(Ao(_n(f,g)),Math.max(t.width,t.height)*2),g));m=qt(t,i,x,An).sort(wi)[0]}}else{let p=o;if(!p){let f=zn(Ao(_n(a,l)),Gt(a,l)+Math.max(t.width,t.height)+d*2);p=o??yi(Hn(f,l),Hn(zn(f,-1),l))}m=Gt(a,l)<1?a:qt(t,i,p,d).sort((f,h)=>wi(f,l)-wi(h,l))[0]}return!m||wi(a,m)<dp?a:m},El=(e,t,n,i)=>{let o=de(t,n),r=re(i,o,-t.angle),s=Bt(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?re(q(t.x-s,t.y),o,t.angle):re(q(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?re(q(t.x,t.y+t.height+s),o,t.angle):re(q(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?re(q(t.x+t.width,t.y+t.height+s),o,t.angle):re(q(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?re(q(t.x+t.width,t.y-s),o,t.angle):re(q(t.x+t.width+s,t.y),o,t.angle):i},gp=(e,t,n,i,o=.05)=>{let{x:r,y:s,width:a,height:l,angle:d}=t,c=de(t,n,-.1,-.1),u=re(i,c,-d),m=Bt(t,e),p=Kr(o*l,5,80),f=Kr(o*a,5,80);if(Gt(c,u)<m)return i;if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return re(q(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return re(q(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return re(q(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return re(q(c[0],s+l+m),c,d);if(t.type==="diamond"){let h=m,E=q(r+a/4-h,s+l/4-h),g=q(r+3*a/4+h,s+l/4-h),x=q(r+a/4-h,s+3*l/4+h),w=q(r+3*a/4+h,s+3*l/4+h);if(Gt(E,u)<Math.max(f,p))return re(E,c,d);if(Gt(g,u)<Math.max(f,p))return re(g,c,d);if(Gt(x,u)<Math.max(f,p))return re(x,c,d);if(Gt(w,u)<Math.max(f,p))return re(w,c,d)}return i},xp=(e,t)=>t.width**2+t.height**2-(e.width**2+e.height**2),Un=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||cp(e.points[e.points.length-1],q(0,0)))return null;let s=tn(Ii(n.fixedPoint),i,o),a=t==="startBinding"?0:e.points.length-1,l=Y(e),d=t==="startBinding"?e.endBinding:e.startBinding,c=d&&o.get(d.elementId),u=ae(i,o),m=c&&ae(c,o),p=c&&xp(i,c)<(t==="endBinding"?1:0),f=m&&Mn(u,m),h=!1;if(!f&&!l&&e.startBinding&&e.endBinding&&c&&e.points.length===2){let w=tn(e.startBinding.fixedPoint,t==="startBinding"?i:c,o),b=tn(e.endBinding.fixedPoint,t==="endBinding"?i:c,o),y=yi(w,b),I=qt(t==="endBinding"?i:c,o,y,0,!0),S=qt(t==="startBinding"?i:c,o,y,0,!0);I.length>0&&S.length>0&&(h=Gt(I[0],S[0])<40)}let E=(h||f)&&p,g=r;if(!l&&!g){let[w,b,y,I]=O.getElementAbsoluteCoords(e,o),S=q((w+y)/2,(b+I)/2),A=wr(i)?El(e,i,o,s):s,M=re(q(e.x+e.points[a===0?1:e.points.length-2][0],e.y+e.points[a===0?1:e.points.length-2][1]),S,e.angle),k=Bt(i,e),L=zn(Ao(_n(A,M)),Gt(A,M)+Math.max(i.width,i.height)+k*2);g=yi(Hn(L,M),Hn(zn(L,-1),M))}let x=n.mode==="orbit"&&i?E?s:Mo({...e,points:[a===0?O.createPointAt(e,o,s[0],s[1],null):e.points[0],...e.points.slice(1,-1),a===e.points.length-1?O.createPointAt(e,o,s[0],s[1],null):e.points[e.points.length-1]]},i,a===0?"start":"end",o,g):s;return O.createPointAt(e,o,x[0],x[1],null)},wp=(e,t,n,i)=>{let o=[t.x,t.y,t.x+t.width,t.y+t.height],r=Mo(e,t,n,i),s=q(o[0]+(o[2]-o[0])/2,o[1]+(o[3]-o[1])/2),a=re(r,s,-t.angle);return{fixedPoint:Ii([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},Do=(e,t,n,i,o)=>{let r=o||O.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=q(t.x+t.width/2,t.y+t.height/2),a=re(r,s,-t.angle),l=(a[0]-t.x)/t.width,d=(a[1]-t.y)/t.height;return{fixedPoint:Ii([l,d])}},gl=(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})}Y(i)&&Object.assign(i,Nn(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},qy=(e,t)=>{let n=ml(e);for(let i of t)nn.unbindAffected(n,i,(o,r)=>ye(o,n,r)),on.unbindAffected(n,i,(o,r)=>ye(o,n,r))},bi=(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},xl=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),To=(e,t,n)=>{Ce(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},vo=(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(H(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},nn=class{static unbindAffected(t,n,i){n&&vo(t,n,o=>{!o||o.isDeleted||To(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:bi(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||vo(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(H(n)&&i(o,{boundElements:bi(o.boundElements,new Set,new Array(n))}),ee(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:bi(o.boundElements,new Set,new Array(n))}))))})}},on=class{static unbindAffected(t,n,i){n&&To(t,n,o=>{!o||o.isDeleted||vo(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||To(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:bi(n.boundElements,new Set([s]))});return}ee(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:bi(n.boundElements,new Set([o.id]))})))})}},tn=(e,t,n)=>{let[i,o]=Ii(e);return re(q(t.x+t.width*i,t.y+t.height*o),de(t,n),t.angle)},yp=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?tn(e.startBinding.fixedPoint,n,t):q(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?tn(e.endBinding.fixedPoint,i,t):q(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},wl=(e,t)=>{let[n,i]=yp(e,t);return[O.pointFromAbsoluteCoords(e,n,t),O.pointFromAbsoluteCoords(e,i,t)]},Ii=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,bp=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",Pp={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"}]},Ip=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}}),Sp=(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=Pp[t],d=Ip(l);for(let m of d)if(m.start<=m.end){if(a>=m.start&&a<=m.end)return m.side}else if(a>=m.start||a<=m.end)return m.side;let c=1/0,u=l[0].side;for(let m of l){let p=Math.abs(a-m.centerAngle);p>180&&(p=360-p),p<c&&(c=p,u=m.side)}return u},Ky=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!Ce(n))return null;let i=de(n,t),o=bp(n),r=Sp(Ii(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=$t(n),[d,c,u,m]=a,p,f;switch(r){case"left":{if(l.length>=3){let E=l[2][1];p=E[0]-s,f=E[1]}else{let h=Me(c[1],u[0]);p=h[0]-s,f=h[1]}break}case"right":{if(l.length>=1){let E=l[0][1];p=E[0]+s,f=E[1]}else{let h=Me(m[1],d[0]);p=h[0]+s,f=h[1]}break}case"top":{if(l.length>=4){let E=l[3][1];p=E[0],f=E[1]-s}else{let h=Me(u[1],m[0]);p=h[0],f=h[1]-s}break}case"bottom":{if(l.length>=2){let E=l[1][1];p=E[0],f=E[1]+s}else{let h=Me(d[1],c[0]);p=h[0],f=h[1]+s}break}case"top-right":{let h=Me(m[0],m[1]);p=h[0]+s*.707,f=h[1]-s*.707;break}case"bottom-right":{let h=Me(d[0],d[1]);p=h[0]+s*.707,f=h[1]+s*.707;break}case"bottom-left":{let h=Me(c[0],c[1]);p=h[0]-s*.707,f=h[1]+s*.707;break}case"top-left":{let h=Me(u[0],u[1]);p=h[0]-s*.707,f=h[1]-s*.707;break}default:return null}return re(q(p,f),i,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,m;switch(r){case"top":{u=a,m=l-c-s;break}case"right":{u=a+d+s,m=l;break}case"bottom":{u=a,m=l+c+s;break}case"left":{u=a-d-s,m=l;break}case"top-right":{let p=-Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f+s*.707,m=l+h-s*.707;break}case"bottom-right":{let p=Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f+s*.707,m=l+h+s*.707;break}case"bottom-left":{let p=3*Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f-s*.707,m=l+h+s*.707;break}case"top-left":{let p=-3*Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f-s*.707,m=l+h-s*.707;break}default:return null}return re(q(u,m),i,n.angle)}if(li(n)){let[a,l]=Vt(n),[d,c,u,m]=a,p,f;switch(r){case"top":{let h=Me(d[0],d[1]);p=h[0],f=h[1]-s;break}case"right":{let h=Me(c[0],c[1]);p=h[0]+s,f=h[1];break}case"bottom":{let h=Me(u[0],u[1]);p=h[0],f=h[1]+s;break}case"left":{let h=Me(m[0],m[1]);p=h[0]-s,f=h[1];break}case"top-left":{if(l.length>=1){let h=l[0],E=h[0],g=h[3],x=Me(E,g);p=x[0]-s*.707,f=x[1]-s*.707}else p=n.x-s,f=n.y-s;break}case"top-right":{if(l.length>=2){let h=l[1],E=h[0],g=h[3],x=Me(E,g);p=x[0]+s*.707,f=x[1]-s*.707}else p=n.x+n.width+s,f=n.y-s;break}case"bottom-right":{if(l.length>=3){let h=l[2],E=h[0],g=h[3],x=Me(E,g);p=x[0]+s*.707,f=x[1]+s*.707}else p=n.x+n.width+s,f=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let h=l[3],E=h[0],g=h[3],x=Me(E,g);p=x[0]-s*.707,f=x[1]+s*.707}else p=n.x-s,f=n.y+n.height+s;break}default:return null}return re(q(p,f),i,n.angle)}return null},Me=(e,t)=>q((e[0]+t[0])/2,(e[1]+t[1])/2);var Jr=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>C(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},O=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,i=!1){this.elementId=t.id,bl(t.points[0],C(0,0))||(console.error("Linear element is not normalized",Error().stack),ye(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.elbowed=Y(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,m]=X(n.selectionElement,o),f=e.getPointsGlobalCoordinates(l,o).reduce((h,E,g)=>((E[0]>=d&&E[0]<=u&&E[1]>=c&&E[1]<=m||t.shiftKey&&s?.includes(g))&&h.push(g),h),[]).filter(h=>!(Y(l)&&h!==0&&h!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:f.length?f:null}})}static handlePointerMove(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);Te(d,"Element being dragged must exist in the scene"),Te(d.points.length>1,"Element must have at least 2 points");let c=d.points.length-1,u=d.points[c],m=d.points[c-1],p=r.customLineAngle??vl(m,d.points[c]),f=0,h=0;if(Si(t)){let[y,I]=e._getShiftLockedDelta(d,s,m,C(i,o),t[vn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),S=C(y+m[0],I+m[1]);f=S[0]-u[0],h=S[1]-u[1]}else{let y=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[vn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());f=y[0]-u[0],h=y[1]-u[1]}let E=null,{positions:g,updates:x}=Tl([c],f,h,i,o,s,d,a,n,Si(t),t.altKey);if(e.movePoints(d,n.scene,g,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement}),Be(d,!1)&&Pi(n.state)&&(E=x?.suggestedBinding??null),Be(d)&&Ml(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!E||Dp(n.state.suggestedBinding??[],E)))return null;let w=Be(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:p,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&w&&x?.suggestedBinding?.id!==w.id?Al(d,C(d.x,d.y),w,"start",s):r.initialState.altFocusPoint}},suggestedBinding:E}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);Te(p,"Element being dragged must exist in the scene"),Te(p.points.length>1,"Element must have at least 2 points"),Te(u,"There must be selected points in order to drag them"),l&&u.some((T,$)=>T>0&&T!==p.points.length-1?(u[$]=p.points.length-1,m=p.points.length-1,!0):!1),Te(m>-1&&u.includes(m)&&p.points[m],`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${p.points.length-1}) lastClickedPoint(${m})`);let f=p.points[m],h=p.points[m===0?1:m-1],E=u.length===1,g=r.customLineAngle??vl(h,p.points[m]),x=u.includes(0),w=u.includes(p.points.length-1),b=0,y=0;if(Si(t)&&E){let[T,$]=e._getShiftLockedDelta(p,s,h,C(i,o),t[vn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),g),Z=C(T+h[0],$+h[1]);b=Z[0]-f[0],y=Z[1]-f[1]}else{let T=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[vn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());b=T[0]-f[0],y=T[1]-f[1]}let I=null,{positions:S,updates:A}=Tl(u,b,y,i,o,s,p,a,n,Si(t)&&E,t.altKey);e.movePoints(p,n.scene,S,{startBinding:A?.startBinding,endBinding:A?.endBinding,moveMidPointsWithElement:A?.moveMidPointsWithElement}),Be(p,!1)&&Pi(n.state)&&(x||w)&&(I=A?.suggestedBinding??null),Be(p)&&x!==w&&Ml(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),V(p,s)&&In(p,n.scene,!1);let k=l?w?[p.points.length-1]:[0]:u,L=l?k[0]:m,G=!x&&!w?e.getPointGlobalCoordinates(p,f,s):null,B=L,U=Be(p)&&p.startBinding&&s.get(p.startBinding.elementId),N=Be(p)&&p.endBinding&&s.get(p.endBinding.elementId),W=w&&U&&A?.suggestedBinding?.id!==U.id?U:x&&N&&A?.suggestedBinding?.id!==N.id?N:null;return{selectedLinearElement:{...r,selectedPointsIndices:k,initialState:{...r.initialState,lastClickedPoint:L,altFocusPoint:!r.initialState.altFocusPoint&&Be(p)&&W?Al(p,C(p.x,p.y),W,"start",s):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:G,hoverPointIndex:B,isDragging:!0,customLineAngle:g},suggestedBinding:I}}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),{elementId:s,selectedPointsIndices:a,isDragging:l,initialState:d}=n,c=e.getElement(s,r);if(!c)return n;if(l&&a)for(let u of a)(u===0||u===c.points.length-1)&&Lp(c.points,i.zoom.value)&&(Pt(c)&&o.mutateElement(c,{...Dl(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,pointerOffset:{x:0,y:0},customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1}}}static getEditorMidPoints=(t,n,i)=>{let o=V(t,n);if(!Y(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(!Y(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!Y(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&rn(C(c[0],c[1]),C(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&rn(m[u],C(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r){if(Y(t))return o>=0&&o<t.points.length?rn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=rn(n,i);if(t.points.length>2&&t.roundness){let[a,l]=Sl(t);Te(a.length===0&&l.length>0,"Only linears built out of curves are supported"),Te(a.length+l.length>=o,"Invalid segment index while calculating mid point"),s=Ap(l[o])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(Y(t)){Te(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=yl(t.points[n-1],t.points[n]);return C(t.x+r[0],t.y+r[1])}let[i,o]=Sl(t);if(Te(i.length===0&&o.length>0||i.length>0&&o.length===0,"Only linears built out of either segments or curves are supported"),Te(i.length+o.length>=n,"Invalid segment index while calculating mid point"),i.length){let r=i[n-1];return yl(r[0],r[1])}if(o.length){let r=o[n-1];return Tp(r,.5)}Te(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let m=e.getSegmentMidpointHitCoords(r,o,a,l),p=C(o.x,o.y),f=null;if(m)f=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(u,{points:[...u.points,e.createPointAt(u,l,o.x,o.y,t[vn.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:p,segmentMidpoint:{value:m,index:f,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let h=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y);(h>=0||m)&&(d.hitElement=u);let[E,g,x,w]=X(u,l),b=(E+x)/2,y=(g+w)/2,I=h>-1&&Ae(C(u.x+u.points[h][0],u.y+u.points[h][1]),C(b,y),u.angle),S=h>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(h)?Bp([...r.selectedPointsIndices||[],h]):[h]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:h,origin:p,segmentMidpoint:{value:m,index:f,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:S,pointerOffset:I?{x:o.x-I[0],y:o.y-I[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:bl(t,n)}static handlePointerMoveInEditMode(t,n,i,o){let r=o.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=o.scene.getNonDeletedElementsMap(),d=e.getElement(s,l);if(!d)return r.selectedLinearElement;let{points:c}=d,u=c[c.length-1];if(!t.altKey)return u===a&&e.deletePoints(d,o,[c.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let m;if(Si(t)&&c.length>=2){let p=c[c.length-2],[f,h]=e._getShiftLockedDelta(d,l,p,C(n,i),t[vn.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=C(f+p[0],h+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[vn.CTRL_OR_CMD]||Y(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:m}]])):e.addPoints(d,o.scene,[m]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=X(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Ae(C(c+n[0],u+n[1]),C(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=X(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return Ae(C(c+d[0],u+d[1]),C(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=X(t,i),a=C(r,s),l=t.points[o],{x:d,y:c}=t;return l?Ae(C(d+l[0],c+l[1]),a,t.angle):Ae(C(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(Y(t))return C(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=X(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=Ae(C(n[0],n[1]),C(l,d),-t.angle);return C(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(rn(C(o,r),C(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]=X(t,n),u=(a+d)/2,m=(l+c)/2,[p,f]=Ae(C(s[0],s[1]),C(u,m),-t.angle);return C(p-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=Jr(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){Te(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);Te(s,"The linear element does not exist in the provided Scene"),Te(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((m,p,f)=>{if(++c,m.push(p),o.includes(f)){let E=a[f+1];E||(d=!0),m.push(E?C((p[0]+E[0])/2,(p[1]+E[1])/2):C(p[0],p[1])),l.push(c+1),++c}return m},[]);if(n.mutateElement(s,{points:u}),d){let m=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:C(m[0]+30,m[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!i.includes(u));Pt(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=C(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=Jr({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];Pt(t)&&t.polygon&&(o[0]=C(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=Jr({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o){let{points:r}=t;if(Pt(t)&&t.polygon){let c=i.get(0),u=i.get(r.length-1);c?i.set(r.length-1,{point:C(c.point[0],c.point[1]),isDragging:c.isDragging}):u&&i.set(0,{point:C(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=i.get(0)?.point??C(0,0),[a,l]=s,d=Y(t)?[i.get(0)?.point??r[0],i.get(r.length-1)?.point??r[r.length-1]]:r.map((c,u)=>{let m=i.get(u)?.point??c;return o?.moveMidPointsWithElement&&u!==0&&u!==r.length-1&&!i.has(u)?m:C(m[0]-a,m[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&&Y(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=rn(a,C(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<vp/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&&!Y(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(Y(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})}else{let l=es(t,i),d=es(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,m=(d[0]+d[2])/2,p=(d[1]+d[3])/2,f=m-c,h=p-u,E=Ae(C(o,r),C(f,h),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+E[0],y:t.y+E[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(Y(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=Il(o[0],o[1],r),{width:c,height:u}=Ll(a[0],a[1],l,d,s);return Ae(C(c,u),C(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&ye(n,i,{isDeleted:!0});let r=0,s=0;if(t.points.length%2===1){let a=Math.floor(t.points.length/2),l=e.getPointGlobalCoordinates(t,t.points[a],i);r=l[0]-n.width/2,s=l[1]-n.height/2}else{let a=t.points.length/2-1,l=e.getSegmentMidPoint(t,a+1);r=l[0]-n.width/2,s=l[1]-n.height/2}return{x:r,y:s}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:m}=e.getBoundTextElementPosition(t,o,n),p=u+o.width,f=m+o.height,h=C(d,c),E=Ae(C(r,s),h,t.angle),g=Ae(C(a,s),h,t.angle),x=Ae(C(u,m),h,-t.angle),w=Ae(C(p,m),h,-t.angle),b=Ae(C(u,f),h,-t.angle),y=Ae(C(p,f),h,-t.angle);return E[0]<g[0]&&E[1]>=g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(w[0],y[0])),s=Math.min(s,x[1]),l=Math.max(l,y[1])):E[0]>=g[0]&&E[1]>g[1]?(r=Math.min(r,y[0]),a=Math.max(a,Math.max(x[0],w[0])),s=Math.min(s,b[1]),l=Math.max(l,w[1])):E[0]>=g[0]?(r=Math.min(r,w[0]),a=Math.max(a,b[0]),s=Math.min(s,y[1]),l=Math.max(l,x[1])):E[1]<=g[1]&&(r=Math.min(r,Math.min(w[0],x[0])),a=Math.max(a,y[0]),s=Math.min(s,w[1]),l=Math.max(l,b[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=Ye.generateElementShape(t,null),r=yt(o[0]),[s,a,l,d]=Ai(r),c=s+t.x,u=a+t.y,m=l+t.x,p=d+t.y,f=(c+m)/2,h=(u+p)/2,E=i&&V(t,n);return E?e.getMinMaxXYWithBoundText(t,n,[c,u,m,p],E):[c,u,m,p,f,h]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!Y(a))return t;if(n&&n>0&&n<a.points.length){let l=Re(Lt(Mp(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,f)=>(p[f.index]=f,p),{});d[n]={index:n,start:C(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:C(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((p,f)=>p.index-f.index),u=c.map(p=>p.index).reduce((p,f)=>f<n?p+1:p,0);r.mutateElement(a,{fixedSegments:c});let m=C(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:m,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:m}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},Bp=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},Tl=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=new Map(e.map(W=>[W,{point:C(s.points[W][0]+t,s.points[W][1]+n),isDragging:!0}]));if(!H(s))return{positions:u};let m=e.includes(0),p=e.includes(s.points.length-1),{start:f,end:h}=Qr(s,u,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c});if(Y(s))return{positions:u,updates:{suggestedBinding:m?f.element:p?h.element:null}};if(m===p)return{positions:u};let E={suggestedBinding:null};f.mode===null?E.startBinding=null:f.mode?(E.startBinding={elementId:f.element.id,mode:f.mode,...Do(s,f.element,"start",r,f.focusPoint)},m&&(E.startBinding.mode==="orbit"||!Mi("COMPLEX_BINDINGS"))&&(E.suggestedBinding=f.element)):m&&(E.suggestedBinding=l.state.suggestedBinding),h.mode===null?E.endBinding=null:h.mode?(E.endBinding={elementId:h.element.id,mode:h.mode,...Do(s,h.element,"end",r,h.focusPoint)},p&&(E.endBinding.mode==="orbit"||!Mi("COMPLEX_BINDINGS"))&&(E.suggestedBinding=h.element)):p&&(E.suggestedBinding=l.state.suggestedBinding);let g=m?C(s.points[0][0]+t,s.points[0][1]+n):s.points[0],x=p?C(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],w={...s,points:[g,...s.points.slice(1,-1),x],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},b=f.focusPoint&&h.focusPoint?Pl(f.focusPoint,h.focusPoint):void 0,y=f.focusPoint&&h.focusPoint?Pl(h.focusPoint,f.focusPoint):void 0,I=s.endBinding&&w.startBinding&&m&&w.startBinding.elementId===s.endBinding.elementId,S=s.startBinding&&w.endBinding&&p&&s.startBinding.elementId===w.endBinding.elementId,A=w.endBinding?h.element??r.get(w.endBinding.elementId):null,M=I?w.points[w.points.length-1]:S&&l.state.bindMode!=="inside"&&Mi("COMPLEX_BINDINGS")?w.points[0]:A&&Un(s,"endBinding",w.endBinding,A,r,y)||w.points[w.points.length-1];w.points[w.points.length-1]=M;let k=w.startBinding?f.element??r.get(w.startBinding.elementId):null,L=S&&Mi("COMPLEX_BINDINGS")?w.points[0]:I&&l.state.bindMode!=="inside"&&Mi("COMPLEX_BINDINGS")?w.points[w.points.length-1]:k&&Un(s,"startBinding",w.startBinding,k,r,b)||w.points[0],G=rn(M,w.points[w.points.length-1])!==0,B=rn(L,w.points[0])!==0,U=new Set(e);k&&B&&U.add(0),A&&G&&U.add(s.points.length-1);let N=Array.from(U);return{updates:E.startBinding||E.suggestedBinding?{startBinding:E.startBinding,suggestedBinding:E.suggestedBinding}:void 0,positions:new Map(N.map(W=>[W,W===0?{point:L,isDragging:!0}:W===s.points.length-1?{point:M,isDragging:!0}:u.get(W)]))}},vl=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);P();import{arrayToMap as ft}from"@excalidraw/common";import{isPointWithinBounds as Jp,pointFrom as rs}from"@excalidraw/math";P();import{vectorCross as Ol,vectorFromPoint as Lo}from"@excalidraw/math";function Bl(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 Cp(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var Gp=1e-6;function Cl(e,t){let n=Lo(e[1],e[0]),i=Lo(t,e[0]),o=Ol(n,i);return Math.abs(o)<Gp}function ts(e,t){let n=Lo(e[1],e[0]),i=Lo(t,e[0]);return Ol(n,i)<0}function Gl(e,t){return Cl(e,t[0])||Cl(e,t[1])||(ts(e,t[0])?!ts(e,t[1]):ts(e,t[1]))}function kl(e,t){return Cp(Bl(e),Bl(t))&&Gl(e,t)&&Gl(t,e)}P();import{arrayToMap as Op}from"@excalidraw/common";import{getElementBounds as kp}from"@excalidraw/element";import{isArrowElement as Rp,isExcalidrawElement as Fp,isFreeDrawElement as Np,isLinearElement as Hp,isTextElement as zp}from"@excalidraw/element";import{rangeIncludesValue as Bo,pointFrom as Ot,pointRotateRads as _p,rangeInclusive as Co}from"@excalidraw/math";var Up=e=>e.type==="diamond"?[Ot(e.width/2,0),Ot(e.width,e.height/2),Ot(e.width/2,e.height),Ot(0,e.height/2)]:[Ot(0,0),Ot(0+e.width,0),Ot(0+e.width,e.height),Ot(0,e.height)],Wp=e=>Hp(e)||Np(e)?e.points:Up(e),Rl=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},Nl=e=>{let t=Wp(e),{cx:n,cy:i}=Rl(t),o=Ot(n,i),r=t.map(c=>_p(c,o,e.angle)),{minX:s,minY:a,maxX:l,maxY:d}=Rl(r);return[s+e.x,a+e.y,l+e.x,d+e.y]},Fl=(e,t,n=!1)=>{let i=Nl(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},Yp=(e,t)=>{let n=Nl(e);return(Bo(n[0],Co(t[0],t[2]))||Bo(t[0],Co(n[0],n[2])))&&(Bo(n[1],Co(t[1],t[3]))||Bo(t[1],Co(n[1],n[3])))},Hl=({elements:e,bounds:t,type:n,errorMargin:i=0})=>{Fp(t)&&(t=kp(t,Op(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"?Yp(s,o):n==="inside"?Fl(s,o):Fl(s,o,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);zp(s)&&s.containerId&&r.add(s.containerId),Rp(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 qp,isShallowEqual as Kp}from"@excalidraw/common";P();var jp=(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}}},zl=function(){let e=null,t=null,n=null,i=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let d={};for(let m of r){let p=m.groupIds;if(a.editingGroupId){let f=p.indexOf(a.editingGroupId);f>-1&&(p=p.slice(0,f))}if(p.length>0){let f=p[p.length-1];d[f]=!0}}let c={},u=s.reduce((m,p)=>{if(p.isDeleted)return m;let f=p.groupIds.find(h=>d[h]);return f&&(m[p.id]=!0,Array.isArray(c[f])?c[f].push(p.id):c[f]=[p.id]),m},{});for(let m of Object.keys(c))c[m].length<2&&d[m]&&(d[m]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:ns({...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:ns(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),Xp=(e,t)=>is(e,t)!=null,is=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Vp=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),_l=(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,...jp(r,n,e)}}}return n.selectedGroupIds},Tb=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),$p=(e,t)=>e.groupIds.includes(t),ve=(e,t)=>{let n=[];for(let i of e.values())$p(i,t)&&n.push(i);return n},Zp=(e,t)=>e.groupIds.find(n=>t[n]),vb=(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},Db=(e,t)=>e.filter(n=>!t[n]),Lb=(e,t)=>{let n=new Map;return e.forEach(i=>{let o=i.groupIds.length===0?i.id:i.groupIds[i.groupIds.length-1],r=n.get(o)||[],s=V(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},Ul=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,jl=(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},Go=(e,t,n)=>{let i=Vp(n),o=e.filter(u=>!ce(u)),r=new Map,s=new Map,a=u=>{let m=s.get(u.id)||[],p=V(u,t);p&&m.push(p),s.set(u.id,[...m,u])},l=(u,m)=>{let p=r.get(m)||[],f=V(u,t);f&&p.push(f),r.set(m,[...p,u])},d=(u,m)=>{let p=u.groupIds.indexOf(m,0);return u.groupIds.slice(0,p).length>0?l(u,u.groupIds[p-1]):a(u)},c=e.every(u=>Xp(n,u));return o.forEach(u=>{let m=Zp(u,n.selectedGroupIds);m?i.length===1&&c?d(u,m):l(u,m):a(u)}),Array.from(r.values()).concat(Array.from(s.values()))};var Xl=e=>{let t=new Set;return e.forEach(n=>{K(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},os=(e,t,n,i=!0)=>{let[o,r,s,a]=X(t,n),l=e.filter(d=>{let[c,u,m,p]=ae(d,n),f=kt(d,n);if(f){let[h,E,g,x]=ae(f,n);c=Math.max(h,c),u=Math.max(E,u),m=Math.min(g,m),p=Math.min(x,p)}return d.locked===!1&&d.type!=="selection"&&!ce(d)&&o<=c&&r<=u&&s>=m&&a>=p});return l=i?Xl(l):l,l=l.filter(d=>{let c=kt(d,n);return c?sn(d,c,n):!0}),l},zb=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=Vl(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},_b=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=>{K(s)&&an(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}),ns=(e,t)=>Kp(t.selectedElementIds,e)?t.selectedElementIds:e,Qp=(e,t)=>{let n=e.filter(Q);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 O(i,qp(t))}return null},Wb=(e,t,n)=>({selectedLinearElement:Qp(e,t),...zl({editingGroupId:n.editingGroupId,selectedElementIds:Xl(e).reduce((i,o)=>(ce(o)||(i[o.id]=!0),i),{})},t,n,null)});var $l=(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&&ye(a,i,{frameId:s??null})}};function Wn(e,t,n){let i=ss(t,n),o=ss(e,n);return i.some(s=>o.some(a=>kl(s,a)))}var Zl=(e,t,n)=>Oo(os(e,t,n,!1)).filter(i=>!K(i)&&!i.frameId||i.frameId===t.id),as=(e,t,n)=>os([t],e,n).some(i=>i.id===t.id),n0=(e,t)=>{let n=ft(e);return e.filter(i=>Wn(i,t,n))},ln=(e,t,n)=>{let[i,o,r,s]=X(t,n),[a,l,d,c]=De(e);return i<=a&&o<=l&&r>=d&&s>=c},sn=(e,t,n)=>ln([e],t,n)||Wn(e,t,n)||as(e,t,n),i0=(e,t,n)=>{let[i,o,r,s]=X(t,n);return Jp(rs(i,o),rs(e.x,e.y),rs(r,s))},o0=(e,t,n)=>{let i=ft(e),o=t.flatMap(r=>ve(e,r));return o.length===0?!0:!!o.find(r=>ln([r],n,i)||Wn(r,n,i))},r0=(e,t,n)=>{let i=ft(e),o=t.flatMap(r=>ve(e,r));return o.length===0?!0:o.find(r=>ln([r],n,i)||Wn(r,n,i))===void 0},s0=e=>{let t=new Map;for(let n of e){let i=K(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,an(e,i))}return t},an=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},ef=e=>e.filter(t=>K(t)),a0=e=>{let t=ft(ef(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},l0=(e,t,n,i)=>{let o=an(e,t.id),r=new Set(o),s=new Set([...Zl(e,t,i),...o.filter(m=>as(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(!Wn(m,t,i))m.groupIds.length===0&&r.delete(m);else if(m.groupIds.length>0)for(let p of m.groupIds)l.add(p);for(let m of a)if(m.groupIds.length>0){let p=!0;for(let f of m.groupIds)l.has(f)&&(p=!1);p&&r.delete(m)}let d=Array.from(s).filter(m=>m.groupIds.length===0);for(let m of d)r.add(m);let c=Array.from(s).filter(m=>m.groupIds.length>0),u=_l(c,n);for(let[m,p]of Object.entries(u))if(p){let f=ve(e,m);if(ln(f,t,i))for(let h of f)r.add(h)}return[...r].filter(m=>!(ee(m)&&m.containerId))},d0=(e,t,n)=>tf(Oo(e,Zl(e,t,n)),t,n),tf=(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=>ve(n,l)));s=!ln(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},kt=(e,t)=>e.frameId&&t.get(e.frameId)||null,c0=(e,t)=>{let n=new Set,i=ft(e);e=Oo(e);for(let s of e)K(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(K(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=ve(e,a);if(l.some(d=>sn(d,t,i)))for(let d of l)r.push(d)}}else sn(s,t,i)&&r.push(s);return r},nf=(e,t,n,i)=>{let o=ft(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)K(d)&&d.id!==n.id&&l.add(d.id);for(let d of Oo(e,t)){if(K(d)||d.frameId&&l.has(d.frameId)||d.frameId&&i.selectedElementIds[d.id]&&i.selectedElementIds[d.frameId])continue;r.has(d.id)||a.push(d);let c=V(d,o);c&&!s.has(c.id)&&!r.has(c.id)&&a.push(c)}for(let d of a)ye(d,o,{frameId:n.id});return e},ql=(e,t)=>{let n=new Map,i=new Map;for(let o of e)if(o.frameId){n.set(o.id,o);let r=i.get(o.frameId)||[];r.push(o);let s=V(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)ye(o,t,{frameId:null})},of=(e,t)=>{let n=an(e,t.id);return ql(n,ft(e)),e},u0=(e,t,n,i)=>nf(of(e,n),t,n,i.state).slice(),m0=(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=>ve(e,l)).forEach(l=>o.add(l));let r=new Set,s=ft(e);return o.forEach(a=>{a.frameId&&!K(a)&&!Kl(a,s,t)&&r.add(a)}),r.size>0&&ql(r,s),e},Oo=(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)ve(e,s).some(a=>K(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},rf=(e,t,n)=>{let i=ee(e)&&Se(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?kt(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:kt(i,t)},Kl=(e,t,n,i)=>{let o=i?.targetFrame??rf(e,t,n);if(!o)return!1;let r=ee(e)&&Se(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 sn(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=>ve(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(K(l))return s(!1),!1;for(let l of a)if(sn(l,o,t))return s(!0),!0;return!1},p0=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Wn(e,t,i)||as(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!ln([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=Kl(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},sf="Frame",af="AI Frame",lf=e=>io(e)?sf:af,f0=e=>e.name===null?lf(e):e.name,h0=(e,t)=>Hl({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),E0=e=>{let t=ft(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Ef=(e,t)=>yn(e)&&!t.imageCache.has(e.fileId),zo=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}},gf=(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*=uf/100),r},xf=(e,t,n)=>{let r=zo(e),[s,a,l,d]=X(e,t),c=Q(e)||Ie(e)?dn(s,l):e.width,u=Q(e)||Ie(e)?dn(a,d):e.height,m=c*window.devicePixelRatio+r*2,p=u*window.devicePixelRatio+r*2,f=n.value;return(m*f>32767||p*f>32767)&&(f=Math.min(32767/m,32767/p)),m*p*f*f>16777216&&(f=Math.sqrt(16777216/(m*p))),m=Math.floor(m*f),p=Math.floor(p*f),{width:m,height:p,scale:f}},td=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=zo(e),{width:l,height:d,scale:c}=xf(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(Q(e)||Ie(e)){let[g,x]=X(e,t);u=e.x>g?dn(e.x,g)*window.devicePixelRatio*c:0,m=e.y>x?dn(e.y,x)*window.devicePixelRatio*c:0,s.translate(u,m)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let p=wn.canvas(r);Fo(e,p,s,i),s.restore();let f=V(e,t),h=document.createElement("canvas"),E=h.getContext("2d");if(H(e)&&f){let[g,x,w,b]=X(e,t),y=Math.max(dn(g,w),dn(x,b));h.width=y*window.devicePixelRatio*c+a*c*10,h.height=y*window.devicePixelRatio*c+a*c*10,E.translate(h.width/2,h.height/2),E.rotate(e.angle),E.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,I,S]=X(f,t);E.rotate(-e.angle);let A=(h.width-r.width)/2,M=(h.height-r.height)/2,k=h.width/2-(I-g)*window.devicePixelRatio*c-A-a*c,L=h.height/2-(S-x)*window.devicePixelRatio*c-M-a*c;E.translate(-k,-L),E.clearRect(-(f.width/2+Ro)*window.devicePixelRatio*c,-(f.height/2+Ro)*window.devicePixelRatio*c,(f.width+Ro*2)*window.devicePixelRatio*c,(f.height+Ro*2)*window.devicePixelRatio*c)}return{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,boundTextElementVersion:V(e,t)?.version||null,containingFrameOpacity:kt(e,t)?.opacity||100,boundTextCanvas:h,angle:e.angle,imageCrop:xe(e)?e.crop:null}},B0=14,nd=typeof document<"u"?document.createElement("img"):{src:""};nd.src=`data:${ed.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 id=typeof document<"u"?document.createElement("img"):{src:""};id.src=`data:${ed.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 wf=(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"?id:nd,e.width/2-i/2,e.height/2-i/2,i,i)},Fo=(e,t,n,i)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(Ye.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Ye.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=Ye.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=i.theme===No.DARK?Ho(e.strokeColor):e.strokeColor,n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{let o=yn(e)?i.imageCache.get(e.fileId)?.image:void 0;if(o!=null&&!(o instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,St(Math.min(e.width,e.height),e)),n.clip());let{x:r,y:s,width:a,height:l}=e.crop?e.crop:{x:0,y:0,width:o.naturalWidth,height:o.naturalHeight};n.drawImage(o,r,s,a,l,0,0,e.width,e.height)}else wf(e,n);break}default:if(ee(e)){let o=pf(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=mf(e),n.fillStyle=i.theme===No.DARK?Ho(e.strokeColor):e.strokeColor,n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
|
|
10
10
|
`).split(`
|
|
11
|
-
`),l=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,c=Ho(e.fontSize,e.lineHeight),d=Ym(e.fontFamily,e.fontSize,c);for(let u=0;u<a.length;u++)n.fillText(a[u],l,u*c+d);n.restore(),s&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},Ei=new WeakMap,Ml=(e,t,n,o)=>{let i=n?o.zoom:{value:1},r=Ei.get(e),s=r&&r.zoomValue!==i.value&&!o?.shouldCacheIgnoreZoom,a=W(e,t),l=a?.version||null,c=xe(e)?e.crop:null,d=vt(e,t)?.opacity||100;if(!r||s||r.theme!==o.theme||r.boundTextElementVersion!==l||r.imageCrop!==c||r.containingFrameOpacity!==d||_(e)&&a&&e.angle!==r.angle){let u=Ll(e,t,i,n,o);return u?(Ei.set(e,u),u):null}return r},Nr=(e,t,n,o,i)=>{let r=e.element,s=gi(r),a=e.scale,[l,c,d,u]=H(r,i),p=((l+d)/2+o.scrollX)*window.devicePixelRatio,m=((c+u)/2+o.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=W(r,i);if(_(r)&&f){let E=(e.boundTextCanvas.width-e.canvas.width)/2,h=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(p,m),t.drawImage(e.boundTextCanvas,-(d-l)/2*window.devicePixelRatio-E/a-s,-(u-c)/2*window.devicePixelRatio-h/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(p,m),t.rotate(r.angle),"scale"in e.element&&!Dl(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-p,-m),t.drawImage(e.canvas,(l+o.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(c+o.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,i),h=ar(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((h.x+o.scrollX)*window.devicePixelRatio,(h.y+o.scrollY)*window.devicePixelRatio,Je(r,E)*window.devicePixelRatio,eo(r,E)*window.devicePixelRatio)}t.restore()},$b=(e,t,n,o)=>{t.save(),t.translate(e.x+n.scrollX,e.y+n.scrollY),t.fillStyle="rgba(0, 0, 200, 0.04)";let i=.5/n.zoom.value;t.fillRect(i,i,e.width,e.height),t.lineWidth=1/n.zoom.value,t.strokeStyle=o,t.strokeRect(i,i,e.width,e.height),t.restore()},Zb=(e,t,n,o,i,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(i.globalAlpha=Xm(e,vt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Nm:1),e.type){case"magicframe":case"frame":{s.frameRendering.enabled&&s.frameRendering.outline&&(i.save(),i.translate(e.x+s.scrollX,e.y+s.scrollY),i.fillStyle="rgba(0, 0, 200, 0.04)",i.lineWidth=fi.strokeWidth/s.zoom.value,i.strokeStyle=fi.strokeColor,ia(e)&&(i.strokeStyle=s.theme===Al.LIGHT?"#7affd7":"#1d8264"),fi.radius&&i.roundRect?(i.beginPath(),i.roundRect(0,0,e.width,e.height,fi.radius/s.zoom.value),i.stroke(),i.closePath()):i.strokeRect(0,0,e.width,e.height),i.restore());break}case"freedraw":{if(be.generateElementShape(e,null),r.isExporting){let[l,c,d,u]=H(e,t),p=(l+d)/2+s.scrollX,m=(c+u)/2+s.scrollY,f=(d-l)/2-(e.x-l),E=(u-c)/2-(e.y-c);i.save(),i.translate(p,m),i.rotate(e.angle),i.translate(-f,-E),hi(e,o,i,r,s),i.restore()}else{let l=Ml(e,n,r,s);if(!l)return;Nr(l,i,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(be.generateElementShape(e,r),r.isExporting){let[l,c,d,u]=H(e,t),p=(l+d)/2+s.scrollX,m=(c+u)/2+s.scrollY,f=(d-l)/2-(e.x-l),E=(u-c)/2-(e.y-c);if(oe(e)){let g=Ce(e,t);if(_(g)){let x=Y.getBoundTextElementPosition(g,e,t);f=(d-l)/2-(x.x-l),E=(u-c)/2-(x.y-c)}}i.save(),i.translate(p,m),vl(e,r,s)&&(i.filter="none");let h=W(e,t);if(_(e)&&h){let g=document.createElement("canvas"),x=g.getContext("2d"),y=Math.max(Qt(l,d),Qt(c,u)),b=gi(e);g.width=y*s.exportScale+b*10*s.exportScale,g.height=y*s.exportScale+b*10*s.exportScale,x.translate(g.width/2,g.height/2),x.scale(s.exportScale,s.exportScale),f=e.width/2-(e.x-l),E=e.height/2-(e.y-c),x.rotate(e.angle);let w=an.canvas(g);x.translate(-f,-E),hi(e,w,x,r,s),x.translate(f,E),x.rotate(-e.angle);let[,,,,I,M]=H(h,t),D=(l+d)/2-I,T=(c+u)/2-M;x.translate(-D,-T),x.clearRect(-h.width/2,-h.height/2,h.width,h.height),i.scale(1/s.exportScale,1/s.exportScale),i.drawImage(g,-g.width/2,-g.height/2,g.width,g.height)}else i.rotate(e.angle),e.type==="image"&&i.scale(e.scale[0],e.scale[1]),i.translate(-f,-E),hi(e,o,i,r,s);i.restore()}else{let l=Ml(e,n,r,s);if(!l)return;let c=i.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Fm(e.angle))&&(i.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&xe(l.element)&&l.element.crop!==null){i.save(),i.globalAlpha=.1;let d=Ll(Qs(l.element,t),n,s.zoom,r,s);d&&Nr(d,i,r,s,n),i.restore()}Nr(l,i,r,s,n),i.imageSmoothingEnabled=c}break}default:throw new Error(`Unimplemented type ${e.type}`)}i.globalAlpha=1},Gl=new WeakMap([]);function Ol(e){let t=$m(e),n=new Path2D(t);return Gl.set(e,n),n}function Vm(e){return Gl.get(e)}function $m(e){let t=e.simulatePressure?e.points:e.points.length?e.points.map(([o,i],r)=>[o,i,e.pressures[r]]):[[0,0,.5]],n={simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:o=>Math.sin(o*Math.PI/2),last:!!e.lastCommittedPoint};return qm(Vs(t,n))}function Tl(e,t){return[(e[0]+t[0])/2,(e[1]+t[1])/2]}var Zm=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;function qm(e){if(!e.length)return"";let t=e.length-1;return e.reduce((n,o,i,r)=>(i===t?n.push(o,Tl(o,r[0]),"L",r[0],"Z"):n.push(o,Tl(o,r[i+1])),n),["M",e[0],"Q"]).join(" ").replace(Zm,"$1")}P();var Qb=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",Jb=e=>e!=="image"&&e!=="frame"&&e!=="magicframe",e0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",t0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Rl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",n0=e=>e==="arrow",o0=e=>e==="arrow";var be=class e{static rg=new Xe;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 o=n?.isExporting?void 0:e.get(t);if(o!==void 0)return o;Ei.delete(t);let i=of(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:Jm.white,embedsValidationStatus:null});return e.cache.set(t,i),i}},tf=e=>[8,8+e],zl=e=>[1.5,6+e];function nf(e){let t=e.roughness,n=Math.max(e.width,e.height),o=Math.min(e.width,e.height);return o>=20&&n>=50||o>=15&&e.roundness&&Rl(e.type)||X(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var ke=(e,t=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?tf(e.strokeWidth):e.strokeStyle==="dotted"?zl(e.strokeWidth):void 0,disableMultiStroke:e.strokeStyle!=="solid",strokeWidth:e.strokeStyle!=="solid"?e.strokeWidth+.5:e.strokeWidth,fillWeight:e.strokeWidth/2,hachureGap:e.strokeWidth*4,roughness:nf(e),stroke:e.strokeColor,preserveVertices:t||e.roughness<Km.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=ao(e.backgroundColor)?void 0:e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return ln(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},Fl=(e,t,n)=>Ro(e)&&(t||oa(e)&&n?.get(e.id)!==!0)&&ao(e.backgroundColor)&&ao(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:Oo(e)?{...e,strokeColor:ao(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:ao(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Nl=(e,t,n,o,i,r,s)=>{let a=Hr(e,t,n,o);if(a===null)return[];let l=(c,d)=>{if(c===null)return[];let[,,u,p,m,f]=c;return[i.line(u,p,m,f,d)]};switch(o){case"dot":case"circle":case"circle_outline":{let[c,d,u]=a;return delete r.strokeLineDash,[i.circle(c,d,u,{...r,fill:o==="circle_outline"?s:e.strokeColor,fillStyle:"solid",stroke:e.strokeColor,roughness:Math.min(.5,r.roughness||0)})]}case"triangle":case"triangle_outline":{let[c,d,u,p,m,f]=a;return delete r.strokeLineDash,[i.polygon([[c,d],[u,p],[m,f],[c,d]],{...r,fill:o==="triangle_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[c,d,u,p,m,f,E,h]=a;return delete r.strokeLineDash,[i.polygon([[c,d],[u,p],[m,f],[E,h],[c,d]],{...r,fill:o==="diamond_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"crowfoot_one":return l(a,r);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[c,d,u,p,m,f]=a;if(e.strokeStyle==="dotted"){let E=zl(e.strokeWidth-1);r.strokeLineDash=[E[0],E[1]-1]}else delete r.strokeLineDash;return r.roughness=Math.min(1,r.roughness||0),[i.line(u,p,c,d,r),i.line(m,f,c,d,r),...o==="crowfoot_one_or_many"?l(Hr(e,t,n,"crowfoot_one"),r):[]]}}},ta=e=>{let t=new Xe,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=ct(e.points.reduce((i,r)=>[Math.min(e.x+r[0],i[0]),Math.min(e.y+r[1],i[1]),Math.max(e.x+r[0],i[2]),Math.max(e.y+r[1],i[3])],[1/0,1/0,-1/0,-1/0]));switch(e.type){case"line":case"arrow":{let i=e.points.length?e.points:[ce(0,0)];return G(e)?t.path(Hl(i,16),n).sets[0].ops:e.roundness?t.curve(i,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Lt(ce(e.x+r.data[0],e.y+r.data[1]),o,e.angle);return{op:"move",data:ce(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(ce(e.x+r.data[0],e.y+r.data[1]),o,e.angle),Lt(ce(e.x+r.data[2],e.y+r.data[3]),o,e.angle),Lt(ce(e.x+r.data[4],e.y+r.data[5]),o,e.angle)].map(a=>ce(a[0]-e.x,a[1]-e.y)).flat()}}):i.map((r,s)=>{let a=Lt(ce(e.x+r[0],e.y+r[1]),o,e.angle);return{op:s===0?"move":"lineTo",data:ce(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let i=Wn(e.points,.75);return t.curve(i,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Lt(ce(e.x+r.data[0],e.y+r.data[1]),o,e.angle);return{op:"move",data:ce(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(ce(e.x+r.data[0],e.y+r.data[1]),o,e.angle),Lt(ce(e.x+r.data[2],e.y+r.data[3]),o,e.angle),Lt(ce(e.x+r.data[4],e.y+r.data[5]),o,e.angle)].map(a=>ce(a[0]-e.x,a[1]-e.y)).flat()}})}}},of=(e,t,{isExporting:n,canvasBackgroundColor:o,embedsValidationStatus:i})=>{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`,ke(Fl(e,n,i),!0))}else r=t.rectangle(0,0,e.width,e.height,ke(Fl(e,n,i),!1));return r}case"diamond":{let r,[s,a,l,c,d,u,p,m]=Go(e);if(e.roundness){let f=yt(Math.abs(s-p),e),E=yt(Math.abs(c-a),e);r=t.path(`M ${s+f} ${a+E} L ${l-f} ${c-E}
|
|
12
|
-
C ${
|
|
13
|
-
L ${
|
|
14
|
-
C ${
|
|
15
|
-
L ${
|
|
16
|
-
C ${
|
|
17
|
-
L ${
|
|
18
|
-
C ${s} ${a}, ${s} ${a}, ${s+f} ${a+E}`,ke(e,!0))}else r=t.polygon([[s,a],[l,c],[d,u],[p,m]],ke(e));return r}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,ke(e));case"line":case"arrow":{let r,s=ke(e),a=e.points.length?e.points:[ce(0,0)];if(G(e)?a.every(l=>Math.abs(l[0])<=1e6&&Math.abs(l[1])<=1e6)?r=[t.path(Hl(a,16),ke(e,!0))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(a)),r=[]):e.roundness?r=[t.curve(a,s)]:s.fill?r=[t.polygon(a,s)]:r=[t.linearPath(a,s)],e.type==="arrow"){let{startArrowhead:l=null,endArrowhead:c="arrow"}=e;if(l!==null){let d=Nl(e,r,"start",l,t,s,o);r.push(...d)}if(c!==null){let d=Nl(e,r,"end",c,t,s,o);r.push(...d)}}return r}case"freedraw":{let r;if(Ol(e),ln(e.points)){let s=Wn(e.points,.75);r=t.curve(s,{...ke(e),stroke:"none"})}else r=null;return r}case"frame":case"magicframe":case"text":case"image":return null;default:return Qm(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Hl=(e,t)=>{let n=[];for(let i=1;i<e.length-1;i+=1){let r=e[i-1],s=e[i+1],a=e[i],l=et(a,r),c=et(s,a),d=Math.min(t,kl(e[i],s)/2,kl(e[i],r)/2);l?r[0]<a[0]?n.push([e[i][0]-d,e[i][1]]):n.push([e[i][0]+d,e[i][1]]):r[1]<a[1]?n.push([e[i][0],e[i][1]-d]):n.push([e[i][0],e[i][1]+d]),n.push(e[i]),c?s[0]<a[0]?n.push([e[i][0]-d,e[i][1]]):n.push([e[i][0]+d,e[i][1]]):s[1]<a[1]?n.push([e[i][0],e[i][1]-d]):n.push([e[i][0],e[i][1]+d])}let o=[`M ${e[0][0]} ${e[0][1]}`];for(let i=0;i<n.length;i+=3)o.push(`L ${n[i][0]} ${n[i][1]}`),o.push(`Q ${n[i+1][0]} ${n[i+1][1]}, ${n[i+2][0]} ${n[i+2][1]}`);return o.push(`L ${e[e.length-1][0]} ${e[e.length-1][1]}`),o.join(" ")},_l=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return ks(e);case"arrow":case"line":{let n=be.get(e)?.[0]??be.generateElementShape(e,null)[0],[,,,,o,i]=H(e,t);return Wo(e)?Hs(e,n,ce(e.x,e.y),e.angle,ce(o,i)):Ns(n,ce(e.x,e.y),e.angle,ce(o,i))}case"ellipse":return Fs(e);case"freedraw":{let[,,,,n,o]=H(e,t);return zs(e,ce(n,o),Wo(e))}}},nl=(e,t)=>{let n=[...e.points];if(t){if(!la(e.points))return null;let i=n[0],r=n[n.length-1];Math.hypot(i[0]-r[0],i[1]-r[1])>ef||n.length<4?n.push(ce(i[0],i[1])):n[n.length-1]=ce(i[0],i[1])}return{polygon:t,points:n}};var Ur=class e{static boundsCache=new WeakMap;static nonRotatedBoundsCache=new WeakMap;static getBounds(t,n,o=!1){let i=o&&t.angle!==0?e.nonRotatedBoundsCache.get(t):e.boundsCache.get(t);if(i?.version&&i.version===t.version&&!de(t))return i.bounds;if(o&&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 o,[i,r,s,a,l,c]=H(t,n);if(Se(t)){let[d,u,p,m]=Xr(t.points.map(([f,E])=>se(v(f,E),v(l-t.x,c-t.y),t.angle)));return[d+t.x,u+t.y,p+t.x,m+t.y]}else if(X(t))o=mf(t,l,c,n);else if(t.type==="diamond"){let[d,u]=se(v(l,r),v(l,c),t.angle),[p,m]=se(v(l,a),v(l,c),t.angle),[f,E]=se(v(i,c),v(l,c),t.angle),[h,g]=se(v(s,c),v(l,c),t.angle),x=Math.min(d,p,f,h),y=Math.min(u,m,E,g),b=Math.max(d,p,f,h),w=Math.max(u,m,E,g);o=[x,y,b,w]}else if(t.type==="ellipse"){let d=(s-i)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(d*p,u*m),E=Math.hypot(u*p,d*m);o=[l-f,c-E,l+f,c+E]}else{let[d,u]=se(v(i,r),v(l,c),t.angle),[p,m]=se(v(i,a),v(l,c),t.angle),[f,E]=se(v(s,a),v(l,c),t.angle),[h,g]=se(v(s,r),v(l,c),t.angle),x=Math.min(d,p,f,h),y=Math.min(u,m,E,g),b=Math.max(d,p,f,h),w=Math.max(u,m,E,g);o=[x,y,b,w]}return o}},H=(e,t,n=!1)=>{if(Se(e))return cf(e);if(X(e))return Y.getElementAbsoluteCoords(e,t,n);if(oe(e)){let o=t?Ce(e,t):null;if(_(o)){let{x:i,y:r}=Y.getBoundTextElementPosition(o,e,t);return[i,r,i+e.width,r+e.height,i+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]},kr=(e,t)=>{let n=_l(e,t),[o,i,r,s,a,l]=H(e,t),c=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(Ee(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(af(e)){let[h,g]=yn(e),x=g.map(b=>Xl(b,c,e.angle)).flat();return[...Ul(h,c,e.angle),...x]}else if(e.type==="diamond"){let[h,g]=bn(e),x=g.map(b=>Xl(b,c,e.angle)).flat();return[...Ul(h,c,e.angle),...x]}else if(n.type==="polygon"){if(oe(e)){let x=Ce(e,t);if(x&&X(x))return[Ee(v(o,i),v(r,i)),Ee(v(r,i),v(r,s)),Ee(v(r,s),v(o,s)),Ee(v(o,s),v(o,i))]}let h=n.data,g=[];for(let x=0;x<h.length-1;x++)g.push(Ee(h[x],h[x+1]));return g}else if(n.type==="ellipse")return lf(e)}let[d,u,p,m,,,f,E]=[[o,i],[r,i],[o,s],[r,s],[a,i],[a,s],[o,l],[r,l]].map(h=>se(h,c,e.angle));return[Ee(d,u),Ee(p,m),Ee(d,p),Ee(u,m),Ee(d,E),Ee(p,E),Ee(u,f),Ee(m,f)]},af=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),Ul=(e,t,n)=>e.map(o=>Ee(se(o[0],t,n),se(o[1],t,n))),Xl=(e,t,n)=>{let o=Et(e,10),i=0,r=[];for(;i<o.length-1;)r.push(Ee(se(v(o[i][0],o[i][1]),t,n),se(v(o[i+1][0],o[i+1][1]),t,n))),i++;return r},lf=e=>{let t=v(e.x+e.width/2,e.y+e.height/2),n=e.width/2,o=e.height/2,i=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let c=l*a,d=t[0]+n*Math.cos(c),u=t[1]+o*Math.sin(c);r.push(se(v(d,u),t,e.angle))}for(let l=0;l<r.length-1;l++)i.push(Ee(r[l],r[l+1]));return i.push(Ee(r[r.length-1],r[0])),i},G0=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Go=e=>{let t=Math.floor(e.width/2)+1,n=0,o=e.width,i=Math.floor(e.height/2)+1,r=t,s=e.height;return[t,n,o,i,r,s,0,i]},Wl=(e,t,n,o,i)=>{let r=1-e;return Math.pow(r,3)*t+3*Math.pow(r,2)*e*n+3*r*Math.pow(e,2)*o+Math.pow(e,3)*i},jl=(e,t,n,o)=>{let i=t-e,r=n-t,s=o-n,a=3*i-6*r+3*s,l=6*r-6*i,c=3*i,d=l*l-4*a*c;if(!(d>=0))return!1;let p=null,m=null,f=1/0,E=1/0;return a===0?f=E=-c/l:(f=(-l+Math.sqrt(d))/(2*a),E=(-l-Math.sqrt(d))/(2*a)),f>=0&&f<=1&&(p=Wl(f,e,t,n,o)),E>=0&&E<=1&&(m=Wl(E,e,t,n,o)),[p,m]},jo=(e,t,n,o)=>{let i=jl(e[0],t[0],n[0],o[0]),r=jl(e[1],t[1],n[1],o[1]),s=Math.min(e[0],o[0]),a=Math.max(e[0],o[0]);if(i){let d=i.filter(u=>u!==null);s=Math.min(s,...d),a=Math.max(a,...d)}let l=Math.min(e[1],o[1]),c=Math.max(e[1],o[1]);if(r){let d=r.filter(u=>u!==null);l=Math.min(l,...d),c=Math.max(c,...d)}return[s,l,a,c]},so=(e,t)=>{let n=v(0,0),{minX:o,minY:i,maxX:r,maxY:s}=e.reduce((a,{op:l,data:c})=>{if(l==="move"){let d=$l(c);Yr(d!=null,"Op data is not a point"),n=d}else if(l==="bcurveTo"){let d=v(c[0],c[1]),u=v(c[2],c[3]),p=v(c[4],c[5]),m=t?t(d):d,f=t?t(u):u,E=t?t(p):p,h=t?t(n):n;n=p;let[g,x,y,b]=jo(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[o,i,r,s]},Xr=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;for(let[r,s]of e)t=Math.min(t,r),n=Math.min(n,s),o=Math.max(o,r),i=Math.max(i,s);return[t,n,o,i]},cf=e=>{let[t,n,o,i]=Xr(e.points),r=t+e.x,s=n+e.y,a=o+e.x,l=i+e.y;return[r,s,a,l,(r+a)/2,(s+l)/2]},df=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}},uf=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},Hr=(e,t,n,o)=>{if(t.length<1)return null;let i=gt(t[0]);if(i.length<1)return null;let r=n==="start"?1:i.length-1,s=i[r].data;Yr(s.length===6,"Op data length is not 6");let a=v(s[4],s[5]),l=v(s[2],s[3]),c=v(s[0],s[1]),d=i[r-1],u=v(0,0);if(d.op==="move"){let N=$l(d.data);Yr(N!=null,"Op data is not a point"),u=N}else d.op==="bcurveTo"&&(u=v(d.data[4],d.data[5]));let p=(N,te)=>Math.pow(1-N,3)*a[te]+3*N*Math.pow(1-N,2)*l[te]+3*Math.pow(N,2)*(1-N)*c[te]+u[te]*Math.pow(N,3),[m,f]=n==="start"?u:a,[E,h]=[p(.3,0),p(.3,1)],g=Math.hypot(m-E,f-h),x=(m-E)/g,y=(f-h)/g,b=df(o),w=0;{let[N,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(N-S,te-Q)}let M=Math.min(b,w*(o==="diamond"||o==="diamond_outline"?.25:.5)),D=m-x*M,T=f-y*M;if(o==="dot"||o==="circle"||o==="circle_outline"){let N=Math.hypot(T-f,D-m)+e.strokeWidth-2;return[m,f,N]}let F=uf(o);if(o==="crowfoot_many"||o==="crowfoot_one_or_many"){let[N,te]=se(v(m,f),v(D,T),_r(-F)),[S,Q]=se(v(m,f),v(D,T),_r(F));return[D,T,N,te,S,Q]}let[C,k]=se(v(D,T),v(m,f),-F*Math.PI/180),[L,j]=se(v(D,T),v(m,f),_r(F));if(o==="diamond"||o==="diamond_outline"){let N,te;if(n==="start"){let[S,Q]=e.points.length>1?e.points[1]:[0,0];[N,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];[N,te]=se(v(m-M*2,f),v(m,f),Math.atan2(f-Q,m-S))}return[m,f,C,k,N,te,L,j]}return[m,f,C,k,L,j]},pf=e=>{let t=an.generator(),n=ke(e),o=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[o](e.points,n)},mf=(e,t,n,o)=>{let i=W(e,o);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(i){let h=Y.getMinMaxXYWithBoundText(e,o,[m,f,m,f],i);E=[h[0],h[1],h[2],h[3]]}return E}let s=be.get(e)?.[0]??pf(e),a=gt(s),c=so(a,([u,p])=>se(v(e.x+u,e.y+p),v(t,n),e.angle)),d=[c[0],c[1],c[2],c[3]];if(i){let u=Y.getMinMaxXYWithBoundText(e,o,d,i);d=[u[0],u[1],u[2],u[3]]}return d},he=(e,t,n=!1)=>Ur.getBounds(e,t,n),tt=(e,t)=>{if(!rf(e))return[0,0,0,0];let n=1/0,o=-1/0,i=1/0,r=-1/0,s=t||Vl(e);return e.forEach(a=>{let[l,c,d,u]=he(a,s);n=Math.min(n,l),i=Math.min(i,c),o=Math.max(o,d),r=Math.max(r,u)}),[n,i,o,r]},O0=(e,t)=>{let[n,o,i,r]=tt(e);return[n+t.x,o+t.y,i+t.x,r+t.y]},Nt=(e,t,n,o)=>{if(!(X(e)||Se(e)))return[e.x,e.y,e.x+t,e.y+n];let i=Yl(0,t,Yl(1,n,e.points,o),o),r;if(Se(e))r=Xr(i);else{let d=an.generator(),u=e.roundness?d.curve(i,ke(e)):d.linearPath(i,ke(e)),p=gt(u);r=so(p)}let[s,a,l,c]=r;return[s+e.x,a+e.y,l+e.x,c+e.y]},Lr=(e,t)=>{let n=an.generator(),o=e.roundness==null?n.linearPath(t,ke(e)):n.curve(t,ke(e)),i=gt(o),[r,s,a,l]=so(i);return[r+e.x,s+e.y,a+e.x,l+e.y]},R0=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,o=e[0],i=Vl(e);return e.forEach(r=>{let[s,a,l,c]=he(r,i),d=sf(v((s+l)/2,(a+c)/2),v(t.x,t.y));d<n&&(n=d,o=r)}),he(o,i)},Ct=e=>{let[t,n,o,i]=tt(e);return{minX:t,minY:n,maxX:o,maxY:i,width:o-t,height:i-n,midX:(t+o)/2,midY:(n+i)/2}},k0=({scrollX:e,scrollY:t,width:n,height:o,zoom:i})=>[-e,-t,-e+n/i.value,-t+o/i.value],ct=e=>v(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),Ve=(e,t,n)=>{let o={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},i=fe(e,t),[r,s]=se(v(o.minX,o.minY),i,e.angle),[a,l]=se(v(o.maxX,o.minY),i,e.angle),[c,d]=se(v(o.maxX,o.maxY),i,e.angle),[u,p]=se(v(o.minX,o.maxY),i,e.angle),m=[Math.min(r,a,c,u),Math.min(s,l,d,p),Math.max(r,a,c,u),Math.max(s,l,d,p)];if(n){let[f,E,h,g]=n;return[m[0]-g,m[1]-f,m[2]+E,m[3]+h]}return m},Mn=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],pn=(e,t)=>{if(e==null||t==null)return!1;let[n,o,i,r]=e,[s,a,l,c]=t;return n<l&&i>s&&o<c&&r>a},fe=(e,t,n=0,o=0)=>{let[i,r]=ct(he(e,t));return v(i+n,r+o)};var gf=.1,ql=e=>X(e)||Se(e)?e.points.length<2||e.points.length===2&&_(e)&&Ef(e.points[0],e.points[e.points.length-1],gf):e.width===0&&e.height===0,yl=(e,t,n,o,i)=>{let[r,s,a,l]=he(e,i),c=xi({clientX:o.offsetLeft,clientY:o.offsetTop},o),d=xi({clientX:o.offsetLeft+t,clientY:o.offsetTop+n},o);return c.x<=a&&c.y<=l&&d.x>=r&&d.y>=s},X0=(e,t,n,o,i,r)=>{let[s,a,l,c]=tt(e,i),d=xi({clientX:o.offsetLeft+(r?.left||0),clientY:o.offsetTop+(r?.top||0)},o),u=xi({clientX:o.offsetLeft+t-(r?.right||0),clientY:o.offsetTop+n-(r?.bottom||0)},o);return s>=d.x&&a>=d.y&&l<=u.x&&c<=u.y},Wr=(e,t,n)=>{let o=Math.abs(t),i=Math.abs(n);if(e==="line"||e==="arrow"||e==="freedraw"){let r=Math.round(Math.atan(i/o)/Bt)*Bt;r===0?n=0:r===Math.PI/2?t=0:n=o*Math.tan(r)*Math.sign(n)||n}else e!=="selection"&&(n=o*Math.sign(n));return{width:t,height:n}},ol=(e,t,n,o,i)=>{let r=n-e,s=o-t,a=Math.atan2(s,r),l=Math.round(a/Bt)*Bt;if(i){let c=Math.floor(i/Bt)*Bt;ff(a,c,c+Bt)&&(hf(a,i)<Bt/6?l=i:Zl(a)>Zl(i)?l=c+Bt:l=c)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let c=Math.tan(l),d=-1,u=t-c*e,p=-1/c,m=-1,f=o-p*n,E=(d*f-m*u)/(c*m-p*d),h=(u*p-f*c)/(c*m-p*d);r=E-e,s=h-t}return{width:r,height:s}},W0=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 K0=(e,t,n,o)=>{let i=ui(e,n.getNonDeletedElementsMap(),o),r=Ct(e);return i.flatMap(s=>{let a=xf(s,r,t);return s.map(l=>{let c=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ue(l,n,{simultaneouslyUpdated:s}),c})})},xf=(e,t,{axis:n,position:o})=>{let i=Ct(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return o==="start"?{...a,[n]:t[r]-i[r]}:o==="end"?{...a,[n]:t[s]-i[s]}:{...a,[n]:(t[r]+t[s])/2-(i[r]+i[s])/2}};P();import{arrayToMap as mh,arrayToObject as Gt,assertNever as Ac,isDevEnv as kn,isShallowEqual as Dc,isTestEnv as Fn,randomInteger as Tc}from"@excalidraw/common";P();import{assertNever as vf,COLOR_PALETTE as Lf,isDevEnv as Cf,isTestEnv as Bf,randomId as Gf,Emitter as Jl,toIterable as Bn}from"@excalidraw/common";P();import{ORIG_ID as Pf,randomId as Ql,randomInteger as If,arrayToMap as Sf,castArray as jr,findLastIndex as lo,getUpdatedTimestamp as Mf,isTestEnv as Tf}from"@excalidraw/common";P();import{arrayToMapWithIndex as wf}from"@excalidraw/common";var yf=e=>{let t=e.slice(),n=new Set,o=r=>{let s=r[0]?.groupIds?.join(""),a=[r[0]],l=[];for(let c of r.slice(1))c.groupIds?.join("")===s?a.push(c):l.push(c);return l.length?[...a,...o(l)]:a},i=new Map;return t.forEach((r,s)=>{if(!i.has(r.id))if(r.groupIds?.length){let a=r.groupIds[r.groupIds.length-1],l=t.slice(s).filter(c=>{let d=c?.groupIds?.some(u=>u===a);return d&&i.set(c.id,!0),d});for(let c of o(l))n.add(c)}else n.add(r)}),n.size!==e.length?(console.error("normalizeGroupElementOrder: lost some elements... bailing!"),e):[...n]},bf=e=>{let t=wf(e),n=e.slice(),o=new Set;return n.forEach((i,r)=>{i&&(i.boundElements?.length?(o.add(i),n[r]=null,i.boundElements.forEach(s=>{let a=t.get(s.id);a&&s.type==="text"&&(o.add(a[0]),n[a[1]]=null)})):i.type==="text"&&i.containerId&&t.get(i.containerId)?.[0].boundElements?.find(a=>a.id===i.id)||(o.add(i),n[r]=null))}),o.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...o]},Kl=e=>bf(yf(e));var Af=(e,t,n,o)=>{let i=$r(n);return Tf()&&Df(i,n.id),i.id=Ql(),i.updated=Mf(),o&&(i.seed=If(),Ra(i)),i.groupIds=xl(i.groupIds,e,r=>(t.has(r)||t.set(r,Ql()),t.get(r))),i},u1=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},o=new Map,i=new Map,r=[],s=[],a=new Map,l=new Map,c=new Map,d=Sf(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(h=>[h.id,h]));if(e.type==="in-place")for(let h of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(h)).forEach(g=>u.set(g.id,g));t=Kl(t);let p=t.slice(),m=h=>{let x=jr(h).reduce((y,b)=>{if(o.has(b.id))return y;o.set(b.id,!0);let w=Af(n.editingGroupId,i,b,e.randomizeSeed);return o.set(w.id,!0),c.set(w.id,w),a.set(b.id,w.id),l.set(w.id,b),s.push(b),r.push(w),y.push(w),y},[]);return Array.isArray(h)?x:x[0]||null},f=(h,g)=>{if(g){if(h>p.length-1){p.push(...jr(g));return}p.splice(h+1,0,...jr(g))}},E=new Set(t.filter(h=>u.has(h.id)&&$(h)).map(h=>h.id));for(let h of t){if(o.has(h.id)||!u.has(h.id))continue;let g=Gr(n,h);if(g){let x=Ae(t,g).flatMap(b=>$(b)?[...qt(t,b.id),b]:[b]),y=lo(p,b=>b.groupIds?.includes(g));f(y,m(x));continue}if(!(h.frameId&&E.has(h.frameId))){if($(h)){let x=h.id,y=qt(t,x),b=lo(p,w=>w.frameId===x||w.id===x);f(b,m([...y,h]));continue}if(st(h)){let x=W(h,d),y=lo(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(de(h)){let x=Ce(h,d),y=lo(p,b=>b.id===h.id||b.id===x?.id);x?f(y,m([x,h])):f(y,m(h));continue}f(lo(p,x=>x.id===h.id),m(h))}}if($a(r,a,c),bl(p,s,a),e.overrides)for(let h of r){let g=l.get(h.id);g&&Object.assign(h,e.overrides({duplicateElement:h,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:c,elementsWithDuplicates:p,origIdToDuplicateId:a}},Vr=(e,t=0)=>{if(e==null||typeof e!="object")return e;let n=Object.prototype.toString.call(e);if(n==="[object Object]"){let o=typeof e.constructor=="function"?Object.create(Object.getPrototypeOf(e)):{};for(let i in e)if(e.hasOwnProperty(i)){if(t===0&&(i==="shape"||i==="canvas"))continue;o[i]=Vr(e[i],t+1)}return o}if(Array.isArray(e)){let o=e.length,i=new Array(o);for(;o--;)i[o]=Vr(e[o],t+1);return i}return A.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},$r=e=>Vr(e),Df=(e,t)=>{Object.defineProperty(e,Pf,{value:t,writable:!1,enumerable:!1})};var Fe={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},ec=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Jl;onStoreIncrementEmitter=new Jl;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Jt.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,o;if("change"in t)o=t.change;else{let r=Jt.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?oc(t.elements):void 0,t.appState);o=co.create(r,s)}let i="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:o,delta:i}))}commit(t,n){this.flushMicroActions();try{let o=this.getScheduledMacroAction();this.processAction({action:o,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=Jt.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,o=void 0){let i=this.snapshot,r,s;if(n?r=n:r=co.create(i,t),o?s=o:s=Kr.calculate(i,t),!s.isEmpty()){let a=new Zr(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let o;if(n)o=n;else{let r=this.snapshot;o=co.create(r,t)}let i=new qr(o);this.onStoreIncrementEmitter.trigger(i)}applyChangeToSnapshot(t){let n=this.snapshot,o=this.snapshot.applyChange(t);return n===o?null:o}maybeCloneSnapshot(t,n,o){if(!n&&!o)return null;let i=this.snapshot,r=this.snapshot.maybeClone(t,n,o);return i===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 o;if("change"in t?o=this.applyChangeToSnapshot(t.change):o=this.maybeCloneSnapshot(n,t.elements,t.appState),!o)return;let i="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case Fe.IMMEDIATELY:this.emitDurableIncrement(o,i,r);break;case Fe.NEVER:case Fe.EVENTUALLY:this.emitEphemeralIncrement(o,i);break;default:vf(n,"Unknown store action")}}finally{switch(n){case Fe.IMMEDIATELY:case Fe.NEVER:this.snapshot=o;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()),Bf()||Cf())throw new Error(t)}}},co=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let o=n.getChangedElements(t),i=n.getChangedAppState(t);return new e(o,i)}},wi=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Zr=class extends wi{constructor(n,o){super("durable",n);this.change=n;this.delta=o}},qr=class extends wi{constructor(n){super("ephemeral",n);this.change=n}},Kr=class{constructor(t,n,o){this.id=t;this.elements=n;this.appState=o}static create(t,n,o={id:Gf()}){return new this(o.id,t,n)}static calculate(t,n){let o=n.metadata.didElementsChange?hn.calculate(t.elements,n.elements):hn.empty(),i=n.metadata.didAppStateChange?fn.calculate(t.appState,n.appState):fn.empty();return this.create(o,i)}static restore(t){let{id:n,elements:o,appState:i}=t;return new this(n,hn.restore(o),fn.restore(i))}static load({id:t,elements:{added:n,removed:o,updated:i}}){let r=hn.create(n,o,i);return new this(t,r,fn.empty())}static inverse(t){return this.create(t.elements.inverse(),t.appState.inverse())}static applyTo(t,n,o,i={excludedProperties:new Set}){let[r,s]=t.elements.applyTo(n,Jt.empty().elements,i),[a,l]=t.appState.applyTo(o,r);return[r,a,s||l]}static applyLatestChanges(t,n,o,i){return this.create(t.elements.applyLatestChanges(n,o,i),t.appState,{id:t.id})}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Jt=class e{constructor(t,n,o={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=o}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,o={didElementsChange:!1,didAppStateChange:!1}){return new e(t,tc(n)?n:Gn(n),o)}static empty(){return new e(new Map,Of(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let o of Bn(t.elements))this.elements.get(o.id)||(n[o.id]=Me(o,{isDeleted:!0}));for(let o of Bn(this.elements))t.elements.get(o.id)!==o&&(n[o.id]=o);return n}getChangedAppState(t){return q.getRightDifferences(t.appState,this.appState).reduce((n,o)=>Object.assign(n,{[o]:this.appState[o]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[i,r]of Object.entries(t.elements))n.set(i,r);let o=Gn({...this.appState,...t.appState});return e.create(n,o,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,o){let i={shouldCompareHashes:!1};t===Fe.EVENTUALLY&&(i.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,i),s=this.maybeCreateAppStateSnapshot(o,i),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 o=tc(t)?t:Gn(t);return this.detectChangedAppState(o,n)?o:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let o=this.detectChangedElements(t,n);return o?.size?this.createElementsSnapshot(o):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let o=q.isRightDifferent(this.appState,t);if(!o)return;let i=rc(JSON.stringify(t));if(!(n.shouldCompareHashes&&this._lastChangedAppStateHash===i))return this._lastChangedAppStateHash=i,o}detectChangedElements(t,n={shouldCompareHashes:!1}){if(this.elements===t)return;let o=new Map;for(let r of Bn(this.elements))t.get(r.id)||o.set(r.id,Me(r,{isDeleted:!0}));for(let r of Bn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(xe(r)&&!zt(r))continue;o.set(r.id,r)}}if(!o.size)return;let i=ic(o);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===i))return this._lastChangedElementsHash=i,o}createElementsSnapshot(t){let n=new Map;for(let o of Bn(this.elements))n.set(o.id,o);for(let o of Bn(t))n.set(o.id,$r(o));return n}},nc="__observedAppState",Of=()=>({name:null,editingGroupId:null,viewBackgroundColor:Lf.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),Gn=e=>{let t={name:e.name,editingGroupId:e.editingGroupId,viewBackgroundColor:e.viewBackgroundColor,selectedElementIds:e.selectedElementIds,selectedGroupIds:e.selectedGroupIds,croppingElementId:e.croppingElementId,activeLockedId:e.activeLockedId,lockedMultiSelections:e.lockedMultiSelections,selectedLinearElement:e.selectedLinearElement?{elementId:e.selectedLinearElement.elementId,isEditing:!!e.selectedLinearElement.isEditing}:null};return Reflect.defineProperty(t,nc,{value:!0,enumerable:!1}),t},tc=e=>!!Reflect.get(e,nc);P();P();var lc="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Rn(e,t,n){let o=n[0];if(t!=null&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)===o||t&&t.slice(-1)===o)throw new Error("trailing zero");if(t){let s=0;for(;(e[s]||o)===t[s];)s++;if(s>0)return t.slice(0,s)+Rn(e.slice(s),t.slice(s),n)}let i=e?n.indexOf(e[0]):0,r=t!=null?n.indexOf(t[0]):n.length;if(r-i>1){let s=Math.round(.5*(i+r));return n[s]}else return t&&t.length>1?t.slice(0,1):n[i]+Rn(e.slice(1),null,n)}function cc(e){if(e.length!==dc(e[0]))throw new Error("invalid integer part of order key: "+e)}function dc(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("invalid order key head: "+e)}function uo(e){let t=dc(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function sc(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=uo(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function ac(e,t){cc(e);let[n,...o]=e.split(""),i=!0;for(let r=o.length-1;i&&r>=0;r--){let s=t.indexOf(o[r])+1;s===t.length?o[r]=t[0]:(o[r]=t[s],i=!1)}if(i){if(n==="Z")return"a"+t[0];if(n==="z")return null;let r=String.fromCharCode(n.charCodeAt(0)+1);return r>"a"?o.push(t[0]):o.pop(),r+o.join("")}else return n+o.join("")}function Rf(e,t){cc(e);let[n,...o]=e.split(""),i=!0;for(let r=o.length-1;i&&r>=0;r--){let s=t.indexOf(o[r])-1;s===-1?o[r]=t.slice(-1):(o[r]=t[s],i=!1)}if(i){if(n==="a")return"Z"+t.slice(-1);if(n==="A")return null;let r=String.fromCharCode(n.charCodeAt(0)-1);return r<"Z"?o.push(t.slice(-1)):o.pop(),r+o.join("")}else return n+o.join("")}function On(e,t,n=lc){if(e!=null&&sc(e,n),t!=null&&sc(t,n),e!=null&&t!=null&&e>=t)throw new Error(e+" >= "+t);if(e==null){if(t==null)return"a"+n[0];let l=uo(t),c=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Rn("",c,n);if(l<t)return l;let d=Rf(l,n);if(d==null)throw new Error("cannot decrement any more");return d}if(t==null){let l=uo(e),c=e.slice(l.length),d=ac(l,n);return d??l+Rn(c,null,n)}let o=uo(e),i=e.slice(o.length),r=uo(t),s=t.slice(r.length);if(o===r)return o+Rn(i,s,n);let a=ac(o,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:o+Rn(i,null,n)}function yi(e,t,n,o=lc){if(n===0)return[];if(n===1)return[On(e,t,o)];if(t==null){let s=On(e,t,o),a=[s];for(let l=0;l<n-1;l++)s=On(s,t,o),a.push(s);return a}if(e==null){let s=On(e,t,o),a=[s];for(let l=0;l<n-1;l++)s=On(e,s,o),a.push(s);return a.reverse(),a}let i=Math.floor(n/2),r=On(e,t,o);return[...yi(e,r,i,o),r,...yi(r,t,n-i-1,o)]}import{arrayToMap as bi}from"@excalidraw/common";var Qr=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},kf=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:o,reconciliationContext:i})=>{let r=[],s=l=>`${l?.index}:${l?.id}:${l?.type}:${l?.isDeleted}:${l?.version}:${l?.versionNonce}`,a=e.map(l=>l.index);for(let[l,c]of a.entries()){let d=a[l-1],u=a[l+1];if(Jr(c,d,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&st(e[l])){let p=e[l],m=W(p,bi(e));m&&m.index<=p.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(m)}", "${s(p)}"`)}}if(r.length){let l=new Qr,c=[];if(i&&(c.push("Additional reconciliation context:"),c.push(i.localElements.map(d=>s(d))),c.push(i.remoteElements.map(d=>s(d)))),o||console.error(r.join(`
|
|
11
|
+
`),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=lo(e.fontSize,e.lineHeight),d=ff(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}`)}},vi=new WeakMap,Jl=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=vi.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=V(e,t),l=a?.version||null,d=xe(e)?e.crop:null,c=kt(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.boundTextElementVersion!==l||r.imageCrop!==d||r.containingFrameOpacity!==c||H(e)&&a&&e.angle!==r.angle){let u=td(e,t,o,n,i);return u?(vi.set(e,u),u):null}return r},ds=(e,t,n,i,o)=>{let r=e.element,s=zo(r),a=e.scale,[l,d,c,u]=X(r,o),m=((l+c)/2+i.scrollX)*window.devicePixelRatio,p=((d+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=V(r,o);if(H(r)&&f){let h=(e.boundTextCanvas.width-e.canvas.width)/2,E=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(m,p),t.drawImage(e.boundTextCanvas,-(c-l)/2*window.devicePixelRatio-h/a-s,-(u-d)/2*window.devicePixelRatio-E/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(m,p),t.rotate(r.angle),"scale"in e.element&&!Ef(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-m,-p),t.drawImage(e.canvas,(l+i.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(d+i.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),v.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&dt(r)){let h=V(r,o),E=Gr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((E.x+i.scrollX)*window.devicePixelRatio,(E.y+i.scrollY)*window.devicePixelRatio,nt(r,h)*window.devicePixelRatio,pi(r,h)*window.devicePixelRatio)}t.restore()},C0=(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()},G0=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=gf(e,kt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?cf: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=Ti.strokeWidth/s.zoom.value,o.strokeStyle=s.theme===No.DARK?Ho(Ti.strokeColor):Ti.strokeColor,va(e)&&(o.strokeStyle=s.theme===No.LIGHT?"#7affd7":Ho("#1d8264")),Ti.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Ti.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]=X(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),h=(u-d)/2-(e.y-d);o.save(),o.translate(m,p),o.rotate(e.angle),o.translate(-f,-h),Fo(e,i,o,r),o.restore()}else{let l=Jl(e,n,r,s);if(!l)return;ds(l,o,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=X(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),h=(u-d)/2-(e.y-d);if(ee(e)){let g=Se(e,t);if(H(g)){let x=O.getBoundTextElementPosition(g,e,t);f=(c-l)/2-(x.x-l),h=(u-d)/2-(x.y-d)}}o.save(),o.translate(m,p);let E=V(e,t);if(H(e)&&E){let g=document.createElement("canvas"),x=g.getContext("2d"),w=Math.max(dn(l,c),dn(d,u)),b=zo(e);g.width=w*s.exportScale+b*10*s.exportScale,g.height=w*s.exportScale+b*10*s.exportScale,x.translate(g.width/2,g.height/2),x.scale(s.exportScale,s.exportScale),f=e.width/2-(e.x-l),h=e.height/2-(e.y-d),x.rotate(e.angle);let y=wn.canvas(g);x.translate(-f,-h),Fo(e,y,x,r),x.translate(f,h),x.rotate(-e.angle);let[,,,,I,S]=X(E,t),A=(l+c)/2-I,M=(d+u)/2-S;x.translate(-A,-M),x.clearRect(-E.width/2,-E.height/2,E.width,E.height),o.scale(1/s.exportScale,1/s.exportScale),o.drawImage(g,-g.width/2,-g.height/2,g.width,g.height)}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-f,-h),Fo(e,i,o,r);o.restore()}else{let l=Jl(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||df(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&xe(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=td(Ma(l.element,t),n,s.zoom,r,s);c&&ds(c,o,r,s,n),o.restore()}ds(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function O0(e,t,n){let i=ae({...e,angle:0},n),o=ko((i[0]+i[2])/2,(i[1]+i[3])/2);return hf(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(Ql(r[r.length-1][1],ls(ko(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[Ql(ls(ko(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),ls(ko(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}P();var F0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",N0=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable",H0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",z0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",od=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",_0=e=>e==="arrow",U0=e=>e==="arrow";var Ye=class e{static rg=new Ve;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),vi.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;vi.delete(t);let o=Af(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:Pf.white,embedsValidationStatus:null,theme:cs.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||cs.LIGHT}),o}},Sf=e=>[8,8+e],dd=e=>[1.5,6+e];function Mf(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&&od(e.type)||Q(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Fe=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?Sf(e.strokeWidth):e.strokeStyle==="dotted"?dd(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:Mf(e),stroke:n?_o(e.strokeColor):e.strokeColor,preserveVertices:t||e.roughness<yf.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=Di(e.backgroundColor)?void 0:n?_o(e.backgroundColor):e.backgroundColor,e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return bn(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:n?_o(e.backgroundColor):e.backgroundColor),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},sd=(e,t,n)=>no(e)&&(t||Ta(e)&&n?.get(e.id)!==!0)&&Di(e.backgroundColor)&&Di(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:to(e)?{...e,strokeColor:Di(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Di(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,ad=(e,t,n,i,o,r,s,a)=>{let l=us(e,t,n,i);if(l===null)return[];let d=(u,m)=>{if(u===null)return[];let[,,p,f,h,E]=u;return[o.line(p,f,h,E,m)]},c=a?_o(e.strokeColor):e.strokeColor;switch(i){case"dot":case"circle":case"circle_outline":{let[u,m,p]=l;return delete r.strokeLineDash,[o.circle(u,m,p,{...r,fill:i==="circle_outline"?s:c,fillStyle:"solid",stroke:c,roughness:Math.min(.5,r.roughness||0)})]}case"triangle":case"triangle_outline":{let[u,m,p,f,h,E]=l;return delete r.strokeLineDash,[o.polygon([[u,m],[p,f],[h,E],[u,m]],{...r,fill:i==="triangle_outline"?s:c,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[u,m,p,f,h,E,g,x]=l;return delete r.strokeLineDash,[o.polygon([[u,m],[p,f],[h,E],[g,x],[u,m]],{...r,fill:i==="diamond_outline"?s:c,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"crowfoot_one":return d(l,r);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[u,m,p,f,h,E]=l;if(e.strokeStyle==="dotted"){let g=dd(e.strokeWidth-1);r.strokeLineDash=[g[0],g[1]-1]}else delete r.strokeLineDash;return r.roughness=Math.min(1,r.roughness||0),[o.line(p,f,u,m,r),o.line(h,E,u,m,r),...i==="crowfoot_one_or_many"?d(us(e,t,n,"crowfoot_one"),r):[]]}}},Fa=e=>{let t=new Ve,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=ut(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:[le(0,0)];return Y(e)?t.path(cd(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=Rt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:le(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Rt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Rt(le(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Rt(le(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>le(a[0]-e.x,a[1]-e.y)).flat()}}):o.map((r,s)=>{let a=Rt(le(e.x+r[0],e.y+r[1]),i,e.angle);return{op:s===0?"move":"lineTo",data:le(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let o=ni(e.points,.75);return t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Rt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:le(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Rt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Rt(le(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Rt(le(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>le(a[0]-e.x,a[1]-e.y)).flat()}})}}},Af=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===cs.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=St(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`,Fe(sd(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,Fe(sd(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,f,h]=kn(e);if(e.roundness){let E=St(Math.abs(l-f),e),g=St(Math.abs(u-d),e);a=t.path(`M ${l+E} ${d+g} L ${c-E} ${u-g}
|
|
12
|
+
C ${c} ${u}, ${c} ${u}, ${c-E} ${u+g}
|
|
13
|
+
L ${m+E} ${p-g}
|
|
14
|
+
C ${m} ${p}, ${m} ${p}, ${m-E} ${p-g}
|
|
15
|
+
L ${f+E} ${h+g}
|
|
16
|
+
C ${f} ${h}, ${f} ${h}, ${f+E} ${h-g}
|
|
17
|
+
L ${l-E} ${d+g}
|
|
18
|
+
C ${l} ${d}, ${l} ${d}, ${l+E} ${d+g}`,Fe(e,!0,s))}else a=t.polygon([[l,d],[c,u],[m,p],[f,h]],Fe(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Fe(e,!1,s));case"line":case"arrow":{let a,l=Fe(e,!1,s),d=e.points.length?e.points:[le(0,0)];if(Y(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(cd(d,16),Fe(e,!0,s))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(d)),a=[]):e.roundness?a=[t.curve(d,l)]:l.fill?a=[t.polygon(d,l)]:a=[t.linearPath(d,l)],e.type==="arrow"){let{startArrowhead:c=null,endArrowhead:u="arrow"}=e;if(c!==null){let m=ad(e,a,"start",c,t,l,i,s);a.push(...m)}if(u!==null){let m=ad(e,a,"end",u,t,l,i,s);a.push(...m)}}return a}case"freedraw":{let a=[];if(bn(e.points)){let l=ni(e.points,.75);a.push(t.curve(l,{...Fe(e,!1,s),stroke:"none"}))}return a.push(Tf(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return bf(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},cd=(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=it(a,r),d=it(s,a),c=Math.min(t,rd(e[o],s)/2,rd(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(" ")},ud=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return da(e);case"arrow":case"line":{let n=Ye.generateElementShape(e,null)[0],[,,,,i,o]=X(e,t);return fo(e)?pa(e,n,le(e.x,e.y),e.angle,le(i,o)):ua(n,le(e.x,e.y),e.angle,le(i,o))}case"ellipse":return ca(e);case"freedraw":{let[,,,,n,i]=X(e,t);return ma(e,le(n,i),fo(e))}}},Dl=(e,t)=>{let n=[...e.points];if(t){if(!Ba(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>If||n.length<4?n.push(le(o[0],o[1])):n[n.length-1]=le(o[0],o[1])}return{polygon:t,points:n}},Tf=e=>Lf(vf(e)),vf=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 ya(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:n=>Math.sin(n*Math.PI/2),last:!0})},ld=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],Df=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,Lf=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,ld(i,r[0]),"L",r[0],"Z"):n.push(i,ld(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(Df,"$1")};var fs=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]=X(t,n);if(Ie(t)){let[c,u,m,p]=hs(t.points.map(([f,h])=>oe(D(f,h),D(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,m+t.x,p+t.y]}else if(Q(t))i=Hf(t,l,d,n);else if(t.type==="diamond"){let[c,u]=oe(D(l,r),D(l,d),t.angle),[m,p]=oe(D(l,a),D(l,d),t.angle),[f,h]=oe(D(o,d),D(l,d),t.angle),[E,g]=oe(D(s,d),D(l,d),t.angle),x=Math.min(c,m,f,E),w=Math.min(u,p,h,g),b=Math.max(c,m,f,E),y=Math.max(u,p,h,g);i=[x,w,b,y]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,m=Math.cos(t.angle),p=Math.sin(t.angle),f=Math.hypot(c*m,u*p),h=Math.hypot(u*m,c*p);i=[l-f,d-h,l+f,d+h]}else{let[c,u]=oe(D(o,r),D(l,d),t.angle),[m,p]=oe(D(o,a),D(l,d),t.angle),[f,h]=oe(D(s,a),D(l,d),t.angle),[E,g]=oe(D(s,r),D(l,d),t.angle),x=Math.min(c,m,f,E),w=Math.min(u,p,h,g),b=Math.max(c,m,f,E),y=Math.max(u,p,h,g);i=[x,w,b,y]}return i}},X=(e,t,n=!1)=>{if(Ie(e))return kf(e);if(Q(e))return O.getElementAbsoluteCoords(e,t,n);if(ee(e)){let i=t?Se(e,t):null;if(H(i)){let{x:o,y:r}=O.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]},ss=(e,t)=>{let n=ud(e,t),[i,o,r,s,a,l]=X(e,t),d=D(a,l);if(n.type==="polycurve"){let g=n.data.map(w=>wt(w,10)),x=[];if(Pt(e)&&!e.polygon||H(e))for(let w of g){let b=0;for(;b<w.length-1;)x.push(Ee(D(w[b][0],w[b][1]),D(w[b+1][0],w[b+1][1]))),b++}else{let w=g.flat(),b=0;for(;b<w.length-1;)x.push(Ee(D(w[b][0],w[b][1]),D(w[b+1][0],w[b+1][1]))),b++}return x}else{if(n.type==="polyline")return n.data;if(Gf(e)){let[E,g]=Vt(e),x=g.map(b=>fd(b,d,e.angle)).flat();return[...pd(E,d,e.angle),...x]}else if(e.type==="diamond"){let[E,g]=$t(e),x=g.map(b=>fd(b,d,e.angle)).flat();return[...pd(E,d,e.angle),...x]}else if(n.type==="polygon"){if(ee(e)){let x=Se(e,t);if(x&&Q(x))return[Ee(D(i,o),D(r,o)),Ee(D(r,o),D(r,s)),Ee(D(r,s),D(i,s)),Ee(D(i,s),D(i,o))]}let E=n.data,g=[];for(let x=0;x<E.length-1;x++)g.push(Ee(E[x],E[x+1]));return g}else if(n.type==="ellipse")return Of(e)}let[c,u,m,p,,,f,h]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(E=>oe(E,d,e.angle));return[Ee(c,u),Ee(m,p),Ee(c,m),Ee(u,p),Ee(c,h),Ee(m,h),Ee(u,f),Ee(p,f)]},Gf=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),pd=(e,t,n)=>e.map(i=>Ee(oe(i[0],t,n),oe(i[1],t,n))),fd=(e,t,n)=>{let i=wt(e,10),o=0,r=[];for(;o<i.length-1;)r.push(Ee(oe(D(i[o][0],i[o][1]),t,n),oe(D(i[o+1][0],i[o+1][1]),t,n))),o++;return r},Of=e=>{let t=D(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(oe(D(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(Ee(r[l],r[l+1]));return o.push(Ee(r[r.length-1],r[0])),o},x1=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],kn=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]},hd=(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},Ed=(e,t,n,i)=>{let o=t-e,r=n-t,s=i-n,a=3*o-6*r+3*s,l=6*r-6*o,d=3*o,c=l*l-4*a*d;if(!(c>=0))return!1;let m=null,p=null,f=1/0,h=1/0;return a===0?f=h=-d/l:(f=(-l+Math.sqrt(c))/(2*a),h=(-l-Math.sqrt(c))/(2*a)),f>=0&&f<=1&&(m=hd(f,e,t,n,i)),h>=0&&h<=1&&(p=hd(h,e,t,n,i)),[m,p]},Eo=(e,t,n,i)=>{let o=Ed(e[0],t[0],n[0],i[0]),r=Ed(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=D(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=xd(d);ps(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=D(d[0],d[1]),u=D(d[2],d[3]),m=D(d[4],d[5]),p=t?t(c):c,f=t?t(u):u,h=t?t(m):m,E=t?t(n):n;n=m;let[g,x,w,b]=Eo(E,p,f,h);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,w),a.maxY=Math.max(a.maxY,b)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},hs=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]},kf=e=>{let[t,n,i,o]=hs(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]},Rf=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}},Ff=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},us=(e,t,n,i)=>{if(t.length<1)return null;let o=yt(t[0]);if(o.length<1)return null;let r=n==="start"?1:o.length-1,s=o[r].data;ps(s.length===6,"Op data length is not 6");let a=D(s[4],s[5]),l=D(s[2],s[3]),d=D(s[0],s[1]),c=o[r-1],u=D(0,0);if(c.op==="move"){let N=xd(c.data);ps(N!=null,"Op data is not a point"),u=N}else c.op==="bcurveTo"&&(u=D(c.data[4],c.data[5]));let m=(N,W)=>Math.pow(1-N,3)*a[W]+3*N*Math.pow(1-N,2)*l[W]+3*Math.pow(N,2)*(1-N)*d[W]+u[W]*Math.pow(N,3),[p,f]=n==="start"?u:a,[h,E]=[m(.3,0),m(.3,1)],g=Math.hypot(p-h,f-E),x=(p-h)/g,w=(f-E)/g,b=Rf(i),y=0;{let[N,W]=n==="end"?e.points[e.points.length-1]:e.points[0],[F,T]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];y=Math.hypot(N-F,W-T)}let S=Math.min(b,y*(i==="diamond"||i==="diamond_outline"?.25:.5)),A=p-x*S,M=f-w*S;if(i==="dot"||i==="circle"||i==="circle_outline"){let N=Math.hypot(M-f,A-p)+e.strokeWidth-2;return[p,f,N]}let k=Ff(i);if(i==="crowfoot_many"||i==="crowfoot_one_or_many"){let[N,W]=oe(D(p,f),D(A,M),ms(-k)),[F,T]=oe(D(p,f),D(A,M),ms(k));return[A,M,N,W,F,T]}let[L,G]=oe(D(A,M),D(p,f),-k*Math.PI/180),[B,U]=oe(D(A,M),D(p,f),ms(k));if(i==="diamond"||i==="diamond_outline"){let N,W;if(n==="start"){let[F,T]=e.points.length>1?e.points[1]:[0,0];[N,W]=oe(D(p+S*2,f),D(p,f),Math.atan2(T-f,F-p))}else{let[F,T]=e.points.length>1?e.points[e.points.length-2]:[0,0];[N,W]=oe(D(p-S*2,f),D(p,f),Math.atan2(f-T,p-F))}return[p,f,L,G,N,W,B,U]}return[p,f,L,G,B,U]},Nf=e=>{let t=wn.generator(),n=Fe(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},Hf=(e,t,n,i)=>{let o=V(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,f]=oe(D(e.x+u,e.y+m),D(t,n),e.angle),h=[p,f,p,f];if(o){let E=O.getMinMaxXYWithBoundText(e,i,[p,f,p,f],o);h=[E[0],E[1],E[2],E[3]]}return h}let s=Ye.get(e,null)?.[0]??Nf(e),a=yt(s),d=Ai(a,([u,m])=>oe(D(e.x+u,e.y+m),D(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=O.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},ae=(e,t,n=!1)=>fs.getBounds(e,t,n),De=(e,t)=>{if(!Bf(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||gd(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]},w1=(e,t)=>{let[n,i,o,r]=De(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},jt=(e,t,n,i)=>{if(!(Q(e)||Ie(e)))return[e.x,e.y,e.x+t,e.y+n];let o=md(0,t,md(1,n,e.points,i),i),r;if(Ie(e))r=hs(o);else{let c=wn.generator(),u=e.roundness?c.curve(o,Fe(e)):c.linearPath(o,Fe(e)),m=yt(u);r=Ai(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},es=(e,t)=>{let n=wn.generator(),i=e.roundness==null?n.linearPath(t,Fe(e)):n.curve(t,Fe(e)),o=yt(i),[r,s,a,l]=Ai(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},y1=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=gd(e);return e.forEach(r=>{let[s,a,l,d]=ae(r,o),c=Cf(D((s+l)/2,(a+d)/2),D(t.x,t.y));c<n&&(n=c,i=r)}),ae(i,o)},Ft=e=>{let[t,n,i,o]=De(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},b1=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],ut=e=>D(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),qe=(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=de(e,t),[r,s]=oe(D(i.minX,i.minY),o,e.angle),[a,l]=oe(D(i.maxX,i.minY),o,e.angle),[d,c]=oe(D(i.maxX,i.maxY),o,e.angle),[u,m]=oe(D(i.minX,i.maxY),o,e.angle),p=[Math.min(r,a,d,u),Math.min(s,l,c,m),Math.max(r,a,d,u),Math.max(s,l,c,m)];if(n){let[f,h,E,g]=n;return[p[0]-g,p[1]-f,p[2]+h,p[3]+E]}return p},Kt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],Mn=(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},de=(e,t,n=0,i=0)=>{if(Q(e)){let[s,a,l,d]=X(e,t),[c,u]=D((s+l)/2,(a+d)/2);return D(c+n,u+i)}let[o,r]=ut(ae(e,t));return D(o+n,r+i)};var Wf=.1,yd=e=>Q(e)||Ie(e)?e.points.length<2||e.points.length===2&&H(e)&&Uf(e.points[0],e.points[e.points.length-1],Wf):e.width===0&&e.height===0,Vl=(e,t,n,i,o)=>{let[r,s,a,l]=ae(e,o),d=Uo({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=Uo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},D1=(e,t,n,i,o,r)=>{let[s,a,l,d]=De(e,o),c=Uo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=Uo({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},Es=(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)/Nt)*Nt;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}},Ll=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Nt)*Nt;if(o){let d=Math.floor(o/Nt)*Nt;zf(a,d,d+Nt)&&(_f(a,o)<Nt/6?l=o:wd(a)>wd(o)?l=d+Nt:l=d)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,m=-1/d,p=-1,f=i-m*n,h=(c*f-p*u)/(d*p-m*c),E=(u*m-f*d)/(d*p-m*c);r=h-e,s=E-t}return{width:r,height:s}},L1=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 R1=(e,t,n,i)=>{let o=Go(e,n.getNonDeletedElementsMap(),i),r=Ft(e);return o.flatMap(s=>{let a=Yf(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return je(l,n,{simultaneouslyUpdated:s}),d})})},Yf=(e,t,{axis:n,position:i})=>{let o=Ft(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 Nh,arrayToObject as Ht,assertNever as Kd,isDevEnv as pn,isShallowEqual as Qd,isTestEnv as fn,randomInteger as qd}from"@excalidraw/common";P();import{assertNever as th,COLOR_PALETTE as nh,isDevEnv as ih,isTestEnv as oh,randomId as rh,Emitter as Id,toIterable as Yn}from"@excalidraw/common";P();import{ORIG_ID as $f,randomId as Pd,randomInteger as Zf,arrayToMap as qf,castArray as gs,findLastIndex as Li,getUpdatedTimestamp as Kf,isTestEnv as Qf}from"@excalidraw/common";P();import{arrayToMapWithIndex as jf}from"@excalidraw/common";var Xf=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]},Vf=e=>{let t=jf(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]},bd=e=>Vf(Xf(e));var Jf=(e,t,n,i)=>{let o=ws(n);return Qf()&&eh(o,n.id),o.id=Pd(),o.updated=Kf(),i&&(o.seed=Zf(),dl(o)),o.groupIds=jl(o.groupIds,e,r=>(t.has(r)||t.set(r,Pd()),t.get(r))),o},q1=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=qf(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(E=>[E.id,E]));if(e.type==="in-place")for(let E of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(E)).forEach(g=>u.set(g.id,g));t=bd(t);let m=t.slice(),p=E=>{let x=gs(E).reduce((w,b)=>{if(i.has(b.id))return w;i.set(b.id,!0);let y=Jf(n.editingGroupId,o,b,e.randomizeSeed);return i.set(y.id,!0),d.set(y.id,y),a.set(b.id,y.id),l.set(y.id,b),s.push(b),r.push(y),w.push(y),w},[]);return Array.isArray(E)?x:x[0]||null},f=(E,g)=>{if(g){if(E>m.length-1){m.push(...gs(g));return}m.splice(E+1,0,...gs(g))}},h=new Set(t.filter(E=>u.has(E.id)&&K(E)).map(E=>E.id));for(let E of t){if(i.has(E.id)||!u.has(E.id))continue;let g=is(n,E);if(g){let x=ve(t,g).flatMap(b=>K(b)?[...an(t,b.id),b]:[b]),w=Li(m,b=>b.groupIds?.includes(g));f(w,p(x));continue}if(!(E.frameId&&h.has(E.frameId))){if(K(E)){let x=E.id,w=an(t,x),b=Li(m,y=>y.frameId===x||y.id===x);f(b,p([...w,E]));continue}if(dt(E)){let x=V(E,c),w=Li(m,b=>b.id===E.id||"containerId"in b&&b.containerId===E.id);x?f(w,p([E,x])):f(w,p(E));continue}if(ce(E)){let x=Se(E,c),w=Li(m,b=>b.id===E.id||b.id===x?.id);x?f(w,p([x,E])):f(w,p(E));continue}f(Li(m,x=>x.id===E.id),p(E))}}if(gl(r,a,d),$l(m,s,a),e.overrides)for(let E of r){let g=l.get(E.id);g&&Object.assign(E,e.overrides({duplicateElement:E,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:m,origIdToDuplicateId:a}},xs=(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]=xs(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=xs(e[i],t+1);return o}return v.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},ws=e=>xs(e),eh=(e,t)=>{Object.defineProperty(e,$f,{value:t,writable:!1,enumerable:!1})};var Ne={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},Sd=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Id;onStoreIncrementEmitter=new Id;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=mn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Ne.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=mn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?Td(t.elements):void 0,t.appState);i=Bi.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=mn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=Bi.create(o,t),i?s=i:s=Ps.calculate(o,t),!s.isEmpty()){let a=new ys(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=Bi.create(r,t)}let o=new bs(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===Ne.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 Ne.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Ne.NEVER:case Ne.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:th(n,"Unknown store action")}}finally{switch(n){case Ne.IMMEDIATELY:case Ne.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Ne.IMMEDIATELY)?t=Ne.IMMEDIATELY:this.scheduledMacroActions.has(Ne.NEVER)?t=Ne.NEVER:t=Ne.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Ne).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()),oh()||ih())throw new Error(t)}}},Bi=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},Wo=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},ys=class extends Wo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},bs=class extends Wo{constructor(n){super("ephemeral",n);this.change=n}},Ps=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:rh()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?un.calculate(t.elements,n.elements):un.empty(),o=n.metadata.didAppStateChange?cn.calculate(t.appState,n.appState):cn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,un.restore(i),cn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=un.create(n,i,o),a=cn.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,mn.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(un.empty(),cn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},mn=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,Md(n)?n:jn(n),i)}static empty(){return new e(new Map,sh(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of Yn(t.elements))this.elements.get(i.id)||(n[i.id]=ge(i,{isDeleted:!0}));for(let i of Yn(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return _.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=jn({...this.appState,...t.appState});return e.create(n,i,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,i){let o={shouldCompareHashes:!1};t===Ne.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=Md(t)?t:jn(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=_.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 Yn(this.elements))t.get(r.id)||i.set(r.id,ge(r,{isDeleted:!0}));for(let r of Yn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(xe(r)&&!yn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=vd(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of Yn(this.elements))n.set(i.id,i);for(let i of Yn(t))n.set(i.id,ws(i));return n}},Ad="__observedAppState",sh=()=>({name:null,editingGroupId:null,viewBackgroundColor:nh.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),jn=e=>{let t={name:e.name,editingGroupId:e.editingGroupId,viewBackgroundColor:e.viewBackgroundColor,selectedElementIds:e.selectedElementIds,selectedGroupIds:e.selectedGroupIds,croppingElementId:e.croppingElementId,activeLockedId:e.activeLockedId,lockedMultiSelections:e.lockedMultiSelections,selectedLinearElement:e.selectedLinearElement?{elementId:e.selectedLinearElement.elementId,isEditing:!!e.selectedLinearElement.isEditing}:null};return Reflect.defineProperty(t,Ad,{value:!0,enumerable:!1}),t},Md=e=>!!Reflect.get(e,Ad);P();P();var Cd="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Vn(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)+Vn(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]+Vn(e.slice(1),null,n)}function Gd(e){if(e.length!==Od(e[0]))throw new Error("invalid integer part of order key: "+e)}function Od(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 Ci(e){let t=Od(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function Ld(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=Ci(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function Bd(e,t){Gd(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 ah(e,t){Gd(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 Xn(e,t,n=Cd){if(e!=null&&Ld(e,n),t!=null&&Ld(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=Ci(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Vn("",d,n);if(l<t)return l;let c=ah(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=Ci(e),d=e.slice(l.length),c=Bd(l,n);return c??l+Vn(d,null,n)}let i=Ci(e),o=e.slice(i.length),r=Ci(t),s=t.slice(r.length);if(i===r)return i+Vn(o,s,n);let a=Bd(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+Vn(o,null,n)}function Yo(e,t,n,i=Cd){if(n===0)return[];if(n===1)return[Xn(e,t,i)];if(t==null){let s=Xn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Xn(s,t,i),a.push(s);return a}if(e==null){let s=Xn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Xn(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=Xn(e,t,i);return[...Yo(e,r,o,i),r,...Yo(r,t,n-o-1,i)]}import{arrayToMap as jo}from"@excalidraw/common";var Is=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},lh=(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(Ss(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&dt(e[l])){let m=e[l],p=V(m,jo(e));p&&p.index<=m.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(p)}", "${s(m)}"`)}}if(r.length){let l=new Is,d=[];if(o&&(d.push("Additional reconciliation context:"),d.push(o.localElements.map(c=>s(c))),d.push(o.remoteElements.map(c=>s(c)))),i||console.error(r.join(`
|
|
19
19
|
|
|
20
|
-
`),l.stack,e.map(d=>s(d)),...c),t)throw l}},pc=e=>e.sort((t,n)=>uc(t)&&uc(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),po=(e,t)=>{try{let n=bi(e),o=Nf(e,t),i=es(e,o),r=e.map(s=>{let a=i.get(s);return a?{...s,index:a.index}:s});kf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of i)ye(s,n,{index:a})}catch{Ff(e)}return e},Ff=e=>{let t=bi(e),n=mc(e),o=es(e,n);for(let[i,{index:r}]of o)ye(i,t,{index:r});return e},oc=e=>{let t=bi(e),n=mc(e),o=es(e,n);for(let[i,{index:r}]of o)t.set(i.id,Me(i,{index:r}));return t},Nf=(e,t)=>{let n=[],o=0;for(;o<e.length;)if(t.has(e[o].id)){let i=[o-1,o];for(;++o<e.length&&t.has(e[o].id);)i.push(o);i.push(o),n.push(i)}else o++;return n},mc=e=>{let t=[],n,o,i=-1,r=0,s=c=>{let d=e[i]?e[i].index:void 0,u=e[c-1]?.index;return!d&&u||d&&u&&u>d?[u,c-1]:[d,i]},a=c=>{let d=e[r]?e[r].index:void 0;if(d&&c<r)return[d,r];let u=r;for(;++u<e.length;){let p=e[u]?.index;if(!d&&p||d&&p&&p>d)return[p,u]}return[void 0,u]},l=0;for(;l<e.length;){let c=e[l].index;if([n,i]=s(l),[o,r]=a(l),Jr(c,n,o))l++;else{let d=[i,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[f,E]=a(l);if(Jr(u,p,f))break;[n,i]=[p,m],[o,r]=[f,E],d.push(l)}d.push(r),t.push(d)}}return t},Jr=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,es=(e,t)=>{let n=new Map;for(let o of t){let i=o.shift(),r=o.pop(),s=yi(e[i]?.index,e[r]?.index,o.length);for(let a=0;a<o.length;a++){let l=e[o[a]];n.set(l,{index:s[a]})}}return n},uc=e=>!!e.index;P();var Mc=gd(xc(),1);import{randomInteger as nh,arrayToMap as wc,toBrandedType as yc,isDevEnv as bc,isTestEnv as Pc,toArray as oh}from"@excalidraw/common";import{isNonDeletedElement as ih}from"@excalidraw/element";import{isFrameLikeElement as rh}from"@excalidraw/element";import{getElementsInGroup as sh}from"@excalidraw/element";import{syncInvalidIndices as ah,syncMovedIndices as Ic,validateFractionalIndices as lh}from"@excalidraw/element";import{getSelectedElements as ch}from"@excalidraw/element";import{mutateElement as dh}from"@excalidraw/element";var Sc=e=>{let t=new Map,n=[];for(let o of e)o.isDeleted||(n.push(o),t.set(o.id,o));return{elementsMap:t,elements:n}},uh=(0,Mc.default)(e=>{(bc()||Pc()||window?.DEBUG_FRACTIONAL_INDICES)&&lh(e,{shouldThrow:bc()||Pc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),ph=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let o of t)n+=`${o}:${e[o]?"1":"0"}`;return n},Ii=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=yc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=yc(new Map);selectedElementsCache={selectedElementIds:null,elements:null,cache:new Map};sceneNonce;getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}constructor(t=null){t&&this.replaceAllElements(t)}getSelectedElements(t){let n=ph(t),o=t?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===o&&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 i=ch(o,{selectedElementIds:t.selectedElementIds},t);return t?.elements==null&&(this.selectedElementsCache.selectedElementIds=t.selectedElementIds,this.selectedElementsCache.elements=this.nonDeletedElements,this.selectedElementsCache.cache.set(n,i)),i}getNonDeletedFramesLikes(){return this.nonDeletedFramesLikes}getElement(t){return this.elementsMap.get(t)||null}getNonDeletedElement(t){let n=this.getElement(t);return n&&ih(n)?n:null}mapElements(t){let n=!1,o=this.elements.map(i=>{let r=t(i);return r!==i&&(n=!0),r});return n&&this.replaceAllElements(o),n}replaceAllElements(t){let n=oh(t),o=[];uh(n),this.elements=ah(n),this.elementsMap.clear(),this.elements.forEach(r=>{rh(r)&&o.push(r),this.elementsMap.set(r.id,r)});let i=Sc(this.elements);this.nonDeletedElements=i.elements,this.nonDeletedElementsMap=i.elementsMap,this.frames=o,this.nonDeletedFramesLikes=Sc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=nh();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 o=[...this.elements.slice(0,n),t,...this.elements.slice(n)];Ic(o,wc([t])),this.replaceAllElements(o)}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 o=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];Ic(o,wc(t)),this.replaceAllElements(o)}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(),o=n.get(t);return o?[o]:sh(n,t)};mutateElement(t,n,o={informMutation:!0,isDragging:!1}){let i=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=dh(t,i,n,o);return this.elementsMap.has(t.id)&&r!==s&&o.informMutation&&this.triggerUpdate(),t}};var q=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,o,i){let r=o&&i!=="inserted"?o(t,"deleted"):t,s=o&&i!=="deleted"?o(n,"inserted"):n;return new e(r,s)}static calculate(t,n,o,i){if(t===n)return e.empty();let r={},s={};for(let c of this.getDifferences(t,n))r[c]=t[c],s[c]=n[c];let[a,l]=i?i(r,s):[r,s];return e.create(a,l,o)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n){return e.create({...t.deleted,...n.deleted},{...t.inserted,...n.inserted})}static mergeObjects(t,n,o){let i={...t};for(let r of Object.keys(o))delete i[r];return{...i,...n}}static mergeArrays(t,n,o,i){return Object.values(e.mergeObjects(Gt(t??[],i),Gt(n??[],i),Gt(o??[],i)))}static diffObjects(t,n,o,i){if(!t[o]&&!n[o])return;let r=t[o]!==null&&typeof t[o]=="object",s=n[o]!==null&&typeof n[o]=="object";if(r||s){let a=t[o]??{},l=n[o]??{},c=e.getLeftDifferences(a,l).reduce((u,p)=>(u[p]=i(a[p]),u),{}),d=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=i(l[p]),u),{});Object.keys(c).length||Object.keys(d).length?(Reflect.set(t,o,c),Reflect.set(n,o,d)):(Reflect.deleteProperty(t,o),Reflect.deleteProperty(n,o))}else t[o]===n[o]&&(Reflect.deleteProperty(t,o),Reflect.deleteProperty(n,o))}static diffArrays(t,n,o,i){if(!(!t[o]&&!n[o])&&(Array.isArray(t[o])||Array.isArray(n[o]))){let r=Array.isArray(t[o])?t[o]:[],s=Array.isArray(n[o])?n[o]:[],a=Gt(e.getLeftDifferences(Gt(r,i),Gt(s,i)),c=>c),l=Gt(e.getRightDifferences(Gt(r,i),Gt(s,i)),c=>c);if(Object.keys(a).length||Object.keys(l).length){let c=r.filter(u=>a[i?i(u):String(u)]),d=s.filter(u=>l[i?i(u):String(u)]);Reflect.set(t,o,c),Reflect.set(n,o,d)}else Reflect.deleteProperty(t,o),Reflect.deleteProperty(n,o)}}static isLeftDifferent(t,n,o=!1){return!!this.distinctKeysIterator("left",t,n,o).next().value}static isRightDifferent(t,n,o=!1){return!!this.distinctKeysIterator("right",t,n,o).next().value}static isInnerDifferent(t,n,o=!1){return!!!!this.distinctKeysIterator("inner",t,n,o).next().value}static isDifferent(t,n,o=!1){return!!!!this.distinctKeysIterator("full",t,n,o).next().value}static getLeftDifferences(t,n,o=!1){return Array.from(this.distinctKeysIterator("left",t,n,o)).sort()}static getRightDifferences(t,n,o=!1){return Array.from(this.distinctKeysIterator("right",t,n,o)).sort()}static getInnerDifferences(t,n,o=!1){return Array.from(this.distinctKeysIterator("inner",t,n,o)).sort()}static getDifferences(t,n,o=!1){return Array.from(this.distinctKeysIterator("full",t,n,o)).sort()}static*distinctKeysIterator(t,n,o,i=!1){if(n===o)return;let r=[];t==="left"?r=Object.keys(n):t==="right"?r=Object.keys(o):t==="inner"?r=Object.keys(n).filter(s=>s in o):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(o)])):Ac(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let s of r){let a=n[s],l=o[s];if(a!==l){if(!i&&typeof a=="object"&&typeof l=="object"&&a!==null&&l!==null&&Dc(a,l))continue;yield s}}}},fn=class e{constructor(t){this.delta=t}static calculate(t,n){let o=q.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(o)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(q.create({},{}))}inverse(){let t=q.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){return this.delta=q.merge(this.delta,t.delta),this}applyTo(t,n){try{let{selectedElementIds:o={},selectedGroupIds:i={}}=this.delta.deleted,{selectedElementIds:r={},selectedGroupIds:s={},selectedLinearElement:a,...l}=this.delta.inserted,c=q.mergeObjects(t.selectedElementIds,r,o),d=q.mergeObjects(t.selectedGroupIds,s,i),u=a&&n.has(a.elementId)?new Y(n.get(a.elementId),n,a.isEditing):null,p={...t,...l,selectedElementIds:c,selectedGroupIds:d,selectedLinearElement:typeof a<"u"?u:t.selectedLinearElement},m=this.filterInvisibleChanges(t,p,n);return[p,m]}catch(o){if(console.error("Couldn't apply appstate change",o),Fn()||kn())throw o;return[t,!1]}}isEmpty(){return q.isEmpty(this.delta)}filterInvisibleChanges(t,n,o){let i=Gn(t),r=Gn(n),s=q.isRightDifferent(e.stripElementsProps(i),e.stripElementsProps(r)),a=q.isRightDifferent(e.stripStandaloneProps(i),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let c=q.getRightDifferences(e.stripStandaloneProps(i),e.stripStandaloneProps(r)),d=new Set;(c.includes("editingGroupId")||c.includes("selectedGroupIds"))&&(d=hl(o));for(let u of c)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],o,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],d,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let y=o.get(x);y&&!y.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?d.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=o.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},E=n[u]||{};Dc(f,E)||(l.value=!0);break;case"activeLockedId":let h=t[u]||null,g=n[u]||null;h!==g&&(l.value=!0);break;default:Ac(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,o){let i=Object.keys(t);if(!i.length)return o.value=!0,t;let r={...t};for(let s of i){let a=n.get(s);a&&!a.isDeleted?o.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,o){if(!Object.keys(t).length)return o.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?o.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:o,selectedElementIds:i,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...c}=t;return c}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:o,...i}=t;return i}static postProcess(t,n){try{q.diffObjects(t,n,"selectedElementIds",o=>!0),q.diffObjects(t,n,"selectedGroupIds",o=>o??!1),q.diffObjects(t,n,"lockedMultiSelections",o=>o??{}),q.diffObjects(t,n,"activeLockedId",o=>o??null)}catch(o){if(console.error("Couldn't postprocess appstate change deltas."),Fn()||kn())throw o}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let o of Object.keys(t).sort())n[o]=t[o];return n}},hn=class e{constructor(t,n,o){this.added=t;this.removed=n;this.updated=o}static create(t,n,o,i={shouldRedistribute:!1}){let r;if(i.shouldRedistribute){let s={},a={},l={},c=[...Object.entries(t),...Object.entries(n),...Object.entries(o)];for(let[d,u]of c)this.satisfiesAddition(u)?s[d]=u:this.satisfiesRemoval(u)?a[d]=u:l[d]=u;r=new e(s,a,l)}else r=new e(t,n,o);return(Fn()||kn())&&(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:o,updated:i}=t;return e.create(n,o,i)}static satisfiesAddition=({deleted:t,inserted:n})=>t.isDeleted===!0&&!n.isDeleted;static satisfiesRemoval=({deleted:t,inserted:n})=>!t.isDeleted&&n.isDeleted===!0;static satisfiesUpdate=({deleted:t,inserted:n})=>!!t.isDeleted==!!n.isDeleted;static satisfiesCommmonInvariants=({deleted:t,inserted:n})=>!!(t.version&&n.version&&Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static validate(t,n,o){for(let[i,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!o(r))throw console.error(`Broken invariant for "${n}" delta, element "${i}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${i}".`)}static calculate(t,n){if(t===n)return e.empty();let o={},i={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s,isDeleted:!1},c={isDeleted:!0,version:s.version+1,versionNonce:Tc()},d=q.create(l,c,e.stripIrrelevantProps);i[s.id]=d}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:Tc()},c={...s,isDeleted:!1},d=q.create(l,c,e.stripIrrelevantProps);o[s.id]=d;continue}if(a.versionNonce!==s.versionNonce){let l=q.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?o[s.id]=l:i[s.id]=l;continue}q.isEmpty(l)||(r[s.id]=l)}}return e.create(o,i,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:c}]of Object.entries(r))s[a]=q.create({...l},{...c});return s},n=t(this.added),o=t(this.removed),i=t(this.updated);return e.create(o,n,i)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,o){let i=(c,d)=>(u,p)=>{let m;switch(p){case"deleted":m=c;break;case"inserted":m=d;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let E of Object.keys(u))switch(E){case"boundElements":f[E]=u[E];break;default:f[E]=m[E]}return f},r=c=>{let d={};for(let[u,p]of Object.entries(c)){let m=t.get(u),f=n.get(u),E=null;m||f?E=q.create(p.deleted,p.inserted,i(m,f),o):E=p,q.isInnerDifferent(E.deleted,E.inserted)&&(d[u]=E)}return d},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=Jt.empty().elements,o={excludedProperties:new Set}){let i=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1};try{let a=e.createApplier(i,n,o,s),l=a(this.added),c=a(this.removed),d=a(this.updated),u=this.resolveConflicts(t,i);r=new Map([...l,...c,...d,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),Fn()||kn())throw a;return[t,!0]}try{i=e.reorderElements(i,r,s);let a=new Ii(i);e.redrawTextBoundingBoxes(a,r),e.redrawBoundArrows(a,r)}catch(a){if(console.error("Couldn't mutate elements after applying elements change",a),Fn()||kn())throw a}finally{return[i,s.containsVisibleDifference]}}squash(t){let{added:n,removed:o,updated:i}=t;for(let[r,s]of Object.entries(n)){let a=this.added[r];a?this.added[r]=q.merge(a,s):this.added[r]=s}for(let[r,s]of Object.entries(o)){let a=this.removed[r];a?this.removed[r]=q.merge(a,s):this.removed[r]=s}for(let[r,s]of Object.entries(i)){let a=this.updated[r];a?this.updated[r]=q.merge(a,s):this.updated[r]=s}return this}static createApplier=(t,n,o,i)=>r=>{let s=e.createGetter(t,n,i);return Object.entries(r).reduce((a,[l,c])=>{let d=s(l,c.inserted);if(d){let u=e.applyDelta(d,c,o,i);t.set(u.id,u),a.set(u.id,u)}return a},new Map)};static createGetter=(t,n,o)=>(i,r)=>{let s=t.get(i);return s||(s=n.get(i),s?(o.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(o.containsVisibleDifference=!0)):s=Me({id:i,version:1},{...r})),s};static applyDelta(t,n,o,i){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=q.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),Me(t,r)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:q.isRightDifferent(t,n)}resolveConflicts(t,n){let o=new Map,i=(s,a)=>{let l=n.get(s.id);if(!l)return;let c;t.get(s.id)===l?c=Me(l,a):c=ye(l,n,a),o.set(c.id,c),n.set(c.id,c)};for(let s of Object.keys(this.removed))e.unbindAffected(t,n,s,i);for(let s of Object.keys(this.added))e.rebindAffected(t,n,s,i);for(let[s]of Array.from(Object.entries(this.updated)).filter(([a,l])=>Object.keys({...l.deleted,...l.inserted}).find(c=>Za.has(c)))){let a=n.get(s);!a||a.isDeleted||e.rebindAffected(t,n,s,i)}let r=new Map(Array.from(t).filter(([s])=>o.has(s)));return this.squash(e.calculate(r,o)),o}static unbindAffected(t,n,o,i){let r=()=>t.get(o),s=()=>n.get(o);Vt.unbindAffected(n,r(),i),Vt.unbindAffected(n,s(),i),$t.unbindAffected(n,r(),i),$t.unbindAffected(n,s(),i)}static rebindAffected(t,n,o,i){let r=()=>t.get(o),s=()=>n.get(o);Vt.unbindAffected(n,r(),i),Vt.rebindAffected(n,s(),i),$t.unbindAffected(n,r(),(a,l)=>{oe(a)&&i(a,l)}),$t.rebindAffected(n,s(),i)}static redrawTextBoundingBoxes(t,n){let o=t.getNonDeletedElementsMap(),i=new Map;for(let r of n.values()){if(de(r)){let{containerId:s}=r,a=s?o.get(s):void 0;a&&i.set(a.id,{container:a,boundText:r})}if(st(r)){let s=It(r),a=s?o.get(s):void 0;a&&i.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of i.values())r.isDeleted||s.isDeleted||ga(s,r,t)}static redrawBoundArrows(t,n){for(let o of n.values())!o.isDeleted&&Le(o)&&Ue(o,t,{changedElements:n})}static reorderElements(t,n,o){if(!o.containsZindexDifference)return t;let i=Array.from(t.values()),r=pc([...i]),s=q.getRightDifferences(i,r,!0).reduce((a,l)=>{let c=i[Number(l)];return c&&n.has(c.id)&&a.set(c.id,c),a},new Map);return!o.containsVisibleDifference&&s.size&&(o.containsVisibleDifference=!0),mh(po(r,s))}static postProcess(t,n){try{q.diffArrays(t,n,"boundElements",r=>r.id);let o=t.points??[],i=n.points??[];q.isDifferent(o,i)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(o){if(console.error("Couldn't postprocess elements delta."),Fn()||kn())throw o}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:o,...i}=t;return i}};P();var oP=(e,t,n,o)=>{let[i,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Ct(e),c=ui(e,t,o).map(m=>[m,Ct(m)]).sort((m,f)=>m[1][r]-f[1][r]),d=0;for(let m of c)d+=m[1][a];let u=(l[a]-d)/(c.length-1);if(u<0){let m=c.findIndex(g=>g[1][i]===l[i]),f=c.findIndex(g=>g[1][s]===l[s]),E=(c[f][1][r]-c[m][1][r])/(c.length-1),h=c[m][1][r];return c.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=>Me(w,{x:w.x+b.x,y:w.y+b.y}))})}let p=l[i];return c.flatMap(([m,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[i],p+=u,p+=f[a],m.map(h=>Me(h,{x:h.x+E.x,y:h.y+E.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as fh,getGridPoint as hh,getFontString as Eh}from"@excalidraw/common";var mP=(e,t,n,o,i,r)=>{if(t.length===1&&G(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(u=>{if(G(u)&&u.startBinding&&u.endBinding){let p=t.find(f=>f.id===u.startBinding?.elementId),m=t.find(f=>f.id===u.endBinding?.elementId);return p&&m}return!0}),a=new Set(s),l=s.filter(u=>$(u)).map(u=>u.id);if(l.length>0)for(let u of o.getNonDeletedElements())u.frameId!==null&&l.includes(u.frameId)&&a.add(u);let c=[];for(let u of a){let p=e.originalElements.get(u.id);if(!p)return;c.push(p)}let d=gh(tt(c),n,i,r);a.forEach(u=>{if(vc(e,u,o,d),!_(u)){let p=W(u,o.getNonDeletedElementsMap());p&&vc(e,p,o,d),Ue(u,o,{simultaneouslyUpdated:Array.from(a)})}})},gh=(e,t,n,o)=>{let[i,r]=e,s=i+t.x+n.x,a=r+t.y+n.y;if(n.x===0||n.y===0){let[l,c]=hh(i+t.x,r+t.y,o);n.x===0&&(s=l),n.y===0&&(a=c)}return{x:s-i,y:a-r}},vc=(e,t,n,o)=>{let i=e.originalElements.get(t.id)??t,r=i.x+o.x,s=i.y+o.y;n.mutateElement(t,{x:r,y:s})},fP=(e,t,n)=>{let[o,i]=tt(e);return[t-o,n-i]},hP=({newElement:e,elementType:t,originX:n,originY:o,x:i,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:c,zoom:d,scene:u,widthAspectRatio:p=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-o)>Math.abs(i-n)?{width:s,height:a}=Wr(t,a,i<n?-s:s):{width:s,height:a}=Wr(t,s,r<o?-a:a),a<0&&(a=-a)));let E=i<n?n-s:n,h=r<o?o-a:o;c&&(s+=s,a+=a,E=n-s/2,h=o-a/2);let g=null;if(oe(e)){a=e.height;let x=zo(Eh({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(i-n)>fh/d&&(g={autoResize:!1}),h=o,c&&(E=n-s/2)}if(s!==0&&a!==0){let x=null;xe(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:E+(m?.x??0),y:h+(m?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as Si,normalizeLink as Lc}from"@excalidraw/common";var yP=(e,t)=>{let n=window.location.href;try{let o=new URL(n);return o.searchParams.set(Si,e),Lc(o.toString())}catch(o){console.error(o)}return Lc(n)},bP=(e,t)=>{if(e.length>0&&xh(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},xh=e=>!!(e.length===1||e.length>1&&El(e)),PP=e=>{try{let t=new URL(e);return t.searchParams.has(Si)&&t.host===window.location.host}catch{return!1}},IP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Si))return t.get(Si)}catch{}return null};P();import{FONT_FAMILY as Lh,VERTICAL_ALIGN as Ch,escapeDoubleQuotes as os,getFontString as Bh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as en,DEFAULT_FONT_FAMILY as wh,DEFAULT_FONT_SIZE as yh,DEFAULT_TEXT_ALIGN as bh,DEFAULT_VERTICAL_ALIGN as Ph,VERTICAL_ALIGN as Ih,randomInteger as Sh,randomId as Mh,getFontString as Mi,getUpdatedTimestamp as Th,getLineHeight as Ah}from"@excalidraw/common";var nt=(e,{x:t,y:n,strokeColor:o=en.strokeColor,backgroundColor:i=en.backgroundColor,fillStyle:r=en.fillStyle,strokeWidth:s=en.strokeWidth,strokeStyle:a=en.strokeStyle,roughness:l=en.roughness,opacity:c=en.opacity,width:d=0,height:u=0,angle:p=0,groupIds:m=[],frameId:f=null,index:E=null,roundness:h=null,boundElements:g=null,link:x=null,locked:y=en.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||d<-1e6||d>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:d,height:u,points:b.points}),{id:b.id||Mh(),type:e,x:t,y:n,width:d,height:u,angle:p,strokeColor:o,backgroundColor:i,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:c,groupIds:m,frameId:f,index:E,roundness:h,seed:b.seed??Sh(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Th(),link:x,locked:y,customData:b.customData}),ns=e=>nt(e.type,e),GP=e=>nt("embeddable",e),OP=e=>({...nt("iframe",e)}),RP=e=>Me({...nt("frame",e),type:"frame",name:e?.name||null},{}),kP=e=>Me({...nt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Cc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Bc=e=>{let t=e.fontFamily||wh,n=e.fontSize||yh,o=e.lineHeight||Ah(t),i=tr(e.text),r=Qe(i,Mi({fontFamily:t,fontSize:n}),o),s=e.textAlign||bh,a=e.verticalAlign||Ph,l=Cc({textAlign:s,verticalAlign:a},r),c={...nt("text",e),text:i,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??i,autoResize:e.autoResize??!0,lineHeight:o};return Me(c,{})},Dh=(e,t,n)=>{let{width:o,height:i}=Qe(n,Mi(e),e.lineHeight);e.autoResize||(o=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Ih.MIDDLE&&!e.containerId&&e.autoResize){let c=Qe(e.text,Mi(e),e.lineHeight),d=Cc(e,{width:o-c.width,height:i-c.height});a=e.x-d.x,l=e.y-d.y}else{let[c,d,u,p]=H(e,t),[m,f,E,h]=Nt(e,o,i,!1),g=(c-m)/2,x=(d-f)/2,y=(u-E)/2,b=(p-h)/2;[a,l]=vh({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,y,b)}return{width:o,height:i,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},vh=(e,t,n,o,i,r,s,a)=>{let l=Math.cos(o),c=Math.sin(o);return e.e&&e.w?t+=i+s:e.e?(t+=i*(1+l),n+=i*c,t+=s*(1-l),n+=s*-c):e.w&&(t+=i*(1-l),n+=i*-c,t+=s*(1+l),n+=s*c),e.n&&e.s?n+=r+a:e.n?(t+=r*c,n+=r*(1-l),t+=a*-c,n+=a*(1+l)):e.s&&(t+=r*-c,n+=r*(1+l),t+=a*c,n+=a*(1-l)),[t,n]},FP=(e,t,n,o=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(o=Pt(o,Mi(e),t?Je(t,e):e.width));let i=Dh(e,n,o);return{text:o,...i}},NP=e=>({...nt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,lastCommittedPoint:null}),zP=e=>{let t={...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return cn(t)?{...t,polygon:e.polygon??!1}:t},Gc=e=>e.elbowed?{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},HP=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,Gh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,Oh=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Rh=/^https:\/\/(?:www\.)?figma\.com/,Oc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,kh=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Fh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Rc=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,Nh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,zh=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Hh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,kc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Fc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,_h=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Yh=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[,o="0",i="0",r="0"]=n;return parseInt(o)*3600+parseInt(i)*60+parseInt(r)},rs=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Nc=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),is=e=>`<html><body>${e}</body></html>`,VP=e=>{if(!e)return null;if(ft.has(e))return ft.get(e);let t=e,n=Nc.has(ss(e,Nc)||""),o="generic",i={w:560,h:840},r=e.match(Gh);if(r?.[2]){let c=Yh(t),d=c>0?`&start=${c}`:"",u=e.includes("shorts");switch(o="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${d}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${d}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${d}`;break}return i=u?{w:315,h:560}:{w:560,h:315},ft.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}}let s=e.match(Oh);if(s?.[1]){let c=s?.[1],d=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return o="video",e=`https://player.vimeo.com/video/${c}?api=1`,i={w:560,h:315},ft.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,error:d,sandbox:{allowSameOrigin:n}}}if(e.match(Rh))return o="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,i={w:550,h:550},ft.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}};let l=e.match(zh);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ft.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}};if(Fh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Rc.test(e)){let c=e.match(Rc)[1],d=os(`https://twitter.com/x/status/${c}`),u={type:"document",srcdoc:p=>is(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${d}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,u),u}if(Fc.test(e)){let[,c,d,u]=e.match(Fc),p=os(`https://reddit.com/r/${c}/comments/${d}/${u}`),m={type:"document",srcdoc:f=>is(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${p}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,m),m}if(Oc.test(e)){let[,c,d]=e.match(Oc),u=os(`https://gist.github.com/${c}/${d}`),p={type:"document",srcdoc:()=>is(`
|
|
20
|
+
`),l.stack,e.map(c=>s(c)),...d),t)throw l}},Rd=e=>e.sort((t,n)=>kd(t)&&kd(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),Gi=(e,t)=>{try{let n=jo(e),i=dh(e,t),o=As(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});lh(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)ye(s,n,{index:a})}catch{Ms(e)}return e},Ms=e=>{let t=jo(e),n=Fd(e),i=As(e,n);for(let[o,{index:r}]of i)ye(o,t,{index:r});return e},Td=e=>{let t=jo(e),n=Fd(e),i=As(e,n);for(let[o,{index:r}]of i)t.set(o.id,ge(o,{index:r}));return t},dh=(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},Fd=e=>{let t=[],n,i,o=-1,r=0,s=d=>{let c=e[o]?e[o].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,o]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let m=e[u]?.index;if(!c&&m||c&&m&&m>c)return[m,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,o]=s(l),[i,r]=a(l),Ss(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[m,p]=s(l),[f,h]=a(l);if(Ss(u,m,f))break;[n,o]=[m,p],[i,r]=[f,h],c.push(l)}c.push(r),t.push(c)}}return t},Ss=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,As=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=Yo(e[o]?.index,e[r]?.index,i.length);for(let a=0;a<i.length;a++){let l=e[i[a]];n.set(l,{index:s[a]})}}return n},kd=e=>!!e.index;P();var Zd=Yc(Ud(),1);import{randomInteger as Th,arrayToMap as Wd,toBrandedType as Yd,isDevEnv as jd,isTestEnv as Xd,toArray as vh}from"@excalidraw/common";import{isNonDeletedElement as Dh}from"@excalidraw/element";import{isFrameLikeElement as Lh}from"@excalidraw/element";import{getElementsInGroup as Bh}from"@excalidraw/element";import{syncInvalidIndices as Ch,syncMovedIndices as Vd,validateFractionalIndices as Gh}from"@excalidraw/element";import{getSelectedElements as Oh}from"@excalidraw/element";import{mutateElement as kh}from"@excalidraw/element";var $d=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}},Rh=(0,Zd.default)(e=>{(jd()||Xd()||window?.DEBUG_FRACTIONAL_INDICES)&&Gh(e,{shouldThrow:jd()||Xd(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),Fh=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},$n=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=Yd(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=Yd(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=Fh(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=Oh(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&&Dh(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=vh(t),o=[];n?.skipValidation||Rh(i),this.elements=Ch(i),this.elementsMap.clear(),this.elements.forEach(s=>{Lh(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=$d(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=$d(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=Th();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)];Vd(i,Wd([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)];Vd(i,Wd(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]:Bh(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=kh(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var _=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(Ht(t??[],o),Ht(n??[],o),Ht(i??[],o)))}static diffObjects(t,n,i,o){if(!t[i]&&!n[i])return;let r=t[i]!==null&&typeof t[i]=="object",s=n[i]!==null&&typeof n[i]=="object";if(r||s){let a=t[i]??{},l=n[i]??{},d=e.getLeftDifferences(a,l).reduce((u,m)=>(u[m]=o(a[m]),u),{}),c=e.getRightDifferences(a,l).reduce((u,m)=>(u[m]=o(l[m]),u),{});Object.keys(d).length||Object.keys(c).length?(Reflect.set(t,i,d),Reflect.set(n,i,c)):(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}else t[i]===n[i]&&(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}static diffArrays(t,n,i,o){if(!(!t[i]&&!n[i])&&(Array.isArray(t[i])||Array.isArray(n[i]))){let r=Array.isArray(t[i])?t[i]:[],s=Array.isArray(n[i])?n[i]:[],a=Ht(e.getLeftDifferences(Ht(r,o),Ht(s,o)),d=>d),l=Ht(e.getRightDifferences(Ht(r,o),Ht(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)])):Kd(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&&Qd(a,l))continue;yield s}}}},cn=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=_.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(_.create({},{}))}inverse(){let t=_.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=_.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=_.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=_.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=_.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=_.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=_.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=_.merge(this.delta,t.delta,_.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=_.mergeObjects(t.selectedElementIds,s,i),m=_.mergeObjects(t.selectedGroupIds,a,o),p=_.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new O(n.get(d.elementId),n,d.isEditing):null,h={...t,...c,selectedElementIds:u,selectedGroupIds:m,lockedMultiSelections:p,selectedLinearElement:typeof d<"u"?f:t.selectedLinearElement},E=this.filterInvisibleChanges(t,h,n);return[h,E]}catch(i){if(console.error("Couldn't apply appstate change",i),fn()||pn())throw i;return[t,!1]}}isEmpty(){return _.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=jn(t),r=jn(n),s=_.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=_.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=_.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=Ul(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let w=i.get(x);w&&!w.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let m=n[u];m?c.has(m)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let p=n[u];if(!p)l.value=!0;else{let x=i.get(p.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},h=n[u]||{};Qd(f,h)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,g=n[u]||null;E!==g&&(l.value=!0);break;default:Kd(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{_.diffObjects(t,n,"selectedElementIds",i=>!0),_.diffObjects(t,n,"selectedGroupIds",i=>i??!1),_.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),fn()||pn())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}},un=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(fn()||pn())&&(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:qd()},c=_.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:qd()},d={...s},c=_.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=_.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]=_.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,m)=>{let p;switch(m){case"deleted":p=d;break;case"inserted":p=c;break}if(!p)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let h of Object.keys(u))switch(h){case"boundElements":f[h]=u[h];break;default:f[h]=p[h]}return f},r=d=>{let c={};for(let[u,m]of Object.entries(d)){let p=t.get(u),f=n.get(u),h=null;p||f?h=_.create(m.deleted,m.inserted,o(p,f),i):h=m,_.isInnerDifferent(h.deleted,h.inserted)&&(c[u]=h)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=mn.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),fn()||pn())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),fn()||pn())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=_.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=_.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return _.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]=_.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]=_.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=_.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(fn()||pn())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,i,o,r)=>s=>{let a=e.createGetter(n,i,o);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let m=e.applyDelta(u,c,o,r);if(n.set(m.id,m),l.set(m.id,m),!o.applyDirection){let p=t.get(d);p&&(o.applyDirection=p.version>m.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?(i.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(i.containsVisibleDifference=!0)):s=ge({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=_.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),ge(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:_.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,m=l,p;c===d?p=ge(d,{...m,version:u},!0):p=ye(d,n,{...m,version:c?.version!==d.version?d.version:u}),o.set(p.id,p),n.set(p.id,p)};for(let a of Object.keys(this.removed))e.unbindAffected(t,n,a,r);for(let a of Object.keys(this.added))e.rebindAffected(t,n,a,r);for(let[a]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>xl.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);nn.unbindAffected(n,r(),o),nn.unbindAffected(n,s(),o),on.unbindAffected(n,r(),o),on.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);nn.unbindAffected(n,r(),o),nn.rebindAffected(n,s(),o),on.unbindAffected(n,r(),(a,l)=>{ee(a)&&o(a,l)}),on.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new $n(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),fn()||pn())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(dt(r)){let s=vt(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||mo(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Ce(i)&&je(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=Rd([...o]),s=_.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),Nh(Gi(r,s))}static postProcess(t,n){try{_.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];_.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),fn()||pn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var UP=(e,t,n,i)=>{let[o,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Ft(e),d=Go(e,t,i).map(p=>[p,Ft(p)]).sort((p,f)=>p[1][r]-f[1][r]),c=0;for(let p of d)c+=p[1][a];let u=(l[a]-c)/(d.length-1);if(u<0){let p=d.findIndex(g=>g[1][o]===l[o]),f=d.findIndex(g=>g[1][s]===l[s]),h=(d[f][1][r]-d[p][1][r])/(d.length-1),E=d[p][1][r];return d.flatMap(([g,x],w)=>{let b={x:0,y:0};return w!==p&&w!==f&&(E+=h,b[n.axis]=E-x[r]),g.map(y=>ge(y,{x:y.x+b.x,y:y.y+b.y}))})}let m=l[o];return d.flatMap(([p,f])=>{let h={x:0,y:0};return h[n.axis]=m-f[o],m+=u,m+=f[a],p.map(E=>ge(E,{x:E.x+h.x,y:E.y+h.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as Hh,getGridPoint as zh,getFontString as _h,DRAGGING_THRESHOLD as Uh}from"@excalidraw/common";var QP=(e,t,n,i,o,r)=>{if(t.length===1&&Y(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(Y(m)&&m.startBinding&&m.endBinding){let p=t.find(h=>h.id===m.startBinding?.elementId),f=t.find(h=>h.id===m.endBinding?.elementId);return p&&f}return!0}),a=new Set(s),l=s.filter(m=>K(m)).map(m=>m.id);if(l.length>0)for(let m of i.getNonDeletedElements())m.frameId!==null&&l.includes(m.frameId)&&a.add(m);let d=[];for(let m of a){let p=e.originalElements.get(m.id);if(!p)return;d.push(p)}let c=Wh(De(d),n,o,r),u=new Set(Array.from(a,m=>m.id));a.forEach(m=>{let p=!H(m),f=p||(m.startBinding?u.has(m.startBinding.elementId):!1),h=p||(m.endBinding?u.has(m.endBinding.elementId):!1);if(H(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>Uh||!m.startBinding&&!m.endBinding){vs(e,m,i,c);let E=m.startBinding&&!f,g=m.endBinding&&!h;(E||g)&&(E&&Ke(m,"start",i),g&&Ke(m,"end",i))}}else{vs(e,m,i,c);let E=V(m,i.getNonDeletedElementsMap());E&&vs(e,E,i,c),je(m,i,{simultaneouslyUpdated:Array.from(a)})}})},Wh=(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]=zh(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},vs=(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})},JP=(e,t,n)=>{let[i,o]=De(e);return[t-i,n-o]},eI=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:m=null,originOffset:p=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(m?a=s/m:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Es(t,a,o<n?-s:s):{width:s,height:a}=Es(t,s,r<i?-a:a),a<0&&(a=-a)));let h=o<n?n-s:n,E=r<i?i-a:i;d&&(s+=s,a+=a,h=n-s/2,E=i-a/2);let g=null;if(ee(e)){a=e.height;let x=ao(_h({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>Hh/c&&(g={autoResize:!1}),E=i,d&&(h=n-s/2)}if(s!==0&&a!==0){let x=null;xe(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:h+(p?.x??0),y:E+(p?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as Vo,normalizeLink as Jd}from"@excalidraw/common";var rI=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Vo,e),Jd(i.toString())}catch(i){console.error(i)}return Jd(n)},sI=(e,t)=>{if(e.length>0&&Yh(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},Yh=e=>!!(e.length===1||e.length>1&&Wl(e)),aI=e=>{try{let t=new URL(e);return t.searchParams.has(Vo)&&t.host===window.location.host}catch{return!1}},lI=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Vo))return t.get(Vo)}catch{}return null};P();import{FONT_FAMILY as nE,VERTICAL_ALIGN as iE,escapeDoubleQuotes as Ds,getFontString as oE}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as hn,DEFAULT_FONT_FAMILY as jh,DEFAULT_FONT_SIZE as Xh,DEFAULT_TEXT_ALIGN as Vh,DEFAULT_VERTICAL_ALIGN as $h,VERTICAL_ALIGN as Zh,randomInteger as qh,randomId as Kh,getFontString as $o,getUpdatedTimestamp as Qh,getLineHeight as Jh}from"@excalidraw/common";var rt=(e,{x:t,y:n,strokeColor:i=hn.strokeColor,backgroundColor:o=hn.backgroundColor,fillStyle:r=hn.fillStyle,strokeWidth:s=hn.strokeWidth,strokeStyle:a=hn.strokeStyle,roughness:l=hn.roughness,opacity:d=hn.opacity,width:c=0,height:u=0,angle:m=0,groupIds:p=[],frameId:f=null,index:h=null,roundness:E=null,boundElements:g=null,link:x=null,locked:w=hn.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||Kh(),type:e,x:t,y:n,width:c,height:u,angle:m,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:p,frameId:f,index:h,roundness:E,seed:b.seed??qh(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Qh(),link:x,locked:w,customData:b.customData}),Dn=e=>rt(e.type,e),xI=e=>rt("embeddable",e),wI=e=>({...rt("iframe",e)}),ec=e=>ge({...rt("frame",e),type:"frame",name:e?.name||null},{}),tc=e=>ge({...rt("magicframe",e),type:"magicframe",name:e?.name||null},{}),nc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Ln=e=>{let t=e.fontFamily||jh,n=e.fontSize||Xh,i=e.lineHeight||Jh(t),o=ui(e.text),r=_e(o,$o({fontFamily:t,fontSize:n}),i),s=e.textAlign||Vh,a=e.verticalAlign||$h,l=nc({textAlign:s,verticalAlign:a},r),d={...rt("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 ge(d,{})},eE=(e,t,n)=>{let{width:i,height:o}=_e(n,$o(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Zh.MIDDLE&&!e.containerId&&e.autoResize){let d=_e(e.text,$o(e),e.lineHeight),c=nc(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,m]=X(e,t),[p,f,h,E]=jt(e,i,o,!1),g=(d-p)/2,x=(c-f)/2,w=(u-h)/2,b=(m-E)/2;[a,l]=tE({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,w,b)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},tE=(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]},yI=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Tt(i,$o(e),t?nt(t,e):e.width));let o=eE(e,n,i);return{text:i,...o}},bI=e=>({...rt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure}),ic=e=>{let t={...rt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Pt(t)?{...t,polygon:e.polygon??!1}:t},Zo=e=>e.elbowed?{...rt(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}:{...rt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},oc=e=>({...rt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ht=new Map,rE=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,sE=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,aE=/^https:\/\/(?:www\.)?figma\.com/,rc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,lE=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,dE=/^(?:https?:\/\/)?forms\.microsoft\.com\//,sc=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,cE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,uE=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,mE=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,ac=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,lc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,pE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,fE=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)},Bs=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"]),dc=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"]),Ls=e=>`<html><body>${e}</body></html>`,vI=e=>{if(!e)return null;if(ht.has(e))return ht.get(e);let t=e,n=dc.has(Cs(e,dc)||""),i="generic",o={w:560,h:840},r=e.match(rE);if(r?.[2]){let d=fE(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},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(sE);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},ht.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(aE))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let l=e.match(uE);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(dE.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),sc.test(e)){let d=e.match(sc)[1],c=Ds(`https://twitter.com/x/status/${d}`),u={type:"document",srcdoc:m=>Ls(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${m}"><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 ht.set(t,u),u}if(lc.test(e)){let[,d,c,u]=e.match(lc),m=Ds(`https://reddit.com/r/${d}/comments/${c}/${u}`),p={type:"document",srcdoc:f=>Ls(`<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 ht.set(t,p),p}if(rc.test(e)){let[,d,c]=e.match(rc),u=Ds(`https://gist.github.com/${d}/${c}`),m={type:"document",srcdoc:()=>Ls(`
|
|
21
21
|
<script src="${u}.js"><\/script>
|
|
22
22
|
<style type="text/css">
|
|
23
23
|
* { margin: 0px; }
|
|
24
24
|
table, .gist { height: 100%; }
|
|
25
25
|
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
|
|
26
26
|
</style>
|
|
27
|
-
`),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return ft.set(e,p),p}return ft.set(e,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}},$P=e=>{let t;Oo(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),o=Lh.Helvetica,i=Bh({fontSize:n,fontFamily:o});return Bc({x:e.x+e.width/2,y:e.y+e.height/2,strokeColor:e.strokeColor!=="transparent"?e.strokeColor:"black",backgroundColor:"transparent",fontFamily:o,fontSize:n,text:Pt(t,i,e.width-20),textAlign:"center",verticalAlign:Ch.MIDDLE,angle:e.angle??0})},ss=(e,t)=>{try{let{hostname:n}=new URL(e),o=n.replace(/^www\./,"");if(t instanceof Set){if(rs.has(o))return o;let r=o.replace(/^([^.]+)/,"*");return rs.has(r)?r:null}let i=t.replace(/^www\./,"");if(o===i)return i}catch{}return null},ZP=e=>{let t=e.match(Nh);if(t&&t.length===2)return t[1];let n=e.match(_h);if(n&&n.length===2)return n[1];let o=e.match(kh);if(o&&o.length===2)return o[1];if(kc.test(e))return`https://giphy.com/embed/${kc.exec(e)[1]}`;let i=e.match(Hh);return i&&i.length===2?i[1]:e},qP=(e,t)=>{if(!e)return!1;if(t!=null)if(typeof t=="function"){let n=t(e);if(typeof n=="boolean")return n}else{if(typeof t=="boolean")return t;if(t instanceof RegExp)return t.test(e);if(Array.isArray(t)){for(let n of t)if(n instanceof RegExp){if(e.match(n))return!0}else if(ss(e,n))return!0;return!1}}return!!ss(e,rs)};P();import{KEYS as Ti,invariant as Ai,toBrandedType as Uh}from"@excalidraw/common";import{pointFrom as zc}from"@excalidraw/math";var Nn=100,En=100,dI=e=>{switch(e){case Ti.ARROW_UP:return"up";case Ti.ARROW_DOWN:return"down";case Ti.ARROW_RIGHT:return"right";case Ti.ARROW_LEFT:return"left";default:return"right"}},Yc=(e,t,n,o)=>{let i=[...n.values()].reduce((r,s)=>{let a;if(G(s)&&(a=s[e==="predecessors"?"startBinding":"endBinding"])&&s[e==="predecessors"?"endBinding":"startBinding"]?.elementId===t.id){let l=n.get(a.elementId);if(!l)return r;Ai(Le(l),"not an ExcalidrawBindableElement");let c=e==="predecessors"?s.points[s.points.length-1]:[0,0],d=to(t,Ve(t,n),[c[0]+s.x,c[1]+s.y]);r.push({relative:l,heading:d})}return r},[]);switch(o){case"up":return i.filter(r=>pe(r.heading,He)).map(r=>r.relative);case"down":return i.filter(r=>pe(r.heading,we)).map(r=>r.relative);case"right":return i.filter(r=>pe(r.heading,me)).map(r=>r.relative);case"left":return i.filter(r=>pe(r.heading,Oe)).map(r=>r.relative)}},as=(e,t,n)=>Yc("successors",e,t,n),ls=(e,t,n)=>Yc("predecessors",e,t,n),Xh=(e,t,n)=>{let o=En+e.width;if(n==="up"||n==="down"){let a=Nn+e.height,l=e.x,c=e.x+e.width;if(t.every(d=>d.x+d.width<l||d.x>c))return{x:0,y:a*(n==="up"?-1:1)}}else if(n==="right"||n==="left"){let a=e.y,l=e.y+e.height;if(t.every(c=>c.y+c.height<a||c.y>l))return{x:(En+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Nn+e.height,l=(t.length===0,a),c=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*o:t.length/2*o*-1;return n==="up"?{x:c,y:l*-1}:{x:c,y:l}}let i=Nn+e.height,r=(t.length===0,En+e.width),s=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*i:t.length/2*i*-1;return n==="left"?{x:r*-1,y:s}:{x:r,y:s}},Wh=(e,t,n,o)=>{let i=o.getNonDeletedElementsMap(),r=as(e,i,n),s=ls(e,i,n),a=Xh(e,[...r,...s],n),l=ns({type:e.type,x:e.x+a.x,y:e.y+a.y,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});Ai(Ji(l),"not an ExcalidrawFlowchartNodeElement");let c=Uc(e,l,n,t,o);return{nextNode:l,bindingArrow:c}},jh=(e,t,n,o,i)=>{let r=[];for(let s=0;s<i;s++){let a,l;if(n==="left"||n==="right"){let u=Nn*(i-1)+i*e.height,p=e.y+e.height/2-u/2,m=En+e.width;n==="left"&&(m*=-1),a=e.x+m;let f=(Nn+e.height)*s;l=p+f}else{let u=En*(i-1)+i*e.width,p=e.x+e.width/2-u/2,m=Nn+e.height;n==="up"&&(m*=-1),l=e.y+m;let f=(En+e.width)*s;a=p+f}let c=ns({type:e.type,x:a,y:l,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});Ai(Ji(c),"not an ExcalidrawFlowchartNodeElement");let d=Uc(e,c,n,t,o);r.push(c),r.push(d)}return r},Uc=(e,t,n,o,i)=>{let r,s;switch(n){case"up":{r=e.x+e.width/2,s=e.y-6;break}case"down":{r=e.x+e.width/2,s=e.y+e.height+6;break}case"right":{r=e.x+e.width+6,s=e.y+e.height/2;break}case"left":{r=e.x-6,s=e.y+e.height/2;break}}let l,c;switch(n){case"up":{l=t.x+t.width/2-r,c=t.y+t.height-s+6;break}case"down":{l=t.x+t.width/2-r,c=t.y-s-6;break}case"right":{l=t.x-r-6,c=t.y-s+t.height/2;break}case"left":{l=t.x+t.width-r+6,c=t.y-s+t.height/2;break}}let d=Gc({type:"arrow",x:r,y:s,startArrowhead:null,endArrowhead:o.currentItemEndArrowhead,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeWidth:e.strokeWidth,opacity:e.opacity,roughness:e.roughness,points:[zc(0,0),zc(l,c)],elbowed:!0}),u=i.getNonDeletedElementsMap();mn(d,e,"start",i),mn(d,t,"end",i);let p=new Map;p.set(e.id,e),p.set(t.id,t),p.set(d.id,d),Y.movePoints(d,i,new Map([[1,{point:d.points[1]}]]));let m=Tn(d,Uh(new Map([...u.entries(),[e.id,e],[t.id,t],[d.id,d]])),{points:d.points});return{...d,...m}},Hc=class{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,o){if(!Le(t))return null;if(o!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&o===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let i=[...as(t,n,o),...ls(t,n,o)];if(i.length>0)return this.sameLevelIndex=0,this.isExploring=!0,this.sameLevelNodes=i,this.direction=o,this.visitedNodes.add(i[0].id),i[0].id;if(o===this.direction||!this.isExploring){this.isExploring||this.visitedNodes.add(t.id);let s=["up","right","down","left"].filter(a=>a!==o).map(a=>[...as(t,n,a),...ls(t,n,a)]).flat().filter(a=>!this.visitedNodes.has(a.id));for(let a of s)if(!this.visitedNodes.has(a.id))return this.visitedNodes.add(a.id),this.isExploring=!0,this.direction=o,a.id}return null}},_c=class{isCreatingChart=!1;numberOfNodes=0;direction="right";pendingNodes=null;createNodes(t,n,o,i){let r=i.getNonDeletedElementsMap();if(o!==this.direction){let{nextNode:s,bindingArrow:a}=Wh(t,n,o,i);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=o,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=jh(t,n,o,i,this.numberOfNodes);this.isCreatingChart=!0,this.direction=o,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);Ai(s&&ko(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>Kt([a],s,r)||Zt(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>ye(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},uI=(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 Xc,SVG_NS as Vh}from"@excalidraw/common";var $h=e=>new Promise((t,n)=>{let o=new Image;o.onload=()=>{t(o)},o.onerror=i=>{n(i)},o.src=e}),EI=async({fileIds:e,files:t,imageCache:n})=>{let o=new Map,i=new Map;return await Promise.all(e.reduce((r,s)=>{let a=t[s];return a&&!o.has(s)?(o.set(s,!0),r.concat((async()=>{try{if(a.mimeType===Xc.binary)throw new Error("Only images can be added to ImageCache");let l=$h(a.dataURL),c={image:l,mimeType:a.mimeType};n.set(s,c);let d=await l;n.set(s,{...c,image:d})}catch{i.set(s,!0)}})())):r},[])),{imageCache:n,updatedFiles:o,erroredFiles:i}},gI=e=>e.filter(t=>zt(t)),Zh=e=>e?.nodeName.toLowerCase()==="svg",xI=e=>{let t=new DOMParser().parseFromString(e,Xc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Zh(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Vh);let i=n.getAttribute("width"),r=n.getAttribute("height");(i?.includes("%")||i==="auto")&&(i=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!i||!r){if(i=i||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,i,r]=a)}n.setAttribute("width",i),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${i} ${r}`),n.outerHTML}};P();import{pointCenter as qh,normalizeRadians as vi,pointFrom as re,pointRotateRads as ot}from"@excalidraw/math";import{MIN_FONT_SIZE as ds,SHIFT_LOCKING_ANGLE as Li,rescalePoints as Wc,getFontString as Di}from"@excalidraw/common";var CI=(e,t,n,o,i,r,s,a,l,c,d)=>{let u=o.getNonDeletedElementsMap();if(n.length===1){let[p]=n;if(t==="rotation")G(p)||(Kh(p,o,a,l,i),Ue(p,o));else if(t){let m=n[0].id,f=u.get(m),E=e.get(m);if(f&&E){let{nextWidth:h,nextHeight:g}=nE(f,E,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});tE(h,g,f,E,e,o,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return oe(p)&&Ue(p,o),!0}else if(n.length>1){if(t==="rotation")return Jh(e,n,o,a,l,i,c,d),!0;if(t){let{nextWidth:p,nextHeight:m,flipByX:f,flipByY:E,originalBoundingBox:h}=oE(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return iE(n,u,t,o,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:E,nextWidth:p,nextHeight:m,originalBoundingBox:h}),!0}}return!1},Kh=(e,t,n,o,i)=>{let[r,s,a,l]=H(e,t.getNonDeletedElementsMap()),c=(r+a)/2,d=(s+l)/2,u;$(e)?u=0:(u=5*Math.PI/2+Math.atan2(o-d,n-c),i&&(u=u+Li/2,u=u-u%Li),u=vi(u));let p=It(e);if(t.mutateElement(e,{angle:u}),p){let m=t.getElement(p);m&&!_(e)&&t.mutateElement(m,{angle:u})}},jc=(e,t,n,o)=>X(e)||Se(e)?{points:Wc(0,t,Wc(1,n,e.points,o),o)}:{},us=(e,t,n)=>{let o=e.width;if(de(e)){let s=Ce(e,t);s&&(o=Je(s,e))}let r=e.fontSize*(n/o);return r<ds?null:{size:r}},Qh=(e,t,n,o,i,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),c=us(t,a,l);if(c!==null){if(o.includes("n")||o.includes("s")){let d=re(e.x,e.y),u=cs(d,e.width,e.height,l,s,e.angle,o,!1,i);n.mutateElement(t,{fontSize:c.size,width:l,height:s,x:u.x,y:u.y});return}if(o==="e"||o==="w"){let d=zo(Di({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(d,r),p=Pt(t.originalText,Di(t),Math.abs(u)),m=Qe(p,Di(t),t.lineHeight),f=m.height,E=re(e.x,e.y),h=cs(E,e.width,e.height,u,f,t.angle,o,!1,i),g={width:Math.abs(u),height:Math.abs(m.height),x:h.x,y:h.y,text:p,autoResize:!1};n.mutateElement(t,g)}}},Jh=(e,t,n,o,i,r,s,a)=>{let l=n.getNonDeletedElementsMap(),c=5*Math.PI/2+Math.atan2(i-a,o-s);r&&(c+=Li/2,c-=c%Li);for(let d of t)if(!$(d)){let[u,p,m,f]=H(d,l),E=(u+m)/2,h=(p+f)/2,g=e.get(d.id)?.angle??d.angle,[x,y]=ot(re(E,h),re(s,a),c+g-d.angle),b=G(d)?{points:qa(d,l)}:{x:d.x+(x-E),y:d.y+(y-h),angle:vi(c+g)};n.mutateElement(d,b),Ue(d,n,{simultaneouslyUpdated:t});let w=W(d,l);w&&!_(d)&&n.mutateElement(w,{x:w.x+(x-E),y:w.y+(y-h),angle:vi(c+g)})}n.triggerUpdate()},BI=(e,t,n,o,i)=>{let[r,s,a,l]=t.length===1?H(t[0],n):tt(t),c=(r+a)/2,d=(s+l)/2,u=t.length===1?t[0].angle:0;switch([o,i]=ot(re(o,i),re(c,d),-u),e){case"n":return ot(re(o-(r+a)/2,i-s),re(0,0),u);case"s":return ot(re(o-(r+a)/2,i-l),re(0,0),u);case"w":return ot(re(o-r,i-(s+l)/2),re(0,0),u);case"e":return ot(re(o-a,i-(s+l)/2),re(0,0),u);case"nw":return ot(re(o-r,i-s),re(0,0),u);case"ne":return ot(re(o-a,i-s),re(0,0),u);case"sw":return ot(re(o-r,i-l),re(0,0),u);case"se":return ot(re(o-a,i-l),re(0,0),u);default:return[0,0]}},GI=(e,t)=>{let[,[n,o]]=t.points;return e==="nw"&&(n<0||o<0)||e==="ne"&&n>=0||e==="sw"&&n<=0||e==="se"&&(n>0||o>0)?"end":"origin"},eE=(e,t,n)=>{if(n)return"center";if(t)switch(e){case"n":return"south-side";case"e":return"west-side";case"s":return"north-side";case"w":return"east-side";case"ne":return"bottom-left";case"nw":return"bottom-right";case"se":return"top-left";case"sw":return"top-right"}return["e","se","s"].includes(e)?"top-left":["n","nw","w"].includes(e)?"bottom-right":e==="ne"?"bottom-left":"top-right"},cs=(e,t,n,o,i,r,s,a,l)=>{let c=eE(s,a,l),[d,u]=e;switch(c){case"top-left":return{x:d+(t-o)/2+(o-t)/2*Math.cos(r)+(n-i)/2*Math.sin(r),y:u+(n-i)/2+(o-t)/2*Math.sin(r)+(i-n)/2*Math.cos(r)};case"top-right":return{x:d+(t-o)/2*(Math.cos(r)+1)+(n-i)/2*Math.sin(r),y:u+(n-i)/2+(t-o)/2*Math.sin(r)+(i-n)/2*Math.cos(r)};case"bottom-left":return{x:d+(t-o)/2*(1-Math.cos(r))+(i-n)/2*Math.sin(r),y:u+(n-i)/2*(Math.cos(r)+1)+(o-t)/2*Math.sin(r)};case"bottom-right":return{x:d+(t-o)/2*(Math.cos(r)+1)+(i-n)/2*Math.sin(r),y:u+(n-i)/2*(Math.cos(r)+1)+(t-o)/2*Math.sin(r)};case"center":return{x:d-(o-t)/2,y:u-(i-n)/2};case"east-side":return{x:d+(t-o)/2*(Math.cos(r)+1),y:u+(t-o)/2*Math.sin(r)+(n-i)/2};case"west-side":return{x:d+(t-o)/2*(1-Math.cos(r)),y:u+(o-t)/2*Math.sin(r)+(n-i)/2};case"north-side":return{x:d+(t-o)/2+(n-i)/2*Math.sin(r),y:u+(i-n)/2*(Math.cos(r)-1)};case"south-side":return{x:d+(t-o)/2+(i-n)/2*Math.sin(r),y:u+(n-i)/2*(Math.cos(r)+1)}}},tE=(e,t,n,o,i,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:c=!1}={})=>{if(oe(n)&&oe(o))return Qh(o,n,r,s,c,e,t);let d={},u=r.getNonDeletedElementsMap(),p=W(n,u);if(p){let h=i.get(p.id);if(h&&(d={fontSize:h.fontSize}),l){let g={...n,width:e,height:t},x=us(p,u,Je(g,p));if(x===null)return;d={fontSize:x.size}}else{let g=pa(Di(p),p.lineHeight),x=ma(p.fontSize,p.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let m=jc(o,e,t,!0),f=re(o.x,o.y);if(X(o)){let[h,g]=he(o,i);f=re(h,g)}let E=cs(f,o.width,o.height,e,t,o.angle,s,l,c);if(X(o)&&m.points){let h=o.x-f[0],g=o.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 o&&r.mutateElement(n,{scale:[(Math.sign(e)||o.scale[0])*o.scale[0],(Math.sign(t)||o.scale[1])*o.scale[1]]}),_(n)&&p&&l){let h=e/n.width*p.fontSize;if(h<ds)return;d.fontSize=h}if(e!==0&&t!==0&&Number.isFinite(E.x)&&Number.isFinite(E.y)){let h={...E,width:Math.abs(e),height:Math.abs(t),...m};r.mutateElement(n,h,{informMutation:a,isDragging:!1}),p&&d!=null&&r.mutateElement(p,{fontSize:d.fontSize}),un(n,r,s,l),Ue(n,r,{newSize:{width:e,height:t}})}},nE=(e,t,n,o,i,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,c,d]=Nt(t,t.width,t.height,!0),u=re(a,l),p=re(c,d),m=qh(u,p),f=ot(re(o,i),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,F=e.height*D;if(s&&(T=2*T-t.width,F=2*F-t.height),r){let C=Math.abs(T)/t.width,k=Math.abs(F)/t.height;if(n.length===1&&(F*=C,T*=k),n.length===2){let L=Math.max(C,k);T=t.width*L*Math.sign(T),F=t.height*L*Math.sign(F)}}return{nextWidth:T,nextHeight:F}},oE=(e,t,n,o,i,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(L=>t.get(L.id)),c=l.reduce((L,j)=>{if(!X(j))return L;let N=It(j);if(!N)return L;let te=t.get(N)??null;return de(te)?[...L,{...te,...Y.getBoundTextElementPosition(j,te,n)}]:L},[]),d=Ct(l.map(L=>L).concat(c)),{minX:u,minY:p,maxX:m,maxY:f,midX:E,midY:h}=d,g=m-u,x=f-p,y={ne:[u,f],se:[u,p],sw:[m,p],nw:[m,f],e:[u,p+x/2],w:[m,p+x/2],n:[u+g/2,f],s:[u+g/2,p]},[b,w]=a?[E,h]:y[o],I=a?2:1,M=Math.max(Math.abs(i-b)/g||0,Math.abs(r-w)/x||0)*I,D=o.includes("e")||o.includes("w")?Math.abs(i-b)*I:g,T=o.includes("n")||o.includes("s")?Math.abs(r-w)*I:x;s&&(D=g*M*Math.sign(i-b),T=x*M*Math.sign(r-w));let F={ne:[i<b,r>w],se:[i<b,r<w],sw:[i>b,r<w],nw:[i>b,r>w],e:[i<b,!1],w:[i>b,!1],n:[!1,r>w],s:[!1,r<w]},[C,k]=F[o].map(L=>L);return{originalBoundingBox:d,nextWidth:D,nextHeight:T,flipByX:C,flipByY:k}},iE=(e,t,n,o,i,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:c,nextWidth:d,originalBoundingBox:u}={})=>{if(d===void 0&&c===void 0&&a===void 0&&l===void 0||c===0||d===0)return;i||(i=t);let p=e.reduce((I,M)=>{let D=i.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(!X(D))return M;let T=It(D);if(!T)return M;let F=i.get(T)??null;return de(F)?[...M,{...F,...Y.getBoundTextElementPosition(D,F,t)}]:M},[]);m=Ct(p.map(({orig:M})=>M).concat(I))}let{minX:f,minY:E,maxX:h,maxY:g,midX:x,midY:y}=m,b=h-f,w=g-E;if(d===void 0&&c===void 0&&(d=b,c=w),r&&(d===void 0?d=c*(b/w):c===void 0?c=d*(w/b):Math.abs(d/c-b/w)>.001&&(d=c*(b/w))),d&&c){let I=n.includes("e")||n.includes("w")?Math.abs(d)/b:1,M=n.includes("n")||n.includes("s")?Math.abs(c)/w:1,D;n.length===1?D=n.includes("e")||n.includes("w")?I:M:D=Math.max(Math.abs(d)/b||0,Math.abs(c)/w||0);let T={ne:[f,g],se:[f,E],sw:[h,E],nw:[h,g],e:[f,E+w/2],w:[h,E+w/2],n:[f+b/2,g],s:[f+b/2,E]},[F,C]=s?[x,y]:T[n],k=r||p.some(S=>S.latest.angle!==0||oe(S.latest)||gl(S.latest));k&&(I=D,M=D);let[L,j]=[a?-1:1,l?-1:1],N=[];for(let{orig:S,latest:Q}of p){if(oe(S)&&de(S))continue;let V=S.width*I,ne=S.height*M,tn=vi(S.angle*L*j),it=X(S)||Se(S),gn=S.x-F,Gi=S.y-C,mo=a&&!it?V:0,zn=l&&!it?ne:0,Oi=F+L*(gn*I+mo),fo=C+j*(Gi*M+zn),nn=jc(S,V*L,ne*j,!1),ge={x:Oi,y:fo,width:V,height:ne,angle:tn,...nn};if(G(S)&&(S.startBinding&&(ge.startBinding={...S.startBinding,fixedPoint:[a?-S.startBinding.fixedPoint[0]+1:S.startBinding.fixedPoint[0],l?-S.startBinding.fixedPoint[1]+1:S.startBinding.fixedPoint[1]]}),S.endBinding&&(ge.endBinding={...S.endBinding,fixedPoint:[a?-S.endBinding.fixedPoint[0]+1:S.endBinding.fixedPoint[0],l?-S.endBinding.fixedPoint[1]+1:S.endBinding.fixedPoint[1]]}),S.fixedSegments&&nn.points&&(ge.fixedSegments=S.fixedSegments.map(De=>({...De,start:nn.points[De.index-1],end:nn.points[De.index]})))),xe(S)&&(ge.scale=[S.scale[0]*L,S.scale[1]*j]),oe(S)){let De=us(S,t,V);if(!De)return;ge.fontSize=De.size}let on=i.get(It(S)??"");if(on)if(k){let De=on.fontSize*D;if(De<ds)return;ge.boundTextFontSize=De}else ge.boundTextFontSize=on.fontSize;N.push({element:Q,update:ge})}let te=N.map(({element:S})=>S);for(let{element:S,update:{boundTextFontSize:Q,...V}}of N){let{width:ne,height:tn,angle:it}=V;o.mutateElement(S,V),Ue(S,o,{simultaneouslyUpdated:te,newSize:{width:ne,height:tn}});let gn=W(S,t);gn&&Q&&(o.mutateElement(gn,{fontSize:Q,angle:X(S)?void 0:it}),un(S,o,n,!0))}o.triggerUpdate()}};P();import{pointFrom as $e,pointOnLineSegment as Qc,pointRotateRads as Bi}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as gs}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as ms,isAndroid as rE,isIOS as sE}from"@excalidraw/common";import{pointFrom as Vc,pointRotateRads as aE}from"@excalidraw/math";var $c={mouse:8,pen:16,touch:28},lE=16,qc={e:!0,s:!0,n:!0,w:!0},HI={e:!0,s:!0,n:!0,w:!0},_I={e:!0,s:!0,n:!0,w:!0,rotation:!0},Zc={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},ps={e:!0,s:!0,n:!0,w:!0},Ot=(e,t,n,o,i,r,s)=>{let[a,l]=aE(Vc(e+n/2,t+o/2),Vc(i,r),s);return[a-n/2,l-o/2,n,o]},Ci=e=>!(e.viewport.isMobile||e.isTouchScreen&&(rE||sE)),fs=e=>Ci(e)?qc:{},hs=([e,t,n,o,i,r],s,a,l,c={},d=4,u=ms)=>{let p=$c[l],m=p/a.value,f=p/a.value,E=p/a.value,h=p/a.value,g=n-e,x=o-t,y=d/a.value,b=(p-u*2)/(2*a.value),w={nw:c.nw?void 0:Ot(e-y-E+b,t-y-h+b,m,f,i,r,s),ne:c.ne?void 0:Ot(n+y-b,t-y-h+b,m,f,i,r,s),sw:c.sw?void 0:Ot(e-y-E+b,o+y-b,m,f,i,r,s),se:c.se?void 0:Ot(n+y-b,o+y-b,m,f,i,r,s),rotation:c.rotation?void 0:Ot(e+g/2-m/2,t-y-h+b-lE/a.value,m,f,i,r,s)},I=5*$c.mouse/a.value;return Math.abs(g)>I&&(c.n||(w.n=Ot(e+g/2-m/2,t-y-h+b,m,f,i,r,s)),c.s||(w.s=Ot(e+g/2-m/2,o+y-b,m,f,i,r,s))),Math.abs(x)>I&&(c.w||(w.w=Ot(e-y-E+b,t+x/2-f/2,m,f,i,r,s)),c.e||(w.e=Ot(n+y-b,t+x/2-f/2,m,f,i,r,s))),w},Kc=(e,t,n,o="mouse",i=qc)=>{if(e.locked||G(e))return{};if(e.type==="freedraw"||X(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?i=ps:s[0]>0&&s[1]<0?i=Zc:s[0]>0&&s[1]>0?i=ps:s[0]<0&&s[1]>0?i=Zc:s[0]<0&&s[1]<0&&(i=ps)}}else $(e)&&(i={...i,rotation:!0});let r=X(e)?ms+8:xe(e)?0:ms;return hs(H(e,n,!0),e.angle,t,o,i,r,xe(e)?0:void 0)},YI=(e,t)=>{if(t.selectedLinearElement?.isEditing)return!1;if(e.length>1)return!0;let n=e[0];return G(n)?!1:X(n)?n.points.length>2:!0};var xs=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],cE=(e,t,n,o,i,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...c}=Kc(e,r,t,s,fs(a));if(l&&xs(l,o,i))return"rotation";let d=Object.keys(c).filter(u=>{let p=c[u];return p?xs(p,o,i):!1});if(d.length>0)return d[0];if(Ci(a)){let[u,p,m,f,E,h]=H(e,t);if(!(X(e)&&e.points.length<=2)){let g=xe(e)?0:gs/r.value,x=gs/r.value,y=Jc($e(u-g,p-g),$e(m+g,f+g),$e(E,h),e.angle);for(let[b,w]of Object.entries(y))if(Qc($e(o,i),w,x))return b}}return!1},qI=(e,t,n,o,i,r,s,a)=>e.reduce((l,c)=>{if(l)return l;let d=cE(c,s,t,n,o,i,r,a);return d?{element:c,transformHandleType:d}:null},null),KI=([e,t,n,o],i,r,s,a,l)=>{let c=hs([e,t,n,o,(e+n)/2,(t+o)/2],0,s,a,fs(l)),d=Object.keys(c).find(u=>{let p=c[u];return p&&xs(p,i,r)});if(d)return d;if(Ci(l)){let u=(e+n)/2,p=(t+o)/2,m=gs/s.value,f=Jc($e(e-m,t-m),$e(n+m,o+m),$e(u,p),0);for(let[E,h]of Object.entries(f))if(Qc($e(i,r),h,m))return E}return!1},Es=["ns","nesw","ew","nwse"],dE=(e,t)=>{let n=Es.indexOf(e);if(n>=0){let o=Math.round(t/(Math.PI/4));e=Es[(n+o)%Es.length]}return e},QI=e=>{let{element:t,transformHandleType:n}=e,o=t&&Math.sign(t.height)*Math.sign(t.width)===-1,i=null;switch(n){case"n":case"s":i="ns";break;case"w":case"e":i="ew";break;case"nw":case"se":o?i="nesw":i="nwse";break;case"ne":case"sw":o?i="nwse":i="nesw";break;case"rotation":return"grab"}return i&&t&&(i=dE(i,t.angle)),i?`${i}-resize`:""},Jc=([e,t],[n,o],i,r)=>{let s=Bi($e(e,t),i,r),a=Bi($e(n,t),i,r),l=Bi($e(e,o),i,r),c=Bi($e(n,o),i,r);return{n:[s,a],e:[a,c],s:[c,l],w:[l,s]}};P();var nS=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||pt(t,e).length));P();import{arrayToMap as td,findIndex as nd,findLastIndex as od}from"@excalidraw/common";var ws=(e,t)=>e.frameId===t||e.id===t,id=(e,t,n)=>{let o=[],i=[],r=null,s=-1,a=td(n||pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(i.length&&(o=o.concat(i),i=[]),o.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,i.push(s)):i=[]}return o},uE=e=>{let t=0;return e.reduce((n,o,i)=>(i>0&&e[i-1]!==o-1&&(t=++t),(n[t]||(n[t]=[])).push(o),n),[])},ed=(e,t,n,o)=>{if("containerId"in e&&e.containerId){let i=o.getElement(e.containerId);if(i)return n==="left"?Math.min(t.indexOf(i),t.indexOf(e)):Math.max(t.indexOf(i),t.indexOf(e))}else{let i=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(i){let r=o.getElement(i);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},pE=(e,t)=>{let n=-1,o=-1;return e.forEach((i,r)=>{ws(i,t)&&(n===-1&&(n=r),o=r)}),n===-1?[]:e.slice(n,o+1)},mE=(e,t,n,o,i,r)=>{let s=t[n],a=p=>p.isDeleted?!1:i?p.frameId===i:e.editingGroupId?p.groupIds.includes(e.editingGroupId):!0,l=o==="left"?od(t,p=>a(p),Math.max(0,n-1)):nd(t,p=>a(p),n+1),c=t[l];if(!c)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===c?.groupIds.join(""))return ed(c,t,o,r)??l;if(!c?.groupIds.includes(e.editingGroupId))return-1}if(!i&&(c.frameId||$(c))){let p=pE(t,c.frameId||c.id);return o==="left"?t.indexOf(p[0]):t.indexOf(p[p.length-1])}if(!c.groupIds.length)return ed(c,t,o,r)??l;let d=e.editingGroupId?c.groupIds[c.groupIds.indexOf(e.editingGroupId)-1]:c.groupIds[c.groupIds.length-1],u=Ae(t,d);return u.length?o==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},rd=(e,t)=>t.reduce((n,o)=>{let i=e[o];return n.set(i.id,i),n},new Map),sd=(e,t,n,o)=>{let i=id(e,t),r=rd(e,i),s=uE(i);n==="right"&&(s=s.reverse());let a=new Set(i.filter(l=>$(e[l])).map(l=>e[l].id));return s.forEach((l,c)=>{let d=l[0],u=l[l.length-1],p=n==="left"?d:u,m=l.some(y=>{let b=e[y];return b.frameId&&a.has(b.frameId)})?null:e[p]?.frameId,f=mE(t,e,p,n,m,o);if(f===-1||p===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,d),h=e.slice(d,u+1),g=n==="left"?e.slice(f,d):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...E,...h,...g,...x]:[...E,...g,...h,...x]}),po(e,r),e},ad=(e,t,n,o,i)=>{let r=id(e,t,i),s=rd(e,r),a=[],l,c;if(n==="left"){if(o)l=nd(e,f=>ws(f,o));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;c=r[r.length-1]}else{if(o)c=od(e,f=>ws(f,o));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;c=e.indexOf(f[f.length-1])}else c=e.length-1;l=r[0]}l===-1&&(l=0);for(let f=l;f<c+1;f++)r.includes(f)||a.push(e[f]);let d=Array.from(s.values()),u=e.slice(0,l),p=e.slice(c+1),m=n==="left"?[...u,...d,...a,...p]:[...u,...a,...d,...p];return po(m,s),m};function ld(e,t,n,o){let i=td(pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let c of e)i.has(c.id)&&$(c)&&s.add(c.id);for(let c of e)if(i.has(c.id))if($(c)||c.frameId&&s.has(c.frameId))r.regularElements.push(c);else if(!c.frameId)r.regularElements.push(c);else{let d=r.frameChildren.get(c.frameId)||[];d.push(c),r.frameChildren.set(c.frameId,d)}let a=e,l=Array.from(r.frameChildren.entries());for(let[c,d]of l)a=o(e,t,n,c,d);return o(a,t,n,null,r.regularElements)}var dS=(e,t,n)=>sd(e,t,"left",n),uS=(e,t,n)=>sd(e,t,"right",n),pS=(e,t)=>ld(e,t,"left",ad),mS=(e,t)=>ld(e,t,"right",ad);var wS=e=>e.reduce((t,n)=>t+n.version,0),ic=e=>{let t=5381;for(let n of fE(e))t=(t<<5)+t+n.versionNonce;return t>>>0},rc=e=>{let t=5381;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);t=(t<<5)+t+o}return t>>>0},yS=e=>e.filter(t=>!t.isDeleted&&!ql(t)),hE=e=>e.filter(t=>!t.isDeleted),bS=e=>!e.isDeleted,ys=e=>hE(e).map(t=>Ki(t.type)?{...t,lastCommittedPoint:null}:t),PS=e=>ys(e),IS=e=>ys(e),SS=e=>ys(e);export{fn as AppStateDelta,ee as BASE_PADDING,Rp as BINDING_HIGHLIGHT_THICKNESS,$t as BindableElement,Vt as BoundElement,Fe as CaptureUpdateAction,Vb as DEFAULT_LINK_SIZE,qc as DEFAULT_OMIT_SIDES,q as Delta,Zr as DurableIncrement,Ur as ElementBounds,hn as ElementsDelta,qr as EphemeralIncrement,ie as FIXED_BINDING_DISTANCE,_c as FlowChartCreator,Hc as FlowChartNavigator,we as HEADING_DOWN,Oe as HEADING_LEFT,me as HEADING_RIGHT,He as HEADING_UP,Um as IMAGE_INVERT_FILTER,gf as INVISIBLY_SMALL_ELEMENT_SIZE,Qr as InvalidFractionalIndexError,Y as LinearElementEditor,Ie as MINIMAL_CROP_SIZE,_I as OMIT_SIDES_FOR_FRAME,HI as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Ii as Scene,be as ShapeCache,ec as Store,co as StoreChange,Kr as StoreDelta,wi as StoreIncrement,Jt as StoreSnapshot,Ve as aabbForElement,Cm as addElementsToFrame,jh as addNewNodes,Uy as addToGroup,K0 as alignElements,$p as avoidRectangularCorner,bl as bindElementsToFramesAfterDuplication,mn as bindLinearElement,Tr as bindOrUnbindLinearElement,zp as bindOrUnbindLinearElements,Pr as bindPointToSnapToElementOutline,oi as bindingBorderTest,Za as bindingProperties,Ra as bumpVersion,ja as calculateFixedPointForElbowArrowBinding,Ax as canApplyRoundnessTypeToElement,la as canBecomePolygon,Rl as canChangeRoundness,xh as canCreateLinkFromElements,o0 as canHaveArrowheads,Ci as canResizeFromSides,Pn as charWidth,PS as clearElementsForDatabase,IS as clearElementsForExport,SS as clearElementsForLocalStorage,pe as compareHeading,xa as computeBoundTextPosition,sr as computeContainerDimensionForBoundText,jx as containsCJK,$P as createPlaceholderEmbeddableLabel,is as createSrcDoc,ux as cropElement,bn as deconstructDiamondElement,Bo as deconstructLinearOrFreeDrawElement,yn as deconstructRectanguloidElement,$r as deepCopyElement,yP as defaultGetElementLinkFromSelection,zx as detectLineHeight,_t as distanceToElement,oP as distributeElements,pn as doBoundsIntersect,hP as dragNewElement,mP as dragSelectedElements,Af as duplicateElement,u1 as duplicateElements,Yy as editGroupForSelectedElement,fe as elementCenterPoint,Zt as elementOverlapsWithFrame,Ei as elementWithCanvasCache,Kt as elementsAreInFrameBounds,El as elementsAreInSameGroup,qP as embeddableURLValidator,wl as excludeElementsInFramesFromSelection,Mb as filterElementsEligibleAsFrameChildren,py as fixBindingsAfterDeletion,$a as fixDuplicatedBindingsAfterDuplication,pr as flipHeading,Cb as frameAndChildrenSelectedTogether,Ol as generateFreeDrawShape,ta as generateLinearCollisionShape,ke as generateRoughOptions,ma as getApproxMinLineHeight,pa as getApproxMinLineWidth,qa as getArrowLocalFixedPoints,uf as getArrowheadAngle,Hr as getArrowheadPoints,df as getArrowheadSize,W as getBoundTextElement,It as getBoundTextElementId,ow as getBoundTextElementPosition,eo as getBoundTextMaxHeight,Je as getBoundTextMaxWidth,Xr as getBoundsFromPoints,ct as getCenterForBounds,R0 as getClosestElementBounds,Ct as getCommonBoundingBox,tt as getCommonBounds,tw as getContainerCenter,ar as getContainerCoords,Ce as getContainerElement,vt as getContainingFrame,yt as getCornerRadius,jo as getCubicBezierCurveBound,QI as getCursorForResizingElement,km as getDefaultFrameName,Dx as getDefaultRoundnessTypeForElement,Go as getDiamondPoints,fP as getDragOffsetXY,O0 as getDraggedElementsBounds,H as getElementAbsoluteCoords,he as getElementBounds,kr as getElementLineSegments,Lr as getElementPointsCoords,_l as getElementShape,qI as getElementWithTransformHandleType,Pl as getElementsCompletelyInFrame,Ae as getElementsInGroup,Sb as getElementsInNewFrame,Ib as getElementsInResizingFrame,gb as getElementsIntersectingFrame,Lb as getElementsOverlappingFrame,Or as getElementsWithinSelection,VP as getEmbedLink,px as getFlipAdjustedCropPosition,qt as getFrameChildren,vm as getFrameLikeElements,vb as getFrameLikeTitle,Vm as getFreeDrawPath2D,$m as getFreeDrawSvgPath,ti as getGlobalFixedPointForBindableElement,Jp as getGlobalFixedPoints,Oa as getHeadingForElbowArrowSnap,Wt as getHoveredElementForBinding,gI as getInitializedImageElements,Ho as getLineHeightInPx,Ht as getLineWidth,Lx as getLinearElementSubType,dI as getLinkDirectionFromKey,bP as getLinkIdAndTypeFromSelection,ol as getLockedLinearCursorAlignSize,wu as getMaxCharWidth,Wy as getMaximumGroups,_x as getMinCharWidth,so as getMinMaxXYFromCurvePathOps,zo as getMinTextElementWidth,xl as getNewGroupIdsForDuplication,hE as getNonDeletedElements,hl as getNonDeletedGroupIds,W0 as getNormalizedDimensions,Gn as getObservedAppState,fs as getOmitSidesForDevice,Ox as getOriginalContainerHeightFromCache,Wr as getPerfectElementSize,ls as getPredecessors,G0 as getRectangleBoxAbsoluteCoords,Xm as getRenderOpacity,GI as getResizeArrowDirection,BI as getResizeOffsetXY,Nt as getResizedElementAbsoluteCoords,Pb as getRootElements,wS as getSceneVersion,pt as getSelectedElements,ui as getSelectedElementsByGroup,Gr as getSelectedGroupForElement,Sm as getSelectedGroupIdForElement,Pm as getSelectedGroupIds,ib as getSelectionStateForElements,cy as getSuggestedBindingsForArrows,ob as getTargetElements,Gm as getTargetFrame,nw as getTextElementAngle,aw as getTextFromElements,xu as getTextHeight,fa as getTextWidth,KI as getTransformHandleTypeFromCoords,Kc as getTransformHandles,hs as getTransformHandlesFromCoords,Qs as getUncroppedImageElement,ji as getUncroppedWidthAndHeight,tb as getVisibleAndNonSelectedElements,yS as getVisibleElements,k0 as getVisibleSceneBounds,bb as groupByFrameLikes,wb as groupsAreAtLeastIntersectingTheFrame,yb as groupsAreCompletelyOutOfFrame,un as handleBindTextResize,Qb as hasBackground,st as hasBoundTextElement,Jb as hasStrokeColor,t0 as hasStrokeStyle,e0 as hasStrokeWidth,ic as hashElementsVersion,rc as hashString,Ge as headingForPoint,to as headingForPointFromElement,et as headingForPointIsHorizontal,Re as headingIsHorizontal,Bw as headingIsVertical,ep as hitElementBoundText,Ju as hitElementBoundingBox,Tw as hitElementBoundingBoxOnly,Qu as hitElementItself,In as intersectElementWithLineSegment,Tx as isArrowBoundToElement,_ as isArrowElement,Le as isBindableElement,Qi as isBindingElement,uu as isBindingElementType,Mr as isBindingEnabled,de as isBoundToContainer,vx as isBounds,xb as isCursorInFrame,du as isCurvedArrow,G as isElbowArrow,X0 as isElementCompletelyInViewport,Fr as isElementContainingFrame,Sl as isElementInFrame,Im as isElementInGroup,yl as isElementInViewport,Cn as isElementIntersectingFrame,PP as isElementLink,oa as isEmbeddableElement,Mx as isExcalidrawElement,Qn as isFixedPointBinding,Ji as isFlowchartNodeElement,ko as isFrameElement,$ as isFrameLikeElement,Se as isFreeDrawElement,lu as isFreeDrawElementType,Zh as isHTMLSVGElement,Oo as isIframeElement,Ro as isIframeLikeElement,xe as isImageElement,gl as isInGroup,zt as isInitializedImageElement,ql as isInvisiblySmallElement,cn as isLineElement,X as isLinearElement,Xa as isLinearElementSimpleAndAlreadyBound,Ki as isLinearElementType,ia as isMagicFrameElement,Nx as isMeasureTextSupported,uI as isNodeInFlowchart,bS as isNonDeletedElement,ln as isPathALoop,Sa as isPointInElement,Sx as isRectangularElement,ra as isRectanguloidElement,bm as isSelectedViaGroup,cu as isSharpArrow,Ix as isSimpleArrow,nb as isSomeElementSelected,pu as isTextBindableContainer,oe as isTextElement,sa as isUsingAdaptiveRadius,aa as isUsingProportionalRadius,Cx as isValidPolygon,sw as isValidTextContainer,$h as loadHTMLImageElement,Br as makeNextSelectedElementIds,ai as maxBindingGap,dy as maybeBindLinearElement,ZP as maybeParseEmbedSrc,Ya as maybeSuggestBindingsForLinearElementAtCoords,us as measureFontSizeFromWidth,Qe as measureText,pS as moveAllLeft,mS as moveAllRight,dS as moveOneLeft,uS as moveOneRight,ye as mutateElement,Gc as newArrowElement,ns as newElement,Me as newElementWith,GP as newEmbeddableElement,RP as newFrameElement,NP as newFreeDrawElement,OP as newIframeElement,HP as newImageElement,zP as newLinearElement,kP as newMagicFrameElement,Bc as newTextElement,Kl as normalizeElementOrder,Ar as normalizeFixedPoint,xI as normalizeSVG,tr as normalizeText,pi as omitGroupsContainingFrameLikes,Lm as omitPartialGroups,pc as orderByFractionalIndex,Jn as originalContainerCache,IP as parseElementLinkFromURL,Tu as parseTokens,Gl as pathsCache,Mn as pointInsideBounds,ga as redrawTextBoundingBox,FP as refreshTextDimensions,Bm as removeAllElementsFromFrame,Il as removeElementsFromFrame,Xy as removeFromSelectedGroups,Zb as renderElement,$b as renderSelectionElement,Tb as replaceAllElementsInFrame,jc as rescalePointsInElement,da as resetOriginalContainerCache,iE as resizeMultipleElements,tE as resizeSingleElement,Qh as resizeSingleTextElement,cE as resizeTest,ym as selectGroup,ml as selectGroupsForSelectedElements,fl as selectGroupsFromGivenElements,Hx as setCustomTextMetricsProvider,iw as shouldAllowVerticalAlign,Db as shouldApplyFrameClip,ly as shouldEnableBindingForPointerEvent,YI as shouldShowBoundingBox,Wo as shouldTestInside,nS as showSelectedShapeActions,Zp as snapToMid,rw as suppportsHorizontalAlign,Ff as syncInvalidIndices,oc as syncInvalidIndicesImmutable,po as syncMovedIndices,nl as toggleLinePolygonState,n0 as toolIsArrow,CI as transformElements,uy as updateBindings,Ue as updateBoundElements,Tn as updateElbowArrowPoints,Ab as updateFrameMembershipOfSelectedElements,EI as updateImageCache,ca as updateOriginalContainerCache,Ga as validateElbowPoints,kf as validateFractionalIndices,Mt as vectorToHeading,Pt as wrapText};
|
|
27
|
+
`),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return ht.set(e,m),m}return ht.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},DI=e=>{let t;to(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=nE.Helvetica,o=oE({fontSize:n,fontFamily:i});return Ln({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:Tt(t,o,e.width-20),textAlign:"center",verticalAlign:iE.MIDDLE,angle:e.angle??0})},Cs=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(Bs.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return Bs.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},LI=e=>{let t=e.match(cE);if(t&&t.length===2)return t[1];let n=e.match(pE);if(n&&n.length===2)return n[1];let i=e.match(lE);if(i&&i.length===2)return i[1];if(ac.test(e))return`https://giphy.com/embed/${ac.exec(e)[1]}`;let o=e.match(mE);return o&&o.length===2?o[1]:e},BI=(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(Cs(e,n))return!0;return!1}}return!!Cs(e,Bs)};P();import{KEYS as qo,invariant as Ko,toBrandedType as hE}from"@excalidraw/common";import{pointFrom as cc}from"@excalidraw/math";var Zn=100,Bn=100,jI=e=>{switch(e){case qo.ARROW_UP:return"up";case qo.ARROW_DOWN:return"down";case qo.ARROW_RIGHT:return"right";case qo.ARROW_LEFT:return"left";default:return"right"}},pc=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(Y(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;Ko(Ce(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=hi(t,qe(t,n),[d[0]+s.x,d[1]+s.y]);r.push({relative:l,heading:c})}return r},[]);switch(i){case"up":return o.filter(r=>pe(r.heading,We)).map(r=>r.relative);case"down":return o.filter(r=>pe(r.heading,we)).map(r=>r.relative);case"right":return o.filter(r=>pe(r.heading,fe)).map(r=>r.relative);case"left":return o.filter(r=>pe(r.heading,ke)).map(r=>r.relative)}},Gs=(e,t,n)=>pc("successors",e,t,n),Os=(e,t,n)=>pc("predecessors",e,t,n),EE=(e,t,n)=>{let i=Bn+e.width;if(n==="up"||n==="down"){let a=Zn+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:(Bn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Zn+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=Zn+e.height,r=(t.length===0,Bn+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}},gE=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=Gs(e,o,n),s=Os(e,o,n),a=EE(e,[...r,...s],n),l=Dn({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});Ko(yr(l),"not an ExcalidrawFlowchartNodeElement");let d=fc(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},xE=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=Zn*(o-1)+o*e.height,m=e.y+e.height/2-u/2,p=Bn+e.width;n==="left"&&(p*=-1),a=e.x+p;let f=(Zn+e.height)*s;l=m+f}else{let u=Bn*(o-1)+o*e.width,m=e.x+e.width/2-u/2,p=Zn+e.height;n==="up"&&(p*=-1),l=e.y+p;let f=(Bn+e.width)*s;a=m+f}let d=Dn({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});Ko(yr(d),"not an ExcalidrawFlowchartNodeElement");let c=fc(e,d,n,t,i);r.push(d),r.push(c)}return r},fc=(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=Zo({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:[cc(0,0),cc(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();Tn(c,e,"orbit","start",o),Tn(c,t,"orbit","end",o);let m=new Map;m.set(e.id,e),m.set(t.id,t),m.set(c.id,c),O.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=Nn(c,hE(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p}},uc=class{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!Ce(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...Gs(t,n,i),...Os(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=>[...Gs(t,n,a),...Os(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}},mc=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}=gE(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=xE(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);Ko(s&&io(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>ln([a],s,r)||sn(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>ye(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},XI=(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 hc,SVG_NS as wE}from"@excalidraw/common";var yE=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),KI=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===hc.binary)throw new Error("Only images can be added to ImageCache");let l=yE(a.dataURL),d={image:l,mimeType:a.mimeType};n.set(s,d);let c=await l;n.set(s,{...d,image:c})}catch{o.set(s,!0)}})())):r},[])),{imageCache:n,updatedFiles:i,erroredFiles:o}},QI=e=>e.filter(t=>yn(t)),bE=e=>e?.nodeName.toLowerCase()==="svg",JI=e=>{let t=new DOMParser().parseFromString(e,hc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!bE(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",wE);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 oS=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(p=>[p]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let p=0;p<s;p+=a)l.push(r.slice(p,p+a));let d=0,c=l.map(p=>{let f=0,h=0,E=p.map(g=>{let[x,w,b,y]=De(g);return{elements:g,bounds:[x,w,b,y],width:b-x,height:y-w}});return E.forEach((g,x)=>{f+=g.width,x<E.length-1&&(f+=i),g.height>h&&(h=g.height)}),d+=h,{unitBounds:E,width:f,maxHeight:h}}),u=d+Math.max(0,l.length-1)*i,m=n-u/2;return c.forEach(p=>{let{unitBounds:f,width:h,maxHeight:E}=p,g=t-h/2;f.forEach(x=>{let[w,b]=x.bounds,y=g-w,I=m-b;x.elements.forEach(S=>{o.push(ge(S,{x:S.x+y,y:S.y+I}))}),g+=x.width+i}),m+=E+i}),o};P();import{pointCenter as PE,normalizeRadians as Jo,pointFrom as ie,pointRotateRads as st}from"@excalidraw/math";import{MIN_FONT_SIZE as Rs,SHIFT_LOCKING_ANGLE as er,rescalePoints as Ec,getFontString as Qo}from"@excalidraw/common";var gS=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[m]=n;if(t==="rotation")Y(m)||(IE(m,i,a,l,o),je(m,i));else if(t){let p=n[0].id,f=u.get(p),h=e.get(p);if(f&&h){let{nextWidth:E,nextHeight:g}=vE(f,h,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});TE(E,g,f,h,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return ee(m)&&je(m,i),!0}else if(n.length>1){if(t==="rotation")return ME(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:f,flipByY:h,originalBoundingBox:E}=DE(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return LE(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:h,nextWidth:m,nextHeight:p,originalBoundingBox:E}),!0}}return!1},IE=(e,t,n,i,o)=>{let[r,s,a,l]=X(e,t.getNonDeletedElementsMap()),d=(r+a)/2,c=(s+l)/2,u;K(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-c,n-d),o&&(u=u+er/2,u=u-u%er),u=Jo(u));let m=vt(e),p={angle:u};if(Be(e)&&(p={...p},e.startBinding&&Ke(e,"start",t),e.endBinding&&Ke(e,"end",t)),t.mutateElement(e,p),m){let f=t.getElement(m);if(f&&!H(e)){let{x:h,y:E}=mi(e,f,t.getNonDeletedElementsMap());t.mutateElement(f,{angle:u,x:h,y:E})}}},gc=(e,t,n,i)=>Q(e)||Ie(e)?{points:Ec(0,t,Ec(1,n,e.points,i),i)}:{},Fs=(e,t,n)=>{let i=e.width;if(ce(e)){let s=Se(e,t);s&&(i=nt(s,e))}let r=e.fontSize*(n/i);return r<Rs?null:{size:r}},SE=(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=ie(e.x,e.y),u=ks(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=ao(Qo({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=Tt(t.originalText,Qo(t),Math.abs(u)),p=_e(m,Qo(t),t.lineHeight),f=p.height,h=ie(e.x,e.y),E=ks(h,e.width,e.height,u,f,t.angle,i,!1,o),g={width:Math.abs(u),height:Math.abs(p.height),x:E.x,y:E.y,text:m,autoResize:!1};n.mutateElement(t,g)}}},ME=(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+=er/2,d-=d%er);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!K(u)){let[m,p,f,h]=X(u,l),E=(m+f)/2,g=(p+h)/2,x=e.get(u.id)?.angle??u.angle,[w,b]=st(ie(E,g),ie(s,a),d+x-u.angle),y=Y(u)?{points:wl(u,l)}:{x:u.x+(w-E),y:u.y+(b-g),angle:Jo(d+x)};n.mutateElement(u,y),je(u,n,{simultaneouslyUpdated:t}),Be(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||Ke(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||Ke(u,"end",n)));let I=V(u,l);if(I&&!H(u)){let{x:S,y:A}=mi(u,I,l);n.mutateElement(I,{x:S,y:A,angle:Jo(d+x)})}}n.triggerUpdate()},xS=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?X(t[0],n):De(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=st(ie(i,o),ie(d,c),-u),e){case"n":return st(ie(i-(r+a)/2,o-s),ie(0,0),u);case"s":return st(ie(i-(r+a)/2,o-l),ie(0,0),u);case"w":return st(ie(i-r,o-(s+l)/2),ie(0,0),u);case"e":return st(ie(i-a,o-(s+l)/2),ie(0,0),u);case"nw":return st(ie(i-r,o-s),ie(0,0),u);case"ne":return st(ie(i-a,o-s),ie(0,0),u);case"sw":return st(ie(i-r,o-l),ie(0,0),u);case"se":return st(ie(i-a,o-l),ie(0,0),u);default:return[0,0]}},wS=(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"},ks=(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)}}},TE=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(ee(n)&&ee(i))return SE(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=V(n,u);if(m){let E=o.get(m.id);if(E&&(c={fontSize:E.fontSize}),l){let g={...n,width:e,height:t},x=Fs(m,u,nt(g,m));if(x===null)return;c={fontSize:x.size}}else{let g=_a(Qo(m),m.lineHeight),x=Ua(m.fontSize,m.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let p=gc(i,e,t,!0),f=ie(i.x,i.y);if(Q(i)){let[E,g]=ae(i,o);f=ie(E,g)}let h=ks(f,i.width,i.height,e,t,i.angle,s,l,d);if(Q(i)&&p.points){let E=i.x-f[0],g=i.y-f[1];h.x+=E,h.y+=g;let x=p.points[0][0],w=p.points[0][1];h.x+=x,h.y+=w,p.points=p.points.map(b=>ie(b[0]-x,b[1]-w))}if(e<0&&(h.x=h.x+e),t<0&&(h.y=h.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),H(n)&&m&&l){let E=e/n.width*m.fontSize;if(E<Rs)return;c.fontSize=E}if(e!==0&&t!==0&&Number.isFinite(h.x)&&Number.isFinite(h.y)){let E={...h,width:Math.abs(e),height:Math.abs(t),...p};Be(n)&&(n.startBinding&&(E={...E},n.startBinding&&Ke(n,"start",r)),n.endBinding&&(E={...E,endBinding:null})),r.mutateElement(n,E,{informMutation:a,isDragging:!1}),m&&c!=null&&r.mutateElement(m,{fontSize:c.fontSize}),In(n,r,s,l),je(n,r)}},vE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=jt(t,t.width,t.height,!0),u=ie(a,l),m=ie(d,c),p=PE(u,m),f=st(ie(i,o),p,-t.angle),[h,E,g,x]=jt(e,e.width,e.height,!0),w=g-h,b=x-E,y=m[0]-u[0],I=m[1]-u[1],S=y/w,A=I/b;n.includes("e")&&(S=(f[0]-u[0])/w),n.includes("s")&&(A=(f[1]-u[1])/b),n.includes("w")&&(S=(m[0]-f[0])/w),n.includes("n")&&(A=(m[1]-f[1])/b);let M=e.width*S,k=e.height*A;if(s&&(M=2*M-t.width,k=2*k-t.height),r){let L=Math.abs(M)/t.width,G=Math.abs(k)/t.height;if(n.length===1&&(k*=L,M*=G),n.length===2){let B=Math.max(L,G);M=t.width*B*Math.sign(M),k=t.height*B*Math.sign(k)}}return{nextWidth:M,nextHeight:k}},DE=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(B=>t.get(B.id)),d=l.reduce((B,U)=>{if(!Q(U))return B;let N=vt(U);if(!N)return B;let W=t.get(N)??null;return ce(W)?[...B,{...W,...O.getBoundTextElementPosition(U,W,n)}]:B},[]),c=Ft(l.map(B=>B).concat(d)),{minX:u,minY:m,maxX:p,maxY:f,midX:h,midY:E}=c,g=p-u,x=f-m,w={ne:[u,f],se:[u,m],sw:[p,m],nw:[p,f],e:[u,m+x/2],w:[p,m+x/2],n:[u+g/2,f],s:[u+g/2,m]},[b,y]=a?[h,E]:w[i],I=a?2:1,S=Math.max(Math.abs(o-b)/g||0,Math.abs(r-y)/x||0)*I,A=i.includes("e")||i.includes("w")?Math.abs(o-b)*I:g,M=i.includes("n")||i.includes("s")?Math.abs(r-y)*I:x;s&&(A=g*S*Math.sign(o-b),M=x*S*Math.sign(r-y));let k={ne:[o<b,r>y],se:[o<b,r<y],sw:[o>b,r<y],nw:[o>b,r>y],e:[o<b,!1],w:[o>b,!1],n:[!1,r>y],s:[!1,r<y]},[L,G]=k[i].map(B=>B);return{originalBoundingBox:c,nextWidth:A,nextHeight:M,flipByX:L,flipByY:G}},LE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:d,nextWidth:c,originalBoundingBox:u}={})=>{if(c===void 0&&d===void 0&&a===void 0&&l===void 0||d===0||c===0)return;o||(o=t);let m=e.reduce((I,S)=>{let A=o.get(S.id);return A&&I.push({orig:A,latest:S}),I},[]),p;if(u)p=u;else{let I=m.reduce((S,{orig:A})=>{if(!Q(A))return S;let M=vt(A);if(!M)return S;let k=o.get(M)??null;return ce(k)?[...S,{...k,...O.getBoundTextElementPosition(A,k,t)}]:S},[]);p=Ft(m.map(({orig:S})=>S).concat(I))}let{minX:f,minY:h,maxX:E,maxY:g,midX:x,midY:w}=p,b=E-f,y=g-h;if(c===void 0&&d===void 0&&(c=b,d=y),r&&(c===void 0?c=d*(b/y):d===void 0?d=c*(y/b):Math.abs(c/d-b/y)>.001&&(c=d*(b/y))),c&&d){let I=n.includes("e")||n.includes("w")?Math.abs(c)/b:1,S=n.includes("n")||n.includes("s")?Math.abs(d)/y:1,A;n.length===1?A=n.includes("e")||n.includes("w")?I:S:A=Math.max(Math.abs(c)/b||0,Math.abs(d)/y||0);let M={ne:[f,g],se:[f,h],sw:[E,h],nw:[E,g],e:[f,h+y/2],w:[E,h+y/2],n:[f+b/2,g],s:[f+b/2,h]},[k,L]=s?[x,w]:M[n],G=r||m.some(T=>T.latest.angle!==0||ee(T.latest)||Yl(T.latest));G&&(I=A,S=A);let[B,U]=[a?-1:1,l?-1:1],N=[];for(let{orig:T,latest:$}of m){if(ee(T)&&ce(T))continue;let Z=T.width*I,Et=T.height*S,at=Jo(T.angle*B*U),Oi=Q(T)||Ie(T),rr=T.x-k,ki=T.y-L,qn=a&&!Oi?Z:0,sr=l&&!Oi?Et:0,Ri=k+B*(rr*I+qn),Fi=L+U*(ki*S+sr),He=gc(T,Z*B,Et*U,!1),Xe={x:Ri,y:Fi,width:Z,height:Et,angle:at,...He};if(Y(T)&&(T.startBinding&&(Xe.startBinding={...T.startBinding,fixedPoint:[a?-T.startBinding.fixedPoint[0]+1:T.startBinding.fixedPoint[0],l?-T.startBinding.fixedPoint[1]+1:T.startBinding.fixedPoint[1]]}),T.endBinding&&(Xe.endBinding={...T.endBinding,fixedPoint:[a?-T.endBinding.fixedPoint[0]+1:T.endBinding.fixedPoint[0],l?-T.endBinding.fixedPoint[1]+1:T.endBinding.fixedPoint[1]]}),T.fixedSegments&&He.points&&(Xe.fixedSegments=T.fixedSegments.map(gt=>({...gt,start:He.points[gt.index-1],end:He.points[gt.index]})))),xe(T)&&(Xe.scale=[T.scale[0]*B,T.scale[1]*U]),ee(T)){let gt=Fs(T,t,Z);if(!gt)return;Xe.fontSize=gt.size}let _t=o.get(vt(T)??"");if(_t)if(G){let gt=_t.fontSize*A;if(gt<Rs)return;Xe.boundTextFontSize=gt}else Xe.boundTextFontSize=_t.fontSize;N.push({element:$,update:Xe})}let W=N.map(({element:T})=>T),F=new Map(N.map(({element:T})=>[T.id,T]));for(let{element:T,update:{boundTextFontSize:$,...Z}}of N){let{angle:Et}=Z;i.mutateElement(T,Z),je(T,i,{simultaneouslyUpdated:W}),Be(T)&&(T.startBinding&&(F.has(T.startBinding.elementId)||Ke(T,"start",i)),T.endBinding&&(F.has(T.endBinding.elementId)||Ke(T,"end",i)));let at=V(T,t);at&&$&&(i.mutateElement(at,{fontSize:$,angle:Q(T)?void 0:Et}),In(T,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as Qe,pointOnLineSegment as Ic,pointRotateRads as nr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as Ws}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as Hs}from"@excalidraw/common";import{pointFrom as xc,pointRotateRads as BE}from"@excalidraw/math";var wc={mouse:8,pen:16,touch:28},CE=16,bc={e:!0,s:!0,n:!0,w:!0},AS={e:!0,s:!0,n:!0,w:!0},TS={e:!0,s:!0,n:!0,w:!0,rotation:!0},yc={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},Ns={e:!0,s:!0,n:!0,w:!0},zt=(e,t,n,i,o,r,s)=>{let[a,l]=BE(xc(e+n/2,t+i/2),xc(o,r),s);return[a-n/2,l-i/2,n,i]},tr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),zs=e=>tr(e)?bc:{},_s=([e,t,n,i,o,r],s,a,l,d={},c=4,u=Hs)=>{let m=wc[l],p=m/a.value,f=m/a.value,h=m/a.value,E=m/a.value,g=n-e,x=i-t,w=c/a.value,b=(m-u*2)/(2*a.value),y={nw:d.nw?void 0:zt(e-w-h+b,t-w-E+b,p,f,o,r,s),ne:d.ne?void 0:zt(n+w-b,t-w-E+b,p,f,o,r,s),sw:d.sw?void 0:zt(e-w-h+b,i+w-b,p,f,o,r,s),se:d.se?void 0:zt(n+w-b,i+w-b,p,f,o,r,s),rotation:d.rotation?void 0:zt(e+g/2-p/2,t-w-E+b-CE/a.value,p,f,o,r,s)},I=5*wc.mouse/a.value;return Math.abs(g)>I&&(d.n||(y.n=zt(e+g/2-p/2,t-w-E+b,p,f,o,r,s)),d.s||(y.s=zt(e+g/2-p/2,i+w-b,p,f,o,r,s))),Math.abs(x)>I&&(d.w||(y.w=zt(e-w-h+b,t+x/2-f/2,p,f,o,r,s)),d.e||(y.e=zt(n+w-b,t+x/2-f/2,p,f,o,r,s))),y},Pc=(e,t,n,i="mouse",o=bc)=>{if(e.locked||Y(e))return{};if(e.type==="freedraw"||Q(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=Ns:s[0]>0&&s[1]<0?o=yc:s[0]>0&&s[1]>0?o=Ns:s[0]<0&&s[1]>0?o=yc:s[0]<0&&s[1]<0&&(o=Ns)}}else K(e)&&(o={...o,rotation:!0});let r=Q(e)?Hs+8:xe(e)?0:Hs;return _s(X(e,n,!0),e.angle,t,i,o,r,xe(e)?0:void 0)},vS=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return Y(i)?!1:Q(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var Ys=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],GE=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=Pc(e,r,t,s,zs(a));if(l&&Ys(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?Ys(m,i,o):!1});if(c.length>0)return c[0];if(tr(a)){let[u,m,p,f,h,E]=X(e,t);if(!(Q(e)&&e.points.length<=2)){let g=xe(e)?0:Ws/r.value,x=Ws/r.value,w=Sc(Qe(u-g,m-g),Qe(p+g,f+g),Qe(h,E),e.angle);for(let[b,y]of Object.entries(w))if(Ic(Qe(i,o),y,x))return b}}return!1},RS=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=GE(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),FS=([e,t,n,i],o,r,s,a,l)=>{let d=_s([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,zs(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&Ys(m,o,r)});if(c)return c;if(tr(l)){let u=(e+n)/2,m=(t+i)/2,p=Ws/s.value,f=Sc(Qe(e-p,t-p),Qe(n+p,i+p),Qe(u,m),0);for(let[h,E]of Object.entries(f))if(Ic(Qe(o,r),E,p))return h}return!1},Us=["ns","nesw","ew","nwse"],OE=(e,t)=>{let n=Us.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=Us[(n+i)%Us.length]}return e},NS=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=OE(o,t.angle)),o?`${o}-resize`:""},Sc=([e,t],[n,i],o,r)=>{let s=nr(Qe(e,t),o,r),a=nr(Qe(n,t),o,r),l=nr(Qe(e,i),o,r),d=nr(Qe(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var US=(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{pointFrom as ir}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as kE,DEFAULT_FONT_SIZE as RE,TEXT_ALIGN as FE,VERTICAL_ALIGN as NE,getSizeFromPoints as HE,randomId as zE,arrayToMap as _E,assertNever as js,cloneJSON as Ac,getFontString as UE,isDevEnv as WE,toBrandedType as YE,getLineHeight as jE}from"@excalidraw/common";var or={width:100,height:0},En=100,XE=(e,t,n)=>{let i=Ln({x:0,y:0,textAlign:FE.CENTER,verticalAlign:NE.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),mo(i,e,n),[e,i]},Mc=(e,t,n,i,o)=>{let r,s;if(Object.assign(e,{startBinding:e?.startBinding||null,endBinding:e.endBinding||null}),t){let c=t?.width??En,u=t?.height??En,m;t.id&&(m=i.getElement(t.id),m||console.error(`No element for start binding with id ${t.id} found`));let p=t.x||e.x-c,f=t.y||e.y-u/2,h=m?m.type:t.type;if(h){if(h==="text"){let E="";m&&m.type==="text"?E=m.text:t.type==="text"&&(E=t.text),E||console.error(`No text found for start binding text element for ${e.id}`),r=Ln({x:p,y:f,type:"text",...m,...t,text:E}),Object.assign(r,{x:t.x||e.x-r.width,y:t.y||e.y-r.height/2})}else switch(h){case"rectangle":case"ellipse":case"diamond":{r=Dn({x:p,y:f,width:c,height:u,...m,...t,type:h});break}default:js(e,`Unhandled element start type "${t.type}"`,!0)}Tn(e,r,"orbit","start",o)}}if(n){let c=n?.height??En,u=n?.width??En,m;n.id&&(m=i.getElement(n.id),m||console.error(`No element for end binding with id ${n.id} found`));let p=n.x||e.x+e.width,f=n.y||e.y-c/2,h=m?m.type:n.type;if(h){if(h==="text"){let E="";m&&m.type==="text"?E=m.text:n.type==="text"&&(E=n.text),E||console.error(`No text found for end binding text element for ${e.id}`),s=Ln({x:p,y:f,type:"text",...m,...n,text:E}),Object.assign(s,{y:n.y||e.y-s.height/2})}else switch(h){case"rectangle":case"ellipse":case"diamond":{s=Dn({x:p,y:f,width:u,height:c,...m,...n,type:h});break}default:js(e,`Unhandled element end type "${h}"`,!0)}Tn(e,s,"orbit","end",o)}}if(e.points.length<2)return{linearElement:e,startBoundElement:r,endBoundElement:s};let a=e.points.length-1,l=.5,d=Ac(e.points);return e.points[a][0]>e.points[a-1][0]&&(d[0][0]=l,d[a][0]-=l),e.points[a][0]<e.points[a-1][0]&&(d[0][0]=-l,d[a][0]+=l),e.points[a][1]>e.points[a-1][1]&&(d[0][1]=l,d[a][1]-=l),e.points[a][1]<e.points[a-1][1]&&(d[0][1]=-l,d[a][1]+=l),Object.assign(e,O.getNormalizeElementPointsAndCoords({...e,points:d})),{linearElement:e,startBoundElement:r,endBoundElement:s}},Xs=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>Ms(Array.from(this.excalidrawElements.values()));getElementsMap=()=>YE(_E(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},nM=(e,t)=>{if(!e)return[];let n=Ac(e),i=new Xs,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:zE()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||En,p=l?.label?.text&&l.height===void 0?0:l?.height||En;d=Dn({...l,width:m,height:p});break}case"line":{let m=l.width||or.width,p=l.height||or.height;d=ic({width:m,height:p,points:[ir(0,0),ir(m,p)],...l});break}case"arrow":{let m=l.width||or.width,p=l.height||or.height;d=Zo({width:m,height:p,endArrowhead:"arrow",points:[ir(0,0),ir(m,p)],...l,type:"arrow"}),Object.assign(d,HE(d.points));break}case"text":{let m=l?.fontFamily||kE,p=l?.fontSize||RE,f=l?.lineHeight||jE(m),h=l.text??"",E=ui(h),g=_e(E,UE({fontFamily:m,fontSize:p}),f);d=Ln({width:g.width,height:g.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=oc({width:l?.width||En,height:l?.height||En,...l});break}case"frame":{d=ec({x:0,y:0,...l});break}case"magicframe":{d=tc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,js(l,`Unhandled element type "${l.type}"`,!0)}i.getElement(d.id)?console.error(`Duplicate id found for ${d.id}`):(i.add(d),o.set(d.id,l),c&&r.set(c,d.id))}let s=i.getElementsMap(),a=new $n(s);for(let[l,d]of o){let c=i.getElement(l);switch(d.type){case"rectangle":case"ellipse":case"diamond":case"arrow":{if(d.label?.text){let[u,m]=XE(c,d?.label,a);if(i.add(u),i.add(m),H(u)){let p=d.type==="arrow"?d?.start:void 0,f=d.type==="arrow"?d?.end:void 0;if(p&&p.id){let x=r.get(p.id);x&&Object.assign(p,{id:x})}if(f&&f.id){let x=r.get(f.id);x&&Object.assign(f,{id:x})}let{linearElement:h,startBoundElement:E,endBoundElement:g}=Mc(u,p,f,i,a);u=h,i.add(h),i.add(E),i.add(g)}}else switch(d.type){case"arrow":{let{start:u,end:m}=d;if(u&&u.id){let E=r.get(u.id);Object.assign(u,{id:E})}if(m&&m.id){let E=r.get(m.id);Object.assign(m,{id:E})}let{linearElement:p,startBoundElement:f,endBoundElement:h}=Mc(c,u,m,i,a);i.add(p),i.add(f),i.add(h);break}}break}}}for(let[l,d]of o){if(d.type!=="frame"&&d.type!=="magicframe")continue;let c=i.getElement(l);if(!c)throw new Error(`Excalidraw element with id ${l} doesn't exist`);let u=[];d.children.forEach(y=>{let I=r.get(y);if(!I)throw new Error(`Element with ${y} wasn't mapped correctly`);let S=i.getElement(I);if(!S)throw new Error(`Frame element with id ${I} doesn't exist`);Object.assign(S,{frameId:c.id}),S?.boundElements?.forEach(A=>{let M=i.getElement(A.id);if(!M)throw new Error(`Bound element with id ${A.id} doesn't exist`);Object.assign(M,{frameId:c.id}),u.push(M)}),u.push(S)});let[m,p,f,h]=De(u),E=10;m=m-E,p=p-E,f=f+E,h=h+E;let g=c?.x||m,x=c?.y||p,w=c?.width||f-m,b=c?.height||h-p;Object.assign(c,{x:g,y:x,width:w,height:b}),WE()&&d.children.length&&(c?.x||c?.y||c?.width||c?.height)&&console.info("User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically")}return i.getElements()};P();import{arrayToMap as vc,findIndex as Dc,findLastIndex as Lc}from"@excalidraw/common";var Vs=(e,t)=>e.frameId===t||e.id===t,Bc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=vc(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},VE=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),[])},Tc=(e,t,n,i)=>{if("containerId"in e&&e.containerId){let o=i.getElement(e.containerId);if(o)return n==="left"?Math.min(t.indexOf(o),t.indexOf(e)):Math.max(t.indexOf(o),t.indexOf(e))}else{let o=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(o){let r=i.getElement(o);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},$E=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{Vs(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},mM=(e,t,n,i,o)=>{let r=Dt(e,n,i);if(!r)return n;let s=V(r,i),a=ee(r)?Se(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),m=u.splice(c,1)[0];u.splice(d,0,m),o.replaceAllElements(u)}return n},ZE=(e,t,n,i,o,r)=>{let s=t[n],a=m=>m.isDeleted?!1:o?m.frameId===o:e.editingGroupId?m.groupIds.includes(e.editingGroupId):!0,l=i==="left"?Lc(t,m=>a(m),Math.max(0,n-1)):Dc(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Tc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||K(d))){let m=$E(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Tc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=ve(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},Cc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Gc=(e,t,n,i)=>{let o=Bc(e,t),r=Cc(e,o),s=VE(o);n==="right"&&(s=s.reverse());let a=new Set(o.filter(l=>K(e[l])).map(l=>e[l].id));return s.forEach((l,d)=>{let c=l[0],u=l[l.length-1],m=n==="left"?c:u,p=l.some(w=>{let b=e[w];return b.frameId&&a.has(b.frameId)})?null:e[m]?.frameId,f=ZE(t,e,m,n,p,i);if(f===-1||m===f)return;let h=n==="left"?e.slice(0,f):e.slice(0,c),E=e.slice(c,u+1),g=n==="left"?e.slice(f,c):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...h,...E,...g,...x]:[...h,...g,...E,...x]}),Gi(e,r),e},Oc=(e,t,n,i,o)=>{let r=Bc(e,t,o),s=Cc(e,r),a=[],l,d;if(n==="left"){if(i)l=Dc(e,f=>Vs(f,i));else if(t.editingGroupId){let f=ve(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=Lc(e,f=>Vs(f,i));else if(t.editingGroupId){let f=ve(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let c=Array.from(s.values()),u=e.slice(0,l),m=e.slice(d+1),p=n==="left"?[...u,...c,...a,...m]:[...u,...a,...c,...m];return Gi(p,s),p};function kc(e,t,n,i){let o=vc(pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)o.has(d.id)&&K(d)&&s.add(d.id);for(let d of e)if(o.has(d.id))if(K(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 pM=(e,t,n)=>Gc(e,t,"left",n),fM=(e,t,n)=>Gc(e,t,"right",n),hM=(e,t)=>kc(e,t,"left",Oc),EM=(e,t)=>kc(e,t,"right",Oc);var bM=e=>e.reduce((t,n)=>t+n.version,0),vd=e=>{let t=5381;for(let n of qE(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},PM=e=>e.filter(t=>!t.isDeleted&&!yd(t)),IM=e=>e.filter(t=>!t.isDeleted),SM=e=>!e.isDeleted;export{cn as AppStateDelta,pl as BASE_BINDING_GAP,An as BASE_BINDING_GAP_ELBOW,ne as BASE_PADDING,on as BindableElement,nn as BoundElement,Ne as CaptureUpdateAction,B0 as DEFAULT_LINK_SIZE,bc as DEFAULT_OMIT_SIDES,_ as Delta,ys as DurableIncrement,fs as ElementBounds,un as ElementsDelta,bs as EphemeralIncrement,mc as FlowChartCreator,uc as FlowChartNavigator,we as HEADING_DOWN,ke as HEADING_LEFT,fe as HEADING_RIGHT,We as HEADING_UP,Wf as INVISIBLY_SMALL_ELEMENT_SIZE,Is as InvalidFractionalIndexError,O as LinearElementEditor,Pe as MINIMAL_CROP_SIZE,TS as OMIT_SIDES_FOR_FRAME,AS as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,$n as Scene,Ye as ShapeCache,Sd as Store,Bi as StoreChange,Ps as StoreDelta,Wo as StoreIncrement,mn as StoreSnapshot,qe as aabbForElement,nf as addElementsToFrame,xE as addNewNodes,vb as addToGroup,R1 as alignElements,El as avoidRectangularCorner,Tn as bindBindingElement,$l as bindElementsToFramesAfterDuplication,fl as bindOrUnbindBindingElement,$y as bindOrUnbindBindingElements,Mo as bindPointToSnapToElementOutline,xl as bindingProperties,dl as bumpVersion,wp as calculateFixedPointForElbowArrowBinding,Do as calculateFixedPointForNonElbowArrowBinding,tw as canApplyRoundnessTypeToElement,Ba as canBecomePolygon,od as canChangeRoundness,Yh as canCreateLinkFromElements,U0 as canHaveArrowheads,tr as canResizeFromSides,Rn as charWidth,pe as compareHeading,mi as computeBoundTextPosition,Cr as computeContainerDimensionForBoundText,vw as containsCJK,nM as convertToExcalidrawElements,DI as createPlaceholderEmbeddableLabel,Ls as createSrcDoc,Xx as cropElement,$t as deconstructDiamondElement,oo as deconstructLinearOrFreeDrawElement,Vt as deconstructRectanguloidElement,ws as deepCopyElement,rI as defaultGetElementLinkFromSelection,bw as detectLineHeight,Sn as distanceToElement,UP as distributeElements,Mn as doBoundsIntersect,eI as dragNewElement,QP as dragSelectedElements,Jf as duplicateElement,q1 as duplicateElements,Tb as editGroupForSelectedElement,de as elementCenterPoint,sn as elementOverlapsWithFrame,vi as elementWithCanvasCache,ln as elementsAreInFrameBounds,Wl as elementsAreInSameGroup,BI as embeddableURLValidator,Xl as excludeElementsInFramesFromSelection,c0 as filterElementsEligibleAsFrameChildren,qy as fixBindingsAfterDeletion,gl as fixDuplicatedBindingsAfterDuplication,Hr as flipHeading,E0 as frameAndChildrenSelectedTogether,Fa as generateLinearCollisionShape,Fe as generateRoughOptions,ho as getAllHoveredElementAtPoint,Ua as getApproxMinLineHeight,_a as getApproxMinLineWidth,wl as getArrowLocalFixedPoints,Ff as getArrowheadAngle,us as getArrowheadPoints,Rf as getArrowheadSize,Bt as getBindingGap,Ky as getBindingSideMidPoint,Qr as getBindingStrategyForDraggingBindingElementEndpoints,V as getBoundTextElement,vt as getBoundTextElementId,zw as getBoundTextElementPosition,pi as getBoundTextMaxHeight,nt as getBoundTextMaxWidth,hs as getBoundsFromPoints,ut as getCenterForBounds,y1 as getClosestElementBounds,Ft as getCommonBoundingBox,De as getCommonBounds,Nw as getContainerCenter,Gr as getContainerCoords,Se as getContainerElement,kt as getContainingFrame,St as getCornerRadius,Eo as getCubicBezierCurveBound,NS as getCursorForResizingElement,lf as getDefaultFrameName,nw as getDefaultRoundnessTypeForElement,kn as getDiamondPoints,JP as getDragOffsetXY,w1 as getDraggedElementsBounds,X as getElementAbsoluteCoords,ae as getElementBounds,ss as getElementLineSegments,es as getElementPointsCoords,ud as getElementShape,RS as getElementWithTransformHandleType,Zl as getElementsCompletelyInFrame,ve as getElementsInGroup,d0 as getElementsInNewFrame,l0 as getElementsInResizingFrame,n0 as getElementsIntersectingFrame,h0 as getElementsOverlappingFrame,os as getElementsWithinSelection,vI as getEmbedLink,Vx as getFlipAdjustedCropPosition,an as getFrameChildren,ef as getFrameLikeElements,f0 as getFrameLikeTitle,O0 as getFreedrawOutlineAsSegments,vf as getFreedrawOutlinePoints,tn as getGlobalFixedPointForBindableElement,yp as getGlobalFixedPoints,ll as getHeadingForElbowArrowSnap,Dt as getHoveredElementForBinding,QI as getInitializedImageElements,lo as getLineHeightInPx,Zt as getLineWidth,iw as getLinearElementSubType,jI as getLinkDirectionFromKey,sI as getLinkIdAndTypeFromSelection,Ll as getLockedLinearCursorAlignSize,qu as getMaxCharWidth,Lb as getMaximumGroups,Iw as getMinCharWidth,Ai as getMinMaxXYFromCurvePathOps,ao as getMinTextElementWidth,jl as getNewGroupIdsForDuplication,IM as getNonDeletedElements,Ul as getNonDeletedGroupIds,L1 as getNormalizedDimensions,jn as getObservedAppState,zs as getOmitSidesForEditorInterface,Ew as getOriginalContainerHeightFromCache,Es as getPerfectElementSize,Os as getPredecessors,x1 as getRectangleBoxAbsoluteCoords,gf as getRenderOpacity,wS as getResizeArrowDirection,xS as getResizeOffsetXY,jt as getResizedElementAbsoluteCoords,a0 as getRootElements,bM as getSceneVersion,pt as getSelectedElements,Go as getSelectedElementsByGroup,is as getSelectedGroupForElement,Zp as getSelectedGroupIdForElement,Vp as getSelectedGroupIds,Wb as getSelectionStateForElements,Ub as getTargetElements,rf as getTargetFrame,Hw as getTextElementAngle,Yw as getTextFromElements,Zu as getTextHeight,Wa as getTextWidth,FS as getTransformHandleTypeFromCoords,Pc as getTransformHandles,_s as getTransformHandlesFromCoords,Ma as getUncroppedImageElement,xr as getUncroppedWidthAndHeight,zb as getVisibleAndNonSelectedElements,PM as getVisibleElements,b1 as getVisibleSceneBounds,s0 as groupByFrameLikes,o0 as groupsAreAtLeastIntersectingTheFrame,r0 as groupsAreCompletelyOutOfFrame,In as handleBindTextResize,F0 as hasBackground,dt as hasBoundTextElement,vS as hasBoundingBox,N0 as hasStrokeColor,z0 as hasStrokeStyle,H0 as hasStrokeWidth,vd as hashElementsVersion,Dd as hashString,Oe as headingForPoint,hi as headingForPointFromElement,it as headingForPointIsHorizontal,Re as headingIsHorizontal,hy as headingIsVertical,Cm as hitElementBoundText,Bm as hitElementBoundingBox,dy as hitElementBoundingBoxOnly,Lm as hitElementItself,qt as intersectElementWithLineSegment,ew as isArrowBoundToElement,H as isArrowElement,Ce as isBindableElement,Fr as isBindableElementInsideOtherBindable,Be as isBindingElement,Ou as isBindingElementType,Pi as isBindingEnabled,ce as isBoundToContainer,i0 as isCursorInFrame,Cu as isCurvedArrow,Y as isElbowArrow,D1 as isElementCompletelyInViewport,as as isElementContainingFrame,Kl as isElementInFrame,$p as isElementInGroup,Vl as isElementInViewport,Wn as isElementIntersectingFrame,aI as isElementLink,Ta as isEmbeddableElement,Jx as isExcalidrawElement,yr as isFlowchartNodeElement,io as isFrameElement,K as isFrameLikeElement,Ie as isFreeDrawElement,Lu as isFreeDrawElementType,bE as isHTMLSVGElement,to as isIframeElement,no as isIframeLikeElement,xe as isImageElement,Yl as isInGroup,yn as isInitializedImageElement,yd as isInvisiblySmallElement,Pt as isLineElement,Q as isLinearElement,Gu as isLinearElementType,va as isMagicFrameElement,yw as isMeasureTextSupported,XI as isNodeInFlowchart,SM as isNonDeletedElement,bn as isPathALoop,Mt as isPointInElement,li as isRectangularElement,wr as isRectanguloidElement,Xp as isSelectedViaGroup,Bu as isSharpArrow,Qx as isSimpleArrow,_b as isSomeElementSelected,ku as isTextBindableContainer,ee as isTextElement,Da as isUsingAdaptiveRadius,La as isUsingProportionalRadius,ow as isValidPolygon,Ww as isValidTextContainer,yE as loadHTMLImageElement,ns as makeNextSelectedElementIds,xi as maxBindingDistance_simple,LI as maybeParseEmbedSrc,Fs as measureFontSizeFromWidth,_e as measureText,hM as moveAllLeft,EM as moveAllRight,mM as moveArrowAboveBindable,pM as moveOneLeft,fM as moveOneRight,ye as mutateElement,Zo as newArrowElement,Dn as newElement,ge as newElementWith,xI as newEmbeddableElement,ec as newFrameElement,bI as newFreeDrawElement,wI as newIframeElement,oc as newImageElement,ic as newLinearElement,tc as newMagicFrameElement,Ln as newTextElement,bd as normalizeElementOrder,Ii as normalizeFixedPoint,JI as normalizeSVG,ui as normalizeText,Oo as omitGroupsContainingFrameLikes,tf as omitPartialGroups,Rd as orderByFractionalIndex,ci as originalContainerCache,lI as parseElementLinkFromURL,im as parseTokens,Kt as pointInsideBounds,oS as positionElementsOnGrid,Ar as projectFixedPointOntoDiagonal,mo as redrawTextBoundingBox,yI as refreshTextDimensions,of as removeAllElementsFromFrame,ql as removeElementsFromFrame,Db as removeFromSelectedGroups,G0 as renderElement,C0 as renderSelectionElement,u0 as replaceAllElementsInFrame,gc as rescalePointsInElement,Ha as resetOriginalContainerCache,LE as resizeMultipleElements,TE as resizeSingleElement,SE as resizeSingleTextElement,GE as resizeTest,jp as selectGroup,zl as selectGroupsForSelectedElements,_l as selectGroupsFromGivenElements,Pw as setCustomTextMetricsProvider,_w as shouldAllowVerticalAlign,p0 as shouldApplyFrameClip,Vy as shouldEnableBindingForPointerEvent,fo as shouldTestInside,US as showSelectedShapeActions,Uw as suppportsHorizontalAlign,Ms as syncInvalidIndices,Td as syncInvalidIndicesImmutable,Gi as syncMovedIndices,Dl as toggleLinePolygonState,_0 as toolIsArrow,gS as transformElements,Ke as unbindBindingElement,Zy as updateBindings,je as updateBoundElements,Un as updateBoundPoint,Nn as updateElbowArrowPoints,m0 as updateFrameMembershipOfSelectedElements,KI as updateImageCache,Na as updateOriginalContainerCache,al as validateElbowPoints,lh as validateFractionalIndices,Lt as vectorToHeading,Tt as wrapText};
|