@excalidraw/element 0.18.0-4872083 → 0.18.0-4ce38fb
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 +5645 -3994
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +16 -15
- package/dist/types/common/src/colors.d.ts +13 -7
- package/dist/types/common/src/constants.d.ts +54 -0
- package/dist/types/common/src/keys.d.ts +2 -0
- package/dist/types/common/src/random.d.ts +7 -0
- package/dist/types/common/src/utils.d.ts +5 -0
- package/dist/types/element/src/Scene.d.ts +1 -1
- package/dist/types/element/src/binding.d.ts +13 -7
- package/dist/types/element/src/collision.d.ts +14 -5
- package/dist/types/element/src/comparisons.d.ts +5 -3
- package/dist/types/element/src/delta.d.ts +23 -1
- package/dist/types/element/src/duplicate.d.ts +60 -0
- package/dist/types/element/src/flowchart.d.ts +5 -1
- package/dist/types/element/src/frame.d.ts +2 -2
- package/dist/types/element/src/index.d.ts +2 -0
- package/dist/types/element/src/linearElementEditor.d.ts +10 -0
- package/dist/types/element/src/listMarker.d.ts +34 -0
- package/dist/types/element/src/mutateElement.d.ts +1 -1
- package/dist/types/element/src/newElement.d.ts +39 -3
- package/dist/types/element/src/renderElement.d.ts +21 -4
- package/dist/types/element/src/shape.d.ts +15 -1
- package/dist/types/element/src/sizeHelpers.d.ts +6 -0
- package/dist/types/element/src/stickyNote.d.ts +183 -0
- package/dist/types/element/src/textElement.d.ts +9 -1
- package/dist/types/element/src/transform.d.ts +25 -6
- package/dist/types/element/src/typeChecks.d.ts +3 -2
- package/dist/types/element/src/types.d.ts +35 -6
- package/dist/types/element/src/utils.d.ts +15 -4
- package/dist/types/element/src/zindex.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +60 -3
- package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +40 -2
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +140 -7
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +40 -2
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +61 -4
- package/dist/types/excalidraw/actions/actionDeselect.d.ts +23 -1
- package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -2
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +40 -2
- package/dist/types/excalidraw/actions/actionExport.d.ts +40 -2
- package/dist/types/excalidraw/actions/actionFinalize.d.ts +1 -0
- package/dist/types/excalidraw/actions/actionFrame.d.ts +111 -4
- package/dist/types/excalidraw/actions/actionGroup.d.ts +40 -2
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +71 -2
- package/dist/types/excalidraw/actions/actionLink.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionMenu.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionProperties.d.ts +50 -8
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionStyles.d.ts +21 -2
- package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionToggleShowHints.d.ts +197 -0
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +20 -1
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +20 -1
- package/dist/types/excalidraw/actions/colorTargets.d.ts +39 -0
- package/dist/types/excalidraw/actions/index.d.ts +1 -0
- package/dist/types/excalidraw/actions/types.d.ts +1 -1
- package/dist/types/excalidraw/appState.d.ts +23 -1
- package/dist/types/excalidraw/components/App.arrowText.d.ts +28 -30
- package/dist/types/excalidraw/components/App.bucketFill.d.ts +10 -0
- package/dist/types/excalidraw/components/App.clipboard.d.ts +31 -0
- package/dist/types/excalidraw/components/App.cursor.d.ts +8 -0
- package/dist/types/excalidraw/components/App.d.ts +110 -199
- package/dist/types/excalidraw/components/App.duplicate.d.ts +101 -0
- package/dist/types/excalidraw/components/App.pan.d.ts +62 -0
- package/dist/types/excalidraw/components/App.text.d.ts +146 -0
- package/dist/types/excalidraw/components/App.textTool.d.ts +140 -0
- package/dist/types/excalidraw/components/App.toolDrag.d.ts +63 -0
- package/dist/types/excalidraw/components/App.viewport.d.ts +41 -1
- package/dist/types/excalidraw/components/App.wheel.d.ts +26 -0
- package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +6 -2
- package/dist/types/excalidraw/components/ColorPicker/CustomColorList.d.ts +3 -1
- package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +4 -1
- package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +4 -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/colorTopPicksDnD.d.ts +11 -0
- package/dist/types/excalidraw/components/FileDropOverlay.d.ts +2 -0
- package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +4 -1
- package/dist/types/excalidraw/components/FontPicker/FontPickerList.d.ts +6 -1
- package/dist/types/excalidraw/components/FontPicker/fontTopPicksDnD.d.ts +12 -0
- package/dist/types/excalidraw/components/IconButton.d.ts +2 -0
- package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +6 -2
- package/dist/types/excalidraw/components/LibraryUnit.d.ts +7 -2
- package/dist/types/excalidraw/components/Tools.d.ts +7 -2
- package/dist/types/excalidraw/components/Tooltip.d.ts +15 -1
- package/dist/types/excalidraw/components/TopPicksDnD/TopPicksContextMenu.d.ts +14 -0
- package/dist/types/excalidraw/components/TopPicksDnD/TopPicksTip.d.ts +11 -0
- package/dist/types/excalidraw/components/TopPicksDnD/topPicksDnD.d.ts +58 -0
- package/dist/types/excalidraw/components/canvases/NewElementCanvas.d.ts +2 -0
- package/dist/types/excalidraw/components/icons.d.ts +2 -0
- package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -0
- package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +2 -2
- package/dist/types/excalidraw/data/blob.d.ts +40 -2
- package/dist/types/excalidraw/data/json.d.ts +20 -1
- package/dist/types/excalidraw/fonts/Fonts.d.ts +3 -2
- package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +5 -5
- package/dist/types/excalidraw/lasso/utils.d.ts +2 -0
- package/dist/types/excalidraw/renderOverrides.d.ts +9 -0
- package/dist/types/excalidraw/renderer/helpers.d.ts +25 -0
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +1 -1
- package/dist/types/excalidraw/scene/Renderer.d.ts +64 -2
- package/dist/types/excalidraw/scene/index.d.ts +1 -1
- package/dist/types/excalidraw/scene/types.d.ts +3 -1
- package/dist/types/excalidraw/types.d.ts +140 -18
- package/dist/types/excalidraw/viewport.d.ts +33 -1
- package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +12 -1
- package/dist/types/math/src/curve.d.ts +19 -12
- package/dist/types/math/src/segment.d.ts +6 -0
- package/dist/types/utils/src/export.d.ts +1 -0
- package/dist/types/utils/src/shape.d.ts +2 -2
- package/package.json +4 -4
package/dist/prod/index.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
var Ju=Object.create;var Ua=Object.defineProperty;var em=Object.getOwnPropertyDescriptor;var tm=Object.getOwnPropertyNames;var nm=Object.getPrototypeOf,im=Object.prototype.hasOwnProperty;var om=(e,t)=>()=>(e&&(t=e(e=0)),t);var rm=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var sm=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of tm(t))!im.call(e,o)&&o!==n&&Ua(e,o,{get:()=>t[o],enumerable:!(i=em(t,o))||i.enumerable});return e};var am=(e,t,n)=>(n=e!=null?Ju(nm(e)):{},sm(t||!e||!e.__esModule?Ua(n,"default",{value:e,enumerable:!0}):n,e));var N,I=om(()=>{N={PROD:!0}});var nu=rm((oA,tu)=>{I();var eu="Expected a function",Qc=NaN,bE="[object Symbol]",wE=/^\s+|\s+$/g,yE=/^[-+]0x[0-9a-f]+$/i,PE=/^0b[01]+$/i,IE=/^0o[0-7]+$/i,SE=parseInt,ME=typeof global=="object"&&global&&global.Object===Object&&global,AE=typeof self=="object"&&self&&self.Object===Object&&self,TE=ME||AE||Function("return this")(),DE=Object.prototype,vE=DE.toString,BE=Math.max,LE=Math.min,wa=function(){return TE.Date.now()};function CE(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(eu);t=Jc(t)||0,Mr(n)&&(c=!!n.leading,u="maxWait"in n,r=u?BE(Jc(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?LE(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=wa();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(wa())}function w(){var M=wa(),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 GE(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(eu);return Mr(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),CE(e,t,{leading:i,maxWait:t,trailing:o})}function Mr(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function kE(e){return!!e&&typeof e=="object"}function OE(e){return typeof e=="symbol"||kE(e)&&vE.call(e)==bE}function Jc(e){if(typeof e=="number")return e;if(OE(e))return Qc;if(Mr(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Mr(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(wE,"");var n=PE.test(e);return n||IE.test(e)?SE(e.slice(2),n?2:8):yE.test(e)?Qc:+e}tu.exports=GE});I();import{toIterable as Hb}from"@excalidraw/common";I();import{SHIFT_LOCKING_ANGLE as mn,viewportCoordsToSceneCoords as Er}from"@excalidraw/common";import{normalizeRadians as Ac,radiansBetweenAngles as fg,radiansDifference as hg}from"@excalidraw/math";import{pointsEqual as gg}from"@excalidraw/math";I();I();I();I();I();I();I();I();I();function zr(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 dm(e,t,n){let i=[];e.forEach(o=>i.push(...o)),zr(i,t,n)}function cm(e,t){return e[0]===t[0]&&e[1]===t[1]}function Ya(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)zr(d,a,o);let l=um(s,r,i);if(o){for(let d of s)zr(d,a,-o);dm(l,a,-o)}return l}function um(e,t,n){let i=[];for(let d of e){let c=[...d];cm(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),Ya(e,o,i,r||1)}var gn=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 En(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 po=class extends gn{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)En([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 fo=class extends gn{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 ho=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=En(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 go=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=En(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 Eo=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=En(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 Xa(e,t){let n=e.fillStyle||"hachure";if(!nt[n])switch(n){case"zigzag":nt[n]||(nt[n]=new po(t));break;case"cross-hatch":nt[n]||(nt[n]=new fo(t));break;case"dots":nt[n]||(nt[n]=new ho(t));break;case"dashed":nt[n]||(nt[n]=new go(t));break;case"zigzag-line":nt[n]||(nt[n]=new Eo(t));break;case"hachure":default:n="hachure",nt[n]||(nt[n]=new gn(t));break}return nt[n]}I();function ja(){return Math.floor(Math.random()*2**31)}var xo=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 bo={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function mm(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 _r(e,t){return e.type===t}function di(e){let t=[],n=mm(e),i="BOD",o=0,r=n[o];for(;!_r(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=bo[r.text],i=r.text;else return di("M0,0"+e);else _r(r,1)?s=bo[i]:(o++,s=bo[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(_r(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof bo[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)&&($a(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 $a(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=$a(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 fm={randOffset:Em,randOffsetWithRange:xm,ellipse:gm,doubleLineOps:bm};function Hr(e,t,n,i,o){return{type:"path",ops:Qt(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(...Qt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Qt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return Hr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function hm(e,t){return Ri(e,!0,t)}function Qa(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return hm(r,o)}function Wr(e,t){let n=Za(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=Za(e,1.5*(1+t.roughness*.22),wm(t));n=n.concat(i)}return{type:"path",ops:n}}function gm(e,t,n,i,o){let r=Ur(n,i,o);return Po(e,t,o,r).opset}function Ur(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=U(s*l,n),a+=U(a*l,n),{increment:r,rx:s,ry:a}}function Po(e,t,n,i){let[o,r]=Ka(i.increment,e,t,i.rx,i.ry,1,i.increment*wo(.1,wo(.4,1,n),n),n),s=yo(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=Ka(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=yo(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Yr(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+=U(u*.01,l),m+=U(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=qa(g,d,c,u,m,p,h,1,l);if(!l.disableMultiStroke){let x=qa(g,d,c,u,m,p,h,1.5,l);E.push(...x)}return s&&(a?E.push(...Qt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...Qt(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=Fi(Oi(di(e))),i=[],o=[0,0],r=[0,0];for(let{key:s,data:a}of n)switch(s){case"M":{r=[a[0],a[1]],o=[a[0],a[1]];break}case"L":i.push(...Qt(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,d,c,u,m,p]=a;i.push(...ym(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...Qt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function Io(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]+U(o,t),i[0][1]+U(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+U(o,t),i[s][1]+U(o,t)]})}}return{type:"fillPath",ops:n}}function Yn(e,t){return Xa(t,fm).fillPolygons(e,t)}function Ja(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=U(d*.01,s),c+=U(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]),Yn([h],s)}function Em(e,t){return U(e,t)}function xm(e,t,n){return wo(e,t,n)}function bm(e,t,n,i,o){return Qt(e,t,n,i,o,!0)}function wm(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function el(e){return e.randomizer||(e.randomizer=new xo(e.seed||0)),e.randomizer.next()}function wo(e,t,n,i=1){return n.roughness*i*(el(n)*(t-e)+e)}function U(e,t,n=1){return wo(-e,e,t,n)}function Qt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=Va(e,t,n,i,o,!0,!1);if(s)return a;let l=Va(e,t,n,i,o,!0,!0);return a.concat(l)}function Va(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+el(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,h=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=U(p,o,d),h=U(h,o,d);let f=[],g=()=>U(u,o,d),E=()=>U(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:U(c,o,d)),t+(x?0:U(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 Za(e,t,n){let i=[];i.push([e[0][0]+U(t,n),e[0][1]+U(t,n)]),i.push([e[0][0]+U(t,n),e[0][1]+U(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+U(t,n),e[o][1]+U(t,n)]),o===e.length-1&&i.push([e[o][0]+U(t,n),e[o][1]+U(t,n)]);return yo(i,null,n)}function yo(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]+U(a,n),t[1]+U(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...Qt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function Ka(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=U(.5,a)-Math.PI/2;c.push([U(r,a)+t+.9*i*Math.cos(u-e),U(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=[U(r,a)+t+i*Math.cos(p),U(r,a)+n+o*Math.sin(p)];d.push(h),c.push(h)}c.push([U(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),U(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([U(r,a)+t+.98*i*Math.cos(u+s),U(r,a)+n+.98*o*Math.sin(u+s)]),c.push([U(r,a)+t+.9*i*Math.cos(u+s*.5),U(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function qa(e,t,n,i,o,r,s,a,l){let d=r+U(.1,l),c=[];c.push([U(a,l)+t+.9*i*Math.cos(d-e),U(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([U(a,l)+t+i*Math.cos(u),U(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)]),yo(c,null,l)}function ym(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:U(d[0],a)),s[1]+(m?0:U(d[0],a))]}),c=m?[o,r]:[o+U(d[p],a),r+U(d[p],a)],l.push({op:"bcurveTo",data:[e+U(d[p],a),t+U(d[p],a),n+U(d[p],a),i+U(d[p],a),c[0],c[1]]});return l}I();function zi(e){return[...e]}function So(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 Pm(e,t){return Math.sqrt(Mo(e,t))}function Mo(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Im(e,t,n){let i=Mo(t,n);if(i===0)return Mo(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)),Mo(e,Xn(t,n,o))}function Xn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Sm(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 jr(e,t,n,i){let o=i||[];if(Sm(e,t)<n){let r=e[t+0];o.length?Pm(o[o.length-1],r)>1&&o.push(r):o.push(r),o.push(e[t+3])}else{let s=e[t+0],a=e[t+1],l=e[t+2],d=e[t+3],c=Xn(s,a,.5),u=Xn(a,l,.5),m=Xn(l,d,.5),p=Xn(c,u,.5),h=Xn(u,m,.5),f=Xn(p,h,.5);jr([s,c,p,f],0,n,o),jr([f,h,m,d],0,n,o)}return o}function xn(e,t){return Ao(e,0,e.length,t)}function Ao(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=Im(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(Ao(e,t,d+1,i,r),Ao(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;jr(e,s,t,i)}return n&&n>0?Ao(i,0,i.length,n):i}I();function tl(e,t,n){let i=di(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=xn(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 ja()}_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",[Hr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=Qa(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(Io([d],s)):a.push(Yn([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=Ur(i,o,s),d=Po(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Po(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(Yn([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=Yr(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=Yr(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(Ja(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=Wr(t,i);if(i.fill&&i.fill!==mt&&t.length>=3)if(i.fillStyle==="solid"){let s=Wr(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=So(t),a=It(s,10,(1+i.roughness)/2);o.push(Yn([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(Io([t],i)):o.push(Yn([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=tl(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(Io(d,i));else o.push(Yn(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 To=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 Do=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 ci={canvas(e,t){return new To(e,t)},svg(e,t){return new Do(e,t)},generator(e){return new bt(e)},newSeed(){return bt.newSeed()}};import{arrayToMap as Sc,invariant as sa,rescalePoints as bc,sizeOf as ig}from"@excalidraw/common";import{degreesToRadians as ra,lineSegment as Pe,pointFrom as O,pointFromArray as Mc,pointRotateRads as ae}from"@excalidraw/math";I();import{invariant as Mm}from"@excalidraw/common";import{curve as Am,lineSegment as Tm,pointFrom as Ee,pointDistance as My,pointFromArray as Dm,pointFromVector as vm,pointRotateRads as St,polygon as nl,polygonFromPoints as $r,PRECISION as Ay,segmentsIntersectAt as Ty,vector as Bm,vectorAdd as Lm,vectorFromPoint as Cm,vectorScale as Dy}from"@excalidraw/math";import{getElementAbsoluteCoords as By}from"@excalidraw/element";var il=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=nl(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=nl(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 ol=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}}},Jt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},rl=(e,t=Ee(0,0),n,i)=>{let o=l=>St(Ee(l[0]+t[0],l[1]+t[1]),i,n),r=Jt(e),s=[],a=Ee(0,0);for(let l of r){if(l.op==="move"){let d=Dm(l.data);Mm(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(Am(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Gm=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Tm(t,o)),t=o}return n},sl=(e,t,n=!1)=>{let i=r=>St(vm(Lm(Cm(r),Bm(e.x,e.y))),t,e.angle),o=Gm(e.points.map(r=>i(r)));return n?{type:"polygon",data:$r(o.flat())}:{type:"polyline",data:o}},al=(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:$r(e.points.map(c=>r(c)))};let s=Jt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(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:$r(d)}};I();I();function ll(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function km(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 Om(e,t){return[e[0]/t,e[1]/t]}function Hi(e){return[e[1],-e[0]]}function dl(e,t){return e[0]*t[0]+e[1]*t[1]}function Nm(e,t){return e[0]===t[0]&&e[1]===t[1]}function Fm(e){return Math.hypot(e[0],e[1])}function Rm(e){return e[0]*e[0]+e[1]*e[1]}function cl(e,t){return Rm(wt(e,t))}function pl(e){return Om(e,Fm(e))}function zm(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 Vr(e,t,n){return At(e,Mt(wt(t,e),n))}function ul(e,t,n){return At(e,Mt(t,n))}var{min:ui,PI:_m}=Math,ml=.275,Ui=_m+1e-4;function Hm(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=ui(1,P.distance/n),z=ui(1,1-C);v=ui(1,L+(z-L)*(C*ml))}return(L+v)/2},e[0].pressure),w=ll(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=ui(1,z/n),ie=ui(1,1-pe);P=ui(1,y+(ie-y)*(pe*ml))}w=ll(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?dl(C,ne):1,Ft=dl(C,S)<0&&!k,Rt=Ae!==null&&Ae<0;if(Ft||Rt){let pe=Mt(Hi(S),w);for(let ie=1/13,Le=0;Le<=1;Le+=ie)F=Wi(wt(v,pe),v,Ui*Le),x.push(F),B=Wi(At(v,pe),v,Ui*-Le),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 hn=Mt(Hi(Vr(ne,C,Ae)),w);F=wt(v,hn),(L<=1||cl(T,F)>E)&&(x.push(F),T=F),B=At(v,hn),(L<=1||cl(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=ul(G,pl(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(km(e[e.length-1].vector));if(g||f&&e.length===1)D.push(_);else if(m){let P=ul(_,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 Zr(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(Vr(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):Vr(u.point,a[p],s);if(Nm(u.point,h))continue;let f=zm(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:pl(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 fl(e,t={}){return Hm(Zr(e,t),t)}I();I();I();function xe([e,t,n],[i,o,r]){return[e+i,t+o,n+r]}function mi([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 $n([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 hl(e,t,n){return xe(e,Me(mi(t,e),n))}function Kr(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 Qr([e,t]){return Math.sqrt(e**2+t**2)}function jn([e,t],[n,i]){return Math.sqrt((n-e)**2+(i-t)**2)}function gl(e){if(e.length<2)return 0;let t=0;for(let n=1;n<=e.length-1;n++)t+=jn(e[n-1],e[n]);return t+=jn(e[e.length-2],e[e.length-1]),t}var Wm=(e,t,n)=>Math.max(t,Math.min(n,e));function El(e,t,n){let i=jn(t,n);if(i===0)return jn(e,t);let o=Wm(((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 jn(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=El(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 vo=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=hl(this.lastPoint,t,1-this.options.streamline)),this.tailPoints.push(t),gl(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=Kr(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=jn(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 _=$n(mi(T,A)),W=$n(mi(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(Qr(te)===0?_:$n(te),G)),Ft=xe(A,Me(Qr(ne)===0?W:$n(ne),G)),Rt=qr(Kr(A,T,F)),hn=e.constants.cornerDetectionMaxAngle/180*Math.PI*e.constants.cornerDetectionVariance(s);if(Math.abs(Rt)<hn){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=$n(mi(u,c)),f=$n(mi(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 uc,pointRotateRads as cn}from"@excalidraw/math";import{ROUGHNESS as Hh,THEME as ia,isTransparent as so,assertNever as Wh,COLOR_PALETTE as Uh,LINE_POLYGON_POINT_MERGE_DISTANCE as Yh,applyDarkModeFilter as ao,DEFAULT_STROKE_STREAMLINE as Xh}from"@excalidraw/common";I();import{isRightAngleRads as Dh,lineSegment as sc,pointFrom as cr,pointRotateRads as Js}from"@excalidraw/math";import{BOUND_TEXT_PADDING as On,DEFAULT_REDUCED_GLOBAL_ALPHA as vh,ELEMENT_READY_TO_ERASE_OPACITY as Bh,FRAME_STYLE as ur,DARK_THEME_FILTER as Lh,MIME_TYPES as ta,THEME as Mi,distance as Nn,getFontString as Ch,isRTL as Gh,getVerticalOffset as kh,invariant as Oh,applyDarkModeFilter as pr,isSafari as Nh}from"@excalidraw/common";I();import{pointFrom as en,pointCenter as Ym,pointRotateRads as bn,vectorFromPoint as Jr,vectorNormalize as xl,vectorSubtract as bl,vectorAdd as Bo,vectorScale as Lo,pointFromVector as wl,clamp as Re,isCloseTo as yl}from"@excalidraw/math";var ze=10,$y=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=es(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,h=bn(en(r,s),re(e,t),-e.angle);r=h[0],s=h[1];let f=e.width,g=e.height,E=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=E.height,b=E.width,y=e.scale[0]===-1,w=e.scale[1]===-1,M=s-e.y,S=r-e.x;n.includes("n")&&(g=Re(e.height-M,ze,w?d-p:e.height+p)),n.includes("s")&&(M=s-e.y-e.height,g=Re(e.height+M,ze,w?e.height+p:d-p)),n.includes("e")&&(S=r-e.x-e.width,f=Re(e.width+S,ze,y?e.width+m:l-m)),n.includes("w")&&(f=Re(e.width-S,ze,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=Re(g*a,ze,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=Re(g*a,ze,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=Re(f/a,ze,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=Re(f/a,ze,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=Re(f/a,ze,B),f=g*a}else{let B=y?m+e.width:l-m;f=Re(g*a,ze,B),g=f/a}A(n,E);break}case"nw":{if(a)if(S<M){let B=w?d-p:p+e.height;g=Re(f/a,ze,B),f=g*a}else{let B=y?l-m:m+e.width;f=Re(g*a,ze,B),g=f/a}A(n,E);break}case"se":{if(a)if(S>M){let B=w?p+e.height:d-p;g=Re(f/a,ze,B),f=g*a}else{let B=y?m+e.width:l-m;f=Re(g*a,ze,B),g=f/a}A(n,E);break}case"sw":{if(a)if(-S>M){let B=w?p+e.height:d-p;g=Re(f/a,ze,B),f=g*a}else{let B=y?l-m:m+e.width;f=Re(g*a,ze,B),g=f/a}A(n,E);break}default:break}let F=Xm(e,n,f,g,!!a);return yl(E.width,E.naturalWidth)&&yl(E.height,E.naturalHeight)&&(E=null),{x:F[0],y:F[1],width:f,height:g,crop:E}},Xm=(e,t,n,i,o)=>{let[r,s,a,l]=wn(e,e.width,e.height,!0),d=en(r,s),c=en(a,l),u=Ym(d,c),[m,p,h,f]=wn(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=bn(x,u,b),w=[x[0]+Math.abs(g)/2,x[1]+Math.abs(E)/2],M=bn(w,u,b);x=bn(y,M,-b);let S=[...x];return S[0]+=e.x-m,S[1]+=e.y-p,S},Pl=(e,t)=>{if(e.crop){let{width:n,height:i}=es(e),[o,r,s,a,l,d]=Z(e,t),c=Jr(bn(en(o,r),en(l,d),e.angle)),u=Jr(bn(en(s,r),en(l,d),e.angle)),m=xl(bl(u,c)),p=Jr(bn(en(o,a),en(l,d),e.angle)),h=bl(p,c),f=xl(h),{cropX:g,cropY:E}=jm(e.crop,e.scale),x=Bo(Bo(c,Lo(m,-g*n/e.crop.naturalWidth)),Lo(f,-E*i/e.crop.naturalHeight)),b=wl(Bo(Bo(x,Lo(m,n/2)),Lo(f,i/2))),y=bn(wl(x),b,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},es=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}},jm=(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}},Vy=(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}=es(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};I();import{pointCenter as Cd,pointFrom as H,pointRotateRads as qe,pointsEqual as Gd,pointDistance as ti,vectorFromPoint as Zf,curveLength as Kf,curvePointAtLength as qf}from"@excalidraw/math";import{DRAGGING_THRESHOLD as Qf,KEYS as Jn,shouldRotateWithDiscreteAngle as ei,getGridPoint as kd,invariant as dt,isShallowEqual as Jf,getFeatureFlag as Pi}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as Od,getSnapOutlineMidPoint as Nd,isPathALoop as eh,moveArrowAboveBindable as Fd,projectFixedPointOntoDiagonal as Rd}from"@excalidraw/element";I();import{arrayToMap as Sd,getFeatureFlag as Tf,getGridPoint as Rs,invariant as dn,isTransparent as Df}from"@excalidraw/common";import{PRECISION as vf,clamp as ir,lineSegment as bi,pointDistance as Tn,pointDistanceSq as xt,pointFrom as q,pointFromArray as Bf,pointFromVector as tr,pointRotateRads as ge,pointsEqual as Lf,vectorFromPoint as wi,vectorNormalize as Fs,vectorScale as nr}from"@excalidraw/math";I();import{invariant as Ql,isTransparent as Jl}from"@excalidraw/common";import{curveIntersectLineSegment as ed,isPointWithinBounds as ys,lineSegment as Qi,lineSegmentIntersectionPoints as td,pointFrom as De,pointFromVector as Xp,pointRotateRads as ht,pointsEqual as nd,vectorFromPoint as jp,vectorNormalize as $p,vectorScale as Vp}from"@excalidraw/math";import{ellipse as Zp,ellipseSegmentInterceptPoints as Kp}from"@excalidraw/math/ellipse";I();import{DEFAULT_ADAPTIVE_RADIUS as ep,DEFAULT_PROPORTIONAL_RADIUS as ns,invariant as tp,LINE_CONFIRM_THRESHOLD as np,ROUNDNESS as is}from"@excalidraw/common";import{bezierEquation as ip,curve as tn,curveCatmullRomCubicApproxPoints as Gl,curveOffsetPoints as kl,lineSegment as Ce,lineSegmentIntersectionPoints as Ll,pointDistance as Zn,pointFrom as Y,pointFromArray as op,pointFromVector as rp,pointRotateRads as pt,pointTranslate as Cl,rectangle as sp,vectorFromPoint as Ol,vectorNormalize as ap,vectorScale as os}from"@excalidraw/math";I();import{ROUNDNESS as Xi,assertNever as $m}from"@excalidraw/common";import{pointsEqual as Il}from"@excalidraw/math";var Vn=e=>!!e&&e.type==="image"&&!!e.fileId,ke=e=>!!e&&e.type==="image",Sl=e=>!!e&&e.type==="embeddable",Co=e=>!!e&&e.type==="iframe",Go=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),oe=e=>e!=null&&e.type==="text",ko=e=>e!=null&&e.type==="frame",Ml=e=>e!=null&&e.type==="magicframe",J=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),be=e=>e!=null&&Vm(e.type),Vm=e=>e==="freedraw",K=e=>e!=null&&qm(e.type),Oe=e=>e!=null&&e.type==="line",X=e=>e!=null&&e.type==="arrow",j=e=>X(e)&&e.elbowed,Jy=e=>X(e)&&!e.elbowed,Zm=e=>X(e)&&!e.elbowed&&!e.roundness,Km=e=>X(e)&&!e.elbowed&&e.roundness!==null,qm=e=>e==="arrow"||e==="line",_e=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&Qm(e.type),Qm=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),Al=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"),Jm=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||X(e)),Tl=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 $m(t,null),!1}},Dl=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",_t=e=>Jm(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),Ie=e=>e!==null&&"containerId"in e&&e.containerId!==null&&oe(e),e0=e=>!!e.startBinding||!!e.endBinding,Oo=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",vl=e=>e==="line"||e==="arrow"||e==="diamond",t0=(e,t)=>!!((e===Xi.ADAPTIVE_RADIUS||e===Xi.LEGACY)&&Oo(t.type)||e===Xi.PROPORTIONAL_RADIUS&&vl(t.type)),n0=e=>vl(e.type)?{type:Xi.PROPORTIONAL_RADIUS}:Oo(e.type)?{type:Xi.ADAPTIVE_RADIUS}:null,i0=e=>Zm(e)?"sharpArrow":Km(e)?"curvedArrow":j(e)?"elbowArrow":"line",ts=e=>e.length>3&&Il(e[0],e[e.length-1]),Bl=e=>e.length>3||e.length===3&&!Il(e[0],e[e.length-1]),o0=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,rs=(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)},ss=(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 No(e,t){let n=rs(e,0);if(n)return n;let i=Fl(e,t),o=[],r=[];for(let a=0;a<i.length;a+=1){let l=i[a],d=i[a-1]&&op(i[a-1].data.slice(-2));switch(l.op){case"move":continue;case"lineTo":if(!d)throw new Error("prevPoint is undefined");o.push(Ce(Y(e.x+d[0],e.y+d[1]),Y(e.x+l.data[0],e.y+l.data[1])));continue;case"bcurveTo":if(!d)throw new Error("prevPoint is undefined");r.push(tn(Y(e.x+d[0],e.y+d[1]),Y(e.x+l.data[0],e.y+l.data[1]),Y(e.x+l.data[2],e.y+l.data[3]),Y(e.x+l.data[4],e.y+l.data[5])));continue;default:console.error("Unknown op type",l.op)}}let s=[o,r];return ss(e,s,0),s}function yn(e,t=0){let n=rs(e,t);if(n)return n;let i=nn(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=sp(Y(e.x,e.y),Y(e.x+e.width,e.y+e.height)),r=Ce(Y(o[0][0]+i,o[0][1]),Y(o[1][0]-i,o[0][1])),s=Ce(Y(o[1][0],o[0][1]+i),Y(o[1][0],o[1][1]-i)),a=Ce(Y(o[0][0]+i,o[1][1]),Y(o[1][0]-i,o[1][1])),l=Ce(Y(o[0][0],o[1][1]-i),Y(o[0][0],o[0][1]+i)),d=[tn(l[1],Y(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),Y(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),tn(r[1],Y(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),Y(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),tn(s[1],Y(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),Y(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),tn(a[0],Y(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),Y(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],c=t>0?d.map(p=>Gl(kl(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[Ce(c[0][c[0].length-1][3],c[1][0][0]),Ce(c[1][c[1].length-1][3],c[2][0][0]),Ce(c[2][c[2].length-1][3],c[3][0][0]),Ce(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return ss(e,m,t),m}function Nl(e,t=0){let[n,i,o,r,s,a,l,d]=pi(e),c=e.roundness?nn(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?nn(Math.abs(r-i),e):(r-i)*.01,[m,p,h,f]=[Y(e.x+n,e.y+i),Y(e.x+o,e.y+r),Y(e.x+s,e.y+a),Y(e.x+l,e.y+d)];return[tn(Y(p[0]-c,p[1]-u),p,p,Y(p[0]-c,p[1]+u)),tn(Y(h[0]+c,h[1]-u),h,h,Y(h[0]-c,h[1]-u)),tn(Y(f[0]+c,f[1]+u),f,f,Y(f[0]+c,f[1]-u)),tn(Y(m[0]-c,m[1]+u),m,m,Y(m[0]+c,m[1]+u))]}function Pn(e,t=0){let n=rs(e,t);if(n)return n;let i=Nl(e,t),o=t>0?i.map(a=>Gl(kl(a,t))):[[i[0]],[i[1]],[i[2]],[i[3]]],s=[[Ce(o[0][o[0].length-1][3],o[1][0][0]),Ce(o[1][o[1].length-1][3],o[2][0][0]),Ce(o[2][o[2].length-1][3],o[3][0][0]),Ce(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return ss(e,s,t),s}var Tt=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return Zn(n,i)<=np/t}return!1},nn=(e,t)=>{if(t.roundness?.type===is.PROPORTIONAL_RADIUS||t.roundness?.type===is.LEGACY)return e*ns;if(t.roundness?.type===is.ADAPTIVE_RADIUS){let n=t.roundness?.value??ep,i=n/ns;return e<=i?e*ns:n}return 0},lp=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=ap(Ol(a[1],a[0])),d=os(l,n);return Ce(Cl(a[0],d),Cl(a[1],os(d,-1)))},o=re(e,t),r=i(ji(e)?Ce(pt(Y(e.x,e.y),o,e.angle),pt(Y(e.x+e.width,e.y+e.height),o,e.angle)):Ce(pt(Y(e.x+e.width/2,e.y),o,e.angle),pt(Y(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(ji(e)?Ce(pt(Y(e.x+e.width,e.y),o,e.angle),pt(Y(e.x,e.y+e.height),o,e.angle)):Ce(pt(Y(e.x,e.y+e.height/2),o,e.angle),pt(Y(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},dp=(e,t,n,i)=>{let o=re(t,n);return(t.type==="diamond"?Nl(t).map(a=>{let l=ip(a,.5),d=pt(l,o,t.angle);return Y(d[0],d[1])}):[pt(Y(t.x+t.width,t.y+t.height/2),o,t.angle),pt(Y(t.x+t.width/2,t.y+t.height),o,t.angle),pt(Y(t.x,t.y+t.height/2),o,t.angle),pt(Y(t.x+t.width/2,t.y),o,t.angle)]).find(a=>Zn(e,a)<=Dt(i)+t.strokeWidth/2&&!Ht({point:e,element:t,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))},as=(e,t,n,i,o,r,s=!0)=>{if(tp(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;if(s){let E=dp(t,n,o,r);if(E)return E}let[a,l]=lp(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&&He(We(E.fixedPoint),x,o);b&&(d=b)}let c=rp(os(Ol(t,d),2*Zn(d,t)+Math.max(Zn(a[0],a[1]),Zn(l[0],l[1]))),d),u=Ce(c,d),m=Ll(a,u),p=Ll(l,u),h=m&&Zn(d,m),f=p&&Zn(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 Cp,ARROW_LABEL_WIDTH_FRACTION as Gp,BOUND_TEXT_PADDING as Wt,DEFAULT_FONT_SIZE as kp,TEXT_ALIGN as Yl,VERTICAL_ALIGN as Xl,getFontString as Wo,isProdEnv as Op,invariant as Np}from"@excalidraw/common";import{pointFrom as jl,pointRotateRads as Fp}from"@excalidraw/math";I();var Vi={},Rl=(e,t)=>{let n=Vi[e]||(Vi[e]={height:t});return n.height=t,n},zl=e=>{Vi[e]&&delete Vi[e]},x0=e=>Vi[e]?.height??null;I();import{BOUND_TEXT_PADDING as Ro,DEFAULT_FONT_SIZE as cp,DEFAULT_FONT_FAMILY as up,getFontString as mp,isTestEnv as pp,normalizeEOL as fp}from"@excalidraw/common";var ft=(e,t,n)=>{let i=e.split(`
|
|
1
|
+
var Ep=Object.create;var Sl=Object.defineProperty;var xp=Object.getOwnPropertyDescriptor;var bp=Object.getOwnPropertyNames;var yp=Object.getPrototypeOf,wp=Object.prototype.hasOwnProperty;var Pp=(e,t)=>()=>(e&&(t=e(e=0)),t);var Sp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ip=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of bp(t))!wp.call(e,o)&&o!==n&&Sl(e,o,{get:()=>t[o],enumerable:!(i=xp(t,o))||i.enumerable});return e};var Mp=(e,t,n)=>(n=e!=null?Ep(yp(e)):{},Ip(t||!e||!e.__esModule?Sl(n,"default",{value:e,enumerable:!0}):n,e));var G,M=Pp(()=>{G={PROD:!0}});var fm=Sp((HD,pm)=>{M();var mm="Expected a function",cm=NaN,Pb="[object Symbol]",Sb=/^\s+|\s+$/g,Ib=/^[-+]0x[0-9a-f]+$/i,Mb=/^0b[01]+$/i,Tb=/^0o[0-7]+$/i,Ab=parseInt,Db=typeof global=="object"&&global&&global.Object===Object&&global,vb=typeof self=="object"&&self&&self.Object===Object&&self,Lb=Db||vb||Function("return this")(),Bb=Object.prototype,kb=Bb.toString,Cb=Math.max,Nb=Math.min,Qa=function(){return Lb.Date.now()};function Ob(e,t,n){var i,o,r,s,a,l,d=0,c=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(mm);t=um(t)||0,Fr(n)&&(c=!!n.leading,u="maxWait"in n,r=u?Cb(um(n.maxWait)||0,t):r,p="trailing"in n?!!n.trailing:p);function m(S){var I=i,A=o;return i=o=void 0,d=S,s=e.apply(A,I),s}function h(S){return d=S,a=setTimeout(E,t),c?m(S):s}function f(S){var I=S-l,A=S-d,T=t-I;return u?Nb(T,r-A):T}function g(S){var I=S-l,A=S-d;return l===void 0||I>=t||I<0||u&&A>=r}function E(){var S=Qa();if(g(S))return x(S);a=setTimeout(E,f(S))}function x(S){return a=void 0,p&&i?m(S):(i=o=void 0,s)}function b(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function y(){return a===void 0?s:x(Qa())}function w(){var S=Qa(),I=g(S);if(i=arguments,o=this,l=S,I){if(a===void 0)return h(l);if(u)return a=setTimeout(E,t),m(l)}return a===void 0&&(a=setTimeout(E,t)),s}return w.cancel=b,w.flush=y,w}function Gb(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(mm);return Fr(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),Ob(e,t,{leading:i,maxWait:t,trailing:o})}function Fr(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Fb(e){return!!e&&typeof e=="object"}function Rb(e){return typeof e=="symbol"||Fb(e)&&kb.call(e)==Pb}function um(e){if(typeof e=="number")return e;if(Rb(e))return cm;if(Fr(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Fr(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Sb,"");var n=Mb.test(e);return n||Tb.test(e)?Ab(e.slice(2),n?2:8):Ib.test(e)?cm:+e}pm.exports=Gb});M();import{toIterable as Jw}from"@excalidraw/common";M();import{SHIFT_LOCKING_ANGLE as fn,viewportCoordsToSceneCoords as vr}from"@excalidraw/common";import{normalizeRadians as Lu,radiansBetweenAngles as xx,radiansDifference as bx}from"@excalidraw/math";import{pointsEqual as yx}from"@excalidraw/math";M();M();M();M();M();M();M();M();M();function qr(e,t,n){if(e&&e.length){let[i,o]=t,r=Math.PI/180*n,s=Math.cos(r),a=Math.sin(r);for(let l of e){let[d,c]=l;l[0]=(d-i)*s-(c-o)*a+i,l[1]=(d-i)*a+(c-o)*s+o}}}function Ap(e,t,n){let i=[];e.forEach(o=>i.push(...o)),qr(i,t,n)}function Dp(e,t){return e[0]===t[0]&&e[1]===t[1]}function Il(e,t,n,i=1){let o=n,r=Math.max(t,.1),s=e[0]&&e[0][0]&&typeof e[0][0]=="number"?[e]:e,a=[0,0];if(o)for(let d of s)qr(d,a,o);let l=vp(s,r,i);if(o){for(let d of s)qr(d,a,-o);Ap(l,a,-o)}return l}function vp(e,t,n){let i=[];for(let d of e){let c=[...d];Dp(c[0],c[c.length-1])||c.push([c[0][0],c[0][1]]),c.length>2&&i.push(c)}let o=[];t=Math.max(t,.1);let r=[];for(let d of i)for(let c=0;c<d.length-1;c++){let u=d[c],p=d[c+1];if(u[1]!==p[1]){let m=Math.min(u[1],p[1]);r.push({ymin:m,ymax:Math.max(u[1],p[1]),x:m===u[1]?u[0]:p[0],islope:(p[0]-u[0])/(p[1]-u[1])})}}if(r.sort((d,c)=>d.ymin<c.ymin?-1:d.ymin>c.ymin?1:d.x<c.x?-1:d.x>c.x?1:d.ymax===c.ymax?0:(d.ymax-c.ymax)/Math.abs(d.ymax-c.ymax)),!r.length)return o;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let d=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)d=u;r.splice(0,d+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(d=>!(d.edge.ymax<=a)),s.sort((d,c)=>d.edge.x===c.edge.x?0:(d.edge.x-c.edge.x)/Math.abs(d.edge.x-c.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let d=0;d<s.length;d=d+2){let c=d+1;if(c>=s.length)break;let u=s[d].edge,p=s[c].edge;o.push([[Math.round(u.x),a],[Math.round(p.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.edge.islope}),l++}return o}function Ut(e,t){var n;let i=t.hachureAngle+90,o=t.hachureGap;o<0&&(o=t.strokeWidth*4),o=Math.max(o,.1);let r=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(r=o),Il(e,o,i,r||1)}var yn=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=Ut(t,n);return{type:"fillSketch",ops:this.renderLines(i,n)}}renderLines(t,n){let i=[];for(let o of t)i.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return i}};M();M();function wn(e){let t=e[0],n=e[1];return Math.sqrt(Math.pow(t[0]-n[0],2)+Math.pow(t[1]-n[1],2))}var Ao=class extends yn{fillPolygons(t,n){let i=n.hachureGap;i<0&&(i=n.strokeWidth*4),i=Math.max(i,.1);let o=Object.assign({},n,{hachureGap:i}),r=Ut(t,o),s=Math.PI/180*n.hachureAngle,a=[],l=i*.5*Math.cos(s),d=i*.5*Math.sin(s);for(let[u,p]of r)wn([u,p])&&a.push([[u[0]-l,u[1]+d],[...p]],[[u[0]+l,u[1]-d],[...p]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};M();var Do=class extends yn{fillPolygons(t,n){let i=this._fillPolygons(t,n),o=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),r=this._fillPolygons(t,o);return i.ops=i.ops.concat(r.ops),i}};M();var vo=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=Ut(t,n);return this.dotsOnLines(i,n)}dotsOnLines(t,n){let i=[],o=n.hachureGap;o<0&&(o=n.strokeWidth*4),o=Math.max(o,.1);let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let s=o/4;for(let a of t){let l=wn(a),d=l/o,c=Math.ceil(d)-1,u=l-c*o,p=(a[0][0]+a[1][0])/2-o/4,m=Math.min(a[0][1],a[1][1]);for(let h=0;h<c;h++){let f=m+u+h*o,g=p-s+Math.random()*2*s,E=f-s+Math.random()*2*s,x=this.helper.ellipse(g,E,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};M();var Lo=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=Ut(t,n);return{type:"fillSketch",ops:this.dashedLine(i,n)}}dashedLine(t,n){let i=n.dashOffset<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashOffset,o=n.dashGap<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashGap,r=[];return t.forEach(s=>{let a=wn(s),l=Math.floor(a/(i+o)),d=(a+o-l*(i+o))/2,c=s[0],u=s[1];c[0]>u[0]&&(c=s[1],u=s[0]);let p=Math.atan((u[1]-c[1])/(u[0]-c[0]));for(let m=0;m<l;m++){let h=m*(i+o),f=h+i,g=[c[0]+h*Math.cos(p)+d*Math.cos(p),c[1]+h*Math.sin(p)+d*Math.sin(p)],E=[c[0]+f*Math.cos(p)+d*Math.cos(p),c[1]+f*Math.sin(p)+d*Math.sin(p)];r.push(...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],n))}}),r}};M();var Bo=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,o=n.zigzagOffset<0?i:n.zigzagOffset;n=Object.assign({},n,{hachureGap:i+o});let r=Ut(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=wn(r),a=Math.round(s/(2*n)),l=r[0],d=r[1];l[0]>d[0]&&(l=r[1],d=r[0]);let c=Math.atan((d[1]-l[1])/(d[0]-l[0]));for(let u=0;u<a;u++){let p=u*2*n,m=(u+1)*2*n,h=Math.sqrt(2*Math.pow(n,2)),f=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],g=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],E=[f[0]+h*Math.cos(c+Math.PI/4),f[1]+h*Math.sin(c+Math.PI/4)];o.push(...this.helper.doubleLineOps(f[0],f[1],E[0],E[1],i),...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],i))}}),o}};var at={};function Ml(e,t){let n=e.fillStyle||"hachure";if(!at[n])switch(n){case"zigzag":at[n]||(at[n]=new Ao(t));break;case"cross-hatch":at[n]||(at[n]=new Do(t));break;case"dots":at[n]||(at[n]=new vo(t));break;case"dashed":at[n]||(at[n]=new Lo(t));break;case"zigzag-line":at[n]||(at[n]=new Bo(t));break;case"hachure":default:n="hachure",at[n]||(at[n]=new yn(t));break}return at[n]}M();function Tl(){return Math.floor(Math.random()*2**31)}var ko=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};M();M();var Co={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Lp(e){let t=new Array;for(;e!=="";)if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([aAcChHlLmMqQsStTvVzZ])/))t[t.length]={type:0,text:RegExp.$1},e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))t[t.length]={type:1,text:`${parseFloat(RegExp.$1)}`},e=e.substr(RegExp.$1.length);else return[];return t[t.length]={type:2,text:""},t}function Qr(e,t){return e.type===t}function Ei(e){let t=[],n=Lp(e),i="BOD",o=0,r=n[o];for(;!Qr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=Co[r.text],i=r.text;else return Ei("M0,0"+e);else Qr(r,1)?s=Co[i]:(o++,s=Co[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(Qr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof Co[i]=="number"){let l={key:i,data:a};t.push(l),o+=s,r=n[o],i==="M"&&(i="L"),i==="m"&&(i="l")}else throw new Error("Bad segment: "+i)}else throw new Error("Path data ended short")}return t}M();function Yi(e){let t=0,n=0,i=0,o=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[i,o]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),i=t,o=n;break;case"L":r.push({key:"L",data:[...a]}),[t,n]=a;break;case"l":t+=a[0],n+=a[1],r.push({key:"L",data:[t,n]});break;case"C":r.push({key:"C",data:[...a]}),t=a[4],n=a[5];break;case"c":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":r.push({key:"Q",data:[...a]}),t=a[2],n=a[3];break;case"q":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":r.push({key:"A",data:[...a]}),t=a[5],n=a[6];break;case"a":t+=a[5],n+=a[6],r.push({key:"A",data:[a[0],a[1],a[2],a[3],a[4],t,n]});break;case"H":r.push({key:"H",data:[...a]}),t=a[0];break;case"h":t+=a[0],r.push({key:"H",data:[t]});break;case"V":r.push({key:"V",data:[...a]}),n=a[0];break;case"v":n+=a[0],r.push({key:"V",data:[n]});break;case"S":r.push({key:"S",data:[...a]}),t=a[2],n=a[3];break;case"s":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=i,n=o;break}return r}M();function $i(e){let t=[],n="",i=0,o=0,r=0,s=0,a=0,l=0;for(let{key:d,data:c}of e){switch(d){case"M":t.push({key:"M",data:[...c]}),[i,o]=c,[r,s]=c;break;case"C":t.push({key:"C",data:[...c]}),i=c[4],o=c[5],a=c[2],l=c[3];break;case"L":t.push({key:"L",data:[...c]}),[i,o]=c;break;case"H":i=c[0],t.push({key:"L",data:[i,o]});break;case"V":o=c[0],t.push({key:"L",data:[i,o]});break;case"S":{let u=0,p=0;n==="C"||n==="S"?(u=i+(i-a),p=o+(o-l)):(u=i,p=o),t.push({key:"C",data:[u,p,...c]}),a=c[0],l=c[1],i=c[2],o=c[3];break}case"T":{let[u,p]=c,m=0,h=0;n==="Q"||n==="T"?(m=i+(i-a),h=o+(o-l)):(m=i,h=o);let f=i+2*(m-i)/3,g=o+2*(h-o)/3,E=u+2*(m-u)/3,x=p+2*(h-p)/3;t.push({key:"C",data:[f,g,E,x,u,p]}),a=m,l=h,i=u,o=p;break}case"Q":{let[u,p,m,h]=c,f=i+2*(u-i)/3,g=o+2*(p-o)/3,E=m+2*(u-m)/3,x=h+2*(p-h)/3;t.push({key:"C",data:[f,g,E,x,m,h]}),a=u,l=p,i=m,o=h;break}case"A":{let u=Math.abs(c[0]),p=Math.abs(c[1]),m=c[2],h=c[3],f=c[4],g=c[5],E=c[6];u===0||p===0?(t.push({key:"C",data:[i,o,g,E,g,E]}),i=g,o=E):(i!==g||o!==E)&&(Al(i,o,g,E,u,p,m,h,f).forEach(function(b){t.push({key:"C",data:b})}),i=g,o=E);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function Bp(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 Al(e,t,n,i,o,r,s,a,l,d){let c=Bp(s),u=[],p=0,m=0,h=0,f=0;if(d)[p,m,h,f]=d;else{[e,t]=Xi(e,t,-c),[n,i]=Xi(n,i,-c);let N=(e-n)/2,C=(t-i)/2,z=N*N/(o*o)+C*C/(r*r);z>1&&(z=Math.sqrt(z),o=z*o,r=z*r);let U=a===l?-1:1,D=o*o,L=r*r,P=D*L-D*C*C-L*N*N,B=D*C*C+L*N*N,k=U*Math.sqrt(Math.abs(P/B));h=k*o*C/r+(e+n)/2,f=k*-r*N/o+(t+i)/2,p=Math.asin(parseFloat(((t-f)/r).toFixed(9))),m=Math.asin(parseFloat(((i-f)/r).toFixed(9))),e<h&&(p=Math.PI-p),n<h&&(m=Math.PI-m),p<0&&(p=Math.PI*2+p),m<0&&(m=Math.PI*2+m),l&&p>m&&(p=p-Math.PI*2),!l&&m>p&&(m=m-Math.PI*2)}let g=m-p;if(Math.abs(g)>Math.PI*120/180){let N=m,C=n,z=i;l&&m>p?m=p+Math.PI*120/180*1:m=p+Math.PI*120/180*-1,n=h+o*Math.cos(m),i=f+r*Math.sin(m),u=Al(n,i,C,z,o,r,s,0,l,[m,N,h,f])}g=m-p;let E=Math.cos(p),x=Math.sin(p),b=Math.cos(m),y=Math.sin(m),w=Math.tan(g/4),S=4/3*o*w,I=4/3*r*w,A=[e,t],T=[e+S*x,t-I*E],O=[n+S*y,i-I*b],v=[n,i];if(T[0]=2*A[0]-T[0],T[1]=2*A[1]-T[1],d)return[T,O,v].concat(u);{u=[T,O,v].concat(u);let N=[];for(let C=0;C<u.length;C+=3){let z=Xi(u[C][0],u[C][1],c),U=Xi(u[C+1][0],u[C+1][1],c),D=Xi(u[C+2][0],u[C+2][1],c);N.push([z[0],z[1],U[0],U[1],D[0],D[1]])}return N}}var kp={randOffset:Op,randOffsetWithRange:Gp,ellipse:Np,doubleLineOps:Fp};function Jr(e,t,n,i,o){return{type:"path",ops:Qt(e,t,n,i,o)}}function ji(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Qt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Qt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return Jr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Cp(e,t){return ji(e,!0,t)}function kl(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Cp(r,o)}function es(e,t){let n=vl(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=vl(e,1.5*(1+t.roughness*.22),Rp(t));n=n.concat(i)}return{type:"path",ops:n}}function Np(e,t,n,i,o){let r=ts(n,i,o);return Go(e,t,o,r).opset}function ts(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=$(s*l,n),a+=$(a*l,n),{increment:r,rx:s,ry:a}}function Go(e,t,n,i){let[o,r]=Ll(i.increment,e,t,i.rx,i.ry,1,i.increment*No(.1,No(.4,1,n),n),n),s=Oo(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=Ll(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Oo(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function ns(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),p=Math.abs(i/2);u+=$(u*.01,l),p+=$(p*.01,l);let m=o,h=r;for(;m<0;)m+=Math.PI*2,h+=Math.PI*2;h-m>Math.PI*2&&(m=0,h=Math.PI*2);let f=Math.PI*2/l.curveStepCount,g=Math.min(f/2,(h-m)/2),E=Bl(g,d,c,u,p,m,h,1,l);if(!l.disableMultiStroke){let x=Bl(g,d,c,u,p,m,h,1.5,l);E.push(...x)}return s&&(a?E.push(...Qt(d,c,d+u*Math.cos(m),c+p*Math.sin(m),l),...Qt(d,c,d+u*Math.cos(h),c+p*Math.sin(h),l)):E.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(m),c+p*Math.sin(m)]})),{type:"path",ops:E}}function is(e,t){let n=$i(Yi(Ei(e))),i=[],o=[0,0],r=[0,0];for(let{key:s,data:a}of n)switch(s){case"M":{r=[a[0],a[1]],o=[a[0],a[1]];break}case"L":i.push(...Qt(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,d,c,u,p,m]=a;i.push(...zp(l,d,c,u,p,m,r,t)),r=[p,m];break}case"Z":i.push(...Qt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function Fo(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+$(o,t),i[0][1]+$(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+$(o,t),i[s][1]+$(o,t)]})}}return{type:"fillPath",ops:n}}function Zn(e,t){return Ml(t,kp).fillPolygons(e,t)}function Cl(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=$(d*.01,s),c+=$(c*.01,s);let u=o,p=r;for(;u<0;)u+=Math.PI*2,p+=Math.PI*2;p-u>Math.PI*2&&(u=0,p=Math.PI*2);let m=(p-u)/s.curveStepCount,h=[];for(let f=u;f<=p;f=f+m)h.push([a+d*Math.cos(f),l+c*Math.sin(f)]);return h.push([a+d*Math.cos(p),l+c*Math.sin(p)]),h.push([a,l]),Zn([h],s)}function Op(e,t){return $(e,t)}function Gp(e,t,n){return No(e,t,n)}function Fp(e,t,n,i,o){return Qt(e,t,n,i,o,!0)}function Rp(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Nl(e){return e.randomizer||(e.randomizer=new ko(e.seed||0)),e.randomizer.next()}function No(e,t,n,i=1){return n.roughness*i*(Nl(n)*(t-e)+e)}function $(e,t,n=1){return No(-e,e,t,n)}function Qt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=Dl(e,t,n,i,o,!0,!1);if(s)return a;let l=Dl(e,t,n,i,o,!0,!0);return a.concat(l)}function Dl(e,t,n,i,o,r,s){let a=Math.pow(e-n,2)+Math.pow(t-i,2),l=Math.sqrt(a),d=1;l<200?d=1:l>500?d=.4:d=-.0016668*l+1.233334;let c=o.maxRandomnessOffset||0;c*c*100>a&&(c=l/10);let u=c/2,p=.2+Nl(o)*.2,m=o.bowing*o.maxRandomnessOffset*(i-t)/200,h=o.bowing*o.maxRandomnessOffset*(e-n)/200;m=$(m,o,d),h=$(h,o,d);let f=[],g=()=>$(u,o,d),E=()=>$(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:$(c,o,d)),t+(x?0:$(c,o,d))]})),s?f.push({op:"bcurveTo",data:[m+e+(n-e)*p+g(),h+t+(i-t)*p+g(),m+e+2*(n-e)*p+g(),h+t+2*(i-t)*p+g(),n+(x?0:g()),i+(x?0:g())]}):f.push({op:"bcurveTo",data:[m+e+(n-e)*p+E(),h+t+(i-t)*p+E(),m+e+2*(n-e)*p+E(),h+t+2*(i-t)*p+E(),n+(x?0:E()),i+(x?0:E())]}),f}function vl(e,t,n){let i=[];i.push([e[0][0]+$(t,n),e[0][1]+$(t,n)]),i.push([e[0][0]+$(t,n),e[0][1]+$(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+$(t,n),e[o][1]+$(t,n)]),o===e.length-1&&i.push([e[o][0]+$(t,n),e[o][1]+$(t,n)]);return Oo(i,null,n)}function Oo(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]+$(a,n),t[1]+$(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...Qt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function Ll(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let p=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(p),c.push(p)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=$(.5,a)-Math.PI/2;c.push([$(r,a)+t+.9*i*Math.cos(u-e),$(r,a)+n+.9*o*Math.sin(u-e)]);let p=Math.PI*2+u-.01;for(let m=u;m<p;m=m+e){let h=[$(r,a)+t+i*Math.cos(m),$(r,a)+n+o*Math.sin(m)];d.push(h),c.push(h)}c.push([$(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),$(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([$(r,a)+t+.98*i*Math.cos(u+s),$(r,a)+n+.98*o*Math.sin(u+s)]),c.push([$(r,a)+t+.9*i*Math.cos(u+s*.5),$(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function Bl(e,t,n,i,o,r,s,a,l){let d=r+$(.1,l),c=[];c.push([$(a,l)+t+.9*i*Math.cos(d-e),$(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([$(a,l)+t+i*Math.cos(u),$(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)]),Oo(c,null,l)}function zp(e,t,n,i,o,r,s,a){let l=[],d=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],c=[0,0],u=a.disableMultiStroke?1:2,p=a.preserveVertices;for(let m=0;m<u;m++)m===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(p?0:$(d[0],a)),s[1]+(p?0:$(d[0],a))]}),c=p?[o,r]:[o+$(d[m],a),r+$(d[m],a)],l.push({op:"bcurveTo",data:[e+$(d[m],a),t+$(d[m],a),n+$(d[m],a),i+$(d[m],a),c[0],c[1]]});return l}M();function Vi(e){return[...e]}function Ro(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(Vi(e[0]),Vi(e[1]),Vi(e[2]),Vi(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(Vi(o[0]));for(let a=1;a+2<o.length;a++){let l=o[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*o[a+1][0]-s*o[a-1][0])/6,l[1]+(s*o[a+1][1]-s*o[a-1][1])/6],r[2]=[o[a+1][0]+(s*o[a][0]-s*o[a+2][0])/6,o[a+1][1]+(s*o[a][1]-s*o[a+2][1])/6],r[3]=[o[a+1][0],o[a+1][1]],i.push(r[1],r[2],r[3])}}return i}M();function _p(e,t){return Math.sqrt(zo(e,t))}function zo(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Hp(e,t,n){let i=zo(t,n);if(i===0)return zo(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)),zo(e,qn(t,n,o))}function qn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Up(e,t){let n=e[t+0],i=e[t+1],o=e[t+2],r=e[t+3],s=3*i[0]-2*n[0]-r[0];s*=s;let a=3*i[1]-2*n[1]-r[1];a*=a;let l=3*o[0]-2*r[0]-n[0];l*=l;let d=3*o[1]-2*r[1]-n[1];return d*=d,s<l&&(s=l),a<d&&(a=d),s+a}function os(e,t,n,i){let o=i||[];if(Up(e,t)<n){let r=e[t+0];o.length?_p(o[o.length-1],r)>1&&o.push(r):o.push(r),o.push(e[t+3])}else{let s=e[t+0],a=e[t+1],l=e[t+2],d=e[t+3],c=qn(s,a,.5),u=qn(a,l,.5),p=qn(l,d,.5),m=qn(c,u,.5),h=qn(u,p,.5),f=qn(m,h,.5);os([s,c,m,f],0,n,o),os([f,h,p,d],0,n,o)}return o}function Pn(e,t){return _o(e,0,e.length,t)}function _o(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=Hp(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(_o(e,t,d+1,i,r),_o(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function Et(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;os(e,s,t,i)}return n&&n>0?_o(i,0,i.length,n):i}M();function Ol(e,t,n){let i=Ei(e),o=$i(Yi(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Et(l,t)),l=[]},c=()=>{d(),s.length&&(r.push(s),s=[])};for(let{key:p,data:m}of o)switch(p){case"M":c(),a=[m[0],m[1]],s.push(a);break;case"L":d(),s.push([m[0],m[1]]);break;case"C":if(!l.length){let h=s.length?s[s.length-1]:a;l.push([h[0],h[1]])}l.push([m[0],m[1]]),l.push([m[2],m[3]]),l.push([m[4],m[5]]);break;case"Z":d(),s.push([a[0],a[1]]);break}if(c(),!n)return r;let u=[];for(let p of r){let m=Pn(p,n);m.length&&u.push(m)}return u}var xt="none",bt=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Tl()}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,i){return{shape:t,sets:n||[],options:i||this.defaultOptions}}line(t,n,i,o,r){let s=this._o(r);return this._d("line",[Jr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=kl(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(Fo([d],s)):a.push(Zn([d],s))}return s.stroke!==xt&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=ts(i,o,s),d=Go(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Go(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(Zn([d.estimatedPoints],s));return s.stroke!==xt&&a.push(d.opset),this._d("ellipse",a,s)}circle(t,n,i,o){let r=this.ellipse(t,n,i,i,o);return r.shape="circle",r}linearPath(t,n){let i=this._o(n);return this._d("linearPath",[ji(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=ns(t,n,i,o,r,s,a,!0,d);if(a&&d.fill)if(d.fillStyle==="solid"){let p=Object.assign({},d);p.disableMultiStroke=!0;let m=ns(t,n,i,o,r,s,!0,!1,p);m.type="fillPath",c.push(m)}else c.push(Cl(t,n,i,o,r,s,d));return d.stroke!==xt&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=es(t,i);if(i.fill&&i.fill!==xt&&t.length>=3)if(i.fillStyle==="solid"){let s=es(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(s.ops)})}else{let s=Ro(t),a=Et(s,10,(1+i.roughness)/2);o.push(Zn([a],i))}return i.stroke!==xt&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=ji(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(Fo([t],i)):o.push(Zn([t],i))),i.stroke!==xt&&o.push(r),this._d("polygon",o,i)}path(t,n){let i=this._o(n),o=[];if(!t)return this._d("path",o,i);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=i.fill&&i.fill!=="transparent"&&i.fill!==xt,s=i.stroke!==xt,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=Ol(t,1,l),c=is(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=is(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else o.push(Fo(d,i));else o.push(Zn(d,i));return s&&(a?d.forEach(u=>{o.push(ji(u,!1,i))}):o.push(c)),this._d("path",o,i)}opsToPath(t,n){let i="";for(let o of t.ops){let r=typeof n=="number"&&n>=0?o.data.map(s=>+s.toFixed(n)):o.data;switch(o.op){case"move":i+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":i+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":i+=`L${r[0]} ${r[1]} `;break}}return i.trim()}toPaths(t){let n=t.sets||[],i=t.options||this.defaultOptions,o=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:xt};break;case"fillPath":s={d:this.opsToPath(r),stroke:xt,strokeWidth:0,fill:i.fill||xt};break;case"fillSketch":s=this.fillSketch(r,i);break}s&&o.push(s)}return o}fillSketch(t,n){let i=n.fillWeight;return i<0&&(i=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||xt,strokeWidth:i,fill:xt}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var Ho=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new bt(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":o.save(),o.strokeStyle=i.stroke==="none"?"transparent":i.stroke,o.lineWidth=i.strokeWidth,i.strokeLineDash&&o.setLineDash(i.strokeLineDash),i.strokeLineDashOffset&&(o.lineDashOffset=i.strokeLineDashOffset),this._drawToContext(o,s,r),o.restore();break;case"fillPath":{o.save(),o.fillStyle=i.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,s,r,a),o.restore();break}case"fillSketch":this.fillSketch(o,s,i);break}}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2),t.save(),i.fillLineDash&&t.setLineDash(i.fillLineDash),i.fillLineDashOffset&&(t.lineDashOffset=i.fillLineDashOffset),t.strokeStyle=i.fill||"",t.lineWidth=o,this._drawToContext(t,n,i.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,i,o="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof i=="number"&&i>=0?r.data.map(a=>+a.toFixed(i)):r.data;switch(r.op){case"move":t.moveTo(s[0],s[1]);break;case"bcurveTo":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"lineTo":t.lineTo(s[0],s[1]);break}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s),s}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s),s}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s),s}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r),r}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i),i}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i),i}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d),d}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i),i}path(t,n){let i=this.gen.path(t,n);return this.draw(i),i}};M();M();var Ki="http://www.w3.org/2000/svg";var Uo=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(Ki,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(Ki,"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(Ki,"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(Ki,"path");return r.setAttribute("d",this.opsToPath(n,i.fixedDecimalPlaceDigits)),r.setAttribute("stroke",i.fill||""),r.setAttribute("stroke-width",o+""),r.setAttribute("fill","none"),i.fillLineDash&&r.setAttribute("stroke-dasharray",i.fillLineDash.join(" ").trim()),i.fillLineDashOffset&&r.setAttribute("stroke-dashoffset",`${i.fillLineDashOffset}`),r}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,n){return this.gen.opsToPath(t,n)}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s)}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s)}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s)}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r)}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i)}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i)}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d)}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i)}path(t,n){let i=this.gen.path(t,n);return this.draw(i)}};var xi={canvas(e,t){return new Ho(e,t)},svg(e,t){return new Uo(e,t)},generator(e){return new bt(e)},newSeed(){return bt.newSeed()}};import{arrayToMap as Du,invariant as Fa,rescalePoints as Su,sizeOf as ax}from"@excalidraw/common";import{degreesToRadians as Ga,lineSegment as we,pointFrom as F,pointFromArray as vu,pointRotateRads as le}from"@excalidraw/math";M();import{invariant as Wp}from"@excalidraw/common";import{curve as Yp,lineSegment as Xp,pointFrom as xe,pointDistance as FP,pointFromArray as $p,pointFromVector as jp,pointRotateRads as At,polygon as Gl,polygonFromPoints as rs,PRECISION as RP,segmentsIntersectAt as zP,vector as Vp,vectorAdd as Kp,vectorFromPoint as Zp,vectorScale as _P}from"@excalidraw/math";import{getElementAbsoluteCoords as UP}from"@excalidraw/element";var Fl=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=xe(s,a),d;return e.type==="diamond"?d=Gl(At(xe(s,r),l,t),At(xe(o+n,a),l,t),At(xe(s,r+i),l,t),At(xe(o,a),l,t)):d=Gl(At(xe(o,r),l,t),At(xe(o+n,r),l,t),At(xe(o+n,r+i),l,t),At(xe(o,r+i),l,t)),{type:"polygon",data:d}};var Rl=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:xe(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},Jt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},zl=(e,t=xe(0,0),n,i)=>{let o=l=>At(xe(l[0]+t[0],l[1]+t[1]),i,n),r=Jt(e),s=[],a=xe(0,0);for(let l of r){if(l.op==="move"){let d=$p(l.data);Wp(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(xe(l.data[0],l.data[1])),c=o(xe(l.data[2],l.data[3])),u=o(xe(l.data[4],l.data[5]));s.push(Yp(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},qp=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Xp(t,o)),t=o}return n},_l=(e,t,n=!1)=>{let i=r=>At(jp(Kp(Zp(r),Vp(e.x,e.y))),t,e.angle),o=qp(e.points.map(r=>i(r)));return n?{type:"polygon",data:rs(o.flat())}:{type:"polyline",data:o}},Hl=(e,t,n=xe(0,0),i,o)=>{let r=c=>At(xe(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:rs(e.points.map(c=>r(c)))};let s=Jt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(xe(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(xe(c.data[0],c.data[1])),a.push(xe(c.data[2],c.data[3])),a.push(xe(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(xe(c.data[0],c.data[1]));let d=Et(a,10,5).map(c=>r(c));return{type:"polygon",data:rs(d)}};M();M();function Ul(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function Qp(e){return[-e[0],-e[1]]}function vt(e,t){return[e[0]+t[0],e[1]+t[1]]}function wt(e,t){return[e[0]-t[0],e[1]-t[1]]}function Dt(e,t){return[e[0]*t,e[1]*t]}function Jp(e,t){return[e[0]/t,e[1]/t]}function Zi(e){return[e[1],-e[0]]}function Wl(e,t){return e[0]*t[0]+e[1]*t[1]}function ef(e,t){return e[0]===t[0]&&e[1]===t[1]}function tf(e){return Math.hypot(e[0],e[1])}function nf(e){return e[0]*e[0]+e[1]*e[1]}function Yl(e,t){return nf(wt(e,t))}function jl(e){return Jp(e,tf(e))}function of(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function qi(e,t,n){let i=Math.sin(n),o=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*o-s*i,l=r*i+s*o;return[a+t[0],l+t[1]]}function ss(e,t,n){return vt(e,Dt(wt(t,e),n))}function Xl(e,t,n){return vt(e,Dt(t,n))}var{min:bi,PI:rf}=Math,$l=.275,Qi=rf+1e-4;function sf(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:p=!0,easing:m=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 B=P.pressure;if(r){let k=bi(1,P.distance/n),_=bi(1,1-k);B=bi(1,L+(_-L)*(k*$l))}return(L+B)/2},e[0].pressure),w=Ul(n,o,e[e.length-1].pressure,s),S,I=e[0].vector,A=e[0].point,T=A,O=A,v=T,N=!1;for(let L=0;L<e.length;L++){let{pressure:P}=e[L],{point:B,vector:k,distance:_,runningLength:K}=e[L];if(L<e.length-1&&h-K<3)continue;if(o){if(r){let fe=bi(1,_/n),oe=bi(1,1-fe);P=bi(1,y+(oe-y)*(fe*$l))}w=Ul(n,o,P,s)}else w=n/2;S===void 0&&(S=w);let te=K<f?u(K/f):1,ne=h-K<g?m((h-K)/g):1;w=Math.max(.01,w*Math.min(te,ne));let ie=(L<e.length-1?e[L+1]:e[L]).vector,Ae=L<e.length-1?Wl(k,ie):1,_t=Wl(k,I)<0&&!N,Ht=Ae!==null&&Ae<0;if(_t||Ht){let fe=Dt(Zi(I),w);for(let oe=1/13,Ne=0;Ne<=1;Ne+=oe)O=qi(wt(B,fe),B,Qi*Ne),x.push(O),v=qi(vt(B,fe),B,Qi*-Ne),b.push(v);A=O,T=v,Ht&&(N=!0);continue}if(N=!1,L===e.length-1){let fe=Dt(Zi(k),w);x.push(wt(B,fe)),b.push(vt(B,fe));continue}let bn=Dt(Zi(ss(ie,k,Ae)),w);O=wt(B,bn),(L<=1||Yl(A,O)>E)&&(x.push(O),A=O),v=vt(B,bn),(L<=1||Yl(T,v)>E)&&(b.push(v),T=v),y=P,I=k}let C=e[0].point.slice(0,2),z=e.length>1?e[e.length-1].point.slice(0,2):vt(e[0].point,[1,1]),U=[],D=[];if(e.length===1){if(!(f||g)||d){let L=Xl(C,jl(Zi(wt(C,z))),-(S||w)),P=[];for(let B=1/13,k=B;k<=1;k+=B)P.push(qi(L,C,Qi*2*k));return P}}else{if(!(f||g&&e.length===1))if(c)for(let P=1/13,B=P;B<=1;B+=P){let k=qi(b[0],C,Qi*B);U.push(k)}else{let P=wt(x[0],b[0]),B=Dt(P,.5),k=Dt(P,.51);U.push(wt(C,B),wt(C,k),vt(C,k),vt(C,B))}let L=Zi(Qp(e[e.length-1].vector));if(g||f&&e.length===1)D.push(z);else if(p){let P=Xl(z,L,w);for(let B=1/29,k=B;k<1;k+=B)D.push(qi(P,z,Qi*3*k))}else D.push(vt(z,Dt(L,w)),vt(z,Dt(L,w*.99)),wt(z,Dt(L,w*.99)),wt(z,Dt(L,w)))}return x.concat(D,b.reverse(),U)}function as(e,t={}){var n;let{streamline:i=.5,size:o=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-i)*.85,a=Array.isArray(e[0])?e:e.map(({x:m,y:h,pressure:f=.5})=>[m,h,f]);if(a.length===2){let m=a[1];a=a.slice(0,-1);for(let h=1;h<5;h++)a.push(ss(a[0],m,h/4))}a.length===1&&(a=[...a,[...vt(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=!1,c=0,u=l[0],p=a.length-1;for(let m=1;m<a.length;m++){let h=r&&m===p?a[m].slice(0,2):ss(u.point,a[m],s);if(ef(u.point,h))continue;let f=of(h,u.point);if(c+=f,m<p&&!d){if(c<o)continue;d=!0}u={point:h,pressure:a[m][2]>=0?a[m][2]:.5,vector:jl(wt(u.point,h)),distance:f,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function Vl(e,t={}){return sf(as(e,t),t)}M();M();M();function be([e,t,n],[i,o,r]){return[e+i,t+o,n+r]}function yi([e,t,n],[i,o,r]){return[e-i,t-o,n-r]}function Ie([e,t,n],i){return[e*i,t*i,n*i]}function Jn([e,t,n]){return[e/Math.sqrt(e**2+t**2),t/Math.sqrt(e**2+t**2),n]}function Fe([e,t,n],i){return[Math.cos(i)*e-Math.sin(i)*t,Math.sin(i)*e+Math.cos(i)*t,n]}function Kl(e,t,n){return be(e,Ie(yi(t,e),n))}function ls(e,t,n){return Math.atan2(n[1]-e[1],n[0]-e[0])-Math.atan2(t[1]-e[1],t[0]-e[0])}function ds(e){return Math.atan2(Math.sin(e),Math.cos(e))}function cs([e,t]){return Math.sqrt(e**2+t**2)}function Qn([e,t],[n,i]){return Math.sqrt((n-e)**2+(i-t)**2)}function Zl(e){if(e.length<2)return 0;let t=0;for(let n=1;n<=e.length-1;n++)t+=Qn(e[n-1],e[n]);return t+=Qn(e[e.length-2],e[e.length-1]),t}var af=(e,t,n)=>Math.max(t,Math.min(n,e));function ql(e,t,n){let i=Qn(t,n);if(i===0)return Qn(e,t);let o=af(((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i**2,0,1),r=[t[0]+o*(n[0]-t[0]),t[1]+o*(n[1]-t[1]),e[2]];return Qn(r,e)}M();function Ji(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=ql(l,n,i);return c>s?[c,d]:[s,a]},[0,-1]);if(o>=t){let s=e[r];return[...Ji([n,...e.slice(1,r),s],t).slice(0,-1),s,...Ji([s,...e.slice(r,-1),i],t).slice(1)]}return[n,i]}var Wo=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=Kl(this.lastPoint,t,1-this.options.streamline)),this.tailPoints.push(t),Zl(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=Ji(n,this.options.simplify));let i=n.length;if(i===0)return[];if(i===1){let I=n[0],A=this.getSize(t,I[2],0,i,0);if(A<.5)return[];let T=[];for(let O=0;O<=Math.PI*2;O+=Math.PI/16)T.push(be(I,Ie(Fe([1,0,0],O),A)));return T.push(be(I,Ie([1,0,0],this.getSize(t,I[2],0,i,0)))),T}if(i===2){let I=n[0],A=n[1],T=this.getSize(t,I[2],0,i,0),O=this.getSize(t,A[2],0,i,0);if(T<.5||O<.5)return[];let v=[],N=ls(I,[I[0],I[1]-100,I[2]],A);for(let C=N;C<=Math.PI+N;C+=Math.PI/16)v.push(be(I,Ie(Fe([1,0,0],C),T)));for(let C=Math.PI+N;C<=Math.PI*2+N;C+=Math.PI/16)v.push(be(A,Ie(Fe([1,0,0],C),O)));return v.push(v[0]),v}let o=[],r=[],s=0,a=0,l=0,d=0;for(let I=1;I<i-1;I++){let A=n[I-1],T=n[I],O=n[I+1],v=T[2],N=Qn(A,T);d+=N,s=a+(N-a)*.2;let C=this.getSize(t,v,I,i,d);if(C===0){l=I+1;continue}let z=Jn(yi(A,T)),U=Jn(yi(O,T)),D=Fe(z,Math.PI/2),L=Fe(z,-Math.PI/2),P=Fe(U,Math.PI/2),B=Fe(U,-Math.PI/2),k=be(T,Ie(D,C)),_=be(T,Ie(L,C)),K=be(T,Ie(P,C)),te=be(T,Ie(B,C)),ne=be(D,B),ie=be(L,P),Ae=be(T,Ie(cs(ne)===0?z:Jn(ne),C)),_t=be(T,Ie(cs(ie)===0?U:Jn(ie),C)),Ht=ds(ls(T,A,O)),bn=e.constants.cornerDetectionMaxAngle/180*Math.PI*e.constants.cornerDetectionVariance(s);if(Math.abs(Ht)<bn){let fe=Math.abs(ds(Math.PI-Ht));if(fe===0)continue;if(Ht<0){r.push(_,_t);for(let oe=0;oe<=fe;oe+=fe/4)o.push(be(T,Fe(Ie(D,C),oe)));for(let oe=fe;oe>=0;oe-=fe/4)r.push(be(T,Fe(Ie(D,C),oe)));r.push(_t,K)}else{o.push(k,Ae);for(let oe=0;oe<=fe;oe+=fe/4)r.push(be(T,Fe(Ie(D,-C),-oe)));for(let oe=fe;oe>=0;oe-=fe/4)o.push(be(T,Fe(Ie(D,-C),-oe)));o.push(Ae,te)}}else o.push(Ae),r.push(_t);a=s}if(l>=i-2){if(this.options.keepHead){let I=n[i-1],A=[];for(let T=0;T<=Math.PI*2;T+=Math.PI/16)A.push(be(I,Ie(Fe([1,0,0],T),this.options.size)));return A.push(be(I,Ie([1,0,0],this.options.size))),A}return[]}let c=n[l],u=n[l+1],p=n[i-2],m=n[i-1],h=Jn(yi(u,c)),f=Jn(yi(p,m)),g=Fe(h,-Math.PI/2),E=Fe(f,Math.PI/2),x=this.getSize(t,c[2],0,i,0),b=[],y=this.options.keepHead?this.options.size:this.getSize(t,p[2],i-2,i,d),w=[];if(x>.1){for(let I=0;I<=Math.PI;I+=Math.PI/16)b.unshift(be(c,Fe(Ie(g,x),-I)));b.unshift(be(c,Ie(g,-x)))}else b.push(c);for(let I=0;I<=Math.PI*3;I+=Math.PI/16)w.push(be(m,Fe(Ie(E,-y),-I)));let S=[...b,...o,...w.reverse(),...r.reverse()];return b.length>0&&S.push(b[0]),this.options.simplify>0&&this.options.simplifyPhase==="output"?Ji(S,this.options.simplify):S}};import{pointFrom as Ce,pointDistance as mu,pointRotateRads as Ni,polygonFromPoints as $E}from"@excalidraw/math";import{ROUGHNESS as jE,THEME as Ca,isTransparent as bo,assertNever as VE,COLOR_PALETTE as KE,LINE_POLYGON_POINT_MERGE_DISTANCE as ZE,applyDarkModeFilter as yo,DEFAULT_STROKE_STREAMLINE as qE}from"@excalidraw/common";M();import{clamp as nu,isRightAngleRads as TE,lineSegment as iu,pointFrom as Mr,pointRotateRads as Aa}from"@excalidraw/math";import{BOUND_TEXT_PADDING as Wn,DEFAULT_REDUCED_GLOBAL_ALPHA as AE,ELEMENT_READY_TO_ERASE_OPACITY as DE,FRAME_STYLE as Tr,DARK_THEME_FILTER as vE,MIME_TYPES as Ba,THEME as mn,distance as Yn,getFontString as LE,isRTL as BE,getVerticalOffset as kE,invariant as CE,applyDarkModeFilter as ci,isSafari as NE,STICKY_NOTE_EDGE_SHADOW_OPACITY as OE,STICKY_NOTE_EDGE_SHADOW_WIDTH as GE,STICKY_NOTE_FOOTER as Da,STICKY_NOTE_SHADOW_OPACITY as FE,DEFAULT_ZOOM as RE}from"@excalidraw/common";M();import{pointFrom as en,pointCenter as df,pointRotateRads as Sn,vectorFromPoint as us,vectorNormalize as Ql,vectorSubtract as Jl,vectorAdd as Yo,vectorScale as Xo,pointFromVector as ed,clamp as We,isCloseTo as td}from"@excalidraw/math";var Ye=10,r1=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=ms(e),c=i/l,u=o/d,p=(e.crop?.x??0)/c,m=(e.crop?.y??0)/u,h=Sn(en(r,s),re(e,t),-e.angle);r=h[0],s=h[1];let f=e.width,g=e.height,E=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=E.height,b=E.width,y=e.scale[0]===-1,w=e.scale[1]===-1,S=s-e.y,I=r-e.x;n.includes("n")&&(g=We(e.height-S,Ye,w?d-m:e.height+m)),n.includes("s")&&(S=s-e.y-e.height,g=We(e.height+S,Ye,w?e.height+m:d-m)),n.includes("e")&&(I=r-e.x-e.width,f=We(e.width+I,Ye,y?e.width+p:l-p)),n.includes("w")&&(f=We(e.width-I,Ye,y?l-p:e.width+p));let A=v=>{v.height=g*u,v.width=f*c};A(E);let T=(v,N)=>{A(N),v.includes("n")&&(w||(N.y+=x-N.height)),v.includes("s")&&w&&(N.y+=x-N.height),v.includes("e")&&y&&(N.x+=b-N.width),v.includes("w")&&(y||(N.x+=b-N.width))};switch(n){case"n":{if(a){let v=p+e.width/2,N=l-p-e.width/2,C=Math.min(v,N)*2;f=We(g*a,Ye,C),g=f/a}T(n,E),a&&(E.x+=(b-E.width)/2);break}case"s":{if(a){let v=p+e.width/2,N=l-p-e.width/2,C=Math.min(v,N)*2;f=We(g*a,Ye,C),g=f/a}T(n,E),a&&(E.x+=(b-E.width)/2);break}case"w":{if(a){let v=m+e.height/2,N=d-m-e.height/2,C=Math.min(v,N)*2;g=We(f/a,Ye,C),f=g*a}T(n,E),a&&(E.y+=(x-E.height)/2);break}case"e":{if(a){let v=m+e.height/2,N=d-m-e.height/2,C=Math.min(v,N)*2;g=We(f/a,Ye,C),f=g*a}T(n,E),a&&(E.y+=(x-E.height)/2);break}case"ne":{if(a)if(I>-S){let v=w?d-m:m+e.height;g=We(f/a,Ye,v),f=g*a}else{let v=y?p+e.width:l-p;f=We(g*a,Ye,v),g=f/a}T(n,E);break}case"nw":{if(a)if(I<S){let v=w?d-m:m+e.height;g=We(f/a,Ye,v),f=g*a}else{let v=y?l-p:p+e.width;f=We(g*a,Ye,v),g=f/a}T(n,E);break}case"se":{if(a)if(I>S){let v=w?m+e.height:d-m;g=We(f/a,Ye,v),f=g*a}else{let v=y?p+e.width:l-p;f=We(g*a,Ye,v),g=f/a}T(n,E);break}case"sw":{if(a)if(-I>S){let v=w?m+e.height:d-m;g=We(f/a,Ye,v),f=g*a}else{let v=y?l-p:p+e.width;f=We(g*a,Ye,v),g=f/a}T(n,E);break}default:break}let O=cf(e,n,f,g,!!a);return td(E.width,E.naturalWidth)&&td(E.height,E.naturalHeight)&&(E=null),{x:O[0],y:O[1],width:f,height:g,crop:E}},cf=(e,t,n,i,o)=>{let[r,s,a,l]=In(e,e.width,e.height,!0),d=en(r,s),c=en(a,l),u=df(d,c),[p,m,h,f]=In(e,n,i,!0),g=h-p,E=f-m,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(g),c[1]-Math.abs(E)]),t==="ne"){let A=[d[0],c[1]];x=[A[0],A[1]-Math.abs(E)]}if(t==="sw"){let A=[c[0],d[1]];x=[A[0]-Math.abs(g),A[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-g/2),["e","w"].includes(t)&&(x[1]=u[1]-E/2));let b=e.angle,y=Sn(x,u,b),w=[x[0]+Math.abs(g)/2,x[1]+Math.abs(E)/2],S=Sn(w,u,b);x=Sn(y,S,-b);let I=[...x];return I[0]+=e.x-p,I[1]+=e.y-m,I},nd=(e,t)=>{if(e.crop){let{width:n,height:i}=ms(e),[o,r,s,a,l,d]=Q(e,t),c=us(Sn(en(o,r),en(l,d),e.angle)),u=us(Sn(en(s,r),en(l,d),e.angle)),p=Ql(Jl(u,c)),m=us(Sn(en(o,a),en(l,d),e.angle)),h=Jl(m,c),f=Ql(h),{cropX:g,cropY:E}=uf(e.crop,e.scale),x=Yo(Yo(c,Xo(p,-g*n/e.crop.naturalWidth)),Xo(f,-E*i/e.crop.naturalHeight)),b=ed(Yo(Yo(x,Xo(p,n/2)),Xo(f,i/2))),y=Sn(ed(x),b,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},ms=e=>{if(e.crop){let t=e.width/(e.crop.width/e.crop.naturalWidth),n=e.height/(e.crop.height/e.crop.naturalHeight);return{width:t,height:n}}return{width:e.width,height:e.height}},uf=(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}},s1=(e,t=!1)=>{let n=e.crop;if(!n)return null;let i=e.scale[0]===-1,o=e.scale[1]===-1,r=n.x,s=n.y;if(i&&(r=n.naturalWidth-n.width-n.x),o&&(s=n.naturalHeight-n.height-n.y),t)return{x:r,y:s};let{width:a,height:l}=ms(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};M();import{pointCenter as Ic,pointFrom as H,pointRotateRads as nt,pointsEqual as Mc,pointDistance as Vt,vectorFromPoint as _g,curveLength as Nc,curveLengthAtParameter as Hg,curvePointAtLength as Oc,lineSegmentClosestParameter as Ug,lineSegmentPointAt as Gc,curveClosestParameter as Wg,clamp as ma,bezierEquation as Yg,isCurve as wr}from"@excalidraw/math";import{DRAGGING_THRESHOLD as Xg,KEYS as ai,shouldRotateWithDiscreteAngle as li,getGridPoint as Tc,invariant as ft,isShallowEqual as $g,getFeatureFlag as Li}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as Ac,getSnapOutlineMidPoint as pa,isPathALoop as jg,moveArrowAboveBindable as Dc,projectFixedPointOntoDiagonal as vc,getLinearElementPathSegments as Vg}from"@excalidraw/element";M();import{arrayToMap as hc,getFeatureFlag as yg,getGridPoint as la,invariant as un,isTransparent as wg}from"@excalidraw/common";import{PRECISION as Pg,clamp as gc,lineSegment as ri,pointDistance as da,pointDistanceSq as tt,pointFrom as ue,pointFromArray as Sg,pointFromVector as co,pointRotateRads as et,pointsEqual as Ig,vectorFromPoint as Gn,vectorNormalize as xr,vectorScale as uo}from"@excalidraw/math";M();import{invariant as ig,isTransparent as Jd}from"@excalidraw/common";import{curveIntersectLineSegment as ec,isPointWithinBounds as ra,lineSegment as hr,lineSegmentIntersectionPoints as tc,pointFrom as Te,pointFromVector as og,pointRotateRads as mt,pointsEqual as nc,polygonIncludesPoint as rg,vectorFromPoint as sg,vectorNormalize as ag,vectorScale as lg}from"@excalidraw/math";import{ellipse as dg,ellipseSegmentInterceptPoints as cg}from"@excalidraw/math/ellipse";M();import{DEFAULT_ADAPTIVE_RADIUS as Yh,DEFAULT_PROPORTIONAL_RADIUS as Vs,invariant as Xh,LINE_CONFIRM_THRESHOLD as $h,ROUNDNESS as Ks}from"@excalidraw/common";import{bezierEquation as jh,clamp as zd,curve as dn,curveCatmullRomCubicApproxPoints as Ud,curveOffsetPoints as Wd,lineSegment as ke,lineSegmentIntersectionPoints as _d,pointDistance as ln,pointFrom as Y,pointFromArray as Vh,pointFromVector as Kh,pointRotateRads as It,pointTranslate as Hd,rectangle as Zh,vectorFromPoint as Yd,vectorNormalize as qh,vectorScale as Zs}from"@excalidraw/math";M();import{ROUNDNESS as eo,assertNever as mf}from"@excalidraw/common";import{pointsEqual as id}from"@excalidraw/math";var ei=e=>!!e&&e.type==="image"&&!!e.fileId,Oe=e=>!!e&&e.type==="image",od=e=>!!e&&e.type==="embeddable",$o=e=>!!e&&e.type==="iframe",jo=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),j=e=>e!=null&&e.type==="text",ye=e=>e!=null&&e.type==="stickynote",Vo=e=>e!=null&&e.type==="frame",rd=e=>e!=null&&e.type==="magicframe",J=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),ge=e=>e!=null&&pf(e.type),pf=e=>e==="freedraw",ee=e=>e!=null&&gf(e.type),Re=e=>e!=null&&e.type==="line",W=e=>e!=null&&e.type==="arrow",X=e=>W(e)&&e.elbowed,u1=e=>W(e)&&!e.elbowed,ff=e=>W(e)&&!e.elbowed&&!e.roundness,hf=e=>W(e)&&!e.elbowed&&e.roundness!==null,gf=e=>e==="arrow"||e==="line",Xe=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&Ef(e.type),Ef=e=>e==="arrow",Pe=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),sd=e=>e!=null&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="diamond"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),to=e=>e!=null&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="image"||e.type==="text"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="freedraw"),xf=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="diamond"||e.type==="ellipse"||W(e)),ad=e=>{let t=e?.type;if(!t)return!1;switch(t){case"text":case"diamond":case"rectangle":case"stickynote":case"iframe":case"embeddable":case"ellipse":case"arrow":case"freedraw":case"line":case"frame":case"magicframe":case"image":case"selection":return!0;default:return mf(t,null),!1}},ld=e=>e.type==="rectangle"||e.type==="stickynote"||e.type==="ellipse"||e.type==="diamond",Wt=e=>xf(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),pe=e=>e!==null&&"containerId"in e&&e.containerId!==null&&j(e),m1=e=>!!e.startBinding||!!e.endBinding,Ko=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",dd=e=>e==="line"||e==="arrow"||e==="diamond"||e==="stickynote",p1=(e,t)=>!!((e===eo.ADAPTIVE_RADIUS||e===eo.LEGACY)&&Ko(t.type)||e===eo.PROPORTIONAL_RADIUS&&dd(t.type)),f1=e=>dd(e.type)?{type:eo.PROPORTIONAL_RADIUS}:Ko(e.type)?{type:eo.ADAPTIVE_RADIUS}:null,h1=e=>ff(e)?"sharpArrow":hf(e)?"curvedArrow":X(e)?"elbowArrow":"line",ps=e=>e.length>3&&id(e[0],e[e.length-1]),cd=e=>e.length>3||e.length===3&&!id(e[0],e[e.length-1]),g1=e=>{switch(e){case"rectangle":case"stickynote":case"diamond":case"ellipse":case"arrow":case"line":case"freedraw":case"text":case"image":case"frame":case"embeddable":return!0;default:return!1}};M();import{DEFAULT_ELEMENT_PROPS as Th,DEFAULT_STICKY_NOTE_BG as Ah,MIN_FONT_SIZE as Dh,arrayToMap as Nd,STICKY_NOTE_BODY_INSET_Y as Us,STICKY_NOTE_FALLBACK_FONT_SIZE as vh,STICKY_NOTE_FOOTER as Ld,STICKY_NOTE_FONT_STEP as Hs,STICKY_NOTE_MAX_FONT_SIZE as Lh,STICKY_NOTE_MIN_SIZE as Di,STICKY_NOTE_MIN_FONT_SIZE as Bh,STICKY_NOTE_PADDING as ur,STICKY_NOTE_SHADOW_OFFSET as Bd,getFontString as kd,getLineHeight as kh,isTransparent as mr,seededRandom as Od}from"@excalidraw/common";import{clamp as Ch}from"@excalidraw/math";M();import{getSizeFromPoints as Kf,randomInteger as Ds,getUpdatedTimestamp as vs}from"@excalidraw/common";M();import{clamp as tr,pointDistance as ys,pointFrom as Z,pointScaleFromOrigin as Bf,pointsEqual as io,pointTranslate as bs,vector as Yt,vectorCross as nr,vectorFromPoint as ws,vectorScale as kf}from"@excalidraw/math";import{BinaryHeap as Cf,invariant as Si,isAnyTrue as Nf,getSizeFromPoints as md,isDevEnv as Of,arrayToMap as Gf,DEFAULT_ZOOM as Ff}from"@excalidraw/common";M();import{curvePointDistance as fs,distanceToLineSegment as Zo,pointRotateRads as hs,polygonIncludesPointNonZero as bf}from"@excalidraw/math";import{ellipse as yf,ellipseDistanceFromPoint as wf}from"@excalidraw/math/ellipse";var tn=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"stickynote":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return Pf(e,t,n);case"diamond":return Sf(e,t,n);case"ellipse":return If(e,t,n);case"line":case"arrow":return Mf(e,t,n);case"freedraw":return Tf(e,t,n)}},Pf=(e,t,n)=>{let i=re(e,t),o=hs(n,i,-e.angle),[r,s]=Mn(e);return Math.min(...r.map(a=>Zo(o,a)),...s.map(a=>fs(a,o)))},Sf=(e,t,n)=>{let i=re(e,t),o=hs(n,i,-e.angle),[r,s]=Tn(e);return Math.min(...r.map(a=>Zo(o,a)),...s.map(a=>fs(a,o)))},If=(e,t,n)=>{let i=re(e,t);return wf(hs(n,i,-e.angle),yf(i,e.width/2,e.height/2))},Mf=(e,t,n)=>{let[i,o]=wi(e,t);return Math.min(...i.map(r=>Zo(n,r)),...o.map(r=>fs(r,n)))},Tf=(e,t,n)=>{let[i]=wi(e,t);if(i.length===0)return 1/0;let o=i.map(r=>r[0]);return bf(n,o)?0:Math.min(...i.map(r=>Zo(n,r)))};M();import{invariant as ud,isDevEnv as Af,isTestEnv as Df}from"@excalidraw/common";import{pointFrom as An,pointFromVector as qo,pointRotateRads as Qo,pointScaleFromOrigin as Jo,pointsEqual as vf,triangleIncludesPoint as gs,vectorCross as lt,vectorFromPoint as se,vectorScale as er}from"@excalidraw/math";var Ee=[1,0],ve=[0,1],ze=[-1,0],qe=[0,-1],Lt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?Ee:t<=-o?ze:n>i?ve:qe},dt=(e,t)=>Lt(se(e,t)),Bt=(e,t)=>ct(dt(e,t)),he=(e,t)=>e[0]===t[0]&&e[1]===t[1],ct=e=>he(e,Ee)||he(e,ze),D1=e=>!ct(e),Lf=(e,t,n)=>{let i=nn(t);(Af()||Df())&&(ud(e.width>0&&e.height>0,"Diamond element has no width or height"),ud(!vf(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=qo(er(se(Qo(An(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=qo(er(se(Qo(An(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=qo(er(se(Qo(An(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=qo(er(se(Qo(An(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(lt(se(n,r),se(r,s))<=0&<(se(n,r),se(r,l))>0)return dt(r,i);if(lt(se(n,s),se(s,a))<=0&<(se(n,s),se(s,r))>0)return dt(s,i);if(lt(se(n,a),se(a,l))<=0&<(se(n,a),se(a,s))>0)return dt(a,i);if(lt(se(n,l),se(l,r))<=0&<(se(n,l),se(l,a))>0)return dt(l,i);if(lt(se(n,i),se(r,i))<=0&<(se(n,i),se(s,i))>0){let c=e.width>e.height?r:s;return dt(c,i)}else if(lt(se(n,i),se(s,i))<=0&<(se(n,i),se(a,i))>0){let c=e.width>e.height?a:s;return dt(c,i)}else if(lt(se(n,i),se(a,i))<=0&<(se(n,i),se(l,i))>0){let c=e.width>e.height?a:l;return dt(c,i)}let d=e.width>e.height?r:l;return dt(d,i)},Pi=(e,t,n)=>{let o=nn(t);if(e.type==="diamond")return Lf(e,t,n);let r=Jo(An(t[0],t[1]),o,2),s=Jo(An(t[2],t[1]),o,2),a=Jo(An(t[0],t[3]),o,2),l=Jo(An(t[2],t[3]),o,2);return gs([r,s,o],n)?qe:gs([s,l,o],n)?Ee:gs([l,a,o],n)?ve:ze},Es=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];var Ps=1,ce=40,Rf=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>Z(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=dt(s,l[a-1]),c=dt(l[a-1],l[a-2]);if(he(d,c)){let u=n?.findIndex(m=>m.index===a-1)??-1,p=n?.findIndex(m=>m.index===a)??-1;p!==-1&&(n[p].start=Z(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(m=>{m.index>a-1&&(m.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(ys(l[a-2],l[a-1])<Ps){let d=n?.findIndex(p=>p.index===a-2)??-1,c=n?.findIndex(p=>p.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),o.splice(-2,2),n.forEach(p=>{p.index>a-2&&(p.index-=2)});let u=Bt(s,l[a-1]);return o.push(Z(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}o.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==o.length-1);return r.length===0?on(Ms(Ts(Is(e,Ss(e,t,o.map(s=>Z(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(Of()&&Si(bd(o),"Invalid elbow points with fixed segments"),on(o,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},zf=(e,t,n)=>{let i=t.map(T=>T.index),r=(e.fixedSegments?.map(T=>T.index)??[]).findIndex(T=>!i.includes(T));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,p=l?null:e.endBinding,{startHeading:m,endHeading:h,startGlobalPoint:f,endGlobalPoint:g,hoveredStartElement:E,hoveredEndElement:x,...b}=Ss({x:d,y:c,startBinding:u,endBinding:p,startArrowhead:null,endArrowhead:null,points:e.points},n,[Z(0,0),Z(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:y}=on(Ms(Ts(Is(e,{startHeading:m,endHeading:h,startGlobalPoint:f,endGlobalPoint:g,hoveredStartElement:E,hoveredEndElement:x,...b})??[])),t,null,null);if(!y||y.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let w=[];if(a)for(let T=0;T<a.index;T++)w.push(Z(e.x+e.points[T][0],e.y+e.points[T][1]));if(y.forEach(T=>{w.push(Z(e.x+(a?a.end[0]:0)+T[0],e.y+(a?a.end[1]:0)+T[1]))}),l)for(let T=l.index;T<e.points.length;T++)w.push(Z(e.x+e.points[T][0],e.y+e.points[T][1]));let S=(l?.index??e.points.length)-(a?.index??0)-1,I=t.map(T=>T.index>s?{...T,index:T.index-S+(y.length-1)}:T),A=w.flatMap((T,O)=>{let v=w[O-1],N=w[O+1];if(v&&N){let C=dt(T,v),z=dt(N,T);if(he(C,z))return I.forEach(U=>{U.index>O&&(U.index-=1)}),[];if(he(C,Es(z)))return I.forEach(U=>{U.index>O&&(U.index+=1)}),[T,T]}return[T]});return on(A,I,!1,!1)},_f=(e,t,n,i,o,r)=>{let s=t.map((w,S)=>e.fixedSegments==null||e.fixedSegments[S]===void 0||e.fixedSegments[S].index!==w.index||(w.start[0]!==e.fixedSegments[S].start[0]&&w.end[0]!==e.fixedSegments[S].end[0])!=(w.start[1]!==e.fixedSegments[S].start[1]&&w.end[1]!==e.fixedSegments[S].end[1])?S:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,d=ys(t[s].start,t[s].end),c=d<ce+5;if(a===-1&&t[s].index===1&&o){let w=ct(n),I=(w?he(n,Ee):he(n,ve))?c?d/2:ce:c?-d/2:-ce;t[s].start=Z(t[s].start[0]+(w?I:0),t[s].start[1]+(w?0:I))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=ct(i),I=(w?he(i,Ee):he(i,ve))?c?d/2:ce:c?-d/2:-ce;t[s].end=Z(t[s].end[0]+(w?I:0),t[s].end[1]+(w?0:I))}let u=t.map(w=>({...w,start:Z(e.x+w.start[0],e.y+w.start[1]),end:Z(e.x+w.end[0],e.y+w.end[1])})),p=e.points.map((w,S)=>Z(e.x+w[0],e.y+w[1])),m=u[s].index-1,h=u[s].index,f=u[s].start,g=u[s].end,E=p[m-1]&&!io(p[m],p[m-1])?Bt(p[m-1],p[m]):void 0,x=p[h+1]&&!io(p[h],p[h+1])?Bt(p[h+1],p[h]):void 0;if(E!==void 0){let w=E?1:0;p[m-1][w]=f[w]}if(p[m]=f,p[h]=g,x!==void 0){let w=x?1:0;p[h+1][w]=g[w]}let b=u.findIndex(w=>w.index===m);if(b!==-1){let w=Bt(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=Bt(u[y].end,u[y].start)?1:0;u[y].end[w]=g[w],u[y].start=g}if(a===-1&&m===0){let w=o?ct(n):Bt(p[1],p[0]);p.unshift(Z(w?f[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:f[1])),o&&p.unshift(Z(e.x+e.points[0][0],e.y+e.points[0][1]));for(let S of u)S.index+=o?2:1}if(l===-1&&h===e.points.length-1){let w=ct(i);p.push(Z(w?g[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:g[1])),r&&p.push(Z(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return on(p,u.map(w=>({...w,start:Z(w.start[0]-e.x,w.start[1]-e.y),end:Z(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},Hf=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((g,E)=>E===0?Z(e.x+g[0],e.y+g[1]):E===t.length-1?Z(e.x+g[0],e.y+g[1]):Z(e.x+e.points[E][0],e.y+e.points[E][1])),p=n.map(g=>({...g,start:Z(e.x+(g.start[0]-t[0][0]),e.y+(g.start[1]-t[0][1])),end:Z(e.x+(g.end[0]-t[0][0]),e.y+(g.end[1]-t[0][1]))})),m=[],h=2+(d?1:0),f=2+(c?1:0);for(;m.length+h<u.length-f;)m.push(u[m.length+h]);{let g=u.at(d?2:1),E=u.at(d?3:2);if(!g||!E)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=ct(i),b=ct(Lt(ws(g,E)));if(a&&x===b){let y=x?he(i,Ee):he(i,ve);if(m.unshift(Z(b?r[0]+(y?ce:-ce):E[0],b?E[1]:r[1]+(y?ce:-ce))),m.unshift(Z(x?r[0]+(y?ce:-ce):r[0],x?r[1]:r[1]+(y?ce:-ce))),!d){d=!0;for(let w of p)w.index>1&&(w.index+=1)}}else if(m.unshift(Z(b?r[0]:g[0],b?g[1]:r[1])),d){d=!1;for(let y of p)y.index>1&&(y.index-=1)}m.unshift(r)}{let g=u.at(u.length-(c?3:2)),E=u.at(u.length-(c?4:3));if(!g||!E)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=ct(o),b=Bt(E,g);if(l&&x===b){let y=x?he(o,Ee):he(o,ve);m.push(Z(b?s[0]+(y?ce:-ce):E[0],b?E[1]:s[1]+(y?ce:-ce))),m.push(Z(x?s[0]+(y?ce:-ce):s[0],x?s[1]:s[1]+(y?ce:-ce))),c||(c=!0)}else m.push(Z(b?s[0]:g[0],b?g[1]:s[1])),c&&(c=!1)}return m.push(s),on(m,p.map(({index:g})=>({index:g,start:m[g-1],end:m[g]})).map(g=>({...g,start:Z(g.start[0]-r[0],g.start[1]-r[1]),end:Z(g.end[0]-r[0],g.end[1]-r[1])})),d,c)},Dn=1e6,Ii=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};G.PROD||(Si(!n.points||n.points.length>=2,"Updated point array length must match the arrow point length, contain exactly the new start and end points or not be specified at all (i.e. you can't add new points between start and end manually to elbow arrows)"),Si(!e.fixedSegments||e.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Si(!n.fixedSegments||n.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Si(e.points.slice(1).map((w,S)=>w[0]===e.points[S][0]||w[1]===e.points[S][1]),"Elbow arrow segments must be either horizontal or vertical"),Si(n.fixedSegments?.find(w=>w.index===1&&io(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&io(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&&or(d.elementId,t),p=c&&or(c.elementId,t),m=bd(r);if(d&&!u&&m||c&&!p&&m||t.size===0&&m||Object.keys(l).length===0&&(u?.id!==d?.elementId||p?.id!==c?.elementId))return on(r.map(w=>Z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y}=Ss({x:e.x,y:e.y,startBinding:d,endBinding:c,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,i);return t.size===0&&m?on(r.map(w=>Z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?Rf(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,S)=>io(w,e.points[S]??Z(1/0,1/0)))&&m?{}:o.length===0?on(Ms(Ts(Is(e,{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?zf(e,o,t):n.points?n.points&&n.fixedSegments?n:Hf(e,r,o,h,f,g,E,x,b):_f(e,o,h,f,x,b)},Ss=(e,t,n,i)=>{let o=bs(n[0],Yt(e.x,e.y)),r=bs(n[n.length-1],Yt(e.x,e.y)),s=i?.zoom??Ff,a=null,l=null;if(i?.isDragging&&i?.isBindingEnabled!==!1){let S=Array.from(t.values());a=gd(o,t,S,s)||null,l=gd(r,t,S,s)||null}else a=e.startBinding&&or(e.startBinding.elementId,t)||null,l=e.endBinding&&or(e.endBinding.elementId,t)||null;let d=fd({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=fd({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,s,l,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),u=hd(d,c,a,o,t,s),p=hd(c,d,l,r,t,s),m=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],h=[c[0]-2,c[1]-2,c[0]+2,c[1]+2],f=a?ut(a,t,vn(u,e.startArrowhead?Le(a)*6:Le(a)*2,1)):m,g=l?ut(l,t,vn(p,e.endArrowhead?Le(l)*6:Le(l)*2,1)):h,E=Xt(d,l?ut(l,t,vn(p,ce,ce)):h)||Xt(c,a?ut(a,t,vn(u,ce,ce)):m),x=xd(E?[m,h]:[f,g]),b=Yf(E?m:f,E?h:g,x,E?vn(u,!a&&!l?0:ce,0):vn(u,!a&&!l?0:ce-(e.startArrowhead?Ln*6:Ln*2),ce),E?vn(p,!a&&!l?0:ce,0):vn(p,!a&&!l?0:ce-(e.endArrowhead?Ln*6:Ln*2),ce),E,a&&ut(a,t),l&&ut(l,t)),y=pd(b[0],u,d),w=pd(b[1],p,c);return{dynamicAABBs:b,startDonglePosition:y,startGlobalPoint:d,startHeading:u,endDonglePosition:w,endGlobalPoint:c,endHeading:p,commonBounds:x,hoveredStartElement:a,hoveredEndElement:l,boundsOverlap:E,startElementBounds:f,endElementBounds:g}},Is=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Xf(n,i||o,r,s||a,l,d),p=i&&ir(i,u),m=s&&ir(s,u),h=ir(a,u);h&&c&&(h.closed=!0);let f=ir(o,u);f&&e.startBinding&&(f.closed=!0);let g=p&&m&&(Xt(p.pos,n[1])||Xt(m.pos,n[0])),E=Uf(p||f,m||h,u,r||Ee,l||Ee,g?[]:n);if(E){let x=E.map(b=>[b.pos[0],b.pos[1]]);return p&&x.unshift(o),m&&x.push(a),x}return null},vn=(e,t,n)=>{switch(e){case qe:return[t,n,n,n];case Ee:return[n,t,n,n];case ve:return[n,n,t,n]}return[n,n,n,t]},Uf=(e,t,n,i,o,r)=>{let s=xs(e.pos,t.pos),a=new Cf(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Wf(e,l);l.closed=!0;let d=jf(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let p=Bf(u.pos,l.pos,.5);if(Nf(...r.map(y=>Xt(p,y))))continue;let m=Vf(c),h=l.parent?Lt(ws(l.pos,l.parent.pos)):i,f=Es(h);if(he(f,m)||Ed(e.addr,u.addr)&&he(m,i)||Ed(t.addr,u.addr)&&he(m,o))continue;let E=h!==m,x=l.g+xs(u.pos,l.pos)+(E?Math.pow(s,3):0),b=u.visited;if(!b||x<u.g){let y=$f(u,t,m,o);u.visited=!0,u.parent=l,u.h=xs(t.pos,u.pos)+y*Math.pow(s,2),u.g=x,u.f=u.g+u.h,b?a.rescoreElement(u):a.push(u)}}}return null},Wf=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},xs=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Yf=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,p,m]=i??[0,0,0,0],[h,f,g,E]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-m):(l[0]+d[2])/2:e[0]>t[0]?e[0]-m:n[0]-m,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+p):(l[3]+d[1])/2:e[3]<t[3]?e[3]+p:n[3]+p],b=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-E):(d[0]+l[2])/2:t[0]>e[0]?t[0]-E:n[0]-E,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-h):(d[1]+l[3])/2:t[1]>e[1]?t[1]-h:n[1]-h,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+f):(d[2]+l[0])/2:t[2]<e[2]?t[2]+f:n[2]+f,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+g):(d[3]+l[1])/2:t[3]<e[3]?t[3]+g:n[3]+g],y=xd([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 nr(Yt(e[2]-w,e[1]-S),Yt(e[0]-w,e[3]-S))>0?[[x[0],x[1],I,x[3]],[I,b[1],b[2],b[3]]]:[[x[0],A,x[2],x[3]],[b[0],b[1],b[2],A]]}else if(e[2]<t[0]&&e[3]<t[1]){let I=x[2]+(b[0]-x[2])/2,A=x[3]+(b[1]-x[3])/2;return nr(Yt(e[0]-w,e[1]-S),Yt(e[2]-w,e[3]-S))>0?[[x[0],x[1],x[2],A],[b[0],A,b[2],b[3]]]:[[x[0],x[1],I,x[3]],[I,b[1],b[2],b[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let I=b[2]+(x[0]-b[2])/2,A=x[3]+(b[1]-x[3])/2;return nr(Yt(e[2]-w,e[1]-S),Yt(e[0]-w,e[3]-S))>0?[[I,x[1],x[2],x[3]],[b[0],b[1],I,b[3]]]:[[x[0],x[1],x[2],A],[b[0],A,b[2],b[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let I=b[2]+(x[0]-b[2])/2,A=b[3]+(x[1]-b[3])/2;return nr(Yt(e[0]-w,e[1]-S),Yt(e[2]-w,e[3]-S))>0?[[I,x[1],x[2],x[3]],[b[0],b[1],I,b[3]]]:[[x[0],A,x[2],x[3]],[b[0],b[1],b[2],A]]}}return[x,b]},Xf=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===ze||n===Ee?a.add(t[1]):s.add(t[0]),o===ze||o===Ee?a.add(i[1]):s.add(i[0]),e.forEach(c=>{s.add(c[0]),s.add(c[2]),a.add(c[1]),a.add(c[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((c,u)=>c-u),d=Array.from(s).sort((c,u)=>c-u);return{row:l.length,col:d.length,data:l.flatMap((c,u)=>d.map((p,m)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[m,u],pos:[p,c]})))}},pd=(e,t,n)=>{switch(t){case qe:return Z(n[0],e[1]);case Ee:return Z(e[2],n[1]);case ve:return Z(n[0],e[3])}return Z(e[0],n[1])},$f=(e,t,n,i)=>{if(i===Ee)switch(n){case Ee:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case qe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ve:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ze:return e.pos[1]===t.pos[1]?4:2}else if(i===ze)switch(n){case Ee:return e.pos[1]===t.pos[1]?4:2;case qe:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ve:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ze:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===qe)switch(n){case Ee:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case qe:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ve:return e.pos[0]===t.pos[0]?4:2;case ze:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===ve)switch(n){case Ee:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case qe:return e.pos[0]===t.pos[0]?4:2;case ve:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ze:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},jf=([e,t],n)=>[no([e,t-1],n),no([e+1,t],n),no([e,t+1],n),no([e-1,t],n)],no=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,ir=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=no([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},xd=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]))],or=(e,t)=>{let n=t.get(e);return n&&Pe(n)?n:null},on=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>bs(a,kf(ws(e[0]),-1)));return(o<-Dn||o>Dn||r<-Dn||r>Dn||o+s[s.length-1][0]<-Dn||o+s[s.length-1][0]>Dn||r+s[s.length-1][1]<-Dn||r+s[s.length-1][1]>Dn)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...md(s)}),s=s.map(([a,l])=>Z(tr(a,-1e6,1e6),tr(l,-1e6,1e6))),{points:s,x:tr(o,-1e6,1e6),y:tr(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...md(s),startIsSpecial:n,endIsSpecial:i}},Ms=e=>{if(e.length>1){let t=Math.abs(e[0][1]-e[1][1])<Math.abs(e[0][0]-e[1][0]);return e.filter((n,i)=>{if(i===0||i===e.length-1)return!0;let o=e[i+1],r=Math.abs(n[1]-o[1])<Math.abs(n[0]-o[0]);return t===r?(t=r,!1):(t=r,!0)})}return e},Ts=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return ys(i,t)>Ps}):e,Vf=e=>{switch(e){case 0:return qe;case 1:return Ee;case 2:return ve}return ze},fd=(e,t,n,i,o,r,s,a,l=!0,d=!0)=>a?l&&r&&s?As(e,r,t,s,o,void 0,d):i:r?_e(n||[0,0],r,s??Gf([r])):i,hd=(e,t,n,i,o,r)=>yd(e,t,n,n&&ut(n,o,Array(4).fill(tn(n,o,e))),i,o,r),gd=(e,t,n,i)=>rn(e,n,t,i),Ed=(e,t)=>e[0]===t[0]&&e[1]===t[1],bd=(e,t=Ps)=>e.slice(1).map((n,i)=>Math.abs(n[0]-e[i][0])<t||Math.abs(n[1]-e[i][1])<t).every(Boolean);var He=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;X(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...Ii({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Kf(r),...n});for(let l in n){let d=n[l];if(typeof d<"u"){if(e[l]===d&&(typeof d!="object"||d===null||l==="groupIds"||l==="scale"))continue;if(l==="scale"){let c=e[l],u=d;if(c[0]===u[0]&&c[1]===u[1])continue}else if(l==="points"){let c=e[l],u=d;if(c.length===u.length){let p=!1,m=c.length;for(;--m;){let h=c[m],f=u[m];if(h[0]!==f[0]||h[1]!==f[1]){p=!0;break}}if(!p)continue}}e[l]=d,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof a<"u"||typeof r<"u")&&Qe.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Ds(),e.updated=vs()),e},Me=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Ds(),updated:vs()}},Ls=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Ds(),e.updated=vs(),e);M();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as xh,ARROW_LABEL_WIDTH_FRACTION as bh,BOUND_TEXT_PADDING as an,DEFAULT_FONT_SIZE as yh,STICKY_NOTE_BODY_INSET_Y as wh,STICKY_NOTE_PADDING as Rs,TEXT_ALIGN as Ad,VERTICAL_ALIGN as Dd,getFontString as cr,isProdEnv as Ph,invariant as Sh}from"@excalidraw/common";import{pointFrom as Gs,pointRotateRads as Ih}from"@excalidraw/math";M();var oo={},wd=(e,t)=>{let n=oo[e]||(oo[e]={height:t});return n.height=t,n},Pd=e=>{oo[e]&&delete oo[e]},j1=e=>oo[e]?.height??null;M();import{BOUND_TEXT_PADDING as sr,DEFAULT_FONT_SIZE as Zf,DEFAULT_FONT_FAMILY as qf,getFontString as Qf,isTestEnv as Jf,normalizeEOL as eh}from"@excalidraw/common";var Ue=(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=th(i,o,n);return{width:Td(i,t),height:r}},Sd="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),Id=(e,t)=>{let n=nh(e);return n===0?Ue(Sd.split("").join(`
|
|
4
|
+
`),e,t).width+sr*2:n+sr*2},ar=(e,t)=>Ue("",e,t).width+sr*2,q1=()=>Td(Sd,Qf({fontSize:Zf,fontFamily:qf}))>0,ro=e=>eh(e).replace(/\t/g," "),ks=e=>ro(e).split(`
|
|
5
|
+
`),Q1=e=>{let t=ks(e.text).length;return e.height/t/e.fontSize},lr=(e,t)=>e*t,Md=(e,t)=>lr(e,t)+sr*2,rr,J1=e=>{rr=e},Bs=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 Jf()?r*10:r}},Bn=(e,t)=>(rr||(rr=new Bs),rr.getLineWidth(e,t)),Td=(e,t)=>{let n=ks(e),i=0;return n.forEach(o=>{i=Math.max(i,Bn(o,t))}),i},th=(e,t,n)=>{let i=ks(e).length;return lr(t,n)*i},Mi=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=Bn(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),eS=e=>{let t=Mi.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},nh=e=>{let t=Mi.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};M();import{isDevEnv as ih,isTestEnv as oh}from"@excalidraw/common";var Cs,dr,Ns,rS=e=>(Cs||(Cs=de.class(...Object.values(sn))),Cs.test(e)),rh=()=>{if(!dr)try{dr=ah()}catch{dr=sh()}return dr},Os=()=>(Ns||(Ns=lh()),Ns),Pt={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},sn={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},ti={FLAG:/\p{RI}\p{RI}/u,JOINER:/(?:\p{Emoji_Modifier}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?/u,ZWJ:/\u200D/u,ANY:/[\p{Emoji}]/u,MOST:/[\p{Extended_Pictographic}\p{Emoji_Presentation}]/u},sh=()=>de.or(Os(),Se.On(Pt.HYPHEN,Pt.WHITESPACE,sn.CHAR)),ah=()=>de.or(Os(),Se.Before(Pt.WHITESPACE).Build(),Se.After(Pt.WHITESPACE,Pt.HYPHEN).Build(),Se.Before(sn.CHAR,sn.CURRENCY).NotPrecededBy(Pt.OPENING,sn.OPENING).Build(),Se.After(sn.CHAR).NotFollowedBy(Pt.HYPHEN,Pt.CLOSING,sn.CLOSING).Build(),Se.BeforeMany(sn.OPENING).NotPrecededBy(Pt.OPENING).Build(),Se.AfterMany(sn.CLOSING).NotFollowedBy(Pt.CLOSING).Build(),Se.AfterMany(Pt.CLOSING).FollowedBy(Pt.OPENING).Build()),lh=()=>de.group(de.or(ti.FLAG,de.and(ti.MOST,ti.JOINER,de.build(`(?:${ti.ZWJ.source}(?:${ti.FLAG.source}|${ti.ANY.source}${ti.JOINER.source}))*`)))),de={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>de.build(de.join(...e)),or:(...e)=>de.build(e.map(t=>t.source).join("|")),group:(...e)=>de.build(`(${de.join(...e)})`),class:(...e)=>de.build(`[${de.join(...e)}]`)},Se={On:(...e)=>{let t=de.join(...e);return de.build(`([${t}])`)},Before:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?=[${t}])`);return Se.Chain(n)},After:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<=[${t}])`);return Se.Chain(n)},BeforeMany:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<![${t}])(?=[${t}])`);return Se.Chain(n)},AfterMany:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<=[${t}])(?![${t}])`);return Se.Chain(n)},NotBefore:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?![${t}])`);return Se.Chain(n)},NotAfter:(...e)=>{let t=de.join(...e),n=()=>de.build(`(?<![${t}])`);return Se.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=Se.After(...t).Build(),o=()=>de.and(i,n);return Se.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=Se.Before(...t).Build(),o=()=>de.and(n,i);return Se.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=Se.NotAfter(...t).Build(),o=()=>de.and(i,n);return Se.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=Se.NotBefore(...t).Build(),o=()=>de.and(n,i);return Se.Chain(o)}})},dh=e=>{let t=rh();return e.normalize("NFC").split(t).filter(Boolean)},St=(e,t,n)=>uh(e,t,n).map(i=>i.text).join(`
|
|
6
|
+
`),ch=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}})},uh=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return ch(e);let i=[],o=0;for(let r of e.split(`
|
|
8
|
+
`))Bn(r,t)<=n?i.push({text:r,start:o,end:o+r.length}):i.push(...mh(r,t,n,o)),o+=r.length+1;return i},mh=(e,t,n,i)=>{let o=[],r=dh(e),s="",a=i,l=i,d=0,c=i,u=0;for(;u<r.length;){let p=r[u],m=c,h=m+p.length,f=s+p,g=gh(p)?d+Mi.calculate(p,t):Bn(f,t);if(/\s/.test(p)||g<=n){s||(a=m),s=f,l=h,d=g,c=h,u++;continue}if(s)o.push(hh(s,a,l)),s="",a=m,l=m,d=0;else{let E=ph(p,t,n,m),x=E[E.length-1]??{text:"",start:m,end:m},b=E.slice(0,-1);o.push(...b),s=x.text,a=x.start,l=x.end,d=Bn(x.text,t),c=h,u++}}if(s){let p=fh(s,a,l,t,n);o.push(p)}return o},ph=(e,t,n,i)=>{if(Os().test(e))return[{text:e,start:i,end:i+e.length}];Eh(e);let o=[],r=Array.from(e),s="",a=i,l=i,d=0,c=i;for(let u of r){let p=c,m=p+u.length,h=Mi.calculate(u,t),f=d+h;if(f<=n){s||(a=p),s=s+u,l=m,d=f,c=m;continue}s&&o.push({text:s,start:a,end:l}),s=u,a=p,l=m,d=h,c=m}return s&&o.push({text:s,start:a,end:l}),o},fh=(e,t,n,i,o)=>{if(!(Bn(e,i)>o))return{text:e,start:t,end:n};let[,s,a]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],l=Bn(s,i);for(let d of Array.from(a)){let c=Mi.calculate(d,i),u=l+c;if(u>o)break;s=s+d,l=u}return{text:s,start:t,end:n-(e.length-s.length)}},hh=(e,t,n)=>{let i=e.trimEnd();return{text:i,start:t,end:n-(e.length-i.length)}},gh=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Eh=e=>{if((oh()||ih())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var Ti=(e,t,n)=>{let i=n.getNonDeletedElementsMap();if(t&&ye(t)){Ai(t,n,{text:e});return}let o;Ph()||Sh(!t||!W(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?W(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?kt(t,e):e.width,r.text=St(e.originalText,cr(e),o));let s=Ue(r.text,cr(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=so(t,e),l=kt(t,e);if(!W(t)&&s.height>a){let p=Fs(s.height,t.type);n.mutateElement(t,{height:p}),wd(t.id,p)}if(s.width>l){let p=Fs(s.width,t.type);n.mutateElement(t,{width:p})}let d={...e,...r},{x:c,y:u}=ii(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},ni=(e,t,n,i=!1,o=!1,r=!1)=>{if(ye(e)){Ai(e,t,{bindings:!1});return}let s=t.getNonDeletedElementsMap();if(!Ct(e))return;Pd(e.id);let l=q(e,s);if(l&&l.text){if(!e)return;let d=l.text,c=l.height,u=l.width,p=kt(e,l),m=so(e,l),h=e.height;if(i||n!=="n"&&n!=="s"){d&&(d=St(l.originalText,cr(l),p));let f=Ue(d,cr(l),l.lineHeight);c=f.height,u=f.width}if(c>m){h=Fs(c,e.type);let f=(n==="n"||n==="ne"||n==="nw")!==r;t.mutateElement(e,{height:h,...!W(e)&&ao(e,h,o?"center":f?"bottom":"top")})}t.mutateElement(l,{text:d,width:u,height:c}),W(e)||t.mutateElement(l,ii(e,l,s))}},ii=(e,t,n)=>{if(W(e))return R.getBoundTextElementPosition(e,t,n);let i=zs(e),o=so(e,t),r=kt(e,t),s,a;if(t.verticalAlign===Dd.TOP)a=i.y;else if(t.verticalAlign===Dd.BOTTOM)a=i.y+(o-t.height);else if(ye(e)){let d=e.height-Rs*2;a=i.y+Math.min((d-t.height)/2,o-t.height)}else a=i.y+(o/2-t.height/2);t.textAlign===Ad.LEFT?s=i.x:t.textAlign===Ad.RIGHT?s=i.x+(r-t.width):s=i.x+(r/2-t.width/2);let l=e.angle??0;if(l!==0){let d=ye(e)?Gs(e.x+e.width/2,e.y+e.height/2):Gs(i.x+r/2,i.y+o/2),c=Gs(s+t.width/2,a+t.height/2),[u,p]=Ih(c,d,l);return{x:u-t.width/2,y:p-t.height/2}}return{x:s,y:a}},Ct=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,q=(e,t)=>{if(!e)return null;let n=Ct(e);if(n){let i=t.get(n)||null;return i&&!$e(i)&&console.error("[NONDELETED][INVARIANT] Bound text element `isDeleted: true` which is not expected."),i}return null},Be=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,xS=(e,t)=>{if(!W(e))return{x:e.x+e.width/2,y:e.y+e.height/2};let n=R.getBoundTextElementCenter(e,t);return{x:n[0],y:n[1]}},zs=e=>{let t=ye(e)?Rs:an,n=t,i=t;return e.type==="ellipse"&&(n+=e.width/2*(1-Math.sqrt(2)/2),i+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(n+=e.width/4,i+=e.height/4),{x:e.x+n,y:e.y+i}},bS=(e,t)=>W(t)?0:t?t.angle:e.angle,yS=(e,t,n)=>{if(W(e))return R.getBoundTextElementPosition(e,t,n)},_s=(e,t)=>{if(!e.containerId)return e;let n=t.get(e.containerId);return!n||!W(n)?e:{...e,...R.getBoundTextElementPosition(n,e,t)}},wS=(e,t)=>e.some(n=>{if(pe(n)){let i=Be(n,t);return!W(i)}return!1}),PS=(e,t)=>e.some(n=>{if(pe(n)){let i=Be(n,t);return!W(i)}return j(n)}),Mh=new Set(["rectangle","stickynote","ellipse","diamond","arrow"]),SS=e=>Mh.has(e.type),Fs=(e,t)=>{e=Math.ceil(e);let n=an*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},kt=(e,t)=>{let{width:n}=e;if(W(e)){let i=(t?.fontSize??yh)*xh;return Math.max(bh*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-an*2:e.type==="diamond"?Math.round(n/2)-an*2:n-(ye(e)?Rs:an)*2},so=(e,t)=>{let{height:n}=e;return ye(e)?Math.max(0,n-wh):W(e)?n-an*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-an*2:e.type==="diamond"?Math.round(n/2)-an*2:n-an*2},IS=(e,t=`
|
|
9
9
|
|
|
10
|
-
`)=>e.reduce((i,o)=>(oe(o)&&i.push(o.text),i),[]).join(t);I();import{curvePointDistance as hs,distanceToLineSegment as gs,pointRotateRads as Es}from"@excalidraw/math";import{ellipse as zp,ellipseDistanceFromPoint as _p}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 Hp(e,t,n);case"diamond":return Wp(e,t,n);case"ellipse":return Up(e,t,n);case"line":case"arrow":case"freedraw":return Yp(e,t,n)}},Hp=(e,t,n)=>{let i=re(e,t),o=Es(n,i,-e.angle),[r,s]=yn(e);return Math.min(...r.map(a=>gs(o,a)),...s.map(a=>hs(a,o)))},Wp=(e,t,n)=>{let i=re(e,t),o=Es(n,i,-e.angle),[r,s]=Pn(e);return Math.min(...r.map(a=>gs(o,a)),...s.map(a=>hs(a,o)))},Up=(e,t,n)=>{let i=re(e,t);return _p(Es(n,i,-e.angle),zp(i,e.width/2,e.height/2))},Yp=(e,t,n)=>{let[i,o]=No(e,t);return Math.min(...i.map(r=>gs(n,r)),...o.map(r=>hs(r,n)))};I();var hi=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw"||e==="autoshape"||e==="bucketfill",nP=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable"||e==="autoshape",iP=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="autoshape",oP=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line"||e==="autoshape",rP=e=>e==="freedraw",$l=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",sP=e=>e==="arrow",aP=e=>e==="arrow";var Yo=e=>{if(e.type==="arrow")return!1;let t=hi(e.type)&&!Jl(e.backgroundColor)||_t(e)||Go(e)||oe(e);return e.type==="line"?t&&Tt(e.points):e.type==="freedraw"?t&&Tt(e.points):t||ke(e)},xs=null,Vl=null,bs=1/0,ws=!1,Zl=!1,Kl=null,qp=(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(xs&&nd(e,xs)&&(ws?bs<=n:bs>=n)&&r===Zl&&qp(o,Kl)){let u=Vl?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return ws}let s=o?ys(De(o.x-n,o.y-n),e,De(o.x+o.width+n,o.y+o.height+n)):!1,a=ue(t,i,!0);if(!id(e,a,t.angle,n)&&!s)return!1;let c=(r||Yo(t))&&it(e,t,i)||ql(e,t,i,n)||s;return xs=e,Vl=new WeakRef(t),bs=n,Zl=r,Kl=o,ws=c,c},id=(e,t,n,i=0)=>{let o=n===0?e:ht(e,an(t),-n);return ys(De(t[0]-i,t[1]-i),o,De(t[2]+i,t[3]+i))},Qp=(e,t,n,i=0)=>{let o=ue(t,n,!0);return id(e,o,t.angle,i)},PP=(e,t)=>!Ht(e)&&!Jp(e.point,e.element,t)&&Qp(e.point,e.element,t),Jp=(e,t,n)=>{let i=de(t,n);if(!i)return!1;let o=K(t)?{...i,...R.getBoundTextElementPosition(t,i,n)}:i;return it(e,o,n)},od=(e,[t,n],i,o=0)=>{let r=De(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,Qi(re(e,i),r)),u=Ut(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},Xo=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(Ql(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),we(s,!1)&&od(s,e,n,i)&&(o.push(s),hi(s.type)&&!Jl(s.backgroundColor)))break}return o},sn=(e,t,n,i)=>{let o=Xo(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()},rd=(e,t,n,i,o)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];Ql(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),we(l,!1)&&od(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)<=ve(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 tf(e,t,n,i,o);case"diamond":return nf(e,t,n,i,o);case"ellipse":return of(e,t,n,i);case"line":case"freedraw":case"arrow":return ef(e,n,t,o)}},sd=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=jo(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!gt(a,l))continue;let d=ed(s,t);if(d.length>0){for(let c of d)n.push(ht(c,i,o));if(r)return n}}return n},ad=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=td(s,t);if(a&&(n.push(ht(a,i,o)),r))return n}return n},ef=(e,t,n,i=!1)=>{let[o,r]=No(e,n),s=[];for(let a of o){let l=td(a,t);if(l&&(s.push(l),i))return s}for(let a of r){let l=jo(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=ed(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),i))return s}return s},tf=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=ht(n[0],r,-e.angle),a=ht(n[1],r,-e.angle),l=Qi(s,a),[d,c]=yn(e,i),u=[];return ad(d,l,u,r,e.angle,o),o&&u.length>0||sd(c,l,u,r,e.angle,o),u},nf=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=ht(n[0],r,-e.angle),a=ht(n[1],r,-e.angle),l=Qi(s,a),[d,c]=Pn(e,i),u=[];return ad(d,l,u,r,e.angle,o),o&&u.length>0||sd(c,l,u,r,e.angle,o),u},of=(e,t,n,i=0)=>{let o=re(e,t),r=ht(n[0],o,-e.angle),s=ht(n[1],o,-e.angle);return Kp(Zp(o,e.width/2+i,e.height/2+i),Qi(r,s)).map(a=>ht(a,o,e.angle))},ql=(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(!ys(De(i,o),e,De(r,s)))return!1;let a=De((i+r)/2,(o+s)/2),l=Xp(Vp($p(jp(e,a,.1)),Math.max(t.width,t.height)*2),a),d=Qi(e,l);return ot(t,n,d).filter((u,m,p)=>p.findIndex(h=>nd(h,u))===m).length%2===1},Ps=(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,M]=pi(s);return[De(l+f,d+g-a),De(l+E+a,d+x),De(l+b,d+y+a),De(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[De(f,g-x-a),De(f+E+a,g),De(f,g+x+a),De(f-E-a,g)].map(y=>ht(y,p,m))}return[De(l-a,d-a),De(l+c+a,d-a),De(l+c+a,d+u+a),De(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 ld,isDevEnv as rf,isTestEnv as sf}from"@excalidraw/common";import{pointFrom as Sn,pointFromVector as $o,pointRotateRads as Vo,pointScaleFromOrigin as Zo,pointsEqual as af,triangleIncludesPoint as Is,vectorCross as rt,vectorFromPoint as se,vectorScale as Ko}from"@excalidraw/math";var he=[1,0],Be=[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?Be:Ze},st=(e,t)=>Xt(se(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),DP=e=>!at(e),lf=(e,t,n)=>{let i=an(t);(rf()||sf())&&(ld(e.width>0&&e.height>0,"Diamond element has no width or height"),ld(!af(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=$o(Ko(se(Vo(Sn(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=$o(Ko(se(Vo(Sn(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=$o(Ko(se(Vo(Sn(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=$o(Ko(se(Vo(Sn(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(rt(se(n,r),se(r,s))<=0&&rt(se(n,r),se(r,l))>0)return st(r,i);if(rt(se(n,s),se(s,a))<=0&&rt(se(n,s),se(s,r))>0)return st(s,i);if(rt(se(n,a),se(a,l))<=0&&rt(se(n,a),se(a,s))>0)return st(a,i);if(rt(se(n,l),se(l,r))<=0&&rt(se(n,l),se(l,a))>0)return st(l,i);if(rt(se(n,i),se(r,i))<=0&&rt(se(n,i),se(s,i))>0){let c=e.width>e.height?r:s;return st(c,i)}else if(rt(se(n,i),se(s,i))<=0&&rt(se(n,i),se(a,i))>0){let c=e.width>e.height?a:s;return st(c,i)}else if(rt(se(n,i),se(a,i))<=0&&rt(se(n,i),se(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)},gi=(e,t,n)=>{let o=an(t);if(e.type==="diamond")return lf(e,t,n);let r=Zo(Sn(t[0],t[1]),o,2),s=Zo(Sn(t[2],t[1]),o,2),a=Zo(Sn(t[0],t[3]),o,2),l=Zo(Sn(t[2],t[3]),o,2);return Is([r,s,o],n)?Ze:Is([s,l,o],n)?he:Is([l,a,o],n)?Be:Ne},Ss=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];I();import{getSizeFromPoints as Af,randomInteger as Os,getUpdatedTimestamp as Ns}from"@excalidraw/common";I();import{clamp as qo,pointDistance as Ts,pointFrom as V,pointScaleFromOrigin as df,pointsEqual as eo,pointTranslate as As,vector as jt,vectorCross as Qo,vectorFromPoint as Ds,vectorScale as cf}from"@excalidraw/math";import{BinaryHeap as uf,invariant as Ei,isAnyTrue as mf,getSizeFromPoints as dd,isDevEnv as pf,arrayToMap as ff}from"@excalidraw/common";var vs=1,ce=40,hf=(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(Ts(l[a-2],l[a-1])<vs){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?ln(Cs(Gs(Ls(e,Bs(e,t,o.map(s=>V(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(pf()&&Ei(gd(o),"Invalid elbow points with fixed segments"),ln(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}},gf=(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}=Bs({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}=ln(Cs(Gs(Ls(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,Ss(_)))return S.forEach(W=>{W.index>F&&(W.index+=1)}),[A,A]}return[A]});return ln(T,S,!1,!1)},Ef=(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=Ts(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,Be))?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,Be))?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]&&!eo(m[p],m[p-1])?Lt(m[p-1],m[p]):void 0,x=m[h+1]&&!eo(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 ln(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)},xf=(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(Ds(g,E)));if(a&&x===b){let y=x?fe(i,he):fe(i,Be);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,Be);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),ln(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)},Mn=1e6,xi=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};N.PROD||(Ei(!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)"),Ei(!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"),Ei(!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"),Ei(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"),Ei(n.fixedSegments?.find(w=>w.index===1&&eo(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&eo(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&&er(d.elementId,t),m=c&&er(c.elementId,t),p=gd(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 ln(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}=Bs({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?ln(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?hf(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,M)=>eo(w,e.points[M]??V(1/0,1/0)))&&p?{}:o.length===0?ln(Cs(Gs(Ls(e,{startHeading:h,endHeading:f,startGlobalPoint:g,endGlobalPoint:E,hoveredStartElement:x,hoveredEndElement:b,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?gf(e,o,t):n.points?n.points&&n.fixedSegments?n:xf(e,r,o,h,f,g,E,x,b):Ef(e,o,h,f,x,b)},Bs=(e,t,n,i)=>{let o=As(n[0],jt(e.x,e.y)),r=As(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=pd(o,t,w,i?.zoom)||null,a=pd(r,t,w,i?.zoom)||null}else s=e.startBinding&&er(e.startBinding.elementId,t)||null,a=e.endBinding&&er(e.endBinding.elementId,t)||null;let l=ud({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),d=ud({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=md(l,d,s,o,t,i?.zoom),u=md(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,An(c,e.startArrowhead?ve(s,{elbowed:!0})*6:ve(s,{elbowed:!0})*2,1)):m,f=a?lt(a,t,An(u,e.endArrowhead?ve(a,{elbowed:!0})*6:ve(a,{elbowed:!0})*2,1)):p,g=Yt(l,a?lt(a,t,An(u,ce,ce)):p)||Yt(d,s?lt(s,t,An(c,ce,ce)):m),E=hd(g?[m,p]:[h,f]),x=yf(g?m:h,g?p:f,E,g?An(c,!s&&!a?0:ce,0):An(c,!s&&!a?0:ce-(e.startArrowhead?Qn*6:Qn*2),ce),g?An(u,!s&&!a?0:ce,0):An(u,!s&&!a?0:ce-(e.endArrowhead?Qn*6:Qn*2),ce),g,s&<(s,t),a&<(a,t)),b=cd(x[0],c,l),y=cd(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}},Ls=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Pf(n,i||o,r,s||a,l,d),m=i&&Jo(i,u),p=s&&Jo(s,u),h=Jo(a,u);h&&c&&(h.closed=!0);let f=Jo(o,u);f&&e.startBinding&&(f.closed=!0);let g=m&&p&&(Yt(m.pos,n[1])||Yt(p.pos,n[0])),E=bf(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},An=(e,t,n)=>{switch(e){case Ze:return[t,n,n,n];case he:return[n,t,n,n];case Be:return[n,n,t,n]}return[n,n,n,t]},bf=(e,t,n,i,o,r)=>{let s=Ms(e.pos,t.pos),a=new uf(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return wf(e,l);l.closed=!0;let d=Sf(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=df(u.pos,l.pos,.5);if(mf(...r.map(y=>Yt(m,y))))continue;let p=Mf(c),h=l.parent?Xt(Ds(l.pos,l.parent.pos)):i,f=Ss(h);if(fe(f,p)||fd(e.addr,u.addr)&&fe(p,i)||fd(t.addr,u.addr)&&fe(p,o))continue;let E=h!==p,x=l.g+Ms(u.pos,l.pos)+(E?Math.pow(s,3):0),b=u.visited;if(!b||x<u.g){let y=If(u,t,p,o);u.visited=!0,u.parent=l,u.h=Ms(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},wf=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},Ms=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),yf=(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=hd([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 Qo(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 Qo(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 Qo(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 Qo(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]},Pf=(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]})))}},cd=(e,t,n)=>{switch(t){case Ze:return V(n[0],e[1]);case he:return V(e[2],n[1]);case Be:return V(n[0],e[3])}return V(e[0],n[1])},If=(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 Be: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 Be: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 Be: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===Be)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 Be: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},Sf=([e,t],n)=>[Ji([e,t-1],n),Ji([e+1,t],n),Ji([e,t+1],n),Ji([e-1,t],n)],Ji=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Jo=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=Ji([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},hd=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]))],er=(e,t)=>{let n=t.get(e);return n&&we(n)?n:null},ln=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>As(a,cf(Ds(e[0]),-1)));return(o<-Mn||o>Mn||r<-Mn||r>Mn||o+s[s.length-1][0]<-Mn||o+s[s.length-1][0]>Mn||r+s[s.length-1][1]<-Mn||r+s[s.length-1][1]>Mn)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...dd(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,...dd(s),startIsSpecial:n,endIsSpecial:i}},Cs=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},Gs=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Ts(i,t)>vs}):e,Mf=e=>{switch(e){case 0:return Ze;case 1:return he;case 2:return Be}return Ne},ud=(e,t,n,i,o,r,s,a=!0,l=!0)=>s?a&&o&&r?ks(e,o,t,r,void 0,l):i:o?He(n||[0,0],o,r??ff([o])):i,md=(e,t,n,i,o,r)=>Ed(e,t,n,n&<(n,o,Array(4).fill(Ut(n,o,e))),i,o,r),pd=(e,t,n,i)=>sn(e,n,t,Dt(i)),fd=(e,t)=>e[0]===t[0]&&e[1]===t[1],gd=(e,t=vs)=>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 Fe=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;j(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...xi({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Af(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??Os(),e.updated=Ns()),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??Os(),updated:Ns()}},xd=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Os(),e.updated=Ns(),e);var Md=5,Qn=5,Cf=10,no=10/1.5,or=1,ve=(e,t)=>(t.elbowed?Qn:Md)+e.strokeWidth/2,Dt=e=>{let t=Math.max(Md,15),n=e?.value&&e.value<1?e.value:1;return ir(t/(n*1.5),t,t*2)},$t=e=>e.isBindingEnabled,Gf=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=zs(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0}),d=r.isMidpointSnappingEnabled&&!s?.angleLocked&&!r.gridModeEnabled;if(bd(e,a,"start",o,r.isBindingEnabled,d),bd(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}},bd=(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)},Ad=(e,t,n,i,o)=>{dn(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;dn(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=sn(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}},kf=(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=sn(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(Xo(h,i,n).find(b=>b.id===E.elementId)){let b=n.get(e.startBinding.elementId);return dn(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);dn(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??q(e.x,e.y)},y=f&&Ps(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}}dn(!1,"New arrow creation should not reach here")},wd=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=sn(e,o,i),m=n?Xo(e,o,i).some(g=>g.id===n.elementId):!1,p=n?i.get(n.elementId):null,h=m&&p?Df(p.backgroundColor):!1,f=u&&p&&Ps(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}},zs=(e,t,n,i,o,r,s,a)=>Tf("COMPLEX_BINDINGS")?Of(e,t,o,r,s,a):Td(e,t,n,i,o,r,s,a),Td=(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(j(e))return Ad(e,t,o,r,a?.zoom);let h=c?e.endBinding:e.startBinding,f=t.get(c?0:d)?.point;dn(f,`Local point must be defined for ${c?"start":"end"} dragging`);let g=R.getPointGlobalCoordinates(e,f,o),E=sn(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&&He(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?Bf(Rs(s.selectedLinearElement.initialState.origin[0],s.selectedLinearElement.initialState.origin[1],a.gridSize)):b?He(h.fixedPoint,b,o):R.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:E,focusPoint:u?g:b?He(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:as(e,a?.angleLocked?g:s.gridModeEnabled?Hf(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:as(e,T,b,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||T})),{start:c?S:k,end:u?S:k}},Of=(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(j(e))return Ad(e,t,n,i);if(r?.newArrow){let{start:p,end:h}=kf(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;dn(p,"Local point must be defined for start dragging");let h=R.getPointGlobalCoordinates(e,p,n),{current:f,other:g}=wd(h,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:f,end:g}}if(c){let p=t.get(l)?.point;dn(p,"Local point must be defined for end dragging");let h=R.getPointGlobalCoordinates(e,p,n),{current:f,other:g}=wd(h,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:g,end:f}}return{start:u,end:m}},a1=(e,t,n)=>{e.forEach(i=>{Gf(i,new Map,1/0,1/0,t,n)})},Dd=(e,t,n,i,o)=>{o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:n}),Sd(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;j(e)?d={elementId:t.id,mode:"orbit",...Wf(e,t,i,l,s,a)}:d={elementId:t.id,mode:n,...yi(e,t,i,l,r)},Dd(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=Ff(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),rr(r,e,a=>{if(a&&!Ve(a)&&console.error("[NONDELETED][INVARIANT] updateBoundElements(): `isDeleted: true` in visitor"),!X(a)||!Ve(a)||!Nf(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=sr(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=de(a,r);u&&!u.isDeleted&&qn(a,t,!1)})},yd=(e,t,n,i,o)=>{dn(!j(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=Td(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)}},l1=(e,t,n,i)=>{if(X(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&yd(e,"startBinding",o,t,n),e.endBinding&&yd(e,"endBinding",o,t,n)}else je(e,t,{...i,changedElements:new Map([[e.id,e]])})},Nf=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,Ff=e=>new Set((e||[]).map(t=>t.id)),Ed=(e,t,n,i,o,r,s)=>{let a=Xt(wi(t,e));return!n||!i?a:Rf(o,n,r,s)?gi(n,i,e):Xt(wi(e,re(n,r)))},Rf=(e,t,n,i)=>{let o=Ut(t,n,e),r=Dt(i);return o>r?null:o},ks=(e,t,n,i,o,r=!0)=>{let s=j(e),a=R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return a;let l=Al(t)&&s?zf(e,t,i,a):a,d=o&&!s?o[1]:R.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),c=ve(t,e),u=lt(t,i),m=an(u),p=null;if(s){let h=at(gi(t,u,a)),g=(r?_s(t,i,l,.05,e):void 0)||a,E=q(h?m[0]:g[0],h?g[1]:m[1]),x=o??bi(E,tr(nr(Fs(wi(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=bi(b,tr(nr(Fs(wi(g,b)),Math.max(t.width,t.height)*2),b));p=ot(t,i,y,Qn).sort(xt)[0]}}else{let h=o;if(!h){let f=nr(Fs(wi(l,d)),Tn(l,d)+Math.max(t.width,t.height)+c*2);h=o??bi(tr(f,d),tr(nr(f,-1),d))}p=Tn(l,d)<1?l:ot(t,i,h,c).sort((f,g)=>xt(f,d)-xt(g,d))[0]}return!p||xt(l,p)<vf?l:p},zf=(e,t,n,i)=>{let o=re(t,n),r=ge(i,o,-t.angle),s=ve(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},_s=(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=ge(n,c,-d),m=o?ve(e,o):0,p=ir(i*l,5,80),h=ir(i*a,5,80);if(!(Tn(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(Tn(g,u)<Math.max(h,p))return ge(g,c,d);if(Tn(E,u)<Math.max(h,p))return ge(E,c,d);if(Tn(x,u)<Math.max(h,p))return ge(x,c,d);if(Tn(b,u)<Math.max(h,p))return ge(b,c,d)}}},_f=(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:He(We(i.fixedPoint),o,n),binding:i,mode:i.mode}},Hf=(e,t,n,i,o,r)=>{if(!i)return e;let s=lt(t,n),a=r&&(t.type==="ellipse"||t.type==="diamond")?Xt(wi(r,e)):gi(t,s,e),l=ve(t,o),d=Math.max(t.width,t.height)+l*2,c=an(s),u=Math.abs(a[0]),m=Math.abs(a[1]);if(u>=m){let[,g]=Rs(e[0],e[1],i),E=bi(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]=Rs(e[0],e[1],i),h=bi(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])},Pd=e=>e.width*e.height,Ct=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||Lf(e.points[e.points.length-1],q(0,0)))return null;let s=He(We(n.fixedPoint),i,o);if(n.mode==="inside")return R.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=_f(e,t==="startBinding"?"endBinding":"startBinding",o),d=R.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&bi(s,c),m=a&&u&&ot(a,o,u,ve(a,e)).sort((b,y)=>xt(b,s)-xt(y,s))[0],p=u&&ot(i,o,u,ve(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&&Pd(a)<Pd(i)*2&&Ht({element:a,point:p,elementsMap:o,threshold:ve(a,e),overrideShouldTestInside:!0}))return R.createPointAt(e,o,g[0],g[1],null);let x=Tn(a&&(m||l)||d,p||s)<=Cf;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)},Wf=(e,t,n,i,o=!0,r=!0)=>{let s=[t.x,t.y,t.x+t.width,t.y+t.height],a=o?ks(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<or||t.height<or)return{fixedPoint:We([.5,.5])};let c=ve(t,e);return{fixedPoint:We([(d[0]-t.x)/Math.max(t.width,c),(d[1]-t.y)/Math.max(t.height,c)])}},yi=(e,t,n,i,o)=>{let r=o||R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=re(t,i),a=ge(r,s,-t.angle);if(t.width<or||t.height<or)return{fixedPoint:We([.5,.5])};let l=ve(t,e),d=(a[0]-t.x)/Math.max(t.width,l),c=(a[1]-t.y)/Math.max(t.height,l);return{fixedPoint:We([d,c])}},vd=(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})}j(i)&&Object.assign(i,xi(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},d1=(e,t)=>{let n=Sd(e);for(let i of t)Dn.unbindAffected(n,i,(o,r)=>Fe(o,n,r)),vn.unbindAffected(n,i,(o,r)=>Fe(o,n,r))},to=(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},Bd=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),rr=(e,t,n)=>{we(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},sr=(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(X(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},Dn=class{static unbindAffected(t,n,i){n&&sr(t,n,o=>{!o||o.isDeleted||rr(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:to(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||sr(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(X(n)&&i(o,{boundElements:to(o.boundElements,new Set,new Array(n))}),oe(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:to(o.boundElements,new Set,new Array(n))}))))})}},vn=class{static unbindAffected(t,n,i){n&&rr(t,n,o=>{!o||o.isDeleted||sr(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||rr(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:to(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:to(n.boundElements,new Set([o.id]))})))})}},He=(e,t,n)=>{let[i,o]=We(e);return ge(q(t.x+t.width*i,t.y+t.height*o),re(t,n),t.angle)},Uf=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?He(e.startBinding.fixedPoint,n,t):q(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?He(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]},Ld=(e,t)=>{let[n,i]=Uf(e,t);return[R.pointFromAbsoluteCoords(e,n,t),R.pointFromAbsoluteCoords(e,i,t)]},Yf=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),Id=10,We=e=>{if(!Yf(e))return[.5001,.5001];let t=1e-4,n=e.map(i=>ir(i,-Id,Id));return Math.abs(n[0]-.5)<t||Math.abs(n[1]-.5)<t?n.map(i=>Math.abs(i-.5)<t?.5001:i):n},Xf=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",jf={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"}]},$f=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}}),Vf=(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=jf[t],d=$f(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},c1=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!we(n))return null;let i=re(n,t),o=Xf(n),r=Vf(We(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=Pn(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]=yn(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),u1=(e,t,n,i,o)=>{Dd(e,t,{elementId:t.id,fixedPoint:We(i),mode:"orbit"},n,o)};var Hs=({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}},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,Gd(t.points[0],H(0,0))||(console.error("Linear element is not normalized",Error().stack),Fe(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=j(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=>!(j(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??_d(m,d.points[c]),h=0,f=0;if(ei(t)){let[M,S]=e._getShiftLockedDelta(d,s,m,H(i,o),t[Jn.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[Jn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());h=M[0]-u[0],f=M[1]-u[1]}let g=null,{positions:E,updates:x}=zd([c],h,f,i,o,s,d,a,n,ei(t),t.altKey,r),b=ei(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}),_e(d,!1)&&$t(n.state)&&(g=x?.suggestedBinding??null),_e(d)&&Fd(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!g||Jf(n.state.suggestedBinding??[],g)))return null;let y=_e(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?Rd(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??_d(f,p.points[m]),x=u.includes(0),b=u.includes(p.points.length-1),y=0,w=0;if(ei(t)&&g){let[v,C]=e._getShiftLockedDelta(p,s,f,H(i,o),t[Jn.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[Jn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=v[0]-h[0],w=v[1]-h[1]}let M=null,{positions:S,updates:T}=zd(u,y,w,i,o,s,p,a,n,ei(t)&&g,t.altKey,r),A=ei(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}),_e(p,!1)&&$t(n.state)&&(x||b)&&(M=T?.suggestedBinding??null),_e(p)&&x!==b&&Fd(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),de(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=_e(p)&&p.startBinding&&s.get(p.startBinding.elementId),D=_e(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&&_e(p)&&L?Rd(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)&&eh(c.points,i.zoom.value)&&(Oe(c)&&o.mutateElement(c,{...Hd(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=de(t,n);if(!j(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(!j(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!j(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&ti(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&&ti(m[u],H(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r,s){if(j(t))return o>=0&&o<t.points.length?ti(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=ti(n,i);if(t.points.length>2&&t.roundness){let[l,d]=Od(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=Kf(d[o])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,i){if(j(t)){dt(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=Cd(t.points[n-1],t.points[n]);return H(t.x+s[0],t.y+s[1])}let[o,r]=Od(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 Cd(s[0],s[1])}if(r.length){let s=r[n-1];return qf(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,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[Jn.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);(f>=0||m)&&(d.hitElement=u);let[g,E,x,b]=Z(u,l),y=(g+x)/2,w=(E+b)/2,M=f>-1&&qe(H(u.x+u.points[f][0],u.y+u.points[f][1]),H(y,w),u.angle),S=f>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(f)?th([...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,arrowOtherEndpointInitialBinding:S?.includes(0)?u.endBinding:u.startBinding},selectedPointsIndices:S,pointerOffset:M?{x:o.x-M[0],y:o.y-M[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Gd(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(ei(t)&&c.length>=2){let p=c[c.length-2],[h,f]=e._getShiftLockedDelta(d,l,p,H(n,i),t[Jn.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[Jn.CTRL_OR_CMD]||j(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(j(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 getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(ti(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=kd(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}=Hs(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}=Hs({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}=Hs({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=j(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&&j(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=ti(a,H(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<Qf/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&&!j(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(j(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=Ws(t,i),d=Ws(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(j(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=kd(o[0],o[1],r),{width:c,height:u}=Wd(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 getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&Fe(n,i,{isDeleted:!0});let r=e.getBoundTextElementCenter(t,i);return{x:r[0]-n.width/2,y:r[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=Jt(o[0]),[s,a,l,d]=io(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&&de(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||!j(a))return t;if(n&&n>0&&n<a.points.length){let l=at(Xt(Zf(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)})}},th=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},zd=(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(!X(s))return{positions:m};let p=e.includes(0),h=e.includes(s.points.length-1),{start:f,end:g}=zs(s,m,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c,gridSize:l.getEffectiveGridSize()});if(j(s)){let W=p?f.element:h?g.element:null;return{positions:m,updates:{suggestedBinding:W?{element:W,midPoint:l.state.isMidpointSnappingEnabled?_s(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,...yi(s,f.element,"start",r,f.focusPoint)},p&&(E.startBinding.mode==="orbit"||!Pi("COMPLEX_BINDINGS"))&&(E.suggestedBinding=f.element?{element:f.element,midPoint:Nd(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,...yi(s,g.element,"end",r,g.focusPoint)},h&&(E.endBinding.mode==="orbit"||!Pi("COMPLEX_BINDINGS"))&&(E.suggestedBinding=g.element?{element:g.element,midPoint:Nd(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"&&Pi("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&&Pi("COMPLEX_BINDINGS")?y.points[0]:w&&l.state.bindMode!=="inside"&&Pi("COMPLEX_BINDINGS")?T:A&&Ct(y,"startBinding",y.startBinding,A,r,p)||y.points[0],B=!(M&&l.state.bindMode!=="inside"&&Pi("COMPLEX_BINDINGS"))&&!!S,k=ti(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)]))}},_d=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);I();import{arrayToMap as Gt}from"@excalidraw/common";import{isPointWithinBounds as Eh,pointFrom as Zs,segmentsIntersectAt as xh}from"@excalidraw/math";I();import{arrayToMap as ah,isShallowEqual as lh}from"@excalidraw/common";I();var nh=(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:Us({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):Zt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Us(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),ih=(e,t)=>Ys(e,t)!=null,Ys=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),oh=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),Yd=(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,...nh(r,n,e)}}}return n.selectedGroupIds},C1=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),rh=(e,t)=>e.groupIds.includes(t),Qe=(e,t)=>{let n=[];for(let i of e.values())rh(i,t)&&n.push(i);return n},sh=(e,t)=>e.groupIds.find(n=>t[n]),G1=(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},k1=(e,t)=>e.filter(n=>!t[n]),O1=(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=de(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},Xd=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},jd=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},$d=e=>e.groupIds.length>0,Vd=(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},ar=(e,t,n)=>{let i=new Map,r=oh(n).length===1&&e.every(s=>ih(n,s));return e.forEach(s=>{if(Ie(s))return;let a,l=sh(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=de(s,t);i.set(a,[...d,s,...c?[c]:[]])}),[...i.values()]};var dh=e=>e.locked||Ie(e),ch=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),uh=e=>{let t=new Set;return e.forEach(n=>{J(n)&&t.add(n.id)}),ch(e,t)},Zd=(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 Kd({elements:e,bounds:[d,c,u,m],elementsMap:n,type:o,shouldIgnoreElementFromSelection:dh,excludeElementsInFrames:i})},j1=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=qd(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},$1=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}(),Zt=(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)&&Bn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},V1=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement&&t.activeTool.type!=="autoshape"?[t.newElement]:Zt(e,t,{includeBoundTextElement:!0}),Us=(e,t)=>lh(t.selectedElementIds,e)?t.selectedElementIds:e,mh=(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,ah(t))}return null},Z1=(e,t,n)=>({selectedLinearElement:mh(e,t),...Ud({editingGroupId:n.editingGroupId,selectedElementIds:uh(e).reduce((i,o)=>(Ie(o)||(i[o.id]=!0),i),{})},t,n,null)}),K1=(e,t)=>t.editingTextElement||e.length===1&&oe(e[0])&&e[0]||null;I();import{arrayToMap as lr}from"@excalidraw/common";import{validateOrderKey as ph,generateNKeysBetween as fh}from"@excalidraw/fractional-indexing";var Xs=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},hh=(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?lr(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(js(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 Xs,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(`
|
|
10
|
+
`)=>e.reduce((i,o)=>(j(o)&&i.push(o.text),i),[]).join(t),vd=.5;var Nh=[0,1.5,8],Oh=.04,Gh=16,Nn=e=>!e||mr(e)?Th.strokeColor:e,Ws=e=>!e||mr(e)?Ah:e,GS=(e,t,n)=>t==="backgroundColor"&&j(e)&&pr(e,n)?n.get(e.containerId)??e:e,FS=(e,t,n,i)=>{if(ye(e))return t==="backgroundColor"?{backgroundColor:Ws(n)}:{strokeColor:Nn(n)};if(t==="strokeColor"&&j(e)&&pr(e,i)){let o=i.get(e.containerId);return{strokeColor:mr(n)?Nn(o?.strokeColor):n}}return t==="backgroundColor"?{backgroundColor:n}:{strokeColor:n}},RS=(e,t)=>{let n=Nd(e),i=new Map;for(let o of e){if(!ye(o)||o.isDeleted)continue;let r=q(o,n);if(!r||r.strokeColor===o.strokeColor)continue;let s=t.get(o.id)?.strokeColor!==o.strokeColor,a=t.get(r.id)?.strokeColor!==r.strokeColor;mr(r.strokeColor)||s&&!a?i.set(r.id,Nn(o.strokeColor)):i.set(o.id,Nn(r.strokeColor))}return i.size?e.map(o=>{let r=i.get(o.id);return r===void 0?o:Me(o,{strokeColor:r})}):e},kn=(e,t)=>(e()*2-1)*t,Cn=(e,t,n)=>{let i=t.x-e.x,o=t.y-e.y,r=Math.hypot(i,o);if(!r)return e;let s=Math.min(n/r,1);return{x:e.x+i*s,y:e.y+o*s}},Ys=e=>e.roundness?Math.min(Math.min(e.width,e.height)*Oh,Gh):0,Fh=(e,{offsetX:t=0,offsetY:n=0,seedOffset:i=0}={})=>{let o=Math.max(0,Math.min(2,Math.round(e.roughness))),r=Math.min(Nh[o],Math.min(e.width,e.height)*.012);if(!r)return[{x:t,y:n},{x:t+e.width,y:n},{x:t+e.width,y:n+e.height},{x:t,y:n+e.height}];let s=Od(e.seed+i);return[{x:t+kn(s,r),y:n+kn(s,r)},{x:t+e.width+kn(s,r),y:n+kn(s,r)},{x:t+e.width+kn(s,r),y:n+e.height+kn(s,r)},{x:t+kn(s,r),y:n+e.height+kn(s,r)}]},Xs=(e,{shadow:t=!1}={})=>{let n=Fh(e,t?{offsetX:Bd,offsetY:Bd,seedOffset:1}:void 0),i=Ys(e),o=e.roughness===2?Math.floor(Od(e.seed)()*n.length):-1;if(!i&&o===-1)return[{type:"move",point:n[0]},...n.slice(1).map(a=>({type:"line",point:a}))];let r=n.map((a,l)=>{let d=n[(l+n.length-1)%n.length],c=n[(l+1)%n.length],u=Math.min(i,Math.hypot(a.x-d.x,a.y-d.y)/2,Math.hypot(a.x-c.x,a.y-c.y)/2);if(l===o){let p=Math.min(e.width,e.height),m=Math.min(p*.18,40),h=Math.min(p*.02,5)*(t?.5:1),f={x:a.x+(l===1||l===2?-h:h),y:a.y+(l>=2?-h:h)},g=Cn(a,d,m),E=Cn(a,c,m);return[{type:"line",point:g},{type:"quadratic",control:Cn(a,d,m/2),point:Cn(f,g,u)},{type:"quadratic",control:f,point:Cn(f,E,u)},{type:"quadratic",control:Cn(a,c,m/2),point:E}]}return[{type:"line",point:Cn(a,d,u)},{type:"quadratic",control:a,point:Cn(a,c,u)}]}),s=[{type:"move",point:r[0][r[0].length-1].point}];for(let a=1;a<=r.length;a++)s.push(...r[a%r.length]);return s},$s=e=>Number.isFinite(e)?Math.min(Lh,Math.max(Dh,e)):vh,pr=(e,t)=>!!e.containerId&&ye(t.get(e.containerId)),zS=(e,t)=>pr(e,t)?e.baseFontSize??e.fontSize:e.fontSize,_S=(e,t,n)=>pr(e,n)?{baseFontSize:$s(t)}:{fontSize:t},Rh=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],zh=(e,{short:t=!1,now:n=Date.now()}={})=>{if(e===null||!Number.isFinite(e))return null;let i=new Date(e);if(Number.isNaN(i.getTime()))return null;let o=`${i.getDate()} ${Rh[i.getMonth()]}`,r=i.getFullYear();return t||r===new Date(n).getFullYear()?o:`${o} ${r}`},Gd=(e,t=Date.now())=>{if(e.width<Di||e.height<Di)return null;let n=zh(e.created,{short:e.width-ur*2<Ld.minBodyWidthForYear,now:t});return n?{text:n,x:e.width-ur,y:e.height-Ld.baselineFromBottom}:null},Fd=({fontSize:e,fontFamily:t})=>{let n=Math.ceil($s(e)*kh(t));return{width:Math.max(Di,n+ur*2),height:Math.max(Di,n+Us)}},_h=new Map,Hh=e=>Math.max(e.width,Di),Uh=(e,{baseFontSize:t,fontSizeMin:n,maxWidth:i,maxHeight:o,warmStart:r})=>{let s=Math.max(0,Math.ceil((t-n)/Hs)),a=h=>h>=s?n:t-h*Hs,l=new Map,d=h=>{let f=l.get(h);return f||(f=e(a(h)),l.set(h,f)),f},c=h=>{let f=d(h);return f.width<=i&&f.height<=o};if(s===0)return d(0);let u=Ch(Math.round((t-r)/Hs),0,s),p,m;if(c(u)){if(u===0||!c(u-1))return d(u);p=0,m=u-1}else{if(u===s)return d(s);p=u+1,m=s}for(;p<m;){let h=p+m>>1;c(h)?m=h:p=h+1}return d(p)},Rd=(e,t,n={})=>{let i=Hh(e),o=Math.max(n.baseHeight??(e.baseHeight||e.height),Di),r=n.anchor??"top";if(!t)return{container:{...ao(e,o,r),width:i,height:o,baseHeight:o},text:null};let s=n.originalText??t.originalText,a=$s(n.baseFontSize??t.baseFontSize??t.fontSize),l=Math.min(Bh,a),d=Math.max(i-ur*2,1),c=Math.max(o-Us,0),{fontFamily:u,lineHeight:p}=t,m=y=>{let w=kd({fontFamily:u,fontSize:y}),S=St(s,w,d);return{text:S,fontSize:y,...Ue(S,w,p)}},h=!s.trim(),f=h?{text:"",fontSize:a,...Ue("",kd({fontFamily:u,fontSize:a}),p)}:Uh(m,{baseFontSize:a,fontSizeMin:l,maxWidth:d,maxHeight:c,warmStart:t.fontSize}),g=h?o:Math.max(o,f.height+Us),E={...ao(e,g,r),width:i,height:g,baseHeight:o},{x,y:b}=ii({...e,...E},{...t,text:f.text,fontSize:f.fontSize,width:f.width,height:f.height},_h);return{container:E,text:{text:f.text,fontSize:f.fontSize,baseFontSize:a,width:f.width,height:f.height,x,y:b,angle:e.angle}}},js=(e,t,n,{proportional:i,fromCenter:o,flip:r=!1})=>{let s=t.get(e.id),a=ye(s)?s:e,l=q(a,t),d=l?l.baseFontSize??l.fontSize:void 0;if(r)return{baseHeight:a.baseHeight,baseFontSize:d};let c=i||n.includes("n")||n.includes("s"),u=i&&a.width?e.width/a.width:1,p=n.length===1;return{baseHeight:c?e.height:a.baseHeight,baseFontSize:d===void 0?void 0:d*u,anchor:o?"center":n.includes("n")?"bottom":i&&p&&(n==="e"||n==="w")?"center":"top"}},Ai=(e,t,{text:n,bindings:i,...o}={})=>{let r=t.getNonDeletedElementsMap(),s=n===void 0?q(e,r):n,a=Rd(e,s,o);return t.mutateElement(e,a.container),s&&a.text&&t.mutateElement(s,a.text),i!==!1&&!e.isDeleted&&Ge(e,t,i||void 0),a},Cd={container:["x","y","width","baseHeight","angle"],text:["originalText","baseFontSize","fontFamily","lineHeight","textAlign","verticalAlign"]},Wh=(e,t,n)=>{let i=n.get(e.id),o=t?n.get(t.id):null;return!i||t&&!o||!t&&i.boundElements?.some(({type:r})=>r==="text")?!0:Cd.container.some(r=>i[r]!==e[r])||!!t&&Cd.text.some(r=>o[r]!==t[r])},HS=(e,t,n)=>{if(!t.size)return e;let i=Nd(e),o=new Set;for(let s of t){let a=i.get(s);if(!(!a||a.isDeleted)){if(ye(a))o.add(a.id);else if(j(a)&&a.containerId){let l=i.get(a.containerId);l&&!l.isDeleted&&ye(l)&&o.add(l.id)}}}if(!o.size)return e;let r=new Map;for(let s of o){let a=i.get(s),l=q(a,i);if(n?.prevElementsMap&&!Wh(a,l,n.prevElementsMap))continue;let d=Rd(a,l),c=Me(a,d.container);if(c!==a&&r.set(s,c),l&&d.text){let u=Me(l,d.text);u!==l&&r.set(l.id,u)}}return r.size?e.map(s=>r.get(s.id)??s):e};var lo=new WeakMap,qs=(e,t)=>{let n=lo.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){lo.delete(e);return}return o.get(t)},Qs=(e,t,n)=>{let i=lo.get(e);if(!i){lo.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){lo.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function wi(e,t){let n=qs(e,0);if(n)return n;let i=$d(e,t),o=[],r=[];for(let a=0;a<i.length;a+=1){let l=i[a],d=i[a-1]&&Vh(i[a-1].data.slice(-2));switch(l.op){case"move":continue;case"lineTo":if(!d)throw new Error("prevPoint is undefined");o.push(ke(Y(e.x+d[0],e.y+d[1]),Y(e.x+l.data[0],e.y+l.data[1])));continue;case"bcurveTo":if(!d)throw new Error("prevPoint is undefined");r.push(dn(Y(e.x+d[0],e.y+d[1]),Y(e.x+l.data[0],e.y+l.data[1]),Y(e.x+l.data[2],e.y+l.data[3]),Y(e.x+l.data[4],e.y+l.data[5])));continue;default:console.error("Unknown op type",l.op)}}let s=[o,r];return Qs(e,s,0),s}function eI(e,t){if(X(e))return e.points.slice(1).map((o,r)=>ke(Y(e.x+e.points[r][0],e.y+e.points[r][1]),Y(e.x+o[0],e.y+o[1])));let[n,i]=wi(e,t);return i.length>0?i:n}function Mn(e,t=0){let n=qs(e,t);if(n)return n;let i=e.type==="stickynote"?Ys(e):cn(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=Zh(Y(e.x,e.y),Y(e.x+e.width,e.y+e.height)),r=ke(Y(o[0][0]+i,o[0][1]),Y(o[1][0]-i,o[0][1])),s=ke(Y(o[1][0],o[0][1]+i),Y(o[1][0],o[1][1]-i)),a=ke(Y(o[0][0]+i,o[1][1]),Y(o[1][0]-i,o[1][1])),l=ke(Y(o[0][0],o[1][1]-i),Y(o[0][0],o[0][1]+i)),d=[dn(l[1],Y(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),Y(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),dn(r[1],Y(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),Y(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),dn(s[1],Y(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),Y(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),dn(a[0],Y(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),Y(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],c=t>0?d.map(m=>Ud(Wd(m,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],p=[[ke(c[0][c[0].length-1][3],c[1][0][0]),ke(c[1][c[1].length-1][3],c[2][0][0]),ke(c[2][c[2].length-1][3],c[3][0][0]),ke(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Qs(e,p,t),p}function Xd(e,t=0){let[n,i,o,r,s,a,l,d]=vi(e),c=e.roundness?cn(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?cn(Math.abs(r-i),e):(r-i)*.01,[p,m,h,f]=[Y(e.x+n,e.y+i),Y(e.x+o,e.y+r),Y(e.x+s,e.y+a),Y(e.x+l,e.y+d)];return[dn(Y(m[0]-c,m[1]-u),m,m,Y(m[0]-c,m[1]+u)),dn(Y(h[0]+c,h[1]-u),h,h,Y(h[0]-c,h[1]-u)),dn(Y(f[0]+c,f[1]+u),f,f,Y(f[0]+c,f[1]-u)),dn(Y(p[0]-c,p[1]+u),p,p,Y(p[0]+c,p[1]+u))]}function Tn(e,t=0){let n=qs(e,t);if(n)return n;let i=Xd(e,t),o=t>0?i.map(a=>Ud(Wd(a,t))):[[i[0]],[i[1]],[i[2]],[i[3]]],s=[[ke(o[0][o[0].length-1][3],o[1][0][0]),ke(o[1][o[1].length-1][3],o[2][0][0]),ke(o[2][o[2].length-1][3],o[3][0][0]),ke(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return Qs(e,s,t),s}var Nt=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return ln(n,i)<=$h/t}return!1},cn=(e,t)=>{if(t.roundness?.type===Ks.PROPORTIONAL_RADIUS||t.roundness?.type===Ks.LEGACY)return e*Vs;if(t.roundness?.type===Ks.ADAPTIVE_RADIUS){let n=t.roundness?.value??Yh,i=n/Vs;return e<=i?e*Vs:n}return 0},Qh=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=qh(Yd(a[1],a[0])),d=Zs(l,n);return ke(Hd(a[0],d),Hd(a[1],Zs(d,-1)))},o=re(e,t),r=i(to(e)?ke(It(Y(e.x,e.y),o,e.angle),It(Y(e.x+e.width,e.y+e.height),o,e.angle)):ke(It(Y(e.x+e.width/2,e.y),o,e.angle),It(Y(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(to(e)?ke(It(Y(e.x+e.width,e.y),o,e.angle),It(Y(e.x,e.y+e.height),o,e.angle)):ke(It(Y(e.x,e.y+e.height/2),o,e.angle),It(Y(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},Jh=(e,t,n,i,o,r)=>{let{x:s,y:a,width:l,height:d,angle:c}=e,u=It(t,i,-c),p=Le(e);if(ln(i,u)<p)return;let[m,h,f,g]=Js(e,n);if(u[0]<=s+l/2&&u[1]>i[1]-r&&u[1]<i[1]+r)return{point:f,onAxis:!0};if(u[1]<=a+d/2&&u[0]>i[0]-o&&u[0]<i[0]+o)return{point:g,onAxis:!0};if(u[0]>=s+l/2&&u[1]>i[1]-r&&u[1]<i[1]+r)return{point:m,onAxis:!0};if(u[1]>=a+d/2&&u[0]>i[0]-o&&u[0]<i[0]+o)return{point:h,onAxis:!0};if(e.type==="diamond"){let E=Math.max(o,r),x=[[s+l/4,a+d/4,-1,-1],[s+3*l/4,a+d/4,1,-1],[s+l/4,a+3*d/4,-1,1],[s+3*l/4,a+3*d/4,1,1]];for(let[b,y,w,S]of x){let I=Y(b+w*p,y+S*p);if(ln(I,u)<E)return{point:It(Y(b,y),i,c),onAxis:!1}}}},eg=(e,t,n,i)=>{let o=Js(e,n);for(let r=0;r<o.length;r++)if(ln(o[r],t)<=i&&!Ot({point:t,element:e,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))return r;return-1},Js=(e,t)=>{let n=re(e,t);return e.type==="diamond"?Xd(e).map(i=>It(jh(i,.5),n,e.angle)):[Y(e.width,e.height/2),Y(e.width/2,e.height),Y(0,e.height/2),Y(e.width/2,0)].map(([i,o])=>It(Y(e.x+i,e.y+o),n,e.angle))},ea=(e,t,n,i)=>{let r=On(i)+t.strokeWidth/2;return Jh(t,e,n,re(t,n),zd(.05*t.width,5,r),zd(.05*t.height,5,r))},tg=(e,t,n,i,o)=>{if(o.elbowed)return ea(e,t,n,i)?.point;let r=On(i)+t.strokeWidth/2,s=eg(t,e,n,r);return s===-1?void 0:Js(t,n)[s]},ta=(e,t,n,i,o,r,s=!0)=>{if(Xh(e.points.length>=2,"Arrow must have at least two points"),s){let E=tg(t,n,o,r,e);if(E)return E}if(e.width<3&&e.height<3)return null;let[a,l]=Qh(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(je(E.fixedPoint),x,o);b&&(d=b)}let c=Kh(Zs(Yd(t,d),2*ln(d,t)+Math.max(ln(a[0],a[1]),ln(l[0],l[1]))),d),u=ke(c,d),p=_d(a,u),m=_d(l,u),h=p&&ln(d,p),f=m&&ln(d,m),g=null;return h!=null&&f!=null?g=h<f?p:m:g=p||m||null,g&&Je(g,n,o)?g:null};M();var oi=e=>e==="rectangle"||e==="stickynote"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw"||e==="autoshape"||e==="bucketfill",iI=e=>oi(e)&&e!=="stickynote",oI=e=>e==="rectangle"||e==="stickynote"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable"||e==="autoshape",rI=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="autoshape",ng=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line"||e==="autoshape",sI=e=>ng(e)||e==="stickynote",aI=e=>e==="freedraw",jd=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="stickynote"||e==="image",lI=e=>e==="arrow",dI=e=>e==="arrow";var gr=e=>{if(e.type==="arrow")return!1;let t=oi(e.type)&&!Jd(e.backgroundColor)||Wt(e)||jo(e)||j(e);return e.type==="line"?t&&Nt(e.points):e.type==="freedraw"?t&&Nt(e.points):t||Oe(e)},na=null,Vd=null,ia=1/0,oa=!1,Kd=!1,Zd=null,ug=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,Ot=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(!pe(t)&&na&&nc(e,na)&&(oa?ia<=n:ia>=n)&&r===Kd&&ug(o,Zd)){let u=Vd?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return oa}let s=o?ra(Te(o.x-n,o.y-n),e,Te(o.x+o.width+n,o.y+o.height+n)):!1,a=ae(t,i,!0);if(!ic(e,a,t.angle,ge(t)?n+lc(t):n)&&!s)return!1;j(t)&&(t=_s(t,i));let c=(r||gr(t))&&Je(e,t,i)||Qd(e,t,i,n)||s;return na=e,Vd=new WeakRef(t),ia=n,Kd=r,Zd=o,oa=c,c},ic=(e,t,n,i=0)=>{let o=n===0?e:mt(e,nn(t),-n);return ra(Te(t[0]-i,t[1]-i),o,Te(t[2]+i,t[3]+i))},mg=(e,t,n,i=0)=>{let o=ae(t,n,!0);return ic(e,o,t.angle,i)},II=(e,t)=>!Ot(e)&&!pg(e.point,e.element,t)&&mg(e.point,e.element,t),pg=(e,t,n)=>{let i=q(t,n);if(!i)return!1;let o=_s(i,n);return Je(e,o,n)},fg=(e,t,n)=>{if(!e.frameId)return!1;let i=n.get(e.frameId);return!!i&&J(i)&&!Xt(t,ae(i,n))},hg=(e,t,n,i=0)=>{let[o,r]=t,s=Math.max(1,i),a=[o-s,r-s,o+s,r+s],l=ae(e,n);if(!yt(a,l)||fg(e,t,n))return-1/0;let d=Je(t,e,n);if(d&&J(e))return-1/0;let c=tn(e,n,t);return d?c:c>i?-1/0:-c},qd=e=>Oe(e)||oi(e.type)&&!Jd(e.backgroundColor),oc=(e,t,n,i)=>{let o=On(i),r=[],s=null;for(let a=t.length-1;a>=0;--a){let l=t[a];if(ig(!l.isDeleted,"Elements passed to binding hit tests should not contain deleted elements"),s&&l.frameId!==s||!Pe(l))continue;J(l)&&qd(l)&&Je(e,l,n)&&(s=l.id);let d=hg(l,e,n,o);if(d>-o&&(l.locked||r.push({element:l,distance:d}),d>=0&&qd(l)))break}return r},sa=(e,t,n,i)=>oc(e,t,n,i).map(({element:o})=>o),rn=(e,t,n,i)=>{let o=oc(e,t,n,i);if(o.length===0)return null;if(o.length===1)return o[0].element;let r=o.sort((m,h)=>Math.abs(m.distance)-Math.abs(h.distance)),s=r[0],[a,l,d,c]=ae(s.element,n),u=Math.max(1e-5,Math.abs(d-a)*Math.abs(c-l)),p=r.filter(m=>m.element!==s.element&&m.distance>=0).map(m=>{let[h,f,g,E]=ae(m.element,n),x=Math.max(0,Math.min(g,d)-Math.max(h,a)),b=Math.max(0,Math.min(E,c)-Math.max(f,l)),y=Math.max(1e-5,Math.abs(g-h)*Math.abs(E-f));return{...m,overlapPercent:b*x/y,relativeArea:y/u}}).filter(m=>m.overlapPercent>.25&&m.relativeArea<.75);return s.distance>=0&&p.length>0?p[0].element:s.element},pt=(e,t,n,i=0,o=!1)=>{let r=[Math.min(n[0][0]-i,n[1][0]-i),Math.min(n[0][1]-i,n[1][1]-i),Math.max(n[0][0]+i,n[1][0]+i),Math.max(n[0][1]+i,n[1][1]+i)],s=ae(e,t);if(!yt(r,s))return[];switch(e.type){case"rectangle":case"stickynote":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return Eg(e,t,n,i,o);case"diamond":return xg(e,t,n,i,o);case"ellipse":return bg(e,t,n,i);case"line":case"freedraw":case"arrow":return gg(e,n,t,o)}},fr=1e-6,rc=(e,t,n,i,o,r=!1)=>{let s=[Math.min(t[0][0],t[1][0])-fr,Math.min(t[0][1],t[1][1])-fr,Math.max(t[0][0],t[1][0])+fr,Math.max(t[0][1],t[1][1])+fr];for(let a of e){let l=Er(a[0],a[1],a[2],a[3]);if(!yt(l,s))continue;let d=ec(a,t);if(d.length>0){for(let c of d)n.push(mt(c,i,o));if(r)return n}}return n},sc=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=tc(s,t);if(a&&(n.push(mt(a,i,o)),r))return n}return n},gg=(e,t,n,i=!1)=>{let[o,r]=wi(e,n),s=[];for(let a of o){let l=tc(a,t);if(l&&(s.push(l),i))return s}for(let a of r){let l=Er(a[0],a[1],a[2],a[3]),d=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!yt(l,d))continue;let c=ec(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),i))return s}return s},Eg=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=mt(n[0],r,-e.angle),a=mt(n[1],r,-e.angle),l=hr(s,a),[d,c]=Mn(e,i),u=[];return sc(d,l,u,r,e.angle,o),o&&u.length>0||rc(c,l,u,r,e.angle,o),u},xg=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=mt(n[0],r,-e.angle),a=mt(n[1],r,-e.angle),l=hr(s,a),[d,c]=Tn(e,i),u=[];return sc(d,l,u,r,e.angle,o),o&&u.length>0||rc(c,l,u,r,e.angle,o),u},bg=(e,t,n,i=0)=>{let o=re(e,t),r=mt(n[0],o,-e.angle),s=mt(n[1],o,-e.angle);return cg(dg(o,e.width/2+i,e.height/2+i),hr(r,s)).map(a=>mt(a,o,e.angle))},Qd=(e,t,n,i=1)=>tn(t,n,e)<=i,Je=(e,t,n)=>{if((ee(t)||ge(t))&&!Nt(t.points))return!1;if(ge(t)){let[u,p,m,h]=ae(t,n,!0),[f,g]=mt(e,Te((u+m)/2,(p+h)/2),-t.angle);return rg(Te(f-t.x,g-t.y),ac(t))}let[i,o,r,s]=ae(t,n);if(!ra(Te(i,o),e,Te(r,s)))return!1;let a=Te((i+r)/2,(o+s)/2),l=og(lg(ag(sg(e,a,.1)),Math.max(t.width,t.height)*2),a),d=hr(e,l);return pt(t,n,d).filter((u,p,m)=>m.findIndex(h=>nc(h,u))===p).length%2===1},aa=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:p}=s,m=re(s,n);if(s.type==="diamond"){let[f,g,E,x,b,y,w,S]=vi(s);return[Te(l+f,d+g-a),Te(l+E+a,d+x),Te(l+b,d+y+a),Te(l+w-a,d+S)].map(A=>mt(A,m,p))}if(s.type==="ellipse"){let f=l+c/2,g=d+u/2,E=c/2,x=u/2;return[Te(f,g-x-a),Te(f+E+a,g),Te(f,g+x+a),Te(f-E-a,g)].map(y=>mt(y,m,p))}return[Te(l-a,d-a),Te(l+c+a,d-a),Te(l+c+a,d+u+a),Te(l-a,d+u+a)].map(f=>mt(f,m,p))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Je(s,t,n))};var Ln=5,Mg=10,fo=10/1.5,br=1,Le=e=>Ln+e.strokeWidth/2,On=e=>{let t=Math.max(Ln,15),n=e?.value&&e.value<1?e.value:1;return gc(t/(n*1.5),t,t*2)},$t=e=>e.isBindingEnabled,Tg=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=ca(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0}),d=r.isMidpointSnappingEnabled&&!s?.angleLocked&&!r.gridModeEnabled;if(dc(e,a,"start",o,r.zoom,r.isBindingEnabled,d),dc(e,l,"end",o,r.zoom,r.isBindingEnabled,d),a.focusPoint||l.focusPoint){let c=new Map;a.focusPoint&&c.set(0,{point:Gt(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&c.set(e.points.length-1,{point:Gt(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),R.movePoints(e,o,c)}return{start:a,end:l}},dc=(e,{mode:t,element:n,focusPoint:i},o,r,s,a=!0,l=!0)=>{t===null?Ke(e,o,r):t!==void 0&&jt(e,n,t,o,r,s,i,a,l)},Ec=(e,t,n,i,o)=>{un(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;un(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=R.getPointGlobalCoordinates(e,a,n),d=rn(l,i,n,o),c=d?{element:d,mode:"orbit",focusPoint:R.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},Ag=(e,t,n,i,o,r,s,a,l,d,c)=>{let u={mode:void 0},p={mode:void 0},m=e.points.length>2,h=R.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),f=rn(h,i,n,l.zoom);if(o)return f?u={element:f,mode:"inside",focusPoint:h}:u={mode:null},{start:u,end:p};if(r){let g=l?.selectedLinearElement?.initialState.origin;if(f&&e.startBinding?.elementId===f.id){let E=ue(f.x+f.width/2,f.y+f.height/2);return{start:m?{mode:void 0}:{mode:"inside",element:f,focusPoint:g??E},end:m?{mode:"orbit",element:f,focusPoint:h}:{mode:"inside",element:f,focusPoint:h}}}if(f&&e.startBinding){let E=e.startBinding;if(sa(h,i,n,l.zoom).find(b=>b.id===E.elementId)){let b=n.get(e.startBinding.elementId);return un(b,"Other element must be in the elements map"),{start:m?{mode:void 0}:{mode:b.id!==f.id?"orbit":"inside",element:b,focusPoint:g??ue(e.x,e.y)},end:{mode:"orbit",element:f,focusPoint:h}}}}if(e.startBinding&&e.startBinding.elementId!==f?.id){let E=n.get(e.startBinding.elementId);un(E,"Other element must be in the elements map");let b={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:E,focusPoint:c?re(E,n):g??ue(e.x,e.y)},y=f&&aa(E,f,n),w;if(f){let S=d==="inside"||d==="skip";w={mode:S&&!y?"inside":"orbit",element:f,focusPoint:h}}else w={mode:null};return{start:m?{mode:void 0}:b,end:w}}if(!e.startBinding)return f?p={mode:d==="inside"||d==="skip"?"inside":"orbit",element:f,focusPoint:h}:p={mode:null},{start:u,end:p}}un(!1,"New arrow creation should not reach here")},cc=(e,t,n,i,o,r,s,a,l)=>{let d={mode:void 0},c={mode:void 0},u=s.points.length>2,p=rn(e,o,i,a),m=n?sa(e,o,i,a).some(E=>E.id===n.elementId):!1,h=n?i.get(n.elementId):null,f=m&&h?wg(h.backgroundColor):!1,g=p&&h&&aa(h,p,i);return r==="inside"||r==="skip"?(d=p?{element:!m||!h||f?p:h,focusPoint:e,mode:"inside"}:{mode:null},c=l&&p&&p.id===n?.elementId?{mode:null}:c,{current:d,other:c}):p?p.id===t?.elementId&&t.mode==="inside"?{current:{mode:"inside",focusPoint:e,element:p},other:c}:n?n.elementId===p.id?n.mode==="orbit"?(d={element:p,mode:"orbit",focusPoint:e},c={mode:l?null:void 0},{current:d,other:u?{mode:void 0}:c}):(d={element:p,mode:"inside",focusPoint:e},{current:d,other:u?{mode:void 0}:c}):(m&&h&&!f?d={element:h,mode:"inside",focusPoint:e}:d={element:p,mode:"orbit",focusPoint:e},{current:d,other:u?{mode:void 0}:c}):(d={element:p,mode:"orbit",focusPoint:e},{current:d,other:u?{mode:void 0}:c}):{current:{mode:null},other:c}},ca=(e,t,n,i,o,r,s,a)=>yg("COMPLEX_BINDINGS")?Dg(e,t,o,r,s,a):xc(e,t,n,i,o,r,s,a),xc=(e,t,n,i,o,r,s,a)=>{let d=e.points.length-1,c=t.has(0),u=t.has(d),p={mode:void 0},m={mode:void 0};if(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!c&&!u)return{start:p,end:m};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!$t(s))return p=c?{mode:null}:p,m=u?{mode:null}:m,{start:p,end:m};if(X(e))return Ec(e,t,o,r,s.zoom);let h=c?e.endBinding:e.startBinding,f=t.get(c?0:d)?.point;un(f,`Local point must be defined for ${c?"start":"end"} dragging`);let g=R.getPointGlobalCoordinates(e,f,o),E=rn(a?.angleLocked||s.gridModeEnabled?ue(n,i):g,r,o,s.zoom),x=E&&(a?.angleLocked?Je(ue(n,i),E,o):Je(g,E,o)),b=h?o.get(h.elementId):void 0,y=h&&b&&_e(h.fixedPoint,b,o),w=b&&y&&Ot({point:y,element:b,elementsMap:o,threshold:0,overrideShouldTestInside:!0}),S=s.selectedLinearElement?.initialState.arrowOtherEndpointInitialBinding;if(h&&h.elementId===E?.id&&(!a?.newArrow||s.selectedLinearElement?.initialState.origin))return{start:{mode:"inside",element:E,focusPoint:c?g:a?.newArrow?Sg(la(s.selectedLinearElement.initialState.origin[0],s.selectedLinearElement.initialState.origin[1],a.gridSize)):b?_e(h.fixedPoint,b,o):R.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:E,focusPoint:u?g:b?_e(h.fixedPoint,b,o):R.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?E?{mode:"inside",element:E,focusPoint:g}:{mode:null}:p,end:u?E?{mode:"inside",element:E,focusPoint:g}:{mode:null}:m};let I=E?x?{mode:"inside",element:E,focusPoint:g}:{mode:"orbit",element:E,focusPoint:ta(e,a?.angleLocked?g:s.gridModeEnabled?Cg(ue(n,i),E,o,s.gridSize,e,R.getPointAtIndexGlobalCoordinates(e,c?1:-2,o)):g,E,c?"start":"end",o,s.zoom,s.isMidpointSnappingEnabled&&!a?.angleLocked&&!s.gridModeEnabled)||g}:{mode:null},A=R.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),T=y&&b&&Ot({point:g,element:b,elementsMap:o,threshold:On(s.zoom),overrideShouldTestInside:!0}),O=S?.mode==="inside",v=a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:h?.mode==="inside"&&O,N={mode:void 0};return v||(h?.mode==="inside"&&!O&&b&&!a?.newArrow?N={mode:"orbit",element:b,focusPoint:y||A}:b&&!w&&!T&&s.selectedLinearElement?.initialState.altFocusPoint?N={mode:"orbit",element:b,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&b&&(N={mode:"orbit",element:b,focusPoint:ta(e,A,b,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||A})),{start:c?I:N,end:u?I:N}},Dg=(e,t,n,i,o,r)=>{let s=o.bindMode||"orbit",a=0,l=e.points.length-1,d=t.has(a),c=t.has(l),u={mode:void 0},p={mode:void 0};if(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!d&&!c)return{start:u,end:p};if(d&&c)return{start:{mode:null},end:{mode:null}};if(!$t(o))return u=d?{mode:null}:u,p=c?{mode:null}:p,{start:u,end:p};if(X(e))return Ec(e,t,n,i,o.zoom);if(r?.newArrow){let{start:m,end:h}=Ag(e,t,n,i,d,c,a,l,o,s,r?.shiftKey);return{start:m,end:h}}if(d){let m=t.get(a)?.point;un(m,"Local point must be defined for start dragging");let h=R.getPointGlobalCoordinates(e,m,n),{current:f,other:g}=cc(h,e.startBinding,e.endBinding,n,i,s,e,o.zoom,r?.finalize);return{start:f,end:g}}if(c){let m=t.get(l)?.point;un(m,"Local point must be defined for end dragging");let h=R.getPointGlobalCoordinates(e,m,n),{current:f,other:g}=cc(h,e.endBinding,e.startBinding,n,i,s,e,o.zoom,r?.finalize);return{start:g,end:f}}return{start:u,end:p}},HI=(e,t,n)=>{e.forEach(i=>{Tg(i,new Map,1/0,1/0,t,n)})},bc=(e,t,n,i,o)=>{o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:n}),hc(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},jt=(e,t,n,i,o,r,s,a=!0,l=!0)=>{let d=o.getNonDeletedElementsMap(),c;X(e)?c={elementId:t.id,mode:"orbit",...yc(e,t,i,d,r,a,l)}:c={elementId:t.id,mode:n,...si(e,t,i,d,s)},bc(e,t,c,i,o)},Ke=(e,t,n)=>{let i=t==="start"?"startBinding":"endBinding",o=e[i];if(o==null)return null;let r=e[t==="start"?"endBinding":"startBinding"];if(!r||r.elementId!==o.elementId){let s=n.getNonDeletedElementsMap().get(o.elementId);n.mutateElement(s,{boundElements:s.boundElements?.filter(a=>a.id!==e.id)})}return n.mutateElement(e,{[i]:null}),o.elementId},UI=(e,t,n)=>{let i=t.getNonDeletedElementsMap(),o=re(e,i),r=Math.max(e.width,e.height)*2;po(i,e,s=>{if(!W(s)||!$e(s))return;let a={};for(let l of["startBinding","endBinding"]){let d=s[l];if(d?.elementId!==e.id)continue;let c=l==="startBinding"?"start":"end";if(X(s)){a[l]={...d,...yc(s,e,c,i,n)};continue}let u=_e(d.fixedPoint,e,i);if(Ot({element:e,point:u,elementsMap:i,threshold:Le(e),overrideShouldTestInside:!0}))continue;let p=Gn(u,o);if(p[0]===0&&p[1]===0)continue;let m=pt(e,i,ri(o,co(uo(xr(p),r),o))).sort((h,f)=>tt(h,u)-tt(f,u))[0];m&&(a[l]={...d,...si(s,e,c,i,m)})}(a.startBinding||a.endBinding)&&He(s,i,a)})},Ge=(e,t,n)=>{if(!Pe(e))return;let{simultaneouslyUpdated:i}=n??{},o=ua(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),po(r,e,a=>{if(a&&!$e(a)&&console.error("[NONDELETED][INVARIANT] updateBoundElements(): `isDeleted: true` in visitor"),!W(a)||!$e(a)||!vg(a,e))return;let l=a.startBinding?r.get(a.startBinding.elementId):null,d=a.endBinding?l?.id===a.endBinding.elementId?l:r.get(a.endBinding.elementId):null;if(o.has(a.id))return;let c=yr(r,a,(p,m)=>{if(p&&Pe(p)&&(m==="startBinding"||m==="endBinding")&&(e.id===a[m]?.elementId||e.id===a[m==="startBinding"?"endBinding":"startBinding"]?.elementId)){let h=Gt(a,m,a[m],p,r);if(h)return[m==="startBinding"?0:a.points.length-1,{point:h}]}return null}).filter(p=>p!==null);R.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=q(a,r);u&&!u.isDeleted&&ni(a,t,!1)})},uc=(e,t,n,i,o)=>{un(!X(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=R.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&Ot({element:s,point:a,elementsMap:n,threshold:On(o.zoom)}),d=t==="startBinding"?"start":"end";if(Ke(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],p=xc(e,new Map([[c,{point:u}]]),a[0],a[1],n,i.getNonDeletedElements(),o);p[d]&&p[d].element?.id===s.id&&p[d].mode&&jt(e,s,p[d].mode,d,i,o.zoom,p[d].focusPoint)}},WI=(e,t,n,i)=>{if(W(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&uc(e,"startBinding",o,t,n),e.endBinding&&uc(e,"endBinding",o,t,n)}else Ge(e,t,{...i,changedElements:new Map([[e.id,e]])})},vg=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,mc=new WeakMap,ua=e=>{if(!e)return new Set;let t=mc.get(e);return t||(t=new Set(e.map(n=>n.id)),mc.set(e,t)),t},yd=(e,t,n,i,o,r,s)=>{let a=Lt(Gn(t,e));return!n||!i?a:Lg(o,n,r,s)?Pi(n,i,e):Lt(Gn(e,re(n,r)))},Lg=(e,t,n,i)=>{let o=tn(t,n,e),r=On(i);return o>r?null:o},As=(e,t,n,i,o,r,s=!0)=>{let a=X(e),l=R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return l;let d=sd(t)&&a?Bg(e,t,i,l):l,c=r&&!a?r[1]:R.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),u=Le(t),p=ut(t,i),m=nn(p),h=null;if(a){let f=s?ea(d,t,i,o):void 0,g=f?.point??l,E=ct(f?.onAxis?Lt(Gn(f.point,m)):Pi(t,p,l)),x=ue(E?m[0]:g[0],E?g[1]:m[1]),b=r??ri(x,co(uo(xr(Gn(g,x)),Math.max(t.width,t.height)*2),x)),y=(w,S)=>tt(w,g)-tt(S,g);if(h=pt(t,i,b,u).sort(y)[0],!h){let w=ue(E?g[0]:m[0],E?m[1]:g[1]),S=ri(w,co(uo(xr(Gn(g,w)),Math.max(t.width,t.height)*2),w));h=pt(t,i,S,Ln).sort(y)[0]}}else{let f=r;if(!f){let g=uo(xr(Gn(d,c)),da(d,c)+Math.max(t.width,t.height)+u*2);f=r??ri(co(g,c),co(uo(g,-1),c))}h=da(d,c)<1?d:pt(t,i,f,u).sort((g,E)=>tt(g,c)-tt(E,c))[0]}return!h||tt(d,h)<Pg?d:h},Bg=(e,t,n,i)=>{let o=re(t,n),r=et(i,o,-t.angle),s=Le(t);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?et(ue(t.x-s,t.y),o,t.angle):et(ue(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?et(ue(t.x,t.y+t.height+s),o,t.angle):et(ue(t.x-s,t.y+t.height),o,t.angle):r[0]>t.x+t.width&&r[1]>t.y+t.height?r[0]-t.x<t.width+s?et(ue(t.x+t.width,t.y+t.height+s),o,t.angle):et(ue(t.x+t.width+s,t.y+t.height),o,t.angle):r[0]>t.x+t.width&&r[1]<t.y?r[0]-t.x<t.width+s?et(ue(t.x+t.width,t.y-s),o,t.angle):et(ue(t.x+t.width+s,t.y),o,t.angle):i},kg=(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(je(i.fixedPoint),o,n),binding:i,mode:i.mode}},Cg=(e,t,n,i,o,r)=>{if(!i)return e;let s=ut(t,n),a=r&&(t.type==="ellipse"||t.type==="diamond")?Lt(Gn(r,e)):Pi(t,s,e),l=Le(t),d=Math.max(t.width,t.height)+l*2,c=nn(s),u=Math.abs(a[0]),p=Math.abs(a[1]);if(u>=p){let[,g]=la(e[0],e[1],i),E=ri(ue(c[0]-d,g),ue(c[0]+d,g));return pt(t,n,E,l).sort((b,y)=>tt(b,e)-tt(y,e))[0]??ue(e[0],g)}let[m]=la(e[0],e[1],i),h=ri(ue(m,c[1]-d),ue(m,c[1]+d));return pt(t,n,h,l).sort((g,E)=>tt(g,e)-tt(E,e))[0]??ue(m,e[1])},pc=e=>e.width*e.height,Gt=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||Ig(e.points[e.points.length-1],ue(0,0)))return null;let s=_e(je(n.fixedPoint),i,o);if(n.mode==="inside")return R.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=kg(e,t==="startBinding"?"endBinding":"startBinding",o),d=R.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&ri(s,c),p=a&&u&&pt(a,o,u,Le(a)).sort((b,y)=>tt(b,s)-tt(y,s))[0],m=u&&pt(i,o,u,Le(i)).sort((b,y)=>tt(b,c)-tt(y,c))[0],h=e.startArrowhead!==null,f=e.endArrowhead!==null,g=!h&&!f||t==="startBinding"&&h||t==="endBinding"&&f?s:m||s;if(a&&m&&!r&&pc(a)<pc(i)*2&&Ot({element:a,point:m,elementsMap:o,threshold:Le(a),overrideShouldTestInside:!0}))return R.createPointAt(e,o,g[0],g[1],null);let x=da(a&&(p||l)||d,m||s)<=Mg;return a?x?R.createPointAt(e,o,g?.[0]||s[0],g?.[1]||s[1],null):R.createPointAt(e,o,m?.[0]||s[0],m?.[1]||s[1],null):R.createPointAt(e,o,x?s[0]:m?.[0]??s[0],x?s[1]:m?.[1]??s[1],null)},yc=(e,t,n,i,o,r=!0,s=!0)=>{let a=[t.x,t.y,t.x+t.width,t.y+t.height],l=r?As(e,t,n,i,o,void 0,s):R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),d=ue(a[0]+(a[2]-a[0])/2,a[1]+(a[3]-a[1])/2),c=et(l,d,-t.angle);if(t.width<br||t.height<br)return{fixedPoint:je([.5,.5])};let u=Le(t);return{fixedPoint:je([(c[0]-t.x)/Math.max(t.width,u),(c[1]-t.y)/Math.max(t.height,u)])}},si=(e,t,n,i,o)=>{let r=o||R.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=re(t,i),a=et(r,s,-t.angle);if(t.width<br||t.height<br)return{fixedPoint:je([.5,.5])};let l=Le(t),d=(a[0]-t.x)/Math.max(t.width,l),c=(a[1]-t.y)/Math.max(t.height,l);return{fixedPoint:je([d,c])}},wc=(e,t,n)=>{for(let i of e){if("boundElements"in i&&i.boundElements&&Object.assign(i,{boundElements:i.boundElements.reduce((o,r)=>{let s=t.get(r.id);return s&&o.push({...r,id:s}),o},[])}),"containerId"in i&&i.containerId&&Object.assign(i,{containerId:t.get(i.containerId)??null}),"endBinding"in i&&i.endBinding){let o=t.get(i.endBinding.elementId);Object.assign(i,{endBinding:o?{...i.endBinding,elementId:o}:null})}if("startBinding"in i&&i.startBinding){let o=t.get(i.startBinding.elementId);Object.assign(i,{startBinding:o?{...i.startBinding,elementId:o}:null})}X(i)&&Object.assign(i,Ii(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},YI=(e,t)=>{let n=hc(e);for(let i of t)Fn.unbindAffected(n,i,(o,r)=>He(o,n,r)),Rn.unbindAffected(n,i,(o,r)=>He(o,n,r))},mo=(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},Pc=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),po=(e,t,n)=>{Pe(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},yr=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(pe(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(W(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},Fn=class{static unbindAffected(t,n,i){n&&yr(t,n,o=>{!o||o.isDeleted||po(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:mo(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||yr(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(W(n)&&i(o,{boundElements:mo(o.boundElements,new Set,new Array(n))}),j(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:mo(o.boundElements,new Set,new Array(n))}))))})}},Rn=class{static unbindAffected(t,n,i){n&&po(t,n,o=>{!o||o.isDeleted||yr(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||po(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:mo(n.boundElements,new Set([s]))});return}j(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:mo(n.boundElements,new Set([o.id]))})))})}},_e=(e,t,n)=>{let[i,o]=je(e);return et(ue(t.x+t.width*i,t.y+t.height*o),re(t,n),t.angle)},Ng=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?_e(e.startBinding.fixedPoint,n,t):ue(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?_e(e.endBinding.fixedPoint,i,t):ue(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},Sc=(e,t)=>{let[n,i]=Ng(e,t);return[R.pointFromAbsoluteCoords(e,n,t),R.pointFromAbsoluteCoords(e,i,t)]},Og=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),fc=10,je=e=>{if(!Og(e))return[.5001,.5001];let t=1e-4,n=e.map(i=>gc(i,-fc,fc));return Math.abs(n[0]-.5)<t||Math.abs(n[1]-.5)<t?n.map(i=>Math.abs(i-.5)<t?.5001:i):n},Gg=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",Fg={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"}]},Rg=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}}),zg=(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=Fg[t],d=Rg(l);for(let p of d)if(p.start<=p.end){if(a>=p.start&&a<=p.end)return p.side}else if(a>=p.start||a<=p.end)return p.side;let c=1/0,u=l[0].side;for(let p of l){let m=Math.abs(a-p.centerAngle);m>180&&(m=360-m),m<c&&(c=m,u=p.side)}return u},XI=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!Pe(n))return null;let i=re(n,t),o=Gg(n),r=zg(je(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=Tn(n),[d,c,u,p]=a,m,h;switch(r){case"left":{if(l.length>=3){let g=l[2][1];m=g[0]-s,h=g[1]}else{let f=Ve(c[1],u[0]);m=f[0]-s,h=f[1]}break}case"right":{if(l.length>=1){let g=l[0][1];m=g[0]+s,h=g[1]}else{let f=Ve(p[1],d[0]);m=f[0]+s,h=f[1]}break}case"top":{if(l.length>=4){let g=l[3][1];m=g[0],h=g[1]-s}else{let f=Ve(u[1],p[0]);m=f[0],h=f[1]-s}break}case"bottom":{if(l.length>=2){let g=l[1][1];m=g[0],h=g[1]+s}else{let f=Ve(d[1],c[0]);m=f[0],h=f[1]+s}break}case"top-right":{let f=Ve(p[0],p[1]);m=f[0]+s*.707,h=f[1]-s*.707;break}case"bottom-right":{let f=Ve(d[0],d[1]);m=f[0]+s*.707,h=f[1]+s*.707;break}case"bottom-left":{let f=Ve(c[0],c[1]);m=f[0]-s*.707,h=f[1]+s*.707;break}case"top-left":{let f=Ve(u[0],u[1]);m=f[0]-s*.707,h=f[1]-s*.707;break}default:return null}return et(ue(m,h),i,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,p;switch(r){case"top":{u=a,p=l-c-s;break}case"right":{u=a+d+s,p=l;break}case"bottom":{u=a,p=l+c+s;break}case"left":{u=a-d-s,p=l;break}case"top-right":{let m=-Math.PI/4,h=d*Math.cos(m),f=c*Math.sin(m);u=a+h+s*.707,p=l+f-s*.707;break}case"bottom-right":{let m=Math.PI/4,h=d*Math.cos(m),f=c*Math.sin(m);u=a+h+s*.707,p=l+f+s*.707;break}case"bottom-left":{let m=3*Math.PI/4,h=d*Math.cos(m),f=c*Math.sin(m);u=a+h-s*.707,p=l+f+s*.707;break}case"top-left":{let m=-3*Math.PI/4,h=d*Math.cos(m),f=c*Math.sin(m);u=a+h-s*.707,p=l+f-s*.707;break}default:return null}return et(ue(u,p),i,n.angle)}if(to(n)){let[a,l]=Mn(n),[d,c,u,p]=a,m,h;switch(r){case"top":{let f=Ve(d[0],d[1]);m=f[0],h=f[1]-s;break}case"right":{let f=Ve(c[0],c[1]);m=f[0]+s,h=f[1];break}case"bottom":{let f=Ve(u[0],u[1]);m=f[0],h=f[1]+s;break}case"left":{let f=Ve(p[0],p[1]);m=f[0]-s,h=f[1];break}case"top-left":{if(l.length>=1){let f=l[0],g=f[0],E=f[3],x=Ve(g,E);m=x[0]-s*.707,h=x[1]-s*.707}else m=n.x-s,h=n.y-s;break}case"top-right":{if(l.length>=2){let f=l[1],g=f[0],E=f[3],x=Ve(g,E);m=x[0]+s*.707,h=x[1]-s*.707}else m=n.x+n.width+s,h=n.y-s;break}case"bottom-right":{if(l.length>=3){let f=l[2],g=f[0],E=f[3],x=Ve(g,E);m=x[0]+s*.707,h=x[1]+s*.707}else m=n.x+n.width+s,h=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let f=l[3],g=f[0],E=f[3],x=Ve(g,E);m=x[0]-s*.707,h=x[1]+s*.707}else m=n.x-s,h=n.y+n.height+s;break}default:return null}return et(ue(m,h),i,n.angle)}return null},Ve=(e,t)=>ue((e[0]+t[0])/2,(e[1]+t[1])/2),$I=(e,t,n,i,o)=>{bc(e,t,{elementId:t.id,fixedPoint:je(i),mode:"orbit"},n,o)};var fa=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>H(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},Lc=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,Mc(t.points[0],H(0,0))||(console.error("Linear element is not normalized",Error().stack),He(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,arrowOtherEndpointInitialBinding:null,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=X(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,p]=Q(n.selectionElement,o),h=e.getPointsGlobalCoordinates(l,o).reduce((f,g,E)=>((g[0]>=d&&g[0]<=u&&g[1]>=c&&g[1]<=p||t.shiftKey&&s?.includes(E))&&f.push(E),f),[]).filter(f=>!(X(l)&&f!==0&&f!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:h.length?h:null}})}static handlePointerMove(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);ft(d,"Element being dragged must exist in the scene"),ft(d.points.length>1,"Element must have at least 2 points");let c=d.points.length-1,u=d.points[c],p=d.points[c-1],m=r.customLineAngle??kc(p,d.points[c]),h=0,f=0;if(li(t)){let[I,A]=e._getShiftLockedDelta(d,s,p,H(i,o),t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),m),T=H(I+p[0],A+p[1]);h=T[0]-u[0],f=T[1]-u[1]}else{let I=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize());h=I[0]-u[0],f=I[1]-u[1]}let g=null,{positions:E,updates:x,hit:b}=Bc([c],h,f,i,o,s,d,a,n,li(t),t.altKey,r),y=li(t);if(e.movePoints(d,n.scene,E,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!y&&!n.state.gridModeEnabled}),Xe(d,!1)&&$t(n.state)&&(g=x?.suggestedBinding??null),Xe(d)&&b&&Dc(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene,b),n.state.selectedLinearElement?.customLineAngle===m&&r.initialState.altFocusPoint&&(!g||$g(n.state.suggestedBinding??[],g)))return null;let w=Xe(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:m,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&w&&x?.suggestedBinding?.element.id!==w.id?vc(d,H(d.x,d.y),w,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!y&&!n.state.gridModeEnabled):r.initialState.altFocusPoint}},suggestedBinding:g}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:p}=c,m=e.getElement(d,s);ft(m,"Element being dragged must exist in the scene"),ft(m.points.length>1,"Element must have at least 2 points"),ft(u,"There must be selected points in order to drag them"),l&&u.some((k,_)=>k>0&&k!==m.points.length-1?(u[_]=m.points.length-1,p=m.points.length-1,!0):!1),(p<0||!u.includes(p)||!m.points[p])&&(console.error(`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${m.points.length-1}) lastClickedPoint(${p}) isElbowArrow: ${l}`),p=m.points.length-1);let h=m.points[p],f=m.points[p===0?1:p-1],g=u.length===1,E=r.customLineAngle??kc(f,m.points[p]),x=u.includes(0),b=u.includes(m.points.length-1),y=0,w=0;if(li(t)&&g){let[k,_]=e._getShiftLockedDelta(m,s,f,H(i,o),t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),E),K=H(k+f[0],_+f[1]);y=K[0]-h[0],w=K[1]-h[1]}else{let k=e.createPointAt(m,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=k[0]-h[0],w=k[1]-h[1]}let S=null,{positions:I,updates:A,hit:T}=Bc(u,y,w,i,o,s,m,a,n,li(t)&&g,t.altKey,r),O=li(t)&&g;e.movePoints(m,n.scene,I,{startBinding:A?.startBinding,endBinding:A?.endBinding,moveMidPointsWithElement:A?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!O&&!n.state.gridModeEnabled}),Xe(m,!1)&&$t(n.state)&&(x||b)&&(S=A?.suggestedBinding??null),Xe(m)&&x!==b&&T&&Dc(e.getPointGlobalCoordinates(m,x?m.points[0]:m.points[m.points.length-1],s),m,a,s,n.scene,T),q(m,s)&&ni(m,n.scene,!1);let N=l?b?[m.points.length-1]:[0]:u,C=l?N[0]:p,z=!x&&!b?e.getPointGlobalCoordinates(m,h,s):null,U=C,D=Xe(m)&&m.startBinding&&s.get(m.startBinding.elementId),L=Xe(m)&&m.endBinding&&s.get(m.endBinding.elementId),P=b&&D&&A?.suggestedBinding?.element.id!==D.id?D:x&&L&&A?.suggestedBinding?.element.id!==L.id?L:null;return{selectedLinearElement:{...r,selectedPointsIndices:N,initialState:{...r.initialState,lastClickedPoint:C,altFocusPoint:!r.initialState.altFocusPoint&&Xe(m)&&P?vc(m,H(m.x,m.y),P,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!O&&!n.state.gridModeEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:z,hoverPointIndex:U,isDragging:!0,customLineAngle:E},suggestedBinding:S}}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),{elementId:s,selectedPointsIndices:a,isDragging:l,initialState:d}=n,c=e.getElement(s,r);if(!c)return n;if(l&&a)for(let u of a)(u===0||u===c.points.length-1)&&jg(c.points,i.zoom.value)&&(Re(c)&&o.mutateElement(c,{...Fc(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=q(t,n);if(!X(t)&&!i.selectedLinearElement?.isEditing&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom,n)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1,n);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!X(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!X(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Vt(H(c[0],c[1]),H(n.x,n.y))<=d)return c;let u=0,p=e.getEditorMidPoints(s,o,i);for(;u<p.length;){if(p[u]!==null&&Vt(p[u],H(n.x,n.y))<=d)return p[u];u++}return null};static isSegmentTooShort(t,n,i,o,r,s){if(X(t))return o>=0&&o<t.points.length?Vt(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=Vt(n,i);if(t.points.length>2&&t.roundness){let[l,d]=Ac(t,s);ft(l.length===0&&d.length>0,"Only linears built out of curves are supported"),ft(l.length+d.length>=o,"Invalid segment index while calculating mid point"),a=Nc(d[o])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,i){if(X(t)){ft(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=Ic(t.points[n-1],t.points[n]);return H(t.x+s[0],t.y+s[1])}let[o,r]=Ac(t,i);if(ft(o.length===0&&r.length>0||o.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),ft(o.length+r.length>=n,"Invalid segment index while calculating mid point"),o.length){let s=o[n-1];return Ic(s[0],s[1])}if(r.length){let s=r[n-1];return Oc(s,.5)}ft(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,hitBoundText:!1,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let p=e.getSegmentMidpointHitCoords(r,o,a,l),m=H(o.x,o.y),h=null;if(p)h=e.getSegmentMidPointIndex(r,a,p,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(u,{points:[...u.points,e.createPointAt(u,l,o.x,o.y,t[ai.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:m,segmentMidpoint:{value:p,index:h,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:u.startBinding},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let f=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y),g=e.isPointHandle(u,f),E=q(u,l),x=null;if(!g&&!p&&E&&W(u)&&n.arrowText.isBoundTextGrabbable(u,o.x,o.y)){let{x:N,y:C}=e.getBoundTextElementPosition(u,E,l);x={x:o.x-(N+E.width/2),y:o.y-(C+E.height/2)}}let b=x?-1:f;d.hitBoundText=!!x,(b>=0||p||x)&&(d.hitElement=u);let[y,w,S,I]=Q(u,l),A=(y+S)/2,T=(w+I)/2,O=b>-1&&nt(H(u.x+u.points[b][0],u.y+u.points[b][1]),H(A,T),u.angle),v=b>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(b)?Kg([...r.selectedPointsIndices||[],b]):[b]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:b,origin:m,segmentMidpoint:{value:p,index:h,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null,arrowOtherEndpointInitialBinding:v?.includes(0)?u.endBinding:u.startBinding},selectedPointsIndices:v,pointerOffset:O?{x:o.x-O[0],y:o.y-O[1]}:x??{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Mc(t,n)}static handlePointerMoveInEditMode(t,n,i,o){let r=o.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=o.scene.getNonDeletedElementsMap(),d=e.getElement(s,l);if(!d)return r.selectedLinearElement;let{points:c}=d,u=c[c.length-1];if(!t.altKey)return u===a&&e.deletePoints(d,o,[c.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let p;if(li(t)&&c.length>=2){let m=c[c.length-2],[h,f]=e._getShiftLockedDelta(d,l,m,H(n,i),t[ai.CTRL_OR_CMD]?null:o.getEffectiveGridSize());p=H(h+m[0],f+m[1])}else p=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[ai.CTRL_OR_CMD]||X(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:p}]])):e.addPoints(d,o.scene,[p]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=Q(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return nt(H(c+n[0],u+n[1]),H(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=Q(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return nt(H(c+d[0],u+d[1]),H(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=Q(t,i),a=H(r,s),l=t.points[o],{x:d,y:c}=t;return l?nt(H(d+l[0],c+l[1]),a,t.angle):nt(H(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(X(t))return H(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=Q(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=nt(H(n[0],n[1]),H(l,d),-t.angle);return H(c-t.x,u-t.y)}static isPointHandle(t,n){return n>=0&&(!X(t)||n===0||n===t.points.length-1)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Vt(H(o,r),H(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=Tc(i,o,r),[a,l,d,c]=Q(t,n),u=(a+d)/2,p=(l+c)/2,[m,h]=nt(H(s[0],s[1]),H(u,p),-t.angle);return H(m-t.x,h-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=fa(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){ft(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);ft(s,"The linear element does not exist in the provided Scene"),ft(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((p,m,h)=>{if(++c,p.push(m),o.includes(h)){let g=a[h+1];g||(d=!0),p.push(g?H((m[0]+g[0])/2,(m[1]+g[1])/2):H(m[0],m[1])),l.push(c+1),++c}return p},[]);if(n.mutateElement(s,{points:u}),d){let p=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:H(p[0]+30,p[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!i.includes(u));Re(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=H(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=fa({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];Re(t)&&t.polygon&&(o[0]=H(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=fa({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o,r){let{points:s}=t;if(Re(t)&&t.polygon){let u=i.get(0),p=i.get(s.length-1);u?i.set(s.length-1,{point:H(u.point[0],u.point[1]),isDragging:u.isDragging}):p&&i.set(0,{point:H(p.point[0],p.point[1]),isDragging:p.isDragging})}let a=i.get(0)?.point??H(0,0),[l,d]=a,c=X(t)?[i.get(0)?.point??s[0],i.get(s.length-1)?.point??s[s.length-1]]:s.map((u,p)=>{let m=i.get(p)?.point??u;return o?.moveMidPointsWithElement&&p!==0&&p!==s.length-1&&!i.has(p)?m:H(m[0]-l,m[1]-d)});e._updatePoints(t,n,c,l,d,o,{isDragging:Array.from(i.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&X(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=Vt(a,H(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<Xg/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!X(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.initialState,segmentMidpoint:{...t.initialState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,i,o,r,s,a){if(X(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=ga(t,i),d=ga(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,p=(d[0]+d[2])/2,m=(d[1]+d[3])/2,h=p-c,f=m-u,g=nt(H(o,r),H(h,f),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+g[0],y:t.y+g[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(X(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=Tc(o[0],o[1],r),{width:c,height:u}=Rc(a[0],a[1],l,d,s);return nt(H(c,u),H(0,0),-t.angle)}static getBoundTextElementCenter=(t,n)=>{if(t.points.length%2===1){let o=Math.floor(t.points.length/2);return e.getPointGlobalCoordinates(t,t.points[o],n)}let i=t.points.length/2-1;return e.getSegmentMidPoint(t,i+1,n)};static handleBoundTextDragging(t,n,i,o){let r=n.getNonDeletedElementsMap(),s=e.getElement(t.elementId,r),a=q(s,r);if(!s||!W(s)||!a)return null;let l=H(i-t.pointerOffset.x,o-t.pointerOffset.y),{segments:d,lengths:c,prefixSums:u,totalLength:p}=Cc(s,r);if(d.length===0||p===0)return null;let m=1/0,h=0,f=0;for(let b=0;b<d.length;b++){let{t:y,distance:w}=qg(d[b],l);w<m&&(m=w,h=b,f=y)}let g=Qg(d[h],f,c[h]),E=ma((u[h]+g)/p,0,1),x=e.getPointAtPathParameter(s,E,r);return x?(n.mutateElement(a,{labelPosition:E,x:x[0]-a.width/2,y:x[1]-a.height/2}),{...t,isDragging:!0}):null}static getPointAtPathParameter(t,n,i){if(!Number.isFinite(n))return null;let{segments:o,lengths:r,prefixSums:s,totalLength:a}=Cc(t,i);if(o.length===0)return null;let l=ma(n,0,1)*a,d=o.findIndex((p,m)=>l<=s[m+1]),c=d===-1?o.length-1:d,u=r[c]===0?0:ma((l-s[c])/r[c],0,1);return Jg(o[c],u,r[c])}static getBoundTextElementPosition=(t,n,i)=>{let o=Lc.get(n);if(o&&o.containerVersion===t.version&&o.textVersion===n.version)return o.position;let r=e.computeBoundTextElementPosition(t,n,i);return Lc.set(n,{containerVersion:t.version,textVersion:n.version,position:r}),r};static computeBoundTextElementPosition=(t,n,i)=>{if(t.points.length<2)return{x:n.x,y:n.y};if(W(t)&&n.labelPosition!=null){let r=e.getPointAtPathParameter(t,n.labelPosition,i);if(r)return{x:r[0]-n.width/2,y:r[1]-n.height/2}}let o=e.getBoundTextElementCenter(t,i);return{x:o[0]-n.width/2,y:o[1]-n.height/2}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:p}=e.getBoundTextElementPosition(t,o,n),m=u+o.width,h=p+o.height,f=H(d,c),g=nt(H(r,s),f,t.angle),E=nt(H(a,s),f,t.angle),x=nt(H(u,p),f,-t.angle),b=nt(H(m,p),f,-t.angle),y=nt(H(u,h),f,-t.angle),w=nt(H(m,h),f,-t.angle);return g[0]<E[0]&&g[1]>=E[1]?(r=Math.min(r,y[0]),a=Math.max(a,Math.max(b[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):g[0]>=E[0]&&g[1]>E[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],b[0])),s=Math.min(s,y[1]),l=Math.max(l,b[1])):g[0]>=E[0]?(r=Math.min(r,b[0]),a=Math.max(a,y[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):g[1]<=E[1]&&(r=Math.min(r,Math.min(b[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,b[1]),l=Math.max(l,y[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=Qe.generateElementShape(t,null),r=Jt(o[0]),[s,a,l,d]=ho(r),c=s+t.x,u=a+t.y,p=l+t.x,m=d+t.y,h=(c+p)/2,f=(u+m)/2,g=i&&q(t,n);return g?e.getMinMaxXYWithBoundText(t,n,[c,u,p,m],g):[c,u,p,m,h,f]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!X(a))return t;if(n&&n>0&&n<a.points.length){let l=ct(Lt(_g(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((m,h)=>(m[h.index]=h,m),{});d[n]={index:n,start:H(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:H(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((m,h)=>m.index-h.index),u=c.map(m=>m.index).reduce((m,h)=>h<n?m+1:m,0);r.mutateElement(a,{fixedSegments:c});let p=H(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:p,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:p}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},Kg=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},Bc=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let p=new Map(e.map(U=>{let D=s.points[U]??s.points.at(-1);return[U,{point:H(D[0]+t,D[1]+n),isDragging:!0}]}));if(!W(s))return{positions:p};let m=e.includes(0),h=e.includes(s.points.length-1),{start:f,end:g}=ca(s,p,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c,gridSize:l.getEffectiveGridSize()});if(X(s)){let U=m?f.element:h?g.element:null;return{positions:p,updates:{suggestedBinding:U?{element:U,midPoint:l.state.isMidpointSnappingEnabled?pa(H(i-u.pointerOffset.x,o-u.pointerOffset.y),U,r,l.state.zoom,s):void 0}:null},hit:U}}if(!m&&!h){let U={...s,points:s.points.map((L,P)=>p.get(P)?.point??L)},D=new Map(p);if(s.startBinding){let L=r.get(s.startBinding.elementId);if(L){let P=Gt(U,"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=Gt(U,"endBinding",s.endBinding,L,r)??null;P&&D.set(s.points.length-1,{point:P,isDragging:!0})}}return{positions:D}}if(m===h)return{positions:p};let E={suggestedBinding:null};f.mode===null?E.startBinding=null:f.mode?(E.startBinding={elementId:f.element.id,mode:f.mode,...si(s,f.element,"start",r,f.focusPoint)},m&&(E.startBinding.mode==="orbit"||!Li("COMPLEX_BINDINGS"))&&(E.suggestedBinding=f.element?{element:f.element,midPoint:pa(H(i-u.pointerOffset.x,o-u.pointerOffset.y),f.element,r,l.state.zoom,s)}:null)):m&&(E.suggestedBinding=l.state.suggestedBinding),g.mode===null?E.endBinding=null:g.mode?(E.endBinding={elementId:g.element.id,mode:g.mode,...si(s,g.element,"end",r,g.focusPoint)},h&&(E.endBinding.mode==="orbit"||!Li("COMPLEX_BINDINGS"))&&(E.suggestedBinding=g.element?{element:g.element,midPoint:pa(H(i-u.pointerOffset.x,o-u.pointerOffset.y),g.element,r,l.state.zoom,s)}:null)):h&&(E.suggestedBinding=l.state.suggestedBinding);let x=m?H(s.points[0][0]+t,s.points[0][1]+n):s.points[0],b=h?H(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],y={...s,points:[x,...s.points.slice(1,-1),b],startBinding:E.startBinding===void 0?s.startBinding:E.startBinding===null?null:E.startBinding,endBinding:E.endBinding===void 0?s.endBinding:E.endBinding===null?null:E.endBinding},w=s.endBinding&&y.startBinding&&m&&y.startBinding.elementId===s.endBinding.elementId,S=s.startBinding&&y.endBinding&&h&&s.startBinding.elementId===y.endBinding.elementId,I=y.endBinding?g.element??r.get(y.endBinding.elementId):null,A=S&&l.state.bindMode!=="inside"&&Li("COMPLEX_BINDINGS")?y.points[0]:I&&Gt(y,"endBinding",y.endBinding,I,r,h)||y.points[y.points.length-1];y.points[y.points.length-1]=A;let T=y.startBinding?f.element??r.get(y.startBinding.elementId):null,O=S&&Li("COMPLEX_BINDINGS")?y.points[0]:w&&l.state.bindMode!=="inside"&&Li("COMPLEX_BINDINGS")?A:T&&Gt(y,"startBinding",y.startBinding,T,r,m)||y.points[0],v=!(S&&l.state.bindMode!=="inside"&&Li("COMPLEX_BINDINGS"))&&!!I,N=Vt(O,y.points[0])!==0,C=new Set(e);T&&N&&C.add(0),I&&v&&C.add(s.points.length-1);let z=Array.from(C);return{updates:E,positions:new Map(z.map(U=>[U,U===0?{point:O,isDragging:!0}:U===s.points.length-1?{point:A,isDragging:!0}:p.get(U)])),hit:m?f.element:g.element}},kc=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]),ha=new WeakMap;function Cc(e,t){let n=ha.get(e);if(n){if(n.version===e.version)return n.metrics;ha.delete(e)}let i=Vg(e,t),o=i.map(Zg),r=new Array(o.length+1);r[0]=0;for(let a=0;a<o.length;a++)r[a+1]=r[a]+o[a];let s={segments:i,lengths:o,prefixSums:r,totalLength:r[o.length]};return ha.set(e,{version:e.version,metrics:s}),s}var Zg=e=>wr(e)?Nc(e):Vt(e[0],e[1]),qg=(e,t)=>{if(wr(e)){let i=Wg(e,t);return{t:i,distance:Vt(t,Yg(e,i))}}let n=Ug(t,e);return{t:n,distance:Vt(t,Gc(e,n))}},Qg=(e,t,n)=>wr(e)?Hg(e,t):t*n,Jg=(e,t,n)=>wr(e)?Oc(e,t,n):Gc(e,t);M();import{arrayToMap as Ft}from"@excalidraw/common";import{isPointWithinBounds as hE,pointFrom as Sa,segmentsIntersectAt as gE}from"@excalidraw/math";M();import{arrayToMap as rE,isShallowEqual as sE}from"@excalidraw/common";M();var eE=(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}}},zc=function(){let e=null,t=null,n=null,i=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let d={};for(let p of r){let m=p.groupIds;if(a.editingGroupId){let h=m.indexOf(a.editingGroupId);h>-1&&(m=m.slice(0,h))}if(m.length>0){let h=m[m.length-1];d[h]=!0}}let c={},u=s.reduce((p,m)=>{if(m.isDeleted)return p;let h=m.groupIds.find(f=>d[f]);return h&&(p[m.id]=!0,Array.isArray(c[h])?c[h].push(m.id):c[h]=[m.id]),p},{});for(let p of Object.keys(c))c[p].length<2&&d[p]&&(d[p]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:Ea({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):Kt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Ea(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),tE=(e,t)=>xa(e,t)!=null,xa=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),nE=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),_c=(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,...eE(r,n,e)}}}return n.selectedGroupIds},pM=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),iE=(e,t)=>e.groupIds.includes(t),it=(e,t)=>{let n=[];for(let i of e.values())iE(i,t)&&n.push(i);return n},oE=(e,t)=>e.groupIds.find(n=>t[n]),fM=(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},hM=(e,t)=>e.filter(n=>!t[n]),gM=(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=q(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},Hc=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},Uc=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},Wc=e=>e.groupIds.length>0,Yc=(e,t,n)=>{let i=[...e],o=t?e.indexOf(t):-1,r=o>-1?o:e.length;for(let s=0;s<r;s++)i[s]=n(i[s]);return i},Pr=(e,t,n)=>{let i=new Map,r=nE(n).length===1&&e.every(s=>tE(n,s));return e.forEach(s=>{if(pe(s))return;let a,l=oE(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=q(s,t);i.set(a,[...d,s,...c?[c]:[]])}),[...i.values()]};var aE=e=>e.locked||pe(e),lE=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),dE=e=>{let t=new Set;return e.forEach(n=>{J(n)&&t.add(n.id)}),lE(e,t)},Xc=(e,t,n,i=!0,o="contain")=>{let[r,s,a,l]=Q(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),p=Math.max(s,l);return $c({elements:e,bounds:[d,c,u,p],elementsMap:n,type:o,shouldIgnoreElementFromSelection:aE,excludeElementsInFrames:i})},AM=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=jc(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},DM=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]){$e(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&&pe(r)&&$e(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{J(s)&&zn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},vM=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement&&t.activeTool.type!=="autoshape"?[t.newElement]:Kt(e,t,{includeBoundTextElement:!0}),Ea=(e,t)=>sE(t.selectedElementIds,e)?t.selectedElementIds:e,cE=(e,t)=>{let n=e.filter(ee);if(n.length===1){let i=n[0],o=i.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===i.id||o.includes(s.id)))return new R(i,rE(t))}return null},LM=(e,t,n)=>({selectedLinearElement:cE(e,t),...zc({editingGroupId:n.editingGroupId,selectedElementIds:dE(e).reduce((i,o)=>(pe(o)||(i[o.id]=!0),i),{})},t,n,null)}),BM=(e,t)=>t.editingTextElement||e.length===1&&j(e[0])&&e[0]||null;M();import{arrayToMap as Sr}from"@excalidraw/common";import{validateOrderKey as uE,generateNKeysBetween as mE}from"@excalidraw/fractional-indexing";var ba=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},pE=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=d=>`${d?.index}:${d?.id}:${d?.type}:${d?.isDeleted}:${d?.version}:${d?.versionNonce}`,a=n?Sr(e):null,l=e.map(d=>d.index);for(let[d,c]of l.entries()){let u=l[d-1],p=l[d+1];if(ya(c,u,p)||r.push(`Fractional indices invariant has been compromised: "${s(e[d-1])}", "${s(e[d])}", "${s(e[d+1])}"`),n&&a&&Wt(e[d])&&$e(e[d])){let m=e[d],h=Ct(m),f=h?a.get(h):null;f&&$e(f)&&f.index<=m.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(f)}", "${s(m)}"`)}}if(r.length){let d=new ba,c=[];if(o&&(c.push("Additional reconciliation context:"),c.push(o.localElements.map(u=>s(u))),c.push(o.remoteElements.map(u=>s(u)))),i||console.error(r.join(`
|
|
11
11
|
|
|
12
|
-
`),d.stack,e.map(u=>s(u)),...c),t)throw d}},Jd=e=>e.sort((t,n)=>Qd(t)&&Qd(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),ni=(e,t)=>{try{let n=lr(e),i=gh(e,t),o=Vs(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});hh(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)Fe(s,n,{index:a})}catch{$s(e)}return e},$s=e=>{let t=lr(e),n=tc(e),i=Vs(e,n);for(let[o,{index:r}]of i)Fe(o,t,{index:r});return e},ec=e=>{let t=lr(e),n=tc(e),i=Vs(e,n);for(let[o,{index:r}]of i)t.set(o.id,Ke(o,{index:r}));return t},gh=(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},tc=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),js(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(js(u,m,h))break;[n,o]=[m,p],[i,r]=[h,f],c.push(l)}c.push(r),t.push(c)}}return t},js=(e,t,n)=>{if(!e)return!1;try{ph(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},Vs=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=fh(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},Qd=e=>!!e.index;var nc=(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&&Fe(a,i,{frameId:s??null})}};function Si(e,t,n){let i=Ii(t,n),o=Ii(e,n);return i.some(s=>o.some(a=>xh(s,a)))}var ic=(e,t,n)=>dr(Zd(e,t,n,!1)).filter(i=>!J(i)&&!i.frameId||i.frameId===t.id),Ks=(e,t,n)=>Qs(ue(e,n),ue(t,n)),EI=(e,t)=>{let n=Gt(e);return e.filter(i=>Si(i,t,n))},Gn=(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},Ln=(e,t,n)=>Gn([e],t,n)||Si(e,t,n)||Ks(e,t,n),xI=(e,t,n)=>{let[i,o,r,s]=Z(t,n);return Eh(Zs(i,o),Zs(e.x,e.y),Zs(r,s))},bI=(e,t,n)=>{let i=Gt(e),o=t.flatMap(r=>Qe(e,r));return o.length===0?!0:!!o.find(r=>Gn([r],n,i)||Si(r,n,i))},wI=(e,t,n)=>{let i=Gt(e),o=t.flatMap(r=>Qe(e,r));return o.length===0?!0:o.find(r=>Gn([r],n,i)||Si(r,n,i))===void 0},yI=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,Bn(e,i))}return t},Bn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},qs=e=>e.filter(t=>J(t)),PI=e=>{let t=Gt(qs(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},II=(e,t,n,i)=>{let o=Bn(e,t.id),r=new Set(o),s=new Set([...ic(e,t,i),...o.filter(p=>Ks(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(!Si(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=kn(c),m=Yd(u,n);for(let[p,h]of Object.entries(m))if(h){let f=Qe(e,p);if(Gn(f,t,i))for(let g of f)r.add(g)}return[...r].filter(p=>!(oe(p)&&p.containerId))},SI=(e,t,n)=>bh(dr(e,ic(e,t,n)),t,n),bh=(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=!Gn(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Cn=(e,t)=>e.frameId&&t.get(e.frameId)||null,MI=(e,t)=>{let n=new Set,i=Gt(e);e=dr(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=>Ln(d,t,i)))for(let d of l)r.push(d)}}else Ln(s,t,i)&&r.push(s);return r},wh=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},yh=(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},Ph=(e,t,n)=>{let i=Gt(e),o=wh(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 dr(e,t)){if(J(c)||c.frameId&&s.has(c.frameId))continue;r.add(c);let u=de(c,i);u&&!r.has(u)&&r.add(u)}for(let c of r)c.frameId!==n.id&&Fe(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=yh(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]))},oc=(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=de(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)Fe(o,t,{frameId:null})},Ih=(e,t)=>{let n=Bn(e,t.id);return oc(n,Gt(e)),e},AI=(e,t,n)=>Ph(Ih(e,n),t,n).slice(),TI=(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)&&!rc(a,s,t)&&r.add(a)}),r.size>0&&oc(r,s),e},dr=(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},Sh=(e,t,n)=>{let i=oe(e)&&Ue(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Cn(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Cn(i,t)},rc=(e,t,n,i)=>{let o=i?.targetFrame??Sh(e,t,n);if(!o)return!1;let r=oe(e)&&Ue(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 Ln(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(Zt(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(Ln(l,o,t))return s(!0),!0;return!1},DI=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Si(e,t,i)||Ks(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Gn([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=rc(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},Mh="Frame",Ah="AI Frame",Th=e=>ko(e)?Mh:Ah,vI=e=>e.name===null?Th(e):e.name,BI=(e,t,n)=>e.filter(i=>(!i.frameId||i.frameId===t.id)&>(ue(i,n),ue(t,n))),LI=e=>{let t=Gt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Fh=(e,t)=>Vn(e)&&!t.imageCache.has(e.fileId),fr=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}},Rh=(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*=Bh/100),r},zh=(e,t,n)=>{let r=fr(e),[s,a,l,d]=Z(e,t),c=K(e)||be(e)?Nn(s,l):e.width,u=K(e)||be(e)?Nn(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}},lc=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=fr(e),{width:l,height:d,scale:c}=zh(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?Nn(e.x,h)*window.devicePixelRatio*c:0,m=e.y>f?Nn(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=ci.canvas(r);return mr(e,p,s,i),s.restore(),{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,containingFrameOpacity:Cn(e,t)?.opacity||100,imageCrop:ke(e)?e.crop:null}},jI=14,dc=typeof document<"u"?document.createElement("img"):{src:""};dc.src=`data:${ta.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 cc=typeof document<"u"?document.createElement("img"):{src:""};cc.src=`data:${ta.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 _h=(e,t,n)=>{t.fillStyle=n===Mi.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"?cc:dc,e.width/2-o/2,e.height/2-o/2,o,o)},mr=(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=pr(e.strokeColor,i.theme===Mi.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=Vn(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,nn(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===Mi.DARK&&o?.mimeType===ta.svg;if(c&&Nh){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=Lh),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else _h(e,n,i.theme);n.restore();break}default:if(oe(e)){let o=Gh(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=Ch(e),n.fillStyle=pr(e.strokeColor,i.theme===Mi.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}},Kc=e=>e.sort((t,n)=>Vc(t)&&Vc(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),di=(e,t)=>{try{let n=Sr(e),i=fE(e,t),o=Pa(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});pE(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)He(s,n,{index:a})}catch{wa(e)}return e},wa=e=>{let t=Sr(e),n=qc(e),i=Pa(e,n);for(let[o,{index:r}]of i)He(o,t,{index:r});return e},Zc=e=>{let t=Sr(e),n=qc(e),i=Pa(e,n);for(let[o,{index:r}]of i)t.set(o.id,Me(o,{index:r}));return t},fE=(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},qc=e=>{let t=[],n,i,o=-1,r=0,s=d=>{let c=e[o]?e[o].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,o]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let p=e[u]?.index;if(!c&&p||c&&p&&p>c)return[p,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,o]=s(l),[i,r]=a(l),ya(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[h,f]=a(l);if(ya(u,p,h))break;[n,o]=[p,m],[i,r]=[h,f],c.push(l)}c.push(r),t.push(c)}}return t},ya=(e,t,n)=>{if(!e)return!1;try{uE(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},Pa=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=mE(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},Vc=e=>!!e.index;var Qc=(e,t,n)=>{let i=Ft(e);for(let o of t)if(o.frameId){let r=n.get(o.id),s=n.get(o.frameId),a=r&&i.get(r);a&&He(a,i,{frameId:s??null})}};function ki(e,t,n){let i=Bi(t,n),o=Bi(e,n);return i.some(s=>o.some(a=>gE(s,a)))}var Jc=(e,t,n)=>Ir(Xc(e,t,n,!1)).filter(i=>!J(i)&&!i.frameId||i.frameId===t.id),Ia=(e,t,n)=>Ta(ae(e,n),ae(t,n)),QM=(e,t)=>{let n=Ft(e);return e.filter(i=>ki(i,t,n))},Un=(e,t,n)=>{let[i,o,r,s]=Q(t,n),[a,l,d,c]=ot(e);return i<=a&&o<=l&&r>=d&&s>=c},_n=(e,t,n)=>Un([e],t,n)||ki(e,t,n)||Ia(e,t,n),JM=(e,t,n)=>{let[i,o,r,s]=Q(t,n);return hE(Sa(i,o),Sa(e.x,e.y),Sa(r,s))},eT=(e,t,n)=>{let i=Ft(e),o=t.flatMap(r=>it(e,r));return o.length===0?!0:!!o.find(r=>Un([r],n,i)||ki(r,n,i))},tT=(e,t,n)=>{let i=Ft(e),o=t.flatMap(r=>it(e,r));return o.length===0?!0:o.find(r=>Un([r],n,i)||ki(r,n,i))===void 0},nT=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,zn(e,i))}return t},zn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Ma=e=>e.filter(t=>J(t)),iT=e=>{let t=Ft(Ma(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},oT=(e,t,n,i)=>{let o=zn(e,t.id),r=new Set(o),s=new Set([...Jc(e,t,i),...o.filter(m=>Ia(m,t,i))]),a=o.filter(m=>!s.has(m)),l=new Set(Array.from(s).flatMap(m=>m.groupIds));for(let m of a)if(!ki(m,t,i))m.groupIds.length===0&&r.delete(m);else if(m.groupIds.length>0)for(let h of m.groupIds)l.add(h);for(let m of a)if(m.groupIds.length>0){let h=!0;for(let f of m.groupIds)l.has(f)&&(h=!1);h&&r.delete(m)}let d=Array.from(s).filter(m=>m.groupIds.length===0);for(let m of d)r.add(m);let c=Array.from(s).filter(m=>m.groupIds.length>0),u=Ci(c),p=_c(u,n);for(let[m,h]of Object.entries(p))if(h){let f=it(e,m);if(Un(f,t,i))for(let g of f)r.add(g)}return[...r].filter(m=>!(j(m)&&m.containerId))},rT=(e,t,n)=>EE(Ir(e,Jc(e,t,n)),t,n),EE=(e,t,n)=>{let i=[],o=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>o.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>it(n,l)));s=!Un(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Hn=(e,t)=>e.frameId&&t.get(e.frameId)||null,sT=(e,t)=>{let n=new Set,i=Ft(e);e=Ir(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=it(e,a);if(l.some(d=>_n(d,t,i)))for(let d of l)r.push(d)}}else _n(s,t,i)&&r.push(s);return r},xE=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},bE=(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},yE=(e,t,n)=>{let i=Ft(e),o=xE(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 Ir(e,t)){if(J(c)||c.frameId&&s.has(c.frameId))continue;r.add(c);let u=q(c,i);u&&!r.has(u)&&r.add(u)}for(let c of r)c.frameId!==n.id&&He(c,i,{frameId:n.id});if(!r.size||o===n.id)return e;let a=Array.from(e.values()).filter(c=>!r.has(c)),l=bE(a,n.id);if(l===null)return e;let d=[...a.slice(0,l),...r,...a.slice(l)];return di(d,Ft([...r])),Array.isArray(e)?d:new Map(d.map(c=>[c.id,c]))},eu=(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=q(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)He(o,t,{frameId:null})},wE=(e,t)=>{let n=zn(e,t.id);return eu(n,Ft(e)),e},aT=(e,t,n)=>yE(wE(e,n),t,n).slice(),lT=(e,t,n)=>{let i=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),o=new Set(i);if(t.editingGroupId)for(let a of i)a.groupIds.length===0?o.add(a):a.groupIds.flatMap(l=>it(e,l)).forEach(l=>o.add(l));let r=new Set,s=Ft(e);return o.forEach(a=>{a.frameId&&!J(a)&&!tu(a,s,t)&&r.add(a)}),r.size>0&&eu(r,s),e},Ir=(e,t)=>{let n=new Set,i=t||e;for(let s of i.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let o=new Set;for(let s of n)it(e,s).some(a=>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},PE=(e,t,n)=>{let i=j(e)&&Be(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Hn(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Hn(i,t)},tu=(e,t,n,i)=>{let o=i?.targetFrame??PE(e,t,n);if(!o)return!1;let r=j(e)&&Be(e,t)||e,s=l=>{i?.checkedGroups&&r.groupIds.forEach(d=>{i.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[o.id])return!0;if(r.groupIds.length===0)return _n(r,o,t);for(let l of r.groupIds)if(i?.checkedGroups?.has(l))return i.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>i?.checkedGroups?!i.checkedGroups.has(l):!0).flatMap(l=>it(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(Kt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(J(l))return s(!1),!1;for(let l of a)if(_n(l,o,t))return s(!0),!0;return!1},dT=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=ki(e,t,i)||Ia(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Un([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=tu(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},SE="Frame",IE="AI Frame",ME=e=>Vo(e)?SE:IE,cT=e=>e.name===null?ME(e):e.name,uT=(e,t,n)=>e.filter(i=>(!i.frameId||i.frameId===t.id)&&yt(ae(i,n),ae(t,n))),mT=e=>{let t=Ft(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var zE=(e,t)=>ei(e)&&!t.imageCache.has(e.fileId),go=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}},au={x:0,y:0},_E=(e,t,n)=>{let i=j(e)?Be(e,t):null;return n?.get((i??e).id)?.offset},DT=(e,t)=>t.x===0&&t.y===0?e:{...e,x:e.x+t.x,y:e.y+t.y},HE=(e,t,n,i=t)=>{let{elementRenderOverrides:o,elementsPendingErasure:r,pendingFlowchartNodes:s}=n,a=o?.get(e.id),l=Hn(e,t),c=(l?nu(o?.get(l.id)?.opacity??l.opacity,0,100):100)*nu(a?.opacity??e.opacity,0,100)/1e4;(r.has(e.id)||s?.some(p=>p.id===e.id)||l&&r.has(l.id))&&(c*=DE/100);let u=_E(e,i,o);return{opacity:c,offset:u??au}},UE=(e,t,n)=>{let r=go(e),[s,a,l,d]=Q(e,t),c=ee(e)||ge(e)?Yn(s,l):e.width,u=ee(e)||ge(e)?Yn(a,d):e.height,p=c*window.devicePixelRatio+r*2,m=u*window.devicePixelRatio+r*2,h=n.value;return(p*h>32767||m*h>32767)&&(h=Math.min(32767/p,32767/m)),p*m*h*h>16777216&&(h=Math.sqrt(16777216/(p*m))),p=Math.floor(p*h),m=Math.floor(m*h),{width:p,height:m,scale:h}},lu=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=go(e),{width:l,height:d,scale:c}=UE(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,p=0;if(ee(e)||ge(e)){let[h,f]=Q(e,t);u=e.x>h?Yn(e.x,h)*window.devicePixelRatio*c:0,p=e.y>f?Yn(e.y,f)*window.devicePixelRatio*c:0,s.translate(u,p)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let m=xi.canvas(r);return Ar(e,m,s,i),s.restore(),{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:p,containingFrameOpacity:Hn(e,t)?.opacity||100,imageCrop:Oe(e)?e.crop:null}},vT=14,du=typeof document<"u"?document.createElement("img"):{src:""};du.src=`data:${Ba.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 cu=typeof document<"u"?document.createElement("img"):{src:""};cu.src=`data:${Ba.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 WE=(e,t,n)=>{t.fillStyle=n===mn.DARK?"#2E2E2E":"#E7E7E7",t.fillRect(0,0,e.width,e.height);let i=Math.min(e.width,e.height),o=Math.min(i,Math.min(i*.4,100));t.drawImage(e.status==="error"?cu:du,e.width/2-o/2,e.height/2-o/2,o,o)},La=(e,t)=>{e.beginPath();for(let n of t)n.type==="move"?e.moveTo(n.point.x,n.point.y):n.type==="line"?e.lineTo(n.point.x,n.point.y):e.quadraticCurveTo(n.control.x,n.control.y,n.point.x,n.point.y);e.closePath()},ou=(e,t)=>{La(e,t),e.fill()},YE=(e,t)=>{e.save(),La(e,t),e.clip(),e.lineWidth=GE*2,e.strokeStyle=`rgba(0, 0, 0, ${OE})`,La(e,t),e.stroke(),e.restore()},Ar=(e,t,n,i)=>{switch(e.type){case"stickynote":{n.save(),n.fillStyle=`rgba(0, 0, 0, ${FE})`,ou(n,Xs(e,{shadow:!0}));let o=Xs(e);n.fillStyle=ci(e.backgroundColor,i.theme===mn.DARK),ou(n,o),YE(n,o);let r=Gd(e);r&&(n.font=`${Da.fontSize}px ${Da.fontFamily}`,n.textAlign="right",n.textBaseline="alphabetic",n.fillStyle=ci(e.strokeColor,i.theme===mn.DARK),n.globalAlpha*=Da.opacity,n.fillText(r.text,r.x,r.y)),n.restore();break}case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(Qe.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Qe.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=Qe.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=ci(e.strokeColor,i.theme===mn.DARK),n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{n.save();let o=e.fileId!==null?i.imageCache.get(e.fileId):null,r=ei(e)?o?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,cn(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight},c=i.theme===mn.DARK&&o?.mimeType===Ba.svg;if(c&&NE){let u=window.devicePixelRatio||1,p=document.createElement("canvas");p.width=e.width*u,p.height=e.height*u;let m=p.getContext("2d");if(m){m.scale(u,u),m.drawImage(r,s,a,l,d,0,0,e.width,e.height);let h=m.getImageData(0,0,p.width,p.height),f=h.data;for(let g=0;g<f.length;g+=4)f[g]=255-f[g],f[g+1]=255-f[g+1],f[g+2]=255-f[g+2];m.putImageData(h,0,0),n.drawImage(p,0,0,p.width,p.height,0,0,e.width,e.height)}}else c&&(n.filter=vE),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else WE(e,n,i.theme);n.restore();break}default:if(j(e)){let o=BE(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=LE(e),n.fillStyle=ci(e.strokeColor,i.theme===mn.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=_o(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}`)}},oo=new WeakMap,ac=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=oo.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=ke(e)?e.crop:null,l=Cn(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.imageCrop!==a||r.containingFrameOpacity!==l){let d=lc(e,t,o,n,i);return d?(oo.set(e,d),d):null}return r},ea=(e,t,n,i,o)=>{let r=e.element,s=fr(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=de(r,o);if(X(r)&&p){let[,,,,h,f]=Z(p,o),g=Math.max(Nn(a,d),Nn(l,c))*window.devicePixelRatio+s*10;t.beginPath(),t.rect(u-g,m-g,g*2,g*2),t.rect((h-p.width/2-On+i.scrollX)*window.devicePixelRatio,(f-p.height/2-On+i.scrollY)*window.devicePixelRatio,(p.width+On*2)*window.devicePixelRatio,(p.height+On*2)*window.devicePixelRatio),t.clip("evenodd")}if(t.translate(u,m),t.rotate(r.angle),"scale"in e.element&&!Fh(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=de(r,o),f=fs(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()},$I=(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()},VI=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=Rh(e,Cn(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?vh: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=ur.strokeWidth/s.zoom.value,o.strokeStyle=pr(ur.strokeColor,s.theme===Mi.DARK),Ml(e)&&(o.strokeStyle=s.theme===Mi.LIGHT?"#7affd7":pr("#1d8264")),ur.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,ur.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),mr(e,i,o,r),o.restore()}else{let l=ac(e,n,r,s);if(!l)return;ea(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=Ue(e,t);if(X(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=de(e,t);if(X(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-On,M=y-p-x.height/2-On,S=x.width+On*2,T=x.height+On*2,A=Math.max(Nn(l,c),Nn(d,u))+fr(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),mr(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),mr(e,i,o,r);o.restore()}else{let l=ac(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Dh(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&ke(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=lc(Pl(l.element,t),n,s.zoom,r,s);c&&ea(c,o,r,s,n),o.restore()}ea(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function ZI(e,t,n){let i=ue({...e,angle:0},n),o=cr((i[0]+i[2])/2,(i[1]+i[3])/2);return Oh(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(sc(r[r.length-1][1],Js(cr(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[sc(Js(cr(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),Js(cr(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),oo.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;oo.delete(t);let o=Vh(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:Uh.white,embedsValidationStatus:null,theme:ia.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||ia.LIGHT}),o}},jh=e=>[8,8+e],hc=e=>[1.5,6+e];function $h(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&&$l(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"?jh(e.strokeWidth):e.strokeStyle==="dotted"?hc(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:$h(e),stroke:ao(e.strokeColor,n),preserveVertices:t||e.roughness<Hh.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=so(e.backgroundColor)?void 0:ao(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:ao(e.backgroundColor,n)),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},mc=(e,t,n)=>Go(e)&&(t||Sl(e)&&n?.get(e.id)!==!0)&&so(e.backgroundColor)&&so(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:Co(e)?{...e,strokeColor:so(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:so(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,ro=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},hr=(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)]},ii=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=hc(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},na=(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=ao(e.strokeColor,a),d=ao(s,a),c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return na(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 ro(o,et(e,t,n,i),ii(e,r));case"cardinality_many":return hr(o,et(e,t,n,i),ii(e,r));case"cardinality_one_or_many":{let m=ii(e,r);return[...hr(o,et(e,t,n,"cardinality_many"),m),...ro(o,et(e,t,n,"cardinality_one",c),m)]}case"cardinality_exactly_one":{let m=ii(e,r);return[...ro(o,et(e,t,n,"cardinality_one",-.5),m),...ro(o,et(e,t,n,"cardinality_one"),m)]}case"cardinality_zero_or_one":{let m=ii(e,r);return[...na(o,r,l,et(e,t,n,"circle_outline",1.5),d,u),...ro(o,et(e,t,n,"cardinality_one",-.5),m)]}case"cardinality_zero_or_many":{let m=ii(e,r);return[...hr(o,et(e,t,n,"cardinality_many"),m),...na(o,r,l,et(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return hr(o,et(e,t,n,i),ii(e,r))}},Fl=(e,t)=>{let n=new bt,i={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=re(e,t);switch(e.type){case"line":case"arrow":{let r=e.points.length?e.points:[ye(0,0)];return j(e)?n.path(gc(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=cn(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:[cn(ye(e.x+s.data[0],e.y+s.data[1]),o,e.angle),cn(ye(e.x+s.data[2],e.y+s.data[3]),o,e.angle),cn(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=cn(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=xn(e.points,.75);return n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=cn(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:[cn(ye(e.x+s.data[0],e.y+s.data[1]),o,e.angle),cn(ye(e.x+s.data[2],e.y+s.data[3]),o,e.angle),cn(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()}})}}},Vh=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===ia.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=nn(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(mc(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,ct(mc(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,h,f]=pi(e);if(e.roundness){let g=nn(Math.abs(l-h),e),E=nn(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=lr(e.fontSize,e.lineHeight),d=kE(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}`)}},Eo=new WeakMap,ru=(e,t,n,i)=>{let o=n?i.zoom:RE,r=Eo.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=Oe(e)?e.crop:null,l=Hn(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.imageCrop!==a||r.containingFrameOpacity!==l){let d=lu(e,t,o,n,i);return d?(Eo.set(e,d),d):null}return r},uu=(e,t)=>!t?.shouldCacheIgnoreZoom&&(!e.angle||TE(e.angle)),su=1e-6,va=(e,t,n,i,o,r)=>{let s=e.element,a=window.devicePixelRatio,l=go(s),[d,c,u,p]=Q(s,o),m=((d+u)/2+r.x+i.scrollX)*a,h=((c+p)/2+r.y+i.scrollY)*a;t.save(),t.scale(1/a,1/a);let f=q(s,o);if(W(s)&&f){let[,,,,b,y]=Q(f,o),w=Math.max(Yn(d,u),Yn(c,p))*a+l*10;t.beginPath(),t.rect(m-w,h-w,w*2,w*2),t.rect((b-f.width/2-Wn+r.x+i.scrollX)*a,(y-f.height/2-Wn+r.y+i.scrollY)*a,(f.width+Wn*2)*a,(f.height+Wn*2)*a),t.clip("evenodd")}t.translate(m,h),t.rotate(s.angle),"scale"in e.element&&!zE(s,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-m,-h);let g=(d+r.x+i.scrollX)*a-l,E=(c+r.y+i.scrollY)*a-l,x=t.getTransform();if(uu(s,i)){let{a:b,b:y,c:w,d:S,e:I,f:A}=x,T=j(s)?Be(s,o):null,O=T&&!T.angle?T:s,v=O===s?null:Q(O,o),N=v?.[0]??d,C=v?.[1]??c,z=O===s?l:go(O),U=(N+r.x+i.scrollX)*a-z,D=(C+r.y+i.scrollY)*a-z,L=(d-N)*a+z-l,P=(c-C)*a+z-l;t.setTransform(b,y,w,S,Math.round(b*U+w*D+I)+Math.round(b*L+w*P+su),Math.round(y*U+S*D+A)+Math.round(y*L+S*P+su)),g=0,E=0}if(t.drawImage(e.canvas,g,E,e.canvas.width/e.scale,e.canvas.height/e.scale),t.setTransform(x),G.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&Wt(s)){let b=q(s,o),y=zs(s);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((y.x+r.x+i.scrollX)*a,(y.y+r.y+i.scrollY)*a,kt(s,b)*a,so(s,b)*a)}t.restore()},LT=(e,t,n,i)=>{t.save(),t.translate(e.x+n.scrollX,e.y+n.scrollY),t.fillStyle=ci("rgba(0, 0, 200, 0.04)",n.theme===mn.DARK);let o=.5/n.zoom.value;t.fillRect(o,o,e.width,e.height),t.lineWidth=1/n.zoom.value,t.strokeStyle=i,t.strokeRect(o,o,e.width,e.height),t.restore()},BT=(e,t,n,i,o,r,s,a=HE(e,t,r,n))=>{let l=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];o.save(),o.globalAlpha=a.opacity*(l?AE:1),(r.isExporting||J(e))&&(a.offset.x||a.offset.y)&&o.translate(a.offset.x,a.offset.y);try{XE(e,t,n,i,o,r,s,a)}finally{o.restore()}},XE=(e,t,n,i,o,r,s,a)=>{switch(e.type){case"magicframe":case"frame":{s.frameRendering.enabled&&s.frameRendering.outline&&(o.save(),o.translate(e.x+s.scrollX,e.y+s.scrollY),o.fillStyle="rgba(0, 0, 200, 0.04)",o.lineWidth=Tr.strokeWidth/s.zoom.value,o.strokeStyle=ci(Tr.strokeColor,s.theme===mn.DARK),rd(e)&&(o.strokeStyle=s.theme===mn.LIGHT?"#7affd7":ci("#1d8264")),Tr.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Tr.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(r.isExporting){let[l,d,c,u]=Q(e,t),p=(l+c)/2+s.scrollX,m=(d+u)/2+s.scrollY,h=(c-l)/2-(e.x-l),f=(u-d)/2-(e.y-d);o.save(),o.translate(p,m),o.rotate(e.angle),o.translate(-h,-f),Ar(e,i,o,r),o.restore()}else{let l=ru(e,n,r,s);if(!l)return;va(l,o,r,s,n,a.offset)}break}case"rectangle":case"stickynote":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=Q(e,t),p=(l+c)/2,m=(d+u)/2,h=p+s.scrollX,f=m+s.scrollY,g=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);if(j(e)){let b=Be(e,t);if(W(b)){let y=R.getBoundTextElementPosition(b,e,t);g=(c-l)/2-(y.x-l),E=(u-d)/2-(y.y-d)}}o.save(),o.translate(h,f);let x=q(e,t);if(W(e)&&x){g=e.width/2-(e.x-l),E=e.height/2-(e.y-d);let[,,,,b,y]=Q(x,t),w=b-p-x.width/2-Wn,S=y-m-x.height/2-Wn,I=x.width+Wn*2,A=x.height+Wn*2,T=Math.max(Yn(l,c),Yn(d,u))+go(e)*10;o.save(),o.beginPath(),o.rect(-T,-T,T*2,T*2),o.rect(w,S,I,A),o.clip("evenodd"),o.rotate(e.angle),o.translate(-g,-E),Ar(e,i,o,r),o.restore()}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-g,-E),Ar(e,i,o,r);o.restore()}else{let l=ru(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(uu(e,s)&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&Oe(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=lu(nd(l.element,t),n,s.zoom,r,s);c&&va(c,o,r,s,n,au),o.restore()}va(l,o,r,s,n,a.offset),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}};function kT(e,t,n){let i=ae({...e,angle:0},n),o=Mr((i[0]+i[2])/2,(i[1]+i[3])/2);return CE(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(iu(r[r.length-1][1],Aa(Mr(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[iu(Aa(Mr(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),Aa(Mr(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}var Qe=class e{static rg=new bt;static cache=new WeakMap;static get=(t,n)=>{let i=e.cache.get(t);if(i&&(n===null||i.theme===n))return i.shape};static delete=t=>{e.cache.delete(t),Eo.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;Eo.delete(t);let o=ex(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:KE.white,embedsValidationStatus:null,theme:Ca.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||Ca.LIGHT}),o}},QE=e=>[8,8+e],Eu=e=>[1.5,6+e];function JE(e){let t=e.roughness,n=Math.max(e.width,e.height),i=Math.min(e.width,e.height);return i>=20&&n>=50||i>=15&&e.roundness&&jd(e.type)||ee(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var ht=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?QE(e.strokeWidth):e.strokeStyle==="dotted"?Eu(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:JE(e),stroke:yo(e.strokeColor,n),preserveVertices:t||e.roughness<jE.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=bo(e.backgroundColor)?void 0:yo(e.backgroundColor,n),e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return Nt(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:yo(e.backgroundColor,n)),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},pu=(e,t,n)=>jo(e)&&(t||od(e)&&n?.get(e.id)!==!0)&&bo(e.backgroundColor)&&bo(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:$o(e)?{...e,strokeColor:bo(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:bo(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,xo=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},Dr=(e,t,n)=>{if(t===null)return[];let[i,o,r,s,a,l]=t;return[e.line(r,s,i,o,n),e.line(a,l,i,o,n)]},ui=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=Eu(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},ka=(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)]},fu=(e,t,n,i,o,r,s,a)=>{if(i===null)return[];let l=yo(e.strokeColor,a),d=yo(s,a),c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return ka(o,r,l,rt(e,t,n,i),i==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let p=rt(e,t,n,i);if(p===null)return[];let[m,h,f,g,E,x]=p,b={...r,fill:i==="triangle_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete b.strokeLineDash,[o.polygon([[m,h],[f,g],[E,x],[m,h]],b)]}case"diamond":case"diamond_outline":{let p=rt(e,t,n,i);if(p===null)return[];let[m,h,f,g,E,x,b,y]=p,w={...r,fill:i==="diamond_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete w.strokeLineDash,[o.polygon([[m,h],[f,g],[E,x],[b,y],[m,h]],w)]}case"cardinality_one":return xo(o,rt(e,t,n,i),ui(e,r));case"cardinality_many":return Dr(o,rt(e,t,n,i),ui(e,r));case"cardinality_one_or_many":{let p=ui(e,r);return[...Dr(o,rt(e,t,n,"cardinality_many"),p),...xo(o,rt(e,t,n,"cardinality_one",c),p)]}case"cardinality_exactly_one":{let p=ui(e,r);return[...xo(o,rt(e,t,n,"cardinality_one",-.5),p),...xo(o,rt(e,t,n,"cardinality_one"),p)]}case"cardinality_zero_or_one":{let p=ui(e,r);return[...ka(o,r,l,rt(e,t,n,"circle_outline",1.5),d,u),...xo(o,rt(e,t,n,"cardinality_one",-.5),p)]}case"cardinality_zero_or_many":{let p=ui(e,r);return[...Dr(o,rt(e,t,n,"cardinality_many"),p),...ka(o,r,l,rt(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return Dr(o,rt(e,t,n,i),ui(e,r))}},xu=e=>Pn(e.points,.75),hu=new WeakMap,ac=e=>{let t=hu.get(e);if(t?.version===e.version)return t.polygon;let n=new bt().curve(xu(e),{roughness:0,disableMultiStroke:!0}).sets[0].ops,i=[];for(let{data:r}of n)for(let s=0;s<r.length;s+=2)i.push(Ce(r[s],r[s+1]));let o=$E(Et(i,.5));return hu.set(e,{version:e.version,polygon:o}),o},$d=(e,t)=>{let n=new bt,i={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=re(e,t);switch(e.type){case"line":case"arrow":{let r=e.points.length?e.points:[Ce(0,0)];return X(e)?n.path(bu(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=Ni(Ce(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:Ce(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Ni(Ce(e.x+s.data[0],e.y+s.data[1]),o,e.angle),Ni(Ce(e.x+s.data[2],e.y+s.data[3]),o,e.angle),Ni(Ce(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>Ce(l[0]-e.x,l[1]-e.y)).flat()}}):r.map((s,a)=>{let l=Ni(Ce(e.x+s[0],e.y+s[1]),o,e.angle);return{op:a===0?"move":"lineTo",data:Ce(l[0]-e.x,l[1]-e.y)}})}case"freedraw":{let r=wu(e);if(r.length<2)return[];let s=e.strokeOptions?.variability==="constant"?Pn(r,Na.COLLISION_SIMPLIFY_TOLERANCE):r;if(s.length<2)return[];let[a,l]=s[0],[d,c]=s[s.length-1];return(a===d&&l===c?s:[...s,s[0]]).map((p,m)=>{let h=Ni(Ce(e.x+p[0],e.y+p[1]),o,e.angle);return{op:m===0?"move":"lineTo",data:Ce(h[0]-e.x,h[1]-e.y)}})}}},ex=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===Ca.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=cn(Math.min(l,d),e);a=t.path(`M ${c} 0 L ${l-c} 0 Q ${l} 0, ${l} ${c} L ${l} ${d-c} Q ${l} ${d}, ${l-c} ${d} L ${c} ${d} Q 0 ${d}, 0 ${d-c} L 0 ${c} Q 0 0, ${c} 0`,ht(pu(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,ht(pu(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,p,m,h,f]=vi(e);if(e.roundness){let g=cn(Math.abs(l-h),e),E=cn(Math.abs(u-d),e);a=t.path(`M ${l+g} ${d+E} L ${c-g} ${u-E}
|
|
15
15
|
C ${c} ${u}, ${c} ${u}, ${c-g} ${u+E}
|
|
16
|
-
L ${
|
|
17
|
-
C ${
|
|
16
|
+
L ${p+g} ${m-E}
|
|
17
|
+
C ${p} ${m}, ${p} ${m}, ${p-g} ${m-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}`,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(j(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(gc(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=xn(e.points,.75);a.push(t.curve(l,{...ct(e,!1,s),stroke:"none"}))}return a.push(Zh(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return Wh(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},gc=(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,uc(e[o],s)/2,uc(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(" ")},Ec=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return il(e);case"arrow":case"line":{let n=Et.generateElementShape(e,null)[0],[,,,,i,o]=Z(e,t);return Yo(e)?al(e,n,ye(e.x,e.y),e.angle,ye(i,o)):rl(n,ye(e.x,e.y),e.angle,ye(i,o))}case"ellipse":return ol(e);case"freedraw":{let[,,,,n,i]=Z(e,t);return sl(e,ye(n,i),Yo(e))}}},Hd=(e,t)=>{let n=[...e.points];if(t){if(!Bl(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>Yh||n.length<4?n.push(ye(o[0],o[1])):n[n.length-1]=ye(o[0],o[1])}return{polygon:t,points:n}},Zh=e=>ng(eg(e)),gr={SIZE_FACTOR:4.25,THINNING:.6,SMOOTHING:.5},Kh={SIZE_FACTOR:1.4},oa=e=>e.strokeOptions?.streamline??Xh,qh=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 fl(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*gr.SIZE_FACTOR,thinning:gr.THINNING,smoothing:gr.SMOOTHING,streamline:oa(e),easing:n=>Math.sin(n*Math.PI/2),last:!0})},Qh=e=>new vo({size:e.strokeWidth*Kh.SIZE_FACTOR,streamline:oa(e),simplify:0,sizeMapping:t=>Math.max(.1,t.pressure)}),Jh=e=>{let t=Qh(e);return e.points.map(([n,i])=>t.addPoint([n,i,1])),t.getStrokeOutline().map(([n,i])=>[n,i])},eg=e=>e.strokeOptions?.variability==="constant"?Jh(e):qh(e),xc=e=>Zr(e.points,{size:e.strokeWidth*gr.SIZE_FACTOR,streamline:oa(e),last:!0}).map(t=>t.point),fc=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],tg=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,ng=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,fc(i,r[0]),"L",r[0],"Z"):n.push(i,fc(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(tg,"$1")};var aa=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]=oi(t.points.map(([h,f])=>ae(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=mg(t,l,d,n);else if(t.type==="diamond"){let[c,u]=ae(O(l,r),O(l,d),t.angle),[m,p]=ae(O(l,a),O(l,d),t.angle),[h,f]=ae(O(o,d),O(l,d),t.angle),[g,E]=ae(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]=ae(O(o,r),O(l,d),t.angle),[m,p]=ae(O(o,a),O(l,d),t.angle),[h,f]=ae(O(s,a),O(l,d),t.angle),[g,E]=ae(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 sg(e);if(K(e))return R.getElementAbsoluteCoords(e,t,n);if(oe(e)){let i=t?Ue(e,t):null;if(X(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]},Ii=(e,t)=>{let n=Ec(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||X(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(og(e)){let[g,E]=yn(e),x=E.map(y=>yc(y,d,e.angle)).flat();return[...wc(g,d,e.angle),...x]}else if(e.type==="diamond"){let[g,E]=Pn(e),x=E.map(y=>yc(y,d,e.angle)).flat();return[...wc(g,d,e.angle),...x]}else if(n.type==="polygon"){if(oe(e)){let x=Ue(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 rg(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=>ae(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)]},og=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),wc=(e,t,n)=>e.map(i=>Pe(ae(i[0],t,n),ae(i[1],t,n))),yc=(e,t,n)=>{let i=It(e,10),o=0,r=[];for(;o<i.length-1;)r.push(Pe(ae(O(i[o][0],i[o][1]),t,n),ae(O(i[o+1][0],i[o+1][1]),t,n))),o++;return r},rg=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(ae(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},DS=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],pi=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]},Pc=(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},Ic=(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=Pc(h,e,t,n,i)),f>=0&&f<=1&&(p=Pc(f,e,t,n,i)),[m,p]},jo=(e,t,n,i)=>{let o=Ic(e[0],t[0],n[0],i[0]),r=Ic(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]},io=(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=Mc(d);sa(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]=jo(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]},oi=(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]},sg=e=>{let[t,n,i,o]=oi(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]},ag=20,lg=15,dg=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 lg;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return ag;default:return 15}},cg=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=Jt(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;sa(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=Mc(u.data);sa(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=dg(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=cg(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[P,v]=ae(O(A,F),O(B,k),ra(-G)),[C,z]=ae(O(A,F),O(B,k),ra(G));return[B,k,P,v,C,z]}let[_,W]=ae(O(B,k),O(A,F),-G*Math.PI/180),[D,L]=ae(O(B,k),O(A,F),ra(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]=ae(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]=ae(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]},ug=e=>{let t=ci.generator(),n=ct(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},mg=(e,t,n,i)=>{let o=de(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,h]=ae(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]??ug(e),a=Jt(s),d=io(a,([u,m])=>ae(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)=>aa.getBounds(e,t,n),Je=(e,t)=>{if(!ig(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Sc(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]},vS=(e,t)=>{let[n,i,o,r]=Je(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},wn=(e,t,n,i)=>{if(!(K(e)||be(e)))return[e.x,e.y,e.x+t,e.y+n];let o=bc(0,t,bc(1,n,e.points,i),i),r;if(be(e))r=oi(o);else{let c=ci.generator(),u=e.roundness?c.curve(o,ct(e)):c.linearPath(o,ct(e)),m=Jt(u);r=io(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Ws=(e,t)=>{let n=ci.generator(),i=e.roundness==null?n.linearPath(t,ct(e)):n.curve(t,ct(e)),o=Jt(i),[r,s,a,l]=io(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},un=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}},BS=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],an=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=re(e,t),[r,s]=ae(O(i.minX,i.minY),o,e.angle),[a,l]=ae(O(i.maxX,i.minY),o,e.angle),[d,c]=ae(O(i.maxX,i.maxY),o,e.angle),[u,m]=ae(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],pg=(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},Qs=(e,t)=>[O(t[0],t[1]),O(t[0],t[3]),O(t[2],t[1]),O(t[2],t[3])].every(n=>pg(n,e)),Kd=({elements:e,elementsMap:t,bounds:n,type:i,excludeElementsInFrames:o,shouldIgnoreElementFromSelection:r})=>{t||(t=Sc(e));let s=Tl(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=X(f)&&de(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=Cn(f,t);if(w&&Ln(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(Qs(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=re(f,t);S=f.points.some(A=>{let F=ae(O(f.x+A[0],f.y+A[1]),T,f.angle);return Yt(F,s)})}else{let T=ue(f,t,!0),A=re(f,t);S=[ae(O((T[0]+T[2])/2,T[1]),A,f.angle),ae(O(T[2],(T[1]+T[3])/2),A,f.angle),ae(O((T[0]+T[2])/2,T[3]),A,f.angle),ae(O(T[0],(T[1]+T[3])/2),A,f.angle)].some(F=>Yt(ae(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))},re=(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]=an(ue(e,t));return O(o+n,r+i)};var Eg=.1,Tc=e=>K(e)||be(e)?e.points.length<2||e.points.length===2&&X(e)&&gg(e.points[0],e.points[e.points.length-1],Eg):e.width===0&&e.height===0,qd=(e,t,n,i,o)=>{let[r,s,a,l]=ue(e,o),d=Er({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=Er({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},RS=(e,t,n,i,o,r)=>{let[s,a,l,d]=Je(e,o),c=Er({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=Er({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},la=(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)/mn)*mn;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}},Wd=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/mn)*mn;if(o){let d=Math.floor(o/mn)*mn;fg(a,d,d+mn)&&(hg(a,o)<mn/6?l=o:Ac(a)>Ac(o)?l=d+mn: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}},zS=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 jS=(e,t,n,i)=>{let o=ar(e,n.getNonDeletedElementsMap(),i).map(kn),r=un(e);return o.flatMap(s=>{let a=xg(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})})},xg=(e,t,{axis:n,position:i})=>{let o=un(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 wr,VERTICAL_ALIGN as yr}from"@excalidraw/common";import{pointDistance as Bg,pointFromVector as Lg,pointsEqual as kc,vector as Cg,vectorDot as Gg,vectorFromPoint as Gc,vectorNormalize as kg,vectorScale as Og}from"@excalidraw/math";I();import{DEFAULT_ELEMENT_PROPS as Fn,DEFAULT_FONT_FAMILY as bg,DEFAULT_FONT_SIZE as wg,DEFAULT_TEXT_ALIGN as yg,DEFAULT_VERTICAL_ALIGN as Pg,DEFAULT_STROKE_STREAMLINE as Ig,VERTICAL_ALIGN as ri,randomInteger as Sg,randomId as Mg,getFontString as xr,getUpdatedTimestamp as Ag,getLineHeight as Tg}from"@excalidraw/common";var kt=(e,{x:t,y:n,strokeColor:i=Fn.strokeColor,backgroundColor:o=Fn.backgroundColor,fillStyle:r=Fn.fillStyle,strokeWidth:s=Fn.strokeWidth,strokeStyle:a=Fn.strokeStyle,roughness:l=Fn.roughness,opacity:d=Fn.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=Fn.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||Mg(),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??Sg(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:E,updated:Ag(),link:x,locked:b,customData:y.customData}),Ai=e=>kt(e.type,e),nM=e=>kt("embeddable",e),iM=e=>({...kt("iframe",e)}),Dc=e=>Ke({...kt("frame",e),type:"frame",name:e?.name||null},{}),vc=e=>Ke({...kt("magicframe",e),type:"magicframe",name:e?.name||null},{}),da=e=>({x:e.textAlign==="center"?.5:e.textAlign==="right"?1:0,y:e.verticalAlign===ri.MIDDLE?.5:e.verticalAlign===ri.BOTTOM?1:0}),Bc=(e,t)=>{let n=da(e);return{x:t.width*n.x,y:t.height*n.y}},si=e=>{let t=e.fontFamily||bg,n=e.fontSize||wg,i=e.lineHeight||Tg(t),o=Zi(e.text),r=ft(o,xr({fontFamily:t,fontSize:n}),i),s=e.textAlign||yg,a=e.verticalAlign||Pg,l=Bc({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};return Ke(d,{})},Dg=(e,t,n)=>{let{width:i,height:o}=ft(n,xr(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===ri.MIDDLE&&!e.containerId&&e.autoResize){let d=ft(e.text,xr(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]=Z(e,t),[p,h,f,g]=wn(e,i,o,!1),E=(d-p)/2,x=(c-h)/2,b=(u-f)/2,y=(m-g)/2;[a,l]=vg({n:s===ri.MIDDLE||s===ri.BOTTOM,s:s===ri.MIDDLE||s===ri.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}},vg=(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]},oM=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=rn(i,xr(e),t?vt(t,e):e.width));let o=Dg(e,n,i);return{text:i,...o}},rM=e=>({...kt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,strokeOptions:e.strokeOptions??{variability:"variable",streamline:Ig}}),Lc=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},br=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},Cc=e=>({...kt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var hM=(e,t,n,i)=>{for(let o=t.length-1;o>=0;o--){let r=t[o];if(!(!X(r)||r.locked||r.points.length<2))for(let s of["end","start"]){if(r[s==="start"?"startBinding":"endBinding"]||kc(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(Bg(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(kc(o,r))return null;let s=Gc(o,r),a=Math.abs(s[0])>=Math.abs(s[1])?s[0]>=0?he:Ne:s[1]>=0?Be:Ze,l=j(e)?0:ve({strokeWidth:i},e),d=kg(Gc(r,o)),c=Math.abs(Gg(d,Cg(a[0],a[1]))),u=Lg(Og(d,-l/c),o);return fe(a,he)?{fixedPoint:We([0,.5]),anchor:u,textAlign:wr.LEFT,verticalAlign:yr.MIDDLE}:fe(a,Ne)?{fixedPoint:We([1,.5]),anchor:u,textAlign:wr.RIGHT,verticalAlign:yr.MIDDLE}:fe(a,Be)?{fixedPoint:We([.5,0]),anchor:u,textAlign:wr.CENTER,verticalAlign:yr.TOP}:{fixedPoint:We([.5,1]),anchor:u,textAlign:wr.CENTER,verticalAlign:yr.BOTTOM}},EM=(e,t)=>!!e.boundElements?.some(({id:n,type:i})=>{if(i!=="arrow")return!1;let o=t.get(n);return X(o)&&(o.startBinding?.elementId===e.id||o.endBinding?.elementId===e.id)}),xM=e=>{let t=da(e).x;return{anchorRatio:t,anchorX:e.x+e.width*t}};I();import{distanceToLineSegment as Oc,lineSegment as ai,lineSegmentIntersectionPoints as Ng,pointDistance as Kt,pointFrom as Di,pointRotateRads as Ir,polygonArea as co,polygonIncludesPoint as Nc,polygonIncludesPointNonZero as Pr,polygonSignedArea as ua}from"@excalidraw/math";import{isOpaqueColor as Fg,isTransparent as uo}from"@excalidraw/common";var Rg=6,zg=2,_g=2,Hg=.5,Wg={snapEpsilon:.5,gapTolerance:Rg,minArea:4,maxBoundarySegments:2560,maxGeneratedPoints:1536,fallbackSearchRadius:512},_c=([e,t,n,i],o)=>[e-o,t-o,n+o,i+o],Ug=e=>Kt(e[0],e[1]),lo=(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},Fc=(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)}},Yg=(e,t,n)=>{let i=n[0]-t[0],o=n[1]-t[1],r=Math.hypot(i,o);return r===0?Kt(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),Xg=(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},jg=(e,t)=>{let n=re(e,t),o=(e.roundness&&e.points.length>2?It(So(e.points),.15,Hg):e.points).map(s=>Ir(Di(e.x+s[0],e.y+s[1]),n,e.angle)),r=[];for(let s=0;s<o.length-1;s++)r.push(ai(o[s],o[s+1]));return r},$g=(e,t)=>{let n=re(e,t),i=xc(e).map(r=>Ir(Di(e.x+r[0],e.y+r[1]),n,e.angle)),o=[];for(let r=0;r<i.length-1;r++)o.push(ai(i[r],i[r+1]));return o},Vg=(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,ai(e,t)).map(u=>lo(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=Xg(s,c))}return s.filter(([a,l])=>Kt(Ti(e,t,a),Ti(e,t,l))>=o).map(([a,l])=>[Ti(e,t,a),Ti(e,t,l)])},ma=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(Kt(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)}}},Rc=e=>!(!hi(e.type)||e.fillStyle!=="solid"||e.opacity<100||!Fg(e.backgroundColor)||(Oe(e)||be(e))&&!Tt(e.points)),Hc=new Set(["rectangle","diamond","ellipse","frame","magicframe","line","freedraw"]),pa=e=>e.opacity<=0,Wc=e=>!pa(e)&&(e.type==="image"||!uo(e.strokeColor)||hi(e.type)&&!uo(e.backgroundColor)),Uc=e=>Oe(e)&&e.polygon&&ts(e.points)&&!pa(e)&&!uo(e.backgroundColor)&&uo(e.strokeColor),Zg=e=>Hc.has(e.type)?Oe(e)?e.polygon&&ts(e.points):be(e)?Tt(e.points):!0:!1,ca=e=>!pa(e)&&Hc.has(e.type)&&!uo(e.strokeColor),Kg=(e,t,n)=>{for(let i=t.length-1;i>=0;i--){let o=t[i];if(!(!Wc(o)||Uc(o))&&Zg(o)&&it(e,o,n))return o}return null},qg=(e,t)=>{let n=t.snapEpsilon,i=new ma(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=>ai(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(_c(P.box,n),Q.box))continue;let ee=Ng(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:lo(P.pa,P.pb,i.nodes[te])}),Q.splits.push({node:te,t:lo(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)=>{Fc(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=lo(C.pa,C.pb,L);z<=0||z>=1||Oc(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||Kt(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};Fc(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,Le=>{if(Le===C||Q.includes(Le))return;let Te=Kt(z,i.nodes[Le]);Te>=n&&Te<=w&&Te<te&&(te=Te,ee=Le)});let ne=null,Ae=1/0,Ft=0,Rt=Math.floor(z[0]/D),hn=Math.floor(z[1]/D),pe=new Set;for(let Le=-1;Le<=1;Le++)for(let Te=-1;Te<=1;Te++){let $e=L.get(`${Rt+Le}:${hn+Te}`);if($e)for(let qt of $e){let li=x(qt.u,qt.v);if(pe.has(li)||(pe.add(li),!f.has(li)||qt.u===C||qt.v===C))continue;let Ha=i.nodes[qt.u],Wa=i.nodes[qt.v],Fr=lo(Ha,Wa,z);if(Fr<=0||Fr>=1)continue;let Rr=Oc(z,ai(Ha,Wa));Rr<=w&&Rr<Ae&&(Ae=Rr,ne=qt,Ft=Fr)}}let ie=r.get(C)??o[0].elementId;if(ne&&Ae<te){let Le=i.nodes[ne.u],Te=i.nodes[ne.v],$e=i.getOrCreate(Ti(Le,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 li of qt)y(ne.u,$e,li),y($e,ne.v,li);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 _},Qg=(e,t,n)=>{if(e.length===0)return null;let i=1,o=new Map;for(let c of e)o.set(c,-ua(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||Pr(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&&!Pr(t,c.ring)&&Pr(c.ring[0],a.ring)),d=l.filter(c=>!l.some(u=>u!==c&&Pr(c.ring[0],u.ring)));return{face:a,holes:d}},Jg=(e,t)=>{let n=[];for(let i of e)(n.length===0||Kt(n[n.length-1],i)>=t)&&n.push(i);for(;n.length>1&&Kt(n[0],n[n.length-1])<t;)n.pop();return n},eE=(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];Yg(e[i],o,r)>=t&&n.push(e[i])}return n.length>=3?n:e},zc=(e,t,n)=>{let i=Jg(e,t.snapEpsilon);if(i.length<3)return null;let o=.75,r=xn(i,o);for(;r.length>n&&o<1e6;)o*=2,r=xn(i,o);return r.length>n?null:(r=eE(r,.05),r.length>=3?r:null)},tE=(e,t)=>{let n=Math.sign(ua(t,0))===Math.sign(ua(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=Kt(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},nE=(e,t,n)=>{let i=zc(e,n,n.maxGeneratedPoints);if(!i)return null;let o=t.map((s,a)=>({holeRing:s,index:a})).sort((s,a)=>co(a.holeRing,0)-co(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=zc(s,n,l);d&&(i=tE(i,d),r.push(a))}return{scenePoints:[...i,i[0]],splicedHoleIndices:r}},CM=e=>{let t={...Wg,...e.options},{point:n,elements:i,elementsMap:o}=e,r=Kg(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&&ca(P)&&G(P)),W=i.filter(P=>Rc(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,_g),Q=Oe(P)?jg(P,o):be(P)?$g(P,o):Ii(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];Kt(ee,te)>=t.snapEpsilon&&Q.push(ai(te,ee))}for(let ee of Q){if(D.length>t.maxBoundarySegments)return;if(Ug(ee)!==0){if(C.length===0){D.push({segment:ee,elementId:P.id});continue}for(let[te,ne]of Vg(ee[0],ee[1],C,o,t.snapEpsilon,z))D.push({segment:ai(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=qg(B,t);return k?Qg(k,n,t):"too_complex"},d=null;if(r){let B=t.gapTolerance+2+Math.max(r.strokeWidth??1,1),k=_c(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+(ca(_)?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+(ca(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=nE(c.ring,u.map(B=>B.ring),t);if(!m)return{ok:!1,reason:"invalid_polygon"};let{scenePoints:p,splicedHoleIndices:h}=m;if(co(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]=oi(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=re(B,o),P=Math.max(1,Math.floor(B.points.length/8));for(let v=0;v<B.points.length;v+=P)D.push(Ir(Di(B.x+B.points[v][0],B.y+B.points[v][1]),L,B.angle))}return D.some(L=>Nc(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=Ii(B,o),L=Math.max(1,Math.floor(D.length/16));for(let v=0;v<D.length;v+=L)if(Nc(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)Rc(B)&&S(B)&&(A=B),(g.has(B.id)||Wc(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}},GM=e=>{let{hitElement:t,scenePoints:n,elementsMap:i}=e;if(!Uc(t))return!1;let o=re(t,i),r=t.points.map(b=>Ir(Di(t.x+b[0],t.y+b[1]),o,t.angle)),s=co(r,0),a=co(n,0),l=Math.abs(s-a)<=.05*Math.max(s,a),[d,c,u,m]=oi(r),[p,h,f,g]=oi(n),E=zg,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 ZE,arrayToObject as pn,assertNever as du,isDevEnv as Hn,isShallowEqual as cu,isTestEnv as Wn,randomInteger as lu}from"@excalidraw/common";I();import{assertNever as pE,COLOR_PALETTE as fE,isDevEnv as hE,isTestEnv as gE,randomId as EE,Emitter as jc,toIterable as Bi}from"@excalidraw/common";I();import{ORIG_ID as sE,randomId as Xc,randomInteger as aE,arrayToMap as lE,castArray as fa,findLastIndex as vi,getUpdatedTimestamp as dE,isTestEnv as cE}from"@excalidraw/common";I();import{arrayToMap as iE}from"@excalidraw/common";var oE=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},rE=e=>{let t=iE(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]},Yc=e=>rE(oE(e));var uE=(e,t,n,i)=>{let o=ga(n);return cE()&&mE(o,n.id),o.id=Xc(),o.updated=dE(),i&&(o.seed=aE(),xd(o)),o.groupIds=Vd(o.groupIds,e,r=>(t.has(r)||t.set(r,Xc()),t.get(r))),o},VM=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=lE(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=Yc(t);let p=t.slice(),h=E=>{let b=fa(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=uE(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(...fa(x));return}p.splice(E+1,0,...fa(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=Ys(n,E);if(x){let b=Qe(t,x).flatMap(w=>J(w)&&!m?[...Bn(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=Bn(t,b),w=vi(p,M=>M.frameId===b||M.id===b);f(w,h([...y,E]));continue}if(_t(E)){let b=de(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=Ue(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(vd(r,a,d),nc(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}},ha=(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]=ha(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=ha(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},ga=e=>ha(e),mE=(e,t)=>{Object.defineProperty(e,sE,{value:t,writable:!1,enumerable:!1})};var ut={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},$c=class{constructor(t){this.app=t}onDurableIncrementEmitter=new jc;onStoreIncrementEmitter=new jc;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=_n.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=_n.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?ec(t.elements):void 0,t.appState);i=mo.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=_n.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=mo.create(o,t),i?s=i:s=ba.calculate(o,t),!s.isEmpty()){let a=new Ea(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=mo.create(r,t)}let o=new xa(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:pE(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()),gE()||hE())throw new Error(t)}}},mo=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},Sr=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Ea=class extends Sr{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},xa=class extends Sr{constructor(n){super("ephemeral",n);this.change=n}},ba=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:EE()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?zn.calculate(t.elements,n.elements):zn.empty(),o=n.metadata.didAppStateChange?Rn.calculate(t.appState,n.appState):Rn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,zn.restore(i),Rn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=zn.create(n,i,o),a=Rn.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,_n.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(zn.empty(),Rn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},_n=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,Vc(n)?n:Li(n),i)}static empty(){return new e(new Map,xE(),{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=Vc(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=qc(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)&&!Vn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=Kc(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,ga(i));return n}},Zc="__observedAppState",xE=()=>({name:null,editingGroupId:null,viewBackgroundColor:fE.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,Zc,{value:!0,enumerable:!1}),t},Vc=e=>!!Reflect.get(e,Zc);I();var au=am(nu(),1);import{randomInteger as NE,arrayToMap as FE,toBrandedType as iu,isDevEnv as ou,isTestEnv as ru,toArray as RE}from"@excalidraw/common";import{isNonDeletedElement as zE}from"@excalidraw/element";import{isFrameLikeElement as _E}from"@excalidraw/element";import{getElementsInGroup as HE}from"@excalidraw/element";import{syncInvalidIndices as WE,syncMovedIndices as UE,validateFractionalIndices as YE}from"@excalidraw/element";import{getSelectedElements as XE}from"@excalidraw/element";import{mutateElement as jE}from"@excalidraw/element";var su=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}},$E=(0,au.default)(e=>{(ou()||ru()||window?.DEBUG_FRACTIONAL_INDICES)&&YE(e,{shouldThrow:ou()||ru(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),VE=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=iu(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=iu(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=VE(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=XE(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&&zE(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=RE(t),o=[];n?.skipValidation||$E(i),this.elements=WE(i),this.elementsMap.clear(),this.elements.forEach(s=>{_E(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=su(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=su(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=NE();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)];UE(i,FE(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]:HE(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=jE(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(pn(t??[],o),pn(n??[],o),pn(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=pn(e.getLeftDifferences(pn(r,o),pn(s,o)),d=>d),l=pn(e.getRightDifferences(pn(r,o),pn(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)])):du(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&&cu(a,l))continue;yield s}}}},Rn=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),Wn()||Hn())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=Xd(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]||{};cu(h,f)||(l.value=!0);break;case"activeLockedId":let g=t[u]||null,E=n[u]||null;g!==E&&(l.value=!0);break;default:du(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."),Wn()||Hn())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}},zn=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(Wn()||Hn())&&(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:lu()},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:lu()},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=_n.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),Wn()||Hn())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),Wn()||Hn())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(Wn()||Hn())&&(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=Fe(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=>Bd.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);Dn.unbindAffected(n,r(),o),Dn.unbindAffected(n,s(),o),vn.unbindAffected(n,r(),o),vn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Dn.unbindAffected(n,r(),o),Dn.rebindAffected(n,s(),o),vn.unbindAffected(n,r(),(a,l)=>{oe(a)&&o(a,l)}),vn.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),Wn()||Hn())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||Uo(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=Jd([...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),ZE(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."),Wn()||Hn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};I();var CA=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=un(e),c=ar(e,t,i).map(kn).map(h=>[h,un(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 KE,getGridPoint as qE,getFontString as QE,DRAGGING_THRESHOLD as JE}from"@excalidraw/common";var WA=(e,t,n,i,o,r)=>{if(t.length===1&&j(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(j(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=ex(Je(d),n,o,r),u=new Set(Array.from(a,m=>m.id));a.forEach(m=>{let p=!X(m),h=p||(m.startBinding?u.has(m.startBinding.elementId):!1),f=p||(m.endBinding?u.has(m.endBinding.elementId):!1);if(X(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>JE||!m.startBinding&&!m.endBinding){ya(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{ya(e,m,i,c);let g=de(m,i.getNonDeletedElementsMap());g&&ya(e,g,i,c),je(m,i,{simultaneouslyUpdated:Array.from(a)})}})},ex=(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]=qE(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},ya=(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})},UA=(e,t,n)=>{let[i,o]=Je(e);return[t-i,n-o]},tx=({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,zo(QE({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight));s.mutateElement(e,{x:t-c*n,...o===void 0?{}:{y:o},width:c,...d>KE/r?{autoResize:!1}:{}},{informMutation:a,isDragging:!1})},YA=({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}=la(t,a,o<n?-s:s):{width:s,height:a}=la(t,s,r<i?-a:a),a<0&&(a=-a))),oe(e)){tx({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 Ar,normalizeLink as uu}from"@excalidraw/common";var ZA=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Ar,e),uu(i.toString())}catch(i){console.error(i)}return uu(n)},KA=(e,t)=>{if(e.length>0&&nx(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},nx=e=>!!(e.length===1||e.length>1&&jd(e)),qA=e=>{try{let t=new URL(e);return t.searchParams.has(Ar)&&t.host===window.location.host}catch{return!1}},QA=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Ar))return t.get(Ar)}catch{}return null};I();import{FONT_FAMILY as ix,VERTICAL_ALIGN as ox,escapeDoubleQuotes as Pa,getFontString as rx}from"@excalidraw/common";var Ot=new Map,sx=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,ax=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,lx=/^https:\/\/(?:www\.)?figma\.com/,mu=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,dx=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,cx=/^(?:https?:\/\/)?forms\.microsoft\.com\//,pu=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,ux=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,mx=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,px=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,fu=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,hu=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,fx=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Eu=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)},hx=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=Eu(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}},Sa=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"]),gu=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"]),Ia=e=>`<html><body>${e}</body></html>`,rT=e=>{if(!e)return null;if(Ot.has(e))return Ot.get(e);let t=e,n=gu.has(Ma(e,gu)||""),i="generic",o={w:560,h:840},r=e.match(sx);if(r?.[2]){let c=Eu(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(ax);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=hx(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(lx))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(mx);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(cx.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),pu.test(e)){let c=e.match(pu)[1],u=Pa(`https://twitter.com/x/status/${c}`),m={type:"document",srcdoc:p=>Ia(`<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(hu.test(e)){let[,c,u,m]=e.match(hu),p=Pa(`https://reddit.com/r/${c}/comments/${u}/${m}`),h={type:"document",srcdoc:f=>Ia(`<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(mu.test(e)){let[,c,u]=e.match(mu),m=Pa(`https://gist.github.com/${c}/${u}`),p={type:"document",srcdoc:()=>Ia(`
|
|
22
|
-
<script src="${
|
|
21
|
+
C ${l} ${d}, ${l} ${d}, ${l+g} ${d+E}`,ht(e,!0,s))}else a=t.polygon([[l,d],[c,u],[p,m],[h,f]],ht(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,ht(e,!1,s));case"line":case"arrow":{let a,l=ht(e,!1,s),d=e.points.length?e.points:[Ce(0,0)];if(X(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(bu(d,16),ht(e,!0,s))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(d)),a=[]):e.roundness?a=[t.curve(d,l)]:l.fill?a=[t.polygon(d,l)]:a=[t.linearPath(d,l)],e.type==="arrow"){let{startArrowhead:c=null,endArrowhead:u="arrow"}=e;if(c!==null){let p=fu(e,a,"start",c,t,l,i,s);a.push(...p)}if(u!==null){let p=fu(e,a,"end",u,t,l,i,s);a.push(...p)}}return a}case"freedraw":{let a=[];return Nt(e.points)&&a.push(t.curve(xu(e),{...ht(e,!1,s),stroke:"none"})),a.push(tx(e)),a}case"stickynote":case"frame":case"magicframe":case"text":case"image":return null;default:return VE(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},bu=(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=Bt(a,r),d=Bt(s,a),c=Math.min(t,mu(e[o],s)/2,mu(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(" ")},yu=(e,t)=>{switch(e.type){case"rectangle":case"stickynote":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Fl(e);case"arrow":case"line":{let n=Qe.generateElementShape(e,null)[0],[,,,,i,o]=Q(e,t);return gr(e)?Hl(e,n,Ce(e.x,e.y),e.angle,Ce(i,o)):zl(n,Ce(e.x,e.y),e.angle,Ce(i,o))}case"ellipse":return Rl(e);case"freedraw":{let[,,,,n,i]=Q(e,t);return _l(e,Ce(n,i),gr(e))}}},Fc=(e,t)=>{let n=[...e.points];if(t){if(!cd(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>ZE||n.length<4?n.push(Ce(o[0],o[1])):n[n.length-1]=Ce(o[0],o[1])}return{polygon:t,points:n}},tx=e=>sx(wu(e)),wo={SIZE_FACTOR:4.25,THINNING:.6,SMOOTHING:.5},Na={SIZE_FACTOR:1.4,COLLISION_SIMPLIFY_TOLERANCE:.2},Oa=e=>e.strokeOptions?.streamline??qE,nx=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 Vl(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*wo.SIZE_FACTOR,thinning:wo.THINNING,smoothing:wo.SMOOTHING,streamline:Oa(e),easing:n=>Math.sin(n*Math.PI/2),last:!0})},ix=e=>new Wo({size:e.strokeWidth*Na.SIZE_FACTOR,streamline:Oa(e),simplify:0,sizeMapping:t=>Math.max(.1,t.pressure)}),ox=e=>{let t=ix(e);return e.points.map(([n,i])=>t.addPoint([n,i,1])),t.getStrokeOutline().map(([n,i])=>[n,i])},wu=e=>e.strokeOptions?.variability==="constant"?ox(e):nx(e),lc=e=>e.strokeOptions?.variability==="constant"?e.strokeWidth*Na.SIZE_FACTOR:e.strokeWidth*wo.SIZE_FACTOR+3,Pu=e=>as(e.points,{size:e.strokeWidth*wo.SIZE_FACTOR,streamline:Oa(e),last:!0}).map(t=>t.point),gu=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],rx=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,sx=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,gu(i,r[0]),"L",r[0],"Z"):n.push(i,gu(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(rx,"$1")};var Ra=class e{static boundsCache=new WeakMap;static nonRotatedBoundsCache=new WeakMap;static getBounds(t,n,i=!1){let o=i&&t.angle!==0?e.nonRotatedBoundsCache.get(t):e.boundsCache.get(t);if(o?.version&&o.version===t.version&&!pe(t))return o.bounds;if(i&&t.angle!==0){let s=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:s}),s}let r=e.calculateBounds(t,n);return e.boundsCache.set(t,{version:t.version,bounds:r}),r}static calculateBounds(t,n){let i,[o,r,s,a,l,d]=Q(t,n);if(ge(t)){let[c,u,p,m]=mi(t.points.map(([h,f])=>le(F(h,f),F(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,p+t.x,m+t.y]}else if(ee(t))i=gx(t,l,d,n);else if(t.type==="diamond"){let[c,u]=le(F(l,r),F(l,d),t.angle),[p,m]=le(F(l,a),F(l,d),t.angle),[h,f]=le(F(o,d),F(l,d),t.angle),[g,E]=le(F(s,d),F(l,d),t.angle),x=Math.min(c,p,h,g),b=Math.min(u,m,f,E),y=Math.max(c,p,h,g),w=Math.max(u,m,f,E);i=[x,b,y,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),h=Math.hypot(c*p,u*m),f=Math.hypot(u*p,c*m);i=[l-h,d-f,l+h,d+f]}else{let[c,u]=le(F(o,r),F(l,d),t.angle),[p,m]=le(F(o,a),F(l,d),t.angle),[h,f]=le(F(s,a),F(l,d),t.angle),[g,E]=le(F(s,r),F(l,d),t.angle),x=Math.min(c,p,h,g),b=Math.min(u,m,f,E),y=Math.max(c,p,h,g),w=Math.max(u,m,f,E);i=[x,b,y,w]}return i}},Q=(e,t,n=!1)=>{if(ge(e))return cx(e);if(ee(e))return R.getElementAbsoluteCoords(e,t,n);if(j(e)){let i=t?Be(e,t):null;if(W(i)){let{x:o,y:r}=R.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},Bi=(e,t)=>{let n=yu(e,t),[i,o,r,s,a,l]=Q(e,t),d=F(a,l);if(n.type==="polycurve"){let E=n.data.map(b=>Et(b,10)),x=[];if(Re(e)&&!e.polygon||W(e))for(let b of E){let y=0;for(;y<b.length-1;)x.push(we(F(b[y][0],b[y][1]),F(b[y+1][0],b[y+1][1]))),y++}else{let b=E.flat(),y=0;for(;y<b.length-1;)x.push(we(F(b[y][0],b[y][1]),F(b[y+1][0],b[y+1][1]))),y++}return x}else{if(n.type==="polyline")return n.data;if(lx(e)){let[g,E]=Mn(e),x=E.map(y=>Mu(y,d,e.angle)).flat();return[...Iu(g,d,e.angle),...x]}else if(e.type==="diamond"){let[g,E]=Tn(e),x=E.map(y=>Mu(y,d,e.angle)).flat();return[...Iu(g,d,e.angle),...x]}else if(n.type==="polygon"){if(j(e)){let x=Be(e,t);if(x&&ee(x))return[we(F(i,o),F(r,o)),we(F(r,o),F(r,s)),we(F(r,s),F(i,s)),we(F(i,s),F(i,o))]}let g=n.data,E=[];for(let x=0;x<g.length-1;x++)E.push(we(g[x],g[x+1]));return E}else if(n.type==="ellipse")return dx(e)}let[c,u,p,m,,,h,f]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(g=>le(g,d,e.angle));return[we(c,u),we(p,m),we(c,p),we(u,m),we(c,f),we(p,f),we(u,h),we(m,h)]},lx=e=>e!=null&&(e.type==="rectangle"||e.type==="stickynote"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),Iu=(e,t,n)=>e.map(i=>we(le(i[0],t,n),le(i[1],t,n))),Mu=(e,t,n)=>{let i=Et(e,10),o=0,r=[];for(;o<i.length-1;)r.push(we(le(F(i[o][0],i[o][1]),t,n),le(F(i[o+1][0],i[o+1][1]),t,n))),o++;return r},dx=e=>{let t=F(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(le(F(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(we(r[l],r[l+1]));return o.push(we(r[r.length-1],r[0])),o},uA=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],vi=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]},Tu=(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},Au=(e,t,n,i)=>{let o=t-e,r=n-t,s=i-n,a=3*o-6*r+3*s,l=6*r-6*o,d=3*o,c=l*l-4*a*d;if(!(c>=0))return!1;let p=null,m=null,h=1/0,f=1/0;return a===0?h=f=-d/l:(h=(-l+Math.sqrt(c))/(2*a),f=(-l-Math.sqrt(c))/(2*a)),h>=0&&h<=1&&(p=Tu(h,e,t,n,i)),f>=0&&f<=1&&(m=Tu(f,e,t,n,i)),[p,m]},Er=(e,t,n,i)=>{let o=Au(e[0],t[0],n[0],i[0]),r=Au(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]},ho=(e,t)=>{let n=F(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=vu(d);Fa(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=F(d[0],d[1]),u=F(d[2],d[3]),p=F(d[4],d[5]),m=t?t(c):c,h=t?t(u):u,f=t?t(p):p,g=t?t(n):n;n=p;let[E,x,b,y]=Er(g,m,h,f);a.minX=Math.min(a.minX,E),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,b),a.maxY=Math.max(a.maxY,y)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},mi=(e,t=0)=>{let n=1/0,i=1/0,o=-1/0,r=-1/0;for(let[s,a]of e)n=Math.min(n,s),i=Math.min(i,a),o=Math.max(o,s),r=Math.max(r,a);return[n-t,i-t,o+t,r+t]},cx=e=>{let[t,n,i,o]=mi(e.points),r=t+e.x,s=n+e.y,a=i+e.x,l=o+e.y;return[r,s,a,l,(r+a)/2,(s+l)/2]},ux=20,mx=15,px=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 mx;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return ux;default:return 15}},fx=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},rt=(e,t,n,i,o=0)=>{if(i===null||t.length<1)return null;let r=Jt(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;Fa(a.length===6,"Op data length is not 6");let l=F(a[4],a[5]),d=F(a[2],a[3]),c=F(a[0],a[1]),u=r[s-1],p=F(0,0);if(u.op==="move"){let P=vu(u.data);Fa(P!=null,"Op data is not a point"),p=P}else u.op==="bcurveTo"&&(p=F(u.data[4],u.data[5]));let m=(P,B)=>Math.pow(1-P,3)*l[B]+3*P*Math.pow(1-P,2)*d[B]+3*Math.pow(P,2)*(1-P)*c[B]+p[B]*Math.pow(P,3),[h,f]=n==="start"?p:l,[g,E]=[m(.3,0),m(.3,1)],x=Math.hypot(h-g,f-E),b=(h-g)/x,y=(f-E)/x,w=px(i),S=0;{let[P,B]=n==="end"?e.points[e.points.length-1]:e.points[0],[k,_]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];S=Math.hypot(P-k,B-_)}let A=Math.min(w,S*(i==="diamond"||i==="diamond_outline"?.25:.5)),T=h-b*A*o,O=f-y*A*o,v=T-b*A,N=O-y*A;if(i==="circle"||i==="circle_outline"){let P=Math.hypot(N-O,v-T)+e.strokeWidth-2;return[T,O,P]}let C=fx(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[P,B]=le(F(T,O),F(v,N),Ga(-C)),[k,_]=le(F(T,O),F(v,N),Ga(C));return[v,N,P,B,k,_]}let[z,U]=le(F(v,N),F(T,O),-C*Math.PI/180),[D,L]=le(F(v,N),F(T,O),Ga(C));if(i==="diamond"||i==="diamond_outline"){let P,B;if(n==="start"){let[k,_]=e.points.length>1?e.points[1]:[0,0];[P,B]=le(F(T+A*2,O),F(T,O),Math.atan2(_-O,k-T))}else{let[k,_]=e.points.length>1?e.points[e.points.length-2]:[0,0];[P,B]=le(F(T-A*2,O),F(T,O),Math.atan2(O-_,T-k))}return[T,O,z,U,P,B,D,L]}return[T,O,z,U,D,L]},hx=e=>{let t=xi.generator(),n=ht(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},gx=(e,t,n,i)=>{let o=q(e,i);if(e.points.length<2){let[u,p]=e.points[0],[m,h]=le(F(e.x+u,e.y+p),F(t,n),e.angle),f=[m,h,m,h];if(o){let g=R.getMinMaxXYWithBoundText(e,i,[m,h,m,h],o);f=[g[0],g[1],g[2],g[3]]}return f}let s=Qe.get(e,null)?.[0]??hx(e),a=Jt(s),d=ho(a,([u,p])=>le(F(e.x+u,e.y+p),F(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=R.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},ae=(e,t,n=!1)=>Ra.getBounds(e,t,n),ot=(e,t)=>{if(!ax(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Du(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]},mA=(e,t)=>{let[n,i,o,r]=ot(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},In=(e,t,n,i)=>{if(!(ee(e)||ge(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Su(0,t,Su(1,n,e.points,i),i),r;if(ge(e))r=mi(o);else{let c=xi.generator(),u=e.roundness?c.curve(o,ht(e)):c.linearPath(o,ht(e)),p=Jt(u);r=ho(p)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},ga=(e,t)=>{let n=xi.generator(),i=e.roundness==null?n.linearPath(t,ht(e)):n.curve(t,ht(e)),o=Jt(i),[r,s,a,l]=ho(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},pn=e=>{let[t,n,i,o]=ot(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},pA=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],nn=e=>F(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),ut=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=re(e,t),[r,s]=le(F(i.minX,i.minY),o,e.angle),[a,l]=le(F(i.maxX,i.minY),o,e.angle),[d,c]=le(F(i.maxX,i.maxY),o,e.angle),[u,p]=le(F(i.minX,i.maxY),o,e.angle),m=[Math.min(r,a,d,u),Math.min(s,l,c,p),Math.max(r,a,d,u),Math.max(s,l,c,p)];if(n){let[h,f,g,E]=n;return[m[0]-E,m[1]-h,m[2]+f,m[3]+g]}return m},Xt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],Ex=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],yt=(e,t)=>{if(e==null||t==null)return!1;let[n,i,o,r]=e,[s,a,l,d]=t;return n<l&&o>s&&i<d&&r>a},Ta=(e,t)=>[F(t[0],t[1]),F(t[0],t[3]),F(t[2],t[1]),F(t[2],t[3])].every(n=>Ex(n,e)),$c=({elements:e,elementsMap:t,bounds:n,type:i,excludeElementsInFrames:o,shouldIgnoreElementFromSelection:r})=>{t||(t=Du(e));let s=ad(n)?ae(n,t):n,[a,l,d,c]=s,u=[we(F(a,l),F(d,l)),we(F(d,l),F(d,c)),we(F(d,c),F(a,c)),we(F(a,c),F(a,l))],p=o?new Set:null,m={},h=new Set;for(let f of e){if(r?.(f))continue;let g=f.groupIds.at(-1);g&&(m[g]||(m[g]=[]),m[g].push(f));let E=f.strokeWidth,x=null,b=ae(f,t);b=[b[0]-E/2,b[1]-E/2,b[2]+E/2,b[3]+E/2];let y=W(f)&&q(f,t);if(y){let{x:I,y:A}=R.getBoundTextElementPosition(f,y,t);x=[I,A,I+y.width,A+y.height]}let w=Hn(f,t);if(w&&_n(f,w,t)){let I=ae(w,t);b=[Math.max(b[0],I[0]),Math.max(b[1],I[1]),Math.min(b[2],I[2]),Math.min(b[3],I[3])],x=x?[Math.max(x[0],I[0]),Math.max(x[1],I[1]),Math.min(x[2],I[2]),Math.min(x[3],I[3])]:null}let S=x?[Math.min(x[0],b[0]),Math.min(x[1],b[1]),Math.max(x[2],b[2]),Math.max(x[3],b[3])]:b;if(Ta(s,S)){p&&J(f)&&p.add(f.id),h.add(f);continue}if(i==="overlap"&&x&&yt(s,x)){h.add(f);continue}if(i==="overlap"&&yt(s,b)){let I=!1;if(ee(f)||ge(f)){let A=re(f,t);I=f.points.some(T=>{let O=le(F(f.x+T[0],f.y+T[1]),A,f.angle);return Xt(O,s)})}else{let A=ae(f,t,!0),T=re(f,t);I=[le(F((A[0]+A[2])/2,A[1]),T,f.angle),le(F(A[2],(A[1]+A[3])/2),T,f.angle),le(F((A[0]+A[2])/2,A[3]),T,f.angle),le(F(A[0],(A[1]+A[3])/2),T,f.angle)].some(O=>Xt(le(O,T,f.angle),s))}if(I||(I=u.some(A=>pt(f,t,A,E/2,!0).length>0)),I){p&&J(f)&&p.add(f.id),h.add(f);continue}}}return p&&h.forEach(f=>{f.frameId&&p.has(f.frameId)&&h.delete(f)}),i==="overlap"?Array.from(h).forEach(f=>{let g=f.groupIds.at(-1);(g?m[g]:null)?.forEach(x=>h.add(x))}):i==="contain"&&h.forEach(f=>{let g=f.groupIds.at(-1),E=g?m[g]:null;E&&!E.every(x=>h.has(x))&&h.delete(f)}),e.filter(f=>h.has(f))},re=(e,t,n=0,i=0)=>{if(ee(e)||ge(e)){let[s,a,l,d]=Q(e,t),[c,u]=F((s+l)/2,(a+d)/2);return F(c+n,u+i)}let[o,r]=nn(ae(e,t));return F(o+n,r+i)};var ao=(e,t,n="top")=>{let i=(e.height-t)/2;if(n==="center")return{x:e.x,y:e.y+i};let o=Math.sin(e.angle),r=Math.cos(e.angle);return n==="bottom"?{x:e.x-i*o,y:e.y+i*(1+r)}:{x:e.x+i*o,y:e.y+i*(1-r)}},wx=.1,Bu=e=>ee(e)||ge(e)?e.points.length<2||e.points.length===2&&W(e)&&yx(e.points[0],e.points[e.points.length-1],wx):e.width===0&&e.height===0,jc=(e,t,n,i,o)=>{let[r,s,a,l]=ae(e,o),d=vr({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=vr({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},wA=(e,t,n,i,o,r)=>{let[s,a,l,d]=ot(e,o),c=vr({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=vr({clientX:i.offsetLeft+t-(r?.right||0),clientY:i.offsetTop+n-(r?.bottom||0)},i);return s>=c.x&&a>=c.y&&l<=u.x&&d<=u.y},za=(e,t,n)=>{let i=Math.abs(t),o=Math.abs(n);if(e==="line"||e==="arrow"||e==="freedraw"){let r=Math.round(Math.atan(o/i)/fn)*fn;r===0?n=0:r===Math.PI/2?t=0:n=i*Math.tan(r)*Math.sign(n)||n}else e!=="selection"&&(n=i*Math.sign(n));return{width:t,height:n}},Rc=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/fn)*fn;if(o){let d=Math.floor(o/fn)*fn;xx(a,d,d+fn)&&(bx(a,o)<fn/6?l=o:Lu(a)>Lu(o)?l=d+fn:l=d)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,p=-1/d,m=-1,h=i-p*n,f=(c*h-m*u)/(d*m-p*c),g=(u*p-h*d)/(d*m-p*c);r=f-e,s=g-t}return{width:r,height:s}},PA=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t};M();var vA=(e,t,n,i)=>{let o=Pr(e,n.getNonDeletedElementsMap(),i).map(Ci),r=pn(e);return o.flatMap(s=>{let a=Px(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ge(l,n,{simultaneouslyUpdated:s}),d})})},Px=(e,t,{axis:n,position:i})=>{let o=pn(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};M();import{TEXT_ALIGN as kr,VERTICAL_ALIGN as Cr}from"@excalidraw/common";import{pointDistance as Nx,pointFromVector as Ox,pointsEqual as Xu,vector as Gx,vectorDot as Fx,vectorFromPoint as Yu,vectorNormalize as Rx,vectorScale as zx}from"@excalidraw/math";M();import{DEFAULT_ELEMENT_PROPS as Xn,DEFAULT_FONT_FAMILY as Sx,DEFAULT_FONT_SIZE as Ix,DEFAULT_TEXT_ALIGN as Mx,DEFAULT_STICKY_NOTE_SIZE as Tx,STICKY_NOTE_MIN_SIZE as ku,DEFAULT_VERTICAL_ALIGN as Ax,DEFAULT_STROKE_STREAMLINE as Dx,VERTICAL_ALIGN as pi,randomInteger as vx,randomId as Lx,getFontString as Po,getUpdatedTimestamp as Bx,getLineHeight as kx}from"@excalidraw/common";var Mt=(e,{x:t,y:n,strokeColor:i=Xn.strokeColor,backgroundColor:o=Xn.backgroundColor,fillStyle:r=Xn.fillStyle,strokeWidth:s=Xn.strokeWidth,strokeStyle:a=Xn.strokeStyle,roughness:l=Xn.roughness,opacity:d=Xn.opacity,width:c=0,height:u=0,angle:p=0,groupIds:m=[],frameId:h=null,index:f=null,roundness:g=null,boundElements:E=null,link:x=null,locked:b=Xn.locked,...y})=>{(t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:y.points});let w=Bx();return{id:y.id||Lx(),type:e,x:t,y:n,width:c,height:u,angle:p,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:m,frameId:h,index:f,roundness:g,seed:y.seed??vx(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:E,updated:w,created:y.created===void 0?w:y.created,link:x,locked:b,customData:y.customData}},Oi=e=>Mt(e.type,e),Nu=e=>Me(e,{backgroundColor:Ws(e.backgroundColor),strokeColor:Nn(e.strokeColor),fillStyle:"solid"}),_a=e=>{let t=Math.max(e.width,ku),n=Math.max(e.baseHeight||e.height||Tx,ku);return Me(e,{width:t,height:Math.max(e.height,n),baseHeight:n})},_A=e=>_a(Nu(e)),Lr=e=>{let t=Mt("stickynote",e);return Nu({...t,baseHeight:e.baseHeight??t.height})},Ou=e=>Mt("embeddable",e),Gu=e=>({...Mt("iframe",e)}),Fu=e=>Me({...Mt("frame",e),type:"frame",name:e?.name||null},{}),Ru=e=>Me({...Mt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Ha=e=>({x:e.textAlign==="center"?.5:e.textAlign==="right"?1:0,y:e.verticalAlign===pi.MIDDLE?.5:e.verticalAlign===pi.BOTTOM?1:0}),zu=(e,t)=>{let n=Ha(e);return{x:t.width*n.x,y:t.height*n.y}},fi=e=>{let t=e.fontFamily||Sx,n=e.fontSize||Ix,i=e.lineHeight||kx(t),o=ro(e.text),r=Ue(o,Po({fontFamily:t,fontSize:n}),i),s=e.textAlign||Mx,a=e.verticalAlign||Ax,l=zu({textAlign:s,verticalAlign:a},r),d={...Mt("text",e),text:o,fontSize:n,baseFontSize:e.baseFontSize??null,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i,labelPosition:e.labelPosition??null};return Me(d,{})},Cu=(e,t,n,i)=>{let{width:o,height:r}=Ue(n,Po(e),e.lineHeight);i!==void 0?o=i:e.autoResize||(o=e.width);let{textAlign:s,verticalAlign:a}=e,l,d;if(s==="center"&&a===pi.MIDDLE&&!e.containerId&&e.autoResize){let c=Ue(e.text,Po(e),e.lineHeight),u=zu(e,{width:o-c.width,height:r-c.height});l=e.x-u.x,d=e.y-u.y}else{let[c,u,p,m]=Q(e,t),[h,f,g,E]=In(e,o,r,!1),x=(c-h)/2,b=(u-f)/2,y=(p-g)/2,w=(m-E)/2;[l,d]=Cx({n:a===pi.MIDDLE||a===pi.BOTTOM,s:a===pi.MIDDLE||a===pi.TOP,e:s==="center"||s==="left",w:s==="center"||s==="right"},e.x,e.y,e.angle,x,b,y,w)}return{width:o,height:r,x:Number.isFinite(l)?l:e.x,y:Number.isFinite(d)?d:e.y}},Cx=(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]},_u=(e,t,n,i=e.text,o)=>{if(e.isDeleted)return;if(o!==void 0&&!t&&e.autoResize&&e.width<=o){let s=Po(e);if(Ue(i,s,e.lineHeight).width>o){let a=St(i,s,o);return{text:a,autoResize:!1,...Cu(e,n,a,o)}}}(t||!e.autoResize)&&(i=St(i,Po(e),t?kt(t,e):e.width));let r=Cu(e,n,i);return{text:i,...r}},Hu=e=>({...Mt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,strokeOptions:e.strokeOptions??{variability:"variable",streamline:Dx}}),Uu=e=>{let t={...Mt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Re(t)?{...t,polygon:e.polygon??!1}:t},Br=e=>e.elbowed?{...Mt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...Mt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},Wu=e=>({...Mt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ZA=(e,t,n,i)=>{for(let o=t.length-1;o>=0;o--){let r=t[o];if(!(!W(r)||r.locked||r.points.length<2))for(let s of["end","start"]){if(r[s==="start"?"startBinding":"endBinding"]||Xu(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(Nx(e,a)*i.value<R.POINT_HANDLE_SIZE+1)return{arrow:r,startOrEnd:s}}}return null},qA=(e,t,n,i)=>{let o=R.getPointAtIndexGlobalCoordinates(e,t==="start"?0:-1,n),r=R.getPointAtIndexGlobalCoordinates(e,t==="start"?1:-2,n);if(Xu(o,r))return null;let s=Yu(o,r),a=Math.abs(s[0])>=Math.abs(s[1])?s[0]>=0?Ee:ze:s[1]>=0?ve:qe,l=X(e)?0:Le({strokeWidth:i}),d=Rx(Yu(r,o)),c=Math.abs(Fx(d,Gx(a[0],a[1]))),u=Ox(zx(d,-l/c),o);return he(a,Ee)?{fixedPoint:je([0,.5]),anchor:u,textAlign:kr.LEFT,verticalAlign:Cr.MIDDLE}:he(a,ze)?{fixedPoint:je([1,.5]),anchor:u,textAlign:kr.RIGHT,verticalAlign:Cr.MIDDLE}:he(a,ve)?{fixedPoint:je([.5,0]),anchor:u,textAlign:kr.CENTER,verticalAlign:Cr.TOP}:{fixedPoint:je([.5,1]),anchor:u,textAlign:kr.CENTER,verticalAlign:Cr.BOTTOM}},QA=(e,t)=>!!e.boundElements?.some(({id:n,type:i})=>{if(i!=="arrow")return!1;let o=t.get(n);return W(o)&&(o.startBinding?.elementId===e.id||o.endBinding?.elementId===e.id)}),JA=e=>{let t=Ha(e).x;return{anchorRatio:t,anchorX:e.x+e.width*t}};M();import{distanceToLineSegment as $u,lineSegment as hi,lineSegmentIntersectionPoints as _x,pointDistance as Zt,pointFrom as Fi,pointRotateRads as Or,polygonArea as Io,polygonIncludesPoint as ju,polygonIncludesPointNonZero as Nr,polygonSignedArea as Wa}from"@excalidraw/math";import{isOpaqueColor as Hx,isTransparent as Mo}from"@excalidraw/common";var Ux=6,Wx=2,Yx=2,Xx=.5,$x={snapEpsilon:.5,gapTolerance:Ux,minArea:4,maxBoundarySegments:2560,maxGeneratedPoints:1536,fallbackSearchRadius:512},qu=([e,t,n,i],o)=>[e-o,t-o,n+o,i+o],jx=e=>Zt(e[0],e[1]),So=(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},Vu=(e,t,n,i,o)=>{let r=Math.min(e[0],t[0]),s=Math.max(e[0],t[0]),a=t[0]-e[0],l=t[1]-e[1],d=Math.floor((r-n)/i),c=Math.floor((s+n)/i);for(let u=d;u<=c;u++){let p=e[1],m=t[1];if(a!==0){let g=(Math.max(r,u*i-n)-e[0])/a,E=(Math.min(s,(u+1)*i+n)-e[0])/a;p=e[1]+g*l,m=e[1]+E*l}let h=Math.floor((Math.min(p,m)-n)/i),f=Math.floor((Math.max(p,m)+n)/i);for(let g=h;g<=f;g++)o(u,g)}},Vx=(e,t,n)=>{let i=n[0]-t[0],o=n[1]-t[1],r=Math.hypot(i,o);return r===0?Zt(e,t):Math.abs((e[0]-t[0])*o-(e[1]-t[1])*i)/r},Gi=(e,t,n)=>Fi(e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n),Kx=(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},Zx=(e,t)=>{let n=re(e,t),o=(e.roundness&&e.points.length>2?Et(Ro(e.points),.15,Xx):e.points).map(s=>Or(Fi(e.x+s[0],e.y+s[1]),n,e.angle)),r=[];for(let s=0;s<o.length-1;s++)r.push(hi(o[s],o[s+1]));return r},qx=(e,t)=>{let n=re(e,t),i=Pu(e).map(r=>Or(Fi(e.x+r[0],e.y+r[1]),n,e.angle)),o=[];for(let r=0;r<i.length-1;r++)o.push(hi(i[r],i[r+1]));return o},Qx=(e,t,n,i,o,r)=>{let s=[[0,1]];for(let a of n){if(s.length===0)break;let d=[0,...pt(a,i,hi(e,t)).map(u=>So(e,t,u)).filter(u=>u>0&&u<1).sort((u,p)=>u-p),1],c=[];for(let u=0;u<d.length-1;u++){let p=d[u],m=d[u+1];if(m-p<1e-9)continue;let h=Gi(e,t,(p+m)/2);Je(h,a,i)&&tn(a,i,h)>r&&c.push([p,m])}c.length&&(s=Kx(s,c))}return s.filter(([a,l])=>Zt(Gi(e,t,a),Gi(e,t,l))>=o).map(([a,l])=>[Gi(e,t,a),Gi(e,t,l)])},Ya=class{constructor(t){this.eps=t;this.cellSize=Math.max(t,1)}nodes=[];cells=new Map;cellSize;cellKey(t,n){return`${t}:${n}`}getOrCreate(t){let n=Math.floor(t[0]/this.cellSize),i=Math.floor(t[1]/this.cellSize);for(let a=-1;a<=1;a++)for(let l=-1;l<=1;l++){let d=this.cells.get(this.cellKey(n+a,i+l));if(d){for(let c of d)if(Zt(this.nodes[c],t)<=this.eps)return c}}let o=this.nodes.length;this.nodes.push(t);let r=this.cellKey(n,i),s=this.cells.get(r);return s?s.push(o):this.cells.set(r,[o]),o}forEachInRadius(t,n,i){let o=Math.floor((t[0]-n)/this.cellSize),r=Math.floor((t[0]+n)/this.cellSize),s=Math.floor((t[1]-n)/this.cellSize),a=Math.floor((t[1]+n)/this.cellSize);for(let l=o;l<=r;l++)for(let d=s;d<=a;d++){let c=this.cells.get(this.cellKey(l,d));if(c)for(let u of c)i(u)}}},Ku=e=>!(!oi(e.type)||e.fillStyle!=="solid"||e.opacity<100||!Hx(e.backgroundColor)||(Re(e)||ge(e))&&!Nt(e.points)),Qu=new Set(["rectangle","diamond","ellipse","frame","magicframe","line","freedraw"]),Xa=e=>e.opacity<=0,Ju=e=>!Xa(e)&&(e.type==="image"||!Mo(e.strokeColor)||oi(e.type)&&!Mo(e.backgroundColor)),em=e=>Re(e)&&e.polygon&&ps(e.points)&&!Xa(e)&&!Mo(e.backgroundColor)&&Mo(e.strokeColor),Jx=e=>Qu.has(e.type)?Re(e)?e.polygon&&ps(e.points):ge(e)?Nt(e.points):!0:!1,Ua=e=>!Xa(e)&&Qu.has(e.type)&&!Mo(e.strokeColor),eb=(e,t,n)=>{for(let i=t.length-1;i>=0;i--){let o=t[i];if(!(!Ju(o)||em(o))&&Jx(o)&&Je(e,o,n))return o}return null},tb=(e,t)=>{let n=t.snapEpsilon,i=new Ya(n),o=[],r=new Map;for(let{segment:D,elementId:L}of e){let P=i.getOrCreate(D[0]),B=i.getOrCreate(D[1]);if(r.has(P)||r.set(P,L),r.has(B)||r.set(B,L),P===B)continue;let k=i.nodes[P],_=i.nodes[B];o.push({a:P,b:B,pa:k,pb:_,elementId:L,box:[Math.min(k[0],_[0]),Math.min(k[1],_[1]),Math.max(k[0],_[0]),Math.max(k[1],_[1])],splits:[{node:P,t:0},{node:B,t:1}]})}let s=o.map(D=>hi(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],B=P.box[2]+n;for(let k=D+1;k<a.length;k++){let _=a[k],K=o[_];if(K.box[0]>B)break;if(!yt(qu(P.box,n),K.box))continue;let te=_x(s[L],s[_],n);if(!te)continue;let ne=i.getOrCreate(te);r.has(ne)||r.set(ne,P.elementId),P.splits.push({node:ne,t:So(P.pa,P.pb,i.nodes[ne])}),K.splits.push({node:ne,t:So(K.pa,K.pb,i.nodes[ne])})}}if(i.nodes.length>t.maxBoundarySegments*4)return null;let l=1/0,d=1/0,c=-1/0,u=-1/0;for(let D of o)l=Math.min(l,D.box[0]),d=Math.min(d,D.box[1]),c=Math.max(c,D.box[2]),u=Math.max(u,D.box[3]);let p=Math.max(c-l,u-d,0),m=Math.max(n*2,p/128),h=new Map;o.forEach((D,L)=>{Vu(D.pa,D.pb,n,m,(P,B)=>{let k=`${P}:${B}`,_=h.get(k);_?_.push(L):h.set(k,[L])})});for(let D=0;D<i.nodes.length;D++){let L=i.nodes[D],P=h.get(`${Math.floor(L[0]/m)}:${Math.floor(L[1]/m)}`);if(P)for(let B of P){let k=o[B];if(D===k.a||D===k.b)continue;let _=So(k.pa,k.pb,L);_<=0||_>=1||$u(L,s[B])<=n&&k.splits.push({node:D,t:_})}}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||Zt(i.nodes[D],i.nodes[L])<n)return;let B=x(D,L),k=E.get(B);k?k.add(P):E.set(B,new Set([P])),!f.has(B)&&(f.add(B),b(D,L),b(L,D))};for(let D of o){let L=new Map;for(let B of D.splits)L.has(B.node)||L.set(B.node,B.t);let P=[...L.entries()].map(([B,k])=>({node:B,t:k})).sort((B,k)=>B.t-k.t);for(let B=0;B<P.length-1;B++)y(P[B].node,P[B+1].node,D.elementId)}if(f.size===0)return[];let w=Math.max(n,t.gapTolerance),S=D=>new Set(g.get(D)??[]).size===1,I=[];for(let D of g.keys())S(D)&&I.push(D);if(I.length>0){let D=Math.max(w,p/128,1),L=new Map,P=(k,_)=>{let K={u:k,v:_};Vu(i.nodes[k],i.nodes[_],0,D,(te,ne)=>{let ie=`${te}:${ne}`,Ae=L.get(ie);Ae?Ae.push(K):L.set(ie,[K])})};for(let k of f){let[_,K]=k.split("-").map(Number);P(_,K)}let B=(k,_)=>{let K=x(k,_);f.delete(K);let te=E.get(K);E.delete(K);let ne=g.get(k),ie=g.get(_);return ne?.splice(ne.indexOf(_),1),ie?.splice(ie.indexOf(k),1),te};for(let k of I){if(!S(k))continue;let _=i.nodes[k],K=g.get(k)??[],te=-1,ne=1/0;i.forEachInRadius(_,w,Ne=>{if(Ne===k||K.includes(Ne))return;let De=Zt(_,i.nodes[Ne]);De>=n&&De<=w&&De<ne&&(ne=De,te=Ne)});let ie=null,Ae=1/0,_t=0,Ht=Math.floor(_[0]/D),bn=Math.floor(_[1]/D),fe=new Set;for(let Ne=-1;Ne<=1;Ne++)for(let De=-1;De<=1;De++){let Ze=L.get(`${Ht+Ne}:${bn+De}`);if(Ze)for(let qt of Ze){let gi=x(qt.u,qt.v);if(fe.has(gi)||(fe.add(gi),!f.has(gi)||qt.u===k||qt.v===k))continue;let wl=i.nodes[qt.u],Pl=i.nodes[qt.v],Kr=So(wl,Pl,_);if(Kr<=0||Kr>=1)continue;let Zr=$u(_,hi(wl,Pl));Zr<=w&&Zr<Ae&&(Ae=Zr,ie=qt,_t=Kr)}}let oe=r.get(k)??o[0].elementId;if(ie&&Ae<ne){let Ne=i.nodes[ie.u],De=i.nodes[ie.v],Ze=i.getOrCreate(Gi(Ne,De,_t));if(Ze===ie.u||Ze===ie.v)y(k,Ze,oe),P(k,Ze);else{r.has(Ze)||r.set(Ze,E.get(x(ie.u,ie.v))?.values().next().value??oe);let qt=B(ie.u,ie.v)??new Set([oe]);for(let gi of qt)y(ie.u,Ze,gi),y(Ze,ie.v,gi);P(ie.u,Ze),P(Ze,ie.v),y(k,Ze,oe),P(k,Ze)}}else te>=0&&(y(k,te,oe),P(k,te))}}let A=new Map,T=0;for(let D of g.keys()){if(A.has(D))continue;let L=[D];for(A.set(D,T);L.length;){let P=L.pop();for(let B of g.get(P)??[])A.has(B)||(A.set(B,T),L.push(B))}T++}let O=(D,L)=>Math.atan2(i.nodes[L][1]-i.nodes[D][1],i.nodes[L][0]-i.nodes[D][0]),v=new Map,N=new Map;for(let[D,L]of g){let P=Array.from(new Set(L));P.sort((k,_)=>O(D,k)-O(D,_)),v.set(D,P);let B=new Map;P.forEach((k,_)=>B.set(k,_)),N.set(D,B)}let C=new Set,z=[],U=f.size*2+4;for(let[D,L]of g)for(let P of L){if(C.has(`${D}->${P}`))continue;let B=[],k=D,_=P,K=0;for(;K++<=U;){C.add(`${k}->${_}`),B.push(k);let te=v.get(_),ie=(N.get(_).get(k)-1+te.length)%te.length,Ae=te[ie];if(k=_,_=Ae,k===D&&_===P)break}if(B.length>=3){let te=new Set;for(let ne=0;ne<B.length;ne++){let ie=E.get(x(B[ne],B[(ne+1)%B.length]));if(ie)for(let Ae of ie)te.add(Ae)}z.push({ring:B.map(ne=>i.nodes[ne]),contributors:te,componentId:A.get(D)??-1})}}return z},nb=(e,t,n)=>{if(e.length===0)return null;let i=1,o=new Map;for(let c of e)o.set(c,-Wa(c.ring,0));let r=null,s=1/0;for(let c of e){let u=o.get(c);if(Math.sign(u)===i)continue;let p=Math.abs(u);p<n.minArea||Nr(t,c.ring)&&p<s&&(s=p,r=c)}if(!r)return null;let a=r,l=e.filter(c=>c.componentId!==a.componentId&&Math.sign(o.get(c))===i&&Math.abs(o.get(c))>=n.minArea&&!Nr(t,c.ring)&&Nr(c.ring[0],a.ring)),d=l.filter(c=>!l.some(u=>u!==c&&Nr(c.ring[0],u.ring)));return{face:a,holes:d}},ib=(e,t)=>{let n=[];for(let i of e)(n.length===0||Zt(n[n.length-1],i)>=t)&&n.push(i);for(;n.length>1&&Zt(n[0],n[n.length-1])<t;)n.pop();return n},ob=(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];Vx(e[i],o,r)>=t&&n.push(e[i])}return n.length>=3?n:e},Zu=(e,t,n)=>{let i=ib(e,t.snapEpsilon);if(i.length<3)return null;let o=.75,r=Pn(i,o);for(;r.length>n&&o<1e6;)o*=2,r=Pn(i,o);return r.length>n?null:(r=ob(r,.05),r.length>=3?r:null)},rb=(e,t)=>{let n=Math.sign(Wa(t,0))===Math.sign(Wa(e,0))?[...t].reverse():t,i=0,o=0,r=1/0;for(let a=0;a<e.length;a++)for(let l=0;l<n.length;l++){let d=Zt(e[a],n[l]);d<r&&(r=d,i=a,o=l)}let s=e.slice(0,i+1);for(let a=0;a<=n.length;a++)s.push(n[(o+a)%n.length]);return s.push(e[i]),s.push(...e.slice(i+1)),s},sb=(e,t,n)=>{let i=Zu(e,n,n.maxGeneratedPoints);if(!i)return null;let o=t.map((s,a)=>({holeRing:s,index:a})).sort((s,a)=>Io(a.holeRing,0)-Io(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=Zu(s,n,l);d&&(i=rb(i,d),r.push(a))}return{scenePoints:[...i,i[0]],splicedHoleIndices:r}},pD=e=>{let t={...$x,...e.options},{point:n,elements:i,elementsMap:o}=e,r=eb(n,i,o),s=new Map;i.forEach((v,N)=>s.set(v.id,N));let a=(v,N)=>{let C=P=>yt(v,ae(P,o)),z=i.filter(P=>P.id!==N?.id&&Ua(P)&&C(P)),U=i.filter(P=>Ku(P)&&C(P)),D=[],L=P=>{let B=s.get(P.id)??0,k=U.filter(te=>te.id!==P.id&&(s.get(te.id)??0)>B),_=Math.max(t.snapEpsilon,P.strokeWidth/2,Yx),K=Re(P)?Zx(P,o):ge(P)?qx(P,o):Bi(P,o);if((P.type==="freedraw"||Re(P)&&!P.polygon)&&Nt(P.points)&&K.length>0){let te=K[0][0],ne=K[K.length-1][1];Zt(te,ne)>=t.snapEpsilon&&K.push(hi(ne,te))}for(let te of K){if(D.length>t.maxBoundarySegments)return;if(jx(te)!==0){if(k.length===0){D.push({segment:te,elementId:P.id});continue}for(let[ne,ie]of Qx(te[0],te[1],k,o,t.snapEpsilon,_))D.push({segment:hi(ne,ie),elementId:P.id})}}};for(let P of N?[N,...z]:z){if(D.length>t.maxBoundarySegments)break;L(P)}return D.length>t.maxBoundarySegments?null:D},l=v=>{let N=tb(v,t);return N?nb(N,n,t):"too_complex"},d=null;if(r){let v=t.gapTolerance+2+Math.max(r.strokeWidth??1,1),N=qu(ae(r,o),v),C=a(N,r);if(!C)return{ok:!1,reason:"too_complex"};let z=l(C);if(z==="too_complex")return{ok:!1,reason:"too_complex"};if(!z)return{ok:!1,reason:"open_region"};d=z}else{let v=i.reduce((C,z)=>C+(Ua(z)?1:0),0);if(v===0)return{ok:!1,reason:"no_owner"};let N=t.fallbackSearchRadius;for(let C=0;C<4&&!d;C++,N*=2){let z=[n[0]-N,n[1]-N,n[0]+N,n[1]+N],U=i.reduce((B,k)=>B+(Ua(k)&&yt(z,ae(k,o))?1:0),0),D=C===3||U===v;if(U===0)continue;let L=a(z,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(B=>B[0]>z[0]+t.gapTolerance&&B[1]>z[1]+t.gapTolerance&&B[0]<z[2]-t.gapTolerance&&B[1]<z[3]-t.gapTolerance))&&(d=P),!d&&D)break}if(!d)return{ok:!1,reason:"no_owner"}}let{face:c,holes:u}=d,p=sb(c.ring,u.map(v=>v.ring),t);if(!p)return{ok:!1,reason:"invalid_polygon"};let{scenePoints:m,splicedHoleIndices:h}=p;if(Io(m,0)<t.minArea)return{ok:!1,reason:"too_small"};let f=new Set(c.contributors);for(let v of h)for(let N of u[v].contributors)f.add(N);let g=new Set(r?[r.id,...f]:f);for(let v of u)for(let N of v.contributors)g.add(N);let E=m,[x,b,y,w]=mi(m),S=v=>{let[N,C,z,U]=ae(v,o);if(z<x||N>y||U<b||C>w)return!1;let D=[Fi((N+z)/2,(C+U)/2)];if(ee(v)||ge(v)){let L=re(v,o),P=Math.max(1,Math.floor(v.points.length/8));for(let B=0;B<v.points.length;B+=P)D.push(Or(Fi(v.x+v.points[B][0],v.y+v.points[B][1]),L,v.angle))}return D.some(L=>ju(L,E))},I=v=>{let[N,C,z,U]=ae(v,o);if(z<x||N>y||U<b||C>w)return!1;if(Je(n,v,o))return!0;let D=Bi(v,o),L=Math.max(1,Math.floor(D.length/16));for(let B=0;B<D.length;B+=L)if(ju(D[B][0],E))return!0;let P=Math.max(1,Math.floor(m.length/16));for(let B=0;B<m.length;B+=P)if(Je(m[B],v,o))return!0;return!1},A=null,T=null;for(let v of i)Ku(v)&&I(v)&&(T=v),(g.has(v.id)||Ju(v)&&S(v))&&(A=A??v);let O=T?{placement:"above",elementId:T.id}:{placement:"below",elementId:(A??i[i.length-1]).id};return{ok:!0,ownerId:r?.id??null,boundaryElementIds:[...f].filter(v=>v!==r?.id),scenePoints:m,insertion:O}},fD=e=>{let{hitElement:t,scenePoints:n,elementsMap:i}=e;if(!em(t))return!1;let o=re(t,i),r=t.points.map(b=>Or(Fi(t.x+b[0],t.y+b[1]),o,t.angle)),s=Io(r,0),a=Io(n,0),l=Math.abs(s-a)<=.05*Math.max(s,a),[d,c,u,p]=mi(r),[m,h,f,g]=mi(n),E=Wx,x=Math.abs(d-m)<=E&&Math.abs(c-h)<=E&&Math.abs(u-f)<=E&&Math.abs(p-g)<=E;return l&&x};M();import{arrayToMap as Qb,arrayToObject as hn,assertNever as wm,isDevEnv as gn,isShallowEqual as Ja,isTestEnv as En,randomInteger as ym}from"@excalidraw/common";M();import{assertNever as gb,COLOR_PALETTE as Eb,isDevEnv as xb,isTestEnv as bb,randomId as yb,Emitter as om,toIterable as zi}from"@excalidraw/common";M();import{ORIG_ID as cb,randomId as nm,randomInteger as ub,arrayToMap as im,castArray as $a,findLastIndex as Ri,getUpdatedTimestamp as mb,isTestEnv as pb}from"@excalidraw/common";M();import{arrayToMap as ab}from"@excalidraw/common";var lb=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},db=e=>{let t=ab(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]},tm=e=>db(lb(e));var fb=(e,t,n,i)=>{let o=Va(n);return pb()&&hb(o,n.id),o.id=nm(),o.updated=mb(),o.created=o.updated,i&&(o.seed=ub(),Ls(o)),o.groupIds=Yc(o.groupIds,e,r=>(t.has(r)||t.set(r,nm()),t.get(r))),o},LD=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},i=new Map,o=new Map,r=[],s=[],a=new Map,l=new Map,d=new Map,c=new Map,u=im(t),p=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(x=>[x.id,x])),m=e.type==="everything"&&e.preserveFrameChildrenOrder;if(e.type==="in-place")for(let x of Object.keys(e.appState.selectedGroupIds))t.filter(b=>b.groupIds?.includes(x)).forEach(b=>p.set(b.id,b));t=tm(t);let h=t.slice(),f=x=>{let y=$a(x).reduce((w,S)=>{if(i.has(S.id))return w;i.set(S.id,!0),$e(S)||console.error("[NONDELETED][INVARIANT] Element to duplicate should be non-deleted");let I=fb(n.editingGroupId,o,S,e.randomizeSeed);return i.set(I.id,!0),d.set(I.id,I),c.set(S.id,S),a.set(S.id,I.id),l.set(I.id,S.id),s.push(S),r.push(I),w.push(I),w},[]);return Array.isArray(x)?y:y[0]||null},g=(x,b)=>{if(b){if(x>h.length-1){h.push(...$a(b));return}h.splice(x+1,0,...$a(b))}},E=new Set(t.filter(x=>p.has(x.id)&&J(x)).map(x=>x.id));for(let x of t){if(i.has(x.id)||!p.has(x.id))continue;let b=xa(n,x);if(b){let y=it(t,b).flatMap(S=>J(S)&&!m?[...zn(t,S.id),S]:[S]),w=Ri(h,S=>S.groupIds?.includes(b));g(w,f(y));continue}if(!(!m&&x.frameId&&E.has(x.frameId))){if(J(x)){let y=x.id;if(m){g(Ri(h,I=>I.id===y),f(x));continue}let w=zn(t,y),S=Ri(h,I=>I.frameId===y||I.id===y);g(S,f([...w,x]));continue}if(Wt(x)){let y=q(x,u),w=Ri(h,S=>S.id===x.id||"containerId"in S&&S.containerId===x.id);y?g(w,f([x,y])):g(w,f(x));continue}if(pe(x)){let y=Be(x,u),w=Ri(h,S=>S.id===x.id||S.id===y?.id);y?g(w,f([y,x])):g(w,f(x));continue}g(Ri(h,y=>y.id===x.id),f(x))}}if(wc(r,a,d),Qc(h,s,a),e.overrides)for(let x of r){let b=c.get(l.get(x.id));b&&Object.assign(x,e.overrides({duplicateElement:x,origElement:b,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,origElementsMap:c,elementsWithDuplicates:h,origIdToDuplicateId:a,duplicateIdToOrigId:l}},BD=(e,t,n)=>{if(e===!1)return{elements:t,duplicatedElements:[]};if(!e)return{elements:t,duplicatedElements:n};let i=im(n),o=new Map;for(let d of e)i.has(d.id)&&o.set(d.id,d);let r=new Set;for(let[d,c]of o){let u=i.get(d);c!==u&&(Object.assign(u,c),Qe.delete(u),Ls(u)),u.isDeleted||r.add(d)}let s=d=>i.has(d)&&!r.has(d);for(let d of r){let c=i.get(d);pe(c)&&s(c.containerId)&&r.delete(d)}let a=[];for(let d of e){let c=i.get(d.id);c?r.has(d.id)&&o.get(d.id)===d&&a.push(c):a.push(d)}if(r.size===n.length)return{elements:a,duplicatedElements:n};let l=n.filter(d=>r.has(d.id));for(let d of l){let c={};d.boundElements?.some(u=>s(u.id))&&(c.boundElements=d.boundElements.filter(u=>!s(u.id))),d.frameId&&s(d.frameId)&&(c.frameId=null),W(d)&&(d.startBinding&&s(d.startBinding.elementId)&&(c.startBinding=null),d.endBinding&&s(d.endBinding.elementId)&&(c.endBinding=null)),Object.assign(d,c)}return{elements:a,duplicatedElements:l}},ja=(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]=ja(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=ja(e[i],t+1);return o}return G.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},Va=e=>ja(e),hb=(e,t)=>{Object.defineProperty(e,cb,{value:t,writable:!1,enumerable:!1})};var gt={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},rm=class{constructor(t){this.app=t}onDurableIncrementEmitter=new om;onStoreIncrementEmitter=new om;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Vn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(gt.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=Vn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?Zc(t.elements):void 0,t.appState);i=To.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=Vn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=To.create(o,t),i?s=i:s=qa.calculate(o,t),!s.isEmpty()){let a=new Ka(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=To.create(r,t)}let o=new Za(i);this.onStoreIncrementEmitter.trigger(o)}applyChangeToSnapshot(t){let n=this.snapshot,i=this.snapshot.applyChange(t);return n===i?null:i}maybeCloneSnapshot(t,n,i){if(!n&&!i)return null;let o=this.snapshot,r=this.snapshot.maybeClone(t,n,i);return o===r?null:r}flushMicroActions(){for(let t of this.scheduledMicroActions)try{t()}catch(n){console.error("Failed to execute scheduled micro action",n)}this.scheduledMicroActions=[]}processAction(t){let{action:n}=t;if(n===gt.EVENTUALLY&&!this.onStoreIncrementEmitter.subscribers.length)return;let i;if("change"in t?i=this.applyChangeToSnapshot(t.change):i=this.maybeCloneSnapshot(n,t.elements,t.appState),!i)return;let o="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case gt.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case gt.NEVER:case gt.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:gb(n,"Unknown store action")}}finally{switch(n){case gt.IMMEDIATELY:case gt.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(gt.IMMEDIATELY)?t=gt.IMMEDIATELY:this.scheduledMacroActions.has(gt.NEVER)?t=gt.NEVER:t=gt.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(gt).length)){let t=`There can be at most three store actions scheduled at the same time, but there are "${this.scheduledMacroActions.size}".`;if(console.error(t,this.scheduledMacroActions.values()),bb()||xb())throw new Error(t)}}},To=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},Gr=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Ka=class extends Gr{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},Za=class extends Gr{constructor(n){super("ephemeral",n);this.change=n}},qa=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:yb()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?jn.calculate(t.elements,n.elements):jn.empty(),o=n.metadata.didAppStateChange?$n.calculate(t.appState,n.appState):$n.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,jn.restore(i),$n.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=jn.create(n,i,o),a=$n.create(r);return new this(t,s,a)}static squash(...t){let n=e.empty();for(let i of t)n.elements.squash(i.elements),n.appState.squash(i.appState);return n}static inverse(t){return this.create(t.elements.inverse(),t.appState.inverse())}static applyTo(t,n,i,o){let[r,s]=t.elements.applyTo(n,Vn.empty().elements,o),[a,l]=t.appState.applyTo(i,r);return[r,a,s||l]}static applyLatestChanges(t,n,i,o){return this.create(t.elements.applyLatestChanges(n,i,o),t.appState,{id:t.id})}static empty(){return e.create(jn.empty(),$n.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Vn=class e{constructor(t,n,i={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=i}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,i={didElementsChange:!1,didAppStateChange:!1}){return new e(t,sm(n)?n:_i(n),i)}static empty(){return new e(new Map,wb(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of zi(t.elements))this.elements.get(i.id)||(n[i.id]=Me(i,{isDeleted:!0}));for(let i of zi(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return V.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=_i({...this.appState,...t.appState});return e.create(n,i,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,i){let o={shouldCompareHashes:!1};t===gt.EVENTUALLY&&(o.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,o),s=this.maybeCreateAppStateSnapshot(i,o),a=!1,l=!1;return this.elements!==r&&(a=!0),this.appState!==s&&(l=!0),!a&&!l?this:new e(r,s,{didElementsChange:a,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let i=sm(t)?t:_i(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=V.isRightDifferent(this.appState,t);if(!i)return;let o=dm(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 zi(this.elements))t.get(r.id)||i.set(r.id,Me(r,{isDeleted:!0}));for(let r of zi(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(Oe(r)&&!ei(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=lm(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of zi(this.elements))n.set(i.id,i);for(let i of zi(t))n.set(i.id,Va(i));return n}},am="__observedAppState",wb=()=>({name:null,editingGroupId:null,viewBackgroundColor:Eb.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),_i=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,am,{value:!0,enumerable:!1}),t},sm=e=>!!Reflect.get(e,am);M();var bm=Mp(fm(),1);import{randomInteger as zb,arrayToMap as _b,toBrandedType as hm,isDevEnv as gm,isTestEnv as Em,toArray as Hb}from"@excalidraw/common";import{isNonDeletedElement as Ub}from"@excalidraw/element";import{isFrameLikeElement as Wb}from"@excalidraw/element";import{getElementsInGroup as Yb}from"@excalidraw/element";import{syncInvalidIndices as Xb,syncMovedIndices as $b,validateFractionalIndices as jb}from"@excalidraw/element";import{getSelectedElements as Vb}from"@excalidraw/element";import{mutateElement as Kb}from"@excalidraw/element";var xm=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}},Zb=(0,bm.default)(e=>{(gm()||Em()||window?.DEBUG_FRACTIONAL_INDICES)&&jb(e,{shouldThrow:gm()||Em(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),qb=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Hi=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=hm(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=hm(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=qb(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=Vb(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&&Ub(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=Hb(t),o=[];n?.skipValidation||Zb(i),this.elements=Xb(i),this.elementsMap.clear(),this.elements.forEach(s=>{Wb(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=xm(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=xm(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=zb();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementsAtIndex(t,n){if(!t.length)return;if(n===null&&(n=this.elements.length),!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];$b(i,_b(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]:Yb(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=Kb(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var V=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i=e.empty()){return e.create({...t.deleted,...n.deleted,...i.deleted},{...t.inserted,...n.inserted,...i.inserted})}static mergeObjects(t,n,i={}){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(hn(t??[],o),hn(n??[],o),hn(i??[],o)))}static diffObjects(t,n,i,o){if(!t[i]&&!n[i])return;let r=t[i]!==null&&typeof t[i]=="object",s=n[i]!==null&&typeof n[i]=="object";if(r||s){let a=t[i]??{},l=n[i]??{},d=e.getLeftDifferences(a,l).reduce((u,p)=>(u[p]=o(a[p]),u),{}),c=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=o(l[p]),u),{});Object.keys(d).length||Object.keys(c).length?(Reflect.set(t,i,d),Reflect.set(n,i,c)):(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}else t[i]===n[i]&&(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}static diffArrays(t,n,i,o){if(!(!t[i]&&!n[i])&&(Array.isArray(t[i])||Array.isArray(n[i]))){let r=Array.isArray(t[i])?t[i]:[],s=Array.isArray(n[i])?n[i]:[],a=hn(e.getLeftDifferences(hn(r,o),hn(s,o)),d=>d),l=hn(e.getRightDifferences(hn(r,o),hn(s,o)),d=>d);if(Object.keys(a).length||Object.keys(l).length){let d=r.filter(u=>a[o?o(u):String(u)]),c=s.filter(u=>l[o?o(u):String(u)]);Reflect.set(t,i,d),Reflect.set(n,i,c)}else Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i)}}static isLeftDifferent(t,n,i=!1){return!!this.distinctKeysIterator("left",t,n,i).next().value}static isRightDifferent(t,n,i=!1){return!!this.distinctKeysIterator("right",t,n,i).next().value}static isInnerDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("inner",t,n,i).next().value}static isDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("full",t,n,i).next().value}static getLeftDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("left",t,n,i)).sort()}static getRightDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("right",t,n,i)).sort()}static getInnerDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("inner",t,n,i)).sort()}static getDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("full",t,n,i)).sort()}static*distinctKeysIterator(t,n,i,o=!1){if(n===i)return;let r=[];t==="left"?r=Object.keys(n):t==="right"?r=Object.keys(i):t==="inner"?r=Object.keys(n).filter(s=>s in i):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(i)])):wm(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let s of r){let a=n[s],l=i[s];if(a!==l){if(!o&&typeof a=="object"&&typeof l=="object"&&a!==null&&l!==null&&Ja(a,l))continue;yield s}}}},$n=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=V.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(V.create({},{}))}inverse(){let t=V.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=V.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=V.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=V.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=V.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=V.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=V.mergeObjects(this.delta.inserted.lockedMultiSelections??{},t.delta.inserted.lockedMultiSelections??{}),l={},d={};return(Object.keys(n).length||Object.keys(i).length)&&(d.selectedElementIds=n,l.selectedElementIds=i),(Object.keys(o).length||Object.keys(r).length)&&(d.selectedGroupIds=o,l.selectedGroupIds=r),(Object.keys(s).length||Object.keys(a).length)&&(d.lockedMultiSelections=s,l.lockedMultiSelections=a),this.delta=V.merge(this.delta,t.delta,V.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:s={},selectedGroupIds:a={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=V.mergeObjects(t.selectedElementIds,s,i),p=V.mergeObjects(t.selectedGroupIds,a,o),m=V.mergeObjects(t.lockedMultiSelections,l,r),h=d&&n.has(d.elementId)?new R(n.get(d.elementId),n,d.isEditing):null,f={...t,...c,selectedElementIds:u,selectedGroupIds:p,lockedMultiSelections:m,selectedLinearElement:typeof d<"u"?h:t.selectedLinearElement},g=this.filterInvisibleChanges(t,f,n);return[f,g]}catch(i){if(console.error("Couldn't apply appstate change",i),En()||gn())throw i;return[t,!1]}}isEmpty(){return V.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=_i(t),r=_i(n),s=V.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=V.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=V.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=Hc(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let b=i.get(x);b&&!b.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?c.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=i.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let h=t[u]||{},f=n[u]||{};Ja(h,f)||(l.value=!0);break;case"activeLockedId":let g=t[u]||null,E=n[u]||null;g!==E&&(l.value=!0);break;default:wm(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{V.diffObjects(t,n,"selectedElementIds",i=>!0),V.diffObjects(t,n,"selectedGroupIds",i=>i??!1),V.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),En()||gn())throw i}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let i of Object.keys(t).sort())n[i]=t[i];return n}},jn=class e{constructor(t,n,i){this.added=t;this.removed=n;this.updated=i}static create(t,n,i,o={shouldRedistribute:!1}){let r;if(o.shouldRedistribute){let s={},a={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(i)];for(let[c,u]of d)this.satisfiesAddition(u)?s[c]=u:this.satisfiesRemoval(u)?a[c]=u:l[c]=u;r=new e(s,a,l)}else r=new e(t,n,i);return(En()||gn())&&(e.validate(r,"added",this.satisfiesAddition),e.validate(r,"removed",this.satisfiesRemoval),e.validate(r,"updated",this.satisfiesUpdate)),r}static restore(t){let{added:n,removed:i,updated:o}=t;return e.create(n,i,o)}static satisfiesAddition=({deleted:t,inserted:n})=>t.isDeleted===!0&&!n.isDeleted;static satisfiesRemoval=({deleted:t,inserted:n})=>!t.isDeleted&&n.isDeleted===!0;static satisfiesUpdate=({deleted:t,inserted:n})=>!!t.isDeleted==!!n.isDeleted;static satisfiesCommmonInvariants=({deleted:t,inserted:n})=>!!(Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static satisfiesUniqueInvariants=(t,n)=>{let{added:i,removed:o,updated:r}=t;return[i[n],o[n],r[n]].filter(Boolean).length===1};static validate(t,n,i){for(let[o,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!this.satisfiesUniqueInvariants(t,o)||!i(r))throw console.error(`Broken invariant for "${n}" delta, element "${o}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${o}".`)}static calculate(t,n){if(t===n)return e.empty();let i={},o={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s},d={isDeleted:!0,version:s.version+1,versionNonce:ym()},c=V.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:ym()},d={...s},c=V.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=V.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}r[s.id]=l}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=V.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,p)=>{let m;switch(p){case"deleted":m=d;break;case"inserted":m=c;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let h={};for(let f of Object.keys(u))switch(f){case"boundElements":h[f]=u[f];break;default:h[f]=m[f]}return h},r=d=>{let c={};for(let[u,p]of Object.entries(d)){let m=t.get(u),h=n.get(u),f=null;m||h?f=V.create(p.deleted,p.inserted,o(m,h),i):f=p,V.isInnerDifferent(f.deleted,f.inserted)&&(c[u]=f)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=Vn.empty().elements,i){let o=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let a=e.createApplier(t,o,n,s,i),l=a(this.added),d=a(this.removed),c=a(this.updated),u=this.resolveConflicts(t,o,s.applyDirection);r=new Map([...l,...d,...c,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),En()||gn())throw a;return[t,!0]}try{let a=new Set(r.keys()),l=new Map;for(let c of a){let u=t.get(c),p=o.get(c);for(let m of[u,p])if(m){j(m)&&m.containerId&&a.add(m.containerId);for(let h of m.boundElements??[])a.add(h.id)}u&&l.set(c,u===p?{...u}:u)}o=e.reorderElements(o,r,s);let d=En()||gn()?new Map(Array.from(o,([c,u])=>[c,u.version])):void 0;if(e.redrawElements(o,r),d){for(let[c,u]of o)if(d.get(c)!==u.version&&!a.has(c))throw new Error(`Redrawn element "${c}" is missing from idsToCheck`)}if(!s.containsVisibleDifference){for(let c of a)if(e.checkForVisibleDifference(l.get(c),o.get(c),l,o)){s.containsVisibleDifference=!0;break}}}catch(a){if(s.containsVisibleDifference=!0,console.error("Couldn't mutate elements after applying elements change",a),En()||gn())throw a}return[o,s.containsVisibleDifference]}squash(t){if(t.isEmpty())return this;let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=V.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=V.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return V.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=V.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=V.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=V.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(En()||gn())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,i,o,r)=>s=>{let a=e.createGetter(n,i,o);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let p=e.applyDelta(u,c,o,r);if(n.set(p.id,p),l.set(p.id,p),!o.applyDirection){let m=t.get(d);m&&(o.applyDirection=m.version>p.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?i.containsZindexDifference=!0:s=Me({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=V.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Me(t,r,!0)}static checkForVisibleDifference(t,n,i,o){let r=(d,c)=>!d||d.isDeleted||j(d)&&!d.text.trim()&&!d.boundElements?.length&&!W(c.get(d.containerId??""))?null:d,s=r(t,i),a=r(n,o);if(!s||!a)return s!==a;let l=(d,c)=>(d.boundElements??[]).filter(u=>{let p=c.get(u.id);return u.type!=="text"||W(d)||!p||!j(p)||!!p.text.trim()}).map(({id:u,type:p})=>`${p}:${u}`);return V.getDifferences(s,a).some(d=>{switch(d){case"index":case"version":case"versionNonce":case"updated":case"created":return!1;case"boundElements":return!Ja(l(s,i),l(a,o));default:return!0}})}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,p=l,m;c===d?m=Me(d,{...p,version:u},!0):m=He(d,n,{...p,version:c?.version!==d.version?d.version:u}),o.set(m.id,m),n.set(m.id,m)};for(let a of Object.keys(this.removed))e.unbindAffected(t,n,a,r);for(let a of Object.keys(this.added))e.rebindAffected(t,n,a,r);for(let[a]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>Pc.has(c)))){let l=n.get(a);!l||l.isDeleted||e.rebindAffected(t,n,a,r)}let s=new Map(Array.from(t).filter(([a])=>o.has(a)));return this.squash(e.calculate(s,o)),o}static unbindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Fn.unbindAffected(n,r(),o),Fn.unbindAffected(n,s(),o),Rn.unbindAffected(n,r(),o),Rn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Fn.unbindAffected(n,r(),o),Fn.rebindAffected(n,s(),o),Rn.unbindAffected(n,r(),(a,l)=>{j(a)&&o(a,l)}),Rn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Hi(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),En()||gn())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(pe(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=Ct(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||Ti(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Pe(i)&&Ge(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=Kc([...o]),s=V.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),Qb(di(r,s))}static postProcess(t,n){try{V.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];V.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),En()||gn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};M();var hv=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=pn(e),c=Pr(e,t,i).map(Ci).map(h=>[h,pn(h)]).sort((h,f)=>h[1][s]-f[1][s]),u=0;for(let h of c)u+=h[1][l];let p=(d[l]-u)/(c.length-1);if(p<0){let h=c.findIndex(x=>x[1][r]===d[r]),f=c.findIndex(x=>x[1][a]===d[a]),g=(c[f][1][s]-c[h][1][s])/(c.length-1),E=c[h][1][s];return c.flatMap(([x,b],y)=>{let w={x:0,y:0};return y!==h&&y!==f&&(E+=g,w[n.axis]=E-b[s]),x.map(S=>{let I=o.mutateElement(S,{x:S.x+w.x,y:S.y+w.y});return Ge(S,o,{simultaneouslyUpdated:x}),I})})}let m=d[r];return c.flatMap(([h,f])=>{let g={x:0,y:0};return g[n.axis]=m-f[r],m+=p,m+=f[l],h.map(E=>{let x=o.mutateElement(E,{x:E.x+g.x,y:E.y+g.y});return Ge(E,o,{simultaneouslyUpdated:h}),x})})};M();import{TEXT_AUTOWRAP_THRESHOLD as Jb,getGridPoint as ey,getFontString as ty,DRAGGING_THRESHOLD as ny}from"@excalidraw/common";var Mv=(e,t,n,i,o,r)=>{if(t.length===1&&X(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(X(m)&&m.startBinding&&m.endBinding){let h=t.find(g=>g.id===m.startBinding?.elementId),f=t.find(g=>g.id===m.endBinding?.elementId);return h&&f}return!0}),a=new Set(s),l=s.filter(m=>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 h=e.originalElements.get(m.id);if(!h)return;d.push(h)}let c=iy(ot(d),n,o,r),u=Array.from(a),p=ua(u);a.forEach(m=>{if(W(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>ny||!m.startBinding&&!m.endBinding){el(e,m,i,c);let h=m.startBinding?!p.has(m.startBinding.elementId):!0,f=m.endBinding?!p.has(m.endBinding.elementId):!0;(h||f)&&(h&&Ke(m,"start",i),f&&Ke(m,"end",i))}}else{el(e,m,i,c);let h=q(m,i.getNonDeletedElementsMap());h&&el(e,h,i,c),Ge(m,i,{simultaneouslyUpdated:u})}})},iy=(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]=ey(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},el=(e,t,n,i)=>{let o=e.originalElements.get(t.id)??t,r=o.x+i.x,s=o.y+i.y;n.mutateElement(t,{x:r,y:s})},Tv=(e,t,n)=>{let[i,o]=ot(e);return[t-i,n-o]},oy=({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,ar(ty({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight));s.mutateElement(e,{x:t-c*n,...o===void 0?{}:{y:o},width:c,...d>Jb/r?{autoResize:!1}:{}},{informMutation:a,isDragging:!1})},Av=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:p=null,originOffset:m=null,informMutation:h=!0})=>{if(l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=za(t,a,o<n?-s:s):{width:s,height:a}=za(t,s,r<i?-a:a),a<0&&(a=-a))),j(e)){oy({newElement:e,anchorX:n+(m?.x??0),anchorRatio:d?.5:o<n?1:0,pointerX:o,nextY:i+(m?.y??0),zoom:c,scene:u,informMutation:h});return}let f=o<n?n-s:n,g=r<i?i-a:i;if(d&&(s+=s,a+=a,f=n-s/2,g=i-a/2),s!==0&&a!==0){let E=null;Oe(e)&&(E={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:f+(m?.x??0),y:g+(m?.y??0),width:s,height:a,...E},{informMutation:h,isDragging:!1})}};M();import{ELEMENT_LINK_KEY as Rr,normalizeLink as Pm}from"@excalidraw/common";var kv=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Rr,e),Pm(i.toString())}catch(i){console.error(i)}return Pm(n)},Cv=(e,t)=>{if(e.length>0&&ry(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},ry=e=>!!(e.length===1||e.length>1&&Uc(e)),Nv=e=>{try{let t=new URL(e);return t.searchParams.has(Rr)&&t.host===window.location.host}catch{return!1}},Ov=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Rr))return t.get(Rr)}catch{}return null};M();import{FONT_FAMILY as sy,VERTICAL_ALIGN as ay,escapeDoubleQuotes as tl,getFontString as ly}from"@excalidraw/common";var Rt=new Map,dy=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|live\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,cy=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,uy=/^https:\/\/(?:www\.)?figma\.com/,Sm=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,my=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,py=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Im=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,fy=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,hy=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,gy=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Mm=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Tm=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,Ey=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Dm=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)},xy=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=Dm(t.toString());return{fileId:i,resourceKey:r&&/^[a-zA-Z0-9_-]+$/.test(r)?r:void 0,timestamp:s>0?s:void 0}}catch{return null}},il=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Am=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),nl=e=>`<html><body>${e}</body></html>`,Uv=e=>{if(!e)return null;if(Rt.has(e))return Rt.get(e);let t=e,n=Am.has(ol(e,Am)||""),i="generic",o={w:560,h:840},r=e.match(dy);if(r?.[2]){let c=Dm(t),u=c>0?`&start=${c}`:"",p=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${u}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break}return o=p?{w:315,h:560}:{w:560,h:315},Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(cy);if(s?.[1]){let c=s?.[1],u=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${c}?api=1`,o={w:560,h:315},Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=xy(e);if(a){i="video";let c=new URLSearchParams;a.resourceKey&&c.set("resourcekey",a.resourceKey),a.timestamp&&c.set("t",`${a.timestamp}`);let u=c.toString();return e=`https://drive.google.com/file/d/${a.fileId}/preview${u?`?${u}`:""}`,o={w:560,h:315},Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(uy))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(hy);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),Rt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(py.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Im.test(e)){let c=e.match(Im)[1],u=tl(`https://twitter.com/x/status/${c}`),p={type:"document",srcdoc:m=>nl(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${m}"><a href="${u}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return Rt.set(t,p),p}if(Tm.test(e)){let[,c,u,p]=e.match(Tm),m=tl(`https://reddit.com/r/${c}/comments/${u}/${p}`),h={type:"document",srcdoc:f=>nl(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${m}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return Rt.set(t,h),h}if(Sm.test(e)){let[,c,u]=e.match(Sm),p=tl(`https://gist.github.com/${c}/${u}`),m={type:"document",srcdoc:()=>nl(`
|
|
22
|
+
<script src="${p}.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 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}}},sT=e=>{let t;Co(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=ix.Helvetica,o=rx({fontSize:n,fontFamily:i});return si({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:rn(t,o,e.width-20),textAlign:"center",verticalAlign:ox.MIDDLE,angle:e.angle??0})},Ma=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(Sa.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return Sa.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},aT=e=>{let t=e.match(ux);if(t&&t.length===2)return t[1];let n=e.match(fx);if(n&&n.length===2)return n[1];let i=e.match(dx);if(i&&i.length===2)return i[1];if(fu.test(e))return`https://giphy.com/embed/${fu.exec(e)[1]}`;let o=e.match(px);return o&&o.length===2?o[1]:e},lT=(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(Ma(e,n))return!0;return!1}}return!!Ma(e,Sa)};I();import{invariant as Aa,toBrandedType as gx}from"@excalidraw/common";import{clamp as Ex,pointFrom as xu}from"@excalidraw/math";var bu=100,wu=100,xx=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},Iu=(e,t,n)=>n.every(i=>e+t<=i.start||e>=i.end),bx=(e,t,n)=>{if(Iu(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=Ex(e,i[a],o[a]-t),d=Math.abs(l-e);d<=s&&(r=l,s=d)}return r},wx=(e,t)=>{let n=[...t.values()].filter(j),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},yx=(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?wu:bu,d=r?bu:wu,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=xx(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=>Iu(b,f,p)).sort((b,y)=>Math.abs(b+f/2-u)-Math.abs(y+f/2-u))[0]??null)??bx(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}},Px=(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 Aa(Dl(i),"not an ExcalidrawFlowchartNodeElement"),i},Ix=(e,t,n,i,o,r=null)=>{let s=i.getNonDeletedElementsMap(),a=wx(e,s).map(u=>lt(u,s)),{positions:l,crossStart:d}=yx(e,n,o,a,r),c=[];for(let u of l){let m=Px(e,u.x,u.y),p=Sx(e,m,n,t,i);c.push(m,p)}return{nodes:c,crossStart:d}},Sx=(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=br({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:[xu(0,0),xu(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=xi(c,gx(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p,isDeleted:c.isDeleted}},yu=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(j(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;Aa(we(d),"not an ExcalidrawBindableElement");let c=t==="predecessors"?a.points[a.points.length-1]:[0,0],u=gi(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,Be)).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)}},Pu=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}=Ix(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);Aa(l&&ko(l),"not an ExcalidrawFrameElement"),l&&this.pendingNodes.every(d=>Gn([d],l,r)||Ln(d,l,r))&&(this.pendingNodes=this.pendingNodes.map(d=>Fe(d,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0,this.clusterCrossStart=null}},PT=(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 Da}from"@excalidraw/math";import{invariant as Ou}from"@excalidraw/common";I();import{arrayToMap as Mu,findIndex as Au,findLastIndex as Tu}from"@excalidraw/common";import{isFiniteNumber as Mx}from"@excalidraw/math";var Ta=(e,t)=>e.frameId===t||e.id===t,Du=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Mu(n||Zt(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},Ax=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),[])},Su=(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))}}},Tx=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{Ta(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},vu=(e,t,n,i,o,r)=>{let s=r||sn(e,kn(n),i);if(!s)return n;let a=de(s,i),l=oe(s)?Ue(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},Dx=(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"?Tu(t,m=>a(m),Math.max(0,n-1)):Au(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Su(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||J(d))){let m=Tx(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Su(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},Bu=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Lu=(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},Cu=(e,t,n,i)=>{let o=e,r=Du(e,t),s=Bu(e,r),a=Ax(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=Dx(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]}),Lu(o,e)?(ni(e,s),e):o},Gu=(e,t,n,i,o)=>{let r=Du(e,t,o);if(r.length===0)return e;let s=Bu(e,r),a=[],l,d;if(n==="left"){if(i)l=Au(e,f=>Ta(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=Tu(e,f=>Ta(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=>Mx(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 Lu(e,h)?(ni(h,s),h):e};function ku(e,t,n,i){let o=Mu(Zt(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 kT=(e,t,n)=>Cu(e,t,"left",n),OT=(e,t,n)=>Cu(e,t,"right",n),NT=(e,t)=>ku(e,t,"left",Gu),FT=(e,t)=>ku(e,t,"right",Gu);var Tr=(e,t,n,i,o,r,s=!1)=>{if(j(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)<no*1.5/o.zoom.value)return!1}let a=R.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return Gi(e,a)>=no*1.5/o.zoom.value&&Ht({element:n,elementsMap:i,point:e,threshold:ve(n,t),overrideShouldTestInside:!0})},vx=(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})},Nu=(e,t,n,i,o,r,s)=>{let a=R.getElement(e.elementId,t);if(!a||!_e(a)||j(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,m=Da(n.x-c,n.y-u),p=l?"startBinding":"endBinding",h=rd(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",...yi(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)}vx(a,h,l,t,i,o,s),h&&$t(o)&&vu(m,a,i.getElementsIncludingDeleted(),t,i,h)},$T=(e,t,n,i)=>{let o=Da(t.origin.x,t.origin.y),r=no*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&we(s)&&!s.isDeleted){let a=He(e.startBinding.fixedPoint,s,n);if(Tr(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=He(e.endBinding.fixedPoint,s,n);if(Tr(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}},VT=(e,t)=>{Ou(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=R.getElement(e.elementId,t.getNonDeletedElementsMap());Ou(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}},ZT=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=Da(t,n),a=no*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&we(l)&&!l.isDeleted){let d=He(e.startBinding.fixedPoint,l,r);if(Tr(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=He(e.endBinding.fixedPoint,l,r);if(Tr(d,e,l,r,o,"end")&&Gi(s,d)<=a)return"end"}}return null};I();import{MIME_TYPES as Fu,SVG_NS as Bx}from"@excalidraw/common";var Lx=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===Fu.binary)throw new Error("Only images can be added to ImageCache");let l=Lx(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}},tD=e=>e.filter(t=>Vn(t)),Cx=e=>e?.nodeName.toLowerCase()==="svg",nD=e=>{let t=new DOMParser().parseFromString(e,Fu.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Cx(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Bx);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 aD=(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 Gx,normalizeRadians as vr,pointFrom as me,pointRotateRads as Nt}from"@excalidraw/math";import{MIN_FONT_SIZE as Ba,SHIFT_LOCKING_ANGLE as Br,rescalePoints as Ru,getFontString as Dr}from"@excalidraw/common";var wD=(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")j(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}=zx(h,f,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});Rx(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 Nx(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:h,flipByY:f,originalBoundingBox:g}=_x(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return Hx(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+Br/2,u=u-u%Br),u=vr(u));let m=Bt(e),p={angle:u};if(_e(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&&!X(e)){let{x:f,y:g}=Ki(e,h,t.getNonDeletedElementsMap());t.mutateElement(h,{angle:u,x:f,y:g})}}},zu=(e,t,n,i)=>K(e)||be(e)?{points:Ru(0,t,Ru(1,n,e.points,i),i)}:{},La=(e,t,n)=>{let i=e.width;if(Ie(e)){let s=Ue(e,t);s&&(i=vt(s,e))}let r=e.fontSize*(n/i);return r<Ba?null:{size:r}},Ox=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=La(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=me(e.x,e.y),u=va(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=zo(Dr({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=rn(t.originalText,Dr(t),Math.abs(u)),p=ft(m,Dr(t),t.lineHeight),h=p.height,f=me(e.x,e.y),g=va(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)}}},Nx=(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+=Br/2,d-=d%Br);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=j(u)?{points:Ld(u,l)}:{x:u.x+(b-g),y:u.y+(y-E),angle:vr(d+x)};n.mutateElement(u,w),je(u,n,{simultaneouslyUpdated:t}),_e(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=de(u,l);if(M&&!X(u)){let{x:S,y:T}=Ki(u,M,l);n.mutateElement(M,{x:S,y:T,angle:vr(d+x)})}}n.triggerUpdate()},yD=(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]}},PD=(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"},Fx=(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"},va=(e,t,n,i,o,r,s,a,l)=>{let d=Fx(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)}}},Rx=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(oe(n)&&oe(i))return Ox(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=de(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=La(m,u,vt(E,m));if(x===null)return;c={fontSize:x.size}}else{let E=Hl(Dr(m),m.lineHeight),x=Wl(m.fontSize,m.lineHeight);e=Math.max(e,E),t=Math.max(t,x)}}let p=zu(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=va(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]]}),X(n)&&m&&l){let g=e/n.width*m.fontSize;if(g<Ba)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};_e(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)}},zx=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=wn(t,t.width,t.height,!0),u=me(a,l),m=me(d,c),p=Gx(u,m),h=Nt(me(i,o),p,-t.angle),[f,g,E,x]=wn(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}},_x=(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=un(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}},Hx=(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=un([...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)||$d(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=vr(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),hn=B+_*(ne*S+Ft),pe=zu(P,C*G,z*_,!1),ie={x:Rt,y:hn,width:C,height:z,angle:Q,...pe};if(j(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=La(P,t,C);if(!Te)return;ie.fontSize=Te.size}let Le=o.get(Bt(P)??"");if(Le)if(k){let Te=Le.fontSize*T;if(Te<Ba)return;ie.boundTextFontSize=Te}else ie.boundTextFontSize=Le.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}),_e(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=de(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 Xu,pointRotateRads as Cr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as Fa}from"@excalidraw/common";I();import{DEFAULT_TRANSFORM_HANDLE_SPACING as Ga}from"@excalidraw/common";import{pointFrom as _u,pointRotateRads as Wx}from"@excalidraw/math";var Hu={mouse:8,pen:16,touch:28},Ux=16,Uu={e:!0,s:!0,n:!0,w:!0},vD={e:!0,s:!0,n:!0,w:!0},BD={e:!0,s:!0,n:!0,w:!0,rotation:!0},Wu={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},Ca={e:!0,s:!0,n:!0,w:!0},fn=(e,t,n,i,o,r,s)=>{let[a,l]=Wx(_u(e+n/2,t+i/2),_u(o,r),s);return[a-n/2,l-i/2,n,i]},Lr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),ka=e=>Lr(e)?Uu:{},Oa=([e,t,n,i,o,r],s,a,l,d={},c=4,u=Ga)=>{let m=Hu[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:fn(e-b-f+y,t-b-g+y,p,h,o,r,s),ne:d.ne?void 0:fn(n+b-y,t-b-g+y,p,h,o,r,s),sw:d.sw?void 0:fn(e-b-f+y,i+b-y,p,h,o,r,s),se:d.se?void 0:fn(n+b-y,i+b-y,p,h,o,r,s),rotation:d.rotation?void 0:fn(e+E/2-p/2,t-b-g+y-Ux/a.value,p,h,o,r,s)},M=5*Hu.mouse/a.value;return Math.abs(E)>M&&(d.n||(w.n=fn(e+E/2-p/2,t-b-g+y,p,h,o,r,s)),d.s||(w.s=fn(e+E/2-p/2,i+b-y,p,h,o,r,s))),Math.abs(x)>M&&(d.w||(w.w=fn(e-b-f+y,t+x/2-h/2,p,h,o,r,s)),d.e||(w.e=fn(n+b-y,t+x/2-h/2,p,h,o,r,s))),w},Yu=(e,t,n,i="mouse",o=Uu)=>{if(e.locked||j(e))return{};if(e.type==="freedraw"||K(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=Ca:s[0]>0&&s[1]<0?o=Wu:s[0]>0&&s[1]>0?o=Ca:s[0]<0&&s[1]>0?o=Wu:s[0]<0&&s[1]<0&&(o=Ca)}}else J(e)&&(o={...o,rotation:!0});let r=K(e)?Ga+8:ke(e)?0:Ga;return Oa(Z(e,n,!0),e.angle,t,i,o,r,ke(e)?0:void 0)},LD=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return j(i)?!1:K(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var Ra=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],Yx=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=Yu(e,r,t,s,ka(a));if(l&&Ra(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?Ra(m,i,o):!1});if(c.length>0)return c[0];if(Lr(a)){let[u,m,p,h,f,g]=Z(e,t);if(!(K(e)&&e.points.length<=2)){let E=ke(e)?0:Fa/r.value,x=Fa/r.value,b=ju(Pt(u-E,m-E),Pt(p+E,h+E),Pt(f,g),e.angle);for(let[y,w]of Object.entries(b))if(Xu(Pt(i,o),w,x))return y}}return!1},zD=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=Yx(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),_D=([e,t,n,i],o,r,s,a,l)=>{let d=Oa([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,ka(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&Ra(m,o,r)});if(c)return c;if(Lr(l)){let u=(e+n)/2,m=(t+i)/2,p=Fa/s.value,h=ju(Pt(e-p,t-p),Pt(n+p,i+p),Pt(u,m),0);for(let[f,g]of Object.entries(h))if(Xu(Pt(o,r),g,p))return f}return!1},Na=["ns","nesw","ew","nwse"],Xx=(e,t)=>{let n=Na.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=Na[(n+i)%Na.length]}return e},HD=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=Xx(o,t.angle)),o?`${o}-resize`:""},ju=([e,t],[n,i],o,r)=>{let s=Cr(Pt(e,t),o,r),a=Cr(Pt(n,t),o,r),l=Cr(Pt(e,i),o,r),d=Cr(Pt(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};I();var XD=(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")||Zt(t,e).length));I();import{pointFrom as Gr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as jx,DEFAULT_FONT_SIZE as $x,TEXT_ALIGN as Vx,VERTICAL_ALIGN as Zx,getSizeFromPoints as Kx,randomId as qx,arrayToMap as Qx,assertNever as za,cloneJSON as Vu,getFontString as Jx,isDevEnv as eb,toBrandedType as tb,getLineHeight as nb}from"@excalidraw/common";var kr={width:100,height:0},Un=100,ib=(e,t,n)=>{let i=si({x:0,y:0,textAlign:Vx.CENTER,verticalAlign:Zx.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),Uo(i,e,n),[e,i]},$u=(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??Un,u=t?.height??Un,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=si({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:za(e,`Unhandled element start type "${t.type}"`,!0)}Vt(e,r,"orbit","start",o)}}if(n){let c=n?.height??Un,u=n?.width??Un,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=si({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:za(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=Vu(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}},_a=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>$s(Array.from(this.excalidrawElements.values()));getElementsMap=()=>tb(Qx(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},rv=(e,t)=>{if(!e)return[];let n=Vu(e),i=new _a,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:qx()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||Un,p=l?.label?.text&&l.height===void 0?0:l?.height||Un;d=Ai({...l,width:m,height:p});break}case"line":{let m=l.width||kr.width,p=l.height||kr.height;d=Lc({width:m,height:p,points:[Gr(0,0),Gr(m,p)],...l});break}case"arrow":{let m=l.width||kr.width,p=l.height||kr.height;d=br({width:m,height:p,endArrowhead:"arrow",points:[Gr(0,0),Gr(m,p)],...l,type:"arrow"}),Object.assign(d,Kx(d.points));break}case"text":{let m=l?.fontFamily||jx,p=l?.fontSize||$x,h=l?.lineHeight||nb(m),f=l.text??"",g=Zi(f),E=ft(g,Jx({fontFamily:m,fontSize:p}),h);d=si({width:E.width,height:E.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=Cc({width:l?.width||Un,height:l?.height||Un,...l});break}case"frame":{d=Dc({x:0,y:0,...l});break}case"magicframe":{d=vc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,za(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]=ib(c,d?.label,a);if(i.add(u),i.add(m),X(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}=$u(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}=$u(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}),eb()&&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 cv=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return Nu(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 ob=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}},pv=e=>{let t=ob(e);return t===null?null:t};I();import{getBoundsFromPoints as Qu,getElementAbsoluteCoords as rb}from"@excalidraw/element/bounds";import{newArrowElement as Zu,newElement as sb,newLinearElement as Or}from"@excalidraw/element/newElement";import{ELEMENT_PENDING_DRAW_SHAPE_OPACITY as ab,getStrokeWidthByKey as Nr,ROUNDNESS as Ku}from"@excalidraw/common";import{convexHull as lb,distanceToLineSegment as db,elongation as cb,kurtosis as qu,lineSegment as ub,orientPrincipalAxes as mb,pointFrom as tt,polygonArea as pb,principalAxes as fb,principalCoords as hb,skewness as gb}from"@excalidraw/math";var Eb=64,xb=25,bb=.15,wb=.25,yb=.5,Pb=.15,Ib=.3,Sb=1.5,ki=3;function Mb(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 Ab(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=ub(t,n),r=0;for(let s of e)Math.hypot(s[0]-n[0],s[1]-n[1])<=yb*i||(r=Math.max(r,db(s,o)));return r/i}function Tb(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 Db(e){let t=Tb(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 vb(e){let t=Mb(e,Eb),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=mb(t,fb(t)),r=hb(t,o).map(([m])=>m),s=lb(t),[a,l,d,c]=Qu(t),u=(d-a)*(c-l);return{gapRatio:n>0?i/n:0,elongation:cb(o),majorSkew:gb(r),hullFillRatio:u>0?pb(s)/u:0,cornerTurnShare:Db(t),kurtosisProduct:qu(t.map(([m])=>m))*qu(t.map(([,m])=>m)),shaftDeviationRatio:Ab(t)}}var Bb=[{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}],Lb=.2,Cb=.2,Gb=.7;function kb(e){let t="freedraw",n=Sb;for(let i of Bb){let o=Math.hypot((e.hullFillRatio-i.hullFillRatio)/Lb,(e.cornerTurnShare-i.cornerTurnShare)/Cb,(e.kurtosisProduct-i.kurtosisProduct)/Gb);o<n&&(n=o,t=i.type)}return t}function Ob(e){return e.elongation>wb||e.shaftDeviationRatio>Pb?"freedraw":Math.abs(e.majorSkew)>=Ib?"arrow":"line"}function Nb(e){return e.gapRatio>bb?Ob(e):kb(e)}function Fb(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 Rb=(e,t,n=1)=>{typeof window<"u"&&(window.LAST_POINTS=e.map(([u,m])=>tt(u,m)));let i=Qu(e),[o,r,s,a]=i,l=Math.max(s-o,a-r);if(e.length<3||l*n<xb)return{type:"freedraw",points:e,boundingBox:i};let d=Nb(vb(e));return{type:t?.type==="arrow"&&d!=="arrow"?"freedraw":d,points:e,boundingBox:i}},zb=(e,t,n,i,o)=>{let r=Rb(e,i,t.zoom.value),s=r.boundingBox,[a,l,d,c]=s,m=(o??qs([...n.values()])).find(h=>{let[f,g,E,x]=rb(h,n);return f<=a&&g<=l&&E>=d&&x>=c})?.id??null,p=t.currentItemRoundness==="round"?{type:Oo(r.type)?Ku.ADAPTIVE_RADIUS:Ku.PROPORTIONAL_RADIUS}:null;switch(r.type){case"rectangle":case"diamond":case"ellipse":return sb({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:Nr(r.type,t.currentItemStrokeWidthKey)});case"arrow":{let[h,f]=r.points[0],[g,E]=Fb(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=Or({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:Nr(r.type,t.currentItemStrokeWidthKey)}),S=R.getNormalizeElementPointsAndCoords(M);return Or({...M,...S})}let y=Zu({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:Nr(r.type,t.currentItemStrokeWidthKey)}),w=R.getNormalizeElementPointsAndCoords(y);return Zu({...y,...w})}case"line":{let[h,f]=r.points[0],g=r.points[r.points.length-1],E=Or({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:Nr(r.type,t.currentItemStrokeWidthKey)}),x=R.getNormalizeElementPointsAndCoords(E);return Or({...E,...x})}}},_b=(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},Iv=(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=zb(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:ab,isDeleted:!1};_b(o,r)||e.setState({newElement:r})}else e.state.newElement!==null&&e.setState({newElement:null})}return!0}return!1};var Dv=e=>e.reduce((t,n)=>t+n.version,0),Kc=e=>{let t=5381;for(let n of Hb(e))t=(t<<5)+t+n.versionNonce;return t>>>0},qc=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,vv=e=>e.filter(t=>Ve(t)&&!Tc(t)),kn=e=>e.filter(Ve);export{Rn as AppStateDelta,Cf as BASE_ARROW_MIN_LENGTH,Md as BASE_BINDING_GAP,Qn as BASE_BINDING_GAP_ELBOW,ce as BASE_PADDING,vn as BindableElement,Dn as BoundElement,ut as CaptureUpdateAction,Wg as DEFAULT_BUCKET_FILL_OPTIONS,jI as DEFAULT_LINK_SIZE,Uu as DEFAULT_OMIT_SIDES,$ as Delta,Ea as DurableIncrement,aa as ElementBounds,zn as ElementsDelta,xa as EphemeralIncrement,no as FOCUS_POINT_SIZE,Pu as FlowChartCreator,yu as FlowChartNavigator,Be as HEADING_DOWN,Ne as HEADING_LEFT,he as HEADING_RIGHT,Ze as HEADING_UP,Eg as INVISIBLY_SMALL_ELEMENT_SIZE,Xs as InvalidFractionalIndexError,R as LinearElementEditor,ze as MINIMAL_CROP_SIZE,BD as OMIT_SIDES_FOR_FRAME,vD as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Ci as Scene,Et as ShapeCache,$c as Store,mo as StoreChange,ba as StoreDelta,Sr as StoreIncrement,_n as StoreSnapshot,lt as aabbForElement,Ph as addElementsToFrame,G1 as addToGroup,jS as alignElements,zf as avoidRectangularCorner,Vt as bindBindingElement,u1 as bindBindingElementToFixedPoint,nc as bindElementsToFramesAfterDuplication,Gf as bindOrUnbindBindingElement,a1 as bindOrUnbindBindingElements,ks as bindPointToSnapToElementOutline,Bd as bindingProperties,Qs as boundsContainBounds,xd as bumpVersion,Wf as calculateFixedPointForElbowArrowBinding,yi as calculateFixedPointForNonElbowArrowBinding,t0 as canApplyRoundnessTypeToElement,Bl as canBecomePolygon,$l as canChangeRoundness,nx as canCreateLinkFromElements,aP as canHaveArrowheads,Lr as canResizeFromSides,fi as charWidth,fe as compareHeading,Ki as computeBoundTextPosition,CM as computeBucketFillPolygon,ps as computeContainerDimensionForBoundText,B0 as containsCJK,rv as convertToExcalidrawElements,zb as convertToShape,Iv as convertToShapeHandlePointerMoveFromPointerDown,sT as createPlaceholderEmbeddableLabel,Ia as createSrcDoc,$y as cropElement,Pn as deconstructDiamondElement,No as deconstructLinearOrFreeDrawElement,yn as deconstructRectanguloidElement,ga as deepCopyElement,ZA as defaultGetElementLinkFromSelection,I0 as detectLineHeight,Ut as distanceToElement,CA as distributeElements,gt as doBoundsIntersect,YA as dragNewElement,tx as dragNewTextElement,WA as dragSelectedElements,uE as duplicateElement,VM as duplicateElements,C1 as editGroupForSelectedElement,re as elementCenterPoint,Ln as elementOverlapsWithFrame,oo as elementWithCanvasCache,Gn as elementsAreInFrameBounds,jd as elementsAreInSameGroup,Kd as elementsOverlappingBBox,lT as embeddableURLValidator,uh as excludeElementsInFramesFromSelection,MI as filterElementsEligibleAsFrameChildren,d1 as fixBindingsAfterDeletion,vd as fixDuplicatedBindingsAfterDuplication,Ss as flipHeading,LI as frameAndChildrenSelectedTogether,Fl as generateLinearCollisionShape,ct as generateRoughOptions,K1 as getActiveTextElement,Xo as getAllHoveredElementAtPoint,Wl as getApproxMinLineHeight,Hl as getApproxMinLineWidth,Ld as getArrowLocalFixedPoints,cg as getArrowheadAngle,pv as getArrowheadForPicker,et as getArrowheadPoints,dg as getArrowheadSize,ve as getBindingGap,c1 as getBindingSideMidPoint,zs as getBindingStrategyForDraggingBindingElementEndpoints,de as getBoundTextElement,Bt as getBoundTextElementId,U0 as getBoundTextElementPosition,qi as getBoundTextMaxHeight,vt as getBoundTextMaxWidth,oi as getBoundsFromPoints,an as getCenterForBounds,un as getCommonBoundingBox,Je as getCommonBounds,wh as getCommonFrameId,H0 as getContainerCenter,fs as getContainerCoords,Ue as getContainerElement,Cn as getContainingFrame,nn as getCornerRadius,jo as getCubicBezierCurveBound,HD as getCursorForResizingElement,Th as getDefaultFrameName,n0 as getDefaultRoundnessTypeForElement,Nl as getDiamondBaseCorners,pi as getDiamondPoints,UA as getDragOffsetXY,vS as getDraggedElementsBounds,Z as getElementAbsoluteCoords,ue as getElementBounds,Ii as getElementLineSegments,Ws as getElementPointsCoords,Ec as getElementShape,zD as getElementWithTransformHandleType,ic as getElementsCompletelyInFrame,Qe as getElementsInGroup,SI as getElementsInNewFrame,II as getElementsInResizingFrame,EI as getElementsIntersectingFrame,BI as getElementsOverlappingFrame,Zd as getElementsWithinSelection,rT as getEmbedLink,xM as getEndpointBoundTextDragAnchor,Vy as getFlipAdjustedCropPosition,Bn as getFrameChildren,yh as getFrameChildrenInsertionIndex,qs as getFrameLikeElements,vI as getFrameLikeTitle,ZI as getFreedrawOutlineAsSegments,eg as getFreedrawOutlinePoints,xc as getFreedrawStrokeCenterPoints,He as getGlobalFixedPointForBindableElement,Uf as getGlobalFixedPoints,Ed as getHeadingForElbowArrowSnap,sn as getHoveredElementForBinding,rd as getHoveredElementForFocusPoint,tD as getInitializedImageElements,_o as getLineHeightInPx,In as getLineWidth,i0 as getLinearElementSubType,KA as getLinkIdAndTypeFromSelection,Wd as getLockedLinearCursorAlignSize,gp as getMaxCharWidth,O1 as getMaximumGroups,M0 as getMinCharWidth,io as getMinMaxXYFromCurvePathOps,zo as getMinTextElementWidth,Vd as getNewGroupIdsForDuplication,kn as getNonDeletedElements,Xd as getNonDeletedGroupIds,zS as getNormalizedDimensions,Li as getObservedAppState,ka as getOmitSidesForEditorInterface,x0 as getOriginalContainerHeightFromCache,la as getPerfectElementSize,DS as getRectangleBoxAbsoluteCoords,Rh as getRenderOpacity,PD as getResizeArrowDirection,yD as getResizeOffsetXY,wn as getResizedElementAbsoluteCoords,PI as getRootElements,Dv as getSceneVersion,Zt as getSelectedElements,ar as getSelectedElementsByGroup,Ys as getSelectedGroupForElement,sh as getSelectedGroupIdForElement,oh as getSelectedGroupIds,Z1 as getSelectionStateForElements,dp as getSnapOutlineMidPoint,V1 as getTargetElements,Sh as getTargetFrame,da as getTextAnchorRatios,gM as getTextBindingForArrowEndpoint,W0 as getTextElementAngle,$0 as getTextFromElements,hp as getTextHeight,Ul as getTextWidth,_D as getTransformHandleTypeFromCoords,Yu as getTransformHandles,Oa as getTransformHandlesFromCoords,hM as getUnboundArrowEndpointAtPoint,Pl as getUncroppedImageElement,es as getUncroppedWidthAndHeight,j1 as getVisibleAndNonSelectedElements,vv as getVisibleElements,BS as getVisibleSceneBounds,Mp as getWrappedTextLines,yI as groupByFrameLikes,bI as groupsAreAtLeastIntersectingTheFrame,wI as groupsAreCompletelyOutOfFrame,qn as handleBindTextResize,Nu as handleFocusPointDrag,ZT as handleFocusPointHover,$T as handleFocusPointPointerDown,VT as handleFocusPointPointerUp,hi as hasBackground,_t as hasBoundTextElement,LD as hasBoundingBox,rP as hasFreedrawMode,nP as hasStrokeColor,oP as hasStrokeStyle,iP as hasStrokeWidth,Kc as hashElementsVersion,qc as hashString,st as headingForPoint,gi as headingForPointFromElement,Lt as headingForPointIsHorizontal,at as headingIsHorizontal,DP as headingIsVertical,Jp as hitElementBoundText,Qp as hitElementBoundingBox,PP as hitElementBoundingBoxOnly,Ht as hitElementItself,ot as intersectElementWithLineSegment,e0 as isArrowBoundToElement,X as isArrowElement,we as isBindableElement,Ps as isBindableElementInsideOtherBindable,_e as isBindingElement,Qm as isBindingElementType,$t as isBindingEnabled,Ie as isBoundToContainer,Uc as isBucketFillCompatible,xI as isCursorInFrame,Km as isCurvedArrow,j as isElbowArrow,RS as isElementCompletelyInViewport,Ks as isElementContainingFrame,rc as isElementInFrame,rh as isElementInGroup,qd as isElementInViewport,Si as isElementIntersectingFrame,qA as isElementLink,o0 as isEligibleFrameChildType,Sl as isEmbeddableElement,EM as isEndpointBoundText,Tl as isExcalidrawElement,Yf as isFixedPoint,Dl as isFlowchartNodeElement,Tr as isFocusPointVisible,ko as isFrameElement,J as isFrameLikeElement,be as isFreeDrawElement,Vm as isFreeDrawElementType,Cx as isHTMLSVGElement,Co as isIframeElement,Go as isIframeLikeElement,ke as isImageElement,$d as isInGroup,Vn as isInitializedImageElement,Tc as isInvisiblySmallElement,Oe as isLineElement,K as isLinearElement,qm as isLinearElementType,Ml as isMagicFrameElement,P0 as isMeasureTextSupported,PT as isNodeInFlowchart,Ve as isNonDeletedElement,Tt as isPathALoop,it as isPointInElement,ji as isRectangularElement,Al as isRectanguloidElement,GM as isRestylableFill,ih as isSelectedViaGroup,Zm as isSharpArrow,Jy as isSimpleArrow,$1 as isSomeElementSelected,Jm as isTextBindableContainer,oe as isTextElement,Oo as isUsingAdaptiveRadius,vl as isUsingProportionalRadius,ts as isValidPolygon,j0 as isValidTextContainer,Lx as loadHTMLImageElement,Us as makeNextSelectedElementIds,Dt as maxBindingDistance_simple,cv as maybeHandleArrowPointlikeDrag,aT as maybeParseEmbedSrc,La as measureFontSizeFromWidth,ft as measureText,NT as moveAllLeft,FT as moveAllRight,vu as moveArrowAboveBindable,kT as moveOneLeft,OT as moveOneRight,Fe as mutateElement,br as newArrowElement,Ai as newElement,Ke as newElementWith,nM as newEmbeddableElement,Dc as newFrameElement,rM as newFreeDrawElement,iM as newIframeElement,Cc as newImageElement,Lc as newLinearElement,vc as newMagicFrameElement,si as newTextElement,ob as normalizeArrowhead,rE as normalizeBoundElementsOrder,Yc as normalizeElementOrder,We as normalizeFixedPoint,nD as normalizeSVG,Zi as normalizeText,dr as omitGroupsContainingFrameLikes,bh as omitPartialGroups,Jd as orderByFractionalIndex,Vi as originalContainerCache,QA as parseElementLinkFromURL,Ip as parseTokens,Yt as pointInsideBounds,pg as pointInsideBoundsInclusive,aD as positionElementsOnGrid,as as projectFixedPointOntoDiagonal,Rb as recognizeShape,Uo as redrawTextBoundingBox,oM as refreshTextDimensions,Ih as removeAllElementsFromFrame,oc as removeElementsFromFrame,k1 as removeFromSelectedGroups,VI as renderElement,$I as renderSelectionElement,Rc as rendersOpaqueFill,AI as replaceAllElementsInFrame,zu as rescalePointsInElement,zl as resetOriginalContainerCache,Hx as resizeMultipleElements,Rx as resizeSingleElement,Ox as resizeSingleTextElement,Yx as resizeTest,nh as selectGroup,Ud as selectGroupsForSelectedElements,Yd as selectGroupsFromGivenElements,S0 as setCustomTextMetricsProvider,Y0 as shouldAllowVerticalAlign,DI as shouldApplyFrameClip,Yo as shouldTestInside,XD as showSelectedShapeActions,_s as snapToMid,X0 as suppportsHorizontalAlign,$s as syncInvalidIndices,ec as syncInvalidIndicesImmutable,ni as syncMovedIndices,Hd as toggleLinePolygonState,sP as toolIsArrow,wD as transformElements,Xe as unbindBindingElement,l1 as updateBindings,je as updateBoundElements,Ct as updateBoundPoint,xi as updateElbowArrowPoints,TI as updateFrameMembershipOfSelectedElements,eD as updateImageCache,Rl as updateOriginalContainerCache,gd as validateElbowPoints,hh as validateFractionalIndices,Xt as vectorToHeading,rn as wrapText};
|
|
28
|
+
`),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return Rt.set(e,m),m}return Rt.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},Wv=e=>{let t;$o(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=sy.Helvetica,o=ly({fontSize:n,fontFamily:i});return fi({x:e.x+e.width/2,y:e.y+e.height/2,strokeColor:e.strokeColor!=="transparent"?e.strokeColor:"black",backgroundColor:"transparent",fontFamily:i,fontSize:n,text:St(t,o,e.width-20),textAlign:"center",verticalAlign:ay.MIDDLE,angle:e.angle??0})},ol=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(il.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return il.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},Yv=e=>{let t=e.match(fy);if(t&&t.length===2)return t[1];let n=e.match(Ey);if(n&&n.length===2)return n[1];let i=e.match(my);if(i&&i.length===2)return i[1];if(Mm.test(e))return`https://giphy.com/embed/${Mm.exec(e)[1]}`;let o=e.match(gy);return o&&o.length===2?o[1]:e},Xv=(e,t)=>{if(!e)return!1;if(t!=null)if(typeof t=="function"){let n=t(e);if(typeof n=="boolean")return n}else{if(typeof t=="boolean")return t;if(t instanceof RegExp)return t.test(e);if(Array.isArray(t)){for(let n of t)if(n instanceof RegExp){if(e.match(n))return!0}else if(ol(e,n))return!0;return!1}}return!!ol(e,il)};M();import{invariant as rl,toBrandedType as by}from"@excalidraw/common";import{clamp as yy,pointFrom as vm}from"@excalidraw/math";var Lm=100,Bm=100,wy=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},Nm=(e,t,n)=>n.every(i=>e+t<=i.start||e>=i.end),Py=(e,t,n)=>{if(Nm(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=yy(e,i[a],o[a]-t),d=Math.abs(l-e);d<=s&&(r=l,s=d)}return r},Sy=(e,t)=>{let n=[...t.values()].filter(X),i=new Set([e.id]),o=[e.id],r=[];for(;o.length>0;){let s=o.shift();for(let a of n){let l=a.startBinding?.elementId,d=a.endBinding?.elementId,c;if(l===s?c=d:d===s&&(c=l),!c||i.has(c))continue;i.add(c);let u=t.get(c);u&&Pe(u)&&(r.push(u),o.push(c))}}return r},Iy=(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?Bm:Lm,d=r?Lm:Bm,c=r?e.x:e.y,u=r?e.y+e.height/2:e.x+e.width/2,p=t==="right"||t==="down"?c+s+l:c-l-s,m=wy(i.filter(b=>{let y=r?b[0]:b[1],w=r?b[2]:b[3];return y<p+s&&w>p}).map(b=>({start:(r?b[1]:b[0])-d,end:(r?b[3]:b[2])+d}))),h=a+d,f=n*a+(n-1)*d,E=(o===null?null:[o,o-h].filter(b=>Nm(b,f,m)).sort((b,y)=>Math.abs(b+f/2-u)-Math.abs(y+f/2-u))[0]??null)??Py(u-f/2,f,m);return{positions:Array.from({length:n},(b,y)=>{let w=E+y*h;return r?{x:p,y:w}:{x:w,y:p}}),crossStart:E}},My=(e,t,n)=>{let i={x:t,y:n,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle},o=e.type==="stickynote"?Lr({type:"stickynote",...i,baseHeight:e.baseHeight}):Oi({type:e.type,...i});return rl(ld(o),"not an ExcalidrawFlowchartNodeElement"),o},Ty=(e,t,n,i,o,r=null)=>{let s=i.getNonDeletedElementsMap(),a=Sy(e,s).map(u=>ut(u,s)),{positions:l,crossStart:d}=Iy(e,n,o,a,r),c=[];for(let u of l){let p=My(e,u.x,u.y),m=Ay(e,p,n,t,i);c.push(p,m)}return{nodes:c,crossStart:d}},Ay=(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=Br({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:[vm(0,0),vm(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();jt(c,e,"orbit","start",o,i.zoom),jt(c,t,"orbit","end",o,i.zoom);let p=new Map;p.set(e.id,e),p.set(t.id,t),p.set(c.id,c),R.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let m=Ii(c,by(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...m,isDeleted:c.isDeleted}},km=class e{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!Pe(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...e.getSuccessors(t,n,i),...e.getPredecessors(t,n,i)];if(o.length>0)return this.sameLevelIndex=0,this.isExploring=!0,this.sameLevelNodes=o,this.direction=i,this.visitedNodes.add(o[0].id),o[0].id;if(i===this.direction||!this.isExploring){this.isExploring||this.visitedNodes.add(t.id);let s=["up","right","down","left"].filter(a=>a!==i).map(a=>[...e.getSuccessors(t,n,a),...e.getPredecessors(t,n,a)]).flat().filter(a=>!this.visitedNodes.has(a.id));for(let a of s)if(!this.visitedNodes.has(a.id))return this.visitedNodes.add(a.id),this.isExploring=!0,this.direction=i,a.id}return null}static getNodeRelatives(t,n,i,o){let r=[...i.values()].reduce((s,a)=>{let l;if(X(a)&&(l=a[t==="predecessors"?"startBinding":"endBinding"])&&a[t==="predecessors"?"endBinding":"startBinding"]?.elementId===n.id){let d=i.get(l.elementId);if(!d)return s;rl(Pe(d),"not an ExcalidrawBindableElement");let c=t==="predecessors"?a.points[a.points.length-1]:[0,0],u=Pi(n,ut(n,i),[c[0]+a.x,c[1]+a.y]);s.push({relative:d,heading:u})}return s},[]);switch(o){case"up":return r.filter(s=>he(s.heading,qe)).map(s=>s.relative);case"down":return r.filter(s=>he(s.heading,ve)).map(s=>s.relative);case"right":return r.filter(s=>he(s.heading,Ee)).map(s=>s.relative);case"left":return r.filter(s=>he(s.heading,ze)).map(s=>s.relative)}}static getSuccessors(t,n,i){return e.getNodeRelatives("successors",t,n,i)}static getPredecessors(t,n,i){return e.getNodeRelatives("predecessors",t,n,i)}},Cm=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}=Ty(t,n,i,o,this.numberOfNodes,this.clusterCrossStart);if(this.isCreatingChart=!0,this.direction=i,this.clusterCrossStart=a,this.pendingNodes=s,t.frameId){let l=r.get(t.frameId);rl(l&&Vo(l),"not an ExcalidrawFrameElement"),l&&this.pendingNodes.every(d=>Un([d],l,r)||_n(d,l,r))&&(this.pendingNodes=this.pendingNodes.map(d=>He(d,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0,this.clusterCrossStart=null}},rL=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};M();import{pointDistance as Ui,pointFrom as al}from"@excalidraw/math";import{invariant as $m}from"@excalidraw/common";M();import{arrayToMap as Gm,findIndex as Fm,findLastIndex as Rm}from"@excalidraw/common";import{isFiniteNumber as Dy}from"@excalidraw/math";var sl=(e,t)=>e.frameId===t||e.id===t,zm=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Gm(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},vy=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),[])},Om=(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))}}},Ly=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{sl(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},_m=(e,t,n,i,o,r)=>{if(!r)return n;let s=q(r,i),a=j(r)?Be(r,i):null,l=[r.id,s?.id,a?.id].filter(u=>!!u),d=n.findIndex(u=>l.includes(u.id)),c=n.findIndex(u=>u.id===t.id);if(c!==-1&&d!==-1&&c<d){let u=Array.from(n),p=u.splice(c,1)[0];u.splice(d,0,p),o.replaceAllElements(u)}return n},By=(e,t,n,i,o,r)=>{let s=t[n],a=p=>p.isDeleted?!1:o?p.frameId===o:e.editingGroupId?p.groupIds.includes(e.editingGroupId):!0,l=i==="left"?Rm(t,p=>a(p),Math.max(0,n-1)):Fm(t,p=>a(p),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Om(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||J(d))){let p=Ly(t,d.frameId||d.id);return i==="left"?t.indexOf(p[0]):t.indexOf(p[p.length-1])}if(!d.groupIds.length)return Om(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=it(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},Hm=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Um=(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},Wm=(e,t,n,i)=>{let o=e,r=zm(e,t),s=Hm(e,r),a=vy(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],p=d[d.length-1],m=n==="left"?u:p,h=d.some(y=>{let w=e[y];return w.frameId&&l.has(w.frameId)})?null:e[m]?.frameId,f=By(t,e,m,n,h,i);if(f===-1||m===f)return;let g=n==="left"?e.slice(0,f):e.slice(0,u),E=e.slice(u,p+1),x=n==="left"?e.slice(f,u):e.slice(p+1,f+1),b=n==="left"?e.slice(p+1):e.slice(f+1);e=n==="left"?[...g,...E,...x,...b]:[...g,...x,...E,...b]}),Um(o,e)?(di(e,s),e):o},Ym=(e,t,n,i,o)=>{let r=zm(e,t,o);if(r.length===0)return e;let s=Hm(e,r),a=[],l,d;if(n==="left"){if(i)l=Fm(e,f=>sl(f,i));else if(t.editingGroupId){let f=it(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;d=r[r.length-1]}else{if(i)d=Rm(e,f=>sl(f,i));else if(t.editingGroupId){let f=it(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);let c=f=>Dy(f)&&f>=0;if(!c(l)||!c(d)||l>d||r.some(f=>f<l||f>d))return e;for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let u=Array.from(s.values()),p=e.slice(0,l),m=e.slice(d+1),h=n==="left"?[...p,...u,...a,...m]:[...p,...a,...u,...m];return Um(e,h)?(di(h,s),h):e};function Xm(e,t,n,i){let o=Gm(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 hL=(e,t,n)=>Wm(e,t,"left",n),gL=(e,t,n)=>Wm(e,t,"right",n),EL=(e,t)=>Xm(e,t,"left",Ym),xL=(e,t)=>Xm(e,t,"right",Ym);var zr=(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(Ui(e,d)<fo*1.5/o.zoom.value)return!1}let a=R.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return Ui(e,a)>=fo*1.5/o.zoom.value&&Ot({element:n,elementsMap:i,point:e,threshold:Le(n),overrideShouldTestInside:!0})},ky=(e,t,n,i,o,r,s)=>{let a=new Map,l=r.selectedLinearElement?.initialState.arrowOtherEndpointInitialBinding,d=n?"startBinding":"endBinding",c=n?"endBinding":"startBinding",u=e[d],p=l?.mode==="orbit"&&e[c]?.mode==="inside"?l:e[c];if(u&&t){let m=t&&p&&u.elementId===p.elementId;s||m?u={...u,mode:"inside"}:u={...u,mode:"orbit"};let h=n?0:e.points.length-1,f=Gt(e,d,u,t,i,!0);f&&a.set(h,{point:f})}if(p&&p.mode==="orbit"){let m=i.get(p.elementId);if(m&&Pe(m)&&$t(r)){t&&p.elementId===t.id?p={...p,mode:"inside"}:p={...p,mode:"orbit"};let f=n?e.points.length-1:0,g=Gt(e,c,p,m,i);g&&a.set(f,{point:g})}}a.size>0&&R.movePoints(e,o,a,{[d]:u,[c]:p})},jm=(e,t,n,i,o,r,s)=>{let a=R.getElement(e.elementId,t);if(!a||!Xe(a)||X(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,p=al(n.x-c,n.y-u),m=l?"startBinding":"endBinding",h=rn(p,i.getNonDeletedElements(),t,o.zoom);if(h&&$t(o)){a[m]&&h.id!==d?.elementId&&Ke(a,e.draggedFocusPointBinding,i);let f=s&&a[m]?.mode==="orbit"?"inside":!s&&a[m]?.mode==="inside"?"orbit":null;(!a[m]||f)&&jt(a,h,f||"orbit",e.draggedFocusPointBinding,i,o.zoom,p),i.mutateElement(a,{[m]:{...a[m],elementId:h.id,mode:f||a[m]?.mode||"orbit",...si(a,h,e.draggedFocusPointBinding,t,p)}})}else{let f=new Map,g=l?0:a.points.length-1;f.set(g,{point:R.createPointAt(a,t,p[0],p[1],r)}),R.movePoints(a,i,f),a[m]&&Ke(a,l?"start":"end",i)}ky(a,h,l,t,i,o,s),h&&$t(o)&&_m(p,a,i.getElementsIncludingDeleted(),t,i,h)},DL=(e,t,n,i)=>{let o=al(t.origin.x,t.origin.y),r=fo*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&Pe(s)&&!s.isDeleted){let a=_e(e.startBinding.fixedPoint,s,n);if(zr(a,e,s,n,i,"start")&&Ui(o,a)<=r)return{hitFocusPoint:"start",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]},arrowOtherEndpointInitialBinding:e.endBinding}}}if(e.endBinding?.elementId){let s=n.get(e.endBinding.elementId);if(s&&Pe(s)&&!s.isDeleted){let a=_e(e.endBinding.fixedPoint,s,n);if(zr(a,e,s,n,i,"end")&&Ui(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}},vL=(e,t)=>{$m(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=R.getElement(e.elementId,t.getNonDeletedElementsMap());$m(n,"Arrow must be in the scene");let i=e.draggedFocusPointBinding==="start"?"startBinding":"endBinding",o=e.draggedFocusPointBinding==="start"?"endBinding":"startBinding",r=n[i]?.elementId,s=n[o]?.elementId,a=r&&t.getNonDeletedElements().find(d=>d.id!==r&&d.id!==s&&Pe(d)&&d.boundElements?.find(({id:c})=>c===n.id));a&&t.mutateElement(a,{boundElements:a.boundElements?.filter(({id:d})=>d!==n.id)});let l=r&&t.getNonDeletedElementsMap().get(r);return l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]}),{arrowOtherEndpointInitialBinding:null}},LL=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=al(t,n),a=fo*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&Pe(l)&&!l.isDeleted){let d=_e(e.startBinding.fixedPoint,l,r);if(zr(d,e,l,r,o,"start")&&Ui(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&Pe(l)&&!l.isDeleted){let d=_e(e.endBinding.fixedPoint,l,r);if(zr(d,e,l,r,o,"end")&&Ui(s,d)<=a)return"end"}}return null};M();import{MIME_TYPES as Vm,SVG_NS as Cy}from"@excalidraw/common";var Ny=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),OL=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===Vm.binary)throw new Error("Only images can be added to ImageCache");let l=Ny(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}},GL=e=>e.filter(t=>ei(t)),Oy=e=>e?.nodeName.toLowerCase()==="svg",FL=e=>{let t=new DOMParser().parseFromString(e,Vm.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Oy(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Cy);let o=n.getAttribute("width"),r=n.getAttribute("height");(o?.includes("%")||o==="auto")&&(o=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!o||!r){if(o=o||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,o,r]=a)}n.setAttribute("width",o),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${o} ${r}`),n.outerHTML}};M();import{arrayToMap as Gy}from"@excalidraw/common";var Fy=/^(\s*)(?:\((\d{1,9}|[a-zA-Z]+)\)|\[(\d{1,9})\]|(\d{1,9}|[a-zA-Z]+)([.)]))(?=\s|$)/,Ry=/^(\s*)(\d{1,9})\s*$/,zy=8,ll={decimal:42,alpha:9,roman:99},qm=e=>["","x","xx","xxx","xl","l","lx","lxx","lxxx","xc"][Math.floor(e/10)]+["","i","ii","iii","iv","v","vi","vii","viii","ix"][e%10],Km=new Map(Array.from({length:ll.roman},(e,t)=>[qm(t+1),t+1])),_y=e=>{let t=e.match(Ry);if(!t)return null;let[,n,i]=t;return{index:n.length,value:i,kind:"decimal",isUpperCase:!1,style:"decimal",ordinal:parseInt(i,10),contentIndex:e.length}},Zm=e=>{let t=e.match(Fy);if(!t)return null;let[,n,i,o,r,s]=t,a=i??o??r,l=a.toLowerCase(),d=/[A-Z]/.test(a),c=l.charCodeAt(0)-97+1,u,p;if(/\d/.test(a))u="decimal",p=parseInt(a,10);else{if(d&&/[a-z]/.test(a))return null;if(a.length===1&&c<=zy)u="alpha",p=c;else if(Km.has(l))u="roman",p=Km.get(l);else return null}let m=i!==void 0?"()":o!==void 0?"[]":s;return{index:n.length+(r!==void 0?0:1),value:a,kind:u,isUpperCase:d,style:`${u}${d?"-upper":""}${m}`,ordinal:p,contentIndex:t[0].length+e.slice(t[0].length).match(/^\s*/)[0].length}},Hy=e=>{let t=_y(e)??Zm(e);return!t||t.ordinal>ll[t.kind]||e.slice(t.index).split(`
|
|
29
|
+
`).slice(1).some(i=>Zm(i)?.style===t.style)?null:t},Uy=(e,t,n)=>{if(n>ll[t.kind])return null;let i;return t.kind==="decimal"?i=String(n).padStart(t.value.startsWith("0")?t.value.length:0,"0"):t.kind==="alpha"?i=String.fromCharCode(97+n-1):i=qm(n),t.isUpperCase&&(i=i.toUpperCase()),e.slice(0,t.index)+i+e.slice(t.index+t.value.length)},Qm=(e,t,n,i)=>{t?(i.mutateElement(e,{originalText:n}),Ti(e,t,i)):i.mutateElement(e,{originalText:n,..._u(e,null,i.getNonDeletedElementsMap(),n)})},YL=(e,t)=>{let n=Gy(e),i=t.getNonDeletedElementsMap(),o=new Map;for(let a of e){if(pe(a)&&n.has(a.containerId))continue;let l=j(a)?a:q(a,i),d=l&&Hy(l.originalText);if(!l||!d)return[];let c=o.get(d.style)??[];c.push({element:l,container:l===a?null:a,marker:d}),o.set(d.style,c)}let r=[...o.values()].flat();if(r.length>1&&r.some(({element:a,marker:l})=>l.contentIndex<a.originalText.length))return[];let s=[];for(let a of o.values()){let l=Math.max(...a.map(d=>d.marker.ordinal));a.sort((d,c)=>d.marker.ordinal-c.marker.ordinal);for(let[d,{element:c,container:u,marker:p}]of a.entries()){let m=Uy(c.originalText,p,l+1+d);m!==null&&(s.push({elementId:c.id,prevOriginalText:c.originalText,nextOriginalText:m,contentStart:p.contentIndex+m.length-c.originalText.length,prevContainerSize:u?{width:u.width,height:u.height}:null}),Qm(c,u,m,t))}}return s},XL=(e,t,n)=>{let i=n.getNonDeletedElementsMap();for(let o of e){let r=i.get(o.elementId);if(!r||!j(r))continue;let s=Be(r,i);t==="prev"&&s&&o.prevContainerSize&&n.mutateElement(s,o.prevContainerSize),Qm(r,s,t==="prev"?o.prevOriginalText:o.nextOriginalText,n)}};M();var ZL=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(m=>[m]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let m=0;m<s;m+=a)l.push(r.slice(m,m+a));let d=0,c=l.map(m=>{let h=0,f=0,g=m.map(E=>{let[x,b,y,w]=ot(E);return{elements:E,bounds:[x,b,y,w],width:y-x,height:w-b}});return g.forEach((E,x)=>{h+=E.width,x<g.length-1&&(h+=i),E.height>f&&(f=E.height)}),d+=f,{unitBounds:g,width:h,maxHeight:f}}),u=d+Math.max(0,l.length-1)*i,p=n-u/2;return c.forEach(m=>{let{unitBounds:h,width:f,maxHeight:g}=m,E=t-f/2;h.forEach(x=>{let[b,y]=x.bounds,w=E-b,S=p-y;x.elements.forEach(I=>{o.push(Me(I,{x:I.x+w,y:I.y+S}))}),E+=x.width+i}),p+=g+i}),o};M();import{pointCenter as Wy,normalizeRadians as Hr,pointFrom as me,pointRotateRads as zt}from"@excalidraw/math";import{MIN_FONT_SIZE as cl,SHIFT_LOCKING_ANGLE as Ur,STICKY_NOTE_MIN_SIZE as Jm,rescalePoints as ep,getFontString as _r}from"@excalidraw/common";var cB=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[p]=n;if(t==="rotation")X(p)||(Yy(p,i,a,l,o),Ge(p,i));else if(t){let m=n[0].id,h=u.get(m),f=e.get(m);if(h&&f){let{nextWidth:g,nextHeight:E}=Ky(h,f,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});Vy(g,E,h,f,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return j(p)&&Ge(p,i),!0}else if(n.length>1){if(t==="rotation")return $y(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:p,nextHeight:m,flipByX:h,flipByY:f,originalBoundingBox:g}=Zy(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return qy(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:h,flipByY:f,nextWidth:p,nextHeight:m,originalBoundingBox:g}),!0}}return!1},Yy=(e,t,n,i,o)=>{let[r,s,a,l]=Q(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+Ur/2,u=u-u%Ur),u=Hr(u));let p=Ct(e),m={angle:u};if(Xe(e)&&(m={...m},e.startBinding&&Ke(e,"start",t),e.endBinding&&Ke(e,"end",t)),t.mutateElement(e,m),p){let h=t.getElement(p);if(h&&!W(e)){let{x:f,y:g}=ii(e,h,t.getNonDeletedElementsMap());t.mutateElement(h,{angle:u,x:f,y:g})}}},tp=(e,t,n,i)=>ee(e)||ge(e)?{points:ep(0,t,ep(1,n,e.points,i),i)}:{},ul=(e,t,n)=>{let i=e.width;if(pe(e)){let s=Be(e,t);s&&(i=kt(s,e))}let r=e.fontSize*(n/i);return r<cl?null:{size:r}},Xy=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=ul(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=me(e.x,e.y),u=dl(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=ar(_r({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),p=St(t.originalText,_r(t),Math.abs(u)),m=Ue(p,_r(t),t.lineHeight),h=m.height,f=me(e.x,e.y),g=dl(f,e.width,e.height,u,h,t.angle,i,!1,o),E={width:Math.abs(u),height:Math.abs(m.height),x:g.x,y:g.y,text:p,autoResize:!1};n.mutateElement(t,E)}}},$y=(e,t,n,i,o,r,s,a)=>{let l=n.getNonDeletedElementsMap(),d=5*Math.PI/2+Math.atan2(o-a,i-s);r&&(d+=Ur/2,d-=d%Ur);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!J(u)){let[p,m,h,f]=Q(u,l),g=(p+h)/2,E=(m+f)/2,x=e.get(u.id)?.angle??u.angle,[b,y]=zt(me(g,E),me(s,a),d+x-u.angle),w=X(u)?{points:Sc(u,l)}:{x:u.x+(b-g),y:u.y+(y-E),angle:Hr(d+x)};n.mutateElement(u,w),Ge(u,n,{simultaneouslyUpdated:t}),Xe(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||Ke(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||Ke(u,"end",n)));let S=q(u,l);if(S&&!W(u)){let{x:I,y:A}=ii(u,S,l);n.mutateElement(S,{x:I,y:A,angle:Hr(d+x)})}}n.triggerUpdate()},uB=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?Q(t[0],n):ot(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=zt(me(i,o),me(d,c),-u),e){case"n":return zt(me(i-(r+a)/2,o-s),me(0,0),u);case"s":return zt(me(i-(r+a)/2,o-l),me(0,0),u);case"w":return zt(me(i-r,o-(s+l)/2),me(0,0),u);case"e":return zt(me(i-a,o-(s+l)/2),me(0,0),u);case"nw":return zt(me(i-r,o-s),me(0,0),u);case"ne":return zt(me(i-a,o-s),me(0,0),u);case"sw":return zt(me(i-r,o-l),me(0,0),u);case"se":return zt(me(i-a,o-l),me(0,0),u);default:return[0,0]}},mB=(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"},jy=(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"},dl=(e,t,n,i,o,r,s,a,l)=>{let d=jy(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)}}},Vy=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(j(n)&&j(i))return Xy(i,n,r,s,d,e,t);let c=e<0?-1:1,u=t<0?-1:1;e=Math.abs(e),t=Math.abs(t);let p=r.getNonDeletedElementsMap(),m=q(n,p),h=ye(n),f;if(h?f=m?Fd({fontSize:m.baseFontSize??m.fontSize,fontFamily:m.fontFamily}):{width:Jm,height:Jm}:m&&!l&&(f={width:Id(_r(m),m.lineHeight),height:Md(m.fontSize,m.lineHeight)}),f&&(e=Math.max(e,f.width),t=Math.max(t,f.height),l)){let y=Math.max(e/i.width,t/i.height);e=i.width*y,t=i.height*y}let g={};if(m&&!h){let y=o.get(m.id);if(y&&(g={fontSize:y.fontSize}),l){let w={...n,width:e,height:t},S=ul(m,p,kt(w,m));if(S===null)return;g={fontSize:S.size}}}e*=c,t*=u;let E=tp(i,e,t,!0),x=me(i.x,i.y);if(ee(i)){let[y,w]=ae(i,o);x=me(y,w)}let b=dl(x,i.width,i.height,e,t,i.angle,s,l,d);if(ee(i)&&E.points){let y=i.x-x[0],w=i.y-x[1];b.x+=y,b.y+=w;let S=E.points[0][0],I=E.points[0][1];b.x+=S,b.y+=I,E.points=E.points.map(A=>me(A[0]-S,A[1]-I))}if(e<0&&(b.x=b.x+e),t<0&&(b.y=b.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),W(n)&&m&&l){let y=Math.abs(e)/n.width*m.fontSize;if(y<cl)return;g.fontSize=y}if(e!==0&&t!==0&&Number.isFinite(b.x)&&Number.isFinite(b.y)){let y={...b,width:Math.abs(e),height:Math.abs(t),...E};Xe(n)&&(n.startBinding&&(y={...y},n.startBinding&&Ke(n,"start",r)),n.endBinding&&(y={...y,endBinding:null})),r.mutateElement(n,y,{informMutation:a,isDragging:!1}),ye(n)?Ai(n,r,{...js(n,o,s,{proportional:l,fromCenter:d}),bindings:!1}):(m&&g!=null&&r.mutateElement(m,{fontSize:g.fontSize}),ni(n,r,s,l,d,u<0)),Ge(n,r)}},Ky=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=In(t,t.width,t.height,!0),u=me(a,l),p=me(d,c),m=Wy(u,p),h=zt(me(i,o),m,-t.angle),[f,g,E,x]=In(e,e.width,e.height,!0),b=E-f,y=x-g,w=p[0]-u[0],S=p[1]-u[1],I=w/b,A=S/y;n.includes("e")&&(I=(h[0]-u[0])/b),n.includes("s")&&(A=(h[1]-u[1])/y),n.includes("w")&&(I=(p[0]-h[0])/b),n.includes("n")&&(A=(p[1]-h[1])/y);let T=e.width*I,O=e.height*A;if(s&&(T=2*T-t.width,O=2*O-t.height),r){let v=Math.abs(T)/t.width,N=Math.abs(O)/t.height;if(n.length===1&&(O*=v,T*=N),n.length===2){let C=Math.max(v,N);T=t.width*C*Math.sign(T),O=t.height*C*Math.sign(O)}}return{nextWidth:T,nextHeight:O}},Zy=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(C=>t.get(C.id)),d=l.reduce((C,z)=>{if(!ee(z))return C;let U=Ct(z);if(!U)return C;let D=t.get(U)??null;return pe(D)?[...C,{...D,...R.getBoundTextElementPosition(z,D,n)}]:C},[]),c=pn(l.map(C=>C).concat(d)),{minX:u,minY:p,maxX:m,maxY:h,midX:f,midY:g}=c,E=m-u,x=h-p,b={ne:[u,h],se:[u,p],sw:[m,p],nw:[m,h],e:[u,p+x/2],w:[m,p+x/2],n:[u+E/2,h],s:[u+E/2,p]},[y,w]=a?[f,g]:b[i],S=a?2:1,I=Math.max(Math.abs(o-y)/E||0,Math.abs(r-w)/x||0)*S,A=i.includes("e")||i.includes("w")?Math.abs(o-y)*S:E,T=i.includes("n")||i.includes("s")?Math.abs(r-w)*S:x;s&&(A=E*I*Math.sign(o-y),T=x*I*Math.sign(r-w));let O={ne:[o<y,r>w],se:[o<y,r<w],sw:[o>y,r<w],nw:[o>y,r>w],e:[o<y,!1],w:[o>y,!1],n:[!1,r>w],s:[!1,r<w]},[v,N]=O[i].map(C=>C);return{originalBoundingBox:c,nextWidth:A,nextHeight:T,flipByX:v,flipByY:N}},qy=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:d,nextWidth:c,originalBoundingBox:u}={})=>{if(c===void 0&&d===void 0&&a===void 0&&l===void 0||d===0||c===0)return;o||(o=t);let p=e.reduce((S,I)=>{let A=o.get(I.id);return A&&S.push({orig:A,latest:I}),S},[]),m;if(u)m=u;else{let S=p.reduce((I,{orig:A})=>{if(!ee(A))return I;let T=Ct(A);if(!T)return I;let O=o.get(T)??null;return pe(O)?[...I,{...O,...R.getBoundTextElementPosition(A,O,t)}]:I},[]);m=pn([...p.map(({orig:I})=>I),...S])}let{minX:h,minY:f,maxX:g,maxY:E,midX:x,midY:b}=m,y=g-h,w=E-f;if(c===void 0&&d===void 0&&(c=y,d=w),r&&(c===void 0?c=d*(y/w):d===void 0?d=c*(w/y):Math.abs(c/d-y/w)>.001&&(c=d*(y/w))),c&&d){let S=n.includes("e")||n.includes("w")?Math.abs(c)/y:1,I=n.includes("n")||n.includes("s")?Math.abs(d)/w:1,A;n.length===1?A=n.includes("e")||n.includes("w")?S:I:A=Math.max(Math.abs(c)/y||0,Math.abs(d)/w||0);let T={ne:[h,E],se:[h,f],sw:[g,f],nw:[g,E],e:[h,f+w/2],w:[g,f+w/2],n:[h+y/2,E],s:[h+y/2,f]},[O,v]=s?[x,b]:T[n],N=r||p.some(P=>P.latest.angle!==0||j(P.latest)||Wc(P.latest));N&&(S=A,I=A);let[C,z]=[a?-1:1,l?-1:1],U=[];for(let{orig:P,latest:B}of p){if(j(P)&&pe(P))continue;let k=P.width*S,_=P.height*I,K=Hr(P.angle*C*z),te=ee(P)||ge(P),ne=P.x-O,ie=P.y-v,Ae=a&&!te?k:0,_t=l&&!te?_:0,Ht=O+C*(ne*S+Ae),bn=v+z*(ie*I+_t),fe=tp(P,k*C,_*z,!1),oe={x:Ht,y:bn,width:k,height:_,angle:K,...fe};if(X(P)&&(P.startBinding&&(oe.startBinding={...P.startBinding,fixedPoint:[a?-P.startBinding.fixedPoint[0]+1:P.startBinding.fixedPoint[0],l?-P.startBinding.fixedPoint[1]+1:P.startBinding.fixedPoint[1]]}),P.endBinding&&(oe.endBinding={...P.endBinding,fixedPoint:[a?-P.endBinding.fixedPoint[0]+1:P.endBinding.fixedPoint[0],l?-P.endBinding.fixedPoint[1]+1:P.endBinding.fixedPoint[1]]}),P.fixedSegments&&fe.points&&(oe.fixedSegments=P.fixedSegments.map(De=>({...De,start:fe.points[De.index-1],end:fe.points[De.index]})))),Oe(P)&&(oe.scale=[P.scale[0]*C,P.scale[1]*z]),j(P)){let De=ul(P,t,k);if(!De)return;oe.fontSize=De.size}let Ne=o.get(Ct(P)??"");if(Ne&&!ye(P))if(N){let De=Ne.fontSize*A;if(De<cl)return;oe.boundTextFontSize=De}else oe.boundTextFontSize=Ne.fontSize;U.push({element:B,update:oe})}let D=U.map(({element:P})=>P),L=new Map(U.map(({element:P})=>[P.id,P]));for(let{element:P,update:{boundTextFontSize:B,...k}}of U){let{angle:_}=k;i.mutateElement(P,k),ye(P)?Ai(P,i,{...js(P,o,n,{proportional:N,fromCenter:s,flip:a||l}),bindings:{simultaneouslyUpdated:D}}):Ge(P,i,{simultaneouslyUpdated:D}),Xe(P)&&(P.startBinding&&(L.has(P.startBinding.elementId)||Ke(P,"start",i)),P.endBinding&&(L.has(P.endBinding.elementId)||Ke(P,"end",i)));let K=q(P,t);K&&B&&!ye(P)&&(i.mutateElement(K,{fontSize:B,angle:ee(P)?void 0:_}),ni(P,i,n,!0,s,l))}i.triggerUpdate()}};M();import{pointFrom as Tt,pointOnLineSegment as ap,pointRotateRads as Yr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as El}from"@excalidraw/common";M();import{DEFAULT_TRANSFORM_HANDLE_SPACING as pl}from"@excalidraw/common";import{pointFrom as np,pointRotateRads as Qy}from"@excalidraw/math";var ip={mouse:8,pen:16,touch:28},Jy=16,rp={e:!0,s:!0,n:!0,w:!0},bB={e:!0,s:!0,n:!0,w:!0},yB={e:!0,s:!0,n:!0,w:!0,rotation:!0},op={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},ml={e:!0,s:!0,n:!0,w:!0},xn=(e,t,n,i,o,r,s)=>{let[a,l]=Qy(np(e+n/2,t+i/2),np(o,r),s);return[a-n/2,l-i/2,n,i]},Wr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),fl=e=>Wr(e)?rp:{},hl=([e,t,n,i,o,r],s,a,l,d={},c=4,u=pl)=>{let p=ip[l],m=p/a.value,h=p/a.value,f=p/a.value,g=p/a.value,E=n-e,x=i-t,b=c/a.value,y=(p-u*2)/(2*a.value),w={nw:d.nw?void 0:xn(e-b-f+y,t-b-g+y,m,h,o,r,s),ne:d.ne?void 0:xn(n+b-y,t-b-g+y,m,h,o,r,s),sw:d.sw?void 0:xn(e-b-f+y,i+b-y,m,h,o,r,s),se:d.se?void 0:xn(n+b-y,i+b-y,m,h,o,r,s),rotation:d.rotation?void 0:xn(e+E/2-m/2,t-b-g+y-Jy/a.value,m,h,o,r,s)},S=5*ip.mouse/a.value;return Math.abs(E)>S&&(d.n||(w.n=xn(e+E/2-m/2,t-b-g+y,m,h,o,r,s)),d.s||(w.s=xn(e+E/2-m/2,i+b-y,m,h,o,r,s))),Math.abs(x)>S&&(d.w||(w.w=xn(e-b-f+y,t+x/2-h/2,m,h,o,r,s)),d.e||(w.e=xn(n+b-y,t+x/2-h/2,m,h,o,r,s))),w},sp=(e,t,n,i="mouse",o=rp)=>{if(e.locked||X(e))return{};if(e.type==="freedraw"||ee(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=ml:s[0]>0&&s[1]<0?o=op:s[0]>0&&s[1]>0?o=ml:s[0]<0&&s[1]>0?o=op:s[0]<0&&s[1]<0&&(o=ml)}}else J(e)&&(o={...o,rotation:!0});let r=ee(e)?pl+8:Oe(e)?0:pl;return hl(Q(e,n,!0),e.angle,t,i,o,r,Oe(e)?0:void 0)},wB=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return X(i)?!1:ee(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var xl=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],ew=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=sp(e,r,t,s,fl(a));if(l&&xl(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let p=d[u];return p?xl(p,i,o):!1});if(c.length>0)return c[0];if(Wr(a)){let[u,p,m,h,f,g]=Q(e,t);if(!(ee(e)&&e.points.length<=2)){let E=Oe(e)?0:El/r.value,x=El/r.value,b=lp(Tt(u-E,p-E),Tt(m+E,h+E),Tt(f,g),e.angle);for(let[y,w]of Object.entries(b))if(ap(Tt(i,o),w,x))return y}}return!1},vB=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=ew(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),LB=([e,t,n,i],o,r,s,a,l)=>{let d=hl([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,fl(l)),c=Object.keys(d).find(u=>{let p=d[u];return p&&xl(p,o,r)});if(c)return c;if(Wr(l)){let u=(e+n)/2,p=(t+i)/2,m=El/s.value,h=lp(Tt(e-m,t-m),Tt(n+m,i+m),Tt(u,p),0);for(let[f,g]of Object.entries(h))if(ap(Tt(o,r),g,m))return f}return!1},gl=["ns","nesw","ew","nwse"],tw=(e,t)=>{let n=gl.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=gl[(n+i)%gl.length]}return e},BB=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=tw(o,t.angle)),o?`${o}-resize`:""},lp=([e,t],[n,i],o,r)=>{let s=Yr(Tt(e,t),o,r),a=Yr(Tt(n,t),o,r),l=Yr(Tt(e,i),o,r),d=Yr(Tt(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};M();var OB=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||Kt(t,e).length));M();import{pointFrom as Xr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as nw,DEFAULT_FONT_SIZE as iw,TEXT_ALIGN as ow,VERTICAL_ALIGN as rw,getSizeFromPoints as sw,randomId as aw,arrayToMap as lw,assertNever as bl,cloneJSON as mp,getFontString as dw,getUpdatedTimestamp as cw,isDevEnv as uw,toBrandedType as mw,getLineHeight as pw,DEFAULT_STICKY_NOTE_SIZE as dp,isTransparent as fw,DEFAULT_ZOOM as cp}from"@excalidraw/common";var $r={width:100,height:0},Kn=100,hw=(e,t,n)=>{let i=ye(e)?Nn(t.strokeColor&&!fw(t.strokeColor)?t.strokeColor:e.strokeColor):null,o=fi({x:0,y:0,textAlign:ow.CENTER,verticalAlign:rw.MIDDLE,...t,containerId:e.id,strokeColor:i??(t.strokeColor||e.strokeColor),labelPosition:W(e)?vd:null});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:o.id}),...i&&i!==e.strokeColor?{strokeColor:i}:null}),Ti(o,e,n),[e,o]},up=(e,t,n,i,o,r)=>{let s,a;if(Object.assign(e,{startBinding:e?.startBinding||null,endBinding:e.endBinding||null}),t){let u=t?.width??Kn,p=t?.height??Kn,m;t.id&&(m=i.getElement(t.id),m||console.error(`No element for start binding with id ${t.id} found`));let h=t.x||e.x-u,f=t.y||e.y-p/2,g=m?m.type:t.type;if(g){if(g==="text"){let E="";m&&m.type==="text"?E=m.text:t.type==="text"&&(E=t.text),E||console.error(`No text found for start binding text element for ${e.id}`),s=fi({x:h,y:f,type:"text",...m,...t,text:E}),Object.assign(s,{x:t.x||e.x-s.width,y:t.y||e.y-s.height/2})}else switch(g){case"rectangle":case"ellipse":case"diamond":{s=Oi({x:h,y:f,width:u,height:p,...m,...t,type:g});break}default:bl(e,`Unhandled element start type "${t.type}"`,!0)}jt(e,s,"orbit","start",o,r)}}if(n){let u=n?.height??Kn,p=n?.width??Kn,m;n.id&&(m=i.getElement(n.id),m||console.error(`No element for end binding with id ${n.id} found`));let h=n.x||e.x+e.width,f=n.y||e.y-u/2,g=m?m.type:n.type;if(g){if(g==="text"){let E="";m&&m.type==="text"?E=m.text:n.type==="text"&&(E=n.text),E||console.error(`No text found for end binding text element for ${e.id}`),a=fi({x:h,y:f,type:"text",...m,...n,text:E}),Object.assign(a,{y:n.y||e.y-a.height/2})}else switch(g){case"rectangle":case"ellipse":case"diamond":{a=Oi({x:h,y:f,width:p,height:u,...m,...n,type:g});break}default:bl(e,`Unhandled element end type "${g}"`,!0)}jt(e,a,"orbit","end",o,r)}}if(e.points.length<2)return{linearElement:e,startBoundElement:s,endBoundElement:a};let l=e.points.length-1,d=.5,c=mp(e.points);return e.points[l][0]>e.points[l-1][0]&&(c[0][0]=d,c[l][0]-=d),e.points[l][0]<e.points[l-1][0]&&(c[0][0]=-d,c[l][0]+=d),e.points[l][1]>e.points[l-1][1]&&(c[0][1]=d,c[l][1]-=d),e.points[l][1]<e.points[l-1][1]&&(c[0][1]=-d,c[l][1]+=d),Object.assign(e,R.getNormalizeElementPointsAndCoords({...e,points:c})),{linearElement:e,startBoundElement:s,endBoundElement:a}},yl=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>wa(Array.from(this.excalidrawElements.values()));getElementsMap=()=>mw(lw(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},ZB=(e,t)=>{if(!e)return[];let n=mp(e),i=new yl,o=new Map,r=new Map,s=cw();for(let d of n){let c,u=d.id;switch(t?.regenerateIds!==!1&&Object.assign(d,{id:aw(),created:s}),d.type){case"rectangle":case"ellipse":case"diamond":{let m=d?.label?.text&&d.width===void 0?0:d?.width||Kn,h=d?.label?.text&&d.height===void 0?0:d?.height||Kn;c=Oi({...d,width:m,height:h});break}case"line":{let m=d.width||$r.width,h=d.height||$r.height;c=Uu({width:m,height:h,points:[Xr(0,0),Xr(m,h)],...d});break}case"arrow":{let m=d.width||$r.width,h=d.height||$r.height;c=Br({width:m,height:h,endArrowhead:"arrow",points:[Xr(0,0),Xr(m,h)],...d,type:"arrow"}),Object.assign(c,sw(c.points));break}case"text":{let m=d?.fontFamily||nw,h=d?.fontSize||iw,f=d?.lineHeight||pw(m),g=d.text??"",E=ro(g),x=Ue(E,dw({fontFamily:m,fontSize:h}),f);c=fi({width:x.width,height:x.height,fontFamily:m,fontSize:h,...d});break}case"image":{c=Wu({width:d?.width||Kn,height:d?.height||Kn,...d});break}case"frame":{c=Fu({x:0,y:0,...d});break}case"magicframe":{c=Ru({x:0,y:0,...d});break}case"freedraw":{c=Hu({...d});break}case"iframe":{c=Gu({...d});break}case"stickynote":{let m=d.width||dp,h=d.height||dp;c=_a(Lr({...d,type:"stickynote",width:m,height:h,baseHeight:d.baseHeight??h}));break}case"embeddable":{c=Ou({...d});break}default:c=d,bl(d,`Unhandled element type "${d.type}"`,!0)}i.getElement(c.id)?console.error(`Duplicate id found for ${c.id}`):(i.add(c),o.set(c.id,d),u&&r.set(u,c.id))}let a=i.getElementsMap(),l=new Hi(a);for(let[d,c]of o){let u=i.getElement(d);switch(c.type){case"rectangle":case"ellipse":case"diamond":case"stickynote":case"arrow":{if(c.label?.text){let[p,m]=hw(u,c?.label,l);if(i.add(p),i.add(m),W(p)){let h=c.type==="arrow"?c?.start:void 0,f=c.type==="arrow"?c?.end:void 0;if(h&&h.id){let b=r.get(h.id);b&&Object.assign(h,{id:b})}if(f&&f.id){let b=r.get(f.id);b&&Object.assign(f,{id:b})}let{linearElement:g,startBoundElement:E,endBoundElement:x}=up(p,h,f,i,l,cp);p=g,i.add(g),i.add(E),i.add(x)}}else switch(c.type){case"arrow":{let{start:p,end:m}=c;if(p&&p.id){let E=r.get(p.id);Object.assign(p,{id:E})}if(m&&m.id){let E=r.get(m.id);Object.assign(m,{id:E})}let{linearElement:h,startBoundElement:f,endBoundElement:g}=up(u,p,m,i,l,cp);i.add(h),i.add(f),i.add(g);break}}break}}}for(let[d,c]of o){if(c.type!=="frame"&&c.type!=="magicframe")continue;let u=i.getElement(d);if(!u)throw new Error(`Excalidraw element with id ${d} doesn't exist`);let p=[];c.children.forEach(S=>{let I=r.get(S);if(!I)throw new Error(`Element with ${S} wasn't mapped correctly`);let A=i.getElement(I);if(!A)throw new Error(`Frame element with id ${I} doesn't exist`);Object.assign(A,{frameId:u.id}),A?.boundElements?.forEach(T=>{let O=i.getElement(T.id);if(!O)throw new Error(`Bound element with id ${T.id} doesn't exist`);Object.assign(O,{frameId:u.id}),p.push(O)}),p.push(A)});let[m,h,f,g]=ot(p),E=10;m=m-E,h=h-E,f=f+E,g=g+E;let x=u?.x||m,b=u?.y||h,y=u?.width||f-m,w=u?.height||g-h;Object.assign(u,{x,y:b,width:y,height:w}),uw()&&c.children.length&&(u?.x||u?.y||u?.width||u?.height)&&console.info("User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically")}return i.getElements()};M();var tk=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return jm(n.selectedLinearElement,e.scene.getNonDeletedElementsMap(),e.lastPointerMoveCoords,e.scene,n,e.getEffectiveGridSize(),t.altKey),!0;if(n.selectedLinearElement.hoverPointIndex!==null&&e.lastPointerMoveEvent&&n.selectedLinearElement.initialState.lastClickedPoint>=0&&n.selectedLinearElement.isDragging)return R.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};M();var gw=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}},ok=e=>{let t=gw(e);return t===null?null:t};M();import{getBoundsFromPoints as gp,getElementAbsoluteCoords as Ew}from"@excalidraw/element/bounds";import{newArrowElement as pp,newElement as xw,newLinearElement as jr}from"@excalidraw/element/newElement";import{ELEMENT_PENDING_DRAW_SHAPE_OPACITY as bw,getStrokeWidthByKey as Vr,ROUNDNESS as fp}from"@excalidraw/common";import{convexHull as yw,distanceToLineSegment as ww,elongation as Pw,kurtosis as hp,lineSegment as Sw,orientPrincipalAxes as Iw,pointFrom as st,polygonArea as Mw,principalAxes as Tw,principalCoords as Aw,skewness as Dw}from"@excalidraw/math";var vw=64,Lw=25,Bw=.15,kw=.25,Cw=.5,Nw=.15,Ow=.3,Gw=1.5,Wi=3;function Fw(e,t){let n=0;for(let a=1;a<e.length;a++)n+=Math.hypot(e[a][0]-e[a-1][0],e[a][1]-e[a-1][1]);let i=n/(t-1),o=0,r=[e[0]],s=e[0];for(let a=1;a<e.length;a++){let l=e[a],d=Math.hypot(l[0]-s[0],l[1]-s[1]);if(o+d>=i){let c=i-o;for(;c<=d+1e-10;){let u=c/d,p=[s[0]+u*(l[0]-s[0]),s[1]+u*(l[1]-s[1])];if(r.push(p),r.length===t)return r;s=p,o=0,c+=i}o=d-(c-i)}else o+=d;s=l}for(;r.length<t;)r.push(e[e.length-1]);return r}function Rw(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=Sw(t,n),r=0;for(let s of e)Math.hypot(s[0]-n[0],s[1]-n[1])<=Cw*i||(r=Math.max(r,ww(s,o)));return r/i}function zw(e){let t=[];for(let n=Wi;n<e.length-Wi;n++){let[i,o]=e[n-Wi],[r,s]=e[n],[a,l]=e[n+Wi],d=r-i,c=s-o,u=a-r,p=l-s;t.push(Math.abs(Math.atan2(d*p-c*u,d*u+c*p)))}return t}function _w(e){let t=zw(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-Wi;l<=s+Wi;l++)l>=0&&l<t.length&&!i[l]&&(o+=t[l],i[l]=!0)}return o/n}function Hw(e){let t=Fw(e,vw),n=0;for(let p=1;p<t.length;p++)n+=Math.hypot(t[p][0]-t[p-1][0],t[p][1]-t[p-1][1]);let i=Math.hypot(t[t.length-1][0]-t[0][0],t[t.length-1][1]-t[0][1]),o=Iw(t,Tw(t)),r=Aw(t,o).map(([p])=>p),s=yw(t),[a,l,d,c]=gp(t),u=(d-a)*(c-l);return{gapRatio:n>0?i/n:0,elongation:Pw(o),majorSkew:Dw(r),hullFillRatio:u>0?Mw(s)/u:0,cornerTurnShare:_w(t),kurtosisProduct:hp(t.map(([p])=>p))*hp(t.map(([,p])=>p)),shaftDeviationRatio:Rw(t)}}var Uw=[{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}],Ww=.2,Yw=.2,Xw=.7;function $w(e){let t="freedraw",n=Gw;for(let i of Uw){let o=Math.hypot((e.hullFillRatio-i.hullFillRatio)/Ww,(e.cornerTurnShare-i.cornerTurnShare)/Yw,(e.kurtosisProduct-i.kurtosisProduct)/Xw);o<n&&(n=o,t=i.type)}return t}function jw(e){return e.elongation>kw||e.shaftDeviationRatio>Nw?"freedraw":Math.abs(e.majorSkew)>=Ow?"arrow":"line"}function Vw(e){return e.gapRatio>Bw?jw(e):$w(e)}function Kw(e,t,n){let[i,o,r,s]=t,a=r-i,l=s-o;if(a===0&&l===0)return e[e.length-1];let d=[st(i,o),st((i+r)/2,o),st(r,o),st(r,(o+s)/2),st(r,s),st((i+r)/2,s),st(i,s),st(i,(o+s)/2)],c=-1,u=st(r,s);for(let h of d){let f=Math.hypot(h[0]-n[0],h[1]-n[1]);f>c&&(c=f,u=h)}let p=1/0,m=e[e.length-1];for(let h of e){let f=Math.hypot(h[0]-u[0],h[1]-u[1]);f<p&&(p=f,m=h)}return m}var Zw=(e,t,n=1)=>{typeof window<"u"&&(window.LAST_POINTS=e.map(([u,p])=>st(u,p)));let i=gp(e),[o,r,s,a]=i,l=Math.max(s-o,a-r);if(e.length<3||l*n<Lw)return{type:"freedraw",points:e,boundingBox:i};let d=Vw(Hw(e));return{type:t?.type==="arrow"&&d!=="arrow"?"freedraw":d,points:e,boundingBox:i}},qw=(e,t,n,i,o)=>{let r=Zw(e,i,t.zoom.value),s=r.boundingBox,[a,l,d,c]=s,p=(o??Ma([...n.values()])).find(h=>{let[f,g,E,x]=Ew(h,n);return f<=a&&g<=l&&E>=d&&x>=c})?.id??null,m=t.currentItemRoundness==="round"?{type:Ko(r.type)?fp.ADAPTIVE_RADIUS:fp.PROPORTIONAL_RADIUS}:null;switch(r.type){case"rectangle":case"diamond":case"ellipse":return xw({type:r.type,x:r.boundingBox[0],y:r.boundingBox[1],width:r.boundingBox[2]-r.boundingBox[0],height:r.boundingBox[3]-r.boundingBox[1],groupIds:[],angle:0,frameId:p,roundness:m,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Vr(r.type,t.currentItemStrokeWidthKey)});case"arrow":{let[h,f]=r.points[0],[g,E]=Kw(r.points,r.boundingBox,r.points[0]),x=st(g-h,E-f);if(Math.hypot(g-r.points[0][0],E-r.points[0][1])<60){let S=jr({type:"line",x:h,y:f,points:[st(r.points[0][0]-h,r.points[0][1]-f),x],groupIds:[],frameId:p,locked:!1,angle:0,roundness:m,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Vr(r.type,t.currentItemStrokeWidthKey)}),I=R.getNormalizeElementPointsAndCoords(S);return jr({...S,...I})}let y=pp({type:"arrow",x:h,y:f,startArrowhead:t.currentItemStartArrowhead,endArrowhead:t.currentItemEndArrowhead,points:[st(r.points[0][0]-h,r.points[0][1]-f),x],groupIds:[],frameId:p,locked:!1,angle:0,roundness:m,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Vr(r.type,t.currentItemStrokeWidthKey)}),w=R.getNormalizeElementPointsAndCoords(y);return pp({...y,...w})}case"line":{let[h,f]=r.points[0],g=r.points[r.points.length-1],E=jr({type:r.type,x:h,y:f,points:[st(r.points[0][0]-h,r.points[0][1]-f),st(g[0]-h,g[1]-f)],groupIds:[],frameId:p,locked:!1,angle:0,roundness:m,roughness:t.currentItemRoughness,backgroundColor:t.currentItemBackgroundColor,strokeColor:t.currentItemStrokeColor,fillStyle:t.currentItemFillStyle,opacity:t.currentItemOpacity,strokeStyle:t.currentItemStrokeStyle,strokeWidth:Vr(r.type,t.currentItemStrokeWidthKey)}),x=R.getNormalizeElementPointsAndCoords(E);return jr({...E,...x})}}},Qw=(e,t)=>{if(!e||e.type!==t.type||e.x!==t.x||e.y!==t.y||e.width!==t.width||e.height!==t.height||e.angle!==t.angle)return!1;if(ee(e)&&ee(t)){if(e.points.length!==t.points.length)return!1;for(let n=0;n<e.points.length;n++)if(e.points[n][0]!==t.points[n][0]||e.points[n][1]!==t.points[n][1])return!1}return!0},fk=(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=qw(n,e.state,e.scene.getNonDeletedElementsMap(),e.state.newElement,e.scene.getNonDeletedFramesLikes());if(i&&!Re(i)){let o=e.state.newElement,r={...i,id:o?.type===i.type?o.id:i.id,created:o?.type===i.type?o.created:i.created,seed:1,opacity:bw,isDeleted:!1};Qw(o,r)||e.setState({newElement:r})}else e.state.newElement!==null&&e.setState({newElement:null})}return!0}return!1};var bk=e=>e.reduce((t,n)=>t+n.version,0),lm=e=>{let t=5381;for(let n of Jw(e))t=(t<<5)+t+n.versionNonce;return t>>>0},dm=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},$e=e=>!e.isDeleted,yk=e=>e.filter(t=>$e(t)&&!Bu(t)),Ci=e=>e.filter($e);export{$n as AppStateDelta,Mg as BASE_ARROW_MIN_LENGTH,Ln as BASE_BINDING_GAP,ce as BASE_PADDING,Rn as BindableElement,Fn as BoundElement,gt as CaptureUpdateAction,vd as DEFAULT_BOUND_TEXT_LABEL_POSITION,$x as DEFAULT_BUCKET_FILL_OPTIONS,vT as DEFAULT_LINK_SIZE,rp as DEFAULT_OMIT_SIDES,V as Delta,Ka as DurableIncrement,Ra as ElementBounds,jn as ElementsDelta,Za as EphemeralIncrement,fo as FOCUS_POINT_SIZE,Cm as FlowChartCreator,km as FlowChartNavigator,ve as HEADING_DOWN,ze as HEADING_LEFT,Ee as HEADING_RIGHT,qe as HEADING_UP,wx as INVISIBLY_SMALL_ELEMENT_SIZE,ba as InvalidFractionalIndexError,R as LinearElementEditor,Ye as MINIMAL_CROP_SIZE,yB as OMIT_SIDES_FOR_FRAME,bB as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Hi as Scene,Qe as ShapeCache,rm as Store,To as StoreChange,qa as StoreDelta,Gr as StoreIncrement,Vn as StoreSnapshot,ut as aabbForElement,yE as addElementsToFrame,Ty as addNewNodes,fM as addToGroup,YL as advanceDuplicatedListMarkers,vA as alignElements,XL as applyListMarkerAdvances,Bg as avoidRectangularCorner,jt as bindBindingElement,$I as bindBindingElementToFixedPoint,Qc as bindElementsToFramesAfterDuplication,Tg as bindOrUnbindBindingElement,HI as bindOrUnbindBindingElements,As as bindPointToSnapToElementOutline,Pc as bindingProperties,Ta as boundsContainBounds,Ls as bumpVersion,yc as calculateFixedPointForElbowArrowBinding,si as calculateFixedPointForNonElbowArrowBinding,p1 as canApplyRoundnessTypeToElement,cd as canBecomePolygon,jd as canChangeRoundness,ry as canCreateLinkFromElements,dI as canHaveArrowheads,Wr as canResizeFromSides,Mi as charWidth,he as compareHeading,ii as computeBoundTextPosition,pD as computeBucketFillPolygon,Fs as computeContainerDimensionForBoundText,rS as containsCJK,ZB as convertToExcalidrawElements,qw as convertToShape,fk as convertToShapeHandlePointerMoveFromPointerDown,Wv as createPlaceholderEmbeddableLabel,nl as createSrcDoc,r1 as cropElement,Tn as deconstructDiamondElement,wi as deconstructLinearOrFreeDrawElement,Mn as deconstructRectanguloidElement,Va as deepCopyElement,kv as defaultGetElementLinkFromSelection,Q1 as detectLineHeight,tn as distanceToElement,hv as distributeElements,yt as doBoundsIntersect,Av as dragNewElement,oy as dragNewTextElement,Mv as dragSelectedElements,fb as duplicateElement,LD as duplicateElements,pM as editGroupForSelectedElement,re as elementCenterPoint,_n as elementOverlapsWithFrame,Eo as elementWithCanvasCache,Un as elementsAreInFrameBounds,Uc as elementsAreInSameGroup,$c as elementsOverlappingBBox,Xv as embeddableURLValidator,dE as excludeElementsInFramesFromSelection,sT as filterElementsEligibleAsFrameChildren,YI as fixBindingsAfterDeletion,wc as fixDuplicatedBindingsAfterDuplication,Es as flipHeading,mT as frameAndChildrenSelectedTogether,$d as generateLinearCollisionShape,ht as generateRoughOptions,BM as getActiveTextElement,sa as getAllHoveredElementAtPoint,Js as getAllMidpoints,Md as getApproxMinLineHeight,Id as getApproxMinLineWidth,Sc as getArrowLocalFixedPoints,fx as getArrowheadAngle,ok as getArrowheadForPicker,rt as getArrowheadPoints,px as getArrowheadSize,zS as getBaseFontSize,_S as getBaseFontSizeUpdate,Le as getBindingGap,XI as getBindingSideMidPoint,ca as getBindingStrategyForDraggingBindingElementEndpoints,q as getBoundTextElement,Ct as getBoundTextElementId,yS as getBoundTextElementPosition,so as getBoundTextMaxHeight,kt as getBoundTextMaxWidth,mi as getBoundsFromPoints,nn as getCenterForBounds,GS as getColorTargetElement,FS as getColorUpdate,pn as getCommonBoundingBox,ot as getCommonBounds,xE as getCommonFrameId,xS as getContainerCenter,zs as getContainerCoords,Be as getContainerElement,Hn as getContainingFrame,cn as getCornerRadius,Er as getCubicBezierCurveBound,BB as getCursorForResizingElement,ME as getDefaultFrameName,f1 as getDefaultRoundnessTypeForElement,Xd as getDiamondBaseCorners,vi as getDiamondPoints,Tv as getDragOffsetXY,mA as getDraggedElementsBounds,ea as getElbowArrowSnapMidPoint,Q as getElementAbsoluteCoords,ae as getElementBounds,Bi as getElementLineSegments,ga as getElementPointsCoords,_E as getElementRenderOffset,yu as getElementShape,vB as getElementWithTransformHandleType,Jc as getElementsCompletelyInFrame,it as getElementsInGroup,rT as getElementsInNewFrame,oT as getElementsInResizingFrame,QM as getElementsIntersectingFrame,uT as getElementsOverlappingFrame,Xc as getElementsWithinSelection,Uv as getEmbedLink,JA as getEndpointBoundTextDragAnchor,s1 as getFlipAdjustedCropPosition,zn as getFrameChildren,bE as getFrameChildrenInsertionIndex,Ma as getFrameLikeElements,cT as getFrameLikeTitle,ac as getFreedrawFillPolygon,lc as getFreedrawMaxStrokeRadius,kT as getFreedrawOutlineAsSegments,wu as getFreedrawOutlinePoints,Pu as getFreedrawStrokeCenterPoints,_e as getGlobalFixedPointForBindableElement,Ng as getGlobalFixedPoints,yd as getHeadingForElbowArrowSnap,rn as getHoveredElementForBinding,GL as getInitializedImageElements,lr as getLineHeightInPx,Bn as getLineWidth,eI as getLinearElementPathSegments,h1 as getLinearElementSubType,Cv as getLinkIdAndTypeFromSelection,Rc as getLockedLinearCursorAlignSize,nh as getMaxCharWidth,gM as getMaximumGroups,eS as getMinCharWidth,ho as getMinMaxXYFromCurvePathOps,ar as getMinTextElementWidth,Yc as getNewGroupIdsForDuplication,Ci as getNonDeletedElements,Hc as getNonDeletedGroupIds,PA as getNormalizedDimensions,_i as getObservedAppState,fl as getOmitSidesForEditorInterface,j1 as getOriginalContainerHeightFromCache,za as getPerfectElementSize,ao as getPositionAfterHeightChange,uA as getRectangleBoxAbsoluteCoords,DT as getRenderElementWithPositionOverride,mB as getResizeArrowDirection,uB as getResizeOffsetXY,In as getResizedElementAbsoluteCoords,iT as getRootElements,bk as getSceneVersion,Kt as getSelectedElements,Pr as getSelectedElementsByGroup,xa as getSelectedGroupForElement,oE as getSelectedGroupIdForElement,nE as getSelectedGroupIds,LM as getSelectionStateForElements,ua as getSimultaneouslyUpdatedElementIds,tg as getSnapOutlineMidPoint,Ys as getStickyNoteCornerRadius,zh as getStickyNoteDateLabel,Gd as getStickyNoteFooter,Rd as getStickyNoteLayout,Fd as getStickyNoteMinSize,Xs as getStickyNotePathCommands,Fh as getStickyNoteRenderPoints,js as getStickyNoteResizeIntent,vM as getTargetElements,PE as getTargetFrame,Ha as getTextAnchorRatios,qA as getTextBindingForArrowEndpoint,bS as getTextElementAngle,_s as getTextElementWithAccuratePosition,IS as getTextFromElements,th as getTextHeight,Td as getTextWidth,LB as getTransformHandleTypeFromCoords,sp as getTransformHandles,hl as getTransformHandlesFromCoords,ZA as getUnboundArrowEndpointAtPoint,nd as getUncroppedImageElement,ms as getUncroppedWidthAndHeight,AM as getVisibleAndNonSelectedElements,yk as getVisibleElements,pA as getVisibleSceneBounds,uh as getWrappedTextLines,nT as groupByFrameLikes,eT as groupsAreAtLeastIntersectingTheFrame,tT as groupsAreCompletelyOutOfFrame,ni as handleBindTextResize,jm as handleFocusPointDrag,LL as handleFocusPointHover,DL as handleFocusPointPointerDown,vL as handleFocusPointPointerUp,oi as hasBackground,Wt as hasBoundTextElement,wB as hasBoundingBox,iI as hasFillStyle,aI as hasFreedrawMode,sI as hasRoughness,oI as hasStrokeColor,ng as hasStrokeStyle,rI as hasStrokeWidth,lm as hashElementsVersion,dm as hashString,dt as headingForPoint,Pi as headingForPointFromElement,Bt as headingForPointIsHorizontal,ct as headingIsHorizontal,D1 as headingIsVertical,pg as hitElementBoundText,mg as hitElementBoundingBox,II as hitElementBoundingBoxOnly,Ot as hitElementItself,pt as intersectElementWithLineSegment,m1 as isArrowBoundToElement,W as isArrowElement,Pe as isBindableElement,aa as isBindableElementInsideOtherBindable,Xe as isBindingElement,Ef as isBindingElementType,$t as isBindingEnabled,pe as isBoundToContainer,em as isBucketFillCompatible,JM as isCursorInFrame,hf as isCurvedArrow,X as isElbowArrow,wA as isElementCompletelyInViewport,Ia as isElementContainingFrame,tu as isElementInFrame,iE as isElementInGroup,jc as isElementInViewport,ki as isElementIntersectingFrame,Nv as isElementLink,g1 as isEligibleFrameChildType,od as isEmbeddableElement,QA as isEndpointBoundText,ad as isExcalidrawElement,Og as isFixedPoint,ld as isFlowchartNodeElement,zr as isFocusPointVisible,Vo as isFrameElement,J as isFrameLikeElement,ge as isFreeDrawElement,pf as isFreeDrawElementType,Oy as isHTMLSVGElement,$o as isIframeElement,jo as isIframeLikeElement,Oe as isImageElement,Wc as isInGroup,ei as isInitializedImageElement,Bu as isInvisiblySmallElement,Re as isLineElement,ee as isLinearElement,gf as isLinearElementType,rd as isMagicFrameElement,q1 as isMeasureTextSupported,rL as isNodeInFlowchart,$e as isNonDeletedElement,qd as isOpaqueForBinding,Nt as isPathALoop,Je as isPointInElement,to as isRectangularElement,sd as isRectanguloidElement,fD as isRestylableFill,tE as isSelectedViaGroup,ff as isSharpArrow,u1 as isSimpleArrow,DM as isSomeElementSelected,pr as isStickyNoteBoundText,ye as isStickyNoteElement,xf as isTextBindableContainer,j as isTextElement,Ko as isUsingAdaptiveRadius,dd as isUsingProportionalRadius,ps as isValidPolygon,SS as isValidTextContainer,Ny as loadHTMLImageElement,Ea as makeNextSelectedElementIds,On as maxBindingDistance_simple,tk as maybeHandleArrowPointlikeDrag,Yv as maybeParseEmbedSrc,ul as measureFontSizeFromWidth,Ue as measureText,EL as moveAllLeft,xL as moveAllRight,_m as moveArrowAboveBindable,hL as moveOneLeft,gL as moveOneRight,He as mutateElement,Br as newArrowElement,Oi as newElement,Me as newElementWith,Ou as newEmbeddableElement,Fu as newFrameElement,Hu as newFreeDrawElement,Gu as newIframeElement,Wu as newImageElement,Uu as newLinearElement,Ru as newMagicFrameElement,Lr as newStickyNoteElement,fi as newTextElement,gw as normalizeArrowhead,db as normalizeBoundElementsOrder,tm as normalizeElementOrder,je as normalizeFixedPoint,FL as normalizeSVG,_A as normalizeStickyNote,Ws as normalizeStickyNoteBackgroundColor,$s as normalizeStickyNoteFontSize,_a as normalizeStickyNoteGeometry,Nn as normalizeStickyNoteStrokeColor,Nu as normalizeStickyNoteStyle,ro as normalizeText,Ir as omitGroupsContainingFrameLikes,EE as omitPartialGroups,Kc as orderByFractionalIndex,oo as originalContainerCache,Ov as parseElementLinkFromURL,dh as parseTokens,Xt as pointInsideBounds,Ex as pointInsideBoundsInclusive,ZL as positionElementsOnGrid,ta as projectFixedPointOntoDiagonal,UI as reanchorBindingsToOutline,Zw as recognizeShape,BD as reconcileDuplicatedElements,Ti as redrawTextBoundingBox,_u as refreshTextDimensions,HS as relayoutStickyNotes,wE as removeAllElementsFromFrame,eu as removeElementsFromFrame,hM as removeFromSelectedGroups,BT as renderElement,LT as renderSelectionElement,Ku as rendersOpaqueFill,aT as replaceAllElementsInFrame,tp as rescalePointsInElement,Pd as resetOriginalContainerCache,qy as resizeMultipleElements,Vy as resizeSingleElement,Xy as resizeSingleTextElement,ew as resizeTest,HE as resolveElementRenderState,eE as selectGroup,zc as selectGroupsForSelectedElements,_c as selectGroupsFromGivenElements,J1 as setCustomTextMetricsProvider,wS as shouldAllowVerticalAlign,dT as shouldApplyFrameClip,gr as shouldTestInside,OB as showSelectedShapeActions,PS as suppportsHorizontalAlign,wa as syncInvalidIndices,Zc as syncInvalidIndicesImmutable,di as syncMovedIndices,RS as syncStickyNoteInk,Fc as toggleLinePolygonState,lI as toolIsArrow,cB as transformElements,Ke as unbindBindingElement,WI as updateBindings,Ge as updateBoundElements,Gt as updateBoundPoint,Ii as updateElbowArrowPoints,lT as updateFrameMembershipOfSelectedElements,OL as updateImageCache,wd as updateOriginalContainerCache,Ai as updateStickyNoteLayout,bd as validateElbowPoints,pE as validateFractionalIndices,Lt as vectorToHeading,St as wrapText};
|