@excalidraw/element 0.18.0-dda3affcb-8fc71066d → 0.18.0-ec07091

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 (61) hide show
  1. package/dist/dev/index.js +846 -512
  2. package/dist/dev/index.js.map +4 -4
  3. package/dist/prod/index.js +14 -14
  4. package/dist/types/common/src/constants.d.ts +20 -4
  5. package/dist/types/common/src/utils.d.ts +3 -0
  6. package/dist/types/element/src/bounds.d.ts +1 -1
  7. package/dist/types/element/src/delta.d.ts +4 -5
  8. package/dist/types/element/src/index.d.ts +1 -0
  9. package/dist/types/element/src/positionElementsOnGrid.d.ts +2 -0
  10. package/dist/types/element/src/renderElement.d.ts +4 -1
  11. package/dist/types/element/src/store.d.ts +5 -0
  12. package/dist/types/element/src/textElement.d.ts +1 -1
  13. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +6 -3
  14. package/dist/types/excalidraw/actions/actionBoundText.d.ts +4 -2
  15. package/dist/types/excalidraw/actions/actionCanvas.d.ts +29 -15
  16. package/dist/types/excalidraw/actions/actionClipboard.d.ts +12 -6
  17. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +2 -1
  18. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +6 -3
  19. package/dist/types/excalidraw/actions/actionElementLink.d.ts +2 -1
  20. package/dist/types/excalidraw/actions/actionElementLock.d.ts +4 -2
  21. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +2 -1
  22. package/dist/types/excalidraw/actions/actionExport.d.ts +18 -9
  23. package/dist/types/excalidraw/actions/actionFinalize.d.ts +4 -2
  24. package/dist/types/excalidraw/actions/actionFrame.d.ts +8 -4
  25. package/dist/types/excalidraw/actions/actionGroup.d.ts +4 -2
  26. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +3 -2
  27. package/dist/types/excalidraw/actions/actionLink.d.ts +2 -1
  28. package/dist/types/excalidraw/actions/actionMenu.d.ts +6 -3
  29. package/dist/types/excalidraw/actions/actionNavigate.d.ts +4 -2
  30. package/dist/types/excalidraw/actions/actionProperties.d.ts +48 -24
  31. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +2 -1
  32. package/dist/types/excalidraw/actions/actionStyles.d.ts +2 -1
  33. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +2 -1
  34. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +2 -1
  35. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +2 -1
  36. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +2 -1
  37. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +2 -1
  38. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +2 -1
  39. package/dist/types/excalidraw/actions/index.d.ts +1 -1
  40. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  41. package/dist/types/excalidraw/appState.d.ts +1 -0
  42. package/dist/types/excalidraw/clipboard.d.ts +64 -1
  43. package/dist/types/excalidraw/components/Actions.d.ts +8 -1
  44. package/dist/types/excalidraw/components/App.d.ts +13 -11
  45. package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +2 -1
  46. package/dist/types/excalidraw/components/CommandPalette/CommandPalette.d.ts +1 -0
  47. package/dist/types/excalidraw/components/FontPicker/FontPicker.d.ts +2 -1
  48. package/dist/types/excalidraw/components/FontPicker/FontPickerTrigger.d.ts +2 -1
  49. package/dist/types/excalidraw/components/InlineIcon.d.ts +3 -1
  50. package/dist/types/excalidraw/components/LibraryMenuSection.d.ts +1 -1
  51. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -0
  52. package/dist/types/excalidraw/components/TextField.d.ts +1 -0
  53. package/dist/types/excalidraw/components/icons.d.ts +6 -0
  54. package/dist/types/excalidraw/components/shapes.d.ts +129 -1
  55. package/dist/types/excalidraw/data/blob.d.ts +3 -7
  56. package/dist/types/excalidraw/data/types.d.ts +4 -1
  57. package/dist/types/excalidraw/hooks/useLibraryItemSvg.d.ts +1 -1
  58. package/dist/types/excalidraw/hooks/useTextEditorFocus.d.ts +14 -0
  59. package/dist/types/excalidraw/types.d.ts +6 -3
  60. package/dist/types/math/src/segment.d.ts +1 -0
  61. package/package.json +3 -3
@@ -1,27 +1,27 @@
1
- var cd=Object.create;var bs=Object.defineProperty;var dd=Object.getOwnPropertyDescriptor;var ud=Object.getOwnPropertyNames;var pd=Object.getPrototypeOf,md=Object.prototype.hasOwnProperty;var fd=(e,t)=>()=>(e&&(t=e(e=0)),t);var hd=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ed=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ud(t))!md.call(e,o)&&o!==n&&bs(e,o,{get:()=>t[o],enumerable:!(i=dd(t,o))||i.enumerable});return e};var gd=(e,t,n)=>(n=e!=null?cd(pd(e)):{},Ed(t||!e||!e.__esModule?bs(n,"default",{value:e,enumerable:!0}):n,e));var A,P=fd(()=>{A={PROD:!0}});var xc=hd((L1,gc)=>{P();var Ec="Expected a function",fc=NaN,zf="[object Symbol]",Hf=/^\s+|\s+$/g,_f=/^[-+]0x[0-9a-f]+$/i,Yf=/^0b[01]+$/i,Uf=/^0o[0-7]+$/i,Xf=parseInt,Wf=typeof global=="object"&&global&&global.Object===Object&&global,jf=typeof self=="object"&&self&&self.Object===Object&&self,Vf=Wf||jf||Function("return this")(),$f=Object.prototype,Zf=$f.toString,qf=Math.max,Kf=Math.min,ts=function(){return Vf.Date.now()};function Qf(e,t,n){var i,o,r,s,a,l,c=0,d=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(Ec);t=hc(t)||0,Po(n)&&(d=!!n.leading,u="maxWait"in n,r=u?qf(hc(n.maxWait)||0,t):r,p="trailing"in n?!!n.trailing:p);function m(I){var M=i,D=o;return i=o=void 0,c=I,s=e.apply(D,M),s}function f(I){return c=I,a=setTimeout(g,t),d?m(I):s}function E(I){var M=I-l,D=I-c,T=t-M;return u?Kf(T,r-D):T}function h(I){var M=I-l,D=I-c;return l===void 0||M>=t||M<0||u&&D>=r}function g(){var I=ts();if(h(I))return x(I);a=setTimeout(g,E(I))}function x(I){return a=void 0,p&&i?m(I):(i=o=void 0,s)}function y(){a!==void 0&&clearTimeout(a),c=0,i=l=o=a=void 0}function b(){return a===void 0?s:x(ts())}function w(){var I=ts(),M=h(I);if(i=arguments,o=this,l=I,M){if(a===void 0)return f(l);if(u)return a=setTimeout(g,t),m(l)}return a===void 0&&(a=setTimeout(g,t)),s}return w.cancel=y,w.flush=b,w}function Jf(e,t,n){var i=!0,o=!0;if(typeof e!="function")throw new TypeError(Ec);return Po(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),Qf(e,t,{leading:i,maxWait:t,trailing:o})}function Po(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function eh(e){return!!e&&typeof e=="object"}function th(e){return typeof e=="symbol"||eh(e)&&Zf.call(e)==zf}function hc(e){if(typeof e=="number")return e;if(th(e))return fc;if(Po(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Po(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Hf,"");var n=Yf.test(e);return n||Uf.test(e)?Xf(e.slice(2),n?2:8):_f.test(e)?fc:+e}gc.exports=Jf});P();import{toIterable as fE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as Bt,viewportCoordsToSceneCoords as xo}from"@excalidraw/common";import{normalizeRadians as Zl,radiansBetweenAngles as ff,radiansDifference as hf}from"@excalidraw/math";import{pointsEqual as Ef}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function Ro(e,t,n){if(e&&e.length){let[i,o]=t,r=Math.PI/180*n,s=Math.cos(r),a=Math.sin(r);for(let l of e){let[c,d]=l;l[0]=(c-i)*s-(d-o)*a+i,l[1]=(c-i)*a+(d-o)*s+o}}}function wd(e,t,n){let i=[];e.forEach(o=>i.push(...o)),Ro(i,t,n)}function yd(e,t){return e[0]===t[0]&&e[1]===t[1]}function Ps(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 c of s)Ro(c,a,o);let l=bd(s,r,i);if(o){for(let c of s)Ro(c,a,-o);wd(l,a,-o)}return l}function bd(e,t,n){let i=[];for(let c of e){let d=[...c];yd(d[0],d[d.length-1])||d.push([d[0][0],d[0][1]]),d.length>2&&i.push(d)}let o=[];t=Math.max(t,.1);let r=[];for(let c of i)for(let d=0;d<c.length-1;d++){let u=c[d],p=c[d+1];if(u[1]!==p[1]){let m=Math.min(u[1],p[1]);r.push({ymin:m,ymax:Math.max(u[1],p[1]),x:m===u[1]?u[0]:p[0],islope:(p[0]-u[0])/(p[1]-u[1])})}}if(r.sort((c,d)=>c.ymin<d.ymin?-1:c.ymin>d.ymin?1:c.x<d.x?-1:c.x>d.x?1:c.ymax===d.ymax?0:(c.ymax-d.ymax)/Math.abs(c.ymax-d.ymax)),!r.length)return o;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let c=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)c=u;r.splice(0,c+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(c=>!(c.edge.ymax<=a)),s.sort((c,d)=>c.edge.x===d.edge.x?0:(c.edge.x-d.edge.x)/Math.abs(c.edge.x-d.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let c=0;c<s.length;c=c+2){let d=c+1;if(d>=s.length)break;let u=s[c].edge,p=s[d].edge;o.push([[Math.round(u.x),a],[Math.round(p.x),a]])}a+=n,s.forEach(c=>{c.edge.x=c.edge.x+n*c.edge.islope}),l++}return o}function rt(e,t){var n;let i=t.hachureAngle+90,o=t.hachureGap;o<0&&(o=t.strokeWidth*4),o=Math.max(o,.1);let r=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(r=o),Ps(e,o,i,r||1)}var Rt=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let i=rt(t,n);return{type:"fillSketch",ops:this.renderLines(i,n)}}renderLines(t,n){let i=[];for(let o of t)i.push(...this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],n));return i}};P();P();function 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 fi=class extends Rt{fillPolygons(t,n){let i=n.hachureGap;i<0&&(i=n.strokeWidth*4),i=Math.max(i,.1);let o=Object.assign({},n,{hachureGap:i}),r=rt(t,o),s=Math.PI/180*n.hachureAngle,a=[],l=i*.5*Math.cos(s),c=i*.5*Math.sin(s);for(let[u,p]of r)kt([u,p])&&a.push([[u[0]-l,u[1]+c],[...p]],[[u[0]+l,u[1]-c],[...p]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var hi=class extends Rt{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 Ei=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let i=rt(t,n);return this.dotsOnLines(i,n)}dotsOnLines(t,n){let i=[],o=n.hachureGap;o<0&&(o=n.strokeWidth*4),o=Math.max(o,.1);let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let s=o/4;for(let a of t){let l=kt(a),c=l/o,d=Math.ceil(c)-1,u=l-d*o,p=(a[0][0]+a[1][0])/2-o/4,m=Math.min(a[0][1],a[1][1]);for(let f=0;f<d;f++){let E=m+u+f*o,h=p-s+Math.random()*2*s,g=E-s+Math.random()*2*s,x=this.helper.ellipse(h,g,r,r,n);i.push(...x.ops)}}return{type:"fillSketch",ops:i}}};P();var gi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=rt(t,n);return{type:"fillSketch",ops:this.dashedLine(i,n)}}dashedLine(t,n){let i=n.dashOffset<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashOffset,o=n.dashGap<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashGap,r=[];return t.forEach(s=>{let a=kt(s),l=Math.floor(a/(i+o)),c=(a+o-l*(i+o))/2,d=s[0],u=s[1];d[0]>u[0]&&(d=s[1],u=s[0]);let p=Math.atan((u[1]-d[1])/(u[0]-d[0]));for(let m=0;m<l;m++){let f=m*(i+o),E=f+i,h=[d[0]+f*Math.cos(p)+c*Math.cos(p),d[1]+f*Math.sin(p)+c*Math.sin(p)],g=[d[0]+E*Math.cos(p)+c*Math.cos(p),d[1]+E*Math.sin(p)+c*Math.sin(p)];r.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],n))}}),r}};P();var xi=class{constructor(t){this.helper=t}fillPolygons(t,n){let i=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,o=n.zigzagOffset<0?i:n.zigzagOffset;n=Object.assign({},n,{hachureGap:i+o});let r=rt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,o,n)}}zigzagLines(t,n,i){let o=[];return t.forEach(r=>{let s=kt(r),a=Math.round(s/(2*n)),l=r[0],c=r[1];l[0]>c[0]&&(l=r[1],c=r[0]);let d=Math.atan((c[1]-l[1])/(c[0]-l[0]));for(let u=0;u<a;u++){let p=u*2*n,m=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),E=[l[0]+p*Math.cos(d),l[1]+p*Math.sin(d)],h=[l[0]+m*Math.cos(d),l[1]+m*Math.sin(d)],g=[E[0]+f*Math.cos(d+Math.PI/4),E[1]+f*Math.sin(d+Math.PI/4)];o.push(...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],i),...this.helper.doubleLineOps(g[0],g[1],h[0],h[1],i))}}),o}};var ve={};function Is(e,t){let n=e.fillStyle||"hachure";if(!ve[n])switch(n){case"zigzag":ve[n]||(ve[n]=new fi(t));break;case"cross-hatch":ve[n]||(ve[n]=new hi(t));break;case"dots":ve[n]||(ve[n]=new Ei(t));break;case"dashed":ve[n]||(ve[n]=new gi(t));break;case"zigzag-line":ve[n]||(ve[n]=new xi(t));break;case"hachure":default:n="hachure",ve[n]||(ve[n]=new Rt(t));break}return ve[n]}P();function Ss(){return Math.floor(Math.random()*2**31)}var wi=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 yi={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 Pd(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 ko(e,t){return e.type===t}function yn(e){let t=[],n=Pd(e),i="BOD",o=0,r=n[o];for(;!ko(r,2);){let s=0,a=[];if(i==="BOD")if(r.text==="M"||r.text==="m")o++,s=yi[r.text],i=r.text;else return yn("M0,0"+e);else ko(r,1)?s=yi[i]:(o++,s=yi[r.text],i=r.text);if(o+s<n.length){for(let l=o;l<o+s;l++){let c=n[l];if(ko(c,1))a[a.length]=+c.text;else throw new Error("Param not a number: "+i+","+c.text)}if(typeof yi[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 Hn(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((c,d)=>d%2?c+n:c+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((c,d)=>d%2?c+n:c+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((c,d)=>d%2?c+n:c+t);r.push({key:"S",data:l}),t=l[2],n=l[3];break}case"T":r.push({key:"T",data:[...a]}),t=a[0],n=a[1];break;case"t":t+=a[0],n+=a[1],r.push({key:"T",data:[t,n]});break;case"Z":case"z":r.push({key:"Z",data:[]}),t=i,n=o;break}return r}P();function Yn(e){let t=[],n="",i=0,o=0,r=0,s=0,a=0,l=0;for(let{key:c,data:d}of e){switch(c){case"M":t.push({key:"M",data:[...d]}),[i,o]=d,[r,s]=d;break;case"C":t.push({key:"C",data:[...d]}),i=d[4],o=d[5],a=d[2],l=d[3];break;case"L":t.push({key:"L",data:[...d]}),[i,o]=d;break;case"H":i=d[0],t.push({key:"L",data:[i,o]});break;case"V":o=d[0],t.push({key:"L",data:[i,o]});break;case"S":{let u=0,p=0;n==="C"||n==="S"?(u=i+(i-a),p=o+(o-l)):(u=i,p=o),t.push({key:"C",data:[u,p,...d]}),a=d[0],l=d[1],i=d[2],o=d[3];break}case"T":{let[u,p]=d,m=0,f=0;n==="Q"||n==="T"?(m=i+(i-a),f=o+(o-l)):(m=i,f=o);let E=i+2*(m-i)/3,h=o+2*(f-o)/3,g=u+2*(m-u)/3,x=p+2*(f-p)/3;t.push({key:"C",data:[E,h,g,x,u,p]}),a=m,l=f,i=u,o=p;break}case"Q":{let[u,p,m,f]=d,E=i+2*(u-i)/3,h=o+2*(p-o)/3,g=m+2*(u-m)/3,x=f+2*(p-f)/3;t.push({key:"C",data:[E,h,g,x,m,f]}),a=u,l=p,i=m,o=f;break}case"A":{let u=Math.abs(d[0]),p=Math.abs(d[1]),m=d[2],f=d[3],E=d[4],h=d[5],g=d[6];u===0||p===0?(t.push({key:"C",data:[i,o,h,g,h,g]}),i=h,o=g):(i!==h||o!==g)&&(Ms(i,o,h,g,u,p,m,f,E).forEach(function(y){t.push({key:"C",data:y})}),i=h,o=g);break}case"Z":t.push({key:"Z",data:[]}),i=r,o=s;break}n=c}return t}function Id(e){return Math.PI*e/180}function _n(e,t,n){let i=e*Math.cos(n)-t*Math.sin(n),o=e*Math.sin(n)+t*Math.cos(n);return[i,o]}function Ms(e,t,n,i,o,r,s,a,l,c){let d=Id(s),u=[],p=0,m=0,f=0,E=0;if(c)[p,m,f,E]=c;else{[e,t]=_n(e,t,-d),[n,i]=_n(n,i,-d);let k=(e-n)/2,L=(t-i)/2,j=k*k/(o*o)+L*L/(r*r);j>1&&(j=Math.sqrt(j),o=j*o,r=j*r);let N=a===l?-1:1,te=o*o,S=r*r,Q=te*S-te*L*L-S*k*k,V=te*L*L+S*k*k,ne=N*Math.sqrt(Math.abs(Q/V));f=ne*o*L/r+(e+n)/2,E=ne*-r*k/o+(t+i)/2,p=Math.asin(parseFloat(((t-E)/r).toFixed(9))),m=Math.asin(parseFloat(((i-E)/r).toFixed(9))),e<f&&(p=Math.PI-p),n<f&&(m=Math.PI-m),p<0&&(p=Math.PI*2+p),m<0&&(m=Math.PI*2+m),l&&p>m&&(p=p-Math.PI*2),!l&&m>p&&(m=m-Math.PI*2)}let h=m-p;if(Math.abs(h)>Math.PI*120/180){let k=m,L=n,j=i;l&&m>p?m=p+Math.PI*120/180*1:m=p+Math.PI*120/180*-1,n=f+o*Math.cos(m),i=E+r*Math.sin(m),u=Ms(n,i,L,j,o,r,s,0,l,[m,k,f,E])}h=m-p;let g=Math.cos(p),x=Math.sin(p),y=Math.cos(m),b=Math.sin(m),w=Math.tan(h/4),I=4/3*o*w,M=4/3*r*w,D=[e,t],T=[e+I*x,t-M*g],F=[n+I*b,i-M*y],C=[n,i];if(T[0]=2*D[0]-T[0],T[1]=2*D[1]-T[1],c)return[T,F,C].concat(u);{u=[T,F,C].concat(u);let k=[];for(let L=0;L<u.length;L+=3){let j=_n(u[L][0],u[L][1],d),N=_n(u[L+1][0],u[L+1][1],d),te=_n(u[L+2][0],u[L+2][1],d);k.push([j[0],j[1],N[0],N[1],te[0],te[1]])}return k}}var Sd={randOffset:Ad,randOffsetWithRange:Dd,ellipse:Td,doubleLineOps:vd};function Fo(e,t,n,i,o){return{type:"path",ops:ht(e,t,n,i,o)}}function Un(e,t,n){let i=(e||[]).length;if(i>2){let o=[];for(let r=0;r<i-1;r++)o.push(...ht(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&o.push(...ht(e[i-1][0],e[i-1][1],e[0][0],e[0][1],n)),{type:"path",ops:o}}else if(i===2)return Fo(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function Md(e,t){return Un(e,!0,t)}function Ls(e,t,n,i,o){let r=[[e,t],[e+n,t],[e+n,t+i],[e,t+i]];return Md(r,o)}function No(e,t){let n=As(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let i=As(e,1.5*(1+t.roughness*.22),Ld(t));n=n.concat(i)}return{type:"path",ops:n}}function Td(e,t,n,i,o){let r=zo(n,i,o);return Ii(e,t,o,r).opset}function zo(e,t,n){let i=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),o=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*i)),r=Math.PI*2/o,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=O(s*l,n),a+=O(a*l,n),{increment:r,rx:s,ry:a}}function Ii(e,t,n,i){let[o,r]=Ds(i.increment,e,t,i.rx,i.ry,1,i.increment*bi(.1,bi(.4,1,n),n),n),s=Pi(o,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=Ds(i.increment,e,t,i.rx,i.ry,1.5,0,n),l=Pi(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Ho(e,t,n,i,o,r,s,a,l){let c=e,d=t,u=Math.abs(n/2),p=Math.abs(i/2);u+=O(u*.01,l),p+=O(p*.01,l);let m=o,f=r;for(;m<0;)m+=Math.PI*2,f+=Math.PI*2;f-m>Math.PI*2&&(m=0,f=Math.PI*2);let E=Math.PI*2/l.curveStepCount,h=Math.min(E/2,(f-m)/2),g=vs(h,c,d,u,p,m,f,1,l);if(!l.disableMultiStroke){let x=vs(h,c,d,u,p,m,f,1.5,l);g.push(...x)}return s&&(a?g.push(...ht(c,d,c+u*Math.cos(m),d+p*Math.sin(m),l),...ht(c,d,c+u*Math.cos(f),d+p*Math.sin(f),l)):g.push({op:"lineTo",data:[c,d]},{op:"lineTo",data:[c+u*Math.cos(m),d+p*Math.sin(m)]})),{type:"path",ops:g}}function _o(e,t){let n=Yn(Hn(yn(e))),i=[],o=[0,0],r=[0,0];for(let{key:s,data:a}of n)switch(s){case"M":{r=[a[0],a[1]],o=[a[0],a[1]];break}case"L":i.push(...ht(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,c,d,u,p,m]=a;i.push(...Cd(l,c,d,u,p,m,r,t)),r=[p,m];break}case"Z":i.push(...ht(r[0],r[1],o[0],o[1],t)),r=[o[0],o[1]];break}return{type:"path",ops:i}}function Si(e,t){let n=[];for(let i of e)if(i.length){let o=t.maxRandomnessOffset||0,r=i.length;if(r>2){n.push({op:"move",data:[i[0][0]+O(o,t),i[0][1]+O(o,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[i[s][0]+O(o,t),i[s][1]+O(o,t)]})}}return{type:"fillPath",ops:n}}function rn(e,t){return Is(t,Sd).fillPolygons(e,t)}function Cs(e,t,n,i,o,r,s){let a=e,l=t,c=Math.abs(n/2),d=Math.abs(i/2);c+=O(c*.01,s),d+=O(d*.01,s);let u=o,p=r;for(;u<0;)u+=Math.PI*2,p+=Math.PI*2;p-u>Math.PI*2&&(u=0,p=Math.PI*2);let m=(p-u)/s.curveStepCount,f=[];for(let E=u;E<=p;E=E+m)f.push([a+c*Math.cos(E),l+d*Math.sin(E)]);return f.push([a+c*Math.cos(p),l+d*Math.sin(p)]),f.push([a,l]),rn([f],s)}function Ad(e,t){return O(e,t)}function Dd(e,t,n){return bi(e,t,n)}function vd(e,t,n,i,o){return ht(e,t,n,i,o,!0)}function Ld(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Bs(e){return e.randomizer||(e.randomizer=new wi(e.seed||0)),e.randomizer.next()}function bi(e,t,n,i=1){return n.roughness*i*(Bs(n)*(t-e)+e)}function O(e,t,n=1){return bi(-e,e,t,n)}function ht(e,t,n,i,o,r=!1){let s=r?o.disableMultiStrokeFill:o.disableMultiStroke,a=Ts(e,t,n,i,o,!0,!1);if(s)return a;let l=Ts(e,t,n,i,o,!0,!0);return a.concat(l)}function Ts(e,t,n,i,o,r,s){let a=Math.pow(e-n,2)+Math.pow(t-i,2),l=Math.sqrt(a),c=1;l<200?c=1:l>500?c=.4:c=-.0016668*l+1.233334;let d=o.maxRandomnessOffset||0;d*d*100>a&&(d=l/10);let u=d/2,p=.2+Bs(o)*.2,m=o.bowing*o.maxRandomnessOffset*(i-t)/200,f=o.bowing*o.maxRandomnessOffset*(e-n)/200;m=O(m,o,c),f=O(f,o,c);let E=[],h=()=>O(u,o,c),g=()=>O(d,o,c),x=o.preserveVertices;return r&&(s?E.push({op:"move",data:[e+(x?0:h()),t+(x?0:h())]}):E.push({op:"move",data:[e+(x?0:O(d,o,c)),t+(x?0:O(d,o,c))]})),s?E.push({op:"bcurveTo",data:[m+e+(n-e)*p+h(),f+t+(i-t)*p+h(),m+e+2*(n-e)*p+h(),f+t+2*(i-t)*p+h(),n+(x?0:h()),i+(x?0:h())]}):E.push({op:"bcurveTo",data:[m+e+(n-e)*p+g(),f+t+(i-t)*p+g(),m+e+2*(n-e)*p+g(),f+t+2*(i-t)*p+g(),n+(x?0:g()),i+(x?0:g())]}),E}function As(e,t,n){let i=[];i.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]),i.push([e[0][0]+O(t,n),e[0][1]+O(t,n)]);for(let o=1;o<e.length;o++)i.push([e[o][0]+O(t,n),e[o][1]+O(t,n)]),o===e.length-1&&i.push([e[o][0]+O(t,n),e[o][1]+O(t,n)]);return Pi(i,null,n)}function Pi(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]+O(a,n),t[1]+O(a,n)]})}}else i===3?(o.push({op:"move",data:[e[1][0],e[1][1]]}),o.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):i===2&&o.push(...ht(e[0][0],e[0][1],e[1][0],e[1][1],n));return o}function Ds(e,t,n,i,o,r,s,a){let l=a.roughness===0,c=[],d=[];if(l){e=e/4,d.push([t+i*Math.cos(-e),n+o*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let p=[t+i*Math.cos(u),n+o*Math.sin(u)];c.push(p),d.push(p)}d.push([t+i*Math.cos(0),n+o*Math.sin(0)]),d.push([t+i*Math.cos(e),n+o*Math.sin(e)])}else{let u=O(.5,a)-Math.PI/2;d.push([O(r,a)+t+.9*i*Math.cos(u-e),O(r,a)+n+.9*o*Math.sin(u-e)]);let p=Math.PI*2+u-.01;for(let m=u;m<p;m=m+e){let f=[O(r,a)+t+i*Math.cos(m),O(r,a)+n+o*Math.sin(m)];c.push(f),d.push(f)}d.push([O(r,a)+t+i*Math.cos(u+Math.PI*2+s*.5),O(r,a)+n+o*Math.sin(u+Math.PI*2+s*.5)]),d.push([O(r,a)+t+.98*i*Math.cos(u+s),O(r,a)+n+.98*o*Math.sin(u+s)]),d.push([O(r,a)+t+.9*i*Math.cos(u+s*.5),O(r,a)+n+.9*o*Math.sin(u+s*.5)])}return[d,c]}function vs(e,t,n,i,o,r,s,a,l){let c=r+O(.1,l),d=[];d.push([O(a,l)+t+.9*i*Math.cos(c-e),O(a,l)+n+.9*o*Math.sin(c-e)]);for(let u=c;u<=s;u=u+e)d.push([O(a,l)+t+i*Math.cos(u),O(a,l)+n+o*Math.sin(u)]);return d.push([t+i*Math.cos(s),n+o*Math.sin(s)]),d.push([t+i*Math.cos(s),n+o*Math.sin(s)]),Pi(d,null,l)}function Cd(e,t,n,i,o,r,s,a){let l=[],c=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],d=[0,0],u=a.disableMultiStroke?1:2,p=a.preserveVertices;for(let m=0;m<u;m++)m===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(p?0:O(c[0],a)),s[1]+(p?0:O(c[0],a))]}),d=p?[o,r]:[o+O(c[m],a),r+O(c[m],a)],l.push({op:"bcurveTo",data:[e+O(c[m],a),t+O(c[m],a),n+O(c[m],a),i+O(c[m],a),d[0],d[1]]});return l}P();function Xn(e){return[...e]}function Gs(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let i=[];if(n===3)i.push(Xn(e[0]),Xn(e[1]),Xn(e[2]),Xn(e[2]));else{let o=[];o.push(e[0],e[0]);for(let a=1;a<e.length;a++)o.push(e[a]),a===e.length-1&&o.push(e[a]);let r=[],s=1-t;i.push(Xn(o[0]));for(let a=1;a+2<o.length;a++){let l=o[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*o[a+1][0]-s*o[a-1][0])/6,l[1]+(s*o[a+1][1]-s*o[a-1][1])/6],r[2]=[o[a+1][0]+(s*o[a][0]-s*o[a+2][0])/6,o[a+1][1]+(s*o[a][1]-s*o[a+2][1])/6],r[3]=[o[a+1][0],o[a+1][1]],i.push(r[1],r[2],r[3])}}return i}P();function Bd(e,t){return Math.sqrt(Mi(e,t))}function Mi(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Gd(e,t,n){let i=Mi(t,n);if(i===0)return Mi(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)),Mi(e,sn(t,n,o))}function sn(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Od(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 c=3*o[1]-2*r[1]-n[1];return c*=c,s<l&&(s=l),a<c&&(a=c),s+a}function Yo(e,t,n,i){let o=i||[];if(Od(e,t)<n){let r=e[t+0];o.length?Bd(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],c=e[t+3],d=sn(s,a,.5),u=sn(a,l,.5),p=sn(l,c,.5),m=sn(d,u,.5),f=sn(u,p,.5),E=sn(m,f,.5);Yo([s,d,m,E],0,n,o),Yo([E,f,p,c],0,n,o)}return o}function Wn(e,t){return Ti(e,0,e.length,t)}function Ti(e,t,n,i,o){let r=o||[],s=e[t],a=e[n-1],l=0,c=1;for(let d=t+1;d<n-1;++d){let u=Gd(e[d],s,a);u>l&&(l=u,c=d)}return Math.sqrt(l)>i?(Ti(e,t,c+1,i,r),Ti(e,c,n,i,r)):(r.length||r.push(s),r.push(a)),r}function Et(e,t=.15,n){let i=[],o=(e.length-1)/3;for(let r=0;r<o;r++){let s=r*3;Yo(e,s,t,i)}return n&&n>0?Ti(i,0,i.length,n):i}P();function Os(e,t,n){let i=yn(e),o=Yn(Hn(i)),r=[],s=[],a=[0,0],l=[],c=()=>{l.length>=4&&s.push(...Et(l,t)),l=[]},d=()=>{c(),s.length&&(r.push(s),s=[])};for(let{key:p,data:m}of o)switch(p){case"M":d(),a=[m[0],m[1]],s.push(a);break;case"L":c(),s.push([m[0],m[1]]);break;case"C":if(!l.length){let f=s.length?s[s.length-1]:a;l.push([f[0],f[1]])}l.push([m[0],m[1]]),l.push([m[2],m[3]]),l.push([m[4],m[5]]);break;case"Z":c(),s.push([a[0],a[1]]);break}if(d(),!n)return r;let u=[];for(let p of r){let m=Wn(p,n);m.length&&u.push(m)}return u}var Ne="none",Xe=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 Ss()}_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",[Fo(t,n,i,o,s)],s)}rectangle(t,n,i,o,r){let s=this._o(r),a=[],l=Ls(t,n,i,o,s);if(s.fill){let c=[[t,n],[t+i,n],[t+i,n+o],[t,n+o]];s.fillStyle==="solid"?a.push(Si([c],s)):a.push(rn([c],s))}return s.stroke!==Ne&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,i,o,r){let s=this._o(r),a=[],l=zo(i,o,s),c=Ii(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let d=Ii(t,n,s,l).opset;d.type="fillPath",a.push(d)}else a.push(rn([c.estimatedPoints],s));return s.stroke!==Ne&&a.push(c.opset),this._d("ellipse",a,s)}circle(t,n,i,o){let r=this.ellipse(t,n,i,i,o);return r.shape="circle",r}linearPath(t,n){let i=this._o(n);return this._d("linearPath",[Un(t,!1,i)],i)}arc(t,n,i,o,r,s,a=!1,l){let c=this._o(l),d=[],u=Ho(t,n,i,o,r,s,a,!0,c);if(a&&c.fill)if(c.fillStyle==="solid"){let p=Object.assign({},c);p.disableMultiStroke=!0;let m=Ho(t,n,i,o,r,s,!0,!1,p);m.type="fillPath",d.push(m)}else d.push(Cs(t,n,i,o,r,s,c));return c.stroke!==Ne&&d.push(u),this._d("arc",d,c)}curve(t,n){let i=this._o(n),o=[],r=No(t,i);if(i.fill&&i.fill!==Ne&&t.length>=3)if(i.fillStyle==="solid"){let s=No(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=Gs(t),a=Et(s,10,(1+i.roughness)/2);o.push(rn([a],i))}return i.stroke!==Ne&&o.push(r),this._d("curve",o,i)}polygon(t,n){let i=this._o(n),o=[],r=Un(t,!0,i);return i.fill&&(i.fillStyle==="solid"?o.push(Si([t],i)):o.push(rn([t],i))),i.stroke!==Ne&&o.push(r),this._d("polygon",o,i)}path(t,n){let i=this._o(n),o=[];if(!t)return this._d("path",o,i);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=i.fill&&i.fill!=="transparent"&&i.fill!==Ne,s=i.stroke!==Ne,a=!!(i.simplification&&i.simplification<1),l=a?4-4*(i.simplification||1):(1+i.roughness)/2,c=Os(t,1,l),d=_o(t,i);if(r)if(i.fillStyle==="solid")if(c.length===1){let u=_o(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(Si(c,i));else o.push(rn(c,i));return s&&(a?c.forEach(u=>{o.push(Un(u,!1,i))}):o.push(d)),this._d("path",o,i)}opsToPath(t,n){let i="";for(let o of t.ops){let r=typeof n=="number"&&n>=0?o.data.map(s=>+s.toFixed(n)):o.data;switch(o.op){case"move":i+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":i+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":i+=`L${r[0]} ${r[1]} `;break}}return i.trim()}toPaths(t){let n=t.sets||[],i=t.options||this.defaultOptions,o=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:i.stroke,strokeWidth:i.strokeWidth,fill:Ne};break;case"fillPath":s={d:this.opsToPath(r),stroke:Ne,strokeWidth:0,fill:i.fill||Ne};break;case"fillSketch":s=this.fillSketch(r,i);break}s&&o.push(s)}return o}fillSketch(t,n){let i=n.fillWeight;return i<0&&(i=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||Ne,strokeWidth:i,fill:Ne}}_mergedShape(t){return t.filter((n,i)=>i===0?!0:n.op!=="move")}};var Ai=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new Xe(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 c=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(c),c}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 jn="http://www.w3.org/2000/svg";var Di=class{constructor(t,n){this.svg=t,this.gen=new Xe(n)}draw(t){let n=t.sets||[],i=t.options||this.getDefaultOptions(),o=this.svg.ownerDocument||window.document,r=o.createElementNS(jn,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=o.createElementNS(jn,"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(jn,"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(jn,"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 c=this.gen.arc(t,n,i,o,r,s,a,l);return this.draw(c)}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 an={canvas(e,t){return new Ai(e,t)},svg(e,t){return new Di(e,t)},generator(e){return new Xe(e)},newSeed(){return Xe.newSeed()}};import{arrayToMap as Vl,invariant as Yr,rescalePoints as Yl,sizeOf as rf}from"@excalidraw/common";import{degreesToRadians as _r,lineSegment as Ee,pointDistance as sf,pointFrom as v,pointFromArray as $l,pointRotateRads as se}from"@excalidraw/math";P();import{invariant as Rd}from"@excalidraw/common";import{curve as kd,lineSegment as Fd,pointFrom as le,pointDistance as Jg,pointFromArray as Nd,pointFromVector as zd,pointRotateRads as Ze,polygon as Rs,polygonFromPoints as Uo,PRECISION as ex,segmentsIntersectAt as tx,vector as Hd,vectorAdd as _d,vectorFromPoint as Yd,vectorScale as nx}from"@excalidraw/math";import{getElementAbsoluteCoords as ox}from"@excalidraw/element";var ks=e=>{let{angle:t,width:n,height:i,x:o,y:r}=e,s=o+n/2,a=r+i/2,l=le(s,a),c;return e.type==="diamond"?c=Rs(Ze(le(s,r),l,t),Ze(le(o+n,a),l,t),Ze(le(s,r+i),l,t),Ze(le(o,a),l,t)):c=Rs(Ze(le(o,r),l,t),Ze(le(o+n,r),l,t),Ze(le(o+n,r+i),l,t),Ze(le(o,r+i),l,t)),{type:"polygon",data:c}};var Fs=e=>{let{width:t,height:n,angle:i,x:o,y:r}=e;return{type:"ellipse",data:{center:le(o+t/2,r+n/2),angle:i,halfWidth:t/2,halfHeight:n/2}}},gt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},Ns=(e,t=le(0,0),n,i)=>{let o=l=>Ze(le(l[0]+t[0],l[1]+t[1]),i,n),r=gt(e),s=[],a=le(0,0);for(let l of r){if(l.op==="move"){let c=Nd(l.data);Rd(c!=null,"Ops data is not a point"),a=o(c)}if(l.op==="bcurveTo"){let c=o(le(l.data[0],l.data[1])),d=o(le(l.data[2],l.data[3])),u=o(le(l.data[4],l.data[5]));s.push(kd(a,c,d,u)),a=u}}return{type:"polycurve",data:s}},Ud=e=>{let t=e[0],n=[];for(let i=1;i<e.length;i++){let o=e[i];n.push(Fd(t,o)),t=o}return n},zs=(e,t,n=!1)=>{let i=r=>Ze(zd(_d(Yd(r),Hd(e.x,e.y))),t,e.angle),o=Ud(e.points.map(r=>i(r)));return n?{type:"polygon",data:Uo(o.flat())}:{type:"polyline",data:o}},Hs=(e,t,n=le(0,0),i,o)=>{let r=d=>Ze(le(d[0]+n[0],d[1]+n[1]),o,i);if(e.roundness===null)return{type:"polygon",data:Uo(e.points.map(d=>r(d)))};let s=gt(t),a=[],l=!1;for(let d of s)d.op==="move"?(l=!l,l&&a.push(le(d.data[0],d.data[1]))):d.op==="bcurveTo"?l&&(a.push(le(d.data[0],d.data[1])),a.push(le(d.data[2],d.data[3])),a.push(le(d.data[4],d.data[5]))):d.op==="lineTo"&&l&&a.push(le(d.data[0],d.data[1]));let c=Et(a,10,5).map(d=>r(d));return{type:"polygon",data:Uo(c)}};P();import{pointFrom as ce,pointDistance as kl,pointRotateRads as Lt}from"@excalidraw/math";import{ROUGHNESS as Km,isTransparent as ai,assertNever as Qm,COLOR_PALETTE as Jm,LINE_POLYGON_POINT_MERGE_DISTANCE as ef}from"@excalidraw/common";P();P();function _s(e,t,n,i=o=>o){return e*i(.5-t*(.5-n))}function Xd(e){return[-e[0],-e[1]]}function Ke(e,t){return[e[0]+t[0],e[1]+t[1]]}function We(e,t){return[e[0]-t[0],e[1]-t[1]]}function qe(e,t){return[e[0]*t,e[1]*t]}function Wd(e,t){return[e[0]/t,e[1]/t]}function Vn(e){return[e[1],-e[0]]}function Ys(e,t){return e[0]*t[0]+e[1]*t[1]}function jd(e,t){return e[0]===t[0]&&e[1]===t[1]}function Vd(e){return Math.hypot(e[0],e[1])}function $d(e){return e[0]*e[0]+e[1]*e[1]}function Us(e,t){return $d(We(e,t))}function js(e){return Wd(e,Vd(e))}function Zd(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function $n(e,t,n){let i=Math.sin(n),o=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*o-s*i,l=r*i+s*o;return[a+t[0],l+t[1]]}function Xo(e,t,n){return Ke(e,qe(We(t,e),n))}function Xs(e,t,n){return Ke(e,qe(t,n))}var{min:bn,PI:qd}=Math,Ws=.275,Zn=qd+1e-4;function Kd(e,t={}){let{size:n=16,smoothing:i=.5,thinning:o=.5,simulatePressure:r=!0,easing:s=S=>S,start:a={},end:l={},last:c=!1}=t,{cap:d=!0,easing:u=S=>S*(2-S)}=a,{cap:p=!0,easing:m=S=>--S*S*S+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,E=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,h=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*i,2),x=[],y=[],b=e.slice(0,10).reduce((S,Q)=>{let V=Q.pressure;if(r){let ne=bn(1,Q.distance/n),tn=bn(1,1-ne);V=bn(1,S+(tn-S)*(ne*Ws))}return(S+V)/2},e[0].pressure),w=_s(n,o,e[e.length-1].pressure,s),I,M=e[0].vector,D=e[0].point,T=D,F=D,C=T,k=!1;for(let S=0;S<e.length;S++){let{pressure:Q}=e[S],{point:V,vector:ne,distance:tn,runningLength:ot}=e[S];if(S<e.length-1&&f-ot<3)continue;if(o){if(r){let ge=bn(1,tn/n),on=bn(1,1-ge);Q=bn(1,b+(on-b)*(ge*Ws))}w=_s(n,o,Q,s)}else w=n/2;I===void 0&&(I=w);let wn=ot<E?u(ot/E):1,Go=f-ot<h?m((f-ot)/h):1;w=Math.max(.01,w*Math.min(wn,Go));let pi=(S<e.length-1?e[S+1]:e[S]).vector,zn=S<e.length-1?Ys(ne,pi):1,Oo=Ys(ne,M)<0&&!k,mi=zn!==null&&zn<0;if(Oo||mi){let ge=qe(Vn(M),w);for(let on=1/13,De=0;De<=1;De+=on)F=$n(We(V,ge),V,Zn*De),x.push(F),C=$n(Ke(V,ge),V,Zn*-De),y.push(C);D=F,T=C,mi&&(k=!0);continue}if(k=!1,S===e.length-1){let ge=qe(Vn(ne),w);x.push(We(V,ge)),y.push(Ke(V,ge));continue}let nn=qe(Vn(Xo(pi,ne,zn)),w);F=We(V,nn),(S<=1||Us(D,F)>g)&&(x.push(F),D=F),C=Ke(V,nn),(S<=1||Us(T,C)>g)&&(y.push(C),T=C),b=Q,M=ne}let L=e[0].point.slice(0,2),j=e.length>1?e[e.length-1].point.slice(0,2):Ke(e[0].point,[1,1]),N=[],te=[];if(e.length===1){if(!(E||h)||c){let S=Xs(L,js(Vn(We(L,j))),-(I||w)),Q=[];for(let V=1/13,ne=V;ne<=1;ne+=V)Q.push($n(S,L,Zn*2*ne));return Q}}else{if(!(E||h&&e.length===1))if(d)for(let Q=1/13,V=Q;V<=1;V+=Q){let ne=$n(y[0],L,Zn*V);N.push(ne)}else{let Q=We(x[0],y[0]),V=qe(Q,.5),ne=qe(Q,.51);N.push(We(L,V),We(L,ne),Ke(L,ne),Ke(L,V))}let S=Vn(Xd(e[e.length-1].vector));if(h||E&&e.length===1)te.push(j);else if(p){let Q=Xs(j,S,w);for(let V=1/29,ne=V;ne<1;ne+=V)te.push($n(Q,j,Zn*3*ne))}else te.push(Ke(j,qe(S,w)),Ke(j,qe(S,w*.99)),We(j,qe(S,w*.99)),We(j,qe(S,w)))}return x.concat(te,y.reverse(),N)}function Qd(e,t={}){var n;let{streamline:i=.5,size:o=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-i)*.85,a=Array.isArray(e[0])?e:e.map(({x:m,y:f,pressure:E=.5})=>[m,f,E]);if(a.length===2){let m=a[1];a=a.slice(0,-1);for(let f=1;f<5;f++)a.push(Xo(a[0],m,f/4))}a.length===1&&(a=[...a,[...Ke(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}],c=!1,d=0,u=l[0],p=a.length-1;for(let m=1;m<a.length;m++){let f=r&&m===p?a[m].slice(0,2):Xo(u.point,a[m],s);if(jd(u.point,f))continue;let E=Zd(f,u.point);if(d+=E,m<p&&!c){if(d<o)continue;c=!0}u={point:f,pressure:a[m][2]>=0?a[m][2]:.5,vector:js(We(u.point,f)),distance:E,runningLength:d},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function Vs(e,t={}){return Kd(Qd(e,t),t)}import{isRightAngleRads as Fm}from"@excalidraw/math";import{BOUND_TEXT_PADDING as mo,DEFAULT_REDUCED_GLOBAL_ALPHA as Nm,ELEMENT_READY_TO_ERASE_OPACITY as zm,FRAME_STYLE as fo,MIME_TYPES as zr,THEME as Al,distance as Qt,getFontString as Hm,isRTL as _m,getVerticalOffset as Ym}from"@excalidraw/common";P();import{pointFrom as xt,pointCenter as Jd,pointRotateRads as Ft,vectorFromPoint as Wo,vectorNormalize as $s,vectorSubtract as Zs,vectorAdd as vi,vectorScale as Li,pointFromVector as qs,clamp as Pe,isCloseTo as Ks}from"@excalidraw/math";var Ie=10,ux=(e,t,n,i,o,r,s,a)=>{let{width:l,height:c}=jo(e),d=i/l,u=o/c,p=(e.crop?.x??0)/d,m=(e.crop?.y??0)/u,f=Ft(xt(r,s),fe(e,t),-e.angle);r=f[0],s=f[1];let E=e.width,h=e.height,g=e.crop??{x:0,y:0,width:i,height:o,naturalWidth:i,naturalHeight:o},x=g.height,y=g.width,b=e.scale[0]===-1,w=e.scale[1]===-1,I=s-e.y,M=r-e.x;n.includes("n")&&(h=Pe(e.height-I,Ie,w?c-m:e.height+m)),n.includes("s")&&(I=s-e.y-e.height,h=Pe(e.height+I,Ie,w?e.height+m:c-m)),n.includes("e")&&(M=r-e.x-e.width,E=Pe(e.width+M,Ie,b?e.width+p:l-p)),n.includes("w")&&(E=Pe(e.width-M,Ie,b?l-p:e.width+p));let D=C=>{C.height=h*u,C.width=E*d};D(g);let T=(C,k)=>{D(k),C.includes("n")&&(w||(k.y+=x-k.height)),C.includes("s")&&w&&(k.y+=x-k.height),C.includes("e")&&b&&(k.x+=y-k.width),C.includes("w")&&(b||(k.x+=y-k.width))};switch(n){case"n":{if(a){let C=p+e.width/2,k=l-p-e.width/2,L=Math.min(C,k)*2;E=Pe(h*a,Ie,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"s":{if(a){let C=p+e.width/2,k=l-p-e.width/2,L=Math.min(C,k)*2;E=Pe(h*a,Ie,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"w":{if(a){let C=m+e.height/2,k=c-m-e.height/2,L=Math.min(C,k)*2;h=Pe(E/a,Ie,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let C=m+e.height/2,k=c-m-e.height/2,L=Math.min(C,k)*2;h=Pe(E/a,Ie,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(M>-I){let C=w?c-m:m+e.height;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?p+e.width:l-p;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"nw":{if(a)if(M<I){let C=w?c-m:m+e.height;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?l-p:p+e.width;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"se":{if(a)if(M>I){let C=w?m+e.height:c-m;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?p+e.width:l-p;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}case"sw":{if(a)if(-M>I){let C=w?m+e.height:c-m;h=Pe(E/a,Ie,C),E=h*a}else{let C=b?l-p:p+e.width;E=Pe(h*a,Ie,C),h=E/a}T(n,g);break}default:break}let F=eu(e,n,E,h,!!a);return Ks(g.width,g.naturalWidth)&&Ks(g.height,g.naturalHeight)&&(g=null),{x:F[0],y:F[1],width:E,height:h,crop:g}},eu=(e,t,n,i,o)=>{let[r,s,a,l]=Nt(e,e.width,e.height,!0),c=xt(r,s),d=xt(a,l),u=Jd(c,d),[p,m,f,E]=Nt(e,n,i,!0),h=f-p,g=E-m,x=[...c];if(["n","w","nw"].includes(t)&&(x=[d[0]-Math.abs(h),d[1]-Math.abs(g)]),t==="ne"){let D=[c[0],d[1]];x=[D[0],D[1]-Math.abs(g)]}if(t==="sw"){let D=[d[0],c[1]];x=[D[0]-Math.abs(h),D[1]]}o&&(["s","n"].includes(t)&&(x[0]=u[0]-h/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let y=e.angle,b=Ft(x,u,y),w=[x[0]+Math.abs(h)/2,x[1]+Math.abs(g)/2],I=Ft(w,u,y);x=Ft(b,I,-y);let M=[...x];return M[0]+=e.x-p,M[1]+=e.y-m,M},Qs=(e,t)=>{if(e.crop){let{width:n,height:i}=jo(e),[o,r,s,a,l,c]=H(e,t),d=Wo(Ft(xt(o,r),xt(l,c),e.angle)),u=Wo(Ft(xt(s,r),xt(l,c),e.angle)),p=$s(Zs(u,d)),m=Wo(Ft(xt(o,a),xt(l,c),e.angle)),f=Zs(m,d),E=$s(f),{cropX:h,cropY:g}=tu(e.crop,e.scale),x=vi(vi(d,Li(p,-h*n/e.crop.naturalWidth)),Li(E,-g*i/e.crop.naturalHeight)),y=qs(vi(vi(x,Li(p,n/2)),Li(E,i/2))),b=Ft(qs(x),y,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:i,crop:null}}return e},jo=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}},tu=(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}},px=(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}=jo(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as Ka,pointFrom as B,pointRotateRads as Te,pointsEqual as Qa,pointDistance as Cn,vectorFromPoint as em,curveLength as tm,curvePointAtLength as nm}from"@excalidraw/math";import{DRAGGING_THRESHOLD as im,KEYS as Bn,shouldRotateWithDiscreteAngle as Ja,getGridPoint as el,invariant as At,tupleToCoors as Dr,viewportCoordsToSceneCoords as om}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as tl,isPathALoop as rm}from"@excalidraw/element";P();import{KEYS as Dp,arrayToMap as Ha,isBindingFallthroughEnabled as to,tupleToCoors as vp,invariant as Lp,isDevEnv as Cp,isTestEnv as Bp}from"@excalidraw/common";import{lineSegment as Ye,pointFrom as R,pointRotateRads as ae,vectorFromPoint as Z,pointDistanceSq as jt,clamp as ka,pointDistance as ut,pointFromVector as vn,vectorScale as Ln,vectorNormalize as ri,vectorCross as _e,pointsEqual as Gp,lineSegmentIntersectionPoints as Fa,PRECISION as Op}from"@excalidraw/math";P();import{isTransparent as Xu}from"@excalidraw/common";import{curveIntersectLineSegment as ya,isPointWithinBounds as Yi,lineSegment as Ui,lineSegmentIntersectionPoints as ba,pointFrom as St,pointFromVector as Wu,pointRotateRads as lt,pointsEqual as ju,vectorFromPoint as Vu,vectorNormalize as $u,vectorScale as Zu}from"@excalidraw/math";import{ellipse as qu,ellipseSegmentInterceptPoints as Ku}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as nu,DEFAULT_PROPORTIONAL_RADIUS as Vo,LINE_CONFIRM_THRESHOLD as iu,ROUNDNESS as $o}from"@excalidraw/common";import{curve as wt,curveCatmullRomCubicApproxPoints as Js,curveOffsetPoints as ea,lineSegment as ze,pointDistance as ou,pointFrom as U,pointFromArray as ru,rectangle as su}from"@excalidraw/math";var qn=new WeakMap,Zo=(e,t)=>{let n=qn.get(e);if(!n)return;let{version:i,shapes:o}=n;if(i!==e.version){qn.delete(e);return}return o.get(t)},qo=(e,t,n)=>{let i=qn.get(e);if(!i){qn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:o,shapes:r}=i;if(o!==e.version){qn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function Ci(e){let t=Zo(e,0);if(t)return t;let n=ta(e),i=[],o=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&ru(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");i.push(ze(U(e.x+l[0],e.y+l[1]),U(e.x+a.data[0],e.y+a.data[1])));continue;case"bcurveTo":if(!l)throw new Error("prevPoint is undefined");o.push(wt(U(e.x+l[0],e.y+l[1]),U(e.x+a.data[0],e.y+a.data[1]),U(e.x+a.data[2],e.y+a.data[3]),U(e.x+a.data[4],e.y+a.data[5])));continue;default:console.error("Unknown op type",a.op)}}let r=[i,o];return qo(e,r,0),r}function Pn(e,t=0){let n=Zo(e,t);if(n)return n;let i=yt(Math.min(e.width,e.height),e);i===0&&(i=.01);let o=su(U(e.x,e.y),U(e.x+e.width,e.y+e.height)),r=ze(U(o[0][0]+i,o[0][1]),U(o[1][0]-i,o[0][1])),s=ze(U(o[1][0],o[0][1]+i),U(o[1][0],o[1][1]-i)),a=ze(U(o[0][0]+i,o[1][1]),U(o[1][0]-i,o[1][1])),l=ze(U(o[0][0],o[1][1]-i),U(o[0][0],o[0][1]+i)),c=[wt(l[1],U(l[1][0]+2/3*(o[0][0]-l[1][0]),l[1][1]+2/3*(o[0][1]-l[1][1])),U(r[0][0]+2/3*(o[0][0]-r[0][0]),r[0][1]+2/3*(o[0][1]-r[0][1])),r[0]),wt(r[1],U(r[1][0]+2/3*(o[1][0]-r[1][0]),r[1][1]+2/3*(o[0][1]-r[1][1])),U(s[0][0]+2/3*(o[1][0]-s[0][0]),s[0][1]+2/3*(o[0][1]-s[0][1])),s[0]),wt(s[1],U(s[1][0]+2/3*(o[1][0]-s[1][0]),s[1][1]+2/3*(o[1][1]-s[1][1])),U(a[1][0]+2/3*(o[1][0]-a[1][0]),a[1][1]+2/3*(o[1][1]-a[1][1])),a[1]),wt(a[0],U(a[0][0]+2/3*(o[0][0]-a[0][0]),a[0][1]+2/3*(o[1][1]-a[0][1])),U(l[0][0]+2/3*(o[0][0]-l[0][0]),l[0][1]+2/3*(o[1][1]-l[0][1])),l[0])],d=t>0?c.map(m=>Js(ea(m,t))):[[c[0]],[c[1]],[c[2]],[c[3]]],p=[[ze(d[0][d[0].length-1][3],d[1][0][0]),ze(d[1][d[1].length-1][3],d[2][0][0]),ze(d[2][d[2].length-1][3],d[3][0][0]),ze(d[3][d[3].length-1][3],d[0][0][0])],d.flat()];return qo(e,p,t),p}function In(e,t=0){let n=Zo(e,t);if(n)return n;let[i,o,r,s,a,l,c,d]=Bi(e),u=e.roundness?yt(Math.abs(i-c),e):(i-c)*.01,p=e.roundness?yt(Math.abs(s-o),e):(s-o)*.01,[m,f,E,h]=[U(e.x+i,e.y+o),U(e.x+r,e.y+s),U(e.x+a,e.y+l),U(e.x+c,e.y+d)],g=[wt(U(f[0]-u,f[1]-p),f,f,U(f[0]-u,f[1]+p)),wt(U(E[0]+u,E[1]-p),E,E,U(E[0]-u,E[1]-p)),wt(U(h[0]+u,h[1]+p),h,h,U(h[0]+u,h[1]-p)),wt(U(m[0]-u,m[1]+p),m,m,U(m[0]+u,m[1]+p))],x=t>0?g.map(w=>Js(ea(w,t))):[[g[0]],[g[1]],[g[2]],[g[3]]],b=[[ze(x[0][x[0].length-1][3],x[1][0][0]),ze(x[1][x[1].length-1][3],x[2][0][0]),ze(x[2][x[2].length-1][3],x[3][0][0]),ze(x[3][x[3].length-1][3],x[0][0][0])],x.flat()];return qo(e,b,t),b}var ln=(e,t=1)=>{if(e.length>=3){let[n,i]=[e[0],e[e.length-1]];return ou(n,i)<=iu/t}return!1},yt=(e,t)=>{if(t.roundness?.type===$o.PROPORTIONAL_RADIUS||t.roundness?.type===$o.LEGACY)return e*Vo;if(t.roundness?.type===$o.ADAPTIVE_RADIUS){let n=t.roundness?.value??nu,i=n/Vo;return e<=i?e*Vo:n}return 0};P();import{ROUNDNESS as Kn,assertNever as au}from"@excalidraw/common";import{pointsEqual as na}from"@excalidraw/math";var zt=e=>!!e&&e.type==="image"&&!!e.fileId,xe=e=>!!e&&e.type==="image",ia=e=>!!e&&e.type==="embeddable",Gi=e=>!!e&&e.type==="iframe",Oi=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),ie=e=>e!=null&&e.type==="text",Ri=e=>e!=null&&e.type==="frame",oa=e=>e!=null&&e.type==="magicframe",$=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Se=e=>e!=null&&lu(e.type),lu=e=>e==="freedraw",X=e=>e!=null&&Ko(e.type),cn=e=>e!=null&&e.type==="line",_=e=>e!=null&&e.type==="arrow",G=e=>_(e)&&e.elbowed,Ix=e=>_(e)&&!e.elbowed,cu=e=>_(e)&&!e.elbowed&&!e.roundness,du=e=>_(e)&&!e.elbowed&&e.roundness!==null,Ko=e=>e==="arrow"||e==="line",Qo=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&uu(e.type),uu=e=>e==="arrow",Le=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),ra=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),Sx=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"),pu=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||_(e)),Mx=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 au(t,null),!1}},Jo=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",st=e=>pu(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),de=e=>e!==null&&"containerId"in e&&e.containerId!==null&&ie(e),Tx=e=>!!e.startBinding||!!e.endBinding,sa=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",aa=e=>e==="line"||e==="arrow"||e==="diamond",Ax=(e,t)=>!!((e===Kn.ADAPTIVE_RADIUS||e===Kn.LEGACY)&&sa(t.type)||e===Kn.PROPORTIONAL_RADIUS&&aa(t.type)),Dx=e=>aa(e.type)?{type:Kn.PROPORTIONAL_RADIUS}:sa(e.type)?{type:Kn.ADAPTIVE_RADIUS}:null,Qn=e=>Object.hasOwn(e,"fixedPoint")&&e.fixedPoint!=null,vx=e=>Array.isArray(e)&&e.length===4&&typeof e[0]=="number"&&typeof e[1]=="number"&&typeof e[2]=="number"&&typeof e[3]=="number",Lx=e=>cu(e)?"sharpArrow":du(e)?"curvedArrow":G(e)?"elbowArrow":"line",Cx=e=>e.length>3&&na(e[0],e[e.length-1]),la=e=>e.length>3||e.length===3&&!na(e[0],e[e.length-1]);P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Bu,ARROW_LABEL_WIDTH_FRACTION as Gu,BOUND_TEXT_PADDING as at,DEFAULT_FONT_SIZE as Ou,TEXT_ALIGN as ha,VERTICAL_ALIGN as Ea,getFontString as _i,isProdEnv as Ru,invariant as ku}from"@excalidraw/common";P();var Jn={},ca=(e,t)=>{let n=Jn[e]||(Jn[e]={height:t});return n.height=t,n},da=e=>{Jn[e]&&delete Jn[e]},Ox=e=>Jn[e]?.height??null;P();import{BOUND_TEXT_PADDING as Fi,DEFAULT_FONT_SIZE as mu,DEFAULT_FONT_FAMILY as fu,getFontString as hu,isTestEnv as Eu,normalizeEOL as gu}from"@excalidraw/common";var Qe=(e,t,n)=>{let i=e.split(`
1
+ var mc=Object.create;var Ss=Object.defineProperty;var fc=Object.getOwnPropertyDescriptor;var hc=Object.getOwnPropertyNames;var Ec=Object.getPrototypeOf,gc=Object.prototype.hasOwnProperty;var xc=(e,t)=>()=>(e&&(t=e(e=0)),t);var wc=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var yc=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of hc(t))!gc.call(e,i)&&i!==n&&Ss(e,i,{get:()=>t[i],enumerable:!(o=fc(t,i))||o.enumerable});return e};var bc=(e,t,n)=>(n=e!=null?mc(Ec(e)):{},yc(t||!e||!e.__esModule?Ss(n,"default",{value:e,enumerable:!0}):n,e));var A,P=xc(()=>{A={PROD:!0}});var Pd=wc((H1,bd)=>{P();var yd="Expected a function",xd=NaN,Wf="[object Symbol]",Vf=/^\s+|\s+$/g,$f=/^[-+]0x[0-9a-f]+$/i,Zf=/^0b[01]+$/i,qf=/^0o[0-7]+$/i,Kf=parseInt,Qf=typeof global=="object"&&global&&global.Object===Object&&global,Jf=typeof self=="object"&&self&&self.Object===Object&&self,eh=Qf||Jf||Function("return this")(),th=Object.prototype,nh=th.toString,oh=Math.max,ih=Math.min,is=function(){return eh.Date.now()};function rh(e,t,n){var o,i,r,s,a,l,d=0,c=!1,u=!1,p=!0;if(typeof e!="function")throw new TypeError(yd);t=wd(t)||0,Si(n)&&(c=!!n.leading,u="maxWait"in n,r=u?oh(wd(n.maxWait)||0,t):r,p="trailing"in n?!!n.trailing:p);function m(I){var M=o,D=i;return o=i=void 0,d=I,s=e.apply(D,M),s}function f(I){return d=I,a=setTimeout(g,t),c?m(I):s}function E(I){var M=I-l,D=I-d,T=t-M;return u?ih(T,r-D):T}function h(I){var M=I-l,D=I-d;return l===void 0||M>=t||M<0||u&&D>=r}function g(){var I=is();if(h(I))return x(I);a=setTimeout(g,E(I))}function x(I){return a=void 0,p&&o?m(I):(o=i=void 0,s)}function y(){a!==void 0&&clearTimeout(a),d=0,o=l=i=a=void 0}function b(){return a===void 0?s:x(is())}function w(){var I=is(),M=h(I);if(o=arguments,i=this,l=I,M){if(a===void 0)return f(l);if(u)return a=setTimeout(g,t),m(l)}return a===void 0&&(a=setTimeout(g,t)),s}return w.cancel=y,w.flush=b,w}function sh(e,t,n){var o=!0,i=!0;if(typeof e!="function")throw new TypeError(yd);return Si(n)&&(o="leading"in n?!!n.leading:o,i="trailing"in n?!!n.trailing:i),rh(e,t,{leading:o,maxWait:t,trailing:i})}function Si(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function ah(e){return!!e&&typeof e=="object"}function lh(e){return typeof e=="symbol"||ah(e)&&nh.call(e)==Wf}function wd(e){if(typeof e=="number")return e;if(lh(e))return xd;if(Si(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Si(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Vf,"");var n=Zf.test(e);return n||qf.test(e)?Kf(e.slice(2),n?2:8):$f.test(e)?xd:+e}bd.exports=sh});P();import{toIterable as bE}from"@excalidraw/common";P();import{SHIFT_LOCKING_ANGLE as kt,viewportCoordsToSceneCoords as yi}from"@excalidraw/common";import{normalizeRadians as Jl,radiansBetweenAngles as bf,radiansDifference as Pf}from"@excalidraw/math";import{pointsEqual as If}from"@excalidraw/math";P();P();P();P();P();P();P();P();P();function Fi(e,t,n){if(e&&e.length){let[o,i]=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-o)*s-(c-i)*a+o,l[1]=(d-o)*a+(c-i)*s+i}}}function Ic(e,t,n){let o=[];e.forEach(i=>o.push(...i)),Fi(o,t,n)}function Sc(e,t){return e[0]===t[0]&&e[1]===t[1]}function Ms(e,t,n,o=1){let i=n,r=Math.max(t,.1),s=e[0]&&e[0][0]&&typeof e[0][0]=="number"?[e]:e,a=[0,0];if(i)for(let d of s)Fi(d,a,i);let l=Mc(s,r,o);if(i){for(let d of s)Fi(d,a,-i);Ic(l,a,-i)}return l}function Mc(e,t,n){let o=[];for(let d of e){let c=[...d];Sc(c[0],c[c.length-1])||c.push([c[0][0],c[0][1]]),c.length>2&&o.push(c)}let i=[];t=Math.max(t,.1);let r=[];for(let d of o)for(let c=0;c<d.length-1;c++){let u=d[c],p=d[c+1];if(u[1]!==p[1]){let m=Math.min(u[1],p[1]);r.push({ymin:m,ymax:Math.max(u[1],p[1]),x:m===u[1]?u[0]:p[0],islope:(p[0]-u[0])/(p[1]-u[1])})}}if(r.sort((d,c)=>d.ymin<c.ymin?-1:d.ymin>c.ymin?1:d.x<c.x?-1:d.x>c.x?1:d.ymax===c.ymax?0:(d.ymax-c.ymax)/Math.abs(d.ymax-c.ymax)),!r.length)return i;let s=[],a=r[0].ymin,l=0;for(;s.length||r.length;){if(r.length){let d=-1;for(let u=0;u<r.length&&!(r[u].ymin>a);u++)d=u;r.splice(0,d+1).forEach(u=>{s.push({s:a,edge:u})})}if(s=s.filter(d=>!(d.edge.ymax<=a)),s.sort((d,c)=>d.edge.x===c.edge.x?0:(d.edge.x-c.edge.x)/Math.abs(d.edge.x-c.edge.x)),(n!==1||l%t===0)&&s.length>1)for(let d=0;d<s.length;d=d+2){let c=d+1;if(c>=s.length)break;let u=s[d].edge,p=s[c].edge;i.push([[Math.round(u.x),a],[Math.round(p.x),a]])}a+=n,s.forEach(d=>{d.edge.x=d.edge.x+n*d.edge.islope}),l++}return i}function rt(e,t){var n;let o=t.hachureAngle+90,i=t.hachureGap;i<0&&(i=t.strokeWidth*4),i=Math.max(i,.1);let r=1;return t.roughness>=1&&(((n=t.randomizer)===null||n===void 0?void 0:n.next())||Math.random())>.7&&(r=i),Ms(e,i,o,r||1)}var Ft=class{constructor(t){this.helper=t}fillPolygons(t,n){return this._fillPolygons(t,n)}_fillPolygons(t,n){let o=rt(t,n);return{type:"fillSketch",ops:this.renderLines(o,n)}}renderLines(t,n){let o=[];for(let i of t)o.push(...this.helper.doubleLineOps(i[0][0],i[0][1],i[1][0],i[1][1],n));return o}};P();P();function Nt(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 Eo=class extends Ft{fillPolygons(t,n){let o=n.hachureGap;o<0&&(o=n.strokeWidth*4),o=Math.max(o,.1);let i=Object.assign({},n,{hachureGap:o}),r=rt(t,i),s=Math.PI/180*n.hachureAngle,a=[],l=o*.5*Math.cos(s),d=o*.5*Math.sin(s);for(let[u,p]of r)Nt([u,p])&&a.push([[u[0]-l,u[1]+d],[...p]],[[u[0]+l,u[1]-d],[...p]]);return{type:"fillSketch",ops:this.renderLines(a,n)}}};P();var go=class extends Ft{fillPolygons(t,n){let o=this._fillPolygons(t,n),i=Object.assign({},n,{hachureAngle:n.hachureAngle+90}),r=this._fillPolygons(t,i);return o.ops=o.ops.concat(r.ops),o}};P();var xo=class{constructor(t){this.helper=t}fillPolygons(t,n){n=Object.assign({},n,{hachureAngle:0});let o=rt(t,n);return this.dotsOnLines(o,n)}dotsOnLines(t,n){let o=[],i=n.hachureGap;i<0&&(i=n.strokeWidth*4),i=Math.max(i,.1);let r=n.fillWeight;r<0&&(r=n.strokeWidth/2);let s=i/4;for(let a of t){let l=Nt(a),d=l/i,c=Math.ceil(d)-1,u=l-c*i,p=(a[0][0]+a[1][0])/2-i/4,m=Math.min(a[0][1],a[1][1]);for(let f=0;f<c;f++){let E=m+u+f*i,h=p-s+Math.random()*2*s,g=E-s+Math.random()*2*s,x=this.helper.ellipse(h,g,r,r,n);o.push(...x.ops)}}return{type:"fillSketch",ops:o}}};P();var wo=class{constructor(t){this.helper=t}fillPolygons(t,n){let o=rt(t,n);return{type:"fillSketch",ops:this.dashedLine(o,n)}}dashedLine(t,n){let o=n.dashOffset<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashOffset,i=n.dashGap<0?n.hachureGap<0?n.strokeWidth*4:n.hachureGap:n.dashGap,r=[];return t.forEach(s=>{let a=Nt(s),l=Math.floor(a/(o+i)),d=(a+i-l*(o+i))/2,c=s[0],u=s[1];c[0]>u[0]&&(c=s[1],u=s[0]);let p=Math.atan((u[1]-c[1])/(u[0]-c[0]));for(let m=0;m<l;m++){let f=m*(o+i),E=f+o,h=[c[0]+f*Math.cos(p)+d*Math.cos(p),c[1]+f*Math.sin(p)+d*Math.sin(p)],g=[c[0]+E*Math.cos(p)+d*Math.cos(p),c[1]+E*Math.sin(p)+d*Math.sin(p)];r.push(...this.helper.doubleLineOps(h[0],h[1],g[0],g[1],n))}}),r}};P();var yo=class{constructor(t){this.helper=t}fillPolygons(t,n){let o=n.hachureGap<0?n.strokeWidth*4:n.hachureGap,i=n.zigzagOffset<0?o:n.zigzagOffset;n=Object.assign({},n,{hachureGap:o+i});let r=rt(t,n);return{type:"fillSketch",ops:this.zigzagLines(r,i,n)}}zigzagLines(t,n,o){let i=[];return t.forEach(r=>{let s=Nt(r),a=Math.round(s/(2*n)),l=r[0],d=r[1];l[0]>d[0]&&(l=r[1],d=r[0]);let c=Math.atan((d[1]-l[1])/(d[0]-l[0]));for(let u=0;u<a;u++){let p=u*2*n,m=(u+1)*2*n,f=Math.sqrt(2*Math.pow(n,2)),E=[l[0]+p*Math.cos(c),l[1]+p*Math.sin(c)],h=[l[0]+m*Math.cos(c),l[1]+m*Math.sin(c)],g=[E[0]+f*Math.cos(c+Math.PI/4),E[1]+f*Math.sin(c+Math.PI/4)];i.push(...this.helper.doubleLineOps(E[0],E[1],g[0],g[1],o),...this.helper.doubleLineOps(g[0],g[1],h[0],h[1],o))}}),i}};var ve={};function Ts(e,t){let n=e.fillStyle||"hachure";if(!ve[n])switch(n){case"zigzag":ve[n]||(ve[n]=new Eo(t));break;case"cross-hatch":ve[n]||(ve[n]=new go(t));break;case"dots":ve[n]||(ve[n]=new xo(t));break;case"dashed":ve[n]||(ve[n]=new wo(t));break;case"zigzag-line":ve[n]||(ve[n]=new yo(t));break;case"hachure":default:n="hachure",ve[n]||(ve[n]=new Ft(t));break}return ve[n]}P();function As(){return Math.floor(Math.random()*2**31)}var bo=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 Po={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 Tc(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 Ni(e,t){return e.type===t}function In(e){let t=[],n=Tc(e),o="BOD",i=0,r=n[i];for(;!Ni(r,2);){let s=0,a=[];if(o==="BOD")if(r.text==="M"||r.text==="m")i++,s=Po[r.text],o=r.text;else return In("M0,0"+e);else Ni(r,1)?s=Po[o]:(i++,s=Po[r.text],o=r.text);if(i+s<n.length){for(let l=i;l<i+s;l++){let d=n[l];if(Ni(d,1))a[a.length]=+d.text;else throw new Error("Param not a number: "+o+","+d.text)}if(typeof Po[o]=="number"){let l={key:o,data:a};t.push(l),i+=s,r=n[i],o==="M"&&(o="L"),o==="m"&&(o="l")}else throw new Error("Bad segment: "+o)}else throw new Error("Path data ended short")}return t}P();function _n(e){let t=0,n=0,o=0,i=0,r=[];for(let{key:s,data:a}of e)switch(s){case"M":r.push({key:"M",data:[...a]}),[t,n]=a,[o,i]=a;break;case"m":t+=a[0],n+=a[1],r.push({key:"M",data:[t,n]}),o=t,i=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=o,n=i;break}return r}P();function Un(e){let t=[],n="",o=0,i=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]}),[o,i]=c,[r,s]=c;break;case"C":t.push({key:"C",data:[...c]}),o=c[4],i=c[5],a=c[2],l=c[3];break;case"L":t.push({key:"L",data:[...c]}),[o,i]=c;break;case"H":o=c[0],t.push({key:"L",data:[o,i]});break;case"V":i=c[0],t.push({key:"L",data:[o,i]});break;case"S":{let u=0,p=0;n==="C"||n==="S"?(u=o+(o-a),p=i+(i-l)):(u=o,p=i),t.push({key:"C",data:[u,p,...c]}),a=c[0],l=c[1],o=c[2],i=c[3];break}case"T":{let[u,p]=c,m=0,f=0;n==="Q"||n==="T"?(m=o+(o-a),f=i+(i-l)):(m=o,f=i);let E=o+2*(m-o)/3,h=i+2*(f-i)/3,g=u+2*(m-u)/3,x=p+2*(f-p)/3;t.push({key:"C",data:[E,h,g,x,u,p]}),a=m,l=f,o=u,i=p;break}case"Q":{let[u,p,m,f]=c,E=o+2*(u-o)/3,h=i+2*(p-i)/3,g=m+2*(u-m)/3,x=f+2*(p-f)/3;t.push({key:"C",data:[E,h,g,x,m,f]}),a=u,l=p,o=m,i=f;break}case"A":{let u=Math.abs(c[0]),p=Math.abs(c[1]),m=c[2],f=c[3],E=c[4],h=c[5],g=c[6];u===0||p===0?(t.push({key:"C",data:[o,i,h,g,h,g]}),o=h,i=g):(o!==h||i!==g)&&(Ds(o,i,h,g,u,p,m,f,E).forEach(function(y){t.push({key:"C",data:y})}),o=h,i=g);break}case"Z":t.push({key:"Z",data:[]}),o=r,i=s;break}n=d}return t}function Ac(e){return Math.PI*e/180}function Yn(e,t,n){let o=e*Math.cos(n)-t*Math.sin(n),i=e*Math.sin(n)+t*Math.cos(n);return[o,i]}function Ds(e,t,n,o,i,r,s,a,l,d){let c=Ac(s),u=[],p=0,m=0,f=0,E=0;if(d)[p,m,f,E]=d;else{[e,t]=Yn(e,t,-c),[n,o]=Yn(n,o,-c);let R=(e-n)/2,L=(t-o)/2,$=R*R/(i*i)+L*L/(r*r);$>1&&($=Math.sqrt($),i=$*i,r=$*r);let H=a===l?-1:1,te=i*i,S=r*r,Q=te*S-te*L*L-S*R*R,Z=te*L*L+S*R*R,ne=H*Math.sqrt(Math.abs(Q/Z));f=ne*i*L/r+(e+n)/2,E=ne*-r*R/i+(t+o)/2,p=Math.asin(parseFloat(((t-E)/r).toFixed(9))),m=Math.asin(parseFloat(((o-E)/r).toFixed(9))),e<f&&(p=Math.PI-p),n<f&&(m=Math.PI-m),p<0&&(p=Math.PI*2+p),m<0&&(m=Math.PI*2+m),l&&p>m&&(p=p-Math.PI*2),!l&&m>p&&(m=m-Math.PI*2)}let h=m-p;if(Math.abs(h)>Math.PI*120/180){let R=m,L=n,$=o;l&&m>p?m=p+Math.PI*120/180*1:m=p+Math.PI*120/180*-1,n=f+i*Math.cos(m),o=E+r*Math.sin(m),u=Ds(n,o,L,$,i,r,s,0,l,[m,R,f,E])}h=m-p;let g=Math.cos(p),x=Math.sin(p),y=Math.cos(m),b=Math.sin(m),w=Math.tan(h/4),I=4/3*i*w,M=4/3*r*w,D=[e,t],T=[e+I*x,t-M*g],N=[n+I*b,o-M*y],C=[n,o];if(T[0]=2*D[0]-T[0],T[1]=2*D[1]-T[1],d)return[T,N,C].concat(u);{u=[T,N,C].concat(u);let R=[];for(let L=0;L<u.length;L+=3){let $=Yn(u[L][0],u[L][1],c),H=Yn(u[L+1][0],u[L+1][1],c),te=Yn(u[L+2][0],u[L+2][1],c);R.push([$[0],$[1],H[0],H[1],te[0],te[1]])}return R}}var Dc={randOffset:Cc,randOffsetWithRange:Gc,ellipse:Lc,doubleLineOps:Bc};function Hi(e,t,n,o,i){return{type:"path",ops:ht(e,t,n,o,i)}}function Xn(e,t,n){let o=(e||[]).length;if(o>2){let i=[];for(let r=0;r<o-1;r++)i.push(...ht(e[r][0],e[r][1],e[r+1][0],e[r+1][1],n));return t&&i.push(...ht(e[o-1][0],e[o-1][1],e[0][0],e[0][1],n)),{type:"path",ops:i}}else if(o===2)return Hi(e[0][0],e[0][1],e[1][0],e[1][1],n);return{type:"path",ops:[]}}function vc(e,t){return Xn(e,!0,t)}function Bs(e,t,n,o,i){let r=[[e,t],[e+n,t],[e+n,t+o],[e,t+o]];return vc(r,i)}function zi(e,t){let n=Ls(e,1*(1+t.roughness*.2),t);if(!t.disableMultiStroke){let o=Ls(e,1.5*(1+t.roughness*.22),kc(t));n=n.concat(o)}return{type:"path",ops:n}}function Lc(e,t,n,o,i){let r=_i(n,o,i);return Mo(e,t,i,r).opset}function _i(e,t,n){let o=Math.sqrt(Math.PI*2*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),i=Math.ceil(Math.max(n.curveStepCount,n.curveStepCount/Math.sqrt(200)*o)),r=Math.PI*2/i,s=Math.abs(e/2),a=Math.abs(t/2),l=1-n.curveFitting;return s+=k(s*l,n),a+=k(a*l,n),{increment:r,rx:s,ry:a}}function Mo(e,t,n,o){let[i,r]=Cs(o.increment,e,t,o.rx,o.ry,1,o.increment*Io(.1,Io(.4,1,n),n),n),s=So(i,null,n);if(!n.disableMultiStroke&&n.roughness!==0){let[a]=Cs(o.increment,e,t,o.rx,o.ry,1.5,0,n),l=So(a,null,n);s=s.concat(l)}return{estimatedPoints:r,opset:{type:"path",ops:s}}}function Yi(e,t,n,o,i,r,s,a,l){let d=e,c=t,u=Math.abs(n/2),p=Math.abs(o/2);u+=k(u*.01,l),p+=k(p*.01,l);let m=i,f=r;for(;m<0;)m+=Math.PI*2,f+=Math.PI*2;f-m>Math.PI*2&&(m=0,f=Math.PI*2);let E=Math.PI*2/l.curveStepCount,h=Math.min(E/2,(f-m)/2),g=Gs(h,d,c,u,p,m,f,1,l);if(!l.disableMultiStroke){let x=Gs(h,d,c,u,p,m,f,1.5,l);g.push(...x)}return s&&(a?g.push(...ht(d,c,d+u*Math.cos(m),c+p*Math.sin(m),l),...ht(d,c,d+u*Math.cos(f),c+p*Math.sin(f),l)):g.push({op:"lineTo",data:[d,c]},{op:"lineTo",data:[d+u*Math.cos(m),c+p*Math.sin(m)]})),{type:"path",ops:g}}function Ui(e,t){let n=Un(_n(In(e))),o=[],i=[0,0],r=[0,0];for(let{key:s,data:a}of n)switch(s){case"M":{r=[a[0],a[1]],i=[a[0],a[1]];break}case"L":o.push(...ht(r[0],r[1],a[0],a[1],t)),r=[a[0],a[1]];break;case"C":{let[l,d,c,u,p,m]=a;o.push(...Oc(l,d,c,u,p,m,r,t)),r=[p,m];break}case"Z":o.push(...ht(r[0],r[1],i[0],i[1],t)),r=[i[0],i[1]];break}return{type:"path",ops:o}}function To(e,t){let n=[];for(let o of e)if(o.length){let i=t.maxRandomnessOffset||0,r=o.length;if(r>2){n.push({op:"move",data:[o[0][0]+k(i,t),o[0][1]+k(i,t)]});for(let s=1;s<r;s++)n.push({op:"lineTo",data:[o[s][0]+k(i,t),o[s][1]+k(i,t)]})}}return{type:"fillPath",ops:n}}function cn(e,t){return Ts(t,Dc).fillPolygons(e,t)}function ks(e,t,n,o,i,r,s){let a=e,l=t,d=Math.abs(n/2),c=Math.abs(o/2);d+=k(d*.01,s),c+=k(c*.01,s);let u=i,p=r;for(;u<0;)u+=Math.PI*2,p+=Math.PI*2;p-u>Math.PI*2&&(u=0,p=Math.PI*2);let m=(p-u)/s.curveStepCount,f=[];for(let E=u;E<=p;E=E+m)f.push([a+d*Math.cos(E),l+c*Math.sin(E)]);return f.push([a+d*Math.cos(p),l+c*Math.sin(p)]),f.push([a,l]),cn([f],s)}function Cc(e,t){return k(e,t)}function Gc(e,t,n){return Io(e,t,n)}function Bc(e,t,n,o,i){return ht(e,t,n,o,i,!0)}function kc(e){let t=Object.assign({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function Os(e){return e.randomizer||(e.randomizer=new bo(e.seed||0)),e.randomizer.next()}function Io(e,t,n,o=1){return n.roughness*o*(Os(n)*(t-e)+e)}function k(e,t,n=1){return Io(-e,e,t,n)}function ht(e,t,n,o,i,r=!1){let s=r?i.disableMultiStrokeFill:i.disableMultiStroke,a=vs(e,t,n,o,i,!0,!1);if(s)return a;let l=vs(e,t,n,o,i,!0,!0);return a.concat(l)}function vs(e,t,n,o,i,r,s){let a=Math.pow(e-n,2)+Math.pow(t-o,2),l=Math.sqrt(a),d=1;l<200?d=1:l>500?d=.4:d=-.0016668*l+1.233334;let c=i.maxRandomnessOffset||0;c*c*100>a&&(c=l/10);let u=c/2,p=.2+Os(i)*.2,m=i.bowing*i.maxRandomnessOffset*(o-t)/200,f=i.bowing*i.maxRandomnessOffset*(e-n)/200;m=k(m,i,d),f=k(f,i,d);let E=[],h=()=>k(u,i,d),g=()=>k(c,i,d),x=i.preserveVertices;return r&&(s?E.push({op:"move",data:[e+(x?0:h()),t+(x?0:h())]}):E.push({op:"move",data:[e+(x?0:k(c,i,d)),t+(x?0:k(c,i,d))]})),s?E.push({op:"bcurveTo",data:[m+e+(n-e)*p+h(),f+t+(o-t)*p+h(),m+e+2*(n-e)*p+h(),f+t+2*(o-t)*p+h(),n+(x?0:h()),o+(x?0:h())]}):E.push({op:"bcurveTo",data:[m+e+(n-e)*p+g(),f+t+(o-t)*p+g(),m+e+2*(n-e)*p+g(),f+t+2*(o-t)*p+g(),n+(x?0:g()),o+(x?0:g())]}),E}function Ls(e,t,n){let o=[];o.push([e[0][0]+k(t,n),e[0][1]+k(t,n)]),o.push([e[0][0]+k(t,n),e[0][1]+k(t,n)]);for(let i=1;i<e.length;i++)o.push([e[i][0]+k(t,n),e[i][1]+k(t,n)]),i===e.length-1&&o.push([e[i][0]+k(t,n),e[i][1]+k(t,n)]);return So(o,null,n)}function So(e,t,n){let o=e.length,i=[];if(o>3){let r=[],s=1-n.curveTightness;i.push({op:"move",data:[e[1][0],e[1][1]]});for(let a=1;a+2<o;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]],i.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;i.push({op:"lineTo",data:[t[0]+k(a,n),t[1]+k(a,n)]})}}else o===3?(i.push({op:"move",data:[e[1][0],e[1][1]]}),i.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):o===2&&i.push(...ht(e[0][0],e[0][1],e[1][0],e[1][1],n));return i}function Cs(e,t,n,o,i,r,s,a){let l=a.roughness===0,d=[],c=[];if(l){e=e/4,c.push([t+o*Math.cos(-e),n+i*Math.sin(-e)]);for(let u=0;u<=Math.PI*2;u=u+e){let p=[t+o*Math.cos(u),n+i*Math.sin(u)];d.push(p),c.push(p)}c.push([t+o*Math.cos(0),n+i*Math.sin(0)]),c.push([t+o*Math.cos(e),n+i*Math.sin(e)])}else{let u=k(.5,a)-Math.PI/2;c.push([k(r,a)+t+.9*o*Math.cos(u-e),k(r,a)+n+.9*i*Math.sin(u-e)]);let p=Math.PI*2+u-.01;for(let m=u;m<p;m=m+e){let f=[k(r,a)+t+o*Math.cos(m),k(r,a)+n+i*Math.sin(m)];d.push(f),c.push(f)}c.push([k(r,a)+t+o*Math.cos(u+Math.PI*2+s*.5),k(r,a)+n+i*Math.sin(u+Math.PI*2+s*.5)]),c.push([k(r,a)+t+.98*o*Math.cos(u+s),k(r,a)+n+.98*i*Math.sin(u+s)]),c.push([k(r,a)+t+.9*o*Math.cos(u+s*.5),k(r,a)+n+.9*i*Math.sin(u+s*.5)])}return[c,d]}function Gs(e,t,n,o,i,r,s,a,l){let d=r+k(.1,l),c=[];c.push([k(a,l)+t+.9*o*Math.cos(d-e),k(a,l)+n+.9*i*Math.sin(d-e)]);for(let u=d;u<=s;u=u+e)c.push([k(a,l)+t+o*Math.cos(u),k(a,l)+n+i*Math.sin(u)]);return c.push([t+o*Math.cos(s),n+i*Math.sin(s)]),c.push([t+o*Math.cos(s),n+i*Math.sin(s)]),So(c,null,l)}function Oc(e,t,n,o,i,r,s,a){let l=[],d=[a.maxRandomnessOffset||1,(a.maxRandomnessOffset||1)+.3],c=[0,0],u=a.disableMultiStroke?1:2,p=a.preserveVertices;for(let m=0;m<u;m++)m===0?l.push({op:"move",data:[s[0],s[1]]}):l.push({op:"move",data:[s[0]+(p?0:k(d[0],a)),s[1]+(p?0:k(d[0],a))]}),c=p?[i,r]:[i+k(d[m],a),r+k(d[m],a)],l.push({op:"bcurveTo",data:[e+k(d[m],a),t+k(d[m],a),n+k(d[m],a),o+k(d[m],a),c[0],c[1]]});return l}P();function jn(e){return[...e]}function Rs(e,t=0){let n=e.length;if(n<3)throw new Error("A curve must have at least three points.");let o=[];if(n===3)o.push(jn(e[0]),jn(e[1]),jn(e[2]),jn(e[2]));else{let i=[];i.push(e[0],e[0]);for(let a=1;a<e.length;a++)i.push(e[a]),a===e.length-1&&i.push(e[a]);let r=[],s=1-t;o.push(jn(i[0]));for(let a=1;a+2<i.length;a++){let l=i[a];r[0]=[l[0],l[1]],r[1]=[l[0]+(s*i[a+1][0]-s*i[a-1][0])/6,l[1]+(s*i[a+1][1]-s*i[a-1][1])/6],r[2]=[i[a+1][0]+(s*i[a][0]-s*i[a+2][0])/6,i[a+1][1]+(s*i[a][1]-s*i[a+2][1])/6],r[3]=[i[a+1][0],i[a+1][1]],o.push(r[1],r[2],r[3])}}return o}P();function Rc(e,t){return Math.sqrt(Ao(e,t))}function Ao(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function Fc(e,t,n){let o=Ao(t,n);if(o===0)return Ao(e,t);let i=((e[0]-t[0])*(n[0]-t[0])+(e[1]-t[1])*(n[1]-t[1]))/o;return i=Math.max(0,Math.min(1,i)),Ao(e,un(t,n,i))}function un(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n]}function Nc(e,t){let n=e[t+0],o=e[t+1],i=e[t+2],r=e[t+3],s=3*o[0]-2*n[0]-r[0];s*=s;let a=3*o[1]-2*n[1]-r[1];a*=a;let l=3*i[0]-2*r[0]-n[0];l*=l;let d=3*i[1]-2*r[1]-n[1];return d*=d,s<l&&(s=l),a<d&&(a=d),s+a}function Xi(e,t,n,o){let i=o||[];if(Nc(e,t)<n){let r=e[t+0];i.length?Rc(i[i.length-1],r)>1&&i.push(r):i.push(r),i.push(e[t+3])}else{let s=e[t+0],a=e[t+1],l=e[t+2],d=e[t+3],c=un(s,a,.5),u=un(a,l,.5),p=un(l,d,.5),m=un(c,u,.5),f=un(u,p,.5),E=un(m,f,.5);Xi([s,c,m,E],0,n,i),Xi([E,f,p,d],0,n,i)}return i}function Wn(e,t){return Do(e,0,e.length,t)}function Do(e,t,n,o,i){let r=i||[],s=e[t],a=e[n-1],l=0,d=1;for(let c=t+1;c<n-1;++c){let u=Fc(e[c],s,a);u>l&&(l=u,d=c)}return Math.sqrt(l)>o?(Do(e,t,d+1,o,r),Do(e,d,n,o,r)):(r.length||r.push(s),r.push(a)),r}function Et(e,t=.15,n){let o=[],i=(e.length-1)/3;for(let r=0;r<i;r++){let s=r*3;Xi(e,s,t,o)}return n&&n>0?Do(o,0,o.length,n):o}P();function Fs(e,t,n){let o=In(e),i=Un(_n(o)),r=[],s=[],a=[0,0],l=[],d=()=>{l.length>=4&&s.push(...Et(l,t)),l=[]},c=()=>{d(),s.length&&(r.push(s),s=[])};for(let{key:p,data:m}of i)switch(p){case"M":c(),a=[m[0],m[1]],s.push(a);break;case"L":d(),s.push([m[0],m[1]]);break;case"C":if(!l.length){let f=s.length?s[s.length-1]:a;l.push([f[0],f[1]])}l.push([m[0],m[1]]),l.push([m[2],m[3]]),l.push([m[4],m[5]]);break;case"Z":d(),s.push([a[0],a[1]]);break}if(c(),!n)return r;let u=[];for(let p of r){let m=Wn(p,n);m.length&&u.push(m)}return u}var He="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 As()}_o(t){return t?Object.assign({},this.defaultOptions,t):this.defaultOptions}_d(t,n,o){return{shape:t,sets:n||[],options:o||this.defaultOptions}}line(t,n,o,i,r){let s=this._o(r);return this._d("line",[Hi(t,n,o,i,s)],s)}rectangle(t,n,o,i,r){let s=this._o(r),a=[],l=Bs(t,n,o,i,s);if(s.fill){let d=[[t,n],[t+o,n],[t+o,n+i],[t,n+i]];s.fillStyle==="solid"?a.push(To([d],s)):a.push(cn([d],s))}return s.stroke!==He&&a.push(l),this._d("rectangle",a,s)}ellipse(t,n,o,i,r){let s=this._o(r),a=[],l=_i(o,i,s),d=Mo(t,n,s,l);if(s.fill)if(s.fillStyle==="solid"){let c=Mo(t,n,s,l).opset;c.type="fillPath",a.push(c)}else a.push(cn([d.estimatedPoints],s));return s.stroke!==He&&a.push(d.opset),this._d("ellipse",a,s)}circle(t,n,o,i){let r=this.ellipse(t,n,o,o,i);return r.shape="circle",r}linearPath(t,n){let o=this._o(n);return this._d("linearPath",[Xn(t,!1,o)],o)}arc(t,n,o,i,r,s,a=!1,l){let d=this._o(l),c=[],u=Yi(t,n,o,i,r,s,a,!0,d);if(a&&d.fill)if(d.fillStyle==="solid"){let p=Object.assign({},d);p.disableMultiStroke=!0;let m=Yi(t,n,o,i,r,s,!0,!1,p);m.type="fillPath",c.push(m)}else c.push(ks(t,n,o,i,r,s,d));return d.stroke!==He&&c.push(u),this._d("arc",c,d)}curve(t,n){let o=this._o(n),i=[],r=zi(t,o);if(o.fill&&o.fill!==He&&t.length>=3)if(o.fillStyle==="solid"){let s=zi(t,Object.assign(Object.assign({},o),{disableMultiStroke:!0,roughness:o.roughness?o.roughness+o.fillShapeRoughnessGain:0}));i.push({type:"fillPath",ops:this._mergedShape(s.ops)})}else{let s=Rs(t),a=Et(s,10,(1+o.roughness)/2);i.push(cn([a],o))}return o.stroke!==He&&i.push(r),this._d("curve",i,o)}polygon(t,n){let o=this._o(n),i=[],r=Xn(t,!0,o);return o.fill&&(o.fillStyle==="solid"?i.push(To([t],o)):i.push(cn([t],o))),o.stroke!==He&&i.push(r),this._d("polygon",i,o)}path(t,n){let o=this._o(n),i=[];if(!t)return this._d("path",i,o);t=(t||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");let r=o.fill&&o.fill!=="transparent"&&o.fill!==He,s=o.stroke!==He,a=!!(o.simplification&&o.simplification<1),l=a?4-4*(o.simplification||1):(1+o.roughness)/2,d=Fs(t,1,l),c=Ui(t,o);if(r)if(o.fillStyle==="solid")if(d.length===1){let u=Ui(t,Object.assign(Object.assign({},o),{disableMultiStroke:!0,roughness:o.roughness?o.roughness+o.fillShapeRoughnessGain:0}));i.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else i.push(To(d,o));else i.push(cn(d,o));return s&&(a?d.forEach(u=>{i.push(Xn(u,!1,o))}):i.push(c)),this._d("path",i,o)}opsToPath(t,n){let o="";for(let i of t.ops){let r=typeof n=="number"&&n>=0?i.data.map(s=>+s.toFixed(n)):i.data;switch(i.op){case"move":o+=`M${r[0]} ${r[1]} `;break;case"bcurveTo":o+=`C${r[0]} ${r[1]}, ${r[2]} ${r[3]}, ${r[4]} ${r[5]} `;break;case"lineTo":o+=`L${r[0]} ${r[1]} `;break}}return o.trim()}toPaths(t){let n=t.sets||[],o=t.options||this.defaultOptions,i=[];for(let r of n){let s=null;switch(r.type){case"path":s={d:this.opsToPath(r),stroke:o.stroke,strokeWidth:o.strokeWidth,fill:He};break;case"fillPath":s={d:this.opsToPath(r),stroke:He,strokeWidth:0,fill:o.fill||He};break;case"fillSketch":s=this.fillSketch(r,o);break}s&&i.push(s)}return i}fillSketch(t,n){let o=n.fillWeight;return o<0&&(o=n.strokeWidth/2),{d:this.opsToPath(t),stroke:n.fill||He,strokeWidth:o,fill:He}}_mergedShape(t){return t.filter((n,o)=>o===0?!0:n.op!=="move")}};var vo=class{constructor(t,n){this.canvas=t,this.ctx=this.canvas.getContext("2d"),this.gen=new je(n)}draw(t){let n=t.sets||[],o=t.options||this.getDefaultOptions(),i=this.ctx,r=t.options.fixedDecimalPlaceDigits;for(let s of n)switch(s.type){case"path":i.save(),i.strokeStyle=o.stroke==="none"?"transparent":o.stroke,i.lineWidth=o.strokeWidth,o.strokeLineDash&&i.setLineDash(o.strokeLineDash),o.strokeLineDashOffset&&(i.lineDashOffset=o.strokeLineDashOffset),this._drawToContext(i,s,r),i.restore();break;case"fillPath":{i.save(),i.fillStyle=o.fill||"";let a=t.shape==="curve"||t.shape==="polygon"||t.shape==="path"?"evenodd":"nonzero";this._drawToContext(i,s,r,a),i.restore();break}case"fillSketch":this.fillSketch(i,s,o);break}}fillSketch(t,n,o){let i=o.fillWeight;i<0&&(i=o.strokeWidth/2),t.save(),o.fillLineDash&&t.setLineDash(o.fillLineDash),o.fillLineDashOffset&&(t.lineDashOffset=o.fillLineDashOffset),t.strokeStyle=o.fill||"",t.lineWidth=i,this._drawToContext(t,n,o.fixedDecimalPlaceDigits),t.restore()}_drawToContext(t,n,o,i="nonzero"){t.beginPath();for(let r of n.ops){let s=typeof o=="number"&&o>=0?r.data.map(a=>+a.toFixed(o)):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(i):t.stroke()}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}line(t,n,o,i,r){let s=this.gen.line(t,n,o,i,r);return this.draw(s),s}rectangle(t,n,o,i,r){let s=this.gen.rectangle(t,n,o,i,r);return this.draw(s),s}ellipse(t,n,o,i,r){let s=this.gen.ellipse(t,n,o,i,r);return this.draw(s),s}circle(t,n,o,i){let r=this.gen.circle(t,n,o,i);return this.draw(r),r}linearPath(t,n){let o=this.gen.linearPath(t,n);return this.draw(o),o}polygon(t,n){let o=this.gen.polygon(t,n);return this.draw(o),o}arc(t,n,o,i,r,s,a=!1,l){let d=this.gen.arc(t,n,o,i,r,s,a,l);return this.draw(d),d}curve(t,n){let o=this.gen.curve(t,n);return this.draw(o),o}path(t,n){let o=this.gen.path(t,n);return this.draw(o),o}};P();P();var Vn="http://www.w3.org/2000/svg";var Lo=class{constructor(t,n){this.svg=t,this.gen=new je(n)}draw(t){let n=t.sets||[],o=t.options||this.getDefaultOptions(),i=this.svg.ownerDocument||window.document,r=i.createElementNS(Vn,"g"),s=t.options.fixedDecimalPlaceDigits;for(let a of n){let l=null;switch(a.type){case"path":{l=i.createElementNS(Vn,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke",o.stroke),l.setAttribute("stroke-width",o.strokeWidth+""),l.setAttribute("fill","none"),o.strokeLineDash&&l.setAttribute("stroke-dasharray",o.strokeLineDash.join(" ").trim()),o.strokeLineDashOffset&&l.setAttribute("stroke-dashoffset",`${o.strokeLineDashOffset}`);break}case"fillPath":{l=i.createElementNS(Vn,"path"),l.setAttribute("d",this.opsToPath(a,s)),l.setAttribute("stroke","none"),l.setAttribute("stroke-width","0"),l.setAttribute("fill",o.fill||""),(t.shape==="curve"||t.shape==="polygon")&&l.setAttribute("fill-rule","evenodd");break}case"fillSketch":{l=this.fillSketch(i,a,o);break}}l&&r.appendChild(l)}return r}fillSketch(t,n,o){let i=o.fillWeight;i<0&&(i=o.strokeWidth/2);let r=t.createElementNS(Vn,"path");return r.setAttribute("d",this.opsToPath(n,o.fixedDecimalPlaceDigits)),r.setAttribute("stroke",o.fill||""),r.setAttribute("stroke-width",i+""),r.setAttribute("fill","none"),o.fillLineDash&&r.setAttribute("stroke-dasharray",o.fillLineDash.join(" ").trim()),o.fillLineDashOffset&&r.setAttribute("stroke-dashoffset",`${o.fillLineDashOffset}`),r}get generator(){return this.gen}getDefaultOptions(){return this.gen.defaultOptions}opsToPath(t,n){return this.gen.opsToPath(t,n)}line(t,n,o,i,r){let s=this.gen.line(t,n,o,i,r);return this.draw(s)}rectangle(t,n,o,i,r){let s=this.gen.rectangle(t,n,o,i,r);return this.draw(s)}ellipse(t,n,o,i,r){let s=this.gen.ellipse(t,n,o,i,r);return this.draw(s)}circle(t,n,o,i){let r=this.gen.circle(t,n,o,i);return this.draw(r)}linearPath(t,n){let o=this.gen.linearPath(t,n);return this.draw(o)}polygon(t,n){let o=this.gen.polygon(t,n);return this.draw(o)}arc(t,n,o,i,r,s,a=!1,l){let d=this.gen.arc(t,n,o,i,r,s,a,l);return this.draw(d)}curve(t,n){let o=this.gen.curve(t,n);return this.draw(o)}path(t,n){let o=this.gen.path(t,n);return this.draw(o)}};var pn={canvas(e,t){return new vo(e,t)},svg(e,t){return new Lo(e,t)},generator(e){return new je(e)},newSeed(){return je.newSeed()}};import{arrayToMap as Kl,invariant as jr,rescalePoints as Wl,sizeOf as pf}from"@excalidraw/common";import{degreesToRadians as Xr,lineSegment as Ee,pointDistance as mf,pointFrom as v,pointFromArray as Ql,pointRotateRads as se}from"@excalidraw/math";P();import{invariant as Hc}from"@excalidraw/common";import{curve as zc,lineSegment as _c,pointFrom as le,pointDistance as sx,pointFromArray as Yc,pointFromVector as Uc,pointRotateRads as qe,polygon as Ns,polygonFromPoints as ji,PRECISION as ax,segmentsIntersectAt as lx,vector as Xc,vectorAdd as jc,vectorFromPoint as Wc,vectorScale as dx}from"@excalidraw/math";import{getElementAbsoluteCoords as ux}from"@excalidraw/element";var Hs=e=>{let{angle:t,width:n,height:o,x:i,y:r}=e,s=i+n/2,a=r+o/2,l=le(s,a),d;return e.type==="diamond"?d=Ns(qe(le(s,r),l,t),qe(le(i+n,a),l,t),qe(le(s,r+o),l,t),qe(le(i,a),l,t)):d=Ns(qe(le(i,r),l,t),qe(le(i+n,r),l,t),qe(le(i+n,r+o),l,t),qe(le(i,r+o),l,t)),{type:"polygon",data:d}};var zs=e=>{let{width:t,height:n,angle:o,x:i,y:r}=e;return{type:"ellipse",data:{center:le(i+t/2,r+n/2),angle:o,halfWidth:t/2,halfHeight:n/2}}},gt=e=>{if(!e)return[];for(let t of e.sets)if(t.type==="path")return t.ops;return e.sets[0].ops},_s=(e,t=le(0,0),n,o)=>{let i=l=>qe(le(l[0]+t[0],l[1]+t[1]),o,n),r=gt(e),s=[],a=le(0,0);for(let l of r){if(l.op==="move"){let d=Yc(l.data);Hc(d!=null,"Ops data is not a point"),a=i(d)}if(l.op==="bcurveTo"){let d=i(le(l.data[0],l.data[1])),c=i(le(l.data[2],l.data[3])),u=i(le(l.data[4],l.data[5]));s.push(zc(a,d,c,u)),a=u}}return{type:"polycurve",data:s}},Vc=e=>{let t=e[0],n=[];for(let o=1;o<e.length;o++){let i=e[o];n.push(_c(t,i)),t=i}return n},Ys=(e,t,n=!1)=>{let o=r=>qe(Uc(jc(Wc(r),Xc(e.x,e.y))),t,e.angle),i=Vc(e.points.map(r=>o(r)));return n?{type:"polygon",data:ji(i.flat())}:{type:"polyline",data:i}},Us=(e,t,n=le(0,0),o,i)=>{let r=c=>qe(le(c[0]+n[0],c[1]+n[1]),i,o);if(e.roundness===null)return{type:"polygon",data:ji(e.points.map(c=>r(c)))};let s=gt(t),a=[],l=!1;for(let c of s)c.op==="move"?(l=!l,l&&a.push(le(c.data[0],c.data[1]))):c.op==="bcurveTo"?l&&(a.push(le(c.data[0],c.data[1])),a.push(le(c.data[2],c.data[3])),a.push(le(c.data[4],c.data[5]))):c.op==="lineTo"&&l&&a.push(le(c.data[0],c.data[1]));let d=Et(a,10,5).map(c=>r(c));return{type:"polygon",data:ji(d)}};P();import{pointFrom as de,pointDistance as zl,pointRotateRads as Gt}from"@excalidraw/math";import{ROUGHNESS as rf,isTransparent as lo,assertNever as sf,COLOR_PALETTE as af,LINE_POLYGON_POINT_MERGE_DISTANCE as lf}from"@excalidraw/common";P();P();function Xs(e,t,n,o=i=>i){return e*o(.5-t*(.5-n))}function $c(e){return[-e[0],-e[1]]}function Qe(e,t){return[e[0]+t[0],e[1]+t[1]]}function We(e,t){return[e[0]-t[0],e[1]-t[1]]}function Ke(e,t){return[e[0]*t,e[1]*t]}function Zc(e,t){return[e[0]/t,e[1]/t]}function $n(e){return[e[1],-e[0]]}function js(e,t){return e[0]*t[0]+e[1]*t[1]}function qc(e,t){return e[0]===t[0]&&e[1]===t[1]}function Kc(e){return Math.hypot(e[0],e[1])}function Qc(e){return e[0]*e[0]+e[1]*e[1]}function Ws(e,t){return Qc(We(e,t))}function Zs(e){return Zc(e,Kc(e))}function Jc(e,t){return Math.hypot(e[1]-t[1],e[0]-t[0])}function Zn(e,t,n){let o=Math.sin(n),i=Math.cos(n),r=e[0]-t[0],s=e[1]-t[1],a=r*i-s*o,l=r*o+s*i;return[a+t[0],l+t[1]]}function Wi(e,t,n){return Qe(e,Ke(We(t,e),n))}function Vs(e,t,n){return Qe(e,Ke(t,n))}var{min:Sn,PI:eu}=Math,$s=.275,qn=eu+1e-4;function tu(e,t={}){let{size:n=16,smoothing:o=.5,thinning:i=.5,simulatePressure:r=!0,easing:s=S=>S,start:a={},end:l={},last:d=!1}=t,{cap:c=!0,easing:u=S=>S*(2-S)}=a,{cap:p=!0,easing:m=S=>--S*S*S+1}=l;if(e.length===0||n<=0)return[];let f=e[e.length-1].runningLength,E=a.taper===!1?0:a.taper===!0?Math.max(n,f):a.taper,h=l.taper===!1?0:l.taper===!0?Math.max(n,f):l.taper,g=Math.pow(n*o,2),x=[],y=[],b=e.slice(0,10).reduce((S,Q)=>{let Z=Q.pressure;if(r){let ne=Sn(1,Q.distance/n),an=Sn(1,1-ne);Z=Sn(1,S+(an-S)*(ne*$s))}return(S+Z)/2},e[0].pressure),w=Xs(n,i,e[e.length-1].pressure,s),I,M=e[0].vector,D=e[0].point,T=D,N=D,C=T,R=!1;for(let S=0;S<e.length;S++){let{pressure:Q}=e[S],{point:Z,vector:ne,distance:an,runningLength:it}=e[S];if(S<e.length-1&&f-it<3)continue;if(i){if(r){let xe=Sn(1,an/n),dn=Sn(1,1-xe);Q=Sn(1,b+(dn-b)*(xe*$s))}w=Xs(n,i,Q,s)}else w=n/2;I===void 0&&(I=w);let Pn=it<E?u(it/E):1,Oi=f-it<h?m((f-it)/h):1;w=Math.max(.01,w*Math.min(Pn,Oi));let fo=(S<e.length-1?e[S+1]:e[S]).vector,zn=S<e.length-1?js(ne,fo):1,Ri=js(ne,M)<0&&!R,ho=zn!==null&&zn<0;if(Ri||ho){let xe=Ke($n(M),w);for(let dn=1/13,De=0;De<=1;De+=dn)N=Zn(We(Z,xe),Z,qn*De),x.push(N),C=Zn(Qe(Z,xe),Z,qn*-De),y.push(C);D=N,T=C,ho&&(R=!0);continue}if(R=!1,S===e.length-1){let xe=Ke($n(ne),w);x.push(We(Z,xe)),y.push(Qe(Z,xe));continue}let ln=Ke($n(Wi(fo,ne,zn)),w);N=We(Z,ln),(S<=1||Ws(D,N)>g)&&(x.push(N),D=N),C=Qe(Z,ln),(S<=1||Ws(T,C)>g)&&(y.push(C),T=C),b=Q,M=ne}let L=e[0].point.slice(0,2),$=e.length>1?e[e.length-1].point.slice(0,2):Qe(e[0].point,[1,1]),H=[],te=[];if(e.length===1){if(!(E||h)||d){let S=Vs(L,Zs($n(We(L,$))),-(I||w)),Q=[];for(let Z=1/13,ne=Z;ne<=1;ne+=Z)Q.push(Zn(S,L,qn*2*ne));return Q}}else{if(!(E||h&&e.length===1))if(c)for(let Q=1/13,Z=Q;Z<=1;Z+=Q){let ne=Zn(y[0],L,qn*Z);H.push(ne)}else{let Q=We(x[0],y[0]),Z=Ke(Q,.5),ne=Ke(Q,.51);H.push(We(L,Z),We(L,ne),Qe(L,ne),Qe(L,Z))}let S=$n($c(e[e.length-1].vector));if(h||E&&e.length===1)te.push($);else if(p){let Q=Vs($,S,w);for(let Z=1/29,ne=Z;ne<1;ne+=Z)te.push(Zn(Q,$,qn*3*ne))}else te.push(Qe($,Ke(S,w)),Qe($,Ke(S,w*.99)),We($,Ke(S,w*.99)),We($,Ke(S,w)))}return x.concat(te,y.reverse(),H)}function nu(e,t={}){var n;let{streamline:o=.5,size:i=16,last:r=!1}=t;if(e.length===0)return[];let s=.15+(1-o)*.85,a=Array.isArray(e[0])?e:e.map(({x:m,y:f,pressure:E=.5})=>[m,f,E]);if(a.length===2){let m=a[1];a=a.slice(0,-1);for(let f=1;f<5;f++)a.push(Wi(a[0],m,f/4))}a.length===1&&(a=[...a,[...Qe(a[0],[1,1]),...a[0].slice(2)]]);let l=[{point:[a[0][0],a[0][1]],pressure:a[0][2]>=0?a[0][2]:.25,vector:[1,1],distance:0,runningLength:0}],d=!1,c=0,u=l[0],p=a.length-1;for(let m=1;m<a.length;m++){let f=r&&m===p?a[m].slice(0,2):Wi(u.point,a[m],s);if(qc(u.point,f))continue;let E=Jc(f,u.point);if(c+=E,m<p&&!d){if(c<i)continue;d=!0}u={point:f,pressure:a[m][2]>=0?a[m][2]:.5,vector:Zs(We(u.point,f)),distance:E,runningLength:c},l.push(u)}return l[0].vector=((n=l[1])==null?void 0:n.vector)||[0,0],l}function qs(e,t={}){return tu(nu(e,t),t)}import{isRightAngleRads as Ym,lineSegment as Dl,pointFrom as fi,pointRotateRads as zr}from"@excalidraw/math";import{BOUND_TEXT_PADDING as hi,DEFAULT_REDUCED_GLOBAL_ALPHA as Um,ELEMENT_READY_TO_ERASE_OPACITY as Xm,FRAME_STYLE as Ei,MIME_TYPES as Yr,THEME as Cl,distance as Jt,getFontString as jm,isRTL as Wm,getVerticalOffset as Vm,invariant as $m}from"@excalidraw/common";P();import{pointFrom as xt,pointCenter as ou,pointRotateRads as Ht,vectorFromPoint as Vi,vectorNormalize as Ks,vectorSubtract as Qs,vectorAdd as Co,vectorScale as Go,pointFromVector as Js,clamp as Ie,isCloseTo as ea}from"@excalidraw/math";var Se=10,xx=(e,t,n,o,i,r,s,a)=>{let{width:l,height:d}=$i(e),c=o/l,u=i/d,p=(e.crop?.x??0)/c,m=(e.crop?.y??0)/u,f=Ht(xt(r,s),he(e,t),-e.angle);r=f[0],s=f[1];let E=e.width,h=e.height,g=e.crop??{x:0,y:0,width:o,height:i,naturalWidth:o,naturalHeight:i},x=g.height,y=g.width,b=e.scale[0]===-1,w=e.scale[1]===-1,I=s-e.y,M=r-e.x;n.includes("n")&&(h=Ie(e.height-I,Se,w?d-m:e.height+m)),n.includes("s")&&(I=s-e.y-e.height,h=Ie(e.height+I,Se,w?e.height+m:d-m)),n.includes("e")&&(M=r-e.x-e.width,E=Ie(e.width+M,Se,b?e.width+p:l-p)),n.includes("w")&&(E=Ie(e.width-M,Se,b?l-p:e.width+p));let D=C=>{C.height=h*u,C.width=E*c};D(g);let T=(C,R)=>{D(R),C.includes("n")&&(w||(R.y+=x-R.height)),C.includes("s")&&w&&(R.y+=x-R.height),C.includes("e")&&b&&(R.x+=y-R.width),C.includes("w")&&(b||(R.x+=y-R.width))};switch(n){case"n":{if(a){let C=p+e.width/2,R=l-p-e.width/2,L=Math.min(C,R)*2;E=Ie(h*a,Se,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"s":{if(a){let C=p+e.width/2,R=l-p-e.width/2,L=Math.min(C,R)*2;E=Ie(h*a,Se,L),h=E/a}T(n,g),a&&(g.x+=(y-g.width)/2);break}case"w":{if(a){let C=m+e.height/2,R=d-m-e.height/2,L=Math.min(C,R)*2;h=Ie(E/a,Se,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"e":{if(a){let C=m+e.height/2,R=d-m-e.height/2,L=Math.min(C,R)*2;h=Ie(E/a,Se,L),E=h*a}T(n,g),a&&(g.y+=(x-g.height)/2);break}case"ne":{if(a)if(M>-I){let C=w?d-m:m+e.height;h=Ie(E/a,Se,C),E=h*a}else{let C=b?p+e.width:l-p;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"nw":{if(a)if(M<I){let C=w?d-m:m+e.height;h=Ie(E/a,Se,C),E=h*a}else{let C=b?l-p:p+e.width;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"se":{if(a)if(M>I){let C=w?m+e.height:d-m;h=Ie(E/a,Se,C),E=h*a}else{let C=b?p+e.width:l-p;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}case"sw":{if(a)if(-M>I){let C=w?m+e.height:d-m;h=Ie(E/a,Se,C),E=h*a}else{let C=b?l-p:p+e.width;E=Ie(h*a,Se,C),h=E/a}T(n,g);break}default:break}let N=iu(e,n,E,h,!!a);return ea(g.width,g.naturalWidth)&&ea(g.height,g.naturalHeight)&&(g=null),{x:N[0],y:N[1],width:E,height:h,crop:g}},iu=(e,t,n,o,i)=>{let[r,s,a,l]=zt(e,e.width,e.height,!0),d=xt(r,s),c=xt(a,l),u=ou(d,c),[p,m,f,E]=zt(e,n,o,!0),h=f-p,g=E-m,x=[...d];if(["n","w","nw"].includes(t)&&(x=[c[0]-Math.abs(h),c[1]-Math.abs(g)]),t==="ne"){let D=[d[0],c[1]];x=[D[0],D[1]-Math.abs(g)]}if(t==="sw"){let D=[c[0],d[1]];x=[D[0]-Math.abs(h),D[1]]}i&&(["s","n"].includes(t)&&(x[0]=u[0]-h/2),["e","w"].includes(t)&&(x[1]=u[1]-g/2));let y=e.angle,b=Ht(x,u,y),w=[x[0]+Math.abs(h)/2,x[1]+Math.abs(g)/2],I=Ht(w,u,y);x=Ht(b,I,-y);let M=[...x];return M[0]+=e.x-p,M[1]+=e.y-m,M},ta=(e,t)=>{if(e.crop){let{width:n,height:o}=$i(e),[i,r,s,a,l,d]=Y(e,t),c=Vi(Ht(xt(i,r),xt(l,d),e.angle)),u=Vi(Ht(xt(s,r),xt(l,d),e.angle)),p=Ks(Qs(u,c)),m=Vi(Ht(xt(i,a),xt(l,d),e.angle)),f=Qs(m,c),E=Ks(f),{cropX:h,cropY:g}=ru(e.crop,e.scale),x=Co(Co(c,Go(p,-h*n/e.crop.naturalWidth)),Go(E,-g*o/e.crop.naturalHeight)),y=Js(Co(Co(x,Go(p,n/2)),Go(E,o/2))),b=Ht(Js(x),y,-e.angle);return{...e,x:b[0],y:b[1],width:n,height:o,crop:null}}return e},$i=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}},ru=(e,t)=>{let n=e.x,o=e.y,i=t[0]===-1,r=t[1]===-1;return i&&(n=e.naturalWidth-Math.abs(n)-e.width),r&&(o=e.naturalHeight-Math.abs(o)-e.height),{cropX:n,cropY:o}},wx=(e,t=!1)=>{let n=e.crop;if(!n)return null;let o=e.scale[0]===-1,i=e.scale[1]===-1,r=n.x,s=n.y;if(o&&(r=n.naturalWidth-n.width-n.x),i&&(s=n.naturalHeight-n.height-n.y),t)return{x:r,y:s};let{width:a,height:l}=$i(e);return{x:r/(n.naturalWidth/a),y:s/(n.naturalHeight/l)}};P();import{pointCenter as el,pointFrom as G,pointRotateRads as Te,pointsEqual as tl,pointDistance as Gn,vectorFromPoint as rm,curveLength as sm,curvePointAtLength as am}from"@excalidraw/math";import{DRAGGING_THRESHOLD as lm,KEYS as Bn,shouldRotateWithDiscreteAngle as nl,getGridPoint as ol,invariant as vt,tupleToCoors as Lr,viewportCoordsToSceneCoords as dm}from"@excalidraw/common";import{deconstructLinearOrFreeDrawElement as il,isPathALoop as cm}from"@excalidraw/element";P();import{KEYS as Bp,arrayToMap as Ua,isBindingFallthroughEnabled as oi,tupleToCoors as kp,invariant as Op,isDevEnv as Rp,isTestEnv as Fp}from"@excalidraw/common";import{lineSegment as Re,pointFrom as O,pointRotateRads as ae,vectorFromPoint as V,pointDistanceSq as Dt,clamp as Ha,pointDistance as ut,pointFromVector as xn,vectorScale as wn,vectorNormalize as Cn,vectorCross as Ye,pointsEqual as Np,lineSegmentIntersectionPoints as za,PRECISION as Hp}from"@excalidraw/math";P();import{isTransparent as Zu}from"@excalidraw/common";import{curveIntersectLineSegment as Ia,isPointWithinBounds as Xo,lineSegment as jo,lineSegmentIntersectionPoints as Sa,pointFrom as Mt,pointFromVector as qu,pointRotateRads as lt,pointsEqual as Ku,vectorFromPoint as Qu,vectorNormalize as Ju,vectorScale as ep}from"@excalidraw/math";import{ellipse as tp,ellipseSegmentInterceptPoints as np}from"@excalidraw/math/ellipse";P();import{DEFAULT_ADAPTIVE_RADIUS as su,DEFAULT_PROPORTIONAL_RADIUS as Zi,LINE_CONFIRM_THRESHOLD as au,ROUNDNESS as qi}from"@excalidraw/common";import{curve as wt,curveCatmullRomCubicApproxPoints as na,curveOffsetPoints as oa,lineSegment as ze,pointDistance as lu,pointFrom as X,pointFromArray as du,rectangle as cu}from"@excalidraw/math";var Kn=new WeakMap,Ki=(e,t)=>{let n=Kn.get(e);if(!n)return;let{version:o,shapes:i}=n;if(o!==e.version){Kn.delete(e);return}return i.get(t)},Qi=(e,t,n)=>{let o=Kn.get(e);if(!o){Kn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}let{version:i,shapes:r}=o;if(i!==e.version){Kn.set(e,{version:e.version,shapes:new Map([[n,t]])});return}r.set(n,t)};function Bo(e){let t=Ki(e,0);if(t)return t;let n=ia(e),o=[],i=[];for(let s=0;s<n.length;s+=1){let a=n[s],l=n[s-1]&&du(n[s-1].data.slice(-2));switch(a.op){case"move":continue;case"lineTo":if(!l)throw new Error("prevPoint is undefined");o.push(ze(X(e.x+l[0],e.y+l[1]),X(e.x+a.data[0],e.y+a.data[1])));continue;case"bcurveTo":if(!l)throw new Error("prevPoint is undefined");i.push(wt(X(e.x+l[0],e.y+l[1]),X(e.x+a.data[0],e.y+a.data[1]),X(e.x+a.data[2],e.y+a.data[3]),X(e.x+a.data[4],e.y+a.data[5])));continue;default:console.error("Unknown op type",a.op)}}let r=[o,i];return Qi(e,r,0),r}function Mn(e,t=0){let n=Ki(e,t);if(n)return n;let o=yt(Math.min(e.width,e.height),e);o===0&&(o=.01);let i=cu(X(e.x,e.y),X(e.x+e.width,e.y+e.height)),r=ze(X(i[0][0]+o,i[0][1]),X(i[1][0]-o,i[0][1])),s=ze(X(i[1][0],i[0][1]+o),X(i[1][0],i[1][1]-o)),a=ze(X(i[0][0]+o,i[1][1]),X(i[1][0]-o,i[1][1])),l=ze(X(i[0][0],i[1][1]-o),X(i[0][0],i[0][1]+o)),d=[wt(l[1],X(l[1][0]+2/3*(i[0][0]-l[1][0]),l[1][1]+2/3*(i[0][1]-l[1][1])),X(r[0][0]+2/3*(i[0][0]-r[0][0]),r[0][1]+2/3*(i[0][1]-r[0][1])),r[0]),wt(r[1],X(r[1][0]+2/3*(i[1][0]-r[1][0]),r[1][1]+2/3*(i[0][1]-r[1][1])),X(s[0][0]+2/3*(i[1][0]-s[0][0]),s[0][1]+2/3*(i[0][1]-s[0][1])),s[0]),wt(s[1],X(s[1][0]+2/3*(i[1][0]-s[1][0]),s[1][1]+2/3*(i[1][1]-s[1][1])),X(a[1][0]+2/3*(i[1][0]-a[1][0]),a[1][1]+2/3*(i[1][1]-a[1][1])),a[1]),wt(a[0],X(a[0][0]+2/3*(i[0][0]-a[0][0]),a[0][1]+2/3*(i[1][1]-a[0][1])),X(l[0][0]+2/3*(i[0][0]-l[0][0]),l[0][1]+2/3*(i[1][1]-l[0][1])),l[0])],c=t>0?d.map(m=>na(oa(m,t))):[[d[0]],[d[1]],[d[2]],[d[3]]],p=[[ze(c[0][c[0].length-1][3],c[1][0][0]),ze(c[1][c[1].length-1][3],c[2][0][0]),ze(c[2][c[2].length-1][3],c[3][0][0]),ze(c[3][c[3].length-1][3],c[0][0][0])],c.flat()];return Qi(e,p,t),p}function Tn(e,t=0){let n=Ki(e,t);if(n)return n;let[o,i,r,s,a,l,d,c]=ko(e),u=e.roundness?yt(Math.abs(o-d),e):(o-d)*.01,p=e.roundness?yt(Math.abs(s-i),e):(s-i)*.01,[m,f,E,h]=[X(e.x+o,e.y+i),X(e.x+r,e.y+s),X(e.x+a,e.y+l),X(e.x+d,e.y+c)],g=[wt(X(f[0]-u,f[1]-p),f,f,X(f[0]-u,f[1]+p)),wt(X(E[0]+u,E[1]-p),E,E,X(E[0]-u,E[1]-p)),wt(X(h[0]+u,h[1]+p),h,h,X(h[0]+u,h[1]-p)),wt(X(m[0]-u,m[1]+p),m,m,X(m[0]+u,m[1]+p))],x=t>0?g.map(w=>na(oa(w,t))):[[g[0]],[g[1]],[g[2]],[g[3]]],b=[[ze(x[0][x[0].length-1][3],x[1][0][0]),ze(x[1][x[1].length-1][3],x[2][0][0]),ze(x[2][x[2].length-1][3],x[3][0][0]),ze(x[3][x[3].length-1][3],x[0][0][0])],x.flat()];return Qi(e,b,t),b}var mn=(e,t=1)=>{if(e.length>=3){let[n,o]=[e[0],e[e.length-1]];return lu(n,o)<=au/t}return!1},yt=(e,t)=>{if(t.roundness?.type===qi.PROPORTIONAL_RADIUS||t.roundness?.type===qi.LEGACY)return e*Zi;if(t.roundness?.type===qi.ADAPTIVE_RADIUS){let n=t.roundness?.value??su,o=n/Zi;return e<=o?e*Zi:n}return 0};P();import{ROUNDNESS as Qn,assertNever as uu}from"@excalidraw/common";import{pointsEqual as ra}from"@excalidraw/math";var _t=e=>!!e&&e.type==="image"&&!!e.fileId,we=e=>!!e&&e.type==="image",sa=e=>!!e&&e.type==="embeddable",Oo=e=>!!e&&e.type==="iframe",Ro=e=>!!e&&(e.type==="iframe"||e.type==="embeddable"),oe=e=>e!=null&&e.type==="text",Fo=e=>e!=null&&e.type==="frame",aa=e=>e!=null&&e.type==="magicframe",q=e=>e!=null&&(e.type==="frame"||e.type==="magicframe"),Me=e=>e!=null&&pu(e.type),pu=e=>e==="freedraw",j=e=>e!=null&&Ji(e.type),bt=e=>e!=null&&e.type==="line",_=e=>e!=null&&e.type==="arrow",B=e=>_(e)&&e.elbowed,Lx=e=>_(e)&&!e.elbowed,mu=e=>_(e)&&!e.elbowed&&!e.roundness,fu=e=>_(e)&&!e.elbowed&&e.roundness!==null,Ji=e=>e==="arrow"||e==="line",er=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&hu(e.type),hu=e=>e==="arrow",Le=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||e.type==="image"||e.type==="iframe"||e.type==="embeddable"||e.type==="frame"||e.type==="magicframe"||e.type==="text"&&!e.containerId),la=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),Cx=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"),Eu=(e,t=!0)=>e!=null&&(!e.locked||t===!0)&&(e.type==="rectangle"||e.type==="diamond"||e.type==="ellipse"||_(e)),Gx=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 uu(t,null),!1}},tr=e=>e.type==="rectangle"||e.type==="ellipse"||e.type==="diamond",st=e=>Eu(e)&&!!e.boundElements?.some(({type:t})=>t==="text"),ce=e=>e!==null&&"containerId"in e&&e.containerId!==null&&oe(e),Bx=e=>!!e.startBinding||!!e.endBinding,da=e=>e==="rectangle"||e==="embeddable"||e==="iframe"||e==="image",ca=e=>e==="line"||e==="arrow"||e==="diamond",kx=(e,t)=>!!((e===Qn.ADAPTIVE_RADIUS||e===Qn.LEGACY)&&da(t.type)||e===Qn.PROPORTIONAL_RADIUS&&ca(t.type)),Ox=e=>ca(e.type)?{type:Qn.PROPORTIONAL_RADIUS}:da(e.type)?{type:Qn.ADAPTIVE_RADIUS}:null,Jn=e=>Object.hasOwn(e,"fixedPoint")&&e.fixedPoint!=null,Rx=e=>Array.isArray(e)&&e.length===4&&typeof e[0]=="number"&&typeof e[1]=="number"&&typeof e[2]=="number"&&typeof e[3]=="number",Fx=e=>mu(e)?"sharpArrow":fu(e)?"curvedArrow":B(e)?"elbowArrow":"line",Nx=e=>e.length>3&&ra(e[0],e[e.length-1]),ua=e=>e.length>3||e.length===3&&!ra(e[0],e[e.length-1]);P();import{ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO as Ru,ARROW_LABEL_WIDTH_FRACTION as Fu,BOUND_TEXT_PADDING as at,DEFAULT_FONT_SIZE as Nu,TEXT_ALIGN as xa,VERTICAL_ALIGN as wa,getFontString as Uo,isProdEnv as Hu,invariant as zu}from"@excalidraw/common";import{pointFrom as ya,pointRotateRads as _u}from"@excalidraw/math";P();var eo={},pa=(e,t)=>{let n=eo[e]||(eo[e]={height:t});return n.height=t,n},ma=e=>{eo[e]&&delete eo[e]},_x=e=>eo[e]?.height??null;P();import{BOUND_TEXT_PADDING as Ho,DEFAULT_FONT_SIZE as gu,DEFAULT_FONT_FAMILY as xu,getFontString as wu,isTestEnv as yu,normalizeEOL as bu}from"@excalidraw/common";var Je=(e,t,n)=>{let o=e.split(`
2
2
  `).map(a=>a||" ").join(`
3
- `),o=parseFloat(t),r=xu(i,o,n);return{width:fa(i,t),height:r}},ua="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),pa=(e,t)=>{let n=wu(e);return n===0?Qe(ua.split("").join(`
4
- `),e,t).width+Fi*2:n+Fi*2},Ni=(e,t)=>Qe("",e,t).width+Fi*2,Nx=()=>fa(ua,hu({fontSize:mu,fontFamily:fu}))>0,tr=e=>gu(e).replace(/\t/g," "),nr=e=>tr(e).split(`
5
- `),zx=e=>{let t=nr(e.text).length;return e.height/t/e.fontSize},zi=(e,t)=>e*t,ma=(e,t)=>zi(e,t)+Fi*2,ki,Hx=e=>{ki=e},er=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 Eu()?r*10:r}},Ht=(e,t)=>(ki||(ki=new er),ki.getLineWidth(e,t)),fa=(e,t)=>{let n=nr(e),i=0;return n.forEach(o=>{i=Math.max(i,Ht(o,t))}),i},xu=(e,t,n)=>{let i=nr(e).length;return zi(t,n)*i},Sn=(()=>{let e={};return{calculate:(o,r)=>{let s=o.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=Ht(o,r);e[r][s]=a}return e[r][s]},getCache:o=>e[o],clearCache:o=>{e[o]=[]}}})(),_x=e=>{let t=Sn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.min(...n)},wu=e=>{let t=Sn.getCache(e);if(!t)return 0;let n=t.filter(i=>i!==void 0);return Math.max(...n)};P();import{isDevEnv as yu,isTestEnv as bu}from"@excalidraw/common";var ir,Hi,or,jx=e=>(ir||(ir=J.class(...Object.values(bt))),ir.test(e)),Pu=()=>{if(!Hi)try{Hi=Su()}catch{Hi=Iu()}return Hi},rr=()=>(or||(or=Mu()),or),je={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},bt={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},dn={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},Iu=()=>J.or(rr(),ue.On(je.HYPHEN,je.WHITESPACE,bt.CHAR)),Su=()=>J.or(rr(),ue.Before(je.WHITESPACE).Build(),ue.After(je.WHITESPACE,je.HYPHEN).Build(),ue.Before(bt.CHAR,bt.CURRENCY).NotPrecededBy(je.OPENING,bt.OPENING).Build(),ue.After(bt.CHAR).NotFollowedBy(je.HYPHEN,je.CLOSING,bt.CLOSING).Build(),ue.BeforeMany(bt.OPENING).NotPrecededBy(je.OPENING).Build(),ue.AfterMany(bt.CLOSING).NotFollowedBy(je.CLOSING).Build(),ue.AfterMany(je.CLOSING).FollowedBy(je.OPENING).Build()),Mu=()=>J.group(J.or(dn.FLAG,J.and(dn.MOST,dn.JOINER,J.build(`(?:${dn.ZWJ.source}(?:${dn.FLAG.source}|${dn.ANY.source}${dn.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)}})},Tu=e=>{let t=Pu();return e.normalize("NFC").split(t).filter(Boolean)},Pt=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return e;let i=[],o=e.split(`
6
- `);for(let r of o){if(Ht(r,t)<=n){i.push(r);continue}let a=Au(r,t,n);i.push(...a)}return i.join(`
7
- `)},Au=(e,t,n)=>{let i=[],r=Tu(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let c=l.value,d=s+c,u=Lu(c)?a+Sn.calculate(c,t):Ht(d,t);if(/\s/.test(c)||u<=n){s=d,a=u,l=r.next();continue}if(s)i.push(s.trimEnd()),s="",a=0;else{let p=Du(c,t,n),m=p[p.length-1]??"",f=p.slice(0,-1);i.push(...f),s=m,a=Ht(m,t),l=r.next()}}if(s){let c=vu(s,t,n);i.push(c)}return i},Du=(e,t,n)=>{if(rr().test(e))return[e];Cu(e);let i=[],o=Array.from(e),r="",s=0;for(let a of o){let l=Sn.calculate(a,t),c=s+l;if(c<=n){r=r+a,s=c;continue}r&&i.push(r),r=a,s=l}return r&&i.push(r),i},vu=(e,t,n)=>{if(!(Ht(e,t)>n))return e;let[,o,r]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],s=Ht(o,t);for(let a of Array.from(r)){let l=Sn.calculate(a,t),c=s+l;if(c>n)break;o=o+a,s=c}return o},Lu=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Cu=e=>{if((bu()||yu())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var ga=(e,t,n)=>{let i=n.getNonDeletedElementsMap(),o;Ru()||ku(!t||!_(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?_(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(o=t?Je(t,e):e.width,r.text=Pt(e.originalText,_i(e),o));let s=Qe(r.text,_i(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=ei(t,e),l=Je(t,e);if(!_(t)&&s.height>a){let p=sr(s.height,t.type);n.mutateElement(t,{height:p}),ca(t.id,p)}if(s.width>l){let p=sr(s.width,t.type);n.mutateElement(t,{width:p})}let c={...e,...r},{x:d,y:u}=xa(t,c,i);r.x=d,r.y=u}n.mutateElement(e,r)},un=(e,t,n,i=!1)=>{let o=t.getNonDeletedElementsMap();if(!It(e))return;da(e.id);let s=W(e,o);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,c=s.width,d=Je(e,s),u=ei(e,s),p=e.height;if(i||n!=="n"&&n!=="s"){a&&(a=Pt(s.originalText,_i(s),d));let m=Qe(a,_i(s),s.lineHeight);l=m.height,c=m.width}if(l>u){p=sr(l,e.type);let m=p-e.height,f=!_(e)&&(n==="ne"||n==="nw"||n==="n")?e.y-m:e.y;t.mutateElement(e,{height:p,y:f})}t.mutateElement(s,{text:a,width:c,height:l}),_(e)||t.mutateElement(s,xa(e,s,o))}},xa=(e,t,n)=>{if(_(e))return Y.getBoundTextElementPosition(e,t,n);let i=ar(e),o=ei(e,t),r=Je(e,t),s,a;return t.verticalAlign===Ea.TOP?a=i.y:t.verticalAlign===Ea.BOTTOM?a=i.y+(o-t.height):a=i.y+(o/2-t.height/2),t.textAlign===ha.LEFT?s=i.x:t.textAlign===ha.RIGHT?s=i.x+(r-t.width):s=i.x+(r/2-t.width/2),{x:s,y:a}},It=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,W=(e,t)=>{if(!e)return null;let n=It(e);return n&&t.get(n)||null},Ce=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,tw=(e,t,n)=>{if(!_(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(Y.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=Y.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let o=e.points.length/2-1,r=Y.getEditorMidPoints(e,n,t)[o];return r||(r=Y.getSegmentMidPoint(e,o+1)),{x:r[0],y:r[1]}},ar=e=>{let t=at,n=at;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},nw=(e,t)=>_(t)?0:t?t.angle:e.angle,iw=(e,t,n)=>{if(_(e))return Y.getBoundTextElementPosition(e,t,n)},ow=(e,t)=>e.some(n=>{if(de(n)){let i=Ce(n,t);return!_(i)}return!1}),rw=(e,t)=>e.some(n=>{if(de(n)){let i=Ce(n,t);return!_(i)}return ie(n)}),Fu=new Set(["rectangle","ellipse","diamond","arrow"]),sw=e=>Fu.has(e.type),sr=(e,t)=>{e=Math.ceil(e);let n=at*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},Je=(e,t)=>{let{width:n}=e;if(_(e)){let i=(t?.fontSize??Ou)*Bu;return Math.max(Gu*n,i)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-at*2:e.type==="diamond"?Math.round(n/2)-at*2:n-at*2},ei=(e,t)=>{let{height:n}=e;return _(e)?n-at*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-at*2:e.type==="diamond"?Math.round(n/2)-at*2:n-at*2},aw=(e,t=`
3
+ `),i=parseFloat(t),r=Pu(o,i,n);return{width:ga(o,t),height:r}},fa="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toLocaleUpperCase(),ha=(e,t)=>{let n=Iu(e);return n===0?Je(fa.split("").join(`
4
+ `),e,t).width+Ho*2:n+Ho*2},zo=(e,t)=>Je("",e,t).width+Ho*2,jx=()=>ga(fa,wu({fontSize:gu,fontFamily:xu}))>0,or=e=>bu(e).replace(/\t/g," "),ir=e=>or(e).split(`
5
+ `),Wx=e=>{let t=ir(e.text).length;return e.height/t/e.fontSize},_o=(e,t)=>e*t,Ea=(e,t)=>_o(e,t)+Ho*2,No,Vx=e=>{No=e},nr=class{canvas;constructor(){this.canvas=document.createElement("canvas")}getLineWidth(t,n){let o=this.canvas.getContext("2d");o.font=n;let r=o.measureText(t).width;return yu()?r*10:r}},Yt=(e,t)=>(No||(No=new nr),No.getLineWidth(e,t)),ga=(e,t)=>{let n=ir(e),o=0;return n.forEach(i=>{o=Math.max(o,Yt(i,t))}),o},Pu=(e,t,n)=>{let o=ir(e).length;return _o(t,n)*o},An=(()=>{let e={};return{calculate:(i,r)=>{let s=i.charCodeAt(0);if(e[r]||(e[r]=[]),!e[r][s]){let a=Yt(i,r);e[r][s]=a}return e[r][s]},getCache:i=>e[i],clearCache:i=>{e[i]=[]}}})(),$x=e=>{let t=An.getCache(e);if(!t)return 0;let n=t.filter(o=>o!==void 0);return Math.min(...n)},Iu=e=>{let t=An.getCache(e);if(!t)return 0;let n=t.filter(o=>o!==void 0);return Math.max(...n)};P();import{isDevEnv as Su,isTestEnv as Mu}from"@excalidraw/common";var rr,Yo,sr,Jx=e=>(rr||(rr=J.class(...Object.values(Pt))),rr.test(e)),Tu=()=>{if(!Yo)try{Yo=Du()}catch{Yo=Au()}return Yo},ar=()=>(sr||(sr=vu()),sr),Ve={WHITESPACE:/\s/u,HYPHEN:/-/u,OPENING:/<\(\[\{/u,CLOSING:/>\)\]\}.,:;!\?…\//u},Pt={CHAR:/\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}`'^〃〰〆#&*+-ー/\=|¦〒¬ ̄/u,OPENING:/([{〈《⦅「「『【〖〔〘〚<〝/u,CLOSING:/)]}〉》⦆」」』】〗〕〙〛>。.,、〟‥?!:;・〜〞/u,CURRENCY:/¥₩£¢$/u},fn={FLAG:/\p{RI}\p{RI}/u,JOINER:/(?:\p{Emoji_Modifier}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?/u,ZWJ:/\u200D/u,ANY:/[\p{Emoji}]/u,MOST:/[\p{Extended_Pictographic}\p{Emoji_Presentation}]/u},Au=()=>J.or(ar(),ue.On(Ve.HYPHEN,Ve.WHITESPACE,Pt.CHAR)),Du=()=>J.or(ar(),ue.Before(Ve.WHITESPACE).Build(),ue.After(Ve.WHITESPACE,Ve.HYPHEN).Build(),ue.Before(Pt.CHAR,Pt.CURRENCY).NotPrecededBy(Ve.OPENING,Pt.OPENING).Build(),ue.After(Pt.CHAR).NotFollowedBy(Ve.HYPHEN,Ve.CLOSING,Pt.CLOSING).Build(),ue.BeforeMany(Pt.OPENING).NotPrecededBy(Ve.OPENING).Build(),ue.AfterMany(Pt.CLOSING).NotFollowedBy(Ve.CLOSING).Build(),ue.AfterMany(Ve.CLOSING).FollowedBy(Ve.OPENING).Build()),vu=()=>J.group(J.or(fn.FLAG,J.and(fn.MOST,fn.JOINER,J.build(`(?:${fn.ZWJ.source}(?:${fn.FLAG.source}|${fn.ANY.source}${fn.JOINER.source}))*`)))),J={build:e=>new RegExp(e,"u"),join:(...e)=>e.map(t=>t.source).join(""),and:(...e)=>J.build(J.join(...e)),or:(...e)=>J.build(e.map(t=>t.source).join("|")),group:(...e)=>J.build(`(${J.join(...e)})`),class:(...e)=>J.build(`[${J.join(...e)}]`)},ue={On:(...e)=>{let t=J.join(...e);return J.build(`([${t}])`)},Before:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?=[${t}])`);return ue.Chain(n)},After:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<=[${t}])`);return ue.Chain(n)},BeforeMany:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<![${t}])(?=[${t}])`);return ue.Chain(n)},AfterMany:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<=[${t}])(?![${t}])`);return ue.Chain(n)},NotBefore:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?![${t}])`);return ue.Chain(n)},NotAfter:(...e)=>{let t=J.join(...e),n=()=>J.build(`(?<![${t}])`);return ue.Chain(n)},Chain:e=>({Build:e,PreceededBy:(...t)=>{let n=e(),o=ue.After(...t).Build(),i=()=>J.and(o,n);return ue.Chain(i)},FollowedBy:(...t)=>{let n=e(),o=ue.Before(...t).Build(),i=()=>J.and(n,o);return ue.Chain(i)},NotPrecededBy:(...t)=>{let n=e(),o=ue.NotAfter(...t).Build(),i=()=>J.and(o,n);return ue.Chain(i)},NotFollowedBy:(...t)=>{let n=e(),o=ue.NotBefore(...t).Build(),i=()=>J.and(n,o);return ue.Chain(i)}})},Lu=e=>{let t=Tu();return e.normalize("NFC").split(t).filter(Boolean)},It=(e,t,n)=>{if(!Number.isFinite(n)||n<0)return e;let o=[],i=e.split(`
6
+ `);for(let r of i){if(Yt(r,t)<=n){o.push(r);continue}let a=Cu(r,t,n);o.push(...a)}return o.join(`
7
+ `)},Cu=(e,t,n)=>{let o=[],r=Lu(e)[Symbol.iterator](),s="",a=0,l=r.next();for(;!l.done;){let d=l.value,c=s+d,u=ku(d)?a+An.calculate(d,t):Yt(c,t);if(/\s/.test(d)||u<=n){s=c,a=u,l=r.next();continue}if(s)o.push(s.trimEnd()),s="",a=0;else{let p=Gu(d,t,n),m=p[p.length-1]??"",f=p.slice(0,-1);o.push(...f),s=m,a=Yt(m,t),l=r.next()}}if(s){let d=Bu(s,t,n);o.push(d)}return o},Gu=(e,t,n)=>{if(ar().test(e))return[e];Ou(e);let o=[],i=Array.from(e),r="",s=0;for(let a of i){let l=An.calculate(a,t),d=s+l;if(d<=n){r=r+a,s=d;continue}r&&o.push(r),r=a,s=l}return r&&o.push(r),o},Bu=(e,t,n)=>{if(!(Yt(e,t)>n))return e;let[,i,r]=e.match(/^(.+?)(\s+)$/)??[e,e.trimEnd(),""],s=Yt(i,t);for(let a of Array.from(r)){let l=An.calculate(a,t),d=s+l;if(d>n)break;i=i+a,s=d}return i},ku=e=>e.codePointAt(0)!==void 0&&e.codePointAt(1)===void 0,Ou=e=>{if((Mu()||Su())&&/\s/.test(e))throw new Error("Word should not contain any whitespaces!")};var ba=(e,t,n)=>{let o=n.getNonDeletedElementsMap(),i;Hu()||zu(!t||!_(t)||e.angle===0,"text element angle must be 0 if bound to arrow container");let r={x:e.x,y:e.y,text:e.text,width:e.width,height:e.height,angle:t?_(t)?0:t.angle:e.angle};r.text=e.text,(t||!e.autoResize)&&(i=t?et(t,e):e.width,r.text=It(e.originalText,Uo(e),i));let s=Je(r.text,Uo(e),e.lineHeight);if(e.autoResize&&(r.width=s.width),r.height=s.height,t){let a=no(t,e),l=et(t,e);if(!_(t)&&s.height>a){let p=lr(s.height,t.type);n.mutateElement(t,{height:p}),pa(t.id,p)}if(s.width>l){let p=lr(s.width,t.type);n.mutateElement(t,{width:p})}let d={...e,...r},{x:c,y:u}=to(t,d,o);r.x=c,r.y=u}n.mutateElement(e,r)},hn=(e,t,n,o=!1)=>{let i=t.getNonDeletedElementsMap();if(!St(e))return;ma(e.id);let s=W(e,i);if(s&&s.text){if(!e)return;let a=s.text,l=s.height,d=s.width,c=et(e,s),u=no(e,s),p=e.height;if(o||n!=="n"&&n!=="s"){a&&(a=It(s.originalText,Uo(s),c));let m=Je(a,Uo(s),s.lineHeight);l=m.height,d=m.width}if(l>u){p=lr(l,e.type);let m=p-e.height,f=!_(e)&&(n==="ne"||n==="nw"||n==="n")?e.y-m:e.y;t.mutateElement(e,{height:p,y:f})}t.mutateElement(s,{text:a,width:d,height:l}),_(e)||t.mutateElement(s,to(e,s,i))}},to=(e,t,n)=>{if(_(e))return U.getBoundTextElementPosition(e,t,n);let o=dr(e),i=no(e,t),r=et(e,t),s,a;t.verticalAlign===wa.TOP?a=o.y:t.verticalAlign===wa.BOTTOM?a=o.y+(i-t.height):a=o.y+(i/2-t.height/2),t.textAlign===xa.LEFT?s=o.x:t.textAlign===xa.RIGHT?s=o.x+(r-t.width):s=o.x+(r/2-t.width/2);let l=e.angle??0;if(l!==0){let d=ya(o.x+r/2,o.y+i/2),c=ya(s+t.width/2,a+t.height/2),[u,p]=_u(c,d,l);return{x:u-t.width/2,y:p-t.height/2}}return{x:s,y:a}},St=e=>e?.boundElements?.length&&e?.boundElements?.find(t=>t.type==="text")?.id||null,W=(e,t)=>{if(!e)return null;let n=St(e);return n&&t.get(n)||null},Ce=(e,t)=>e&&e.containerId&&t.get(e.containerId)||null,dw=(e,t,n)=>{if(!_(e))return{x:e.x+e.width/2,y:e.y+e.height/2};if(U.getPointsGlobalCoordinates(e,n).length%2===1){let s=Math.floor(e.points.length/2),a=U.getPointGlobalCoordinates(e,e.points[s],n);return{x:a[0],y:a[1]}}let i=e.points.length/2-1,r=U.getEditorMidPoints(e,n,t)[i];return r||(r=U.getSegmentMidPoint(e,i+1)),{x:r[0],y:r[1]}},dr=e=>{let t=at,n=at;return e.type==="ellipse"&&(t+=e.width/2*(1-Math.sqrt(2)/2),n+=e.height/2*(1-Math.sqrt(2)/2)),e.type==="diamond"&&(t+=e.width/4,n+=e.height/4),{x:e.x+t,y:e.y+n}},cw=(e,t)=>_(t)?0:t?t.angle:e.angle,uw=(e,t,n)=>{if(_(e))return U.getBoundTextElementPosition(e,t,n)},pw=(e,t)=>e.some(n=>{if(ce(n)){let o=Ce(n,t);return!_(o)}return!1}),mw=(e,t)=>e.some(n=>{if(ce(n)){let o=Ce(n,t);return!_(o)}return oe(n)}),Yu=new Set(["rectangle","ellipse","diamond","arrow"]),fw=e=>Yu.has(e.type),lr=(e,t)=>{e=Math.ceil(e);let n=at*2;return t==="ellipse"?Math.round((e+n)/Math.sqrt(2)*2):t==="arrow"?e+n*8:t==="diamond"?2*(e+n):e+n},et=(e,t)=>{let{width:n}=e;if(_(e)){let o=(t?.fontSize??Nu)*Ru;return Math.max(Fu*n,o)}return e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-at*2:e.type==="diamond"?Math.round(n/2)-at*2:n-at*2},no=(e,t)=>{let{height:n}=e;return _(e)?n-at*8*2<=0?t.height:n:e.type==="ellipse"?Math.round(n/2*Math.sqrt(2))-at*2:e.type==="diamond"?Math.round(n/2)-at*2:n-at*2},hw=(e,t=`
8
8
 
9
- `)=>e.reduce((i,o)=>(ie(o)&&i.push(o.text),i),[]).join(t);P();import{curvePointDistance as lr,distanceToLineSegment as cr,pointRotateRads as dr}from"@excalidraw/math";import{ellipse as Nu,ellipseDistanceFromPoint as zu}from"@excalidraw/math/ellipse";var _t=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return Hu(e,t,n);case"diamond":return _u(e,t,n);case"ellipse":return Yu(e,t,n);case"line":case"arrow":case"freedraw":return Uu(e,n)}},Hu=(e,t,n)=>{let i=fe(e,t),o=dr(n,i,-e.angle),[r,s]=Pn(e);return Math.min(...r.map(a=>cr(o,a)),...s.map(a=>lr(a,o)).filter(a=>a!==null))},_u=(e,t,n)=>{let i=fe(e,t),o=dr(n,i,-e.angle),[r,s]=In(e);return Math.min(...r.map(a=>cr(o,a)),...s.map(a=>lr(a,o)).filter(a=>a!==null))},Yu=(e,t,n)=>{let i=fe(e,t);return zu(dr(n,i,-e.angle),Nu(i,e.width/2,e.height/2))},Uu=(e,t)=>{let[n,i]=Ci(e);return Math.min(...n.map(o=>cr(t,o)),...i.map(o=>lr(o,t)))};var Xi=e=>{if(e.type==="arrow")return!1;let t=!Xu(e.backgroundColor)||st(e)||Oi(e)||ie(e);return e.type==="line"?t&&ln(e.points):e.type==="freedraw"?t&&ln(e.points):t||xe(e)},Qu=({point:e,element:t,threshold:n,elementsMap:i,frameNameBound:o=null})=>{let r=o?Yi(St(o.x-n,o.y-n),e,St(o.x+o.width+n,o.y+o.height+n)):!1,s=he(t,i,!0);return!Yi(St(s[0]-n,s[1]-n),lt(e,ct(s),-t.angle),St(s[2]+n,s[3]+n))&&!r?!1:Xi(t)&&Sa(e,t,i)||wa(e,t,i,n)||r},Ju=(e,t,n,i=0)=>{let[o,r,s,a]=he(t,n);return o-=i,r-=i,s+=i,a+=i,Yi(St(o,r),e,St(s,a))},Tw=(e,t)=>!Qu(e)&&!ep(e.point,e.element,t)&&Ju(e.point,e.element,t),ep=(e,t,n)=>{let i=W(t,n);if(!i)return!1;let o=X(t)?{...i,...Y.getBoundTextElementPosition(t,i,n)}:i;return Sa(e,o,n)},Mn=(e,t,n,i=0,o=!1)=>{let r=[Math.min(n[0][0]-i,n[1][0]-i),Math.min(n[0][1]-i,n[1][1]-i),Math.max(n[0][0]+i,n[1][0]+i),Math.max(n[0][1]+i,n[1][1]+i)],s=he(e,t);if(!pn(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return np(e,t,n,i,o);case"diamond":return ip(e,t,n,i,o);case"ellipse":return op(e,t,n,i);case"line":case"freedraw":case"arrow":return tp(e,n,o)}},Pa=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=Wi(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!pn(a,l))continue;let c=ya(s,t);if(c.length>0){for(let d of c)n.push(lt(d,i,o));if(r)return n}}return n},Ia=(e,t,n,i,o,r=!1)=>{for(let s of e){let a=ba(s,t);if(a&&(n.push(lt(a,i,o)),r))return n}return n},tp=(e,t,n=!1)=>{let[i,o]=Ci(e),r=[];for(let s of i){let a=ba(s,t);if(a&&(r.push(a),n))return r}for(let s of o){let a=Wi(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!pn(a,l))continue;let c=ya(s,t);if(c.length>0&&(r.push(...c),n))return r}return r},np=(e,t,n,i=0,o=!1)=>{let r=fe(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Ui(s,a),[c,d]=Pn(e,i),u=[];return Ia(c,l,u,r,e.angle,o),o&&u.length>0||Pa(d,l,u,r,e.angle,o),u},ip=(e,t,n,i=0,o=!1)=>{let r=fe(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=Ui(s,a),[c,d]=In(e,i),u=[];return Ia(c,l,u,r,e.angle,o),o&&u.length>0||Pa(d,l,u,r,e.angle,o),u},op=(e,t,n,i=0)=>{let o=fe(e,t),r=lt(n[0],o,-e.angle),s=lt(n[1],o,-e.angle);return Ku(qu(o,e.width/2+i,e.height/2+i),Ui(r,s)).map(a=>lt(a,o,e.angle))},wa=(e,t,n,i=1)=>_t(t,n,e)<=i,Sa=(e,t,n)=>{if((X(t)||Se(t))&&!ln(t.points))return!1;let[i,o,r,s]=he(t,n);if(!Yi(St(i,o),e,St(r,s)))return!1;let a=St((i+r)/2,(o+s)/2),l=Wu(Zu($u(Vu(e,a,.1)),Math.max(t.width,t.height)*2),a),c=Ui(e,l);return Mn(t,n,c).filter((u,p,m)=>m.findIndex(f=>ju(f,u))===p).length%2===1};P();import{invariant as Ma,isDevEnv as rp,isTestEnv as sp}from"@excalidraw/common";import{pointFrom as Yt,pointFromVector as ji,pointRotateRads as Vi,pointScaleFromOrigin as $i,pointsEqual as ap,triangleIncludesPoint as ur,vectorCross as Be,vectorFromPoint as K,vectorScale as Zi}from"@excalidraw/math";var me=[1,0],we=[0,1],Oe=[-1,0],He=[0,-1],Mt=e=>{let[t,n]=e,i=Math.abs(t),o=Math.abs(n);return t>o?me:t<=-o?Oe:n>i?we:He},Ge=(e,t)=>Mt(K(e,t)),et=(e,t)=>Re(Ge(e,t)),pe=(e,t)=>e[0]===t[0]&&e[1]===t[1],Re=e=>pe(e,me)||pe(e,Oe),Bw=e=>!Re(e),lp=(e,t,n)=>{let i=ct(t);(rp()||sp())&&(Ma(e.width>0&&e.height>0,"Diamond element has no width or height"),Ma(!ap(i,n),"The point is too close to the element mid point to determine heading"));let o=.95,r=ji(Zi(K(Vi(Yt(e.x+e.width/2,e.y),i,e.angle),i),o),i),s=ji(Zi(K(Vi(Yt(e.x+e.width,e.y+e.height/2),i,e.angle),i),o),i),a=ji(Zi(K(Vi(Yt(e.x+e.width/2,e.y+e.height),i,e.angle),i),o),i),l=ji(Zi(K(Vi(Yt(e.x,e.y+e.height/2),i,e.angle),i),o),i);if(Be(K(n,r),K(r,s))<=0&&Be(K(n,r),K(r,l))>0)return Ge(r,i);if(Be(K(n,s),K(s,a))<=0&&Be(K(n,s),K(s,r))>0)return Ge(s,i);if(Be(K(n,a),K(a,l))<=0&&Be(K(n,a),K(a,s))>0)return Ge(a,i);if(Be(K(n,l),K(l,r))<=0&&Be(K(n,l),K(l,a))>0)return Ge(l,i);if(Be(K(n,i),K(r,i))<=0&&Be(K(n,i),K(s,i))>0){let d=e.width>e.height?r:s;return Ge(d,i)}else if(Be(K(n,i),K(s,i))<=0&&Be(K(n,i),K(a,i))>0){let d=e.width>e.height?a:s;return Ge(d,i)}else if(Be(K(n,i),K(a,i))<=0&&Be(K(n,i),K(l,i))>0){let d=e.width>e.height?a:l;return Ge(d,i)}let c=e.width>e.height?r:l;return Ge(c,i)},ti=(e,t,n)=>{let o=ct(t);if(e.type==="diamond")return lp(e,t,n);let r=$i(Yt(t[0],t[1]),o,2),s=$i(Yt(t[2],t[1]),o,2),a=$i(Yt(t[0],t[3]),o,2),l=$i(Yt(t[2],t[3]),o,2);return ur([r,s,o],n)?He:ur([s,l,o],n)?me:ur([l,a,o],n)?we:Oe},pr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Ap,randomInteger as Ir,getUpdatedTimestamp as Sr}from"@excalidraw/common";P();import{clamp as qi,pointDistance as hr,pointFrom as z,pointScaleFromOrigin as cp,pointsEqual as ii,pointTranslate as fr,vector as dt,vectorCross as Ki,vectorFromPoint as Er,vectorScale as dp}from"@excalidraw/math";import{BinaryHeap as up,invariant as Tn,isAnyTrue as pp,tupleToCoors as mp,getSizeFromPoints as Ta,isDevEnv as fp,arrayToMap as hp}from"@excalidraw/common";var gr=1,ee=40,Ep=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let i=[];e.points.map(s=>z(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return i.push(s);let c=Ge(s,l[a-1]),d=Ge(l[a-1],l[a-2]);if(pe(c,d)){let u=n?.findIndex(m=>m.index===a-1)??-1,p=n?.findIndex(m=>m.index===a)??-1;p!==-1&&(n[p].start=z(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),i.splice(-1,1),n.forEach(m=>{m.index>a-1&&(m.index-=1)})}return i.push(s)});let o=[];i.forEach((s,a,l)=>{if(a<3)return o.push(s);if(hr(l[a-2],l[a-1])<gr){let c=n?.findIndex(p=>p.index===a-2)??-1,d=n?.findIndex(p=>p.index===a-1)??-1;d!==-1&&n.splice(d,1),c!==-1&&n.splice(c,1),o.splice(-2,2),n.forEach(p=>{p.index>a-2&&(p.index-=2)});let u=et(s,l[a-1]);return o.push(z(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}o.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==o.length-1);return r.length===0?Tt(yr(br(wr(e,xr(e,t,o.map(s=>z(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(fp()&&Tn(Ga(o),"Invalid elbow points with fixed segments"),Tt(o,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},gp=(e,t,n)=>{let i=t.map(T=>T.index),r=(e.fixedSegments?.map(T=>T.index)??[]).findIndex(T=>!i.includes(T));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],c=e.x+(a?a.end[0]:0),d=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,p=l?null:e.endBinding,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y}=xr({x:c,y:d,startBinding:u,endBinding:p,startArrowhead:null,endArrowhead:null,points:e.points},n,[z(0,0),z(e.x+(l?.start[0]??e.points[e.points.length-1][0])-c,e.y+(l?.start[1]??e.points[e.points.length-1][1])-d)],{isDragging:!1}),{points:b}=Tt(yr(br(wr(e,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y})??[])),t,null,null),w=[];if(a)for(let T=0;T<a.index;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));if(b.forEach(T=>{w.push(z(e.x+(a?a.end[0]:0)+T[0],e.y+(a?a.end[1]:0)+T[1]))}),l)for(let T=l.index;T<e.points.length;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,M=t.map(T=>T.index>s?{...T,index:T.index-I+(b.length-1)}:T),D=w.flatMap((T,F)=>{let C=w[F-1],k=w[F+1];if(C&&k){let L=Ge(T,C),j=Ge(k,T);if(pe(L,j))return M.forEach(N=>{N.index>F&&(N.index-=1)}),[];if(pe(L,pr(j)))return M.forEach(N=>{N.index>F&&(N.index+=1)}),[T,T]}return[T]});return Tt(D,M,!1,!1)},xp=(e,t,n,i,o,r)=>{let s=t.map((w,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==w.index||(w.start[0]!==e.fixedSegments[I].start[0]&&w.end[0]!==e.fixedSegments[I].end[0])!=(w.start[1]!==e.fixedSegments[I].start[1]&&w.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,c=hr(t[s].start,t[s].end),d=c<ee+5;if(a===-1&&t[s].index===1&&o){let w=Re(n),M=(w?pe(n,me):pe(n,we))?d?c/2:ee:d?-c/2:-ee;t[s].start=z(t[s].start[0]+(w?M:0),t[s].start[1]+(w?0:M))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=Re(i),M=(w?pe(i,me):pe(i,we))?d?c/2:ee:d?-c/2:-ee;t[s].end=z(t[s].end[0]+(w?M:0),t[s].end[1]+(w?0:M))}let u=t.map(w=>({...w,start:z(e.x+w.start[0],e.y+w.start[1]),end:z(e.x+w.end[0],e.y+w.end[1])})),p=e.points.map((w,I)=>z(e.x+w[0],e.y+w[1])),m=u[s].index-1,f=u[s].index,E=u[s].start,h=u[s].end,g=p[m-1]&&!ii(p[m],p[m-1])?et(p[m-1],p[m]):void 0,x=p[f+1]&&!ii(p[f],p[f+1])?et(p[f+1],p[f]):void 0;if(g!==void 0){let w=g?1:0;p[m-1][w]=E[w]}if(p[m]=E,p[f]=h,x!==void 0){let w=x?1:0;p[f+1][w]=h[w]}let y=u.findIndex(w=>w.index===m);if(y!==-1){let w=et(u[y].end,u[y].start)?1:0;u[y].start[w]=E[w],u[y].end=E}let b=u.findIndex(w=>w.index===f+1);if(b!==-1){let w=et(u[b].end,u[b].start)?1:0;u[b].end[w]=h[w],u[b].start=h}if(a===-1&&m===0){let w=o?Re(n):et(p[1],p[0]);p.unshift(z(w?E[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:E[1])),o&&p.unshift(z(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=o?2:1}if(l===-1&&f===e.points.length-1){let w=Re(i);p.push(z(w?h[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:h[1])),r&&p.push(z(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return Tt(p,u.map(w=>({...w,start:z(w.start[0]-e.x,w.start[1]-e.y),end:z(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},wp=(e,t,n,i,o,r,s,a,l)=>{let c=e.startIsSpecial??null,d=e.endIsSpecial??null,u=t.map((h,g)=>g===0?z(e.x+h[0],e.y+h[1]):g===t.length-1?z(e.x+h[0],e.y+h[1]):z(e.x+e.points[g][0],e.y+e.points[g][1])),p=n.map(h=>({...h,start:z(e.x+(h.start[0]-t[0][0]),e.y+(h.start[1]-t[0][1])),end:z(e.x+(h.end[0]-t[0][0]),e.y+(h.end[1]-t[0][1]))})),m=[],f=2+(c?1:0),E=2+(d?1:0);for(;m.length+f<u.length-E;)m.push(u[m.length+f]);{let h=u[c?2:1],g=u[c?3:2],x=Re(i),y=Re(Mt(Er(h,g)));if(a&&x===y){let b=x?pe(i,me):pe(i,we);if(m.unshift(z(y?r[0]+(b?ee:-ee):g[0],y?g[1]:r[1]+(b?ee:-ee))),m.unshift(z(x?r[0]+(b?ee:-ee):r[0],x?r[1]:r[1]+(b?ee:-ee))),!c){c=!0;for(let w of p)w.index>1&&(w.index+=1)}}else if(m.unshift(z(y?r[0]:h[0],y?h[1]:r[1])),c){c=!1;for(let b of p)b.index>1&&(b.index-=1)}m.unshift(r)}{let h=u[u.length-(d?3:2)],g=u[u.length-(d?4:3)],x=Re(o),y=et(g,h);if(l&&x===y){let b=x?pe(o,me):pe(o,we);m.push(z(y?s[0]+(b?ee:-ee):g[0],y?g[1]:s[1]+(b?ee:-ee))),m.push(z(x?s[0]+(b?ee:-ee):s[0],x?s[1]:s[1]+(b?ee:-ee))),d||(d=!0)}else m.push(z(y?s[0]:h[0],y?h[1]:s[1])),d&&(d=!1)}return m.push(s),Tt(m,p.map(({index:h})=>({index:h,start:m[h-1],end:m[h]})).map(h=>({...h,start:z(h.start[0]-r[0],h.start[1]-r[1]),end:z(h.end[0]-r[0],h.end[1]-r[1])})),c,d)},Ut=1e6,Dn=(e,t,n,i)=>{if(e.points.length<2)return{points:n.points??e.points};A.PROD||(Tn(!n.points||n.points.length>=2,"Updated point array length must match the arrow point length, contain exactly the new start and end points or not be specified at all (i.e. you can't add new points between start and end manually to elbow arrows)"),Tn(!e.fixedSegments||e.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Tn(!n.fixedSegments||n.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Tn(e.points.slice(1).map((w,I)=>w[0]===e.points[I][0]||w[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Tn(n.fixedSegments?.find(w=>w.index===1&&ii(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&ii(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let o=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,c=typeof s<"u"?s:e.startBinding,d=typeof a<"u"?a:e.endBinding,u=c&&Ji(c.elementId,t),p=d&&Ji(d.elementId,t),m=Ga(r);if(c&&!u&&m||d&&!p&&m||t.size===0&&m||Object.keys(l).length===0&&(u?.id!==c?.elementId||p?.id!==d?.elementId))return Tt(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b}=xr({x:e.x,y:e.y,startBinding:c,endBinding:d,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,i);return t.size===0&&m?Tt(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?Ep(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,I)=>ii(w,e.points[I]??z(1/0,1/0)))&&m?{}:o.length===0?Tt(yr(br(wr(e,{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b})??[])),o,null,null):(e.fixedSegments?.length??0)>o.length?gp(e,o,t):n.points?n.points&&n.fixedSegments?n:wp(e,r,o,f,E,h,g,x,y):xp(e,o,f,E,x,y)},xr=(e,t,n,i)=>{let o=fr(n[0],dt(e.x,e.y)),r=fr(n[n.length-1],dt(e.x,e.y)),s=null,a=null;if(i?.isDragging){let w=Array.from(t.values());s=La(o,t,w,i?.zoom)||null,a=La(r,t,w,i?.zoom)||null}else s=e.startBinding&&Ji(e.startBinding.elementId,t)||null,a=e.endBinding&&Ji(e.endBinding.elementId,t)||null;let l=Da({...e,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,o,s,t,i?.isDragging),c=Da({...e,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,i?.isDragging),d=va(l,c,s,o,t),u=va(c,l,a,r,t),p=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],m=[c[0]-2,c[1]-2,c[0]+2,c[1]+2],f=s?Ve(s,t,Xt(d,e.startArrowhead?oe*6:oe*2,1)):p,E=a?Ve(a,t,Xt(u,e.endArrowhead?oe*6:oe*2,1)):m,h=An(l,a?Ve(a,t,Xt(u,ee,ee)):m)||An(c,s?Ve(s,t,Xt(d,ee,ee)):p),g=Ba(h?[p,m]:[f,E]),x=Pp(h?p:f,h?m:E,g,h?Xt(d,!s&&!a?0:ee,0):Xt(d,!s&&!a?0:ee-(e.startArrowhead?oe*6:oe*2),ee),h?Xt(u,!s&&!a?0:ee,0):Xt(u,!s&&!a?0:ee-(e.endArrowhead?oe*6:oe*2),ee),h,s&&Ve(s,t),a&&Ve(a,t)),y=Aa(x[0],d,l),b=Aa(x[1],u,c);return{dynamicAABBs:x,startDonglePosition:y,startGlobalPoint:l,startHeading:d,endDonglePosition:b,endGlobalPoint:c,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:h,startElementBounds:f,endElementBounds:E}},wr=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:i,startGlobalPoint:o,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:c,hoveredEndElement:d}=t,u=Ip(n,i||o,r,s||a,l,c),p=i&&Qi(i,u),m=s&&Qi(s,u),f=Qi(a,u);f&&d&&(f.closed=!0);let E=Qi(o,u);E&&e.startBinding&&(E.closed=!0);let h=p&&m&&(An(p.pos,n[1])||An(m.pos,n[0])),g=yp(p||E,m||f,u,r||me,l||me,h?[]:n);if(g){let x=g.map(y=>[y.pos[0],y.pos[1]]);return p&&x.unshift(o),m&&x.push(a),x}return null},Xt=(e,t,n)=>{switch(e){case He:return[t,n,n,n];case me:return[n,t,n,n];case we:return[n,n,t,n]}return[n,n,n,t]},yp=(e,t,n,i,o,r)=>{let s=mr(e.pos,t.pos),a=new up(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return bp(e,l);l.closed=!0;let c=Mp(l.addr,n);for(let d=0;d<4;d++){let u=c[d];if(!u||u.closed)continue;let p=cp(u.pos,l.pos,.5);if(pp(...r.map(b=>An(p,b))))continue;let m=Tp(d),f=l.parent?Mt(Er(l.pos,l.parent.pos)):i,E=pr(f);if(pe(E,m)||Ca(e.addr,u.addr)&&pe(m,i)||Ca(t.addr,u.addr)&&pe(m,o))continue;let g=f!==m,x=l.g+mr(u.pos,l.pos)+(g?Math.pow(s,3):0),y=u.visited;if(!y||x<u.g){let b=Sp(u,t,m,o);u.visited=!0,u.parent=l,u.h=mr(t.pos,u.pos)+b*Math.pow(s,2),u.g=x,u.f=u.g+u.h,y?a.rescoreElement(u):a.push(u)}}}return null},bp=(e,t)=>{let n=t,i=[];for(;n.parent;)i.unshift(n),n=n.parent;return i.unshift(e),i},mr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Pp=(e,t,n,i,o,r,s,a)=>{let l=s??e,c=a??t,[d,u,p,m]=i??[0,0,0,0],[f,E,h,g]=o??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+c[2])/2,e[0]-m):(l[0]+c[2])/2:e[0]>t[0]?e[0]-m:n[0]-m,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+c[3])/2,e[1]-d):(l[1]+c[3])/2:e[1]>t[1]?e[1]-d:n[1]-d,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+c[0])/2,e[2]+u):(l[2]+c[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]+c[1])/2,e[3]+p):(l[3]+c[1])/2:e[3]<t[3]?e[3]+p:n[3]+p],y=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((c[0]+l[2])/2,t[0]-g):(c[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((c[1]+l[3])/2,t[1]-f):(c[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((c[2]+l[0])/2,t[2]+E):(c[2]+l[0])/2:t[2]<e[2]?t[2]+E:n[2]+E,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((c[3]+l[1])/2,t[3]+h):(c[3]+l[1])/2:t[3]<e[3]?t[3]+h:n[3]+h],b=Ba([x,y]);if(!r&&x[2]-x[0]+y[2]-y[0]>b[2]-b[0]+1e-11&&x[3]-x[1]+y[3]-y[1]>b[3]-b[1]+1e-11){let[w,I]=[(y[0]+y[2])/2,(y[1]+y[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let M=x[2]+(y[0]-x[2])/2,D=y[3]+(x[1]-y[3])/2;return Ki(dt(e[2]-w,e[1]-I),dt(e[0]-w,e[3]-I))>0?[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}else if(e[2]<t[0]&&e[3]<t[1]){let M=x[2]+(y[0]-x[2])/2,D=x[3]+(y[1]-x[3])/2;return Ki(dt(e[0]-w,e[1]-I),dt(e[2]-w,e[3]-I))>0?[[x[0],x[1],x[2],D],[y[0],D,y[2],y[3]]]:[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let M=y[2]+(x[0]-y[2])/2,D=x[3]+(y[1]-x[3])/2;return Ki(dt(e[2]-w,e[1]-I),dt(e[0]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],x[1],x[2],D],[y[0],D,y[2],y[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let M=y[2]+(x[0]-y[2])/2,D=y[3]+(x[1]-y[3])/2;return Ki(dt(e[0]-w,e[1]-I),dt(e[2]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}}return[x,y]},Ip=(e,t,n,i,o,r)=>{let s=new Set,a=new Set;n===Oe||n===me?a.add(t[1]):s.add(t[0]),o===Oe||o===me?a.add(i[1]):s.add(i[0]),e.forEach(d=>{s.add(d[0]),s.add(d[2]),a.add(d[1]),a.add(d[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((d,u)=>d-u),c=Array.from(s).sort((d,u)=>d-u);return{row:l.length,col:c.length,data:l.flatMap((d,u)=>c.map((p,m)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[m,u],pos:[p,d]})))}},Aa=(e,t,n)=>{switch(t){case He:return z(n[0],e[1]);case me:return z(e[2],n[1]);case we:return z(n[0],e[3])}return z(e[0],n[1])},Sp=(e,t,n,i)=>{if(i===me)switch(n){case me:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case He: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 Oe:return e.pos[1]===t.pos[1]?4:2}else if(i===Oe)switch(n){case me:return e.pos[1]===t.pos[1]?4:2;case He:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case we:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case Oe:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(i===He)switch(n){case me:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case we:return e.pos[0]===t.pos[0]?4:2;case Oe:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(i===we)switch(n){case me:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case He: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 Oe:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Mp=([e,t],n)=>[ni([e,t-1],n),ni([e+1,t],n),ni([e,t+1],n),ni([e-1,t],n)],ni=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,Qi=(e,t)=>{for(let n=0;n<t.col;n++)for(let i=0;i<t.row;i++){let o=ni([n,i],t);if(o&&e[0]===o.pos[0]&&e[1]===o.pos[1])return o}return null},Ba=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]))],Ji=(e,t)=>{let n=t.get(e);return n&&Le(n)?n:null},Tt=(e,t,n,i)=>{let o=e[0][0],r=e[0][1],s=e.map(a=>fr(a,dp(Er(e[0]),-1)));return(o<-Ut||o>Ut||r<-Ut||r>Ut||o+s[s.length-1][0]<-Ut||r+s[s.length-1][0]>Ut||o+s[s.length-1][1]<-Ut||r+s[s.length-1][1]>Ut)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:o,y:r,points:s,...Ta(s)}),s=s.map(([a,l])=>z(qi(a,-1e6,1e6),qi(l,-1e6,1e6))),{points:s,x:qi(o,-1e6,1e6),y:qi(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...Ta(s),startIsSpecial:n,endIsSpecial:i}},yr=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},br=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let i=e[n-1];return hr(i,t)>gr}):e,Tp=e=>{switch(e){case 0:return He;case 1:return me;case 2:return we}return Oe},Da=(e,t,n,i,o,r,s)=>s?o&&r?Pr(e,o,t,r):i:o?eo(n||[0,0],o,r??hp([o])):i,va=(e,t,n,i,o)=>Oa(e,t,n,n&&Ve(n,o,Array(4).fill(_t(n,o,e))),i,o),La=(e,t,n,i)=>Wt(mp(e),n,t,i,!0,!0),Ca=(e,t)=>e[0]===t[0]&&e[1]===t[1],Ga=(e,t=gr)=>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,startBinding:a,endBinding:l,fileId:c}=n;G(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u"||typeof a<"u"||typeof l<"u")?n={...n,angle:0,...Dn({...e,x:n.x||e.x,y:n.y||e.y},t,n,i)}:typeof r<"u"&&(n={...Ap(r),...n});for(let d in n){let u=n[d];if(typeof u<"u"){if(e[d]===u&&(typeof u!="object"||u===null||d==="groupIds"||d==="scale"))continue;if(d==="scale"){let p=e[d],m=u;if(p[0]===m[0]&&p[1]===m[1])continue}else if(d==="points"){let p=e[d],m=u;if(p.length===m.length){let f=!1,E=p.length;for(;--E;){let h=p[E],g=m[E];if(h[0]!==g[0]||h[1]!==g[1]){f=!0;break}}if(!f)continue}}e[d]=u,o=!0}}return o&&((typeof n.height<"u"||typeof n.width<"u"||typeof c<"u"||typeof r<"u")&&be.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Ir(),e.updated=Sr()),e},Me=(e,t,n=!1)=>{let i=!1;for(let o in t){let r=t[o];if(typeof r<"u"){if(e[o]===r&&(typeof r!="object"||r===null))continue;i=!0}}return!i&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Ir(),updated:Sr()}},Ra=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Ir(),e.updated=Sr(),e);var ly=e=>!e[Dp.CTRL_OR_CMD],Mr=e=>e.isBindingEnabled,oe=5,Rp=10,kp=(e,t)=>{let n=[];return t.forEach(i=>{let o=e.getNonDeletedElement(i);o!=null&&n.push(o)}),n},Tr=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=new Set,s=new Set;Na(e,t,n,"start",r,s,i,o),Na(e,n,t,"end",r,s,i,o);let a=Array.from(s).filter(l=>!r.has(l));kp(i,a).forEach(l=>{i.mutateElement(l,{boundElements:l.boundElements?.filter(c=>c.type!=="arrow"||c.id!==e.id)})})},Na=(e,t,n,i,o,r,s,a)=>{if(t!=="keep"){if(t===null){let l=_p(e,i,s);l!=null&&r.add(l);return}Wa(e)?(n==null||(n==="keep"?!Ua(e,t,i):i==="start"||n.id!==t.id))&&(mn(e,t,i,s),o.add(t.id)):(mn(e,t,i,s),o.add(t.id))}},_a=(e,t,n)=>["start","end"].map(i=>{let o=Va(e,i,t),r=i==="start"?e.startBinding?.elementId:e.endBinding?.elementId;if(r){let s=t.get(r);if(Le(s)&&no(s,o,t,n))return s}return null}),Fp=(e,t,n,i,o,r)=>{let a=e.points.length-1,l=n.findIndex(p=>p===0)>-1,c=n.findIndex(p=>p===a)>-1,d=l?t?io(e,"start",i,o,r):null:"keep",u=c?t?io(e,"end",i,o,r):null:"keep";return[d,u]},Np=(e,t,n,i,o)=>{if(G(e))return["keep","keep"];let[r,s]=_a(e,t,o),a=r&&i?io(e,"start",t,n,o):null,l=s&&i?io(e,"end",t,n,o):null;return[a,l]},zp=(e,t,n,i,o)=>{e.forEach(r=>{let[s,a]=n?.length?Fp(r,t,n??[],i.getNonDeletedElementsMap(),i.getNonDeletedElements(),o):Np(r,i.getNonDeletedElementsMap(),i.getNonDeletedElements(),t,o);Tr(r,s,a,i)})},cy=(e,t,n)=>e.length>50?[]:e.filter(X).flatMap(i=>_a(i,t,n)).filter(i=>i!==null).filter(i=>e.filter(o=>o.id===i?.id).length===0),Ya=(e,t,n,i,o)=>Array.from(t.reduce((r,s)=>{let a=Wt(s,n.getNonDeletedElements(),n.getNonDeletedElementsMap(),i,G(e),G(e));return a!=null&&!Xa(e,o?.id,a)&&r.add(a),r},new Set)),dy=(e,t,n,i)=>{let o=i.getNonDeletedElements(),r=i.getNonDeletedElementsMap();t.startBoundElement!=null&&mn(e,t.startBoundElement,"start",i);let s=Wt(n,o,r,t.zoom,G(e),G(e));s!==null&&(Ua(e,s,"end")||mn(e,s,"end",i))},Hp=(e,t)=>({...e,gap:Math.min(e.gap,so(t,t.width,t.height))}),mn=(e,t,n,i)=>{if(!_(e))return;let o={elementId:t.id,...Hp(Xp(e,t,n,i.getNonDeletedElementsMap()),t)};G(e)&&(o={...o,...ja(e,t,n,i.getNonDeletedElementsMap())}),i.mutateElement(e,{[n==="start"?"startBinding":"endBinding"]:o}),Ha(t.boundElements||[]).has(e.id)||i.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Ua=(e,t,n)=>{let i=e[n==="start"?"endBinding":"startBinding"];return Xa(e,i?.elementId,t)},Xa=(e,t,n)=>t===n.id&&Wa(e),Wa=e=>e.points.length<3&&!G(e),_p=(e,t,n)=>{let i=t==="start"?"startBinding":"endBinding",o=e[i];return o==null?null:(n.mutateElement(e,{[i]:null}),o.elementId)},Wt=(e,t,n,i,o,r)=>{if(r){let a=!1,l=Up(t,d=>Le(d,!1)&&no(d,e,n,i,(o||!to(d))&&!$(d))).filter(d=>a?!1:(to(d)||(a=!0),!0));if(!l||l.length===0)return null;if(l.length===1)return l[0];let c=l.filter(d=>no(d,e,n,i,!1));return c.length===1?c[0]:l.sort((d,u)=>u.width**2+u.height**2-(d.width**2+d.height**2)).pop()}return Yp(t,a=>Le(a,!1)&&no(a,e,n,i,(o||!to(a))&&!$(a)))},Yp=(e,t)=>{let n=null;for(let i=e.length-1;i>=0;--i){let o=e[i];if(!o.isDeleted&&t(o)){n=o;break}}return n},Up=(e,t)=>{let n=[];for(let i=e.length-1;i>=0;--i){let o=e[i];o.isDeleted||t(o)&&n.push(o)}return n},Xp=(e,t,n,i)=>{let o=n==="start"?-1:1,r=o===-1?0:e.points.length-1,s=r-o,a=Y.getPointAtIndexGlobalCoordinates(e,r,i),l=Y.getPointAtIndexGlobalCoordinates(e,s,i);return{focus:Kp(t,i,l,a),gap:Math.max(1,_t(t,i,a))}},Ue=(e,t,n)=>{if(!Le(e))return;let{newSize:i,simultaneouslyUpdated:o}=n??{},r=jp(o),s=t.getNonDeletedElementsMap();n?.changedElements&&(s=new Map(s),n.changedElements.forEach(a=>{s.set(a.id,a)})),oo(s,e,a=>{if(!X(a)||a.isDeleted||!Wp(a,e))return;let l=a.startBinding?s.get(a.startBinding.elementId):null,c=a.endBinding?s.get(a.endBinding.elementId):null,d=null,u=null;l&&c&&(d=he(l,s),u=he(c,s));let p={startBinding:za(e,a.startBinding,i),endBinding:za(e,a.endBinding,i)};if(r.has(a.id)){t.mutateElement(a,p);return}let m=ro(s,a,(E,h)=>{if(E&&Le(E)&&(h==="startBinding"||h==="endBinding")&&(e.id===a[h]?.elementId||e.id===a[h==="startBinding"?"endBinding":"startBinding"]?.elementId&&!pn(d,u))){let g=qp(a,h,p[h],E,s);if(g)return[h==="startBinding"?0:a.points.length-1,{point:g}]}return null}).filter(E=>E!==null);Y.movePoints(a,t,new Map(m),{...e.id===a.startBinding?.elementId?{startBinding:p.startBinding}:{},...e.id===a.endBinding?.elementId?{endBinding:p.endBinding}:{}});let f=W(a,s);f&&!f.isDeleted&&un(a,t,!1)})},uy=(e,t,n)=>{X(e)?zp([e],!0,[],t,n?.zoom):Ue(e,t,{...n,changedElements:new Map([[e.id,e]])})},Wp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,jp=e=>new Set((e||[]).map(t=>t.id)),Oa=(e,t,n,i,o,r,s)=>{let a=Mt(Z(t,e));return!n||!i?a:Vp(o,n,r,s)?ti(n,i,e):Mt(Z(e,fe(n,r)))},Vp=(e,t,n,i)=>{let o=_t(t,n,e),r=so(t,t.width,t.height,i);return o>r?null:o},Pr=(e,t,n,i)=>{(Cp()||Bp())&&Lp(e.points.length>1,"Arrow should have at least 2 points");let o=Ve(t,i),r=e.points[n==="start"?0:e.points.length-1],s=R(e.x+r[0],e.y+r[1]),a=ra(t)?$p(t,i,s):s,l=G(e),c=ct(o),d=n==="start"?1:e.points.length-2,u=ae(R(e.x+e.points[d][0],e.y+e.points[d][1]),c,e.angle??0),p=null;if(l){let m=Re(ti(t,o,s)),f=Zp(t,i,a),E=R(m?c[0]:f[0],m?f[1]:c[1]),h=Ye(E,vn(Ln(ri(Z(f,E)),Math.max(t.width,t.height)*2),E));p=Mn(t,i,h,oe).sort(jt)[0]}else p=Mn(t,i,Ye(u,vn(Ln(ri(Z(a,u)),ut(a,u)+Math.max(t.width,t.height)*2),u)),oe).sort((m,f)=>jt(m,u)-jt(f,u))[0];return!p||jt(a,p)<Op?a:l?p:a},$p=(e,t,n)=>{let i=fe(e,t),o=ae(n,i,-e.angle);return o[0]<e.x&&o[1]<e.y?o[1]-e.y>-oe?ae(R(e.x-oe,e.y),i,e.angle):ae(R(e.x,e.y-oe),i,e.angle):o[0]<e.x&&o[1]>e.y+e.height?o[0]-e.x>-oe?ae(R(e.x,e.y+e.height+oe),i,e.angle):ae(R(e.x-oe,e.y+e.height),i,e.angle):o[0]>e.x+e.width&&o[1]>e.y+e.height?o[0]-e.x<e.width+oe?ae(R(e.x+e.width,e.y+e.height+oe),i,e.angle):ae(R(e.x+e.width+oe,e.y+e.height),i,e.angle):o[0]>e.x+e.width&&o[1]<e.y?o[0]-e.x<e.width+oe?ae(R(e.x+e.width,e.y-oe),i,e.angle):ae(R(e.x+e.width+oe,e.y),i,e.angle):n},Zp=(e,t,n,i=.05)=>{let{x:o,y:r,width:s,height:a,angle:l}=e,c=fe(e,t,-.1,-.1),d=ae(n,c,-l),u=ka(i*a,5,80),p=ka(i*s,5,80);if(d[0]<=o+s/2&&d[1]>c[1]-u&&d[1]<c[1]+u)return ae(R(o-oe,c[1]),c,l);if(d[1]<=r+a/2&&d[0]>c[0]-p&&d[0]<c[0]+p)return ae(R(c[0],r-oe),c,l);if(d[0]>=o+s/2&&d[1]>c[1]-u&&d[1]<c[1]+u)return ae(R(o+s+oe,c[1]),c,l);if(d[1]>=r+a/2&&d[0]>c[0]-p&&d[0]<c[0]+p)return ae(R(c[0],r+a+oe),c,l);if(e.type==="diamond"){let m=oe,f=R(o+s/4-m,r+a/4-m),E=R(o+3*s/4+m,r+a/4-m),h=R(o+s/4-m,r+3*a/4+m),g=R(o+3*s/4+m,r+3*a/4+m);if(ut(f,d)<Math.max(p,u))return ae(f,c,l);if(ut(E,d)<Math.max(p,u))return ae(E,c,l);if(ut(h,d)<Math.max(p,u))return ae(h,c,l);if(ut(g,d)<Math.max(p,u))return ae(g,c,l)}return n},qp=(e,t,n,i,o)=>{if(n==null||n.elementId!==i.id&&e.points.length>2)return null;let r=t==="startBinding"?-1:1,s=r===-1?0:e.points.length-1;if(G(e)&&Qn(n)){let u=Ar(n.fixedPoint)??ja(e,i,t==="startBinding"?"start":"end",o).fixedPoint,p=fe(i,o),m=R(i.x+u[0]*i.width,i.y+u[1]*i.height),f=ae(m,p,i.angle);return Y.pointFromAbsoluteCoords(e,f,o)}let a=s-r,l=Y.getPointAtIndexGlobalCoordinates(e,a,o),c=Qp(i,o,n.focus,l),d;if(n.gap===0)d=c;else{let u=Y.getPointAtIndexGlobalCoordinates(e,s,o),p=fe(i,o),m=ut(l,u)+ut(l,p)+Math.max(i.width,i.height)*2,f=[...Mn(i,o,Ye(l,vn(Ln(ri(Z(c,l)),m),l)),n.gap).sort((E,h)=>jt(E,l)-jt(h,l)),vn(Ln(ri(Z(c,l)),ut(l,u)),l)];f.length>1?d=f[0]:f.length===1?d=c:d=u}return Y.pointFromAbsoluteCoords(e,d,o)},ja=(e,t,n,i)=>{let o=[t.x,t.y,t.x+t.width,t.y+t.height],r=Pr(e,t,n,i),s=R(o[0]+(o[2]-o[0])/2,o[1]+(o[3]-o[1])/2),a=ae(r,s,-t.angle);return{fixedPoint:Ar([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},za=(e,t,n)=>{if(t==null||n==null)return t;let{width:i,height:o}=n,{width:r,height:s}=e,a=Math.max(1,Math.min(so(e,i,o),t.gap*(i<o?i/r:o/s)));return{...t,gap:a}},io=(e,t,n,i,o)=>Wt(Va(e,t,n),i,n,o,G(e),G(e)),Va=(e,t,n)=>{let i=t==="start"?0:-1;return vp(Y.getPointAtIndexGlobalCoordinates(e,i,n))},$a=(e,t,n)=>{for(let i of e){if("boundElements"in i&&i.boundElements&&Object.assign(i,{boundElements:i.boundElements.reduce((o,r)=>{let s=t.get(r.id);return s&&o.push({...r,id:s}),o},[])}),"containerId"in i&&i.containerId&&Object.assign(i,{containerId:t.get(i.containerId)??null}),"endBinding"in i&&i.endBinding){let o=t.get(i.endBinding.elementId);Object.assign(i,{endBinding:o?{...i.endBinding,elementId:o}:null})}if("startBinding"in i&&i.startBinding){let o=t.get(i.startBinding.elementId);Object.assign(i,{startBinding:o?{...i.startBinding,elementId:o}:null})}G(i)&&Object.assign(i,Dn(i,n,{points:[i.points[0],i.points[i.points.length-1]]}))}},py=(e,t)=>{let n=Ha(e);for(let i of t)Vt.unbindAffected(n,i,(o,r)=>ye(o,n,r)),$t.unbindAffected(n,i,(o,r)=>ye(o,n,r))},oi=(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},no=(e,{x:t,y:n},i,o,r)=>{let s=R(t,n),a=so(e,e.width,e.height,o),l=(r||!to(e))&&!$(e),c=[t-a,n-a,t+a,n+a],d=he(e,i);if(!pn(c,d))return!1;let u=Mn(e,i,Ye(fe(e,i),s)),p=_t(e,i,s);return l?u.length===0||p<=a:u.length>0&&p<=a},so=(e,t,n,i)=>{let o=i?.value&&i.value<1?i.value:1,s=(e.type==="diamond"?1/Math.sqrt(2):1)*Math.min(t,n);return Math.max(16,Math.min(.25*s,32),Rp/o+oe)},Kp=(e,t,n,i)=>{let o=fe(e,t);if(Gp(n,i))return 0;let r=ae(n,o,-e.angle),s=ae(i,o,-e.angle),a=Math.sign(_e(Z(s,n),Z(s,o)))*-1,l=Ye(s,vn(Ln(ri(Z(s,r)),Math.max(e.width*2,e.height*2)),s)),c=e.type==="diamond"?[Ye(R(e.x+e.width/2,e.y),R(e.x+e.width/2,e.y+e.height)),Ye(R(e.x,e.y+e.height/2),R(e.x+e.width,e.y+e.height/2))]:[Ye(R(e.x,e.y),R(e.x+e.width,e.y+e.height)),Ye(R(e.x+e.width,e.y),R(e.x,e.y+e.height))],d=e.type==="diamond"?[Ye(R(e.x+e.width/2,e.y-e.height),R(e.x+e.width/2,e.y+e.height*2)),Ye(R(e.x-e.width,e.y+e.height/2),R(e.x+e.width*2,e.y+e.height/2))]:[Ye(R(e.x-e.width,e.y-e.height),R(e.x+e.width*2,e.y+e.height*2)),Ye(R(e.x+e.width*2,e.y-e.height),R(e.x-e.width,e.y+e.height*2))];return[Fa(l,d[0]),Fa(l,d[1])].filter(m=>m!==null).sort((m,f)=>jt(m,i)-jt(f,i)).map((m,f)=>a*ut(o,m)/(e.type==="diamond"?ut(c[f][0],c[f][1])/2:Math.sqrt(e.width**2+e.height**2)/2)).sort((m,f)=>Math.abs(m)-Math.abs(f))[0]??0},Qp=(e,t,n,i)=>{let o=fe(e,t);if(n===0)return o;let r=(e.type==="diamond"?[R(e.x,e.y+e.height/2),R(e.x+e.width/2,e.y),R(e.x+e.width,e.y+e.height/2),R(e.x+e.width/2,e.y+e.height)]:[R(e.x,e.y),R(e.x+e.width,e.y),R(e.x+e.width,e.y+e.height),R(e.x,e.y+e.height)]).map(l=>vn(Ln(Z(l,o),Math.abs(n)),o)).map(l=>ae(l,o,e.angle)),s=[_e(Z(i,r[0]),Z(r[1],r[0]))>0&&(n>0?_e(Z(i,r[1]),Z(r[2],r[1]))<0:_e(Z(i,r[3]),Z(r[0],r[3]))<0),_e(Z(i,r[1]),Z(r[2],r[1]))>0&&(n>0?_e(Z(i,r[2]),Z(r[3],r[2]))<0:_e(Z(i,r[0]),Z(r[1],r[0]))<0),_e(Z(i,r[2]),Z(r[3],r[2]))>0&&(n>0?_e(Z(i,r[3]),Z(r[0],r[3]))<0:_e(Z(i,r[1]),Z(r[2],r[1]))<0),_e(Z(i,r[3]),Z(r[0],r[3]))>0&&(n>0?_e(Z(i,r[0]),Z(r[1],r[0]))<0:_e(Z(i,r[2]),Z(r[3],r[2]))<0)];return s[0]?n>0?r[1]:r[0]:s[1]?n>0?r[2]:r[1]:s[2]?n>0?r[3]:r[2]:n>0?r[0]:r[3]},Za=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),oo=(e,t,n)=>{Le(t)&&(t.boundElements?.slice()??[]).forEach(({id:o})=>{n(e.get(o),"boundElements",o)})},ro=(e,t,n)=>{let i=[];if(t.frameId){let o=t.frameId;i.push(n(e.get(o),"frameId",o))}if(de(t)){let o=t.containerId;i.push(n(e.get(o),"containerId",o))}if(_(t)){if(t.startBinding){let o=t.startBinding.elementId;i.push(n(e.get(o),"startBinding",o))}if(t.endBinding){let o=t.endBinding.elementId;i.push(n(e.get(o),"endBinding",o))}}return i},Vt=class{static unbindAffected(t,n,i){n&&ro(t,n,o=>{!o||o.isDeleted||oo(t,o,(r,s,a)=>{a===n.id&&i(o,{boundElements:oi(o.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,i)=>{!n||n.isDeleted||ro(t,n,(o,r)=>{if(!o||o.isDeleted){i(n,{[r]:null});return}r!=="frameId"&&(o.boundElements?.find(s=>s.id===n.id)||(_(n)&&i(o,{boundElements:oi(o.boundElements,new Set,new Array(n))}),ie(n)&&(o.boundElements?.find(s=>s.type==="text")?i(n,{[r]:null}):i(o,{boundElements:oi(o.boundElements,new Set,new Array(n))}))))})}},$t=class{static unbindAffected(t,n,i){n&&oo(t,n,o=>{!o||o.isDeleted||ro(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:oi(n.boundElements,new Set([s]))});return}ie(o)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===o.id?o.containerId!==n.id&&i(o,{containerId:n.id}):(o.containerId!==null&&i(o,{containerId:null}),i(n,{boundElements:oi(n.boundElements,new Set([o.id]))})))})}},eo=(e,t,n)=>{let[i,o]=Ar(e);return ae(R(t.x+t.width*i,t.y+t.height*o),fe(t,n),t.angle)},Jp=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),i=e.endBinding&&t.get(e.endBinding.elementId),o=n&&e.startBinding?eo(e.startBinding.fixedPoint,n,t):R(e.x+e.points[0][0],e.y+e.points[0][1]),r=i&&e.endBinding?eo(e.endBinding.fixedPoint,i,t):R(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[o,r]},qa=(e,t)=>{let[n,i]=Jp(e,t);return[Y.pointFromAbsoluteCoords(e,n,t),Y.pointFromAbsoluteCoords(e,i,t)]},Ar=e=>e&&(Math.abs(e[0]-.5)<1e-4||Math.abs(e[1]-.5)<1e-4)?e.map(t=>Math.abs(t-.5)<1e-4?.5001:t):e;var vr=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(i=>B(i[0]-t,i[1]-n)),offsetX:t,offsetY:n}},Y=class e{elementId;selectedPointsIndices;pointerDownState;isDragging;lastUncommittedPoint;pointerOffset;startBindingElement;endBindingElement;hoverPointIndex;segmentMidPointHoveredCoords;elbowed;customLineAngle;isEditing;constructor(t,n,i=!1){this.elementId=t.id,Qa(t.points[0],B(0,0))||(console.error("Linear element is not normalized",Error().stack),ye(t,n,e.getNormalizeElementPointsAndCoords(t))),this.selectedPointsIndices=null,this.lastUncommittedPoint=null,this.isDragging=!1,this.pointerOffset={x:0,y:0},this.startBindingElement="keep",this.endBindingElement="keep",this.pointerDownState={prevSelectedPointsIndices:null,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:null,segmentMidpoint:{value:null,index:null,added:!1}},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.elbowed=G(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=i}static POINT_HANDLE_SIZE=10;static getElement(t,n){let i=n.get(t);return i||null}static handleBoxSelection(t,n,i,o){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,o);if(!l)return!1;let[c,d,u,p]=H(n.selectionElement,o),f=e.getPointsGlobalCoordinates(l,o).reduce((E,h,g)=>((h[0]>=c&&h[0]<=u&&h[1]>=d&&h[1]<=p||t.shiftKey&&s?.includes(g))&&E.push(g),E),[]).filter(E=>!(G(l)&&E!==0&&E!==l.points.length-1));i({selectedLinearElement:{...r,selectedPointsIndices:f.length?f:null}})}static handlePointDragging(t,n,i,o,r){if(!r)return null;let{elementId:s}=r,a=n.scene.getNonDeletedElementsMap(),l=e.getElement(s,a),c=r.customLineAngle;if(!l||G(l)&&!r.pointerDownState.lastClickedIsEndPoint&&r.pointerDownState.lastClickedPoint!==0)return null;let d=G(l)?[r.selectedPointsIndices?.includes(0)?0:void 0,r.selectedPointsIndices?.find(m=>m>0)?l.points.length-1:void 0].filter(m=>m!==void 0):r.selectedPointsIndices,u=G(l)?r.pointerDownState.lastClickedPoint>0?l.points.length-1:0:r.pointerDownState.lastClickedPoint,p=l.points[u];if(d&&p){if(Ja(t)&&d.length===1&&l.points.length>1){let h=d[0],g=l.points[h===0?1:h-1];c=r.customLineAngle??Math.atan2(l.points[h][1]-g[1],l.points[h][0]-g[0]);let[x,y]=e._getShiftLockedDelta(l,a,g,B(i,o),t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),c);e.movePoints(l,n.scene,new Map([[h,{point:B(x+g[0],y+g[1]),isDragging:h===u}]]))}else{let h=e.createPointAt(l,a,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize()),g=h[0]-p[0],x=h[1]-p[1];e.movePoints(l,n.scene,new Map(d.map(y=>{let b=y===u?e.createPointAt(l,a,i-r.pointerOffset.x,o-r.pointerOffset.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize()):B(l.points[y][0]+g,l.points[y][1]+x);return[y,{point:b,isDragging:y===u}]})))}W(l,a)&&un(l,n.scene,!1);let f=[];if(Qo(l,!1)){let h=d[0]===0,g=d[d.length-1]===l.points.length-1,x=[];!h!=!g?x.push({x:i,y:o}):(h&&x.push(Dr(e.getPointGlobalCoordinates(l,l.points[0],a))),g&&x.push(Dr(e.getPointGlobalCoordinates(l,l.points[d[d.length-1]],a)))),x.length&&(f=Ya(l,x,n.scene,n.state.zoom))}let E={...r,selectedPointsIndices:d,segmentMidPointHoveredCoords:u!==0&&u!==l.points.length-1?this.getPointGlobalCoordinates(l,p,a):null,hoverPointIndex:u===0||u===l.points.length-1?u:-1,isDragging:!0,customLineAngle:c};return{...n.state,selectedLinearElement:E,suggestedBindings:f}}return null}static handlePointerUp(t,n,i,o){let r=o.getNonDeletedElementsMap(),s=o.getNonDeletedElements(),a=om(t,i),{elementId:l,selectedPointsIndices:c,isDragging:d,pointerDownState:u}=n,p=e.getElement(l,r);if(!p)return n;let m={};if(d&&c){for(let f of c)if(f===0||f===p.points.length-1){rm(p.points,i.zoom.value)&&(cn(p)&&o.mutateElement(p,{...nl(p,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(p,o,new Map([[f,{point:f===0?p.points[p.points.length-1]:p.points[0]}]])));let E=Mr(i)?Wt((c?.length??0)>1?Dr(e.getPointAtIndexGlobalCoordinates(p,f,r)):a,s,r,i.zoom,G(p),G(p)):null;m[f===0?"startBindingElement":"endBindingElement"]=E}}return{...n,...m,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:d||t.shiftKey?!d&&t.shiftKey&&u.prevSelectedPointsIndices?.includes(u.lastClickedPoint)?c&&c.filter(f=>f!==u.lastClickedPoint):c:c?.includes(u.lastClickedPoint)?[u.lastClickedPoint]:c,isDragging:!1,pointerOffset:{x:0,y:0},customLineAngle:null}}static getEditorMidPoints=(t,n,i)=>{let o=W(t,n);if(!G(t)&&!i.selectedLinearElement?.isEditing&&t.points.length>2&&!o)return[];let r=e.getPointsGlobalCoordinates(t,n),s=0,a=[];for(;s<r.length-1;){if(e.isSegmentTooShort(t,t.points[s],t.points[s+1],s,i.zoom)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,i,o)=>{let{elementId:r}=t,s=e.getElement(r,o);if(!s)return null;let a=e.getPointIndexUnderCursor(s,o,i.zoom,n.x,n.y);if(!G(s)&&a>=0||e.getPointsGlobalCoordinates(s,o).length>=3&&!i.selectedLinearElement?.isEditing&&!G(s))return null;let c=(e.POINT_HANDLE_SIZE+1)/i.zoom.value,d=t.segmentMidPointHoveredCoords;if(d&&Cn(B(d[0],d[1]),B(n.x,n.y))<=c)return d;let u=0,p=e.getEditorMidPoints(s,o,i);for(;u<p.length;){if(p[u]!==null&&Cn(p[u],B(n.x,n.y))<=c)return p[u];u++}return null};static isSegmentTooShort(t,n,i,o,r){if(G(t))return o>=0&&o<t.points.length?Cn(n,i)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=Cn(n,i);if(t.points.length>2&&t.roundness){let[a,l]=tl(t);At(a.length===0&&l.length>0,"Only linears built out of curves are supported"),At(a.length+l.length>=o,"Invalid segment index while calculating mid point"),s=tm(l[o])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(G(t)){At(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=Ka(t.points[n-1],t.points[n]);return B(t.x+r[0],t.y+r[1])}let[i,o]=tl(t);if(At(i.length===0&&o.length>0||i.length>0&&o.length===0,"Only linears built out of either segments or curves are supported"),At(i.length+o.length>=n,"Invalid segment index while calculating mid point"),i.length){let r=i[n-1];return Ka(r[0],r[1])}if(o.length){let r=o[n-1];return nm(r,.5)}At(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,i,o){let r=e.getElement(t.elementId,o);if(!r)return-1;let s=e.getEditorMidPoints(r,o,n),a=0;for(;a<s.length;){if(e.arePointsEqual(i,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,i,o,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),c=s.getNonDeletedElements(),d={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return d;let{elementId:u}=r,p=e.getElement(u,l);if(!p)return d;let m=e.getSegmentMidpointHitCoords(r,o,a,l),f=null;if(m)f=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(p,{points:[...p.points,e.createPointAt(p,l,o.x,o.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),d.didAddPoint=!0),i.scheduleCapture(),d.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:{x:o.x,y:o.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:[p.points.length-1],lastUncommittedPoint:null,endBindingElement:Wt(o,c,l,n.state.zoom,r.elbowed)},d.didAddPoint=!0,d;let E=e.getPointIndexUnderCursor(p,l,a.zoom,o.x,o.y);if(E>=0||m)d.hitElement=p;else{let{startBindingElement:D,endBindingElement:T}=r;Mr(a)&&Qo(p)&&Tr(p,D,T,s)}let[h,g,x,y]=H(p,l),b=(h+x)/2,w=(g+y)/2,I=E>-1&&Te(B(p.x+p.points[E][0],p.y+p.points[E][1]),B(b,w),p.angle),M=E>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(E)?sm([...r.selectedPointsIndices||[],E]):[E]:null;return d.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:E,lastClickedIsEndPoint:E===p.points.length-1,origin:{x:o.x,y:o.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:M,pointerOffset:I?{x:o.x-I[0],y:o.y-I[1]}:{x:0,y:0}},d}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:Qa(t,n)}static handlePointerMove(t,n,i,o){let r=o.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=o.scene.getNonDeletedElementsMap(),c=e.getElement(s,l);if(!c)return r.selectedLinearElement;let{points:d}=c,u=d[d.length-1];if(!t.altKey)return u===a&&e.deletePoints(c,o,[d.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let p;if(Ja(t)&&d.length>=2){let m=d[d.length-2],[f,E]=e._getShiftLockedDelta(c,l,m,B(n,i),t[Bn.CTRL_OR_CMD]?null:o.getEffectiveGridSize());p=B(f+m[0],E+m[1])}else p=e.createPointAt(c,l,n-r.selectedLinearElement.pointerOffset.x,i-r.selectedLinearElement.pointerOffset.y,t[Bn.CTRL_OR_CMD]||G(c)?null:o.getEffectiveGridSize());return u===a?e.movePoints(c,o.scene,new Map([[c.points.length-1,{point:p}]])):e.addPoints(c,o.scene,[p]),{...r.selectedLinearElement,lastUncommittedPoint:c.points[c.points.length-1]}}static getPointGlobalCoordinates(t,n,i){let[o,r,s,a]=H(t,i),l=(o+s)/2,c=(r+a)/2,{x:d,y:u}=t;return Te(B(d+n[0],u+n[1]),B(l,c),t.angle)}static getPointsGlobalCoordinates(t,n){let[i,o,r,s]=H(t,n),a=(i+r)/2,l=(o+s)/2;return t.points.map(c=>{let{x:d,y:u}=t;return Te(B(d+c[0],u+c[1]),B(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,i){let o=n<0?t.points.length+n:n,[r,s,a,l]=H(t,i),c=(r+a)/2,d=(s+l)/2,u=t.points[o],{x:p,y:m}=t;return u?Te(B(p+u[0],m+u[1]),B(c,d),t.angle):Te(B(p,m),B(c,d),t.angle)}static pointFromAbsoluteCoords(t,n,i){if(G(t))return B(n[0]-t.x,n[1]-t.y);let[o,r,s,a]=H(t,i),l=(o+s)/2,c=(r+a)/2,[d,u]=Te(B(n[0],n[1]),B(l,c),-t.angle);return B(d-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,i,o,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Cn(B(o,r),B(l[0],l[1]))*i.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,i,o,r){let s=el(i,o,r),[a,l,c,d]=H(t,n),u=(a+c)/2,p=(l+d)/2,[m,f]=Te(B(s[0],s[1]),B(u,p),-t.angle);return B(m-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:i,offsetY:o}=vr(t);return{points:n,x:t.x+i,y:t.y+o}}static duplicateSelectedPoints(t,n){At(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let i=n.getNonDeletedElementsMap(),{selectedPointsIndices:o,elementId:r}=t.selectedLinearElement,s=e.getElement(r,i);At(s,"The linear element does not exist in the provided Scene"),At(o!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],c=!1,d=-1,u=a.reduce((p,m,f)=>{if(++d,p.push(m),o.includes(f)){let h=a[f+1];h||(c=!0),p.push(h?B((m[0]+h[0])/2,(m[1]+h[1])/2):B(m[0],m[1])),l.push(d+1),++d}return p},[]);if(n.mutateElement(s,{points:u}),c){let p=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:B(p[0]+30,p[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,i){let o=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((d,u)=>!i.includes(u));cn(t)&&t.polygon&&(o||i.includes(0)||i.includes(t.points.length-1))&&(r[0]=B(r[r.length-1][0],r[r.length-1][1]));let{points:a,offsetX:l,offsetY:c}=vr({points:r});e._updatePoints(t,n.scene,a,l,c)}static addPoints(t,n,i){let o=[...t.points,...i];cn(t)&&t.polygon&&(o[0]=B(o[o.length-1][0],o[o.length-1][1]));let{points:r,offsetX:s,offsetY:a}=vr({points:o});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,i,o){let{points:r}=t;if(cn(t)&&t.polygon){let d=i.get(0),u=i.get(r.length-1);d?i.set(r.length-1,{point:B(d.point[0],d.point[1]),isDragging:d.isDragging}):u&&i.set(0,{point:B(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=i.get(0)?.point??B(0,0),[a,l]=s,c=G(t)?[i.get(0)?.point??r[0],i.get(r.length-1)?.point??r[r.length-1]]:r.map((d,u)=>{let p=i.get(u)?.point??d;return B(p[0]-a,p[1]-l)});e._updatePoints(t,n,c,a,l,o,{isDragging:Array.from(i.values()).some(d=>d.isDragging)})}static shouldAddMidpoint(t,n,i,o){let r=e.getElement(t.elementId,o);if(r&&G(r)||!r)return!1;let{segmentMidpoint:s}=t.pointerDownState;if(s.added||s.value===null||s.index===null||t.pointerDownState.origin===null)return!1;let a=t.pointerDownState.origin,l=Cn(B(a.x,a.y),B(n.x,n.y));return!(!i.selectedLinearElement?.isEditing&&l<im/i.zoom.value)}static addMidpoint(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.pointerDownState,c={pointerDownState:t.pointerDownState,selectedPointsIndices:t.selectedPointsIndices},d=e.createPointAt(a,s,n.x,n.y,o&&!G(a)?i.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),d,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),c.pointerDownState={...t.pointerDownState,segmentMidpoint:{...t.pointerDownState.segmentMidpoint,added:!0},lastClickedPoint:l.index},c.selectedPointsIndices=[l.index],c}static _updatePoints(t,n,i,o,r,s,a){if(G(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding!==null&&Qn(s.startBinding)?s.startBinding:null),s?.endBinding!==void 0&&(l.endBinding=s.endBinding!==null&&Qn(s.endBinding)?s.endBinding:null),l.points=Array.from(i),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1})}else{let l=Lr(t,i),c=Lr(t,t.points),d=(l[0]+l[2])/2,u=(l[1]+l[3])/2,p=(c[0]+c[2])/2,m=(c[1]+c[3])/2,f=p-d,E=m-u,h=Te(B(o,r),B(f,E),t.angle);n.mutateElement(t,{...s,points:i,x:t.x+h[0],y:t.y+h[1]})}}static _getShiftLockedDelta(t,n,i,o,r,s){let a=e.getPointGlobalCoordinates(t,i,n);if(G(t))return[o[0]-a[0],o[1]-a[1]];let[l,c]=el(o[0],o[1],r),{width:d,height:u}=il(a[0],a[1],l,c,s);return Te(B(d,u),B(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,c=(r+a)/2,d=(s+l)/2,{x:u,y:p}=e.getBoundTextElementPosition(t,o,n),m=u+o.width,f=p+o.height,E=B(c,d),h=Te(B(r,s),E,t.angle),g=Te(B(a,s),E,t.angle),x=Te(B(u,p),E,-t.angle),y=Te(B(m,p),E,-t.angle),b=Te(B(u,f),E,-t.angle),w=Te(B(m,f),E,-t.angle);return h[0]<g[0]&&h[1]>=g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(y[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):h[0]>=g[0]&&h[1]>g[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],y[0])),s=Math.min(s,b[1]),l=Math.max(l,y[1])):h[0]>=g[0]?(r=Math.min(r,y[0]),a=Math.max(a,b[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):h[1]<=g[1]&&(r=Math.min(r,Math.min(y[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,y[1]),l=Math.max(l,b[1])),[r,s,a,l,c,d]};static getElementAbsoluteCoords=(t,n,i=!1)=>{let o,r,s,a,l;if(t.points.length<2||!be.get(t)){let{minX:p,minY:m,maxX:f,maxY:E}=t.points.reduce((h,[g,x])=>(h.minY=Math.min(h.minY,x),h.minX=Math.min(h.minX,g),h.maxX=Math.max(h.maxX,g),h.maxY=Math.max(h.maxY,x),h),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});r=p+t.x,s=m+t.y,a=f+t.x,l=E+t.y}else{let p=be.generateElementShape(t,null),m=gt(p[0]),[f,E,h,g]=si(m);r=f+t.x,s=E+t.y,a=h+t.x,l=g+t.y}let c=(r+a)/2,d=(s+l)/2;if(o=[r,s,a,l,c,d],!i)return o;let u=W(t,n);return u&&(o=e.getMinMaxXYWithBoundText(t,n,[r,s,a,l],u)),o};static moveFixedSegment(t,n,i,o,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!G(a))return t;if(n&&n>0&&n<a.points.length){let l=Re(Mt(em(a.points[n],a.points[n-1]))),c=(a.fixedSegments??[]).reduce((m,f)=>(m[f.index]=f,m),{});c[n]={index:n,start:B(l?a.points[n-1][0]:i-a.x,l?o-a.y:a.points[n-1][1]),end:B(l?a.points[n][0]:i-a.x,l?o-a.y:a.points[n][1])};let d=Object.values(c).sort((m,f)=>m.index-f.index),u=d.map(m=>m.index).reduce((m,f)=>f<n?m+1:m,0);r.mutateElement(a,{fixedSegments:d});let p=B(a.x+(a.fixedSegments[u].start[0]+a.fixedSegments[u].end[0])/2,a.y+(a.fixedSegments[u].start[1]+a.fixedSegments[u].end[1])/2);return{...t,segmentMidPointHoveredCoords:p,pointerDownState:{...t.pointerDownState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:p}}}}return t}static deleteFixedSegment(t,n,i){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(o=>o.index!==i)})}},sm=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,i)=>n-i),t.length?t:null};P();import{arrayToMap as mt}from"@excalidraw/common";import{isPointWithinBounds as Dm,pointFrom as Rr}from"@excalidraw/math";P();import{vectorCross as al,vectorFromPoint as ao}from"@excalidraw/math";function ol(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 am(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var lm=1e-6;function rl(e,t){let n=ao(e[1],e[0]),i=ao(t,e[0]),o=al(n,i);return Math.abs(o)<lm}function Cr(e,t){let n=ao(e[1],e[0]),i=ao(t,e[0]);return al(n,i)<0}function sl(e,t){return rl(e,t[0])||rl(e,t[1])||(Cr(e,t[0])?!Cr(e,t[1]):Cr(e,t[1]))}function ll(e,t){return am(ol(e),ol(t))&&sl(e,t)&&sl(t,e)}P();import{arrayToMap as cm}from"@excalidraw/common";import{getElementBounds as dm}from"@excalidraw/element";import{isArrowElement as um,isExcalidrawElement as pm,isFreeDrawElement as mm,isLinearElement as fm,isTextElement as hm}from"@excalidraw/element";import{rangeIncludesValue as lo,pointFrom as Dt,pointRotateRads as Em,rangeInclusive as co}from"@excalidraw/math";var gm=e=>e.type==="diamond"?[Dt(e.width/2,0),Dt(e.width,e.height/2),Dt(e.width/2,e.height),Dt(0,e.height/2)]:[Dt(0,0),Dt(0+e.width,0),Dt(0+e.width,e.height),Dt(0,e.height)],xm=e=>fm(e)||mm(e)?e.points:gm(e),cl=e=>{let t=e.reduce((n,[i,o])=>(n.minY=Math.min(n.minY,o),n.minX=Math.min(n.minX,i),n.maxX=Math.max(n.maxX,i),n.maxY=Math.max(n.maxY,o),n),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0,cx:0,cy:0});return t.cx=(t.maxX+t.minX)/2,t.cy=(t.maxY+t.minY)/2,t},ul=e=>{let t=xm(e),{cx:n,cy:i}=cl(t),o=Dt(n,i),r=t.map(d=>Em(d,o,e.angle)),{minX:s,minY:a,maxX:l,maxY:c}=cl(r);return[s+e.x,a+e.y,l+e.x,c+e.y]},dl=(e,t,n=!1)=>{let i=ul(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},wm=(e,t)=>{let n=ul(e);return(lo(n[0],co(t[0],t[2]))||lo(t[0],co(n[0],n[2])))&&(lo(n[1],co(t[1],t[3]))||lo(t[1],co(n[1],n[3])))},pl=({elements:e,bounds:t,type:n,errorMargin:i=0})=>{pm(t)&&(t=dm(t,cm(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"?wm(s,o):n==="inside"?dl(s,o):dl(s,o,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);hm(s)&&s.containerId&&r.add(s.containerId),um(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 Mm,isShallowEqual as Tm}from"@excalidraw/common";P();var ym=(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}}},ml=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 c={};for(let p of r){let m=p.groupIds;if(a.editingGroupId){let f=m.indexOf(a.editingGroupId);f>-1&&(m=m.slice(0,f))}if(m.length>0){let f=m[m.length-1];c[f]=!0}}let d={},u=s.reduce((p,m)=>{if(m.isDeleted)return p;let f=m.groupIds.find(E=>c[E]);return f&&(p[m.id]=!0,Array.isArray(d[f])?d[f].push(m.id):d[f]=[m.id]),p},{});for(let p of Object.keys(d))d[p].length<2&&c[p]&&(c[p]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:c,selectedElementIds:Br({...a.selectedElementIds,...u},l)},n},o=(r,s,a,l)=>{let c=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):pt(s,r);return c.length?i(c,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:Br(r.selectedElementIds,a)}};return o.clearCache=()=>{t=null,e=null,n=null},o}(),bm=(e,t)=>Gr(e,t)!=null,Gr=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Pm=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),fl=(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,...ym(r,n,e)}}}return n.selectedGroupIds},Yy=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Im=(e,t)=>e.groupIds.includes(t),Ae=(e,t)=>{let n=[];for(let i of e.values())Im(i,t)&&n.push(i);return n},Sm=(e,t)=>e.groupIds.find(n=>t[n]),Uy=(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},Xy=(e,t)=>e.filter(n=>!t[n]),Wy=(e,t)=>{let n=new Map;return e.forEach(i=>{let o=i.groupIds.length===0?i.id:i.groupIds[i.groupIds.length-1],r=n.get(o)||[],s=W(i,t);s&&r.push(s),n.set(o,[...r,i])}),Array.from(n.values())},hl=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let i of n.groupIds??[])t.add(i);return t},El=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},gl=e=>e.groupIds.length>0,xl=(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},uo=(e,t,n)=>{let i=Pm(n),o=e.filter(u=>!de(u)),r=new Map,s=new Map,a=u=>{let p=s.get(u.id)||[],m=W(u,t);m&&p.push(m),s.set(u.id,[...p,u])},l=(u,p)=>{let m=r.get(p)||[],f=W(u,t);f&&m.push(f),r.set(p,[...m,u])},c=(u,p)=>{let m=u.groupIds.indexOf(p,0);return u.groupIds.slice(0,m).length>0?l(u,u.groupIds[m-1]):a(u)},d=e.every(u=>bm(n,u));return o.forEach(u=>{let p=Sm(u,n.selectedGroupIds);p?i.length===1&&d?c(u,p):l(u,p):a(u)}),Array.from(r.values()).concat(Array.from(s.values()))};var wl=e=>{let t=new Set;return e.forEach(n=>{$(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},Or=(e,t,n,i=!0)=>{let[o,r,s,a]=H(t,n),l=e.filter(c=>{let[d,u,p,m]=he(c,n),f=vt(c,n);if(f){let[E,h,g,x]=he(f,n);d=Math.max(E,d),u=Math.max(h,u),p=Math.min(g,p),m=Math.min(x,m)}return c.locked===!1&&c.type!=="selection"&&!de(c)&&o<=d&&r<=u&&s>=p&&a>=m});return l=i?wl(l):l,l=l.filter(c=>{let d=vt(c,n);return d?Zt(c,d,n):!0}),l},tb=(e,t,n,i)=>{let o=new Set(t.map(r=>r.id));return e.filter(r=>{let s=yl(r,n.width,n.height,n,i);return!o.has(r.id)&&s})},nb=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&&de(r)&&t.selectedElementIds[r?.containerId]){o.push(r),i.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return o.forEach(s=>{$(s)&&qt(e,s.id).forEach(a=>!i.has(a.id)&&r.push(a)),r.push(s)}),r}return o},ib=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:pt(e,t,{includeBoundTextElement:!0}),Br=(e,t)=>Tm(t.selectedElementIds,e)?t.selectedElementIds:e,Am=(e,t)=>{let n=e.filter(X);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 Y(i,Mm(t))}return null},ob=(e,t,n)=>({selectedLinearElement:Am(e,t),...ml({editingGroupId:n.editingGroupId,selectedElementIds:wl(e).reduce((i,o)=>(de(o)||(i[o.id]=!0),i),{})},t,n,null)});var bl=(e,t,n)=>{let i=mt(e);for(let o of t)if(o.frameId){let r=n.get(o.id),s=n.get(o.frameId),a=r&&i.get(r);a&&ye(a,i,{frameId:s??null})}};function Gn(e,t,n){let i=kr(t,n),o=kr(e,n);return i.some(s=>o.some(a=>ll(s,a)))}var Pl=(e,t,n)=>po(Or(e,t,n,!1)).filter(i=>!$(i)&&!i.frameId||i.frameId===t.id),Fr=(e,t,n)=>Or([t],e,n).some(i=>i.id===t.id),gb=(e,t)=>{let n=mt(e);return e.filter(i=>Gn(i,t,n))},Kt=(e,t,n)=>{let[i,o,r,s]=H(t,n),[a,l,c,d]=tt(e);return i<=a&&o<=l&&r>=c&&s>=d},Zt=(e,t,n)=>Kt([e],t,n)||Gn(e,t,n)||Fr(e,t,n),xb=(e,t,n)=>{let[i,o,r,s]=H(t,n);return Dm(Rr(i,o),Rr(e.x,e.y),Rr(r,s))},wb=(e,t,n)=>{let i=mt(e),o=t.flatMap(r=>Ae(e,r));return o.length===0?!0:!!o.find(r=>Kt([r],n,i)||Gn(r,n,i))},yb=(e,t,n)=>{let i=mt(e),o=t.flatMap(r=>Ae(e,r));return o.length===0?!0:o.find(r=>Kt([r],n,i)||Gn(r,n,i))===void 0},bb=e=>{let t=new Map;for(let n of e){let i=$(n)?n.id:n.frameId;i&&!t.has(i)&&t.set(i,qt(e,i))}return t},qt=(e,t)=>{let n=[];for(let i of e.values())i.frameId===t&&n.push(i);return n},vm=e=>e.filter(t=>$(t)),Pb=e=>{let t=mt(vm(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},Ib=(e,t,n,i)=>{let o=qt(e,t.id),r=new Set(o),s=new Set([...Pl(e,t,i),...o.filter(p=>Fr(p,t,i))]),a=o.filter(p=>!s.has(p)),l=new Set(Array.from(s).flatMap(p=>p.groupIds));for(let p of a)if(!Gn(p,t,i))p.groupIds.length===0&&r.delete(p);else if(p.groupIds.length>0)for(let m of p.groupIds)l.add(m);for(let p of a)if(p.groupIds.length>0){let m=!0;for(let f of p.groupIds)l.has(f)&&(m=!1);m&&r.delete(p)}let c=Array.from(s).filter(p=>p.groupIds.length===0);for(let p of c)r.add(p);let d=Array.from(s).filter(p=>p.groupIds.length>0),u=fl(d,n);for(let[p,m]of Object.entries(u))if(m){let f=Ae(e,p);if(Kt(f,t,i))for(let E of f)r.add(E)}return[...r].filter(p=>!(ie(p)&&p.containerId))},Sb=(e,t,n)=>Lm(po(e,Pl(e,t,n)),t,n),Lm=(e,t,n)=>{let i=[],o=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>o.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>Ae(n,l)));s=!Kt(Array.from(a),t,n)}r.groupIds.forEach(a=>{o.set(a,s)})}s||i.push(r)}return i},vt=(e,t)=>e.frameId&&t.get(e.frameId)||null,Mb=(e,t)=>{let n=new Set,i=mt(e);e=po(e);for(let s of e)$(s)&&s.id!==t.id&&n.add(s.id);let o=new Set,r=[];for(let s of e)if(!($(s)||s.frameId&&n.has(s.frameId)))if(s.groupIds.length){let a=s.groupIds.at(-1);if(!o.has(a)){o.add(a);let l=Ae(e,a);if(l.some(c=>Zt(c,t,i)))for(let c of l)r.push(c)}}else Zt(s,t,i)&&r.push(s);return r},Cm=(e,t,n,i)=>{let o=mt(e),r=new Map;for(let c of e.values())c.frameId===n.id&&r.set(c.id,!0);let s=new Set(t.map(c=>c.id)),a=[],l=new Set;for(let c of t)$(c)&&c.id!==n.id&&l.add(c.id);for(let c of po(e,t)){if($(c)||c.frameId&&l.has(c.frameId)||c.frameId&&i.selectedElementIds[c.id]&&i.selectedElementIds[c.frameId])continue;r.has(c.id)||a.push(c);let d=W(c,o);d&&!s.has(d.id)&&!r.has(d.id)&&a.push(d)}for(let c of a)ye(c,o,{frameId:n.id});return e},Il=(e,t)=>{let n=new Map,i=new Map;for(let o of e)if(o.frameId){n.set(o.id,o);let r=i.get(o.frameId)||[];r.push(o);let s=W(o,t);s&&(n.set(s.id,s),r.push(s)),i.set(o.frameId,r)}for(let[,o]of n)ye(o,t,{frameId:null})},Bm=(e,t)=>{let n=qt(e,t.id);return Il(n,mt(e)),e},Tb=(e,t,n,i)=>Cm(Bm(e,n),t,n,i.state).slice(),Ab=(e,t,n)=>{let i=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),o=new Set(i);if(t.editingGroupId)for(let a of i)a.groupIds.length===0?o.add(a):a.groupIds.flatMap(l=>Ae(e,l)).forEach(l=>o.add(l));let r=new Set,s=mt(e);return o.forEach(a=>{a.frameId&&!$(a)&&!Sl(a,s,t)&&r.add(a)}),r.size>0&&Il(r,s),e},po=(e,t)=>{let n=new Set,i=t||e;for(let s of i.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let o=new Set;for(let s of n)Ae(e,s).some(a=>$(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},Gm=(e,t,n)=>{let i=ie(e)&&Ce(e,t)||e;return i.frameId&&n.selectedElementIds[i.id]&&n.selectedElementIds[i.frameId]?vt(i,t):n.selectedElementIds[i.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:vt(i,t)},Sl=(e,t,n,i)=>{let o=i?.targetFrame??Gm(e,t,n);if(!o)return!1;let r=ie(e)&&Ce(e,t)||e,s=l=>{i?.checkedGroups&&r.groupIds.forEach(c=>{i.checkedGroups?.set(c,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[o.id])return!0;if(r.groupIds.length===0)return Zt(r,o,t);for(let l of r.groupIds)if(i?.checkedGroups?.has(l))return i.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>i?.checkedGroups?!i.checkedGroups.has(l):!0).flatMap(l=>Ae(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(pt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(d=>{a.delete(d)})}for(let l of a)if($(l))return s(!1),!1;for(let l of a)if(Zt(l,o,t))return s(!0),!0;return!1},Db=(e,t,n,i,o)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=Gn(e,t,i)||Fr(e,t,i);if(r){for(let s of e.groupIds)o?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Kt([e],t,i)){let s=!1;if(n.selectedElementsAreBeingDragged)s=Sl(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},Om="Frame",Rm="AI Frame",km=e=>Ri(e)?Om:Rm,vb=e=>e.name===null?km(e):e.name,Lb=(e,t)=>pl({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),Cb=e=>{let t=mt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Um="invert(100%) hue-rotate(180deg) saturate(1.25)",Dl=(e,t)=>zt(e)&&!t.imageCache.has(e.fileId),vl=(e,t,n)=>n.theme===Al.DARK&&zt(e)&&!Dl(e,t)&&t.imageCache.get(e.fileId)?.mimeType!==zr.svg,go=e=>{switch(e.type){case"freedraw":return e.strokeWidth*12;case"text":return e.fontSize/2;case"arrow":return e.endArrowhead||e.endArrowhead?40:20;default:return 20}},Xm=(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*=zm/100),r},Wm=(e,t,n)=>{let r=go(e),[s,a,l,c]=H(e,t),d=X(e)||Se(e)?Qt(s,l):e.width,u=X(e)||Se(e)?Qt(a,c):e.height,p=d*window.devicePixelRatio+r*2,m=u*window.devicePixelRatio+r*2,f=n.value;return(p*f>32767||m*f>32767)&&(f=Math.min(32767/p,32767/m)),p*m*f*f>16777216&&(f=Math.sqrt(16777216/(p*m))),p=Math.floor(p*f),m=Math.floor(m*f),{width:p,height:m,scale:f}},Ll=(e,t,n,i,o)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=go(e),{width:l,height:c,scale:d}=Wm(e,t,n);if(!l||!c)return null;r.width=l,r.height=c;let u=-100,p=0;if(X(e)||Se(e)){let[g,x]=H(e,t);u=e.x>g?Qt(e.x,g)*window.devicePixelRatio*d:0,p=e.y>x?Qt(e.y,x)*window.devicePixelRatio*d:0,s.translate(u,p)}s.save(),s.translate(a*d,a*d),s.scale(window.devicePixelRatio*d,window.devicePixelRatio*d);let m=an.canvas(r);vl(e,i,o)&&(s.filter=Um),ho(e,m,s,i,o),s.restore();let f=W(e,t),E=document.createElement("canvas"),h=E.getContext("2d");if(_(e)&&f){let[g,x,y,b]=H(e,t),w=Math.max(Qt(g,y),Qt(x,b));E.width=w*window.devicePixelRatio*d+a*d*10,E.height=w*window.devicePixelRatio*d+a*d*10,h.translate(E.width/2,E.height/2),h.rotate(e.angle),h.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,I,M]=H(f,t);h.rotate(-e.angle);let D=(E.width-r.width)/2,T=(E.height-r.height)/2,F=E.width/2-(I-g)*window.devicePixelRatio*d-D-a*d,C=E.height/2-(M-x)*window.devicePixelRatio*d-T-a*d;h.translate(-F,-C),h.clearRect(-(f.width/2+mo)*window.devicePixelRatio*d,-(f.height/2+mo)*window.devicePixelRatio*d,(f.width+mo*2)*window.devicePixelRatio*d,(f.height+mo*2)*window.devicePixelRatio*d)}return{element:e,canvas:r,theme:o.theme,scale:d,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:p,boundTextElementVersion:W(e,t)?.version||null,containingFrameOpacity:vt(e,t)?.opacity||100,boundTextCanvas:E,angle:e.angle,imageCrop:xe(e)?e.crop:null}},Vb=14,Cl=typeof document<"u"?document.createElement("img"):{src:""};Cl.src=`data:${zr.svg},${encodeURIComponent('<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>')}`;var Bl=typeof document<"u"?document.createElement("img"):{src:""};Bl.src=`data:${zr.svg},${encodeURIComponent('<svg viewBox="0 0 668 668" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48ZM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56ZM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.81709 0 0 .81709 124.825 145.825)"/><path d="M256 8C119.034 8 8 119.033 8 256c0 136.967 111.034 248 248 248s248-111.034 248-248S392.967 8 256 8Zm130.108 117.892c65.448 65.448 70 165.481 20.677 235.637L150.47 105.216c70.204-49.356 170.226-44.735 235.638 20.676ZM125.892 386.108c-65.448-65.448-70-165.481-20.677-235.637L361.53 406.784c-70.203 49.356-170.226 44.736-235.638-20.676Z" style="fill:#888;fill-rule:nonzero" transform="matrix(.30366 0 0 .30366 506.822 60.065)"/></svg>')}`;var jm=(e,t)=>{t.fillStyle="#E7E7E7",t.fillRect(0,0,e.width,e.height);let n=Math.min(e.width,e.height),i=Math.min(n,Math.min(n*.4,100));t.drawImage(e.status==="error"?Bl:Cl,e.width/2-i/2,e.height/2-i/2,i,i)},ho=(e,t,n,i,o)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(be.get(e));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",be.get(e).forEach(r=>{t.draw(r)});break}case"freedraw":{n.save(),n.fillStyle=e.strokeColor;let r=Vm(e),s=be.get(e);s&&t.draw(s),n.fillStyle=e.strokeColor,n.fill(r),n.restore();break}case"image":{let r=zt(e)?i.imageCache.get(e.fileId)?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,yt(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:c}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight};n.drawImage(r,s,a,l,c,0,0,e.width,e.height)}else jm(e,n);break}default:if(ie(e)){let r=_m(e.text),s=r&&!n.canvas.isConnected;s&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",r?"rtl":"ltr"),n.save(),n.font=Hm(e),n.fillStyle=e.strokeColor,n.textAlign=e.textAlign;let a=e.text.replace(/\r\n?/g,`
9
+ `)=>e.reduce((o,i)=>(oe(i)&&o.push(i.text),o),[]).join(t);P();import{curvePointDistance as cr,distanceToLineSegment as ur,pointRotateRads as pr}from"@excalidraw/math";import{ellipse as Uu,ellipseDistanceFromPoint as Xu}from"@excalidraw/math/ellipse";var Ut=(e,t,n)=>{switch(e.type){case"selection":case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"magicframe":return ju(e,t,n);case"diamond":return Wu(e,t,n);case"ellipse":return Vu(e,t,n);case"line":case"arrow":case"freedraw":return $u(e,n)}},ju=(e,t,n)=>{let o=he(e,t),i=pr(n,o,-e.angle),[r,s]=Mn(e);return Math.min(...r.map(a=>ur(i,a)),...s.map(a=>cr(a,i)).filter(a=>a!==null))},Wu=(e,t,n)=>{let o=he(e,t),i=pr(n,o,-e.angle),[r,s]=Tn(e);return Math.min(...r.map(a=>ur(i,a)),...s.map(a=>cr(a,i)).filter(a=>a!==null))},Vu=(e,t,n)=>{let o=he(e,t);return Xu(pr(n,o,-e.angle),Uu(o,e.width/2,e.height/2))},$u=(e,t)=>{let[n,o]=Bo(e);return Math.min(...n.map(i=>ur(t,i)),...o.map(i=>cr(i,t)))};var Wo=e=>{if(e.type==="arrow")return!1;let t=!Zu(e.backgroundColor)||st(e)||Ro(e)||oe(e);return e.type==="line"?t&&mn(e.points):e.type==="freedraw"?t&&mn(e.points):t||we(e)},op=({point:e,element:t,threshold:n,elementsMap:o,frameNameBound:i=null})=>{let r=i?Xo(Mt(i.x-n,i.y-n),e,Mt(i.x+i.width+n,i.y+i.height+n)):!1,s=pe(t,o,!0);return!Xo(Mt(s[0]-n,s[1]-n),lt(e,dt(s),-t.angle),Mt(s[2]+n,s[3]+n))&&!r?!1:Wo(t)&&Aa(e,t,o)||Pa(e,t,o,n)||r},ip=(e,t,n,o=0)=>{let[i,r,s,a]=pe(t,n);return i-=o,r-=o,s+=o,a+=o,Xo(Mt(i,r),e,Mt(s,a))},kw=(e,t)=>!op(e)&&!rp(e.point,e.element,t)&&ip(e.point,e.element,t),rp=(e,t,n)=>{let o=W(t,n);if(!o)return!1;let i=j(t)?{...o,...U.getBoundTextElementPosition(t,o,n)}:o;return Aa(e,i,n)},En=(e,t,n,o=0,i=!1)=>{let r=[Math.min(n[0][0]-o,n[1][0]-o),Math.min(n[0][1]-o,n[1][1]-o),Math.max(n[0][0]+o,n[1][0]+o),Math.max(n[0][1]+o,n[1][1]+o)],s=pe(e,t);if(!gn(r,s))return[];switch(e.type){case"rectangle":case"image":case"text":case"iframe":case"embeddable":case"frame":case"selection":case"magicframe":return ap(e,t,n,o,i);case"diamond":return lp(e,t,n,o,i);case"ellipse":return dp(e,t,n,o);case"line":case"freedraw":case"arrow":return sp(e,n,i)}},Ma=(e,t,n,o,i,r=!1)=>{for(let s of e){let a=Vo(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!gn(a,l))continue;let d=Ia(s,t);if(d.length>0){for(let c of d)n.push(lt(c,o,i));if(r)return n}}return n},Ta=(e,t,n,o,i,r=!1)=>{for(let s of e){let a=Sa(s,t);if(a&&(n.push(lt(a,o,i)),r))return n}return n},sp=(e,t,n=!1)=>{let[o,i]=Bo(e),r=[];for(let s of o){let a=Sa(s,t);if(a&&(r.push(a),n))return r}for(let s of i){let a=Vo(s[0],s[1],s[2],s[3]),l=[Math.min(t[0][0],t[1][0]),Math.min(t[0][1],t[1][1]),Math.max(t[0][0],t[1][0]),Math.max(t[0][1],t[1][1])];if(!gn(a,l))continue;let d=Ia(s,t);if(d.length>0&&(r.push(...d),n))return r}return r},ap=(e,t,n,o=0,i=!1)=>{let r=he(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=jo(s,a),[d,c]=Mn(e,o),u=[];return Ta(d,l,u,r,e.angle,i),i&&u.length>0||Ma(c,l,u,r,e.angle,i),u},lp=(e,t,n,o=0,i=!1)=>{let r=he(e,t),s=lt(n[0],r,-e.angle),a=lt(n[1],r,-e.angle),l=jo(s,a),[d,c]=Tn(e,o),u=[];return Ta(d,l,u,r,e.angle,i),i&&u.length>0||Ma(c,l,u,r,e.angle,i),u},dp=(e,t,n,o=0)=>{let i=he(e,t),r=lt(n[0],i,-e.angle),s=lt(n[1],i,-e.angle);return np(tp(i,e.width/2+o,e.height/2+o),jo(r,s)).map(a=>lt(a,i,e.angle))},Pa=(e,t,n,o=1)=>Ut(t,n,e)<=o,Aa=(e,t,n)=>{if((j(t)||Me(t))&&!mn(t.points))return!1;let[o,i,r,s]=pe(t,n);if(!Xo(Mt(o,i),e,Mt(r,s)))return!1;let a=Mt((o+r)/2,(i+s)/2),l=qu(ep(Ju(Qu(e,a,.1)),Math.max(t.width,t.height)*2),a),d=jo(e,l);return En(t,n,d).filter((u,p,m)=>m.findIndex(f=>Ku(f,u))===p).length%2===1};P();import{invariant as Da,isDevEnv as cp,isTestEnv as up}from"@excalidraw/common";import{pointFrom as Xt,pointFromVector as $o,pointRotateRads as Zo,pointScaleFromOrigin as qo,pointsEqual as pp,triangleIncludesPoint as mr,vectorCross as Ge,vectorFromPoint as K,vectorScale as Ko}from"@excalidraw/math";var fe=[1,0],ye=[0,1],ke=[-1,0],_e=[0,-1],Tt=e=>{let[t,n]=e,o=Math.abs(t),i=Math.abs(n);return t>i?fe:t<=-i?ke:n>o?ye:_e},Be=(e,t)=>Tt(K(e,t)),tt=(e,t)=>Oe(Be(e,t)),me=(e,t)=>e[0]===t[0]&&e[1]===t[1],Oe=e=>me(e,fe)||me(e,ke),zw=e=>!Oe(e),mp=(e,t,n)=>{let o=dt(t);(cp()||up())&&(Da(e.width>0&&e.height>0,"Diamond element has no width or height"),Da(!pp(o,n),"The point is too close to the element mid point to determine heading"));let i=.95,r=$o(Ko(K(Zo(Xt(e.x+e.width/2,e.y),o,e.angle),o),i),o),s=$o(Ko(K(Zo(Xt(e.x+e.width,e.y+e.height/2),o,e.angle),o),i),o),a=$o(Ko(K(Zo(Xt(e.x+e.width/2,e.y+e.height),o,e.angle),o),i),o),l=$o(Ko(K(Zo(Xt(e.x,e.y+e.height/2),o,e.angle),o),i),o);if(Ge(K(n,r),K(r,s))<=0&&Ge(K(n,r),K(r,l))>0)return Be(r,o);if(Ge(K(n,s),K(s,a))<=0&&Ge(K(n,s),K(s,r))>0)return Be(s,o);if(Ge(K(n,a),K(a,l))<=0&&Ge(K(n,a),K(a,s))>0)return Be(a,o);if(Ge(K(n,l),K(l,r))<=0&&Ge(K(n,l),K(l,a))>0)return Be(l,o);if(Ge(K(n,o),K(r,o))<=0&&Ge(K(n,o),K(s,o))>0){let c=e.width>e.height?r:s;return Be(c,o)}else if(Ge(K(n,o),K(s,o))<=0&&Ge(K(n,o),K(a,o))>0){let c=e.width>e.height?a:s;return Be(c,o)}else if(Ge(K(n,o),K(a,o))<=0&&Ge(K(n,o),K(l,o))>0){let c=e.width>e.height?a:l;return Be(c,o)}let d=e.width>e.height?r:l;return Be(d,o)},oo=(e,t,n)=>{let i=dt(t);if(e.type==="diamond")return mp(e,t,n);let r=qo(Xt(t[0],t[1]),i,2),s=qo(Xt(t[2],t[1]),i,2),a=qo(Xt(t[0],t[3]),i,2),l=qo(Xt(t[2],t[3]),i,2);return mr([r,s,i],n)?_e:mr([s,l,i],n)?fe:mr([l,a,i],n)?ye:ke},fr=e=>[e[0]===0?0:e[0]>0?-1:1,e[1]===0?0:e[1]>0?-1:1];P();import{getSizeFromPoints as Gp,randomInteger as Mr,getUpdatedTimestamp as Tr}from"@excalidraw/common";P();import{clamp as Qo,pointDistance as gr,pointFrom as z,pointScaleFromOrigin as fp,pointsEqual as ro,pointTranslate as Er,vector as ct,vectorCross as Jo,vectorFromPoint as xr,vectorScale as hp}from"@excalidraw/math";import{BinaryHeap as Ep,invariant as Dn,isAnyTrue as gp,tupleToCoors as xp,getSizeFromPoints as va,isDevEnv as wp,arrayToMap as yp}from"@excalidraw/common";var wr=1,ee=40,bp=(e,t)=>{let n=e.fixedSegments?e.fixedSegments.slice():null;if(n){let o=[];e.points.map(s=>z(e.x+s[0],e.y+s[1])).forEach((s,a,l)=>{if(a<2)return o.push(s);let d=Be(s,l[a-1]),c=Be(l[a-1],l[a-2]);if(me(d,c)){let u=n?.findIndex(m=>m.index===a-1)??-1,p=n?.findIndex(m=>m.index===a)??-1;p!==-1&&(n[p].start=z(l[a-2][0]-e.x,l[a-2][1]-e.y)),u!==-1&&n.splice(u,1),o.splice(-1,1),n.forEach(m=>{m.index>a-1&&(m.index-=1)})}return o.push(s)});let i=[];o.forEach((s,a,l)=>{if(a<3)return i.push(s);if(gr(l[a-2],l[a-1])<wr){let d=n?.findIndex(p=>p.index===a-2)??-1,c=n?.findIndex(p=>p.index===a-1)??-1;c!==-1&&n.splice(c,1),d!==-1&&n.splice(d,1),i.splice(-2,2),n.forEach(p=>{p.index>a-2&&(p.index-=2)});let u=tt(s,l[a-1]);return i.push(z(u?s[0]:l[a-2][0],u?l[a-2][1]:s[1]))}i.push(s)});let r=n.filter(s=>s.index!==1&&s.index!==i.length-1);return r.length===0?At(Pr(Ir(br(e,yr(e,t,i.map(s=>z(s[0]-e.x,s[1]-e.y))))??[])),r,null,null):(wp()&&Dn(Ra(i),"Invalid elbow points with fixed segments"),At(i,r,e.startIsSpecial,e.endIsSpecial))}return{x:e.x,y:e.y,points:e.points,fixedSegments:e.fixedSegments,startIsSpecial:e.startIsSpecial,endIsSpecial:e.endIsSpecial}},Pp=(e,t,n)=>{let o=t.map(T=>T.index),r=(e.fixedSegments?.map(T=>T.index)??[]).findIndex(T=>!o.includes(T));if(r===-1||!e.fixedSegments?.[r])return{points:e.points};let s=e.fixedSegments[r].index,a=e.fixedSegments[r-1],l=e.fixedSegments[r+1],d=e.x+(a?a.end[0]:0),c=e.y+(a?a.end[1]:0),u=a?null:e.startBinding,p=l?null:e.endBinding,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y}=yr({x:d,y:c,startBinding:u,endBinding:p,startArrowhead:null,endArrowhead:null,points:e.points},n,[z(0,0),z(e.x+(l?.start[0]??e.points[e.points.length-1][0])-d,e.y+(l?.start[1]??e.points[e.points.length-1][1])-c)],{isDragging:!1}),{points:b}=At(Pr(Ir(br(e,{startHeading:m,endHeading:f,startGlobalPoint:E,endGlobalPoint:h,hoveredStartElement:g,hoveredEndElement:x,...y})??[])),t,null,null);if(!b||b.length<2)throw new Error("Property 'points' is required in the update returned by normalizeArrowElementUpdate()");let w=[];if(a)for(let T=0;T<a.index;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));if(b.forEach(T=>{w.push(z(e.x+(a?a.end[0]:0)+T[0],e.y+(a?a.end[1]:0)+T[1]))}),l)for(let T=l.index;T<e.points.length;T++)w.push(z(e.x+e.points[T][0],e.y+e.points[T][1]));let I=(l?.index??e.points.length)-(a?.index??0)-1,M=t.map(T=>T.index>s?{...T,index:T.index-I+(b.length-1)}:T),D=w.flatMap((T,N)=>{let C=w[N-1],R=w[N+1];if(C&&R){let L=Be(T,C),$=Be(R,T);if(me(L,$))return M.forEach(H=>{H.index>N&&(H.index-=1)}),[];if(me(L,fr($)))return M.forEach(H=>{H.index>N&&(H.index+=1)}),[T,T]}return[T]});return At(D,M,!1,!1)},Ip=(e,t,n,o,i,r)=>{let s=t.map((w,I)=>e.fixedSegments==null||e.fixedSegments[I]===void 0||e.fixedSegments[I].index!==w.index||(w.start[0]!==e.fixedSegments[I].start[0]&&w.end[0]!==e.fixedSegments[I].end[0])!=(w.start[1]!==e.fixedSegments[I].start[1]&&w.end[1]!==e.fixedSegments[I].end[1])?I:null).filter(w=>w!==null).shift();if(s==null)return{points:e.points};let a=e.fixedSegments?.findIndex(w=>w.index===1)??-1,l=e.fixedSegments?.findIndex(w=>w.index===e.points.length-1)??-1,d=gr(t[s].start,t[s].end),c=d<ee+5;if(a===-1&&t[s].index===1&&i){let w=Oe(n),M=(w?me(n,fe):me(n,ye))?c?d/2:ee:c?-d/2:-ee;t[s].start=z(t[s].start[0]+(w?M:0),t[s].start[1]+(w?0:M))}if(l===-1&&t[s].index===e.points.length-1&&r){let w=Oe(o),M=(w?me(o,fe):me(o,ye))?c?d/2:ee:c?-d/2:-ee;t[s].end=z(t[s].end[0]+(w?M:0),t[s].end[1]+(w?0:M))}let u=t.map(w=>({...w,start:z(e.x+w.start[0],e.y+w.start[1]),end:z(e.x+w.end[0],e.y+w.end[1])})),p=e.points.map((w,I)=>z(e.x+w[0],e.y+w[1])),m=u[s].index-1,f=u[s].index,E=u[s].start,h=u[s].end,g=p[m-1]&&!ro(p[m],p[m-1])?tt(p[m-1],p[m]):void 0,x=p[f+1]&&!ro(p[f],p[f+1])?tt(p[f+1],p[f]):void 0;if(g!==void 0){let w=g?1:0;p[m-1][w]=E[w]}if(p[m]=E,p[f]=h,x!==void 0){let w=x?1:0;p[f+1][w]=h[w]}let y=u.findIndex(w=>w.index===m);if(y!==-1){let w=tt(u[y].end,u[y].start)?1:0;u[y].start[w]=E[w],u[y].end=E}let b=u.findIndex(w=>w.index===f+1);if(b!==-1){let w=tt(u[b].end,u[b].start)?1:0;u[b].end[w]=h[w],u[b].start=h}if(a===-1&&m===0){let w=i?Oe(n):tt(p[1],p[0]);p.unshift(z(w?E[0]:e.x+e.points[0][0],w?e.y+e.points[0][1]:E[1])),i&&p.unshift(z(e.x+e.points[0][0],e.y+e.points[0][1]));for(let I of u)I.index+=i?2:1}if(l===-1&&f===e.points.length-1){let w=Oe(o);p.push(z(w?h[0]:e.x+e.points[e.points.length-1][0],w?e.y+e.points[e.points.length-1][1]:h[1])),r&&p.push(z(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]))}return At(p,u.map(w=>({...w,start:z(w.start[0]-e.x,w.start[1]-e.y),end:z(w.end[0]-e.x,w.end[1]-e.y)})),!1,!1)},Sp=(e,t,n,o,i,r,s,a,l)=>{let d=e.startIsSpecial??null,c=e.endIsSpecial??null,u=t.map((h,g)=>g===0?z(e.x+h[0],e.y+h[1]):g===t.length-1?z(e.x+h[0],e.y+h[1]):z(e.x+e.points[g][0],e.y+e.points[g][1])),p=n.map(h=>({...h,start:z(e.x+(h.start[0]-t[0][0]),e.y+(h.start[1]-t[0][1])),end:z(e.x+(h.end[0]-t[0][0]),e.y+(h.end[1]-t[0][1]))})),m=[],f=2+(d?1:0),E=2+(c?1:0);for(;m.length+f<u.length-E;)m.push(u[m.length+f]);{let h=u.at(d?2:1),g=u.at(d?3:2);if(!h||!g)throw new Error(`Second and third points must exist when handling endpoint drag (${d})`);let x=Oe(o),y=Oe(Tt(xr(h,g)));if(a&&x===y){let b=x?me(o,fe):me(o,ye);if(m.unshift(z(y?r[0]+(b?ee:-ee):g[0],y?g[1]:r[1]+(b?ee:-ee))),m.unshift(z(x?r[0]+(b?ee:-ee):r[0],x?r[1]:r[1]+(b?ee:-ee))),!d){d=!0;for(let w of p)w.index>1&&(w.index+=1)}}else if(m.unshift(z(y?r[0]:h[0],y?h[1]:r[1])),d){d=!1;for(let b of p)b.index>1&&(b.index-=1)}m.unshift(r)}{let h=u.at(u.length-(c?3:2)),g=u.at(u.length-(c?4:3));if(!h||!g)throw new Error(`Second and third to last points must exist when handling endpoint drag (${c})`);let x=Oe(i),y=tt(g,h);if(l&&x===y){let b=x?me(i,fe):me(i,ye);m.push(z(y?s[0]+(b?ee:-ee):g[0],y?g[1]:s[1]+(b?ee:-ee))),m.push(z(x?s[0]+(b?ee:-ee):s[0],x?s[1]:s[1]+(b?ee:-ee))),c||(c=!0)}else m.push(z(y?s[0]:h[0],y?h[1]:s[1])),c&&(c=!1)}return m.push(s),At(m,p.map(({index:h})=>({index:h,start:m[h-1],end:m[h]})).map(h=>({...h,start:z(h.start[0]-r[0],h.start[1]-r[1]),end:z(h.end[0]-r[0],h.end[1]-r[1])})),d,c)},jt=1e6,Ln=(e,t,n,o)=>{if(e.points.length<2)return{points:n.points??e.points};A.PROD||(Dn(!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)"),Dn(!e.fixedSegments||e.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Fixed segments must be either horizontal or vertical"),Dn(!n.fixedSegments||n.fixedSegments.map(w=>w.start[0]===w.end[0]||w.start[1]===w.end[1]).every(Boolean),"Updates to fixed segments must be either horizontal or vertical"),Dn(e.points.slice(1).map((w,I)=>w[0]===e.points[I][0]||w[1]===e.points[I][1]),"Elbow arrow segments must be either horizontal or vertical"),Dn(n.fixedSegments?.find(w=>w.index===1&&ro(w.start,(n.points??e.points)[0]))==null&&n.fixedSegments?.find(w=>w.index===(n.points??e.points).length-1&&ro(w.end,(n.points??e.points)[(n.points??e.points).length-1]))==null,"The first and last segments cannot be fixed"));let i=n.fixedSegments??e.fixedSegments??[],r=n.points?n.points&&n.points.length===2?e.points.map((w,I)=>I===0?n.points[0]:I===e.points.length-1?n.points[1]:w):n.points.slice():e.points.slice(),{startBinding:s,endBinding:a,...l}=n,d=typeof s<"u"?s:e.startBinding,c=typeof a<"u"?a:e.endBinding,u=d&&ti(d.elementId,t),p=c&&ti(c.elementId,t),m=Ra(r);if(d&&!u&&m||c&&!p&&m||t.size===0&&m||Object.keys(l).length===0&&(u?.id!==d?.elementId||p?.id!==c?.elementId))return At(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial);let{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b}=yr({x:e.x,y:e.y,startBinding:d,endBinding:c,startArrowhead:e.startArrowhead,endArrowhead:e.endArrowhead,points:e.points},t,r,o);return t.size===0&&m?At(r.map(w=>z(e.x+w[0],e.y+w[1])),e.fixedSegments,e.startIsSpecial,e.endIsSpecial):!n.points&&!n.fixedSegments&&!n.startBinding&&!n.endBinding?bp(e,t):n.startBinding===e.startBinding&&n.endBinding===e.endBinding&&(n.points??[]).every((w,I)=>ro(w,e.points[I]??z(1/0,1/0)))&&m?{}:i.length===0?At(Pr(Ir(br(e,{startHeading:f,endHeading:E,startGlobalPoint:h,endGlobalPoint:g,hoveredStartElement:x,hoveredEndElement:y,...b})??[])),i,null,null):(e.fixedSegments?.length??0)>i.length?Pp(e,i,t):n.points?n.points&&n.fixedSegments?n:Sp(e,r,i,f,E,h,g,x,y):Ip(e,i,f,E,x,y)},yr=(e,t,n,o)=>{let i=Er(n[0],ct(e.x,e.y)),r=Er(n[n.length-1],ct(e.x,e.y)),s=null,a=null;if(o?.isDragging){let w=Array.from(t.values());s=Ba(i,t,w,o?.zoom)||null,a=Ba(r,t,w,o?.zoom)||null}else s=e.startBinding&&ti(e.startBinding.elementId,t)||null,a=e.endBinding&&ti(e.endBinding.elementId,t)||null;let l=Ca({...e,type:"arrow",elbowed:!0,points:n},"start",e.startBinding?.fixedPoint,i,s,t,o?.isDragging),d=Ca({...e,type:"arrow",elbowed:!0,points:n},"end",e.endBinding?.fixedPoint,r,a,t,o?.isDragging),c=Ga(l,d,s,i,t),u=Ga(d,l,a,r,t),p=[l[0]-2,l[1]-2,l[0]+2,l[1]+2],m=[d[0]-2,d[1]-2,d[0]+2,d[1]+2],f=s?$e(s,t,Wt(c,e.startArrowhead?ie*6:ie*2,1)):p,E=a?$e(a,t,Wt(u,e.endArrowhead?ie*6:ie*2,1)):m,h=vn(l,a?$e(a,t,Wt(u,ee,ee)):m)||vn(d,s?$e(s,t,Wt(c,ee,ee)):p),g=Oa(h?[p,m]:[f,E]),x=Ap(h?p:f,h?m:E,g,h?Wt(c,!s&&!a?0:ee,0):Wt(c,!s&&!a?0:ee-(e.startArrowhead?ie*6:ie*2),ee),h?Wt(u,!s&&!a?0:ee,0):Wt(u,!s&&!a?0:ee-(e.endArrowhead?ie*6:ie*2),ee),h,s&&$e(s,t),a&&$e(a,t)),y=La(x[0],c,l),b=La(x[1],u,d);return{dynamicAABBs:x,startDonglePosition:y,startGlobalPoint:l,startHeading:c,endDonglePosition:b,endGlobalPoint:d,endHeading:u,commonBounds:g,hoveredStartElement:s,hoveredEndElement:a,boundsOverlap:h,startElementBounds:f,endElementBounds:E}},br=(e,t)=>{let{dynamicAABBs:n,startDonglePosition:o,startGlobalPoint:i,startHeading:r,endDonglePosition:s,endGlobalPoint:a,endHeading:l,commonBounds:d,hoveredEndElement:c}=t,u=Dp(n,o||i,r,s||a,l,d),p=o&&ei(o,u),m=s&&ei(s,u),f=ei(a,u);f&&c&&(f.closed=!0);let E=ei(i,u);E&&e.startBinding&&(E.closed=!0);let h=p&&m&&(vn(p.pos,n[1])||vn(m.pos,n[0])),g=Mp(p||E,m||f,u,r||fe,l||fe,h?[]:n);if(g){let x=g.map(y=>[y.pos[0],y.pos[1]]);return p&&x.unshift(i),m&&x.push(a),x}return null},Wt=(e,t,n)=>{switch(e){case _e:return[t,n,n,n];case fe:return[n,t,n,n];case ye:return[n,n,t,n]}return[n,n,n,t]},Mp=(e,t,n,o,i,r)=>{let s=hr(e.pos,t.pos),a=new Ep(l=>l.f);for(a.push(e);a.size()>0;){let l=a.pop();if(!l||l.closed)continue;if(l===t)return Tp(e,l);l.closed=!0;let d=Lp(l.addr,n);for(let c=0;c<4;c++){let u=d[c];if(!u||u.closed)continue;let p=fp(u.pos,l.pos,.5);if(gp(...r.map(b=>vn(p,b))))continue;let m=Cp(c),f=l.parent?Tt(xr(l.pos,l.parent.pos)):o,E=fr(f);if(me(E,m)||ka(e.addr,u.addr)&&me(m,o)||ka(t.addr,u.addr)&&me(m,i))continue;let g=f!==m,x=l.g+hr(u.pos,l.pos)+(g?Math.pow(s,3):0),y=u.visited;if(!y||x<u.g){let b=vp(u,t,m,i);u.visited=!0,u.parent=l,u.h=hr(t.pos,u.pos)+b*Math.pow(s,2),u.g=x,u.f=u.g+u.h,y?a.rescoreElement(u):a.push(u)}}}return null},Tp=(e,t)=>{let n=t,o=[];for(;n.parent;)o.unshift(n),n=n.parent;return o.unshift(e),o},hr=(e,t)=>Math.abs(e[0]-t[0])+Math.abs(e[1]-t[1]),Ap=(e,t,n,o,i,r,s,a)=>{let l=s??e,d=a??t,[c,u,p,m]=o??[0,0,0,0],[f,E,h,g]=i??[0,0,0,0],x=[e[0]>t[2]?e[1]>t[3]||e[3]<t[1]?Math.min((l[0]+d[2])/2,e[0]-m):(l[0]+d[2])/2:e[0]>t[0]?e[0]-m:n[0]-m,e[1]>t[3]?e[0]>t[2]||e[2]<t[0]?Math.min((l[1]+d[3])/2,e[1]-c):(l[1]+d[3])/2:e[1]>t[1]?e[1]-c:n[1]-c,e[2]<t[0]?e[1]>t[3]||e[3]<t[1]?Math.max((l[2]+d[0])/2,e[2]+u):(l[2]+d[0])/2:e[2]<t[2]?e[2]+u:n[2]+u,e[3]<t[1]?e[0]>t[2]||e[2]<t[0]?Math.max((l[3]+d[1])/2,e[3]+p):(l[3]+d[1])/2:e[3]<t[3]?e[3]+p:n[3]+p],y=[t[0]>e[2]?t[1]>e[3]||t[3]<e[1]?Math.min((d[0]+l[2])/2,t[0]-g):(d[0]+l[2])/2:t[0]>e[0]?t[0]-g:n[0]-g,t[1]>e[3]?t[0]>e[2]||t[2]<e[0]?Math.min((d[1]+l[3])/2,t[1]-f):(d[1]+l[3])/2:t[1]>e[1]?t[1]-f:n[1]-f,t[2]<e[0]?t[1]>e[3]||t[3]<e[1]?Math.max((d[2]+l[0])/2,t[2]+E):(d[2]+l[0])/2:t[2]<e[2]?t[2]+E:n[2]+E,t[3]<e[1]?t[0]>e[2]||t[2]<e[0]?Math.max((d[3]+l[1])/2,t[3]+h):(d[3]+l[1])/2:t[3]<e[3]?t[3]+h:n[3]+h],b=Oa([x,y]);if(!r&&x[2]-x[0]+y[2]-y[0]>b[2]-b[0]+1e-11&&x[3]-x[1]+y[3]-y[1]>b[3]-b[1]+1e-11){let[w,I]=[(y[0]+y[2])/2,(y[1]+y[3])/2];if(t[0]>e[2]&&e[1]>t[3]){let M=x[2]+(y[0]-x[2])/2,D=y[3]+(x[1]-y[3])/2;return Jo(ct(e[2]-w,e[1]-I),ct(e[0]-w,e[3]-I))>0?[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}else if(e[2]<t[0]&&e[3]<t[1]){let M=x[2]+(y[0]-x[2])/2,D=x[3]+(y[1]-x[3])/2;return Jo(ct(e[0]-w,e[1]-I),ct(e[2]-w,e[3]-I))>0?[[x[0],x[1],x[2],D],[y[0],D,y[2],y[3]]]:[[x[0],x[1],M,x[3]],[M,y[1],y[2],y[3]]]}else if(e[0]>t[2]&&e[3]<t[1]){let M=y[2]+(x[0]-y[2])/2,D=x[3]+(y[1]-x[3])/2;return Jo(ct(e[2]-w,e[1]-I),ct(e[0]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],x[1],x[2],D],[y[0],D,y[2],y[3]]]}else if(e[0]>t[2]&&e[1]>t[3]){let M=y[2]+(x[0]-y[2])/2,D=y[3]+(x[1]-y[3])/2;return Jo(ct(e[0]-w,e[1]-I),ct(e[2]-w,e[3]-I))>0?[[M,x[1],x[2],x[3]],[y[0],y[1],M,y[3]]]:[[x[0],D,x[2],x[3]],[y[0],y[1],y[2],D]]}}return[x,y]},Dp=(e,t,n,o,i,r)=>{let s=new Set,a=new Set;n===ke||n===fe?a.add(t[1]):s.add(t[0]),i===ke||i===fe?a.add(o[1]):s.add(o[0]),e.forEach(c=>{s.add(c[0]),s.add(c[2]),a.add(c[1]),a.add(c[3])}),s.add(r[0]),s.add(r[2]),a.add(r[1]),a.add(r[3]);let l=Array.from(a).sort((c,u)=>c-u),d=Array.from(s).sort((c,u)=>c-u);return{row:l.length,col:d.length,data:l.flatMap((c,u)=>d.map((p,m)=>({f:0,g:0,h:0,closed:!1,visited:!1,parent:null,addr:[m,u],pos:[p,c]})))}},La=(e,t,n)=>{switch(t){case _e:return z(n[0],e[1]);case fe:return z(e[2],n[1]);case ye:return z(n[0],e[3])}return z(e[0],n[1])},vp=(e,t,n,o)=>{if(o===fe)switch(n){case fe:return e.pos[0]>=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2;case _e:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ye:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case ke:return e.pos[1]===t.pos[1]?4:2}else if(o===ke)switch(n){case fe:return e.pos[1]===t.pos[1]?4:2;case _e:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ye:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3;case ke:return e.pos[0]<=t.pos[0]?4:e.pos[1]===t.pos[1]?0:2}else if(o===_e)switch(n){case fe:return e.pos[1]>t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case _e:return e.pos[1]>=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ye:return e.pos[0]===t.pos[0]?4:2;case ke:return e.pos[1]>t.pos[1]&&e.pos[0]>t.pos[0]?1:3}else if(o===ye)switch(n){case fe:return e.pos[1]<t.pos[1]&&e.pos[0]<t.pos[0]?1:3;case _e:return e.pos[0]===t.pos[0]?4:2;case ye:return e.pos[1]<=t.pos[1]?4:e.pos[0]===t.pos[0]?0:2;case ke:return e.pos[1]<t.pos[1]&&e.pos[0]>t.pos[0]?1:3}return 0},Lp=([e,t],n)=>[io([e,t-1],n),io([e+1,t],n),io([e,t+1],n),io([e-1,t],n)],io=([e,t],n)=>e<0||e>=n.col||t<0||t>=n.row?null:n.data[t*n.col+e]??null,ei=(e,t)=>{for(let n=0;n<t.col;n++)for(let o=0;o<t.row;o++){let i=io([n,o],t);if(i&&e[0]===i.pos[0]&&e[1]===i.pos[1])return i}return null},Oa=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]))],ti=(e,t)=>{let n=t.get(e);return n&&Le(n)?n:null},At=(e,t,n,o)=>{let i=e[0][0],r=e[0][1],s=e.map(a=>Er(a,hp(xr(e[0]),-1)));return(i<-jt||i>jt||r<-jt||r>jt||i+s[s.length-1][0]<-jt||r+s[s.length-1][0]>jt||i+s[s.length-1][1]<-jt||r+s[s.length-1][1]>jt)&&console.error("Elbow arrow normalization is outside reasonable bounds (> 1e6)",{x:i,y:r,points:s,...va(s)}),s=s.map(([a,l])=>z(Qo(a,-1e6,1e6),Qo(l,-1e6,1e6))),{points:s,x:Qo(i,-1e6,1e6),y:Qo(r,-1e6,1e6),fixedSegments:(t?.length??0)>0?t:null,...va(s),startIsSpecial:n,endIsSpecial:o}},Pr=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,o)=>{if(o===0||o===e.length-1)return!0;let i=e[o+1],r=Math.abs(n[1]-i[1])<Math.abs(n[0]-i[0]);return t===r?(t=r,!1):(t=r,!0)})}return e},Ir=e=>e.length>=4?e.filter((t,n)=>{if(n===0||n===e.length-1)return!0;let o=e[n-1];return gr(o,t)>wr}):e,Cp=e=>{switch(e){case 0:return _e;case 1:return fe;case 2:return ye}return ke},Ca=(e,t,n,o,i,r,s)=>s?i&&r?Sr(e,i,t,r):o:i?ni(n||[0,0],i,r??yp([i])):o,Ga=(e,t,n,o,i)=>Fa(e,t,n,n&&$e(n,i,Array(4).fill(Ut(n,i,e))),o,i),Ba=(e,t,n,o)=>Vt(xp(e),n,t,o,!0,!0),ka=(e,t)=>e[0]===t[0]&&e[1]===t[1],Ra=(e,t=wr)=>e.slice(1).map((n,o)=>Math.abs(n[0]-e[o][0])<t||Math.abs(n[1]-e[o][1])<t).every(Boolean);var be=(e,t,n,o)=>{let i=!1,{points:r,fixedSegments:s,startBinding:a,endBinding:l,fileId:d}=n;B(e)&&(Object.keys(n).length===0||typeof r<"u"||typeof s<"u"||typeof a<"u"||typeof l<"u")?n={...n,angle:0,...Ln({...e,x:n.x||e.x,y:n.y||e.y},t,n,o)}:typeof r<"u"&&(n={...Gp(r),...n});for(let c in n){let u=n[c];if(typeof u<"u"){if(e[c]===u&&(typeof u!="object"||u===null||c==="groupIds"||c==="scale"))continue;if(c==="scale"){let p=e[c],m=u;if(p[0]===m[0]&&p[1]===m[1])continue}else if(c==="points"){let p=e[c],m=u;if(p.length===m.length){let f=!1,E=p.length;for(;--E;){let h=p[E],g=m[E];if(h[0]!==g[0]||h[1]!==g[1]){f=!0;break}}if(!f)continue}}e[c]=u,i=!0}}return i&&((typeof n.height<"u"||typeof n.width<"u"||typeof d<"u"||typeof r<"u")&&Pe.delete(e),e.version=n.version??e.version+1,e.versionNonce=n.versionNonce??Mr(),e.updated=Tr()),e},ge=(e,t,n=!1)=>{let o=!1;for(let i in t){let r=t[i];if(typeof r<"u"){if(e[i]===r&&(typeof r!="object"||r===null))continue;o=!0}}return!o&&!n?e:{...e,...t,version:t.version??e.version+1,versionNonce:t.versionNonce??Mr(),updated:Tr()}},Na=(e,t)=>(e.version=(t??e.version)+1,e.versionNonce=Mr(),e.updated=Tr(),e);var Ey=e=>!e[Bp.CTRL_OR_CMD],Ar=e=>e.isBindingEnabled,ie=5,zp=10,_p=(e,t)=>{let n=[];return t.forEach(o=>{let i=e.getNonDeletedElement(o);i!=null&&n.push(i)}),n},Dr=(e,t,n,o)=>{let i=o.getNonDeletedElementsMap(),r=new Set,s=new Set;_a(e,t,n,"start",r,s,o,i),_a(e,n,t,"end",r,s,o,i);let a=Array.from(s).filter(l=>!r.has(l));_p(o,a).forEach(l=>{o.mutateElement(l,{boundElements:l.boundElements?.filter(d=>d.type!=="arrow"||d.id!==e.id)})})},_a=(e,t,n,o,i,r,s,a)=>{if(t!=="keep"){if(t===null){let l=Wp(e,o,s);l!=null&&r.add(l);return}$a(e)?(n==null||(n==="keep"?!Wa(e,t,o):o==="start"||n.id!==t.id))&&(yn(e,t,o,s),i.add(t.id)):(yn(e,t,o,s),i.add(t.id))}},Xa=(e,t,n)=>["start","end"].map(o=>{let i=qa(e,o,t),r=o==="start"?e.startBinding?.elementId:e.endBinding?.elementId;if(r){let s=t.get(r);if(Le(s)&&ii(s,i,t,n))return s}return null}),Yp=(e,t,n,o,i,r)=>{let a=e.points.length-1,l=n.findIndex(p=>p===0)>-1,d=n.findIndex(p=>p===a)>-1,c=l?t?ri(e,"start",o,i,r):null:"keep",u=d?t?ri(e,"end",o,i,r):null:"keep";return[c,u]},Up=(e,t,n,o,i)=>{if(B(e))return["keep","keep"];let[r,s]=Xa(e,t,i),a=r&&o?ri(e,"start",t,n,i):null,l=s&&o?ri(e,"end",t,n,i):null;return[a,l]},Xp=(e,t,n,o,i)=>{e.forEach(r=>{let[s,a]=n?.length?Yp(r,t,n??[],o.getNonDeletedElementsMap(),o.getNonDeletedElements(),i):Up(r,o.getNonDeletedElementsMap(),o.getNonDeletedElements(),t,i);Dr(r,s,a,o)})},gy=(e,t,n)=>e.length>50?[]:e.filter(j).flatMap(o=>Xa(o,t,n)).filter(o=>o!==null).filter(o=>e.filter(i=>i.id===o?.id).length===0),ja=(e,t,n,o,i)=>Array.from(t.reduce((r,s)=>{let a=Vt(s,n.getNonDeletedElements(),n.getNonDeletedElementsMap(),o,B(e),B(e));return a!=null&&!Va(e,i?.id,a)&&r.add(a),r},new Set)),xy=(e,t,n,o)=>{let i=o.getNonDeletedElements(),r=o.getNonDeletedElementsMap();t.startBoundElement!=null&&yn(e,t.startBoundElement,"start",o);let s=Vt(n,i,r,t.zoom,B(e),B(e));s!==null&&(Wa(e,s,"end")||yn(e,s,"end",o))},jp=(e,t)=>({...e,gap:Math.min(e.gap,li(t,t.width,t.height))}),yn=(e,t,n,o)=>{if(!_(e))return;let i={elementId:t.id,...jp(Zp(e,t,n,o.getNonDeletedElementsMap()),t)};B(e)&&(i={...i,...Za(e,t,n,o.getNonDeletedElementsMap())}),o.mutateElement(e,{[n==="start"?"startBinding":"endBinding"]:i}),Ua(t.boundElements||[]).has(e.id)||o.mutateElement(t,{boundElements:(t.boundElements||[]).concat({id:e.id,type:"arrow"})})},Wa=(e,t,n)=>{let o=e[n==="start"?"endBinding":"startBinding"];return Va(e,o?.elementId,t)},Va=(e,t,n)=>t===n.id&&$a(e),$a=e=>e.points.length<3&&!B(e),Wp=(e,t,n)=>{let o=t==="start"?"startBinding":"endBinding",i=e[o];return i==null?null:(n.mutateElement(e,{[o]:null}),i.elementId)},Vt=(e,t,n,o,i,r)=>{if(r){let a=!1,l=$p(t,c=>Le(c,!1)&&ii(c,e,n,o,(i||!oi(c))&&!q(c))).filter(c=>a?!1:(oi(c)||(a=!0),!0));if(!l||l.length===0)return null;if(l.length===1)return l[0];let d=l.filter(c=>ii(c,e,n,o,!1));return d.length===1?d[0]:l.sort((c,u)=>u.width**2+u.height**2-(c.width**2+c.height**2)).pop()}return Vp(t,a=>Le(a,!1)&&ii(a,e,n,o,(i||!oi(a))&&!q(a)))},Vp=(e,t)=>{let n=null;for(let o=e.length-1;o>=0;--o){let i=e[o];if(!i.isDeleted&&t(i)){n=i;break}}return n},$p=(e,t)=>{let n=[];for(let o=e.length-1;o>=0;--o){let i=e[o];i.isDeleted||t(i)&&n.push(i)}return n},Zp=(e,t,n,o)=>{let i=n==="start"?-1:1,r=i===-1?0:e.points.length-1,s=r-i,a=U.getPointAtIndexGlobalCoordinates(e,r,o),l=U.getPointAtIndexGlobalCoordinates(e,s,o);return{focus:nm(t,o,l,a),gap:Math.max(1,Ut(t,o,a))}},Ue=(e,t,n)=>{if(!Le(e))return;let{newSize:o,simultaneouslyUpdated:i}=n??{},r=Kp(i),s=t.getNonDeletedElementsMap();n?.changedElements&&(s=new Map(s),n.changedElements.forEach(a=>{s.set(a.id,a)})),si(s,e,a=>{if(!j(a)||a.isDeleted||!qp(a,e))return;let l=a.startBinding?s.get(a.startBinding.elementId):null,d=a.endBinding?s.get(a.endBinding.elementId):null,c=null,u=null;l&&d&&(c=pe(l,s),u=pe(d,s));let p={startBinding:Ya(e,a.startBinding,o),endBinding:Ya(e,a.endBinding,o)};if(r.has(a.id)){t.mutateElement(a,p);return}let m=ai(s,a,(E,h)=>{if(E&&Le(E)&&(h==="startBinding"||h==="endBinding")&&(e.id===a[h]?.elementId||e.id===a[h==="startBinding"?"endBinding":"startBinding"]?.elementId&&!gn(c,u))){let g=tm(a,h,p[h],E,s);if(g)return[h==="startBinding"?0:a.points.length-1,{point:g}]}return null}).filter(E=>E!==null);U.movePoints(a,t,new Map(m),{...e.id===a.startBinding?.elementId?{startBinding:p.startBinding}:{},...e.id===a.endBinding?.elementId?{endBinding:p.endBinding}:{}});let f=W(a,s);f&&!f.isDeleted&&hn(a,t,!1)})},wy=(e,t,n)=>{j(e)?Xp([e],!0,[],t,n?.zoom):Ue(e,t,{...n,changedElements:new Map([[e.id,e]])})},qp=(e,t)=>e.startBinding?.elementId===t.id||e.endBinding?.elementId===t.id,Kp=e=>new Set((e||[]).map(t=>t.id)),Fa=(e,t,n,o,i,r,s)=>{let a=Tt(V(t,e));return!n||!o?a:Qp(i,n,r,s)?oo(n,o,e):Tt(V(e,he(n,r)))},Qp=(e,t,n,o)=>{let i=Ut(t,n,e),r=li(t,t.width,t.height,o);return i>r?null:i},Sr=(e,t,n,o)=>{(Rp()||Fp())&&Op(e.points.length>1,"Arrow should have at least 2 points");let i=$e(t,o),r=e.points[n==="start"?0:e.points.length-1],s=O(e.x+r[0],e.y+r[1]),a=la(t)?Jp(t,o,s):s,l=B(e),d=dt(i),c=n==="start"?1:e.points.length-2,u=ae(O(e.x+e.points[c][0],e.y+e.points[c][1]),d,e.angle??0),p=null;if(l){let m=Oe(oo(t,i,s)),f=em(t,o,a),E=O(m?d[0]:f[0],m?f[1]:d[1]),h=Re(E,xn(wn(Cn(V(f,E)),Math.max(t.width,t.height)*2),E));if(p=En(t,o,h,ie).sort(Dt)[0],!p){let g=O(m?f[0]:d[0],m?d[1]:f[1]),x=Re(g,xn(wn(Cn(V(f,g)),Math.max(t.width,t.height)*2),g));p=En(t,o,x,ie).sort(Dt)[0]}}else p=En(t,o,Re(u,xn(wn(Cn(V(a,u)),ut(a,u)+Math.max(t.width,t.height)*2),u)),ie).sort((m,f)=>Dt(m,u)-Dt(f,u))[0];return!p||Dt(a,p)<Hp?a:l?p:a},Jp=(e,t,n)=>{let o=he(e,t),i=ae(n,o,-e.angle);return i[0]<e.x&&i[1]<e.y?i[1]-e.y>-ie?ae(O(e.x-ie,e.y),o,e.angle):ae(O(e.x,e.y-ie),o,e.angle):i[0]<e.x&&i[1]>e.y+e.height?i[0]-e.x>-ie?ae(O(e.x,e.y+e.height+ie),o,e.angle):ae(O(e.x-ie,e.y+e.height),o,e.angle):i[0]>e.x+e.width&&i[1]>e.y+e.height?i[0]-e.x<e.width+ie?ae(O(e.x+e.width,e.y+e.height+ie),o,e.angle):ae(O(e.x+e.width+ie,e.y+e.height),o,e.angle):i[0]>e.x+e.width&&i[1]<e.y?i[0]-e.x<e.width+ie?ae(O(e.x+e.width,e.y-ie),o,e.angle):ae(O(e.x+e.width+ie,e.y),o,e.angle):n},em=(e,t,n,o=.05)=>{let{x:i,y:r,width:s,height:a,angle:l}=e,d=he(e,t,-.1,-.1),c=ae(n,d,-l),u=Ha(o*a,5,80),p=Ha(o*s,5,80);if(c[0]<=i+s/2&&c[1]>d[1]-u&&c[1]<d[1]+u)return ae(O(i-ie,d[1]),d,l);if(c[1]<=r+a/2&&c[0]>d[0]-p&&c[0]<d[0]+p)return ae(O(d[0],r-ie),d,l);if(c[0]>=i+s/2&&c[1]>d[1]-u&&c[1]<d[1]+u)return ae(O(i+s+ie,d[1]),d,l);if(c[1]>=r+a/2&&c[0]>d[0]-p&&c[0]<d[0]+p)return ae(O(d[0],r+a+ie),d,l);if(e.type==="diamond"){let m=ie,f=O(i+s/4-m,r+a/4-m),E=O(i+3*s/4+m,r+a/4-m),h=O(i+s/4-m,r+3*a/4+m),g=O(i+3*s/4+m,r+3*a/4+m);if(ut(f,c)<Math.max(p,u))return ae(f,d,l);if(ut(E,c)<Math.max(p,u))return ae(E,d,l);if(ut(h,c)<Math.max(p,u))return ae(h,d,l);if(ut(g,c)<Math.max(p,u))return ae(g,d,l)}return n},tm=(e,t,n,o,i)=>{if(n==null||n.elementId!==o.id&&e.points.length>2)return null;let r=t==="startBinding"?-1:1,s=r===-1?0:e.points.length-1;if(B(e)&&Jn(n)){let u=vr(n.fixedPoint)??Za(e,o,t==="startBinding"?"start":"end",i).fixedPoint,p=he(o,i),m=O(o.x+u[0]*o.width,o.y+u[1]*o.height),f=ae(m,p,o.angle);return U.pointFromAbsoluteCoords(e,f,i)}let a=s-r,l=U.getPointAtIndexGlobalCoordinates(e,a,i),d=om(o,i,n.focus,l),c;if(n.gap===0)c=d;else{let u=U.getPointAtIndexGlobalCoordinates(e,s,i),p=he(o,i),m=ut(l,u)+ut(l,p)+Math.max(o.width,o.height)*2,f=[...En(o,i,Re(l,xn(wn(Cn(V(d,l)),m),l)),n.gap).sort((E,h)=>Dt(E,l)-Dt(h,l)),xn(wn(Cn(V(d,l)),ut(l,u)),l)];f.length>1?c=f[0]:f.length===1?c=d:c=u}return U.pointFromAbsoluteCoords(e,c,i)},Za=(e,t,n,o)=>{let i=[t.x,t.y,t.x+t.width,t.y+t.height],r=Sr(e,t,n,o),s=O(i[0]+(i[2]-i[0])/2,i[1]+(i[3]-i[1])/2),a=ae(r,s,-t.angle);return{fixedPoint:vr([(a[0]-t.x)/t.width,(a[1]-t.y)/t.height])}},Ya=(e,t,n)=>{if(t==null||n==null)return t;let{width:o,height:i}=n,{width:r,height:s}=e,a=Math.max(1,Math.min(li(e,o,i),t.gap*(o<i?o/r:i/s)));return{...t,gap:a}},ri=(e,t,n,o,i)=>Vt(qa(e,t,n),o,n,i,B(e),B(e)),qa=(e,t,n)=>{let o=t==="start"?0:-1;return kp(U.getPointAtIndexGlobalCoordinates(e,o,n))},Ka=(e,t,n)=>{for(let o of e){if("boundElements"in o&&o.boundElements&&Object.assign(o,{boundElements:o.boundElements.reduce((i,r)=>{let s=t.get(r.id);return s&&i.push({...r,id:s}),i},[])}),"containerId"in o&&o.containerId&&Object.assign(o,{containerId:t.get(o.containerId)??null}),"endBinding"in o&&o.endBinding){let i=t.get(o.endBinding.elementId);Object.assign(o,{endBinding:i?{...o.endBinding,elementId:i}:null})}if("startBinding"in o&&o.startBinding){let i=t.get(o.startBinding.elementId);Object.assign(o,{startBinding:i?{...o.startBinding,elementId:i}:null})}B(o)&&Object.assign(o,Ln(o,n,{points:[o.points[0],o.points[o.points.length-1]]}))}},yy=(e,t)=>{let n=Ua(e);for(let o of t)$t.unbindAffected(n,o,(i,r)=>be(i,n,r)),Zt.unbindAffected(n,o,(i,r)=>be(i,n,r))},so=(e,t,n=[])=>{if(!e)return null;let o=e.filter(i=>!t.has(i.id));return o.push(...n.map(i=>({id:i.id,type:i.type}))),o},ii=(e,{x:t,y:n},o,i,r)=>{let s=O(t,n),a=li(e,e.width,e.height,i),l=(r||!oi(e))&&!q(e),d=[t-a,n-a,t+a,n+a],c=pe(e,o);if(!gn(d,c))return!1;let u=En(e,o,Re(he(e,o),s)),p=Ut(e,o,s);return l?u.length===0||p<=a:u.length>0&&p<=a},li=(e,t,n,o)=>{let i=o?.value&&o.value<1?o.value:1,s=(e.type==="diamond"?1/Math.sqrt(2):1)*Math.min(t,n);return Math.max(16,Math.min(.25*s,32),zp/i+ie)},nm=(e,t,n,o)=>{let i=he(e,t);if(Np(n,o))return 0;let r=ae(n,i,-e.angle),s=ae(o,i,-e.angle),a=Math.sign(Ye(V(s,n),V(s,i)))*-1,l=Re(s,xn(wn(Cn(V(s,r)),Math.max(e.width*2,e.height*2)),s)),d=e.type==="diamond"?[Re(O(e.x+e.width/2,e.y),O(e.x+e.width/2,e.y+e.height)),Re(O(e.x,e.y+e.height/2),O(e.x+e.width,e.y+e.height/2))]:[Re(O(e.x,e.y),O(e.x+e.width,e.y+e.height)),Re(O(e.x+e.width,e.y),O(e.x,e.y+e.height))],c=e.type==="diamond"?[Re(O(e.x+e.width/2,e.y-e.height),O(e.x+e.width/2,e.y+e.height*2)),Re(O(e.x-e.width,e.y+e.height/2),O(e.x+e.width*2,e.y+e.height/2))]:[Re(O(e.x-e.width,e.y-e.height),O(e.x+e.width*2,e.y+e.height*2)),Re(O(e.x+e.width*2,e.y-e.height),O(e.x-e.width,e.y+e.height*2))];return[za(l,c[0]),za(l,c[1])].filter(m=>m!==null).sort((m,f)=>Dt(m,o)-Dt(f,o)).map((m,f)=>a*ut(i,m)/(e.type==="diamond"?ut(d[f][0],d[f][1])/2:Math.sqrt(e.width**2+e.height**2)/2)).sort((m,f)=>Math.abs(m)-Math.abs(f))[0]??0},om=(e,t,n,o)=>{let i=he(e,t);if(n===0)return i;let r=(e.type==="diamond"?[O(e.x,e.y+e.height/2),O(e.x+e.width/2,e.y),O(e.x+e.width,e.y+e.height/2),O(e.x+e.width/2,e.y+e.height)]:[O(e.x,e.y),O(e.x+e.width,e.y),O(e.x+e.width,e.y+e.height),O(e.x,e.y+e.height)]).map(l=>xn(wn(V(l,i),Math.abs(n)),i)).map(l=>ae(l,i,e.angle)),s=[Ye(V(o,r[0]),V(r[1],r[0]))>0&&(n>0?Ye(V(o,r[1]),V(r[2],r[1]))<0:Ye(V(o,r[3]),V(r[0],r[3]))<0),Ye(V(o,r[1]),V(r[2],r[1]))>0&&(n>0?Ye(V(o,r[2]),V(r[3],r[2]))<0:Ye(V(o,r[0]),V(r[1],r[0]))<0),Ye(V(o,r[2]),V(r[3],r[2]))>0&&(n>0?Ye(V(o,r[3]),V(r[0],r[3]))<0:Ye(V(o,r[1]),V(r[2],r[1]))<0),Ye(V(o,r[3]),V(r[0],r[3]))>0&&(n>0?Ye(V(o,r[0]),V(r[1],r[0]))<0:Ye(V(o,r[2]),V(r[3],r[2]))<0)];return s[0]?n>0?r[1]:r[0]:s[1]?n>0?r[2]:r[1]:s[2]?n>0?r[3]:r[2]:n>0?r[0]:r[3]},Qa=new Set(["boundElements","frameId","containerId","startBinding","endBinding"]),si=(e,t,n)=>{Le(t)&&(t.boundElements?.slice()??[]).forEach(({id:i})=>{n(e.get(i),"boundElements",i)})},ai=(e,t,n)=>{let o=[];if(t.frameId){let i=t.frameId;o.push(n(e.get(i),"frameId",i))}if(ce(t)){let i=t.containerId;o.push(n(e.get(i),"containerId",i))}if(_(t)){if(t.startBinding){let i=t.startBinding.elementId;o.push(n(e.get(i),"startBinding",i))}if(t.endBinding){let i=t.endBinding.elementId;o.push(n(e.get(i),"endBinding",i))}}return o},$t=class{static unbindAffected(t,n,o){n&&ai(t,n,i=>{!i||i.isDeleted||si(t,i,(r,s,a)=>{a===n.id&&o(i,{boundElements:so(i.boundElements,new Set([a]))})})})}static rebindAffected=(t,n,o)=>{!n||n.isDeleted||ai(t,n,(i,r)=>{if(!i||i.isDeleted){o(n,{[r]:null});return}r!=="frameId"&&(i.boundElements?.find(s=>s.id===n.id)||(_(n)&&o(i,{boundElements:so(i.boundElements,new Set,new Array(n))}),oe(n)&&(i.boundElements?.find(s=>s.type==="text")?o(n,{[r]:null}):o(i,{boundElements:so(i.boundElements,new Set,new Array(n))}))))})}},Zt=class{static unbindAffected(t,n,o){n&&si(t,n,i=>{!i||i.isDeleted||ai(t,i,(r,s,a)=>{a===n.id&&o(i,{[s]:null})})})}static rebindAffected=(t,n,o)=>{!n||n.isDeleted||si(t,n,(i,r,s)=>{if(!i||i.isDeleted){o(n,{boundElements:so(n.boundElements,new Set([s]))});return}oe(i)&&((n.boundElements?.slice()??[]).reverse().find(l=>l.type==="text")?.id===i.id?i.containerId!==n.id&&o(i,{containerId:n.id}):(i.containerId!==null&&o(i,{containerId:null}),o(n,{boundElements:so(n.boundElements,new Set([i.id]))})))})}},ni=(e,t,n)=>{let[o,i]=vr(e);return ae(O(t.x+t.width*o,t.y+t.height*i),he(t,n),t.angle)},im=(e,t)=>{let n=e.startBinding&&t.get(e.startBinding.elementId),o=e.endBinding&&t.get(e.endBinding.elementId),i=n&&e.startBinding?ni(e.startBinding.fixedPoint,n,t):O(e.x+e.points[0][0],e.y+e.points[0][1]),r=o&&e.endBinding?ni(e.endBinding.fixedPoint,o,t):O(e.x+e.points[e.points.length-1][0],e.y+e.points[e.points.length-1][1]);return[i,r]},Ja=(e,t)=>{let[n,o]=im(e,t);return[U.pointFromAbsoluteCoords(e,n,t),U.pointFromAbsoluteCoords(e,o,t)]},vr=e=>e&&(Math.abs(e[0]-.5)<1e-4||Math.abs(e[1]-.5)<1e-4)?e.map(t=>Math.abs(t-.5)<1e-4?.5001:t):e;var Cr=({points:e})=>{let t=e[0][0],n=e[0][1];return{points:e.map(o=>G(o[0]-t,o[1]-n)),offsetX:t,offsetY:n}},U=class e{elementId;selectedPointsIndices;pointerDownState;isDragging;lastUncommittedPoint;pointerOffset;startBindingElement;endBindingElement;hoverPointIndex;segmentMidPointHoveredCoords;elbowed;customLineAngle;isEditing;constructor(t,n,o=!1){this.elementId=t.id,tl(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.isDragging=!1,this.pointerOffset={x:0,y:0},this.startBindingElement="keep",this.endBindingElement="keep",this.pointerDownState={prevSelectedPointsIndices:null,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:null,segmentMidpoint:{value:null,index:null,added:!1}},this.hoverPointIndex=-1,this.segmentMidPointHoveredCoords=null,this.elbowed=B(t)&&t.elbowed,this.customLineAngle=null,this.isEditing=o}static POINT_HANDLE_SIZE=10;static getElement(t,n){let o=n.get(t);return o||null}static handleBoxSelection(t,n,o,i){if(!n.selectedLinearElement?.isEditing||!n.selectionElement)return!1;let{selectedLinearElement:r}=n,{selectedPointsIndices:s,elementId:a}=r,l=e.getElement(a,i);if(!l)return!1;let[d,c,u,p]=Y(n.selectionElement,i),f=e.getPointsGlobalCoordinates(l,i).reduce((E,h,g)=>((h[0]>=d&&h[0]<=u&&h[1]>=c&&h[1]<=p||t.shiftKey&&s?.includes(g))&&E.push(g),E),[]).filter(E=>!(B(l)&&E!==0&&E!==l.points.length-1));o({selectedLinearElement:{...r,selectedPointsIndices:f.length?f:null}})}static handlePointDragging(t,n,o,i,r){if(!r)return null;let{elementId:s}=r,a=n.scene.getNonDeletedElementsMap(),l=e.getElement(s,a),d=r.customLineAngle;if(!l||B(l)&&!r.pointerDownState.lastClickedIsEndPoint&&r.pointerDownState.lastClickedPoint!==0)return null;let c=B(l)?[r.selectedPointsIndices?.includes(0)?0:void 0,r.selectedPointsIndices?.find(m=>m>0)?l.points.length-1:void 0].filter(m=>m!==void 0):r.selectedPointsIndices,u=B(l)?r.pointerDownState.lastClickedPoint>0?l.points.length-1:0:r.pointerDownState.lastClickedPoint,p=l.points[u];if(c&&p){if(nl(t)&&c.length===1&&l.points.length>1){let h=c[0],g=l.points[h===0?1:h-1];d=r.customLineAngle??Math.atan2(l.points[h][1]-g[1],l.points[h][0]-g[0]);let[x,y]=e._getShiftLockedDelta(l,a,g,G(o,i),t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize(),d);e.movePoints(l,n.scene,new Map([[h,{point:G(x+g[0],y+g[1]),isDragging:h===u}]]))}else{let h=e.createPointAt(l,a,o-r.pointerOffset.x,i-r.pointerOffset.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize()),g=h[0]-p[0],x=h[1]-p[1];e.movePoints(l,n.scene,new Map(c.map(y=>{let b=y===u?e.createPointAt(l,a,o-r.pointerOffset.x,i-r.pointerOffset.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize()):G(l.points[y][0]+g,l.points[y][1]+x);return[y,{point:b,isDragging:y===u}]})))}W(l,a)&&hn(l,n.scene,!1);let f=[];if(er(l,!1)){let h=c[0]===0,g=c[c.length-1]===l.points.length-1,x=[];!h!=!g?x.push({x:o,y:i}):(h&&x.push(Lr(e.getPointGlobalCoordinates(l,l.points[0],a))),g&&x.push(Lr(e.getPointGlobalCoordinates(l,l.points[c[c.length-1]],a)))),x.length&&(f=ja(l,x,n.scene,n.state.zoom))}let E={...r,selectedPointsIndices:c,segmentMidPointHoveredCoords:u!==0&&u!==l.points.length-1?this.getPointGlobalCoordinates(l,p,a):null,hoverPointIndex:u===0||u===l.points.length-1?u:-1,isDragging:!0,customLineAngle:d};return{...n.state,selectedLinearElement:E,suggestedBindings:f}}return null}static handlePointerUp(t,n,o,i){let r=i.getNonDeletedElementsMap(),s=i.getNonDeletedElements(),a=dm(t,o),{elementId:l,selectedPointsIndices:d,isDragging:c,pointerDownState:u}=n,p=e.getElement(l,r);if(!p)return n;let m={};if(c&&d){for(let f of d)if(f===0||f===p.points.length-1){cm(p.points,o.zoom.value)&&(bt(p)&&i.mutateElement(p,{...rl(p,!0)},{informMutation:!1,isDragging:!1}),e.movePoints(p,i,new Map([[f,{point:f===0?p.points[p.points.length-1]:p.points[0]}]])));let E=Ar(o)?Vt((d?.length??0)>1?Lr(e.getPointAtIndexGlobalCoordinates(p,f,r)):a,s,r,o.zoom,B(p),B(p)):null;m[f===0?"startBindingElement":"endBindingElement"]=E}}return{...n,...m,segmentMidPointHoveredCoords:null,hoverPointIndex:-1,selectedPointsIndices:c||t.shiftKey?!c&&t.shiftKey&&u.prevSelectedPointsIndices?.includes(u.lastClickedPoint)?d&&d.filter(f=>f!==u.lastClickedPoint):d:d?.includes(u.lastClickedPoint)?[u.lastClickedPoint]:d,isDragging:!1,pointerOffset:{x:0,y:0},customLineAngle:null}}static getEditorMidPoints=(t,n,o)=>{let i=W(t,n);if(!B(t)&&!o.selectedLinearElement?.isEditing&&t.points.length>2&&!i)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,o.zoom)){a.push(null),s++;continue}let l=e.getSegmentMidPoint(t,s+1);a.push(l),s++}return a};static getSegmentMidpointHitCoords=(t,n,o,i)=>{let{elementId:r}=t,s=e.getElement(r,i);if(!s)return null;let a=e.getPointIndexUnderCursor(s,i,o.zoom,n.x,n.y);if(!B(s)&&a>=0||e.getPointsGlobalCoordinates(s,i).length>=3&&!o.selectedLinearElement?.isEditing&&!B(s))return null;let d=(e.POINT_HANDLE_SIZE+1)/o.zoom.value,c=t.segmentMidPointHoveredCoords;if(c&&Gn(G(c[0],c[1]),G(n.x,n.y))<=d)return c;let u=0,p=e.getEditorMidPoints(s,i,o);for(;u<p.length;){if(p[u]!==null&&Gn(p[u],G(n.x,n.y))<=d)return p[u];u++}return null};static isSegmentTooShort(t,n,o,i,r){if(B(t))return i>=0&&i<t.points.length?Gn(n,o)*r.value<e.POINT_HANDLE_SIZE/2:!1;let s=Gn(n,o);if(t.points.length>2&&t.roundness){let[a,l]=il(t);vt(a.length===0&&l.length>0,"Only linears built out of curves are supported"),vt(a.length+l.length>=i,"Invalid segment index while calculating mid point"),s=sm(l[i])}return s*r.value<e.POINT_HANDLE_SIZE*4}static getSegmentMidPoint(t,n){if(B(t)){vt(t.points.length>=n,"Invalid segment index while calculating elbow arrow mid point");let r=el(t.points[n-1],t.points[n]);return G(t.x+r[0],t.y+r[1])}let[o,i]=il(t);if(vt(o.length===0&&i.length>0||o.length>0&&i.length===0,"Only linears built out of either segments or curves are supported"),vt(o.length+i.length>=n,"Invalid segment index while calculating mid point"),o.length){let r=o[n-1];return el(r[0],r[1])}if(i.length){let r=i[n-1];return am(r,.5)}vt(!1,"Invalid segment type while calculating mid point")}static getSegmentMidPointIndex(t,n,o,i){let r=e.getElement(t.elementId,i);if(!r)return-1;let s=e.getEditorMidPoints(r,i,n),a=0;for(;a<s.length;){if(e.arePointsEqual(o,s[a]))return a+1;a++}return-1}static handlePointerDown(t,n,o,i,r,s){let a=n.state,l=s.getNonDeletedElementsMap(),d=s.getNonDeletedElements(),c={didAddPoint:!1,hitElement:null,linearElementEditor:null};if(!r)return c;let{elementId:u}=r,p=e.getElement(u,l);if(!p)return c;let m=e.getSegmentMidpointHitCoords(r,i,a,l),f=null;if(m)f=e.getSegmentMidPointIndex(r,a,m,l);else if(t.altKey&&a.selectedLinearElement?.isEditing)return r.lastUncommittedPoint==null&&(s.mutateElement(p,{points:[...p.points,e.createPointAt(p,l,i.x,i.y,t[Bn.CTRL_OR_CMD]?null:n.getEffectiveGridSize())]}),c.didAddPoint=!0),o.scheduleCapture(),c.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:-1,lastClickedIsEndPoint:!1,origin:{x:i.x,y:i.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:[p.points.length-1],lastUncommittedPoint:null,endBindingElement:Vt(i,d,l,n.state.zoom,r.elbowed)},c.didAddPoint=!0,c;let E=e.getPointIndexUnderCursor(p,l,a.zoom,i.x,i.y);if(E>=0||m)c.hitElement=p;else{let{startBindingElement:D,endBindingElement:T}=r;Ar(a)&&er(p)&&Dr(p,D,T,s)}let[h,g,x,y]=Y(p,l),b=(h+x)/2,w=(g+y)/2,I=E>-1&&Te(G(p.x+p.points[E][0],p.y+p.points[E][1]),G(b,w),p.angle),M=E>-1||t.shiftKey?t.shiftKey||r.selectedPointsIndices?.includes(E)?um([...r.selectedPointsIndices||[],E]):[E]:null;return c.linearElementEditor={...r,pointerDownState:{prevSelectedPointsIndices:r.selectedPointsIndices,lastClickedPoint:E,lastClickedIsEndPoint:E===p.points.length-1,origin:{x:i.x,y:i.y},segmentMidpoint:{value:m,index:f,added:!1}},selectedPointsIndices:M,pointerOffset:I?{x:i.x-I[0],y:i.y-I[1]}:{x:0,y:0}},c}static arePointsEqual(t,n){return!t&&!n?!0:!t||!n?!1:tl(t,n)}static handlePointerMove(t,n,o,i){let r=i.state;if(!r.selectedLinearElement?.isEditing)return null;let{elementId:s,lastUncommittedPoint:a}=r.selectedLinearElement,l=i.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,i,[c.length-1]),r.selectedLinearElement?.lastUncommittedPoint?{...r.selectedLinearElement,lastUncommittedPoint:null}:r.selectedLinearElement;let p;if(nl(t)&&c.length>=2){let m=c[c.length-2],[f,E]=e._getShiftLockedDelta(d,l,m,G(n,o),t[Bn.CTRL_OR_CMD]?null:i.getEffectiveGridSize());p=G(f+m[0],E+m[1])}else p=e.createPointAt(d,l,n-r.selectedLinearElement.pointerOffset.x,o-r.selectedLinearElement.pointerOffset.y,t[Bn.CTRL_OR_CMD]||B(d)?null:i.getEffectiveGridSize());return u===a?e.movePoints(d,i.scene,new Map([[d.points.length-1,{point:p}]])):e.addPoints(d,i.scene,[p]),{...r.selectedLinearElement,lastUncommittedPoint:d.points[d.points.length-1]}}static getPointGlobalCoordinates(t,n,o){let[i,r,s,a]=Y(t,o),l=(i+s)/2,d=(r+a)/2,{x:c,y:u}=t;return Te(G(c+n[0],u+n[1]),G(l,d),t.angle)}static getPointsGlobalCoordinates(t,n){let[o,i,r,s]=Y(t,n),a=(o+r)/2,l=(i+s)/2;return t.points.map(d=>{let{x:c,y:u}=t;return Te(G(c+d[0],u+d[1]),G(a,l),t.angle)})}static getPointAtIndexGlobalCoordinates(t,n,o){let i=n<0?t.points.length+n:n,[r,s,a,l]=Y(t,o),d=(r+a)/2,c=(s+l)/2,u=t.points[i],{x:p,y:m}=t;return u?Te(G(p+u[0],m+u[1]),G(d,c),t.angle):Te(G(p,m),G(d,c),t.angle)}static pointFromAbsoluteCoords(t,n,o){if(B(t))return G(n[0]-t.x,n[1]-t.y);let[i,r,s,a]=Y(t,o),l=(i+s)/2,d=(r+a)/2,[c,u]=Te(G(n[0],n[1]),G(l,d),-t.angle);return G(c-t.x,u-t.y)}static getPointIndexUnderCursor(t,n,o,i,r){let s=e.getPointsGlobalCoordinates(t,n),a=s.length;for(;--a>-1;){let l=s[a];if(Gn(G(i,r),G(l[0],l[1]))*o.value<e.POINT_HANDLE_SIZE+1)return a}return-1}static createPointAt(t,n,o,i,r){let s=ol(o,i,r),[a,l,d,c]=Y(t,n),u=(a+d)/2,p=(l+c)/2,[m,f]=Te(G(s[0],s[1]),G(u,p),-t.angle);return G(m-t.x,f-t.y)}static getNormalizeElementPointsAndCoords(t){let{points:n,offsetX:o,offsetY:i}=Cr(t);return{points:n,x:t.x+o,y:t.y+i}}static duplicateSelectedPoints(t,n){vt(t.selectedLinearElement?.isEditing,"Not currently editing a linear element");let o=n.getNonDeletedElementsMap(),{selectedPointsIndices:i,elementId:r}=t.selectedLinearElement,s=e.getElement(r,o);vt(s,"The linear element does not exist in the provided Scene"),vt(i!=null,"There are no selected points to duplicate");let{points:a}=s,l=[],d=!1,c=-1,u=a.reduce((p,m,f)=>{if(++c,p.push(m),i.includes(f)){let h=a[f+1];h||(d=!0),p.push(h?G((m[0]+h[0])/2,(m[1]+h[1])/2):G(m[0],m[1])),l.push(c+1),++c}return p},[]);if(n.mutateElement(s,{points:u}),d){let p=s.points[s.points.length-1];e.movePoints(s,n,new Map([[s.points.length-1,{point:G(p[0]+30,p[1]+30)}]]))}return{...t,selectedLinearElement:{...t.selectedLinearElement,selectedPointsIndices:l}}}static deletePoints(t,n,o){let i=n.state.selectedLinearElement?.isEditing&&n.state.selectedLinearElement?.lastUncommittedPoint===t.points[t.points.length-1],r=t.points.filter((c,u)=>!o.includes(u));bt(t)&&t.polygon&&(i||o.includes(0)||o.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}=Cr({points:r});e._updatePoints(t,n.scene,a,l,d)}static addPoints(t,n,o){let i=[...t.points,...o];bt(t)&&t.polygon&&(i[0]=G(i[i.length-1][0],i[i.length-1][1]));let{points:r,offsetX:s,offsetY:a}=Cr({points:i});e._updatePoints(t,n,r,s,a)}static movePoints(t,n,o,i){let{points:r}=t;if(bt(t)&&t.polygon){let c=o.get(0),u=o.get(r.length-1);c?o.set(r.length-1,{point:G(c.point[0],c.point[1]),isDragging:c.isDragging}):u&&o.set(0,{point:G(u.point[0],u.point[1]),isDragging:u.isDragging})}let s=o.get(0)?.point??G(0,0),[a,l]=s,d=B(t)?[o.get(0)?.point??r[0],o.get(r.length-1)?.point??r[r.length-1]]:r.map((c,u)=>{let p=o.get(u)?.point??c;return G(p[0]-a,p[1]-l)});e._updatePoints(t,n,d,a,l,i,{isDragging:Array.from(o.values()).some(c=>c.isDragging)})}static shouldAddMidpoint(t,n,o,i){let r=e.getElement(t.elementId,i);if(r&&B(r)||!r)return!1;let{segmentMidpoint:s}=t.pointerDownState;if(s.added||s.value===null||s.index===null||t.pointerDownState.origin===null)return!1;let a=t.pointerDownState.origin,l=Gn(G(a.x,a.y),G(n.x,n.y));return!(!o.selectedLinearElement?.isEditing&&l<lm/o.zoom.value)}static addMidpoint(t,n,o,i,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a)return;let{segmentMidpoint:l}=t.pointerDownState,d={pointerDownState:t.pointerDownState,selectedPointsIndices:t.selectedPointsIndices},c=e.createPointAt(a,s,n.x,n.y,i&&!B(a)?o.getEffectiveGridSize():null),u=[...a.points.slice(0,l.index),c,...a.points.slice(l.index)];return r.mutateElement(a,{points:u}),d.pointerDownState={...t.pointerDownState,segmentMidpoint:{...t.pointerDownState.segmentMidpoint,added:!0},lastClickedPoint:l.index},d.selectedPointsIndices=[l.index],d}static _updatePoints(t,n,o,i,r,s,a){if(B(t)){let l={};s?.startBinding!==void 0&&(l.startBinding=s.startBinding!==null&&Jn(s.startBinding)?s.startBinding:null),s?.endBinding!==void 0&&(l.endBinding=s.endBinding!==null&&Jn(s.endBinding)?s.endBinding:null),l.points=Array.from(o),n.mutateElement(t,l,{informMutation:!0,isDragging:a?.isDragging??!1})}else{let l=Gr(t,o),d=Gr(t,t.points),c=(l[0]+l[2])/2,u=(l[1]+l[3])/2,p=(d[0]+d[2])/2,m=(d[1]+d[3])/2,f=p-c,E=m-u,h=Te(G(i,r),G(f,E),t.angle);n.mutateElement(t,{...s,points:o,x:t.x+h[0],y:t.y+h[1]})}}static _getShiftLockedDelta(t,n,o,i,r,s){let a=e.getPointGlobalCoordinates(t,o,n);if(B(t))return[i[0]-a[0],i[1]-a[1]];let[l,d]=ol(i[0],i[1],r),{width:c,height:u}=sl(a[0],a[1],l,d,s);return Te(G(c,u),G(0,0),-t.angle)}static getBoundTextElementPosition=(t,n,o)=>{e.getPointsGlobalCoordinates(t,o).length<2&&be(n,o,{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],o);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,o,i)=>{let[r,s,a,l]=o,d=(r+a)/2,c=(s+l)/2,{x:u,y:p}=e.getBoundTextElementPosition(t,i,n),m=u+i.width,f=p+i.height,E=G(d,c),h=Te(G(r,s),E,t.angle),g=Te(G(a,s),E,t.angle),x=Te(G(u,p),E,-t.angle),y=Te(G(m,p),E,-t.angle),b=Te(G(u,f),E,-t.angle),w=Te(G(m,f),E,-t.angle);return h[0]<g[0]&&h[1]>=g[1]?(r=Math.min(r,b[0]),a=Math.max(a,Math.max(y[0],w[0])),s=Math.min(s,x[1]),l=Math.max(l,w[1])):h[0]>=g[0]&&h[1]>g[1]?(r=Math.min(r,w[0]),a=Math.max(a,Math.max(x[0],y[0])),s=Math.min(s,b[1]),l=Math.max(l,y[1])):h[0]>=g[0]?(r=Math.min(r,y[0]),a=Math.max(a,b[0]),s=Math.min(s,w[1]),l=Math.max(l,x[1])):h[1]<=g[1]&&(r=Math.min(r,Math.min(y[0],x[0])),a=Math.max(a,w[0]),s=Math.min(s,y[1]),l=Math.max(l,b[1])),[r,s,a,l,d,c]};static getElementAbsoluteCoords=(t,n,o=!1)=>{let i,r,s,a,l;if(t.points.length<2||!Pe.get(t)){let{minX:p,minY:m,maxX:f,maxY:E}=t.points.reduce((h,[g,x])=>(h.minY=Math.min(h.minY,x),h.minX=Math.min(h.minX,g),h.maxX=Math.max(h.maxX,g),h.maxY=Math.max(h.maxY,x),h),{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});r=p+t.x,s=m+t.y,a=f+t.x,l=E+t.y}else{let p=Pe.generateElementShape(t,null),m=gt(p[0]),[f,E,h,g]=ao(m);r=f+t.x,s=E+t.y,a=h+t.x,l=g+t.y}let d=(r+a)/2,c=(s+l)/2;if(i=[r,s,a,l,d,c],!o)return i;let u=W(t,n);return u&&(i=e.getMinMaxXYWithBoundText(t,n,[r,s,a,l],u)),i};static moveFixedSegment(t,n,o,i,r){let s=r.getNonDeletedElementsMap(),a=e.getElement(t.elementId,s);if(!a||!B(a))return t;if(n&&n>0&&n<a.points.length){let l=Oe(Tt(rm(a.points[n],a.points[n-1]))),d=(a.fixedSegments??[]).reduce((m,f)=>(m[f.index]=f,m),{});d[n]={index:n,start:G(l?a.points[n-1][0]:o-a.x,l?i-a.y:a.points[n-1][1]),end:G(l?a.points[n][0]:o-a.x,l?i-a.y:a.points[n][1])};let c=Object.values(d).sort((m,f)=>m.index-f.index),u=c.map(m=>m.index).reduce((m,f)=>f<n?m+1:m,0);r.mutateElement(a,{fixedSegments:c});let p=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:p,pointerDownState:{...t.pointerDownState,segmentMidpoint:{added:!1,index:a.fixedSegments[u].index,value:p}}}}return t}static deleteFixedSegment(t,n,o){n.mutateElement(t,{fixedSegments:t.fixedSegments?.filter(i=>i.index!==o)})}},um=e=>{let t=[...new Set(e.filter(n=>n!==null&&n!==-1))];return t=t.sort((n,o)=>n-o),t.length?t:null};P();import{arrayToMap as mt}from"@excalidraw/common";import{isPointWithinBounds as Bm,pointFrom as Fr}from"@excalidraw/math";P();import{vectorCross as cl,vectorFromPoint as di}from"@excalidraw/math";function al(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 pm(e,t){return e[0]<=t[2]&&e[2]>=t[0]&&e[1]<=t[3]&&e[3]>=t[1]}var mm=1e-6;function ll(e,t){let n=di(e[1],e[0]),o=di(t,e[0]),i=cl(n,o);return Math.abs(i)<mm}function Br(e,t){let n=di(e[1],e[0]),o=di(t,e[0]);return cl(n,o)<0}function dl(e,t){return ll(e,t[0])||ll(e,t[1])||(Br(e,t[0])?!Br(e,t[1]):Br(e,t[1]))}function ul(e,t){return pm(al(e),al(t))&&dl(e,t)&&dl(t,e)}P();import{arrayToMap as fm}from"@excalidraw/common";import{getElementBounds as hm}from"@excalidraw/element";import{isArrowElement as Em,isExcalidrawElement as gm,isFreeDrawElement as xm,isLinearElement as wm,isTextElement as ym}from"@excalidraw/element";import{rangeIncludesValue as ci,pointFrom as Lt,pointRotateRads as bm,rangeInclusive as ui}from"@excalidraw/math";var Pm=e=>e.type==="diamond"?[Lt(e.width/2,0),Lt(e.width,e.height/2),Lt(e.width/2,e.height),Lt(0,e.height/2)]:[Lt(0,0),Lt(0+e.width,0),Lt(0+e.width,e.height),Lt(0,e.height)],Im=e=>wm(e)||xm(e)?e.points:Pm(e),pl=e=>{let t=e.reduce((n,[o,i])=>(n.minY=Math.min(n.minY,i),n.minX=Math.min(n.minX,o),n.maxX=Math.max(n.maxX,o),n.maxY=Math.max(n.maxY,i),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},fl=e=>{let t=Im(e),{cx:n,cy:o}=pl(t),i=Lt(n,o),r=t.map(c=>bm(c,i,e.angle)),{minX:s,minY:a,maxX:l,maxY:d}=pl(r);return[s+e.x,a+e.y,l+e.x,d+e.y]},ml=(e,t,n=!1)=>{let o=fl(e),i=t[0]<=o[0]&&t[2]>=o[2]&&t[1]<=o[1]&&t[3]>=o[3];return n?i?!0:o[0]<=t[0]&&o[2]>=t[2]&&o[1]<=t[1]&&o[3]>=t[3]:i},Sm=(e,t)=>{let n=fl(e);return(ci(n[0],ui(t[0],t[2]))||ci(t[0],ui(n[0],n[2])))&&(ci(n[1],ui(t[1],t[3]))||ci(t[1],ui(n[1],n[3])))},hl=({elements:e,bounds:t,type:n,errorMargin:o=0})=>{gm(t)&&(t=hm(t,fm(e)));let i=[t[0]-o,t[1]-o,t[2]+o,t[3]+o],r=new Set;for(let s of e){if(r.has(s.id))continue;if(n==="overlap"?Sm(s,i):n==="inside"?ml(s,i):ml(s,i,!0)){if(r.add(s.id),s.boundElements)for(let l of s.boundElements)r.add(l.id);ym(s)&&s.containerId&&r.add(s.containerId),Em(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 Lm,isShallowEqual as Cm}from"@excalidraw/common";P();var Mm=(e,t,n)=>{let o=n.reduce((i,r)=>(r.groupIds.includes(e)&&(i[r.id]=!0),i),{});return Object.keys(o).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,...o}}},El=function(){let e=null,t=null,n=null,o=(r,s,a,l)=>{if(n!==void 0&&s===t&&r===e&&a.editingGroupId===n?.editingGroupId)return n;let d={};for(let p of r){let m=p.groupIds;if(a.editingGroupId){let f=m.indexOf(a.editingGroupId);f>-1&&(m=m.slice(0,f))}if(m.length>0){let f=m[m.length-1];d[f]=!0}}let c={},u=s.reduce((p,m)=>{if(m.isDeleted)return p;let f=m.groupIds.find(E=>d[E]);return f&&(p[m.id]=!0,Array.isArray(c[f])?c[f].push(m.id):c[f]=[m.id]),p},{});for(let p of Object.keys(c))c[p].length<2&&d[p]&&(d[p]=!1);return t=s,e=r,n={editingGroupId:a.editingGroupId,selectedGroupIds:d,selectedElementIds:kr({...a.selectedElementIds,...u},l)},n},i=(r,s,a,l)=>{let d=l?l.scene.getSelectedElements({selectedElementIds:r.selectedElementIds,elements:s}):pt(s,r);return d.length?o(d,s,r,a):{selectedGroupIds:{},editingGroupId:null,selectedElementIds:kr(r.selectedElementIds,a)}};return i.clearCache=()=>{t=null,e=null,n=null},i}(),Tm=(e,t)=>Or(e,t)!=null,Or=(e,t)=>t.groupIds.filter(n=>n!==e.editingGroupId).find(n=>e.selectedGroupIds[n]),Am=e=>Object.entries(e.selectedGroupIds).filter(([t,n])=>n).map(([t,n])=>t),gl=(e,t)=>{let n={...t,selectedGroupIds:{}};for(let o of e){let i=o.groupIds;if(t.editingGroupId){let r=i.indexOf(t.editingGroupId);r>-1&&(i=i.slice(0,r))}if(i.length>0){let r=i[i.length-1];n={...n,...Mm(r,n,e)}}}return n.selectedGroupIds},qy=(e,t)=>({...e,editingGroupId:t.groupIds.length?t.groupIds[0]:null,selectedGroupIds:{},selectedElementIds:{[t.id]:!0}}),Dm=(e,t)=>e.groupIds.includes(t),Ae=(e,t)=>{let n=[];for(let o of e.values())Dm(o,t)&&n.push(o);return n},vm=(e,t)=>e.groupIds.find(n=>t[n]),Ky=(e,t,n)=>{let o=[...e],i=n?o.indexOf(n):-1,r=i>-1?i:o.length;return o.splice(r,0,t),o},Qy=(e,t)=>e.filter(n=>!t[n]),Jy=(e,t)=>{let n=new Map;return e.forEach(o=>{let i=o.groupIds.length===0?o.id:o.groupIds[o.groupIds.length-1],r=n.get(i)||[],s=W(o,t);s&&r.push(s),n.set(i,[...r,o])}),Array.from(n.values())},xl=e=>{let t=new Set;for(let[,n]of e)if(!n.isDeleted)for(let o of n.groupIds??[])t.add(o);return t},wl=e=>{let t=e.flatMap(i=>i.groupIds),n=new Map,o=0;for(let i of t)n.set(i,(n.get(i)??0)+1),n.get(i)>o&&(o=n.get(i));return o===e.length},yl=e=>e.groupIds.length>0,bl=(e,t,n)=>{let o=[...e],i=t?e.indexOf(t):-1,r=i>-1?i:e.length;for(let s=0;s<r;s++)o[s]=n(o[s]);return o},pi=(e,t,n)=>{let o=Am(n),i=e.filter(u=>!ce(u)),r=new Map,s=new Map,a=u=>{let p=s.get(u.id)||[],m=W(u,t);m&&p.push(m),s.set(u.id,[...p,u])},l=(u,p)=>{let m=r.get(p)||[],f=W(u,t);f&&m.push(f),r.set(p,[...m,u])},d=(u,p)=>{let m=u.groupIds.indexOf(p,0);return u.groupIds.slice(0,m).length>0?l(u,u.groupIds[m-1]):a(u)},c=e.every(u=>Tm(n,u));return i.forEach(u=>{let p=vm(u,n.selectedGroupIds);p?o.length===1&&c?d(u,p):l(u,p):a(u)}),Array.from(r.values()).concat(Array.from(s.values()))};var Pl=e=>{let t=new Set;return e.forEach(n=>{q(n)&&t.add(n.id)}),e.filter(n=>!(n.frameId&&t.has(n.frameId)))},Rr=(e,t,n,o=!0)=>{let[i,r,s,a]=Y(t,n),l=e.filter(d=>{let[c,u,p,m]=pe(d,n),f=Ct(d,n);if(f){let[E,h,g,x]=pe(f,n);c=Math.max(E,c),u=Math.max(h,u),p=Math.min(g,p),m=Math.min(x,m)}return d.locked===!1&&d.type!=="selection"&&!ce(d)&&i<=c&&r<=u&&s>=p&&a>=m});return l=o?Pl(l):l,l=l.filter(d=>{let c=Ct(d,n);return c?qt(d,c,n):!0}),l},db=(e,t,n,o)=>{let i=new Set(t.map(r=>r.id));return e.filter(r=>{let s=Il(r,n.width,n.height,n,o);return!i.has(r.id)&&s})},cb=function(){let e=null,t=null,n=null,o=(i,r)=>(n!=null&&i===e&&r.selectedElementIds===t||(n=i.some(s=>r.selectedElementIds[s.id]),e=i,t=r.selectedElementIds),n);return o.clearCache=()=>{e=null,t=null,n=null},o}(),pt=(e,t,n)=>{let o=new Set,i=[];for(let r of e.values()){if(t.selectedElementIds[r.id]){i.push(r),o.add(r.id);continue}if(n?.includeBoundTextElement&&ce(r)&&t.selectedElementIds[r?.containerId]){i.push(r),o.add(r.id);continue}}if(n?.includeElementsInFrames){let r=[];return i.forEach(s=>{q(s)&&Kt(e,s.id).forEach(a=>!o.has(a.id)&&r.push(a)),r.push(s)}),r}return i},ub=(e,t)=>t.editingTextElement?[t.editingTextElement]:t.newElement?[t.newElement]:pt(e,t,{includeBoundTextElement:!0}),kr=(e,t)=>Cm(t.selectedElementIds,e)?t.selectedElementIds:e,Gm=(e,t)=>{let n=e.filter(j);if(n.length===1){let o=n[0],i=o.boundElements?.map(s=>s.id)??[];if(e.every(s=>s.id===o.id||i.includes(s.id)))return new U(o,Lm(t))}return null},pb=(e,t,n)=>({selectedLinearElement:Gm(e,t),...El({editingGroupId:n.editingGroupId,selectedElementIds:Pl(e).reduce((o,i)=>(ce(i)||(o[i.id]=!0),o),{})},t,n,null)});var Sl=(e,t,n)=>{let o=mt(e);for(let i of t)if(i.frameId){let r=n.get(i.id),s=n.get(i.frameId),a=r&&o.get(r);a&&be(a,o,{frameId:s??null})}};function kn(e,t,n){let o=Nr(t,n),i=Nr(e,n);return o.some(s=>i.some(a=>ul(s,a)))}var Ml=(e,t,n)=>mi(Rr(e,t,n,!1)).filter(o=>!q(o)&&!o.frameId||o.frameId===t.id),Hr=(e,t,n)=>Rr([t],e,n).some(o=>o.id===t.id),Mb=(e,t)=>{let n=mt(e);return e.filter(o=>kn(o,t,n))},Qt=(e,t,n)=>{let[o,i,r,s]=Y(t,n),[a,l,d,c]=Xe(e);return o<=a&&i<=l&&r>=d&&s>=c},qt=(e,t,n)=>Qt([e],t,n)||kn(e,t,n)||Hr(e,t,n),Tb=(e,t,n)=>{let[o,i,r,s]=Y(t,n);return Bm(Fr(o,i),Fr(e.x,e.y),Fr(r,s))},Ab=(e,t,n)=>{let o=mt(e),i=t.flatMap(r=>Ae(e,r));return i.length===0?!0:!!i.find(r=>Qt([r],n,o)||kn(r,n,o))},Db=(e,t,n)=>{let o=mt(e),i=t.flatMap(r=>Ae(e,r));return i.length===0?!0:i.find(r=>Qt([r],n,o)||kn(r,n,o))===void 0},vb=e=>{let t=new Map;for(let n of e){let o=q(n)?n.id:n.frameId;o&&!t.has(o)&&t.set(o,Kt(e,o))}return t},Kt=(e,t)=>{let n=[];for(let o of e.values())o.frameId===t&&n.push(o);return n},km=e=>e.filter(t=>q(t)),Lb=e=>{let t=mt(km(e));return e.filter(n=>t.has(n.id)||!n.frameId||!t.has(n.frameId))},Cb=(e,t,n,o)=>{let i=Kt(e,t.id),r=new Set(i),s=new Set([...Ml(e,t,o),...i.filter(p=>Hr(p,t,o))]),a=i.filter(p=>!s.has(p)),l=new Set(Array.from(s).flatMap(p=>p.groupIds));for(let p of a)if(!kn(p,t,o))p.groupIds.length===0&&r.delete(p);else if(p.groupIds.length>0)for(let m of p.groupIds)l.add(m);for(let p of a)if(p.groupIds.length>0){let m=!0;for(let f of p.groupIds)l.has(f)&&(m=!1);m&&r.delete(p)}let d=Array.from(s).filter(p=>p.groupIds.length===0);for(let p of d)r.add(p);let c=Array.from(s).filter(p=>p.groupIds.length>0),u=gl(c,n);for(let[p,m]of Object.entries(u))if(m){let f=Ae(e,p);if(Qt(f,t,o))for(let E of f)r.add(E)}return[...r].filter(p=>!(oe(p)&&p.containerId))},Gb=(e,t,n)=>Om(mi(e,Ml(e,t,n)),t,n),Om=(e,t,n)=>{let o=[],i=new Map;for(let r of e){let s=!1;if(r.groupIds.length>0){if(r.groupIds.some(a=>i.get(a)))s=!0;else{let a=new Set(r.groupIds.flatMap(l=>Ae(n,l)));s=!Qt(Array.from(a),t,n)}r.groupIds.forEach(a=>{i.set(a,s)})}s||o.push(r)}return o},Ct=(e,t)=>e.frameId&&t.get(e.frameId)||null,Bb=(e,t)=>{let n=new Set,o=mt(e);e=mi(e);for(let s of e)q(s)&&s.id!==t.id&&n.add(s.id);let i=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(!i.has(a)){i.add(a);let l=Ae(e,a);if(l.some(d=>qt(d,t,o)))for(let d of l)r.push(d)}}else qt(s,t,o)&&r.push(s);return r},Rm=(e,t,n,o)=>{let i=mt(e),r=new Map;for(let d of e.values())d.frameId===n.id&&r.set(d.id,!0);let s=new Set(t.map(d=>d.id)),a=[],l=new Set;for(let d of t)q(d)&&d.id!==n.id&&l.add(d.id);for(let d of mi(e,t)){if(q(d)||d.frameId&&l.has(d.frameId)||d.frameId&&o.selectedElementIds[d.id]&&o.selectedElementIds[d.frameId])continue;r.has(d.id)||a.push(d);let c=W(d,i);c&&!s.has(c.id)&&!r.has(c.id)&&a.push(c)}for(let d of a)be(d,i,{frameId:n.id});return e},Tl=(e,t)=>{let n=new Map,o=new Map;for(let i of e)if(i.frameId){n.set(i.id,i);let r=o.get(i.frameId)||[];r.push(i);let s=W(i,t);s&&(n.set(s.id,s),r.push(s)),o.set(i.frameId,r)}for(let[,i]of n)be(i,t,{frameId:null})},Fm=(e,t)=>{let n=Kt(e,t.id);return Tl(n,mt(e)),e},kb=(e,t,n,o)=>Rm(Fm(e,n),t,n,o.state).slice(),Ob=(e,t,n)=>{let o=n.scene.getSelectedElements({selectedElementIds:t.selectedElementIds,elements:e}),i=new Set(o);if(t.editingGroupId)for(let a of o)a.groupIds.length===0?i.add(a):a.groupIds.flatMap(l=>Ae(e,l)).forEach(l=>i.add(l));let r=new Set,s=mt(e);return i.forEach(a=>{a.frameId&&!q(a)&&!Al(a,s,t)&&r.add(a)}),r.size>0&&Tl(r,s),e},mi=(e,t)=>{let n=new Set,o=t||e;for(let s of o.values()){let a=s.groupIds[s.groupIds.length-1];a&&n.add(a)}let i=new Set;for(let s of n)Ae(e,s).some(a=>q(a))&&i.add(s);let r=[];for(let s of o.values())i.has(s.groupIds[s.groupIds.length-1])||r.push(s);return r},Nm=(e,t,n)=>{let o=oe(e)&&Ce(e,t)||e;return o.frameId&&n.selectedElementIds[o.id]&&n.selectedElementIds[o.frameId]?Ct(o,t):n.selectedElementIds[o.id]&&n.selectedElementsAreBeingDragged?n.frameToHighlight:Ct(o,t)},Al=(e,t,n,o)=>{let i=o?.targetFrame??Nm(e,t,n);if(!i)return!1;let r=oe(e)&&Ce(e,t)||e,s=l=>{o?.checkedGroups&&r.groupIds.forEach(d=>{o.checkedGroups?.set(d,l)})};if(!n.selectedElementIds[r.id]||!n.selectedElementsAreBeingDragged||n.selectedElementIds[r.id]&&n.selectedElementIds[i.id])return!0;if(r.groupIds.length===0)return qt(r,i,t);for(let l of r.groupIds)if(o?.checkedGroups?.has(l))return o.checkedGroups.get(l);let a=new Set(r.groupIds.filter(l=>o?.checkedGroups?!o.checkedGroups.has(l):!0).flatMap(l=>Ae(t,l)));if(n.editingGroupId&&n.selectedElementsAreBeingDragged){let l=new Set(pt(t,n));if(n.frameToHighlight!==null)return!0;l.forEach(c=>{a.delete(c)})}for(let l of a)if(q(l))return s(!1),!1;for(let l of a)if(qt(l,i,t))return s(!0),!0;return!1},Rb=(e,t,n,o,i)=>{if(!n.frameRendering||!n.frameRendering.clip)return!1;let r=kn(e,t,o)||Hr(e,t,o);if(r){for(let s of e.groupIds)i?.set(s,!0);return!0}if(!r&&e.groupIds.length>0&&!Qt([e],t,o)){let s=!1;if(n.selectedElementsAreBeingDragged)s=Al(e,o,n,{targetFrame:t,checkedGroups:i});else{s=e.frameId===t.id;for(let a of e.groupIds)i?.set(a,s)}for(let a of e.groupIds)i?.set(a,s);return s}return!1},Hm="Frame",zm="AI Frame",_m=e=>Fo(e)?Hm:zm,Fb=e=>e.name===null?_m(e):e.name,Nb=(e,t)=>hl({elements:e,bounds:t,type:"overlap"}).filter(n=>!n.frameId||n.frameId===t.id),Hb=e=>{let t=mt(e);return e.length>1&&e.some(n=>n.frameId&&t.has(n.frameId))};var Zm="invert(100%) hue-rotate(180deg) saturate(1.25)",Gl=(e,t)=>_t(e)&&!t.imageCache.has(e.fileId),Bl=(e,t,n)=>n.theme===Cl.DARK&&_t(e)&&!Gl(e,t)&&t.imageCache.get(e.fileId)?.mimeType!==Yr.svg,wi=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}},qm=(e,t,n,o,i=1)=>{let r=(t?.opacity??100)*e.opacity/1e4*i;return(n.has(e.id)||o&&o.some(s=>s.id===e.id)||t&&n.has(t.id))&&(r*=Xm/100),r},Km=(e,t,n)=>{let r=wi(e),[s,a,l,d]=Y(e,t),c=j(e)||Me(e)?Jt(s,l):e.width,u=j(e)||Me(e)?Jt(a,d):e.height,p=c*window.devicePixelRatio+r*2,m=u*window.devicePixelRatio+r*2,f=n.value;return(p*f>32767||m*f>32767)&&(f=Math.min(32767/p,32767/m)),p*m*f*f>16777216&&(f=Math.sqrt(16777216/(p*m))),p=Math.floor(p*f),m=Math.floor(m*f),{width:p,height:m,scale:f}},kl=(e,t,n,o,i)=>{let r=document.createElement("canvas"),s=r.getContext("2d"),a=wi(e),{width:l,height:d,scale:c}=Km(e,t,n);if(!l||!d)return null;r.width=l,r.height=d;let u=-100,p=0;if(j(e)||Me(e)){let[g,x]=Y(e,t);u=e.x>g?Jt(e.x,g)*window.devicePixelRatio*c:0,p=e.y>x?Jt(e.y,x)*window.devicePixelRatio*c:0,s.translate(u,p)}s.save(),s.translate(a*c,a*c),s.scale(window.devicePixelRatio*c,window.devicePixelRatio*c);let m=pn.canvas(r);Bl(e,o,i)&&(s.filter=Zm),gi(e,m,s,o,i),s.restore();let f=W(e,t),E=document.createElement("canvas"),h=E.getContext("2d");if(_(e)&&f){let[g,x,y,b]=Y(e,t),w=Math.max(Jt(g,y),Jt(x,b));E.width=w*window.devicePixelRatio*c+a*c*10,E.height=w*window.devicePixelRatio*c+a*c*10,h.translate(E.width/2,E.height/2),h.rotate(e.angle),h.drawImage(r,-r.width/2,-r.height/2,r.width,r.height);let[,,,,I,M]=Y(f,t);h.rotate(-e.angle);let D=(E.width-r.width)/2,T=(E.height-r.height)/2,N=E.width/2-(I-g)*window.devicePixelRatio*c-D-a*c,C=E.height/2-(M-x)*window.devicePixelRatio*c-T-a*c;h.translate(-N,-C),h.clearRect(-(f.width/2+hi)*window.devicePixelRatio*c,-(f.height/2+hi)*window.devicePixelRatio*c,(f.width+hi*2)*window.devicePixelRatio*c,(f.height+hi*2)*window.devicePixelRatio*c)}return{element:e,canvas:r,theme:i.theme,scale:c,zoomValue:n.value,canvasOffsetX:u,canvasOffsetY:p,boundTextElementVersion:W(e,t)?.version||null,containingFrameOpacity:Ct(e,t)?.opacity||100,boundTextCanvas:E,angle:e.angle,imageCrop:we(e)?e.crop:null}},t0=14,Ol=typeof document<"u"?document.createElement("img"):{src:""};Ol.src=`data:${Yr.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 Rl=typeof document<"u"?document.createElement("img"):{src:""};Rl.src=`data:${Yr.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 Qm=(e,t)=>{t.fillStyle="#E7E7E7",t.fillRect(0,0,e.width,e.height);let n=Math.min(e.width,e.height),o=Math.min(n,Math.min(n*.4,100));t.drawImage(e.status==="error"?Rl:Ol,e.width/2-o/2,e.height/2-o/2,o,o)},gi=(e,t,n,o,i)=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":{n.lineJoin="round",n.lineCap="round",t.draw(Pe.get(e));break}case"arrow":case"line":{n.lineJoin="round",n.lineCap="round",Pe.get(e).forEach(r=>{t.draw(r)});break}case"freedraw":{n.save(),n.fillStyle=e.strokeColor;let r=Jm(e),s=Pe.get(e);s&&t.draw(s),n.fillStyle=e.strokeColor,n.fill(r),n.restore();break}case"image":{let r=_t(e)?o.imageCache.get(e.fileId)?.image:void 0;if(r!=null&&!(r instanceof Promise)){e.roundness&&n.roundRect&&(n.beginPath(),n.roundRect(0,0,e.width,e.height,yt(Math.min(e.width,e.height),e)),n.clip());let{x:s,y:a,width:l,height:d}=e.crop?e.crop:{x:0,y:0,width:r.naturalWidth,height:r.naturalHeight};n.drawImage(r,s,a,l,d,0,0,e.width,e.height)}else Qm(e,n);break}default:if(oe(e)){let r=Wm(e.text),s=r&&!n.canvas.isConnected;s&&document.body.appendChild(n.canvas),n.canvas.setAttribute("dir",r?"rtl":"ltr"),n.save(),n.font=jm(e),n.fillStyle=e.strokeColor,n.textAlign=e.textAlign;let a=e.text.replace(/\r\n?/g,`
10
10
  `).split(`
11
- `),l=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,c=zi(e.fontSize,e.lineHeight),d=Ym(e.fontFamily,e.fontSize,c);for(let u=0;u<a.length;u++)n.fillText(a[u],l,u*c+d);n.restore(),s&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},Eo=new WeakMap,Ml=(e,t,n,i)=>{let o=n?i.zoom:{value:1},r=Eo.get(e),s=r&&r.zoomValue!==o.value&&!i?.shouldCacheIgnoreZoom,a=W(e,t),l=a?.version||null,c=xe(e)?e.crop:null,d=vt(e,t)?.opacity||100;if(!r||s||r.theme!==i.theme||r.boundTextElementVersion!==l||r.imageCrop!==c||r.containingFrameOpacity!==d||_(e)&&a&&e.angle!==r.angle){let u=Ll(e,t,o,n,i);return u?(Eo.set(e,u),u):null}return r},Nr=(e,t,n,i,o)=>{let r=e.element,s=go(r),a=e.scale,[l,c,d,u]=H(r,o),p=((l+d)/2+i.scrollX)*window.devicePixelRatio,m=((c+u)/2+i.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=W(r,o);if(_(r)&&f){let E=(e.boundTextCanvas.width-e.canvas.width)/2,h=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(p,m),t.drawImage(e.boundTextCanvas,-(d-l)/2*window.devicePixelRatio-E/a-s,-(u-c)/2*window.devicePixelRatio-h/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(p,m),t.rotate(r.angle),"scale"in e.element&&!Dl(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-p,-m),t.drawImage(e.canvas,(l+i.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(c+i.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),A.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&st(r)){let E=W(r,o),h=ar(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((h.x+i.scrollX)*window.devicePixelRatio,(h.y+i.scrollY)*window.devicePixelRatio,Je(r,E)*window.devicePixelRatio,ei(r,E)*window.devicePixelRatio)}t.restore()},$b=(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()},Zb=(e,t,n,i,o,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(o.globalAlpha=Xm(e,vt(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Nm: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=fo.strokeWidth/s.zoom.value,o.strokeStyle=fo.strokeColor,oa(e)&&(o.strokeStyle=s.theme===Al.LIGHT?"#7affd7":"#1d8264"),fo.radius&&o.roundRect?(o.beginPath(),o.roundRect(0,0,e.width,e.height,fo.radius/s.zoom.value),o.stroke(),o.closePath()):o.strokeRect(0,0,e.width,e.height),o.restore());break}case"freedraw":{if(be.generateElementShape(e,null),r.isExporting){let[l,c,d,u]=H(e,t),p=(l+d)/2+s.scrollX,m=(c+u)/2+s.scrollY,f=(d-l)/2-(e.x-l),E=(u-c)/2-(e.y-c);o.save(),o.translate(p,m),o.rotate(e.angle),o.translate(-f,-E),ho(e,i,o,r,s),o.restore()}else{let l=Ml(e,n,r,s);if(!l)return;Nr(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(be.generateElementShape(e,r),r.isExporting){let[l,c,d,u]=H(e,t),p=(l+d)/2+s.scrollX,m=(c+u)/2+s.scrollY,f=(d-l)/2-(e.x-l),E=(u-c)/2-(e.y-c);if(ie(e)){let g=Ce(e,t);if(_(g)){let x=Y.getBoundTextElementPosition(g,e,t);f=(d-l)/2-(x.x-l),E=(u-c)/2-(x.y-c)}}o.save(),o.translate(p,m),vl(e,r,s)&&(o.filter="none");let h=W(e,t);if(_(e)&&h){let g=document.createElement("canvas"),x=g.getContext("2d"),y=Math.max(Qt(l,d),Qt(c,u)),b=go(e);g.width=y*s.exportScale+b*10*s.exportScale,g.height=y*s.exportScale+b*10*s.exportScale,x.translate(g.width/2,g.height/2),x.scale(s.exportScale,s.exportScale),f=e.width/2-(e.x-l),E=e.height/2-(e.y-c),x.rotate(e.angle);let w=an.canvas(g);x.translate(-f,-E),ho(e,w,x,r,s),x.translate(f,E),x.rotate(-e.angle);let[,,,,I,M]=H(h,t),D=(l+d)/2-I,T=(c+u)/2-M;x.translate(-D,-T),x.clearRect(-h.width/2,-h.height/2,h.width,h.height),o.scale(1/s.exportScale,1/s.exportScale),o.drawImage(g,-g.width/2,-g.height/2,g.width,g.height)}else o.rotate(e.angle),e.type==="image"&&o.scale(e.scale[0],e.scale[1]),o.translate(-f,-E),ho(e,i,o,r,s);o.restore()}else{let l=Ml(e,n,r,s);if(!l)return;let c=o.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Fm(e.angle))&&(o.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&xe(l.element)&&l.element.crop!==null){o.save(),o.globalAlpha=.1;let d=Ll(Qs(l.element,t),n,s.zoom,r,s);d&&Nr(d,o,r,s,n),o.restore()}Nr(l,o,r,s,n),o.imageSmoothingEnabled=c}break}default:throw new Error(`Unimplemented type ${e.type}`)}o.globalAlpha=1},Gl=new WeakMap([]);function Ol(e){let t=$m(e),n=new Path2D(t);return Gl.set(e,n),n}function Vm(e){return Gl.get(e)}function $m(e){let t=e.simulatePressure?e.points:e.points.length?e.points.map(([i,o],r)=>[i,o,e.pressures[r]]):[[0,0,.5]],n={simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:i=>Math.sin(i*Math.PI/2),last:!!e.lastCommittedPoint};return qm(Vs(t,n))}function Tl(e,t){return[(e[0]+t[0])/2,(e[1]+t[1])/2]}var Zm=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;function qm(e){if(!e.length)return"";let t=e.length-1;return e.reduce((n,i,o,r)=>(o===t?n.push(i,Tl(i,r[0]),"L",r[0],"Z"):n.push(i,Tl(i,r[o+1])),n),["M",e[0],"Q"]).join(" ").replace(Zm,"$1")}P();var Qb=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",Jb=e=>e!=="image"&&e!=="frame"&&e!=="magicframe",e0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",t0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Rl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",n0=e=>e==="arrow",i0=e=>e==="arrow";var be=class e{static rg=new Xe;static cache=new WeakMap;static get=t=>e.cache.get(t);static set=(t,n)=>e.cache.set(t,n);static delete=t=>e.cache.delete(t);static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let i=n?.isExporting?void 0:e.get(t);if(i!==void 0)return i;Eo.delete(t);let o=of(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:Jm.white,embedsValidationStatus:null});return e.cache.set(t,o),o}},tf=e=>[8,8+e],zl=e=>[1.5,6+e];function nf(e){let t=e.roughness,n=Math.max(e.width,e.height),i=Math.min(e.width,e.height);return i>=20&&n>=50||i>=15&&e.roundness&&Rl(e.type)||X(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var ke=(e,t=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?tf(e.strokeWidth):e.strokeStyle==="dotted"?zl(e.strokeWidth):void 0,disableMultiStroke:e.strokeStyle!=="solid",strokeWidth:e.strokeStyle!=="solid"?e.strokeWidth+.5:e.strokeWidth,fillWeight:e.strokeWidth/2,hachureGap:e.strokeWidth*4,roughness:nf(e),stroke:e.strokeColor,preserveVertices:t||e.roughness<Km.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=ai(e.backgroundColor)?void 0:e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return ln(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},Fl=(e,t,n)=>Oi(e)&&(t||ia(e)&&n?.get(e.id)!==!0)&&ai(e.backgroundColor)&&ai(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:Gi(e)?{...e,strokeColor:ai(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:ai(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Nl=(e,t,n,i,o,r,s)=>{let a=Hr(e,t,n,i);if(a===null)return[];let l=(c,d)=>{if(c===null)return[];let[,,u,p,m,f]=c;return[o.line(u,p,m,f,d)]};switch(i){case"dot":case"circle":case"circle_outline":{let[c,d,u]=a;return delete r.strokeLineDash,[o.circle(c,d,u,{...r,fill:i==="circle_outline"?s:e.strokeColor,fillStyle:"solid",stroke:e.strokeColor,roughness:Math.min(.5,r.roughness||0)})]}case"triangle":case"triangle_outline":{let[c,d,u,p,m,f]=a;return delete r.strokeLineDash,[o.polygon([[c,d],[u,p],[m,f],[c,d]],{...r,fill:i==="triangle_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[c,d,u,p,m,f,E,h]=a;return delete r.strokeLineDash,[o.polygon([[c,d],[u,p],[m,f],[E,h],[c,d]],{...r,fill:i==="diamond_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"crowfoot_one":return l(a,r);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[c,d,u,p,m,f]=a;if(e.strokeStyle==="dotted"){let E=zl(e.strokeWidth-1);r.strokeLineDash=[E[0],E[1]-1]}else delete r.strokeLineDash;return r.roughness=Math.min(1,r.roughness||0),[o.line(u,p,c,d,r),o.line(m,f,c,d,r),...i==="crowfoot_one_or_many"?l(Hr(e,t,n,"crowfoot_one"),r):[]]}}},ta=e=>{let t=new Xe,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},i=ct(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:[ce(0,0)];return G(e)?t.path(Hl(o,16),n).sets[0].ops:e.roundness?t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Lt(ce(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:ce(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(ce(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Lt(ce(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Lt(ce(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>ce(a[0]-e.x,a[1]-e.y)).flat()}}):o.map((r,s)=>{let a=Lt(ce(e.x+r[0],e.y+r[1]),i,e.angle);return{op:s===0?"move":"lineTo",data:ce(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let o=Wn(e.points,.75);return t.curve(o,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Lt(ce(e.x+r.data[0],e.y+r.data[1]),i,e.angle);return{op:"move",data:ce(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Lt(ce(e.x+r.data[0],e.y+r.data[1]),i,e.angle),Lt(ce(e.x+r.data[2],e.y+r.data[3]),i,e.angle),Lt(ce(e.x+r.data[4],e.y+r.data[5]),i,e.angle)].map(a=>ce(a[0]-e.x,a[1]-e.y)).flat()}})}}},of=(e,t,{isExporting:n,canvasBackgroundColor:i,embedsValidationStatus:o})=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":{let r;if(e.roundness){let s=e.width,a=e.height,l=yt(Math.min(s,a),e);r=t.path(`M ${l} 0 L ${s-l} 0 Q ${s} 0, ${s} ${l} L ${s} ${a-l} Q ${s} ${a}, ${s-l} ${a} L ${l} ${a} Q 0 ${a}, 0 ${a-l} L 0 ${l} Q 0 0, ${l} 0`,ke(Fl(e,n,o),!0))}else r=t.rectangle(0,0,e.width,e.height,ke(Fl(e,n,o),!1));return r}case"diamond":{let r,[s,a,l,c,d,u,p,m]=Bi(e);if(e.roundness){let f=yt(Math.abs(s-p),e),E=yt(Math.abs(c-a),e);r=t.path(`M ${s+f} ${a+E} L ${l-f} ${c-E}
12
- C ${l} ${c}, ${l} ${c}, ${l-f} ${c+E}
13
- L ${d+f} ${u-E}
14
- C ${d} ${u}, ${d} ${u}, ${d-f} ${u-E}
11
+ `),l=e.textAlign==="center"?e.width/2:e.textAlign==="right"?e.width:0,d=_o(e.fontSize,e.lineHeight),c=Vm(e.fontFamily,e.fontSize,d);for(let u=0;u<a.length;u++)n.fillText(a[u],l,u*d+c);n.restore(),s&&n.canvas.remove()}else throw new Error(`Unimplemented type ${e.type}`)}},xi=new WeakMap,vl=(e,t,n,o)=>{let i=n?o.zoom:{value:1},r=xi.get(e),s=r&&r.zoomValue!==i.value&&!o?.shouldCacheIgnoreZoom,a=W(e,t),l=a?.version||null,d=we(e)?e.crop:null,c=Ct(e,t)?.opacity||100;if(!r||s||r.theme!==o.theme||r.boundTextElementVersion!==l||r.imageCrop!==d||r.containingFrameOpacity!==c||_(e)&&a&&e.angle!==r.angle){let u=kl(e,t,i,n,o);return u?(xi.set(e,u),u):null}return r},_r=(e,t,n,o,i)=>{let r=e.element,s=wi(r),a=e.scale,[l,d,c,u]=Y(r,i),p=((l+c)/2+o.scrollX)*window.devicePixelRatio,m=((d+u)/2+o.scrollY)*window.devicePixelRatio;t.save(),t.scale(1/window.devicePixelRatio,1/window.devicePixelRatio);let f=W(r,i);if(_(r)&&f){let E=(e.boundTextCanvas.width-e.canvas.width)/2,h=(e.boundTextCanvas.height-e.canvas.height)/2;t.translate(p,m),t.drawImage(e.boundTextCanvas,-(c-l)/2*window.devicePixelRatio-E/a-s,-(u-d)/2*window.devicePixelRatio-h/a-s,e.boundTextCanvas.width/a,e.boundTextCanvas.height/a)}else if(t.translate(p,m),t.rotate(r.angle),"scale"in e.element&&!Gl(r,n)&&t.scale(e.element.scale[0],e.element.scale[1]),t.translate(-p,-m),t.drawImage(e.canvas,(l+o.scrollX)*window.devicePixelRatio-s*e.scale/e.scale,(d+o.scrollY)*window.devicePixelRatio-s*e.scale/e.scale,e.canvas.width/e.scale,e.canvas.height/e.scale),A.VITE_APP_DEBUG_ENABLE_TEXT_CONTAINER_BOUNDING_BOX==="true"&&st(r)){let E=W(r,i),h=dr(r);t.strokeStyle="#c92a2a",t.lineWidth=3,t.strokeRect((h.x+o.scrollX)*window.devicePixelRatio,(h.y+o.scrollY)*window.devicePixelRatio,et(r,E)*window.devicePixelRatio,no(r,E)*window.devicePixelRatio)}t.restore()},n0=(e,t,n,o)=>{t.save(),t.translate(e.x+n.scrollX,e.y+n.scrollY),t.fillStyle="rgba(0, 0, 200, 0.04)";let i=.5/n.zoom.value;t.fillRect(i,i,e.width,e.height),t.lineWidth=1/n.zoom.value,t.strokeStyle=o,t.strokeRect(i,i,e.width,e.height),t.restore()},o0=(e,t,n,o,i,r,s)=>{let a=s.openDialog?.name==="elementLinkSelector"&&!s.selectedElementIds[e.id]&&!s.hoveredElementIds[e.id];switch(i.globalAlpha=qm(e,Ct(e,t),r.elementsPendingErasure,r.pendingFlowchartNodes,a?Um:1),e.type){case"magicframe":case"frame":{s.frameRendering.enabled&&s.frameRendering.outline&&(i.save(),i.translate(e.x+s.scrollX,e.y+s.scrollY),i.fillStyle="rgba(0, 0, 200, 0.04)",i.lineWidth=Ei.strokeWidth/s.zoom.value,i.strokeStyle=Ei.strokeColor,aa(e)&&(i.strokeStyle=s.theme===Cl.LIGHT?"#7affd7":"#1d8264"),Ei.radius&&i.roundRect?(i.beginPath(),i.roundRect(0,0,e.width,e.height,Ei.radius/s.zoom.value),i.stroke(),i.closePath()):i.strokeRect(0,0,e.width,e.height),i.restore());break}case"freedraw":{if(Pe.generateElementShape(e,null),r.isExporting){let[l,d,c,u]=Y(e,t),p=(l+c)/2+s.scrollX,m=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);i.save(),i.translate(p,m),i.rotate(e.angle),i.translate(-f,-E),gi(e,o,i,r,s),i.restore()}else{let l=vl(e,n,r,s);if(!l)return;_r(l,i,r,s,n)}break}case"rectangle":case"diamond":case"ellipse":case"line":case"arrow":case"image":case"text":case"iframe":case"embeddable":{if(Pe.generateElementShape(e,r),r.isExporting){let[l,d,c,u]=Y(e,t),p=(l+c)/2+s.scrollX,m=(d+u)/2+s.scrollY,f=(c-l)/2-(e.x-l),E=(u-d)/2-(e.y-d);if(oe(e)){let g=Ce(e,t);if(_(g)){let x=U.getBoundTextElementPosition(g,e,t);f=(c-l)/2-(x.x-l),E=(u-d)/2-(x.y-d)}}i.save(),i.translate(p,m),Bl(e,r,s)&&(i.filter="none");let h=W(e,t);if(_(e)&&h){let g=document.createElement("canvas"),x=g.getContext("2d"),y=Math.max(Jt(l,c),Jt(d,u)),b=wi(e);g.width=y*s.exportScale+b*10*s.exportScale,g.height=y*s.exportScale+b*10*s.exportScale,x.translate(g.width/2,g.height/2),x.scale(s.exportScale,s.exportScale),f=e.width/2-(e.x-l),E=e.height/2-(e.y-d),x.rotate(e.angle);let w=pn.canvas(g);x.translate(-f,-E),gi(e,w,x,r,s),x.translate(f,E),x.rotate(-e.angle);let[,,,,I,M]=Y(h,t),D=(l+c)/2-I,T=(d+u)/2-M;x.translate(-D,-T),x.clearRect(-h.width/2,-h.height/2,h.width,h.height),i.scale(1/s.exportScale,1/s.exportScale),i.drawImage(g,-g.width/2,-g.height/2,g.width,g.height)}else i.rotate(e.angle),e.type==="image"&&i.scale(e.scale[0],e.scale[1]),i.translate(-f,-E),gi(e,o,i,r,s);i.restore()}else{let l=vl(e,n,r,s);if(!l)return;let d=i.imageSmoothingEnabled;if(!s?.shouldCacheIgnoreZoom&&(!e.angle||Ym(e.angle))&&(i.imageSmoothingEnabled=!1),e.id===s.croppingElementId&&we(l.element)&&l.element.crop!==null){i.save(),i.globalAlpha=.1;let c=kl(ta(l.element,t),n,s.zoom,r,s);c&&_r(c,i,r,s,n),i.restore()}_r(l,i,r,s,n),i.imageSmoothingEnabled=d}break}default:throw new Error(`Unimplemented type ${e.type}`)}i.globalAlpha=1},Fl=new WeakMap([]);function Nl(e){let t=ef(e),n=new Path2D(t);return Fl.set(e,n),n}function Jm(e){return Fl.get(e)}function ef(e){return of(tf(e))}function i0(e,t,n){let o=pe({...e,angle:0},n),i=fi((o[0]+o[2])/2,(o[1]+o[3])/2);return $m(t.length>=2,"Freepath outline must have at least 2 points"),t.slice(2).reduce((r,s)=>(r.push(Dl(r[r.length-1][1],zr(fi(s[0]+e.x,s[1]+e.y),i,e.angle))),r),[Dl(zr(fi(t[0][0]+e.x,t[0][1]+e.y),i,e.angle),zr(fi(t[1][0]+e.x,t[1][1]+e.y),i,e.angle))])}function tf(e){let t=e.simulatePressure?e.points:e.points.length?e.points.map(([o,i],r)=>[o,i,e.pressures[r]]):[[0,0,.5]],n={simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:o=>Math.sin(o*Math.PI/2),last:!!e.lastCommittedPoint};return qs(t,n)}function Ll(e,t){return[(e[0]+t[0])/2,(e[1]+t[1])/2]}var nf=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g;function of(e){if(!e.length)return"";let t=e.length-1;return e.reduce((n,o,i,r)=>(i===t?n.push(o,Ll(o,r[0]),"L",r[0],"Z"):n.push(o,Ll(o,r[i+1])),n),["M",e[0],"Q"]).join(" ").replace(nf,"$1")}P();var a0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="line"||e==="freedraw",l0=e=>e!=="image"&&e!=="frame"&&e!=="magicframe",d0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="freedraw"||e==="arrow"||e==="line",c0=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="ellipse"||e==="diamond"||e==="arrow"||e==="line",Hl=e=>e==="rectangle"||e==="iframe"||e==="embeddable"||e==="line"||e==="diamond"||e==="image",u0=e=>e==="arrow",p0=e=>e==="arrow";var Pe=class e{static rg=new je;static cache=new WeakMap;static get=t=>e.cache.get(t);static set=(t,n)=>e.cache.set(t,n);static delete=t=>e.cache.delete(t);static destroy=()=>{e.cache=new WeakMap};static generateElementShape=(t,n)=>{let o=n?.isExporting?void 0:e.get(t);if(o!==void 0)return o;xi.delete(t);let i=uf(t,e.rg,n||{isExporting:!1,canvasBackgroundColor:af.white,embedsValidationStatus:null});return e.cache.set(t,i),i}},df=e=>[8,8+e],Ul=e=>[1.5,6+e];function cf(e){let t=e.roughness,n=Math.max(e.width,e.height),o=Math.min(e.width,e.height);return o>=20&&n>=50||o>=15&&e.roundness&&Hl(e.type)||j(e)&&n>=50?t:Math.min(t/(n<10?3:2),2.5)}var Fe=(e,t=!1)=>{let n={seed:e.seed,strokeLineDash:e.strokeStyle==="dashed"?df(e.strokeWidth):e.strokeStyle==="dotted"?Ul(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:cf(e),stroke:e.strokeColor,preserveVertices:t||e.roughness<rf.cartoonist};switch(e.type){case"rectangle":case"iframe":case"embeddable":case"diamond":case"ellipse":return n.fillStyle=e.fillStyle,n.fill=lo(e.backgroundColor)?void 0:e.backgroundColor,e.type==="ellipse"&&(n.curveFitting=1),n;case"line":case"freedraw":return mn(e.points)&&(n.fillStyle=e.fillStyle,n.fill=e.backgroundColor==="transparent"?void 0:e.backgroundColor),n;case"arrow":return n;default:throw new Error(`Unimplemented type ${e.type}`)}},_l=(e,t,n)=>Ro(e)&&(t||sa(e)&&n?.get(e.id)!==!0)&&lo(e.backgroundColor)&&lo(e.strokeColor)?{...e,roughness:0,backgroundColor:"#d3d3d3",fillStyle:"solid"}:Oo(e)?{...e,strokeColor:lo(e.strokeColor)?"#000000":e.strokeColor,backgroundColor:lo(e.backgroundColor)?"#f4f4f6":e.backgroundColor}:e,Yl=(e,t,n,o,i,r,s)=>{let a=Ur(e,t,n,o);if(a===null)return[];let l=(d,c)=>{if(d===null)return[];let[,,u,p,m,f]=d;return[i.line(u,p,m,f,c)]};switch(o){case"dot":case"circle":case"circle_outline":{let[d,c,u]=a;return delete r.strokeLineDash,[i.circle(d,c,u,{...r,fill:o==="circle_outline"?s:e.strokeColor,fillStyle:"solid",stroke:e.strokeColor,roughness:Math.min(.5,r.roughness||0)})]}case"triangle":case"triangle_outline":{let[d,c,u,p,m,f]=a;return delete r.strokeLineDash,[i.polygon([[d,c],[u,p],[m,f],[d,c]],{...r,fill:o==="triangle_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"diamond":case"diamond_outline":{let[d,c,u,p,m,f,E,h]=a;return delete r.strokeLineDash,[i.polygon([[d,c],[u,p],[m,f],[E,h],[d,c]],{...r,fill:o==="diamond_outline"?s:e.strokeColor,fillStyle:"solid",roughness:Math.min(1,r.roughness||0)})]}case"crowfoot_one":return l(a,r);case"bar":case"arrow":case"crowfoot_many":case"crowfoot_one_or_many":default:{let[d,c,u,p,m,f]=a;if(e.strokeStyle==="dotted"){let E=Ul(e.strokeWidth-1);r.strokeLineDash=[E[0],E[1]-1]}else delete r.strokeLineDash;return r.roughness=Math.min(1,r.roughness||0),[i.line(u,p,d,c,r),i.line(m,f,d,c,r),...o==="crowfoot_one_or_many"?l(Ur(e,t,n,"crowfoot_one"),r):[]]}}},ia=e=>{let t=new je,n={seed:e.seed,disableMultiStroke:!0,disableMultiStrokeFill:!0,roughness:0,preserveVertices:!0},o=dt(e.points.reduce((i,r)=>[Math.min(e.x+r[0],i[0]),Math.min(e.y+r[1],i[1]),Math.max(e.x+r[0],i[2]),Math.max(e.y+r[1],i[3])],[1/0,1/0,-1/0,-1/0]));switch(e.type){case"line":case"arrow":{let i=e.points.length?e.points:[de(0,0)];return B(e)?t.path(Xl(i,16),n).sets[0].ops:e.roundness?t.curve(i,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Gt(de(e.x+r.data[0],e.y+r.data[1]),o,e.angle);return{op:"move",data:de(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Gt(de(e.x+r.data[0],e.y+r.data[1]),o,e.angle),Gt(de(e.x+r.data[2],e.y+r.data[3]),o,e.angle),Gt(de(e.x+r.data[4],e.y+r.data[5]),o,e.angle)].map(a=>de(a[0]-e.x,a[1]-e.y)).flat()}}):i.map((r,s)=>{let a=Gt(de(e.x+r[0],e.y+r[1]),o,e.angle);return{op:s===0?"move":"lineTo",data:de(a[0]-e.x,a[1]-e.y)}})}case"freedraw":{if(e.points.length<2)return[];let i=Wn(e.points,.75);return t.curve(i,n).sets[0].ops.slice(0,e.points.length).map((r,s)=>{if(s===0){let a=Gt(de(e.x+r.data[0],e.y+r.data[1]),o,e.angle);return{op:"move",data:de(a[0]-e.x,a[1]-e.y)}}return{op:"bcurveTo",data:[Gt(de(e.x+r.data[0],e.y+r.data[1]),o,e.angle),Gt(de(e.x+r.data[2],e.y+r.data[3]),o,e.angle),Gt(de(e.x+r.data[4],e.y+r.data[5]),o,e.angle)].map(a=>de(a[0]-e.x,a[1]-e.y)).flat()}})}}},uf=(e,t,{isExporting:n,canvasBackgroundColor:o,embedsValidationStatus:i})=>{switch(e.type){case"rectangle":case"iframe":case"embeddable":{let r;if(e.roundness){let s=e.width,a=e.height,l=yt(Math.min(s,a),e);r=t.path(`M ${l} 0 L ${s-l} 0 Q ${s} 0, ${s} ${l} L ${s} ${a-l} Q ${s} ${a}, ${s-l} ${a} L ${l} ${a} Q 0 ${a}, 0 ${a-l} L 0 ${l} Q 0 0, ${l} 0`,Fe(_l(e,n,i),!0))}else r=t.rectangle(0,0,e.width,e.height,Fe(_l(e,n,i),!1));return r}case"diamond":{let r,[s,a,l,d,c,u,p,m]=ko(e);if(e.roundness){let f=yt(Math.abs(s-p),e),E=yt(Math.abs(d-a),e);r=t.path(`M ${s+f} ${a+E} L ${l-f} ${d-E}
12
+ C ${l} ${d}, ${l} ${d}, ${l-f} ${d+E}
13
+ L ${c+f} ${u-E}
14
+ C ${c} ${u}, ${c} ${u}, ${c-f} ${u-E}
15
15
  L ${p+f} ${m+E}
16
16
  C ${p} ${m}, ${p} ${m}, ${p+f} ${m-E}
17
17
  L ${s-f} ${a+E}
18
- C ${s} ${a}, ${s} ${a}, ${s+f} ${a+E}`,ke(e,!0))}else r=t.polygon([[s,a],[l,c],[d,u],[p,m]],ke(e));return r}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,ke(e));case"line":case"arrow":{let r,s=ke(e),a=e.points.length?e.points:[ce(0,0)];if(G(e)?a.every(l=>Math.abs(l[0])<=1e6&&Math.abs(l[1])<=1e6)?r=[t.path(Hl(a,16),ke(e,!0))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(a)),r=[]):e.roundness?r=[t.curve(a,s)]:s.fill?r=[t.polygon(a,s)]:r=[t.linearPath(a,s)],e.type==="arrow"){let{startArrowhead:l=null,endArrowhead:c="arrow"}=e;if(l!==null){let d=Nl(e,r,"start",l,t,s,i);r.push(...d)}if(c!==null){let d=Nl(e,r,"end",c,t,s,i);r.push(...d)}}return r}case"freedraw":{let r;if(Ol(e),ln(e.points)){let s=Wn(e.points,.75);r=t.curve(s,{...ke(e),stroke:"none"})}else r=null;return r}case"frame":case"magicframe":case"text":case"image":return null;default:return Qm(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Hl=(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=et(a,r),c=et(s,a),d=Math.min(t,kl(e[o],s)/2,kl(e[o],r)/2);l?r[0]<a[0]?n.push([e[o][0]-d,e[o][1]]):n.push([e[o][0]+d,e[o][1]]):r[1]<a[1]?n.push([e[o][0],e[o][1]-d]):n.push([e[o][0],e[o][1]+d]),n.push(e[o]),c?s[0]<a[0]?n.push([e[o][0]-d,e[o][1]]):n.push([e[o][0]+d,e[o][1]]):s[1]<a[1]?n.push([e[o][0],e[o][1]-d]):n.push([e[o][0],e[o][1]+d])}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(" ")},_l=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return ks(e);case"arrow":case"line":{let n=be.get(e)?.[0]??be.generateElementShape(e,null)[0],[,,,,i,o]=H(e,t);return Xi(e)?Hs(e,n,ce(e.x,e.y),e.angle,ce(i,o)):Ns(n,ce(e.x,e.y),e.angle,ce(i,o))}case"ellipse":return Fs(e);case"freedraw":{let[,,,,n,i]=H(e,t);return zs(e,ce(n,i),Xi(e))}}},nl=(e,t)=>{let n=[...e.points];if(t){if(!la(e.points))return null;let o=n[0],r=n[n.length-1];Math.hypot(o[0]-r[0],o[1]-r[1])>ef||n.length<4?n.push(ce(o[0],o[1])):n[n.length-1]=ce(o[0],o[1])}return{polygon:t,points:n}};var Ur=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&&!de(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,c]=H(t,n);if(Se(t)){let[d,u,p,m]=Xr(t.points.map(([f,E])=>se(v(f,E),v(l-t.x,c-t.y),t.angle)));return[d+t.x,u+t.y,p+t.x,m+t.y]}else if(X(t))i=mf(t,l,c,n);else if(t.type==="diamond"){let[d,u]=se(v(l,r),v(l,c),t.angle),[p,m]=se(v(l,a),v(l,c),t.angle),[f,E]=se(v(o,c),v(l,c),t.angle),[h,g]=se(v(s,c),v(l,c),t.angle),x=Math.min(d,p,f,h),y=Math.min(u,m,E,g),b=Math.max(d,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}else if(t.type==="ellipse"){let d=(s-o)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(d*p,u*m),E=Math.hypot(u*p,d*m);i=[l-f,c-E,l+f,c+E]}else{let[d,u]=se(v(o,r),v(l,c),t.angle),[p,m]=se(v(o,a),v(l,c),t.angle),[f,E]=se(v(s,a),v(l,c),t.angle),[h,g]=se(v(s,r),v(l,c),t.angle),x=Math.min(d,p,f,h),y=Math.min(u,m,E,g),b=Math.max(d,p,f,h),w=Math.max(u,m,E,g);i=[x,y,b,w]}return i}},H=(e,t,n=!1)=>{if(Se(e))return cf(e);if(X(e))return Y.getElementAbsoluteCoords(e,t,n);if(ie(e)){let i=t?Ce(e,t):null;if(_(i)){let{x:o,y:r}=Y.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]},kr=(e,t)=>{let n=_l(e,t),[i,o,r,s,a,l]=H(e,t),c=v(a,l);if(n.type==="polycurve"){let g=n.data.map(b=>Et(b,10)).flat(),x=0,y=[];for(;x<g.length-1;)y.push(Ee(v(g[x][0],g[x][1]),v(g[x+1][0],g[x+1][1]))),x++;return y}else{if(n.type==="polyline")return n.data;if(af(e)){let[h,g]=Pn(e),x=g.map(b=>Xl(b,c,e.angle)).flat();return[...Ul(h,c,e.angle),...x]}else if(e.type==="diamond"){let[h,g]=In(e),x=g.map(b=>Xl(b,c,e.angle)).flat();return[...Ul(h,c,e.angle),...x]}else if(n.type==="polygon"){if(ie(e)){let x=Ce(e,t);if(x&&X(x))return[Ee(v(i,o),v(r,o)),Ee(v(r,o),v(r,s)),Ee(v(r,s),v(i,s)),Ee(v(i,s),v(i,o))]}let h=n.data,g=[];for(let x=0;x<h.length-1;x++)g.push(Ee(h[x],h[x+1]));return g}else if(n.type==="ellipse")return lf(e)}let[d,u,p,m,,,f,E]=[[i,o],[r,o],[i,s],[r,s],[a,o],[a,s],[i,l],[r,l]].map(h=>se(h,c,e.angle));return[Ee(d,u),Ee(p,m),Ee(d,p),Ee(u,m),Ee(d,E),Ee(p,E),Ee(u,f),Ee(m,f)]},af=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),Ul=(e,t,n)=>e.map(i=>Ee(se(i[0],t,n),se(i[1],t,n))),Xl=(e,t,n)=>{let i=Et(e,10),o=0,r=[];for(;o<i.length-1;)r.push(Ee(se(v(i[o][0],i[o][1]),t,n),se(v(i[o+1][0],i[o+1][1]),t,n))),o++;return r},lf=e=>{let t=v(e.x+e.width/2,e.y+e.height/2),n=e.width/2,i=e.height/2,o=[],r=[],s=90,a=Math.PI*2/s;for(let l=0;l<s;l++){let c=l*a,d=t[0]+n*Math.cos(c),u=t[1]+i*Math.sin(c);r.push(se(v(d,u),t,e.angle))}for(let l=0;l<r.length-1;l++)o.push(Ee(r[l],r[l+1]));return o.push(Ee(r[r.length-1],r[0])),o},G0=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],Bi=e=>{let t=Math.floor(e.width/2)+1,n=0,i=e.width,o=Math.floor(e.height/2)+1,r=t,s=e.height;return[t,n,i,o,r,s,0,o]},Wl=(e,t,n,i,o)=>{let r=1-e;return Math.pow(r,3)*t+3*Math.pow(r,2)*e*n+3*r*Math.pow(e,2)*i+Math.pow(e,3)*o},jl=(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,c=3*o,d=l*l-4*a*c;if(!(d>=0))return!1;let p=null,m=null,f=1/0,E=1/0;return a===0?f=E=-c/l:(f=(-l+Math.sqrt(d))/(2*a),E=(-l-Math.sqrt(d))/(2*a)),f>=0&&f<=1&&(p=Wl(f,e,t,n,i)),E>=0&&E<=1&&(m=Wl(E,e,t,n,i)),[p,m]},Wi=(e,t,n,i)=>{let o=jl(e[0],t[0],n[0],i[0]),r=jl(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 d=o.filter(u=>u!==null);s=Math.min(s,...d),a=Math.max(a,...d)}let l=Math.min(e[1],i[1]),c=Math.max(e[1],i[1]);if(r){let d=r.filter(u=>u!==null);l=Math.min(l,...d),c=Math.max(c,...d)}return[s,l,a,c]},si=(e,t)=>{let n=v(0,0),{minX:i,minY:o,maxX:r,maxY:s}=e.reduce((a,{op:l,data:c})=>{if(l==="move"){let d=$l(c);Yr(d!=null,"Op data is not a point"),n=d}else if(l==="bcurveTo"){let d=v(c[0],c[1]),u=v(c[2],c[3]),p=v(c[4],c[5]),m=t?t(d):d,f=t?t(u):u,E=t?t(p):p,h=t?t(n):n;n=p;let[g,x,y,b]=Wi(h,m,f,E);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,y),a.maxY=Math.max(a.maxY,b)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[i,o,r,s]},Xr=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]},cf=e=>{let[t,n,i,o]=Xr(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]},df=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}},uf=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},Hr=(e,t,n,i)=>{if(t.length<1)return null;let o=gt(t[0]);if(o.length<1)return null;let r=n==="start"?1:o.length-1,s=o[r].data;Yr(s.length===6,"Op data length is not 6");let a=v(s[4],s[5]),l=v(s[2],s[3]),c=v(s[0],s[1]),d=o[r-1],u=v(0,0);if(d.op==="move"){let N=$l(d.data);Yr(N!=null,"Op data is not a point"),u=N}else d.op==="bcurveTo"&&(u=v(d.data[4],d.data[5]));let p=(N,te)=>Math.pow(1-N,3)*a[te]+3*N*Math.pow(1-N,2)*l[te]+3*Math.pow(N,2)*(1-N)*c[te]+u[te]*Math.pow(N,3),[m,f]=n==="start"?u:a,[E,h]=[p(.3,0),p(.3,1)],g=Math.hypot(m-E,f-h),x=(m-E)/g,y=(f-h)/g,b=df(i),w=0;{let[N,te]=n==="end"?e.points[e.points.length-1]:e.points[0],[S,Q]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];w=Math.hypot(N-S,te-Q)}let M=Math.min(b,w*(i==="diamond"||i==="diamond_outline"?.25:.5)),D=m-x*M,T=f-y*M;if(i==="dot"||i==="circle"||i==="circle_outline"){let N=Math.hypot(T-f,D-m)+e.strokeWidth-2;return[m,f,N]}let F=uf(i);if(i==="crowfoot_many"||i==="crowfoot_one_or_many"){let[N,te]=se(v(m,f),v(D,T),_r(-F)),[S,Q]=se(v(m,f),v(D,T),_r(F));return[D,T,N,te,S,Q]}let[C,k]=se(v(D,T),v(m,f),-F*Math.PI/180),[L,j]=se(v(D,T),v(m,f),_r(F));if(i==="diamond"||i==="diamond_outline"){let N,te;if(n==="start"){let[S,Q]=e.points.length>1?e.points[1]:[0,0];[N,te]=se(v(m+M*2,f),v(m,f),Math.atan2(Q-f,S-m))}else{let[S,Q]=e.points.length>1?e.points[e.points.length-2]:[0,0];[N,te]=se(v(m-M*2,f),v(m,f),Math.atan2(f-Q,m-S))}return[m,f,C,k,N,te,L,j]}return[m,f,C,k,L,j]},pf=e=>{let t=an.generator(),n=ke(e),i=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[i](e.points,n)},mf=(e,t,n,i)=>{let o=W(e,i);if(e.points.length<2){let[u,p]=e.points[0],[m,f]=se(v(e.x+u,e.y+p),v(t,n),e.angle),E=[m,f,m,f];if(o){let h=Y.getMinMaxXYWithBoundText(e,i,[m,f,m,f],o);E=[h[0],h[1],h[2],h[3]]}return E}let s=be.get(e)?.[0]??pf(e),a=gt(s),c=si(a,([u,p])=>se(v(e.x+u,e.y+p),v(t,n),e.angle)),d=[c[0],c[1],c[2],c[3]];if(o){let u=Y.getMinMaxXYWithBoundText(e,i,d,o);d=[u[0],u[1],u[2],u[3]]}return d},he=(e,t,n=!1)=>Ur.getBounds(e,t,n),tt=(e,t)=>{if(!rf(e))return[0,0,0,0];let n=1/0,i=-1/0,o=1/0,r=-1/0,s=t||Vl(e);return e.forEach(a=>{let[l,c,d,u]=he(a,s);n=Math.min(n,l),o=Math.min(o,c),i=Math.max(i,d),r=Math.max(r,u)}),[n,o,i,r]},O0=(e,t)=>{let[n,i,o,r]=tt(e);return[n+t.x,i+t.y,o+t.x,r+t.y]},Nt=(e,t,n,i)=>{if(!(X(e)||Se(e)))return[e.x,e.y,e.x+t,e.y+n];let o=Yl(0,t,Yl(1,n,e.points,i),i),r;if(Se(e))r=Xr(o);else{let d=an.generator(),u=e.roundness?d.curve(o,ke(e)):d.linearPath(o,ke(e)),p=gt(u);r=si(p)}let[s,a,l,c]=r;return[s+e.x,a+e.y,l+e.x,c+e.y]},Lr=(e,t)=>{let n=an.generator(),i=e.roundness==null?n.linearPath(t,ke(e)):n.curve(t,ke(e)),o=gt(i),[r,s,a,l]=si(o);return[r+e.x,s+e.y,a+e.x,l+e.y]},R0=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,i=e[0],o=Vl(e);return e.forEach(r=>{let[s,a,l,c]=he(r,o),d=sf(v((s+l)/2,(a+c)/2),v(t.x,t.y));d<n&&(n=d,i=r)}),he(i,o)},Ct=e=>{let[t,n,i,o]=tt(e);return{minX:t,minY:n,maxX:i,maxY:o,width:i-t,height:o-n,midX:(t+i)/2,midY:(n+o)/2}},k0=({scrollX:e,scrollY:t,width:n,height:i,zoom:o})=>[-e,-t,-e+n/o.value,-t+i/o.value],ct=e=>v(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),Ve=(e,t,n)=>{let i={minX:e.x,minY:e.y,maxX:e.x+e.width,maxY:e.y+e.height,midX:e.x+e.width/2,midY:e.y+e.height/2},o=fe(e,t),[r,s]=se(v(i.minX,i.minY),o,e.angle),[a,l]=se(v(i.maxX,i.minY),o,e.angle),[c,d]=se(v(i.maxX,i.maxY),o,e.angle),[u,p]=se(v(i.minX,i.maxY),o,e.angle),m=[Math.min(r,a,c,u),Math.min(s,l,d,p),Math.max(r,a,c,u),Math.max(s,l,d,p)];if(n){let[f,E,h,g]=n;return[m[0]-g,m[1]-f,m[2]+E,m[3]+h]}return m},An=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],pn=(e,t)=>{if(e==null||t==null)return!1;let[n,i,o,r]=e,[s,a,l,c]=t;return n<l&&o>s&&i<c&&r>a},fe=(e,t,n=0,i=0)=>{let[o,r]=ct(he(e,t));return v(o+n,r+i)};var gf=.1,ql=e=>X(e)||Se(e)?e.points.length<2||e.points.length===2&&_(e)&&Ef(e.points[0],e.points[e.points.length-1],gf):e.width===0&&e.height===0,yl=(e,t,n,i,o)=>{let[r,s,a,l]=he(e,o),c=xo({clientX:i.offsetLeft,clientY:i.offsetTop},i),d=xo({clientX:i.offsetLeft+t,clientY:i.offsetTop+n},i);return c.x<=a&&c.y<=l&&d.x>=r&&d.y>=s},X0=(e,t,n,i,o,r)=>{let[s,a,l,c]=tt(e,o),d=xo({clientX:i.offsetLeft+(r?.left||0),clientY:i.offsetTop+(r?.top||0)},i),u=xo({clientX:i.offsetLeft+t-(r?.right||0),clientY:i.offsetTop+n-(r?.bottom||0)},i);return s>=d.x&&a>=d.y&&l<=u.x&&c<=u.y},Wr=(e,t,n)=>{let i=Math.abs(t),o=Math.abs(n);if(e==="line"||e==="arrow"||e==="freedraw"){let r=Math.round(Math.atan(o/i)/Bt)*Bt;r===0?n=0:r===Math.PI/2?t=0:n=i*Math.tan(r)*Math.sign(n)||n}else e!=="selection"&&(n=i*Math.sign(n));return{width:t,height:n}},il=(e,t,n,i,o)=>{let r=n-e,s=i-t,a=Math.atan2(s,r),l=Math.round(a/Bt)*Bt;if(o){let c=Math.floor(o/Bt)*Bt;ff(a,c,c+Bt)&&(hf(a,o)<Bt/6?l=o:Zl(a)>Zl(o)?l=c+Bt:l=c)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let c=Math.tan(l),d=-1,u=t-c*e,p=-1/c,m=-1,f=i-p*n,E=(d*f-m*u)/(c*m-p*d),h=(u*p-f*c)/(c*m-p*d);r=E-e,s=h-t}return{width:r,height:s}},W0=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 K0=(e,t,n,i)=>{let o=uo(e,n.getNonDeletedElementsMap(),i),r=Ct(e);return o.flatMap(s=>{let a=xf(s,r,t);return s.map(l=>{let c=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ue(l,n,{simultaneouslyUpdated:s}),c})})},xf=(e,t,{axis:n,position:i})=>{let o=Ct(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return i==="start"?{...a,[n]:t[r]-o[r]}:i==="end"?{...a,[n]:t[s]-o[s]}:{...a,[n]:(t[r]+t[s])/2-(o[r]+o[s])/2}};P();import{arrayToMap as mh,arrayToObject as Gt,assertNever as Ac,isDevEnv as En,isShallowEqual as Dc,isTestEnv as gn,randomInteger as Tc}from"@excalidraw/common";P();import{assertNever as vf,COLOR_PALETTE as Lf,isDevEnv as Cf,isTestEnv as Bf,randomId as Gf,Emitter as Jl,toIterable as On}from"@excalidraw/common";P();import{ORIG_ID as Pf,randomId as Ql,randomInteger as If,arrayToMap as Sf,castArray as jr,findLastIndex as li,getUpdatedTimestamp as Mf,isTestEnv as Tf}from"@excalidraw/common";P();import{arrayToMapWithIndex as wf}from"@excalidraw/common";var yf=e=>{let t=e.slice(),n=new Set,i=r=>{let s=r[0]?.groupIds?.join(""),a=[r[0]],l=[];for(let c of r.slice(1))c.groupIds?.join("")===s?a.push(c):l.push(c);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(c=>{let d=c?.groupIds?.some(u=>u===a);return d&&o.set(c.id,!0),d});for(let c of i(l))n.add(c)}else n.add(r)}),n.size!==e.length?(console.error("normalizeGroupElementOrder: lost some elements... bailing!"),e):[...n]},bf=e=>{let t=wf(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]},Kl=e=>bf(yf(e));var Af=(e,t,n,i)=>{let o=$r(n);return Tf()&&Df(o,n.id),o.id=Ql(),o.updated=Mf(),i&&(o.seed=If(),Ra(o)),o.groupIds=xl(o.groupIds,e,r=>(t.has(r)||t.set(r,Ql()),t.get(r))),o},u1=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,c=new Map,d=Sf(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(h=>[h.id,h]));if(e.type==="in-place")for(let h of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(h)).forEach(g=>u.set(g.id,g));t=Kl(t);let p=t.slice(),m=h=>{let x=jr(h).reduce((y,b)=>{if(i.has(b.id))return y;i.set(b.id,!0);let w=Af(n.editingGroupId,o,b,e.randomizeSeed);return i.set(w.id,!0),c.set(w.id,w),a.set(b.id,w.id),l.set(w.id,b),s.push(b),r.push(w),y.push(w),y},[]);return Array.isArray(h)?x:x[0]||null},f=(h,g)=>{if(g){if(h>p.length-1){p.push(...jr(g));return}p.splice(h+1,0,...jr(g))}},E=new Set(t.filter(h=>u.has(h.id)&&$(h)).map(h=>h.id));for(let h of t){if(i.has(h.id)||!u.has(h.id))continue;let g=Gr(n,h);if(g){let x=Ae(t,g).flatMap(b=>$(b)?[...qt(t,b.id),b]:[b]),y=li(p,b=>b.groupIds?.includes(g));f(y,m(x));continue}if(!(h.frameId&&E.has(h.frameId))){if($(h)){let x=h.id,y=qt(t,x),b=li(p,w=>w.frameId===x||w.id===x);f(b,m([...y,h]));continue}if(st(h)){let x=W(h,d),y=li(p,b=>b.id===h.id||"containerId"in b&&b.containerId===h.id);x?f(y,m([h,x])):f(y,m(h));continue}if(de(h)){let x=Ce(h,d),y=li(p,b=>b.id===h.id||b.id===x?.id);x?f(y,m([x,h])):f(y,m(h));continue}f(li(p,x=>x.id===h.id),m(h))}}if($a(r,a,c),bl(p,s,a),e.overrides)for(let h of r){let g=l.get(h.id);g&&Object.assign(h,e.overrides({duplicateElement:h,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:c,elementsWithDuplicates:p,origIdToDuplicateId:a}},Vr=(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]=Vr(e[o],t+1)}return i}if(Array.isArray(e)){let i=e.length,o=new Array(i);for(;i--;)o[i]=Vr(e[i],t+1);return o}return A.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},$r=e=>Vr(e),Df=(e,t)=>{Object.defineProperty(e,Pf,{value:t,writable:!1,enumerable:!1})};var Fe={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},ec=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Jl;onStoreIncrementEmitter=new Jl;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Jt.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Fe.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,i;if("change"in t)i=t.change;else{let r=Jt.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?ic(t.elements):void 0,t.appState);i=ci.create(r,s)}let o="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:i,delta:o}))}commit(t,n){this.flushMicroActions();try{let i=this.getScheduledMacroAction();this.processAction({action:i,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=Jt.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,i=void 0){let o=this.snapshot,r,s;if(n?r=n:r=ci.create(o,t),i?s=i:s=Kr.calculate(o,t),!s.isEmpty()){let a=new Zr(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let i;if(n)i=n;else{let r=this.snapshot;i=ci.create(r,t)}let o=new qr(i);this.onStoreIncrementEmitter.trigger(o)}applyChangeToSnapshot(t){let n=this.snapshot,i=this.snapshot.applyChange(t);return n===i?null:i}maybeCloneSnapshot(t,n,i){if(!n&&!i)return null;let o=this.snapshot,r=this.snapshot.maybeClone(t,n,i);return o===r?null:r}flushMicroActions(){for(let t of this.scheduledMicroActions)try{t()}catch(n){console.error("Failed to execute scheduled micro action",n)}this.scheduledMicroActions=[]}processAction(t){let{action:n}=t;if(n===Fe.EVENTUALLY&&!this.onStoreIncrementEmitter.subscribers.length)return;let i;if("change"in t?i=this.applyChangeToSnapshot(t.change):i=this.maybeCloneSnapshot(n,t.elements,t.appState),!i)return;let o="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case Fe.IMMEDIATELY:this.emitDurableIncrement(i,o,r);break;case Fe.NEVER:case Fe.EVENTUALLY:this.emitEphemeralIncrement(i,o);break;default:vf(n,"Unknown store action")}}finally{switch(n){case Fe.IMMEDIATELY:case Fe.NEVER:this.snapshot=i;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Fe.IMMEDIATELY)?t=Fe.IMMEDIATELY:this.scheduledMacroActions.has(Fe.NEVER)?t=Fe.NEVER:t=Fe.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Fe).length)){let t=`There can be at most three store actions scheduled at the same time, but there are "${this.scheduledMacroActions.size}".`;if(console.error(t,this.scheduledMacroActions.values()),Bf()||Cf())throw new Error(t)}}},ci=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let i=n.getChangedElements(t),o=n.getChangedAppState(t);return new e(i,o)}},wo=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Zr=class extends wo{constructor(n,i){super("durable",n);this.change=n;this.delta=i}},qr=class extends wo{constructor(n){super("ephemeral",n);this.change=n}},Kr=class{constructor(t,n,i){this.id=t;this.elements=n;this.appState=i}static create(t,n,i={id:Gf()}){return new this(i.id,t,n)}static calculate(t,n){let i=n.metadata.didElementsChange?hn.calculate(t.elements,n.elements):hn.empty(),o=n.metadata.didAppStateChange?fn.calculate(t.appState,n.appState):fn.empty();return this.create(i,o)}static restore(t){let{id:n,elements:i,appState:o}=t;return new this(n,hn.restore(i),fn.restore(o))}static load({id:t,elements:{added:n,removed:i,updated:o},appState:{delta:r}}){let s=hn.create(n,i,o),a=fn.create(r);return new this(t,s,a)}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,Jt.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})}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Jt=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,tc(n)?n:Rn(n),i)}static empty(){return new e(new Map,Of(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let i of On(t.elements))this.elements.get(i.id)||(n[i.id]=Me(i,{isDeleted:!0}));for(let i of On(this.elements))t.elements.get(i.id)!==i&&(n[i.id]=i);return n}getChangedAppState(t){return q.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=Rn({...this.appState,...t.appState});return e.create(n,i,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,i){let o={shouldCompareHashes:!1};t===Fe.EVENTUALLY&&(o.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,o),s=this.maybeCreateAppStateSnapshot(i,o),a=!1,l=!1;return this.elements!==r&&(a=!0),this.appState!==s&&(l=!0),!a&&!l?this:new e(r,s,{didElementsChange:a,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let i=tc(t)?t:Rn(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=q.isRightDifferent(this.appState,t);if(!i)return;let o=rc(JSON.stringify(t));if(!(n.shouldCompareHashes&&this._lastChangedAppStateHash===o))return this._lastChangedAppStateHash=o,i}detectChangedElements(t,n={shouldCompareHashes:!1}){if(this.elements===t)return;let i=new Map;for(let r of On(this.elements))t.get(r.id)||i.set(r.id,Me(r,{isDeleted:!0}));for(let r of On(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(xe(r)&&!zt(r))continue;i.set(r.id,r)}}if(!i.size)return;let o=oc(i);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===o))return this._lastChangedElementsHash=o,i}createElementsSnapshot(t){let n=new Map;for(let i of On(this.elements))n.set(i.id,i);for(let i of On(t))n.set(i.id,$r(i));return n}},nc="__observedAppState",Of=()=>({name:null,editingGroupId:null,viewBackgroundColor:Lf.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),Rn=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,nc,{value:!0,enumerable:!1}),t},tc=e=>!!Reflect.get(e,nc);P();P();var lc="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Fn(e,t,n){let i=n[0];if(t!=null&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)===i||t&&t.slice(-1)===i)throw new Error("trailing zero");if(t){let s=0;for(;(e[s]||i)===t[s];)s++;if(s>0)return t.slice(0,s)+Fn(e.slice(s),t.slice(s),n)}let o=e?n.indexOf(e[0]):0,r=t!=null?n.indexOf(t[0]):n.length;if(r-o>1){let s=Math.round(.5*(o+r));return n[s]}else return t&&t.length>1?t.slice(0,1):n[o]+Fn(e.slice(1),null,n)}function cc(e){if(e.length!==dc(e[0]))throw new Error("invalid integer part of order key: "+e)}function dc(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 di(e){let t=dc(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function sc(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=di(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function ac(e,t){cc(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 Rf(e,t){cc(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 kn(e,t,n=lc){if(e!=null&&sc(e,n),t!=null&&sc(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=di(t),c=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Fn("",c,n);if(l<t)return l;let d=Rf(l,n);if(d==null)throw new Error("cannot decrement any more");return d}if(t==null){let l=di(e),c=e.slice(l.length),d=ac(l,n);return d??l+Fn(c,null,n)}let i=di(e),o=e.slice(i.length),r=di(t),s=t.slice(r.length);if(i===r)return i+Fn(o,s,n);let a=ac(i,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:i+Fn(o,null,n)}function yo(e,t,n,i=lc){if(n===0)return[];if(n===1)return[kn(e,t,i)];if(t==null){let s=kn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=kn(s,t,i),a.push(s);return a}if(e==null){let s=kn(e,t,i),a=[s];for(let l=0;l<n-1;l++)s=kn(e,s,i),a.push(s);return a.reverse(),a}let o=Math.floor(n/2),r=kn(e,t,i);return[...yo(e,r,o,i),r,...yo(r,t,n-o-1,i)]}import{arrayToMap as bo}from"@excalidraw/common";var Qr=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},kf=(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,c]of a.entries()){let d=a[l-1],u=a[l+1];if(Jr(c,d,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&st(e[l])){let p=e[l],m=W(p,bo(e));m&&m.index<=p.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(m)}", "${s(p)}"`)}}if(r.length){let l=new Qr,c=[];if(o&&(c.push("Additional reconciliation context:"),c.push(o.localElements.map(d=>s(d))),c.push(o.remoteElements.map(d=>s(d)))),i||console.error(r.join(`
18
+ C ${s} ${a}, ${s} ${a}, ${s+f} ${a+E}`,Fe(e,!0))}else r=t.polygon([[s,a],[l,d],[c,u],[p,m]],Fe(e));return r}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Fe(e));case"line":case"arrow":{let r,s=Fe(e),a=e.points.length?e.points:[de(0,0)];if(B(e)?a.every(l=>Math.abs(l[0])<=1e6&&Math.abs(l[1])<=1e6)?r=[t.path(Xl(a,16),Fe(e,!0))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(a)),r=[]):e.roundness?r=[t.curve(a,s)]:s.fill?r=[t.polygon(a,s)]:r=[t.linearPath(a,s)],e.type==="arrow"){let{startArrowhead:l=null,endArrowhead:d="arrow"}=e;if(l!==null){let c=Yl(e,r,"start",l,t,s,o);r.push(...c)}if(d!==null){let c=Yl(e,r,"end",d,t,s,o);r.push(...c)}}return r}case"freedraw":{let r;if(Nl(e),mn(e.points)){let s=Wn(e.points,.75);r=t.curve(s,{...Fe(e),stroke:"none"})}else r=null;return r}case"frame":case"magicframe":case"text":case"image":return null;default:return sf(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},Xl=(e,t)=>{let n=[];for(let i=1;i<e.length-1;i+=1){let r=e[i-1],s=e[i+1],a=e[i],l=tt(a,r),d=tt(s,a),c=Math.min(t,zl(e[i],s)/2,zl(e[i],r)/2);l?r[0]<a[0]?n.push([e[i][0]-c,e[i][1]]):n.push([e[i][0]+c,e[i][1]]):r[1]<a[1]?n.push([e[i][0],e[i][1]-c]):n.push([e[i][0],e[i][1]+c]),n.push(e[i]),d?s[0]<a[0]?n.push([e[i][0]-c,e[i][1]]):n.push([e[i][0]+c,e[i][1]]):s[1]<a[1]?n.push([e[i][0],e[i][1]-c]):n.push([e[i][0],e[i][1]+c])}let o=[`M ${e[0][0]} ${e[0][1]}`];for(let i=0;i<n.length;i+=3)o.push(`L ${n[i][0]} ${n[i][1]}`),o.push(`Q ${n[i+1][0]} ${n[i+1][1]}, ${n[i+2][0]} ${n[i+2][1]}`);return o.push(`L ${e[e.length-1][0]} ${e[e.length-1][1]}`),o.join(" ")},jl=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return Hs(e);case"arrow":case"line":{let n=Pe.get(e)?.[0]??Pe.generateElementShape(e,null)[0],[,,,,o,i]=Y(e,t);return Wo(e)?Us(e,n,de(e.x,e.y),e.angle,de(o,i)):_s(n,de(e.x,e.y),e.angle,de(o,i))}case"ellipse":return zs(e);case"freedraw":{let[,,,,n,o]=Y(e,t);return Ys(e,de(n,o),Wo(e))}}},rl=(e,t)=>{let n=[...e.points];if(t){if(!ua(e.points))return null;let i=n[0],r=n[n.length-1];Math.hypot(i[0]-r[0],i[1]-r[1])>lf||n.length<4?n.push(de(i[0],i[1])):n[n.length-1]=de(i[0],i[1])}return{polygon:t,points:n}};var Wr=class e{static boundsCache=new WeakMap;static nonRotatedBoundsCache=new WeakMap;static getBounds(t,n,o=!1){let i=o&&t.angle!==0?e.nonRotatedBoundsCache.get(t):e.boundsCache.get(t);if(i?.version&&i.version===t.version&&!ce(t))return i.bounds;if(o&&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 o,[i,r,s,a,l,d]=Y(t,n);if(Me(t)){let[c,u,p,m]=Vr(t.points.map(([f,E])=>se(v(f,E),v(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,p+t.x,m+t.y]}else if(j(t))o=yf(t,l,d,n);else if(t.type==="diamond"){let[c,u]=se(v(l,r),v(l,d),t.angle),[p,m]=se(v(l,a),v(l,d),t.angle),[f,E]=se(v(i,d),v(l,d),t.angle),[h,g]=se(v(s,d),v(l,d),t.angle),x=Math.min(c,p,f,h),y=Math.min(u,m,E,g),b=Math.max(c,p,f,h),w=Math.max(u,m,E,g);o=[x,y,b,w]}else if(t.type==="ellipse"){let c=(s-i)/2,u=(a-r)/2,p=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(c*p,u*m),E=Math.hypot(u*p,c*m);o=[l-f,d-E,l+f,d+E]}else{let[c,u]=se(v(i,r),v(l,d),t.angle),[p,m]=se(v(i,a),v(l,d),t.angle),[f,E]=se(v(s,a),v(l,d),t.angle),[h,g]=se(v(s,r),v(l,d),t.angle),x=Math.min(c,p,f,h),y=Math.min(u,m,E,g),b=Math.max(c,p,f,h),w=Math.max(u,m,E,g);o=[x,y,b,w]}return o}},Y=(e,t,n=!1)=>{if(Me(e))return Ef(e);if(j(e))return U.getElementAbsoluteCoords(e,t,n);if(oe(e)){let o=t?Ce(e,t):null;if(_(o)){let{x:i,y:r}=U.getBoundTextElementPosition(o,e,t);return[i,r,i+e.width,r+e.height,i+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]},Nr=(e,t)=>{let n=jl(e,t),[o,i,r,s,a,l]=Y(e,t),d=v(a,l);if(n.type==="polycurve"){let g=n.data.map(y=>Et(y,10)),x=[];if(bt(e)&&!e.polygon||_(e))for(let y of g){let b=0;for(;b<y.length-1;)x.push(Ee(v(y[b][0],y[b][1]),v(y[b+1][0],y[b+1][1]))),b++}else{let y=g.flat(),b=0;for(;b<y.length-1;)x.push(Ee(v(y[b][0],y[b][1]),v(y[b+1][0],y[b+1][1]))),b++}return x}else{if(n.type==="polyline")return n.data;if(ff(e)){let[h,g]=Mn(e),x=g.map(b=>$l(b,d,e.angle)).flat();return[...Vl(h,d,e.angle),...x]}else if(e.type==="diamond"){let[h,g]=Tn(e),x=g.map(b=>$l(b,d,e.angle)).flat();return[...Vl(h,d,e.angle),...x]}else if(n.type==="polygon"){if(oe(e)){let x=Ce(e,t);if(x&&j(x))return[Ee(v(o,i),v(r,i)),Ee(v(r,i),v(r,s)),Ee(v(r,s),v(o,s)),Ee(v(o,s),v(o,i))]}let h=n.data,g=[];for(let x=0;x<h.length-1;x++)g.push(Ee(h[x],h[x+1]));return g}else if(n.type==="ellipse")return hf(e)}let[c,u,p,m,,,f,E]=[[o,i],[r,i],[o,s],[r,s],[a,i],[a,s],[o,l],[r,l]].map(h=>se(h,d,e.angle));return[Ee(c,u),Ee(p,m),Ee(c,p),Ee(u,m),Ee(c,E),Ee(p,E),Ee(u,f),Ee(m,f)]},ff=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),Vl=(e,t,n)=>e.map(o=>Ee(se(o[0],t,n),se(o[1],t,n))),$l=(e,t,n)=>{let o=Et(e,10),i=0,r=[];for(;i<o.length-1;)r.push(Ee(se(v(o[i][0],o[i][1]),t,n),se(v(o[i+1][0],o[i+1][1]),t,n))),i++;return r},hf=e=>{let t=v(e.x+e.width/2,e.y+e.height/2),n=e.width/2,o=e.height/2,i=[],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]+o*Math.sin(d);r.push(se(v(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)i.push(Ee(r[l],r[l+1]));return i.push(Ee(r[r.length-1],r[0])),i},Y0=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],ko=e=>{let t=Math.floor(e.width/2)+1,n=0,o=e.width,i=Math.floor(e.height/2)+1,r=t,s=e.height;return[t,n,o,i,r,s,0,i]},Zl=(e,t,n,o,i)=>{let r=1-e;return Math.pow(r,3)*t+3*Math.pow(r,2)*e*n+3*r*Math.pow(e,2)*o+Math.pow(e,3)*i},ql=(e,t,n,o)=>{let i=t-e,r=n-t,s=o-n,a=3*i-6*r+3*s,l=6*r-6*i,d=3*i,c=l*l-4*a*d;if(!(c>=0))return!1;let p=null,m=null,f=1/0,E=1/0;return a===0?f=E=-d/l:(f=(-l+Math.sqrt(c))/(2*a),E=(-l-Math.sqrt(c))/(2*a)),f>=0&&f<=1&&(p=Zl(f,e,t,n,o)),E>=0&&E<=1&&(m=Zl(E,e,t,n,o)),[p,m]},Vo=(e,t,n,o)=>{let i=ql(e[0],t[0],n[0],o[0]),r=ql(e[1],t[1],n[1],o[1]),s=Math.min(e[0],o[0]),a=Math.max(e[0],o[0]);if(i){let c=i.filter(u=>u!==null);s=Math.min(s,...c),a=Math.max(a,...c)}let l=Math.min(e[1],o[1]),d=Math.max(e[1],o[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]},ao=(e,t)=>{let n=v(0,0),{minX:o,minY:i,maxX:r,maxY:s}=e.reduce((a,{op:l,data:d})=>{if(l==="move"){let c=Ql(d);jr(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=v(d[0],d[1]),u=v(d[2],d[3]),p=v(d[4],d[5]),m=t?t(c):c,f=t?t(u):u,E=t?t(p):p,h=t?t(n):n;n=p;let[g,x,y,b]=Vo(h,m,f,E);a.minX=Math.min(a.minX,g),a.minY=Math.min(a.minY,x),a.maxX=Math.max(a.maxX,y),a.maxY=Math.max(a.maxY,b)}return a},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[o,i,r,s]},Vr=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;for(let[r,s]of e)t=Math.min(t,r),n=Math.min(n,s),o=Math.max(o,r),i=Math.max(i,s);return[t,n,o,i]},Ef=e=>{let[t,n,o,i]=Vr(e.points),r=t+e.x,s=n+e.y,a=o+e.x,l=i+e.y;return[r,s,a,l,(r+a)/2,(s+l)/2]},gf=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}},xf=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},Ur=(e,t,n,o)=>{if(t.length<1)return null;let i=gt(t[0]);if(i.length<1)return null;let r=n==="start"?1:i.length-1,s=i[r].data;jr(s.length===6,"Op data length is not 6");let a=v(s[4],s[5]),l=v(s[2],s[3]),d=v(s[0],s[1]),c=i[r-1],u=v(0,0);if(c.op==="move"){let H=Ql(c.data);jr(H!=null,"Op data is not a point"),u=H}else c.op==="bcurveTo"&&(u=v(c.data[4],c.data[5]));let p=(H,te)=>Math.pow(1-H,3)*a[te]+3*H*Math.pow(1-H,2)*l[te]+3*Math.pow(H,2)*(1-H)*d[te]+u[te]*Math.pow(H,3),[m,f]=n==="start"?u:a,[E,h]=[p(.3,0),p(.3,1)],g=Math.hypot(m-E,f-h),x=(m-E)/g,y=(f-h)/g,b=gf(o),w=0;{let[H,te]=n==="end"?e.points[e.points.length-1]:e.points[0],[S,Q]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];w=Math.hypot(H-S,te-Q)}let M=Math.min(b,w*(o==="diamond"||o==="diamond_outline"?.25:.5)),D=m-x*M,T=f-y*M;if(o==="dot"||o==="circle"||o==="circle_outline"){let H=Math.hypot(T-f,D-m)+e.strokeWidth-2;return[m,f,H]}let N=xf(o);if(o==="crowfoot_many"||o==="crowfoot_one_or_many"){let[H,te]=se(v(m,f),v(D,T),Xr(-N)),[S,Q]=se(v(m,f),v(D,T),Xr(N));return[D,T,H,te,S,Q]}let[C,R]=se(v(D,T),v(m,f),-N*Math.PI/180),[L,$]=se(v(D,T),v(m,f),Xr(N));if(o==="diamond"||o==="diamond_outline"){let H,te;if(n==="start"){let[S,Q]=e.points.length>1?e.points[1]:[0,0];[H,te]=se(v(m+M*2,f),v(m,f),Math.atan2(Q-f,S-m))}else{let[S,Q]=e.points.length>1?e.points[e.points.length-2]:[0,0];[H,te]=se(v(m-M*2,f),v(m,f),Math.atan2(f-Q,m-S))}return[m,f,C,R,H,te,L,$]}return[m,f,C,R,L,$]},wf=e=>{let t=pn.generator(),n=Fe(e),o=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[o](e.points,n)},yf=(e,t,n,o)=>{let i=W(e,o);if(e.points.length<2){let[u,p]=e.points[0],[m,f]=se(v(e.x+u,e.y+p),v(t,n),e.angle),E=[m,f,m,f];if(i){let h=U.getMinMaxXYWithBoundText(e,o,[m,f,m,f],i);E=[h[0],h[1],h[2],h[3]]}return E}let s=Pe.get(e)?.[0]??wf(e),a=gt(s),d=ao(a,([u,p])=>se(v(e.x+u,e.y+p),v(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(i){let u=U.getMinMaxXYWithBoundText(e,o,c,i);c=[u[0],u[1],u[2],u[3]]}return c},pe=(e,t,n=!1)=>Wr.getBounds(e,t,n),Xe=(e,t)=>{if(!pf(e))return[0,0,0,0];let n=1/0,o=-1/0,i=1/0,r=-1/0,s=t||Kl(e);return e.forEach(a=>{let[l,d,c,u]=pe(a,s);n=Math.min(n,l),i=Math.min(i,d),o=Math.max(o,c),r=Math.max(r,u)}),[n,i,o,r]},U0=(e,t)=>{let[n,o,i,r]=Xe(e);return[n+t.x,o+t.y,i+t.x,r+t.y]},zt=(e,t,n,o)=>{if(!(j(e)||Me(e)))return[e.x,e.y,e.x+t,e.y+n];let i=Wl(0,t,Wl(1,n,e.points,o),o),r;if(Me(e))r=Vr(i);else{let c=pn.generator(),u=e.roundness?c.curve(i,Fe(e)):c.linearPath(i,Fe(e)),p=gt(u);r=ao(p)}let[s,a,l,d]=r;return[s+e.x,a+e.y,l+e.x,d+e.y]},Gr=(e,t)=>{let n=pn.generator(),o=e.roundness==null?n.linearPath(t,Fe(e)):n.curve(t,Fe(e)),i=gt(o),[r,s,a,l]=ao(i);return[r+e.x,s+e.y,a+e.x,l+e.y]},X0=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,o=e[0],i=Kl(e);return e.forEach(r=>{let[s,a,l,d]=pe(r,i),c=mf(v((s+l)/2,(a+d)/2),v(t.x,t.y));c<n&&(n=c,o=r)}),pe(o,i)},Bt=e=>{let[t,n,o,i]=Xe(e);return{minX:t,minY:n,maxX:o,maxY:i,width:o-t,height:i-n,midX:(t+o)/2,midY:(n+i)/2}},j0=({scrollX:e,scrollY:t,width:n,height:o,zoom:i})=>[-e,-t,-e+n/i.value,-t+o/i.value],dt=e=>v(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),$e=(e,t,n)=>{let o={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},i=he(e,t),[r,s]=se(v(o.minX,o.minY),i,e.angle),[a,l]=se(v(o.maxX,o.minY),i,e.angle),[d,c]=se(v(o.maxX,o.maxY),i,e.angle),[u,p]=se(v(o.minX,o.maxY),i,e.angle),m=[Math.min(r,a,d,u),Math.min(s,l,c,p),Math.max(r,a,d,u),Math.max(s,l,c,p)];if(n){let[f,E,h,g]=n;return[m[0]-g,m[1]-f,m[2]+E,m[3]+h]}return m},vn=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],gn=(e,t)=>{if(e==null||t==null)return!1;let[n,o,i,r]=e,[s,a,l,d]=t;return n<l&&i>s&&o<d&&r>a},he=(e,t,n=0,o=0)=>{let[i,r]=dt(pe(e,t));return v(i+n,r+o)};var Sf=.1,ed=e=>j(e)||Me(e)?e.points.length<2||e.points.length===2&&_(e)&&If(e.points[0],e.points[e.points.length-1],Sf):e.width===0&&e.height===0,Il=(e,t,n,o,i)=>{let[r,s,a,l]=pe(e,i),d=yi({clientX:o.offsetLeft,clientY:o.offsetTop},o),c=yi({clientX:o.offsetLeft+t,clientY:o.offsetTop+n},o);return d.x<=a&&d.y<=l&&c.x>=r&&c.y>=s},J0=(e,t,n,o,i,r)=>{let[s,a,l,d]=Xe(e,i),c=yi({clientX:o.offsetLeft+(r?.left||0),clientY:o.offsetTop+(r?.top||0)},o),u=yi({clientX:o.offsetLeft+t-(r?.right||0),clientY:o.offsetTop+n-(r?.bottom||0)},o);return s>=c.x&&a>=c.y&&l<=u.x&&d<=u.y},$r=(e,t,n)=>{let o=Math.abs(t),i=Math.abs(n);if(e==="line"||e==="arrow"||e==="freedraw"){let r=Math.round(Math.atan(i/o)/kt)*kt;r===0?n=0:r===Math.PI/2?t=0:n=o*Math.tan(r)*Math.sign(n)||n}else e!=="selection"&&(n=o*Math.sign(n));return{width:t,height:n}},sl=(e,t,n,o,i)=>{let r=n-e,s=o-t,a=Math.atan2(s,r),l=Math.round(a/kt)*kt;if(i){let d=Math.floor(i/kt)*kt;bf(a,d,d+kt)&&(Pf(a,i)<kt/6?l=i:Jl(a)>Jl(i)?l=d+kt:l=d)}if(l===0)s=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,p=-1/d,m=-1,f=o-p*n,E=(c*f-m*u)/(d*m-p*c),h=(u*p-f*d)/(d*m-p*c);r=E-e,s=h-t}return{width:r,height:s}},e1=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 s1=(e,t,n,o)=>{let i=pi(e,n.getNonDeletedElementsMap(),o),r=Bt(e);return i.flatMap(s=>{let a=Mf(s,r,t);return s.map(l=>{let d=n.mutateElement(l,{x:l.x+a.x,y:l.y+a.y});return Ue(l,n,{simultaneouslyUpdated:s}),d})})},Mf=(e,t,{axis:n,position:o})=>{let i=Bt(e),[r,s]=n==="x"?["minX","maxX"]:["minY","maxY"],a={x:0,y:0};return o==="start"?{...a,[n]:t[r]-i[r]}:o==="end"?{...a,[n]:t[s]-i[s]}:{...a,[n]:(t[r]+t[s])/2-(i[r]+i[s])/2}};P();import{arrayToMap as yh,arrayToObject as Ot,assertNever as Cd,isDevEnv as on,isShallowEqual as Gd,isTestEnv as rn,randomInteger as Ld}from"@excalidraw/common";P();import{assertNever as Rf,COLOR_PALETTE as Ff,isDevEnv as Nf,isTestEnv as Hf,randomId as zf,Emitter as od,toIterable as On}from"@excalidraw/common";P();import{ORIG_ID as vf,randomId as nd,randomInteger as Lf,arrayToMap as Cf,castArray as Zr,findLastIndex as co,getUpdatedTimestamp as Gf,isTestEnv as Bf}from"@excalidraw/common";P();import{arrayToMapWithIndex as Tf}from"@excalidraw/common";var Af=e=>{let t=e.slice(),n=new Set,o=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,...o(l)]:a},i=new Map;return t.forEach((r,s)=>{if(!i.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&&i.set(d.id,!0),c});for(let d of o(l))n.add(d)}else n.add(r)}),n.size!==e.length?(console.error("normalizeGroupElementOrder: lost some elements... bailing!"),e):[...n]},Df=e=>{let t=Tf(e),n=e.slice(),o=new Set;return n.forEach((i,r)=>{i&&(i.boundElements?.length?(o.add(i),n[r]=null,i.boundElements.forEach(s=>{let a=t.get(s.id);a&&s.type==="text"&&(o.add(a[0]),n[a[1]]=null)})):i.type==="text"&&i.containerId&&t.get(i.containerId)?.[0].boundElements?.find(a=>a.id===i.id)||(o.add(i),n[r]=null))}),o.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...o]},td=e=>Df(Af(e));var kf=(e,t,n,o)=>{let i=Kr(n);return Bf()&&Of(i,n.id),i.id=nd(),i.updated=Gf(),o&&(i.seed=Lf(),Na(i)),i.groupIds=bl(i.groupIds,e,r=>(t.has(r)||t.set(r,nd()),t.get(r))),i},y1=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},o=new Map,i=new Map,r=[],s=[],a=new Map,l=new Map,d=new Map,c=Cf(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(h=>[h.id,h]));if(e.type==="in-place")for(let h of Object.keys(e.appState.selectedGroupIds))t.filter(g=>g.groupIds?.includes(h)).forEach(g=>u.set(g.id,g));t=td(t);let p=t.slice(),m=h=>{let x=Zr(h).reduce((y,b)=>{if(o.has(b.id))return y;o.set(b.id,!0);let w=kf(n.editingGroupId,i,b,e.randomizeSeed);return o.set(w.id,!0),d.set(w.id,w),a.set(b.id,w.id),l.set(w.id,b),s.push(b),r.push(w),y.push(w),y},[]);return Array.isArray(h)?x:x[0]||null},f=(h,g)=>{if(g){if(h>p.length-1){p.push(...Zr(g));return}p.splice(h+1,0,...Zr(g))}},E=new Set(t.filter(h=>u.has(h.id)&&q(h)).map(h=>h.id));for(let h of t){if(o.has(h.id)||!u.has(h.id))continue;let g=Or(n,h);if(g){let x=Ae(t,g).flatMap(b=>q(b)?[...Kt(t,b.id),b]:[b]),y=co(p,b=>b.groupIds?.includes(g));f(y,m(x));continue}if(!(h.frameId&&E.has(h.frameId))){if(q(h)){let x=h.id,y=Kt(t,x),b=co(p,w=>w.frameId===x||w.id===x);f(b,m([...y,h]));continue}if(st(h)){let x=W(h,c),y=co(p,b=>b.id===h.id||"containerId"in b&&b.containerId===h.id);x?f(y,m([h,x])):f(y,m(h));continue}if(ce(h)){let x=Ce(h,c),y=co(p,b=>b.id===h.id||b.id===x?.id);x?f(y,m([x,h])):f(y,m(h));continue}f(co(p,x=>x.id===h.id),m(h))}}if(Ka(r,a,d),Sl(p,s,a),e.overrides)for(let h of r){let g=l.get(h.id);g&&Object.assign(h,e.overrides({duplicateElement:h,origElement:g,origIdToDuplicateId:a}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:p,origIdToDuplicateId:a}},qr=(e,t=0)=>{if(e==null||typeof e!="object")return e;let n=Object.prototype.toString.call(e);if(n==="[object Object]"){let o=typeof e.constructor=="function"?Object.create(Object.getPrototypeOf(e)):{};for(let i in e)if(e.hasOwnProperty(i)){if(t===0&&(i==="shape"||i==="canvas"))continue;o[i]=qr(e[i],t+1)}return o}if(Array.isArray(e)){let o=e.length,i=new Array(o);for(;o--;)i[o]=qr(e[o],t+1);return i}return A.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},Kr=e=>qr(e),Of=(e,t)=>{Object.defineProperty(e,vf,{value:t,writable:!1,enumerable:!1})};var Ne={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},id=class{constructor(t){this.app=t}onDurableIncrementEmitter=new od;onStoreIncrementEmitter=new od;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=nn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Ne.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,o;if("change"in t)o=t.change;else{let r=nn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),s=r.maybeClone(n,t.elements?ad(t.elements):void 0,t.appState);o=uo.create(r,s)}let i="delta"in t?t.delta:void 0;this.scheduledMicroActions.push(()=>this.processAction({action:n,change:o,delta:i}))}commit(t,n){this.flushMicroActions();try{let o=this.getScheduledMacroAction();this.processAction({action:o,elements:t,appState:n})}finally{this.satisfiesScheduledActionsInvariant(),this.scheduledMacroActions=new Set}}clear(){this.snapshot=nn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,o=void 0){let i=this.snapshot,r,s;if(n?r=n:r=uo.create(i,t),o?s=o:s=es.calculate(i,t),!s.isEmpty()){let a=new Qr(r,s);this.onDurableIncrementEmitter.trigger(a),this.onStoreIncrementEmitter.trigger(a)}}emitEphemeralIncrement(t,n=void 0){let o;if(n)o=n;else{let r=this.snapshot;o=uo.create(r,t)}let i=new Jr(o);this.onStoreIncrementEmitter.trigger(i)}applyChangeToSnapshot(t){let n=this.snapshot,o=this.snapshot.applyChange(t);return n===o?null:o}maybeCloneSnapshot(t,n,o){if(!n&&!o)return null;let i=this.snapshot,r=this.snapshot.maybeClone(t,n,o);return i===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===Ne.EVENTUALLY&&!this.onStoreIncrementEmitter.subscribers.length)return;let o;if("change"in t?o=this.applyChangeToSnapshot(t.change):o=this.maybeCloneSnapshot(n,t.elements,t.appState),!o)return;let i="change"in t?t.change:void 0,r="delta"in t?t.delta:void 0;try{switch(n){case Ne.IMMEDIATELY:this.emitDurableIncrement(o,i,r);break;case Ne.NEVER:case Ne.EVENTUALLY:this.emitEphemeralIncrement(o,i);break;default:Rf(n,"Unknown store action")}}finally{switch(n){case Ne.IMMEDIATELY:case Ne.NEVER:this.snapshot=o;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Ne.IMMEDIATELY)?t=Ne.IMMEDIATELY:this.scheduledMacroActions.has(Ne.NEVER)?t=Ne.NEVER:t=Ne.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Ne).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()),Hf()||Nf())throw new Error(t)}}},uo=class e{constructor(t,n){this.elements=t;this.appState=n}static create(t,n){let o=n.getChangedElements(t),i=n.getChangedAppState(t);return new e(o,i)}},bi=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},Qr=class extends bi{constructor(n,o){super("durable",n);this.change=n;this.delta=o}},Jr=class extends bi{constructor(n){super("ephemeral",n);this.change=n}},es=class e{constructor(t,n,o){this.id=t;this.elements=n;this.appState=o}static create(t,n,o={id:zf()}){return new this(o.id,t,n)}static calculate(t,n){let o=n.metadata.didElementsChange?tn.calculate(t.elements,n.elements):tn.empty(),i=n.metadata.didAppStateChange?en.calculate(t.appState,n.appState):en.empty();return this.create(o,i)}static restore(t){let{id:n,elements:o,appState:i}=t;return new this(n,tn.restore(o),en.restore(i))}static load({id:t,elements:{added:n,removed:o,updated:i},appState:{delta:r}}){let s=tn.create(n,o,i),a=en.create(r);return new this(t,s,a)}static squash(...t){let n=e.empty();for(let o of t)n.elements.squash(o.elements),n.appState.squash(o.appState);return n}static inverse(t){return this.create(t.elements.inverse(),t.appState.inverse())}static applyTo(t,n,o,i){let[r,s]=t.elements.applyTo(n,nn.empty().elements,i),[a,l]=t.appState.applyTo(o,r);return[r,a,s||l]}static applyLatestChanges(t,n,o,i){return this.create(t.elements.applyLatestChanges(n,o,i),t.appState,{id:t.id})}static empty(){return e.create(tn.empty(),en.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},nn=class e{constructor(t,n,o={didElementsChange:!1,didAppStateChange:!1,isEmpty:!1}){this.elements=t;this.appState=n;this.metadata=o}_lastChangedElementsHash=0;_lastChangedAppStateHash=0;static create(t,n,o={didElementsChange:!1,didAppStateChange:!1}){return new e(t,rd(n)?n:Rn(n),o)}static empty(){return new e(new Map,_f(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let o of On(t.elements))this.elements.get(o.id)||(n[o.id]=ge(o,{isDeleted:!0}));for(let o of On(this.elements))t.elements.get(o.id)!==o&&(n[o.id]=o);return n}getChangedAppState(t){return F.getRightDifferences(t.appState,this.appState).reduce((n,o)=>Object.assign(n,{[o]:this.appState[o]}),{})}isEmpty(){return this.metadata.isEmpty}applyChange(t){let n=new Map(this.elements);for(let[i,r]of Object.entries(t.elements))n.set(i,r);let o=Rn({...this.appState,...t.appState});return e.create(n,o,{didElementsChange:Object.keys(t.elements).length>0,didAppStateChange:Object.keys(t.appState).length>0})}maybeClone(t,n,o){let i={shouldCompareHashes:!1};t===Ne.EVENTUALLY&&(i.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,i),s=this.maybeCreateAppStateSnapshot(o,i),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 o=rd(t)?t:Rn(t);return this.detectChangedAppState(o,n)?o:this.appState}maybeCreateElementsSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.elements;let o=this.detectChangedElements(t,n);return o?.size?this.createElementsSnapshot(o):this.elements}detectChangedAppState(t,n={shouldCompareHashes:!1}){if(this.appState===t)return;let o=F.isRightDifferent(this.appState,t);if(!o)return;let i=dd(JSON.stringify(t));if(!(n.shouldCompareHashes&&this._lastChangedAppStateHash===i))return this._lastChangedAppStateHash=i,o}detectChangedElements(t,n={shouldCompareHashes:!1}){if(this.elements===t)return;let o=new Map;for(let r of On(this.elements))t.get(r.id)||o.set(r.id,ge(r,{isDeleted:!0}));for(let r of On(t)){let s=this.elements.get(r.id);if(!s||s.version<r.version){if(we(r)&&!_t(r))continue;o.set(r.id,r)}}if(!o.size)return;let i=ld(o);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===i))return this._lastChangedElementsHash=i,o}createElementsSnapshot(t){let n=new Map;for(let o of On(this.elements))n.set(o.id,o);for(let o of On(t))n.set(o.id,Kr(o));return n}},sd="__observedAppState",_f=()=>({name:null,editingGroupId:null,viewBackgroundColor:Ff.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),Rn=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,sd,{value:!0,enumerable:!1}),t},rd=e=>!!Reflect.get(e,sd);P();P();var pd="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";function Nn(e,t,n){let o=n[0];if(t!=null&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)===o||t&&t.slice(-1)===o)throw new Error("trailing zero");if(t){let s=0;for(;(e[s]||o)===t[s];)s++;if(s>0)return t.slice(0,s)+Nn(e.slice(s),t.slice(s),n)}let i=e?n.indexOf(e[0]):0,r=t!=null?n.indexOf(t[0]):n.length;if(r-i>1){let s=Math.round(.5*(i+r));return n[s]}else return t&&t.length>1?t.slice(0,1):n[i]+Nn(e.slice(1),null,n)}function md(e){if(e.length!==fd(e[0]))throw new Error("invalid integer part of order key: "+e)}function fd(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 po(e){let t=fd(e[0]);if(t>e.length)throw new Error("invalid order key: "+e);return e.slice(0,t)}function cd(e,t){if(e==="A"+t[0].repeat(26))throw new Error("invalid order key: "+e);let n=po(e);if(e.slice(n.length).slice(-1)===t[0])throw new Error("invalid order key: "+e)}function ud(e,t){md(e);let[n,...o]=e.split(""),i=!0;for(let r=o.length-1;i&&r>=0;r--){let s=t.indexOf(o[r])+1;s===t.length?o[r]=t[0]:(o[r]=t[s],i=!1)}if(i){if(n==="Z")return"a"+t[0];if(n==="z")return null;let r=String.fromCharCode(n.charCodeAt(0)+1);return r>"a"?o.push(t[0]):o.pop(),r+o.join("")}else return n+o.join("")}function Yf(e,t){md(e);let[n,...o]=e.split(""),i=!0;for(let r=o.length-1;i&&r>=0;r--){let s=t.indexOf(o[r])-1;s===-1?o[r]=t.slice(-1):(o[r]=t[s],i=!1)}if(i){if(n==="a")return"Z"+t.slice(-1);if(n==="A")return null;let r=String.fromCharCode(n.charCodeAt(0)-1);return r<"Z"?o.push(t.slice(-1)):o.pop(),r+o.join("")}else return n+o.join("")}function Fn(e,t,n=pd){if(e!=null&&cd(e,n),t!=null&&cd(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=po(t),d=t.slice(l.length);if(l==="A"+n[0].repeat(26))return l+Nn("",d,n);if(l<t)return l;let c=Yf(l,n);if(c==null)throw new Error("cannot decrement any more");return c}if(t==null){let l=po(e),d=e.slice(l.length),c=ud(l,n);return c??l+Nn(d,null,n)}let o=po(e),i=e.slice(o.length),r=po(t),s=t.slice(r.length);if(o===r)return o+Nn(i,s,n);let a=ud(o,n);if(a==null)throw new Error("cannot increment any more");return a<t?a:o+Nn(i,null,n)}function Pi(e,t,n,o=pd){if(n===0)return[];if(n===1)return[Fn(e,t,o)];if(t==null){let s=Fn(e,t,o),a=[s];for(let l=0;l<n-1;l++)s=Fn(s,t,o),a.push(s);return a}if(e==null){let s=Fn(e,t,o),a=[s];for(let l=0;l<n-1;l++)s=Fn(e,s,o),a.push(s);return a.reverse(),a}let i=Math.floor(n/2),r=Fn(e,t,o);return[...Pi(e,r,i,o),r,...Pi(r,t,n-i-1,o)]}import{arrayToMap as Ii}from"@excalidraw/common";var ts=class extends Error{code="ELEMENT_HAS_INVALID_INDEX"},Uf=(e,{shouldThrow:t=!1,includeBoundTextValidation:n=!1,ignoreLogs:o,reconciliationContext:i})=>{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(ns(d,c,u)||r.push(`Fractional indices invariant has been compromised: "${s(e[l-1])}", "${s(e[l])}", "${s(e[l+1])}"`),n&&st(e[l])){let p=e[l],m=W(p,Ii(e));m&&m.index<=p.index&&r.push(`Fractional indices invariant for bound elements has been compromised: "${s(m)}", "${s(p)}"`)}}if(r.length){let l=new ts,d=[];if(i&&(d.push("Additional reconciliation context:"),d.push(i.localElements.map(c=>s(c))),d.push(i.remoteElements.map(c=>s(c)))),o||console.error(r.join(`
19
19
 
20
- `),l.stack,e.map(d=>s(d)),...c),t)throw l}},pc=e=>e.sort((t,n)=>uc(t)&&uc(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),ui=(e,t)=>{try{let n=bo(e),i=Nf(e,t),o=es(e,i),r=e.map(s=>{let a=o.get(s);return a?{...s,index:a.index}:s});kf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of o)ye(s,n,{index:a})}catch{Ff(e)}return e},Ff=e=>{let t=bo(e),n=mc(e),i=es(e,n);for(let[o,{index:r}]of i)ye(o,t,{index:r});return e},ic=e=>{let t=bo(e),n=mc(e),i=es(e,n);for(let[o,{index:r}]of i)t.set(o.id,Me(o,{index:r}));return t},Nf=(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},mc=e=>{let t=[],n,i,o=-1,r=0,s=c=>{let d=e[o]?e[o].index:void 0,u=e[c-1]?.index;return!d&&u||d&&u&&u>d?[u,c-1]:[d,o]},a=c=>{let d=e[r]?e[r].index:void 0;if(d&&c<r)return[d,r];let u=r;for(;++u<e.length;){let p=e[u]?.index;if(!d&&p||d&&p&&p>d)return[p,u]}return[void 0,u]},l=0;for(;l<e.length;){let c=e[l].index;if([n,o]=s(l),[i,r]=a(l),Jr(c,n,i))l++;else{let d=[o,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[f,E]=a(l);if(Jr(u,p,f))break;[n,o]=[p,m],[i,r]=[f,E],d.push(l)}d.push(r),t.push(d)}}return t},Jr=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,es=(e,t)=>{let n=new Map;for(let i of t){let o=i.shift(),r=i.pop(),s=yo(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},uc=e=>!!e.index;P();var Mc=gd(xc(),1);import{randomInteger as nh,arrayToMap as wc,toBrandedType as yc,isDevEnv as bc,isTestEnv as Pc,toArray as ih}from"@excalidraw/common";import{isNonDeletedElement as oh}from"@excalidraw/element";import{isFrameLikeElement as rh}from"@excalidraw/element";import{getElementsInGroup as sh}from"@excalidraw/element";import{syncInvalidIndices as ah,syncMovedIndices as Ic,validateFractionalIndices as lh}from"@excalidraw/element";import{getSelectedElements as ch}from"@excalidraw/element";import{mutateElement as dh}from"@excalidraw/element";var Sc=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}},uh=(0,Mc.default)(e=>{(bc()||Pc()||window?.DEBUG_FRACTIONAL_INDICES)&&lh(e,{shouldThrow:bc()||Pc(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),ph=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let i of t)n+=`${i}:${e[i]?"1":"0"}`;return n},Io=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=yc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=yc(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=ph(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=ch(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&&oh(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=ih(t),o=[];n?.skipValidation||uh(i),this.elements=ah(i),this.elementsMap.clear(),this.elements.forEach(s=>{rh(s)&&o.push(s),this.elementsMap.set(s.id,s)});let r=Sc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=o,this.nonDeletedFramesLikes=Sc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=nh();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)];Ic(i,wc([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)];Ic(i,wc(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]:sh(n,t)};mutateElement(t,n,i={informMutation:!0,isDragging:!1}){let o=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=dh(t,o,n,i);return this.elementsMap.has(t.id)&&r!==s&&i.informMutation&&this.triggerUpdate(),t}};var q=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 c of this.getDifferences(t,n))r[c]=t[c],s[c]=n[c];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){return e.create({...t.deleted,...n.deleted},{...t.inserted,...n.inserted})}static mergeObjects(t,n,i){let o={...t};for(let r of Object.keys(i))delete o[r];return{...o,...n}}static mergeArrays(t,n,i,o){return Object.values(e.mergeObjects(Gt(t??[],o),Gt(n??[],o),Gt(i??[],o)))}static diffObjects(t,n,i,o){if(!t[i]&&!n[i])return;let r=t[i]!==null&&typeof t[i]=="object",s=n[i]!==null&&typeof n[i]=="object";if(r||s){let a=t[i]??{},l=n[i]??{},c=e.getLeftDifferences(a,l).reduce((u,p)=>(u[p]=o(a[p]),u),{}),d=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=o(l[p]),u),{});Object.keys(c).length||Object.keys(d).length?(Reflect.set(t,i,c),Reflect.set(n,i,d)):(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}else t[i]===n[i]&&(Reflect.deleteProperty(t,i),Reflect.deleteProperty(n,i))}static diffArrays(t,n,i,o){if(!(!t[i]&&!n[i])&&(Array.isArray(t[i])||Array.isArray(n[i]))){let r=Array.isArray(t[i])?t[i]:[],s=Array.isArray(n[i])?n[i]:[],a=Gt(e.getLeftDifferences(Gt(r,o),Gt(s,o)),c=>c),l=Gt(e.getRightDifferences(Gt(r,o),Gt(s,o)),c=>c);if(Object.keys(a).length||Object.keys(l).length){let c=r.filter(u=>a[o?o(u):String(u)]),d=s.filter(u=>l[o?o(u):String(u)]);Reflect.set(t,i,c),Reflect.set(n,i,d)}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)])):Ac(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&&Dc(a,l))continue;yield s}}}},fn=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let i=q.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(q.create({},{}))}inverse(){let t=q.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){return this.delta=q.merge(this.delta,t.delta),this}applyTo(t,n){try{let{selectedElementIds:i={},selectedGroupIds:o={}}=this.delta.deleted,{selectedElementIds:r={},selectedGroupIds:s={},selectedLinearElement:a,...l}=this.delta.inserted,c=q.mergeObjects(t.selectedElementIds,r,i),d=q.mergeObjects(t.selectedGroupIds,s,o),u=a&&n.has(a.elementId)?new Y(n.get(a.elementId),n,a.isEditing):null,p={...t,...l,selectedElementIds:c,selectedGroupIds:d,selectedLinearElement:typeof a<"u"?u:t.selectedLinearElement},m=this.filterInvisibleChanges(t,p,n);return[p,m]}catch(i){if(console.error("Couldn't apply appstate change",i),gn()||En())throw i;return[t,!1]}}isEmpty(){return q.isEmpty(this.delta)}filterInvisibleChanges(t,n,i){let o=Rn(t),r=Rn(n),s=q.isRightDifferent(e.stripElementsProps(o),e.stripElementsProps(r)),a=q.isRightDifferent(e.stripStandaloneProps(o),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let c=q.getRightDifferences(e.stripStandaloneProps(o),e.stripStandaloneProps(r)),d=new Set;(c.includes("editingGroupId")||c.includes("selectedGroupIds"))&&(d=hl(i));for(let u of c)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],i,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],d,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let y=i.get(x);y&&!y.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?d.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=i.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},E=n[u]||{};Dc(f,E)||(l.value=!0);break;case"activeLockedId":let h=t[u]||null,g=n[u]||null;h!==g&&(l.value=!0);break;default:Ac(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,...c}=t;return c}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:i,...o}=t;return o}static postProcess(t,n){try{q.diffObjects(t,n,"selectedElementIds",i=>!0),q.diffObjects(t,n,"selectedGroupIds",i=>i??!1),q.diffObjects(t,n,"lockedMultiSelections",i=>i??{}),q.diffObjects(t,n,"activeLockedId",i=>i??null)}catch(i){if(console.error("Couldn't postprocess appstate change deltas."),gn()||En())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}},hn=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={},c=[...Object.entries(t),...Object.entries(n),...Object.entries(i)];for(let[d,u]of c)this.satisfiesAddition(u)?s[d]=u:this.satisfiesRemoval(u)?a[d]=u:l[d]=u;r=new e(s,a,l)}else r=new e(t,n,i);return(gn()||En())&&(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})=>!!(t.version&&n.version&&Number.isInteger(t.version)&&Number.isInteger(n.version)&&t.version>=0&&n.version>=0&&t.version!==n.version);static validate(t,n,i){for(let[o,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!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},c={isDeleted:!0,version:s.version+1,versionNonce:Tc()},d=q.create(l,c,e.stripIrrelevantProps);s.isDeleted||(o[s.id]=d)}for(let s of n.values()){let a=t.get(s.id);if(!a){let l={isDeleted:!0,version:s.version-1,versionNonce:Tc()},c={...s},d=q.create(l,c,e.stripIrrelevantProps);s.isDeleted||(i[s.id]=d);continue}if(a.versionNonce!==s.versionNonce){let l=q.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}let c=e.stripVersionProps(l.deleted),d=e.stripVersionProps(l.inserted);q.isInnerDifferent(c,d,!0)&&(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:c}]of Object.entries(r))s[a]=q.create({...l},{...c});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=(c,d)=>(u,p)=>{let m;switch(p){case"deleted":m=c;break;case"inserted":m=d;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let E of Object.keys(u))switch(E){case"boundElements":f[E]=u[E];break;default:f[E]=m[E]}return f},r=c=>{let d={};for(let[u,p]of Object.entries(c)){let m=t.get(u),f=n.get(u),E=null;m||f?E=q.create(p.deleted,p.inserted,o(m,f),i):E=p;let h=e.stripVersionProps(E.deleted),g=e.stripVersionProps(E.inserted);q.isInnerDifferent(h,g)&&(d[u]=E)}return d},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=Jt.empty().elements,i){let o=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1};try{let a=e.createApplier(o,n,s,i),l=a(this.added),c=a(this.removed),d=a(this.updated),u=this.resolveConflicts(t,o);r=new Map([...l,...c,...d,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),gn()||En())throw a;return[t,!0]}try{o=e.reorderElements(o,r,s),i?.skipRedraw||e.redrawElements(o,r)}catch(a){if(console.error("Couldn't mutate elements after applying elements change",a),gn()||En())throw a}finally{return[o,s.containsVisibleDifference]}}squash(t){let{added:n,removed:i,updated:o}=t;for(let[r,s]of Object.entries(n)){let a=this.added[r];a?this.added[r]=q.merge(a,s):this.added[r]=s}for(let[r,s]of Object.entries(i)){let a=this.removed[r];a?this.removed[r]=q.merge(a,s):this.removed[r]=s}for(let[r,s]of Object.entries(o)){let a=this.updated[r];a?this.updated[r]=q.merge(a,s):this.updated[r]=s}return this}static createApplier=(t,n,i,o)=>r=>{let s=e.createGetter(t,n,i);return Object.entries(r).reduce((a,[l,c])=>{let d=s(l,c.inserted);if(d){let u=e.applyDelta(d,c,i,o);t.set(u.id,u),a.set(u.id,u)}return a},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=Me({id:o,version:1},{...r})),s};static applyDelta(t,n,i,o){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||o?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=q.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),Me(t,r)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:q.isRightDifferent(t,n)}resolveConflicts(t,n){let i=new Map,o=(s,a)=>{let l=n.get(s.id);if(!l)return;let c=t.get(s.id),d;c===l?d=Me(l,a):d=ye(l,n,a),i.set(d.id,d),n.set(d.id,d)};for(let s of Object.keys(this.removed))e.unbindAffected(t,n,s,o);for(let s of Object.keys(this.added))e.rebindAffected(t,n,s,o);for(let[s]of Array.from(Object.entries(this.updated)).filter(([a,l])=>Object.keys({...l.deleted,...l.inserted}).find(c=>Za.has(c)))){let a=n.get(s);!a||a.isDeleted||e.rebindAffected(t,n,s,o)}let r=new Map(Array.from(t).filter(([s])=>i.has(s)));return this.squash(e.calculate(r,i)),i}static unbindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.unbindAffected(n,s(),o),$t.unbindAffected(n,r(),o),$t.unbindAffected(n,s(),o)}static rebindAffected(t,n,i,o){let r=()=>t.get(i),s=()=>n.get(i);Vt.unbindAffected(n,r(),o),Vt.rebindAffected(n,s(),o),$t.unbindAffected(n,r(),(a,l)=>{ie(a)&&o(a,l)}),$t.rebindAffected(n,s(),o)}static redrawElements(t,n){try{let i=new Io(t,{skipValidation:!0});e.redrawTextBoundingBoxes(i,n),e.redrawBoundArrows(i,n)}catch(i){if(console.error("Couldn't redraw elements",i),gn()||En())throw i}finally{return t}}static redrawTextBoundingBoxes(t,n){let i=t.getNonDeletedElementsMap(),o=new Map;for(let r of n.values()){if(de(r)){let{containerId:s}=r,a=s?i.get(s):void 0;a&&o.set(a.id,{container:a,boundText:r})}if(st(r)){let s=It(r),a=s?i.get(s):void 0;a&&o.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of o.values())r.isDeleted||s.isDeleted||ga(s,r,t)}static redrawBoundArrows(t,n){for(let i of n.values())!i.isDeleted&&Le(i)&&Ue(i,t,{changedElements:n})}static reorderElements(t,n,i){if(!i.containsZindexDifference)return t;let o=Array.from(t.values()),r=pc([...o]),s=q.getRightDifferences(o,r,!0).reduce((a,l)=>{let c=o[Number(l)];return c&&n.has(c.id)&&a.set(c.id,c),a},new Map);return!i.containsVisibleDifference&&s.size&&(i.containsVisibleDifference=!0),mh(ui(r,s))}static postProcess(t,n){try{q.diffArrays(t,n,"boundElements",r=>r.id);let i=t.points??[],o=n.points??[];q.isDifferent(i,o)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(i){if(console.error("Couldn't postprocess elements delta."),gn()||En())throw i}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:i,...o}=t;return o}static stripVersionProps(t){let{version:n,versionNonce:i,...o}=t;return o}};P();var iP=(e,t,n,i)=>{let[o,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Ct(e),c=uo(e,t,i).map(m=>[m,Ct(m)]).sort((m,f)=>m[1][r]-f[1][r]),d=0;for(let m of c)d+=m[1][a];let u=(l[a]-d)/(c.length-1);if(u<0){let m=c.findIndex(g=>g[1][o]===l[o]),f=c.findIndex(g=>g[1][s]===l[s]),E=(c[f][1][r]-c[m][1][r])/(c.length-1),h=c[m][1][r];return c.flatMap(([g,x],y)=>{let b={x:0,y:0};return y!==m&&y!==f&&(h+=E,b[n.axis]=h-x[r]),g.map(w=>Me(w,{x:w.x+b.x,y:w.y+b.y}))})}let p=l[o];return c.flatMap(([m,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[o],p+=u,p+=f[a],m.map(h=>Me(h,{x:h.x+E.x,y:h.y+E.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as fh,getGridPoint as hh,getFontString as Eh}from"@excalidraw/common";var mP=(e,t,n,i,o,r)=>{if(t.length===1&&G(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(u=>{if(G(u)&&u.startBinding&&u.endBinding){let p=t.find(f=>f.id===u.startBinding?.elementId),m=t.find(f=>f.id===u.endBinding?.elementId);return p&&m}return!0}),a=new Set(s),l=s.filter(u=>$(u)).map(u=>u.id);if(l.length>0)for(let u of i.getNonDeletedElements())u.frameId!==null&&l.includes(u.frameId)&&a.add(u);let c=[];for(let u of a){let p=e.originalElements.get(u.id);if(!p)return;c.push(p)}let d=gh(tt(c),n,o,r);a.forEach(u=>{if(vc(e,u,i,d),!_(u)){let p=W(u,i.getNonDeletedElementsMap());p&&vc(e,p,i,d),Ue(u,i,{simultaneouslyUpdated:Array.from(a)})}})},gh=(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,c]=hh(o+t.x,r+t.y,i);n.x===0&&(s=l),n.y===0&&(a=c)}return{x:s-o,y:a-r}},vc=(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})},fP=(e,t,n)=>{let[i,o]=tt(e);return[t-i,n-o]},hP=({newElement:e,elementType:t,originX:n,originY:i,x:o,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:c,zoom:d,scene:u,widthAspectRatio:p=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-i)>Math.abs(o-n)?{width:s,height:a}=Wr(t,a,o<n?-s:s):{width:s,height:a}=Wr(t,s,r<i?-a:a),a<0&&(a=-a)));let E=o<n?n-s:n,h=r<i?i-a:i;c&&(s+=s,a+=a,E=n-s/2,h=i-a/2);let g=null;if(ie(e)){a=e.height;let x=Ni(Eh({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(o-n)>fh/d&&(g={autoResize:!1}),h=i,c&&(E=n-s/2)}if(s!==0&&a!==0){let x=null;xe(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:E+(m?.x??0),y:h+(m?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as So,normalizeLink as Lc}from"@excalidraw/common";var yP=(e,t)=>{let n=window.location.href;try{let i=new URL(n);return i.searchParams.set(So,e),Lc(i.toString())}catch(i){console.error(i)}return Lc(n)},bP=(e,t)=>{if(e.length>0&&xh(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},xh=e=>!!(e.length===1||e.length>1&&El(e)),PP=e=>{try{let t=new URL(e);return t.searchParams.has(So)&&t.host===window.location.host}catch{return!1}},IP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(So))return t.get(So)}catch{}return null};P();import{FONT_FAMILY as Lh,VERTICAL_ALIGN as Ch,escapeDoubleQuotes as is,getFontString as Bh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as en,DEFAULT_FONT_FAMILY as wh,DEFAULT_FONT_SIZE as yh,DEFAULT_TEXT_ALIGN as bh,DEFAULT_VERTICAL_ALIGN as Ph,VERTICAL_ALIGN as Ih,randomInteger as Sh,randomId as Mh,getFontString as Mo,getUpdatedTimestamp as Th,getLineHeight as Ah}from"@excalidraw/common";var nt=(e,{x:t,y:n,strokeColor:i=en.strokeColor,backgroundColor:o=en.backgroundColor,fillStyle:r=en.fillStyle,strokeWidth:s=en.strokeWidth,strokeStyle:a=en.strokeStyle,roughness:l=en.roughness,opacity:c=en.opacity,width:d=0,height:u=0,angle:p=0,groupIds:m=[],frameId:f=null,index:E=null,roundness:h=null,boundElements:g=null,link:x=null,locked:y=en.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||d<-1e6||d>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:d,height:u,points:b.points}),{id:b.id||Mh(),type:e,x:t,y:n,width:d,height:u,angle:p,strokeColor:i,backgroundColor:o,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:c,groupIds:m,frameId:f,index:E,roundness:h,seed:b.seed??Sh(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Th(),link:x,locked:y,customData:b.customData}),ns=e=>nt(e.type,e),GP=e=>nt("embeddable",e),OP=e=>({...nt("iframe",e)}),RP=e=>Me({...nt("frame",e),type:"frame",name:e?.name||null},{}),kP=e=>Me({...nt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Cc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Bc=e=>{let t=e.fontFamily||wh,n=e.fontSize||yh,i=e.lineHeight||Ah(t),o=tr(e.text),r=Qe(o,Mo({fontFamily:t,fontSize:n}),i),s=e.textAlign||bh,a=e.verticalAlign||Ph,l=Cc({textAlign:s,verticalAlign:a},r),c={...nt("text",e),text:o,fontSize:n,fontFamily:t,textAlign:s,verticalAlign:a,x:e.x-l.x,y:e.y-l.y,width:r.width,height:r.height,containerId:e.containerId||null,originalText:e.originalText??o,autoResize:e.autoResize??!0,lineHeight:i};return Me(c,{})},Dh=(e,t,n)=>{let{width:i,height:o}=Qe(n,Mo(e),e.lineHeight);e.autoResize||(i=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Ih.MIDDLE&&!e.containerId&&e.autoResize){let c=Qe(e.text,Mo(e),e.lineHeight),d=Cc(e,{width:i-c.width,height:o-c.height});a=e.x-d.x,l=e.y-d.y}else{let[c,d,u,p]=H(e,t),[m,f,E,h]=Nt(e,i,o,!1),g=(c-m)/2,x=(d-f)/2,y=(u-E)/2,b=(p-h)/2;[a,l]=vh({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,y,b)}return{width:i,height:o,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},vh=(e,t,n,i,o,r,s,a)=>{let l=Math.cos(i),c=Math.sin(i);return e.e&&e.w?t+=o+s:e.e?(t+=o*(1+l),n+=o*c,t+=s*(1-l),n+=s*-c):e.w&&(t+=o*(1-l),n+=o*-c,t+=s*(1+l),n+=s*c),e.n&&e.s?n+=r+a:e.n?(t+=r*c,n+=r*(1-l),t+=a*-c,n+=a*(1+l)):e.s&&(t+=r*-c,n+=r*(1+l),t+=a*c,n+=a*(1-l)),[t,n]},FP=(e,t,n,i=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(i=Pt(i,Mo(e),t?Je(t,e):e.width));let o=Dh(e,n,i);return{text:i,...o}},NP=e=>({...nt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,lastCommittedPoint:null}),zP=e=>{let t={...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return cn(t)?{...t,polygon:e.polygon??!1}:t},Gc=e=>e.elbowed?{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},HP=e=>({...nt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ft=new Map,Gh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,Oh=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Rh=/^https:\/\/(?:www\.)?figma\.com/,Oc=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,kh=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Fh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Rc=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,Nh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,zh=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Hh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,kc=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,Fc=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,_h=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Yh=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)},rs=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Nc=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),os=e=>`<html><body>${e}</body></html>`,VP=e=>{if(!e)return null;if(ft.has(e))return ft.get(e);let t=e,n=Nc.has(ss(e,Nc)||""),i="generic",o={w:560,h:840},r=e.match(Gh);if(r?.[2]){let c=Yh(t),d=c>0?`&start=${c}`:"",u=e.includes("shorts");switch(i="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${d}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${d}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${d}`;break}return o=u?{w:315,h:560}:{w:560,h:315},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}}let s=e.match(Oh);if(s?.[1]){let c=s?.[1],d=/^\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},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,error:d,sandbox:{allowSameOrigin:n}}}if(e.match(Rh))return i="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,o={w:550,h:550},ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};let l=e.match(zh);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ft.set(t,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}};if(Fh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Rc.test(e)){let c=e.match(Rc)[1],d=is(`https://twitter.com/x/status/${c}`),u={type:"document",srcdoc:p=>os(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${d}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,u),u}if(Fc.test(e)){let[,c,d,u]=e.match(Fc),p=is(`https://reddit.com/r/${c}/comments/${d}/${u}`),m={type:"document",srcdoc:f=>os(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${p}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,m),m}if(Oc.test(e)){let[,c,d]=e.match(Oc),u=is(`https://gist.github.com/${c}/${d}`),p={type:"document",srcdoc:()=>os(`
20
+ `),l.stack,e.map(c=>s(c)),...d),t)throw l}},Ed=e=>e.sort((t,n)=>hd(t)&&hd(n)?t.index<n.index?-1:t.index>n.index?1:t.id<n.id?-1:1:1),mo=(e,t)=>{try{let n=Ii(e),o=jf(e,t),i=os(e,o),r=e.map(s=>{let a=i.get(s);return a?{...s,index:a.index}:s});Uf(r,{includeBoundTextValidation:!1,shouldThrow:!0,ignoreLogs:!0});for(let[s,{index:a}]of i)be(s,n,{index:a})}catch{Xf(e)}return e},Xf=e=>{let t=Ii(e),n=gd(e),o=os(e,n);for(let[i,{index:r}]of o)be(i,t,{index:r});return e},ad=e=>{let t=Ii(e),n=gd(e),o=os(e,n);for(let[i,{index:r}]of o)t.set(i.id,ge(i,{index:r}));return t},jf=(e,t)=>{let n=[],o=0;for(;o<e.length;)if(t.has(e[o].id)){let i=[o-1,o];for(;++o<e.length&&t.has(e[o].id);)i.push(o);i.push(o),n.push(i)}else o++;return n},gd=e=>{let t=[],n,o,i=-1,r=0,s=d=>{let c=e[i]?e[i].index:void 0,u=e[d-1]?.index;return!c&&u||c&&u&&u>c?[u,d-1]:[c,i]},a=d=>{let c=e[r]?e[r].index:void 0;if(c&&d<r)return[c,r];let u=r;for(;++u<e.length;){let p=e[u]?.index;if(!c&&p||c&&p&&p>c)return[p,u]}return[void 0,u]},l=0;for(;l<e.length;){let d=e[l].index;if([n,i]=s(l),[o,r]=a(l),ns(d,n,o))l++;else{let c=[i,l];for(;++l<e.length;){let u=e[l].index,[p,m]=s(l),[f,E]=a(l);if(ns(u,p,f))break;[n,i]=[p,m],[o,r]=[f,E],c.push(l)}c.push(r),t.push(c)}}return t},ns=(e,t,n)=>e?t&&n?t<e&&e<n:!t&&n?e<n:t&&!n?t<e:!!e:!1,os=(e,t)=>{let n=new Map;for(let o of t){let i=o.shift(),r=o.pop(),s=Pi(e[i]?.index,e[r]?.index,o.length);for(let a=0;a<o.length;a++){let l=e[o[a]];n.set(l,{index:s[a]})}}return n},hd=e=>!!e.index;P();var vd=bc(Pd(),1);import{randomInteger as dh,arrayToMap as Id,toBrandedType as Sd,isDevEnv as Md,isTestEnv as Td,toArray as ch}from"@excalidraw/common";import{isNonDeletedElement as uh}from"@excalidraw/element";import{isFrameLikeElement as ph}from"@excalidraw/element";import{getElementsInGroup as mh}from"@excalidraw/element";import{syncInvalidIndices as fh,syncMovedIndices as Ad,validateFractionalIndices as hh}from"@excalidraw/element";import{getSelectedElements as Eh}from"@excalidraw/element";import{mutateElement as gh}from"@excalidraw/element";var Dd=e=>{let t=new Map,n=[];for(let o of e)o.isDeleted||(n.push(o),t.set(o.id,o));return{elementsMap:t,elements:n}},xh=(0,vd.default)(e=>{(Md()||Td()||window?.DEBUG_FRACTIONAL_INDICES)&&hh(e,{shouldThrow:Md()||Td(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),wh=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let o of t)n+=`${o}:${e[o]?"1":"0"}`;return n},Mi=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=Sd(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=Sd(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=wh(t),o=t?.elements||this.nonDeletedElements;if(this.selectedElementsCache.elements===o&&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 i=Eh(o,{selectedElementIds:t.selectedElementIds},t);return t?.elements==null&&(this.selectedElementsCache.selectedElementIds=t.selectedElementIds,this.selectedElementsCache.elements=this.nonDeletedElements,this.selectedElementsCache.cache.set(n,i)),i}getNonDeletedFramesLikes(){return this.nonDeletedFramesLikes}getElement(t){return this.elementsMap.get(t)||null}getNonDeletedElement(t){let n=this.getElement(t);return n&&uh(n)?n:null}mapElements(t){let n=!1,o=this.elements.map(i=>{let r=t(i);return r!==i&&(n=!0),r});return n&&this.replaceAllElements(o),n}replaceAllElements(t,n){let o=ch(t),i=[];n?.skipValidation||xh(o),this.elements=fh(o),this.elementsMap.clear(),this.elements.forEach(s=>{ph(s)&&i.push(s),this.elementsMap.set(s.id,s)});let r=Dd(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=i,this.nonDeletedFramesLikes=Dd(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=dh();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 o=[...this.elements.slice(0,n),t,...this.elements.slice(n)];Ad(o,Id([t])),this.replaceAllElements(o)}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 o=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];Ad(o,Id(t)),this.replaceAllElements(o)}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(),o=n.get(t);return o?[o]:mh(n,t)};mutateElement(t,n,o={informMutation:!0,isDragging:!1}){let i=this.getNonDeletedElementsMap(),{version:r}=t,{version:s}=gh(t,i,n,o);return this.elementsMap.has(t.id)&&r!==s&&o.informMutation&&this.triggerUpdate(),t}};var F=class e{constructor(t,n){this.deleted=t;this.inserted=n}static create(t,n,o,i){let r=o&&i!=="inserted"?o(t,"deleted"):t,s=o&&i!=="deleted"?o(n,"inserted"):n;return new e(r,s)}static calculate(t,n,o,i){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]=i?i(r,s):[r,s];return e.create(a,l,o)}static empty(){return new e({},{})}static isEmpty(t){return!Object.keys(t.deleted).length&&!Object.keys(t.inserted).length}static merge(t,n,o=e.empty()){return e.create({...t.deleted,...n.deleted,...o.deleted},{...t.inserted,...n.inserted,...o.inserted})}static mergeObjects(t,n,o={}){let i={...t};for(let r of Object.keys(o))delete i[r];return{...i,...n}}static mergeArrays(t,n,o,i){return Object.values(e.mergeObjects(Ot(t??[],i),Ot(n??[],i),Ot(o??[],i)))}static diffObjects(t,n,o,i){if(!t[o]&&!n[o])return;let r=t[o]!==null&&typeof t[o]=="object",s=n[o]!==null&&typeof n[o]=="object";if(r||s){let a=t[o]??{},l=n[o]??{},d=e.getLeftDifferences(a,l).reduce((u,p)=>(u[p]=i(a[p]),u),{}),c=e.getRightDifferences(a,l).reduce((u,p)=>(u[p]=i(l[p]),u),{});Object.keys(d).length||Object.keys(c).length?(Reflect.set(t,o,d),Reflect.set(n,o,c)):(Reflect.deleteProperty(t,o),Reflect.deleteProperty(n,o))}else t[o]===n[o]&&(Reflect.deleteProperty(t,o),Reflect.deleteProperty(n,o))}static diffArrays(t,n,o,i){if(!(!t[o]&&!n[o])&&(Array.isArray(t[o])||Array.isArray(n[o]))){let r=Array.isArray(t[o])?t[o]:[],s=Array.isArray(n[o])?n[o]:[],a=Ot(e.getLeftDifferences(Ot(r,i),Ot(s,i)),d=>d),l=Ot(e.getRightDifferences(Ot(r,i),Ot(s,i)),d=>d);if(Object.keys(a).length||Object.keys(l).length){let d=r.filter(u=>a[i?i(u):String(u)]),c=s.filter(u=>l[i?i(u):String(u)]);Reflect.set(t,o,d),Reflect.set(n,o,c)}else Reflect.deleteProperty(t,o),Reflect.deleteProperty(n,o)}}static isLeftDifferent(t,n,o=!1){return!!this.distinctKeysIterator("left",t,n,o).next().value}static isRightDifferent(t,n,o=!1){return!!this.distinctKeysIterator("right",t,n,o).next().value}static isInnerDifferent(t,n,o=!1){return!!!!this.distinctKeysIterator("inner",t,n,o).next().value}static isDifferent(t,n,o=!1){return!!!!this.distinctKeysIterator("full",t,n,o).next().value}static getLeftDifferences(t,n,o=!1){return Array.from(this.distinctKeysIterator("left",t,n,o)).sort()}static getRightDifferences(t,n,o=!1){return Array.from(this.distinctKeysIterator("right",t,n,o)).sort()}static getInnerDifferences(t,n,o=!1){return Array.from(this.distinctKeysIterator("inner",t,n,o)).sort()}static getDifferences(t,n,o=!1){return Array.from(this.distinctKeysIterator("full",t,n,o)).sort()}static*distinctKeysIterator(t,n,o,i=!1){if(n===o)return;let r=[];t==="left"?r=Object.keys(n):t==="right"?r=Object.keys(o):t==="inner"?r=Object.keys(n).filter(s=>s in o):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(o)])):Cd(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let s of r){let a=n[s],l=o[s];if(a!==l){if(!i&&typeof a=="object"&&typeof l=="object"&&a!==null&&l!==null&&Gd(a,l))continue;yield s}}}},en=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let o=F.calculate(t,n,e.orderAppStateKeys,e.postProcess);return new e(o)}static restore(t){let{delta:n}=t;return new e(n)}static empty(){return new e(F.create({},{}))}inverse(){let t=F.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=F.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),o=F.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),i=F.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=F.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),s=F.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),a=F.mergeObjects(this.delta.inserted.lockedMultiSelections??{},t.delta.inserted.lockedMultiSelections??{}),l={},d={};return(Object.keys(n).length||Object.keys(o).length)&&(d.selectedElementIds=n,l.selectedElementIds=o),(Object.keys(i).length||Object.keys(r).length)&&(d.selectedGroupIds=i,l.selectedGroupIds=r),(Object.keys(s).length||Object.keys(a).length)&&(d.lockedMultiSelections=s,l.lockedMultiSelections=a),this.delta=F.merge(this.delta,t.delta,F.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:o={},selectedGroupIds:i={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:s={},selectedGroupIds:a={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=F.mergeObjects(t.selectedElementIds,s,o),p=F.mergeObjects(t.selectedGroupIds,a,i),m=F.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new U(n.get(d.elementId),n,d.isEditing):null,E={...t,...c,selectedElementIds:u,selectedGroupIds:p,lockedMultiSelections:m,selectedLinearElement:typeof d<"u"?f:t.selectedLinearElement},h=this.filterInvisibleChanges(t,E,n);return[E,h]}catch(o){if(console.error("Couldn't apply appstate change",o),rn()||on())throw o;return[t,!1]}}isEmpty(){return F.isEmpty(this.delta)}filterInvisibleChanges(t,n,o){let i=Rn(t),r=Rn(n),s=F.isRightDifferent(e.stripElementsProps(i),e.stripElementsProps(r)),a=F.isRightDifferent(e.stripStandaloneProps(i),e.stripStandaloneProps(r));if(!s&&!a)return!1;let l={value:s};if(a){let d=F.getRightDifferences(e.stripStandaloneProps(i),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=xl(o));for(let u of d)switch(u){case"selectedElementIds":n[u]=e.filterSelectedElements(n[u],o,l);break;case"selectedGroupIds":n[u]=e.filterSelectedGroups(n[u],c,l);break;case"croppingElementId":{let x=n[u];if(!x)l.value=!0;else{let y=o.get(x);y&&!y.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let p=n[u];p?c.has(p)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let x=o.get(m.elementId);x&&!x.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},E=n[u]||{};Gd(f,E)||(l.value=!0);break;case"activeLockedId":let h=t[u]||null,g=n[u]||null;h!==g&&(l.value=!0);break;default:Cd(u,`Unknown ObservedElementsAppState's key "${u}"`,!0)}}return l.value}static filterSelectedElements(t,n,o){let i=Object.keys(t);if(!i.length)return o.value=!0,t;let r={...t};for(let s of i){let a=n.get(s);a&&!a.isDeleted?o.value=!0:delete r[s]}return r}static filterSelectedGroups(t,n,o){if(!Object.keys(t).length)return o.value=!0,t;let r={...t};for(let s of Object.keys(r))n.has(s)?o.value=!0:delete r[s];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:o,selectedElementIds:i,selectedLinearElement:r,croppingElementId:s,lockedMultiSelections:a,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:o,...i}=t;return i}static postProcess(t,n){try{F.diffObjects(t,n,"selectedElementIds",o=>!0),F.diffObjects(t,n,"selectedGroupIds",o=>o??!1),F.diffObjects(t,n,"lockedMultiSelections",o=>o??{})}catch(o){if(console.error("Couldn't postprocess appstate change deltas."),rn()||on())throw o}finally{return[t,n]}}static orderAppStateKeys(t){let n={};for(let o of Object.keys(t).sort())n[o]=t[o];return n}},tn=class e{constructor(t,n,o){this.added=t;this.removed=n;this.updated=o}static create(t,n,o,i={shouldRedistribute:!1}){let r;if(i.shouldRedistribute){let s={},a={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(o)];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,o);return(rn()||on())&&(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:o,updated:i}=t;return e.create(n,o,i)}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:o,removed:i,updated:r}=t;return[o[n],i[n],r[n]].filter(Boolean).length===1};static validate(t,n,o){for(let[i,r]of Object.entries(t[n]))if(!this.satisfiesCommmonInvariants(r)||!this.satisfiesUniqueInvariants(t,i)||!o(r))throw console.error(`Broken invariant for "${n}" delta, element "${i}", delta:`,r),new Error(`ElementsDelta invariant broken for element "${i}".`)}static calculate(t,n){if(t===n)return e.empty();let o={},i={},r={};for(let s of t.values())if(!n.get(s.id)){let l={...s},d={isDeleted:!0,version:s.version+1,versionNonce:Ld()},c=F.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:i[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:Ld()},d={...s},c=F.create(l,d,e.stripIrrelevantProps);s.isDeleted?r[s.id]=c:o[s.id]=c;continue}if(a.versionNonce!==s.versionNonce){let l=F.calculate(a,s,e.stripIrrelevantProps,e.postProcess);if(typeof a.isDeleted=="boolean"&&typeof s.isDeleted=="boolean"&&a.isDeleted!==s.isDeleted){a.isDeleted&&!s.isDeleted?o[s.id]=l:i[s.id]=l;continue}r[s.id]=l}}return e.create(o,i,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let s={};for(let[a,{inserted:l,deleted:d}]of Object.entries(r))s[a]=F.create({...l},{...d});return s},n=t(this.added),o=t(this.removed),i=t(this.updated);return e.create(o,n,i)}isEmpty(){return Object.keys(this.added).length===0&&Object.keys(this.removed).length===0&&Object.keys(this.updated).length===0}applyLatestChanges(t,n,o){let i=(d,c)=>(u,p)=>{let m;switch(p){case"deleted":m=d;break;case"inserted":m=c;break}if(!m)return console.error("Element not found when trying to apply latest changes"),u;let f={};for(let E of Object.keys(u))switch(E){case"boundElements":f[E]=u[E];break;default:f[E]=m[E]}return f},r=d=>{let c={};for(let[u,p]of Object.entries(d)){let m=t.get(u),f=n.get(u),E=null;m||f?E=F.create(p.deleted,p.inserted,i(m,f),o):E=p,F.isInnerDifferent(E.deleted,E.inserted)&&(c[u]=E)}return c},s=r(this.added),a=r(this.removed),l=r(this.updated);return e.create(s,a,l,{shouldRedistribute:!0})}applyTo(t,n=nn.empty().elements,o){let i=new Map(t),r,s={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let a=e.createApplier(t,i,n,s,o),l=a(this.added),d=a(this.removed),c=a(this.updated),u=this.resolveConflicts(t,i,s.applyDirection);r=new Map([...l,...d,...c,...u])}catch(a){if(console.error("Couldn't apply elements delta",a),rn()||on())throw a;return[t,!0]}try{i=e.reorderElements(i,r,s),e.redrawElements(i,r)}catch(a){if(console.error("Couldn't mutate elements after applying elements change",a),rn()||on())throw a}finally{return[i,s.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:o,updated:i}=t,r=(s,a)=>{let l=F.mergeArrays(s.deleted.boundElements??[],a.deleted.boundElements??[],void 0,c=>c.id)??[],d=F.mergeArrays(s.inserted.boundElements??[],a.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return F.create({boundElements:l},{boundElements:d})};for(let[s,a]of Object.entries(n)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.added[s]=a;else{let d=r(l,a);delete this.removed[s],delete this.updated[s],this.added[s]=F.merge(l,a,d)}}for(let[s,a]of Object.entries(o)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.removed[s]=a;else{let d=r(l,a);delete this.added[s],delete this.updated[s],this.removed[s]=F.merge(l,a,d)}}for(let[s,a]of Object.entries(i)){let l=this.added[s]??this.removed[s]??this.updated[s];if(!l)this.updated[s]=a;else{let d=r(l,a),c=F.merge(l,a,d);l===this.added[s]?this.added[s]=c:l===this.removed[s]?this.removed[s]=c:this.updated[s]=c}}return(rn()||on())&&(e.validate(this,"added",e.satisfiesAddition),e.validate(this,"removed",e.satisfiesRemoval),e.validate(this,"updated",e.satisfiesUpdate)),this}static createApplier=(t,n,o,i,r)=>s=>{let a=e.createGetter(n,o,i);return Object.entries(s).reduce((l,[d,c])=>{let u=a(d,c.inserted);if(u){let p=e.applyDelta(u,c,i,r);if(n.set(p.id,p),l.set(p.id,p),!i.applyDirection){let m=t.get(d);m&&(i.applyDirection=m.version>p.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,o)=>(i,r)=>{let s=t.get(i);return s||(s=n.get(i),s?(o.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!s.isDeleted)&&(o.containsVisibleDifference=!0)):s=ge({id:i,version:1},{...r})),s};static applyDelta(t,n,o,i){let r={};for(let s of Object.keys(n.inserted)){if(s==="boundElements"||i?.excludedProperties?.has(s))continue;let a=n.inserted[s];Reflect.set(r,s,a)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let s=F.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,a=>a.id);Object.assign(r,{boundElements:s})}if(!o.containsVisibleDifference){let{index:s,...a}=r,l=e.checkForVisibleDifference(t,a);o.containsVisibleDifference=l}return o.containsZindexDifference||(o.containsZindexDifference=n.deleted.index!==n.inserted.index),ge(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:F.isRightDifferent(t,n)}resolveConflicts(t,n,o="forward"){let i=new Map,r=(a,l)=>{let d=n.get(a.id);if(!d)return;let c=t.get(a.id),u=o==="forward"?d.version+1:d.version-1,p=l,m;c===d?m=ge(d,{...p,version:u},!0):m=be(d,n,{...p,version:c?.version!==d.version?d.version:u}),i.set(m.id,m),n.set(m.id,m)};for(let a of Object.keys(this.removed))e.unbindAffected(t,n,a,r);for(let a of Object.keys(this.added))e.rebindAffected(t,n,a,r);for(let[a]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>Qa.has(c)))){let l=n.get(a);!l||l.isDeleted||e.rebindAffected(t,n,a,r)}let s=new Map(Array.from(t).filter(([a])=>i.has(a)));return this.squash(e.calculate(s,i)),i}static unbindAffected(t,n,o,i){let r=()=>t.get(o),s=()=>n.get(o);$t.unbindAffected(n,r(),i),$t.unbindAffected(n,s(),i),Zt.unbindAffected(n,r(),i),Zt.unbindAffected(n,s(),i)}static rebindAffected(t,n,o,i){let r=()=>t.get(o),s=()=>n.get(o);$t.unbindAffected(n,r(),i),$t.rebindAffected(n,s(),i),Zt.unbindAffected(n,r(),(a,l)=>{oe(a)&&i(a,l)}),Zt.rebindAffected(n,s(),i)}static redrawElements(t,n){try{let o=new Mi(t,{skipValidation:!0});e.redrawTextBoundingBoxes(o,n),e.redrawBoundArrows(o,n)}catch(o){if(console.error("Couldn't redraw elements",o),rn()||on())throw o}finally{return t}}static redrawTextBoundingBoxes(t,n){let o=t.getNonDeletedElementsMap(),i=new Map;for(let r of n.values()){if(ce(r)){let{containerId:s}=r,a=s?o.get(s):void 0;a&&i.set(a.id,{container:a,boundText:r})}if(st(r)){let s=St(r),a=s?o.get(s):void 0;a&&i.set(r.id,{container:r,boundText:a})}}for(let{container:r,boundText:s}of i.values())r.isDeleted||s.isDeleted||ba(s,r,t)}static redrawBoundArrows(t,n){for(let o of n.values())!o.isDeleted&&Le(o)&&Ue(o,t,{changedElements:n})}static reorderElements(t,n,o){if(!o.containsZindexDifference)return t;let i=Array.from(t.values()),r=Ed([...i]),s=F.getRightDifferences(i,r,!0).reduce((a,l)=>{let d=i[Number(l)];return d&&n.has(d.id)&&a.set(d.id,d),a},new Map);return!o.containsVisibleDifference&&s.size&&(o.containsVisibleDifference=!0),yh(mo(r,s))}static postProcess(t,n){try{F.diffArrays(t,n,"boundElements",r=>r.id);let o=t.points??[],i=n.points??[];F.isDifferent(o,i)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(o){if(console.error("Couldn't postprocess elements delta."),rn()||on())throw o}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:o,...i}=t;return i}};P();var pP=(e,t,n,o)=>{let[i,r,s,a]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],l=Bt(e),d=pi(e,t,o).map(m=>[m,Bt(m)]).sort((m,f)=>m[1][r]-f[1][r]),c=0;for(let m of d)c+=m[1][a];let u=(l[a]-c)/(d.length-1);if(u<0){let m=d.findIndex(g=>g[1][i]===l[i]),f=d.findIndex(g=>g[1][s]===l[s]),E=(d[f][1][r]-d[m][1][r])/(d.length-1),h=d[m][1][r];return d.flatMap(([g,x],y)=>{let b={x:0,y:0};return y!==m&&y!==f&&(h+=E,b[n.axis]=h-x[r]),g.map(w=>ge(w,{x:w.x+b.x,y:w.y+b.y}))})}let p=l[i];return d.flatMap(([m,f])=>{let E={x:0,y:0};return E[n.axis]=p-f[i],p+=u,p+=f[a],m.map(h=>ge(h,{x:h.x+E.x,y:h.y+E.y}))})};P();import{TEXT_AUTOWRAP_THRESHOLD as bh,getGridPoint as Ph,getFontString as Ih}from"@excalidraw/common";var PP=(e,t,n,o,i,r)=>{if(t.length===1&&B(t[0])&&(t[0].startBinding||t[0].endBinding))return;let s=t.filter(u=>{if(B(u)&&u.startBinding&&u.endBinding){let p=t.find(f=>f.id===u.startBinding?.elementId),m=t.find(f=>f.id===u.endBinding?.elementId);return p&&m}return!0}),a=new Set(s),l=s.filter(u=>q(u)).map(u=>u.id);if(l.length>0)for(let u of o.getNonDeletedElements())u.frameId!==null&&l.includes(u.frameId)&&a.add(u);let d=[];for(let u of a){let p=e.originalElements.get(u.id);if(!p)return;d.push(p)}let c=Sh(Xe(d),n,i,r);a.forEach(u=>{if(Bd(e,u,o,c),!_(u)){let p=W(u,o.getNonDeletedElementsMap());p&&Bd(e,p,o,c),Ue(u,o,{simultaneouslyUpdated:Array.from(a)})}})},Sh=(e,t,n,o)=>{let[i,r]=e,s=i+t.x+n.x,a=r+t.y+n.y;if(n.x===0||n.y===0){let[l,d]=Ph(i+t.x,r+t.y,o);n.x===0&&(s=l),n.y===0&&(a=d)}return{x:s-i,y:a-r}},Bd=(e,t,n,o)=>{let i=e.originalElements.get(t.id)??t,r=i.x+o.x,s=i.y+o.y;n.mutateElement(t,{x:r,y:s})},IP=(e,t,n)=>{let[o,i]=Xe(e);return[t-o,n-i]},SP=({newElement:e,elementType:t,originX:n,originY:o,x:i,y:r,width:s,height:a,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:p=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(p?a=s/p:(Math.abs(r-o)>Math.abs(i-n)?{width:s,height:a}=$r(t,a,i<n?-s:s):{width:s,height:a}=$r(t,s,r<o?-a:a),a<0&&(a=-a)));let E=i<n?n-s:n,h=r<o?o-a:o;d&&(s+=s,a+=a,E=n-s/2,h=o-a/2);let g=null;if(oe(e)){a=e.height;let x=zo(Ih({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);s=Math.max(s,x),Math.abs(i-n)>bh/c&&(g={autoResize:!1}),h=o,d&&(E=n-s/2)}if(s!==0&&a!==0){let x=null;we(e)&&(x={initialWidth:s,initialHeight:a}),u.mutateElement(e,{x:E+(m?.x??0),y:h+(m?.y??0),width:s,height:a,...g,...x},{informMutation:f,isDragging:!1})}};P();import{ELEMENT_LINK_KEY as Ti,normalizeLink as kd}from"@excalidraw/common";var vP=(e,t)=>{let n=window.location.href;try{let o=new URL(n);return o.searchParams.set(Ti,e),kd(o.toString())}catch(o){console.error(o)}return kd(n)},LP=(e,t)=>{if(e.length>0&&Mh(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},Mh=e=>!!(e.length===1||e.length>1&&wl(e)),CP=e=>{try{let t=new URL(e);return t.searchParams.has(Ti)&&t.host===window.location.host}catch{return!1}},GP=e=>{try{let{searchParams:t}=new URL(e);if(t.has(Ti))return t.get(Ti)}catch{}return null};P();import{FONT_FAMILY as Fh,VERTICAL_ALIGN as Nh,escapeDoubleQuotes as ss,getFontString as Hh}from"@excalidraw/common";P();import{DEFAULT_ELEMENT_PROPS as sn,DEFAULT_FONT_FAMILY as Th,DEFAULT_FONT_SIZE as Ah,DEFAULT_TEXT_ALIGN as Dh,DEFAULT_VERTICAL_ALIGN as vh,VERTICAL_ALIGN as Lh,randomInteger as Ch,randomId as Gh,getFontString as Ai,getUpdatedTimestamp as Bh,getLineHeight as kh}from"@excalidraw/common";var nt=(e,{x:t,y:n,strokeColor:o=sn.strokeColor,backgroundColor:i=sn.backgroundColor,fillStyle:r=sn.fillStyle,strokeWidth:s=sn.strokeWidth,strokeStyle:a=sn.strokeStyle,roughness:l=sn.roughness,opacity:d=sn.opacity,width:c=0,height:u=0,angle:p=0,groupIds:m=[],frameId:f=null,index:E=null,roundness:h=null,boundElements:g=null,link:x=null,locked:y=sn.locked,...b})=>((t<-1e6||t>1e6||n<-1e6||n>1e6||c<-1e6||c>1e6||u<-1e6||u>1e6)&&console.error("New element size or position is too large",{x:t,y:n,width:c,height:u,points:b.points}),{id:b.id||Gh(),type:e,x:t,y:n,width:c,height:u,angle:p,strokeColor:o,backgroundColor:i,fillStyle:r,strokeWidth:s,strokeStyle:a,roughness:l,opacity:d,groupIds:m,frameId:f,index:E,roundness:h,seed:b.seed??Ch(),version:b.version||1,versionNonce:b.versionNonce??0,isDeleted:!1,boundElements:g,updated:Bh(),link:x,locked:y,customData:b.customData}),rs=e=>nt(e.type,e),YP=e=>nt("embeddable",e),UP=e=>({...nt("iframe",e)}),XP=e=>ge({...nt("frame",e),type:"frame",name:e?.name||null},{}),jP=e=>ge({...nt("magicframe",e),type:"magicframe",name:e?.name||null},{}),Od=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Rd=e=>{let t=e.fontFamily||Th,n=e.fontSize||Ah,o=e.lineHeight||kh(t),i=or(e.text),r=Je(i,Ai({fontFamily:t,fontSize:n}),o),s=e.textAlign||Dh,a=e.verticalAlign||vh,l=Od({textAlign:s,verticalAlign:a},r),d={...nt("text",e),text:i,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??i,autoResize:e.autoResize??!0,lineHeight:o};return ge(d,{})},Oh=(e,t,n)=>{let{width:o,height:i}=Je(n,Ai(e),e.lineHeight);e.autoResize||(o=e.width);let{textAlign:r,verticalAlign:s}=e,a,l;if(r==="center"&&s===Lh.MIDDLE&&!e.containerId&&e.autoResize){let d=Je(e.text,Ai(e),e.lineHeight),c=Od(e,{width:o-d.width,height:i-d.height});a=e.x-c.x,l=e.y-c.y}else{let[d,c,u,p]=Y(e,t),[m,f,E,h]=zt(e,o,i,!1),g=(d-m)/2,x=(c-f)/2,y=(u-E)/2,b=(p-h)/2;[a,l]=Rh({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,g,x,y,b)}return{width:o,height:i,x:Number.isFinite(a)?a:e.x,y:Number.isFinite(l)?l:e.y}},Rh=(e,t,n,o,i,r,s,a)=>{let l=Math.cos(o),d=Math.sin(o);return e.e&&e.w?t+=i+s:e.e?(t+=i*(1+l),n+=i*d,t+=s*(1-l),n+=s*-d):e.w&&(t+=i*(1-l),n+=i*-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]},WP=(e,t,n,o=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(o=It(o,Ai(e),t?et(t,e):e.width));let i=Oh(e,n,o);return{text:o,...i}},VP=e=>({...nt(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure,lastCommittedPoint:null}),$P=e=>{let t={...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return bt(t)?{...t,polygon:e.polygon??!1}:t},Fd=e=>e.elbowed?{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...nt(e.type,e),points:e.points||[],lastCommittedPoint:null,startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},ZP=e=>({...nt("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var ft=new Map,zh=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,_h=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Yh=/^https:\/\/(?:www\.)?figma\.com/,Nd=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Uh=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Xh=/^(?:https?:\/\/)?forms\.microsoft\.com\//,Hd=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,jh=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,Wh=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Vh=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,zd=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,_d=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,$h=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,Zh=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[,o="0",i="0",r="0"]=n;return parseInt(o)*3600+parseInt(i)*60+parseInt(r)},ls=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),Yd=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),as=e=>`<html><body>${e}</body></html>`,nI=e=>{if(!e)return null;if(ft.has(e))return ft.get(e);let t=e,n=Yd.has(ds(e,Yd)||""),o="generic",i={w:560,h:840},r=e.match(zh);if(r?.[2]){let d=Zh(t),c=d>0?`&start=${d}`:"",u=e.includes("shorts");switch(o="video",r[1]){case"embed/":case"watch?v=":case"shorts/":e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${c}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${c}`;break}return i=u?{w:315,h:560}:{w:560,h:315},ft.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}}let s=e.match(_h);if(s?.[1]){let d=s?.[1],c=/^\d+$/.test(d)?void 0:new URIError("Invalid embed link format");return o="video",e=`https://player.vimeo.com/video/${d}?api=1`,i={w:560,h:315},ft.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,error:c,sandbox:{allowSameOrigin:n}}}if(e.match(Yh))return o="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,i={w:550,h:550},ft.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}};let l=e.match(Wh);if(l)return e=l[1]==="embed"?l[0]:l[0].replace("/v","/embed"),ft.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}};if(Xh.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),Hd.test(e)){let d=e.match(Hd)[1],c=ss(`https://twitter.com/x/status/${d}`),u={type:"document",srcdoc:p=>as(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${p}"><a href="${c}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,u),u}if(_d.test(e)){let[,d,c,u]=e.match(_d),p=ss(`https://reddit.com/r/${d}/comments/${c}/${u}`),m={type:"document",srcdoc:f=>as(`<blockquote class="reddit-embed-bq" data-embed-theme="${f}"><a href="${p}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return ft.set(t,m),m}if(Nd.test(e)){let[,d,c]=e.match(Nd),u=ss(`https://gist.github.com/${d}/${c}`),p={type:"document",srcdoc:()=>as(`
21
21
  <script src="${u}.js"><\/script>
22
22
  <style type="text/css">
23
23
  * { margin: 0px; }
24
24
  table, .gist { height: 100%; }
25
25
  .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
26
26
  </style>
27
- `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return ft.set(e,p),p}return ft.set(e,{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:o,type:i,sandbox:{allowSameOrigin:n}}},$P=e=>{let t;Gi(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=Lh.Helvetica,o=Bh({fontSize:n,fontFamily:i});return Bc({x:e.x+e.width/2,y:e.y+e.height/2,strokeColor:e.strokeColor!=="transparent"?e.strokeColor:"black",backgroundColor:"transparent",fontFamily:i,fontSize:n,text:Pt(t,o,e.width-20),textAlign:"center",verticalAlign:Ch.MIDDLE,angle:e.angle??0})},ss=(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},ZP=e=>{let t=e.match(Nh);if(t&&t.length===2)return t[1];let n=e.match(_h);if(n&&n.length===2)return n[1];let i=e.match(kh);if(i&&i.length===2)return i[1];if(kc.test(e))return`https://giphy.com/embed/${kc.exec(e)[1]}`;let o=e.match(Hh);return o&&o.length===2?o[1]:e},qP=(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(ss(e,n))return!0;return!1}}return!!ss(e,rs)};P();import{KEYS as To,invariant as Ao,toBrandedType as Uh}from"@excalidraw/common";import{pointFrom as zc}from"@excalidraw/math";var Nn=100,xn=100,dI=e=>{switch(e){case To.ARROW_UP:return"up";case To.ARROW_DOWN:return"down";case To.ARROW_RIGHT:return"right";case To.ARROW_LEFT:return"left";default:return"right"}},Yc=(e,t,n,i)=>{let o=[...n.values()].reduce((r,s)=>{let a;if(G(s)&&(a=s[e==="predecessors"?"startBinding":"endBinding"])&&s[e==="predecessors"?"endBinding":"startBinding"]?.elementId===t.id){let l=n.get(a.elementId);if(!l)return r;Ao(Le(l),"not an ExcalidrawBindableElement");let c=e==="predecessors"?s.points[s.points.length-1]:[0,0],d=ti(t,Ve(t,n),[c[0]+s.x,c[1]+s.y]);r.push({relative:l,heading:d})}return r},[]);switch(i){case"up":return o.filter(r=>pe(r.heading,He)).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,me)).map(r=>r.relative);case"left":return o.filter(r=>pe(r.heading,Oe)).map(r=>r.relative)}},as=(e,t,n)=>Yc("successors",e,t,n),ls=(e,t,n)=>Yc("predecessors",e,t,n),Xh=(e,t,n)=>{let i=xn+e.width;if(n==="up"||n==="down"){let a=Nn+e.height,l=e.x,c=e.x+e.width;if(t.every(d=>d.x+d.width<l||d.x>c))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(c=>c.y+c.height<a||c.y>l))return{x:(xn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Nn+e.height,l=(t.length===0,a),c=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*i:t.length/2*i*-1;return n==="up"?{x:c,y:l*-1}:{x:c,y:l}}let o=Nn+e.height,r=(t.length===0,xn+e.width),s=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*o:t.length/2*o*-1;return n==="left"?{x:r*-1,y:s}:{x:r,y:s}},Wh=(e,t,n,i)=>{let o=i.getNonDeletedElementsMap(),r=as(e,o,n),s=ls(e,o,n),a=Xh(e,[...r,...s],n),l=ns({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});Ao(Jo(l),"not an ExcalidrawFlowchartNodeElement");let c=Uc(e,l,n,t,i);return{nextNode:l,bindingArrow:c}},jh=(e,t,n,i,o)=>{let r=[];for(let s=0;s<o;s++){let a,l;if(n==="left"||n==="right"){let u=Nn*(o-1)+o*e.height,p=e.y+e.height/2-u/2,m=xn+e.width;n==="left"&&(m*=-1),a=e.x+m;let f=(Nn+e.height)*s;l=p+f}else{let u=xn*(o-1)+o*e.width,p=e.x+e.width/2-u/2,m=Nn+e.height;n==="up"&&(m*=-1),l=e.y+m;let f=(xn+e.width)*s;a=p+f}let c=ns({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});Ao(Jo(c),"not an ExcalidrawFlowchartNodeElement");let d=Uc(e,c,n,t,i);r.push(c),r.push(d)}return r},Uc=(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,c;switch(n){case"up":{l=t.x+t.width/2-r,c=t.y+t.height-s+6;break}case"down":{l=t.x+t.width/2-r,c=t.y-s-6;break}case"right":{l=t.x-r-6,c=t.y-s+t.height/2;break}case"left":{l=t.x+t.width-r+6,c=t.y-s+t.height/2;break}}let d=Gc({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:[zc(0,0),zc(l,c)],elbowed:!0}),u=o.getNonDeletedElementsMap();mn(d,e,"start",o),mn(d,t,"end",o);let p=new Map;p.set(e.id,e),p.set(t.id,t),p.set(d.id,d),Y.movePoints(d,o,new Map([[1,{point:d.points[1]}]]));let m=Dn(d,Uh(new Map([...u.entries(),[e.id,e],[t.id,t],[d.id,d]])),{points:d.points});return{...d,...m}},Hc=class{isExploring=!1;sameLevelNodes=[];sameLevelIndex=0;direction=null;visitedNodes=new Set;clear(){this.isExploring=!1,this.sameLevelNodes=[],this.sameLevelIndex=0,this.direction=null,this.visitedNodes.clear()}exploreByDirection(t,n,i){if(!Le(t))return null;if(i!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&i===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let o=[...as(t,n,i),...ls(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=>[...as(t,n,a),...ls(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}},_c=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}=Wh(t,n,i,o);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=i,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=jh(t,n,i,o,this.numberOfNodes);this.isCreatingChart=!0,this.direction=i,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);Ao(s&&Ri(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>Kt([a],s,r)||Zt(a,s,r))&&(this.pendingNodes=this.pendingNodes.map(a=>ye(a,r,{frameId:t.frameId})))}}clear(){this.isCreatingChart=!1,this.pendingNodes=null,this.direction=null,this.numberOfNodes=0}},uI=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{MIME_TYPES as Xc,SVG_NS as Vh}from"@excalidraw/common";var $h=e=>new Promise((t,n)=>{let i=new Image;i.onload=()=>{t(i)},i.onerror=o=>{n(o)},i.src=e}),EI=async({fileIds:e,files:t,imageCache:n})=>{let i=new Map,o=new Map;return await Promise.all(e.reduce((r,s)=>{let a=t[s];return a&&!i.has(s)?(i.set(s,!0),r.concat((async()=>{try{if(a.mimeType===Xc.binary)throw new Error("Only images can be added to ImageCache");let l=$h(a.dataURL),c={image:l,mimeType:a.mimeType};n.set(s,c);let d=await l;n.set(s,{...c,image:d})}catch{o.set(s,!0)}})())):r},[])),{imageCache:n,updatedFiles:i,erroredFiles:o}},gI=e=>e.filter(t=>zt(t)),Zh=e=>e?.nodeName.toLowerCase()==="svg",xI=e=>{let t=new DOMParser().parseFromString(e,Xc.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!Zh(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",Vh);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();import{pointCenter as qh,normalizeRadians as vo,pointFrom as re,pointRotateRads as it}from"@excalidraw/math";import{MIN_FONT_SIZE as ds,SHIFT_LOCKING_ANGLE as Lo,rescalePoints as Wc,getFontString as Do}from"@excalidraw/common";var CI=(e,t,n,i,o,r,s,a,l,c,d)=>{let u=i.getNonDeletedElementsMap();if(n.length===1){let[p]=n;if(t==="rotation")G(p)||(Kh(p,i,a,l,o),Ue(p,i));else if(t){let m=n[0].id,f=u.get(m),E=e.get(m);if(f&&E){let{nextWidth:h,nextHeight:g}=nE(f,E,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});tE(h,g,f,E,e,i,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return ie(p)&&Ue(p,i),!0}else if(n.length>1){if(t==="rotation")return Jh(e,n,i,a,l,o,c,d),!0;if(t){let{nextWidth:p,nextHeight:m,flipByX:f,flipByY:E,originalBoundingBox:h}=iE(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return oE(n,u,t,i,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:E,nextWidth:p,nextHeight:m,originalBoundingBox:h}),!0}}return!1},Kh=(e,t,n,i,o)=>{let[r,s,a,l]=H(e,t.getNonDeletedElementsMap()),c=(r+a)/2,d=(s+l)/2,u;$(e)?u=0:(u=5*Math.PI/2+Math.atan2(i-d,n-c),o&&(u=u+Lo/2,u=u-u%Lo),u=vo(u));let p=It(e);if(t.mutateElement(e,{angle:u}),p){let m=t.getElement(p);m&&!_(e)&&t.mutateElement(m,{angle:u})}},jc=(e,t,n,i)=>X(e)||Se(e)?{points:Wc(0,t,Wc(1,n,e.points,i),i)}:{},us=(e,t,n)=>{let i=e.width;if(de(e)){let s=Ce(e,t);s&&(i=Je(s,e))}let r=e.fontSize*(n/i);return r<ds?null:{size:r}},Qh=(e,t,n,i,o,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),c=us(t,a,l);if(c!==null){if(i.includes("n")||i.includes("s")){let d=re(e.x,e.y),u=cs(d,e.width,e.height,l,s,e.angle,i,!1,o);n.mutateElement(t,{fontSize:c.size,width:l,height:s,x:u.x,y:u.y});return}if(i==="e"||i==="w"){let d=Ni(Do({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(d,r),p=Pt(t.originalText,Do(t),Math.abs(u)),m=Qe(p,Do(t),t.lineHeight),f=m.height,E=re(e.x,e.y),h=cs(E,e.width,e.height,u,f,t.angle,i,!1,o),g={width:Math.abs(u),height:Math.abs(m.height),x:h.x,y:h.y,text:p,autoResize:!1};n.mutateElement(t,g)}}},Jh=(e,t,n,i,o,r,s,a)=>{let l=n.getNonDeletedElementsMap(),c=5*Math.PI/2+Math.atan2(o-a,i-s);r&&(c+=Lo/2,c-=c%Lo);for(let d of t)if(!$(d)){let[u,p,m,f]=H(d,l),E=(u+m)/2,h=(p+f)/2,g=e.get(d.id)?.angle??d.angle,[x,y]=it(re(E,h),re(s,a),c+g-d.angle),b=G(d)?{points:qa(d,l)}:{x:d.x+(x-E),y:d.y+(y-h),angle:vo(c+g)};n.mutateElement(d,b),Ue(d,n,{simultaneouslyUpdated:t});let w=W(d,l);w&&!_(d)&&n.mutateElement(w,{x:w.x+(x-E),y:w.y+(y-h),angle:vo(c+g)})}n.triggerUpdate()},BI=(e,t,n,i,o)=>{let[r,s,a,l]=t.length===1?H(t[0],n):tt(t),c=(r+a)/2,d=(s+l)/2,u=t.length===1?t[0].angle:0;switch([i,o]=it(re(i,o),re(c,d),-u),e){case"n":return it(re(i-(r+a)/2,o-s),re(0,0),u);case"s":return it(re(i-(r+a)/2,o-l),re(0,0),u);case"w":return it(re(i-r,o-(s+l)/2),re(0,0),u);case"e":return it(re(i-a,o-(s+l)/2),re(0,0),u);case"nw":return it(re(i-r,o-s),re(0,0),u);case"ne":return it(re(i-a,o-s),re(0,0),u);case"sw":return it(re(i-r,o-l),re(0,0),u);case"se":return it(re(i-a,o-l),re(0,0),u);default:return[0,0]}},GI=(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"},eE=(e,t,n)=>{if(n)return"center";if(t)switch(e){case"n":return"south-side";case"e":return"west-side";case"s":return"north-side";case"w":return"east-side";case"ne":return"bottom-left";case"nw":return"bottom-right";case"se":return"top-left";case"sw":return"top-right"}return["e","se","s"].includes(e)?"top-left":["n","nw","w"].includes(e)?"bottom-right":e==="ne"?"bottom-left":"top-right"},cs=(e,t,n,i,o,r,s,a,l)=>{let c=eE(s,a,l),[d,u]=e;switch(c){case"top-left":return{x:d+(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:d+(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:d+(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:d+(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:d-(i-t)/2,y:u-(o-n)/2};case"east-side":return{x:d+(t-i)/2*(Math.cos(r)+1),y:u+(t-i)/2*Math.sin(r)+(n-o)/2};case"west-side":return{x:d+(t-i)/2*(1-Math.cos(r)),y:u+(i-t)/2*Math.sin(r)+(n-o)/2};case"north-side":return{x:d+(t-i)/2+(n-o)/2*Math.sin(r),y:u+(o-n)/2*(Math.cos(r)-1)};case"south-side":return{x:d+(t-i)/2+(o-n)/2*Math.sin(r),y:u+(n-o)/2*(Math.cos(r)+1)}}},tE=(e,t,n,i,o,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:c=!1}={})=>{if(ie(n)&&ie(i))return Qh(i,n,r,s,c,e,t);let d={},u=r.getNonDeletedElementsMap(),p=W(n,u);if(p){let h=o.get(p.id);if(h&&(d={fontSize:h.fontSize}),l){let g={...n,width:e,height:t},x=us(p,u,Je(g,p));if(x===null)return;d={fontSize:x.size}}else{let g=pa(Do(p),p.lineHeight),x=ma(p.fontSize,p.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let m=jc(i,e,t,!0),f=re(i.x,i.y);if(X(i)){let[h,g]=he(i,o);f=re(h,g)}let E=cs(f,i.width,i.height,e,t,i.angle,s,l,c);if(X(i)&&m.points){let h=i.x-f[0],g=i.y-f[1];E.x+=h,E.y+=g;let x=m.points[0][0],y=m.points[0][1];E.x+=x,E.y+=y,m.points=m.points.map(b=>re(b[0]-x,b[1]-y))}if(e<0&&(E.x=E.x+e),t<0&&(E.y=E.y+t),"scale"in n&&"scale"in i&&r.mutateElement(n,{scale:[(Math.sign(e)||i.scale[0])*i.scale[0],(Math.sign(t)||i.scale[1])*i.scale[1]]}),_(n)&&p&&l){let h=e/n.width*p.fontSize;if(h<ds)return;d.fontSize=h}if(e!==0&&t!==0&&Number.isFinite(E.x)&&Number.isFinite(E.y)){let h={...E,width:Math.abs(e),height:Math.abs(t),...m};r.mutateElement(n,h,{informMutation:a,isDragging:!1}),p&&d!=null&&r.mutateElement(p,{fontSize:d.fontSize}),un(n,r,s,l),Ue(n,r,{newSize:{width:e,height:t}})}},nE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,c,d]=Nt(t,t.width,t.height,!0),u=re(a,l),p=re(c,d),m=qh(u,p),f=it(re(i,o),m,-t.angle),[E,h,g,x]=Nt(e,e.width,e.height,!0),y=g-E,b=x-h,w=p[0]-u[0],I=p[1]-u[1],M=w/y,D=I/b;n.includes("e")&&(M=(f[0]-u[0])/y),n.includes("s")&&(D=(f[1]-u[1])/b),n.includes("w")&&(M=(p[0]-f[0])/y),n.includes("n")&&(D=(p[1]-f[1])/b);let T=e.width*M,F=e.height*D;if(s&&(T=2*T-t.width,F=2*F-t.height),r){let C=Math.abs(T)/t.width,k=Math.abs(F)/t.height;if(n.length===1&&(F*=C,T*=k),n.length===2){let L=Math.max(C,k);T=t.width*L*Math.sign(T),F=t.height*L*Math.sign(F)}}return{nextWidth:T,nextHeight:F}},iE=(e,t,n,i,o,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(L=>t.get(L.id)),c=l.reduce((L,j)=>{if(!X(j))return L;let N=It(j);if(!N)return L;let te=t.get(N)??null;return de(te)?[...L,{...te,...Y.getBoundTextElementPosition(j,te,n)}]:L},[]),d=Ct(l.map(L=>L).concat(c)),{minX:u,minY:p,maxX:m,maxY:f,midX:E,midY:h}=d,g=m-u,x=f-p,y={ne:[u,f],se:[u,p],sw:[m,p],nw:[m,f],e:[u,p+x/2],w:[m,p+x/2],n:[u+g/2,f],s:[u+g/2,p]},[b,w]=a?[E,h]:y[i],I=a?2:1,M=Math.max(Math.abs(o-b)/g||0,Math.abs(r-w)/x||0)*I,D=i.includes("e")||i.includes("w")?Math.abs(o-b)*I:g,T=i.includes("n")||i.includes("s")?Math.abs(r-w)*I:x;s&&(D=g*M*Math.sign(o-b),T=x*M*Math.sign(r-w));let F={ne:[o<b,r>w],se:[o<b,r<w],sw:[o>b,r<w],nw:[o>b,r>w],e:[o<b,!1],w:[o>b,!1],n:[!1,r>w],s:[!1,r<w]},[C,k]=F[i].map(L=>L);return{originalBoundingBox:d,nextWidth:D,nextHeight:T,flipByX:C,flipByY:k}},oE=(e,t,n,i,o,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1,flipByX:a=!1,flipByY:l=!1,nextHeight:c,nextWidth:d,originalBoundingBox:u}={})=>{if(d===void 0&&c===void 0&&a===void 0&&l===void 0||c===0||d===0)return;o||(o=t);let p=e.reduce((I,M)=>{let D=o.get(M.id);return D&&I.push({orig:D,latest:M}),I},[]),m;if(u)m=u;else{let I=p.reduce((M,{orig:D})=>{if(!X(D))return M;let T=It(D);if(!T)return M;let F=o.get(T)??null;return de(F)?[...M,{...F,...Y.getBoundTextElementPosition(D,F,t)}]:M},[]);m=Ct(p.map(({orig:M})=>M).concat(I))}let{minX:f,minY:E,maxX:h,maxY:g,midX:x,midY:y}=m,b=h-f,w=g-E;if(d===void 0&&c===void 0&&(d=b,c=w),r&&(d===void 0?d=c*(b/w):c===void 0?c=d*(w/b):Math.abs(d/c-b/w)>.001&&(d=c*(b/w))),d&&c){let I=n.includes("e")||n.includes("w")?Math.abs(d)/b:1,M=n.includes("n")||n.includes("s")?Math.abs(c)/w:1,D;n.length===1?D=n.includes("e")||n.includes("w")?I:M:D=Math.max(Math.abs(d)/b||0,Math.abs(c)/w||0);let T={ne:[f,g],se:[f,E],sw:[h,E],nw:[h,g],e:[f,E+w/2],w:[h,E+w/2],n:[f+b/2,g],s:[f+b/2,E]},[F,C]=s?[x,y]:T[n],k=r||p.some(S=>S.latest.angle!==0||ie(S.latest)||gl(S.latest));k&&(I=D,M=D);let[L,j]=[a?-1:1,l?-1:1],N=[];for(let{orig:S,latest:Q}of p){if(ie(S)&&de(S))continue;let V=S.width*I,ne=S.height*M,tn=vo(S.angle*L*j),ot=X(S)||Se(S),wn=S.x-F,Go=S.y-C,pi=a&&!ot?V:0,zn=l&&!ot?ne:0,Oo=F+L*(wn*I+pi),mi=C+j*(Go*M+zn),nn=jc(S,V*L,ne*j,!1),ge={x:Oo,y:mi,width:V,height:ne,angle:tn,...nn};if(G(S)&&(S.startBinding&&(ge.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&&(ge.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&&nn.points&&(ge.fixedSegments=S.fixedSegments.map(De=>({...De,start:nn.points[De.index-1],end:nn.points[De.index]})))),xe(S)&&(ge.scale=[S.scale[0]*L,S.scale[1]*j]),ie(S)){let De=us(S,t,V);if(!De)return;ge.fontSize=De.size}let on=o.get(It(S)??"");if(on)if(k){let De=on.fontSize*D;if(De<ds)return;ge.boundTextFontSize=De}else ge.boundTextFontSize=on.fontSize;N.push({element:Q,update:ge})}let te=N.map(({element:S})=>S);for(let{element:S,update:{boundTextFontSize:Q,...V}}of N){let{width:ne,height:tn,angle:ot}=V;i.mutateElement(S,V),Ue(S,i,{simultaneouslyUpdated:te,newSize:{width:ne,height:tn}});let wn=W(S,t);wn&&Q&&(i.mutateElement(wn,{fontSize:Q,angle:X(S)?void 0:ot}),un(S,i,n,!0))}i.triggerUpdate()}};P();import{pointFrom as $e,pointOnLineSegment as Qc,pointRotateRads as Bo}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as gs}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as ms,isAndroid as rE,isIOS as sE}from"@excalidraw/common";import{pointFrom as Vc,pointRotateRads as aE}from"@excalidraw/math";var $c={mouse:8,pen:16,touch:28},lE=16,qc={e:!0,s:!0,n:!0,w:!0},HI={e:!0,s:!0,n:!0,w:!0},_I={e:!0,s:!0,n:!0,w:!0,rotation:!0},Zc={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},ps={e:!0,s:!0,n:!0,w:!0},Ot=(e,t,n,i,o,r,s)=>{let[a,l]=aE(Vc(e+n/2,t+i/2),Vc(o,r),s);return[a-n/2,l-i/2,n,i]},Co=e=>!(e.viewport.isMobile||e.isTouchScreen&&(rE||sE)),fs=e=>Co(e)?qc:{},hs=([e,t,n,i,o,r],s,a,l,c={},d=4,u=ms)=>{let p=$c[l],m=p/a.value,f=p/a.value,E=p/a.value,h=p/a.value,g=n-e,x=i-t,y=d/a.value,b=(p-u*2)/(2*a.value),w={nw:c.nw?void 0:Ot(e-y-E+b,t-y-h+b,m,f,o,r,s),ne:c.ne?void 0:Ot(n+y-b,t-y-h+b,m,f,o,r,s),sw:c.sw?void 0:Ot(e-y-E+b,i+y-b,m,f,o,r,s),se:c.se?void 0:Ot(n+y-b,i+y-b,m,f,o,r,s),rotation:c.rotation?void 0:Ot(e+g/2-m/2,t-y-h+b-lE/a.value,m,f,o,r,s)},I=5*$c.mouse/a.value;return Math.abs(g)>I&&(c.n||(w.n=Ot(e+g/2-m/2,t-y-h+b,m,f,o,r,s)),c.s||(w.s=Ot(e+g/2-m/2,i+y-b,m,f,o,r,s))),Math.abs(x)>I&&(c.w||(w.w=Ot(e-y-E+b,t+x/2-f/2,m,f,o,r,s)),c.e||(w.e=Ot(n+y-b,t+x/2-f/2,m,f,o,r,s))),w},Kc=(e,t,n,i="mouse",o=qc)=>{if(e.locked||G(e))return{};if(e.type==="freedraw"||X(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?o=ps:s[0]>0&&s[1]<0?o=Zc:s[0]>0&&s[1]>0?o=ps:s[0]<0&&s[1]>0?o=Zc:s[0]<0&&s[1]<0&&(o=ps)}}else $(e)&&(o={...o,rotation:!0});let r=X(e)?ms+8:xe(e)?0:ms;return hs(H(e,n,!0),e.angle,t,i,o,r,xe(e)?0:void 0)},YI=(e,t)=>{if(t.selectedLinearElement?.isEditing)return!1;if(e.length>1)return!0;let n=e[0];return G(n)?!1:X(n)?n.points.length>2:!0};var xs=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],cE=(e,t,n,i,o,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...c}=Kc(e,r,t,s,fs(a));if(l&&xs(l,i,o))return"rotation";let d=Object.keys(c).filter(u=>{let p=c[u];return p?xs(p,i,o):!1});if(d.length>0)return d[0];if(Co(a)){let[u,p,m,f,E,h]=H(e,t);if(!(X(e)&&e.points.length<=2)){let g=xe(e)?0:gs/r.value,x=gs/r.value,y=Jc($e(u-g,p-g),$e(m+g,f+g),$e(E,h),e.angle);for(let[b,w]of Object.entries(y))if(Qc($e(i,o),w,x))return b}}return!1},qI=(e,t,n,i,o,r,s,a)=>e.reduce((l,c)=>{if(l)return l;let d=cE(c,s,t,n,i,o,r,a);return d?{element:c,transformHandleType:d}:null},null),KI=([e,t,n,i],o,r,s,a,l)=>{let c=hs([e,t,n,i,(e+n)/2,(t+i)/2],0,s,a,fs(l)),d=Object.keys(c).find(u=>{let p=c[u];return p&&xs(p,o,r)});if(d)return d;if(Co(l)){let u=(e+n)/2,p=(t+i)/2,m=gs/s.value,f=Jc($e(e-m,t-m),$e(n+m,i+m),$e(u,p),0);for(let[E,h]of Object.entries(f))if(Qc($e(o,r),h,m))return E}return!1},Es=["ns","nesw","ew","nwse"],dE=(e,t)=>{let n=Es.indexOf(e);if(n>=0){let i=Math.round(t/(Math.PI/4));e=Es[(n+i)%Es.length]}return e},QI=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=dE(o,t.angle)),o?`${o}-resize`:""},Jc=([e,t],[n,i],o,r)=>{let s=Bo($e(e,t),o,r),a=Bo($e(n,t),o,r),l=Bo($e(e,i),o,r),c=Bo($e(n,i),o,r);return{n:[s,a],e:[a,c],s:[c,l],w:[l,s]}};P();var nS=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||pt(t,e).length));P();import{arrayToMap as td,findIndex as nd,findLastIndex as id}from"@excalidraw/common";var ws=(e,t)=>e.frameId===t||e.id===t,od=(e,t,n)=>{let i=[],o=[],r=null,s=-1,a=td(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),[])},ed=(e,t,n,i)=>{if("containerId"in e&&e.containerId){let o=i.getElement(e.containerId);if(o)return n==="left"?Math.min(t.indexOf(o),t.indexOf(e)):Math.max(t.indexOf(o),t.indexOf(e))}else{let o=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(o){let r=i.getElement(o);if(r)return n==="left"?Math.min(t.indexOf(r),t.indexOf(e)):Math.max(t.indexOf(r),t.indexOf(e))}}},pE=(e,t)=>{let n=-1,i=-1;return e.forEach((o,r)=>{ws(o,t)&&(n===-1&&(n=r),i=r)}),n===-1?[]:e.slice(n,i+1)},mE=(e,t,n,i,o,r)=>{let s=t[n],a=p=>p.isDeleted?!1:o?p.frameId===o:e.editingGroupId?p.groupIds.includes(e.editingGroupId):!0,l=i==="left"?id(t,p=>a(p),Math.max(0,n-1)):nd(t,p=>a(p),n+1),c=t[l];if(!c)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===c?.groupIds.join(""))return ed(c,t,i,r)??l;if(!c?.groupIds.includes(e.editingGroupId))return-1}if(!o&&(c.frameId||$(c))){let p=pE(t,c.frameId||c.id);return i==="left"?t.indexOf(p[0]):t.indexOf(p[p.length-1])}if(!c.groupIds.length)return ed(c,t,i,r)??l;let d=e.editingGroupId?c.groupIds[c.groupIds.indexOf(e.editingGroupId)-1]:c.groupIds[c.groupIds.length-1],u=Ae(t,d);return u.length?i==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},rd=(e,t)=>t.reduce((n,i)=>{let o=e[i];return n.set(o.id,o),n},new Map),sd=(e,t,n,i)=>{let o=od(e,t),r=rd(e,o),s=uE(o);n==="right"&&(s=s.reverse());let a=new Set(o.filter(l=>$(e[l])).map(l=>e[l].id));return s.forEach((l,c)=>{let d=l[0],u=l[l.length-1],p=n==="left"?d:u,m=l.some(y=>{let b=e[y];return b.frameId&&a.has(b.frameId)})?null:e[p]?.frameId,f=mE(t,e,p,n,m,i);if(f===-1||p===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,d),h=e.slice(d,u+1),g=n==="left"?e.slice(f,d):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...E,...h,...g,...x]:[...E,...g,...h,...x]}),ui(e,r),e},ad=(e,t,n,i,o)=>{let r=od(e,t,o),s=rd(e,r),a=[],l,c;if(n==="left"){if(i)l=nd(e,f=>ws(f,i));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;c=r[r.length-1]}else{if(i)c=id(e,f=>ws(f,i));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;c=e.indexOf(f[f.length-1])}else c=e.length-1;l=r[0]}l===-1&&(l=0);for(let f=l;f<c+1;f++)r.includes(f)||a.push(e[f]);let d=Array.from(s.values()),u=e.slice(0,l),p=e.slice(c+1),m=n==="left"?[...u,...d,...a,...p]:[...u,...a,...d,...p];return ui(m,s),m};function ld(e,t,n,i){let o=td(pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let c of e)o.has(c.id)&&$(c)&&s.add(c.id);for(let c of e)if(o.has(c.id))if($(c)||c.frameId&&s.has(c.frameId))r.regularElements.push(c);else if(!c.frameId)r.regularElements.push(c);else{let d=r.frameChildren.get(c.frameId)||[];d.push(c),r.frameChildren.set(c.frameId,d)}let a=e,l=Array.from(r.frameChildren.entries());for(let[c,d]of l)a=i(e,t,n,c,d);return i(a,t,n,null,r.regularElements)}var dS=(e,t,n)=>sd(e,t,"left",n),uS=(e,t,n)=>sd(e,t,"right",n),pS=(e,t)=>ld(e,t,"left",ad),mS=(e,t)=>ld(e,t,"right",ad);var wS=e=>e.reduce((t,n)=>t+n.version,0),oc=e=>{let t=5381;for(let n of fE(e))t=(t<<5)+t+n.versionNonce;return t>>>0},rc=e=>{let t=5381;for(let n=0;n<e.length;n++){let i=e.charCodeAt(n);t=(t<<5)+t+i}return t>>>0},yS=e=>e.filter(t=>!t.isDeleted&&!ql(t)),hE=e=>e.filter(t=>!t.isDeleted),bS=e=>!e.isDeleted,ys=e=>hE(e).map(t=>Ko(t.type)?{...t,lastCommittedPoint:null}:t),PS=e=>ys(e),IS=e=>ys(e),SS=e=>ys(e);export{fn as AppStateDelta,ee as BASE_PADDING,Rp as BINDING_HIGHLIGHT_THICKNESS,$t as BindableElement,Vt as BoundElement,Fe as CaptureUpdateAction,Vb as DEFAULT_LINK_SIZE,qc as DEFAULT_OMIT_SIDES,q as Delta,Zr as DurableIncrement,Ur as ElementBounds,hn as ElementsDelta,qr as EphemeralIncrement,oe as FIXED_BINDING_DISTANCE,_c as FlowChartCreator,Hc as FlowChartNavigator,we as HEADING_DOWN,Oe as HEADING_LEFT,me as HEADING_RIGHT,He as HEADING_UP,Um as IMAGE_INVERT_FILTER,gf as INVISIBLY_SMALL_ELEMENT_SIZE,Qr as InvalidFractionalIndexError,Y as LinearElementEditor,Ie as MINIMAL_CROP_SIZE,_I as OMIT_SIDES_FOR_FRAME,HI as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Io as Scene,be as ShapeCache,ec as Store,ci as StoreChange,Kr as StoreDelta,wo as StoreIncrement,Jt as StoreSnapshot,Ve as aabbForElement,Cm as addElementsToFrame,jh as addNewNodes,Uy as addToGroup,K0 as alignElements,$p as avoidRectangularCorner,bl as bindElementsToFramesAfterDuplication,mn as bindLinearElement,Tr as bindOrUnbindLinearElement,zp as bindOrUnbindLinearElements,Pr as bindPointToSnapToElementOutline,no as bindingBorderTest,Za as bindingProperties,Ra as bumpVersion,ja as calculateFixedPointForElbowArrowBinding,Ax as canApplyRoundnessTypeToElement,la as canBecomePolygon,Rl as canChangeRoundness,xh as canCreateLinkFromElements,i0 as canHaveArrowheads,Co as canResizeFromSides,Sn as charWidth,PS as clearElementsForDatabase,IS as clearElementsForExport,SS as clearElementsForLocalStorage,pe as compareHeading,xa as computeBoundTextPosition,sr as computeContainerDimensionForBoundText,jx as containsCJK,$P as createPlaceholderEmbeddableLabel,os as createSrcDoc,ux as cropElement,In as deconstructDiamondElement,Ci as deconstructLinearOrFreeDrawElement,Pn as deconstructRectanguloidElement,$r as deepCopyElement,yP as defaultGetElementLinkFromSelection,zx as detectLineHeight,_t as distanceToElement,iP as distributeElements,pn as doBoundsIntersect,hP as dragNewElement,mP as dragSelectedElements,Af as duplicateElement,u1 as duplicateElements,Yy as editGroupForSelectedElement,fe as elementCenterPoint,Zt as elementOverlapsWithFrame,Eo as elementWithCanvasCache,Kt as elementsAreInFrameBounds,El as elementsAreInSameGroup,qP as embeddableURLValidator,wl as excludeElementsInFramesFromSelection,Mb as filterElementsEligibleAsFrameChildren,py as fixBindingsAfterDeletion,$a as fixDuplicatedBindingsAfterDuplication,pr as flipHeading,Cb as frameAndChildrenSelectedTogether,Ol as generateFreeDrawShape,ta as generateLinearCollisionShape,ke as generateRoughOptions,ma as getApproxMinLineHeight,pa as getApproxMinLineWidth,qa as getArrowLocalFixedPoints,uf as getArrowheadAngle,Hr as getArrowheadPoints,df as getArrowheadSize,W as getBoundTextElement,It as getBoundTextElementId,iw as getBoundTextElementPosition,ei as getBoundTextMaxHeight,Je as getBoundTextMaxWidth,Xr as getBoundsFromPoints,ct as getCenterForBounds,R0 as getClosestElementBounds,Ct as getCommonBoundingBox,tt as getCommonBounds,tw as getContainerCenter,ar as getContainerCoords,Ce as getContainerElement,vt as getContainingFrame,yt as getCornerRadius,Wi as getCubicBezierCurveBound,QI as getCursorForResizingElement,km as getDefaultFrameName,Dx as getDefaultRoundnessTypeForElement,Bi as getDiamondPoints,fP as getDragOffsetXY,O0 as getDraggedElementsBounds,H as getElementAbsoluteCoords,he as getElementBounds,kr as getElementLineSegments,Lr as getElementPointsCoords,_l as getElementShape,qI as getElementWithTransformHandleType,Pl as getElementsCompletelyInFrame,Ae as getElementsInGroup,Sb as getElementsInNewFrame,Ib as getElementsInResizingFrame,gb as getElementsIntersectingFrame,Lb as getElementsOverlappingFrame,Or as getElementsWithinSelection,VP as getEmbedLink,px as getFlipAdjustedCropPosition,qt as getFrameChildren,vm as getFrameLikeElements,vb as getFrameLikeTitle,Vm as getFreeDrawPath2D,$m as getFreeDrawSvgPath,eo as getGlobalFixedPointForBindableElement,Jp as getGlobalFixedPoints,Oa as getHeadingForElbowArrowSnap,Wt as getHoveredElementForBinding,gI as getInitializedImageElements,zi as getLineHeightInPx,Ht as getLineWidth,Lx as getLinearElementSubType,dI as getLinkDirectionFromKey,bP as getLinkIdAndTypeFromSelection,il as getLockedLinearCursorAlignSize,wu as getMaxCharWidth,Wy as getMaximumGroups,_x as getMinCharWidth,si as getMinMaxXYFromCurvePathOps,Ni as getMinTextElementWidth,xl as getNewGroupIdsForDuplication,hE as getNonDeletedElements,hl as getNonDeletedGroupIds,W0 as getNormalizedDimensions,Rn as getObservedAppState,fs as getOmitSidesForDevice,Ox as getOriginalContainerHeightFromCache,Wr as getPerfectElementSize,ls as getPredecessors,G0 as getRectangleBoxAbsoluteCoords,Xm as getRenderOpacity,GI as getResizeArrowDirection,BI as getResizeOffsetXY,Nt as getResizedElementAbsoluteCoords,Pb as getRootElements,wS as getSceneVersion,pt as getSelectedElements,uo as getSelectedElementsByGroup,Gr as getSelectedGroupForElement,Sm as getSelectedGroupIdForElement,Pm as getSelectedGroupIds,ob as getSelectionStateForElements,cy as getSuggestedBindingsForArrows,ib as getTargetElements,Gm as getTargetFrame,nw as getTextElementAngle,aw as getTextFromElements,xu as getTextHeight,fa as getTextWidth,KI as getTransformHandleTypeFromCoords,Kc as getTransformHandles,hs as getTransformHandlesFromCoords,Qs as getUncroppedImageElement,jo as getUncroppedWidthAndHeight,tb as getVisibleAndNonSelectedElements,yS as getVisibleElements,k0 as getVisibleSceneBounds,bb as groupByFrameLikes,wb as groupsAreAtLeastIntersectingTheFrame,yb as groupsAreCompletelyOutOfFrame,un as handleBindTextResize,Qb as hasBackground,st as hasBoundTextElement,Jb as hasStrokeColor,t0 as hasStrokeStyle,e0 as hasStrokeWidth,oc as hashElementsVersion,rc as hashString,Ge as headingForPoint,ti as headingForPointFromElement,et as headingForPointIsHorizontal,Re as headingIsHorizontal,Bw as headingIsVertical,ep as hitElementBoundText,Ju as hitElementBoundingBox,Tw as hitElementBoundingBoxOnly,Qu as hitElementItself,Mn as intersectElementWithLineSegment,Tx as isArrowBoundToElement,_ as isArrowElement,Le as isBindableElement,Qo as isBindingElement,uu as isBindingElementType,Mr as isBindingEnabled,de as isBoundToContainer,vx as isBounds,xb as isCursorInFrame,du as isCurvedArrow,G as isElbowArrow,X0 as isElementCompletelyInViewport,Fr as isElementContainingFrame,Sl as isElementInFrame,Im as isElementInGroup,yl as isElementInViewport,Gn as isElementIntersectingFrame,PP as isElementLink,ia as isEmbeddableElement,Mx as isExcalidrawElement,Qn as isFixedPointBinding,Jo as isFlowchartNodeElement,Ri as isFrameElement,$ as isFrameLikeElement,Se as isFreeDrawElement,lu as isFreeDrawElementType,Zh as isHTMLSVGElement,Gi as isIframeElement,Oi as isIframeLikeElement,xe as isImageElement,gl as isInGroup,zt as isInitializedImageElement,ql as isInvisiblySmallElement,cn as isLineElement,X as isLinearElement,Xa as isLinearElementSimpleAndAlreadyBound,Ko as isLinearElementType,oa as isMagicFrameElement,Nx as isMeasureTextSupported,uI as isNodeInFlowchart,bS as isNonDeletedElement,ln as isPathALoop,Sa as isPointInElement,Sx as isRectangularElement,ra as isRectanguloidElement,bm as isSelectedViaGroup,cu as isSharpArrow,Ix as isSimpleArrow,nb as isSomeElementSelected,pu as isTextBindableContainer,ie as isTextElement,sa as isUsingAdaptiveRadius,aa as isUsingProportionalRadius,Cx as isValidPolygon,sw as isValidTextContainer,$h as loadHTMLImageElement,Br as makeNextSelectedElementIds,so as maxBindingGap,dy as maybeBindLinearElement,ZP as maybeParseEmbedSrc,Ya as maybeSuggestBindingsForLinearElementAtCoords,us as measureFontSizeFromWidth,Qe as measureText,pS as moveAllLeft,mS as moveAllRight,dS as moveOneLeft,uS as moveOneRight,ye as mutateElement,Gc as newArrowElement,ns as newElement,Me as newElementWith,GP as newEmbeddableElement,RP as newFrameElement,NP as newFreeDrawElement,OP as newIframeElement,HP as newImageElement,zP as newLinearElement,kP as newMagicFrameElement,Bc as newTextElement,Kl as normalizeElementOrder,Ar as normalizeFixedPoint,xI as normalizeSVG,tr as normalizeText,po as omitGroupsContainingFrameLikes,Lm as omitPartialGroups,pc as orderByFractionalIndex,Jn as originalContainerCache,IP as parseElementLinkFromURL,Tu as parseTokens,Gl as pathsCache,An as pointInsideBounds,ga as redrawTextBoundingBox,FP as refreshTextDimensions,Bm as removeAllElementsFromFrame,Il as removeElementsFromFrame,Xy as removeFromSelectedGroups,Zb as renderElement,$b as renderSelectionElement,Tb as replaceAllElementsInFrame,jc as rescalePointsInElement,da as resetOriginalContainerCache,oE as resizeMultipleElements,tE as resizeSingleElement,Qh as resizeSingleTextElement,cE as resizeTest,ym as selectGroup,ml as selectGroupsForSelectedElements,fl as selectGroupsFromGivenElements,Hx as setCustomTextMetricsProvider,ow as shouldAllowVerticalAlign,Db as shouldApplyFrameClip,ly as shouldEnableBindingForPointerEvent,YI as shouldShowBoundingBox,Xi as shouldTestInside,nS as showSelectedShapeActions,Zp as snapToMid,rw as suppportsHorizontalAlign,Ff as syncInvalidIndices,ic as syncInvalidIndicesImmutable,ui as syncMovedIndices,nl as toggleLinePolygonState,n0 as toolIsArrow,CI as transformElements,uy as updateBindings,Ue as updateBoundElements,Dn as updateElbowArrowPoints,Ab as updateFrameMembershipOfSelectedElements,EI as updateImageCache,ca as updateOriginalContainerCache,Ga as validateElbowPoints,kf as validateFractionalIndices,Mt as vectorToHeading,Pt as wrapText};
27
+ `),intrinsicSize:{w:550,h:720},sandbox:{allowSameOrigin:n}};return ft.set(e,p),p}return ft.set(e,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}},oI=e=>{let t;Oo(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),o=Fh.Helvetica,i=Hh({fontSize:n,fontFamily:o});return Rd({x:e.x+e.width/2,y:e.y+e.height/2,strokeColor:e.strokeColor!=="transparent"?e.strokeColor:"black",backgroundColor:"transparent",fontFamily:o,fontSize:n,text:It(t,i,e.width-20),textAlign:"center",verticalAlign:Nh.MIDDLE,angle:e.angle??0})},ds=(e,t)=>{try{let{hostname:n}=new URL(e),o=n.replace(/^www\./,"");if(t instanceof Set){if(ls.has(o))return o;let r=o.replace(/^([^.]+)/,"*");return ls.has(r)?r:null}let i=t.replace(/^www\./,"");if(o===i)return i}catch{}return null},iI=e=>{let t=e.match(jh);if(t&&t.length===2)return t[1];let n=e.match($h);if(n&&n.length===2)return n[1];let o=e.match(Uh);if(o&&o.length===2)return o[1];if(zd.test(e))return`https://giphy.com/embed/${zd.exec(e)[1]}`;let i=e.match(Vh);return i&&i.length===2?i[1]:e},rI=(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(ds(e,n))return!0;return!1}}return!!ds(e,ls)};P();import{KEYS as Di,invariant as vi,toBrandedType as qh}from"@excalidraw/common";import{pointFrom as Ud}from"@excalidraw/math";var Hn=100,bn=100,wI=e=>{switch(e){case Di.ARROW_UP:return"up";case Di.ARROW_DOWN:return"down";case Di.ARROW_RIGHT:return"right";case Di.ARROW_LEFT:return"left";default:return"right"}},Wd=(e,t,n,o)=>{let i=[...n.values()].reduce((r,s)=>{let a;if(B(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;vi(Le(l),"not an ExcalidrawBindableElement");let d=e==="predecessors"?s.points[s.points.length-1]:[0,0],c=oo(t,$e(t,n),[d[0]+s.x,d[1]+s.y]);r.push({relative:l,heading:c})}return r},[]);switch(o){case"up":return i.filter(r=>me(r.heading,_e)).map(r=>r.relative);case"down":return i.filter(r=>me(r.heading,ye)).map(r=>r.relative);case"right":return i.filter(r=>me(r.heading,fe)).map(r=>r.relative);case"left":return i.filter(r=>me(r.heading,ke)).map(r=>r.relative)}},cs=(e,t,n)=>Wd("successors",e,t,n),us=(e,t,n)=>Wd("predecessors",e,t,n),Kh=(e,t,n)=>{let o=bn+e.width;if(n==="up"||n==="down"){let a=Hn+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:(bn+e.width)*(n==="left"?-1:1),y:0}}if(n==="up"||n==="down"){let a=Hn+e.height,l=(t.length===0,a),d=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*o:t.length/2*o*-1;return n==="up"?{x:d,y:l*-1}:{x:d,y:l}}let i=Hn+e.height,r=(t.length===0,bn+e.width),s=t.length===0?0:(t.length+1)%2===0?(t.length+1)/2*i:t.length/2*i*-1;return n==="left"?{x:r*-1,y:s}:{x:r,y:s}},Qh=(e,t,n,o)=>{let i=o.getNonDeletedElementsMap(),r=cs(e,i,n),s=us(e,i,n),a=Kh(e,[...r,...s],n),l=rs({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});vi(tr(l),"not an ExcalidrawFlowchartNodeElement");let d=Vd(e,l,n,t,o);return{nextNode:l,bindingArrow:d}},Jh=(e,t,n,o,i)=>{let r=[];for(let s=0;s<i;s++){let a,l;if(n==="left"||n==="right"){let u=Hn*(i-1)+i*e.height,p=e.y+e.height/2-u/2,m=bn+e.width;n==="left"&&(m*=-1),a=e.x+m;let f=(Hn+e.height)*s;l=p+f}else{let u=bn*(i-1)+i*e.width,p=e.x+e.width/2-u/2,m=Hn+e.height;n==="up"&&(m*=-1),l=e.y+m;let f=(bn+e.width)*s;a=p+f}let d=rs({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});vi(tr(d),"not an ExcalidrawFlowchartNodeElement");let c=Vd(e,d,n,t,o);r.push(d),r.push(c)}return r},Vd=(e,t,n,o,i)=>{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=Fd({type:"arrow",x:r,y:s,startArrowhead:null,endArrowhead:o.currentItemEndArrowhead,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeWidth:e.strokeWidth,opacity:e.opacity,roughness:e.roughness,points:[Ud(0,0),Ud(l,d)],elbowed:!0}),u=i.getNonDeletedElementsMap();yn(c,e,"start",i),yn(c,t,"end",i);let p=new Map;p.set(e.id,e),p.set(t.id,t),p.set(c.id,c),U.movePoints(c,i,new Map([[1,{point:c.points[1]}]]));let m=Ln(c,qh(new Map([...u.entries(),[e.id,e],[t.id,t],[c.id,c]])),{points:c.points});return{...c,...m}},Xd=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,o){if(!Le(t))return null;if(o!==this.direction&&this.clear(),this.visitedNodes.has(t.id)||this.visitedNodes.add(t.id),this.isExploring&&o===this.direction&&this.sameLevelNodes.length>1)return this.sameLevelIndex=(this.sameLevelIndex+1)%this.sameLevelNodes.length,this.sameLevelNodes[this.sameLevelIndex].id;let i=[...cs(t,n,o),...us(t,n,o)];if(i.length>0)return this.sameLevelIndex=0,this.isExploring=!0,this.sameLevelNodes=i,this.direction=o,this.visitedNodes.add(i[0].id),i[0].id;if(o===this.direction||!this.isExploring){this.isExploring||this.visitedNodes.add(t.id);let s=["up","right","down","left"].filter(a=>a!==o).map(a=>[...cs(t,n,a),...us(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=o,a.id}return null}},jd=class{isCreatingChart=!1;numberOfNodes=0;direction="right";pendingNodes=null;createNodes(t,n,o,i){let r=i.getNonDeletedElementsMap();if(o!==this.direction){let{nextNode:s,bindingArrow:a}=Qh(t,n,o,i);this.numberOfNodes=1,this.isCreatingChart=!0,this.direction=o,this.pendingNodes=[s,a]}else{this.numberOfNodes+=1;let s=Jh(t,n,o,i,this.numberOfNodes);this.isCreatingChart=!0,this.direction=o,this.pendingNodes=s}if(t.frameId){let s=r.get(t.frameId);vi(s&&Fo(s),"not an ExcalidrawFrameElement"),s&&this.pendingNodes.every(a=>Qt([a],s,r)||qt(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}},yI=(e,t)=>{for(let[,n]of t)if(n.type==="arrow"&&(n.startBinding?.elementId===e.id||n.endBinding?.elementId===e.id))return!0;return!1};P();import{MIME_TYPES as $d,SVG_NS as eE}from"@excalidraw/common";var tE=e=>new Promise((t,n)=>{let o=new Image;o.onload=()=>{t(o)},o.onerror=i=>{n(i)},o.src=e}),MI=async({fileIds:e,files:t,imageCache:n})=>{let o=new Map,i=new Map;return await Promise.all(e.reduce((r,s)=>{let a=t[s];return a&&!o.has(s)?(o.set(s,!0),r.concat((async()=>{try{if(a.mimeType===$d.binary)throw new Error("Only images can be added to ImageCache");let l=tE(a.dataURL),d={image:l,mimeType:a.mimeType};n.set(s,d);let c=await l;n.set(s,{...d,image:c})}catch{i.set(s,!0)}})())):r},[])),{imageCache:n,updatedFiles:o,erroredFiles:i}},TI=e=>e.filter(t=>_t(t)),nE=e=>e?.nodeName.toLowerCase()==="svg",AI=e=>{let t=new DOMParser().parseFromString(e,$d.svg),n=t.querySelector("svg");if(t.querySelector("parsererror")||!nE(n))throw new Error("Invalid SVG");{n.hasAttribute("xmlns")||n.setAttribute("xmlns",eE);let i=n.getAttribute("width"),r=n.getAttribute("height");(i?.includes("%")||i==="auto")&&(i=null),(r?.includes("%")||r==="auto")&&(r=null);let s=n.getAttribute("viewBox");if(!i||!r){if(i=i||"50",r=r||"50",s){let a=s.match(/\d+ +\d+ +(\d+(?:\.\d+)?) +(\d+(?:\.\d+)?)/);a&&([,i,r]=a)}n.setAttribute("width",i),n.setAttribute("height",r)}return s||n.setAttribute("viewBox",`0 0 ${i} ${r}`),n.outerHTML}};P();var GI=(e,t,n,o=50)=>{if(!e||e.length===0)return[];let i=[],r=Array.isArray(e[0])?e:e.map(m=>[m]),s=r.length,a=Math.max(1,Math.ceil(Math.sqrt(s))),l=[];for(let m=0;m<s;m+=a)l.push(r.slice(m,m+a));let d=0,c=l.map(m=>{let f=0,E=0,h=m.map(g=>{let[x,y,b,w]=Xe(g);return{elements:g,bounds:[x,y,b,w],width:b-x,height:w-y}});return h.forEach((g,x)=>{f+=g.width,x<h.length-1&&(f+=o),g.height>E&&(E=g.height)}),d+=E,{unitBounds:h,width:f,maxHeight:E}}),u=d+Math.max(0,l.length-1)*o,p=n-u/2;return c.forEach(m=>{let{unitBounds:f,width:E,maxHeight:h}=m,g=t-E/2;f.forEach(x=>{let[y,b]=x.bounds,w=g-y,I=p-b;x.elements.forEach(M=>{i.push(ge(M,{x:M.x+w,y:M.y+I}))}),g+=x.width+o}),p+=h+o}),i};P();import{pointCenter as oE,normalizeRadians as Ci,pointFrom as re,pointRotateRads as ot}from"@excalidraw/math";import{MIN_FONT_SIZE as ms,SHIFT_LOCKING_ANGLE as Gi,rescalePoints as Zd,getFontString as Li}from"@excalidraw/common";var jI=(e,t,n,o,i,r,s,a,l,d,c)=>{let u=o.getNonDeletedElementsMap();if(n.length===1){let[p]=n;if(t==="rotation")B(p)||(iE(p,o,a,l,i),Ue(p,o));else if(t){let m=n[0].id,f=u.get(m),E=e.get(m);if(f&&E){let{nextWidth:h,nextHeight:g}=dE(f,E,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});lE(h,g,f,E,e,o,t,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r})}}return oe(p)&&Ue(p,o),!0}else if(n.length>1){if(t==="rotation")return sE(e,n,o,a,l,i,d,c),!0;if(t){let{nextWidth:p,nextHeight:m,flipByX:f,flipByY:E,originalBoundingBox:h}=cE(n,e,u,t,a,l,{shouldMaintainAspectRatio:s,shouldResizeFromCenter:r});return uE(n,u,t,o,e,{shouldResizeFromCenter:r,shouldMaintainAspectRatio:s,flipByX:f,flipByY:E,nextWidth:p,nextHeight:m,originalBoundingBox:h}),!0}}return!1},iE=(e,t,n,o,i)=>{let[r,s,a,l]=Y(e,t.getNonDeletedElementsMap()),d=(r+a)/2,c=(s+l)/2,u;q(e)?u=0:(u=5*Math.PI/2+Math.atan2(o-c,n-d),i&&(u=u+Gi/2,u=u-u%Gi),u=Ci(u));let p=St(e);if(t.mutateElement(e,{angle:u}),p){let m=t.getElement(p);if(m&&!_(e)){let{x:f,y:E}=to(e,m,t.getNonDeletedElementsMap());t.mutateElement(m,{angle:u,x:f,y:E})}}},qd=(e,t,n,o)=>j(e)||Me(e)?{points:Zd(0,t,Zd(1,n,e.points,o),o)}:{},fs=(e,t,n)=>{let o=e.width;if(ce(e)){let s=Ce(e,t);s&&(o=et(s,e))}let r=e.fontSize*(n/o);return r<ms?null:{size:r}},rE=(e,t,n,o,i,r,s)=>{let a=n.getNonDeletedElementsMap(),l=t.width*(s/t.height),d=fs(t,a,l);if(d!==null){if(o.includes("n")||o.includes("s")){let c=re(e.x,e.y),u=ps(c,e.width,e.height,l,s,e.angle,o,!1,i);n.mutateElement(t,{fontSize:d.size,width:l,height:s,x:u.x,y:u.y});return}if(o==="e"||o==="w"){let c=zo(Li({fontSize:t.fontSize,fontFamily:t.fontFamily}),t.lineHeight),u=Math.max(c,r),p=It(t.originalText,Li(t),Math.abs(u)),m=Je(p,Li(t),t.lineHeight),f=m.height,E=re(e.x,e.y),h=ps(E,e.width,e.height,u,f,t.angle,o,!1,i),g={width:Math.abs(u),height:Math.abs(m.height),x:h.x,y:h.y,text:p,autoResize:!1};n.mutateElement(t,g)}}},sE=(e,t,n,o,i,r,s,a)=>{let l=n.getNonDeletedElementsMap(),d=5*Math.PI/2+Math.atan2(i-a,o-s);r&&(d+=Gi/2,d-=d%Gi);for(let c of t)if(!q(c)){let[u,p,m,f]=Y(c,l),E=(u+m)/2,h=(p+f)/2,g=e.get(c.id)?.angle??c.angle,[x,y]=ot(re(E,h),re(s,a),d+g-c.angle),b=B(c)?{points:Ja(c,l)}:{x:c.x+(x-E),y:c.y+(y-h),angle:Ci(d+g)};n.mutateElement(c,b),Ue(c,n,{simultaneouslyUpdated:t});let w=W(c,l);if(w&&!_(c)){let{x:I,y:M}=to(c,w,l);n.mutateElement(w,{x:I,y:M,angle:Ci(d+g)})}}n.triggerUpdate()},WI=(e,t,n,o,i)=>{let[r,s,a,l]=t.length===1?Y(t[0],n):Xe(t),d=(r+a)/2,c=(s+l)/2,u=t.length===1?t[0].angle:0;switch([o,i]=ot(re(o,i),re(d,c),-u),e){case"n":return ot(re(o-(r+a)/2,i-s),re(0,0),u);case"s":return ot(re(o-(r+a)/2,i-l),re(0,0),u);case"w":return ot(re(o-r,i-(s+l)/2),re(0,0),u);case"e":return ot(re(o-a,i-(s+l)/2),re(0,0),u);case"nw":return ot(re(o-r,i-s),re(0,0),u);case"ne":return ot(re(o-a,i-s),re(0,0),u);case"sw":return ot(re(o-r,i-l),re(0,0),u);case"se":return ot(re(o-a,i-l),re(0,0),u);default:return[0,0]}},VI=(e,t)=>{let[,[n,o]]=t.points;return e==="nw"&&(n<0||o<0)||e==="ne"&&n>=0||e==="sw"&&n<=0||e==="se"&&(n>0||o>0)?"end":"origin"},aE=(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"},ps=(e,t,n,o,i,r,s,a,l)=>{let d=aE(s,a,l),[c,u]=e;switch(d){case"top-left":return{x:c+(t-o)/2+(o-t)/2*Math.cos(r)+(n-i)/2*Math.sin(r),y:u+(n-i)/2+(o-t)/2*Math.sin(r)+(i-n)/2*Math.cos(r)};case"top-right":return{x:c+(t-o)/2*(Math.cos(r)+1)+(n-i)/2*Math.sin(r),y:u+(n-i)/2+(t-o)/2*Math.sin(r)+(i-n)/2*Math.cos(r)};case"bottom-left":return{x:c+(t-o)/2*(1-Math.cos(r))+(i-n)/2*Math.sin(r),y:u+(n-i)/2*(Math.cos(r)+1)+(o-t)/2*Math.sin(r)};case"bottom-right":return{x:c+(t-o)/2*(Math.cos(r)+1)+(i-n)/2*Math.sin(r),y:u+(n-i)/2*(Math.cos(r)+1)+(t-o)/2*Math.sin(r)};case"center":return{x:c-(o-t)/2,y:u-(i-n)/2};case"east-side":return{x:c+(t-o)/2*(Math.cos(r)+1),y:u+(t-o)/2*Math.sin(r)+(n-i)/2};case"west-side":return{x:c+(t-o)/2*(1-Math.cos(r)),y:u+(o-t)/2*Math.sin(r)+(n-i)/2};case"north-side":return{x:c+(t-o)/2+(n-i)/2*Math.sin(r),y:u+(i-n)/2*(Math.cos(r)-1)};case"south-side":return{x:c+(t-o)/2+(i-n)/2*Math.sin(r),y:u+(n-i)/2*(Math.cos(r)+1)}}},lE=(e,t,n,o,i,r,s,{shouldInformMutation:a=!0,shouldMaintainAspectRatio:l=!1,shouldResizeFromCenter:d=!1}={})=>{if(oe(n)&&oe(o))return rE(o,n,r,s,d,e,t);let c={},u=r.getNonDeletedElementsMap(),p=W(n,u);if(p){let h=i.get(p.id);if(h&&(c={fontSize:h.fontSize}),l){let g={...n,width:e,height:t},x=fs(p,u,et(g,p));if(x===null)return;c={fontSize:x.size}}else{let g=ha(Li(p),p.lineHeight),x=Ea(p.fontSize,p.lineHeight);e=Math.max(e,g),t=Math.max(t,x)}}let m=qd(o,e,t,!0),f=re(o.x,o.y);if(j(o)){let[h,g]=pe(o,i);f=re(h,g)}let E=ps(f,o.width,o.height,e,t,o.angle,s,l,d);if(j(o)&&m.points){let h=o.x-f[0],g=o.y-f[1];E.x+=h,E.y+=g;let x=m.points[0][0],y=m.points[0][1];E.x+=x,E.y+=y,m.points=m.points.map(b=>re(b[0]-x,b[1]-y))}if(e<0&&(E.x=E.x+e),t<0&&(E.y=E.y+t),"scale"in n&&"scale"in o&&r.mutateElement(n,{scale:[(Math.sign(e)||o.scale[0])*o.scale[0],(Math.sign(t)||o.scale[1])*o.scale[1]]}),_(n)&&p&&l){let h=e/n.width*p.fontSize;if(h<ms)return;c.fontSize=h}if(e!==0&&t!==0&&Number.isFinite(E.x)&&Number.isFinite(E.y)){let h={...E,width:Math.abs(e),height:Math.abs(t),...m};r.mutateElement(n,h,{informMutation:a,isDragging:!1}),p&&c!=null&&r.mutateElement(p,{fontSize:c.fontSize}),hn(n,r,s,l),Ue(n,r,{newSize:{width:e,height:t}})}},dE=(e,t,n,o,i,{shouldMaintainAspectRatio:r=!1,shouldResizeFromCenter:s=!1}={})=>{let[a,l,d,c]=zt(t,t.width,t.height,!0),u=re(a,l),p=re(d,c),m=oE(u,p),f=ot(re(o,i),m,-t.angle),[E,h,g,x]=zt(e,e.width,e.height,!0),y=g-E,b=x-h,w=p[0]-u[0],I=p[1]-u[1],M=w/y,D=I/b;n.includes("e")&&(M=(f[0]-u[0])/y),n.includes("s")&&(D=(f[1]-u[1])/b),n.includes("w")&&(M=(p[0]-f[0])/y),n.includes("n")&&(D=(p[1]-f[1])/b);let T=e.width*M,N=e.height*D;if(s&&(T=2*T-t.width,N=2*N-t.height),r){let C=Math.abs(T)/t.width,R=Math.abs(N)/t.height;if(n.length===1&&(N*=C,T*=R),n.length===2){let L=Math.max(C,R);T=t.width*L*Math.sign(T),N=t.height*L*Math.sign(N)}}return{nextWidth:T,nextHeight:N}},cE=(e,t,n,o,i,r,{shouldMaintainAspectRatio:s=!1,shouldResizeFromCenter:a=!1}={})=>{let l=e.map(L=>t.get(L.id)),d=l.reduce((L,$)=>{if(!j($))return L;let H=St($);if(!H)return L;let te=t.get(H)??null;return ce(te)?[...L,{...te,...U.getBoundTextElementPosition($,te,n)}]:L},[]),c=Bt(l.map(L=>L).concat(d)),{minX:u,minY:p,maxX:m,maxY:f,midX:E,midY:h}=c,g=m-u,x=f-p,y={ne:[u,f],se:[u,p],sw:[m,p],nw:[m,f],e:[u,p+x/2],w:[m,p+x/2],n:[u+g/2,f],s:[u+g/2,p]},[b,w]=a?[E,h]:y[o],I=a?2:1,M=Math.max(Math.abs(i-b)/g||0,Math.abs(r-w)/x||0)*I,D=o.includes("e")||o.includes("w")?Math.abs(i-b)*I:g,T=o.includes("n")||o.includes("s")?Math.abs(r-w)*I:x;s&&(D=g*M*Math.sign(i-b),T=x*M*Math.sign(r-w));let N={ne:[i<b,r>w],se:[i<b,r<w],sw:[i>b,r<w],nw:[i>b,r>w],e:[i<b,!1],w:[i>b,!1],n:[!1,r>w],s:[!1,r<w]},[C,R]=N[o].map(L=>L);return{originalBoundingBox:c,nextWidth:D,nextHeight:T,flipByX:C,flipByY:R}},uE=(e,t,n,o,i,{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;i||(i=t);let p=e.reduce((I,M)=>{let D=i.get(M.id);return D&&I.push({orig:D,latest:M}),I},[]),m;if(u)m=u;else{let I=p.reduce((M,{orig:D})=>{if(!j(D))return M;let T=St(D);if(!T)return M;let N=i.get(T)??null;return ce(N)?[...M,{...N,...U.getBoundTextElementPosition(D,N,t)}]:M},[]);m=Bt(p.map(({orig:M})=>M).concat(I))}let{minX:f,minY:E,maxX:h,maxY:g,midX:x,midY:y}=m,b=h-f,w=g-E;if(c===void 0&&d===void 0&&(c=b,d=w),r&&(c===void 0?c=d*(b/w):d===void 0?d=c*(w/b):Math.abs(c/d-b/w)>.001&&(c=d*(b/w))),c&&d){let I=n.includes("e")||n.includes("w")?Math.abs(c)/b:1,M=n.includes("n")||n.includes("s")?Math.abs(d)/w:1,D;n.length===1?D=n.includes("e")||n.includes("w")?I:M:D=Math.max(Math.abs(c)/b||0,Math.abs(d)/w||0);let T={ne:[f,g],se:[f,E],sw:[h,E],nw:[h,g],e:[f,E+w/2],w:[h,E+w/2],n:[f+b/2,g],s:[f+b/2,E]},[N,C]=s?[x,y]:T[n],R=r||p.some(S=>S.latest.angle!==0||oe(S.latest)||yl(S.latest));R&&(I=D,M=D);let[L,$]=[a?-1:1,l?-1:1],H=[];for(let{orig:S,latest:Q}of p){if(oe(S)&&ce(S))continue;let Z=S.width*I,ne=S.height*M,an=Ci(S.angle*L*$),it=j(S)||Me(S),Pn=S.x-N,Oi=S.y-C,fo=a&&!it?Z:0,zn=l&&!it?ne:0,Ri=N+L*(Pn*I+fo),ho=C+$*(Oi*M+zn),ln=qd(S,Z*L,ne*$,!1),xe={x:Ri,y:ho,width:Z,height:ne,angle:an,...ln};if(B(S)&&(S.startBinding&&(xe.startBinding={...S.startBinding,fixedPoint:[a?-S.startBinding.fixedPoint[0]+1:S.startBinding.fixedPoint[0],l?-S.startBinding.fixedPoint[1]+1:S.startBinding.fixedPoint[1]]}),S.endBinding&&(xe.endBinding={...S.endBinding,fixedPoint:[a?-S.endBinding.fixedPoint[0]+1:S.endBinding.fixedPoint[0],l?-S.endBinding.fixedPoint[1]+1:S.endBinding.fixedPoint[1]]}),S.fixedSegments&&ln.points&&(xe.fixedSegments=S.fixedSegments.map(De=>({...De,start:ln.points[De.index-1],end:ln.points[De.index]})))),we(S)&&(xe.scale=[S.scale[0]*L,S.scale[1]*$]),oe(S)){let De=fs(S,t,Z);if(!De)return;xe.fontSize=De.size}let dn=i.get(St(S)??"");if(dn)if(R){let De=dn.fontSize*D;if(De<ms)return;xe.boundTextFontSize=De}else xe.boundTextFontSize=dn.fontSize;H.push({element:Q,update:xe})}let te=H.map(({element:S})=>S);for(let{element:S,update:{boundTextFontSize:Q,...Z}}of H){let{width:ne,height:an,angle:it}=Z;o.mutateElement(S,Z),Ue(S,o,{simultaneouslyUpdated:te,newSize:{width:ne,height:an}});let Pn=W(S,t);Pn&&Q&&(o.mutateElement(Pn,{fontSize:Q,angle:j(S)?void 0:it}),hn(S,o,n,!0))}o.triggerUpdate()}};P();import{pointFrom as Ze,pointOnLineSegment as nc,pointRotateRads as ki}from"@excalidraw/math";import{SIDE_RESIZING_THRESHOLD as ys}from"@excalidraw/common";P();import{DEFAULT_TRANSFORM_HANDLE_SPACING as Es,isAndroid as pE,isIOS as mE}from"@excalidraw/common";import{pointFrom as Kd,pointRotateRads as fE}from"@excalidraw/math";var Qd={mouse:8,pen:16,touch:28},hE=16,ec={e:!0,s:!0,n:!0,w:!0},eS={e:!0,s:!0,n:!0,w:!0},tS={e:!0,s:!0,n:!0,w:!0,rotation:!0},Jd={e:!0,s:!0,n:!0,w:!0,nw:!0,se:!0},hs={e:!0,s:!0,n:!0,w:!0},Rt=(e,t,n,o,i,r,s)=>{let[a,l]=fE(Kd(e+n/2,t+o/2),Kd(i,r),s);return[a-n/2,l-o/2,n,o]},Bi=e=>!(e.viewport.isMobile||e.isTouchScreen&&(pE||mE)),gs=e=>Bi(e)?ec:{},xs=([e,t,n,o,i,r],s,a,l,d={},c=4,u=Es)=>{let p=Qd[l],m=p/a.value,f=p/a.value,E=p/a.value,h=p/a.value,g=n-e,x=o-t,y=c/a.value,b=(p-u*2)/(2*a.value),w={nw:d.nw?void 0:Rt(e-y-E+b,t-y-h+b,m,f,i,r,s),ne:d.ne?void 0:Rt(n+y-b,t-y-h+b,m,f,i,r,s),sw:d.sw?void 0:Rt(e-y-E+b,o+y-b,m,f,i,r,s),se:d.se?void 0:Rt(n+y-b,o+y-b,m,f,i,r,s),rotation:d.rotation?void 0:Rt(e+g/2-m/2,t-y-h+b-hE/a.value,m,f,i,r,s)},I=5*Qd.mouse/a.value;return Math.abs(g)>I&&(d.n||(w.n=Rt(e+g/2-m/2,t-y-h+b,m,f,i,r,s)),d.s||(w.s=Rt(e+g/2-m/2,o+y-b,m,f,i,r,s))),Math.abs(x)>I&&(d.w||(w.w=Rt(e-y-E+b,t+x/2-f/2,m,f,i,r,s)),d.e||(w.e=Rt(n+y-b,t+x/2-f/2,m,f,i,r,s))),w},tc=(e,t,n,o="mouse",i=ec)=>{if(e.locked||B(e))return{};if(e.type==="freedraw"||j(e)){if(e.points.length===2){let[,s]=e.points;s[0]===0||s[1]===0?i=hs:s[0]>0&&s[1]<0?i=Jd:s[0]>0&&s[1]>0?i=hs:s[0]<0&&s[1]>0?i=Jd:s[0]<0&&s[1]<0&&(i=hs)}}else q(e)&&(i={...i,rotation:!0});let r=j(e)?Es+8:we(e)?0:Es;return xs(Y(e,n,!0),e.angle,t,o,i,r,we(e)?0:void 0)},nS=(e,t)=>{if(t.selectedLinearElement?.isEditing)return!1;if(e.length>1)return!0;let n=e[0];return B(n)?!1:j(n)?n.points.length>2:!0};var bs=(e,t,n)=>t>=e[0]&&t<=e[0]+e[2]&&n>=e[1]&&n<=e[1]+e[3],EE=(e,t,n,o,i,r,s,a)=>{if(!n.selectedElementIds[e.id])return!1;let{rotation:l,...d}=tc(e,r,t,s,gs(a));if(l&&bs(l,o,i))return"rotation";let c=Object.keys(d).filter(u=>{let p=d[u];return p?bs(p,o,i):!1});if(c.length>0)return c[0];if(Bi(a)){let[u,p,m,f,E,h]=Y(e,t);if(!(j(e)&&e.points.length<=2)){let g=we(e)?0:ys/r.value,x=ys/r.value,y=oc(Ze(u-g,p-g),Ze(m+g,f+g),Ze(E,h),e.angle);for(let[b,w]of Object.entries(y))if(nc(Ze(o,i),w,x))return b}}return!1},cS=(e,t,n,o,i,r,s,a)=>e.reduce((l,d)=>{if(l)return l;let c=EE(d,s,t,n,o,i,r,a);return c?{element:d,transformHandleType:c}:null},null),uS=([e,t,n,o],i,r,s,a,l)=>{let d=xs([e,t,n,o,(e+n)/2,(t+o)/2],0,s,a,gs(l)),c=Object.keys(d).find(u=>{let p=d[u];return p&&bs(p,i,r)});if(c)return c;if(Bi(l)){let u=(e+n)/2,p=(t+o)/2,m=ys/s.value,f=oc(Ze(e-m,t-m),Ze(n+m,o+m),Ze(u,p),0);for(let[E,h]of Object.entries(f))if(nc(Ze(i,r),h,m))return E}return!1},ws=["ns","nesw","ew","nwse"],gE=(e,t)=>{let n=ws.indexOf(e);if(n>=0){let o=Math.round(t/(Math.PI/4));e=ws[(n+o)%ws.length]}return e},pS=e=>{let{element:t,transformHandleType:n}=e,o=t&&Math.sign(t.height)*Math.sign(t.width)===-1,i=null;switch(n){case"n":case"s":i="ns";break;case"w":case"e":i="ew";break;case"nw":case"se":o?i="nesw":i="nwse";break;case"ne":case"sw":o?i="nwse":i="nesw";break;case"rotation":return"grab"}return i&&t&&(i=gE(i,t.angle)),i?`${i}-resize`:""},oc=([e,t],[n,o],i,r)=>{let s=ki(Ze(e,t),i,r),a=ki(Ze(n,t),i,r),l=ki(Ze(e,o),i,r),d=ki(Ze(n,o),i,r);return{n:[s,a],e:[a,d],s:[d,l],w:[l,s]}};P();var ES=(e,t)=>!!(!e.viewModeEnabled&&e.openDialog?.name!=="elementLinkSelector"&&(e.activeTool.type!=="custom"&&(e.editingTextElement||e.activeTool.type!=="selection"&&e.activeTool.type!=="lasso"&&e.activeTool.type!=="eraser"&&e.activeTool.type!=="hand"&&e.activeTool.type!=="laser")||pt(t,e).length));P();import{arrayToMap as rc,findIndex as sc,findLastIndex as ac}from"@excalidraw/common";var Ps=(e,t)=>e.frameId===t||e.id===t,lc=(e,t,n)=>{let o=[],i=[],r=null,s=-1,a=rc(n||pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0}));for(;++s<e.length;){let l=e[s];a.get(l.id)?(i.length&&(o=o.concat(i),i=[]),o.push(s),r=s+1):l.isDeleted&&r===s?(r=s+1,i.push(s)):i=[]}return o},xE=e=>{let t=0;return e.reduce((n,o,i)=>(i>0&&e[i-1]!==o-1&&(t=++t),(n[t]||(n[t]=[])).push(o),n),[])},ic=(e,t,n,o)=>{if("containerId"in e&&e.containerId){let i=o.getElement(e.containerId);if(i)return n==="left"?Math.min(t.indexOf(i),t.indexOf(e)):Math.max(t.indexOf(i),t.indexOf(e))}else{let i=e.boundElements?.find(r=>r.type!=="arrow")?.id;if(i){let r=o.getElement(i);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,o=-1;return e.forEach((i,r)=>{Ps(i,t)&&(n===-1&&(n=r),o=r)}),n===-1?[]:e.slice(n,o+1)},yE=(e,t,n,o,i,r)=>{let s=t[n],a=p=>p.isDeleted?!1:i?p.frameId===i:e.editingGroupId?p.groupIds.includes(e.editingGroupId):!0,l=o==="left"?ac(t,p=>a(p),Math.max(0,n-1)):sc(t,p=>a(p),n+1),d=t[l];if(!d)return-1;if(e.editingGroupId){if(s?.groupIds.join("")===d?.groupIds.join(""))return ic(d,t,o,r)??l;if(!d?.groupIds.includes(e.editingGroupId))return-1}if(!i&&(d.frameId||q(d))){let p=wE(t,d.frameId||d.id);return o==="left"?t.indexOf(p[0]):t.indexOf(p[p.length-1])}if(!d.groupIds.length)return ic(d,t,o,r)??l;let c=e.editingGroupId?d.groupIds[d.groupIds.indexOf(e.editingGroupId)-1]:d.groupIds[d.groupIds.length-1],u=Ae(t,c);return u.length?o==="left"?t.indexOf(u[0]):t.indexOf(u[u.length-1]):l},dc=(e,t)=>t.reduce((n,o)=>{let i=e[o];return n.set(i.id,i),n},new Map),cc=(e,t,n,o)=>{let i=lc(e,t),r=dc(e,i),s=xE(i);n==="right"&&(s=s.reverse());let a=new Set(i.filter(l=>q(e[l])).map(l=>e[l].id));return s.forEach((l,d)=>{let c=l[0],u=l[l.length-1],p=n==="left"?c:u,m=l.some(y=>{let b=e[y];return b.frameId&&a.has(b.frameId)})?null:e[p]?.frameId,f=yE(t,e,p,n,m,o);if(f===-1||p===f)return;let E=n==="left"?e.slice(0,f):e.slice(0,c),h=e.slice(c,u+1),g=n==="left"?e.slice(f,c):e.slice(u+1,f+1),x=n==="left"?e.slice(u+1):e.slice(f+1);e=n==="left"?[...E,...h,...g,...x]:[...E,...g,...h,...x]}),mo(e,r),e},uc=(e,t,n,o,i)=>{let r=lc(e,t,i),s=dc(e,r),a=[],l,d;if(n==="left"){if(o)l=sc(e,f=>Ps(f,o));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;l=e.indexOf(f[0])}else l=0;d=r[r.length-1]}else{if(o)d=ac(e,f=>Ps(f,o));else if(t.editingGroupId){let f=Ae(e,t.editingGroupId);if(!f.length)return e;d=e.indexOf(f[f.length-1])}else d=e.length-1;l=r[0]}l===-1&&(l=0);for(let f=l;f<d+1;f++)r.includes(f)||a.push(e[f]);let c=Array.from(s.values()),u=e.slice(0,l),p=e.slice(d+1),m=n==="left"?[...u,...c,...a,...p]:[...u,...a,...c,...p];return mo(m,s),m};function pc(e,t,n,o){let i=rc(pt(e,t,{includeBoundTextElement:!0,includeElementsInFrames:!0})),r={regularElements:[],frameChildren:new Map},s=new Set;for(let d of e)i.has(d.id)&&q(d)&&s.add(d.id);for(let d of e)if(i.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=o(e,t,n,d,c);return o(a,t,n,null,r.regularElements)}var SS=(e,t,n)=>cc(e,t,"left",n),MS=(e,t,n)=>cc(e,t,"right",n),TS=(e,t)=>pc(e,t,"left",uc),AS=(e,t)=>pc(e,t,"right",uc);var BS=e=>e.reduce((t,n)=>t+n.version,0),ld=e=>{let t=5381;for(let n of bE(e))t=(t<<5)+t+n.versionNonce;return t>>>0},dd=e=>{let t=5381;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);t=(t<<5)+t+o}return t>>>0},kS=e=>e.filter(t=>!t.isDeleted&&!ed(t)),PE=e=>e.filter(t=>!t.isDeleted),OS=e=>!e.isDeleted,Is=e=>PE(e).map(t=>Ji(t.type)?{...t,lastCommittedPoint:null}:t),RS=e=>Is(e),FS=e=>Is(e),NS=e=>Is(e);export{en as AppStateDelta,ee as BASE_PADDING,zp as BINDING_HIGHLIGHT_THICKNESS,Zt as BindableElement,$t as BoundElement,Ne as CaptureUpdateAction,t0 as DEFAULT_LINK_SIZE,ec as DEFAULT_OMIT_SIDES,F as Delta,Qr as DurableIncrement,Wr as ElementBounds,tn as ElementsDelta,Jr as EphemeralIncrement,ie as FIXED_BINDING_DISTANCE,jd as FlowChartCreator,Xd as FlowChartNavigator,ye as HEADING_DOWN,ke as HEADING_LEFT,fe as HEADING_RIGHT,_e as HEADING_UP,Zm as IMAGE_INVERT_FILTER,Sf as INVISIBLY_SMALL_ELEMENT_SIZE,ts as InvalidFractionalIndexError,U as LinearElementEditor,Se as MINIMAL_CROP_SIZE,tS as OMIT_SIDES_FOR_FRAME,eS as OMIT_SIDES_FOR_MULTIPLE_ELEMENTS,Mi as Scene,Pe as ShapeCache,id as Store,uo as StoreChange,es as StoreDelta,bi as StoreIncrement,nn as StoreSnapshot,$e as aabbForElement,Rm as addElementsToFrame,Jh as addNewNodes,Ky as addToGroup,s1 as alignElements,Jp as avoidRectangularCorner,Sl as bindElementsToFramesAfterDuplication,yn as bindLinearElement,Dr as bindOrUnbindLinearElement,Xp as bindOrUnbindLinearElements,Sr as bindPointToSnapToElementOutline,ii as bindingBorderTest,Qa as bindingProperties,Na as bumpVersion,Za as calculateFixedPointForElbowArrowBinding,kx as canApplyRoundnessTypeToElement,ua as canBecomePolygon,Hl as canChangeRoundness,Mh as canCreateLinkFromElements,p0 as canHaveArrowheads,Bi as canResizeFromSides,An as charWidth,RS as clearElementsForDatabase,FS as clearElementsForExport,NS as clearElementsForLocalStorage,me as compareHeading,to as computeBoundTextPosition,lr as computeContainerDimensionForBoundText,Jx as containsCJK,oI as createPlaceholderEmbeddableLabel,as as createSrcDoc,xx as cropElement,Tn as deconstructDiamondElement,Bo as deconstructLinearOrFreeDrawElement,Mn as deconstructRectanguloidElement,Kr as deepCopyElement,vP as defaultGetElementLinkFromSelection,Wx as detectLineHeight,Ut as distanceToElement,pP as distributeElements,gn as doBoundsIntersect,SP as dragNewElement,PP as dragSelectedElements,kf as duplicateElement,y1 as duplicateElements,qy as editGroupForSelectedElement,he as elementCenterPoint,qt as elementOverlapsWithFrame,xi as elementWithCanvasCache,Qt as elementsAreInFrameBounds,wl as elementsAreInSameGroup,rI as embeddableURLValidator,Pl as excludeElementsInFramesFromSelection,Bb as filterElementsEligibleAsFrameChildren,yy as fixBindingsAfterDeletion,Ka as fixDuplicatedBindingsAfterDuplication,fr as flipHeading,Hb as frameAndChildrenSelectedTogether,Nl as generateFreeDrawShape,ia as generateLinearCollisionShape,Fe as generateRoughOptions,Ea as getApproxMinLineHeight,ha as getApproxMinLineWidth,Ja as getArrowLocalFixedPoints,xf as getArrowheadAngle,Ur as getArrowheadPoints,gf as getArrowheadSize,W as getBoundTextElement,St as getBoundTextElementId,uw as getBoundTextElementPosition,no as getBoundTextMaxHeight,et as getBoundTextMaxWidth,Vr as getBoundsFromPoints,dt as getCenterForBounds,X0 as getClosestElementBounds,Bt as getCommonBoundingBox,Xe as getCommonBounds,dw as getContainerCenter,dr as getContainerCoords,Ce as getContainerElement,Ct as getContainingFrame,yt as getCornerRadius,Vo as getCubicBezierCurveBound,pS as getCursorForResizingElement,_m as getDefaultFrameName,Ox as getDefaultRoundnessTypeForElement,ko as getDiamondPoints,IP as getDragOffsetXY,U0 as getDraggedElementsBounds,Y as getElementAbsoluteCoords,pe as getElementBounds,Nr as getElementLineSegments,Gr as getElementPointsCoords,jl as getElementShape,cS as getElementWithTransformHandleType,Ml as getElementsCompletelyInFrame,Ae as getElementsInGroup,Gb as getElementsInNewFrame,Cb as getElementsInResizingFrame,Mb as getElementsIntersectingFrame,Nb as getElementsOverlappingFrame,Rr as getElementsWithinSelection,nI as getEmbedLink,wx as getFlipAdjustedCropPosition,Kt as getFrameChildren,km as getFrameLikeElements,Fb as getFrameLikeTitle,Jm as getFreeDrawPath2D,ef as getFreeDrawSvgPath,i0 as getFreedrawOutlineAsSegments,tf as getFreedrawOutlinePoints,ni as getGlobalFixedPointForBindableElement,im as getGlobalFixedPoints,Fa as getHeadingForElbowArrowSnap,Vt as getHoveredElementForBinding,TI as getInitializedImageElements,_o as getLineHeightInPx,Yt as getLineWidth,Fx as getLinearElementSubType,wI as getLinkDirectionFromKey,LP as getLinkIdAndTypeFromSelection,sl as getLockedLinearCursorAlignSize,Iu as getMaxCharWidth,Jy as getMaximumGroups,$x as getMinCharWidth,ao as getMinMaxXYFromCurvePathOps,zo as getMinTextElementWidth,bl as getNewGroupIdsForDuplication,PE as getNonDeletedElements,xl as getNonDeletedGroupIds,e1 as getNormalizedDimensions,Rn as getObservedAppState,gs as getOmitSidesForDevice,_x as getOriginalContainerHeightFromCache,$r as getPerfectElementSize,us as getPredecessors,Y0 as getRectangleBoxAbsoluteCoords,qm as getRenderOpacity,VI as getResizeArrowDirection,WI as getResizeOffsetXY,zt as getResizedElementAbsoluteCoords,Lb as getRootElements,BS as getSceneVersion,pt as getSelectedElements,pi as getSelectedElementsByGroup,Or as getSelectedGroupForElement,vm as getSelectedGroupIdForElement,Am as getSelectedGroupIds,pb as getSelectionStateForElements,gy as getSuggestedBindingsForArrows,ub as getTargetElements,Nm as getTargetFrame,cw as getTextElementAngle,hw as getTextFromElements,Pu as getTextHeight,ga as getTextWidth,uS as getTransformHandleTypeFromCoords,tc as getTransformHandles,xs as getTransformHandlesFromCoords,ta as getUncroppedImageElement,$i as getUncroppedWidthAndHeight,db as getVisibleAndNonSelectedElements,kS as getVisibleElements,j0 as getVisibleSceneBounds,vb as groupByFrameLikes,Ab as groupsAreAtLeastIntersectingTheFrame,Db as groupsAreCompletelyOutOfFrame,hn as handleBindTextResize,a0 as hasBackground,st as hasBoundTextElement,l0 as hasStrokeColor,c0 as hasStrokeStyle,d0 as hasStrokeWidth,ld as hashElementsVersion,dd as hashString,Be as headingForPoint,oo as headingForPointFromElement,tt as headingForPointIsHorizontal,Oe as headingIsHorizontal,zw as headingIsVertical,rp as hitElementBoundText,ip as hitElementBoundingBox,kw as hitElementBoundingBoxOnly,op as hitElementItself,En as intersectElementWithLineSegment,Bx as isArrowBoundToElement,_ as isArrowElement,Le as isBindableElement,er as isBindingElement,hu as isBindingElementType,Ar as isBindingEnabled,ce as isBoundToContainer,Rx as isBounds,Tb as isCursorInFrame,fu as isCurvedArrow,B as isElbowArrow,J0 as isElementCompletelyInViewport,Hr as isElementContainingFrame,Al as isElementInFrame,Dm as isElementInGroup,Il as isElementInViewport,kn as isElementIntersectingFrame,CP as isElementLink,sa as isEmbeddableElement,Gx as isExcalidrawElement,Jn as isFixedPointBinding,tr as isFlowchartNodeElement,Fo as isFrameElement,q as isFrameLikeElement,Me as isFreeDrawElement,pu as isFreeDrawElementType,nE as isHTMLSVGElement,Oo as isIframeElement,Ro as isIframeLikeElement,we as isImageElement,yl as isInGroup,_t as isInitializedImageElement,ed as isInvisiblySmallElement,bt as isLineElement,j as isLinearElement,Va as isLinearElementSimpleAndAlreadyBound,Ji as isLinearElementType,aa as isMagicFrameElement,jx as isMeasureTextSupported,yI as isNodeInFlowchart,OS as isNonDeletedElement,mn as isPathALoop,Aa as isPointInElement,Cx as isRectangularElement,la as isRectanguloidElement,Tm as isSelectedViaGroup,mu as isSharpArrow,Lx as isSimpleArrow,cb as isSomeElementSelected,Eu as isTextBindableContainer,oe as isTextElement,da as isUsingAdaptiveRadius,ca as isUsingProportionalRadius,Nx as isValidPolygon,fw as isValidTextContainer,tE as loadHTMLImageElement,kr as makeNextSelectedElementIds,li as maxBindingGap,xy as maybeBindLinearElement,iI as maybeParseEmbedSrc,ja as maybeSuggestBindingsForLinearElementAtCoords,fs as measureFontSizeFromWidth,Je as measureText,TS as moveAllLeft,AS as moveAllRight,SS as moveOneLeft,MS as moveOneRight,be as mutateElement,Fd as newArrowElement,rs as newElement,ge as newElementWith,YP as newEmbeddableElement,XP as newFrameElement,VP as newFreeDrawElement,UP as newIframeElement,ZP as newImageElement,$P as newLinearElement,jP as newMagicFrameElement,Rd as newTextElement,td as normalizeElementOrder,vr as normalizeFixedPoint,AI as normalizeSVG,or as normalizeText,mi as omitGroupsContainingFrameLikes,Om as omitPartialGroups,Ed as orderByFractionalIndex,eo as originalContainerCache,GP as parseElementLinkFromURL,Lu as parseTokens,Fl as pathsCache,vn as pointInsideBounds,GI as positionElementsOnGrid,ba as redrawTextBoundingBox,WP as refreshTextDimensions,Fm as removeAllElementsFromFrame,Tl as removeElementsFromFrame,Qy as removeFromSelectedGroups,o0 as renderElement,n0 as renderSelectionElement,kb as replaceAllElementsInFrame,qd as rescalePointsInElement,ma as resetOriginalContainerCache,uE as resizeMultipleElements,lE as resizeSingleElement,rE as resizeSingleTextElement,EE as resizeTest,Mm as selectGroup,El as selectGroupsForSelectedElements,gl as selectGroupsFromGivenElements,Vx as setCustomTextMetricsProvider,pw as shouldAllowVerticalAlign,Rb as shouldApplyFrameClip,Ey as shouldEnableBindingForPointerEvent,nS as shouldShowBoundingBox,Wo as shouldTestInside,ES as showSelectedShapeActions,em as snapToMid,mw as suppportsHorizontalAlign,Xf as syncInvalidIndices,ad as syncInvalidIndicesImmutable,mo as syncMovedIndices,rl as toggleLinePolygonState,u0 as toolIsArrow,jI as transformElements,wy as updateBindings,Ue as updateBoundElements,Ln as updateElbowArrowPoints,Ob as updateFrameMembershipOfSelectedElements,MI as updateImageCache,pa as updateOriginalContainerCache,Ra as validateElbowPoints,Uf as validateFractionalIndices,Tt as vectorToHeading,It as wrapText};