@excalidraw/element 0.18.0-b9d27d3 → 0.18.0-c141960

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 (102) hide show
  1. package/dist/dev/index.js +2346 -1756
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +17 -17
  4. package/dist/types/common/src/constants.d.ts +9 -13
  5. package/dist/types/common/src/editorInterface.d.ts +34 -0
  6. package/dist/types/common/src/index.d.ts +2 -0
  7. package/dist/types/common/src/utils.d.ts +9 -3
  8. package/dist/types/common/src/visualdebug.d.ts +41 -0
  9. package/dist/types/element/src/binding.d.ts +55 -43
  10. package/dist/types/element/src/collision.d.ts +6 -2
  11. package/dist/types/element/src/index.d.ts +0 -3
  12. package/dist/types/element/src/linearElementEditor.d.ts +15 -18
  13. package/dist/types/element/src/renderElement.d.ts +5 -2
  14. package/dist/types/element/src/resizeTest.d.ts +5 -4
  15. package/dist/types/element/src/transformHandles.d.ts +5 -4
  16. package/dist/types/element/src/typeChecks.d.ts +2 -3
  17. package/dist/types/element/src/types.d.ts +7 -11
  18. package/dist/types/element/src/utils.d.ts +2 -1
  19. package/dist/types/element/src/zindex.d.ts +7 -1
  20. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +34 -13
  21. package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -6
  22. package/dist/types/excalidraw/actions/actionBoundText.d.ts +25 -11
  23. package/dist/types/excalidraw/actions/actionCanvas.d.ts +152 -275
  24. package/dist/types/excalidraw/actions/actionClipboard.d.ts +46 -773
  25. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +12 -5
  26. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +42 -23
  27. package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -2
  28. package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +2 -2
  29. package/dist/types/excalidraw/actions/actionElementLink.d.ts +11 -6
  30. package/dist/types/excalidraw/actions/actionElementLock.d.ts +23 -9
  31. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +12 -5
  32. package/dist/types/excalidraw/actions/actionExport.d.ts +68 -943
  33. package/dist/types/excalidraw/actions/actionFinalize.d.ts +10 -393
  34. package/dist/types/excalidraw/actions/actionFlip.d.ts +2 -2
  35. package/dist/types/excalidraw/actions/actionFrame.d.ts +50 -24
  36. package/dist/types/excalidraw/actions/actionGroup.d.ts +24 -10
  37. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +22 -19
  38. package/dist/types/excalidraw/actions/actionLink.d.ts +9 -2
  39. package/dist/types/excalidraw/actions/actionMenu.d.ts +10 -371
  40. package/dist/types/excalidraw/actions/actionNavigate.d.ts +21 -359
  41. package/dist/types/excalidraw/actions/actionProperties.d.ts +87 -2403
  42. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +12 -5
  43. package/dist/types/excalidraw/actions/actionStyles.d.ts +13 -6
  44. package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +1 -1
  45. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +11 -4
  46. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +11 -4
  47. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +10 -5
  48. package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
  49. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +11 -4
  50. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +11 -4
  51. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +12 -5
  52. package/dist/types/excalidraw/actions/actionZindex.d.ts +2 -2
  53. package/dist/types/excalidraw/actions/index.d.ts +2 -2
  54. package/dist/types/excalidraw/actions/manager.d.ts +1 -1
  55. package/dist/types/excalidraw/actions/register.d.ts +1 -1
  56. package/dist/types/excalidraw/actions/types.d.ts +4 -4
  57. package/dist/types/excalidraw/appState.d.ts +9 -4
  58. package/dist/types/excalidraw/clipboard.d.ts +2 -0
  59. package/dist/types/excalidraw/components/Actions.d.ts +21 -4
  60. package/dist/types/excalidraw/components/App.d.ts +26 -19
  61. package/dist/types/excalidraw/components/ColorPicker/Picker.d.ts +2 -0
  62. package/dist/types/excalidraw/components/ColorPicker/PickerColorList.d.ts +2 -1
  63. package/dist/types/excalidraw/components/ColorPicker/ShadeList.d.ts +2 -1
  64. package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
  65. package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -2
  66. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +1 -1
  67. package/dist/types/excalidraw/components/FilledButton.d.ts +1 -1
  68. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +2 -1
  69. package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +3 -1
  70. package/dist/types/excalidraw/components/HintViewer.d.ts +4 -3
  71. package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
  72. package/dist/types/excalidraw/components/LayerUI.d.ts +2 -1
  73. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
  74. package/dist/types/excalidraw/components/MobileMenu.d.ts +3 -5
  75. package/dist/types/excalidraw/components/MobileToolBar.d.ts +11 -0
  76. package/dist/types/excalidraw/components/Popover.d.ts +2 -1
  77. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -0
  78. package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
  79. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +1 -2
  80. package/dist/types/excalidraw/components/TextField.d.ts +1 -0
  81. package/dist/types/excalidraw/components/ToolPopover.d.ts +25 -0
  82. package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +6 -3
  83. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +4 -2
  84. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +2 -1
  85. package/dist/types/excalidraw/components/icons.d.ts +10 -0
  86. package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +13 -1
  87. package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +0 -3
  88. package/dist/types/excalidraw/data/blob.d.ts +2 -2
  89. package/dist/types/excalidraw/data/restore.d.ts +3 -3
  90. package/dist/types/excalidraw/data/types.d.ts +4 -1
  91. package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
  92. package/dist/types/excalidraw/hooks/useOutsideClick.d.ts +3 -1
  93. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +14 -0
  94. package/dist/types/excalidraw/index.d.ts +2 -3
  95. package/dist/types/excalidraw/renderer/animation.d.ts +12 -0
  96. package/dist/types/excalidraw/renderer/helpers.d.ts +1 -5
  97. package/dist/types/excalidraw/renderer/interactiveScene.d.ts +5 -13
  98. package/dist/types/excalidraw/scene/types.d.ts +15 -3
  99. package/dist/types/excalidraw/shortcut.d.ts +1 -0
  100. package/dist/types/excalidraw/types.d.ts +31 -21
  101. package/dist/types/math/src/segment.d.ts +1 -0
  102. package/package.json +3 -3
@@ -1,27 +1,27 @@
1
- var cc=Object.create;var Ps=Object.defineProperty;var uc=Object.getOwnPropertyDescriptor;var pc=Object.getOwnPropertyNames;var mc=Object.getPrototypeOf,fc=Object.prototype.hasOwnProperty;var hc=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ec=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var gc=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of pc(t))!fc.call(e,o)&&o!==n&&Ps(e,o,{get:()=>t[o],enumerable:!(i=uc(t,o))||i.enumerable});return e};var xc=(e,t,n)=>(n=e!=null?cc(mc(e)):{},gc(t||!e||!e.__esModule?Ps(n,"default",{value:e,enumerable:!0}):n,e));var A,P=hc(()=>{A={PROD:!0}});var wd=Ec((G1,xd)=>{P();var gd="Expected a function",hd=NaN,_f="[object Symbol]",Yf=/^\s+|\s+$/g,Uf=/^[-+]0x[0-9a-f]+$/i,Xf=/^0b[01]+$/i,jf=/^0o[0-7]+$/i,Wf=parseInt,Vf=typeof global=="object"&&global&&global.Object===Object&&global,$f=typeof self=="object"&&self&&self.Object===Object&&self,Zf=Vf||$f||Function("return this")(),qf=Object.prototype,Kf=qf.toString,Qf=Math.max,Jf=Math.min,ns=function(){return Zf.Date.now()};function eh(e,t,n){var i,o,r,s,a,l,d=0,c=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(gd);t=Ed(t)||0,Io(n)&&(c=!!n.leading,u="maxWait"in n,r=u?Qf(Ed(n.maxWait)||0,t):r,p="trailing"in n?!!n.trailing:p);function m(I){var M=i,D=o;return i=o=void 0,d=I,s=e.apply(D,M),s}function f(I){return d=I,a=setTimeout(g,t),c?m(I):s}function E(I){var M=I-l,D=I-d,T=t-M;return u?Jf(T,r-D):T}function h(I){var M=I-l,D=I-d;return l===void 0||M>=t||M<0||u&&D>=r}function g(){var I=ns();if(h(I))return x(I);a=setTimeout(g,E(I))}function x(I){return a=void 0,p&&i?m(I):(i=o=void 0,s)}function y(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function b(){return a===void 0?s:x(ns())}function w(){var I=ns(),M=h(I);if(i=arguments,o=this,l=I,M){if(a===void 0)return f(l);if(u)return a=setTimeout(g,t),m(l)}return a===void 0&&(a=setTimeout(g,t)),s}return w.cancel=y,w.flush=b,w}function th(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(gd);return Io(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),eh(e,t,{leading:i,maxWait:t,trailing:o})}function Io(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function nh(e){return!!e&&typeof e=="object"}function ih(e){return typeof e=="symbol"||nh(e)&&Kf.call(e)==_f}function Ed(e){if(typeof e=="number")return e;if(ih(e))return hd;if(Io(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Io(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Yf,"");var n=Xf.test(e);return n||jf.test(e)?Wf(e.slice(2),n?2:8):Uf.test(e)?hd:+e}xd.exports=th});P();import{toIterable as EE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Bt,viewportCoordsToSceneCoords as wo}from"@excalidraw/common";import{normalizeRadians as ql,radiansBetweenAngles as Ef,radiansDifference as gf}from"@excalidraw/math";import{pointsEqual as xf}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function Ro(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 yc(e,t,n){let i=[];e.forEach(o=>i.push(...o)),Ro(i,t,n)}function bc(e,t){return e[0]===t[0]&&e[1]===t[1]}function Is(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)Ro(d,a,o);let l=Pc(s,r,i);if(o){for(let d of s)Ro(d,a,-o);yc(l,a,-o)}return l}function Pc(e,t,n){let i=[];for(let d of e){let c=[...d];bc(c[0],c[c.length-1])||c.push([c[0][0],c[0][1]]),c.length>2&&i.push(c)}let o=[];t=Math.max(t,.1);let r=[];for(let d of i)for(let c=0;c<d.length-1;c++){let u=d[c],p=d[c+1];if(u[1]!==p[1]){let m=Math.min(u[1],p[1]);r.push({ymin:m,ymax:Math.max(u[1],p[1]),x:m===u[1]?u[0]:p[0],islope:(p[0]-u[0])/(p[1]-u[1])})}}if(r.sort((d,c)=>d.ymin<c.ymin?-1:d.ymin>c.ymin?1:d.x<c.x?-1:d.x>c.x?1:d.ymax===c.ymax?0:(d.ymax-c.ymax)/Math.abs(d.ymax-c.ymax)),!r.length)return o;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let d=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)d=u;r.splice(0,d+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(d=>!(d.edge.ymax<=a)),s.sort((d,c)=>d.edge.x===c.edge.x?0:(d.edge.x-c.edge.x)/Math.abs(d.edge.x-c.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let d=0;d<s.length;d=d+2){let c=d+1;if(c>=s.length)break;let u=s[d].edge,p=s[c].edge;o.push([[Math.round(u.x),a],[Math.round(p.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.edge.islope}),l++}return o}function rt(e,t){var n;let i=t.hachureAngle+90,o=t.hachureGap;o<0&&(o=t.strokeWidth*4),o=Math.max(o,.1);let r=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(r=o),Is(e,o,i,r||1)}var Ot=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=rt(t,n);return{type:"fillSketch",ops:this.renderLines(i,n)}}renderLines(t,n){let i=[];for(let o of t)i.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return i}};P();P();function Rt(e){let t=e[0],n=e[1];return Math.sqrt(Math.pow(t[0]-n[0],2)+Math.pow(t[1]-n[1],2))}var hi=class extends Ot{fillPolygons(t,n){let i=n.hachureGap;i<0&&(i=n.strokeWidth*4),i=Math.max(i,.1);let o=Object.assign({},n,{hachureGap:i}),r=rt(t,o),s=Math.PI/180*n.hachureAngle,a=[],l=i*.5*Math.cos(s),d=i*.5*Math.sin(s);for(let[u,p]of r)Rt([u,p])&&a.push([[u[0]-l,u[1]+d],[...p]],[[u[0]+l,u[1]-d],[...p]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var Ei=class extends Ot{fillPolygons(t,n){let i=this._fillPolygons(t,n),o=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),r=this._fillPolygons(t,o);return i.ops=i.ops.concat(r.ops),i}};P();var gi=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=rt(t,n);return this.dotsOnLines(i,n)}dotsOnLines(t,n){let i=[],o=n.hachureGap;o<0&&(o=n.strokeWidth*4),o=Math.max(o,.1);let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let s=o/4;for(let a of t){let l=Rt(a),d=l/o,c=Math.ceil(d)-1,u=l-c*o,p=(a[0][0]+a[1][0])/2-o/4,m=Math.min(a[0][1],a[1][1]);for(let f=0;f<c;f++){let E=m+u+f*o,h=p-s+Math.random()*2*s,g=E-s+Math.random()*2*s,x=this.helper.ellipse(h,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var xi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=rt(t,n);return{type:"fillSketch",ops:this.dashedLine(i,n)}}dashedLine(t,n){let i=n.dashOffset<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashOffset,o=n.dashGap<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashGap,r=[];return t.forEach(s=>{let a=Rt(s),l=Math.floor(a/(i+o)),d=(a+o-l*(i+o))/2,c=s[0],u=s[1];c[0]>u[0]&&(c=s[1],u=s[0]);let p=Math.atan((u[1]-c[1])/(u[0]-c[0]));for(let m=0;m<l;m++){let f=m*(i+o),E=f+i,h=[c[0]+f*Math.cos(p)+d*Math.cos(p),c[1]+f*Math.sin(p)+d*Math.sin(p)],g=[c[0]+E*Math.cos(p)+d*Math.cos(p),c[1]+E*Math.sin(p)+d*Math.sin(p)];r.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],n))}}),r}};P();var wi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,o=n.zigzagOffset<0?i:n.zigzagOffset;n=Object.assign({},n,{hachureGap:i+o});let r=rt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=Rt(r),a=Math.round(s/(2*n)),l=r[0],d=r[1];l[0]>d[0]&&(l=r[1],d=r[0]);let c=Math.atan((d[1]-l[1])/(d[0]-l[0]));for(let u=0;u<a;u++){let p=u*2*n,m=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),E=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],h=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],g=[E[0]+f*Math.cos(c+Math.PI/4),E[1]+f*Math.sin(c+Math.PI/4)];o.push(...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],i),...this.helper.doubleLineOps(g[0],g[1],h[0],h[1],i))}}),o}};var ve={};function Ss(e,t){let n=e.fillStyle||"hachure";if(!ve[n])switch(n){case"zigzag":ve[n]||(ve[n]=new hi(t));break;case"cross-hatch":ve[n]||(ve[n]=new Ei(t));break;case"dots":ve[n]||(ve[n]=new gi(t));break;case"dashed":ve[n]||(ve[n]=new xi(t));break;case"zigzag-line":ve[n]||(ve[n]=new wi(t));break;case"hachure":default:n="hachure",ve[n]||(ve[n]=new Ot(t));break}return ve[n]}P();function Ms(){return Math.floor(Math.random()*2**31)}var yi=class{constructor(t){this.seed=t}next(){return this.seed?(2**31-1&(this.seed=Math.imul(48271,this.seed)))/2**31:Math.random()}};P();P();var bi={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Ic(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 Fo(e,t){return e.type===t}function yn(e){let t=[],n=Ic(e),i="BOD",o=0,r=n[o];for(;!Fo(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=bi[r.text],i=r.text;else return yn("M0,0"+e);else Fo(r,1)?s=bi[i]:(o++,s=bi[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(Fo(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof bi[i]=="number"){let l={key:i,data:a};t.push(l),o+=s,r=n[o],i==="M"&&(i="L"),i==="m"&&(i="l")}else throw new Error("Bad segment: "+i)}else throw new Error("Path data ended short")}return t}P();function zn(e){let t=0,n=0,i=0,o=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[i,o]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),i=t,o=n;break;case"L":r.push({key:"L",data:[...a]}),[t,n]=a;break;case"l":t+=a[0],n+=a[1],r.push({key:"L",data:[t,n]});break;case"C":r.push({key:"C",data:[...a]}),t=a[4],n=a[5];break;case"c":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":r.push({key:"Q",data:[...a]}),t=a[2],n=a[3];break;case"q":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":r.push({key:"A",data:[...a]}),t=a[5],n=a[6];break;case"a":t+=a[5],n+=a[6],r.push({key:"A",data:[a[0],a[1],a[2],a[3],a[4],t,n]});break;case"H":r.push({key:"H",data:[...a]}),t=a[0];break;case"h":t+=a[0],r.push({key:"H",data:[t]});break;case"V":r.push({key:"V",data:[...a]}),n=a[0];break;case"v":n+=a[0],r.push({key:"V",data:[n]});break;case"S":r.push({key:"S",data:[...a]}),t=a[2],n=a[3];break;case"s":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=i,n=o;break}return r}P();function Yn(e){let t=[],n="",i=0,o=0,r=0,s=0,a=0,l=0;for(let{key:d,data:c}of e){switch(d){case"M":t.push({key:"M",data:[...c]}),[i,o]=c,[r,s]=c;break;case"C":t.push({key:"C",data:[...c]}),i=c[4],o=c[5],a=c[2],l=c[3];break;case"L":t.push({key:"L",data:[...c]}),[i,o]=c;break;case"H":i=c[0],t.push({key:"L",data:[i,o]});break;case"V":o=c[0],t.push({key:"L",data:[i,o]});break;case"S":{let u=0,p=0;n==="C"||n==="S"?(u=i+(i-a),p=o+(o-l)):(u=i,p=o),t.push({key:"C",data:[u,p,...c]}),a=c[0],l=c[1],i=c[2],o=c[3];break}case"T":{let[u,p]=c,m=0,f=0;n==="Q"||n==="T"?(m=i+(i-a),f=o+(o-l)):(m=i,f=o);let E=i+2*(m-i)/3,h=o+2*(f-o)/3,g=u+2*(m-u)/3,x=p+2*(f-p)/3;t.push({key:"C",data:[E,h,g,x,u,p]}),a=m,l=f,i=u,o=p;break}case"Q":{let[u,p,m,f]=c,E=i+2*(u-i)/3,h=o+2*(p-o)/3,g=m+2*(u-m)/3,x=f+2*(p-f)/3;t.push({key:"C",data:[E,h,g,x,m,f]}),a=u,l=p,i=m,o=f;break}case"A":{let u=Math.abs(c[0]),p=Math.abs(c[1]),m=c[2],f=c[3],E=c[4],h=c[5],g=c[6];u===0||p===0?(t.push({key:"C",data:[i,o,h,g,h,g]}),i=h,o=g):(i!==h||o!==g)&&(Ts(i,o,h,g,u,p,m,f,E).forEach(function(y){t.push({key:"C",data:y})}),i=h,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function Sc(e){return Math.PI*e/180}function _n(e,t,n){let i=e*Math.cos(n)-t*Math.sin(n),o=e*Math.sin(n)+t*Math.cos(n);return[i,o]}function Ts(e,t,n,i,o,r,s,a,l,d){let c=Sc(s),u=[],p=0,m=0,f=0,E=0;if(d)[p,m,f,E]=d;else{[e,t]=_n(e,t,-c),[n,i]=_n(n,i,-c);let R=(e-n)/2,L=(t-i)/2,V=R*R/(o*o)+L*L/(r*r);V>1&&(V=Math.sqrt(V),o=V*o,r=V*r);let H=a===l?-1:1,te=o*o,S=r*r,Q=te*S-te*L*L-S*R*R,$=te*L*L+S*R*R,ne=H*Math.sqrt(Math.abs(Q/$));f=ne*o*L/r+(e+n)/2,E=ne*-r*R/o+(t+i)/2,p=Math.asin(parseFloat(((t-E)/r).toFixed(9))),m=Math.asin(parseFloat(((i-E)/r).toFixed(9))),e<f&&(p=Math.PI-p),n<f&&(m=Math.PI-m),p<0&&(p=Math.PI*2+p),m<0&&(m=Math.PI*2+m),l&&p>m&&(p=p-Math.PI*2),!l&&m>p&&(m=m-Math.PI*2)}let h=m-p;if(Math.abs(h)>Math.PI*120/180){let R=m,L=n,V=i;l&&m>p?m=p+Math.PI*120/180*1:m=p+Math.PI*120/180*-1,n=f+o*Math.cos(m),i=E+r*Math.sin(m),u=Ts(n,i,L,V,o,r,s,0,l,[m,R,f,E])}h=m-p;let g=Math.cos(p),x=Math.sin(p),y=Math.cos(m),b=Math.sin(m),w=Math.tan(h/4),I=4/3*o*w,M=4/3*r*w,D=[e,t],T=[e+I*x,t-M*g],N=[n+I*b,i-M*y],C=[n,i];if(T[0]=2*D[0]-T[0],T[1]=2*D[1]-T[1],d)return[T,N,C].concat(u);{u=[T,N,C].concat(u);let R=[];for(let L=0;L<u.length;L+=3){let V=_n(u[L][0],u[L][1],c),H=_n(u[L+1][0],u[L+1][1],c),te=_n(u[L+2][0],u[L+2][1],c);R.push([V[0],V[1],H[0],H[1],te[0],te[1]])}return R}}var Mc={randOffset:Dc,randOffsetWithRange:vc,ellipse:Ac,doubleLineOps:Lc};function No(e,t,n,i,o){return{type:"path",ops:ht(e,t,n,i,o)}}function Un(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...ht(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...ht(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return No(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Tc(e,t){return Un(e,!0,t)}function Cs(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Tc(r,o)}function Ho(e,t){let n=Ds(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=Ds(e,1.5*(1+t.roughness*.22),Cc(t));n=n.concat(i)}return{type:"path",ops:n}}function Ac(e,t,n,i,o){let r=zo(n,i,o);return Si(e,t,o,r).opset}function zo(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=k(s*l,n),a+=k(a*l,n),{increment:r,rx:s,ry:a}}function Si(e,t,n,i){let[o,r]=vs(i.increment,e,t,i.rx,i.ry,1,i.increment*Pi(.1,Pi(.4,1,n),n),n),s=Ii(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=vs(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Ii(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function _o(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),p=Math.abs(i/2);u+=k(u*.01,l),p+=k(p*.01,l);let m=o,f=r;for(;m<0;)m+=Math.PI*2,f+=Math.PI*2;f-m>Math.PI*2&&(m=0,f=Math.PI*2);let E=Math.PI*2/l.curveStepCount,h=Math.min(E/2,(f-m)/2),g=Ls(h,d,c,u,p,m,f,1,l);if(!l.disableMultiStroke){let x=Ls(h,d,c,u,p,m,f,1.5,l);g.push(...x)}return s&&(a?g.push(...ht(d,c,d+u*Math.cos(m),c+p*Math.sin(m),l),...ht(d,c,d+u*Math.cos(f),c+p*Math.sin(f),l)):g.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(m),c+p*Math.sin(m)]})),{type:"path",ops:g}}function Yo(e,t){let n=Yn(zn(yn(e))),i=[],o=[0,0],r=[0,0];for(let{key:s,data:a}of n)switch(s){case"M":{r=[a[0],a[1]],o=[a[0],a[1]];break}case"L":i.push(...ht(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,d,c,u,p,m]=a;i.push(...Bc(l,d,c,u,p,m,r,t)),r=[p,m];break}case"Z":i.push(...ht(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function Mi(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+k(o,t),i[0][1]+k(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+k(o,t),i[s][1]+k(o,t)]})}}return{type:"fillPath",ops:n}}function dn(e,t){return Ss(t,Mc).fillPolygons(e,t)}function Bs(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=k(d*.01,s),c+=k(c*.01,s);let u=o,p=r;for(;u<0;)u+=Math.PI*2,p+=Math.PI*2;p-u>Math.PI*2&&(u=0,p=Math.PI*2);let m=(p-u)/s.curveStepCount,f=[];for(let E=u;E<=p;E=E+m)f.push([a+d*Math.cos(E),l+c*Math.sin(E)]);return f.push([a+d*Math.cos(p),l+c*Math.sin(p)]),f.push([a,l]),dn([f],s)}function Dc(e,t){return k(e,t)}function vc(e,t,n){return Pi(e,t,n)}function Lc(e,t,n,i,o){return ht(e,t,n,i,o,!0)}function Cc(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Gs(e){return e.randomizer||(e.randomizer=new yi(e.seed||0)),e.randomizer.next()}function Pi(e,t,n,i=1){return n.roughness*i*(Gs(n)*(t-e)+e)}function k(e,t,n=1){return Pi(-e,e,t,n)}function ht(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=As(e,t,n,i,o,!0,!1);if(s)return a;let l=As(e,t,n,i,o,!0,!0);return a.concat(l)}function As(e,t,n,i,o,r,s){let a=Math.pow(e-n,2)+Math.pow(t-i,2),l=Math.sqrt(a),d=1;l<200?d=1:l>500?d=.4:d=-.0016668*l+1.233334;let c=o.maxRandomnessOffset||0;c*c*100>a&&(c=l/10);let u=c/2,p=.2+Gs(o)*.2,m=o.bowing*o.maxRandomnessOffset*(i-t)/200,f=o.bowing*o.maxRandomnessOffset*(e-n)/200;m=k(m,o,d),f=k(f,o,d);let E=[],h=()=>k(u,o,d),g=()=>k(c,o,d),x=o.preserveVertices;return r&&(s?E.push({op:"move",data:[e+(x?0:h()),t+(x?0:h())]}):E.push({op:"move",data:[e+(x?0:k(c,o,d)),t+(x?0:k(c,o,d))]})),s?E.push({op:"bcurveTo",data:[m+e+(n-e)*p+h(),f+t+(i-t)*p+h(),m+e+2*(n-e)*p+h(),f+t+2*(i-t)*p+h(),n+(x?0:h()),i+(x?0:h())]}):E.push({op:"bcurveTo",data:[m+e+(n-e)*p+g(),f+t+(i-t)*p+g(),m+e+2*(n-e)*p+g(),f+t+2*(i-t)*p+g(),n+(x?0:g()),i+(x?0:g())]}),E}function Ds(e,t,n){let i=[];i.push([e[0][0]+k(t,n),e[0][1]+k(t,n)]),i.push([e[0][0]+k(t,n),e[0][1]+k(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+k(t,n),e[o][1]+k(t,n)]),o===e.length-1&&i.push([e[o][0]+k(t,n),e[o][1]+k(t,n)]);return Ii(i,null,n)}function Ii(e,t,n){let i=e.length,o=[];if(i>3){let r=[],s=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<i;a++){let l=e[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*e[a+1][0]-s*e[a-1][0])/6,l[1]+(s*e[a+1][1]-s*e[a-1][1])/6],r[2]=[e[a+1][0]+(s*e[a][0]-s*e[a+2][0])/6,e[a+1][1]+(s*e[a][1]-s*e[a+2][1])/6],r[3]=[e[a+1][0],e[a+1][1]],o.push({op:"bcurveTo",data:[r[1][0],r[1][1],r[2][0],r[2][1],r[3][0],r[3][1]]})}if(t&&t.length===2){let a=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+k(a,n),t[1]+k(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...ht(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function vs(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let p=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(p),c.push(p)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=k(.5,a)-Math.PI/2;c.push([k(r,a)+t+.9*i*Math.cos(u-e),k(r,a)+n+.9*o*Math.sin(u-e)]);let p=Math.PI*2+u-.01;for(let m=u;m<p;m=m+e){let f=[k(r,a)+t+i*Math.cos(m),k(r,a)+n+o*Math.sin(m)];d.push(f),c.push(f)}c.push([k(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),k(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([k(r,a)+t+.98*i*Math.cos(u+s),k(r,a)+n+.98*o*Math.sin(u+s)]),c.push([k(r,a)+t+.9*i*Math.cos(u+s*.5),k(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function Ls(e,t,n,i,o,r,s,a,l){let d=r+k(.1,l),c=[];c.push([k(a,l)+t+.9*i*Math.cos(d-e),k(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([k(a,l)+t+i*Math.cos(u),k(a,l)+n+o*Math.sin(u)]);return c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),Ii(c,null,l)}function Bc(e,t,n,i,o,r,s,a){let l=[],d=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],c=[0,0],u=a.disableMultiStroke?1:2,p=a.preserveVertices;for(let m=0;m<u;m++)m===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(p?0:k(d[0],a)),s[1]+(p?0:k(d[0],a))]}),c=p?[o,r]:[o+k(d[m],a),r+k(d[m],a)],l.push({op:"bcurveTo",data:[e+k(d[m],a),t+k(d[m],a),n+k(d[m],a),i+k(d[m],a),c[0],c[1]]});return l}P();function Xn(e){return[...e]}function ks(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let i=[];if(n===3)i.push(Xn(e[0]),Xn(e[1]),Xn(e[2]),Xn(e[2]));else{let o=[];o.push(e[0],e[0]);for(let a=1;a<e.length;a++)o.push(e[a]),a===e.length-1&&o.push(e[a]);let r=[],s=1-t;i.push(Xn(o[0]));for(let a=1;a+2<o.length;a++){let l=o[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*o[a+1][0]-s*o[a-1][0])/6,l[1]+(s*o[a+1][1]-s*o[a-1][1])/6],r[2]=[o[a+1][0]+(s*o[a][0]-s*o[a+2][0])/6,o[a+1][1]+(s*o[a][1]-s*o[a+2][1])/6],r[3]=[o[a+1][0],o[a+1][1]],i.push(r[1],r[2],r[3])}}return i}P();function Gc(e,t){return Math.sqrt(Ti(e,t))}function Ti(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function kc(e,t,n){let i=Ti(t,n);if(i===0)return Ti(e,t);let o=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i;return o=Math.max(0,Math.min(1,o)),Ti(e,cn(t,n,o))}function cn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Oc(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 Uo(e,t,n,i){let o=i||[];if(Oc(e,t)<n){let r=e[t+0];o.length?Gc(o[o.length-1],r)>1&&o.push(r):o.push(r),o.push(e[t+3])}else{let s=e[t+0],a=e[t+1],l=e[t+2],d=e[t+3],c=cn(s,a,.5),u=cn(a,l,.5),p=cn(l,d,.5),m=cn(c,u,.5),f=cn(u,p,.5),E=cn(m,f,.5);Uo([s,c,m,E],0,n,o),Uo([E,f,p,d],0,n,o)}return o}function jn(e,t){return Ai(e,0,e.length,t)}function Ai(e,t,n,i,o){let r=o||[],s=e[t],a=e[n-1],l=0,d=1;for(let c=t+1;c<n-1;++c){let u=kc(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(Ai(e,t,d+1,i,r),Ai(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function Et(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;Uo(e,s,t,i)}return n&&n>0?Ai(i,0,i.length,n):i}P();function Os(e,t,n){let i=yn(e),o=Yn(zn(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Et(l,t)),l=[]},c=()=>{d(),s.length&&(r.push(s),s=[])};for(let{key:p,data:m}of o)switch(p){case"M":c(),a=[m[0],m[1]],s.push(a);break;case"L":d(),s.push([m[0],m[1]]);break;case"C":if(!l.length){let f=s.length?s[s.length-1]:a;l.push([f[0],f[1]])}l.push([m[0],m[1]]),l.push([m[2],m[3]]),l.push([m[4],m[5]]);break;case"Z":d(),s.push([a[0],a[1]]);break}if(c(),!n)return r;let u=[];for(let p of r){let m=jn(p,n);m.length&&u.push(m)}return u}var Ne="none",je=class{constructor(t){this.defaultOptions={maxRandomnessOffset:2,roughness:1,bowing:1,stroke:"#000",strokeWidth:1,curveTightness:0,curveFitting:.95,curveStepCount:9,fillStyle:"hachure",fillWeight:-1,hachureAngle:-41,hachureGap:-1,dashOffset:-1,dashGap:-1,zigzagOffset:-1,seed:0,disableMultiStroke:!1,disableMultiStrokeFill:!1,preserveVertices:!1,fillShapeRoughnessGain:.8},this.config=t||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}static newSeed(){return Ms()}_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",[No(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=Cs(t,n,i,o,s);if(s.fill){let d=[[t,n],[t+i,n],[t+i,n+o],[t,n+o]];s.fillStyle==="solid"?a.push(Mi([d],s)):a.push(dn([d],s))}return s.stroke!==Ne&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=zo(i,o,s),d=Si(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Si(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(dn([d.estimatedPoints],s));return s.stroke!==Ne&&a.push(d.opset),this._d("ellipse",a,s)}circle(t,n,i,o){let r=this.ellipse(t,n,i,i,o);return r.shape="circle",r}linearPath(t,n){let i=this._o(n);return this._d("linearPath",[Un(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=_o(t,n,i,o,r,s,a,!0,d);if(a&&d.fill)if(d.fillStyle==="solid"){let p=Object.assign({},d);p.disableMultiStroke=!0;let m=_o(t,n,i,o,r,s,!0,!1,p);m.type="fillPath",c.push(m)}else c.push(Bs(t,n,i,o,r,s,d));return d.stroke!==Ne&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=Ho(t,i);if(i.fill&&i.fill!==Ne&&t.length>=3)if(i.fillStyle==="solid"){let s=Ho(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=ks(t),a=Et(s,10,(1+i.roughness)/2);o.push(dn([a],i))}return i.stroke!==Ne&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=Un(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(Mi([t],i)):o.push(dn([t],i))),i.stroke!==Ne&&o.push(r),this._d("polygon",o,i)}path(t,n){let i=this._o(n),o=[];if(!t)return this._d("path",o,i);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=i.fill&&i.fill!=="transparent"&&i.fill!==Ne,s=i.stroke!==Ne,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=Os(t,1,l),c=Yo(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=Yo(t,Object.assign(Object.assign({},i),{disableMultiStroke:!0,roughness:i.roughness?i.roughness+i.fillShapeRoughnessGain:0}));o.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else o.push(Mi(d,i));else o.push(dn(d,i));return s&&(a?d.forEach(u=>{o.push(Un(u,!1,i))}):o.push(c)),this._d("path",o,i)}opsToPath(t,n){let i="";for(let o of t.ops){let r=typeof n=="number"&&n>=0?o.data.map(s=>+s.toFixed(n)):o.data;switch(o.op){case"move":i+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":i+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":i+=`L${r[0]} ${r[1]} `;break}}return i.trim()}toPaths(t){let n=t.sets||[],i=t.options||this.defaultOptions,o=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:Ne};break;case"fillPath":s={d:this.opsToPath(r),stroke:Ne,strokeWidth:0,fill:i.fill||Ne};break;case"fillSketch":s=this.fillSketch(r,i);break}s&&o.push(s)}return o}fillSketch(t,n){let i=n.fillWeight;return i<0&&(i=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||Ne,strokeWidth:i,fill:Ne}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var Di=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new je(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":o.save(),o.strokeStyle=i.stroke==="none"?"transparent":i.stroke,o.lineWidth=i.strokeWidth,i.strokeLineDash&&o.setLineDash(i.strokeLineDash),i.strokeLineDashOffset&&(o.lineDashOffset=i.strokeLineDashOffset),this._drawToContext(o,s,r),o.restore();break;case"fillPath":{o.save(),o.fillStyle=i.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(o,s,r,a),o.restore();break}case"fillSketch":this.fillSketch(o,s,i);break}}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2),t.save(),i.fillLineDash&&t.setLineDash(i.fillLineDash),i.fillLineDashOffset&&(t.lineDashOffset=i.fillLineDashOffset),t.strokeStyle=i.fill||"",t.lineWidth=o,this._drawToContext(t,n,i.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,i,o="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof i=="number"&&i>=0?r.data.map(a=>+a.toFixed(i)):r.data;switch(r.op){case"move":t.moveTo(s[0],s[1]);break;case"bcurveTo":t.bezierCurveTo(s[0],s[1],s[2],s[3],s[4],s[5]);break;case"lineTo":t.lineTo(s[0],s[1]);break}}n.type==="fillPath"?t.fill(o):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s),s}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s),s}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s),s}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r),r}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i),i}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i),i}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d),d}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i),i}path(t,n){let i=this.gen.path(t,n);return this.draw(i),i}};P();P();var Wn="http://www.w3.org/2000/svg";var vi=class{constructor(t,n){this.svg=t,this.gen=new je(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(Wn,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(Wn,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke",i.stroke),l.setAttribute("stroke-width",i.strokeWidth+""),l.setAttribute("fill","none"),i.strokeLineDash&&l.setAttribute("stroke-dasharray",i.strokeLineDash.join(" ").trim()),i.strokeLineDashOffset&&l.setAttribute("stroke-dashoffset",`${i.strokeLineDashOffset}`);break}case"fillPath":{l=o.createElementNS(Wn,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke","none"),l.setAttribute("stroke-width","0"),l.setAttribute("fill",i.fill||""),(t.shape==="curve"||t.shape==="polygon")&&l.setAttribute("fill-rule","evenodd");break}case"fillSketch":{l=this.fillSketch(o,a,i);break}}l&&r.appendChild(l)}return r}fillSketch(t,n,i){let o=i.fillWeight;o<0&&(o=i.strokeWidth/2);let r=t.createElementNS(Wn,"path");return r.setAttribute("d",this.opsToPath(n,i.fixedDecimalPlaceDigits)),r.setAttribute("stroke",i.fill||""),r.setAttribute("stroke-width",o+""),r.setAttribute("fill","none"),i.fillLineDash&&r.setAttribute("stroke-dasharray",i.fillLineDash.join(" ").trim()),i.fillLineDashOffset&&r.setAttribute("stroke-dashoffset",`${i.fillLineDashOffset}`),r}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,n){return this.gen.opsToPath(t,n)}line(t,n,i,o,r){let s=this.gen.line(t,n,i,o,r);return this.draw(s)}rectangle(t,n,i,o,r){let s=this.gen.rectangle(t,n,i,o,r);return this.draw(s)}ellipse(t,n,i,o,r){let s=this.gen.ellipse(t,n,i,o,r);return this.draw(s)}circle(t,n,i,o){let r=this.gen.circle(t,n,i,o);return this.draw(r)}linearPath(t,n){let i=this.gen.linearPath(t,n);return this.draw(i)}polygon(t,n){let i=this.gen.polygon(t,n);return this.draw(i)}arc(t,n,i,o,r,s,a=!1,l){let d=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(d)}curve(t,n){let i=this.gen.curve(t,n);return this.draw(i)}path(t,n){let i=this.gen.path(t,n);return this.draw(i)}};var un={canvas(e,t){return new Di(e,t)},svg(e,t){return new vi(e,t)},generator(e){return new je(e)},newSeed(){return je.newSeed()}};import{arrayToMap as $l,invariant as Ur,rescalePoints as Ul,sizeOf as af}from"@excalidraw/common";import{degreesToRadians as Yr,lineSegment as ge,pointDistance as lf,pointFrom as v,pointFromArray as Zl,pointRotateRads as se}from"@excalidraw/math";P();import{invariant as Rc}from"@excalidraw/common";import{curve as Fc,lineSegment as Nc,pointFrom as le,pointDistance as tx,pointFromArray as Hc,pointFromVector as zc,pointRotateRads as qe,polygon as Rs,polygonFromPoints as Xo,PRECISION as nx,segmentsIntersectAt as ix,vector as _c,vectorAdd as Yc,vectorFromPoint as Uc,vectorScale as ox}from"@excalidraw/math";import{getElementAbsoluteCoords as sx}from"@excalidraw/element";var Fs=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=le(s,a),d;return e.type==="diamond"?d=Rs(qe(le(s,r),l,t),qe(le(o+n,a),l,t),qe(le(s,r+i),l,t),qe(le(o,a),l,t)):d=Rs(qe(le(o,r),l,t),qe(le(o+n,r),l,t),qe(le(o+n,r+i),l,t),qe(le(o,r+i),l,t)),{type:"polygon",data:d}};var Ns=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:le(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},gt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},Hs=(e,t=le(0,0),n,i)=>{let o=l=>qe(le(l[0]+t[0],l[1]+t[1]),i,n),r=gt(e),s=[],a=le(0,0);for(let l of r){if(l.op==="move"){let d=Hc(l.data);Rc(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(le(l.data[0],l.data[1])),c=o(le(l.data[2],l.data[3])),u=o(le(l.data[4],l.data[5]));s.push(Fc(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Xc=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Nc(t,o)),t=o}return n},zs=(e,t,n=!1)=>{let i=r=>qe(zc(Yc(Uc(r),_c(e.x,e.y))),t,e.angle),o=Xc(e.points.map(r=>i(r)));return n?{type:"polygon",data:Xo(o.flat())}:{type:"polyline",data:o}},_s=(e,t,n=le(0,0),i,o)=>{let r=c=>qe(le(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:Xo(e.points.map(c=>r(c)))};let s=gt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(le(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(le(c.data[0],c.data[1])),a.push(le(c.data[2],c.data[3])),a.push(le(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(le(c.data[0],c.data[1]));let d=Et(a,10,5).map(c=>r(c));return{type:"polygon",data:Xo(d)}};P();import{pointFrom as de,pointDistance as Fl,pointRotateRads as Lt}from"@excalidraw/math";import{ROUGHNESS as Jm,isTransparent as li,assertNever as ef,COLOR_PALETTE as tf,LINE_POLYGON_POINT_MERGE_DISTANCE as nf}from"@excalidraw/common";P();P();function Ys(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function jc(e){return[-e[0],-e[1]]}function Qe(e,t){return[e[0]+t[0],e[1]+t[1]]}function We(e,t){return[e[0]-t[0],e[1]-t[1]]}function Ke(e,t){return[e[0]*t,e[1]*t]}function Wc(e,t){return[e[0]/t,e[1]/t]}function Vn(e){return[e[1],-e[0]]}function Us(e,t){return e[0]*t[0]+e[1]*t[1]}function Vc(e,t){return e[0]===t[0]&&e[1]===t[1]}function $c(e){return Math.hypot(e[0],e[1])}function Zc(e){return e[0]*e[0]+e[1]*e[1]}function Xs(e,t){return Zc(We(e,t))}function Vs(e){return Wc(e,$c(e))}function qc(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function $n(e,t,n){let i=Math.sin(n),o=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*o-s*i,l=r*i+s*o;return[a+t[0],l+t[1]]}function jo(e,t,n){return Qe(e,Ke(We(t,e),n))}function js(e,t,n){return Qe(e,Ke(t,n))}var{min:bn,PI:Kc}=Math,Ws=.275,Zn=Kc+1e-4;function Qc(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=S=>S,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=S=>S*(2-S)}=a,{cap:p=!0,easing:m=S=>--S*S*S+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,E=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,h=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*i,2),x=[],y=[],b=e.slice(0,10).reduce((S,Q)=>{let $=Q.pressure;if(r){let ne=bn(1,Q.distance/n),sn=bn(1,1-ne);$=bn(1,S+(sn-S)*(ne*Ws))}return(S+$)/2},e[0].pressure),w=Ys(n,o,e[e.length-1].pressure,s),I,M=e[0].vector,D=e[0].point,T=D,N=D,C=T,R=!1;for(let S=0;S<e.length;S++){let{pressure:Q}=e[S],{point:$,vector:ne,distance:sn,runningLength:ot}=e[S];if(S<e.length-1&&f-ot<3)continue;if(o){if(r){let xe=bn(1,sn/n),ln=bn(1,1-xe);Q=bn(1,b+(ln-b)*(xe*Ws))}w=Ys(n,o,Q,s)}else w=n/2;I===void 0&&(I=w);let wn=ot<E?u(ot/E):1,ko=f-ot<h?m((f-ot)/h):1;w=Math.max(.01,w*Math.min(wn,ko));let mi=(S<e.length-1?e[S+1]:e[S]).vector,Hn=S<e.length-1?Us(ne,mi):1,Oo=Us(ne,M)<0&&!R,fi=Hn!==null&&Hn<0;if(Oo||fi){let xe=Ke(Vn(M),w);for(let ln=1/13,De=0;De<=1;De+=ln)N=$n(We($,xe),$,Zn*De),x.push(N),C=$n(Qe($,xe),$,Zn*-De),y.push(C);D=N,T=C,fi&&(R=!0);continue}if(R=!1,S===e.length-1){let xe=Ke(Vn(ne),w);x.push(We($,xe)),y.push(Qe($,xe));continue}let an=Ke(Vn(jo(mi,ne,Hn)),w);N=We($,an),(S<=1||Xs(D,N)>g)&&(x.push(N),D=N),C=Qe($,an),(S<=1||Xs(T,C)>g)&&(y.push(C),T=C),b=Q,M=ne}let L=e[0].point.slice(0,2),V=e.length>1?e[e.length-1].point.slice(0,2):Qe(e[0].point,[1,1]),H=[],te=[];if(e.length===1){if(!(E||h)||d){let S=js(L,Vs(Vn(We(L,V))),-(I||w)),Q=[];for(let $=1/13,ne=$;ne<=1;ne+=$)Q.push($n(S,L,Zn*2*ne));return Q}}else{if(!(E||h&&e.length===1))if(c)for(let Q=1/13,$=Q;$<=1;$+=Q){let ne=$n(y[0],L,Zn*$);H.push(ne)}else{let Q=We(x[0],y[0]),$=Ke(Q,.5),ne=Ke(Q,.51);H.push(We(L,$),We(L,ne),Qe(L,ne),Qe(L,$))}let S=Vn(jc(e[e.length-1].vector));if(h||E&&e.length===1)te.push(V);else if(p){let Q=js(V,S,w);for(let $=1/29,ne=$;ne<1;ne+=$)te.push($n(Q,V,Zn*3*ne))}else te.push(Qe(V,Ke(S,w)),Qe(V,Ke(S,w*.99)),We(V,Ke(S,w*.99)),We(V,Ke(S,w)))}return x.concat(te,y.reverse(),H)}function Jc(e,t={}){var n;let{streamline:i=.5,size:o=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-i)*.85,a=Array.isArray(e[0])?e:e.map(({x:m,y:f,pressure:E=.5})=>[m,f,E]);if(a.length===2){let m=a[1];a=a.slice(0,-1);for(let f=1;f<5;f++)a.push(jo(a[0],m,f/4))}a.length===1&&(a=[...a,[...Qe(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=!1,c=0,u=l[0],p=a.length-1;for(let m=1;m<a.length;m++){let f=r&&m===p?a[m].slice(0,2):jo(u.point,a[m],s);if(Vc(u.point,f))continue;let E=qc(f,u.point);if(c+=E,m<p&&!d){if(c<o)continue;d=!0}u={point:f,pressure:a[m][2]>=0?a[m][2]:.5,vector:Vs(We(u.point,f)),distance:E,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function $s(e,t={}){return Qc(Jc(e,t),t)}import{isRightAngleRads as Hm}from"@excalidraw/math";import{BOUND_TEXT_PADDING as fo,DEFAULT_REDUCED_GLOBAL_ALPHA as zm,ELEMENT_READY_TO_ERASE_OPACITY as _m,FRAME_STYLE as ho,MIME_TYPES as zr,THEME as Dl,distance as Qt,getFontString as Ym,isRTL as Um,getVerticalOffset as Xm}from"@excalidraw/common";P();import{pointFrom as xt,pointCenter as eu,pointRotateRads as Ft,vectorFromPoint as Wo,vectorNormalize as Zs,vectorSubtract as qs,vectorAdd as Li,vectorScale as Ci,pointFromVector as Ks,clamp as Ie,isCloseTo as Qs}from"@excalidraw/math";var Se=10,mx=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=Vo(e),c=i/l,u=o/d,p=(e.crop?.x??0)/c,m=(e.crop?.y??0)/u,f=Ft(xt(r,s),fe(e,t),-e.angle);r=f[0],s=f[1];let E=e.width,h=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,y=g.width,b=e.scale[0]===-1,w=e.scale[1]===-1,I=s-e.y,M=r-e.x;n.includes("n")&&(h=Ie(e.height-I,Se,w?d-m:e.height+m)),n.includes("s")&&(I=s-e.y-e.height,h=Ie(e.height+I,Se,w?e.height+m:d-m)),n.includes("e")&&(M=r-e.x-e.width,E=Ie(e.width+M,Se,b?e.width+p:l-p)),n.includes("w")&&(E=Ie(e.width-M,Se,b?l-p:e.width+p));let D=C=>{C.height=h*u,C.width=E*c};D(g);let T=(C,R)=>{D(R),C.includes("n")&&(w||(R.y+=x-R.height)),C.includes("s")&&w&&(R.y+=x-R.height),C.includes("e")&&b&&(R.x+=y-R.width),C.includes("w")&&(b||(R.x+=y-R.width))};switch(n){case"n":{if(a){let C=p+e.width/2,R=l-p-e.width/2,L=Math.min(C,R)*2;E=Ie(h*a,Se,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"s":{if(a){let C=p+e.width/2,R=l-p-e.width/2,L=Math.min(C,R)*2;E=Ie(h*a,Se,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"w":{if(a){let C=m+e.height/2,R=d-m-e.height/2,L=Math.min(C,R)*2;h=Ie(E/a,Se,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let C=m+e.height/2,R=d-m-e.height/2,L=Math.min(C,R)*2;h=Ie(E/a,Se,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(M>-I){let C=w?d-m:m+e.height;h=Ie(E/a,Se,C),E=h*a}else{let C=b?p+e.width:l-p;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"nw":{if(a)if(M<I){let C=w?d-m:m+e.height;h=Ie(E/a,Se,C),E=h*a}else{let C=b?l-p:p+e.width;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"se":{if(a)if(M>I){let C=w?m+e.height:d-m;h=Ie(E/a,Se,C),E=h*a}else{let C=b?p+e.width:l-p;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"sw":{if(a)if(-M>I){let C=w?m+e.height:d-m;h=Ie(E/a,Se,C),E=h*a}else{let C=b?l-p:p+e.width;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}default:break}let N=tu(e,n,E,h,!!a);return Qs(g.width,g.naturalWidth)&&Qs(g.height,g.naturalHeight)&&(g=null),{x:N[0],y:N[1],width:E,height:h,crop:g}},tu=(e,t,n,i,o)=>{let[r,s,a,l]=Nt(e,e.width,e.height,!0),d=xt(r,s),c=xt(a,l),u=eu(d,c),[p,m,f,E]=Nt(e,n,i,!0),h=f-p,g=E-m,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(h),c[1]-Math.abs(g)]),t==="ne"){let D=[d[0],c[1]];x=[D[0],D[1]-Math.abs(g)]}if(t==="sw"){let D=[c[0],d[1]];x=[D[0]-Math.abs(h),D[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-h/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let y=e.angle,b=Ft(x,u,y),w=[x[0]+Math.abs(h)/2,x[1]+Math.abs(g)/2],I=Ft(w,u,y);x=Ft(b,I,-y);let M=[...x];return M[0]+=e.x-p,M[1]+=e.y-m,M},Js=(e,t)=>{if(e.crop){let{width:n,height:i}=Vo(e),[o,r,s,a,l,d]=_(e,t),c=Wo(Ft(xt(o,r),xt(l,d),e.angle)),u=Wo(Ft(xt(s,r),xt(l,d),e.angle)),p=Zs(qs(u,c)),m=Wo(Ft(xt(o,a),xt(l,d),e.angle)),f=qs(m,c),E=Zs(f),{cropX:h,cropY:g}=nu(e.crop,e.scale),x=Li(Li(c,Ci(p,-h*n/e.crop.naturalWidth)),Ci(E,-g*i/e.crop.naturalHeight)),y=Ks(Li(Li(x,Ci(p,n/2)),Ci(E,i/2))),b=Ft(Ks(x),y,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:i,crop:null}}return e},Vo=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}},nu=(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}},fx=(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}=Vo(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as Qa,pointFrom as B,pointRotateRads as Te,pointsEqual as Ja,pointDistance as Cn,vectorFromPoint as nm,curveLength as im,curvePointAtLength as om}from"@excalidraw/math";import{DRAGGING_THRESHOLD as rm,KEYS as Bn,shouldRotateWithDiscreteAngle as el,getGridPoint as tl,invariant as At,tupleToCoors as vr,viewportCoordsToSceneCoords as sm}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as nl,isPathALoop as am}from"@excalidraw/element";P();import{KEYS as Lp,arrayToMap as _a,isBindingFallthroughEnabled as no,tupleToCoors as Cp,invariant as Bp,isDevEnv as Gp,isTestEnv as kp}from"@excalidraw/common";import{lineSegment as Ye,pointFrom as O,pointRotateRads as ae,vectorFromPoint as q,pointDistanceSq as Wt,clamp as Fa,pointDistance as ut,pointFromVector as vn,vectorScale as Ln,vectorNormalize as si,vectorCross as _e,pointsEqual as Op,lineSegmentIntersectionPoints as Na,PRECISION as Rp}from"@excalidraw/math";P();import{isTransparent as Wu}from"@excalidraw/common";import{curveIntersectLineSegment as ba,isPointWithinBounds as Ui,lineSegment as Xi,lineSegmentIntersectionPoints as Pa,pointFrom as St,pointFromVector as Vu,pointRotateRads as lt,pointsEqual as $u,vectorFromPoint as Zu,vectorNormalize as qu,vectorScale as Ku}from"@excalidraw/math";import{ellipse as Qu,ellipseSegmentInterceptPoints as Ju}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as iu,DEFAULT_PROPORTIONAL_RADIUS as $o,LINE_CONFIRM_THRESHOLD as ou,ROUNDNESS as Zo}from"@excalidraw/common";import{curve as wt,curveCatmullRomCubicApproxPoints as ea,curveOffsetPoints as ta,lineSegment as He,pointDistance as ru,pointFrom as X,pointFromArray as su,rectangle as au}from"@excalidraw/math";var qn=new WeakMap,qo=(e,t)=>{let n=qn.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){qn.delete(e);return}return o.get(t)},Ko=(e,t,n)=>{let i=qn.get(e);if(!i){qn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){qn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function Bi(e){let t=qo(e,0);if(t)return t;let n=na(e),i=[],o=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&su(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");i.push(He(X(e.x+l[0],e.y+l[1]),X(e.x+a.data[0],e.y+a.data[1])));continue;case"bcurveTo":if(!l)throw new Error("prevPoint is undefined");o.push(wt(X(e.x+l[0],e.y+l[1]),X(e.x+a.data[0],e.y+a.data[1]),X(e.x+a.data[2],e.y+a.data[3]),X(e.x+a.data[4],e.y+a.data[5])));continue;default:console.error("Unknown op type",a.op)}}let r=[i,o];return Ko(e,r,0),r}function Pn(e,t=0){let n=qo(e,t);if(n)return n;let i=yt(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=au(X(e.x,e.y),X(e.x+e.width,e.y+e.height)),r=He(X(o[0][0]+i,o[0][1]),X(o[1][0]-i,o[0][1])),s=He(X(o[1][0],o[0][1]+i),X(o[1][0],o[1][1]-i)),a=He(X(o[0][0]+i,o[1][1]),X(o[1][0]-i,o[1][1])),l=He(X(o[0][0],o[1][1]-i),X(o[0][0],o[0][1]+i)),d=[wt(l[1],X(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),X(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),wt(r[1],X(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),X(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),wt(s[1],X(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),X(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),wt(a[0],X(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),X(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],c=t>0?d.map(m=>ea(ta(m,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],p=[[He(c[0][c[0].length-1][3],c[1][0][0]),He(c[1][c[1].length-1][3],c[2][0][0]),He(c[2][c[2].length-1][3],c[3][0][0]),He(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Ko(e,p,t),p}function In(e,t=0){let n=qo(e,t);if(n)return n;let[i,o,r,s,a,l,d,c]=Gi(e),u=e.roundness?yt(Math.abs(i-d),e):(i-d)*.01,p=e.roundness?yt(Math.abs(s-o),e):(s-o)*.01,[m,f,E,h]=[X(e.x+i,e.y+o),X(e.x+r,e.y+s),X(e.x+a,e.y+l),X(e.x+d,e.y+c)],g=[wt(X(f[0]-u,f[1]-p),f,f,X(f[0]-u,f[1]+p)),wt(X(E[0]+u,E[1]-p),E,E,X(E[0]-u,E[1]-p)),wt(X(h[0]+u,h[1]+p),h,h,X(h[0]+u,h[1]-p)),wt(X(m[0]-u,m[1]+p),m,m,X(m[0]+u,m[1]+p))],x=t>0?g.map(w=>ea(ta(w,t))):[[g[0]],[g[1]],[g[2]],[g[3]]],b=[[He(x[0][x[0].length-1][3],x[1][0][0]),He(x[1][x[1].length-1][3],x[2][0][0]),He(x[2][x[2].length-1][3],x[3][0][0]),He(x[3][x[3].length-1][3],x[0][0][0])],x.flat()];return Ko(e,b,t),b}var pn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return ru(n,i)<=ou/t}return!1},yt=(e,t)=>{if(t.roundness?.type===Zo.PROPORTIONAL_RADIUS||t.roundness?.type===Zo.LEGACY)return e*$o;if(t.roundness?.type===Zo.ADAPTIVE_RADIUS){let n=t.roundness?.value??iu,i=n/$o;return e<=i?e*$o:n}return 0};P();import{ROUNDNESS as Kn,assertNever as lu}from"@excalidraw/common";import{pointsEqual as ia}from"@excalidraw/math";var Ht=e=>!!e&&e.type==="image"&&!!e.fileId,we=e=>!!e&&e.type==="image",oa=e=>!!e&&e.type==="embeddable",ki=e=>!!e&&e.type==="iframe",Oi=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),ie=e=>e!=null&&e.type==="text",Ri=e=>e!=null&&e.type==="frame",ra=e=>e!=null&&e.type==="magicframe",Z=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Me=e=>e!=null&&du(e.type),du=e=>e==="freedraw",j=e=>e!=null&&Qo(e.type),mn=e=>e!=null&&e.type==="line",Y=e=>e!=null&&e.type==="arrow",G=e=>Y(e)&&e.elbowed,Mx=e=>Y(e)&&!e.elbowed,cu=e=>Y(e)&&!e.elbowed&&!e.roundness,uu=e=>Y(e)&&!e.elbowed&&e.roundness!==null,Qo=e=>e==="arrow"||e==="line",Jo=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&pu(e.type),pu=e=>e==="arrow",Le=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),sa=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),Tx=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"),mu=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||Y(e)),Ax=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 lu(t,null),!1}},er=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",st=e=>mu(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),ce=e=>e!==null&&"containerId"in e&&e.containerId!==null&&ie(e),Dx=e=>!!e.startBinding||!!e.endBinding,aa=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",la=e=>e==="line"||e==="arrow"||e==="diamond",vx=(e,t)=>!!((e===Kn.ADAPTIVE_RADIUS||e===Kn.LEGACY)&&aa(t.type)||e===Kn.PROPORTIONAL_RADIUS&&la(t.type)),Lx=e=>la(e.type)?{type:Kn.PROPORTIONAL_RADIUS}:aa(e.type)?{type:Kn.ADAPTIVE_RADIUS}:null,Qn=e=>Object.hasOwn(e,"fixedPoint")&&e.fixedPoint!=null,Cx=e=>Array.isArray(e)&&e.length===4&&typeof e[0]=="number"&&typeof e[1]=="number"&&typeof e[2]=="number"&&typeof e[3]=="number",Bx=e=>cu(e)?"sharpArrow":uu(e)?"curvedArrow":G(e)?"elbowArrow":"line",Gx=e=>e.length>3&&ia(e[0],e[e.length-1]),da=e=>e.length>3||e.length===3&&!ia(e[0],e[e.length-1]);P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Gu,ARROW_LABEL_WIDTH_FRACTION as ku,BOUND_TEXT_PADDING as at,DEFAULT_FONT_SIZE as Ou,TEXT_ALIGN as Ea,VERTICAL_ALIGN as ga,getFontString as Yi,isProdEnv as Ru,invariant as Fu}from"@excalidraw/common";import{pointFrom as xa,pointRotateRads as Nu}from"@excalidraw/math";P();var Jn={},ca=(e,t)=>{let n=Jn[e]||(Jn[e]={height:t});return n.height=t,n},ua=e=>{Jn[e]&&delete Jn[e]},Rx=e=>Jn[e]?.height??null;P();import{BOUND_TEXT_PADDING as Ni,DEFAULT_FONT_SIZE as fu,DEFAULT_FONT_FAMILY as hu,getFontString as Eu,isTestEnv as gu,normalizeEOL as xu}from"@excalidraw/common";var Je=(e,t,n)=>{let i=e.split(`
1
+ var Sc=Object.create;var Os=Object.defineProperty;var Mc=Object.getOwnPropertyDescriptor;var Ac=Object.getOwnPropertyNames;var Tc=Object.getPrototypeOf,vc=Object.prototype.hasOwnProperty;var Dc=(e,t)=>()=>(e&&(t=e(e=0)),t);var Lc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Bc=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ac(t))!vc.call(e,o)&&o!==n&&Os(e,o,{get:()=>t[o],enumerable:!(i=Mc(t,o))||i.enumerable});return e};var Cc=(e,t,n)=>(n=e!=null?Sc(Tc(e)):{},Bc(t||!e||!e.__esModule?Os(n,"default",{value:e,enumerable:!0}):n,e));var v,P=Dc(()=>{v={PROD:!0}});var Od=Lc((X1,Gd)=>{P();var Cd="Expected a function",Ld=NaN,qf="[object Symbol]",Kf=/^\s+|\s+$/g,Qf=/^[-+]0x[0-9a-f]+$/i,Jf=/^0b[01]+$/i,eh=/^0o[0-7]+$/i,th=parseInt,nh=typeof global=="object"&&global&&global.Object===Object&&global,ih=typeof self=="object"&&self&&self.Object===Object&&self,oh=nh||ih||Function("return this")(),rh=Object.prototype,sh=rh.toString,ah=Math.max,lh=Math.min,fs=function(){return oh.Date.now()};function dh(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(Cd);t=Bd(t)||0,Oo(n)&&(c=!!n.leading,u="maxWait"in n,r=u?ah(Bd(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(I){var S=i,A=o;return i=o=void 0,d=I,s=e.apply(A,S),s}function f(I){return d=I,a=setTimeout(g,t),c?p(I):s}function h(I){var S=I-l,A=I-d,M=t-S;return u?lh(M,r-A):M}function E(I){var S=I-l,A=I-d;return l===void 0||S>=t||S<0||u&&A>=r}function g(){var I=fs();if(E(I))return x(I);a=setTimeout(g,h(I))}function x(I){return a=void 0,m&&i?p(I):(i=o=void 0,s)}function y(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function b(){return a===void 0?s:x(fs())}function w(){var I=fs(),S=E(I);if(i=arguments,o=this,l=I,S){if(a===void 0)return f(l);if(u)return a=setTimeout(g,t),p(l)}return a===void 0&&(a=setTimeout(g,t)),s}return w.cancel=y,w.flush=b,w}function ch(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(Cd);return Oo(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),dh(e,t,{leading:i,maxWait:t,trailing:o})}function Oo(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function uh(e){return!!e&&typeof e=="object"}function mh(e){return typeof e=="symbol"||uh(e)&&sh.call(e)==qf}function Bd(e){if(typeof e=="number")return e;if(mh(e))return Ld;if(Oo(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Oo(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Kf,"");var n=Jf.test(e);return n||eh.test(e)?th(e.slice(2),n?2:8):Qf.test(e)?Ld:+e}Gd.exports=ch});P();import{toIterable as SE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as kt,viewportCoordsToSceneCoords as Lo}from"@excalidraw/common";import{normalizeRadians as ud,radiansBetweenAngles as Mf,radiansDifference as Af}from"@excalidraw/math";import{pointsEqual as Tf}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function Vo(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 Oc(e,t,n){let i=[];e.forEach(o=>i.push(...o)),Vo(i,t,n)}function Rc(e,t){return e[0]===t[0]&&e[1]===t[1]}function Rs(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)Vo(d,a,o);let l=kc(s,r,i);if(o){for(let d of s)Vo(d,a,-o);Oc(l,a,-o)}return l}function kc(e,t,n){let i=[];for(let d of e){let c=[...d];Rc(c[0],c[c.length-1])||c.push([c[0][0],c[0][1]]),c.length>2&&i.push(c)}let o=[];t=Math.max(t,.1);let r=[];for(let d of i)for(let c=0;c<d.length-1;c++){let u=d[c],m=d[c+1];if(u[1]!==m[1]){let p=Math.min(u[1],m[1]);r.push({ymin:p,ymax:Math.max(u[1],m[1]),x:p===u[1]?u[0]:m[0],islope:(m[0]-u[0])/(m[1]-u[1])})}}if(r.sort((d,c)=>d.ymin<c.ymin?-1:d.ymin>c.ymin?1:d.x<c.x?-1:d.x>c.x?1:d.ymax===c.ymax?0:(d.ymax-c.ymax)/Math.abs(d.ymax-c.ymax)),!r.length)return o;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let d=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)d=u;r.splice(0,d+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(d=>!(d.edge.ymax<=a)),s.sort((d,c)=>d.edge.x===c.edge.x?0:(d.edge.x-c.edge.x)/Math.abs(d.edge.x-c.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let d=0;d<s.length;d=d+2){let c=d+1;if(c>=s.length)break;let u=s[d].edge,m=s[c].edge;o.push([[Math.round(u.x),a],[Math.round(m.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.edge.islope}),l++}return o}function lt(e,t){var n;let i=t.hachureAngle+90,o=t.hachureGap;o<0&&(o=t.strokeWidth*4),o=Math.max(o,.1);let r=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(r=o),Rs(e,o,i,r||1)}var zt=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=lt(t,n);return{type:"fillSketch",ops:this.renderLines(i,n)}}renderLines(t,n){let i=[];for(let o of t)i.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return i}};P();P();function _t(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 Ai=class extends zt{fillPolygons(t,n){let i=n.hachureGap;i<0&&(i=n.strokeWidth*4),i=Math.max(i,.1);let o=Object.assign({},n,{hachureGap:i}),r=lt(t,o),s=Math.PI/180*n.hachureAngle,a=[],l=i*.5*Math.cos(s),d=i*.5*Math.sin(s);for(let[u,m]of r)_t([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 Ti=class extends zt{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 vi=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=lt(t,n);return this.dotsOnLines(i,n)}dotsOnLines(t,n){let i=[],o=n.hachureGap;o<0&&(o=n.strokeWidth*4),o=Math.max(o,.1);let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let s=o/4;for(let a of t){let l=_t(a),d=l/o,c=Math.ceil(d)-1,u=l-c*o,m=(a[0][0]+a[1][0])/2-o/4,p=Math.min(a[0][1],a[1][1]);for(let f=0;f<c;f++){let h=p+u+f*o,E=m-s+Math.random()*2*s,g=h-s+Math.random()*2*s,x=this.helper.ellipse(E,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var Di=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=lt(t,n);return{type:"fillSketch",ops:this.dashedLine(i,n)}}dashedLine(t,n){let i=n.dashOffset<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashOffset,o=n.dashGap<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashGap,r=[];return t.forEach(s=>{let a=_t(s),l=Math.floor(a/(i+o)),d=(a+o-l*(i+o))/2,c=s[0],u=s[1];c[0]>u[0]&&(c=s[1],u=s[0]);let m=Math.atan((u[1]-c[1])/(u[0]-c[0]));for(let p=0;p<l;p++){let f=p*(i+o),h=f+i,E=[c[0]+f*Math.cos(m)+d*Math.cos(m),c[1]+f*Math.sin(m)+d*Math.sin(m)],g=[c[0]+h*Math.cos(m)+d*Math.cos(m),c[1]+h*Math.sin(m)+d*Math.sin(m)];r.push(...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],n))}}),r}};P();var Li=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,o=n.zigzagOffset<0?i:n.zigzagOffset;n=Object.assign({},n,{hachureGap:i+o});let r=lt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=_t(r),a=Math.round(s/(2*n)),l=r[0],d=r[1];l[0]>d[0]&&(l=r[1],d=r[0]);let c=Math.atan((d[1]-l[1])/(d[0]-l[0]));for(let u=0;u<a;u++){let m=u*2*n,p=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),h=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],E=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],g=[h[0]+f*Math.cos(c+Math.PI/4),h[1]+f*Math.sin(c+Math.PI/4)];o.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],i),...this.helper.doubleLineOps(g[0],g[1],E[0],E[1],i))}}),o}};var De={};function ks(e,t){let n=e.fillStyle||"hachure";if(!De[n])switch(n){case"zigzag":De[n]||(De[n]=new Ai(t));break;case"cross-hatch":De[n]||(De[n]=new Ti(t));break;case"dots":De[n]||(De[n]=new vi(t));break;case"dashed":De[n]||(De[n]=new Di(t));break;case"zigzag-line":De[n]||(De[n]=new Li(t));break;case"hachure":default:n="hachure",De[n]||(De[n]=new zt(t));break}return De[n]}P();function Fs(){return Math.floor(Math.random()*2**31)}var Bi=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 Ci={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 Fc(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 $o(e,t){return e.type===t}function Mn(e){let t=[],n=Fc(e),i="BOD",o=0,r=n[o];for(;!$o(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=Ci[r.text],i=r.text;else return Mn("M0,0"+e);else $o(r,1)?s=Ci[i]:(o++,s=Ci[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if($o(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof Ci[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 jn(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 Vn(e){let t=[],n="",i=0,o=0,r=0,s=0,a=0,l=0;for(let{key:d,data:c}of e){switch(d){case"M":t.push({key:"M",data:[...c]}),[i,o]=c,[r,s]=c;break;case"C":t.push({key:"C",data:[...c]}),i=c[4],o=c[5],a=c[2],l=c[3];break;case"L":t.push({key:"L",data:[...c]}),[i,o]=c;break;case"H":i=c[0],t.push({key:"L",data:[i,o]});break;case"V":o=c[0],t.push({key:"L",data:[i,o]});break;case"S":{let u=0,m=0;n==="C"||n==="S"?(u=i+(i-a),m=o+(o-l)):(u=i,m=o),t.push({key:"C",data:[u,m,...c]}),a=c[0],l=c[1],i=c[2],o=c[3];break}case"T":{let[u,m]=c,p=0,f=0;n==="Q"||n==="T"?(p=i+(i-a),f=o+(o-l)):(p=i,f=o);let h=i+2*(p-i)/3,E=o+2*(f-o)/3,g=u+2*(p-u)/3,x=m+2*(f-m)/3;t.push({key:"C",data:[h,E,g,x,u,m]}),a=p,l=f,i=u,o=m;break}case"Q":{let[u,m,p,f]=c,h=i+2*(u-i)/3,E=o+2*(m-o)/3,g=p+2*(u-p)/3,x=f+2*(m-f)/3;t.push({key:"C",data:[h,E,g,x,p,f]}),a=u,l=m,i=p,o=f;break}case"A":{let u=Math.abs(c[0]),m=Math.abs(c[1]),p=c[2],f=c[3],h=c[4],E=c[5],g=c[6];u===0||m===0?(t.push({key:"C",data:[i,o,E,g,E,g]}),i=E,o=g):(i!==E||o!==g)&&(Ns(i,o,E,g,u,m,p,f,h).forEach(function(y){t.push({key:"C",data:y})}),i=E,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function Nc(e){return Math.PI*e/180}function Wn(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 Ns(e,t,n,i,o,r,s,a,l,d){let c=Nc(s),u=[],m=0,p=0,f=0,h=0;if(d)[m,p,f,h]=d;else{[e,t]=Wn(e,t,-c),[n,i]=Wn(n,i,-c);let G=(e-n)/2,D=(t-i)/2,V=G*G/(o*o)+D*D/(r*r);V>1&&(V=Math.sqrt(V),o=V*o,r=V*r);let N=a===l?-1:1,Z=o*o,O=r*r,T=Z*O-Z*D*D-O*G*G,j=Z*D*D+O*G*G,$=N*Math.sqrt(Math.abs(T/j));f=$*o*D/r+(e+n)/2,h=$*-r*G/o+(t+i)/2,m=Math.asin(parseFloat(((t-h)/r).toFixed(9))),p=Math.asin(parseFloat(((i-h)/r).toFixed(9))),e<f&&(m=Math.PI-m),n<f&&(p=Math.PI-p),m<0&&(m=Math.PI*2+m),p<0&&(p=Math.PI*2+p),l&&m>p&&(m=m-Math.PI*2),!l&&p>m&&(p=p-Math.PI*2)}let E=p-m;if(Math.abs(E)>Math.PI*120/180){let G=p,D=n,V=i;l&&p>m?p=m+Math.PI*120/180*1:p=m+Math.PI*120/180*-1,n=f+o*Math.cos(p),i=h+r*Math.sin(p),u=Ns(n,i,D,V,o,r,s,0,l,[p,G,f,h])}E=p-m;let g=Math.cos(m),x=Math.sin(m),y=Math.cos(p),b=Math.sin(p),w=Math.tan(E/4),I=4/3*o*w,S=4/3*r*w,A=[e,t],M=[e+I*x,t-S*g],F=[n+I*b,i-S*y],B=[n,i];if(M[0]=2*A[0]-M[0],M[1]=2*A[1]-M[1],d)return[M,F,B].concat(u);{u=[M,F,B].concat(u);let G=[];for(let D=0;D<u.length;D+=3){let V=Wn(u[D][0],u[D][1],c),N=Wn(u[D+1][0],u[D+1][1],c),Z=Wn(u[D+2][0],u[D+2][1],c);G.push([V[0],V[1],N[0],N[1],Z[0],Z[1]])}return G}}var Hc={randOffset:Uc,randOffsetWithRange:Yc,ellipse:_c,doubleLineOps:Xc};function Zo(e,t,n,i,o){return{type:"path",ops:gt(e,t,n,i,o)}}function $n(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 Zo(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function zc(e,t){return $n(e,!0,t)}function Ys(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return zc(r,o)}function qo(e,t){let n=zs(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=zs(e,1.5*(1+t.roughness*.22),jc(t));n=n.concat(i)}return{type:"path",ops:n}}function _c(e,t,n,i,o){let r=Ko(n,i,o);return Ri(e,t,o,r).opset}function Ko(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 Ri(e,t,n,i){let[o,r]=_s(i.increment,e,t,i.rx,i.ry,1,i.increment*Gi(.1,Gi(.4,1,n),n),n),s=Oi(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=_s(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Oi(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Qo(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),m=Math.abs(i/2);u+=R(u*.01,l),m+=R(m*.01,l);let p=o,f=r;for(;p<0;)p+=Math.PI*2,f+=Math.PI*2;f-p>Math.PI*2&&(p=0,f=Math.PI*2);let h=Math.PI*2/l.curveStepCount,E=Math.min(h/2,(f-p)/2),g=Us(E,d,c,u,m,p,f,1,l);if(!l.disableMultiStroke){let x=Us(E,d,c,u,m,p,f,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(f),c+m*Math.sin(f),l)):g.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(p),c+m*Math.sin(p)]})),{type:"path",ops:g}}function Jo(e,t){let n=Vn(jn(Mn(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(...Wc(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 ki(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 fn(e,t){return ks(t,Hc).fillPolygons(e,t)}function Xs(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=R(d*.01,s),c+=R(c*.01,s);let u=o,m=r;for(;u<0;)u+=Math.PI*2,m+=Math.PI*2;m-u>Math.PI*2&&(u=0,m=Math.PI*2);let p=(m-u)/s.curveStepCount,f=[];for(let h=u;h<=m;h=h+p)f.push([a+d*Math.cos(h),l+c*Math.sin(h)]);return f.push([a+d*Math.cos(m),l+c*Math.sin(m)]),f.push([a,l]),fn([f],s)}function Uc(e,t){return R(e,t)}function Yc(e,t,n){return Gi(e,t,n)}function Xc(e,t,n,i,o){return gt(e,t,n,i,o,!0)}function jc(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function js(e){return e.randomizer||(e.randomizer=new Bi(e.seed||0)),e.randomizer.next()}function Gi(e,t,n,i=1){return n.roughness*i*(js(n)*(t-e)+e)}function R(e,t,n=1){return Gi(-e,e,t,n)}function gt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=Hs(e,t,n,i,o,!0,!1);if(s)return a;let l=Hs(e,t,n,i,o,!0,!0);return a.concat(l)}function Hs(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+js(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,f=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=R(p,o,d),f=R(f,o,d);let h=[],E=()=>R(u,o,d),g=()=>R(c,o,d),x=o.preserveVertices;return r&&(s?h.push({op:"move",data:[e+(x?0:E()),t+(x?0:E())]}):h.push({op:"move",data:[e+(x?0:R(c,o,d)),t+(x?0:R(c,o,d))]})),s?h.push({op:"bcurveTo",data:[p+e+(n-e)*m+E(),f+t+(i-t)*m+E(),p+e+2*(n-e)*m+E(),f+t+2*(i-t)*m+E(),n+(x?0:E()),i+(x?0:E())]}):h.push({op:"bcurveTo",data:[p+e+(n-e)*m+g(),f+t+(i-t)*m+g(),p+e+2*(n-e)*m+g(),f+t+2*(i-t)*m+g(),n+(x?0:g()),i+(x?0:g())]}),h}function zs(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 Oi(i,null,n)}function Oi(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 _s(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let m=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(m),c.push(m)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=R(.5,a)-Math.PI/2;c.push([R(r,a)+t+.9*i*Math.cos(u-e),R(r,a)+n+.9*o*Math.sin(u-e)]);let m=Math.PI*2+u-.01;for(let p=u;p<m;p=p+e){let f=[R(r,a)+t+i*Math.cos(p),R(r,a)+n+o*Math.sin(p)];d.push(f),c.push(f)}c.push([R(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),R(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([R(r,a)+t+.98*i*Math.cos(u+s),R(r,a)+n+.98*o*Math.sin(u+s)]),c.push([R(r,a)+t+.9*i*Math.cos(u+s*.5),R(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function Us(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)]),Oi(c,null,l)}function Wc(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 Zn(e){return[...e]}function Ws(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(Zn(e[0]),Zn(e[1]),Zn(e[2]),Zn(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(Zn(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 Vc(e,t){return Math.sqrt(Fi(e,t))}function Fi(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function $c(e,t,n){let i=Fi(t,n);if(i===0)return Fi(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)),Fi(e,hn(t,n,o))}function hn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Zc(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 er(e,t,n,i){let o=i||[];if(Zc(e,t)<n){let r=e[t+0];o.length?Vc(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=hn(s,a,.5),u=hn(a,l,.5),m=hn(l,d,.5),p=hn(c,u,.5),f=hn(u,m,.5),h=hn(p,f,.5);er([s,c,p,h],0,n,o),er([h,f,m,d],0,n,o)}return o}function qn(e,t){return Ni(e,0,e.length,t)}function Ni(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=$c(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(Ni(e,t,d+1,i,r),Ni(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function xt(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;er(e,s,t,i)}return n&&n>0?Ni(i,0,i.length,n):i}P();function Vs(e,t,n){let i=Mn(e),o=Vn(jn(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...xt(l,t)),l=[]},c=()=>{d(),s.length&&(r.push(s),s=[])};for(let{key:m,data:p}of o)switch(m){case"M":c(),a=[p[0],p[1]],s.push(a);break;case"L":d(),s.push([p[0],p[1]]);break;case"C":if(!l.length){let f=s.length?s[s.length-1]:a;l.push([f[0],f[1]])}l.push([p[0],p[1]]),l.push([p[2],p[3]]),l.push([p[4],p[5]]);break;case"Z":d(),s.push([a[0],a[1]]);break}if(c(),!n)return r;let u=[];for(let m of r){let p=qn(m,n);p.length&&u.push(p)}return u}var Ne="none",We=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 Fs()}_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",[Zo(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=Ys(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(ki([d],s)):a.push(fn([d],s))}return s.stroke!==Ne&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=Ko(i,o,s),d=Ri(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Ri(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(fn([d.estimatedPoints],s));return s.stroke!==Ne&&a.push(d.opset),this._d("ellipse",a,s)}circle(t,n,i,o){let r=this.ellipse(t,n,i,i,o);return r.shape="circle",r}linearPath(t,n){let i=this._o(n);return this._d("linearPath",[$n(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=Qo(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=Qo(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(Xs(t,n,i,o,r,s,d));return d.stroke!==Ne&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=qo(t,i);if(i.fill&&i.fill!==Ne&&t.length>=3)if(i.fillStyle==="solid"){let s=qo(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=Ws(t),a=xt(s,10,(1+i.roughness)/2);o.push(fn([a],i))}return i.stroke!==Ne&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=$n(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(ki([t],i)):o.push(fn([t],i))),i.stroke!==Ne&&o.push(r),this._d("polygon",o,i)}path(t,n){let i=this._o(n),o=[];if(!t)return this._d("path",o,i);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=i.fill&&i.fill!=="transparent"&&i.fill!==Ne,s=i.stroke!==Ne,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=Vs(t,1,l),c=Jo(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=Jo(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(ki(d,i));else o.push(fn(d,i));return s&&(a?d.forEach(u=>{o.push($n(u,!1,i))}):o.push(c)),this._d("path",o,i)}opsToPath(t,n){let i="";for(let o of t.ops){let r=typeof n=="number"&&n>=0?o.data.map(s=>+s.toFixed(n)):o.data;switch(o.op){case"move":i+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":i+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":i+=`L${r[0]} ${r[1]} `;break}}return i.trim()}toPaths(t){let n=t.sets||[],i=t.options||this.defaultOptions,o=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:Ne};break;case"fillPath":s={d:this.opsToPath(r),stroke:Ne,strokeWidth:0,fill:i.fill||Ne};break;case"fillSketch":s=this.fillSketch(r,i);break}s&&o.push(s)}return o}fillSketch(t,n){let i=n.fillWeight;return i<0&&(i=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||Ne,strokeWidth:i,fill:Ne}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var Hi=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new We(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 Kn="http://www.w3.org/2000/svg";var zi=class{constructor(t,n){this.svg=t,this.gen=new We(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(Kn,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(Kn,"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(Kn,"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(Kn,"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 En={canvas(e,t){return new Hi(e,t)},svg(e,t){return new zi(e,t)},generator(e){return new We(e)},newSeed(){return We.newSeed()}};import{arrayToMap as dd,invariant as ts,rescalePoints as od,sizeOf as Ef}from"@excalidraw/common";import{degreesToRadians as es,lineSegment as Ee,pointDistance as gf,pointFrom as L,pointFromArray as cd,pointRotateRads as oe}from"@excalidraw/math";P();import{invariant as qc}from"@excalidraw/common";import{curve as Kc,lineSegment as Qc,pointFrom as re,pointDistance as lx,pointFromArray as Jc,pointFromVector as eu,pointRotateRads as Qe,polygon as $s,polygonFromPoints as tr,PRECISION as dx,segmentsIntersectAt as cx,vector as tu,vectorAdd as nu,vectorFromPoint as iu,vectorScale as ux}from"@excalidraw/math";import{getElementAbsoluteCoords as px}from"@excalidraw/element";var Zs=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=re(s,a),d;return e.type==="diamond"?d=$s(Qe(re(s,r),l,t),Qe(re(o+n,a),l,t),Qe(re(s,r+i),l,t),Qe(re(o,a),l,t)):d=$s(Qe(re(o,r),l,t),Qe(re(o+n,r),l,t),Qe(re(o+n,r+i),l,t),Qe(re(o,r+i),l,t)),{type:"polygon",data:d}};var qs=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:re(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},wt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},Ks=(e,t=re(0,0),n,i)=>{let o=l=>Qe(re(l[0]+t[0],l[1]+t[1]),i,n),r=wt(e),s=[],a=re(0,0);for(let l of r){if(l.op==="move"){let d=Jc(l.data);qc(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(re(l.data[0],l.data[1])),c=o(re(l.data[2],l.data[3])),u=o(re(l.data[4],l.data[5]));s.push(Kc(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},ou=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Qc(t,o)),t=o}return n},Qs=(e,t,n=!1)=>{let i=r=>Qe(eu(nu(iu(r),tu(e.x,e.y))),t,e.angle),o=ou(e.points.map(r=>i(r)));return n?{type:"polygon",data:tr(o.flat())}:{type:"polyline",data:o}},Js=(e,t,n=re(0,0),i,o)=>{let r=c=>Qe(re(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:tr(e.points.map(c=>r(c)))};let s=wt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(re(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(re(c.data[0],c.data[1])),a.push(re(c.data[2],c.data[3])),a.push(re(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(re(c.data[0],c.data[1]));let d=xt(a,10,5).map(c=>r(c));return{type:"polygon",data:tr(d)}};P();import{pointFrom as ae,pointDistance as Ql,pointRotateRads as Ot}from"@excalidraw/math";import{ROUGHNESS as df,isTransparent as gi,assertNever as cf,COLOR_PALETTE as uf,LINE_POLYGON_POINT_MERGE_DISTANCE as mf}from"@excalidraw/common";P();P();function ea(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function ru(e){return[-e[0],-e[1]]}function et(e,t){return[e[0]+t[0],e[1]+t[1]]}function Ve(e,t){return[e[0]-t[0],e[1]-t[1]]}function Je(e,t){return[e[0]*t,e[1]*t]}function su(e,t){return[e[0]/t,e[1]/t]}function Qn(e){return[e[1],-e[0]]}function ta(e,t){return e[0]*t[0]+e[1]*t[1]}function au(e,t){return e[0]===t[0]&&e[1]===t[1]}function lu(e){return Math.hypot(e[0],e[1])}function du(e){return e[0]*e[0]+e[1]*e[1]}function na(e,t){return du(Ve(e,t))}function ra(e){return su(e,lu(e))}function cu(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function Jn(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 nr(e,t,n){return et(e,Je(Ve(t,e),n))}function ia(e,t,n){return et(e,Je(t,n))}var{min:An,PI:uu}=Math,oa=.275,ei=uu+1e-4;function mu(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=O=>O,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=O=>O*(2-O)}=a,{cap:m=!0,easing:p=O=>--O*O*O+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,h=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,E=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*i,2),x=[],y=[],b=e.slice(0,10).reduce((O,T)=>{let j=T.pressure;if(r){let $=An(1,T.distance/n),Xe=An(1,1-$);j=An(1,O+(Xe-O)*($*oa))}return(O+j)/2},e[0].pressure),w=ea(n,o,e[e.length-1].pressure,s),I,S=e[0].vector,A=e[0].point,M=A,F=A,B=M,G=!1;for(let O=0;O<e.length;O++){let{pressure:T}=e[O],{point:j,vector:$,distance:Xe,runningLength:at}=e[O];if(O<e.length-1&&f-at<3)continue;if(o){if(r){let Fe=An(1,Xe/n),je=An(1,1-Fe);T=An(1,b+(je-b)*(Fe*oa))}w=ea(n,o,T,s)}else w=n/2;I===void 0&&(I=w);let Pi=at<h?u(at/h):1,jo=f-at<E?p((f-at)/E):1;w=Math.max(.01,w*Math.min(Pi,jo));let Ii=(O<e.length-1?e[O+1]:e[O]).vector,Xn=O<e.length-1?ta($,Ii):1,Wo=ta($,S)<0&&!G,Si=Xn!==null&&Xn<0;if(Wo||Si){let Fe=Je(Qn(S),w);for(let je=1/13,Ht=0;Ht<=1;Ht+=je)F=Jn(Ve(j,Fe),j,ei*Ht),x.push(F),B=Jn(et(j,Fe),j,ei*-Ht),y.push(B);A=F,M=B,Si&&(G=!0);continue}if(G=!1,O===e.length-1){let Fe=Je(Qn($),w);x.push(Ve(j,Fe)),y.push(et(j,Fe));continue}let Mi=Je(Qn(nr(Ii,$,Xn)),w);F=Ve(j,Mi),(O<=1||na(A,F)>g)&&(x.push(F),A=F),B=et(j,Mi),(O<=1||na(M,B)>g)&&(y.push(B),M=B),b=T,S=$}let D=e[0].point.slice(0,2),V=e.length>1?e[e.length-1].point.slice(0,2):et(e[0].point,[1,1]),N=[],Z=[];if(e.length===1){if(!(h||E)||d){let O=ia(D,ra(Qn(Ve(D,V))),-(I||w)),T=[];for(let j=1/13,$=j;$<=1;$+=j)T.push(Jn(O,D,ei*2*$));return T}}else{if(!(h||E&&e.length===1))if(c)for(let T=1/13,j=T;j<=1;j+=T){let $=Jn(y[0],D,ei*j);N.push($)}else{let T=Ve(x[0],y[0]),j=Je(T,.5),$=Je(T,.51);N.push(Ve(D,j),Ve(D,$),et(D,$),et(D,j))}let O=Qn(ru(e[e.length-1].vector));if(E||h&&e.length===1)Z.push(V);else if(m){let T=ia(V,O,w);for(let j=1/29,$=j;$<1;$+=j)Z.push(Jn(T,V,ei*3*$))}else Z.push(et(V,Je(O,w)),et(V,Je(O,w*.99)),Ve(V,Je(O,w*.99)),Ve(V,Je(O,w)))}return x.concat(Z,y.reverse(),N)}function pu(e,t={}){var n;let{streamline:i=.5,size:o=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-i)*.85,a=Array.isArray(e[0])?e:e.map(({x:p,y:f,pressure:h=.5})=>[p,f,h]);if(a.length===2){let p=a[1];a=a.slice(0,-1);for(let f=1;f<5;f++)a.push(nr(a[0],p,f/4))}a.length===1&&(a=[...a,[...et(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=!1,c=0,u=l[0],m=a.length-1;for(let p=1;p<a.length;p++){let f=r&&p===m?a[p].slice(0,2):nr(u.point,a[p],s);if(au(u.point,f))continue;let h=cu(f,u.point);if(c+=h,p<m&&!d){if(c<o)continue;d=!0}u={point:f,pressure:a[p][2]>=0?a[p][2]:.5,vector:ra(Ve(u.point,f)),distance:h,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function sa(e,t={}){return mu(pu(e,t),t)}import{isRightAngleRads as Wp,lineSegment as zl,pointFrom as So,pointRotateRads as qr}from"@excalidraw/math";import{BOUND_TEXT_PADDING as Mo,DEFAULT_REDUCED_GLOBAL_ALPHA as Vp,ELEMENT_READY_TO_ERASE_OPACITY as $p,FRAME_STYLE as Ao,MIME_TYPES as Qr,THEME as Yl,distance as an,getFontString as Zp,isRTL as qp,getVerticalOffset as Kp,invariant as Qp}from"@excalidraw/common";P();import{pointFrom as yt,pointCenter as fu,pointRotateRads as Ut,vectorFromPoint as ir,vectorNormalize as aa,vectorSubtract as la,vectorAdd as _i,vectorScale as Ui,pointFromVector as da,clamp as be,isCloseTo as ca}from"@excalidraw/math";var Pe=10,yx=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=or(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,f=Ut(yt(r,s),fe(e,t),-e.angle);r=f[0],s=f[1];let h=e.width,E=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,y=g.width,b=e.scale[0]===-1,w=e.scale[1]===-1,I=s-e.y,S=r-e.x;n.includes("n")&&(E=be(e.height-I,Pe,w?d-p:e.height+p)),n.includes("s")&&(I=s-e.y-e.height,E=be(e.height+I,Pe,w?e.height+p:d-p)),n.includes("e")&&(S=r-e.x-e.width,h=be(e.width+S,Pe,b?e.width+m:l-m)),n.includes("w")&&(h=be(e.width-S,Pe,b?l-m:e.width+m));let A=B=>{B.height=E*u,B.width=h*c};A(g);let M=(B,G)=>{A(G),B.includes("n")&&(w||(G.y+=x-G.height)),B.includes("s")&&w&&(G.y+=x-G.height),B.includes("e")&&b&&(G.x+=y-G.width),B.includes("w")&&(b||(G.x+=y-G.width))};switch(n){case"n":{if(a){let B=m+e.width/2,G=l-m-e.width/2,D=Math.min(B,G)*2;h=be(E*a,Pe,D),E=h/a}M(n,g),a&&(g.x+=(y-g.width)/2);break}case"s":{if(a){let B=m+e.width/2,G=l-m-e.width/2,D=Math.min(B,G)*2;h=be(E*a,Pe,D),E=h/a}M(n,g),a&&(g.x+=(y-g.width)/2);break}case"w":{if(a){let B=p+e.height/2,G=d-p-e.height/2,D=Math.min(B,G)*2;E=be(h/a,Pe,D),h=E*a}M(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let B=p+e.height/2,G=d-p-e.height/2,D=Math.min(B,G)*2;E=be(h/a,Pe,D),h=E*a}M(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(S>-I){let B=w?d-p:p+e.height;E=be(h/a,Pe,B),h=E*a}else{let B=b?m+e.width:l-m;h=be(E*a,Pe,B),E=h/a}M(n,g);break}case"nw":{if(a)if(S<I){let B=w?d-p:p+e.height;E=be(h/a,Pe,B),h=E*a}else{let B=b?l-m:m+e.width;h=be(E*a,Pe,B),E=h/a}M(n,g);break}case"se":{if(a)if(S>I){let B=w?p+e.height:d-p;E=be(h/a,Pe,B),h=E*a}else{let B=b?m+e.width:l-m;h=be(E*a,Pe,B),E=h/a}M(n,g);break}case"sw":{if(a)if(-S>I){let B=w?p+e.height:d-p;E=be(h/a,Pe,B),h=E*a}else{let B=b?l-m:m+e.width;h=be(E*a,Pe,B),E=h/a}M(n,g);break}default:break}let F=hu(e,n,h,E,!!a);return ca(g.width,g.naturalWidth)&&ca(g.height,g.naturalHeight)&&(g=null),{x:F[0],y:F[1],width:h,height:E,crop:g}},hu=(e,t,n,i,o)=>{let[r,s,a,l]=Yt(e,e.width,e.height,!0),d=yt(r,s),c=yt(a,l),u=fu(d,c),[m,p,f,h]=Yt(e,n,i,!0),E=f-m,g=h-p,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(E),c[1]-Math.abs(g)]),t==="ne"){let A=[d[0],c[1]];x=[A[0],A[1]-Math.abs(g)]}if(t==="sw"){let A=[c[0],d[1]];x=[A[0]-Math.abs(E),A[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-E/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let y=e.angle,b=Ut(x,u,y),w=[x[0]+Math.abs(E)/2,x[1]+Math.abs(g)/2],I=Ut(w,u,y);x=Ut(b,I,-y);let S=[...x];return S[0]+=e.x-m,S[1]+=e.y-p,S},ua=(e,t)=>{if(e.crop){let{width:n,height:i}=or(e),[o,r,s,a,l,d]=X(e,t),c=ir(Ut(yt(o,r),yt(l,d),e.angle)),u=ir(Ut(yt(s,r),yt(l,d),e.angle)),m=aa(la(u,c)),p=ir(Ut(yt(o,a),yt(l,d),e.angle)),f=la(p,c),h=aa(f),{cropX:E,cropY:g}=Eu(e.crop,e.scale),x=_i(_i(c,Ui(m,-E*n/e.crop.naturalWidth)),Ui(h,-g*i/e.crop.naturalHeight)),y=da(_i(_i(x,Ui(m,n/2)),Ui(h,i/2))),b=Ut(da(x),y,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:i,crop:null}}return e},or=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}},Eu=(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}},bx=(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}=or(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as ll,pointFrom as C,pointRotateRads as Ae,pointsEqual as dl,pointDistance as nn,vectorFromPoint as lp,curveLength as dp,curvePointAtLength as cp,lineSegment as up}from"@excalidraw/math";import{DRAGGING_THRESHOLD as mp,KEYS as In,shouldRotateWithDiscreteAngle as zr,getGridPoint as cl,invariant as Te,isShallowEqual as pp,getFeatureFlag as hi}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as ul,getHoveredElementForBinding as ml,isPathALoop as fp,moveArrowAboveBindable as pl,projectFixedPointOntoDiagonal as fl}from"@excalidraw/element";P();import{KEYS as $m,arrayToMap as el,getFeatureFlag as Zm,invariant as ot,isTransparent as qm}from"@excalidraw/common";import{PRECISION as Km,clamp as Nr,lineSegment as mi,pointDistance as Bt,pointDistanceSq as ui,pointFrom as ne,pointFromVector as On,pointRotateRads as pe,vectorFromPoint as kn,vectorNormalize as po,vectorScale as Rn}from"@excalidraw/math";P();import{invariant as cm,isTransparent as ka}from"@excalidraw/common";import{curveIntersectLineSegment as Fa,isPointWithinBounds as Ji,lineSegment as si,lineSegmentIntersectionPoints as Na,pointFrom as ce,pointFromVector as um,pointRotateRads as ze,pointsEqual as mm,vectorFromPoint as pm,vectorNormalize as fm,vectorScale as hm}from"@excalidraw/math";import{ellipse as Em,ellipseSegmentInterceptPoints as gm}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as Su,DEFAULT_PROPORTIONAL_RADIUS as lr,invariant as Mu,LINE_CONFIRM_THRESHOLD as Au,ROUNDNESS as dr}from"@excalidraw/common";import{curve as Pt,curveCatmullRomCubicApproxPoints as ya,curveOffsetPoints as ba,lineSegment as he,lineSegmentIntersectionPoints as xa,pointDistance as Tn,pointFrom as z,pointFromArray as Tu,pointFromVector as vu,pointRotateRads as jt,pointTranslate as wa,rectangle as Du,vectorFromPoint as Pa,vectorNormalize as Lu,vectorScale as cr}from"@excalidraw/math";P();import{ROUNDNESS as ti,assertNever as gu}from"@excalidraw/common";import{pointsEqual as ma}from"@excalidraw/math";var Xt=e=>!!e&&e.type==="image"&&!!e.fileId,xe=e=>!!e&&e.type==="image",pa=e=>!!e&&e.type==="embeddable",Yi=e=>!!e&&e.type==="iframe",Xi=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),J=e=>e!=null&&e.type==="text",ji=e=>e!=null&&e.type==="frame",fa=e=>e!=null&&e.type==="magicframe",q=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Ie=e=>e!=null&&xu(e.type),xu=e=>e==="freedraw",K=e=>e!=null&&bu(e.type),bt=e=>e!=null&&e.type==="line",H=e=>e!=null&&e.type==="arrow",U=e=>H(e)&&e.elbowed,Ax=e=>H(e)&&!e.elbowed,wu=e=>H(e)&&!e.elbowed&&!e.roundness,yu=e=>H(e)&&!e.elbowed&&e.roundness!==null,bu=e=>e==="arrow"||e==="line",Le=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&Pu(e.type),Pu=e=>e==="arrow",He=(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),rr=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),sr=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"),Iu=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||H(e)),Tx=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 gu(t,null),!1}},ar=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",dt=e=>Iu(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),le=e=>e!==null&&"containerId"in e&&e.containerId!==null&&J(e),vx=e=>!!e.startBinding||!!e.endBinding,ha=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",Ea=e=>e==="line"||e==="arrow"||e==="diamond",Dx=(e,t)=>!!((e===ti.ADAPTIVE_RADIUS||e===ti.LEGACY)&&ha(t.type)||e===ti.PROPORTIONAL_RADIUS&&Ea(t.type)),Lx=e=>Ea(e.type)?{type:ti.PROPORTIONAL_RADIUS}:ha(e.type)?{type:ti.ADAPTIVE_RADIUS}:null,Bx=e=>Array.isArray(e)&&e.length===4&&typeof e[0]=="number"&&typeof e[1]=="number"&&typeof e[2]=="number"&&typeof e[3]=="number",Cx=e=>wu(e)?"sharpArrow":yu(e)?"curvedArrow":U(e)?"elbowArrow":"line",Gx=e=>e.length>3&&ma(e[0],e[e.length-1]),ga=e=>e.length>3||e.length===3&&!ma(e[0],e[e.length-1]);var ni=new WeakMap,ur=(e,t)=>{let n=ni.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){ni.delete(e);return}return o.get(t)},mr=(e,t,n)=>{let i=ni.get(e);if(!i){ni.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){ni.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function Wi(e){let t=ur(e,0);if(t)return t;let n=Sa(e),i=[],o=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&Tu(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");i.push(he(z(e.x+l[0],e.y+l[1]),z(e.x+a.data[0],e.y+a.data[1])));continue;case"bcurveTo":if(!l)throw new Error("prevPoint is undefined");o.push(Pt(z(e.x+l[0],e.y+l[1]),z(e.x+a.data[0],e.y+a.data[1]),z(e.x+a.data[2],e.y+a.data[3]),z(e.x+a.data[4],e.y+a.data[5])));continue;default:console.error("Unknown op type",a.op)}}let r=[i,o];return mr(e,r,0),r}function vn(e,t=0){let n=ur(e,t);if(n)return n;let i=It(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=Du(z(e.x,e.y),z(e.x+e.width,e.y+e.height)),r=he(z(o[0][0]+i,o[0][1]),z(o[1][0]-i,o[0][1])),s=he(z(o[1][0],o[0][1]+i),z(o[1][0],o[1][1]-i)),a=he(z(o[0][0]+i,o[1][1]),z(o[1][0]-i,o[1][1])),l=he(z(o[0][0],o[1][1]-i),z(o[0][0],o[0][1]+i)),d=[Pt(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]),Pt(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]),Pt(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]),Pt(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=>ya(ba(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[he(c[0][c[0].length-1][3],c[1][0][0]),he(c[1][c[1].length-1][3],c[2][0][0]),he(c[2][c[2].length-1][3],c[3][0][0]),he(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return mr(e,m,t),m}function Dn(e,t=0){let n=ur(e,t);if(n)return n;let[i,o,r,s,a,l,d,c]=Ln(e),u=e.roundness?It(Math.abs(i-d),e):(i-d)*.01,m=e.roundness?It(Math.abs(s-o),e):(s-o)*.01,[p,f,h,E]=[z(e.x+i,e.y+o),z(e.x+r,e.y+s),z(e.x+a,e.y+l),z(e.x+d,e.y+c)],x=[Pt(z(f[0]-u,f[1]-m),f,f,z(f[0]-u,f[1]+m)),Pt(z(h[0]+u,h[1]-m),h,h,z(h[0]-u,h[1]-m)),Pt(z(E[0]+u,E[1]+m),E,E,z(E[0]+u,E[1]-m)),Pt(z(p[0]-u,p[1]+m),p,p,z(p[0]+u,p[1]+m))].map(w=>ya(ba(w,t))),b=[[he(x[0][x[0].length-1][3],x[1][0][0]),he(x[1][x[1].length-1][3],x[2][0][0]),he(x[2][x[2].length-1][3],x[3][0][0]),he(x[3][x[3].length-1][3],x[0][0][0])],x.flat()];return mr(e,b,t),b}var gn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return Tn(n,i)<=Au/t}return!1},It=(e,t)=>{if(t.roundness?.type===dr.PROPORTIONAL_RADIUS||t.roundness?.type===dr.LEGACY)return e*lr;if(t.roundness?.type===dr.ADAPTIVE_RADIUS){let n=t.roundness?.value??Su,i=n/lr;return e<=i?e*lr:n}return 0},Bu=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=Lu(Pa(a[1],a[0])),d=cr(l,n);return he(wa(a[0],d),wa(a[1],cr(d,-1)))},o=fe(e,t),r=i(sr(e)?he(jt(z(e.x,e.y),o,e.angle),jt(z(e.x+e.width,e.y+e.height),o,e.angle)):he(jt(z(e.x+e.width/2,e.y),o,e.angle),jt(z(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(sr(e)?he(jt(z(e.x+e.width,e.y),o,e.angle),jt(z(e.x,e.y+e.height),o,e.angle)):he(jt(z(e.x,e.y+e.height/2),o,e.angle),jt(z(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},Ia=(e,t,n,i,o)=>{if(Mu(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;let[r,s]=Bu(n,o),a=k.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o),l=vu(cr(Pa(t,a),2*Tn(a,t)+Math.max(Tn(r[0],r[1]),Tn(s[0],s[1]))),a),d=he(t,l),c=xa(r,d),u=xa(s,d),m=c&&Tn(a,c),p=u&&Tn(a,u),f=null;return m!=null&&p!=null?f=m<p?c:u:f=c||u||null,f&&Wt(f,n,o)?f:null};P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Ku,ARROW_LABEL_WIDTH_FRACTION as Qu,BOUND_TEXT_PADDING as ct,DEFAULT_FONT_SIZE as Ju,TEXT_ALIGN as Ba,VERTICAL_ALIGN as Ca,getFontString as Qi,isProdEnv as em,invariant as tm}from"@excalidraw/common";import{pointFrom as Ga,pointRotateRads as nm}from"@excalidraw/math";P();var ii={},Ma=(e,t)=>{let n=ii[e]||(ii[e]={height:t});return n.height=t,n},Aa=e=>{ii[e]&&delete ii[e]},jx=e=>ii[e]?.height??null;P();import{BOUND_TEXT_PADDING as $i,DEFAULT_FONT_SIZE as Cu,DEFAULT_FONT_FAMILY as Gu,getFontString as Ou,isTestEnv as Ru,normalizeEOL as ku}from"@excalidraw/common";var tt=(e,t,n)=>{let i=e.split(`
2
2
  `).map(a=>a||" ").join(`
3
- `),o=parseFloat(t),r=wu(i,o,n);return{width:ha(i,t),height:r}},pa="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),ma=(e,t)=>{let n=yu(e);return n===0?Je(pa.split("").join(`
4
- `),e,t).width+Ni*2:n+Ni*2},Hi=(e,t)=>Je("",e,t).width+Ni*2,zx=()=>ha(pa,Eu({fontSize:fu,fontFamily:hu}))>0,nr=e=>xu(e).replace(/\t/g," "),ir=e=>nr(e).split(`
5
- `),_x=e=>{let t=ir(e.text).length;return e.height/t/e.fontSize},zi=(e,t)=>e*t,fa=(e,t)=>zi(e,t)+Ni*2,Fi,Yx=e=>{Fi=e},tr=class{canvas;constructor(){this.canvas=document.createElement("canvas")}getLineWidth(t,n){let i=this.canvas.getContext("2d");i.font=n;let r=i.measureText(t).width;return gu()?r*10:r}},zt=(e,t)=>(Fi||(Fi=new tr),Fi.getLineWidth(e,t)),ha=(e,t)=>{let n=ir(e),i=0;return n.forEach(o=>{i=Math.max(i,zt(o,t))}),i},wu=(e,t,n)=>{let i=ir(e).length;return zi(t,n)*i},Sn=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=zt(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),Ux=e=>{let t=Sn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},yu=e=>{let t=Sn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as bu,isTestEnv as Pu}from"@excalidraw/common";var or,_i,rr,$x=e=>(or||(or=J.class(...Object.values(bt))),or.test(e)),Iu=()=>{if(!_i)try{_i=Mu()}catch{_i=Su()}return _i},sr=()=>(rr||(rr=Tu()),rr),Ve={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},bt={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},fn={FLAG:/\p{RI}\p{RI}/u,JOINER:/(?:\p{Emoji_Modifier}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?/u,ZWJ:/\u200D/u,ANY:/[\p{Emoji}]/u,MOST:/[\p{Extended_Pictographic}\p{Emoji_Presentation}]/u},Su=()=>J.or(sr(),ue.On(Ve.HYPHEN,Ve.WHITESPACE,bt.CHAR)),Mu=()=>J.or(sr(),ue.Before(Ve.WHITESPACE).Build(),ue.After(Ve.WHITESPACE,Ve.HYPHEN).Build(),ue.Before(bt.CHAR,bt.CURRENCY).NotPrecededBy(Ve.OPENING,bt.OPENING).Build(),ue.After(bt.CHAR).NotFollowedBy(Ve.HYPHEN,Ve.CLOSING,bt.CLOSING).Build(),ue.BeforeMany(bt.OPENING).NotPrecededBy(Ve.OPENING).Build(),ue.AfterMany(bt.CLOSING).NotFollowedBy(Ve.CLOSING).Build(),ue.AfterMany(Ve.CLOSING).FollowedBy(Ve.OPENING).Build()),Tu=()=>J.group(J.or(fn.FLAG,J.and(fn.MOST,fn.JOINER,J.build(`(?:${fn.ZWJ.source}(?:${fn.FLAG.source}|${fn.ANY.source}${fn.JOINER.source}))*`)))),J={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>J.build(J.join(...e)),or:(...e)=>J.build(e.map(t=>t.source).join("|")),group:(...e)=>J.build(`(${J.join(...e)})`),class:(...e)=>J.build(`[${J.join(...e)}]`)},ue={On:(...e)=>{let t=J.join(...e);return J.build(`([${t}])`)},Before:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?=[${t}])`);return ue.Chain(n)},After:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<=[${t}])`);return ue.Chain(n)},BeforeMany:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<![${t}])(?=[${t}])`);return ue.Chain(n)},AfterMany:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<=[${t}])(?![${t}])`);return ue.Chain(n)},NotBefore:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?![${t}])`);return ue.Chain(n)},NotAfter:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<![${t}])`);return ue.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=ue.After(...t).Build(),o=()=>J.and(i,n);return ue.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=ue.Before(...t).Build(),o=()=>J.and(n,i);return ue.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=ue.NotAfter(...t).Build(),o=()=>J.and(i,n);return ue.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=ue.NotBefore(...t).Build(),o=()=>J.and(n,i);return ue.Chain(o)}})},Au=e=>{let t=Iu();return e.normalize("NFC").split(t).filter(Boolean)},Pt=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return e;let i=[],o=e.split(`
6
- `);for(let r of o){if(zt(r,t)<=n){i.push(r);continue}let a=Du(r,t,n);i.push(...a)}return i.join(`
7
- `)},Du=(e,t,n)=>{let i=[],r=Au(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let d=l.value,c=s+d,u=Cu(d)?a+Sn.calculate(d,t):zt(c,t);if(/\s/.test(d)||u<=n){s=c,a=u,l=r.next();continue}if(s)i.push(s.trimEnd()),s="",a=0;else{let p=vu(d,t,n),m=p[p.length-1]??"",f=p.slice(0,-1);i.push(...f),s=m,a=zt(m,t),l=r.next()}}if(s){let d=Lu(s,t,n);i.push(d)}return i},vu=(e,t,n)=>{if(sr().test(e))return[e];Bu(e);let i=[],o=Array.from(e),r="",s=0;for(let a of o){let l=Sn.calculate(a,t),d=s+l;if(d<=n){r=r+a,s=d;continue}r&&i.push(r),r=a,s=l}return r&&i.push(r),i},Lu=(e,t,n)=>{if(!(zt(e,t)>n))return e;let[,o,r]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],s=zt(o,t);for(let a of Array.from(r)){let l=Sn.calculate(a,t),d=s+l;if(d>n)break;o=o+a,s=d}return o},Cu=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Bu=e=>{if((Pu()||bu())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var wa=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;Ru()||Fu(!t||!Y(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?Y(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?et(t,e):e.width,r.text=Pt(e.originalText,Yi(e),o));let s=Je(r.text,Yi(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=ti(t,e),l=et(t,e);if(!Y(t)&&s.height>a){let p=ar(s.height,t.type);n.mutateElement(t,{height:p}),ca(t.id,p)}if(s.width>l){let p=ar(s.width,t.type);n.mutateElement(t,{width:p})}let d={...e,...r},{x:c,y:u}=ei(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},hn=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!It(e))return;ua(e.id);let s=W(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=et(e,s),u=ti(e,s),p=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=Pt(s.originalText,Yi(s),c));let m=Je(a,Yi(s),s.lineHeight);l=m.height,d=m.width}if(l>u){p=ar(l,e.type);let m=p-e.height,f=!Y(e)&&(n==="ne"||n==="nw"||n==="n")?e.y-m:e.y;t.mutateElement(e,{height:p,y:f})}t.mutateElement(s,{text:a,width:d,height:l}),Y(e)||t.mutateElement(s,ei(e,s,o))}},ei=(e,t,n)=>{if(Y(e))return U.getBoundTextElementPosition(e,t,n);let i=lr(e),o=ti(e,t),r=et(e,t),s,a;t.verticalAlign===ga.TOP?a=i.y:t.verticalAlign===ga.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===Ea.LEFT?s=i.x:t.textAlign===Ea.RIGHT?s=i.x+(r-t.width):s=i.x+(r/2-t.width/2);let l=e.angle??0;if(l!==0){let d=xa(i.x+r/2,i.y+o/2),c=xa(s+t.width/2,a+t.height/2),[u,p]=Nu(c,d,l);return{x:u-t.width/2,y:p-t.height/2}}return{x:s,y:a}},It=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,W=(e,t)=>{if(!e)return null;let n=It(e);return n&&t.get(n)||null},Ce=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,ow=(e,t,n)=>{if(!Y(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(U.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=U.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=U.getEditorMidPoints(e,n,t)[o];return r||(r=U.getSegmentMidPoint(e,o+1)),{x:r[0],y:r[1]}},lr=e=>{let t=at,n=at;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},rw=(e,t)=>Y(t)?0:t?t.angle:e.angle,sw=(e,t,n)=>{if(Y(e))return U.getBoundTextElementPosition(e,t,n)},aw=(e,t)=>e.some(n=>{if(ce(n)){let i=Ce(n,t);return!Y(i)}return!1}),lw=(e,t)=>e.some(n=>{if(ce(n)){let i=Ce(n,t);return!Y(i)}return ie(n)}),Hu=new Set(["rectangle","ellipse","diamond","arrow"]),dw=e=>Hu.has(e.type),ar=(e,t)=>{e=Math.ceil(e);let n=at*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},et=(e,t)=>{let{width:n}=e;if(Y(e)){let i=(t?.fontSize??Ou)*Gu;return Math.max(ku*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-at*2:e.type==="diamond"?Math.round(n/2)-at*2:n-at*2},ti=(e,t)=>{let{height:n}=e;return Y(e)?n-at*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-at*2:e.type==="diamond"?Math.round(n/2)-at*2:n-at*2},cw=(e,t=`
3
+ `),o=parseFloat(t),r=Fu(i,o,n);return{width:La(i,t),height:r}},Ta="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),va=(e,t)=>{let n=Nu(e);return n===0?tt(Ta.split("").join(`
4
+ `),e,t).width+$i*2:n+$i*2},Zi=(e,t)=>tt("",e,t).width+$i*2,Zx=()=>La(Ta,Ou({fontSize:Cu,fontFamily:Gu}))>0,fr=e=>ku(e).replace(/\t/g," "),hr=e=>fr(e).split(`
5
+ `),qx=e=>{let t=hr(e.text).length;return e.height/t/e.fontSize},qi=(e,t)=>e*t,Da=(e,t)=>qi(e,t)+$i*2,Vi,Kx=e=>{Vi=e},pr=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 Ru()?r*10:r}},Vt=(e,t)=>(Vi||(Vi=new pr),Vi.getLineWidth(e,t)),La=(e,t)=>{let n=hr(e),i=0;return n.forEach(o=>{i=Math.max(i,Vt(o,t))}),i},Fu=(e,t,n)=>{let i=hr(e).length;return qi(t,n)*i},Bn=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=Vt(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),Qx=e=>{let t=Bn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},Nu=e=>{let t=Bn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as Hu,isTestEnv as zu}from"@excalidraw/common";var Er,Ki,gr,iw=e=>(Er||(Er=ee.class(...Object.values(St))),Er.test(e)),_u=()=>{if(!Ki)try{Ki=Yu()}catch{Ki=Uu()}return Ki},xr=()=>(gr||(gr=Xu()),gr),$e={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},St={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},xn={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},Uu=()=>ee.or(xr(),de.On($e.HYPHEN,$e.WHITESPACE,St.CHAR)),Yu=()=>ee.or(xr(),de.Before($e.WHITESPACE).Build(),de.After($e.WHITESPACE,$e.HYPHEN).Build(),de.Before(St.CHAR,St.CURRENCY).NotPrecededBy($e.OPENING,St.OPENING).Build(),de.After(St.CHAR).NotFollowedBy($e.HYPHEN,$e.CLOSING,St.CLOSING).Build(),de.BeforeMany(St.OPENING).NotPrecededBy($e.OPENING).Build(),de.AfterMany(St.CLOSING).NotFollowedBy($e.CLOSING).Build(),de.AfterMany($e.CLOSING).FollowedBy($e.OPENING).Build()),Xu=()=>ee.group(ee.or(xn.FLAG,ee.and(xn.MOST,xn.JOINER,ee.build(`(?:${xn.ZWJ.source}(?:${xn.FLAG.source}|${xn.ANY.source}${xn.JOINER.source}))*`)))),ee={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>ee.build(ee.join(...e)),or:(...e)=>ee.build(e.map(t=>t.source).join("|")),group:(...e)=>ee.build(`(${ee.join(...e)})`),class:(...e)=>ee.build(`[${ee.join(...e)}]`)},de={On:(...e)=>{let t=ee.join(...e);return ee.build(`([${t}])`)},Before:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?=[${t}])`);return de.Chain(n)},After:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?<=[${t}])`);return de.Chain(n)},BeforeMany:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?<![${t}])(?=[${t}])`);return de.Chain(n)},AfterMany:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?<=[${t}])(?![${t}])`);return de.Chain(n)},NotBefore:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?![${t}])`);return de.Chain(n)},NotAfter:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?<![${t}])`);return de.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=de.After(...t).Build(),o=()=>ee.and(i,n);return de.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=de.Before(...t).Build(),o=()=>ee.and(n,i);return de.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=de.NotAfter(...t).Build(),o=()=>ee.and(i,n);return de.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=de.NotBefore(...t).Build(),o=()=>ee.and(n,i);return de.Chain(o)}})},ju=e=>{let t=_u();return e.normalize("NFC").split(t).filter(Boolean)},Mt=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return e;let i=[],o=e.split(`
6
+ `);for(let r of o){if(Vt(r,t)<=n){i.push(r);continue}let a=Wu(r,t,n);i.push(...a)}return i.join(`
7
+ `)},Wu=(e,t,n)=>{let i=[],r=ju(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let d=l.value,c=s+d,u=Zu(d)?a+Bn.calculate(d,t):Vt(c,t);if(/\s/.test(d)||u<=n){s=c,a=u,l=r.next();continue}if(s)i.push(s.trimEnd()),s="",a=0;else{let m=Vu(d,t,n),p=m[m.length-1]??"",f=m.slice(0,-1);i.push(...f),s=p,a=Vt(p,t),l=r.next()}}if(s){let d=$u(s,t,n);i.push(d)}return i},Vu=(e,t,n)=>{if(xr().test(e))return[e];qu(e);let i=[],o=Array.from(e),r="",s=0;for(let a of o){let l=Bn.calculate(a,t),d=s+l;if(d<=n){r=r+a,s=d;continue}r&&i.push(r),r=a,s=l}return r&&i.push(r),i},$u=(e,t,n)=>{if(!(Vt(e,t)>n))return e;let[,o,r]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],s=Vt(o,t);for(let a of Array.from(r)){let l=Bn.calculate(a,t),d=s+l;if(d>n)break;o=o+a,s=d}return o},Zu=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,qu=e=>{if((zu()||Hu())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var Oa=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;em()||tm(!t||!H(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?H(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?nt(t,e):e.width,r.text=Mt(e.originalText,Qi(e),o));let s=tt(r.text,Qi(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=ri(t,e),l=nt(t,e);if(!H(t)&&s.height>a){let m=wr(s.height,t.type);n.mutateElement(t,{height:m}),Ma(t.id,m)}if(s.width>l){let m=wr(s.width,t.type);n.mutateElement(t,{width:m})}let d={...e,...r},{x:c,y:u}=oi(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},wn=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!At(e))return;Aa(e.id);let s=W(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=nt(e,s),u=ri(e,s),m=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=Mt(s.originalText,Qi(s),c));let p=tt(a,Qi(s),s.lineHeight);l=p.height,d=p.width}if(l>u){m=wr(l,e.type);let p=m-e.height,f=!H(e)&&(n==="ne"||n==="nw"||n==="n")?e.y-p:e.y;t.mutateElement(e,{height:m,y:f})}t.mutateElement(s,{text:a,width:d,height:l}),H(e)||t.mutateElement(s,oi(e,s,o))}},oi=(e,t,n)=>{if(H(e))return k.getBoundTextElementPosition(e,t,n);let i=yr(e),o=ri(e,t),r=nt(e,t),s,a;t.verticalAlign===Ca.TOP?a=i.y:t.verticalAlign===Ca.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===Ba.LEFT?s=i.x:t.textAlign===Ba.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=Ga(i.x+r/2,i.y+o/2),c=Ga(s+t.width/2,a+t.height/2),[u,m]=nm(c,d,l);return{x:u-t.width/2,y:m-t.height/2}}return{x:s,y:a}},At=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,W=(e,t)=>{if(!e)return null;let n=At(e);return n&&t.get(n)||null},Se=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,pw=(e,t,n)=>{if(!H(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(k.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=k.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=k.getEditorMidPoints(e,n,t)[o];return r||(r=k.getSegmentMidPoint(e,o+1)),{x:r[0],y:r[1]}},yr=e=>{let t=ct,n=ct;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},fw=(e,t)=>H(t)?0:t?t.angle:e.angle,hw=(e,t,n)=>{if(H(e))return k.getBoundTextElementPosition(e,t,n)},Ew=(e,t)=>e.some(n=>{if(le(n)){let i=Se(n,t);return!H(i)}return!1}),gw=(e,t)=>e.some(n=>{if(le(n)){let i=Se(n,t);return!H(i)}return J(n)}),im=new Set(["rectangle","ellipse","diamond","arrow"]),xw=e=>im.has(e.type),wr=(e,t)=>{e=Math.ceil(e);let n=ct*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},nt=(e,t)=>{let{width:n}=e;if(H(e)){let i=(t?.fontSize??Ju)*Ku;return Math.max(Qu*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-ct*2:e.type==="diamond"?Math.round(n/2)-ct*2:n-ct*2},ri=(e,t)=>{let{height:n}=e;return H(e)?n-ct*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-ct*2:e.type==="diamond"?Math.round(n/2)-ct*2:n-ct*2},ww=(e,t=`
8
8
 
9
- `)=>e.reduce((i,o)=>(ie(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as dr,distanceToLineSegment as cr,pointRotateRads as ur}from"@excalidraw/math";import{ellipse as zu,ellipseDistanceFromPoint as _u}from"@excalidraw/math/ellipse";var _t=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return Yu(e,t,n);case"diamond":return Uu(e,t,n);case"ellipse":return Xu(e,t,n);case"line":case"arrow":case"freedraw":return ju(e,n)}},Yu=(e,t,n)=>{let i=fe(e,t),o=ur(n,i,-e.angle),[r,s]=Pn(e);return Math.min(...r.map(a=>cr(o,a)),...s.map(a=>dr(a,o)).filter(a=>a!==null))},Uu=(e,t,n)=>{let i=fe(e,t),o=ur(n,i,-e.angle),[r,s]=In(e);return Math.min(...r.map(a=>cr(o,a)),...s.map(a=>dr(a,o)).filter(a=>a!==null))},Xu=(e,t,n)=>{let i=fe(e,t);return _u(ur(n,i,-e.angle),zu(i,e.width/2,e.height/2))},ju=(e,t)=>{let[n,i]=Bi(e);return Math.min(...n.map(o=>cr(t,o)),...i.map(o=>dr(o,t)))};var ji=e=>{if(e.type==="arrow")return!1;let t=!Wu(e.backgroundColor)||st(e)||Oi(e)||ie(e);return e.type==="line"?t&&pn(e.points):e.type==="freedraw"?t&&pn(e.points):t||we(e)},ep=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null})=>{let r=o?Ui(St(o.x-n,o.y-n),e,St(o.x+o.width+n,o.y+o.height+n)):!1,s=he(t,i,!0);return!Ui(St(s[0]-n,s[1]-n),lt(e,dt(s),-t.angle),St(s[2]+n,s[3]+n))&&!r?!1:ji(t)&&Ma(e,t,i)||ya(e,t,i,n)||r},tp=(e,t,n,i=0)=>{let[o,r,s,a]=he(t,n);return o-=i,r-=i,s+=i,a+=i,Ui(St(o,r),e,St(s,a))},vw=(e,t)=>!ep(e)&&!np(e.point,e.element,t)&&tp(e.point,e.element,t),np=(e,t,n)=>{let i=W(t,n);if(!i)return!1;let o=j(t)?{...i,...U.getBoundTextElementPosition(t,i,n)}:i;return Ma(e,o,n)},Mn=(e,t,n,i=0,o=!1)=>{let r=[Math.min(n[0][0]-i,n[1][0]-i),Math.min(n[0][1]-i,n[1][1]-i),Math.max(n[0][0]+i,n[1][0]+i),Math.max(n[0][1]+i,n[1][1]+i)],s=he(e,t);if(!En(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return op(e,t,n,i,o);case"diamond":return rp(e,t,n,i,o);case"ellipse":return sp(e,t,n,i);case"line":case"freedraw":case"arrow":return ip(e,n,o)}},Ia=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Wi(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!En(a,l))continue;let d=ba(s,t);if(d.length>0){for(let c of d)n.push(lt(c,i,o));if(r)return n}}return n},Sa=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Pa(s,t);if(a&&(n.push(lt(a,i,o)),r))return n}return n},ip=(e,t,n=!1)=>{let[i,o]=Bi(e),r=[];for(let s of i){let a=Pa(s,t);if(a&&(r.push(a),n))return r}for(let s of o){let a=Wi(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!En(a,l))continue;let d=ba(s,t);if(d.length>0&&(r.push(...d),n))return r}return r},op=(e,t,n,i=0,o=!1)=>{let r=fe(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Xi(s,a),[d,c]=Pn(e,i),u=[];return Sa(d,l,u,r,e.angle,o),o&&u.length>0||Ia(c,l,u,r,e.angle,o),u},rp=(e,t,n,i=0,o=!1)=>{let r=fe(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Xi(s,a),[d,c]=In(e,i),u=[];return Sa(d,l,u,r,e.angle,o),o&&u.length>0||Ia(c,l,u,r,e.angle,o),u},sp=(e,t,n,i=0)=>{let o=fe(e,t),r=lt(n[0],o,-e.angle),s=lt(n[1],o,-e.angle);return Ju(Qu(o,e.width/2+i,e.height/2+i),Xi(r,s)).map(a=>lt(a,o,e.angle))},ya=(e,t,n,i=1)=>_t(t,n,e)<=i,Ma=(e,t,n)=>{if((j(t)||Me(t))&&!pn(t.points))return!1;let[i,o,r,s]=he(t,n);if(!Ui(St(i,o),e,St(r,s)))return!1;let a=St((i+r)/2,(o+s)/2),l=Vu(Ku(qu(Zu(e,a,.1)),Math.max(t.width,t.height)*2),a),d=Xi(e,l);return Mn(t,n,d).filter((u,p,m)=>m.findIndex(f=>$u(f,u))===p).length%2===1};P();import{invariant as Ta,isDevEnv as ap,isTestEnv as lp}from"@excalidraw/common";import{pointFrom as Yt,pointFromVector as Vi,pointRotateRads as $i,pointScaleFromOrigin as Zi,pointsEqual as dp,triangleIncludesPoint as pr,vectorCross as Be,vectorFromPoint as K,vectorScale as qi}from"@excalidraw/math";var me=[1,0],ye=[0,1],ke=[-1,0],ze=[0,-1],Mt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?me:t<=-o?ke:n>i?ye:ze},Ge=(e,t)=>Mt(K(e,t)),tt=(e,t)=>Oe(Ge(e,t)),pe=(e,t)=>e[0]===t[0]&&e[1]===t[1],Oe=e=>pe(e,me)||pe(e,ke),Ow=e=>!Oe(e),cp=(e,t,n)=>{let i=dt(t);(ap()||lp())&&(Ta(e.width>0&&e.height>0,"Diamond element has no width or height"),Ta(!dp(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Vi(qi(K($i(Yt(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Vi(qi(K($i(Yt(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Vi(qi(K($i(Yt(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Vi(qi(K($i(Yt(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Be(K(n,r),K(r,s))<=0&&Be(K(n,r),K(r,l))>0)return Ge(r,i);if(Be(K(n,s),K(s,a))<=0&&Be(K(n,s),K(s,r))>0)return Ge(s,i);if(Be(K(n,a),K(a,l))<=0&&Be(K(n,a),K(a,s))>0)return Ge(a,i);if(Be(K(n,l),K(l,r))<=0&&Be(K(n,l),K(l,a))>0)return Ge(l,i);if(Be(K(n,i),K(r,i))<=0&&Be(K(n,i),K(s,i))>0){let c=e.width>e.height?r:s;return Ge(c,i)}else if(Be(K(n,i),K(s,i))<=0&&Be(K(n,i),K(a,i))>0){let c=e.width>e.height?a:s;return Ge(c,i)}else if(Be(K(n,i),K(a,i))<=0&&Be(K(n,i),K(l,i))>0){let c=e.width>e.height?a:l;return Ge(c,i)}let d=e.width>e.height?r:l;return Ge(d,i)},ni=(e,t,n)=>{let o=dt(t);if(e.type==="diamond")return cp(e,t,n);let r=Zi(Yt(t[0],t[1]),o,2),s=Zi(Yt(t[2],t[1]),o,2),a=Zi(Yt(t[0],t[3]),o,2),l=Zi(Yt(t[2],t[3]),o,2);return pr([r,s,o],n)?ze:pr([s,l,o],n)?me:pr([l,a,o],n)?ye:ke},mr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as vp,randomInteger as Sr,getUpdatedTimestamp as Mr}from"@excalidraw/common";P();import{clamp as Ki,pointDistance as Er,pointFrom as z,pointScaleFromOrigin as up,pointsEqual as oi,pointTranslate as hr,vector as ct,vectorCross as Qi,vectorFromPoint as gr,vectorScale as pp}from"@excalidraw/math";import{BinaryHeap as mp,invariant as Tn,isAnyTrue as fp,tupleToCoors as hp,getSizeFromPoints as Aa,isDevEnv as Ep,arrayToMap as gp}from"@excalidraw/common";var xr=1,ee=40,xp=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>z(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=Ge(s,l[a-1]),c=Ge(l[a-1],l[a-2]);if(pe(d,c)){let u=n?.findIndex(m=>m.index===a-1)??-1,p=n?.findIndex(m=>m.index===a)??-1;p!==-1&&(n[p].start=z(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(m=>{m.index>a-1&&(m.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(Er(l[a-2],l[a-1])<xr){let d=n?.findIndex(p=>p.index===a-2)??-1,c=n?.findIndex(p=>p.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),o.splice(-2,2),n.forEach(p=>{p.index>a-2&&(p.index-=2)});let u=tt(s,l[a-1]);return o.push(z(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}o.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==o.length-1);return r.length===0?Tt(br(Pr(yr(e,wr(e,t,o.map(s=>z(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(Ep()&&Tn(ka(o),"Invalid elbow points with fixed segments"),Tt(o,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},wp=(e,t,n)=>{let i=t.map(T=>T.index),r=(e.fixedSegments?.map(T=>T.index)??[]).findIndex(T=>!i.includes(T));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,p=l?null:e.endBinding,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y}=wr({x:d,y:c,startBinding:u,endBinding:p,startArrowhead:null,endArrowhead:null,points:e.points},n,[z(0,0),z(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:b}=Tt(br(Pr(yr(e,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y})??[])),t,null,null);if(!b||b.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let w=[];if(a)for(let T=0;T<a.index;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));if(b.forEach(T=>{w.push(z(e.x+(a?a.end[0]:0)+T[0],e.y+(a?a.end[1]:0)+T[1]))}),l)for(let T=l.index;T<e.points.length;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,M=t.map(T=>T.index>s?{...T,index:T.index-I+(b.length-1)}:T),D=w.flatMap((T,N)=>{let C=w[N-1],R=w[N+1];if(C&&R){let L=Ge(T,C),V=Ge(R,T);if(pe(L,V))return M.forEach(H=>{H.index>N&&(H.index-=1)}),[];if(pe(L,mr(V)))return M.forEach(H=>{H.index>N&&(H.index+=1)}),[T,T]}return[T]});return Tt(D,M,!1,!1)},yp=(e,t,n,i,o,r)=>{let s=t.map((w,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==w.index||(w.start[0]!==e.fixedSegments[I].start[0]&&w.end[0]!==e.fixedSegments[I].end[0])!=(w.start[1]!==e.fixedSegments[I].start[1]&&w.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,d=Er(t[s].start,t[s].end),c=d<ee+5;if(a===-1&&t[s].index===1&&o){let w=Oe(n),M=(w?pe(n,me):pe(n,ye))?c?d/2:ee:c?-d/2:-ee;t[s].start=z(t[s].start[0]+(w?M:0),t[s].start[1]+(w?0:M))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=Oe(i),M=(w?pe(i,me):pe(i,ye))?c?d/2:ee:c?-d/2:-ee;t[s].end=z(t[s].end[0]+(w?M:0),t[s].end[1]+(w?0:M))}let u=t.map(w=>({...w,start:z(e.x+w.start[0],e.y+w.start[1]),end:z(e.x+w.end[0],e.y+w.end[1])})),p=e.points.map((w,I)=>z(e.x+w[0],e.y+w[1])),m=u[s].index-1,f=u[s].index,E=u[s].start,h=u[s].end,g=p[m-1]&&!oi(p[m],p[m-1])?tt(p[m-1],p[m]):void 0,x=p[f+1]&&!oi(p[f],p[f+1])?tt(p[f+1],p[f]):void 0;if(g!==void 0){let w=g?1:0;p[m-1][w]=E[w]}if(p[m]=E,p[f]=h,x!==void 0){let w=x?1:0;p[f+1][w]=h[w]}let y=u.findIndex(w=>w.index===m);if(y!==-1){let w=tt(u[y].end,u[y].start)?1:0;u[y].start[w]=E[w],u[y].end=E}let b=u.findIndex(w=>w.index===f+1);if(b!==-1){let w=tt(u[b].end,u[b].start)?1:0;u[b].end[w]=h[w],u[b].start=h}if(a===-1&&m===0){let w=o?Oe(n):tt(p[1],p[0]);p.unshift(z(w?E[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:E[1])),o&&p.unshift(z(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=o?2:1}if(l===-1&&f===e.points.length-1){let w=Oe(i);p.push(z(w?h[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:h[1])),r&&p.push(z(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return Tt(p,u.map(w=>({...w,start:z(w.start[0]-e.x,w.start[1]-e.y),end:z(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},bp=(e,t,n,i,o,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((h,g)=>g===0?z(e.x+h[0],e.y+h[1]):g===t.length-1?z(e.x+h[0],e.y+h[1]):z(e.x+e.points[g][0],e.y+e.points[g][1])),p=n.map(h=>({...h,start:z(e.x+(h.start[0]-t[0][0]),e.y+(h.start[1]-t[0][1])),end:z(e.x+(h.end[0]-t[0][0]),e.y+(h.end[1]-t[0][1]))})),m=[],f=2+(d?1:0),E=2+(c?1:0);for(;m.length+f<u.length-E;)m.push(u[m.length+f]);{let h=u.at(d?2:1),g=u.at(d?3:2);if(!h||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=Oe(i),y=Oe(Mt(gr(h,g)));if(a&&x===y){let b=x?pe(i,me):pe(i,ye);if(m.unshift(z(y?r[0]+(b?ee:-ee):g[0],y?g[1]:r[1]+(b?ee:-ee))),m.unshift(z(x?r[0]+(b?ee:-ee):r[0],x?r[1]:r[1]+(b?ee:-ee))),!d){d=!0;for(let w of p)w.index>1&&(w.index+=1)}}else if(m.unshift(z(y?r[0]:h[0],y?h[1]:r[1])),d){d=!1;for(let b of p)b.index>1&&(b.index-=1)}m.unshift(r)}{let h=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!h||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=Oe(o),y=tt(g,h);if(l&&x===y){let b=x?pe(o,me):pe(o,ye);m.push(z(y?s[0]+(b?ee:-ee):g[0],y?g[1]:s[1]+(b?ee:-ee))),m.push(z(x?s[0]+(b?ee:-ee):s[0],x?s[1]:s[1]+(b?ee:-ee))),c||(c=!0)}else m.push(z(y?s[0]:h[0],y?h[1]:s[1])),c&&(c=!1)}return m.push(s),Tt(m,p.map(({index:h})=>({index:h,start:m[h-1],end:m[h]})).map(h=>({...h,start:z(h.start[0]-r[0],h.start[1]-r[1]),end:z(h.end[0]-r[0],h.end[1]-r[1])})),d,c)},Ut=1e6,Dn=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};A.PROD||(Tn(!n.points||n.points.length>=2,"Updated point array length must match the arrow point length, contain exactly the new start and end points or not be specified at all (i.e. you can't add new points between start and end manually to elbow arrows)"),Tn(!e.fixedSegments||e.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Tn(!n.fixedSegments||n.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Tn(e.points.slice(1).map((w,I)=>w[0]===e.points[I][0]||w[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Tn(n.fixedSegments?.find(w=>w.index===1&&oi(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&oi(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let o=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&eo(d.elementId,t),p=c&&eo(c.elementId,t),m=ka(r);if(d&&!u&&m||c&&!p&&m||t.size===0&&m||Object.keys(l).length===0&&(u?.id!==d?.elementId||p?.id!==c?.elementId))return Tt(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b}=wr({x:e.x,y:e.y,startBinding:d,endBinding:c,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,i);return t.size===0&&m?Tt(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?xp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,I)=>oi(w,e.points[I]??z(1/0,1/0)))&&m?{}:o.length===0?Tt(br(Pr(yr(e,{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?wp(e,o,t):n.points?n.points&&n.fixedSegments?n:bp(e,r,o,f,E,h,g,x,y):yp(e,o,f,E,x,y)},wr=(e,t,n,i)=>{let o=hr(n[0],ct(e.x,e.y)),r=hr(n[n.length-1],ct(e.x,e.y)),s=null,a=null;if(i?.isDragging){let w=Array.from(t.values());s=Ca(o,t,w,i?.zoom)||null,a=Ca(r,t,w,i?.zoom)||null}else s=e.startBinding&&eo(e.startBinding.elementId,t)||null,a=e.endBinding&&eo(e.endBinding.elementId,t)||null;let l=va({...e,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging),d=va({...e,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging),c=La(l,d,s,o,t),u=La(d,l,a,r,t),p=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],m=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],f=s?$e(s,t,Xt(c,e.startArrowhead?oe*6:oe*2,1)):p,E=a?$e(a,t,Xt(u,e.endArrowhead?oe*6:oe*2,1)):m,h=An(l,a?$e(a,t,Xt(u,ee,ee)):m)||An(d,s?$e(s,t,Xt(c,ee,ee)):p),g=Ga(h?[p,m]:[f,E]),x=Sp(h?p:f,h?m:E,g,h?Xt(c,!s&&!a?0:ee,0):Xt(c,!s&&!a?0:ee-(e.startArrowhead?oe*6:oe*2),ee),h?Xt(u,!s&&!a?0:ee,0):Xt(u,!s&&!a?0:ee-(e.endArrowhead?oe*6:oe*2),ee),h,s&&$e(s,t),a&&$e(a,t)),y=Da(x[0],c,l),b=Da(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:y,startGlobalPoint:l,startHeading:c,endDonglePosition:b,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:h,startElementBounds:f,endElementBounds:E}},yr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Mp(n,i||o,r,s||a,l,d),p=i&&Ji(i,u),m=s&&Ji(s,u),f=Ji(a,u);f&&c&&(f.closed=!0);let E=Ji(o,u);E&&e.startBinding&&(E.closed=!0);let h=p&&m&&(An(p.pos,n[1])||An(m.pos,n[0])),g=Pp(p||E,m||f,u,r||me,l||me,h?[]:n);if(g){let x=g.map(y=>[y.pos[0],y.pos[1]]);return p&&x.unshift(o),m&&x.push(a),x}return null},Xt=(e,t,n)=>{switch(e){case ze:return[t,n,n,n];case me:return[n,t,n,n];case ye:return[n,n,t,n]}return[n,n,n,t]},Pp=(e,t,n,i,o,r)=>{let s=fr(e.pos,t.pos),a=new mp(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Ip(e,l);l.closed=!0;let d=Ap(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let p=up(u.pos,l.pos,.5);if(fp(...r.map(b=>An(p,b))))continue;let m=Dp(c),f=l.parent?Mt(gr(l.pos,l.parent.pos)):i,E=mr(f);if(pe(E,m)||Ba(e.addr,u.addr)&&pe(m,i)||Ba(t.addr,u.addr)&&pe(m,o))continue;let g=f!==m,x=l.g+fr(u.pos,l.pos)+(g?Math.pow(s,3):0),y=u.visited;if(!y||x<u.g){let b=Tp(u,t,m,o);u.visited=!0,u.parent=l,u.h=fr(t.pos,u.pos)+b*Math.pow(s,2),u.g=x,u.f=u.g+u.h,y?a.rescoreElement(u):a.push(u)}}}return null},Ip=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},fr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Sp=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,p,m]=i??[0,0,0,0],[f,E,h,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-m):(l[0]+d[2])/2:e[0]>t[0]?e[0]-m:n[0]-m,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+p):(l[3]+d[1])/2:e[3]<t[3]?e[3]+p:n[3]+p],y=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-f):(d[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+E):(d[2]+l[0])/2:t[2]<e[2]?t[2]+E:n[2]+E,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+h):(d[3]+l[1])/2:t[3]<e[3]?t[3]+h:n[3]+h],b=Ga([x,y]);if(!r&&x[2]-x[0]+y[2]-y[0]>b[2]-b[0]+1e-11&&x[3]-x[1]+y[3]-y[1]>b[3]-b[1]+1e-11){let[w,I]=[(y[0]+y[2])/2,(y[1]+y[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let M=x[2]+(y[0]-x[2])/2,D=y[3]+(x[1]-y[3])/2;return Qi(ct(e[2]-w,e[1]-I),ct(e[0]-w,e[3]-I))>0?[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}else if(e[2]<t[0]&&e[3]<t[1]){let M=x[2]+(y[0]-x[2])/2,D=x[3]+(y[1]-x[3])/2;return Qi(ct(e[0]-w,e[1]-I),ct(e[2]-w,e[3]-I))>0?[[x[0],x[1],x[2],D],[y[0],D,y[2],y[3]]]:[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let M=y[2]+(x[0]-y[2])/2,D=x[3]+(y[1]-x[3])/2;return Qi(ct(e[2]-w,e[1]-I),ct(e[0]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],x[1],x[2],D],[y[0],D,y[2],y[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let M=y[2]+(x[0]-y[2])/2,D=y[3]+(x[1]-y[3])/2;return Qi(ct(e[0]-w,e[1]-I),ct(e[2]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}}return[x,y]},Mp=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===ke||n===me?a.add(t[1]):s.add(t[0]),o===ke||o===me?a.add(i[1]):s.add(i[0]),e.forEach(c=>{s.add(c[0]),s.add(c[2]),a.add(c[1]),a.add(c[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((c,u)=>c-u),d=Array.from(s).sort((c,u)=>c-u);return{row:l.length,col:d.length,data:l.flatMap((c,u)=>d.map((p,m)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[m,u],pos:[p,c]})))}},Da=(e,t,n)=>{switch(t){case ze:return z(n[0],e[1]);case me:return z(e[2],n[1]);case ye:return z(n[0],e[3])}return z(e[0],n[1])},Tp=(e,t,n,i)=>{if(i===me)switch(n){case me:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case ze:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ye:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ke:return e.pos[1]===t.pos[1]?4:2}else if(i===ke)switch(n){case me:return e.pos[1]===t.pos[1]?4:2;case ze:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ye:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ke:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===ze)switch(n){case me:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ze:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ye:return e.pos[0]===t.pos[0]?4:2;case ke:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===ye)switch(n){case me:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ze:return e.pos[0]===t.pos[0]?4:2;case ye:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ke:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Ap=([e,t],n)=>[ii([e,t-1],n),ii([e+1,t],n),ii([e,t+1],n),ii([e-1,t],n)],ii=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Ji=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=ii([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Ga=e=>[Math.min(...e.map(t=>t[0])),Math.min(...e.map(t=>t[1])),Math.max(...e.map(t=>t[2])),Math.max(...e.map(t=>t[3]))],eo=(e,t)=>{let n=t.get(e);return n&&Le(n)?n:null},Tt=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>hr(a,pp(gr(e[0]),-1)));return(o<-Ut||o>Ut||r<-Ut||r>Ut||o+s[s.length-1][0]<-Ut||r+s[s.length-1][0]>Ut||o+s[s.length-1][1]<-Ut||r+s[s.length-1][1]>Ut)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...Aa(s)}),s=s.map(([a,l])=>z(Ki(a,-1e6,1e6),Ki(l,-1e6,1e6))),{points:s,x:Ki(o,-1e6,1e6),y:Ki(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Aa(s),startIsSpecial:n,endIsSpecial:i}},br=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},Pr=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Er(i,t)>xr}):e,Dp=e=>{switch(e){case 0:return ze;case 1:return me;case 2:return ye}return ke},va=(e,t,n,i,o,r,s)=>s?o&&r?Ir(e,o,t,r):i:o?to(n||[0,0],o,r??gp([o])):i,La=(e,t,n,i,o)=>Oa(e,t,n,n&&$e(n,o,Array(4).fill(_t(n,o,e))),i,o),Ca=(e,t,n,i)=>jt(hp(e),n,t,i,!0,!0),Ba=(e,t)=>e[0]===t[0]&&e[1]===t[1],ka=(e,t=xr)=>e.slice(1).map((n,i)=>Math.abs(n[0]-e[i][0])<t||Math.abs(n[1]-e[i][1])<t).every(Boolean);var be=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,startBinding:a,endBinding:l,fileId:d}=n;G(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u"||typeof a<"u"||typeof l<"u")?n={...n,angle:0,...Dn({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...vp(r),...n});for(let c in n){let u=n[c];if(typeof u<"u"){if(e[c]===u&&(typeof u!="object"||u===null||c==="groupIds"||c==="scale"))continue;if(c==="scale"){let p=e[c],m=u;if(p[0]===m[0]&&p[1]===m[1])continue}else if(c==="points"){let p=e[c],m=u;if(p.length===m.length){let f=!1,E=p.length;for(;--E;){let h=p[E],g=m[E];if(h[0]!==g[0]||h[1]!==g[1]){f=!0;break}}if(!f)continue}}e[c]=u,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof d<"u"||typeof r<"u")&&Pe.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Sr(),e.updated=Mr()),e},Ee=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Sr(),updated:Mr()}},Ra=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Sr(),e.updated=Mr(),e);var uy=e=>!e[Lp.CTRL_OR_CMD],Tr=e=>e.isBindingEnabled,oe=5,Fp=10,Np=(e,t)=>{let n=[];return t.forEach(i=>{let o=e.getNonDeletedElement(i);o!=null&&n.push(o)}),n},Ar=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=new Set,s=new Set;Ha(e,t,n,"start",r,s,i,o),Ha(e,n,t,"end",r,s,i,o);let a=Array.from(s).filter(l=>!r.has(l));Np(i,a).forEach(l=>{i.mutateElement(l,{boundElements:l.boundElements?.filter(d=>d.type!=="arrow"||d.id!==e.id)})})},Ha=(e,t,n,i,o,r,s,a)=>{if(t!=="keep"){if(t===null){let l=Up(e,i,s);l!=null&&r.add(l);return}Wa(e)?(n==null||(n==="keep"?!Xa(e,t,i):i==="start"||n.id!==t.id))&&(gn(e,t,i,s),o.add(t.id)):(gn(e,t,i,s),o.add(t.id))}},Ya=(e,t,n)=>["start","end"].map(i=>{let o=$a(e,i,t),r=i==="start"?e.startBinding?.elementId:e.endBinding?.elementId;if(r){let s=t.get(r);if(Le(s)&&io(s,o,t,n))return s}return null}),Hp=(e,t,n,i,o,r)=>{let a=e.points.length-1,l=n.findIndex(p=>p===0)>-1,d=n.findIndex(p=>p===a)>-1,c=l?t?oo(e,"start",i,o,r):null:"keep",u=d?t?oo(e,"end",i,o,r):null:"keep";return[c,u]},zp=(e,t,n,i,o)=>{if(G(e))return["keep","keep"];let[r,s]=Ya(e,t,o),a=r&&i?oo(e,"start",t,n,o):null,l=s&&i?oo(e,"end",t,n,o):null;return[a,l]},_p=(e,t,n,i,o)=>{e.forEach(r=>{let[s,a]=n?.length?Hp(r,t,n??[],i.getNonDeletedElementsMap(),i.getNonDeletedElements(),o):zp(r,i.getNonDeletedElementsMap(),i.getNonDeletedElements(),t,o);Ar(r,s,a,i)})},py=(e,t,n)=>e.length>50?[]:e.filter(j).flatMap(i=>Ya(i,t,n)).filter(i=>i!==null).filter(i=>e.filter(o=>o.id===i?.id).length===0),Ua=(e,t,n,i,o)=>Array.from(t.reduce((r,s)=>{let a=jt(s,n.getNonDeletedElements(),n.getNonDeletedElementsMap(),i,G(e),G(e));return a!=null&&!ja(e,o?.id,a)&&r.add(a),r},new Set)),my=(e,t,n,i)=>{let o=i.getNonDeletedElements(),r=i.getNonDeletedElementsMap();t.startBoundElement!=null&&gn(e,t.startBoundElement,"start",i);let s=jt(n,o,r,t.zoom,G(e),G(e));s!==null&&(Xa(e,s,"end")||gn(e,s,"end",i))},Yp=(e,t)=>({...e,gap:Math.min(e.gap,ao(t,t.width,t.height))}),gn=(e,t,n,i)=>{if(!Y(e))return;let o={elementId:t.id,...Yp(Wp(e,t,n,i.getNonDeletedElementsMap()),t)};G(e)&&(o={...o,...Va(e,t,n,i.getNonDeletedElementsMap())}),i.mutateElement(e,{[n==="start"?"startBinding":"endBinding"]:o}),_a(t.boundElements||[]).has(e.id)||i.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Xa=(e,t,n)=>{let i=e[n==="start"?"endBinding":"startBinding"];return ja(e,i?.elementId,t)},ja=(e,t,n)=>t===n.id&&Wa(e),Wa=e=>e.points.length<3&&!G(e),Up=(e,t,n)=>{let i=t==="start"?"startBinding":"endBinding",o=e[i];return o==null?null:(n.mutateElement(e,{[i]:null}),o.elementId)},jt=(e,t,n,i,o,r)=>{if(r){let a=!1,l=jp(t,c=>Le(c,!1)&&io(c,e,n,i,(o||!no(c))&&!Z(c))).filter(c=>a?!1:(no(c)||(a=!0),!0));if(!l||l.length===0)return null;if(l.length===1)return l[0];let d=l.filter(c=>io(c,e,n,i,!1));return d.length===1?d[0]:l.sort((c,u)=>u.width**2+u.height**2-(c.width**2+c.height**2)).pop()}return Xp(t,a=>Le(a,!1)&&io(a,e,n,i,(o||!no(a))&&!Z(a)))},Xp=(e,t)=>{let n=null;for(let i=e.length-1;i>=0;--i){let o=e[i];if(!o.isDeleted&&t(o)){n=o;break}}return n},jp=(e,t)=>{let n=[];for(let i=e.length-1;i>=0;--i){let o=e[i];o.isDeleted||t(o)&&n.push(o)}return n},Wp=(e,t,n,i)=>{let o=n==="start"?-1:1,r=o===-1?0:e.points.length-1,s=r-o,a=U.getPointAtIndexGlobalCoordinates(e,r,i),l=U.getPointAtIndexGlobalCoordinates(e,s,i);return{focus:Jp(t,i,l,a),gap:Math.max(1,_t(t,i,a))}},Ue=(e,t,n)=>{if(!Le(e))return;let{newSize:i,simultaneouslyUpdated:o}=n??{},r=$p(o),s=t.getNonDeletedElementsMap();n?.changedElements&&(s=new Map(s),n.changedElements.forEach(a=>{s.set(a.id,a)})),ro(s,e,a=>{if(!j(a)||a.isDeleted||!Vp(a,e))return;let l=a.startBinding?s.get(a.startBinding.elementId):null,d=a.endBinding?s.get(a.endBinding.elementId):null,c=null,u=null;l&&d&&(c=he(l,s),u=he(d,s));let p={startBinding:za(e,a.startBinding,i),endBinding:za(e,a.endBinding,i)};if(r.has(a.id)){t.mutateElement(a,p);return}let m=so(s,a,(E,h)=>{if(E&&Le(E)&&(h==="startBinding"||h==="endBinding")&&(e.id===a[h]?.elementId||e.id===a[h==="startBinding"?"endBinding":"startBinding"]?.elementId&&!En(c,u))){let g=Qp(a,h,p[h],E,s);if(g)return[h==="startBinding"?0:a.points.length-1,{point:g}]}return null}).filter(E=>E!==null);U.movePoints(a,t,new Map(m),{...e.id===a.startBinding?.elementId?{startBinding:p.startBinding}:{},...e.id===a.endBinding?.elementId?{endBinding:p.endBinding}:{}});let f=W(a,s);f&&!f.isDeleted&&hn(a,t,!1)})},fy=(e,t,n)=>{j(e)?_p([e],!0,[],t,n?.zoom):Ue(e,t,{...n,changedElements:new Map([[e.id,e]])})},Vp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,$p=e=>new Set((e||[]).map(t=>t.id)),Oa=(e,t,n,i,o,r,s)=>{let a=Mt(q(t,e));return!n||!i?a:Zp(o,n,r,s)?ni(n,i,e):Mt(q(e,fe(n,r)))},Zp=(e,t,n,i)=>{let o=_t(t,n,e),r=ao(t,t.width,t.height,i);return o>r?null:o},Ir=(e,t,n,i)=>{(Gp()||kp())&&Bp(e.points.length>1,"Arrow should have at least 2 points");let o=$e(t,i),r=e.points[n==="start"?0:e.points.length-1],s=O(e.x+r[0],e.y+r[1]),a=sa(t)?qp(t,i,s):s,l=G(e),d=dt(o),c=n==="start"?1:e.points.length-2,u=ae(O(e.x+e.points[c][0],e.y+e.points[c][1]),d,e.angle??0),p=null;if(l){let m=Oe(ni(t,o,s)),f=Kp(t,i,a),E=O(m?d[0]:f[0],m?f[1]:d[1]),h=Ye(E,vn(Ln(si(q(f,E)),Math.max(t.width,t.height)*2),E));p=Mn(t,i,h,oe).sort(Wt)[0]}else p=Mn(t,i,Ye(u,vn(Ln(si(q(a,u)),ut(a,u)+Math.max(t.width,t.height)*2),u)),oe).sort((m,f)=>Wt(m,u)-Wt(f,u))[0];return!p||Wt(a,p)<Rp?a:l?p:a},qp=(e,t,n)=>{let i=fe(e,t),o=ae(n,i,-e.angle);return o[0]<e.x&&o[1]<e.y?o[1]-e.y>-oe?ae(O(e.x-oe,e.y),i,e.angle):ae(O(e.x,e.y-oe),i,e.angle):o[0]<e.x&&o[1]>e.y+e.height?o[0]-e.x>-oe?ae(O(e.x,e.y+e.height+oe),i,e.angle):ae(O(e.x-oe,e.y+e.height),i,e.angle):o[0]>e.x+e.width&&o[1]>e.y+e.height?o[0]-e.x<e.width+oe?ae(O(e.x+e.width,e.y+e.height+oe),i,e.angle):ae(O(e.x+e.width+oe,e.y+e.height),i,e.angle):o[0]>e.x+e.width&&o[1]<e.y?o[0]-e.x<e.width+oe?ae(O(e.x+e.width,e.y-oe),i,e.angle):ae(O(e.x+e.width+oe,e.y),i,e.angle):n},Kp=(e,t,n,i=.05)=>{let{x:o,y:r,width:s,height:a,angle:l}=e,d=fe(e,t,-.1,-.1),c=ae(n,d,-l),u=Fa(i*a,5,80),p=Fa(i*s,5,80);if(c[0]<=o+s/2&&c[1]>d[1]-u&&c[1]<d[1]+u)return ae(O(o-oe,d[1]),d,l);if(c[1]<=r+a/2&&c[0]>d[0]-p&&c[0]<d[0]+p)return ae(O(d[0],r-oe),d,l);if(c[0]>=o+s/2&&c[1]>d[1]-u&&c[1]<d[1]+u)return ae(O(o+s+oe,d[1]),d,l);if(c[1]>=r+a/2&&c[0]>d[0]-p&&c[0]<d[0]+p)return ae(O(d[0],r+a+oe),d,l);if(e.type==="diamond"){let m=oe,f=O(o+s/4-m,r+a/4-m),E=O(o+3*s/4+m,r+a/4-m),h=O(o+s/4-m,r+3*a/4+m),g=O(o+3*s/4+m,r+3*a/4+m);if(ut(f,c)<Math.max(p,u))return ae(f,d,l);if(ut(E,c)<Math.max(p,u))return ae(E,d,l);if(ut(h,c)<Math.max(p,u))return ae(h,d,l);if(ut(g,c)<Math.max(p,u))return ae(g,d,l)}return n},Qp=(e,t,n,i,o)=>{if(n==null||n.elementId!==i.id&&e.points.length>2)return null;let r=t==="startBinding"?-1:1,s=r===-1?0:e.points.length-1;if(G(e)&&Qn(n)){let u=Dr(n.fixedPoint)??Va(e,i,t==="startBinding"?"start":"end",o).fixedPoint,p=fe(i,o),m=O(i.x+u[0]*i.width,i.y+u[1]*i.height),f=ae(m,p,i.angle);return U.pointFromAbsoluteCoords(e,f,o)}let a=s-r,l=U.getPointAtIndexGlobalCoordinates(e,a,o),d=em(i,o,n.focus,l),c;if(n.gap===0)c=d;else{let u=U.getPointAtIndexGlobalCoordinates(e,s,o),p=fe(i,o),m=ut(l,u)+ut(l,p)+Math.max(i.width,i.height)*2,f=[...Mn(i,o,Ye(l,vn(Ln(si(q(d,l)),m),l)),n.gap).sort((E,h)=>Wt(E,l)-Wt(h,l)),vn(Ln(si(q(d,l)),ut(l,u)),l)];f.length>1?c=f[0]:f.length===1?c=d:c=u}return U.pointFromAbsoluteCoords(e,c,o)},Va=(e,t,n,i)=>{let o=[t.x,t.y,t.x+t.width,t.y+t.height],r=Ir(e,t,n,i),s=O(o[0]+(o[2]-o[0])/2,o[1]+(o[3]-o[1])/2),a=ae(r,s,-t.angle);return{fixedPoint:Dr([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},za=(e,t,n)=>{if(t==null||n==null)return t;let{width:i,height:o}=n,{width:r,height:s}=e,a=Math.max(1,Math.min(ao(e,i,o),t.gap*(i<o?i/r:o/s)));return{...t,gap:a}},oo=(e,t,n,i,o)=>jt($a(e,t,n),i,n,o,G(e),G(e)),$a=(e,t,n)=>{let i=t==="start"?0:-1;return Cp(U.getPointAtIndexGlobalCoordinates(e,i,n))},Za=(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})}G(i)&&Object.assign(i,Dn(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},hy=(e,t)=>{let n=_a(e);for(let i of t)Vt.unbindAffected(n,i,(o,r)=>be(o,n,r)),$t.unbindAffected(n,i,(o,r)=>be(o,n,r))},ri=(e,t,n=[])=>{if(!e)return null;let i=e.filter(o=>!t.has(o.id));return i.push(...n.map(o=>({id:o.id,type:o.type}))),i},io=(e,{x:t,y:n},i,o,r)=>{let s=O(t,n),a=ao(e,e.width,e.height,o),l=(r||!no(e))&&!Z(e),d=[t-a,n-a,t+a,n+a],c=he(e,i);if(!En(d,c))return!1;let u=Mn(e,i,Ye(fe(e,i),s)),p=_t(e,i,s);return l?u.length===0||p<=a:u.length>0&&p<=a},ao=(e,t,n,i)=>{let o=i?.value&&i.value<1?i.value:1,s=(e.type==="diamond"?1/Math.sqrt(2):1)*Math.min(t,n);return Math.max(16,Math.min(.25*s,32),Fp/o+oe)},Jp=(e,t,n,i)=>{let o=fe(e,t);if(Op(n,i))return 0;let r=ae(n,o,-e.angle),s=ae(i,o,-e.angle),a=Math.sign(_e(q(s,n),q(s,o)))*-1,l=Ye(s,vn(Ln(si(q(s,r)),Math.max(e.width*2,e.height*2)),s)),d=e.type==="diamond"?[Ye(O(e.x+e.width/2,e.y),O(e.x+e.width/2,e.y+e.height)),Ye(O(e.x,e.y+e.height/2),O(e.x+e.width,e.y+e.height/2))]:[Ye(O(e.x,e.y),O(e.x+e.width,e.y+e.height)),Ye(O(e.x+e.width,e.y),O(e.x,e.y+e.height))],c=e.type==="diamond"?[Ye(O(e.x+e.width/2,e.y-e.height),O(e.x+e.width/2,e.y+e.height*2)),Ye(O(e.x-e.width,e.y+e.height/2),O(e.x+e.width*2,e.y+e.height/2))]:[Ye(O(e.x-e.width,e.y-e.height),O(e.x+e.width*2,e.y+e.height*2)),Ye(O(e.x+e.width*2,e.y-e.height),O(e.x-e.width,e.y+e.height*2))];return[Na(l,c[0]),Na(l,c[1])].filter(m=>m!==null).sort((m,f)=>Wt(m,i)-Wt(f,i)).map((m,f)=>a*ut(o,m)/(e.type==="diamond"?ut(d[f][0],d[f][1])/2:Math.sqrt(e.width**2+e.height**2)/2)).sort((m,f)=>Math.abs(m)-Math.abs(f))[0]??0},em=(e,t,n,i)=>{let o=fe(e,t);if(n===0)return o;let r=(e.type==="diamond"?[O(e.x,e.y+e.height/2),O(e.x+e.width/2,e.y),O(e.x+e.width,e.y+e.height/2),O(e.x+e.width/2,e.y+e.height)]:[O(e.x,e.y),O(e.x+e.width,e.y),O(e.x+e.width,e.y+e.height),O(e.x,e.y+e.height)]).map(l=>vn(Ln(q(l,o),Math.abs(n)),o)).map(l=>ae(l,o,e.angle)),s=[_e(q(i,r[0]),q(r[1],r[0]))>0&&(n>0?_e(q(i,r[1]),q(r[2],r[1]))<0:_e(q(i,r[3]),q(r[0],r[3]))<0),_e(q(i,r[1]),q(r[2],r[1]))>0&&(n>0?_e(q(i,r[2]),q(r[3],r[2]))<0:_e(q(i,r[0]),q(r[1],r[0]))<0),_e(q(i,r[2]),q(r[3],r[2]))>0&&(n>0?_e(q(i,r[3]),q(r[0],r[3]))<0:_e(q(i,r[1]),q(r[2],r[1]))<0),_e(q(i,r[3]),q(r[0],r[3]))>0&&(n>0?_e(q(i,r[0]),q(r[1],r[0]))<0:_e(q(i,r[2]),q(r[3],r[2]))<0)];return s[0]?n>0?r[1]:r[0]:s[1]?n>0?r[2]:r[1]:s[2]?n>0?r[3]:r[2]:n>0?r[0]:r[3]},qa=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),ro=(e,t,n)=>{Le(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},so=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(ce(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(Y(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},Vt=class{static unbindAffected(t,n,i){n&&so(t,n,o=>{!o||o.isDeleted||ro(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:ri(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||so(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(Y(n)&&i(o,{boundElements:ri(o.boundElements,new Set,new Array(n))}),ie(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:ri(o.boundElements,new Set,new Array(n))}))))})}},$t=class{static unbindAffected(t,n,i){n&&ro(t,n,o=>{!o||o.isDeleted||so(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||ro(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:ri(n.boundElements,new Set([s]))});return}ie(o)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===o.id?o.containerId!==n.id&&i(o,{containerId:n.id}):(o.containerId!==null&&i(o,{containerId:null}),i(n,{boundElements:ri(n.boundElements,new Set([o.id]))})))})}},to=(e,t,n)=>{let[i,o]=Dr(e);return ae(O(t.x+t.width*i,t.y+t.height*o),fe(t,n),t.angle)},tm=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?to(e.startBinding.fixedPoint,n,t):O(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?to(e.endBinding.fixedPoint,i,t):O(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},Ka=(e,t)=>{let[n,i]=tm(e,t);return[U.pointFromAbsoluteCoords(e,n,t),U.pointFromAbsoluteCoords(e,i,t)]},Dr=e=>e&&(Math.abs(e[0]-.5)<1e-4||Math.abs(e[1]-.5)<1e-4)?e.map(t=>Math.abs(t-.5)<1e-4?.5001:t):e;var Lr=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>B(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},U=class e{elementId;selectedPointsIndices;pointerDownState;isDragging;lastUncommittedPoint;pointerOffset;startBindingElement;endBindingElement;hoverPointIndex;segmentMidPointHoveredCoords;elbowed;customLineAngle;isEditing;constructor(t,n,i=!1){this.elementId=t.id,Ja(t.points[0],B(0,0))||(console.error("Linear element is not normalized",Error().stack),be(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.startBindingElement="keep",this.endBindingElement="keep",this.pointerDownState={prevSelectedPointsIndices:null,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:null,segmentMidpoint:{value:null,index:null,added:!1}},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.elbowed=G(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,p]=_(n.selectionElement,o),f=e.getPointsGlobalCoordinates(l,o).reduce((E,h,g)=>((h[0]>=d&&h[0]<=u&&h[1]>=c&&h[1]<=p||t.shiftKey&&s?.includes(g))&&E.push(g),E),[]).filter(E=>!(G(l)&&E!==0&&E!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:f.length?f:null}})}static handlePointDragging(t,n,i,o,r){if(!r)return null;let{elementId:s}=r,a=n.scene.getNonDeletedElementsMap(),l=e.getElement(s,a),d=r.customLineAngle;if(!l||G(l)&&!r.pointerDownState.lastClickedIsEndPoint&&r.pointerDownState.lastClickedPoint!==0)return null;let c=G(l)?[r.selectedPointsIndices?.includes(0)?0:void 0,r.selectedPointsIndices?.find(m=>m>0)?l.points.length-1:void 0].filter(m=>m!==void 0):r.selectedPointsIndices,u=G(l)?r.pointerDownState.lastClickedPoint>0?l.points.length-1:0:r.pointerDownState.lastClickedPoint,p=l.points[u];if(c&&p){if(el(t)&&c.length===1&&l.points.length>1){let h=c[0],g=l.points[h===0?1:h-1];d=r.customLineAngle??Math.atan2(l.points[h][1]-g[1],l.points[h][0]-g[0]);let[x,y]=e._getShiftLockedDelta(l,a,g,B(i,o),t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),d);e.movePoints(l,n.scene,new Map([[h,{point:B(x+g[0],y+g[1]),isDragging:h===u}]]))}else{let h=e.createPointAt(l,a,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize()),g=h[0]-p[0],x=h[1]-p[1];e.movePoints(l,n.scene,new Map(c.map(y=>{let b=y===u?e.createPointAt(l,a,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize()):B(l.points[y][0]+g,l.points[y][1]+x);return[y,{point:b,isDragging:y===u}]})))}W(l,a)&&hn(l,n.scene,!1);let f=[];if(Jo(l,!1)){let h=c[0]===0,g=c[c.length-1]===l.points.length-1,x=[];!h!=!g?x.push({x:i,y:o}):(h&&x.push(vr(e.getPointGlobalCoordinates(l,l.points[0],a))),g&&x.push(vr(e.getPointGlobalCoordinates(l,l.points[c[c.length-1]],a)))),x.length&&(f=Ua(l,x,n.scene,n.state.zoom))}let E={...r,selectedPointsIndices:c,segmentMidPointHoveredCoords:u!==0&&u!==l.points.length-1?this.getPointGlobalCoordinates(l,p,a):null,hoverPointIndex:u===0||u===l.points.length-1?u:-1,isDragging:!0,customLineAngle:d};return{...n.state,selectedLinearElement:E,suggestedBindings:f}}return null}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),s=o.getNonDeletedElements(),a=sm(t,i),{elementId:l,selectedPointsIndices:d,isDragging:c,pointerDownState:u}=n,p=e.getElement(l,r);if(!p)return n;let m={};if(c&&d){for(let f of d)if(f===0||f===p.points.length-1){am(p.points,i.zoom.value)&&(mn(p)&&o.mutateElement(p,{...il(p,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(p,o,new Map([[f,{point:f===0?p.points[p.points.length-1]:p.points[0]}]])));let E=Tr(i)?jt((d?.length??0)>1?vr(e.getPointAtIndexGlobalCoordinates(p,f,r)):a,s,r,i.zoom,G(p),G(p)):null;m[f===0?"startBindingElement":"endBindingElement"]=E}}return{...n,...m,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:c||t.shiftKey?!c&&t.shiftKey&&u.prevSelectedPointsIndices?.includes(u.lastClickedPoint)?d&&d.filter(f=>f!==u.lastClickedPoint):d:d?.includes(u.lastClickedPoint)?[u.lastClickedPoint]:d,isDragging:!1,pointerOffset:{x:0,y:0},customLineAngle:null}}static getEditorMidPoints=(t,n,i)=>{let o=W(t,n);if(!G(t)&&!i.selectedLinearElement?.isEditing&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!G(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!G(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Cn(B(c[0],c[1]),B(n.x,n.y))<=d)return c;let u=0,p=e.getEditorMidPoints(s,o,i);for(;u<p.length;){if(p[u]!==null&&Cn(p[u],B(n.x,n.y))<=d)return p[u];u++}return null};static isSegmentTooShort(t,n,i,o,r){if(G(t))return o>=0&&o<t.points.length?Cn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=Cn(n,i);if(t.points.length>2&&t.roundness){let[a,l]=nl(t);At(a.length===0&&l.length>0,"Only linears built out of curves are supported"),At(a.length+l.length>=o,"Invalid segment index while calculating mid point"),s=im(l[o])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(G(t)){At(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=Qa(t.points[n-1],t.points[n]);return B(t.x+r[0],t.y+r[1])}let[i,o]=nl(t);if(At(i.length===0&&o.length>0||i.length>0&&o.length===0,"Only linears built out of either segments or curves are supported"),At(i.length+o.length>=n,"Invalid segment index while calculating mid point"),i.length){let r=i[n-1];return Qa(r[0],r[1])}if(o.length){let r=o[n-1];return om(r,.5)}At(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d=s.getNonDeletedElements(),c={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return c;let{elementId:u}=r,p=e.getElement(u,l);if(!p)return c;let m=e.getSegmentMidpointHitCoords(r,o,a,l),f=null;if(m)f=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(p,{points:[...p.points,e.createPointAt(p,l,o.x,o.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),c.didAddPoint=!0),i.scheduleCapture(),c.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:{x:o.x,y:o.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:[p.points.length-1],lastUncommittedPoint:null,endBindingElement:jt(o,d,l,n.state.zoom,r.elbowed)},c.didAddPoint=!0,c;let E=e.getPointIndexUnderCursor(p,l,a.zoom,o.x,o.y);if(E>=0||m)c.hitElement=p;else{let{startBindingElement:D,endBindingElement:T}=r;Tr(a)&&Jo(p)&&Ar(p,D,T,s)}let[h,g,x,y]=_(p,l),b=(h+x)/2,w=(g+y)/2,I=E>-1&&Te(B(p.x+p.points[E][0],p.y+p.points[E][1]),B(b,w),p.angle),M=E>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(E)?lm([...r.selectedPointsIndices||[],E]):[E]:null;return c.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:E,lastClickedIsEndPoint:E===p.points.length-1,origin:{x:o.x,y:o.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:M,pointerOffset:I?{x:o.x-I[0],y:o.y-I[1]}:{x:0,y:0}},c}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Ja(t,n)}static handlePointerMove(t,n,i,o){let r=o.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=o.scene.getNonDeletedElementsMap(),d=e.getElement(s,l);if(!d)return r.selectedLinearElement;let{points:c}=d,u=c[c.length-1];if(!t.altKey)return u===a&&e.deletePoints(d,o,[c.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let p;if(el(t)&&c.length>=2){let m=c[c.length-2],[f,E]=e._getShiftLockedDelta(d,l,m,B(n,i),t[Bn.CTRL_OR_CMD]?null:o.getEffectiveGridSize());p=B(f+m[0],E+m[1])}else p=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[Bn.CTRL_OR_CMD]||G(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:p}]])):e.addPoints(d,o.scene,[p]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=_(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Te(B(c+n[0],u+n[1]),B(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=_(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return Te(B(c+d[0],u+d[1]),B(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[r,s,a,l]=_(t,i),d=(r+a)/2,c=(s+l)/2,u=t.points[o],{x:p,y:m}=t;return u?Te(B(p+u[0],m+u[1]),B(d,c),t.angle):Te(B(p,m),B(d,c),t.angle)}static pointFromAbsoluteCoords(t,n,i){if(G(t))return B(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=_(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=Te(B(n[0],n[1]),B(l,d),-t.angle);return B(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Cn(B(o,r),B(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=tl(i,o,r),[a,l,d,c]=_(t,n),u=(a+d)/2,p=(l+c)/2,[m,f]=Te(B(s[0],s[1]),B(u,p),-t.angle);return B(m-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=Lr(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){At(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);At(s,"The linear element does not exist in the provided Scene"),At(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((p,m,f)=>{if(++c,p.push(m),o.includes(f)){let h=a[f+1];h||(d=!0),p.push(h?B((m[0]+h[0])/2,(m[1]+h[1])/2):B(m[0],m[1])),l.push(c+1),++c}return p},[]);if(n.mutateElement(s,{points:u}),d){let p=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:B(p[0]+30,p[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!i.includes(u));mn(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=B(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=Lr({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];mn(t)&&t.polygon&&(o[0]=B(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=Lr({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o){let{points:r}=t;if(mn(t)&&t.polygon){let c=i.get(0),u=i.get(r.length-1);c?i.set(r.length-1,{point:B(c.point[0],c.point[1]),isDragging:c.isDragging}):u&&i.set(0,{point:B(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=i.get(0)?.point??B(0,0),[a,l]=s,d=G(t)?[i.get(0)?.point??r[0],i.get(r.length-1)?.point??r[r.length-1]]:r.map((c,u)=>{let p=i.get(u)?.point??c;return B(p[0]-a,p[1]-l)});e._updatePoints(t,n,d,a,l,o,{isDragging:Array.from(i.values()).some(c=>c.isDragging)})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&G(r)||!r)return!1;let{segmentMidpoint:s}=t.pointerDownState;if(s.added||s.value===null||s.index===null||t.pointerDownState.origin===null)return!1;let a=t.pointerDownState.origin,l=Cn(B(a.x,a.y),B(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<rm/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.pointerDownState,d={pointerDownState:t.pointerDownState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!G(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.pointerDownState,segmentMidpoint:{...t.pointerDownState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,i,o,r,s,a){if(G(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding!==null&&Qn(s.startBinding)?s.startBinding:null),s?.endBinding!==void 0&&(l.endBinding=s.endBinding!==null&&Qn(s.endBinding)?s.endBinding:null),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1})}else{let l=Cr(t,i),d=Cr(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,p=(d[0]+d[2])/2,m=(d[1]+d[3])/2,f=p-c,E=m-u,h=Te(B(o,r),B(f,E),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+h[0],y:t.y+h[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(G(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=tl(o[0],o[1],r),{width:c,height:u}=ol(a[0],a[1],l,d,s);return Te(B(c,u),B(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&be(n,i,{isDeleted:!0});let r=0,s=0;if(t.points.length%2===1){let a=Math.floor(t.points.length/2),l=e.getPointGlobalCoordinates(t,t.points[a],i);r=l[0]-n.width/2,s=l[1]-n.height/2}else{let a=t.points.length/2-1,l=e.getSegmentMidPoint(t,a+1);r=l[0]-n.width/2,s=l[1]-n.height/2}return{x:r,y:s}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:p}=e.getBoundTextElementPosition(t,o,n),m=u+o.width,f=p+o.height,E=B(d,c),h=Te(B(r,s),E,t.angle),g=Te(B(a,s),E,t.angle),x=Te(B(u,p),E,-t.angle),y=Te(B(m,p),E,-t.angle),b=Te(B(u,f),E,-t.angle),w=Te(B(m,f),E,-t.angle);return h[0]<g[0]&&h[1]>=g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(y[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):h[0]>=g[0]&&h[1]>g[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],y[0])),s=Math.min(s,b[1]),l=Math.max(l,y[1])):h[0]>=g[0]?(r=Math.min(r,y[0]),a=Math.max(a,b[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):h[1]<=g[1]&&(r=Math.min(r,Math.min(y[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,y[1]),l=Math.max(l,b[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o,r,s,a,l;if(t.points.length<2||!Pe.get(t)){let{minX:p,minY:m,maxX:f,maxY:E}=t.points.reduce((h,[g,x])=>(h.minY=Math.min(h.minY,x),h.minX=Math.min(h.minX,g),h.maxX=Math.max(h.maxX,g),h.maxY=Math.max(h.maxY,x),h),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});r=p+t.x,s=m+t.y,a=f+t.x,l=E+t.y}else{let p=Pe.generateElementShape(t,null),m=gt(p[0]),[f,E,h,g]=ai(m);r=f+t.x,s=E+t.y,a=h+t.x,l=g+t.y}let d=(r+a)/2,c=(s+l)/2;if(o=[r,s,a,l,d,c],!i)return o;let u=W(t,n);return u&&(o=e.getMinMaxXYWithBoundText(t,n,[r,s,a,l],u)),o};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!G(a))return t;if(n&&n>0&&n<a.points.length){let l=Oe(Mt(nm(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((m,f)=>(m[f.index]=f,m),{});d[n]={index:n,start:B(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:B(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((m,f)=>m.index-f.index),u=c.map(m=>m.index).reduce((m,f)=>f<n?m+1:m,0);r.mutateElement(a,{fixedSegments:c});let p=B(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:p,pointerDownState:{...t.pointerDownState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:p}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},lm=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null};P();import{arrayToMap as mt}from"@excalidraw/common";import{isPointWithinBounds as Lm,pointFrom as Rr}from"@excalidraw/math";P();import{vectorCross as ll,vectorFromPoint as lo}from"@excalidraw/math";function rl(e){return[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])]}function dm(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var cm=1e-6;function sl(e,t){let n=lo(e[1],e[0]),i=lo(t,e[0]),o=ll(n,i);return Math.abs(o)<cm}function Br(e,t){let n=lo(e[1],e[0]),i=lo(t,e[0]);return ll(n,i)<0}function al(e,t){return sl(e,t[0])||sl(e,t[1])||(Br(e,t[0])?!Br(e,t[1]):Br(e,t[1]))}function dl(e,t){return dm(rl(e),rl(t))&&al(e,t)&&al(t,e)}P();import{arrayToMap as um}from"@excalidraw/common";import{getElementBounds as pm}from"@excalidraw/element";import{isArrowElement as mm,isExcalidrawElement as fm,isFreeDrawElement as hm,isLinearElement as Em,isTextElement as gm}from"@excalidraw/element";import{rangeIncludesValue as co,pointFrom as Dt,pointRotateRads as xm,rangeInclusive as uo}from"@excalidraw/math";var wm=e=>e.type==="diamond"?[Dt(e.width/2,0),Dt(e.width,e.height/2),Dt(e.width/2,e.height),Dt(0,e.height/2)]:[Dt(0,0),Dt(0+e.width,0),Dt(0+e.width,e.height),Dt(0,e.height)],ym=e=>Em(e)||hm(e)?e.points:wm(e),cl=e=>{let t=e.reduce((n,[i,o])=>(n.minY=Math.min(n.minY,o),n.minX=Math.min(n.minX,i),n.maxX=Math.max(n.maxX,i),n.maxY=Math.max(n.maxY,o),n),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},pl=e=>{let t=ym(e),{cx:n,cy:i}=cl(t),o=Dt(n,i),r=t.map(c=>xm(c,o,e.angle)),{minX:s,minY:a,maxX:l,maxY:d}=cl(r);return[s+e.x,a+e.y,l+e.x,d+e.y]},ul=(e,t,n=!1)=>{let i=pl(e),o=t[0]<=i[0]&&t[2]>=i[2]&&t[1]<=i[1]&&t[3]>=i[3];return n?o?!0:i[0]<=t[0]&&i[2]>=t[2]&&i[1]<=t[1]&&i[3]>=t[3]:o},bm=(e,t)=>{let n=pl(e);return(co(n[0],uo(t[0],t[2]))||co(t[0],uo(n[0],n[2])))&&(co(n[1],uo(t[1],t[3]))||co(t[1],uo(n[1],n[3])))},ml=({elements:e,bounds:t,type:n,errorMargin:i=0})=>{fm(t)&&(t=pm(t,um(e)));let o=[t[0]-i,t[1]-i,t[2]+i,t[3]+i],r=new Set;for(let s of e){if(r.has(s.id))continue;if(n==="overlap"?bm(s,o):n==="inside"?ul(s,o):ul(s,o,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);gm(s)&&s.containerId&&r.add(s.containerId),mm(s)&&(s.startBinding&&r.add(s.startBinding.elementId),s.endBinding&&r.add(s.endBinding?.elementId))}}return e.filter(s=>r.has(s.id))};P();import{arrayToMap as Am,isShallowEqual as Dm}from"@excalidraw/common";P();var Pm=(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}}},fl=function(){let e=null,t=null,n=null,i=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let d={};for(let p of r){let m=p.groupIds;if(a.editingGroupId){let f=m.indexOf(a.editingGroupId);f>-1&&(m=m.slice(0,f))}if(m.length>0){let f=m[m.length-1];d[f]=!0}}let c={},u=s.reduce((p,m)=>{if(m.isDeleted)return p;let f=m.groupIds.find(E=>d[E]);return f&&(p[m.id]=!0,Array.isArray(c[f])?c[f].push(m.id):c[f]=[m.id]),p},{});for(let p of Object.keys(c))c[p].length<2&&d[p]&&(d[p]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:Gr({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):pt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Gr(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),Im=(e,t)=>kr(e,t)!=null,kr=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Sm=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),hl=(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,...Pm(r,n,e)}}}return n.selectedGroupIds},jy=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Mm=(e,t)=>e.groupIds.includes(t),Ae=(e,t)=>{let n=[];for(let i of e.values())Mm(i,t)&&n.push(i);return n},Tm=(e,t)=>e.groupIds.find(n=>t[n]),Wy=(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},Vy=(e,t)=>e.filter(n=>!t[n]),$y=(e,t)=>{let n=new Map;return e.forEach(i=>{let o=i.groupIds.length===0?i.id:i.groupIds[i.groupIds.length-1],r=n.get(o)||[],s=W(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},El=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},gl=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},xl=e=>e.groupIds.length>0,wl=(e,t,n)=>{let i=[...e],o=t?e.indexOf(t):-1,r=o>-1?o:e.length;for(let s=0;s<r;s++)i[s]=n(i[s]);return i},po=(e,t,n)=>{let i=Sm(n),o=e.filter(u=>!ce(u)),r=new Map,s=new Map,a=u=>{let p=s.get(u.id)||[],m=W(u,t);m&&p.push(m),s.set(u.id,[...p,u])},l=(u,p)=>{let m=r.get(p)||[],f=W(u,t);f&&m.push(f),r.set(p,[...m,u])},d=(u,p)=>{let m=u.groupIds.indexOf(p,0);return u.groupIds.slice(0,m).length>0?l(u,u.groupIds[m-1]):a(u)},c=e.every(u=>Im(n,u));return o.forEach(u=>{let p=Tm(u,n.selectedGroupIds);p?i.length===1&&c?d(u,p):l(u,p):a(u)}),Array.from(r.values()).concat(Array.from(s.values()))};var yl=e=>{let t=new Set;return e.forEach(n=>{Z(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},Or=(e,t,n,i=!0)=>{let[o,r,s,a]=_(t,n),l=e.filter(d=>{let[c,u,p,m]=he(d,n),f=vt(d,n);if(f){let[E,h,g,x]=he(f,n);c=Math.max(E,c),u=Math.max(h,u),p=Math.min(g,p),m=Math.min(x,m)}return d.locked===!1&&d.type!=="selection"&&!ce(d)&&o<=c&&r<=u&&s>=p&&a>=m});return l=i?yl(l):l,l=l.filter(d=>{let c=vt(d,n);return c?Zt(d,c,n):!0}),l},ob=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=bl(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},rb=function(){let e=null,t=null,n=null,i=(o,r)=>(n!=null&&o===e&&r.selectedElementIds===t||(n=o.some(s=>r.selectedElementIds[s.id]),e=o,t=r.selectedElementIds),n);return i.clearCache=()=>{e=null,t=null,n=null},i}(),pt=(e,t,n)=>{let i=new Set,o=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){o.push(r),i.add(r.id);continue}if(n?.includeBoundTextElement&&ce(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{Z(s)&&qt(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},sb=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:pt(e,t,{includeBoundTextElement:!0}),Gr=(e,t)=>Dm(t.selectedElementIds,e)?t.selectedElementIds:e,vm=(e,t)=>{let n=e.filter(j);if(n.length===1){let i=n[0],o=i.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===i.id||o.includes(s.id)))return new U(i,Am(t))}return null},ab=(e,t,n)=>({selectedLinearElement:vm(e,t),...fl({editingGroupId:n.editingGroupId,selectedElementIds:yl(e).reduce((i,o)=>(ce(o)||(i[o.id]=!0),i),{})},t,n,null)});var Pl=(e,t,n)=>{let i=mt(e);for(let o of t)if(o.frameId){let r=n.get(o.id),s=n.get(o.frameId),a=r&&i.get(r);a&&be(a,i,{frameId:s??null})}};function Gn(e,t,n){let i=Fr(t,n),o=Fr(e,n);return i.some(s=>o.some(a=>dl(s,a)))}var Il=(e,t,n)=>mo(Or(e,t,n,!1)).filter(i=>!Z(i)&&!i.frameId||i.frameId===t.id),Nr=(e,t,n)=>Or([t],e,n).some(i=>i.id===t.id),yb=(e,t)=>{let n=mt(e);return e.filter(i=>Gn(i,t,n))},Kt=(e,t,n)=>{let[i,o,r,s]=_(t,n),[a,l,d,c]=Xe(e);return i<=a&&o<=l&&r>=d&&s>=c},Zt=(e,t,n)=>Kt([e],t,n)||Gn(e,t,n)||Nr(e,t,n),bb=(e,t,n)=>{let[i,o,r,s]=_(t,n);return Lm(Rr(i,o),Rr(e.x,e.y),Rr(r,s))},Pb=(e,t,n)=>{let i=mt(e),o=t.flatMap(r=>Ae(e,r));return o.length===0?!0:!!o.find(r=>Kt([r],n,i)||Gn(r,n,i))},Ib=(e,t,n)=>{let i=mt(e),o=t.flatMap(r=>Ae(e,r));return o.length===0?!0:o.find(r=>Kt([r],n,i)||Gn(r,n,i))===void 0},Sb=e=>{let t=new Map;for(let n of e){let i=Z(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,qt(e,i))}return t},qt=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Cm=e=>e.filter(t=>Z(t)),Mb=e=>{let t=mt(Cm(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},Tb=(e,t,n,i)=>{let o=qt(e,t.id),r=new Set(o),s=new Set([...Il(e,t,i),...o.filter(p=>Nr(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(!Gn(p,t,i))p.groupIds.length===0&&r.delete(p);else if(p.groupIds.length>0)for(let m of p.groupIds)l.add(m);for(let p of a)if(p.groupIds.length>0){let m=!0;for(let f of p.groupIds)l.has(f)&&(m=!1);m&&r.delete(p)}let d=Array.from(s).filter(p=>p.groupIds.length===0);for(let p of d)r.add(p);let c=Array.from(s).filter(p=>p.groupIds.length>0),u=hl(c,n);for(let[p,m]of Object.entries(u))if(m){let f=Ae(e,p);if(Kt(f,t,i))for(let E of f)r.add(E)}return[...r].filter(p=>!(ie(p)&&p.containerId))},Ab=(e,t,n)=>Bm(mo(e,Il(e,t,n)),t,n),Bm=(e,t,n)=>{let i=[],o=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>o.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>Ae(n,l)));s=!Kt(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},vt=(e,t)=>e.frameId&&t.get(e.frameId)||null,Db=(e,t)=>{let n=new Set,i=mt(e);e=mo(e);for(let s of e)Z(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!(Z(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!o.has(a)){o.add(a);let l=Ae(e,a);if(l.some(d=>Zt(d,t,i)))for(let d of l)r.push(d)}}else Zt(s,t,i)&&r.push(s);return r},Gm=(e,t,n,i)=>{let o=mt(e),r=new Map;for(let d of e.values())d.frameId===n.id&&r.set(d.id,!0);let s=new Set(t.map(d=>d.id)),a=[],l=new Set;for(let d of t)Z(d)&&d.id!==n.id&&l.add(d.id);for(let d of mo(e,t)){if(Z(d)||d.frameId&&l.has(d.frameId)||d.frameId&&i.selectedElementIds[d.id]&&i.selectedElementIds[d.frameId])continue;r.has(d.id)||a.push(d);let c=W(d,o);c&&!s.has(c.id)&&!r.has(c.id)&&a.push(c)}for(let d of a)be(d,o,{frameId:n.id});return e},Sl=(e,t)=>{let n=new Map,i=new Map;for(let o of e)if(o.frameId){n.set(o.id,o);let r=i.get(o.frameId)||[];r.push(o);let s=W(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)be(o,t,{frameId:null})},km=(e,t)=>{let n=qt(e,t.id);return Sl(n,mt(e)),e},vb=(e,t,n,i)=>Gm(km(e,n),t,n,i.state).slice(),Lb=(e,t,n)=>{let i=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),o=new Set(i);if(t.editingGroupId)for(let a of i)a.groupIds.length===0?o.add(a):a.groupIds.flatMap(l=>Ae(e,l)).forEach(l=>o.add(l));let r=new Set,s=mt(e);return o.forEach(a=>{a.frameId&&!Z(a)&&!Ml(a,s,t)&&r.add(a)}),r.size>0&&Sl(r,s),e},mo=(e,t)=>{let n=new Set,i=t||e;for(let s of i.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let o=new Set;for(let s of n)Ae(e,s).some(a=>Z(a))&&o.add(s);let r=[];for(let s of i.values())o.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},Om=(e,t,n)=>{let i=ie(e)&&Ce(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?vt(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:vt(i,t)},Ml=(e,t,n,i)=>{let o=i?.targetFrame??Om(e,t,n);if(!o)return!1;let r=ie(e)&&Ce(e,t)||e,s=l=>{i?.checkedGroups&&r.groupIds.forEach(d=>{i.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[o.id])return!0;if(r.groupIds.length===0)return Zt(r,o,t);for(let l of r.groupIds)if(i?.checkedGroups?.has(l))return i.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>i?.checkedGroups?!i.checkedGroups.has(l):!0).flatMap(l=>Ae(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(pt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(Z(l))return s(!1),!1;for(let l of a)if(Zt(l,o,t))return s(!0),!0;return!1},Cb=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Gn(e,t,i)||Nr(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Kt([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=Ml(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},Rm="Frame",Fm="AI Frame",Nm=e=>Ri(e)?Rm:Fm,Bb=e=>e.name===null?Nm(e):e.name,Gb=(e,t)=>ml({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),kb=e=>{let t=mt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var jm="invert(100%) hue-rotate(180deg) saturate(1.25)",vl=(e,t)=>Ht(e)&&!t.imageCache.has(e.fileId),Ll=(e,t,n)=>n.theme===Dl.DARK&&Ht(e)&&!vl(e,t)&&t.imageCache.get(e.fileId)?.mimeType!==zr.svg,xo=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}},Wm=(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*=_m/100),r},Vm=(e,t,n)=>{let r=xo(e),[s,a,l,d]=_(e,t),c=j(e)||Me(e)?Qt(s,l):e.width,u=j(e)||Me(e)?Qt(a,d):e.height,p=c*window.devicePixelRatio+r*2,m=u*window.devicePixelRatio+r*2,f=n.value;return(p*f>32767||m*f>32767)&&(f=Math.min(32767/p,32767/m)),p*m*f*f>16777216&&(f=Math.sqrt(16777216/(p*m))),p=Math.floor(p*f),m=Math.floor(m*f),{width:p,height:m,scale:f}},Cl=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=xo(e),{width:l,height:d,scale:c}=Vm(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,p=0;if(j(e)||Me(e)){let[g,x]=_(e,t);u=e.x>g?Qt(e.x,g)*window.devicePixelRatio*c:0,p=e.y>x?Qt(e.y,x)*window.devicePixelRatio*c:0,s.translate(u,p)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let m=un.canvas(r);Ll(e,i,o)&&(s.filter=jm),Eo(e,m,s,i,o),s.restore();let f=W(e,t),E=document.createElement("canvas"),h=E.getContext("2d");if(Y(e)&&f){let[g,x,y,b]=_(e,t),w=Math.max(Qt(g,y),Qt(x,b));E.width=w*window.devicePixelRatio*c+a*c*10,E.height=w*window.devicePixelRatio*c+a*c*10,h.translate(E.width/2,E.height/2),h.rotate(e.angle),h.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,I,M]=_(f,t);h.rotate(-e.angle);let D=(E.width-r.width)/2,T=(E.height-r.height)/2,N=E.width/2-(I-g)*window.devicePixelRatio*c-D-a*c,C=E.height/2-(M-x)*window.devicePixelRatio*c-T-a*c;h.translate(-N,-C),h.clearRect(-(f.width/2+fo)*window.devicePixelRatio*c,-(f.height/2+fo)*window.devicePixelRatio*c,(f.width+fo*2)*window.devicePixelRatio*c,(f.height+fo*2)*window.devicePixelRatio*c)}return{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:p,boundTextElementVersion:W(e,t)?.version||null,containingFrameOpacity:vt(e,t)?.opacity||100,boundTextCanvas:E,angle:e.angle,imageCrop:we(e)?e.crop:null}},qb=14,Bl=typeof document<"u"?document.createElement("img"):{src:""};Bl.src=`data:${zr.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var Gl=typeof document<"u"?document.createElement("img"):{src:""};Gl.src=`data:${zr.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var $m=(e,t)=>{t.fillStyle="#E7E7E7",t.fillRect(0,0,e.width,e.height);let n=Math.min(e.width,e.height),i=Math.min(n,Math.min(n*.4,100));t.drawImage(e.status==="error"?Gl:Bl,e.width/2-i/2,e.height/2-i/2,i,i)},Eo=(e,t,n,i,o)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(Pe.get(e));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Pe.get(e).forEach(r=>{t.draw(r)});break}case"freedraw":{n.save(),n.fillStyle=e.strokeColor;let r=Zm(e),s=Pe.get(e);s&&t.draw(s),n.fillStyle=e.strokeColor,n.fill(r),n.restore();break}case"image":{let r=Ht(e)?i.imageCache.get(e.fileId)?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,yt(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight};n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else $m(e,n);break}default:if(ie(e)){let r=Um(e.text),s=r&&!n.canvas.isConnected;s&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",r?"rtl":"ltr"),n.save(),n.font=Ym(e),n.fillStyle=e.strokeColor,n.textAlign=e.textAlign;let a=e.text.replace(/\r\n?/g,`
9
+ `)=>e.reduce((i,o)=>(J(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as br,distanceToLineSegment as Pr,pointRotateRads as Ir}from"@excalidraw/math";import{ellipse as om,ellipseDistanceFromPoint as rm}from"@excalidraw/math/ellipse";var yn=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return sm(e,t,n);case"diamond":return am(e,t,n);case"ellipse":return lm(e,t,n);case"line":case"arrow":case"freedraw":return dm(e,n)}},sm=(e,t,n)=>{let i=fe(e,t),o=Ir(n,i,-e.angle),[r,s]=vn(e);return Math.min(...r.map(a=>Pr(o,a)),...s.map(a=>br(a,o)).filter(a=>a!==null))},am=(e,t,n)=>{let i=fe(e,t),o=Ir(n,i,-e.angle),[r,s]=Dn(e);return Math.min(...r.map(a=>Pr(o,a)),...s.map(a=>br(a,o)).filter(a=>a!==null))},lm=(e,t,n)=>{let i=fe(e,t);return rm(Ir(n,i,-e.angle),om(i,e.width/2,e.height/2))},dm=(e,t)=>{let[n,i]=Wi(e);return Math.min(...n.map(o=>Pr(t,o)),...i.map(o=>br(o,t)))};var eo=e=>{if(e.type==="arrow")return!1;let t=!ka(e.backgroundColor)||dt(e)||Xi(e)||J(e);return e.type==="line"?t&&gn(e.points):e.type==="freedraw"?t&&gn(e.points):t||xe(e)},xm=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{let s=o?Ji(ce(o.x-n,o.y-n),e,ce(o.x+o.width+n,o.y+o.height+n)):!1,a=se(t,i,!0);return!Ji(ce(a[0]-n,a[1]-n),ze(e,ut(a),-t.angle),ce(a[2]+n,a[3]+n))&&!s?!1:(r||eo(t))&&Wt(e,t,i)||Ra(e,t,i,n)||s},wm=(e,t,n,i=0)=>{let[o,r,s,a]=se(t,n);return o-=i,r-=i,s+=i,a+=i,Ji(ce(o,r),e,ce(s,a))},Nw=(e,t)=>!xm(e)&&!ym(e.point,e.element,t)&&wm(e.point,e.element,t),ym=(e,t,n)=>{let i=W(t,n);if(!i)return!1;let o=K(t)?{...i,...k.getBoundTextElementPosition(t,i,n)}:i;return Wt(e,o,n)},bm=(e,[t,n],i,o=0)=>{let r=ce(t,n),s=!q(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=se(e,i);if(!bn(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&q(m)){let p=se(m,i);if(!Zt(r,p))return!1}}let c=$t(e,i,si(fe(e,i),r)),u=yn(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},to=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(cm(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),He(s,!1)&&bm(s,e,n,i?.(s))&&(o.push(s),!ka(s.backgroundColor)))break}return o},Tt=(e,t,n,i)=>{let o=to(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()},$t=(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=se(e,t);if(!bn(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return Im(e,t,n,i,o);case"diamond":return Sm(e,t,n,i,o);case"ellipse":return Mm(e,t,n,i);case"line":case"freedraw":case"arrow":return Pm(e,n,o)}},Ha=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=no(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(!bn(a,l))continue;let d=Fa(s,t);if(d.length>0){for(let c of d)n.push(ze(c,i,o));if(r)return n}}return n},za=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Na(s,t);if(a&&(n.push(ze(a,i,o)),r))return n}return n},Pm=(e,t,n=!1)=>{let[i,o]=Wi(e),r=[];for(let s of i){let a=Na(s,t);if(a&&(r.push(a),n))return r}for(let s of o){let a=no(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(!bn(a,l))continue;let d=Fa(s,t);if(d.length>0&&(r.push(...d),n))return r}return r},Im=(e,t,n,i=0,o=!1)=>{let r=fe(e,t),s=ze(n[0],r,-e.angle),a=ze(n[1],r,-e.angle),l=si(s,a),[d,c]=vn(e,i),u=[];return za(d,l,u,r,e.angle,o),o&&u.length>0||Ha(c,l,u,r,e.angle,o),u},Sm=(e,t,n,i=0,o=!1)=>{let r=fe(e,t),s=ze(n[0],r,-e.angle),a=ze(n[1],r,-e.angle),l=si(s,a),[d,c]=Dn(e,i),u=[];return za(d,l,u,r,e.angle,o),o&&u.length>0||Ha(c,l,u,r,e.angle,o),u},Mm=(e,t,n,i=0)=>{let o=fe(e,t),r=ze(n[0],o,-e.angle),s=ze(n[1],o,-e.angle);return gm(Em(o,e.width/2+i,e.height/2+i),si(r,s)).map(a=>ze(a,o,e.angle))},Ra=(e,t,n,i=1)=>yn(t,n,e)<=i,Wt=(e,t,n)=>{if((K(t)||Ie(t))&&!gn(t.points))return!1;let[i,o,r,s]=se(t,n);if(!Ji(ce(i,o),e,ce(r,s)))return!1;let a=ce((i+r)/2,(o+s)/2),l=um(hm(fm(pm(e,a,.1)),Math.max(t.width,t.height)*2),a),d=si(e,l);return $t(t,n,d).filter((u,m,p)=>p.findIndex(f=>mm(f,u))===m).length%2===1},Sr=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:m}=s,p=fe(s,n);if(s.type==="diamond"){let[h,E,g,x,y,b,w,I]=Ln(s);return[ce(l+h,d+E-a),ce(l+g+a,d+x),ce(l+y,d+b+a),ce(l+w-a,d+I)].map(A=>ze(A,p,m))}if(s.type==="ellipse"){let h=l+c/2,E=d+u/2,g=c/2,x=u/2;return[ce(h,E-x-a),ce(h+g+a,E),ce(h,E+x+a),ce(h-g-a,E)].map(b=>ze(b,p,m))}return[ce(l-a,d-a),ce(l+c+a,d-a),ce(l+c+a,d+u+a),ce(l-a,d+u+a)].map(h=>ze(h,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Wt(s,t,n))};P();import{invariant as _a,isDevEnv as Am,isTestEnv as Tm}from"@excalidraw/common";import{pointFrom as qt,pointFromVector as io,pointRotateRads as oo,pointScaleFromOrigin as ro,pointsEqual as vm,triangleIncludesPoint as Mr,vectorCross as Be,vectorFromPoint as Q,vectorScale as so}from"@excalidraw/math";var me=[1,0],we=[0,1],Ge=[-1,0],_e=[0,-1],vt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?me:t<=-o?Ge:n>i?we:_e},Ce=(e,t)=>vt(Q(e,t)),it=(e,t)=>Oe(Ce(e,t)),ue=(e,t)=>e[0]===t[0]&&e[1]===t[1],Oe=e=>ue(e,me)||ue(e,Ge),Xw=e=>!Oe(e),Dm=(e,t,n)=>{let i=ut(t);(Am()||Tm())&&(_a(e.width>0&&e.height>0,"Diamond element has no width or height"),_a(!vm(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=io(so(Q(oo(qt(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=io(so(Q(oo(qt(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=io(so(Q(oo(qt(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=io(so(Q(oo(qt(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Be(Q(n,r),Q(r,s))<=0&&Be(Q(n,r),Q(r,l))>0)return Ce(r,i);if(Be(Q(n,s),Q(s,a))<=0&&Be(Q(n,s),Q(s,r))>0)return Ce(s,i);if(Be(Q(n,a),Q(a,l))<=0&&Be(Q(n,a),Q(a,s))>0)return Ce(a,i);if(Be(Q(n,l),Q(l,r))<=0&&Be(Q(n,l),Q(l,a))>0)return Ce(l,i);if(Be(Q(n,i),Q(r,i))<=0&&Be(Q(n,i),Q(s,i))>0){let c=e.width>e.height?r:s;return Ce(c,i)}else if(Be(Q(n,i),Q(s,i))<=0&&Be(Q(n,i),Q(a,i))>0){let c=e.width>e.height?a:s;return Ce(c,i)}else if(Be(Q(n,i),Q(a,i))<=0&&Be(Q(n,i),Q(l,i))>0){let c=e.width>e.height?a:l;return Ce(c,i)}let d=e.width>e.height?r:l;return Ce(d,i)},ai=(e,t,n)=>{let o=ut(t);if(e.type==="diamond")return Dm(e,t,n);let r=ro(qt(t[0],t[1]),o,2),s=ro(qt(t[2],t[1]),o,2),a=ro(qt(t[0],t[3]),o,2),l=ro(qt(t[2],t[3]),o,2);return Mr([r,s,o],n)?_e:Mr([s,l,o],n)?me:Mr([l,a,o],n)?we:Ge},Ar=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Vm,randomInteger as kr,getUpdatedTimestamp as Fr}from"@excalidraw/common";P();import{clamp as ao,pointDistance as Dr,pointFrom as Y,pointScaleFromOrigin as Lm,pointsEqual as di,pointTranslate as vr,vector as mt,vectorCross as lo,vectorFromPoint as Lr,vectorScale as Bm}from"@excalidraw/math";import{BinaryHeap as Cm,invariant as Cn,isAnyTrue as Gm,getSizeFromPoints as Ua,isDevEnv as Om,arrayToMap as Rm}from"@excalidraw/common";var Br=1,te=40,km=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>Y(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=Ce(s,l[a-1]),c=Ce(l[a-1],l[a-2]);if(ue(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=Y(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(Dr(l[a-2],l[a-1])<Br){let d=n?.findIndex(m=>m.index===a-2)??-1,c=n?.findIndex(m=>m.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),o.splice(-2,2),n.forEach(m=>{m.index>a-2&&(m.index-=2)});let u=it(s,l[a-1]);return o.push(Y(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?Lt(Or(Rr(Gr(e,Cr(e,t,o.map(s=>Y(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(Om()&&Cn(Za(o),"Invalid elbow points with fixed segments"),Lt(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}},Fm=(e,t,n)=>{let i=t.map(M=>M.index),r=(e.fixedSegments?.map(M=>M.index)??[]).findIndex(M=>!i.includes(M));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,m=l?null:e.endBinding,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...y}=Cr({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[Y(0,0),Y(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:b}=Lt(Or(Rr(Gr(e,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...y})??[])),t,null,null);if(!b||b.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let w=[];if(a)for(let M=0;M<a.index;M++)w.push(Y(e.x+e.points[M][0],e.y+e.points[M][1]));if(b.forEach(M=>{w.push(Y(e.x+(a?a.end[0]:0)+M[0],e.y+(a?a.end[1]:0)+M[1]))}),l)for(let M=l.index;M<e.points.length;M++)w.push(Y(e.x+e.points[M][0],e.y+e.points[M][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,S=t.map(M=>M.index>s?{...M,index:M.index-I+(b.length-1)}:M),A=w.flatMap((M,F)=>{let B=w[F-1],G=w[F+1];if(B&&G){let D=Ce(M,B),V=Ce(G,M);if(ue(D,V))return S.forEach(N=>{N.index>F&&(N.index-=1)}),[];if(ue(D,Ar(V)))return S.forEach(N=>{N.index>F&&(N.index+=1)}),[M,M]}return[M]});return Lt(A,S,!1,!1)},Nm=(e,t,n,i,o,r)=>{let s=t.map((w,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==w.index||(w.start[0]!==e.fixedSegments[I].start[0]&&w.end[0]!==e.fixedSegments[I].end[0])!=(w.start[1]!==e.fixedSegments[I].start[1]&&w.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,d=Dr(t[s].start,t[s].end),c=d<te+5;if(a===-1&&t[s].index===1&&o){let w=Oe(n),S=(w?ue(n,me):ue(n,we))?c?d/2:te:c?-d/2:-te;t[s].start=Y(t[s].start[0]+(w?S:0),t[s].start[1]+(w?0:S))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=Oe(i),S=(w?ue(i,me):ue(i,we))?c?d/2:te:c?-d/2:-te;t[s].end=Y(t[s].end[0]+(w?S:0),t[s].end[1]+(w?0:S))}let u=t.map(w=>({...w,start:Y(e.x+w.start[0],e.y+w.start[1]),end:Y(e.x+w.end[0],e.y+w.end[1])})),m=e.points.map((w,I)=>Y(e.x+w[0],e.y+w[1])),p=u[s].index-1,f=u[s].index,h=u[s].start,E=u[s].end,g=m[p-1]&&!di(m[p],m[p-1])?it(m[p-1],m[p]):void 0,x=m[f+1]&&!di(m[f],m[f+1])?it(m[f+1],m[f]):void 0;if(g!==void 0){let w=g?1:0;m[p-1][w]=h[w]}if(m[p]=h,m[f]=E,x!==void 0){let w=x?1:0;m[f+1][w]=E[w]}let y=u.findIndex(w=>w.index===p);if(y!==-1){let w=it(u[y].end,u[y].start)?1:0;u[y].start[w]=h[w],u[y].end=h}let b=u.findIndex(w=>w.index===f+1);if(b!==-1){let w=it(u[b].end,u[b].start)?1:0;u[b].end[w]=E[w],u[b].start=E}if(a===-1&&p===0){let w=o?Oe(n):it(m[1],m[0]);m.unshift(Y(w?h[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:h[1])),o&&m.unshift(Y(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=o?2:1}if(l===-1&&f===e.points.length-1){let w=Oe(i);m.push(Y(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(Y(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return Lt(m,u.map(w=>({...w,start:Y(w.start[0]-e.x,w.start[1]-e.y),end:Y(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},Hm=(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?Y(e.x+E[0],e.y+E[1]):g===t.length-1?Y(e.x+E[0],e.y+E[1]):Y(e.x+e.points[g][0],e.y+e.points[g][1])),m=n.map(E=>({...E,start:Y(e.x+(E.start[0]-t[0][0]),e.y+(E.start[1]-t[0][1])),end:Y(e.x+(E.end[0]-t[0][0]),e.y+(E.end[1]-t[0][1]))})),p=[],f=2+(d?1:0),h=2+(c?1:0);for(;p.length+f<u.length-h;)p.push(u[p.length+f]);{let E=u.at(d?2:1),g=u.at(d?3:2);if(!E||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=Oe(i),y=Oe(vt(Lr(E,g)));if(a&&x===y){let b=x?ue(i,me):ue(i,we);if(p.unshift(Y(y?r[0]+(b?te:-te):g[0],y?g[1]:r[1]+(b?te:-te))),p.unshift(Y(x?r[0]+(b?te:-te):r[0],x?r[1]:r[1]+(b?te:-te))),!d){d=!0;for(let w of m)w.index>1&&(w.index+=1)}}else if(p.unshift(Y(y?r[0]:E[0],y?E[1]:r[1])),d){d=!1;for(let b of m)b.index>1&&(b.index-=1)}p.unshift(r)}{let E=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!E||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=Oe(o),y=it(g,E);if(l&&x===y){let b=x?ue(o,me):ue(o,we);p.push(Y(y?s[0]+(b?te:-te):g[0],y?g[1]:s[1]+(b?te:-te))),p.push(Y(x?s[0]+(b?te:-te):s[0],x?s[1]:s[1]+(b?te:-te))),c||(c=!0)}else p.push(Y(y?s[0]:E[0],y?E[1]:s[1])),c&&(c=!1)}return p.push(s),Lt(p,m.map(({index:E})=>({index:E,start:p[E-1],end:p[E]})).map(E=>({...E,start:Y(E.start[0]-r[0],E.start[1]-r[1]),end:Y(E.end[0]-r[0],E.end[1]-r[1])})),d,c)},Kt=1e6,Gn=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};v.PROD||(Cn(!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)"),Cn(!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"),Cn(!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"),Cn(e.points.slice(1).map((w,I)=>w[0]===e.points[I][0]||w[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Cn(n.fixedSegments?.find(w=>w.index===1&&di(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&di(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let o=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&uo(d.elementId,t),m=c&&uo(c.elementId,t),p=Za(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 Lt(r.map(w=>Y(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b}=Cr({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?Lt(r.map(w=>Y(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?km(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,I)=>di(w,e.points[I]??Y(1/0,1/0)))&&p?{}:o.length===0?Lt(Or(Rr(Gr(e,{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?Fm(e,o,t):n.points?n.points&&n.fixedSegments?n:Hm(e,r,o,f,h,E,g,x,y):Nm(e,o,f,h,x,y)},Cr=(e,t,n,i)=>{let o=vr(n[0],mt(e.x,e.y)),r=vr(n[n.length-1],mt(e.x,e.y)),s=null,a=null;if(i?.isDragging){let w=Array.from(t.values());s=Wa(o,t,w,i?.zoom)||null,a=Wa(r,t,w,i?.zoom)||null}else s=e.startBinding&&uo(e.startBinding.elementId,t)||null,a=e.endBinding&&uo(e.endBinding.elementId,t)||null;let l=Xa({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging),d=Xa({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging),c=ja(l,d,s,o,t,i?.zoom),u=ja(d,l,a,r,t,i?.zoom),m=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],p=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],f=s?Ze(s,t,Qt(c,e.startArrowhead?Dt(s,{elbowed:!0})*6:Dt(s,{elbowed:!0})*2,1)):m,h=a?Ze(a,t,Qt(u,e.endArrowhead?Dt(a,{elbowed:!0})*6:Dt(a,{elbowed:!0})*2,1)):p,E=Zt(l,a?Ze(a,t,Qt(u,te,te)):p)||Zt(d,s?Ze(s,t,Qt(c,te,te)):m),g=$a(E?[m,p]:[f,h]),x=Um(E?m:f,E?p:h,g,E?Qt(c,!s&&!a?0:te,0):Qt(c,!s&&!a?0:te-(e.startArrowhead?Pn*6:Pn*2),te),E?Qt(u,!s&&!a?0:te,0):Qt(u,!s&&!a?0:te-(e.endArrowhead?Pn*6:Pn*2),te),E,s&&Ze(s,t),a&&Ze(a,t)),y=Ya(x[0],c,l),b=Ya(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:y,startGlobalPoint:l,startHeading:c,endDonglePosition:b,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:E,startElementBounds:f,endElementBounds:h}},Gr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Ym(n,i||o,r,s||a,l,d),m=i&&co(i,u),p=s&&co(s,u),f=co(a,u);f&&c&&(f.closed=!0);let h=co(o,u);h&&e.startBinding&&(h.closed=!0);let E=m&&p&&(Zt(m.pos,n[1])||Zt(p.pos,n[0])),g=zm(m||h,p||f,u,r||me,l||me,E?[]:n);if(g){let x=g.map(y=>[y.pos[0],y.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},Qt=(e,t,n)=>{switch(e){case _e:return[t,n,n,n];case me:return[n,t,n,n];case we:return[n,n,t,n]}return[n,n,n,t]},zm=(e,t,n,i,o,r)=>{let s=Tr(e.pos,t.pos),a=new Cm(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return _m(e,l);l.closed=!0;let d=jm(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=Lm(u.pos,l.pos,.5);if(Gm(...r.map(b=>Zt(m,b))))continue;let p=Wm(c),f=l.parent?vt(Lr(l.pos,l.parent.pos)):i,h=Ar(f);if(ue(h,p)||Va(e.addr,u.addr)&&ue(p,i)||Va(t.addr,u.addr)&&ue(p,o))continue;let g=f!==p,x=l.g+Tr(u.pos,l.pos)+(g?Math.pow(s,3):0),y=u.visited;if(!y||x<u.g){let b=Xm(u,t,p,o);u.visited=!0,u.parent=l,u.h=Tr(t.pos,u.pos)+b*Math.pow(s,2),u.g=x,u.f=u.g+u.h,y?a.rescoreElement(u):a.push(u)}}}return null},_m=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},Tr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Um=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,m,p]=i??[0,0,0,0],[f,h,E,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-p):(l[0]+d[2])/2:e[0]>t[0]?e[0]-p:n[0]-p,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+m):(l[3]+d[1])/2:e[3]<t[3]?e[3]+m:n[3]+m],y=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-f):(d[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+h):(d[2]+l[0])/2:t[2]<e[2]?t[2]+h:n[2]+h,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+E):(d[3]+l[1])/2:t[3]<e[3]?t[3]+E:n[3]+E],b=$a([x,y]);if(!r&&x[2]-x[0]+y[2]-y[0]>b[2]-b[0]+1e-11&&x[3]-x[1]+y[3]-y[1]>b[3]-b[1]+1e-11){let[w,I]=[(y[0]+y[2])/2,(y[1]+y[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let S=x[2]+(y[0]-x[2])/2,A=y[3]+(x[1]-y[3])/2;return lo(mt(e[2]-w,e[1]-I),mt(e[0]-w,e[3]-I))>0?[[x[0],x[1],S,x[3]],[S,y[1],y[2],y[3]]]:[[x[0],A,x[2],x[3]],[y[0],y[1],y[2],A]]}else if(e[2]<t[0]&&e[3]<t[1]){let S=x[2]+(y[0]-x[2])/2,A=x[3]+(y[1]-x[3])/2;return lo(mt(e[0]-w,e[1]-I),mt(e[2]-w,e[3]-I))>0?[[x[0],x[1],x[2],A],[y[0],A,y[2],y[3]]]:[[x[0],x[1],S,x[3]],[S,y[1],y[2],y[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let S=y[2]+(x[0]-y[2])/2,A=x[3]+(y[1]-x[3])/2;return lo(mt(e[2]-w,e[1]-I),mt(e[0]-w,e[3]-I))>0?[[S,x[1],x[2],x[3]],[y[0],y[1],S,y[3]]]:[[x[0],x[1],x[2],A],[y[0],A,y[2],y[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let S=y[2]+(x[0]-y[2])/2,A=y[3]+(x[1]-y[3])/2;return lo(mt(e[0]-w,e[1]-I),mt(e[2]-w,e[3]-I))>0?[[S,x[1],x[2],x[3]],[y[0],y[1],S,y[3]]]:[[x[0],A,x[2],x[3]],[y[0],y[1],y[2],A]]}}return[x,y]},Ym=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===Ge||n===me?a.add(t[1]):s.add(t[0]),o===Ge||o===me?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]})))}},Ya=(e,t,n)=>{switch(t){case _e:return Y(n[0],e[1]);case me:return Y(e[2],n[1]);case we:return Y(n[0],e[3])}return Y(e[0],n[1])},Xm=(e,t,n,i)=>{if(i===me)switch(n){case me:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case _e:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Ge:return e.pos[1]===t.pos[1]?4:2}else if(i===Ge)switch(n){case me:return e.pos[1]===t.pos[1]?4:2;case _e:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Ge:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===_e)switch(n){case me:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case _e:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case we:return e.pos[0]===t.pos[0]?4:2;case Ge:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===we)switch(n){case me:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case _e:return e.pos[0]===t.pos[0]?4:2;case we:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case Ge:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},jm=([e,t],n)=>[li([e,t-1],n),li([e+1,t],n),li([e,t+1],n),li([e-1,t],n)],li=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,co=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=li([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},$a=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]))],uo=(e,t)=>{let n=t.get(e);return n&&He(n)?n:null},Lt=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>vr(a,Bm(Lr(e[0]),-1)));return(o<-Kt||o>Kt||r<-Kt||r>Kt||o+s[s.length-1][0]<-Kt||r+s[s.length-1][0]>Kt||o+s[s.length-1][1]<-Kt||r+s[s.length-1][1]>Kt)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...Ua(s)}),s=s.map(([a,l])=>Y(ao(a,-1e6,1e6),ao(l,-1e6,1e6))),{points:s,x:ao(o,-1e6,1e6),y:ao(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Ua(s),startIsSpecial:n,endIsSpecial:i}},Or=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},Rr=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Dr(i,t)>Br}):e,Wm=e=>{switch(e){case 0:return _e;case 1:return me;case 2:return we}return Ge},Xa=(e,t,n,i,o,r,s)=>s?o&&r?mo(e,o,t,r):i:o?Jt(n||[0,0],o,r??Rm([o])):i,ja=(e,t,n,i,o,r)=>qa(e,t,n,n&&Ze(n,o,Array(4).fill(yn(n,o,e))),i,o,r),Wa=(e,t,n,i)=>Tt(e,n,t,o=>ci(i)),Va=(e,t)=>e[0]===t[0]&&e[1]===t[1],Za=(e,t=Br)=>e.slice(1).map((n,i)=>Math.abs(n[0]-e[i][0])<t||Math.abs(n[1]-e[i][1])<t).every(Boolean);var ye=(e,t,n,i)=>{let o=!1,{points:r,fixedSegments:s,fileId:a}=n;U(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...Gn({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Vm(r),...n});for(let l in n){let d=n[l];if(typeof d<"u"){if(e[l]===d&&(typeof d!="object"||d===null||l==="groupIds"||l==="scale"))continue;if(l==="scale"){let c=e[l],u=d;if(c[0]===u[0]&&c[1]===u[1])continue}else if(l==="points"){let c=e[l],u=d;if(c.length===u.length){let m=!1,p=c.length;for(;--p;){let f=c[p],h=u[p];if(f[0]!==h[0]||f[1]!==h[1]){m=!0;break}}if(!m)continue}}e[l]=d,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof a<"u"||typeof r<"u")&&Me.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??kr(),e.updated=Fr()),e},ge=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??kr(),updated:Fr()}},Ka=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=kr(),e.updated=Fr(),e);var tl=10,Pn=5,Dt=(e,t)=>(t.elbowed?Pn:tl)+e.strokeWidth/2,ci=e=>{let t=Math.max(tl,15),n=e?.value&&e.value<1?e.value:1;return Nr(t/(n*1.5),t,t*2)},Py=e=>!e[$m.CTRL_OR_CMD],fi=e=>e.isBindingEnabled,nl=(e,t,n,i,o)=>{let{start:r,end:s}=Hr(e,t,n.getNonDeletedElementsMap(),n.getNonDeletedElements(),i,{...o,finalize:!0});if(Qa(e,r,"start",n),Qa(e,s,"end",n),r.focusPoint||s.focusPoint){let a=new Map;r.focusPoint&&a.set(0,{point:Fn(e,"startBinding",e.startBinding,r.element,n.getNonDeletedElementsMap())||e.points[0]}),s.focusPoint&&a.set(e.points.length-1,{point:Fn(e,"endBinding",e.endBinding,s.element,n.getNonDeletedElementsMap())||e.points[e.points.length-1]}),k.movePoints(e,n,a)}return{start:r,end:s}},Qa=(e,{mode:t,element:n,focusPoint:i},o,r)=>{t===null?qe(e,o,r):t!==void 0&&Eo(e,n,t,o,r,i)},il=(e,t,n,i,o)=>{ot(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;ot(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=k.getPointGlobalCoordinates(e,a,n),d=Tt(l,i,n,m=>ci(o)),c=d?{element:d,mode:"orbit",focusPoint:k.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},Qm=(e,t,n,i,o,r,s,a,l,d,c)=>{let u={mode:void 0},m={mode:void 0},p=e.points.length>2,f=k.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),h=Tt(f,i,n);if(o)return h?u={element:h,mode:"inside",focusPoint:f}:u={mode:null},{start:u,end:m};if(r){let E=l?.selectedLinearElement?.initialState.origin;if(h&&e.startBinding?.elementId===h.id){let g=ne(h.x+h.width/2,h.y+h.height/2);return{start:p?{mode:void 0}:{mode:"inside",element:h,focusPoint:E??g},end:p?{mode:"orbit",element:h,focusPoint:f}:{mode:"inside",element:h,focusPoint:f}}}if(h&&e.startBinding){let g=e.startBinding;if(to(f,i,n).find(y=>y.id===g.elementId)){let y=n.get(e.startBinding.elementId);return ot(y,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:y.id!==h.id?"orbit":"inside",element:y,focusPoint:E??ne(e.x,e.y)},end:{mode:"orbit",element:h,focusPoint:f}}}}if(e.startBinding&&e.startBinding.elementId!==h?.id){let g=n.get(e.startBinding.elementId);ot(g,"Other element must be in the elements map");let y={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:g,focusPoint:c?fe(g,n):E??ne(e.x,e.y)},b=h&&Sr(g,h,n),w;if(h){let I=d==="inside"||d==="skip";w={mode:I&&!b?"inside":"orbit",element:h,focusPoint:f}}else w={mode:null};return{start:p?{mode:void 0}:y,end:w}}if(!e.startBinding)return h?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:h,focusPoint:f}:m={mode:null},{start:u,end:m}}ot(!1,"New arrow creation should not reach here")},Ja=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=Tt(e,o,i),m=n?to(e,o,i).some(E=>E.id===n.elementId):!1,p=n?i.get(n.elementId):null,f=m&&p?qm(p.backgroundColor):!1,h=u&&p&&Sr(p,u,i);return r==="inside"||r==="skip"?(l=u?{element:!m||!p||f?u:p,focusPoint:e,mode:"inside"}:{mode:null},d=a&&u&&u.id===n?.elementId?{mode:null}:d,{current:l,other:d}):u?u.id===t?.elementId&&t.mode==="inside"?{current:{mode:"inside",focusPoint:e,element:u},other:d}:n?n.elementId===u.id?n.mode==="orbit"?(l={element:u,mode:"orbit",focusPoint:e},d={mode:a?null:void 0},{current:l,other:c?{mode:void 0}:d}):(l={element:u,mode:"inside",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):(m&&p&&!f?l={element:p,mode:"inside",focusPoint:e}:l={element:u,mode:"orbit",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):(l={element:u,mode:"orbit",focusPoint:e},{current:l,other:c?{mode:void 0}:d}):{current:{mode:null},other:d}},Hr=(e,t,n,i,o,r)=>Zm("COMPLEX_BINDINGS")?ep(e,t,n,i,o,r):Jm(e,t,n,i,o,r),Jm=(e,t,n,i,o,r)=>{let a=e.points.length-1,l=t.has(0),d=t.has(a),c={mode:void 0},u={mode:void 0};if(ot(e.points.length>1,"Do not attempt to bind linear elements with a single point"),!l&&!d)return{start:c,end:u};if(l&&d)return{start:{mode:null},end:{mode:null}};if(!fi(o))return c=l?{mode:null}:c,u=d?{mode:null}:u,{start:c,end:u};if(U(e))return il(e,t,n,i,r?.zoom);let m=l?e.endBinding:e.startBinding,p=t.get(l?0:a)?.point;ot(p,`Local point must be defined for ${l?"start":"end"} dragging`);let f=k.getPointGlobalCoordinates(e,p,n),h=Tt(f,i,n,I=>ci(o.zoom)),E=h&&Wt(f,h,n),g=m?n.get(m.elementId):void 0,x=m&&g&&Jt(m.fixedPoint,g,n),y=g&&x&&Wt(x,g,n);if(m&&m.elementId===h?.id)return ot(!r?.newArrow||o.selectedLinearElement?.initialState.origin,"appState.selectedLinearElement.initialState.origin must be defined for new arrows"),{start:{mode:"inside",element:h,focusPoint:l?f:r?.newArrow?o.selectedLinearElement.initialState.origin:k.getPointAtIndexGlobalCoordinates(e,0,n)},end:{mode:"inside",element:h,focusPoint:d?f:k.getPointAtIndexGlobalCoordinates(e,-1,n)}};if(r?.altKey)return{start:l?h?{mode:"inside",element:h,focusPoint:f}:{mode:null}:c,end:d?h?{mode:"inside",element:h,focusPoint:f}:{mode:null}:u};let b=h?E?{mode:"inside",element:h,focusPoint:f}:{mode:"orbit",element:h,focusPoint:Ia(e,f,h,l?"start":"end",n)||f}:{mode:null},w=g&&!y&&o.selectedLinearElement?.initialState.altFocusPoint?{mode:"orbit",element:g,focusPoint:o.selectedLinearElement.initialState.altFocusPoint}:{mode:void 0};return{start:l?b:w,end:d?b:w}},ep=(e,t,n,i,o,r)=>{let s=o.bindMode||"orbit",a=0,l=e.points.length-1,d=t.has(a),c=t.has(l),u={mode:void 0},m={mode:void 0};if(ot(e.points.length>1,"Do not attempt to bind linear elements with a single point"),!d&&!c)return{start:u,end:m};if(d&&c)return{start:{mode:null},end:{mode:null}};if(!fi(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(U(e))return il(e,t,n,i);if(r?.newArrow){let{start:p,end:f}=Qm(e,t,n,i,d,c,a,l,o,s,r?.shiftKey);return{start:p,end:f}}if(d){let p=t.get(a)?.point;ot(p,"Local point must be defined for start dragging");let f=k.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=Ja(f,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:h,end:E}}if(c){let p=t.get(l)?.point;ot(p,"Local point must be defined for end dragging");let f=k.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=Ja(f,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:E,end:h}}return{start:u,end:m}},Iy=(e,t,n)=>{e.forEach(i=>{nl(i,new Map,t,n)})},Eo=(e,t,n,i,o,r)=>{let s=o.getNonDeletedElementsMap(),a;U(e)?a={elementId:t.id,mode:"orbit",...sp(e,t,i,s)}:a={elementId:t.id,mode:n,...go(e,t,i,s,r)},o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:a}),el(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},qe=(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},Ue=(e,t,n)=>{if(!He(e))return;let{simultaneouslyUpdated:i}=n??{},o=np(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(s=>{r.set(s.id,s)})),fo(r,e,s=>{if(!H(s)||s.isDeleted||!tp(s,e))return;let a=s.startBinding?r.get(s.startBinding.elementId):null,l=s.endBinding?a?.id===s.endBinding.elementId?a:r.get(s.endBinding.elementId):null;if(o.has(s.id))return;let d=ho(r,s,(u,m)=>{if(u&&He(u)&&(m==="startBinding"||m==="endBinding")&&(e.id===s[m]?.elementId||e.id===s[m==="startBinding"?"endBinding":"startBinding"]?.elementId)){let p=Fn(s,m,s[m],u,r);if(p)return[m==="startBinding"?0:s.points.length-1,{point:p}]}return null}).filter(u=>u!==null);k.movePoints(s,t,new Map(d),{moveMidPointsWithElement:!!a&&a?.id===l?.id});let c=W(s,r);c&&!c.isDeleted&&wn(s,t,!1)})},Sy=(e,t,n,i)=>{H(e)?nl(e,new Map,t,n):Ue(e,t,{...i,changedElements:new Map([[e.id,e]])})},tp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,np=e=>new Set((e||[]).map(t=>t.id)),qa=(e,t,n,i,o,r,s)=>{let a=vt(kn(t,e));return!n||!i?a:ip(o,n,r,s)?ai(n,i,e):vt(kn(e,fe(n,r)))},ip=(e,t,n,i)=>{let o=yn(t,n,e),r=ci(i);return o>r?null:o},mo=(e,t,n,i,o)=>{let r=U(e),s=o&&!r?o[0]:k.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return s;let a=rr(t)?ol(e,t,i,s):s,l=o&&!r?o[1]:k.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),d=Dt(t,e),c=Ze(t,i),u=ut(c),m=null;if(r){let p=Oe(ai(t,c,s)),f=op(e,t,i,a),h=ne(p?u[0]:f[0],p?f[1]:u[1]),E=o??mi(h,On(Rn(po(kn(f,h)),Math.max(t.width,t.height)*2),h));if(m=$t(t,i,E,d).sort(ui)[0],!m){let g=ne(p?f[0]:u[0],p?u[1]:f[1]),x=mi(g,On(Rn(po(kn(f,g)),Math.max(t.width,t.height)*2),g));m=$t(t,i,x,Pn).sort(ui)[0]}}else{let p=o;if(!p){let f=Rn(po(kn(a,l)),Bt(a,l)+Math.max(t.width,t.height)+d*2);p=o??mi(On(f,l),On(Rn(f,-1),l))}m=Bt(a,l)<1?a:$t(t,i,p,d).sort((f,h)=>ui(f,l)-ui(h,l))[0]}return!m||ui(a,m)<Km?a:m},ol=(e,t,n,i)=>{let o=fe(t,n),r=pe(i,o,-t.angle),s=Dt(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?pe(ne(t.x-s,t.y),o,t.angle):pe(ne(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?pe(ne(t.x,t.y+t.height+s),o,t.angle):pe(ne(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?pe(ne(t.x+t.width,t.y+t.height+s),o,t.angle):pe(ne(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?pe(ne(t.x+t.width,t.y-s),o,t.angle):pe(ne(t.x+t.width+s,t.y),o,t.angle):i},op=(e,t,n,i,o=.05)=>{let{x:r,y:s,width:a,height:l,angle:d}=t,c=fe(t,n,-.1,-.1),u=pe(i,c,-d),m=Dt(t,e),p=Nr(o*l,5,80),f=Nr(o*a,5,80);if(Bt(c,u)<m)return i;if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return pe(ne(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return pe(ne(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return pe(ne(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return pe(ne(c[0],s+l+m),c,d);if(t.type==="diamond"){let h=m,E=ne(r+a/4-h,s+l/4-h),g=ne(r+3*a/4+h,s+l/4-h),x=ne(r+a/4-h,s+3*l/4+h),y=ne(r+3*a/4+h,s+3*l/4+h);if(Bt(E,u)<Math.max(f,p))return pe(E,c,d);if(Bt(g,u)<Math.max(f,p))return pe(g,c,d);if(Bt(x,u)<Math.max(f,p))return pe(x,c,d);if(Bt(y,u)<Math.max(f,p))return pe(y,c,d)}return i},rp=(e,t)=>t.width**2+t.height**2-(e.width**2+e.height**2),Fn=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2)return null;let s=Jt(xo(n.fixedPoint),i,o),a=t==="startBinding"?0:e.points.length-1,l=U(e),d=t==="startBinding"?e.endBinding:e.startBinding,c=d&&o.get(d.elementId),u=se(i,o),m=c&&se(c,o),p=c&&rp(i,c)<(t==="endBinding"?1:0),f=m&&bn(u,m),h=!1;if(!f&&!l&&e.startBinding&&e.endBinding&&c&&e.points.length===2){let y=Jt(e.startBinding.fixedPoint,t==="startBinding"?i:c,o),b=Jt(e.endBinding.fixedPoint,t==="endBinding"?i:c,o),w=mi(y,b),I=$t(t==="endBinding"?i:c,o,w,0,!0),S=$t(t==="startBinding"?i:c,o,w,0,!0);I.length>0&&S.length>0&&(h=Bt(I[0],S[0])<40)}let E=(h||f)&&p,g=r;if(!l&&!g){let[y,b,w,I]=k.getElementAbsoluteCoords(e,o),S=ne((y+w)/2,(b+I)/2),A=rr(i)?ol(e,i,o,s):s,M=pe(ne(e.x+e.points[a===0?1:e.points.length-2][0],e.y+e.points[a===0?1:e.points.length-2][1]),S,e.angle),F=Dt(i,e),B=Rn(po(kn(A,M)),Bt(A,M)+Math.max(i.width,i.height)+F*2);g=mi(On(B,M),On(Rn(B,-1),M))}let x=n.mode==="orbit"&&i?E?s:mo({...e,points:[a===0?k.createPointAt(e,o,s[0],s[1],null):e.points[0],...e.points.slice(1,-1),a===e.points.length-1?k.createPointAt(e,o,s[0],s[1],null):e.points[e.points.length-1]]},i,a===0?"start":"end",o,g):s;return k.createPointAt(e,o,x[0],x[1],null)},sp=(e,t,n,i)=>{let o=[t.x,t.y,t.x+t.width,t.y+t.height],r=mo(e,t,n,i),s=ne(o[0]+(o[2]-o[0])/2,o[1]+(o[3]-o[1])/2),a=pe(r,s,-t.angle);return{fixedPoint:xo([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},go=(e,t,n,i,o)=>{let r=o||k.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=ne(t.x+t.width/2,t.y+t.height/2),a=pe(r,s,-t.angle),l=(a[0]-t.x)/t.width,d=(a[1]-t.y)/t.height;return{fixedPoint:xo([l,d])}},rl=(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,Gn(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},My=(e,t)=>{let n=el(e);for(let i of t)en.unbindAffected(n,i,(o,r)=>ye(o,n,r)),tn.unbindAffected(n,i,(o,r)=>ye(o,n,r))},pi=(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},sl=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),fo=(e,t,n)=>{He(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},ho=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(le(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(H(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},en=class{static unbindAffected(t,n,i){n&&ho(t,n,o=>{!o||o.isDeleted||fo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:pi(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||ho(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(H(n)&&i(o,{boundElements:pi(o.boundElements,new Set,new Array(n))}),J(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:pi(o.boundElements,new Set,new Array(n))}))))})}},tn=class{static unbindAffected(t,n,i){n&&fo(t,n,o=>{!o||o.isDeleted||ho(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||fo(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:pi(n.boundElements,new Set([s]))});return}J(o)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===o.id?o.containerId!==n.id&&i(o,{containerId:n.id}):(o.containerId!==null&&i(o,{containerId:null}),i(n,{boundElements:pi(n.boundElements,new Set([o.id]))})))})}},Jt=(e,t,n)=>{let[i,o]=xo(e);return pe(ne(t.x+t.width*i,t.y+t.height*o),fe(t,n),t.angle)},ap=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?Jt(e.startBinding.fixedPoint,n,t):ne(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?Jt(e.endBinding.fixedPoint,i,t):ne(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},al=(e,t)=>{let[n,i]=ap(e,t);return[k.pointFromAbsoluteCoords(e,n,t),k.pointFromAbsoluteCoords(e,i,t)]},xo=e=>e&&(Math.abs(e[0]-.5)<1e-4||Math.abs(e[1]-.5)<1e-4)?e.map(t=>Math.abs(t-.5)<1e-4?.5001:t):e;var _r=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>C(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},k=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,i=!1){this.elementId=t.id,dl(t.points[0],C(0,0))||(console.error("Linear element is not normalized",Error().stack),ye(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.elbowed=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]=X(n.selectionElement,o),f=e.getPointsGlobalCoordinates(l,o).reduce((h,E,g)=>((E[0]>=d&&E[0]<=u&&E[1]>=c&&E[1]<=m||t.shiftKey&&s?.includes(g))&&h.push(g),h),[]).filter(h=>!(U(l)&&h!==0&&h!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:f.length?f:null}})}static handlePointerMove(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elementId:l}=r,d=e.getElement(l,s);Te(d,"Element being dragged must exist in the scene"),Te(d.points.length>1,"Element must have at least 2 points");let c=d.points.length-1,u=d.points[c],m=d.points[c-1],p=r.customLineAngle??El(m,d.points[c]),f=ml(C(i,o),a,s),h=0,E=0;if(zr(t)&&!f&&!d.startBinding&&!d.endBinding){let[I,S]=e._getShiftLockedDelta(d,s,m,C(i,o),t[In.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),A=C(I+m[0],S+m[1]);h=A[0]-u[0],E=A[1]-u[1]}else{let I=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[In.CTRL_OR_CMD]?null:n.getEffectiveGridSize());h=I[0]-u[0],E=I[1]-u[1]}let g=null,{positions:x,updates:y}=hl([c],h,E,s,d,a,n,t.shiftKey,t.altKey);if(e.movePoints(d,n.scene,x,{startBinding:y?.startBinding,endBinding:y?.endBinding,moveMidPointsWithElement:y?.moveMidPointsWithElement}),Le(d,!1)&&fi(n.state)&&(g=y?.suggestedBinding??null),Le(d)&&pl(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!g||pp(n.state.suggestedBinding??[],g)))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&&y?.suggestedBinding?.id!==b.id?fl(d,C(d.x,d.y),b,"start",s):r.initialState.altFocusPoint}},suggestedBinding:g}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);Te(p,"Element being dragged must exist in the scene"),Te(p.points.length>1,"Element must have at least 2 points"),Te(u,"There must be selected points in order to drag them"),l&&u.some((j,$)=>j>0&&j!==p.points.length-1?(u[$]=p.points.length-1,m=p.points.length-1,!0):!1),Te(m>-1&&u.includes(m)&&p.points[m],`There must be a valid lastClickedPoint in order to drag it. selectedPointsIndices(${JSON.stringify(u)}) points(0..${p.points.length-1}) lastClickedPoint(${m})`);let f=p.points[m],h=p.points[m===0?1:m-1],E=u.length===1,g=r.customLineAngle??El(h,p.points[m]),x=u.includes(0),y=u.includes(p.points.length-1),b=ml(C(i,o),a,s),w=0,I=0;if(zr(t)&&E&&!b&&!p.startBinding&&!p.endBinding){let[j,$]=e._getShiftLockedDelta(p,s,h,C(i,o),t[In.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),g),Xe=C(j+h[0],$+h[1]);w=Xe[0]-f[0],I=Xe[1]-f[1]}else{let j=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[In.CTRL_OR_CMD]?null:n.getEffectiveGridSize());w=j[0]-f[0],I=j[1]-f[1]}let S=null,{positions:A,updates:M}=hl(u,w,I,s,p,a,n,t.shiftKey,t.altKey);e.movePoints(p,n.scene,A,{startBinding:M?.startBinding,endBinding:M?.endBinding,moveMidPointsWithElement:M?.moveMidPointsWithElement}),Le(p,!1)&&fi(n.state)&&(x||y)&&(S=M?.suggestedBinding??null),Le(p)&&x!==y&&pl(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),W(p,s)&&wn(p,n.scene,!1);let B=l?y?[p.points.length-1]:[0]:u,G=l?B[0]:m,D=!x&&!y?e.getPointGlobalCoordinates(p,f,s):null,V=G,N=Le(p)&&p.startBinding&&s.get(p.startBinding.elementId),Z=Le(p)&&p.endBinding&&s.get(p.endBinding.elementId),O=y&&N&&M?.suggestedBinding?.id!==N.id?N:x&&Z&&M?.suggestedBinding?.id!==Z.id?Z:null;return{selectedLinearElement:{...r,selectedPointsIndices:B,initialState:{...r.initialState,lastClickedPoint:G,altFocusPoint:!r.initialState.altFocusPoint&&Le(p)&&O?fl(p,C(p.x,p.y),O,"start",s):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:D,hoverPointIndex:V,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)&&fp(c.points,i.zoom.value)&&(bt(c)&&o.mutateElement(c,{...gl(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,o,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,pointerOffset:{x:0,y:0},customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1}}}static getEditorMidPoints=(t,n,i)=>{let o=W(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)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!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&&nn(C(c[0],c[1]),C(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&nn(m[u],C(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r){if(U(t))return o>=0&&o<t.points.length?nn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=nn(n,i);if(t.points.length>2&&t.roundness){let[a,l]=ul(t);Te(a.length===0&&l.length>0,"Only linears built out of curves are supported"),Te(a.length+l.length>=o,"Invalid segment index while calculating mid point"),s=dp(l[o])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(U(t)){Te(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=ll(t.points[n-1],t.points[n]);return C(t.x+r[0],t.y+r[1])}let[i,o]=ul(t);if(Te(i.length===0&&o.length>0||i.length>0&&o.length===0,"Only linears built out of either segments or curves are supported"),Te(i.length+o.length>=n,"Invalid segment index while calculating mid point"),i.length){let r=i[n-1];return ll(r[0],r[1])}if(o.length){let r=o[n-1];return cp(r,.5)}Te(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:c}=r,u=e.getElement(c,l);if(!u)return d;let m=e.getSegmentMidpointHitCoords(r,o,a,l),p=C(o.x,o.y),f=null;if(m)f=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(u,{points:[...u.points,e.createPointAt(u,l,o.x,o.y,t[In.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:p,segmentMidpoint:{value:m,index:f,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let h=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y);(h>=0||m)&&(d.hitElement=u);let[E,g,x,y]=X(u,l),b=(E+x)/2,w=(g+y)/2,I=h>-1&&Ae(C(u.x+u.points[h][0],u.y+u.points[h][1]),C(b,w),u.angle),S=h>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(h)?hp([...r.selectedPointsIndices||[],h]):[h]:null;return d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:h,origin:p,segmentMidpoint:{value:m,index:f,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:S,pointerOffset:I?{x:o.x-I[0],y:o.y-I[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:dl(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(zr(t)&&c.length>=2){let p=c[c.length-2],[f,h]=e._getShiftLockedDelta(d,l,p,C(n,i),t[In.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=C(f+p[0],h+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[In.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]=X(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Ae(C(c+n[0],u+n[1]),C(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=X(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return Ae(C(c+d[0],u+d[1]),C(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=X(t,i),a=C(r,s),l=t.points[o],{x:d,y:c}=t;return l?Ae(C(d+l[0],c+l[1]),a,t.angle):Ae(C(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(U(t))return C(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=X(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=Ae(C(n[0],n[1]),C(l,d),-t.angle);return C(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(nn(C(o,r),C(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=cl(i,o,r),[a,l,d,c]=X(t,n),u=(a+d)/2,m=(l+c)/2,[p,f]=Ae(C(s[0],s[1]),C(u,m),-t.angle);return C(p-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=_r(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){Te(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);Te(s,"The linear element does not exist in the provided Scene"),Te(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((m,p,f)=>{if(++c,m.push(p),o.includes(f)){let E=a[f+1];E||(d=!0),m.push(E?C((p[0]+E[0])/2,(p[1]+E[1])/2):C(p[0],p[1])),l.push(c+1),++c}return m},[]);if(n.mutateElement(s,{points:u}),d){let m=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:C(m[0]+30,m[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!i.includes(u));bt(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=C(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=_r({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];bt(t)&&t.polygon&&(o[0]=C(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=_r({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o){let{points:r}=t;if(bt(t)&&t.polygon){let c=i.get(0),u=i.get(r.length-1);c?i.set(r.length-1,{point:C(c.point[0],c.point[1]),isDragging:c.isDragging}):u&&i.set(0,{point:C(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=i.get(0)?.point??C(0,0),[a,l]=s,d=U(t)?[i.get(0)?.point??r[0],i.get(r.length-1)?.point??r[r.length-1]]:r.map((c,u)=>{let m=i.get(u)?.point??c;return o?.moveMidPointsWithElement&&u!==0&&u!==r.length-1&&!i.has(u)?m:C(m[0]-a,m[1]-l)});e._updatePoints(t,n,d,a,l,o,{isDragging:Array.from(i.values()).some(c=>c.isDragging)})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&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=nn(a,C(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<mp/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})}else{let l=Ur(t,i),d=Ur(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,m=(d[0]+d[2])/2,p=(d[1]+d[3])/2,f=m-c,h=p-u,E=Ae(C(o,r),C(f,h),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+E[0],y:t.y+E[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(U(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=cl(o[0],o[1],r),{width:c,height:u}=xl(a[0],a[1],l,d,s);return Ae(C(c,u),C(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,i)=>{e.getPointsGlobalCoordinates(t,i).length<2&&ye(n,i,{isDeleted:!0});let r=0,s=0;if(t.points.length%2===1){let a=Math.floor(t.points.length/2),l=e.getPointGlobalCoordinates(t,t.points[a],i);r=l[0]-n.width/2,s=l[1]-n.height/2}else{let a=t.points.length/2-1,l=e.getSegmentMidPoint(t,a+1);r=l[0]-n.width/2,s=l[1]-n.height/2}return{x:r,y:s}};static getMinMaxXYWithBoundText=(t,n,i,o)=>{let[r,s,a,l]=i,d=(r+a)/2,c=(s+l)/2,{x:u,y:m}=e.getBoundTextElementPosition(t,o,n),p=u+o.width,f=m+o.height,h=C(d,c),E=Ae(C(r,s),h,t.angle),g=Ae(C(a,s),h,t.angle),x=Ae(C(u,m),h,-t.angle),y=Ae(C(p,m),h,-t.angle),b=Ae(C(u,f),h,-t.angle),w=Ae(C(p,f),h,-t.angle);return E[0]<g[0]&&E[1]>=g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(y[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],y[0])),s=Math.min(s,b[1]),l=Math.max(l,y[1])):E[0]>=g[0]?(r=Math.min(r,y[0]),a=Math.max(a,b[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):E[1]<=g[1]&&(r=Math.min(r,Math.min(y[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,y[1]),l=Math.max(l,b[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=Me.generateElementShape(t,null),r=wt(o[0]),[s,a,l,d]=Ei(r),c=s+t.x,u=a+t.y,m=l+t.x,p=d+t.y,f=(c+m)/2,h=(u+p)/2,E=i&&W(t,n);return E?e.getMinMaxXYWithBoundText(t,n,[c,u,m,p],E):[c,u,m,p,f,h]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!U(a))return t;if(n&&n>0&&n<a.points.length){let l=Oe(vt(lp(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,f)=>(p[f.index]=f,p),{});d[n]={index:n,start:C(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:C(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let c=Object.values(d).sort((p,f)=>p.index-f.index),u=c.map(p=>p.index).reduce((p,f)=>f<n?p+1:p,0);r.mutateElement(a,{fixedSegments:c});let m=C(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:m,initialState:{...t.initialState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:m}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},hp=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},hl=(e,t,n,i,o,r,s,a,l)=>{let d=new Map(e.map(D=>[D,{point:C(o.points[D][0]+t,o.points[D][1]+n),isDragging:!0}]));if(!H(o))return{positions:d};let c=e.includes(0),u=e.includes(o.points.length-1),{start:m,end:p}=Hr(o,d,i,r,s.state,{newArrow:!!s.state.newElement,shiftKey:a,altKey:l});if(U(o))return{positions:d,updates:{suggestedBinding:c?m.element:u?p.element:null}};if(c===u)return{positions:d};let f={suggestedBinding:null};m.mode===null?f.startBinding=null:m.mode?(f.startBinding={elementId:m.element.id,mode:m.mode,...go(o,m.element,"start",i,m.focusPoint)},c&&(f.startBinding.mode==="orbit"||!hi("COMPLEX_BINDINGS"))&&(f.suggestedBinding=m.element)):c&&(f.suggestedBinding=s.state.suggestedBinding),p.mode===null?f.endBinding=null:p.mode?(f.endBinding={elementId:p.element.id,mode:p.mode,...go(o,p.element,"end",i,p.focusPoint)},u&&(f.endBinding.mode==="orbit"||!hi("COMPLEX_BINDINGS"))&&(f.suggestedBinding=p.element)):u&&(f.suggestedBinding=s.state.suggestedBinding);let h=c?C(o.points[0][0]+t,o.points[0][1]+n):o.points[0],E=u?C(o.points[o.points.length-1][0]+t,o.points[o.points.length-1][1]+n):o.points[o.points.length-1],g={...o,points:[h,...o.points.slice(1,-1),E],startBinding:f.startBinding===void 0?o.startBinding:f.startBinding===null?null:f.startBinding,endBinding:f.endBinding===void 0?o.endBinding:f.endBinding===null?null:f.endBinding},x=m.focusPoint&&p.focusPoint?up(m.focusPoint,p.focusPoint):void 0,y=o.endBinding&&g.startBinding&&c&&g.startBinding.elementId===o.endBinding.elementId,b=o.startBinding&&g.endBinding&&u&&o.startBinding.elementId===g.endBinding.elementId,w=g.endBinding?p.element??i.get(g.endBinding.elementId):null,I=y?g.points[g.points.length-1]:b&&s.state.bindMode!=="inside"&&hi("COMPLEX_BINDINGS")?g.points[0]:w&&Fn(o,"endBinding",g.endBinding,w,i,x)||g.points[g.points.length-1];g.points[g.points.length-1]=I;let S=g.startBinding?m.element??i.get(g.startBinding.elementId):null,A=b&&hi("COMPLEX_BINDINGS")?g.points[0]:y&&s.state.bindMode!=="inside"&&hi("COMPLEX_BINDINGS")?g.points[g.points.length-1]:S&&Fn(o,"startBinding",g.startBinding,S,i,x)||g.points[0],M=nn(I,g.points[g.points.length-1])!==0,F=nn(A,g.points[0])!==0,B=new Set(e);S&&F&&B.add(0),w&&M&&B.add(o.points.length-1);let G=Array.from(B);return{updates:f.startBinding||f.suggestedBinding?{startBinding:f.startBinding,suggestedBinding:f.suggestedBinding}:void 0,positions:new Map(G.map(D=>[D,D===0?{point:A,isDragging:!0}:D===o.points.length-1?{point:I,isDragging:!0}:d.get(D)]))}},El=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);P();import{arrayToMap as ft}from"@excalidraw/common";import{isPointWithinBounds as Fp,pointFrom as Vr}from"@excalidraw/math";P();import{vectorCross as Pl,vectorFromPoint as wo}from"@excalidraw/math";function wl(e){return[Math.min(e[0][0],e[1][0]),Math.min(e[0][1],e[1][1]),Math.max(e[0][0],e[1][0]),Math.max(e[0][1],e[1][1])]}function Ep(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var gp=1e-6;function yl(e,t){let n=wo(e[1],e[0]),i=wo(t,e[0]),o=Pl(n,i);return Math.abs(o)<gp}function Yr(e,t){let n=wo(e[1],e[0]),i=wo(t,e[0]);return Pl(n,i)<0}function bl(e,t){return yl(e,t[0])||yl(e,t[1])||(Yr(e,t[0])?!Yr(e,t[1]):Yr(e,t[1]))}function Il(e,t){return Ep(wl(e),wl(t))&&bl(e,t)&&bl(t,e)}P();import{arrayToMap as xp}from"@excalidraw/common";import{getElementBounds as wp}from"@excalidraw/element";import{isArrowElement as yp,isExcalidrawElement as bp,isFreeDrawElement as Pp,isLinearElement as Ip,isTextElement as Sp}from"@excalidraw/element";import{rangeIncludesValue as yo,pointFrom as Ct,pointRotateRads as Mp,rangeInclusive as bo}from"@excalidraw/math";var Ap=e=>e.type==="diamond"?[Ct(e.width/2,0),Ct(e.width,e.height/2),Ct(e.width/2,e.height),Ct(0,e.height/2)]:[Ct(0,0),Ct(0+e.width,0),Ct(0+e.width,e.height),Ct(0,e.height)],Tp=e=>Ip(e)||Pp(e)?e.points:Ap(e),Sl=e=>{let t=e.reduce((n,[i,o])=>(n.minY=Math.min(n.minY,o),n.minX=Math.min(n.minX,i),n.maxX=Math.max(n.maxX,i),n.maxY=Math.max(n.maxY,o),n),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},Al=e=>{let t=Tp(e),{cx:n,cy:i}=Sl(t),o=Ct(n,i),r=t.map(c=>Mp(c,o,e.angle)),{minX:s,minY:a,maxX:l,maxY:d}=Sl(r);return[s+e.x,a+e.y,l+e.x,d+e.y]},Ml=(e,t,n=!1)=>{let i=Al(e),o=t[0]<=i[0]&&t[2]>=i[2]&&t[1]<=i[1]&&t[3]>=i[3];return n?o?!0:i[0]<=t[0]&&i[2]>=t[2]&&i[1]<=t[1]&&i[3]>=t[3]:o},vp=(e,t)=>{let n=Al(e);return(yo(n[0],bo(t[0],t[2]))||yo(t[0],bo(n[0],n[2])))&&(yo(n[1],bo(t[1],t[3]))||yo(t[1],bo(n[1],n[3])))},Tl=({elements:e,bounds:t,type:n,errorMargin:i=0})=>{bp(t)&&(t=wp(t,xp(e)));let o=[t[0]-i,t[1]-i,t[2]+i,t[3]+i],r=new Set;for(let s of e){if(r.has(s.id))continue;if(n==="overlap"?vp(s,o):n==="inside"?Ml(s,o):Ml(s,o,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);Sp(s)&&s.containerId&&r.add(s.containerId),yp(s)&&(s.startBinding&&r.add(s.startBinding.elementId),s.endBinding&&r.add(s.endBinding?.elementId))}}return e.filter(s=>r.has(s.id))};P();import{arrayToMap as Op,isShallowEqual as Rp}from"@excalidraw/common";P();var Dp=(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}}},vl=function(){let e=null,t=null,n=null,i=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let d={};for(let m of r){let p=m.groupIds;if(a.editingGroupId){let f=p.indexOf(a.editingGroupId);f>-1&&(p=p.slice(0,f))}if(p.length>0){let f=p[p.length-1];d[f]=!0}}let c={},u=s.reduce((m,p)=>{if(p.isDeleted)return m;let f=p.groupIds.find(h=>d[h]);return f&&(m[p.id]=!0,Array.isArray(c[f])?c[f].push(p.id):c[f]=[p.id]),m},{});for(let m of Object.keys(c))c[m].length<2&&d[m]&&(d[m]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:Xr({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):pt(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Xr(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),Lp=(e,t)=>jr(e,t)!=null,jr=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Bp=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),Dl=(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,...Dp(r,n,e)}}}return n.selectedGroupIds},tb=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Cp=(e,t)=>e.groupIds.includes(t),ve=(e,t)=>{let n=[];for(let i of e.values())Cp(i,t)&&n.push(i);return n},Gp=(e,t)=>e.groupIds.find(n=>t[n]),nb=(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},ib=(e,t)=>e.filter(n=>!t[n]),ob=(e,t)=>{let n=new Map;return e.forEach(i=>{let o=i.groupIds.length===0?i.id:i.groupIds[i.groupIds.length-1],r=n.get(o)||[],s=W(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},Ll=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},Bl=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},Cl=e=>e.groupIds.length>0,Gl=(e,t,n)=>{let i=[...e],o=t?e.indexOf(t):-1,r=o>-1?o:e.length;for(let s=0;s<r;s++)i[s]=n(i[s]);return i},Po=(e,t,n)=>{let i=Bp(n),o=e.filter(u=>!le(u)),r=new Map,s=new Map,a=u=>{let m=s.get(u.id)||[],p=W(u,t);p&&m.push(p),s.set(u.id,[...m,u])},l=(u,m)=>{let p=r.get(m)||[],f=W(u,t);f&&p.push(f),r.set(m,[...p,u])},d=(u,m)=>{let p=u.groupIds.indexOf(m,0);return u.groupIds.slice(0,p).length>0?l(u,u.groupIds[p-1]):a(u)},c=e.every(u=>Lp(n,u));return o.forEach(u=>{let m=Gp(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 Ol=e=>{let t=new Set;return e.forEach(n=>{q(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},Wr=(e,t,n,i=!0)=>{let[o,r,s,a]=X(t,n),l=e.filter(d=>{let[c,u,m,p]=se(d,n),f=Gt(d,n);if(f){let[h,E,g,x]=se(f,n);c=Math.max(h,c),u=Math.max(E,u),m=Math.min(g,m),p=Math.min(x,p)}return d.locked===!1&&d.type!=="selection"&&!le(d)&&o<=c&&r<=u&&s>=m&&a>=p});return l=i?Ol(l):l,l=l.filter(d=>{let c=Gt(d,n);return c?on(d,c,n):!0}),l},fb=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=Rl(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},hb=function(){let e=null,t=null,n=null,i=(o,r)=>(n!=null&&o===e&&r.selectedElementIds===t||(n=o.some(s=>r.selectedElementIds[s.id]),e=o,t=r.selectedElementIds),n);return i.clearCache=()=>{e=null,t=null,n=null},i}(),pt=(e,t,n)=>{let i=new Set,o=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){o.push(r),i.add(r.id);continue}if(n?.includeBoundTextElement&&le(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{q(s)&&rn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},Eb=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:pt(e,t,{includeBoundTextElement:!0}),Xr=(e,t)=>Rp(t.selectedElementIds,e)?t.selectedElementIds:e,kp=(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 k(i,Op(t))}return null},gb=(e,t,n)=>({selectedLinearElement:kp(e,t),...vl({editingGroupId:n.editingGroupId,selectedElementIds:Ol(e).reduce((i,o)=>(le(o)||(i[o.id]=!0),i),{})},t,n,null)});var kl=(e,t,n)=>{let i=ft(e);for(let o of t)if(o.frameId){let r=n.get(o.id),s=n.get(o.frameId),a=r&&i.get(r);a&&ye(a,i,{frameId:s??null})}};function Nn(e,t,n){let i=$r(t,n),o=$r(e,n);return i.some(s=>o.some(a=>Il(s,a)))}var Fl=(e,t,n)=>Io(Wr(e,t,n,!1)).filter(i=>!q(i)&&!i.frameId||i.frameId===t.id),Zr=(e,t,n)=>Wr([t],e,n).some(i=>i.id===t.id),Lb=(e,t)=>{let n=ft(e);return e.filter(i=>Nn(i,t,n))},sn=(e,t,n)=>{let[i,o,r,s]=X(t,n),[a,l,d,c]=Ye(e);return i<=a&&o<=l&&r>=d&&s>=c},on=(e,t,n)=>sn([e],t,n)||Nn(e,t,n)||Zr(e,t,n),Bb=(e,t,n)=>{let[i,o,r,s]=X(t,n);return Fp(Vr(i,o),Vr(e.x,e.y),Vr(r,s))},Cb=(e,t,n)=>{let i=ft(e),o=t.flatMap(r=>ve(e,r));return o.length===0?!0:!!o.find(r=>sn([r],n,i)||Nn(r,n,i))},Gb=(e,t,n)=>{let i=ft(e),o=t.flatMap(r=>ve(e,r));return o.length===0?!0:o.find(r=>sn([r],n,i)||Nn(r,n,i))===void 0},Ob=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,rn(e,i))}return t},rn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Np=e=>e.filter(t=>q(t)),Rb=e=>{let t=ft(Np(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},kb=(e,t,n,i)=>{let o=rn(e,t.id),r=new Set(o),s=new Set([...Fl(e,t,i),...o.filter(m=>Zr(m,t,i))]),a=o.filter(m=>!s.has(m)),l=new Set(Array.from(s).flatMap(m=>m.groupIds));for(let m of a)if(!Nn(m,t,i))m.groupIds.length===0&&r.delete(m);else if(m.groupIds.length>0)for(let p of m.groupIds)l.add(p);for(let m of a)if(m.groupIds.length>0){let p=!0;for(let f of m.groupIds)l.has(f)&&(p=!1);p&&r.delete(m)}let d=Array.from(s).filter(m=>m.groupIds.length===0);for(let m of d)r.add(m);let c=Array.from(s).filter(m=>m.groupIds.length>0),u=Dl(c,n);for(let[m,p]of Object.entries(u))if(p){let f=ve(e,m);if(sn(f,t,i))for(let h of f)r.add(h)}return[...r].filter(m=>!(J(m)&&m.containerId))},Fb=(e,t,n)=>Hp(Io(e,Fl(e,t,n)),t,n),Hp=(e,t,n)=>{let i=[],o=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>o.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>ve(n,l)));s=!sn(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Gt=(e,t)=>e.frameId&&t.get(e.frameId)||null,Nb=(e,t)=>{let n=new Set,i=ft(e);e=Io(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=ve(e,a);if(l.some(d=>on(d,t,i)))for(let d of l)r.push(d)}}else on(s,t,i)&&r.push(s);return r},zp=(e,t,n,i)=>{let o=ft(e),r=new Map;for(let d of e.values())d.frameId===n.id&&r.set(d.id,!0);let s=new Set(t.map(d=>d.id)),a=[],l=new Set;for(let d of t)q(d)&&d.id!==n.id&&l.add(d.id);for(let d of Io(e,t)){if(q(d)||d.frameId&&l.has(d.frameId)||d.frameId&&i.selectedElementIds[d.id]&&i.selectedElementIds[d.frameId])continue;r.has(d.id)||a.push(d);let c=W(d,o);c&&!s.has(c.id)&&!r.has(c.id)&&a.push(c)}for(let d of a)ye(d,o,{frameId:n.id});return e},Nl=(e,t)=>{let n=new Map,i=new Map;for(let o of e)if(o.frameId){n.set(o.id,o);let r=i.get(o.frameId)||[];r.push(o);let s=W(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)ye(o,t,{frameId:null})},_p=(e,t)=>{let n=rn(e,t.id);return Nl(n,ft(e)),e},Hb=(e,t,n,i)=>zp(_p(e,n),t,n,i.state).slice(),zb=(e,t,n)=>{let i=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),o=new Set(i);if(t.editingGroupId)for(let a of i)a.groupIds.length===0?o.add(a):a.groupIds.flatMap(l=>ve(e,l)).forEach(l=>o.add(l));let r=new Set,s=ft(e);return o.forEach(a=>{a.frameId&&!q(a)&&!Hl(a,s,t)&&r.add(a)}),r.size>0&&Nl(r,s),e},Io=(e,t)=>{let n=new Set,i=t||e;for(let s of i.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let o=new Set;for(let s of n)ve(e,s).some(a=>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},Up=(e,t,n)=>{let i=J(e)&&Se(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Gt(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Gt(i,t)},Hl=(e,t,n,i)=>{let o=i?.targetFrame??Up(e,t,n);if(!o)return!1;let r=J(e)&&Se(e,t)||e,s=l=>{i?.checkedGroups&&r.groupIds.forEach(d=>{i.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[o.id])return!0;if(r.groupIds.length===0)return on(r,o,t);for(let l of r.groupIds)if(i?.checkedGroups?.has(l))return i.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>i?.checkedGroups?!i.checkedGroups.has(l):!0).flatMap(l=>ve(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(pt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(q(l))return s(!1),!1;for(let l of a)if(on(l,o,t))return s(!0),!0;return!1},_b=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Nn(e,t,i)||Zr(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!sn([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=Hl(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},Yp="Frame",Xp="AI Frame",jp=e=>ji(e)?Yp:Xp,Ub=e=>e.name===null?jp(e):e.name,Yb=(e,t)=>Tl({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),Xb=e=>{let t=ft(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Jp="invert(100%) hue-rotate(180deg) saturate(1.25)",Xl=(e,t)=>Xt(e)&&!t.imageCache.has(e.fileId),jl=(e,t,n)=>n.theme===Yl.DARK&&Xt(e)&&!Xl(e,t)&&t.imageCache.get(e.fileId)?.mimeType!==Qr.svg,Do=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}},ef=(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*=$p/100),r},tf=(e,t,n)=>{let r=Do(e),[s,a,l,d]=X(e,t),c=K(e)||Ie(e)?an(s,l):e.width,u=K(e)||Ie(e)?an(a,d):e.height,m=c*window.devicePixelRatio+r*2,p=u*window.devicePixelRatio+r*2,f=n.value;return(m*f>32767||p*f>32767)&&(f=Math.min(32767/m,32767/p)),m*p*f*f>16777216&&(f=Math.sqrt(16777216/(m*p))),m=Math.floor(m*f),p=Math.floor(p*f),{width:m,height:p,scale:f}},Wl=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=Do(e),{width:l,height:d,scale:c}=tf(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(K(e)||Ie(e)){let[g,x]=X(e,t);u=e.x>g?an(e.x,g)*window.devicePixelRatio*c:0,m=e.y>x?an(e.y,x)*window.devicePixelRatio*c:0,s.translate(u,m)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let p=En.canvas(r);jl(e,i,o)&&(s.filter=Jp),To(e,p,s,i),s.restore();let f=W(e,t),h=document.createElement("canvas"),E=h.getContext("2d");if(H(e)&&f){let[g,x,y,b]=X(e,t),w=Math.max(an(g,y),an(x,b));h.width=w*window.devicePixelRatio*c+a*c*10,h.height=w*window.devicePixelRatio*c+a*c*10,E.translate(h.width/2,h.height/2),E.rotate(e.angle),E.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,I,S]=X(f,t);E.rotate(-e.angle);let A=(h.width-r.width)/2,M=(h.height-r.height)/2,F=h.width/2-(I-g)*window.devicePixelRatio*c-A-a*c,B=h.height/2-(S-x)*window.devicePixelRatio*c-M-a*c;E.translate(-F,-B),E.clearRect(-(f.width/2+Mo)*window.devicePixelRatio*c,-(f.height/2+Mo)*window.devicePixelRatio*c,(f.width+Mo*2)*window.devicePixelRatio*c,(f.height+Mo*2)*window.devicePixelRatio*c)}return{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,boundTextElementVersion:W(e,t)?.version||null,containingFrameOpacity:Gt(e,t)?.opacity||100,boundTextCanvas:h,angle:e.angle,imageCrop:xe(e)?e.crop:null}},s0=14,Vl=typeof document<"u"?document.createElement("img"):{src:""};Vl.src=`data:${Qr.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 $l=typeof document<"u"?document.createElement("img"):{src:""};$l.src=`data:${Qr.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 nf=(e,t)=>{t.fillStyle="#E7E7E7",t.fillRect(0,0,e.width,e.height);let n=Math.min(e.width,e.height),i=Math.min(n,Math.min(n*.4,100));t.drawImage(e.status==="error"?$l:Vl,e.width/2-i/2,e.height/2-i/2,i,i)},To=(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(Me.get(e));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Me.get(e).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save(),n.fillStyle=e.strokeColor;let o=of(e),r=Me.get(e);r&&t.draw(r),n.fillStyle=e.strokeColor,n.fill(o),n.restore();break}case"image":{let o=Xt(e)?i.imageCache.get(e.fileId)?.image:void 0;if(o!=null&&!(o instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,It(Math.min(e.width,e.height),e)),n.clip());let{x:r,y:s,width:a,height:l}=e.crop?e.crop:{x:0,y:0,width:o.naturalWidth,height:o.naturalHeight};n.drawImage(o,r,s,a,l,0,0,e.width,e.height)}else nf(e,n);break}default:if(J(e)){let o=qp(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=Zp(e),n.fillStyle=e.strokeColor,n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
10
10
  `).split(`
11
- `),l=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,d=zi(e.fontSize,e.lineHeight),c=Xm(e.fontFamily,e.fontSize,d);for(let u=0;u<a.length;u++)n.fillText(a[u],l,u*d+c);n.restore(),s&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},go=new WeakMap,Tl=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=go.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=W(e,t),l=a?.version||null,d=we(e)?e.crop:null,c=vt(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.boundTextElementVersion!==l||r.imageCrop!==d||r.containingFrameOpacity!==c||Y(e)&&a&&e.angle!==r.angle){let u=Cl(e,t,o,n,i);return u?(go.set(e,u),u):null}return r},Hr=(e,t,n,i,o)=>{let r=e.element,s=xo(r),a=e.scale,[l,d,c,u]=_(r,o),p=((l+c)/2+i.scrollX)*window.devicePixelRatio,m=((d+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=W(r,o);if(Y(r)&&f){let E=(e.boundTextCanvas.width-e.canvas.width)/2,h=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(p,m),t.drawImage(e.boundTextCanvas,-(c-l)/2*window.devicePixelRatio-E/a-s,-(u-d)/2*window.devicePixelRatio-h/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(p,m),t.rotate(r.angle),"scale"in e.element&&!vl(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-p,-m),t.drawImage(e.canvas,(l+i.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(d+i.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),A.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&st(r)){let E=W(r,o),h=lr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((h.x+i.scrollX)*window.devicePixelRatio,(h.y+i.scrollY)*window.devicePixelRatio,et(r,E)*window.devicePixelRatio,ti(r,E)*window.devicePixelRatio)}t.restore()},Kb=(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()},Qb=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=Wm(e,vt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?zm: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=ho.strokeWidth/s.zoom.value,o.strokeStyle=ho.strokeColor,ra(e)&&(o.strokeStyle=s.theme===Dl.LIGHT?"#7affd7":"#1d8264"),ho.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,ho.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(Pe.generateElementShape(e,null),r.isExporting){let[l,d,c,u]=_(e,t),p=(l+c)/2+s.scrollX,m=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);o.save(),o.translate(p,m),o.rotate(e.angle),o.translate(-f,-E),Eo(e,i,o,r,s),o.restore()}else{let l=Tl(e,n,r,s);if(!l)return;Hr(l,o,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(Pe.generateElementShape(e,r),r.isExporting){let[l,d,c,u]=_(e,t),p=(l+c)/2+s.scrollX,m=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);if(ie(e)){let g=Ce(e,t);if(Y(g)){let x=U.getBoundTextElementPosition(g,e,t);f=(c-l)/2-(x.x-l),E=(u-d)/2-(x.y-d)}}o.save(),o.translate(p,m),Ll(e,r,s)&&(o.filter="none");let h=W(e,t);if(Y(e)&&h){let g=document.createElement("canvas"),x=g.getContext("2d"),y=Math.max(Qt(l,c),Qt(d,u)),b=xo(e);g.width=y*s.exportScale+b*10*s.exportScale,g.height=y*s.exportScale+b*10*s.exportScale,x.translate(g.width/2,g.height/2),x.scale(s.exportScale,s.exportScale),f=e.width/2-(e.x-l),E=e.height/2-(e.y-d),x.rotate(e.angle);let w=un.canvas(g);x.translate(-f,-E),Eo(e,w,x,r,s),x.translate(f,E),x.rotate(-e.angle);let[,,,,I,M]=_(h,t),D=(l+c)/2-I,T=(d+u)/2-M;x.translate(-D,-T),x.clearRect(-h.width/2,-h.height/2,h.width,h.height),o.scale(1/s.exportScale,1/s.exportScale),o.drawImage(g,-g.width/2,-g.height/2,g.width,g.height)}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-f,-E),Eo(e,i,o,r,s);o.restore()}else{let l=Tl(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Hm(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&we(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=Cl(Js(l.element,t),n,s.zoom,r,s);c&&Hr(c,o,r,s,n),o.restore()}Hr(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1},kl=new WeakMap([]);function Ol(e){let t=qm(e),n=new Path2D(t);return kl.set(e,n),n}function Zm(e){return kl.get(e)}function qm(e){let t=e.simulatePressure?e.points:e.points.length?e.points.map(([i,o],r)=>[i,o,e.pressures[r]]):[[0,0,.5]],n={simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:i=>Math.sin(i*Math.PI/2),last:!!e.lastCommittedPoint};return Qm($s(t,n))}function Al(e,t){return[(e[0]+t[0])/2,(e[1]+t[1])/2]}var Km=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;function Qm(e){if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Al(i,r[0]),"L",r[0],"Z"):n.push(i,Al(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(Km,"$1")}P();var t0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",n0=e=>e!=="image"&&e!=="frame"&&e!=="magicframe",i0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",o0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Rl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",r0=e=>e==="arrow",s0=e=>e==="arrow";var Pe=class e{static rg=new je;static cache=new WeakMap;static get=t=>e.cache.get(t);static set=(t,n)=>e.cache.set(t,n);static delete=t=>e.cache.delete(t);static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let i=n?.isExporting?void 0:e.get(t);if(i!==void 0)return i;go.delete(t);let o=sf(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:tf.white,embedsValidationStatus:null});return e.cache.set(t,o),o}},of=e=>[8,8+e],zl=e=>[1.5,6+e];function rf(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&&Rl(e.type)||j(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Re=(e,t=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?of(e.strokeWidth):e.strokeStyle==="dotted"?zl(e.strokeWidth):void 0,disableMultiStroke:e.strokeStyle!=="solid",strokeWidth:e.strokeStyle!=="solid"?e.strokeWidth+.5:e.strokeWidth,fillWeight:e.strokeWidth/2,hachureGap:e.strokeWidth*4,roughness:rf(e),stroke:e.strokeColor,preserveVertices:t||e.roughness<Jm.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=li(e.backgroundColor)?void 0:e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return pn(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},Nl=(e,t,n)=>Oi(e)&&(t||oa(e)&&n?.get(e.id)!==!0)&&li(e.backgroundColor)&&li(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:ki(e)?{...e,strokeColor:li(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:li(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Hl=(e,t,n,i,o,r,s)=>{let a=_r(e,t,n,i);if(a===null)return[];let l=(d,c)=>{if(d===null)return[];let[,,u,p,m,f]=d;return[o.line(u,p,m,f,c)]};switch(i){case"dot":case"circle":case"circle_outline":{let[d,c,u]=a;return delete r.strokeLineDash,[o.circle(d,c,u,{...r,fill:i==="circle_outline"?s:e.strokeColor,fillStyle:"solid",stroke:e.strokeColor,roughness:Math.min(.5,r.roughness||0)})]}case"triangle":case"triangle_outline":{let[d,c,u,p,m,f]=a;return delete r.strokeLineDash,[o.polygon([[d,c],[u,p],[m,f],[d,c]],{...r,fill:i==="triangle_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[d,c,u,p,m,f,E,h]=a;return delete r.strokeLineDash,[o.polygon([[d,c],[u,p],[m,f],[E,h],[d,c]],{...r,fill:i==="diamond_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"crowfoot_one":return l(a,r);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[d,c,u,p,m,f]=a;if(e.strokeStyle==="dotted"){let E=zl(e.strokeWidth-1);r.strokeLineDash=[E[0],E[1]-1]}else delete r.strokeLineDash;return r.roughness=Math.min(1,r.roughness||0),[o.line(u,p,d,c,r),o.line(m,f,d,c,r),...i==="crowfoot_one_or_many"?l(_r(e,t,n,"crowfoot_one"),r):[]]}}},na=e=>{let t=new je,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=dt(e.points.reduce((o,r)=>[Math.min(e.x+r[0],o[0]),Math.min(e.y+r[1],o[1]),Math.max(e.x+r[0],o[2]),Math.max(e.y+r[1],o[3])],[1/0,1/0,-1/0,-1/0]));switch(e.type){case"line":case"arrow":{let o=e.points.length?e.points:[de(0,0)];return G(e)?t.path(_l(o,16),n).sets[0].ops:e.roundness?t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Lt(de(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:de(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(de(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Lt(de(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Lt(de(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>de(a[0]-e.x,a[1]-e.y)).flat()}}):o.map((r,s)=>{let a=Lt(de(e.x+r[0],e.y+r[1]),i,e.angle);return{op:s===0?"move":"lineTo",data:de(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let o=jn(e.points,.75);return t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Lt(de(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:de(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(de(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Lt(de(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Lt(de(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>de(a[0]-e.x,a[1]-e.y)).flat()}})}}},sf=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o})=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":{let r;if(e.roundness){let s=e.width,a=e.height,l=yt(Math.min(s,a),e);r=t.path(`M ${l} 0 L ${s-l} 0 Q ${s} 0, ${s} ${l} L ${s} ${a-l} Q ${s} ${a}, ${s-l} ${a} L ${l} ${a} Q 0 ${a}, 0 ${a-l} L 0 ${l} Q 0 0, ${l} 0`,Re(Nl(e,n,o),!0))}else r=t.rectangle(0,0,e.width,e.height,Re(Nl(e,n,o),!1));return r}case"diamond":{let r,[s,a,l,d,c,u,p,m]=Gi(e);if(e.roundness){let f=yt(Math.abs(s-p),e),E=yt(Math.abs(d-a),e);r=t.path(`M ${s+f} ${a+E} L ${l-f} ${d-E}
12
- C ${l} ${d}, ${l} ${d}, ${l-f} ${d+E}
13
- L ${c+f} ${u-E}
14
- C ${c} ${u}, ${c} ${u}, ${c-f} ${u-E}
15
- L ${p+f} ${m+E}
16
- C ${p} ${m}, ${p} ${m}, ${p+f} ${m-E}
17
- L ${s-f} ${a+E}
18
- C ${s} ${a}, ${s} ${a}, ${s+f} ${a+E}`,Re(e,!0))}else r=t.polygon([[s,a],[l,d],[c,u],[p,m]],Re(e));return r}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Re(e));case"line":case"arrow":{let r,s=Re(e),a=e.points.length?e.points:[de(0,0)];if(G(e)?a.every(l=>Math.abs(l[0])<=1e6&&Math.abs(l[1])<=1e6)?r=[t.path(_l(a,16),Re(e,!0))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(a)),r=[]):e.roundness?r=[t.curve(a,s)]:s.fill?r=[t.polygon(a,s)]:r=[t.linearPath(a,s)],e.type==="arrow"){let{startArrowhead:l=null,endArrowhead:d="arrow"}=e;if(l!==null){let c=Hl(e,r,"start",l,t,s,i);r.push(...c)}if(d!==null){let c=Hl(e,r,"end",d,t,s,i);r.push(...c)}}return r}case"freedraw":{let r;if(Ol(e),pn(e.points)){let s=jn(e.points,.75);r=t.curve(s,{...Re(e),stroke:"none"})}else r=null;return r}case"frame":case"magicframe":case"text":case"image":return null;default:return ef(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},_l=(e,t)=>{let n=[];for(let o=1;o<e.length-1;o+=1){let r=e[o-1],s=e[o+1],a=e[o],l=tt(a,r),d=tt(s,a),c=Math.min(t,Fl(e[o],s)/2,Fl(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(" ")},Yl=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Fs(e);case"arrow":case"line":{let n=Pe.get(e)?.[0]??Pe.generateElementShape(e,null)[0],[,,,,i,o]=_(e,t);return ji(e)?_s(e,n,de(e.x,e.y),e.angle,de(i,o)):Hs(n,de(e.x,e.y),e.angle,de(i,o))}case"ellipse":return Ns(e);case"freedraw":{let[,,,,n,i]=_(e,t);return zs(e,de(n,i),ji(e))}}},il=(e,t)=>{let n=[...e.points];if(t){if(!da(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>nf||n.length<4?n.push(de(o[0],o[1])):n[n.length-1]=de(o[0],o[1])}return{polygon:t,points:n}};var Xr=class e{static boundsCache=new WeakMap;static nonRotatedBoundsCache=new WeakMap;static getBounds(t,n,i=!1){let o=i&&t.angle!==0?e.nonRotatedBoundsCache.get(t):e.boundsCache.get(t);if(o?.version&&o.version===t.version&&!ce(t))return o.bounds;if(i&&t.angle!==0){let s=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:s}),s}let r=e.calculateBounds(t,n);return e.boundsCache.set(t,{version:t.version,bounds:r}),r}static calculateBounds(t,n){let i,[o,r,s,a,l,d]=_(t,n);if(Me(t)){let[c,u,p,m]=jr(t.points.map(([f,E])=>se(v(f,E),v(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,p+t.x,m+t.y]}else if(j(t))i=hf(t,l,d,n);else if(t.type==="diamond"){let[c,u]=se(v(l,r),v(l,d),t.angle),[p,m]=se(v(l,a),v(l,d),t.angle),[f,E]=se(v(o,d),v(l,d),t.angle),[h,g]=se(v(s,d),v(l,d),t.angle),x=Math.min(c,p,f,h),y=Math.min(u,m,E,g),b=Math.max(c,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(c*p,u*m),E=Math.hypot(u*p,c*m);i=[l-f,d-E,l+f,d+E]}else{let[c,u]=se(v(o,r),v(l,d),t.angle),[p,m]=se(v(o,a),v(l,d),t.angle),[f,E]=se(v(s,a),v(l,d),t.angle),[h,g]=se(v(s,r),v(l,d),t.angle),x=Math.min(c,p,f,h),y=Math.min(u,m,E,g),b=Math.max(c,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}return i}},_=(e,t,n=!1)=>{if(Me(e))return uf(e);if(j(e))return U.getElementAbsoluteCoords(e,t,n);if(ie(e)){let i=t?Ce(e,t):null;if(Y(i)){let{x:o,y:r}=U.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},Fr=(e,t)=>{let n=Yl(e,t),[i,o,r,s,a,l]=_(e,t),d=v(a,l);if(n.type==="polycurve"){let g=n.data.map(b=>Et(b,10)).flat(),x=0,y=[];for(;x<g.length-1;)y.push(ge(v(g[x][0],g[x][1]),v(g[x+1][0],g[x+1][1]))),x++;return y}else{if(n.type==="polyline")return n.data;if(df(e)){let[h,g]=Pn(e),x=g.map(b=>jl(b,d,e.angle)).flat();return[...Xl(h,d,e.angle),...x]}else if(e.type==="diamond"){let[h,g]=In(e),x=g.map(b=>jl(b,d,e.angle)).flat();return[...Xl(h,d,e.angle),...x]}else if(n.type==="polygon"){if(ie(e)){let x=Ce(e,t);if(x&&j(x))return[ge(v(i,o),v(r,o)),ge(v(r,o),v(r,s)),ge(v(r,s),v(i,s)),ge(v(i,s),v(i,o))]}let h=n.data,g=[];for(let x=0;x<h.length-1;x++)g.push(ge(h[x],h[x+1]));return g}else if(n.type==="ellipse")return cf(e)}let[c,u,p,m,,,f,E]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(h=>se(h,d,e.angle));return[ge(c,u),ge(p,m),ge(c,p),ge(u,m),ge(c,E),ge(p,E),ge(u,f),ge(m,f)]},df=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),Xl=(e,t,n)=>e.map(i=>ge(se(i[0],t,n),se(i[1],t,n))),jl=(e,t,n)=>{let i=Et(e,10),o=0,r=[];for(;o<i.length-1;)r.push(ge(se(v(i[o][0],i[o][1]),t,n),se(v(i[o+1][0],i[o+1][1]),t,n))),o++;return r},cf=e=>{let t=v(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(se(v(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(ge(r[l],r[l+1]));return o.push(ge(r[r.length-1],r[0])),o},R0=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Gi=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]},Wl=(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},Vl=(e,t,n,i)=>{let o=t-e,r=n-t,s=i-n,a=3*o-6*r+3*s,l=6*r-6*o,d=3*o,c=l*l-4*a*d;if(!(c>=0))return!1;let p=null,m=null,f=1/0,E=1/0;return a===0?f=E=-d/l:(f=(-l+Math.sqrt(c))/(2*a),E=(-l-Math.sqrt(c))/(2*a)),f>=0&&f<=1&&(p=Wl(f,e,t,n,i)),E>=0&&E<=1&&(m=Wl(E,e,t,n,i)),[p,m]},Wi=(e,t,n,i)=>{let o=Vl(e[0],t[0],n[0],i[0]),r=Vl(e[1],t[1],n[1],i[1]),s=Math.min(e[0],i[0]),a=Math.max(e[0],i[0]);if(o){let c=o.filter(u=>u!==null);s=Math.min(s,...c),a=Math.max(a,...c)}let l=Math.min(e[1],i[1]),d=Math.max(e[1],i[1]);if(r){let c=r.filter(u=>u!==null);l=Math.min(l,...c),d=Math.max(d,...c)}return[s,l,a,d]},ai=(e,t)=>{let n=v(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=Zl(d);Ur(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=v(d[0],d[1]),u=v(d[2],d[3]),p=v(d[4],d[5]),m=t?t(c):c,f=t?t(u):u,E=t?t(p):p,h=t?t(n):n;n=p;let[g,x,y,b]=Wi(h,m,f,E);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,y),a.maxY=Math.max(a.maxY,b)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},jr=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;for(let[r,s]of e)t=Math.min(t,r),n=Math.min(n,s),i=Math.max(i,r),o=Math.max(o,s);return[t,n,i,o]},uf=e=>{let[t,n,i,o]=jr(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]},pf=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"crowfoot_many":case"crowfoot_one":case"crowfoot_one_or_many":return 20;default:return 15}},mf=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},_r=(e,t,n,i)=>{if(t.length<1)return null;let o=gt(t[0]);if(o.length<1)return null;let r=n==="start"?1:o.length-1,s=o[r].data;Ur(s.length===6,"Op data length is not 6");let a=v(s[4],s[5]),l=v(s[2],s[3]),d=v(s[0],s[1]),c=o[r-1],u=v(0,0);if(c.op==="move"){let H=Zl(c.data);Ur(H!=null,"Op data is not a point"),u=H}else c.op==="bcurveTo"&&(u=v(c.data[4],c.data[5]));let p=(H,te)=>Math.pow(1-H,3)*a[te]+3*H*Math.pow(1-H,2)*l[te]+3*Math.pow(H,2)*(1-H)*d[te]+u[te]*Math.pow(H,3),[m,f]=n==="start"?u:a,[E,h]=[p(.3,0),p(.3,1)],g=Math.hypot(m-E,f-h),x=(m-E)/g,y=(f-h)/g,b=pf(i),w=0;{let[H,te]=n==="end"?e.points[e.points.length-1]:e.points[0],[S,Q]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];w=Math.hypot(H-S,te-Q)}let M=Math.min(b,w*(i==="diamond"||i==="diamond_outline"?.25:.5)),D=m-x*M,T=f-y*M;if(i==="dot"||i==="circle"||i==="circle_outline"){let H=Math.hypot(T-f,D-m)+e.strokeWidth-2;return[m,f,H]}let N=mf(i);if(i==="crowfoot_many"||i==="crowfoot_one_or_many"){let[H,te]=se(v(m,f),v(D,T),Yr(-N)),[S,Q]=se(v(m,f),v(D,T),Yr(N));return[D,T,H,te,S,Q]}let[C,R]=se(v(D,T),v(m,f),-N*Math.PI/180),[L,V]=se(v(D,T),v(m,f),Yr(N));if(i==="diamond"||i==="diamond_outline"){let H,te;if(n==="start"){let[S,Q]=e.points.length>1?e.points[1]:[0,0];[H,te]=se(v(m+M*2,f),v(m,f),Math.atan2(Q-f,S-m))}else{let[S,Q]=e.points.length>1?e.points[e.points.length-2]:[0,0];[H,te]=se(v(m-M*2,f),v(m,f),Math.atan2(f-Q,m-S))}return[m,f,C,R,H,te,L,V]}return[m,f,C,R,L,V]},ff=e=>{let t=un.generator(),n=Re(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},hf=(e,t,n,i)=>{let o=W(e,i);if(e.points.length<2){let[u,p]=e.points[0],[m,f]=se(v(e.x+u,e.y+p),v(t,n),e.angle),E=[m,f,m,f];if(o){let h=U.getMinMaxXYWithBoundText(e,i,[m,f,m,f],o);E=[h[0],h[1],h[2],h[3]]}return E}let s=Pe.get(e)?.[0]??ff(e),a=gt(s),d=ai(a,([u,p])=>se(v(e.x+u,e.y+p),v(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=U.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},he=(e,t,n=!1)=>Xr.getBounds(e,t,n),Xe=(e,t)=>{if(!af(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||$l(e);return e.forEach(a=>{let[l,d,c,u]=he(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]},F0=(e,t)=>{let[n,i,o,r]=Xe(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},Nt=(e,t,n,i)=>{if(!(j(e)||Me(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Ul(0,t,Ul(1,n,e.points,i),i),r;if(Me(e))r=jr(o);else{let c=un.generator(),u=e.roundness?c.curve(o,Re(e)):c.linearPath(o,Re(e)),p=gt(u);r=ai(p)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Cr=(e,t)=>{let n=un.generator(),i=e.roundness==null?n.linearPath(t,Re(e)):n.curve(t,Re(e)),o=gt(i),[r,s,a,l]=ai(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},N0=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=$l(e);return e.forEach(r=>{let[s,a,l,d]=he(r,o),c=lf(v((s+l)/2,(a+d)/2),v(t.x,t.y));c<n&&(n=c,i=r)}),he(i,o)},Ct=e=>{let[t,n,i,o]=Xe(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},H0=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],dt=e=>v(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),$e=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=fe(e,t),[r,s]=se(v(i.minX,i.minY),o,e.angle),[a,l]=se(v(i.maxX,i.minY),o,e.angle),[d,c]=se(v(i.maxX,i.maxY),o,e.angle),[u,p]=se(v(i.minX,i.maxY),o,e.angle),m=[Math.min(r,a,d,u),Math.min(s,l,c,p),Math.max(r,a,d,u),Math.max(s,l,c,p)];if(n){let[f,E,h,g]=n;return[m[0]-g,m[1]-f,m[2]+E,m[3]+h]}return m},An=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],En=(e,t)=>{if(e==null||t==null)return!1;let[n,i,o,r]=e,[s,a,l,d]=t;return n<l&&o>s&&i<d&&r>a},fe=(e,t,n=0,i=0)=>{let[o,r]=dt(he(e,t));return v(o+n,r+i)};var wf=.1,Kl=e=>j(e)||Me(e)?e.points.length<2||e.points.length===2&&Y(e)&&xf(e.points[0],e.points[e.points.length-1],wf):e.width===0&&e.height===0,bl=(e,t,n,i,o)=>{let[r,s,a,l]=he(e,o),d=wo({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=wo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},V0=(e,t,n,i,o,r)=>{let[s,a,l,d]=Xe(e,o),c=wo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=wo({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},Wr=(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)/Bt)*Bt;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}},ol=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Bt)*Bt;if(o){let d=Math.floor(o/Bt)*Bt;Ef(a,d,d+Bt)&&(gf(a,o)<Bt/6?l=o:ql(a)>ql(o)?l=d+Bt:l=d)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,p=-1/d,m=-1,f=i-p*n,E=(c*f-m*u)/(d*m-p*c),h=(u*p-f*d)/(d*m-p*c);r=E-e,s=h-t}return{width:r,height:s}},$0=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 e1=(e,t,n,i)=>{let o=po(e,n.getNonDeletedElementsMap(),i),r=Ct(e);return o.flatMap(s=>{let a=yf(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ue(l,n,{simultaneouslyUpdated:s}),d})})},yf=(e,t,{axis:n,position:i})=>{let o=Ct(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};P();import{arrayToMap as hh,arrayToObject as Gt,assertNever as Dd,isDevEnv as nn,isShallowEqual as vd,isTestEnv as on,randomInteger as Ad}from"@excalidraw/common";P();import{assertNever as Cf,COLOR_PALETTE as Bf,isDevEnv as Gf,isTestEnv as kf,randomId as Of,Emitter as ed,toIterable as kn}from"@excalidraw/common";P();import{ORIG_ID as Sf,randomId as Jl,randomInteger as Mf,arrayToMap as Tf,castArray as Vr,findLastIndex as di,getUpdatedTimestamp as Af,isTestEnv as Df}from"@excalidraw/common";P();import{arrayToMapWithIndex as bf}from"@excalidraw/common";var Pf=e=>{let t=e.slice(),n=new Set,i=r=>{let s=r[0]?.groupIds?.join(""),a=[r[0]],l=[];for(let d of r.slice(1))d.groupIds?.join("")===s?a.push(d):l.push(d);return l.length?[...a,...i(l)]:a},o=new Map;return t.forEach((r,s)=>{if(!o.has(r.id))if(r.groupIds?.length){let a=r.groupIds[r.groupIds.length-1],l=t.slice(s).filter(d=>{let c=d?.groupIds?.some(u=>u===a);return c&&o.set(d.id,!0),c});for(let d of i(l))n.add(d)}else n.add(r)}),n.size!==e.length?(console.error("normalizeGroupElementOrder: lost some elements... bailing!"),e):[...n]},If=e=>{let t=bf(e),n=e.slice(),i=new Set;return n.forEach((o,r)=>{o&&(o.boundElements?.length?(i.add(o),n[r]=null,o.boundElements.forEach(s=>{let a=t.get(s.id);a&&s.type==="text"&&(i.add(a[0]),n[a[1]]=null)})):o.type==="text"&&o.containerId&&t.get(o.containerId)?.[0].boundElements?.find(a=>a.id===o.id)||(i.add(o),n[r]=null))}),i.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...i]},Ql=e=>If(Pf(e));var vf=(e,t,n,i)=>{let o=Zr(n);return Df()&&Lf(o,n.id),o.id=Jl(),o.updated=Af(),i&&(o.seed=Mf(),Ra(o)),o.groupIds=wl(o.groupIds,e,r=>(t.has(r)||t.set(r,Jl()),t.get(r))),o},f1=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=Tf(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(h=>[h.id,h]));if(e.type==="in-place")for(let h of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(h)).forEach(g=>u.set(g.id,g));t=Ql(t);let p=t.slice(),m=h=>{let x=Vr(h).reduce((y,b)=>{if(i.has(b.id))return y;i.set(b.id,!0);let w=vf(n.editingGroupId,o,b,e.randomizeSeed);return i.set(w.id,!0),d.set(w.id,w),a.set(b.id,w.id),l.set(w.id,b),s.push(b),r.push(w),y.push(w),y},[]);return Array.isArray(h)?x:x[0]||null},f=(h,g)=>{if(g){if(h>p.length-1){p.push(...Vr(g));return}p.splice(h+1,0,...Vr(g))}},E=new Set(t.filter(h=>u.has(h.id)&&Z(h)).map(h=>h.id));for(let h of t){if(i.has(h.id)||!u.has(h.id))continue;let g=kr(n,h);if(g){let x=Ae(t,g).flatMap(b=>Z(b)?[...qt(t,b.id),b]:[b]),y=di(p,b=>b.groupIds?.includes(g));f(y,m(x));continue}if(!(h.frameId&&E.has(h.frameId))){if(Z(h)){let x=h.id,y=qt(t,x),b=di(p,w=>w.frameId===x||w.id===x);f(b,m([...y,h]));continue}if(st(h)){let x=W(h,c),y=di(p,b=>b.id===h.id||"containerId"in b&&b.containerId===h.id);x?f(y,m([h,x])):f(y,m(h));continue}if(ce(h)){let x=Ce(h,c),y=di(p,b=>b.id===h.id||b.id===x?.id);x?f(y,m([x,h])):f(y,m(h));continue}f(di(p,x=>x.id===h.id),m(h))}}if(Za(r,a,d),Pl(p,s,a),e.overrides)for(let h of r){let g=l.get(h.id);g&&Object.assign(h,e.overrides({duplicateElement:h,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:p,origIdToDuplicateId:a}},$r=(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]=$r(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=$r(e[i],t+1);return o}return A.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},Zr=e=>$r(e),Lf=(e,t)=>{Object.defineProperty(e,Sf,{value:t,writable:!1,enumerable:!1})};var Fe={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},td=class{constructor(t){this.app=t}onDurableIncrementEmitter=new ed;onStoreIncrementEmitter=new ed;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=tn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Fe.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=tn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?od(t.elements):void 0,t.appState);i=ci.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=tn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=ci.create(o,t),i?s=i:s=Qr.calculate(o,t),!s.isEmpty()){let a=new qr(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=ci.create(r,t)}let o=new Kr(i);this.onStoreIncrementEmitter.trigger(o)}applyChangeToSnapshot(t){let n=this.snapshot,i=this.snapshot.applyChange(t);return n===i?null:i}maybeCloneSnapshot(t,n,i){if(!n&&!i)return null;let o=this.snapshot,r=this.snapshot.maybeClone(t,n,i);return o===r?null:r}flushMicroActions(){for(let t of this.scheduledMicroActions)try{t()}catch(n){console.error("Failed to execute scheduled micro action",n)}this.scheduledMicroActions=[]}processAction(t){let{action:n}=t;if(n===Fe.EVENTUALLY&&!this.onStoreIncrementEmitter.subscribers.length)return;let i;if("change"in t?i=this.applyChangeToSnapshot(t.change):i=this.maybeCloneSnapshot(n,t.elements,t.appState),!i)return;let o="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case Fe.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Fe.NEVER:case Fe.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:Cf(n,"Unknown store action")}}finally{switch(n){case Fe.IMMEDIATELY:case Fe.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Fe.IMMEDIATELY)?t=Fe.IMMEDIATELY:this.scheduledMacroActions.has(Fe.NEVER)?t=Fe.NEVER:t=Fe.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Fe).length)){let t=`There can be at most three store actions scheduled at the same time, but there are "${this.scheduledMacroActions.size}".`;if(console.error(t,this.scheduledMacroActions.values()),kf()||Gf())throw new Error(t)}}},ci=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},yo=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},qr=class extends yo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},Kr=class extends yo{constructor(n){super("ephemeral",n);this.change=n}},Qr=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:Of()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?en.calculate(t.elements,n.elements):en.empty(),o=n.metadata.didAppStateChange?Jt.calculate(t.appState,n.appState):Jt.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,en.restore(i),Jt.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=en.create(n,i,o),a=Jt.create(r);return new this(t,s,a)}static squash(...t){let n=e.empty();for(let i of t)n.elements.squash(i.elements),n.appState.squash(i.appState);return n}static inverse(t){return this.create(t.elements.inverse(),t.appState.inverse())}static applyTo(t,n,i,o){let[r,s]=t.elements.applyTo(n,tn.empty().elements,o),[a,l]=t.appState.applyTo(i,r);return[r,a,s||l]}static applyLatestChanges(t,n,i,o){return this.create(t.elements.applyLatestChanges(n,i,o),t.appState,{id:t.id})}static empty(){return e.create(en.empty(),Jt.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},tn=class e{constructor(t,n,i={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=i}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,i={didElementsChange:!1,didAppStateChange:!1}){return new e(t,nd(n)?n:On(n),i)}static empty(){return new e(new Map,Rf(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of kn(t.elements))this.elements.get(i.id)||(n[i.id]=Ee(i,{isDeleted:!0}));for(let i of kn(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return F.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=On({...this.appState,...t.appState});return e.create(n,i,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,i){let o={shouldCompareHashes:!1};t===Fe.EVENTUALLY&&(o.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,o),s=this.maybeCreateAppStateSnapshot(i,o),a=!1,l=!1;return this.elements!==r&&(a=!0),this.appState!==s&&(l=!0),!a&&!l?this:new e(r,s,{didElementsChange:a,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let i=nd(t)?t:On(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=F.isRightDifferent(this.appState,t);if(!i)return;let o=sd(JSON.stringify(t));if(!(n.shouldCompareHashes&&this._lastChangedAppStateHash===o))return this._lastChangedAppStateHash=o,i}detectChangedElements(t,n={shouldCompareHashes:!1}){if(this.elements===t)return;let i=new Map;for(let r of kn(this.elements))t.get(r.id)||i.set(r.id,Ee(r,{isDeleted:!0}));for(let r of kn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(we(r)&&!Ht(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=rd(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of kn(this.elements))n.set(i.id,i);for(let i of kn(t))n.set(i.id,Zr(i));return n}},id="__observedAppState",Rf=()=>({name:null,editingGroupId:null,viewBackgroundColor:Bf.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),On=e=>{let t={name:e.name,editingGroupId:e.editingGroupId,viewBackgroundColor:e.viewBackgroundColor,selectedElementIds:e.selectedElementIds,selectedGroupIds:e.selectedGroupIds,croppingElementId:e.croppingElementId,activeLockedId:e.activeLockedId,lockedMultiSelections:e.lockedMultiSelections,selectedLinearElement:e.selectedLinearElement?{elementId:e.selectedLinearElement.elementId,isEditing:!!e.selectedLinearElement.isEditing}:null};return Reflect.defineProperty(t,id,{value:!0,enumerable:!1}),t},nd=e=>!!Reflect.get(e,id);P();P();var dd="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Fn(e,t,n){let i=n[0];if(t!=null&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)===i||t&&t.slice(-1)===i)throw new Error("trailing zero");if(t){let s=0;for(;(e[s]||i)===t[s];)s++;if(s>0)return t.slice(0,s)+Fn(e.slice(s),t.slice(s),n)}let o=e?n.indexOf(e[0]):0,r=t!=null?n.indexOf(t[0]):n.length;if(r-o>1){let s=Math.round(.5*(o+r));return n[s]}else return t&&t.length>1?t.slice(0,1):n[o]+Fn(e.slice(1),null,n)}function cd(e){if(e.length!==ud(e[0]))throw new Error("invalid integer part of order key: "+e)}function ud(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("invalid order key head: "+e)}function ui(e){let t=ud(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function ad(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=ui(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function ld(e,t){cd(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])+1;s===t.length?i[r]=t[0]:(i[r]=t[s],o=!1)}if(o){if(n==="Z")return"a"+t[0];if(n==="z")return null;let r=String.fromCharCode(n.charCodeAt(0)+1);return r>"a"?i.push(t[0]):i.pop(),r+i.join("")}else return n+i.join("")}function Ff(e,t){cd(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])-1;s===-1?i[r]=t.slice(-1):(i[r]=t[s],o=!1)}if(o){if(n==="a")return"Z"+t.slice(-1);if(n==="A")return null;let r=String.fromCharCode(n.charCodeAt(0)-1);return r<"Z"?i.push(t.slice(-1)):i.pop(),r+i.join("")}else return n+i.join("")}function Rn(e,t,n=dd){if(e!=null&&ad(e,n),t!=null&&ad(t,n),e!=null&&t!=null&&e>=t)throw new Error(e+" >= "+t);if(e==null){if(t==null)return"a"+n[0];let l=ui(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Fn("",d,n);if(l<t)return l;let c=Ff(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=ui(e),d=e.slice(l.length),c=ld(l,n);return c??l+Fn(d,null,n)}let i=ui(e),o=e.slice(i.length),r=ui(t),s=t.slice(r.length);if(i===r)return i+Fn(o,s,n);let a=ld(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+Fn(o,null,n)}function bo(e,t,n,i=dd){if(n===0)return[];if(n===1)return[Rn(e,t,i)];if(t==null){let s=Rn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Rn(s,t,i),a.push(s);return a}if(e==null){let s=Rn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Rn(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=Rn(e,t,i);return[...bo(e,r,o,i),r,...bo(r,t,n-o-1,i)]}import{arrayToMap as Po}from"@excalidraw/common";var Jr=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Nf=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=l=>`${l?.index}:${l?.id}:${l?.type}:${l?.isDeleted}:${l?.version}:${l?.versionNonce}`,a=e.map(l=>l.index);for(let[l,d]of a.entries()){let c=a[l-1],u=a[l+1];if(es(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&st(e[l])){let p=e[l],m=W(p,Po(e));m&&m.index<=p.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(m)}", "${s(p)}"`)}}if(r.length){let l=new Jr,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(`
11
+ `),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=qi(e.fontSize,e.lineHeight),d=Kp(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}`)}},vo=new WeakMap,_l=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=vo.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=W(e,t),l=a?.version||null,d=xe(e)?e.crop:null,c=Gt(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.boundTextElementVersion!==l||r.imageCrop!==d||r.containingFrameOpacity!==c||H(e)&&a&&e.angle!==r.angle){let u=Wl(e,t,o,n,i);return u?(vo.set(e,u),u):null}return r},Kr=(e,t,n,i,o)=>{let r=e.element,s=Do(r),a=e.scale,[l,d,c,u]=X(r,o),m=((l+c)/2+i.scrollX)*window.devicePixelRatio,p=((d+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=W(r,o);if(H(r)&&f){let h=(e.boundTextCanvas.width-e.canvas.width)/2,E=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(m,p),t.drawImage(e.boundTextCanvas,-(c-l)/2*window.devicePixelRatio-h/a-s,-(u-d)/2*window.devicePixelRatio-E/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(m,p),t.rotate(r.angle),"scale"in e.element&&!Xl(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-m,-p),t.drawImage(e.canvas,(l+i.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(d+i.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),v.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&dt(r)){let h=W(r,o),E=yr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((E.x+i.scrollX)*window.devicePixelRatio,(E.y+i.scrollY)*window.devicePixelRatio,nt(r,h)*window.devicePixelRatio,ri(r,h)*window.devicePixelRatio)}t.restore()},a0=(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()},l0=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=ef(e,Gt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Vp: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=Ao.strokeWidth/s.zoom.value,o.strokeStyle=Ao.strokeColor,fa(e)&&(o.strokeStyle=s.theme===Yl.LIGHT?"#7affd7":"#1d8264"),Ao.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Ao.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(Me.generateElementShape(e,null),r.isExporting){let[l,d,c,u]=X(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),h=(u-d)/2-(e.y-d);o.save(),o.translate(m,p),o.rotate(e.angle),o.translate(-f,-h),To(e,i,o,r),o.restore()}else{let l=_l(e,n,r,s);if(!l)return;Kr(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(Me.generateElementShape(e,r),r.isExporting){let[l,d,c,u]=X(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),h=(u-d)/2-(e.y-d);if(J(e)){let g=Se(e,t);if(H(g)){let x=k.getBoundTextElementPosition(g,e,t);f=(c-l)/2-(x.x-l),h=(u-d)/2-(x.y-d)}}o.save(),o.translate(m,p),jl(e,r,s)&&(o.filter="none");let E=W(e,t);if(H(e)&&E){let g=document.createElement("canvas"),x=g.getContext("2d"),y=Math.max(an(l,c),an(d,u)),b=Do(e);g.width=y*s.exportScale+b*10*s.exportScale,g.height=y*s.exportScale+b*10*s.exportScale,x.translate(g.width/2,g.height/2),x.scale(s.exportScale,s.exportScale),f=e.width/2-(e.x-l),h=e.height/2-(e.y-d),x.rotate(e.angle);let w=En.canvas(g);x.translate(-f,-h),To(e,w,x,r),x.translate(f,h),x.rotate(-e.angle);let[,,,,I,S]=X(E,t),A=(l+c)/2-I,M=(d+u)/2-S;x.translate(-A,-M),x.clearRect(-E.width/2,-E.height/2,E.width,E.height),o.scale(1/s.exportScale,1/s.exportScale),o.drawImage(g,-g.width/2,-g.height/2,g.width,g.height)}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-f,-h),To(e,i,o,r);o.restore()}else{let l=_l(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Wp(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&xe(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=Wl(ua(l.element,t),n,s.zoom,r,s);c&&Kr(c,o,r,s,n),o.restore()}Kr(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1},Zl=new WeakMap([]);function ql(e){let t=rf(e),n=new Path2D(t);return Zl.set(e,n),n}function of(e){return Zl.get(e)}function rf(e){return lf(sf(e))}function d0(e,t,n){let i=se({...e,angle:0},n),o=So((i[0]+i[2])/2,(i[1]+i[3])/2);return Qp(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(zl(r[r.length-1][1],qr(So(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[zl(qr(So(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),qr(So(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}function sf(e){let t=e.simulatePressure?e.points:e.points.length?e.points.map(([i,o],r)=>[i,o,e.pressures[r]]):[[0,0,.5]],n={simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:i=>Math.sin(i*Math.PI/2),last:!0};return sa(t,n)}function Ul(e,t){return[(e[0]+t[0])/2,(e[1]+t[1])/2]}var af=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;function lf(e){if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Ul(i,r[0]),"L",r[0],"Z"):n.push(i,Ul(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(af,"$1")}P();var m0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",p0=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text",f0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",h0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Kl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",E0=e=>e==="arrow",g0=e=>e==="arrow";var Me=class e{static rg=new We;static cache=new WeakMap;static get=t=>e.cache.get(t);static set=(t,n)=>e.cache.set(t,n);static delete=t=>e.cache.delete(t);static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let i=n?.isExporting?void 0:e.get(t);if(i!==void 0)return i;vo.delete(t);let o=hf(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:uf.white,embedsValidationStatus:null});return e.cache.set(t,o),o}},pf=e=>[8,8+e],td=e=>[1.5,6+e];function ff(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&&Kl(e.type)||K(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Re=(e,t=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?pf(e.strokeWidth):e.strokeStyle==="dotted"?td(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:ff(e),stroke:e.strokeColor,preserveVertices:t||e.roughness<df.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=gi(e.backgroundColor)?void 0:e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return gn(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},Jl=(e,t,n)=>Xi(e)&&(t||pa(e)&&n?.get(e.id)!==!0)&&gi(e.backgroundColor)&&gi(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:Yi(e)?{...e,strokeColor:gi(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:gi(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,ed=(e,t,n,i,o,r,s)=>{let a=Jr(e,t,n,i);if(a===null)return[];let l=(d,c)=>{if(d===null)return[];let[,,u,m,p,f]=d;return[o.line(u,m,p,f,c)]};switch(i){case"dot":case"circle":case"circle_outline":{let[d,c,u]=a;return delete r.strokeLineDash,[o.circle(d,c,u,{...r,fill:i==="circle_outline"?s:e.strokeColor,fillStyle:"solid",stroke:e.strokeColor,roughness:Math.min(.5,r.roughness||0)})]}case"triangle":case"triangle_outline":{let[d,c,u,m,p,f]=a;return delete r.strokeLineDash,[o.polygon([[d,c],[u,m],[p,f],[d,c]],{...r,fill:i==="triangle_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[d,c,u,m,p,f,h,E]=a;return delete r.strokeLineDash,[o.polygon([[d,c],[u,m],[p,f],[h,E],[d,c]],{...r,fill:i==="diamond_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"crowfoot_one":return l(a,r);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[d,c,u,m,p,f]=a;if(e.strokeStyle==="dotted"){let h=td(e.strokeWidth-1);r.strokeLineDash=[h[0],h[1]-1]}else delete r.strokeLineDash;return r.roughness=Math.min(1,r.roughness||0),[o.line(u,m,d,c,r),o.line(p,f,d,c,r),...i==="crowfoot_one_or_many"?l(Jr(e,t,n,"crowfoot_one"),r):[]]}}},Sa=e=>{let t=new We,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=ut(e.points.reduce((o,r)=>[Math.min(e.x+r[0],o[0]),Math.min(e.y+r[1],o[1]),Math.max(e.x+r[0],o[2]),Math.max(e.y+r[1],o[3])],[1/0,1/0,-1/0,-1/0]));switch(e.type){case"line":case"arrow":{let o=e.points.length?e.points:[ae(0,0)];return U(e)?t.path(nd(o,16),n).sets[0].ops:e.roundness?t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Ot(ae(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:ae(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Ot(ae(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Ot(ae(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Ot(ae(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>ae(a[0]-e.x,a[1]-e.y)).flat()}}):o.map((r,s)=>{let a=Ot(ae(e.x+r[0],e.y+r[1]),i,e.angle);return{op:s===0?"move":"lineTo",data:ae(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let o=qn(e.points,.75);return t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Ot(ae(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:ae(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Ot(ae(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Ot(ae(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Ot(ae(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>ae(a[0]-e.x,a[1]-e.y)).flat()}})}}},hf=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o})=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":{let r;if(e.roundness){let s=e.width,a=e.height,l=It(Math.min(s,a),e);r=t.path(`M ${l} 0 L ${s-l} 0 Q ${s} 0, ${s} ${l} L ${s} ${a-l} Q ${s} ${a}, ${s-l} ${a} L ${l} ${a} Q 0 ${a}, 0 ${a-l} L 0 ${l} Q 0 0, ${l} 0`,Re(Jl(e,n,o),!0))}else r=t.rectangle(0,0,e.width,e.height,Re(Jl(e,n,o),!1));return r}case"diamond":{let r,[s,a,l,d,c,u,m,p]=Ln(e);if(e.roundness){let f=It(Math.abs(s-m),e),h=It(Math.abs(d-a),e);r=t.path(`M ${s+f} ${a+h} L ${l-f} ${d-h}
12
+ C ${l} ${d}, ${l} ${d}, ${l-f} ${d+h}
13
+ L ${c+f} ${u-h}
14
+ C ${c} ${u}, ${c} ${u}, ${c-f} ${u-h}
15
+ L ${m+f} ${p+h}
16
+ C ${m} ${p}, ${m} ${p}, ${m+f} ${p-h}
17
+ L ${s-f} ${a+h}
18
+ C ${s} ${a}, ${s} ${a}, ${s+f} ${a+h}`,Re(e,!0))}else r=t.polygon([[s,a],[l,d],[c,u],[m,p]],Re(e));return r}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Re(e));case"line":case"arrow":{let r,s=Re(e),a=e.points.length?e.points:[ae(0,0)];if(U(e)?a.every(l=>Math.abs(l[0])<=1e6&&Math.abs(l[1])<=1e6)?r=[t.path(nd(a,16),Re(e,!0))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(a)),r=[]):e.roundness?r=[t.curve(a,s)]:s.fill?r=[t.polygon(a,s)]:r=[t.linearPath(a,s)],e.type==="arrow"){let{startArrowhead:l=null,endArrowhead:d="arrow"}=e;if(l!==null){let c=ed(e,r,"start",l,t,s,i);r.push(...c)}if(d!==null){let c=ed(e,r,"end",d,t,s,i);r.push(...c)}}return r}case"freedraw":{let r;if(ql(e),gn(e.points)){let s=qn(e.points,.75);r=t.curve(s,{...Re(e),stroke:"none"})}else r=null;return r}case"frame":case"magicframe":case"text":case"image":return null;default:return cf(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},nd=(e,t)=>{let n=[];for(let o=1;o<e.length-1;o+=1){let r=e[o-1],s=e[o+1],a=e[o],l=it(a,r),d=it(s,a),c=Math.min(t,Ql(e[o],s)/2,Ql(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(" ")},id=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Zs(e);case"arrow":case"line":{let n=Me.get(e)?.[0]??Me.generateElementShape(e,null)[0],[,,,,i,o]=X(e,t);return eo(e)?Js(e,n,ae(e.x,e.y),e.angle,ae(i,o)):Ks(n,ae(e.x,e.y),e.angle,ae(i,o))}case"ellipse":return qs(e);case"freedraw":{let[,,,,n,i]=X(e,t);return Qs(e,ae(n,i),eo(e))}}},gl=(e,t)=>{let n=[...e.points];if(t){if(!ga(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>mf||n.length<4?n.push(ae(o[0],o[1])):n[n.length-1]=ae(o[0],o[1])}return{polygon:t,points:n}};var ns=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&&!le(t))return o.bounds;if(i&&t.angle!==0){let s=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:s}),s}let r=e.calculateBounds(t,n);return e.boundsCache.set(t,{version:t.version,bounds:r}),r}static calculateBounds(t,n){let i,[o,r,s,a,l,d]=X(t,n);if(Ie(t)){let[c,u,m,p]=is(t.points.map(([f,h])=>oe(L(f,h),L(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=Sf(t,l,d,n);else if(t.type==="diamond"){let[c,u]=oe(L(l,r),L(l,d),t.angle),[m,p]=oe(L(l,a),L(l,d),t.angle),[f,h]=oe(L(o,d),L(l,d),t.angle),[E,g]=oe(L(s,d),L(l,d),t.angle),x=Math.min(c,m,f,E),y=Math.min(u,p,h,g),b=Math.max(c,m,f,E),w=Math.max(u,p,h,g);i=[x,y,b,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),f=Math.hypot(c*m,u*p),h=Math.hypot(u*m,c*p);i=[l-f,d-h,l+f,d+h]}else{let[c,u]=oe(L(o,r),L(l,d),t.angle),[m,p]=oe(L(o,a),L(l,d),t.angle),[f,h]=oe(L(s,a),L(l,d),t.angle),[E,g]=oe(L(s,r),L(l,d),t.angle),x=Math.min(c,m,f,E),y=Math.min(u,p,h,g),b=Math.max(c,m,f,E),w=Math.max(u,p,h,g);i=[x,y,b,w]}return i}},X=(e,t,n=!1)=>{if(Ie(e))return yf(e);if(K(e))return k.getElementAbsoluteCoords(e,t,n);if(J(e)){let i=t?Se(e,t):null;if(H(i)){let{x:o,y:r}=k.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]},$r=(e,t)=>{let n=id(e,t),[i,o,r,s,a,l]=X(e,t),d=L(a,l);if(n.type==="polycurve"){let g=n.data.map(y=>xt(y,10)),x=[];if(bt(e)&&!e.polygon||H(e))for(let y of g){let b=0;for(;b<y.length-1;)x.push(Ee(L(y[b][0],y[b][1]),L(y[b+1][0],y[b+1][1]))),b++}else{let y=g.flat(),b=0;for(;b<y.length-1;)x.push(Ee(L(y[b][0],y[b][1]),L(y[b+1][0],y[b+1][1]))),b++}return x}else{if(n.type==="polyline")return n.data;if(xf(e)){let[E,g]=vn(e),x=g.map(b=>sd(b,d,e.angle)).flat();return[...rd(E,d,e.angle),...x]}else if(e.type==="diamond"){let[E,g]=Dn(e),x=g.map(b=>sd(b,d,e.angle)).flat();return[...rd(E,d,e.angle),...x]}else if(n.type==="polygon"){if(J(e)){let x=Se(e,t);if(x&&K(x))return[Ee(L(i,o),L(r,o)),Ee(L(r,o),L(r,s)),Ee(L(r,s),L(i,s)),Ee(L(i,s),L(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 wf(e)}let[c,u,m,p,,,f,h]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(E=>oe(E,d,e.angle));return[Ee(c,u),Ee(m,p),Ee(c,m),Ee(u,p),Ee(c,h),Ee(m,h),Ee(u,f),Ee(p,f)]},xf=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),rd=(e,t,n)=>e.map(i=>Ee(oe(i[0],t,n),oe(i[1],t,n))),sd=(e,t,n)=>{let i=xt(e,10),o=0,r=[];for(;o<i.length-1;)r.push(Ee(oe(L(i[o][0],i[o][1]),t,n),oe(L(i[o+1][0],i[o+1][1]),t,n))),o++;return r},wf=e=>{let t=L(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(oe(L(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},V0=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Ln=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]},ad=(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},ld=(e,t,n,i)=>{let o=t-e,r=n-t,s=i-n,a=3*o-6*r+3*s,l=6*r-6*o,d=3*o,c=l*l-4*a*d;if(!(c>=0))return!1;let m=null,p=null,f=1/0,h=1/0;return a===0?f=h=-d/l:(f=(-l+Math.sqrt(c))/(2*a),h=(-l-Math.sqrt(c))/(2*a)),f>=0&&f<=1&&(m=ad(f,e,t,n,i)),h>=0&&h<=1&&(p=ad(h,e,t,n,i)),[m,p]},no=(e,t,n,i)=>{let o=ld(e[0],t[0],n[0],i[0]),r=ld(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]},Ei=(e,t)=>{let n=L(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=cd(d);ts(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=L(d[0],d[1]),u=L(d[2],d[3]),m=L(d[4],d[5]),p=t?t(c):c,f=t?t(u):u,h=t?t(m):m,E=t?t(n):n;n=m;let[g,x,y,b]=no(E,p,f,h);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,y),a.maxY=Math.max(a.maxY,b)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},is=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;for(let[r,s]of e)t=Math.min(t,r),n=Math.min(n,s),i=Math.max(i,r),o=Math.max(o,s);return[t,n,i,o]},yf=e=>{let[t,n,i,o]=is(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]},bf=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"crowfoot_many":case"crowfoot_one":case"crowfoot_one_or_many":return 20;default:return 15}},Pf=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},Jr=(e,t,n,i)=>{if(t.length<1)return null;let o=wt(t[0]);if(o.length<1)return null;let r=n==="start"?1:o.length-1,s=o[r].data;ts(s.length===6,"Op data length is not 6");let a=L(s[4],s[5]),l=L(s[2],s[3]),d=L(s[0],s[1]),c=o[r-1],u=L(0,0);if(c.op==="move"){let N=cd(c.data);ts(N!=null,"Op data is not a point"),u=N}else c.op==="bcurveTo"&&(u=L(c.data[4],c.data[5]));let m=(N,Z)=>Math.pow(1-N,3)*a[Z]+3*N*Math.pow(1-N,2)*l[Z]+3*Math.pow(N,2)*(1-N)*d[Z]+u[Z]*Math.pow(N,3),[p,f]=n==="start"?u:a,[h,E]=[m(.3,0),m(.3,1)],g=Math.hypot(p-h,f-E),x=(p-h)/g,y=(f-E)/g,b=bf(i),w=0;{let[N,Z]=n==="end"?e.points[e.points.length-1]:e.points[0],[O,T]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];w=Math.hypot(N-O,Z-T)}let S=Math.min(b,w*(i==="diamond"||i==="diamond_outline"?.25:.5)),A=p-x*S,M=f-y*S;if(i==="dot"||i==="circle"||i==="circle_outline"){let N=Math.hypot(M-f,A-p)+e.strokeWidth-2;return[p,f,N]}let F=Pf(i);if(i==="crowfoot_many"||i==="crowfoot_one_or_many"){let[N,Z]=oe(L(p,f),L(A,M),es(-F)),[O,T]=oe(L(p,f),L(A,M),es(F));return[A,M,N,Z,O,T]}let[B,G]=oe(L(A,M),L(p,f),-F*Math.PI/180),[D,V]=oe(L(A,M),L(p,f),es(F));if(i==="diamond"||i==="diamond_outline"){let N,Z;if(n==="start"){let[O,T]=e.points.length>1?e.points[1]:[0,0];[N,Z]=oe(L(p+S*2,f),L(p,f),Math.atan2(T-f,O-p))}else{let[O,T]=e.points.length>1?e.points[e.points.length-2]:[0,0];[N,Z]=oe(L(p-S*2,f),L(p,f),Math.atan2(f-T,p-O))}return[p,f,B,G,N,Z,D,V]}return[p,f,B,G,D,V]},If=e=>{let t=En.generator(),n=Re(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},Sf=(e,t,n,i)=>{let o=W(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,f]=oe(L(e.x+u,e.y+m),L(t,n),e.angle),h=[p,f,p,f];if(o){let E=k.getMinMaxXYWithBoundText(e,i,[p,f,p,f],o);h=[E[0],E[1],E[2],E[3]]}return h}let s=Me.get(e)?.[0]??If(e),a=wt(s),d=Ei(a,([u,m])=>oe(L(e.x+u,e.y+m),L(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=k.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},se=(e,t,n=!1)=>ns.getBounds(e,t,n),Ye=(e,t)=>{if(!Ef(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||dd(e);return e.forEach(a=>{let[l,d,c,u]=se(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]},$0=(e,t)=>{let[n,i,o,r]=Ye(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},Yt=(e,t,n,i)=>{if(!(K(e)||Ie(e)))return[e.x,e.y,e.x+t,e.y+n];let o=od(0,t,od(1,n,e.points,i),i),r;if(Ie(e))r=is(o);else{let c=En.generator(),u=e.roundness?c.curve(o,Re(e)):c.linearPath(o,Re(e)),m=wt(u);r=Ei(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Ur=(e,t)=>{let n=En.generator(),i=e.roundness==null?n.linearPath(t,Re(e)):n.curve(t,Re(e)),o=wt(i),[r,s,a,l]=Ei(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},Z0=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=dd(e);return e.forEach(r=>{let[s,a,l,d]=se(r,o),c=gf(L((s+l)/2,(a+d)/2),L(t.x,t.y));c<n&&(n=c,i=r)}),se(i,o)},Rt=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}},q0=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],ut=e=>L(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),Ze=(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=fe(e,t),[r,s]=oe(L(i.minX,i.minY),o,e.angle),[a,l]=oe(L(i.maxX,i.minY),o,e.angle),[d,c]=oe(L(i.maxX,i.maxY),o,e.angle),[u,m]=oe(L(i.minX,i.maxY),o,e.angle),p=[Math.min(r,a,d,u),Math.min(s,l,c,m),Math.max(r,a,d,u),Math.max(s,l,c,m)];if(n){let[f,h,E,g]=n;return[p[0]-g,p[1]-f,p[2]+h,p[3]+E]}return p},Zt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],bn=(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},fe=(e,t,n=0,i=0)=>{if(K(e)){let[s,a,l,d]=X(e,t),[c,u]=L((s+l)/2,(a+d)/2);return L(c+n,u+i)}let[o,r]=ut(se(e,t));return L(o+n,r+i)};var vf=.1,md=e=>K(e)||Ie(e)?e.points.length<2||e.points.length===2&&H(e)&&Tf(e.points[0],e.points[e.points.length-1],vf):e.width===0&&e.height===0,Rl=(e,t,n,i,o)=>{let[r,s,a,l]=se(e,o),d=Lo({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=Lo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},o1=(e,t,n,i,o,r)=>{let[s,a,l,d]=Ye(e,o),c=Lo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=Lo({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},os=(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)/kt)*kt;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}},xl=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/kt)*kt;if(o){let d=Math.floor(o/kt)*kt;Mf(a,d,d+kt)&&(Af(a,o)<kt/6?l=o:ud(a)>ud(o)?l=d+kt:l=d)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,m=-1/d,p=-1,f=i-m*n,h=(c*f-p*u)/(d*p-m*c),E=(u*m-f*d)/(d*p-m*c);r=h-e,s=E-t}return{width:r,height:s}},r1=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 u1=(e,t,n,i)=>{let o=Po(e,n.getNonDeletedElementsMap(),i),r=Rt(e);return o.flatMap(s=>{let a=Df(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ue(l,n,{simultaneouslyUpdated:s}),d})})},Df=(e,t,{axis:n,position:i})=>{let o=Rt(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 Sh,arrayToObject as Ft,assertNever as Yd,isDevEnv as un,isShallowEqual as Xd,isTestEnv as mn,randomInteger as Ud}from"@excalidraw/common";P();import{assertNever as zf,COLOR_PALETTE as _f,isDevEnv as Uf,isTestEnv as Yf,randomId as Xf,Emitter as hd,toIterable as Hn}from"@excalidraw/common";P();import{ORIG_ID as Gf,randomId as fd,randomInteger as Of,arrayToMap as Rf,castArray as rs,findLastIndex as xi,getUpdatedTimestamp as kf,isTestEnv as Ff}from"@excalidraw/common";P();import{arrayToMapWithIndex as Lf}from"@excalidraw/common";var Bf=e=>{let t=e.slice(),n=new Set,i=r=>{let s=r[0]?.groupIds?.join(""),a=[r[0]],l=[];for(let d of r.slice(1))d.groupIds?.join("")===s?a.push(d):l.push(d);return l.length?[...a,...i(l)]:a},o=new Map;return t.forEach((r,s)=>{if(!o.has(r.id))if(r.groupIds?.length){let a=r.groupIds[r.groupIds.length-1],l=t.slice(s).filter(d=>{let c=d?.groupIds?.some(u=>u===a);return c&&o.set(d.id,!0),c});for(let d of i(l))n.add(d)}else n.add(r)}),n.size!==e.length?(console.error("normalizeGroupElementOrder: lost some elements... bailing!"),e):[...n]},Cf=e=>{let t=Lf(e),n=e.slice(),i=new Set;return n.forEach((o,r)=>{o&&(o.boundElements?.length?(i.add(o),n[r]=null,o.boundElements.forEach(s=>{let a=t.get(s.id);a&&s.type==="text"&&(i.add(a[0]),n[a[1]]=null)})):o.type==="text"&&o.containerId&&t.get(o.containerId)?.[0].boundElements?.find(a=>a.id===o.id)||(i.add(o),n[r]=null))}),i.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...i]},pd=e=>Cf(Bf(e));var Nf=(e,t,n,i)=>{let o=as(n);return Ff()&&Hf(o,n.id),o.id=fd(),o.updated=kf(),i&&(o.seed=Of(),Ka(o)),o.groupIds=Gl(o.groupIds,e,r=>(t.has(r)||t.set(r,fd()),t.get(r))),o},M1=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=Rf(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(E=>[E.id,E]));if(e.type==="in-place")for(let E of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(E)).forEach(g=>u.set(g.id,g));t=pd(t);let m=t.slice(),p=E=>{let x=rs(E).reduce((y,b)=>{if(i.has(b.id))return y;i.set(b.id,!0);let w=Nf(n.editingGroupId,o,b,e.randomizeSeed);return i.set(w.id,!0),d.set(w.id,w),a.set(b.id,w.id),l.set(w.id,b),s.push(b),r.push(w),y.push(w),y},[]);return Array.isArray(E)?x:x[0]||null},f=(E,g)=>{if(g){if(E>m.length-1){m.push(...rs(g));return}m.splice(E+1,0,...rs(g))}},h=new Set(t.filter(E=>u.has(E.id)&&q(E)).map(E=>E.id));for(let E of t){if(i.has(E.id)||!u.has(E.id))continue;let g=jr(n,E);if(g){let x=ve(t,g).flatMap(b=>q(b)?[...rn(t,b.id),b]:[b]),y=xi(m,b=>b.groupIds?.includes(g));f(y,p(x));continue}if(!(E.frameId&&h.has(E.frameId))){if(q(E)){let x=E.id,y=rn(t,x),b=xi(m,w=>w.frameId===x||w.id===x);f(b,p([...y,E]));continue}if(dt(E)){let x=W(E,c),y=xi(m,b=>b.id===E.id||"containerId"in b&&b.containerId===E.id);x?f(y,p([E,x])):f(y,p(E));continue}if(le(E)){let x=Se(E,c),y=xi(m,b=>b.id===E.id||b.id===x?.id);x?f(y,p([x,E])):f(y,p(E));continue}f(xi(m,x=>x.id===E.id),p(E))}}if(rl(r,a,d),kl(m,s,a),e.overrides)for(let E of r){let g=l.get(E.id);g&&Object.assign(E,e.overrides({duplicateElement:E,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:m,origIdToDuplicateId:a}},ss=(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]=ss(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=ss(e[i],t+1);return o}return v.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},as=e=>ss(e),Hf=(e,t)=>{Object.defineProperty(e,Gf,{value:t,writable:!1,enumerable:!1})};var ke={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},Ed=class{constructor(t){this.app=t}onDurableIncrementEmitter=new hd;onStoreIncrementEmitter=new hd;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=cn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(ke.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=cn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?wd(t.elements):void 0,t.appState);i=wi.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=cn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=wi.create(o,t),i?s=i:s=cs.calculate(o,t),!s.isEmpty()){let a=new ls(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=wi.create(r,t)}let o=new ds(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===ke.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 ke.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case ke.NEVER:case ke.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:zf(n,"Unknown store action")}}finally{switch(n){case ke.IMMEDIATELY:case ke.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(ke.IMMEDIATELY)?t=ke.IMMEDIATELY:this.scheduledMacroActions.has(ke.NEVER)?t=ke.NEVER:t=ke.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(ke).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()),Yf()||Uf())throw new Error(t)}}},wi=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},Bo=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},ls=class extends Bo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},ds=class extends Bo{constructor(n){super("ephemeral",n);this.change=n}},cs=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:Xf()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?dn.calculate(t.elements,n.elements):dn.empty(),o=n.metadata.didAppStateChange?ln.calculate(t.appState,n.appState):ln.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,dn.restore(i),ln.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=dn.create(n,i,o),a=ln.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,cn.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(dn.empty(),ln.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},cn=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,gd(n)?n:zn(n),i)}static empty(){return new e(new Map,jf(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of Hn(t.elements))this.elements.get(i.id)||(n[i.id]=ge(i,{isDeleted:!0}));for(let i of Hn(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return _.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=zn({...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===ke.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=gd(t)?t:zn(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=_.isRightDifferent(this.appState,t);if(!i)return;let o=bd(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 Hn(this.elements))t.get(r.id)||i.set(r.id,ge(r,{isDeleted:!0}));for(let r of Hn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(xe(r)&&!Xt(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=yd(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of Hn(this.elements))n.set(i.id,i);for(let i of Hn(t))n.set(i.id,as(i));return n}},xd="__observedAppState",jf=()=>({name:null,editingGroupId:null,viewBackgroundColor:_f.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),zn=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,xd,{value:!0,enumerable:!1}),t},gd=e=>!!Reflect.get(e,xd);P();P();var Sd="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Un(e,t,n){let i=n[0];if(t!=null&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)===i||t&&t.slice(-1)===i)throw new Error("trailing zero");if(t){let s=0;for(;(e[s]||i)===t[s];)s++;if(s>0)return t.slice(0,s)+Un(e.slice(s),t.slice(s),n)}let o=e?n.indexOf(e[0]):0,r=t!=null?n.indexOf(t[0]):n.length;if(r-o>1){let s=Math.round(.5*(o+r));return n[s]}else return t&&t.length>1?t.slice(0,1):n[o]+Un(e.slice(1),null,n)}function Md(e){if(e.length!==Ad(e[0]))throw new Error("invalid integer part of order key: "+e)}function Ad(e){if(e>="a"&&e<="z")return e.charCodeAt(0)-97+2;if(e>="A"&&e<="Z")return 90-e.charCodeAt(0)+2;throw new Error("invalid order key head: "+e)}function yi(e){let t=Ad(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function Pd(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=yi(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function Id(e,t){Md(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])+1;s===t.length?i[r]=t[0]:(i[r]=t[s],o=!1)}if(o){if(n==="Z")return"a"+t[0];if(n==="z")return null;let r=String.fromCharCode(n.charCodeAt(0)+1);return r>"a"?i.push(t[0]):i.pop(),r+i.join("")}else return n+i.join("")}function Wf(e,t){Md(e);let[n,...i]=e.split(""),o=!0;for(let r=i.length-1;o&&r>=0;r--){let s=t.indexOf(i[r])-1;s===-1?i[r]=t.slice(-1):(i[r]=t[s],o=!1)}if(o){if(n==="a")return"Z"+t.slice(-1);if(n==="A")return null;let r=String.fromCharCode(n.charCodeAt(0)-1);return r<"Z"?i.push(t.slice(-1)):i.pop(),r+i.join("")}else return n+i.join("")}function _n(e,t,n=Sd){if(e!=null&&Pd(e,n),t!=null&&Pd(t,n),e!=null&&t!=null&&e>=t)throw new Error(e+" >= "+t);if(e==null){if(t==null)return"a"+n[0];let l=yi(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Un("",d,n);if(l<t)return l;let c=Wf(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=yi(e),d=e.slice(l.length),c=Id(l,n);return c??l+Un(d,null,n)}let i=yi(e),o=e.slice(i.length),r=yi(t),s=t.slice(r.length);if(i===r)return i+Un(o,s,n);let a=Id(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+Un(o,null,n)}function Co(e,t,n,i=Sd){if(n===0)return[];if(n===1)return[_n(e,t,i)];if(t==null){let s=_n(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=_n(s,t,i),a.push(s);return a}if(e==null){let s=_n(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=_n(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=_n(e,t,i);return[...Co(e,r,o,i),r,...Co(r,t,n-o-1,i)]}import{arrayToMap as Go}from"@excalidraw/common";var us=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Vf=(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(ms(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&dt(e[l])){let m=e[l],p=W(m,Go(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 us,d=[];if(o&&(d.push("Additional reconciliation context:"),d.push(o.localElements.map(c=>s(c))),d.push(o.remoteElements.map(c=>s(c)))),i||console.error(r.join(`
19
19
 
20
- `),l.stack,e.map(c=>s(c)),...d),t)throw l}},md=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),pi=(e,t)=>{try{let n=Po(e),i=zf(e,t),o=ts(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Nf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)be(s,n,{index:a})}catch{Hf(e)}return e},Hf=e=>{let t=Po(e),n=fd(e),i=ts(e,n);for(let[o,{index:r}]of i)be(o,t,{index:r});return e},od=e=>{let t=Po(e),n=fd(e),i=ts(e,n);for(let[o,{index:r}]of i)t.set(o.id,Ee(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},fd=e=>{let t=[],n,i,o=-1,r=0,s=d=>{let c=e[o]?e[o].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,o]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let p=e[u]?.index;if(!c&&p||c&&p&&p>c)return[p,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,o]=s(l),[i,r]=a(l),es(d,n,i))l++;else{let c=[o,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[f,E]=a(l);if(es(u,p,f))break;[n,o]=[p,m],[i,r]=[f,E],c.push(l)}c.push(r),t.push(c)}}return t},es=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,ts=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=bo(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;P();var Td=xc(wd(),1);import{randomInteger as oh,arrayToMap as yd,toBrandedType as bd,isDevEnv as Pd,isTestEnv as Id,toArray as rh}from"@excalidraw/common";import{isNonDeletedElement as sh}from"@excalidraw/element";import{isFrameLikeElement as ah}from"@excalidraw/element";import{getElementsInGroup as lh}from"@excalidraw/element";import{syncInvalidIndices as dh,syncMovedIndices as Sd,validateFractionalIndices as ch}from"@excalidraw/element";import{getSelectedElements as uh}from"@excalidraw/element";import{mutateElement as ph}from"@excalidraw/element";var Md=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}},mh=(0,Td.default)(e=>{(Pd()||Id()||window?.DEBUG_FRACTIONAL_INDICES)&&ch(e,{shouldThrow:Pd()||Id(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),fh=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},So=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=bd(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=bd(new Map);selectedElementsCache={selectedElementIds:null,elements:null,cache:new Map};sceneNonce;getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}constructor(t=null,n){t&&this.replaceAllElements(t,n)}getSelectedElements(t){let n=fh(t),i=t?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===i&&this.selectedElementsCache.selectedElementIds===t.selectedElementIds){let r=this.selectedElementsCache.cache.get(n);if(r)return r}else t?.elements==null&&this.selectedElementsCache.cache.clear();let o=uh(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&&sh(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=rh(t),o=[];n?.skipValidation||mh(i),this.elements=dh(i),this.elementsMap.clear(),this.elements.forEach(s=>{ah(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=Md(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=Md(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=oh();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementAtIndex(t,n){if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),t,...this.elements.slice(n)];Sd(i,yd([t])),this.replaceAllElements(i)}insertElementsAtIndex(t,n){if(!t.length)return;if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];Sd(i,yd(t)),this.replaceAllElements(i)}insertElement=t=>{let n=t.frameId?this.getElementIndex(t.frameId):this.elements.length;this.insertElementAtIndex(t,n)};insertElements=t=>{if(!t.length)return;let n=t[0]?.frameId?this.getElementIndex(t[0].frameId):this.elements.length;this.insertElementsAtIndex(t,n)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),i=n.get(t);return i?[i]:lh(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=ph(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var F=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i=e.empty()){return e.create({...t.deleted,...n.deleted,...i.deleted},{...t.inserted,...n.inserted,...i.inserted})}static mergeObjects(t,n,i={}){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Gt(t??[],o),Gt(n??[],o),Gt(i??[],o)))}static diffObjects(t,n,i,o){if(!t[i]&&!n[i])return;let r=t[i]!==null&&typeof t[i]=="object",s=n[i]!==null&&typeof n[i]=="object";if(r||s){let a=t[i]??{},l=n[i]??{},d=e.getLeftDifferences(a,l).reduce((u,p)=>(u[p]=o(a[p]),u),{}),c=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=o(l[p]),u),{});Object.keys(d).length||Object.keys(c).length?(Reflect.set(t,i,d),Reflect.set(n,i,c)):(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}else t[i]===n[i]&&(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}static diffArrays(t,n,i,o){if(!(!t[i]&&!n[i])&&(Array.isArray(t[i])||Array.isArray(n[i]))){let r=Array.isArray(t[i])?t[i]:[],s=Array.isArray(n[i])?n[i]:[],a=Gt(e.getLeftDifferences(Gt(r,o),Gt(s,o)),d=>d),l=Gt(e.getRightDifferences(Gt(r,o),Gt(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)])):Dd(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&&vd(a,l))continue;yield s}}}},Jt=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=F.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(F.create({},{}))}inverse(){let t=F.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=F.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=F.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=F.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=F.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=F.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=F.mergeObjects(this.delta.inserted.lockedMultiSelections??{},t.delta.inserted.lockedMultiSelections??{}),l={},d={};return(Object.keys(n).length||Object.keys(i).length)&&(d.selectedElementIds=n,l.selectedElementIds=i),(Object.keys(o).length||Object.keys(r).length)&&(d.selectedGroupIds=o,l.selectedGroupIds=r),(Object.keys(s).length||Object.keys(a).length)&&(d.lockedMultiSelections=s,l.lockedMultiSelections=a),this.delta=F.merge(this.delta,t.delta,F.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:s={},selectedGroupIds:a={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=F.mergeObjects(t.selectedElementIds,s,i),p=F.mergeObjects(t.selectedGroupIds,a,o),m=F.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new U(n.get(d.elementId),n,d.isEditing):null,E={...t,...c,selectedElementIds:u,selectedGroupIds:p,lockedMultiSelections:m,selectedLinearElement:typeof d<"u"?f:t.selectedLinearElement},h=this.filterInvisibleChanges(t,E,n);return[E,h]}catch(i){if(console.error("Couldn't apply appstate change",i),on()||nn())throw i;return[t,!1]}}isEmpty(){return F.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=On(t),r=On(n),s=F.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=F.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=F.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=El(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let y=i.get(x);y&&!y.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?c.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=i.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},E=n[u]||{};vd(f,E)||(l.value=!0);break;case"activeLockedId":let h=t[u]||null,g=n[u]||null;h!==g&&(l.value=!0);break;default:Dd(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{F.diffObjects(t,n,"selectedElementIds",i=>!0),F.diffObjects(t,n,"selectedGroupIds",i=>i??!1),F.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),on()||nn())throw i}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let i of Object.keys(t).sort())n[i]=t[i];return n}},en=class e{constructor(t,n,i){this.added=t;this.removed=n;this.updated=i}static create(t,n,i,o={shouldRedistribute:!1}){let r;if(o.shouldRedistribute){let s={},a={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(i)];for(let[c,u]of d)this.satisfiesAddition(u)?s[c]=u:this.satisfiesRemoval(u)?a[c]=u:l[c]=u;r=new e(s,a,l)}else r=new e(t,n,i);return(on()||nn())&&(e.validate(r,"added",this.satisfiesAddition),e.validate(r,"removed",this.satisfiesRemoval),e.validate(r,"updated",this.satisfiesUpdate)),r}static restore(t){let{added:n,removed:i,updated:o}=t;return e.create(n,i,o)}static satisfiesAddition=({deleted:t,inserted:n})=>t.isDeleted===!0&&!n.isDeleted;static satisfiesRemoval=({deleted:t,inserted:n})=>!t.isDeleted&&n.isDeleted===!0;static satisfiesUpdate=({deleted:t,inserted:n})=>!!t.isDeleted==!!n.isDeleted;static satisfiesCommmonInvariants=({deleted:t,inserted:n})=>!!(Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static satisfiesUniqueInvariants=(t,n)=>{let{added:i,removed:o,updated:r}=t;return[i[n],o[n],r[n]].filter(Boolean).length===1};static validate(t,n,i){for(let[o,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!this.satisfiesUniqueInvariants(t,o)||!i(r))throw console.error(`Broken invariant for "${n}" delta, element "${o}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${o}".`)}static calculate(t,n){if(t===n)return e.empty();let i={},o={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s},d={isDeleted:!0,version:s.version+1,versionNonce:Ad()},c=F.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:Ad()},d={...s},c=F.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=F.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}r[s.id]=l}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=F.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,p)=>{let m;switch(p){case"deleted":m=d;break;case"inserted":m=c;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let E of Object.keys(u))switch(E){case"boundElements":f[E]=u[E];break;default:f[E]=m[E]}return f},r=d=>{let c={};for(let[u,p]of Object.entries(d)){let m=t.get(u),f=n.get(u),E=null;m||f?E=F.create(p.deleted,p.inserted,o(m,f),i):E=p,F.isInnerDifferent(E.deleted,E.inserted)&&(c[u]=E)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=tn.empty().elements,i){let o=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let a=e.createApplier(t,o,n,s,i),l=a(this.added),d=a(this.removed),c=a(this.updated),u=this.resolveConflicts(t,o,s.applyDirection);r=new Map([...l,...d,...c,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),on()||nn())throw a;return[t,!0]}try{o=e.reorderElements(o,r,s),e.redrawElements(o,r)}catch(a){if(console.error("Couldn't mutate elements after applying elements change",a),on()||nn())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=F.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=F.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return F.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=F.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=F.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=F.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(on()||nn())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,i,o,r)=>s=>{let a=e.createGetter(n,i,o);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let p=e.applyDelta(u,c,o,r);if(n.set(p.id,p),l.set(p.id,p),!o.applyDirection){let m=t.get(d);m&&(o.applyDirection=m.version>p.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?(i.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(i.containsVisibleDifference=!0)):s=Ee({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=F.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!i.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);i.containsVisibleDifference=l}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Ee(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:F.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,p=l,m;c===d?m=Ee(d,{...p,version:u},!0):m=be(d,n,{...p,version:c?.version!==d.version?d.version:u}),o.set(m.id,m),n.set(m.id,m)};for(let a of Object.keys(this.removed))e.unbindAffected(t,n,a,r);for(let a of Object.keys(this.added))e.rebindAffected(t,n,a,r);for(let[a]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>qa.has(c)))){let l=n.get(a);!l||l.isDeleted||e.rebindAffected(t,n,a,r)}let s=new Map(Array.from(t).filter(([a])=>o.has(a)));return this.squash(e.calculate(s,o)),o}static unbindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.unbindAffected(n,s(),o),$t.unbindAffected(n,r(),o),$t.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.rebindAffected(n,s(),o),$t.unbindAffected(n,r(),(a,l)=>{ie(a)&&o(a,l)}),$t.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new So(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),on()||nn())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(ce(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(st(r)){let s=It(r),a=s?i.get(s):void 0;a&&o.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of o.values())r.isDeleted||s.isDeleted||wa(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Le(i)&&Ue(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=md([...o]),s=F.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),hh(pi(r,s))}static postProcess(t,n){try{F.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];F.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),on()||nn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var sP=(e,t,n,i)=>{let[o,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Ct(e),d=po(e,t,i).map(m=>[m,Ct(m)]).sort((m,f)=>m[1][r]-f[1][r]),c=0;for(let m of d)c+=m[1][a];let u=(l[a]-c)/(d.length-1);if(u<0){let m=d.findIndex(g=>g[1][o]===l[o]),f=d.findIndex(g=>g[1][s]===l[s]),E=(d[f][1][r]-d[m][1][r])/(d.length-1),h=d[m][1][r];return d.flatMap(([g,x],y)=>{let b={x:0,y:0};return y!==m&&y!==f&&(h+=E,b[n.axis]=h-x[r]),g.map(w=>Ee(w,{x:w.x+b.x,y:w.y+b.y}))})}let p=l[o];return d.flatMap(([m,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[o],p+=u,p+=f[a],m.map(h=>Ee(h,{x:h.x+E.x,y:h.y+E.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as Eh,getGridPoint as gh,getFontString as xh}from"@excalidraw/common";var EP=(e,t,n,i,o,r)=>{if(t.length===1&&G(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(u=>{if(G(u)&&u.startBinding&&u.endBinding){let p=t.find(f=>f.id===u.startBinding?.elementId),m=t.find(f=>f.id===u.endBinding?.elementId);return p&&m}return!0}),a=new Set(s),l=s.filter(u=>Z(u)).map(u=>u.id);if(l.length>0)for(let u of i.getNonDeletedElements())u.frameId!==null&&l.includes(u.frameId)&&a.add(u);let d=[];for(let u of a){let p=e.originalElements.get(u.id);if(!p)return;d.push(p)}let c=wh(Xe(d),n,o,r);a.forEach(u=>{if(Ld(e,u,i,c),!Y(u)){let p=W(u,i.getNonDeletedElementsMap());p&&Ld(e,p,i,c),Ue(u,i,{simultaneouslyUpdated:Array.from(a)})}})},wh=(e,t,n,i)=>{let[o,r]=e,s=o+t.x+n.x,a=r+t.y+n.y;if(n.x===0||n.y===0){let[l,d]=gh(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Ld=(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})},gP=(e,t,n)=>{let[i,o]=Xe(e);return[t-i,n-o]},xP=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:p=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Wr(t,a,o<n?-s:s):{width:s,height:a}=Wr(t,s,r<i?-a:a),a<0&&(a=-a)));let E=o<n?n-s:n,h=r<i?i-a:i;d&&(s+=s,a+=a,E=n-s/2,h=i-a/2);let g=null;if(ie(e)){a=e.height;let x=Hi(xh({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>Eh/c&&(g={autoResize:!1}),h=i,d&&(E=n-s/2)}if(s!==0&&a!==0){let x=null;we(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:E+(m?.x??0),y:h+(m?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as Mo,normalizeLink as Cd}from"@excalidraw/common";var IP=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Mo,e),Cd(i.toString())}catch(i){console.error(i)}return Cd(n)},SP=(e,t)=>{if(e.length>0&&yh(e)){if(e.length===1)return{id:e[0].id,type:"element"};if(e.length>1){let n=Object.keys(t.selectedGroupIds)[0];return n?{id:n,type:"group"}:{id:e[0].groupIds[0],type:"group"}}}return null},yh=e=>!!(e.length===1||e.length>1&&gl(e)),MP=e=>{try{let t=new URL(e);return t.searchParams.has(Mo)&&t.host===window.location.host}catch{return!1}},TP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Mo))return t.get(Mo)}catch{}return null};P();import{FONT_FAMILY as Bh,VERTICAL_ALIGN as Gh,escapeDoubleQuotes as os,getFontString as kh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as rn,DEFAULT_FONT_FAMILY as bh,DEFAULT_FONT_SIZE as Ph,DEFAULT_TEXT_ALIGN as Ih,DEFAULT_VERTICAL_ALIGN as Sh,VERTICAL_ALIGN as Mh,randomInteger as Th,randomId as Ah,getFontString as To,getUpdatedTimestamp as Dh,getLineHeight as vh}from"@excalidraw/common";var nt=(e,{x:t,y:n,strokeColor:i=rn.strokeColor,backgroundColor:o=rn.backgroundColor,fillStyle:r=rn.fillStyle,strokeWidth:s=rn.strokeWidth,strokeStyle:a=rn.strokeStyle,roughness:l=rn.roughness,opacity:d=rn.opacity,width:c=0,height:u=0,angle:p=0,groupIds:m=[],frameId:f=null,index:E=null,roundness:h=null,boundElements:g=null,link:x=null,locked:y=rn.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:b.points}),{id:b.id||Ah(),type:e,x:t,y:n,width:c,height:u,angle:p,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:m,frameId:f,index:E,roundness:h,seed:b.seed??Th(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Dh(),link:x,locked:y,customData:b.customData}),is=e=>nt(e.type,e),RP=e=>nt("embeddable",e),FP=e=>({...nt("iframe",e)}),NP=e=>Ee({...nt("frame",e),type:"frame",name:e?.name||null},{}),HP=e=>Ee({...nt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Bd=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Gd=e=>{let t=e.fontFamily||bh,n=e.fontSize||Ph,i=e.lineHeight||vh(t),o=nr(e.text),r=Je(o,To({fontFamily:t,fontSize:n}),i),s=e.textAlign||Ih,a=e.verticalAlign||Sh,l=Bd({textAlign:s,verticalAlign:a},r),d={...nt("text",e),text:o,fontSize:n,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i};return Ee(d,{})},Lh=(e,t,n)=>{let{width:i,height:o}=Je(n,To(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Mh.MIDDLE&&!e.containerId&&e.autoResize){let d=Je(e.text,To(e),e.lineHeight),c=Bd(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,p]=_(e,t),[m,f,E,h]=Nt(e,i,o,!1),g=(d-m)/2,x=(c-f)/2,y=(u-E)/2,b=(p-h)/2;[a,l]=Ch({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,y,b)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},Ch=(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]},zP=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Pt(i,To(e),t?et(t,e):e.width));let o=Lh(e,n,i);return{text:i,...o}},_P=e=>({...nt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,lastCommittedPoint:null}),YP=e=>{let t={...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return mn(t)?{...t,polygon:e.polygon??!1}:t},kd=e=>e.elbowed?{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},UP=e=>({...nt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ft=new Map,Oh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,Rh=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Fh=/^https:\/\/(?:www\.)?figma\.com/,Od=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Nh=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Hh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Rd=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,zh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,_h=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Yh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Fd=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Nd=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,Uh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Xh=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)},ss=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Hd=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),rs=e=>`<html><body>${e}</body></html>`,qP=e=>{if(!e)return null;if(ft.has(e))return ft.get(e);let t=e,n=Hd.has(as(e,Hd)||""),i="generic",o={w:560,h:840},r=e.match(Oh);if(r?.[2]){let d=Xh(t),c=d>0?`&start=${d}`:"",u=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${c}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break}return o=u?{w:315,h:560}:{w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(Rh);if(s?.[1]){let d=s?.[1],c=/^\d+$/.test(d)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${d}?api=1`,o={w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:c,sandbox:{allowSameOrigin:n}}}if(e.match(Fh))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let l=e.match(_h);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(Hh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Rd.test(e)){let d=e.match(Rd)[1],c=os(`https://twitter.com/x/status/${d}`),u={type:"document",srcdoc:p=>rs(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${c}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,u),u}if(Nd.test(e)){let[,d,c,u]=e.match(Nd),p=os(`https://reddit.com/r/${d}/comments/${c}/${u}`),m={type:"document",srcdoc:f=>rs(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${p}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,m),m}if(Od.test(e)){let[,d,c]=e.match(Od),u=os(`https://gist.github.com/${d}/${c}`),p={type:"document",srcdoc:()=>rs(`
20
+ `),l.stack,e.map(c=>s(c)),...d),t)throw l}},vd=e=>e.sort((t,n)=>Td(t)&&Td(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),bi=(e,t)=>{try{let n=Go(e),i=Zf(e,t),o=ps(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Vf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)ye(s,n,{index:a})}catch{$f(e)}return e},$f=e=>{let t=Go(e),n=Dd(e),i=ps(e,n);for(let[o,{index:r}]of i)ye(o,t,{index:r});return e},wd=e=>{let t=Go(e),n=Dd(e),i=ps(e,n);for(let[o,{index:r}]of i)t.set(o.id,ge(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},Dd=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),[f,h]=a(l);if(ms(u,m,f))break;[n,o]=[m,p],[i,r]=[f,h],c.push(l)}c.push(r),t.push(c)}}return t},ms=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,ps=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=Co(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},Td=e=>!!e.index;P();var _d=Cc(Od(),1);import{randomInteger as ph,arrayToMap as Rd,toBrandedType as kd,isDevEnv as Fd,isTestEnv as Nd,toArray as fh}from"@excalidraw/common";import{isNonDeletedElement as hh}from"@excalidraw/element";import{isFrameLikeElement as Eh}from"@excalidraw/element";import{getElementsInGroup as gh}from"@excalidraw/element";import{syncInvalidIndices as xh,syncMovedIndices as Hd,validateFractionalIndices as wh}from"@excalidraw/element";import{getSelectedElements as yh}from"@excalidraw/element";import{mutateElement as bh}from"@excalidraw/element";var zd=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}},Ph=(0,_d.default)(e=>{(Fd()||Nd()||window?.DEBUG_FRACTIONAL_INDICES)&&wh(e,{shouldThrow:Fd()||Nd(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),Ih=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Ro=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=kd(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=kd(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=Ih(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=yh(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&&hh(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=fh(t),o=[];n?.skipValidation||Ph(i),this.elements=xh(i),this.elementsMap.clear(),this.elements.forEach(s=>{Eh(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=zd(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=zd(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=ph();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementAtIndex(t,n){if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),t,...this.elements.slice(n)];Hd(i,Rd([t])),this.replaceAllElements(i)}insertElementsAtIndex(t,n){if(!t.length)return;if(!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let i=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];Hd(i,Rd(t)),this.replaceAllElements(i)}insertElement=t=>{let n=t.frameId?this.getElementIndex(t.frameId):this.elements.length;this.insertElementAtIndex(t,n)};insertElements=t=>{if(!t.length)return;let n=t[0]?.frameId?this.getElementIndex(t[0].frameId):this.elements.length;this.insertElementsAtIndex(t,n)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),i=n.get(t);return i?[i]:gh(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=bh(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var _=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i=e.empty()){return e.create({...t.deleted,...n.deleted,...i.deleted},{...t.inserted,...n.inserted,...i.inserted})}static mergeObjects(t,n,i={}){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Ft(t??[],o),Ft(n??[],o),Ft(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=Ft(e.getLeftDifferences(Ft(r,o),Ft(s,o)),d=>d),l=Ft(e.getRightDifferences(Ft(r,o),Ft(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)])):Yd(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&&Xd(a,l))continue;yield s}}}},ln=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=_.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(_.create({},{}))}inverse(){let t=_.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=_.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=_.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=_.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=_.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=_.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=_.mergeObjects(this.delta.inserted.lockedMultiSelections??{},t.delta.inserted.lockedMultiSelections??{}),l={},d={};return(Object.keys(n).length||Object.keys(i).length)&&(d.selectedElementIds=n,l.selectedElementIds=i),(Object.keys(o).length||Object.keys(r).length)&&(d.selectedGroupIds=o,l.selectedGroupIds=r),(Object.keys(s).length||Object.keys(a).length)&&(d.lockedMultiSelections=s,l.lockedMultiSelections=a),this.delta=_.merge(this.delta,t.delta,_.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:s={},selectedGroupIds:a={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=_.mergeObjects(t.selectedElementIds,s,i),m=_.mergeObjects(t.selectedGroupIds,a,o),p=_.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new k(n.get(d.elementId),n,d.isEditing):null,h={...t,...c,selectedElementIds:u,selectedGroupIds:m,lockedMultiSelections:p,selectedLinearElement:typeof d<"u"?f:t.selectedLinearElement},E=this.filterInvisibleChanges(t,h,n);return[h,E]}catch(i){if(console.error("Couldn't apply appstate change",i),mn()||un())throw i;return[t,!1]}}isEmpty(){return _.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=zn(t),r=zn(n),s=_.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=_.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=_.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=Ll(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let y=i.get(x);y&&!y.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let m=n[u];m?c.has(m)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let p=n[u];if(!p)l.value=!0;else{let x=i.get(p.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},h=n[u]||{};Xd(f,h)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,g=n[u]||null;E!==g&&(l.value=!0);break;default:Yd(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{_.diffObjects(t,n,"selectedElementIds",i=>!0),_.diffObjects(t,n,"selectedGroupIds",i=>i??!1),_.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),mn()||un())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}},dn=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(mn()||un())&&(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:Ud()},c=_.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:Ud()},d={...s},c=_.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=_.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}r[s.id]=l}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=_.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,m)=>{let p;switch(m){case"deleted":p=d;break;case"inserted":p=c;break}if(!p)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let h of Object.keys(u))switch(h){case"boundElements":f[h]=u[h];break;default:f[h]=p[h]}return f},r=d=>{let c={};for(let[u,m]of Object.entries(d)){let p=t.get(u),f=n.get(u),h=null;p||f?h=_.create(m.deleted,m.inserted,o(p,f),i):h=m,_.isInnerDifferent(h.deleted,h.inserted)&&(c[u]=h)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=cn.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),mn()||un())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),mn()||un())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=_.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=_.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return _.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=_.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=_.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=_.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(mn()||un())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,i,o,r)=>s=>{let a=e.createGetter(n,i,o);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let m=e.applyDelta(u,c,o,r);if(n.set(m.id,m),l.set(m.id,m),!o.applyDirection){let p=t.get(d);p&&(o.applyDirection=p.version>m.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,i)=>(o,r)=>{let s=t.get(o);return s||(s=n.get(o),s?(i.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(i.containsVisibleDifference=!0)):s=ge({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=_.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!i.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);i.containsVisibleDifference=l}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),ge(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:_.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,m=l,p;c===d?p=ge(d,{...m,version:u},!0):p=ye(d,n,{...m,version:c?.version!==d.version?d.version:u}),o.set(p.id,p),n.set(p.id,p)};for(let a of Object.keys(this.removed))e.unbindAffected(t,n,a,r);for(let a of Object.keys(this.added))e.rebindAffected(t,n,a,r);for(let[a]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>sl.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);en.unbindAffected(n,r(),o),en.unbindAffected(n,s(),o),tn.unbindAffected(n,r(),o),tn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);en.unbindAffected(n,r(),o),en.rebindAffected(n,s(),o),tn.unbindAffected(n,r(),(a,l)=>{J(a)&&o(a,l)}),tn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Ro(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),mn()||un())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(le(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(dt(r)){let s=At(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||Oa(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&He(i)&&Ue(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=vd([...o]),s=_.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),Sh(bi(r,s))}static postProcess(t,n){try{_.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];_.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),mn()||un())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var gP=(e,t,n,i)=>{let[o,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Rt(e),d=Po(e,t,i).map(p=>[p,Rt(p)]).sort((p,f)=>p[1][r]-f[1][r]),c=0;for(let p of d)c+=p[1][a];let u=(l[a]-c)/(d.length-1);if(u<0){let p=d.findIndex(g=>g[1][o]===l[o]),f=d.findIndex(g=>g[1][s]===l[s]),h=(d[f][1][r]-d[p][1][r])/(d.length-1),E=d[p][1][r];return d.flatMap(([g,x],y)=>{let b={x:0,y:0};return y!==p&&y!==f&&(E+=h,b[n.axis]=E-x[r]),g.map(w=>ge(w,{x:w.x+b.x,y:w.y+b.y}))})}let m=l[o];return d.flatMap(([p,f])=>{let h={x:0,y:0};return h[n.axis]=m-f[o],m+=u,m+=f[a],p.map(E=>ge(E,{x:E.x+h.x,y:E.y+h.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as Mh,getGridPoint as Ah,getFontString as Th,DRAGGING_THRESHOLD as vh}from"@excalidraw/common";var TP=(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(h=>h.id===m.startBinding?.elementId),f=t.find(h=>h.id===m.endBinding?.elementId);return p&&f}return!0}),a=new Set(s),l=s.filter(m=>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=Dh(Ye(d),n,o,r),u=new Set(Array.from(a,m=>m.id));a.forEach(m=>{let p=!H(m),f=p||(m.startBinding?u.has(m.startBinding.elementId):!1),h=p||(m.endBinding?u.has(m.endBinding.elementId):!1);if(H(m)){if(a.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>vh||!m.startBinding&&!m.endBinding){hs(e,m,i,c);let E=m.startBinding&&!f,g=m.endBinding&&!h;(E||g)&&(E&&qe(m,"start",i),g&&qe(m,"end",i))}}else{hs(e,m,i,c);let E=W(m,i.getNonDeletedElementsMap());E&&hs(e,E,i,c),Ue(m,i,{simultaneouslyUpdated:Array.from(a)})}})},Dh=(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]=Ah(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},hs=(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})},vP=(e,t,n)=>{let[i,o]=Ye(e);return[t-i,n-o]},DP=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:m=null,originOffset:p=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(m?a=s/m:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=os(t,a,o<n?-s:s):{width:s,height:a}=os(t,s,r<i?-a:a),a<0&&(a=-a)));let h=o<n?n-s:n,E=r<i?i-a:i;d&&(s+=s,a+=a,h=n-s/2,E=i-a/2);let g=null;if(J(e)){a=e.height;let x=Zi(Th({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>Mh/c&&(g={autoResize:!1}),E=i,d&&(h=n-s/2)}if(s!==0&&a!==0){let x=null;xe(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:h+(p?.x??0),y:E+(p?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as ko,normalizeLink as jd}from"@excalidraw/common";var OP=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(ko,e),jd(i.toString())}catch(i){console.error(i)}return jd(n)},RP=(e,t)=>{if(e.length>0&&Lh(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},Lh=e=>!!(e.length===1||e.length>1&&Bl(e)),kP=e=>{try{let t=new URL(e);return t.searchParams.has(ko)&&t.host===window.location.host}catch{return!1}},FP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(ko))return t.get(ko)}catch{}return null};P();import{FONT_FAMILY as Uh,VERTICAL_ALIGN as Yh,escapeDoubleQuotes as gs,getFontString as Xh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as pn,DEFAULT_FONT_FAMILY as Bh,DEFAULT_FONT_SIZE as Ch,DEFAULT_TEXT_ALIGN as Gh,DEFAULT_VERTICAL_ALIGN as Oh,VERTICAL_ALIGN as Rh,randomInteger as kh,randomId as Fh,getFontString as Fo,getUpdatedTimestamp as Nh,getLineHeight as Hh}from"@excalidraw/common";var rt=(e,{x:t,y:n,strokeColor:i=pn.strokeColor,backgroundColor:o=pn.backgroundColor,fillStyle:r=pn.fillStyle,strokeWidth:s=pn.strokeWidth,strokeStyle:a=pn.strokeStyle,roughness:l=pn.roughness,opacity:d=pn.opacity,width:c=0,height:u=0,angle:m=0,groupIds:p=[],frameId:f=null,index:h=null,roundness:E=null,boundElements:g=null,link:x=null,locked:y=pn.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:b.points}),{id:b.id||Fh(),type:e,x:t,y:n,width:c,height:u,angle:m,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:p,frameId:f,index:h,roundness:E,seed:b.seed??kh(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Nh(),link:x,locked:y,customData:b.customData}),Es=e=>rt(e.type,e),VP=e=>rt("embeddable",e),$P=e=>({...rt("iframe",e)}),ZP=e=>ge({...rt("frame",e),type:"frame",name:e?.name||null},{}),qP=e=>ge({...rt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Wd=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Vd=e=>{let t=e.fontFamily||Bh,n=e.fontSize||Ch,i=e.lineHeight||Hh(t),o=fr(e.text),r=tt(o,Fo({fontFamily:t,fontSize:n}),i),s=e.textAlign||Gh,a=e.verticalAlign||Oh,l=Wd({textAlign:s,verticalAlign:a},r),d={...rt("text",e),text:o,fontSize:n,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i};return ge(d,{})},zh=(e,t,n)=>{let{width:i,height:o}=tt(n,Fo(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Rh.MIDDLE&&!e.containerId&&e.autoResize){let d=tt(e.text,Fo(e),e.lineHeight),c=Wd(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,m]=X(e,t),[p,f,h,E]=Yt(e,i,o,!1),g=(d-p)/2,x=(c-f)/2,y=(u-h)/2,b=(m-E)/2;[a,l]=_h({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,y,b)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},_h=(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]},KP=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Mt(i,Fo(e),t?nt(t,e):e.width));let o=zh(e,n,i);return{text:i,...o}},QP=e=>({...rt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure}),JP=e=>{let t={...rt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return bt(t)?{...t,polygon:e.polygon??!1}:t},$d=e=>e.elbowed?{...rt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...rt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},eI=e=>({...rt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ht=new Map,jh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,Wh=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Vh=/^https:\/\/(?:www\.)?figma\.com/,Zd=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,$h=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Zh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,qd=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,qh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,Kh=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Qh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Kd=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Qd=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,Jh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,eE=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)},ws=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Jd=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),xs=e=>`<html><body>${e}</body></html>`,aI=e=>{if(!e)return null;if(ht.has(e))return ht.get(e);let t=e,n=Jd.has(ys(e,Jd)||""),i="generic",o={w:560,h:840},r=e.match(jh);if(r?.[2]){let d=eE(t),c=d>0?`&start=${d}`:"",u=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${c}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break}return o=u?{w:315,h:560}:{w:560,h:315},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(Wh);if(s?.[1]){let d=s?.[1],c=/^\d+$/.test(d)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${d}?api=1`,o={w:560,h:315},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:c,sandbox:{allowSameOrigin:n}}}if(e.match(Vh))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let l=e.match(Kh);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ht.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(Zh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),qd.test(e)){let d=e.match(qd)[1],c=gs(`https://twitter.com/x/status/${d}`),u={type:"document",srcdoc:m=>xs(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${m}"><a href="${c}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ht.set(t,u),u}if(Qd.test(e)){let[,d,c,u]=e.match(Qd),m=gs(`https://reddit.com/r/${d}/comments/${c}/${u}`),p={type:"document",srcdoc:f=>xs(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${m}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ht.set(t,p),p}if(Zd.test(e)){let[,d,c]=e.match(Zd),u=gs(`https://gist.github.com/${d}/${c}`),m={type:"document",srcdoc:()=>xs(`
21
21
  <script src="${u}.js"><\/script>
22
22
  <style type="text/css">
23
23
  * { margin: 0px; }
24
24
  table, .gist { height: 100%; }
25
25
  .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
26
26
  </style>
27
- `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return ft.set(e,p),p}return ft.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},KP=e=>{let t;ki(e)?t="IFrame element":t=!e.link||e?.link===""?"Empty Web-Embed":e.link;let n=Math.max(Math.min(e.width/2,e.width/t.length),e.width/30),i=Bh.Helvetica,o=kh({fontSize:n,fontFamily:i});return Gd({x:e.x+e.width/2,y:e.y+e.height/2,strokeColor:e.strokeColor!=="transparent"?e.strokeColor:"black",backgroundColor:"transparent",fontFamily:i,fontSize:n,text:Pt(t,o,e.width-20),textAlign:"center",verticalAlign:Gh.MIDDLE,angle:e.angle??0})},as=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(ss.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return ss.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},QP=e=>{let t=e.match(zh);if(t&&t.length===2)return t[1];let n=e.match(Uh);if(n&&n.length===2)return n[1];let i=e.match(Nh);if(i&&i.length===2)return i[1];if(Fd.test(e))return`https://giphy.com/embed/${Fd.exec(e)[1]}`;let o=e.match(Yh);return o&&o.length===2?o[1]:e},JP=(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(as(e,n))return!0;return!1}}return!!as(e,ss)};P();import{KEYS as Ao,invariant as Do,toBrandedType as jh}from"@excalidraw/common";import{pointFrom as zd}from"@excalidraw/math";var Nn=100,xn=100,mI=e=>{switch(e){case Ao.ARROW_UP:return"up";case Ao.ARROW_DOWN:return"down";case Ao.ARROW_RIGHT:return"right";case Ao.ARROW_LEFT:return"left";default:return"right"}},Ud=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(G(s)&&(a=s[e==="predecessors"?"startBinding":"endBinding"])&&s[e==="predecessors"?"endBinding":"startBinding"]?.elementId===t.id){let l=n.get(a.elementId);if(!l)return r;Do(Le(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=ni(t,$e(t,n),[d[0]+s.x,d[1]+s.y]);r.push({relative:l,heading:c})}return r},[]);switch(i){case"up":return o.filter(r=>pe(r.heading,ze)).map(r=>r.relative);case"down":return o.filter(r=>pe(r.heading,ye)).map(r=>r.relative);case"right":return o.filter(r=>pe(r.heading,me)).map(r=>r.relative);case"left":return o.filter(r=>pe(r.heading,ke)).map(r=>r.relative)}},ls=(e,t,n)=>Ud("successors",e,t,n),ds=(e,t,n)=>Ud("predecessors",e,t,n),Wh=(e,t,n)=>{let i=xn+e.width;if(n==="up"||n==="down"){let a=Nn+e.height,l=e.x,d=e.x+e.width;if(t.every(c=>c.x+c.width<l||c.x>d))return{x:0,y:a*(n==="up"?-1:1)}}else if(n==="right"||n==="left"){let a=e.y,l=e.y+e.height;if(t.every(d=>d.y+d.height<a||d.y>l))return{x:(xn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Nn+e.height,l=(t.length===0,a),d=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*i:t.length/2*i*-1;return n==="up"?{x:d,y:l*-1}:{x:d,y:l}}let o=Nn+e.height,r=(t.length===0,xn+e.width),s=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*o:t.length/2*o*-1;return n==="left"?{x:r*-1,y:s}:{x:r,y:s}},Vh=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=ls(e,o,n),s=ds(e,o,n),a=Wh(e,[...r,...s],n),l=is({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});Do(er(l),"not an ExcalidrawFlowchartNodeElement");let d=Xd(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},$h=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=Nn*(o-1)+o*e.height,p=e.y+e.height/2-u/2,m=xn+e.width;n==="left"&&(m*=-1),a=e.x+m;let f=(Nn+e.height)*s;l=p+f}else{let u=xn*(o-1)+o*e.width,p=e.x+e.width/2-u/2,m=Nn+e.height;n==="up"&&(m*=-1),l=e.y+m;let f=(xn+e.width)*s;a=p+f}let d=is({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});Do(er(d),"not an ExcalidrawFlowchartNodeElement");let c=Xd(e,d,n,t,i);r.push(d),r.push(c)}return r},Xd=(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=kd({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:[zd(0,0),zd(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();gn(c,e,"start",o),gn(c,t,"end",o);let p=new Map;p.set(e.id,e),p.set(t.id,t),p.set(c.id,c),U.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let m=Dn(c,jh(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...m}},_d=class{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!Le(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...ls(t,n,i),...ds(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=>[...ls(t,n,a),...ds(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}},Yd=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}=Vh(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=$h(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);Do(s&&Ri(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>Kt([a],s,r)||Zt(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>be(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},fI=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{MIME_TYPES as jd,SVG_NS as Zh}from"@excalidraw/common";var qh=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),wI=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===jd.binary)throw new Error("Only images can be added to ImageCache");let l=qh(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}},yI=e=>e.filter(t=>Ht(t)),Kh=e=>e?.nodeName.toLowerCase()==="svg",bI=e=>{let t=new DOMParser().parseFromString(e,jd.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Kh(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Zh);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 TI=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(m=>[m]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let m=0;m<s;m+=a)l.push(r.slice(m,m+a));let d=0,c=l.map(m=>{let f=0,E=0,h=m.map(g=>{let[x,y,b,w]=Xe(g);return{elements:g,bounds:[x,y,b,w],width:b-x,height:w-y}});return h.forEach((g,x)=>{f+=g.width,x<h.length-1&&(f+=i),g.height>E&&(E=g.height)}),d+=E,{unitBounds:h,width:f,maxHeight:E}}),u=d+Math.max(0,l.length-1)*i,p=n-u/2;return c.forEach(m=>{let{unitBounds:f,width:E,maxHeight:h}=m,g=t-E/2;f.forEach(x=>{let[y,b]=x.bounds,w=g-y,I=p-b;x.elements.forEach(M=>{o.push(Ee(M,{x:M.x+w,y:M.y+I}))}),g+=x.width+i}),p+=h+i}),o};P();import{pointCenter as Qh,normalizeRadians as Lo,pointFrom as re,pointRotateRads as it}from"@excalidraw/math";import{MIN_FONT_SIZE as us,SHIFT_LOCKING_ANGLE as Co,rescalePoints as Wd,getFontString as vo}from"@excalidraw/common";var HI=(e,t,n,i,o,r,s,a,l,d,c)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[p]=n;if(t==="rotation")G(p)||(Jh(p,i,a,l,o),Ue(p,i));else if(t){let m=n[0].id,f=u.get(m),E=e.get(m);if(f&&E){let{nextWidth:h,nextHeight:g}=oE(f,E,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});iE(h,g,f,E,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return ie(p)&&Ue(p,i),!0}else if(n.length>1){if(t==="rotation")return tE(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:p,nextHeight:m,flipByX:f,flipByY:E,originalBoundingBox:h}=rE(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return sE(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:E,nextWidth:p,nextHeight:m,originalBoundingBox:h}),!0}}return!1},Jh=(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+Co/2,u=u-u%Co),u=Lo(u));let p=It(e);if(t.mutateElement(e,{angle:u}),p){let m=t.getElement(p);if(m&&!Y(e)){let{x:f,y:E}=ei(e,m,t.getNonDeletedElementsMap());t.mutateElement(m,{angle:u,x:f,y:E})}}},Vd=(e,t,n,i)=>j(e)||Me(e)?{points:Wd(0,t,Wd(1,n,e.points,i),i)}:{},ps=(e,t,n)=>{let i=e.width;if(ce(e)){let s=Ce(e,t);s&&(i=et(s,e))}let r=e.fontSize*(n/i);return r<us?null:{size:r}},eE=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=ps(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=re(e.x,e.y),u=cs(c,e.width,e.height,l,s,e.angle,i,!1,o);n.mutateElement(t,{fontSize:d.size,width:l,height:s,x:u.x,y:u.y});return}if(i==="e"||i==="w"){let c=Hi(vo({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),p=Pt(t.originalText,vo(t),Math.abs(u)),m=Je(p,vo(t),t.lineHeight),f=m.height,E=re(e.x,e.y),h=cs(E,e.width,e.height,u,f,t.angle,i,!1,o),g={width:Math.abs(u),height:Math.abs(m.height),x:h.x,y:h.y,text:p,autoResize:!1};n.mutateElement(t,g)}}},tE=(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+=Co/2,d-=d%Co);for(let c of t)if(!Z(c)){let[u,p,m,f]=_(c,l),E=(u+m)/2,h=(p+f)/2,g=e.get(c.id)?.angle??c.angle,[x,y]=it(re(E,h),re(s,a),d+g-c.angle),b=G(c)?{points:Ka(c,l)}:{x:c.x+(x-E),y:c.y+(y-h),angle:Lo(d+g)};n.mutateElement(c,b),Ue(c,n,{simultaneouslyUpdated:t});let w=W(c,l);if(w&&!Y(c)){let{x:I,y:M}=ei(c,w,l);n.mutateElement(w,{x:I,y:M,angle:Lo(d+g)})}}n.triggerUpdate()},zI=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?_(t[0],n):Xe(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=it(re(i,o),re(d,c),-u),e){case"n":return it(re(i-(r+a)/2,o-s),re(0,0),u);case"s":return it(re(i-(r+a)/2,o-l),re(0,0),u);case"w":return it(re(i-r,o-(s+l)/2),re(0,0),u);case"e":return it(re(i-a,o-(s+l)/2),re(0,0),u);case"nw":return it(re(i-r,o-s),re(0,0),u);case"ne":return it(re(i-a,o-s),re(0,0),u);case"sw":return it(re(i-r,o-l),re(0,0),u);case"se":return it(re(i-a,o-l),re(0,0),u);default:return[0,0]}},_I=(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"},nE=(e,t,n)=>{if(n)return"center";if(t)switch(e){case"n":return"south-side";case"e":return"west-side";case"s":return"north-side";case"w":return"east-side";case"ne":return"bottom-left";case"nw":return"bottom-right";case"se":return"top-left";case"sw":return"top-right"}return["e","se","s"].includes(e)?"top-left":["n","nw","w"].includes(e)?"bottom-right":e==="ne"?"bottom-left":"top-right"},cs=(e,t,n,i,o,r,s,a,l)=>{let d=nE(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)}}},iE=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(ie(n)&&ie(i))return eE(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),p=W(n,u);if(p){let h=o.get(p.id);if(h&&(c={fontSize:h.fontSize}),l){let g={...n,width:e,height:t},x=ps(p,u,et(g,p));if(x===null)return;c={fontSize:x.size}}else{let g=ma(vo(p),p.lineHeight),x=fa(p.fontSize,p.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let m=Vd(i,e,t,!0),f=re(i.x,i.y);if(j(i)){let[h,g]=he(i,o);f=re(h,g)}let E=cs(f,i.width,i.height,e,t,i.angle,s,l,d);if(j(i)&&m.points){let h=i.x-f[0],g=i.y-f[1];E.x+=h,E.y+=g;let x=m.points[0][0],y=m.points[0][1];E.x+=x,E.y+=y,m.points=m.points.map(b=>re(b[0]-x,b[1]-y))}if(e<0&&(E.x=E.x+e),t<0&&(E.y=E.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),Y(n)&&p&&l){let h=e/n.width*p.fontSize;if(h<us)return;c.fontSize=h}if(e!==0&&t!==0&&Number.isFinite(E.x)&&Number.isFinite(E.y)){let h={...E,width:Math.abs(e),height:Math.abs(t),...m};r.mutateElement(n,h,{informMutation:a,isDragging:!1}),p&&c!=null&&r.mutateElement(p,{fontSize:c.fontSize}),hn(n,r,s,l),Ue(n,r,{newSize:{width:e,height:t}})}},oE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=Nt(t,t.width,t.height,!0),u=re(a,l),p=re(d,c),m=Qh(u,p),f=it(re(i,o),m,-t.angle),[E,h,g,x]=Nt(e,e.width,e.height,!0),y=g-E,b=x-h,w=p[0]-u[0],I=p[1]-u[1],M=w/y,D=I/b;n.includes("e")&&(M=(f[0]-u[0])/y),n.includes("s")&&(D=(f[1]-u[1])/b),n.includes("w")&&(M=(p[0]-f[0])/y),n.includes("n")&&(D=(p[1]-f[1])/b);let T=e.width*M,N=e.height*D;if(s&&(T=2*T-t.width,N=2*N-t.height),r){let C=Math.abs(T)/t.width,R=Math.abs(N)/t.height;if(n.length===1&&(N*=C,T*=R),n.length===2){let L=Math.max(C,R);T=t.width*L*Math.sign(T),N=t.height*L*Math.sign(N)}}return{nextWidth:T,nextHeight:N}},rE=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(L=>t.get(L.id)),d=l.reduce((L,V)=>{if(!j(V))return L;let H=It(V);if(!H)return L;let te=t.get(H)??null;return ce(te)?[...L,{...te,...U.getBoundTextElementPosition(V,te,n)}]:L},[]),c=Ct(l.map(L=>L).concat(d)),{minX:u,minY:p,maxX:m,maxY:f,midX:E,midY:h}=c,g=m-u,x=f-p,y={ne:[u,f],se:[u,p],sw:[m,p],nw:[m,f],e:[u,p+x/2],w:[m,p+x/2],n:[u+g/2,f],s:[u+g/2,p]},[b,w]=a?[E,h]:y[i],I=a?2:1,M=Math.max(Math.abs(o-b)/g||0,Math.abs(r-w)/x||0)*I,D=i.includes("e")||i.includes("w")?Math.abs(o-b)*I:g,T=i.includes("n")||i.includes("s")?Math.abs(r-w)*I:x;s&&(D=g*M*Math.sign(o-b),T=x*M*Math.sign(r-w));let N={ne:[o<b,r>w],se:[o<b,r<w],sw:[o>b,r<w],nw:[o>b,r>w],e:[o<b,!1],w:[o>b,!1],n:[!1,r>w],s:[!1,r<w]},[C,R]=N[i].map(L=>L);return{originalBoundingBox:c,nextWidth:D,nextHeight:T,flipByX:C,flipByY:R}},sE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:d,nextWidth:c,originalBoundingBox:u}={})=>{if(c===void 0&&d===void 0&&a===void 0&&l===void 0||d===0||c===0)return;o||(o=t);let p=e.reduce((I,M)=>{let D=o.get(M.id);return D&&I.push({orig:D,latest:M}),I},[]),m;if(u)m=u;else{let I=p.reduce((M,{orig:D})=>{if(!j(D))return M;let T=It(D);if(!T)return M;let N=o.get(T)??null;return ce(N)?[...M,{...N,...U.getBoundTextElementPosition(D,N,t)}]:M},[]);m=Ct(p.map(({orig:M})=>M).concat(I))}let{minX:f,minY:E,maxX:h,maxY:g,midX:x,midY:y}=m,b=h-f,w=g-E;if(c===void 0&&d===void 0&&(c=b,d=w),r&&(c===void 0?c=d*(b/w):d===void 0?d=c*(w/b):Math.abs(c/d-b/w)>.001&&(c=d*(b/w))),c&&d){let I=n.includes("e")||n.includes("w")?Math.abs(c)/b:1,M=n.includes("n")||n.includes("s")?Math.abs(d)/w:1,D;n.length===1?D=n.includes("e")||n.includes("w")?I:M:D=Math.max(Math.abs(c)/b||0,Math.abs(d)/w||0);let T={ne:[f,g],se:[f,E],sw:[h,E],nw:[h,g],e:[f,E+w/2],w:[h,E+w/2],n:[f+b/2,g],s:[f+b/2,E]},[N,C]=s?[x,y]:T[n],R=r||p.some(S=>S.latest.angle!==0||ie(S.latest)||xl(S.latest));R&&(I=D,M=D);let[L,V]=[a?-1:1,l?-1:1],H=[];for(let{orig:S,latest:Q}of p){if(ie(S)&&ce(S))continue;let $=S.width*I,ne=S.height*M,sn=Lo(S.angle*L*V),ot=j(S)||Me(S),wn=S.x-N,ko=S.y-C,mi=a&&!ot?$:0,Hn=l&&!ot?ne:0,Oo=N+L*(wn*I+mi),fi=C+V*(ko*M+Hn),an=Vd(S,$*L,ne*V,!1),xe={x:Oo,y:fi,width:$,height:ne,angle:sn,...an};if(G(S)&&(S.startBinding&&(xe.startBinding={...S.startBinding,fixedPoint:[a?-S.startBinding.fixedPoint[0]+1:S.startBinding.fixedPoint[0],l?-S.startBinding.fixedPoint[1]+1:S.startBinding.fixedPoint[1]]}),S.endBinding&&(xe.endBinding={...S.endBinding,fixedPoint:[a?-S.endBinding.fixedPoint[0]+1:S.endBinding.fixedPoint[0],l?-S.endBinding.fixedPoint[1]+1:S.endBinding.fixedPoint[1]]}),S.fixedSegments&&an.points&&(xe.fixedSegments=S.fixedSegments.map(De=>({...De,start:an.points[De.index-1],end:an.points[De.index]})))),we(S)&&(xe.scale=[S.scale[0]*L,S.scale[1]*V]),ie(S)){let De=ps(S,t,$);if(!De)return;xe.fontSize=De.size}let ln=o.get(It(S)??"");if(ln)if(R){let De=ln.fontSize*D;if(De<us)return;xe.boundTextFontSize=De}else xe.boundTextFontSize=ln.fontSize;H.push({element:Q,update:xe})}let te=H.map(({element:S})=>S);for(let{element:S,update:{boundTextFontSize:Q,...$}}of H){let{width:ne,height:sn,angle:ot}=$;i.mutateElement(S,$),Ue(S,i,{simultaneouslyUpdated:te,newSize:{width:ne,height:sn}});let wn=W(S,t);wn&&Q&&(i.mutateElement(wn,{fontSize:Q,angle:j(S)?void 0:ot}),hn(S,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as Ze,pointOnLineSegment as Jd,pointRotateRads as Go}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as xs}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as fs,isAndroid as aE,isIOS as lE}from"@excalidraw/common";import{pointFrom as $d,pointRotateRads as dE}from"@excalidraw/math";var Zd={mouse:8,pen:16,touch:28},cE=16,Kd={e:!0,s:!0,n:!0,w:!0},$I={e:!0,s:!0,n:!0,w:!0},ZI={e:!0,s:!0,n:!0,w:!0,rotation:!0},qd={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},ms={e:!0,s:!0,n:!0,w:!0},kt=(e,t,n,i,o,r,s)=>{let[a,l]=dE($d(e+n/2,t+i/2),$d(o,r),s);return[a-n/2,l-i/2,n,i]},Bo=e=>!(e.viewport.isMobile||e.isTouchScreen&&(aE||lE)),hs=e=>Bo(e)?Kd:{},Es=([e,t,n,i,o,r],s,a,l,d={},c=4,u=fs)=>{let p=Zd[l],m=p/a.value,f=p/a.value,E=p/a.value,h=p/a.value,g=n-e,x=i-t,y=c/a.value,b=(p-u*2)/(2*a.value),w={nw:d.nw?void 0:kt(e-y-E+b,t-y-h+b,m,f,o,r,s),ne:d.ne?void 0:kt(n+y-b,t-y-h+b,m,f,o,r,s),sw:d.sw?void 0:kt(e-y-E+b,i+y-b,m,f,o,r,s),se:d.se?void 0:kt(n+y-b,i+y-b,m,f,o,r,s),rotation:d.rotation?void 0:kt(e+g/2-m/2,t-y-h+b-cE/a.value,m,f,o,r,s)},I=5*Zd.mouse/a.value;return Math.abs(g)>I&&(d.n||(w.n=kt(e+g/2-m/2,t-y-h+b,m,f,o,r,s)),d.s||(w.s=kt(e+g/2-m/2,i+y-b,m,f,o,r,s))),Math.abs(x)>I&&(d.w||(w.w=kt(e-y-E+b,t+x/2-f/2,m,f,o,r,s)),d.e||(w.e=kt(n+y-b,t+x/2-f/2,m,f,o,r,s))),w},Qd=(e,t,n,i="mouse",o=Kd)=>{if(e.locked||G(e))return{};if(e.type==="freedraw"||j(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=ms:s[0]>0&&s[1]<0?o=qd:s[0]>0&&s[1]>0?o=ms:s[0]<0&&s[1]>0?o=qd:s[0]<0&&s[1]<0&&(o=ms)}}else Z(e)&&(o={...o,rotation:!0});let r=j(e)?fs+8:we(e)?0:fs;return Es(_(e,n,!0),e.angle,t,i,o,r,we(e)?0:void 0)},qI=(e,t)=>{if(t.selectedLinearElement?.isEditing)return!1;if(e.length>1)return!0;let n=e[0];return G(n)?!1:j(n)?n.points.length>2:!0};var ws=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],uE=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=Qd(e,r,t,s,hs(a));if(l&&ws(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let p=d[u];return p?ws(p,i,o):!1});if(c.length>0)return c[0];if(Bo(a)){let[u,p,m,f,E,h]=_(e,t);if(!(j(e)&&e.points.length<=2)){let g=we(e)?0:xs/r.value,x=xs/r.value,y=ec(Ze(u-g,p-g),Ze(m+g,f+g),Ze(E,h),e.angle);for(let[b,w]of Object.entries(y))if(Jd(Ze(i,o),w,x))return b}}return!1},oS=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=uE(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),rS=([e,t,n,i],o,r,s,a,l)=>{let d=Es([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,hs(l)),c=Object.keys(d).find(u=>{let p=d[u];return p&&ws(p,o,r)});if(c)return c;if(Bo(l)){let u=(e+n)/2,p=(t+i)/2,m=xs/s.value,f=ec(Ze(e-m,t-m),Ze(n+m,i+m),Ze(u,p),0);for(let[E,h]of Object.entries(f))if(Jd(Ze(o,r),h,m))return E}return!1},gs=["ns","nesw","ew","nwse"],pE=(e,t)=>{let n=gs.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=gs[(n+i)%gs.length]}return e},sS=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=pE(o,t.angle)),o?`${o}-resize`:""},ec=([e,t],[n,i],o,r)=>{let s=Go(Ze(e,t),o,r),a=Go(Ze(n,t),o,r),l=Go(Ze(e,i),o,r),d=Go(Ze(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var cS=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||pt(t,e).length));P();import{arrayToMap as nc,findIndex as ic,findLastIndex as oc}from"@excalidraw/common";var ys=(e,t)=>e.frameId===t||e.id===t,rc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=nc(n||pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(o.length&&(i=i.concat(o),o=[]),i.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,o.push(s)):o=[]}return i},mE=e=>{let t=0;return e.reduce((n,i,o)=>(o>0&&e[o-1]!==i-1&&(t=++t),(n[t]||(n[t]=[])).push(i),n),[])},tc=(e,t,n,i)=>{if("containerId"in e&&e.containerId){let o=i.getElement(e.containerId);if(o)return n==="left"?Math.min(t.indexOf(o),t.indexOf(e)):Math.max(t.indexOf(o),t.indexOf(e))}else{let o=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(o){let r=i.getElement(o);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},fE=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{ys(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},hE=(e,t,n,i,o,r)=>{let s=t[n],a=p=>p.isDeleted?!1:o?p.frameId===o:e.editingGroupId?p.groupIds.includes(e.editingGroupId):!0,l=i==="left"?oc(t,p=>a(p),Math.max(0,n-1)):ic(t,p=>a(p),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return tc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||Z(d))){let p=fE(t,d.frameId||d.id);return i==="left"?t.indexOf(p[0]):t.indexOf(p[p.length-1])}if(!d.groupIds.length)return tc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Ae(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},sc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),ac=(e,t,n,i)=>{let o=rc(e,t),r=sc(e,o),s=mE(o);n==="right"&&(s=s.reverse());let a=new Set(o.filter(l=>Z(e[l])).map(l=>e[l].id));return s.forEach((l,d)=>{let c=l[0],u=l[l.length-1],p=n==="left"?c:u,m=l.some(y=>{let b=e[y];return b.frameId&&a.has(b.frameId)})?null:e[p]?.frameId,f=hE(t,e,p,n,m,i);if(f===-1||p===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,c),h=e.slice(c,u+1),g=n==="left"?e.slice(f,c):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...E,...h,...g,...x]:[...E,...g,...h,...x]}),pi(e,r),e},lc=(e,t,n,i,o)=>{let r=rc(e,t,o),s=sc(e,r),a=[],l,d;if(n==="left"){if(i)l=ic(e,f=>ys(f,i));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;d=r[r.length-1]}else{if(i)d=oc(e,f=>ys(f,i));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let c=Array.from(s.values()),u=e.slice(0,l),p=e.slice(d+1),m=n==="left"?[...u,...c,...a,...p]:[...u,...a,...c,...p];return pi(m,s),m};function dc(e,t,n,i){let o=nc(pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)o.has(d.id)&&Z(d)&&s.add(d.id);for(let d of e)if(o.has(d.id))if(Z(d)||d.frameId&&s.has(d.frameId))r.regularElements.push(d);else if(!d.frameId)r.regularElements.push(d);else{let c=r.frameChildren.get(d.frameId)||[];c.push(d),r.frameChildren.set(d.frameId,c)}let a=e,l=Array.from(r.frameChildren.entries());for(let[d,c]of l)a=i(e,t,n,d,c);return i(a,t,n,null,r.regularElements)}var xS=(e,t,n)=>ac(e,t,"left",n),wS=(e,t,n)=>ac(e,t,"right",n),yS=(e,t)=>dc(e,t,"left",lc),bS=(e,t)=>dc(e,t,"right",lc);var AS=e=>e.reduce((t,n)=>t+n.version,0),rd=e=>{let t=5381;for(let n of EE(e))t=(t<<5)+t+n.versionNonce;return t>>>0},sd=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},DS=e=>e.filter(t=>!t.isDeleted&&!Kl(t)),gE=e=>e.filter(t=>!t.isDeleted),vS=e=>!e.isDeleted,bs=e=>gE(e).map(t=>Qo(t.type)?{...t,lastCommittedPoint:null}:t),LS=e=>bs(e),CS=e=>bs(e),BS=e=>bs(e);export{Jt as AppStateDelta,ee as BASE_PADDING,Fp as BINDING_HIGHLIGHT_THICKNESS,$t as BindableElement,Vt as BoundElement,Fe as CaptureUpdateAction,qb as DEFAULT_LINK_SIZE,Kd as DEFAULT_OMIT_SIDES,F as Delta,qr as DurableIncrement,Xr as ElementBounds,en as ElementsDelta,Kr as EphemeralIncrement,oe as FIXED_BINDING_DISTANCE,Yd as FlowChartCreator,_d as FlowChartNavigator,ye as HEADING_DOWN,ke as HEADING_LEFT,me as HEADING_RIGHT,ze as HEADING_UP,jm as IMAGE_INVERT_FILTER,wf as INVISIBLY_SMALL_ELEMENT_SIZE,Jr as InvalidFractionalIndexError,U as LinearElementEditor,Se as MINIMAL_CROP_SIZE,ZI as OMIT_SIDES_FOR_FRAME,$I as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,So as Scene,Pe as ShapeCache,td as Store,ci as StoreChange,Qr as StoreDelta,yo as StoreIncrement,tn as StoreSnapshot,$e as aabbForElement,Gm as addElementsToFrame,$h as addNewNodes,Wy as addToGroup,e1 as alignElements,qp as avoidRectangularCorner,Pl as bindElementsToFramesAfterDuplication,gn as bindLinearElement,Ar as bindOrUnbindLinearElement,_p as bindOrUnbindLinearElements,Ir as bindPointToSnapToElementOutline,io as bindingBorderTest,qa as bindingProperties,Ra as bumpVersion,Va as calculateFixedPointForElbowArrowBinding,vx as canApplyRoundnessTypeToElement,da as canBecomePolygon,Rl as canChangeRoundness,yh as canCreateLinkFromElements,s0 as canHaveArrowheads,Bo as canResizeFromSides,Sn as charWidth,LS as clearElementsForDatabase,CS as clearElementsForExport,BS as clearElementsForLocalStorage,pe as compareHeading,ei as computeBoundTextPosition,ar as computeContainerDimensionForBoundText,$x as containsCJK,KP as createPlaceholderEmbeddableLabel,rs as createSrcDoc,mx as cropElement,In as deconstructDiamondElement,Bi as deconstructLinearOrFreeDrawElement,Pn as deconstructRectanguloidElement,Zr as deepCopyElement,IP as defaultGetElementLinkFromSelection,_x as detectLineHeight,_t as distanceToElement,sP as distributeElements,En as doBoundsIntersect,xP as dragNewElement,EP as dragSelectedElements,vf as duplicateElement,f1 as duplicateElements,jy as editGroupForSelectedElement,fe as elementCenterPoint,Zt as elementOverlapsWithFrame,go as elementWithCanvasCache,Kt as elementsAreInFrameBounds,gl as elementsAreInSameGroup,JP as embeddableURLValidator,yl as excludeElementsInFramesFromSelection,Db as filterElementsEligibleAsFrameChildren,hy as fixBindingsAfterDeletion,Za as fixDuplicatedBindingsAfterDuplication,mr as flipHeading,kb as frameAndChildrenSelectedTogether,Ol as generateFreeDrawShape,na as generateLinearCollisionShape,Re as generateRoughOptions,fa as getApproxMinLineHeight,ma as getApproxMinLineWidth,Ka as getArrowLocalFixedPoints,mf as getArrowheadAngle,_r as getArrowheadPoints,pf as getArrowheadSize,W as getBoundTextElement,It as getBoundTextElementId,sw as getBoundTextElementPosition,ti as getBoundTextMaxHeight,et as getBoundTextMaxWidth,jr as getBoundsFromPoints,dt as getCenterForBounds,N0 as getClosestElementBounds,Ct as getCommonBoundingBox,Xe as getCommonBounds,ow as getContainerCenter,lr as getContainerCoords,Ce as getContainerElement,vt as getContainingFrame,yt as getCornerRadius,Wi as getCubicBezierCurveBound,sS as getCursorForResizingElement,Nm as getDefaultFrameName,Lx as getDefaultRoundnessTypeForElement,Gi as getDiamondPoints,gP as getDragOffsetXY,F0 as getDraggedElementsBounds,_ as getElementAbsoluteCoords,he as getElementBounds,Fr as getElementLineSegments,Cr as getElementPointsCoords,Yl as getElementShape,oS as getElementWithTransformHandleType,Il as getElementsCompletelyInFrame,Ae as getElementsInGroup,Ab as getElementsInNewFrame,Tb as getElementsInResizingFrame,yb as getElementsIntersectingFrame,Gb as getElementsOverlappingFrame,Or as getElementsWithinSelection,qP as getEmbedLink,fx as getFlipAdjustedCropPosition,qt as getFrameChildren,Cm as getFrameLikeElements,Bb as getFrameLikeTitle,Zm as getFreeDrawPath2D,qm as getFreeDrawSvgPath,to as getGlobalFixedPointForBindableElement,tm as getGlobalFixedPoints,Oa as getHeadingForElbowArrowSnap,jt as getHoveredElementForBinding,yI as getInitializedImageElements,zi as getLineHeightInPx,zt as getLineWidth,Bx as getLinearElementSubType,mI as getLinkDirectionFromKey,SP as getLinkIdAndTypeFromSelection,ol as getLockedLinearCursorAlignSize,yu as getMaxCharWidth,$y as getMaximumGroups,Ux as getMinCharWidth,ai as getMinMaxXYFromCurvePathOps,Hi as getMinTextElementWidth,wl as getNewGroupIdsForDuplication,gE as getNonDeletedElements,El as getNonDeletedGroupIds,$0 as getNormalizedDimensions,On as getObservedAppState,hs as getOmitSidesForDevice,Rx as getOriginalContainerHeightFromCache,Wr as getPerfectElementSize,ds as getPredecessors,R0 as getRectangleBoxAbsoluteCoords,Wm as getRenderOpacity,_I as getResizeArrowDirection,zI as getResizeOffsetXY,Nt as getResizedElementAbsoluteCoords,Mb as getRootElements,AS as getSceneVersion,pt as getSelectedElements,po as getSelectedElementsByGroup,kr as getSelectedGroupForElement,Tm as getSelectedGroupIdForElement,Sm as getSelectedGroupIds,ab as getSelectionStateForElements,py as getSuggestedBindingsForArrows,sb as getTargetElements,Om as getTargetFrame,rw as getTextElementAngle,cw as getTextFromElements,wu as getTextHeight,ha as getTextWidth,rS as getTransformHandleTypeFromCoords,Qd as getTransformHandles,Es as getTransformHandlesFromCoords,Js as getUncroppedImageElement,Vo as getUncroppedWidthAndHeight,ob as getVisibleAndNonSelectedElements,DS as getVisibleElements,H0 as getVisibleSceneBounds,Sb as groupByFrameLikes,Pb as groupsAreAtLeastIntersectingTheFrame,Ib as groupsAreCompletelyOutOfFrame,hn as handleBindTextResize,t0 as hasBackground,st as hasBoundTextElement,n0 as hasStrokeColor,o0 as hasStrokeStyle,i0 as hasStrokeWidth,rd as hashElementsVersion,sd as hashString,Ge as headingForPoint,ni as headingForPointFromElement,tt as headingForPointIsHorizontal,Oe as headingIsHorizontal,Ow as headingIsVertical,np as hitElementBoundText,tp as hitElementBoundingBox,vw as hitElementBoundingBoxOnly,ep as hitElementItself,Mn as intersectElementWithLineSegment,Dx as isArrowBoundToElement,Y as isArrowElement,Le as isBindableElement,Jo as isBindingElement,pu as isBindingElementType,Tr as isBindingEnabled,ce as isBoundToContainer,Cx as isBounds,bb as isCursorInFrame,uu as isCurvedArrow,G as isElbowArrow,V0 as isElementCompletelyInViewport,Nr as isElementContainingFrame,Ml as isElementInFrame,Mm as isElementInGroup,bl as isElementInViewport,Gn as isElementIntersectingFrame,MP as isElementLink,oa as isEmbeddableElement,Ax as isExcalidrawElement,Qn as isFixedPointBinding,er as isFlowchartNodeElement,Ri as isFrameElement,Z as isFrameLikeElement,Me as isFreeDrawElement,du as isFreeDrawElementType,Kh as isHTMLSVGElement,ki as isIframeElement,Oi as isIframeLikeElement,we as isImageElement,xl as isInGroup,Ht as isInitializedImageElement,Kl as isInvisiblySmallElement,mn as isLineElement,j as isLinearElement,ja as isLinearElementSimpleAndAlreadyBound,Qo as isLinearElementType,ra as isMagicFrameElement,zx as isMeasureTextSupported,fI as isNodeInFlowchart,vS as isNonDeletedElement,pn as isPathALoop,Ma as isPointInElement,Tx as isRectangularElement,sa as isRectanguloidElement,Im as isSelectedViaGroup,cu as isSharpArrow,Mx as isSimpleArrow,rb as isSomeElementSelected,mu as isTextBindableContainer,ie as isTextElement,aa as isUsingAdaptiveRadius,la as isUsingProportionalRadius,Gx as isValidPolygon,dw as isValidTextContainer,qh as loadHTMLImageElement,Gr as makeNextSelectedElementIds,ao as maxBindingGap,my as maybeBindLinearElement,QP as maybeParseEmbedSrc,Ua as maybeSuggestBindingsForLinearElementAtCoords,ps as measureFontSizeFromWidth,Je as measureText,yS as moveAllLeft,bS as moveAllRight,xS as moveOneLeft,wS as moveOneRight,be as mutateElement,kd as newArrowElement,is as newElement,Ee as newElementWith,RP as newEmbeddableElement,NP as newFrameElement,_P as newFreeDrawElement,FP as newIframeElement,UP as newImageElement,YP as newLinearElement,HP as newMagicFrameElement,Gd as newTextElement,Ql as normalizeElementOrder,Dr as normalizeFixedPoint,bI as normalizeSVG,nr as normalizeText,mo as omitGroupsContainingFrameLikes,Bm as omitPartialGroups,md as orderByFractionalIndex,Jn as originalContainerCache,TP as parseElementLinkFromURL,Au as parseTokens,kl as pathsCache,An as pointInsideBounds,TI as positionElementsOnGrid,wa as redrawTextBoundingBox,zP as refreshTextDimensions,km as removeAllElementsFromFrame,Sl as removeElementsFromFrame,Vy as removeFromSelectedGroups,Qb as renderElement,Kb as renderSelectionElement,vb as replaceAllElementsInFrame,Vd as rescalePointsInElement,ua as resetOriginalContainerCache,sE as resizeMultipleElements,iE as resizeSingleElement,eE as resizeSingleTextElement,uE as resizeTest,Pm as selectGroup,fl as selectGroupsForSelectedElements,hl as selectGroupsFromGivenElements,Yx as setCustomTextMetricsProvider,aw as shouldAllowVerticalAlign,Cb as shouldApplyFrameClip,uy as shouldEnableBindingForPointerEvent,qI as shouldShowBoundingBox,ji as shouldTestInside,cS as showSelectedShapeActions,Kp as snapToMid,lw as suppportsHorizontalAlign,Hf as syncInvalidIndices,od as syncInvalidIndicesImmutable,pi as syncMovedIndices,il as toggleLinePolygonState,r0 as toolIsArrow,HI as transformElements,fy as updateBindings,Ue as updateBoundElements,Dn as updateElbowArrowPoints,Lb as updateFrameMembershipOfSelectedElements,wI as updateImageCache,ca as updateOriginalContainerCache,ka as validateElbowPoints,Nf as validateFractionalIndices,Mt as vectorToHeading,Pt as wrapText};
27
+ `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return ht.set(e,m),m}return ht.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},lI=e=>{let t;Yi(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=Uh.Helvetica,o=Xh({fontSize:n,fontFamily:i});return Vd({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:Mt(t,o,e.width-20),textAlign:"center",verticalAlign:Yh.MIDDLE,angle:e.angle??0})},ys=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(ws.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return ws.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},dI=e=>{let t=e.match(qh);if(t&&t.length===2)return t[1];let n=e.match(Jh);if(n&&n.length===2)return n[1];let i=e.match($h);if(i&&i.length===2)return i[1];if(Kd.test(e))return`https://giphy.com/embed/${Kd.exec(e)[1]}`;let o=e.match(Qh);return o&&o.length===2?o[1]:e},cI=(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(ys(e,n))return!0;return!1}}return!!ys(e,ws)};P();import{KEYS as No,invariant as Ho,toBrandedType as tE}from"@excalidraw/common";import{pointFrom as ec}from"@excalidraw/math";var Yn=100,Sn=100,SI=e=>{switch(e){case No.ARROW_UP:return"up";case No.ARROW_DOWN:return"down";case No.ARROW_RIGHT:return"right";case No.ARROW_LEFT:return"left";default:return"right"}},ic=(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;Ho(He(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=ai(t,Ze(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=>ue(r.heading,_e)).map(r=>r.relative);case"down":return o.filter(r=>ue(r.heading,we)).map(r=>r.relative);case"right":return o.filter(r=>ue(r.heading,me)).map(r=>r.relative);case"left":return o.filter(r=>ue(r.heading,Ge)).map(r=>r.relative)}},bs=(e,t,n)=>ic("successors",e,t,n),Ps=(e,t,n)=>ic("predecessors",e,t,n),nE=(e,t,n)=>{let i=Sn+e.width;if(n==="up"||n==="down"){let a=Yn+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:(Sn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Yn+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=Yn+e.height,r=(t.length===0,Sn+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}},iE=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=bs(e,o,n),s=Ps(e,o,n),a=nE(e,[...r,...s],n),l=Es({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});Ho(ar(l),"not an ExcalidrawFlowchartNodeElement");let d=oc(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},oE=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=Yn*(o-1)+o*e.height,m=e.y+e.height/2-u/2,p=Sn+e.width;n==="left"&&(p*=-1),a=e.x+p;let f=(Yn+e.height)*s;l=m+f}else{let u=Sn*(o-1)+o*e.width,m=e.x+e.width/2-u/2,p=Yn+e.height;n==="up"&&(p*=-1),l=e.y+p;let f=(Sn+e.width)*s;a=m+f}let d=Es({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});Ho(ar(d),"not an ExcalidrawFlowchartNodeElement");let c=oc(e,d,n,t,i);r.push(d),r.push(c)}return r},oc=(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=$d({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:[ec(0,0),ec(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();Eo(c,e,"orbit","start",o),Eo(c,t,"orbit","end",o);let m=new Map;m.set(e.id,e),m.set(t.id,t),m.set(c.id,c),k.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=Gn(c,tE(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p}},tc=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(!He(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=[...bs(t,n,i),...Ps(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=>[...bs(t,n,a),...Ps(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}},nc=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}=iE(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=oE(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);Ho(s&&ji(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>sn([a],s,r)||on(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>ye(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},MI=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{MIME_TYPES as rc,SVG_NS as rE}from"@excalidraw/common";var sE=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),LI=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===rc.binary)throw new Error("Only images can be added to ImageCache");let l=sE(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}},BI=e=>e.filter(t=>Xt(t)),aE=e=>e?.nodeName.toLowerCase()==="svg",CI=e=>{let t=new DOMParser().parseFromString(e,rc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!aE(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",rE);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 FI=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(p=>[p]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let p=0;p<s;p+=a)l.push(r.slice(p,p+a));let d=0,c=l.map(p=>{let f=0,h=0,E=p.map(g=>{let[x,y,b,w]=Ye(g);return{elements:g,bounds:[x,y,b,w],width:b-x,height:w-y}});return E.forEach((g,x)=>{f+=g.width,x<E.length-1&&(f+=i),g.height>h&&(h=g.height)}),d+=h,{unitBounds:E,width:f,maxHeight:h}}),u=d+Math.max(0,l.length-1)*i,m=n-u/2;return c.forEach(p=>{let{unitBounds:f,width:h,maxHeight:E}=p,g=t-h/2;f.forEach(x=>{let[y,b]=x.bounds,w=g-y,I=m-b;x.elements.forEach(S=>{o.push(ge(S,{x:S.x+w,y:S.y+I}))}),g+=x.width+i}),m+=E+i}),o};P();import{pointCenter as lE,normalizeRadians as _o,pointFrom as ie,pointRotateRads as st}from"@excalidraw/math";import{MIN_FONT_SIZE as Ss,SHIFT_LOCKING_ANGLE as Uo,rescalePoints as sc,getFontString as zo}from"@excalidraw/common";var qI=(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)||(dE(m,i,a,l,o),Ue(m,i));else if(t){let p=n[0].id,f=u.get(p),h=e.get(p);if(f&&h){let{nextWidth:E,nextHeight:g}=fE(f,h,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});pE(E,g,f,h,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return J(m)&&Ue(m,i),!0}else if(n.length>1){if(t==="rotation")return uE(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:f,flipByY:h,originalBoundingBox:E}=hE(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return EE(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:h,nextWidth:m,nextHeight:p,originalBoundingBox:E}),!0}}return!1},dE=(e,t,n,i,o)=>{let[r,s,a,l]=X(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+Uo/2,u=u-u%Uo),u=_o(u));let m=At(e),p={angle:u};if(Le(e)&&(p={...p},e.startBinding&&qe(e,"start",t),e.endBinding&&qe(e,"end",t)),t.mutateElement(e,p),m){let f=t.getElement(m);if(f&&!H(e)){let{x:h,y:E}=oi(e,f,t.getNonDeletedElementsMap());t.mutateElement(f,{angle:u,x:h,y:E})}}},ac=(e,t,n,i)=>K(e)||Ie(e)?{points:sc(0,t,sc(1,n,e.points,i),i)}:{},Ms=(e,t,n)=>{let i=e.width;if(le(e)){let s=Se(e,t);s&&(i=nt(s,e))}let r=e.fontSize*(n/i);return r<Ss?null:{size:r}},cE=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=Ms(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=ie(e.x,e.y),u=Is(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=Zi(zo({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=Mt(t.originalText,zo(t),Math.abs(u)),p=tt(m,zo(t),t.lineHeight),f=p.height,h=ie(e.x,e.y),E=Is(h,e.width,e.height,u,f,t.angle,i,!1,o),g={width:Math.abs(u),height:Math.abs(p.height),x:E.x,y:E.y,text:m,autoResize:!1};n.mutateElement(t,g)}}},uE=(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+=Uo/2,d-=d%Uo);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!q(u)){let[m,p,f,h]=X(u,l),E=(m+f)/2,g=(p+h)/2,x=e.get(u.id)?.angle??u.angle,[y,b]=st(ie(E,g),ie(s,a),d+x-u.angle),w=U(u)?{points:al(u,l)}:{x:u.x+(y-E),y:u.y+(b-g),angle:_o(d+x)};n.mutateElement(u,w),Ue(u,n,{simultaneouslyUpdated:t}),Le(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||qe(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||qe(u,"end",n)));let I=W(u,l);if(I&&!H(u)){let{x:S,y:A}=oi(u,I,l);n.mutateElement(I,{x:S,y:A,angle:_o(d+x)})}}n.triggerUpdate()},KI=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?X(t[0],n):Ye(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=st(ie(i,o),ie(d,c),-u),e){case"n":return st(ie(i-(r+a)/2,o-s),ie(0,0),u);case"s":return st(ie(i-(r+a)/2,o-l),ie(0,0),u);case"w":return st(ie(i-r,o-(s+l)/2),ie(0,0),u);case"e":return st(ie(i-a,o-(s+l)/2),ie(0,0),u);case"nw":return st(ie(i-r,o-s),ie(0,0),u);case"ne":return st(ie(i-a,o-s),ie(0,0),u);case"sw":return st(ie(i-r,o-l),ie(0,0),u);case"se":return st(ie(i-a,o-l),ie(0,0),u);default:return[0,0]}},QI=(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"},mE=(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"},Is=(e,t,n,i,o,r,s,a,l)=>{let d=mE(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)}}},pE=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(J(n)&&J(i))return cE(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=W(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=Ms(m,u,nt(g,m));if(x===null)return;c={fontSize:x.size}}else{let g=va(zo(m),m.lineHeight),x=Da(m.fontSize,m.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let p=ac(i,e,t,!0),f=ie(i.x,i.y);if(K(i)){let[E,g]=se(i,o);f=ie(E,g)}let h=Is(f,i.width,i.height,e,t,i.angle,s,l,d);if(K(i)&&p.points){let E=i.x-f[0],g=i.y-f[1];h.x+=E,h.y+=g;let x=p.points[0][0],y=p.points[0][1];h.x+=x,h.y+=y,p.points=p.points.map(b=>ie(b[0]-x,b[1]-y))}if(e<0&&(h.x=h.x+e),t<0&&(h.y=h.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),H(n)&&m&&l){let E=e/n.width*m.fontSize;if(E<Ss)return;c.fontSize=E}if(e!==0&&t!==0&&Number.isFinite(h.x)&&Number.isFinite(h.y)){let E={...h,width:Math.abs(e),height:Math.abs(t),...p};Le(n)&&(n.startBinding&&(E={...E},n.startBinding&&qe(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}),wn(n,r,s,l),Ue(n,r)}},fE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=Yt(t,t.width,t.height,!0),u=ie(a,l),m=ie(d,c),p=lE(u,m),f=st(ie(i,o),p,-t.angle),[h,E,g,x]=Yt(e,e.width,e.height,!0),y=g-h,b=x-E,w=m[0]-u[0],I=m[1]-u[1],S=w/y,A=I/b;n.includes("e")&&(S=(f[0]-u[0])/y),n.includes("s")&&(A=(f[1]-u[1])/b),n.includes("w")&&(S=(m[0]-f[0])/y),n.includes("n")&&(A=(m[1]-f[1])/b);let M=e.width*S,F=e.height*A;if(s&&(M=2*M-t.width,F=2*F-t.height),r){let B=Math.abs(M)/t.width,G=Math.abs(F)/t.height;if(n.length===1&&(F*=B,M*=G),n.length===2){let D=Math.max(B,G);M=t.width*D*Math.sign(M),F=t.height*D*Math.sign(F)}}return{nextWidth:M,nextHeight:F}},hE=(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,V)=>{if(!K(V))return D;let N=At(V);if(!N)return D;let Z=t.get(N)??null;return le(Z)?[...D,{...Z,...k.getBoundTextElementPosition(V,Z,n)}]:D},[]),c=Rt(l.map(D=>D).concat(d)),{minX:u,minY:m,maxX:p,maxY:f,midX:h,midY:E}=c,g=p-u,x=f-m,y={ne:[u,f],se:[u,m],sw:[p,m],nw:[p,f],e:[u,m+x/2],w:[p,m+x/2],n:[u+g/2,f],s:[u+g/2,m]},[b,w]=a?[h,E]:y[i],I=a?2:1,S=Math.max(Math.abs(o-b)/g||0,Math.abs(r-w)/x||0)*I,A=i.includes("e")||i.includes("w")?Math.abs(o-b)*I:g,M=i.includes("n")||i.includes("s")?Math.abs(r-w)*I:x;s&&(A=g*S*Math.sign(o-b),M=x*S*Math.sign(r-w));let F={ne:[o<b,r>w],se:[o<b,r<w],sw:[o>b,r<w],nw:[o>b,r>w],e:[o<b,!1],w:[o>b,!1],n:[!1,r>w],s:[!1,r<w]},[B,G]=F[i].map(D=>D);return{originalBoundingBox:c,nextWidth:A,nextHeight:M,flipByX:B,flipByY:G}},EE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:d,nextWidth:c,originalBoundingBox:u}={})=>{if(c===void 0&&d===void 0&&a===void 0&&l===void 0||d===0||c===0)return;o||(o=t);let m=e.reduce((I,S)=>{let A=o.get(S.id);return A&&I.push({orig:A,latest:S}),I},[]),p;if(u)p=u;else{let I=m.reduce((S,{orig:A})=>{if(!K(A))return S;let M=At(A);if(!M)return S;let F=o.get(M)??null;return le(F)?[...S,{...F,...k.getBoundTextElementPosition(A,F,t)}]:S},[]);p=Rt(m.map(({orig:S})=>S).concat(I))}let{minX:f,minY:h,maxX:E,maxY:g,midX:x,midY:y}=p,b=E-f,w=g-h;if(c===void 0&&d===void 0&&(c=b,d=w),r&&(c===void 0?c=d*(b/w):d===void 0?d=c*(w/b):Math.abs(c/d-b/w)>.001&&(c=d*(b/w))),c&&d){let I=n.includes("e")||n.includes("w")?Math.abs(c)/b:1,S=n.includes("n")||n.includes("s")?Math.abs(d)/w:1,A;n.length===1?A=n.includes("e")||n.includes("w")?I:S:A=Math.max(Math.abs(c)/b||0,Math.abs(d)/w||0);let M={ne:[f,g],se:[f,h],sw:[E,h],nw:[E,g],e:[f,h+w/2],w:[E,h+w/2],n:[f+b/2,g],s:[f+b/2,h]},[F,B]=s?[x,y]:M[n],G=r||m.some(T=>T.latest.angle!==0||J(T.latest)||Cl(T.latest));G&&(I=A,S=A);let[D,V]=[a?-1:1,l?-1:1],N=[];for(let{orig:T,latest:j}of m){if(J(T)&&le(T))continue;let $=T.width*I,Xe=T.height*S,at=_o(T.angle*D*V),Pi=K(T)||Ie(T),jo=T.x-F,Ii=T.y-B,Xn=a&&!Pi?$:0,Wo=l&&!Pi?Xe:0,Si=F+D*(jo*I+Xn),Mi=B+V*(Ii*S+Wo),Fe=ac(T,$*D,Xe*V,!1),je={x:Si,y:Mi,width:$,height:Xe,angle:at,...Fe};if(U(T)&&(T.startBinding&&(je.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&&(je.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&&Fe.points&&(je.fixedSegments=T.fixedSegments.map(Et=>({...Et,start:Fe.points[Et.index-1],end:Fe.points[Et.index]})))),xe(T)&&(je.scale=[T.scale[0]*D,T.scale[1]*V]),J(T)){let Et=Ms(T,t,$);if(!Et)return;je.fontSize=Et.size}let Ht=o.get(At(T)??"");if(Ht)if(G){let Et=Ht.fontSize*A;if(Et<Ss)return;je.boundTextFontSize=Et}else je.boundTextFontSize=Ht.fontSize;N.push({element:j,update:je})}let Z=N.map(({element:T})=>T),O=new Map(N.map(({element:T})=>[T.id,T]));for(let{element:T,update:{boundTextFontSize:j,...$}}of N){let{angle:Xe}=$;i.mutateElement(T,$),Ue(T,i,{simultaneouslyUpdated:Z}),Le(T)&&(T.startBinding&&(O.has(T.startBinding.elementId)||qe(T,"start",i)),T.endBinding&&(O.has(T.endBinding.elementId)||qe(T,"end",i)));let at=W(T,t);at&&j&&(i.mutateElement(at,{fontSize:j,angle:K(T)?void 0:Xe}),wn(T,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as Ke,pointOnLineSegment as pc,pointRotateRads as Xo}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as Bs}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as Ts}from"@excalidraw/common";import{pointFrom as lc,pointRotateRads as gE}from"@excalidraw/math";var dc={mouse:8,pen:16,touch:28},xE=16,uc={e:!0,s:!0,n:!0,w:!0},rS={e:!0,s:!0,n:!0,w:!0},sS={e:!0,s:!0,n:!0,w:!0,rotation:!0},cc={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},As={e:!0,s:!0,n:!0,w:!0},Nt=(e,t,n,i,o,r,s)=>{let[a,l]=gE(lc(e+n/2,t+i/2),lc(o,r),s);return[a-n/2,l-i/2,n,i]},Yo=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),vs=e=>Yo(e)?uc:{},Ds=([e,t,n,i,o,r],s,a,l,d={},c=4,u=Ts)=>{let m=dc[l],p=m/a.value,f=m/a.value,h=m/a.value,E=m/a.value,g=n-e,x=i-t,y=c/a.value,b=(m-u*2)/(2*a.value),w={nw:d.nw?void 0:Nt(e-y-h+b,t-y-E+b,p,f,o,r,s),ne:d.ne?void 0:Nt(n+y-b,t-y-E+b,p,f,o,r,s),sw:d.sw?void 0:Nt(e-y-h+b,i+y-b,p,f,o,r,s),se:d.se?void 0:Nt(n+y-b,i+y-b,p,f,o,r,s),rotation:d.rotation?void 0:Nt(e+g/2-p/2,t-y-E+b-xE/a.value,p,f,o,r,s)},I=5*dc.mouse/a.value;return Math.abs(g)>I&&(d.n||(w.n=Nt(e+g/2-p/2,t-y-E+b,p,f,o,r,s)),d.s||(w.s=Nt(e+g/2-p/2,i+y-b,p,f,o,r,s))),Math.abs(x)>I&&(d.w||(w.w=Nt(e-y-h+b,t+x/2-f/2,p,f,o,r,s)),d.e||(w.e=Nt(n+y-b,t+x/2-f/2,p,f,o,r,s))),w},mc=(e,t,n,i="mouse",o=uc)=>{if(e.locked||U(e))return{};if(e.type==="freedraw"||K(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=As:s[0]>0&&s[1]<0?o=cc:s[0]>0&&s[1]>0?o=As:s[0]<0&&s[1]>0?o=cc:s[0]<0&&s[1]<0&&(o=As)}}else q(e)&&(o={...o,rotation:!0});let r=K(e)?Ts+8:xe(e)?0:Ts;return Ds(X(e,n,!0),e.angle,t,i,o,r,xe(e)?0:void 0)},aS=(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:K(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var Cs=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],wE=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=mc(e,r,t,s,vs(a));if(l&&Cs(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?Cs(m,i,o):!1});if(c.length>0)return c[0];if(Yo(a)){let[u,m,p,f,h,E]=X(e,t);if(!(K(e)&&e.points.length<=2)){let g=xe(e)?0:Bs/r.value,x=Bs/r.value,y=fc(Ke(u-g,m-g),Ke(p+g,f+g),Ke(h,E),e.angle);for(let[b,w]of Object.entries(y))if(pc(Ke(i,o),w,x))return b}}return!1},hS=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=wE(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),ES=([e,t,n,i],o,r,s,a,l)=>{let d=Ds([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,vs(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&Cs(m,o,r)});if(c)return c;if(Yo(l)){let u=(e+n)/2,m=(t+i)/2,p=Bs/s.value,f=fc(Ke(e-p,t-p),Ke(n+p,i+p),Ke(u,m),0);for(let[h,E]of Object.entries(f))if(pc(Ke(o,r),E,p))return h}return!1},Ls=["ns","nesw","ew","nwse"],yE=(e,t)=>{let n=Ls.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=Ls[(n+i)%Ls.length]}return e},gS=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=yE(o,t.angle)),o?`${o}-resize`:""},fc=([e,t],[n,i],o,r)=>{let s=Xo(Ke(e,t),o,r),a=Xo(Ke(n,t),o,r),l=Xo(Ke(e,i),o,r),d=Xo(Ke(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var bS=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||pt(t,e).length));P();import{arrayToMap as Ec,findIndex as gc,findLastIndex as xc}from"@excalidraw/common";var Gs=(e,t)=>e.frameId===t||e.id===t,wc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Ec(n||pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(o.length&&(i=i.concat(o),o=[]),i.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,o.push(s)):o=[]}return i},bE=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),[])},hc=(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))}}},PE=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{Gs(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},BS=(e,t,n,i,o)=>{let r=Tt(e,n,i);if(!r)return n;let s=W(r,i),a=J(r)?Se(r,i):null,l=[r.id,s?.id,a?.id].filter(u=>!!u),d=n.findIndex(u=>l.includes(u.id)),c=n.findIndex(u=>u.id===t.id);if(c!==-1&&d!==-1&&c<d){let u=Array.from(n),m=u.splice(c,1)[0];u.splice(d,0,m),o.replaceAllElements(u)}return n},IE=(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"?xc(t,m=>a(m),Math.max(0,n-1)):gc(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return hc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||q(d))){let m=PE(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return hc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=ve(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},yc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),bc=(e,t,n,i)=>{let o=wc(e,t),r=yc(e,o),s=bE(o);n==="right"&&(s=s.reverse());let a=new Set(o.filter(l=>q(e[l])).map(l=>e[l].id));return s.forEach((l,d)=>{let c=l[0],u=l[l.length-1],m=n==="left"?c:u,p=l.some(y=>{let b=e[y];return b.frameId&&a.has(b.frameId)})?null:e[m]?.frameId,f=IE(t,e,m,n,p,i);if(f===-1||m===f)return;let h=n==="left"?e.slice(0,f):e.slice(0,c),E=e.slice(c,u+1),g=n==="left"?e.slice(f,c):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...h,...E,...g,...x]:[...h,...g,...E,...x]}),bi(e,r),e},Pc=(e,t,n,i,o)=>{let r=wc(e,t,o),s=yc(e,r),a=[],l,d;if(n==="left"){if(i)l=gc(e,f=>Gs(f,i));else if(t.editingGroupId){let f=ve(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;d=r[r.length-1]}else{if(i)d=xc(e,f=>Gs(f,i));else if(t.editingGroupId){let f=ve(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let c=Array.from(s.values()),u=e.slice(0,l),m=e.slice(d+1),p=n==="left"?[...u,...c,...a,...m]:[...u,...a,...c,...m];return bi(p,s),p};function Ic(e,t,n,i){let o=Ec(pt(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(e,t,n,d,c);return i(a,t,n,null,r.regularElements)}var CS=(e,t,n)=>bc(e,t,"left",n),GS=(e,t,n)=>bc(e,t,"right",n),OS=(e,t)=>Ic(e,t,"left",Pc),RS=(e,t)=>Ic(e,t,"right",Pc);var zS=e=>e.reduce((t,n)=>t+n.version,0),yd=e=>{let t=5381;for(let n of SE(e))t=(t<<5)+t+n.versionNonce;return t>>>0},bd=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},_S=e=>e.filter(t=>!t.isDeleted&&!md(t)),US=e=>e.filter(t=>!t.isDeleted),YS=e=>!e.isDeleted;export{ln as AppStateDelta,tl as BASE_BINDING_GAP,Pn as BASE_BINDING_GAP_ELBOW,te as BASE_PADDING,tn as BindableElement,en as BoundElement,ke as CaptureUpdateAction,s0 as DEFAULT_LINK_SIZE,uc as DEFAULT_OMIT_SIDES,_ as Delta,ls as DurableIncrement,ns as ElementBounds,dn as ElementsDelta,ds as EphemeralIncrement,nc as FlowChartCreator,tc as FlowChartNavigator,we as HEADING_DOWN,Ge as HEADING_LEFT,me as HEADING_RIGHT,_e as HEADING_UP,Jp as IMAGE_INVERT_FILTER,vf as INVISIBLY_SMALL_ELEMENT_SIZE,us as InvalidFractionalIndexError,k as LinearElementEditor,Pe as MINIMAL_CROP_SIZE,sS as OMIT_SIDES_FOR_FRAME,rS as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Ro as Scene,Me as ShapeCache,Ed as Store,wi as StoreChange,cs as StoreDelta,Bo as StoreIncrement,cn as StoreSnapshot,Ze as aabbForElement,zp as addElementsToFrame,oE as addNewNodes,nb as addToGroup,u1 as alignElements,ol as avoidRectangularCorner,Eo as bindBindingElement,kl as bindElementsToFramesAfterDuplication,nl as bindOrUnbindBindingElement,Iy as bindOrUnbindBindingElements,mo as bindPointToSnapToElementOutline,sl as bindingProperties,Ka as bumpVersion,sp as calculateFixedPointForElbowArrowBinding,go as calculateFixedPointForNonElbowArrowBinding,Dx as canApplyRoundnessTypeToElement,ga as canBecomePolygon,Kl as canChangeRoundness,Lh as canCreateLinkFromElements,g0 as canHaveArrowheads,Yo as canResizeFromSides,Bn as charWidth,ue as compareHeading,oi as computeBoundTextPosition,wr as computeContainerDimensionForBoundText,iw as containsCJK,lI as createPlaceholderEmbeddableLabel,xs as createSrcDoc,yx as cropElement,Dn as deconstructDiamondElement,Wi as deconstructLinearOrFreeDrawElement,vn as deconstructRectanguloidElement,as as deepCopyElement,OP as defaultGetElementLinkFromSelection,qx as detectLineHeight,yn as distanceToElement,gP as distributeElements,bn as doBoundsIntersect,DP as dragNewElement,TP as dragSelectedElements,Nf as duplicateElement,M1 as duplicateElements,tb as editGroupForSelectedElement,fe as elementCenterPoint,on as elementOverlapsWithFrame,vo as elementWithCanvasCache,sn as elementsAreInFrameBounds,Bl as elementsAreInSameGroup,cI as embeddableURLValidator,Ol as excludeElementsInFramesFromSelection,Nb as filterElementsEligibleAsFrameChildren,My as fixBindingsAfterDeletion,rl as fixDuplicatedBindingsAfterDuplication,Ar as flipHeading,Xb as frameAndChildrenSelectedTogether,ql as generateFreeDrawShape,Sa as generateLinearCollisionShape,Re as generateRoughOptions,to as getAllHoveredElementAtPoint,Da as getApproxMinLineHeight,va as getApproxMinLineWidth,al as getArrowLocalFixedPoints,Pf as getArrowheadAngle,Jr as getArrowheadPoints,bf as getArrowheadSize,Dt as getBindingGap,Hr as getBindingStrategyForDraggingBindingElementEndpoints,W as getBoundTextElement,At as getBoundTextElementId,hw as getBoundTextElementPosition,ri as getBoundTextMaxHeight,nt as getBoundTextMaxWidth,is as getBoundsFromPoints,ut as getCenterForBounds,Z0 as getClosestElementBounds,Rt as getCommonBoundingBox,Ye as getCommonBounds,pw as getContainerCenter,yr as getContainerCoords,Se as getContainerElement,Gt as getContainingFrame,It as getCornerRadius,no as getCubicBezierCurveBound,gS as getCursorForResizingElement,jp as getDefaultFrameName,Lx as getDefaultRoundnessTypeForElement,Ln as getDiamondPoints,vP as getDragOffsetXY,$0 as getDraggedElementsBounds,X as getElementAbsoluteCoords,se as getElementBounds,$r as getElementLineSegments,Ur as getElementPointsCoords,id as getElementShape,hS as getElementWithTransformHandleType,Fl as getElementsCompletelyInFrame,ve as getElementsInGroup,Fb as getElementsInNewFrame,kb as getElementsInResizingFrame,Lb as getElementsIntersectingFrame,Yb as getElementsOverlappingFrame,Wr as getElementsWithinSelection,aI as getEmbedLink,bx as getFlipAdjustedCropPosition,rn as getFrameChildren,Np as getFrameLikeElements,Ub as getFrameLikeTitle,of as getFreeDrawPath2D,rf as getFreeDrawSvgPath,d0 as getFreedrawOutlineAsSegments,sf as getFreedrawOutlinePoints,Jt as getGlobalFixedPointForBindableElement,ap as getGlobalFixedPoints,qa as getHeadingForElbowArrowSnap,Tt as getHoveredElementForBinding,BI as getInitializedImageElements,qi as getLineHeightInPx,Vt as getLineWidth,Cx as getLinearElementSubType,SI as getLinkDirectionFromKey,RP as getLinkIdAndTypeFromSelection,xl as getLockedLinearCursorAlignSize,Nu as getMaxCharWidth,ob as getMaximumGroups,Qx as getMinCharWidth,Ei as getMinMaxXYFromCurvePathOps,Zi as getMinTextElementWidth,Gl as getNewGroupIdsForDuplication,US as getNonDeletedElements,Ll as getNonDeletedGroupIds,r1 as getNormalizedDimensions,zn as getObservedAppState,vs as getOmitSidesForEditorInterface,jx as getOriginalContainerHeightFromCache,os as getPerfectElementSize,Ps as getPredecessors,V0 as getRectangleBoxAbsoluteCoords,ef as getRenderOpacity,QI as getResizeArrowDirection,KI as getResizeOffsetXY,Yt as getResizedElementAbsoluteCoords,Rb as getRootElements,zS as getSceneVersion,pt as getSelectedElements,Po as getSelectedElementsByGroup,jr as getSelectedGroupForElement,Gp as getSelectedGroupIdForElement,Bp as getSelectedGroupIds,gb as getSelectionStateForElements,Eb as getTargetElements,Up as getTargetFrame,fw as getTextElementAngle,ww as getTextFromElements,Fu as getTextHeight,La as getTextWidth,ES as getTransformHandleTypeFromCoords,mc as getTransformHandles,Ds as getTransformHandlesFromCoords,ua as getUncroppedImageElement,or as getUncroppedWidthAndHeight,fb as getVisibleAndNonSelectedElements,_S as getVisibleElements,q0 as getVisibleSceneBounds,Ob as groupByFrameLikes,Cb as groupsAreAtLeastIntersectingTheFrame,Gb as groupsAreCompletelyOutOfFrame,wn as handleBindTextResize,m0 as hasBackground,dt as hasBoundTextElement,aS as hasBoundingBox,p0 as hasStrokeColor,h0 as hasStrokeStyle,f0 as hasStrokeWidth,yd as hashElementsVersion,bd as hashString,Ce as headingForPoint,ai as headingForPointFromElement,it as headingForPointIsHorizontal,Oe as headingIsHorizontal,Xw as headingIsVertical,ym as hitElementBoundText,wm as hitElementBoundingBox,Nw as hitElementBoundingBoxOnly,xm as hitElementItself,$t as intersectElementWithLineSegment,vx as isArrowBoundToElement,H as isArrowElement,He as isBindableElement,Sr as isBindableElementInsideOtherBindable,Le as isBindingElement,Pu as isBindingElementType,fi as isBindingEnabled,le as isBoundToContainer,Bx as isBounds,Bb as isCursorInFrame,yu as isCurvedArrow,U as isElbowArrow,o1 as isElementCompletelyInViewport,Zr as isElementContainingFrame,Hl as isElementInFrame,Cp as isElementInGroup,Rl as isElementInViewport,Nn as isElementIntersectingFrame,kP as isElementLink,pa as isEmbeddableElement,Tx as isExcalidrawElement,ar as isFlowchartNodeElement,ji as isFrameElement,q as isFrameLikeElement,Ie as isFreeDrawElement,xu as isFreeDrawElementType,aE as isHTMLSVGElement,Yi as isIframeElement,Xi as isIframeLikeElement,xe as isImageElement,Cl as isInGroup,Xt as isInitializedImageElement,md as isInvisiblySmallElement,bt as isLineElement,K as isLinearElement,bu as isLinearElementType,fa as isMagicFrameElement,Zx as isMeasureTextSupported,MI as isNodeInFlowchart,YS as isNonDeletedElement,gn as isPathALoop,Wt as isPointInElement,sr as isRectangularElement,rr as isRectanguloidElement,Lp as isSelectedViaGroup,wu as isSharpArrow,Ax as isSimpleArrow,hb as isSomeElementSelected,Iu as isTextBindableContainer,J as isTextElement,ha as isUsingAdaptiveRadius,Ea as isUsingProportionalRadius,Gx as isValidPolygon,xw as isValidTextContainer,sE as loadHTMLImageElement,Xr as makeNextSelectedElementIds,ci as maxBindingDistance_simple,dI as maybeParseEmbedSrc,Ms as measureFontSizeFromWidth,tt as measureText,OS as moveAllLeft,RS as moveAllRight,BS as moveArrowAboveBindable,CS as moveOneLeft,GS as moveOneRight,ye as mutateElement,$d as newArrowElement,Es as newElement,ge as newElementWith,VP as newEmbeddableElement,ZP as newFrameElement,QP as newFreeDrawElement,$P as newIframeElement,eI as newImageElement,JP as newLinearElement,qP as newMagicFrameElement,Vd as newTextElement,pd as normalizeElementOrder,xo as normalizeFixedPoint,CI as normalizeSVG,fr as normalizeText,Io as omitGroupsContainingFrameLikes,Hp as omitPartialGroups,vd as orderByFractionalIndex,ii as originalContainerCache,FP as parseElementLinkFromURL,ju as parseTokens,Zl as pathsCache,Zt as pointInsideBounds,FI as positionElementsOnGrid,Ia as projectFixedPointOntoDiagonal,Oa as redrawTextBoundingBox,KP as refreshTextDimensions,_p as removeAllElementsFromFrame,Nl as removeElementsFromFrame,ib as removeFromSelectedGroups,l0 as renderElement,a0 as renderSelectionElement,Hb as replaceAllElementsInFrame,ac as rescalePointsInElement,Aa as resetOriginalContainerCache,EE as resizeMultipleElements,pE as resizeSingleElement,cE as resizeSingleTextElement,wE as resizeTest,Dp as selectGroup,vl as selectGroupsForSelectedElements,Dl as selectGroupsFromGivenElements,Kx as setCustomTextMetricsProvider,Ew as shouldAllowVerticalAlign,_b as shouldApplyFrameClip,Py as shouldEnableBindingForPointerEvent,eo as shouldTestInside,bS as showSelectedShapeActions,gw as suppportsHorizontalAlign,$f as syncInvalidIndices,wd as syncInvalidIndicesImmutable,bi as syncMovedIndices,gl as toggleLinePolygonState,E0 as toolIsArrow,qI as transformElements,qe as unbindBindingElement,Sy as updateBindings,Ue as updateBoundElements,Fn as updateBoundPoint,Gn as updateElbowArrowPoints,zb as updateFrameMembershipOfSelectedElements,LI as updateImageCache,Ma as updateOriginalContainerCache,Za as validateElbowPoints,Vf as validateFractionalIndices,vt as vectorToHeading,Mt as wrapText};