@excalidraw/element 0.18.0-7ea3229 → 0.18.0-816c81c

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 (90) hide show
  1. package/dist/dev/index.js +359 -152
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +11 -11
  4. package/dist/types/common/src/appEventBus.d.ts +27 -0
  5. package/dist/types/common/src/colors.d.ts +1 -1
  6. package/dist/types/common/src/index.d.ts +2 -0
  7. package/dist/types/common/src/utils.d.ts +1 -3
  8. package/dist/types/common/src/versionedSnapshotStore.d.ts +17 -0
  9. package/dist/types/element/src/Scene.d.ts +2 -0
  10. package/dist/types/element/src/arrowheads.d.ts +3 -0
  11. package/dist/types/element/src/binding.d.ts +3 -4
  12. package/dist/types/element/src/bounds.d.ts +1 -1
  13. package/dist/types/element/src/elbowArrow.d.ts +2 -0
  14. package/dist/types/element/src/index.d.ts +1 -0
  15. package/dist/types/element/src/linearElementEditor.d.ts +3 -0
  16. package/dist/types/element/src/mutateElement.d.ts +2 -0
  17. package/dist/types/element/src/types.d.ts +5 -2
  18. package/dist/types/element/src/utils.d.ts +1 -1
  19. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +23 -29
  20. package/dist/types/excalidraw/actions/actionBoundText.d.ts +16 -20
  21. package/dist/types/excalidraw/actions/actionCanvas.d.ts +97 -121
  22. package/dist/types/excalidraw/actions/actionClipboard.d.ts +16 -20
  23. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +8 -10
  24. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +24 -30
  25. package/dist/types/excalidraw/actions/actionElementLink.d.ts +4 -10
  26. package/dist/types/excalidraw/actions/actionElementLock.d.ts +16 -20
  27. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +8 -10
  28. package/dist/types/excalidraw/actions/actionExport.d.ts +60 -344
  29. package/dist/types/excalidraw/actions/actionFrame.d.ts +32 -40
  30. package/dist/types/excalidraw/actions/actionGroup.d.ts +16 -20
  31. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +8 -10
  32. package/dist/types/excalidraw/actions/actionLink.d.ts +8 -10
  33. package/dist/types/excalidraw/actions/actionMenu.d.ts +4 -10
  34. package/dist/types/excalidraw/actions/actionProperties.d.ts +16 -20
  35. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +8 -10
  36. package/dist/types/excalidraw/actions/actionStyles.d.ts +7 -9
  37. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +172 -0
  38. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +8 -10
  39. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +172 -0
  40. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +8 -10
  41. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +4 -10
  42. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +8 -10
  43. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +8 -10
  44. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +8 -10
  45. package/dist/types/excalidraw/actions/index.d.ts +2 -0
  46. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  47. package/dist/types/excalidraw/appState.d.ts +4 -2
  48. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
  49. package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
  50. package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
  51. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
  52. package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
  53. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
  54. package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
  55. package/dist/types/excalidraw/charts/index.d.ts +7 -0
  56. package/dist/types/excalidraw/clipboard.d.ts +2 -5
  57. package/dist/types/excalidraw/components/App.d.ts +33 -11
  58. package/dist/types/excalidraw/components/AppStateObserver.d.ts +37 -0
  59. package/dist/types/excalidraw/components/IconPicker.d.ts +14 -9
  60. package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
  61. package/dist/types/excalidraw/components/TTDDialog/CodeMirrorEditor.d.ts +11 -0
  62. package/dist/types/excalidraw/components/TTDDialog/TTDDialogInput.d.ts +3 -3
  63. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +4 -1
  64. package/dist/types/excalidraw/components/TTDDialog/mermaid-lang-lite.d.ts +2 -0
  65. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidAutoFix.d.ts +1 -0
  66. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +10 -0
  67. package/dist/types/excalidraw/components/Toast.d.ts +8 -4
  68. package/dist/types/excalidraw/components/icons.d.ts +17 -8
  69. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -0
  70. package/dist/types/excalidraw/data/blob.d.ts +25 -30
  71. package/dist/types/excalidraw/data/filesystem.d.ts +3 -5
  72. package/dist/types/excalidraw/data/index.d.ts +2 -3
  73. package/dist/types/excalidraw/data/json.d.ts +28 -22
  74. package/dist/types/excalidraw/data/resave.d.ts +7 -2
  75. package/dist/types/excalidraw/types.d.ts +84 -13
  76. package/package.json +3 -3
  77. package/dist/types/excalidraw/charts.d.ts +0 -27
  78. package/dist/types/excalidraw/components/DiagramToCodePlugin/DiagramToCodePlugin.d.ts +0 -4
  79. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -15
  80. package/dist/types/excalidraw/components/InitializeApp.d.ts +0 -10
  81. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +0 -8
  82. package/dist/types/excalidraw/components/TTDDialog/utils/TTDStreamFetch.d.ts +0 -24
  83. package/dist/types/excalidraw/components/footer/FooterCenter.d.ts +0 -8
  84. package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -11
  85. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -58
  86. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Hints.d.ts +0 -19
  87. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +0 -84
  88. package/dist/types/excalidraw/data/reconcile.d.ts +0 -7
  89. package/dist/types/excalidraw/index.d.ts +0 -47
  90. package/dist/types/excalidraw/polyfill.d.ts +0 -2
@@ -1,27 +1,27 @@
1
- var iu=Object.create;var ta=Object.defineProperty;var ou=Object.getOwnPropertyDescriptor;var ru=Object.getOwnPropertyNames;var su=Object.getPrototypeOf,au=Object.prototype.hasOwnProperty;var lu=(e,t)=>()=>(e&&(t=e(e=0)),t);var du=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var cu=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ru(t))!au.call(e,o)&&o!==n&&ta(e,o,{get:()=>t[o],enumerable:!(i=ou(t,o))||i.enumerable});return e};var uu=(e,t,n)=>(n=e!=null?iu(su(e)):{},cu(t||!e||!e.__esModule?ta(n,"default",{value:e,enumerable:!0}):n,e));var v,P=lu(()=>{v={PROD:!0}});var rc=du((UP,oc)=>{P();var ic="Expected a function",tc=NaN,Gh="[object Symbol]",Oh=/^\s+|\s+$/g,kh=/^[-+]0x[0-9a-f]+$/i,Fh=/^0b[01]+$/i,Rh=/^0o[0-7]+$/i,Nh=parseInt,zh=typeof global=="object"&&global&&global.Object===Object&&global,Hh=typeof self=="object"&&self&&self.Object===Object&&self,_h=zh||Hh||Function("return this")(),Uh=Object.prototype,Wh=Uh.toString,Yh=Math.max,jh=Math.min,Gs=function(){return _h.Date.now()};function Xh(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(ic);t=nc(t)||0,$o(n)&&(c=!!n.leading,u="maxWait"in n,r=u?Yh(nc(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(I){var S=i,T=o;return i=o=void 0,d=I,s=e.apply(T,S),s}function f(I){return d=I,a=setTimeout(g,t),c?p(I):s}function h(I){var S=I-l,T=I-d,M=t-S;return u?jh(M,r-T):M}function E(I){var S=I-l,T=I-d;return l===void 0||S>=t||S<0||u&&T>=r}function g(){var I=Gs();if(E(I))return x(I);a=setTimeout(g,h(I))}function x(I){return a=void 0,m&&i?p(I):(i=o=void 0,s)}function w(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function y(){return a===void 0?s:x(Gs())}function b(){var I=Gs(),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 b.cancel=w,b.flush=y,b}function $h(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(ic);return $o(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),Xh(e,t,{leading:i,maxWait:t,trailing:o})}function $o(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Vh(e){return!!e&&typeof e=="object"}function Zh(e){return typeof e=="symbol"||Vh(e)&&Wh.call(e)==Gh}function nc(e){if(typeof e=="number")return e;if(Zh(e))return tc;if($o(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=$o(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Oh,"");var n=Fh.test(e);return n||Rh.test(e)?Nh(e.slice(2),n?2:8):kh.test(e)?tc:+e}oc.exports=$h});P();import{toIterable as bg}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as jt,viewportCoordsToSceneCoords as Wo}from"@excalidraw/common";import{normalizeRadians as Fd,radiansBetweenAngles as dh,radiansDifference as ch}from"@excalidraw/math";import{pointsEqual as uh}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function dr(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 pu(e,t,n){let i=[];e.forEach(o=>i.push(...o)),dr(i,t,n)}function fu(e,t){return e[0]===t[0]&&e[1]===t[1]}function na(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)dr(d,a,o);let l=hu(s,r,i);if(o){for(let d of s)dr(d,a,-o);pu(l,a,-o)}return l}function hu(e,t,n){let i=[];for(let d of e){let c=[...d];fu(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 ft(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),na(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=ft(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 qt(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 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=ft(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)qt([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 _i=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 Ui=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=ft(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=qt(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 Wi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=ft(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=qt(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 Yi=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=ft(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=qt(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 ke={};function ia(e,t){let n=e.fillStyle||"hachure";if(!ke[n])switch(n){case"zigzag":ke[n]||(ke[n]=new Hi(t));break;case"cross-hatch":ke[n]||(ke[n]=new _i(t));break;case"dots":ke[n]||(ke[n]=new Ui(t));break;case"dashed":ke[n]||(ke[n]=new Wi(t));break;case"zigzag-line":ke[n]||(ke[n]=new Yi(t));break;case"hachure":default:n="hachure",ke[n]||(ke[n]=new Zt(t));break}return ke[n]}P();function oa(){return Math.floor(Math.random()*2**31)}var ji=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 Xi={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function Eu(e){let t=new Array;for(;e!=="";)if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([aAcChHlLmMqQsStTvVzZ])/))t[t.length]={type:0,text:RegExp.$1},e=e.substr(RegExp.$1.length);else if(e.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))t[t.length]={type:1,text:`${parseFloat(RegExp.$1)}`},e=e.substr(RegExp.$1.length);else return[];return t[t.length]={type:2,text:""},t}function cr(e,t){return e.type===t}function Nn(e){let t=[],n=Eu(e),i="BOD",o=0,r=n[o];for(;!cr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=Xi[r.text],i=r.text;else return Nn("M0,0"+e);else cr(r,1)?s=Xi[i]:(o++,s=Xi[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(cr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof Xi[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 ni(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 oi(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)&&(ra(i,o,E,g,u,m,p,f,h).forEach(function(w){t.push({key:"C",data:w})}),i=E,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function gu(e){return Math.PI*e/180}function ii(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 ra(e,t,n,i,o,r,s,a,l,d){let c=gu(s),u=[],m=0,p=0,f=0,h=0;if(d)[m,p,f,h]=d;else{[e,t]=ii(e,t,-c),[n,i]=ii(n,i,-c);let F=(e-n)/2,B=(t-i)/2,Y=F*F/(o*o)+B*B/(r*r);Y>1&&(Y=Math.sqrt(Y),o=Y*o,r=Y*r);let O=a===l?-1:1,X=o*o,k=r*r,A=X*k-X*B*B-k*F*F,V=X*B*B+k*F*F,Z=O*Math.sqrt(Math.abs(A/V));f=Z*o*B/r+(e+n)/2,h=Z*-r*F/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 F=p,B=n,Y=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=ra(n,i,B,Y,o,r,s,0,l,[p,F,f,h])}E=p-m;let g=Math.cos(m),x=Math.sin(m),w=Math.cos(p),y=Math.sin(p),b=Math.tan(E/4),I=4/3*o*b,S=4/3*r*b,T=[e,t],M=[e+I*x,t-S*g],R=[n+I*y,i-S*w],C=[n,i];if(M[0]=2*T[0]-M[0],M[1]=2*T[1]-M[1],d)return[M,R,C].concat(u);{u=[M,R,C].concat(u);let F=[];for(let B=0;B<u.length;B+=3){let Y=ii(u[B][0],u[B][1],c),O=ii(u[B+1][0],u[B+1][1],c),X=ii(u[B+2][0],u[B+2][1],c);F.push([Y[0],Y[1],O[0],O[1],X[0],X[1]])}return F}}var xu={randOffset:yu,randOffsetWithRange:Pu,ellipse:bu,doubleLineOps:Iu};function ur(e,t,n,i,o){return{type:"path",ops:Mt(e,t,n,i,o)}}function ri(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Mt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Mt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return ur(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function wu(e,t){return ri(e,!0,t)}function ca(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return wu(r,o)}function mr(e,t){let n=aa(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=aa(e,1.5*(1+t.roughness*.22),Su(t));n=n.concat(i)}return{type:"path",ops:n}}function bu(e,t,n,i,o){let r=pr(n,i,o);return Zi(e,t,o,r).opset}function pr(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=N(s*l,n),a+=N(a*l,n),{increment:r,rx:s,ry:a}}function Zi(e,t,n,i){let[o,r]=la(i.increment,e,t,i.rx,i.ry,1,i.increment*$i(.1,$i(.4,1,n),n),n),s=Vi(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=la(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Vi(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function fr(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),m=Math.abs(i/2);u+=N(u*.01,l),m+=N(m*.01,l);let p=o,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=da(E,d,c,u,m,p,f,1,l);if(!l.disableMultiStroke){let x=da(E,d,c,u,m,p,f,1.5,l);g.push(...x)}return s&&(a?g.push(...Mt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...Mt(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 hr(e,t){let n=oi(ni(Nn(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(...Mt(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,d,c,u,m,p]=a;i.push(...Au(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...Mt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function qi(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+N(o,t),i[0][1]+N(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+N(o,t),i[s][1]+N(o,t)]})}}return{type:"fillPath",ops:n}}function Sn(e,t){return ia(t,xu).fillPolygons(e,t)}function ua(e,t,n,i,o,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(i/2);d+=N(d*.01,s),c+=N(c*.01,s);let u=o,m=r;for(;u<0;)u+=Math.PI*2,m+=Math.PI*2;m-u>Math.PI*2&&(u=0,m=Math.PI*2);let p=(m-u)/s.curveStepCount,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]),Sn([f],s)}function yu(e,t){return N(e,t)}function Pu(e,t,n){return $i(e,t,n)}function Iu(e,t,n,i,o){return Mt(e,t,n,i,o,!0)}function Su(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function ma(e){return e.randomizer||(e.randomizer=new ji(e.seed||0)),e.randomizer.next()}function $i(e,t,n,i=1){return n.roughness*i*(ma(n)*(t-e)+e)}function N(e,t,n=1){return $i(-e,e,t,n)}function Mt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=sa(e,t,n,i,o,!0,!1);if(s)return a;let l=sa(e,t,n,i,o,!0,!0);return a.concat(l)}function sa(e,t,n,i,o,r,s){let a=Math.pow(e-n,2)+Math.pow(t-i,2),l=Math.sqrt(a),d=1;l<200?d=1:l>500?d=.4:d=-.0016668*l+1.233334;let c=o.maxRandomnessOffset||0;c*c*100>a&&(c=l/10);let u=c/2,m=.2+ma(o)*.2,p=o.bowing*o.maxRandomnessOffset*(i-t)/200,f=o.bowing*o.maxRandomnessOffset*(e-n)/200;p=N(p,o,d),f=N(f,o,d);let h=[],E=()=>N(u,o,d),g=()=>N(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:N(c,o,d)),t+(x?0:N(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 aa(e,t,n){let i=[];i.push([e[0][0]+N(t,n),e[0][1]+N(t,n)]),i.push([e[0][0]+N(t,n),e[0][1]+N(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+N(t,n),e[o][1]+N(t,n)]),o===e.length-1&&i.push([e[o][0]+N(t,n),e[o][1]+N(t,n)]);return Vi(i,null,n)}function Vi(e,t,n){let i=e.length,o=[];if(i>3){let r=[],s=1-n.curveTightness;o.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<i;a++){let l=e[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*e[a+1][0]-s*e[a-1][0])/6,l[1]+(s*e[a+1][1]-s*e[a-1][1])/6],r[2]=[e[a+1][0]+(s*e[a][0]-s*e[a+2][0])/6,e[a+1][1]+(s*e[a][1]-s*e[a+2][1])/6],r[3]=[e[a+1][0],e[a+1][1]],o.push({op:"bcurveTo",data:[r[1][0],r[1][1],r[2][0],r[2][1],r[3][0],r[3][1]]})}if(t&&t.length===2){let a=n.maxRandomnessOffset;o.push({op:"lineTo",data:[t[0]+N(a,n),t[1]+N(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...Mt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function la(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let m=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(m),c.push(m)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=N(.5,a)-Math.PI/2;c.push([N(r,a)+t+.9*i*Math.cos(u-e),N(r,a)+n+.9*o*Math.sin(u-e)]);let m=Math.PI*2+u-.01;for(let p=u;p<m;p=p+e){let f=[N(r,a)+t+i*Math.cos(p),N(r,a)+n+o*Math.sin(p)];d.push(f),c.push(f)}c.push([N(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),N(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),c.push([N(r,a)+t+.98*i*Math.cos(u+s),N(r,a)+n+.98*o*Math.sin(u+s)]),c.push([N(r,a)+t+.9*i*Math.cos(u+s*.5),N(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[c,d]}function da(e,t,n,i,o,r,s,a,l){let d=r+N(.1,l),c=[];c.push([N(a,l)+t+.9*i*Math.cos(d-e),N(a,l)+n+.9*o*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([N(a,l)+t+i*Math.cos(u),N(a,l)+n+o*Math.sin(u)]);return c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),c.push([t+i*Math.cos(s),n+o*Math.sin(s)]),Vi(c,null,l)}function Au(e,t,n,i,o,r,s,a){let l=[],d=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],c=[0,0],u=a.disableMultiStroke?1:2,m=a.preserveVertices;for(let p=0;p<u;p++)p===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(m?0:N(d[0],a)),s[1]+(m?0:N(d[0],a))]}),c=m?[o,r]:[o+N(d[p],a),r+N(d[p],a)],l.push({op:"bcurveTo",data:[e+N(d[p],a),t+N(d[p],a),n+N(d[p],a),i+N(d[p],a),c[0],c[1]]});return l}P();function si(e){return[...e]}function pa(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(si(e[0]),si(e[1]),si(e[2]),si(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(si(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 Mu(e,t){return Math.sqrt(Ki(e,t))}function Ki(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Tu(e,t,n){let i=Ki(t,n);if(i===0)return Ki(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)),Ki(e,An(t,n,o))}function An(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function vu(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(vu(e,t)<n){let r=e[t+0];o.length?Mu(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=An(s,a,.5),u=An(a,l,.5),m=An(l,d,.5),p=An(c,u,.5),f=An(u,m,.5),h=An(p,f,.5);Er([s,c,p,h],0,n,o),Er([h,f,m,d],0,n,o)}return o}function ai(e,t){return Qi(e,0,e.length,t)}function Qi(e,t,n,i,o){let r=o||[],s=e[t],a=e[n-1],l=0,d=1;for(let c=t+1;c<n-1;++c){let u=Tu(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(Qi(e,t,d+1,i,r),Qi(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function Tt(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?Qi(i,0,i.length,n):i}P();function fa(e,t,n){let i=Nn(e),o=oi(ni(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Tt(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=ai(m,n);p.length&&u.push(p)}return u}var Ye="none",Ke=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 oa()}_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",[ur(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=ca(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(qi([d],s)):a.push(Sn([d],s))}return s.stroke!==Ye&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=pr(i,o,s),d=Zi(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Zi(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(Sn([d.estimatedPoints],s));return s.stroke!==Ye&&a.push(d.opset),this._d("ellipse",a,s)}circle(t,n,i,o){let r=this.ellipse(t,n,i,i,o);return r.shape="circle",r}linearPath(t,n){let i=this._o(n);return this._d("linearPath",[ri(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=fr(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=fr(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(ua(t,n,i,o,r,s,d));return d.stroke!==Ye&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=mr(t,i);if(i.fill&&i.fill!==Ye&&t.length>=3)if(i.fillStyle==="solid"){let s=mr(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=pa(t),a=Tt(s,10,(1+i.roughness)/2);o.push(Sn([a],i))}return i.stroke!==Ye&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=ri(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(qi([t],i)):o.push(Sn([t],i))),i.stroke!==Ye&&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!==Ye,s=i.stroke!==Ye,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=fa(t,1,l),c=hr(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=hr(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(qi(d,i));else o.push(Sn(d,i));return s&&(a?d.forEach(u=>{o.push(ri(u,!1,i))}):o.push(c)),this._d("path",o,i)}opsToPath(t,n){let i="";for(let o of t.ops){let r=typeof n=="number"&&n>=0?o.data.map(s=>+s.toFixed(n)):o.data;switch(o.op){case"move":i+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":i+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":i+=`L${r[0]} ${r[1]} `;break}}return i.trim()}toPaths(t){let n=t.sets||[],i=t.options||this.defaultOptions,o=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:Ye};break;case"fillPath":s={d:this.opsToPath(r),stroke:Ye,strokeWidth:0,fill:i.fill||Ye};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||Ye,strokeWidth:i,fill:Ye}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var Ji=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new Ke(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 li="http://www.w3.org/2000/svg";var eo=class{constructor(t,n){this.svg=t,this.gen=new Ke(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(li,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(li,"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(li,"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(li,"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 Mn={canvas(e,t){return new Ji(e,t)},svg(e,t){return new eo(e,t)},generator(e){return new Ke(e)},newSeed(){return Ke.newSeed()}};import{arrayToMap as Od,invariant as ws,rescalePoints as Dd,sizeOf as eh}from"@excalidraw/common";import{degreesToRadians as xs,lineSegment as ge,pointDistance as th,pointFrom as D,pointFromArray as kd,pointRotateRads as oe}from"@excalidraw/math";P();import{invariant as Du}from"@excalidraw/common";import{curve as Bu,lineSegment as Lu,pointFrom as ae,pointDistance as ow,pointFromArray as Cu,pointFromVector as Gu,pointRotateRads as it,polygon as ha,polygonFromPoints as gr,PRECISION as rw,segmentsIntersectAt as sw,vector as Ou,vectorAdd as ku,vectorFromPoint as Fu,vectorScale as aw}from"@excalidraw/math";import{getElementAbsoluteCoords as dw}from"@excalidraw/element";var Ea=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=ae(s,a),d;return e.type==="diamond"?d=ha(it(ae(s,r),l,t),it(ae(o+n,a),l,t),it(ae(s,r+i),l,t),it(ae(o,a),l,t)):d=ha(it(ae(o,r),l,t),it(ae(o+n,r),l,t),it(ae(o+n,r+i),l,t),it(ae(o,r+i),l,t)),{type:"polygon",data:d}};var ga=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:ae(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},vt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},xa=(e,t=ae(0,0),n,i)=>{let o=l=>it(ae(l[0]+t[0],l[1]+t[1]),i,n),r=vt(e),s=[],a=ae(0,0);for(let l of r){if(l.op==="move"){let d=Cu(l.data);Du(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(ae(l.data[0],l.data[1])),c=o(ae(l.data[2],l.data[3])),u=o(ae(l.data[4],l.data[5]));s.push(Bu(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Ru=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Lu(t,o)),t=o}return n},wa=(e,t,n=!1)=>{let i=r=>it(Gu(ku(Fu(r),Ou(e.x,e.y))),t,e.angle),o=Ru(e.points.map(r=>i(r)));return n?{type:"polygon",data:gr(o.flat())}:{type:"polyline",data:o}},ba=(e,t,n=ae(0,0),i,o)=>{let r=c=>it(ae(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:gr(e.points.map(c=>r(c)))};let s=vt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(ae(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(ae(c.data[0],c.data[1])),a.push(ae(c.data[2],c.data[3])),a.push(ae(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(ae(c.data[0],c.data[1]));let d=Tt(a,10,5).map(c=>r(c));return{type:"polygon",data:gr(d)}};P();P();function ya(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function Nu(e){return[-e[0],-e[1]]}function rt(e,t){return[e[0]+t[0],e[1]+t[1]]}function Qe(e,t){return[e[0]-t[0],e[1]-t[1]]}function ot(e,t){return[e[0]*t,e[1]*t]}function zu(e,t){return[e[0]/t,e[1]/t]}function di(e){return[e[1],-e[0]]}function Pa(e,t){return e[0]*t[0]+e[1]*t[1]}function Hu(e,t){return e[0]===t[0]&&e[1]===t[1]}function _u(e){return Math.hypot(e[0],e[1])}function Uu(e){return e[0]*e[0]+e[1]*e[1]}function Ia(e,t){return Uu(Qe(e,t))}function Ma(e){return zu(e,_u(e))}function Wu(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function ci(e,t,n){let i=Math.sin(n),o=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*o-s*i,l=r*i+s*o;return[a+t[0],l+t[1]]}function xr(e,t,n){return rt(e,ot(Qe(t,e),n))}function Sa(e,t,n){return rt(e,ot(t,n))}var{min:zn,PI:Yu}=Math,Aa=.275,ui=Yu+1e-4;function ju(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=k=>k,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=k=>k*(2-k)}=a,{cap:m=!0,easing:p=k=>--k*k*k+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,h=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,E=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*i,2),x=[],w=[],y=e.slice(0,10).reduce((k,A)=>{let V=A.pressure;if(r){let Z=zn(1,A.distance/n),St=zn(1,1-Z);V=zn(1,k+(St-k)*(Z*Aa))}return(k+V)/2},e[0].pressure),b=ya(n,o,e[e.length-1].pressure,s),I,S=e[0].vector,T=e[0].point,M=T,R=T,C=M,F=!1;for(let k=0;k<e.length;k++){let{pressure:A}=e[k],{point:V,vector:Z,distance:St,runningLength:pt}=e[k];if(k<e.length-1&&f-pt<3)continue;if(o){if(r){let We=zn(1,St/n),qe=zn(1,1-We);A=zn(1,y+(qe-y)*(We*Aa))}b=ya(n,o,A,s)}else b=n/2;I===void 0&&(I=b);let Fi=pt<h?u(pt/h):1,ar=f-pt<E?p((f-pt)/E):1;b=Math.max(.01,b*Math.min(Fi,ar));let Ri=(k<e.length-1?e[k+1]:e[k]).vector,ti=k<e.length-1?Pa(Z,Ri):1,lr=Pa(Z,S)<0&&!F,Ni=ti!==null&&ti<0;if(lr||Ni){let We=ot(di(S),b);for(let qe=1/13,Vt=0;Vt<=1;Vt+=qe)R=ci(Qe(V,We),V,ui*Vt),x.push(R),C=ci(rt(V,We),V,ui*-Vt),w.push(C);T=R,M=C,Ni&&(F=!0);continue}if(F=!1,k===e.length-1){let We=ot(di(Z),b);x.push(Qe(V,We)),w.push(rt(V,We));continue}let zi=ot(di(xr(Ri,Z,ti)),b);R=Qe(V,zi),(k<=1||Ia(T,R)>g)&&(x.push(R),T=R),C=rt(V,zi),(k<=1||Ia(M,C)>g)&&(w.push(C),M=C),y=A,S=Z}let B=e[0].point.slice(0,2),Y=e.length>1?e[e.length-1].point.slice(0,2):rt(e[0].point,[1,1]),O=[],X=[];if(e.length===1){if(!(h||E)||d){let k=Sa(B,Ma(di(Qe(B,Y))),-(I||b)),A=[];for(let V=1/13,Z=V;Z<=1;Z+=V)A.push(ci(k,B,ui*2*Z));return A}}else{if(!(h||E&&e.length===1))if(c)for(let A=1/13,V=A;V<=1;V+=A){let Z=ci(w[0],B,ui*V);O.push(Z)}else{let A=Qe(x[0],w[0]),V=ot(A,.5),Z=ot(A,.51);O.push(Qe(B,V),Qe(B,Z),rt(B,Z),rt(B,V))}let k=di(Nu(e[e.length-1].vector));if(E||h&&e.length===1)X.push(Y);else if(m){let A=Sa(Y,k,b);for(let V=1/29,Z=V;Z<1;Z+=V)X.push(ci(A,Y,ui*3*Z))}else X.push(rt(Y,ot(k,b)),rt(Y,ot(k,b*.99)),Qe(Y,ot(k,b*.99)),Qe(Y,ot(k,b)))}return x.concat(X,w.reverse(),O)}function Xu(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(xr(a[0],p,f/4))}a.length===1&&(a=[...a,[...rt(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):xr(u.point,a[p],s);if(Hu(u.point,f))continue;let h=Wu(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:Ma(Qe(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 Ta(e,t={}){return ju(Xu(e,t),t)}import{pointFrom as le,pointDistance as Pd,pointRotateRads as Wt}from"@excalidraw/math";import{ROUGHNESS as Wf,THEME as Es,isTransparent as Li,assertNever as Yf,COLOR_PALETTE as jf,LINE_POLYGON_POINT_MERGE_DISTANCE as Xf,applyDarkModeFilter as Uo}from"@excalidraw/common";P();import{isRightAngleRads as Bf,lineSegment as Ed,pointFrom as Ro,pointRotateRads as ps}from"@excalidraw/math";import{BOUND_TEXT_PADDING as No,DEFAULT_REDUCED_GLOBAL_ALPHA as Lf,ELEMENT_READY_TO_ERASE_OPACITY as Cf,FRAME_STYLE as Di,DARK_THEME_FILTER as Gf,MIME_TYPES as hs,THEME as $n,distance as En,getFontString as Of,isRTL as kf,getVerticalOffset as Ff,invariant as Rf,applyDarkModeFilter as Ho,isSafari as Nf}from"@excalidraw/common";P();import{pointFrom as Dt,pointCenter as $u,pointRotateRads as Kt,vectorFromPoint as wr,vectorNormalize as va,vectorSubtract as Da,vectorAdd as to,vectorScale as no,pointFromVector as Ba,clamp as ye,isCloseTo as La}from"@excalidraw/math";var Pe=10,Ew=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=br(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,f=Kt(Dt(r,s),re(e,t),-e.angle);r=f[0],s=f[1];let h=e.width,E=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,w=g.width,y=e.scale[0]===-1,b=e.scale[1]===-1,I=s-e.y,S=r-e.x;n.includes("n")&&(E=ye(e.height-I,Pe,b?d-p:e.height+p)),n.includes("s")&&(I=s-e.y-e.height,E=ye(e.height+I,Pe,b?e.height+p:d-p)),n.includes("e")&&(S=r-e.x-e.width,h=ye(e.width+S,Pe,y?e.width+m:l-m)),n.includes("w")&&(h=ye(e.width-S,Pe,y?l-m:e.width+m));let T=C=>{C.height=E*u,C.width=h*c};T(g);let M=(C,F)=>{T(F),C.includes("n")&&(b||(F.y+=x-F.height)),C.includes("s")&&b&&(F.y+=x-F.height),C.includes("e")&&y&&(F.x+=w-F.width),C.includes("w")&&(y||(F.x+=w-F.width))};switch(n){case"n":{if(a){let C=m+e.width/2,F=l-m-e.width/2,B=Math.min(C,F)*2;h=ye(E*a,Pe,B),E=h/a}M(n,g),a&&(g.x+=(w-g.width)/2);break}case"s":{if(a){let C=m+e.width/2,F=l-m-e.width/2,B=Math.min(C,F)*2;h=ye(E*a,Pe,B),E=h/a}M(n,g),a&&(g.x+=(w-g.width)/2);break}case"w":{if(a){let C=p+e.height/2,F=d-p-e.height/2,B=Math.min(C,F)*2;E=ye(h/a,Pe,B),h=E*a}M(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let C=p+e.height/2,F=d-p-e.height/2,B=Math.min(C,F)*2;E=ye(h/a,Pe,B),h=E*a}M(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(S>-I){let C=b?d-p:p+e.height;E=ye(h/a,Pe,C),h=E*a}else{let C=y?m+e.width:l-m;h=ye(E*a,Pe,C),E=h/a}M(n,g);break}case"nw":{if(a)if(S<I){let C=b?d-p:p+e.height;E=ye(h/a,Pe,C),h=E*a}else{let C=y?l-m:m+e.width;h=ye(E*a,Pe,C),E=h/a}M(n,g);break}case"se":{if(a)if(S>I){let C=b?p+e.height:d-p;E=ye(h/a,Pe,C),h=E*a}else{let C=y?m+e.width:l-m;h=ye(E*a,Pe,C),E=h/a}M(n,g);break}case"sw":{if(a)if(-S>I){let C=b?p+e.height:d-p;E=ye(h/a,Pe,C),h=E*a}else{let C=y?l-m:m+e.width;h=ye(E*a,Pe,C),E=h/a}M(n,g);break}default:break}let R=Vu(e,n,h,E,!!a);return La(g.width,g.naturalWidth)&&La(g.height,g.naturalHeight)&&(g=null),{x:R[0],y:R[1],width:h,height:E,crop:g}},Vu=(e,t,n,i,o)=>{let[r,s,a,l]=Qt(e,e.width,e.height,!0),d=Dt(r,s),c=Dt(a,l),u=$u(d,c),[m,p,f,h]=Qt(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 T=[d[0],c[1]];x=[T[0],T[1]-Math.abs(g)]}if(t==="sw"){let T=[c[0],d[1]];x=[T[0]-Math.abs(E),T[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-E/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let w=e.angle,y=Kt(x,u,w),b=[x[0]+Math.abs(E)/2,x[1]+Math.abs(g)/2],I=Kt(b,u,w);x=Kt(y,I,-w);let S=[...x];return S[0]+=e.x-m,S[1]+=e.y-p,S},Ca=(e,t)=>{if(e.crop){let{width:n,height:i}=br(e),[o,r,s,a,l,d]=j(e,t),c=wr(Kt(Dt(o,r),Dt(l,d),e.angle)),u=wr(Kt(Dt(s,r),Dt(l,d),e.angle)),m=va(Da(u,c)),p=wr(Kt(Dt(o,a),Dt(l,d),e.angle)),f=Da(p,c),h=va(f),{cropX:E,cropY:g}=Zu(e.crop,e.scale),x=to(to(c,no(m,-E*n/e.crop.naturalWidth)),no(h,-g*i/e.crop.naturalHeight)),w=Ba(to(to(x,no(m,n/2)),no(h,i/2))),y=Kt(Ba(x),w,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},br=e=>{if(e.crop){let t=e.width/(e.crop.width/e.crop.naturalWidth),n=e.height/(e.crop.height/e.crop.naturalHeight);return{width:t,height:n}}return{width:e.width,height:e.height}},Zu=(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}},gw=(e,t=!1)=>{let n=e.crop;if(!n)return null;let i=e.scale[0]===-1,o=e.scale[1]===-1,r=n.x,s=n.y;if(i&&(r=n.naturalWidth-n.width-n.x),o&&(s=n.naturalHeight-n.height-n.y),t)return{x:r,y:s};let{width:a,height:l}=br(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as Nl,pointFrom as G,pointRotateRads as Le,pointsEqual as zl,pointDistance as On,vectorFromPoint as Xp,curveLength as $p,curvePointAtLength as Vp}from"@excalidraw/math";import{DRAGGING_THRESHOLD as Zp,KEYS as Gn,shouldRotateWithDiscreteAngle as Ti,getGridPoint as Hl,invariant as Ce,isShallowEqual as qp,getFeatureFlag as jn}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as _l,getSnapOutlineMidPoint as Ul,isPathALoop as Kp,moveArrowAboveBindable as Wl,projectFixedPointOntoDiagonal as Yl}from"@excalidraw/element";P();import{KEYS as Ap,arrayToMap as Ll,getFeatureFlag as Mp,invariant as tt,isTransparent as Tp}from"@excalidraw/common";import{PRECISION as vp,clamp as ts,lineSegment as Do,pointDistance as cn,pointDistanceSq as Ht,pointFrom as ne,pointFromVector as To,pointRotateRads as se,pointsEqual as Dp,vectorFromPoint as Si,vectorNormalize as es,vectorScale as vo}from"@excalidraw/math";P();import{invariant as al,isTransparent as ll}from"@excalidraw/common";import{curveIntersectLineSegment as dl,isPointWithinBounds as ho,lineSegment as wi,lineSegmentIntersectionPoints as cl,pointFrom as me,pointFromVector as jm,pointRotateRads as $e,pointsEqual as ul,vectorFromPoint as Xm,vectorNormalize as $m,vectorScale as Vm}from"@excalidraw/math";import{ellipse as Zm,ellipseSegmentInterceptPoints as qm}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as im,DEFAULT_PROPORTIONAL_RADIUS as Pr,invariant as om,LINE_CONFIRM_THRESHOLD as rm,ROUNDNESS as Ir}from"@excalidraw/common";import{bezierEquation as sm,curve as Lt,curveCatmullRomCubicApproxPoints as Ua,curveOffsetPoints as Wa,lineSegment as Ee,lineSegmentIntersectionPoints as Ha,pointDistance as vn,pointFrom as z,pointFromArray as am,pointFromVector as lm,pointRotateRads as je,pointTranslate as _a,rectangle as dm,vectorFromPoint as Ya,vectorNormalize as cm,vectorScale as Sr}from"@excalidraw/math";P();import{ROUNDNESS as mi,assertNever as qu}from"@excalidraw/common";import{pointsEqual as Ga}from"@excalidraw/math";var Tn=e=>!!e&&e.type==="image"&&!!e.fileId,xe=e=>!!e&&e.type==="image",Oa=e=>!!e&&e.type==="embeddable",io=e=>!!e&&e.type==="iframe",oo=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),J=e=>e!=null&&e.type==="text",ro=e=>e!=null&&e.type==="frame",ka=e=>e!=null&&e.type==="magicframe",q=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Ie=e=>e!=null&&Ku(e.type),Ku=e=>e==="freedraw",K=e=>e!=null&&em(e.type),Bt=e=>e!=null&&e.type==="line",H=e=>e!=null&&e.type==="arrow",_=e=>H(e)&&e.elbowed,Pw=e=>H(e)&&!e.elbowed,Qu=e=>H(e)&&!e.elbowed&&!e.roundness,Ju=e=>H(e)&&!e.elbowed&&e.roundness!==null,em=e=>e==="arrow"||e==="line",Se=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&tm(e.type),tm=e=>e==="arrow",de=(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),Fa=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),pi=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"),nm=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||H(e)),Iw=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 qu(t,null),!1}},yr=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",ht=e=>nm(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),ce=e=>e!==null&&"containerId"in e&&e.containerId!==null&&J(e),Sw=e=>!!e.startBinding||!!e.endBinding,Ra=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",Na=e=>e==="line"||e==="arrow"||e==="diamond",Aw=(e,t)=>!!((e===mi.ADAPTIVE_RADIUS||e===mi.LEGACY)&&Ra(t.type)||e===mi.PROPORTIONAL_RADIUS&&Na(t.type)),Mw=e=>Na(e.type)?{type:mi.PROPORTIONAL_RADIUS}:Ra(e.type)?{type:mi.ADAPTIVE_RADIUS}:null,Tw=e=>Qu(e)?"sharpArrow":Ju(e)?"curvedArrow":_(e)?"elbowArrow":"line",vw=e=>e.length>3&&Ga(e[0],e[e.length-1]),za=e=>e.length>3||e.length===3&&!Ga(e[0],e[e.length-1]);var fi=new WeakMap,Ar=(e,t)=>{let n=fi.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){fi.delete(e);return}return o.get(t)},Mr=(e,t,n)=>{let i=fi.get(e);if(!i){fi.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){fi.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function so(e){let t=Ar(e,0);if(t)return t;let n=Xa(e),i=[],o=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&am(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");i.push(Ee(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(Lt(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 Jt(e,t=0){let n=Ar(e,t);if(n)return n;let i=Ct(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=dm(z(e.x,e.y),z(e.x+e.width,e.y+e.height)),r=Ee(z(o[0][0]+i,o[0][1]),z(o[1][0]-i,o[0][1])),s=Ee(z(o[1][0],o[0][1]+i),z(o[1][0],o[1][1]-i)),a=Ee(z(o[0][0]+i,o[1][1]),z(o[1][0]-i,o[1][1])),l=Ee(z(o[0][0],o[1][1]-i),z(o[0][0],o[0][1]+i)),d=[Lt(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]),Lt(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]),Lt(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]),Lt(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=>Ua(Wa(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[Ee(c[0][c[0].length-1][3],c[1][0][0]),Ee(c[1][c[1].length-1][3],c[2][0][0]),Ee(c[2][c[2].length-1][3],c[3][0][0]),Ee(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Mr(e,m,t),m}function ja(e,t=0){let[n,i,o,r,s,a,l,d]=Hn(e),c=e.roundness?Ct(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?Ct(Math.abs(r-i),e):(r-i)*.01,[m,p,f,h]=[z(e.x+n,e.y+i),z(e.x+o,e.y+r),z(e.x+s,e.y+a),z(e.x+l,e.y+d)];return[Lt(z(p[0]-c,p[1]-u),p,p,z(p[0]-c,p[1]+u)),Lt(z(f[0]+c,f[1]-u),f,f,z(f[0]-c,f[1]-u)),Lt(z(h[0]+c,h[1]+u),h,h,z(h[0]+c,h[1]-u)),Lt(z(m[0]-c,m[1]+u),m,m,z(m[0]+c,m[1]+u))]}function en(e,t=0){let n=Ar(e,t);if(n)return n;let o=ja(e,t).map(a=>Ua(Wa(a,t))),s=[[Ee(o[0][o[0].length-1][3],o[1][0][0]),Ee(o[1][o[1].length-1][3],o[2][0][0]),Ee(o[2][o[2].length-1][3],o[3][0][0]),Ee(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return Mr(e,s,t),s}var Dn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return vn(n,i)<=rm/t}return!1},Ct=(e,t)=>{if(t.roundness?.type===Ir.PROPORTIONAL_RADIUS||t.roundness?.type===Ir.LEGACY)return e*Pr;if(t.roundness?.type===Ir.ADAPTIVE_RADIUS){let n=t.roundness?.value??im,i=n/Pr;return e<=i?e*Pr:n}return 0},um=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=cm(Ya(a[1],a[0])),d=Sr(l,n);return Ee(_a(a[0],d),_a(a[1],Sr(d,-1)))},o=re(e,t),r=i(pi(e)?Ee(je(z(e.x,e.y),o,e.angle),je(z(e.x+e.width,e.y+e.height),o,e.angle)):Ee(je(z(e.x+e.width/2,e.y),o,e.angle),je(z(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(pi(e)?Ee(je(z(e.x+e.width,e.y),o,e.angle),je(z(e.x,e.y+e.height),o,e.angle)):Ee(je(z(e.x,e.y+e.height/2),o,e.angle),je(z(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},mm=(e,t,n,i)=>{let o=re(t,n);return(t.type==="diamond"?ja(t).map(a=>{let l=sm(a,.5),d=je(l,o,t.angle);return z(d[0],d[1])}):[je(z(t.x+t.width,t.y+t.height/2),o,t.angle),je(z(t.x+t.width/2,t.y+t.height),o,t.angle),je(z(t.x,t.y+t.height/2),o,t.angle),je(z(t.x+t.width/2,t.y),o,t.angle)]).find(a=>vn(e,a)<=st(i)+t.strokeWidth/2&&!Et({point:e,element:t,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))},Tr=(e,t,n,i,o,r)=>{if(om(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;let s=mm(t,n,o,r);if(s)return s;let[a,l]=um(n,o),d=L.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o);if(e.points.length===2){let g=i==="start"?e.endBinding:e.startBinding,x=g&&o.get(g.elementId),w=g&&x&&Fe(tn(g.fixedPoint),x,o);w&&(d=w)}let c=lm(Sr(Ya(t,d),2*vn(d,t)+Math.max(vn(a[0],a[1]),vn(l[0],l[1]))),d),u=Ee(c,d),m=Ha(a,u),p=Ha(l,u),f=m&&vn(d,m),h=p&&vn(d,p),E=null;return f!=null&&h!=null?E=f<h?m:p:E=m||p||null,E&&Gt(E,n,o)?E:null};P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Cm,ARROW_LABEL_WIDTH_FRACTION as Gm,BOUND_TEXT_PADDING as gt,DEFAULT_FONT_SIZE as Om,TEXT_ALIGN as Ja,VERTICAL_ALIGN as el,getFontString as po,isProdEnv as km,invariant as Fm}from"@excalidraw/common";import{pointFrom as tl,pointRotateRads as Rm}from"@excalidraw/math";P();var hi={},$a=(e,t)=>{let n=hi[e]||(hi[e]={height:t});return n.height=t,n},Va=e=>{hi[e]&&delete hi[e]},Uw=e=>hi[e]?.height??null;P();import{BOUND_TEXT_PADDING as lo,DEFAULT_FONT_SIZE as pm,DEFAULT_FONT_FAMILY as fm,getFontString as hm,isTestEnv as Em,normalizeEOL as gm}from"@excalidraw/common";var Xe=(e,t,n)=>{let i=e.split(`
1
+ var au=Object.create;var ra=Object.defineProperty;var lu=Object.getOwnPropertyDescriptor;var du=Object.getOwnPropertyNames;var cu=Object.getPrototypeOf,uu=Object.prototype.hasOwnProperty;var mu=(e,t)=>()=>(e&&(t=e(e=0)),t);var pu=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var fu=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of du(t))!uu.call(e,o)&&o!==n&&ra(e,o,{get:()=>t[o],enumerable:!(i=lu(t,o))||i.enumerable});return e};var hu=(e,t,n)=>(n=e!=null?au(cu(e)):{},fu(t||!e||!e.__esModule?ra(n,"default",{value:e,enumerable:!0}):n,e));var v,P=mu(()=>{v={PROD:!0}});var dc=pu(($P,lc)=>{P();var ac="Expected a function",rc=NaN,Nh="[object Symbol]",zh=/^\s+|\s+$/g,Hh=/^[-+]0x[0-9a-f]+$/i,_h=/^0b[01]+$/i,Uh=/^0o[0-7]+$/i,Wh=parseInt,Yh=typeof global=="object"&&global&&global.Object===Object&&global,jh=typeof self=="object"&&self&&self.Object===Object&&self,Xh=Yh||jh||Function("return this")(),$h=Object.prototype,Vh=$h.toString,Zh=Math.max,qh=Math.min,Rs=function(){return Xh.Date.now()};function Kh(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(ac);t=sc(t)||0,Ko(n)&&(c=!!n.leading,u="maxWait"in n,r=u?Zh(sc(n.maxWait)||0,t):r,m="trailing"in n?!!n.trailing:m);function p(I){var A=i,T=o;return i=o=void 0,d=I,s=e.apply(T,A),s}function f(I){return d=I,a=setTimeout(g,t),c?p(I):s}function h(I){var A=I-l,T=I-d,M=t-A;return u?qh(M,r-T):M}function E(I){var A=I-l,T=I-d;return l===void 0||A>=t||A<0||u&&T>=r}function g(){var I=Rs();if(E(I))return x(I);a=setTimeout(g,h(I))}function x(I){return a=void 0,m&&i?p(I):(i=o=void 0,s)}function w(){a!==void 0&&clearTimeout(a),d=0,i=l=o=a=void 0}function y(){return a===void 0?s:x(Rs())}function b(){var I=Rs(),A=E(I);if(i=arguments,o=this,l=I,A){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 b.cancel=w,b.flush=y,b}function Qh(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(ac);return Ko(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),Kh(e,t,{leading:i,maxWait:t,trailing:o})}function Ko(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Jh(e){return!!e&&typeof e=="object"}function eE(e){return typeof e=="symbol"||Jh(e)&&Vh.call(e)==Nh}function sc(e){if(typeof e=="number")return e;if(eE(e))return rc;if(Ko(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Ko(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(zh,"");var n=_h.test(e);return n||Uh.test(e)?Wh(e.slice(2),n?2:8):Hh.test(e)?rc:+e}lc.exports=Qh});P();import{toIterable as Mg}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Xt,viewportCoordsToSceneCoords as $o}from"@excalidraw/common";import{normalizeRadians as Hd,radiansBetweenAngles as fh,radiansDifference as hh}from"@excalidraw/math";import{pointsEqual as Eh}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function pr(e,t,n){if(e&&e.length){let[i,o]=t,r=Math.PI/180*n,s=Math.cos(r),a=Math.sin(r);for(let l of e){let[d,c]=l;l[0]=(d-i)*s-(c-o)*a+i,l[1]=(d-i)*a+(c-o)*s+o}}}function gu(e,t,n){let i=[];e.forEach(o=>i.push(...o)),pr(i,t,n)}function xu(e,t){return e[0]===t[0]&&e[1]===t[1]}function sa(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)pr(d,a,o);let l=wu(s,r,i);if(o){for(let d of s)pr(d,a,-o);gu(l,a,-o)}return l}function wu(e,t,n){let i=[];for(let d of e){let c=[...d];xu(c[0],c[c.length-1])||c.push([c[0][0],c[0][1]]),c.length>2&&i.push(c)}let o=[];t=Math.max(t,.1);let r=[];for(let d of i)for(let c=0;c<d.length-1;c++){let u=d[c],m=d[c+1];if(u[1]!==m[1]){let p=Math.min(u[1],m[1]);r.push({ymin:p,ymax:Math.max(u[1],m[1]),x:p===u[1]?u[0]:m[0],islope:(m[0]-u[0])/(m[1]-u[1])})}}if(r.sort((d,c)=>d.ymin<c.ymin?-1:d.ymin>c.ymin?1:d.x<c.x?-1:d.x>c.x?1:d.ymax===c.ymax?0:(d.ymax-c.ymax)/Math.abs(d.ymax-c.ymax)),!r.length)return o;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let d=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)d=u;r.splice(0,d+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(d=>!(d.edge.ymax<=a)),s.sort((d,c)=>d.edge.x===c.edge.x?0:(d.edge.x-c.edge.x)/Math.abs(d.edge.x-c.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let d=0;d<s.length;d=d+2){let c=d+1;if(c>=s.length)break;let u=s[d].edge,m=s[c].edge;o.push([[Math.round(u.x),a],[Math.round(m.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.edge.islope}),l++}return o}function Et(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),sa(e,o,i,r||1)}var qt=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=Et(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 Kt(e){let t=e[0],n=e[1];return Math.sqrt(Math.pow(t[0]-n[0],2)+Math.pow(t[1]-n[1],2))}var Yi=class extends qt{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=Et(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)Kt([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 ji=class extends qt{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 Xi=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=Et(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=Kt(a),d=l/o,c=Math.ceil(d)-1,u=l-c*o,m=(a[0][0]+a[1][0])/2-o/4,p=Math.min(a[0][1],a[1][1]);for(let f=0;f<c;f++){let h=p+u+f*o,E=m-s+Math.random()*2*s,g=h-s+Math.random()*2*s,x=this.helper.ellipse(E,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var $i=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=Et(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=Kt(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 Vi=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=Et(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=Kt(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 Re={};function aa(e,t){let n=e.fillStyle||"hachure";if(!Re[n])switch(n){case"zigzag":Re[n]||(Re[n]=new Yi(t));break;case"cross-hatch":Re[n]||(Re[n]=new ji(t));break;case"dots":Re[n]||(Re[n]=new Xi(t));break;case"dashed":Re[n]||(Re[n]=new $i(t));break;case"zigzag-line":Re[n]||(Re[n]=new Vi(t));break;case"hachure":default:n="hachure",Re[n]||(Re[n]=new qt(t));break}return Re[n]}P();function la(){return Math.floor(Math.random()*2**31)}var Zi=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 qi={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 bu(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 fr(e,t){return e.type===t}function Hn(e){let t=[],n=bu(e),i="BOD",o=0,r=n[o];for(;!fr(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=qi[r.text],i=r.text;else return Hn("M0,0"+e);else fr(r,1)?s=qi[i]:(o++,s=qi[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let d=n[l];if(fr(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+i+","+d.text)}if(typeof qi[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 oi(e){let t=0,n=0,i=0,o=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[i,o]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),i=t,o=n;break;case"L":r.push({key:"L",data:[...a]}),[t,n]=a;break;case"l":t+=a[0],n+=a[1],r.push({key:"L",data:[t,n]});break;case"C":r.push({key:"C",data:[...a]}),t=a[4],n=a[5];break;case"c":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"C",data:l}),t=l[4],n=l[5];break}case"Q":r.push({key:"Q",data:[...a]}),t=a[2],n=a[3];break;case"q":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"Q",data:l}),t=l[2],n=l[3];break}case"A":r.push({key:"A",data:[...a]}),t=a[5],n=a[6];break;case"a":t+=a[5],n+=a[6],r.push({key:"A",data:[a[0],a[1],a[2],a[3],a[4],t,n]});break;case"H":r.push({key:"H",data:[...a]}),t=a[0];break;case"h":t+=a[0],r.push({key:"H",data:[t]});break;case"V":r.push({key:"V",data:[...a]}),n=a[0];break;case"v":n+=a[0],r.push({key:"V",data:[n]});break;case"S":r.push({key:"S",data:[...a]}),t=a[2],n=a[3];break;case"s":{let l=a.map((d,c)=>c%2?d+n:d+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=i,n=o;break}return r}P();function si(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)&&(da(i,o,E,g,u,m,p,f,h).forEach(function(w){t.push({key:"C",data:w})}),i=E,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=d}return t}function yu(e){return Math.PI*e/180}function ri(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 da(e,t,n,i,o,r,s,a,l,d){let c=yu(s),u=[],m=0,p=0,f=0,h=0;if(d)[m,p,f,h]=d;else{[e,t]=ri(e,t,-c),[n,i]=ri(n,i,-c);let k=(e-n)/2,B=(t-i)/2,X=k*k/(o*o)+B*B/(r*r);X>1&&(X=Math.sqrt(X),o=X*o,r=X*r);let _=a===l?-1:1,ie=o*o,F=r*r,S=ie*F-ie*B*B-F*k*k,z=ie*B*B+F*k*k,W=_*Math.sqrt(Math.abs(S/z));f=W*o*B/r+(e+n)/2,h=W*-r*k/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 k=p,B=n,X=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=da(n,i,B,X,o,r,s,0,l,[p,k,f,h])}E=p-m;let g=Math.cos(m),x=Math.sin(m),w=Math.cos(p),y=Math.sin(p),b=Math.tan(E/4),I=4/3*o*b,A=4/3*r*b,T=[e,t],M=[e+I*x,t-A*g],O=[n+I*y,i-A*w],L=[n,i];if(M[0]=2*T[0]-M[0],M[1]=2*T[1]-M[1],d)return[M,O,L].concat(u);{u=[M,O,L].concat(u);let k=[];for(let B=0;B<u.length;B+=3){let X=ri(u[B][0],u[B][1],c),_=ri(u[B+1][0],u[B+1][1],c),ie=ri(u[B+2][0],u[B+2][1],c);k.push([X[0],X[1],_[0],_[1],ie[0],ie[1]])}return k}}var Pu={randOffset:Au,randOffsetWithRange:Mu,ellipse:Su,doubleLineOps:Tu};function hr(e,t,n,i,o){return{type:"path",ops:Tt(e,t,n,i,o)}}function ai(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...Tt(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...Tt(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return hr(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Iu(e,t){return ai(e,!0,t)}function fa(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Iu(r,o)}function Er(e,t){let n=ua(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=ua(e,1.5*(1+t.roughness*.22),vu(t));n=n.concat(i)}return{type:"path",ops:n}}function Su(e,t,n,i,o){let r=gr(n,i,o);return Ji(e,t,o,r).opset}function gr(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=R(s*l,n),a+=R(a*l,n),{increment:r,rx:s,ry:a}}function Ji(e,t,n,i){let[o,r]=ma(i.increment,e,t,i.rx,i.ry,1,i.increment*Ki(.1,Ki(.4,1,n),n),n),s=Qi(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=ma(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Qi(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function xr(e,t,n,i,o,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),m=Math.abs(i/2);u+=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=pa(E,d,c,u,m,p,f,1,l);if(!l.disableMultiStroke){let x=pa(E,d,c,u,m,p,f,1.5,l);g.push(...x)}return s&&(a?g.push(...Tt(d,c,d+u*Math.cos(p),c+m*Math.sin(p),l),...Tt(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 wr(e,t){let n=si(oi(Hn(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(...Tt(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(...Du(l,d,c,u,m,p,r,t)),r=[m,p];break}case"Z":i.push(...Tt(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function eo(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 An(e,t){return aa(t,Pu).fillPolygons(e,t)}function ha(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]),An([f],s)}function Au(e,t){return R(e,t)}function Mu(e,t,n){return Ki(e,t,n)}function Tu(e,t,n,i,o){return Tt(e,t,n,i,o,!0)}function vu(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Ea(e){return e.randomizer||(e.randomizer=new Zi(e.seed||0)),e.randomizer.next()}function Ki(e,t,n,i=1){return n.roughness*i*(Ea(n)*(t-e)+e)}function R(e,t,n=1){return Ki(-e,e,t,n)}function Tt(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=ca(e,t,n,i,o,!0,!1);if(s)return a;let l=ca(e,t,n,i,o,!0,!0);return a.concat(l)}function ca(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+Ea(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 ua(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 Qi(i,null,n)}function Qi(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(...Tt(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function ma(e,t,n,i,o,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let m=[t+i*Math.cos(u),n+o*Math.sin(u)];d.push(m),c.push(m)}c.push([t+i*Math.cos(0),n+o*Math.sin(0)]),c.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=R(.5,a)-Math.PI/2;c.push([R(r,a)+t+.9*i*Math.cos(u-e),R(r,a)+n+.9*o*Math.sin(u-e)]);let m=Math.PI*2+u-.01;for(let p=u;p<m;p=p+e){let 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 pa(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)]),Qi(c,null,l)}function Du(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 li(e){return[...e]}function ga(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(li(e[0]),li(e[1]),li(e[2]),li(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(li(o[0]));for(let a=1;a+2<o.length;a++){let l=o[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*o[a+1][0]-s*o[a-1][0])/6,l[1]+(s*o[a+1][1]-s*o[a-1][1])/6],r[2]=[o[a+1][0]+(s*o[a][0]-s*o[a+2][0])/6,o[a+1][1]+(s*o[a][1]-s*o[a+2][1])/6],r[3]=[o[a+1][0],o[a+1][1]],i.push(r[1],r[2],r[3])}}return i}P();function Bu(e,t){return Math.sqrt(to(e,t))}function to(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Lu(e,t,n){let i=to(t,n);if(i===0)return to(e,t);let o=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/i;return o=Math.max(0,Math.min(1,o)),to(e,Mn(t,n,o))}function Mn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Cu(e,t){let n=e[t+0],i=e[t+1],o=e[t+2],r=e[t+3],s=3*i[0]-2*n[0]-r[0];s*=s;let a=3*i[1]-2*n[1]-r[1];a*=a;let l=3*o[0]-2*r[0]-n[0];l*=l;let d=3*o[1]-2*r[1]-n[1];return d*=d,s<l&&(s=l),a<d&&(a=d),s+a}function br(e,t,n,i){let o=i||[];if(Cu(e,t)<n){let r=e[t+0];o.length?Bu(o[o.length-1],r)>1&&o.push(r):o.push(r),o.push(e[t+3])}else{let s=e[t+0],a=e[t+1],l=e[t+2],d=e[t+3],c=Mn(s,a,.5),u=Mn(a,l,.5),m=Mn(l,d,.5),p=Mn(c,u,.5),f=Mn(u,m,.5),h=Mn(p,f,.5);br([s,c,p,h],0,n,o),br([h,f,m,d],0,n,o)}return o}function di(e,t){return no(e,0,e.length,t)}function no(e,t,n,i,o){let r=o||[],s=e[t],a=e[n-1],l=0,d=1;for(let c=t+1;c<n-1;++c){let u=Lu(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>i?(no(e,t,d+1,i,r),no(e,d,n,i,r)):(r.length||r.push(s),r.push(a)),r}function vt(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;br(e,s,t,i)}return n&&n>0?no(i,0,i.length,n):i}P();function xa(e,t,n){let i=Hn(e),o=si(oi(i)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...vt(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=di(m,n);p.length&&u.push(p)}return u}var Xe="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 la()}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,i){return{shape:t,sets:n||[],options:i||this.defaultOptions}}line(t,n,i,o,r){let s=this._o(r);return this._d("line",[hr(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=fa(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(eo([d],s)):a.push(An([d],s))}return s.stroke!==Xe&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=gr(i,o,s),d=Ji(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Ji(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(An([d.estimatedPoints],s));return s.stroke!==Xe&&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",[ai(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let d=this._o(l),c=[],u=xr(t,n,i,o,r,s,a,!0,d);if(a&&d.fill)if(d.fillStyle==="solid"){let m=Object.assign({},d);m.disableMultiStroke=!0;let p=xr(t,n,i,o,r,s,!0,!1,m);p.type="fillPath",c.push(p)}else c.push(ha(t,n,i,o,r,s,d));return d.stroke!==Xe&&c.push(u),this._d("arc",c,d)}curve(t,n){let i=this._o(n),o=[],r=Er(t,i);if(i.fill&&i.fill!==Xe&&t.length>=3)if(i.fillStyle==="solid"){let s=Er(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=ga(t),a=vt(s,10,(1+i.roughness)/2);o.push(An([a],i))}return i.stroke!==Xe&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=ai(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(eo([t],i)):o.push(An([t],i))),i.stroke!==Xe&&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!==Xe,s=i.stroke!==Xe,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,d=xa(t,1,l),c=wr(t,i);if(r)if(i.fillStyle==="solid")if(d.length===1){let u=wr(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(eo(d,i));else o.push(An(d,i));return s&&(a?d.forEach(u=>{o.push(ai(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:Xe};break;case"fillPath":s={d:this.opsToPath(r),stroke:Xe,strokeWidth:0,fill:i.fill||Xe};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||Xe,strokeWidth:i,fill:Xe}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var io=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 ci="http://www.w3.org/2000/svg";var oo=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(ci,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(ci,"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(ci,"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(ci,"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 Tn={canvas(e,t){return new io(e,t)},svg(e,t){return new oo(e,t)},generator(e){return new Je(e)},newSeed(){return Je.newSeed()}};import{arrayToMap as Nd,invariant as Is,rescalePoints as Gd,sizeOf as ih}from"@excalidraw/common";import{degreesToRadians as Ps,lineSegment as ge,pointDistance as oh,pointFrom as D,pointFromArray as zd,pointRotateRads as oe}from"@excalidraw/math";P();import{invariant as Gu}from"@excalidraw/common";import{curve as Ou,lineSegment as ku,pointFrom as ae,pointDistance as cw,pointFromArray as Fu,pointFromVector as Ru,pointRotateRads as rt,polygon as wa,polygonFromPoints as yr,PRECISION as uw,segmentsIntersectAt as mw,vector as Nu,vectorAdd as zu,vectorFromPoint as Hu,vectorScale as pw}from"@excalidraw/math";import{getElementAbsoluteCoords as hw}from"@excalidraw/element";var ba=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=ae(s,a),d;return e.type==="diamond"?d=wa(rt(ae(s,r),l,t),rt(ae(o+n,a),l,t),rt(ae(s,r+i),l,t),rt(ae(o,a),l,t)):d=wa(rt(ae(o,r),l,t),rt(ae(o+n,r),l,t),rt(ae(o+n,r+i),l,t),rt(ae(o,r+i),l,t)),{type:"polygon",data:d}};var ya=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:ae(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},Dt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},Pa=(e,t=ae(0,0),n,i)=>{let o=l=>rt(ae(l[0]+t[0],l[1]+t[1]),i,n),r=Dt(e),s=[],a=ae(0,0);for(let l of r){if(l.op==="move"){let d=Fu(l.data);Gu(d!=null,"Ops data is not a point"),a=o(d)}if(l.op==="bcurveTo"){let d=o(ae(l.data[0],l.data[1])),c=o(ae(l.data[2],l.data[3])),u=o(ae(l.data[4],l.data[5]));s.push(Ou(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},_u=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(ku(t,o)),t=o}return n},Ia=(e,t,n=!1)=>{let i=r=>rt(Ru(zu(Hu(r),Nu(e.x,e.y))),t,e.angle),o=_u(e.points.map(r=>i(r)));return n?{type:"polygon",data:yr(o.flat())}:{type:"polyline",data:o}},Sa=(e,t,n=ae(0,0),i,o)=>{let r=c=>rt(ae(c[0]+n[0],c[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:yr(e.points.map(c=>r(c)))};let s=Dt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(ae(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(ae(c.data[0],c.data[1])),a.push(ae(c.data[2],c.data[3])),a.push(ae(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(ae(c.data[0],c.data[1]));let d=vt(a,10,5).map(c=>r(c));return{type:"polygon",data:yr(d)}};P();P();function Aa(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function Uu(e){return[-e[0],-e[1]]}function at(e,t){return[e[0]+t[0],e[1]+t[1]]}function et(e,t){return[e[0]-t[0],e[1]-t[1]]}function st(e,t){return[e[0]*t,e[1]*t]}function Wu(e,t){return[e[0]/t,e[1]/t]}function ui(e){return[e[1],-e[0]]}function Ma(e,t){return e[0]*t[0]+e[1]*t[1]}function Yu(e,t){return e[0]===t[0]&&e[1]===t[1]}function ju(e){return Math.hypot(e[0],e[1])}function Xu(e){return e[0]*e[0]+e[1]*e[1]}function Ta(e,t){return Xu(et(e,t))}function Ba(e){return Wu(e,ju(e))}function $u(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function mi(e,t,n){let i=Math.sin(n),o=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*o-s*i,l=r*i+s*o;return[a+t[0],l+t[1]]}function Pr(e,t,n){return at(e,st(et(t,e),n))}function va(e,t,n){return at(e,st(t,n))}var{min:_n,PI:Vu}=Math,Da=.275,pi=Vu+1e-4;function Zu(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=F=>F,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=F=>F*(2-F)}=a,{cap:m=!0,easing:p=F=>--F*F*F+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,h=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,E=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*i,2),x=[],w=[],y=e.slice(0,10).reduce((F,S)=>{let z=S.pressure;if(r){let W=_n(1,S.distance/n),xe=_n(1,1-W);z=_n(1,F+(xe-F)*(W*Da))}return(F+z)/2},e[0].pressure),b=Aa(n,o,e[e.length-1].pressure,s),I,A=e[0].vector,T=e[0].point,M=T,O=T,L=M,k=!1;for(let F=0;F<e.length;F++){let{pressure:S}=e[F],{point:z,vector:W,distance:xe,runningLength:ht}=e[F];if(F<e.length-1&&f-ht<3)continue;if(o){if(r){let je=_n(1,xe/n),Qe=_n(1,1-je);S=_n(1,y+(Qe-y)*(je*Da))}b=Aa(n,o,S,s)}else b=n/2;I===void 0&&(I=b);let Hi=ht<h?u(ht/h):1,ur=f-ht<E?p((f-ht)/E):1;b=Math.max(.01,b*Math.min(Hi,ur));let _i=(F<e.length-1?e[F+1]:e[F]).vector,ii=F<e.length-1?Ma(W,_i):1,mr=Ma(W,A)<0&&!k,Ui=ii!==null&&ii<0;if(mr||Ui){let je=st(ui(A),b);for(let Qe=1/13,Zt=0;Zt<=1;Zt+=Qe)O=mi(et(z,je),z,pi*Zt),x.push(O),L=mi(at(z,je),z,pi*-Zt),w.push(L);T=O,M=L,Ui&&(k=!0);continue}if(k=!1,F===e.length-1){let je=st(ui(W),b);x.push(et(z,je)),w.push(at(z,je));continue}let Wi=st(ui(Pr(_i,W,ii)),b);O=et(z,Wi),(F<=1||Ta(T,O)>g)&&(x.push(O),T=O),L=at(z,Wi),(F<=1||Ta(M,L)>g)&&(w.push(L),M=L),y=S,A=W}let B=e[0].point.slice(0,2),X=e.length>1?e[e.length-1].point.slice(0,2):at(e[0].point,[1,1]),_=[],ie=[];if(e.length===1){if(!(h||E)||d){let F=va(B,Ba(ui(et(B,X))),-(I||b)),S=[];for(let z=1/13,W=z;W<=1;W+=z)S.push(mi(F,B,pi*2*W));return S}}else{if(!(h||E&&e.length===1))if(c)for(let S=1/13,z=S;z<=1;z+=S){let W=mi(w[0],B,pi*z);_.push(W)}else{let S=et(x[0],w[0]),z=st(S,.5),W=st(S,.51);_.push(et(B,z),et(B,W),at(B,W),at(B,z))}let F=ui(Uu(e[e.length-1].vector));if(E||h&&e.length===1)ie.push(X);else if(m){let S=va(X,F,b);for(let z=1/29,W=z;W<1;W+=z)ie.push(mi(S,X,pi*3*W))}else ie.push(at(X,st(F,b)),at(X,st(F,b*.99)),et(X,st(F,b*.99)),et(X,st(F,b)))}return x.concat(ie,w.reverse(),_)}function qu(e,t={}){var n;let{streamline:i=.5,size:o=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-i)*.85,a=Array.isArray(e[0])?e:e.map(({x:p,y: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(Pr(a[0],p,f/4))}a.length===1&&(a=[...a,[...at(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=!1,c=0,u=l[0],m=a.length-1;for(let p=1;p<a.length;p++){let f=r&&p===m?a[p].slice(0,2):Pr(u.point,a[p],s);if(Yu(u.point,f))continue;let h=$u(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:Ba(et(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 La(e,t={}){return Zu(qu(e,t),t)}import{pointFrom as le,pointDistance as Md,pointRotateRads as Yt}from"@excalidraw/math";import{ROUGHNESS as Xf,THEME as ys,isTransparent as Oi,assertNever as $f,COLOR_PALETTE as Vf,LINE_POLYGON_POINT_MERGE_DISTANCE as Zf,applyDarkModeFilter as ki}from"@excalidraw/common";P();import{isRightAngleRads as Gf,lineSegment as bd,pointFrom as _o,pointRotateRads as gs}from"@excalidraw/math";import{BOUND_TEXT_PADDING as Uo,DEFAULT_REDUCED_GLOBAL_ALPHA as Of,ELEMENT_READY_TO_ERASE_OPACITY as kf,FRAME_STYLE as Li,DARK_THEME_FILTER as Ff,MIME_TYPES as ws,THEME as Zn,distance as gn,getFontString as Rf,isRTL as Nf,getVerticalOffset as zf,invariant as Hf,applyDarkModeFilter as Yo,isSafari as _f}from"@excalidraw/common";P();import{pointFrom as Bt,pointCenter as Ku,pointRotateRads as Qt,vectorFromPoint as Ir,vectorNormalize as Ca,vectorSubtract as Ga,vectorAdd as ro,vectorScale as so,pointFromVector as Oa,clamp as Pe,isCloseTo as ka}from"@excalidraw/math";var Ie=10,Pw=(e,t,n,i,o,r,s,a)=>{let{width:l,height:d}=Sr(e),c=i/l,u=o/d,m=(e.crop?.x??0)/c,p=(e.crop?.y??0)/u,f=Qt(Bt(r,s),re(e,t),-e.angle);r=f[0],s=f[1];let h=e.width,E=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,w=g.width,y=e.scale[0]===-1,b=e.scale[1]===-1,I=s-e.y,A=r-e.x;n.includes("n")&&(E=Pe(e.height-I,Ie,b?d-p:e.height+p)),n.includes("s")&&(I=s-e.y-e.height,E=Pe(e.height+I,Ie,b?e.height+p:d-p)),n.includes("e")&&(A=r-e.x-e.width,h=Pe(e.width+A,Ie,y?e.width+m:l-m)),n.includes("w")&&(h=Pe(e.width-A,Ie,y?l-m:e.width+m));let T=L=>{L.height=E*u,L.width=h*c};T(g);let M=(L,k)=>{T(k),L.includes("n")&&(b||(k.y+=x-k.height)),L.includes("s")&&b&&(k.y+=x-k.height),L.includes("e")&&y&&(k.x+=w-k.width),L.includes("w")&&(y||(k.x+=w-k.width))};switch(n){case"n":{if(a){let L=m+e.width/2,k=l-m-e.width/2,B=Math.min(L,k)*2;h=Pe(E*a,Ie,B),E=h/a}M(n,g),a&&(g.x+=(w-g.width)/2);break}case"s":{if(a){let L=m+e.width/2,k=l-m-e.width/2,B=Math.min(L,k)*2;h=Pe(E*a,Ie,B),E=h/a}M(n,g),a&&(g.x+=(w-g.width)/2);break}case"w":{if(a){let L=p+e.height/2,k=d-p-e.height/2,B=Math.min(L,k)*2;E=Pe(h/a,Ie,B),h=E*a}M(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let L=p+e.height/2,k=d-p-e.height/2,B=Math.min(L,k)*2;E=Pe(h/a,Ie,B),h=E*a}M(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(A>-I){let L=b?d-p:p+e.height;E=Pe(h/a,Ie,L),h=E*a}else{let L=y?m+e.width:l-m;h=Pe(E*a,Ie,L),E=h/a}M(n,g);break}case"nw":{if(a)if(A<I){let L=b?d-p:p+e.height;E=Pe(h/a,Ie,L),h=E*a}else{let L=y?l-m:m+e.width;h=Pe(E*a,Ie,L),E=h/a}M(n,g);break}case"se":{if(a)if(A>I){let L=b?p+e.height:d-p;E=Pe(h/a,Ie,L),h=E*a}else{let L=y?m+e.width:l-m;h=Pe(E*a,Ie,L),E=h/a}M(n,g);break}case"sw":{if(a)if(-A>I){let L=b?p+e.height:d-p;E=Pe(h/a,Ie,L),h=E*a}else{let L=y?l-m:m+e.width;h=Pe(E*a,Ie,L),E=h/a}M(n,g);break}default:break}let O=Qu(e,n,h,E,!!a);return ka(g.width,g.naturalWidth)&&ka(g.height,g.naturalHeight)&&(g=null),{x:O[0],y:O[1],width:h,height:E,crop:g}},Qu=(e,t,n,i,o)=>{let[r,s,a,l]=Jt(e,e.width,e.height,!0),d=Bt(r,s),c=Bt(a,l),u=Ku(d,c),[m,p,f,h]=Jt(e,n,i,!0),E=f-m,g=h-p,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(E),c[1]-Math.abs(g)]),t==="ne"){let T=[d[0],c[1]];x=[T[0],T[1]-Math.abs(g)]}if(t==="sw"){let T=[c[0],d[1]];x=[T[0]-Math.abs(E),T[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-E/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let w=e.angle,y=Qt(x,u,w),b=[x[0]+Math.abs(E)/2,x[1]+Math.abs(g)/2],I=Qt(b,u,w);x=Qt(y,I,-w);let A=[...x];return A[0]+=e.x-m,A[1]+=e.y-p,A},Fa=(e,t)=>{if(e.crop){let{width:n,height:i}=Sr(e),[o,r,s,a,l,d]=$(e,t),c=Ir(Qt(Bt(o,r),Bt(l,d),e.angle)),u=Ir(Qt(Bt(s,r),Bt(l,d),e.angle)),m=Ca(Ga(u,c)),p=Ir(Qt(Bt(o,a),Bt(l,d),e.angle)),f=Ga(p,c),h=Ca(f),{cropX:E,cropY:g}=Ju(e.crop,e.scale),x=ro(ro(c,so(m,-E*n/e.crop.naturalWidth)),so(h,-g*i/e.crop.naturalHeight)),w=Oa(ro(ro(x,so(m,n/2)),so(h,i/2))),y=Qt(Oa(x),w,-e.angle);return{...e,x:y[0],y:y[1],width:n,height:i,crop:null}}return e},Sr=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}},Ju=(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}},Iw=(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}=Sr(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as Ul,pointFrom as G,pointRotateRads as Ce,pointsEqual as Wl,pointDistance as kn,vectorFromPoint as Zp,curveLength as qp,curvePointAtLength as Kp}from"@excalidraw/math";import{DRAGGING_THRESHOLD as Qp,KEYS as On,shouldRotateWithDiscreteAngle as Di,getGridPoint as Yl,invariant as Ge,isShallowEqual as Jp,getFeatureFlag as $n}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as jl,getSnapOutlineMidPoint as Xl,isPathALoop as ef,moveArrowAboveBindable as $l,projectFixedPointOntoDiagonal as Vl}from"@excalidraw/element";P();import{arrayToMap as kl,getFeatureFlag as Dp,invariant as it,isTransparent as Bp}from"@excalidraw/common";import{PRECISION as Lp,clamp as rs,lineSegment as Go,pointDistance as un,pointDistanceSq as _t,pointFrom as te,pointFromVector as Lo,pointRotateRads as se,pointsEqual as Cp,vectorFromPoint as Mi,vectorNormalize as os,vectorScale as Co}from"@excalidraw/math";P();import{invariant as ul,isTransparent as ml}from"@excalidraw/common";import{curveIntersectLineSegment as pl,isPointWithinBounds as wo,lineSegment as yi,lineSegmentIntersectionPoints as fl,pointFrom as me,pointFromVector as Zm,pointRotateRads as Ze,pointsEqual as hl,vectorFromPoint as qm,vectorNormalize as Km,vectorScale as Qm}from"@excalidraw/math";import{ellipse as Jm,ellipseSegmentInterceptPoints as ep}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as am,DEFAULT_PROPORTIONAL_RADIUS as Mr,invariant as lm,LINE_CONFIRM_THRESHOLD as dm,ROUNDNESS as Tr}from"@excalidraw/common";import{bezierEquation as cm,curve as Ct,curveCatmullRomCubicApproxPoints as Xa,curveOffsetPoints as $a,lineSegment as Ee,lineSegmentIntersectionPoints as Ya,pointDistance as Dn,pointFrom as N,pointFromArray as um,pointFromVector as mm,pointRotateRads as $e,pointTranslate as ja,rectangle as pm,vectorFromPoint as Va,vectorNormalize as fm,vectorScale as vr}from"@excalidraw/math";P();import{ROUNDNESS as fi,assertNever as em}from"@excalidraw/common";import{pointsEqual as Ra}from"@excalidraw/math";var vn=e=>!!e&&e.type==="image"&&!!e.fileId,we=e=>!!e&&e.type==="image",Na=e=>!!e&&e.type==="embeddable",ao=e=>!!e&&e.type==="iframe",lo=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),Q=e=>e!=null&&e.type==="text",co=e=>e!=null&&e.type==="frame",za=e=>e!=null&&e.type==="magicframe",Z=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Se=e=>e!=null&&tm(e.type),tm=e=>e==="freedraw",q=e=>e!=null&&om(e.type),Lt=e=>e!=null&&e.type==="line",H=e=>e!=null&&e.type==="arrow",U=e=>H(e)&&e.elbowed,vw=e=>H(e)&&!e.elbowed,nm=e=>H(e)&&!e.elbowed&&!e.roundness,im=e=>H(e)&&!e.elbowed&&e.roundness!==null,om=e=>e==="arrow"||e==="line",Ae=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&rm(e.type),rm=e=>e==="arrow",de=(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),Ha=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),hi=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"),sm=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||H(e)),Dw=e=>{let t=e?.type;if(!t)return!1;switch(t){case"text":case"diamond":case"rectangle":case"iframe":case"embeddable":case"ellipse":case"arrow":case"freedraw":case"line":case"frame":case"magicframe":case"image":case"selection":return!0;default:return em(t,null),!1}},Ar=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",gt=e=>sm(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),ce=e=>e!==null&&"containerId"in e&&e.containerId!==null&&Q(e),Bw=e=>!!e.startBinding||!!e.endBinding,_a=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",Ua=e=>e==="line"||e==="arrow"||e==="diamond",Lw=(e,t)=>!!((e===fi.ADAPTIVE_RADIUS||e===fi.LEGACY)&&_a(t.type)||e===fi.PROPORTIONAL_RADIUS&&Ua(t.type)),Cw=e=>Ua(e.type)?{type:fi.PROPORTIONAL_RADIUS}:_a(e.type)?{type:fi.ADAPTIVE_RADIUS}:null,Gw=e=>nm(e)?"sharpArrow":im(e)?"curvedArrow":U(e)?"elbowArrow":"line",Ow=e=>e.length>3&&Ra(e[0],e[e.length-1]),Wa=e=>e.length>3||e.length===3&&!Ra(e[0],e[e.length-1]);var Ei=new WeakMap,Dr=(e,t)=>{let n=Ei.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){Ei.delete(e);return}return o.get(t)},Br=(e,t,n)=>{let i=Ei.get(e);if(!i){Ei.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){Ei.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function uo(e){let t=Dr(e,0);if(t)return t;let n=qa(e),i=[],o=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&um(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");i.push(Ee(N(e.x+l[0],e.y+l[1]),N(e.x+a.data[0],e.y+a.data[1])));continue;case"bcurveTo":if(!l)throw new Error("prevPoint is undefined");o.push(Ct(N(e.x+l[0],e.y+l[1]),N(e.x+a.data[0],e.y+a.data[1]),N(e.x+a.data[2],e.y+a.data[3]),N(e.x+a.data[4],e.y+a.data[5])));continue;default:console.error("Unknown op type",a.op)}}let r=[i,o];return Br(e,r,0),r}function en(e,t=0){let n=Dr(e,t);if(n)return n;let i=Gt(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=pm(N(e.x,e.y),N(e.x+e.width,e.y+e.height)),r=Ee(N(o[0][0]+i,o[0][1]),N(o[1][0]-i,o[0][1])),s=Ee(N(o[1][0],o[0][1]+i),N(o[1][0],o[1][1]-i)),a=Ee(N(o[0][0]+i,o[1][1]),N(o[1][0]-i,o[1][1])),l=Ee(N(o[0][0],o[1][1]-i),N(o[0][0],o[0][1]+i)),d=[Ct(l[1],N(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),N(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),Ct(r[1],N(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),N(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),Ct(s[1],N(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),N(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),Ct(a[0],N(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),N(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=>Xa($a(p,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],m=[[Ee(c[0][c[0].length-1][3],c[1][0][0]),Ee(c[1][c[1].length-1][3],c[2][0][0]),Ee(c[2][c[2].length-1][3],c[3][0][0]),Ee(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Br(e,m,t),m}function Za(e,t=0){let[n,i,o,r,s,a,l,d]=Un(e),c=e.roundness?Gt(Math.abs(n-l),e):(n-l)*.01,u=e.roundness?Gt(Math.abs(r-i),e):(r-i)*.01,[m,p,f,h]=[N(e.x+n,e.y+i),N(e.x+o,e.y+r),N(e.x+s,e.y+a),N(e.x+l,e.y+d)];return[Ct(N(p[0]-c,p[1]-u),p,p,N(p[0]-c,p[1]+u)),Ct(N(f[0]+c,f[1]-u),f,f,N(f[0]-c,f[1]-u)),Ct(N(h[0]+c,h[1]+u),h,h,N(h[0]+c,h[1]-u)),Ct(N(m[0]-c,m[1]+u),m,m,N(m[0]+c,m[1]+u))]}function tn(e,t=0){let n=Dr(e,t);if(n)return n;let o=Za(e,t).map(a=>Xa($a(a,t))),s=[[Ee(o[0][o[0].length-1][3],o[1][0][0]),Ee(o[1][o[1].length-1][3],o[2][0][0]),Ee(o[2][o[2].length-1][3],o[3][0][0]),Ee(o[3][o[3].length-1][3],o[0][0][0])],o.flat()];return Br(e,s,t),s}var Bn=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return Dn(n,i)<=dm/t}return!1},Gt=(e,t)=>{if(t.roundness?.type===Tr.PROPORTIONAL_RADIUS||t.roundness?.type===Tr.LEGACY)return e*Mr;if(t.roundness?.type===Tr.ADAPTIVE_RADIUS){let n=t.roundness?.value??am,i=n/Mr;return e<=i?e*Mr:n}return 0},hm=(e,t)=>{let n=e.type==="rectangle"?15:0,i=a=>{let l=fm(Va(a[1],a[0])),d=vr(l,n);return Ee(ja(a[0],d),ja(a[1],vr(d,-1)))},o=re(e,t),r=i(hi(e)?Ee($e(N(e.x,e.y),o,e.angle),$e(N(e.x+e.width,e.y+e.height),o,e.angle)):Ee($e(N(e.x+e.width/2,e.y),o,e.angle),$e(N(e.x+e.width/2,e.y+e.height),o,e.angle))),s=i(hi(e)?Ee($e(N(e.x+e.width,e.y),o,e.angle),$e(N(e.x,e.y+e.height),o,e.angle)):Ee($e(N(e.x,e.y+e.height/2),o,e.angle),$e(N(e.x+e.width,e.y+e.height/2),o,e.angle)));return[r,s]},Em=(e,t,n,i)=>{let o=re(t,n);return(t.type==="diamond"?Za(t).map(a=>{let l=cm(a,.5),d=$e(l,o,t.angle);return N(d[0],d[1])}):[$e(N(t.x+t.width,t.y+t.height/2),o,t.angle),$e(N(t.x+t.width/2,t.y+t.height),o,t.angle),$e(N(t.x,t.y+t.height/2),o,t.angle),$e(N(t.x+t.width/2,t.y),o,t.angle)]).find(a=>Dn(e,a)<=lt(i)+t.strokeWidth/2&&!xt({point:e,element:t,threshold:0,elementsMap:n,overrideShouldTestInside:!0}))},Lr=(e,t,n,i,o,r,s=!0)=>{if(lm(e.points.length>=2,"Arrow must have at least two points"),e.width<3&&e.height<3)return null;if(s){let g=Em(t,n,o,r);if(g)return g}let[a,l]=hm(n,o),d=C.getPointAtIndexGlobalCoordinates(e,i==="start"?1:e.points.length-2,o);if(e.points.length===2){let g=i==="start"?e.endBinding:e.startBinding,x=g&&o.get(g.elementId),w=g&&x&&Ne(nn(g.fixedPoint),x,o);w&&(d=w)}let c=mm(vr(Va(t,d),2*Dn(d,t)+Math.max(Dn(a[0],a[1]),Dn(l[0],l[1]))),d),u=Ee(c,d),m=Ya(a,u),p=Ya(l,u),f=m&&Dn(d,m),h=p&&Dn(d,p),E=null;return f!=null&&h!=null?E=f<h?m:p:E=m||p||null,E&&Ot(E,n,o)?E:null};P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Fm,ARROW_LABEL_WIDTH_FRACTION as Rm,BOUND_TEXT_PADDING as wt,DEFAULT_FONT_SIZE as Nm,TEXT_ALIGN as il,VERTICAL_ALIGN as ol,getFontString as go,isProdEnv as zm,invariant as Hm}from"@excalidraw/common";import{pointFrom as rl,pointRotateRads as _m}from"@excalidraw/math";P();var gi={},Ka=(e,t)=>{let n=gi[e]||(gi[e]={height:t});return n.height=t,n},Qa=e=>{gi[e]&&delete gi[e]},Vw=e=>gi[e]?.height??null;P();import{BOUND_TEXT_PADDING as po,DEFAULT_FONT_SIZE as gm,DEFAULT_FONT_FAMILY as xm,getFontString as wm,isTestEnv as bm,normalizeEOL as ym}from"@excalidraw/common";var Ve=(e,t,n)=>{let i=e.split(`
2
2
  `).map(a=>a||" ").join(`
3
- `),o=parseFloat(t),r=xm(i,o,n);return{width:Qa(i,t),height:r}},Za="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),qa=(e,t)=>{let n=wm(e);return n===0?Xe(Za.split("").join(`
4
- `),e,t).width+lo*2:n+lo*2},co=(e,t)=>Xe("",e,t).width+lo*2,Xw=()=>Qa(Za,hm({fontSize:pm,fontFamily:fm}))>0,Ei=e=>gm(e).replace(/\t/g," "),Dr=e=>Ei(e).split(`
5
- `),$w=e=>{let t=Dr(e.text).length;return e.height/t/e.fontSize},uo=(e,t)=>e*t,Ka=(e,t)=>uo(e,t)+lo*2,ao,Vw=e=>{ao=e},vr=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 Em()?r*10:r}},nn=(e,t)=>(ao||(ao=new vr),ao.getLineWidth(e,t)),Qa=(e,t)=>{let n=Dr(e),i=0;return n.forEach(o=>{i=Math.max(i,nn(o,t))}),i},xm=(e,t,n)=>{let i=Dr(e).length;return uo(t,n)*i},_n=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=nn(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),Zw=e=>{let t=_n.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},wm=e=>{let t=_n.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as bm,isTestEnv as ym}from"@excalidraw/common";var Br,mo,Lr,eb=e=>(Br||(Br=ee.class(...Object.values(Ot))),Br.test(e)),Pm=()=>{if(!mo)try{mo=Sm()}catch{mo=Im()}return mo},Cr=()=>(Lr||(Lr=Am()),Lr),Je={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},Ot={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},Bn={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},Im=()=>ee.or(Cr(),ue.On(Je.HYPHEN,Je.WHITESPACE,Ot.CHAR)),Sm=()=>ee.or(Cr(),ue.Before(Je.WHITESPACE).Build(),ue.After(Je.WHITESPACE,Je.HYPHEN).Build(),ue.Before(Ot.CHAR,Ot.CURRENCY).NotPrecededBy(Je.OPENING,Ot.OPENING).Build(),ue.After(Ot.CHAR).NotFollowedBy(Je.HYPHEN,Je.CLOSING,Ot.CLOSING).Build(),ue.BeforeMany(Ot.OPENING).NotPrecededBy(Je.OPENING).Build(),ue.AfterMany(Ot.CLOSING).NotFollowedBy(Je.CLOSING).Build(),ue.AfterMany(Je.CLOSING).FollowedBy(Je.OPENING).Build()),Am=()=>ee.group(ee.or(Bn.FLAG,ee.and(Bn.MOST,Bn.JOINER,ee.build(`(?:${Bn.ZWJ.source}(?:${Bn.FLAG.source}|${Bn.ANY.source}${Bn.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)}]`)},ue={On:(...e)=>{let t=ee.join(...e);return ee.build(`([${t}])`)},Before:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?=[${t}])`);return ue.Chain(n)},After:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?<=[${t}])`);return ue.Chain(n)},BeforeMany:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?<![${t}])(?=[${t}])`);return ue.Chain(n)},AfterMany:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?<=[${t}])(?![${t}])`);return ue.Chain(n)},NotBefore:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?![${t}])`);return ue.Chain(n)},NotAfter:(...e)=>{let t=ee.join(...e),n=()=>ee.build(`(?<![${t}])`);return ue.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),i=ue.After(...t).Build(),o=()=>ee.and(i,n);return ue.Chain(o)},FollowedBy:(...t)=>{let n=e(),i=ue.Before(...t).Build(),o=()=>ee.and(n,i);return ue.Chain(o)},NotPrecededBy:(...t)=>{let n=e(),i=ue.NotAfter(...t).Build(),o=()=>ee.and(i,n);return ue.Chain(o)},NotFollowedBy:(...t)=>{let n=e(),i=ue.NotBefore(...t).Build(),o=()=>ee.and(n,i);return ue.Chain(o)}})},Mm=e=>{let t=Pm();return e.normalize("NFC").split(t).filter(Boolean)},kt=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return e;let i=[],o=e.split(`
6
- `);for(let r of o){if(nn(r,t)<=n){i.push(r);continue}let a=Tm(r,t,n);i.push(...a)}return i.join(`
7
- `)},Tm=(e,t,n)=>{let i=[],r=Mm(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let d=l.value,c=s+d,u=Bm(d)?a+_n.calculate(d,t):nn(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=vm(d,t,n),p=m[m.length-1]??"",f=m.slice(0,-1);i.push(...f),s=p,a=nn(p,t),l=r.next()}}if(s){let d=Dm(s,t,n);i.push(d)}return i},vm=(e,t,n)=>{if(Cr().test(e))return[e];Lm(e);let i=[],o=Array.from(e),r="",s=0;for(let a of o){let l=_n.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},Dm=(e,t,n)=>{if(!(nn(e,t)>n))return e;let[,o,r]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],s=nn(o,t);for(let a of Array.from(r)){let l=_n.calculate(a,t),d=s+l;if(d>n)break;o=o+a,s=d}return o},Bm=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Lm=e=>{if((ym()||bm())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var fo=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;km()||Fm(!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?at(t,e):e.width,r.text=kt(e.originalText,po(e),o));let s=Xe(r.text,po(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=xi(t,e),l=at(t,e);if(!H(t)&&s.height>a){let m=Gr(s.height,t.type);n.mutateElement(t,{height:m}),$a(t.id,m)}if(s.width>l){let m=Gr(s.width,t.type);n.mutateElement(t,{width:m})}let d={...e,...r},{x:c,y:u}=gi(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},Ln=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!Ft(e))return;Va(e.id);let s=$(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=at(e,s),u=xi(e,s),m=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=kt(s.originalText,po(s),c));let p=Xe(a,po(s),s.lineHeight);l=p.height,d=p.width}if(l>u){m=Gr(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,gi(e,s,o))}},gi=(e,t,n)=>{if(H(e))return L.getBoundTextElementPosition(e,t,n);let i=Or(e),o=xi(e,t),r=at(e,t),s,a;t.verticalAlign===el.TOP?a=i.y:t.verticalAlign===el.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===Ja.LEFT?s=i.x:t.textAlign===Ja.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=tl(i.x+r/2,i.y+o/2),c=tl(s+t.width/2,a+t.height/2),[u,m]=Rm(c,d,l);return{x:u-t.width/2,y:m-t.height/2}}return{x:s,y:a}},Ft=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,$=(e,t)=>{if(!e)return null;let n=Ft(e);return n&&t.get(n)||null},Ae=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,cb=(e,t,n)=>{if(!H(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(L.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=L.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=L.getEditorMidPoints(e,n,t)[o];return r||(r=L.getSegmentMidPoint(e,o+1)),{x:r[0],y:r[1]}},Or=e=>{let t=gt,n=gt;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}},ub=(e,t)=>H(t)?0:t?t.angle:e.angle,mb=(e,t,n)=>{if(H(e))return L.getBoundTextElementPosition(e,t,n)},pb=(e,t)=>e.some(n=>{if(ce(n)){let i=Ae(n,t);return!H(i)}return!1}),fb=(e,t)=>e.some(n=>{if(ce(n)){let i=Ae(n,t);return!H(i)}return J(n)}),Nm=new Set(["rectangle","ellipse","diamond","arrow"]),hb=e=>Nm.has(e.type),Gr=(e,t)=>{e=Math.ceil(e);let n=gt*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},at=(e,t)=>{let{width:n}=e;if(H(e)){let i=(t?.fontSize??Om)*Cm;return Math.max(Gm*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-gt*2:e.type==="diamond"?Math.round(n/2)-gt*2:n-gt*2},xi=(e,t)=>{let{height:n}=e;return H(e)?n-gt*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-gt*2:e.type==="diamond"?Math.round(n/2)-gt*2:n-gt*2},Eb=(e,t=`
3
+ `),o=parseFloat(t),r=Pm(i,o,n);return{width:nl(i,t),height:r}},Ja="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),el=(e,t)=>{let n=Im(e);return n===0?Ve(Ja.split("").join(`
4
+ `),e,t).width+po*2:n+po*2},fo=(e,t)=>Ve("",e,t).width+po*2,Qw=()=>nl(Ja,wm({fontSize:gm,fontFamily:xm}))>0,xi=e=>ym(e).replace(/\t/g," "),Gr=e=>xi(e).split(`
5
+ `),Jw=e=>{let t=Gr(e.text).length;return e.height/t/e.fontSize},ho=(e,t)=>e*t,tl=(e,t)=>ho(e,t)+po*2,mo,eb=e=>{mo=e},Cr=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 bm()?r*10:r}},on=(e,t)=>(mo||(mo=new Cr),mo.getLineWidth(e,t)),nl=(e,t)=>{let n=Gr(e),i=0;return n.forEach(o=>{i=Math.max(i,on(o,t))}),i},Pm=(e,t,n)=>{let i=Gr(e).length;return ho(t,n)*i},Wn=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=on(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),tb=e=>{let t=Wn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},Im=e=>{let t=Wn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as Sm,isTestEnv as Am}from"@excalidraw/common";var Or,Eo,kr,sb=e=>(Or||(Or=J.class(...Object.values(kt))),Or.test(e)),Mm=()=>{if(!Eo)try{Eo=vm()}catch{Eo=Tm()}return Eo},Fr=()=>(kr||(kr=Dm()),kr),tt={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},kt={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},Ln={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},Tm=()=>J.or(Fr(),ue.On(tt.HYPHEN,tt.WHITESPACE,kt.CHAR)),vm=()=>J.or(Fr(),ue.Before(tt.WHITESPACE).Build(),ue.After(tt.WHITESPACE,tt.HYPHEN).Build(),ue.Before(kt.CHAR,kt.CURRENCY).NotPrecededBy(tt.OPENING,kt.OPENING).Build(),ue.After(kt.CHAR).NotFollowedBy(tt.HYPHEN,tt.CLOSING,kt.CLOSING).Build(),ue.BeforeMany(kt.OPENING).NotPrecededBy(tt.OPENING).Build(),ue.AfterMany(kt.CLOSING).NotFollowedBy(tt.CLOSING).Build(),ue.AfterMany(tt.CLOSING).FollowedBy(tt.OPENING).Build()),Dm=()=>J.group(J.or(Ln.FLAG,J.and(Ln.MOST,Ln.JOINER,J.build(`(?:${Ln.ZWJ.source}(?:${Ln.FLAG.source}|${Ln.ANY.source}${Ln.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)}})},Bm=e=>{let t=Mm();return e.normalize("NFC").split(t).filter(Boolean)},Ft=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return e;let i=[],o=e.split(`
6
+ `);for(let r of o){if(on(r,t)<=n){i.push(r);continue}let a=Lm(r,t,n);i.push(...a)}return i.join(`
7
+ `)},Lm=(e,t,n)=>{let i=[],r=Bm(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let d=l.value,c=s+d,u=Om(d)?a+Wn.calculate(d,t):on(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=Cm(d,t,n),p=m[m.length-1]??"",f=m.slice(0,-1);i.push(...f),s=p,a=on(p,t),l=r.next()}}if(s){let d=Gm(s,t,n);i.push(d)}return i},Cm=(e,t,n)=>{if(Fr().test(e))return[e];km(e);let i=[],o=Array.from(e),r="",s=0;for(let a of o){let l=Wn.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},Gm=(e,t,n)=>{if(!(on(e,t)>n))return e;let[,o,r]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],s=on(o,t);for(let a of Array.from(r)){let l=Wn.calculate(a,t),d=s+l;if(d>n)break;o=o+a,s=d}return o},Om=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,km=e=>{if((Am()||Sm())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var xo=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;zm()||Hm(!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?dt(t,e):e.width,r.text=Ft(e.originalText,go(e),o));let s=Ve(r.text,go(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=bi(t,e),l=dt(t,e);if(!H(t)&&s.height>a){let m=Rr(s.height,t.type);n.mutateElement(t,{height:m}),Ka(t.id,m)}if(s.width>l){let m=Rr(s.width,t.type);n.mutateElement(t,{width:m})}let d={...e,...r},{x:c,y:u}=wi(t,d,i);r.x=c,r.y=u}n.mutateElement(e,r)},Cn=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!Rt(e))return;Qa(e.id);let s=V(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=dt(e,s),u=bi(e,s),m=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=Ft(s.originalText,go(s),c));let p=Ve(a,go(s),s.lineHeight);l=p.height,d=p.width}if(l>u){m=Rr(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,wi(e,s,o))}},wi=(e,t,n)=>{if(H(e))return C.getBoundTextElementPosition(e,t,n);let i=Nr(e),o=bi(e,t),r=dt(e,t),s,a;t.verticalAlign===ol.TOP?a=i.y:t.verticalAlign===ol.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===il.LEFT?s=i.x:t.textAlign===il.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=rl(i.x+r/2,i.y+o/2),c=rl(s+t.width/2,a+t.height/2),[u,m]=_m(c,d,l);return{x:u-t.width/2,y:m-t.height/2}}return{x:s,y:a}},Rt=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,V=(e,t)=>{if(!e)return null;let n=Rt(e);return n&&t.get(n)||null},Me=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,Eb=(e,t,n)=>{if(!H(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(C.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=C.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=C.getEditorMidPoints(e,n,t)[o];return r||(r=C.getSegmentMidPoint(e,o+1)),{x:r[0],y:r[1]}},Nr=e=>{let t=wt,n=wt;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},gb=(e,t)=>H(t)?0:t?t.angle:e.angle,xb=(e,t,n)=>{if(H(e))return C.getBoundTextElementPosition(e,t,n)},wb=(e,t)=>e.some(n=>{if(ce(n)){let i=Me(n,t);return!H(i)}return!1}),bb=(e,t)=>e.some(n=>{if(ce(n)){let i=Me(n,t);return!H(i)}return Q(n)}),Um=new Set(["rectangle","ellipse","diamond","arrow"]),yb=e=>Um.has(e.type),Rr=(e,t)=>{e=Math.ceil(e);let n=wt*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},dt=(e,t)=>{let{width:n}=e;if(H(e)){let i=(t?.fontSize??Nm)*Fm;return Math.max(Rm*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-wt*2:e.type==="diamond"?Math.round(n/2)-wt*2:n-wt*2},bi=(e,t)=>{let{height:n}=e;return H(e)?n-wt*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-wt*2:e.type==="diamond"?Math.round(n/2)-wt*2:n-wt*2},Pb=(e,t=`
8
8
 
9
- `)=>e.reduce((i,o)=>(J(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as kr,distanceToLineSegment as Fr,pointRotateRads as Rr}from"@excalidraw/math";import{ellipse as zm,ellipseDistanceFromPoint as Hm}from"@excalidraw/math/ellipse";var on=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return _m(e,t,n);case"diamond":return Um(e,t,n);case"ellipse":return Wm(e,t,n);case"line":case"arrow":case"freedraw":return Ym(e,n)}},_m=(e,t,n)=>{let i=re(e,t),o=Rr(n,i,-e.angle),[r,s]=Jt(e);return Math.min(...r.map(a=>Fr(o,a)),...s.map(a=>kr(a,o)).filter(a=>a!==null))},Um=(e,t,n)=>{let i=re(e,t),o=Rr(n,i,-e.angle),[r,s]=en(e);return Math.min(...r.map(a=>Fr(o,a)),...s.map(a=>kr(a,o)).filter(a=>a!==null))},Wm=(e,t,n)=>{let i=re(e,t);return Hm(Rr(n,i,-e.angle),zm(i,e.width/2,e.height/2))},Ym=(e,t)=>{let[n,i]=so(e);return Math.min(...n.map(o=>Fr(t,o)),...i.map(o=>kr(o,t)))};var Eo=e=>{if(e.type==="arrow")return!1;let t=!ll(e.backgroundColor)||ht(e)||oo(e)||J(e);return e.type==="line"?t&&Dn(e.points):e.type==="freedraw"?t&&Dn(e.points):t||xe(e)},Nr=null,nl=null,il=1/0,ol=!1,rl=!1,Et=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(Nr&&ul(e,Nr)&&il<=n&&r===rl){let u=nl?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return ol}let s=o?ho(me(o.x-n,o.y-n),e,me(o.x+o.width+n,o.y+o.height+n)):!1,a=he(t,i,!0);if(!ho(me(a[0]-n,a[1]-n),$e(e,xt(a),-t.angle),me(a[2]+n,a[3]+n))&&!s)return!1;let c=(r||Eo(t))&&Gt(e,t,i)||sl(e,t,i,n)||s;return Nr=e,nl=new WeakRef(t),il=n,rl=r,ol=c,c},Km=(e,t,n,i=0)=>{let[o,r,s,a]=he(t,n);return o-=i,r-=i,s+=i,a+=i,ho(me(o,r),e,me(s,a))},Fb=(e,t)=>!Et(e)&&!Qm(e.point,e.element,t)&&Km(e.point,e.element,t),Qm=(e,t,n)=>{let i=$(t,n);if(!i)return!1;let o=K(t)?{...i,...L.getBoundTextElementPosition(t,i,n)}:i;return Gt(e,o,n)},ml=(e,[t,n],i,o=0)=>{let r=me(t,n),s=!q(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=he(e,i);if(!bi(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&q(m)){let p=he(m,i);if(!sn(r,p))return!1}}let c=rn(e,i,wi(re(e,i),r)),u=on(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},go=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(al(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),de(s,!1)&&ml(s,e,n,i)&&(o.push(s),!ll(s.backgroundColor)))break}return o},Rt=(e,t,n,i)=>{let o=go(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()},pl=(e,t,n,i,o)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];al(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),de(l,!1)&&ml(l,e,i,o)&&r.push(l)}if(!r||r.length===0)return null;if(r.length===1)return r[0];let s=r.filter(a=>on(a,i,e)<=De(a,t)||Gt(e,a,i));return s.length===0?null:s[0]},rn=(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(!bi(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return ep(e,t,n,i,o);case"diamond":return tp(e,t,n,i,o);case"ellipse":return np(e,t,n,i);case"line":case"freedraw":case"arrow":return Jm(e,n,o)}},fl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=xo(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(!bi(a,l))continue;let d=dl(s,t);if(d.length>0){for(let c of d)n.push($e(c,i,o));if(r)return n}}return n},hl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=cl(s,t);if(a&&(n.push($e(a,i,o)),r))return n}return n},Jm=(e,t,n=!1)=>{let[i,o]=so(e),r=[];for(let s of i){let a=cl(s,t);if(a&&(r.push(a),n))return r}for(let s of o){let a=xo(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(!bi(a,l))continue;let d=dl(s,t);if(d.length>0&&(r.push(...d),n))return r}return r},ep=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=$e(n[0],r,-e.angle),a=$e(n[1],r,-e.angle),l=wi(s,a),[d,c]=Jt(e,i),u=[];return hl(d,l,u,r,e.angle,o),o&&u.length>0||fl(c,l,u,r,e.angle,o),u},tp=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=$e(n[0],r,-e.angle),a=$e(n[1],r,-e.angle),l=wi(s,a),[d,c]=en(e,i),u=[];return hl(d,l,u,r,e.angle,o),o&&u.length>0||fl(c,l,u,r,e.angle,o),u},np=(e,t,n,i=0)=>{let o=re(e,t),r=$e(n[0],o,-e.angle),s=$e(n[1],o,-e.angle);return qm(Zm(o,e.width/2+i,e.height/2+i),wi(r,s)).map(a=>$e(a,o,e.angle))},sl=(e,t,n,i=1)=>on(t,n,e)<=i,Gt=(e,t,n)=>{if((K(t)||Ie(t))&&!Dn(t.points))return!1;let[i,o,r,s]=he(t,n);if(!ho(me(i,o),e,me(r,s)))return!1;let a=me((i+r)/2,(o+s)/2),l=jm(Vm($m(Xm(e,a,.1)),Math.max(t.width,t.height)*2),a),d=wi(e,l);return rn(t,n,d).filter((u,m,p)=>p.findIndex(f=>ul(f,u))===m).length%2===1},zr=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:m}=s,p=re(s,n);if(s.type==="diamond"){let[h,E,g,x,w,y,b,I]=Hn(s);return[me(l+h,d+E-a),me(l+g+a,d+x),me(l+w,d+y+a),me(l+b-a,d+I)].map(T=>$e(T,p,m))}if(s.type==="ellipse"){let h=l+c/2,E=d+u/2,g=c/2,x=u/2;return[me(h,E-x-a),me(h+g+a,E),me(h,E+x+a),me(h-g-a,E)].map(y=>$e(y,p,m))}return[me(l-a,d-a),me(l+c+a,d-a),me(l+c+a,d+u+a),me(l-a,d+u+a)].map(h=>$e(h,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Gt(s,t,n))};P();import{invariant as El,isDevEnv as ip,isTestEnv as op}from"@excalidraw/common";import{pointFrom as an,pointFromVector as wo,pointRotateRads as bo,pointScaleFromOrigin as yo,pointsEqual as rp,triangleIncludesPoint as Hr,vectorCross as Re,vectorFromPoint as Q,vectorScale as Po}from"@excalidraw/math";var fe=[1,0],we=[0,1],ze=[-1,0],Ve=[0,-1],Nt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?fe:t<=-o?ze:n>i?we:Ve},Ne=(e,t)=>Nt(Q(e,t)),lt=(e,t)=>He(Ne(e,t)),pe=(e,t)=>e[0]===t[0]&&e[1]===t[1],He=e=>pe(e,fe)||pe(e,ze),Ub=e=>!He(e),sp=(e,t,n)=>{let i=xt(t);(ip()||op())&&(El(e.width>0&&e.height>0,"Diamond element has no width or height"),El(!rp(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=wo(Po(Q(bo(an(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=wo(Po(Q(bo(an(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=wo(Po(Q(bo(an(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=wo(Po(Q(bo(an(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Re(Q(n,r),Q(r,s))<=0&&Re(Q(n,r),Q(r,l))>0)return Ne(r,i);if(Re(Q(n,s),Q(s,a))<=0&&Re(Q(n,s),Q(s,r))>0)return Ne(s,i);if(Re(Q(n,a),Q(a,l))<=0&&Re(Q(n,a),Q(a,s))>0)return Ne(a,i);if(Re(Q(n,l),Q(l,r))<=0&&Re(Q(n,l),Q(l,a))>0)return Ne(l,i);if(Re(Q(n,i),Q(r,i))<=0&&Re(Q(n,i),Q(s,i))>0){let c=e.width>e.height?r:s;return Ne(c,i)}else if(Re(Q(n,i),Q(s,i))<=0&&Re(Q(n,i),Q(a,i))>0){let c=e.width>e.height?a:s;return Ne(c,i)}else if(Re(Q(n,i),Q(a,i))<=0&&Re(Q(n,i),Q(l,i))>0){let c=e.width>e.height?a:l;return Ne(c,i)}let d=e.width>e.height?r:l;return Ne(d,i)},yi=(e,t,n)=>{let o=xt(t);if(e.type==="diamond")return sp(e,t,n);let r=yo(an(t[0],t[1]),o,2),s=yo(an(t[2],t[1]),o,2),a=yo(an(t[0],t[3]),o,2),l=yo(an(t[2],t[3]),o,2);return Hr([r,s,o],n)?Ve:Hr([s,l,o],n)?fe:Hr([l,a,o],n)?we:ze},_r=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Sp,randomInteger as Qr,getUpdatedTimestamp as Jr}from"@excalidraw/common";P();import{clamp as Io,pointDistance as Yr,pointFrom as W,pointScaleFromOrigin as ap,pointsEqual as Ii,pointTranslate as Wr,vector as wt,vectorCross as So,vectorFromPoint as jr,vectorScale as lp}from"@excalidraw/math";import{BinaryHeap as dp,invariant as Un,isAnyTrue as cp,getSizeFromPoints as gl,isDevEnv as up,arrayToMap as mp}from"@excalidraw/common";var Xr=1,te=40,pp=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>W(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=Ne(s,l[a-1]),c=Ne(l[a-1],l[a-2]);if(pe(d,c)){let u=n?.findIndex(p=>p.index===a-1)??-1,m=n?.findIndex(p=>p.index===a)??-1;m!==-1&&(n[m].start=W(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(Yr(l[a-2],l[a-1])<Xr){let d=n?.findIndex(m=>m.index===a-2)??-1,c=n?.findIndex(m=>m.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),o.splice(-2,2),n.forEach(m=>{m.index>a-2&&(m.index-=2)});let u=lt(s,l[a-1]);return o.push(W(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?zt(Zr(qr(Vr(e,$r(e,t,o.map(s=>W(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(up()&&Un(Sl(o),"Invalid elbow points with fixed segments"),zt(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}},fp=(e,t,n)=>{let i=t.map(M=>M.index),r=(e.fixedSegments?.map(M=>M.index)??[]).findIndex(M=>!i.includes(M));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,m=l?null:e.endBinding,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...w}=$r({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[W(0,0),W(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:y}=zt(Zr(qr(Vr(e,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...w})??[])),t,null,null);if(!y||y.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let b=[];if(a)for(let M=0;M<a.index;M++)b.push(W(e.x+e.points[M][0],e.y+e.points[M][1]));if(y.forEach(M=>{b.push(W(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++)b.push(W(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+(y.length-1)}:M),T=b.flatMap((M,R)=>{let C=b[R-1],F=b[R+1];if(C&&F){let B=Ne(M,C),Y=Ne(F,M);if(pe(B,Y))return S.forEach(O=>{O.index>R&&(O.index-=1)}),[];if(pe(B,_r(Y)))return S.forEach(O=>{O.index>R&&(O.index+=1)}),[M,M]}return[M]});return zt(T,S,!1,!1)},hp=(e,t,n,i,o,r)=>{let s=t.map((b,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==b.index||(b.start[0]!==e.fixedSegments[I].start[0]&&b.end[0]!==e.fixedSegments[I].end[0])!=(b.start[1]!==e.fixedSegments[I].start[1]&&b.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(b=>b!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(b=>b.index===1)??-1,l=e.fixedSegments?.findIndex(b=>b.index===e.points.length-1)??-1,d=Yr(t[s].start,t[s].end),c=d<te+5;if(a===-1&&t[s].index===1&&o){let b=He(n),S=(b?pe(n,fe):pe(n,we))?c?d/2:te:c?-d/2:-te;t[s].start=W(t[s].start[0]+(b?S:0),t[s].start[1]+(b?0:S))}if(l===-1&&t[s].index===e.points.length-1&&r){let b=He(i),S=(b?pe(i,fe):pe(i,we))?c?d/2:te:c?-d/2:-te;t[s].end=W(t[s].end[0]+(b?S:0),t[s].end[1]+(b?0:S))}let u=t.map(b=>({...b,start:W(e.x+b.start[0],e.y+b.start[1]),end:W(e.x+b.end[0],e.y+b.end[1])})),m=e.points.map((b,I)=>W(e.x+b[0],e.y+b[1])),p=u[s].index-1,f=u[s].index,h=u[s].start,E=u[s].end,g=m[p-1]&&!Ii(m[p],m[p-1])?lt(m[p-1],m[p]):void 0,x=m[f+1]&&!Ii(m[f],m[f+1])?lt(m[f+1],m[f]):void 0;if(g!==void 0){let b=g?1:0;m[p-1][b]=h[b]}if(m[p]=h,m[f]=E,x!==void 0){let b=x?1:0;m[f+1][b]=E[b]}let w=u.findIndex(b=>b.index===p);if(w!==-1){let b=lt(u[w].end,u[w].start)?1:0;u[w].start[b]=h[b],u[w].end=h}let y=u.findIndex(b=>b.index===f+1);if(y!==-1){let b=lt(u[y].end,u[y].start)?1:0;u[y].end[b]=E[b],u[y].start=E}if(a===-1&&p===0){let b=o?He(n):lt(m[1],m[0]);m.unshift(W(b?h[0]:e.x+e.points[0][0],b?e.y+e.points[0][1]:h[1])),o&&m.unshift(W(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 b=He(i);m.push(W(b?E[0]:e.x+e.points[e.points.length-1][0],b?e.y+e.points[e.points.length-1][1]:E[1])),r&&m.push(W(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return zt(m,u.map(b=>({...b,start:W(b.start[0]-e.x,b.start[1]-e.y),end:W(b.end[0]-e.x,b.end[1]-e.y)})),!1,!1)},Ep=(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?W(e.x+E[0],e.y+E[1]):g===t.length-1?W(e.x+E[0],e.y+E[1]):W(e.x+e.points[g][0],e.y+e.points[g][1])),m=n.map(E=>({...E,start:W(e.x+(E.start[0]-t[0][0]),e.y+(E.start[1]-t[0][1])),end:W(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=He(i),w=He(Nt(jr(E,g)));if(a&&x===w){let y=x?pe(i,fe):pe(i,we);if(p.unshift(W(w?r[0]+(y?te:-te):g[0],w?g[1]:r[1]+(y?te:-te))),p.unshift(W(x?r[0]+(y?te:-te):r[0],x?r[1]:r[1]+(y?te:-te))),!d){d=!0;for(let b of m)b.index>1&&(b.index+=1)}}else if(p.unshift(W(w?r[0]:E[0],w?E[1]:r[1])),d){d=!1;for(let y of m)y.index>1&&(y.index-=1)}p.unshift(r)}{let E=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!E||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=He(o),w=lt(g,E);if(l&&x===w){let y=x?pe(o,fe):pe(o,we);p.push(W(w?s[0]+(y?te:-te):g[0],w?g[1]:s[1]+(y?te:-te))),p.push(W(x?s[0]+(y?te:-te):s[0],x?s[1]:s[1]+(y?te:-te))),c||(c=!0)}else p.push(W(w?s[0]:E[0],w?E[1]:s[1])),c&&(c=!1)}return p.push(s),zt(p,m.map(({index:E})=>({index:E,start:p[E-1],end:p[E]})).map(E=>({...E,start:W(E.start[0]-r[0],E.start[1]-r[1]),end:W(E.end[0]-r[0],E.end[1]-r[1])})),d,c)},ln=1e6,Wn=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};v.PROD||(Un(!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)"),Un(!e.fixedSegments||e.fixedSegments.map(b=>b.start[0]===b.end[0]||b.start[1]===b.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Un(!n.fixedSegments||n.fixedSegments.map(b=>b.start[0]===b.end[0]||b.start[1]===b.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Un(e.points.slice(1).map((b,I)=>b[0]===e.points[I][0]||b[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Un(n.fixedSegments?.find(b=>b.index===1&&Ii(b.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(b=>b.index===(n.points??e.points).length-1&&Ii(b.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((b,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:b):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&&Mo(d.elementId,t),m=c&&Mo(c.elementId,t),p=Sl(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 zt(r.map(b=>W(e.x+b[0],e.y+b[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:w,...y}=$r({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?zt(r.map(b=>W(e.x+b[0],e.y+b[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?pp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((b,I)=>Ii(b,e.points[I]??W(1/0,1/0)))&&p?{}:o.length===0?zt(Zr(qr(Vr(e,{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:w,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?fp(e,o,t):n.points?n.points&&n.fixedSegments?n:Ep(e,r,o,f,h,E,g,x,w):hp(e,o,f,h,x,w)},$r=(e,t,n,i)=>{let o=Wr(n[0],wt(e.x,e.y)),r=Wr(n[n.length-1],wt(e.x,e.y)),s=null,a=null;if(i?.isDragging){let b=Array.from(t.values());s=yl(o,t,b,i?.zoom)||null,a=yl(r,t,b,i?.zoom)||null}else s=e.startBinding&&Mo(e.startBinding.elementId,t)||null,a=e.endBinding&&Mo(e.endBinding.elementId,t)||null;let l=wl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging),d=wl({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging),c=bl(l,d,s,o,t,i?.zoom),u=bl(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?et(s,t,dn(c,e.startArrowhead?De(s,{elbowed:!0})*6:De(s,{elbowed:!0})*2,1)):m,h=a?et(a,t,dn(u,e.endArrowhead?De(a,{elbowed:!0})*6:De(a,{elbowed:!0})*2,1)):p,E=sn(l,a?et(a,t,dn(u,te,te)):p)||sn(d,s?et(s,t,dn(c,te,te)):m),g=Il(E?[m,p]:[f,h]),x=wp(E?m:f,E?p:h,g,E?dn(c,!s&&!a?0:te,0):dn(c,!s&&!a?0:te-(e.startArrowhead?Cn*6:Cn*2),te),E?dn(u,!s&&!a?0:te,0):dn(u,!s&&!a?0:te-(e.endArrowhead?Cn*6:Cn*2),te),E,s&&et(s,t),a&&et(a,t)),w=xl(x[0],c,l),y=xl(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:w,startGlobalPoint:l,startHeading:c,endDonglePosition:y,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:E,startElementBounds:f,endElementBounds:h}},Vr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=bp(n,i||o,r,s||a,l,d),m=i&&Ao(i,u),p=s&&Ao(s,u),f=Ao(a,u);f&&c&&(f.closed=!0);let h=Ao(o,u);h&&e.startBinding&&(h.closed=!0);let E=m&&p&&(sn(m.pos,n[1])||sn(p.pos,n[0])),g=gp(m||h,p||f,u,r||fe,l||fe,E?[]:n);if(g){let x=g.map(w=>[w.pos[0],w.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},dn=(e,t,n)=>{switch(e){case Ve:return[t,n,n,n];case fe:return[n,t,n,n];case we:return[n,n,t,n]}return[n,n,n,t]},gp=(e,t,n,i,o,r)=>{let s=Ur(e.pos,t.pos),a=new dp(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return xp(e,l);l.closed=!0;let d=Pp(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=ap(u.pos,l.pos,.5);if(cp(...r.map(y=>sn(m,y))))continue;let p=Ip(c),f=l.parent?Nt(jr(l.pos,l.parent.pos)):i,h=_r(f);if(pe(h,p)||Pl(e.addr,u.addr)&&pe(p,i)||Pl(t.addr,u.addr)&&pe(p,o))continue;let g=f!==p,x=l.g+Ur(u.pos,l.pos)+(g?Math.pow(s,3):0),w=u.visited;if(!w||x<u.g){let y=yp(u,t,p,o);u.visited=!0,u.parent=l,u.h=Ur(t.pos,u.pos)+y*Math.pow(s,2),u.g=x,u.f=u.g+u.h,w?a.rescoreElement(u):a.push(u)}}}return null},xp=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},Ur=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),wp=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,m,p]=i??[0,0,0,0],[f,h,E,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-p):(l[0]+d[2])/2:e[0]>t[0]?e[0]-p:n[0]-p,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+m):(l[3]+d[1])/2:e[3]<t[3]?e[3]+m:n[3]+m],w=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-f):(d[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+h):(d[2]+l[0])/2:t[2]<e[2]?t[2]+h:n[2]+h,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+E):(d[3]+l[1])/2:t[3]<e[3]?t[3]+E:n[3]+E],y=Il([x,w]);if(!r&&x[2]-x[0]+w[2]-w[0]>y[2]-y[0]+1e-11&&x[3]-x[1]+w[3]-w[1]>y[3]-y[1]+1e-11){let[b,I]=[(w[0]+w[2])/2,(w[1]+w[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let S=x[2]+(w[0]-x[2])/2,T=w[3]+(x[1]-w[3])/2;return So(wt(e[2]-b,e[1]-I),wt(e[0]-b,e[3]-I))>0?[[x[0],x[1],S,x[3]],[S,w[1],w[2],w[3]]]:[[x[0],T,x[2],x[3]],[w[0],w[1],w[2],T]]}else if(e[2]<t[0]&&e[3]<t[1]){let S=x[2]+(w[0]-x[2])/2,T=x[3]+(w[1]-x[3])/2;return So(wt(e[0]-b,e[1]-I),wt(e[2]-b,e[3]-I))>0?[[x[0],x[1],x[2],T],[w[0],T,w[2],w[3]]]:[[x[0],x[1],S,x[3]],[S,w[1],w[2],w[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let S=w[2]+(x[0]-w[2])/2,T=x[3]+(w[1]-x[3])/2;return So(wt(e[2]-b,e[1]-I),wt(e[0]-b,e[3]-I))>0?[[S,x[1],x[2],x[3]],[w[0],w[1],S,w[3]]]:[[x[0],x[1],x[2],T],[w[0],T,w[2],w[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let S=w[2]+(x[0]-w[2])/2,T=w[3]+(x[1]-w[3])/2;return So(wt(e[0]-b,e[1]-I),wt(e[2]-b,e[3]-I))>0?[[S,x[1],x[2],x[3]],[w[0],w[1],S,w[3]]]:[[x[0],T,x[2],x[3]],[w[0],w[1],w[2],T]]}}return[x,w]},bp=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===ze||n===fe?a.add(t[1]):s.add(t[0]),o===ze||o===fe?a.add(i[1]):s.add(i[0]),e.forEach(c=>{s.add(c[0]),s.add(c[2]),a.add(c[1]),a.add(c[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((c,u)=>c-u),d=Array.from(s).sort((c,u)=>c-u);return{row:l.length,col:d.length,data:l.flatMap((c,u)=>d.map((m,p)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[p,u],pos:[m,c]})))}},xl=(e,t,n)=>{switch(t){case Ve:return W(n[0],e[1]);case fe:return W(e[2],n[1]);case we:return W(n[0],e[3])}return W(e[0],n[1])},yp=(e,t,n,i)=>{if(i===fe)switch(n){case fe:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case Ve: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 ze:return e.pos[1]===t.pos[1]?4:2}else if(i===ze)switch(n){case fe:return e.pos[1]===t.pos[1]?4:2;case Ve: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 ze:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===Ve)switch(n){case fe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Ve: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 ze:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===we)switch(n){case fe:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case Ve: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 ze:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Pp=([e,t],n)=>[Pi([e,t-1],n),Pi([e+1,t],n),Pi([e,t+1],n),Pi([e-1,t],n)],Pi=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Ao=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=Pi([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Il=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]))],Mo=(e,t)=>{let n=t.get(e);return n&&de(n)?n:null},zt=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>Wr(a,lp(jr(e[0]),-1)));return(o<-ln||o>ln||r<-ln||r>ln||o+s[s.length-1][0]<-ln||r+s[s.length-1][0]>ln||o+s[s.length-1][1]<-ln||r+s[s.length-1][1]>ln)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...gl(s)}),s=s.map(([a,l])=>W(Io(a,-1e6,1e6),Io(l,-1e6,1e6))),{points:s,x:Io(o,-1e6,1e6),y:Io(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...gl(s),startIsSpecial:n,endIsSpecial:i}},Zr=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},qr=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Yr(i,t)>Xr}):e,Ip=e=>{switch(e){case 0:return Ve;case 1:return fe;case 2:return we}return ze},wl=(e,t,n,i,o,r,s)=>s?o&&r?Kr(e,o,t,r):i:o?Fe(n||[0,0],o,r??mp([o])):i,bl=(e,t,n,i,o,r)=>Al(e,t,n,n&&et(n,o,Array(4).fill(on(n,o,e))),i,o,r),yl=(e,t,n,i)=>Rt(e,n,t,st(i)),Pl=(e,t)=>e[0]===t[0]&&e[1]===t[1],Sl=(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,fileId:a}=n;_(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u")?n={...n,angle:0,...Wn({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Sp(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")&&Ze.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Qr(),e.updated=Jr()),e},Be=(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??Qr(),updated:Jr()}},Ml=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Qr(),e.updated=Jr(),e);var Cl=5,Cn=5,Bp=10,Mi=10/1.5,De=(e,t)=>(t.elbowed?Cn:Cl)+e.strokeWidth/2,st=e=>{let t=Math.max(Cl,15),n=e?.value&&e.value<1?e.value:1;return ts(t/(n*1.5),t,t*2)},by=e=>!e[Ap.CTRL_OR_CMD],bt=e=>e.isBindingEnabled,Lp=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=ns(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0});if(Tl(e,a,"start",o),Tl(e,l,"end",o),a.focusPoint||l.focusPoint){let d=new Map;a.focusPoint&&d.set(0,{point:dt(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&d.set(e.points.length-1,{point:dt(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),L.movePoints(e,o,d)}return{start:a,end:l}},Tl=(e,{mode:t,element:n,focusPoint:i},o,r)=>{t===null?Te(e,o,r):t!==void 0&&yt(e,n,t,o,r,i)},Gl=(e,t,n,i,o)=>{tt(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;tt(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=L.getPointGlobalCoordinates(e,a,n),d=Rt(l,i,n,st(o)),c=d?{element:d,mode:"orbit",focusPoint:L.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},Cp=(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=L.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),h=Rt(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(go(f,i,n).find(w=>w.id===g.elementId)){let w=n.get(e.startBinding.elementId);return tt(w,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:w.id!==h.id?"orbit":"inside",element:w,focusPoint:E??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);tt(g,"Other element must be in the elements map");let w={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:g,focusPoint:c?re(g,n):E??ne(e.x,e.y)},y=h&&zr(g,h,n),b;if(h){let I=d==="inside"||d==="skip";b={mode:I&&!y?"inside":"orbit",element:h,focusPoint:f}}else b={mode:null};return{start:p?{mode:void 0}:w,end:b}}if(!e.startBinding)return h?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:h,focusPoint:f}:m={mode:null},{start:u,end:m}}tt(!1,"New arrow creation should not reach here")},vl=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=Rt(e,o,i),m=n?go(e,o,i).some(E=>E.id===n.elementId):!1,p=n?i.get(n.elementId):null,f=m&&p?Tp(p.backgroundColor):!1,h=u&&p&&zr(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}},ns=(e,t,n,i,o,r,s,a)=>Mp("COMPLEX_BINDINGS")?Gp(e,t,o,r,s,a):Ol(e,t,n,i,o,r,s,a),Ol=(e,t,n,i,o,r,s,a)=>{let d=e.points.length-1,c=t.has(0),u=t.has(d),m={mode:void 0},p={mode:void 0};if(tt(e.points.length>1,"Do not attempt to bind linear elements with a single point"),!c&&!u)return{start:m,end:p};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!bt(s))return m=c?{mode:null}:m,p=u?{mode:null}:p,{start:m,end:p};if(_(e))return Gl(e,t,o,r,a?.zoom);let f=c?e.endBinding:e.startBinding,h=t.get(c?0:d)?.point;tt(h,`Local point must be defined for ${c?"start":"end"} dragging`);let E=L.getPointGlobalCoordinates(e,h,o),g=Rt(E,r,o,st(s.zoom)),x=g&&(a?.angleLocked?Gt(ne(n,i),g,o):Gt(E,g,o)),w=f?o.get(f.elementId):void 0,y=f&&w&&Fe(f.fixedPoint,w,o),b=w&&y&&Et({point:y,element:w,elementsMap:o,threshold:0,overrideShouldTestInside:!0});if(f&&f.elementId===g?.id)return tt(!a?.newArrow||s.selectedLinearElement?.initialState.origin,"appState.selectedLinearElement.initialState.origin must be defined for new arrows"),{start:{mode:"inside",element:g,focusPoint:c?E:a?.newArrow?s.selectedLinearElement.initialState.origin:L.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:g,focusPoint:u?E:L.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:m,end:u?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:p};let I=g?x?{mode:"inside",element:g,focusPoint:E}:{mode:"orbit",element:g,focusPoint:Tr(e,E,g,c?"start":"end",o,s.zoom)||E}:{mode:null},S=L.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),T=y&&w&&Et({point:E,element:w,elementsMap:o,threshold:st(s.zoom),overrideShouldTestInside:!0}),R=(a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:f?.mode==="inside")?{mode:void 0}:w&&!b&&!T&&s.selectedLinearElement?.initialState.altFocusPoint?{mode:"orbit",element:w,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&w?{mode:"orbit",element:w,focusPoint:Tr(e,S,w,c?"end":"start",o,s.zoom)||S}:{mode:void 0};return{start:c?I:R,end:u?I:R}},Gp=(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(tt(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(!bt(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(_(e))return Gl(e,t,n,i);if(r?.newArrow){let{start:p,end:f}=Cp(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;tt(p,"Local point must be defined for start dragging");let f=L.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=vl(f,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:h,end:E}}if(c){let p=t.get(l)?.point;tt(p,"Local point must be defined for end dragging");let f=L.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=vl(f,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:E,end:h}}return{start:u,end:m}},yy=(e,t,n)=>{e.forEach(i=>{Lp(i,new Map,1/0,1/0,t,n)})},yt=(e,t,n,i,o,r)=>{let s=o.getNonDeletedElementsMap(),a;_(e)?a={elementId:t.id,mode:"orbit",...zp(e,t,i,s)}:a={elementId:t.id,mode:n,...Yn(e,t,i,s,r)},o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:a}),Ll(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Te=(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},ve=(e,t,n)=>{if(!de(e))return;let{simultaneouslyUpdated:i}=n??{},o=kp(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),Bo(r,e,a=>{if(!H(a)||a.isDeleted||!Op(a,e))return;let l=a.startBinding?r.get(a.startBinding.elementId):null,d=a.endBinding?l?.id===a.endBinding.elementId?l:r.get(a.endBinding.elementId):null;if(o.has(a.id))return;let c=Lo(r,a,(m,p)=>{if(m&&de(m)&&(p==="startBinding"||p==="endBinding")&&(e.id===a[p]?.elementId||e.id===a[p==="startBinding"?"endBinding":"startBinding"]?.elementId)){let f=dt(a,p,a[p],m,r);if(f)return[p==="startBinding"?0:a.points.length-1,{point:f}]}return null}).filter(m=>m!==null);L.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=$(a,r);u&&!u.isDeleted&&Ln(a,t,!1)})},Dl=(e,t,n,i,o)=>{tt(!_(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=L.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&Et({element:s,point:a,elementsMap:n,threshold:st(o.zoom)}),d=t==="startBinding"?"start":"end";if(Te(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],m=Ol(e,new Map([[c,{point:u}]]),a[0],a[1],n,i.getNonDeletedElements(),o);m[d]&&m[d].element?.id===s.id&&m[d].mode&&yt(e,s,m[d].mode,d,i,m[d].focusPoint)}},Py=(e,t,n,i)=>{if(H(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&Dl(e,"startBinding",o,t,n),e.endBinding&&Dl(e,"endBinding",o,t,n)}else ve(e,t,{...i,changedElements:new Map([[e.id,e]])})},Op=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,kp=e=>new Set((e||[]).map(t=>t.id)),Al=(e,t,n,i,o,r,s)=>{let a=Nt(Si(t,e));return!n||!i?a:Fp(o,n,r,s)?yi(n,i,e):Nt(Si(e,re(n,r)))},Fp=(e,t,n,i)=>{let o=on(t,n,e),r=st(i);return o>r?null:o},Kr=(e,t,n,i,o)=>{let r=_(e),s=L.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return s;let a=Fa(t)&&r?Rp(e,t,i,s):s,l=o&&!r?o[1]:L.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),d=De(t,e),c=et(t,i),u=xt(c),m=null;if(r){let p=He(yi(t,c,s)),h=is(t,i,a,.05,e)||s,E=ne(p?u[0]:h[0],p?h[1]:u[1]),g=o??Do(E,To(vo(es(Si(h,E)),Math.max(t.width,t.height)*2),E));if(m=rn(t,i,g,d).sort(Ht)[0],!m){let x=ne(p?h[0]:u[0],p?u[1]:h[1]),w=Do(x,To(vo(es(Si(h,x)),Math.max(t.width,t.height)*2),x));m=rn(t,i,w,Cn).sort(Ht)[0]}}else{let p=o;if(!p){let f=vo(es(Si(a,l)),cn(a,l)+Math.max(t.width,t.height)+d*2);p=o??Do(To(f,l),To(vo(f,-1),l))}m=cn(a,l)<1?a:rn(t,i,p,d).sort((f,h)=>Ht(f,l)-Ht(h,l))[0]}return!m||Ht(a,m)<vp?a:m},Rp=(e,t,n,i)=>{let o=re(t,n),r=se(i,o,-t.angle),s=De(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?se(ne(t.x-s,t.y),o,t.angle):se(ne(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?se(ne(t.x,t.y+t.height+s),o,t.angle):se(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?se(ne(t.x+t.width,t.y+t.height+s),o,t.angle):se(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?se(ne(t.x+t.width,t.y-s),o,t.angle):se(ne(t.x+t.width+s,t.y),o,t.angle):i},is=(e,t,n,i=.05,o)=>{let{x:r,y:s,width:a,height:l,angle:d}=e,c=re(e,t,-.1,-.1),u=se(n,c,-d),m=o?De(e,o):0,p=ts(i*l,5,80),f=ts(i*a,5,80);if(!(cn(c,u)<m)){if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return se(ne(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return se(ne(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return se(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 se(ne(c[0],s+l+m),c,d);if(e.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),w=ne(r+3*a/4+h,s+3*l/4+h);if(cn(E,u)<Math.max(f,p))return se(E,c,d);if(cn(g,u)<Math.max(f,p))return se(g,c,d);if(cn(x,u)<Math.max(f,p))return se(x,c,d);if(cn(w,u)<Math.max(f,p))return se(w,c,d)}}},Np=(e,t,n)=>{let i=e[t];if(!i)return{element:null,fixedPoint:null,focusPoint:null,binding:i,mode:null};let o=n.get(i.elementId);return{element:o,fixedPoint:i.fixedPoint,focusPoint:Fe(tn(i.fixedPoint),o,n),binding:i,mode:i.mode}},Bl=e=>e.width*e.height,dt=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||Dp(e.points[e.points.length-1],ne(0,0)))return null;let s=Fe(tn(n.fixedPoint),i,o);if(n.mode==="inside")return L.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=Np(e,t==="startBinding"?"endBinding":"startBinding",o),d=L.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?-1:0,o),c=l||d,u=c&&Do(s,c),m=a&&u&&rn(a,o,u,De(a,e)).sort((w,y)=>Ht(w,s)-Ht(y,s))[0],p=u&&rn(i,o,u,De(i,e)).sort((w,y)=>Ht(w,c)-Ht(y,c))[0],f=e.startArrowhead!==null,h=e.endArrowhead!==null,E=!f&&!h||t==="startBinding"&&f||t==="endBinding"&&h?s:p||s;if(a&&p&&!r&&Bl(a)<Bl(i)*2&&Et({element:a,point:p,elementsMap:o,threshold:De(a,e),overrideShouldTestInside:!0}))return L.createPointAt(e,o,E[0],E[1],null);let x=cn(a&&(m||l)||d,p||s)<=Bp;return a?x?L.createPointAt(e,o,E?.[0]||s[0],E?.[1]||s[1],null):L.createPointAt(e,o,p?.[0]||s[0],p?.[1]||s[1],null):L.createPointAt(e,o,x?s[0]:p?.[0]??s[0],x?s[1]:p?.[1]??s[1],null)},zp=(e,t,n,i)=>{let o=[t.x,t.y,t.x+t.width,t.y+t.height],r=Kr(e,t,n,i),s=ne(o[0]+(o[2]-o[0])/2,o[1]+(o[3]-o[1])/2),a=se(r,s,-t.angle);return{fixedPoint:tn([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},Yn=(e,t,n,i,o)=>{let r=o||L.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=re(t,i),a=se(r,s,-t.angle),l=(a[0]-t.x)/t.width,d=(a[1]-t.y)/t.height;return{fixedPoint:tn([l,d])}},kl=(e,t,n)=>{for(let i of e){if("boundElements"in i&&i.boundElements&&Object.assign(i,{boundElements:i.boundElements.reduce((o,r)=>{let s=t.get(r.id);return s&&o.push({...r,id:s}),o},[])}),"containerId"in i&&i.containerId&&Object.assign(i,{containerId:t.get(i.containerId)??null}),"endBinding"in i&&i.endBinding){let o=t.get(i.endBinding.elementId);Object.assign(i,{endBinding:o?{...i.endBinding,elementId:o}:null})}if("startBinding"in i&&i.startBinding){let o=t.get(i.startBinding.elementId);Object.assign(i,{startBinding:o?{...i.startBinding,elementId:o}:null})}_(i)&&Object.assign(i,Wn(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},Iy=(e,t)=>{let n=Ll(e);for(let i of t)un.unbindAffected(n,i,(o,r)=>be(o,n,r)),mn.unbindAffected(n,i,(o,r)=>be(o,n,r))},Ai=(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},Fl=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),Bo=(e,t,n)=>{de(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},Lo=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(ce(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(H(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},un=class{static unbindAffected(t,n,i){n&&Lo(t,n,o=>{!o||o.isDeleted||Bo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:Ai(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||Lo(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:Ai(o.boundElements,new Set,new Array(n))}),J(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:Ai(o.boundElements,new Set,new Array(n))}))))})}},mn=class{static unbindAffected(t,n,i){n&&Bo(t,n,o=>{!o||o.isDeleted||Lo(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||Bo(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:Ai(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:Ai(n.boundElements,new Set([o.id]))})))})}},Fe=(e,t,n)=>{let[i,o]=tn(e);return se(ne(t.x+t.width*i,t.y+t.height*o),re(t,n),t.angle)},Hp=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?Fe(e.startBinding.fixedPoint,n,t):ne(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?Fe(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]},Rl=(e,t)=>{let[n,i]=Hp(e,t);return[L.pointFromAbsoluteCoords(e,n,t),L.pointFromAbsoluteCoords(e,i,t)]},_p=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),tn=e=>{if(!_p(e))return[.5001,.5001];let t=1e-4;return Math.abs(e[0]-.5)<t||Math.abs(e[1]-.5)<t?e.map(n=>Math.abs(n-.5)<t?.5001:n):e},Up=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",Wp={rectangle:[{centerAngle:0,sectorWidth:75,side:"right"},{centerAngle:45,sectorWidth:15,side:"bottom-right"},{centerAngle:90,sectorWidth:75,side:"bottom"},{centerAngle:135,sectorWidth:15,side:"bottom-left"},{centerAngle:180,sectorWidth:75,side:"left"},{centerAngle:225,sectorWidth:15,side:"top-left"},{centerAngle:270,sectorWidth:75,side:"top"},{centerAngle:315,sectorWidth:15,side:"top-right"}],diamond:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}],ellipse:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}]},Yp=e=>e.map((t,n)=>{let i=t.sectorWidth/2,o=t.centerAngle-i,r=t.centerAngle+i;return o=(o%360+360)%360,r=(r%360+360)%360,{start:o,end:r,side:t.side}}),jp=(e,t)=>{let[n,i]=e,o=n-.5,r=i-.5,s=Math.atan2(r,o);s<0&&(s+=2*Math.PI);let a=s*180/Math.PI,l=Wp[t],d=Yp(l);for(let m of d)if(m.start<=m.end){if(a>=m.start&&a<=m.end)return m.side}else if(a>=m.start||a<=m.end)return m.side;let c=1/0,u=l[0].side;for(let m of l){let p=Math.abs(a-m.centerAngle);p>180&&(p=360-p),p<c&&(c=p,u=m.side)}return u},Sy=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!de(n))return null;let i=re(n,t),o=Up(n),r=jp(tn(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=en(n),[d,c,u,m]=a,p,f;switch(r){case"left":{if(l.length>=3){let E=l[2][1];p=E[0]-s,f=E[1]}else{let h=Me(c[1],u[0]);p=h[0]-s,f=h[1]}break}case"right":{if(l.length>=1){let E=l[0][1];p=E[0]+s,f=E[1]}else{let h=Me(m[1],d[0]);p=h[0]+s,f=h[1]}break}case"top":{if(l.length>=4){let E=l[3][1];p=E[0],f=E[1]-s}else{let h=Me(u[1],m[0]);p=h[0],f=h[1]-s}break}case"bottom":{if(l.length>=2){let E=l[1][1];p=E[0],f=E[1]+s}else{let h=Me(d[1],c[0]);p=h[0],f=h[1]+s}break}case"top-right":{let h=Me(m[0],m[1]);p=h[0]+s*.707,f=h[1]-s*.707;break}case"bottom-right":{let h=Me(d[0],d[1]);p=h[0]+s*.707,f=h[1]+s*.707;break}case"bottom-left":{let h=Me(c[0],c[1]);p=h[0]-s*.707,f=h[1]+s*.707;break}case"top-left":{let h=Me(u[0],u[1]);p=h[0]-s*.707,f=h[1]-s*.707;break}default:return null}return se(ne(p,f),i,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,m;switch(r){case"top":{u=a,m=l-c-s;break}case"right":{u=a+d+s,m=l;break}case"bottom":{u=a,m=l+c+s;break}case"left":{u=a-d-s,m=l;break}case"top-right":{let p=-Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f+s*.707,m=l+h-s*.707;break}case"bottom-right":{let p=Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f+s*.707,m=l+h+s*.707;break}case"bottom-left":{let p=3*Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f-s*.707,m=l+h+s*.707;break}case"top-left":{let p=-3*Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f-s*.707,m=l+h-s*.707;break}default:return null}return se(ne(u,m),i,n.angle)}if(pi(n)){let[a,l]=Jt(n),[d,c,u,m]=a,p,f;switch(r){case"top":{let h=Me(d[0],d[1]);p=h[0],f=h[1]-s;break}case"right":{let h=Me(c[0],c[1]);p=h[0]+s,f=h[1];break}case"bottom":{let h=Me(u[0],u[1]);p=h[0],f=h[1]+s;break}case"left":{let h=Me(m[0],m[1]);p=h[0]-s,f=h[1];break}case"top-left":{if(l.length>=1){let h=l[0],E=h[0],g=h[3],x=Me(E,g);p=x[0]-s*.707,f=x[1]-s*.707}else p=n.x-s,f=n.y-s;break}case"top-right":{if(l.length>=2){let h=l[1],E=h[0],g=h[3],x=Me(E,g);p=x[0]+s*.707,f=x[1]-s*.707}else p=n.x+n.width+s,f=n.y-s;break}case"bottom-right":{if(l.length>=3){let h=l[2],E=h[0],g=h[3],x=Me(E,g);p=x[0]+s*.707,f=x[1]+s*.707}else p=n.x+n.width+s,f=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let h=l[3],E=h[0],g=h[3],x=Me(E,g);p=x[0]-s*.707,f=x[1]+s*.707}else p=n.x-s,f=n.y+n.height+s;break}default:return null}return se(ne(p,f),i,n.angle)}return null},Me=(e,t)=>ne((e[0]+t[0])/2,(e[1]+t[1])/2);var os=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>G(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},L=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;hoveredFocusPointBinding;draggedFocusPointBinding;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,i=!1){this.elementId=t.id,zl(t.points[0],G(0,0))||(console.error("Linear element is not normalized",Error().stack),be(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.lastCommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.initialState={prevSelectedPointsIndices:null,lastClickedPoint:-1,origin:null,segmentMidpoint:{value:null,index:null,added:!1},arrowStartIsInside:!1,altFocusPoint:null},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=_(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]=j(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=>!(_(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);Ce(d,"Element being dragged must exist in the scene"),Ce(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??Xl(m,d.points[c]),f=0,h=0;if(Ti(t)){let[b,I]=e._getShiftLockedDelta(d,s,m,G(i,o),t[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),S=G(b+m[0],I+m[1]);f=S[0]-u[0],h=S[1]-u[1]}else{let b=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());f=b[0]-u[0],h=b[1]-u[1]}let E=null,{positions:g,updates:x}=jl([c],f,h,i,o,s,d,a,n,Ti(t),t.altKey,r);if(e.movePoints(d,n.scene,g,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement}),Se(d,!1)&&bt(n.state)&&(E=x?.suggestedBinding??null),Se(d)&&Wl(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!E||qp(n.state.suggestedBinding??[],E)))return null;let w=Se(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:p,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&w&&x?.suggestedBinding?.element.id!==w.id?Yl(d,G(d.x,d.y),w,"start",s,n.state.zoom):r.initialState.altFocusPoint}},suggestedBinding:E}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);Ce(p,"Element being dragged must exist in the scene"),Ce(p.points.length>1,"Element must have at least 2 points"),Ce(u,"There must be selected points in order to drag them"),l&&u.some((A,V)=>A>0&&A!==p.points.length-1?(u[V]=p.points.length-1,m=p.points.length-1,!0):!1),Ce(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??Xl(h,p.points[m]),x=u.includes(0),w=u.includes(p.points.length-1),y=0,b=0;if(Ti(t)&&E){let[A,V]=e._getShiftLockedDelta(p,s,h,G(i,o),t[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),g),Z=G(A+h[0],V+h[1]);y=Z[0]-f[0],b=Z[1]-f[1]}else{let A=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=A[0]-f[0],b=A[1]-f[1]}let I=null,{positions:S,updates:T}=jl(u,y,b,i,o,s,p,a,n,Ti(t)&&E,t.altKey,r);e.movePoints(p,n.scene,S,{startBinding:T?.startBinding,endBinding:T?.endBinding,moveMidPointsWithElement:T?.moveMidPointsWithElement}),Se(p,!1)&&bt(n.state)&&(x||w)&&(I=T?.suggestedBinding??null),Se(p)&&x!==w&&Wl(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),$(p,s)&&Ln(p,n.scene,!1);let R=l?w?[p.points.length-1]:[0]:u,C=l?R[0]:m,F=!x&&!w?e.getPointGlobalCoordinates(p,f,s):null,B=C,Y=Se(p)&&p.startBinding&&s.get(p.startBinding.elementId),O=Se(p)&&p.endBinding&&s.get(p.endBinding.elementId),X=w&&Y&&T?.suggestedBinding?.element.id!==Y.id?Y:x&&O&&T?.suggestedBinding?.element.id!==O.id?O:null;return{selectedLinearElement:{...r,selectedPointsIndices:R,initialState:{...r.initialState,lastClickedPoint:C,altFocusPoint:!r.initialState.altFocusPoint&&Se(p)&&X?Yl(p,G(p.x,p.y),X,"start",s,n.state.zoom):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:F,hoverPointIndex:B,isDragging:!0,customLineAngle:g},suggestedBinding:I}}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),{elementId:s,selectedPointsIndices:a,isDragging:l,initialState:d}=n,c=e.getElement(s,r);if(!c)return n;if(l&&a)for(let u of a)(u===0||u===c.points.length-1)&&Kp(c.points,i.zoom.value)&&(Bt(c)&&o.mutateElement(c,{...$l(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,o,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1}}}static getEditorMidPoints=(t,n,i)=>{let o=$(t,n);if(!_(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(!_(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!_(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&On(G(c[0],c[1]),G(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&On(m[u],G(n.x,n.y))<=d)return m[u];u++}return null};static isSegmentTooShort(t,n,i,o,r){if(_(t))return o>=0&&o<t.points.length?On(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=On(n,i);if(t.points.length>2&&t.roundness){let[a,l]=_l(t);Ce(a.length===0&&l.length>0,"Only linears built out of curves are supported"),Ce(a.length+l.length>=o,"Invalid segment index while calculating mid point"),s=$p(l[o])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(_(t)){Ce(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=Nl(t.points[n-1],t.points[n]);return G(t.x+r[0],t.y+r[1])}let[i,o]=_l(t);if(Ce(i.length===0&&o.length>0||i.length>0&&o.length===0,"Only linears built out of either segments or curves are supported"),Ce(i.length+o.length>=n,"Invalid segment index while calculating mid point"),i.length){let r=i[n-1];return Nl(r[0],r[1])}if(o.length){let r=o[n-1];return Vp(r,.5)}Ce(!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=G(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[Gn.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:p,segmentMidpoint:{value:m,index:f,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let h=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y);(h>=0||m)&&(d.hitElement=u);let[E,g,x,w]=j(u,l),y=(E+x)/2,b=(g+w)/2,I=h>-1&&Le(G(u.x+u.points[h][0],u.y+u.points[h][1]),G(y,b),u.angle),S=h>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(h)?Qp([...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:zl(t,n)}static handlePointerMoveInEditMode(t,n,i,o){let r=o.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=o.scene.getNonDeletedElementsMap(),d=e.getElement(s,l);if(!d)return r.selectedLinearElement;let{points:c}=d,u=c[c.length-1];if(!t.altKey)return u===a&&e.deletePoints(d,o,[c.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let m;if(Ti(t)&&c.length>=2){let p=c[c.length-2],[f,h]=e._getShiftLockedDelta(d,l,p,G(n,i),t[Gn.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=G(f+p[0],h+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[Gn.CTRL_OR_CMD]||_(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]=j(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Le(G(c+n[0],u+n[1]),G(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=j(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return Le(G(c+d[0],u+d[1]),G(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=j(t,i),a=G(r,s),l=t.points[o],{x:d,y:c}=t;return l?Le(G(d+l[0],c+l[1]),a,t.angle):Le(G(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(_(t))return G(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=j(t,i),l=(o+s)/2,d=(r+a)/2,[c,u]=Le(G(n[0],n[1]),G(l,d),-t.angle);return G(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(On(G(o,r),G(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=Hl(i,o,r),[a,l,d,c]=j(t,n),u=(a+d)/2,m=(l+c)/2,[p,f]=Le(G(s[0],s[1]),G(u,m),-t.angle);return G(p-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=os(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){Ce(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);Ce(s,"The linear element does not exist in the provided Scene"),Ce(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?G((p[0]+E[0])/2,(p[1]+E[1])/2):G(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:G(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]=G(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=os({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]=G(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=os({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:G(c.point[0],c.point[1]),isDragging:c.isDragging}):u&&i.set(0,{point:G(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=i.get(0)?.point??G(0,0),[a,l]=s,d=_(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:G(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&&_(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=On(a,G(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<Zp/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&&!_(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(_(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=rs(t,i),d=rs(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=Le(G(o,r),G(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(_(t))return[o[0]-a[0],o[1]-a[1]];let[l,d]=Hl(o[0],o[1],r),{width:c,height:u}=Vl(a[0],a[1],l,d,s);return Le(G(c,u),G(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:m}=e.getBoundTextElementPosition(t,o,n),p=u+o.width,f=m+o.height,h=G(d,c),E=Le(G(r,s),h,t.angle),g=Le(G(a,s),h,t.angle),x=Le(G(u,m),h,-t.angle),w=Le(G(p,m),h,-t.angle),y=Le(G(u,f),h,-t.angle),b=Le(G(p,f),h,-t.angle);return E[0]<g[0]&&E[1]>=g[1]?(r=Math.min(r,y[0]),a=Math.max(a,Math.max(w[0],b[0])),s=Math.min(s,x[1]),l=Math.max(l,b[1])):E[0]>=g[0]&&E[1]>g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(x[0],w[0])),s=Math.min(s,y[1]),l=Math.max(l,w[1])):E[0]>=g[0]?(r=Math.min(r,w[0]),a=Math.max(a,y[0]),s=Math.min(s,b[1]),l=Math.max(l,x[1])):E[1]<=g[1]&&(r=Math.min(r,Math.min(w[0],x[0])),a=Math.max(a,b[0]),s=Math.min(s,w[1]),l=Math.max(l,y[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=Ze.generateElementShape(t,null),r=vt(o[0]),[s,a,l,d]=vi(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&&$(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||!_(a))return t;if(n&&n>0&&n<a.points.length){let l=He(Nt(Xp(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,f)=>(p[f.index]=f,p),{});d[n]={index:n,start:G(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:G(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=G(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)})}},Qp=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},jl=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let m=new Map(e.map(O=>[O,{point:G(s.points[O][0]+t,s.points[O][1]+n),isDragging:!0}]));if(!H(s))return{positions:m};let p=e.includes(0),f=e.includes(s.points.length-1),{start:h,end:E}=ns(s,m,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c});if(_(s)){let O=p?h.element:f?E.element:null;return{positions:m,updates:{suggestedBinding:O?{element:O,midPoint:is(O,r,G(i-u.pointerOffset.x,o-u.pointerOffset.y))}:null}}}if(!p&&!f){let O={...s,points:s.points.map((k,A)=>m.get(A)?.point??k)},X=new Map(m);if(s.startBinding){let k=r.get(s.startBinding.elementId);if(k){let A=dt(O,"startBinding",s.startBinding,k,r)??null;A&&X.set(0,{point:A,isDragging:!0})}}if(s.endBinding){let k=r.get(s.endBinding.elementId);if(k){let A=dt(O,"endBinding",s.endBinding,k,r)??null;A&&X.set(s.points.length-1,{point:A,isDragging:!0})}}return{positions:X}}if(p===f)return{positions:m};let g={suggestedBinding:null};h.mode===null?g.startBinding=null:h.mode?(g.startBinding={elementId:h.element.id,mode:h.mode,...Yn(s,h.element,"start",r,h.focusPoint)},p&&(g.startBinding.mode==="orbit"||!jn("COMPLEX_BINDINGS"))&&(g.suggestedBinding=h.element?{element:h.element,midPoint:Ul(G(i-u.pointerOffset.x,o-u.pointerOffset.y),h.element,r,l.state.zoom)}:null)):p&&(g.suggestedBinding=l.state.suggestedBinding),E.mode===null?g.endBinding=null:E.mode?(g.endBinding={elementId:E.element.id,mode:E.mode,...Yn(s,E.element,"end",r,E.focusPoint)},f&&(g.endBinding.mode==="orbit"||!jn("COMPLEX_BINDINGS"))&&(g.suggestedBinding=E.element?{element:E.element,midPoint:Ul(G(i-u.pointerOffset.x,o-u.pointerOffset.y),E.element,r,l.state.zoom)}:null)):f&&(g.suggestedBinding=l.state.suggestedBinding);let x=p?G(s.points[0][0]+t,s.points[0][1]+n):s.points[0],w=f?G(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],y={...s,points:[x,...s.points.slice(1,-1),w],startBinding:g.startBinding===void 0?s.startBinding:g.startBinding===null?null:g.startBinding,endBinding:g.endBinding===void 0?s.endBinding:g.endBinding===null?null:g.endBinding},b=s.endBinding&&y.startBinding&&p&&y.startBinding.elementId===s.endBinding.elementId,I=s.startBinding&&y.endBinding&&f&&s.startBinding.elementId===y.endBinding.elementId,S=y.endBinding?E.element??r.get(y.endBinding.elementId):null,T=b?y.points[y.points.length-1]:I&&l.state.bindMode!=="inside"&&jn("COMPLEX_BINDINGS")?y.points[0]:S&&dt(s,"endBinding",y.endBinding,S,r,f)||y.points[y.points.length-1];y.points[y.points.length-1]=T;let M=y.startBinding?h.element??r.get(y.startBinding.elementId):null,R=I&&jn("COMPLEX_BINDINGS")?y.points[0]:b&&l.state.bindMode!=="inside"&&jn("COMPLEX_BINDINGS")?T:M&&dt(s,"startBinding",y.startBinding,M,r,p)||y.points[0],C=!b&&!(I&&l.state.bindMode!=="inside"&&jn("COMPLEX_BINDINGS"))&&!!S,F=On(R,y.points[0])!==0,B=new Set(e);M&&F&&B.add(0),S&&C&&B.add(s.points.length-1);let Y=Array.from(B);return{updates:g,positions:new Map(Y.map(O=>[O,O===0?{point:R,isDragging:!0}:O===s.points.length-1?{point:T,isDragging:!0}:m.get(O)]))}},Xl=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);P();import{arrayToMap as It}from"@excalidraw/common";import{isPointWithinBounds as yf,pointFrom as cs}from"@excalidraw/math";P();import{vectorCross as Ql,vectorFromPoint as Co}from"@excalidraw/math";function Zl(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 Jp(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var ef=1e-6;function ql(e,t){let n=Co(e[1],e[0]),i=Co(t,e[0]),o=Ql(n,i);return Math.abs(o)<ef}function ss(e,t){let n=Co(e[1],e[0]),i=Co(t,e[0]);return Ql(n,i)<0}function Kl(e,t){return ql(e,t[0])||ql(e,t[1])||(ss(e,t[0])?!ss(e,t[1]):ss(e,t[1]))}function Jl(e,t){return Jp(Zl(e),Zl(t))&&Kl(e,t)&&Kl(t,e)}P();import{arrayToMap as tf}from"@excalidraw/common";import{getElementBounds as nf}from"@excalidraw/element";import{isArrowElement as of,isExcalidrawElement as rf,isFreeDrawElement as sf,isLinearElement as af,isTextElement as lf}from"@excalidraw/element";import{rangeIncludesValue as Go,pointFrom as _t,pointRotateRads as df,rangeInclusive as Oo}from"@excalidraw/math";var cf=e=>e.type==="diamond"?[_t(e.width/2,0),_t(e.width,e.height/2),_t(e.width/2,e.height),_t(0,e.height/2)]:[_t(0,0),_t(0+e.width,0),_t(0+e.width,e.height),_t(0,e.height)],uf=e=>af(e)||sf(e)?e.points:cf(e),ed=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},nd=e=>{let t=uf(e),{cx:n,cy:i}=ed(t),o=_t(n,i),r=t.map(c=>df(c,o,e.angle)),{minX:s,minY:a,maxX:l,maxY:d}=ed(r);return[s+e.x,a+e.y,l+e.x,d+e.y]},td=(e,t,n=!1)=>{let i=nd(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},mf=(e,t)=>{let n=nd(e);return(Go(n[0],Oo(t[0],t[2]))||Go(t[0],Oo(n[0],n[2])))&&(Go(n[1],Oo(t[1],t[3]))||Go(t[1],Oo(n[1],n[3])))},id=({elements:e,bounds:t,type:n,errorMargin:i=0})=>{rf(t)&&(t=nf(t,tf(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"?mf(s,o):n==="inside"?td(s,o):td(s,o,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);lf(s)&&s.containerId&&r.add(s.containerId),of(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 xf,isShallowEqual as wf}from"@excalidraw/common";P();var pf=(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}}},od=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:as({...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:as(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),ff=(e,t)=>ls(e,t)!=null,ls=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),hf=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),rd=(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,...pf(r,n,e)}}}return n.selectedGroupIds},e0=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Ef=(e,t)=>e.groupIds.includes(t),Ge=(e,t)=>{let n=[];for(let i of e.values())Ef(i,t)&&n.push(i);return n},gf=(e,t)=>e.groupIds.find(n=>t[n]),t0=(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},n0=(e,t)=>e.filter(n=>!t[n]),i0=(e,t)=>{let n=new Map;return e.forEach(i=>{let o=i.groupIds.length===0?i.id:i.groupIds[i.groupIds.length-1],r=n.get(o)||[],s=$(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},sd=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},ad=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},ld=e=>e.groupIds.length>0,dd=(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},ko=(e,t,n)=>{let i=hf(n),o=e.filter(u=>!ce(u)),r=new Map,s=new Map,a=u=>{let m=s.get(u.id)||[],p=$(u,t);p&&m.push(p),s.set(u.id,[...m,u])},l=(u,m)=>{let p=r.get(m)||[],f=$(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=>ff(n,u));return o.forEach(u=>{let m=gf(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 cd=e=>{let t=new Set;return e.forEach(n=>{q(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},ds=(e,t,n,i=!0)=>{let[o,r,s,a]=j(t,n),l=e.filter(d=>{let[c,u,m,p]=he(d,n),f=Ut(d,n);if(f){let[h,E,g,x]=he(f,n);c=Math.max(h,c),u=Math.max(E,u),m=Math.min(g,m),p=Math.min(x,p)}return d.locked===!1&&d.type!=="selection"&&!ce(d)&&o<=c&&r<=u&&s>=m&&a>=p});return l=i?cd(l):l,l=l.filter(d=>{let c=Ut(d,n);return c?pn(d,c,n):!0}),l},p0=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=ud(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},f0=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=>{q(s)&&fn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},h0=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:Pt(e,t,{includeBoundTextElement:!0}),as=(e,t)=>wf(t.selectedElementIds,e)?t.selectedElementIds:e,bf=(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 L(i,xf(t))}return null},E0=(e,t,n)=>({selectedLinearElement:bf(e,t),...od({editingGroupId:n.editingGroupId,selectedElementIds:cd(e).reduce((i,o)=>(ce(o)||(i[o.id]=!0),i),{})},t,n,null)});var md=(e,t,n)=>{let i=It(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 Xn(e,t,n){let i=us(t,n),o=us(e,n);return i.some(s=>o.some(a=>Jl(s,a)))}var pd=(e,t,n)=>Fo(ds(e,t,n,!1)).filter(i=>!q(i)&&!i.frameId||i.frameId===t.id),ms=(e,t,n)=>ds([t],e,n).some(i=>i.id===t.id),D0=(e,t)=>{let n=It(e);return e.filter(i=>Xn(i,t,n))},hn=(e,t,n)=>{let[i,o,r,s]=j(t,n),[a,l,d,c]=Oe(e);return i<=a&&o<=l&&r>=d&&s>=c},pn=(e,t,n)=>hn([e],t,n)||Xn(e,t,n)||ms(e,t,n),B0=(e,t,n)=>{let[i,o,r,s]=j(t,n);return yf(cs(i,o),cs(e.x,e.y),cs(r,s))},L0=(e,t,n)=>{let i=It(e),o=t.flatMap(r=>Ge(e,r));return o.length===0?!0:!!o.find(r=>hn([r],n,i)||Xn(r,n,i))},C0=(e,t,n)=>{let i=It(e),o=t.flatMap(r=>Ge(e,r));return o.length===0?!0:o.find(r=>hn([r],n,i)||Xn(r,n,i))===void 0},G0=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,fn(e,i))}return t},fn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Pf=e=>e.filter(t=>q(t)),O0=e=>{let t=It(Pf(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},k0=(e,t,n,i)=>{let o=fn(e,t.id),r=new Set(o),s=new Set([...pd(e,t,i),...o.filter(m=>ms(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(!Xn(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=rd(c,n);for(let[m,p]of Object.entries(u))if(p){let f=Ge(e,m);if(hn(f,t,i))for(let h of f)r.add(h)}return[...r].filter(m=>!(J(m)&&m.containerId))},F0=(e,t,n)=>If(Fo(e,pd(e,t,n)),t,n),If=(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=>Ge(n,l)));s=!hn(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Ut=(e,t)=>e.frameId&&t.get(e.frameId)||null,R0=(e,t)=>{let n=new Set,i=It(e);e=Fo(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=Ge(e,a);if(l.some(d=>pn(d,t,i)))for(let d of l)r.push(d)}}else pn(s,t,i)&&r.push(s);return r},Sf=(e,t,n,i)=>{let o=It(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 Fo(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=$(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},fd=(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=$(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})},Af=(e,t)=>{let n=fn(e,t.id);return fd(n,It(e)),e},N0=(e,t,n,i)=>Sf(Af(e,n),t,n,i.state).slice(),z0=(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=>Ge(e,l)).forEach(l=>o.add(l));let r=new Set,s=It(e);return o.forEach(a=>{a.frameId&&!q(a)&&!hd(a,s,t)&&r.add(a)}),r.size>0&&fd(r,s),e},Fo=(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)Ge(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},Mf=(e,t,n)=>{let i=J(e)&&Ae(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Ut(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Ut(i,t)},hd=(e,t,n,i)=>{let o=i?.targetFrame??Mf(e,t,n);if(!o)return!1;let r=J(e)&&Ae(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 pn(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=>Ge(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(pn(l,o,t))return s(!0),!0;return!1},H0=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Xn(e,t,i)||ms(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!hn([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=hd(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},Tf="Frame",vf="AI Frame",Df=e=>ro(e)?Tf:vf,_0=e=>e.name===null?Df(e):e.name,U0=(e,t)=>id({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),W0=e=>{let t=It(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var zf=(e,t)=>Tn(e)&&!t.imageCache.has(e.fileId),_o=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}},Hf=(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*=Cf/100),r},_f=(e,t,n)=>{let r=_o(e),[s,a,l,d]=j(e,t),c=K(e)||Ie(e)?En(s,l):e.width,u=K(e)||Ie(e)?En(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}},xd=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=_o(e),{width:l,height:d,scale:c}=_f(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]=j(e,t);u=e.x>g?En(e.x,g)*window.devicePixelRatio*c:0,m=e.y>x?En(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=Mn.canvas(r);zo(e,p,s,i),s.restore();let f=$(e,t),h=document.createElement("canvas"),E=h.getContext("2d");if(H(e)&&f){let[g,x,w,y]=j(e,t),b=Math.max(En(g,w),En(x,y));h.width=b*window.devicePixelRatio*c+a*c*10,h.height=b*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]=j(f,t);E.rotate(-e.angle);let T=(h.width-r.width)/2,M=(h.height-r.height)/2,R=h.width/2-(I-g)*window.devicePixelRatio*c-T-a*c,C=h.height/2-(S-x)*window.devicePixelRatio*c-M-a*c;E.translate(-R,-C),E.clearRect(-(f.width/2+No)*window.devicePixelRatio*c,-(f.height/2+No)*window.devicePixelRatio*c,(f.width+No*2)*window.devicePixelRatio*c,(f.height+No*2)*window.devicePixelRatio*c)}return{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,boundTextElementVersion:$(e,t)?.version||null,containingFrameOpacity:Ut(e,t)?.opacity||100,boundTextCanvas:h,angle:e.angle,imageCrop:xe(e)?e.crop:null}},o1=14,wd=typeof document<"u"?document.createElement("img"):{src:""};wd.src=`data:${hs.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 bd=typeof document<"u"?document.createElement("img"):{src:""};bd.src=`data:${hs.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 Uf=(e,t,n)=>{t.fillStyle=n===$n.DARK?"#2E2E2E":"#E7E7E7",t.fillRect(0,0,e.width,e.height);let i=Math.min(e.width,e.height),o=Math.min(i,Math.min(i*.4,100));t.drawImage(e.status==="error"?bd:wd,e.width/2-o/2,e.height/2-o/2,o,o)},zo=(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(Ze.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Ze.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=Ze.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=i.theme===$n.DARK?Ho(e.strokeColor):e.strokeColor,n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{n.save();let o=e.fileId!==null?i.imageCache.get(e.fileId):null,r=Tn(e)?o?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,Ct(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight},c=i.theme===$n.DARK&&o?.mimeType===hs.svg;if(c&&Nf){let u=window.devicePixelRatio||1,m=document.createElement("canvas");m.width=e.width*u,m.height=e.height*u;let p=m.getContext("2d");if(p){p.scale(u,u),p.drawImage(r,s,a,l,d,0,0,e.width,e.height);let f=p.getImageData(0,0,m.width,m.height),h=f.data;for(let E=0;E<h.length;E+=4)h[E]=255-h[E],h[E+1]=255-h[E+1],h[E+2]=255-h[E+2];p.putImageData(f,0,0),n.drawImage(m,0,0,m.width,m.height,0,0,e.width,e.height)}}else c&&(n.filter=Gf),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else Uf(e,n,i.theme);n.restore();break}default:if(J(e)){let o=kf(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=Of(e),n.fillStyle=i.theme===$n.DARK?Ho(e.strokeColor):e.strokeColor,n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
9
+ `)=>e.reduce((i,o)=>(Q(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as zr,distanceToLineSegment as Hr,pointRotateRads as _r}from"@excalidraw/math";import{ellipse as Wm,ellipseDistanceFromPoint as Ym}from"@excalidraw/math/ellipse";var rn=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return jm(e,t,n);case"diamond":return Xm(e,t,n);case"ellipse":return $m(e,t,n);case"line":case"arrow":case"freedraw":return Vm(e,n)}},jm=(e,t,n)=>{let i=re(e,t),o=_r(n,i,-e.angle),[r,s]=en(e);return Math.min(...r.map(a=>Hr(o,a)),...s.map(a=>zr(a,o)).filter(a=>a!==null))},Xm=(e,t,n)=>{let i=re(e,t),o=_r(n,i,-e.angle),[r,s]=tn(e);return Math.min(...r.map(a=>Hr(o,a)),...s.map(a=>zr(a,o)).filter(a=>a!==null))},$m=(e,t,n)=>{let i=re(e,t);return Ym(_r(n,i,-e.angle),Wm(i,e.width/2,e.height/2))},Vm=(e,t)=>{let[n,i]=uo(e);return Math.min(...n.map(o=>Hr(t,o)),...i.map(o=>zr(o,t)))};var bo=e=>{if(e.type==="arrow")return!1;let t=!ml(e.backgroundColor)||gt(e)||lo(e)||Q(e);return e.type==="line"?t&&Bn(e.points):e.type==="freedraw"?t&&Bn(e.points):t||we(e)},Ur=null,sl=null,al=1/0,ll=!1,dl=!1,xt=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null,overrideShouldTestInside:r=!1})=>{if(Ur&&hl(e,Ur)&&al<=n&&r===dl){let u=sl?.deref();if(u&&u.id===t.id&&u.version===t.version&&u.versionNonce===t.versionNonce)return ll}let s=o?wo(me(o.x-n,o.y-n),e,me(o.x+o.width+n,o.y+o.height+n)):!1,a=he(t,i,!0);if(!wo(me(a[0]-n,a[1]-n),Ze(e,bt(a),-t.angle),me(a[2]+n,a[3]+n))&&!s)return!1;let c=(r||bo(t))&&Ot(e,t,i)||cl(e,t,i,n)||s;return Ur=e,sl=new WeakRef(t),al=n,dl=r,ll=c,c},tp=(e,t,n,i=0)=>{let[o,r,s,a]=he(t,n);return o-=i,r-=i,s+=i,a+=i,wo(me(o,r),e,me(s,a))},Ub=(e,t)=>!xt(e)&&!np(e.point,e.element,t)&&tp(e.point,e.element,t),np=(e,t,n)=>{let i=V(t,n);if(!i)return!1;let o=q(t)?{...i,...C.getBoundTextElementPosition(t,i,n)}:i;return Ot(e,o,n)},El=(e,[t,n],i,o=0)=>{let r=me(t,n),s=!Z(e),a=Math.max(1,o),l=[t-a,n-a,t+a,n+a],d=he(e,i);if(!Pi(l,d))return!1;if(e.frameId){let m=i.get(e.frameId);if(m&&Z(m)){let p=he(m,i);if(!an(r,p))return!1}}let c=sn(e,i,yi(re(e,i),r)),u=rn(e,i,r);return s?c.length===0||u<=o:c.length>0&&u<=a},yo=(e,t,n,i)=>{let o=[];for(let r=t.length-1;r>=0;--r){let s=t[r];if(ul(!s.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),de(s,!1)&&El(s,e,n,i)&&(o.push(s),!ml(s.backgroundColor)))break}return o},Nt=(e,t,n,i)=>{let o=yo(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()},gl=(e,t,n,i,o)=>{let r=[];for(let a=n.length-1;a>=0;--a){let l=n[a];ul(!l.isDeleted,"Elements in the function parameter for getAllElementsAtPositionForBinding() should not contain deleted elements"),de(l,!1)&&El(l,e,i,o)&&r.push(l)}if(!r||r.length===0)return null;if(r.length===1)return r[0];let s=r.filter(a=>rn(a,i,e)<=Be(a,t)||Ot(e,a,i));return s.length===0?null:s[0]},sn=(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(!Pi(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)}},xl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Po(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(!Pi(a,l))continue;let d=pl(s,t);if(d.length>0){for(let c of d)n.push(Ze(c,i,o));if(r)return n}}return n},wl=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=fl(s,t);if(a&&(n.push(Ze(a,i,o)),r))return n}return n},ip=(e,t,n=!1)=>{let[i,o]=uo(e),r=[];for(let s of i){let a=fl(s,t);if(a&&(r.push(a),n))return r}for(let s of o){let a=Po(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(!Pi(a,l))continue;let d=pl(s,t);if(d.length>0&&(r.push(...d),n))return r}return r},op=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=Ze(n[0],r,-e.angle),a=Ze(n[1],r,-e.angle),l=yi(s,a),[d,c]=en(e,i),u=[];return wl(d,l,u,r,e.angle,o),o&&u.length>0||xl(c,l,u,r,e.angle,o),u},rp=(e,t,n,i=0,o=!1)=>{let r=re(e,t),s=Ze(n[0],r,-e.angle),a=Ze(n[1],r,-e.angle),l=yi(s,a),[d,c]=tn(e,i),u=[];return wl(d,l,u,r,e.angle,o),o&&u.length>0||xl(c,l,u,r,e.angle,o),u},sp=(e,t,n,i=0)=>{let o=re(e,t),r=Ze(n[0],o,-e.angle),s=Ze(n[1],o,-e.angle);return ep(Jm(o,e.width/2+i,e.height/2+i),yi(r,s)).map(a=>Ze(a,o,e.angle))},cl=(e,t,n,i=1)=>rn(t,n,e)<=i,Ot=(e,t,n)=>{if((q(t)||Se(t))&&!Bn(t.points))return!1;let[i,o,r,s]=he(t,n);if(!wo(me(i,o),e,me(r,s)))return!1;let a=me((i+r)/2,(o+s)/2),l=Zm(Qm(Km(qm(e,a,.1)),Math.max(t.width,t.height)*2),a),d=yi(e,l);return sn(t,n,d).filter((u,m,p)=>p.findIndex(f=>hl(f,u))===m).length%2===1},Wr=(e,t,n)=>{let i=(s,a)=>{let{x:l,y:d,width:c,height:u,angle:m}=s,p=re(s,n);if(s.type==="diamond"){let[h,E,g,x,w,y,b,I]=Un(s);return[me(l+h,d+E-a),me(l+g+a,d+x),me(l+w,d+y+a),me(l+b-a,d+I)].map(T=>Ze(T,p,m))}if(s.type==="ellipse"){let h=l+c/2,E=d+u/2,g=c/2,x=u/2;return[me(h,E-x-a),me(h+g+a,E),me(h,E+x+a),me(h-g-a,E)].map(y=>Ze(y,p,m))}return[me(l-a,d-a),me(l+c+a,d-a),me(l+c+a,d+u+a),me(l-a,d+u+a)].map(h=>Ze(h,p,m))},o=-1*Math.max(e.width,e.height)/20;return i(e,o).every(s=>Ot(s,t,n))};P();import{invariant as bl,isDevEnv as ap,isTestEnv as lp}from"@excalidraw/common";import{pointFrom as ln,pointFromVector as Io,pointRotateRads as So,pointScaleFromOrigin as Ao,pointsEqual as dp,triangleIncludesPoint as Yr,vectorCross as ze,vectorFromPoint as K,vectorScale as Mo}from"@excalidraw/math";var fe=[1,0],be=[0,1],_e=[-1,0],qe=[0,-1],zt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?fe:t<=-o?_e:n>i?be:qe},He=(e,t)=>zt(K(e,t)),ct=(e,t)=>Ue(He(e,t)),pe=(e,t)=>e[0]===t[0]&&e[1]===t[1],Ue=e=>pe(e,fe)||pe(e,_e),Vb=e=>!Ue(e),cp=(e,t,n)=>{let i=bt(t);(ap()||lp())&&(bl(e.width>0&&e.height>0,"Diamond element has no width or height"),bl(!dp(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=Io(Mo(K(So(ln(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=Io(Mo(K(So(ln(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=Io(Mo(K(So(ln(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=Io(Mo(K(So(ln(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(ze(K(n,r),K(r,s))<=0&&ze(K(n,r),K(r,l))>0)return He(r,i);if(ze(K(n,s),K(s,a))<=0&&ze(K(n,s),K(s,r))>0)return He(s,i);if(ze(K(n,a),K(a,l))<=0&&ze(K(n,a),K(a,s))>0)return He(a,i);if(ze(K(n,l),K(l,r))<=0&&ze(K(n,l),K(l,a))>0)return He(l,i);if(ze(K(n,i),K(r,i))<=0&&ze(K(n,i),K(s,i))>0){let c=e.width>e.height?r:s;return He(c,i)}else if(ze(K(n,i),K(s,i))<=0&&ze(K(n,i),K(a,i))>0){let c=e.width>e.height?a:s;return He(c,i)}else if(ze(K(n,i),K(a,i))<=0&&ze(K(n,i),K(l,i))>0){let c=e.width>e.height?a:l;return He(c,i)}let d=e.width>e.height?r:l;return He(d,i)},Ii=(e,t,n)=>{let o=bt(t);if(e.type==="diamond")return cp(e,t,n);let r=Ao(ln(t[0],t[1]),o,2),s=Ao(ln(t[2],t[1]),o,2),a=Ao(ln(t[0],t[3]),o,2),l=Ao(ln(t[2],t[3]),o,2);return Yr([r,s,o],n)?qe:Yr([s,l,o],n)?fe:Yr([l,a,o],n)?be:_e},jr=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 ns,getUpdatedTimestamp as is}from"@excalidraw/common";P();import{clamp as To,pointDistance as Vr,pointFrom as j,pointScaleFromOrigin as up,pointsEqual as Ai,pointTranslate as $r,vector as yt,vectorCross as vo,vectorFromPoint as Zr,vectorScale as mp}from"@excalidraw/math";import{BinaryHeap as pp,invariant as Yn,isAnyTrue as fp,getSizeFromPoints as yl,isDevEnv as hp,arrayToMap as Ep}from"@excalidraw/common";var qr=1,ee=40,gp=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>j(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let d=He(s,l[a-1]),c=He(l[a-1],l[a-2]);if(pe(d,c)){let u=n?.findIndex(p=>p.index===a-1)??-1,m=n?.findIndex(p=>p.index===a)??-1;m!==-1&&(n[m].start=j(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(p=>{p.index>a-1&&(p.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(Vr(l[a-2],l[a-1])<qr){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=ct(s,l[a-1]);return o.push(j(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}o.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==o.length-1);return r.length===0?Ht(Jr(es(Qr(e,Kr(e,t,o.map(s=>j(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(hp()&&Yn(vl(o),"Invalid elbow points with fixed segments"),Ht(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}},xp=(e,t,n)=>{let i=t.map(M=>M.index),r=(e.fixedSegments?.map(M=>M.index)??[]).findIndex(M=>!i.includes(M));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,m=l?null:e.endBinding,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...w}=Kr({x:d,y:c,startBinding:u,endBinding:m,startArrowhead:null,endArrowhead:null,points:e.points},n,[j(0,0),j(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:y}=Ht(Jr(es(Qr(e,{startHeading:p,endHeading:f,startGlobalPoint:h,endGlobalPoint:E,hoveredStartElement:g,hoveredEndElement:x,...w})??[])),t,null,null);if(!y||y.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let b=[];if(a)for(let M=0;M<a.index;M++)b.push(j(e.x+e.points[M][0],e.y+e.points[M][1]));if(y.forEach(M=>{b.push(j(e.x+(a?a.end[0]:0)+M[0],e.y+(a?a.end[1]:0)+M[1]))}),l)for(let M=l.index;M<e.points.length;M++)b.push(j(e.x+e.points[M][0],e.y+e.points[M][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,A=t.map(M=>M.index>s?{...M,index:M.index-I+(y.length-1)}:M),T=b.flatMap((M,O)=>{let L=b[O-1],k=b[O+1];if(L&&k){let B=He(M,L),X=He(k,M);if(pe(B,X))return A.forEach(_=>{_.index>O&&(_.index-=1)}),[];if(pe(B,jr(X)))return A.forEach(_=>{_.index>O&&(_.index+=1)}),[M,M]}return[M]});return Ht(T,A,!1,!1)},wp=(e,t,n,i,o,r)=>{let s=t.map((b,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==b.index||(b.start[0]!==e.fixedSegments[I].start[0]&&b.end[0]!==e.fixedSegments[I].end[0])!=(b.start[1]!==e.fixedSegments[I].start[1]&&b.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(b=>b!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(b=>b.index===1)??-1,l=e.fixedSegments?.findIndex(b=>b.index===e.points.length-1)??-1,d=Vr(t[s].start,t[s].end),c=d<ee+5;if(a===-1&&t[s].index===1&&o){let b=Ue(n),A=(b?pe(n,fe):pe(n,be))?c?d/2:ee:c?-d/2:-ee;t[s].start=j(t[s].start[0]+(b?A:0),t[s].start[1]+(b?0:A))}if(l===-1&&t[s].index===e.points.length-1&&r){let b=Ue(i),A=(b?pe(i,fe):pe(i,be))?c?d/2:ee:c?-d/2:-ee;t[s].end=j(t[s].end[0]+(b?A:0),t[s].end[1]+(b?0:A))}let u=t.map(b=>({...b,start:j(e.x+b.start[0],e.y+b.start[1]),end:j(e.x+b.end[0],e.y+b.end[1])})),m=e.points.map((b,I)=>j(e.x+b[0],e.y+b[1])),p=u[s].index-1,f=u[s].index,h=u[s].start,E=u[s].end,g=m[p-1]&&!Ai(m[p],m[p-1])?ct(m[p-1],m[p]):void 0,x=m[f+1]&&!Ai(m[f],m[f+1])?ct(m[f+1],m[f]):void 0;if(g!==void 0){let b=g?1:0;m[p-1][b]=h[b]}if(m[p]=h,m[f]=E,x!==void 0){let b=x?1:0;m[f+1][b]=E[b]}let w=u.findIndex(b=>b.index===p);if(w!==-1){let b=ct(u[w].end,u[w].start)?1:0;u[w].start[b]=h[b],u[w].end=h}let y=u.findIndex(b=>b.index===f+1);if(y!==-1){let b=ct(u[y].end,u[y].start)?1:0;u[y].end[b]=E[b],u[y].start=E}if(a===-1&&p===0){let b=o?Ue(n):ct(m[1],m[0]);m.unshift(j(b?h[0]:e.x+e.points[0][0],b?e.y+e.points[0][1]:h[1])),o&&m.unshift(j(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=o?2:1}if(l===-1&&f===e.points.length-1){let b=Ue(i);m.push(j(b?E[0]:e.x+e.points[e.points.length-1][0],b?e.y+e.points[e.points.length-1][1]:E[1])),r&&m.push(j(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return Ht(m,u.map(b=>({...b,start:j(b.start[0]-e.x,b.start[1]-e.y),end:j(b.end[0]-e.x,b.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((E,g)=>g===0?j(e.x+E[0],e.y+E[1]):g===t.length-1?j(e.x+E[0],e.y+E[1]):j(e.x+e.points[g][0],e.y+e.points[g][1])),m=n.map(E=>({...E,start:j(e.x+(E.start[0]-t[0][0]),e.y+(E.start[1]-t[0][1])),end:j(e.x+(E.end[0]-t[0][0]),e.y+(E.end[1]-t[0][1]))})),p=[],f=2+(d?1:0),h=2+(c?1:0);for(;p.length+f<u.length-h;)p.push(u[p.length+f]);{let E=u.at(d?2:1),g=u.at(d?3:2);if(!E||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=Ue(i),w=Ue(zt(Zr(E,g)));if(a&&x===w){let y=x?pe(i,fe):pe(i,be);if(p.unshift(j(w?r[0]+(y?ee:-ee):g[0],w?g[1]:r[1]+(y?ee:-ee))),p.unshift(j(x?r[0]+(y?ee:-ee):r[0],x?r[1]:r[1]+(y?ee:-ee))),!d){d=!0;for(let b of m)b.index>1&&(b.index+=1)}}else if(p.unshift(j(w?r[0]:E[0],w?E[1]:r[1])),d){d=!1;for(let y of m)y.index>1&&(y.index-=1)}p.unshift(r)}{let E=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!E||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=Ue(o),w=ct(g,E);if(l&&x===w){let y=x?pe(o,fe):pe(o,be);p.push(j(w?s[0]+(y?ee:-ee):g[0],w?g[1]:s[1]+(y?ee:-ee))),p.push(j(x?s[0]+(y?ee:-ee):s[0],x?s[1]:s[1]+(y?ee:-ee))),c||(c=!0)}else p.push(j(w?s[0]:E[0],w?E[1]:s[1])),c&&(c=!1)}return p.push(s),Ht(p,m.map(({index:E})=>({index:E,start:p[E-1],end:p[E]})).map(E=>({...E,start:j(E.start[0]-r[0],E.start[1]-r[1]),end:j(E.end[0]-r[0],E.end[1]-r[1])})),d,c)},dn=1e6,jn=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};v.PROD||(Yn(!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)"),Yn(!e.fixedSegments||e.fixedSegments.map(b=>b.start[0]===b.end[0]||b.start[1]===b.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Yn(!n.fixedSegments||n.fixedSegments.map(b=>b.start[0]===b.end[0]||b.start[1]===b.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Yn(e.points.slice(1).map((b,I)=>b[0]===e.points[I][0]||b[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Yn(n.fixedSegments?.find(b=>b.index===1&&Ai(b.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(b=>b.index===(n.points??e.points).length-1&&Ai(b.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((b,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:b):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&&Bo(d.elementId,t),m=c&&Bo(c.elementId,t),p=vl(r);if(d&&!u&&p||c&&!m&&p||t.size===0&&p||Object.keys(l).length===0&&(u?.id!==d?.elementId||m?.id!==c?.elementId))return Ht(r.map(b=>j(e.x+b[0],e.y+b[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:w,...y}=Kr({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?Ht(r.map(b=>j(e.x+b[0],e.y+b[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?gp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((b,I)=>Ai(b,e.points[I]??j(1/0,1/0)))&&p?{}:o.length===0?Ht(Jr(es(Qr(e,{startHeading:f,endHeading:h,startGlobalPoint:E,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:w,...y})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?xp(e,o,t):n.points?n.points&&n.fixedSegments?n:bp(e,r,o,f,h,E,g,x,w):wp(e,o,f,h,x,w)},Kr=(e,t,n,i)=>{let o=$r(n[0],yt(e.x,e.y)),r=$r(n[n.length-1],yt(e.x,e.y)),s=null,a=null;if(i?.isDragging&&i?.isBindingEnabled!==!1){let b=Array.from(t.values());s=Al(o,t,b,i?.zoom)||null,a=Al(r,t,b,i?.zoom)||null}else s=e.startBinding&&Bo(e.startBinding.elementId,t)||null,a=e.endBinding&&Bo(e.endBinding.elementId,t)||null;let l=Il({...e,angle:0,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),d=Il({...e,angle:0,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging,i?.isBindingEnabled,i?.isMidpointSnappingEnabled),c=Sl(l,d,s,o,t,i?.zoom),u=Sl(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?nt(s,t,cn(c,e.startArrowhead?Be(s,{elbowed:!0})*6:Be(s,{elbowed:!0})*2,1)):m,h=a?nt(a,t,cn(u,e.endArrowhead?Be(a,{elbowed:!0})*6:Be(a,{elbowed:!0})*2,1)):p,E=an(l,a?nt(a,t,cn(u,ee,ee)):p)||an(d,s?nt(s,t,cn(c,ee,ee)):m),g=Tl(E?[m,p]:[f,h]),x=Ip(E?m:f,E?p:h,g,E?cn(c,!s&&!a?0:ee,0):cn(c,!s&&!a?0:ee-(e.startArrowhead?Gn*6:Gn*2),ee),E?cn(u,!s&&!a?0:ee,0):cn(u,!s&&!a?0:ee-(e.endArrowhead?Gn*6:Gn*2),ee),E,s&&nt(s,t),a&&nt(a,t)),w=Pl(x[0],c,l),y=Pl(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:w,startGlobalPoint:l,startHeading:c,endDonglePosition:y,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:E,startElementBounds:f,endElementBounds:h}},Qr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Sp(n,i||o,r,s||a,l,d),m=i&&Do(i,u),p=s&&Do(s,u),f=Do(a,u);f&&c&&(f.closed=!0);let h=Do(o,u);h&&e.startBinding&&(h.closed=!0);let E=m&&p&&(an(m.pos,n[1])||an(p.pos,n[0])),g=yp(m||h,p||f,u,r||fe,l||fe,E?[]:n);if(g){let x=g.map(w=>[w.pos[0],w.pos[1]]);return m&&x.unshift(o),p&&x.push(a),x}return null},cn=(e,t,n)=>{switch(e){case qe:return[t,n,n,n];case fe:return[n,t,n,n];case be:return[n,n,t,n]}return[n,n,n,t]},yp=(e,t,n,i,o,r)=>{let s=Xr(e.pos,t.pos),a=new pp(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Pp(e,l);l.closed=!0;let d=Mp(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let m=up(u.pos,l.pos,.5);if(fp(...r.map(y=>an(m,y))))continue;let p=Tp(c),f=l.parent?zt(Zr(l.pos,l.parent.pos)):i,h=jr(f);if(pe(h,p)||Ml(e.addr,u.addr)&&pe(p,i)||Ml(t.addr,u.addr)&&pe(p,o))continue;let g=f!==p,x=l.g+Xr(u.pos,l.pos)+(g?Math.pow(s,3):0),w=u.visited;if(!w||x<u.g){let y=Ap(u,t,p,o);u.visited=!0,u.parent=l,u.h=Xr(t.pos,u.pos)+y*Math.pow(s,2),u.g=x,u.f=u.g+u.h,w?a.rescoreElement(u):a.push(u)}}}return null},Pp=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},Xr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Ip=(e,t,n,i,o,r,s,a)=>{let l=s??e,d=a??t,[c,u,m,p]=i??[0,0,0,0],[f,h,E,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-p):(l[0]+d[2])/2:e[0]>t[0]?e[0]-p:n[0]-p,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+m):(l[3]+d[1])/2:e[3]<t[3]?e[3]+m:n[3]+m],w=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-f):(d[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+h):(d[2]+l[0])/2:t[2]<e[2]?t[2]+h:n[2]+h,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+E):(d[3]+l[1])/2:t[3]<e[3]?t[3]+E:n[3]+E],y=Tl([x,w]);if(!r&&x[2]-x[0]+w[2]-w[0]>y[2]-y[0]+1e-11&&x[3]-x[1]+w[3]-w[1]>y[3]-y[1]+1e-11){let[b,I]=[(w[0]+w[2])/2,(w[1]+w[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let A=x[2]+(w[0]-x[2])/2,T=w[3]+(x[1]-w[3])/2;return vo(yt(e[2]-b,e[1]-I),yt(e[0]-b,e[3]-I))>0?[[x[0],x[1],A,x[3]],[A,w[1],w[2],w[3]]]:[[x[0],T,x[2],x[3]],[w[0],w[1],w[2],T]]}else if(e[2]<t[0]&&e[3]<t[1]){let A=x[2]+(w[0]-x[2])/2,T=x[3]+(w[1]-x[3])/2;return vo(yt(e[0]-b,e[1]-I),yt(e[2]-b,e[3]-I))>0?[[x[0],x[1],x[2],T],[w[0],T,w[2],w[3]]]:[[x[0],x[1],A,x[3]],[A,w[1],w[2],w[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let A=w[2]+(x[0]-w[2])/2,T=x[3]+(w[1]-x[3])/2;return vo(yt(e[2]-b,e[1]-I),yt(e[0]-b,e[3]-I))>0?[[A,x[1],x[2],x[3]],[w[0],w[1],A,w[3]]]:[[x[0],x[1],x[2],T],[w[0],T,w[2],w[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let A=w[2]+(x[0]-w[2])/2,T=w[3]+(x[1]-w[3])/2;return vo(yt(e[0]-b,e[1]-I),yt(e[2]-b,e[3]-I))>0?[[A,x[1],x[2],x[3]],[w[0],w[1],A,w[3]]]:[[x[0],T,x[2],x[3]],[w[0],w[1],w[2],T]]}}return[x,w]},Sp=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===_e||n===fe?a.add(t[1]):s.add(t[0]),o===_e||o===fe?a.add(i[1]):s.add(i[0]),e.forEach(c=>{s.add(c[0]),s.add(c[2]),a.add(c[1]),a.add(c[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((c,u)=>c-u),d=Array.from(s).sort((c,u)=>c-u);return{row:l.length,col:d.length,data:l.flatMap((c,u)=>d.map((m,p)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[p,u],pos:[m,c]})))}},Pl=(e,t,n)=>{switch(t){case qe:return j(n[0],e[1]);case fe:return j(e[2],n[1]);case be:return j(n[0],e[3])}return j(e[0],n[1])},Ap=(e,t,n,i)=>{if(i===fe)switch(n){case fe:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case qe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case be:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case _e:return e.pos[1]===t.pos[1]?4:2}else if(i===_e)switch(n){case fe:return e.pos[1]===t.pos[1]?4:2;case qe:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case be: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:e.pos[1]===t.pos[1]?0:2}else if(i===qe)switch(n){case fe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case qe:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case be:return e.pos[0]===t.pos[0]?4:2;case _e:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===be)switch(n){case fe:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case qe:return e.pos[0]===t.pos[0]?4:2;case be:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case _e:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Mp=([e,t],n)=>[Si([e,t-1],n),Si([e+1,t],n),Si([e,t+1],n),Si([e-1,t],n)],Si=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Do=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=Si([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Tl=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]))],Bo=(e,t)=>{let n=t.get(e);return n&&de(n)?n:null},Ht=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>$r(a,mp(Zr(e[0]),-1)));return(o<-dn||o>dn||r<-dn||r>dn||o+s[s.length-1][0]<-dn||r+s[s.length-1][0]>dn||o+s[s.length-1][1]<-dn||r+s[s.length-1][1]>dn)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...yl(s)}),s=s.map(([a,l])=>j(To(a,-1e6,1e6),To(l,-1e6,1e6))),{points:s,x:To(o,-1e6,1e6),y:To(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...yl(s),startIsSpecial:n,endIsSpecial:i}},Jr=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},es=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return Vr(i,t)>qr}):e,Tp=e=>{switch(e){case 0:return qe;case 1:return fe;case 2:return be}return _e},Il=(e,t,n,i,o,r,s,a=!0,l=!0)=>s?a&&o&&r?ts(e,o,t,r,void 0,l):i:o?Ne(n||[0,0],o,r??Ep([o])):i,Sl=(e,t,n,i,o,r)=>Dl(e,t,n,n&&nt(n,o,Array(4).fill(rn(n,o,e))),i,o,r),Al=(e,t,n,i)=>Nt(e,n,t,lt(i)),Ml=(e,t)=>e[0]===t[0]&&e[1]===t[1],vl=(e,t=qr)=>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,...jn({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...vp(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")&&Ke.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??ns(),e.updated=is()),e},Le=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??ns(),updated:is()}},Bl=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=ns(),e.updated=is(),e);var Fl=5,Gn=5,Gp=10,vi=10/1.5,Be=(e,t)=>(t.elbowed?Gn:Fl)+e.strokeWidth/2,lt=e=>{let t=Math.max(Fl,15),n=e?.value&&e.value<1?e.value:1;return rs(t/(n*1.5),t,t*2)},Pt=e=>e.isBindingEnabled,Op=(e,t,n,i,o,r,s)=>{let{start:a,end:l}=ss(e,t,n,i,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),r,{...s,finalize:!0});if(Ll(e,a,"start",o,r.isBindingEnabled),Ll(e,l,"end",o,r.isBindingEnabled),a.focusPoint||l.focusPoint){let d=new Map;a.focusPoint&&d.set(0,{point:ut(e,"startBinding",e.startBinding,a.element,o.getNonDeletedElementsMap())||e.points[0]}),l.focusPoint&&d.set(e.points.length-1,{point:ut(e,"endBinding",e.endBinding,l.element,o.getNonDeletedElementsMap())||e.points[e.points.length-1]}),C.movePoints(e,o,d)}return{start:a,end:l}},Ll=(e,{mode:t,element:n,focusPoint:i},o,r,s=!0)=>{t===null?ve(e,o,r):t!==void 0&&It(e,n,t,o,r,i,s)},Rl=(e,t,n,i,o)=>{it(t.size===1,"Bound elbow arrows cannot be moved");let r=t.entries().next().value;it(r,"There should be a position update for dragging an elbow arrow endpoint");let[s,{point:a}]=r,l=C.getPointGlobalCoordinates(e,a,n),d=Nt(l,i,n,lt(o)),c=d?{element:d,mode:"orbit",focusPoint:C.getPointAtIndexGlobalCoordinates(e,s,n)}:{mode:null},u={mode:void 0};return s===0?{start:c,end:u}:{start:u,end:c}},kp=(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=C.getPointGlobalCoordinates(e,t.get(o?s:a).point,n),h=Nt(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=te(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(yo(f,i,n).find(w=>w.id===g.elementId)){let w=n.get(e.startBinding.elementId);return it(w,"Other element must be in the elements map"),{start:p?{mode:void 0}:{mode:w.id!==h.id?"orbit":"inside",element:w,focusPoint:E??te(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);it(g,"Other element must be in the elements map");let w={mode:!!l.selectedLinearElement?.initialState.arrowStartIsInside?"inside":"orbit",element:g,focusPoint:c?re(g,n):E??te(e.x,e.y)},y=h&&Wr(g,h,n),b;if(h){let I=d==="inside"||d==="skip";b={mode:I&&!y?"inside":"orbit",element:h,focusPoint:f}}else b={mode:null};return{start:p?{mode:void 0}:w,end:b}}if(!e.startBinding)return h?m={mode:d==="inside"||d==="skip"?"inside":"orbit",element:h,focusPoint:f}:m={mode:null},{start:u,end:m}}it(!1,"New arrow creation should not reach here")},Cl=(e,t,n,i,o,r,s,a)=>{let l={mode:void 0},d={mode:void 0},c=s.points.length>2,u=Nt(e,o,i),m=n?yo(e,o,i).some(E=>E.id===n.elementId):!1,p=n?i.get(n.elementId):null,f=m&&p?Bp(p.backgroundColor):!1,h=u&&p&&Wr(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}},ss=(e,t,n,i,o,r,s,a)=>Dp("COMPLEX_BINDINGS")?Fp(e,t,o,r,s,a):Nl(e,t,n,i,o,r,s,a),Nl=(e,t,n,i,o,r,s,a)=>{let d=e.points.length-1,c=t.has(0),u=t.has(d),m={mode:void 0},p={mode:void 0};if(it(e.points.length>1,"Do not attempt to bind linear elements with a single point"),!c&&!u)return{start:m,end:p};if(c&&u)return{start:{mode:null},end:{mode:null}};if(!Pt(s))return m=c?{mode:null}:m,p=u?{mode:null}:p,{start:m,end:p};if(U(e))return Rl(e,t,o,r,a?.zoom);let f=c?e.endBinding:e.startBinding,h=t.get(c?0:d)?.point;it(h,`Local point must be defined for ${c?"start":"end"} dragging`);let E=C.getPointGlobalCoordinates(e,h,o),g=Nt(E,r,o,lt(s.zoom)),x=g&&(a?.angleLocked?Ot(te(n,i),g,o):Ot(E,g,o)),w=f?o.get(f.elementId):void 0,y=f&&w&&Ne(f.fixedPoint,w,o),b=w&&y&&xt({point:y,element:w,elementsMap:o,threshold:0,overrideShouldTestInside:!0});if(f&&f.elementId===g?.id)return it(!a?.newArrow||s.selectedLinearElement?.initialState.origin,"appState.selectedLinearElement.initialState.origin must be defined for new arrows"),{start:{mode:"inside",element:g,focusPoint:c?E:a?.newArrow?s.selectedLinearElement.initialState.origin:C.getPointAtIndexGlobalCoordinates(e,0,o)},end:{mode:"inside",element:g,focusPoint:u?E:C.getPointAtIndexGlobalCoordinates(e,-1,o)}};if(a?.altKey)return{start:c?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:m,end:u?g?{mode:"inside",element:g,focusPoint:E}:{mode:null}:p};let I=g?x?{mode:"inside",element:g,focusPoint:E}:{mode:"orbit",element:g,focusPoint:Lr(e,E,g,c?"start":"end",o,s.zoom,s.isMidpointSnappingEnabled)||E}:{mode:null},A=C.getPointAtIndexGlobalCoordinates(e,c?-1:0,o),T=y&&w&&xt({point:E,element:w,elementsMap:o,threshold:lt(s.zoom),overrideShouldTestInside:!0}),O=(a?.newArrow?s.selectedLinearElement?.initialState.arrowStartIsInside:f?.mode==="inside")?{mode:void 0}:w&&!b&&!T&&s.selectedLinearElement?.initialState.altFocusPoint?{mode:"orbit",element:w,focusPoint:s.selectedLinearElement.initialState.altFocusPoint}:a?.angleLocked&&w?{mode:"orbit",element:w,focusPoint:Lr(e,A,w,c?"end":"start",o,s.zoom,s.isMidpointSnappingEnabled)||A}:{mode:void 0};return{start:c?I:O,end:u?I:O}},Fp=(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(it(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(!Pt(o))return u=d?{mode:null}:u,m=c?{mode:null}:m,{start:u,end:m};if(U(e))return Rl(e,t,n,i);if(r?.newArrow){let{start:p,end:f}=kp(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;it(p,"Local point must be defined for start dragging");let f=C.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=Cl(f,e.startBinding,e.endBinding,n,i,s,e,r?.finalize);return{start:h,end:E}}if(c){let p=t.get(l)?.point;it(p,"Local point must be defined for end dragging");let f=C.getPointGlobalCoordinates(e,p,n),{current:h,other:E}=Cl(f,e.endBinding,e.startBinding,n,i,s,e,r?.finalize);return{start:E,end:h}}return{start:u,end:m}},My=(e,t,n)=>{e.forEach(i=>{Op(i,new Map,1/0,1/0,t,n)})},It=(e,t,n,i,o,r,s=!0)=>{let a=o.getNonDeletedElementsMap(),l;U(e)?l={elementId:t.id,mode:"orbit",...Up(e,t,i,a,s)}:l={elementId:t.id,mode:n,...Xn(e,t,i,a,r)},o.mutateElement(e,{[i==="start"?"startBinding":"endBinding"]:l}),kl(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},ve=(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},De=(e,t,n)=>{if(!de(e))return;let{simultaneouslyUpdated:i}=n??{},o=Np(i),r=t.getNonDeletedElementsMap();n?.changedElements&&(r=new Map(r),n.changedElements.forEach(a=>{r.set(a.id,a)})),Oo(r,e,a=>{if(!H(a)||a.isDeleted||!Rp(a,e))return;let l=a.startBinding?r.get(a.startBinding.elementId):null,d=a.endBinding?l?.id===a.endBinding.elementId?l:r.get(a.endBinding.elementId):null;if(o.has(a.id))return;let c=ko(r,a,(m,p)=>{if(m&&de(m)&&(p==="startBinding"||p==="endBinding")&&(e.id===a[p]?.elementId||e.id===a[p==="startBinding"?"endBinding":"startBinding"]?.elementId)){let f=ut(a,p,a[p],m,r);if(f)return[p==="startBinding"?0:a.points.length-1,{point:f}]}return null}).filter(m=>m!==null);C.movePoints(a,t,new Map(c),{moveMidPointsWithElement:!!l&&l?.id===d?.id});let u=V(a,r);u&&!u.isDeleted&&Cn(a,t,!1)})},Gl=(e,t,n,i,o)=>{it(!U(e),"Elbow arrows not supported for indirect updates");let r=e[t],s=r&&n.get(r.elementId),a=C.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?0:-1,n),l=s&&xt({element:s,point:a,elementsMap:n,threshold:lt(o.zoom)}),d=t==="startBinding"?"start":"end";if(ve(e,d,i),l){let c=t==="startBinding"?0:e.points.length-1,u=e.points[c],m=Nl(e,new Map([[c,{point:u}]]),a[0],a[1],n,i.getNonDeletedElements(),o);m[d]&&m[d].element?.id===s.id&&m[d].mode&&It(e,s,m[d].mode,d,i,m[d].focusPoint)}},Ty=(e,t,n,i)=>{if(H(e)){let o=t.getNonDeletedElementsMap();e.startBinding&&Gl(e,"startBinding",o,t,n),e.endBinding&&Gl(e,"endBinding",o,t,n)}else De(e,t,{...i,changedElements:new Map([[e.id,e]])})},Rp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,Np=e=>new Set((e||[]).map(t=>t.id)),Dl=(e,t,n,i,o,r,s)=>{let a=zt(Mi(t,e));return!n||!i?a:zp(o,n,r,s)?Ii(n,i,e):zt(Mi(e,re(n,r)))},zp=(e,t,n,i)=>{let o=rn(t,n,e),r=lt(i);return o>r?null:o},ts=(e,t,n,i,o,r=!0)=>{let s=U(e),a=C.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i);if(e.points.length<2)return a;let l=Ha(t)&&s?Hp(e,t,i,a):a,d=o&&!s?o[1]:C.getPointAtIndexGlobalCoordinates(e,n==="start"?1:-2,i),c=Be(t,e),u=nt(t,i),m=bt(u),p=null;if(s){let f=Ue(Ii(t,u,a)),E=(r?as(t,i,l,.05,e):void 0)||a,g=te(f?m[0]:E[0],f?E[1]:m[1]),x=o??Go(g,Lo(Co(os(Mi(E,g)),Math.max(t.width,t.height)*2),g));if(p=sn(t,i,x,c).sort(_t)[0],!p){let w=te(f?E[0]:m[0],f?m[1]:E[1]),y=Go(w,Lo(Co(os(Mi(E,w)),Math.max(t.width,t.height)*2),w));p=sn(t,i,y,Gn).sort(_t)[0]}}else{let f=o;if(!f){let h=Co(os(Mi(l,d)),un(l,d)+Math.max(t.width,t.height)+c*2);f=o??Go(Lo(h,d),Lo(Co(h,-1),d))}p=un(l,d)<1?l:sn(t,i,f,c).sort((h,E)=>_t(h,d)-_t(E,d))[0]}return!p||_t(l,p)<Lp?l:p},Hp=(e,t,n,i)=>{let o=re(t,n),r=se(i,o,-t.angle),s=Be(t,e);return r[0]<t.x&&r[1]<t.y?r[1]-t.y>-s?se(te(t.x-s,t.y),o,t.angle):se(te(t.x,t.y-s),o,t.angle):r[0]<t.x&&r[1]>t.y+t.height?r[0]-t.x>-s?se(te(t.x,t.y+t.height+s),o,t.angle):se(te(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?se(te(t.x+t.width,t.y+t.height+s),o,t.angle):se(te(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?se(te(t.x+t.width,t.y-s),o,t.angle):se(te(t.x+t.width+s,t.y),o,t.angle):i},as=(e,t,n,i=.05,o)=>{let{x:r,y:s,width:a,height:l,angle:d}=e,c=re(e,t,-.1,-.1),u=se(n,c,-d),m=o?Be(e,o):0,p=rs(i*l,5,80),f=rs(i*a,5,80);if(!(un(c,u)<m)){if(u[0]<=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return se(te(r-m,c[1]),c,d);if(u[1]<=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return se(te(c[0],s-m),c,d);if(u[0]>=r+a/2&&u[1]>c[1]-p&&u[1]<c[1]+p)return se(te(r+a+m,c[1]),c,d);if(u[1]>=s+l/2&&u[0]>c[0]-f&&u[0]<c[0]+f)return se(te(c[0],s+l+m),c,d);if(e.type==="diamond"){let h=m,E=te(r+a/4-h,s+l/4-h),g=te(r+3*a/4+h,s+l/4-h),x=te(r+a/4-h,s+3*l/4+h),w=te(r+3*a/4+h,s+3*l/4+h);if(un(E,u)<Math.max(f,p))return se(E,c,d);if(un(g,u)<Math.max(f,p))return se(g,c,d);if(un(x,u)<Math.max(f,p))return se(x,c,d);if(un(w,u)<Math.max(f,p))return se(w,c,d)}}},_p=(e,t,n)=>{let i=e[t];if(!i)return{element:null,fixedPoint:null,focusPoint:null,binding:i,mode:null};let o=n.get(i.elementId);return{element:o,fixedPoint:i.fixedPoint,focusPoint:Ne(nn(i.fixedPoint),o,n),binding:i,mode:i.mode}},Ol=e=>e.width*e.height,ut=(e,t,n,i,o,r)=>{if(n==null||n.elementId!==i.id&&e.points.length>2||Cp(e.points[e.points.length-1],te(0,0)))return null;let s=Ne(nn(n.fixedPoint),i,o);if(n.mode==="inside")return C.createPointAt(e,o,s[0],s[1],null);let{element:a,focusPoint:l}=_p(e,t==="startBinding"?"endBinding":"startBinding",o),d=C.getPointAtIndexGlobalCoordinates(e,t==="startBinding"?1:-2,o),c=e.points.length===2&&l||d,u=c&&Go(s,c),m=a&&u&&sn(a,o,u,Be(a,e)).sort((w,y)=>_t(w,s)-_t(y,s))[0],p=u&&sn(i,o,u,Be(i,e)).sort((w,y)=>_t(w,c)-_t(y,c))[0],f=e.startArrowhead!==null,h=e.endArrowhead!==null,E=!f&&!h||t==="startBinding"&&f||t==="endBinding"&&h?s:p||s;if(a&&p&&!r&&Ol(a)<Ol(i)*2&&xt({element:a,point:p,elementsMap:o,threshold:Be(a,e),overrideShouldTestInside:!0}))return C.createPointAt(e,o,E[0],E[1],null);let x=un(a&&(m||l)||d,p||s)<=Gp;return a?x?C.createPointAt(e,o,E?.[0]||s[0],E?.[1]||s[1],null):C.createPointAt(e,o,p?.[0]||s[0],p?.[1]||s[1],null):C.createPointAt(e,o,x?s[0]:p?.[0]??s[0],x?s[1]:p?.[1]??s[1],null)},Up=(e,t,n,i,o=!0,r=!0)=>{let s=[t.x,t.y,t.x+t.width,t.y+t.height],a=o?ts(e,t,n,i,void 0,r):C.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),l=te(s[0]+(s[2]-s[0])/2,s[1]+(s[3]-s[1])/2),d=se(a,l,-t.angle);return{fixedPoint:nn([(d[0]-t.x)/t.width,(d[1]-t.y)/t.height])}},Xn=(e,t,n,i,o)=>{let r=o||C.getPointAtIndexGlobalCoordinates(e,n==="start"?0:-1,i),s=re(t,i),a=se(r,s,-t.angle),l=(a[0]-t.x)/t.width,d=(a[1]-t.y)/t.height;return{fixedPoint:nn([l,d])}},zl=(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,jn(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},vy=(e,t)=>{let n=kl(e);for(let i of t)mn.unbindAffected(n,i,(o,r)=>ye(o,n,r)),pn.unbindAffected(n,i,(o,r)=>ye(o,n,r))},Ti=(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},Hl=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),Oo=(e,t,n)=>{de(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},ko=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(ce(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(H(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},mn=class{static unbindAffected(t,n,i){n&&ko(t,n,o=>{!o||o.isDeleted||Oo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:Ti(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||ko(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:Ti(o.boundElements,new Set,new Array(n))}),Q(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:Ti(o.boundElements,new Set,new Array(n))}))))})}},pn=class{static unbindAffected(t,n,i){n&&Oo(t,n,o=>{!o||o.isDeleted||ko(t,o,(r,s,a)=>{a===n.id&&i(o,{[s]:null})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||Oo(t,n,(o,r,s)=>{if(!o||o.isDeleted){i(n,{boundElements:Ti(n.boundElements,new Set([s]))});return}Q(o)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===o.id?o.containerId!==n.id&&i(o,{containerId:n.id}):(o.containerId!==null&&i(o,{containerId:null}),i(n,{boundElements:Ti(n.boundElements,new Set([o.id]))})))})}},Ne=(e,t,n)=>{let[i,o]=nn(e);return se(te(t.x+t.width*i,t.y+t.height*o),re(t,n),t.angle)},Wp=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?Ne(e.startBinding.fixedPoint,n,t):te(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?Ne(e.endBinding.fixedPoint,i,t):te(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},_l=(e,t)=>{let[n,i]=Wp(e,t);return[C.pointFromAbsoluteCoords(e,n,t),C.pointFromAbsoluteCoords(e,i,t)]},Yp=e=>Array.isArray(e)&&e.length===2&&e.every(t=>Number.isFinite(t)),nn=e=>{if(!Yp(e))return[.5001,.5001];let t=1e-4;return Math.abs(e[0]-.5)<t||Math.abs(e[1]-.5)<t?e.map(n=>Math.abs(n-.5)<t?.5001:n):e},jp=e=>e.type==="ellipse"||e.type==="diamond"?e.type:"rectangle",Xp={rectangle:[{centerAngle:0,sectorWidth:75,side:"right"},{centerAngle:45,sectorWidth:15,side:"bottom-right"},{centerAngle:90,sectorWidth:75,side:"bottom"},{centerAngle:135,sectorWidth:15,side:"bottom-left"},{centerAngle:180,sectorWidth:75,side:"left"},{centerAngle:225,sectorWidth:15,side:"top-left"},{centerAngle:270,sectorWidth:75,side:"top"},{centerAngle:315,sectorWidth:15,side:"top-right"}],diamond:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}],ellipse:[{centerAngle:0,sectorWidth:15,side:"right"},{centerAngle:45,sectorWidth:75,side:"bottom-right"},{centerAngle:90,sectorWidth:15,side:"bottom"},{centerAngle:135,sectorWidth:75,side:"bottom-left"},{centerAngle:180,sectorWidth:15,side:"left"},{centerAngle:225,sectorWidth:75,side:"top-left"},{centerAngle:270,sectorWidth:15,side:"top"},{centerAngle:315,sectorWidth:75,side:"top-right"}]},$p=e=>e.map((t,n)=>{let i=t.sectorWidth/2,o=t.centerAngle-i,r=t.centerAngle+i;return o=(o%360+360)%360,r=(r%360+360)%360,{start:o,end:r,side:t.side}}),Vp=(e,t)=>{let[n,i]=e,o=n-.5,r=i-.5,s=Math.atan2(r,o);s<0&&(s+=2*Math.PI);let a=s*180/Math.PI,l=Xp[t],d=$p(l);for(let m of d)if(m.start<=m.end){if(a>=m.start&&a<=m.end)return m.side}else if(a>=m.start||a<=m.end)return m.side;let c=1/0,u=l[0].side;for(let m of l){let p=Math.abs(a-m.centerAngle);p>180&&(p=360-p),p<c&&(c=p,u=m.side)}return u},Dy=(e,t)=>{let n=t.get(e.elementId);if(!n||n.isDeleted||!de(n))return null;let i=re(n,t),o=jp(n),r=Vp(nn(e.fixedPoint),o),s=.01;if(n.type==="diamond"){let[a,l]=tn(n),[d,c,u,m]=a,p,f;switch(r){case"left":{if(l.length>=3){let E=l[2][1];p=E[0]-s,f=E[1]}else{let h=Te(c[1],u[0]);p=h[0]-s,f=h[1]}break}case"right":{if(l.length>=1){let E=l[0][1];p=E[0]+s,f=E[1]}else{let h=Te(m[1],d[0]);p=h[0]+s,f=h[1]}break}case"top":{if(l.length>=4){let E=l[3][1];p=E[0],f=E[1]-s}else{let h=Te(u[1],m[0]);p=h[0],f=h[1]-s}break}case"bottom":{if(l.length>=2){let E=l[1][1];p=E[0],f=E[1]+s}else{let h=Te(d[1],c[0]);p=h[0],f=h[1]+s}break}case"top-right":{let h=Te(m[0],m[1]);p=h[0]+s*.707,f=h[1]-s*.707;break}case"bottom-right":{let h=Te(d[0],d[1]);p=h[0]+s*.707,f=h[1]+s*.707;break}case"bottom-left":{let h=Te(c[0],c[1]);p=h[0]-s*.707,f=h[1]+s*.707;break}case"top-left":{let h=Te(u[0],u[1]);p=h[0]-s*.707,f=h[1]-s*.707;break}default:return null}return se(te(p,f),i,n.angle)}if(n.type==="ellipse"){let a=n.x+n.width/2,l=n.y+n.height/2,d=n.width/2,c=n.height/2,u,m;switch(r){case"top":{u=a,m=l-c-s;break}case"right":{u=a+d+s,m=l;break}case"bottom":{u=a,m=l+c+s;break}case"left":{u=a-d-s,m=l;break}case"top-right":{let p=-Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f+s*.707,m=l+h-s*.707;break}case"bottom-right":{let p=Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f+s*.707,m=l+h+s*.707;break}case"bottom-left":{let p=3*Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f-s*.707,m=l+h+s*.707;break}case"top-left":{let p=-3*Math.PI/4,f=d*Math.cos(p),h=c*Math.sin(p);u=a+f-s*.707,m=l+h-s*.707;break}default:return null}return se(te(u,m),i,n.angle)}if(hi(n)){let[a,l]=en(n),[d,c,u,m]=a,p,f;switch(r){case"top":{let h=Te(d[0],d[1]);p=h[0],f=h[1]-s;break}case"right":{let h=Te(c[0],c[1]);p=h[0]+s,f=h[1];break}case"bottom":{let h=Te(u[0],u[1]);p=h[0],f=h[1]+s;break}case"left":{let h=Te(m[0],m[1]);p=h[0]-s,f=h[1];break}case"top-left":{if(l.length>=1){let h=l[0],E=h[0],g=h[3],x=Te(E,g);p=x[0]-s*.707,f=x[1]-s*.707}else p=n.x-s,f=n.y-s;break}case"top-right":{if(l.length>=2){let h=l[1],E=h[0],g=h[3],x=Te(E,g);p=x[0]+s*.707,f=x[1]-s*.707}else p=n.x+n.width+s,f=n.y-s;break}case"bottom-right":{if(l.length>=3){let h=l[2],E=h[0],g=h[3],x=Te(E,g);p=x[0]+s*.707,f=x[1]+s*.707}else p=n.x+n.width+s,f=n.y+n.height+s;break}case"bottom-left":{if(l.length>=4){let h=l[3],E=h[0],g=h[3],x=Te(E,g);p=x[0]-s*.707,f=x[1]+s*.707}else p=n.x-s,f=n.y+n.height+s;break}default:return null}return se(te(p,f),i,n.angle)}return null},Te=(e,t)=>te((e[0]+t[0])/2,(e[1]+t[1])/2);var ls=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>G(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},C=class e{elementId;selectedPointsIndices;initialState;isDragging;lastUncommittedPoint;lastCommittedPoint;pointerOffset;hoverPointIndex;segmentMidPointHoveredCoords;hoveredFocusPointBinding;draggedFocusPointBinding;elbowed;customLineAngle;isEditing;pointerDownState;constructor(t,n,i=!1){this.elementId=t.id,Wl(t.points[0],G(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.hoveredFocusPointBinding=null,this.draggedFocusPointBinding=null,this.elbowed=U(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[d,c,u,m]=$(n.selectionElement,o),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);Ge(d,"Element being dragged must exist in the scene"),Ge(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??ql(m,d.points[c]),f=0,h=0;if(Di(t)){let[b,I]=e._getShiftLockedDelta(d,s,m,G(i,o),t[On.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),p),A=G(b+m[0],I+m[1]);f=A[0]-u[0],h=A[1]-u[1]}else{let b=e.createPointAt(d,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[On.CTRL_OR_CMD]?null:n.getEffectiveGridSize());f=b[0]-u[0],h=b[1]-u[1]}let E=null,{positions:g,updates:x}=Zl([c],f,h,i,o,s,d,a,n,Di(t),t.altKey,r);if(e.movePoints(d,n.scene,g,{startBinding:x?.startBinding,endBinding:x?.endBinding,moveMidPointsWithElement:x?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled}),Ae(d,!1)&&Pt(n.state)&&(E=x?.suggestedBinding??null),Ae(d)&&$l(e.getPointGlobalCoordinates(d,d.points[d.points.length-1],s),d,a,s,n.scene),n.state.selectedLinearElement?.customLineAngle===p&&r.initialState.altFocusPoint&&(!E||Jp(n.state.suggestedBinding??[],E)))return null;let w=Ae(d)&&d.startBinding&&s.get(d.startBinding.elementId);return{selectedLinearElement:{...r,customLineAngle:p,initialState:{...r.initialState,altFocusPoint:!r.initialState.altFocusPoint&&w&&x?.suggestedBinding?.element.id!==w.id?Vl(d,G(d.x,d.y),w,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled):r.initialState.altFocusPoint}},suggestedBinding:E}}static handlePointDragging(t,n,i,o,r){let s=n.scene.getNonDeletedElementsMap(),a=n.scene.getNonDeletedElements(),{elbowed:l,elementId:d,initialState:c}=r,u=Array.from(r.selectedPointsIndices??[]),{lastClickedPoint:m}=c,p=e.getElement(d,s);Ge(p,"Element being dragged must exist in the scene"),Ge(p.points.length>1,"Element must have at least 2 points"),Ge(u,"There must be selected points in order to drag them"),l&&u.some((S,z)=>S>0&&S!==p.points.length-1?(u[z]=p.points.length-1,m=p.points.length-1,!0):!1),Ge(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??ql(h,p.points[m]),x=u.includes(0),w=u.includes(p.points.length-1),y=0,b=0;if(Di(t)&&E){let[S,z]=e._getShiftLockedDelta(p,s,h,G(i,o),t[On.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),g),W=G(S+h[0],z+h[1]);y=W[0]-f[0],b=W[1]-f[1]}else{let S=e.createPointAt(p,s,i-r.pointerOffset.x,o-r.pointerOffset.y,t[On.CTRL_OR_CMD]?null:n.getEffectiveGridSize());y=S[0]-f[0],b=S[1]-f[1]}let I=null,{positions:A,updates:T}=Zl(u,y,b,i,o,s,p,a,n,Di(t)&&E,t.altKey,r);e.movePoints(p,n.scene,A,{startBinding:T?.startBinding,endBinding:T?.endBinding,moveMidPointsWithElement:T?.moveMidPointsWithElement},{isBindingEnabled:n.state.isBindingEnabled,isMidpointSnappingEnabled:n.state.isMidpointSnappingEnabled}),Ae(p,!1)&&Pt(n.state)&&(x||w)&&(I=T?.suggestedBinding??null),Ae(p)&&x!==w&&$l(e.getPointGlobalCoordinates(p,x?p.points[0]:p.points[p.points.length-1],s),p,a,s,n.scene),V(p,s)&&Cn(p,n.scene,!1);let O=l?w?[p.points.length-1]:[0]:u,L=l?O[0]:m,k=!x&&!w?e.getPointGlobalCoordinates(p,f,s):null,B=L,X=Ae(p)&&p.startBinding&&s.get(p.startBinding.elementId),_=Ae(p)&&p.endBinding&&s.get(p.endBinding.elementId),ie=w&&X&&T?.suggestedBinding?.element.id!==X.id?X:x&&_&&T?.suggestedBinding?.element.id!==_.id?_:null;return{selectedLinearElement:{...r,selectedPointsIndices:O,initialState:{...r.initialState,lastClickedPoint:L,altFocusPoint:!r.initialState.altFocusPoint&&Ae(p)&&ie?Vl(p,G(p.x,p.y),ie,"start",s,n.state.zoom,n.state.isMidpointSnappingEnabled):r.initialState.altFocusPoint},segmentMidPointHoveredCoords:k,hoverPointIndex:B,isDragging:!0,customLineAngle:g},suggestedBinding:I}}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),{elementId:s,selectedPointsIndices:a,isDragging:l,initialState:d}=n,c=e.getElement(s,r);if(!c)return n;if(l&&a)for(let u of a)(u===0||u===c.points.length-1)&&ef(c.points,i.zoom.value)&&(Lt(c)&&o.mutateElement(c,{...Kl(c,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(c,o,new Map([[u,{point:u===0?c.points[c.points.length-1]:c.points[0]}]])));return{...n,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:l||t.shiftKey?!l&&t.shiftKey&&d.prevSelectedPointsIndices?.includes(d.lastClickedPoint)?a&&a.filter(u=>u!==d.lastClickedPoint):a:a?.includes(d.lastClickedPoint)?[d.lastClickedPoint]:a,isDragging:!1,customLineAngle:null,initialState:{...n.initialState,origin:null,arrowStartIsInside:!1}}}static getEditorMidPoints=(t,n,i)=>{let o=V(t,n);if(!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&&kn(G(c[0],c[1]),G(n.x,n.y))<=d)return c;let u=0,m=e.getEditorMidPoints(s,o,i);for(;u<m.length;){if(m[u]!==null&&kn(m[u],G(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?kn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=kn(n,i);if(t.points.length>2&&t.roundness){let[a,l]=jl(t);Ge(a.length===0&&l.length>0,"Only linears built out of curves are supported"),Ge(a.length+l.length>=o,"Invalid segment index while calculating mid point"),s=qp(l[o])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(U(t)){Ge(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=Ul(t.points[n-1],t.points[n]);return G(t.x+r[0],t.y+r[1])}let[i,o]=jl(t);if(Ge(i.length===0&&o.length>0||i.length>0&&o.length===0,"Only linears built out of either segments or curves are supported"),Ge(i.length+o.length>=n,"Invalid segment index while calculating mid point"),i.length){let r=i[n-1];return Ul(r[0],r[1])}if(o.length){let r=o[n-1];return Kp(r,.5)}Ge(!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=G(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[On.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,initialState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,origin:p,segmentMidpoint:{value:m,index:f,added:!1},arrowStartIsInside:!!n.state.newElement&&(n.state.bindMode==="inside"||n.state.bindMode==="skip"),altFocusPoint:null},selectedPointsIndices:[u.points.length-1],lastUncommittedPoint:null},d.didAddPoint=!0,d;let h=e.getPointIndexUnderCursor(u,l,a.zoom,o.x,o.y);(h>=0||m)&&(d.hitElement=u);let[E,g,x,w]=$(u,l),y=(E+x)/2,b=(g+w)/2,I=h>-1&&Ce(G(u.x+u.points[h][0],u.y+u.points[h][1]),G(y,b),u.angle),A=h>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(h)?tf([...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:A,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:Wl(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(Di(t)&&c.length>=2){let p=c[c.length-2],[f,h]=e._getShiftLockedDelta(d,l,p,G(n,i),t[On.CTRL_OR_CMD]?null:o.getEffectiveGridSize());m=G(f+p[0],h+p[1])}else m=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[On.CTRL_OR_CMD]||U(d)?null:o.getEffectiveGridSize());return u===a?e.movePoints(d,o.scene,new Map([[d.points.length-1,{point:m}]])):e.addPoints(d,o.scene,[m]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=$(t,i),l=(o+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Ce(G(c+n[0],u+n[1]),G(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 Ce(G(c+d[0],u+d[1]),G(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[,,,,r,s]=$(t,i),a=G(r,s),l=t.points[o],{x:d,y:c}=t;return l?Ce(G(d+l[0],c+l[1]),a,t.angle):Ce(G(d,c),a,t.angle)}static pointFromAbsoluteCoords(t,n,i){if(U(t))return G(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]=Ce(G(n[0],n[1]),G(l,d),-t.angle);return G(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(kn(G(o,r),G(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=Yl(i,o,r),[a,l,d,c]=$(t,n),u=(a+d)/2,m=(l+c)/2,[p,f]=Ce(G(s[0],s[1]),G(u,m),-t.angle);return G(p-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=ls(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){Ge(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);Ge(s,"The linear element does not exist in the provided Scene"),Ge(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?G((p[0]+E[0])/2,(p[1]+E[1])/2):G(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:G(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));Lt(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=G(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:d}=ls({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,i){let o=[...t.points,...i];Lt(t)&&t.polygon&&(o[0]=G(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=ls({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o,r){let{points:s}=t;if(Lt(t)&&t.polygon){let u=i.get(0),m=i.get(s.length-1);u?i.set(s.length-1,{point:G(u.point[0],u.point[1]),isDragging:u.isDragging}):m&&i.set(0,{point:G(m.point[0],m.point[1]),isDragging:m.isDragging})}let a=i.get(0)?.point??G(0,0),[l,d]=a,c=U(t)?[i.get(0)?.point??s[0],i.get(s.length-1)?.point??s[s.length-1]]:s.map((u,m)=>{let p=i.get(m)?.point??u;return o?.moveMidPointsWithElement&&m!==0&&m!==s.length-1&&!i.has(m)?p:G(p[0]-l,p[1]-d)});e._updatePoints(t,n,c,l,d,o,{isDragging:Array.from(i.values()).some(u=>u.isDragging),isBindingEnabled:r?.isBindingEnabled,isMidpointSnappingEnabled:r?.isMidpointSnappingEnabled})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&U(r)||!r)return!1;let{segmentMidpoint:s}=t.initialState;if(s.added||s.value===null||s.index===null||t.initialState.origin===null)return!1;let a=t.initialState.origin,l=kn(a,G(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<Qp/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.initialState,d={pointerDownState:t.initialState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,o&&!U(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.initialState,segmentMidpoint:{...t.initialState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,i,o,r,s,a){if(U(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding),s?.endBinding!==void 0&&(l.endBinding=s.endBinding),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1,isBindingEnabled:a?.isBindingEnabled,isMidpointSnappingEnabled:a?.isMidpointSnappingEnabled})}else{let l=ds(t,i),d=ds(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=Ce(G(o,r),G(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]=Yl(o[0],o[1],r),{width:c,height:u}=Ql(a[0],a[1],l,d,s);return Ce(G(c,u),G(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=G(d,c),E=Ce(G(r,s),h,t.angle),g=Ce(G(a,s),h,t.angle),x=Ce(G(u,m),h,-t.angle),w=Ce(G(p,m),h,-t.angle),y=Ce(G(u,f),h,-t.angle),b=Ce(G(p,f),h,-t.angle);return E[0]<g[0]&&E[1]>=g[1]?(r=Math.min(r,y[0]),a=Math.max(a,Math.max(w[0],b[0])),s=Math.min(s,x[1]),l=Math.max(l,b[1])):E[0]>=g[0]&&E[1]>g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(x[0],w[0])),s=Math.min(s,y[1]),l=Math.max(l,w[1])):E[0]>=g[0]?(r=Math.min(r,w[0]),a=Math.max(a,y[0]),s=Math.min(s,b[1]),l=Math.max(l,x[1])):E[1]<=g[1]&&(r=Math.min(r,Math.min(w[0],x[0])),a=Math.max(a,b[0]),s=Math.min(s,w[1]),l=Math.max(l,y[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o=Ke.generateElementShape(t,null),r=Dt(o[0]),[s,a,l,d]=Bi(r),c=s+t.x,u=a+t.y,m=l+t.x,p=d+t.y,f=(c+m)/2,h=(u+p)/2,E=i&&V(t,n);return E?e.getMinMaxXYWithBoundText(t,n,[c,u,m,p],E):[c,u,m,p,f,h]};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!U(a))return t;if(n&&n>0&&n<a.points.length){let l=Ue(zt(Zp(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((p,f)=>(p[f.index]=f,p),{});d[n]={index:n,start:G(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:G(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=G(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)})}},tf=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null},Zl=(e,t,n,i,o,r,s,a,l,d,c,u)=>{let m=new Map(e.map(_=>[_,{point:G(s.points[_][0]+t,s.points[_][1]+n),isDragging:!0}]));if(!H(s))return{positions:m};let p=e.includes(0),f=e.includes(s.points.length-1),{start:h,end:E}=ss(s,m,i,o,r,a,l.state,{newArrow:!!l.state.newElement,angleLocked:d,altKey:c});if(U(s)){let _=p?h.element:f?E.element:null;return{positions:m,updates:{suggestedBinding:_?{element:_,midPoint:l.state.isMidpointSnappingEnabled?as(_,r,G(i-u.pointerOffset.x,o-u.pointerOffset.y)):void 0}:null}}}if(!p&&!f){let _={...s,points:s.points.map((F,S)=>m.get(S)?.point??F)},ie=new Map(m);if(s.startBinding){let F=r.get(s.startBinding.elementId);if(F){let S=ut(_,"startBinding",s.startBinding,F,r)??null;S&&ie.set(0,{point:S,isDragging:!0})}}if(s.endBinding){let F=r.get(s.endBinding.elementId);if(F){let S=ut(_,"endBinding",s.endBinding,F,r)??null;S&&ie.set(s.points.length-1,{point:S,isDragging:!0})}}return{positions:ie}}if(p===f)return{positions:m};let g={suggestedBinding:null};h.mode===null?g.startBinding=null:h.mode?(g.startBinding={elementId:h.element.id,mode:h.mode,...Xn(s,h.element,"start",r,h.focusPoint)},p&&(g.startBinding.mode==="orbit"||!$n("COMPLEX_BINDINGS"))&&(g.suggestedBinding=h.element?{element:h.element,midPoint:Xl(G(i-u.pointerOffset.x,o-u.pointerOffset.y),h.element,r,l.state.zoom)}:null)):p&&(g.suggestedBinding=l.state.suggestedBinding),E.mode===null?g.endBinding=null:E.mode?(g.endBinding={elementId:E.element.id,mode:E.mode,...Xn(s,E.element,"end",r,E.focusPoint)},f&&(g.endBinding.mode==="orbit"||!$n("COMPLEX_BINDINGS"))&&(g.suggestedBinding=E.element?{element:E.element,midPoint:Xl(G(i-u.pointerOffset.x,o-u.pointerOffset.y),E.element,r,l.state.zoom)}:null)):f&&(g.suggestedBinding=l.state.suggestedBinding);let x=p?G(s.points[0][0]+t,s.points[0][1]+n):s.points[0],w=f?G(s.points[s.points.length-1][0]+t,s.points[s.points.length-1][1]+n):s.points[s.points.length-1],y={...s,points:[x,...s.points.slice(1,-1),w],startBinding:g.startBinding===void 0?s.startBinding:g.startBinding===null?null:g.startBinding,endBinding:g.endBinding===void 0?s.endBinding:g.endBinding===null?null:g.endBinding},b=s.endBinding&&y.startBinding&&p&&y.startBinding.elementId===s.endBinding.elementId,I=s.startBinding&&y.endBinding&&f&&s.startBinding.elementId===y.endBinding.elementId,A=y.endBinding?E.element??r.get(y.endBinding.elementId):null,T=b?y.points[y.points.length-1]:I&&l.state.bindMode!=="inside"&&$n("COMPLEX_BINDINGS")?y.points[0]:A&&ut(s,"endBinding",y.endBinding,A,r,f)||y.points[y.points.length-1];y.points[y.points.length-1]=T;let M=y.startBinding?h.element??r.get(y.startBinding.elementId):null,O=I&&$n("COMPLEX_BINDINGS")?y.points[0]:b&&l.state.bindMode!=="inside"&&$n("COMPLEX_BINDINGS")?T:M&&ut(s,"startBinding",y.startBinding,M,r,p)||y.points[0],L=!b&&!(I&&l.state.bindMode!=="inside"&&$n("COMPLEX_BINDINGS"))&&!!A,k=kn(O,y.points[0])!==0,B=new Set(e);M&&k&&B.add(0),A&&L&&B.add(s.points.length-1);let X=Array.from(B);return{updates:g,positions:new Map(X.map(_=>[_,_===0?{point:O,isDragging:!0}:_===s.points.length-1?{point:T,isDragging:!0}:m.get(_)]))}},ql=(e,t)=>Math.atan2(t[1]-e[1],t[0]-e[0]);P();import{arrayToMap as At}from"@excalidraw/common";import{isPointWithinBounds as Sf,pointFrom as fs}from"@excalidraw/math";P();import{vectorCross as nd,vectorFromPoint as Fo}from"@excalidraw/math";function Jl(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 nf(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var of=1e-6;function ed(e,t){let n=Fo(e[1],e[0]),i=Fo(t,e[0]),o=nd(n,i);return Math.abs(o)<of}function cs(e,t){let n=Fo(e[1],e[0]),i=Fo(t,e[0]);return nd(n,i)<0}function td(e,t){return ed(e,t[0])||ed(e,t[1])||(cs(e,t[0])?!cs(e,t[1]):cs(e,t[1]))}function id(e,t){return nf(Jl(e),Jl(t))&&td(e,t)&&td(t,e)}P();import{arrayToMap as rf}from"@excalidraw/common";import{getElementBounds as sf}from"@excalidraw/element";import{isArrowElement as af,isExcalidrawElement as lf,isFreeDrawElement as df,isLinearElement as cf,isTextElement as uf}from"@excalidraw/element";import{rangeIncludesValue as Ro,pointFrom as Ut,pointRotateRads as mf,rangeInclusive as No}from"@excalidraw/math";var pf=e=>e.type==="diamond"?[Ut(e.width/2,0),Ut(e.width,e.height/2),Ut(e.width/2,e.height),Ut(0,e.height/2)]:[Ut(0,0),Ut(0+e.width,0),Ut(0+e.width,e.height),Ut(0,e.height)],ff=e=>cf(e)||df(e)?e.points:pf(e),od=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},sd=e=>{let t=ff(e),{cx:n,cy:i}=od(t),o=Ut(n,i),r=t.map(c=>mf(c,o,e.angle)),{minX:s,minY:a,maxX:l,maxY:d}=od(r);return[s+e.x,a+e.y,l+e.x,d+e.y]},rd=(e,t,n=!1)=>{let i=sd(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},hf=(e,t)=>{let n=sd(e);return(Ro(n[0],No(t[0],t[2]))||Ro(t[0],No(n[0],n[2])))&&(Ro(n[1],No(t[1],t[3]))||Ro(t[1],No(n[1],n[3])))},ad=({elements:e,bounds:t,type:n,errorMargin:i=0})=>{lf(t)&&(t=sf(t,rf(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"?hf(s,o):n==="inside"?rd(s,o):rd(s,o,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);uf(s)&&s.containerId&&r.add(s.containerId),af(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 yf,isShallowEqual as Pf}from"@excalidraw/common";P();var Ef=(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}}},ld=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:us({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):St(s,r);return d.length?i(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:us(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),gf=(e,t)=>ms(e,t)!=null,ms=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),xf=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),dd=(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,...Ef(r,n,e)}}}return n.selectedGroupIds},r0=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),wf=(e,t)=>e.groupIds.includes(t),Oe=(e,t)=>{let n=[];for(let i of e.values())wf(i,t)&&n.push(i);return n},bf=(e,t)=>e.groupIds.find(n=>t[n]),s0=(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},a0=(e,t)=>e.filter(n=>!t[n]),l0=(e,t)=>{let n=new Map;return e.forEach(i=>{let o=i.groupIds.length===0?i.id:i.groupIds[i.groupIds.length-1],r=n.get(o)||[],s=V(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},cd=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},ud=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},md=e=>e.groupIds.length>0,pd=(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},zo=(e,t,n)=>{let i=xf(n),o=e.filter(u=>!ce(u)),r=new Map,s=new Map,a=u=>{let m=s.get(u.id)||[],p=V(u,t);p&&m.push(p),s.set(u.id,[...m,u])},l=(u,m)=>{let p=r.get(m)||[],f=V(u,t);f&&p.push(f),r.set(m,[...p,u])},d=(u,m)=>{let p=u.groupIds.indexOf(m,0);return u.groupIds.slice(0,p).length>0?l(u,u.groupIds[p-1]):a(u)},c=e.every(u=>gf(n,u));return o.forEach(u=>{let m=bf(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 fd=e=>{let t=new Set;return e.forEach(n=>{Z(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},ps=(e,t,n,i=!0)=>{let[o,r,s,a]=$(t,n),l=e.filter(d=>{let[c,u,m,p]=he(d,n),f=Wt(d,n);if(f){let[h,E,g,x]=he(f,n);c=Math.max(h,c),u=Math.max(E,u),m=Math.min(g,m),p=Math.min(x,p)}return d.locked===!1&&d.type!=="selection"&&!ce(d)&&o<=c&&r<=u&&s>=m&&a>=p});return l=i?fd(l):l,l=l.filter(d=>{let c=Wt(d,n);return c?fn(d,c,n):!0}),l},x0=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=hd(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},w0=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}(),St=(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)&&hn(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},b0=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:St(e,t,{includeBoundTextElement:!0}),us=(e,t)=>Pf(t.selectedElementIds,e)?t.selectedElementIds:e,If=(e,t)=>{let n=e.filter(q);if(n.length===1){let i=n[0],o=i.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===i.id||o.includes(s.id)))return new C(i,yf(t))}return null},y0=(e,t,n)=>({selectedLinearElement:If(e,t),...ld({editingGroupId:n.editingGroupId,selectedElementIds:fd(e).reduce((i,o)=>(ce(o)||(i[o.id]=!0),i),{})},t,n,null)});var Ed=(e,t,n)=>{let i=At(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 Vn(e,t,n){let i=hs(t,n),o=hs(e,n);return i.some(s=>o.some(a=>id(s,a)))}var gd=(e,t,n)=>Ho(ps(e,t,n,!1)).filter(i=>!Z(i)&&!i.frameId||i.frameId===t.id),Es=(e,t,n)=>ps([t],e,n).some(i=>i.id===t.id),O0=(e,t)=>{let n=At(e);return e.filter(i=>Vn(i,t,n))},En=(e,t,n)=>{let[i,o,r,s]=$(t,n),[a,l,d,c]=ke(e);return i<=a&&o<=l&&r>=d&&s>=c},fn=(e,t,n)=>En([e],t,n)||Vn(e,t,n)||Es(e,t,n),k0=(e,t,n)=>{let[i,o,r,s]=$(t,n);return Sf(fs(i,o),fs(e.x,e.y),fs(r,s))},F0=(e,t,n)=>{let i=At(e),o=t.flatMap(r=>Oe(e,r));return o.length===0?!0:!!o.find(r=>En([r],n,i)||Vn(r,n,i))},R0=(e,t,n)=>{let i=At(e),o=t.flatMap(r=>Oe(e,r));return o.length===0?!0:o.find(r=>En([r],n,i)||Vn(r,n,i))===void 0},N0=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,hn(e,i))}return t},hn=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},Af=e=>e.filter(t=>Z(t)),z0=e=>{let t=At(Af(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},H0=(e,t,n,i)=>{let o=hn(e,t.id),r=new Set(o),s=new Set([...gd(e,t,i),...o.filter(m=>Es(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(!Vn(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=dd(c,n);for(let[m,p]of Object.entries(u))if(p){let f=Oe(e,m);if(En(f,t,i))for(let h of f)r.add(h)}return[...r].filter(m=>!(Q(m)&&m.containerId))},_0=(e,t,n)=>Mf(Ho(e,gd(e,t,n)),t,n),Mf=(e,t,n)=>{let i=[],o=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>o.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>Oe(n,l)));s=!En(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},Wt=(e,t)=>e.frameId&&t.get(e.frameId)||null,U0=(e,t)=>{let n=new Set,i=At(e);e=Ho(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=Oe(e,a);if(l.some(d=>fn(d,t,i)))for(let d of l)r.push(d)}}else fn(s,t,i)&&r.push(s);return r},Tf=(e,t,n,i)=>{let o=At(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 Ho(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=V(d,o);c&&!s.has(c.id)&&!r.has(c.id)&&a.push(c)}for(let d of a)ye(d,o,{frameId:n.id});return e},xd=(e,t)=>{let n=new Map,i=new Map;for(let o of e)if(o.frameId){n.set(o.id,o);let r=i.get(o.frameId)||[];r.push(o);let s=V(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)ye(o,t,{frameId:null})},vf=(e,t)=>{let n=hn(e,t.id);return xd(n,At(e)),e},W0=(e,t,n,i)=>Tf(vf(e,n),t,n,i.state).slice(),Y0=(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=>Oe(e,l)).forEach(l=>o.add(l));let r=new Set,s=At(e);return o.forEach(a=>{a.frameId&&!Z(a)&&!wd(a,s,t)&&r.add(a)}),r.size>0&&xd(r,s),e},Ho=(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)Oe(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},Df=(e,t,n)=>{let i=Q(e)&&Me(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?Wt(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Wt(i,t)},wd=(e,t,n,i)=>{let o=i?.targetFrame??Df(e,t,n);if(!o)return!1;let r=Q(e)&&Me(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 fn(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=>Oe(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(St(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(fn(l,o,t))return s(!0),!0;return!1},j0=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Vn(e,t,i)||Es(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!En([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=wd(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},Bf="Frame",Lf="AI Frame",Cf=e=>co(e)?Bf:Lf,X0=e=>e.name===null?Cf(e):e.name,$0=(e,t)=>ad({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),V0=e=>{let t=At(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Uf=(e,t)=>vn(e)&&!t.imageCache.has(e.fileId),jo=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}},Wf=(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*=kf/100),r},Yf=(e,t,n)=>{let r=jo(e),[s,a,l,d]=$(e,t),c=q(e)||Se(e)?gn(s,l):e.width,u=q(e)||Se(e)?gn(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}},Pd=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=jo(e),{width:l,height:d,scale:c}=Yf(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,m=0;if(q(e)||Se(e)){let[g,x]=$(e,t);u=e.x>g?gn(e.x,g)*window.devicePixelRatio*c:0,m=e.y>x?gn(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=Tn.canvas(r);Wo(e,p,s,i),s.restore();let f=V(e,t),h=document.createElement("canvas"),E=h.getContext("2d");if(H(e)&&f){let[g,x,w,y]=$(e,t),b=Math.max(gn(g,w),gn(x,y));h.width=b*window.devicePixelRatio*c+a*c*10,h.height=b*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,A]=$(f,t);E.rotate(-e.angle);let T=(h.width-r.width)/2,M=(h.height-r.height)/2,O=h.width/2-(I-g)*window.devicePixelRatio*c-T-a*c,L=h.height/2-(A-x)*window.devicePixelRatio*c-M-a*c;E.translate(-O,-L),E.clearRect(-(f.width/2+Uo)*window.devicePixelRatio*c,-(f.height/2+Uo)*window.devicePixelRatio*c,(f.width+Uo*2)*window.devicePixelRatio*c,(f.height+Uo*2)*window.devicePixelRatio*c)}return{element:e,canvas:r,theme:o.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:m,boundTextElementVersion:V(e,t)?.version||null,containingFrameOpacity:Wt(e,t)?.opacity||100,boundTextCanvas:h,angle:e.angle,imageCrop:we(e)?e.crop:null}},d1=14,Id=typeof document<"u"?document.createElement("img"):{src:""};Id.src=`data:${ws.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 Sd=typeof document<"u"?document.createElement("img"):{src:""};Sd.src=`data:${ws.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 jf=(e,t,n)=>{t.fillStyle=n===Zn.DARK?"#2E2E2E":"#E7E7E7",t.fillRect(0,0,e.width,e.height);let i=Math.min(e.width,e.height),o=Math.min(i,Math.min(i*.4,100));t.drawImage(e.status==="error"?Sd:Id,e.width/2-o/2,e.height/2-o/2,o,o)},Wo=(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(Ke.generateElementShape(e,i));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Ke.generateElementShape(e,i).forEach(o=>{t.draw(o)});break}case"freedraw":{n.save();let o=Ke.generateElementShape(e,i);for(let r of o)typeof r=="string"?(n.fillStyle=i.theme===Zn.DARK?Yo(e.strokeColor):e.strokeColor,n.fill(new Path2D(r))):t.draw(r);n.restore();break}case"image":{n.save();let o=e.fileId!==null?i.imageCache.get(e.fileId):null,r=vn(e)?o?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,Gt(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight},c=i.theme===Zn.DARK&&o?.mimeType===ws.svg;if(c&&_f){let u=window.devicePixelRatio||1,m=document.createElement("canvas");m.width=e.width*u,m.height=e.height*u;let p=m.getContext("2d");if(p){p.scale(u,u),p.drawImage(r,s,a,l,d,0,0,e.width,e.height);let f=p.getImageData(0,0,m.width,m.height),h=f.data;for(let E=0;E<h.length;E+=4)h[E]=255-h[E],h[E+1]=255-h[E+1],h[E+2]=255-h[E+2];p.putImageData(f,0,0),n.drawImage(m,0,0,m.width,m.height,0,0,e.width,e.height)}}else c&&(n.filter=Ff),n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else jf(e,n,i.theme);n.restore();break}default:if(Q(e)){let o=Nf(e.text),r=o&&!n.canvas.isConnected;r&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",o?"rtl":"ltr"),n.save(),n.font=Rf(e),n.fillStyle=i.theme===Zn.DARK?Yo(e.strokeColor):e.strokeColor,n.textAlign=e.textAlign;let s=e.text.replace(/\r\n?/g,`
10
10
  `).split(`
11
- `),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=uo(e.fontSize,e.lineHeight),d=Ff(e.fontFamily,e.fontSize,l);for(let c=0;c<s.length;c++)n.fillText(s[c],a,c*l+d);n.restore(),r&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},Bi=new WeakMap,gd=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=Bi.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=$(e,t),l=a?.version||null,d=xe(e)?e.crop:null,c=Ut(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=xd(e,t,o,n,i);return u?(Bi.set(e,u),u):null}return r},fs=(e,t,n,i,o)=>{let r=e.element,s=_o(r),a=e.scale,[l,d,c,u]=j(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=$(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&&!zf(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"&&ht(r)){let h=$(r,o),E=Or(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((E.x+i.scrollX)*window.devicePixelRatio,(E.y+i.scrollY)*window.devicePixelRatio,at(r,h)*window.devicePixelRatio,xi(r,h)*window.devicePixelRatio)}t.restore()},r1=(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()},s1=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=Hf(e,Ut(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Lf: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=Di.strokeWidth/s.zoom.value,o.strokeStyle=s.theme===$n.DARK?Ho(Di.strokeColor):Di.strokeColor,ka(e)&&(o.strokeStyle=s.theme===$n.LIGHT?"#7affd7":Ho("#1d8264")),Di.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Di.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(r.isExporting){let[l,d,c,u]=j(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),zo(e,i,o,r),o.restore()}else{let l=gd(e,n,r,s);if(!l)return;fs(l,o,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=j(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=Ae(e,t);if(H(g)){let x=L.getBoundTextElementPosition(g,e,t);f=(c-l)/2-(x.x-l),h=(u-d)/2-(x.y-d)}}o.save(),o.translate(m,p);let E=$(e,t);if(H(e)&&E){let g=document.createElement("canvas"),x=g.getContext("2d"),w=Math.max(En(l,c),En(d,u)),y=_o(e);g.width=w*s.exportScale+y*10*s.exportScale,g.height=w*s.exportScale+y*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 b=Mn.canvas(g);x.translate(-f,-h),zo(e,b,x,r),x.translate(f,h),x.rotate(-e.angle);let[,,,,I,S]=j(E,t),T=(l+c)/2-I,M=(d+u)/2-S;x.translate(-T,-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),zo(e,i,o,r);o.restore()}else{let l=gd(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Bf(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&xe(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=xd(Ca(l.element,t),n,s.zoom,r,s);c&&fs(c,o,r,s,n),o.restore()}fs(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function a1(e,t,n){let i=he({...e,angle:0},n),o=Ro((i[0]+i[2])/2,(i[1]+i[3])/2);return Rf(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(Ed(r[r.length-1][1],ps(Ro(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[Ed(ps(Ro(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),ps(Ro(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}P();var c1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",u1=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable",m1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",p1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",yd=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",f1=e=>e==="arrow",h1=e=>e==="arrow";var Ze=class e{static rg=new Ke;static cache=new WeakMap;static get=(t,n)=>{let i=e.cache.get(t);if(i&&(n===null||i.theme===n))return i.shape};static delete=t=>{e.cache.delete(t),Bi.delete(t)};static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let i=n?.isExporting?void 0:e.get(t,n?n.theme:null);if(i!==void 0)return i;Bi.delete(t);let o=Zf(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:jf.white,embedsValidationStatus:null,theme:Es.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||Es.LIGHT}),o}},$f=e=>[8,8+e],Md=e=>[1.5,6+e];function Vf(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&&yd(e.type)||K(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var _e=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?$f(e.strokeWidth):e.strokeStyle==="dotted"?Md(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:Vf(e),stroke:n?Uo(e.strokeColor):e.strokeColor,preserveVertices:t||e.roughness<Wf.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=Li(e.backgroundColor)?void 0:n?Uo(e.backgroundColor):e.backgroundColor,e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return Dn(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:n?Uo(e.backgroundColor):e.backgroundColor),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},Id=(e,t,n)=>oo(e)&&(t||Oa(e)&&n?.get(e.id)!==!0)&&Li(e.backgroundColor)&&Li(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:io(e)?{...e,strokeColor:Li(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Li(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Sd=(e,t,n,i,o,r,s,a)=>{let l=gs(e,t,n,i);if(l===null)return[];let d=(u,m)=>{if(u===null)return[];let[,,p,f,h,E]=u;return[o.line(p,f,h,E,m)]},c=a?Uo(e.strokeColor):e.strokeColor;switch(i){case"dot":case"circle":case"circle_outline":{let[u,m,p]=l;return delete r.strokeLineDash,[o.circle(u,m,p,{...r,fill:i==="circle_outline"?s:c,fillStyle:"solid",stroke:c,roughness:Math.min(.5,r.roughness||0)})]}case"triangle":case"triangle_outline":{let[u,m,p,f,h,E]=l;return delete r.strokeLineDash,[o.polygon([[u,m],[p,f],[h,E],[u,m]],{...r,fill:i==="triangle_outline"?s:c,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[u,m,p,f,h,E,g,x]=l;return delete r.strokeLineDash,[o.polygon([[u,m],[p,f],[h,E],[g,x],[u,m]],{...r,fill:i==="diamond_outline"?s:c,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"crowfoot_one":return d(l,r);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[u,m,p,f,h,E]=l;if(e.strokeStyle==="dotted"){let g=Md(e.strokeWidth-1);r.strokeLineDash=[g[0],g[1]-1]}else delete r.strokeLineDash;return r.roughness=Math.min(1,r.roughness||0),[o.line(p,f,u,m,r),o.line(h,E,u,m,r),...i==="crowfoot_one_or_many"?d(gs(e,t,n,"crowfoot_one"),r):[]]}}},Xa=e=>{let t=new Ke,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=xt(e.points.reduce((o,r)=>[Math.min(e.x+r[0],o[0]),Math.min(e.y+r[1],o[1]),Math.max(e.x+r[0],o[2]),Math.max(e.y+r[1],o[3])],[1/0,1/0,-1/0,-1/0]));switch(e.type){case"line":case"arrow":{let o=e.points.length?e.points:[le(0,0)];return _(e)?t.path(Td(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=Wt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:le(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Wt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Wt(le(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Wt(le(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>le(a[0]-e.x,a[1]-e.y)).flat()}}):o.map((r,s)=>{let a=Wt(le(e.x+r[0],e.y+r[1]),i,e.angle);return{op:s===0?"move":"lineTo",data:le(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let o=ai(e.points,.75);return t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Wt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:le(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Wt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Wt(le(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Wt(le(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>le(a[0]-e.x,a[1]-e.y)).flat()}})}}},Zf=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===Es.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=Ct(Math.min(l,d),e);a=t.path(`M ${c} 0 L ${l-c} 0 Q ${l} 0, ${l} ${c} L ${l} ${d-c} Q ${l} ${d}, ${l-c} ${d} L ${c} ${d} Q 0 ${d}, 0 ${d-c} L 0 ${c} Q 0 0, ${c} 0`,_e(Id(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,_e(Id(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,f,h]=Hn(e);if(e.roundness){let E=Ct(Math.abs(l-f),e),g=Ct(Math.abs(u-d),e);a=t.path(`M ${l+E} ${d+g} L ${c-E} ${u-g}
11
+ `),a=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,l=ho(e.fontSize,e.lineHeight),d=zf(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}`)}},Ci=new WeakMap,yd=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=Ci.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=V(e,t),l=a?.version||null,d=we(e)?e.crop:null,c=Wt(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=Pd(e,t,o,n,i);return u?(Ci.set(e,u),u):null}return r},xs=(e,t,n,i,o)=>{let r=e.element,s=jo(r),a=e.scale,[l,d,c,u]=$(r,o),m=((l+c)/2+i.scrollX)*window.devicePixelRatio,p=((d+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=V(r,o);if(H(r)&&f){let h=(e.boundTextCanvas.width-e.canvas.width)/2,E=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(m,p),t.drawImage(e.boundTextCanvas,-(c-l)/2*window.devicePixelRatio-h/a-s,-(u-d)/2*window.devicePixelRatio-E/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(m,p),t.rotate(r.angle),"scale"in e.element&&!Uf(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"&&gt(r)){let h=V(r,o),E=Nr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((E.x+i.scrollX)*window.devicePixelRatio,(E.y+i.scrollY)*window.devicePixelRatio,dt(r,h)*window.devicePixelRatio,bi(r,h)*window.devicePixelRatio)}t.restore()},c1=(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()},u1=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=Wf(e,Wt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Of: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=Li.strokeWidth/s.zoom.value,o.strokeStyle=s.theme===Zn.DARK?Yo(Li.strokeColor):Li.strokeColor,za(e)&&(o.strokeStyle=s.theme===Zn.LIGHT?"#7affd7":Yo("#1d8264")),Li.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,Li.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(r.isExporting){let[l,d,c,u]=$(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,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),Wo(e,i,o,r),o.restore()}else{let l=yd(e,n,r,s);if(!l)return;xs(l,o,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(r.isExporting){let[l,d,c,u]=$(e,t),m=(l+c)/2+s.scrollX,p=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),h=(u-d)/2-(e.y-d);if(Q(e)){let g=Me(e,t);if(H(g)){let x=C.getBoundTextElementPosition(g,e,t);f=(c-l)/2-(x.x-l),h=(u-d)/2-(x.y-d)}}o.save(),o.translate(m,p);let E=V(e,t);if(H(e)&&E){let g=document.createElement("canvas"),x=g.getContext("2d"),w=Math.max(gn(l,c),gn(d,u)),y=jo(e);g.width=w*s.exportScale+y*10*s.exportScale,g.height=w*s.exportScale+y*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 b=Tn.canvas(g);x.translate(-f,-h),Wo(e,b,x,r),x.translate(f,h),x.rotate(-e.angle);let[,,,,I,A]=$(E,t),T=(l+c)/2-I,M=(d+u)/2-A;x.translate(-T,-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),Wo(e,i,o,r);o.restore()}else{let l=yd(e,n,r,s);if(!l)return;let d=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Gf(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&we(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let c=Pd(Fa(l.element,t),n,s.zoom,r,s);c&&xs(c,o,r,s,n),o.restore()}xs(l,o,r,s,n),o.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1};function m1(e,t,n){let i=he({...e,angle:0},n),o=_o((i[0]+i[2])/2,(i[1]+i[3])/2);return Hf(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(bd(r[r.length-1][1],gs(_o(s[0]+e.x,s[1]+e.y),o,e.angle))),r),[bd(gs(_o(t[0][0]+e.x,t[0][1]+e.y),o,e.angle),gs(_o(t[1][0]+e.x,t[1][1]+e.y),o,e.angle))])}P();var h1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",E1=e=>e==="rectangle"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line"||e==="text"||e==="embeddable",g1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",x1=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Ad=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",w1=e=>e==="arrow",b1=e=>e==="arrow";var Ke=class e{static rg=new Je;static cache=new WeakMap;static get=(t,n)=>{let i=e.cache.get(t);if(i&&(n===null||i.theme===n))return i.shape};static delete=t=>{e.cache.delete(t),Ci.delete(t)};static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let i=n?.isExporting?void 0:e.get(t,n?n.theme:null);if(i!==void 0)return i;Ci.delete(t);let o=Qf(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:Vf.white,embedsValidationStatus:null,theme:ys.LIGHT});return n?.isExporting||e.cache.set(t,{shape:o,theme:n?.theme||ys.LIGHT}),o}},qf=e=>[8,8+e],Bd=e=>[1.5,6+e];function Kf(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&&Ad(e.type)||q(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var We=(e,t=!1,n=!1)=>{let i={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?qf(e.strokeWidth):e.strokeStyle==="dotted"?Bd(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:Kf(e),stroke:n?ki(e.strokeColor):e.strokeColor,preserveVertices:t||e.roughness<Xf.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return i.fillStyle=e.fillStyle,i.fill=Oi(e.backgroundColor)?void 0:n?ki(e.backgroundColor):e.backgroundColor,e.type==="ellipse"&&(i.curveFitting=1),i;case"line":case"freedraw":return Bn(e.points)&&(i.fillStyle=e.fillStyle,i.fill=e.backgroundColor==="transparent"?void 0:n?ki(e.backgroundColor):e.backgroundColor),i;case"arrow":return i;default:throw new Error(`Unimplemented type ${e.type}`)}},Td=(e,t,n)=>lo(e)&&(t||Na(e)&&n?.get(e.id)!==!0)&&Oi(e.backgroundColor)&&Oi(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:ao(e)?{...e,strokeColor:Oi(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:Oi(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Gi=(e,t,n)=>{if(t===null)return[];let[,,i,o,r,s]=t;return[e.line(i,o,r,s,n)]},Xo=(e,t,n)=>{if(t===null)return[];let[i,o,r,s,a,l]=t;return[e.line(r,s,i,o,n),e.line(a,l,i,o,n)]},Fn=(e,t)=>{let n={...t};if(e.strokeStyle==="dotted"){let i=Bd(e.strokeWidth-1);n.strokeLineDash=[i[0],i[1]-1]}else delete n.strokeLineDash;return n.roughness=Math.min(1,n.roughness||0),n},bs=(e,t,n,i,o,r=1)=>{if(i===null)return[];let[s,a,l]=i,d={...t,fill:o,fillStyle:"solid",stroke:n,roughness:Math.min(.5,t.roughness||0)};return delete d.strokeLineDash,[e.circle(s,a,l*r,d)]},vd=(e,t,n,i,o,r,s,a)=>{if(i===null)return[];let l=a?ki(e.strokeColor):e.strokeColor,d=a?ki(s):s,c=-.25,u=.8;switch(i){case"circle":case"circle_outline":return bs(o,r,l,Fe(e,t,n,i),i==="circle_outline"?d:l);case"triangle":case"triangle_outline":{let m=Fe(e,t,n,i);if(m===null)return[];let[p,f,h,E,g,x]=m,w={...r,fill:i==="triangle_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete w.strokeLineDash,[o.polygon([[p,f],[h,E],[g,x],[p,f]],w)]}case"diamond":case"diamond_outline":{let m=Fe(e,t,n,i);if(m===null)return[];let[p,f,h,E,g,x,w,y]=m,b={...r,fill:i==="diamond_outline"?d:l,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)};return delete b.strokeLineDash,[o.polygon([[p,f],[h,E],[g,x],[w,y],[p,f]],b)]}case"cardinality_one":return Gi(o,Fe(e,t,n,i),Fn(e,r));case"cardinality_many":return Xo(o,Fe(e,t,n,i),Fn(e,r));case"cardinality_one_or_many":{let m=Fn(e,r);return[...Xo(o,Fe(e,t,n,"cardinality_many"),m),...Gi(o,Fe(e,t,n,"cardinality_one",c),m)]}case"cardinality_exactly_one":{let m=Fn(e,r);return[...Gi(o,Fe(e,t,n,"cardinality_one",-.5),m),...Gi(o,Fe(e,t,n,"cardinality_one"),m)]}case"cardinality_zero_or_one":{let m=Fn(e,r);return[...bs(o,r,l,Fe(e,t,n,"circle_outline",1.5),d,u),...Gi(o,Fe(e,t,n,"cardinality_one",-.5),m)]}case"cardinality_zero_or_many":{let m=Fn(e,r);return[...Xo(o,Fe(e,t,n,"cardinality_many"),m),...bs(o,r,l,Fe(e,t,n,"circle_outline",1.5),d,u)]}case"bar":case"arrow":default:return Xo(o,Fe(e,t,n,i),Fn(e,r))}},qa=e=>{let t=new Je,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=bt(e.points.reduce((o,r)=>[Math.min(e.x+r[0],o[0]),Math.min(e.y+r[1],o[1]),Math.max(e.x+r[0],o[2]),Math.max(e.y+r[1],o[3])],[1/0,1/0,-1/0,-1/0]));switch(e.type){case"line":case"arrow":{let o=e.points.length?e.points:[le(0,0)];return U(e)?t.path(Ld(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=Yt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:le(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Yt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Yt(le(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Yt(le(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>le(a[0]-e.x,a[1]-e.y)).flat()}}):o.map((r,s)=>{let a=Yt(le(e.x+r[0],e.y+r[1]),i,e.angle);return{op:s===0?"move":"lineTo",data:le(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let o=di(e.points,.75);return t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Yt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:le(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Yt(le(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Yt(le(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Yt(le(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>le(a[0]-e.x,a[1]-e.y)).flat()}})}}},Qf=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o,theme:r})=>{let s=r===ys.DARK;switch(e.type){case"rectangle":case"iframe":case"embeddable":{let a;if(e.roundness){let l=e.width,d=e.height,c=Gt(Math.min(l,d),e);a=t.path(`M ${c} 0 L ${l-c} 0 Q ${l} 0, ${l} ${c} L ${l} ${d-c} Q ${l} ${d}, ${l-c} ${d} L ${c} ${d} Q 0 ${d}, 0 ${d-c} L 0 ${c} Q 0 0, ${c} 0`,We(Td(e,n,o),!0,s))}else a=t.rectangle(0,0,e.width,e.height,We(Td(e,n,o),!1,s));return a}case"diamond":{let a,[l,d,c,u,m,p,f,h]=Un(e);if(e.roundness){let E=Gt(Math.abs(l-f),e),g=Gt(Math.abs(u-d),e);a=t.path(`M ${l+E} ${d+g} L ${c-E} ${u-g}
12
12
  C ${c} ${u}, ${c} ${u}, ${c-E} ${u+g}
13
13
  L ${m+E} ${p-g}
14
14
  C ${m} ${p}, ${m} ${p}, ${m-E} ${p-g}
15
15
  L ${f+E} ${h+g}
16
16
  C ${f} ${h}, ${f} ${h}, ${f+E} ${h-g}
17
17
  L ${l-E} ${d+g}
18
- C ${l} ${d}, ${l} ${d}, ${l+E} ${d+g}`,_e(e,!0,s))}else a=t.polygon([[l,d],[c,u],[m,p],[f,h]],_e(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,_e(e,!1,s));case"line":case"arrow":{let a,l=_e(e,!1,s),d=e.points.length?e.points:[le(0,0)];if(_(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(Td(d,16),_e(e,!0,s))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(d)),a=[]):e.roundness?a=[t.curve(d,l)]:l.fill?a=[t.polygon(d,l)]:a=[t.linearPath(d,l)],e.type==="arrow"){let{startArrowhead:c=null,endArrowhead:u="arrow"}=e;if(c!==null){let m=Sd(e,a,"start",c,t,l,i,s);a.push(...m)}if(u!==null){let m=Sd(e,a,"end",u,t,l,i,s);a.push(...m)}}return a}case"freedraw":{let a=[];if(Dn(e.points)){let l=ai(e.points,.75);a.push(t.curve(l,{..._e(e,!1,s),stroke:"none"}))}return a.push(qf(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return Yf(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Td=(e,t)=>{let n=[];for(let o=1;o<e.length-1;o+=1){let r=e[o-1],s=e[o+1],a=e[o],l=lt(a,r),d=lt(s,a),c=Math.min(t,Pd(e[o],s)/2,Pd(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(" ")},vd=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Ea(e);case"arrow":case"line":{let n=Ze.generateElementShape(e,null)[0],[,,,,i,o]=j(e,t);return Eo(e)?ba(e,n,le(e.x,e.y),e.angle,le(i,o)):xa(n,le(e.x,e.y),e.angle,le(i,o))}case"ellipse":return ga(e);case"freedraw":{let[,,,,n,i]=j(e,t);return wa(e,le(n,i),Eo(e))}}},$l=(e,t)=>{let n=[...e.points];if(t){if(!za(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>Xf||n.length<4?n.push(le(o[0],o[1])):n[n.length-1]=le(o[0],o[1])}return{polygon:t,points:n}},qf=e=>Jf(Kf(e)),Kf=e=>{let t=e.simulatePressure?e.points:e.points.length?e.points.map(([n,i],o)=>[n,i,e.pressures[o]]):[[0,0,.5]];return Ta(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:n=>Math.sin(n*Math.PI/2),last:!0})},Ad=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],Qf=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,Jf=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Ad(i,r[0]),"L",r[0],"Z"):n.push(i,Ad(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(Qf,"$1")};var bs=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]=j(t,n);if(Ie(t)){let[c,u,m,p]=ys(t.points.map(([f,h])=>oe(D(f,h),D(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,m+t.x,p+t.y]}else if(K(t))i=lh(t,l,d,n);else if(t.type==="diamond"){let[c,u]=oe(D(l,r),D(l,d),t.angle),[m,p]=oe(D(l,a),D(l,d),t.angle),[f,h]=oe(D(o,d),D(l,d),t.angle),[E,g]=oe(D(s,d),D(l,d),t.angle),x=Math.min(c,m,f,E),w=Math.min(u,p,h,g),y=Math.max(c,m,f,E),b=Math.max(u,p,h,g);i=[x,w,y,b]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,m=Math.cos(t.angle),p=Math.sin(t.angle),f=Math.hypot(c*m,u*p),h=Math.hypot(u*m,c*p);i=[l-f,d-h,l+f,d+h]}else{let[c,u]=oe(D(o,r),D(l,d),t.angle),[m,p]=oe(D(o,a),D(l,d),t.angle),[f,h]=oe(D(s,a),D(l,d),t.angle),[E,g]=oe(D(s,r),D(l,d),t.angle),x=Math.min(c,m,f,E),w=Math.min(u,p,h,g),y=Math.max(c,m,f,E),b=Math.max(u,p,h,g);i=[x,w,y,b]}return i}},j=(e,t,n=!1)=>{if(Ie(e))return oh(e);if(K(e))return L.getElementAbsoluteCoords(e,t,n);if(J(e)){let i=t?Ae(e,t):null;if(H(i)){let{x:o,y:r}=L.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]},us=(e,t)=>{let n=vd(e,t),[i,o,r,s,a,l]=j(e,t),d=D(a,l);if(n.type==="polycurve"){let g=n.data.map(w=>Tt(w,10)),x=[];if(Bt(e)&&!e.polygon||H(e))for(let w of g){let y=0;for(;y<w.length-1;)x.push(ge(D(w[y][0],w[y][1]),D(w[y+1][0],w[y+1][1]))),y++}else{let w=g.flat(),y=0;for(;y<w.length-1;)x.push(ge(D(w[y][0],w[y][1]),D(w[y+1][0],w[y+1][1]))),y++}return x}else{if(n.type==="polyline")return n.data;if(nh(e)){let[E,g]=Jt(e),x=g.map(y=>Ld(y,d,e.angle)).flat();return[...Bd(E,d,e.angle),...x]}else if(e.type==="diamond"){let[E,g]=en(e),x=g.map(y=>Ld(y,d,e.angle)).flat();return[...Bd(E,d,e.angle),...x]}else if(n.type==="polygon"){if(J(e)){let x=Ae(e,t);if(x&&K(x))return[ge(D(i,o),D(r,o)),ge(D(r,o),D(r,s)),ge(D(r,s),D(i,s)),ge(D(i,s),D(i,o))]}let E=n.data,g=[];for(let x=0;x<E.length-1;x++)g.push(ge(E[x],E[x+1]));return g}else if(n.type==="ellipse")return ih(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[ge(c,u),ge(m,p),ge(c,m),ge(u,p),ge(c,h),ge(m,h),ge(u,f),ge(p,f)]},nh=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),Bd=(e,t,n)=>e.map(i=>ge(oe(i[0],t,n),oe(i[1],t,n))),Ld=(e,t,n)=>{let i=Tt(e,10),o=0,r=[];for(;o<i.length-1;)r.push(ge(oe(D(i[o][0],i[o][1]),t,n),oe(D(i[o+1][0],i[o+1][1]),t,n))),o++;return r},ih=e=>{let t=D(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(oe(D(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(ge(r[l],r[l+1]));return o.push(ge(r[r.length-1],r[0])),o},j1=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Hn=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]},Cd=(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},Gd=(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=Cd(f,e,t,n,i)),h>=0&&h<=1&&(p=Cd(h,e,t,n,i)),[m,p]},xo=(e,t,n,i)=>{let o=Gd(e[0],t[0],n[0],i[0]),r=Gd(e[1],t[1],n[1],i[1]),s=Math.min(e[0],i[0]),a=Math.max(e[0],i[0]);if(o){let c=o.filter(u=>u!==null);s=Math.min(s,...c),a=Math.max(a,...c)}let l=Math.min(e[1],i[1]),d=Math.max(e[1],i[1]);if(r){let c=r.filter(u=>u!==null);l=Math.min(l,...c),d=Math.max(d,...c)}return[s,l,a,d]},vi=(e,t)=>{let n=D(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=kd(d);ws(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=D(d[0],d[1]),u=D(d[2],d[3]),m=D(d[4],d[5]),p=t?t(c):c,f=t?t(u):u,h=t?t(m):m,E=t?t(n):n;n=m;let[g,x,w,y]=xo(E,p,f,h);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,w),a.maxY=Math.max(a.maxY,y)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},ys=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]},oh=e=>{let[t,n,i,o]=ys(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]},rh=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}},sh=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},gs=(e,t,n,i)=>{if(t.length<1)return null;let o=vt(t[0]);if(o.length<1)return null;let r=n==="start"?1:o.length-1,s=o[r].data;ws(s.length===6,"Op data length is not 6");let a=D(s[4],s[5]),l=D(s[2],s[3]),d=D(s[0],s[1]),c=o[r-1],u=D(0,0);if(c.op==="move"){let O=kd(c.data);ws(O!=null,"Op data is not a point"),u=O}else c.op==="bcurveTo"&&(u=D(c.data[4],c.data[5]));let m=(O,X)=>Math.pow(1-O,3)*a[X]+3*O*Math.pow(1-O,2)*l[X]+3*Math.pow(O,2)*(1-O)*d[X]+u[X]*Math.pow(O,3),[p,f]=n==="start"?u:a,[h,E]=[m(.3,0),m(.3,1)],g=Math.hypot(p-h,f-E),x=(p-h)/g,w=(f-E)/g,y=rh(i),b=0;{let[O,X]=n==="end"?e.points[e.points.length-1]:e.points[0],[k,A]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];b=Math.hypot(O-k,X-A)}let S=Math.min(y,b*(i==="diamond"||i==="diamond_outline"?.25:.5)),T=p-x*S,M=f-w*S;if(i==="dot"||i==="circle"||i==="circle_outline"){let O=Math.hypot(M-f,T-p)+e.strokeWidth-2;return[p,f,O]}let R=sh(i);if(i==="crowfoot_many"||i==="crowfoot_one_or_many"){let[O,X]=oe(D(p,f),D(T,M),xs(-R)),[k,A]=oe(D(p,f),D(T,M),xs(R));return[T,M,O,X,k,A]}let[C,F]=oe(D(T,M),D(p,f),-R*Math.PI/180),[B,Y]=oe(D(T,M),D(p,f),xs(R));if(i==="diamond"||i==="diamond_outline"){let O,X;if(n==="start"){let[k,A]=e.points.length>1?e.points[1]:[0,0];[O,X]=oe(D(p+S*2,f),D(p,f),Math.atan2(A-f,k-p))}else{let[k,A]=e.points.length>1?e.points[e.points.length-2]:[0,0];[O,X]=oe(D(p-S*2,f),D(p,f),Math.atan2(f-A,p-k))}return[p,f,C,F,O,X,B,Y]}return[p,f,C,F,B,Y]},ah=e=>{let t=Mn.generator(),n=_e(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},lh=(e,t,n,i)=>{let o=$(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,f]=oe(D(e.x+u,e.y+m),D(t,n),e.angle),h=[p,f,p,f];if(o){let E=L.getMinMaxXYWithBoundText(e,i,[p,f,p,f],o);h=[E[0],E[1],E[2],E[3]]}return h}let s=Ze.get(e,null)?.[0]??ah(e),a=vt(s),d=vi(a,([u,m])=>oe(D(e.x+u,e.y+m),D(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=L.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},he=(e,t,n=!1)=>bs.getBounds(e,t,n),Oe=(e,t)=>{if(!eh(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Od(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]},X1=(e,t)=>{let[n,i,o,r]=Oe(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},Qt=(e,t,n,i)=>{if(!(K(e)||Ie(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Dd(0,t,Dd(1,n,e.points,i),i),r;if(Ie(e))r=ys(o);else{let c=Mn.generator(),u=e.roundness?c.curve(o,_e(e)):c.linearPath(o,_e(e)),m=vt(u);r=vi(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},rs=(e,t)=>{let n=Mn.generator(),i=e.roundness==null?n.linearPath(t,_e(e)):n.curve(t,_e(e)),o=vt(i),[r,s,a,l]=vi(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},$1=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=Od(e);return e.forEach(r=>{let[s,a,l,d]=he(r,o),c=th(D((s+l)/2,(a+d)/2),D(t.x,t.y));c<n&&(n=c,i=r)}),he(i,o)},Yt=e=>{let[t,n,i,o]=Oe(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},V1=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],xt=e=>D(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),et=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=re(e,t),[r,s]=oe(D(i.minX,i.minY),o,e.angle),[a,l]=oe(D(i.maxX,i.minY),o,e.angle),[d,c]=oe(D(i.maxX,i.maxY),o,e.angle),[u,m]=oe(D(i.minX,i.maxY),o,e.angle),p=[Math.min(r,a,d,u),Math.min(s,l,c,m),Math.max(r,a,d,u),Math.max(s,l,c,m)];if(n){let[f,h,E,g]=n;return[p[0]-g,p[1]-f,p[2]+h,p[3]+E]}return p},sn=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],bi=(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},re=(e,t,n=0,i=0)=>{if(K(e)){let[s,a,l,d]=j(e,t),[c,u]=D((s+l)/2,(a+d)/2);return D(c+n,u+i)}let[o,r]=xt(he(e,t));return D(o+n,r+i)};var mh=.1,Rd=e=>K(e)||Ie(e)?e.points.length<2||e.points.length===2&&H(e)&&uh(e.points[0],e.points[e.points.length-1],mh):e.width===0&&e.height===0,ud=(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},nP=(e,t,n,i,o,r)=>{let[s,a,l,d]=Oe(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},Ps=(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)/jt)*jt;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}},Vl=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/jt)*jt;if(o){let d=Math.floor(o/jt)*jt;dh(a,d,d+jt)&&(ch(a,o)<jt/6?l=o:Fd(a)>Fd(o)?l=d+jt: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}},iP=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 dP=(e,t,n,i)=>{let o=ko(e,n.getNonDeletedElementsMap(),i),r=Yt(e);return o.flatMap(s=>{let a=ph(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return ve(l,n,{simultaneouslyUpdated:s}),d})})},ph=(e,t,{axis:n,position:i})=>{let o=Yt(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 aE,arrayToObject as Xt,assertNever as fc,isDevEnv as bn,isShallowEqual as hc,isTestEnv as yn,randomInteger as pc}from"@excalidraw/common";P();import{assertNever as Sh,COLOR_PALETTE as Ah,isDevEnv as Mh,isTestEnv as Th,randomId as vh,Emitter as Hd,toIterable as Vn}from"@excalidraw/common";P();import{ORIG_ID as gh,randomId as zd,randomInteger as xh,arrayToMap as wh,castArray as Is,findLastIndex as Ci,getUpdatedTimestamp as bh,isTestEnv as yh}from"@excalidraw/common";P();import{arrayToMapWithIndex as fh}from"@excalidraw/common";var hh=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]},Eh=e=>{let t=fh(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]},Nd=e=>Eh(hh(e));var Ph=(e,t,n,i)=>{let o=As(n);return yh()&&Ih(o,n.id),o.id=zd(),o.updated=bh(),i&&(o.seed=xh(),Ml(o)),o.groupIds=dd(o.groupIds,e,r=>(t.has(r)||t.set(r,zd()),t.get(r))),o},IP=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=wh(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=Nd(t);let m=t.slice(),p=E=>{let x=Is(E).reduce((w,y)=>{if(i.has(y.id))return w;i.set(y.id,!0);let b=Ph(n.editingGroupId,o,y,e.randomizeSeed);return i.set(b.id,!0),d.set(b.id,b),a.set(y.id,b.id),l.set(b.id,y),s.push(y),r.push(b),w.push(b),w},[]);return Array.isArray(E)?x:x[0]||null},f=(E,g)=>{if(g){if(E>m.length-1){m.push(...Is(g));return}m.splice(E+1,0,...Is(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=ls(n,E);if(g){let x=Ge(t,g).flatMap(y=>q(y)?[...fn(t,y.id),y]:[y]),w=Ci(m,y=>y.groupIds?.includes(g));f(w,p(x));continue}if(!(E.frameId&&h.has(E.frameId))){if(q(E)){let x=E.id,w=fn(t,x),y=Ci(m,b=>b.frameId===x||b.id===x);f(y,p([...w,E]));continue}if(ht(E)){let x=$(E,c),w=Ci(m,y=>y.id===E.id||"containerId"in y&&y.containerId===E.id);x?f(w,p([E,x])):f(w,p(E));continue}if(ce(E)){let x=Ae(E,c),w=Ci(m,y=>y.id===E.id||y.id===x?.id);x?f(w,p([x,E])):f(w,p(E));continue}f(Ci(m,x=>x.id===E.id),p(E))}}if(kl(r,a,d),md(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),Ih=(e,t)=>{Object.defineProperty(e,gh,{value:t,writable:!1,enumerable:!1})};var Ue={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},_d=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Hd;onStoreIncrementEmitter=new Hd;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=wn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Ue.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=wn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?Yd(t.elements):void 0,t.appState);i=Gi.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=wn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=Gi.create(o,t),i?s=i:s=vs.calculate(o,t),!s.isEmpty()){let a=new Ms(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=Gi.create(r,t)}let o=new Ts(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===Ue.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 Ue.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Ue.NEVER:case Ue.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:Sh(n,"Unknown store action")}}finally{switch(n){case Ue.IMMEDIATELY:case Ue.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Ue.IMMEDIATELY)?t=Ue.IMMEDIATELY:this.scheduledMacroActions.has(Ue.NEVER)?t=Ue.NEVER:t=Ue.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Ue).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()),Th()||Mh())throw new Error(t)}}},Gi=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"}},Ms=class extends Yo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},Ts=class extends Yo{constructor(n){super("ephemeral",n);this.change=n}},vs=class e{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:vh()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?xn.calculate(t.elements,n.elements):xn.empty(),o=n.metadata.didAppStateChange?gn.calculate(t.appState,n.appState):gn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,xn.restore(i),gn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=xn.create(n,i,o),a=gn.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,wn.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(xn.empty(),gn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},wn=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,Ud(n)?n:Zn(n),i)}static empty(){return new e(new Map,Dh(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of Vn(t.elements))this.elements.get(i.id)||(n[i.id]=Be(i,{isDeleted:!0}));for(let i of Vn(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return U.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===Ue.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=Ud(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=U.isRightDifferent(this.appState,t);if(!i)return;let o=Xd(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 Vn(this.elements))t.get(r.id)||i.set(r.id,Be(r,{isDeleted:!0}));for(let r of Vn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(xe(r)&&!Tn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=jd(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of Vn(this.elements))n.set(i.id,i);for(let i of Vn(t))n.set(i.id,As(i));return n}},Wd="__observedAppState",Dh=()=>({name:null,editingGroupId:null,viewBackgroundColor:Ah.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,Wd,{value:!0,enumerable:!1}),t},Ud=e=>!!Reflect.get(e,Wd);P();P();var Zd="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Kn(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)+Kn(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]+Kn(e.slice(1),null,n)}function qd(e){if(e.length!==Kd(e[0]))throw new Error("invalid integer part of order key: "+e)}function Kd(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 Oi(e){let t=Kd(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function $d(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=Oi(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function Vd(e,t){qd(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 Bh(e,t){qd(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 qn(e,t,n=Zd){if(e!=null&&$d(e,n),t!=null&&$d(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=Oi(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Kn("",d,n);if(l<t)return l;let c=Bh(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=Oi(e),d=e.slice(l.length),c=Vd(l,n);return c??l+Kn(d,null,n)}let i=Oi(e),o=e.slice(i.length),r=Oi(t),s=t.slice(r.length);if(i===r)return i+Kn(o,s,n);let a=Vd(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+Kn(o,null,n)}function jo(e,t,n,i=Zd){if(n===0)return[];if(n===1)return[qn(e,t,i)];if(t==null){let s=qn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=qn(s,t,i),a.push(s);return a}if(e==null){let s=qn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=qn(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=qn(e,t,i);return[...jo(e,r,o,i),r,...jo(r,t,n-o-1,i)]}import{arrayToMap as Xo}from"@excalidraw/common";var Ds=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Lh=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:i,reconciliationContext:o})=>{let r=[],s=l=>`${l?.index}:${l?.id}:${l?.type}:${l?.isDeleted}:${l?.version}:${l?.versionNonce}`,a=e.map(l=>l.index);for(let[l,d]of a.entries()){let c=a[l-1],u=a[l+1];if(Bs(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&ht(e[l])){let m=e[l],p=$(m,Xo(e));p&&p.index<=m.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(p)}", "${s(m)}"`)}}if(r.length){let l=new Ds,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(`
18
+ C ${l} ${d}, ${l} ${d}, ${l+E} ${d+g}`,We(e,!0,s))}else a=t.polygon([[l,d],[c,u],[m,p],[f,h]],We(e,!1,s));return a}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,We(e,!1,s));case"line":case"arrow":{let a,l=We(e,!1,s),d=e.points.length?e.points:[le(0,0)];if(U(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?a=[t.path(Ld(d,16),We(e,!0,s))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(d)),a=[]):e.roundness?a=[t.curve(d,l)]:l.fill?a=[t.polygon(d,l)]:a=[t.linearPath(d,l)],e.type==="arrow"){let{startArrowhead:c=null,endArrowhead:u="arrow"}=e;if(c!==null){let m=vd(e,a,"start",c,t,l,i,s);a.push(...m)}if(u!==null){let m=vd(e,a,"end",u,t,l,i,s);a.push(...m)}}return a}case"freedraw":{let a=[];if(Bn(e.points)){let l=di(e.points,.75);a.push(t.curve(l,{...We(e,!1,s),stroke:"none"}))}return a.push(Jf(e)),a}case"frame":case"magicframe":case"text":case"image":return null;default:return $f(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Ld=(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=ct(a,r),d=ct(s,a),c=Math.min(t,Md(e[o],s)/2,Md(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(" ")},Cd=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return ba(e);case"arrow":case"line":{let n=Ke.generateElementShape(e,null)[0],[,,,,i,o]=$(e,t);return bo(e)?Sa(e,n,le(e.x,e.y),e.angle,le(i,o)):Pa(n,le(e.x,e.y),e.angle,le(i,o))}case"ellipse":return ya(e);case"freedraw":{let[,,,,n,i]=$(e,t);return Ia(e,le(n,i),bo(e))}}},Kl=(e,t)=>{let n=[...e.points];if(t){if(!Wa(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>Zf||n.length<4?n.push(le(o[0],o[1])):n[n.length-1]=le(o[0],o[1])}return{polygon:t,points:n}},Jf=e=>nh(eh(e)),eh=e=>{let t=e.simulatePressure?e.points:e.points.length?e.points.map(([n,i],o)=>[n,i,e.pressures[o]]):[[0,0,.5]];return La(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:n=>Math.sin(n*Math.PI/2),last:!0})},Dd=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],th=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,nh=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Dd(i,r[0]),"L",r[0],"Z"):n.push(i,Dd(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(th,"$1")};var Ss=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(Se(t)){let[c,u,m,p]=As(t.points.map(([f,h])=>oe(D(f,h),D(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,m+t.x,p+t.y]}else if(q(t))i=ph(t,l,d,n);else if(t.type==="diamond"){let[c,u]=oe(D(l,r),D(l,d),t.angle),[m,p]=oe(D(l,a),D(l,d),t.angle),[f,h]=oe(D(o,d),D(l,d),t.angle),[E,g]=oe(D(s,d),D(l,d),t.angle),x=Math.min(c,m,f,E),w=Math.min(u,p,h,g),y=Math.max(c,m,f,E),b=Math.max(u,p,h,g);i=[x,w,y,b]}else if(t.type==="ellipse"){let c=(s-o)/2,u=(a-r)/2,m=Math.cos(t.angle),p=Math.sin(t.angle),f=Math.hypot(c*m,u*p),h=Math.hypot(u*m,c*p);i=[l-f,d-h,l+f,d+h]}else{let[c,u]=oe(D(o,r),D(l,d),t.angle),[m,p]=oe(D(o,a),D(l,d),t.angle),[f,h]=oe(D(s,a),D(l,d),t.angle),[E,g]=oe(D(s,r),D(l,d),t.angle),x=Math.min(c,m,f,E),w=Math.min(u,p,h,g),y=Math.max(c,m,f,E),b=Math.max(u,p,h,g);i=[x,w,y,b]}return i}},$=(e,t,n=!1)=>{if(Se(e))return ah(e);if(q(e))return C.getElementAbsoluteCoords(e,t,n);if(Q(e)){let i=t?Me(e,t):null;if(H(i)){let{x:o,y:r}=C.getBoundTextElementPosition(i,e,t);return[o,r,o+e.width,r+e.height,o+e.width/2,r+e.height/2]}}return[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2]},hs=(e,t)=>{let n=Cd(e,t),[i,o,r,s,a,l]=$(e,t),d=D(a,l);if(n.type==="polycurve"){let g=n.data.map(w=>vt(w,10)),x=[];if(Lt(e)&&!e.polygon||H(e))for(let w of g){let y=0;for(;y<w.length-1;)x.push(ge(D(w[y][0],w[y][1]),D(w[y+1][0],w[y+1][1]))),y++}else{let w=g.flat(),y=0;for(;y<w.length-1;)x.push(ge(D(w[y][0],w[y][1]),D(w[y+1][0],w[y+1][1]))),y++}return x}else{if(n.type==="polyline")return n.data;if(rh(e)){let[E,g]=en(e),x=g.map(y=>kd(y,d,e.angle)).flat();return[...Od(E,d,e.angle),...x]}else if(e.type==="diamond"){let[E,g]=tn(e),x=g.map(y=>kd(y,d,e.angle)).flat();return[...Od(E,d,e.angle),...x]}else if(n.type==="polygon"){if(Q(e)){let x=Me(e,t);if(x&&q(x))return[ge(D(i,o),D(r,o)),ge(D(r,o),D(r,s)),ge(D(r,s),D(i,s)),ge(D(i,s),D(i,o))]}let E=n.data,g=[];for(let x=0;x<E.length-1;x++)g.push(ge(E[x],E[x+1]));return g}else if(n.type==="ellipse")return sh(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[ge(c,u),ge(m,p),ge(c,m),ge(u,p),ge(c,h),ge(m,h),ge(u,f),ge(p,f)]},rh=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),Od=(e,t,n)=>e.map(i=>ge(oe(i[0],t,n),oe(i[1],t,n))),kd=(e,t,n)=>{let i=vt(e,10),o=0,r=[];for(;o<i.length-1;)r.push(ge(oe(D(i[o][0],i[o][1]),t,n),oe(D(i[o+1][0],i[o+1][1]),t,n))),o++;return r},sh=e=>{let t=D(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let d=l*a,c=t[0]+n*Math.cos(d),u=t[1]+i*Math.sin(d);r.push(oe(D(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(ge(r[l],r[l+1]));return o.push(ge(r[r.length-1],r[0])),o},q1=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Un=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]},Fd=(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},Rd=(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=Fd(f,e,t,n,i)),h>=0&&h<=1&&(p=Fd(h,e,t,n,i)),[m,p]},Po=(e,t,n,i)=>{let o=Rd(e[0],t[0],n[0],i[0]),r=Rd(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]},Bi=(e,t)=>{let n=D(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=zd(d);Is(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=D(d[0],d[1]),u=D(d[2],d[3]),m=D(d[4],d[5]),p=t?t(c):c,f=t?t(u):u,h=t?t(m):m,E=t?t(n):n;n=m;let[g,x,w,y]=Po(E,p,f,h);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,w),a.maxY=Math.max(a.maxY,y)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},As=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]},ah=e=>{let[t,n,i,o]=As(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]},lh=20,dh=15,ch=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"cardinality_many":case"cardinality_one_or_many":case"cardinality_zero_or_many":return dh;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return lh;default:return 15}},uh=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},Fe=(e,t,n,i,o=0)=>{if(i===null||t.length<1)return null;let r=Dt(t[0]);if(r.length<1)return null;let s=n==="start"?1:r.length-1,a=r[s].data;Is(a.length===6,"Op data length is not 6");let l=D(a[4],a[5]),d=D(a[2],a[3]),c=D(a[0],a[1]),u=r[s-1],m=D(0,0);if(u.op==="move"){let S=zd(u.data);Is(S!=null,"Op data is not a point"),m=S}else u.op==="bcurveTo"&&(m=D(u.data[4],u.data[5]));let p=(S,z)=>Math.pow(1-S,3)*l[z]+3*S*Math.pow(1-S,2)*d[z]+3*Math.pow(S,2)*(1-S)*c[z]+m[z]*Math.pow(S,3),[f,h]=n==="start"?m:l,[E,g]=[p(.3,0),p(.3,1)],x=Math.hypot(f-E,h-g),w=(f-E)/x,y=(h-g)/x,b=ch(i),I=0;{let[S,z]=n==="end"?e.points[e.points.length-1]:e.points[0],[W,xe]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];I=Math.hypot(S-W,z-xe)}let T=Math.min(b,I*(i==="diamond"||i==="diamond_outline"?.25:.5)),M=f-w*T*o,O=h-y*T*o,L=M-w*T,k=O-y*T;if(i==="circle"||i==="circle_outline"){let S=Math.hypot(k-O,L-M)+e.strokeWidth-2;return[M,O,S]}let B=uh(i);if(i==="cardinality_many"||i==="cardinality_one_or_many"){let[S,z]=oe(D(M,O),D(L,k),Ps(-B)),[W,xe]=oe(D(M,O),D(L,k),Ps(B));return[L,k,S,z,W,xe]}let[X,_]=oe(D(L,k),D(M,O),-B*Math.PI/180),[ie,F]=oe(D(L,k),D(M,O),Ps(B));if(i==="diamond"||i==="diamond_outline"){let S,z;if(n==="start"){let[W,xe]=e.points.length>1?e.points[1]:[0,0];[S,z]=oe(D(M+T*2,O),D(M,O),Math.atan2(xe-O,W-M))}else{let[W,xe]=e.points.length>1?e.points[e.points.length-2]:[0,0];[S,z]=oe(D(M-T*2,O),D(M,O),Math.atan2(O-xe,M-W))}return[M,O,X,_,S,z,ie,F]}return[M,O,X,_,ie,F]},mh=e=>{let t=Tn.generator(),n=We(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},ph=(e,t,n,i)=>{let o=V(e,i);if(e.points.length<2){let[u,m]=e.points[0],[p,f]=oe(D(e.x+u,e.y+m),D(t,n),e.angle),h=[p,f,p,f];if(o){let E=C.getMinMaxXYWithBoundText(e,i,[p,f,p,f],o);h=[E[0],E[1],E[2],E[3]]}return h}let s=Ke.get(e,null)?.[0]??mh(e),a=Dt(s),d=Bi(a,([u,m])=>oe(D(e.x+u,e.y+m),D(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(o){let u=C.getMinMaxXYWithBoundText(e,i,c,o);c=[u[0],u[1],u[2],u[3]]}return c},he=(e,t,n=!1)=>Ss.getBounds(e,t,n),ke=(e,t)=>{if(!ih(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Nd(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]},K1=(e,t)=>{let[n,i,o,r]=ke(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},Jt=(e,t,n,i)=>{if(!(q(e)||Se(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Gd(0,t,Gd(1,n,e.points,i),i),r;if(Se(e))r=As(o);else{let c=Tn.generator(),u=e.roundness?c.curve(o,We(e)):c.linearPath(o,We(e)),m=Dt(u);r=Bi(m)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},ds=(e,t)=>{let n=Tn.generator(),i=e.roundness==null?n.linearPath(t,We(e)):n.curve(t,We(e)),o=Dt(i),[r,s,a,l]=Bi(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},Q1=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=Nd(e);return e.forEach(r=>{let[s,a,l,d]=he(r,o),c=oh(D((s+l)/2,(a+d)/2),D(t.x,t.y));c<n&&(n=c,i=r)}),he(i,o)},jt=e=>{let[t,n,i,o]=ke(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},J1=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],bt=e=>D(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),nt=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=re(e,t),[r,s]=oe(D(i.minX,i.minY),o,e.angle),[a,l]=oe(D(i.maxX,i.minY),o,e.angle),[d,c]=oe(D(i.maxX,i.maxY),o,e.angle),[u,m]=oe(D(i.minX,i.maxY),o,e.angle),p=[Math.min(r,a,d,u),Math.min(s,l,c,m),Math.max(r,a,d,u),Math.max(s,l,c,m)];if(n){let[f,h,E,g]=n;return[p[0]-g,p[1]-f,p[2]+h,p[3]+E]}return p},an=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],Pi=(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},re=(e,t,n=0,i=0)=>{if(q(e)){let[s,a,l,d]=$(e,t),[c,u]=D((s+l)/2,(a+d)/2);return D(c+n,u+i)}let[o,r]=bt(he(e,t));return D(o+n,r+i)};var gh=.1,_d=e=>q(e)||Se(e)?e.points.length<2||e.points.length===2&&H(e)&&Eh(e.points[0],e.points[e.points.length-1],gh):e.width===0&&e.height===0,hd=(e,t,n,i,o)=>{let[r,s,a,l]=he(e,o),d=$o({clientX:i.offsetLeft,clientY:i.offsetTop},i),c=$o({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},aP=(e,t,n,i,o,r)=>{let[s,a,l,d]=ke(e,o),c=$o({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=$o({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},Ms=(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)/Xt)*Xt;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}},Ql=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Xt)*Xt;if(o){let d=Math.floor(o/Xt)*Xt;fh(a,d,d+Xt)&&(hh(a,o)<Xt/6?l=o:Hd(a)>Hd(o)?l=d+Xt: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}},lP=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 fP=(e,t,n,i)=>{let o=zo(e,n.getNonDeletedElementsMap(),i),r=jt(e);return o.flatMap(s=>{let a=xh(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return De(l,n,{simultaneouslyUpdated:s}),d})})},xh=(e,t,{axis:n,position:i})=>{let o=jt(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};P();import{arrayToMap as mE,arrayToObject as $t,assertNever as xc,isDevEnv as yn,isShallowEqual as wc,isTestEnv as Pn,randomInteger as gc}from"@excalidraw/common";P();import{assertNever as Dh,COLOR_PALETTE as Bh,isDevEnv as Lh,isTestEnv as Ch,randomId as Gh,Emitter as Yd,toIterable as qn}from"@excalidraw/common";P();import{ORIG_ID as Ph,randomId as Wd,randomInteger as Ih,arrayToMap as Sh,castArray as Ts,findLastIndex as Fi,getUpdatedTimestamp as Ah,isTestEnv as Mh}from"@excalidraw/common";P();import{arrayToMapWithIndex as wh}from"@excalidraw/common";var bh=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]},yh=e=>{let t=wh(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]},Ud=e=>yh(bh(e));var Th=(e,t,n,i)=>{let o=Ds(n);return Mh()&&vh(o,n.id),o.id=Wd(),o.updated=Ah(),i&&(o.seed=Ih(),Bl(o)),o.groupIds=pd(o.groupIds,e,r=>(t.has(r)||t.set(r,Wd()),t.get(r))),o},vP=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=Sh(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=Ud(t);let m=t.slice(),p=E=>{let x=Ts(E).reduce((w,y)=>{if(i.has(y.id))return w;i.set(y.id,!0);let b=Th(n.editingGroupId,o,y,e.randomizeSeed);return i.set(b.id,!0),d.set(b.id,b),a.set(y.id,b.id),l.set(b.id,y),s.push(y),r.push(b),w.push(b),w},[]);return Array.isArray(E)?x:x[0]||null},f=(E,g)=>{if(g){if(E>m.length-1){m.push(...Ts(g));return}m.splice(E+1,0,...Ts(g))}},h=new Set(t.filter(E=>u.has(E.id)&&Z(E)).map(E=>E.id));for(let E of t){if(i.has(E.id)||!u.has(E.id))continue;let g=ms(n,E);if(g){let x=Oe(t,g).flatMap(y=>Z(y)?[...hn(t,y.id),y]:[y]),w=Fi(m,y=>y.groupIds?.includes(g));f(w,p(x));continue}if(!(E.frameId&&h.has(E.frameId))){if(Z(E)){let x=E.id,w=hn(t,x),y=Fi(m,b=>b.frameId===x||b.id===x);f(y,p([...w,E]));continue}if(gt(E)){let x=V(E,c),w=Fi(m,y=>y.id===E.id||"containerId"in y&&y.containerId===E.id);x?f(w,p([E,x])):f(w,p(E));continue}if(ce(E)){let x=Me(E,c),w=Fi(m,y=>y.id===E.id||y.id===x?.id);x?f(w,p([x,E])):f(w,p(E));continue}f(Fi(m,x=>x.id===E.id),p(E))}}if(zl(r,a,d),Ed(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}},vs=(e,t=0)=>{if(e==null||typeof e!="object")return e;let n=Object.prototype.toString.call(e);if(n==="[object Object]"){let i=typeof e.constructor=="function"?Object.create(Object.getPrototypeOf(e)):{};for(let o in e)if(e.hasOwnProperty(o)){if(t===0&&(o==="shape"||o==="canvas"))continue;i[o]=vs(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=vs(e[i],t+1);return o}return 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},Ds=e=>vs(e),vh=(e,t)=>{Object.defineProperty(e,Ph,{value:t,writable:!1,enumerable:!1})};var Ye={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},jd=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Yd;onStoreIncrementEmitter=new Yd;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=bn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Ye.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=bn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?Vd(t.elements):void 0,t.appState);i=Ri.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=bn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=Ri.create(o,t),i?s=i:s=Cs.calculate(o,t),!s.isEmpty()){let a=new Bs(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=Ri.create(r,t)}let o=new Ls(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===Ye.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 Ye.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Ye.NEVER:case Ye.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:Dh(n,"Unknown store action")}}finally{switch(n){case Ye.IMMEDIATELY:case Ye.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Ye.IMMEDIATELY)?t=Ye.IMMEDIATELY:this.scheduledMacroActions.has(Ye.NEVER)?t=Ye.NEVER:t=Ye.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Ye).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()),Ch()||Lh())throw new Error(t)}}},Ri=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)}},Vo=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Bs=class extends Vo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},Ls=class extends Vo{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:Gh()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?wn.calculate(t.elements,n.elements):wn.empty(),o=n.metadata.didAppStateChange?xn.calculate(t.appState,n.appState):xn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,wn.restore(i),xn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=wn.create(n,i,o),a=xn.create(r);return new this(t,s,a)}static squash(...t){let n=e.empty();for(let i of t)n.elements.squash(i.elements),n.appState.squash(i.appState);return n}static inverse(t){return this.create(t.elements.inverse(),t.appState.inverse())}static applyTo(t,n,i,o){let[r,s]=t.elements.applyTo(n,bn.empty().elements,o),[a,l]=t.appState.applyTo(i,r);return[r,a,s||l]}static applyLatestChanges(t,n,i,o){return this.create(t.elements.applyLatestChanges(n,i,o),t.appState,{id:t.id})}static empty(){return e.create(wn.empty(),xn.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},bn=class e{constructor(t,n,i={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=i}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,i={didElementsChange:!1,didAppStateChange:!1}){return new e(t,Xd(n)?n:Kn(n),i)}static empty(){return new e(new Map,Oh(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of qn(t.elements))this.elements.get(i.id)||(n[i.id]=Le(i,{isDeleted:!0}));for(let i of qn(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return Y.getRightDifferences(t.appState,this.appState).reduce((n,i)=>Object.assign(n,{[i]:this.appState[i]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[o,r]of Object.entries(t.elements))n.set(o,r);let i=Kn({...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===Ye.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=Xd(t)?t:Kn(t);return this.detectChangedAppState(i,n)?i:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let i=this.detectChangedElements(t,n);return i?.size?this.createElementsSnapshot(i):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let i=Y.isRightDifferent(this.appState,t);if(!i)return;let o=qd(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 qn(this.elements))t.get(r.id)||i.set(r.id,Le(r,{isDeleted:!0}));for(let r of qn(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(we(r)&&!vn(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=Zd(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of qn(this.elements))n.set(i.id,i);for(let i of qn(t))n.set(i.id,Ds(i));return n}},$d="__observedAppState",Oh=()=>({name:null,editingGroupId:null,viewBackgroundColor:Bh.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),Kn=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,$d,{value:!0,enumerable:!1}),t},Xd=e=>!!Reflect.get(e,$d);P();P();var Jd="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Jn(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)+Jn(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]+Jn(e.slice(1),null,n)}function ec(e){if(e.length!==tc(e[0]))throw new Error("invalid integer part of order key: "+e)}function tc(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 Ni(e){let t=tc(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function Kd(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=Ni(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function Qd(e,t){ec(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 kh(e,t){ec(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 Qn(e,t,n=Jd){if(e!=null&&Kd(e,n),t!=null&&Kd(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=Ni(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Jn("",d,n);if(l<t)return l;let c=kh(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=Ni(e),d=e.slice(l.length),c=Qd(l,n);return c??l+Jn(d,null,n)}let i=Ni(e),o=e.slice(i.length),r=Ni(t),s=t.slice(r.length);if(i===r)return i+Jn(o,s,n);let a=Qd(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+Jn(o,null,n)}function Zo(e,t,n,i=Jd){if(n===0)return[];if(n===1)return[Qn(e,t,i)];if(t==null){let s=Qn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Qn(s,t,i),a.push(s);return a}if(e==null){let s=Qn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=Qn(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=Qn(e,t,i);return[...Zo(e,r,o,i),r,...Zo(r,t,n-o-1,i)]}import{arrayToMap as qo}from"@excalidraw/common";var Gs=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Fh=(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(Os(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&gt(e[l])){let m=e[l],p=V(m,qo(e));p&&p.index<=m.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(p)}", "${s(m)}"`)}}if(r.length){let l=new Gs,d=[];if(o&&(d.push("Additional reconciliation context:"),d.push(o.localElements.map(c=>s(c))),d.push(o.remoteElements.map(c=>s(c)))),i||console.error(r.join(`
19
19
 
20
- `),l.stack,e.map(c=>s(c)),...d),t)throw l}},Jd=e=>e.sort((t,n)=>Qd(t)&&Qd(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),ki=(e,t)=>{try{let n=Xo(e),i=Ch(e,t),o=Cs(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Lh(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)be(s,n,{index:a})}catch{Ls(e)}return e},Ls=e=>{let t=Xo(e),n=ec(e),i=Cs(e,n);for(let[o,{index:r}]of i)be(o,t,{index:r});return e},Yd=e=>{let t=Xo(e),n=ec(e),i=Cs(e,n);for(let[o,{index:r}]of i)t.set(o.id,Be(o,{index:r}));return t},Ch=(e,t)=>{let n=[],i=0;for(;i<e.length;)if(t.has(e[i].id)){let o=[i-1,i];for(;++i<e.length&&t.has(e[i].id);)o.push(i);o.push(i),n.push(o)}else i++;return n},ec=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),Bs(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(Bs(u,m,f))break;[n,o]=[m,p],[i,r]=[f,h],c.push(l)}c.push(r),t.push(c)}}return t},Bs=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,Cs=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=jo(e[o]?.index,e[r]?.index,i.length);for(let a=0;a<i.length;a++){let l=e[i[a]];n.set(l,{index:s[a]})}}return n},Qd=e=>!!e.index;P();var mc=uu(rc(),1);import{randomInteger as qh,arrayToMap as sc,toBrandedType as ac,isDevEnv as lc,isTestEnv as dc,toArray as Kh}from"@excalidraw/common";import{isNonDeletedElement as Qh}from"@excalidraw/element";import{isFrameLikeElement as Jh}from"@excalidraw/element";import{getElementsInGroup as eE}from"@excalidraw/element";import{syncInvalidIndices as tE,syncMovedIndices as cc,validateFractionalIndices as nE}from"@excalidraw/element";import{getSelectedElements as iE}from"@excalidraw/element";import{mutateElement as oE}from"@excalidraw/element";var uc=e=>{let t=new Map,n=[];for(let i of e)i.isDeleted||(n.push(i),t.set(i.id,i));return{elementsMap:t,elements:n}},rE=(0,mc.default)(e=>{(lc()||dc()||window?.DEBUG_FRACTIONAL_INDICES)&&nE(e,{shouldThrow:lc()||dc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),sE=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Qn=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=ac(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=ac(new Map);selectedElementsCache={selectedElementIds:null,elements:null,cache:new Map};sceneNonce;getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}constructor(t=null,n){t&&this.replaceAllElements(t,n)}getSelectedElements(t){let n=sE(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=iE(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&&Qh(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=Kh(t),o=[];n?.skipValidation||rE(i),this.elements=tE(i),this.elementsMap.clear(),this.elements.forEach(s=>{Jh(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=uc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=uc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=qh();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)];cc(i,sc([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)];cc(i,sc(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]:eE(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=oE(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var U=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(Xt(t??[],o),Xt(n??[],o),Xt(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=Xt(e.getLeftDifferences(Xt(r,o),Xt(s,o)),d=>d),l=Xt(e.getRightDifferences(Xt(r,o),Xt(s,o)),d=>d);if(Object.keys(a).length||Object.keys(l).length){let d=r.filter(u=>a[o?o(u):String(u)]),c=s.filter(u=>l[o?o(u):String(u)]);Reflect.set(t,i,d),Reflect.set(n,i,c)}else Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i)}}static isLeftDifferent(t,n,i=!1){return!!this.distinctKeysIterator("left",t,n,i).next().value}static isRightDifferent(t,n,i=!1){return!!this.distinctKeysIterator("right",t,n,i).next().value}static isInnerDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("inner",t,n,i).next().value}static isDifferent(t,n,i=!1){return!!!!this.distinctKeysIterator("full",t,n,i).next().value}static getLeftDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("left",t,n,i)).sort()}static getRightDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("right",t,n,i)).sort()}static getInnerDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("inner",t,n,i)).sort()}static getDifferences(t,n,i=!1){return Array.from(this.distinctKeysIterator("full",t,n,i)).sort()}static*distinctKeysIterator(t,n,i,o=!1){if(n===i)return;let r=[];t==="left"?r=Object.keys(n):t==="right"?r=Object.keys(i):t==="inner"?r=Object.keys(n).filter(s=>s in i):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(i)])):fc(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let s of r){let a=n[s],l=i[s];if(a!==l){if(!o&&typeof a=="object"&&typeof l=="object"&&a!==null&&l!==null&&hc(a,l))continue;yield s}}}},gn=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=U.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(U.create({},{}))}inverse(){let t=U.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=U.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=U.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=U.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=U.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=U.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=U.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=U.merge(this.delta,t.delta,U.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=U.mergeObjects(t.selectedElementIds,s,i),m=U.mergeObjects(t.selectedGroupIds,a,o),p=U.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new L(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),yn()||bn())throw i;return[t,!1]}}isEmpty(){return U.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=Zn(t),r=Zn(n),s=U.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=U.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=U.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=sd(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let w=i.get(x);w&&!w.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let m=n[u];m?c.has(m)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let p=n[u];if(!p)l.value=!0;else{let x=i.get(p.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},h=n[u]||{};hc(f,h)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,g=n[u]||null;E!==g&&(l.value=!0);break;default:fc(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{U.diffObjects(t,n,"selectedElementIds",i=>!0),U.diffObjects(t,n,"selectedGroupIds",i=>i??!1),U.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),yn()||bn())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}},xn=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(yn()||bn())&&(e.validate(r,"added",this.satisfiesAddition),e.validate(r,"removed",this.satisfiesRemoval),e.validate(r,"updated",this.satisfiesUpdate)),r}static restore(t){let{added:n,removed:i,updated:o}=t;return e.create(n,i,o)}static satisfiesAddition=({deleted:t,inserted:n})=>t.isDeleted===!0&&!n.isDeleted;static satisfiesRemoval=({deleted:t,inserted:n})=>!t.isDeleted&&n.isDeleted===!0;static satisfiesUpdate=({deleted:t,inserted:n})=>!!t.isDeleted==!!n.isDeleted;static satisfiesCommmonInvariants=({deleted:t,inserted:n})=>!!(Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static satisfiesUniqueInvariants=(t,n)=>{let{added:i,removed:o,updated:r}=t;return[i[n],o[n],r[n]].filter(Boolean).length===1};static validate(t,n,i){for(let[o,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!this.satisfiesUniqueInvariants(t,o)||!i(r))throw console.error(`Broken invariant for "${n}" delta, element "${o}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${o}".`)}static calculate(t,n){if(t===n)return e.empty();let i={},o={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s},d={isDeleted:!0,version:s.version+1,versionNonce:pc()},c=U.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:pc()},d={...s},c=U.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=U.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]=U.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=U.create(m.deleted,m.inserted,o(p,f),i):h=m,U.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=wn.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),yn()||bn())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),yn()||bn())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=U.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=U.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return U.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]=U.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]=U.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=U.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(yn()||bn())&&(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=Be({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=U.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),Be(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:U.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=Be(d,{...m,version:u},!0):p=be(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=>Fl.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);un.unbindAffected(n,r(),o),un.unbindAffected(n,s(),o),mn.unbindAffected(n,r(),o),mn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);un.unbindAffected(n,r(),o),un.rebindAffected(n,s(),o),mn.unbindAffected(n,r(),(a,l)=>{J(a)&&o(a,l)}),mn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Qn(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),yn()||bn())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(ht(r)){let s=Ft(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||fo(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&de(i)&&ve(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=Jd([...o]),s=U.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),aE(ki(r,s))}static postProcess(t,n){try{U.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];U.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),yn()||bn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var hI=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=Yt(e),c=ko(e,t,i).map(f=>[f,Yt(f)]).sort((f,h)=>f[1][s]-h[1][s]),u=0;for(let f of c)u+=f[1][l];let m=(d[l]-u)/(c.length-1);if(m<0){let f=c.findIndex(x=>x[1][r]===d[r]),h=c.findIndex(x=>x[1][a]===d[a]),E=(c[h][1][s]-c[f][1][s])/(c.length-1),g=c[f][1][s];return c.flatMap(([x,w],y)=>{let b={x:0,y:0};return y!==f&&y!==h&&(g+=E,b[n.axis]=g-w[s]),x.map(I=>{let S=o.mutateElement(I,{x:I.x+b.x,y:I.y+b.y});return ve(I,o,{simultaneouslyUpdated:x}),S})})}let p=d[r];return c.flatMap(([f,h])=>{let E={x:0,y:0};return E[n.axis]=p-h[r],p+=m,p+=h[l],f.map(g=>{let x=o.mutateElement(g,{x:g.x+E.x,y:g.y+E.y});return ve(g,o,{simultaneouslyUpdated:f}),x})})};P();import{TEXT_AUTOWRAP_THRESHOLD as lE,getGridPoint as dE,getFontString as cE,DRAGGING_THRESHOLD as uE}from"@excalidraw/common";var AI=(e,t,n,i,o,r)=>{if(t.length===1&&_(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(m=>{if(_(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=mE(Oe(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))>uE||!m.startBinding&&!m.endBinding){Os(e,m,i,c);let E=m.startBinding&&!f,g=m.endBinding&&!h;(E||g)&&(E&&Te(m,"start",i),g&&Te(m,"end",i))}}else{Os(e,m,i,c);let E=$(m,i.getNonDeletedElementsMap());E&&Os(e,E,i,c),ve(m,i,{simultaneouslyUpdated:Array.from(a)})}})},mE=(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]=dE(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Os=(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})},MI=(e,t,n)=>{let[i,o]=Oe(e);return[t-i,n-o]},TI=({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}=Ps(t,a,o<n?-s:s):{width:s,height:a}=Ps(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=co(cE({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>lE/c&&(g={autoResize:!1}),E=i,d&&(h=n-s/2)}if(s!==0&&a!==0){let x=null;xe(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:h+(p?.x??0),y:E+(p?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as Vo,normalizeLink as Ec}from"@excalidraw/common";var CI=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Vo,e),Ec(i.toString())}catch(i){console.error(i)}return Ec(n)},GI=(e,t)=>{if(e.length>0&&pE(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},pE=e=>!!(e.length===1||e.length>1&&ad(e)),OI=e=>{try{let t=new URL(e);return t.searchParams.has(Vo)&&t.host===window.location.host}catch{return!1}},kI=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Vo))return t.get(Vo)}catch{}return null};P();import{FONT_FAMILY as AE,VERTICAL_ALIGN as ME,escapeDoubleQuotes as ks,getFontString as TE}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as Pn,DEFAULT_FONT_FAMILY as fE,DEFAULT_FONT_SIZE as hE,DEFAULT_TEXT_ALIGN as EE,DEFAULT_VERTICAL_ALIGN as gE,VERTICAL_ALIGN as xE,randomInteger as wE,randomId as bE,getFontString as Zo,getUpdatedTimestamp as yE,getLineHeight as PE}from"@excalidraw/common";var ct=(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:w=Pn.locked,...y})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:y.points}),{id:y.id||bE(),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:y.seed??wE(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:g,updated:yE(),link:x,locked:w,customData:y.customData}),kn=e=>ct(e.type,e),jI=e=>ct("embeddable",e),XI=e=>({...ct("iframe",e)}),gc=e=>Be({...ct("frame",e),type:"frame",name:e?.name||null},{}),xc=e=>Be({...ct("magicframe",e),type:"magicframe",name:e?.name||null},{}),wc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Fn=e=>{let t=e.fontFamily||fE,n=e.fontSize||hE,i=e.lineHeight||PE(t),o=Ei(e.text),r=Xe(o,Zo({fontFamily:t,fontSize:n}),i),s=e.textAlign||EE,a=e.verticalAlign||gE,l=wc({textAlign:s,verticalAlign:a},r),d={...ct("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 Be(d,{})},IE=(e,t,n)=>{let{width:i,height:o}=Xe(n,Zo(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===xE.MIDDLE&&!e.containerId&&e.autoResize){let d=Xe(e.text,Zo(e),e.lineHeight),c=wc(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]=j(e,t),[p,f,h,E]=Qt(e,i,o,!1),g=(d-p)/2,x=(c-f)/2,w=(u-h)/2,y=(m-E)/2;[a,l]=SE({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,w,y)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},SE=(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]},$I=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=kt(i,Zo(e),t?at(t,e):e.width));let o=IE(e,n,i);return{text:i,...o}},VI=e=>({...ct(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure}),bc=e=>{let t={...ct(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Bt(t)?{...t,polygon:e.polygon??!1}:t},qo=e=>e.elbowed?{...ct(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}:{...ct(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},yc=e=>({...ct("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ut=new Map,vE=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,DE=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,BE=/^https:\/\/(?:www\.)?figma\.com/,Pc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,LE=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,CE=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Ic=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,GE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,OE=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,kE=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,Sc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Ac=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,FE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Tc=e=>{let t;try{let s=new URL(e.startsWith("http")?e:`https://${e}`);t=s.searchParams.get("t")||s.searchParams.get("start")}catch{t=e.match(/[?&#](?:t|start)=([^&#\s]+)/)?.[1]}if(!t)return 0;if(/^\d+$/.test(t))return parseInt(t,10);let n=t.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/);if(!n)return 0;let[,i="0",o="0",r="0"]=n;return parseInt(i)*3600+parseInt(o)*60+parseInt(r)},RE=e=>{try{let t=new URL(e.startsWith("http")?e:`https://${e}`);if(t.hostname.replace(/^www\./,"")!=="drive.google.com")return null;let i=null,o=t.pathname.match(/^\/file\/d\/([^/]+)(?:\/|$)/);if(o?.[1]?i=o[1]:(t.pathname==="/open"||t.pathname==="/uc")&&(i=t.searchParams.get("id")),!i||!/^[a-zA-Z0-9_-]+$/.test(i))return null;let r=t.searchParams.get("resourcekey"),s=Tc(t.toString());return{fileId:i,resourceKey:r&&/^[a-zA-Z0-9_-]+$/.test(r)?r:void 0,timestamp:s>0?s:void 0}}catch{return null}},Rs=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Mc=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),Fs=e=>`<html><body>${e}</body></html>`,tS=e=>{if(!e)return null;if(ut.has(e))return ut.get(e);let t=e,n=Mc.has(Ns(e,Mc)||""),i="generic",o={w:560,h:840},r=e.match(vE);if(r?.[2]){let c=Tc(t),u=c>0?`&start=${c}`:"",m=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${u}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break}return o=m?{w:315,h:560}:{w:560,h:315},ut.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(DE);if(s?.[1]){let c=s?.[1],u=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${c}?api=1`,o={w:560,h:315},ut.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=RE(e);if(a){i="video";let c=new URLSearchParams;a.resourceKey&&c.set("resourcekey",a.resourceKey),a.timestamp&&c.set("t",`${a.timestamp}`);let u=c.toString();return e=`https://drive.google.com/file/d/${a.fileId}/preview${u?`?${u}`:""}`,o={w:560,h:315},ut.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(BE))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ut.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(OE);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),ut.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(CE.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Ic.test(e)){let c=e.match(Ic)[1],u=ks(`https://twitter.com/x/status/${c}`),m={type:"document",srcdoc:p=>Fs(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${u}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ut.set(t,m),m}if(Ac.test(e)){let[,c,u,m]=e.match(Ac),p=ks(`https://reddit.com/r/${c}/comments/${u}/${m}`),f={type:"document",srcdoc:h=>Fs(`<blockquote class="reddit-embed-bq" data-embed-theme="${h}"><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 ut.set(t,f),f}if(Pc.test(e)){let[,c,u]=e.match(Pc),m=ks(`https://gist.github.com/${c}/${u}`),p={type:"document",srcdoc:()=>Fs(`
20
+ `),l.stack,e.map(c=>s(c)),...d),t)throw l}},ic=e=>e.sort((t,n)=>nc(t)&&nc(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),zi=(e,t)=>{try{let n=qo(e),i=Rh(e,t),o=Fs(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});Fh(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)ye(s,n,{index:a})}catch{ks(e)}return e},ks=e=>{let t=qo(e),n=oc(e),i=Fs(e,n);for(let[o,{index:r}]of i)ye(o,t,{index:r});return e},Vd=e=>{let t=qo(e),n=oc(e),i=Fs(e,n);for(let[o,{index:r}]of i)t.set(o.id,Le(o,{index:r}));return t},Rh=(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},oc=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),Os(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(Os(u,m,f))break;[n,o]=[m,p],[i,r]=[f,h],c.push(l)}c.push(r),t.push(c)}}return t},Os=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,Fs=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=Zo(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},nc=e=>!!e.index;P();var Ec=hu(dc(),1);import{randomInteger as tE,arrayToMap as cc,toBrandedType as uc,isDevEnv as mc,isTestEnv as pc,toArray as nE}from"@excalidraw/common";import{isNonDeletedElement as iE}from"@excalidraw/element";import{isFrameLikeElement as oE}from"@excalidraw/element";import{getElementsInGroup as rE}from"@excalidraw/element";import{syncInvalidIndices as sE,syncMovedIndices as fc,validateFractionalIndices as aE}from"@excalidraw/element";import{getSelectedElements as lE}from"@excalidraw/element";import{mutateElement as dE}from"@excalidraw/element";var hc=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}},cE=(0,Ec.default)(e=>{(mc()||pc()||window?.DEBUG_FRACTIONAL_INDICES)&&aE(e,{shouldThrow:mc()||pc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),uE=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},ei=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=uc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=uc(new Map);selectedElementsCache={selectedElementIds:null,elements:null,cache:new Map};sceneNonce;getSceneNonce(){return this.sceneNonce}getNonDeletedElementsMap(){return this.nonDeletedElementsMap}getElementsIncludingDeleted(){return this.elements}getElementsMapIncludingDeleted(){return this.elementsMap}getNonDeletedElements(){return this.nonDeletedElements}getFramesIncludingDeleted(){return this.frames}constructor(t=null,n){t&&this.replaceAllElements(t,n)}getSelectedElements(t){let n=uE(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=lE(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&&iE(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=nE(t),o=[];n?.skipValidation||cE(i),this.elements=sE(i),this.elementsMap.clear(),this.elements.forEach(s=>{oE(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=hc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=hc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=tE();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)];fc(i,cc([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)];fc(i,cc(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]:rE(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=dE(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var Y=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,i,o){let r=i&&o!=="inserted"?i(t,"deleted"):t,s=i&&o!=="deleted"?i(n,"inserted"):n;return new e(r,s)}static calculate(t,n,i,o){if(t===n)return e.empty();let r={},s={};for(let d of this.getDifferences(t,n))r[d]=t[d],s[d]=n[d];let[a,l]=o?o(r,s):[r,s];return e.create(a,l,i)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,i=e.empty()){return e.create({...t.deleted,...n.deleted,...i.deleted},{...t.inserted,...n.inserted,...i.inserted})}static mergeObjects(t,n,i={}){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects($t(t??[],o),$t(n??[],o),$t(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=$t(e.getLeftDifferences($t(r,o),$t(s,o)),d=>d),l=$t(e.getRightDifferences($t(r,o),$t(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)])):xc(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&&wc(a,l))continue;yield s}}}},xn=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=Y.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(i)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(Y.create({},{}))}inverse(){let t=Y.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=Y.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),i=Y.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),o=Y.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=Y.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=Y.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=Y.mergeObjects(this.delta.inserted.lockedMultiSelections??{},t.delta.inserted.lockedMultiSelections??{}),l={},d={};return(Object.keys(n).length||Object.keys(i).length)&&(d.selectedElementIds=n,l.selectedElementIds=i),(Object.keys(o).length||Object.keys(r).length)&&(d.selectedGroupIds=o,l.selectedGroupIds=r),(Object.keys(s).length||Object.keys(a).length)&&(d.lockedMultiSelections=s,l.lockedMultiSelections=a),this.delta=Y.merge(this.delta,t.delta,Y.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:s={},selectedGroupIds:a={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=Y.mergeObjects(t.selectedElementIds,s,i),m=Y.mergeObjects(t.selectedGroupIds,a,o),p=Y.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new C(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),Pn()||yn())throw i;return[t,!1]}}isEmpty(){return Y.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=Kn(t),r=Kn(n),s=Y.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=Y.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=Y.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=cd(i));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let w=i.get(x);w&&!w.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let m=n[u];m?c.has(m)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let p=n[u];if(!p)l.value=!0;else{let x=i.get(p.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},h=n[u]||{};wc(f,h)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,g=n[u]||null;E!==g&&(l.value=!0);break;default:xc(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,i){let o=Object.keys(t);if(!o.length)return i.value=!0,t;let r={...t};for(let s of o){let a=n.get(s);a&&!a.isDeleted?i.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,i){if(!Object.keys(t).length)return i.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?i.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:i,selectedElementIds:o,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{Y.diffObjects(t,n,"selectedElementIds",i=>!0),Y.diffObjects(t,n,"selectedGroupIds",i=>i??!1),Y.diffObjects(t,n,"lockedMultiSelections",i=>i??{})}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),Pn()||yn())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}},wn=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(Pn()||yn())&&(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:gc()},c=Y.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:gc()},d={...s},c=Y.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=Y.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?i[s.id]=l:o[s.id]=l;continue}r[s.id]=l}}return e.create(i,o,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=Y.create({...l},{...d});return s},n=t(this.added),i=t(this.removed),o=t(this.updated);return e.create(i,n,o)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,i){let o=(d,c)=>(u,m)=>{let p;switch(m){case"deleted":p=d;break;case"inserted":p=c;break}if(!p)return console.error("Element not found when trying to apply latest changes"),u;let 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=Y.create(m.deleted,m.inserted,o(p,f),i):h=m,Y.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=bn.empty().elements,i){let o=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let a=e.createApplier(t,o,n,s,i),l=a(this.added),d=a(this.removed),c=a(this.updated),u=this.resolveConflicts(t,o,s.applyDirection);r=new Map([...l,...d,...c,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),Pn()||yn())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),Pn()||yn())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:i,updated:o}=t,r=(s,a)=>{let l=Y.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=Y.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return Y.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=Y.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=Y.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=Y.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(Pn()||yn())&&(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=Le({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=Y.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!i.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);i.containsVisibleDifference=l}return i.containsZindexDifference||(i.containsZindexDifference=n.deleted.index!==n.inserted.index),Le(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:Y.isRightDifferent(t,n)}resolveConflicts(t,n,i="forward"){let o=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=i==="forward"?d.version+1:d.version-1,m=l,p;c===d?p=Le(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=>Hl.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);mn.unbindAffected(n,r(),o),mn.unbindAffected(n,s(),o),pn.unbindAffected(n,r(),o),pn.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);mn.unbindAffected(n,r(),o),mn.rebindAffected(n,s(),o),pn.unbindAffected(n,r(),(a,l)=>{Q(a)&&o(a,l)}),pn.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new ei(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),Pn()||yn())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(gt(r)){let s=Rt(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||xo(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&de(i)&&De(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=ic([...o]),s=Y.getRightDifferences(o,r,!0).reduce((a,l)=>{let d=o[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),mE(zi(r,s))}static postProcess(t,n){try{Y.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];Y.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),Pn()||yn())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}};P();var bI=(e,t,n,i,o)=>{let[r,s,a,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=jt(e),c=zo(e,t,i).map(f=>[f,jt(f)]).sort((f,h)=>f[1][s]-h[1][s]),u=0;for(let f of c)u+=f[1][l];let m=(d[l]-u)/(c.length-1);if(m<0){let f=c.findIndex(x=>x[1][r]===d[r]),h=c.findIndex(x=>x[1][a]===d[a]),E=(c[h][1][s]-c[f][1][s])/(c.length-1),g=c[f][1][s];return c.flatMap(([x,w],y)=>{let b={x:0,y:0};return y!==f&&y!==h&&(g+=E,b[n.axis]=g-w[s]),x.map(I=>{let A=o.mutateElement(I,{x:I.x+b.x,y:I.y+b.y});return De(I,o,{simultaneouslyUpdated:x}),A})})}let p=d[r];return c.flatMap(([f,h])=>{let E={x:0,y:0};return E[n.axis]=p-h[r],p+=m,p+=h[l],f.map(g=>{let x=o.mutateElement(g,{x:g.x+E.x,y:g.y+E.y});return De(g,o,{simultaneouslyUpdated:f}),x})})};P();import{TEXT_AUTOWRAP_THRESHOLD as pE,getGridPoint as fE,getFontString as hE,DRAGGING_THRESHOLD as EE}from"@excalidraw/common";var BI=(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=>Z(m)).map(m=>m.id);if(l.length>0)for(let m of i.getNonDeletedElements())m.frameId!==null&&l.includes(m.frameId)&&a.add(m);let d=[];for(let m of a){let p=e.originalElements.get(m.id);if(!p)return;d.push(p)}let c=gE(ke(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))>EE||!m.startBinding&&!m.endBinding){Ns(e,m,i,c);let E=m.startBinding&&!f,g=m.endBinding&&!h;(E||g)&&(E&&ve(m,"start",i),g&&ve(m,"end",i))}}else{Ns(e,m,i,c);let E=V(m,i.getNonDeletedElementsMap());E&&Ns(e,E,i,c),De(m,i,{simultaneouslyUpdated:Array.from(a)})}})},gE=(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]=fE(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-o,y:a-r}},Ns=(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})},LI=(e,t,n)=>{let[i,o]=ke(e);return[t-i,n-o]},CI=({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}=Ms(t,a,o<n?-s:s):{width:s,height:a}=Ms(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(Q(e)){a=e.height;let x=fo(hE({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>pE/c&&(g={autoResize:!1}),E=i,d&&(h=n-s/2)}if(s!==0&&a!==0){let x=null;we(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 Qo,normalizeLink as bc}from"@excalidraw/common";var RI=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(Qo,e),bc(i.toString())}catch(i){console.error(i)}return bc(n)},NI=(e,t)=>{if(e.length>0&&xE(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},xE=e=>!!(e.length===1||e.length>1&&ud(e)),zI=e=>{try{let t=new URL(e);return t.searchParams.has(Qo)&&t.host===window.location.host}catch{return!1}},HI=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Qo))return t.get(Qo)}catch{}return null};P();import{FONT_FAMILY as BE,VERTICAL_ALIGN as LE,escapeDoubleQuotes as zs,getFontString as CE}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as In,DEFAULT_FONT_FAMILY as wE,DEFAULT_FONT_SIZE as bE,DEFAULT_TEXT_ALIGN as yE,DEFAULT_VERTICAL_ALIGN as PE,VERTICAL_ALIGN as IE,randomInteger as SE,randomId as AE,getFontString as Jo,getUpdatedTimestamp as ME,getLineHeight as TE}from"@excalidraw/common";var mt=(e,{x:t,y:n,strokeColor:i=In.strokeColor,backgroundColor:o=In.backgroundColor,fillStyle:r=In.fillStyle,strokeWidth:s=In.strokeWidth,strokeStyle:a=In.strokeStyle,roughness:l=In.roughness,opacity:d=In.opacity,width:c=0,height:u=0,angle:m=0,groupIds:p=[],frameId:f=null,index:h=null,roundness:E=null,boundElements:g=null,link:x=null,locked:w=In.locked,...y})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:y.points}),{id:y.id||AE(),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:y.seed??SE(),version:y.version||1,versionNonce:y.versionNonce??0,isDeleted:!1,boundElements:g,updated:ME(),link:x,locked:w,customData:y.customData}),Rn=e=>mt(e.type,e),qI=e=>mt("embeddable",e),KI=e=>({...mt("iframe",e)}),yc=e=>Le({...mt("frame",e),type:"frame",name:e?.name||null},{}),Pc=e=>Le({...mt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Ic=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Nn=e=>{let t=e.fontFamily||wE,n=e.fontSize||bE,i=e.lineHeight||TE(t),o=xi(e.text),r=Ve(o,Jo({fontFamily:t,fontSize:n}),i),s=e.textAlign||yE,a=e.verticalAlign||PE,l=Ic({textAlign:s,verticalAlign:a},r),d={...mt("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 Le(d,{})},vE=(e,t,n)=>{let{width:i,height:o}=Ve(n,Jo(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===IE.MIDDLE&&!e.containerId&&e.autoResize){let d=Ve(e.text,Jo(e),e.lineHeight),c=Ic(e,{width:i-d.width,height:o-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,m]=$(e,t),[p,f,h,E]=Jt(e,i,o,!1),g=(d-p)/2,x=(c-f)/2,w=(u-h)/2,y=(m-E)/2;[a,l]=DE({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,w,y)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},DE=(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]},QI=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Ft(i,Jo(e),t?dt(t,e):e.width));let o=vE(e,n,i);return{text:i,...o}},JI=e=>({...mt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure}),Sc=e=>{let t={...mt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Lt(t)?{...t,polygon:e.polygon??!1}:t},er=e=>e.elbowed?{...mt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...mt(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},Ac=e=>({...mt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var pt=new Map,GE=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,OE=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,kE=/^https:\/\/(?:www\.)?figma\.com/,Mc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,FE=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,RE=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Tc=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,NE=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,zE=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,HE=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,vc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Dc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,_E=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Lc=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)},UE=e=>{try{let t=new URL(e.startsWith("http")?e:`https://${e}`);if(t.hostname.replace(/^www\./,"")!=="drive.google.com")return null;let i=null,o=t.pathname.match(/^\/file\/d\/([^/]+)(?:\/|$)/);if(o?.[1]?i=o[1]:(t.pathname==="/open"||t.pathname==="/uc")&&(i=t.searchParams.get("id")),!i||!/^[a-zA-Z0-9_-]+$/.test(i))return null;let r=t.searchParams.get("resourcekey"),s=Lc(t.toString());return{fileId:i,resourceKey:r&&/^[a-zA-Z0-9_-]+$/.test(r)?r:void 0,timestamp:s>0?s:void 0}}catch{return null}},_s=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Bc=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),Hs=e=>`<html><body>${e}</body></html>`,sS=e=>{if(!e)return null;if(pt.has(e))return pt.get(e);let t=e,n=Bc.has(Us(e,Bc)||""),i="generic",o={w:560,h:840},r=e.match(GE);if(r?.[2]){let c=Lc(t),u=c>0?`&start=${c}`:"",m=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${u}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break}return o=m?{w:315,h:560}:{w:560,h:315},pt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(OE);if(s?.[1]){let c=s?.[1],u=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return i="video",e=`https://player.vimeo.com/video/${c}?api=1`,o={w:560,h:315},pt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:u,sandbox:{allowSameOrigin:n}}}let a=UE(e);if(a){i="video";let c=new URLSearchParams;a.resourceKey&&c.set("resourcekey",a.resourceKey),a.timestamp&&c.set("t",`${a.timestamp}`);let u=c.toString();return e=`https://drive.google.com/file/d/${a.fileId}/preview${u?`?${u}`:""}`,o={w:560,h:315},pt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}if(e.match(kE))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},pt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let d=e.match(zE);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),pt.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(RE.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Tc.test(e)){let c=e.match(Tc)[1],u=zs(`https://twitter.com/x/status/${c}`),m={type:"document",srcdoc:p=>Hs(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${u}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return pt.set(t,m),m}if(Dc.test(e)){let[,c,u,m]=e.match(Dc),p=zs(`https://reddit.com/r/${c}/comments/${u}/${m}`),f={type:"document",srcdoc:h=>Hs(`<blockquote class="reddit-embed-bq" data-embed-theme="${h}"><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 pt.set(t,f),f}if(Mc.test(e)){let[,c,u]=e.match(Mc),m=zs(`https://gist.github.com/${c}/${u}`),p={type:"document",srcdoc:()=>Hs(`
21
21
  <script src="${m}.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 ut.set(e,p),p}return ut.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},nS=e=>{let t;io(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=AE.Helvetica,o=TE({fontSize:n,fontFamily:i});return Fn({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:kt(t,o,e.width-20),textAlign:"center",verticalAlign:ME.MIDDLE,angle:e.angle??0})},Ns=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(Rs.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return Rs.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},iS=e=>{let t=e.match(GE);if(t&&t.length===2)return t[1];let n=e.match(FE);if(n&&n.length===2)return n[1];let i=e.match(LE);if(i&&i.length===2)return i[1];if(Sc.test(e))return`https://giphy.com/embed/${Sc.exec(e)[1]}`;let o=e.match(kE);return o&&o.length===2?o[1]:e},oS=(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(Ns(e,n))return!0;return!1}}return!!Ns(e,Rs)};P();import{KEYS as Ko,invariant as Qo,toBrandedType as NE}from"@excalidraw/common";import{pointFrom as vc}from"@excalidraw/math";var Jn=100,Rn=100,xS=e=>{switch(e){case Ko.ARROW_UP:return"up";case Ko.ARROW_DOWN:return"down";case Ko.ARROW_RIGHT:return"right";case Ko.ARROW_LEFT:return"left";default:return"right"}},Lc=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(_(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;Qo(de(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=yi(t,et(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,Ve)).map(r=>r.relative);case"down":return o.filter(r=>pe(r.heading,we)).map(r=>r.relative);case"right":return o.filter(r=>pe(r.heading,fe)).map(r=>r.relative);case"left":return o.filter(r=>pe(r.heading,ze)).map(r=>r.relative)}},zs=(e,t,n)=>Lc("successors",e,t,n),Hs=(e,t,n)=>Lc("predecessors",e,t,n),zE=(e,t,n)=>{let i=Rn+e.width;if(n==="up"||n==="down"){let a=Jn+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:(Rn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Jn+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=Jn+e.height,r=(t.length===0,Rn+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}},HE=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=zs(e,o,n),s=Hs(e,o,n),a=zE(e,[...r,...s],n),l=kn({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});Qo(yr(l),"not an ExcalidrawFlowchartNodeElement");let d=Cc(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},_E=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=Jn*(o-1)+o*e.height,m=e.y+e.height/2-u/2,p=Rn+e.width;n==="left"&&(p*=-1),a=e.x+p;let f=(Jn+e.height)*s;l=m+f}else{let u=Rn*(o-1)+o*e.width,m=e.x+e.width/2-u/2,p=Jn+e.height;n==="up"&&(p*=-1),l=e.y+p;let f=(Rn+e.width)*s;a=m+f}let d=kn({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});Qo(yr(d),"not an ExcalidrawFlowchartNodeElement");let c=Cc(e,d,n,t,i);r.push(d),r.push(c)}return r},Cc=(e,t,n,i,o)=>{let r,s;switch(n){case"up":{r=e.x+e.width/2,s=e.y-6;break}case"down":{r=e.x+e.width/2,s=e.y+e.height+6;break}case"right":{r=e.x+e.width+6,s=e.y+e.height/2;break}case"left":{r=e.x-6,s=e.y+e.height/2;break}}let l,d;switch(n){case"up":{l=t.x+t.width/2-r,d=t.y+t.height-s+6;break}case"down":{l=t.x+t.width/2-r,d=t.y-s-6;break}case"right":{l=t.x-r-6,d=t.y-s+t.height/2;break}case"left":{l=t.x+t.width-r+6,d=t.y-s+t.height/2;break}}let c=qo({type:"arrow",x:r,y:s,startArrowhead:null,endArrowhead:i.currentItemEndArrowhead,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeWidth:e.strokeWidth,opacity:e.opacity,roughness:e.roughness,points:[vc(0,0),vc(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();yt(c,e,"orbit","start",o),yt(c,t,"orbit","end",o);let m=new Map;m.set(e.id,e),m.set(t.id,t),m.set(c.id,c),L.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=Wn(c,NE(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p}},Dc=class{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!de(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...zs(t,n,i),...Hs(t,n,i)];if(o.length>0)return this.sameLevelIndex=0,this.isExploring=!0,this.sameLevelNodes=o,this.direction=i,this.visitedNodes.add(o[0].id),o[0].id;if(i===this.direction||!this.isExploring){this.isExploring||this.visitedNodes.add(t.id);let s=["up","right","down","left"].filter(a=>a!==i).map(a=>[...zs(t,n,a),...Hs(t,n,a)]).flat().filter(a=>!this.visitedNodes.has(a.id));for(let a of s)if(!this.visitedNodes.has(a.id))return this.visitedNodes.add(a.id),this.isExploring=!0,this.direction=i,a.id}return null}},Bc=class{isCreatingChart=!1;numberOfNodes=0;direction="right";pendingNodes=null;createNodes(t,n,i,o){let r=o.getNonDeletedElementsMap();if(i!==this.direction){let{nextNode:s,bindingArrow:a}=HE(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=_E(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);Qo(s&&ro(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>hn([a],s,r)||pn(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}},wS=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{pointDistance as ei,pointFrom as Us}from"@excalidraw/math";import{invariant as Wc}from"@excalidraw/common";P();import{arrayToMap as Oc,findIndex as kc,findLastIndex as Fc}from"@excalidraw/common";var _s=(e,t)=>e.frameId===t||e.id===t,Rc=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Oc(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},UE=e=>{let t=0;return e.reduce((n,i,o)=>(o>0&&e[o-1]!==i-1&&(t=++t),(n[t]||(n[t]=[])).push(i),n),[])},Gc=(e,t,n,i)=>{if("containerId"in e&&e.containerId){let o=i.getElement(e.containerId);if(o)return n==="left"?Math.min(t.indexOf(o),t.indexOf(e)):Math.max(t.indexOf(o),t.indexOf(e))}else{let o=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(o){let r=i.getElement(o);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},WE=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{_s(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},Nc=(e,t,n,i,o,r)=>{let s=r||Rt(e,n,i);if(!s)return n;let a=$(s,i),l=J(s)?Ae(s,i):null,d=[s.id,a?.id,l?.id].filter(m=>!!m),c=n.findIndex(m=>d.includes(m.id)),u=n.findIndex(m=>m.id===t.id);if(u!==-1&&c!==-1&&u<c){let m=Array.from(n),p=m.splice(u,1)[0];m.splice(c,0,p),o.replaceAllElements(m)}return n},YE=(e,t,n,i,o,r)=>{let s=t[n],a=m=>m.isDeleted?!1:o?m.frameId===o:e.editingGroupId?m.groupIds.includes(e.editingGroupId):!0,l=i==="left"?Fc(t,m=>a(m),Math.max(0,n-1)):kc(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Gc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||q(d))){let m=WE(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Gc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Ge(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},zc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Hc=(e,t,n,i)=>{let o=Rc(e,t),r=zc(e,o),s=UE(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(w=>{let y=e[w];return y.frameId&&a.has(y.frameId)})?null:e[m]?.frameId,f=YE(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]}),ki(e,r),e},_c=(e,t,n,i,o)=>{let r=Rc(e,t,o),s=zc(e,r),a=[],l,d;if(n==="left"){if(i)l=kc(e,f=>_s(f,i));else if(t.editingGroupId){let f=Ge(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;d=r[r.length-1]}else{if(i)d=Fc(e,f=>_s(f,i));else if(t.editingGroupId){let f=Ge(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 ki(p,s),p};function Uc(e,t,n,i){let o=Oc(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 DS=(e,t,n)=>Hc(e,t,"left",n),BS=(e,t,n)=>Hc(e,t,"right",n),LS=(e,t)=>Uc(e,t,"left",_c),CS=(e,t)=>Uc(e,t,"right",_c);var Jo=(e,t,n,i,o,r,s=!1)=>{if(_(t)||!bt(o)||t.points.length!==2)return!1;if(!s){let l=t.startBinding?.elementId===n.id?0:t.points.length-1,d=L.getPointAtIndexGlobalCoordinates(t,l,i);if(ei(e,d)<Mi*1.5/o.zoom.value)return!1}let a=L.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return ei(e,a)>=Mi*1.5/o.zoom.value&&Et({element:n,elementsMap:i,point:e,threshold:De(n,t),overrideShouldTestInside:!0})},jE=(e,t,n,i,o,r,s)=>{let a=new Map,l=n?"startBinding":"endBinding",d=n?"endBinding":"startBinding",c=e[l],u=e[d];if(c&&t){let m=t&&u&&c.elementId===u.elementId;s||m?c={...c,mode:"inside"}:c={...c,mode:"orbit"};let p=n?0:e.points.length-1,f=dt(e,l,c,t,i,!0);f&&a.set(p,{point:f})}if(u&&u.mode==="orbit"){let m=i.get(u.elementId);if(m&&de(m)&&bt(r)){let p=t&&u.elementId===t.id;s||p?u={...u,mode:"inside"}:u={...u,mode:"orbit"};let f=n?e.points.length-1:0,h=dt(e,d,u,m,i);h&&a.set(f,{point:h})}}a.size>0&&L.movePoints(e,o,a,{[l]:c,[d]:u})},Yc=(e,t,n,i,o,r,s)=>{let a=L.getElement(e.elementId,t);if(!a||!Se(a)||_(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,m=Us(n.x-c,n.y-u),p=l?"startBinding":"endBinding",f=pl(m,a,i.getNonDeletedElements(),t,st(o.zoom));if(f&&bt(o)){a[p]&&f.id!==d?.elementId&&Te(a,e.draggedFocusPointBinding,i);let h=s&&a[p]?.mode==="orbit"?"inside":!s&&a[p]?.mode==="inside"?"orbit":null;(!a[p]||h)&&yt(a,f,h||"orbit",e.draggedFocusPointBinding,i,m),i.mutateElement(a,{[p]:{...a[p],elementId:f.id,mode:h||a[p]?.mode||"orbit",...Yn(a,f,e.draggedFocusPointBinding,t,m)}})}else{let h=new Map,E=l?0:a.points.length-1;h.set(E,{point:L.createPointAt(a,t,m[0],m[1],r)}),L.movePoints(a,i,h),a[p]&&Te(a,l?"start":"end",i)}jE(a,f,l,t,i,o,s),f&&bt(o)&&Nc(m,a,i.getElementsIncludingDeleted(),t,i,f)},US=(e,t,n,i)=>{let o=Us(t.origin.x,t.origin.y),r=Mi*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&de(s)&&!s.isDeleted){let a=Fe(e.startBinding.fixedPoint,s,n);if(Jo(a,e,s,n,i,"start")&&ei(o,a)<=r)return{hitFocusPoint:"start",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}if(e.endBinding?.elementId){let s=n.get(e.endBinding.elementId);if(s&&de(s)&&!s.isDeleted){let a=Fe(e.endBinding.fixedPoint,s,n);if(Jo(a,e,s,n,i,"end")&&ei(o,a)<=r)return{hitFocusPoint:"end",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}return{hitFocusPoint:null,pointerOffset:{x:0,y:0}}},WS=(e,t)=>{Wc(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=L.getElement(e.elementId,t.getNonDeletedElementsMap());Wc(n,"Arrow must be in the scene");let i=e.draggedFocusPointBinding==="start"?"startBinding":"endBinding",o=e.draggedFocusPointBinding==="start"?"endBinding":"startBinding",r=n[i]?.elementId,s=n[o]?.elementId,a=r&&t.getNonDeletedElements().find(d=>d.id!==r&&d.id!==s&&de(d)&&d.boundElements?.find(({id:c})=>c===n.id));a&&t.mutateElement(a,{boundElements:a.boundElements?.filter(({id:d})=>d!==n.id)});let l=r&&t.getNonDeletedElementsMap().get(r);l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]})},YS=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=Us(t,n),a=Mi*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&de(l)&&!l.isDeleted){let d=Fe(e.startBinding.fixedPoint,l,r);if(Jo(d,e,l,r,o,"start")&&ei(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&de(l)&&!l.isDeleted){let d=Fe(e.endBinding.fixedPoint,l,r);if(Jo(d,e,l,r,o,"end")&&ei(s,d)<=a)return"end"}}return null};P();import{MIME_TYPES as jc,SVG_NS as XE}from"@excalidraw/common";var $E=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),ZS=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===jc.binary)throw new Error("Only images can be added to ImageCache");let l=$E(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}},qS=e=>e.filter(t=>Tn(t)),VE=e=>e?.nodeName.toLowerCase()==="svg",KS=e=>{let t=new DOMParser().parseFromString(e,jc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!VE(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",XE);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 nA=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(p=>[p]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let p=0;p<s;p+=a)l.push(r.slice(p,p+a));let d=0,c=l.map(p=>{let f=0,h=0,E=p.map(g=>{let[x,w,y,b]=Oe(g);return{elements:g,bounds:[x,w,y,b],width:y-x,height:b-w}});return E.forEach((g,x)=>{f+=g.width,x<E.length-1&&(f+=i),g.height>h&&(h=g.height)}),d+=h,{unitBounds:E,width:f,maxHeight:h}}),u=d+Math.max(0,l.length-1)*i,m=n-u/2;return c.forEach(p=>{let{unitBounds:f,width:h,maxHeight:E}=p,g=t-h/2;f.forEach(x=>{let[w,y]=x.bounds,b=g-w,I=m-y;x.elements.forEach(S=>{o.push(Be(S,{x:S.x+b,y:S.y+I}))}),g+=x.width+i}),m+=E+i}),o};P();import{pointCenter as ZE,normalizeRadians as tr,pointFrom as ie,pointRotateRads as mt}from"@excalidraw/math";import{MIN_FONT_SIZE as Ys,SHIFT_LOCKING_ANGLE as nr,rescalePoints as Xc,getFontString as er}from"@excalidraw/common";var hA=(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")_(m)||(qE(m,i,a,l,o),ve(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}=tg(f,h,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});eg(E,g,f,h,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return J(m)&&ve(m,i),!0}else if(n.length>1){if(t==="rotation")return QE(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:f,flipByY:h,originalBoundingBox:E}=ng(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return ig(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:h,nextWidth:m,nextHeight:p,originalBoundingBox:E}),!0}}return!1},qE=(e,t,n,i,o)=>{let[r,s,a,l]=j(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+nr/2,u=u-u%nr),u=tr(u));let m=Ft(e),p={angle:u};if(Se(e)&&(p={...p},e.startBinding&&Te(e,"start",t),e.endBinding&&Te(e,"end",t)),t.mutateElement(e,p),m){let f=t.getElement(m);if(f&&!H(e)){let{x:h,y:E}=gi(e,f,t.getNonDeletedElementsMap());t.mutateElement(f,{angle:u,x:h,y:E})}}},$c=(e,t,n,i)=>K(e)||Ie(e)?{points:Xc(0,t,Xc(1,n,e.points,i),i)}:{},js=(e,t,n)=>{let i=e.width;if(ce(e)){let s=Ae(e,t);s&&(i=at(s,e))}let r=e.fontSize*(n/i);return r<Ys?null:{size:r}},KE=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=js(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=ie(e.x,e.y),u=Ws(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=co(er({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=kt(t.originalText,er(t),Math.abs(u)),p=Xe(m,er(t),t.lineHeight),f=p.height,h=ie(e.x,e.y),E=Ws(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)}}},QE=(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+=nr/2,d-=d%nr);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!q(u)){let[m,p,f,h]=j(u,l),E=(m+f)/2,g=(p+h)/2,x=e.get(u.id)?.angle??u.angle,[w,y]=mt(ie(E,g),ie(s,a),d+x-u.angle),b=_(u)?{points:Rl(u,l)}:{x:u.x+(w-E),y:u.y+(y-g),angle:tr(d+x)};n.mutateElement(u,b),ve(u,n,{simultaneouslyUpdated:t}),Se(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||Te(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||Te(u,"end",n)));let I=$(u,l);if(I&&!H(u)){let{x:S,y:T}=gi(u,I,l);n.mutateElement(I,{x:S,y:T,angle:tr(d+x)})}}n.triggerUpdate()},EA=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?j(t[0],n):Oe(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=mt(ie(i,o),ie(d,c),-u),e){case"n":return mt(ie(i-(r+a)/2,o-s),ie(0,0),u);case"s":return mt(ie(i-(r+a)/2,o-l),ie(0,0),u);case"w":return mt(ie(i-r,o-(s+l)/2),ie(0,0),u);case"e":return mt(ie(i-a,o-(s+l)/2),ie(0,0),u);case"nw":return mt(ie(i-r,o-s),ie(0,0),u);case"ne":return mt(ie(i-a,o-s),ie(0,0),u);case"sw":return mt(ie(i-r,o-l),ie(0,0),u);case"se":return mt(ie(i-a,o-l),ie(0,0),u);default:return[0,0]}},gA=(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"},JE=(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"},Ws=(e,t,n,i,o,r,s,a,l)=>{let d=JE(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)}}},eg=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(J(n)&&J(i))return KE(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=$(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=js(m,u,at(g,m));if(x===null)return;c={fontSize:x.size}}else{let g=qa(er(m),m.lineHeight),x=Ka(m.fontSize,m.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let p=$c(i,e,t,!0),f=ie(i.x,i.y);if(K(i)){let[E,g]=he(i,o);f=ie(E,g)}let h=Ws(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],w=p.points[0][1];h.x+=x,h.y+=w,p.points=p.points.map(y=>ie(y[0]-x,y[1]-w))}if(e<0&&(h.x=h.x+e),t<0&&(h.y=h.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),H(n)&&m&&l){let E=e/n.width*m.fontSize;if(E<Ys)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};Se(n)&&(n.startBinding&&(E={...E},n.startBinding&&Te(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}),Ln(n,r,s,l),ve(n,r)}},tg=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=Qt(t,t.width,t.height,!0),u=ie(a,l),m=ie(d,c),p=ZE(u,m),f=mt(ie(i,o),p,-t.angle),[h,E,g,x]=Qt(e,e.width,e.height,!0),w=g-h,y=x-E,b=m[0]-u[0],I=m[1]-u[1],S=b/w,T=I/y;n.includes("e")&&(S=(f[0]-u[0])/w),n.includes("s")&&(T=(f[1]-u[1])/y),n.includes("w")&&(S=(m[0]-f[0])/w),n.includes("n")&&(T=(m[1]-f[1])/y);let M=e.width*S,R=e.height*T;if(s&&(M=2*M-t.width,R=2*R-t.height),r){let C=Math.abs(M)/t.width,F=Math.abs(R)/t.height;if(n.length===1&&(R*=C,M*=F),n.length===2){let B=Math.max(C,F);M=t.width*B*Math.sign(M),R=t.height*B*Math.sign(R)}}return{nextWidth:M,nextHeight:R}},ng=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(B=>t.get(B.id)),d=l.reduce((B,Y)=>{if(!K(Y))return B;let O=Ft(Y);if(!O)return B;let X=t.get(O)??null;return ce(X)?[...B,{...X,...L.getBoundTextElementPosition(Y,X,n)}]:B},[]),c=Yt(l.map(B=>B).concat(d)),{minX:u,minY:m,maxX:p,maxY:f,midX:h,midY:E}=c,g=p-u,x=f-m,w={ne:[u,f],se:[u,m],sw:[p,m],nw:[p,f],e:[u,m+x/2],w:[p,m+x/2],n:[u+g/2,f],s:[u+g/2,m]},[y,b]=a?[h,E]:w[i],I=a?2:1,S=Math.max(Math.abs(o-y)/g||0,Math.abs(r-b)/x||0)*I,T=i.includes("e")||i.includes("w")?Math.abs(o-y)*I:g,M=i.includes("n")||i.includes("s")?Math.abs(r-b)*I:x;s&&(T=g*S*Math.sign(o-y),M=x*S*Math.sign(r-b));let R={ne:[o<y,r>b],se:[o<y,r<b],sw:[o>y,r<b],nw:[o>y,r>b],e:[o<y,!1],w:[o>y,!1],n:[!1,r>b],s:[!1,r<b]},[C,F]=R[i].map(B=>B);return{originalBoundingBox:c,nextWidth:T,nextHeight:M,flipByX:C,flipByY:F}},ig=(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 T=o.get(S.id);return T&&I.push({orig:T,latest:S}),I},[]),p;if(u)p=u;else{let I=m.reduce((S,{orig:T})=>{if(!K(T))return S;let M=Ft(T);if(!M)return S;let R=o.get(M)??null;return ce(R)?[...S,{...R,...L.getBoundTextElementPosition(T,R,t)}]:S},[]);p=Yt(m.map(({orig:S})=>S).concat(I))}let{minX:f,minY:h,maxX:E,maxY:g,midX:x,midY:w}=p,y=E-f,b=g-h;if(c===void 0&&d===void 0&&(c=y,d=b),r&&(c===void 0?c=d*(y/b):d===void 0?d=c*(b/y):Math.abs(c/d-y/b)>.001&&(c=d*(y/b))),c&&d){let I=n.includes("e")||n.includes("w")?Math.abs(c)/y:1,S=n.includes("n")||n.includes("s")?Math.abs(d)/b:1,T;n.length===1?T=n.includes("e")||n.includes("w")?I:S:T=Math.max(Math.abs(c)/y||0,Math.abs(d)/b||0);let M={ne:[f,g],se:[f,h],sw:[E,h],nw:[E,g],e:[f,h+b/2],w:[E,h+b/2],n:[f+y/2,g],s:[f+y/2,h]},[R,C]=s?[x,w]:M[n],F=r||m.some(A=>A.latest.angle!==0||J(A.latest)||ld(A.latest));F&&(I=T,S=T);let[B,Y]=[a?-1:1,l?-1:1],O=[];for(let{orig:A,latest:V}of m){if(J(A)&&ce(A))continue;let Z=A.width*I,St=A.height*S,pt=tr(A.angle*B*Y),Fi=K(A)||Ie(A),ar=A.x-R,Ri=A.y-C,ti=a&&!Fi?Z:0,lr=l&&!Fi?St:0,Ni=R+B*(ar*I+ti),zi=C+Y*(Ri*S+lr),We=$c(A,Z*B,St*Y,!1),qe={x:Ni,y:zi,width:Z,height:St,angle:pt,...We};if(_(A)&&(A.startBinding&&(qe.startBinding={...A.startBinding,fixedPoint:[a?-A.startBinding.fixedPoint[0]+1:A.startBinding.fixedPoint[0],l?-A.startBinding.fixedPoint[1]+1:A.startBinding.fixedPoint[1]]}),A.endBinding&&(qe.endBinding={...A.endBinding,fixedPoint:[a?-A.endBinding.fixedPoint[0]+1:A.endBinding.fixedPoint[0],l?-A.endBinding.fixedPoint[1]+1:A.endBinding.fixedPoint[1]]}),A.fixedSegments&&We.points&&(qe.fixedSegments=A.fixedSegments.map(At=>({...At,start:We.points[At.index-1],end:We.points[At.index]})))),xe(A)&&(qe.scale=[A.scale[0]*B,A.scale[1]*Y]),J(A)){let At=js(A,t,Z);if(!At)return;qe.fontSize=At.size}let Vt=o.get(Ft(A)??"");if(Vt)if(F){let At=Vt.fontSize*T;if(At<Ys)return;qe.boundTextFontSize=At}else qe.boundTextFontSize=Vt.fontSize;O.push({element:V,update:qe})}let X=O.map(({element:A})=>A),k=new Map(O.map(({element:A})=>[A.id,A]));for(let{element:A,update:{boundTextFontSize:V,...Z}}of O){let{angle:St}=Z;i.mutateElement(A,Z),ve(A,i,{simultaneouslyUpdated:X}),Se(A)&&(A.startBinding&&(k.has(A.startBinding.elementId)||Te(A,"start",i)),A.endBinding&&(k.has(A.endBinding.elementId)||Te(A,"end",i)));let pt=$(A,t);pt&&V&&(i.mutateElement(pt,{fontSize:V,angle:K(A)?void 0:St}),Ln(A,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as nt,pointOnLineSegment as Jc,pointRotateRads as or}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as Ks}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as $s}from"@excalidraw/common";import{pointFrom as Vc,pointRotateRads as og}from"@excalidraw/math";var Zc={mouse:8,pen:16,touch:28},rg=16,Kc={e:!0,s:!0,n:!0,w:!0},SA={e:!0,s:!0,n:!0,w:!0},AA={e:!0,s:!0,n:!0,w:!0,rotation:!0},qc={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},Xs={e:!0,s:!0,n:!0,w:!0},$t=(e,t,n,i,o,r,s)=>{let[a,l]=og(Vc(e+n/2,t+i/2),Vc(o,r),s);return[a-n/2,l-i/2,n,i]},ir=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),Vs=e=>ir(e)?Kc:{},Zs=([e,t,n,i,o,r],s,a,l,d={},c=4,u=$s)=>{let m=Zc[l],p=m/a.value,f=m/a.value,h=m/a.value,E=m/a.value,g=n-e,x=i-t,w=c/a.value,y=(m-u*2)/(2*a.value),b={nw:d.nw?void 0:$t(e-w-h+y,t-w-E+y,p,f,o,r,s),ne:d.ne?void 0:$t(n+w-y,t-w-E+y,p,f,o,r,s),sw:d.sw?void 0:$t(e-w-h+y,i+w-y,p,f,o,r,s),se:d.se?void 0:$t(n+w-y,i+w-y,p,f,o,r,s),rotation:d.rotation?void 0:$t(e+g/2-p/2,t-w-E+y-rg/a.value,p,f,o,r,s)},I=5*Zc.mouse/a.value;return Math.abs(g)>I&&(d.n||(b.n=$t(e+g/2-p/2,t-w-E+y,p,f,o,r,s)),d.s||(b.s=$t(e+g/2-p/2,i+w-y,p,f,o,r,s))),Math.abs(x)>I&&(d.w||(b.w=$t(e-w-h+y,t+x/2-f/2,p,f,o,r,s)),d.e||(b.e=$t(n+w-y,t+x/2-f/2,p,f,o,r,s))),b},Qc=(e,t,n,i="mouse",o=Kc)=>{if(e.locked||_(e))return{};if(e.type==="freedraw"||K(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=Xs:s[0]>0&&s[1]<0?o=qc:s[0]>0&&s[1]>0?o=Xs:s[0]<0&&s[1]>0?o=qc:s[0]<0&&s[1]<0&&(o=Xs)}}else q(e)&&(o={...o,rotation:!0});let r=K(e)?$s+8:xe(e)?0:$s;return Zs(j(e,n,!0),e.angle,t,i,o,r,xe(e)?0:void 0)},MA=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return _(i)?!1:K(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var Qs=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],sg=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=Qc(e,r,t,s,Vs(a));if(l&&Qs(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?Qs(m,i,o):!1});if(c.length>0)return c[0];if(ir(a)){let[u,m,p,f,h,E]=j(e,t);if(!(K(e)&&e.points.length<=2)){let g=xe(e)?0:Ks/r.value,x=Ks/r.value,w=eu(nt(u-g,m-g),nt(p+g,f+g),nt(h,E),e.angle);for(let[y,b]of Object.entries(w))if(Jc(nt(i,o),b,x))return y}}return!1},OA=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=sg(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),kA=([e,t,n,i],o,r,s,a,l)=>{let d=Zs([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&&Qs(m,o,r)});if(c)return c;if(ir(l)){let u=(e+n)/2,m=(t+i)/2,p=Ks/s.value,f=eu(nt(e-p,t-p),nt(n+p,i+p),nt(u,m),0);for(let[h,E]of Object.entries(f))if(Jc(nt(o,r),E,p))return h}return!1},qs=["ns","nesw","ew","nwse"],ag=(e,t)=>{let n=qs.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=qs[(n+i)%qs.length]}return e},FA=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=ag(o,t.angle)),o?`${o}-resize`:""},eu=([e,t],[n,i],o,r)=>{let s=or(nt(e,t),o,r),a=or(nt(n,t),o,r),l=or(nt(e,i),o,r),d=or(nt(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var HA=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||Pt(t,e).length));P();import{pointFrom as rr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as lg,DEFAULT_FONT_SIZE as dg,TEXT_ALIGN as cg,VERTICAL_ALIGN as ug,getSizeFromPoints as mg,randomId as pg,arrayToMap as fg,assertNever as Js,cloneJSON as nu,getFontString as hg,isDevEnv as Eg,toBrandedType as gg,getLineHeight as xg}from"@excalidraw/common";var sr={width:100,height:0},In=100,wg=(e,t,n)=>{let i=Fn({x:0,y:0,textAlign:cg.CENTER,verticalAlign:ug.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),fo(i,e,n),[e,i]},tu=(e,t,n,i,o)=>{let r,s;if(Object.assign(e,{startBinding:e?.startBinding||null,endBinding:e.endBinding||null}),t){let c=t?.width??In,u=t?.height??In,m;t.id&&(m=i.getElement(t.id),m||console.error(`No element for start binding with id ${t.id} found`));let p=t.x||e.x-c,f=t.y||e.y-u/2,h=m?m.type:t.type;if(h){if(h==="text"){let E="";m&&m.type==="text"?E=m.text:t.type==="text"&&(E=t.text),E||console.error(`No text found for start binding text element for ${e.id}`),r=Fn({x:p,y:f,type:"text",...m,...t,text:E}),Object.assign(r,{x:t.x||e.x-r.width,y:t.y||e.y-r.height/2})}else switch(h){case"rectangle":case"ellipse":case"diamond":{r=kn({x:p,y:f,width:c,height:u,...m,...t,type:h});break}default:Js(e,`Unhandled element start type "${t.type}"`,!0)}yt(e,r,"orbit","start",o)}}if(n){let c=n?.height??In,u=n?.width??In,m;n.id&&(m=i.getElement(n.id),m||console.error(`No element for end binding with id ${n.id} found`));let p=n.x||e.x+e.width,f=n.y||e.y-c/2,h=m?m.type:n.type;if(h){if(h==="text"){let E="";m&&m.type==="text"?E=m.text:n.type==="text"&&(E=n.text),E||console.error(`No text found for end binding text element for ${e.id}`),s=Fn({x:p,y:f,type:"text",...m,...n,text:E}),Object.assign(s,{y:n.y||e.y-s.height/2})}else switch(h){case"rectangle":case"ellipse":case"diamond":{s=kn({x:p,y:f,width:u,height:c,...m,...n,type:h});break}default:Js(e,`Unhandled element end type "${h}"`,!0)}yt(e,s,"orbit","end",o)}}if(e.points.length<2)return{linearElement:e,startBoundElement:r,endBoundElement:s};let a=e.points.length-1,l=.5,d=nu(e.points);return e.points[a][0]>e.points[a-1][0]&&(d[0][0]=l,d[a][0]-=l),e.points[a][0]<e.points[a-1][0]&&(d[0][0]=-l,d[a][0]+=l),e.points[a][1]>e.points[a-1][1]&&(d[0][1]=l,d[a][1]-=l),e.points[a][1]<e.points[a-1][1]&&(d[0][1]=-l,d[a][1]+=l),Object.assign(e,L.getNormalizeElementPointsAndCoords({...e,points:d})),{linearElement:e,startBoundElement:r,endBoundElement:s}},ea=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>Ls(Array.from(this.excalidrawElements.values()));getElementsMap=()=>gg(fg(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},eM=(e,t)=>{if(!e)return[];let n=nu(e),i=new ea,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:pg()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||In,p=l?.label?.text&&l.height===void 0?0:l?.height||In;d=kn({...l,width:m,height:p});break}case"line":{let m=l.width||sr.width,p=l.height||sr.height;d=bc({width:m,height:p,points:[rr(0,0),rr(m,p)],...l});break}case"arrow":{let m=l.width||sr.width,p=l.height||sr.height;d=qo({width:m,height:p,endArrowhead:"arrow",points:[rr(0,0),rr(m,p)],...l,type:"arrow"}),Object.assign(d,mg(d.points));break}case"text":{let m=l?.fontFamily||lg,p=l?.fontSize||dg,f=l?.lineHeight||xg(m),h=l.text??"",E=Ei(h),g=Xe(E,hg({fontFamily:m,fontSize:p}),f);d=Fn({width:g.width,height:g.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=yc({width:l?.width||In,height:l?.height||In,...l});break}case"frame":{d=gc({x:0,y:0,...l});break}case"magicframe":{d=xc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,Js(l,`Unhandled element type "${l.type}"`,!0)}i.getElement(d.id)?console.error(`Duplicate id found for ${d.id}`):(i.add(d),o.set(d.id,l),c&&r.set(c,d.id))}let s=i.getElementsMap(),a=new Qn(s);for(let[l,d]of o){let c=i.getElement(l);switch(d.type){case"rectangle":case"ellipse":case"diamond":case"arrow":{if(d.label?.text){let[u,m]=wg(c,d?.label,a);if(i.add(u),i.add(m),H(u)){let p=d.type==="arrow"?d?.start:void 0,f=d.type==="arrow"?d?.end:void 0;if(p&&p.id){let x=r.get(p.id);x&&Object.assign(p,{id:x})}if(f&&f.id){let x=r.get(f.id);x&&Object.assign(f,{id:x})}let{linearElement:h,startBoundElement:E,endBoundElement:g}=tu(u,p,f,i,a);u=h,i.add(h),i.add(E),i.add(g)}}else switch(d.type){case"arrow":{let{start:u,end:m}=d;if(u&&u.id){let E=r.get(u.id);Object.assign(u,{id:E})}if(m&&m.id){let E=r.get(m.id);Object.assign(m,{id:E})}let{linearElement:p,startBoundElement:f,endBoundElement:h}=tu(c,u,m,i,a);i.add(p),i.add(f),i.add(h);break}}break}}}for(let[l,d]of o){if(d.type!=="frame"&&d.type!=="magicframe")continue;let c=i.getElement(l);if(!c)throw new Error(`Excalidraw element with id ${l} doesn't exist`);let u=[];d.children.forEach(b=>{let I=r.get(b);if(!I)throw new Error(`Element with ${b} wasn't mapped correctly`);let S=i.getElement(I);if(!S)throw new Error(`Frame element with id ${I} doesn't exist`);Object.assign(S,{frameId:c.id}),S?.boundElements?.forEach(T=>{let M=i.getElement(T.id);if(!M)throw new Error(`Bound element with id ${T.id} doesn't exist`);Object.assign(M,{frameId:c.id}),u.push(M)}),u.push(S)});let[m,p,f,h]=Oe(u),E=10;m=m-E,p=p-E,f=f+E,h=h+E;let g=c?.x||m,x=c?.y||p,w=c?.width||f-m,y=c?.height||h-p;Object.assign(c,{x:g,y:x,width:w,height:y}),Eg()&&d.children.length&&(c?.x||c?.y||c?.width||c?.height)&&console.info("User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically")}return i.getElements()};P();var rM=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return Yc(n.selectedLinearElement,e.scene.getNonDeletedElementsMap(),e.lastPointerMoveCoords,e.scene,n,e.getEffectiveGridSize(),t.altKey),!0;if(n.selectedLinearElement.hoverPointIndex!==null&&e.lastPointerMoveEvent&&n.selectedLinearElement.initialState.lastClickedPoint>=0&&n.selectedLinearElement.isDragging)return L.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};var cM=e=>e.reduce((t,n)=>t+n.version,0),jd=e=>{let t=5381;for(let n of bg(e))t=(t<<5)+t+n.versionNonce;return t>>>0},Xd=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},uM=e=>e.filter(t=>!t.isDeleted&&!Rd(t)),mM=e=>e.filter(t=>!t.isDeleted),pM=e=>!e.isDeleted;export{gn as AppStateDelta,Bp as BASE_ARROW_MIN_LENGTH,Cl as BASE_BINDING_GAP,Cn as BASE_BINDING_GAP_ELBOW,te as BASE_PADDING,mn as BindableElement,un as BoundElement,Ue as CaptureUpdateAction,o1 as DEFAULT_LINK_SIZE,Kc as DEFAULT_OMIT_SIDES,U as Delta,Ms as DurableIncrement,bs as ElementBounds,xn as ElementsDelta,Ts as EphemeralIncrement,Mi as FOCUS_POINT_SIZE,Bc as FlowChartCreator,Dc as FlowChartNavigator,we as HEADING_DOWN,ze as HEADING_LEFT,fe as HEADING_RIGHT,Ve as HEADING_UP,mh as INVISIBLY_SMALL_ELEMENT_SIZE,Ds as InvalidFractionalIndexError,L as LinearElementEditor,Pe as MINIMAL_CROP_SIZE,AA as OMIT_SIDES_FOR_FRAME,SA as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Qn as Scene,Ze as ShapeCache,_d as Store,Gi as StoreChange,vs as StoreDelta,Yo as StoreIncrement,wn as StoreSnapshot,et as aabbForElement,Sf as addElementsToFrame,_E as addNewNodes,t0 as addToGroup,dP as alignElements,Rp as avoidRectangularCorner,yt as bindBindingElement,md as bindElementsToFramesAfterDuplication,Lp as bindOrUnbindBindingElement,yy as bindOrUnbindBindingElements,Kr as bindPointToSnapToElementOutline,Fl as bindingProperties,Ml as bumpVersion,zp as calculateFixedPointForElbowArrowBinding,Yn as calculateFixedPointForNonElbowArrowBinding,Aw as canApplyRoundnessTypeToElement,za as canBecomePolygon,yd as canChangeRoundness,pE as canCreateLinkFromElements,h1 as canHaveArrowheads,ir as canResizeFromSides,_n as charWidth,pe as compareHeading,gi as computeBoundTextPosition,Gr as computeContainerDimensionForBoundText,eb as containsCJK,eM as convertToExcalidrawElements,nS as createPlaceholderEmbeddableLabel,Fs as createSrcDoc,Ew as cropElement,en as deconstructDiamondElement,so as deconstructLinearOrFreeDrawElement,Jt as deconstructRectanguloidElement,As as deepCopyElement,CI as defaultGetElementLinkFromSelection,$w as detectLineHeight,on as distanceToElement,hI as distributeElements,bi as doBoundsIntersect,TI as dragNewElement,AI as dragSelectedElements,Ph as duplicateElement,IP as duplicateElements,e0 as editGroupForSelectedElement,re as elementCenterPoint,pn as elementOverlapsWithFrame,Bi as elementWithCanvasCache,hn as elementsAreInFrameBounds,ad as elementsAreInSameGroup,oS as embeddableURLValidator,cd as excludeElementsInFramesFromSelection,R0 as filterElementsEligibleAsFrameChildren,Iy as fixBindingsAfterDeletion,kl as fixDuplicatedBindingsAfterDuplication,_r as flipHeading,W0 as frameAndChildrenSelectedTogether,Xa as generateLinearCollisionShape,_e as generateRoughOptions,go as getAllHoveredElementAtPoint,Ka as getApproxMinLineHeight,qa as getApproxMinLineWidth,Rl as getArrowLocalFixedPoints,sh as getArrowheadAngle,gs as getArrowheadPoints,rh as getArrowheadSize,De as getBindingGap,Sy as getBindingSideMidPoint,ns as getBindingStrategyForDraggingBindingElementEndpoints,$ as getBoundTextElement,Ft as getBoundTextElementId,mb as getBoundTextElementPosition,xi as getBoundTextMaxHeight,at as getBoundTextMaxWidth,ys as getBoundsFromPoints,xt as getCenterForBounds,$1 as getClosestElementBounds,Yt as getCommonBoundingBox,Oe as getCommonBounds,cb as getContainerCenter,Or as getContainerCoords,Ae as getContainerElement,Ut as getContainingFrame,Ct as getCornerRadius,xo as getCubicBezierCurveBound,FA as getCursorForResizingElement,Df as getDefaultFrameName,Mw as getDefaultRoundnessTypeForElement,ja as getDiamondBaseCorners,Hn as getDiamondPoints,MI as getDragOffsetXY,X1 as getDraggedElementsBounds,j as getElementAbsoluteCoords,he as getElementBounds,us as getElementLineSegments,rs as getElementPointsCoords,vd as getElementShape,OA as getElementWithTransformHandleType,pd as getElementsCompletelyInFrame,Ge as getElementsInGroup,F0 as getElementsInNewFrame,k0 as getElementsInResizingFrame,D0 as getElementsIntersectingFrame,U0 as getElementsOverlappingFrame,ds as getElementsWithinSelection,tS as getEmbedLink,gw as getFlipAdjustedCropPosition,fn as getFrameChildren,Pf as getFrameLikeElements,_0 as getFrameLikeTitle,a1 as getFreedrawOutlineAsSegments,Kf as getFreedrawOutlinePoints,Fe as getGlobalFixedPointForBindableElement,Hp as getGlobalFixedPoints,Al as getHeadingForElbowArrowSnap,Rt as getHoveredElementForBinding,pl as getHoveredElementForFocusPoint,qS as getInitializedImageElements,uo as getLineHeightInPx,nn as getLineWidth,Tw as getLinearElementSubType,xS as getLinkDirectionFromKey,GI as getLinkIdAndTypeFromSelection,Vl as getLockedLinearCursorAlignSize,wm as getMaxCharWidth,i0 as getMaximumGroups,Zw as getMinCharWidth,vi as getMinMaxXYFromCurvePathOps,co as getMinTextElementWidth,dd as getNewGroupIdsForDuplication,mM as getNonDeletedElements,sd as getNonDeletedGroupIds,iP as getNormalizedDimensions,Zn as getObservedAppState,Vs as getOmitSidesForEditorInterface,Uw as getOriginalContainerHeightFromCache,Ps as getPerfectElementSize,Hs as getPredecessors,j1 as getRectangleBoxAbsoluteCoords,Hf as getRenderOpacity,gA as getResizeArrowDirection,EA as getResizeOffsetXY,Qt as getResizedElementAbsoluteCoords,O0 as getRootElements,cM as getSceneVersion,Pt as getSelectedElements,ko as getSelectedElementsByGroup,ls as getSelectedGroupForElement,gf as getSelectedGroupIdForElement,hf as getSelectedGroupIds,E0 as getSelectionStateForElements,mm as getSnapOutlineMidPoint,h0 as getTargetElements,Mf as getTargetFrame,ub as getTextElementAngle,Eb as getTextFromElements,xm as getTextHeight,Qa as getTextWidth,kA as getTransformHandleTypeFromCoords,Qc as getTransformHandles,Zs as getTransformHandlesFromCoords,Ca as getUncroppedImageElement,br as getUncroppedWidthAndHeight,p0 as getVisibleAndNonSelectedElements,uM as getVisibleElements,V1 as getVisibleSceneBounds,G0 as groupByFrameLikes,L0 as groupsAreAtLeastIntersectingTheFrame,C0 as groupsAreCompletelyOutOfFrame,Ln as handleBindTextResize,Yc as handleFocusPointDrag,YS as handleFocusPointHover,US as handleFocusPointPointerDown,WS as handleFocusPointPointerUp,c1 as hasBackground,ht as hasBoundTextElement,MA as hasBoundingBox,u1 as hasStrokeColor,p1 as hasStrokeStyle,m1 as hasStrokeWidth,jd as hashElementsVersion,Xd as hashString,Ne as headingForPoint,yi as headingForPointFromElement,lt as headingForPointIsHorizontal,He as headingIsHorizontal,Ub as headingIsVertical,Qm as hitElementBoundText,Km as hitElementBoundingBox,Fb as hitElementBoundingBoxOnly,Et as hitElementItself,rn as intersectElementWithLineSegment,Sw as isArrowBoundToElement,H as isArrowElement,de as isBindableElement,zr as isBindableElementInsideOtherBindable,Se as isBindingElement,tm as isBindingElementType,bt as isBindingEnabled,ce as isBoundToContainer,B0 as isCursorInFrame,Ju as isCurvedArrow,_ as isElbowArrow,nP as isElementCompletelyInViewport,ms as isElementContainingFrame,hd as isElementInFrame,Ef as isElementInGroup,ud as isElementInViewport,Xn as isElementIntersectingFrame,OI as isElementLink,Oa as isEmbeddableElement,Iw as isExcalidrawElement,_p as isFixedPoint,yr as isFlowchartNodeElement,Jo as isFocusPointVisible,ro as isFrameElement,q as isFrameLikeElement,Ie as isFreeDrawElement,Ku as isFreeDrawElementType,VE as isHTMLSVGElement,io as isIframeElement,oo as isIframeLikeElement,xe as isImageElement,ld as isInGroup,Tn as isInitializedImageElement,Rd as isInvisiblySmallElement,Bt as isLineElement,K as isLinearElement,em as isLinearElementType,ka as isMagicFrameElement,Xw as isMeasureTextSupported,wS as isNodeInFlowchart,pM as isNonDeletedElement,Dn as isPathALoop,Gt as isPointInElement,pi as isRectangularElement,Fa as isRectanguloidElement,ff as isSelectedViaGroup,Qu as isSharpArrow,Pw as isSimpleArrow,f0 as isSomeElementSelected,nm as isTextBindableContainer,J as isTextElement,Ra as isUsingAdaptiveRadius,Na as isUsingProportionalRadius,vw as isValidPolygon,hb as isValidTextContainer,$E as loadHTMLImageElement,as as makeNextSelectedElementIds,st as maxBindingDistance_simple,rM as maybeHandleArrowPointlikeDrag,iS as maybeParseEmbedSrc,js as measureFontSizeFromWidth,Xe as measureText,LS as moveAllLeft,CS as moveAllRight,Nc as moveArrowAboveBindable,DS as moveOneLeft,BS as moveOneRight,be as mutateElement,qo as newArrowElement,kn as newElement,Be as newElementWith,jI as newEmbeddableElement,gc as newFrameElement,VI as newFreeDrawElement,XI as newIframeElement,yc as newImageElement,bc as newLinearElement,xc as newMagicFrameElement,Fn as newTextElement,Nd as normalizeElementOrder,tn as normalizeFixedPoint,KS as normalizeSVG,Ei as normalizeText,Fo as omitGroupsContainingFrameLikes,If as omitPartialGroups,Jd as orderByFractionalIndex,hi as originalContainerCache,kI as parseElementLinkFromURL,Mm as parseTokens,sn as pointInsideBounds,nA as positionElementsOnGrid,Tr as projectFixedPointOntoDiagonal,fo as redrawTextBoundingBox,$I as refreshTextDimensions,Af as removeAllElementsFromFrame,fd as removeElementsFromFrame,n0 as removeFromSelectedGroups,s1 as renderElement,r1 as renderSelectionElement,N0 as replaceAllElementsInFrame,$c as rescalePointsInElement,Va as resetOriginalContainerCache,ig as resizeMultipleElements,eg as resizeSingleElement,KE as resizeSingleTextElement,sg as resizeTest,pf as selectGroup,od as selectGroupsForSelectedElements,rd as selectGroupsFromGivenElements,Vw as setCustomTextMetricsProvider,pb as shouldAllowVerticalAlign,H0 as shouldApplyFrameClip,by as shouldEnableBindingForPointerEvent,Eo as shouldTestInside,HA as showSelectedShapeActions,is as snapToMid,fb as suppportsHorizontalAlign,Ls as syncInvalidIndices,Yd as syncInvalidIndicesImmutable,ki as syncMovedIndices,$l as toggleLinePolygonState,f1 as toolIsArrow,hA as transformElements,Te as unbindBindingElement,Py as updateBindings,ve as updateBoundElements,dt as updateBoundPoint,Wn as updateElbowArrowPoints,z0 as updateFrameMembershipOfSelectedElements,ZS as updateImageCache,$a as updateOriginalContainerCache,Sl as validateElbowPoints,Lh as validateFractionalIndices,Nt as vectorToHeading,kt as wrapText};
27
+ `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return pt.set(e,p),p}return pt.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},aS=e=>{let t;ao(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=BE.Helvetica,o=CE({fontSize:n,fontFamily:i});return Nn({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:Ft(t,o,e.width-20),textAlign:"center",verticalAlign:LE.MIDDLE,angle:e.angle??0})},Us=(e,t)=>{try{let{hostname:n}=new URL(e),i=n.replace(/^www\./,"");if(t instanceof Set){if(_s.has(i))return i;let r=i.replace(/^([^.]+)/,"*");return _s.has(r)?r:null}let o=t.replace(/^www\./,"");if(i===o)return o}catch{}return null},lS=e=>{let t=e.match(NE);if(t&&t.length===2)return t[1];let n=e.match(_E);if(n&&n.length===2)return n[1];let i=e.match(FE);if(i&&i.length===2)return i[1];if(vc.test(e))return`https://giphy.com/embed/${vc.exec(e)[1]}`;let o=e.match(HE);return o&&o.length===2?o[1]:e},dS=(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(Us(e,n))return!0;return!1}}return!!Us(e,_s)};P();import{KEYS as tr,invariant as nr,toBrandedType as WE}from"@excalidraw/common";import{pointFrom as Cc}from"@excalidraw/math";var ti=100,zn=100,IS=e=>{switch(e){case tr.ARROW_UP:return"up";case tr.ARROW_DOWN:return"down";case tr.ARROW_RIGHT:return"right";case tr.ARROW_LEFT:return"left";default:return"right"}},kc=(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;nr(de(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=Ii(t,nt(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,qe)).map(r=>r.relative);case"down":return o.filter(r=>pe(r.heading,be)).map(r=>r.relative);case"right":return o.filter(r=>pe(r.heading,fe)).map(r=>r.relative);case"left":return o.filter(r=>pe(r.heading,_e)).map(r=>r.relative)}},Ws=(e,t,n)=>kc("successors",e,t,n),Ys=(e,t,n)=>kc("predecessors",e,t,n),YE=(e,t,n)=>{let i=zn+e.width;if(n==="up"||n==="down"){let a=ti+e.height,l=e.x,d=e.x+e.width;if(t.every(c=>c.x+c.width<l||c.x>d))return{x:0,y:a*(n==="up"?-1:1)}}else if(n==="right"||n==="left"){let a=e.y,l=e.y+e.height;if(t.every(d=>d.y+d.height<a||d.y>l))return{x:(zn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=ti+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=ti+e.height,r=(t.length===0,zn+e.width),s=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*o:t.length/2*o*-1;return n==="left"?{x:r*-1,y:s}:{x:r,y:s}},jE=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=Ws(e,o,n),s=Ys(e,o,n),a=YE(e,[...r,...s],n),l=Rn({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});nr(Ar(l),"not an ExcalidrawFlowchartNodeElement");let d=Fc(e,l,n,t,i);return{nextNode:l,bindingArrow:d}},XE=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=ti*(o-1)+o*e.height,m=e.y+e.height/2-u/2,p=zn+e.width;n==="left"&&(p*=-1),a=e.x+p;let f=(ti+e.height)*s;l=m+f}else{let u=zn*(o-1)+o*e.width,m=e.x+e.width/2-u/2,p=ti+e.height;n==="up"&&(p*=-1),l=e.y+p;let f=(zn+e.width)*s;a=m+f}let d=Rn({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});nr(Ar(d),"not an ExcalidrawFlowchartNodeElement");let c=Fc(e,d,n,t,i);r.push(d),r.push(c)}return r},Fc=(e,t,n,i,o)=>{let r,s;switch(n){case"up":{r=e.x+e.width/2,s=e.y-6;break}case"down":{r=e.x+e.width/2,s=e.y+e.height+6;break}case"right":{r=e.x+e.width+6,s=e.y+e.height/2;break}case"left":{r=e.x-6,s=e.y+e.height/2;break}}let l,d;switch(n){case"up":{l=t.x+t.width/2-r,d=t.y+t.height-s+6;break}case"down":{l=t.x+t.width/2-r,d=t.y-s-6;break}case"right":{l=t.x-r-6,d=t.y-s+t.height/2;break}case"left":{l=t.x+t.width-r+6,d=t.y-s+t.height/2;break}}let c=er({type:"arrow",x:r,y:s,startArrowhead:null,endArrowhead:i.currentItemEndArrowhead,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeWidth:e.strokeWidth,opacity:e.opacity,roughness:e.roughness,points:[Cc(0,0),Cc(l,d)],elbowed:!0}),u=o.getNonDeletedElementsMap();It(c,e,"orbit","start",o),It(c,t,"orbit","end",o);let m=new Map;m.set(e.id,e),m.set(t.id,t),m.set(c.id,c),C.movePoints(c,o,new Map([[1,{point:c.points[1]}]]));let p=jn(c,WE(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...p}},Gc=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(!de(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=[...Ws(t,n,i),...Ys(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=>[...Ws(t,n,a),...Ys(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}},Oc=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}=jE(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=XE(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);nr(s&&co(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>En([a],s,r)||fn(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}},SS=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{pointDistance as ni,pointFrom as Xs}from"@excalidraw/math";import{invariant as $c}from"@excalidraw/common";P();import{arrayToMap as Nc,findIndex as zc,findLastIndex as Hc}from"@excalidraw/common";var js=(e,t)=>e.frameId===t||e.id===t,_c=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=Nc(n||St(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},$E=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),[])},Rc=(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))}}},VE=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{js(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},Uc=(e,t,n,i,o,r)=>{let s=r||Nt(e,n,i);if(!s)return n;let a=V(s,i),l=Q(s)?Me(s,i):null,d=[s.id,a?.id,l?.id].filter(m=>!!m),c=n.findIndex(m=>d.includes(m.id)),u=n.findIndex(m=>m.id===t.id);if(u!==-1&&c!==-1&&u<c){let m=Array.from(n),p=m.splice(u,1)[0];m.splice(c,0,p),o.replaceAllElements(m)}return n},ZE=(e,t,n,i,o,r)=>{let s=t[n],a=m=>m.isDeleted?!1:o?m.frameId===o:e.editingGroupId?m.groupIds.includes(e.editingGroupId):!0,l=i==="left"?Hc(t,m=>a(m),Math.max(0,n-1)):zc(t,m=>a(m),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return Rc(d,t,i,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(d.frameId||Z(d))){let m=VE(t,d.frameId||d.id);return i==="left"?t.indexOf(m[0]):t.indexOf(m[m.length-1])}if(!d.groupIds.length)return Rc(d,t,i,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Oe(t,c);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},Wc=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),Yc=(e,t,n,i)=>{let o=_c(e,t),r=Wc(e,o),s=$E(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],m=n==="left"?c:u,p=l.some(w=>{let y=e[w];return y.frameId&&a.has(y.frameId)})?null:e[m]?.frameId,f=ZE(t,e,m,n,p,i);if(f===-1||m===f)return;let h=n==="left"?e.slice(0,f):e.slice(0,c),E=e.slice(c,u+1),g=n==="left"?e.slice(f,c):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...h,...E,...g,...x]:[...h,...g,...E,...x]}),zi(e,r),e},jc=(e,t,n,i,o)=>{let r=_c(e,t,o),s=Wc(e,r),a=[],l,d;if(n==="left"){if(i)l=zc(e,f=>js(f,i));else if(t.editingGroupId){let f=Oe(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=Hc(e,f=>js(f,i));else if(t.editingGroupId){let f=Oe(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 zi(p,s),p};function Xc(e,t,n,i){let o=Nc(St(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 OS=(e,t,n)=>Yc(e,t,"left",n),kS=(e,t,n)=>Yc(e,t,"right",n),FS=(e,t)=>Xc(e,t,"left",jc),RS=(e,t)=>Xc(e,t,"right",jc);var ir=(e,t,n,i,o,r,s=!1)=>{if(U(t)||!Pt(o)||t.points.length!==2)return!1;if(!s){let l=t.startBinding?.elementId===n.id?0:t.points.length-1,d=C.getPointAtIndexGlobalCoordinates(t,l,i);if(ni(e,d)<vi*1.5/o.zoom.value)return!1}let a=C.getPointAtIndexGlobalCoordinates(t,r==="end"?t.points.length-1:0,i);return ni(e,a)>=vi*1.5/o.zoom.value&&xt({element:n,elementsMap:i,point:e,threshold:Be(n,t),overrideShouldTestInside:!0})},qE=(e,t,n,i,o,r,s)=>{let a=new Map,l=n?"startBinding":"endBinding",d=n?"endBinding":"startBinding",c=e[l],u=e[d];if(c&&t){let m=t&&u&&c.elementId===u.elementId;s||m?c={...c,mode:"inside"}:c={...c,mode:"orbit"};let p=n?0:e.points.length-1,f=ut(e,l,c,t,i,!0);f&&a.set(p,{point:f})}if(u&&u.mode==="orbit"){let m=i.get(u.elementId);if(m&&de(m)&&Pt(r)){let p=t&&u.elementId===t.id;s||p?u={...u,mode:"inside"}:u={...u,mode:"orbit"};let f=n?e.points.length-1:0,h=ut(e,d,u,m,i);h&&a.set(f,{point:h})}}a.size>0&&C.movePoints(e,o,a,{[l]:c,[d]:u})},Vc=(e,t,n,i,o,r,s)=>{let a=C.getElement(e.elementId,t);if(!a||!Ae(a)||U(a)||!e.hoveredFocusPointBinding||!e.draggedFocusPointBinding)return;let l=e.draggedFocusPointBinding==="start",d=l?a.startBinding:a.endBinding,{x:c,y:u}=e.pointerOffset,m=Xs(n.x-c,n.y-u),p=l?"startBinding":"endBinding",f=gl(m,a,i.getNonDeletedElements(),t,lt(o.zoom));if(f&&Pt(o)){a[p]&&f.id!==d?.elementId&&ve(a,e.draggedFocusPointBinding,i);let h=s&&a[p]?.mode==="orbit"?"inside":!s&&a[p]?.mode==="inside"?"orbit":null;(!a[p]||h)&&It(a,f,h||"orbit",e.draggedFocusPointBinding,i,m),i.mutateElement(a,{[p]:{...a[p],elementId:f.id,mode:h||a[p]?.mode||"orbit",...Xn(a,f,e.draggedFocusPointBinding,t,m)}})}else{let h=new Map,E=l?0:a.points.length-1;h.set(E,{point:C.createPointAt(a,t,m[0],m[1],r)}),C.movePoints(a,i,h),a[p]&&ve(a,l?"start":"end",i)}qE(a,f,l,t,i,o,s),f&&Pt(o)&&Uc(m,a,i.getElementsIncludingDeleted(),t,i,f)},$S=(e,t,n,i)=>{let o=Xs(t.origin.x,t.origin.y),r=vi*1.5/i.zoom.value;if(e.startBinding?.elementId){let s=n.get(e.startBinding.elementId);if(s&&de(s)&&!s.isDeleted){let a=Ne(e.startBinding.fixedPoint,s,n);if(ir(a,e,s,n,i,"start")&&ni(o,a)<=r)return{hitFocusPoint:"start",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}if(e.endBinding?.elementId){let s=n.get(e.endBinding.elementId);if(s&&de(s)&&!s.isDeleted){let a=Ne(e.endBinding.fixedPoint,s,n);if(ir(a,e,s,n,i,"end")&&ni(o,a)<=r)return{hitFocusPoint:"end",pointerOffset:{x:o[0]-a[0],y:o[1]-a[1]}}}}return{hitFocusPoint:null,pointerOffset:{x:0,y:0}}},VS=(e,t)=>{$c(e.draggedFocusPointBinding,"Must have a dragged focus point at pointer release");let n=C.getElement(e.elementId,t.getNonDeletedElementsMap());$c(n,"Arrow must be in the scene");let i=e.draggedFocusPointBinding==="start"?"startBinding":"endBinding",o=e.draggedFocusPointBinding==="start"?"endBinding":"startBinding",r=n[i]?.elementId,s=n[o]?.elementId,a=r&&t.getNonDeletedElements().find(d=>d.id!==r&&d.id!==s&&de(d)&&d.boundElements?.find(({id:c})=>c===n.id));a&&t.mutateElement(a,{boundElements:a.boundElements?.filter(({id:d})=>d!==n.id)});let l=r&&t.getNonDeletedElementsMap().get(r);l&&t.mutateElement(l,{boundElements:[...(l.boundElements||[])?.filter(({id:d})=>d!==n.id),{id:n.id,type:"arrow"}]})},ZS=(e,t,n,i,o)=>{let r=i.getNonDeletedElementsMap(),s=Xs(t,n),a=vi*1.5/o.zoom.value;if(e.startBinding?.elementId){let l=r.get(e.startBinding.elementId);if(l&&de(l)&&!l.isDeleted){let d=Ne(e.startBinding.fixedPoint,l,r);if(ir(d,e,l,r,o,"start")&&ni(s,d)<=a)return"start"}}if(e.endBinding?.elementId){let l=r.get(e.endBinding.elementId);if(l&&de(l)&&!l.isDeleted){let d=Ne(e.endBinding.fixedPoint,l,r);if(ir(d,e,l,r,o,"end")&&ni(s,d)<=a)return"end"}}return null};P();import{MIME_TYPES as Zc,SVG_NS as KE}from"@excalidraw/common";var QE=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),eA=async({fileIds:e,files:t,imageCache:n})=>{let i=new Map,o=new Map;return await Promise.all(e.reduce((r,s)=>{let a=t[s];return a&&!i.has(s)?(i.set(s,!0),r.concat((async()=>{try{if(a.mimeType===Zc.binary)throw new Error("Only images can be added to ImageCache");let l=QE(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}},tA=e=>e.filter(t=>vn(t)),JE=e=>e?.nodeName.toLowerCase()==="svg",nA=e=>{let t=new DOMParser().parseFromString(e,Zc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!JE(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",KE);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 aA=(e,t,n,i=50)=>{if(!e||e.length===0)return[];let o=[],r=Array.isArray(e[0])?e:e.map(p=>[p]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let p=0;p<s;p+=a)l.push(r.slice(p,p+a));let d=0,c=l.map(p=>{let f=0,h=0,E=p.map(g=>{let[x,w,y,b]=ke(g);return{elements:g,bounds:[x,w,y,b],width:y-x,height:b-w}});return E.forEach((g,x)=>{f+=g.width,x<E.length-1&&(f+=i),g.height>h&&(h=g.height)}),d+=h,{unitBounds:E,width:f,maxHeight:h}}),u=d+Math.max(0,l.length-1)*i,m=n-u/2;return c.forEach(p=>{let{unitBounds:f,width:h,maxHeight:E}=p,g=t-h/2;f.forEach(x=>{let[w,y]=x.bounds,b=g-w,I=m-y;x.elements.forEach(A=>{o.push(Le(A,{x:A.x+b,y:A.y+I}))}),g+=x.width+i}),m+=E+i}),o};P();import{pointCenter as eg,normalizeRadians as rr,pointFrom as ne,pointRotateRads as ft}from"@excalidraw/math";import{MIN_FONT_SIZE as Vs,SHIFT_LOCKING_ANGLE as sr,rescalePoints as qc,getFontString as or}from"@excalidraw/common";var bA=(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)||(tg(m,i,a,l,o),De(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}=sg(f,h,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});rg(E,g,f,h,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return Q(m)&&De(m,i),!0}else if(n.length>1){if(t==="rotation")return ig(e,n,i,a,l,o,d,c),!0;if(t){let{nextWidth:m,nextHeight:p,flipByX:f,flipByY:h,originalBoundingBox:E}=ag(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return lg(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:h,nextWidth:m,nextHeight:p,originalBoundingBox:E}),!0}}return!1},tg=(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+sr/2,u=u-u%sr),u=rr(u));let m=Rt(e),p={angle:u};if(Ae(e)&&(p={...p},e.startBinding&&ve(e,"start",t),e.endBinding&&ve(e,"end",t)),t.mutateElement(e,p),m){let f=t.getElement(m);if(f&&!H(e)){let{x:h,y:E}=wi(e,f,t.getNonDeletedElementsMap());t.mutateElement(f,{angle:u,x:h,y:E})}}},Kc=(e,t,n,i)=>q(e)||Se(e)?{points:qc(0,t,qc(1,n,e.points,i),i)}:{},Zs=(e,t,n)=>{let i=e.width;if(ce(e)){let s=Me(e,t);s&&(i=dt(s,e))}let r=e.fontSize*(n/i);return r<Vs?null:{size:r}},ng=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=Zs(t,a,l);if(d!==null){if(i.includes("n")||i.includes("s")){let c=ne(e.x,e.y),u=$s(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=fo(or({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),m=Ft(t.originalText,or(t),Math.abs(u)),p=Ve(m,or(t),t.lineHeight),f=p.height,h=ne(e.x,e.y),E=$s(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)}}},ig=(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+=sr/2,d-=d%sr);let c=new Map(t.map(u=>[u.id,u]));for(let u of t)if(!Z(u)){let[m,p,f,h]=$(u,l),E=(m+f)/2,g=(p+h)/2,x=e.get(u.id)?.angle??u.angle,[w,y]=ft(ne(E,g),ne(s,a),d+x-u.angle),b=U(u)?{points:_l(u,l)}:{x:u.x+(w-E),y:u.y+(y-g),angle:rr(d+x)};n.mutateElement(u,b),De(u,n,{simultaneouslyUpdated:t}),Ae(u)&&(u.startBinding&&(c.has(u.startBinding.elementId)||ve(u,"start",n)),u.endBinding&&(c.has(u.endBinding.elementId)||ve(u,"end",n)));let I=V(u,l);if(I&&!H(u)){let{x:A,y:T}=wi(u,I,l);n.mutateElement(I,{x:A,y:T,angle:rr(d+x)})}}n.triggerUpdate()},yA=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?$(t[0],n):ke(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=ft(ne(i,o),ne(d,c),-u),e){case"n":return ft(ne(i-(r+a)/2,o-s),ne(0,0),u);case"s":return ft(ne(i-(r+a)/2,o-l),ne(0,0),u);case"w":return ft(ne(i-r,o-(s+l)/2),ne(0,0),u);case"e":return ft(ne(i-a,o-(s+l)/2),ne(0,0),u);case"nw":return ft(ne(i-r,o-s),ne(0,0),u);case"ne":return ft(ne(i-a,o-s),ne(0,0),u);case"sw":return ft(ne(i-r,o-l),ne(0,0),u);case"se":return ft(ne(i-a,o-l),ne(0,0),u);default:return[0,0]}},PA=(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"},og=(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"},$s=(e,t,n,i,o,r,s,a,l)=>{let d=og(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)}}},rg=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(Q(n)&&Q(i))return ng(i,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),m=V(n,u);if(m){let E=o.get(m.id);if(E&&(c={fontSize:E.fontSize}),l){let g={...n,width:e,height:t},x=Zs(m,u,dt(g,m));if(x===null)return;c={fontSize:x.size}}else{let g=el(or(m),m.lineHeight),x=tl(m.fontSize,m.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let p=Kc(i,e,t,!0),f=ne(i.x,i.y);if(q(i)){let[E,g]=he(i,o);f=ne(E,g)}let h=$s(f,i.width,i.height,e,t,i.angle,s,l,d);if(q(i)&&p.points){let E=i.x-f[0],g=i.y-f[1];h.x+=E,h.y+=g;let x=p.points[0][0],w=p.points[0][1];h.x+=x,h.y+=w,p.points=p.points.map(y=>ne(y[0]-x,y[1]-w))}if(e<0&&(h.x=h.x+e),t<0&&(h.y=h.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),H(n)&&m&&l){let E=e/n.width*m.fontSize;if(E<Vs)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};Ae(n)&&(n.startBinding&&(E={...E},n.startBinding&&ve(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}),Cn(n,r,s,l),De(n,r)}},sg=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=Jt(t,t.width,t.height,!0),u=ne(a,l),m=ne(d,c),p=eg(u,m),f=ft(ne(i,o),p,-t.angle),[h,E,g,x]=Jt(e,e.width,e.height,!0),w=g-h,y=x-E,b=m[0]-u[0],I=m[1]-u[1],A=b/w,T=I/y;n.includes("e")&&(A=(f[0]-u[0])/w),n.includes("s")&&(T=(f[1]-u[1])/y),n.includes("w")&&(A=(m[0]-f[0])/w),n.includes("n")&&(T=(m[1]-f[1])/y);let M=e.width*A,O=e.height*T;if(s&&(M=2*M-t.width,O=2*O-t.height),r){let L=Math.abs(M)/t.width,k=Math.abs(O)/t.height;if(n.length===1&&(O*=L,M*=k),n.length===2){let B=Math.max(L,k);M=t.width*B*Math.sign(M),O=t.height*B*Math.sign(O)}}return{nextWidth:M,nextHeight:O}},ag=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(B=>t.get(B.id)),d=l.reduce((B,X)=>{if(!q(X))return B;let _=Rt(X);if(!_)return B;let ie=t.get(_)??null;return ce(ie)?[...B,{...ie,...C.getBoundTextElementPosition(X,ie,n)}]:B},[]),c=jt(l.map(B=>B).concat(d)),{minX:u,minY:m,maxX:p,maxY:f,midX:h,midY:E}=c,g=p-u,x=f-m,w={ne:[u,f],se:[u,m],sw:[p,m],nw:[p,f],e:[u,m+x/2],w:[p,m+x/2],n:[u+g/2,f],s:[u+g/2,m]},[y,b]=a?[h,E]:w[i],I=a?2:1,A=Math.max(Math.abs(o-y)/g||0,Math.abs(r-b)/x||0)*I,T=i.includes("e")||i.includes("w")?Math.abs(o-y)*I:g,M=i.includes("n")||i.includes("s")?Math.abs(r-b)*I:x;s&&(T=g*A*Math.sign(o-y),M=x*A*Math.sign(r-b));let O={ne:[o<y,r>b],se:[o<y,r<b],sw:[o>y,r<b],nw:[o>y,r>b],e:[o<y,!1],w:[o>y,!1],n:[!1,r>b],s:[!1,r<b]},[L,k]=O[i].map(B=>B);return{originalBoundingBox:c,nextWidth:T,nextHeight:M,flipByX:L,flipByY:k}},lg=(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,A)=>{let T=o.get(A.id);return T&&I.push({orig:T,latest:A}),I},[]),p;if(u)p=u;else{let I=m.reduce((A,{orig:T})=>{if(!q(T))return A;let M=Rt(T);if(!M)return A;let O=o.get(M)??null;return ce(O)?[...A,{...O,...C.getBoundTextElementPosition(T,O,t)}]:A},[]);p=jt(m.map(({orig:A})=>A).concat(I))}let{minX:f,minY:h,maxX:E,maxY:g,midX:x,midY:w}=p,y=E-f,b=g-h;if(c===void 0&&d===void 0&&(c=y,d=b),r&&(c===void 0?c=d*(y/b):d===void 0?d=c*(b/y):Math.abs(c/d-y/b)>.001&&(c=d*(y/b))),c&&d){let I=n.includes("e")||n.includes("w")?Math.abs(c)/y:1,A=n.includes("n")||n.includes("s")?Math.abs(d)/b:1,T;n.length===1?T=n.includes("e")||n.includes("w")?I:A:T=Math.max(Math.abs(c)/y||0,Math.abs(d)/b||0);let M={ne:[f,g],se:[f,h],sw:[E,h],nw:[E,g],e:[f,h+b/2],w:[E,h+b/2],n:[f+y/2,g],s:[f+y/2,h]},[O,L]=s?[x,w]:M[n],k=r||m.some(S=>S.latest.angle!==0||Q(S.latest)||md(S.latest));k&&(I=T,A=T);let[B,X]=[a?-1:1,l?-1:1],_=[];for(let{orig:S,latest:z}of m){if(Q(S)&&ce(S))continue;let W=S.width*I,xe=S.height*A,ht=rr(S.angle*B*X),Hi=q(S)||Se(S),ur=S.x-O,_i=S.y-L,ii=a&&!Hi?W:0,mr=l&&!Hi?xe:0,Ui=O+B*(ur*I+ii),Wi=L+X*(_i*A+mr),je=Kc(S,W*B,xe*X,!1),Qe={x:Ui,y:Wi,width:W,height:xe,angle:ht,...je};if(U(S)&&(S.startBinding&&(Qe.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&&(Qe.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&&je.points&&(Qe.fixedSegments=S.fixedSegments.map(Mt=>({...Mt,start:je.points[Mt.index-1],end:je.points[Mt.index]})))),we(S)&&(Qe.scale=[S.scale[0]*B,S.scale[1]*X]),Q(S)){let Mt=Zs(S,t,W);if(!Mt)return;Qe.fontSize=Mt.size}let Zt=o.get(Rt(S)??"");if(Zt)if(k){let Mt=Zt.fontSize*T;if(Mt<Vs)return;Qe.boundTextFontSize=Mt}else Qe.boundTextFontSize=Zt.fontSize;_.push({element:z,update:Qe})}let ie=_.map(({element:S})=>S),F=new Map(_.map(({element:S})=>[S.id,S]));for(let{element:S,update:{boundTextFontSize:z,...W}}of _){let{angle:xe}=W;i.mutateElement(S,W),De(S,i,{simultaneouslyUpdated:ie}),Ae(S)&&(S.startBinding&&(F.has(S.startBinding.elementId)||ve(S,"start",i)),S.endBinding&&(F.has(S.endBinding.elementId)||ve(S,"end",i)));let ht=V(S,t);ht&&z&&(i.mutateElement(ht,{fontSize:z,angle:q(S)?void 0:xe}),Cn(S,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as ot,pointOnLineSegment as iu,pointRotateRads as lr}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as ta}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as Ks}from"@excalidraw/common";import{pointFrom as Qc,pointRotateRads as dg}from"@excalidraw/math";var Jc={mouse:8,pen:16,touch:28},cg=16,tu={e:!0,s:!0,n:!0,w:!0},DA={e:!0,s:!0,n:!0,w:!0},BA={e:!0,s:!0,n:!0,w:!0,rotation:!0},eu={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},qs={e:!0,s:!0,n:!0,w:!0},Vt=(e,t,n,i,o,r,s)=>{let[a,l]=dg(Qc(e+n/2,t+i/2),Qc(o,r),s);return[a-n/2,l-i/2,n,i]},ar=e=>!(e.formFactor==="phone"&&e.userAgent.isMobileDevice),Qs=e=>ar(e)?tu:{},Js=([e,t,n,i,o,r],s,a,l,d={},c=4,u=Ks)=>{let m=Jc[l],p=m/a.value,f=m/a.value,h=m/a.value,E=m/a.value,g=n-e,x=i-t,w=c/a.value,y=(m-u*2)/(2*a.value),b={nw:d.nw?void 0:Vt(e-w-h+y,t-w-E+y,p,f,o,r,s),ne:d.ne?void 0:Vt(n+w-y,t-w-E+y,p,f,o,r,s),sw:d.sw?void 0:Vt(e-w-h+y,i+w-y,p,f,o,r,s),se:d.se?void 0:Vt(n+w-y,i+w-y,p,f,o,r,s),rotation:d.rotation?void 0:Vt(e+g/2-p/2,t-w-E+y-cg/a.value,p,f,o,r,s)},I=5*Jc.mouse/a.value;return Math.abs(g)>I&&(d.n||(b.n=Vt(e+g/2-p/2,t-w-E+y,p,f,o,r,s)),d.s||(b.s=Vt(e+g/2-p/2,i+w-y,p,f,o,r,s))),Math.abs(x)>I&&(d.w||(b.w=Vt(e-w-h+y,t+x/2-f/2,p,f,o,r,s)),d.e||(b.e=Vt(n+w-y,t+x/2-f/2,p,f,o,r,s))),b},nu=(e,t,n,i="mouse",o=tu)=>{if(e.locked||U(e))return{};if(e.type==="freedraw"||q(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=qs:s[0]>0&&s[1]<0?o=eu:s[0]>0&&s[1]>0?o=qs:s[0]<0&&s[1]>0?o=eu:s[0]<0&&s[1]<0&&(o=qs)}}else Z(e)&&(o={...o,rotation:!0});let r=q(e)?Ks+8:we(e)?0:Ks;return Js($(e,n,!0),e.angle,t,i,o,r,we(e)?0:void 0)},LA=(e,t,n)=>{if(t.selectedLinearElement?.isEditing||t.selectedLinearElement?.isDragging)return!1;if(e.length>1)return!0;let i=e[0];return U(i)?!1:q(i)?i.points.length>2&&!n.userAgent.isMobileDevice:!0};var na=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],ug=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=nu(e,r,t,s,Qs(a));if(l&&na(l,i,o))return"rotation";let c=Object.keys(d).filter(u=>{let m=d[u];return m?na(m,i,o):!1});if(c.length>0)return c[0];if(ar(a)){let[u,m,p,f,h,E]=$(e,t);if(!(q(e)&&e.points.length<=2)){let g=we(e)?0:ta/r.value,x=ta/r.value,w=ou(ot(u-g,m-g),ot(p+g,f+g),ot(h,E),e.angle);for(let[y,b]of Object.entries(w))if(iu(ot(i,o),b,x))return y}}return!1},zA=(e,t,n,i,o,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=ug(d,s,t,n,i,o,r,a);return c?{element:d,transformHandleType:c}:null},null),HA=([e,t,n,i],o,r,s,a,l)=>{let d=Js([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,Qs(l)),c=Object.keys(d).find(u=>{let m=d[u];return m&&na(m,o,r)});if(c)return c;if(ar(l)){let u=(e+n)/2,m=(t+i)/2,p=ta/s.value,f=ou(ot(e-p,t-p),ot(n+p,i+p),ot(u,m),0);for(let[h,E]of Object.entries(f))if(iu(ot(o,r),E,p))return h}return!1},ea=["ns","nesw","ew","nwse"],mg=(e,t)=>{let n=ea.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=ea[(n+i)%ea.length]}return e},_A=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=mg(o,t.angle)),o?`${o}-resize`:""},ou=([e,t],[n,i],o,r)=>{let s=lr(ot(e,t),o,r),a=lr(ot(n,t),o,r),l=lr(ot(e,i),o,r),d=lr(ot(n,i),o,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var jA=(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")||St(t,e).length));P();import{pointFrom as dr}from"@excalidraw/math";import{DEFAULT_FONT_FAMILY as pg,DEFAULT_FONT_SIZE as fg,TEXT_ALIGN as hg,VERTICAL_ALIGN as Eg,getSizeFromPoints as gg,randomId as xg,arrayToMap as wg,assertNever as ia,cloneJSON as su,getFontString as bg,isDevEnv as yg,toBrandedType as Pg,getLineHeight as Ig}from"@excalidraw/common";var cr={width:100,height:0},Sn=100,Sg=(e,t,n)=>{let i=Nn({x:0,y:0,textAlign:hg.CENTER,verticalAlign:Eg.MIDDLE,...t,containerId:e.id,strokeColor:t.strokeColor||e.strokeColor});return Object.assign(e,{boundElements:(e.boundElements||[]).concat({type:"text",id:i.id})}),xo(i,e,n),[e,i]},ru=(e,t,n,i,o)=>{let r,s;if(Object.assign(e,{startBinding:e?.startBinding||null,endBinding:e.endBinding||null}),t){let c=t?.width??Sn,u=t?.height??Sn,m;t.id&&(m=i.getElement(t.id),m||console.error(`No element for start binding with id ${t.id} found`));let p=t.x||e.x-c,f=t.y||e.y-u/2,h=m?m.type:t.type;if(h){if(h==="text"){let E="";m&&m.type==="text"?E=m.text:t.type==="text"&&(E=t.text),E||console.error(`No text found for start binding text element for ${e.id}`),r=Nn({x:p,y:f,type:"text",...m,...t,text:E}),Object.assign(r,{x:t.x||e.x-r.width,y:t.y||e.y-r.height/2})}else switch(h){case"rectangle":case"ellipse":case"diamond":{r=Rn({x:p,y:f,width:c,height:u,...m,...t,type:h});break}default:ia(e,`Unhandled element start type "${t.type}"`,!0)}It(e,r,"orbit","start",o)}}if(n){let c=n?.height??Sn,u=n?.width??Sn,m;n.id&&(m=i.getElement(n.id),m||console.error(`No element for end binding with id ${n.id} found`));let p=n.x||e.x+e.width,f=n.y||e.y-c/2,h=m?m.type:n.type;if(h){if(h==="text"){let E="";m&&m.type==="text"?E=m.text:n.type==="text"&&(E=n.text),E||console.error(`No text found for end binding text element for ${e.id}`),s=Nn({x:p,y:f,type:"text",...m,...n,text:E}),Object.assign(s,{y:n.y||e.y-s.height/2})}else switch(h){case"rectangle":case"ellipse":case"diamond":{s=Rn({x:p,y:f,width:u,height:c,...m,...n,type:h});break}default:ia(e,`Unhandled element end type "${h}"`,!0)}It(e,s,"orbit","end",o)}}if(e.points.length<2)return{linearElement:e,startBoundElement:r,endBoundElement:s};let a=e.points.length-1,l=.5,d=su(e.points);return e.points[a][0]>e.points[a-1][0]&&(d[0][0]=l,d[a][0]-=l),e.points[a][0]<e.points[a-1][0]&&(d[0][0]=-l,d[a][0]+=l),e.points[a][1]>e.points[a-1][1]&&(d[0][1]=l,d[a][1]-=l),e.points[a][1]<e.points[a-1][1]&&(d[0][1]=-l,d[a][1]+=l),Object.assign(e,C.getNormalizeElementPointsAndCoords({...e,points:d})),{linearElement:e,startBoundElement:r,endBoundElement:s}},oa=class{excalidrawElements=new Map;add=t=>{t&&this.excalidrawElements.set(t.id,t)};getElements=()=>ks(Array.from(this.excalidrawElements.values()));getElementsMap=()=>Pg(wg(this.getElements()));getElement=t=>this.excalidrawElements.get(t)},rM=(e,t)=>{if(!e)return[];let n=su(e),i=new oa,o=new Map,r=new Map;for(let l of n){let d,c=l.id;switch(t?.regenerateIds!==!1&&Object.assign(l,{id:xg()}),l.type){case"rectangle":case"ellipse":case"diamond":{let m=l?.label?.text&&l.width===void 0?0:l?.width||Sn,p=l?.label?.text&&l.height===void 0?0:l?.height||Sn;d=Rn({...l,width:m,height:p});break}case"line":{let m=l.width||cr.width,p=l.height||cr.height;d=Sc({width:m,height:p,points:[dr(0,0),dr(m,p)],...l});break}case"arrow":{let m=l.width||cr.width,p=l.height||cr.height;d=er({width:m,height:p,endArrowhead:"arrow",points:[dr(0,0),dr(m,p)],...l,type:"arrow"}),Object.assign(d,gg(d.points));break}case"text":{let m=l?.fontFamily||pg,p=l?.fontSize||fg,f=l?.lineHeight||Ig(m),h=l.text??"",E=xi(h),g=Ve(E,bg({fontFamily:m,fontSize:p}),f);d=Nn({width:g.width,height:g.height,fontFamily:m,fontSize:p,...l});break}case"image":{d=Ac({width:l?.width||Sn,height:l?.height||Sn,...l});break}case"frame":{d=yc({x:0,y:0,...l});break}case"magicframe":{d=Pc({x:0,y:0,...l});break}case"freedraw":case"iframe":case"embeddable":{d=l;break}default:d=l,ia(l,`Unhandled element type "${l.type}"`,!0)}i.getElement(d.id)?console.error(`Duplicate id found for ${d.id}`):(i.add(d),o.set(d.id,l),c&&r.set(c,d.id))}let s=i.getElementsMap(),a=new ei(s);for(let[l,d]of o){let c=i.getElement(l);switch(d.type){case"rectangle":case"ellipse":case"diamond":case"arrow":{if(d.label?.text){let[u,m]=Sg(c,d?.label,a);if(i.add(u),i.add(m),H(u)){let p=d.type==="arrow"?d?.start:void 0,f=d.type==="arrow"?d?.end:void 0;if(p&&p.id){let x=r.get(p.id);x&&Object.assign(p,{id:x})}if(f&&f.id){let x=r.get(f.id);x&&Object.assign(f,{id:x})}let{linearElement:h,startBoundElement:E,endBoundElement:g}=ru(u,p,f,i,a);u=h,i.add(h),i.add(E),i.add(g)}}else switch(d.type){case"arrow":{let{start:u,end:m}=d;if(u&&u.id){let E=r.get(u.id);Object.assign(u,{id:E})}if(m&&m.id){let E=r.get(m.id);Object.assign(m,{id:E})}let{linearElement:p,startBoundElement:f,endBoundElement:h}=ru(c,u,m,i,a);i.add(p),i.add(f),i.add(h);break}}break}}}for(let[l,d]of o){if(d.type!=="frame"&&d.type!=="magicframe")continue;let c=i.getElement(l);if(!c)throw new Error(`Excalidraw element with id ${l} doesn't exist`);let u=[];d.children.forEach(b=>{let I=r.get(b);if(!I)throw new Error(`Element with ${b} wasn't mapped correctly`);let A=i.getElement(I);if(!A)throw new Error(`Frame element with id ${I} doesn't exist`);Object.assign(A,{frameId:c.id}),A?.boundElements?.forEach(T=>{let M=i.getElement(T.id);if(!M)throw new Error(`Bound element with id ${T.id} doesn't exist`);Object.assign(M,{frameId:c.id}),u.push(M)}),u.push(A)});let[m,p,f,h]=ke(u),E=10;m=m-E,p=p-E,f=f+E,h=h+E;let g=c?.x||m,x=c?.y||p,w=c?.width||f-m,y=c?.height||h-p;Object.assign(c,{x:g,y:x,width:w,height:y}),yg()&&d.children.length&&(c?.x||c?.y||c?.width||c?.height)&&console.info("User provided frame attributes are being considered, if you find this inaccurate, please remove any of the attributes - x, y, width and height so frame coordinates and dimensions are calculated automatically")}return i.getElements()};P();var cM=({app:e,event:t})=>{let n=e.state;if(n.selectedLinearElement&&e.lastPointerMoveCoords){if(n.selectedLinearElement.draggedFocusPointBinding)return Vc(n.selectedLinearElement,e.scene.getNonDeletedElementsMap(),e.lastPointerMoveCoords,e.scene,n,e.getEffectiveGridSize(),t.altKey),!0;if(n.selectedLinearElement.hoverPointIndex!==null&&e.lastPointerMoveEvent&&n.selectedLinearElement.initialState.lastClickedPoint>=0&&n.selectedLinearElement.isDragging)return C.handlePointDragging(e.lastPointerMoveEvent,e,e.lastPointerMoveCoords.x,e.lastPointerMoveCoords.y,n.selectedLinearElement),!0}return!1};P();var Ag=e=>{switch(e){case void 0:case null:return null;case"dot":return"circle";case"crowfoot_one":return"cardinality_one";case"crowfoot_many":return"cardinality_many";case"crowfoot_one_or_many":return"cardinality_one_or_many";default:return e}},pM=e=>{let t=Ag(e);return t===null?null:t};var xM=e=>e.reduce((t,n)=>t+n.version,0),Zd=e=>{let t=5381;for(let n of Mg(e))t=(t<<5)+t+n.versionNonce;return t>>>0},qd=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},wM=e=>e.filter(t=>!t.isDeleted&&!_d(t)),bM=e=>e.filter(t=>!t.isDeleted),yM=e=>!e.isDeleted;export{xn as AppStateDelta,Gp as BASE_ARROW_MIN_LENGTH,Fl as BASE_BINDING_GAP,Gn as BASE_BINDING_GAP_ELBOW,ee as BASE_PADDING,pn as BindableElement,mn as BoundElement,Ye as CaptureUpdateAction,d1 as DEFAULT_LINK_SIZE,tu as DEFAULT_OMIT_SIDES,Y as Delta,Bs as DurableIncrement,Ss as ElementBounds,wn as ElementsDelta,Ls as EphemeralIncrement,vi as FOCUS_POINT_SIZE,Oc as FlowChartCreator,Gc as FlowChartNavigator,be as HEADING_DOWN,_e as HEADING_LEFT,fe as HEADING_RIGHT,qe as HEADING_UP,gh as INVISIBLY_SMALL_ELEMENT_SIZE,Gs as InvalidFractionalIndexError,C as LinearElementEditor,Ie as MINIMAL_CROP_SIZE,BA as OMIT_SIDES_FOR_FRAME,DA as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,ei as Scene,Ke as ShapeCache,jd as Store,Ri as StoreChange,Cs as StoreDelta,Vo as StoreIncrement,bn as StoreSnapshot,nt as aabbForElement,Tf as addElementsToFrame,XE as addNewNodes,s0 as addToGroup,fP as alignElements,Hp as avoidRectangularCorner,It as bindBindingElement,Ed as bindElementsToFramesAfterDuplication,Op as bindOrUnbindBindingElement,My as bindOrUnbindBindingElements,ts as bindPointToSnapToElementOutline,Hl as bindingProperties,Bl as bumpVersion,Up as calculateFixedPointForElbowArrowBinding,Xn as calculateFixedPointForNonElbowArrowBinding,Lw as canApplyRoundnessTypeToElement,Wa as canBecomePolygon,Ad as canChangeRoundness,xE as canCreateLinkFromElements,b1 as canHaveArrowheads,ar as canResizeFromSides,Wn as charWidth,pe as compareHeading,wi as computeBoundTextPosition,Rr as computeContainerDimensionForBoundText,sb as containsCJK,rM as convertToExcalidrawElements,aS as createPlaceholderEmbeddableLabel,Hs as createSrcDoc,Pw as cropElement,tn as deconstructDiamondElement,uo as deconstructLinearOrFreeDrawElement,en as deconstructRectanguloidElement,Ds as deepCopyElement,RI as defaultGetElementLinkFromSelection,Jw as detectLineHeight,rn as distanceToElement,bI as distributeElements,Pi as doBoundsIntersect,CI as dragNewElement,BI as dragSelectedElements,Th as duplicateElement,vP as duplicateElements,r0 as editGroupForSelectedElement,re as elementCenterPoint,fn as elementOverlapsWithFrame,Ci as elementWithCanvasCache,En as elementsAreInFrameBounds,ud as elementsAreInSameGroup,dS as embeddableURLValidator,fd as excludeElementsInFramesFromSelection,U0 as filterElementsEligibleAsFrameChildren,vy as fixBindingsAfterDeletion,zl as fixDuplicatedBindingsAfterDuplication,jr as flipHeading,V0 as frameAndChildrenSelectedTogether,qa as generateLinearCollisionShape,We as generateRoughOptions,yo as getAllHoveredElementAtPoint,tl as getApproxMinLineHeight,el as getApproxMinLineWidth,_l as getArrowLocalFixedPoints,uh as getArrowheadAngle,pM as getArrowheadForPicker,Fe as getArrowheadPoints,ch as getArrowheadSize,Be as getBindingGap,Dy as getBindingSideMidPoint,ss as getBindingStrategyForDraggingBindingElementEndpoints,V as getBoundTextElement,Rt as getBoundTextElementId,xb as getBoundTextElementPosition,bi as getBoundTextMaxHeight,dt as getBoundTextMaxWidth,As as getBoundsFromPoints,bt as getCenterForBounds,Q1 as getClosestElementBounds,jt as getCommonBoundingBox,ke as getCommonBounds,Eb as getContainerCenter,Nr as getContainerCoords,Me as getContainerElement,Wt as getContainingFrame,Gt as getCornerRadius,Po as getCubicBezierCurveBound,_A as getCursorForResizingElement,Cf as getDefaultFrameName,Cw as getDefaultRoundnessTypeForElement,Za as getDiamondBaseCorners,Un as getDiamondPoints,LI as getDragOffsetXY,K1 as getDraggedElementsBounds,$ as getElementAbsoluteCoords,he as getElementBounds,hs as getElementLineSegments,ds as getElementPointsCoords,Cd as getElementShape,zA as getElementWithTransformHandleType,gd as getElementsCompletelyInFrame,Oe as getElementsInGroup,_0 as getElementsInNewFrame,H0 as getElementsInResizingFrame,O0 as getElementsIntersectingFrame,$0 as getElementsOverlappingFrame,ps as getElementsWithinSelection,sS as getEmbedLink,Iw as getFlipAdjustedCropPosition,hn as getFrameChildren,Af as getFrameLikeElements,X0 as getFrameLikeTitle,m1 as getFreedrawOutlineAsSegments,eh as getFreedrawOutlinePoints,Ne as getGlobalFixedPointForBindableElement,Wp as getGlobalFixedPoints,Dl as getHeadingForElbowArrowSnap,Nt as getHoveredElementForBinding,gl as getHoveredElementForFocusPoint,tA as getInitializedImageElements,ho as getLineHeightInPx,on as getLineWidth,Gw as getLinearElementSubType,IS as getLinkDirectionFromKey,NI as getLinkIdAndTypeFromSelection,Ql as getLockedLinearCursorAlignSize,Im as getMaxCharWidth,l0 as getMaximumGroups,tb as getMinCharWidth,Bi as getMinMaxXYFromCurvePathOps,fo as getMinTextElementWidth,pd as getNewGroupIdsForDuplication,bM as getNonDeletedElements,cd as getNonDeletedGroupIds,lP as getNormalizedDimensions,Kn as getObservedAppState,Qs as getOmitSidesForEditorInterface,Vw as getOriginalContainerHeightFromCache,Ms as getPerfectElementSize,Ys as getPredecessors,q1 as getRectangleBoxAbsoluteCoords,Wf as getRenderOpacity,PA as getResizeArrowDirection,yA as getResizeOffsetXY,Jt as getResizedElementAbsoluteCoords,z0 as getRootElements,xM as getSceneVersion,St as getSelectedElements,zo as getSelectedElementsByGroup,ms as getSelectedGroupForElement,bf as getSelectedGroupIdForElement,xf as getSelectedGroupIds,y0 as getSelectionStateForElements,Em as getSnapOutlineMidPoint,b0 as getTargetElements,Df as getTargetFrame,gb as getTextElementAngle,Pb as getTextFromElements,Pm as getTextHeight,nl as getTextWidth,HA as getTransformHandleTypeFromCoords,nu as getTransformHandles,Js as getTransformHandlesFromCoords,Fa as getUncroppedImageElement,Sr as getUncroppedWidthAndHeight,x0 as getVisibleAndNonSelectedElements,wM as getVisibleElements,J1 as getVisibleSceneBounds,N0 as groupByFrameLikes,F0 as groupsAreAtLeastIntersectingTheFrame,R0 as groupsAreCompletelyOutOfFrame,Cn as handleBindTextResize,Vc as handleFocusPointDrag,ZS as handleFocusPointHover,$S as handleFocusPointPointerDown,VS as handleFocusPointPointerUp,h1 as hasBackground,gt as hasBoundTextElement,LA as hasBoundingBox,E1 as hasStrokeColor,x1 as hasStrokeStyle,g1 as hasStrokeWidth,Zd as hashElementsVersion,qd as hashString,He as headingForPoint,Ii as headingForPointFromElement,ct as headingForPointIsHorizontal,Ue as headingIsHorizontal,Vb as headingIsVertical,np as hitElementBoundText,tp as hitElementBoundingBox,Ub as hitElementBoundingBoxOnly,xt as hitElementItself,sn as intersectElementWithLineSegment,Bw as isArrowBoundToElement,H as isArrowElement,de as isBindableElement,Wr as isBindableElementInsideOtherBindable,Ae as isBindingElement,rm as isBindingElementType,Pt as isBindingEnabled,ce as isBoundToContainer,k0 as isCursorInFrame,im as isCurvedArrow,U as isElbowArrow,aP as isElementCompletelyInViewport,Es as isElementContainingFrame,wd as isElementInFrame,wf as isElementInGroup,hd as isElementInViewport,Vn as isElementIntersectingFrame,zI as isElementLink,Na as isEmbeddableElement,Dw as isExcalidrawElement,Yp as isFixedPoint,Ar as isFlowchartNodeElement,ir as isFocusPointVisible,co as isFrameElement,Z as isFrameLikeElement,Se as isFreeDrawElement,tm as isFreeDrawElementType,JE as isHTMLSVGElement,ao as isIframeElement,lo as isIframeLikeElement,we as isImageElement,md as isInGroup,vn as isInitializedImageElement,_d as isInvisiblySmallElement,Lt as isLineElement,q as isLinearElement,om as isLinearElementType,za as isMagicFrameElement,Qw as isMeasureTextSupported,SS as isNodeInFlowchart,yM as isNonDeletedElement,Bn as isPathALoop,Ot as isPointInElement,hi as isRectangularElement,Ha as isRectanguloidElement,gf as isSelectedViaGroup,nm as isSharpArrow,vw as isSimpleArrow,w0 as isSomeElementSelected,sm as isTextBindableContainer,Q as isTextElement,_a as isUsingAdaptiveRadius,Ua as isUsingProportionalRadius,Ow as isValidPolygon,yb as isValidTextContainer,QE as loadHTMLImageElement,us as makeNextSelectedElementIds,lt as maxBindingDistance_simple,cM as maybeHandleArrowPointlikeDrag,lS as maybeParseEmbedSrc,Zs as measureFontSizeFromWidth,Ve as measureText,FS as moveAllLeft,RS as moveAllRight,Uc as moveArrowAboveBindable,OS as moveOneLeft,kS as moveOneRight,ye as mutateElement,er as newArrowElement,Rn as newElement,Le as newElementWith,qI as newEmbeddableElement,yc as newFrameElement,JI as newFreeDrawElement,KI as newIframeElement,Ac as newImageElement,Sc as newLinearElement,Pc as newMagicFrameElement,Nn as newTextElement,Ag as normalizeArrowhead,Ud as normalizeElementOrder,nn as normalizeFixedPoint,nA as normalizeSVG,xi as normalizeText,Ho as omitGroupsContainingFrameLikes,Mf as omitPartialGroups,ic as orderByFractionalIndex,gi as originalContainerCache,HI as parseElementLinkFromURL,Bm as parseTokens,an as pointInsideBounds,aA as positionElementsOnGrid,Lr as projectFixedPointOntoDiagonal,xo as redrawTextBoundingBox,QI as refreshTextDimensions,vf as removeAllElementsFromFrame,xd as removeElementsFromFrame,a0 as removeFromSelectedGroups,u1 as renderElement,c1 as renderSelectionElement,W0 as replaceAllElementsInFrame,Kc as rescalePointsInElement,Qa as resetOriginalContainerCache,lg as resizeMultipleElements,rg as resizeSingleElement,ng as resizeSingleTextElement,ug as resizeTest,Ef as selectGroup,ld as selectGroupsForSelectedElements,dd as selectGroupsFromGivenElements,eb as setCustomTextMetricsProvider,wb as shouldAllowVerticalAlign,j0 as shouldApplyFrameClip,bo as shouldTestInside,jA as showSelectedShapeActions,as as snapToMid,bb as suppportsHorizontalAlign,ks as syncInvalidIndices,Vd as syncInvalidIndicesImmutable,zi as syncMovedIndices,Kl as toggleLinePolygonState,w1 as toolIsArrow,bA as transformElements,ve as unbindBindingElement,Ty as updateBindings,De as updateBoundElements,ut as updateBoundPoint,jn as updateElbowArrowPoints,Y0 as updateFrameMembershipOfSelectedElements,eA as updateImageCache,Ka as updateOriginalContainerCache,vl as validateElbowPoints,Fh as validateFractionalIndices,zt as vectorToHeading,Ft as wrapText};