@excalidraw/element 0.18.0-063e025 → 0.18.0-1acf66e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/dev/index.js +3951 -3199
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +12 -12
  4. package/dist/types/common/src/constants.d.ts +2 -0
  5. package/dist/types/common/src/points.d.ts +1 -1
  6. package/dist/types/common/src/utils.d.ts +1 -1
  7. package/dist/types/element/src/arrowEndpointText.d.ts +49 -0
  8. package/dist/types/element/src/arrows/focus.d.ts +5 -2
  9. package/dist/types/element/src/binding.d.ts +12 -3
  10. package/dist/types/element/src/comparisons.d.ts +4 -4
  11. package/dist/types/element/src/convertToShape.d.ts +23 -0
  12. package/dist/types/element/src/dragElements.d.ts +27 -0
  13. package/dist/types/element/src/flowchart.d.ts +6 -6
  14. package/dist/types/element/src/groups.d.ts +1 -1
  15. package/dist/types/element/src/index.d.ts +2 -0
  16. package/dist/types/element/src/linearElementEditor.d.ts +7 -0
  17. package/dist/types/element/src/newElement.d.ts +13 -0
  18. package/dist/types/element/src/selection.d.ts +1 -1
  19. package/dist/types/element/src/textElement.d.ts +6 -3
  20. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +15 -3
  21. package/dist/types/excalidraw/actions/actionBoundText.d.ts +10 -2
  22. package/dist/types/excalidraw/actions/actionCanvas.d.ts +99 -565
  23. package/dist/types/excalidraw/actions/actionClipboard.d.ts +10 -2
  24. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +5 -1
  25. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +16 -3
  26. package/dist/types/excalidraw/actions/actionDeselect.d.ts +2 -1
  27. package/dist/types/excalidraw/actions/actionElementLink.d.ts +5 -1
  28. package/dist/types/excalidraw/actions/actionElementLock.d.ts +10 -2
  29. package/dist/types/excalidraw/actions/actionExport.d.ts +12 -4
  30. package/dist/types/excalidraw/actions/actionFrame.d.ts +15 -178
  31. package/dist/types/excalidraw/actions/actionGroup.d.ts +10 -2
  32. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +6 -1
  33. package/dist/types/excalidraw/actions/actionLink.d.ts +5 -1
  34. package/dist/types/excalidraw/actions/actionMenu.d.ts +5 -1
  35. package/dist/types/excalidraw/actions/actionProperties.d.ts +10 -2
  36. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +5 -1
  37. package/dist/types/excalidraw/actions/actionStyles.d.ts +5 -1
  38. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +1 -1
  39. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +5 -1
  40. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +5 -1
  41. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +5 -1
  42. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +5 -1
  43. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +5 -1
  44. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +5 -1
  45. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +6 -2
  46. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +5 -1
  47. package/dist/types/excalidraw/actions/index.d.ts +0 -1
  48. package/dist/types/excalidraw/actions/manager.d.ts +1 -0
  49. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  50. package/dist/types/excalidraw/actions/types.d.ts +5 -1
  51. package/dist/types/excalidraw/appState.d.ts +4 -4
  52. package/dist/types/excalidraw/components/Actions.d.ts +16 -10
  53. package/dist/types/excalidraw/components/App.arrowText.d.ts +72 -0
  54. package/dist/types/excalidraw/components/App.cursor.d.ts +31 -0
  55. package/dist/types/excalidraw/components/App.d.ts +322 -76
  56. package/dist/types/excalidraw/components/App.drawshape.d.ts +55 -0
  57. package/dist/types/excalidraw/components/App.flowchart.d.ts +21 -0
  58. package/dist/types/excalidraw/components/App.viewport.d.ts +73 -0
  59. package/dist/types/excalidraw/components/{ToolButton.d.ts → IconButton.d.ts} +16 -19
  60. package/dist/types/excalidraw/components/LaserPointerButton.d.ts +2 -4
  61. package/dist/types/excalidraw/components/LayerUI.d.ts +4 -2
  62. package/dist/types/excalidraw/components/LockButton.d.ts +3 -4
  63. package/dist/types/excalidraw/components/MagicButton.d.ts +0 -2
  64. package/dist/types/excalidraw/components/MobileMenu.d.ts +4 -4
  65. package/dist/types/excalidraw/components/MobileToolbar.d.ts +9 -0
  66. package/dist/types/excalidraw/components/PenModeButton.d.ts +2 -5
  67. package/dist/types/excalidraw/components/Popover.d.ts +1 -3
  68. package/dist/types/excalidraw/components/{ButtonIcon.d.ts → RadioButton.d.ts} +2 -5
  69. package/dist/types/excalidraw/components/ToolPopover.d.ts +3 -6
  70. package/dist/types/excalidraw/components/Toolbar.d.ts +11 -0
  71. package/dist/types/excalidraw/components/Tools.d.ts +145 -0
  72. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +2 -0
  73. package/dist/types/excalidraw/components/footer/Footer.d.ts +3 -1
  74. package/dist/types/excalidraw/components/icons.d.ts +1 -1
  75. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +1 -1
  76. package/dist/types/excalidraw/components/positionElementBesideCursor.d.ts +26 -0
  77. package/dist/types/excalidraw/components/shapeActionPredicates.d.ts +39 -0
  78. package/dist/types/excalidraw/data/blob.d.ts +14 -6
  79. package/dist/types/excalidraw/data/json.d.ts +7 -3
  80. package/dist/types/excalidraw/drawShapeTrail.d.ts +16 -0
  81. package/dist/types/excalidraw/scene/types.d.ts +3 -0
  82. package/dist/types/excalidraw/types.d.ts +199 -13
  83. package/dist/types/excalidraw/viewport.d.ts +20 -64
  84. package/dist/types/laser-pointer/src/state.d.ts +1 -0
  85. package/dist/types/math/src/index.d.ts +1 -0
  86. package/dist/types/math/src/pca.d.ts +79 -0
  87. package/dist/types/math/src/polygon.d.ts +25 -1
  88. package/package.json +4 -4
  89. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +0 -173
  90. package/dist/types/excalidraw/components/HandButton.d.ts +0 -10
  91. package/dist/types/excalidraw/components/MobileToolBar.d.ts +0 -10
  92. package/dist/types/excalidraw/components/shapes.d.ts +0 -270
  93. package/dist/types/excalidraw/cursor.d.ts +0 -5
  94. package/dist/types/excalidraw/scene/zoom.d.ts +0 -12
@@ -1,28 +1,28 @@
1
- var au=Object.create;var ma=Object.defineProperty;var lu=Object.getOwnPropertyDescriptor;var du=Object.getOwnPropertyNames;var cu=Object.getPrototypeOf,uu=Object.prototype.hasOwnProperty;var mu=(e,t)=>()=>(e&&(t=e(e=0)),t);var pu=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var fu=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of du(t))!uu.call(e,o)&&o!==n&&ma(e,o,{get:()=>t[o],enumerable:!(i=lu(t,o))||i.enumerable});return e};var hu=(e,t,n)=>(n=e!=null?au(cu(e)):{},fu(t||!e||!e.__esModule?ma(n,"default",{value:e,enumerable:!0}):n,e));var B,P=mu(()=>{B={PROD:!0}});var cc=pu((dI,dc)=>{P();var lc="Expected a function",sc=NaN,Wh="[object Symbol]",Uh=/^\s+|\s+$/g,Yh=/^[-+]0x[0-9a-f]+$/i,jh=/^0b[01]+$/i,Xh=/^0o[0-7]+$/i,$h=parseInt,Vh=typeof global=="object"&&global&&global.Object===Object&&global,Zh=typeof self=="object"&&self&&self.Object===Object&&self,qh=Vh||Zh||Function("return this")(),Kh=Object.prototype,Qh=Kh.toString,Jh=Math.max,eE=Math.min,Ys=function(){return qh.Date.now()};function tE(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(lc);t=ac(t)||0,nr(n)&&(c=!!n.leading,u="maxWait"in n,r=u?Jh(ac(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(S){var I=i,M=o;return i=o=void 0,d=S,s=e.apply(M,I),s}function h(S){return d=S,a=setTimeout(g,t),c?p(S):s}function f(S){var I=S-l,M=S-d,A=t-I;return u?eE(A,r-M):A}function E(S){var I=S-l,M=S-d;return l===void 0||I>=t||I<0||u&&M>=r}function g(){var S=Ys();if(E(S))return x(S);a=setTimeout(g,f(S))}function x(S){return a=void 0,m&&i?p(S):(i=o=void 0,s)}function b(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function y(){return a===void 0?s:x(Ys())}function w(){var S=Ys(),I=E(S);if(i=arguments,o=this,l=S,I){if(a===void 0)return h(l);if(u)return a=setTimeout(g,t),p(l)}return a===void 0&&(a=setTimeout(g,t)),s}return w.cancel=b,w.flush=y,w}function nE(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(lc);return nr(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),tE(e,t,{leading:i,maxWait:t,trailing:o})}function nr(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function iE(e){return!!e&&typeof e=="object"}function oE(e){return typeof e=="symbol"||iE(e)&&Qh.call(e)==Wh}function ac(e){if(typeof e=="number")return e;if(oE(e))return sc;if(nr(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=nr(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Uh,"");var n=jh.test(e);return n||Xh.test(e)?$h(e.slice(2),n?2:8):Yh.test(e)?sc:+e}dc.exports=nE});P();import{toIterable as Og}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Qt,viewportCoordsToSceneCoords as er}from"@excalidraw/common";import{normalizeRadians as qd,radiansBetweenAngles as yh,radiansDifference as Ph}from"@excalidraw/math";import{pointsEqual as Ih}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function Er(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 gu(e,t,n){let i=[];e.forEach(o=>i.push(...o)),Er(i,t,n)}function xu(e,t){return e[0]===t[0]&&e[1]===t[1]}function pa(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)Er(d,a,o);let l=bu(s,r,i);if(o){for(let d of s)Er(d,a,-o);gu(l,a,-o)}return l}function bu(e,t,n){let i=[];for(let d of e){let c=[...d];xu(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 wt(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),pa(e,o,i,r||1)}var on=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=wt(t,n);return{type:"fillSketch",ops:this.renderLines(i,n)}}renderLines(t,n){let i=[];for(let o of t)i.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return i}};P();P();function rn(e){let t=e[0],n=e[1];return Math.sqrt(Math.pow(t[0]-n[0],2)+Math.pow(t[1]-n[1],2))}var Ki=class extends on{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=wt(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)rn([u,m])&&a.push([[u[0]-l,u[1]+d],[...m]],[[u[0]+l,u[1]-d],[...m]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var Qi=class extends on{fillPolygons(t,n){let i=this._fillPolygons(t,n),o=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),r=this._fillPolygons(t,o);return i.ops=i.ops.concat(r.ops),i}};P();var Ji=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=wt(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=rn(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,E=m-s+Math.random()*2*s,g=f-s+Math.random()*2*s,x=this.helper.ellipse(E,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var eo=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=wt(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=rn(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,E=[c[0]+h*Math.cos(m)+d*Math.cos(m),c[1]+h*Math.sin(m)+d*Math.sin(m)],g=[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(E[0],E[1],g[0],g[1],n))}}),r}};P();var to=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,o=n.zigzagOffset<0?i:n.zigzagOffset;n=Object.assign({},n,{hachureGap:i+o});let r=wt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=rn(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)],E=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],g=[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],g[0],g[1],i),...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],i))}}),o}};var _e={};function fa(e,t){let n=e.fillStyle||"hachure";if(!_e[n])switch(n){case"zigzag":_e[n]||(_e[n]=new Ki(t));break;case"cross-hatch":_e[n]||(_e[n]=new Qi(t));break;case"dots":_e[n]||(_e[n]=new Ji(t));break;case"dashed":_e[n]||(_e[n]=new eo(t));break;case"zigzag-line":_e[n]||(_e[n]=new to(t));break;case"hachure":default:n="hachure",_e[n]||(_e[n]=new on(t));break}return _e[n]}P();function ha(){return Math.floor(Math.random()*2**31)}var no=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};P();P();var io={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function wu(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 gr(e,t){return e.type===t}function ti(e){let t=[],n=wu(e),i="BOD",o=0,r=n[o];for(;!gr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=io[r.text],i=r.text;else return ti("M0,0"+e);else gr(r,1)?s=io[i]:(o++,s=io[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(gr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof io[i]=="number"){let l={key:i,data:a};t.push(l),o+=s,r=n[o],i==="M"&&(i="L"),i==="m"&&(i="l")}else throw new Error("Bad segment: "+i)}else throw new Error("Path data ended short")}return t}P();function bi(e){let t=0,n=0,i=0,o=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[i,o]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),i=t,o=n;break;case"L":r.push({key:"L",data:[...a]}),[t,n]=a;break;case"l":t+=a[0],n+=a[1],r.push({key:"L",data:[t,n]});break;case"C":r.push({key:"C",data:[...a]}),t=a[4],n=a[5];break;case"c":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":r.push({key:"Q",data:[...a]}),t=a[2],n=a[3];break;case"q":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":r.push({key:"A",data:[...a]}),t=a[5],n=a[6];break;case"a":t+=a[5],n+=a[6],r.push({key:"A",data:[a[0],a[1],a[2],a[3],a[4],t,n]});break;case"H":r.push({key:"H",data:[...a]}),t=a[0];break;case"h":t+=a[0],r.push({key:"H",data:[t]});break;case"V":r.push({key:"V",data:[...a]}),n=a[0];break;case"v":n+=a[0],r.push({key:"V",data:[n]});break;case"S":r.push({key:"S",data:[...a]}),t=a[2],n=a[3];break;case"s":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=i,n=o;break}return r}P();function yi(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,E=o+2*(h-o)/3,g=u+2*(p-u)/3,x=m+2*(h-m)/3;t.push({key:"C",data:[f,E,g,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,E=o+2*(m-o)/3,g=p+2*(u-p)/3,x=h+2*(m-h)/3;t.push({key:"C",data:[f,E,g,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],E=c[5],g=c[6];u===0||m===0?(t.push({key:"C",data:[i,o,E,g,E,g]}),i=E,o=g):(i!==E||o!==g)&&(Ea(i,o,E,g,u,m,p,h,f).forEach(function(b){t.push({key:"C",data:b})}),i=E,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function yu(e){return Math.PI*e/180}function wi(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 Ea(e,t,n,i,o,r,s,a,l,d){let c=yu(s),u=[],m=0,p=0,h=0,f=0;if(d)[m,p,h,f]=d;else{[e,t]=wi(e,t,-c),[n,i]=wi(n,i,-c);let O=(e-n)/2,D=(t-i)/2,Y=O*O/(o*o)+D*D/(r*r);Y>1&&(Y=Math.sqrt(Y),o=Y*o,r=Y*r);let H=a===l?-1:1,V=o*o,F=r*r,T=V*F-V*D*D-F*O*O,N=V*D*D+F*O*O,_=H*Math.sqrt(Math.abs(T/N));h=_*o*D/r+(e+n)/2,f=_*-r*O/o+(t+i)/2,m=Math.asin(parseFloat(((t-f)/r).toFixed(9))),p=Math.asin(parseFloat(((i-f)/r).toFixed(9))),e<h&&(m=Math.PI-m),n<h&&(p=Math.PI-p),m<0&&(m=Math.PI*2+m),p<0&&(p=Math.PI*2+p),l&&m>p&&(m=m-Math.PI*2),!l&&p>m&&(p=p-Math.PI*2)}let E=p-m;if(Math.abs(E)>Math.PI*120/180){let O=p,D=n,Y=i;l&&p>m?p=m+Math.PI*120/180*1:p=m+Math.PI*120/180*-1,n=h+o*Math.cos(p),i=f+r*Math.sin(p),u=Ea(n,i,D,Y,o,r,s,0,l,[p,O,h,f])}E=p-m;let g=Math.cos(m),x=Math.sin(m),b=Math.cos(p),y=Math.sin(p),w=Math.tan(E/4),S=4/3*o*w,I=4/3*r*w,M=[e,t],A=[e+S*x,t-I*g],L=[n+S*y,i-I*b],C=[n,i];if(A[0]=2*M[0]-A[0],A[1]=2*M[1]-A[1],d)return[A,L,C].concat(u);{u=[A,L,C].concat(u);let O=[];for(let D=0;D<u.length;D+=3){let Y=wi(u[D][0],u[D][1],c),H=wi(u[D+1][0],u[D+1][1],c),V=wi(u[D+2][0],u[D+2][1],c);O.push([Y[0],Y[1],H[0],H[1],V[0],V[1]])}return O}}var Pu={randOffset:Au,randOffsetWithRange:Mu,ellipse:Su,doubleLineOps:Tu};function xr(e,t,n,i,o){return{type:"path",ops:Gt(e,t,n,i,o)}}function Pi(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Gt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Gt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return xr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Iu(e,t){return Pi(e,!0,t)}function ya(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Iu(r,o)}function br(e,t){let n=xa(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=xa(e,1.5*(1+t.roughness*.22),Du(t));n=n.concat(i)}return{type:"path",ops:n}}function Su(e,t,n,i,o){let r=wr(n,i,o);return so(e,t,o,r).opset}function wr(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=R(s*l,n),a+=R(a*l,n),{increment:r,rx:s,ry:a}}function so(e,t,n,i){let[o,r]=ba(i.increment,e,t,i.rx,i.ry,1,i.increment*oo(.1,oo(.4,1,n),n),n),s=ro(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=ba(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=ro(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function 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+=R(u*.01,l),m+=R(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,E=Math.min(f/2,(h-p)/2),g=wa(E,d,c,u,m,p,h,1,l);if(!l.disableMultiStroke){let x=wa(E,d,c,u,m,p,h,1.5,l);g.push(...x)}return s&&(a?g.push(...Gt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...Gt(d,c,d+u*Math.cos(h),c+m*Math.sin(h),l)):g.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(p),c+m*Math.sin(p)]})),{type:"path",ops:g}}function Pr(e,t){let n=yi(bi(ti(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(...Gt(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(...vu(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...Gt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function ao(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+R(o,t),i[0][1]+R(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+R(o,t),i[s][1]+R(o,t)]})}}return{type:"fillPath",ops:n}}function kn(e,t){return fa(t,Pu).fillPolygons(e,t)}function Pa(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=R(d*.01,s),c+=R(c*.01,s);let u=o,m=r;for(;u<0;)u+=Math.PI*2,m+=Math.PI*2;m-u>Math.PI*2&&(u=0,m=Math.PI*2);let p=(m-u)/s.curveStepCount,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]),kn([h],s)}function Au(e,t){return R(e,t)}function Mu(e,t,n){return oo(e,t,n)}function Tu(e,t,n,i,o){return Gt(e,t,n,i,o,!0)}function Du(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Ia(e){return e.randomizer||(e.randomizer=new no(e.seed||0)),e.randomizer.next()}function oo(e,t,n,i=1){return n.roughness*i*(Ia(n)*(t-e)+e)}function R(e,t,n=1){return oo(-e,e,t,n)}function Gt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=ga(e,t,n,i,o,!0,!1);if(s)return a;let l=ga(e,t,n,i,o,!0,!0);return a.concat(l)}function ga(e,t,n,i,o,r,s){let a=Math.pow(e-n,2)+Math.pow(t-i,2),l=Math.sqrt(a),d=1;l<200?d=1:l>500?d=.4:d=-.0016668*l+1.233334;let c=o.maxRandomnessOffset||0;c*c*100>a&&(c=l/10);let u=c/2,m=.2+Ia(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,h=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=R(p,o,d),h=R(h,o,d);let f=[],E=()=>R(u,o,d),g=()=>R(c,o,d),x=o.preserveVertices;return r&&(s?f.push({op:"move",data:[e+(x?0:E()),t+(x?0:E())]}):f.push({op:"move",data:[e+(x?0:R(c,o,d)),t+(x?0:R(c,o,d))]})),s?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.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}function xa(e,t,n){let i=[];i.push([e[0][0]+R(t,n),e[0][1]+R(t,n)]),i.push([e[0][0]+R(t,n),e[0][1]+R(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+R(t,n),e[o][1]+R(t,n)]),o===e.length-1&&i.push([e[o][0]+R(t,n),e[o][1]+R(t,n)]);return ro(i,null,n)}function ro(e,t,n){let i=e.length,o=[];if(i>3){let r=[],s=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<i;a++){let l=e[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*e[a+1][0]-s*e[a-1][0])/6,l[1]+(s*e[a+1][1]-s*e[a-1][1])/6],r[2]=[e[a+1][0]+(s*e[a][0]-s*e[a+2][0])/6,e[a+1][1]+(s*e[a][1]-s*e[a+2][1])/6],r[3]=[e[a+1][0],e[a+1][1]],o.push({op:"bcurveTo",data:[r[1][0],r[1][1],r[2][0],r[2][1],r[3][0],r[3][1]]})}if(t&&t.length===2){let a=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+R(a,n),t[1]+R(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...Gt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function ba(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let m=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(m),c.push(m)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=R(.5,a)-Math.PI/2;c.push([R(r,a)+t+.9*i*Math.cos(u-e),R(r,a)+n+.9*o*Math.sin(u-e)]);let m=Math.PI*2+u-.01;for(let p=u;p<m;p=p+e){let h=[R(r,a)+t+i*Math.cos(p),R(r,a)+n+o*Math.sin(p)];d.push(h),c.push(h)}c.push([R(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),R(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([R(r,a)+t+.98*i*Math.cos(u+s),R(r,a)+n+.98*o*Math.sin(u+s)]),c.push([R(r,a)+t+.9*i*Math.cos(u+s*.5),R(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function wa(e,t,n,i,o,r,s,a,l){let d=r+R(.1,l),c=[];c.push([R(a,l)+t+.9*i*Math.cos(d-e),R(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([R(a,l)+t+i*Math.cos(u),R(a,l)+n+o*Math.sin(u)]);return c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),ro(c,null,l)}function vu(e,t,n,i,o,r,s,a){let l=[],d=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],c=[0,0],u=a.disableMultiStroke?1:2,m=a.preserveVertices;for(let p=0;p<u;p++)p===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(m?0:R(d[0],a)),s[1]+(m?0:R(d[0],a))]}),c=m?[o,r]:[o+R(d[p],a),r+R(d[p],a)],l.push({op:"bcurveTo",data:[e+R(d[p],a),t+R(d[p],a),n+R(d[p],a),i+R(d[p],a),c[0],c[1]]});return l}P();function Ii(e){return[...e]}function Sa(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let i=[];if(n===3)i.push(Ii(e[0]),Ii(e[1]),Ii(e[2]),Ii(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(Ii(o[0]));for(let a=1;a+2<o.length;a++){let l=o[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*o[a+1][0]-s*o[a-1][0])/6,l[1]+(s*o[a+1][1]-s*o[a-1][1])/6],r[2]=[o[a+1][0]+(s*o[a][0]-s*o[a+2][0])/6,o[a+1][1]+(s*o[a][1]-s*o[a+2][1])/6],r[3]=[o[a+1][0],o[a+1][1]],i.push(r[1],r[2],r[3])}}return i}P();function Bu(e,t){return Math.sqrt(lo(e,t))}function lo(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Lu(e,t,n){let i=lo(t,n);if(i===0)return lo(e,t);let o=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i;return o=Math.max(0,Math.min(1,o)),lo(e,Fn(t,n,o))}function Fn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Cu(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 Ir(e,t,n,i){let o=i||[];if(Cu(e,t)<n){let r=e[t+0];o.length?Bu(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=Fn(s,a,.5),u=Fn(a,l,.5),m=Fn(l,d,.5),p=Fn(c,u,.5),h=Fn(u,m,.5),f=Fn(p,h,.5);Ir([s,c,p,f],0,n,o),Ir([f,h,m,d],0,n,o)}return o}function Si(e,t){return co(e,0,e.length,t)}function co(e,t,n,i,o){let r=o||[],s=e[t],a=e[n-1],l=0,d=1;for(let c=t+1;c<n-1;++c){let u=Lu(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(co(e,t,d+1,i,r),co(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function Ot(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;Ir(e,s,t,i)}return n&&n>0?co(i,0,i.length,n):i}P();function Aa(e,t,n){let i=ti(e),o=yi(bi(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Ot(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=Si(m,n);p.length&&u.push(p)}return u}var qe="none",it=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return ha()}_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",[xr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=ya(t,n,i,o,s);if(s.fill){let d=[[t,n],[t+i,n],[t+i,n+o],[t,n+o]];s.fillStyle==="solid"?a.push(ao([d],s)):a.push(kn([d],s))}return s.stroke!==qe&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=wr(i,o,s),d=so(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=so(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(kn([d.estimatedPoints],s));return s.stroke!==qe&&a.push(d.opset),this._d("ellipse",a,s)}circle(t,n,i,o){let r=this.ellipse(t,n,i,i,o);return r.shape="circle",r}linearPath(t,n){let i=this._o(n);return this._d("linearPath",[Pi(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(Pa(t,n,i,o,r,s,d));return d.stroke!==qe&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=br(t,i);if(i.fill&&i.fill!==qe&&t.length>=3)if(i.fillStyle==="solid"){let s=br(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(s.ops)})}else{let s=Sa(t),a=Ot(s,10,(1+i.roughness)/2);o.push(kn([a],i))}return i.stroke!==qe&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=Pi(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(ao([t],i)):o.push(kn([t],i))),i.stroke!==qe&&o.push(r),this._d("polygon",o,i)}path(t,n){let i=this._o(n),o=[];if(!t)return this._d("path",o,i);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=i.fill&&i.fill!=="transparent"&&i.fill!==qe,s=i.stroke!==qe,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=Aa(t,1,l),c=Pr(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=Pr(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else o.push(ao(d,i));else o.push(kn(d,i));return s&&(a?d.forEach(u=>{o.push(Pi(u,!1,i))}):o.push(c)),this._d("path",o,i)}opsToPath(t,n){let i="";for(let o of t.ops){let r=typeof n=="number"&&n>=0?o.data.map(s=>+s.toFixed(n)):o.data;switch(o.op){case"move":i+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":i+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":i+=`L${r[0]} ${r[1]} `;break}}return i.trim()}toPaths(t){let n=t.sets||[],i=t.options||this.defaultOptions,o=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:qe};break;case"fillPath":s={d:this.opsToPath(r),stroke:qe,strokeWidth:0,fill:i.fill||qe};break;case"fillSketch":s=this.fillSketch(r,i);break}s&&o.push(s)}return o}fillSketch(t,n){let i=n.fillWeight;return i<0&&(i=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||qe,strokeWidth:i,fill:qe}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var uo=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new it(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":o.save(),o.strokeStyle=i.stroke==="none"?"transparent":i.stroke,o.lineWidth=i.strokeWidth,i.strokeLineDash&&o.setLineDash(i.strokeLineDash),i.strokeLineDashOffset&&(o.lineDashOffset=i.strokeLineDashOffset),this._drawToContext(o,s,r),o.restore();break;case"fillPath":{o.save(),o.fillStyle=i.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,s,r,a),o.restore();break}case"fillSketch":this.fillSketch(o,s,i);break}}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2),t.save(),i.fillLineDash&&t.setLineDash(i.fillLineDash),i.fillLineDashOffset&&(t.lineDashOffset=i.fillLineDashOffset),t.strokeStyle=i.fill||"",t.lineWidth=o,this._drawToContext(t,n,i.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,i,o="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof i=="number"&&i>=0?r.data.map(a=>+a.toFixed(i)):r.data;switch(r.op){case"move":t.moveTo(s[0],s[1]);break;case"bcurveTo":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"lineTo":t.lineTo(s[0],s[1]);break}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s),s}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s),s}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s),s}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r),r}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i),i}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i),i}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d),d}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i),i}path(t,n){let i=this.gen.path(t,n);return this.draw(i),i}};P();P();var Ai="http://www.w3.org/2000/svg";var mo=class{constructor(t,n){this.svg=t,this.gen=new it(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(Ai,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(Ai,"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(Ai,"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(Ai,"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 ni={canvas(e,t){return new uo(e,t)},svg(e,t){return new mo(e,t)},generator(e){return new it(e)},newSeed(){return it.newSeed()}};import{arrayToMap as Vd,invariant as Os,rescalePoints as Ud,sizeOf as ch}from"@excalidraw/common";import{degreesToRadians as Gs,lineSegment as pe,pointFrom as v,pointFromArray as Zd,pointRotateRads as ee}from"@excalidraw/math";P();import{invariant as Gu}from"@excalidraw/common";import{curve as Ou,lineSegment as ku,pointFrom as ce,pointDistance as xb,pointFromArray as Fu,pointFromVector as Nu,pointRotateRads as lt,polygon as Ma,polygonFromPoints as Sr,PRECISION as bb,segmentsIntersectAt as wb,vector as Ru,vectorAdd as zu,vectorFromPoint as Hu,vectorScale as yb}from"@excalidraw/math";import{getElementAbsoluteCoords as Ib}from"@excalidraw/element";var Ta=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=ce(s,a),d;return e.type==="diamond"?d=Ma(lt(ce(s,r),l,t),lt(ce(o+n,a),l,t),lt(ce(s,r+i),l,t),lt(ce(o,a),l,t)):d=Ma(lt(ce(o,r),l,t),lt(ce(o+n,r),l,t),lt(ce(o+n,r+i),l,t),lt(ce(o,r+i),l,t)),{type:"polygon",data:d}};var Da=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:ce(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},kt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},va=(e,t=ce(0,0),n,i)=>{let o=l=>lt(ce(l[0]+t[0],l[1]+t[1]),i,n),r=kt(e),s=[],a=ce(0,0);for(let l of r){if(l.op==="move"){let d=Fu(l.data);Gu(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(ce(l.data[0],l.data[1])),c=o(ce(l.data[2],l.data[3])),u=o(ce(l.data[4],l.data[5]));s.push(Ou(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},_u=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(ku(t,o)),t=o}return n},Ba=(e,t,n=!1)=>{let i=r=>lt(Nu(zu(Hu(r),Ru(e.x,e.y))),t,e.angle),o=_u(e.points.map(r=>i(r)));return n?{type:"polygon",data:Sr(o.flat())}:{type:"polyline",data:o}},La=(e,t,n=ce(0,0),i,o)=>{let r=c=>lt(ce(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:Sr(e.points.map(c=>r(c)))};let s=kt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(ce(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(ce(c.data[0],c.data[1])),a.push(ce(c.data[2],c.data[3])),a.push(ce(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(ce(c.data[0],c.data[1]));let d=Ot(a,10,5).map(c=>r(c));return{type:"polygon",data:Sr(d)}};P();P();function Ca(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function Wu(e){return[-e[0],-e[1]]}function ct(e,t){return[e[0]+t[0],e[1]+t[1]]}function ot(e,t){return[e[0]-t[0],e[1]-t[1]]}function dt(e,t){return[e[0]*t,e[1]*t]}function Uu(e,t){return[e[0]/t,e[1]/t]}function Mi(e){return[e[1],-e[0]]}function Ga(e,t){return e[0]*t[0]+e[1]*t[1]}function Yu(e,t){return e[0]===t[0]&&e[1]===t[1]}function ju(e){return Math.hypot(e[0],e[1])}function Xu(e){return e[0]*e[0]+e[1]*e[1]}function Oa(e,t){return Xu(ot(e,t))}function Na(e){return Uu(e,ju(e))}function $u(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function Ti(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 Ar(e,t,n){return ct(e,dt(ot(t,e),n))}function ka(e,t,n){return ct(e,dt(t,n))}var{min:ii,PI:Vu}=Math,Fa=.275,Di=Vu+1e-4;function Zu(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=F=>F,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=F=>F*(2-F)}=a,{cap:m=!0,easing:p=F=>--F*F*F+1}=l;if(e.length===0||n<=0)return[];let h=e[e.length-1].runningLength,f=a.taper===!1?0:a.taper===!0?Math.max(n,h):a.taper,E=l.taper===!1?0:l.taper===!0?Math.max(n,h):l.taper,g=Math.pow(n*i,2),x=[],b=[],y=e.slice(0,10).reduce((F,T)=>{let N=T.pressure;if(r){let _=ii(1,T.distance/n),ye=ii(1,1-_);N=ii(1,F+(ye-F)*(_*Fa))}return(F+N)/2},e[0].pressure),w=Ca(n,o,e[e.length-1].pressure,s),S,I=e[0].vector,M=e[0].point,A=M,L=M,C=A,O=!1;for(let F=0;F<e.length;F++){let{pressure:T}=e[F],{point:N,vector:_,distance:ye,runningLength:nt}=e[F];if(F<e.length-1&&h-nt<3)continue;if(o){if(r){let de=ii(1,ye/n),oe=ii(1,1-de);T=ii(1,y+(oe-y)*(de*Fa))}w=Ca(n,o,T,s)}else w=n/2;S===void 0&&(S=w);let Qn=nt<f?u(nt/f):1,Jn=h-nt<E?p((h-nt)/E):1;w=Math.max(.01,w*Math.min(Qn,Jn));let Gn=(F<e.length-1?e[F+1]:e[F]).vector,Lt=F<e.length-1?Ga(_,Gn):1,On=Ga(_,I)<0&&!O,tn=Lt!==null&&Lt<0;if(On||tn){let de=dt(Mi(I),w);for(let oe=1/13,nn=0;nn<=1;nn+=oe)L=Ti(ot(N,de),N,Di*nn),x.push(L),C=Ti(ct(N,de),N,Di*-nn),b.push(C);M=L,A=C,tn&&(O=!0);continue}if(O=!1,F===e.length-1){let de=dt(Mi(_),w);x.push(ot(N,de)),b.push(ct(N,de));continue}let ei=dt(Mi(Ar(Gn,_,Lt)),w);L=ot(N,ei),(F<=1||Oa(M,L)>g)&&(x.push(L),M=L),C=ct(N,ei),(F<=1||Oa(A,C)>g)&&(b.push(C),A=C),y=T,I=_}let D=e[0].point.slice(0,2),Y=e.length>1?e[e.length-1].point.slice(0,2):ct(e[0].point,[1,1]),H=[],V=[];if(e.length===1){if(!(f||E)||d){let F=ka(D,Na(Mi(ot(D,Y))),-(S||w)),T=[];for(let N=1/13,_=N;_<=1;_+=N)T.push(Ti(F,D,Di*2*_));return T}}else{if(!(f||E&&e.length===1))if(c)for(let T=1/13,N=T;N<=1;N+=T){let _=Ti(b[0],D,Di*N);H.push(_)}else{let T=ot(x[0],b[0]),N=dt(T,.5),_=dt(T,.51);H.push(ot(D,N),ot(D,_),ct(D,_),ct(D,N))}let F=Mi(Wu(e[e.length-1].vector));if(E||f&&e.length===1)V.push(Y);else if(m){let T=ka(Y,F,w);for(let N=1/29,_=N;_<1;_+=N)V.push(Ti(T,Y,Di*3*_))}else V.push(ct(Y,dt(F,w)),ct(Y,dt(F,w*.99)),ot(Y,dt(F,w*.99)),ot(Y,dt(F,w)))}return x.concat(V,b.reverse(),H)}function qu(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(Ar(a[0],p,h/4))}a.length===1&&(a=[...a,[...ct(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=!1,c=0,u=l[0],m=a.length-1;for(let p=1;p<a.length;p++){let h=r&&p===m?a[p].slice(0,2):Ar(u.point,a[p],s);if(Yu(u.point,h))continue;let f=$u(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:Na(ot(u.point,h)),distance:f,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function Ra(e,t={}){return Zu(qu(e,t),t)}P();P();P();function ue([e,t,n],[i,o,r]){return[e+i,t+o,n+r]}function oi([e,t,n],[i,o,r]){return[e-i,t-o,n-r]}function be([e,t,n],i){return[e*i,t*i,n*i]}function Rn([e,t,n]){return[e/Math.sqrt(e**2+t**2),t/Math.sqrt(e**2+t**2),n]}function Se([e,t,n],i){return[Math.cos(i)*e-Math.sin(i)*t,Math.sin(i)*e+Math.cos(i)*t,n]}function za(e,t,n){return ue(e,be(oi(t,e),n))}function Mr(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 Tr(e){return Math.atan2(Math.sin(e),Math.cos(e))}function Dr([e,t]){return Math.sqrt(e**2+t**2)}function Nn([e,t],[n,i]){return Math.sqrt((n-e)**2+(i-t)**2)}function Ha(e){if(e.length<2)return 0;let t=0;for(let n=1;n<=e.length-1;n++)t+=Nn(e[n-1],e[n]);return t+=Nn(e[e.length-2],e[e.length-1]),t}var Ku=(e,t,n)=>Math.max(t,Math.min(n,e));function _a(e,t,n){let i=Nn(t,n);if(i===0)return Nn(e,t);let o=Ku(((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 Nn(r,e)}P();function vi(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=_a(l,n,i);return c>s?[c,d]:[s,a]},[0,-1]);if(o>=t){let s=e[r];return[...vi([n,...e.slice(1,r),s],t).slice(0,-1),s,...vi([s,...e.slice(r,-1),i],t).slice(1)]}return[n,i]}var po=class e{static defaults={size:2,streamline:.45,simplify:.1,simplifyPhase:"output",keepHead:!1,sizeMapping:()=>1};static constants={cornerDetectionMaxAngle:75,cornerDetectionVariance:t=>t>35?.5:1,maxTailLength:50};options;constructor(t){this.options=Object.assign({},e.defaults,t)}originalPoints=[];stablePoints=[];tailPoints=[];isFresh=!0;get lastPoint(){return this.tailPoints[this.tailPoints.length-1]??this.stablePoints[this.stablePoints.length-1]}addPoint(t){let n=this.originalPoints[this.originalPoints.length-1];if(!(n&&n[0]===t[0]&&n[1]===t[1])){if(this.originalPoints.push(t),this.isFresh){this.isFresh=!1,this.stablePoints.push(t);return}this.options.streamline>0&&(t=za(this.lastPoint,t,1-this.options.streamline)),this.tailPoints.push(t),Ha(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=vi(n,this.options.simplify));let i=n.length;if(i===0)return[];if(i===1){let I=n[0],M=this.getSize(t,I[2],0,i,0);if(M<.5)return[];let A=[];for(let L=0;L<=Math.PI*2;L+=Math.PI/16)A.push(ue(I,be(Se([1,0,0],L),M)));return A.push(ue(I,be([1,0,0],this.getSize(t,I[2],0,i,0)))),A}if(i===2){let I=n[0],M=n[1],A=this.getSize(t,I[2],0,i,0),L=this.getSize(t,M[2],0,i,0);if(A<.5||L<.5)return[];let C=[],O=Mr(I,[I[0],I[1]-100,I[2]],M);for(let D=O;D<=Math.PI+O;D+=Math.PI/16)C.push(ue(I,be(Se([1,0,0],D),A)));for(let D=Math.PI+O;D<=Math.PI*2+O;D+=Math.PI/16)C.push(ue(M,be(Se([1,0,0],D),L)));return C.push(C[0]),C}let o=[],r=[],s=0,a=0,l=0,d=0;for(let I=1;I<i-1;I++){let M=n[I-1],A=n[I],L=n[I+1],C=A[2],O=Nn(M,A);d+=O,s=a+(O-a)*.2;let D=this.getSize(t,C,I,i,d);if(D===0){l=I+1;continue}let Y=Rn(oi(M,A)),H=Rn(oi(L,A)),V=Se(Y,Math.PI/2),F=Se(Y,-Math.PI/2),T=Se(H,Math.PI/2),N=Se(H,-Math.PI/2),_=ue(A,be(V,D)),ye=ue(A,be(F,D)),nt=ue(A,be(T,D)),Qn=ue(A,be(N,D)),Jn=ue(V,N),Gn=ue(F,T),Lt=ue(A,be(Dr(Jn)===0?Y:Rn(Jn),D)),On=ue(A,be(Dr(Gn)===0?H:Rn(Gn),D)),tn=Tr(Mr(A,M,L)),ei=e.constants.cornerDetectionMaxAngle/180*Math.PI*e.constants.cornerDetectionVariance(s);if(Math.abs(tn)<ei){let de=Math.abs(Tr(Math.PI-tn));if(de===0)continue;if(tn<0){r.push(ye,On);for(let oe=0;oe<=de;oe+=de/4)o.push(ue(A,Se(be(V,D),oe)));for(let oe=de;oe>=0;oe-=de/4)r.push(ue(A,Se(be(V,D),oe)));r.push(On,nt)}else{o.push(_,Lt);for(let oe=0;oe<=de;oe+=de/4)r.push(ue(A,Se(be(V,-D),-oe)));for(let oe=de;oe>=0;oe-=de/4)o.push(ue(A,Se(be(V,-D),-oe)));o.push(Lt,Qn)}}else o.push(Lt),r.push(On);a=s}if(l>=i-2){if(this.options.keepHead){let I=n[i-1],M=[];for(let A=0;A<=Math.PI*2;A+=Math.PI/16)M.push(ue(I,be(Se([1,0,0],A),this.options.size)));return M.push(ue(I,be([1,0,0],this.options.size))),M}return[]}let c=n[l],u=n[l+1],m=n[i-2],p=n[i-1],h=Rn(oi(u,c)),f=Rn(oi(m,p)),E=Se(h,-Math.PI/2),g=Se(f,Math.PI/2),x=this.getSize(t,c[2],0,i,0),b=[],y=this.options.keepHead?this.options.size:this.getSize(t,m[2],i-2,i,d),w=[];if(x>.1){for(let I=0;I<=Math.PI;I+=Math.PI/16)b.unshift(ue(c,Se(be(E,x),-I)));b.unshift(ue(c,be(E,-x)))}else b.push(c);for(let I=0;I<=Math.PI*3;I+=Math.PI/16)w.push(ue(p,Se(be(g,-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"?vi(S,this.options.simplify):S}};import{pointFrom as me,pointDistance as kd,pointRotateRads as qt}from"@excalidraw/math";import{ROUGHNESS as Vf,THEME as Cs,isTransparent as Vi,assertNever as Zf,COLOR_PALETTE as qf,LINE_POLYGON_POINT_MERGE_DISTANCE as Kf,applyDarkModeFilter as Zi,DEFAULT_STROKE_STREAMLINE as Qf}from"@excalidraw/common";P();import{isRightAngleRads as kf,lineSegment as Bd,pointFrom as Vo,pointRotateRads as Ts}from"@excalidraw/math";import{BOUND_TEXT_PADDING as Sn,DEFAULT_REDUCED_GLOBAL_ALPHA as Ff,ELEMENT_READY_TO_ERASE_OPACITY as Nf,FRAME_STYLE as Zo,DARK_THEME_FILTER as Rf,MIME_TYPES as vs,THEME as mi,distance as An,getFontString as zf,isRTL as Hf,getVerticalOffset as _f,invariant as Wf,applyDarkModeFilter as Ko,isSafari as Uf}from"@excalidraw/common";P();import{pointFrom as Ft,pointCenter as Ju,pointRotateRads as sn,vectorFromPoint as vr,vectorNormalize as Wa,vectorSubtract as Ua,vectorAdd as fo,vectorScale as ho,pointFromVector as Ya,clamp as ve,isCloseTo as ja}from"@excalidraw/math";var Be=10,Hb=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=Br(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,h=sn(Ft(r,s),re(e,t),-e.angle);r=h[0],s=h[1];let f=e.width,E=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,b=g.width,y=e.scale[0]===-1,w=e.scale[1]===-1,S=s-e.y,I=r-e.x;n.includes("n")&&(E=ve(e.height-S,Be,w?d-p:e.height+p)),n.includes("s")&&(S=s-e.y-e.height,E=ve(e.height+S,Be,w?e.height+p:d-p)),n.includes("e")&&(I=r-e.x-e.width,f=ve(e.width+I,Be,y?e.width+m:l-m)),n.includes("w")&&(f=ve(e.width-I,Be,y?l-m:e.width+m));let M=C=>{C.height=E*u,C.width=f*c};M(g);let A=(C,O)=>{M(O),C.includes("n")&&(w||(O.y+=x-O.height)),C.includes("s")&&w&&(O.y+=x-O.height),C.includes("e")&&y&&(O.x+=b-O.width),C.includes("w")&&(y||(O.x+=b-O.width))};switch(n){case"n":{if(a){let C=m+e.width/2,O=l-m-e.width/2,D=Math.min(C,O)*2;f=ve(E*a,Be,D),E=f/a}A(n,g),a&&(g.x+=(b-g.width)/2);break}case"s":{if(a){let C=m+e.width/2,O=l-m-e.width/2,D=Math.min(C,O)*2;f=ve(E*a,Be,D),E=f/a}A(n,g),a&&(g.x+=(b-g.width)/2);break}case"w":{if(a){let C=p+e.height/2,O=d-p-e.height/2,D=Math.min(C,O)*2;E=ve(f/a,Be,D),f=E*a}A(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let C=p+e.height/2,O=d-p-e.height/2,D=Math.min(C,O)*2;E=ve(f/a,Be,D),f=E*a}A(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(I>-S){let C=w?d-p:p+e.height;E=ve(f/a,Be,C),f=E*a}else{let C=y?m+e.width:l-m;f=ve(E*a,Be,C),E=f/a}A(n,g);break}case"nw":{if(a)if(I<S){let C=w?d-p:p+e.height;E=ve(f/a,Be,C),f=E*a}else{let C=y?l-m:m+e.width;f=ve(E*a,Be,C),E=f/a}A(n,g);break}case"se":{if(a)if(I>S){let C=w?p+e.height:d-p;E=ve(f/a,Be,C),f=E*a}else{let C=y?m+e.width:l-m;f=ve(E*a,Be,C),E=f/a}A(n,g);break}case"sw":{if(a)if(-I>S){let C=w?p+e.height:d-p;E=ve(f/a,Be,C),f=E*a}else{let C=y?l-m:m+e.width;f=ve(E*a,Be,C),E=f/a}A(n,g);break}default:break}let L=em(e,n,f,E,!!a);return ja(g.width,g.naturalWidth)&&ja(g.height,g.naturalHeight)&&(g=null),{x:L[0],y:L[1],width:f,height:E,crop:g}},em=(e,t,n,i,o)=>{let[r,s,a,l]=an(e,e.width,e.height,!0),d=Ft(r,s),c=Ft(a,l),u=Ju(d,c),[m,p,h,f]=an(e,n,i,!0),E=h-m,g=f-p,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(E),c[1]-Math.abs(g)]),t==="ne"){let M=[d[0],c[1]];x=[M[0],M[1]-Math.abs(g)]}if(t==="sw"){let M=[c[0],d[1]];x=[M[0]-Math.abs(E),M[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-E/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let b=e.angle,y=sn(x,u,b),w=[x[0]+Math.abs(E)/2,x[1]+Math.abs(g)/2],S=sn(w,u,b);x=sn(y,S,-b);let I=[...x];return I[0]+=e.x-m,I[1]+=e.y-p,I},Xa=(e,t)=>{if(e.crop){let{width:n,height:i}=Br(e),[o,r,s,a,l,d]=$(e,t),c=vr(sn(Ft(o,r),Ft(l,d),e.angle)),u=vr(sn(Ft(s,r),Ft(l,d),e.angle)),m=Wa(Ua(u,c)),p=vr(sn(Ft(o,a),Ft(l,d),e.angle)),h=Ua(p,c),f=Wa(h),{cropX:E,cropY:g}=tm(e.crop,e.scale),x=fo(fo(c,ho(m,-E*n/e.crop.naturalWidth)),ho(f,-g*i/e.crop.naturalHeight)),b=Ya(fo(fo(x,ho(m,n/2)),ho(f,i/2))),y=sn(Ya(x),b,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},Br=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}},tm=(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}},_b=(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}=Br(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as nd,pointFrom as k,pointRotateRads as Ne,pointsEqual as id,pointDistance as Xn,vectorFromPoint as ef,curveLength as tf,curvePointAtLength as nf}from"@excalidraw/math";import{DRAGGING_THRESHOLD as of,KEYS as jn,shouldRotateWithDiscreteAngle as Yi,getGridPoint as od,invariant as $e,isShallowEqual as rf,getFeatureFlag as ci}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as rd,getSnapOutlineMidPoint as sd,isPathALoop as sf,moveArrowAboveBindable as ad,projectFixedPointOntoDiagonal as ld}from"@excalidraw/element";P();import{arrayToMap as Zl,getFeatureFlag as Op,invariant as Zt,isTransparent as kp}from"@excalidraw/common";import{PRECISION as Fp,clamp as _o,lineSegment as Ho,pointDistance as En,pointDistanceSq as Vt,pointFrom as ie,pointFromVector as Ro,pointRotateRads as le,pointsEqual as Np,vectorFromPoint as _i,vectorNormalize as ms,vectorScale as zo}from"@excalidraw/math";P();import{invariant as Il,isTransparent as Sl}from"@excalidraw/common";import{curveIntersectLineSegment as Al,isPointWithinBounds as qr,lineSegment as Ni,lineSegmentIntersectionPoints as Ml,pointFrom as we,pointFromVector as ep,pointRotateRads as Je,pointsEqual as Tl,vectorFromPoint as tp,vectorNormalize as np,vectorScale as ip}from"@excalidraw/math";import{ellipse as op,ellipseSegmentInterceptPoints as rp}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as dm,DEFAULT_PROPORTIONAL_RADIUS as Cr,invariant as cm,LINE_CONFIRM_THRESHOLD as um,ROUNDNESS as Gr}from"@excalidraw/common";import{bezierEquation as mm,curve as Rt,curveCatmullRomCubicApproxPoints as il,curveOffsetPoints as ol,lineSegment as Pe,lineSegmentIntersectionPoints as tl,pointDistance as Hn,pointFrom as z,pointFromArray as pm,pointFromVector as fm,pointRotateRads as Ke,pointTranslate as nl,rectangle as hm,vectorFromPoint as rl,vectorNormalize as Em,vectorScale as Or}from"@excalidraw/math";P();import{ROUNDNESS as Bi,assertNever as nm}from"@excalidraw/common";import{pointsEqual as $a}from"@excalidraw/math";var zn=e=>!!e&&e.type==="image"&&!!e.fileId,Ae=e=>!!e&&e.type==="image",Va=e=>!!e&&e.type==="embeddable",Eo=e=>!!e&&e.type==="iframe",go=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),K=e=>e!=null&&e.type==="text",xo=e=>e!=null&&e.type==="frame",Za=e=>e!=null&&e.type==="magicframe",Z=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Ie=e=>e!=null&&im(e.type),im=e=>e==="freedraw",Q=e=>e!=null&&sm(e.type),Nt=e=>e!=null&&e.type==="line",W=e=>e!=null&&e.type==="arrow",U=e=>W(e)&&e.elbowed,Xb=e=>W(e)&&!e.elbowed,om=e=>W(e)&&!e.elbowed&&!e.roundness,rm=e=>W(e)&&!e.elbowed&&e.roundness!==null,sm=e=>e==="arrow"||e==="line",Le=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&am(e.type),am=e=>e==="arrow",fe=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),qa=e=>e!=null&&(e.type==="rectangle"||e.type==="diamond"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),Li=e=>e!=null&&(e.type==="rectangle"||e.type==="image"||e.type==="text"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="freedraw"),lm=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||W(e)),Ka=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 nm(t,null),!1}},Lr=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",yt=e=>lm(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),he=e=>e!==null&&"containerId"in e&&e.containerId!==null&&K(e),$b=e=>!!e.startBinding||!!e.endBinding,Qa=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",Ja=e=>e==="line"||e==="arrow"||e==="diamond",Vb=(e,t)=>!!((e===Bi.ADAPTIVE_RADIUS||e===Bi.LEGACY)&&Qa(t.type)||e===Bi.PROPORTIONAL_RADIUS&&Ja(t.type)),Zb=e=>Ja(e.type)?{type:Bi.PROPORTIONAL_RADIUS}:Qa(e.type)?{type:Bi.ADAPTIVE_RADIUS}:null,qb=e=>om(e)?"sharpArrow":rm(e)?"curvedArrow":U(e)?"elbowArrow":"line",Kb=e=>e.length>3&&$a(e[0],e[e.length-1]),el=e=>e.length>3||e.length===3&&!$a(e[0],e[e.length-1]),Qb=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 Ci=new WeakMap,kr=(e,t)=>{let n=Ci.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){Ci.delete(e);return}return o.get(t)},Fr=(e,t,n)=>{let i=Ci.get(e);if(!i){Ci.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){Ci.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function bo(e,t){let n=kr(e,0);if(n)return n;let i=al(e,t),o=[],r=[];for(let a=0;a<i.length;a+=1){let l=i[a],d=i[a-1]&&pm(i[a-1].data.slice(-2));switch(l.op){case"move":continue;case"lineTo":if(!d)throw new Error("prevPoint is undefined");o.push(Pe(z(e.x+d[0],e.y+d[1]),z(e.x+l.data[0],e.y+l.data[1])));continue;case"bcurveTo":if(!d)throw new Error("prevPoint is undefined");r.push(Rt(z(e.x+d[0],e.y+d[1]),z(e.x+l.data[0],e.y+l.data[1]),z(e.x+l.data[2],e.y+l.data[3]),z(e.x+l.data[4],e.y+l.data[5])));continue;default:console.error("Unknown op type",l.op)}}let s=[o,r];return Fr(e,s,0),s}function ln(e,t=0){let n=kr(e,t);if(n)return n;let i=zt(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=hm(z(e.x,e.y),z(e.x+e.width,e.y+e.height)),r=Pe(z(o[0][0]+i,o[0][1]),z(o[1][0]-i,o[0][1])),s=Pe(z(o[1][0],o[0][1]+i),z(o[1][0],o[1][1]-i)),a=Pe(z(o[0][0]+i,o[1][1]),z(o[1][0]-i,o[1][1])),l=Pe(z(o[0][0],o[1][1]-i),z(o[0][0],o[0][1]+i)),d=[Rt(l[1],z(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),z(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),Rt(r[1],z(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),z(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),Rt(s[1],z(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),z(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),Rt(a[0],z(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),z(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],c=t>0?d.map(p=>il(ol(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[Pe(c[0][c[0].length-1][3],c[1][0][0]),Pe(c[1][c[1].length-1][3],c[2][0][0]),Pe(c[2][c[2].length-1][3],c[3][0][0]),Pe(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Fr(e,m,t),m}function sl(e,t=0){let[n,i,o,r,s,a,l,d]=ri(e),c=e.roundness?zt(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?zt(Math.abs(r-i),e):(r-i)*.01,[m,p,h,f]=[z(e.x+n,e.y+i),z(e.x+o,e.y+r),z(e.x+s,e.y+a),z(e.x+l,e.y+d)];return[Rt(z(p[0]-c,p[1]-u),p,p,z(p[0]-c,p[1]+u)),Rt(z(h[0]+c,h[1]-u),h,h,z(h[0]-c,h[1]-u)),Rt(z(f[0]+c,f[1]+u),f,f,z(f[0]+c,f[1]-u)),Rt(z(m[0]-c,m[1]+u),m,m,z(m[0]+c,m[1]+u))]}function dn(e,t=0){let n=kr(e,t);if(n)return n;let o=sl(e,t).map(a=>il(ol(a,t))),s=[[Pe(o[0][o[0].length-1][3],o[1][0][0]),Pe(o[1][o[1].length-1][3],o[2][0][0]),Pe(o[2][o[2].length-1][3],o[3][0][0]),Pe(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return Fr(e,s,t),s}var _n=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return Hn(n,i)<=um/t}return!1},zt=(e,t)=>{if(t.roundness?.type===Gr.PROPORTIONAL_RADIUS||t.roundness?.type===Gr.LEGACY)return e*Cr;if(t.roundness?.type===Gr.ADAPTIVE_RADIUS){let n=t.roundness?.value??dm,i=n/Cr;return e<=i?e*Cr:n}return 0},gm=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=Em(rl(a[1],a[0])),d=Or(l,n);return Pe(nl(a[0],d),nl(a[1],Or(d,-1)))},o=re(e,t),r=i(Li(e)?Pe(Ke(z(e.x,e.y),o,e.angle),Ke(z(e.x+e.width,e.y+e.height),o,e.angle)):Pe(Ke(z(e.x+e.width/2,e.y),o,e.angle),Ke(z(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(Li(e)?Pe(Ke(z(e.x+e.width,e.y),o,e.angle),Ke(z(e.x,e.y+e.height),o,e.angle)):Pe(Ke(z(e.x,e.y+e.height/2),o,e.angle),Ke(z(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},xm=(e,t,n,i)=>{let o=re(t,n);return(t.type==="diamond"?sl(t).map(a=>{let l=mm(a,.5),d=Ke(l,o,t.angle);return z(d[0],d[1])}):[Ke(z(t.x+t.width,t.y+t.height/2),o,t.angle),Ke(z(t.x+t.width/2,t.y+t.height),o,t.angle),Ke(z(t.x,t.y+t.height/2),o,t.angle),Ke(z(t.x+t.width/2,t.y),o,t.angle)]).find(a=>Hn(e,a)<=ut(i)+t.strokeWidth/2&&!Pt({point:e,element:t,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))},Nr=(e,t,n,i,o,r,s=!0)=>{if(cm(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;if(s){let g=xm(t,n,o,r);if(g)return g}let[a,l]=gm(n,o),d=G.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o);if(e.points.length===2){let g=i==="start"?e.endBinding:e.startBinding,x=g&&o.get(g.elementId),b=g&&x&&We(It(g.fixedPoint),x,o);b&&(d=b)}let c=fm(Or(rl(t,d),2*Hn(d,t)+Math.max(Hn(a[0],a[1]),Hn(l[0],l[1]))),d),u=Pe(c,d),m=tl(a,u),p=tl(l,u),h=m&&Hn(d,m),f=p&&Hn(d,p),E=null;return h!=null&&f!=null?E=h<f?m:p:E=m||p||null,E&&Ht(E,n,o)?E:null};P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as _m,ARROW_LABEL_WIDTH_FRACTION as Wm,BOUND_TEXT_PADDING as St,DEFAULT_FONT_SIZE as Um,TEXT_ALIGN as fl,VERTICAL_ALIGN as hl,getFontString as Ao,isProdEnv as Ym,invariant as jm}from"@excalidraw/common";import{pointFrom as El,pointRotateRads as Xm}from"@excalidraw/math";P();var Gi={},ll=(e,t)=>{let n=Gi[e]||(Gi[e]={height:t});return n.height=t,n},dl=e=>{Gi[e]&&delete Gi[e]},mw=e=>Gi[e]?.height??null;P();import{BOUND_TEXT_PADDING as yo,DEFAULT_FONT_SIZE as bm,DEFAULT_FONT_FAMILY as wm,getFontString as ym,isTestEnv as Pm,normalizeEOL as Im}from"@excalidraw/common";var Qe=(e,t,n)=>{let i=e.split(`
1
+ var yu=Object.create;var ba=Object.defineProperty;var Pu=Object.getOwnPropertyDescriptor;var Iu=Object.getOwnPropertyNames;var Su=Object.getPrototypeOf,Au=Object.prototype.hasOwnProperty;var Mu=(e,t)=>()=>(e&&(t=e(e=0)),t);var Tu=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Du=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Iu(t))!Au.call(e,o)&&o!==n&&ba(e,o,{get:()=>t[o],enumerable:!(i=Pu(t,o))||i.enumerable});return e};var vu=(e,t,n)=>(n=e!=null?yu(Su(e)):{},Du(t||!e||!e.__esModule?ba(n,"default",{value:e,enumerable:!0}):n,e));var B,P=Mu(()=>{B={PROD:!0}});var Sc=Tu((XS,Ic)=>{P();var Pc="Expected a function",wc=NaN,yE="[object Symbol]",PE=/^\s+|\s+$/g,IE=/^[-+]0x[0-9a-f]+$/i,SE=/^0b[01]+$/i,AE=/^0o[0-7]+$/i,ME=parseInt,TE=typeof global=="object"&&global&&global.Object===Object&&global,DE=typeof self=="object"&&self&&self.Object===Object&&self,vE=TE||DE||Function("return this")(),BE=Object.prototype,LE=BE.toString,CE=Math.max,GE=Math.min,Qs=function(){return vE.Date.now()};function NE(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(Pc);t=yc(t)||0,lr(n)&&(c=!!n.leading,u="maxWait"in n,r=u?CE(yc(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(S){var I=i,M=o;return i=o=void 0,d=S,s=e.apply(M,I),s}function h(S){return d=S,a=setTimeout(g,t),c?p(S):s}function f(S){var I=S-l,M=S-d,A=t-I;return u?GE(A,r-M):A}function E(S){var I=S-l,M=S-d;return l===void 0||I>=t||I<0||u&&M>=r}function g(){var S=Qs();if(E(S))return x(S);a=setTimeout(g,f(S))}function x(S){return a=void 0,m&&i?p(S):(i=o=void 0,s)}function b(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function y(){return a===void 0?s:x(Qs())}function w(){var S=Qs(),I=E(S);if(i=arguments,o=this,l=S,I){if(a===void 0)return h(l);if(u)return a=setTimeout(g,t),p(l)}return a===void 0&&(a=setTimeout(g,t)),s}return w.cancel=b,w.flush=y,w}function OE(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(Pc);return lr(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),NE(e,t,{leading:i,maxWait:t,trailing:o})}function lr(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function kE(e){return!!e&&typeof e=="object"}function FE(e){return typeof e=="symbol"||kE(e)&&LE.call(e)==yE}function yc(e){if(typeof e=="number")return e;if(FE(e))return wc;if(lr(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=lr(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(PE,"");var n=SE.test(e);return n||AE.test(e)?ME(e.slice(2),n?2:8):IE.test(e)?wc:+e}Ic.exports=OE});P();import{toIterable as Ux}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as en,viewportCoordsToSceneCoords as nr}from"@excalidraw/common";import{normalizeRadians as ic,radiansBetweenAngles as Fh,radiansDifference as Rh}from"@excalidraw/math";import{pointsEqual as zh}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function wr(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 Lu(e,t,n){let i=[];e.forEach(o=>i.push(...o)),wr(i,t,n)}function Cu(e,t){return e[0]===t[0]&&e[1]===t[1]}function wa(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)wr(d,a,o);let l=Gu(s,r,i);if(o){for(let d of s)wr(d,a,-o);Lu(l,a,-o)}return l}function Gu(e,t,n){let i=[];for(let d of e){let c=[...d];Cu(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 Mt(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),wa(e,o,i,r||1)}var sn=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=Mt(t,n);return{type:"fillSketch",ops:this.renderLines(i,n)}}renderLines(t,n){let i=[];for(let o of t)i.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return i}};P();P();function an(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 Ji=class extends sn{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=Mt(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)an([u,m])&&a.push([[u[0]-l,u[1]+d],[...m]],[[u[0]+l,u[1]-d],[...m]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var eo=class extends sn{fillPolygons(t,n){let i=this._fillPolygons(t,n),o=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),r=this._fillPolygons(t,o);return i.ops=i.ops.concat(r.ops),i}};P();var to=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=Mt(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=an(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,E=m-s+Math.random()*2*s,g=f-s+Math.random()*2*s,x=this.helper.ellipse(E,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var no=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=Mt(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=an(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,E=[c[0]+h*Math.cos(m)+d*Math.cos(m),c[1]+h*Math.sin(m)+d*Math.sin(m)],g=[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(E[0],E[1],g[0],g[1],n))}}),r}};P();var io=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=Mt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=an(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)],E=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],g=[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],g[0],g[1],i),...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],i))}}),o}};var Ve={};function ya(e,t){let n=e.fillStyle||"hachure";if(!Ve[n])switch(n){case"zigzag":Ve[n]||(Ve[n]=new Ji(t));break;case"cross-hatch":Ve[n]||(Ve[n]=new eo(t));break;case"dots":Ve[n]||(Ve[n]=new to(t));break;case"dashed":Ve[n]||(Ve[n]=new no(t));break;case"zigzag-line":Ve[n]||(Ve[n]=new io(t));break;case"hachure":default:n="hachure",Ve[n]||(Ve[n]=new sn(t));break}return Ve[n]}P();function Pa(){return Math.floor(Math.random()*2**31)}var oo=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};P();P();var ro={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 Nu(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 yr(e,t){return e.type===t}function ni(e){let t=[],n=Nu(e),i="BOD",o=0,r=n[o];for(;!yr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=ro[r.text],i=r.text;else return ni("M0,0"+e);else yr(r,1)?s=ro[i]:(o++,s=ro[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(yr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof ro[i]=="number"){let l={key:i,data:a};t.push(l),o+=s,r=n[o],i==="M"&&(i="L"),i==="m"&&(i="l")}else throw new Error("Bad segment: "+i)}else throw new Error("Path data ended short")}return t}P();function Si(e){let t=0,n=0,i=0,o=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[i,o]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),i=t,o=n;break;case"L":r.push({key:"L",data:[...a]}),[t,n]=a;break;case"l":t+=a[0],n+=a[1],r.push({key:"L",data:[t,n]});break;case"C":r.push({key:"C",data:[...a]}),t=a[4],n=a[5];break;case"c":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":r.push({key:"Q",data:[...a]}),t=a[2],n=a[3];break;case"q":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":r.push({key:"A",data:[...a]}),t=a[5],n=a[6];break;case"a":t+=a[5],n+=a[6],r.push({key:"A",data:[a[0],a[1],a[2],a[3],a[4],t,n]});break;case"H":r.push({key:"H",data:[...a]}),t=a[0];break;case"h":t+=a[0],r.push({key:"H",data:[t]});break;case"V":r.push({key:"V",data:[...a]}),n=a[0];break;case"v":n+=a[0],r.push({key:"V",data:[n]});break;case"S":r.push({key:"S",data:[...a]}),t=a[2],n=a[3];break;case"s":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=i,n=o;break}return r}P();function Mi(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,E=o+2*(h-o)/3,g=u+2*(p-u)/3,x=m+2*(h-m)/3;t.push({key:"C",data:[f,E,g,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,E=o+2*(m-o)/3,g=p+2*(u-p)/3,x=h+2*(m-h)/3;t.push({key:"C",data:[f,E,g,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],E=c[5],g=c[6];u===0||m===0?(t.push({key:"C",data:[i,o,E,g,E,g]}),i=E,o=g):(i!==E||o!==g)&&(Ia(i,o,E,g,u,m,p,h,f).forEach(function(b){t.push({key:"C",data:b})}),i=E,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function Ou(e){return Math.PI*e/180}function Ai(e,t,n){let i=e*Math.cos(n)-t*Math.sin(n),o=e*Math.sin(n)+t*Math.cos(n);return[i,o]}function Ia(e,t,n,i,o,r,s,a,l,d){let c=Ou(s),u=[],m=0,p=0,h=0,f=0;if(d)[m,p,h,f]=d;else{[e,t]=Ai(e,t,-c),[n,i]=Ai(n,i,-c);let N=(e-n)/2,D=(t-i)/2,j=N*N/(o*o)+D*D/(r*r);j>1&&(j=Math.sqrt(j),o=j*o,r=j*r);let H=a===l?-1:1,Z=o*o,k=r*r,T=Z*k-Z*D*D-k*N*N,F=Z*D*D+k*N*N,U=H*Math.sqrt(Math.abs(T/F));h=U*o*D/r+(e+n)/2,f=U*-r*N/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 E=p-m;if(Math.abs(E)>Math.PI*120/180){let N=p,D=n,j=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=Ia(n,i,D,j,o,r,s,0,l,[p,N,h,f])}E=p-m;let g=Math.cos(m),x=Math.sin(m),b=Math.cos(p),y=Math.sin(p),w=Math.tan(E/4),S=4/3*o*w,I=4/3*r*w,M=[e,t],A=[e+S*x,t-I*g],G=[n+S*y,i-I*b],L=[n,i];if(A[0]=2*M[0]-A[0],A[1]=2*M[1]-A[1],d)return[A,G,L].concat(u);{u=[A,G,L].concat(u);let N=[];for(let D=0;D<u.length;D+=3){let j=Ai(u[D][0],u[D][1],c),H=Ai(u[D+1][0],u[D+1][1],c),Z=Ai(u[D+2][0],u[D+2][1],c);N.push([j[0],j[1],H[0],H[1],Z[0],Z[1]])}return N}}var ku={randOffset:zu,randOffsetWithRange:Hu,ellipse:Ru,doubleLineOps:_u};function Pr(e,t,n,i,o){return{type:"path",ops:Rt(e,t,n,i,o)}}function Ti(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Rt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Rt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return Pr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Fu(e,t){return Ti(e,!0,t)}function Da(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Fu(r,o)}function Ir(e,t){let n=Aa(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=Aa(e,1.5*(1+t.roughness*.22),Wu(t));n=n.concat(i)}return{type:"path",ops:n}}function Ru(e,t,n,i,o){let r=Sr(n,i,o);return lo(e,t,o,r).opset}function Sr(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=R(s*l,n),a+=R(a*l,n),{increment:r,rx:s,ry:a}}function lo(e,t,n,i){let[o,r]=Ma(i.increment,e,t,i.rx,i.ry,1,i.increment*so(.1,so(.4,1,n),n),n),s=ao(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=Ma(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=ao(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Ar(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),m=Math.abs(i/2);u+=R(u*.01,l),m+=R(m*.01,l);let p=o,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,E=Math.min(f/2,(h-p)/2),g=Ta(E,d,c,u,m,p,h,1,l);if(!l.disableMultiStroke){let x=Ta(E,d,c,u,m,p,h,1.5,l);g.push(...x)}return s&&(a?g.push(...Rt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...Rt(d,c,d+u*Math.cos(h),c+m*Math.sin(h),l)):g.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(p),c+m*Math.sin(p)]})),{type:"path",ops:g}}function Mr(e,t){let n=Mi(Si(ni(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(...Rt(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(...Uu(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...Rt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function co(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+R(o,t),i[0][1]+R(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+R(o,t),i[s][1]+R(o,t)]})}}return{type:"fillPath",ops:n}}function kn(e,t){return ya(t,ku).fillPolygons(e,t)}function va(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=R(d*.01,s),c+=R(c*.01,s);let u=o,m=r;for(;u<0;)u+=Math.PI*2,m+=Math.PI*2;m-u>Math.PI*2&&(u=0,m=Math.PI*2);let p=(m-u)/s.curveStepCount,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]),kn([h],s)}function zu(e,t){return R(e,t)}function Hu(e,t,n){return so(e,t,n)}function _u(e,t,n,i,o){return Rt(e,t,n,i,o,!0)}function Wu(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Ba(e){return e.randomizer||(e.randomizer=new oo(e.seed||0)),e.randomizer.next()}function so(e,t,n,i=1){return n.roughness*i*(Ba(n)*(t-e)+e)}function R(e,t,n=1){return so(-e,e,t,n)}function Rt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=Sa(e,t,n,i,o,!0,!1);if(s)return a;let l=Sa(e,t,n,i,o,!0,!0);return a.concat(l)}function Sa(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+Ba(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,h=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=R(p,o,d),h=R(h,o,d);let f=[],E=()=>R(u,o,d),g=()=>R(c,o,d),x=o.preserveVertices;return r&&(s?f.push({op:"move",data:[e+(x?0:E()),t+(x?0:E())]}):f.push({op:"move",data:[e+(x?0:R(c,o,d)),t+(x?0:R(c,o,d))]})),s?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.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}function Aa(e,t,n){let i=[];i.push([e[0][0]+R(t,n),e[0][1]+R(t,n)]),i.push([e[0][0]+R(t,n),e[0][1]+R(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+R(t,n),e[o][1]+R(t,n)]),o===e.length-1&&i.push([e[o][0]+R(t,n),e[o][1]+R(t,n)]);return ao(i,null,n)}function ao(e,t,n){let i=e.length,o=[];if(i>3){let r=[],s=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<i;a++){let l=e[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*e[a+1][0]-s*e[a-1][0])/6,l[1]+(s*e[a+1][1]-s*e[a-1][1])/6],r[2]=[e[a+1][0]+(s*e[a][0]-s*e[a+2][0])/6,e[a+1][1]+(s*e[a][1]-s*e[a+2][1])/6],r[3]=[e[a+1][0],e[a+1][1]],o.push({op:"bcurveTo",data:[r[1][0],r[1][1],r[2][0],r[2][1],r[3][0],r[3][1]]})}if(t&&t.length===2){let a=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+R(a,n),t[1]+R(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...Rt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function Ma(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let m=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(m),c.push(m)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=R(.5,a)-Math.PI/2;c.push([R(r,a)+t+.9*i*Math.cos(u-e),R(r,a)+n+.9*o*Math.sin(u-e)]);let m=Math.PI*2+u-.01;for(let p=u;p<m;p=p+e){let h=[R(r,a)+t+i*Math.cos(p),R(r,a)+n+o*Math.sin(p)];d.push(h),c.push(h)}c.push([R(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),R(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([R(r,a)+t+.98*i*Math.cos(u+s),R(r,a)+n+.98*o*Math.sin(u+s)]),c.push([R(r,a)+t+.9*i*Math.cos(u+s*.5),R(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function Ta(e,t,n,i,o,r,s,a,l){let d=r+R(.1,l),c=[];c.push([R(a,l)+t+.9*i*Math.cos(d-e),R(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([R(a,l)+t+i*Math.cos(u),R(a,l)+n+o*Math.sin(u)]);return c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),ao(c,null,l)}function Uu(e,t,n,i,o,r,s,a){let l=[],d=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],c=[0,0],u=a.disableMultiStroke?1:2,m=a.preserveVertices;for(let p=0;p<u;p++)p===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(m?0:R(d[0],a)),s[1]+(m?0:R(d[0],a))]}),c=m?[o,r]:[o+R(d[p],a),r+R(d[p],a)],l.push({op:"bcurveTo",data:[e+R(d[p],a),t+R(d[p],a),n+R(d[p],a),i+R(d[p],a),c[0],c[1]]});return l}P();function Di(e){return[...e]}function La(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(Di(e[0]),Di(e[1]),Di(e[2]),Di(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(Di(o[0]));for(let a=1;a+2<o.length;a++){let l=o[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*o[a+1][0]-s*o[a-1][0])/6,l[1]+(s*o[a+1][1]-s*o[a-1][1])/6],r[2]=[o[a+1][0]+(s*o[a][0]-s*o[a+2][0])/6,o[a+1][1]+(s*o[a][1]-s*o[a+2][1])/6],r[3]=[o[a+1][0],o[a+1][1]],i.push(r[1],r[2],r[3])}}return i}P();function Yu(e,t){return Math.sqrt(uo(e,t))}function uo(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function ju(e,t,n){let i=uo(t,n);if(i===0)return uo(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)),uo(e,Fn(t,n,o))}function Fn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Xu(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 Tr(e,t,n,i){let o=i||[];if(Xu(e,t)<n){let r=e[t+0];o.length?Yu(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=Fn(s,a,.5),u=Fn(a,l,.5),m=Fn(l,d,.5),p=Fn(c,u,.5),h=Fn(u,m,.5),f=Fn(p,h,.5);Tr([s,c,p,f],0,n,o),Tr([f,h,m,d],0,n,o)}return o}function vi(e,t){return mo(e,0,e.length,t)}function mo(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=ju(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(mo(e,t,d+1,i,r),mo(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function zt(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;Tr(e,s,t,i)}return n&&n>0?mo(i,0,i.length,n):i}P();function Ca(e,t,n){let i=ni(e),o=Mi(Si(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...zt(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=vi(m,n);p.length&&u.push(p)}return u}var tt="none",lt=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 Pa()}_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",[Pr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=Da(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(co([d],s)):a.push(kn([d],s))}return s.stroke!==tt&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=Sr(i,o,s),d=lo(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=lo(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(kn([d.estimatedPoints],s));return s.stroke!==tt&&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",[Ti(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=Ar(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=Ar(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(va(t,n,i,o,r,s,d));return d.stroke!==tt&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=Ir(t,i);if(i.fill&&i.fill!==tt&&t.length>=3)if(i.fillStyle==="solid"){let s=Ir(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=La(t),a=zt(s,10,(1+i.roughness)/2);o.push(kn([a],i))}return i.stroke!==tt&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=Ti(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(co([t],i)):o.push(kn([t],i))),i.stroke!==tt&&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!==tt,s=i.stroke!==tt,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=Ca(t,1,l),c=Mr(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=Mr(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(co(d,i));else o.push(kn(d,i));return s&&(a?d.forEach(u=>{o.push(Ti(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:tt};break;case"fillPath":s={d:this.opsToPath(r),stroke:tt,strokeWidth:0,fill:i.fill||tt};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||tt,strokeWidth:i,fill:tt}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var po=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new lt(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":o.save(),o.strokeStyle=i.stroke==="none"?"transparent":i.stroke,o.lineWidth=i.strokeWidth,i.strokeLineDash&&o.setLineDash(i.strokeLineDash),i.strokeLineDashOffset&&(o.lineDashOffset=i.strokeLineDashOffset),this._drawToContext(o,s,r),o.restore();break;case"fillPath":{o.save(),o.fillStyle=i.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,s,r,a),o.restore();break}case"fillSketch":this.fillSketch(o,s,i);break}}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2),t.save(),i.fillLineDash&&t.setLineDash(i.fillLineDash),i.fillLineDashOffset&&(t.lineDashOffset=i.fillLineDashOffset),t.strokeStyle=i.fill||"",t.lineWidth=o,this._drawToContext(t,n,i.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,i,o="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof i=="number"&&i>=0?r.data.map(a=>+a.toFixed(i)):r.data;switch(r.op){case"move":t.moveTo(s[0],s[1]);break;case"bcurveTo":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"lineTo":t.lineTo(s[0],s[1]);break}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s),s}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s),s}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s),s}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r),r}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i),i}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i),i}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d),d}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i),i}path(t,n){let i=this.gen.path(t,n);return this.draw(i),i}};P();P();var Bi="http://www.w3.org/2000/svg";var fo=class{constructor(t,n){this.svg=t,this.gen=new lt(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(Bi,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(Bi,"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(Bi,"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(Bi,"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 ii={canvas(e,t){return new po(e,t)},svg(e,t){return new fo(e,t)},generator(e){return new lt(e)},newSeed(){return lt.newSeed()}};import{arrayToMap as tc,invariant as _s,rescalePoints as qd,sizeOf as Mh}from"@excalidraw/common";import{degreesToRadians as Hs,lineSegment as Ee,pointFrom as v,pointFromArray as nc,pointRotateRads as ee}from"@excalidraw/math";P();import{invariant as Vu}from"@excalidraw/common";import{curve as $u,lineSegment as Zu,pointFrom as me,pointDistance as Tw,pointFromArray as qu,pointFromVector as Ku,pointRotateRads as pt,polygon as Ga,polygonFromPoints as Dr,PRECISION as Dw,segmentsIntersectAt as vw,vector as Qu,vectorAdd as Ju,vectorFromPoint as em,vectorScale as Bw}from"@excalidraw/math";import{getElementAbsoluteCoords as Cw}from"@excalidraw/element";var Na=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=me(s,a),d;return e.type==="diamond"?d=Ga(pt(me(s,r),l,t),pt(me(o+n,a),l,t),pt(me(s,r+i),l,t),pt(me(o,a),l,t)):d=Ga(pt(me(o,r),l,t),pt(me(o+n,r),l,t),pt(me(o+n,r+i),l,t),pt(me(o,r+i),l,t)),{type:"polygon",data:d}};var Oa=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:me(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},Ht=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},ka=(e,t=me(0,0),n,i)=>{let o=l=>pt(me(l[0]+t[0],l[1]+t[1]),i,n),r=Ht(e),s=[],a=me(0,0);for(let l of r){if(l.op==="move"){let d=qu(l.data);Vu(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(me(l.data[0],l.data[1])),c=o(me(l.data[2],l.data[3])),u=o(me(l.data[4],l.data[5]));s.push($u(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},tm=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Zu(t,o)),t=o}return n},Fa=(e,t,n=!1)=>{let i=r=>pt(Ku(Ju(em(r),Qu(e.x,e.y))),t,e.angle),o=tm(e.points.map(r=>i(r)));return n?{type:"polygon",data:Dr(o.flat())}:{type:"polyline",data:o}},Ra=(e,t,n=me(0,0),i,o)=>{let r=c=>pt(me(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:Dr(e.points.map(c=>r(c)))};let s=Ht(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(me(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(me(c.data[0],c.data[1])),a.push(me(c.data[2],c.data[3])),a.push(me(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(me(c.data[0],c.data[1]));let d=zt(a,10,5).map(c=>r(c));return{type:"polygon",data:Dr(d)}};P();P();function za(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function nm(e){return[-e[0],-e[1]]}function ht(e,t){return[e[0]+t[0],e[1]+t[1]]}function dt(e,t){return[e[0]-t[0],e[1]-t[1]]}function ft(e,t){return[e[0]*t,e[1]*t]}function im(e,t){return[e[0]/t,e[1]/t]}function Li(e){return[e[1],-e[0]]}function Ha(e,t){return e[0]*t[0]+e[1]*t[1]}function om(e,t){return e[0]===t[0]&&e[1]===t[1]}function rm(e){return Math.hypot(e[0],e[1])}function sm(e){return e[0]*e[0]+e[1]*e[1]}function _a(e,t){return sm(dt(e,t))}function Ya(e){return im(e,rm(e))}function am(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function Ci(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 ht(e,ft(dt(t,e),n))}function Wa(e,t,n){return ht(e,ft(t,n))}var{min:oi,PI:lm}=Math,Ua=.275,Gi=lm+1e-4;function dm(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=k=>k,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=k=>k*(2-k)}=a,{cap:m=!0,easing:p=k=>--k*k*k+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,E=l.taper===!1?0:l.taper===!0?Math.max(n,h):l.taper,g=Math.pow(n*i,2),x=[],b=[],y=e.slice(0,10).reduce((k,T)=>{let F=T.pressure;if(r){let U=oi(1,T.distance/n),ge=oi(1,1-U);F=oi(1,k+(ge-k)*(U*Ua))}return(k+F)/2},e[0].pressure),w=za(n,o,e[e.length-1].pressure,s),S,I=e[0].vector,M=e[0].point,A=M,G=M,L=A,N=!1;for(let k=0;k<e.length;k++){let{pressure:T}=e[k],{point:F,vector:U,distance:ge,runningLength:at}=e[k];if(k<e.length-1&&h-at<3)continue;if(o){if(r){let ue=oi(1,ge/n),oe=oi(1,1-ue);T=oi(1,y+(oe-y)*(ue*Ua))}w=za(n,o,T,s)}else w=n/2;S===void 0&&(S=w);let Jn=at<f?u(at/f):1,ei=h-at<E?p((h-at)/E):1;w=Math.max(.01,w*Math.min(Jn,ei));let Nn=(k<e.length-1?e[k+1]:e[k]).vector,kt=k<e.length-1?Ha(U,Nn):1,On=Ha(U,I)<0&&!N,on=kt!==null&&kt<0;if(On||on){let ue=ft(Li(I),w);for(let oe=1/13,rn=0;rn<=1;rn+=oe)G=Ci(dt(F,ue),F,Gi*rn),x.push(G),L=Ci(ht(F,ue),F,Gi*-rn),b.push(L);M=G,A=L,on&&(N=!0);continue}if(N=!1,k===e.length-1){let ue=ft(Li(U),w);x.push(dt(F,ue)),b.push(ht(F,ue));continue}let ti=ft(Li(vr(Nn,U,kt)),w);G=dt(F,ti),(k<=1||_a(M,G)>g)&&(x.push(G),M=G),L=ht(F,ti),(k<=1||_a(A,L)>g)&&(b.push(L),A=L),y=T,I=U}let D=e[0].point.slice(0,2),j=e.length>1?e[e.length-1].point.slice(0,2):ht(e[0].point,[1,1]),H=[],Z=[];if(e.length===1){if(!(f||E)||d){let k=Wa(D,Ya(Li(dt(D,j))),-(S||w)),T=[];for(let F=1/13,U=F;U<=1;U+=F)T.push(Ci(k,D,Gi*2*U));return T}}else{if(!(f||E&&e.length===1))if(c)for(let T=1/13,F=T;F<=1;F+=T){let U=Ci(b[0],D,Gi*F);H.push(U)}else{let T=dt(x[0],b[0]),F=ft(T,.5),U=ft(T,.51);H.push(dt(D,F),dt(D,U),ht(D,U),ht(D,F))}let k=Li(nm(e[e.length-1].vector));if(E||f&&e.length===1)Z.push(j);else if(m){let T=Wa(j,k,w);for(let F=1/29,U=F;U<1;U+=F)Z.push(Ci(T,j,Gi*3*U))}else Z.push(ht(j,ft(k,w)),ht(j,ft(k,w*.99)),dt(j,ft(k,w*.99)),dt(j,ft(k,w)))}return x.concat(Z,b.reverse(),H)}function cm(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,[...ht(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(om(u.point,h))continue;let f=am(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:Ya(dt(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 ja(e,t={}){return dm(cm(e,t),t)}P();P();P();function pe([e,t,n],[i,o,r]){return[e+i,t+o,n+r]}function ri([e,t,n],[i,o,r]){return[e-i,t-o,n-r]}function we([e,t,n],i){return[e*i,t*i,n*i]}function zn([e,t,n]){return[e/Math.sqrt(e**2+t**2),t/Math.sqrt(e**2+t**2),n]}function Me([e,t,n],i){return[Math.cos(i)*e-Math.sin(i)*t,Math.sin(i)*e+Math.cos(i)*t,n]}function Xa(e,t,n){return pe(e,we(ri(t,e),n))}function Br(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 Lr(e){return Math.atan2(Math.sin(e),Math.cos(e))}function Cr([e,t]){return Math.sqrt(e**2+t**2)}function Rn([e,t],[n,i]){return Math.sqrt((n-e)**2+(i-t)**2)}function Va(e){if(e.length<2)return 0;let t=0;for(let n=1;n<=e.length-1;n++)t+=Rn(e[n-1],e[n]);return t+=Rn(e[e.length-2],e[e.length-1]),t}var um=(e,t,n)=>Math.max(t,Math.min(n,e));function $a(e,t,n){let i=Rn(t,n);if(i===0)return Rn(e,t);let o=um(((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 Rn(r,e)}P();function Ni(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=$a(l,n,i);return c>s?[c,d]:[s,a]},[0,-1]);if(o>=t){let s=e[r];return[...Ni([n,...e.slice(1,r),s],t).slice(0,-1),s,...Ni([s,...e.slice(r,-1),i],t).slice(1)]}return[n,i]}var ho=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=Xa(this.lastPoint,t,1-this.options.streamline)),this.tailPoints.push(t),Va(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=Ni(n,this.options.simplify));let i=n.length;if(i===0)return[];if(i===1){let I=n[0],M=this.getSize(t,I[2],0,i,0);if(M<.5)return[];let A=[];for(let G=0;G<=Math.PI*2;G+=Math.PI/16)A.push(pe(I,we(Me([1,0,0],G),M)));return A.push(pe(I,we([1,0,0],this.getSize(t,I[2],0,i,0)))),A}if(i===2){let I=n[0],M=n[1],A=this.getSize(t,I[2],0,i,0),G=this.getSize(t,M[2],0,i,0);if(A<.5||G<.5)return[];let L=[],N=Br(I,[I[0],I[1]-100,I[2]],M);for(let D=N;D<=Math.PI+N;D+=Math.PI/16)L.push(pe(I,we(Me([1,0,0],D),A)));for(let D=Math.PI+N;D<=Math.PI*2+N;D+=Math.PI/16)L.push(pe(M,we(Me([1,0,0],D),G)));return L.push(L[0]),L}let o=[],r=[],s=0,a=0,l=0,d=0;for(let I=1;I<i-1;I++){let M=n[I-1],A=n[I],G=n[I+1],L=A[2],N=Rn(M,A);d+=N,s=a+(N-a)*.2;let D=this.getSize(t,L,I,i,d);if(D===0){l=I+1;continue}let j=zn(ri(M,A)),H=zn(ri(G,A)),Z=Me(j,Math.PI/2),k=Me(j,-Math.PI/2),T=Me(H,Math.PI/2),F=Me(H,-Math.PI/2),U=pe(A,we(Z,D)),ge=pe(A,we(k,D)),at=pe(A,we(T,D)),Jn=pe(A,we(F,D)),ei=pe(Z,F),Nn=pe(k,T),kt=pe(A,we(Cr(ei)===0?j:zn(ei),D)),On=pe(A,we(Cr(Nn)===0?H:zn(Nn),D)),on=Lr(Br(A,M,G)),ti=e.constants.cornerDetectionMaxAngle/180*Math.PI*e.constants.cornerDetectionVariance(s);if(Math.abs(on)<ti){let ue=Math.abs(Lr(Math.PI-on));if(ue===0)continue;if(on<0){r.push(ge,On);for(let oe=0;oe<=ue;oe+=ue/4)o.push(pe(A,Me(we(Z,D),oe)));for(let oe=ue;oe>=0;oe-=ue/4)r.push(pe(A,Me(we(Z,D),oe)));r.push(On,at)}else{o.push(U,kt);for(let oe=0;oe<=ue;oe+=ue/4)r.push(pe(A,Me(we(Z,-D),-oe)));for(let oe=ue;oe>=0;oe-=ue/4)o.push(pe(A,Me(we(Z,-D),-oe)));o.push(kt,Jn)}}else o.push(kt),r.push(On);a=s}if(l>=i-2){if(this.options.keepHead){let I=n[i-1],M=[];for(let A=0;A<=Math.PI*2;A+=Math.PI/16)M.push(pe(I,we(Me([1,0,0],A),this.options.size)));return M.push(pe(I,we([1,0,0],this.options.size))),M}return[]}let c=n[l],u=n[l+1],m=n[i-2],p=n[i-1],h=zn(ri(u,c)),f=zn(ri(m,p)),E=Me(h,-Math.PI/2),g=Me(f,Math.PI/2),x=this.getSize(t,c[2],0,i,0),b=[],y=this.options.keepHead?this.options.size:this.getSize(t,m[2],i-2,i,d),w=[];if(x>.1){for(let I=0;I<=Math.PI;I+=Math.PI/16)b.unshift(pe(c,Me(we(E,x),-I)));b.unshift(pe(c,we(E,-x)))}else b.push(c);for(let I=0;I<=Math.PI*3;I+=Math.PI/16)w.push(pe(p,Me(we(g,-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"?Ni(S,this.options.simplify):S}};import{pointFrom as he,pointDistance as Wd,pointRotateRads as Qt}from"@excalidraw/math";import{ROUGHNESS as ch,THEME as zs,isTransparent as qi,assertNever as uh,COLOR_PALETTE as mh,LINE_POLYGON_POINT_MERGE_DISTANCE as ph,applyDarkModeFilter as Ki,DEFAULT_STROKE_STREAMLINE as fh}from"@excalidraw/common";P();import{isRightAngleRads as Kf,lineSegment as Fd,pointFrom as qo,pointRotateRads as Ns}from"@excalidraw/math";import{BOUND_TEXT_PADDING as An,DEFAULT_REDUCED_GLOBAL_ALPHA as Qf,ELEMENT_READY_TO_ERASE_OPACITY as Jf,FRAME_STYLE as Ko,DARK_THEME_FILTER as eh,MIME_TYPES as ks,THEME as Ei,distance as Mn,getFontString as th,isRTL as nh,getVerticalOffset as ih,invariant as oh,applyDarkModeFilter as Jo,isSafari as rh}from"@excalidraw/common";P();import{pointFrom as _t,pointCenter as pm,pointRotateRads as ln,vectorFromPoint as Gr,vectorNormalize as Za,vectorSubtract as qa,vectorAdd as Eo,vectorScale as go,pointFromVector as Ka,clamp as Be,isCloseTo as Qa}from"@excalidraw/math";var Le=10,Zw=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=Nr(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,h=ln(_t(r,s),re(e,t),-e.angle);r=h[0],s=h[1];let f=e.width,E=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,b=g.width,y=e.scale[0]===-1,w=e.scale[1]===-1,S=s-e.y,I=r-e.x;n.includes("n")&&(E=Be(e.height-S,Le,w?d-p:e.height+p)),n.includes("s")&&(S=s-e.y-e.height,E=Be(e.height+S,Le,w?e.height+p:d-p)),n.includes("e")&&(I=r-e.x-e.width,f=Be(e.width+I,Le,y?e.width+m:l-m)),n.includes("w")&&(f=Be(e.width-I,Le,y?l-m:e.width+m));let M=L=>{L.height=E*u,L.width=f*c};M(g);let A=(L,N)=>{M(N),L.includes("n")&&(w||(N.y+=x-N.height)),L.includes("s")&&w&&(N.y+=x-N.height),L.includes("e")&&y&&(N.x+=b-N.width),L.includes("w")&&(y||(N.x+=b-N.width))};switch(n){case"n":{if(a){let L=m+e.width/2,N=l-m-e.width/2,D=Math.min(L,N)*2;f=Be(E*a,Le,D),E=f/a}A(n,g),a&&(g.x+=(b-g.width)/2);break}case"s":{if(a){let L=m+e.width/2,N=l-m-e.width/2,D=Math.min(L,N)*2;f=Be(E*a,Le,D),E=f/a}A(n,g),a&&(g.x+=(b-g.width)/2);break}case"w":{if(a){let L=p+e.height/2,N=d-p-e.height/2,D=Math.min(L,N)*2;E=Be(f/a,Le,D),f=E*a}A(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let L=p+e.height/2,N=d-p-e.height/2,D=Math.min(L,N)*2;E=Be(f/a,Le,D),f=E*a}A(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(I>-S){let L=w?d-p:p+e.height;E=Be(f/a,Le,L),f=E*a}else{let L=y?m+e.width:l-m;f=Be(E*a,Le,L),E=f/a}A(n,g);break}case"nw":{if(a)if(I<S){let L=w?d-p:p+e.height;E=Be(f/a,Le,L),f=E*a}else{let L=y?l-m:m+e.width;f=Be(E*a,Le,L),E=f/a}A(n,g);break}case"se":{if(a)if(I>S){let L=w?p+e.height:d-p;E=Be(f/a,Le,L),f=E*a}else{let L=y?m+e.width:l-m;f=Be(E*a,Le,L),E=f/a}A(n,g);break}case"sw":{if(a)if(-I>S){let L=w?p+e.height:d-p;E=Be(f/a,Le,L),f=E*a}else{let L=y?l-m:m+e.width;f=Be(E*a,Le,L),E=f/a}A(n,g);break}default:break}let G=fm(e,n,f,E,!!a);return Qa(g.width,g.naturalWidth)&&Qa(g.height,g.naturalHeight)&&(g=null),{x:G[0],y:G[1],width:f,height:E,crop:g}},fm=(e,t,n,i,o)=>{let[r,s,a,l]=dn(e,e.width,e.height,!0),d=_t(r,s),c=_t(a,l),u=pm(d,c),[m,p,h,f]=dn(e,n,i,!0),E=h-m,g=f-p,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(E),c[1]-Math.abs(g)]),t==="ne"){let M=[d[0],c[1]];x=[M[0],M[1]-Math.abs(g)]}if(t==="sw"){let M=[c[0],d[1]];x=[M[0]-Math.abs(E),M[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-E/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let b=e.angle,y=ln(x,u,b),w=[x[0]+Math.abs(E)/2,x[1]+Math.abs(g)/2],S=ln(w,u,b);x=ln(y,S,-b);let I=[...x];return I[0]+=e.x-m,I[1]+=e.y-p,I},Ja=(e,t)=>{if(e.crop){let{width:n,height:i}=Nr(e),[o,r,s,a,l,d]=V(e,t),c=Gr(ln(_t(o,r),_t(l,d),e.angle)),u=Gr(ln(_t(s,r),_t(l,d),e.angle)),m=Za(qa(u,c)),p=Gr(ln(_t(o,a),_t(l,d),e.angle)),h=qa(p,c),f=Za(h),{cropX:E,cropY:g}=hm(e.crop,e.scale),x=Eo(Eo(c,go(m,-E*n/e.crop.naturalWidth)),go(f,-g*i/e.crop.naturalHeight)),b=Ka(Eo(Eo(x,go(m,n/2)),go(f,i/2))),y=ln(Ka(x),b,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},Nr=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}},hm=(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}},qw=(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}=Nr(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as dd,pointFrom as O,pointRotateRads as We,pointsEqual as cd,pointDistance as $n,vectorFromPoint as xf,curveLength as bf,curvePointAtLength as wf}from"@excalidraw/math";import{DRAGGING_THRESHOLD as yf,KEYS as Xn,shouldRotateWithDiscreteAngle as Vn,getGridPoint as ud,invariant as Qe,isShallowEqual as Pf,getFeatureFlag as fi}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as md,getSnapOutlineMidPoint as pd,isPathALoop as If,moveArrowAboveBindable as fd,projectFixedPointOntoDiagonal as hd}from"@excalidraw/element";P();import{arrayToMap as td,getFeatureFlag as Zp,getGridPoint as xs,invariant as Kt,isTransparent as qp}from"@excalidraw/common";import{PRECISION as Kp,clamp as Uo,lineSegment as ui,pointDistance as gn,pointDistanceSq as st,pointFrom as $,pointFromArray as Qp,pointFromVector as _o,pointRotateRads as ce,pointsEqual as Jp,vectorFromPoint as mi,vectorNormalize as gs,vectorScale as Wo}from"@excalidraw/math";P();import{invariant as vl,isTransparent as Bl}from"@excalidraw/common";import{curveIntersectLineSegment as Ll,isPointWithinBounds as ts,lineSegment as Wi,lineSegmentIntersectionPoints as Cl,pointFrom as ye,pointFromVector as fp,pointRotateRads as ot,pointsEqual as Gl,vectorFromPoint as hp,vectorNormalize as Ep,vectorScale as gp}from"@excalidraw/math";import{ellipse as xp,ellipseSegmentInterceptPoints as bp}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as Im,DEFAULT_PROPORTIONAL_RADIUS as Or,invariant as Sm,LINE_CONFIRM_THRESHOLD as Am,ROUNDNESS as kr}from"@excalidraw/common";import{bezierEquation as Mm,curve as Wt,curveCatmullRomCubicApproxPoints as cl,curveOffsetPoints as ul,lineSegment as Se,lineSegmentIntersectionPoints as ll,pointDistance as _n,pointFrom as z,pointFromArray as Tm,pointFromVector as Dm,pointRotateRads as nt,pointTranslate as dl,rectangle as vm,vectorFromPoint as ml,vectorNormalize as Bm,vectorScale as Fr}from"@excalidraw/math";P();import{ROUNDNESS as Oi,assertNever as Em}from"@excalidraw/common";import{pointsEqual as el}from"@excalidraw/math";var Hn=e=>!!e&&e.type==="image"&&!!e.fileId,Te=e=>!!e&&e.type==="image",tl=e=>!!e&&e.type==="embeddable",xo=e=>!!e&&e.type==="iframe",bo=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),Q=e=>e!=null&&e.type==="text",wo=e=>e!=null&&e.type==="frame",nl=e=>e!=null&&e.type==="magicframe",q=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Ae=e=>e!=null&&gm(e.type),gm=e=>e==="freedraw",K=e=>e!=null&&wm(e.type),Et=e=>e!=null&&e.type==="line",_=e=>e!=null&&e.type==="arrow",W=e=>_(e)&&e.elbowed,ty=e=>_(e)&&!e.elbowed,xm=e=>_(e)&&!e.elbowed&&!e.roundness,bm=e=>_(e)&&!e.elbowed&&e.roundness!==null,wm=e=>e==="arrow"||e==="line",Ce=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&ym(e.type),ym=e=>e==="arrow",fe=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),il=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),ki=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"),Pm=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||_(e)),ol=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 Em(t,null),!1}},rl=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",Tt=e=>Pm(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),xe=e=>e!==null&&"containerId"in e&&e.containerId!==null&&Q(e),ny=e=>!!e.startBinding||!!e.endBinding,yo=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",sl=e=>e==="line"||e==="arrow"||e==="diamond",iy=(e,t)=>!!((e===Oi.ADAPTIVE_RADIUS||e===Oi.LEGACY)&&yo(t.type)||e===Oi.PROPORTIONAL_RADIUS&&sl(t.type)),oy=e=>sl(e.type)?{type:Oi.PROPORTIONAL_RADIUS}:yo(e.type)?{type:Oi.ADAPTIVE_RADIUS}:null,ry=e=>xm(e)?"sharpArrow":bm(e)?"curvedArrow":W(e)?"elbowArrow":"line",sy=e=>e.length>3&&el(e[0],e[e.length-1]),al=e=>e.length>3||e.length===3&&!el(e[0],e[e.length-1]),ay=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 Fi=new WeakMap,Rr=(e,t)=>{let n=Fi.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){Fi.delete(e);return}return o.get(t)},zr=(e,t,n)=>{let i=Fi.get(e);if(!i){Fi.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){Fi.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function Po(e,t){let n=Rr(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]&&Tm(i[a-1].data.slice(-2));switch(l.op){case"move":continue;case"lineTo":if(!d)throw new Error("prevPoint is undefined");o.push(Se(z(e.x+d[0],e.y+d[1]),z(e.x+l.data[0],e.y+l.data[1])));continue;case"bcurveTo":if(!d)throw new Error("prevPoint is undefined");r.push(Wt(z(e.x+d[0],e.y+d[1]),z(e.x+l.data[0],e.y+l.data[1]),z(e.x+l.data[2],e.y+l.data[3]),z(e.x+l.data[4],e.y+l.data[5])));continue;default:console.error("Unknown op type",l.op)}}let s=[o,r];return zr(e,s,0),s}function cn(e,t=0){let n=Rr(e,t);if(n)return n;let i=Ut(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=vm(z(e.x,e.y),z(e.x+e.width,e.y+e.height)),r=Se(z(o[0][0]+i,o[0][1]),z(o[1][0]-i,o[0][1])),s=Se(z(o[1][0],o[0][1]+i),z(o[1][0],o[1][1]-i)),a=Se(z(o[0][0]+i,o[1][1]),z(o[1][0]-i,o[1][1])),l=Se(z(o[0][0],o[1][1]-i),z(o[0][0],o[0][1]+i)),d=[Wt(l[1],z(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),z(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),Wt(r[1],z(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),z(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),Wt(s[1],z(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),z(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),Wt(a[0],z(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),z(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],c=t>0?d.map(p=>cl(ul(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[Se(c[0][c[0].length-1][3],c[1][0][0]),Se(c[1][c[1].length-1][3],c[2][0][0]),Se(c[2][c[2].length-1][3],c[3][0][0]),Se(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return zr(e,m,t),m}function pl(e,t=0){let[n,i,o,r,s,a,l,d]=si(e),c=e.roundness?Ut(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?Ut(Math.abs(r-i),e):(r-i)*.01,[m,p,h,f]=[z(e.x+n,e.y+i),z(e.x+o,e.y+r),z(e.x+s,e.y+a),z(e.x+l,e.y+d)];return[Wt(z(p[0]-c,p[1]-u),p,p,z(p[0]-c,p[1]+u)),Wt(z(h[0]+c,h[1]-u),h,h,z(h[0]-c,h[1]-u)),Wt(z(f[0]+c,f[1]+u),f,f,z(f[0]+c,f[1]-u)),Wt(z(m[0]-c,m[1]+u),m,m,z(m[0]+c,m[1]+u))]}function un(e,t=0){let n=Rr(e,t);if(n)return n;let i=pl(e,t),o=t>0?i.map(a=>cl(ul(a,t))):[[i[0]],[i[1]],[i[2]],[i[3]]],s=[[Se(o[0][o[0].length-1][3],o[1][0][0]),Se(o[1][o[1].length-1][3],o[2][0][0]),Se(o[2][o[2].length-1][3],o[3][0][0]),Se(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return zr(e,s,t),s}var Wn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return _n(n,i)<=Am/t}return!1},Ut=(e,t)=>{if(t.roundness?.type===kr.PROPORTIONAL_RADIUS||t.roundness?.type===kr.LEGACY)return e*Or;if(t.roundness?.type===kr.ADAPTIVE_RADIUS){let n=t.roundness?.value??Im,i=n/Or;return e<=i?e*Or:n}return 0},Lm=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=Bm(ml(a[1],a[0])),d=Fr(l,n);return Se(dl(a[0],d),dl(a[1],Fr(d,-1)))},o=re(e,t),r=i(ki(e)?Se(nt(z(e.x,e.y),o,e.angle),nt(z(e.x+e.width,e.y+e.height),o,e.angle)):Se(nt(z(e.x+e.width/2,e.y),o,e.angle),nt(z(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(ki(e)?Se(nt(z(e.x+e.width,e.y),o,e.angle),nt(z(e.x,e.y+e.height),o,e.angle)):Se(nt(z(e.x,e.y+e.height/2),o,e.angle),nt(z(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},Cm=(e,t,n,i)=>{let o=re(t,n);return(t.type==="diamond"?pl(t).map(a=>{let l=Mm(a,.5),d=nt(l,o,t.angle);return z(d[0],d[1])}):[nt(z(t.x+t.width,t.y+t.height/2),o,t.angle),nt(z(t.x+t.width/2,t.y+t.height),o,t.angle),nt(z(t.x,t.y+t.height/2),o,t.angle),nt(z(t.x+t.width/2,t.y),o,t.angle)]).find(a=>_n(e,a)<=gt(i)+t.strokeWidth/2&&!Dt({point:e,element:t,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))},Hr=(e,t,n,i,o,r,s=!0)=>{if(Sm(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;if(s){let g=Cm(t,n,o,r);if(g)return g}let[a,l]=Lm(n,o),d=C.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o);if(e.points.length===2){let g=i==="start"?e.endBinding:e.startBinding,x=g&&o.get(g.elementId),b=g&&x&&Ge(Ne(g.fixedPoint),x,o);b&&(d=b)}let c=Dm(Fr(ml(t,d),2*_n(d,t)+Math.max(_n(a[0],a[1]),_n(l[0],l[1]))),d),u=Se(c,d),m=ll(a,u),p=ll(l,u),h=m&&_n(d,m),f=p&&_n(d,p),E=null;return h!=null&&f!=null?E=h<f?m:p:E=m||p||null,E&&Yt(E,n,o)?E:null};P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as tp,ARROW_LABEL_WIDTH_FRACTION as np,BOUND_TEXT_PADDING as vt,DEFAULT_FONT_SIZE as ip,TEXT_ALIGN as yl,VERTICAL_ALIGN as Pl,getFontString as Do,isProdEnv as op,invariant as rp}from"@excalidraw/common";import{pointFrom as Il,pointRotateRads as sp}from"@excalidraw/math";P();var Ri={},hl=(e,t)=>{let n=Ri[e]||(Ri[e]={height:t});return n.height=t,n},El=e=>{Ri[e]&&delete Ri[e]},yy=e=>Ri[e]?.height??null;P();import{BOUND_TEXT_PADDING as So,DEFAULT_FONT_SIZE as Gm,DEFAULT_FONT_FAMILY as Nm,getFontString as Om,isTestEnv as km,normalizeEOL as Fm}from"@excalidraw/common";var it=(e,t,n)=>{let i=e.split(`
2
2
  `).map(a=>a||" ").join(`
3
- `),o=parseFloat(t),r=Sm(i,o,n);return{width:pl(i,t),height:r}},cl="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),ul=(e,t)=>{let n=Am(e);return n===0?Qe(cl.split("").join(`
4
- `),e,t).width+yo*2:n+yo*2},Po=(e,t)=>Qe("",e,t).width+yo*2,Ew=()=>pl(cl,ym({fontSize:bm,fontFamily:wm}))>0,Oi=e=>Im(e).replace(/\t/g," "),zr=e=>Oi(e).split(`
5
- `),gw=e=>{let t=zr(e.text).length;return e.height/t/e.fontSize},Io=(e,t)=>e*t,ml=(e,t)=>Io(e,t)+yo*2,wo,xw=e=>{wo=e},Rr=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 Pm()?r*10:r}},cn=(e,t)=>(wo||(wo=new Rr),wo.getLineWidth(e,t)),pl=(e,t)=>{let n=zr(e),i=0;return n.forEach(o=>{i=Math.max(i,cn(o,t))}),i},Sm=(e,t,n)=>{let i=zr(e).length;return Io(t,n)*i},si=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=cn(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),bw=e=>{let t=si.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},Am=e=>{let t=si.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as Mm,isTestEnv as Tm}from"@excalidraw/common";var Hr,So,_r,Sw=e=>(Hr||(Hr=te.class(...Object.values(_t))),Hr.test(e)),Dm=()=>{if(!So)try{So=Bm()}catch{So=vm()}return So},Wr=()=>(_r||(_r=Lm()),_r),rt={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},_t={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},Wn={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},vm=()=>te.or(Wr(),Ee.On(rt.HYPHEN,rt.WHITESPACE,_t.CHAR)),Bm=()=>te.or(Wr(),Ee.Before(rt.WHITESPACE).Build(),Ee.After(rt.WHITESPACE,rt.HYPHEN).Build(),Ee.Before(_t.CHAR,_t.CURRENCY).NotPrecededBy(rt.OPENING,_t.OPENING).Build(),Ee.After(_t.CHAR).NotFollowedBy(rt.HYPHEN,rt.CLOSING,_t.CLOSING).Build(),Ee.BeforeMany(_t.OPENING).NotPrecededBy(rt.OPENING).Build(),Ee.AfterMany(_t.CLOSING).NotFollowedBy(rt.CLOSING).Build(),Ee.AfterMany(rt.CLOSING).FollowedBy(rt.OPENING).Build()),Lm=()=>te.group(te.or(Wn.FLAG,te.and(Wn.MOST,Wn.JOINER,te.build(`(?:${Wn.ZWJ.source}(?:${Wn.FLAG.source}|${Wn.ANY.source}${Wn.JOINER.source}))*`)))),te={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>te.build(te.join(...e)),or:(...e)=>te.build(e.map(t=>t.source).join("|")),group:(...e)=>te.build(`(${te.join(...e)})`),class:(...e)=>te.build(`[${te.join(...e)}]`)},Ee={On:(...e)=>{let t=te.join(...e);return te.build(`([${t}])`)},Before:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?=[${t}])`);return Ee.Chain(n)},After:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<=[${t}])`);return Ee.Chain(n)},BeforeMany:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<![${t}])(?=[${t}])`);return Ee.Chain(n)},AfterMany:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<=[${t}])(?![${t}])`);return Ee.Chain(n)},NotBefore:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?![${t}])`);return Ee.Chain(n)},NotAfter:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<![${t}])`);return Ee.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=Ee.After(...t).Build(),o=()=>te.and(i,n);return Ee.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=Ee.Before(...t).Build(),o=()=>te.and(n,i);return Ee.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=Ee.NotAfter(...t).Build(),o=()=>te.and(i,n);return Ee.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=Ee.NotBefore(...t).Build(),o=()=>te.and(n,i);return Ee.Chain(o)}})},Cm=e=>{let t=Dm();return e.normalize("NFC").split(t).filter(Boolean)},Wt=(e,t,n)=>Om(e,t,n).map(i=>i.text).join(`
6
- `),Gm=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}})},Om=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return Gm(e);let i=[],o=0;for(let r of e.split(`
8
- `))cn(r,t)<=n?i.push({text:r,start:o,end:o+r.length}):i.push(...km(r,t,n,o)),o+=r.length+1;return i},km=(e,t,n,i)=>{let o=[],r=Cm(e),s="",a=i,l=i,d=0,c=i,u=0;for(;u<r.length;){let m=r[u],p=c,h=p+m.length,f=s+m,E=zm(m)?d+si.calculate(m,t):cn(f,t);if(/\s/.test(m)||E<=n){s||(a=p),s=f,l=h,d=E,c=h,u++;continue}if(s)o.push(Rm(s,a,l)),s="",a=p,l=p,d=0;else{let g=Fm(m,t,n,p),x=g[g.length-1]??{text:"",start:p,end:p},b=g.slice(0,-1);o.push(...b),s=x.text,a=x.start,l=x.end,d=cn(x.text,t),c=h,u++}}if(s){let m=Nm(s,a,l,t,n);o.push(m)}return o},Fm=(e,t,n,i)=>{if(Wr().test(e))return[{text:e,start:i,end:i+e.length}];Hm(e);let o=[],r=Array.from(e),s="",a=i,l=i,d=0,c=i;for(let u of r){let m=c,p=m+u.length,h=si.calculate(u,t),f=d+h;if(f<=n){s||(a=m),s=s+u,l=p,d=f,c=p;continue}s&&o.push({text:s,start:a,end:l}),s=u,a=m,l=p,d=h,c=p}return s&&o.push({text:s,start:a,end:l}),o},Nm=(e,t,n,i,o)=>{if(!(cn(e,i)>o))return{text:e,start:t,end:n};let[,s,a]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],l=cn(s,i);for(let d of Array.from(a)){let c=si.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)}},Rm=(e,t,n)=>{let i=e.trimEnd();return{text:i,start:t,end:n-(e.length-i.length)}},zm=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Hm=e=>{if((Tm()||Mm())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var Mo=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;Ym()||jm(!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?mt(t,e):e.width,r.text=Wt(e.originalText,Ao(e),o));let s=Qe(r.text,Ao(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=Fi(t,e),l=mt(t,e);if(!W(t)&&s.height>a){let m=Ur(s.height,t.type);n.mutateElement(t,{height:m}),ll(t.id,m)}if(s.width>l){let m=Ur(s.width,t.type);n.mutateElement(t,{width:m})}let d={...e,...r},{x:c,y:u}=ki(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},Un=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!Ut(e))return;dl(e.id);let s=q(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=mt(e,s),u=Fi(e,s),m=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=Wt(s.originalText,Ao(s),c));let p=Qe(a,Ao(s),s.lineHeight);l=p.height,d=p.width}if(l>u){m=Ur(l,e.type);let p=m-e.height,h=!W(e)&&(n==="ne"||n==="nw"||n==="n")?e.y-p:e.y;t.mutateElement(e,{height:m,y:h})}t.mutateElement(s,{text:a,width:d,height:l}),W(e)||t.mutateElement(s,ki(e,s,o))}},ki=(e,t,n)=>{if(W(e))return G.getBoundTextElementPosition(e,t,n);let i=Yr(e),o=Fi(e,t),r=mt(e,t),s,a;t.verticalAlign===hl.TOP?a=i.y:t.verticalAlign===hl.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===fl.LEFT?s=i.x:t.textAlign===fl.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=El(i.x+r/2,i.y+o/2),c=El(s+t.width/2,a+t.height/2),[u,m]=Xm(c,d,l);return{x:u-t.width/2,y:m-t.height/2}}return{x:s,y:a}},Ut=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,q=(e,t)=>{if(!e)return null;let n=Ut(e);if(n){let i=t.get(n)||null;return i&&!pt(i)&&console.error("[NONDELETED][INVARIANT] Bound text element `isDeleted: true` which is not expected."),i}return null},Ce=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,kw=(e,t,n)=>{if(!W(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(G.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=G.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=G.getEditorMidPoints(e,n,t)[o];return r||(r=G.getSegmentMidPoint(e,o+1,n)),{x:r[0],y:r[1]}},Yr=e=>{let t=St,n=St;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},Fw=(e,t)=>W(t)?0:t?t.angle:e.angle,Nw=(e,t,n)=>{if(W(e))return G.getBoundTextElementPosition(e,t,n)},Rw=(e,t)=>e.some(n=>{if(he(n)){let i=Ce(n,t);return!W(i)}return!1}),zw=(e,t)=>e.some(n=>{if(he(n)){let i=Ce(n,t);return!W(i)}return K(n)}),$m=new Set(["rectangle","ellipse","diamond","arrow"]),Hw=e=>$m.has(e.type),Ur=(e,t)=>{e=Math.ceil(e);let n=St*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},mt=(e,t)=>{let{width:n}=e;if(W(e)){let i=(t?.fontSize??Um)*_m;return Math.max(Wm*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-St*2:e.type==="diamond"?Math.round(n/2)-St*2:n-St*2},Fi=(e,t)=>{let{height:n}=e;return W(e)?n-St*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-St*2:e.type==="diamond"?Math.round(n/2)-St*2:n-St*2},_w=(e,t=`
3
+ `),o=parseFloat(t),r=Rm(i,o,n);return{width:wl(i,t),height:r}},gl="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),xl=(e,t)=>{let n=zm(e);return n===0?it(gl.split("").join(`
4
+ `),e,t).width+So*2:n+So*2},Ao=(e,t)=>it("",e,t).width+So*2,Ay=()=>wl(gl,Om({fontSize:Gm,fontFamily:Nm}))>0,zi=e=>Fm(e).replace(/\t/g," "),Wr=e=>zi(e).split(`
5
+ `),My=e=>{let t=Wr(e.text).length;return e.height/t/e.fontSize},Mo=(e,t)=>e*t,bl=(e,t)=>Mo(e,t)+So*2,Io,Ty=e=>{Io=e},_r=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 km()?r*10:r}},mn=(e,t)=>(Io||(Io=new _r),Io.getLineWidth(e,t)),wl=(e,t)=>{let n=Wr(e),i=0;return n.forEach(o=>{i=Math.max(i,mn(o,t))}),i},Rm=(e,t,n)=>{let i=Wr(e).length;return Mo(t,n)*i},ai=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=mn(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),Dy=e=>{let t=ai.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},zm=e=>{let t=ai.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as Hm,isTestEnv as _m}from"@excalidraw/common";var Ur,To,Yr,Gy=e=>(Ur||(Ur=te.class(...Object.values(jt))),Ur.test(e)),Wm=()=>{if(!To)try{To=Ym()}catch{To=Um()}return To},jr=()=>(Yr||(Yr=jm()),Yr),ct={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},jt={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},Un={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},Um=()=>te.or(jr(),be.On(ct.HYPHEN,ct.WHITESPACE,jt.CHAR)),Ym=()=>te.or(jr(),be.Before(ct.WHITESPACE).Build(),be.After(ct.WHITESPACE,ct.HYPHEN).Build(),be.Before(jt.CHAR,jt.CURRENCY).NotPrecededBy(ct.OPENING,jt.OPENING).Build(),be.After(jt.CHAR).NotFollowedBy(ct.HYPHEN,ct.CLOSING,jt.CLOSING).Build(),be.BeforeMany(jt.OPENING).NotPrecededBy(ct.OPENING).Build(),be.AfterMany(jt.CLOSING).NotFollowedBy(ct.CLOSING).Build(),be.AfterMany(ct.CLOSING).FollowedBy(ct.OPENING).Build()),jm=()=>te.group(te.or(Un.FLAG,te.and(Un.MOST,Un.JOINER,te.build(`(?:${Un.ZWJ.source}(?:${Un.FLAG.source}|${Un.ANY.source}${Un.JOINER.source}))*`)))),te={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>te.build(te.join(...e)),or:(...e)=>te.build(e.map(t=>t.source).join("|")),group:(...e)=>te.build(`(${te.join(...e)})`),class:(...e)=>te.build(`[${te.join(...e)}]`)},be={On:(...e)=>{let t=te.join(...e);return te.build(`([${t}])`)},Before:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?=[${t}])`);return be.Chain(n)},After:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<=[${t}])`);return be.Chain(n)},BeforeMany:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<![${t}])(?=[${t}])`);return be.Chain(n)},AfterMany:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<=[${t}])(?![${t}])`);return be.Chain(n)},NotBefore:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?![${t}])`);return be.Chain(n)},NotAfter:(...e)=>{let t=te.join(...e),n=()=>te.build(`(?<![${t}])`);return be.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=be.After(...t).Build(),o=()=>te.and(i,n);return be.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=be.Before(...t).Build(),o=()=>te.and(n,i);return be.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=be.NotAfter(...t).Build(),o=()=>te.and(i,n);return be.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=be.NotBefore(...t).Build(),o=()=>te.and(n,i);return be.Chain(o)}})},Xm=e=>{let t=Wm();return e.normalize("NFC").split(t).filter(Boolean)},Xt=(e,t,n)=>$m(e,t,n).map(i=>i.text).join(`
6
+ `),Vm=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}})},$m=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return Vm(e);let i=[],o=0;for(let r of e.split(`
8
+ `))mn(r,t)<=n?i.push({text:r,start:o,end:o+r.length}):i.push(...Zm(r,t,n,o)),o+=r.length+1;return i},Zm=(e,t,n,i)=>{let o=[],r=Xm(e),s="",a=i,l=i,d=0,c=i,u=0;for(;u<r.length;){let m=r[u],p=c,h=p+m.length,f=s+m,E=Jm(m)?d+ai.calculate(m,t):mn(f,t);if(/\s/.test(m)||E<=n){s||(a=p),s=f,l=h,d=E,c=h,u++;continue}if(s)o.push(Qm(s,a,l)),s="",a=p,l=p,d=0;else{let g=qm(m,t,n,p),x=g[g.length-1]??{text:"",start:p,end:p},b=g.slice(0,-1);o.push(...b),s=x.text,a=x.start,l=x.end,d=mn(x.text,t),c=h,u++}}if(s){let m=Km(s,a,l,t,n);o.push(m)}return o},qm=(e,t,n,i)=>{if(jr().test(e))return[{text:e,start:i,end:i+e.length}];ep(e);let o=[],r=Array.from(e),s="",a=i,l=i,d=0,c=i;for(let u of r){let m=c,p=m+u.length,h=ai.calculate(u,t),f=d+h;if(f<=n){s||(a=m),s=s+u,l=p,d=f,c=p;continue}s&&o.push({text:s,start:a,end:l}),s=u,a=m,l=p,d=h,c=p}return s&&o.push({text:s,start:a,end:l}),o},Km=(e,t,n,i,o)=>{if(!(mn(e,i)>o))return{text:e,start:t,end:n};let[,s,a]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],l=mn(s,i);for(let d of Array.from(a)){let c=ai.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)}},Qm=(e,t,n)=>{let i=e.trimEnd();return{text:i,start:t,end:n-(e.length-i.length)}},Jm=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,ep=e=>{if((_m()||Hm())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var vo=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;op()||rp(!t||!_(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?_(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?xt(t,e):e.width,r.text=Xt(e.originalText,Do(e),o));let s=it(r.text,Do(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=_i(t,e),l=xt(t,e);if(!_(t)&&s.height>a){let m=Xr(s.height,t.type);n.mutateElement(t,{height:m}),hl(t.id,m)}if(s.width>l){let m=Xr(s.width,t.type);n.mutateElement(t,{width:m})}let d={...e,...r},{x:c,y:u}=Hi(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},Yn=(e,t,n,i=!1,o=!1)=>{let r=t.getNonDeletedElementsMap();if(!bt(e))return;El(e.id);let a=ne(e,r);if(a&&a.text){if(!e)return;let l=a.text,d=a.height,c=a.width,u=xt(e,a),m=_i(e,a),p=e.height;if(i||n!=="n"&&n!=="s"){l&&(l=Xt(a.originalText,Do(a),u));let h=it(l,Do(a),a.lineHeight);d=h.height,c=h.width}if(d>m){p=Xr(d,e.type);let h=p-e.height,f=n==="n"||n==="ne"||n==="nw",E=0;_(e)||(o?E=h/2:f&&(E=h)),t.mutateElement(e,{height:p,y:e.y-E})}t.mutateElement(a,{text:l,width:c,height:d}),_(e)||t.mutateElement(a,Hi(e,a,r))}},Hi=(e,t,n)=>{if(_(e))return C.getBoundTextElementPosition(e,t,n);let i=Vr(e),o=_i(e,t),r=xt(e,t),s,a;t.verticalAlign===Pl.TOP?a=i.y:t.verticalAlign===Pl.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===yl.LEFT?s=i.x:t.textAlign===yl.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=Il(i.x+r/2,i.y+o/2),c=Il(s+t.width/2,a+t.height/2),[u,m]=sp(c,d,l);return{x:u-t.width/2,y:m-t.height/2}}return{x:s,y:a}},bt=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,ne=(e,t)=>{if(!e)return null;let n=bt(e);if(n){let i=t.get(n)||null;return i&&!ze(i)&&console.error("[NONDELETED][INVARIANT] Bound text element `isDeleted: true` which is not expected."),i}return null},Oe=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,Yy=(e,t)=>{if(!_(e))return{x:e.x+e.width/2,y:e.y+e.height/2};let n=C.getBoundTextElementCenter(e,t);return{x:n[0],y:n[1]}},Vr=e=>{let t=vt,n=vt;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},jy=(e,t)=>_(t)?0:t?t.angle:e.angle,Xy=(e,t,n)=>{if(_(e))return C.getBoundTextElementPosition(e,t,n)},Vy=(e,t)=>e.some(n=>{if(xe(n)){let i=Oe(n,t);return!_(i)}return!1}),$y=(e,t)=>e.some(n=>{if(xe(n)){let i=Oe(n,t);return!_(i)}return Q(n)}),ap=new Set(["rectangle","ellipse","diamond","arrow"]),Zy=e=>ap.has(e.type),Xr=(e,t)=>{e=Math.ceil(e);let n=vt*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},xt=(e,t)=>{let{width:n}=e;if(_(e)){let i=(t?.fontSize??ip)*tp;return Math.max(np*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-vt*2:e.type==="diamond"?Math.round(n/2)-vt*2:n-vt*2},_i=(e,t)=>{let{height:n}=e;return _(e)?n-vt*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-vt*2:e.type==="diamond"?Math.round(n/2)-vt*2:n-vt*2},qy=(e,t=`
9
9
 
10
- `)=>e.reduce((i,o)=>(K(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as jr,distanceToLineSegment as Xr,pointRotateRads as $r}from"@excalidraw/math";import{ellipse as Vm,ellipseDistanceFromPoint as Zm}from"@excalidraw/math/ellipse";var un=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return qm(e,t,n);case"diamond":return Km(e,t,n);case"ellipse":return Qm(e,t,n);case"line":case"arrow":case"freedraw":return Jm(e,t,n)}},qm=(e,t,n)=>{let i=re(e,t),o=$r(n,i,-e.angle),[r,s]=ln(e);return Math.min(...r.map(a=>Xr(o,a)),...s.map(a=>jr(a,o)).filter(a=>a!==null))},Km=(e,t,n)=>{let i=re(e,t),o=$r(n,i,-e.angle),[r,s]=dn(e);return Math.min(...r.map(a=>Xr(o,a)),...s.map(a=>jr(a,o)).filter(a=>a!==null))},Qm=(e,t,n)=>{let i=re(e,t);return Zm($r(n,i,-e.angle),Vm(i,e.width/2,e.height/2))},Jm=(e,t,n)=>{let[i,o]=bo(e,t);return Math.min(...i.map(r=>Xr(n,r)),...o.map(r=>jr(r,n)))};P();var Vr=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",qw=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable",Kw=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",Qw=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Jw=e=>e==="freedraw",gl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",ey=e=>e==="arrow",ty=e=>e==="arrow";var To=e=>{if(e.type==="arrow")return!1;let t=Vr(e.type)&&!Sl(e.backgroundColor)||yt(e)||go(e)||K(e);return e.type==="line"?t&&_n(e.points):e.type==="freedraw"?t&&_n(e.points):t||Ae(e)},Zr=null,xl=null,bl=1/0,wl=!1,yl=!1,Pt=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(Zr&&Tl(e,Zr)&&bl<=n&&r===yl){let u=xl?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return wl}let s=o?qr(we(o.x-n,o.y-n),e,we(o.x+o.width+n,o.y+o.height+n)):!1,a=ae(t,i,!0);if(!Dl(e,a,t.angle,n)&&!s)return!1;let c=(r||To(t))&&Ht(e,t,i)||Pl(e,t,i,n)||s;return Zr=e,xl=new WeakRef(t),bl=n,yl=r,wl=c,c},Dl=(e,t,n,i=0)=>{let o=n===0?e:Je(e,mn(t),-n);return qr(we(t[0]-i,t[1]-i),o,we(t[2]+i,t[3]+i))},sp=(e,t,n,i=0)=>{let o=ae(t,n,!0);return Dl(e,o,t.angle,i)},Ey=(e,t)=>!Pt(e)&&!ap(e.point,e.element,t)&&sp(e.point,e.element,t),ap=(e,t,n)=>{let i=q(t,n);if(!i)return!1;let o=Q(t)?{...i,...G.getBoundTextElementPosition(t,i,n)}:i;return Ht(e,o,n)},vl=(e,[t,n],i,o=0)=>{let r=we(t,n),s=!Z(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=ae(e,i);if(!jt(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&Z(m)){let p=ae(m,i);if(!Mt(r,p))return!1}}let c=At(e,i,Ni(re(e,i),r)),u=un(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},Do=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(Il(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),fe(s,!1)&&vl(s,e,n,i)&&(o.push(s),Vr(s.type)&&!Sl(s.backgroundColor)))break}return o},Yt=(e,t,n,i)=>{let o=Do(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()},Bl=(e,t,n,i,o)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];Il(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),fe(l,!1)&&vl(l,e,i,o)&&r.push(l)}if(!r||r.length===0)return null;if(r.length===1)return r[0];let s=r.filter(a=>un(a,i,e)<=Me(a,t)||Ht(e,a,i));return s.length===0?null:s[0]},At=(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(!jt(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return dp(e,t,n,i,o);case"diamond":return cp(e,t,n,i,o);case"ellipse":return up(e,t,n,i);case"line":case"freedraw":case"arrow":return lp(e,n,t,o)}},Ll=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=vo(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(!jt(a,l))continue;let d=Al(s,t);if(d.length>0){for(let c of d)n.push(Je(c,i,o));if(r)return n}}return n},Cl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Ml(s,t);if(a&&(n.push(Je(a,i,o)),r))return n}return n},lp=(e,t,n,i=!1)=>{let[o,r]=bo(e,n),s=[];for(let a of o){let l=Ml(a,t);if(l&&(s.push(l),i))return s}for(let a of r){let l=vo(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(!jt(l,d))continue;let c=Al(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),i))return s}return s},dp=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=Je(n[0],r,-e.angle),a=Je(n[1],r,-e.angle),l=Ni(s,a),[d,c]=ln(e,i),u=[];return Cl(d,l,u,r,e.angle,o),o&&u.length>0||Ll(c,l,u,r,e.angle,o),u},cp=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=Je(n[0],r,-e.angle),a=Je(n[1],r,-e.angle),l=Ni(s,a),[d,c]=dn(e,i),u=[];return Cl(d,l,u,r,e.angle,o),o&&u.length>0||Ll(c,l,u,r,e.angle,o),u},up=(e,t,n,i=0)=>{let o=re(e,t),r=Je(n[0],o,-e.angle),s=Je(n[1],o,-e.angle);return rp(op(o,e.width/2+i,e.height/2+i),Ni(r,s)).map(a=>Je(a,o,e.angle))},Pl=(e,t,n,i=1)=>un(t,n,e)<=i,Ht=(e,t,n)=>{if((Q(t)||Ie(t))&&!_n(t.points))return!1;let[i,o,r,s]=ae(t,n);if(!qr(we(i,o),e,we(r,s)))return!1;let a=we((i+r)/2,(o+s)/2),l=ep(ip(np(tp(e,a,.1)),Math.max(t.width,t.height)*2),a),d=Ni(e,l);return At(t,n,d).filter((u,m,p)=>p.findIndex(h=>Tl(h,u))===m).length%2===1},Kr=(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,E,g,x,b,y,w,S]=ri(s);return[we(l+f,d+E-a),we(l+g+a,d+x),we(l+b,d+y+a),we(l+w-a,d+S)].map(M=>Je(M,p,m))}if(s.type==="ellipse"){let f=l+c/2,E=d+u/2,g=c/2,x=u/2;return[we(f,E-x-a),we(f+g+a,E),we(f,E+x+a),we(f-g-a,E)].map(y=>Je(y,p,m))}return[we(l-a,d-a),we(l+c+a,d-a),we(l+c+a,d+u+a),we(l-a,d+u+a)].map(f=>Je(f,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Ht(s,t,n))};P();import{invariant as Gl,isDevEnv as mp,isTestEnv as pp}from"@excalidraw/common";import{pointFrom as pn,pointFromVector as Bo,pointRotateRads as Lo,pointScaleFromOrigin as Co,pointsEqual as fp,triangleIncludesPoint as Qr,vectorCross as Ue,vectorFromPoint as J,vectorScale as Go}from"@excalidraw/math";var xe=[1,0],Te=[0,1],je=[-1,0],et=[0,-1],Xt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?xe:t<=-o?je:n>i?Te:et},Ye=(e,t)=>Xt(J(e,t)),ft=(e,t)=>Xe(Ye(e,t)),ge=(e,t)=>e[0]===t[0]&&e[1]===t[1],Xe=e=>ge(e,xe)||ge(e,je),Py=e=>!Xe(e),hp=(e,t,n)=>{let i=mn(t);(mp()||pp())&&(Gl(e.width>0&&e.height>0,"Diamond element has no width or height"),Gl(!fp(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Bo(Go(J(Lo(pn(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Bo(Go(J(Lo(pn(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Bo(Go(J(Lo(pn(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Bo(Go(J(Lo(pn(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Ue(J(n,r),J(r,s))<=0&&Ue(J(n,r),J(r,l))>0)return Ye(r,i);if(Ue(J(n,s),J(s,a))<=0&&Ue(J(n,s),J(s,r))>0)return Ye(s,i);if(Ue(J(n,a),J(a,l))<=0&&Ue(J(n,a),J(a,s))>0)return Ye(a,i);if(Ue(J(n,l),J(l,r))<=0&&Ue(J(n,l),J(l,a))>0)return Ye(l,i);if(Ue(J(n,i),J(r,i))<=0&&Ue(J(n,i),J(s,i))>0){let c=e.width>e.height?r:s;return Ye(c,i)}else if(Ue(J(n,i),J(s,i))<=0&&Ue(J(n,i),J(a,i))>0){let c=e.width>e.height?a:s;return Ye(c,i)}else if(Ue(J(n,i),J(a,i))<=0&&Ue(J(n,i),J(l,i))>0){let c=e.width>e.height?a:l;return Ye(c,i)}let d=e.width>e.height?r:l;return Ye(d,i)},Ri=(e,t,n)=>{let o=mn(t);if(e.type==="diamond")return hp(e,t,n);let r=Co(pn(t[0],t[1]),o,2),s=Co(pn(t[2],t[1]),o,2),a=Co(pn(t[0],t[3]),o,2),l=Co(pn(t[2],t[3]),o,2);return Qr([r,s,o],n)?et:Qr([s,l,o],n)?xe:Qr([l,a,o],n)?Te:je},Jr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Gp,randomInteger as cs,getUpdatedTimestamp as us}from"@excalidraw/common";P();import{clamp as Oo,pointDistance as ns,pointFrom as X,pointScaleFromOrigin as Ep,pointsEqual as Hi,pointTranslate as ts,vector as Tt,vectorCross as ko,vectorFromPoint as is,vectorScale as gp}from"@excalidraw/math";import{BinaryHeap as xp,invariant as ai,isAnyTrue as bp,getSizeFromPoints as Ol,isDevEnv as wp,arrayToMap as yp}from"@excalidraw/common";var os=1,ne=40,Pp=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>X(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=Ye(s,l[a-1]),c=Ye(l[a-1],l[a-2]);if(ge(d,c)){let u=n?.findIndex(p=>p.index===a-1)??-1,m=n?.findIndex(p=>p.index===a)??-1;m!==-1&&(n[m].start=X(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(p=>{p.index>a-1&&(p.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(ns(l[a-2],l[a-1])<os){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=ft(s,l[a-1]);return o.push(X(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}o.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==o.length-1);return r.length===0?$t(as(ls(ss(e,rs(e,t,o.map(s=>X(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(wp()&&ai(_l(o),"Invalid elbow points with fixed segments"),$t(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}},Ip=(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:E,hoveredStartElement:g,hoveredEndElement:x,...b}=rs({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[X(0,0),X(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:y}=$t(as(ls(ss(e,{startHeading:p,endHeading:h,startGlobalPoint:f,endGlobalPoint:E,hoveredStartElement:g,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(X(e.x+e.points[A][0],e.y+e.points[A][1]));if(y.forEach(A=>{w.push(X(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(X(e.x+e.points[A][0],e.y+e.points[A][1]));let S=(l?.index??e.points.length)-(a?.index??0)-1,I=t.map(A=>A.index>s?{...A,index:A.index-S+(y.length-1)}:A),M=w.flatMap((A,L)=>{let C=w[L-1],O=w[L+1];if(C&&O){let D=Ye(A,C),Y=Ye(O,A);if(ge(D,Y))return I.forEach(H=>{H.index>L&&(H.index-=1)}),[];if(ge(D,Jr(Y)))return I.forEach(H=>{H.index>L&&(H.index+=1)}),[A,A]}return[A]});return $t(M,I,!1,!1)},Sp=(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=ns(t[s].start,t[s].end),c=d<ne+5;if(a===-1&&t[s].index===1&&o){let w=Xe(n),I=(w?ge(n,xe):ge(n,Te))?c?d/2:ne:c?-d/2:-ne;t[s].start=X(t[s].start[0]+(w?I:0),t[s].start[1]+(w?0:I))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=Xe(i),I=(w?ge(i,xe):ge(i,Te))?c?d/2:ne:c?-d/2:-ne;t[s].end=X(t[s].end[0]+(w?I:0),t[s].end[1]+(w?0:I))}let u=t.map(w=>({...w,start:X(e.x+w.start[0],e.y+w.start[1]),end:X(e.x+w.end[0],e.y+w.end[1])})),m=e.points.map((w,S)=>X(e.x+w[0],e.y+w[1])),p=u[s].index-1,h=u[s].index,f=u[s].start,E=u[s].end,g=m[p-1]&&!Hi(m[p],m[p-1])?ft(m[p-1],m[p]):void 0,x=m[h+1]&&!Hi(m[h],m[h+1])?ft(m[h+1],m[h]):void 0;if(g!==void 0){let w=g?1:0;m[p-1][w]=f[w]}if(m[p]=f,m[h]=E,x!==void 0){let w=x?1:0;m[h+1][w]=E[w]}let b=u.findIndex(w=>w.index===p);if(b!==-1){let w=ft(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=ft(u[y].end,u[y].start)?1:0;u[y].end[w]=E[w],u[y].start=E}if(a===-1&&p===0){let w=o?Xe(n):ft(m[1],m[0]);m.unshift(X(w?f[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:f[1])),o&&m.unshift(X(e.x+e.points[0][0],e.y+e.points[0][1]));for(let S of u)S.index+=o?2:1}if(l===-1&&h===e.points.length-1){let w=Xe(i);m.push(X(w?E[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:E[1])),r&&m.push(X(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return $t(m,u.map(w=>({...w,start:X(w.start[0]-e.x,w.start[1]-e.y),end:X(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},Ap=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((E,g)=>g===0?X(e.x+E[0],e.y+E[1]):g===t.length-1?X(e.x+E[0],e.y+E[1]):X(e.x+e.points[g][0],e.y+e.points[g][1])),m=n.map(E=>({...E,start:X(e.x+(E.start[0]-t[0][0]),e.y+(E.start[1]-t[0][1])),end:X(e.x+(E.end[0]-t[0][0]),e.y+(E.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 E=u.at(d?2:1),g=u.at(d?3:2);if(!E||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=Xe(i),b=Xe(Xt(is(E,g)));if(a&&x===b){let y=x?ge(i,xe):ge(i,Te);if(p.unshift(X(b?r[0]+(y?ne:-ne):g[0],b?g[1]:r[1]+(y?ne:-ne))),p.unshift(X(x?r[0]+(y?ne:-ne):r[0],x?r[1]:r[1]+(y?ne:-ne))),!d){d=!0;for(let w of m)w.index>1&&(w.index+=1)}}else if(p.unshift(X(b?r[0]:E[0],b?E[1]:r[1])),d){d=!1;for(let y of m)y.index>1&&(y.index-=1)}p.unshift(r)}{let E=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!E||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=Xe(o),b=ft(g,E);if(l&&x===b){let y=x?ge(o,xe):ge(o,Te);p.push(X(b?s[0]+(y?ne:-ne):g[0],b?g[1]:s[1]+(y?ne:-ne))),p.push(X(x?s[0]+(y?ne:-ne):s[0],x?s[1]:s[1]+(y?ne:-ne))),c||(c=!0)}else p.push(X(b?s[0]:E[0],b?E[1]:s[1])),c&&(c=!1)}return p.push(s),$t(p,m.map(({index:E})=>({index:E,start:p[E-1],end:p[E]})).map(E=>({...E,start:X(E.start[0]-r[0],E.start[1]-r[1]),end:X(E.end[0]-r[0],E.end[1]-r[1])})),d,c)},fn=1e6,li=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};B.PROD||(ai(!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)"),ai(!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"),ai(!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"),ai(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"),ai(n.fixedSegments?.find(w=>w.index===1&&Hi(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&Hi(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&&No(d.elementId,t),m=c&&No(c.elementId,t),p=_l(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 $t(r.map(w=>X(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:h,endHeading:f,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:b,...y}=rs({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?$t(r.map(w=>X(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?Pp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,S)=>Hi(w,e.points[S]??X(1/0,1/0)))&&p?{}:o.length===0?$t(as(ls(ss(e,{startHeading:h,endHeading:f,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:b,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?Ip(e,o,t):n.points?n.points&&n.fixedSegments?n:Ap(e,r,o,h,f,E,g,x,b):Sp(e,o,h,f,x,b)},rs=(e,t,n,i)=>{let o=ts(n[0],Tt(e.x,e.y)),r=ts(n[n.length-1],Tt(e.x,e.y)),s=null,a=null;if(i?.isDragging&&i?.isBindingEnabled!==!1){let w=Array.from(t.values());s=Rl(o,t,w,i?.zoom)||null,a=Rl(r,t,w,i?.zoom)||null}else s=e.startBinding&&No(e.startBinding.elementId,t)||null,a=e.endBinding&&No(e.endBinding.elementId,t)||null;let l=Fl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),d=Fl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=Nl(l,d,s,o,t,i?.zoom),u=Nl(d,l,a,r,t,i?.zoom),m=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],p=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],h=s?st(s,t,hn(c,e.startArrowhead?Me(s,{elbowed:!0})*6:Me(s,{elbowed:!0})*2,1)):m,f=a?st(a,t,hn(u,e.endArrowhead?Me(a,{elbowed:!0})*6:Me(a,{elbowed:!0})*2,1)):p,E=Mt(l,a?st(a,t,hn(u,ne,ne)):p)||Mt(d,s?st(s,t,hn(c,ne,ne)):m),g=Hl(E?[m,p]:[h,f]),x=Dp(E?m:h,E?p:f,g,E?hn(c,!s&&!a?0:ne,0):hn(c,!s&&!a?0:ne-(e.startArrowhead?Yn*6:Yn*2),ne),E?hn(u,!s&&!a?0:ne,0):hn(u,!s&&!a?0:ne-(e.endArrowhead?Yn*6:Yn*2),ne),E,s&&st(s,t),a&&st(a,t)),b=kl(x[0],c,l),y=kl(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:b,startGlobalPoint:l,startHeading:c,endDonglePosition:y,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:E,startElementBounds:h,endElementBounds:f}},ss=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=vp(n,i||o,r,s||a,l,d),m=i&&Fo(i,u),p=s&&Fo(s,u),h=Fo(a,u);h&&c&&(h.closed=!0);let f=Fo(o,u);f&&e.startBinding&&(f.closed=!0);let E=m&&p&&(Mt(m.pos,n[1])||Mt(p.pos,n[0])),g=Mp(m||f,p||h,u,r||xe,l||xe,E?[]:n);if(g){let x=g.map(b=>[b.pos[0],b.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},hn=(e,t,n)=>{switch(e){case et:return[t,n,n,n];case xe:return[n,t,n,n];case Te:return[n,n,t,n]}return[n,n,n,t]},Mp=(e,t,n,i,o,r)=>{let s=es(e.pos,t.pos),a=new xp(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Tp(e,l);l.closed=!0;let d=Lp(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=Ep(u.pos,l.pos,.5);if(bp(...r.map(y=>Mt(m,y))))continue;let p=Cp(c),h=l.parent?Xt(is(l.pos,l.parent.pos)):i,f=Jr(h);if(ge(f,p)||zl(e.addr,u.addr)&&ge(p,i)||zl(t.addr,u.addr)&&ge(p,o))continue;let g=h!==p,x=l.g+es(u.pos,l.pos)+(g?Math.pow(s,3):0),b=u.visited;if(!b||x<u.g){let y=Bp(u,t,p,o);u.visited=!0,u.parent=l,u.h=es(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},Tp=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},es=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Dp=(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,E,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-p):(l[0]+d[2])/2:e[0]>t[0]?e[0]-p:n[0]-p,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+m):(l[3]+d[1])/2:e[3]<t[3]?e[3]+m:n[3]+m],b=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-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]+E):(d[3]+l[1])/2:t[3]<e[3]?t[3]+E:n[3]+E],y=Hl([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,M=b[3]+(x[1]-b[3])/2;return ko(Tt(e[2]-w,e[1]-S),Tt(e[0]-w,e[3]-S))>0?[[x[0],x[1],I,x[3]],[I,b[1],b[2],b[3]]]:[[x[0],M,x[2],x[3]],[b[0],b[1],b[2],M]]}else if(e[2]<t[0]&&e[3]<t[1]){let I=x[2]+(b[0]-x[2])/2,M=x[3]+(b[1]-x[3])/2;return ko(Tt(e[0]-w,e[1]-S),Tt(e[2]-w,e[3]-S))>0?[[x[0],x[1],x[2],M],[b[0],M,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,M=x[3]+(b[1]-x[3])/2;return ko(Tt(e[2]-w,e[1]-S),Tt(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],M],[b[0],M,b[2],b[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let I=b[2]+(x[0]-b[2])/2,M=b[3]+(x[1]-b[3])/2;return ko(Tt(e[0]-w,e[1]-S),Tt(e[2]-w,e[3]-S))>0?[[I,x[1],x[2],x[3]],[b[0],b[1],I,b[3]]]:[[x[0],M,x[2],x[3]],[b[0],b[1],b[2],M]]}}return[x,b]},vp=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===je||n===xe?a.add(t[1]):s.add(t[0]),o===je||o===xe?a.add(i[1]):s.add(i[0]),e.forEach(c=>{s.add(c[0]),s.add(c[2]),a.add(c[1]),a.add(c[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((c,u)=>c-u),d=Array.from(s).sort((c,u)=>c-u);return{row:l.length,col:d.length,data:l.flatMap((c,u)=>d.map((m,p)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[p,u],pos:[m,c]})))}},kl=(e,t,n)=>{switch(t){case et:return X(n[0],e[1]);case xe:return X(e[2],n[1]);case Te:return X(n[0],e[3])}return X(e[0],n[1])},Bp=(e,t,n,i)=>{if(i===xe)switch(n){case xe:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case et:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Te:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case je:return e.pos[1]===t.pos[1]?4:2}else if(i===je)switch(n){case xe:return e.pos[1]===t.pos[1]?4:2;case et:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Te:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case je:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===et)switch(n){case xe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case et:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Te:return e.pos[0]===t.pos[0]?4:2;case je:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===Te)switch(n){case xe:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case et:return e.pos[0]===t.pos[0]?4:2;case Te:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case je:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Lp=([e,t],n)=>[zi([e,t-1],n),zi([e+1,t],n),zi([e,t+1],n),zi([e-1,t],n)],zi=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Fo=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=zi([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Hl=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]))],No=(e,t)=>{let n=t.get(e);return n&&fe(n)?n:null},$t=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>ts(a,gp(is(e[0]),-1)));return(o<-fn||o>fn||r<-fn||r>fn||o+s[s.length-1][0]<-fn||o+s[s.length-1][0]>fn||r+s[s.length-1][1]<-fn||r+s[s.length-1][1]>fn)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...Ol(s)}),s=s.map(([a,l])=>X(Oo(a,-1e6,1e6),Oo(l,-1e6,1e6))),{points:s,x:Oo(o,-1e6,1e6),y:Oo(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Ol(s),startIsSpecial:n,endIsSpecial:i}},as=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},ls=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return ns(i,t)>os}):e,Cp=e=>{switch(e){case 0:return et;case 1:return xe;case 2:return Te}return je},Fl=(e,t,n,i,o,r,s,a=!0,l=!0)=>s?a&&o&&r?ds(e,o,t,r,void 0,l):i:o?We(n||[0,0],o,r??yp([o])):i,Nl=(e,t,n,i,o,r)=>Wl(e,t,n,n&&st(n,o,Array(4).fill(un(n,o,e))),i,o,r),Rl=(e,t,n,i)=>Yt(e,n,t,ut(i)),zl=(e,t)=>e[0]===t[0]&&e[1]===t[1],_l=(e,t=os)=>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 De=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;U(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...li({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Gp(r),...n});for(let l in n){let d=n[l];if(typeof d<"u"){if(e[l]===d&&(typeof d!="object"||d===null||l==="groupIds"||l==="scale"))continue;if(l==="scale"){let c=e[l],u=d;if(c[0]===u[0]&&c[1]===u[1])continue}else if(l==="points"){let c=e[l],u=d;if(c.length===u.length){let m=!1,p=c.length;for(;--p;){let h=c[p],f=u[p];if(h[0]!==f[0]||h[1]!==f[1]){m=!0;break}}if(!m)continue}}e[l]=d,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof a<"u"||typeof r<"u")&&tt.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??cs(),e.updated=us()),e},Fe=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??cs(),updated:us()}},Ul=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=cs(),e.updated=us(),e);var ql=5,Yn=5,Rp=10,Ui=10/1.5,Wo=1,Me=(e,t)=>(t.elbowed?Yn:ql)+e.strokeWidth/2,ut=e=>{let t=Math.max(ql,15),n=e?.value&&e.value<1?e.value:1;return _o(t/(n*1.5),t,t*2)},Dt=e=>e.isBindingEnabled,zp=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=ps(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0});if(Yl(e,a,"start",o,r.isBindingEnabled),Yl(e,l,"end",o,r.isBindingEnabled),a.focusPoint||l.focusPoint){let d=new Map;a.focusPoint&&d.set(0,{point:ht(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&d.set(e.points.length-1,{point:ht(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),G.movePoints(e,o,d)}return{start:a,end:l}},Yl=(e,{mode:t,element:n,focusPoint:i},o,r,s=!0)=>{t===null?Oe(e,o,r):t!==void 0&&vt(e,n,t,o,r,i,s)},Kl=(e,t,n,i,o)=>{Zt(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;Zt(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=G.getPointGlobalCoordinates(e,a,n),d=Yt(l,i,n,ut(o)),c=d?{element:d,mode:"orbit",focusPoint:G.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},Hp=(e,t,n,i,o,r,s,a,l,d,c)=>{let u={mode:void 0},m={mode:void 0},p=e.points.length>2,h=G.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),f=Yt(h,i,n);if(o)return f?u={element:f,mode:"inside",focusPoint:h}:u={mode:null},{start:u,end:m};if(r){let E=l?.selectedLinearElement?.initialState.origin;if(f&&e.startBinding?.elementId===f.id){let g=ie(f.x+f.width/2,f.y+f.height/2);return{start:p?{mode:void 0}:{mode:"inside",element:f,focusPoint:E??g},end:p?{mode:"orbit",element:f,focusPoint:h}:{mode:"inside",element:f,focusPoint:h}}}if(f&&e.startBinding){let g=e.startBinding;if(Do(h,i,n).find(b=>b.id===g.elementId)){let b=n.get(e.startBinding.elementId);return Zt(b,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:b.id!==f.id?"orbit":"inside",element:b,focusPoint:E??ie(e.x,e.y)},end:{mode:"orbit",element:f,focusPoint:h}}}}if(e.startBinding&&e.startBinding.elementId!==f?.id){let g=n.get(e.startBinding.elementId);Zt(g,"Other element must be in the elements map");let b={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:g,focusPoint:c?re(g,n):E??ie(e.x,e.y)},y=f&&Kr(g,f,n),w;if(f){let S=d==="inside"||d==="skip";w={mode:S&&!y?"inside":"orbit",element:f,focusPoint:h}}else w={mode:null};return{start:p?{mode:void 0}:b,end:w}}if(!e.startBinding)return f?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:f,focusPoint:h}:m={mode:null},{start:u,end:m}}Zt(!1,"New arrow creation should not reach here")},jl=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=Yt(e,o,i),m=n?Do(e,o,i).some(E=>E.id===n.elementId):!1,p=n?i.get(n.elementId):null,h=m&&p?kp(p.backgroundColor):!1,f=u&&p&&Kr(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}},ps=(e,t,n,i,o,r,s,a)=>Op("COMPLEX_BINDINGS")?_p(e,t,o,r,s,a):Ql(e,t,n,i,o,r,s,a),Ql=(e,t,n,i,o,r,s,a)=>{let d=e.points.length-1,c=t.has(0),u=t.has(d),m={mode:void 0},p={mode:void 0};if(e.points.length<2)return console.error("Attempting to bind a linear element with less than 2 points"),{start:{mode:void 0},end:{mode:void 0}};if(!c&&!u)return{start:m,end:p};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!Dt(s))return m=c?{mode:null}:m,p=u?{mode:null}:p,{start:m,end:p};if(U(e))return Kl(e,t,o,r,a?.zoom);let h=c?e.endBinding:e.startBinding,f=t.get(c?0:d)?.point;Zt(f,`Local point must be defined for ${c?"start":"end"} dragging`);let E=G.getPointGlobalCoordinates(e,f,o),g=Yt(E,r,o,ut(s.zoom)),x=g&&(a?.angleLocked?Ht(ie(n,i),g,o):Ht(E,g,o)),b=h?o.get(h.elementId):void 0,y=h&&b&&We(h.fixedPoint,b,o),w=b&&y&&Pt({point:y,element:b,elementsMap:o,threshold:0,overrideShouldTestInside:!0});if(h&&h.elementId===g?.id&&(!a?.newArrow||s.selectedLinearElement?.initialState.origin))return{start:{mode:"inside",element:g,focusPoint:c?E:a?.newArrow?s.selectedLinearElement.initialState.origin:G.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:g,focusPoint:u?E:G.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:m,end:u?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:p};let S=g?x?{mode:"inside",element:g,focusPoint:E}:{mode:"orbit",element:g,focusPoint:Nr(e,E,g,c?"start":"end",o,s.zoom,s.isMidpointSnappingEnabled)||E}:{mode:null},I=G.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),M=y&&b&&Pt({point:E,element:b,elementsMap:o,threshold:ut(s.zoom),overrideShouldTestInside:!0}),L=(a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:h?.mode==="inside")?{mode:void 0}:b&&!w&&!M&&s.selectedLinearElement?.initialState.altFocusPoint?{mode:"orbit",element:b,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&b?{mode:"orbit",element:b,focusPoint:Nr(e,I,b,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||I}:{mode:void 0};return{start:c?S:L,end:u?S:L}},_p=(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(!Dt(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(U(e))return Kl(e,t,n,i);if(r?.newArrow){let{start:p,end:h}=Hp(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;Zt(p,"Local point must be defined for start dragging");let h=G.getPointGlobalCoordinates(e,p,n),{current:f,other:E}=jl(h,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:f,end:E}}if(c){let p=t.get(l)?.point;Zt(p,"Local point must be defined for end dragging");let h=G.getPointGlobalCoordinates(e,p,n),{current:f,other:E}=jl(h,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:E,end:f}}return{start:u,end:m}},t0=(e,t,n)=>{e.forEach(i=>{zp(i,new Map,1/0,1/0,t,n)})},vt=(e,t,n,i,o,r,s=!0)=>{let a=o.getNonDeletedElementsMap(),l;U(e)?l={elementId:t.id,mode:"orbit",...$p(e,t,i,a,s)}:l={elementId:t.id,mode:n,...di(e,t,i,a,r)},o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:l}),Zl(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Oe=(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},ke=(e,t,n)=>{if(!fe(e))return;let{simultaneouslyUpdated:i}=n??{},o=Up(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),Uo(r,e,a=>{if(a&&!pt(a)&&console.error("[NONDELETED][INVARIANT] updateBoundElements(): `isDeleted: true` in visitor"),!W(a)||!pt(a)||!Wp(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=Yo(r,a,(m,p)=>{if(m&&fe(m)&&(p==="startBinding"||p==="endBinding")&&(e.id===a[p]?.elementId||e.id===a[p==="startBinding"?"endBinding":"startBinding"]?.elementId)){let h=ht(a,p,a[p],m,r);if(h)return[p==="startBinding"?0:a.points.length-1,{point:h}]}return null}).filter(m=>m!==null);G.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=q(a,r);u&&!u.isDeleted&&Un(a,t,!1)})},Xl=(e,t,n,i,o)=>{Zt(!U(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=G.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&Pt({element:s,point:a,elementsMap:n,threshold:ut(o.zoom)}),d=t==="startBinding"?"start":"end";if(Oe(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],m=Ql(e,new Map([[c,{point:u}]]),a[0],a[1],n,i.getNonDeletedElements(),o);m[d]&&m[d].element?.id===s.id&&m[d].mode&&vt(e,s,m[d].mode,d,i,m[d].focusPoint)}},n0=(e,t,n,i)=>{if(W(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&Xl(e,"startBinding",o,t,n),e.endBinding&&Xl(e,"endBinding",o,t,n)}else ke(e,t,{...i,changedElements:new Map([[e.id,e]])})},Wp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,Up=e=>new Set((e||[]).map(t=>t.id)),Wl=(e,t,n,i,o,r,s)=>{let a=Xt(_i(t,e));return!n||!i?a:Yp(o,n,r,s)?Ri(n,i,e):Xt(_i(e,re(n,r)))},Yp=(e,t,n,i)=>{let o=un(t,n,e),r=ut(i);return o>r?null:o},ds=(e,t,n,i,o,r=!0)=>{let s=U(e),a=G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return a;let l=qa(t)&&s?jp(e,t,i,a):a,d=o&&!s?o[1]:G.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),c=Me(t,e),u=st(t,i),m=mn(u),p=null;if(s){let h=Xe(Ri(t,u,a)),E=(r?fs(t,i,l,.05,e):void 0)||a,g=ie(h?m[0]:E[0],h?E[1]:m[1]),x=o??Ho(g,Ro(zo(ms(_i(E,g)),Math.max(t.width,t.height)*2),g));if(p=At(t,i,x,c).sort(Vt)[0],!p){let b=ie(h?E[0]:m[0],h?m[1]:E[1]),y=Ho(b,Ro(zo(ms(_i(E,b)),Math.max(t.width,t.height)*2),b));p=At(t,i,y,Yn).sort(Vt)[0]}}else{let h=o;if(!h){let f=zo(ms(_i(l,d)),En(l,d)+Math.max(t.width,t.height)+c*2);h=o??Ho(Ro(f,d),Ro(zo(f,-1),d))}p=En(l,d)<1?l:At(t,i,h,c).sort((f,E)=>Vt(f,d)-Vt(E,d))[0]}return!p||Vt(l,p)<Fp?l:p},jp=(e,t,n,i)=>{let o=re(t,n),r=le(i,o,-t.angle),s=Me(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?le(ie(t.x-s,t.y),o,t.angle):le(ie(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?le(ie(t.x,t.y+t.height+s),o,t.angle):le(ie(t.x-s,t.y+t.height),o,t.angle):r[0]>t.x+t.width&&r[1]>t.y+t.height?r[0]-t.x<t.width+s?le(ie(t.x+t.width,t.y+t.height+s),o,t.angle):le(ie(t.x+t.width+s,t.y+t.height),o,t.angle):r[0]>t.x+t.width&&r[1]<t.y?r[0]-t.x<t.width+s?le(ie(t.x+t.width,t.y-s),o,t.angle):le(ie(t.x+t.width+s,t.y),o,t.angle):i},fs=(e,t,n,i=.05,o)=>{let{x:r,y:s,width:a,height:l,angle:d}=e,c=re(e,t,-.1,-.1),u=le(n,c,-d),m=o?Me(e,o):0,p=_o(i*l,5,80),h=_o(i*a,5,80);if(!(En(c,u)<m)){if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return le(ie(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-h&&u[0]<c[0]+h)return le(ie(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return le(ie(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-h&&u[0]<c[0]+h)return le(ie(c[0],s+l+m),c,d);if(e.type==="diamond"){let f=m,E=ie(r+a/4-f,s+l/4-f),g=ie(r+3*a/4+f,s+l/4-f),x=ie(r+a/4-f,s+3*l/4+f),b=ie(r+3*a/4+f,s+3*l/4+f);if(En(E,u)<Math.max(h,p))return le(E,c,d);if(En(g,u)<Math.max(h,p))return le(g,c,d);if(En(x,u)<Math.max(h,p))return le(x,c,d);if(En(b,u)<Math.max(h,p))return le(b,c,d)}}},Xp=(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:We(It(i.fixedPoint),o,n),binding:i,mode:i.mode}},$l=e=>e.width*e.height,ht=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||Np(e.points[e.points.length-1],ie(0,0)))return null;let s=We(It(n.fixedPoint),i,o);if(n.mode==="inside")return G.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=Xp(e,t==="startBinding"?"endBinding":"startBinding",o),d=G.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&Ho(s,c),m=a&&u&&At(a,o,u,Me(a,e)).sort((b,y)=>Vt(b,s)-Vt(y,s))[0],p=u&&At(i,o,u,Me(i,e)).sort((b,y)=>Vt(b,c)-Vt(y,c))[0],h=e.startArrowhead!==null,f=e.endArrowhead!==null,E=!h&&!f||t==="startBinding"&&h||t==="endBinding"&&f?s:p||s;if(a&&p&&!r&&$l(a)<$l(i)*2&&Pt({element:a,point:p,elementsMap:o,threshold:Me(a,e),overrideShouldTestInside:!0}))return G.createPointAt(e,o,E[0],E[1],null);let x=En(a&&(m||l)||d,p||s)<=Rp;return a?x?G.createPointAt(e,o,E?.[0]||s[0],E?.[1]||s[1],null):G.createPointAt(e,o,p?.[0]||s[0],p?.[1]||s[1],null):G.createPointAt(e,o,x?s[0]:p?.[0]??s[0],x?s[1]:p?.[1]??s[1],null)},$p=(e,t,n,i,o=!0,r=!0)=>{let s=[t.x,t.y,t.x+t.width,t.y+t.height],a=o?ds(e,t,n,i,void 0,r):G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),l=ie(s[0]+(s[2]-s[0])/2,s[1]+(s[3]-s[1])/2),d=le(a,l,-t.angle);if(t.width<Wo||t.height<Wo)return{fixedPoint:It([.5,.5])};let c=Me(t,e);return{fixedPoint:It([(d[0]-t.x)/Math.max(t.width,c),(d[1]-t.y)/Math.max(t.height,c)])}},di=(e,t,n,i,o)=>{let r=o||G.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=re(t,i),a=le(r,s,-t.angle);if(t.width<Wo||t.height<Wo)return{fixedPoint:It([.5,.5])};let l=Me(t,e),d=(a[0]-t.x)/Math.max(t.width,l),c=(a[1]-t.y)/Math.max(t.height,l);return{fixedPoint:It([d,c])}},Jl=(e,t,n)=>{for(let i of e){if("boundElements"in i&&i.boundElements&&Object.assign(i,{boundElements:i.boundElements.reduce((o,r)=>{let s=t.get(r.id);return s&&o.push({...r,id:s}),o},[])}),"containerId"in i&&i.containerId&&Object.assign(i,{containerId:t.get(i.containerId)??null}),"endBinding"in i&&i.endBinding){let o=t.get(i.endBinding.elementId);Object.assign(i,{endBinding:o?{...i.endBinding,elementId:o}:null})}if("startBinding"in i&&i.startBinding){let o=t.get(i.startBinding.elementId);Object.assign(i,{startBinding:o?{...i.startBinding,elementId:o}:null})}U(i)&&Object.assign(i,li(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},i0=(e,t)=>{let n=Zl(e);for(let i of t)gn.unbindAffected(n,i,(o,r)=>De(o,n,r)),xn.unbindAffected(n,i,(o,r)=>De(o,n,r))},Wi=(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},ed=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),Uo=(e,t,n)=>{fe(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},Yo=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(he(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(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},gn=class{static unbindAffected(t,n,i){n&&Yo(t,n,o=>{!o||o.isDeleted||Uo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:Wi(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||Yo(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:Wi(o.boundElements,new Set,new Array(n))}),K(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:Wi(o.boundElements,new Set,new Array(n))}))))})}},xn=class{static unbindAffected(t,n,i){n&&Uo(t,n,o=>{!o||o.isDeleted||Yo(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||Uo(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:Wi(n.boundElements,new Set([s]))});return}K(o)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===o.id?o.containerId!==n.id&&i(o,{containerId:n.id}):(o.containerId!==null&&i(o,{containerId:null}),i(n,{boundElements:Wi(n.boundElements,new Set([o.id]))})))})}},We=(e,t,n)=>{let[i,o]=It(e);return le(ie(t.x+t.width*i,t.y+t.height*o),re(t,n),t.angle)},Vp=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?We(e.startBinding.fixedPoint,n,t):ie(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?We(e.endBinding.fixedPoint,i,t):ie(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},td=(e,t)=>{let[n,i]=Vp(e,t);return[G.pointFromAbsoluteCoords(e,n,t),G.pointFromAbsoluteCoords(e,i,t)]},Zp=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),Vl=10,It=e=>{if(!Zp(e))return[.5001,.5001];let t=1e-4,n=e.map(i=>_o(i,-Vl,Vl));return Math.abs(n[0]-.5)<t||Math.abs(n[1]-.5)<t?n.map(i=>Math.abs(i-.5)<t?.5001:i):n},qp=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",Kp={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"}]},Qp=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}}),Jp=(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=Kp[t],d=Qp(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},o0=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!fe(n))return null;let i=re(n,t),o=qp(n),r=Jp(It(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=dn(n),[d,c,u,m]=a,p,h;switch(r){case"left":{if(l.length>=3){let E=l[2][1];p=E[0]-s,h=E[1]}else{let f=Ge(c[1],u[0]);p=f[0]-s,h=f[1]}break}case"right":{if(l.length>=1){let E=l[0][1];p=E[0]+s,h=E[1]}else{let f=Ge(m[1],d[0]);p=f[0]+s,h=f[1]}break}case"top":{if(l.length>=4){let E=l[3][1];p=E[0],h=E[1]-s}else{let f=Ge(u[1],m[0]);p=f[0],h=f[1]-s}break}case"bottom":{if(l.length>=2){let E=l[1][1];p=E[0],h=E[1]+s}else{let f=Ge(d[1],c[0]);p=f[0],h=f[1]+s}break}case"top-right":{let f=Ge(m[0],m[1]);p=f[0]+s*.707,h=f[1]-s*.707;break}case"bottom-right":{let f=Ge(d[0],d[1]);p=f[0]+s*.707,h=f[1]+s*.707;break}case"bottom-left":{let f=Ge(c[0],c[1]);p=f[0]-s*.707,h=f[1]+s*.707;break}case"top-left":{let f=Ge(u[0],u[1]);p=f[0]-s*.707,h=f[1]-s*.707;break}default:return null}return le(ie(p,h),i,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,m;switch(r){case"top":{u=a,m=l-c-s;break}case"right":{u=a+d+s,m=l;break}case"bottom":{u=a,m=l+c+s;break}case"left":{u=a-d-s,m=l;break}case"top-right":{let p=-Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h+s*.707,m=l+f-s*.707;break}case"bottom-right":{let p=Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h+s*.707,m=l+f+s*.707;break}case"bottom-left":{let p=3*Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h-s*.707,m=l+f+s*.707;break}case"top-left":{let p=-3*Math.PI/4,h=d*Math.cos(p),f=c*Math.sin(p);u=a+h-s*.707,m=l+f-s*.707;break}default:return null}return le(ie(u,m),i,n.angle)}if(Li(n)){let[a,l]=ln(n),[d,c,u,m]=a,p,h;switch(r){case"top":{let f=Ge(d[0],d[1]);p=f[0],h=f[1]-s;break}case"right":{let f=Ge(c[0],c[1]);p=f[0]+s,h=f[1];break}case"bottom":{let f=Ge(u[0],u[1]);p=f[0],h=f[1]+s;break}case"left":{let f=Ge(m[0],m[1]);p=f[0]-s,h=f[1];break}case"top-left":{if(l.length>=1){let f=l[0],E=f[0],g=f[3],x=Ge(E,g);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],E=f[0],g=f[3],x=Ge(E,g);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],E=f[0],g=f[3],x=Ge(E,g);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],E=f[0],g=f[3],x=Ge(E,g);p=x[0]-s*.707,h=x[1]+s*.707}else p=n.x-s,h=n.y+n.height+s;break}default:return null}return le(ie(p,h),i,n.angle)}return null},Ge=(e,t)=>ie((e[0]+t[0])/2,(e[1]+t[1])/2);var hs=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>k(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},G=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;hoveredFocusPointBinding;draggedFocusPointBinding;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,i=!1){this.elementId=t.id,id(t.points[0],k(0,0))||(console.error("Linear element is not normalized",Error().stack),De(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=U(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,m]=$(n.selectionElement,o),h=e.getPointsGlobalCoordinates(l,o).reduce((f,E,g)=>((E[0]>=d&&E[0]<=u&&E[1]>=c&&E[1]<=m||t.shiftKey&&s?.includes(g))&&f.push(g),f),[]).filter(f=>!(U(l)&&f!==0&&f!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:h.length?h:null}})}static handlePointerMove(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);$e(d,"Element being dragged must exist in the scene"),$e(d.points.length>1,"Element must have at least 2 points");let c=d.points.length-1,u=d.points[c],m=d.points[c-1],p=r.customLineAngle??cd(m,d.points[c]),h=0,f=0;if(Yi(t)){let[w,S]=e._getShiftLockedDelta(d,s,m,k(i,o),t[jn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),I=k(w+m[0],S+m[1]);h=I[0]-u[0],f=I[1]-u[1]}else{let w=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[jn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());h=w[0]-u[0],f=w[1]-u[1]}let E=null,{positions:g,updates:x}=dd([c],h,f,i,o,s,d,a,n,Yi(t),t.altKey,r);if(e.movePoints(d,n.scene,g,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled}),Le(d,!1)&&Dt(n.state)&&(E=x?.suggestedBinding??null),Le(d)&&ad(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!E||rf(n.state.suggestedBinding??[],E)))return null;let b=Le(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:p,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&b&&x?.suggestedBinding?.element.id!==b.id?ld(d,k(d.x,d.y),b,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled):r.initialState.altFocusPoint}},suggestedBinding:E}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);$e(p,"Element being dragged must exist in the scene"),$e(p.points.length>1,"Element must have at least 2 points"),$e(u,"There must be selected points in order to drag them"),l&&u.some((T,N)=>T>0&&T!==p.points.length-1?(u[N]=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],E=u.length===1,g=r.customLineAngle??cd(f,p.points[m]),x=u.includes(0),b=u.includes(p.points.length-1),y=0,w=0;if(Yi(t)&&E){let[T,N]=e._getShiftLockedDelta(p,s,f,k(i,o),t[jn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),g),_=k(T+f[0],N+f[1]);y=_[0]-h[0],w=_[1]-h[1]}else{let T=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[jn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=T[0]-h[0],w=T[1]-h[1]}let S=null,{positions:I,updates:M}=dd(u,y,w,i,o,s,p,a,n,Yi(t)&&E,t.altKey,r);e.movePoints(p,n.scene,I,{startBinding:M?.startBinding,endBinding:M?.endBinding,moveMidPointsWithElement:M?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled}),Le(p,!1)&&Dt(n.state)&&(x||b)&&(S=M?.suggestedBinding??null),Le(p)&&x!==b&&ad(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),q(p,s)&&Un(p,n.scene,!1);let L=l?b?[p.points.length-1]:[0]:u,C=l?L[0]:m,O=!x&&!b?e.getPointGlobalCoordinates(p,h,s):null,D=C,Y=Le(p)&&p.startBinding&&s.get(p.startBinding.elementId),H=Le(p)&&p.endBinding&&s.get(p.endBinding.elementId),V=b&&Y&&M?.suggestedBinding?.element.id!==Y.id?Y:x&&H&&M?.suggestedBinding?.element.id!==H.id?H:null;return{selectedLinearElement:{...r,selectedPointsIndices:L,initialState:{...r.initialState,lastClickedPoint:C,altFocusPoint:!r.initialState.altFocusPoint&&Le(p)&&V?ld(p,k(p.x,p.y),V,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:O,hoverPointIndex:D,isDragging:!0,customLineAngle:g},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)&&sf(c.points,i.zoom.value)&&(Nt(c)&&o.mutateElement(c,{...ud(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,o,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1}}}static getEditorMidPoints=(t,n,i)=>{let o=q(t,n);if(!U(t)&&!i.selectedLinearElement?.isEditing&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom,n)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1,n);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!U(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!U(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Xn(k(c[0],c[1]),k(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&Xn(m[u],k(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r,s){if(U(t))return o>=0&&o<t.points.length?Xn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=Xn(n,i);if(t.points.length>2&&t.roundness){let[l,d]=rd(t,s);$e(l.length===0&&d.length>0,"Only linears built out of curves are supported"),$e(l.length+d.length>=o,"Invalid segment index while calculating mid point"),a=tf(d[o])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,i){if(U(t)){$e(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=nd(t.points[n-1],t.points[n]);return k(t.x+s[0],t.y+s[1])}let[o,r]=rd(t,i);if($e(o.length===0&&r.length>0||o.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),$e(o.length+r.length>=n,"Invalid segment index while calculating mid point"),o.length){let s=o[n-1];return nd(s[0],s[1])}if(r.length){let s=r[n-1];return nf(s,.5)}$e(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let m=e.getSegmentMidpointHitCoords(r,o,a,l),p=k(o.x,o.y),h=null;if(m)h=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(u,{points:[...u.points,e.createPointAt(u,l,o.x,o.y,t[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},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[E,g,x,b]=$(u,l),y=(E+x)/2,w=(g+b)/2,S=f>-1&&Ne(k(u.x+u.points[f][0],u.y+u.points[f][1]),k(y,w),u.angle),I=f>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(f)?af([...r.selectedPointsIndices||[],f]):[f]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:f,origin:p,segmentMidpoint:{value:m,index:h,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:I,pointerOffset:S?{x:o.x-S[0],y:o.y-S[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:id(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(Yi(t)&&c.length>=2){let p=c[c.length-2],[h,f]=e._getShiftLockedDelta(d,l,p,k(n,i),t[jn.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=k(h+p[0],f+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[jn.CTRL_OR_CMD]||U(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:m}]])):e.addPoints(d,o.scene,[m]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=$(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Ne(k(c+n[0],u+n[1]),k(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=$(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return Ne(k(c+d[0],u+d[1]),k(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=$(t,i),a=k(r,s),l=t.points[o],{x:d,y:c}=t;return l?Ne(k(d+l[0],c+l[1]),a,t.angle):Ne(k(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(U(t))return k(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=$(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=Ne(k(n[0],n[1]),k(l,d),-t.angle);return k(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Xn(k(o,r),k(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=od(i,o,r),[a,l,d,c]=$(t,n),u=(a+d)/2,m=(l+c)/2,[p,h]=Ne(k(s[0],s[1]),k(u,m),-t.angle);return k(p-t.x,h-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=hs(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){$e(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);$e(s,"The linear element does not exist in the provided Scene"),$e(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((m,p,h)=>{if(++c,m.push(p),o.includes(h)){let E=a[h+1];E||(d=!0),m.push(E?k((p[0]+E[0])/2,(p[1]+E[1])/2):k(p[0],p[1])),l.push(c+1),++c}return m},[]);if(n.mutateElement(s,{points:u}),d){let m=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:k(m[0]+30,m[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!i.includes(u));Nt(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=k(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=hs({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];Nt(t)&&t.polygon&&(o[0]=k(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(Nt(t)&&t.polygon){let u=i.get(0),m=i.get(s.length-1);u?i.set(s.length-1,{point:k(u.point[0],u.point[1]),isDragging:u.isDragging}):m&&i.set(0,{point:k(m.point[0],m.point[1]),isDragging:m.isDragging})}let a=i.get(0)?.point??k(0,0),[l,d]=a,c=U(t)?[i.get(0)?.point??s[0],i.get(s.length-1)?.point??s[s.length-1]]:s.map((u,m)=>{let p=i.get(m)?.point??u;return o?.moveMidPointsWithElement&&m!==0&&m!==s.length-1&&!i.has(m)?p:k(p[0]-l,p[1]-d)});e._updatePoints(t,n,c,l,d,o,{isDragging:Array.from(i.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&U(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=Xn(a,k(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<of/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!U(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.initialState,segmentMidpoint:{...t.initialState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,i,o,r,s,a){if(U(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=Es(t,i),d=Es(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,m=(d[0]+d[2])/2,p=(d[1]+d[3])/2,h=m-c,f=p-u,E=Ne(k(o,r),k(h,f),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+E[0],y:t.y+E[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(U(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=od(o[0],o[1],r),{width:c,height:u}=md(a[0],a[1],l,d,s);return Ne(k(c,u),k(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&De(n,i,{isDeleted:!0});let r=0,s=0;if(t.points.length%2===1){let a=Math.floor(t.points.length/2),l=e.getPointGlobalCoordinates(t,t.points[a],i);r=l[0]-n.width/2,s=l[1]-n.height/2}else{let a=t.points.length/2-1,l=e.getSegmentMidPoint(t,a+1,i);r=l[0]-n.width/2,s=l[1]-n.height/2}return{x:r,y:s}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:m}=e.getBoundTextElementPosition(t,o,n),p=u+o.width,h=m+o.height,f=k(d,c),E=Ne(k(r,s),f,t.angle),g=Ne(k(a,s),f,t.angle),x=Ne(k(u,m),f,-t.angle),b=Ne(k(p,m),f,-t.angle),y=Ne(k(u,h),f,-t.angle),w=Ne(k(p,h),f,-t.angle);return E[0]<g[0]&&E[1]>=g[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])):E[0]>=g[0]&&E[1]>g[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])):E[0]>=g[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])):E[1]<=g[1]&&(r=Math.min(r,Math.min(b[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,b[1]),l=Math.max(l,y[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=tt.generateElementShape(t,null),r=kt(o[0]),[s,a,l,d]=ji(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,E=i&&q(t,n);return E?e.getMinMaxXYWithBoundText(t,n,[c,u,m,p],E):[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||!U(a))return t;if(n&&n>0&&n<a.points.length){let l=Xe(Xt(ef(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,h)=>(p[h.index]=h,p),{});d[n]={index:n,start:k(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:k(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((p,h)=>p.index-h.index),u=c.map(p=>p.index).reduce((p,h)=>h<n?p+1:p,0);r.mutateElement(a,{fixedSegments:c});let m=k(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:m,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:m}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},af=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},dd=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let m=new Map(e.map(H=>{let V=s.points[H]??s.points.at(-1);return[H,{point:k(V[0]+t,V[1]+n),isDragging:!0}]}));if(!W(s))return{positions:m};let p=e.includes(0),h=e.includes(s.points.length-1),{start:f,end:E}=ps(s,m,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c});if(U(s)){let H=p?f.element:h?E.element:null;return{positions:m,updates:{suggestedBinding:H?{element:H,midPoint:l.state.isMidpointSnappingEnabled?fs(H,r,k(i-u.pointerOffset.x,o-u.pointerOffset.y)):void 0}:null}}}if(!p&&!h){let H={...s,points:s.points.map((F,T)=>m.get(T)?.point??F)},V=new Map(m);if(s.startBinding){let F=r.get(s.startBinding.elementId);if(F){let T=ht(H,"startBinding",s.startBinding,F,r)??null;T&&V.set(0,{point:T,isDragging:!0})}}if(s.endBinding){let F=r.get(s.endBinding.elementId);if(F){let T=ht(H,"endBinding",s.endBinding,F,r)??null;T&&V.set(s.points.length-1,{point:T,isDragging:!0})}}return{positions:V}}if(p===h)return{positions:m};let g={suggestedBinding:null};f.mode===null?g.startBinding=null:f.mode?(g.startBinding={elementId:f.element.id,mode:f.mode,...di(s,f.element,"start",r,f.focusPoint)},p&&(g.startBinding.mode==="orbit"||!ci("COMPLEX_BINDINGS"))&&(g.suggestedBinding=f.element?{element:f.element,midPoint:sd(k(i-u.pointerOffset.x,o-u.pointerOffset.y),f.element,r,l.state.zoom)}:null)):p&&(g.suggestedBinding=l.state.suggestedBinding),E.mode===null?g.endBinding=null:E.mode?(g.endBinding={elementId:E.element.id,mode:E.mode,...di(s,E.element,"end",r,E.focusPoint)},h&&(g.endBinding.mode==="orbit"||!ci("COMPLEX_BINDINGS"))&&(g.suggestedBinding=E.element?{element:E.element,midPoint:sd(k(i-u.pointerOffset.x,o-u.pointerOffset.y),E.element,r,l.state.zoom)}:null)):h&&(g.suggestedBinding=l.state.suggestedBinding);let x=p?k(s.points[0][0]+t,s.points[0][1]+n):s.points[0],b=h?k(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],y={...s,points:[x,...s.points.slice(1,-1),b],startBinding:g.startBinding===void 0?s.startBinding:g.startBinding===null?null:g.startBinding,endBinding:g.endBinding===void 0?s.endBinding:g.endBinding===null?null:g.endBinding},w=s.endBinding&&y.startBinding&&p&&y.startBinding.elementId===s.endBinding.elementId,S=s.startBinding&&y.endBinding&&h&&s.startBinding.elementId===y.endBinding.elementId,I=y.endBinding?E.element??r.get(y.endBinding.elementId):null,M=w?y.points[y.points.length-1]:S&&l.state.bindMode!=="inside"&&ci("COMPLEX_BINDINGS")?y.points[0]:I&&ht(y,"endBinding",y.endBinding,I,r,h)||y.points[y.points.length-1];y.points[y.points.length-1]=M;let A=y.startBinding?f.element??r.get(y.startBinding.elementId):null,L=S&&ci("COMPLEX_BINDINGS")?y.points[0]:w&&l.state.bindMode!=="inside"&&ci("COMPLEX_BINDINGS")?M:A&&ht(y,"startBinding",y.startBinding,A,r,p)||y.points[0],C=!w&&!(S&&l.state.bindMode!=="inside"&&ci("COMPLEX_BINDINGS"))&&!!I,O=Xn(L,y.points[0])!==0,D=new Set(e);A&&O&&D.add(0),I&&C&&D.add(s.points.length-1);let Y=Array.from(D);return{updates:g,positions:new Map(Y.map(H=>[H,H===0?{point:L,isDragging:!0}:H===s.points.length-1?{point:M,isDragging:!0}:m.get(H)]))}},cd=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);P();import{arrayToMap as Et}from"@excalidraw/common";import{isPointWithinBounds as If,pointFrom as Is,segmentsIntersectAt as Sf}from"@excalidraw/math";P();import{arrayToMap as pf,isShallowEqual as ff}from"@excalidraw/common";P();var lf=(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}}},pd=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:gs({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):Bt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:gs(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),df=(e,t)=>xs(e,t)!=null,xs=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),cf=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),fd=(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,...lf(r,n,e)}}}return n.selectedGroupIds},A0=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),uf=(e,t)=>e.groupIds.includes(t),Re=(e,t)=>{let n=[];for(let i of e.values())uf(i,t)&&n.push(i);return n},mf=(e,t)=>e.groupIds.find(n=>t[n]),M0=(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},T0=(e,t)=>e.filter(n=>!t[n]),D0=(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())},hd=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},Ed=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},gd=e=>e.groupIds.length>0,xd=(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},jo=(e,t,n)=>{let i=cf(n),o=e.filter(u=>!he(u)),r=new Map,s=new Map,a=u=>{let m=s.get(u.id)||[],p=q(u,t);p&&m.push(p),s.set(u.id,[...m,u])},l=(u,m)=>{let p=r.get(m)||[],h=q(u,t);h&&p.push(h),r.set(m,[...p,u])},d=(u,m)=>{let p=u.groupIds.indexOf(m,0);return u.groupIds.slice(0,p).length>0?l(u,u.groupIds[p-1]):a(u)},c=e.every(u=>df(n,u));return o.forEach(u=>{let m=mf(u,n.selectedGroupIds);m?i.length===1&&c?d(u,m):l(u,m):a(u)}),Array.from(r.values()).concat(Array.from(s.values()))};var hf=e=>e.locked||he(e),Ef=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),gf=e=>{let t=new Set;return e.forEach(n=>{Z(n)&&t.add(n.id)}),Ef(e,t)},bd=(e,t,n,i=!0,o="contain")=>{let[r,s,a,l]=$(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),m=Math.max(s,l);return wd({elements:e,bounds:[d,c,u,m],elementsMap:n,type:o,shouldIgnoreElementFromSelection:hf,excludeElementsInFrames:i})},z0=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=yd(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},H0=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}(),Bt=(e,t,n)=>{let i=new Set,o=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){pt(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&&he(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{Z(s)&&bn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},_0=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:Bt(e,t,{includeBoundTextElement:!0}),gs=(e,t)=>ff(t.selectedElementIds,e)?t.selectedElementIds:e,xf=(e,t)=>{let n=e.filter(Q);if(n.length===1){let i=n[0],o=i.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===i.id||o.includes(s.id)))return new G(i,pf(t))}return null},W0=(e,t,n)=>({selectedLinearElement:xf(e,t),...pd({editingGroupId:n.editingGroupId,selectedElementIds:gf(e).reduce((i,o)=>(he(o)||(i[o.id]=!0),i),{})},t,n,null)}),U0=(e,t)=>t.editingTextElement||e.length===1&&K(e[0])&&e[0]||null;P();import{arrayToMap as Xo}from"@excalidraw/common";import{validateOrderKey as bf,generateNKeysBetween as wf}from"@excalidraw/fractional-indexing";var bs=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},yf=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=l=>`${l?.index}:${l?.id}:${l?.type}:${l?.isDeleted}:${l?.version}:${l?.versionNonce}`,a=e.map(l=>l.index);for(let[l,d]of a.entries()){let c=a[l-1],u=a[l+1];if(ws(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&yt(e[l])){let m=e[l],p=q(m,Xo(e));p&&p.index<=m.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(p)}", "${s(m)}"`)}}if(r.length){let l=new bs,d=[];if(o&&(d.push("Additional reconciliation context:"),d.push(o.localElements.map(c=>s(c))),d.push(o.remoteElements.map(c=>s(c)))),i||console.error(r.join(`
10
+ `)=>e.reduce((i,o)=>(Q(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as $r,distanceToLineSegment as Zr,pointRotateRads as qr}from"@excalidraw/math";import{ellipse as lp,ellipseDistanceFromPoint as dp}from"@excalidraw/math/ellipse";var pn=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return cp(e,t,n);case"diamond":return up(e,t,n);case"ellipse":return mp(e,t,n);case"line":case"arrow":case"freedraw":return pp(e,t,n)}},cp=(e,t,n)=>{let i=re(e,t),o=qr(n,i,-e.angle),[r,s]=cn(e);return Math.min(...r.map(a=>Zr(o,a)),...s.map(a=>$r(a,o)))},up=(e,t,n)=>{let i=re(e,t),o=qr(n,i,-e.angle),[r,s]=un(e);return Math.min(...r.map(a=>Zr(o,a)),...s.map(a=>$r(a,o)))},mp=(e,t,n)=>{let i=re(e,t);return dp(qr(n,i,-e.angle),lp(i,e.width/2,e.height/2))},pp=(e,t,n)=>{let[i,o]=Po(e,t);return Math.min(...i.map(r=>Zr(n,r)),...o.map(r=>$r(r,n)))};P();var Kr=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw"||e==="autoshape",r0=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable"||e==="autoshape",s0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="autoshape",a0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line"||e==="autoshape",l0=e=>e==="freedraw",Sl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",d0=e=>e==="arrow",c0=e=>e==="arrow";var Bo=e=>{if(e.type==="arrow")return!1;let t=Kr(e.type)&&!Bl(e.backgroundColor)||Tt(e)||bo(e)||Q(e);return e.type==="line"?t&&Wn(e.points):e.type==="freedraw"?t&&Wn(e.points):t||Te(e)},Qr=null,Al=null,Jr=1/0,es=!1,Ml=!1,Tl=null,wp=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height,Dt=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(Qr&&Gl(e,Qr)&&(es?Jr<=n:Jr>=n)&&r===Ml&&wp(o,Tl)){let u=Al?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return es}let s=o?ts(ye(o.x-n,o.y-n),e,ye(o.x+o.width+n,o.y+o.height+n)):!1,a=de(t,i,!0);if(!Nl(e,a,t.angle,n)&&!s)return!1;let c=(r||Bo(t))&&Yt(e,t,i)||Dl(e,t,i,n)||s;return Qr=e,Al=new WeakRef(t),Jr=n,Ml=r,Tl=o,es=c,c},Nl=(e,t,n,i=0)=>{let o=n===0?e:ot(e,$t(t),-n);return ts(ye(t[0]-i,t[1]-i),o,ye(t[2]+i,t[3]+i))},yp=(e,t,n,i=0)=>{let o=de(t,n,!0);return Nl(e,o,t.angle,i)},A0=(e,t)=>!Dt(e)&&!Pp(e.point,e.element,t)&&yp(e.point,e.element,t),Pp=(e,t,n)=>{let i=ne(t,n);if(!i)return!1;let o=K(t)?{...i,...C.getBoundTextElementPosition(t,i,n)}:i;return Yt(e,o,n)},Ol=(e,[t,n],i,o=0)=>{let r=ye(t,n),s=!q(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=de(e,i);if(!Zt(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&q(m)){let p=de(m,i);if(!Bt(r,p))return!1}}let c=ut(e,i,Wi(re(e,i),r)),u=pn(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},Lo=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(vl(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),fe(s,!1)&&Ol(s,e,n,i)&&(o.push(s),Kr(s.type)&&!Bl(s.backgroundColor)))break}return o},Vt=(e,t,n,i)=>{let o=Lo(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()},kl=(e,t,n,i,o)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];vl(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),fe(l,!1)&&Ol(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=>pn(a,i,e)<=Pe(a,t)||Yt(e,a,i));return s.length===0?null:s[0]},ut=(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=de(e,t);if(!Zt(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return Sp(e,t,n,i,o);case"diamond":return Ap(e,t,n,i,o);case"ellipse":return Mp(e,t,n,i);case"line":case"freedraw":case"arrow":return Ip(e,n,t,o)}},Fl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Co(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(!Zt(a,l))continue;let d=Ll(s,t);if(d.length>0){for(let c of d)n.push(ot(c,i,o));if(r)return n}}return n},Rl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Cl(s,t);if(a&&(n.push(ot(a,i,o)),r))return n}return n},Ip=(e,t,n,i=!1)=>{let[o,r]=Po(e,n),s=[];for(let a of o){let l=Cl(a,t);if(l&&(s.push(l),i))return s}for(let a of r){let l=Co(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(!Zt(l,d))continue;let c=Ll(a,t,{iterLimit:10});if(c.length>0&&(s.push(...c),i))return s}return s},Sp=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=ot(n[0],r,-e.angle),a=ot(n[1],r,-e.angle),l=Wi(s,a),[d,c]=cn(e,i),u=[];return Rl(d,l,u,r,e.angle,o),o&&u.length>0||Fl(c,l,u,r,e.angle,o),u},Ap=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=ot(n[0],r,-e.angle),a=ot(n[1],r,-e.angle),l=Wi(s,a),[d,c]=un(e,i),u=[];return Rl(d,l,u,r,e.angle,o),o&&u.length>0||Fl(c,l,u,r,e.angle,o),u},Mp=(e,t,n,i=0)=>{let o=re(e,t),r=ot(n[0],o,-e.angle),s=ot(n[1],o,-e.angle);return bp(xp(o,e.width/2+i,e.height/2+i),Wi(r,s)).map(a=>ot(a,o,e.angle))},Dl=(e,t,n,i=1)=>pn(t,n,e)<=i,Yt=(e,t,n)=>{if((K(t)||Ae(t))&&!Wn(t.points))return!1;let[i,o,r,s]=de(t,n);if(!ts(ye(i,o),e,ye(r,s)))return!1;let a=ye((i+r)/2,(o+s)/2),l=fp(gp(Ep(hp(e,a,.1)),Math.max(t.width,t.height)*2),a),d=Wi(e,l);return ut(t,n,d).filter((u,m,p)=>p.findIndex(h=>Gl(h,u))===m).length%2===1},ns=(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,E,g,x,b,y,w,S]=si(s);return[ye(l+f,d+E-a),ye(l+g+a,d+x),ye(l+b,d+y+a),ye(l+w-a,d+S)].map(M=>ot(M,p,m))}if(s.type==="ellipse"){let f=l+c/2,E=d+u/2,g=c/2,x=u/2;return[ye(f,E-x-a),ye(f+g+a,E),ye(f,E+x+a),ye(f-g-a,E)].map(y=>ot(y,p,m))}return[ye(l-a,d-a),ye(l+c+a,d-a),ye(l+c+a,d+u+a),ye(l-a,d+u+a)].map(f=>ot(f,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Yt(s,t,n))};P();import{invariant as zl,isDevEnv as Tp,isTestEnv as Dp}from"@excalidraw/common";import{pointFrom as fn,pointFromVector as Go,pointRotateRads as No,pointScaleFromOrigin as Oo,pointsEqual as vp,triangleIncludesPoint as is,vectorCross as $e,vectorFromPoint as J,vectorScale as ko}from"@excalidraw/math";var le=[1,0],Ie=[0,1],De=[-1,0],He=[0,-1],Lt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?le:t<=-o?De:n>i?Ie:He},Ze=(e,t)=>Lt(J(e,t)),wt=(e,t)=>qe(Ze(e,t)),ae=(e,t)=>e[0]===t[0]&&e[1]===t[1],qe=e=>ae(e,le)||ae(e,De),L0=e=>!qe(e),Bp=(e,t,n)=>{let i=$t(t);(Tp()||Dp())&&(zl(e.width>0&&e.height>0,"Diamond element has no width or height"),zl(!vp(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Go(ko(J(No(fn(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Go(ko(J(No(fn(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Go(ko(J(No(fn(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Go(ko(J(No(fn(e.x,e.y+e.height/2),i,e.angle),i),o),i);if($e(J(n,r),J(r,s))<=0&&$e(J(n,r),J(r,l))>0)return Ze(r,i);if($e(J(n,s),J(s,a))<=0&&$e(J(n,s),J(s,r))>0)return Ze(s,i);if($e(J(n,a),J(a,l))<=0&&$e(J(n,a),J(a,s))>0)return Ze(a,i);if($e(J(n,l),J(l,r))<=0&&$e(J(n,l),J(l,a))>0)return Ze(l,i);if($e(J(n,i),J(r,i))<=0&&$e(J(n,i),J(s,i))>0){let c=e.width>e.height?r:s;return Ze(c,i)}else if($e(J(n,i),J(s,i))<=0&&$e(J(n,i),J(a,i))>0){let c=e.width>e.height?a:s;return Ze(c,i)}else if($e(J(n,i),J(a,i))<=0&&$e(J(n,i),J(l,i))>0){let c=e.width>e.height?a:l;return Ze(c,i)}let d=e.width>e.height?r:l;return Ze(d,i)},li=(e,t,n)=>{let o=$t(t);if(e.type==="diamond")return Bp(e,t,n);let r=Oo(fn(t[0],t[1]),o,2),s=Oo(fn(t[2],t[1]),o,2),a=Oo(fn(t[0],t[3]),o,2),l=Oo(fn(t[2],t[3]),o,2);return is([r,s,o],n)?He:is([s,l,o],n)?le:is([l,a,o],n)?Ie:De},os=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as $p,randomInteger as hs,getUpdatedTimestamp as Es}from"@excalidraw/common";P();import{clamp as Fo,pointDistance as as,pointFrom as X,pointScaleFromOrigin as Lp,pointsEqual as Yi,pointTranslate as ss,vector as Ct,vectorCross as Ro,vectorFromPoint as ls,vectorScale as Cp}from"@excalidraw/math";import{BinaryHeap as Gp,invariant as di,isAnyTrue as Np,getSizeFromPoints as Hl,isDevEnv as Op,arrayToMap as kp}from"@excalidraw/common";var ds=1,ie=40,Fp=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>X(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=Ze(s,l[a-1]),c=Ze(l[a-1],l[a-2]);if(ae(d,c)){let u=n?.findIndex(p=>p.index===a-1)??-1,m=n?.findIndex(p=>p.index===a)??-1;m!==-1&&(n[m].start=X(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(p=>{p.index>a-1&&(p.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(as(l[a-2],l[a-1])<ds){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=wt(s,l[a-1]);return o.push(X(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}o.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==o.length-1);return r.length===0?qt(ms(ps(us(e,cs(e,t,o.map(s=>X(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(Op()&&di(Vl(o),"Invalid elbow points with fixed segments"),qt(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}},Rp=(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:E,hoveredStartElement:g,hoveredEndElement:x,...b}=cs({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[X(0,0),X(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:y}=qt(ms(ps(us(e,{startHeading:p,endHeading:h,startGlobalPoint:f,endGlobalPoint:E,hoveredStartElement:g,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(X(e.x+e.points[A][0],e.y+e.points[A][1]));if(y.forEach(A=>{w.push(X(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(X(e.x+e.points[A][0],e.y+e.points[A][1]));let S=(l?.index??e.points.length)-(a?.index??0)-1,I=t.map(A=>A.index>s?{...A,index:A.index-S+(y.length-1)}:A),M=w.flatMap((A,G)=>{let L=w[G-1],N=w[G+1];if(L&&N){let D=Ze(A,L),j=Ze(N,A);if(ae(D,j))return I.forEach(H=>{H.index>G&&(H.index-=1)}),[];if(ae(D,os(j)))return I.forEach(H=>{H.index>G&&(H.index+=1)}),[A,A]}return[A]});return qt(M,I,!1,!1)},zp=(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=as(t[s].start,t[s].end),c=d<ie+5;if(a===-1&&t[s].index===1&&o){let w=qe(n),I=(w?ae(n,le):ae(n,Ie))?c?d/2:ie:c?-d/2:-ie;t[s].start=X(t[s].start[0]+(w?I:0),t[s].start[1]+(w?0:I))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=qe(i),I=(w?ae(i,le):ae(i,Ie))?c?d/2:ie:c?-d/2:-ie;t[s].end=X(t[s].end[0]+(w?I:0),t[s].end[1]+(w?0:I))}let u=t.map(w=>({...w,start:X(e.x+w.start[0],e.y+w.start[1]),end:X(e.x+w.end[0],e.y+w.end[1])})),m=e.points.map((w,S)=>X(e.x+w[0],e.y+w[1])),p=u[s].index-1,h=u[s].index,f=u[s].start,E=u[s].end,g=m[p-1]&&!Yi(m[p],m[p-1])?wt(m[p-1],m[p]):void 0,x=m[h+1]&&!Yi(m[h],m[h+1])?wt(m[h+1],m[h]):void 0;if(g!==void 0){let w=g?1:0;m[p-1][w]=f[w]}if(m[p]=f,m[h]=E,x!==void 0){let w=x?1:0;m[h+1][w]=E[w]}let b=u.findIndex(w=>w.index===p);if(b!==-1){let w=wt(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=wt(u[y].end,u[y].start)?1:0;u[y].end[w]=E[w],u[y].start=E}if(a===-1&&p===0){let w=o?qe(n):wt(m[1],m[0]);m.unshift(X(w?f[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:f[1])),o&&m.unshift(X(e.x+e.points[0][0],e.y+e.points[0][1]));for(let S of u)S.index+=o?2:1}if(l===-1&&h===e.points.length-1){let w=qe(i);m.push(X(w?E[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:E[1])),r&&m.push(X(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return qt(m,u.map(w=>({...w,start:X(w.start[0]-e.x,w.start[1]-e.y),end:X(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},Hp=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((E,g)=>g===0?X(e.x+E[0],e.y+E[1]):g===t.length-1?X(e.x+E[0],e.y+E[1]):X(e.x+e.points[g][0],e.y+e.points[g][1])),m=n.map(E=>({...E,start:X(e.x+(E.start[0]-t[0][0]),e.y+(E.start[1]-t[0][1])),end:X(e.x+(E.end[0]-t[0][0]),e.y+(E.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 E=u.at(d?2:1),g=u.at(d?3:2);if(!E||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=qe(i),b=qe(Lt(ls(E,g)));if(a&&x===b){let y=x?ae(i,le):ae(i,Ie);if(p.unshift(X(b?r[0]+(y?ie:-ie):g[0],b?g[1]:r[1]+(y?ie:-ie))),p.unshift(X(x?r[0]+(y?ie:-ie):r[0],x?r[1]:r[1]+(y?ie:-ie))),!d){d=!0;for(let w of m)w.index>1&&(w.index+=1)}}else if(p.unshift(X(b?r[0]:E[0],b?E[1]:r[1])),d){d=!1;for(let y of m)y.index>1&&(y.index-=1)}p.unshift(r)}{let E=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!E||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=qe(o),b=wt(g,E);if(l&&x===b){let y=x?ae(o,le):ae(o,Ie);p.push(X(b?s[0]+(y?ie:-ie):g[0],b?g[1]:s[1]+(y?ie:-ie))),p.push(X(x?s[0]+(y?ie:-ie):s[0],x?s[1]:s[1]+(y?ie:-ie))),c||(c=!0)}else p.push(X(b?s[0]:E[0],b?E[1]:s[1])),c&&(c=!1)}return p.push(s),qt(p,m.map(({index:E})=>({index:E,start:p[E-1],end:p[E]})).map(E=>({...E,start:X(E.start[0]-r[0],E.start[1]-r[1]),end:X(E.end[0]-r[0],E.end[1]-r[1])})),d,c)},hn=1e6,ci=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};B.PROD||(di(!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)"),di(!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"),di(!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"),di(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"),di(n.fixedSegments?.find(w=>w.index===1&&Yi(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&Yi(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&&Ho(d.elementId,t),m=c&&Ho(c.elementId,t),p=Vl(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 qt(r.map(w=>X(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:h,endHeading:f,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:b,...y}=cs({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?qt(r.map(w=>X(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?Fp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,S)=>Yi(w,e.points[S]??X(1/0,1/0)))&&p?{}:o.length===0?qt(ms(ps(us(e,{startHeading:h,endHeading:f,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:b,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?Rp(e,o,t):n.points?n.points&&n.fixedSegments?n:Hp(e,r,o,h,f,E,g,x,b):zp(e,o,h,f,x,b)},cs=(e,t,n,i)=>{let o=ss(n[0],Ct(e.x,e.y)),r=ss(n[n.length-1],Ct(e.x,e.y)),s=null,a=null;if(i?.isDragging&&i?.isBindingEnabled!==!1){let w=Array.from(t.values());s=Yl(o,t,w,i?.zoom)||null,a=Yl(r,t,w,i?.zoom)||null}else s=e.startBinding&&Ho(e.startBinding.elementId,t)||null,a=e.endBinding&&Ho(e.endBinding.elementId,t)||null;let l=Wl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),d=Wl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=Ul(l,d,s,o,t,i?.zoom),u=Ul(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?Ke(s,t,En(c,e.startArrowhead?Pe(s,{elbowed:!0})*6:Pe(s,{elbowed:!0})*2,1)):m,f=a?Ke(a,t,En(u,e.endArrowhead?Pe(a,{elbowed:!0})*6:Pe(a,{elbowed:!0})*2,1)):p,E=Bt(l,a?Ke(a,t,En(u,ie,ie)):p)||Bt(d,s?Ke(s,t,En(c,ie,ie)):m),g=Xl(E?[m,p]:[h,f]),x=Up(E?m:h,E?p:f,g,E?En(c,!s&&!a?0:ie,0):En(c,!s&&!a?0:ie-(e.startArrowhead?jn*6:jn*2),ie),E?En(u,!s&&!a?0:ie,0):En(u,!s&&!a?0:ie-(e.endArrowhead?jn*6:jn*2),ie),E,s&&Ke(s,t),a&&Ke(a,t)),b=_l(x[0],c,l),y=_l(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:b,startGlobalPoint:l,startHeading:c,endDonglePosition:y,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:E,startElementBounds:h,endElementBounds:f}},us=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Yp(n,i||o,r,s||a,l,d),m=i&&zo(i,u),p=s&&zo(s,u),h=zo(a,u);h&&c&&(h.closed=!0);let f=zo(o,u);f&&e.startBinding&&(f.closed=!0);let E=m&&p&&(Bt(m.pos,n[1])||Bt(p.pos,n[0])),g=_p(m||f,p||h,u,r||le,l||le,E?[]:n);if(g){let x=g.map(b=>[b.pos[0],b.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},En=(e,t,n)=>{switch(e){case He:return[t,n,n,n];case le:return[n,t,n,n];case Ie:return[n,n,t,n]}return[n,n,n,t]},_p=(e,t,n,i,o,r)=>{let s=rs(e.pos,t.pos),a=new Gp(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Wp(e,l);l.closed=!0;let d=Xp(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=Lp(u.pos,l.pos,.5);if(Np(...r.map(y=>Bt(m,y))))continue;let p=Vp(c),h=l.parent?Lt(ls(l.pos,l.parent.pos)):i,f=os(h);if(ae(f,p)||jl(e.addr,u.addr)&&ae(p,i)||jl(t.addr,u.addr)&&ae(p,o))continue;let g=h!==p,x=l.g+rs(u.pos,l.pos)+(g?Math.pow(s,3):0),b=u.visited;if(!b||x<u.g){let y=jp(u,t,p,o);u.visited=!0,u.parent=l,u.h=rs(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},Wp=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},rs=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Up=(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,E,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-p):(l[0]+d[2])/2:e[0]>t[0]?e[0]-p:n[0]-p,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+m):(l[3]+d[1])/2:e[3]<t[3]?e[3]+m:n[3]+m],b=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-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]+E):(d[3]+l[1])/2:t[3]<e[3]?t[3]+E:n[3]+E],y=Xl([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,M=b[3]+(x[1]-b[3])/2;return Ro(Ct(e[2]-w,e[1]-S),Ct(e[0]-w,e[3]-S))>0?[[x[0],x[1],I,x[3]],[I,b[1],b[2],b[3]]]:[[x[0],M,x[2],x[3]],[b[0],b[1],b[2],M]]}else if(e[2]<t[0]&&e[3]<t[1]){let I=x[2]+(b[0]-x[2])/2,M=x[3]+(b[1]-x[3])/2;return Ro(Ct(e[0]-w,e[1]-S),Ct(e[2]-w,e[3]-S))>0?[[x[0],x[1],x[2],M],[b[0],M,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,M=x[3]+(b[1]-x[3])/2;return Ro(Ct(e[2]-w,e[1]-S),Ct(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],M],[b[0],M,b[2],b[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let I=b[2]+(x[0]-b[2])/2,M=b[3]+(x[1]-b[3])/2;return Ro(Ct(e[0]-w,e[1]-S),Ct(e[2]-w,e[3]-S))>0?[[I,x[1],x[2],x[3]],[b[0],b[1],I,b[3]]]:[[x[0],M,x[2],x[3]],[b[0],b[1],b[2],M]]}}return[x,b]},Yp=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===De||n===le?a.add(t[1]):s.add(t[0]),o===De||o===le?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]})))}},_l=(e,t,n)=>{switch(t){case He:return X(n[0],e[1]);case le:return X(e[2],n[1]);case Ie:return X(n[0],e[3])}return X(e[0],n[1])},jp=(e,t,n,i)=>{if(i===le)switch(n){case le:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case He:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Ie:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case De:return e.pos[1]===t.pos[1]?4:2}else if(i===De)switch(n){case le:return e.pos[1]===t.pos[1]?4:2;case He:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Ie:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case De:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===He)switch(n){case le:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Ie:return e.pos[0]===t.pos[0]?4:2;case De:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===Ie)switch(n){case le:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He:return e.pos[0]===t.pos[0]?4:2;case Ie:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case De:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Xp=([e,t],n)=>[Ui([e,t-1],n),Ui([e+1,t],n),Ui([e,t+1],n),Ui([e-1,t],n)],Ui=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,zo=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=Ui([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Xl=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]))],Ho=(e,t)=>{let n=t.get(e);return n&&fe(n)?n:null},qt=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>ss(a,Cp(ls(e[0]),-1)));return(o<-hn||o>hn||r<-hn||r>hn||o+s[s.length-1][0]<-hn||o+s[s.length-1][0]>hn||r+s[s.length-1][1]<-hn||r+s[s.length-1][1]>hn)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...Hl(s)}),s=s.map(([a,l])=>X(Fo(a,-1e6,1e6),Fo(l,-1e6,1e6))),{points:s,x:Fo(o,-1e6,1e6),y:Fo(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Hl(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},ps=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return as(i,t)>ds}):e,Vp=e=>{switch(e){case 0:return He;case 1:return le;case 2:return Ie}return De},Wl=(e,t,n,i,o,r,s,a=!0,l=!0)=>s?a&&o&&r?fs(e,o,t,r,void 0,l):i:o?Ge(n||[0,0],o,r??kp([o])):i,Ul=(e,t,n,i,o,r)=>$l(e,t,n,n&&Ke(n,o,Array(4).fill(pn(n,o,e))),i,o,r),Yl=(e,t,n,i)=>Vt(e,n,t,gt(i)),jl=(e,t)=>e[0]===t[0]&&e[1]===t[1],Vl=(e,t=ds)=>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 ve=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;W(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...ci({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...$p(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")&&rt.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??hs(),e.updated=Es()),e},_e=(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??hs(),updated:Es()}},Zl=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=hs(),e.updated=Es(),e);var nd=5,jn=5,ef=10,Xi=10/1.5,Yo=1,Pe=(e,t)=>(t.elbowed?jn:nd)+e.strokeWidth/2,gt=e=>{let t=Math.max(nd,15),n=e?.value&&e.value<1?e.value:1;return Uo(t/(n*1.5),t,t*2)},Gt=e=>e.isBindingEnabled,tf=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=bs(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0}),d=r.isMidpointSnappingEnabled&&!s?.angleLocked&&!r.gridModeEnabled;if(ql(e,a,"start",o,r.isBindingEnabled,d),ql(e,l,"end",o,r.isBindingEnabled,d),a.focusPoint||l.focusPoint){let c=new Map;a.focusPoint&&c.set(0,{point:yt(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&c.set(e.points.length-1,{point:yt(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),C.movePoints(e,o,c)}return{start:a,end:l}},ql=(e,{mode:t,element:n,focusPoint:i},o,r,s=!0,a=!0)=>{t===null?Fe(e,o,r):t!==void 0&&Nt(e,n,t,o,r,i,s,a)},id=(e,t,n,i,o)=>{Kt(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;Kt(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=C.getPointGlobalCoordinates(e,a,n),d=Vt(l,i,n,gt(o)),c=d?{element:d,mode:"orbit",focusPoint:C.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},nf=(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=C.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),f=Vt(h,i,n);if(o)return f?u={element:f,mode:"inside",focusPoint:h}:u={mode:null},{start:u,end:m};if(r){let E=l?.selectedLinearElement?.initialState.origin;if(f&&e.startBinding?.elementId===f.id){let g=$(f.x+f.width/2,f.y+f.height/2);return{start:p?{mode:void 0}:{mode:"inside",element:f,focusPoint:E??g},end:p?{mode:"orbit",element:f,focusPoint:h}:{mode:"inside",element:f,focusPoint:h}}}if(f&&e.startBinding){let g=e.startBinding;if(Lo(h,i,n).find(b=>b.id===g.elementId)){let b=n.get(e.startBinding.elementId);return Kt(b,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:b.id!==f.id?"orbit":"inside",element:b,focusPoint:E??$(e.x,e.y)},end:{mode:"orbit",element:f,focusPoint:h}}}}if(e.startBinding&&e.startBinding.elementId!==f?.id){let g=n.get(e.startBinding.elementId);Kt(g,"Other element must be in the elements map");let b={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:g,focusPoint:c?re(g,n):E??$(e.x,e.y)},y=f&&ns(g,f,n),w;if(f){let S=d==="inside"||d==="skip";w={mode:S&&!y?"inside":"orbit",element:f,focusPoint:h}}else w={mode:null};return{start:p?{mode:void 0}:b,end:w}}if(!e.startBinding)return f?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:f,focusPoint:h}:m={mode:null},{start:u,end:m}}Kt(!1,"New arrow creation should not reach here")},Kl=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=Vt(e,o,i),m=n?Lo(e,o,i).some(E=>E.id===n.elementId):!1,p=n?i.get(n.elementId):null,h=m&&p?qp(p.backgroundColor):!1,f=u&&p&&ns(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}},bs=(e,t,n,i,o,r,s,a)=>Zp("COMPLEX_BINDINGS")?of(e,t,o,r,s,a):od(e,t,n,i,o,r,s,a),od=(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(!Gt(s))return m=c?{mode:null}:m,p=u?{mode:null}:p,{start:m,end:p};if(W(e))return id(e,t,o,r,a?.zoom);let h=c?e.endBinding:e.startBinding,f=t.get(c?0:d)?.point;Kt(f,`Local point must be defined for ${c?"start":"end"} dragging`);let E=C.getPointGlobalCoordinates(e,f,o),g=Vt(a?.angleLocked||s.gridModeEnabled?$(n,i):E,r,o,gt(s.zoom)),x=g&&(a?.angleLocked?Yt($(n,i),g,o):Yt(E,g,o)),b=h?o.get(h.elementId):void 0,y=h&&b&&Ge(h.fixedPoint,b,o),w=b&&y&&Dt({point:y,element:b,elementsMap:o,threshold:0,overrideShouldTestInside:!0}),S=s.selectedLinearElement?.initialState.arrowOtherEndpointInitialBinding;if(h&&h.elementId===g?.id&&(!a?.newArrow||s.selectedLinearElement?.initialState.origin))return{start:{mode:"inside",element:g,focusPoint:c?E:a?.newArrow?Qp(xs(s.selectedLinearElement.initialState.origin[0],s.selectedLinearElement.initialState.origin[1],a.gridSize)):b?Ge(h.fixedPoint,b,o):C.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:g,focusPoint:u?E:b?Ge(h.fixedPoint,b,o):C.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:m,end:u?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:p};let I=g?x?{mode:"inside",element:g,focusPoint:E}:{mode:"orbit",element:g,focusPoint:Hr(e,a?.angleLocked?E:s.gridModeEnabled?cf($(n,i),g,o,s.gridSize,e,C.getPointAtIndexGlobalCoordinates(e,c?1:-2,o)):E,g,c?"start":"end",o,s.zoom,s.isMidpointSnappingEnabled&&!a?.angleLocked&&!s.gridModeEnabled)||E}:{mode:null},M=C.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),A=y&&b&&Dt({point:E,element:b,elementsMap:o,threshold:gt(s.zoom),overrideShouldTestInside:!0}),G=S?.mode==="inside",L=a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:h?.mode==="inside"&&G,N={mode:void 0};return L||(h?.mode==="inside"&&!G&&b&&!a?.newArrow?N={mode:"orbit",element:b,focusPoint:y||M}:b&&!w&&!A&&s.selectedLinearElement?.initialState.altFocusPoint?N={mode:"orbit",element:b,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&b&&(N={mode:"orbit",element:b,focusPoint:Hr(e,M,b,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||M})),{start:c?I:N,end:u?I:N}},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(!Gt(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(W(e))return id(e,t,n,i);if(r?.newArrow){let{start:p,end:h}=nf(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;Kt(p,"Local point must be defined for start dragging");let h=C.getPointGlobalCoordinates(e,p,n),{current:f,other:E}=Kl(h,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:f,end:E}}if(c){let p=t.get(l)?.point;Kt(p,"Local point must be defined for end dragging");let h=C.getPointGlobalCoordinates(e,p,n),{current:f,other:E}=Kl(h,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:E,end:f}}return{start:u,end:m}},cP=(e,t,n)=>{e.forEach(i=>{tf(i,new Map,1/0,1/0,t,n)})},rd=(e,t,n,i,o)=>{o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:n}),td(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Nt=(e,t,n,i,o,r,s=!0,a=!0)=>{let l=o.getNonDeletedElementsMap(),d;W(e)?d={elementId:t.id,mode:"orbit",...uf(e,t,i,l,s,a)}:d={elementId:t.id,mode:n,...pi(e,t,i,l,r)},rd(e,t,d,i,o)},Fe=(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},Re=(e,t,n)=>{if(!fe(e))return;let{simultaneouslyUpdated:i}=n??{},o=sf(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),jo(r,e,a=>{if(a&&!ze(a)&&console.error("[NONDELETED][INVARIANT] updateBoundElements(): `isDeleted: true` in visitor"),!_(a)||!ze(a)||!rf(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=Xo(r,a,(m,p)=>{if(m&&fe(m)&&(p==="startBinding"||p==="endBinding")&&(e.id===a[p]?.elementId||e.id===a[p==="startBinding"?"endBinding":"startBinding"]?.elementId)){let h=yt(a,p,a[p],m,r);if(h)return[p==="startBinding"?0:a.points.length-1,{point:h}]}return null}).filter(m=>m!==null);C.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=ne(a,r);u&&!u.isDeleted&&Yn(a,t,!1)})},Ql=(e,t,n,i,o)=>{Kt(!W(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=C.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&Dt({element:s,point:a,elementsMap:n,threshold:gt(o.zoom)}),d=t==="startBinding"?"start":"end";if(Fe(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],m=od(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&&Nt(e,s,m[d].mode,d,i,m[d].focusPoint)}},uP=(e,t,n,i)=>{if(_(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&Ql(e,"startBinding",o,t,n),e.endBinding&&Ql(e,"endBinding",o,t,n)}else Re(e,t,{...i,changedElements:new Map([[e.id,e]])})},rf=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,sf=e=>new Set((e||[]).map(t=>t.id)),$l=(e,t,n,i,o,r,s)=>{let a=Lt(mi(t,e));return!n||!i?a:af(o,n,r,s)?li(n,i,e):Lt(mi(e,re(n,r)))},af=(e,t,n,i)=>{let o=pn(t,n,e),r=gt(i);return o>r?null:o},fs=(e,t,n,i,o,r=!0)=>{let s=W(e),a=C.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return a;let l=il(t)&&s?lf(e,t,i,a):a,d=o&&!s?o[1]:C.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),c=Pe(t,e),u=Ke(t,i),m=$t(u),p=null;if(s){let h=qe(li(t,u,a)),E=(r?ws(t,i,l,.05,e):void 0)||a,g=$(h?m[0]:E[0],h?E[1]:m[1]),x=o??ui(g,_o(Wo(gs(mi(E,g)),Math.max(t.width,t.height)*2),g));if(p=ut(t,i,x,c).sort(st)[0],!p){let b=$(h?E[0]:m[0],h?m[1]:E[1]),y=ui(b,_o(Wo(gs(mi(E,b)),Math.max(t.width,t.height)*2),b));p=ut(t,i,y,jn).sort(st)[0]}}else{let h=o;if(!h){let f=Wo(gs(mi(l,d)),gn(l,d)+Math.max(t.width,t.height)+c*2);h=o??ui(_o(f,d),_o(Wo(f,-1),d))}p=gn(l,d)<1?l:ut(t,i,h,c).sort((f,E)=>st(f,d)-st(E,d))[0]}return!p||st(l,p)<Kp?l:p},lf=(e,t,n,i)=>{let o=re(t,n),r=ce(i,o,-t.angle),s=Pe(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?ce($(t.x-s,t.y),o,t.angle):ce($(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?ce($(t.x,t.y+t.height+s),o,t.angle):ce($(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?ce($(t.x+t.width,t.y+t.height+s),o,t.angle):ce($(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?ce($(t.x+t.width,t.y-s),o,t.angle):ce($(t.x+t.width+s,t.y),o,t.angle):i},ws=(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=ce(n,c,-d),m=o?Pe(e,o):0,p=Uo(i*l,5,80),h=Uo(i*a,5,80);if(!(gn(c,u)<m)){if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return ce($(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-h&&u[0]<c[0]+h)return ce($(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return ce($(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-h&&u[0]<c[0]+h)return ce($(c[0],s+l+m),c,d);if(e.type==="diamond"){let f=m,E=$(r+a/4-f,s+l/4-f),g=$(r+3*a/4+f,s+l/4-f),x=$(r+a/4-f,s+3*l/4+f),b=$(r+3*a/4+f,s+3*l/4+f);if(gn(E,u)<Math.max(h,p))return ce(E,c,d);if(gn(g,u)<Math.max(h,p))return ce(g,c,d);if(gn(x,u)<Math.max(h,p))return ce(x,c,d);if(gn(b,u)<Math.max(h,p))return ce(b,c,d)}}},df=(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:Ge(Ne(i.fixedPoint),o,n),binding:i,mode:i.mode}},cf=(e,t,n,i,o,r)=>{if(!i)return e;let s=Ke(t,n),a=r&&(t.type==="ellipse"||t.type==="diamond")?Lt(mi(r,e)):li(t,s,e),l=Pe(t,o),d=Math.max(t.width,t.height)+l*2,c=$t(s),u=Math.abs(a[0]),m=Math.abs(a[1]);if(u>=m){let[,E]=xs(e[0],e[1],i),g=ui($(c[0]-d,E),$(c[0]+d,E));return ut(t,n,g,l).sort((b,y)=>st(b,e)-st(y,e))[0]??$(e[0],E)}let[p]=xs(e[0],e[1],i),h=ui($(p,c[1]-d),$(p,c[1]+d));return ut(t,n,h,l).sort((E,g)=>st(E,e)-st(g,e))[0]??$(p,e[1])},Jl=e=>e.width*e.height,yt=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||Jp(e.points[e.points.length-1],$(0,0)))return null;let s=Ge(Ne(n.fixedPoint),i,o);if(n.mode==="inside")return C.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=df(e,t==="startBinding"?"endBinding":"startBinding",o),d=C.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&ui(s,c),m=a&&u&&ut(a,o,u,Pe(a,e)).sort((b,y)=>st(b,s)-st(y,s))[0],p=u&&ut(i,o,u,Pe(i,e)).sort((b,y)=>st(b,c)-st(y,c))[0],h=e.startArrowhead!==null,f=e.endArrowhead!==null,E=!h&&!f||t==="startBinding"&&h||t==="endBinding"&&f?s:p||s;if(a&&p&&!r&&Jl(a)<Jl(i)*2&&Dt({element:a,point:p,elementsMap:o,threshold:Pe(a,e),overrideShouldTestInside:!0}))return C.createPointAt(e,o,E[0],E[1],null);let x=gn(a&&(m||l)||d,p||s)<=ef;return a?x?C.createPointAt(e,o,E?.[0]||s[0],E?.[1]||s[1],null):C.createPointAt(e,o,p?.[0]||s[0],p?.[1]||s[1],null):C.createPointAt(e,o,x?s[0]:p?.[0]??s[0],x?s[1]:p?.[1]??s[1],null)},uf=(e,t,n,i,o=!0,r=!0)=>{let s=[t.x,t.y,t.x+t.width,t.y+t.height],a=o?fs(e,t,n,i,void 0,r):C.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),l=$(s[0]+(s[2]-s[0])/2,s[1]+(s[3]-s[1])/2),d=ce(a,l,-t.angle);if(t.width<Yo||t.height<Yo)return{fixedPoint:Ne([.5,.5])};let c=Pe(t,e);return{fixedPoint:Ne([(d[0]-t.x)/Math.max(t.width,c),(d[1]-t.y)/Math.max(t.height,c)])}},pi=(e,t,n,i,o)=>{let r=o||C.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=re(t,i),a=ce(r,s,-t.angle);if(t.width<Yo||t.height<Yo)return{fixedPoint:Ne([.5,.5])};let l=Pe(t,e),d=(a[0]-t.x)/Math.max(t.width,l),c=(a[1]-t.y)/Math.max(t.height,l);return{fixedPoint:Ne([d,c])}},sd=(e,t,n)=>{for(let i of e){if("boundElements"in i&&i.boundElements&&Object.assign(i,{boundElements:i.boundElements.reduce((o,r)=>{let s=t.get(r.id);return s&&o.push({...r,id:s}),o},[])}),"containerId"in i&&i.containerId&&Object.assign(i,{containerId:t.get(i.containerId)??null}),"endBinding"in i&&i.endBinding){let o=t.get(i.endBinding.elementId);Object.assign(i,{endBinding:o?{...i.endBinding,elementId:o}:null})}if("startBinding"in i&&i.startBinding){let o=t.get(i.startBinding.elementId);Object.assign(i,{startBinding:o?{...i.startBinding,elementId:o}:null})}W(i)&&Object.assign(i,ci(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},mP=(e,t)=>{let n=td(e);for(let i of t)xn.unbindAffected(n,i,(o,r)=>ve(o,n,r)),bn.unbindAffected(n,i,(o,r)=>ve(o,n,r))},ji=(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},ad=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),jo=(e,t,n)=>{fe(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},Xo=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(xe(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(_(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},xn=class{static unbindAffected(t,n,i){n&&Xo(t,n,o=>{!o||o.isDeleted||jo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:ji(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||Xo(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(_(n)&&i(o,{boundElements:ji(o.boundElements,new Set,new Array(n))}),Q(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:ji(o.boundElements,new Set,new Array(n))}))))})}},bn=class{static unbindAffected(t,n,i){n&&jo(t,n,o=>{!o||o.isDeleted||Xo(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||jo(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:ji(n.boundElements,new Set([s]))});return}Q(o)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===o.id?o.containerId!==n.id&&i(o,{containerId:n.id}):(o.containerId!==null&&i(o,{containerId:null}),i(n,{boundElements:ji(n.boundElements,new Set([o.id]))})))})}},Ge=(e,t,n)=>{let[i,o]=Ne(e);return ce($(t.x+t.width*i,t.y+t.height*o),re(t,n),t.angle)},mf=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?Ge(e.startBinding.fixedPoint,n,t):$(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?Ge(e.endBinding.fixedPoint,i,t):$(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]=mf(e,t);return[C.pointFromAbsoluteCoords(e,n,t),C.pointFromAbsoluteCoords(e,i,t)]},pf=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),ed=10,Ne=e=>{if(!pf(e))return[.5001,.5001];let t=1e-4,n=e.map(i=>Uo(i,-ed,ed));return Math.abs(n[0]-.5)<t||Math.abs(n[1]-.5)<t?n.map(i=>Math.abs(i-.5)<t?.5001:i):n},ff=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",hf={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"}]},Ef=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}}),gf=(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=hf[t],d=Ef(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},pP=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!fe(n))return null;let i=re(n,t),o=ff(n),r=gf(Ne(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=un(n),[d,c,u,m]=a,p,h;switch(r){case"left":{if(l.length>=3){let E=l[2][1];p=E[0]-s,h=E[1]}else{let f=ke(c[1],u[0]);p=f[0]-s,h=f[1]}break}case"right":{if(l.length>=1){let E=l[0][1];p=E[0]+s,h=E[1]}else{let f=ke(m[1],d[0]);p=f[0]+s,h=f[1]}break}case"top":{if(l.length>=4){let E=l[3][1];p=E[0],h=E[1]-s}else{let f=ke(u[1],m[0]);p=f[0],h=f[1]-s}break}case"bottom":{if(l.length>=2){let E=l[1][1];p=E[0],h=E[1]+s}else{let f=ke(d[1],c[0]);p=f[0],h=f[1]+s}break}case"top-right":{let f=ke(m[0],m[1]);p=f[0]+s*.707,h=f[1]-s*.707;break}case"bottom-right":{let f=ke(d[0],d[1]);p=f[0]+s*.707,h=f[1]+s*.707;break}case"bottom-left":{let f=ke(c[0],c[1]);p=f[0]-s*.707,h=f[1]+s*.707;break}case"top-left":{let f=ke(u[0],u[1]);p=f[0]-s*.707,h=f[1]-s*.707;break}default:return null}return ce($(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 ce($(u,m),i,n.angle)}if(ki(n)){let[a,l]=cn(n),[d,c,u,m]=a,p,h;switch(r){case"top":{let f=ke(d[0],d[1]);p=f[0],h=f[1]-s;break}case"right":{let f=ke(c[0],c[1]);p=f[0]+s,h=f[1];break}case"bottom":{let f=ke(u[0],u[1]);p=f[0],h=f[1]+s;break}case"left":{let f=ke(m[0],m[1]);p=f[0]-s,h=f[1];break}case"top-left":{if(l.length>=1){let f=l[0],E=f[0],g=f[3],x=ke(E,g);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],E=f[0],g=f[3],x=ke(E,g);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],E=f[0],g=f[3],x=ke(E,g);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],E=f[0],g=f[3],x=ke(E,g);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 ce($(p,h),i,n.angle)}return null},ke=(e,t)=>$((e[0]+t[0])/2,(e[1]+t[1])/2),fP=(e,t,n,i,o)=>{rd(e,t,{elementId:t.id,fixedPoint:Ne(i),mode:"orbit"},n,o)};var ys=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>O(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},C=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,cd(t.points[0],O(0,0))||(console.error("Linear element is not normalized",Error().stack),ve(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=W(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,m]=V(n.selectionElement,o),h=e.getPointsGlobalCoordinates(l,o).reduce((f,E,g)=>((E[0]>=d&&E[0]<=u&&E[1]>=c&&E[1]<=m||t.shiftKey&&s?.includes(g))&&f.push(g),f),[]).filter(f=>!(W(l)&&f!==0&&f!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:h.length?h:null}})}static handlePointerMove(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);Qe(d,"Element being dragged must exist in the scene"),Qe(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??gd(m,d.points[c]),h=0,f=0;if(Vn(t)){let[S,I]=e._getShiftLockedDelta(d,s,m,O(i,o),t[Xn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),M=O(S+m[0],I+m[1]);h=M[0]-u[0],f=M[1]-u[1]}else{let S=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Xn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());h=S[0]-u[0],f=S[1]-u[1]}let E=null,{positions:g,updates:x}=Ed([c],h,f,i,o,s,d,a,n,Vn(t),t.altKey,r),b=Vn(t);if(e.movePoints(d,n.scene,g,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!b&&!n.state.gridModeEnabled}),Ce(d,!1)&&Gt(n.state)&&(E=x?.suggestedBinding??null),Ce(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&&(!E||Pf(n.state.suggestedBinding??[],E)))return null;let y=Ce(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?hd(d,O(d.x,d.y),y,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!b&&!n.state.gridModeEnabled):r.initialState.altFocusPoint}},suggestedBinding:E}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);Qe(p,"Element being dragged must exist in the scene"),Qe(p.points.length>1,"Element must have at least 2 points"),Qe(u,"There must be selected points in order to drag them"),l&&u.some((F,U)=>F>0&&F!==p.points.length-1?(u[U]=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],E=u.length===1,g=r.customLineAngle??gd(f,p.points[m]),x=u.includes(0),b=u.includes(p.points.length-1),y=0,w=0;if(Vn(t)&&E){let[F,U]=e._getShiftLockedDelta(p,s,f,O(i,o),t[Xn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),g),ge=O(F+f[0],U+f[1]);y=ge[0]-h[0],w=ge[1]-h[1]}else{let F=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Xn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=F[0]-h[0],w=F[1]-h[1]}let S=null,{positions:I,updates:M}=Ed(u,y,w,i,o,s,p,a,n,Vn(t)&&E,t.altKey,r),A=Vn(t)&&E;e.movePoints(p,n.scene,I,{startBinding:M?.startBinding,endBinding:M?.endBinding,moveMidPointsWithElement:M?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled&&!A&&!n.state.gridModeEnabled}),Ce(p,!1)&&Gt(n.state)&&(x||b)&&(S=M?.suggestedBinding??null),Ce(p)&&x!==b&&fd(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),ne(p,s)&&Yn(p,n.scene,!1);let L=l?b?[p.points.length-1]:[0]:u,N=l?L[0]:m,D=!x&&!b?e.getPointGlobalCoordinates(p,h,s):null,j=N,H=Ce(p)&&p.startBinding&&s.get(p.startBinding.elementId),Z=Ce(p)&&p.endBinding&&s.get(p.endBinding.elementId),k=b&&H&&M?.suggestedBinding?.element.id!==H.id?H:x&&Z&&M?.suggestedBinding?.element.id!==Z.id?Z:null;return{selectedLinearElement:{...r,selectedPointsIndices:L,initialState:{...r.initialState,lastClickedPoint:N,altFocusPoint:!r.initialState.altFocusPoint&&Ce(p)&&k?hd(p,O(p.x,p.y),k,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled&&!A&&!n.state.gridModeEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:D,hoverPointIndex:j,isDragging:!0,customLineAngle:g},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)&&If(c.points,i.zoom.value)&&(Et(c)&&o.mutateElement(c,{...xd(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=ne(t,n);if(!W(t)&&!i.selectedLinearElement?.isEditing&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom,n)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1,n);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!W(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!W(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&$n(O(c[0],c[1]),O(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&$n(m[u],O(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r,s){if(W(t))return o>=0&&o<t.points.length?$n(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let a=$n(n,i);if(t.points.length>2&&t.roundness){let[l,d]=md(t,s);Qe(l.length===0&&d.length>0,"Only linears built out of curves are supported"),Qe(l.length+d.length>=o,"Invalid segment index while calculating mid point"),a=bf(d[o])}return a*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n,i){if(W(t)){Qe(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let s=dd(t.points[n-1],t.points[n]);return O(t.x+s[0],t.y+s[1])}let[o,r]=md(t,i);if(Qe(o.length===0&&r.length>0||o.length>0&&r.length===0,"Only linears built out of either segments or curves are supported"),Qe(o.length+r.length>=n,"Invalid segment index while calculating mid point"),o.length){let s=o[n-1];return dd(s[0],s[1])}if(r.length){let s=r[n-1];return wf(s,.5)}Qe(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let m=e.getSegmentMidpointHitCoords(r,o,a,l),p=O(o.x,o.y),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[Xn.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[E,g,x,b]=V(u,l),y=(E+x)/2,w=(g+b)/2,S=f>-1&&We(O(u.x+u.points[f][0],u.y+u.points[f][1]),O(y,w),u.angle),I=f>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(f)?Sf([...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:I?.includes(0)?u.endBinding:u.startBinding},selectedPointsIndices:I,pointerOffset:S?{x:o.x-S[0],y:o.y-S[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:cd(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(Vn(t)&&c.length>=2){let p=c[c.length-2],[h,f]=e._getShiftLockedDelta(d,l,p,O(n,i),t[Xn.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=O(h+p[0],f+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[Xn.CTRL_OR_CMD]||W(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:m}]])):e.addPoints(d,o.scene,[m]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=V(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return We(O(c+n[0],u+n[1]),O(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=V(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return We(O(c+d[0],u+d[1]),O(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=V(t,i),a=O(r,s),l=t.points[o],{x:d,y:c}=t;return l?We(O(d+l[0],c+l[1]),a,t.angle):We(O(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(W(t))return O(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=V(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=We(O(n[0],n[1]),O(l,d),-t.angle);return O(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if($n(O(o,r),O(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=ud(i,o,r),[a,l,d,c]=V(t,n),u=(a+d)/2,m=(l+c)/2,[p,h]=We(O(s[0],s[1]),O(u,m),-t.angle);return O(p-t.x,h-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=ys(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){Qe(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);Qe(s,"The linear element does not exist in the provided Scene"),Qe(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 E=a[h+1];E||(d=!0),m.push(E?O((p[0]+E[0])/2,(p[1]+E[1])/2):O(p[0],p[1])),l.push(c+1),++c}return m},[]);if(n.mutateElement(s,{points:u}),d){let m=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:O(m[0]+30,m[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!i.includes(u));Et(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=O(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=ys({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];Et(t)&&t.polygon&&(o[0]=O(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=ys({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o,r){let{points:s}=t;if(Et(t)&&t.polygon){let u=i.get(0),m=i.get(s.length-1);u?i.set(s.length-1,{point:O(u.point[0],u.point[1]),isDragging:u.isDragging}):m&&i.set(0,{point:O(m.point[0],m.point[1]),isDragging:m.isDragging})}let a=i.get(0)?.point??O(0,0),[l,d]=a,c=W(t)?[i.get(0)?.point??s[0],i.get(s.length-1)?.point??s[s.length-1]]:s.map((u,m)=>{let p=i.get(m)?.point??u;return o?.moveMidPointsWithElement&&m!==0&&m!==s.length-1&&!i.has(m)?p:O(p[0]-l,p[1]-d)});e._updatePoints(t,n,c,l,d,o,{isDragging:Array.from(i.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&W(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=$n(a,O(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<yf/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!W(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.initialState,segmentMidpoint:{...t.initialState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,i,o,r,s,a){if(W(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=Ps(t,i),d=Ps(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,m=(d[0]+d[2])/2,p=(d[1]+d[3])/2,h=m-c,f=p-u,E=We(O(o,r),O(h,f),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+E[0],y:t.y+E[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(W(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=ud(o[0],o[1],r),{width:c,height:u}=bd(a[0],a[1],l,d,s);return We(O(c,u),O(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&&ve(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=O(d,c),E=We(O(r,s),f,t.angle),g=We(O(a,s),f,t.angle),x=We(O(u,m),f,-t.angle),b=We(O(p,m),f,-t.angle),y=We(O(u,h),f,-t.angle),w=We(O(p,h),f,-t.angle);return E[0]<g[0]&&E[1]>=g[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])):E[0]>=g[0]&&E[1]>g[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])):E[0]>=g[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])):E[1]<=g[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=rt.generateElementShape(t,null),r=Ht(o[0]),[s,a,l,d]=Vi(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,E=i&&ne(t,n);return E?e.getMinMaxXYWithBoundText(t,n,[c,u,m,p],E):[c,u,m,p,h,f]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!W(a))return t;if(n&&n>0&&n<a.points.length){let l=qe(Lt(xf(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,h)=>(p[h.index]=h,p),{});d[n]={index:n,start:O(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:O(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((p,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=O(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:m,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:m}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},Sf=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},Ed=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let m=new Map(e.map(H=>{let Z=s.points[H]??s.points.at(-1);return[H,{point:O(Z[0]+t,Z[1]+n),isDragging:!0}]}));if(!_(s))return{positions:m};let p=e.includes(0),h=e.includes(s.points.length-1),{start:f,end:E}=bs(s,m,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c,gridSize:l.getEffectiveGridSize()});if(W(s)){let H=p?f.element:h?E.element:null;return{positions:m,updates:{suggestedBinding:H?{element:H,midPoint:l.state.isMidpointSnappingEnabled?ws(H,r,O(i-u.pointerOffset.x,o-u.pointerOffset.y)):void 0}:null}}}if(!p&&!h){let H={...s,points:s.points.map((k,T)=>m.get(T)?.point??k)},Z=new Map(m);if(s.startBinding){let k=r.get(s.startBinding.elementId);if(k){let T=yt(H,"startBinding",s.startBinding,k,r)??null;T&&Z.set(0,{point:T,isDragging:!0})}}if(s.endBinding){let k=r.get(s.endBinding.elementId);if(k){let T=yt(H,"endBinding",s.endBinding,k,r)??null;T&&Z.set(s.points.length-1,{point:T,isDragging:!0})}}return{positions:Z}}if(p===h)return{positions:m};let g={suggestedBinding:null};f.mode===null?g.startBinding=null:f.mode?(g.startBinding={elementId:f.element.id,mode:f.mode,...pi(s,f.element,"start",r,f.focusPoint)},p&&(g.startBinding.mode==="orbit"||!fi("COMPLEX_BINDINGS"))&&(g.suggestedBinding=f.element?{element:f.element,midPoint:pd(O(i-u.pointerOffset.x,o-u.pointerOffset.y),f.element,r,l.state.zoom)}:null)):p&&(g.suggestedBinding=l.state.suggestedBinding),E.mode===null?g.endBinding=null:E.mode?(g.endBinding={elementId:E.element.id,mode:E.mode,...pi(s,E.element,"end",r,E.focusPoint)},h&&(g.endBinding.mode==="orbit"||!fi("COMPLEX_BINDINGS"))&&(g.suggestedBinding=E.element?{element:E.element,midPoint:pd(O(i-u.pointerOffset.x,o-u.pointerOffset.y),E.element,r,l.state.zoom)}:null)):h&&(g.suggestedBinding=l.state.suggestedBinding);let x=p?O(s.points[0][0]+t,s.points[0][1]+n):s.points[0],b=h?O(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:g.startBinding===void 0?s.startBinding:g.startBinding===null?null:g.startBinding,endBinding:g.endBinding===void 0?s.endBinding:g.endBinding===null?null:g.endBinding},w=s.endBinding&&y.startBinding&&p&&y.startBinding.elementId===s.endBinding.elementId,S=s.startBinding&&y.endBinding&&h&&s.startBinding.elementId===y.endBinding.elementId,I=y.endBinding?E.element??r.get(y.endBinding.elementId):null,M=S&&l.state.bindMode!=="inside"&&fi("COMPLEX_BINDINGS")?y.points[0]:I&&yt(y,"endBinding",y.endBinding,I,r,h)||y.points[y.points.length-1];y.points[y.points.length-1]=M;let A=y.startBinding?f.element??r.get(y.startBinding.elementId):null,G=S&&fi("COMPLEX_BINDINGS")?y.points[0]:w&&l.state.bindMode!=="inside"&&fi("COMPLEX_BINDINGS")?M:A&&yt(y,"startBinding",y.startBinding,A,r,p)||y.points[0],L=!(S&&l.state.bindMode!=="inside"&&fi("COMPLEX_BINDINGS"))&&!!I,N=$n(G,y.points[0])!==0,D=new Set(e);A&&N&&D.add(0),I&&L&&D.add(s.points.length-1);let j=Array.from(D);return{updates:g,positions:new Map(j.map(H=>[H,H===0?{point:G,isDragging:!0}:H===s.points.length-1?{point:M,isDragging:!0}:m.get(H)]))}},gd=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);P();import{arrayToMap as Pt}from"@excalidraw/common";import{isPointWithinBounds as Hf,pointFrom as vs,segmentsIntersectAt as _f}from"@excalidraw/math";P();import{arrayToMap as Bf,isShallowEqual as Lf}from"@excalidraw/common";P();var Af=(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}}},wd=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:Is({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):Ot(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Is(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),Mf=(e,t)=>Ss(e,t)!=null,Ss=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Tf=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,...Af(r,n,e)}}}return n.selectedGroupIds},OP=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Df=(e,t)=>e.groupIds.includes(t),Ue=(e,t)=>{let n=[];for(let i of e.values())Df(i,t)&&n.push(i);return n},vf=(e,t)=>e.groupIds.find(n=>t[n]),kP=(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},FP=(e,t)=>e.filter(n=>!t[n]),RP=(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=ne(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},Pd=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},Id=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},Sd=e=>e.groupIds.length>0,Ad=(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},Vo=(e,t,n)=>{let i=new Map,r=Tf(n).length===1&&e.every(s=>Mf(n,s));return e.forEach(s=>{if(xe(s))return;let a,l=vf(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=ne(s,t);i.set(a,[...d,s,...c?[c]:[]])}),[...i.values()]};var Cf=e=>e.locked||xe(e),Gf=(e,t)=>e.filter(n=>!(n.frameId&&t.has(n.frameId))),Nf=e=>{let t=new Set;return e.forEach(n=>{q(n)&&t.add(n.id)}),Gf(e,t)},Md=(e,t,n,i=!0,o="contain")=>{let[r,s,a,l]=V(t,n),d=Math.min(r,a),c=Math.min(s,l),u=Math.max(r,a),m=Math.max(s,l);return Td({elements:e,bounds:[d,c,u,m],elementsMap:n,type:o,shouldIgnoreElementFromSelection:Cf,excludeElementsInFrames:i})},ZP=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=Dd(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},qP=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}(),Ot=(e,t,n)=>{let i=new Set,o=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){ze(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&&xe(r)&&ze(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{q(s)&&wn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},KP=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement&&t.activeTool.type!=="autoshape"?[t.newElement]:Ot(e,t,{includeBoundTextElement:!0}),Is=(e,t)=>Lf(t.selectedElementIds,e)?t.selectedElementIds:e,Of=(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 C(i,Bf(t))}return null},QP=(e,t,n)=>({selectedLinearElement:Of(e,t),...wd({editingGroupId:n.editingGroupId,selectedElementIds:Nf(e).reduce((i,o)=>(xe(o)||(i[o.id]=!0),i),{})},t,n,null)}),JP=(e,t)=>t.editingTextElement||e.length===1&&Q(e[0])&&e[0]||null;P();import{arrayToMap as $o}from"@excalidraw/common";import{validateOrderKey as kf,generateNKeysBetween as Ff}from"@excalidraw/fractional-indexing";var As=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Rf=(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?$o(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(Ms(c,u,m)||r.push(`Fractional indices invariant has been compromised: "${s(e[d-1])}", "${s(e[d])}", "${s(e[d+1])}"`),n&&a&&Tt(e[d])&&ze(e[d])){let p=e[d],h=bt(p),f=h?a.get(h):null;f&&ze(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 As,c=[];if(o&&(c.push("Additional reconciliation context:"),c.push(o.localElements.map(u=>s(u))),c.push(o.remoteElements.map(u=>s(u)))),i||console.error(r.join(`
11
11
 
12
- `),l.stack,e.map(c=>s(c)),...d),t)throw l}},Id=e=>e.sort((t,n)=>Pd(t)&&Pd(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),$n=(e,t)=>{try{let n=Xo(e),i=Pf(e,t),o=Ps(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});yf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)De(s,n,{index:a})}catch{ys(e)}return e},ys=e=>{let t=Xo(e),n=Ad(e),i=Ps(e,n);for(let[o,{index:r}]of i)De(o,t,{index:r});return e},Sd=e=>{let t=Xo(e),n=Ad(e),i=Ps(e,n);for(let[o,{index:r}]of i)t.set(o.id,Fe(o,{index:r}));return t},Pf=(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},Ad=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),ws(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(ws(u,m,h))break;[n,o]=[m,p],[i,r]=[h,f],c.push(l)}c.push(r),t.push(c)}}return t},ws=(e,t,n)=>{if(!e)return!1;try{bf(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},Ps=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=wf(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},Pd=e=>!!e.index;var Md=(e,t,n)=>{let i=Et(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&&De(a,i,{frameId:s??null})}};function ui(e,t,n){let i=Ss(t,n),o=Ss(e,n);return i.some(s=>o.some(a=>Sf(s,a)))}var Td=(e,t,n)=>$o(bd(e,t,n,!1)).filter(i=>!Z(i)&&!i.frameId||i.frameId===t.id),As=(e,t,n)=>Ms(ae(e,n),ae(t,n)),dP=(e,t)=>{let n=Et(e);return e.filter(i=>ui(i,t,n))},Pn=(e,t,n)=>{let[i,o,r,s]=$(t,n),[a,l,d,c]=ze(e);return i<=a&&o<=l&&r>=d&&s>=c},wn=(e,t,n)=>Pn([e],t,n)||ui(e,t,n)||As(e,t,n),cP=(e,t,n)=>{let[i,o,r,s]=$(t,n);return If(Is(i,o),Is(e.x,e.y),Is(r,s))},uP=(e,t,n)=>{let i=Et(e),o=t.flatMap(r=>Re(e,r));return o.length===0?!0:!!o.find(r=>Pn([r],n,i)||ui(r,n,i))},mP=(e,t,n)=>{let i=Et(e),o=t.flatMap(r=>Re(e,r));return o.length===0?!0:o.find(r=>Pn([r],n,i)||ui(r,n,i))===void 0},pP=e=>{let t=new Map;for(let n of e){let i=Z(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,bn(e,i))}return t},bn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Af=e=>e.filter(t=>Z(t)),fP=e=>{let t=Et(Af(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},hP=(e,t,n,i)=>{let o=bn(e,t.id),r=new Set(o),s=new Set([...Td(e,t,i),...o.filter(p=>As(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(!ui(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=In(c),m=fd(u,n);for(let[p,h]of Object.entries(m))if(h){let f=Re(e,p);if(Pn(f,t,i))for(let E of f)r.add(E)}return[...r].filter(p=>!(K(p)&&p.containerId))},EP=(e,t,n)=>Mf($o(e,Td(e,t,n)),t,n),Mf=(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=>Re(n,l)));s=!Pn(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},yn=(e,t)=>e.frameId&&t.get(e.frameId)||null,gP=(e,t)=>{let n=new Set,i=Et(e);e=$o(e);for(let s of e)Z(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(Z(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!o.has(a)){o.add(a);let l=Re(e,a);if(l.some(d=>wn(d,t,i)))for(let d of l)r.push(d)}}else wn(s,t,i)&&r.push(s);return r},Tf=e=>{let t;for(let n of e){if(Z(n)||!n.frameId)return null;if(t===void 0)t=n.frameId;else if(t!==n.frameId)return null}return t??null},Df=(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},vf=(e,t,n)=>{let i=Et(e),o=Tf(t),r=new Set,s=new Set;for(let c of t)Z(c)&&c.id!==n.id&&s.add(c.id);for(let c of $o(e,t)){if(Z(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&&De(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=Df(a,n.id);if(l===null)return e;let d=[...a.slice(0,l),...r,...a.slice(l)];return $n(d,Et([...r])),Array.isArray(e)?d:new Map(d.map(c=>[c.id,c]))},Dd=(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)De(o,t,{frameId:null})},Bf=(e,t)=>{let n=bn(e,t.id);return Dd(n,Et(e)),e},xP=(e,t,n)=>vf(Bf(e,n),t,n).slice(),bP=(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=>Re(e,l)).forEach(l=>o.add(l));let r=new Set,s=Et(e);return o.forEach(a=>{a.frameId&&!Z(a)&&!vd(a,s,t)&&r.add(a)}),r.size>0&&Dd(r,s),e},$o=(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)Re(e,s).some(a=>Z(a))&&o.add(s);let r=[];for(let s of i.values())o.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},Lf=(e,t,n)=>{let i=K(e)&&Ce(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?yn(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:yn(i,t)},vd=(e,t,n,i)=>{let o=i?.targetFrame??Lf(e,t,n);if(!o)return!1;let r=K(e)&&Ce(e,t)||e,s=l=>{i?.checkedGroups&&r.groupIds.forEach(d=>{i.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[o.id])return!0;if(r.groupIds.length===0)return wn(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=>Re(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(Bt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(Z(l))return s(!1),!1;for(let l of a)if(wn(l,o,t))return s(!0),!0;return!1},wP=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=ui(e,t,i)||As(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Pn([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=vd(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},Cf="Frame",Gf="AI Frame",Of=e=>xo(e)?Cf:Gf,yP=e=>e.name===null?Of(e):e.name,PP=(e,t,n)=>e.filter(i=>(!i.frameId||i.frameId===t.id)&&jt(ae(i,n),ae(t,n))),IP=e=>{let t=Et(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Yf=(e,t)=>zn(e)&&!t.imageCache.has(e.fileId),Qo=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}},jf=(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*=Nf/100),r},Xf=(e,t,n)=>{let r=Qo(e),[s,a,l,d]=$(e,t),c=Q(e)||Ie(e)?An(s,l):e.width,u=Q(e)||Ie(e)?An(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}},Cd=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=Qo(e),{width:l,height:d,scale:c}=Xf(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(Q(e)||Ie(e)){let[h,f]=$(e,t);u=e.x>h?An(e.x,h)*window.devicePixelRatio*c:0,m=e.y>f?An(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=ni.canvas(r);return qo(e,p,s,i),s.restore(),{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,containingFrameOpacity:yn(e,t)?.opacity||100,imageCrop:Ae(e)?e.crop:null}},RP=14,Gd=typeof document<"u"?document.createElement("img"):{src:""};Gd.src=`data:${vs.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 Od=typeof document<"u"?document.createElement("img"):{src:""};Od.src=`data:${vs.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 $f=(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"?Od:Gd,e.width/2-o/2,e.height/2-o/2,o,o)},qo=(e,t,n,i)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(tt.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",tt.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=tt.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=Ko(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=zn(e)?o?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,zt(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===vs.svg;if(c&&Uf){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 E=0;E<f.length;E+=4)f[E]=255-f[E],f[E+1]=255-f[E+1],f[E+2]=255-f[E+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=Rf),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else $f(e,n,i.theme);n.restore();break}default:if(K(e)){let o=Hf(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=zf(e),n.fillStyle=Ko(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}},Bd=e=>e.sort((t,n)=>vd(t)&&vd(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),Zn=(e,t)=>{try{let n=$o(e),i=zf(e,t),o=Ds(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Rf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)ve(s,n,{index:a})}catch{Ts(e)}return e},Ts=e=>{let t=$o(e),n=Cd(e),i=Ds(e,n);for(let[o,{index:r}]of i)ve(o,t,{index:r});return e},Ld=e=>{let t=$o(e),n=Cd(e),i=Ds(e,n);for(let[o,{index:r}]of i)t.set(o.id,_e(o,{index:r}));return t},zf=(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},Cd=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),Ms(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(Ms(u,m,h))break;[n,o]=[m,p],[i,r]=[h,f],c.push(l)}c.push(r),t.push(c)}}return t},Ms=(e,t,n)=>{if(!e)return!1;try{kf(e)}catch{return!1}return t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e},Ds=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=Ff(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},vd=e=>!!e.index;var Gd=(e,t,n)=>{let i=Pt(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&&ve(a,i,{frameId:s??null})}};function hi(e,t,n){let i=Bs(t,n),o=Bs(e,n);return i.some(s=>o.some(a=>_f(s,a)))}var Nd=(e,t,n)=>Zo(Md(e,t,n,!1)).filter(i=>!q(i)&&!i.frameId||i.frameId===t.id),Ls=(e,t,n)=>Gs(de(e,n),de(t,n)),w1=(e,t)=>{let n=Pt(e);return e.filter(i=>hi(i,t,n))},In=(e,t,n)=>{let[i,o,r,s]=V(t,n),[a,l,d,c]=Ye(e);return i<=a&&o<=l&&r>=d&&s>=c},yn=(e,t,n)=>In([e],t,n)||hi(e,t,n)||Ls(e,t,n),y1=(e,t,n)=>{let[i,o,r,s]=V(t,n);return Hf(vs(i,o),vs(e.x,e.y),vs(r,s))},P1=(e,t,n)=>{let i=Pt(e),o=t.flatMap(r=>Ue(e,r));return o.length===0?!0:!!o.find(r=>In([r],n,i)||hi(r,n,i))},I1=(e,t,n)=>{let i=Pt(e),o=t.flatMap(r=>Ue(e,r));return o.length===0?!0:o.find(r=>In([r],n,i)||hi(r,n,i))===void 0},S1=e=>{let t=new Map;for(let n of e){let i=q(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,wn(e,i))}return t},wn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Cs=e=>e.filter(t=>q(t)),A1=e=>{let t=Pt(Cs(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},M1=(e,t,n,i)=>{let o=wn(e,t.id),r=new Set(o),s=new Set([...Nd(e,t,i),...o.filter(p=>Ls(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(!hi(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=Sn(c),m=yd(u,n);for(let[p,h]of Object.entries(m))if(h){let f=Ue(e,p);if(In(f,t,i))for(let E of f)r.add(E)}return[...r].filter(p=>!(Q(p)&&p.containerId))},T1=(e,t,n)=>Wf(Zo(e,Nd(e,t,n)),t,n),Wf=(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=>Ue(n,l)));s=!In(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Pn=(e,t)=>e.frameId&&t.get(e.frameId)||null,D1=(e,t)=>{let n=new Set,i=Pt(e);e=Zo(e);for(let s of e)q(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(q(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!o.has(a)){o.add(a);let l=Ue(e,a);if(l.some(d=>yn(d,t,i)))for(let d of l)r.push(d)}}else yn(s,t,i)&&r.push(s);return r},Uf=e=>{let t;for(let n of e){if(q(n)||!n.frameId)return null;if(t===void 0)t=n.frameId;else if(t!==n.frameId)return null}return t??null},Yf=(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},jf=(e,t,n)=>{let i=Pt(e),o=Uf(t),r=new Set,s=new Set;for(let c of t)q(c)&&c.id!==n.id&&s.add(c.id);for(let c of Zo(e,t)){if(q(c)||c.frameId&&s.has(c.frameId))continue;r.add(c);let u=ne(c,i);u&&!r.has(u)&&r.add(u)}for(let c of r)c.frameId!==n.id&&ve(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=Yf(a,n.id);if(l===null)return e;let d=[...a.slice(0,l),...r,...a.slice(l)];return Zn(d,Pt([...r])),Array.isArray(e)?d:new Map(d.map(c=>[c.id,c]))},Od=(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=ne(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)ve(o,t,{frameId:null})},Xf=(e,t)=>{let n=wn(e,t.id);return Od(n,Pt(e)),e},v1=(e,t,n)=>jf(Xf(e,n),t,n).slice(),B1=(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=>Ue(e,l)).forEach(l=>o.add(l));let r=new Set,s=Pt(e);return o.forEach(a=>{a.frameId&&!q(a)&&!kd(a,s,t)&&r.add(a)}),r.size>0&&Od(r,s),e},Zo=(e,t)=>{let n=new Set,i=t||e;for(let s of i.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let o=new Set;for(let s of n)Ue(e,s).some(a=>q(a))&&o.add(s);let r=[];for(let s of i.values())o.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},Vf=(e,t,n)=>{let i=Q(e)&&Oe(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Pn(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Pn(i,t)},kd=(e,t,n,i)=>{let o=i?.targetFrame??Vf(e,t,n);if(!o)return!1;let r=Q(e)&&Oe(e,t)||e,s=l=>{i?.checkedGroups&&r.groupIds.forEach(d=>{i.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[o.id])return!0;if(r.groupIds.length===0)return yn(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=>Ue(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(Ot(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(q(l))return s(!1),!1;for(let l of a)if(yn(l,o,t))return s(!0),!0;return!1},L1=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=hi(e,t,i)||Ls(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!In([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=kd(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},$f="Frame",Zf="AI Frame",qf=e=>wo(e)?$f:Zf,C1=e=>e.name===null?qf(e):e.name,G1=(e,t,n)=>e.filter(i=>(!i.frameId||i.frameId===t.id)&&Zt(de(i,n),de(t,n))),N1=e=>{let t=Pt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var sh=(e,t)=>Hn(e)&&!t.imageCache.has(e.fileId),er=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}},ah=(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*=Jf/100),r},lh=(e,t,n)=>{let r=er(e),[s,a,l,d]=V(e,t),c=K(e)||Ae(e)?Mn(s,l):e.width,u=K(e)||Ae(e)?Mn(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}},zd=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=er(e),{width:l,height:d,scale:c}=lh(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(K(e)||Ae(e)){let[h,f]=V(e,t);u=e.x>h?Mn(e.x,h)*window.devicePixelRatio*c:0,m=e.y>f?Mn(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=ii.canvas(r);return Qo(e,p,s,i),s.restore(),{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,containingFrameOpacity:Pn(e,t)?.opacity||100,imageCrop:Te(e)?e.crop:null}},Z1=14,Hd=typeof document<"u"?document.createElement("img"):{src:""};Hd.src=`data:${ks.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 _d=typeof document<"u"?document.createElement("img"):{src:""};_d.src=`data:${ks.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 dh=(e,t,n)=>{t.fillStyle=n===Ei.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"?_d:Hd,e.width/2-o/2,e.height/2-o/2,o,o)},Qo=(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(rt.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",rt.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=rt.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=Jo(e.strokeColor,i.theme===Ei.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=Hn(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,Ut(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===Ei.DARK&&o?.mimeType===ks.svg;if(c&&rh){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 E=0;E<f.length;E+=4)f[E]=255-f[E],f[E+1]=255-f[E+1],f[E+2]=255-f[E+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=eh),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else dh(e,n,i.theme);n.restore();break}default:if(Q(e)){let o=nh(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=th(e),n.fillStyle=Jo(e.strokeColor,i.theme===Ei.DARK),n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
13
13
  `).split(`
14
- `),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=Io(e.fontSize,e.lineHeight),d=_f(e.fontFamily,e.fontSize,l);for(let c=0;c<s.length;c++)n.fillText(s[c],a,c*l+d);n.restore(),r&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},Xi=new WeakMap,Ld=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=Xi.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=Ae(e)?e.crop:null,l=yn(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.imageCrop!==a||r.containingFrameOpacity!==l){let d=Cd(e,t,o,n,i);return d?(Xi.set(e,d),d):null}return r},Ds=(e,t,n,i,o)=>{let r=e.element,s=Qo(r),[a,l,d,c]=$(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=q(r,o);if(W(r)&&p){let[,,,,h,f]=$(p,o),E=Math.max(An(a,d),An(l,c))*window.devicePixelRatio+s*10;t.beginPath(),t.rect(u-E,m-E,E*2,E*2),t.rect((h-p.width/2-Sn+i.scrollX)*window.devicePixelRatio,(f-p.height/2-Sn+i.scrollY)*window.devicePixelRatio,(p.width+Sn*2)*window.devicePixelRatio,(p.height+Sn*2)*window.devicePixelRatio),t.clip("evenodd")}if(t.translate(u,m),t.rotate(r.angle),"scale"in e.element&&!Yf(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),B.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&yt(r)){let h=q(r,o),f=Yr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((f.x+i.scrollX)*window.devicePixelRatio,(f.y+i.scrollY)*window.devicePixelRatio,mt(r,h)*window.devicePixelRatio,Fi(r,h)*window.devicePixelRatio)}t.restore()},zP=(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()},HP=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=jf(e,yn(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Ff: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=Zo.strokeWidth/s.zoom.value,o.strokeStyle=Ko(Zo.strokeColor,s.theme===mi.DARK),Za(e)&&(o.strokeStyle=s.theme===mi.LIGHT?"#7affd7":Ko("#1d8264")),Zo.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Zo.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(r.isExporting){let[l,d,c,u]=$(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,h=(c-l)/2-(e.x-l),f=(u-d)/2-(e.y-d);o.save(),o.translate(m,p),o.rotate(e.angle),o.translate(-h,-f),qo(e,i,o,r),o.restore()}else{let l=Ld(e,n,r,s);if(!l)return;Ds(l,o,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=$(e,t),m=(l+c)/2,p=(d+u)/2,h=m+s.scrollX,f=p+s.scrollY,E=(c-l)/2-(e.x-l),g=(u-d)/2-(e.y-d);if(K(e)){let b=Ce(e,t);if(W(b)){let y=G.getBoundTextElementPosition(b,e,t);E=(c-l)/2-(y.x-l),g=(u-d)/2-(y.y-d)}}o.save(),o.translate(h,f);let x=q(e,t);if(W(e)&&x){E=e.width/2-(e.x-l),g=e.height/2-(e.y-d);let[,,,,b,y]=$(x,t),w=b-m-x.width/2-Sn,S=y-p-x.height/2-Sn,I=x.width+Sn*2,M=x.height+Sn*2,A=Math.max(An(l,c),An(d,u))+Qo(e)*10;o.save(),o.beginPath(),o.rect(-A,-A,A*2,A*2),o.rect(w,S,I,M),o.clip("evenodd"),o.rotate(e.angle),o.translate(-E,-g),qo(e,i,o,r),o.restore()}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-E,-g),qo(e,i,o,r);o.restore()}else{let l=Ld(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||kf(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&Ae(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=Cd(Xa(l.element,t),n,s.zoom,r,s);c&&Ds(c,o,r,s,n),o.restore()}Ds(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function _P(e,t,n){let i=ae({...e,angle:0},n),o=Vo((i[0]+i[2])/2,(i[1]+i[3])/2);return Wf(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(Bd(r[r.length-1][1],Ts(Vo(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[Bd(Ts(Vo(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),Ts(Vo(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}var tt=class e{static rg=new it;static cache=new WeakMap;static get=(t,n)=>{let i=e.cache.get(t);if(i&&(n===null||i.theme===n))return i.shape};static delete=t=>{e.cache.delete(t),Xi.delete(t)};static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let i=n?.isExporting?void 0:e.get(t,n?n.theme:null);if(i!==void 0)return i;Xi.delete(t);let o=th(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:qf.white,embedsValidationStatus:null,theme:Cs.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||Cs.LIGHT}),o}},Jf=e=>[8,8+e],zd=e=>[1.5,6+e];function eh(e){let t=e.roughness,n=Math.max(e.width,e.height),i=Math.min(e.width,e.height);return i>=20&&n>=50||i>=15&&e.roundness&&gl(e.type)||Q(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Ve=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?Jf(e.strokeWidth):e.strokeStyle==="dotted"?zd(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:eh(e),stroke:Zi(e.strokeColor,n),preserveVertices:t||e.roughness<Vf.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=Vi(e.backgroundColor)?void 0:Zi(e.backgroundColor,n),e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return _n(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:Zi(e.backgroundColor,n)),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},Fd=(e,t,n)=>go(e)&&(t||Va(e)&&n?.get(e.id)!==!0)&&Vi(e.backgroundColor)&&Vi(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:Eo(e)?{...e,strokeColor:Vi(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Vi(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,$i=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},Jo=(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)]},Vn=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=zd(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},Bs=(e,t,n,i,o,r=1)=>{if(i===null)return[];let[s,a,l]=i,d={...t,fill:o,fillStyle:"solid",stroke:n,roughness:Math.min(.5,t.roughness||0)};return delete d.strokeLineDash,[e.circle(s,a,l*r,d)]},Nd=(e,t,n,i,o,r,s,a)=>{if(i===null)return[];let l=Zi(e.strokeColor,a),d=Zi(s,a),c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return Bs(o,r,l,He(e,t,n,i),i==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let m=He(e,t,n,i);if(m===null)return[];let[p,h,f,E,g,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,E],[g,x],[p,h]],b)]}case"diamond":case"diamond_outline":{let m=He(e,t,n,i);if(m===null)return[];let[p,h,f,E,g,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,E],[g,x],[b,y],[p,h]],w)]}case"cardinality_one":return $i(o,He(e,t,n,i),Vn(e,r));case"cardinality_many":return Jo(o,He(e,t,n,i),Vn(e,r));case"cardinality_one_or_many":{let m=Vn(e,r);return[...Jo(o,He(e,t,n,"cardinality_many"),m),...$i(o,He(e,t,n,"cardinality_one",c),m)]}case"cardinality_exactly_one":{let m=Vn(e,r);return[...$i(o,He(e,t,n,"cardinality_one",-.5),m),...$i(o,He(e,t,n,"cardinality_one"),m)]}case"cardinality_zero_or_one":{let m=Vn(e,r);return[...Bs(o,r,l,He(e,t,n,"circle_outline",1.5),d,u),...$i(o,He(e,t,n,"cardinality_one",-.5),m)]}case"cardinality_zero_or_many":{let m=Vn(e,r);return[...Jo(o,He(e,t,n,"cardinality_many"),m),...Bs(o,r,l,He(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return Jo(o,He(e,t,n,i),Vn(e,r))}},al=(e,t)=>{let n=new it,i={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=re(e,t);switch(e.type){case"line":case"arrow":{let r=e.points.length?e.points:[me(0,0)];return U(e)?n.path(Hd(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=qt(me(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:me(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[qt(me(e.x+s.data[0],e.y+s.data[1]),o,e.angle),qt(me(e.x+s.data[2],e.y+s.data[3]),o,e.angle),qt(me(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>me(l[0]-e.x,l[1]-e.y)).flat()}}):r.map((s,a)=>{let l=qt(me(e.x+s[0],e.y+s[1]),o,e.angle);return{op:a===0?"move":"lineTo",data:me(l[0]-e.x,l[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let r=Si(e.points,.75);return n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=qt(me(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:me(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[qt(me(e.x+s.data[0],e.y+s.data[1]),o,e.angle),qt(me(e.x+s.data[2],e.y+s.data[3]),o,e.angle),qt(me(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>me(l[0]-e.x,l[1]-e.y)).flat()}})}}},th=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===Cs.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=zt(Math.min(l,d),e);a=t.path(`M ${c} 0 L ${l-c} 0 Q ${l} 0, ${l} ${c} L ${l} ${d-c} Q ${l} ${d}, ${l-c} ${d} L ${c} ${d} Q 0 ${d}, 0 ${d-c} L 0 ${c} Q 0 0, ${c} 0`,Ve(Fd(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,Ve(Fd(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,h,f]=ri(e);if(e.roundness){let E=zt(Math.abs(l-h),e),g=zt(Math.abs(u-d),e);a=t.path(`M ${l+E} ${d+g} L ${c-E} ${u-g}
14
+ `),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=Mo(e.fontSize,e.lineHeight),d=ih(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}`)}},$i=new WeakMap,Rd=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=$i.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=Te(e)?e.crop:null,l=Pn(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.imageCrop!==a||r.containingFrameOpacity!==l){let d=zd(e,t,o,n,i);return d?($i.set(e,d),d):null}return r},Os=(e,t,n,i,o)=>{let r=e.element,s=er(r),[a,l,d,c]=V(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=ne(r,o);if(_(r)&&p){let[,,,,h,f]=V(p,o),E=Math.max(Mn(a,d),Mn(l,c))*window.devicePixelRatio+s*10;t.beginPath(),t.rect(u-E,m-E,E*2,E*2),t.rect((h-p.width/2-An+i.scrollX)*window.devicePixelRatio,(f-p.height/2-An+i.scrollY)*window.devicePixelRatio,(p.width+An*2)*window.devicePixelRatio,(p.height+An*2)*window.devicePixelRatio),t.clip("evenodd")}if(t.translate(u,m),t.rotate(r.angle),"scale"in e.element&&!sh(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),B.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&Tt(r)){let h=ne(r,o),f=Vr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((f.x+i.scrollX)*window.devicePixelRatio,(f.y+i.scrollY)*window.devicePixelRatio,xt(r,h)*window.devicePixelRatio,_i(r,h)*window.devicePixelRatio)}t.restore()},q1=(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()},K1=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=ah(e,Pn(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Qf: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=Ko.strokeWidth/s.zoom.value,o.strokeStyle=Jo(Ko.strokeColor,s.theme===Ei.DARK),nl(e)&&(o.strokeStyle=s.theme===Ei.LIGHT?"#7affd7":Jo("#1d8264")),Ko.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Ko.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]=V(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),Qo(e,i,o,r),o.restore()}else{let l=Rd(e,n,r,s);if(!l)return;Os(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]=V(e,t),m=(l+c)/2,p=(d+u)/2,h=m+s.scrollX,f=p+s.scrollY,E=(c-l)/2-(e.x-l),g=(u-d)/2-(e.y-d);if(Q(e)){let b=Oe(e,t);if(_(b)){let y=C.getBoundTextElementPosition(b,e,t);E=(c-l)/2-(y.x-l),g=(u-d)/2-(y.y-d)}}o.save(),o.translate(h,f);let x=ne(e,t);if(_(e)&&x){E=e.width/2-(e.x-l),g=e.height/2-(e.y-d);let[,,,,b,y]=V(x,t),w=b-m-x.width/2-An,S=y-p-x.height/2-An,I=x.width+An*2,M=x.height+An*2,A=Math.max(Mn(l,c),Mn(d,u))+er(e)*10;o.save(),o.beginPath(),o.rect(-A,-A,A*2,A*2),o.rect(w,S,I,M),o.clip("evenodd"),o.rotate(e.angle),o.translate(-E,-g),Qo(e,i,o,r),o.restore()}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-E,-g),Qo(e,i,o,r);o.restore()}else{let l=Rd(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Kf(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&Te(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=zd(Ja(l.element,t),n,s.zoom,r,s);c&&Os(c,o,r,s,n),o.restore()}Os(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function Q1(e,t,n){let i=de({...e,angle:0},n),o=qo((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(Fd(r[r.length-1][1],Ns(qo(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[Fd(Ns(qo(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),Ns(qo(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}var rt=class e{static rg=new lt;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),$i.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;$i.delete(t);let o=gh(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:mh.white,embedsValidationStatus:null,theme:zs.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||zs.LIGHT}),o}},hh=e=>[8,8+e],Xd=e=>[1.5,6+e];function Eh(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&&Sl(e.type)||K(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Je=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?hh(e.strokeWidth):e.strokeStyle==="dotted"?Xd(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:Eh(e),stroke:Ki(e.strokeColor,n),preserveVertices:t||e.roughness<ch.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=qi(e.backgroundColor)?void 0:Ki(e.backgroundColor,n),e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return Wn(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:Ki(e.backgroundColor,n)),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},Ud=(e,t,n)=>bo(e)&&(t||tl(e)&&n?.get(e.id)!==!0)&&qi(e.backgroundColor)&&qi(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:xo(e)?{...e,strokeColor:qi(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:qi(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Zi=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},tr=(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)]},qn=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=Xd(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},Fs=(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)]},Yd=(e,t,n,i,o,r,s,a)=>{if(i===null)return[];let l=Ki(e.strokeColor,a),d=Ki(s,a),c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return Fs(o,r,l,je(e,t,n,i),i==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let m=je(e,t,n,i);if(m===null)return[];let[p,h,f,E,g,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,E],[g,x],[p,h]],b)]}case"diamond":case"diamond_outline":{let m=je(e,t,n,i);if(m===null)return[];let[p,h,f,E,g,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,E],[g,x],[b,y],[p,h]],w)]}case"cardinality_one":return Zi(o,je(e,t,n,i),qn(e,r));case"cardinality_many":return tr(o,je(e,t,n,i),qn(e,r));case"cardinality_one_or_many":{let m=qn(e,r);return[...tr(o,je(e,t,n,"cardinality_many"),m),...Zi(o,je(e,t,n,"cardinality_one",c),m)]}case"cardinality_exactly_one":{let m=qn(e,r);return[...Zi(o,je(e,t,n,"cardinality_one",-.5),m),...Zi(o,je(e,t,n,"cardinality_one"),m)]}case"cardinality_zero_or_one":{let m=qn(e,r);return[...Fs(o,r,l,je(e,t,n,"circle_outline",1.5),d,u),...Zi(o,je(e,t,n,"cardinality_one",-.5),m)]}case"cardinality_zero_or_many":{let m=qn(e,r);return[...tr(o,je(e,t,n,"cardinality_many"),m),...Fs(o,r,l,je(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return tr(o,je(e,t,n,i),qn(e,r))}},fl=(e,t)=>{let n=new lt,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:[he(0,0)];return W(e)?n.path(Vd(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=Qt(he(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:he(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Qt(he(e.x+s.data[0],e.y+s.data[1]),o,e.angle),Qt(he(e.x+s.data[2],e.y+s.data[3]),o,e.angle),Qt(he(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>he(l[0]-e.x,l[1]-e.y)).flat()}}):r.map((s,a)=>{let l=Qt(he(e.x+s[0],e.y+s[1]),o,e.angle);return{op:a===0?"move":"lineTo",data:he(l[0]-e.x,l[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let r=vi(e.points,.75);return n.curve(r,i).sets[0].ops.slice(0,e.points.length).map((s,a)=>{if(a===0){let l=Qt(he(e.x+s.data[0],e.y+s.data[1]),o,e.angle);return{op:"move",data:he(l[0]-e.x,l[1]-e.y)}}return{op:"bcurveTo",data:[Qt(he(e.x+s.data[0],e.y+s.data[1]),o,e.angle),Qt(he(e.x+s.data[2],e.y+s.data[3]),o,e.angle),Qt(he(e.x+s.data[4],e.y+s.data[5]),o,e.angle)].map(l=>he(l[0]-e.x,l[1]-e.y)).flat()}})}}},gh=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===zs.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=Ut(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`,Je(Ud(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,Je(Ud(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,h,f]=si(e);if(e.roundness){let E=Ut(Math.abs(l-h),e),g=Ut(Math.abs(u-d),e);a=t.path(`M ${l+E} ${d+g} L ${c-E} ${u-g}
15
15
  C ${c} ${u}, ${c} ${u}, ${c-E} ${u+g}
16
16
  L ${m+E} ${p-g}
17
17
  C ${m} ${p}, ${m} ${p}, ${m-E} ${p-g}
18
18
  L ${h+E} ${f+g}
19
19
  C ${h} ${f}, ${h} ${f}, ${h+E} ${f-g}
20
20
  L ${l-E} ${d+g}
21
- C ${l} ${d}, ${l} ${d}, ${l+E} ${d+g}`,Ve(e,!0,s))}else a=t.polygon([[l,d],[c,u],[m,p],[h,f]],Ve(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Ve(e,!1,s));case"line":case"arrow":{let a,l=Ve(e,!1,s),d=e.points.length?e.points:[me(0,0)];if(U(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(Hd(d,16),Ve(e,!0,s))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(d)),a=[]):e.roundness?a=[t.curve(d,l)]:l.fill?a=[t.polygon(d,l)]:a=[t.linearPath(d,l)],e.type==="arrow"){let{startArrowhead:c=null,endArrowhead:u="arrow"}=e;if(c!==null){let m=Nd(e,a,"start",c,t,l,i,s);a.push(...m)}if(u!==null){let m=Nd(e,a,"end",u,t,l,i,s);a.push(...m)}}return a}case"freedraw":{let a=[];if(_n(e.points)){let l=Si(e.points,.75);a.push(t.curve(l,{...Ve(e,!1,s),stroke:"none"}))}return a.push(nh(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return Zf(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Hd=(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=ft(a,r),d=ft(s,a),c=Math.min(t,kd(e[o],s)/2,kd(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(" ")},_d=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Ta(e);case"arrow":case"line":{let n=tt.generateElementShape(e,null)[0],[,,,,i,o]=$(e,t);return To(e)?La(e,n,me(e.x,e.y),e.angle,me(i,o)):va(n,me(e.x,e.y),e.angle,me(i,o))}case"ellipse":return Da(e);case"freedraw":{let[,,,,n,i]=$(e,t);return Ba(e,me(n,i),To(e))}}},ud=(e,t)=>{let n=[...e.points];if(t){if(!el(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>Kf||n.length<4?n.push(me(o[0],o[1])):n[n.length-1]=me(o[0],o[1])}return{polygon:t,points:n}},nh=e=>dh(ah(e)),Ls={SIZE_FACTOR:4.25,THINNING:.6,SMOOTHING:.5},ih={SIZE_FACTOR:1.4},Wd=e=>e.strokeOptions?.streamline??Qf,oh=e=>{let t=e.simulatePressure?e.points:e.points.length?e.points.map(([n,i],o)=>[n,i,e.pressures[o]]):[[0,0,.5]];return Ra(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*Ls.SIZE_FACTOR,thinning:Ls.THINNING,smoothing:Ls.SMOOTHING,streamline:Wd(e),easing:n=>Math.sin(n*Math.PI/2),last:!0})},rh=e=>new po({size:e.strokeWidth*ih.SIZE_FACTOR,streamline:Wd(e),simplify:0,sizeMapping:t=>Math.max(.1,t.pressure)}),sh=e=>{let t=rh(e);return e.points.map(([n,i])=>t.addPoint([n,i,1])),t.getStrokeOutline().map(([n,i])=>[n,i])},ah=e=>e.strokeOptions?.variability==="constant"?sh(e):oh(e),Rd=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],lh=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,dh=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Rd(i,r[0]),"L",r[0],"Z"):n.push(i,Rd(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(lh,"$1")};var ks=class e{static boundsCache=new WeakMap;static nonRotatedBoundsCache=new WeakMap;static getBounds(t,n,i=!1){let o=i&&t.angle!==0?e.nonRotatedBoundsCache.get(t):e.boundsCache.get(t);if(o?.version&&o.version===t.version&&!he(t))return o.bounds;if(i&&t.angle!==0){let s=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:s}),s}let r=e.calculateBounds(t,n);return e.boundsCache.set(t,{version:t.version,bounds:r}),r}static calculateBounds(t,n){let i,[o,r,s,a,l,d]=$(t,n);if(Ie(t)){let[c,u,m,p]=Fs(t.points.map(([h,f])=>ee(v(h,f),v(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,m+t.x,p+t.y]}else if(Q(t))i=bh(t,l,d,n);else if(t.type==="diamond"){let[c,u]=ee(v(l,r),v(l,d),t.angle),[m,p]=ee(v(l,a),v(l,d),t.angle),[h,f]=ee(v(o,d),v(l,d),t.angle),[E,g]=ee(v(s,d),v(l,d),t.angle),x=Math.min(c,m,h,E),b=Math.min(u,p,f,g),y=Math.max(c,m,h,E),w=Math.max(u,p,f,g);i=[x,b,y,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,m=Math.cos(t.angle),p=Math.sin(t.angle),h=Math.hypot(c*m,u*p),f=Math.hypot(u*m,c*p);i=[l-h,d-f,l+h,d+f]}else{let[c,u]=ee(v(o,r),v(l,d),t.angle),[m,p]=ee(v(o,a),v(l,d),t.angle),[h,f]=ee(v(s,a),v(l,d),t.angle),[E,g]=ee(v(s,r),v(l,d),t.angle),x=Math.min(c,m,h,E),b=Math.min(u,p,f,g),y=Math.max(c,m,h,E),w=Math.max(u,p,f,g);i=[x,b,y,w]}return i}},$=(e,t,n=!1)=>{if(Ie(e))return ph(e);if(Q(e))return G.getElementAbsoluteCoords(e,t,n);if(K(e)){let i=t?Ce(e,t):null;if(W(i)){let{x:o,y:r}=G.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},Ss=(e,t)=>{let n=_d(e,t),[i,o,r,s,a,l]=$(e,t),d=v(a,l);if(n.type==="polycurve"){let g=n.data.map(b=>Ot(b,10)),x=[];if(Nt(e)&&!e.polygon||W(e))for(let b of g){let y=0;for(;y<b.length-1;)x.push(pe(v(b[y][0],b[y][1]),v(b[y+1][0],b[y+1][1]))),y++}else{let b=g.flat(),y=0;for(;y<b.length-1;)x.push(pe(v(b[y][0],b[y][1]),v(b[y+1][0],b[y+1][1]))),y++}return x}else{if(n.type==="polyline")return n.data;if(uh(e)){let[E,g]=ln(e),x=g.map(y=>jd(y,d,e.angle)).flat();return[...Yd(E,d,e.angle),...x]}else if(e.type==="diamond"){let[E,g]=dn(e),x=g.map(y=>jd(y,d,e.angle)).flat();return[...Yd(E,d,e.angle),...x]}else if(n.type==="polygon"){if(K(e)){let x=Ce(e,t);if(x&&Q(x))return[pe(v(i,o),v(r,o)),pe(v(r,o),v(r,s)),pe(v(r,s),v(i,s)),pe(v(i,s),v(i,o))]}let E=n.data,g=[];for(let x=0;x<E.length-1;x++)g.push(pe(E[x],E[x+1]));return g}else if(n.type==="ellipse")return mh(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(E=>ee(E,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)]},uh=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),Yd=(e,t,n)=>e.map(i=>pe(ee(i[0],t,n),ee(i[1],t,n))),jd=(e,t,n)=>{let i=Ot(e,10),o=0,r=[];for(;o<i.length-1;)r.push(pe(ee(v(i[o][0],i[o][1]),t,n),ee(v(i[o+1][0],i[o+1][1]),t,n))),o++;return r},mh=e=>{let t=v(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(ee(v(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},w1=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],ri=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]},Xd=(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},$d=(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=Xd(h,e,t,n,i)),f>=0&&f<=1&&(p=Xd(f,e,t,n,i)),[m,p]},vo=(e,t,n,i)=>{let o=$d(e[0],t[0],n[0],i[0]),r=$d(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]},ji=(e,t)=>{let n=v(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=Zd(d);Os(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=v(d[0],d[1]),u=v(d[2],d[3]),m=v(d[4],d[5]),p=t?t(c):c,h=t?t(u):u,f=t?t(m):m,E=t?t(n):n;n=m;let[g,x,b,y]=vo(E,p,h,f);a.minX=Math.min(a.minX,g),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]},Fs=(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]},ph=e=>{let[t,n,i,o]=Fs(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]},fh=20,hh=15,Eh=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 hh;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return fh;default:return 15}},gh=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},He=(e,t,n,i,o=0)=>{if(i===null||t.length<1)return null;let r=kt(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;Os(a.length===6,"Op data length is not 6");let l=v(a[4],a[5]),d=v(a[2],a[3]),c=v(a[0],a[1]),u=r[s-1],m=v(0,0);if(u.op==="move"){let T=Zd(u.data);Os(T!=null,"Op data is not a point"),m=T}else u.op==="bcurveTo"&&(m=v(u.data[4],u.data[5]));let p=(T,N)=>Math.pow(1-T,3)*l[N]+3*T*Math.pow(1-T,2)*d[N]+3*Math.pow(T,2)*(1-T)*c[N]+m[N]*Math.pow(T,3),[h,f]=n==="start"?m:l,[E,g]=[p(.3,0),p(.3,1)],x=Math.hypot(h-E,f-g),b=(h-E)/x,y=(f-g)/x,w=Eh(i),S=0;{let[T,N]=n==="end"?e.points[e.points.length-1]:e.points[0],[_,ye]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];S=Math.hypot(T-_,N-ye)}let M=Math.min(w,S*(i==="diamond"||i==="diamond_outline"?.25:.5)),A=h-b*M*o,L=f-y*M*o,C=A-b*M,O=L-y*M;if(i==="circle"||i==="circle_outline"){let T=Math.hypot(O-L,C-A)+e.strokeWidth-2;return[A,L,T]}let D=gh(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[T,N]=ee(v(A,L),v(C,O),Gs(-D)),[_,ye]=ee(v(A,L),v(C,O),Gs(D));return[C,O,T,N,_,ye]}let[Y,H]=ee(v(C,O),v(A,L),-D*Math.PI/180),[V,F]=ee(v(C,O),v(A,L),Gs(D));if(i==="diamond"||i==="diamond_outline"){let T,N;if(n==="start"){let[_,ye]=e.points.length>1?e.points[1]:[0,0];[T,N]=ee(v(A+M*2,L),v(A,L),Math.atan2(ye-L,_-A))}else{let[_,ye]=e.points.length>1?e.points[e.points.length-2]:[0,0];[T,N]=ee(v(A-M*2,L),v(A,L),Math.atan2(L-ye,A-_))}return[A,L,Y,H,T,N,V,F]}return[A,L,Y,H,V,F]},xh=e=>{let t=ni.generator(),n=Ve(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},bh=(e,t,n,i)=>{let o=q(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,h]=ee(v(e.x+u,e.y+m),v(t,n),e.angle),f=[p,h,p,h];if(o){let E=G.getMinMaxXYWithBoundText(e,i,[p,h,p,h],o);f=[E[0],E[1],E[2],E[3]]}return f}let s=tt.get(e,null)?.[0]??xh(e),a=kt(s),d=ji(a,([u,m])=>ee(v(e.x+u,e.y+m),v(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=G.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},ae=(e,t,n=!1)=>ks.getBounds(e,t,n),ze=(e,t)=>{if(!ch(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Vd(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]},y1=(e,t)=>{let[n,i,o,r]=ze(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},an=(e,t,n,i)=>{if(!(Q(e)||Ie(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Ud(0,t,Ud(1,n,e.points,i),i),r;if(Ie(e))r=Fs(o);else{let c=ni.generator(),u=e.roundness?c.curve(o,Ve(e)):c.linearPath(o,Ve(e)),m=kt(u);r=ji(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Es=(e,t)=>{let n=ni.generator(),i=e.roundness==null?n.linearPath(t,Ve(e)):n.curve(t,Ve(e)),o=kt(i),[r,s,a,l]=ji(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},Kt=e=>{let[t,n,i,o]=ze(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},P1=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],mn=e=>v(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),st=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=re(e,t),[r,s]=ee(v(i.minX,i.minY),o,e.angle),[a,l]=ee(v(i.maxX,i.minY),o,e.angle),[d,c]=ee(v(i.maxX,i.maxY),o,e.angle),[u,m]=ee(v(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,E,g]=n;return[p[0]-g,p[1]-h,p[2]+f,p[3]+E]}return p},Mt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],wh=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],jt=(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},Ms=(e,t)=>[v(t[0],t[1]),v(t[0],t[3]),v(t[2],t[1]),v(t[2],t[3])].every(n=>wh(n,e)),wd=({elements:e,elementsMap:t,bounds:n,type:i,excludeElementsInFrames:o,shouldIgnoreElementFromSelection:r})=>{t||(t=Vd(e));let s=Ka(n)?ae(n,t):n,[a,l,d,c]=s,u=[pe(v(a,l),v(d,l)),pe(v(d,l),v(d,c)),pe(v(d,c),v(a,c)),pe(v(a,c),v(a,l))],m=o?new Set:null,p={},h=new Set;for(let f of e){if(r?.(f))continue;let E=f.groupIds.at(-1);E&&(p[E]||(p[E]=[]),p[E].push(f));let g=f.strokeWidth,x=null,b=ae(f,t);b=[b[0]-g/2,b[1]-g/2,b[2]+g/2,b[3]+g/2];let y=W(f)&&q(f,t);if(y){let{x:I,y:M}=G.getBoundTextElementPosition(f,y,t);x=[I,M,I+y.width,M+y.height]}let w=yn(f,t);if(w&&wn(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(Ms(s,S)){m&&Z(f)&&m.add(f.id),h.add(f);continue}if(i==="overlap"&&x&&jt(s,x)){h.add(f);continue}if(i==="overlap"&&jt(s,b)){let I=!1;if(Q(f)||Ie(f)){let M=re(f,t);I=f.points.some(A=>{let L=ee(v(f.x+A[0],f.y+A[1]),M,f.angle);return Mt(L,s)})}else{let M=ae(f,t,!0),A=re(f,t);I=[ee(v((M[0]+M[2])/2,M[1]),A,f.angle),ee(v(M[2],(M[1]+M[3])/2),A,f.angle),ee(v((M[0]+M[2])/2,M[3]),A,f.angle),ee(v(M[0],(M[1]+M[3])/2),A,f.angle)].some(L=>Mt(ee(L,A,f.angle),s))}if(I||(I=u.some(M=>At(f,t,M,g/2,!0).length>0)),I){m&&Z(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 E=f.groupIds.at(-1);(E?p[E]:null)?.forEach(x=>h.add(x))}):i==="contain"&&h.forEach(f=>{let E=f.groupIds.at(-1),g=E?p[E]:null;g&&!g.every(x=>h.has(x))&&h.delete(f)}),e.filter(f=>h.has(f))},re=(e,t,n=0,i=0)=>{if(Q(e)||Ie(e)){let[s,a,l,d]=$(e,t),[c,u]=v((s+l)/2,(a+d)/2);return v(c+n,u+i)}let[o,r]=mn(ae(e,t));return v(o+n,r+i)};var Sh=.1,Kd=e=>Q(e)||Ie(e)?e.points.length<2||e.points.length===2&&W(e)&&Ih(e.points[0],e.points[e.points.length-1],Sh):e.width===0&&e.height===0,yd=(e,t,n,i,o)=>{let[r,s,a,l]=ae(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},B1=(e,t,n,i,o,r)=>{let[s,a,l,d]=ze(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},Ns=(e,t,n)=>{let i=Math.abs(t),o=Math.abs(n);if(e==="line"||e==="arrow"||e==="freedraw"){let r=Math.round(Math.atan(o/i)/Qt)*Qt;r===0?n=0:r===Math.PI/2?t=0:n=i*Math.tan(r)*Math.sign(n)||n}else e!=="selection"&&(n=i*Math.sign(n));return{width:t,height:n}},md=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Qt)*Qt;if(o){let d=Math.floor(o/Qt)*Qt;yh(a,d,d+Qt)&&(Ph(a,o)<Qt/6?l=o:qd(a)>qd(o)?l=d+Qt:l=d)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,m=-1/d,p=-1,h=i-m*n,f=(c*h-p*u)/(d*p-m*c),E=(u*m-h*d)/(d*p-m*c);r=f-e,s=E-t}return{width:r,height:s}},L1=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t};P();var R1=(e,t,n,i)=>{let o=jo(e,n.getNonDeletedElementsMap(),i).map(In),r=Kt(e);return o.flatMap(s=>{let a=Ah(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return ke(l,n,{simultaneouslyUpdated:s}),d})})},Ah=(e,t,{axis:n,position:i})=>{let o=Kt(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};P();import{arrayToMap as xE,arrayToObject as Jt,assertNever as gc,isDevEnv as vn,isShallowEqual as xc,isTestEnv as Bn,randomInteger as Ec}from"@excalidraw/common";P();import{assertNever as Fh,COLOR_PALETTE as Nh,isDevEnv as Rh,isTestEnv as zh,randomId as Hh,Emitter as ec,toIterable as fi}from"@excalidraw/common";P();import{ORIG_ID as vh,randomId as Jd,randomInteger as Bh,arrayToMap as Lh,castArray as Rs,findLastIndex as pi,getUpdatedTimestamp as Ch,isTestEnv as Gh}from"@excalidraw/common";P();import{arrayToMap as Mh}from"@excalidraw/common";var Th=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},Dh=e=>{let t=Mh(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]},Qd=e=>Dh(Th(e));var Oh=(e,t,n,i)=>{let o=Hs(n);return Gh()&&kh(o,n.id),o.id=Jd(),o.updated=Ch(),i&&(o.seed=Bh(),Ul(o)),o.groupIds=xd(o.groupIds,e,r=>(t.has(r)||t.set(r,Jd()),t.get(r))),o},J1=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},i=new Map,o=new Map,r=[],s=[],a=new Map,l=new Map,d=new Map,c=Lh(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(g=>[g.id,g])),m=e.type==="everything"&&e.preserveFrameChildrenOrder;if(e.type==="in-place")for(let g of Object.keys(e.appState.selectedGroupIds))t.filter(x=>x.groupIds?.includes(g)).forEach(x=>u.set(x.id,x));t=Qd(t);let p=t.slice(),h=g=>{let b=Rs(g).reduce((y,w)=>{if(i.has(w.id))return y;i.set(w.id,!0),pt(w)||console.error("[NONDELETED][INVARIANT] Element to duplicate should be non-deleted");let S=Oh(n.editingGroupId,o,w,e.randomizeSeed);return i.set(S.id,!0),d.set(S.id,S),a.set(w.id,S.id),l.set(S.id,w),s.push(w),r.push(S),y.push(S),y},[]);return Array.isArray(g)?b:b[0]||null},f=(g,x)=>{if(x){if(g>p.length-1){p.push(...Rs(x));return}p.splice(g+1,0,...Rs(x))}},E=new Set(t.filter(g=>u.has(g.id)&&Z(g)).map(g=>g.id));for(let g of t){if(i.has(g.id)||!u.has(g.id))continue;let x=xs(n,g);if(x){let b=Re(t,x).flatMap(w=>Z(w)&&!m?[...bn(t,w.id),w]:[w]),y=pi(p,w=>w.groupIds?.includes(x));f(y,h(b));continue}if(!(!m&&g.frameId&&E.has(g.frameId))){if(Z(g)){let b=g.id;if(m){f(pi(p,S=>S.id===b),h(g));continue}let y=bn(t,b),w=pi(p,S=>S.frameId===b||S.id===b);f(w,h([...y,g]));continue}if(yt(g)){let b=q(g,c),y=pi(p,w=>w.id===g.id||"containerId"in w&&w.containerId===g.id);b?f(y,h([g,b])):f(y,h(g));continue}if(he(g)){let b=Ce(g,c),y=pi(p,w=>w.id===g.id||w.id===b?.id);b?f(y,h([b,g])):f(y,h(g));continue}f(pi(p,b=>b.id===g.id),h(g))}}if(Jl(r,a,d),Md(p,s,a),e.overrides)for(let g of r){let x=l.get(g.id);x&&Object.assign(g,e.overrides({duplicateElement:g,origElement:x,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:p,origIdToDuplicateId:a}},zs=(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]=zs(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=zs(e[i],t+1);return o}return B.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},Hs=e=>zs(e),kh=(e,t)=>{Object.defineProperty(e,vh,{value:t,writable:!1,enumerable:!1})};var Ze={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},tc=class{constructor(t){this.app=t}onDurableIncrementEmitter=new ec;onStoreIncrementEmitter=new ec;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Dn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Ze.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=Dn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?Sd(t.elements):void 0,t.appState);i=qi.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=Dn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=qi.create(o,t),i?s=i:s=Us.calculate(o,t),!s.isEmpty()){let a=new _s(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=qi.create(r,t)}let o=new Ws(i);this.onStoreIncrementEmitter.trigger(o)}applyChangeToSnapshot(t){let n=this.snapshot,i=this.snapshot.applyChange(t);return n===i?null:i}maybeCloneSnapshot(t,n,i){if(!n&&!i)return null;let o=this.snapshot,r=this.snapshot.maybeClone(t,n,i);return o===r?null:r}flushMicroActions(){for(let t of this.scheduledMicroActions)try{t()}catch(n){console.error("Failed to execute scheduled micro action",n)}this.scheduledMicroActions=[]}processAction(t){let{action:n}=t;if(n===Ze.EVENTUALLY&&!this.onStoreIncrementEmitter.subscribers.length)return;let i;if("change"in t?i=this.applyChangeToSnapshot(t.change):i=this.maybeCloneSnapshot(n,t.elements,t.appState),!i)return;let o="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case Ze.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Ze.NEVER:case Ze.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:Fh(n,"Unknown store action")}}finally{switch(n){case Ze.IMMEDIATELY:case Ze.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Ze.IMMEDIATELY)?t=Ze.IMMEDIATELY:this.scheduledMacroActions.has(Ze.NEVER)?t=Ze.NEVER:t=Ze.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Ze).length)){let t=`There can be at most three store actions scheduled at the same time, but there are "${this.scheduledMacroActions.size}".`;if(console.error(t,this.scheduledMacroActions.values()),zh()||Rh())throw new Error(t)}}},qi=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},tr=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},_s=class extends tr{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},Ws=class extends tr{constructor(n){super("ephemeral",n);this.change=n}},Us=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:Hh()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?Tn.calculate(t.elements,n.elements):Tn.empty(),o=n.metadata.didAppStateChange?Mn.calculate(t.appState,n.appState):Mn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,Tn.restore(i),Mn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=Tn.create(n,i,o),a=Mn.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,Dn.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(Tn.empty(),Mn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Dn=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,nc(n)?n:hi(n),i)}static empty(){return new e(new Map,_h(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of fi(t.elements))this.elements.get(i.id)||(n[i.id]=Fe(i,{isDeleted:!0}));for(let i of fi(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return j.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=hi({...this.appState,...t.appState});return e.create(n,i,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,i){let o={shouldCompareHashes:!1};t===Ze.EVENTUALLY&&(o.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,o),s=this.maybeCreateAppStateSnapshot(i,o),a=!1,l=!1;return this.elements!==r&&(a=!0),this.appState!==s&&(l=!0),!a&&!l?this:new e(r,s,{didElementsChange:a,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let i=nc(t)?t:hi(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=j.isRightDifferent(this.appState,t);if(!i)return;let o=rc(JSON.stringify(t));if(!(n.shouldCompareHashes&&this._lastChangedAppStateHash===o))return this._lastChangedAppStateHash=o,i}detectChangedElements(t,n={shouldCompareHashes:!1}){if(this.elements===t)return;let i=new Map;for(let r of fi(this.elements))t.get(r.id)||i.set(r.id,Fe(r,{isDeleted:!0}));for(let r of fi(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(Ae(r)&&!zn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=oc(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of fi(this.elements))n.set(i.id,i);for(let i of fi(t))n.set(i.id,Hs(i));return n}},ic="__observedAppState",_h=()=>({name:null,editingGroupId:null,viewBackgroundColor:Nh.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),hi=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,ic,{value:!0,enumerable:!1}),t},nc=e=>!!Reflect.get(e,ic);P();var hc=hu(cc(),1);import{randomInteger as rE,arrayToMap as sE,toBrandedType as uc,isDevEnv as mc,isTestEnv as pc,toArray as aE}from"@excalidraw/common";import{isNonDeletedElement as lE}from"@excalidraw/element";import{isFrameLikeElement as dE}from"@excalidraw/element";import{getElementsInGroup as cE}from"@excalidraw/element";import{syncInvalidIndices as uE,syncMovedIndices as mE,validateFractionalIndices as pE}from"@excalidraw/element";import{getSelectedElements as fE}from"@excalidraw/element";import{mutateElement as hE}from"@excalidraw/element";var fc=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}},EE=(0,hc.default)(e=>{(mc()||pc()||window?.DEBUG_FRACTIONAL_INDICES)&&pE(e,{shouldThrow:mc()||pc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),gE=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Ei=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=uc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=uc(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=gE(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=fE(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&&lE(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=aE(t),o=[];n?.skipValidation||EE(i),this.elements=uE(i),this.elementsMap.clear(),this.elements.forEach(s=>{dE(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=fc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=fc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=rE();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)];mE(i,sE(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]:cE(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=hE(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var j=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i=e.empty()){return e.create({...t.deleted,...n.deleted,...i.deleted},{...t.inserted,...n.inserted,...i.inserted})}static mergeObjects(t,n,i={}){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Jt(t??[],o),Jt(n??[],o),Jt(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=Jt(e.getLeftDifferences(Jt(r,o),Jt(s,o)),d=>d),l=Jt(e.getRightDifferences(Jt(r,o),Jt(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)])):gc(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&&xc(a,l))continue;yield s}}}},Mn=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=j.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(j.create({},{}))}inverse(){let t=j.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=j.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=j.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=j.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=j.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=j.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=j.mergeObjects(this.delta.inserted.lockedMultiSelections??{},t.delta.inserted.lockedMultiSelections??{}),l={},d={};return(Object.keys(n).length||Object.keys(i).length)&&(d.selectedElementIds=n,l.selectedElementIds=i),(Object.keys(o).length||Object.keys(r).length)&&(d.selectedGroupIds=o,l.selectedGroupIds=r),(Object.keys(s).length||Object.keys(a).length)&&(d.lockedMultiSelections=s,l.lockedMultiSelections=a),this.delta=j.merge(this.delta,t.delta,j.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:s={},selectedGroupIds:a={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=j.mergeObjects(t.selectedElementIds,s,i),m=j.mergeObjects(t.selectedGroupIds,a,o),p=j.mergeObjects(t.lockedMultiSelections,l,r),h=d&&n.has(d.elementId)?new G(n.get(d.elementId),n,d.isEditing):null,f={...t,...c,selectedElementIds:u,selectedGroupIds:m,lockedMultiSelections:p,selectedLinearElement:typeof d<"u"?h:t.selectedLinearElement},E=this.filterInvisibleChanges(t,f,n);return[f,E]}catch(i){if(console.error("Couldn't apply appstate change",i),Bn()||vn())throw i;return[t,!1]}}isEmpty(){return j.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=hi(t),r=hi(n),s=j.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=j.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=j.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=hd(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]||{};xc(h,f)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,g=n[u]||null;E!==g&&(l.value=!0);break;default:gc(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{j.diffObjects(t,n,"selectedElementIds",i=>!0),j.diffObjects(t,n,"selectedGroupIds",i=>i??!1),j.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),Bn()||vn())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}},Tn=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(Bn()||vn())&&(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:Ec()},c=j.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:Ec()},d={...s},c=j.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=j.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}r[s.id]=l}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=j.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,m)=>{let p;switch(m){case"deleted":p=d;break;case"inserted":p=c;break}if(!p)return console.error("Element not found when trying to apply latest changes"),u;let h={};for(let f of Object.keys(u))switch(f){case"boundElements":h[f]=u[f];break;default:h[f]=p[f]}return h},r=d=>{let c={};for(let[u,m]of Object.entries(d)){let p=t.get(u),h=n.get(u),f=null;p||h?f=j.create(m.deleted,m.inserted,o(p,h),i):f=m,j.isInnerDifferent(f.deleted,f.inserted)&&(c[u]=f)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=Dn.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),Bn()||vn())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),Bn()||vn())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=j.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=j.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return j.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=j.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=j.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=j.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(Bn()||vn())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,i,o,r)=>s=>{let a=e.createGetter(n,i,o);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let m=e.applyDelta(u,c,o,r);if(n.set(m.id,m),l.set(m.id,m),!o.applyDirection){let p=t.get(d);p&&(o.applyDirection=p.version>m.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?(i.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(i.containsVisibleDifference=!0)):s=Fe({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=j.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!i.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);i.containsVisibleDifference=l}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Fe(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:j.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,m=l,p;c===d?p=Fe(d,{...m,version:u},!0):p=De(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=>ed.has(c)))){let l=n.get(a);!l||l.isDeleted||e.rebindAffected(t,n,a,r)}let s=new Map(Array.from(t).filter(([a])=>o.has(a)));return this.squash(e.calculate(s,o)),o}static unbindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);gn.unbindAffected(n,r(),o),gn.unbindAffected(n,s(),o),xn.unbindAffected(n,r(),o),xn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);gn.unbindAffected(n,r(),o),gn.rebindAffected(n,s(),o),xn.unbindAffected(n,r(),(a,l)=>{K(a)&&o(a,l)}),xn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Ei(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),Bn()||vn())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(he(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(yt(r)){let s=Ut(r),a=s?i.get(s):void 0;a&&o.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of o.values())r.isDeleted||s.isDeleted||Mo(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&fe(i)&&ke(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=Id([...o]),s=j.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),xE($n(r,s))}static postProcess(t,n){try{j.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];j.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),Bn()||vn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var NI=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=Kt(e),c=jo(e,t,i).map(In).map(h=>[h,Kt(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]),E=(c[f][1][s]-c[h][1][s])/(c.length-1),g=c[h][1][s];return c.flatMap(([x,b],y)=>{let w={x:0,y:0};return y!==h&&y!==f&&(g+=E,w[n.axis]=g-b[s]),x.map(S=>{let I=o.mutateElement(S,{x:S.x+w.x,y:S.y+w.y});return ke(S,o,{simultaneouslyUpdated:x}),I})})}let p=d[r];return c.flatMap(([h,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[r],p+=m,p+=f[l],h.map(g=>{let x=o.mutateElement(g,{x:g.x+E.x,y:g.y+E.y});return ke(g,o,{simultaneouslyUpdated:h}),x})})};P();import{TEXT_AUTOWRAP_THRESHOLD as bE,getGridPoint as wE,getFontString as yE,DRAGGING_THRESHOLD as PE}from"@excalidraw/common";var $I=(e,t,n,i,o,r)=>{if(t.length===1&&U(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(U(m)&&m.startBinding&&m.endBinding){let p=t.find(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=>Z(m)).map(m=>m.id);if(l.length>0)for(let m of i.getNonDeletedElements())m.frameId!==null&&l.includes(m.frameId)&&a.add(m);let d=[];for(let m of a){let p=e.originalElements.get(m.id);if(!p)return;d.push(p)}let c=IE(ze(d),n,o,r),u=new Set(Array.from(a,m=>m.id));a.forEach(m=>{let p=!W(m),h=p||(m.startBinding?u.has(m.startBinding.elementId):!1),f=p||(m.endBinding?u.has(m.endBinding.elementId):!1);if(W(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>PE||!m.startBinding&&!m.endBinding){js(e,m,i,c);let E=m.startBinding&&!h,g=m.endBinding&&!f;(E||g)&&(E&&Oe(m,"start",i),g&&Oe(m,"end",i))}}else{js(e,m,i,c);let E=q(m,i.getNonDeletedElementsMap());E&&js(e,E,i,c),ke(m,i,{simultaneouslyUpdated:Array.from(a)})}})},IE=(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]=wE(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},js=(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})},VI=(e,t,n)=>{let[i,o]=ze(e);return[t-i,n-o]},ZI=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:m=null,originOffset:p=null,informMutation:h=!0})=>{l&&e.type!=="selection"&&(m?a=s/m:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Ns(t,a,o<n?-s:s):{width:s,height:a}=Ns(t,s,r<i?-a:a),a<0&&(a=-a)));let f=o<n?n-s:n,E=r<i?i-a:i;d&&(s+=s,a+=a,f=n-s/2,E=i-a/2);let g=null;if(K(e)){a=e.height;let x=Po(yE({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>bE/c&&(g={autoResize:!1}),E=i,d&&(f=n-s/2)}if(s!==0&&a!==0){let x=null;Ae(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:f+(p?.x??0),y:E+(p?.y??0),width:s,height:a,...g,...x},{informMutation:h,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as ir,normalizeLink as bc}from"@excalidraw/common";var eS=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(ir,e),bc(i.toString())}catch(i){console.error(i)}return bc(n)},tS=(e,t)=>{if(e.length>0&&SE(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},SE=e=>!!(e.length===1||e.length>1&&Ed(e)),nS=e=>{try{let t=new URL(e);return t.searchParams.has(ir)&&t.host===window.location.host}catch{return!1}},iS=e=>{try{let{searchParams:t}=new URL(e);if(t.has(ir))return t.get(ir)}catch{}return null};P();import{FONT_FAMILY as NE,VERTICAL_ALIGN as RE,escapeDoubleQuotes as Xs,getFontString as zE}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as Ln,DEFAULT_FONT_FAMILY as AE,DEFAULT_FONT_SIZE as ME,DEFAULT_TEXT_ALIGN as TE,DEFAULT_VERTICAL_ALIGN as DE,DEFAULT_STROKE_STREAMLINE as vE,VERTICAL_ALIGN as BE,randomInteger as LE,randomId as CE,getFontString as or,getUpdatedTimestamp as GE,getLineHeight as OE}from"@excalidraw/common";var gt=(e,{x:t,y:n,strokeColor:i=Ln.strokeColor,backgroundColor:o=Ln.backgroundColor,fillStyle:r=Ln.fillStyle,strokeWidth:s=Ln.strokeWidth,strokeStyle:a=Ln.strokeStyle,roughness:l=Ln.roughness,opacity:d=Ln.opacity,width:c=0,height:u=0,angle:m=0,groupIds:p=[],frameId:h=null,index:f=null,roundness:E=null,boundElements:g=null,link:x=null,locked:b=Ln.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||CE(),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:E,seed:y.seed??LE(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:g,updated:GE(),link:x,locked:b,customData:y.customData}),Zn=e=>gt(e.type,e),pS=e=>gt("embeddable",e),fS=e=>({...gt("iframe",e)}),wc=e=>Fe({...gt("frame",e),type:"frame",name:e?.name||null},{}),yc=e=>Fe({...gt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Pc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),qn=e=>{let t=e.fontFamily||AE,n=e.fontSize||ME,i=e.lineHeight||OE(t),o=Oi(e.text),r=Qe(o,or({fontFamily:t,fontSize:n}),i),s=e.textAlign||TE,a=e.verticalAlign||DE,l=Pc({textAlign:s,verticalAlign:a},r),d={...gt("text",e),text:o,fontSize:n,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i};return Fe(d,{})},kE=(e,t,n)=>{let{width:i,height:o}=Qe(n,or(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===BE.MIDDLE&&!e.containerId&&e.autoResize){let d=Qe(e.text,or(e),e.lineHeight),c=Pc(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,m]=$(e,t),[p,h,f,E]=an(e,i,o,!1),g=(d-p)/2,x=(c-h)/2,b=(u-f)/2,y=(m-E)/2;[a,l]=FE({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,b,y)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},FE=(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]},hS=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Wt(i,or(e),t?mt(t,e):e.width));let o=kE(e,n,i);return{text:i,...o}},ES=e=>({...gt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,strokeOptions:e.strokeOptions??{variability:"variable",streamline:vE}}),Ic=e=>{let t={...gt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Nt(t)?{...t,polygon:e.polygon??!1}:t},rr=e=>e.elbowed?{...gt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...gt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},Sc=e=>({...gt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var xt=new Map,HE=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,_E=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,WE=/^https:\/\/(?:www\.)?figma\.com/,Ac=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,UE=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,YE=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Mc=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,jE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,XE=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,$E=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Tc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Dc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,VE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Bc=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)},ZE=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=Bc(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}},Vs=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),vc=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),$s=e=>`<html><body>${e}</body></html>`,IS=e=>{if(!e)return null;if(xt.has(e))return xt.get(e);let t=e,n=vc.has(Zs(e,vc)||""),i="generic",o={w:560,h:840},r=e.match(HE);if(r?.[2]){let c=Bc(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},xt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(_E);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},xt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=ZE(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},xt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(WE))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},xt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(XE);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),xt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(YE.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Mc.test(e)){let c=e.match(Mc)[1],u=Xs(`https://twitter.com/x/status/${c}`),m={type:"document",srcdoc:p=>$s(`<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 xt.set(t,m),m}if(Dc.test(e)){let[,c,u,m]=e.match(Dc),p=Xs(`https://reddit.com/r/${c}/comments/${u}/${m}`),h={type:"document",srcdoc:f=>$s(`<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 xt.set(t,h),h}if(Ac.test(e)){let[,c,u]=e.match(Ac),m=Xs(`https://gist.github.com/${c}/${u}`),p={type:"document",srcdoc:()=>$s(`
21
+ C ${l} ${d}, ${l} ${d}, ${l+E} ${d+g}`,Je(e,!0,s))}else a=t.polygon([[l,d],[c,u],[m,p],[h,f]],Je(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Je(e,!1,s));case"line":case"arrow":{let a,l=Je(e,!1,s),d=e.points.length?e.points:[he(0,0)];if(W(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(Vd(d,16),Je(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=Yd(e,a,"start",c,t,l,i,s);a.push(...m)}if(u!==null){let m=Yd(e,a,"end",u,t,l,i,s);a.push(...m)}}return a}case"freedraw":{let a=[];if(Wn(e.points)){let l=vi(e.points,.75);a.push(t.curve(l,{...Je(e,!1,s),stroke:"none"}))}return a.push(xh(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return uh(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Vd=(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=wt(a,r),d=wt(s,a),c=Math.min(t,Wd(e[o],s)/2,Wd(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(" ")},$d=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Na(e);case"arrow":case"line":{let n=rt.generateElementShape(e,null)[0],[,,,,i,o]=V(e,t);return Bo(e)?Ra(e,n,he(e.x,e.y),e.angle,he(i,o)):ka(n,he(e.x,e.y),e.angle,he(i,o))}case"ellipse":return Oa(e);case"freedraw":{let[,,,,n,i]=V(e,t);return Fa(e,he(n,i),Bo(e))}}},xd=(e,t)=>{let n=[...e.points];if(t){if(!al(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>ph||n.length<4?n.push(he(o[0],o[1])):n[n.length-1]=he(o[0],o[1])}return{polygon:t,points:n}},xh=e=>Ah(Ih(e)),Rs={SIZE_FACTOR:4.25,THINNING:.6,SMOOTHING:.5},bh={SIZE_FACTOR:1.4},Zd=e=>e.strokeOptions?.streamline??fh,wh=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 ja(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*Rs.SIZE_FACTOR,thinning:Rs.THINNING,smoothing:Rs.SMOOTHING,streamline:Zd(e),easing:n=>Math.sin(n*Math.PI/2),last:!0})},yh=e=>new ho({size:e.strokeWidth*bh.SIZE_FACTOR,streamline:Zd(e),simplify:0,sizeMapping:t=>Math.max(.1,t.pressure)}),Ph=e=>{let t=yh(e);return e.points.map(([n,i])=>t.addPoint([n,i,1])),t.getStrokeOutline().map(([n,i])=>[n,i])},Ih=e=>e.strokeOptions?.variability==="constant"?Ph(e):wh(e),jd=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],Sh=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,Ah=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,jd(i,r[0]),"L",r[0],"Z"):n.push(i,jd(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(Sh,"$1")};var Ws=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&&!xe(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]=V(t,n);if(Ae(t)){let[c,u,m,p]=Us(t.points.map(([h,f])=>ee(v(h,f),v(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=Oh(t,l,d,n);else if(t.type==="diamond"){let[c,u]=ee(v(l,r),v(l,d),t.angle),[m,p]=ee(v(l,a),v(l,d),t.angle),[h,f]=ee(v(o,d),v(l,d),t.angle),[E,g]=ee(v(s,d),v(l,d),t.angle),x=Math.min(c,m,h,E),b=Math.min(u,p,f,g),y=Math.max(c,m,h,E),w=Math.max(u,p,f,g);i=[x,b,y,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,m=Math.cos(t.angle),p=Math.sin(t.angle),h=Math.hypot(c*m,u*p),f=Math.hypot(u*m,c*p);i=[l-h,d-f,l+h,d+f]}else{let[c,u]=ee(v(o,r),v(l,d),t.angle),[m,p]=ee(v(o,a),v(l,d),t.angle),[h,f]=ee(v(s,a),v(l,d),t.angle),[E,g]=ee(v(s,r),v(l,d),t.angle),x=Math.min(c,m,h,E),b=Math.min(u,p,f,g),y=Math.max(c,m,h,E),w=Math.max(u,p,f,g);i=[x,b,y,w]}return i}},V=(e,t,n=!1)=>{if(Ae(e))return vh(e);if(K(e))return C.getElementAbsoluteCoords(e,t,n);if(Q(e)){let i=t?Oe(e,t):null;if(_(i)){let{x:o,y:r}=C.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]},Bs=(e,t)=>{let n=$d(e,t),[i,o,r,s,a,l]=V(e,t),d=v(a,l);if(n.type==="polycurve"){let g=n.data.map(b=>zt(b,10)),x=[];if(Et(e)&&!e.polygon||_(e))for(let b of g){let y=0;for(;y<b.length-1;)x.push(Ee(v(b[y][0],b[y][1]),v(b[y+1][0],b[y+1][1]))),y++}else{let b=g.flat(),y=0;for(;y<b.length-1;)x.push(Ee(v(b[y][0],b[y][1]),v(b[y+1][0],b[y+1][1]))),y++}return x}else{if(n.type==="polyline")return n.data;if(Th(e)){let[E,g]=cn(e),x=g.map(y=>Qd(y,d,e.angle)).flat();return[...Kd(E,d,e.angle),...x]}else if(e.type==="diamond"){let[E,g]=un(e),x=g.map(y=>Qd(y,d,e.angle)).flat();return[...Kd(E,d,e.angle),...x]}else if(n.type==="polygon"){if(Q(e)){let x=Oe(e,t);if(x&&K(x))return[Ee(v(i,o),v(r,o)),Ee(v(r,o),v(r,s)),Ee(v(r,s),v(i,s)),Ee(v(i,s),v(i,o))]}let E=n.data,g=[];for(let x=0;x<E.length-1;x++)g.push(Ee(E[x],E[x+1]));return g}else if(n.type==="ellipse")return Dh(e)}let[c,u,m,p,,,h,f]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(E=>ee(E,d,e.angle));return[Ee(c,u),Ee(m,p),Ee(c,m),Ee(u,p),Ee(c,f),Ee(m,f),Ee(u,h),Ee(p,h)]},Th=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),Kd=(e,t,n)=>e.map(i=>Ee(ee(i[0],t,n),ee(i[1],t,n))),Qd=(e,t,n)=>{let i=zt(e,10),o=0,r=[];for(;o<i.length-1;)r.push(Ee(ee(v(i[o][0],i[o][1]),t,n),ee(v(i[o+1][0],i[o+1][1]),t,n))),o++;return r},Dh=e=>{let t=v(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(ee(v(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(Ee(r[l],r[l+1]));return o.push(Ee(r[r.length-1],r[0])),o},LI=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],si=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]},Jd=(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},ec=(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=Jd(h,e,t,n,i)),f>=0&&f<=1&&(p=Jd(f,e,t,n,i)),[m,p]},Co=(e,t,n,i)=>{let o=ec(e[0],t[0],n[0],i[0]),r=ec(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]},Vi=(e,t)=>{let n=v(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=nc(d);_s(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=v(d[0],d[1]),u=v(d[2],d[3]),m=v(d[4],d[5]),p=t?t(c):c,h=t?t(u):u,f=t?t(m):m,E=t?t(n):n;n=m;let[g,x,b,y]=Co(E,p,h,f);a.minX=Math.min(a.minX,g),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]},Us=(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]},vh=e=>{let[t,n,i,o]=Us(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]},Bh=20,Lh=15,Ch=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 Lh;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return Bh;default:return 15}},Gh=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},je=(e,t,n,i,o=0)=>{if(i===null||t.length<1)return null;let r=Ht(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;_s(a.length===6,"Op data length is not 6");let l=v(a[4],a[5]),d=v(a[2],a[3]),c=v(a[0],a[1]),u=r[s-1],m=v(0,0);if(u.op==="move"){let T=nc(u.data);_s(T!=null,"Op data is not a point"),m=T}else u.op==="bcurveTo"&&(m=v(u.data[4],u.data[5]));let p=(T,F)=>Math.pow(1-T,3)*l[F]+3*T*Math.pow(1-T,2)*d[F]+3*Math.pow(T,2)*(1-T)*c[F]+m[F]*Math.pow(T,3),[h,f]=n==="start"?m:l,[E,g]=[p(.3,0),p(.3,1)],x=Math.hypot(h-E,f-g),b=(h-E)/x,y=(f-g)/x,w=Ch(i),S=0;{let[T,F]=n==="end"?e.points[e.points.length-1]:e.points[0],[U,ge]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];S=Math.hypot(T-U,F-ge)}let M=Math.min(w,S*(i==="diamond"||i==="diamond_outline"?.25:.5)),A=h-b*M*o,G=f-y*M*o,L=A-b*M,N=G-y*M;if(i==="circle"||i==="circle_outline"){let T=Math.hypot(N-G,L-A)+e.strokeWidth-2;return[A,G,T]}let D=Gh(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[T,F]=ee(v(A,G),v(L,N),Hs(-D)),[U,ge]=ee(v(A,G),v(L,N),Hs(D));return[L,N,T,F,U,ge]}let[j,H]=ee(v(L,N),v(A,G),-D*Math.PI/180),[Z,k]=ee(v(L,N),v(A,G),Hs(D));if(i==="diamond"||i==="diamond_outline"){let T,F;if(n==="start"){let[U,ge]=e.points.length>1?e.points[1]:[0,0];[T,F]=ee(v(A+M*2,G),v(A,G),Math.atan2(ge-G,U-A))}else{let[U,ge]=e.points.length>1?e.points[e.points.length-2]:[0,0];[T,F]=ee(v(A-M*2,G),v(A,G),Math.atan2(G-ge,A-U))}return[A,G,j,H,T,F,Z,k]}return[A,G,j,H,Z,k]},Nh=e=>{let t=ii.generator(),n=Je(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},Oh=(e,t,n,i)=>{let o=ne(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,h]=ee(v(e.x+u,e.y+m),v(t,n),e.angle),f=[p,h,p,h];if(o){let E=C.getMinMaxXYWithBoundText(e,i,[p,h,p,h],o);f=[E[0],E[1],E[2],E[3]]}return f}let s=rt.get(e,null)?.[0]??Nh(e),a=Ht(s),d=Vi(a,([u,m])=>ee(v(e.x+u,e.y+m),v(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=C.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},de=(e,t,n=!1)=>Ws.getBounds(e,t,n),Ye=(e,t)=>{if(!Mh(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||tc(e);return e.forEach(a=>{let[l,d,c,u]=de(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]},CI=(e,t)=>{let[n,i,o,r]=Ye(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},dn=(e,t,n,i)=>{if(!(K(e)||Ae(e)))return[e.x,e.y,e.x+t,e.y+n];let o=qd(0,t,qd(1,n,e.points,i),i),r;if(Ae(e))r=Us(o);else{let c=ii.generator(),u=e.roundness?c.curve(o,Je(e)):c.linearPath(o,Je(e)),m=Ht(u);r=Vi(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Ps=(e,t)=>{let n=ii.generator(),i=e.roundness==null?n.linearPath(t,Je(e)):n.curve(t,Je(e)),o=Ht(i),[r,s,a,l]=Vi(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},Jt=e=>{let[t,n,i,o]=Ye(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},GI=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],$t=e=>v(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),Ke=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=re(e,t),[r,s]=ee(v(i.minX,i.minY),o,e.angle),[a,l]=ee(v(i.maxX,i.minY),o,e.angle),[d,c]=ee(v(i.maxX,i.maxY),o,e.angle),[u,m]=ee(v(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,E,g]=n;return[p[0]-g,p[1]-h,p[2]+f,p[3]+E]}return p},Bt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],kh=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],Zt=(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},Gs=(e,t)=>[v(t[0],t[1]),v(t[0],t[3]),v(t[2],t[1]),v(t[2],t[3])].every(n=>kh(n,e)),Td=({elements:e,elementsMap:t,bounds:n,type:i,excludeElementsInFrames:o,shouldIgnoreElementFromSelection:r})=>{t||(t=tc(e));let s=ol(n)?de(n,t):n,[a,l,d,c]=s,u=[Ee(v(a,l),v(d,l)),Ee(v(d,l),v(d,c)),Ee(v(d,c),v(a,c)),Ee(v(a,c),v(a,l))],m=o?new Set:null,p={},h=new Set;for(let f of e){if(r?.(f))continue;let E=f.groupIds.at(-1);E&&(p[E]||(p[E]=[]),p[E].push(f));let g=f.strokeWidth,x=null,b=de(f,t);b=[b[0]-g/2,b[1]-g/2,b[2]+g/2,b[3]+g/2];let y=_(f)&&ne(f,t);if(y){let{x:I,y:M}=C.getBoundTextElementPosition(f,y,t);x=[I,M,I+y.width,M+y.height]}let w=Pn(f,t);if(w&&yn(f,w,t)){let I=de(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(Gs(s,S)){m&&q(f)&&m.add(f.id),h.add(f);continue}if(i==="overlap"&&x&&Zt(s,x)){h.add(f);continue}if(i==="overlap"&&Zt(s,b)){let I=!1;if(K(f)||Ae(f)){let M=re(f,t);I=f.points.some(A=>{let G=ee(v(f.x+A[0],f.y+A[1]),M,f.angle);return Bt(G,s)})}else{let M=de(f,t,!0),A=re(f,t);I=[ee(v((M[0]+M[2])/2,M[1]),A,f.angle),ee(v(M[2],(M[1]+M[3])/2),A,f.angle),ee(v((M[0]+M[2])/2,M[3]),A,f.angle),ee(v(M[0],(M[1]+M[3])/2),A,f.angle)].some(G=>Bt(ee(G,A,f.angle),s))}if(I||(I=u.some(M=>ut(f,t,M,g/2,!0).length>0)),I){m&&q(f)&&m.add(f.id),h.add(f);continue}}}return m&&h.forEach(f=>{f.frameId&&m.has(f.frameId)&&h.delete(f)}),i==="overlap"?Array.from(h).forEach(f=>{let E=f.groupIds.at(-1);(E?p[E]:null)?.forEach(x=>h.add(x))}):i==="contain"&&h.forEach(f=>{let E=f.groupIds.at(-1),g=E?p[E]:null;g&&!g.every(x=>h.has(x))&&h.delete(f)}),e.filter(f=>h.has(f))},re=(e,t,n=0,i=0)=>{if(K(e)||Ae(e)){let[s,a,l,d]=V(e,t),[c,u]=v((s+l)/2,(a+d)/2);return v(c+n,u+i)}let[o,r]=$t(de(e,t));return v(o+n,r+i)};var Hh=.1,oc=e=>K(e)||Ae(e)?e.points.length<2||e.points.length===2&&_(e)&&zh(e.points[0],e.points[e.points.length-1],Hh):e.width===0&&e.height===0,Dd=(e,t,n,i,o)=>{let[r,s,a,l]=de(e,o),d=nr({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=nr({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},_I=(e,t,n,i,o,r)=>{let[s,a,l,d]=Ye(e,o),c=nr({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=nr({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},Ys=(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)/en)*en;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}},bd=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/en)*en;if(o){let d=Math.floor(o/en)*en;Fh(a,d,d+en)&&(Rh(a,o)<en/6?l=o:ic(a)>ic(o)?l=d+en: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),E=(u*m-h*d)/(d*p-m*c);r=f-e,s=E-t}return{width:r,height:s}},WI=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t};P();var ZI=(e,t,n,i)=>{let o=Vo(e,n.getNonDeletedElementsMap(),i).map(Sn),r=Jt(e);return o.flatMap(s=>{let a=_h(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Re(l,n,{simultaneouslyUpdated:s}),d})})},_h=(e,t,{axis:n,position:i})=>{let o=Jt(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};P();import{TEXT_ALIGN as rr,VERTICAL_ALIGN as sr}from"@excalidraw/common";import{pointDistance as Jh,pointFromVector as eE,pointsEqual as uc,vector as tE,vectorDot as nE,vectorFromPoint as cc,vectorNormalize as iE,vectorScale as oE}from"@excalidraw/math";P();import{DEFAULT_ELEMENT_PROPS as Tn,DEFAULT_FONT_FAMILY as Wh,DEFAULT_FONT_SIZE as Uh,DEFAULT_TEXT_ALIGN as Yh,DEFAULT_VERTICAL_ALIGN as jh,DEFAULT_STROKE_STREAMLINE as Xh,VERTICAL_ALIGN as Kn,randomInteger as Vh,randomId as $h,getFontString as ir,getUpdatedTimestamp as Zh,getLineHeight as qh}from"@excalidraw/common";var It=(e,{x:t,y:n,strokeColor:i=Tn.strokeColor,backgroundColor:o=Tn.backgroundColor,fillStyle:r=Tn.fillStyle,strokeWidth:s=Tn.strokeWidth,strokeStyle:a=Tn.strokeStyle,roughness:l=Tn.roughness,opacity:d=Tn.opacity,width:c=0,height:u=0,angle:m=0,groupIds:p=[],frameId:h=null,index:f=null,roundness:E=null,boundElements:g=null,link:x=null,locked:b=Tn.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||$h(),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:E,seed:y.seed??Vh(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:g,updated:Zh(),link:x,locked:b,customData:y.customData}),gi=e=>It(e.type,e),rS=e=>It("embeddable",e),sS=e=>({...It("iframe",e)}),rc=e=>_e({...It("frame",e),type:"frame",name:e?.name||null},{}),sc=e=>_e({...It("magicframe",e),type:"magicframe",name:e?.name||null},{}),js=e=>({x:e.textAlign==="center"?.5:e.textAlign==="right"?1:0,y:e.verticalAlign===Kn.MIDDLE?.5:e.verticalAlign===Kn.BOTTOM?1:0}),ac=(e,t)=>{let n=js(e);return{x:t.width*n.x,y:t.height*n.y}},Qn=e=>{let t=e.fontFamily||Wh,n=e.fontSize||Uh,i=e.lineHeight||qh(t),o=zi(e.text),r=it(o,ir({fontFamily:t,fontSize:n}),i),s=e.textAlign||Yh,a=e.verticalAlign||jh,l=ac({textAlign:s,verticalAlign:a},r),d={...It("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 _e(d,{})},Kh=(e,t,n)=>{let{width:i,height:o}=it(n,ir(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Kn.MIDDLE&&!e.containerId&&e.autoResize){let d=it(e.text,ir(e),e.lineHeight),c=ac(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]=V(e,t),[p,h,f,E]=dn(e,i,o,!1),g=(d-p)/2,x=(c-h)/2,b=(u-f)/2,y=(m-E)/2;[a,l]=Qh({n:s===Kn.MIDDLE||s===Kn.BOTTOM,s:s===Kn.MIDDLE||s===Kn.TOP,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,b,y)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},Qh=(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]},aS=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Xt(i,ir(e),t?xt(t,e):e.width));let o=Kh(e,n,i);return{text:i,...o}},lS=e=>({...It(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,strokeOptions:e.strokeOptions??{variability:"variable",streamline:Xh}}),lc=e=>{let t={...It(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Et(t)?{...t,polygon:e.polygon??!1}:t},or=e=>e.elbowed?{...It(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}:{...It(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},dc=e=>({...It("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var xS=(e,t,n,i)=>{for(let o=t.length-1;o>=0;o--){let r=t[o];if(!(!_(r)||r.locked||r.points.length<2))for(let s of["end","start"]){if(r[s==="start"?"startBinding":"endBinding"]||uc(r.points[s==="start"?0:r.points.length-1],r.points[s==="start"?1:r.points.length-2]))continue;let a=C.getPointAtIndexGlobalCoordinates(r,s==="start"?0:-1,n);if(Jh(e,a)*i.value<C.POINT_HANDLE_SIZE+1)return{arrow:r,startOrEnd:s}}}return null},bS=(e,t,n,i)=>{let o=C.getPointAtIndexGlobalCoordinates(e,t==="start"?0:-1,n),r=C.getPointAtIndexGlobalCoordinates(e,t==="start"?1:-2,n);if(uc(o,r))return null;let s=cc(o,r),a=Math.abs(s[0])>=Math.abs(s[1])?s[0]>=0?le:De:s[1]>=0?Ie:He,l=W(e)?0:Pe({strokeWidth:i},e),d=iE(cc(r,o)),c=Math.abs(nE(d,tE(a[0],a[1]))),u=eE(oE(d,-l/c),o);return ae(a,le)?{fixedPoint:Ne([0,.5]),anchor:u,textAlign:rr.LEFT,verticalAlign:sr.MIDDLE}:ae(a,De)?{fixedPoint:Ne([1,.5]),anchor:u,textAlign:rr.RIGHT,verticalAlign:sr.MIDDLE}:ae(a,Ie)?{fixedPoint:Ne([.5,0]),anchor:u,textAlign:rr.CENTER,verticalAlign:sr.TOP}:{fixedPoint:Ne([.5,1]),anchor:u,textAlign:rr.CENTER,verticalAlign:sr.BOTTOM}},wS=(e,t)=>!!e.boundElements?.some(({id:n,type:i})=>{if(i!=="arrow")return!1;let o=t.get(n);return _(o)&&(o.startBinding?.elementId===e.id||o.endBinding?.elementId===e.id)}),yS=e=>{let t=js(e).x;return{anchorRatio:t,anchorX:e.x+e.width*t}};P();import{arrayToMap as KE,arrayToObject as tn,assertNever as Lc,isDevEnv as Ln,isShallowEqual as Cc,isTestEnv as Cn,randomInteger as Bc}from"@excalidraw/common";P();import{assertNever as hE,COLOR_PALETTE as EE,isDevEnv as gE,isTestEnv as xE,randomId as bE,Emitter as fc,toIterable as bi}from"@excalidraw/common";P();import{ORIG_ID as lE,randomId as pc,randomInteger as dE,arrayToMap as cE,castArray as Xs,findLastIndex as xi,getUpdatedTimestamp as uE,isTestEnv as mE}from"@excalidraw/common";P();import{arrayToMap as rE}from"@excalidraw/common";var sE=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},aE=e=>{let t=rE(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]},mc=e=>aE(sE(e));var pE=(e,t,n,i)=>{let o=$s(n);return mE()&&fE(o,n.id),o.id=pc(),o.updated=uE(),i&&(o.seed=dE(),Zl(o)),o.groupIds=Ad(o.groupIds,e,r=>(t.has(r)||t.set(r,pc()),t.get(r))),o},kS=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=cE(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(g=>[g.id,g])),m=e.type==="everything"&&e.preserveFrameChildrenOrder;if(e.type==="in-place")for(let g of Object.keys(e.appState.selectedGroupIds))t.filter(x=>x.groupIds?.includes(g)).forEach(x=>u.set(x.id,x));t=mc(t);let p=t.slice(),h=g=>{let b=Xs(g).reduce((y,w)=>{if(i.has(w.id))return y;i.set(w.id,!0),ze(w)||console.error("[NONDELETED][INVARIANT] Element to duplicate should be non-deleted");let S=pE(n.editingGroupId,o,w,e.randomizeSeed);return i.set(S.id,!0),d.set(S.id,S),a.set(w.id,S.id),l.set(S.id,w),s.push(w),r.push(S),y.push(S),y},[]);return Array.isArray(g)?b:b[0]||null},f=(g,x)=>{if(x){if(g>p.length-1){p.push(...Xs(x));return}p.splice(g+1,0,...Xs(x))}},E=new Set(t.filter(g=>u.has(g.id)&&q(g)).map(g=>g.id));for(let g of t){if(i.has(g.id)||!u.has(g.id))continue;let x=Ss(n,g);if(x){let b=Ue(t,x).flatMap(w=>q(w)&&!m?[...wn(t,w.id),w]:[w]),y=xi(p,w=>w.groupIds?.includes(x));f(y,h(b));continue}if(!(!m&&g.frameId&&E.has(g.frameId))){if(q(g)){let b=g.id;if(m){f(xi(p,S=>S.id===b),h(g));continue}let y=wn(t,b),w=xi(p,S=>S.frameId===b||S.id===b);f(w,h([...y,g]));continue}if(Tt(g)){let b=ne(g,c),y=xi(p,w=>w.id===g.id||"containerId"in w&&w.containerId===g.id);b?f(y,h([g,b])):f(y,h(g));continue}if(xe(g)){let b=Oe(g,c),y=xi(p,w=>w.id===g.id||w.id===b?.id);b?f(y,h([b,g])):f(y,h(g));continue}f(xi(p,b=>b.id===g.id),h(g))}}if(sd(r,a,d),Gd(p,s,a),e.overrides)for(let g of r){let x=l.get(g.id);x&&Object.assign(g,e.overrides({duplicateElement:g,origElement:x,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:p,origIdToDuplicateId:a}},Vs=(e,t=0)=>{if(e==null||typeof e!="object")return e;let n=Object.prototype.toString.call(e);if(n==="[object Object]"){let i=typeof e.constructor=="function"?Object.create(Object.getPrototypeOf(e)):{};for(let o in e)if(e.hasOwnProperty(o)){if(t===0&&(o==="shape"||o==="canvas"))continue;i[o]=Vs(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=Vs(e[i],t+1);return o}return B.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},$s=e=>Vs(e),fE=(e,t)=>{Object.defineProperty(e,lE,{value:t,writable:!1,enumerable:!1})};var et={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},hc=class{constructor(t){this.app=t}onDurableIncrementEmitter=new fc;onStoreIncrementEmitter=new fc;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Bn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(et.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=Bn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?Ld(t.elements):void 0,t.appState);i=Qi.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=Bn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=Qi.create(o,t),i?s=i:s=Ks.calculate(o,t),!s.isEmpty()){let a=new Zs(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=Qi.create(r,t)}let o=new qs(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===et.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 et.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case et.NEVER:case et.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:hE(n,"Unknown store action")}}finally{switch(n){case et.IMMEDIATELY:case et.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(et.IMMEDIATELY)?t=et.IMMEDIATELY:this.scheduledMacroActions.has(et.NEVER)?t=et.NEVER:t=et.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(et).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()),xE()||gE())throw new Error(t)}}},Qi=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},ar=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Zs=class extends ar{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},qs=class extends ar{constructor(n){super("ephemeral",n);this.change=n}},Ks=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:bE()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?vn.calculate(t.elements,n.elements):vn.empty(),o=n.metadata.didAppStateChange?Dn.calculate(t.appState,n.appState):Dn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,vn.restore(i),Dn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=vn.create(n,i,o),a=Dn.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,Bn.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(vn.empty(),Dn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Bn=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,Ec(n)?n:wi(n),i)}static empty(){return new e(new Map,wE(),{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]=_e(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 Y.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=wi({...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===et.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=Ec(t)?t:wi(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=Y.isRightDifferent(this.appState,t);if(!i)return;let o=bc(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,_e(r,{isDeleted:!0}));for(let r of bi(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(Te(r)&&!Hn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=xc(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,$s(i));return n}},gc="__observedAppState",wE=()=>({name:null,editingGroupId:null,viewBackgroundColor:EE.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),wi=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,gc,{value:!0,enumerable:!1}),t},Ec=e=>!!Reflect.get(e,gc);P();var vc=vu(Sc(),1);import{randomInteger as RE,arrayToMap as zE,toBrandedType as Ac,isDevEnv as Mc,isTestEnv as Tc,toArray as HE}from"@excalidraw/common";import{isNonDeletedElement as _E}from"@excalidraw/element";import{isFrameLikeElement as WE}from"@excalidraw/element";import{getElementsInGroup as UE}from"@excalidraw/element";import{syncInvalidIndices as YE,syncMovedIndices as jE,validateFractionalIndices as XE}from"@excalidraw/element";import{getSelectedElements as VE}from"@excalidraw/element";import{mutateElement as $E}from"@excalidraw/element";var Dc=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}},ZE=(0,vc.default)(e=>{(Mc()||Tc()||window?.DEBUG_FRACTIONAL_INDICES)&&XE(e,{shouldThrow:Mc()||Tc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),qE=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},yi=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=Ac(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=Ac(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=qE(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=VE(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&&_E(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=HE(t),o=[];n?.skipValidation||ZE(i),this.elements=YE(i),this.elementsMap.clear(),this.elements.forEach(s=>{WE(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=Dc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=Dc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=RE();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)];jE(i,zE(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]:UE(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=$E(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var Y=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(tn(t??[],o),tn(n??[],o),tn(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=tn(e.getLeftDifferences(tn(r,o),tn(s,o)),d=>d),l=tn(e.getRightDifferences(tn(r,o),tn(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)])):Lc(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&&Cc(a,l))continue;yield s}}}},Dn=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=Y.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(Y.create({},{}))}inverse(){let t=Y.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=Y.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=Y.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=Y.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=Y.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=Y.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=Y.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=Y.merge(this.delta,t.delta,Y.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=Y.mergeObjects(t.selectedElementIds,s,i),m=Y.mergeObjects(t.selectedGroupIds,a,o),p=Y.mergeObjects(t.lockedMultiSelections,l,r),h=d&&n.has(d.elementId)?new C(n.get(d.elementId),n,d.isEditing):null,f={...t,...c,selectedElementIds:u,selectedGroupIds:m,lockedMultiSelections:p,selectedLinearElement:typeof d<"u"?h:t.selectedLinearElement},E=this.filterInvisibleChanges(t,f,n);return[f,E]}catch(i){if(console.error("Couldn't apply appstate change",i),Cn()||Ln())throw i;return[t,!1]}}isEmpty(){return Y.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=wi(t),r=wi(n),s=Y.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=Y.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=Y.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=Pd(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let b=i.get(x);b&&!b.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let m=n[u];m?c.has(m)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let p=n[u];if(!p)l.value=!0;else{let x=i.get(p.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let h=t[u]||{},f=n[u]||{};Cc(h,f)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,g=n[u]||null;E!==g&&(l.value=!0);break;default:Lc(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{Y.diffObjects(t,n,"selectedElementIds",i=>!0),Y.diffObjects(t,n,"selectedGroupIds",i=>i??!1),Y.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),Cn()||Ln())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}},vn=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(Cn()||Ln())&&(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:Bc()},c=Y.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:Bc()},d={...s},c=Y.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=Y.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]=Y.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=Y.create(m.deleted,m.inserted,o(p,h),i):f=m,Y.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=Bn.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),Cn()||Ln())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),Cn()||Ln())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=Y.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=Y.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return Y.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]=Y.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]=Y.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=Y.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(Cn()||Ln())&&(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=_e({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=Y.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),_e(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:Y.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=_e(d,{...m,version:u},!0):p=ve(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=>ad.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);xn.unbindAffected(n,r(),o),xn.unbindAffected(n,s(),o),bn.unbindAffected(n,r(),o),bn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);xn.unbindAffected(n,r(),o),xn.rebindAffected(n,s(),o),bn.unbindAffected(n,r(),(a,l)=>{Q(a)&&o(a,l)}),bn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new yi(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),Cn()||Ln())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(xe(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(Tt(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||vo(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&fe(i)&&Re(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=Bd([...o]),s=Y.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),KE(Zn(r,s))}static postProcess(t,n){try{Y.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];Y.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),Cn()||Ln())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var wA=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=Jt(e),c=Vo(e,t,i).map(Sn).map(h=>[h,Jt(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]),E=(c[f][1][s]-c[h][1][s])/(c.length-1),g=c[h][1][s];return c.flatMap(([x,b],y)=>{let w={x:0,y:0};return y!==h&&y!==f&&(g+=E,w[n.axis]=g-b[s]),x.map(S=>{let I=o.mutateElement(S,{x:S.x+w.x,y:S.y+w.y});return Re(S,o,{simultaneouslyUpdated:x}),I})})}let p=d[r];return c.flatMap(([h,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[r],p+=m,p+=f[l],h.map(g=>{let x=o.mutateElement(g,{x:g.x+E.x,y:g.y+E.y});return Re(g,o,{simultaneouslyUpdated:h}),x})})};P();import{TEXT_AUTOWRAP_THRESHOLD as QE,getGridPoint as JE,getFontString as eg,DRAGGING_THRESHOLD as tg}from"@excalidraw/common";var BA=(e,t,n,i,o,r)=>{if(t.length===1&&W(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(W(m)&&m.startBinding&&m.endBinding){let p=t.find(f=>f.id===m.startBinding?.elementId),h=t.find(f=>f.id===m.endBinding?.elementId);return p&&h}return!0}),a=new Set(s),l=s.filter(m=>q(m)).map(m=>m.id);if(l.length>0)for(let m of i.getNonDeletedElements())m.frameId!==null&&l.includes(m.frameId)&&a.add(m);let d=[];for(let m of a){let p=e.originalElements.get(m.id);if(!p)return;d.push(p)}let c=ng(Ye(d),n,o,r),u=new Set(Array.from(a,m=>m.id));a.forEach(m=>{let p=!_(m),h=p||(m.startBinding?u.has(m.startBinding.elementId):!1),f=p||(m.endBinding?u.has(m.endBinding.elementId):!1);if(_(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>tg||!m.startBinding&&!m.endBinding){Js(e,m,i,c);let E=m.startBinding&&!h,g=m.endBinding&&!f;(E||g)&&(E&&Fe(m,"start",i),g&&Fe(m,"end",i))}}else{Js(e,m,i,c);let E=ne(m,i.getNonDeletedElementsMap());E&&Js(e,E,i,c),Re(m,i,{simultaneouslyUpdated:Array.from(a)})}})},ng=(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]=JE(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Js=(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})},LA=(e,t,n)=>{let[i,o]=Ye(e);return[t-i,n-o]},ig=({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,Ao(eg({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight));s.mutateElement(e,{x:t-c*n,...o===void 0?{}:{y:o},width:c,...d>QE/r?{autoResize:!1}:{}},{informMutation:a,isDragging:!1})},CA=({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}=Ys(t,a,o<n?-s:s):{width:s,height:a}=Ys(t,s,r<i?-a:a),a<0&&(a=-a))),Q(e)){ig({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,E=r<i?i-a:i;if(d&&(s+=s,a+=a,f=n-s/2,E=i-a/2),s!==0&&a!==0){let g=null;Te(e)&&(g={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:f+(p?.x??0),y:E+(p?.y??0),width:s,height:a,...g},{informMutation:h,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as dr,normalizeLink as Gc}from"@excalidraw/common";var FA=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(dr,e),Gc(i.toString())}catch(i){console.error(i)}return Gc(n)},RA=(e,t)=>{if(e.length>0&&og(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},og=e=>!!(e.length===1||e.length>1&&Id(e)),zA=e=>{try{let t=new URL(e);return t.searchParams.has(dr)&&t.host===window.location.host}catch{return!1}},HA=e=>{try{let{searchParams:t}=new URL(e);if(t.has(dr))return t.get(dr)}catch{}return null};P();import{FONT_FAMILY as rg,VERTICAL_ALIGN as sg,escapeDoubleQuotes as ea,getFontString as ag}from"@excalidraw/common";var St=new Map,lg=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,dg=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,cg=/^https:\/\/(?:www\.)?figma\.com/,Nc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,ug=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,mg=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Oc=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,pg=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,fg=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,hg=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,kc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Fc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,Eg=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,zc=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)},gg=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=zc(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}},na=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"]),Rc=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"]),ta=e=>`<html><body>${e}</body></html>`,VA=e=>{if(!e)return null;if(St.has(e))return St.get(e);let t=e,n=Rc.has(ia(e,Rc)||""),i="generic",o={w:560,h:840},r=e.match(lg);if(r?.[2]){let c=zc(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},St.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(dg);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},St.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=gg(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},St.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(cg))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},St.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(fg);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),St.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(mg.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Oc.test(e)){let c=e.match(Oc)[1],u=ea(`https://twitter.com/x/status/${c}`),m={type:"document",srcdoc:p=>ta(`<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 St.set(t,m),m}if(Fc.test(e)){let[,c,u,m]=e.match(Fc),p=ea(`https://reddit.com/r/${c}/comments/${u}/${m}`),h={type:"document",srcdoc:f=>ta(`<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 St.set(t,h),h}if(Nc.test(e)){let[,c,u]=e.match(Nc),m=ea(`https://gist.github.com/${c}/${u}`),p={type:"document",srcdoc:()=>ta(`
22
22
  <script src="${m}.js"><\/script>
23
23
  <style type="text/css">
24
24
  * { margin: 0px; }
25
25
  table, .gist { height: 100%; }
26
26
  .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
27
27
  </style>
28
- `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return xt.set(e,p),p}return xt.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},SS=e=>{let t;Eo(e)?t="IFrame element":t=!e.link||e?.link===""?"Empty Web-Embed":e.link;let n=Math.max(Math.min(e.width/2,e.width/t.length),e.width/30),i=NE.Helvetica,o=zE({fontSize:n,fontFamily:i});return qn({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:Wt(t,o,e.width-20),textAlign:"center",verticalAlign:RE.MIDDLE,angle:e.angle??0})},Zs=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(Vs.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return Vs.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},AS=e=>{let t=e.match(jE);if(t&&t.length===2)return t[1];let n=e.match(VE);if(n&&n.length===2)return n[1];let i=e.match(UE);if(i&&i.length===2)return i[1];if(Tc.test(e))return`https://giphy.com/embed/${Tc.exec(e)[1]}`;let o=e.match($E);return o&&o.length===2?o[1]:e},MS=(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(Zs(e,n))return!0;return!1}}return!!Zs(e,Vs)};P();import{KEYS as sr,invariant as ar,toBrandedType as qE}from"@excalidraw/common";import{pointFrom as Lc}from"@excalidraw/math";var gi=100,Kn=100,HS=e=>{switch(e){case sr.ARROW_UP:return"up";case sr.ARROW_DOWN:return"down";case sr.ARROW_RIGHT:return"right";case sr.ARROW_LEFT:return"left";default:return"right"}},Oc=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(U(s)&&(a=s[e==="predecessors"?"startBinding":"endBinding"])&&s[e==="predecessors"?"endBinding":"startBinding"]?.elementId===t.id){let l=n.get(a.elementId);if(!l)return r;ar(fe(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=Ri(t,st(t,n),[d[0]+s.x,d[1]+s.y]);r.push({relative:l,heading:c})}return r},[]);switch(i){case"up":return o.filter(r=>ge(r.heading,et)).map(r=>r.relative);case"down":return o.filter(r=>ge(r.heading,Te)).map(r=>r.relative);case"right":return o.filter(r=>ge(r.heading,xe)).map(r=>r.relative);case"left":return o.filter(r=>ge(r.heading,je)).map(r=>r.relative)}},qs=(e,t,n)=>Oc("successors",e,t,n),Ks=(e,t,n)=>Oc("predecessors",e,t,n),KE=(e,t,n)=>{let i=Kn+e.width;if(n==="up"||n==="down"){let a=gi+e.height,l=e.x,d=e.x+e.width;if(t.every(c=>c.x+c.width<l||c.x>d))return{x:0,y:a*(n==="up"?-1:1)}}else if(n==="right"||n==="left"){let a=e.y,l=e.y+e.height;if(t.every(d=>d.y+d.height<a||d.y>l))return{x:(Kn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=gi+e.height,l=(t.length===0,a),d=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*i:t.length/2*i*-1;return n==="up"?{x:d,y:l*-1}:{x:d,y:l}}let o=gi+e.height,r=(t.length===0,Kn+e.width),s=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*o:t.length/2*o*-1;return n==="left"?{x:r*-1,y:s}:{x:r,y:s}},QE=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=qs(e,o,n),s=Ks(e,o,n),a=KE(e,[...r,...s],n),l=Zn({type:e.type,x:e.x+a.x,y:e.y+a.y,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});ar(Lr(l),"not an ExcalidrawFlowchartNodeElement");let d=kc(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},JE=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=gi*(o-1)+o*e.height,m=e.y+e.height/2-u/2,p=Kn+e.width;n==="left"&&(p*=-1),a=e.x+p;let h=(gi+e.height)*s;l=m+h}else{let u=Kn*(o-1)+o*e.width,m=e.x+e.width/2-u/2,p=gi+e.height;n==="up"&&(p*=-1),l=e.y+p;let h=(Kn+e.width)*s;a=m+h}let d=Zn({type:e.type,x:a,y:l,width:e.width,height:e.height,roundness:e.roundness,roughness:e.roughness,backgroundColor:e.backgroundColor,strokeColor:e.strokeColor,strokeWidth:e.strokeWidth,opacity:e.opacity,fillStyle:e.fillStyle,strokeStyle:e.strokeStyle});ar(Lr(d),"not an ExcalidrawFlowchartNodeElement");let c=kc(e,d,n,t,i);r.push(d),r.push(c)}return r},kc=(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=rr({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:[Lc(0,0),Lc(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),G.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=li(c,qE(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p,isDeleted:c.isDeleted}},Cc=class{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!fe(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...qs(t,n,i),...Ks(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=>[...qs(t,n,a),...Ks(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}},Gc=class{isCreatingChart=!1;numberOfNodes=0;direction="right";pendingNodes=null;createNodes(t,n,i,o){let r=o.getNonDeletedElementsMap();if(i!==this.direction){let{nextNode:s,bindingArrow:a}=QE(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=JE(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);ar(s&&xo(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>Pn([a],s,r)||wn(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>De(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},_S=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{pointDistance as xi,pointFrom as Js}from"@excalidraw/math";import{invariant as $c}from"@excalidraw/common";P();import{arrayToMap as Nc,findIndex as Rc,findLastIndex as zc}from"@excalidraw/common";import{isFiniteNumber as eg}from"@excalidraw/math";var Qs=(e,t)=>e.frameId===t||e.id===t,Hc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Nc(n||Bt(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},tg=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),[])},Fc=(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))}}},ng=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{Qs(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},_c=(e,t,n,i,o,r)=>{let s=r||Yt(e,In(n),i);if(!s)return n;let a=q(s,i),l=K(s)?Ce(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},ig=(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"?zc(t,m=>a(m),Math.max(0,n-1)):Rc(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Fc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||Z(d))){let m=ng(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Fc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Re(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},Wc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Uc=(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},Yc=(e,t,n,i)=>{let o=e,r=Hc(e,t),s=Wc(e,r),a=tg(r);n==="right"&&(a=a.reverse());let l=new Set(r.filter(d=>Z(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=ig(t,e,p,n,h,i);if(f===-1||p===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,u),g=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"?[...E,...g,...x,...b]:[...E,...x,...g,...b]}),Uc(o,e)?($n(e,s),e):o},jc=(e,t,n,i,o)=>{let r=Hc(e,t,o);if(r.length===0)return e;let s=Wc(e,r),a=[],l,d;if(n==="left"){if(i)l=Rc(e,f=>Qs(f,i));else if(t.editingGroupId){let f=Re(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=zc(e,f=>Qs(f,i));else if(t.editingGroupId){let f=Re(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=>eg(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 Uc(e,h)?($n(h,s),h):e};function Xc(e,t,n,i){let o=Nc(Bt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)o.has(d.id)&&Z(d)&&s.add(d.id);for(let d of e)if(o.has(d.id))if(Z(d)||d.frameId&&s.has(d.frameId))r.regularElements.push(d);else if(!d.frameId)r.regularElements.push(d);else{let c=r.frameChildren.get(d.frameId)||[];c.push(d),r.frameChildren.set(d.frameId,c)}let a=e,l=Array.from(r.frameChildren.entries());for(let[d,c]of l)a=i(a,t,n,d,c);return i(a,t,n,null,r.regularElements)}var JS=(e,t,n)=>Yc(e,t,"left",n),eA=(e,t,n)=>Yc(e,t,"right",n),tA=(e,t)=>Xc(e,t,"left",jc),nA=(e,t)=>Xc(e,t,"right",jc);var lr=(e,t,n,i,o,r,s=!1)=>{if(U(t)||!Dt(o)||t.points.length!==2)return!1;if(!s){let l=t.startBinding?.elementId===n.id?0:t.points.length-1,d=G.getPointAtIndexGlobalCoordinates(t,l,i);if(xi(e,d)<Ui*1.5/o.zoom.value)return!1}let a=G.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return xi(e,a)>=Ui*1.5/o.zoom.value&&Pt({element:n,elementsMap:i,point:e,threshold:Me(n,t),overrideShouldTestInside:!0})},og=(e,t,n,i,o,r,s)=>{let a=new Map,l=n?"startBinding":"endBinding",d=n?"endBinding":"startBinding",c=e[l],u=e[d];if(c&&t){let m=t&&u&&c.elementId===u.elementId;s||m?c={...c,mode:"inside"}:c={...c,mode:"orbit"};let p=n?0:e.points.length-1,h=ht(e,l,c,t,i,!0);h&&a.set(p,{point:h})}if(u&&u.mode==="orbit"){let m=i.get(u.elementId);if(m&&fe(m)&&Dt(r)){let p=t&&u.elementId===t.id;s||p?u={...u,mode:"inside"}:u={...u,mode:"orbit"};let h=n?e.points.length-1:0,f=ht(e,d,u,m,i);f&&a.set(h,{point:f})}}a.size>0&&G.movePoints(e,o,a,{[l]:c,[d]:u})},Vc=(e,t,n,i,o,r,s)=>{let a=G.getElement(e.elementId,t);if(!a||!Le(a)||U(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,m=Js(n.x-c,n.y-u),p=l?"startBinding":"endBinding",h=Bl(m,a,i.getNonDeletedElements(),t,ut(o.zoom));if(h&&Dt(o)){a[p]&&h.id!==d?.elementId&&Oe(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",...di(a,h,e.draggedFocusPointBinding,t,m)}})}else{let f=new Map,E=l?0:a.points.length-1;f.set(E,{point:G.createPointAt(a,t,m[0],m[1],r)}),G.movePoints(a,i,f),a[p]&&Oe(a,l?"start":"end",i)}og(a,h,l,t,i,o,s),h&&Dt(o)&&_c(m,a,i.getElementsIncludingDeleted(),t,i,h)},mA=(e,t,n,i)=>{let o=Js(t.origin.x,t.origin.y),r=Ui*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&fe(s)&&!s.isDeleted){let a=We(e.startBinding.fixedPoint,s,n);if(lr(a,e,s,n,i,"start")&&xi(o,a)<=r)return{hitFocusPoint:"start",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}if(e.endBinding?.elementId){let s=n.get(e.endBinding.elementId);if(s&&fe(s)&&!s.isDeleted){let a=We(e.endBinding.fixedPoint,s,n);if(lr(a,e,s,n,i,"end")&&xi(o,a)<=r)return{hitFocusPoint:"end",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}return{hitFocusPoint:null,pointerOffset:{x:0,y:0}}},pA=(e,t)=>{$c(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=G.getElement(e.elementId,t.getNonDeletedElementsMap());$c(n,"Arrow must be in the scene");let i=e.draggedFocusPointBinding==="start"?"startBinding":"endBinding",o=e.draggedFocusPointBinding==="start"?"endBinding":"startBinding",r=n[i]?.elementId,s=n[o]?.elementId,a=r&&t.getNonDeletedElements().find(d=>d.id!==r&&d.id!==s&&fe(d)&&d.boundElements?.find(({id:c})=>c===n.id));a&&t.mutateElement(a,{boundElements:a.boundElements?.filter(({id:d})=>d!==n.id)});let l=r&&t.getNonDeletedElementsMap().get(r);l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]})},fA=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=Js(t,n),a=Ui*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&fe(l)&&!l.isDeleted){let d=We(e.startBinding.fixedPoint,l,r);if(lr(d,e,l,r,o,"start")&&xi(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&fe(l)&&!l.isDeleted){let d=We(e.endBinding.fixedPoint,l,r);if(lr(d,e,l,r,o,"end")&&xi(s,d)<=a)return"end"}}return null};P();import{MIME_TYPES as Zc,SVG_NS as rg}from"@excalidraw/common";var sg=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),bA=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===Zc.binary)throw new Error("Only images can be added to ImageCache");let l=sg(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}},wA=e=>e.filter(t=>zn(t)),ag=e=>e?.nodeName.toLowerCase()==="svg",yA=e=>{let t=new DOMParser().parseFromString(e,Zc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!ag(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",rg);let o=n.getAttribute("width"),r=n.getAttribute("height");(o?.includes("%")||o==="auto")&&(o=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!o||!r){if(o=o||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,o,r]=a)}n.setAttribute("width",o),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${o} ${r}`),n.outerHTML}};P();var MA=(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,E=p.map(g=>{let[x,b,y,w]=ze(g);return{elements:g,bounds:[x,b,y,w],width:y-x,height:w-b}});return E.forEach((g,x)=>{h+=g.width,x<E.length-1&&(h+=i),g.height>f&&(f=g.height)}),d+=f,{unitBounds:E,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:E}=p,g=t-f/2;h.forEach(x=>{let[b,y]=x.bounds,w=g-b,S=m-y;x.elements.forEach(I=>{o.push(Fe(I,{x:I.x+w,y:I.y+S}))}),g+=x.width+i}),m+=E+i}),o};P();import{pointCenter as lg,normalizeRadians as cr,pointFrom as se,pointRotateRads as bt}from"@excalidraw/math";import{MIN_FONT_SIZE as ta,SHIFT_LOCKING_ANGLE as ur,rescalePoints as qc,getFontString as dr}from"@excalidraw/common";var zA=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[m]=n;if(t==="rotation")U(m)||(dg(m,i,a,l,o),ke(m,i));else if(t){let p=n[0].id,h=u.get(p),f=e.get(p);if(h&&f){let{nextWidth:E,nextHeight:g}=fg(h,f,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});pg(E,g,h,f,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return K(m)&&ke(m,i),!0}else if(n.length>1){if(t==="rotation")return ug(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:h,flipByY:f,originalBoundingBox:E}=hg(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return Eg(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:h,flipByY:f,nextWidth:m,nextHeight:p,originalBoundingBox:E}),!0}}return!1},dg=(e,t,n,i,o)=>{let[r,s,a,l]=$(e,t.getNonDeletedElementsMap()),d=(r+a)/2,c=(s+l)/2,u;Z(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-c,n-d),o&&(u=u+ur/2,u=u-u%ur),u=cr(u));let m=Ut(e),p={angle:u};if(Le(e)&&(p={...p},e.startBinding&&Oe(e,"start",t),e.endBinding&&Oe(e,"end",t)),t.mutateElement(e,p),m){let h=t.getElement(m);if(h&&!W(e)){let{x:f,y:E}=ki(e,h,t.getNonDeletedElementsMap());t.mutateElement(h,{angle:u,x:f,y:E})}}},Kc=(e,t,n,i)=>Q(e)||Ie(e)?{points:qc(0,t,qc(1,n,e.points,i),i)}:{},na=(e,t,n)=>{let i=e.width;if(he(e)){let s=Ce(e,t);s&&(i=mt(s,e))}let r=e.fontSize*(n/i);return r<ta?null:{size:r}},cg=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=na(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=se(e.x,e.y),u=ea(c,e.width,e.height,l,s,e.angle,i,!1,o);n.mutateElement(t,{fontSize:d.size,width:l,height:s,x:u.x,y:u.y});return}if(i==="e"||i==="w"){let c=Po(dr({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=Wt(t.originalText,dr(t),Math.abs(u)),p=Qe(m,dr(t),t.lineHeight),h=p.height,f=se(e.x,e.y),E=ea(f,e.width,e.height,u,h,t.angle,i,!1,o),g={width:Math.abs(u),height:Math.abs(p.height),x:E.x,y:E.y,text:m,autoResize:!1};n.mutateElement(t,g)}}},ug=(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(!Z(u)){let[m,p,h,f]=$(u,l),E=(m+h)/2,g=(p+f)/2,x=e.get(u.id)?.angle??u.angle,[b,y]=bt(se(E,g),se(s,a),d+x-u.angle),w=U(u)?{points:td(u,l)}:{x:u.x+(b-E),y:u.y+(y-g),angle:cr(d+x)};n.mutateElement(u,w),ke(u,n,{simultaneouslyUpdated:t}),Le(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||Oe(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||Oe(u,"end",n)));let S=q(u,l);if(S&&!W(u)){let{x:I,y:M}=ki(u,S,l);n.mutateElement(S,{x:I,y:M,angle:cr(d+x)})}}n.triggerUpdate()},HA=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?$(t[0],n):ze(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=bt(se(i,o),se(d,c),-u),e){case"n":return bt(se(i-(r+a)/2,o-s),se(0,0),u);case"s":return bt(se(i-(r+a)/2,o-l),se(0,0),u);case"w":return bt(se(i-r,o-(s+l)/2),se(0,0),u);case"e":return bt(se(i-a,o-(s+l)/2),se(0,0),u);case"nw":return bt(se(i-r,o-s),se(0,0),u);case"ne":return bt(se(i-a,o-s),se(0,0),u);case"sw":return bt(se(i-r,o-l),se(0,0),u);case"se":return bt(se(i-a,o-l),se(0,0),u);default:return[0,0]}},_A=(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"},mg=(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"},ea=(e,t,n,i,o,r,s,a,l)=>{let d=mg(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)}}},pg=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(K(n)&&K(i))return cg(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=q(n,u);if(m){let E=o.get(m.id);if(E&&(c={fontSize:E.fontSize}),l){let g={...n,width:e,height:t},x=na(m,u,mt(g,m));if(x===null)return;c={fontSize:x.size}}else{let g=ul(dr(m),m.lineHeight),x=ml(m.fontSize,m.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let p=Kc(i,e,t,!0),h=se(i.x,i.y);if(Q(i)){let[E,g]=ae(i,o);h=se(E,g)}let f=ea(h,i.width,i.height,e,t,i.angle,s,l,d);if(Q(i)&&p.points){let E=i.x-h[0],g=i.y-h[1];f.x+=E,f.y+=g;let x=p.points[0][0],b=p.points[0][1];f.x+=x,f.y+=b,p.points=p.points.map(y=>se(y[0]-x,y[1]-b))}if(e<0&&(f.x=f.x+e),t<0&&(f.y=f.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),W(n)&&m&&l){let E=e/n.width*m.fontSize;if(E<ta)return;c.fontSize=E}if(e!==0&&t!==0&&Number.isFinite(f.x)&&Number.isFinite(f.y)){let E={...f,width:Math.abs(e),height:Math.abs(t),...p};Le(n)&&(n.startBinding&&(E={...E},n.startBinding&&Oe(n,"start",r)),n.endBinding&&(E={...E,endBinding:null})),r.mutateElement(n,E,{informMutation:a,isDragging:!1}),m&&c!=null&&r.mutateElement(m,{fontSize:c.fontSize}),Un(n,r,s,l),ke(n,r)}},fg=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=an(t,t.width,t.height,!0),u=se(a,l),m=se(d,c),p=lg(u,m),h=bt(se(i,o),p,-t.angle),[f,E,g,x]=an(e,e.width,e.height,!0),b=g-f,y=x-E,w=m[0]-u[0],S=m[1]-u[1],I=w/b,M=S/y;n.includes("e")&&(I=(h[0]-u[0])/b),n.includes("s")&&(M=(h[1]-u[1])/y),n.includes("w")&&(I=(m[0]-h[0])/b),n.includes("n")&&(M=(m[1]-h[1])/y);let A=e.width*I,L=e.height*M;if(s&&(A=2*A-t.width,L=2*L-t.height),r){let C=Math.abs(A)/t.width,O=Math.abs(L)/t.height;if(n.length===1&&(L*=C,A*=O),n.length===2){let D=Math.max(C,O);A=t.width*D*Math.sign(A),L=t.height*D*Math.sign(L)}}return{nextWidth:A,nextHeight:L}},hg=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(D=>t.get(D.id)),d=l.reduce((D,Y)=>{if(!Q(Y))return D;let H=Ut(Y);if(!H)return D;let V=t.get(H)??null;return he(V)?[...D,{...V,...G.getBoundTextElementPosition(Y,V,n)}]:D},[]),c=Kt(l.map(D=>D).concat(d)),{minX:u,minY:m,maxX:p,maxY:h,midX:f,midY:E}=c,g=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+g/2,h],s:[u+g/2,m]},[y,w]=a?[f,E]:b[i],S=a?2:1,I=Math.max(Math.abs(o-y)/g||0,Math.abs(r-w)/x||0)*S,M=i.includes("e")||i.includes("w")?Math.abs(o-y)*S:g,A=i.includes("n")||i.includes("s")?Math.abs(r-w)*S:x;s&&(M=g*I*Math.sign(o-y),A=x*I*Math.sign(r-w));let L={ne:[o<y,r>w],se:[o<y,r<w],sw:[o>y,r<w],nw:[o>y,r>w],e:[o<y,!1],w:[o>y,!1],n:[!1,r>w],s:[!1,r<w]},[C,O]=L[i].map(D=>D);return{originalBoundingBox:c,nextWidth:M,nextHeight:A,flipByX:C,flipByY:O}},Eg=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:d,nextWidth:c,originalBoundingBox:u}={})=>{if(c===void 0&&d===void 0&&a===void 0&&l===void 0||d===0||c===0)return;o||(o=t);let m=e.reduce((S,I)=>{let M=o.get(I.id);return M&&S.push({orig:M,latest:I}),S},[]),p;if(u)p=u;else{let S=m.reduce((I,{orig:M})=>{if(!Q(M))return I;let A=Ut(M);if(!A)return I;let L=o.get(A)??null;return he(L)?[...I,{...L,...G.getBoundTextElementPosition(M,L,t)}]:I},[]);p=Kt([...m.map(({orig:I})=>I),...S])}let{minX:h,minY:f,maxX:E,maxY:g,midX:x,midY:b}=p,y=E-h,w=g-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,M;n.length===1?M=n.includes("e")||n.includes("w")?S:I:M=Math.max(Math.abs(c)/y||0,Math.abs(d)/w||0);let A={ne:[h,g],se:[h,f],sw:[E,f],nw:[E,g],e:[h,f+w/2],w:[E,f+w/2],n:[h+y/2,g],s:[h+y/2,f]},[L,C]=s?[x,b]:A[n],O=r||m.some(T=>T.latest.angle!==0||K(T.latest)||gd(T.latest));O&&(S=M,I=M);let[D,Y]=[a?-1:1,l?-1:1],H=[];for(let{orig:T,latest:N}of m){if(K(T)&&he(T))continue;let _=T.width*S,ye=T.height*I,nt=cr(T.angle*D*Y),Qn=Q(T)||Ie(T),Jn=T.x-L,Gn=T.y-C,Lt=a&&!Qn?_:0,On=l&&!Qn?ye:0,tn=L+D*(Jn*S+Lt),ei=C+Y*(Gn*I+On),de=Kc(T,_*D,ye*Y,!1),oe={x:tn,y:ei,width:_,height:ye,angle:nt,...de};if(U(T)&&(T.startBinding&&(oe.startBinding={...T.startBinding,fixedPoint:[a?-T.startBinding.fixedPoint[0]+1:T.startBinding.fixedPoint[0],l?-T.startBinding.fixedPoint[1]+1:T.startBinding.fixedPoint[1]]}),T.endBinding&&(oe.endBinding={...T.endBinding,fixedPoint:[a?-T.endBinding.fixedPoint[0]+1:T.endBinding.fixedPoint[0],l?-T.endBinding.fixedPoint[1]+1:T.endBinding.fixedPoint[1]]}),T.fixedSegments&&de.points&&(oe.fixedSegments=T.fixedSegments.map(Ct=>({...Ct,start:de.points[Ct.index-1],end:de.points[Ct.index]})))),Ae(T)&&(oe.scale=[T.scale[0]*D,T.scale[1]*Y]),K(T)){let Ct=na(T,t,_);if(!Ct)return;oe.fontSize=Ct.size}let nn=o.get(Ut(T)??"");if(nn)if(O){let Ct=nn.fontSize*M;if(Ct<ta)return;oe.boundTextFontSize=Ct}else oe.boundTextFontSize=nn.fontSize;H.push({element:N,update:oe})}let V=H.map(({element:T})=>T),F=new Map(H.map(({element:T})=>[T.id,T]));for(let{element:T,update:{boundTextFontSize:N,..._}}of H){let{angle:ye}=_;i.mutateElement(T,_),ke(T,i,{simultaneouslyUpdated:V}),Le(T)&&(T.startBinding&&(F.has(T.startBinding.elementId)||Oe(T,"start",i)),T.endBinding&&(F.has(T.endBinding.elementId)||Oe(T,"end",i)));let nt=q(T,t);nt&&N&&(i.mutateElement(nt,{fontSize:N,angle:Q(T)?void 0:ye}),Un(T,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as at,pointOnLineSegment as iu,pointRotateRads as pr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as la}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as oa}from"@excalidraw/common";import{pointFrom as Qc,pointRotateRads as gg}from"@excalidraw/math";var Jc={mouse:8,pen:16,touch:28},xg=16,tu={e:!0,s:!0,n:!0,w:!0},VA={e:!0,s:!0,n:!0,w:!0},ZA={e:!0,s:!0,n:!0,w:!0,rotation:!0},eu={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},ia={e:!0,s:!0,n:!0,w:!0},en=(e,t,n,i,o,r,s)=>{let[a,l]=gg(Qc(e+n/2,t+i/2),Qc(o,r),s);return[a-n/2,l-i/2,n,i]},mr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),ra=e=>mr(e)?tu:{},sa=([e,t,n,i,o,r],s,a,l,d={},c=4,u=oa)=>{let m=Jc[l],p=m/a.value,h=m/a.value,f=m/a.value,E=m/a.value,g=n-e,x=i-t,b=c/a.value,y=(m-u*2)/(2*a.value),w={nw:d.nw?void 0:en(e-b-f+y,t-b-E+y,p,h,o,r,s),ne:d.ne?void 0:en(n+b-y,t-b-E+y,p,h,o,r,s),sw:d.sw?void 0:en(e-b-f+y,i+b-y,p,h,o,r,s),se:d.se?void 0:en(n+b-y,i+b-y,p,h,o,r,s),rotation:d.rotation?void 0:en(e+g/2-p/2,t-b-E+y-xg/a.value,p,h,o,r,s)},S=5*Jc.mouse/a.value;return Math.abs(g)>S&&(d.n||(w.n=en(e+g/2-p/2,t-b-E+y,p,h,o,r,s)),d.s||(w.s=en(e+g/2-p/2,i+b-y,p,h,o,r,s))),Math.abs(x)>S&&(d.w||(w.w=en(e-b-f+y,t+x/2-h/2,p,h,o,r,s)),d.e||(w.e=en(n+b-y,t+x/2-h/2,p,h,o,r,s))),w},nu=(e,t,n,i="mouse",o=tu)=>{if(e.locked||U(e))return{};if(e.type==="freedraw"||Q(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=ia:s[0]>0&&s[1]<0?o=eu:s[0]>0&&s[1]>0?o=ia:s[0]<0&&s[1]>0?o=eu:s[0]<0&&s[1]<0&&(o=ia)}}else Z(e)&&(o={...o,rotation:!0});let r=Q(e)?oa+8:Ae(e)?0:oa;return sa($(e,n,!0),e.angle,t,i,o,r,Ae(e)?0:void 0)},qA=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return U(i)?!1:Q(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var da=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],bg=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=nu(e,r,t,s,ra(a));if(l&&da(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?da(m,i,o):!1});if(c.length>0)return c[0];if(mr(a)){let[u,m,p,h,f,E]=$(e,t);if(!(Q(e)&&e.points.length<=2)){let g=Ae(e)?0:la/r.value,x=la/r.value,b=ou(at(u-g,m-g),at(p+g,h+g),at(f,E),e.angle);for(let[y,w]of Object.entries(b))if(iu(at(i,o),w,x))return y}}return!1},oM=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=bg(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),rM=([e,t,n,i],o,r,s,a,l)=>{let d=sa([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,ra(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&da(m,o,r)});if(c)return c;if(mr(l)){let u=(e+n)/2,m=(t+i)/2,p=la/s.value,h=ou(at(e-p,t-p),at(n+p,i+p),at(u,m),0);for(let[f,E]of Object.entries(h))if(iu(at(o,r),E,p))return f}return!1},aa=["ns","nesw","ew","nwse"],wg=(e,t)=>{let n=aa.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=aa[(n+i)%aa.length]}return e},sM=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=wg(o,t.angle)),o?`${o}-resize`:""},ou=([e,t],[n,i],o,r)=>{let s=pr(at(e,t),o,r),a=pr(at(n,t),o,r),l=pr(at(e,i),o,r),d=pr(at(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var cM=(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")||Bt(t,e).length));P();import{pointFrom as fr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as yg,DEFAULT_FONT_SIZE as Pg,TEXT_ALIGN as Ig,VERTICAL_ALIGN as Sg,getSizeFromPoints as Ag,randomId as Mg,arrayToMap as Tg,assertNever as ca,cloneJSON as su,getFontString as Dg,isDevEnv as vg,toBrandedType as Bg,getLineHeight as Lg}from"@excalidraw/common";var hr={width:100,height:0},Cn=100,Cg=(e,t,n)=>{let i=qn({x:0,y:0,textAlign:Ig.CENTER,verticalAlign:Sg.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),Mo(i,e,n),[e,i]},ru=(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??Cn,u=t?.height??Cn,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 E="";m&&m.type==="text"?E=m.text:t.type==="text"&&(E=t.text),E||console.error(`No text found for start binding text element for ${e.id}`),r=qn({x:p,y:h,type:"text",...m,...t,text:E}),Object.assign(r,{x:t.x||e.x-r.width,y:t.y||e.y-r.height/2})}else switch(f){case"rectangle":case"ellipse":case"diamond":{r=Zn({x:p,y:h,width:c,height:u,...m,...t,type:f});break}default:ca(e,`Unhandled element start type "${t.type}"`,!0)}vt(e,r,"orbit","start",o)}}if(n){let c=n?.height??Cn,u=n?.width??Cn,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 E="";m&&m.type==="text"?E=m.text:n.type==="text"&&(E=n.text),E||console.error(`No text found for end binding text element for ${e.id}`),s=qn({x:p,y:h,type:"text",...m,...n,text:E}),Object.assign(s,{y:n.y||e.y-s.height/2})}else switch(f){case"rectangle":case"ellipse":case"diamond":{s=Zn({x:p,y:h,width:u,height:c,...m,...n,type:f});break}default:ca(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=su(e.points);return e.points[a][0]>e.points[a-1][0]&&(d[0][0]=l,d[a][0]-=l),e.points[a][0]<e.points[a-1][0]&&(d[0][0]=-l,d[a][0]+=l),e.points[a][1]>e.points[a-1][1]&&(d[0][1]=l,d[a][1]-=l),e.points[a][1]<e.points[a-1][1]&&(d[0][1]=-l,d[a][1]+=l),Object.assign(e,G.getNormalizeElementPointsAndCoords({...e,points:d})),{linearElement:e,startBoundElement:r,endBoundElement:s}},ua=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>ys(Array.from(this.excalidrawElements.values()));getElementsMap=()=>Bg(Tg(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},SM=(e,t)=>{if(!e)return[];let n=su(e),i=new ua,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:Mg()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||Cn,p=l?.label?.text&&l.height===void 0?0:l?.height||Cn;d=Zn({...l,width:m,height:p});break}case"line":{let m=l.width||hr.width,p=l.height||hr.height;d=Ic({width:m,height:p,points:[fr(0,0),fr(m,p)],...l});break}case"arrow":{let m=l.width||hr.width,p=l.height||hr.height;d=rr({width:m,height:p,endArrowhead:"arrow",points:[fr(0,0),fr(m,p)],...l,type:"arrow"}),Object.assign(d,Ag(d.points));break}case"text":{let m=l?.fontFamily||yg,p=l?.fontSize||Pg,h=l?.lineHeight||Lg(m),f=l.text??"",E=Oi(f),g=Qe(E,Dg({fontFamily:m,fontSize:p}),h);d=qn({width:g.width,height:g.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=Sc({width:l?.width||Cn,height:l?.height||Cn,...l});break}case"frame":{d=wc({x:0,y:0,...l});break}case"magicframe":{d=yc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,ca(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 Ei(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]=Cg(c,d?.label,a);if(i.add(u),i.add(m),W(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:E,endBoundElement:g}=ru(u,p,h,i,a);u=f,i.add(f),i.add(E),i.add(g)}}else switch(d.type){case"arrow":{let{start:u,end:m}=d;if(u&&u.id){let E=r.get(u.id);Object.assign(u,{id:E})}if(m&&m.id){let E=r.get(m.id);Object.assign(m,{id:E})}let{linearElement:p,startBoundElement:h,endBoundElement:f}=ru(c,u,m,i,a);i.add(p),i.add(h),i.add(f);break}}break}}}for(let[l,d]of o){if(d.type!=="frame"&&d.type!=="magicframe")continue;let c=i.getElement(l);if(!c)throw new Error(`Excalidraw element with id ${l} doesn't exist`);let u=[];d.children.forEach(w=>{let S=r.get(w);if(!S)throw new Error(`Element with ${w} wasn't mapped correctly`);let I=i.getElement(S);if(!I)throw new Error(`Frame element with id ${S} doesn't exist`);Object.assign(I,{frameId:c.id}),I?.boundElements?.forEach(M=>{let A=i.getElement(M.id);if(!A)throw new Error(`Bound element with id ${M.id} doesn't exist`);Object.assign(A,{frameId:c.id}),u.push(A)}),u.push(I)});let[m,p,h,f]=ze(u),E=10;m=m-E,p=p-E,h=h+E,f=f+E;let g=c?.x||m,x=c?.y||p,b=c?.width||h-m,y=c?.height||f-p;Object.assign(c,{x:g,y:x,width:b,height:y}),vg()&&d.children.length&&(c?.x||c?.y||c?.width||c?.height)&&console.info("User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically")}return i.getElements()};P();var vM=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return Vc(n.selectedLinearElement,e.scene.getNonDeletedElementsMap(),e.lastPointerMoveCoords,e.scene,n,e.getEffectiveGridSize(),t.altKey),!0;if(n.selectedLinearElement.hoverPointIndex!==null&&e.lastPointerMoveEvent&&n.selectedLinearElement.initialState.lastClickedPoint>=0&&n.selectedLinearElement.isDragging)return G.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};P();var Gg=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}},CM=e=>{let t=Gg(e);return t===null?null:t};var NM=e=>e.reduce((t,n)=>t+n.version,0),oc=e=>{let t=5381;for(let n of Og(e))t=(t<<5)+t+n.versionNonce;return t>>>0},rc=e=>{let t=5381;for(let n=0;n<e.length;n++){let i=e.charCodeAt(n);t=(t<<5)+t+i}return t>>>0},pt=e=>!e.isDeleted,RM=e=>e.filter(t=>pt(t)&&!Kd(t)),In=e=>e.filter(pt);export{Mn as AppStateDelta,Rp as BASE_ARROW_MIN_LENGTH,ql as BASE_BINDING_GAP,Yn as BASE_BINDING_GAP_ELBOW,ne as BASE_PADDING,xn as BindableElement,gn as BoundElement,Ze as CaptureUpdateAction,RP as DEFAULT_LINK_SIZE,tu as DEFAULT_OMIT_SIDES,j as Delta,_s as DurableIncrement,ks as ElementBounds,Tn as ElementsDelta,Ws as EphemeralIncrement,Ui as FOCUS_POINT_SIZE,Gc as FlowChartCreator,Cc as FlowChartNavigator,Te as HEADING_DOWN,je as HEADING_LEFT,xe as HEADING_RIGHT,et as HEADING_UP,Sh as INVISIBLY_SMALL_ELEMENT_SIZE,bs as InvalidFractionalIndexError,G as LinearElementEditor,Be as MINIMAL_CROP_SIZE,ZA as OMIT_SIDES_FOR_FRAME,VA as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Ei as Scene,tt as ShapeCache,tc as Store,qi as StoreChange,Us as StoreDelta,tr as StoreIncrement,Dn as StoreSnapshot,st as aabbForElement,vf as addElementsToFrame,JE as addNewNodes,M0 as addToGroup,R1 as alignElements,jp as avoidRectangularCorner,vt as bindBindingElement,Md as bindElementsToFramesAfterDuplication,zp as bindOrUnbindBindingElement,t0 as bindOrUnbindBindingElements,ds as bindPointToSnapToElementOutline,ed as bindingProperties,Ms as boundsContainBounds,Ul as bumpVersion,$p as calculateFixedPointForElbowArrowBinding,di as calculateFixedPointForNonElbowArrowBinding,Vb as canApplyRoundnessTypeToElement,el as canBecomePolygon,gl as canChangeRoundness,SE as canCreateLinkFromElements,ty as canHaveArrowheads,mr as canResizeFromSides,si as charWidth,ge as compareHeading,ki as computeBoundTextPosition,Ur as computeContainerDimensionForBoundText,Sw as containsCJK,SM as convertToExcalidrawElements,SS as createPlaceholderEmbeddableLabel,$s as createSrcDoc,Hb as cropElement,dn as deconstructDiamondElement,bo as deconstructLinearOrFreeDrawElement,ln as deconstructRectanguloidElement,Hs as deepCopyElement,eS as defaultGetElementLinkFromSelection,gw as detectLineHeight,un as distanceToElement,NI as distributeElements,jt as doBoundsIntersect,ZI as dragNewElement,$I as dragSelectedElements,Oh as duplicateElement,J1 as duplicateElements,A0 as editGroupForSelectedElement,re as elementCenterPoint,wn as elementOverlapsWithFrame,Xi as elementWithCanvasCache,Pn as elementsAreInFrameBounds,Ed as elementsAreInSameGroup,wd as elementsOverlappingBBox,MS as embeddableURLValidator,gf as excludeElementsInFramesFromSelection,gP as filterElementsEligibleAsFrameChildren,i0 as fixBindingsAfterDeletion,Jl as fixDuplicatedBindingsAfterDuplication,Jr as flipHeading,IP as frameAndChildrenSelectedTogether,al as generateLinearCollisionShape,Ve as generateRoughOptions,U0 as getActiveTextElement,Do as getAllHoveredElementAtPoint,ml as getApproxMinLineHeight,ul as getApproxMinLineWidth,td as getArrowLocalFixedPoints,gh as getArrowheadAngle,CM as getArrowheadForPicker,He as getArrowheadPoints,Eh as getArrowheadSize,Me as getBindingGap,o0 as getBindingSideMidPoint,ps as getBindingStrategyForDraggingBindingElementEndpoints,q as getBoundTextElement,Ut as getBoundTextElementId,Nw as getBoundTextElementPosition,Fi as getBoundTextMaxHeight,mt as getBoundTextMaxWidth,Fs as getBoundsFromPoints,mn as getCenterForBounds,Kt as getCommonBoundingBox,ze as getCommonBounds,Tf as getCommonFrameId,kw as getContainerCenter,Yr as getContainerCoords,Ce as getContainerElement,yn as getContainingFrame,zt as getCornerRadius,vo as getCubicBezierCurveBound,sM as getCursorForResizingElement,Of as getDefaultFrameName,Zb as getDefaultRoundnessTypeForElement,sl as getDiamondBaseCorners,ri as getDiamondPoints,VI as getDragOffsetXY,y1 as getDraggedElementsBounds,$ as getElementAbsoluteCoords,ae as getElementBounds,Ss as getElementLineSegments,Es as getElementPointsCoords,_d as getElementShape,oM as getElementWithTransformHandleType,Td as getElementsCompletelyInFrame,Re as getElementsInGroup,EP as getElementsInNewFrame,hP as getElementsInResizingFrame,dP as getElementsIntersectingFrame,PP as getElementsOverlappingFrame,bd as getElementsWithinSelection,IS as getEmbedLink,_b as getFlipAdjustedCropPosition,bn as getFrameChildren,Df as getFrameChildrenInsertionIndex,Af as getFrameLikeElements,yP as getFrameLikeTitle,_P as getFreedrawOutlineAsSegments,ah as getFreedrawOutlinePoints,We as getGlobalFixedPointForBindableElement,Vp as getGlobalFixedPoints,Wl as getHeadingForElbowArrowSnap,Yt as getHoveredElementForBinding,Bl as getHoveredElementForFocusPoint,wA as getInitializedImageElements,Io as getLineHeightInPx,cn as getLineWidth,qb as getLinearElementSubType,HS as getLinkDirectionFromKey,tS as getLinkIdAndTypeFromSelection,md as getLockedLinearCursorAlignSize,Am as getMaxCharWidth,D0 as getMaximumGroups,bw as getMinCharWidth,ji as getMinMaxXYFromCurvePathOps,Po as getMinTextElementWidth,xd as getNewGroupIdsForDuplication,In as getNonDeletedElements,hd as getNonDeletedGroupIds,L1 as getNormalizedDimensions,hi as getObservedAppState,ra as getOmitSidesForEditorInterface,mw as getOriginalContainerHeightFromCache,Ns as getPerfectElementSize,Ks as getPredecessors,w1 as getRectangleBoxAbsoluteCoords,jf as getRenderOpacity,_A as getResizeArrowDirection,HA as getResizeOffsetXY,an as getResizedElementAbsoluteCoords,fP as getRootElements,NM as getSceneVersion,Bt as getSelectedElements,jo as getSelectedElementsByGroup,xs as getSelectedGroupForElement,mf as getSelectedGroupIdForElement,cf as getSelectedGroupIds,W0 as getSelectionStateForElements,xm as getSnapOutlineMidPoint,_0 as getTargetElements,Lf as getTargetFrame,Fw as getTextElementAngle,_w as getTextFromElements,Sm as getTextHeight,pl as getTextWidth,rM as getTransformHandleTypeFromCoords,nu as getTransformHandles,sa as getTransformHandlesFromCoords,Xa as getUncroppedImageElement,Br as getUncroppedWidthAndHeight,z0 as getVisibleAndNonSelectedElements,RM as getVisibleElements,P1 as getVisibleSceneBounds,Om as getWrappedTextLines,pP as groupByFrameLikes,uP as groupsAreAtLeastIntersectingTheFrame,mP as groupsAreCompletelyOutOfFrame,Un as handleBindTextResize,Vc as handleFocusPointDrag,fA as handleFocusPointHover,mA as handleFocusPointPointerDown,pA as handleFocusPointPointerUp,Vr as hasBackground,yt as hasBoundTextElement,qA as hasBoundingBox,Jw as hasFreedrawMode,qw as hasStrokeColor,Qw as hasStrokeStyle,Kw as hasStrokeWidth,oc as hashElementsVersion,rc as hashString,Ye as headingForPoint,Ri as headingForPointFromElement,ft as headingForPointIsHorizontal,Xe as headingIsHorizontal,Py as headingIsVertical,ap as hitElementBoundText,sp as hitElementBoundingBox,Ey as hitElementBoundingBoxOnly,Pt as hitElementItself,At as intersectElementWithLineSegment,$b as isArrowBoundToElement,W as isArrowElement,fe as isBindableElement,Kr as isBindableElementInsideOtherBindable,Le as isBindingElement,am as isBindingElementType,Dt as isBindingEnabled,he as isBoundToContainer,cP as isCursorInFrame,rm as isCurvedArrow,U as isElbowArrow,B1 as isElementCompletelyInViewport,As as isElementContainingFrame,vd as isElementInFrame,uf as isElementInGroup,yd as isElementInViewport,ui as isElementIntersectingFrame,nS as isElementLink,Qb as isEligibleFrameChildType,Va as isEmbeddableElement,Ka as isExcalidrawElement,Zp as isFixedPoint,Lr as isFlowchartNodeElement,lr as isFocusPointVisible,xo as isFrameElement,Z as isFrameLikeElement,Ie as isFreeDrawElement,im as isFreeDrawElementType,ag as isHTMLSVGElement,Eo as isIframeElement,go as isIframeLikeElement,Ae as isImageElement,gd as isInGroup,zn as isInitializedImageElement,Kd as isInvisiblySmallElement,Nt as isLineElement,Q as isLinearElement,sm as isLinearElementType,Za as isMagicFrameElement,Ew as isMeasureTextSupported,_S as isNodeInFlowchart,pt as isNonDeletedElement,_n as isPathALoop,Ht as isPointInElement,Li as isRectangularElement,qa as isRectanguloidElement,df as isSelectedViaGroup,om as isSharpArrow,Xb as isSimpleArrow,H0 as isSomeElementSelected,lm as isTextBindableContainer,K as isTextElement,Qa as isUsingAdaptiveRadius,Ja as isUsingProportionalRadius,Kb as isValidPolygon,Hw as isValidTextContainer,sg as loadHTMLImageElement,gs as makeNextSelectedElementIds,ut as maxBindingDistance_simple,vM as maybeHandleArrowPointlikeDrag,AS as maybeParseEmbedSrc,na as measureFontSizeFromWidth,Qe as measureText,tA as moveAllLeft,nA as moveAllRight,_c as moveArrowAboveBindable,JS as moveOneLeft,eA as moveOneRight,De as mutateElement,rr as newArrowElement,Zn as newElement,Fe as newElementWith,pS as newEmbeddableElement,wc as newFrameElement,ES as newFreeDrawElement,fS as newIframeElement,Sc as newImageElement,Ic as newLinearElement,yc as newMagicFrameElement,qn as newTextElement,Gg as normalizeArrowhead,Qd as normalizeElementOrder,It as normalizeFixedPoint,yA as normalizeSVG,Oi as normalizeText,$o as omitGroupsContainingFrameLikes,Mf as omitPartialGroups,Id as orderByFractionalIndex,Gi as originalContainerCache,iS as parseElementLinkFromURL,Cm as parseTokens,Mt as pointInsideBounds,wh as pointInsideBoundsInclusive,MA as positionElementsOnGrid,Nr as projectFixedPointOntoDiagonal,Mo as redrawTextBoundingBox,hS as refreshTextDimensions,Bf as removeAllElementsFromFrame,Dd as removeElementsFromFrame,T0 as removeFromSelectedGroups,HP as renderElement,zP as renderSelectionElement,xP as replaceAllElementsInFrame,Kc as rescalePointsInElement,dl as resetOriginalContainerCache,Eg as resizeMultipleElements,pg as resizeSingleElement,cg as resizeSingleTextElement,bg as resizeTest,lf as selectGroup,pd as selectGroupsForSelectedElements,fd as selectGroupsFromGivenElements,xw as setCustomTextMetricsProvider,Rw as shouldAllowVerticalAlign,wP as shouldApplyFrameClip,To as shouldTestInside,cM as showSelectedShapeActions,fs as snapToMid,zw as suppportsHorizontalAlign,ys as syncInvalidIndices,Sd as syncInvalidIndicesImmutable,$n as syncMovedIndices,ud as toggleLinePolygonState,ey as toolIsArrow,zA as transformElements,Oe as unbindBindingElement,n0 as updateBindings,ke as updateBoundElements,ht as updateBoundPoint,li as updateElbowArrowPoints,bP as updateFrameMembershipOfSelectedElements,bA as updateImageCache,ll as updateOriginalContainerCache,_l as validateElbowPoints,yf as validateFractionalIndices,Xt as vectorToHeading,Wt as wrapText};
28
+ `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return St.set(e,p),p}return St.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},$A=e=>{let t;xo(e)?t="IFrame element":t=!e.link||e?.link===""?"Empty Web-Embed":e.link;let n=Math.max(Math.min(e.width/2,e.width/t.length),e.width/30),i=rg.Helvetica,o=ag({fontSize:n,fontFamily:i});return Qn({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:Xt(t,o,e.width-20),textAlign:"center",verticalAlign:sg.MIDDLE,angle:e.angle??0})},ia=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(na.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return na.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},ZA=e=>{let t=e.match(pg);if(t&&t.length===2)return t[1];let n=e.match(Eg);if(n&&n.length===2)return n[1];let i=e.match(ug);if(i&&i.length===2)return i[1];if(kc.test(e))return`https://giphy.com/embed/${kc.exec(e)[1]}`;let o=e.match(hg);return o&&o.length===2?o[1]:e},qA=(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(ia(e,n))return!0;return!1}}return!!ia(e,na)};P();import{invariant as oa,toBrandedType as xg}from"@excalidraw/common";import{clamp as bg,pointFrom as Hc}from"@excalidraw/math";var _c=100,Wc=100,wg=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},jc=(e,t,n)=>n.every(i=>e+t<=i.start||e>=i.end),yg=(e,t,n)=>{if(jc(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=bg(e,i[a],o[a]-t),d=Math.abs(l-e);d<=s&&(r=l,s=d)}return r},Pg=(e,t)=>{let n=[...t.values()].filter(W),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&&fe(u)&&(r.push(u),o.push(c))}}return r},Ig=(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?Wc:_c,d=r?_c:Wc,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=wg(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,g=(o===null?null:[o,o-h].filter(b=>jc(b,f,p)).sort((b,y)=>Math.abs(b+f/2-u)-Math.abs(y+f/2-u))[0]??null)??yg(u-f/2,f,p);return{positions:Array.from({length:n},(b,y)=>{let w=g+y*h;return r?{x:m,y:w}:{x:w,y:m}}),crossStart:g}},Sg=(e,t,n)=>{let i=gi({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 oa(rl(i),"not an ExcalidrawFlowchartNodeElement"),i},Ag=(e,t,n,i,o,r=null)=>{let s=i.getNonDeletedElementsMap(),a=Pg(e,s).map(u=>Ke(u,s)),{positions:l,crossStart:d}=Ig(e,n,o,a,r),c=[];for(let u of l){let m=Sg(e,u.x,u.y),p=Mg(e,m,n,t,i);c.push(m,p)}return{nodes:c,crossStart:d}},Mg=(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=or({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:[Hc(0,0),Hc(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();Nt(c,e,"orbit","start",o),Nt(c,t,"orbit","end",o);let m=new Map;m.set(e.id,e),m.set(t.id,t),m.set(c.id,c),C.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=ci(c,xg(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p,isDeleted:c.isDeleted}},Uc=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(!fe(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...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(W(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;oa(fe(d),"not an ExcalidrawBindableElement");let c=t==="predecessors"?a.points[a.points.length-1]:[0,0],u=li(n,Ke(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=>ae(s.heading,He)).map(s=>s.relative);case"down":return r.filter(s=>ae(s.heading,Ie)).map(s=>s.relative);case"right":return r.filter(s=>ae(s.heading,le)).map(s=>s.relative);case"left":return r.filter(s=>ae(s.heading,De)).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)}},Yc=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}=Ag(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);oa(l&&wo(l),"not an ExcalidrawFrameElement"),l&&this.pendingNodes.every(d=>In([d],l,r)||yn(d,l,r))&&(this.pendingNodes=this.pendingNodes.map(d=>ve(d,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0,this.clusterCrossStart=null}},cM=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{pointDistance as Pi,pointFrom as sa}from"@excalidraw/math";import{invariant as iu}from"@excalidraw/common";P();import{arrayToMap as Vc,findIndex as $c,findLastIndex as Zc}from"@excalidraw/common";import{isFiniteNumber as Tg}from"@excalidraw/math";var ra=(e,t)=>e.frameId===t||e.id===t,qc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Vc(n||Ot(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},Dg=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),[])},Xc=(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))}}},vg=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{ra(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},Kc=(e,t,n,i,o,r)=>{let s=r||Vt(e,Sn(n),i);if(!s)return n;let a=ne(s,i),l=Q(s)?Oe(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},Bg=(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"?Zc(t,m=>a(m),Math.max(0,n-1)):$c(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Xc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||q(d))){let m=vg(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Xc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Ue(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},Qc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Jc=(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},eu=(e,t,n,i)=>{let o=e,r=qc(e,t),s=Qc(e,r),a=Dg(r);n==="right"&&(a=a.reverse());let l=new Set(r.filter(d=>q(e[d])).map(d=>e[d].id));return a.forEach((d,c)=>{let u=d[0],m=d[d.length-1],p=n==="left"?u:m,h=d.some(y=>{let w=e[y];return w.frameId&&l.has(w.frameId)})?null:e[p]?.frameId,f=Bg(t,e,p,n,h,i);if(f===-1||p===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,u),g=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"?[...E,...g,...x,...b]:[...E,...x,...g,...b]}),Jc(o,e)?(Zn(e,s),e):o},tu=(e,t,n,i,o)=>{let r=qc(e,t,o);if(r.length===0)return e;let s=Qc(e,r),a=[],l,d;if(n==="left"){if(i)l=$c(e,f=>ra(f,i));else if(t.editingGroupId){let f=Ue(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=Zc(e,f=>ra(f,i));else if(t.editingGroupId){let f=Ue(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=>Tg(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 Jc(e,h)?(Zn(h,s),h):e};function nu(e,t,n,i){let o=Vc(Ot(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)o.has(d.id)&&q(d)&&s.add(d.id);for(let d of e)if(o.has(d.id))if(q(d)||d.frameId&&s.has(d.frameId))r.regularElements.push(d);else if(!d.frameId)r.regularElements.push(d);else{let c=r.frameChildren.get(d.frameId)||[];c.push(d),r.frameChildren.set(d.frameId,c)}let a=e,l=Array.from(r.frameChildren.entries());for(let[d,c]of l)a=i(a,t,n,d,c);return i(a,t,n,null,r.regularElements)}var PM=(e,t,n)=>eu(e,t,"left",n),IM=(e,t,n)=>eu(e,t,"right",n),SM=(e,t)=>nu(e,t,"left",tu),AM=(e,t)=>nu(e,t,"right",tu);var cr=(e,t,n,i,o,r,s=!1)=>{if(W(t)||!Gt(o)||t.points.length!==2)return!1;if(!s){let l=t.startBinding?.elementId===n.id?0:t.points.length-1,d=C.getPointAtIndexGlobalCoordinates(t,l,i);if(Pi(e,d)<Xi*1.5/o.zoom.value)return!1}let a=C.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return Pi(e,a)>=Xi*1.5/o.zoom.value&&Dt({element:n,elementsMap:i,point:e,threshold:Pe(n,t),overrideShouldTestInside:!0})},Lg=(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=yt(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&&fe(p)&&Gt(r)){t&&m.elementId===t.id?m={...m,mode:"inside"}:m={...m,mode:"orbit"};let f=n?e.points.length-1:0,E=yt(e,c,m,p,i);E&&a.set(f,{point:E})}}a.size>0&&C.movePoints(e,o,a,{[d]:u,[c]:m})},ou=(e,t,n,i,o,r,s)=>{let a=C.getElement(e.elementId,t);if(!a||!Ce(a)||W(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,m=sa(n.x-c,n.y-u),p=l?"startBinding":"endBinding",h=kl(m,a,i.getNonDeletedElements(),t,gt(o.zoom));if(h&&Gt(o)){a[p]&&h.id!==d?.elementId&&Fe(a,e.draggedFocusPointBinding,i);let f=s&&a[p]?.mode==="orbit"?"inside":!s&&a[p]?.mode==="inside"?"orbit":null;(!a[p]||f)&&Nt(a,h,f||"orbit",e.draggedFocusPointBinding,i,m),i.mutateElement(a,{[p]:{...a[p],elementId:h.id,mode:f||a[p]?.mode||"orbit",...pi(a,h,e.draggedFocusPointBinding,t,m)}})}else{let f=new Map,E=l?0:a.points.length-1;f.set(E,{point:C.createPointAt(a,t,m[0],m[1],r)}),C.movePoints(a,i,f),a[p]&&Fe(a,l?"start":"end",i)}Lg(a,h,l,t,i,o,s),h&&Gt(o)&&Kc(m,a,i.getElementsIncludingDeleted(),t,i,h)},OM=(e,t,n,i)=>{let o=sa(t.origin.x,t.origin.y),r=Xi*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&fe(s)&&!s.isDeleted){let a=Ge(e.startBinding.fixedPoint,s,n);if(cr(a,e,s,n,i,"start")&&Pi(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&&fe(s)&&!s.isDeleted){let a=Ge(e.endBinding.fixedPoint,s,n);if(cr(a,e,s,n,i,"end")&&Pi(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}},kM=(e,t)=>{iu(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=C.getElement(e.elementId,t.getNonDeletedElementsMap());iu(n,"Arrow must be in the scene");let i=e.draggedFocusPointBinding==="start"?"startBinding":"endBinding",o=e.draggedFocusPointBinding==="start"?"endBinding":"startBinding",r=n[i]?.elementId,s=n[o]?.elementId,a=r&&t.getNonDeletedElements().find(d=>d.id!==r&&d.id!==s&&fe(d)&&d.boundElements?.find(({id:c})=>c===n.id));a&&t.mutateElement(a,{boundElements:a.boundElements?.filter(({id:d})=>d!==n.id)});let l=r&&t.getNonDeletedElementsMap().get(r);return l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]}),{arrowOtherEndpointInitialBinding:null}},FM=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=sa(t,n),a=Xi*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&fe(l)&&!l.isDeleted){let d=Ge(e.startBinding.fixedPoint,l,r);if(cr(d,e,l,r,o,"start")&&Pi(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&fe(l)&&!l.isDeleted){let d=Ge(e.endBinding.fixedPoint,l,r);if(cr(d,e,l,r,o,"end")&&Pi(s,d)<=a)return"end"}}return null};P();import{MIME_TYPES as ru,SVG_NS as Cg}from"@excalidraw/common";var Gg=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),WM=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===ru.binary)throw new Error("Only images can be added to ImageCache");let l=Gg(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}},UM=e=>e.filter(t=>Hn(t)),Ng=e=>e?.nodeName.toLowerCase()==="svg",YM=e=>{let t=new DOMParser().parseFromString(e,ru.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Ng(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Cg);let o=n.getAttribute("width"),r=n.getAttribute("height");(o?.includes("%")||o==="auto")&&(o=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!o||!r){if(o=o||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,o,r]=a)}n.setAttribute("width",o),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${o} ${r}`),n.outerHTML}};P();var ZM=(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,E=p.map(g=>{let[x,b,y,w]=Ye(g);return{elements:g,bounds:[x,b,y,w],width:y-x,height:w-b}});return E.forEach((g,x)=>{h+=g.width,x<E.length-1&&(h+=i),g.height>f&&(f=g.height)}),d+=f,{unitBounds:E,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:E}=p,g=t-f/2;h.forEach(x=>{let[b,y]=x.bounds,w=g-b,S=m-y;x.elements.forEach(I=>{o.push(_e(I,{x:I.x+w,y:I.y+S}))}),g+=x.width+i}),m+=E+i}),o};P();import{pointCenter as Og,normalizeRadians as mr,pointFrom as se,pointRotateRads as At}from"@excalidraw/math";import{MIN_FONT_SIZE as la,SHIFT_LOCKING_ANGLE as pr,rescalePoints as su,getFontString as ur}from"@excalidraw/common";var lT=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[m]=n;if(t==="rotation")W(m)||(kg(m,i,a,l,o),Re(m,i));else if(t){let p=n[0].id,h=u.get(p),f=e.get(p);if(h&&f){let{nextWidth:E,nextHeight:g}=_g(h,f,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});Hg(E,g,h,f,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return Q(m)&&Re(m,i),!0}else if(n.length>1){if(t==="rotation")return Rg(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:h,flipByY:f,originalBoundingBox:E}=Wg(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return Ug(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:h,flipByY:f,nextWidth:m,nextHeight:p,originalBoundingBox:E}),!0}}return!1},kg=(e,t,n,i,o)=>{let[r,s,a,l]=V(e,t.getNonDeletedElementsMap()),d=(r+a)/2,c=(s+l)/2,u;q(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-c,n-d),o&&(u=u+pr/2,u=u-u%pr),u=mr(u));let m=bt(e),p={angle:u};if(Ce(e)&&(p={...p},e.startBinding&&Fe(e,"start",t),e.endBinding&&Fe(e,"end",t)),t.mutateElement(e,p),m){let h=t.getElement(m);if(h&&!_(e)){let{x:f,y:E}=Hi(e,h,t.getNonDeletedElementsMap());t.mutateElement(h,{angle:u,x:f,y:E})}}},au=(e,t,n,i)=>K(e)||Ae(e)?{points:su(0,t,su(1,n,e.points,i),i)}:{},da=(e,t,n)=>{let i=e.width;if(xe(e)){let s=Oe(e,t);s&&(i=xt(s,e))}let r=e.fontSize*(n/i);return r<la?null:{size:r}},Fg=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=da(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=se(e.x,e.y),u=aa(c,e.width,e.height,l,s,e.angle,i,!1,o);n.mutateElement(t,{fontSize:d.size,width:l,height:s,x:u.x,y:u.y});return}if(i==="e"||i==="w"){let c=Ao(ur({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=Xt(t.originalText,ur(t),Math.abs(u)),p=it(m,ur(t),t.lineHeight),h=p.height,f=se(e.x,e.y),E=aa(f,e.width,e.height,u,h,t.angle,i,!1,o),g={width:Math.abs(u),height:Math.abs(p.height),x:E.x,y:E.y,text:m,autoResize:!1};n.mutateElement(t,g)}}},Rg=(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+=pr/2,d-=d%pr);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!q(u)){let[m,p,h,f]=V(u,l),E=(m+h)/2,g=(p+f)/2,x=e.get(u.id)?.angle??u.angle,[b,y]=At(se(E,g),se(s,a),d+x-u.angle),w=W(u)?{points:ld(u,l)}:{x:u.x+(b-E),y:u.y+(y-g),angle:mr(d+x)};n.mutateElement(u,w),Re(u,n,{simultaneouslyUpdated:t}),Ce(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||Fe(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||Fe(u,"end",n)));let S=ne(u,l);if(S&&!_(u)){let{x:I,y:M}=Hi(u,S,l);n.mutateElement(S,{x:I,y:M,angle:mr(d+x)})}}n.triggerUpdate()},dT=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?V(t[0],n):Ye(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=At(se(i,o),se(d,c),-u),e){case"n":return At(se(i-(r+a)/2,o-s),se(0,0),u);case"s":return At(se(i-(r+a)/2,o-l),se(0,0),u);case"w":return At(se(i-r,o-(s+l)/2),se(0,0),u);case"e":return At(se(i-a,o-(s+l)/2),se(0,0),u);case"nw":return At(se(i-r,o-s),se(0,0),u);case"ne":return At(se(i-a,o-s),se(0,0),u);case"sw":return At(se(i-r,o-l),se(0,0),u);case"se":return At(se(i-a,o-l),se(0,0),u);default:return[0,0]}},cT=(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"},zg=(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"},aa=(e,t,n,i,o,r,s,a,l)=>{let d=zg(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)}}},Hg=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(Q(n)&&Q(i))return Fg(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=ne(n,u);if(m){let E=o.get(m.id);if(E&&(c={fontSize:E.fontSize}),l){let g={...n,width:e,height:t},x=da(m,u,xt(g,m));if(x===null)return;c={fontSize:x.size}}else{let g=xl(ur(m),m.lineHeight),x=bl(m.fontSize,m.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let p=au(i,e,t,!0),h=se(i.x,i.y);if(K(i)){let[E,g]=de(i,o);h=se(E,g)}let f=aa(h,i.width,i.height,e,t,i.angle,s,l,d);if(K(i)&&p.points){let E=i.x-h[0],g=i.y-h[1];f.x+=E,f.y+=g;let x=p.points[0][0],b=p.points[0][1];f.x+=x,f.y+=b,p.points=p.points.map(y=>se(y[0]-x,y[1]-b))}if(e<0&&(f.x=f.x+e),t<0&&(f.y=f.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),_(n)&&m&&l){let E=e/n.width*m.fontSize;if(E<la)return;c.fontSize=E}if(e!==0&&t!==0&&Number.isFinite(f.x)&&Number.isFinite(f.y)){let E={...f,width:Math.abs(e),height:Math.abs(t),...p};Ce(n)&&(n.startBinding&&(E={...E},n.startBinding&&Fe(n,"start",r)),n.endBinding&&(E={...E,endBinding:null})),r.mutateElement(n,E,{informMutation:a,isDragging:!1}),m&&c!=null&&r.mutateElement(m,{fontSize:c.fontSize}),Yn(n,r,s,l,d),Re(n,r)}},_g=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=dn(t,t.width,t.height,!0),u=se(a,l),m=se(d,c),p=Og(u,m),h=At(se(i,o),p,-t.angle),[f,E,g,x]=dn(e,e.width,e.height,!0),b=g-f,y=x-E,w=m[0]-u[0],S=m[1]-u[1],I=w/b,M=S/y;n.includes("e")&&(I=(h[0]-u[0])/b),n.includes("s")&&(M=(h[1]-u[1])/y),n.includes("w")&&(I=(m[0]-h[0])/b),n.includes("n")&&(M=(m[1]-h[1])/y);let A=e.width*I,G=e.height*M;if(s&&(A=2*A-t.width,G=2*G-t.height),r){let L=Math.abs(A)/t.width,N=Math.abs(G)/t.height;if(n.length===1&&(G*=L,A*=N),n.length===2){let D=Math.max(L,N);A=t.width*D*Math.sign(A),G=t.height*D*Math.sign(G)}}return{nextWidth:A,nextHeight:G}},Wg=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(D=>t.get(D.id)),d=l.reduce((D,j)=>{if(!K(j))return D;let H=bt(j);if(!H)return D;let Z=t.get(H)??null;return xe(Z)?[...D,{...Z,...C.getBoundTextElementPosition(j,Z,n)}]:D},[]),c=Jt(l.map(D=>D).concat(d)),{minX:u,minY:m,maxX:p,maxY:h,midX:f,midY:E}=c,g=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+g/2,h],s:[u+g/2,m]},[y,w]=a?[f,E]:b[i],S=a?2:1,I=Math.max(Math.abs(o-y)/g||0,Math.abs(r-w)/x||0)*S,M=i.includes("e")||i.includes("w")?Math.abs(o-y)*S:g,A=i.includes("n")||i.includes("s")?Math.abs(r-w)*S:x;s&&(M=g*I*Math.sign(o-y),A=x*I*Math.sign(r-w));let G={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]},[L,N]=G[i].map(D=>D);return{originalBoundingBox:c,nextWidth:M,nextHeight:A,flipByX:L,flipByY:N}},Ug=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:d,nextWidth:c,originalBoundingBox:u}={})=>{if(c===void 0&&d===void 0&&a===void 0&&l===void 0||d===0||c===0)return;o||(o=t);let m=e.reduce((S,I)=>{let M=o.get(I.id);return M&&S.push({orig:M,latest:I}),S},[]),p;if(u)p=u;else{let S=m.reduce((I,{orig:M})=>{if(!K(M))return I;let A=bt(M);if(!A)return I;let G=o.get(A)??null;return xe(G)?[...I,{...G,...C.getBoundTextElementPosition(M,G,t)}]:I},[]);p=Jt([...m.map(({orig:I})=>I),...S])}let{minX:h,minY:f,maxX:E,maxY:g,midX:x,midY:b}=p,y=E-h,w=g-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,M;n.length===1?M=n.includes("e")||n.includes("w")?S:I:M=Math.max(Math.abs(c)/y||0,Math.abs(d)/w||0);let A={ne:[h,g],se:[h,f],sw:[E,f],nw:[E,g],e:[h,f+w/2],w:[E,f+w/2],n:[h+y/2,g],s:[h+y/2,f]},[G,L]=s?[x,b]:A[n],N=r||m.some(T=>T.latest.angle!==0||Q(T.latest)||Sd(T.latest));N&&(S=M,I=M);let[D,j]=[a?-1:1,l?-1:1],H=[];for(let{orig:T,latest:F}of m){if(Q(T)&&xe(T))continue;let U=T.width*S,ge=T.height*I,at=mr(T.angle*D*j),Jn=K(T)||Ae(T),ei=T.x-G,Nn=T.y-L,kt=a&&!Jn?U:0,On=l&&!Jn?ge:0,on=G+D*(ei*S+kt),ti=L+j*(Nn*I+On),ue=au(T,U*D,ge*j,!1),oe={x:on,y:ti,width:U,height:ge,angle:at,...ue};if(W(T)&&(T.startBinding&&(oe.startBinding={...T.startBinding,fixedPoint:[a?-T.startBinding.fixedPoint[0]+1:T.startBinding.fixedPoint[0],l?-T.startBinding.fixedPoint[1]+1:T.startBinding.fixedPoint[1]]}),T.endBinding&&(oe.endBinding={...T.endBinding,fixedPoint:[a?-T.endBinding.fixedPoint[0]+1:T.endBinding.fixedPoint[0],l?-T.endBinding.fixedPoint[1]+1:T.endBinding.fixedPoint[1]]}),T.fixedSegments&&ue.points&&(oe.fixedSegments=T.fixedSegments.map(Ft=>({...Ft,start:ue.points[Ft.index-1],end:ue.points[Ft.index]})))),Te(T)&&(oe.scale=[T.scale[0]*D,T.scale[1]*j]),Q(T)){let Ft=da(T,t,U);if(!Ft)return;oe.fontSize=Ft.size}let rn=o.get(bt(T)??"");if(rn)if(N){let Ft=rn.fontSize*M;if(Ft<la)return;oe.boundTextFontSize=Ft}else oe.boundTextFontSize=rn.fontSize;H.push({element:F,update:oe})}let Z=H.map(({element:T})=>T),k=new Map(H.map(({element:T})=>[T.id,T]));for(let{element:T,update:{boundTextFontSize:F,...U}}of H){let{angle:ge}=U;i.mutateElement(T,U),Re(T,i,{simultaneouslyUpdated:Z}),Ce(T)&&(T.startBinding&&(k.has(T.startBinding.elementId)||Fe(T,"start",i)),T.endBinding&&(k.has(T.endBinding.elementId)||Fe(T,"end",i)));let at=ne(T,t);at&&F&&(i.mutateElement(at,{fontSize:F,angle:K(T)?void 0:ge}),Yn(T,i,n,!0,s))}i.triggerUpdate()}};P();import{pointFrom as mt,pointOnLineSegment as pu,pointRotateRads as hr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as ha}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as ua}from"@excalidraw/common";import{pointFrom as lu,pointRotateRads as Yg}from"@excalidraw/math";var du={mouse:8,pen:16,touch:28},jg=16,uu={e:!0,s:!0,n:!0,w:!0},gT={e:!0,s:!0,n:!0,w:!0},xT={e:!0,s:!0,n:!0,w:!0,rotation:!0},cu={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},ca={e:!0,s:!0,n:!0,w:!0},nn=(e,t,n,i,o,r,s)=>{let[a,l]=Yg(lu(e+n/2,t+i/2),lu(o,r),s);return[a-n/2,l-i/2,n,i]},fr=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),ma=e=>fr(e)?uu:{},pa=([e,t,n,i,o,r],s,a,l,d={},c=4,u=ua)=>{let m=du[l],p=m/a.value,h=m/a.value,f=m/a.value,E=m/a.value,g=n-e,x=i-t,b=c/a.value,y=(m-u*2)/(2*a.value),w={nw:d.nw?void 0:nn(e-b-f+y,t-b-E+y,p,h,o,r,s),ne:d.ne?void 0:nn(n+b-y,t-b-E+y,p,h,o,r,s),sw:d.sw?void 0:nn(e-b-f+y,i+b-y,p,h,o,r,s),se:d.se?void 0:nn(n+b-y,i+b-y,p,h,o,r,s),rotation:d.rotation?void 0:nn(e+g/2-p/2,t-b-E+y-jg/a.value,p,h,o,r,s)},S=5*du.mouse/a.value;return Math.abs(g)>S&&(d.n||(w.n=nn(e+g/2-p/2,t-b-E+y,p,h,o,r,s)),d.s||(w.s=nn(e+g/2-p/2,i+b-y,p,h,o,r,s))),Math.abs(x)>S&&(d.w||(w.w=nn(e-b-f+y,t+x/2-h/2,p,h,o,r,s)),d.e||(w.e=nn(n+b-y,t+x/2-h/2,p,h,o,r,s))),w},mu=(e,t,n,i="mouse",o=uu)=>{if(e.locked||W(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=cu:s[0]>0&&s[1]>0?o=ca:s[0]<0&&s[1]>0?o=cu:s[0]<0&&s[1]<0&&(o=ca)}}else q(e)&&(o={...o,rotation:!0});let r=K(e)?ua+8:Te(e)?0:ua;return pa(V(e,n,!0),e.angle,t,i,o,r,Te(e)?0:void 0)},bT=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return W(i)?!1:K(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var Ea=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],Xg=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=mu(e,r,t,s,ma(a));if(l&&Ea(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?Ea(m,i,o):!1});if(c.length>0)return c[0];if(fr(a)){let[u,m,p,h,f,E]=V(e,t);if(!(K(e)&&e.points.length<=2)){let g=Te(e)?0:ha/r.value,x=ha/r.value,b=fu(mt(u-g,m-g),mt(p+g,h+g),mt(f,E),e.angle);for(let[y,w]of Object.entries(b))if(pu(mt(i,o),w,x))return y}}return!1},TT=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=Xg(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),DT=([e,t,n,i],o,r,s,a,l)=>{let d=pa([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,ma(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&Ea(m,o,r)});if(c)return c;if(fr(l)){let u=(e+n)/2,m=(t+i)/2,p=ha/s.value,h=fu(mt(e-p,t-p),mt(n+p,i+p),mt(u,m),0);for(let[f,E]of Object.entries(h))if(pu(mt(o,r),E,p))return f}return!1},fa=["ns","nesw","ew","nwse"],Vg=(e,t)=>{let n=fa.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=fa[(n+i)%fa.length]}return e},vT=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=Vg(o,t.angle)),o?`${o}-resize`:""},fu=([e,t],[n,i],o,r)=>{let s=hr(mt(e,t),o,r),a=hr(mt(n,t),o,r),l=hr(mt(e,i),o,r),d=hr(mt(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var GT=(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")||Ot(t,e).length));P();import{pointFrom as Er}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as $g,DEFAULT_FONT_SIZE as Zg,TEXT_ALIGN as qg,VERTICAL_ALIGN as Kg,getSizeFromPoints as Qg,randomId as Jg,arrayToMap as ex,assertNever as ga,cloneJSON as Eu,getFontString as tx,isDevEnv as nx,toBrandedType as ix,getLineHeight as ox}from"@excalidraw/common";var gr={width:100,height:0},Gn=100,rx=(e,t,n)=>{let i=Qn({x:0,y:0,textAlign:qg.CENTER,verticalAlign:Kg.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),vo(i,e,n),[e,i]},hu=(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??Gn,u=t?.height??Gn,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 E="";m&&m.type==="text"?E=m.text:t.type==="text"&&(E=t.text),E||console.error(`No text found for start binding text element for ${e.id}`),r=Qn({x:p,y:h,type:"text",...m,...t,text:E}),Object.assign(r,{x:t.x||e.x-r.width,y:t.y||e.y-r.height/2})}else switch(f){case"rectangle":case"ellipse":case"diamond":{r=gi({x:p,y:h,width:c,height:u,...m,...t,type:f});break}default:ga(e,`Unhandled element start type "${t.type}"`,!0)}Nt(e,r,"orbit","start",o)}}if(n){let c=n?.height??Gn,u=n?.width??Gn,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 E="";m&&m.type==="text"?E=m.text:n.type==="text"&&(E=n.text),E||console.error(`No text found for end binding text element for ${e.id}`),s=Qn({x:p,y:h,type:"text",...m,...n,text:E}),Object.assign(s,{y:n.y||e.y-s.height/2})}else switch(f){case"rectangle":case"ellipse":case"diamond":{s=gi({x:p,y:h,width:u,height:c,...m,...n,type:f});break}default:ga(e,`Unhandled element end type "${f}"`,!0)}Nt(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=Eu(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,C.getNormalizeElementPointsAndCoords({...e,points:d})),{linearElement:e,startBoundElement:r,endBoundElement:s}},xa=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>Ts(Array.from(this.excalidrawElements.values()));getElementsMap=()=>ix(ex(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},VT=(e,t)=>{if(!e)return[];let n=Eu(e),i=new xa,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:Jg()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||Gn,p=l?.label?.text&&l.height===void 0?0:l?.height||Gn;d=gi({...l,width:m,height:p});break}case"line":{let m=l.width||gr.width,p=l.height||gr.height;d=lc({width:m,height:p,points:[Er(0,0),Er(m,p)],...l});break}case"arrow":{let m=l.width||gr.width,p=l.height||gr.height;d=or({width:m,height:p,endArrowhead:"arrow",points:[Er(0,0),Er(m,p)],...l,type:"arrow"}),Object.assign(d,Qg(d.points));break}case"text":{let m=l?.fontFamily||$g,p=l?.fontSize||Zg,h=l?.lineHeight||ox(m),f=l.text??"",E=zi(f),g=it(E,tx({fontFamily:m,fontSize:p}),h);d=Qn({width:g.width,height:g.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=dc({width:l?.width||Gn,height:l?.height||Gn,...l});break}case"frame":{d=rc({x:0,y:0,...l});break}case"magicframe":{d=sc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,ga(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 yi(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]=rx(c,d?.label,a);if(i.add(u),i.add(m),_(u)){let p=d.type==="arrow"?d?.start:void 0,h=d.type==="arrow"?d?.end:void 0;if(p&&p.id){let x=r.get(p.id);x&&Object.assign(p,{id:x})}if(h&&h.id){let x=r.get(h.id);x&&Object.assign(h,{id:x})}let{linearElement:f,startBoundElement:E,endBoundElement:g}=hu(u,p,h,i,a);u=f,i.add(f),i.add(E),i.add(g)}}else switch(d.type){case"arrow":{let{start:u,end:m}=d;if(u&&u.id){let E=r.get(u.id);Object.assign(u,{id:E})}if(m&&m.id){let E=r.get(m.id);Object.assign(m,{id:E})}let{linearElement:p,startBoundElement:h,endBoundElement:f}=hu(c,u,m,i,a);i.add(p),i.add(h),i.add(f);break}}break}}}for(let[l,d]of o){if(d.type!=="frame"&&d.type!=="magicframe")continue;let c=i.getElement(l);if(!c)throw new Error(`Excalidraw element with id ${l} doesn't exist`);let u=[];d.children.forEach(w=>{let S=r.get(w);if(!S)throw new Error(`Element with ${w} wasn't mapped correctly`);let I=i.getElement(S);if(!I)throw new Error(`Frame element with id ${S} doesn't exist`);Object.assign(I,{frameId:c.id}),I?.boundElements?.forEach(M=>{let A=i.getElement(M.id);if(!A)throw new Error(`Bound element with id ${M.id} doesn't exist`);Object.assign(A,{frameId:c.id}),u.push(A)}),u.push(I)});let[m,p,h,f]=Ye(u),E=10;m=m-E,p=p-E,h=h+E,f=f+E;let g=c?.x||m,x=c?.y||p,b=c?.width||h-m,y=c?.height||f-p;Object.assign(c,{x:g,y:x,width:b,height:y}),nx()&&d.children.length&&(c?.x||c?.y||c?.width||c?.height)&&console.info("User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically")}return i.getElements()};P();var QT=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return ou(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 C.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};P();var sx=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}},tD=e=>{let t=sx(e);return t===null?null:t};P();import{getBoundsFromPoints as wu,getElementAbsoluteCoords as ax}from"@excalidraw/element/bounds";import{newArrowElement as gu,newElement as lx,newLinearElement as xr}from"@excalidraw/element/newElement";import{ELEMENT_PENDING_DRAW_SHAPE_OPACITY as dx,getStrokeWidthByKey as br,ROUNDNESS as xu}from"@excalidraw/common";import{convexHull as cx,distanceToLineSegment as ux,elongation as mx,kurtosis as bu,lineSegment as px,orientPrincipalAxes as fx,pointFrom as Xe,polygonArea as hx,principalAxes as Ex,principalCoords as gx,skewness as xx}from"@excalidraw/math";var bx=64,wx=25,yx=.15,Px=.25,Ix=.5,Sx=.15,Ax=.3,Mx=1.5,Ii=3;function Tx(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 Dx(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=px(t,n),r=0;for(let s of e)Math.hypot(s[0]-n[0],s[1]-n[1])<=Ix*i||(r=Math.max(r,ux(s,o)));return r/i}function vx(e){let t=[];for(let n=Ii;n<e.length-Ii;n++){let[i,o]=e[n-Ii],[r,s]=e[n],[a,l]=e[n+Ii],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 Bx(e){let t=vx(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-Ii;l<=s+Ii;l++)l>=0&&l<t.length&&!i[l]&&(o+=t[l],i[l]=!0)}return o/n}function Lx(e){let t=Tx(e,bx),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=fx(t,Ex(t)),r=gx(t,o).map(([m])=>m),s=cx(t),[a,l,d,c]=wu(t),u=(d-a)*(c-l);return{gapRatio:n>0?i/n:0,elongation:mx(o),majorSkew:xx(r),hullFillRatio:u>0?hx(s)/u:0,cornerTurnShare:Bx(t),kurtosisProduct:bu(t.map(([m])=>m))*bu(t.map(([,m])=>m)),shaftDeviationRatio:Dx(t)}}var Cx=[{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}],Gx=.2,Nx=.2,Ox=.7;function kx(e){let t="freedraw",n=Mx;for(let i of Cx){let o=Math.hypot((e.hullFillRatio-i.hullFillRatio)/Gx,(e.cornerTurnShare-i.cornerTurnShare)/Nx,(e.kurtosisProduct-i.kurtosisProduct)/Ox);o<n&&(n=o,t=i.type)}return t}function Fx(e){return e.elongation>Px||e.shaftDeviationRatio>Sx?"freedraw":Math.abs(e.majorSkew)>=Ax?"arrow":"line"}function Rx(e){return e.gapRatio>yx?Fx(e):kx(e)}function zx(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=[Xe(i,o),Xe((i+r)/2,o),Xe(r,o),Xe(r,(o+s)/2),Xe(r,s),Xe((i+r)/2,s),Xe(i,s),Xe(i,(o+s)/2)],c=-1,u=Xe(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 Hx=(e,t,n=1)=>{typeof window<"u"&&(window.LAST_POINTS=e.map(([u,m])=>Xe(u,m)));let i=wu(e),[o,r,s,a]=i,l=Math.max(s-o,a-r);if(e.length<3||l*n<wx)return{type:"freedraw",points:e,boundingBox:i};let d=Rx(Lx(e));return{type:t?.type==="arrow"&&d!=="arrow"?"freedraw":d,points:e,boundingBox:i}},_x=(e,t,n,i,o)=>{let r=Hx(e,i,t.zoom.value),s=r.boundingBox,[a,l,d,c]=s,m=(o??Cs([...n.values()])).find(h=>{let[f,E,g,x]=ax(h,n);return f<=a&&E<=l&&g>=d&&x>=c})?.id??null,p=t.currentItemRoundness==="round"?{type:yo(r.type)?xu.ADAPTIVE_RADIUS:xu.PROPORTIONAL_RADIUS}:null;switch(r.type){case"rectangle":case"diamond":case"ellipse":return lx({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:br(r.type,t.currentItemStrokeWidthKey)});case"arrow":{let[h,f]=r.points[0],[E,g]=zx(r.points,r.boundingBox,r.points[0]),x=Xe(E-h,g-f);if(Math.hypot(E-r.points[0][0],g-r.points[0][1])<60){let S=xr({type:"line",x:h,y:f,points:[Xe(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:br(r.type,t.currentItemStrokeWidthKey)}),I=C.getNormalizeElementPointsAndCoords(S);return xr({...S,...I})}let y=gu({type:"arrow",x:h,y:f,startArrowhead:t.currentItemStartArrowhead,endArrowhead:t.currentItemEndArrowhead,points:[Xe(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:br(r.type,t.currentItemStrokeWidthKey)}),w=C.getNormalizeElementPointsAndCoords(y);return gu({...y,...w})}case"line":{let[h,f]=r.points[0],E=r.points[r.points.length-1],g=xr({type:r.type,x:h,y:f,points:[Xe(r.points[0][0]-h,r.points[0][1]-f),Xe(E[0]-h,E[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:br(r.type,t.currentItemStrokeWidthKey)}),x=C.getNormalizeElementPointsAndCoords(g);return xr({...g,...x})}}},Wx=(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},uD=(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=_x(n,e.state,e.scene.getNonDeletedElementsMap(),e.state.newElement,e.scene.getNonDeletedFramesLikes());if(i&&!Et(i)){let o=e.state.newElement,r={...i,id:o?.type===i.type?o.id:i.id,seed:1,opacity:dx,isDeleted:!1};Wx(o,r)||e.setState({newElement:r})}else e.state.newElement!==null&&e.setState({newElement:null})}return!0}return!1};var ED=e=>e.reduce((t,n)=>t+n.version,0),xc=e=>{let t=5381;for(let n of Ux(e))t=(t<<5)+t+n.versionNonce;return t>>>0},bc=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},ze=e=>!e.isDeleted,gD=e=>e.filter(t=>ze(t)&&!oc(t)),Sn=e=>e.filter(ze);export{Dn as AppStateDelta,ef as BASE_ARROW_MIN_LENGTH,nd as BASE_BINDING_GAP,jn as BASE_BINDING_GAP_ELBOW,ie as BASE_PADDING,bn as BindableElement,xn as BoundElement,et as CaptureUpdateAction,Z1 as DEFAULT_LINK_SIZE,uu as DEFAULT_OMIT_SIDES,Y as Delta,Zs as DurableIncrement,Ws as ElementBounds,vn as ElementsDelta,qs as EphemeralIncrement,Xi as FOCUS_POINT_SIZE,Yc as FlowChartCreator,Uc as FlowChartNavigator,Ie as HEADING_DOWN,De as HEADING_LEFT,le as HEADING_RIGHT,He as HEADING_UP,Hh as INVISIBLY_SMALL_ELEMENT_SIZE,As as InvalidFractionalIndexError,C as LinearElementEditor,Le as MINIMAL_CROP_SIZE,xT as OMIT_SIDES_FOR_FRAME,gT as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,yi as Scene,rt as ShapeCache,hc as Store,Qi as StoreChange,Ks as StoreDelta,ar as StoreIncrement,Bn as StoreSnapshot,Ke as aabbForElement,jf as addElementsToFrame,kP as addToGroup,ZI as alignElements,lf as avoidRectangularCorner,Nt as bindBindingElement,fP as bindBindingElementToFixedPoint,Gd as bindElementsToFramesAfterDuplication,tf as bindOrUnbindBindingElement,cP as bindOrUnbindBindingElements,fs as bindPointToSnapToElementOutline,ad as bindingProperties,Gs as boundsContainBounds,Zl as bumpVersion,uf as calculateFixedPointForElbowArrowBinding,pi as calculateFixedPointForNonElbowArrowBinding,iy as canApplyRoundnessTypeToElement,al as canBecomePolygon,Sl as canChangeRoundness,og as canCreateLinkFromElements,c0 as canHaveArrowheads,fr as canResizeFromSides,ai as charWidth,ae as compareHeading,Hi as computeBoundTextPosition,Xr as computeContainerDimensionForBoundText,Gy as containsCJK,VT as convertToExcalidrawElements,_x as convertToShape,uD as convertToShapeHandlePointerMoveFromPointerDown,$A as createPlaceholderEmbeddableLabel,ta as createSrcDoc,Zw as cropElement,un as deconstructDiamondElement,Po as deconstructLinearOrFreeDrawElement,cn as deconstructRectanguloidElement,$s as deepCopyElement,FA as defaultGetElementLinkFromSelection,My as detectLineHeight,pn as distanceToElement,wA as distributeElements,Zt as doBoundsIntersect,CA as dragNewElement,ig as dragNewTextElement,BA as dragSelectedElements,pE as duplicateElement,kS as duplicateElements,OP as editGroupForSelectedElement,re as elementCenterPoint,yn as elementOverlapsWithFrame,$i as elementWithCanvasCache,In as elementsAreInFrameBounds,Id as elementsAreInSameGroup,Td as elementsOverlappingBBox,qA as embeddableURLValidator,Nf as excludeElementsInFramesFromSelection,D1 as filterElementsEligibleAsFrameChildren,mP as fixBindingsAfterDeletion,sd as fixDuplicatedBindingsAfterDuplication,os as flipHeading,N1 as frameAndChildrenSelectedTogether,fl as generateLinearCollisionShape,Je as generateRoughOptions,JP as getActiveTextElement,Lo as getAllHoveredElementAtPoint,bl as getApproxMinLineHeight,xl as getApproxMinLineWidth,ld as getArrowLocalFixedPoints,Gh as getArrowheadAngle,tD as getArrowheadForPicker,je as getArrowheadPoints,Ch as getArrowheadSize,Pe as getBindingGap,pP as getBindingSideMidPoint,bs as getBindingStrategyForDraggingBindingElementEndpoints,ne as getBoundTextElement,bt as getBoundTextElementId,Xy as getBoundTextElementPosition,_i as getBoundTextMaxHeight,xt as getBoundTextMaxWidth,Us as getBoundsFromPoints,$t as getCenterForBounds,Jt as getCommonBoundingBox,Ye as getCommonBounds,Uf as getCommonFrameId,Yy as getContainerCenter,Vr as getContainerCoords,Oe as getContainerElement,Pn as getContainingFrame,Ut as getCornerRadius,Co as getCubicBezierCurveBound,vT as getCursorForResizingElement,qf as getDefaultFrameName,oy as getDefaultRoundnessTypeForElement,pl as getDiamondBaseCorners,si as getDiamondPoints,LA as getDragOffsetXY,CI as getDraggedElementsBounds,V as getElementAbsoluteCoords,de as getElementBounds,Bs as getElementLineSegments,Ps as getElementPointsCoords,$d as getElementShape,TT as getElementWithTransformHandleType,Nd as getElementsCompletelyInFrame,Ue as getElementsInGroup,T1 as getElementsInNewFrame,M1 as getElementsInResizingFrame,w1 as getElementsIntersectingFrame,G1 as getElementsOverlappingFrame,Md as getElementsWithinSelection,VA as getEmbedLink,yS as getEndpointBoundTextDragAnchor,qw as getFlipAdjustedCropPosition,wn as getFrameChildren,Yf as getFrameChildrenInsertionIndex,Cs as getFrameLikeElements,C1 as getFrameLikeTitle,Q1 as getFreedrawOutlineAsSegments,Ih as getFreedrawOutlinePoints,Ge as getGlobalFixedPointForBindableElement,mf as getGlobalFixedPoints,$l as getHeadingForElbowArrowSnap,Vt as getHoveredElementForBinding,kl as getHoveredElementForFocusPoint,UM as getInitializedImageElements,Mo as getLineHeightInPx,mn as getLineWidth,ry as getLinearElementSubType,RA as getLinkIdAndTypeFromSelection,bd as getLockedLinearCursorAlignSize,zm as getMaxCharWidth,RP as getMaximumGroups,Dy as getMinCharWidth,Vi as getMinMaxXYFromCurvePathOps,Ao as getMinTextElementWidth,Ad as getNewGroupIdsForDuplication,Sn as getNonDeletedElements,Pd as getNonDeletedGroupIds,WI as getNormalizedDimensions,wi as getObservedAppState,ma as getOmitSidesForEditorInterface,yy as getOriginalContainerHeightFromCache,Ys as getPerfectElementSize,LI as getRectangleBoxAbsoluteCoords,ah as getRenderOpacity,cT as getResizeArrowDirection,dT as getResizeOffsetXY,dn as getResizedElementAbsoluteCoords,A1 as getRootElements,ED as getSceneVersion,Ot as getSelectedElements,Vo as getSelectedElementsByGroup,Ss as getSelectedGroupForElement,vf as getSelectedGroupIdForElement,Tf as getSelectedGroupIds,QP as getSelectionStateForElements,Cm as getSnapOutlineMidPoint,KP as getTargetElements,Vf as getTargetFrame,js as getTextAnchorRatios,bS as getTextBindingForArrowEndpoint,jy as getTextElementAngle,qy as getTextFromElements,Rm as getTextHeight,wl as getTextWidth,DT as getTransformHandleTypeFromCoords,mu as getTransformHandles,pa as getTransformHandlesFromCoords,xS as getUnboundArrowEndpointAtPoint,Ja as getUncroppedImageElement,Nr as getUncroppedWidthAndHeight,ZP as getVisibleAndNonSelectedElements,gD as getVisibleElements,GI as getVisibleSceneBounds,$m as getWrappedTextLines,S1 as groupByFrameLikes,P1 as groupsAreAtLeastIntersectingTheFrame,I1 as groupsAreCompletelyOutOfFrame,Yn as handleBindTextResize,ou as handleFocusPointDrag,FM as handleFocusPointHover,OM as handleFocusPointPointerDown,kM as handleFocusPointPointerUp,Kr as hasBackground,Tt as hasBoundTextElement,bT as hasBoundingBox,l0 as hasFreedrawMode,r0 as hasStrokeColor,a0 as hasStrokeStyle,s0 as hasStrokeWidth,xc as hashElementsVersion,bc as hashString,Ze as headingForPoint,li as headingForPointFromElement,wt as headingForPointIsHorizontal,qe as headingIsHorizontal,L0 as headingIsVertical,Pp as hitElementBoundText,yp as hitElementBoundingBox,A0 as hitElementBoundingBoxOnly,Dt as hitElementItself,ut as intersectElementWithLineSegment,ny as isArrowBoundToElement,_ as isArrowElement,fe as isBindableElement,ns as isBindableElementInsideOtherBindable,Ce as isBindingElement,ym as isBindingElementType,Gt as isBindingEnabled,xe as isBoundToContainer,y1 as isCursorInFrame,bm as isCurvedArrow,W as isElbowArrow,_I as isElementCompletelyInViewport,Ls as isElementContainingFrame,kd as isElementInFrame,Df as isElementInGroup,Dd as isElementInViewport,hi as isElementIntersectingFrame,zA as isElementLink,ay as isEligibleFrameChildType,tl as isEmbeddableElement,wS as isEndpointBoundText,ol as isExcalidrawElement,pf as isFixedPoint,rl as isFlowchartNodeElement,cr as isFocusPointVisible,wo as isFrameElement,q as isFrameLikeElement,Ae as isFreeDrawElement,gm as isFreeDrawElementType,Ng as isHTMLSVGElement,xo as isIframeElement,bo as isIframeLikeElement,Te as isImageElement,Sd as isInGroup,Hn as isInitializedImageElement,oc as isInvisiblySmallElement,Et as isLineElement,K as isLinearElement,wm as isLinearElementType,nl as isMagicFrameElement,Ay as isMeasureTextSupported,cM as isNodeInFlowchart,ze as isNonDeletedElement,Wn as isPathALoop,Yt as isPointInElement,ki as isRectangularElement,il as isRectanguloidElement,Mf as isSelectedViaGroup,xm as isSharpArrow,ty as isSimpleArrow,qP as isSomeElementSelected,Pm as isTextBindableContainer,Q as isTextElement,yo as isUsingAdaptiveRadius,sl as isUsingProportionalRadius,sy as isValidPolygon,Zy as isValidTextContainer,Gg as loadHTMLImageElement,Is as makeNextSelectedElementIds,gt as maxBindingDistance_simple,QT as maybeHandleArrowPointlikeDrag,ZA as maybeParseEmbedSrc,da as measureFontSizeFromWidth,it as measureText,SM as moveAllLeft,AM as moveAllRight,Kc as moveArrowAboveBindable,PM as moveOneLeft,IM as moveOneRight,ve as mutateElement,or as newArrowElement,gi as newElement,_e as newElementWith,rS as newEmbeddableElement,rc as newFrameElement,lS as newFreeDrawElement,sS as newIframeElement,dc as newImageElement,lc as newLinearElement,sc as newMagicFrameElement,Qn as newTextElement,sx as normalizeArrowhead,mc as normalizeElementOrder,Ne as normalizeFixedPoint,YM as normalizeSVG,zi as normalizeText,Zo as omitGroupsContainingFrameLikes,Wf as omitPartialGroups,Bd as orderByFractionalIndex,Ri as originalContainerCache,HA as parseElementLinkFromURL,Xm as parseTokens,Bt as pointInsideBounds,kh as pointInsideBoundsInclusive,ZM as positionElementsOnGrid,Hr as projectFixedPointOntoDiagonal,Hx as recognizeShape,vo as redrawTextBoundingBox,aS as refreshTextDimensions,Xf as removeAllElementsFromFrame,Od as removeElementsFromFrame,FP as removeFromSelectedGroups,K1 as renderElement,q1 as renderSelectionElement,v1 as replaceAllElementsInFrame,au as rescalePointsInElement,El as resetOriginalContainerCache,Ug as resizeMultipleElements,Hg as resizeSingleElement,Fg as resizeSingleTextElement,Xg as resizeTest,Af as selectGroup,wd as selectGroupsForSelectedElements,yd as selectGroupsFromGivenElements,Ty as setCustomTextMetricsProvider,Vy as shouldAllowVerticalAlign,L1 as shouldApplyFrameClip,Bo as shouldTestInside,GT as showSelectedShapeActions,ws as snapToMid,$y as suppportsHorizontalAlign,Ts as syncInvalidIndices,Ld as syncInvalidIndicesImmutable,Zn as syncMovedIndices,xd as toggleLinePolygonState,d0 as toolIsArrow,lT as transformElements,Fe as unbindBindingElement,uP as updateBindings,Re as updateBoundElements,yt as updateBoundPoint,ci as updateElbowArrowPoints,B1 as updateFrameMembershipOfSelectedElements,WM as updateImageCache,hl as updateOriginalContainerCache,Vl as validateElbowPoints,Rf as validateFractionalIndices,Lt as vectorToHeading,Xt as wrapText};