@excalidraw/element 0.18.0-2a82821 → 0.18.0-2b1c2a9
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 +5570 -3546
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +12 -12
- package/dist/types/common/src/colors.d.ts +19 -0
- package/dist/types/common/src/constants.d.ts +3 -0
- package/dist/types/common/src/keys.d.ts +2 -0
- package/dist/types/common/src/points.d.ts +1 -1
- package/dist/types/common/src/utils.d.ts +1 -43
- package/dist/types/element/src/Scene.d.ts +1 -1
- package/dist/types/element/src/align.d.ts +2 -2
- package/dist/types/element/src/arrowEndpointText.d.ts +49 -0
- package/dist/types/element/src/arrows/focus.d.ts +5 -2
- package/dist/types/element/src/binding.d.ts +17 -8
- package/dist/types/element/src/bounds.d.ts +5 -9
- package/dist/types/element/src/bucketFill.d.ts +110 -0
- package/dist/types/element/src/collision.d.ts +1 -1
- package/dist/types/element/src/comparisons.d.ts +4 -4
- package/dist/types/element/src/convertToShape.d.ts +23 -0
- package/dist/types/element/src/distribute.d.ts +2 -2
- package/dist/types/element/src/dragElements.d.ts +27 -0
- package/dist/types/element/src/duplicate.d.ts +3 -3
- package/dist/types/element/src/embeddable.d.ts +2 -2
- package/dist/types/element/src/flowchart.d.ts +7 -7
- package/dist/types/element/src/fractionalIndex.d.ts +2 -2
- package/dist/types/element/src/frame.d.ts +4 -4
- package/dist/types/element/src/groups.d.ts +9 -9
- package/dist/types/element/src/index.d.ts +4 -1
- package/dist/types/element/src/linearElementEditor.d.ts +27 -10
- package/dist/types/element/src/newElement.d.ts +14 -0
- package/dist/types/element/src/renderElement.d.ts +0 -3
- package/dist/types/element/src/resizeElements.d.ts +2 -2
- package/dist/types/element/src/selection.d.ts +5 -5
- package/dist/types/element/src/shape.d.ts +12 -0
- package/dist/types/element/src/sortElements.d.ts +10 -0
- package/dist/types/element/src/textElement.d.ts +13 -9
- package/dist/types/element/src/transform.d.ts +2 -2
- package/dist/types/element/src/typeChecks.d.ts +25 -25
- package/dist/types/element/src/types.d.ts +9 -1
- package/dist/types/element/src/utils.d.ts +7 -3
- package/dist/types/element/src/zindex.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +36 -12
- package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +24 -8
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +146 -931
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +24 -8
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +12 -4
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +38 -13
- package/dist/types/excalidraw/actions/actionDeselect.d.ts +9 -4
- package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +12 -4
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +25 -9
- package/dist/types/excalidraw/actions/actionExport.d.ts +26 -10
- package/dist/types/excalidraw/actions/actionFinalize.d.ts +1 -0
- package/dist/types/excalidraw/actions/actionFrame.d.ts +48 -197
- package/dist/types/excalidraw/actions/actionGroup.d.ts +39 -23
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +16 -6
- package/dist/types/excalidraw/actions/actionLink.d.ts +13 -5
- package/dist/types/excalidraw/actions/actionMenu.d.ts +12 -4
- package/dist/types/excalidraw/actions/actionProperties.d.ts +43 -24
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +17 -9
- package/dist/types/excalidraw/actions/actionStyles.d.ts +12 -4
- package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +13 -5
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +16 -9
- package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +13 -5
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +13 -5
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +16 -9
- package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +13 -5
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +14 -6
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +13 -5
- package/dist/types/excalidraw/actions/index.d.ts +1 -2
- package/dist/types/excalidraw/actions/manager.d.ts +1 -0
- package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
- package/dist/types/excalidraw/actions/types.d.ts +8 -4
- package/dist/types/excalidraw/appState.d.ts +9 -4
- package/dist/types/excalidraw/components/Actions.d.ts +17 -12
- package/dist/types/excalidraw/components/App.arrowText.d.ts +104 -0
- package/dist/types/excalidraw/components/App.bucketFill.d.ts +48 -0
- package/dist/types/excalidraw/components/App.cursor.d.ts +38 -0
- package/dist/types/excalidraw/components/App.d.ts +372 -67
- package/dist/types/excalidraw/components/App.drawshape.d.ts +55 -0
- package/dist/types/excalidraw/components/App.flowchart.d.ts +21 -0
- package/dist/types/excalidraw/components/App.viewport.d.ts +73 -0
- package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +9 -3
- package/dist/types/excalidraw/components/ColorPicker/CustomColorList.d.ts +3 -1
- package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +3 -1
- package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +9 -2
- package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +4 -2
- package/dist/types/excalidraw/components/ColorPicker/TopPicks.d.ts +8 -1
- package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +2 -1
- package/dist/types/excalidraw/components/ColorPicker/topPicksDnD.d.ts +31 -0
- package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +1 -1
- package/dist/types/excalidraw/components/CursorHint.d.ts +46 -0
- package/dist/types/excalidraw/components/{ToolButton.d.ts → IconButton.d.ts} +16 -19
- package/dist/types/excalidraw/components/Island.d.ts +7 -0
- package/dist/types/excalidraw/components/LaserPointerButton.d.ts +2 -4
- package/dist/types/excalidraw/components/LayerUI.d.ts +5 -2
- package/dist/types/excalidraw/components/LockButton.d.ts +3 -4
- package/dist/types/excalidraw/components/MagicButton.d.ts +0 -2
- package/dist/types/excalidraw/components/MobileMenu.d.ts +4 -4
- package/dist/types/excalidraw/components/MobileToolbar.d.ts +9 -0
- package/dist/types/excalidraw/components/PenModeButton.d.ts +2 -5
- package/dist/types/excalidraw/components/Popover.d.ts +1 -3
- package/dist/types/excalidraw/components/{ButtonIcon.d.ts → RadioButton.d.ts} +2 -5
- package/dist/types/excalidraw/components/Stats/Angle.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/Dimension.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/DragInput.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/MultiAngle.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/MultiDimension.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/MultiPosition.d.ts +2 -2
- package/dist/types/excalidraw/components/Stats/Position.d.ts +3 -3
- package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
- package/dist/types/excalidraw/components/ToolPopover.d.ts +3 -6
- package/dist/types/excalidraw/components/Toolbar.d.ts +11 -0
- package/dist/types/excalidraw/components/Tools.d.ts +146 -0
- package/dist/types/excalidraw/components/UserList.d.ts +3 -2
- package/dist/types/excalidraw/components/ViewportStatusFrame/ViewportStatusFrame.d.ts +11 -0
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +2 -0
- package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
- package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +2 -2
- package/dist/types/excalidraw/components/icons.d.ts +4 -1
- package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +1 -1
- package/dist/types/excalidraw/components/positionElementBesideCursor.d.ts +26 -0
- package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +39 -0
- package/dist/types/excalidraw/data/blob.d.ts +28 -12
- package/dist/types/excalidraw/data/index.d.ts +4 -4
- package/dist/types/excalidraw/data/json.d.ts +20 -12
- package/dist/types/excalidraw/drawShapeTrail.d.ts +16 -0
- package/dist/types/excalidraw/fonts/Fonts.d.ts +3 -2
- package/dist/types/excalidraw/hooks/useAppStateValue.d.ts +29 -0
- package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +5 -5
- package/dist/types/excalidraw/lasso/utils.d.ts +2 -0
- package/dist/types/excalidraw/renderer/animation.d.ts +1 -0
- package/dist/types/excalidraw/renderer/helpers.d.ts +7 -0
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -3
- package/dist/types/excalidraw/scene/Renderer.d.ts +12 -11
- package/dist/types/excalidraw/scene/export.d.ts +3 -3
- package/dist/types/excalidraw/scene/index.d.ts +1 -1
- package/dist/types/excalidraw/scene/types.d.ts +4 -3
- package/dist/types/excalidraw/snapping.d.ts +7 -7
- package/dist/types/excalidraw/types.d.ts +410 -20
- package/dist/types/excalidraw/viewport.d.ts +275 -0
- package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +2 -3
- package/dist/types/laser-pointer/src/state.d.ts +1 -0
- package/dist/types/math/src/curve.d.ts +19 -12
- package/dist/types/math/src/index.d.ts +1 -0
- package/dist/types/math/src/pca.d.ts +79 -0
- package/dist/types/math/src/polygon.d.ts +25 -1
- package/dist/types/math/src/segment.d.ts +6 -0
- package/dist/types/utils/src/export.d.ts +3 -3
- package/package.json +4 -4
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +0 -172
- package/dist/types/excalidraw/components/FollowMode/FollowMode.d.ts +0 -10
- package/dist/types/excalidraw/components/HandButton.d.ts +0 -10
- package/dist/types/excalidraw/components/MobileToolBar.d.ts +0 -10
- package/dist/types/excalidraw/components/shapes.d.ts +0 -270
- package/dist/types/excalidraw/cursor.d.ts +0 -5
- package/dist/types/excalidraw/scene/scroll.d.ts +0 -18
- package/dist/types/excalidraw/scene/zoom.d.ts +0 -12
package/dist/prod/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
var ou=Object.create;var ua=Object.defineProperty;var ru=Object.getOwnPropertyDescriptor;var su=Object.getOwnPropertyNames;var au=Object.getPrototypeOf,lu=Object.prototype.hasOwnProperty;var du=(e,t)=>()=>(e&&(t=e(e=0)),t);var cu=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var uu=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of su(t))!lu.call(e,o)&&o!==n&&ua(e,o,{get:()=>t[o],enumerable:!(i=ru(t,o))||i.enumerable});return e};var mu=(e,t,n)=>(n=e!=null?ou(au(e)):{},uu(t||!e||!e.__esModule?ua(n,"default",{value:e,enumerable:!0}):n,e));var B,P=du(()=>{B={PROD:!0}});var ac=cu((tI,sc)=>{P();var rc="Expected a function",ic=NaN,zh="[object Symbol]",Hh=/^\s+|\s+$/g,_h=/^[-+]0x[0-9a-f]+$/i,Uh=/^0b[01]+$/i,Wh=/^0o[0-7]+$/i,Yh=parseInt,jh=typeof global=="object"&&global&&global.Object===Object&&global,Xh=typeof self=="object"&&self&&self.Object===Object&&self,$h=jh||Xh||Function("return this")(),Vh=Object.prototype,Zh=Vh.toString,qh=Math.max,Kh=Math.min,Ws=function(){return $h.Date.now()};function Qh(e,t,n){var i,o,r,s,a,l,d=0,c=!1,u=!1,m=!0;if(typeof e!="function")throw new TypeError(rc);t=oc(t)||0,Qo(n)&&(c=!!n.leading,u="maxWait"in n,r=u?qh(oc(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(S){var I=i,A=o;return i=o=void 0,d=S,s=e.apply(A,I),s}function h(S){return d=S,a=setTimeout(E,t),c?p(S):s}function f(S){var I=S-l,A=S-d,M=t-I;return u?Kh(M,r-A):M}function g(S){var I=S-l,A=S-d;return l===void 0||I>=t||I<0||u&&A>=r}function E(){var S=Ws();if(g(S))return x(S);a=setTimeout(E,f(S))}function x(S){return a=void 0,m&&i?p(S):(i=o=void 0,s)}function b(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function y(){return a===void 0?s:x(Ws())}function w(){var S=Ws(),I=g(S);if(i=arguments,o=this,l=S,I){if(a===void 0)return h(l);if(u)return a=setTimeout(E,t),p(l)}return a===void 0&&(a=setTimeout(E,t)),s}return w.cancel=b,w.flush=y,w}function Jh(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(rc);return Qo(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),Qh(e,t,{leading:i,maxWait:t,trailing:o})}function Qo(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function eg(e){return!!e&&typeof e=="object"}function tg(e){return typeof e=="symbol"||eg(e)&&Zh.call(e)==zh}function oc(e){if(typeof e=="number")return e;if(tg(e))return ic;if(Qo(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Qo(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Hh,"");var n=Uh.test(e);return n||Wh.test(e)?Yh(e.slice(2),n?2:8):_h.test(e)?ic:+e}sc.exports=Jh});P();import{toIterable as LE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as qt,viewportCoordsToSceneCoords as qo}from"@excalidraw/common";import{normalizeRadians as $d,radiansBetweenAngles as xh,radiansDifference as bh}from"@excalidraw/math";import{pointsEqual as wh}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function mr(e,t,n){if(e&&e.length){let[i,o]=t,r=Math.PI/180*n,s=Math.cos(r),a=Math.sin(r);for(let l of e){let[d,c]=l;l[0]=(d-i)*s-(c-o)*a+i,l[1]=(d-i)*a+(c-o)*s+o}}}function fu(e,t,n){let i=[];e.forEach(o=>i.push(...o)),mr(i,t,n)}function hu(e,t){return e[0]===t[0]&&e[1]===t[1]}function ma(e,t,n,i=1){let o=n,r=Math.max(t,.1),s=e[0]&&e[0][0]&&typeof e[0][0]=="number"?[e]:e,a=[0,0];if(o)for(let d of s)mr(d,a,o);let l=gu(s,r,i);if(o){for(let d of s)mr(d,a,-o);fu(l,a,-o)}return l}function gu(e,t,n){let i=[];for(let d of e){let c=[...d];hu(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 bt(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),ma(e,o,i,r||1)}var tn=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=bt(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 nn(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 Ki=class extends tn{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=bt(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)nn([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 Qi=class extends tn{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 Ji=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=bt(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=nn(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 h=0;h<c;h++){let f=p+u+h*o,g=m-s+Math.random()*2*s,E=f-s+Math.random()*2*s,x=this.helper.ellipse(g,E,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var eo=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=bt(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=nn(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 h=p*(i+o),f=h+i,g=[c[0]+h*Math.cos(m)+d*Math.cos(m),c[1]+h*Math.sin(m)+d*Math.sin(m)],E=[c[0]+f*Math.cos(m)+d*Math.cos(m),c[1]+f*Math.sin(m)+d*Math.sin(m)];r.push(...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],n))}}),r}};P();var to=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=bt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=nn(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,h=Math.sqrt(2*Math.pow(n,2)),f=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],g=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],E=[f[0]+h*Math.cos(c+Math.PI/4),f[1]+h*Math.sin(c+Math.PI/4)];o.push(...this.helper.doubleLineOps(f[0],f[1],E[0],E[1],i),...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],i))}}),o}};var _e={};function pa(e,t){let n=e.fillStyle||"hachure";if(!_e[n])switch(n){case"zigzag":_e[n]||(_e[n]=new Ki(t));break;case"cross-hatch":_e[n]||(_e[n]=new Qi(t));break;case"dots":_e[n]||(_e[n]=new Ji(t));break;case"dashed":_e[n]||(_e[n]=new eo(t));break;case"zigzag-line":_e[n]||(_e[n]=new to(t));break;case"hachure":default:n="hachure",_e[n]||(_e[n]=new tn(t));break}return _e[n]}P();function fa(){return Math.floor(Math.random()*2**31)}var no=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 io={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 Eu(e){let t=new Array;for(;e!=="";)if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([aAcChHlLmMqQsStTvVzZ])/))t[t.length]={type:0,text:RegExp.$1},e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))t[t.length]={type:1,text:`${parseFloat(RegExp.$1)}`},e=e.substr(RegExp.$1.length);else return[];return t[t.length]={type:2,text:""},t}function pr(e,t){return e.type===t}function Jn(e){let t=[],n=Eu(e),i="BOD",o=0,r=n[o];for(;!pr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=io[r.text],i=r.text;else return Jn("M0,0"+e);else pr(r,1)?s=io[i]:(o++,s=io[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(pr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof io[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 Ei(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 bi(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,h=0;n==="Q"||n==="T"?(p=i+(i-a),h=o+(o-l)):(p=i,h=o);let f=i+2*(p-i)/3,g=o+2*(h-o)/3,E=u+2*(p-u)/3,x=m+2*(h-m)/3;t.push({key:"C",data:[f,g,E,x,u,m]}),a=p,l=h,i=u,o=m;break}case"Q":{let[u,m,p,h]=c,f=i+2*(u-i)/3,g=o+2*(m-o)/3,E=p+2*(u-p)/3,x=h+2*(m-h)/3;t.push({key:"C",data:[f,g,E,x,p,h]}),a=u,l=m,i=p,o=h;break}case"A":{let u=Math.abs(c[0]),m=Math.abs(c[1]),p=c[2],h=c[3],f=c[4],g=c[5],E=c[6];u===0||m===0?(t.push({key:"C",data:[i,o,g,E,g,E]}),i=g,o=E):(i!==g||o!==E)&&(ha(i,o,g,E,u,m,p,h,f).forEach(function(b){t.push({key:"C",data:b})}),i=g,o=E);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function xu(e){return Math.PI*e/180}function xi(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 ha(e,t,n,i,o,r,s,a,l,d){let c=xu(s),u=[],m=0,p=0,h=0,f=0;if(d)[m,p,h,f]=d;else{[e,t]=xi(e,t,-c),[n,i]=xi(n,i,-c);let O=(e-n)/2,v=(t-i)/2,Y=O*O/(o*o)+v*v/(r*r);Y>1&&(Y=Math.sqrt(Y),o=Y*o,r=Y*r);let H=a===l?-1:1,Z=o*o,F=r*r,T=Z*F-Z*v*v-F*O*O,R=Z*v*v+F*O*O,U=H*Math.sqrt(Math.abs(T/R));h=U*o*v/r+(e+n)/2,f=U*-r*O/o+(t+i)/2,m=Math.asin(parseFloat(((t-f)/r).toFixed(9))),p=Math.asin(parseFloat(((i-f)/r).toFixed(9))),e<h&&(m=Math.PI-m),n<h&&(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 g=p-m;if(Math.abs(g)>Math.PI*120/180){let O=p,v=n,Y=i;l&&p>m?p=m+Math.PI*120/180*1:p=m+Math.PI*120/180*-1,n=h+o*Math.cos(p),i=f+r*Math.sin(p),u=ha(n,i,v,Y,o,r,s,0,l,[p,O,h,f])}g=p-m;let E=Math.cos(m),x=Math.sin(m),b=Math.cos(p),y=Math.sin(p),w=Math.tan(g/4),S=4/3*o*w,I=4/3*r*w,A=[e,t],M=[e+S*x,t-I*E],L=[n+S*y,i-I*b],C=[n,i];if(M[0]=2*A[0]-M[0],M[1]=2*A[1]-M[1],d)return[M,L,C].concat(u);{u=[M,L,C].concat(u);let O=[];for(let v=0;v<u.length;v+=3){let Y=xi(u[v][0],u[v][1],c),H=xi(u[v+1][0],u[v+1][1],c),Z=xi(u[v+2][0],u[v+2][1],c);O.push([Y[0],Y[1],H[0],H[1],Z[0],Z[1]])}return O}}var bu={randOffset:Pu,randOffsetWithRange:Iu,ellipse:yu,doubleLineOps:Su};function fr(e,t,n,i,o){return{type:"path",ops:Lt(e,t,n,i,o)}}function wi(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Lt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Lt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return fr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function wu(e,t){return wi(e,!0,t)}function wa(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return wu(r,o)}function hr(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),Mu(t));n=n.concat(i)}return{type:"path",ops:n}}function yu(e,t,n,i,o){let r=gr(n,i,o);return so(e,t,o,r).opset}function gr(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+=N(s*l,n),a+=N(a*l,n),{increment:r,rx:s,ry:a}}function so(e,t,n,i){let[o,r]=xa(i.increment,e,t,i.rx,i.ry,1,i.increment*oo(.1,oo(.4,1,n),n),n),s=ro(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=xa(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=ro(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Er(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+=N(u*.01,l),m+=N(m*.01,l);let p=o,h=r;for(;p<0;)p+=Math.PI*2,h+=Math.PI*2;h-p>Math.PI*2&&(p=0,h=Math.PI*2);let f=Math.PI*2/l.curveStepCount,g=Math.min(f/2,(h-p)/2),E=ba(g,d,c,u,m,p,h,1,l);if(!l.disableMultiStroke){let x=ba(g,d,c,u,m,p,h,1.5,l);E.push(...x)}return s&&(a?E.push(...Lt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...Lt(d,c,d+u*Math.cos(h),c+m*Math.sin(h),l)):E.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(p),c+m*Math.sin(p)]})),{type:"path",ops:E}}function xr(e,t){let n=bi(Ei(Jn(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(...Lt(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(...Au(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...Lt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function ao(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]+N(o,t),i[0][1]+N(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+N(o,t),i[s][1]+N(o,t)]})}}return{type:"fillPath",ops:n}}function Cn(e,t){return pa(t,bu).fillPolygons(e,t)}function ya(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=N(d*.01,s),c+=N(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,h=[];for(let f=u;f<=m;f=f+p)h.push([a+d*Math.cos(f),l+c*Math.sin(f)]);return h.push([a+d*Math.cos(m),l+c*Math.sin(m)]),h.push([a,l]),Cn([h],s)}function Pu(e,t){return N(e,t)}function Iu(e,t,n){return oo(e,t,n)}function Su(e,t,n,i,o){return Lt(e,t,n,i,o,!0)}function Mu(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Pa(e){return e.randomizer||(e.randomizer=new no(e.seed||0)),e.randomizer.next()}function oo(e,t,n,i=1){return n.roughness*i*(Pa(n)*(t-e)+e)}function N(e,t,n=1){return oo(-e,e,t,n)}function Lt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=ga(e,t,n,i,o,!0,!1);if(s)return a;let l=ga(e,t,n,i,o,!0,!0);return a.concat(l)}function ga(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+Pa(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,h=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=N(p,o,d),h=N(h,o,d);let f=[],g=()=>N(u,o,d),E=()=>N(c,o,d),x=o.preserveVertices;return r&&(s?f.push({op:"move",data:[e+(x?0:g()),t+(x?0:g())]}):f.push({op:"move",data:[e+(x?0:N(c,o,d)),t+(x?0:N(c,o,d))]})),s?f.push({op:"bcurveTo",data:[p+e+(n-e)*m+g(),h+t+(i-t)*m+g(),p+e+2*(n-e)*m+g(),h+t+2*(i-t)*m+g(),n+(x?0:g()),i+(x?0:g())]}):f.push({op:"bcurveTo",data:[p+e+(n-e)*m+E(),h+t+(i-t)*m+E(),p+e+2*(n-e)*m+E(),h+t+2*(i-t)*m+E(),n+(x?0:E()),i+(x?0:E())]}),f}function Ea(e,t,n){let i=[];i.push([e[0][0]+N(t,n),e[0][1]+N(t,n)]),i.push([e[0][0]+N(t,n),e[0][1]+N(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+N(t,n),e[o][1]+N(t,n)]),o===e.length-1&&i.push([e[o][0]+N(t,n),e[o][1]+N(t,n)]);return ro(i,null,n)}function ro(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]+N(a,n),t[1]+N(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(...Lt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function xa(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=N(.5,a)-Math.PI/2;c.push([N(r,a)+t+.9*i*Math.cos(u-e),N(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 h=[N(r,a)+t+i*Math.cos(p),N(r,a)+n+o*Math.sin(p)];d.push(h),c.push(h)}c.push([N(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),N(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([N(r,a)+t+.98*i*Math.cos(u+s),N(r,a)+n+.98*o*Math.sin(u+s)]),c.push([N(r,a)+t+.9*i*Math.cos(u+s*.5),N(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function ba(e,t,n,i,o,r,s,a,l){let d=r+N(.1,l),c=[];c.push([N(a,l)+t+.9*i*Math.cos(d-e),N(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([N(a,l)+t+i*Math.cos(u),N(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)]),ro(c,null,l)}function Au(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:N(d[0],a)),s[1]+(m?0:N(d[0],a))]}),c=m?[o,r]:[o+N(d[p],a),r+N(d[p],a)],l.push({op:"bcurveTo",data:[e+N(d[p],a),t+N(d[p],a),n+N(d[p],a),i+N(d[p],a),c[0],c[1]]});return l}P();function yi(e){return[...e]}function Ia(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(yi(e[0]),yi(e[1]),yi(e[2]),yi(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(yi(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 Tu(e,t){return Math.sqrt(lo(e,t))}function lo(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function vu(e,t,n){let i=lo(t,n);if(i===0)return lo(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)),lo(e,Gn(t,n,o))}function Gn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Du(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 br(e,t,n,i){let o=i||[];if(Du(e,t)<n){let r=e[t+0];o.length?Tu(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=Gn(s,a,.5),u=Gn(a,l,.5),m=Gn(l,d,.5),p=Gn(c,u,.5),h=Gn(u,m,.5),f=Gn(p,h,.5);br([s,c,p,f],0,n,o),br([f,h,m,d],0,n,o)}return o}function Pi(e,t){return co(e,0,e.length,t)}function co(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=vu(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(co(e,t,d+1,i,r),co(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function Ct(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;br(e,s,t,i)}return n&&n>0?co(i,0,i.length,n):i}P();function Sa(e,t,n){let i=Jn(e),o=bi(Ei(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Ct(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 h=s.length?s[s.length-1]:a;l.push([h[0],h[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=Pi(m,n);p.length&&u.push(p)}return u}var qe="none",it=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 fa()}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,i){return{shape:t,sets:n||[],options:i||this.defaultOptions}}line(t,n,i,o,r){let s=this._o(r);return this._d("line",[fr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=wa(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(ao([d],s)):a.push(Cn([d],s))}return s.stroke!==qe&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=gr(i,o,s),d=so(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=so(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(Cn([d.estimatedPoints],s));return s.stroke!==qe&&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",[wi(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=Er(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=Er(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(ya(t,n,i,o,r,s,d));return d.stroke!==qe&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=hr(t,i);if(i.fill&&i.fill!==qe&&t.length>=3)if(i.fillStyle==="solid"){let s=hr(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(s.ops)})}else{let s=Ia(t),a=Ct(s,10,(1+i.roughness)/2);o.push(Cn([a],i))}return i.stroke!==qe&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=wi(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(ao([t],i)):o.push(Cn([t],i))),i.stroke!==qe&&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!==qe,s=i.stroke!==qe,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=Sa(t,1,l),c=xr(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=xr(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else o.push(ao(d,i));else o.push(Cn(d,i));return s&&(a?d.forEach(u=>{o.push(wi(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:qe};break;case"fillPath":s={d:this.opsToPath(r),stroke:qe,strokeWidth:0,fill:i.fill||qe};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||qe,strokeWidth:i,fill:qe}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var uo=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new it(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 mo=class{constructor(t,n){this.svg=t,this.gen=new it(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 ei={canvas(e,t){return new uo(e,t)},svg(e,t){return new mo(e,t)},generator(e){return new it(e)},newSeed(){return it.newSeed()}};import{arrayToMap as Os,invariant as Cs,rescalePoints as _d,sizeOf as sh}from"@excalidraw/common";import{degreesToRadians as Ls,lineSegment as pe,pointDistance as ah,pointFrom as D,pointFromArray as Xd,pointRotateRads as ee}from"@excalidraw/math";P();import{invariant as Bu}from"@excalidraw/common";import{curve as Lu,lineSegment as Cu,pointFrom as ce,pointDistance as hb,pointFromArray as Gu,pointFromVector as Ou,pointRotateRads as lt,polygon as Ma,polygonFromPoints as wr,PRECISION as gb,segmentsIntersectAt as Eb,vector as ku,vectorAdd as Fu,vectorFromPoint as Ru,vectorScale as xb}from"@excalidraw/math";import{getElementAbsoluteCoords as wb}from"@excalidraw/element";var Aa=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=ce(s,a),d;return e.type==="diamond"?d=Ma(lt(ce(s,r),l,t),lt(ce(o+n,a),l,t),lt(ce(s,r+i),l,t),lt(ce(o,a),l,t)):d=Ma(lt(ce(o,r),l,t),lt(ce(o+n,r),l,t),lt(ce(o+n,r+i),l,t),lt(ce(o,r+i),l,t)),{type:"polygon",data:d}};var Ta=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:ce(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},Gt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},va=(e,t=ce(0,0),n,i)=>{let o=l=>lt(ce(l[0]+t[0],l[1]+t[1]),i,n),r=Gt(e),s=[],a=ce(0,0);for(let l of r){if(l.op==="move"){let d=Gu(l.data);Bu(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(ce(l.data[0],l.data[1])),c=o(ce(l.data[2],l.data[3])),u=o(ce(l.data[4],l.data[5]));s.push(Lu(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Nu=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},Da=(e,t,n=!1)=>{let i=r=>lt(Ou(Fu(Ru(r),ku(e.x,e.y))),t,e.angle),o=Nu(e.points.map(r=>i(r)));return n?{type:"polygon",data:wr(o.flat())}:{type:"polyline",data:o}},Ba=(e,t,n=ce(0,0),i,o)=>{let r=c=>lt(ce(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:wr(e.points.map(c=>r(c)))};let s=Gt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(ce(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(ce(c.data[0],c.data[1])),a.push(ce(c.data[2],c.data[3])),a.push(ce(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(ce(c.data[0],c.data[1]));let d=Ct(a,10,5).map(c=>r(c));return{type:"polygon",data:wr(d)}};P();P();function La(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function zu(e){return[-e[0],-e[1]]}function ct(e,t){return[e[0]+t[0],e[1]+t[1]]}function ot(e,t){return[e[0]-t[0],e[1]-t[1]]}function dt(e,t){return[e[0]*t,e[1]*t]}function Hu(e,t){return[e[0]/t,e[1]/t]}function Si(e){return[e[1],-e[0]]}function Ca(e,t){return e[0]*t[0]+e[1]*t[1]}function _u(e,t){return e[0]===t[0]&&e[1]===t[1]}function Uu(e){return Math.hypot(e[0],e[1])}function Wu(e){return e[0]*e[0]+e[1]*e[1]}function Ga(e,t){return Wu(ot(e,t))}function Fa(e){return Hu(e,Uu(e))}function Yu(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function Mi(e,t,n){let i=Math.sin(n),o=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*o-s*i,l=r*i+s*o;return[a+t[0],l+t[1]]}function yr(e,t,n){return ct(e,dt(ot(t,e),n))}function Oa(e,t,n){return ct(e,dt(t,n))}var{min:ti,PI:ju}=Math,ka=.275,Ai=ju+1e-4;function Xu(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 h=e[e.length-1].runningLength,f=a.taper===!1?0:a.taper===!0?Math.max(n,h):a.taper,g=l.taper===!1?0:l.taper===!0?Math.max(n,h):l.taper,E=Math.pow(n*i,2),x=[],b=[],y=e.slice(0,10).reduce((F,T)=>{let R=T.pressure;if(r){let U=ti(1,T.distance/n),ye=ti(1,1-U);R=ti(1,F+(ye-F)*(U*ka))}return(F+R)/2},e[0].pressure),w=La(n,o,e[e.length-1].pressure,s),S,I=e[0].vector,A=e[0].point,M=A,L=A,C=M,O=!1;for(let F=0;F<e.length;F++){let{pressure:T}=e[F],{point:R,vector:U,distance:ye,runningLength:nt}=e[F];if(F<e.length-1&&h-nt<3)continue;if(o){if(r){let de=ti(1,ye/n),oe=ti(1,1-de);T=ti(1,y+(oe-y)*(de*ka))}w=La(n,o,T,s)}else w=n/2;S===void 0&&(S=w);let qn=nt<f?u(nt/f):1,Kn=h-nt<g?p((h-nt)/g):1;w=Math.max(.01,w*Math.min(qn,Kn));let Bn=(F<e.length-1?e[F+1]:e[F]).vector,Dt=F<e.length-1?Ca(U,Bn):1,Ln=Ca(U,I)<0&&!O,Jt=Dt!==null&&Dt<0;if(Ln||Jt){let de=dt(Si(I),w);for(let oe=1/13,en=0;en<=1;en+=oe)L=Mi(ot(R,de),R,Ai*en),x.push(L),C=Mi(ct(R,de),R,Ai*-en),b.push(C);A=L,M=C,Jt&&(O=!0);continue}if(O=!1,F===e.length-1){let de=dt(Si(U),w);x.push(ot(R,de)),b.push(ct(R,de));continue}let Qn=dt(Si(yr(Bn,U,Dt)),w);L=ot(R,Qn),(F<=1||Ga(A,L)>E)&&(x.push(L),A=L),C=ct(R,Qn),(F<=1||Ga(M,C)>E)&&(b.push(C),M=C),y=T,I=U}let v=e[0].point.slice(0,2),Y=e.length>1?e[e.length-1].point.slice(0,2):ct(e[0].point,[1,1]),H=[],Z=[];if(e.length===1){if(!(f||g)||d){let F=Oa(v,Fa(Si(ot(v,Y))),-(S||w)),T=[];for(let R=1/13,U=R;U<=1;U+=R)T.push(Mi(F,v,Ai*2*U));return T}}else{if(!(f||g&&e.length===1))if(c)for(let T=1/13,R=T;R<=1;R+=T){let U=Mi(b[0],v,Ai*R);H.push(U)}else{let T=ot(x[0],b[0]),R=dt(T,.5),U=dt(T,.51);H.push(ot(v,R),ot(v,U),ct(v,U),ct(v,R))}let F=Si(zu(e[e.length-1].vector));if(g||f&&e.length===1)Z.push(Y);else if(m){let T=Oa(Y,F,w);for(let R=1/29,U=R;U<1;U+=R)Z.push(Mi(T,Y,Ai*3*U))}else Z.push(ct(Y,dt(F,w)),ct(Y,dt(F,w*.99)),ot(Y,dt(F,w*.99)),ot(Y,dt(F,w)))}return x.concat(Z,b.reverse(),H)}function $u(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:h,pressure:f=.5})=>[p,h,f]);if(a.length===2){let p=a[1];a=a.slice(0,-1);for(let h=1;h<5;h++)a.push(yr(a[0],p,h/4))}a.length===1&&(a=[...a,[...ct(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 h=r&&p===m?a[p].slice(0,2):yr(u.point,a[p],s);if(_u(u.point,h))continue;let f=Yu(h,u.point);if(c+=f,p<m&&!d){if(c<o)continue;d=!0}u={point:h,pressure:a[p][2]>=0?a[p][2]:.5,vector:Fa(ot(u.point,h)),distance:f,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function Ra(e,t={}){return Xu($u(e,t),t)}P();P();P();function ue([e,t,n],[i,o,r]){return[e+i,t+o,n+r]}function ni([e,t,n],[i,o,r]){return[e-i,t-o,n-r]}function be([e,t,n],i){return[e*i,t*i,n*i]}function kn([e,t,n]){return[e/Math.sqrt(e**2+t**2),t/Math.sqrt(e**2+t**2),n]}function Se([e,t,n],i){return[Math.cos(i)*e-Math.sin(i)*t,Math.sin(i)*e+Math.cos(i)*t,n]}function Na(e,t,n){return ue(e,be(ni(t,e),n))}function Pr(e,t,n){return Math.atan2(n[1]-e[1],n[0]-e[0])-Math.atan2(t[1]-e[1],t[0]-e[0])}function Ir(e){return Math.atan2(Math.sin(e),Math.cos(e))}function Sr([e,t]){return Math.sqrt(e**2+t**2)}function On([e,t],[n,i]){return Math.sqrt((n-e)**2+(i-t)**2)}function za(e){if(e.length<2)return 0;let t=0;for(let n=1;n<=e.length-1;n++)t+=On(e[n-1],e[n]);return t+=On(e[e.length-2],e[e.length-1]),t}var Vu=(e,t,n)=>Math.max(t,Math.min(n,e));function Ha(e,t,n){let i=On(t,n);if(i===0)return On(e,t);let o=Vu(((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i**2,0,1),r=[t[0]+o*(n[0]-t[0]),t[1]+o*(n[1]-t[1]),e[2]];return On(r,e)}P();function Ti(e,t){if(t===0||e.length<=2)return e;let n=e[0],i=e[e.length-1],[o,r]=e.reduce(([s,a],l,d)=>{let c=Ha(l,n,i);return c>s?[c,d]:[s,a]},[0,-1]);if(o>=t){let s=e[r];return[...Ti([n,...e.slice(1,r),s],t).slice(0,-1),s,...Ti([s,...e.slice(r,-1),i],t).slice(1)]}return[n,i]}var po=class e{static defaults={size:2,streamline:.45,simplify:.1,simplifyPhase:"output",keepHead:!1,sizeMapping:()=>1};static constants={cornerDetectionMaxAngle:75,cornerDetectionVariance:t=>t>35?.5:1,maxTailLength:50};options;constructor(t){this.options=Object.assign({},e.defaults,t)}originalPoints=[];stablePoints=[];tailPoints=[];isFresh=!0;get lastPoint(){return this.tailPoints[this.tailPoints.length-1]??this.stablePoints[this.stablePoints.length-1]}addPoint(t){let n=this.originalPoints[this.originalPoints.length-1];if(!(n&&n[0]===t[0]&&n[1]===t[1])){if(this.originalPoints.push(t),this.isFresh){this.isFresh=!1,this.stablePoints.push(t);return}this.options.streamline>0&&(t=Na(this.lastPoint,t,1-this.options.streamline)),this.tailPoints.push(t),za(this.tailPoints)>e.constants.maxTailLength&&this.stabilizeTail()}}close(){this.stabilizeTail()}stabilizeTail(){if(this.options.simplify>0&&this.options.simplifyPhase==="tail")throw new Error("Not implemented yet");this.stablePoints.push(...this.tailPoints),this.tailPoints=[]}getSize(t,n,i,o,r){return(t??this.options.size)*this.options.sizeMapping({pressure:n,runningLength:r,currentIndex:i,totalLength:o})}getStrokeOutline(t){if(this.isFresh)return[];let n=[...this.stablePoints,...this.tailPoints];this.options.simplify>0&&this.options.simplifyPhase==="input"&&(n=Ti(n,this.options.simplify));let i=n.length;if(i===0)return[];if(i===1){let I=n[0],A=this.getSize(t,I[2],0,i,0);if(A<.5)return[];let M=[];for(let L=0;L<=Math.PI*2;L+=Math.PI/16)M.push(ue(I,be(Se([1,0,0],L),A)));return M.push(ue(I,be([1,0,0],this.getSize(t,I[2],0,i,0)))),M}if(i===2){let I=n[0],A=n[1],M=this.getSize(t,I[2],0,i,0),L=this.getSize(t,A[2],0,i,0);if(M<.5||L<.5)return[];let C=[],O=Pr(I,[I[0],I[1]-100,I[2]],A);for(let v=O;v<=Math.PI+O;v+=Math.PI/16)C.push(ue(I,be(Se([1,0,0],v),M)));for(let v=Math.PI+O;v<=Math.PI*2+O;v+=Math.PI/16)C.push(ue(A,be(Se([1,0,0],v),L)));return C.push(C[0]),C}let o=[],r=[],s=0,a=0,l=0,d=0;for(let I=1;I<i-1;I++){let A=n[I-1],M=n[I],L=n[I+1],C=M[2],O=On(A,M);d+=O,s=a+(O-a)*.2;let v=this.getSize(t,C,I,i,d);if(v===0){l=I+1;continue}let Y=kn(ni(A,M)),H=kn(ni(L,M)),Z=Se(Y,Math.PI/2),F=Se(Y,-Math.PI/2),T=Se(H,Math.PI/2),R=Se(H,-Math.PI/2),U=ue(M,be(Z,v)),ye=ue(M,be(F,v)),nt=ue(M,be(T,v)),qn=ue(M,be(R,v)),Kn=ue(Z,R),Bn=ue(F,T),Dt=ue(M,be(Sr(Kn)===0?Y:kn(Kn),v)),Ln=ue(M,be(Sr(Bn)===0?H:kn(Bn),v)),Jt=Ir(Pr(M,A,L)),Qn=e.constants.cornerDetectionMaxAngle/180*Math.PI*e.constants.cornerDetectionVariance(s);if(Math.abs(Jt)<Qn){let de=Math.abs(Ir(Math.PI-Jt));if(de===0)continue;if(Jt<0){r.push(ye,Ln);for(let oe=0;oe<=de;oe+=de/4)o.push(ue(M,Se(be(Z,v),oe)));for(let oe=de;oe>=0;oe-=de/4)r.push(ue(M,Se(be(Z,v),oe)));r.push(Ln,nt)}else{o.push(U,Dt);for(let oe=0;oe<=de;oe+=de/4)r.push(ue(M,Se(be(Z,-v),-oe)));for(let oe=de;oe>=0;oe-=de/4)o.push(ue(M,Se(be(Z,-v),-oe)));o.push(Dt,qn)}}else o.push(Dt),r.push(Ln);a=s}if(l>=i-2){if(this.options.keepHead){let I=n[i-1],A=[];for(let M=0;M<=Math.PI*2;M+=Math.PI/16)A.push(ue(I,be(Se([1,0,0],M),this.options.size)));return A.push(ue(I,be([1,0,0],this.options.size))),A}return[]}let c=n[l],u=n[l+1],m=n[i-2],p=n[i-1],h=kn(ni(u,c)),f=kn(ni(m,p)),g=Se(h,-Math.PI/2),E=Se(f,Math.PI/2),x=this.getSize(t,c[2],0,i,0),b=[],y=this.options.keepHead?this.options.size:this.getSize(t,m[2],i-2,i,d),w=[];if(x>.1){for(let I=0;I<=Math.PI;I+=Math.PI/16)b.unshift(ue(c,Se(be(g,x),-I)));b.unshift(ue(c,be(g,-x)))}else b.push(c);for(let I=0;I<=Math.PI*3;I+=Math.PI/16)w.push(ue(p,Se(be(E,-y),-I)));let S=[...b,...o,...w.reverse(),...r.reverse()];return b.length>0&&S.push(b[0]),this.options.simplify>0&&this.options.simplifyPhase==="output"?Ti(S,this.options.simplify):S}};import{pointFrom as me,pointDistance as Gd,pointRotateRads as Vt}from"@excalidraw/math";import{ROUGHNESS as Yf,THEME as Bs,isTransparent as Vi,assertNever as jf,COLOR_PALETTE as Xf,LINE_POLYGON_POINT_MERGE_DISTANCE as $f,applyDarkModeFilter as Zi,DEFAULT_STROKE_STREAMLINE as Vf}from"@excalidraw/common";P();import{isRightAngleRads as Lf,lineSegment as vd,pointFrom as Xo,pointRotateRads as Ss}from"@excalidraw/math";import{BOUND_TEXT_PADDING as Pn,DEFAULT_REDUCED_GLOBAL_ALPHA as Cf,ELEMENT_READY_TO_ERASE_OPACITY as Gf,FRAME_STYLE as $o,DARK_THEME_FILTER as Of,MIME_TYPES as As,THEME as jn,distance as ci,getFontString as kf,isRTL as Ff,getVerticalOffset as Rf,invariant as Nf,applyDarkModeFilter as ji,isSafari as zf}from"@excalidraw/common";P();import{pointFrom as Ot,pointCenter as qu,pointRotateRads as on,vectorFromPoint as Mr,vectorNormalize as _a,vectorSubtract as Ua,vectorAdd as fo,vectorScale as ho,pointFromVector as Wa,clamp as ve,isCloseTo as Ya}from"@excalidraw/math";var De=10,Rb=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=Ar(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,h=on(Ot(r,s),re(e,t),-e.angle);r=h[0],s=h[1];let f=e.width,g=e.height,E=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=E.height,b=E.width,y=e.scale[0]===-1,w=e.scale[1]===-1,S=s-e.y,I=r-e.x;n.includes("n")&&(g=ve(e.height-S,De,w?d-p:e.height+p)),n.includes("s")&&(S=s-e.y-e.height,g=ve(e.height+S,De,w?e.height+p:d-p)),n.includes("e")&&(I=r-e.x-e.width,f=ve(e.width+I,De,y?e.width+m:l-m)),n.includes("w")&&(f=ve(e.width-I,De,y?l-m:e.width+m));let A=C=>{C.height=g*u,C.width=f*c};A(E);let M=(C,O)=>{A(O),C.includes("n")&&(w||(O.y+=x-O.height)),C.includes("s")&&w&&(O.y+=x-O.height),C.includes("e")&&y&&(O.x+=b-O.width),C.includes("w")&&(y||(O.x+=b-O.width))};switch(n){case"n":{if(a){let C=m+e.width/2,O=l-m-e.width/2,v=Math.min(C,O)*2;f=ve(g*a,De,v),g=f/a}M(n,E),a&&(E.x+=(b-E.width)/2);break}case"s":{if(a){let C=m+e.width/2,O=l-m-e.width/2,v=Math.min(C,O)*2;f=ve(g*a,De,v),g=f/a}M(n,E),a&&(E.x+=(b-E.width)/2);break}case"w":{if(a){let C=p+e.height/2,O=d-p-e.height/2,v=Math.min(C,O)*2;g=ve(f/a,De,v),f=g*a}M(n,E),a&&(E.y+=(x-E.height)/2);break}case"e":{if(a){let C=p+e.height/2,O=d-p-e.height/2,v=Math.min(C,O)*2;g=ve(f/a,De,v),f=g*a}M(n,E),a&&(E.y+=(x-E.height)/2);break}case"ne":{if(a)if(I>-S){let C=w?d-p:p+e.height;g=ve(f/a,De,C),f=g*a}else{let C=y?m+e.width:l-m;f=ve(g*a,De,C),g=f/a}M(n,E);break}case"nw":{if(a)if(I<S){let C=w?d-p:p+e.height;g=ve(f/a,De,C),f=g*a}else{let C=y?l-m:m+e.width;f=ve(g*a,De,C),g=f/a}M(n,E);break}case"se":{if(a)if(I>S){let C=w?p+e.height:d-p;g=ve(f/a,De,C),f=g*a}else{let C=y?m+e.width:l-m;f=ve(g*a,De,C),g=f/a}M(n,E);break}case"sw":{if(a)if(-I>S){let C=w?p+e.height:d-p;g=ve(f/a,De,C),f=g*a}else{let C=y?l-m:m+e.width;f=ve(g*a,De,C),g=f/a}M(n,E);break}default:break}let L=Ku(e,n,f,g,!!a);return Ya(E.width,E.naturalWidth)&&Ya(E.height,E.naturalHeight)&&(E=null),{x:L[0],y:L[1],width:f,height:g,crop:E}},Ku=(e,t,n,i,o)=>{let[r,s,a,l]=rn(e,e.width,e.height,!0),d=Ot(r,s),c=Ot(a,l),u=qu(d,c),[m,p,h,f]=rn(e,n,i,!0),g=h-m,E=f-p,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(g),c[1]-Math.abs(E)]),t==="ne"){let A=[d[0],c[1]];x=[A[0],A[1]-Math.abs(E)]}if(t==="sw"){let A=[c[0],d[1]];x=[A[0]-Math.abs(g),A[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-g/2),["e","w"].includes(t)&&(x[1]=u[1]-E/2));let b=e.angle,y=on(x,u,b),w=[x[0]+Math.abs(g)/2,x[1]+Math.abs(E)/2],S=on(w,u,b);x=on(y,S,-b);let I=[...x];return I[0]+=e.x-m,I[1]+=e.y-p,I},ja=(e,t)=>{if(e.crop){let{width:n,height:i}=Ar(e),[o,r,s,a,l,d]=$(e,t),c=Mr(on(Ot(o,r),Ot(l,d),e.angle)),u=Mr(on(Ot(s,r),Ot(l,d),e.angle)),m=_a(Ua(u,c)),p=Mr(on(Ot(o,a),Ot(l,d),e.angle)),h=Ua(p,c),f=_a(h),{cropX:g,cropY:E}=Qu(e.crop,e.scale),x=fo(fo(c,ho(m,-g*n/e.crop.naturalWidth)),ho(f,-E*i/e.crop.naturalHeight)),b=Wa(fo(fo(x,ho(m,n/2)),ho(f,i/2))),y=on(Wa(x),b,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},Ar=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}},Qu=(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}},Nb=(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}=Ar(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as ed,pointFrom as k,pointRotateRads as Re,pointsEqual as td,pointDistance as Wn,vectorFromPoint as qp,curveLength as Kp,curvePointAtLength as Qp}from"@excalidraw/math";import{DRAGGING_THRESHOLD as Jp,KEYS as Un,shouldRotateWithDiscreteAngle as Wi,getGridPoint as nd,invariant as $e,isShallowEqual as ef,getFeatureFlag as li}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as id,getSnapOutlineMidPoint as od,isPathALoop as tf,moveArrowAboveBindable as rd,projectFixedPointOntoDiagonal as sd}from"@excalidraw/element";P();import{arrayToMap as $l,getFeatureFlag as Lp,invariant as $t,isTransparent as Cp}from"@excalidraw/common";import{PRECISION as _i,clamp as ds,lineSegment as Ho,pointDistance as hn,pointDistanceSq as Xt,pointFrom as ie,pointFromVector as No,pointRotateRads as le,pointsEqual as Gp,vectorFromPoint as zi,vectorNormalize as ls,vectorScale as zo}from"@excalidraw/math";P();import{invariant as Pl,isTransparent as Il}from"@excalidraw/common";import{curveIntersectLineSegment as Sl,isPointWithinBounds as Xr,lineSegment as ki,lineSegmentIntersectionPoints as Ml,pointFrom as we,pointFromVector as Km,pointRotateRads as Je,pointsEqual as Al,vectorFromPoint as Qm,vectorNormalize as Jm,vectorScale as ep}from"@excalidraw/math";import{ellipse as tp,ellipseSegmentInterceptPoints as np}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as sm,DEFAULT_PROPORTIONAL_RADIUS as vr,invariant as am,LINE_CONFIRM_THRESHOLD as lm,ROUNDNESS as Dr}from"@excalidraw/common";import{bezierEquation as dm,curve as Ft,curveCatmullRomCubicApproxPoints as nl,curveOffsetPoints as il,lineSegment as Pe,lineSegmentIntersectionPoints as el,pointDistance as Rn,pointFrom as z,pointFromArray as cm,pointFromVector as um,pointRotateRads as Ke,pointTranslate as tl,rectangle as mm,vectorFromPoint as ol,vectorNormalize as pm,vectorScale as Br}from"@excalidraw/math";P();import{ROUNDNESS as vi,assertNever as Ju}from"@excalidraw/common";import{pointsEqual as Xa}from"@excalidraw/math";var Fn=e=>!!e&&e.type==="image"&&!!e.fileId,Me=e=>!!e&&e.type==="image",$a=e=>!!e&&e.type==="embeddable",go=e=>!!e&&e.type==="iframe",Eo=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),K=e=>e!=null&&e.type==="text",xo=e=>e!=null&&e.type==="frame",Va=e=>e!=null&&e.type==="magicframe",q=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Ie=e=>e!=null&&em(e.type),em=e=>e==="freedraw",Q=e=>e!=null&&im(e.type),kt=e=>e!=null&&e.type==="line",_=e=>e!=null&&e.type==="arrow",W=e=>_(e)&&e.elbowed,Wb=e=>_(e)&&!e.elbowed,tm=e=>_(e)&&!e.elbowed&&!e.roundness,nm=e=>_(e)&&!e.elbowed&&e.roundness!==null,im=e=>e==="arrow"||e==="line",Be=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&om(e.type),om=e=>e==="arrow",fe=(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),Za=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),Di=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"),rm=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||_(e)),qa=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 Ju(t,null),!1}},Tr=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",wt=e=>rm(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),he=e=>e!==null&&"containerId"in e&&e.containerId!==null&&K(e),Yb=e=>!!e.startBinding||!!e.endBinding,Ka=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",Qa=e=>e==="line"||e==="arrow"||e==="diamond",jb=(e,t)=>!!((e===vi.ADAPTIVE_RADIUS||e===vi.LEGACY)&&Ka(t.type)||e===vi.PROPORTIONAL_RADIUS&&Qa(t.type)),Xb=e=>Qa(e.type)?{type:vi.PROPORTIONAL_RADIUS}:Ka(e.type)?{type:vi.ADAPTIVE_RADIUS}:null,$b=e=>tm(e)?"sharpArrow":nm(e)?"curvedArrow":W(e)?"elbowArrow":"line",Vb=e=>e.length>3&&Xa(e[0],e[e.length-1]),Ja=e=>e.length>3||e.length===3&&!Xa(e[0],e[e.length-1]),Zb=e=>{switch(e){case"rectangle":case"diamond":case"ellipse":case"arrow":case"line":case"freedraw":case"text":case"image":case"frame":case"embeddable":return!0;default:return!1}};var Bi=new WeakMap,Lr=(e,t)=>{let n=Bi.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){Bi.delete(e);return}return o.get(t)},Cr=(e,t,n)=>{let i=Bi.get(e);if(!i){Bi.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){Bi.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function bo(e,t){let n=Lr(e,0);if(n)return n;let i=sl(e,t),o=[],r=[];for(let a=0;a<i.length;a+=1){let l=i[a],d=i[a-1]&&cm(i[a-1].data.slice(-2));switch(l.op){case"move":continue;case"lineTo":if(!d)throw new Error("prevPoint is undefined");o.push(Pe(z(e.x+d[0],e.y+d[1]),z(e.x+l.data[0],e.y+l.data[1])));continue;case"bcurveTo":if(!d)throw new Error("prevPoint is undefined");r.push(Ft(z(e.x+d[0],e.y+d[1]),z(e.x+l.data[0],e.y+l.data[1]),z(e.x+l.data[2],e.y+l.data[3]),z(e.x+l.data[4],e.y+l.data[5])));continue;default:console.error("Unknown op type",l.op)}}let s=[o,r];return Cr(e,s,0),s}function sn(e,t=0){let n=Lr(e,t);if(n)return n;let i=Rt(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=mm(z(e.x,e.y),z(e.x+e.width,e.y+e.height)),r=Pe(z(o[0][0]+i,o[0][1]),z(o[1][0]-i,o[0][1])),s=Pe(z(o[1][0],o[0][1]+i),z(o[1][0],o[1][1]-i)),a=Pe(z(o[0][0]+i,o[1][1]),z(o[1][0]-i,o[1][1])),l=Pe(z(o[0][0],o[1][1]-i),z(o[0][0],o[0][1]+i)),d=[Ft(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]),Ft(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]),Ft(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]),Ft(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=>nl(il(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[Pe(c[0][c[0].length-1][3],c[1][0][0]),Pe(c[1][c[1].length-1][3],c[2][0][0]),Pe(c[2][c[2].length-1][3],c[3][0][0]),Pe(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Cr(e,m,t),m}function rl(e,t=0){let[n,i,o,r,s,a,l,d]=ii(e),c=e.roundness?Rt(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?Rt(Math.abs(r-i),e):(r-i)*.01,[m,p,h,f]=[z(e.x+n,e.y+i),z(e.x+o,e.y+r),z(e.x+s,e.y+a),z(e.x+l,e.y+d)];return[Ft(z(p[0]-c,p[1]-u),p,p,z(p[0]-c,p[1]+u)),Ft(z(h[0]+c,h[1]-u),h,h,z(h[0]-c,h[1]-u)),Ft(z(f[0]+c,f[1]+u),f,f,z(f[0]+c,f[1]-u)),Ft(z(m[0]-c,m[1]+u),m,m,z(m[0]+c,m[1]+u))]}function an(e,t=0){let n=Lr(e,t);if(n)return n;let o=rl(e,t).map(a=>nl(il(a,t))),s=[[Pe(o[0][o[0].length-1][3],o[1][0][0]),Pe(o[1][o[1].length-1][3],o[2][0][0]),Pe(o[2][o[2].length-1][3],o[3][0][0]),Pe(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return Cr(e,s,t),s}var Nn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return Rn(n,i)<=lm/t}return!1},Rt=(e,t)=>{if(t.roundness?.type===Dr.PROPORTIONAL_RADIUS||t.roundness?.type===Dr.LEGACY)return e*vr;if(t.roundness?.type===Dr.ADAPTIVE_RADIUS){let n=t.roundness?.value??sm,i=n/vr;return e<=i?e*vr:n}return 0},fm=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=pm(ol(a[1],a[0])),d=Br(l,n);return Pe(tl(a[0],d),tl(a[1],Br(d,-1)))},o=re(e,t),r=i(Di(e)?Pe(Ke(z(e.x,e.y),o,e.angle),Ke(z(e.x+e.width,e.y+e.height),o,e.angle)):Pe(Ke(z(e.x+e.width/2,e.y),o,e.angle),Ke(z(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(Di(e)?Pe(Ke(z(e.x+e.width,e.y),o,e.angle),Ke(z(e.x,e.y+e.height),o,e.angle)):Pe(Ke(z(e.x,e.y+e.height/2),o,e.angle),Ke(z(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},hm=(e,t,n,i)=>{let o=re(t,n);return(t.type==="diamond"?rl(t).map(a=>{let l=dm(a,.5),d=Ke(l,o,t.angle);return z(d[0],d[1])}):[Ke(z(t.x+t.width,t.y+t.height/2),o,t.angle),Ke(z(t.x+t.width/2,t.y+t.height),o,t.angle),Ke(z(t.x,t.y+t.height/2),o,t.angle),Ke(z(t.x+t.width/2,t.y),o,t.angle)]).find(a=>Rn(e,a)<=ut(i)+t.strokeWidth/2&&!yt({point:e,element:t,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))},Gr=(e,t,n,i,o,r,s=!0)=>{if(am(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;if(s){let E=hm(t,n,o,r);if(E)return E}let[a,l]=fm(n,o),d=G.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o);if(e.points.length===2){let E=i==="start"?e.endBinding:e.startBinding,x=E&&o.get(E.elementId),b=E&&x&&Ue(ln(E.fixedPoint),x,o);b&&(d=b)}let c=um(Br(ol(t,d),2*Rn(d,t)+Math.max(Rn(a[0],a[1]),Rn(l[0],l[1]))),d),u=Pe(c,d),m=el(a,u),p=el(l,u),h=m&&Rn(d,m),f=p&&Rn(d,p),g=null;return h!=null&&f!=null?g=h<f?m:p:g=m||p||null,g&&Nt(g,n,o)?g:null};P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Nm,ARROW_LABEL_WIDTH_FRACTION as zm,BOUND_TEXT_PADDING as Pt,DEFAULT_FONT_SIZE as Hm,TEXT_ALIGN as pl,VERTICAL_ALIGN as fl,getFontString as Mo,isProdEnv as _m,invariant as Um}from"@excalidraw/common";import{pointFrom as hl,pointRotateRads as Wm}from"@excalidraw/math";P();var Li={},al=(e,t)=>{let n=Li[e]||(Li[e]={height:t});return n.height=t,n},ll=e=>{Li[e]&&delete Li[e]},dw=e=>Li[e]?.height??null;P();import{BOUND_TEXT_PADDING as yo,DEFAULT_FONT_SIZE as gm,DEFAULT_FONT_FAMILY as Em,getFontString as xm,isTestEnv as bm,normalizeEOL as wm}from"@excalidraw/common";var Qe=(e,t,n)=>{let i=e.split(`
|
|
1
|
+
var lm=Object.create;var ja=Object.defineProperty;var dm=Object.getOwnPropertyDescriptor;var cm=Object.getOwnPropertyNames;var um=Object.getPrototypeOf,mm=Object.prototype.hasOwnProperty;var pm=(e,t)=>()=>(e&&(t=e(e=0)),t);var fm=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var hm=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of cm(t))!mm.call(e,o)&&o!==n&&ja(e,o,{get:()=>t[o],enumerable:!(i=dm(t,o))||i.enumerable});return e};var gm=(e,t,n)=>(n=e!=null?lm(um(e)):{},hm(t||!e||!e.__esModule?ja(n,"default",{value:e,enumerable:!0}):n,e));var N,I=pm(()=>{N={PROD:!0}});var uu=fm((yA,cu)=>{I();var du="Expected a function",au=NaN,OE="[object Symbol]",NE=/^\s+|\s+$/g,FE=/^[-+]0x[0-9a-f]+$/i,RE=/^0b[01]+$/i,zE=/^0o[0-7]+$/i,_E=parseInt,HE=typeof global=="object"&&global&&global.Object===Object&&global,WE=typeof self=="object"&&self&&self.Object===Object&&self,UE=HE||WE||Function("return this")(),YE=Object.prototype,XE=YE.toString,jE=Math.max,$E=Math.min,Ia=function(){return UE.Date.now()};function VE(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(du);t=lu(t)||0,Ar(n)&&(c=!!n.leading,u="maxWait"in n,r=u?jE(lu(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(M){var S=i,T=o;return i=o=void 0,d=M,s=e.apply(T,S),s}function h(M){return d=M,a=setTimeout(E,t),c?p(M):s}function f(M){var S=M-l,T=M-d,A=t-S;return u?$E(A,r-T):A}function g(M){var S=M-l,T=M-d;return l===void 0||S>=t||S<0||u&&T>=r}function E(){var M=Ia();if(g(M))return x(M);a=setTimeout(E,f(M))}function x(M){return a=void 0,m&&i?p(M):(i=o=void 0,s)}function b(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function y(){return a===void 0?s:x(Ia())}function w(){var M=Ia(),S=g(M);if(i=arguments,o=this,l=M,S){if(a===void 0)return h(l);if(u)return a=setTimeout(E,t),p(l)}return a===void 0&&(a=setTimeout(E,t)),s}return w.cancel=b,w.flush=y,w}function ZE(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(du);return Ar(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),VE(e,t,{leading:i,maxWait:t,trailing:o})}function Ar(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function KE(e){return!!e&&typeof e=="object"}function qE(e){return typeof e=="symbol"||KE(e)&&XE.call(e)==OE}function lu(e){if(typeof e=="number")return e;if(qE(e))return au;if(Ar(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Ar(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(NE,"");var n=RE.test(e);return n||zE.test(e)?_E(e.slice(2),n?2:8):FE.test(e)?au:+e}cu.exports=ZE});I();import{toIterable as iw}from"@excalidraw/common";I();import{SHIFT_LOCKING_ANGLE as pn,viewportCoordsToSceneCoords as xr}from"@excalidraw/common";import{normalizeRadians as Oc,radiansBetweenAngles as Bg,radiansDifference as Lg}from"@excalidraw/math";import{pointsEqual as Cg}from"@excalidraw/math";I();I();I();I();I();I();I();I();I();function _r(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 xm(e,t,n){let i=[];e.forEach(o=>i.push(...o)),_r(i,t,n)}function bm(e,t){return e[0]===t[0]&&e[1]===t[1]}function $a(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)_r(d,a,o);let l=wm(s,r,i);if(o){for(let d of s)_r(d,a,-o);xm(l,a,-o)}return l}function wm(e,t,n){let i=[];for(let d of e){let c=[...d];bm(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 zt(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),$a(e,o,i,r||1)}var En=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=zt(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}};I();I();function xn(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 En{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=zt(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)xn([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)}}};I();var go=class extends En{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}};I();var Eo=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=zt(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=xn(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 h=0;h<c;h++){let f=p+u+h*o,g=m-s+Math.random()*2*s,E=f-s+Math.random()*2*s,x=this.helper.ellipse(g,E,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};I();var xo=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=zt(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=xn(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 h=p*(i+o),f=h+i,g=[c[0]+h*Math.cos(m)+d*Math.cos(m),c[1]+h*Math.sin(m)+d*Math.sin(m)],E=[c[0]+f*Math.cos(m)+d*Math.cos(m),c[1]+f*Math.sin(m)+d*Math.sin(m)];r.push(...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],n))}}),r}};I();var bo=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,o=n.zigzagOffset<0?i:n.zigzagOffset;n=Object.assign({},n,{hachureGap:i+o});let r=zt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=xn(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,h=Math.sqrt(2*Math.pow(n,2)),f=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],g=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],E=[f[0]+h*Math.cos(c+Math.PI/4),f[1]+h*Math.sin(c+Math.PI/4)];o.push(...this.helper.doubleLineOps(f[0],f[1],E[0],E[1],i),...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],i))}}),o}};var nt={};function Va(e,t){let n=e.fillStyle||"hachure";if(!nt[n])switch(n){case"zigzag":nt[n]||(nt[n]=new ho(t));break;case"cross-hatch":nt[n]||(nt[n]=new go(t));break;case"dots":nt[n]||(nt[n]=new Eo(t));break;case"dashed":nt[n]||(nt[n]=new xo(t));break;case"zigzag-line":nt[n]||(nt[n]=new bo(t));break;case"hachure":default:n="hachure",nt[n]||(nt[n]=new En(t));break}return nt[n]}I();function Za(){return Math.floor(Math.random()*2**31)}var wo=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};I();I();var yo={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 ym(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 Hr(e,t){return e.type===t}function ci(e){let t=[],n=ym(e),i="BOD",o=0,r=n[o];for(;!Hr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=yo[r.text],i=r.text;else return ci("M0,0"+e);else Hr(r,1)?s=yo[i]:(o++,s=yo[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(Hr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof yo[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}I();function Oi(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}I();function Fi(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,h=0;n==="Q"||n==="T"?(p=i+(i-a),h=o+(o-l)):(p=i,h=o);let f=i+2*(p-i)/3,g=o+2*(h-o)/3,E=u+2*(p-u)/3,x=m+2*(h-m)/3;t.push({key:"C",data:[f,g,E,x,u,m]}),a=p,l=h,i=u,o=m;break}case"Q":{let[u,m,p,h]=c,f=i+2*(u-i)/3,g=o+2*(m-o)/3,E=p+2*(u-p)/3,x=h+2*(m-h)/3;t.push({key:"C",data:[f,g,E,x,p,h]}),a=u,l=m,i=p,o=h;break}case"A":{let u=Math.abs(c[0]),m=Math.abs(c[1]),p=c[2],h=c[3],f=c[4],g=c[5],E=c[6];u===0||m===0?(t.push({key:"C",data:[i,o,g,E,g,E]}),i=g,o=E):(i!==g||o!==E)&&(Ka(i,o,g,E,u,m,p,h,f).forEach(function(b){t.push({key:"C",data:b})}),i=g,o=E);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function Pm(e){return Math.PI*e/180}function Ni(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 Ka(e,t,n,i,o,r,s,a,l,d){let c=Pm(s),u=[],m=0,p=0,h=0,f=0;if(d)[m,p,h,f]=d;else{[e,t]=Ni(e,t,-c),[n,i]=Ni(n,i,-c);let k=(e-n)/2,G=(t-i)/2,_=k*k/(o*o)+G*G/(r*r);_>1&&(_=Math.sqrt(_),o=_*o,r=_*r);let W=a===l?-1:1,D=o*o,L=r*r,P=D*L-D*G*G-L*k*k,v=D*G*G+L*k*k,C=W*Math.sqrt(Math.abs(P/v));h=C*o*G/r+(e+n)/2,f=C*-r*k/o+(t+i)/2,m=Math.asin(parseFloat(((t-f)/r).toFixed(9))),p=Math.asin(parseFloat(((i-f)/r).toFixed(9))),e<h&&(m=Math.PI-m),n<h&&(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 g=p-m;if(Math.abs(g)>Math.PI*120/180){let k=p,G=n,_=i;l&&p>m?p=m+Math.PI*120/180*1:p=m+Math.PI*120/180*-1,n=h+o*Math.cos(p),i=f+r*Math.sin(p),u=Ka(n,i,G,_,o,r,s,0,l,[p,k,h,f])}g=p-m;let E=Math.cos(m),x=Math.sin(m),b=Math.cos(p),y=Math.sin(p),w=Math.tan(g/4),M=4/3*o*w,S=4/3*r*w,T=[e,t],A=[e+M*x,t-S*E],F=[n+M*y,i-S*b],B=[n,i];if(A[0]=2*T[0]-A[0],A[1]=2*T[1]-A[1],d)return[A,F,B].concat(u);{u=[A,F,B].concat(u);let k=[];for(let G=0;G<u.length;G+=3){let _=Ni(u[G][0],u[G][1],c),W=Ni(u[G+1][0],u[G+1][1],c),D=Ni(u[G+2][0],u[G+2][1],c);k.push([_[0],_[1],W[0],W[1],D[0],D[1]])}return k}}var Im={randOffset:Am,randOffsetWithRange:Tm,ellipse:Mm,doubleLineOps:Dm};function Wr(e,t,n,i,o){return{type:"path",ops:Jt(e,t,n,i,o)}}function Ri(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Jt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Jt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return Wr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Sm(e,t){return Ri(e,!0,t)}function tl(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Sm(r,o)}function Ur(e,t){let n=Qa(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=Qa(e,1.5*(1+t.roughness*.22),vm(t));n=n.concat(i)}return{type:"path",ops:n}}function Mm(e,t,n,i,o){let r=Yr(n,i,o);return So(e,t,o,r).opset}function Yr(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+=Y(s*l,n),a+=Y(a*l,n),{increment:r,rx:s,ry:a}}function So(e,t,n,i){let[o,r]=Ja(i.increment,e,t,i.rx,i.ry,1,i.increment*Po(.1,Po(.4,1,n),n),n),s=Io(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=Ja(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Io(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Xr(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+=Y(u*.01,l),m+=Y(m*.01,l);let p=o,h=r;for(;p<0;)p+=Math.PI*2,h+=Math.PI*2;h-p>Math.PI*2&&(p=0,h=Math.PI*2);let f=Math.PI*2/l.curveStepCount,g=Math.min(f/2,(h-p)/2),E=el(g,d,c,u,m,p,h,1,l);if(!l.disableMultiStroke){let x=el(g,d,c,u,m,p,h,1.5,l);E.push(...x)}return s&&(a?E.push(...Jt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...Jt(d,c,d+u*Math.cos(h),c+m*Math.sin(h),l)):E.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(p),c+m*Math.sin(p)]})),{type:"path",ops:E}}function jr(e,t){let n=Fi(Oi(ci(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(...Jt(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(...Bm(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...Jt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function Mo(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]+Y(o,t),i[0][1]+Y(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+Y(o,t),i[s][1]+Y(o,t)]})}}return{type:"fillPath",ops:n}}function Xn(e,t){return Va(t,Im).fillPolygons(e,t)}function nl(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=Y(d*.01,s),c+=Y(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,h=[];for(let f=u;f<=m;f=f+p)h.push([a+d*Math.cos(f),l+c*Math.sin(f)]);return h.push([a+d*Math.cos(m),l+c*Math.sin(m)]),h.push([a,l]),Xn([h],s)}function Am(e,t){return Y(e,t)}function Tm(e,t,n){return Po(e,t,n)}function Dm(e,t,n,i,o){return Jt(e,t,n,i,o,!0)}function vm(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function il(e){return e.randomizer||(e.randomizer=new wo(e.seed||0)),e.randomizer.next()}function Po(e,t,n,i=1){return n.roughness*i*(il(n)*(t-e)+e)}function Y(e,t,n=1){return Po(-e,e,t,n)}function Jt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=qa(e,t,n,i,o,!0,!1);if(s)return a;let l=qa(e,t,n,i,o,!0,!0);return a.concat(l)}function qa(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+il(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,h=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=Y(p,o,d),h=Y(h,o,d);let f=[],g=()=>Y(u,o,d),E=()=>Y(c,o,d),x=o.preserveVertices;return r&&(s?f.push({op:"move",data:[e+(x?0:g()),t+(x?0:g())]}):f.push({op:"move",data:[e+(x?0:Y(c,o,d)),t+(x?0:Y(c,o,d))]})),s?f.push({op:"bcurveTo",data:[p+e+(n-e)*m+g(),h+t+(i-t)*m+g(),p+e+2*(n-e)*m+g(),h+t+2*(i-t)*m+g(),n+(x?0:g()),i+(x?0:g())]}):f.push({op:"bcurveTo",data:[p+e+(n-e)*m+E(),h+t+(i-t)*m+E(),p+e+2*(n-e)*m+E(),h+t+2*(i-t)*m+E(),n+(x?0:E()),i+(x?0:E())]}),f}function Qa(e,t,n){let i=[];i.push([e[0][0]+Y(t,n),e[0][1]+Y(t,n)]),i.push([e[0][0]+Y(t,n),e[0][1]+Y(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+Y(t,n),e[o][1]+Y(t,n)]),o===e.length-1&&i.push([e[o][0]+Y(t,n),e[o][1]+Y(t,n)]);return Io(i,null,n)}function Io(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]+Y(a,n),t[1]+Y(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(...Jt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function Ja(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=Y(.5,a)-Math.PI/2;c.push([Y(r,a)+t+.9*i*Math.cos(u-e),Y(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 h=[Y(r,a)+t+i*Math.cos(p),Y(r,a)+n+o*Math.sin(p)];d.push(h),c.push(h)}c.push([Y(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),Y(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([Y(r,a)+t+.98*i*Math.cos(u+s),Y(r,a)+n+.98*o*Math.sin(u+s)]),c.push([Y(r,a)+t+.9*i*Math.cos(u+s*.5),Y(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function el(e,t,n,i,o,r,s,a,l){let d=r+Y(.1,l),c=[];c.push([Y(a,l)+t+.9*i*Math.cos(d-e),Y(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([Y(a,l)+t+i*Math.cos(u),Y(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)]),Io(c,null,l)}function Bm(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:Y(d[0],a)),s[1]+(m?0:Y(d[0],a))]}),c=m?[o,r]:[o+Y(d[p],a),r+Y(d[p],a)],l.push({op:"bcurveTo",data:[e+Y(d[p],a),t+Y(d[p],a),n+Y(d[p],a),i+Y(d[p],a),c[0],c[1]]});return l}I();function zi(e){return[...e]}function Ao(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(zi(e[0]),zi(e[1]),zi(e[2]),zi(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(zi(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}I();function Lm(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 Cm(e,t,n){let i=To(t,n);if(i===0)return To(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)),To(e,jn(t,n,o))}function jn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Gm(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 $r(e,t,n,i){let o=i||[];if(Gm(e,t)<n){let r=e[t+0];o.length?Lm(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=jn(s,a,.5),u=jn(a,l,.5),m=jn(l,d,.5),p=jn(c,u,.5),h=jn(u,m,.5),f=jn(p,h,.5);$r([s,c,p,f],0,n,o),$r([f,h,m,d],0,n,o)}return o}function bn(e,t){return Do(e,0,e.length,t)}function Do(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=Cm(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(Do(e,t,d+1,i,r),Do(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function It(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;$r(e,s,t,i)}return n&&n>0?Do(i,0,i.length,n):i}I();function ol(e,t,n){let i=ci(e),o=Fi(Oi(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...It(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 h=s.length?s[s.length-1]:a;l.push([h[0],h[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=bn(m,n);p.length&&u.push(p)}return u}var mt="none",bt=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Za()}_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",[Wr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=tl(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(Mo([d],s)):a.push(Xn([d],s))}return s.stroke!==mt&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=Yr(i,o,s),d=So(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=So(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(Xn([d.estimatedPoints],s));return s.stroke!==mt&&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",[Ri(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=Xr(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=Xr(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(nl(t,n,i,o,r,s,d));return d.stroke!==mt&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=Ur(t,i);if(i.fill&&i.fill!==mt&&t.length>=3)if(i.fillStyle==="solid"){let s=Ur(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=Ao(t),a=It(s,10,(1+i.roughness)/2);o.push(Xn([a],i))}return i.stroke!==mt&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=Ri(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(Mo([t],i)):o.push(Xn([t],i))),i.stroke!==mt&&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!==mt,s=i.stroke!==mt,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=ol(t,1,l),c=jr(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=jr(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(Mo(d,i));else o.push(Xn(d,i));return s&&(a?d.forEach(u=>{o.push(Ri(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:mt};break;case"fillPath":s={d:this.opsToPath(r),stroke:mt,strokeWidth:0,fill:i.fill||mt};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||mt,strokeWidth:i,fill:mt}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var vo=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new bt(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":o.save(),o.strokeStyle=i.stroke==="none"?"transparent":i.stroke,o.lineWidth=i.strokeWidth,i.strokeLineDash&&o.setLineDash(i.strokeLineDash),i.strokeLineDashOffset&&(o.lineDashOffset=i.strokeLineDashOffset),this._drawToContext(o,s,r),o.restore();break;case"fillPath":{o.save(),o.fillStyle=i.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,s,r,a),o.restore();break}case"fillSketch":this.fillSketch(o,s,i);break}}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2),t.save(),i.fillLineDash&&t.setLineDash(i.fillLineDash),i.fillLineDashOffset&&(t.lineDashOffset=i.fillLineDashOffset),t.strokeStyle=i.fill||"",t.lineWidth=o,this._drawToContext(t,n,i.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,i,o="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof i=="number"&&i>=0?r.data.map(a=>+a.toFixed(i)):r.data;switch(r.op){case"move":t.moveTo(s[0],s[1]);break;case"bcurveTo":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"lineTo":t.lineTo(s[0],s[1]);break}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s),s}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s),s}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s),s}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r),r}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i),i}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i),i}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d),d}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i),i}path(t,n){let i=this.gen.path(t,n);return this.draw(i),i}};I();I();var _i="http://www.w3.org/2000/svg";var Bo=class{constructor(t,n){this.svg=t,this.gen=new bt(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(_i,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(_i,"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(_i,"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(_i,"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 ui={canvas(e,t){return new vo(e,t)},svg(e,t){return new Bo(e,t)},generator(e){return new bt(e)},newSeed(){return bt.newSeed()}};import{arrayToMap as Gc,invariant as da,rescalePoints as Dc,sizeOf as bg}from"@excalidraw/common";import{degreesToRadians as la,lineSegment as Pe,pointFrom as O,pointFromArray as kc,pointRotateRads as le}from"@excalidraw/math";I();import{invariant as km}from"@excalidraw/common";import{curve as Om,lineSegment as Nm,pointFrom as Ee,pointDistance as Hy,pointFromArray as Fm,pointFromVector as Rm,pointRotateRads as St,polygon as rl,polygonFromPoints as Vr,PRECISION as Wy,segmentsIntersectAt as Uy,vector as zm,vectorAdd as _m,vectorFromPoint as Hm,vectorScale as Yy}from"@excalidraw/math";import{getElementAbsoluteCoords as jy}from"@excalidraw/element";var sl=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=Ee(s,a),d;return e.type==="diamond"?d=rl(St(Ee(s,r),l,t),St(Ee(o+n,a),l,t),St(Ee(s,r+i),l,t),St(Ee(o,a),l,t)):d=rl(St(Ee(o,r),l,t),St(Ee(o+n,r),l,t),St(Ee(o+n,r+i),l,t),St(Ee(o,r+i),l,t)),{type:"polygon",data:d}};var al=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:Ee(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},en=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},ll=(e,t=Ee(0,0),n,i)=>{let o=l=>St(Ee(l[0]+t[0],l[1]+t[1]),i,n),r=en(e),s=[],a=Ee(0,0);for(let l of r){if(l.op==="move"){let d=Fm(l.data);km(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(Ee(l.data[0],l.data[1])),c=o(Ee(l.data[2],l.data[3])),u=o(Ee(l.data[4],l.data[5]));s.push(Om(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Wm=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Nm(t,o)),t=o}return n},dl=(e,t,n=!1)=>{let i=r=>St(Rm(_m(Hm(r),zm(e.x,e.y))),t,e.angle),o=Wm(e.points.map(r=>i(r)));return n?{type:"polygon",data:Vr(o.flat())}:{type:"polyline",data:o}},cl=(e,t,n=Ee(0,0),i,o)=>{let r=c=>St(Ee(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:Vr(e.points.map(c=>r(c)))};let s=en(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(Ee(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(Ee(c.data[0],c.data[1])),a.push(Ee(c.data[2],c.data[3])),a.push(Ee(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(Ee(c.data[0],c.data[1]));let d=It(a,10,5).map(c=>r(c));return{type:"polygon",data:Vr(d)}};I();I();function ul(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function Um(e){return[-e[0],-e[1]]}function At(e,t){return[e[0]+t[0],e[1]+t[1]]}function wt(e,t){return[e[0]-t[0],e[1]-t[1]]}function Mt(e,t){return[e[0]*t,e[1]*t]}function Ym(e,t){return[e[0]/t,e[1]/t]}function Hi(e){return[e[1],-e[0]]}function ml(e,t){return e[0]*t[0]+e[1]*t[1]}function Xm(e,t){return e[0]===t[0]&&e[1]===t[1]}function jm(e){return Math.hypot(e[0],e[1])}function $m(e){return e[0]*e[0]+e[1]*e[1]}function pl(e,t){return $m(wt(e,t))}function gl(e){return Ym(e,jm(e))}function Vm(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function Wi(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 Zr(e,t,n){return At(e,Mt(wt(t,e),n))}function fl(e,t,n){return At(e,Mt(t,n))}var{min:mi,PI:Zm}=Math,hl=.275,Ui=Zm+1e-4;function Km(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=L=>L,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=L=>L*(2-L)}=a,{cap:m=!0,easing:p=L=>--L*L*L+1}=l;if(e.length===0||n<=0)return[];let h=e[e.length-1].runningLength,f=a.taper===!1?0:a.taper===!0?Math.max(n,h):a.taper,g=l.taper===!1?0:l.taper===!0?Math.max(n,h):l.taper,E=Math.pow(n*i,2),x=[],b=[],y=e.slice(0,10).reduce((L,P)=>{let v=P.pressure;if(r){let C=mi(1,P.distance/n),z=mi(1,1-C);v=mi(1,L+(z-L)*(C*hl))}return(L+v)/2},e[0].pressure),w=ul(n,o,e[e.length-1].pressure,s),M,S=e[0].vector,T=e[0].point,A=T,F=T,B=A,k=!1;for(let L=0;L<e.length;L++){let{pressure:P}=e[L],{point:v,vector:C,distance:z,runningLength:Q}=e[L];if(L<e.length-1&&h-Q<3)continue;if(o){if(r){let pe=mi(1,z/n),ie=mi(1,1-pe);P=mi(1,y+(ie-y)*(pe*hl))}w=ul(n,o,P,s)}else w=n/2;M===void 0&&(M=w);let ee=Q<f?u(Q/f):1,te=h-Q<g?p((h-Q)/g):1;w=Math.max(.01,w*Math.min(ee,te));let ne=(L<e.length-1?e[L+1]:e[L]).vector,Ae=L<e.length-1?ml(C,ne):1,Ft=ml(C,S)<0&&!k,Rt=Ae!==null&&Ae<0;if(Ft||Rt){let pe=Mt(Hi(S),w);for(let ie=1/13,Ce=0;Ce<=1;Ce+=ie)F=Wi(wt(v,pe),v,Ui*Ce),x.push(F),B=Wi(At(v,pe),v,Ui*-Ce),b.push(B);T=F,A=B,Rt&&(k=!0);continue}if(k=!1,L===e.length-1){let pe=Mt(Hi(C),w);x.push(wt(v,pe)),b.push(At(v,pe));continue}let gn=Mt(Hi(Zr(ne,C,Ae)),w);F=wt(v,gn),(L<=1||pl(T,F)>E)&&(x.push(F),T=F),B=At(v,gn),(L<=1||pl(A,B)>E)&&(b.push(B),A=B),y=P,S=C}let G=e[0].point.slice(0,2),_=e.length>1?e[e.length-1].point.slice(0,2):At(e[0].point,[1,1]),W=[],D=[];if(e.length===1){if(!(f||g)||d){let L=fl(G,gl(Hi(wt(G,_))),-(M||w)),P=[];for(let v=1/13,C=v;C<=1;C+=v)P.push(Wi(L,G,Ui*2*C));return P}}else{if(!(f||g&&e.length===1))if(c)for(let P=1/13,v=P;v<=1;v+=P){let C=Wi(b[0],G,Ui*v);W.push(C)}else{let P=wt(x[0],b[0]),v=Mt(P,.5),C=Mt(P,.51);W.push(wt(G,v),wt(G,C),At(G,C),At(G,v))}let L=Hi(Um(e[e.length-1].vector));if(g||f&&e.length===1)D.push(_);else if(m){let P=fl(_,L,w);for(let v=1/29,C=v;C<1;C+=v)D.push(Wi(P,_,Ui*3*C))}else D.push(At(_,Mt(L,w)),At(_,Mt(L,w*.99)),wt(_,Mt(L,w*.99)),wt(_,Mt(L,w)))}return x.concat(D,b.reverse(),W)}function Kr(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:h,pressure:f=.5})=>[p,h,f]);if(a.length===2){let p=a[1];a=a.slice(0,-1);for(let h=1;h<5;h++)a.push(Zr(a[0],p,h/4))}a.length===1&&(a=[...a,[...At(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 h=r&&p===m?a[p].slice(0,2):Zr(u.point,a[p],s);if(Xm(u.point,h))continue;let f=Vm(h,u.point);if(c+=f,p<m&&!d){if(c<o)continue;d=!0}u={point:h,pressure:a[p][2]>=0?a[p][2]:.5,vector:gl(wt(u.point,h)),distance:f,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function El(e,t={}){return Km(Kr(e,t),t)}I();I();I();function xe([e,t,n],[i,o,r]){return[e+i,t+o,n+r]}function pi([e,t,n],[i,o,r]){return[e-i,t-o,n-r]}function Me([e,t,n],i){return[e*i,t*i,n*i]}function Vn([e,t,n]){return[e/Math.sqrt(e**2+t**2),t/Math.sqrt(e**2+t**2),n]}function Ge([e,t,n],i){return[Math.cos(i)*e-Math.sin(i)*t,Math.sin(i)*e+Math.cos(i)*t,n]}function xl(e,t,n){return xe(e,Me(pi(t,e),n))}function qr(e,t,n){return Math.atan2(n[1]-e[1],n[0]-e[0])-Math.atan2(t[1]-e[1],t[0]-e[0])}function Qr(e){return Math.atan2(Math.sin(e),Math.cos(e))}function Jr([e,t]){return Math.sqrt(e**2+t**2)}function $n([e,t],[n,i]){return Math.sqrt((n-e)**2+(i-t)**2)}function bl(e){if(e.length<2)return 0;let t=0;for(let n=1;n<=e.length-1;n++)t+=$n(e[n-1],e[n]);return t+=$n(e[e.length-2],e[e.length-1]),t}var qm=(e,t,n)=>Math.max(t,Math.min(n,e));function wl(e,t,n){let i=$n(t,n);if(i===0)return $n(e,t);let o=qm(((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i**2,0,1),r=[t[0]+o*(n[0]-t[0]),t[1]+o*(n[1]-t[1]),e[2]];return $n(r,e)}I();function Yi(e,t){if(t===0||e.length<=2)return e;let n=e[0],i=e[e.length-1],[o,r]=e.reduce(([s,a],l,d)=>{let c=wl(l,n,i);return c>s?[c,d]:[s,a]},[0,-1]);if(o>=t){let s=e[r];return[...Yi([n,...e.slice(1,r),s],t).slice(0,-1),s,...Yi([s,...e.slice(r,-1),i],t).slice(1)]}return[n,i]}var Lo=class e{static defaults={size:2,streamline:.45,simplify:.1,simplifyPhase:"output",keepHead:!1,sizeMapping:()=>1};static constants={cornerDetectionMaxAngle:75,cornerDetectionVariance:t=>t>35?.5:1,maxTailLength:50};options;constructor(t){this.options=Object.assign({},e.defaults,t)}originalPoints=[];stablePoints=[];tailPoints=[];isFresh=!0;get lastPoint(){return this.tailPoints[this.tailPoints.length-1]??this.stablePoints[this.stablePoints.length-1]}addPoint(t){let n=this.originalPoints[this.originalPoints.length-1];if(!(n&&n[0]===t[0]&&n[1]===t[1])){if(this.originalPoints.push(t),this.isFresh){this.isFresh=!1,this.stablePoints.push(t);return}this.options.streamline>0&&(t=xl(this.lastPoint,t,1-this.options.streamline)),this.tailPoints.push(t),bl(this.tailPoints)>e.constants.maxTailLength&&this.stabilizeTail()}}close(){this.stabilizeTail()}stabilizeTail(){if(this.options.simplify>0&&this.options.simplifyPhase==="tail")throw new Error("Not implemented yet");this.stablePoints.push(...this.tailPoints),this.tailPoints=[]}getSize(t,n,i,o,r){return(t??this.options.size)*this.options.sizeMapping({pressure:n,runningLength:r,currentIndex:i,totalLength:o})}getStrokeOutline(t){if(this.isFresh)return[];let n=[...this.stablePoints,...this.tailPoints];this.options.simplify>0&&this.options.simplifyPhase==="input"&&(n=Yi(n,this.options.simplify));let i=n.length;if(i===0)return[];if(i===1){let S=n[0],T=this.getSize(t,S[2],0,i,0);if(T<.5)return[];let A=[];for(let F=0;F<=Math.PI*2;F+=Math.PI/16)A.push(xe(S,Me(Ge([1,0,0],F),T)));return A.push(xe(S,Me([1,0,0],this.getSize(t,S[2],0,i,0)))),A}if(i===2){let S=n[0],T=n[1],A=this.getSize(t,S[2],0,i,0),F=this.getSize(t,T[2],0,i,0);if(A<.5||F<.5)return[];let B=[],k=qr(S,[S[0],S[1]-100,S[2]],T);for(let G=k;G<=Math.PI+k;G+=Math.PI/16)B.push(xe(S,Me(Ge([1,0,0],G),A)));for(let G=Math.PI+k;G<=Math.PI*2+k;G+=Math.PI/16)B.push(xe(T,Me(Ge([1,0,0],G),F)));return B.push(B[0]),B}let o=[],r=[],s=0,a=0,l=0,d=0;for(let S=1;S<i-1;S++){let T=n[S-1],A=n[S],F=n[S+1],B=A[2],k=$n(T,A);d+=k,s=a+(k-a)*.2;let G=this.getSize(t,B,S,i,d);if(G===0){l=S+1;continue}let _=Vn(pi(T,A)),W=Vn(pi(F,A)),D=Ge(_,Math.PI/2),L=Ge(_,-Math.PI/2),P=Ge(W,Math.PI/2),v=Ge(W,-Math.PI/2),C=xe(A,Me(D,G)),z=xe(A,Me(L,G)),Q=xe(A,Me(P,G)),ee=xe(A,Me(v,G)),te=xe(D,v),ne=xe(L,P),Ae=xe(A,Me(Jr(te)===0?_:Vn(te),G)),Ft=xe(A,Me(Jr(ne)===0?W:Vn(ne),G)),Rt=Qr(qr(A,T,F)),gn=e.constants.cornerDetectionMaxAngle/180*Math.PI*e.constants.cornerDetectionVariance(s);if(Math.abs(Rt)<gn){let pe=Math.abs(Qr(Math.PI-Rt));if(pe===0)continue;if(Rt<0){r.push(z,Ft);for(let ie=0;ie<=pe;ie+=pe/4)o.push(xe(A,Ge(Me(D,G),ie)));for(let ie=pe;ie>=0;ie-=pe/4)r.push(xe(A,Ge(Me(D,G),ie)));r.push(Ft,Q)}else{o.push(C,Ae);for(let ie=0;ie<=pe;ie+=pe/4)r.push(xe(A,Ge(Me(D,-G),-ie)));for(let ie=pe;ie>=0;ie-=pe/4)o.push(xe(A,Ge(Me(D,-G),-ie)));o.push(Ae,ee)}}else o.push(Ae),r.push(Ft);a=s}if(l>=i-2){if(this.options.keepHead){let S=n[i-1],T=[];for(let A=0;A<=Math.PI*2;A+=Math.PI/16)T.push(xe(S,Me(Ge([1,0,0],A),this.options.size)));return T.push(xe(S,Me([1,0,0],this.options.size))),T}return[]}let c=n[l],u=n[l+1],m=n[i-2],p=n[i-1],h=Vn(pi(u,c)),f=Vn(pi(m,p)),g=Ge(h,-Math.PI/2),E=Ge(f,Math.PI/2),x=this.getSize(t,c[2],0,i,0),b=[],y=this.options.keepHead?this.options.size:this.getSize(t,m[2],i-2,i,d),w=[];if(x>.1){for(let S=0;S<=Math.PI;S+=Math.PI/16)b.unshift(xe(c,Ge(Me(g,x),-S)));b.unshift(xe(c,Me(g,-x)))}else b.push(c);for(let S=0;S<=Math.PI*3;S+=Math.PI/16)w.push(xe(p,Ge(Me(E,-y),-S)));let M=[...b,...o,...w.reverse(),...r.reverse()];return b.length>0&&M.push(b[0]),this.options.simplify>0&&this.options.simplifyPhase==="output"?Yi(M,this.options.simplify):M}};import{pointFrom as ye,pointDistance as wc,pointRotateRads as un}from"@excalidraw/math";import{ROUGHNESS as ig,THEME as sa,isTransparent as lo,assertNever as og,COLOR_PALETTE as rg,LINE_POLYGON_POINT_MERGE_DISTANCE as sg,applyDarkModeFilter as co,DEFAULT_STROKE_STREAMLINE as ag}from"@excalidraw/common";I();import{isRightAngleRads as Yh,lineSegment as hc,pointFrom as mr,pointRotateRads as na}from"@excalidraw/math";import{BOUND_TEXT_PADDING as Nn,DEFAULT_REDUCED_GLOBAL_ALPHA as Xh,ELEMENT_READY_TO_ERASE_OPACITY as jh,FRAME_STYLE as pr,DARK_THEME_FILTER as $h,MIME_TYPES as oa,THEME as ii,distance as Fn,getFontString as Vh,isRTL as Zh,getVerticalOffset as Kh,invariant as qh,applyDarkModeFilter as ro,isSafari as Qh}from"@excalidraw/common";I();import{pointFrom as tn,pointCenter as Jm,pointRotateRads as wn,vectorFromPoint as es,vectorNormalize as yl,vectorSubtract as Pl,vectorAdd as Co,vectorScale as Go,pointFromVector as Il,clamp as Fe,isCloseTo as Sl}from"@excalidraw/math";var Re=10,d0=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=ts(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,h=wn(tn(r,s),se(e,t),-e.angle);r=h[0],s=h[1];let f=e.width,g=e.height,E=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=E.height,b=E.width,y=e.scale[0]===-1,w=e.scale[1]===-1,M=s-e.y,S=r-e.x;n.includes("n")&&(g=Fe(e.height-M,Re,w?d-p:e.height+p)),n.includes("s")&&(M=s-e.y-e.height,g=Fe(e.height+M,Re,w?e.height+p:d-p)),n.includes("e")&&(S=r-e.x-e.width,f=Fe(e.width+S,Re,y?e.width+m:l-m)),n.includes("w")&&(f=Fe(e.width-S,Re,y?l-m:e.width+m));let T=B=>{B.height=g*u,B.width=f*c};T(E);let A=(B,k)=>{T(k),B.includes("n")&&(w||(k.y+=x-k.height)),B.includes("s")&&w&&(k.y+=x-k.height),B.includes("e")&&y&&(k.x+=b-k.width),B.includes("w")&&(y||(k.x+=b-k.width))};switch(n){case"n":{if(a){let B=m+e.width/2,k=l-m-e.width/2,G=Math.min(B,k)*2;f=Fe(g*a,Re,G),g=f/a}A(n,E),a&&(E.x+=(b-E.width)/2);break}case"s":{if(a){let B=m+e.width/2,k=l-m-e.width/2,G=Math.min(B,k)*2;f=Fe(g*a,Re,G),g=f/a}A(n,E),a&&(E.x+=(b-E.width)/2);break}case"w":{if(a){let B=p+e.height/2,k=d-p-e.height/2,G=Math.min(B,k)*2;g=Fe(f/a,Re,G),f=g*a}A(n,E),a&&(E.y+=(x-E.height)/2);break}case"e":{if(a){let B=p+e.height/2,k=d-p-e.height/2,G=Math.min(B,k)*2;g=Fe(f/a,Re,G),f=g*a}A(n,E),a&&(E.y+=(x-E.height)/2);break}case"ne":{if(a)if(S>-M){let B=w?d-p:p+e.height;g=Fe(f/a,Re,B),f=g*a}else{let B=y?m+e.width:l-m;f=Fe(g*a,Re,B),g=f/a}A(n,E);break}case"nw":{if(a)if(S<M){let B=w?d-p:p+e.height;g=Fe(f/a,Re,B),f=g*a}else{let B=y?l-m:m+e.width;f=Fe(g*a,Re,B),g=f/a}A(n,E);break}case"se":{if(a)if(S>M){let B=w?p+e.height:d-p;g=Fe(f/a,Re,B),f=g*a}else{let B=y?m+e.width:l-m;f=Fe(g*a,Re,B),g=f/a}A(n,E);break}case"sw":{if(a)if(-S>M){let B=w?p+e.height:d-p;g=Fe(f/a,Re,B),f=g*a}else{let B=y?l-m:m+e.width;f=Fe(g*a,Re,B),g=f/a}A(n,E);break}default:break}let F=ep(e,n,f,g,!!a);return Sl(E.width,E.naturalWidth)&&Sl(E.height,E.naturalHeight)&&(E=null),{x:F[0],y:F[1],width:f,height:g,crop:E}},ep=(e,t,n,i,o)=>{let[r,s,a,l]=yn(e,e.width,e.height,!0),d=tn(r,s),c=tn(a,l),u=Jm(d,c),[m,p,h,f]=yn(e,n,i,!0),g=h-m,E=f-p,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(g),c[1]-Math.abs(E)]),t==="ne"){let T=[d[0],c[1]];x=[T[0],T[1]-Math.abs(E)]}if(t==="sw"){let T=[c[0],d[1]];x=[T[0]-Math.abs(g),T[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-g/2),["e","w"].includes(t)&&(x[1]=u[1]-E/2));let b=e.angle,y=wn(x,u,b),w=[x[0]+Math.abs(g)/2,x[1]+Math.abs(E)/2],M=wn(w,u,b);x=wn(y,M,-b);let S=[...x];return S[0]+=e.x-m,S[1]+=e.y-p,S},Ml=(e,t)=>{if(e.crop){let{width:n,height:i}=ts(e),[o,r,s,a,l,d]=Z(e,t),c=es(wn(tn(o,r),tn(l,d),e.angle)),u=es(wn(tn(s,r),tn(l,d),e.angle)),m=yl(Pl(u,c)),p=es(wn(tn(o,a),tn(l,d),e.angle)),h=Pl(p,c),f=yl(h),{cropX:g,cropY:E}=tp(e.crop,e.scale),x=Co(Co(c,Go(m,-g*n/e.crop.naturalWidth)),Go(f,-E*i/e.crop.naturalHeight)),b=Il(Co(Co(x,Go(m,n/2)),Go(f,i/2))),y=wn(Il(x),b,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},ts=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}},tp=(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}},c0=(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}=ts(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};I();import{pointCenter as Nd,pointFrom as H,pointRotateRads as qe,pointsEqual as Fd,pointDistance as Zt,vectorFromPoint as oh,curveLength as $d,curveLengthAtParameter as rh,curvePointAtLength as Vd,lineSegmentClosestParameter as sh,lineSegmentPointAt as Zd,curveClosestParameter as ah,clamp as Ws,bezierEquation as lh,isCurve as lr}from"@excalidraw/math";import{DRAGGING_THRESHOLD as dh,KEYS as ei,shouldRotateWithDiscreteAngle as ti,getGridPoint as Rd,invariant as dt,isShallowEqual as ch,getFeatureFlag as Ii}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as zd,getSnapOutlineMidPoint as _d,isPathALoop as uh,moveArrowAboveBindable as Hd,projectFixedPointOntoDiagonal as Wd,getLinearElementPathSegments as mh}from"@excalidraw/element";I();import{arrayToMap as Dd,getFeatureFlag as Nf,getGridPoint as zs,invariant as cn,isTransparent as Ff}from"@excalidraw/common";import{PRECISION as Rf,clamp as or,lineSegment as wi,pointDistance as Dn,pointDistanceSq as xt,pointFrom as q,pointFromArray as zf,pointFromVector as nr,pointRotateRads as ge,pointsEqual as _f,vectorFromPoint as yi,vectorNormalize as Rs,vectorScale as ir}from"@excalidraw/math";I();import{invariant as nd,isTransparent as id}from"@excalidraw/common";import{curveIntersectLineSegment as od,isPointWithinBounds as Ps,lineSegment as Ji,lineSegmentIntersectionPoints as rd,pointFrom as ve,pointFromVector as ef,pointRotateRads as ht,pointsEqual as sd,vectorFromPoint as tf,vectorNormalize as nf,vectorScale as of}from"@excalidraw/math";import{ellipse as rf,ellipseSegmentInterceptPoints as sf}from"@excalidraw/math/ellipse";I();import{DEFAULT_ADAPTIVE_RADIUS as dp,DEFAULT_PROPORTIONAL_RADIUS as is,invariant as cp,LINE_CONFIRM_THRESHOLD as up,ROUNDNESS as os}from"@excalidraw/common";import{bezierEquation as mp,curve as nn,curveCatmullRomCubicApproxPoints as Nl,curveOffsetPoints as Fl,lineSegment as De,lineSegmentIntersectionPoints as kl,pointDistance as Kn,pointFrom as j,pointFromArray as pp,pointFromVector as fp,pointRotateRads as pt,pointTranslate as Ol,rectangle as hp,vectorFromPoint as Rl,vectorNormalize as gp,vectorScale as rs}from"@excalidraw/math";I();import{ROUNDNESS as Xi,assertNever as np}from"@excalidraw/common";import{pointsEqual as Al}from"@excalidraw/math";var Zn=e=>!!e&&e.type==="image"&&!!e.fileId,ke=e=>!!e&&e.type==="image",Tl=e=>!!e&&e.type==="embeddable",ko=e=>!!e&&e.type==="iframe",Oo=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),oe=e=>e!=null&&e.type==="text",No=e=>e!=null&&e.type==="frame",Dl=e=>e!=null&&e.type==="magicframe",J=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),be=e=>e!=null&&ip(e.type),ip=e=>e==="freedraw",K=e=>e!=null&&sp(e.type),Oe=e=>e!=null&&e.type==="line",U=e=>e!=null&&e.type==="arrow",X=e=>U(e)&&e.elbowed,h0=e=>U(e)&&!e.elbowed,op=e=>U(e)&&!e.elbowed&&!e.roundness,rp=e=>U(e)&&!e.elbowed&&e.roundness!==null,sp=e=>e==="arrow"||e==="line",ze=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&ap(e.type),ap=e=>e==="arrow",we=(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),vl=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),ji=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"),lp=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||U(e)),Bl=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 np(t,null),!1}},Ll=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",_t=e=>lp(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),Ie=e=>e!==null&&"containerId"in e&&e.containerId!==null&&oe(e),g0=e=>!!e.startBinding||!!e.endBinding,Fo=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",Cl=e=>e==="line"||e==="arrow"||e==="diamond",E0=(e,t)=>!!((e===Xi.ADAPTIVE_RADIUS||e===Xi.LEGACY)&&Fo(t.type)||e===Xi.PROPORTIONAL_RADIUS&&Cl(t.type)),x0=e=>Cl(e.type)?{type:Xi.PROPORTIONAL_RADIUS}:Fo(e.type)?{type:Xi.ADAPTIVE_RADIUS}:null,b0=e=>op(e)?"sharpArrow":rp(e)?"curvedArrow":X(e)?"elbowArrow":"line",ns=e=>e.length>3&&Al(e[0],e[e.length-1]),Gl=e=>e.length>3||e.length===3&&!Al(e[0],e[e.length-1]),w0=e=>{switch(e){case"rectangle":case"diamond":case"ellipse":case"arrow":case"line":case"freedraw":case"text":case"image":case"frame":case"embeddable":return!0;default:return!1}};var $i=new WeakMap,ss=(e,t)=>{let n=$i.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){$i.delete(e);return}return o.get(t)},as=(e,t,n)=>{let i=$i.get(e);if(!i){$i.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){$i.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function Vi(e,t){let n=ss(e,0);if(n)return n;let i=_l(e,t),o=[],r=[];for(let a=0;a<i.length;a+=1){let l=i[a],d=i[a-1]&&pp(i[a-1].data.slice(-2));switch(l.op){case"move":continue;case"lineTo":if(!d)throw new Error("prevPoint is undefined");o.push(De(j(e.x+d[0],e.y+d[1]),j(e.x+l.data[0],e.y+l.data[1])));continue;case"bcurveTo":if(!d)throw new Error("prevPoint is undefined");r.push(nn(j(e.x+d[0],e.y+d[1]),j(e.x+l.data[0],e.y+l.data[1]),j(e.x+l.data[2],e.y+l.data[3]),j(e.x+l.data[4],e.y+l.data[5])));continue;default:console.error("Unknown op type",l.op)}}let s=[o,r];return as(e,s,0),s}function C0(e,t){if(X(e))return e.points.slice(1).map((o,r)=>De(j(e.x+e.points[r][0],e.y+e.points[r][1]),j(e.x+o[0],e.y+o[1])));let[n,i]=Vi(e,t);return i.length>0?i:n}function Pn(e,t=0){let n=ss(e,t);if(n)return n;let i=on(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=hp(j(e.x,e.y),j(e.x+e.width,e.y+e.height)),r=De(j(o[0][0]+i,o[0][1]),j(o[1][0]-i,o[0][1])),s=De(j(o[1][0],o[0][1]+i),j(o[1][0],o[1][1]-i)),a=De(j(o[0][0]+i,o[1][1]),j(o[1][0]-i,o[1][1])),l=De(j(o[0][0],o[1][1]-i),j(o[0][0],o[0][1]+i)),d=[nn(l[1],j(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),j(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),nn(r[1],j(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),j(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),nn(s[1],j(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),j(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),nn(a[0],j(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),j(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=>Nl(Fl(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[De(c[0][c[0].length-1][3],c[1][0][0]),De(c[1][c[1].length-1][3],c[2][0][0]),De(c[2][c[2].length-1][3],c[3][0][0]),De(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return as(e,m,t),m}function zl(e,t=0){let[n,i,o,r,s,a,l,d]=fi(e),c=e.roundness?on(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?on(Math.abs(r-i),e):(r-i)*.01,[m,p,h,f]=[j(e.x+n,e.y+i),j(e.x+o,e.y+r),j(e.x+s,e.y+a),j(e.x+l,e.y+d)];return[nn(j(p[0]-c,p[1]-u),p,p,j(p[0]-c,p[1]+u)),nn(j(h[0]+c,h[1]-u),h,h,j(h[0]-c,h[1]-u)),nn(j(f[0]+c,f[1]+u),f,f,j(f[0]+c,f[1]-u)),nn(j(m[0]-c,m[1]+u),m,m,j(m[0]+c,m[1]+u))]}function In(e,t=0){let n=ss(e,t);if(n)return n;let i=zl(e,t),o=t>0?i.map(a=>Nl(Fl(a,t))):[[i[0]],[i[1]],[i[2]],[i[3]]],s=[[De(o[0][o[0].length-1][3],o[1][0][0]),De(o[1][o[1].length-1][3],o[2][0][0]),De(o[2][o[2].length-1][3],o[3][0][0]),De(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return as(e,s,t),s}var Tt=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return Kn(n,i)<=up/t}return!1},on=(e,t)=>{if(t.roundness?.type===os.PROPORTIONAL_RADIUS||t.roundness?.type===os.LEGACY)return e*is;if(t.roundness?.type===os.ADAPTIVE_RADIUS){let n=t.roundness?.value??dp,i=n/is;return e<=i?e*is:n}return 0},Ep=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=gp(Rl(a[1],a[0])),d=rs(l,n);return De(Ol(a[0],d),Ol(a[1],rs(d,-1)))},o=se(e,t),r=i(ji(e)?De(pt(j(e.x,e.y),o,e.angle),pt(j(e.x+e.width,e.y+e.height),o,e.angle)):De(pt(j(e.x+e.width/2,e.y),o,e.angle),pt(j(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(ji(e)?De(pt(j(e.x+e.width,e.y),o,e.angle),pt(j(e.x,e.y+e.height),o,e.angle)):De(pt(j(e.x,e.y+e.height/2),o,e.angle),pt(j(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},xp=(e,t,n,i)=>{let o=se(t,n);return(t.type==="diamond"?zl(t).map(a=>{let l=mp(a,.5),d=pt(l,o,t.angle);return j(d[0],d[1])}):[pt(j(t.x+t.width,t.y+t.height/2),o,t.angle),pt(j(t.x+t.width/2,t.y+t.height),o,t.angle),pt(j(t.x,t.y+t.height/2),o,t.angle),pt(j(t.x+t.width/2,t.y),o,t.angle)]).find(a=>Kn(e,a)<=Dt(i)+t.strokeWidth/2&&!Ht({point:e,element:t,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))},ls=(e,t,n,i,o,r,s=!0)=>{if(cp(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;if(s){let E=xp(t,n,o,r);if(E)return E}let[a,l]=Ep(n,o),d=R.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o);if(e.points.length===2){let E=i==="start"?e.endBinding:e.startBinding,x=E&&o.get(E.elementId),b=E&&x&&_e(He(E.fixedPoint),x,o);b&&(d=b)}let c=fp(rs(Rl(t,d),2*Kn(d,t)+Math.max(Kn(a[0],a[1]),Kn(l[0],l[1]))),d),u=De(c,d),m=kl(a,u),p=kl(l,u),h=m&&Kn(d,m),f=p&&Kn(d,p),g=null;return h!=null&&f!=null?g=h<f?m:p:g=m||p||null,g&&it(g,n,o)?g:null};I();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Hp,ARROW_LABEL_WIDTH_FRACTION as Wp,BOUND_TEXT_PADDING as Wt,DEFAULT_FONT_SIZE as Up,TEXT_ALIGN as $l,VERTICAL_ALIGN as Vl,getFontString as Uo,isProdEnv as Yp,invariant as Xp}from"@excalidraw/common";import{pointFrom as Zl,pointRotateRads as jp}from"@excalidraw/math";I();var Zi={},Hl=(e,t)=>{let n=Zi[e]||(Zi[e]={height:t});return n.height=t,n},Wl=e=>{Zi[e]&&delete Zi[e]},O0=e=>Zi[e]?.height??null;I();import{BOUND_TEXT_PADDING as zo,DEFAULT_FONT_SIZE as bp,DEFAULT_FONT_FAMILY as wp,getFontString as yp,isTestEnv as Pp,normalizeEOL as Ip}from"@excalidraw/common";var ft=(e,t,n)=>{let i=e.split(`
|
|
2
2
|
`).map(a=>a||" ").join(`
|
|
3
|
-
`),o=parseFloat(t),r=
|
|
4
|
-
`),e,t).width+
|
|
5
|
-
`),
|
|
6
|
-
`),
|
|
7
|
-
`).map(n=>{let i=t,o=i+n.length;return t=o+1,{text:n,start:i,end:o}})},
|
|
8
|
-
`))
|
|
3
|
+
`),o=parseFloat(t),r=Sp(i,o,n);return{width:jl(i,t),height:r}},Ul="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),Yl=(e,t)=>{let n=Mp(e);return n===0?ft(Ul.split("").join(`
|
|
4
|
+
`),e,t).width+zo*2:n+zo*2},_o=(e,t)=>ft("",e,t).width+zo*2,z0=()=>jl(Ul,yp({fontSize:bp,fontFamily:wp}))>0,Ki=e=>Ip(e).replace(/\t/g," "),cs=e=>Ki(e).split(`
|
|
5
|
+
`),_0=e=>{let t=cs(e.text).length;return e.height/t/e.fontSize},Ho=(e,t)=>e*t,Xl=(e,t)=>Ho(e,t)+zo*2,Ro,H0=e=>{Ro=e},ds=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 Pp()?r*10:r}},Sn=(e,t)=>(Ro||(Ro=new ds),Ro.getLineWidth(e,t)),jl=(e,t)=>{let n=cs(e),i=0;return n.forEach(o=>{i=Math.max(i,Sn(o,t))}),i},Sp=(e,t,n)=>{let i=cs(e).length;return Ho(t,n)*i},hi=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=Sn(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),W0=e=>{let t=hi.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},Mp=e=>{let t=hi.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};I();import{isDevEnv as Ap,isTestEnv as Tp}from"@excalidraw/common";var us,Wo,ms,$0=e=>(us||(us=de.class(...Object.values(rn))),us.test(e)),Dp=()=>{if(!Wo)try{Wo=Bp()}catch{Wo=vp()}return Wo},ps=()=>(ms||(ms=Lp()),ms),yt={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},rn={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},qn={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},vp=()=>de.or(ps(),Se.On(yt.HYPHEN,yt.WHITESPACE,rn.CHAR)),Bp=()=>de.or(ps(),Se.Before(yt.WHITESPACE).Build(),Se.After(yt.WHITESPACE,yt.HYPHEN).Build(),Se.Before(rn.CHAR,rn.CURRENCY).NotPrecededBy(yt.OPENING,rn.OPENING).Build(),Se.After(rn.CHAR).NotFollowedBy(yt.HYPHEN,yt.CLOSING,rn.CLOSING).Build(),Se.BeforeMany(rn.OPENING).NotPrecededBy(yt.OPENING).Build(),Se.AfterMany(rn.CLOSING).NotFollowedBy(yt.CLOSING).Build(),Se.AfterMany(yt.CLOSING).FollowedBy(yt.OPENING).Build()),Lp=()=>de.group(de.or(qn.FLAG,de.and(qn.MOST,qn.JOINER,de.build(`(?:${qn.ZWJ.source}(?:${qn.FLAG.source}|${qn.ANY.source}${qn.JOINER.source}))*`)))),de={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>de.build(de.join(...e)),or:(...e)=>de.build(e.map(t=>t.source).join("|")),group:(...e)=>de.build(`(${de.join(...e)})`),class:(...e)=>de.build(`[${de.join(...e)}]`)},Se={On:(...e)=>{let t=de.join(...e);return de.build(`([${t}])`)},Before:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?=[${t}])`);return Se.Chain(n)},After:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<=[${t}])`);return Se.Chain(n)},BeforeMany:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<![${t}])(?=[${t}])`);return Se.Chain(n)},AfterMany:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<=[${t}])(?![${t}])`);return Se.Chain(n)},NotBefore:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?![${t}])`);return Se.Chain(n)},NotAfter:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<![${t}])`);return Se.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=Se.After(...t).Build(),o=()=>de.and(i,n);return Se.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=Se.Before(...t).Build(),o=()=>de.and(n,i);return Se.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=Se.NotAfter(...t).Build(),o=()=>de.and(i,n);return Se.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=Se.NotBefore(...t).Build(),o=()=>de.and(n,i);return Se.Chain(o)}})},Cp=e=>{let t=Dp();return e.normalize("NFC").split(t).filter(Boolean)},sn=(e,t,n)=>kp(e,t,n).map(i=>i.text).join(`
|
|
6
|
+
`),Gp=e=>{let t=0;return e.split(`
|
|
7
|
+
`).map(n=>{let i=t,o=i+n.length;return t=o+1,{text:n,start:i,end:o}})},kp=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return Gp(e);let i=[],o=0;for(let r of e.split(`
|
|
8
|
+
`))Sn(r,t)<=n?i.push({text:r,start:o,end:o+r.length}):i.push(...Op(r,t,n,o)),o+=r.length+1;return i},Op=(e,t,n,i)=>{let o=[],r=Cp(e),s="",a=i,l=i,d=0,c=i,u=0;for(;u<r.length;){let m=r[u],p=c,h=p+m.length,f=s+m,g=zp(m)?d+hi.calculate(m,t):Sn(f,t);if(/\s/.test(m)||g<=n){s||(a=p),s=f,l=h,d=g,c=h,u++;continue}if(s)o.push(Rp(s,a,l)),s="",a=p,l=p,d=0;else{let E=Np(m,t,n,p),x=E[E.length-1]??{text:"",start:p,end:p},b=E.slice(0,-1);o.push(...b),s=x.text,a=x.start,l=x.end,d=Sn(x.text,t),c=h,u++}}if(s){let m=Fp(s,a,l,t,n);o.push(m)}return o},Np=(e,t,n,i)=>{if(ps().test(e))return[{text:e,start:i,end:i+e.length}];_p(e);let o=[],r=Array.from(e),s="",a=i,l=i,d=0,c=i;for(let u of r){let m=c,p=m+u.length,h=hi.calculate(u,t),f=d+h;if(f<=n){s||(a=m),s=s+u,l=p,d=f,c=p;continue}s&&o.push({text:s,start:a,end:l}),s=u,a=m,l=p,d=h,c=p}return s&&o.push({text:s,start:a,end:l}),o},Fp=(e,t,n,i,o)=>{if(!(Sn(e,i)>o))return{text:e,start:t,end:n};let[,s,a]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],l=Sn(s,i);for(let d of Array.from(a)){let c=hi.calculate(d,i),u=l+c;if(u>o)break;s=s+d,l=u}return{text:s,start:t,end:n-(e.length-s.length)}},Rp=(e,t,n)=>{let i=e.trimEnd();return{text:i,start:t,end:n-(e.length-i.length)}},zp=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,_p=e=>{if((Tp()||Ap())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var Yo=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;Yp()||Xp(!t||!U(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?U(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?vt(t,e):e.width,r.text=sn(e.originalText,Uo(e),o));let s=ft(r.text,Uo(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=Qi(t,e),l=vt(t,e);if(!U(t)&&s.height>a){let m=fs(s.height,t.type);n.mutateElement(t,{height:m}),Hl(t.id,m)}if(s.width>l){let m=fs(s.width,t.type);n.mutateElement(t,{width:m})}let d={...e,...r},{x:c,y:u}=qi(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},Qn=(e,t,n,i=!1,o=!1)=>{let r=t.getNonDeletedElementsMap();if(!Bt(e))return;Wl(e.id);let a=re(e,r);if(a&&a.text){if(!e)return;let l=a.text,d=a.height,c=a.width,u=vt(e,a),m=Qi(e,a),p=e.height;if(i||n!=="n"&&n!=="s"){l&&(l=sn(a.originalText,Uo(a),u));let h=ft(l,Uo(a),a.lineHeight);d=h.height,c=h.width}if(d>m){p=fs(d,e.type);let h=p-e.height,f=n==="n"||n==="ne"||n==="nw",g=0;U(e)||(o?g=h/2:f&&(g=h)),t.mutateElement(e,{height:p,y:e.y-g})}t.mutateElement(a,{text:l,width:c,height:d}),U(e)||t.mutateElement(a,qi(e,a,r))}},qi=(e,t,n)=>{if(U(e))return R.getBoundTextElementPosition(e,t,n);let i=hs(e),o=Qi(e,t),r=vt(e,t),s,a;t.verticalAlign===Vl.TOP?a=i.y:t.verticalAlign===Vl.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===$l.LEFT?s=i.x:t.textAlign===$l.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=Zl(i.x+r/2,i.y+o/2),c=Zl(s+t.width/2,a+t.height/2),[u,m]=jp(c,d,l);return{x:u-t.width/2,y:m-t.height/2}}return{x:s,y:a}},Bt=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,re=(e,t)=>{if(!e)return null;let n=Bt(e);if(n){let i=t.get(n)||null;return i&&!Ve(i)&&console.error("[NONDELETED][INVARIANT] Bound text element `isDeleted: true` which is not expected."),i}return null},We=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,oP=(e,t)=>{if(!U(e))return{x:e.x+e.width/2,y:e.y+e.height/2};let n=R.getBoundTextElementCenter(e,t);return{x:n[0],y:n[1]}},hs=e=>{let t=Wt,n=Wt;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}},rP=(e,t)=>U(t)?0:t?t.angle:e.angle,sP=(e,t,n)=>{if(U(e))return R.getBoundTextElementPosition(e,t,n)},aP=(e,t)=>e.some(n=>{if(Ie(n)){let i=We(n,t);return!U(i)}return!1}),lP=(e,t)=>e.some(n=>{if(Ie(n)){let i=We(n,t);return!U(i)}return oe(n)}),$p=new Set(["rectangle","ellipse","diamond","arrow"]),dP=e=>$p.has(e.type),fs=(e,t)=>{e=Math.ceil(e);let n=Wt*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},vt=(e,t)=>{let{width:n}=e;if(U(e)){let i=(t?.fontSize??Up)*Hp;return Math.max(Wp*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-Wt*2:e.type==="diamond"?Math.round(n/2)-Wt*2:n-Wt*2},Qi=(e,t)=>{let{height:n}=e;return U(e)?n-Wt*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-Wt*2:e.type==="diamond"?Math.round(n/2)-Wt*2:n-Wt*2},cP=(e,t=`
|
|
9
9
|
|
|
10
|
-
`)=>e.reduce((i,o)=>(K(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as _r,distanceToLineSegment as Ur,pointRotateRads as Wr}from"@excalidraw/math";import{ellipse as jm,ellipseDistanceFromPoint as Xm}from"@excalidraw/math/ellipse";var cn=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return $m(e,t,n);case"diamond":return Vm(e,t,n);case"ellipse":return Zm(e,t,n);case"line":case"arrow":case"freedraw":return qm(e,t,n)}},$m=(e,t,n)=>{let i=re(e,t),o=Wr(n,i,-e.angle),[r,s]=sn(e);return Math.min(...r.map(a=>Ur(o,a)),...s.map(a=>_r(a,o)).filter(a=>a!==null))},Vm=(e,t,n)=>{let i=re(e,t),o=Wr(n,i,-e.angle),[r,s]=an(e);return Math.min(...r.map(a=>Ur(o,a)),...s.map(a=>_r(a,o)).filter(a=>a!==null))},Zm=(e,t,n)=>{let i=re(e,t);return Xm(Wr(n,i,-e.angle),jm(i,e.width/2,e.height/2))},qm=(e,t,n)=>{let[i,o]=bo(e,t);return Math.min(...i.map(r=>Ur(n,r)),...o.map(r=>_r(r,n)))};P();var Yr=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",Xw=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable",$w=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",Vw=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Zw=e=>e==="freedraw",gl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",qw=e=>e==="arrow",Kw=e=>e==="arrow";var To=e=>{if(e.type==="arrow")return!1;let t=Yr(e.type)&&!Il(e.backgroundColor)||wt(e)||Eo(e)||K(e);return e.type==="line"?t&&Nn(e.points):e.type==="freedraw"?t&&Nn(e.points):t||Me(e)},jr=null,El=null,xl=1/0,bl=!1,wl=!1,yt=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(jr&&Al(e,jr)&&xl<=n&&r===wl){let u=El?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return bl}let s=o?Xr(we(o.x-n,o.y-n),e,we(o.x+o.width+n,o.y+o.height+n)):!1,a=ae(t,i,!0);if(!Tl(e,a,t.angle,n)&&!s)return!1;let c=(r||To(t))&&Nt(e,t,i)||yl(e,t,i,n)||s;return jr=e,El=new WeakRef(t),xl=n,wl=r,bl=c,c},Tl=(e,t,n,i=0)=>{let o=n===0?e:Je(e,un(t),-n);return Xr(we(t[0]-i,t[1]-i),o,we(t[2]+i,t[3]+i))},ip=(e,t,n,i=0)=>{let o=ae(t,n,!0);return Tl(e,o,t.angle,i)},my=(e,t)=>!yt(e)&&!op(e.point,e.element,t)&&ip(e.point,e.element,t),op=(e,t,n)=>{let i=V(t,n);if(!i)return!1;let o=Q(t)?{...i,...G.getBoundTextElementPosition(t,i,n)}:i;return Nt(e,o,n)},vl=(e,[t,n],i,o=0)=>{let r=we(t,n),s=!q(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=ae(e,i);if(!Wt(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&q(m)){let p=ae(m,i);if(!St(r,p))return!1}}let c=It(e,i,ki(re(e,i),r)),u=cn(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},vo=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(Pl(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),fe(s,!1)&&vl(s,e,n,i)&&(o.push(s),Yr(s.type)&&!Il(s.backgroundColor)))break}return o},Ut=(e,t,n,i)=>{let o=vo(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()},Dl=(e,t,n,i,o)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];Pl(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),fe(l,!1)&&vl(l,e,i,o)&&r.push(l)}if(!r||r.length===0)return null;if(r.length===1)return r[0];let s=r.filter(a=>cn(a,i,e)<=ke(a,t)||Nt(e,a,i));return s.length===0?null:s[0]},It=(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(!Wt(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return sp(e,t,n,i,o);case"diamond":return ap(e,t,n,i,o);case"ellipse":return lp(e,t,n,i);case"line":case"freedraw":case"arrow":return rp(e,n,t,o)}},Bl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Do(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(!Wt(a,l))continue;let d=Sl(s,t);if(d.length>0){for(let c of d)n.push(Je(c,i,o));if(r)return n}}return n},Ll=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Ml(s,t);if(a&&(n.push(Je(a,i,o)),r))return n}return n},rp=(e,t,n,i=!1)=>{let[o,r]=bo(e,n),s=[];for(let a of o){let l=Ml(a,t);if(l&&(s.push(l),i))return s}for(let a of r){let l=Do(a[0],a[1],a[2],a[3]),d=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!Wt(l,d))continue;let c=Sl(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),i))return s}return s},sp=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=Je(n[0],r,-e.angle),a=Je(n[1],r,-e.angle),l=ki(s,a),[d,c]=sn(e,i),u=[];return Ll(d,l,u,r,e.angle,o),o&&u.length>0||Bl(c,l,u,r,e.angle,o),u},ap=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=Je(n[0],r,-e.angle),a=Je(n[1],r,-e.angle),l=ki(s,a),[d,c]=an(e,i),u=[];return Ll(d,l,u,r,e.angle,o),o&&u.length>0||Bl(c,l,u,r,e.angle,o),u},lp=(e,t,n,i=0)=>{let o=re(e,t),r=Je(n[0],o,-e.angle),s=Je(n[1],o,-e.angle);return np(tp(o,e.width/2+i,e.height/2+i),ki(r,s)).map(a=>Je(a,o,e.angle))},yl=(e,t,n,i=1)=>cn(t,n,e)<=i,Nt=(e,t,n)=>{if((Q(t)||Ie(t))&&!Nn(t.points))return!1;let[i,o,r,s]=ae(t,n);if(!Xr(we(i,o),e,we(r,s)))return!1;let a=we((i+r)/2,(o+s)/2),l=Km(ep(Jm(Qm(e,a,.1)),Math.max(t.width,t.height)*2),a),d=ki(e,l);return It(t,n,d).filter((u,m,p)=>p.findIndex(h=>Al(h,u))===m).length%2===1},$r=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:m}=s,p=re(s,n);if(s.type==="diamond"){let[f,g,E,x,b,y,w,S]=ii(s);return[we(l+f,d+g-a),we(l+E+a,d+x),we(l+b,d+y+a),we(l+w-a,d+S)].map(A=>Je(A,p,m))}if(s.type==="ellipse"){let f=l+c/2,g=d+u/2,E=c/2,x=u/2;return[we(f,g-x-a),we(f+E+a,g),we(f,g+x+a),we(f-E-a,g)].map(y=>Je(y,p,m))}return[we(l-a,d-a),we(l+c+a,d-a),we(l+c+a,d+u+a),we(l-a,d+u+a)].map(f=>Je(f,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Nt(s,t,n))};P();import{invariant as Cl,isDevEnv as dp,isTestEnv as cp}from"@excalidraw/common";import{pointFrom as mn,pointFromVector as Bo,pointRotateRads as Lo,pointScaleFromOrigin as Co,pointsEqual as up,triangleIncludesPoint as Vr,vectorCross as We,vectorFromPoint as J,vectorScale as Go}from"@excalidraw/math";var xe=[1,0],Ae=[0,1],je=[-1,0],et=[0,-1],Yt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?xe:t<=-o?je:n>i?Ae:et},Ye=(e,t)=>Yt(J(e,t)),pt=(e,t)=>Xe(Ye(e,t)),Ee=(e,t)=>e[0]===t[0]&&e[1]===t[1],Xe=e=>Ee(e,xe)||Ee(e,je),xy=e=>!Xe(e),mp=(e,t,n)=>{let i=un(t);(dp()||cp())&&(Cl(e.width>0&&e.height>0,"Diamond element has no width or height"),Cl(!up(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Bo(Go(J(Lo(mn(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Bo(Go(J(Lo(mn(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Bo(Go(J(Lo(mn(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Bo(Go(J(Lo(mn(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(We(J(n,r),J(r,s))<=0&&We(J(n,r),J(r,l))>0)return Ye(r,i);if(We(J(n,s),J(s,a))<=0&&We(J(n,s),J(s,r))>0)return Ye(s,i);if(We(J(n,a),J(a,l))<=0&&We(J(n,a),J(a,s))>0)return Ye(a,i);if(We(J(n,l),J(l,r))<=0&&We(J(n,l),J(l,a))>0)return Ye(l,i);if(We(J(n,i),J(r,i))<=0&&We(J(n,i),J(s,i))>0){let c=e.width>e.height?r:s;return Ye(c,i)}else if(We(J(n,i),J(s,i))<=0&&We(J(n,i),J(a,i))>0){let c=e.width>e.height?a:s;return Ye(c,i)}else if(We(J(n,i),J(a,i))<=0&&We(J(n,i),J(l,i))>0){let c=e.width>e.height?a:l;return Ye(c,i)}let d=e.width>e.height?r:l;return Ye(d,i)},Fi=(e,t,n)=>{let o=un(t);if(e.type==="diamond")return mp(e,t,n);let r=Co(mn(t[0],t[1]),o,2),s=Co(mn(t[2],t[1]),o,2),a=Co(mn(t[0],t[3]),o,2),l=Co(mn(t[2],t[3]),o,2);return Vr([r,s,o],n)?et:Vr([s,l,o],n)?xe:Vr([l,a,o],n)?Ae:je},Zr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Bp,randomInteger as ss,getUpdatedTimestamp as as}from"@excalidraw/common";P();import{clamp as Oo,pointDistance as Qr,pointFrom as X,pointScaleFromOrigin as pp,pointsEqual as Ni,pointTranslate as Kr,vector as Mt,vectorCross as ko,vectorFromPoint as Jr,vectorScale as fp}from"@excalidraw/math";import{BinaryHeap as hp,invariant as ri,isAnyTrue as gp,getSizeFromPoints as Gl,isDevEnv as Ep,arrayToMap as xp}from"@excalidraw/common";var es=1,ne=40,bp=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>X(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=Ye(s,l[a-1]),c=Ye(l[a-1],l[a-2]);if(Ee(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=X(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(Qr(l[a-2],l[a-1])<es){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=pt(s,l[a-1]);return o.push(X(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?jt(is(os(ns(e,ts(e,t,o.map(s=>X(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(Ep()&&ri(Hl(o),"Invalid elbow points with fixed segments"),jt(o,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},wp=(e,t,n)=>{let i=t.map(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:h,startGlobalPoint:f,endGlobalPoint:g,hoveredStartElement:E,hoveredEndElement:x,...b}=ts({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[X(0,0),X(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:y}=jt(is(os(ns(e,{startHeading:p,endHeading:h,startGlobalPoint:f,endGlobalPoint:g,hoveredStartElement:E,hoveredEndElement:x,...b})??[])),t,null,null);if(!y||y.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let w=[];if(a)for(let M=0;M<a.index;M++)w.push(X(e.x+e.points[M][0],e.y+e.points[M][1]));if(y.forEach(M=>{w.push(X(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++)w.push(X(e.x+e.points[M][0],e.y+e.points[M][1]));let S=(l?.index??e.points.length)-(a?.index??0)-1,I=t.map(M=>M.index>s?{...M,index:M.index-S+(y.length-1)}:M),A=w.flatMap((M,L)=>{let C=w[L-1],O=w[L+1];if(C&&O){let v=Ye(M,C),Y=Ye(O,M);if(Ee(v,Y))return I.forEach(H=>{H.index>L&&(H.index-=1)}),[];if(Ee(v,Zr(Y)))return I.forEach(H=>{H.index>L&&(H.index+=1)}),[M,M]}return[M]});return jt(A,I,!1,!1)},yp=(e,t,n,i,o,r)=>{let s=t.map((w,S)=>e.fixedSegments==null||e.fixedSegments[S]===void 0||e.fixedSegments[S].index!==w.index||(w.start[0]!==e.fixedSegments[S].start[0]&&w.end[0]!==e.fixedSegments[S].end[0])!=(w.start[1]!==e.fixedSegments[S].start[1]&&w.end[1]!==e.fixedSegments[S].end[1])?S:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,d=Qr(t[s].start,t[s].end),c=d<ne+5;if(a===-1&&t[s].index===1&&o){let w=Xe(n),I=(w?Ee(n,xe):Ee(n,Ae))?c?d/2:ne:c?-d/2:-ne;t[s].start=X(t[s].start[0]+(w?I:0),t[s].start[1]+(w?0:I))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=Xe(i),I=(w?Ee(i,xe):Ee(i,Ae))?c?d/2:ne:c?-d/2:-ne;t[s].end=X(t[s].end[0]+(w?I:0),t[s].end[1]+(w?0:I))}let u=t.map(w=>({...w,start:X(e.x+w.start[0],e.y+w.start[1]),end:X(e.x+w.end[0],e.y+w.end[1])})),m=e.points.map((w,S)=>X(e.x+w[0],e.y+w[1])),p=u[s].index-1,h=u[s].index,f=u[s].start,g=u[s].end,E=m[p-1]&&!Ni(m[p],m[p-1])?pt(m[p-1],m[p]):void 0,x=m[h+1]&&!Ni(m[h],m[h+1])?pt(m[h+1],m[h]):void 0;if(E!==void 0){let w=E?1:0;m[p-1][w]=f[w]}if(m[p]=f,m[h]=g,x!==void 0){let w=x?1:0;m[h+1][w]=g[w]}let b=u.findIndex(w=>w.index===p);if(b!==-1){let w=pt(u[b].end,u[b].start)?1:0;u[b].start[w]=f[w],u[b].end=f}let y=u.findIndex(w=>w.index===h+1);if(y!==-1){let w=pt(u[y].end,u[y].start)?1:0;u[y].end[w]=g[w],u[y].start=g}if(a===-1&&p===0){let w=o?Xe(n):pt(m[1],m[0]);m.unshift(X(w?f[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:f[1])),o&&m.unshift(X(e.x+e.points[0][0],e.y+e.points[0][1]));for(let S of u)S.index+=o?2:1}if(l===-1&&h===e.points.length-1){let w=Xe(i);m.push(X(w?g[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:g[1])),r&&m.push(X(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return jt(m,u.map(w=>({...w,start:X(w.start[0]-e.x,w.start[1]-e.y),end:X(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},Pp=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((g,E)=>E===0?X(e.x+g[0],e.y+g[1]):E===t.length-1?X(e.x+g[0],e.y+g[1]):X(e.x+e.points[E][0],e.y+e.points[E][1])),m=n.map(g=>({...g,start:X(e.x+(g.start[0]-t[0][0]),e.y+(g.start[1]-t[0][1])),end:X(e.x+(g.end[0]-t[0][0]),e.y+(g.end[1]-t[0][1]))})),p=[],h=2+(d?1:0),f=2+(c?1:0);for(;p.length+h<u.length-f;)p.push(u[p.length+h]);{let g=u.at(d?2:1),E=u.at(d?3:2);if(!g||!E)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=Xe(i),b=Xe(Yt(Jr(g,E)));if(a&&x===b){let y=x?Ee(i,xe):Ee(i,Ae);if(p.unshift(X(b?r[0]+(y?ne:-ne):E[0],b?E[1]:r[1]+(y?ne:-ne))),p.unshift(X(x?r[0]+(y?ne:-ne):r[0],x?r[1]:r[1]+(y?ne:-ne))),!d){d=!0;for(let w of m)w.index>1&&(w.index+=1)}}else if(p.unshift(X(b?r[0]:g[0],b?g[1]:r[1])),d){d=!1;for(let y of m)y.index>1&&(y.index-=1)}p.unshift(r)}{let g=u.at(u.length-(c?3:2)),E=u.at(u.length-(c?4:3));if(!g||!E)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=Xe(o),b=pt(E,g);if(l&&x===b){let y=x?Ee(o,xe):Ee(o,Ae);p.push(X(b?s[0]+(y?ne:-ne):E[0],b?E[1]:s[1]+(y?ne:-ne))),p.push(X(x?s[0]+(y?ne:-ne):s[0],x?s[1]:s[1]+(y?ne:-ne))),c||(c=!0)}else p.push(X(b?s[0]:g[0],b?g[1]:s[1])),c&&(c=!1)}return p.push(s),jt(p,m.map(({index:g})=>({index:g,start:p[g-1],end:p[g]})).map(g=>({...g,start:X(g.start[0]-r[0],g.start[1]-r[1]),end:X(g.end[0]-r[0],g.end[1]-r[1])})),d,c)},pn=1e6,si=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};B.PROD||(ri(!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)"),ri(!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"),ri(!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"),ri(e.points.slice(1).map((w,S)=>w[0]===e.points[S][0]||w[1]===e.points[S][1]),"Elbow arrow segments must be either horizontal or vertical"),ri(n.fixedSegments?.find(w=>w.index===1&&Ni(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&Ni(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let o=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,S)=>S===0?n.points[0]:S===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&Ro(d.elementId,t),m=c&&Ro(c.elementId,t),p=Hl(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 jt(r.map(w=>X(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y}=ts({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?jt(r.map(w=>X(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?bp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,S)=>Ni(w,e.points[S]??X(1/0,1/0)))&&p?{}:o.length===0?jt(is(os(ns(e,{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?wp(e,o,t):n.points?n.points&&n.fixedSegments?n:Pp(e,r,o,h,f,g,E,x,b):yp(e,o,h,f,x,b)},ts=(e,t,n,i)=>{let o=Kr(n[0],Mt(e.x,e.y)),r=Kr(n[n.length-1],Mt(e.x,e.y)),s=null,a=null;if(i?.isDragging&&i?.isBindingEnabled!==!1){let w=Array.from(t.values());s=Rl(o,t,w,i?.zoom)||null,a=Rl(r,t,w,i?.zoom)||null}else s=e.startBinding&&Ro(e.startBinding.elementId,t)||null,a=e.endBinding&&Ro(e.endBinding.elementId,t)||null;let l=kl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),d=kl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=Fl(l,d,s,o,t,i?.zoom),u=Fl(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],h=s?st(s,t,fn(c,e.startArrowhead?ke(s,{elbowed:!0})*6:ke(s,{elbowed:!0})*2,1)):m,f=a?st(a,t,fn(u,e.endArrowhead?ke(a,{elbowed:!0})*6:ke(a,{elbowed:!0})*2,1)):p,g=St(l,a?st(a,t,fn(u,ne,ne)):p)||St(d,s?st(s,t,fn(c,ne,ne)):m),E=zl(g?[m,p]:[h,f]),x=Mp(g?m:h,g?p:f,E,g?fn(c,!s&&!a?0:ne,0):fn(c,!s&&!a?0:ne-(e.startArrowhead?_n*6:_n*2),ne),g?fn(u,!s&&!a?0:ne,0):fn(u,!s&&!a?0:ne-(e.endArrowhead?_n*6:_n*2),ne),g,s&&st(s,t),a&&st(a,t)),b=Ol(x[0],c,l),y=Ol(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:b,startGlobalPoint:l,startHeading:c,endDonglePosition:y,endGlobalPoint:d,endHeading:u,commonBounds:E,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:g,startElementBounds:h,endElementBounds:f}},ns=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Ap(n,i||o,r,s||a,l,d),m=i&&Fo(i,u),p=s&&Fo(s,u),h=Fo(a,u);h&&c&&(h.closed=!0);let f=Fo(o,u);f&&e.startBinding&&(f.closed=!0);let g=m&&p&&(St(m.pos,n[1])||St(p.pos,n[0])),E=Ip(m||f,p||h,u,r||xe,l||xe,g?[]:n);if(E){let x=E.map(b=>[b.pos[0],b.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},fn=(e,t,n)=>{switch(e){case et:return[t,n,n,n];case xe:return[n,t,n,n];case Ae:return[n,n,t,n]}return[n,n,n,t]},Ip=(e,t,n,i,o,r)=>{let s=qr(e.pos,t.pos),a=new hp(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Sp(e,l);l.closed=!0;let d=vp(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=pp(u.pos,l.pos,.5);if(gp(...r.map(y=>St(m,y))))continue;let p=Dp(c),h=l.parent?Yt(Jr(l.pos,l.parent.pos)):i,f=Zr(h);if(Ee(f,p)||Nl(e.addr,u.addr)&&Ee(p,i)||Nl(t.addr,u.addr)&&Ee(p,o))continue;let E=h!==p,x=l.g+qr(u.pos,l.pos)+(E?Math.pow(s,3):0),b=u.visited;if(!b||x<u.g){let y=Tp(u,t,p,o);u.visited=!0,u.parent=l,u.h=qr(t.pos,u.pos)+y*Math.pow(s,2),u.g=x,u.f=u.g+u.h,b?a.rescoreElement(u):a.push(u)}}}return null},Sp=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},qr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Mp=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,m,p]=i??[0,0,0,0],[h,f,g,E]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-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],b=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-E):(d[0]+l[2])/2:t[0]>e[0]?t[0]-E:n[0]-E,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-h):(d[1]+l[3])/2:t[1]>e[1]?t[1]-h:n[1]-h,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+f):(d[2]+l[0])/2:t[2]<e[2]?t[2]+f:n[2]+f,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+g):(d[3]+l[1])/2:t[3]<e[3]?t[3]+g:n[3]+g],y=zl([x,b]);if(!r&&x[2]-x[0]+b[2]-b[0]>y[2]-y[0]+1e-11&&x[3]-x[1]+b[3]-b[1]>y[3]-y[1]+1e-11){let[w,S]=[(b[0]+b[2])/2,(b[1]+b[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let I=x[2]+(b[0]-x[2])/2,A=b[3]+(x[1]-b[3])/2;return ko(Mt(e[2]-w,e[1]-S),Mt(e[0]-w,e[3]-S))>0?[[x[0],x[1],I,x[3]],[I,b[1],b[2],b[3]]]:[[x[0],A,x[2],x[3]],[b[0],b[1],b[2],A]]}else if(e[2]<t[0]&&e[3]<t[1]){let I=x[2]+(b[0]-x[2])/2,A=x[3]+(b[1]-x[3])/2;return ko(Mt(e[0]-w,e[1]-S),Mt(e[2]-w,e[3]-S))>0?[[x[0],x[1],x[2],A],[b[0],A,b[2],b[3]]]:[[x[0],x[1],I,x[3]],[I,b[1],b[2],b[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let I=b[2]+(x[0]-b[2])/2,A=x[3]+(b[1]-x[3])/2;return ko(Mt(e[2]-w,e[1]-S),Mt(e[0]-w,e[3]-S))>0?[[I,x[1],x[2],x[3]],[b[0],b[1],I,b[3]]]:[[x[0],x[1],x[2],A],[b[0],A,b[2],b[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let I=b[2]+(x[0]-b[2])/2,A=b[3]+(x[1]-b[3])/2;return ko(Mt(e[0]-w,e[1]-S),Mt(e[2]-w,e[3]-S))>0?[[I,x[1],x[2],x[3]],[b[0],b[1],I,b[3]]]:[[x[0],A,x[2],x[3]],[b[0],b[1],b[2],A]]}}return[x,b]},Ap=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===je||n===xe?a.add(t[1]):s.add(t[0]),o===je||o===xe?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]})))}},Ol=(e,t,n)=>{switch(t){case et:return X(n[0],e[1]);case xe:return X(e[2],n[1]);case Ae:return X(n[0],e[3])}return X(e[0],n[1])},Tp=(e,t,n,i)=>{if(i===xe)switch(n){case xe:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case et:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Ae:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case je:return e.pos[1]===t.pos[1]?4:2}else if(i===je)switch(n){case xe:return e.pos[1]===t.pos[1]?4:2;case et:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Ae:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case je:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===et)switch(n){case xe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case et:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Ae:return e.pos[0]===t.pos[0]?4:2;case je:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===Ae)switch(n){case xe:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case et:return e.pos[0]===t.pos[0]?4:2;case Ae:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case je:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},vp=([e,t],n)=>[Ri([e,t-1],n),Ri([e+1,t],n),Ri([e,t+1],n),Ri([e-1,t],n)],Ri=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Fo=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=Ri([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},zl=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]))],Ro=(e,t)=>{let n=t.get(e);return n&&fe(n)?n:null},jt=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>Kr(a,fp(Jr(e[0]),-1)));return(o<-pn||o>pn||r<-pn||r>pn||o+s[s.length-1][0]<-pn||o+s[s.length-1][0]>pn||r+s[s.length-1][1]<-pn||r+s[s.length-1][1]>pn)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...Gl(s)}),s=s.map(([a,l])=>X(Oo(a,-1e6,1e6),Oo(l,-1e6,1e6))),{points:s,x:Oo(o,-1e6,1e6),y:Oo(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Gl(s),startIsSpecial:n,endIsSpecial:i}},is=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},os=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Qr(i,t)>es}):e,Dp=e=>{switch(e){case 0:return et;case 1:return xe;case 2:return Ae}return je},kl=(e,t,n,i,o,r,s,a=!0,l=!0)=>s?a&&o&&r?rs(e,o,t,r,void 0,l):i:o?Ue(n||[0,0],o,r??xp([o])):i,Fl=(e,t,n,i,o,r)=>_l(e,t,n,n&&st(n,o,Array(4).fill(cn(n,o,e))),i,o,r),Rl=(e,t,n,i)=>Ut(e,n,t,ut(i)),Nl=(e,t)=>e[0]===t[0]&&e[1]===t[1],Hl=(e,t=es)=>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 Te=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;W(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...si({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Bp(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 h=c[p],f=u[p];if(h[0]!==f[0]||h[1]!==f[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")&&tt.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??ss(),e.updated=as()),e},Fe=(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??ss(),updated:as()}},Ul=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=ss(),e.updated=as(),e);var Vl=5,_n=5,Op=10,Ui=10/1.5,ke=(e,t)=>(t.elbowed?_n:Vl)+e.strokeWidth/2,ut=e=>{let t=Math.max(Vl,15),n=e?.value&&e.value<1?e.value:1;return ds(t/(n*1.5),t,t*2)},At=e=>e.isBindingEnabled,kp=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=cs(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0});if(Wl(e,a,"start",o,r.isBindingEnabled),Wl(e,l,"end",o,r.isBindingEnabled),a.focusPoint||l.focusPoint){let d=new Map;a.focusPoint&&d.set(0,{point:ft(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&d.set(e.points.length-1,{point:ft(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),G.movePoints(e,o,d)}return{start:a,end:l}},Wl=(e,{mode:t,element:n,focusPoint:i},o,r,s=!0)=>{t===null?Ge(e,o,r):t!==void 0&&Tt(e,n,t,o,r,i,s)},Zl=(e,t,n,i,o)=>{$t(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;$t(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=G.getPointGlobalCoordinates(e,a,n),d=Ut(l,i,n,ut(o)),c=d?{element:d,mode:"orbit",focusPoint:G.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},Fp=(e,t,n,i,o,r,s,a,l,d,c)=>{let u={mode:void 0},m={mode:void 0},p=e.points.length>2,h=G.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),f=Ut(h,i,n);if(o)return f?u={element:f,mode:"inside",focusPoint:h}:u={mode:null},{start:u,end:m};if(r){let g=l?.selectedLinearElement?.initialState.origin;if(f&&e.startBinding?.elementId===f.id){let E=ie(f.x+f.width/2,f.y+f.height/2);return{start:p?{mode:void 0}:{mode:"inside",element:f,focusPoint:g??E},end:p?{mode:"orbit",element:f,focusPoint:h}:{mode:"inside",element:f,focusPoint:h}}}if(f&&e.startBinding){let E=e.startBinding;if(vo(h,i,n).find(b=>b.id===E.elementId)){let b=n.get(e.startBinding.elementId);return $t(b,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:b.id!==f.id?"orbit":"inside",element:b,focusPoint:g??ie(e.x,e.y)},end:{mode:"orbit",element:f,focusPoint:h}}}}if(e.startBinding&&e.startBinding.elementId!==f?.id){let E=n.get(e.startBinding.elementId);$t(E,"Other element must be in the elements map");let b={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:E,focusPoint:c?re(E,n):g??ie(e.x,e.y)},y=f&&$r(E,f,n),w;if(f){let S=d==="inside"||d==="skip";w={mode:S&&!y?"inside":"orbit",element:f,focusPoint:h}}else w={mode:null};return{start:p?{mode:void 0}:b,end:w}}if(!e.startBinding)return f?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:f,focusPoint:h}:m={mode:null},{start:u,end:m}}$t(!1,"New arrow creation should not reach here")},Yl=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=Ut(e,o,i),m=n?vo(e,o,i).some(g=>g.id===n.elementId):!1,p=n?i.get(n.elementId):null,h=m&&p?Cp(p.backgroundColor):!1,f=u&&p&&$r(p,u,i);return r==="inside"||r==="skip"?(l=u?{element:!m||!p||h?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&&!h?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}},cs=(e,t,n,i,o,r,s,a)=>Lp("COMPLEX_BINDINGS")?Rp(e,t,o,r,s,a):ql(e,t,n,i,o,r,s,a),ql=(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(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!c&&!u)return{start:m,end:p};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!At(s))return m=c?{mode:null}:m,p=u?{mode:null}:p,{start:m,end:p};if(W(e))return Zl(e,t,o,r,a?.zoom);let h=c?e.endBinding:e.startBinding,f=t.get(c?0:d)?.point;$t(f,`Local point must be defined for ${c?"start":"end"} dragging`);let g=G.getPointGlobalCoordinates(e,f,o),E=Ut(g,r,o,ut(s.zoom)),x=E&&(a?.angleLocked?Nt(ie(n,i),E,o):Nt(g,E,o)),b=h?o.get(h.elementId):void 0,y=h&&b&&Ue(h.fixedPoint,b,o),w=b&&y&&yt({point:y,element:b,elementsMap:o,threshold:0,overrideShouldTestInside:!0});if(h&&h.elementId===E?.id&&(!a?.newArrow||s.selectedLinearElement?.initialState.origin))return{start:{mode:"inside",element:E,focusPoint:c?g:a?.newArrow?s.selectedLinearElement.initialState.origin:G.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:E,focusPoint:u?g:G.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?E?{mode:"inside",element:E,focusPoint:g}:{mode:null}:m,end:u?E?{mode:"inside",element:E,focusPoint:g}:{mode:null}:p};let S=E?x?{mode:"inside",element:E,focusPoint:g}:{mode:"orbit",element:E,focusPoint:Gr(e,g,E,c?"start":"end",o,s.zoom,s.isMidpointSnappingEnabled)||g}:{mode:null},I=G.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),A=y&&b&&yt({point:g,element:b,elementsMap:o,threshold:ut(s.zoom),overrideShouldTestInside:!0}),L=(a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:h?.mode==="inside")?{mode:void 0}:b&&!w&&!A&&s.selectedLinearElement?.initialState.altFocusPoint?{mode:"orbit",element:b,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&b?{mode:"orbit",element:b,focusPoint:Gr(e,I,b,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||I}:{mode:void 0};return{start:c?S:L,end:u?S:L}},Rp=(e,t,n,i,o,r)=>{let s=o.bindMode||"orbit",a=0,l=e.points.length-1,d=t.has(a),c=t.has(l),u={mode:void 0},m={mode:void 0};if(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!d&&!c)return{start:u,end:m};if(d&&c)return{start:{mode:null},end:{mode:null}};if(!At(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(W(e))return Zl(e,t,n,i);if(r?.newArrow){let{start:p,end:h}=Fp(e,t,n,i,d,c,a,l,o,s,r?.shiftKey);return{start:p,end:h}}if(d){let p=t.get(a)?.point;$t(p,"Local point must be defined for start dragging");let h=G.getPointGlobalCoordinates(e,p,n),{current:f,other:g}=Yl(h,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:f,end:g}}if(c){let p=t.get(l)?.point;$t(p,"Local point must be defined for end dragging");let h=G.getPointGlobalCoordinates(e,p,n),{current:f,other:g}=Yl(h,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:g,end:f}}return{start:u,end:m}},qy=(e,t,n)=>{e.forEach(i=>{kp(i,new Map,1/0,1/0,t,n)})},Tt=(e,t,n,i,o,r,s=!0)=>{let a=o.getNonDeletedElementsMap(),l;W(e)?l={elementId:t.id,mode:"orbit",...Wp(e,t,i,a,s)}:l={elementId:t.id,mode:n,...ai(e,t,i,a,r)},o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:l}),$l(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Ge=(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},Oe=(e,t,n)=>{if(!fe(e))return;let{simultaneouslyUpdated:i}=n??{},o=zp(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),_o(r,e,a=>{if(!_(a)||a.isDeleted||!Np(a,e))return;let l=a.startBinding?r.get(a.startBinding.elementId):null,d=a.endBinding?l?.id===a.endBinding.elementId?l:r.get(a.endBinding.elementId):null;if(o.has(a.id))return;let c=Uo(r,a,(m,p)=>{if(m&&fe(m)&&(p==="startBinding"||p==="endBinding")&&(e.id===a[p]?.elementId||e.id===a[p==="startBinding"?"endBinding":"startBinding"]?.elementId)){let h=ft(a,p,a[p],m,r);if(h)return[p==="startBinding"?0:a.points.length-1,{point:h}]}return null}).filter(m=>m!==null);G.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=V(a,r);u&&!u.isDeleted&&Hn(a,t,!1)})},jl=(e,t,n,i,o)=>{$t(!W(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=G.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&yt({element:s,point:a,elementsMap:n,threshold:ut(o.zoom)}),d=t==="startBinding"?"start":"end";if(Ge(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],m=ql(e,new Map([[c,{point:u}]]),a[0],a[1],n,i.getNonDeletedElements(),o);m[d]&&m[d].element?.id===s.id&&m[d].mode&&Tt(e,s,m[d].mode,d,i,m[d].focusPoint)}},Ky=(e,t,n,i)=>{if(_(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&jl(e,"startBinding",o,t,n),e.endBinding&&jl(e,"endBinding",o,t,n)}else Oe(e,t,{...i,changedElements:new Map([[e.id,e]])})},Np=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,zp=e=>new Set((e||[]).map(t=>t.id)),_l=(e,t,n,i,o,r,s)=>{let a=Yt(zi(t,e));return!n||!i?a:Hp(o,n,r,s)?Fi(n,i,e):Yt(zi(e,re(n,r)))},Hp=(e,t,n,i)=>{let o=cn(t,n,e),r=ut(i);return o>r?null:o},rs=(e,t,n,i,o,r=!0)=>{let s=W(e),a=G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return a;let l=Za(t)&&s?_p(e,t,i,a):a,d=o&&!s?o[1]:G.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),c=ke(t,e),u=st(t,i),m=un(u),p=null;if(s){let h=Xe(Fi(t,u,a)),g=(r?us(t,i,l,.05,e):void 0)||a,E=ie(h?m[0]:g[0],h?g[1]:m[1]),x=o??Ho(E,No(zo(ls(zi(g,E)),Math.max(t.width,t.height)*2),E));if(p=It(t,i,x,c).sort(Xt)[0],!p){let b=ie(h?g[0]:m[0],h?m[1]:g[1]),y=Ho(b,No(zo(ls(zi(g,b)),Math.max(t.width,t.height)*2),b));p=It(t,i,y,_n).sort(Xt)[0]}}else{let h=o;if(!h){let f=zo(ls(zi(l,d)),hn(l,d)+Math.max(t.width,t.height)+c*2);h=o??Ho(No(f,d),No(zo(f,-1),d))}p=hn(l,d)<1?l:It(t,i,h,c).sort((f,g)=>Xt(f,d)-Xt(g,d))[0]}return!p||Xt(l,p)<_i?l:p},_p=(e,t,n,i)=>{let o=re(t,n),r=le(i,o,-t.angle),s=ke(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?le(ie(t.x-s,t.y),o,t.angle):le(ie(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?le(ie(t.x,t.y+t.height+s),o,t.angle):le(ie(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?le(ie(t.x+t.width,t.y+t.height+s),o,t.angle):le(ie(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?le(ie(t.x+t.width,t.y-s),o,t.angle):le(ie(t.x+t.width+s,t.y),o,t.angle):i},us=(e,t,n,i=.05,o)=>{let{x:r,y:s,width:a,height:l,angle:d}=e,c=re(e,t,-.1,-.1),u=le(n,c,-d),m=o?ke(e,o):0,p=ds(i*l,5,80),h=ds(i*a,5,80);if(!(hn(c,u)<m)){if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return le(ie(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-h&&u[0]<c[0]+h)return le(ie(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return le(ie(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-h&&u[0]<c[0]+h)return le(ie(c[0],s+l+m),c,d);if(e.type==="diamond"){let f=m,g=ie(r+a/4-f,s+l/4-f),E=ie(r+3*a/4+f,s+l/4-f),x=ie(r+a/4-f,s+3*l/4+f),b=ie(r+3*a/4+f,s+3*l/4+f);if(hn(g,u)<Math.max(h,p))return le(g,c,d);if(hn(E,u)<Math.max(h,p))return le(E,c,d);if(hn(x,u)<Math.max(h,p))return le(x,c,d);if(hn(b,u)<Math.max(h,p))return le(b,c,d)}}},Up=(e,t,n)=>{let i=e[t];if(!i)return{element:null,fixedPoint:null,focusPoint:null,binding:i,mode:null};let o=n.get(i.elementId);return{element:o,fixedPoint:i.fixedPoint,focusPoint:Ue(ln(i.fixedPoint),o,n),binding:i,mode:i.mode}},Xl=e=>e.width*e.height,ft=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||Gp(e.points[e.points.length-1],ie(0,0)))return null;let s=Ue(ln(n.fixedPoint),i,o);if(n.mode==="inside")return G.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=Up(e,t==="startBinding"?"endBinding":"startBinding",o),d=G.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&Ho(s,c),m=a&&u&&It(a,o,u,ke(a,e)).sort((b,y)=>Xt(b,s)-Xt(y,s))[0],p=u&&It(i,o,u,ke(i,e)).sort((b,y)=>Xt(b,c)-Xt(y,c))[0],h=e.startArrowhead!==null,f=e.endArrowhead!==null,g=!h&&!f||t==="startBinding"&&h||t==="endBinding"&&f?s:p||s;if(a&&p&&!r&&Xl(a)<Xl(i)*2&&yt({element:a,point:p,elementsMap:o,threshold:ke(a,e),overrideShouldTestInside:!0}))return G.createPointAt(e,o,g[0],g[1],null);let x=hn(a&&(m||l)||d,p||s)<=Op;return a?x?G.createPointAt(e,o,g?.[0]||s[0],g?.[1]||s[1],null):G.createPointAt(e,o,p?.[0]||s[0],p?.[1]||s[1],null):G.createPointAt(e,o,x?s[0]:p?.[0]??s[0],x?s[1]:p?.[1]??s[1],null)},Wp=(e,t,n,i,o=!0,r=!0)=>{let s=[t.x,t.y,t.x+t.width,t.y+t.height],a=o?rs(e,t,n,i,void 0,r):G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),l=ie(s[0]+(s[2]-s[0])/2,s[1]+(s[3]-s[1])/2),d=le(a,l,-t.angle);return{fixedPoint:ln([(d[0]-t.x)/Math.max(t.width,_i),(d[1]-t.y)/Math.max(t.height,_i)])}},ai=(e,t,n,i,o)=>{let r=o||G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=re(t,i),a=le(r,s,-t.angle),l=(a[0]-t.x)/Math.max(t.width,_i),d=(a[1]-t.y)/Math.max(t.height,_i);return{fixedPoint:ln([l,d])}},Kl=(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})}W(i)&&Object.assign(i,si(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},Qy=(e,t)=>{let n=$l(e);for(let i of t)gn.unbindAffected(n,i,(o,r)=>Te(o,n,r)),En.unbindAffected(n,i,(o,r)=>Te(o,n,r))},Hi=(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},Ql=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),_o=(e,t,n)=>{fe(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},Uo=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(he(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(_(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},gn=class{static unbindAffected(t,n,i){n&&Uo(t,n,o=>{!o||o.isDeleted||_o(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:Hi(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||Uo(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(_(n)&&i(o,{boundElements:Hi(o.boundElements,new Set,new Array(n))}),K(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:Hi(o.boundElements,new Set,new Array(n))}))))})}},En=class{static unbindAffected(t,n,i){n&&_o(t,n,o=>{!o||o.isDeleted||Uo(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||_o(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:Hi(n.boundElements,new Set([s]))});return}K(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:Hi(n.boundElements,new Set([o.id]))})))})}},Ue=(e,t,n)=>{let[i,o]=ln(e);return le(ie(t.x+t.width*i,t.y+t.height*o),re(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?Ue(e.startBinding.fixedPoint,n,t):ie(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?Ue(e.endBinding.fixedPoint,i,t):ie(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},Jl=(e,t)=>{let[n,i]=Yp(e,t);return[G.pointFromAbsoluteCoords(e,n,t),G.pointFromAbsoluteCoords(e,i,t)]},jp=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),ln=e=>{if(!jp(e))return[.5001,.5001];let t=1e-4;return Math.abs(e[0]-.5)<t||Math.abs(e[1]-.5)<t?e.map(n=>Math.abs(n-.5)<t?.5001:n):e},Xp=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",$p={rectangle:[{centerAngle:0,sectorWidth:75,side:"right"},{centerAngle:45,sectorWidth:15,side:"bottom-right"},{centerAngle:90,sectorWidth:75,side:"bottom"},{centerAngle:135,sectorWidth:15,side:"bottom-left"},{centerAngle:180,sectorWidth:75,side:"left"},{centerAngle:225,sectorWidth:15,side:"top-left"},{centerAngle:270,sectorWidth:75,side:"top"},{centerAngle:315,sectorWidth:15,side:"top-right"}],diamond:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}],ellipse:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}]},Vp=e=>e.map((t,n)=>{let i=t.sectorWidth/2,o=t.centerAngle-i,r=t.centerAngle+i;return o=(o%360+360)%360,r=(r%360+360)%360,{start:o,end:r,side:t.side}}),Zp=(e,t)=>{let[n,i]=e,o=n-.5,r=i-.5,s=Math.atan2(r,o);s<0&&(s+=2*Math.PI);let a=s*180/Math.PI,l=$p[t],d=Vp(l);for(let m of d)if(m.start<=m.end){if(a>=m.start&&a<=m.end)return m.side}else if(a>=m.start||a<=m.end)return m.side;let c=1/0,u=l[0].side;for(let m of l){let p=Math.abs(a-m.centerAngle);p>180&&(p=360-p),p<c&&(c=p,u=m.side)}return u},Jy=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!fe(n))return null;let i=re(n,t),o=Xp(n),r=Zp(ln(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=an(n),[d,c,u,m]=a,p,h;switch(r){case"left":{if(l.length>=3){let g=l[2][1];p=g[0]-s,h=g[1]}else{let f=Ce(c[1],u[0]);p=f[0]-s,h=f[1]}break}case"right":{if(l.length>=1){let g=l[0][1];p=g[0]+s,h=g[1]}else{let f=Ce(m[1],d[0]);p=f[0]+s,h=f[1]}break}case"top":{if(l.length>=4){let g=l[3][1];p=g[0],h=g[1]-s}else{let f=Ce(u[1],m[0]);p=f[0],h=f[1]-s}break}case"bottom":{if(l.length>=2){let g=l[1][1];p=g[0],h=g[1]+s}else{let f=Ce(d[1],c[0]);p=f[0],h=f[1]+s}break}case"top-right":{let f=Ce(m[0],m[1]);p=f[0]+s*.707,h=f[1]-s*.707;break}case"bottom-right":{let f=Ce(d[0],d[1]);p=f[0]+s*.707,h=f[1]+s*.707;break}case"bottom-left":{let f=Ce(c[0],c[1]);p=f[0]-s*.707,h=f[1]+s*.707;break}case"top-left":{let f=Ce(u[0],u[1]);p=f[0]-s*.707,h=f[1]-s*.707;break}default:return null}return le(ie(p,h),i,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,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,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h+s*.707,m=l+f-s*.707;break}case"bottom-right":{let p=Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h+s*.707,m=l+f+s*.707;break}case"bottom-left":{let p=3*Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h-s*.707,m=l+f+s*.707;break}case"top-left":{let p=-3*Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h-s*.707,m=l+f-s*.707;break}default:return null}return le(ie(u,m),i,n.angle)}if(Di(n)){let[a,l]=sn(n),[d,c,u,m]=a,p,h;switch(r){case"top":{let f=Ce(d[0],d[1]);p=f[0],h=f[1]-s;break}case"right":{let f=Ce(c[0],c[1]);p=f[0]+s,h=f[1];break}case"bottom":{let f=Ce(u[0],u[1]);p=f[0],h=f[1]+s;break}case"left":{let f=Ce(m[0],m[1]);p=f[0]-s,h=f[1];break}case"top-left":{if(l.length>=1){let f=l[0],g=f[0],E=f[3],x=Ce(g,E);p=x[0]-s*.707,h=x[1]-s*.707}else p=n.x-s,h=n.y-s;break}case"top-right":{if(l.length>=2){let f=l[1],g=f[0],E=f[3],x=Ce(g,E);p=x[0]+s*.707,h=x[1]-s*.707}else p=n.x+n.width+s,h=n.y-s;break}case"bottom-right":{if(l.length>=3){let f=l[2],g=f[0],E=f[3],x=Ce(g,E);p=x[0]+s*.707,h=x[1]+s*.707}else p=n.x+n.width+s,h=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let f=l[3],g=f[0],E=f[3],x=Ce(g,E);p=x[0]-s*.707,h=x[1]+s*.707}else p=n.x-s,h=n.y+n.height+s;break}default:return null}return le(ie(p,h),i,n.angle)}return null},Ce=(e,t)=>ie((e[0]+t[0])/2,(e[1]+t[1])/2);var ms=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>k(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},G=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;hoveredFocusPointBinding;draggedFocusPointBinding;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,i=!1){this.elementId=t.id,td(t.points[0],k(0,0))||(console.error("Linear element is not normalized",Error().stack),Te(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=W(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,m]=$(n.selectionElement,o),h=e.getPointsGlobalCoordinates(l,o).reduce((f,g,E)=>((g[0]>=d&&g[0]<=u&&g[1]>=c&&g[1]<=m||t.shiftKey&&s?.includes(E))&&f.push(E),f),[]).filter(f=>!(W(l)&&f!==0&&f!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:h.length?h:null}})}static handlePointerMove(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);$e(d,"Element being dragged must exist in the scene"),$e(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??ld(m,d.points[c]),h=0,f=0;if(Wi(t)){let[w,S]=e._getShiftLockedDelta(d,s,m,k(i,o),t[Un.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),I=k(w+m[0],S+m[1]);h=I[0]-u[0],f=I[1]-u[1]}else{let w=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Un.CTRL_OR_CMD]?null:n.getEffectiveGridSize());h=w[0]-u[0],f=w[1]-u[1]}let g=null,{positions:E,updates:x}=ad([c],h,f,i,o,s,d,a,n,Wi(t),t.altKey,r);if(e.movePoints(d,n.scene,E,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled}),Be(d,!1)&&At(n.state)&&(g=x?.suggestedBinding??null),Be(d)&&rd(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!g||ef(n.state.suggestedBinding??[],g)))return null;let b=Be(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:p,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&b&&x?.suggestedBinding?.element.id!==b.id?sd(d,k(d.x,d.y),b,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled):r.initialState.altFocusPoint}},suggestedBinding:g}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);$e(p,"Element being dragged must exist in the scene"),$e(p.points.length>1,"Element must have at least 2 points"),$e(u,"There must be selected points in order to drag them"),l&&u.some((T,R)=>T>0&&T!==p.points.length-1?(u[R]=p.points.length-1,m=p.points.length-1,!0):!1),(m<0||!u.includes(m)||!p.points[m])&&(console.error(`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${p.points.length-1}) lastClickedPoint(${m}) isElbowArrow: ${l}`),m=p.points.length-1);let h=p.points[m],f=p.points[m===0?1:m-1],g=u.length===1,E=r.customLineAngle??ld(f,p.points[m]),x=u.includes(0),b=u.includes(p.points.length-1),y=0,w=0;if(Wi(t)&&g){let[T,R]=e._getShiftLockedDelta(p,s,f,k(i,o),t[Un.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),E),U=k(T+f[0],R+f[1]);y=U[0]-h[0],w=U[1]-h[1]}else{let T=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Un.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=T[0]-h[0],w=T[1]-h[1]}let S=null,{positions:I,updates:A}=ad(u,y,w,i,o,s,p,a,n,Wi(t)&&g,t.altKey,r);e.movePoints(p,n.scene,I,{startBinding:A?.startBinding,endBinding:A?.endBinding,moveMidPointsWithElement:A?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled}),Be(p,!1)&&At(n.state)&&(x||b)&&(S=A?.suggestedBinding??null),Be(p)&&x!==b&&rd(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),V(p,s)&&Hn(p,n.scene,!1);let L=l?b?[p.points.length-1]:[0]:u,C=l?L[0]:m,O=!x&&!b?e.getPointGlobalCoordinates(p,h,s):null,v=C,Y=Be(p)&&p.startBinding&&s.get(p.startBinding.elementId),H=Be(p)&&p.endBinding&&s.get(p.endBinding.elementId),Z=b&&Y&&A?.suggestedBinding?.element.id!==Y.id?Y:x&&H&&A?.suggestedBinding?.element.id!==H.id?H:null;return{selectedLinearElement:{...r,selectedPointsIndices:L,initialState:{...r.initialState,lastClickedPoint:C,altFocusPoint:!r.initialState.altFocusPoint&&Be(p)&&Z?sd(p,k(p.x,p.y),Z,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:O,hoverPointIndex:v,isDragging:!0,customLineAngle:E},suggestedBinding:S}}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),{elementId:s,selectedPointsIndices:a,isDragging:l,initialState:d}=n,c=e.getElement(s,r);if(!c)return n;if(l&&a)for(let u of a)(u===0||u===c.points.length-1)&&tf(c.points,i.zoom.value)&&(kt(c)&&o.mutateElement(c,{...dd(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,o,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1}}}static getEditorMidPoints=(t,n,i)=>{let o=V(t,n);if(!W(t)&&!i.selectedLinearElement?.isEditing&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom,n)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1,n);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!W(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!W(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Wn(k(c[0],c[1]),k(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&Wn(m[u],k(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r,s){if(W(t))return o>=0&&o<t.points.length?Wn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=Wn(n,i);if(t.points.length>2&&t.roundness){let[l,d]=id(t,s);$e(l.length===0&&d.length>0,"Only linears built out of curves are supported"),$e(l.length+d.length>=o,"Invalid segment index while calculating mid point"),a=Kp(d[o])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,i){if(W(t)){$e(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=ed(t.points[n-1],t.points[n]);return k(t.x+s[0],t.y+s[1])}let[o,r]=id(t,i);if($e(o.length===0&&r.length>0||o.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),$e(o.length+r.length>=n,"Invalid segment index while calculating mid point"),o.length){let s=o[n-1];return ed(s[0],s[1])}if(r.length){let s=r[n-1];return Qp(s,.5)}$e(!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=k(o.x,o.y),h=null;if(m)h=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[Un.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:h,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 f=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y);(f>=0||m)&&(d.hitElement=u);let[g,E,x,b]=$(u,l),y=(g+x)/2,w=(E+b)/2,S=f>-1&&Re(k(u.x+u.points[f][0],u.y+u.points[f][1]),k(y,w),u.angle),I=f>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(f)?nf([...r.selectedPointsIndices||[],f]):[f]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:f,origin:p,segmentMidpoint:{value:m,index:h,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:I,pointerOffset:S?{x:o.x-S[0],y:o.y-S[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:td(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(Wi(t)&&c.length>=2){let p=c[c.length-2],[h,f]=e._getShiftLockedDelta(d,l,p,k(n,i),t[Un.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=k(h+p[0],f+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[Un.CTRL_OR_CMD]||W(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:m}]])):e.addPoints(d,o.scene,[m]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=$(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Re(k(c+n[0],u+n[1]),k(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=$(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return Re(k(c+d[0],u+d[1]),k(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=$(t,i),a=k(r,s),l=t.points[o],{x:d,y:c}=t;return l?Re(k(d+l[0],c+l[1]),a,t.angle):Re(k(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(W(t))return k(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=$(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=Re(k(n[0],n[1]),k(l,d),-t.angle);return k(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(Wn(k(o,r),k(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=nd(i,o,r),[a,l,d,c]=$(t,n),u=(a+d)/2,m=(l+c)/2,[p,h]=Re(k(s[0],s[1]),k(u,m),-t.angle);return k(p-t.x,h-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=ms(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){$e(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);$e(s,"The linear element does not exist in the provided Scene"),$e(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((m,p,h)=>{if(++c,m.push(p),o.includes(h)){let g=a[h+1];g||(d=!0),m.push(g?k((p[0]+g[0])/2,(p[1]+g[1])/2):k(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:k(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));kt(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=k(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=ms({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];kt(t)&&t.polygon&&(o[0]=k(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=ms({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o,r){let{points:s}=t;if(kt(t)&&t.polygon){let u=i.get(0),m=i.get(s.length-1);u?i.set(s.length-1,{point:k(u.point[0],u.point[1]),isDragging:u.isDragging}):m&&i.set(0,{point:k(m.point[0],m.point[1]),isDragging:m.isDragging})}let a=i.get(0)?.point??k(0,0),[l,d]=a,c=W(t)?[i.get(0)?.point??s[0],i.get(s.length-1)?.point??s[s.length-1]]:s.map((u,m)=>{let p=i.get(m)?.point??u;return o?.moveMidPointsWithElement&&m!==0&&m!==s.length-1&&!i.has(m)?p:k(p[0]-l,p[1]-d)});e._updatePoints(t,n,c,l,d,o,{isDragging:Array.from(i.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&W(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=Wn(a,k(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<Jp/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!W(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(W(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=ps(t,i),d=ps(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,h=m-c,f=p-u,g=Re(k(o,r),k(h,f),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+g[0],y:t.y+g[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(W(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=nd(o[0],o[1],r),{width:c,height:u}=cd(a[0],a[1],l,d,s);return Re(k(c,u),k(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&Te(n,i,{isDeleted:!0});let r=0,s=0;if(t.points.length%2===1){let a=Math.floor(t.points.length/2),l=e.getPointGlobalCoordinates(t,t.points[a],i);r=l[0]-n.width/2,s=l[1]-n.height/2}else{let a=t.points.length/2-1,l=e.getSegmentMidPoint(t,a+1,i);r=l[0]-n.width/2,s=l[1]-n.height/2}return{x:r,y:s}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:m}=e.getBoundTextElementPosition(t,o,n),p=u+o.width,h=m+o.height,f=k(d,c),g=Re(k(r,s),f,t.angle),E=Re(k(a,s),f,t.angle),x=Re(k(u,m),f,-t.angle),b=Re(k(p,m),f,-t.angle),y=Re(k(u,h),f,-t.angle),w=Re(k(p,h),f,-t.angle);return g[0]<E[0]&&g[1]>=E[1]?(r=Math.min(r,y[0]),a=Math.max(a,Math.max(b[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):g[0]>=E[0]&&g[1]>E[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],b[0])),s=Math.min(s,y[1]),l=Math.max(l,b[1])):g[0]>=E[0]?(r=Math.min(r,b[0]),a=Math.max(a,y[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):g[1]<=E[1]&&(r=Math.min(r,Math.min(b[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,b[1]),l=Math.max(l,y[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=tt.generateElementShape(t,null),r=Gt(o[0]),[s,a,l,d]=Yi(r),c=s+t.x,u=a+t.y,m=l+t.x,p=d+t.y,h=(c+m)/2,f=(u+p)/2,g=i&&V(t,n);return g?e.getMinMaxXYWithBoundText(t,n,[c,u,m,p],g):[c,u,m,p,h,f]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!W(a))return t;if(n&&n>0&&n<a.points.length){let l=Xe(Yt(qp(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,h)=>(p[h.index]=h,p),{});d[n]={index:n,start:k(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:k(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((p,h)=>p.index-h.index),u=c.map(p=>p.index).reduce((p,h)=>h<n?p+1:p,0);r.mutateElement(a,{fixedSegments:c});let m=k(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:m,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:m}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},nf=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},ad=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let m=new Map(e.map(H=>{let Z=s.points[H]??s.points.at(-1);return[H,{point:k(Z[0]+t,Z[1]+n),isDragging:!0}]}));if(!_(s))return{positions:m};let p=e.includes(0),h=e.includes(s.points.length-1),{start:f,end:g}=cs(s,m,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c});if(W(s)){let H=p?f.element:h?g.element:null;return{positions:m,updates:{suggestedBinding:H?{element:H,midPoint:l.state.isMidpointSnappingEnabled?us(H,r,k(i-u.pointerOffset.x,o-u.pointerOffset.y)):void 0}:null}}}if(!p&&!h){let H={...s,points:s.points.map((F,T)=>m.get(T)?.point??F)},Z=new Map(m);if(s.startBinding){let F=r.get(s.startBinding.elementId);if(F){let T=ft(H,"startBinding",s.startBinding,F,r)??null;T&&Z.set(0,{point:T,isDragging:!0})}}if(s.endBinding){let F=r.get(s.endBinding.elementId);if(F){let T=ft(H,"endBinding",s.endBinding,F,r)??null;T&&Z.set(s.points.length-1,{point:T,isDragging:!0})}}return{positions:Z}}if(p===h)return{positions:m};let E={suggestedBinding:null};f.mode===null?E.startBinding=null:f.mode?(E.startBinding={elementId:f.element.id,mode:f.mode,...ai(s,f.element,"start",r,f.focusPoint)},p&&(E.startBinding.mode==="orbit"||!li("COMPLEX_BINDINGS"))&&(E.suggestedBinding=f.element?{element:f.element,midPoint:od(k(i-u.pointerOffset.x,o-u.pointerOffset.y),f.element,r,l.state.zoom)}:null)):p&&(E.suggestedBinding=l.state.suggestedBinding),g.mode===null?E.endBinding=null:g.mode?(E.endBinding={elementId:g.element.id,mode:g.mode,...ai(s,g.element,"end",r,g.focusPoint)},h&&(E.endBinding.mode==="orbit"||!li("COMPLEX_BINDINGS"))&&(E.suggestedBinding=g.element?{element:g.element,midPoint:od(k(i-u.pointerOffset.x,o-u.pointerOffset.y),g.element,r,l.state.zoom)}:null)):h&&(E.suggestedBinding=l.state.suggestedBinding);let x=p?k(s.points[0][0]+t,s.points[0][1]+n):s.points[0],b=h?k(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],y={...s,points:[x,...s.points.slice(1,-1),b],startBinding:E.startBinding===void 0?s.startBinding:E.startBinding===null?null:E.startBinding,endBinding:E.endBinding===void 0?s.endBinding:E.endBinding===null?null:E.endBinding},w=s.endBinding&&y.startBinding&&p&&y.startBinding.elementId===s.endBinding.elementId,S=s.startBinding&&y.endBinding&&h&&s.startBinding.elementId===y.endBinding.elementId,I=y.endBinding?g.element??r.get(y.endBinding.elementId):null,A=w?y.points[y.points.length-1]:S&&l.state.bindMode!=="inside"&&li("COMPLEX_BINDINGS")?y.points[0]:I&&ft(y,"endBinding",y.endBinding,I,r,h)||y.points[y.points.length-1];y.points[y.points.length-1]=A;let M=y.startBinding?f.element??r.get(y.startBinding.elementId):null,L=S&&li("COMPLEX_BINDINGS")?y.points[0]:w&&l.state.bindMode!=="inside"&&li("COMPLEX_BINDINGS")?A:M&&ft(y,"startBinding",y.startBinding,M,r,p)||y.points[0],C=!w&&!(S&&l.state.bindMode!=="inside"&&li("COMPLEX_BINDINGS"))&&!!I,O=Wn(L,y.points[0])!==0,v=new Set(e);M&&O&&v.add(0),I&&C&&v.add(s.points.length-1);let Y=Array.from(v);return{updates:E,positions:new Map(Y.map(H=>[H,H===0?{point:L,isDragging:!0}:H===s.points.length-1?{point:A,isDragging:!0}:m.get(H)]))}},ld=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);P();import{arrayToMap as ht}from"@excalidraw/common";import{isPointWithinBounds as bf,pointFrom as ws,segmentsIntersectAt as wf}from"@excalidraw/math";P();import{arrayToMap as df,isShallowEqual as cf}from"@excalidraw/common";P();var of=(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}}},ud=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 h=p.indexOf(a.editingGroupId);h>-1&&(p=p.slice(0,h))}if(p.length>0){let h=p[p.length-1];d[h]=!0}}let c={},u=s.reduce((m,p)=>{if(p.isDeleted)return m;let h=p.groupIds.find(f=>d[f]);return h&&(m[p.id]=!0,Array.isArray(c[h])?c[h].push(p.id):c[h]=[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:fs({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):vt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:fs(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),rf=(e,t)=>hs(e,t)!=null,hs=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),sf=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),md=(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,...of(r,n,e)}}}return n.selectedGroupIds},w0=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),af=(e,t)=>e.groupIds.includes(t),Ne=(e,t)=>{let n=[];for(let i of e.values())af(i,t)&&n.push(i);return n},lf=(e,t)=>e.groupIds.find(n=>t[n]),y0=(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},P0=(e,t)=>e.filter(n=>!t[n]),I0=(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())},pd=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},fd=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},hd=e=>e.groupIds.length>0,gd=(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},Wo=(e,t,n)=>{let i=sf(n),o=e.filter(u=>!he(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)||[],h=V(u,t);h&&p.push(h),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=>rf(n,u));return o.forEach(u=>{let m=lf(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 uf=e=>e.locked||he(e),mf=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),pf=e=>{let t=new Set;return e.forEach(n=>{q(n)&&t.add(n.id)}),mf(e,t)},Ed=(e,t,n,i=!0,o="contain")=>{let[r,s,a,l]=$(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),m=Math.max(s,l);return xd({elements:e,bounds:[d,c,u,m],elementsMap:n,type:o,shouldIgnoreElementFromSelection:uf,excludeElementsInFrames:i})},G0=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=bd(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},O0=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}(),vt=(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&&he(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{q(s)&&xn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},k0=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:vt(e,t,{includeBoundTextElement:!0}),fs=(e,t)=>cf(t.selectedElementIds,e)?t.selectedElementIds:e,ff=(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 G(i,df(t))}return null},F0=(e,t,n)=>({selectedLinearElement:ff(e,t),...ud({editingGroupId:n.editingGroupId,selectedElementIds:pf(e).reduce((i,o)=>(he(o)||(i[o.id]=!0),i),{})},t,n,null)}),R0=(e,t)=>t.editingTextElement||e.length===1&&K(e[0])&&e[0]||null;P();import{arrayToMap as Yo}from"@excalidraw/common";import{validateOrderKey as hf,generateNKeysBetween as gf}from"@excalidraw/fractional-indexing";var gs=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Ef=(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(Es(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&wt(e[l])){let m=e[l],p=V(m,Yo(e));p&&p.index<=m.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(p)}", "${s(m)}"`)}}if(r.length){let l=new gs,d=[];if(o&&(d.push("Additional reconciliation context:"),d.push(o.localElements.map(c=>s(c))),d.push(o.remoteElements.map(c=>s(c)))),i||console.error(r.join(`
|
|
10
|
+
`)=>e.reduce((i,o)=>(oe(o)&&i.push(o.text),i),[]).join(t),Kl=.5;I();import{curvePointDistance as gs,distanceToLineSegment as Es,pointRotateRads as xs}from"@excalidraw/math";import{ellipse as Vp,ellipseDistanceFromPoint as Zp}from"@excalidraw/math/ellipse";var Ut=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return Kp(e,t,n);case"diamond":return qp(e,t,n);case"ellipse":return Qp(e,t,n);case"line":case"arrow":case"freedraw":return Jp(e,t,n)}},Kp=(e,t,n)=>{let i=se(e,t),o=xs(n,i,-e.angle),[r,s]=Pn(e);return Math.min(...r.map(a=>Es(o,a)),...s.map(a=>gs(a,o)))},qp=(e,t,n)=>{let i=se(e,t),o=xs(n,i,-e.angle),[r,s]=In(e);return Math.min(...r.map(a=>Es(o,a)),...s.map(a=>gs(a,o)))},Qp=(e,t,n)=>{let i=se(e,t);return Zp(xs(n,i,-e.angle),Vp(i,e.width/2,e.height/2))},Jp=(e,t,n)=>{let[i,o]=Vi(e,t);return Math.min(...i.map(r=>Es(n,r)),...o.map(r=>gs(r,n)))};I();var gi=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw"||e==="autoshape"||e==="bucketfill",bP=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable"||e==="autoshape",wP=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="autoshape",yP=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line"||e==="autoshape",PP=e=>e==="freedraw",ql=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",IP=e=>e==="arrow",SP=e=>e==="arrow";var Xo=e=>{if(e.type==="arrow")return!1;let t=gi(e.type)&&!id(e.backgroundColor)||_t(e)||Oo(e)||oe(e);return e.type==="line"?t&&Tt(e.points):e.type==="freedraw"?t&&Tt(e.points):t||ke(e)},bs=null,Ql=null,ws=1/0,ys=!1,Jl=!1,ed=null,af=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,Ht=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(bs&&sd(e,bs)&&(ys?ws<=n:ws>=n)&&r===Jl&&af(o,ed)){let u=Ql?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return ys}let s=o?Ps(ve(o.x-n,o.y-n),e,ve(o.x+o.width+n,o.y+o.height+n)):!1,a=ue(t,i,!0);if(!ad(e,a,t.angle,n)&&!s)return!1;let c=(r||Xo(t))&&it(e,t,i)||td(e,t,i,n)||s;return bs=e,Ql=new WeakRef(t),ws=n,Jl=r,ed=o,ys=c,c},ad=(e,t,n,i=0)=>{let o=n===0?e:ht(e,ln(t),-n);return Ps(ve(t[0]-i,t[1]-i),o,ve(t[2]+i,t[3]+i))},lf=(e,t,n,i=0)=>{let o=ue(t,n,!0);return ad(e,o,t.angle,i)},zP=(e,t)=>!Ht(e)&&!df(e.point,e.element,t)&&lf(e.point,e.element,t),df=(e,t,n)=>{let i=re(t,n);if(!i)return!1;let o=K(t)?{...i,...R.getBoundTextElementPosition(t,i,n)}:i;return it(e,o,n)},ld=(e,[t,n],i,o=0)=>{let r=ve(t,n),s=!J(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=ue(e,i);if(!gt(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&J(m)){let p=ue(m,i);if(!Yt(r,p))return!1}}let c=ot(e,i,Ji(se(e,i),r)),u=Ut(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},jo=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(nd(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),we(s,!1)&&ld(s,e,n,i)&&(o.push(s),gi(s.type)&&!id(s.backgroundColor)))break}return o},an=(e,t,n,i)=>{let o=jo(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()},dd=(e,t,n,i,o)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];nd(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),we(l,!1)&&ld(l,e,i,o)&&r.push(l)}if(!r||r.length===0)return null;if(r.length===1)return r[0];let s=r.filter(a=>Ut(a,i,e)<=Be(a,t)||it(e,a,i));return s.length===0?null:s[0]},ot=(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=ue(e,t);if(!gt(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return uf(e,t,n,i,o);case"diamond":return mf(e,t,n,i,o);case"ellipse":return pf(e,t,n,i);case"line":case"freedraw":case"arrow":return cf(e,n,t,o)}},cd=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=$o(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(!gt(a,l))continue;let d=od(s,t);if(d.length>0){for(let c of d)n.push(ht(c,i,o));if(r)return n}}return n},ud=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=rd(s,t);if(a&&(n.push(ht(a,i,o)),r))return n}return n},cf=(e,t,n,i=!1)=>{let[o,r]=Vi(e,n),s=[];for(let a of o){let l=rd(a,t);if(l&&(s.push(l),i))return s}for(let a of r){let l=$o(a[0],a[1],a[2],a[3]),d=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!gt(l,d))continue;let c=od(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),i))return s}return s},uf=(e,t,n,i=0,o=!1)=>{let r=se(e,t),s=ht(n[0],r,-e.angle),a=ht(n[1],r,-e.angle),l=Ji(s,a),[d,c]=Pn(e,i),u=[];return ud(d,l,u,r,e.angle,o),o&&u.length>0||cd(c,l,u,r,e.angle,o),u},mf=(e,t,n,i=0,o=!1)=>{let r=se(e,t),s=ht(n[0],r,-e.angle),a=ht(n[1],r,-e.angle),l=Ji(s,a),[d,c]=In(e,i),u=[];return ud(d,l,u,r,e.angle,o),o&&u.length>0||cd(c,l,u,r,e.angle,o),u},pf=(e,t,n,i=0)=>{let o=se(e,t),r=ht(n[0],o,-e.angle),s=ht(n[1],o,-e.angle);return sf(rf(o,e.width/2+i,e.height/2+i),Ji(r,s)).map(a=>ht(a,o,e.angle))},td=(e,t,n,i=1)=>Ut(t,n,e)<=i,it=(e,t,n)=>{if((K(t)||be(t))&&!Tt(t.points))return!1;let[i,o,r,s]=ue(t,n);if(!Ps(ve(i,o),e,ve(r,s)))return!1;let a=ve((i+r)/2,(o+s)/2),l=ef(of(nf(tf(e,a,.1)),Math.max(t.width,t.height)*2),a),d=Ji(e,l);return ot(t,n,d).filter((u,m,p)=>p.findIndex(h=>sd(h,u))===m).length%2===1},Is=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:m}=s,p=se(s,n);if(s.type==="diamond"){let[f,g,E,x,b,y,w,M]=fi(s);return[ve(l+f,d+g-a),ve(l+E+a,d+x),ve(l+b,d+y+a),ve(l+w-a,d+M)].map(T=>ht(T,p,m))}if(s.type==="ellipse"){let f=l+c/2,g=d+u/2,E=c/2,x=u/2;return[ve(f,g-x-a),ve(f+E+a,g),ve(f,g+x+a),ve(f-E-a,g)].map(y=>ht(y,p,m))}return[ve(l-a,d-a),ve(l+c+a,d-a),ve(l+c+a,d+u+a),ve(l-a,d+u+a)].map(f=>ht(f,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>it(s,t,n))};I();import{invariant as md,isDevEnv as ff,isTestEnv as hf}from"@excalidraw/common";import{pointFrom as Mn,pointFromVector as Vo,pointRotateRads as Zo,pointScaleFromOrigin as Ko,pointsEqual as gf,triangleIncludesPoint as Ss,vectorCross as rt,vectorFromPoint as ae,vectorScale as qo}from"@excalidraw/math";var he=[1,0],Le=[0,1],Ne=[-1,0],Ze=[0,-1],Xt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?he:t<=-o?Ne:n>i?Le:Ze},st=(e,t)=>Xt(ae(e,t)),Lt=(e,t)=>at(st(e,t)),fe=(e,t)=>e[0]===t[0]&&e[1]===t[1],at=e=>fe(e,he)||fe(e,Ne),XP=e=>!at(e),Ef=(e,t,n)=>{let i=ln(t);(ff()||hf())&&(md(e.width>0&&e.height>0,"Diamond element has no width or height"),md(!gf(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Vo(qo(ae(Zo(Mn(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Vo(qo(ae(Zo(Mn(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Vo(qo(ae(Zo(Mn(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Vo(qo(ae(Zo(Mn(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(rt(ae(n,r),ae(r,s))<=0&&rt(ae(n,r),ae(r,l))>0)return st(r,i);if(rt(ae(n,s),ae(s,a))<=0&&rt(ae(n,s),ae(s,r))>0)return st(s,i);if(rt(ae(n,a),ae(a,l))<=0&&rt(ae(n,a),ae(a,s))>0)return st(a,i);if(rt(ae(n,l),ae(l,r))<=0&&rt(ae(n,l),ae(l,a))>0)return st(l,i);if(rt(ae(n,i),ae(r,i))<=0&&rt(ae(n,i),ae(s,i))>0){let c=e.width>e.height?r:s;return st(c,i)}else if(rt(ae(n,i),ae(s,i))<=0&&rt(ae(n,i),ae(a,i))>0){let c=e.width>e.height?a:s;return st(c,i)}else if(rt(ae(n,i),ae(a,i))<=0&&rt(ae(n,i),ae(l,i))>0){let c=e.width>e.height?a:l;return st(c,i)}let d=e.width>e.height?r:l;return st(d,i)},Ei=(e,t,n)=>{let o=ln(t);if(e.type==="diamond")return Ef(e,t,n);let r=Ko(Mn(t[0],t[1]),o,2),s=Ko(Mn(t[2],t[1]),o,2),a=Ko(Mn(t[0],t[3]),o,2),l=Ko(Mn(t[2],t[3]),o,2);return Ss([r,s,o],n)?Ze:Ss([s,l,o],n)?he:Ss([l,a,o],n)?Le:Ne},Ms=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];I();import{getSizeFromPoints as Of,randomInteger as Ns,getUpdatedTimestamp as Fs}from"@excalidraw/common";I();import{clamp as Qo,pointDistance as Ds,pointFrom as V,pointScaleFromOrigin as xf,pointsEqual as to,pointTranslate as Ts,vector as jt,vectorCross as Jo,vectorFromPoint as vs,vectorScale as bf}from"@excalidraw/math";import{BinaryHeap as wf,invariant as xi,isAnyTrue as yf,getSizeFromPoints as pd,isDevEnv as Pf,arrayToMap as If}from"@excalidraw/common";var Bs=1,ce=40,Sf=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>V(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=st(s,l[a-1]),c=st(l[a-1],l[a-2]);if(fe(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=V(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(Ds(l[a-2],l[a-1])<Bs){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=Lt(s,l[a-1]);return o.push(V(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?dn(Gs(ks(Cs(e,Ls(e,t,o.map(s=>V(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(Pf()&&xi(wd(o),"Invalid elbow points with fixed segments"),dn(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}},Mf=(e,t,n)=>{let i=t.map(A=>A.index),r=(e.fixedSegments?.map(A=>A.index)??[]).findIndex(A=>!i.includes(A));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:h,startGlobalPoint:f,endGlobalPoint:g,hoveredStartElement:E,hoveredEndElement:x,...b}=Ls({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[V(0,0),V(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:y}=dn(Gs(ks(Cs(e,{startHeading:p,endHeading:h,startGlobalPoint:f,endGlobalPoint:g,hoveredStartElement:E,hoveredEndElement:x,...b})??[])),t,null,null);if(!y||y.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let w=[];if(a)for(let A=0;A<a.index;A++)w.push(V(e.x+e.points[A][0],e.y+e.points[A][1]));if(y.forEach(A=>{w.push(V(e.x+(a?a.end[0]:0)+A[0],e.y+(a?a.end[1]:0)+A[1]))}),l)for(let A=l.index;A<e.points.length;A++)w.push(V(e.x+e.points[A][0],e.y+e.points[A][1]));let M=(l?.index??e.points.length)-(a?.index??0)-1,S=t.map(A=>A.index>s?{...A,index:A.index-M+(y.length-1)}:A),T=w.flatMap((A,F)=>{let B=w[F-1],k=w[F+1];if(B&&k){let G=st(A,B),_=st(k,A);if(fe(G,_))return S.forEach(W=>{W.index>F&&(W.index-=1)}),[];if(fe(G,Ms(_)))return S.forEach(W=>{W.index>F&&(W.index+=1)}),[A,A]}return[A]});return dn(T,S,!1,!1)},Af=(e,t,n,i,o,r)=>{let s=t.map((w,M)=>e.fixedSegments==null||e.fixedSegments[M]===void 0||e.fixedSegments[M].index!==w.index||(w.start[0]!==e.fixedSegments[M].start[0]&&w.end[0]!==e.fixedSegments[M].end[0])!=(w.start[1]!==e.fixedSegments[M].start[1]&&w.end[1]!==e.fixedSegments[M].end[1])?M:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,d=Ds(t[s].start,t[s].end),c=d<ce+5;if(a===-1&&t[s].index===1&&o){let w=at(n),S=(w?fe(n,he):fe(n,Le))?c?d/2:ce:c?-d/2:-ce;t[s].start=V(t[s].start[0]+(w?S:0),t[s].start[1]+(w?0:S))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=at(i),S=(w?fe(i,he):fe(i,Le))?c?d/2:ce:c?-d/2:-ce;t[s].end=V(t[s].end[0]+(w?S:0),t[s].end[1]+(w?0:S))}let u=t.map(w=>({...w,start:V(e.x+w.start[0],e.y+w.start[1]),end:V(e.x+w.end[0],e.y+w.end[1])})),m=e.points.map((w,M)=>V(e.x+w[0],e.y+w[1])),p=u[s].index-1,h=u[s].index,f=u[s].start,g=u[s].end,E=m[p-1]&&!to(m[p],m[p-1])?Lt(m[p-1],m[p]):void 0,x=m[h+1]&&!to(m[h],m[h+1])?Lt(m[h+1],m[h]):void 0;if(E!==void 0){let w=E?1:0;m[p-1][w]=f[w]}if(m[p]=f,m[h]=g,x!==void 0){let w=x?1:0;m[h+1][w]=g[w]}let b=u.findIndex(w=>w.index===p);if(b!==-1){let w=Lt(u[b].end,u[b].start)?1:0;u[b].start[w]=f[w],u[b].end=f}let y=u.findIndex(w=>w.index===h+1);if(y!==-1){let w=Lt(u[y].end,u[y].start)?1:0;u[y].end[w]=g[w],u[y].start=g}if(a===-1&&p===0){let w=o?at(n):Lt(m[1],m[0]);m.unshift(V(w?f[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:f[1])),o&&m.unshift(V(e.x+e.points[0][0],e.y+e.points[0][1]));for(let M of u)M.index+=o?2:1}if(l===-1&&h===e.points.length-1){let w=at(i);m.push(V(w?g[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:g[1])),r&&m.push(V(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return dn(m,u.map(w=>({...w,start:V(w.start[0]-e.x,w.start[1]-e.y),end:V(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},Tf=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((g,E)=>E===0?V(e.x+g[0],e.y+g[1]):E===t.length-1?V(e.x+g[0],e.y+g[1]):V(e.x+e.points[E][0],e.y+e.points[E][1])),m=n.map(g=>({...g,start:V(e.x+(g.start[0]-t[0][0]),e.y+(g.start[1]-t[0][1])),end:V(e.x+(g.end[0]-t[0][0]),e.y+(g.end[1]-t[0][1]))})),p=[],h=2+(d?1:0),f=2+(c?1:0);for(;p.length+h<u.length-f;)p.push(u[p.length+h]);{let g=u.at(d?2:1),E=u.at(d?3:2);if(!g||!E)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=at(i),b=at(Xt(vs(g,E)));if(a&&x===b){let y=x?fe(i,he):fe(i,Le);if(p.unshift(V(b?r[0]+(y?ce:-ce):E[0],b?E[1]:r[1]+(y?ce:-ce))),p.unshift(V(x?r[0]+(y?ce:-ce):r[0],x?r[1]:r[1]+(y?ce:-ce))),!d){d=!0;for(let w of m)w.index>1&&(w.index+=1)}}else if(p.unshift(V(b?r[0]:g[0],b?g[1]:r[1])),d){d=!1;for(let y of m)y.index>1&&(y.index-=1)}p.unshift(r)}{let g=u.at(u.length-(c?3:2)),E=u.at(u.length-(c?4:3));if(!g||!E)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=at(o),b=Lt(E,g);if(l&&x===b){let y=x?fe(o,he):fe(o,Le);p.push(V(b?s[0]+(y?ce:-ce):E[0],b?E[1]:s[1]+(y?ce:-ce))),p.push(V(x?s[0]+(y?ce:-ce):s[0],x?s[1]:s[1]+(y?ce:-ce))),c||(c=!0)}else p.push(V(b?s[0]:g[0],b?g[1]:s[1])),c&&(c=!1)}return p.push(s),dn(p,m.map(({index:g})=>({index:g,start:p[g-1],end:p[g]})).map(g=>({...g,start:V(g.start[0]-r[0],g.start[1]-r[1]),end:V(g.end[0]-r[0],g.end[1]-r[1])})),d,c)},An=1e6,bi=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};N.PROD||(xi(!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)"),xi(!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"),xi(!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"),xi(e.points.slice(1).map((w,M)=>w[0]===e.points[M][0]||w[1]===e.points[M][1]),"Elbow arrow segments must be either horizontal or vertical"),xi(n.fixedSegments?.find(w=>w.index===1&&to(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&to(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let o=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,M)=>M===0?n.points[0]:M===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&tr(d.elementId,t),m=c&&tr(c.elementId,t),p=wd(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 dn(r.map(w=>V(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y}=Ls({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?dn(r.map(w=>V(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?Sf(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,M)=>to(w,e.points[M]??V(1/0,1/0)))&&p?{}:o.length===0?dn(Gs(ks(Cs(e,{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?Mf(e,o,t):n.points?n.points&&n.fixedSegments?n:Tf(e,r,o,h,f,g,E,x,b):Af(e,o,h,f,x,b)},Ls=(e,t,n,i)=>{let o=Ts(n[0],jt(e.x,e.y)),r=Ts(n[n.length-1],jt(e.x,e.y)),s=null,a=null;if(i?.isDragging&&i?.isBindingEnabled!==!1){let w=Array.from(t.values());s=Ed(o,t,w,i?.zoom)||null,a=Ed(r,t,w,i?.zoom)||null}else s=e.startBinding&&tr(e.startBinding.elementId,t)||null,a=e.endBinding&&tr(e.endBinding.elementId,t)||null;let l=hd({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),d=hd({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=gd(l,d,s,o,t,i?.zoom),u=gd(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],h=s?lt(s,t,Tn(c,e.startArrowhead?Be(s,{elbowed:!0})*6:Be(s,{elbowed:!0})*2,1)):m,f=a?lt(a,t,Tn(u,e.endArrowhead?Be(a,{elbowed:!0})*6:Be(a,{elbowed:!0})*2,1)):p,g=Yt(l,a?lt(a,t,Tn(u,ce,ce)):p)||Yt(d,s?lt(s,t,Tn(c,ce,ce)):m),E=bd(g?[m,p]:[h,f]),x=Bf(g?m:h,g?p:f,E,g?Tn(c,!s&&!a?0:ce,0):Tn(c,!s&&!a?0:ce-(e.startArrowhead?Jn*6:Jn*2),ce),g?Tn(u,!s&&!a?0:ce,0):Tn(u,!s&&!a?0:ce-(e.endArrowhead?Jn*6:Jn*2),ce),g,s&<(s,t),a&<(a,t)),b=fd(x[0],c,l),y=fd(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:b,startGlobalPoint:l,startHeading:c,endDonglePosition:y,endGlobalPoint:d,endHeading:u,commonBounds:E,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:g,startElementBounds:h,endElementBounds:f}},Cs=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Lf(n,i||o,r,s||a,l,d),m=i&&er(i,u),p=s&&er(s,u),h=er(a,u);h&&c&&(h.closed=!0);let f=er(o,u);f&&e.startBinding&&(f.closed=!0);let g=m&&p&&(Yt(m.pos,n[1])||Yt(p.pos,n[0])),E=Df(m||f,p||h,u,r||he,l||he,g?[]:n);if(E){let x=E.map(b=>[b.pos[0],b.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},Tn=(e,t,n)=>{switch(e){case Ze:return[t,n,n,n];case he:return[n,t,n,n];case Le:return[n,n,t,n]}return[n,n,n,t]},Df=(e,t,n,i,o,r)=>{let s=As(e.pos,t.pos),a=new wf(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return vf(e,l);l.closed=!0;let d=Gf(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=xf(u.pos,l.pos,.5);if(yf(...r.map(y=>Yt(m,y))))continue;let p=kf(c),h=l.parent?Xt(vs(l.pos,l.parent.pos)):i,f=Ms(h);if(fe(f,p)||xd(e.addr,u.addr)&&fe(p,i)||xd(t.addr,u.addr)&&fe(p,o))continue;let E=h!==p,x=l.g+As(u.pos,l.pos)+(E?Math.pow(s,3):0),b=u.visited;if(!b||x<u.g){let y=Cf(u,t,p,o);u.visited=!0,u.parent=l,u.h=As(t.pos,u.pos)+y*Math.pow(s,2),u.g=x,u.f=u.g+u.h,b?a.rescoreElement(u):a.push(u)}}}return null},vf=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},As=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Bf=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,m,p]=i??[0,0,0,0],[h,f,g,E]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-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],b=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-E):(d[0]+l[2])/2:t[0]>e[0]?t[0]-E:n[0]-E,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-h):(d[1]+l[3])/2:t[1]>e[1]?t[1]-h:n[1]-h,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+f):(d[2]+l[0])/2:t[2]<e[2]?t[2]+f:n[2]+f,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+g):(d[3]+l[1])/2:t[3]<e[3]?t[3]+g:n[3]+g],y=bd([x,b]);if(!r&&x[2]-x[0]+b[2]-b[0]>y[2]-y[0]+1e-11&&x[3]-x[1]+b[3]-b[1]>y[3]-y[1]+1e-11){let[w,M]=[(b[0]+b[2])/2,(b[1]+b[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let S=x[2]+(b[0]-x[2])/2,T=b[3]+(x[1]-b[3])/2;return Jo(jt(e[2]-w,e[1]-M),jt(e[0]-w,e[3]-M))>0?[[x[0],x[1],S,x[3]],[S,b[1],b[2],b[3]]]:[[x[0],T,x[2],x[3]],[b[0],b[1],b[2],T]]}else if(e[2]<t[0]&&e[3]<t[1]){let S=x[2]+(b[0]-x[2])/2,T=x[3]+(b[1]-x[3])/2;return Jo(jt(e[0]-w,e[1]-M),jt(e[2]-w,e[3]-M))>0?[[x[0],x[1],x[2],T],[b[0],T,b[2],b[3]]]:[[x[0],x[1],S,x[3]],[S,b[1],b[2],b[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let S=b[2]+(x[0]-b[2])/2,T=x[3]+(b[1]-x[3])/2;return Jo(jt(e[2]-w,e[1]-M),jt(e[0]-w,e[3]-M))>0?[[S,x[1],x[2],x[3]],[b[0],b[1],S,b[3]]]:[[x[0],x[1],x[2],T],[b[0],T,b[2],b[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let S=b[2]+(x[0]-b[2])/2,T=b[3]+(x[1]-b[3])/2;return Jo(jt(e[0]-w,e[1]-M),jt(e[2]-w,e[3]-M))>0?[[S,x[1],x[2],x[3]],[b[0],b[1],S,b[3]]]:[[x[0],T,x[2],x[3]],[b[0],b[1],b[2],T]]}}return[x,b]},Lf=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===Ne||n===he?a.add(t[1]):s.add(t[0]),o===Ne||o===he?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]})))}},fd=(e,t,n)=>{switch(t){case Ze:return V(n[0],e[1]);case he:return V(e[2],n[1]);case Le:return V(n[0],e[3])}return V(e[0],n[1])},Cf=(e,t,n,i)=>{if(i===he)switch(n){case he:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case Ze:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Le:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Ne:return e.pos[1]===t.pos[1]?4:2}else if(i===Ne)switch(n){case he:return e.pos[1]===t.pos[1]?4:2;case Ze:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Le:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Ne:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===Ze)switch(n){case he:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Ze:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Le:return e.pos[0]===t.pos[0]?4:2;case Ne:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===Le)switch(n){case he:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Ze:return e.pos[0]===t.pos[0]?4:2;case Le:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Ne:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Gf=([e,t],n)=>[eo([e,t-1],n),eo([e+1,t],n),eo([e,t+1],n),eo([e-1,t],n)],eo=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,er=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=eo([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},bd=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]))],tr=(e,t)=>{let n=t.get(e);return n&&we(n)?n:null},dn=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>Ts(a,bf(vs(e[0]),-1)));return(o<-An||o>An||r<-An||r>An||o+s[s.length-1][0]<-An||o+s[s.length-1][0]>An||r+s[s.length-1][1]<-An||r+s[s.length-1][1]>An)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...pd(s)}),s=s.map(([a,l])=>V(Qo(a,-1e6,1e6),Qo(l,-1e6,1e6))),{points:s,x:Qo(o,-1e6,1e6),y:Qo(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...pd(s),startIsSpecial:n,endIsSpecial:i}},Gs=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},ks=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Ds(i,t)>Bs}):e,kf=e=>{switch(e){case 0:return Ze;case 1:return he;case 2:return Le}return Ne},hd=(e,t,n,i,o,r,s,a=!0,l=!0)=>s?a&&o&&r?Os(e,o,t,r,void 0,l):i:o?_e(n||[0,0],o,r??If([o])):i,gd=(e,t,n,i,o,r)=>yd(e,t,n,n&<(n,o,Array(4).fill(Ut(n,o,e))),i,o,r),Ed=(e,t,n,i)=>an(e,n,t,Dt(i)),xd=(e,t)=>e[0]===t[0]&&e[1]===t[1],wd=(e,t=Bs)=>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 Ue=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;X(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...bi({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Of(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 h=c[p],f=u[p];if(h[0]!==f[0]||h[1]!==f[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")&&Et.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Ns(),e.updated=Fs()),e},Ke=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Ns(),updated:Fs()}},Pd=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Ns(),e.updated=Fs(),e);var vd=5,Jn=5,Hf=10,io=10/1.5,rr=1,Be=(e,t)=>(t.elbowed?Jn:vd)+e.strokeWidth/2,Dt=e=>{let t=Math.max(vd,15),n=e?.value&&e.value<1?e.value:1;return or(t/(n*1.5),t,t*2)},$t=e=>e.isBindingEnabled,Wf=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=_s(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0}),d=r.isMidpointSnappingEnabled&&!s?.angleLocked&&!r.gridModeEnabled;if(Id(e,a,"start",o,r.isBindingEnabled,d),Id(e,l,"end",o,r.isBindingEnabled,d),a.focusPoint||l.focusPoint){let c=new Map;a.focusPoint&&c.set(0,{point:Ct(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&c.set(e.points.length-1,{point:Ct(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),R.movePoints(e,o,c)}return{start:a,end:l}},Id=(e,{mode:t,element:n,focusPoint:i},o,r,s=!0,a=!0)=>{t===null?Xe(e,o,r):t!==void 0&&Vt(e,n,t,o,r,i,s,a)},Bd=(e,t,n,i,o)=>{cn(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;cn(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=R.getPointGlobalCoordinates(e,a,n),d=an(l,i,n,Dt(o)),c=d?{element:d,mode:"orbit",focusPoint:R.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},Uf=(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,h=R.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),f=an(h,i,n);if(o)return f?u={element:f,mode:"inside",focusPoint:h}:u={mode:null},{start:u,end:m};if(r){let g=l?.selectedLinearElement?.initialState.origin;if(f&&e.startBinding?.elementId===f.id){let E=q(f.x+f.width/2,f.y+f.height/2);return{start:p?{mode:void 0}:{mode:"inside",element:f,focusPoint:g??E},end:p?{mode:"orbit",element:f,focusPoint:h}:{mode:"inside",element:f,focusPoint:h}}}if(f&&e.startBinding){let E=e.startBinding;if(jo(h,i,n).find(b=>b.id===E.elementId)){let b=n.get(e.startBinding.elementId);return cn(b,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:b.id!==f.id?"orbit":"inside",element:b,focusPoint:g??q(e.x,e.y)},end:{mode:"orbit",element:f,focusPoint:h}}}}if(e.startBinding&&e.startBinding.elementId!==f?.id){let E=n.get(e.startBinding.elementId);cn(E,"Other element must be in the elements map");let b={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:E,focusPoint:c?se(E,n):g??q(e.x,e.y)},y=f&&Is(E,f,n),w;if(f){let M=d==="inside"||d==="skip";w={mode:M&&!y?"inside":"orbit",element:f,focusPoint:h}}else w={mode:null};return{start:p?{mode:void 0}:b,end:w}}if(!e.startBinding)return f?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:f,focusPoint:h}:m={mode:null},{start:u,end:m}}cn(!1,"New arrow creation should not reach here")},Sd=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=an(e,o,i),m=n?jo(e,o,i).some(g=>g.id===n.elementId):!1,p=n?i.get(n.elementId):null,h=m&&p?Ff(p.backgroundColor):!1,f=u&&p&&Is(p,u,i);return r==="inside"||r==="skip"?(l=u?{element:!m||!p||h?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&&!h?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}},_s=(e,t,n,i,o,r,s,a)=>Nf("COMPLEX_BINDINGS")?Yf(e,t,o,r,s,a):Ld(e,t,n,i,o,r,s,a),Ld=(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(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!c&&!u)return{start:m,end:p};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!$t(s))return m=c?{mode:null}:m,p=u?{mode:null}:p,{start:m,end:p};if(X(e))return Bd(e,t,o,r,a?.zoom);let h=c?e.endBinding:e.startBinding,f=t.get(c?0:d)?.point;cn(f,`Local point must be defined for ${c?"start":"end"} dragging`);let g=R.getPointGlobalCoordinates(e,f,o),E=an(a?.angleLocked||s.gridModeEnabled?q(n,i):g,r,o,Dt(s.zoom)),x=E&&(a?.angleLocked?it(q(n,i),E,o):it(g,E,o)),b=h?o.get(h.elementId):void 0,y=h&&b&&_e(h.fixedPoint,b,o),w=b&&y&&Ht({point:y,element:b,elementsMap:o,threshold:0,overrideShouldTestInside:!0}),M=s.selectedLinearElement?.initialState.arrowOtherEndpointInitialBinding;if(h&&h.elementId===E?.id&&(!a?.newArrow||s.selectedLinearElement?.initialState.origin))return{start:{mode:"inside",element:E,focusPoint:c?g:a?.newArrow?zf(zs(s.selectedLinearElement.initialState.origin[0],s.selectedLinearElement.initialState.origin[1],a.gridSize)):b?_e(h.fixedPoint,b,o):R.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:E,focusPoint:u?g:b?_e(h.fixedPoint,b,o):R.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?E?{mode:"inside",element:E,focusPoint:g}:{mode:null}:m,end:u?E?{mode:"inside",element:E,focusPoint:g}:{mode:null}:p};let S=E?x?{mode:"inside",element:E,focusPoint:g}:{mode:"orbit",element:E,focusPoint:ls(e,a?.angleLocked?g:s.gridModeEnabled?Kf(q(n,i),E,o,s.gridSize,e,R.getPointAtIndexGlobalCoordinates(e,c?1:-2,o)):g,E,c?"start":"end",o,s.zoom,s.isMidpointSnappingEnabled&&!a?.angleLocked&&!s.gridModeEnabled)||g}:{mode:null},T=R.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),A=y&&b&&Ht({point:g,element:b,elementsMap:o,threshold:Dt(s.zoom),overrideShouldTestInside:!0}),F=M?.mode==="inside",B=a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:h?.mode==="inside"&&F,k={mode:void 0};return B||(h?.mode==="inside"&&!F&&b&&!a?.newArrow?k={mode:"orbit",element:b,focusPoint:y||T}:b&&!w&&!A&&s.selectedLinearElement?.initialState.altFocusPoint?k={mode:"orbit",element:b,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&b&&(k={mode:"orbit",element:b,focusPoint:ls(e,T,b,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||T})),{start:c?S:k,end:u?S:k}},Yf=(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(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!d&&!c)return{start:u,end:m};if(d&&c)return{start:{mode:null},end:{mode:null}};if(!$t(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(X(e))return Bd(e,t,n,i);if(r?.newArrow){let{start:p,end:h}=Uf(e,t,n,i,d,c,a,l,o,s,r?.shiftKey);return{start:p,end:h}}if(d){let p=t.get(a)?.point;cn(p,"Local point must be defined for start dragging");let h=R.getPointGlobalCoordinates(e,p,n),{current:f,other:g}=Sd(h,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:f,end:g}}if(c){let p=t.get(l)?.point;cn(p,"Local point must be defined for end dragging");let h=R.getPointGlobalCoordinates(e,p,n),{current:f,other:g}=Sd(h,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:g,end:f}}return{start:u,end:m}},S1=(e,t,n)=>{e.forEach(i=>{Wf(i,new Map,1/0,1/0,t,n)})},Cd=(e,t,n,i,o)=>{o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:n}),Dd(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Vt=(e,t,n,i,o,r,s=!0,a=!0)=>{let l=o.getNonDeletedElementsMap(),d;X(e)?d={elementId:t.id,mode:"orbit",...qf(e,t,i,l,s,a)}:d={elementId:t.id,mode:n,...Pi(e,t,i,l,r)},Cd(e,t,d,i,o)},Xe=(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(!we(e))return;let{simultaneouslyUpdated:i}=n??{},o=jf(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),sr(r,e,a=>{if(a&&!Ve(a)&&console.error("[NONDELETED][INVARIANT] updateBoundElements(): `isDeleted: true` in visitor"),!U(a)||!Ve(a)||!Xf(a,e))return;let l=a.startBinding?r.get(a.startBinding.elementId):null,d=a.endBinding?l?.id===a.endBinding.elementId?l:r.get(a.endBinding.elementId):null;if(o.has(a.id))return;let c=ar(r,a,(m,p)=>{if(m&&we(m)&&(p==="startBinding"||p==="endBinding")&&(e.id===a[p]?.elementId||e.id===a[p==="startBinding"?"endBinding":"startBinding"]?.elementId)){let h=Ct(a,p,a[p],m,r);if(h)return[p==="startBinding"?0:a.points.length-1,{point:h}]}return null}).filter(m=>m!==null);R.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=re(a,r);u&&!u.isDeleted&&Qn(a,t,!1)})},Md=(e,t,n,i,o)=>{cn(!X(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=R.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&Ht({element:s,point:a,elementsMap:n,threshold:Dt(o.zoom)}),d=t==="startBinding"?"start":"end";if(Xe(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],m=Ld(e,new Map([[c,{point:u}]]),a[0],a[1],n,i.getNonDeletedElements(),o);m[d]&&m[d].element?.id===s.id&&m[d].mode&&Vt(e,s,m[d].mode,d,i,m[d].focusPoint)}},M1=(e,t,n,i)=>{if(U(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&Md(e,"startBinding",o,t,n),e.endBinding&&Md(e,"endBinding",o,t,n)}else je(e,t,{...i,changedElements:new Map([[e.id,e]])})},Xf=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,jf=e=>new Set((e||[]).map(t=>t.id)),yd=(e,t,n,i,o,r,s)=>{let a=Xt(yi(t,e));return!n||!i?a:$f(o,n,r,s)?Ei(n,i,e):Xt(yi(e,se(n,r)))},$f=(e,t,n,i)=>{let o=Ut(t,n,e),r=Dt(i);return o>r?null:o},Os=(e,t,n,i,o,r=!0)=>{let s=X(e),a=R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return a;let l=vl(t)&&s?Vf(e,t,i,a):a,d=o&&!s?o[1]:R.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),c=Be(t,e),u=lt(t,i),m=ln(u),p=null;if(s){let h=at(Ei(t,u,a)),g=(r?Hs(t,i,l,.05,e):void 0)||a,E=q(h?m[0]:g[0],h?g[1]:m[1]),x=o??wi(E,nr(ir(Rs(yi(g,E)),Math.max(t.width,t.height)*2),E));if(p=ot(t,i,x,c).sort(xt)[0],!p){let b=q(h?g[0]:m[0],h?m[1]:g[1]),y=wi(b,nr(ir(Rs(yi(g,b)),Math.max(t.width,t.height)*2),b));p=ot(t,i,y,Jn).sort(xt)[0]}}else{let h=o;if(!h){let f=ir(Rs(yi(l,d)),Dn(l,d)+Math.max(t.width,t.height)+c*2);h=o??wi(nr(f,d),nr(ir(f,-1),d))}p=Dn(l,d)<1?l:ot(t,i,h,c).sort((f,g)=>xt(f,d)-xt(g,d))[0]}return!p||xt(l,p)<Rf?l:p},Vf=(e,t,n,i)=>{let o=se(t,n),r=ge(i,o,-t.angle),s=Be(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?ge(q(t.x-s,t.y),o,t.angle):ge(q(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?ge(q(t.x,t.y+t.height+s),o,t.angle):ge(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?ge(q(t.x+t.width,t.y+t.height+s),o,t.angle):ge(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?ge(q(t.x+t.width,t.y-s),o,t.angle):ge(q(t.x+t.width+s,t.y),o,t.angle):i},Hs=(e,t,n,i=.05,o)=>{let{x:r,y:s,width:a,height:l,angle:d}=e,c=se(e,t,-.1,-.1),u=ge(n,c,-d),m=o?Be(e,o):0,p=or(i*l,5,80),h=or(i*a,5,80);if(!(Dn(c,u)<m)){if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return ge(q(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-h&&u[0]<c[0]+h)return ge(q(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return ge(q(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-h&&u[0]<c[0]+h)return ge(q(c[0],s+l+m),c,d);if(e.type==="diamond"){let f=m,g=q(r+a/4-f,s+l/4-f),E=q(r+3*a/4+f,s+l/4-f),x=q(r+a/4-f,s+3*l/4+f),b=q(r+3*a/4+f,s+3*l/4+f);if(Dn(g,u)<Math.max(h,p))return ge(g,c,d);if(Dn(E,u)<Math.max(h,p))return ge(E,c,d);if(Dn(x,u)<Math.max(h,p))return ge(x,c,d);if(Dn(b,u)<Math.max(h,p))return ge(b,c,d)}}},Zf=(e,t,n)=>{let i=e[t];if(!i)return{element:null,fixedPoint:null,focusPoint:null,binding:i,mode:null};let o=n.get(i.elementId);return{element:o,fixedPoint:i.fixedPoint,focusPoint:_e(He(i.fixedPoint),o,n),binding:i,mode:i.mode}},Kf=(e,t,n,i,o,r)=>{if(!i)return e;let s=lt(t,n),a=r&&(t.type==="ellipse"||t.type==="diamond")?Xt(yi(r,e)):Ei(t,s,e),l=Be(t,o),d=Math.max(t.width,t.height)+l*2,c=ln(s),u=Math.abs(a[0]),m=Math.abs(a[1]);if(u>=m){let[,g]=zs(e[0],e[1],i),E=wi(q(c[0]-d,g),q(c[0]+d,g));return ot(t,n,E,l).sort((b,y)=>xt(b,e)-xt(y,e))[0]??q(e[0],g)}let[p]=zs(e[0],e[1],i),h=wi(q(p,c[1]-d),q(p,c[1]+d));return ot(t,n,h,l).sort((g,E)=>xt(g,e)-xt(E,e))[0]??q(p,e[1])},Ad=e=>e.width*e.height,Ct=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||_f(e.points[e.points.length-1],q(0,0)))return null;let s=_e(He(n.fixedPoint),i,o);if(n.mode==="inside")return R.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=Zf(e,t==="startBinding"?"endBinding":"startBinding",o),d=R.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&wi(s,c),m=a&&u&&ot(a,o,u,Be(a,e)).sort((b,y)=>xt(b,s)-xt(y,s))[0],p=u&&ot(i,o,u,Be(i,e)).sort((b,y)=>xt(b,c)-xt(y,c))[0],h=e.startArrowhead!==null,f=e.endArrowhead!==null,g=!h&&!f||t==="startBinding"&&h||t==="endBinding"&&f?s:p||s;if(a&&p&&!r&&Ad(a)<Ad(i)*2&&Ht({element:a,point:p,elementsMap:o,threshold:Be(a,e),overrideShouldTestInside:!0}))return R.createPointAt(e,o,g[0],g[1],null);let x=Dn(a&&(m||l)||d,p||s)<=Hf;return a?x?R.createPointAt(e,o,g?.[0]||s[0],g?.[1]||s[1],null):R.createPointAt(e,o,p?.[0]||s[0],p?.[1]||s[1],null):R.createPointAt(e,o,x?s[0]:p?.[0]??s[0],x?s[1]:p?.[1]??s[1],null)},qf=(e,t,n,i,o=!0,r=!0)=>{let s=[t.x,t.y,t.x+t.width,t.y+t.height],a=o?Os(e,t,n,i,void 0,r):R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),l=q(s[0]+(s[2]-s[0])/2,s[1]+(s[3]-s[1])/2),d=ge(a,l,-t.angle);if(t.width<rr||t.height<rr)return{fixedPoint:He([.5,.5])};let c=Be(t,e);return{fixedPoint:He([(d[0]-t.x)/Math.max(t.width,c),(d[1]-t.y)/Math.max(t.height,c)])}},Pi=(e,t,n,i,o)=>{let r=o||R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=se(t,i),a=ge(r,s,-t.angle);if(t.width<rr||t.height<rr)return{fixedPoint:He([.5,.5])};let l=Be(t,e),d=(a[0]-t.x)/Math.max(t.width,l),c=(a[1]-t.y)/Math.max(t.height,l);return{fixedPoint:He([d,c])}},Gd=(e,t,n)=>{for(let i of e){if("boundElements"in i&&i.boundElements&&Object.assign(i,{boundElements:i.boundElements.reduce((o,r)=>{let s=t.get(r.id);return s&&o.push({...r,id:s}),o},[])}),"containerId"in i&&i.containerId&&Object.assign(i,{containerId:t.get(i.containerId)??null}),"endBinding"in i&&i.endBinding){let o=t.get(i.endBinding.elementId);Object.assign(i,{endBinding:o?{...i.endBinding,elementId:o}:null})}if("startBinding"in i&&i.startBinding){let o=t.get(i.startBinding.elementId);Object.assign(i,{startBinding:o?{...i.startBinding,elementId:o}:null})}X(i)&&Object.assign(i,bi(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},A1=(e,t)=>{let n=Dd(e);for(let i of t)vn.unbindAffected(n,i,(o,r)=>Ue(o,n,r)),Bn.unbindAffected(n,i,(o,r)=>Ue(o,n,r))},no=(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},kd=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),sr=(e,t,n)=>{we(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},ar=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(Ie(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(U(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},vn=class{static unbindAffected(t,n,i){n&&ar(t,n,o=>{!o||o.isDeleted||sr(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:no(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||ar(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(U(n)&&i(o,{boundElements:no(o.boundElements,new Set,new Array(n))}),oe(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:no(o.boundElements,new Set,new Array(n))}))))})}},Bn=class{static unbindAffected(t,n,i){n&&sr(t,n,o=>{!o||o.isDeleted||ar(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||sr(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:no(n.boundElements,new Set([s]))});return}oe(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:no(n.boundElements,new Set([o.id]))})))})}},_e=(e,t,n)=>{let[i,o]=He(e);return ge(q(t.x+t.width*i,t.y+t.height*o),se(t,n),t.angle)},Qf=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?_e(e.startBinding.fixedPoint,n,t):q(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?_e(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]},Od=(e,t)=>{let[n,i]=Qf(e,t);return[R.pointFromAbsoluteCoords(e,n,t),R.pointFromAbsoluteCoords(e,i,t)]},Jf=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),Td=10,He=e=>{if(!Jf(e))return[.5001,.5001];let t=1e-4,n=e.map(i=>or(i,-Td,Td));return Math.abs(n[0]-.5)<t||Math.abs(n[1]-.5)<t?n.map(i=>Math.abs(i-.5)<t?.5001:i):n},eh=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",th={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"}]},nh=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}}),ih=(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=th[t],d=nh(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},T1=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!we(n))return null;let i=se(n,t),o=eh(n),r=ih(He(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=In(n),[d,c,u,m]=a,p,h;switch(r){case"left":{if(l.length>=3){let g=l[2][1];p=g[0]-s,h=g[1]}else{let f=Ye(c[1],u[0]);p=f[0]-s,h=f[1]}break}case"right":{if(l.length>=1){let g=l[0][1];p=g[0]+s,h=g[1]}else{let f=Ye(m[1],d[0]);p=f[0]+s,h=f[1]}break}case"top":{if(l.length>=4){let g=l[3][1];p=g[0],h=g[1]-s}else{let f=Ye(u[1],m[0]);p=f[0],h=f[1]-s}break}case"bottom":{if(l.length>=2){let g=l[1][1];p=g[0],h=g[1]+s}else{let f=Ye(d[1],c[0]);p=f[0],h=f[1]+s}break}case"top-right":{let f=Ye(m[0],m[1]);p=f[0]+s*.707,h=f[1]-s*.707;break}case"bottom-right":{let f=Ye(d[0],d[1]);p=f[0]+s*.707,h=f[1]+s*.707;break}case"bottom-left":{let f=Ye(c[0],c[1]);p=f[0]-s*.707,h=f[1]+s*.707;break}case"top-left":{let f=Ye(u[0],u[1]);p=f[0]-s*.707,h=f[1]-s*.707;break}default:return null}return ge(q(p,h),i,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,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,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h+s*.707,m=l+f-s*.707;break}case"bottom-right":{let p=Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h+s*.707,m=l+f+s*.707;break}case"bottom-left":{let p=3*Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h-s*.707,m=l+f+s*.707;break}case"top-left":{let p=-3*Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h-s*.707,m=l+f-s*.707;break}default:return null}return ge(q(u,m),i,n.angle)}if(ji(n)){let[a,l]=Pn(n),[d,c,u,m]=a,p,h;switch(r){case"top":{let f=Ye(d[0],d[1]);p=f[0],h=f[1]-s;break}case"right":{let f=Ye(c[0],c[1]);p=f[0]+s,h=f[1];break}case"bottom":{let f=Ye(u[0],u[1]);p=f[0],h=f[1]+s;break}case"left":{let f=Ye(m[0],m[1]);p=f[0]-s,h=f[1];break}case"top-left":{if(l.length>=1){let f=l[0],g=f[0],E=f[3],x=Ye(g,E);p=x[0]-s*.707,h=x[1]-s*.707}else p=n.x-s,h=n.y-s;break}case"top-right":{if(l.length>=2){let f=l[1],g=f[0],E=f[3],x=Ye(g,E);p=x[0]+s*.707,h=x[1]-s*.707}else p=n.x+n.width+s,h=n.y-s;break}case"bottom-right":{if(l.length>=3){let f=l[2],g=f[0],E=f[3],x=Ye(g,E);p=x[0]+s*.707,h=x[1]+s*.707}else p=n.x+n.width+s,h=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let f=l[3],g=f[0],E=f[3],x=Ye(g,E);p=x[0]-s*.707,h=x[1]+s*.707}else p=n.x-s,h=n.y+n.height+s;break}default:return null}return ge(q(p,h),i,n.angle)}return null},Ye=(e,t)=>q((e[0]+t[0])/2,(e[1]+t[1])/2),D1=(e,t,n,i,o)=>{Cd(e,t,{elementId:t.id,fixedPoint:He(i),mode:"orbit"},n,o)};var Us=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>H(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},Ud=new WeakMap,R=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;hoveredFocusPointBinding;draggedFocusPointBinding;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,i=!1){this.elementId=t.id,Fd(t.points[0],H(0,0))||(console.error("Linear element is not normalized",Error().stack),Ue(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,arrowOtherEndpointInitialBinding:null,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=X(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,m]=Z(n.selectionElement,o),h=e.getPointsGlobalCoordinates(l,o).reduce((f,g,E)=>((g[0]>=d&&g[0]<=u&&g[1]>=c&&g[1]<=m||t.shiftKey&&s?.includes(E))&&f.push(E),f),[]).filter(f=>!(X(l)&&f!==0&&f!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:h.length?h:null}})}static handlePointerMove(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);dt(d,"Element being dragged must exist in the scene"),dt(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??Xd(m,d.points[c]),h=0,f=0;if(ti(t)){let[M,S]=e._getShiftLockedDelta(d,s,m,H(i,o),t[ei.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),T=H(M+m[0],S+m[1]);h=T[0]-u[0],f=T[1]-u[1]}else{let M=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[ei.CTRL_OR_CMD]?null:n.getEffectiveGridSize());h=M[0]-u[0],f=M[1]-u[1]}let g=null,{positions:E,updates:x}=Yd([c],h,f,i,o,s,d,a,n,ti(t),t.altKey,r),b=ti(t);if(e.movePoints(d,n.scene,E,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!b&&!n.state.gridModeEnabled}),ze(d,!1)&&$t(n.state)&&(g=x?.suggestedBinding??null),ze(d)&&Hd(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!g||ch(n.state.suggestedBinding??[],g)))return null;let y=ze(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:p,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&y&&x?.suggestedBinding?.element.id!==y.id?Wd(d,H(d.x,d.y),y,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!b&&!n.state.gridModeEnabled):r.initialState.altFocusPoint}},suggestedBinding:g}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);dt(p,"Element being dragged must exist in the scene"),dt(p.points.length>1,"Element must have at least 2 points"),dt(u,"There must be selected points in order to drag them"),l&&u.some((v,C)=>v>0&&v!==p.points.length-1?(u[C]=p.points.length-1,m=p.points.length-1,!0):!1),(m<0||!u.includes(m)||!p.points[m])&&(console.error(`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${p.points.length-1}) lastClickedPoint(${m}) isElbowArrow: ${l}`),m=p.points.length-1);let h=p.points[m],f=p.points[m===0?1:m-1],g=u.length===1,E=r.customLineAngle??Xd(f,p.points[m]),x=u.includes(0),b=u.includes(p.points.length-1),y=0,w=0;if(ti(t)&&g){let[v,C]=e._getShiftLockedDelta(p,s,f,H(i,o),t[ei.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),E),z=H(v+f[0],C+f[1]);y=z[0]-h[0],w=z[1]-h[1]}else{let v=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[ei.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=v[0]-h[0],w=v[1]-h[1]}let M=null,{positions:S,updates:T}=Yd(u,y,w,i,o,s,p,a,n,ti(t)&&g,t.altKey,r),A=ti(t)&&g;e.movePoints(p,n.scene,S,{startBinding:T?.startBinding,endBinding:T?.endBinding,moveMidPointsWithElement:T?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!A&&!n.state.gridModeEnabled}),ze(p,!1)&&$t(n.state)&&(x||b)&&(M=T?.suggestedBinding??null),ze(p)&&x!==b&&Hd(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),re(p,s)&&Qn(p,n.scene,!1);let B=l?b?[p.points.length-1]:[0]:u,k=l?B[0]:m,G=!x&&!b?e.getPointGlobalCoordinates(p,h,s):null,_=k,W=ze(p)&&p.startBinding&&s.get(p.startBinding.elementId),D=ze(p)&&p.endBinding&&s.get(p.endBinding.elementId),L=b&&W&&T?.suggestedBinding?.element.id!==W.id?W:x&&D&&T?.suggestedBinding?.element.id!==D.id?D:null;return{selectedLinearElement:{...r,selectedPointsIndices:B,initialState:{...r.initialState,lastClickedPoint:k,altFocusPoint:!r.initialState.altFocusPoint&&ze(p)&&L?Wd(p,H(p.x,p.y),L,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!A&&!n.state.gridModeEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:G,hoverPointIndex:_,isDragging:!0,customLineAngle:E},suggestedBinding:M}}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)&&uh(c.points,i.zoom.value)&&(Oe(c)&&o.mutateElement(c,{...Kd(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,o,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1,arrowOtherEndpointInitialBinding:null}}}static getEditorMidPoints=(t,n,i)=>{let o=re(t,n);if(!X(t)&&!i.selectedLinearElement?.isEditing&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom,n)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1,n);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!X(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!X(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Zt(H(c[0],c[1]),H(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&Zt(m[u],H(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r,s){if(X(t))return o>=0&&o<t.points.length?Zt(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=Zt(n,i);if(t.points.length>2&&t.roundness){let[l,d]=zd(t,s);dt(l.length===0&&d.length>0,"Only linears built out of curves are supported"),dt(l.length+d.length>=o,"Invalid segment index while calculating mid point"),a=$d(d[o])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,i){if(X(t)){dt(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=Nd(t.points[n-1],t.points[n]);return H(t.x+s[0],t.y+s[1])}let[o,r]=zd(t,i);if(dt(o.length===0&&r.length>0||o.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),dt(o.length+r.length>=n,"Invalid segment index while calculating mid point"),o.length){let s=o[n-1];return Nd(s[0],s[1])}if(r.length){let s=r[n-1];return Vd(s,.5)}dt(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,hitBoundText:!1,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let m=e.getSegmentMidpointHitCoords(r,o,a,l),p=H(o.x,o.y),h=null;if(m)h=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[ei.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:h,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:u.startBinding},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let f=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y),g=e.isPointHandle(u,f),E=re(u,l),x=null;if(!g&&!m&&E&&U(u)&&n.arrowText.isBoundTextGrabbable(u,o.x,o.y)){let{x:k,y:G}=e.getBoundTextElementPosition(u,E,l);x={x:o.x-(k+E.width/2),y:o.y-(G+E.height/2)}}let b=x?-1:f;d.hitBoundText=!!x,(b>=0||m||x)&&(d.hitElement=u);let[y,w,M,S]=Z(u,l),T=(y+M)/2,A=(w+S)/2,F=b>-1&&qe(H(u.x+u.points[b][0],u.y+u.points[b][1]),H(T,A),u.angle),B=b>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(b)?ph([...r.selectedPointsIndices||[],b]):[b]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:b,origin:p,segmentMidpoint:{value:m,index:h,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:B?.includes(0)?u.endBinding:u.startBinding},selectedPointsIndices:B,pointerOffset:F?{x:o.x-F[0],y:o.y-F[1]}:x??{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Fd(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(ti(t)&&c.length>=2){let p=c[c.length-2],[h,f]=e._getShiftLockedDelta(d,l,p,H(n,i),t[ei.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=H(h+p[0],f+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[ei.CTRL_OR_CMD]||X(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]=Z(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return qe(H(c+n[0],u+n[1]),H(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=Z(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return qe(H(c+d[0],u+d[1]),H(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=Z(t,i),a=H(r,s),l=t.points[o],{x:d,y:c}=t;return l?qe(H(d+l[0],c+l[1]),a,t.angle):qe(H(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(X(t))return H(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=Z(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=qe(H(n[0],n[1]),H(l,d),-t.angle);return H(c-t.x,u-t.y)}static isPointHandle(t,n){return n>=0&&(!X(t)||n===0||n===t.points.length-1)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Zt(H(o,r),H(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=Rd(i,o,r),[a,l,d,c]=Z(t,n),u=(a+d)/2,m=(l+c)/2,[p,h]=qe(H(s[0],s[1]),H(u,m),-t.angle);return H(p-t.x,h-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=Us(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){dt(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);dt(s,"The linear element does not exist in the provided Scene"),dt(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((m,p,h)=>{if(++c,m.push(p),o.includes(h)){let g=a[h+1];g||(d=!0),m.push(g?H((p[0]+g[0])/2,(p[1]+g[1])/2):H(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:H(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));Oe(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=H(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=Us({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];Oe(t)&&t.polygon&&(o[0]=H(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=Us({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o,r){let{points:s}=t;if(Oe(t)&&t.polygon){let u=i.get(0),m=i.get(s.length-1);u?i.set(s.length-1,{point:H(u.point[0],u.point[1]),isDragging:u.isDragging}):m&&i.set(0,{point:H(m.point[0],m.point[1]),isDragging:m.isDragging})}let a=i.get(0)?.point??H(0,0),[l,d]=a,c=X(t)?[i.get(0)?.point??s[0],i.get(s.length-1)?.point??s[s.length-1]]:s.map((u,m)=>{let p=i.get(m)?.point??u;return o?.moveMidPointsWithElement&&m!==0&&m!==s.length-1&&!i.has(m)?p:H(p[0]-l,p[1]-d)});e._updatePoints(t,n,c,l,d,o,{isDragging:Array.from(i.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&X(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=Zt(a,H(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<dh/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!X(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.initialState,segmentMidpoint:{...t.initialState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,i,o,r,s,a){if(X(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=Xs(t,i),d=Xs(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,h=m-c,f=p-u,g=qe(H(o,r),H(h,f),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+g[0],y:t.y+g[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(X(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=Rd(o[0],o[1],r),{width:c,height:u}=qd(a[0],a[1],l,d,s);return qe(H(c,u),H(0,0),-t.angle)}static getBoundTextElementCenter=(t,n)=>{if(t.points.length%2===1){let o=Math.floor(t.points.length/2);return e.getPointGlobalCoordinates(t,t.points[o],n)}let i=t.points.length/2-1;return e.getSegmentMidPoint(t,i+1,n)};static handleBoundTextDragging(t,n,i,o){let r=n.getNonDeletedElementsMap(),s=e.getElement(t.elementId,r),a=re(s,r);if(!s||!U(s)||!a)return null;let l=H(i-t.pointerOffset.x,o-t.pointerOffset.y),{segments:d,lengths:c,prefixSums:u,totalLength:m}=jd(s,r);if(d.length===0||m===0)return null;let p=1/0,h=0,f=0;for(let b=0;b<d.length;b++){let{t:y,distance:w}=hh(d[b],l);w<p&&(p=w,h=b,f=y)}let g=gh(d[h],f,c[h]),E=Ws((u[h]+g)/m,0,1),x=e.getPointAtPathParameter(s,E,r);return x?(n.mutateElement(a,{labelPosition:E,x:x[0]-a.width/2,y:x[1]-a.height/2}),{...t,isDragging:!0}):null}static getPointAtPathParameter(t,n,i){if(!Number.isFinite(n))return null;let{segments:o,lengths:r,prefixSums:s,totalLength:a}=jd(t,i);if(o.length===0)return null;let l=Ws(n,0,1)*a,d=o.findIndex((m,p)=>l<=s[p+1]),c=d===-1?o.length-1:d,u=r[c]===0?0:Ws((l-s[c])/r[c],0,1);return Eh(o[c],u,r[c])}static getBoundTextElementPosition=(t,n,i)=>{let o=Ud.get(n);if(o&&o.containerVersion===t.version&&o.textVersion===n.version)return o.position;let r=e.computeBoundTextElementPosition(t,n,i);return Ud.set(n,{containerVersion:t.version,textVersion:n.version,position:r}),r};static computeBoundTextElementPosition=(t,n,i)=>{if(t.points.length<2)return{x:n.x,y:n.y};if(U(t)&&n.labelPosition!=null){let r=e.getPointAtPathParameter(t,n.labelPosition,i);if(r)return{x:r[0]-n.width/2,y:r[1]-n.height/2}}let o=e.getBoundTextElementCenter(t,i);return{x:o[0]-n.width/2,y:o[1]-n.height/2}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:m}=e.getBoundTextElementPosition(t,o,n),p=u+o.width,h=m+o.height,f=H(d,c),g=qe(H(r,s),f,t.angle),E=qe(H(a,s),f,t.angle),x=qe(H(u,m),f,-t.angle),b=qe(H(p,m),f,-t.angle),y=qe(H(u,h),f,-t.angle),w=qe(H(p,h),f,-t.angle);return g[0]<E[0]&&g[1]>=E[1]?(r=Math.min(r,y[0]),a=Math.max(a,Math.max(b[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):g[0]>=E[0]&&g[1]>E[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],b[0])),s=Math.min(s,y[1]),l=Math.max(l,b[1])):g[0]>=E[0]?(r=Math.min(r,b[0]),a=Math.max(a,y[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):g[1]<=E[1]&&(r=Math.min(r,Math.min(b[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,b[1]),l=Math.max(l,y[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=Et.generateElementShape(t,null),r=en(o[0]),[s,a,l,d]=oo(r),c=s+t.x,u=a+t.y,m=l+t.x,p=d+t.y,h=(c+m)/2,f=(u+p)/2,g=i&&re(t,n);return g?e.getMinMaxXYWithBoundText(t,n,[c,u,m,p],g):[c,u,m,p,h,f]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!X(a))return t;if(n&&n>0&&n<a.points.length){let l=at(Xt(oh(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,h)=>(p[h.index]=h,p),{});d[n]={index:n,start:H(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:H(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((p,h)=>p.index-h.index),u=c.map(p=>p.index).reduce((p,h)=>h<n?p+1:p,0);r.mutateElement(a,{fixedSegments:c});let m=H(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords: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)})}},ph=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},Yd=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let m=new Map(e.map(W=>{let D=s.points[W]??s.points.at(-1);return[W,{point:H(D[0]+t,D[1]+n),isDragging:!0}]}));if(!U(s))return{positions:m};let p=e.includes(0),h=e.includes(s.points.length-1),{start:f,end:g}=_s(s,m,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c,gridSize:l.getEffectiveGridSize()});if(X(s)){let W=p?f.element:h?g.element:null;return{positions:m,updates:{suggestedBinding:W?{element:W,midPoint:l.state.isMidpointSnappingEnabled?Hs(W,r,H(i-u.pointerOffset.x,o-u.pointerOffset.y)):void 0}:null}}}if(!p&&!h){let W={...s,points:s.points.map((L,P)=>m.get(P)?.point??L)},D=new Map(m);if(s.startBinding){let L=r.get(s.startBinding.elementId);if(L){let P=Ct(W,"startBinding",s.startBinding,L,r)??null;P&&D.set(0,{point:P,isDragging:!0})}}if(s.endBinding){let L=r.get(s.endBinding.elementId);if(L){let P=Ct(W,"endBinding",s.endBinding,L,r)??null;P&&D.set(s.points.length-1,{point:P,isDragging:!0})}}return{positions:D}}if(p===h)return{positions:m};let E={suggestedBinding:null};f.mode===null?E.startBinding=null:f.mode?(E.startBinding={elementId:f.element.id,mode:f.mode,...Pi(s,f.element,"start",r,f.focusPoint)},p&&(E.startBinding.mode==="orbit"||!Ii("COMPLEX_BINDINGS"))&&(E.suggestedBinding=f.element?{element:f.element,midPoint:_d(H(i-u.pointerOffset.x,o-u.pointerOffset.y),f.element,r,l.state.zoom)}:null)):p&&(E.suggestedBinding=l.state.suggestedBinding),g.mode===null?E.endBinding=null:g.mode?(E.endBinding={elementId:g.element.id,mode:g.mode,...Pi(s,g.element,"end",r,g.focusPoint)},h&&(E.endBinding.mode==="orbit"||!Ii("COMPLEX_BINDINGS"))&&(E.suggestedBinding=g.element?{element:g.element,midPoint:_d(H(i-u.pointerOffset.x,o-u.pointerOffset.y),g.element,r,l.state.zoom)}:null)):h&&(E.suggestedBinding=l.state.suggestedBinding);let x=p?H(s.points[0][0]+t,s.points[0][1]+n):s.points[0],b=h?H(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],y={...s,points:[x,...s.points.slice(1,-1),b],startBinding:E.startBinding===void 0?s.startBinding:E.startBinding===null?null:E.startBinding,endBinding:E.endBinding===void 0?s.endBinding:E.endBinding===null?null:E.endBinding},w=s.endBinding&&y.startBinding&&p&&y.startBinding.elementId===s.endBinding.elementId,M=s.startBinding&&y.endBinding&&h&&s.startBinding.elementId===y.endBinding.elementId,S=y.endBinding?g.element??r.get(y.endBinding.elementId):null,T=M&&l.state.bindMode!=="inside"&&Ii("COMPLEX_BINDINGS")?y.points[0]:S&&Ct(y,"endBinding",y.endBinding,S,r,h)||y.points[y.points.length-1];y.points[y.points.length-1]=T;let A=y.startBinding?f.element??r.get(y.startBinding.elementId):null,F=M&&Ii("COMPLEX_BINDINGS")?y.points[0]:w&&l.state.bindMode!=="inside"&&Ii("COMPLEX_BINDINGS")?T:A&&Ct(y,"startBinding",y.startBinding,A,r,p)||y.points[0],B=!(M&&l.state.bindMode!=="inside"&&Ii("COMPLEX_BINDINGS"))&&!!S,k=Zt(F,y.points[0])!==0,G=new Set(e);A&&k&&G.add(0),S&&B&&G.add(s.points.length-1);let _=Array.from(G);return{updates:E,positions:new Map(_.map(W=>[W,W===0?{point:F,isDragging:!0}:W===s.points.length-1?{point:T,isDragging:!0}:m.get(W)]))}},Xd=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]),Ys=new WeakMap;function jd(e,t){let n=Ys.get(e);if(n){if(n.version===e.version)return n.metrics;Ys.delete(e)}let i=mh(e,t),o=i.map(fh),r=new Array(o.length+1);r[0]=0;for(let a=0;a<o.length;a++)r[a+1]=r[a]+o[a];let s={segments:i,lengths:o,prefixSums:r,totalLength:r[o.length]};return Ys.set(e,{version:e.version,metrics:s}),s}var fh=e=>lr(e)?$d(e):Zt(e[0],e[1]),hh=(e,t)=>{if(lr(e)){let i=ah(e,t);return{t:i,distance:Zt(t,lh(e,i))}}let n=sh(t,e);return{t:n,distance:Zt(t,Zd(e,n))}},gh=(e,t,n)=>lr(e)?rh(e,t):t*n,Eh=(e,t,n)=>lr(e)?Vd(e,t,n):Zd(e,t);I();import{arrayToMap as Gt}from"@excalidraw/common";import{isPointWithinBounds as Gh,pointFrom as Qs,segmentsIntersectAt as kh}from"@excalidraw/math";I();import{arrayToMap as Ih,isShallowEqual as Sh}from"@excalidraw/common";I();var xh=(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}}},Qd=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 h=p.indexOf(a.editingGroupId);h>-1&&(p=p.slice(0,h))}if(p.length>0){let h=p[p.length-1];d[h]=!0}}let c={},u=s.reduce((m,p)=>{if(p.isDeleted)return m;let h=p.groupIds.find(f=>d[f]);return h&&(m[p.id]=!0,Array.isArray(c[h])?c[h].push(p.id):c[h]=[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:js({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):Kt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:js(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),bh=(e,t)=>$s(e,t)!=null,$s=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),wh=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),Jd=(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,...xh(r,n,e)}}}return n.selectedGroupIds},Z1=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),yh=(e,t)=>e.groupIds.includes(t),Qe=(e,t)=>{let n=[];for(let i of e.values())yh(i,t)&&n.push(i);return n},Ph=(e,t)=>e.groupIds.find(n=>t[n]),K1=(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},q1=(e,t)=>e.filter(n=>!t[n]),Q1=(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=re(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},ec=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},tc=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},nc=e=>e.groupIds.length>0,ic=(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},dr=(e,t,n)=>{let i=new Map,r=wh(n).length===1&&e.every(s=>bh(n,s));return e.forEach(s=>{if(Ie(s))return;let a,l=Ph(s,n.selectedGroupIds);if(!l)a=`${s.id}_element`;else{let u=r?s.groupIds.indexOf(l)-1:s.groupIds.indexOf(l);a=u<0?`${s.id}_element`:`${s.groupIds[u]}_group`}let d=i.get(a)??[],c=re(s,t);i.set(a,[...d,s,...c?[c]:[]])}),[...i.values()]};var Mh=e=>e.locked||Ie(e),Ah=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),Th=e=>{let t=new Set;return e.forEach(n=>{J(n)&&t.add(n.id)}),Ah(e,t)},oc=(e,t,n,i=!0,o="contain")=>{let[r,s,a,l]=Z(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),m=Math.max(s,l);return rc({elements:e,bounds:[d,c,u,m],elementsMap:n,type:o,shouldIgnoreElementFromSelection:Mh,excludeElementsInFrames:i})},dI=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=sc(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},cI=function(){let e=null,t=null,n=null,i=(o,r)=>(n!=null&&o===e&&r.selectedElementIds===t||(n=o.some(s=>r.selectedElementIds[s.id]),e=o,t=r.selectedElementIds),n);return i.clearCache=()=>{e=null,t=null,n=null},i}(),Kt=(e,t,n)=>{let i=new Set,o=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){Ve(r)?(o.push(r),i.add(r.id)):console.error("[NONDELETED][INVARIANT] getSelectedElements skipping deleted selected element which should not be in the selection");continue}if(n?.includeBoundTextElement&&Ie(r)&&Ve(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{J(s)&&Ln(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},uI=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement&&t.activeTool.type!=="autoshape"?[t.newElement]:Kt(e,t,{includeBoundTextElement:!0}),js=(e,t)=>Sh(t.selectedElementIds,e)?t.selectedElementIds:e,Dh=(e,t)=>{let n=e.filter(K);if(n.length===1){let i=n[0],o=i.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===i.id||o.includes(s.id)))return new R(i,Ih(t))}return null},mI=(e,t,n)=>({selectedLinearElement:Dh(e,t),...Qd({editingGroupId:n.editingGroupId,selectedElementIds:Th(e).reduce((i,o)=>(Ie(o)||(i[o.id]=!0),i),{})},t,n,null)}),pI=(e,t)=>t.editingTextElement||e.length===1&&oe(e[0])&&e[0]||null;I();import{arrayToMap as cr}from"@excalidraw/common";import{validateOrderKey as vh,generateNKeysBetween as Bh}from"@excalidraw/fractional-indexing";var Vs=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Lh=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=d=>`${d?.index}:${d?.id}:${d?.type}:${d?.isDeleted}:${d?.version}:${d?.versionNonce}`,a=n?cr(e):null,l=e.map(d=>d.index);for(let[d,c]of l.entries()){let u=l[d-1],m=l[d+1];if(Zs(c,u,m)||r.push(`Fractional indices invariant has been compromised: "${s(e[d-1])}", "${s(e[d])}", "${s(e[d+1])}"`),n&&a&&_t(e[d])&&Ve(e[d])){let p=e[d],h=Bt(p),f=h?a.get(h):null;f&&Ve(f)&&f.index<=p.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(f)}", "${s(p)}"`)}}if(r.length){let d=new Vs,c=[];if(o&&(c.push("Additional reconciliation context:"),c.push(o.localElements.map(u=>s(u))),c.push(o.remoteElements.map(u=>s(u)))),i||console.error(r.join(`
|
|
11
11
|
|
|
12
|
-
`),l.stack,e.map(c=>s(c)),...d),t)throw l}},yd=e=>e.sort((t,n)=>wd(t)&&wd(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),Yn=(e,t)=>{try{let n=Yo(e),i=xf(e,t),o=bs(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Ef(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)Te(s,n,{index:a})}catch{xs(e)}return e},xs=e=>{let t=Yo(e),n=Id(e),i=bs(e,n);for(let[o,{index:r}]of i)Te(o,t,{index:r});return e},Pd=e=>{let t=Yo(e),n=Id(e),i=bs(e,n);for(let[o,{index:r}]of i)t.set(o.id,Fe(o,{index:r}));return t},xf=(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},Id=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),Es(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[m,p]=s(l),[h,f]=a(l);if(Es(u,m,h))break;[n,o]=[m,p],[i,r]=[h,f],c.push(l)}c.push(r),t.push(c)}}return t},Es=(e,t,n)=>{if(!e)return!1;try{hf(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},bs=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=gf(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},wd=e=>!!e.index;var Sd=(e,t,n)=>{let i=ht(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&&Te(a,i,{frameId:s??null})}};function di(e,t,n){let i=ys(t,n),o=ys(e,n);return i.some(s=>o.some(a=>wf(s,a)))}var Md=(e,t,n)=>jo(Ed(e,t,n,!1)).filter(i=>!q(i)&&!i.frameId||i.frameId===t.id),Ps=(e,t,n)=>Is(ae(e,n),ae(t,n)),nP=(e,t)=>{let n=ht(e);return e.filter(i=>di(i,t,n))},yn=(e,t,n)=>{let[i,o,r,s]=$(t,n),[a,l,d,c]=ze(e);return i<=a&&o<=l&&r>=d&&s>=c},bn=(e,t,n)=>yn([e],t,n)||di(e,t,n)||Ps(e,t,n),iP=(e,t,n)=>{let[i,o,r,s]=$(t,n);return bf(ws(i,o),ws(e.x,e.y),ws(r,s))},oP=(e,t,n)=>{let i=ht(e),o=t.flatMap(r=>Ne(e,r));return o.length===0?!0:!!o.find(r=>yn([r],n,i)||di(r,n,i))},rP=(e,t,n)=>{let i=ht(e),o=t.flatMap(r=>Ne(e,r));return o.length===0?!0:o.find(r=>yn([r],n,i)||di(r,n,i))===void 0},sP=e=>{let t=new Map;for(let n of e){let i=q(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,xn(e,i))}return t},xn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},yf=e=>e.filter(t=>q(t)),aP=e=>{let t=ht(yf(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},lP=(e,t,n,i)=>{let o=xn(e,t.id),r=new Set(o),s=new Set([...Md(e,t,i),...o.filter(m=>Ps(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(!di(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 h of m.groupIds)l.has(h)&&(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=md(c,n);for(let[m,p]of Object.entries(u))if(p){let h=Ne(e,m);if(yn(h,t,i))for(let f of h)r.add(f)}return[...r].filter(m=>!(K(m)&&m.containerId))},dP=(e,t,n)=>Pf(jo(e,Md(e,t,n)),t,n),Pf=(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=>Ne(n,l)));s=!yn(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},wn=(e,t)=>e.frameId&&t.get(e.frameId)||null,cP=(e,t)=>{let n=new Set,i=ht(e);e=jo(e);for(let s of e)q(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(q(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!o.has(a)){o.add(a);let l=Ne(e,a);if(l.some(d=>bn(d,t,i)))for(let d of l)r.push(d)}}else bn(s,t,i)&&r.push(s);return r},If=e=>{let t;for(let n of e){if(q(n)||!n.frameId)return null;if(t===void 0)t=n.frameId;else if(t!==n.frameId)return null}return t??null},Sf=(e,t)=>{for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.id===t)return n;if(i.frameId===t)return n+1}return null},Mf=(e,t,n)=>{let i=ht(e),o=If(t),r=new Set,s=new Set;for(let c of t)q(c)&&c.id!==n.id&&s.add(c.id);for(let c of jo(e,t)){if(q(c)||c.frameId&&s.has(c.frameId))continue;r.add(c);let u=V(c,i);u&&!r.has(u)&&r.add(u)}for(let c of r)c.frameId!==n.id&&Te(c,i,{frameId:n.id});if(!r.size||o===n.id)return e;let a=Array.from(e.values()).filter(c=>!r.has(c)),l=Sf(a,n.id);if(l===null)return e;let d=[...a.slice(0,l),...r,...a.slice(l)];return Yn(d,ht([...r])),Array.isArray(e)?d:new Map(d.map(c=>[c.id,c]))},Ad=(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)Te(o,t,{frameId:null})},Af=(e,t)=>{let n=xn(e,t.id);return Ad(n,ht(e)),e},uP=(e,t,n)=>Mf(Af(e,n),t,n).slice(),mP=(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=>Ne(e,l)).forEach(l=>o.add(l));let r=new Set,s=ht(e);return o.forEach(a=>{a.frameId&&!q(a)&&!Td(a,s,t)&&r.add(a)}),r.size>0&&Ad(r,s),e},jo=(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)Ne(e,s).some(a=>q(a))&&o.add(s);let r=[];for(let s of i.values())o.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},Tf=(e,t,n)=>{let i=K(e)&&Le(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?wn(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:wn(i,t)},Td=(e,t,n,i)=>{let o=i?.targetFrame??Tf(e,t,n);if(!o)return!1;let r=K(e)&&Le(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 bn(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=>Ne(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(vt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(q(l))return s(!1),!1;for(let l of a)if(bn(l,o,t))return s(!0),!0;return!1},pP=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=di(e,t,i)||Ps(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!yn([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=Td(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},vf="Frame",Df="AI Frame",Bf=e=>xo(e)?vf:Df,fP=e=>e.name===null?Bf(e):e.name,hP=(e,t,n)=>e.filter(i=>(!i.frameId||i.frameId===t.id)&&Wt(ae(i,n),ae(t,n))),gP=e=>{let t=ht(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Hf=(e,t)=>Fn(e)&&!t.imageCache.has(e.fileId),Ts=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}},_f=(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*=Gf/100),r},Uf=(e,t,n)=>{let r=Ts(e),[s,a,l,d]=$(e,t),c=Q(e)||Ie(e)?ci(s,l):e.width,u=Q(e)||Ie(e)?ci(a,d):e.height,m=c*window.devicePixelRatio+r*2,p=u*window.devicePixelRatio+r*2,h=n.value;return(m*h>32767||p*h>32767)&&(h=Math.min(32767/m,32767/p)),m*p*h*h>16777216&&(h=Math.sqrt(16777216/(m*p))),m=Math.floor(m*h),p=Math.floor(p*h),{width:m,height:p,scale:h}},Bd=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=Ts(e),{width:l,height:d,scale:c}=Uf(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[E,x]=$(e,t);u=e.x>E?ci(e.x,E)*window.devicePixelRatio*c:0,m=e.y>x?ci(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=ei.canvas(r);Vo(e,p,s,i),s.restore();let h=V(e,t),f=document.createElement("canvas"),g=f.getContext("2d");if(_(e)&&h){let[E,x,b,y]=$(e,t),w=Math.max(ci(E,b),ci(x,y));f.width=w*window.devicePixelRatio*c+a*c*10,f.height=w*window.devicePixelRatio*c+a*c*10,g.translate(f.width/2,f.height/2),g.rotate(e.angle),g.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,S,I]=$(h,t);g.rotate(-e.angle);let A=(f.width-r.width)/2,M=(f.height-r.height)/2,L=f.width/2-(S-E)*window.devicePixelRatio*c-A-a*c,C=f.height/2-(I-x)*window.devicePixelRatio*c-M-a*c;g.translate(-L,-C),g.clearRect(-(h.width/2+Pn)*window.devicePixelRatio*c,-(h.height/2+Pn)*window.devicePixelRatio*c,(h.width+Pn*2)*window.devicePixelRatio*c,(h.height+Pn*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:wn(e,t)?.opacity||100,boundTextCanvas:f,angle:e.angle,imageCrop:Me(e)?e.crop:null}},LP=14,Ld=typeof document<"u"?document.createElement("img"):{src:""};Ld.src=`data:${As.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 Cd=typeof document<"u"?document.createElement("img"):{src:""};Cd.src=`data:${As.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,n)=>{t.fillStyle=n===jn.DARK?"#2E2E2E":"#E7E7E7",t.fillRect(0,0,e.width,e.height);let i=Math.min(e.width,e.height),o=Math.min(i,Math.min(i*.4,100));t.drawImage(e.status==="error"?Cd:Ld,e.width/2-o/2,e.height/2-o/2,o,o)},Vo=(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(tt.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",tt.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=tt.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=ji(e.strokeColor,i.theme===jn.DARK),n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{n.save();let o=e.fileId!==null?i.imageCache.get(e.fileId):null,r=Fn(e)?o?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,Rt(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight},c=i.theme===jn.DARK&&o?.mimeType===As.svg;if(c&&zf){let u=window.devicePixelRatio||1,m=document.createElement("canvas");m.width=e.width*u,m.height=e.height*u;let p=m.getContext("2d");if(p){p.scale(u,u),p.drawImage(r,s,a,l,d,0,0,e.width,e.height);let h=p.getImageData(0,0,m.width,m.height),f=h.data;for(let g=0;g<f.length;g+=4)f[g]=255-f[g],f[g+1]=255-f[g+1],f[g+2]=255-f[g+2];p.putImageData(h,0,0),n.drawImage(m,0,0,m.width,m.height,0,0,e.width,e.height)}}else c&&(n.filter=Of),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else Wf(e,n,i.theme);n.restore();break}default:if(K(e)){let o=Ff(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=kf(e),n.fillStyle=ji(e.strokeColor,i.theme===jn.DARK),n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
|
|
12
|
+
`),d.stack,e.map(u=>s(u)),...c),t)throw d}},lc=e=>e.sort((t,n)=>ac(t)&&ac(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),ni=(e,t)=>{try{let n=cr(e),i=Ch(e,t),o=qs(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)Ue(s,n,{index:a})}catch{Ks(e)}return e},Ks=e=>{let t=cr(e),n=cc(e),i=qs(e,n);for(let[o,{index:r}]of i)Ue(o,t,{index:r});return e},dc=e=>{let t=cr(e),n=cc(e),i=qs(e,n);for(let[o,{index:r}]of i)t.set(o.id,Ke(o,{index:r}));return t},Ch=(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},cc=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),Zs(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[m,p]=s(l),[h,f]=a(l);if(Zs(u,m,h))break;[n,o]=[m,p],[i,r]=[h,f],c.push(l)}c.push(r),t.push(c)}}return t},Zs=(e,t,n)=>{if(!e)return!1;try{vh(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},qs=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=Bh(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},ac=e=>!!e.index;var uc=(e,t,n)=>{let i=Gt(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&&Ue(a,i,{frameId:s??null})}};function Mi(e,t,n){let i=Si(t,n),o=Si(e,n);return i.some(s=>o.some(a=>kh(s,a)))}var mc=(e,t,n)=>ur(oc(e,t,n,!1)).filter(i=>!J(i)&&!i.frameId||i.frameId===t.id),Js=(e,t,n)=>ta(ue(e,n),ue(t,n)),kI=(e,t)=>{let n=Gt(e);return e.filter(i=>Mi(i,t,n))},kn=(e,t,n)=>{let[i,o,r,s]=Z(t,n),[a,l,d,c]=Je(e);return i<=a&&o<=l&&r>=d&&s>=c},Cn=(e,t,n)=>kn([e],t,n)||Mi(e,t,n)||Js(e,t,n),OI=(e,t,n)=>{let[i,o,r,s]=Z(t,n);return Gh(Qs(i,o),Qs(e.x,e.y),Qs(r,s))},NI=(e,t,n)=>{let i=Gt(e),o=t.flatMap(r=>Qe(e,r));return o.length===0?!0:!!o.find(r=>kn([r],n,i)||Mi(r,n,i))},FI=(e,t,n)=>{let i=Gt(e),o=t.flatMap(r=>Qe(e,r));return o.length===0?!0:o.find(r=>kn([r],n,i)||Mi(r,n,i))===void 0},RI=e=>{let t=new Map;for(let n of e){let i=J(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,Ln(e,i))}return t},Ln=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},ea=e=>e.filter(t=>J(t)),zI=e=>{let t=Gt(ea(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},_I=(e,t,n,i)=>{let o=Ln(e,t.id),r=new Set(o),s=new Set([...mc(e,t,i),...o.filter(p=>Js(p,t,i))]),a=o.filter(p=>!s.has(p)),l=new Set(Array.from(s).flatMap(p=>p.groupIds));for(let p of a)if(!Mi(p,t,i))p.groupIds.length===0&&r.delete(p);else if(p.groupIds.length>0)for(let h of p.groupIds)l.add(h);for(let p of a)if(p.groupIds.length>0){let h=!0;for(let f of p.groupIds)l.has(f)&&(h=!1);h&&r.delete(p)}let d=Array.from(s).filter(p=>p.groupIds.length===0);for(let p of d)r.add(p);let c=Array.from(s).filter(p=>p.groupIds.length>0),u=On(c),m=Jd(u,n);for(let[p,h]of Object.entries(m))if(h){let f=Qe(e,p);if(kn(f,t,i))for(let g of f)r.add(g)}return[...r].filter(p=>!(oe(p)&&p.containerId))},HI=(e,t,n)=>Oh(ur(e,mc(e,t,n)),t,n),Oh=(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=>Qe(n,l)));s=!kn(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Gn=(e,t)=>e.frameId&&t.get(e.frameId)||null,WI=(e,t)=>{let n=new Set,i=Gt(e);e=ur(e);for(let s of e)J(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(J(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=Qe(e,a);if(l.some(d=>Cn(d,t,i)))for(let d of l)r.push(d)}}else Cn(s,t,i)&&r.push(s);return r},Nh=e=>{let t;for(let n of e){if(J(n)||!n.frameId)return null;if(t===void 0)t=n.frameId;else if(t!==n.frameId)return null}return t??null},Fh=(e,t)=>{for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.id===t)return n;if(i.frameId===t)return n+1}return null},Rh=(e,t,n)=>{let i=Gt(e),o=Nh(t),r=new Set,s=new Set;for(let c of t)J(c)&&c.id!==n.id&&s.add(c.id);for(let c of ur(e,t)){if(J(c)||c.frameId&&s.has(c.frameId))continue;r.add(c);let u=re(c,i);u&&!r.has(u)&&r.add(u)}for(let c of r)c.frameId!==n.id&&Ue(c,i,{frameId:n.id});if(!r.size||o===n.id)return e;let a=Array.from(e.values()).filter(c=>!r.has(c)),l=Fh(a,n.id);if(l===null)return e;let d=[...a.slice(0,l),...r,...a.slice(l)];return ni(d,Gt([...r])),Array.isArray(e)?d:new Map(d.map(c=>[c.id,c]))},pc=(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=re(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)Ue(o,t,{frameId:null})},zh=(e,t)=>{let n=Ln(e,t.id);return pc(n,Gt(e)),e},UI=(e,t,n)=>Rh(zh(e,n),t,n).slice(),YI=(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=>Qe(e,l)).forEach(l=>o.add(l));let r=new Set,s=Gt(e);return o.forEach(a=>{a.frameId&&!J(a)&&!fc(a,s,t)&&r.add(a)}),r.size>0&&pc(r,s),e},ur=(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)Qe(e,s).some(a=>J(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},_h=(e,t,n)=>{let i=oe(e)&&We(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Gn(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Gn(i,t)},fc=(e,t,n,i)=>{let o=i?.targetFrame??_h(e,t,n);if(!o)return!1;let r=oe(e)&&We(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 Cn(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=>Qe(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(Kt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(J(l))return s(!1),!1;for(let l of a)if(Cn(l,o,t))return s(!0),!0;return!1},XI=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Mi(e,t,i)||Js(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!kn([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=fc(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},Hh="Frame",Wh="AI Frame",Uh=e=>No(e)?Hh:Wh,jI=e=>e.name===null?Uh(e):e.name,$I=(e,t,n)=>e.filter(i=>(!i.frameId||i.frameId===t.id)&>(ue(i,n),ue(t,n))),VI=e=>{let t=Gt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Jh=(e,t)=>Zn(e)&&!t.imageCache.has(e.fileId),hr=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}},eg=(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*=jh/100),r},tg=(e,t,n)=>{let r=hr(e),[s,a,l,d]=Z(e,t),c=K(e)||be(e)?Fn(s,l):e.width,u=K(e)||be(e)?Fn(a,d):e.height,m=c*window.devicePixelRatio+r*2,p=u*window.devicePixelRatio+r*2,h=n.value;return(m*h>32767||p*h>32767)&&(h=Math.min(32767/m,32767/p)),m*p*h*h>16777216&&(h=Math.sqrt(16777216/(m*p))),m=Math.floor(m*h),p=Math.floor(p*h),{width:m,height:p,scale:h}},Ec=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=hr(e),{width:l,height:d,scale:c}=tg(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(K(e)||be(e)){let[h,f]=Z(e,t);u=e.x>h?Fn(e.x,h)*window.devicePixelRatio*c:0,m=e.y>f?Fn(e.y,f)*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=ui.canvas(r);return fr(e,p,s,i),s.restore(),{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,containingFrameOpacity:Gn(e,t)?.opacity||100,imageCrop:ke(e)?e.crop:null}},dS=14,xc=typeof document<"u"?document.createElement("img"):{src:""};xc.src=`data:${oa.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 bc=typeof document<"u"?document.createElement("img"):{src:""};bc.src=`data:${oa.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 ng=(e,t,n)=>{t.fillStyle=n===ii.DARK?"#2E2E2E":"#E7E7E7",t.fillRect(0,0,e.width,e.height);let i=Math.min(e.width,e.height),o=Math.min(i,Math.min(i*.4,100));t.drawImage(e.status==="error"?bc:xc,e.width/2-o/2,e.height/2-o/2,o,o)},fr=(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(Et.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Et.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=Et.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=ro(e.strokeColor,i.theme===ii.DARK),n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{n.save();let o=e.fileId!==null?i.imageCache.get(e.fileId):null,r=Zn(e)?o?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,on(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight},c=i.theme===ii.DARK&&o?.mimeType===oa.svg;if(c&&Qh){let u=window.devicePixelRatio||1,m=document.createElement("canvas");m.width=e.width*u,m.height=e.height*u;let p=m.getContext("2d");if(p){p.scale(u,u),p.drawImage(r,s,a,l,d,0,0,e.width,e.height);let h=p.getImageData(0,0,m.width,m.height),f=h.data;for(let g=0;g<f.length;g+=4)f[g]=255-f[g],f[g+1]=255-f[g+1],f[g+2]=255-f[g+2];p.putImageData(h,0,0),n.drawImage(m,0,0,m.width,m.height,0,0,e.width,e.height)}}else c&&(n.filter=$h),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else ng(e,n,i.theme);n.restore();break}default:if(oe(e)){let o=Zh(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=Vh(e),n.fillStyle=ro(e.strokeColor,i.theme===ii.DARK),n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
|
|
13
13
|
`).split(`
|
|
14
|
-
`),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=Io(e.fontSize,e.lineHeight),d=Rf(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}`)}},Xi=new WeakMap,Dd=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=Xi.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=V(e,t),l=a?.version||null,d=Me(e)?e.crop:null,c=wn(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.boundTextElementVersion!==l||r.imageCrop!==d||r.containingFrameOpacity!==c||_(e)&&a&&e.angle!==r.angle){let u=Bd(e,t,o,n,i);return u?(Xi.set(e,u),u):null}return r},Ms=(e,t,n,i,o)=>{let r=e.element,s=Ts(r),a=e.scale,[l,d,c,u]=$(r,o),m=((l+c)/2+i.scrollX)*window.devicePixelRatio,p=((d+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let h=V(r,o);if(_(r)&&h){let f=(e.boundTextCanvas.width-e.canvas.width)/2,g=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(m,p),t.drawImage(e.boundTextCanvas,-(c-l)/2*window.devicePixelRatio-f/a-s,-(u-d)/2*window.devicePixelRatio-g/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(m,p),t.rotate(r.angle),"scale"in e.element&&!Hf(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),B.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&wt(r)){let f=V(r,o),g=Hr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((g.x+i.scrollX)*window.devicePixelRatio,(g.y+i.scrollY)*window.devicePixelRatio,mt(r,f)*window.devicePixelRatio,Oi(r,f)*window.devicePixelRatio)}t.restore()},CP=(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()},GP=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=_f(e,wn(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=$o.strokeWidth/s.zoom.value,o.strokeStyle=ji($o.strokeColor,s.theme===jn.DARK),Va(e)&&(o.strokeStyle=s.theme===jn.LIGHT?"#7affd7":ji("#1d8264")),$o.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,$o.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(r.isExporting){let[l,d,c,u]=$(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,h=(c-l)/2-(e.x-l),f=(u-d)/2-(e.y-d);o.save(),o.translate(m,p),o.rotate(e.angle),o.translate(-h,-f),Vo(e,i,o,r),o.restore()}else{let l=Dd(e,n,r,s);if(!l)return;Ms(l,o,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=$(e,t),m=(l+c)/2,p=(d+u)/2,h=m+s.scrollX,f=p+s.scrollY,g=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);if(K(e)){let b=Le(e,t);if(_(b)){let y=G.getBoundTextElementPosition(b,e,t);g=(c-l)/2-(y.x-l),E=(u-d)/2-(y.y-d)}}o.save(),o.translate(h,f);let x=V(e,t);if(_(e)&&x){g=e.width/2-(e.x-l),E=e.height/2-(e.y-d),o.save(),o.rotate(e.angle),o.translate(-g,-E),Vo(e,i,o,r),o.restore();let[,,,,b,y]=$(x,t),w=b-m-x.width/2-Pn,S=y-p-x.height/2-Pn,I=x.width+Pn*2,A=x.height+Pn*2;"viewBackgroundColor"in s&&(s.viewBackgroundColor==="transparent"||!s.viewBackgroundColor)?o.clearRect(w,S,I,A):(o.save(),o.fillStyle=ji(r.canvasBackgroundColor,r.theme===jn.DARK),o.fillRect(w,S,I,A),o.restore())}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-g,-E),Vo(e,i,o,r);o.restore()}else{let l=Dd(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Lf(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&Me(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=Bd(ja(l.element,t),n,s.zoom,r,s);c&&Ms(c,o,r,s,n),o.restore()}Ms(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function OP(e,t,n){let i=ae({...e,angle:0},n),o=Xo((i[0]+i[2])/2,(i[1]+i[3])/2);return Nf(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(vd(r[r.length-1][1],Ss(Xo(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[vd(Ss(Xo(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),Ss(Xo(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}var tt=class e{static rg=new it;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),Xi.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;Xi.delete(t);let o=Kf(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:Xf.white,embedsValidationStatus:null,theme:Bs.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||Bs.LIGHT}),o}},Zf=e=>[8,8+e],Rd=e=>[1.5,6+e];function qf(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&&gl(e.type)||Q(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Ve=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?Zf(e.strokeWidth):e.strokeStyle==="dotted"?Rd(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:qf(e),stroke:Zi(e.strokeColor,n),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=Vi(e.backgroundColor)?void 0:Zi(e.backgroundColor,n),e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return Nn(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:Zi(e.backgroundColor,n)),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},Od=(e,t,n)=>Eo(e)&&(t||$a(e)&&n?.get(e.id)!==!0)&&Vi(e.backgroundColor)&&Vi(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:go(e)?{...e,strokeColor:Vi(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Vi(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,$i=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},Zo=(e,t,n)=>{if(t===null)return[];let[i,o,r,s,a,l]=t;return[e.line(r,s,i,o,n),e.line(a,l,i,o,n)]},Xn=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=Rd(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},vs=(e,t,n,i,o,r=1)=>{if(i===null)return[];let[s,a,l]=i,d={...t,fill:o,fillStyle:"solid",stroke:n,roughness:Math.min(.5,t.roughness||0)};return delete d.strokeLineDash,[e.circle(s,a,l*r,d)]},kd=(e,t,n,i,o,r,s,a)=>{if(i===null)return[];let l=Zi(e.strokeColor,a),d=Zi(s,a),c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return vs(o,r,l,He(e,t,n,i),i==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let m=He(e,t,n,i);if(m===null)return[];let[p,h,f,g,E,x]=m,b={...r,fill:i==="triangle_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete b.strokeLineDash,[o.polygon([[p,h],[f,g],[E,x],[p,h]],b)]}case"diamond":case"diamond_outline":{let m=He(e,t,n,i);if(m===null)return[];let[p,h,f,g,E,x,b,y]=m,w={...r,fill:i==="diamond_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete w.strokeLineDash,[o.polygon([[p,h],[f,g],[E,x],[b,y],[p,h]],w)]}case"cardinality_one":return $i(o,He(e,t,n,i),Xn(e,r));case"cardinality_many":return Zo(o,He(e,t,n,i),Xn(e,r));case"cardinality_one_or_many":{let m=Xn(e,r);return[...Zo(o,He(e,t,n,"cardinality_many"),m),...$i(o,He(e,t,n,"cardinality_one",c),m)]}case"cardinality_exactly_one":{let m=Xn(e,r);return[...$i(o,He(e,t,n,"cardinality_one",-.5),m),...$i(o,He(e,t,n,"cardinality_one"),m)]}case"cardinality_zero_or_one":{let m=Xn(e,r);return[...vs(o,r,l,He(e,t,n,"circle_outline",1.5),d,u),...$i(o,He(e,t,n,"cardinality_one",-.5),m)]}case"cardinality_zero_or_many":{let m=Xn(e,r);return[...Zo(o,He(e,t,n,"cardinality_many"),m),...vs(o,r,l,He(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return Zo(o,He(e,t,n,i),Xn(e,r))}},sl=(e,t)=>{let n=new it,i={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=re(e,t);switch(e.type){case"line":case"arrow":{let r=e.points.length?e.points:[me(0,0)];return W(e)?n.path(Nd(r,16),i).sets[0].ops:e.roundness?n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=Vt(me(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:me(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Vt(me(e.x+s.data[0],e.y+s.data[1]),o,e.angle),Vt(me(e.x+s.data[2],e.y+s.data[3]),o,e.angle),Vt(me(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>me(l[0]-e.x,l[1]-e.y)).flat()}}):r.map((s,a)=>{let l=Vt(me(e.x+s[0],e.y+s[1]),o,e.angle);return{op:a===0?"move":"lineTo",data:me(l[0]-e.x,l[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let r=Pi(e.points,.75);return n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=Vt(me(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:me(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Vt(me(e.x+s.data[0],e.y+s.data[1]),o,e.angle),Vt(me(e.x+s.data[2],e.y+s.data[3]),o,e.angle),Vt(me(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>me(l[0]-e.x,l[1]-e.y)).flat()}})}}},Kf=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===Bs.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=Rt(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`,Ve(Od(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,Ve(Od(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,h,f]=ii(e);if(e.roundness){let g=Rt(Math.abs(l-h),e),E=Rt(Math.abs(u-d),e);a=t.path(`M ${l+g} ${d+E} L ${c-g} ${u-E}
|
|
14
|
+
`),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=Ho(e.fontSize,e.lineHeight),d=Kh(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}`)}},so=new WeakMap,gc=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=so.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=ke(e)?e.crop:null,l=Gn(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.imageCrop!==a||r.containingFrameOpacity!==l){let d=Ec(e,t,o,n,i);return d?(so.set(e,d),d):null}return r},ia=(e,t,n,i,o)=>{let r=e.element,s=hr(r),[a,l,d,c]=Z(r,o),u=((a+d)/2+i.scrollX)*window.devicePixelRatio,m=((l+c)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let p=re(r,o);if(U(r)&&p){let[,,,,h,f]=Z(p,o),g=Math.max(Fn(a,d),Fn(l,c))*window.devicePixelRatio+s*10;t.beginPath(),t.rect(u-g,m-g,g*2,g*2),t.rect((h-p.width/2-Nn+i.scrollX)*window.devicePixelRatio,(f-p.height/2-Nn+i.scrollY)*window.devicePixelRatio,(p.width+Nn*2)*window.devicePixelRatio,(p.height+Nn*2)*window.devicePixelRatio),t.clip("evenodd")}if(t.translate(u,m),t.rotate(r.angle),"scale"in e.element&&!Jh(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-u,-m),t.drawImage(e.canvas,(a+i.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(l+i.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),N.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&_t(r)){let h=re(r,o),f=hs(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((f.x+i.scrollX)*window.devicePixelRatio,(f.y+i.scrollY)*window.devicePixelRatio,vt(r,h)*window.devicePixelRatio,Qi(r,h)*window.devicePixelRatio)}t.restore()},cS=(e,t,n,i)=>{t.save(),t.translate(e.x+n.scrollX,e.y+n.scrollY),t.fillStyle=ro("rgba(0, 0, 200, 0.04)",n.theme===ii.DARK);let o=.5/n.zoom.value;t.fillRect(o,o,e.width,e.height),t.lineWidth=1/n.zoom.value,t.strokeStyle=i,t.strokeRect(o,o,e.width,e.height),t.restore()},uS=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=eg(e,Gn(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Xh: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=pr.strokeWidth/s.zoom.value,o.strokeStyle=ro(pr.strokeColor,s.theme===ii.DARK),Dl(e)&&(o.strokeStyle=s.theme===ii.LIGHT?"#7affd7":ro("#1d8264")),pr.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,pr.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]=Z(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,h=(c-l)/2-(e.x-l),f=(u-d)/2-(e.y-d);o.save(),o.translate(m,p),o.rotate(e.angle),o.translate(-h,-f),fr(e,i,o,r),o.restore()}else{let l=gc(e,n,r,s);if(!l)return;ia(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]=Z(e,t),m=(l+c)/2,p=(d+u)/2,h=m+s.scrollX,f=p+s.scrollY,g=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);if(oe(e)){let b=We(e,t);if(U(b)){let y=R.getBoundTextElementPosition(b,e,t);g=(c-l)/2-(y.x-l),E=(u-d)/2-(y.y-d)}}o.save(),o.translate(h,f);let x=re(e,t);if(U(e)&&x){g=e.width/2-(e.x-l),E=e.height/2-(e.y-d);let[,,,,b,y]=Z(x,t),w=b-m-x.width/2-Nn,M=y-p-x.height/2-Nn,S=x.width+Nn*2,T=x.height+Nn*2,A=Math.max(Fn(l,c),Fn(d,u))+hr(e)*10;o.save(),o.beginPath(),o.rect(-A,-A,A*2,A*2),o.rect(w,M,S,T),o.clip("evenodd"),o.rotate(e.angle),o.translate(-g,-E),fr(e,i,o,r),o.restore()}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-g,-E),fr(e,i,o,r);o.restore()}else{let l=gc(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Yh(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&ke(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=Ec(Ml(l.element,t),n,s.zoom,r,s);c&&ia(c,o,r,s,n),o.restore()}ia(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function mS(e,t,n){let i=ue({...e,angle:0},n),o=mr((i[0]+i[2])/2,(i[1]+i[3])/2);return qh(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(hc(r[r.length-1][1],na(mr(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[hc(na(mr(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),na(mr(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}var Et=class e{static rg=new bt;static cache=new WeakMap;static get=(t,n)=>{let i=e.cache.get(t);if(i&&(n===null||i.theme===n))return i.shape};static delete=t=>{e.cache.delete(t),so.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;so.delete(t);let o=cg(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:rg.white,embedsValidationStatus:null,theme:sa.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||sa.LIGHT}),o}},lg=e=>[8,8+e],Sc=e=>[1.5,6+e];function dg(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&&ql(e.type)||K(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var ct=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?lg(e.strokeWidth):e.strokeStyle==="dotted"?Sc(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:dg(e),stroke:co(e.strokeColor,n),preserveVertices:t||e.roughness<ig.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=lo(e.backgroundColor)?void 0:co(e.backgroundColor,n),e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return Tt(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:co(e.backgroundColor,n)),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},yc=(e,t,n)=>Oo(e)&&(t||Tl(e)&&n?.get(e.id)!==!0)&&lo(e.backgroundColor)&&lo(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:ko(e)?{...e,strokeColor:lo(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:lo(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,ao=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},gr=(e,t,n)=>{if(t===null)return[];let[i,o,r,s,a,l]=t;return[e.line(r,s,i,o,n),e.line(a,l,i,o,n)]},oi=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=Sc(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},ra=(e,t,n,i,o,r=1)=>{if(i===null)return[];let[s,a,l]=i,d={...t,fill:o,fillStyle:"solid",stroke:n,roughness:Math.min(.5,t.roughness||0)};return delete d.strokeLineDash,[e.circle(s,a,l*r,d)]},Pc=(e,t,n,i,o,r,s,a)=>{if(i===null)return[];let l=co(e.strokeColor,a),d=co(s,a),c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return ra(o,r,l,et(e,t,n,i),i==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let m=et(e,t,n,i);if(m===null)return[];let[p,h,f,g,E,x]=m,b={...r,fill:i==="triangle_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete b.strokeLineDash,[o.polygon([[p,h],[f,g],[E,x],[p,h]],b)]}case"diamond":case"diamond_outline":{let m=et(e,t,n,i);if(m===null)return[];let[p,h,f,g,E,x,b,y]=m,w={...r,fill:i==="diamond_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete w.strokeLineDash,[o.polygon([[p,h],[f,g],[E,x],[b,y],[p,h]],w)]}case"cardinality_one":return ao(o,et(e,t,n,i),oi(e,r));case"cardinality_many":return gr(o,et(e,t,n,i),oi(e,r));case"cardinality_one_or_many":{let m=oi(e,r);return[...gr(o,et(e,t,n,"cardinality_many"),m),...ao(o,et(e,t,n,"cardinality_one",c),m)]}case"cardinality_exactly_one":{let m=oi(e,r);return[...ao(o,et(e,t,n,"cardinality_one",-.5),m),...ao(o,et(e,t,n,"cardinality_one"),m)]}case"cardinality_zero_or_one":{let m=oi(e,r);return[...ra(o,r,l,et(e,t,n,"circle_outline",1.5),d,u),...ao(o,et(e,t,n,"cardinality_one",-.5),m)]}case"cardinality_zero_or_many":{let m=oi(e,r);return[...gr(o,et(e,t,n,"cardinality_many"),m),...ra(o,r,l,et(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return gr(o,et(e,t,n,i),oi(e,r))}},_l=(e,t)=>{let n=new bt,i={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=se(e,t);switch(e.type){case"line":case"arrow":{let r=e.points.length?e.points:[ye(0,0)];return X(e)?n.path(Mc(r,16),i).sets[0].ops:e.roundness?n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=un(ye(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:ye(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[un(ye(e.x+s.data[0],e.y+s.data[1]),o,e.angle),un(ye(e.x+s.data[2],e.y+s.data[3]),o,e.angle),un(ye(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>ye(l[0]-e.x,l[1]-e.y)).flat()}}):r.map((s,a)=>{let l=un(ye(e.x+s[0],e.y+s[1]),o,e.angle);return{op:a===0?"move":"lineTo",data:ye(l[0]-e.x,l[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let r=bn(e.points,.75);return n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=un(ye(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:ye(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[un(ye(e.x+s.data[0],e.y+s.data[1]),o,e.angle),un(ye(e.x+s.data[2],e.y+s.data[3]),o,e.angle),un(ye(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>ye(l[0]-e.x,l[1]-e.y)).flat()}})}}},cg=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===sa.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=on(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`,ct(yc(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,ct(yc(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,h,f]=fi(e);if(e.roundness){let g=on(Math.abs(l-h),e),E=on(Math.abs(u-d),e);a=t.path(`M ${l+g} ${d+E} L ${c-g} ${u-E}
|
|
15
15
|
C ${c} ${u}, ${c} ${u}, ${c-g} ${u+E}
|
|
16
16
|
L ${m+g} ${p-E}
|
|
17
17
|
C ${m} ${p}, ${m} ${p}, ${m-g} ${p-E}
|
|
18
18
|
L ${h+g} ${f+E}
|
|
19
19
|
C ${h} ${f}, ${h} ${f}, ${h+g} ${f-E}
|
|
20
20
|
L ${l-g} ${d+E}
|
|
21
|
-
C ${l} ${d}, ${l} ${d}, ${l+g} ${d+E}`,Ve(e,!0,s))}else a=t.polygon([[l,d],[c,u],[m,p],[h,f]],Ve(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Ve(e,!1,s));case"line":case"arrow":{let a,l=Ve(e,!1,s),d=e.points.length?e.points:[me(0,0)];if(W(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(Nd(d,16),Ve(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=kd(e,a,"start",c,t,l,i,s);a.push(...m)}if(u!==null){let m=kd(e,a,"end",u,t,l,i,s);a.push(...m)}}return a}case"freedraw":{let a=[];if(Nn(e.points)){let l=Pi(e.points,.75);a.push(t.curve(l,{...Ve(e,!1,s),stroke:"none"}))}return a.push(Qf(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return jf(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Nd=(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=pt(a,r),d=pt(s,a),c=Math.min(t,Gd(e[o],s)/2,Gd(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(" ")},zd=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Aa(e);case"arrow":case"line":{let n=tt.generateElementShape(e,null)[0],[,,,,i,o]=$(e,t);return To(e)?Ba(e,n,me(e.x,e.y),e.angle,me(i,o)):va(n,me(e.x,e.y),e.angle,me(i,o))}case"ellipse":return Ta(e);case"freedraw":{let[,,,,n,i]=$(e,t);return Da(e,me(n,i),To(e))}}},dd=(e,t)=>{let n=[...e.points];if(t){if(!Ja(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>$f||n.length<4?n.push(me(o[0],o[1])):n[n.length-1]=me(o[0],o[1])}return{polygon:t,points:n}},Qf=e=>rh(ih(e)),Ds={SIZE_FACTOR:4.25,THINNING:.6,SMOOTHING:.5},Jf={SIZE_FACTOR:1.4},Hd=e=>e.strokeOptions?.streamline??Vf,eh=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 Ra(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*Ds.SIZE_FACTOR,thinning:Ds.THINNING,smoothing:Ds.SMOOTHING,streamline:Hd(e),easing:n=>Math.sin(n*Math.PI/2),last:!0})},th=e=>new po({size:e.strokeWidth*Jf.SIZE_FACTOR,streamline:Hd(e),simplify:0,sizeMapping:t=>Math.max(.1,t.pressure)}),nh=e=>{let t=th(e);return e.points.map(([n,i])=>t.addPoint([n,i,1])),t.getStrokeOutline().map(([n,i])=>[n,i])},ih=e=>e.strokeOptions?.variability==="constant"?nh(e):eh(e),Fd=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],oh=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,rh=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Fd(i,r[0]),"L",r[0],"Z"):n.push(i,Fd(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(oh,"$1")};var Gs=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&&!he(t))return o.bounds;if(i&&t.angle!==0){let s=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:s}),s}let r=e.calculateBounds(t,n);return e.boundsCache.set(t,{version:t.version,bounds:r}),r}static calculateBounds(t,n){let i,[o,r,s,a,l,d]=$(t,n);if(Ie(t)){let[c,u,m,p]=ks(t.points.map(([h,f])=>ee(D(h,f),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=gh(t,l,d,n);else if(t.type==="diamond"){let[c,u]=ee(D(l,r),D(l,d),t.angle),[m,p]=ee(D(l,a),D(l,d),t.angle),[h,f]=ee(D(o,d),D(l,d),t.angle),[g,E]=ee(D(s,d),D(l,d),t.angle),x=Math.min(c,m,h,g),b=Math.min(u,p,f,E),y=Math.max(c,m,h,g),w=Math.max(u,p,f,E);i=[x,b,y,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,m=Math.cos(t.angle),p=Math.sin(t.angle),h=Math.hypot(c*m,u*p),f=Math.hypot(u*m,c*p);i=[l-h,d-f,l+h,d+f]}else{let[c,u]=ee(D(o,r),D(l,d),t.angle),[m,p]=ee(D(o,a),D(l,d),t.angle),[h,f]=ee(D(s,a),D(l,d),t.angle),[g,E]=ee(D(s,r),D(l,d),t.angle),x=Math.min(c,m,h,g),b=Math.min(u,p,f,E),y=Math.max(c,m,h,g),w=Math.max(u,p,f,E);i=[x,b,y,w]}return i}},$=(e,t,n=!1)=>{if(Ie(e))return ch(e);if(Q(e))return G.getElementAbsoluteCoords(e,t,n);if(K(e)){let i=t?Le(e,t):null;if(_(i)){let{x:o,y:r}=G.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},ys=(e,t)=>{let n=zd(e,t),[i,o,r,s,a,l]=$(e,t),d=D(a,l);if(n.type==="polycurve"){let E=n.data.map(b=>Ct(b,10)),x=[];if(kt(e)&&!e.polygon||_(e))for(let b of E){let y=0;for(;y<b.length-1;)x.push(pe(D(b[y][0],b[y][1]),D(b[y+1][0],b[y+1][1]))),y++}else{let b=E.flat(),y=0;for(;y<b.length-1;)x.push(pe(D(b[y][0],b[y][1]),D(b[y+1][0],b[y+1][1]))),y++}return x}else{if(n.type==="polyline")return n.data;if(lh(e)){let[g,E]=sn(e),x=E.map(y=>Wd(y,d,e.angle)).flat();return[...Ud(g,d,e.angle),...x]}else if(e.type==="diamond"){let[g,E]=an(e),x=E.map(y=>Wd(y,d,e.angle)).flat();return[...Ud(g,d,e.angle),...x]}else if(n.type==="polygon"){if(K(e)){let x=Le(e,t);if(x&&Q(x))return[pe(D(i,o),D(r,o)),pe(D(r,o),D(r,s)),pe(D(r,s),D(i,s)),pe(D(i,s),D(i,o))]}let g=n.data,E=[];for(let x=0;x<g.length-1;x++)E.push(pe(g[x],g[x+1]));return E}else if(n.type==="ellipse")return dh(e)}let[c,u,m,p,,,h,f]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(g=>ee(g,d,e.angle));return[pe(c,u),pe(m,p),pe(c,m),pe(u,p),pe(c,f),pe(m,f),pe(u,h),pe(p,h)]},lh=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),Ud=(e,t,n)=>e.map(i=>pe(ee(i[0],t,n),ee(i[1],t,n))),Wd=(e,t,n)=>{let i=Ct(e,10),o=0,r=[];for(;o<i.length-1;)r.push(pe(ee(D(i[o][0],i[o][1]),t,n),ee(D(i[o+1][0],i[o+1][1]),t,n))),o++;return r},dh=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(ee(D(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(pe(r[l],r[l+1]));return o.push(pe(r[r.length-1],r[0])),o},p1=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],ii=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]},Yd=(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},jd=(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,h=1/0,f=1/0;return a===0?h=f=-d/l:(h=(-l+Math.sqrt(c))/(2*a),f=(-l-Math.sqrt(c))/(2*a)),h>=0&&h<=1&&(m=Yd(h,e,t,n,i)),f>=0&&f<=1&&(p=Yd(f,e,t,n,i)),[m,p]},Do=(e,t,n,i)=>{let o=jd(e[0],t[0],n[0],i[0]),r=jd(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]},Yi=(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);Cs(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,h=t?t(u):u,f=t?t(m):m,g=t?t(n):n;n=m;let[E,x,b,y]=Do(g,p,h,f);a.minX=Math.min(a.minX,E),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,b),a.maxY=Math.max(a.maxY,y)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},ks=(e,t=0)=>{let n=1/0,i=1/0,o=-1/0,r=-1/0;for(let[s,a]of e)n=Math.min(n,s),i=Math.min(i,a),o=Math.max(o,s),r=Math.max(r,a);return[n-t,i-t,o+t,r+t]},ch=e=>{let[t,n,i,o]=ks(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]},uh=20,mh=15,ph=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"cardinality_many":case"cardinality_one_or_many":case"cardinality_zero_or_many":return mh;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return uh;default:return 15}},fh=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},He=(e,t,n,i,o=0)=>{if(i===null||t.length<1)return null;let r=Gt(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;Cs(a.length===6,"Op data length is not 6");let l=D(a[4],a[5]),d=D(a[2],a[3]),c=D(a[0],a[1]),u=r[s-1],m=D(0,0);if(u.op==="move"){let T=Xd(u.data);Cs(T!=null,"Op data is not a point"),m=T}else u.op==="bcurveTo"&&(m=D(u.data[4],u.data[5]));let p=(T,R)=>Math.pow(1-T,3)*l[R]+3*T*Math.pow(1-T,2)*d[R]+3*Math.pow(T,2)*(1-T)*c[R]+m[R]*Math.pow(T,3),[h,f]=n==="start"?m:l,[g,E]=[p(.3,0),p(.3,1)],x=Math.hypot(h-g,f-E),b=(h-g)/x,y=(f-E)/x,w=ph(i),S=0;{let[T,R]=n==="end"?e.points[e.points.length-1]:e.points[0],[U,ye]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];S=Math.hypot(T-U,R-ye)}let A=Math.min(w,S*(i==="diamond"||i==="diamond_outline"?.25:.5)),M=h-b*A*o,L=f-y*A*o,C=M-b*A,O=L-y*A;if(i==="circle"||i==="circle_outline"){let T=Math.hypot(O-L,C-M)+e.strokeWidth-2;return[M,L,T]}let v=fh(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[T,R]=ee(D(M,L),D(C,O),Ls(-v)),[U,ye]=ee(D(M,L),D(C,O),Ls(v));return[C,O,T,R,U,ye]}let[Y,H]=ee(D(C,O),D(M,L),-v*Math.PI/180),[Z,F]=ee(D(C,O),D(M,L),Ls(v));if(i==="diamond"||i==="diamond_outline"){let T,R;if(n==="start"){let[U,ye]=e.points.length>1?e.points[1]:[0,0];[T,R]=ee(D(M+A*2,L),D(M,L),Math.atan2(ye-L,U-M))}else{let[U,ye]=e.points.length>1?e.points[e.points.length-2]:[0,0];[T,R]=ee(D(M-A*2,L),D(M,L),Math.atan2(L-ye,M-U))}return[M,L,Y,H,T,R,Z,F]}return[M,L,Y,H,Z,F]},hh=e=>{let t=ei.generator(),n=Ve(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},gh=(e,t,n,i)=>{let o=V(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,h]=ee(D(e.x+u,e.y+m),D(t,n),e.angle),f=[p,h,p,h];if(o){let g=G.getMinMaxXYWithBoundText(e,i,[p,h,p,h],o);f=[g[0],g[1],g[2],g[3]]}return f}let s=tt.get(e,null)?.[0]??hh(e),a=Gt(s),d=Yi(a,([u,m])=>ee(D(e.x+u,e.y+m),D(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=G.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},ae=(e,t,n=!1)=>Gs.getBounds(e,t,n),ze=(e,t)=>{if(!sh(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Os(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]},f1=(e,t)=>{let[n,i,o,r]=ze(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},rn=(e,t,n,i)=>{if(!(Q(e)||Ie(e)))return[e.x,e.y,e.x+t,e.y+n];let o=_d(0,t,_d(1,n,e.points,i),i),r;if(Ie(e))r=ks(o);else{let c=ei.generator(),u=e.roundness?c.curve(o,Ve(e)):c.linearPath(o,Ve(e)),m=Gt(u);r=Yi(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},ps=(e,t)=>{let n=ei.generator(),i=e.roundness==null?n.linearPath(t,Ve(e)):n.curve(t,Ve(e)),o=Gt(i),[r,s,a,l]=Yi(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},h1=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=Os(e);return e.forEach(r=>{let[s,a,l,d]=ae(r,o),c=ah(D((s+l)/2,(a+d)/2),D(t.x,t.y));c<n&&(n=c,i=r)}),ae(i,o)},Zt=e=>{let[t,n,i,o]=ze(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},g1=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],un=e=>D(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),st=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=re(e,t),[r,s]=ee(D(i.minX,i.minY),o,e.angle),[a,l]=ee(D(i.maxX,i.minY),o,e.angle),[d,c]=ee(D(i.maxX,i.maxY),o,e.angle),[u,m]=ee(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[h,f,g,E]=n;return[p[0]-E,p[1]-h,p[2]+f,p[3]+g]}return p},St=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],Eh=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],Wt=(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},Is=(e,t)=>[D(t[0],t[1]),D(t[0],t[3]),D(t[2],t[1]),D(t[2],t[3])].every(n=>Eh(n,e)),xd=({elements:e,elementsMap:t,bounds:n,type:i,excludeElementsInFrames:o,shouldIgnoreElementFromSelection:r})=>{t||(t=Os(e));let s=qa(n)?ae(n,t):n,[a,l,d,c]=s,u=[pe(D(a,l),D(d,l)),pe(D(d,l),D(d,c)),pe(D(d,c),D(a,c)),pe(D(a,c),D(a,l))],m=o?new Set:null,p={},h=new Set;for(let f of e){if(r?.(f))continue;let g=f.groupIds.at(-1);g&&(p[g]||(p[g]=[]),p[g].push(f));let E=f.strokeWidth,x=null,b=ae(f,t);b=[b[0]-E/2,b[1]-E/2,b[2]+E/2,b[3]+E/2];let y=_(f)&&V(f,t);if(y){let{x:I,y:A}=G.getBoundTextElementPosition(f,y,t);x=[I,A,I+y.width,A+y.height]}let w=wn(f,t);if(w&&bn(f,w,t)){let I=ae(w,t);b=[Math.max(b[0],I[0]),Math.max(b[1],I[1]),Math.min(b[2],I[2]),Math.min(b[3],I[3])],x=x?[Math.max(x[0],I[0]),Math.max(x[1],I[1]),Math.min(x[2],I[2]),Math.min(x[3],I[3])]:null}let S=x?[Math.min(x[0],b[0]),Math.min(x[1],b[1]),Math.max(x[2],b[2]),Math.max(x[3],b[3])]:b;if(Is(s,S)){m&&q(f)&&m.add(f.id),h.add(f);continue}if(i==="overlap"&&x&&Wt(s,x)){h.add(f);continue}if(i==="overlap"&&Wt(s,b)){let I=!1;if(Q(f)||Ie(f)){let A=re(f,t);I=f.points.some(M=>{let L=ee(D(f.x+M[0],f.y+M[1]),A,f.angle);return St(L,s)})}else{let A=ae(f,t,!0),M=re(f,t);I=[ee(D((A[0]+A[2])/2,A[1]),M,f.angle),ee(D(A[2],(A[1]+A[3])/2),M,f.angle),ee(D((A[0]+A[2])/2,A[3]),M,f.angle),ee(D(A[0],(A[1]+A[3])/2),M,f.angle)].some(L=>St(ee(L,M,f.angle),s))}if(I||(I=u.some(A=>It(f,t,A,E/2,!0).length>0)),I){m&&q(f)&&m.add(f.id),h.add(f);continue}}}return m&&h.forEach(f=>{f.frameId&&m.has(f.frameId)&&h.delete(f)}),i==="overlap"?Array.from(h).forEach(f=>{let g=f.groupIds.at(-1);(g?p[g]:null)?.forEach(x=>h.add(x))}):i==="contain"&&h.forEach(f=>{let g=f.groupIds.at(-1),E=g?p[g]:null;E&&!E.every(x=>h.has(x))&&h.delete(f)}),e.filter(f=>h.has(f))},re=(e,t,n=0,i=0)=>{if(Q(e)||Ie(e)){let[s,a,l,d]=$(e,t),[c,u]=D((s+l)/2,(a+d)/2);return D(c+n,u+i)}let[o,r]=un(ae(e,t));return D(o+n,r+i)};var yh=.1,Vd=e=>Q(e)||Ie(e)?e.points.length<2||e.points.length===2&&_(e)&&wh(e.points[0],e.points[e.points.length-1],yh):e.width===0&&e.height===0,bd=(e,t,n,i,o)=>{let[r,s,a,l]=ae(e,o),d=qo({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=qo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},S1=(e,t,n,i,o,r)=>{let[s,a,l,d]=ze(e,o),c=qo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=qo({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},Fs=(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)/qt)*qt;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}},cd=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/qt)*qt;if(o){let d=Math.floor(o/qt)*qt;xh(a,d,d+qt)&&(bh(a,o)<qt/6?l=o:$d(a)>$d(o)?l=d+qt: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,h=i-m*n,f=(c*h-p*u)/(d*p-m*c),g=(u*m-h*d)/(d*p-m*c);r=f-e,s=g-t}return{width:r,height:s}},M1=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 L1=(e,t,n,i)=>{let o=Wo(e,n.getNonDeletedElementsMap(),i),r=Zt(e);return o.flatMap(s=>{let a=Ph(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Oe(l,n,{simultaneouslyUpdated:s}),d})})},Ph=(e,t,{axis:n,position:i})=>{let o=Zt(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 hg,arrayToObject as Kt,assertNever as fc,isDevEnv as An,isShallowEqual as hc,isTestEnv as Tn,randomInteger as pc}from"@excalidraw/common";P();import{assertNever as Gh,COLOR_PALETTE as Oh,isDevEnv as kh,isTestEnv as Fh,randomId as Rh,Emitter as Kd,toIterable as mi}from"@excalidraw/common";P();import{ORIG_ID as Ah,randomId as qd,randomInteger as Th,arrayToMap as vh,castArray as Rs,findLastIndex as ui,getUpdatedTimestamp as Dh,isTestEnv as Bh}from"@excalidraw/common";P();import{arrayToMap as Ih}from"@excalidraw/common";var Sh=e=>{let t=(o,r)=>o.groupIds[o.groupIds.length-r-1],n=(o,r)=>{let s=new Map,a=[];for(let l of o){let d=t(l,r);if(d===void 0){a.push(l);continue}let c=s.get(d);c||(c=[],s.set(d,c),a.push(d)),c.push(l)}return a.flatMap(l=>typeof l=="string"?n(s.get(l),r+1):[l])},i=n(e,0);return i.length!==e.length?(console.error("defragmentGroups: lost some elements... bailing!"),e):i},Mh=e=>{let t=Ih(e),n=new Set;for(let i of e)if(!n.has(i)){if(i.boundElements?.length){n.add(i);for(let o of i.boundElements){let r=t.get(o.id);r&&o.type==="text"&&n.add(r)}continue}i.type==="text"&&i.containerId&&t.get(i.containerId)?.boundElements?.some(o=>o.id===i.id)||n.add(i)}return n.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...n]},Zd=e=>Mh(Sh(e));var Lh=(e,t,n,i)=>{let o=zs(n);return Bh()&&Ch(o,n.id),o.id=qd(),o.updated=Dh(),i&&(o.seed=Th(),Ul(o)),o.groupIds=gd(o.groupIds,e,r=>(t.has(r)||t.set(r,qd()),t.get(r))),o},j1=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=vh(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(E=>[E.id,E])),m=e.type==="everything"&&e.preserveFrameChildrenOrder;if(e.type==="in-place")for(let E of Object.keys(e.appState.selectedGroupIds))t.filter(x=>x.groupIds?.includes(E)).forEach(x=>u.set(x.id,x));t=Zd(t);let p=t.slice(),h=E=>{let b=Rs(E).reduce((y,w)=>{if(i.has(w.id))return y;i.set(w.id,!0);let S=Lh(n.editingGroupId,o,w,e.randomizeSeed);return i.set(S.id,!0),d.set(S.id,S),a.set(w.id,S.id),l.set(S.id,w),s.push(w),r.push(S),y.push(S),y},[]);return Array.isArray(E)?b:b[0]||null},f=(E,x)=>{if(x){if(E>p.length-1){p.push(...Rs(x));return}p.splice(E+1,0,...Rs(x))}},g=new Set(t.filter(E=>u.has(E.id)&&q(E)).map(E=>E.id));for(let E of t){if(i.has(E.id)||!u.has(E.id))continue;let x=hs(n,E);if(x){let b=Ne(t,x).flatMap(w=>q(w)&&!m?[...xn(t,w.id),w]:[w]),y=ui(p,w=>w.groupIds?.includes(x));f(y,h(b));continue}if(!(!m&&E.frameId&&g.has(E.frameId))){if(q(E)){let b=E.id;if(m){f(ui(p,S=>S.id===b),h(E));continue}let y=xn(t,b),w=ui(p,S=>S.frameId===b||S.id===b);f(w,h([...y,E]));continue}if(wt(E)){let b=V(E,c),y=ui(p,w=>w.id===E.id||"containerId"in w&&w.containerId===E.id);b?f(y,h([E,b])):f(y,h(E));continue}if(he(E)){let b=Le(E,c),y=ui(p,w=>w.id===E.id||w.id===b?.id);b?f(y,h([b,E])):f(y,h(E));continue}f(ui(p,b=>b.id===E.id),h(E))}}if(Kl(r,a,d),Sd(p,s,a),e.overrides)for(let E of r){let x=l.get(E.id);x&&Object.assign(E,e.overrides({duplicateElement:E,origElement:x,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:p,origIdToDuplicateId:a}},Ns=(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]=Ns(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=Ns(e[i],t+1);return o}return B.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},zs=e=>Ns(e),Ch=(e,t)=>{Object.defineProperty(e,Ah,{value:t,writable:!1,enumerable:!1})};var Ze={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},Qd=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Kd;onStoreIncrementEmitter=new Kd;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(Ze.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?Pd(t.elements):void 0,t.appState);i=qi.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=qi.create(o,t),i?s=i:s=Us.calculate(o,t),!s.isEmpty()){let a=new Hs(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=qi.create(r,t)}let o=new _s(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===Ze.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 Ze.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Ze.NEVER:case Ze.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:Gh(n,"Unknown store action")}}finally{switch(n){case Ze.IMMEDIATELY:case Ze.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Ze.IMMEDIATELY)?t=Ze.IMMEDIATELY:this.scheduledMacroActions.has(Ze.NEVER)?t=Ze.NEVER:t=Ze.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Ze).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()),Fh()||kh())throw new Error(t)}}},qi=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)}},Ko=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Hs=class extends Ko{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},_s=class extends Ko{constructor(n){super("ephemeral",n);this.change=n}},Us=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?Sn.calculate(t.elements,n.elements):Sn.empty(),o=n.metadata.didAppStateChange?In.calculate(t.appState,n.appState):In.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,Sn.restore(i),In.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=Sn.create(n,i,o),a=In.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(Sn.empty(),In.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,Jd(n)?n:pi(n),i)}static empty(){return new e(new Map,Nh(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of mi(t.elements))this.elements.get(i.id)||(n[i.id]=Fe(i,{isDeleted:!0}));for(let i of mi(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return j.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=pi({...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===Ze.EVENTUALLY&&(o.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,o),s=this.maybeCreateAppStateSnapshot(i,o),a=!1,l=!1;return this.elements!==r&&(a=!0),this.appState!==s&&(l=!0),!a&&!l?this:new e(r,s,{didElementsChange:a,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let i=Jd(t)?t:pi(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=j.isRightDifferent(this.appState,t);if(!i)return;let o=nc(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 mi(this.elements))t.get(r.id)||i.set(r.id,Fe(r,{isDeleted:!0}));for(let r of mi(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(Me(r)&&!Fn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=tc(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of mi(this.elements))n.set(i.id,i);for(let i of mi(t))n.set(i.id,zs(i));return n}},ec="__observedAppState",Nh=()=>({name:null,editingGroupId:null,viewBackgroundColor:Oh.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),pi=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,ec,{value:!0,enumerable:!1}),t},Jd=e=>!!Reflect.get(e,ec);P();var mc=mu(ac(),1);import{randomInteger as ng,arrayToMap as ig,toBrandedType as lc,isDevEnv as dc,isTestEnv as cc,toArray as og}from"@excalidraw/common";import{isNonDeletedElement as rg}from"@excalidraw/element";import{isFrameLikeElement as sg}from"@excalidraw/element";import{getElementsInGroup as ag}from"@excalidraw/element";import{syncInvalidIndices as lg,syncMovedIndices as dg,validateFractionalIndices as cg}from"@excalidraw/element";import{getSelectedElements as ug}from"@excalidraw/element";import{mutateElement as mg}from"@excalidraw/element";var uc=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}},pg=(0,mc.default)(e=>{(dc()||cc()||window?.DEBUG_FRACTIONAL_INDICES)&&cg(e,{shouldThrow:dc()||cc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),fg=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},fi=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=lc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=lc(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=fg(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=ug(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&&rg(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=og(t),o=[];n?.skipValidation||pg(i),this.elements=lg(i),this.elementsMap.clear(),this.elements.forEach(s=>{sg(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=uc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=uc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=ng();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementsAtIndex(t,n){if(!t.length)return;if(n===null&&(n=this.elements.length),!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];dg(i,ig(t)),this.replaceAllElements(i)}insertElement=t=>{this.insertElementsAtIndex([t],null)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),i=n.get(t);return i?[i]:ag(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=mg(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var j=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i=e.empty()){return e.create({...t.deleted,...n.deleted,...i.deleted},{...t.inserted,...n.inserted,...i.inserted})}static mergeObjects(t,n,i={}){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Kt(t??[],o),Kt(n??[],o),Kt(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=Kt(e.getLeftDifferences(Kt(r,o),Kt(s,o)),d=>d),l=Kt(e.getRightDifferences(Kt(r,o),Kt(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)])):fc(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&&hc(a,l))continue;yield s}}}},In=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=j.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(j.create({},{}))}inverse(){let t=j.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=j.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=j.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=j.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=j.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=j.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=j.mergeObjects(this.delta.inserted.lockedMultiSelections??{},t.delta.inserted.lockedMultiSelections??{}),l={},d={};return(Object.keys(n).length||Object.keys(i).length)&&(d.selectedElementIds=n,l.selectedElementIds=i),(Object.keys(o).length||Object.keys(r).length)&&(d.selectedGroupIds=o,l.selectedGroupIds=r),(Object.keys(s).length||Object.keys(a).length)&&(d.lockedMultiSelections=s,l.lockedMultiSelections=a),this.delta=j.merge(this.delta,t.delta,j.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:s={},selectedGroupIds:a={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=j.mergeObjects(t.selectedElementIds,s,i),m=j.mergeObjects(t.selectedGroupIds,a,o),p=j.mergeObjects(t.lockedMultiSelections,l,r),h=d&&n.has(d.elementId)?new G(n.get(d.elementId),n,d.isEditing):null,f={...t,...c,selectedElementIds:u,selectedGroupIds:m,lockedMultiSelections:p,selectedLinearElement:typeof d<"u"?h:t.selectedLinearElement},g=this.filterInvisibleChanges(t,f,n);return[f,g]}catch(i){if(console.error("Couldn't apply appstate change",i),Tn()||An())throw i;return[t,!1]}}isEmpty(){return j.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=pi(t),r=pi(n),s=j.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=j.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=j.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=pd(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let b=i.get(x);b&&!b.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let 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 h=t[u]||{},f=n[u]||{};hc(h,f)||(l.value=!0);break;case"activeLockedId":let g=t[u]||null,E=n[u]||null;g!==E&&(l.value=!0);break;default:fc(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{j.diffObjects(t,n,"selectedElementIds",i=>!0),j.diffObjects(t,n,"selectedGroupIds",i=>i??!1),j.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),Tn()||An())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}},Sn=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(Tn()||An())&&(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:pc()},c=j.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:pc()},d={...s},c=j.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=j.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}r[s.id]=l}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=j.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,m)=>{let p;switch(m){case"deleted":p=d;break;case"inserted":p=c;break}if(!p)return console.error("Element not found when trying to apply latest changes"),u;let h={};for(let f of Object.keys(u))switch(f){case"boundElements":h[f]=u[f];break;default:h[f]=p[f]}return h},r=d=>{let c={};for(let[u,m]of Object.entries(d)){let p=t.get(u),h=n.get(u),f=null;p||h?f=j.create(m.deleted,m.inserted,o(p,h),i):f=m,j.isInnerDifferent(f.deleted,f.inserted)&&(c[u]=f)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=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),Tn()||An())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),Tn()||An())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=j.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=j.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return j.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=j.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=j.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=j.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(Tn()||An())&&(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=Fe({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=j.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!i.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);i.containsVisibleDifference=l}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Fe(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:j.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,m=l,p;c===d?p=Fe(d,{...m,version:u},!0):p=Te(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=>Ql.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);gn.unbindAffected(n,r(),o),gn.unbindAffected(n,s(),o),En.unbindAffected(n,r(),o),En.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);gn.unbindAffected(n,r(),o),gn.rebindAffected(n,s(),o),En.unbindAffected(n,r(),(a,l)=>{K(a)&&o(a,l)}),En.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new fi(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),Tn()||An())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(he(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(wt(r)){let s=_t(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||Ao(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&fe(i)&&Oe(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=yd([...o]),s=j.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),hg(Yn(r,s))}static postProcess(t,n){try{j.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];j.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),Tn()||An())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var vI=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=Zt(e),c=Wo(e,t,i).map(h=>[h,Zt(h)]).sort((h,f)=>h[1][s]-f[1][s]),u=0;for(let h of c)u+=h[1][l];let m=(d[l]-u)/(c.length-1);if(m<0){let h=c.findIndex(x=>x[1][r]===d[r]),f=c.findIndex(x=>x[1][a]===d[a]),g=(c[f][1][s]-c[h][1][s])/(c.length-1),E=c[h][1][s];return c.flatMap(([x,b],y)=>{let w={x:0,y:0};return y!==h&&y!==f&&(E+=g,w[n.axis]=E-b[s]),x.map(S=>{let I=o.mutateElement(S,{x:S.x+w.x,y:S.y+w.y});return Oe(S,o,{simultaneouslyUpdated:x}),I})})}let p=d[r];return c.flatMap(([h,f])=>{let g={x:0,y:0};return g[n.axis]=p-f[r],p+=m,p+=f[l],h.map(E=>{let x=o.mutateElement(E,{x:E.x+g.x,y:E.y+g.y});return Oe(E,o,{simultaneouslyUpdated:h}),x})})};P();import{TEXT_AUTOWRAP_THRESHOLD as gg,getGridPoint as Eg,getFontString as xg,DRAGGING_THRESHOLD as bg}from"@excalidraw/common";var NI=(e,t,n,i,o,r)=>{if(t.length===1&&W(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(W(m)&&m.startBinding&&m.endBinding){let p=t.find(f=>f.id===m.startBinding?.elementId),h=t.find(f=>f.id===m.endBinding?.elementId);return p&&h}return!0}),a=new Set(s),l=s.filter(m=>q(m)).map(m=>m.id);if(l.length>0)for(let m of i.getNonDeletedElements())m.frameId!==null&&l.includes(m.frameId)&&a.add(m);let d=[];for(let m of a){let p=e.originalElements.get(m.id);if(!p)return;d.push(p)}let c=wg(ze(d),n,o,r),u=new Set(Array.from(a,m=>m.id));a.forEach(m=>{let p=!_(m),h=p||(m.startBinding?u.has(m.startBinding.elementId):!1),f=p||(m.endBinding?u.has(m.endBinding.elementId):!1);if(_(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>bg||!m.startBinding&&!m.endBinding){Ys(e,m,i,c);let g=m.startBinding&&!h,E=m.endBinding&&!f;(g||E)&&(g&&Ge(m,"start",i),E&&Ge(m,"end",i))}}else{Ys(e,m,i,c);let g=V(m,i.getNonDeletedElementsMap());g&&Ys(e,g,i,c),Oe(m,i,{simultaneouslyUpdated:Array.from(a)})}})},wg=(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]=Eg(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Ys=(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})},zI=(e,t,n)=>{let[i,o]=ze(e);return[t-i,n-o]},HI=({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:h=!0})=>{l&&e.type!=="selection"&&(m?a=s/m:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Fs(t,a,o<n?-s:s):{width:s,height:a}=Fs(t,s,r<i?-a:a),a<0&&(a=-a)));let f=o<n?n-s:n,g=r<i?i-a:i;d&&(s+=s,a+=a,f=n-s/2,g=i-a/2);let E=null;if(K(e)){a=e.height;let x=Po(xg({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>gg/c&&(E={autoResize:!1}),g=i,d&&(f=n-s/2)}if(s!==0&&a!==0){let x=null;Me(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:f+(p?.x??0),y:g+(p?.y??0),width:s,height:a,...E,...x},{informMutation:h,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as Jo,normalizeLink as gc}from"@excalidraw/common";var jI=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Jo,e),gc(i.toString())}catch(i){console.error(i)}return gc(n)},XI=(e,t)=>{if(e.length>0&&yg(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},yg=e=>!!(e.length===1||e.length>1&&fd(e)),$I=e=>{try{let t=new URL(e);return t.searchParams.has(Jo)&&t.host===window.location.host}catch{return!1}},VI=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Jo))return t.get(Jo)}catch{}return null};P();import{FONT_FAMILY as Og,VERTICAL_ALIGN as kg,escapeDoubleQuotes as js,getFontString as Fg}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as vn,DEFAULT_FONT_FAMILY as Pg,DEFAULT_FONT_SIZE as Ig,DEFAULT_TEXT_ALIGN as Sg,DEFAULT_VERTICAL_ALIGN as Mg,DEFAULT_STROKE_STREAMLINE as Ag,VERTICAL_ALIGN as Tg,randomInteger as vg,randomId as Dg,getFontString as er,getUpdatedTimestamp as Bg,getLineHeight as Lg}from"@excalidraw/common";var gt=(e,{x:t,y:n,strokeColor:i=vn.strokeColor,backgroundColor:o=vn.backgroundColor,fillStyle:r=vn.fillStyle,strokeWidth:s=vn.strokeWidth,strokeStyle:a=vn.strokeStyle,roughness:l=vn.roughness,opacity:d=vn.opacity,width:c=0,height:u=0,angle:m=0,groupIds:p=[],frameId:h=null,index:f=null,roundness:g=null,boundElements:E=null,link:x=null,locked:b=vn.locked,...y})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:y.points}),{id:y.id||Dg(),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:h,index:f,roundness:g,seed:y.seed??vg(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:E,updated:Bg(),link:x,locked:b,customData:y.customData}),$n=e=>gt(e.type,e),oS=e=>gt("embeddable",e),rS=e=>({...gt("iframe",e)}),Ec=e=>Fe({...gt("frame",e),type:"frame",name:e?.name||null},{}),xc=e=>Fe({...gt("magicframe",e),type:"magicframe",name:e?.name||null},{}),bc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Vn=e=>{let t=e.fontFamily||Pg,n=e.fontSize||Ig,i=e.lineHeight||Lg(t),o=Ci(e.text),r=Qe(o,er({fontFamily:t,fontSize:n}),i),s=e.textAlign||Sg,a=e.verticalAlign||Mg,l=bc({textAlign:s,verticalAlign:a},r),d={...gt("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 Fe(d,{})},Cg=(e,t,n)=>{let{width:i,height:o}=Qe(n,er(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Tg.MIDDLE&&!e.containerId&&e.autoResize){let d=Qe(e.text,er(e),e.lineHeight),c=bc(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,m]=$(e,t),[p,h,f,g]=rn(e,i,o,!1),E=(d-p)/2,x=(c-h)/2,b=(u-f)/2,y=(m-g)/2;[a,l]=Gg({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,E,x,b,y)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},Gg=(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]},sS=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Ht(i,er(e),t?mt(t,e):e.width));let o=Cg(e,n,i);return{text:i,...o}},aS=e=>({...gt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,strokeOptions:e.strokeOptions??{variability:"variable",streamline:Ag}}),wc=e=>{let t={...gt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return kt(t)?{...t,polygon:e.polygon??!1}:t},tr=e=>e.elbowed?{...gt(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}:{...gt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},yc=e=>({...gt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var Et=new Map,Rg=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,Ng=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,zg=/^https:\/\/(?:www\.)?figma\.com/,Pc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Hg=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,_g=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Ic=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,Ug=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,Wg=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Yg=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Sc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Mc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,jg=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Tc=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)},Xg=e=>{try{let t=new URL(e.startsWith("http")?e:`https://${e}`);if(t.hostname.replace(/^www\./,"")!=="drive.google.com")return null;let i=null,o=t.pathname.match(/^\/file\/d\/([^/]+)(?:\/|$)/);if(o?.[1]?i=o[1]:(t.pathname==="/open"||t.pathname==="/uc")&&(i=t.searchParams.get("id")),!i||!/^[a-zA-Z0-9_-]+$/.test(i))return null;let r=t.searchParams.get("resourcekey"),s=Tc(t.toString());return{fileId:i,resourceKey:r&&/^[a-zA-Z0-9_-]+$/.test(r)?r:void 0,timestamp:s>0?s:void 0}}catch{return null}},$s=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Ac=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),Xs=e=>`<html><body>${e}</body></html>`,fS=e=>{if(!e)return null;if(Et.has(e))return Et.get(e);let t=e,n=Ac.has(Vs(e,Ac)||""),i="generic",o={w:560,h:840},r=e.match(Rg);if(r?.[2]){let c=Tc(t),u=c>0?`&start=${c}`:"",m=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${u}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break}return o=m?{w:315,h:560}:{w:560,h:315},Et.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(Ng);if(s?.[1]){let c=s?.[1],u=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${c}?api=1`,o={w:560,h:315},Et.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=Xg(e);if(a){i="video";let c=new URLSearchParams;a.resourceKey&&c.set("resourcekey",a.resourceKey),a.timestamp&&c.set("t",`${a.timestamp}`);let u=c.toString();return e=`https://drive.google.com/file/d/${a.fileId}/preview${u?`?${u}`:""}`,o={w:560,h:315},Et.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(zg))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},Et.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(Wg);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),Et.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(_g.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Ic.test(e)){let c=e.match(Ic)[1],u=js(`https://twitter.com/x/status/${c}`),m={type:"document",srcdoc:p=>Xs(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${u}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return Et.set(t,m),m}if(Mc.test(e)){let[,c,u,m]=e.match(Mc),p=js(`https://reddit.com/r/${c}/comments/${u}/${m}`),h={type:"document",srcdoc:f=>Xs(`<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 Et.set(t,h),h}if(Pc.test(e)){let[,c,u]=e.match(Pc),m=js(`https://gist.github.com/${c}/${u}`),p={type:"document",srcdoc:()=>Xs(`
|
|
21
|
+
C ${l} ${d}, ${l} ${d}, ${l+g} ${d+E}`,ct(e,!0,s))}else a=t.polygon([[l,d],[c,u],[m,p],[h,f]],ct(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,ct(e,!1,s));case"line":case"arrow":{let a,l=ct(e,!1,s),d=e.points.length?e.points:[ye(0,0)];if(X(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(Mc(d,16),ct(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=Pc(e,a,"start",c,t,l,i,s);a.push(...m)}if(u!==null){let m=Pc(e,a,"end",u,t,l,i,s);a.push(...m)}}return a}case"freedraw":{let a=[];if(Tt(e.points)){let l=bn(e.points,.75);a.push(t.curve(l,{...ct(e,!1,s),stroke:"none"}))}return a.push(ug(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return og(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Mc=(e,t)=>{let n=[];for(let o=1;o<e.length-1;o+=1){let r=e[o-1],s=e[o+1],a=e[o],l=Lt(a,r),d=Lt(s,a),c=Math.min(t,wc(e[o],s)/2,wc(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(" ")},Ac=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return sl(e);case"arrow":case"line":{let n=Et.generateElementShape(e,null)[0],[,,,,i,o]=Z(e,t);return Xo(e)?cl(e,n,ye(e.x,e.y),e.angle,ye(i,o)):ll(n,ye(e.x,e.y),e.angle,ye(i,o))}case"ellipse":return al(e);case"freedraw":{let[,,,,n,i]=Z(e,t);return dl(e,ye(n,i),Xo(e))}}},Kd=(e,t)=>{let n=[...e.points];if(t){if(!Gl(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>sg||n.length<4?n.push(ye(o[0],o[1])):n[n.length-1]=ye(o[0],o[1])}return{polygon:t,points:n}},ug=e=>xg(gg(e)),Er={SIZE_FACTOR:4.25,THINNING:.6,SMOOTHING:.5},mg={SIZE_FACTOR:1.4},aa=e=>e.strokeOptions?.streamline??ag,pg=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 El(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*Er.SIZE_FACTOR,thinning:Er.THINNING,smoothing:Er.SMOOTHING,streamline:aa(e),easing:n=>Math.sin(n*Math.PI/2),last:!0})},fg=e=>new Lo({size:e.strokeWidth*mg.SIZE_FACTOR,streamline:aa(e),simplify:0,sizeMapping:t=>Math.max(.1,t.pressure)}),hg=e=>{let t=fg(e);return e.points.map(([n,i])=>t.addPoint([n,i,1])),t.getStrokeOutline().map(([n,i])=>[n,i])},gg=e=>e.strokeOptions?.variability==="constant"?hg(e):pg(e),Tc=e=>Kr(e.points,{size:e.strokeWidth*Er.SIZE_FACTOR,streamline:aa(e),last:!0}).map(t=>t.point),Ic=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],Eg=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,xg=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Ic(i,r[0]),"L",r[0],"Z"):n.push(i,Ic(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(Eg,"$1")};var ca=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&&!Ie(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]=Z(t,n);if(be(t)){let[c,u,m,p]=ri(t.points.map(([h,f])=>le(O(h,f),O(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,m+t.x,p+t.y]}else if(K(t))i=Dg(t,l,d,n);else if(t.type==="diamond"){let[c,u]=le(O(l,r),O(l,d),t.angle),[m,p]=le(O(l,a),O(l,d),t.angle),[h,f]=le(O(o,d),O(l,d),t.angle),[g,E]=le(O(s,d),O(l,d),t.angle),x=Math.min(c,m,h,g),b=Math.min(u,p,f,E),y=Math.max(c,m,h,g),w=Math.max(u,p,f,E);i=[x,b,y,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,m=Math.cos(t.angle),p=Math.sin(t.angle),h=Math.hypot(c*m,u*p),f=Math.hypot(u*m,c*p);i=[l-h,d-f,l+h,d+f]}else{let[c,u]=le(O(o,r),O(l,d),t.angle),[m,p]=le(O(o,a),O(l,d),t.angle),[h,f]=le(O(s,a),O(l,d),t.angle),[g,E]=le(O(s,r),O(l,d),t.angle),x=Math.min(c,m,h,g),b=Math.min(u,p,f,E),y=Math.max(c,m,h,g),w=Math.max(u,p,f,E);i=[x,b,y,w]}return i}},Z=(e,t,n=!1)=>{if(be(e))return Pg(e);if(K(e))return R.getElementAbsoluteCoords(e,t,n);if(oe(e)){let i=t?We(e,t):null;if(U(i)){let{x:o,y:r}=R.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},Si=(e,t)=>{let n=Ac(e,t),[i,o,r,s,a,l]=Z(e,t),d=O(a,l);if(n.type==="polycurve"){let E=n.data.map(b=>It(b,10)),x=[];if(Oe(e)&&!e.polygon||U(e))for(let b of E){let y=0;for(;y<b.length-1;)x.push(Pe(O(b[y][0],b[y][1]),O(b[y+1][0],b[y+1][1]))),y++}else{let b=E.flat(),y=0;for(;y<b.length-1;)x.push(Pe(O(b[y][0],b[y][1]),O(b[y+1][0],b[y+1][1]))),y++}return x}else{if(n.type==="polyline")return n.data;if(wg(e)){let[g,E]=Pn(e),x=E.map(y=>Bc(y,d,e.angle)).flat();return[...vc(g,d,e.angle),...x]}else if(e.type==="diamond"){let[g,E]=In(e),x=E.map(y=>Bc(y,d,e.angle)).flat();return[...vc(g,d,e.angle),...x]}else if(n.type==="polygon"){if(oe(e)){let x=We(e,t);if(x&&K(x))return[Pe(O(i,o),O(r,o)),Pe(O(r,o),O(r,s)),Pe(O(r,s),O(i,s)),Pe(O(i,s),O(i,o))]}let g=n.data,E=[];for(let x=0;x<g.length-1;x++)E.push(Pe(g[x],g[x+1]));return E}else if(n.type==="ellipse")return yg(e)}let[c,u,m,p,,,h,f]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(g=>le(g,d,e.angle));return[Pe(c,u),Pe(m,p),Pe(c,m),Pe(u,p),Pe(c,f),Pe(m,f),Pe(u,h),Pe(p,h)]},wg=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),vc=(e,t,n)=>e.map(i=>Pe(le(i[0],t,n),le(i[1],t,n))),Bc=(e,t,n)=>{let i=It(e,10),o=0,r=[];for(;o<i.length-1;)r.push(Pe(le(O(i[o][0],i[o][1]),t,n),le(O(i[o+1][0],i[o+1][1]),t,n))),o++;return r},yg=e=>{let t=O(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(le(O(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(Pe(r[l],r[l+1]));return o.push(Pe(r[r.length-1],r[0])),o},XS=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],fi=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]},Lc=(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},Cc=(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,h=1/0,f=1/0;return a===0?h=f=-d/l:(h=(-l+Math.sqrt(c))/(2*a),f=(-l-Math.sqrt(c))/(2*a)),h>=0&&h<=1&&(m=Lc(h,e,t,n,i)),f>=0&&f<=1&&(p=Lc(f,e,t,n,i)),[m,p]},$o=(e,t,n,i)=>{let o=Cc(e[0],t[0],n[0],i[0]),r=Cc(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]},oo=(e,t)=>{let n=O(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=kc(d);da(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=O(d[0],d[1]),u=O(d[2],d[3]),m=O(d[4],d[5]),p=t?t(c):c,h=t?t(u):u,f=t?t(m):m,g=t?t(n):n;n=m;let[E,x,b,y]=$o(g,p,h,f);a.minX=Math.min(a.minX,E),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,b),a.maxY=Math.max(a.maxY,y)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},ri=(e,t=0)=>{let n=1/0,i=1/0,o=-1/0,r=-1/0;for(let[s,a]of e)n=Math.min(n,s),i=Math.min(i,a),o=Math.max(o,s),r=Math.max(r,a);return[n-t,i-t,o+t,r+t]},Pg=e=>{let[t,n,i,o]=ri(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]},Ig=20,Sg=15,Mg=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"cardinality_many":case"cardinality_one_or_many":case"cardinality_zero_or_many":return Sg;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return Ig;default:return 15}},Ag=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},et=(e,t,n,i,o=0)=>{if(i===null||t.length<1)return null;let r=en(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;da(a.length===6,"Op data length is not 6");let l=O(a[4],a[5]),d=O(a[2],a[3]),c=O(a[0],a[1]),u=r[s-1],m=O(0,0);if(u.op==="move"){let P=kc(u.data);da(P!=null,"Op data is not a point"),m=P}else u.op==="bcurveTo"&&(m=O(u.data[4],u.data[5]));let p=(P,v)=>Math.pow(1-P,3)*l[v]+3*P*Math.pow(1-P,2)*d[v]+3*Math.pow(P,2)*(1-P)*c[v]+m[v]*Math.pow(P,3),[h,f]=n==="start"?m:l,[g,E]=[p(.3,0),p(.3,1)],x=Math.hypot(h-g,f-E),b=(h-g)/x,y=(f-E)/x,w=Mg(i),M=0;{let[P,v]=n==="end"?e.points[e.points.length-1]:e.points[0],[C,z]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];M=Math.hypot(P-C,v-z)}let T=Math.min(w,M*(i==="diamond"||i==="diamond_outline"?.25:.5)),A=h-b*T*o,F=f-y*T*o,B=A-b*T,k=F-y*T;if(i==="circle"||i==="circle_outline"){let P=Math.hypot(k-F,B-A)+e.strokeWidth-2;return[A,F,P]}let G=Ag(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[P,v]=le(O(A,F),O(B,k),la(-G)),[C,z]=le(O(A,F),O(B,k),la(G));return[B,k,P,v,C,z]}let[_,W]=le(O(B,k),O(A,F),-G*Math.PI/180),[D,L]=le(O(B,k),O(A,F),la(G));if(i==="diamond"||i==="diamond_outline"){let P,v;if(n==="start"){let[C,z]=e.points.length>1?e.points[1]:[0,0];[P,v]=le(O(A+T*2,F),O(A,F),Math.atan2(z-F,C-A))}else{let[C,z]=e.points.length>1?e.points[e.points.length-2]:[0,0];[P,v]=le(O(A-T*2,F),O(A,F),Math.atan2(F-z,A-C))}return[A,F,_,W,P,v,D,L]}return[A,F,_,W,D,L]},Tg=e=>{let t=ui.generator(),n=ct(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},Dg=(e,t,n,i)=>{let o=re(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,h]=le(O(e.x+u,e.y+m),O(t,n),e.angle),f=[p,h,p,h];if(o){let g=R.getMinMaxXYWithBoundText(e,i,[p,h,p,h],o);f=[g[0],g[1],g[2],g[3]]}return f}let s=Et.get(e,null)?.[0]??Tg(e),a=en(s),d=oo(a,([u,m])=>le(O(e.x+u,e.y+m),O(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=R.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},ue=(e,t,n=!1)=>ca.getBounds(e,t,n),Je=(e,t)=>{if(!bg(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Gc(e);return e.forEach(a=>{let[l,d,c,u]=ue(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]},jS=(e,t)=>{let[n,i,o,r]=Je(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},yn=(e,t,n,i)=>{if(!(K(e)||be(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Dc(0,t,Dc(1,n,e.points,i),i),r;if(be(e))r=ri(o);else{let c=ui.generator(),u=e.roundness?c.curve(o,ct(e)):c.linearPath(o,ct(e)),m=en(u);r=oo(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Xs=(e,t)=>{let n=ui.generator(),i=e.roundness==null?n.linearPath(t,ct(e)):n.curve(t,ct(e)),o=en(i),[r,s,a,l]=oo(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},mn=e=>{let[t,n,i,o]=Je(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},$S=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],ln=e=>O(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),lt=(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=se(e,t),[r,s]=le(O(i.minX,i.minY),o,e.angle),[a,l]=le(O(i.maxX,i.minY),o,e.angle),[d,c]=le(O(i.maxX,i.maxY),o,e.angle),[u,m]=le(O(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[h,f,g,E]=n;return[p[0]-E,p[1]-h,p[2]+f,p[3]+g]}return p},Yt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],vg=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],gt=(e,t)=>{if(e==null||t==null)return!1;let[n,i,o,r]=e,[s,a,l,d]=t;return n<l&&o>s&&i<d&&r>a},ta=(e,t)=>[O(t[0],t[1]),O(t[0],t[3]),O(t[2],t[1]),O(t[2],t[3])].every(n=>vg(n,e)),rc=({elements:e,elementsMap:t,bounds:n,type:i,excludeElementsInFrames:o,shouldIgnoreElementFromSelection:r})=>{t||(t=Gc(e));let s=Bl(n)?ue(n,t):n,[a,l,d,c]=s,u=[Pe(O(a,l),O(d,l)),Pe(O(d,l),O(d,c)),Pe(O(d,c),O(a,c)),Pe(O(a,c),O(a,l))],m=o?new Set:null,p={},h=new Set;for(let f of e){if(r?.(f))continue;let g=f.groupIds.at(-1);g&&(p[g]||(p[g]=[]),p[g].push(f));let E=f.strokeWidth,x=null,b=ue(f,t);b=[b[0]-E/2,b[1]-E/2,b[2]+E/2,b[3]+E/2];let y=U(f)&&re(f,t);if(y){let{x:S,y:T}=R.getBoundTextElementPosition(f,y,t);x=[S,T,S+y.width,T+y.height]}let w=Gn(f,t);if(w&&Cn(f,w,t)){let S=ue(w,t);b=[Math.max(b[0],S[0]),Math.max(b[1],S[1]),Math.min(b[2],S[2]),Math.min(b[3],S[3])],x=x?[Math.max(x[0],S[0]),Math.max(x[1],S[1]),Math.min(x[2],S[2]),Math.min(x[3],S[3])]:null}let M=x?[Math.min(x[0],b[0]),Math.min(x[1],b[1]),Math.max(x[2],b[2]),Math.max(x[3],b[3])]:b;if(ta(s,M)){m&&J(f)&&m.add(f.id),h.add(f);continue}if(i==="overlap"&&x&>(s,x)){h.add(f);continue}if(i==="overlap"&>(s,b)){let S=!1;if(K(f)||be(f)){let T=se(f,t);S=f.points.some(A=>{let F=le(O(f.x+A[0],f.y+A[1]),T,f.angle);return Yt(F,s)})}else{let T=ue(f,t,!0),A=se(f,t);S=[le(O((T[0]+T[2])/2,T[1]),A,f.angle),le(O(T[2],(T[1]+T[3])/2),A,f.angle),le(O((T[0]+T[2])/2,T[3]),A,f.angle),le(O(T[0],(T[1]+T[3])/2),A,f.angle)].some(F=>Yt(le(F,A,f.angle),s))}if(S||(S=u.some(T=>ot(f,t,T,E/2,!0).length>0)),S){m&&J(f)&&m.add(f.id),h.add(f);continue}}}return m&&h.forEach(f=>{f.frameId&&m.has(f.frameId)&&h.delete(f)}),i==="overlap"?Array.from(h).forEach(f=>{let g=f.groupIds.at(-1);(g?p[g]:null)?.forEach(x=>h.add(x))}):i==="contain"&&h.forEach(f=>{let g=f.groupIds.at(-1),E=g?p[g]:null;E&&!E.every(x=>h.has(x))&&h.delete(f)}),e.filter(f=>h.has(f))},se=(e,t,n=0,i=0)=>{if(K(e)||be(e)){let[s,a,l,d]=Z(e,t),[c,u]=O((s+l)/2,(a+d)/2);return O(c+n,u+i)}let[o,r]=ln(ue(e,t));return O(o+n,r+i)};var Gg=.1,Nc=e=>K(e)||be(e)?e.points.length<2||e.points.length===2&&U(e)&&Cg(e.points[0],e.points[e.points.length-1],Gg):e.width===0&&e.height===0,sc=(e,t,n,i,o)=>{let[r,s,a,l]=ue(e,o),d=xr({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=xr({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},tM=(e,t,n,i,o,r)=>{let[s,a,l,d]=Je(e,o),c=xr({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=xr({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},ua=(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)/pn)*pn;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}},qd=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/pn)*pn;if(o){let d=Math.floor(o/pn)*pn;Bg(a,d,d+pn)&&(Lg(a,o)<pn/6?l=o:Oc(a)>Oc(o)?l=d+pn: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,h=i-m*n,f=(c*h-p*u)/(d*p-m*c),g=(u*m-h*d)/(d*p-m*c);r=f-e,s=g-t}return{width:r,height:s}},nM=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};I();var dM=(e,t,n,i)=>{let o=dr(e,n.getNonDeletedElementsMap(),i).map(On),r=mn(e);return o.flatMap(s=>{let a=kg(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})})},kg=(e,t,{axis:n,position:i})=>{let o=mn(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}};I();import{TEXT_ALIGN as yr,VERTICAL_ALIGN as Pr}from"@excalidraw/common";import{pointDistance as jg,pointFromVector as $g,pointsEqual as Uc,vector as Vg,vectorDot as Zg,vectorFromPoint as Wc,vectorNormalize as Kg,vectorScale as qg}from"@excalidraw/math";I();import{DEFAULT_ELEMENT_PROPS as Rn,DEFAULT_FONT_FAMILY as Og,DEFAULT_FONT_SIZE as Ng,DEFAULT_TEXT_ALIGN as Fg,DEFAULT_VERTICAL_ALIGN as Rg,DEFAULT_STROKE_STREAMLINE as zg,VERTICAL_ALIGN as si,randomInteger as _g,randomId as Hg,getFontString as br,getUpdatedTimestamp as Wg,getLineHeight as Ug}from"@excalidraw/common";var kt=(e,{x:t,y:n,strokeColor:i=Rn.strokeColor,backgroundColor:o=Rn.backgroundColor,fillStyle:r=Rn.fillStyle,strokeWidth:s=Rn.strokeWidth,strokeStyle:a=Rn.strokeStyle,roughness:l=Rn.roughness,opacity:d=Rn.opacity,width:c=0,height:u=0,angle:m=0,groupIds:p=[],frameId:h=null,index:f=null,roundness:g=null,boundElements:E=null,link:x=null,locked:b=Rn.locked,...y})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:y.points}),{id:y.id||Hg(),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:h,index:f,roundness:g,seed:y.seed??_g(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:E,updated:Wg(),link:x,locked:b,customData:y.customData}),Ai=e=>kt(e.type,e),bM=e=>kt("embeddable",e),wM=e=>({...kt("iframe",e)}),Fc=e=>Ke({...kt("frame",e),type:"frame",name:e?.name||null},{}),Rc=e=>Ke({...kt("magicframe",e),type:"magicframe",name:e?.name||null},{}),ma=e=>({x:e.textAlign==="center"?.5:e.textAlign==="right"?1:0,y:e.verticalAlign===si.MIDDLE?.5:e.verticalAlign===si.BOTTOM?1:0}),zc=(e,t)=>{let n=ma(e);return{x:t.width*n.x,y:t.height*n.y}},ai=e=>{let t=e.fontFamily||Og,n=e.fontSize||Ng,i=e.lineHeight||Ug(t),o=Ki(e.text),r=ft(o,br({fontFamily:t,fontSize:n}),i),s=e.textAlign||Fg,a=e.verticalAlign||Rg,l=zc({textAlign:s,verticalAlign:a},r),d={...kt("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,labelPosition:e.labelPosition??null};return Ke(d,{})},Yg=(e,t,n)=>{let{width:i,height:o}=ft(n,br(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===si.MIDDLE&&!e.containerId&&e.autoResize){let d=ft(e.text,br(e),e.lineHeight),c=zc(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]=Z(e,t),[p,h,f,g]=yn(e,i,o,!1),E=(d-p)/2,x=(c-h)/2,b=(u-f)/2,y=(m-g)/2;[a,l]=Xg({n:s===si.MIDDLE||s===si.BOTTOM,s:s===si.MIDDLE||s===si.TOP,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,E,x,b,y)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},Xg=(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]},yM=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=sn(i,br(e),t?vt(t,e):e.width));let o=Yg(e,n,i);return{text:i,...o}},PM=e=>({...kt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,strokeOptions:e.strokeOptions??{variability:"variable",streamline:zg}}),_c=e=>{let t={...kt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Oe(t)?{...t,polygon:e.polygon??!1}:t},wr=e=>e.elbowed?{...kt(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}:{...kt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},Hc=e=>({...kt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var CM=(e,t,n,i)=>{for(let o=t.length-1;o>=0;o--){let r=t[o];if(!(!U(r)||r.locked||r.points.length<2))for(let s of["end","start"]){if(r[s==="start"?"startBinding":"endBinding"]||Uc(r.points[s==="start"?0:r.points.length-1],r.points[s==="start"?1:r.points.length-2]))continue;let a=R.getPointAtIndexGlobalCoordinates(r,s==="start"?0:-1,n);if(jg(e,a)*i.value<R.POINT_HANDLE_SIZE+1)return{arrow:r,startOrEnd:s}}}return null},GM=(e,t,n,i)=>{let o=R.getPointAtIndexGlobalCoordinates(e,t==="start"?0:-1,n),r=R.getPointAtIndexGlobalCoordinates(e,t==="start"?1:-2,n);if(Uc(o,r))return null;let s=Wc(o,r),a=Math.abs(s[0])>=Math.abs(s[1])?s[0]>=0?he:Ne:s[1]>=0?Le:Ze,l=X(e)?0:Be({strokeWidth:i},e),d=Kg(Wc(r,o)),c=Math.abs(Zg(d,Vg(a[0],a[1]))),u=$g(qg(d,-l/c),o);return fe(a,he)?{fixedPoint:He([0,.5]),anchor:u,textAlign:yr.LEFT,verticalAlign:Pr.MIDDLE}:fe(a,Ne)?{fixedPoint:He([1,.5]),anchor:u,textAlign:yr.RIGHT,verticalAlign:Pr.MIDDLE}:fe(a,Le)?{fixedPoint:He([.5,0]),anchor:u,textAlign:yr.CENTER,verticalAlign:Pr.TOP}:{fixedPoint:He([.5,1]),anchor:u,textAlign:yr.CENTER,verticalAlign:Pr.BOTTOM}},kM=(e,t)=>!!e.boundElements?.some(({id:n,type:i})=>{if(i!=="arrow")return!1;let o=t.get(n);return U(o)&&(o.startBinding?.elementId===e.id||o.endBinding?.elementId===e.id)}),OM=e=>{let t=ma(e).x;return{anchorRatio:t,anchorX:e.x+e.width*t}};I();import{distanceToLineSegment as Yc,lineSegment as li,lineSegmentIntersectionPoints as Qg,pointDistance as qt,pointFrom as Di,pointRotateRads as Sr,polygonArea as mo,polygonIncludesPoint as Xc,polygonIncludesPointNonZero as Ir,polygonSignedArea as fa}from"@excalidraw/math";import{isOpaqueColor as Jg,isTransparent as po}from"@excalidraw/common";var eE=6,tE=2,nE=2,iE=.5,oE={snapEpsilon:.5,gapTolerance:eE,minArea:4,maxBoundarySegments:2560,maxGeneratedPoints:1536,fallbackSearchRadius:512},Zc=([e,t,n,i],o)=>[e-o,t-o,n+o,i+o],rE=e=>qt(e[0],e[1]),uo=(e,t,n)=>{let i=t[0]-e[0],o=t[1]-e[1],r=i*i+o*o;return r===0?0:((n[0]-e[0])*i+(n[1]-e[1])*o)/r},jc=(e,t,n,i,o)=>{let r=Math.min(e[0],t[0]),s=Math.max(e[0],t[0]),a=t[0]-e[0],l=t[1]-e[1],d=Math.floor((r-n)/i),c=Math.floor((s+n)/i);for(let u=d;u<=c;u++){let m=e[1],p=t[1];if(a!==0){let g=(Math.max(r,u*i-n)-e[0])/a,E=(Math.min(s,(u+1)*i+n)-e[0])/a;m=e[1]+g*l,p=e[1]+E*l}let h=Math.floor((Math.min(m,p)-n)/i),f=Math.floor((Math.max(m,p)+n)/i);for(let g=h;g<=f;g++)o(u,g)}},sE=(e,t,n)=>{let i=n[0]-t[0],o=n[1]-t[1],r=Math.hypot(i,o);return r===0?qt(e,t):Math.abs((e[0]-t[0])*o-(e[1]-t[1])*i)/r},Ti=(e,t,n)=>Di(e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n),aE=(e,t)=>{let n=e;for(let[i,o]of t){let r=[];for(let[s,a]of n){if(o<=s||i>=a){r.push([s,a]);continue}i>s&&r.push([s,i]),o<a&&r.push([o,a])}n=r}return n},lE=(e,t)=>{let n=se(e,t),o=(e.roundness&&e.points.length>2?It(Ao(e.points),.15,iE):e.points).map(s=>Sr(Di(e.x+s[0],e.y+s[1]),n,e.angle)),r=[];for(let s=0;s<o.length-1;s++)r.push(li(o[s],o[s+1]));return r},dE=(e,t)=>{let n=se(e,t),i=Tc(e).map(r=>Sr(Di(e.x+r[0],e.y+r[1]),n,e.angle)),o=[];for(let r=0;r<i.length-1;r++)o.push(li(i[r],i[r+1]));return o},cE=(e,t,n,i,o,r)=>{let s=[[0,1]];for(let a of n){if(s.length===0)break;let d=[0,...ot(a,i,li(e,t)).map(u=>uo(e,t,u)).filter(u=>u>0&&u<1).sort((u,m)=>u-m),1],c=[];for(let u=0;u<d.length-1;u++){let m=d[u],p=d[u+1];if(p-m<1e-9)continue;let h=Ti(e,t,(m+p)/2);it(h,a,i)&&Ut(a,i,h)>r&&c.push([m,p])}c.length&&(s=aE(s,c))}return s.filter(([a,l])=>qt(Ti(e,t,a),Ti(e,t,l))>=o).map(([a,l])=>[Ti(e,t,a),Ti(e,t,l)])},ha=class{constructor(t){this.eps=t;this.cellSize=Math.max(t,1)}nodes=[];cells=new Map;cellSize;cellKey(t,n){return`${t}:${n}`}getOrCreate(t){let n=Math.floor(t[0]/this.cellSize),i=Math.floor(t[1]/this.cellSize);for(let a=-1;a<=1;a++)for(let l=-1;l<=1;l++){let d=this.cells.get(this.cellKey(n+a,i+l));if(d){for(let c of d)if(qt(this.nodes[c],t)<=this.eps)return c}}let o=this.nodes.length;this.nodes.push(t);let r=this.cellKey(n,i),s=this.cells.get(r);return s?s.push(o):this.cells.set(r,[o]),o}forEachInRadius(t,n,i){let o=Math.floor((t[0]-n)/this.cellSize),r=Math.floor((t[0]+n)/this.cellSize),s=Math.floor((t[1]-n)/this.cellSize),a=Math.floor((t[1]+n)/this.cellSize);for(let l=o;l<=r;l++)for(let d=s;d<=a;d++){let c=this.cells.get(this.cellKey(l,d));if(c)for(let u of c)i(u)}}},$c=e=>!(!gi(e.type)||e.fillStyle!=="solid"||e.opacity<100||!Jg(e.backgroundColor)||(Oe(e)||be(e))&&!Tt(e.points)),Kc=new Set(["rectangle","diamond","ellipse","frame","magicframe","line","freedraw"]),ga=e=>e.opacity<=0,qc=e=>!ga(e)&&(e.type==="image"||!po(e.strokeColor)||gi(e.type)&&!po(e.backgroundColor)),Qc=e=>Oe(e)&&e.polygon&&ns(e.points)&&!ga(e)&&!po(e.backgroundColor)&&po(e.strokeColor),uE=e=>Kc.has(e.type)?Oe(e)?e.polygon&&ns(e.points):be(e)?Tt(e.points):!0:!1,pa=e=>!ga(e)&&Kc.has(e.type)&&!po(e.strokeColor),mE=(e,t,n)=>{for(let i=t.length-1;i>=0;i--){let o=t[i];if(!(!qc(o)||Qc(o))&&uE(o)&&it(e,o,n))return o}return null},pE=(e,t)=>{let n=t.snapEpsilon,i=new ha(n),o=[],r=new Map;for(let{segment:D,elementId:L}of e){let P=i.getOrCreate(D[0]),v=i.getOrCreate(D[1]);if(r.has(P)||r.set(P,L),r.has(v)||r.set(v,L),P===v)continue;let C=i.nodes[P],z=i.nodes[v];o.push({a:P,b:v,pa:C,pb:z,elementId:L,box:[Math.min(C[0],z[0]),Math.min(C[1],z[1]),Math.max(C[0],z[0]),Math.max(C[1],z[1])],splits:[{node:P,t:0},{node:v,t:1}]})}let s=o.map(D=>li(D.pa,D.pb)),a=o.map((D,L)=>L).sort((D,L)=>o[D].box[0]-o[L].box[0]);for(let D=0;D<a.length;D++){let L=a[D],P=o[L],v=P.box[2]+n;for(let C=D+1;C<a.length;C++){let z=a[C],Q=o[z];if(Q.box[0]>v)break;if(!gt(Zc(P.box,n),Q.box))continue;let ee=Qg(s[L],s[z],n);if(!ee)continue;let te=i.getOrCreate(ee);r.has(te)||r.set(te,P.elementId),P.splits.push({node:te,t:uo(P.pa,P.pb,i.nodes[te])}),Q.splits.push({node:te,t:uo(Q.pa,Q.pb,i.nodes[te])})}}if(i.nodes.length>t.maxBoundarySegments*4)return null;let l=1/0,d=1/0,c=-1/0,u=-1/0;for(let D of o)l=Math.min(l,D.box[0]),d=Math.min(d,D.box[1]),c=Math.max(c,D.box[2]),u=Math.max(u,D.box[3]);let m=Math.max(c-l,u-d,0),p=Math.max(n*2,m/128),h=new Map;o.forEach((D,L)=>{jc(D.pa,D.pb,n,p,(P,v)=>{let C=`${P}:${v}`,z=h.get(C);z?z.push(L):h.set(C,[L])})});for(let D=0;D<i.nodes.length;D++){let L=i.nodes[D],P=h.get(`${Math.floor(L[0]/p)}:${Math.floor(L[1]/p)}`);if(P)for(let v of P){let C=o[v];if(D===C.a||D===C.b)continue;let z=uo(C.pa,C.pb,L);z<=0||z>=1||Yc(L,s[v])<=n&&C.splits.push({node:D,t:z})}}let f=new Set,g=new Map,E=new Map,x=(D,L)=>D<L?`${D}-${L}`:`${L}-${D}`,b=(D,L)=>{let P=g.get(D);P?P.push(L):g.set(D,[L])},y=(D,L,P)=>{if(D===L||qt(i.nodes[D],i.nodes[L])<n)return;let v=x(D,L),C=E.get(v);C?C.add(P):E.set(v,new Set([P])),!f.has(v)&&(f.add(v),b(D,L),b(L,D))};for(let D of o){let L=new Map;for(let v of D.splits)L.has(v.node)||L.set(v.node,v.t);let P=[...L.entries()].map(([v,C])=>({node:v,t:C})).sort((v,C)=>v.t-C.t);for(let v=0;v<P.length-1;v++)y(P[v].node,P[v+1].node,D.elementId)}if(f.size===0)return[];let w=Math.max(n,t.gapTolerance),M=D=>new Set(g.get(D)??[]).size===1,S=[];for(let D of g.keys())M(D)&&S.push(D);if(S.length>0){let D=Math.max(w,m/128,1),L=new Map,P=(C,z)=>{let Q={u:C,v:z};jc(i.nodes[C],i.nodes[z],0,D,(ee,te)=>{let ne=`${ee}:${te}`,Ae=L.get(ne);Ae?Ae.push(Q):L.set(ne,[Q])})};for(let C of f){let[z,Q]=C.split("-").map(Number);P(z,Q)}let v=(C,z)=>{let Q=x(C,z);f.delete(Q);let ee=E.get(Q);E.delete(Q);let te=g.get(C),ne=g.get(z);return te?.splice(te.indexOf(z),1),ne?.splice(ne.indexOf(C),1),ee};for(let C of S){if(!M(C))continue;let z=i.nodes[C],Q=g.get(C)??[],ee=-1,te=1/0;i.forEachInRadius(z,w,Ce=>{if(Ce===C||Q.includes(Ce))return;let Te=qt(z,i.nodes[Ce]);Te>=n&&Te<=w&&Te<te&&(te=Te,ee=Ce)});let ne=null,Ae=1/0,Ft=0,Rt=Math.floor(z[0]/D),gn=Math.floor(z[1]/D),pe=new Set;for(let Ce=-1;Ce<=1;Ce++)for(let Te=-1;Te<=1;Te++){let $e=L.get(`${Rt+Ce}:${gn+Te}`);if($e)for(let Qt of $e){let di=x(Qt.u,Qt.v);if(pe.has(di)||(pe.add(di),!f.has(di)||Qt.u===C||Qt.v===C))continue;let Ya=i.nodes[Qt.u],Xa=i.nodes[Qt.v],Rr=uo(Ya,Xa,z);if(Rr<=0||Rr>=1)continue;let zr=Yc(z,li(Ya,Xa));zr<=w&&zr<Ae&&(Ae=zr,ne=Qt,Ft=Rr)}}let ie=r.get(C)??o[0].elementId;if(ne&&Ae<te){let Ce=i.nodes[ne.u],Te=i.nodes[ne.v],$e=i.getOrCreate(Ti(Ce,Te,Ft));if($e===ne.u||$e===ne.v)y(C,$e,ie),P(C,$e);else{r.has($e)||r.set($e,E.get(x(ne.u,ne.v))?.values().next().value??ie);let Qt=v(ne.u,ne.v)??new Set([ie]);for(let di of Qt)y(ne.u,$e,di),y($e,ne.v,di);P(ne.u,$e),P($e,ne.v),y(C,$e,ie),P(C,$e)}}else ee>=0&&(y(C,ee,ie),P(C,ee))}}let T=new Map,A=0;for(let D of g.keys()){if(T.has(D))continue;let L=[D];for(T.set(D,A);L.length;){let P=L.pop();for(let v of g.get(P)??[])T.has(v)||(T.set(v,A),L.push(v))}A++}let F=(D,L)=>Math.atan2(i.nodes[L][1]-i.nodes[D][1],i.nodes[L][0]-i.nodes[D][0]),B=new Map,k=new Map;for(let[D,L]of g){let P=Array.from(new Set(L));P.sort((C,z)=>F(D,C)-F(D,z)),B.set(D,P);let v=new Map;P.forEach((C,z)=>v.set(C,z)),k.set(D,v)}let G=new Set,_=[],W=f.size*2+4;for(let[D,L]of g)for(let P of L){if(G.has(`${D}->${P}`))continue;let v=[],C=D,z=P,Q=0;for(;Q++<=W;){G.add(`${C}->${z}`),v.push(C);let ee=B.get(z),ne=(k.get(z).get(C)-1+ee.length)%ee.length,Ae=ee[ne];if(C=z,z=Ae,C===D&&z===P)break}if(v.length>=3){let ee=new Set;for(let te=0;te<v.length;te++){let ne=E.get(x(v[te],v[(te+1)%v.length]));if(ne)for(let Ae of ne)ee.add(Ae)}_.push({ring:v.map(te=>i.nodes[te]),contributors:ee,componentId:T.get(D)??-1})}}return _},fE=(e,t,n)=>{if(e.length===0)return null;let i=1,o=new Map;for(let c of e)o.set(c,-fa(c.ring,0));let r=null,s=1/0;for(let c of e){let u=o.get(c);if(Math.sign(u)===i)continue;let m=Math.abs(u);m<n.minArea||Ir(t,c.ring)&&m<s&&(s=m,r=c)}if(!r)return null;let a=r,l=e.filter(c=>c.componentId!==a.componentId&&Math.sign(o.get(c))===i&&Math.abs(o.get(c))>=n.minArea&&!Ir(t,c.ring)&&Ir(c.ring[0],a.ring)),d=l.filter(c=>!l.some(u=>u!==c&&Ir(c.ring[0],u.ring)));return{face:a,holes:d}},hE=(e,t)=>{let n=[];for(let i of e)(n.length===0||qt(n[n.length-1],i)>=t)&&n.push(i);for(;n.length>1&&qt(n[0],n[n.length-1])<t;)n.pop();return n},gE=(e,t)=>{if(e.length<=3)return e;let n=[];for(let i=0;i<e.length;i++){let o=n[n.length-1]??e[e.length-1],r=e[(i+1)%e.length];sE(e[i],o,r)>=t&&n.push(e[i])}return n.length>=3?n:e},Vc=(e,t,n)=>{let i=hE(e,t.snapEpsilon);if(i.length<3)return null;let o=.75,r=bn(i,o);for(;r.length>n&&o<1e6;)o*=2,r=bn(i,o);return r.length>n?null:(r=gE(r,.05),r.length>=3?r:null)},EE=(e,t)=>{let n=Math.sign(fa(t,0))===Math.sign(fa(e,0))?[...t].reverse():t,i=0,o=0,r=1/0;for(let a=0;a<e.length;a++)for(let l=0;l<n.length;l++){let d=qt(e[a],n[l]);d<r&&(r=d,i=a,o=l)}let s=e.slice(0,i+1);for(let a=0;a<=n.length;a++)s.push(n[(o+a)%n.length]);return s.push(e[i]),s.push(...e.slice(i+1)),s},xE=(e,t,n)=>{let i=Vc(e,n,n.maxGeneratedPoints);if(!i)return null;let o=t.map((s,a)=>({holeRing:s,index:a})).sort((s,a)=>mo(a.holeRing,0)-mo(s.holeRing,0)),r=[];for(let{holeRing:s,index:a}of o){let l=n.maxGeneratedPoints-i.length-2;if(l<3)break;let d=Vc(s,n,l);d&&(i=EE(i,d),r.push(a))}return{scenePoints:[...i,i[0]],splicedHoleIndices:r}},ZM=e=>{let t={...oE,...e.options},{point:n,elements:i,elementsMap:o}=e,r=mE(n,i,o),s=new Map;i.forEach((B,k)=>s.set(B.id,k));let a=(B,k)=>{let G=P=>gt(B,ue(P,o)),_=i.filter(P=>P.id!==k?.id&&pa(P)&&G(P)),W=i.filter(P=>$c(P)&&G(P)),D=[],L=P=>{let v=s.get(P.id)??0,C=W.filter(ee=>ee.id!==P.id&&(s.get(ee.id)??0)>v),z=Math.max(t.snapEpsilon,P.strokeWidth/2,nE),Q=Oe(P)?lE(P,o):be(P)?dE(P,o):Si(P,o);if((P.type==="freedraw"||Oe(P)&&!P.polygon)&&Tt(P.points)&&Q.length>0){let ee=Q[0][0],te=Q[Q.length-1][1];qt(ee,te)>=t.snapEpsilon&&Q.push(li(te,ee))}for(let ee of Q){if(D.length>t.maxBoundarySegments)return;if(rE(ee)!==0){if(C.length===0){D.push({segment:ee,elementId:P.id});continue}for(let[te,ne]of cE(ee[0],ee[1],C,o,t.snapEpsilon,z))D.push({segment:li(te,ne),elementId:P.id})}}};for(let P of k?[k,..._]:_){if(D.length>t.maxBoundarySegments)break;L(P)}return D.length>t.maxBoundarySegments?null:D},l=B=>{let k=pE(B,t);return k?fE(k,n,t):"too_complex"},d=null;if(r){let B=t.gapTolerance+2+Math.max(r.strokeWidth??1,1),k=Zc(ue(r,o),B),G=a(k,r);if(!G)return{ok:!1,reason:"too_complex"};let _=l(G);if(_==="too_complex")return{ok:!1,reason:"too_complex"};if(!_)return{ok:!1,reason:"open_region"};d=_}else{let B=i.reduce((G,_)=>G+(pa(_)?1:0),0);if(B===0)return{ok:!1,reason:"no_owner"};let k=t.fallbackSearchRadius;for(let G=0;G<4&&!d;G++,k*=2){let _=[n[0]-k,n[1]-k,n[0]+k,n[1]+k],W=i.reduce((v,C)=>v+(pa(C)&>(_,ue(C,o))?1:0),0),D=G===3||W===B;if(W===0)continue;let L=a(_,null);if(!L)return{ok:!1,reason:"no_owner"};let P=l(L);if(P==="too_complex")return{ok:!1,reason:"no_owner"};if(P&&(D||P.face.ring.every(v=>v[0]>_[0]+t.gapTolerance&&v[1]>_[1]+t.gapTolerance&&v[0]<_[2]-t.gapTolerance&&v[1]<_[3]-t.gapTolerance))&&(d=P),!d&&D)break}if(!d)return{ok:!1,reason:"no_owner"}}let{face:c,holes:u}=d,m=xE(c.ring,u.map(B=>B.ring),t);if(!m)return{ok:!1,reason:"invalid_polygon"};let{scenePoints:p,splicedHoleIndices:h}=m;if(mo(p,0)<t.minArea)return{ok:!1,reason:"too_small"};let f=new Set(c.contributors);for(let B of h)for(let k of u[B].contributors)f.add(k);let g=new Set(r?[r.id,...f]:f);for(let B of u)for(let k of B.contributors)g.add(k);let E=p,[x,b,y,w]=ri(p),M=B=>{let[k,G,_,W]=ue(B,o);if(_<x||k>y||W<b||G>w)return!1;let D=[Di((k+_)/2,(G+W)/2)];if(K(B)||be(B)){let L=se(B,o),P=Math.max(1,Math.floor(B.points.length/8));for(let v=0;v<B.points.length;v+=P)D.push(Sr(Di(B.x+B.points[v][0],B.y+B.points[v][1]),L,B.angle))}return D.some(L=>Xc(L,E))},S=B=>{let[k,G,_,W]=ue(B,o);if(_<x||k>y||W<b||G>w)return!1;if(it(n,B,o))return!0;let D=Si(B,o),L=Math.max(1,Math.floor(D.length/16));for(let v=0;v<D.length;v+=L)if(Xc(D[v][0],E))return!0;let P=Math.max(1,Math.floor(p.length/16));for(let v=0;v<p.length;v+=P)if(it(p[v],B,o))return!0;return!1},T=null,A=null;for(let B of i)$c(B)&&S(B)&&(A=B),(g.has(B.id)||qc(B)&&M(B))&&(T=T??B);let F=A?{placement:"above",elementId:A.id}:{placement:"below",elementId:(T??i[i.length-1]).id};return{ok:!0,ownerId:r?.id??null,boundaryElementIds:[...f].filter(B=>B!==r?.id),scenePoints:p,insertion:F}},KM=e=>{let{hitElement:t,scenePoints:n,elementsMap:i}=e;if(!Qc(t))return!1;let o=se(t,i),r=t.points.map(b=>Sr(Di(t.x+b[0],t.y+b[1]),o,t.angle)),s=mo(r,0),a=mo(n,0),l=Math.abs(s-a)<=.05*Math.max(s,a),[d,c,u,m]=ri(r),[p,h,f,g]=ri(n),E=tE,x=Math.abs(d-p)<=E&&Math.abs(c-h)<=E&&Math.abs(u-f)<=E&&Math.abs(m-g)<=E;return l&&x};I();import{arrayToMap as ux,arrayToObject as fn,assertNever as xu,isDevEnv as Wn,isShallowEqual as bu,isTestEnv as Un,randomInteger as Eu}from"@excalidraw/common";I();import{assertNever as vE,COLOR_PALETTE as BE,isDevEnv as LE,isTestEnv as CE,randomId as GE,Emitter as tu,toIterable as Bi}from"@excalidraw/common";I();import{ORIG_ID as PE,randomId as eu,randomInteger as IE,arrayToMap as SE,castArray as Ea,findLastIndex as vi,getUpdatedTimestamp as ME,isTestEnv as AE}from"@excalidraw/common";I();import{arrayToMap as bE}from"@excalidraw/common";var wE=e=>{let t=(o,r)=>o.groupIds[o.groupIds.length-r-1],n=(o,r)=>{let s=new Map,a=[];for(let l of o){let d=t(l,r);if(d===void 0){a.push(l);continue}let c=s.get(d);c||(c=[],s.set(d,c),a.push(d)),c.push(l)}return a.flatMap(l=>typeof l=="string"?n(s.get(l),r+1):[l])},i=n(e,0);return i.length!==e.length?(console.error("defragmentGroups: lost some elements... bailing!"),e):i},yE=e=>{let t=bE(e),n=new Set;for(let i of e)if(!n.has(i)){if(i.boundElements?.length){n.add(i);for(let o of i.boundElements){let r=t.get(o.id);r&&o.type==="text"&&n.add(r)}continue}i.type==="text"&&i.containerId&&t.get(i.containerId)?.boundElements?.some(o=>o.id===i.id)||n.add(i)}return n.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...n]},Jc=e=>yE(wE(e));var TE=(e,t,n,i)=>{let o=ba(n);return AE()&&DE(o,n.id),o.id=eu(),o.updated=ME(),i&&(o.seed=IE(),Pd(o)),o.groupIds=ic(o.groupIds,e,r=>(t.has(r)||t.set(r,eu()),t.get(r))),o},uA=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=SE(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(E=>[E.id,E])),m=e.type==="everything"&&e.preserveFrameChildrenOrder;if(e.type==="in-place")for(let E of Object.keys(e.appState.selectedGroupIds))t.filter(x=>x.groupIds?.includes(E)).forEach(x=>u.set(x.id,x));t=Jc(t);let p=t.slice(),h=E=>{let b=Ea(E).reduce((y,w)=>{if(i.has(w.id))return y;i.set(w.id,!0),Ve(w)||console.error("[NONDELETED][INVARIANT] Element to duplicate should be non-deleted");let M=TE(n.editingGroupId,o,w,e.randomizeSeed);return i.set(M.id,!0),d.set(M.id,M),a.set(w.id,M.id),l.set(M.id,w),s.push(w),r.push(M),y.push(M),y},[]);return Array.isArray(E)?b:b[0]||null},f=(E,x)=>{if(x){if(E>p.length-1){p.push(...Ea(x));return}p.splice(E+1,0,...Ea(x))}},g=new Set(t.filter(E=>u.has(E.id)&&J(E)).map(E=>E.id));for(let E of t){if(i.has(E.id)||!u.has(E.id))continue;let x=$s(n,E);if(x){let b=Qe(t,x).flatMap(w=>J(w)&&!m?[...Ln(t,w.id),w]:[w]),y=vi(p,w=>w.groupIds?.includes(x));f(y,h(b));continue}if(!(!m&&E.frameId&&g.has(E.frameId))){if(J(E)){let b=E.id;if(m){f(vi(p,M=>M.id===b),h(E));continue}let y=Ln(t,b),w=vi(p,M=>M.frameId===b||M.id===b);f(w,h([...y,E]));continue}if(_t(E)){let b=re(E,c),y=vi(p,w=>w.id===E.id||"containerId"in w&&w.containerId===E.id);b?f(y,h([E,b])):f(y,h(E));continue}if(Ie(E)){let b=We(E,c),y=vi(p,w=>w.id===E.id||w.id===b?.id);b?f(y,h([b,E])):f(y,h(E));continue}f(vi(p,b=>b.id===E.id),h(E))}}if(Gd(r,a,d),uc(p,s,a),e.overrides)for(let E of r){let x=l.get(E.id);x&&Object.assign(E,e.overrides({duplicateElement:E,origElement:x,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:p,origIdToDuplicateId:a}},xa=(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]=xa(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=xa(e[i],t+1);return o}return N.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},ba=e=>xa(e),DE=(e,t)=>{Object.defineProperty(e,PE,{value:t,writable:!1,enumerable:!1})};var ut={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},nu=class{constructor(t){this.app=t}onDurableIncrementEmitter=new tu;onStoreIncrementEmitter=new tu;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Hn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(ut.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=Hn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?dc(t.elements):void 0,t.appState);i=fo.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=Hn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=fo.create(o,t),i?s=i:s=Pa.calculate(o,t),!s.isEmpty()){let a=new wa(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=fo.create(r,t)}let o=new ya(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===ut.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 ut.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case ut.NEVER:case ut.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:vE(n,"Unknown store action")}}finally{switch(n){case ut.IMMEDIATELY:case ut.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(ut.IMMEDIATELY)?t=ut.IMMEDIATELY:this.scheduledMacroActions.has(ut.NEVER)?t=ut.NEVER:t=ut.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(ut).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()),CE()||LE())throw new Error(t)}}},fo=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)}},Mr=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},wa=class extends Mr{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},ya=class extends Mr{constructor(n){super("ephemeral",n);this.change=n}},Pa=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:GE()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?_n.calculate(t.elements,n.elements):_n.empty(),o=n.metadata.didAppStateChange?zn.calculate(t.appState,n.appState):zn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,_n.restore(i),zn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=_n.create(n,i,o),a=zn.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,Hn.empty().elements,o),[a,l]=t.appState.applyTo(i,r);return[r,a,s||l]}static applyLatestChanges(t,n,i,o){return this.create(t.elements.applyLatestChanges(n,i,o),t.appState,{id:t.id})}static empty(){return e.create(_n.empty(),zn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Hn=class e{constructor(t,n,i={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=i}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,i={didElementsChange:!1,didAppStateChange:!1}){return new e(t,iu(n)?n:Li(n),i)}static empty(){return new e(new Map,kE(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of Bi(t.elements))this.elements.get(i.id)||(n[i.id]=Ke(i,{isDeleted:!0}));for(let i of Bi(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=Li({...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===ut.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=iu(t)?t:Li(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=su(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 Bi(this.elements))t.get(r.id)||i.set(r.id,Ke(r,{isDeleted:!0}));for(let r of Bi(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(ke(r)&&!Zn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=ru(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of Bi(this.elements))n.set(i.id,i);for(let i of Bi(t))n.set(i.id,ba(i));return n}},ou="__observedAppState",kE=()=>({name:null,editingGroupId:null,viewBackgroundColor:BE.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),Li=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,ou,{value:!0,enumerable:!1}),t},iu=e=>!!Reflect.get(e,ou);I();var gu=gm(uu(),1);import{randomInteger as QE,arrayToMap as JE,toBrandedType as mu,isDevEnv as pu,isTestEnv as fu,toArray as ex}from"@excalidraw/common";import{isNonDeletedElement as tx}from"@excalidraw/element";import{isFrameLikeElement as nx}from"@excalidraw/element";import{getElementsInGroup as ix}from"@excalidraw/element";import{syncInvalidIndices as ox,syncMovedIndices as rx,validateFractionalIndices as sx}from"@excalidraw/element";import{getSelectedElements as ax}from"@excalidraw/element";import{mutateElement as lx}from"@excalidraw/element";var hu=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}},dx=(0,gu.default)(e=>{(pu()||fu()||window?.DEBUG_FRACTIONAL_INDICES)&&sx(e,{shouldThrow:pu()||fu(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),cx=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Ci=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=mu(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=mu(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=cx(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=ax(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&&tx(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=ex(t),o=[];n?.skipValidation||dx(i),this.elements=ox(i),this.elementsMap.clear(),this.elements.forEach(s=>{nx(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=hu(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=hu(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=QE();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementsAtIndex(t,n){if(!t.length)return;if(n===null&&(n=this.elements.length),!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];rx(i,JE(t)),this.replaceAllElements(i)}insertElement=t=>{this.insertElementsAtIndex([t],null)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),i=n.get(t);return i?[i]:ix(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=lx(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(fn(t??[],o),fn(n??[],o),fn(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=fn(e.getLeftDifferences(fn(r,o),fn(s,o)),d=>d),l=fn(e.getRightDifferences(fn(r,o),fn(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)])):xu(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&&bu(a,l))continue;yield s}}}},zn=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),h=d&&n.has(d.elementId)?new R(n.get(d.elementId),n,d.isEditing):null,f={...t,...c,selectedElementIds:u,selectedGroupIds:m,lockedMultiSelections:p,selectedLinearElement:typeof d<"u"?h:t.selectedLinearElement},g=this.filterInvisibleChanges(t,f,n);return[f,g]}catch(i){if(console.error("Couldn't apply appstate change",i),Un()||Wn())throw i;return[t,!1]}}isEmpty(){return $.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=Li(t),r=Li(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=ec(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let b=i.get(x);b&&!b.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let 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 h=t[u]||{},f=n[u]||{};bu(h,f)||(l.value=!0);break;case"activeLockedId":let g=t[u]||null,E=n[u]||null;g!==E&&(l.value=!0);break;default:xu(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."),Un()||Wn())throw i}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let i of Object.keys(t).sort())n[i]=t[i];return n}},_n=class e{constructor(t,n,i){this.added=t;this.removed=n;this.updated=i}static create(t,n,i,o={shouldRedistribute:!1}){let r;if(o.shouldRedistribute){let s={},a={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(i)];for(let[c,u]of d)this.satisfiesAddition(u)?s[c]=u:this.satisfiesRemoval(u)?a[c]=u:l[c]=u;r=new e(s,a,l)}else r=new e(t,n,i);return(Un()||Wn())&&(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:Eu()},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:Eu()},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 h={};for(let f of Object.keys(u))switch(f){case"boundElements":h[f]=u[f];break;default:h[f]=p[f]}return h},r=d=>{let c={};for(let[u,m]of Object.entries(d)){let p=t.get(u),h=n.get(u),f=null;p||h?f=$.create(m.deleted,m.inserted,o(p,h),i):f=m,$.isInnerDifferent(f.deleted,f.inserted)&&(c[u]=f)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=Hn.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),Un()||Wn())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),Un()||Wn())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(Un()||Wn())&&(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=Ke({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),Ke(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=Ke(d,{...m,version:u},!0):p=Ue(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=>kd.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);vn.unbindAffected(n,r(),o),vn.unbindAffected(n,s(),o),Bn.unbindAffected(n,r(),o),Bn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);vn.unbindAffected(n,r(),o),vn.rebindAffected(n,s(),o),Bn.unbindAffected(n,r(),(a,l)=>{oe(a)&&o(a,l)}),Bn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Ci(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),Un()||Wn())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(Ie(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(_t(r)){let s=Bt(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||Yo(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&we(i)&&je(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=lc([...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),ux(ni(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."),Un()||Wn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};I();var ZA=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=mn(e),c=dr(e,t,i).map(On).map(h=>[h,mn(h)]).sort((h,f)=>h[1][s]-f[1][s]),u=0;for(let h of c)u+=h[1][l];let m=(d[l]-u)/(c.length-1);if(m<0){let h=c.findIndex(x=>x[1][r]===d[r]),f=c.findIndex(x=>x[1][a]===d[a]),g=(c[f][1][s]-c[h][1][s])/(c.length-1),E=c[h][1][s];return c.flatMap(([x,b],y)=>{let w={x:0,y:0};return y!==h&&y!==f&&(E+=g,w[n.axis]=E-b[s]),x.map(M=>{let S=o.mutateElement(M,{x:M.x+w.x,y:M.y+w.y});return je(M,o,{simultaneouslyUpdated:x}),S})})}let p=d[r];return c.flatMap(([h,f])=>{let g={x:0,y:0};return g[n.axis]=p-f[r],p+=m,p+=f[l],h.map(E=>{let x=o.mutateElement(E,{x:E.x+g.x,y:E.y+g.y});return je(E,o,{simultaneouslyUpdated:h}),x})})};I();import{TEXT_AUTOWRAP_THRESHOLD as mx,getGridPoint as px,getFontString as fx,DRAGGING_THRESHOLD as hx}from"@excalidraw/common";var rT=(e,t,n,i,o,r)=>{if(t.length===1&&X(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(X(m)&&m.startBinding&&m.endBinding){let p=t.find(f=>f.id===m.startBinding?.elementId),h=t.find(f=>f.id===m.endBinding?.elementId);return p&&h}return!0}),a=new Set(s),l=s.filter(m=>J(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=gx(Je(d),n,o,r),u=new Set(Array.from(a,m=>m.id));a.forEach(m=>{let p=!U(m),h=p||(m.startBinding?u.has(m.startBinding.elementId):!1),f=p||(m.endBinding?u.has(m.endBinding.elementId):!1);if(U(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>hx||!m.startBinding&&!m.endBinding){Sa(e,m,i,c);let g=m.startBinding&&!h,E=m.endBinding&&!f;(g||E)&&(g&&Xe(m,"start",i),E&&Xe(m,"end",i))}}else{Sa(e,m,i,c);let g=re(m,i.getNonDeletedElementsMap());g&&Sa(e,g,i,c),je(m,i,{simultaneouslyUpdated:Array.from(a)})}})},gx=(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]=px(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Sa=(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})},sT=(e,t,n)=>{let[i,o]=Je(e);return[t-i,n-o]},Ex=({newElement:e,anchorX:t,anchorRatio:n,pointerX:i,nextY:o,zoom:r,scene:s,informMutation:a=!0})=>{let l=i-t,d=n===0?l:n===1?-l:Math.abs(l),c=Math.max(n===.5?d*2:d,_o(fx({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight));s.mutateElement(e,{x:t-c*n,...o===void 0?{}:{y:o},width:c,...d>mx/r?{autoResize:!1}:{}},{informMutation:a,isDragging:!1})},aT=({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:h=!0})=>{if(l&&e.type!=="selection"&&(m?a=s/m:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=ua(t,a,o<n?-s:s):{width:s,height:a}=ua(t,s,r<i?-a:a),a<0&&(a=-a))),oe(e)){Ex({newElement:e,anchorX:n+(p?.x??0),anchorRatio:d?.5:o<n?1:0,pointerX:o,nextY:i+(p?.y??0),zoom:c,scene:u,informMutation:h});return}let f=o<n?n-s:n,g=r<i?i-a:i;if(d&&(s+=s,a+=a,f=n-s/2,g=i-a/2),s!==0&&a!==0){let E=null;ke(e)&&(E={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:f+(p?.x??0),y:g+(p?.y??0),width:s,height:a,...E},{informMutation:h,isDragging:!1})}};I();import{ELEMENT_LINK_KEY as Tr,normalizeLink as wu}from"@excalidraw/common";var mT=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Tr,e),wu(i.toString())}catch(i){console.error(i)}return wu(n)},pT=(e,t)=>{if(e.length>0&&xx(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},xx=e=>!!(e.length===1||e.length>1&&tc(e)),fT=e=>{try{let t=new URL(e);return t.searchParams.has(Tr)&&t.host===window.location.host}catch{return!1}},hT=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Tr))return t.get(Tr)}catch{}return null};I();import{FONT_FAMILY as bx,VERTICAL_ALIGN as wx,escapeDoubleQuotes as Ma,getFontString as yx}from"@excalidraw/common";var Ot=new Map,Px=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,Ix=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Sx=/^https:\/\/(?:www\.)?figma\.com/,yu=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Mx=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Ax=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Pu=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,Tx=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,Dx=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,vx=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Iu=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Su=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,Bx=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Au=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)},Lx=e=>{try{let t=new URL(e.startsWith("http")?e:`https://${e}`);if(t.hostname.replace(/^www\./,"")!=="drive.google.com")return null;let i=null,o=t.pathname.match(/^\/file\/d\/([^/]+)(?:\/|$)/);if(o?.[1]?i=o[1]:(t.pathname==="/open"||t.pathname==="/uc")&&(i=t.searchParams.get("id")),!i||!/^[a-zA-Z0-9_-]+$/.test(i))return null;let r=t.searchParams.get("resourcekey"),s=Au(t.toString());return{fileId:i,resourceKey:r&&/^[a-zA-Z0-9_-]+$/.test(r)?r:void 0,timestamp:s>0?s:void 0}}catch{return null}},Ta=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Mu=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),Aa=e=>`<html><body>${e}</body></html>`,PT=e=>{if(!e)return null;if(Ot.has(e))return Ot.get(e);let t=e,n=Mu.has(Da(e,Mu)||""),i="generic",o={w:560,h:840},r=e.match(Px);if(r?.[2]){let c=Au(t),u=c>0?`&start=${c}`:"",m=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${u}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break}return o=m?{w:315,h:560}:{w:560,h:315},Ot.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(Ix);if(s?.[1]){let c=s?.[1],u=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${c}?api=1`,o={w:560,h:315},Ot.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=Lx(e);if(a){i="video";let c=new URLSearchParams;a.resourceKey&&c.set("resourcekey",a.resourceKey),a.timestamp&&c.set("t",`${a.timestamp}`);let u=c.toString();return e=`https://drive.google.com/file/d/${a.fileId}/preview${u?`?${u}`:""}`,o={w:560,h:315},Ot.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(Sx))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},Ot.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(Dx);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),Ot.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(Ax.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Pu.test(e)){let c=e.match(Pu)[1],u=Ma(`https://twitter.com/x/status/${c}`),m={type:"document",srcdoc:p=>Aa(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${u}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return Ot.set(t,m),m}if(Su.test(e)){let[,c,u,m]=e.match(Su),p=Ma(`https://reddit.com/r/${c}/comments/${u}/${m}`),h={type:"document",srcdoc:f=>Aa(`<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 Ot.set(t,h),h}if(yu.test(e)){let[,c,u]=e.match(yu),m=Ma(`https://gist.github.com/${c}/${u}`),p={type:"document",srcdoc:()=>Aa(`
|
|
22
22
|
<script src="${m}.js"><\/script>
|
|
23
23
|
<style type="text/css">
|
|
24
24
|
* { margin: 0px; }
|
|
25
25
|
table, .gist { height: 100%; }
|
|
26
26
|
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
|
|
27
27
|
</style>
|
|
28
|
-
`),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return Et.set(e,p),p}return Et.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},hS=e=>{let t;go(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=Og.Helvetica,o=Fg({fontSize:n,fontFamily:i});return Vn({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:Ht(t,o,e.width-20),textAlign:"center",verticalAlign:kg.MIDDLE,angle:e.angle??0})},Vs=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if($s.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return $s.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},gS=e=>{let t=e.match(Ug);if(t&&t.length===2)return t[1];let n=e.match(jg);if(n&&n.length===2)return n[1];let i=e.match(Hg);if(i&&i.length===2)return i[1];if(Sc.test(e))return`https://giphy.com/embed/${Sc.exec(e)[1]}`;let o=e.match(Yg);return o&&o.length===2?o[1]:e},ES=(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(Vs(e,n))return!0;return!1}}return!!Vs(e,$s)};P();import{KEYS as nr,invariant as ir,toBrandedType as $g}from"@excalidraw/common";import{pointFrom as vc}from"@excalidraw/math";var hi=100,Zn=100,LS=e=>{switch(e){case nr.ARROW_UP:return"up";case nr.ARROW_DOWN:return"down";case nr.ARROW_RIGHT:return"right";case nr.ARROW_LEFT:return"left";default:return"right"}},Lc=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(W(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;ir(fe(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=Fi(t,st(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=>Ee(r.heading,et)).map(r=>r.relative);case"down":return o.filter(r=>Ee(r.heading,Ae)).map(r=>r.relative);case"right":return o.filter(r=>Ee(r.heading,xe)).map(r=>r.relative);case"left":return o.filter(r=>Ee(r.heading,je)).map(r=>r.relative)}},Zs=(e,t,n)=>Lc("successors",e,t,n),qs=(e,t,n)=>Lc("predecessors",e,t,n),Vg=(e,t,n)=>{let i=Zn+e.width;if(n==="up"||n==="down"){let a=hi+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:(Zn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=hi+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=hi+e.height,r=(t.length===0,Zn+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}},Zg=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=Zs(e,o,n),s=qs(e,o,n),a=Vg(e,[...r,...s],n),l=$n({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});ir(Tr(l),"not an ExcalidrawFlowchartNodeElement");let d=Cc(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},qg=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=hi*(o-1)+o*e.height,m=e.y+e.height/2-u/2,p=Zn+e.width;n==="left"&&(p*=-1),a=e.x+p;let h=(hi+e.height)*s;l=m+h}else{let u=Zn*(o-1)+o*e.width,m=e.x+e.width/2-u/2,p=hi+e.height;n==="up"&&(p*=-1),l=e.y+p;let h=(Zn+e.width)*s;a=m+h}let d=$n({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});ir(Tr(d),"not an ExcalidrawFlowchartNodeElement");let c=Cc(e,d,n,t,i);r.push(d),r.push(c)}return r},Cc=(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=tr({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:[vc(0,0),vc(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();Tt(c,e,"orbit","start",o),Tt(c,t,"orbit","end",o);let m=new Map;m.set(e.id,e),m.set(t.id,t),m.set(c.id,c),G.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=si(c,$g(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p}},Dc=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(!fe(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=[...Zs(t,n,i),...qs(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=>[...Zs(t,n,a),...qs(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}},Bc=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}=Zg(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=qg(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);ir(s&&xo(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>yn([a],s,r)||bn(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>Te(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},CS=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{pointDistance as gi,pointFrom as Qs}from"@excalidraw/math";import{invariant as Yc}from"@excalidraw/common";P();import{arrayToMap as Oc,findIndex as kc,findLastIndex as Fc}from"@excalidraw/common";import{isFiniteNumber as Kg}from"@excalidraw/math";var Ks=(e,t)=>e.frameId===t||e.id===t,Rc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Oc(n||vt(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},Qg=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),[])},Gc=(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))}}},Jg=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{Ks(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},Nc=(e,t,n,i,o,r)=>{let s=r||Ut(e,n,i);if(!s)return n;let a=V(s,i),l=K(s)?Le(s,i):null,d=[s.id,a?.id,l?.id].filter(m=>!!m),c=n.findIndex(m=>d.includes(m.id)),u=n.findIndex(m=>m.id===t.id);if(u!==-1&&c!==-1&&u<c){let m=Array.from(n),p=m.splice(u,1)[0];m.splice(c,0,p),o.replaceAllElements(m)}return n},eE=(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"?Fc(t,m=>a(m),Math.max(0,n-1)):kc(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Gc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||q(d))){let m=Jg(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Gc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Ne(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},zc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Hc=(e,t)=>{if(e.length!==t.length)return console.error("z-index reordering failed: resulting array have different lengths"),!1;let n=new Map;for(let i of e)n.set(i.id,(n.get(i.id)||0)+1);for(let i of t){let o=n.get(i.id);if(!o)return console.error("z-index reordering failed: element id mismatch / duplicate ids"),!1;n.set(i.id,o-1)}return!0},_c=(e,t,n,i)=>{let o=e,r=Rc(e,t),s=zc(e,r),a=Qg(r);n==="right"&&(a=a.reverse());let l=new Set(r.filter(d=>q(e[d])).map(d=>e[d].id));return a.forEach((d,c)=>{let u=d[0],m=d[d.length-1],p=n==="left"?u:m,h=d.some(y=>{let w=e[y];return w.frameId&&l.has(w.frameId)})?null:e[p]?.frameId,f=eE(t,e,p,n,h,i);if(f===-1||p===f)return;let g=n==="left"?e.slice(0,f):e.slice(0,u),E=e.slice(u,m+1),x=n==="left"?e.slice(f,u):e.slice(m+1,f+1),b=n==="left"?e.slice(m+1):e.slice(f+1);e=n==="left"?[...g,...E,...x,...b]:[...g,...x,...E,...b]}),Hc(o,e)?(Yn(e,s),e):o},Uc=(e,t,n,i,o)=>{let r=Rc(e,t,o);if(r.length===0)return e;let s=zc(e,r),a=[],l,d;if(n==="left"){if(i)l=kc(e,f=>Ks(f,i));else if(t.editingGroupId){let f=Ne(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=Fc(e,f=>Ks(f,i));else if(t.editingGroupId){let f=Ne(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);let c=f=>Kg(f)&&f>=0;if(!c(l)||!c(d)||l>d||r.some(f=>f<l||f>d))return e;for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let u=Array.from(s.values()),m=e.slice(0,l),p=e.slice(d+1),h=n==="left"?[...m,...u,...a,...p]:[...m,...a,...u,...p];return Hc(e,h)?(Yn(h,s),h):e};function Wc(e,t,n,i){let o=Oc(vt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)o.has(d.id)&&q(d)&&s.add(d.id);for(let d of e)if(o.has(d.id))if(q(d)||d.frameId&&s.has(d.frameId))r.regularElements.push(d);else if(!d.frameId)r.regularElements.push(d);else{let c=r.frameChildren.get(d.frameId)||[];c.push(d),r.frameChildren.set(d.frameId,c)}let a=e,l=Array.from(r.frameChildren.entries());for(let[d,c]of l)a=i(a,t,n,d,c);return i(a,t,n,null,r.regularElements)}var WS=(e,t,n)=>_c(e,t,"left",n),YS=(e,t,n)=>_c(e,t,"right",n),jS=(e,t)=>Wc(e,t,"left",Uc),XS=(e,t)=>Wc(e,t,"right",Uc);var or=(e,t,n,i,o,r,s=!1)=>{if(W(t)||!At(o)||t.points.length!==2)return!1;if(!s){let l=t.startBinding?.elementId===n.id?0:t.points.length-1,d=G.getPointAtIndexGlobalCoordinates(t,l,i);if(gi(e,d)<Ui*1.5/o.zoom.value)return!1}let a=G.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return gi(e,a)>=Ui*1.5/o.zoom.value&&yt({element:n,elementsMap:i,point:e,threshold:ke(n,t),overrideShouldTestInside:!0})},tE=(e,t,n,i,o,r,s)=>{let a=new Map,l=n?"startBinding":"endBinding",d=n?"endBinding":"startBinding",c=e[l],u=e[d];if(c&&t){let m=t&&u&&c.elementId===u.elementId;s||m?c={...c,mode:"inside"}:c={...c,mode:"orbit"};let p=n?0:e.points.length-1,h=ft(e,l,c,t,i,!0);h&&a.set(p,{point:h})}if(u&&u.mode==="orbit"){let m=i.get(u.elementId);if(m&&fe(m)&&At(r)){let p=t&&u.elementId===t.id;s||p?u={...u,mode:"inside"}:u={...u,mode:"orbit"};let h=n?e.points.length-1:0,f=ft(e,d,u,m,i);f&&a.set(h,{point:f})}}a.size>0&&G.movePoints(e,o,a,{[l]:c,[d]:u})},jc=(e,t,n,i,o,r,s)=>{let a=G.getElement(e.elementId,t);if(!a||!Be(a)||W(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,m=Qs(n.x-c,n.y-u),p=l?"startBinding":"endBinding",h=Dl(m,a,i.getNonDeletedElements(),t,ut(o.zoom));if(h&&At(o)){a[p]&&h.id!==d?.elementId&&Ge(a,e.draggedFocusPointBinding,i);let f=s&&a[p]?.mode==="orbit"?"inside":!s&&a[p]?.mode==="inside"?"orbit":null;(!a[p]||f)&&Tt(a,h,f||"orbit",e.draggedFocusPointBinding,i,m),i.mutateElement(a,{[p]:{...a[p],elementId:h.id,mode:f||a[p]?.mode||"orbit",...ai(a,h,e.draggedFocusPointBinding,t,m)}})}else{let f=new Map,g=l?0:a.points.length-1;f.set(g,{point:G.createPointAt(a,t,m[0],m[1],r)}),G.movePoints(a,i,f),a[p]&&Ge(a,l?"start":"end",i)}tE(a,h,l,t,i,o,s),h&&At(o)&&Nc(m,a,i.getElementsIncludingDeleted(),t,i,h)},nM=(e,t,n,i)=>{let o=Qs(t.origin.x,t.origin.y),r=Ui*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&fe(s)&&!s.isDeleted){let a=Ue(e.startBinding.fixedPoint,s,n);if(or(a,e,s,n,i,"start")&&gi(o,a)<=r)return{hitFocusPoint:"start",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}if(e.endBinding?.elementId){let s=n.get(e.endBinding.elementId);if(s&&fe(s)&&!s.isDeleted){let a=Ue(e.endBinding.fixedPoint,s,n);if(or(a,e,s,n,i,"end")&&gi(o,a)<=r)return{hitFocusPoint:"end",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}return{hitFocusPoint:null,pointerOffset:{x:0,y:0}}},iM=(e,t)=>{Yc(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=G.getElement(e.elementId,t.getNonDeletedElementsMap());Yc(n,"Arrow must be in the scene");let i=e.draggedFocusPointBinding==="start"?"startBinding":"endBinding",o=e.draggedFocusPointBinding==="start"?"endBinding":"startBinding",r=n[i]?.elementId,s=n[o]?.elementId,a=r&&t.getNonDeletedElements().find(d=>d.id!==r&&d.id!==s&&fe(d)&&d.boundElements?.find(({id:c})=>c===n.id));a&&t.mutateElement(a,{boundElements:a.boundElements?.filter(({id:d})=>d!==n.id)});let l=r&&t.getNonDeletedElementsMap().get(r);l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]})},oM=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=Qs(t,n),a=Ui*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&fe(l)&&!l.isDeleted){let d=Ue(e.startBinding.fixedPoint,l,r);if(or(d,e,l,r,o,"start")&&gi(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&fe(l)&&!l.isDeleted){let d=Ue(e.endBinding.fixedPoint,l,r);if(or(d,e,l,r,o,"end")&&gi(s,d)<=a)return"end"}}return null};P();import{MIME_TYPES as Xc,SVG_NS as nE}from"@excalidraw/common";var iE=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),dM=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===Xc.binary)throw new Error("Only images can be added to ImageCache");let l=iE(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}},cM=e=>e.filter(t=>Fn(t)),oE=e=>e?.nodeName.toLowerCase()==="svg",uM=e=>{let t=new DOMParser().parseFromString(e,Xc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!oE(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",nE);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 gM=(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 h=0,f=0,g=p.map(E=>{let[x,b,y,w]=ze(E);return{elements:E,bounds:[x,b,y,w],width:y-x,height:w-b}});return g.forEach((E,x)=>{h+=E.width,x<g.length-1&&(h+=i),E.height>f&&(f=E.height)}),d+=f,{unitBounds:g,width:h,maxHeight:f}}),u=d+Math.max(0,l.length-1)*i,m=n-u/2;return c.forEach(p=>{let{unitBounds:h,width:f,maxHeight:g}=p,E=t-f/2;h.forEach(x=>{let[b,y]=x.bounds,w=E-b,S=m-y;x.elements.forEach(I=>{o.push(Fe(I,{x:I.x+w,y:I.y+S}))}),E+=x.width+i}),m+=g+i}),o};P();import{pointCenter as rE,normalizeRadians as sr,pointFrom as se,pointRotateRads as xt}from"@excalidraw/math";import{MIN_FONT_SIZE as ea,SHIFT_LOCKING_ANGLE as ar,rescalePoints as $c,getFontString as rr}from"@excalidraw/common";var DM=(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")W(m)||(sE(m,i,a,l,o),Oe(m,i));else if(t){let p=n[0].id,h=u.get(p),f=e.get(p);if(h&&f){let{nextWidth:g,nextHeight:E}=uE(h,f,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});cE(g,E,h,f,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return K(m)&&Oe(m,i),!0}else if(n.length>1){if(t==="rotation")return lE(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:h,flipByY:f,originalBoundingBox:g}=mE(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return pE(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:h,flipByY:f,nextWidth:m,nextHeight:p,originalBoundingBox:g}),!0}}return!1},sE=(e,t,n,i,o)=>{let[r,s,a,l]=$(e,t.getNonDeletedElementsMap()),d=(r+a)/2,c=(s+l)/2,u;q(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-c,n-d),o&&(u=u+ar/2,u=u-u%ar),u=sr(u));let m=_t(e),p={angle:u};if(Be(e)&&(p={...p},e.startBinding&&Ge(e,"start",t),e.endBinding&&Ge(e,"end",t)),t.mutateElement(e,p),m){let h=t.getElement(m);if(h&&!_(e)){let{x:f,y:g}=Gi(e,h,t.getNonDeletedElementsMap());t.mutateElement(h,{angle:u,x:f,y:g})}}},Vc=(e,t,n,i)=>Q(e)||Ie(e)?{points:$c(0,t,$c(1,n,e.points,i),i)}:{},ta=(e,t,n)=>{let i=e.width;if(he(e)){let s=Le(e,t);s&&(i=mt(s,e))}let r=e.fontSize*(n/i);return r<ea?null:{size:r}},aE=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=ta(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=se(e.x,e.y),u=Js(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=Po(rr({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=Ht(t.originalText,rr(t),Math.abs(u)),p=Qe(m,rr(t),t.lineHeight),h=p.height,f=se(e.x,e.y),g=Js(f,e.width,e.height,u,h,t.angle,i,!1,o),E={width:Math.abs(u),height:Math.abs(p.height),x:g.x,y:g.y,text:m,autoResize:!1};n.mutateElement(t,E)}}},lE=(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+=ar/2,d-=d%ar);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!q(u)){let[m,p,h,f]=$(u,l),g=(m+h)/2,E=(p+f)/2,x=e.get(u.id)?.angle??u.angle,[b,y]=xt(se(g,E),se(s,a),d+x-u.angle),w=W(u)?{points:Jl(u,l)}:{x:u.x+(b-g),y:u.y+(y-E),angle:sr(d+x)};n.mutateElement(u,w),Oe(u,n,{simultaneouslyUpdated:t}),Be(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||Ge(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||Ge(u,"end",n)));let S=V(u,l);if(S&&!_(u)){let{x:I,y:A}=Gi(u,S,l);n.mutateElement(S,{x:I,y:A,angle:sr(d+x)})}}n.triggerUpdate()},BM=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?$(t[0],n):ze(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=xt(se(i,o),se(d,c),-u),e){case"n":return xt(se(i-(r+a)/2,o-s),se(0,0),u);case"s":return xt(se(i-(r+a)/2,o-l),se(0,0),u);case"w":return xt(se(i-r,o-(s+l)/2),se(0,0),u);case"e":return xt(se(i-a,o-(s+l)/2),se(0,0),u);case"nw":return xt(se(i-r,o-s),se(0,0),u);case"ne":return xt(se(i-a,o-s),se(0,0),u);case"sw":return xt(se(i-r,o-l),se(0,0),u);case"se":return xt(se(i-a,o-l),se(0,0),u);default:return[0,0]}},LM=(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"},dE=(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"},Js=(e,t,n,i,o,r,s,a,l)=>{let d=dE(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)}}},cE=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(K(n)&&K(i))return aE(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=V(n,u);if(m){let g=o.get(m.id);if(g&&(c={fontSize:g.fontSize}),l){let E={...n,width:e,height:t},x=ta(m,u,mt(E,m));if(x===null)return;c={fontSize:x.size}}else{let E=cl(rr(m),m.lineHeight),x=ul(m.fontSize,m.lineHeight);e=Math.max(e,E),t=Math.max(t,x)}}let p=Vc(i,e,t,!0),h=se(i.x,i.y);if(Q(i)){let[g,E]=ae(i,o);h=se(g,E)}let f=Js(h,i.width,i.height,e,t,i.angle,s,l,d);if(Q(i)&&p.points){let g=i.x-h[0],E=i.y-h[1];f.x+=g,f.y+=E;let x=p.points[0][0],b=p.points[0][1];f.x+=x,f.y+=b,p.points=p.points.map(y=>se(y[0]-x,y[1]-b))}if(e<0&&(f.x=f.x+e),t<0&&(f.y=f.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),_(n)&&m&&l){let g=e/n.width*m.fontSize;if(g<ea)return;c.fontSize=g}if(e!==0&&t!==0&&Number.isFinite(f.x)&&Number.isFinite(f.y)){let g={...f,width:Math.abs(e),height:Math.abs(t),...p};Be(n)&&(n.startBinding&&(g={...g},n.startBinding&&Ge(n,"start",r)),n.endBinding&&(g={...g,endBinding:null})),r.mutateElement(n,g,{informMutation:a,isDragging:!1}),m&&c!=null&&r.mutateElement(m,{fontSize:c.fontSize}),Hn(n,r,s,l),Oe(n,r)}},uE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=rn(t,t.width,t.height,!0),u=se(a,l),m=se(d,c),p=rE(u,m),h=xt(se(i,o),p,-t.angle),[f,g,E,x]=rn(e,e.width,e.height,!0),b=E-f,y=x-g,w=m[0]-u[0],S=m[1]-u[1],I=w/b,A=S/y;n.includes("e")&&(I=(h[0]-u[0])/b),n.includes("s")&&(A=(h[1]-u[1])/y),n.includes("w")&&(I=(m[0]-h[0])/b),n.includes("n")&&(A=(m[1]-h[1])/y);let M=e.width*I,L=e.height*A;if(s&&(M=2*M-t.width,L=2*L-t.height),r){let C=Math.abs(M)/t.width,O=Math.abs(L)/t.height;if(n.length===1&&(L*=C,M*=O),n.length===2){let v=Math.max(C,O);M=t.width*v*Math.sign(M),L=t.height*v*Math.sign(L)}}return{nextWidth:M,nextHeight:L}},mE=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(v=>t.get(v.id)),d=l.reduce((v,Y)=>{if(!Q(Y))return v;let H=_t(Y);if(!H)return v;let Z=t.get(H)??null;return he(Z)?[...v,{...Z,...G.getBoundTextElementPosition(Y,Z,n)}]:v},[]),c=Zt(l.map(v=>v).concat(d)),{minX:u,minY:m,maxX:p,maxY:h,midX:f,midY:g}=c,E=p-u,x=h-m,b={ne:[u,h],se:[u,m],sw:[p,m],nw:[p,h],e:[u,m+x/2],w:[p,m+x/2],n:[u+E/2,h],s:[u+E/2,m]},[y,w]=a?[f,g]:b[i],S=a?2:1,I=Math.max(Math.abs(o-y)/E||0,Math.abs(r-w)/x||0)*S,A=i.includes("e")||i.includes("w")?Math.abs(o-y)*S:E,M=i.includes("n")||i.includes("s")?Math.abs(r-w)*S:x;s&&(A=E*I*Math.sign(o-y),M=x*I*Math.sign(r-w));let L={ne:[o<y,r>w],se:[o<y,r<w],sw:[o>y,r<w],nw:[o>y,r>w],e:[o<y,!1],w:[o>y,!1],n:[!1,r>w],s:[!1,r<w]},[C,O]=L[i].map(v=>v);return{originalBoundingBox:c,nextWidth:A,nextHeight:M,flipByX:C,flipByY:O}},pE=(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((S,I)=>{let A=o.get(I.id);return A&&S.push({orig:A,latest:I}),S},[]),p;if(u)p=u;else{let S=m.reduce((I,{orig:A})=>{if(!Q(A))return I;let M=_t(A);if(!M)return I;let L=o.get(M)??null;return he(L)?[...I,{...L,...G.getBoundTextElementPosition(A,L,t)}]:I},[]);p=Zt(m.map(({orig:I})=>I).concat(S))}let{minX:h,minY:f,maxX:g,maxY:E,midX:x,midY:b}=p,y=g-h,w=E-f;if(c===void 0&&d===void 0&&(c=y,d=w),r&&(c===void 0?c=d*(y/w):d===void 0?d=c*(w/y):Math.abs(c/d-y/w)>.001&&(c=d*(y/w))),c&&d){let S=n.includes("e")||n.includes("w")?Math.abs(c)/y:1,I=n.includes("n")||n.includes("s")?Math.abs(d)/w:1,A;n.length===1?A=n.includes("e")||n.includes("w")?S:I:A=Math.max(Math.abs(c)/y||0,Math.abs(d)/w||0);let M={ne:[h,E],se:[h,f],sw:[g,f],nw:[g,E],e:[h,f+w/2],w:[g,f+w/2],n:[h+y/2,E],s:[h+y/2,f]},[L,C]=s?[x,b]:M[n],O=r||m.some(T=>T.latest.angle!==0||K(T.latest)||hd(T.latest));O&&(S=A,I=A);let[v,Y]=[a?-1:1,l?-1:1],H=[];for(let{orig:T,latest:R}of m){if(K(T)&&he(T))continue;let U=T.width*S,ye=T.height*I,nt=sr(T.angle*v*Y),qn=Q(T)||Ie(T),Kn=T.x-L,Bn=T.y-C,Dt=a&&!qn?U:0,Ln=l&&!qn?ye:0,Jt=L+v*(Kn*S+Dt),Qn=C+Y*(Bn*I+Ln),de=Vc(T,U*v,ye*Y,!1),oe={x:Jt,y:Qn,width:U,height:ye,angle:nt,...de};if(W(T)&&(T.startBinding&&(oe.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&&(oe.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&&de.points&&(oe.fixedSegments=T.fixedSegments.map(Bt=>({...Bt,start:de.points[Bt.index-1],end:de.points[Bt.index]})))),Me(T)&&(oe.scale=[T.scale[0]*v,T.scale[1]*Y]),K(T)){let Bt=ta(T,t,U);if(!Bt)return;oe.fontSize=Bt.size}let en=o.get(_t(T)??"");if(en)if(O){let Bt=en.fontSize*A;if(Bt<ea)return;oe.boundTextFontSize=Bt}else oe.boundTextFontSize=en.fontSize;H.push({element:R,update:oe})}let Z=H.map(({element:T})=>T),F=new Map(H.map(({element:T})=>[T.id,T]));for(let{element:T,update:{boundTextFontSize:R,...U}}of H){let{angle:ye}=U;i.mutateElement(T,U),Oe(T,i,{simultaneouslyUpdated:Z}),Be(T)&&(T.startBinding&&(F.has(T.startBinding.elementId)||Ge(T,"start",i)),T.endBinding&&(F.has(T.endBinding.elementId)||Ge(T,"end",i)));let nt=V(T,t);nt&&R&&(i.mutateElement(nt,{fontSize:R,angle:Q(T)?void 0:ye}),Hn(T,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as at,pointOnLineSegment as eu,pointRotateRads as dr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as aa}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as ia}from"@excalidraw/common";import{pointFrom as Zc,pointRotateRads as fE}from"@excalidraw/math";var qc={mouse:8,pen:16,touch:28},hE=16,Qc={e:!0,s:!0,n:!0,w:!0},NM={e:!0,s:!0,n:!0,w:!0},zM={e:!0,s:!0,n:!0,w:!0,rotation:!0},Kc={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},na={e:!0,s:!0,n:!0,w:!0},Qt=(e,t,n,i,o,r,s)=>{let[a,l]=fE(Zc(e+n/2,t+i/2),Zc(o,r),s);return[a-n/2,l-i/2,n,i]},lr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),oa=e=>lr(e)?Qc:{},ra=([e,t,n,i,o,r],s,a,l,d={},c=4,u=ia)=>{let m=qc[l],p=m/a.value,h=m/a.value,f=m/a.value,g=m/a.value,E=n-e,x=i-t,b=c/a.value,y=(m-u*2)/(2*a.value),w={nw:d.nw?void 0:Qt(e-b-f+y,t-b-g+y,p,h,o,r,s),ne:d.ne?void 0:Qt(n+b-y,t-b-g+y,p,h,o,r,s),sw:d.sw?void 0:Qt(e-b-f+y,i+b-y,p,h,o,r,s),se:d.se?void 0:Qt(n+b-y,i+b-y,p,h,o,r,s),rotation:d.rotation?void 0:Qt(e+E/2-p/2,t-b-g+y-hE/a.value,p,h,o,r,s)},S=5*qc.mouse/a.value;return Math.abs(E)>S&&(d.n||(w.n=Qt(e+E/2-p/2,t-b-g+y,p,h,o,r,s)),d.s||(w.s=Qt(e+E/2-p/2,i+b-y,p,h,o,r,s))),Math.abs(x)>S&&(d.w||(w.w=Qt(e-b-f+y,t+x/2-h/2,p,h,o,r,s)),d.e||(w.e=Qt(n+b-y,t+x/2-h/2,p,h,o,r,s))),w},Jc=(e,t,n,i="mouse",o=Qc)=>{if(e.locked||W(e))return{};if(e.type==="freedraw"||Q(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=na:s[0]>0&&s[1]<0?o=Kc:s[0]>0&&s[1]>0?o=na:s[0]<0&&s[1]>0?o=Kc:s[0]<0&&s[1]<0&&(o=na)}}else q(e)&&(o={...o,rotation:!0});let r=Q(e)?ia+8:Me(e)?0:ia;return ra($(e,n,!0),e.angle,t,i,o,r,Me(e)?0:void 0)},HM=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return W(i)?!1:Q(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var la=(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}=Jc(e,r,t,s,oa(a));if(l&&la(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?la(m,i,o):!1});if(c.length>0)return c[0];if(lr(a)){let[u,m,p,h,f,g]=$(e,t);if(!(Q(e)&&e.points.length<=2)){let E=Me(e)?0:aa/r.value,x=aa/r.value,b=tu(at(u-E,m-E),at(p+E,h+E),at(f,g),e.angle);for(let[y,w]of Object.entries(b))if(eu(at(i,o),w,x))return y}}return!1},VM=(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),ZM=([e,t,n,i],o,r,s,a,l)=>{let d=ra([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,oa(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&la(m,o,r)});if(c)return c;if(lr(l)){let u=(e+n)/2,m=(t+i)/2,p=aa/s.value,h=tu(at(e-p,t-p),at(n+p,i+p),at(u,m),0);for(let[f,g]of Object.entries(h))if(eu(at(o,r),g,p))return f}return!1},sa=["ns","nesw","ew","nwse"],EE=(e,t)=>{let n=sa.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=sa[(n+i)%sa.length]}return e},qM=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=EE(o,t.angle)),o?`${o}-resize`:""},tu=([e,t],[n,i],o,r)=>{let s=dr(at(e,t),o,r),a=dr(at(n,t),o,r),l=dr(at(e,i),o,r),d=dr(at(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var eA=(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")||vt(t,e).length));P();import{pointFrom as cr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as xE,DEFAULT_FONT_SIZE as bE,TEXT_ALIGN as wE,VERTICAL_ALIGN as yE,getSizeFromPoints as PE,randomId as IE,arrayToMap as SE,assertNever as da,cloneJSON as iu,getFontString as ME,isDevEnv as AE,toBrandedType as TE,getLineHeight as vE}from"@excalidraw/common";var ur={width:100,height:0},Dn=100,DE=(e,t,n)=>{let i=Vn({x:0,y:0,textAlign:wE.CENTER,verticalAlign:yE.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),Ao(i,e,n),[e,i]},nu=(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??Dn,u=t?.height??Dn,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,h=t.y||e.y-u/2,f=m?m.type:t.type;if(f){if(f==="text"){let g="";m&&m.type==="text"?g=m.text:t.type==="text"&&(g=t.text),g||console.error(`No text found for start binding text element for ${e.id}`),r=Vn({x:p,y:h,type:"text",...m,...t,text:g}),Object.assign(r,{x:t.x||e.x-r.width,y:t.y||e.y-r.height/2})}else switch(f){case"rectangle":case"ellipse":case"diamond":{r=$n({x:p,y:h,width:c,height:u,...m,...t,type:f});break}default:da(e,`Unhandled element start type "${t.type}"`,!0)}Tt(e,r,"orbit","start",o)}}if(n){let c=n?.height??Dn,u=n?.width??Dn,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,h=n.y||e.y-c/2,f=m?m.type:n.type;if(f){if(f==="text"){let g="";m&&m.type==="text"?g=m.text:n.type==="text"&&(g=n.text),g||console.error(`No text found for end binding text element for ${e.id}`),s=Vn({x:p,y:h,type:"text",...m,...n,text:g}),Object.assign(s,{y:n.y||e.y-s.height/2})}else switch(f){case"rectangle":case"ellipse":case"diamond":{s=$n({x:p,y:h,width:u,height:c,...m,...n,type:f});break}default:da(e,`Unhandled element end type "${f}"`,!0)}Tt(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=iu(e.points);return e.points[a][0]>e.points[a-1][0]&&(d[0][0]=l,d[a][0]-=l),e.points[a][0]<e.points[a-1][0]&&(d[0][0]=-l,d[a][0]+=l),e.points[a][1]>e.points[a-1][1]&&(d[0][1]=l,d[a][1]-=l),e.points[a][1]<e.points[a-1][1]&&(d[0][1]=-l,d[a][1]+=l),Object.assign(e,G.getNormalizeElementPointsAndCoords({...e,points:d})),{linearElement:e,startBoundElement:r,endBoundElement:s}},ca=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>xs(Array.from(this.excalidrawElements.values()));getElementsMap=()=>TE(SE(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},fA=(e,t)=>{if(!e)return[];let n=iu(e),i=new ca,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:IE()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||Dn,p=l?.label?.text&&l.height===void 0?0:l?.height||Dn;d=$n({...l,width:m,height:p});break}case"line":{let m=l.width||ur.width,p=l.height||ur.height;d=wc({width:m,height:p,points:[cr(0,0),cr(m,p)],...l});break}case"arrow":{let m=l.width||ur.width,p=l.height||ur.height;d=tr({width:m,height:p,endArrowhead:"arrow",points:[cr(0,0),cr(m,p)],...l,type:"arrow"}),Object.assign(d,PE(d.points));break}case"text":{let m=l?.fontFamily||xE,p=l?.fontSize||bE,h=l?.lineHeight||vE(m),f=l.text??"",g=Ci(f),E=Qe(g,ME({fontFamily:m,fontSize:p}),h);d=Vn({width:E.width,height:E.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=yc({width:l?.width||Dn,height:l?.height||Dn,...l});break}case"frame":{d=Ec({x:0,y:0,...l});break}case"magicframe":{d=xc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,da(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 fi(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]=DE(c,d?.label,a);if(i.add(u),i.add(m),_(u)){let p=d.type==="arrow"?d?.start:void 0,h=d.type==="arrow"?d?.end:void 0;if(p&&p.id){let x=r.get(p.id);x&&Object.assign(p,{id:x})}if(h&&h.id){let x=r.get(h.id);x&&Object.assign(h,{id:x})}let{linearElement:f,startBoundElement:g,endBoundElement:E}=nu(u,p,h,i,a);u=f,i.add(f),i.add(g),i.add(E)}}else switch(d.type){case"arrow":{let{start:u,end:m}=d;if(u&&u.id){let g=r.get(u.id);Object.assign(u,{id:g})}if(m&&m.id){let g=r.get(m.id);Object.assign(m,{id:g})}let{linearElement:p,startBoundElement:h,endBoundElement:f}=nu(c,u,m,i,a);i.add(p),i.add(h),i.add(f);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(w=>{let S=r.get(w);if(!S)throw new Error(`Element with ${w} wasn't mapped correctly`);let I=i.getElement(S);if(!I)throw new Error(`Frame element with id ${S} doesn't exist`);Object.assign(I,{frameId:c.id}),I?.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(I)});let[m,p,h,f]=ze(u),g=10;m=m-g,p=p-g,h=h+g,f=f+g;let E=c?.x||m,x=c?.y||p,b=c?.width||h-m,y=c?.height||f-p;Object.assign(c,{x:E,y:x,width:b,height:y}),AE()&&d.children.length&&(c?.x||c?.y||c?.width||c?.height)&&console.info("User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically")}return i.getElements()};P();var bA=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return jc(n.selectedLinearElement,e.scene.getNonDeletedElementsMap(),e.lastPointerMoveCoords,e.scene,n,e.getEffectiveGridSize(),t.altKey),!0;if(n.selectedLinearElement.hoverPointIndex!==null&&e.lastPointerMoveEvent&&n.selectedLinearElement.initialState.lastClickedPoint>=0&&n.selectedLinearElement.isDragging)return G.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};P();var BE=e=>{switch(e){case void 0:case null:return null;case"dot":return"circle";case"crowfoot_one":return"cardinality_one";case"crowfoot_many":return"cardinality_many";case"crowfoot_one_or_many":return"cardinality_one_or_many";default:return e}},PA=e=>{let t=BE(e);return t===null?null:t};var TA=e=>e.reduce((t,n)=>t+n.version,0),tc=e=>{let t=5381;for(let n of LE(e))t=(t<<5)+t+n.versionNonce;return t>>>0},nc=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},vA=e=>e.filter(t=>!t.isDeleted&&!Vd(t)),DA=e=>e.filter(t=>!t.isDeleted),BA=e=>!e.isDeleted;export{In as AppStateDelta,Op as BASE_ARROW_MIN_LENGTH,Vl as BASE_BINDING_GAP,_n as BASE_BINDING_GAP_ELBOW,ne as BASE_PADDING,En as BindableElement,gn as BoundElement,Ze as CaptureUpdateAction,LP as DEFAULT_LINK_SIZE,Qc as DEFAULT_OMIT_SIDES,j as Delta,Hs as DurableIncrement,Gs as ElementBounds,Sn as ElementsDelta,_s as EphemeralIncrement,Ui as FOCUS_POINT_SIZE,Bc as FlowChartCreator,Dc as FlowChartNavigator,Ae as HEADING_DOWN,je as HEADING_LEFT,xe as HEADING_RIGHT,et as HEADING_UP,yh as INVISIBLY_SMALL_ELEMENT_SIZE,gs as InvalidFractionalIndexError,G as LinearElementEditor,De as MINIMAL_CROP_SIZE,zM as OMIT_SIDES_FOR_FRAME,NM as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,fi as Scene,tt as ShapeCache,Qd as Store,qi as StoreChange,Us as StoreDelta,Ko as StoreIncrement,Mn as StoreSnapshot,st as aabbForElement,Mf as addElementsToFrame,qg as addNewNodes,y0 as addToGroup,L1 as alignElements,_p as avoidRectangularCorner,Tt as bindBindingElement,Sd as bindElementsToFramesAfterDuplication,kp as bindOrUnbindBindingElement,qy as bindOrUnbindBindingElements,rs as bindPointToSnapToElementOutline,Ql as bindingProperties,Is as boundsContainBounds,Ul as bumpVersion,Wp as calculateFixedPointForElbowArrowBinding,ai as calculateFixedPointForNonElbowArrowBinding,jb as canApplyRoundnessTypeToElement,Ja as canBecomePolygon,gl as canChangeRoundness,yg as canCreateLinkFromElements,Kw as canHaveArrowheads,lr as canResizeFromSides,oi as charWidth,Ee as compareHeading,Gi as computeBoundTextPosition,zr as computeContainerDimensionForBoundText,yw as containsCJK,fA as convertToExcalidrawElements,hS as createPlaceholderEmbeddableLabel,Xs as createSrcDoc,Rb as cropElement,an as deconstructDiamondElement,bo as deconstructLinearOrFreeDrawElement,sn as deconstructRectanguloidElement,zs as deepCopyElement,jI as defaultGetElementLinkFromSelection,fw as detectLineHeight,cn as distanceToElement,vI as distributeElements,Wt as doBoundsIntersect,HI as dragNewElement,NI as dragSelectedElements,Lh as duplicateElement,j1 as duplicateElements,w0 as editGroupForSelectedElement,re as elementCenterPoint,bn as elementOverlapsWithFrame,Xi as elementWithCanvasCache,yn as elementsAreInFrameBounds,fd as elementsAreInSameGroup,xd as elementsOverlappingBBox,ES as embeddableURLValidator,pf as excludeElementsInFramesFromSelection,cP as filterElementsEligibleAsFrameChildren,Qy as fixBindingsAfterDeletion,Kl as fixDuplicatedBindingsAfterDuplication,Zr as flipHeading,gP as frameAndChildrenSelectedTogether,sl as generateLinearCollisionShape,Ve as generateRoughOptions,R0 as getActiveTextElement,vo as getAllHoveredElementAtPoint,ul as getApproxMinLineHeight,cl as getApproxMinLineWidth,Jl as getArrowLocalFixedPoints,fh as getArrowheadAngle,PA as getArrowheadForPicker,He as getArrowheadPoints,ph as getArrowheadSize,ke as getBindingGap,Jy as getBindingSideMidPoint,cs as getBindingStrategyForDraggingBindingElementEndpoints,V as getBoundTextElement,_t as getBoundTextElementId,Gw as getBoundTextElementPosition,Oi as getBoundTextMaxHeight,mt as getBoundTextMaxWidth,ks as getBoundsFromPoints,un as getCenterForBounds,h1 as getClosestElementBounds,Zt as getCommonBoundingBox,ze as getCommonBounds,If as getCommonFrameId,Lw as getContainerCenter,Hr as getContainerCoords,Le as getContainerElement,wn as getContainingFrame,Rt as getCornerRadius,Do as getCubicBezierCurveBound,qM as getCursorForResizingElement,Bf as getDefaultFrameName,Xb as getDefaultRoundnessTypeForElement,rl as getDiamondBaseCorners,ii as getDiamondPoints,zI as getDragOffsetXY,f1 as getDraggedElementsBounds,$ as getElementAbsoluteCoords,ae as getElementBounds,ys as getElementLineSegments,ps as getElementPointsCoords,zd as getElementShape,VM as getElementWithTransformHandleType,Md as getElementsCompletelyInFrame,Ne as getElementsInGroup,dP as getElementsInNewFrame,lP as getElementsInResizingFrame,nP as getElementsIntersectingFrame,hP as getElementsOverlappingFrame,Ed as getElementsWithinSelection,fS as getEmbedLink,Nb as getFlipAdjustedCropPosition,xn as getFrameChildren,Sf as getFrameChildrenInsertionIndex,yf as getFrameLikeElements,fP as getFrameLikeTitle,OP as getFreedrawOutlineAsSegments,ih as getFreedrawOutlinePoints,Ue as getGlobalFixedPointForBindableElement,Yp as getGlobalFixedPoints,_l as getHeadingForElbowArrowSnap,Ut as getHoveredElementForBinding,Dl as getHoveredElementForFocusPoint,cM as getInitializedImageElements,Io as getLineHeightInPx,dn as getLineWidth,$b as getLinearElementSubType,LS as getLinkDirectionFromKey,XI as getLinkIdAndTypeFromSelection,cd as getLockedLinearCursorAlignSize,Pm as getMaxCharWidth,I0 as getMaximumGroups,gw as getMinCharWidth,Yi as getMinMaxXYFromCurvePathOps,Po as getMinTextElementWidth,gd as getNewGroupIdsForDuplication,DA as getNonDeletedElements,pd as getNonDeletedGroupIds,M1 as getNormalizedDimensions,pi as getObservedAppState,oa as getOmitSidesForEditorInterface,dw as getOriginalContainerHeightFromCache,Fs as getPerfectElementSize,qs as getPredecessors,p1 as getRectangleBoxAbsoluteCoords,_f as getRenderOpacity,LM as getResizeArrowDirection,BM as getResizeOffsetXY,rn as getResizedElementAbsoluteCoords,aP as getRootElements,TA as getSceneVersion,vt as getSelectedElements,Wo as getSelectedElementsByGroup,hs as getSelectedGroupForElement,lf as getSelectedGroupIdForElement,sf as getSelectedGroupIds,F0 as getSelectionStateForElements,hm as getSnapOutlineMidPoint,k0 as getTargetElements,Tf as getTargetFrame,Cw as getTextElementAngle,Rw as getTextFromElements,ym as getTextHeight,ml as getTextWidth,ZM as getTransformHandleTypeFromCoords,Jc as getTransformHandles,ra as getTransformHandlesFromCoords,ja as getUncroppedImageElement,Ar as getUncroppedWidthAndHeight,G0 as getVisibleAndNonSelectedElements,vA as getVisibleElements,g1 as getVisibleSceneBounds,Lm as getWrappedTextLines,sP as groupByFrameLikes,oP as groupsAreAtLeastIntersectingTheFrame,rP as groupsAreCompletelyOutOfFrame,Hn as handleBindTextResize,jc as handleFocusPointDrag,oM as handleFocusPointHover,nM as handleFocusPointPointerDown,iM as handleFocusPointPointerUp,Yr as hasBackground,wt as hasBoundTextElement,HM as hasBoundingBox,Zw as hasFreedrawMode,Xw as hasStrokeColor,Vw as hasStrokeStyle,$w as hasStrokeWidth,tc as hashElementsVersion,nc as hashString,Ye as headingForPoint,Fi as headingForPointFromElement,pt as headingForPointIsHorizontal,Xe as headingIsHorizontal,xy as headingIsVertical,op as hitElementBoundText,ip as hitElementBoundingBox,my as hitElementBoundingBoxOnly,yt as hitElementItself,It as intersectElementWithLineSegment,Yb as isArrowBoundToElement,_ as isArrowElement,fe as isBindableElement,$r as isBindableElementInsideOtherBindable,Be as isBindingElement,om as isBindingElementType,At as isBindingEnabled,he as isBoundToContainer,iP as isCursorInFrame,nm as isCurvedArrow,W as isElbowArrow,S1 as isElementCompletelyInViewport,Ps as isElementContainingFrame,Td as isElementInFrame,af as isElementInGroup,bd as isElementInViewport,di as isElementIntersectingFrame,$I as isElementLink,Zb as isEligibleFrameChildType,$a as isEmbeddableElement,qa as isExcalidrawElement,jp as isFixedPoint,Tr as isFlowchartNodeElement,or as isFocusPointVisible,xo as isFrameElement,q as isFrameLikeElement,Ie as isFreeDrawElement,em as isFreeDrawElementType,oE as isHTMLSVGElement,go as isIframeElement,Eo as isIframeLikeElement,Me as isImageElement,hd as isInGroup,Fn as isInitializedImageElement,Vd as isInvisiblySmallElement,kt as isLineElement,Q as isLinearElement,im as isLinearElementType,Va as isMagicFrameElement,pw as isMeasureTextSupported,CS as isNodeInFlowchart,BA as isNonDeletedElement,Nn as isPathALoop,Nt as isPointInElement,Di as isRectangularElement,Za as isRectanguloidElement,rf as isSelectedViaGroup,tm as isSharpArrow,Wb as isSimpleArrow,O0 as isSomeElementSelected,rm as isTextBindableContainer,K as isTextElement,Ka as isUsingAdaptiveRadius,Qa as isUsingProportionalRadius,Vb as isValidPolygon,Fw as isValidTextContainer,iE as loadHTMLImageElement,fs as makeNextSelectedElementIds,ut as maxBindingDistance_simple,bA as maybeHandleArrowPointlikeDrag,gS as maybeParseEmbedSrc,ta as measureFontSizeFromWidth,Qe as measureText,jS as moveAllLeft,XS as moveAllRight,Nc as moveArrowAboveBindable,WS as moveOneLeft,YS as moveOneRight,Te as mutateElement,tr as newArrowElement,$n as newElement,Fe as newElementWith,oS as newEmbeddableElement,Ec as newFrameElement,aS as newFreeDrawElement,rS as newIframeElement,yc as newImageElement,wc as newLinearElement,xc as newMagicFrameElement,Vn as newTextElement,BE as normalizeArrowhead,Zd as normalizeElementOrder,ln as normalizeFixedPoint,uM as normalizeSVG,Ci as normalizeText,jo as omitGroupsContainingFrameLikes,Pf as omitPartialGroups,yd as orderByFractionalIndex,Li as originalContainerCache,VI as parseElementLinkFromURL,Dm as parseTokens,St as pointInsideBounds,Eh as pointInsideBoundsInclusive,gM as positionElementsOnGrid,Gr as projectFixedPointOntoDiagonal,Ao as redrawTextBoundingBox,sS as refreshTextDimensions,Af as removeAllElementsFromFrame,Ad as removeElementsFromFrame,P0 as removeFromSelectedGroups,GP as renderElement,CP as renderSelectionElement,uP as replaceAllElementsInFrame,Vc as rescalePointsInElement,ll as resetOriginalContainerCache,pE as resizeMultipleElements,cE as resizeSingleElement,aE as resizeSingleTextElement,gE as resizeTest,of as selectGroup,ud as selectGroupsForSelectedElements,md as selectGroupsFromGivenElements,hw as setCustomTextMetricsProvider,Ow as shouldAllowVerticalAlign,pP as shouldApplyFrameClip,To as shouldTestInside,eA as showSelectedShapeActions,us as snapToMid,kw as suppportsHorizontalAlign,xs as syncInvalidIndices,Pd as syncInvalidIndicesImmutable,Yn as syncMovedIndices,dd as toggleLinePolygonState,qw as toolIsArrow,DM as transformElements,Ge as unbindBindingElement,Ky as updateBindings,Oe as updateBoundElements,ft as updateBoundPoint,si as updateElbowArrowPoints,mP as updateFrameMembershipOfSelectedElements,dM as updateImageCache,al as updateOriginalContainerCache,Hl as validateElbowPoints,Ef as validateFractionalIndices,Yt as vectorToHeading,Ht as wrapText};
|
|
28
|
+
`),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return Ot.set(e,p),p}return Ot.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},IT=e=>{let t;ko(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=bx.Helvetica,o=yx({fontSize:n,fontFamily:i});return ai({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:sn(t,o,e.width-20),textAlign:"center",verticalAlign:wx.MIDDLE,angle:e.angle??0})},Da=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(Ta.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return Ta.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},ST=e=>{let t=e.match(Tx);if(t&&t.length===2)return t[1];let n=e.match(Bx);if(n&&n.length===2)return n[1];let i=e.match(Mx);if(i&&i.length===2)return i[1];if(Iu.test(e))return`https://giphy.com/embed/${Iu.exec(e)[1]}`;let o=e.match(vx);return o&&o.length===2?o[1]:e},MT=(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(Da(e,n))return!0;return!1}}return!!Da(e,Ta)};I();import{invariant as va,toBrandedType as Cx}from"@excalidraw/common";import{clamp as Gx,pointFrom as Tu}from"@excalidraw/math";var Du=100,vu=100,kx=e=>{let t=[...e].sort((i,o)=>i.start-o.start),n=[];for(let i of t){let o=n[n.length-1];o&&i.start<=o.end?o.end=Math.max(o.end,i.end):n.push({...i})}return n},Cu=(e,t,n)=>n.every(i=>e+t<=i.start||e>=i.end),Ox=(e,t,n)=>{if(Cu(e,t,n))return e;let i=[-1/0,...n.map(a=>a.end)],o=[...n.map(a=>a.start),1/0],r=e,s=1/0;for(let a=0;a<i.length;a++){if(o[a]-i[a]<t)continue;let l=Gx(e,i[a],o[a]-t),d=Math.abs(l-e);d<=s&&(r=l,s=d)}return r},Nx=(e,t)=>{let n=[...t.values()].filter(X),i=new Set([e.id]),o=[e.id],r=[];for(;o.length>0;){let s=o.shift();for(let a of n){let l=a.startBinding?.elementId,d=a.endBinding?.elementId,c;if(l===s?c=d:d===s&&(c=l),!c||i.has(c))continue;i.add(c);let u=t.get(c);u&&we(u)&&(r.push(u),o.push(c))}}return r},Fx=(e,t,n,i,o)=>{let r=t==="left"||t==="right",s=r?e.width:e.height,a=r?e.height:e.width,l=r?vu:Du,d=r?Du:vu,c=r?e.x:e.y,u=r?e.y+e.height/2:e.x+e.width/2,m=t==="right"||t==="down"?c+s+l:c-l-s,p=kx(i.filter(b=>{let y=r?b[0]:b[1],w=r?b[2]:b[3];return y<m+s&&w>m}).map(b=>({start:(r?b[1]:b[0])-d,end:(r?b[3]:b[2])+d}))),h=a+d,f=n*a+(n-1)*d,E=(o===null?null:[o,o-h].filter(b=>Cu(b,f,p)).sort((b,y)=>Math.abs(b+f/2-u)-Math.abs(y+f/2-u))[0]??null)??Ox(u-f/2,f,p);return{positions:Array.from({length:n},(b,y)=>{let w=E+y*h;return r?{x:m,y:w}:{x:w,y:m}}),crossStart:E}},Rx=(e,t,n)=>{let i=Ai({type:e.type,x:t,y:n,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});return va(Ll(i),"not an ExcalidrawFlowchartNodeElement"),i},zx=(e,t,n,i,o,r=null)=>{let s=i.getNonDeletedElementsMap(),a=Nx(e,s).map(u=>lt(u,s)),{positions:l,crossStart:d}=Fx(e,n,o,a,r),c=[];for(let u of l){let m=Rx(e,u.x,u.y),p=_x(e,m,n,t,i);c.push(m,p)}return{nodes:c,crossStart:d}},_x=(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=wr({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:[Tu(0,0),Tu(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();Vt(c,e,"orbit","start",o),Vt(c,t,"orbit","end",o);let m=new Map;m.set(e.id,e),m.set(t.id,t),m.set(c.id,c),R.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=bi(c,Cx(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p,isDeleted:c.isDeleted}},Bu=class e{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!we(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...e.getSuccessors(t,n,i),...e.getPredecessors(t,n,i)];if(o.length>0)return this.sameLevelIndex=0,this.isExploring=!0,this.sameLevelNodes=o,this.direction=i,this.visitedNodes.add(o[0].id),o[0].id;if(i===this.direction||!this.isExploring){this.isExploring||this.visitedNodes.add(t.id);let s=["up","right","down","left"].filter(a=>a!==i).map(a=>[...e.getSuccessors(t,n,a),...e.getPredecessors(t,n,a)]).flat().filter(a=>!this.visitedNodes.has(a.id));for(let a of s)if(!this.visitedNodes.has(a.id))return this.visitedNodes.add(a.id),this.isExploring=!0,this.direction=i,a.id}return null}static getNodeRelatives(t,n,i,o){let r=[...i.values()].reduce((s,a)=>{let l;if(X(a)&&(l=a[t==="predecessors"?"startBinding":"endBinding"])&&a[t==="predecessors"?"endBinding":"startBinding"]?.elementId===n.id){let d=i.get(l.elementId);if(!d)return s;va(we(d),"not an ExcalidrawBindableElement");let c=t==="predecessors"?a.points[a.points.length-1]:[0,0],u=Ei(n,lt(n,i),[c[0]+a.x,c[1]+a.y]);s.push({relative:d,heading:u})}return s},[]);switch(o){case"up":return r.filter(s=>fe(s.heading,Ze)).map(s=>s.relative);case"down":return r.filter(s=>fe(s.heading,Le)).map(s=>s.relative);case"right":return r.filter(s=>fe(s.heading,he)).map(s=>s.relative);case"left":return r.filter(s=>fe(s.heading,Ne)).map(s=>s.relative)}}static getSuccessors(t,n,i){return e.getNodeRelatives("successors",t,n,i)}static getPredecessors(t,n,i){return e.getNodeRelatives("predecessors",t,n,i)}},Lu=class{isCreatingChart=!1;numberOfNodes=0;direction=null;clusterCrossStart=null;pendingNodes=null;createNodes(t,n,i,o){let r=o.getNonDeletedElementsMap();i!==this.direction?(this.numberOfNodes=1,this.clusterCrossStart=null):this.numberOfNodes+=1;let{nodes:s,crossStart:a}=zx(t,n,i,o,this.numberOfNodes,this.clusterCrossStart);if(this.isCreatingChart=!0,this.direction=i,this.clusterCrossStart=a,this.pendingNodes=s,t.frameId){let l=r.get(t.frameId);va(l&&No(l),"not an ExcalidrawFrameElement"),l&&this.pendingNodes.every(d=>kn([d],l,r)||Cn(d,l,r))&&(this.pendingNodes=this.pendingNodes.map(d=>Ue(d,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0,this.clusterCrossStart=null}},zT=(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};I();import{pointDistance as Gi,pointFrom as La}from"@excalidraw/math";import{invariant as Yu}from"@excalidraw/common";I();import{arrayToMap as ku,findIndex as Ou,findLastIndex as Nu}from"@excalidraw/common";import{isFiniteNumber as Hx}from"@excalidraw/math";var Ba=(e,t)=>e.frameId===t||e.id===t,Fu=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=ku(n||Kt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(o.length&&(i=i.concat(o),o=[]),i.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,o.push(s)):o=[]}return i},Wx=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),[])},Gu=(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))}}},Ux=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{Ba(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},Ru=(e,t,n,i,o,r)=>{let s=r||an(e,On(n),i);if(!s)return n;let a=re(s,i),l=oe(s)?We(s,i):null,d=[s.id,a?.id,l?.id].filter(m=>!!m),c=n.findIndex(m=>d.includes(m.id)),u=n.findIndex(m=>m.id===t.id);if(u!==-1&&c!==-1&&u<c){let m=Array.from(n),p=m.splice(u,1)[0];m.splice(c,0,p),o.replaceAllElements(m)}return n},Yx=(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"?Nu(t,m=>a(m),Math.max(0,n-1)):Ou(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Gu(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||J(d))){let m=Ux(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Gu(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Qe(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},zu=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),_u=(e,t)=>{if(e.length!==t.length)return console.error("z-index reordering failed: resulting array have different lengths"),!1;let n=new Map;for(let i of e)n.set(i.id,(n.get(i.id)||0)+1);for(let i of t){let o=n.get(i.id);if(!o)return console.error("z-index reordering failed: element id mismatch / duplicate ids"),!1;n.set(i.id,o-1)}return!0},Hu=(e,t,n,i)=>{let o=e,r=Fu(e,t),s=zu(e,r),a=Wx(r);n==="right"&&(a=a.reverse());let l=new Set(r.filter(d=>J(e[d])).map(d=>e[d].id));return a.forEach((d,c)=>{let u=d[0],m=d[d.length-1],p=n==="left"?u:m,h=d.some(y=>{let w=e[y];return w.frameId&&l.has(w.frameId)})?null:e[p]?.frameId,f=Yx(t,e,p,n,h,i);if(f===-1||p===f)return;let g=n==="left"?e.slice(0,f):e.slice(0,u),E=e.slice(u,m+1),x=n==="left"?e.slice(f,u):e.slice(m+1,f+1),b=n==="left"?e.slice(m+1):e.slice(f+1);e=n==="left"?[...g,...E,...x,...b]:[...g,...x,...E,...b]}),_u(o,e)?(ni(e,s),e):o},Wu=(e,t,n,i,o)=>{let r=Fu(e,t,o);if(r.length===0)return e;let s=zu(e,r),a=[],l,d;if(n==="left"){if(i)l=Ou(e,f=>Ba(f,i));else if(t.editingGroupId){let f=Qe(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=Nu(e,f=>Ba(f,i));else if(t.editingGroupId){let f=Qe(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);let c=f=>Hx(f)&&f>=0;if(!c(l)||!c(d)||l>d||r.some(f=>f<l||f>d))return e;for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let u=Array.from(s.values()),m=e.slice(0,l),p=e.slice(d+1),h=n==="left"?[...m,...u,...a,...p]:[...m,...a,...u,...p];return _u(e,h)?(ni(h,s),h):e};function Uu(e,t,n,i){let o=ku(Kt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)o.has(d.id)&&J(d)&&s.add(d.id);for(let d of e)if(o.has(d.id))if(J(d)||d.frameId&&s.has(d.frameId))r.regularElements.push(d);else if(!d.frameId)r.regularElements.push(d);else{let c=r.frameChildren.get(d.frameId)||[];c.push(d),r.frameChildren.set(d.frameId,c)}let a=e,l=Array.from(r.frameChildren.entries());for(let[d,c]of l)a=i(a,t,n,d,c);return i(a,t,n,null,r.regularElements)}var qT=(e,t,n)=>Hu(e,t,"left",n),QT=(e,t,n)=>Hu(e,t,"right",n),JT=(e,t)=>Uu(e,t,"left",Wu),eD=(e,t)=>Uu(e,t,"right",Wu);var Dr=(e,t,n,i,o,r,s=!1)=>{if(X(t)||!$t(o)||t.points.length!==2)return!1;if(!s){let l=t.startBinding?.elementId===n.id?0:t.points.length-1,d=R.getPointAtIndexGlobalCoordinates(t,l,i);if(Gi(e,d)<io*1.5/o.zoom.value)return!1}let a=R.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return Gi(e,a)>=io*1.5/o.zoom.value&&Ht({element:n,elementsMap:i,point:e,threshold:Be(n,t),overrideShouldTestInside:!0})},Xx=(e,t,n,i,o,r,s)=>{let a=new Map,l=r.selectedLinearElement?.initialState.arrowOtherEndpointInitialBinding,d=n?"startBinding":"endBinding",c=n?"endBinding":"startBinding",u=e[d],m=l?.mode==="orbit"&&e[c]?.mode==="inside"?l:e[c];if(u&&t){let p=t&&m&&u.elementId===m.elementId;s||p?u={...u,mode:"inside"}:u={...u,mode:"orbit"};let h=n?0:e.points.length-1,f=Ct(e,d,u,t,i,!0);f&&a.set(h,{point:f})}if(m&&m.mode==="orbit"){let p=i.get(m.elementId);if(p&&we(p)&&$t(r)){t&&m.elementId===t.id?m={...m,mode:"inside"}:m={...m,mode:"orbit"};let f=n?e.points.length-1:0,g=Ct(e,c,m,p,i);g&&a.set(f,{point:g})}}a.size>0&&R.movePoints(e,o,a,{[d]:u,[c]:m})},Xu=(e,t,n,i,o,r,s)=>{let a=R.getElement(e.elementId,t);if(!a||!ze(a)||X(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,m=La(n.x-c,n.y-u),p=l?"startBinding":"endBinding",h=dd(m,a,i.getNonDeletedElements(),t,Dt(o.zoom));if(h&&$t(o)){a[p]&&h.id!==d?.elementId&&Xe(a,e.draggedFocusPointBinding,i);let f=s&&a[p]?.mode==="orbit"?"inside":!s&&a[p]?.mode==="inside"?"orbit":null;(!a[p]||f)&&Vt(a,h,f||"orbit",e.draggedFocusPointBinding,i,m),i.mutateElement(a,{[p]:{...a[p],elementId:h.id,mode:f||a[p]?.mode||"orbit",...Pi(a,h,e.draggedFocusPointBinding,t,m)}})}else{let f=new Map,g=l?0:a.points.length-1;f.set(g,{point:R.createPointAt(a,t,m[0],m[1],r)}),R.movePoints(a,i,f),a[p]&&Xe(a,l?"start":"end",i)}Xx(a,h,l,t,i,o,s),h&&$t(o)&&Ru(m,a,i.getElementsIncludingDeleted(),t,i,h)},cD=(e,t,n,i)=>{let o=La(t.origin.x,t.origin.y),r=io*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&we(s)&&!s.isDeleted){let a=_e(e.startBinding.fixedPoint,s,n);if(Dr(a,e,s,n,i,"start")&&Gi(o,a)<=r)return{hitFocusPoint:"start",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]},arrowOtherEndpointInitialBinding:e.endBinding}}}if(e.endBinding?.elementId){let s=n.get(e.endBinding.elementId);if(s&&we(s)&&!s.isDeleted){let a=_e(e.endBinding.fixedPoint,s,n);if(Dr(a,e,s,n,i,"end")&&Gi(o,a)<=r)return{hitFocusPoint:"end",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]},arrowOtherEndpointInitialBinding:e.startBinding}}}return{hitFocusPoint:null,pointerOffset:{x:0,y:0},arrowOtherEndpointInitialBinding:null}},uD=(e,t)=>{Yu(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=R.getElement(e.elementId,t.getNonDeletedElementsMap());Yu(n,"Arrow must be in the scene");let i=e.draggedFocusPointBinding==="start"?"startBinding":"endBinding",o=e.draggedFocusPointBinding==="start"?"endBinding":"startBinding",r=n[i]?.elementId,s=n[o]?.elementId,a=r&&t.getNonDeletedElements().find(d=>d.id!==r&&d.id!==s&&we(d)&&d.boundElements?.find(({id:c})=>c===n.id));a&&t.mutateElement(a,{boundElements:a.boundElements?.filter(({id:d})=>d!==n.id)});let l=r&&t.getNonDeletedElementsMap().get(r);return l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]}),{arrowOtherEndpointInitialBinding:null}},mD=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=La(t,n),a=io*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&we(l)&&!l.isDeleted){let d=_e(e.startBinding.fixedPoint,l,r);if(Dr(d,e,l,r,o,"start")&&Gi(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&we(l)&&!l.isDeleted){let d=_e(e.endBinding.fixedPoint,l,r);if(Dr(d,e,l,r,o,"end")&&Gi(s,d)<=a)return"end"}}return null};I();import{MIME_TYPES as ju,SVG_NS as jx}from"@excalidraw/common";var $x=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),ED=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===ju.binary)throw new Error("Only images can be added to ImageCache");let l=$x(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}},xD=e=>e.filter(t=>Zn(t)),Vx=e=>e?.nodeName.toLowerCase()==="svg",bD=e=>{let t=new DOMParser().parseFromString(e,ju.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Vx(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",jx);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}};I();var SD=(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 h=0,f=0,g=p.map(E=>{let[x,b,y,w]=Je(E);return{elements:E,bounds:[x,b,y,w],width:y-x,height:w-b}});return g.forEach((E,x)=>{h+=E.width,x<g.length-1&&(h+=i),E.height>f&&(f=E.height)}),d+=f,{unitBounds:g,width:h,maxHeight:f}}),u=d+Math.max(0,l.length-1)*i,m=n-u/2;return c.forEach(p=>{let{unitBounds:h,width:f,maxHeight:g}=p,E=t-f/2;h.forEach(x=>{let[b,y]=x.bounds,w=E-b,M=m-y;x.elements.forEach(S=>{o.push(Ke(S,{x:S.x+w,y:S.y+M}))}),E+=x.width+i}),m+=g+i}),o};I();import{pointCenter as Zx,normalizeRadians as Br,pointFrom as me,pointRotateRads as Nt}from"@excalidraw/math";import{MIN_FONT_SIZE as Ga,SHIFT_LOCKING_ANGLE as Lr,rescalePoints as $u,getFontString as vr}from"@excalidraw/common";var FD=(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")X(m)||(Kx(m,i,a,l,o),je(m,i));else if(t){let p=n[0].id,h=u.get(p),f=e.get(p);if(h&&f){let{nextWidth:g,nextHeight:E}=tb(h,f,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});eb(g,E,h,f,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return oe(m)&&je(m,i),!0}else if(n.length>1){if(t==="rotation")return Qx(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:h,flipByY:f,originalBoundingBox:g}=nb(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return ib(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:h,flipByY:f,nextWidth:m,nextHeight:p,originalBoundingBox:g}),!0}}return!1},Kx=(e,t,n,i,o)=>{let[r,s,a,l]=Z(e,t.getNonDeletedElementsMap()),d=(r+a)/2,c=(s+l)/2,u;J(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-c,n-d),o&&(u=u+Lr/2,u=u-u%Lr),u=Br(u));let m=Bt(e),p={angle:u};if(ze(e)&&(p={...p},e.startBinding&&Xe(e,"start",t),e.endBinding&&Xe(e,"end",t)),t.mutateElement(e,p),m){let h=t.getElement(m);if(h&&!U(e)){let{x:f,y:g}=qi(e,h,t.getNonDeletedElementsMap());t.mutateElement(h,{angle:u,x:f,y:g})}}},Vu=(e,t,n,i)=>K(e)||be(e)?{points:$u(0,t,$u(1,n,e.points,i),i)}:{},ka=(e,t,n)=>{let i=e.width;if(Ie(e)){let s=We(e,t);s&&(i=vt(s,e))}let r=e.fontSize*(n/i);return r<Ga?null:{size:r}},qx=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=ka(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=me(e.x,e.y),u=Ca(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=_o(vr({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=sn(t.originalText,vr(t),Math.abs(u)),p=ft(m,vr(t),t.lineHeight),h=p.height,f=me(e.x,e.y),g=Ca(f,e.width,e.height,u,h,t.angle,i,!1,o),E={width:Math.abs(u),height:Math.abs(p.height),x:g.x,y:g.y,text:m,autoResize:!1};n.mutateElement(t,E)}}},Qx=(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+=Lr/2,d-=d%Lr);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!J(u)){let[m,p,h,f]=Z(u,l),g=(m+h)/2,E=(p+f)/2,x=e.get(u.id)?.angle??u.angle,[b,y]=Nt(me(g,E),me(s,a),d+x-u.angle),w=X(u)?{points:Od(u,l)}:{x:u.x+(b-g),y:u.y+(y-E),angle:Br(d+x)};n.mutateElement(u,w),je(u,n,{simultaneouslyUpdated:t}),ze(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||Xe(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||Xe(u,"end",n)));let M=re(u,l);if(M&&!U(u)){let{x:S,y:T}=qi(u,M,l);n.mutateElement(M,{x:S,y:T,angle:Br(d+x)})}}n.triggerUpdate()},RD=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?Z(t[0],n):Je(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=Nt(me(i,o),me(d,c),-u),e){case"n":return Nt(me(i-(r+a)/2,o-s),me(0,0),u);case"s":return Nt(me(i-(r+a)/2,o-l),me(0,0),u);case"w":return Nt(me(i-r,o-(s+l)/2),me(0,0),u);case"e":return Nt(me(i-a,o-(s+l)/2),me(0,0),u);case"nw":return Nt(me(i-r,o-s),me(0,0),u);case"ne":return Nt(me(i-a,o-s),me(0,0),u);case"sw":return Nt(me(i-r,o-l),me(0,0),u);case"se":return Nt(me(i-a,o-l),me(0,0),u);default:return[0,0]}},zD=(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"},Jx=(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"},Ca=(e,t,n,i,o,r,s,a,l)=>{let d=Jx(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)}}},eb=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(oe(n)&&oe(i))return qx(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=re(n,u);if(m){let g=o.get(m.id);if(g&&(c={fontSize:g.fontSize}),l){let E={...n,width:e,height:t},x=ka(m,u,vt(E,m));if(x===null)return;c={fontSize:x.size}}else{let E=Yl(vr(m),m.lineHeight),x=Xl(m.fontSize,m.lineHeight);e=Math.max(e,E),t=Math.max(t,x)}}let p=Vu(i,e,t,!0),h=me(i.x,i.y);if(K(i)){let[g,E]=ue(i,o);h=me(g,E)}let f=Ca(h,i.width,i.height,e,t,i.angle,s,l,d);if(K(i)&&p.points){let g=i.x-h[0],E=i.y-h[1];f.x+=g,f.y+=E;let x=p.points[0][0],b=p.points[0][1];f.x+=x,f.y+=b,p.points=p.points.map(y=>me(y[0]-x,y[1]-b))}if(e<0&&(f.x=f.x+e),t<0&&(f.y=f.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]]}),U(n)&&m&&l){let g=e/n.width*m.fontSize;if(g<Ga)return;c.fontSize=g}if(e!==0&&t!==0&&Number.isFinite(f.x)&&Number.isFinite(f.y)){let g={...f,width:Math.abs(e),height:Math.abs(t),...p};ze(n)&&(n.startBinding&&(g={...g},n.startBinding&&Xe(n,"start",r)),n.endBinding&&(g={...g,endBinding:null})),r.mutateElement(n,g,{informMutation:a,isDragging:!1}),m&&c!=null&&r.mutateElement(m,{fontSize:c.fontSize}),Qn(n,r,s,l,d),je(n,r)}},tb=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=yn(t,t.width,t.height,!0),u=me(a,l),m=me(d,c),p=Zx(u,m),h=Nt(me(i,o),p,-t.angle),[f,g,E,x]=yn(e,e.width,e.height,!0),b=E-f,y=x-g,w=m[0]-u[0],M=m[1]-u[1],S=w/b,T=M/y;n.includes("e")&&(S=(h[0]-u[0])/b),n.includes("s")&&(T=(h[1]-u[1])/y),n.includes("w")&&(S=(m[0]-h[0])/b),n.includes("n")&&(T=(m[1]-h[1])/y);let A=e.width*S,F=e.height*T;if(s&&(A=2*A-t.width,F=2*F-t.height),r){let B=Math.abs(A)/t.width,k=Math.abs(F)/t.height;if(n.length===1&&(F*=B,A*=k),n.length===2){let G=Math.max(B,k);A=t.width*G*Math.sign(A),F=t.height*G*Math.sign(F)}}return{nextWidth:A,nextHeight:F}},nb=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(G=>t.get(G.id)),d=l.reduce((G,_)=>{if(!K(_))return G;let W=Bt(_);if(!W)return G;let D=t.get(W)??null;return Ie(D)?[...G,{...D,...R.getBoundTextElementPosition(_,D,n)}]:G},[]),c=mn(l.map(G=>G).concat(d)),{minX:u,minY:m,maxX:p,maxY:h,midX:f,midY:g}=c,E=p-u,x=h-m,b={ne:[u,h],se:[u,m],sw:[p,m],nw:[p,h],e:[u,m+x/2],w:[p,m+x/2],n:[u+E/2,h],s:[u+E/2,m]},[y,w]=a?[f,g]:b[i],M=a?2:1,S=Math.max(Math.abs(o-y)/E||0,Math.abs(r-w)/x||0)*M,T=i.includes("e")||i.includes("w")?Math.abs(o-y)*M:E,A=i.includes("n")||i.includes("s")?Math.abs(r-w)*M:x;s&&(T=E*S*Math.sign(o-y),A=x*S*Math.sign(r-w));let F={ne:[o<y,r>w],se:[o<y,r<w],sw:[o>y,r<w],nw:[o>y,r>w],e:[o<y,!1],w:[o>y,!1],n:[!1,r>w],s:[!1,r<w]},[B,k]=F[i].map(G=>G);return{originalBoundingBox:c,nextWidth:T,nextHeight:A,flipByX:B,flipByY:k}},ib=(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((M,S)=>{let T=o.get(S.id);return T&&M.push({orig:T,latest:S}),M},[]),p;if(u)p=u;else{let M=m.reduce((S,{orig:T})=>{if(!K(T))return S;let A=Bt(T);if(!A)return S;let F=o.get(A)??null;return Ie(F)?[...S,{...F,...R.getBoundTextElementPosition(T,F,t)}]:S},[]);p=mn([...m.map(({orig:S})=>S),...M])}let{minX:h,minY:f,maxX:g,maxY:E,midX:x,midY:b}=p,y=g-h,w=E-f;if(c===void 0&&d===void 0&&(c=y,d=w),r&&(c===void 0?c=d*(y/w):d===void 0?d=c*(w/y):Math.abs(c/d-y/w)>.001&&(c=d*(y/w))),c&&d){let M=n.includes("e")||n.includes("w")?Math.abs(c)/y:1,S=n.includes("n")||n.includes("s")?Math.abs(d)/w:1,T;n.length===1?T=n.includes("e")||n.includes("w")?M:S:T=Math.max(Math.abs(c)/y||0,Math.abs(d)/w||0);let A={ne:[h,E],se:[h,f],sw:[g,f],nw:[g,E],e:[h,f+w/2],w:[g,f+w/2],n:[h+y/2,E],s:[h+y/2,f]},[F,B]=s?[x,b]:A[n],k=r||m.some(P=>P.latest.angle!==0||oe(P.latest)||nc(P.latest));k&&(M=T,S=T);let[G,_]=[a?-1:1,l?-1:1],W=[];for(let{orig:P,latest:v}of m){if(oe(P)&&Ie(P))continue;let C=P.width*M,z=P.height*S,Q=Br(P.angle*G*_),ee=K(P)||be(P),te=P.x-F,ne=P.y-B,Ae=a&&!ee?C:0,Ft=l&&!ee?z:0,Rt=F+G*(te*M+Ae),gn=B+_*(ne*S+Ft),pe=Vu(P,C*G,z*_,!1),ie={x:Rt,y:gn,width:C,height:z,angle:Q,...pe};if(X(P)&&(P.startBinding&&(ie.startBinding={...P.startBinding,fixedPoint:[a?-P.startBinding.fixedPoint[0]+1:P.startBinding.fixedPoint[0],l?-P.startBinding.fixedPoint[1]+1:P.startBinding.fixedPoint[1]]}),P.endBinding&&(ie.endBinding={...P.endBinding,fixedPoint:[a?-P.endBinding.fixedPoint[0]+1:P.endBinding.fixedPoint[0],l?-P.endBinding.fixedPoint[1]+1:P.endBinding.fixedPoint[1]]}),P.fixedSegments&&pe.points&&(ie.fixedSegments=P.fixedSegments.map(Te=>({...Te,start:pe.points[Te.index-1],end:pe.points[Te.index]})))),ke(P)&&(ie.scale=[P.scale[0]*G,P.scale[1]*_]),oe(P)){let Te=ka(P,t,C);if(!Te)return;ie.fontSize=Te.size}let Ce=o.get(Bt(P)??"");if(Ce)if(k){let Te=Ce.fontSize*T;if(Te<Ga)return;ie.boundTextFontSize=Te}else ie.boundTextFontSize=Ce.fontSize;W.push({element:v,update:ie})}let D=W.map(({element:P})=>P),L=new Map(W.map(({element:P})=>[P.id,P]));for(let{element:P,update:{boundTextFontSize:v,...C}}of W){let{angle:z}=C;i.mutateElement(P,C),je(P,i,{simultaneouslyUpdated:D}),ze(P)&&(P.startBinding&&(L.has(P.startBinding.elementId)||Xe(P,"start",i)),P.endBinding&&(L.has(P.endBinding.elementId)||Xe(P,"end",i)));let Q=re(P,t);Q&&v&&(i.mutateElement(Q,{fontSize:v,angle:K(P)?void 0:z}),Qn(P,i,n,!0,s))}i.triggerUpdate()}};I();import{pointFrom as Pt,pointOnLineSegment as em,pointRotateRads as Gr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as _a}from"@excalidraw/common";I();import{DEFAULT_TRANSFORM_HANDLE_SPACING as Na}from"@excalidraw/common";import{pointFrom as Zu,pointRotateRads as ob}from"@excalidraw/math";var Ku={mouse:8,pen:16,touch:28},rb=16,Qu={e:!0,s:!0,n:!0,w:!0},jD={e:!0,s:!0,n:!0,w:!0},$D={e:!0,s:!0,n:!0,w:!0,rotation:!0},qu={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},Oa={e:!0,s:!0,n:!0,w:!0},hn=(e,t,n,i,o,r,s)=>{let[a,l]=ob(Zu(e+n/2,t+i/2),Zu(o,r),s);return[a-n/2,l-i/2,n,i]},Cr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),Fa=e=>Cr(e)?Qu:{},Ra=([e,t,n,i,o,r],s,a,l,d={},c=4,u=Na)=>{let m=Ku[l],p=m/a.value,h=m/a.value,f=m/a.value,g=m/a.value,E=n-e,x=i-t,b=c/a.value,y=(m-u*2)/(2*a.value),w={nw:d.nw?void 0:hn(e-b-f+y,t-b-g+y,p,h,o,r,s),ne:d.ne?void 0:hn(n+b-y,t-b-g+y,p,h,o,r,s),sw:d.sw?void 0:hn(e-b-f+y,i+b-y,p,h,o,r,s),se:d.se?void 0:hn(n+b-y,i+b-y,p,h,o,r,s),rotation:d.rotation?void 0:hn(e+E/2-p/2,t-b-g+y-rb/a.value,p,h,o,r,s)},M=5*Ku.mouse/a.value;return Math.abs(E)>M&&(d.n||(w.n=hn(e+E/2-p/2,t-b-g+y,p,h,o,r,s)),d.s||(w.s=hn(e+E/2-p/2,i+b-y,p,h,o,r,s))),Math.abs(x)>M&&(d.w||(w.w=hn(e-b-f+y,t+x/2-h/2,p,h,o,r,s)),d.e||(w.e=hn(n+b-y,t+x/2-h/2,p,h,o,r,s))),w},Ju=(e,t,n,i="mouse",o=Qu)=>{if(e.locked||X(e))return{};if(e.type==="freedraw"||K(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=Oa:s[0]>0&&s[1]<0?o=qu:s[0]>0&&s[1]>0?o=Oa:s[0]<0&&s[1]>0?o=qu:s[0]<0&&s[1]<0&&(o=Oa)}}else J(e)&&(o={...o,rotation:!0});let r=K(e)?Na+8:ke(e)?0:Na;return Ra(Z(e,n,!0),e.angle,t,i,o,r,ke(e)?0:void 0)},VD=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return X(i)?!1:K(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var Ha=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],sb=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=Ju(e,r,t,s,Fa(a));if(l&&Ha(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?Ha(m,i,o):!1});if(c.length>0)return c[0];if(Cr(a)){let[u,m,p,h,f,g]=Z(e,t);if(!(K(e)&&e.points.length<=2)){let E=ke(e)?0:_a/r.value,x=_a/r.value,b=tm(Pt(u-E,m-E),Pt(p+E,h+E),Pt(f,g),e.angle);for(let[y,w]of Object.entries(b))if(em(Pt(i,o),w,x))return y}}return!1},nv=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=sb(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),iv=([e,t,n,i],o,r,s,a,l)=>{let d=Ra([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,Fa(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&Ha(m,o,r)});if(c)return c;if(Cr(l)){let u=(e+n)/2,m=(t+i)/2,p=_a/s.value,h=tm(Pt(e-p,t-p),Pt(n+p,i+p),Pt(u,m),0);for(let[f,g]of Object.entries(h))if(em(Pt(o,r),g,p))return f}return!1},za=["ns","nesw","ew","nwse"],ab=(e,t)=>{let n=za.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=za[(n+i)%za.length]}return e},ov=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=ab(o,t.angle)),o?`${o}-resize`:""},tm=([e,t],[n,i],o,r)=>{let s=Gr(Pt(e,t),o,r),a=Gr(Pt(n,t),o,r),l=Gr(Pt(e,i),o,r),d=Gr(Pt(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};I();var lv=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||Kt(t,e).length));I();import{pointFrom as kr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as lb,DEFAULT_FONT_SIZE as db,TEXT_ALIGN as cb,VERTICAL_ALIGN as ub,getSizeFromPoints as mb,randomId as pb,arrayToMap as fb,assertNever as Wa,cloneJSON as im,getFontString as hb,isDevEnv as gb,toBrandedType as Eb,getLineHeight as xb}from"@excalidraw/common";var Or={width:100,height:0},Yn=100,bb=(e,t,n)=>{let i=ai({x:0,y:0,textAlign:cb.CENTER,verticalAlign:ub.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor,labelPosition:U(e)?Kl:null});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),Yo(i,e,n),[e,i]},nm=(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??Yn,u=t?.height??Yn,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,h=t.y||e.y-u/2,f=m?m.type:t.type;if(f){if(f==="text"){let g="";m&&m.type==="text"?g=m.text:t.type==="text"&&(g=t.text),g||console.error(`No text found for start binding text element for ${e.id}`),r=ai({x:p,y:h,type:"text",...m,...t,text:g}),Object.assign(r,{x:t.x||e.x-r.width,y:t.y||e.y-r.height/2})}else switch(f){case"rectangle":case"ellipse":case"diamond":{r=Ai({x:p,y:h,width:c,height:u,...m,...t,type:f});break}default:Wa(e,`Unhandled element start type "${t.type}"`,!0)}Vt(e,r,"orbit","start",o)}}if(n){let c=n?.height??Yn,u=n?.width??Yn,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,h=n.y||e.y-c/2,f=m?m.type:n.type;if(f){if(f==="text"){let g="";m&&m.type==="text"?g=m.text:n.type==="text"&&(g=n.text),g||console.error(`No text found for end binding text element for ${e.id}`),s=ai({x:p,y:h,type:"text",...m,...n,text:g}),Object.assign(s,{y:n.y||e.y-s.height/2})}else switch(f){case"rectangle":case"ellipse":case"diamond":{s=Ai({x:p,y:h,width:u,height:c,...m,...n,type:f});break}default:Wa(e,`Unhandled element end type "${f}"`,!0)}Vt(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=im(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,R.getNormalizeElementPointsAndCoords({...e,points:d})),{linearElement:e,startBoundElement:r,endBoundElement:s}},Ua=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>Ks(Array.from(this.excalidrawElements.values()));getElementsMap=()=>Eb(fb(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},Pv=(e,t)=>{if(!e)return[];let n=im(e),i=new Ua,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:pb()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||Yn,p=l?.label?.text&&l.height===void 0?0:l?.height||Yn;d=Ai({...l,width:m,height:p});break}case"line":{let m=l.width||Or.width,p=l.height||Or.height;d=_c({width:m,height:p,points:[kr(0,0),kr(m,p)],...l});break}case"arrow":{let m=l.width||Or.width,p=l.height||Or.height;d=wr({width:m,height:p,endArrowhead:"arrow",points:[kr(0,0),kr(m,p)],...l,type:"arrow"}),Object.assign(d,mb(d.points));break}case"text":{let m=l?.fontFamily||lb,p=l?.fontSize||db,h=l?.lineHeight||xb(m),f=l.text??"",g=Ki(f),E=ft(g,hb({fontFamily:m,fontSize:p}),h);d=ai({width:E.width,height:E.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=Hc({width:l?.width||Yn,height:l?.height||Yn,...l});break}case"frame":{d=Fc({x:0,y:0,...l});break}case"magicframe":{d=Rc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,Wa(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 Ci(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]=bb(c,d?.label,a);if(i.add(u),i.add(m),U(u)){let p=d.type==="arrow"?d?.start:void 0,h=d.type==="arrow"?d?.end:void 0;if(p&&p.id){let x=r.get(p.id);x&&Object.assign(p,{id:x})}if(h&&h.id){let x=r.get(h.id);x&&Object.assign(h,{id:x})}let{linearElement:f,startBoundElement:g,endBoundElement:E}=nm(u,p,h,i,a);u=f,i.add(f),i.add(g),i.add(E)}}else switch(d.type){case"arrow":{let{start:u,end:m}=d;if(u&&u.id){let g=r.get(u.id);Object.assign(u,{id:g})}if(m&&m.id){let g=r.get(m.id);Object.assign(m,{id:g})}let{linearElement:p,startBoundElement:h,endBoundElement:f}=nm(c,u,m,i,a);i.add(p),i.add(h),i.add(f);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(w=>{let M=r.get(w);if(!M)throw new Error(`Element with ${w} wasn't mapped correctly`);let S=i.getElement(M);if(!S)throw new Error(`Frame element with id ${M} doesn't exist`);Object.assign(S,{frameId:c.id}),S?.boundElements?.forEach(T=>{let A=i.getElement(T.id);if(!A)throw new Error(`Bound element with id ${T.id} doesn't exist`);Object.assign(A,{frameId:c.id}),u.push(A)}),u.push(S)});let[m,p,h,f]=Je(u),g=10;m=m-g,p=p-g,h=h+g,f=f+g;let E=c?.x||m,x=c?.y||p,b=c?.width||h-m,y=c?.height||f-p;Object.assign(c,{x:E,y:x,width:b,height:y}),gb()&&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()};I();var Tv=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return Xu(n.selectedLinearElement,e.scene.getNonDeletedElementsMap(),e.lastPointerMoveCoords,e.scene,n,e.getEffectiveGridSize(),t.altKey),!0;if(n.selectedLinearElement.hoverPointIndex!==null&&e.lastPointerMoveEvent&&n.selectedLinearElement.initialState.lastClickedPoint>=0&&n.selectedLinearElement.isDragging)return R.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};I();var wb=e=>{switch(e){case void 0:case null:return null;case"dot":return"circle";case"crowfoot_one":return"cardinality_one";case"crowfoot_many":return"cardinality_many";case"crowfoot_one_or_many":return"cardinality_one_or_many";default:return e}},Bv=e=>{let t=wb(e);return t===null?null:t};I();import{getBoundsFromPoints as am,getElementAbsoluteCoords as yb}from"@excalidraw/element/bounds";import{newArrowElement as om,newElement as Pb,newLinearElement as Nr}from"@excalidraw/element/newElement";import{ELEMENT_PENDING_DRAW_SHAPE_OPACITY as Ib,getStrokeWidthByKey as Fr,ROUNDNESS as rm}from"@excalidraw/common";import{convexHull as Sb,distanceToLineSegment as Mb,elongation as Ab,kurtosis as sm,lineSegment as Tb,orientPrincipalAxes as Db,pointFrom as tt,polygonArea as vb,principalAxes as Bb,principalCoords as Lb,skewness as Cb}from"@excalidraw/math";var Gb=64,kb=25,Ob=.15,Nb=.25,Fb=.5,Rb=.15,zb=.3,_b=1.5,ki=3;function Hb(e,t){let n=0;for(let a=1;a<e.length;a++)n+=Math.hypot(e[a][0]-e[a-1][0],e[a][1]-e[a-1][1]);let i=n/(t-1),o=0,r=[e[0]],s=e[0];for(let a=1;a<e.length;a++){let l=e[a],d=Math.hypot(l[0]-s[0],l[1]-s[1]);if(o+d>=i){let c=i-o;for(;c<=d+1e-10;){let u=c/d,m=[s[0]+u*(l[0]-s[0]),s[1]+u*(l[1]-s[1])];if(r.push(m),r.length===t)return r;s=m,o=0,c+=i}o=d-(c-i)}else o+=d;s=l}for(;r.length<t;)r.push(e[e.length-1]);return r}function Wb(e){let t=e[0],n=t,i=0;for(let s of e){let a=Math.hypot(s[0]-t[0],s[1]-t[1]);a>i&&(i=a,n=s)}if(i===0)return 0;let o=Tb(t,n),r=0;for(let s of e)Math.hypot(s[0]-n[0],s[1]-n[1])<=Fb*i||(r=Math.max(r,Mb(s,o)));return r/i}function Ub(e){let t=[];for(let n=ki;n<e.length-ki;n++){let[i,o]=e[n-ki],[r,s]=e[n],[a,l]=e[n+ki],d=r-i,c=s-o,u=a-r,m=l-s;t.push(Math.abs(Math.atan2(d*m-c*u,d*u+c*m)))}return t}function Yb(e){let t=Ub(e),n=t.reduce((r,s)=>r+s,0);if(n===0)return 0;let i=new Array(t.length).fill(!1),o=0;for(let r=0;r<4;r++){let s=-1,a=0;for(let l=0;l<t.length;l++)!i[l]&&t[l]>a&&(a=t[l],s=l);if(s<0)break;for(let l=s-ki;l<=s+ki;l++)l>=0&&l<t.length&&!i[l]&&(o+=t[l],i[l]=!0)}return o/n}function Xb(e){let t=Hb(e,Gb),n=0;for(let m=1;m<t.length;m++)n+=Math.hypot(t[m][0]-t[m-1][0],t[m][1]-t[m-1][1]);let i=Math.hypot(t[t.length-1][0]-t[0][0],t[t.length-1][1]-t[0][1]),o=Db(t,Bb(t)),r=Lb(t,o).map(([m])=>m),s=Sb(t),[a,l,d,c]=am(t),u=(d-a)*(c-l);return{gapRatio:n>0?i/n:0,elongation:Ab(o),majorSkew:Cb(r),hullFillRatio:u>0?vb(s)/u:0,cornerTurnShare:Yb(t),kurtosisProduct:sm(t.map(([m])=>m))*sm(t.map(([,m])=>m)),shaftDeviationRatio:Wb(t)}}var jb=[{type:"rectangle",hullFillRatio:1,cornerTurnShare:.95,kurtosisProduct:1.83},{type:"diamond",hullFillRatio:.5,cornerTurnShare:.95,kurtosisProduct:3.24},{type:"ellipse",hullFillRatio:Math.PI/4,cornerTurnShare:.55,kurtosisProduct:2.25}],$b=.2,Vb=.2,Zb=.7;function Kb(e){let t="freedraw",n=_b;for(let i of jb){let o=Math.hypot((e.hullFillRatio-i.hullFillRatio)/$b,(e.cornerTurnShare-i.cornerTurnShare)/Vb,(e.kurtosisProduct-i.kurtosisProduct)/Zb);o<n&&(n=o,t=i.type)}return t}function qb(e){return e.elongation>Nb||e.shaftDeviationRatio>Rb?"freedraw":Math.abs(e.majorSkew)>=zb?"arrow":"line"}function Qb(e){return e.gapRatio>Ob?qb(e):Kb(e)}function Jb(e,t,n){let[i,o,r,s]=t,a=r-i,l=s-o;if(a===0&&l===0)return e[e.length-1];let d=[tt(i,o),tt((i+r)/2,o),tt(r,o),tt(r,(o+s)/2),tt(r,s),tt((i+r)/2,s),tt(i,s),tt(i,(o+s)/2)],c=-1,u=tt(r,s);for(let h of d){let f=Math.hypot(h[0]-n[0],h[1]-n[1]);f>c&&(c=f,u=h)}let m=1/0,p=e[e.length-1];for(let h of e){let f=Math.hypot(h[0]-u[0],h[1]-u[1]);f<m&&(m=f,p=h)}return p}var ew=(e,t,n=1)=>{typeof window<"u"&&(window.LAST_POINTS=e.map(([u,m])=>tt(u,m)));let i=am(e),[o,r,s,a]=i,l=Math.max(s-o,a-r);if(e.length<3||l*n<kb)return{type:"freedraw",points:e,boundingBox:i};let d=Qb(Xb(e));return{type:t?.type==="arrow"&&d!=="arrow"?"freedraw":d,points:e,boundingBox:i}},tw=(e,t,n,i,o)=>{let r=ew(e,i,t.zoom.value),s=r.boundingBox,[a,l,d,c]=s,m=(o??ea([...n.values()])).find(h=>{let[f,g,E,x]=yb(h,n);return f<=a&&g<=l&&E>=d&&x>=c})?.id??null,p=t.currentItemRoundness==="round"?{type:Fo(r.type)?rm.ADAPTIVE_RADIUS:rm.PROPORTIONAL_RADIUS}:null;switch(r.type){case"rectangle":case"diamond":case"ellipse":return Pb({type:r.type,x:r.boundingBox[0],y:r.boundingBox[1],width:r.boundingBox[2]-r.boundingBox[0],height:r.boundingBox[3]-r.boundingBox[1],groupIds:[],angle:0,frameId:m,roundness:p,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Fr(r.type,t.currentItemStrokeWidthKey)});case"arrow":{let[h,f]=r.points[0],[g,E]=Jb(r.points,r.boundingBox,r.points[0]),x=tt(g-h,E-f);if(Math.hypot(g-r.points[0][0],E-r.points[0][1])<60){let M=Nr({type:"line",x:h,y:f,points:[tt(r.points[0][0]-h,r.points[0][1]-f),x],groupIds:[],frameId:m,locked:!1,angle:0,roundness:p,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Fr(r.type,t.currentItemStrokeWidthKey)}),S=R.getNormalizeElementPointsAndCoords(M);return Nr({...M,...S})}let y=om({type:"arrow",x:h,y:f,startArrowhead:t.currentItemStartArrowhead,endArrowhead:t.currentItemEndArrowhead,points:[tt(r.points[0][0]-h,r.points[0][1]-f),x],groupIds:[],frameId:m,locked:!1,angle:0,roundness:p,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Fr(r.type,t.currentItemStrokeWidthKey)}),w=R.getNormalizeElementPointsAndCoords(y);return om({...y,...w})}case"line":{let[h,f]=r.points[0],g=r.points[r.points.length-1],E=Nr({type:r.type,x:h,y:f,points:[tt(r.points[0][0]-h,r.points[0][1]-f),tt(g[0]-h,g[1]-f)],groupIds:[],frameId:m,locked:!1,angle:0,roundness:p,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Fr(r.type,t.currentItemStrokeWidthKey)}),x=R.getNormalizeElementPointsAndCoords(E);return Nr({...E,...x})}}},nw=(e,t)=>{if(!e||e.type!==t.type||e.x!==t.x||e.y!==t.y||e.width!==t.width||e.height!==t.height||e.angle!==t.angle)return!1;if(K(e)&&K(t)){if(e.points.length!==t.points.length)return!1;for(let n=0;n<e.points.length;n++)if(e.points[n][0]!==t.points[n][0]||e.points[n][1]!==t.points[n][1])return!1}return!0},_v=(e,t)=>{if(e.state.activeTool.type==="autoshape"){e.drawShape.trail.addPointToPath(t.x,t.y);let n=e.drawShape.trail.getCurrentPoints();if(n.length>=3){let i=tw(n,e.state,e.scene.getNonDeletedElementsMap(),e.state.newElement,e.scene.getNonDeletedFramesLikes());if(i&&!Oe(i)){let o=e.state.newElement,r={...i,id:o?.type===i.type?o.id:i.id,seed:1,opacity:Ib,isDeleted:!1};nw(o,r)||e.setState({newElement:r})}else e.state.newElement!==null&&e.setState({newElement:null})}return!0}return!1};var Xv=e=>e.reduce((t,n)=>t+n.version,0),ru=e=>{let t=5381;for(let n of iw(e))t=(t<<5)+t+n.versionNonce;return t>>>0},su=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},Ve=e=>!e.isDeleted,jv=e=>e.filter(t=>Ve(t)&&!Nc(t)),On=e=>e.filter(Ve);export{zn as AppStateDelta,Hf as BASE_ARROW_MIN_LENGTH,vd as BASE_BINDING_GAP,Jn as BASE_BINDING_GAP_ELBOW,ce as BASE_PADDING,Bn as BindableElement,vn as BoundElement,ut as CaptureUpdateAction,Kl as DEFAULT_BOUND_TEXT_LABEL_POSITION,oE as DEFAULT_BUCKET_FILL_OPTIONS,dS as DEFAULT_LINK_SIZE,Qu as DEFAULT_OMIT_SIDES,$ as Delta,wa as DurableIncrement,ca as ElementBounds,_n as ElementsDelta,ya as EphemeralIncrement,io as FOCUS_POINT_SIZE,Lu as FlowChartCreator,Bu as FlowChartNavigator,Le as HEADING_DOWN,Ne as HEADING_LEFT,he as HEADING_RIGHT,Ze as HEADING_UP,Gg as INVISIBLY_SMALL_ELEMENT_SIZE,Vs as InvalidFractionalIndexError,R as LinearElementEditor,Re as MINIMAL_CROP_SIZE,$D as OMIT_SIDES_FOR_FRAME,jD as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Ci as Scene,Et as ShapeCache,nu as Store,fo as StoreChange,Pa as StoreDelta,Mr as StoreIncrement,Hn as StoreSnapshot,lt as aabbForElement,Rh as addElementsToFrame,K1 as addToGroup,dM as alignElements,Vf as avoidRectangularCorner,Vt as bindBindingElement,D1 as bindBindingElementToFixedPoint,uc as bindElementsToFramesAfterDuplication,Wf as bindOrUnbindBindingElement,S1 as bindOrUnbindBindingElements,Os as bindPointToSnapToElementOutline,kd as bindingProperties,ta as boundsContainBounds,Pd as bumpVersion,qf as calculateFixedPointForElbowArrowBinding,Pi as calculateFixedPointForNonElbowArrowBinding,E0 as canApplyRoundnessTypeToElement,Gl as canBecomePolygon,ql as canChangeRoundness,xx as canCreateLinkFromElements,SP as canHaveArrowheads,Cr as canResizeFromSides,hi as charWidth,fe as compareHeading,qi as computeBoundTextPosition,ZM as computeBucketFillPolygon,fs as computeContainerDimensionForBoundText,$0 as containsCJK,Pv as convertToExcalidrawElements,tw as convertToShape,_v as convertToShapeHandlePointerMoveFromPointerDown,IT as createPlaceholderEmbeddableLabel,Aa as createSrcDoc,d0 as cropElement,In as deconstructDiamondElement,Vi as deconstructLinearOrFreeDrawElement,Pn as deconstructRectanguloidElement,ba as deepCopyElement,mT as defaultGetElementLinkFromSelection,_0 as detectLineHeight,Ut as distanceToElement,ZA as distributeElements,gt as doBoundsIntersect,aT as dragNewElement,Ex as dragNewTextElement,rT as dragSelectedElements,TE as duplicateElement,uA as duplicateElements,Z1 as editGroupForSelectedElement,se as elementCenterPoint,Cn as elementOverlapsWithFrame,so as elementWithCanvasCache,kn as elementsAreInFrameBounds,tc as elementsAreInSameGroup,rc as elementsOverlappingBBox,MT as embeddableURLValidator,Th as excludeElementsInFramesFromSelection,WI as filterElementsEligibleAsFrameChildren,A1 as fixBindingsAfterDeletion,Gd as fixDuplicatedBindingsAfterDuplication,Ms as flipHeading,VI as frameAndChildrenSelectedTogether,_l as generateLinearCollisionShape,ct as generateRoughOptions,pI as getActiveTextElement,jo as getAllHoveredElementAtPoint,Xl as getApproxMinLineHeight,Yl as getApproxMinLineWidth,Od as getArrowLocalFixedPoints,Ag as getArrowheadAngle,Bv as getArrowheadForPicker,et as getArrowheadPoints,Mg as getArrowheadSize,Be as getBindingGap,T1 as getBindingSideMidPoint,_s as getBindingStrategyForDraggingBindingElementEndpoints,re as getBoundTextElement,Bt as getBoundTextElementId,sP as getBoundTextElementPosition,Qi as getBoundTextMaxHeight,vt as getBoundTextMaxWidth,ri as getBoundsFromPoints,ln as getCenterForBounds,mn as getCommonBoundingBox,Je as getCommonBounds,Nh as getCommonFrameId,oP as getContainerCenter,hs as getContainerCoords,We as getContainerElement,Gn as getContainingFrame,on as getCornerRadius,$o as getCubicBezierCurveBound,ov as getCursorForResizingElement,Uh as getDefaultFrameName,x0 as getDefaultRoundnessTypeForElement,zl as getDiamondBaseCorners,fi as getDiamondPoints,sT as getDragOffsetXY,jS as getDraggedElementsBounds,Z as getElementAbsoluteCoords,ue as getElementBounds,Si as getElementLineSegments,Xs as getElementPointsCoords,Ac as getElementShape,nv as getElementWithTransformHandleType,mc as getElementsCompletelyInFrame,Qe as getElementsInGroup,HI as getElementsInNewFrame,_I as getElementsInResizingFrame,kI as getElementsIntersectingFrame,$I as getElementsOverlappingFrame,oc as getElementsWithinSelection,PT as getEmbedLink,OM as getEndpointBoundTextDragAnchor,c0 as getFlipAdjustedCropPosition,Ln as getFrameChildren,Fh as getFrameChildrenInsertionIndex,ea as getFrameLikeElements,jI as getFrameLikeTitle,mS as getFreedrawOutlineAsSegments,gg as getFreedrawOutlinePoints,Tc as getFreedrawStrokeCenterPoints,_e as getGlobalFixedPointForBindableElement,Qf as getGlobalFixedPoints,yd as getHeadingForElbowArrowSnap,an as getHoveredElementForBinding,dd as getHoveredElementForFocusPoint,xD as getInitializedImageElements,Ho as getLineHeightInPx,Sn as getLineWidth,C0 as getLinearElementPathSegments,b0 as getLinearElementSubType,pT as getLinkIdAndTypeFromSelection,qd as getLockedLinearCursorAlignSize,Mp as getMaxCharWidth,Q1 as getMaximumGroups,W0 as getMinCharWidth,oo as getMinMaxXYFromCurvePathOps,_o as getMinTextElementWidth,ic as getNewGroupIdsForDuplication,On as getNonDeletedElements,ec as getNonDeletedGroupIds,nM as getNormalizedDimensions,Li as getObservedAppState,Fa as getOmitSidesForEditorInterface,O0 as getOriginalContainerHeightFromCache,ua as getPerfectElementSize,XS as getRectangleBoxAbsoluteCoords,eg as getRenderOpacity,zD as getResizeArrowDirection,RD as getResizeOffsetXY,yn as getResizedElementAbsoluteCoords,zI as getRootElements,Xv as getSceneVersion,Kt as getSelectedElements,dr as getSelectedElementsByGroup,$s as getSelectedGroupForElement,Ph as getSelectedGroupIdForElement,wh as getSelectedGroupIds,mI as getSelectionStateForElements,xp as getSnapOutlineMidPoint,uI as getTargetElements,_h as getTargetFrame,ma as getTextAnchorRatios,GM as getTextBindingForArrowEndpoint,rP as getTextElementAngle,cP as getTextFromElements,Sp as getTextHeight,jl as getTextWidth,iv as getTransformHandleTypeFromCoords,Ju as getTransformHandles,Ra as getTransformHandlesFromCoords,CM as getUnboundArrowEndpointAtPoint,Ml as getUncroppedImageElement,ts as getUncroppedWidthAndHeight,dI as getVisibleAndNonSelectedElements,jv as getVisibleElements,$S as getVisibleSceneBounds,kp as getWrappedTextLines,RI as groupByFrameLikes,NI as groupsAreAtLeastIntersectingTheFrame,FI as groupsAreCompletelyOutOfFrame,Qn as handleBindTextResize,Xu as handleFocusPointDrag,mD as handleFocusPointHover,cD as handleFocusPointPointerDown,uD as handleFocusPointPointerUp,gi as hasBackground,_t as hasBoundTextElement,VD as hasBoundingBox,PP as hasFreedrawMode,bP as hasStrokeColor,yP as hasStrokeStyle,wP as hasStrokeWidth,ru as hashElementsVersion,su as hashString,st as headingForPoint,Ei as headingForPointFromElement,Lt as headingForPointIsHorizontal,at as headingIsHorizontal,XP as headingIsVertical,df as hitElementBoundText,lf as hitElementBoundingBox,zP as hitElementBoundingBoxOnly,Ht as hitElementItself,ot as intersectElementWithLineSegment,g0 as isArrowBoundToElement,U as isArrowElement,we as isBindableElement,Is as isBindableElementInsideOtherBindable,ze as isBindingElement,ap as isBindingElementType,$t as isBindingEnabled,Ie as isBoundToContainer,Qc as isBucketFillCompatible,OI as isCursorInFrame,rp as isCurvedArrow,X as isElbowArrow,tM as isElementCompletelyInViewport,Js as isElementContainingFrame,fc as isElementInFrame,yh as isElementInGroup,sc as isElementInViewport,Mi as isElementIntersectingFrame,fT as isElementLink,w0 as isEligibleFrameChildType,Tl as isEmbeddableElement,kM as isEndpointBoundText,Bl as isExcalidrawElement,Jf as isFixedPoint,Ll as isFlowchartNodeElement,Dr as isFocusPointVisible,No as isFrameElement,J as isFrameLikeElement,be as isFreeDrawElement,ip as isFreeDrawElementType,Vx as isHTMLSVGElement,ko as isIframeElement,Oo as isIframeLikeElement,ke as isImageElement,nc as isInGroup,Zn as isInitializedImageElement,Nc as isInvisiblySmallElement,Oe as isLineElement,K as isLinearElement,sp as isLinearElementType,Dl as isMagicFrameElement,z0 as isMeasureTextSupported,zT as isNodeInFlowchart,Ve as isNonDeletedElement,Tt as isPathALoop,it as isPointInElement,ji as isRectangularElement,vl as isRectanguloidElement,KM as isRestylableFill,bh as isSelectedViaGroup,op as isSharpArrow,h0 as isSimpleArrow,cI as isSomeElementSelected,lp as isTextBindableContainer,oe as isTextElement,Fo as isUsingAdaptiveRadius,Cl as isUsingProportionalRadius,ns as isValidPolygon,dP as isValidTextContainer,$x as loadHTMLImageElement,js as makeNextSelectedElementIds,Dt as maxBindingDistance_simple,Tv as maybeHandleArrowPointlikeDrag,ST as maybeParseEmbedSrc,ka as measureFontSizeFromWidth,ft as measureText,JT as moveAllLeft,eD as moveAllRight,Ru as moveArrowAboveBindable,qT as moveOneLeft,QT as moveOneRight,Ue as mutateElement,wr as newArrowElement,Ai as newElement,Ke as newElementWith,bM as newEmbeddableElement,Fc as newFrameElement,PM as newFreeDrawElement,wM as newIframeElement,Hc as newImageElement,_c as newLinearElement,Rc as newMagicFrameElement,ai as newTextElement,wb as normalizeArrowhead,yE as normalizeBoundElementsOrder,Jc as normalizeElementOrder,He as normalizeFixedPoint,bD as normalizeSVG,Ki as normalizeText,ur as omitGroupsContainingFrameLikes,Oh as omitPartialGroups,lc as orderByFractionalIndex,Zi as originalContainerCache,hT as parseElementLinkFromURL,Cp as parseTokens,Yt as pointInsideBounds,vg as pointInsideBoundsInclusive,SD as positionElementsOnGrid,ls as projectFixedPointOntoDiagonal,ew as recognizeShape,Yo as redrawTextBoundingBox,yM as refreshTextDimensions,zh as removeAllElementsFromFrame,pc as removeElementsFromFrame,q1 as removeFromSelectedGroups,uS as renderElement,cS as renderSelectionElement,$c as rendersOpaqueFill,UI as replaceAllElementsInFrame,Vu as rescalePointsInElement,Wl as resetOriginalContainerCache,ib as resizeMultipleElements,eb as resizeSingleElement,qx as resizeSingleTextElement,sb as resizeTest,xh as selectGroup,Qd as selectGroupsForSelectedElements,Jd as selectGroupsFromGivenElements,H0 as setCustomTextMetricsProvider,aP as shouldAllowVerticalAlign,XI as shouldApplyFrameClip,Xo as shouldTestInside,lv as showSelectedShapeActions,Hs as snapToMid,lP as suppportsHorizontalAlign,Ks as syncInvalidIndices,dc as syncInvalidIndicesImmutable,ni as syncMovedIndices,Kd as toggleLinePolygonState,IP as toolIsArrow,FD as transformElements,Xe as unbindBindingElement,M1 as updateBindings,je as updateBoundElements,Ct as updateBoundPoint,bi as updateElbowArrowPoints,YI as updateFrameMembershipOfSelectedElements,ED as updateImageCache,Hl as updateOriginalContainerCache,wd as validateElbowPoints,Lh as validateFractionalIndices,Xt as vectorToHeading,sn as wrapText};
|