@myoc/element 0.19.514 → 0.19.516
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev/index.js +1 -0
- package/dist/dev/index.js.map +2 -2
- package/dist/prod/index.js +1 -1
- package/dist/types/element/src/newElement.d.ts +1 -0
- package/dist/types/element/src/types.d.ts +1 -0
- package/dist/types/excalidraw/actions/actionFrame.d.ts +1 -0
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +1 -0
- package/dist/types/excalidraw/scene/Renderer.d.ts +1 -0
- package/package.json +4 -4
package/dist/prod/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var ip=Object.create;var Ds=Object.defineProperty;var rp=Object.getOwnPropertyDe
|
|
|
18
18
|
L ${f+E} ${g+x}
|
|
19
19
|
C ${f} ${g}, ${f} ${g}, ${f+E} ${g-x}
|
|
20
20
|
L ${l-E} ${d+x}
|
|
21
|
-
C ${l} ${d}, ${l} ${d}, ${l+E} ${d+x}`,Qe(e,!0,a))}else s=t.polygon([[l,d],[c,u],[h,m],[f,g]],Qe(e,!1,a));return s}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Qe(e,!1,a));case"line":case"arrow":{let s,l=Qe(e,!1,a),d=e.points.length?e.points:[me(0,0)];if(U(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?s=[t.path(uc(d,16),Qe(e,!0,a))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(d)),s=[]):e.roundness?s=[t.curve(d,l)]:l.fill?s=[t.polygon(d,l)]:s=[t.linearPath(d,l)],e.type==="arrow"){let{startArrowhead:c=null,endArrowhead:u="arrow"}=e;if(c!==null){let h=lc(e,s,"start",c,t,l,o,a);s.push(...h)}if(u!==null){let h=lc(e,s,"end",u,t,l,o,a);s.push(...h)}}return s}case"freedraw":{let s=[];if($t(e.points)){let l=Ao(e.points,.75);s.push(t.curve(l,{...Qe(e,!1,a),stroke:"none"}))}return s.push($m(e)),s}case"frame":case"magicframe":case"text":case"image":return null;default:return _m(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},uc=(e,t)=>{let n=[];for(let i=1;i<e.length-1;i+=1){let r=e[i-1],a=e[i+1],s=e[i],l=bt(s,r),d=bt(a,s),c=Math.min(t,ac(e[i],a)/2,ac(e[i],r)/2);l?r[0]<s[0]?n.push([e[i][0]-c,e[i][1]]):n.push([e[i][0]+c,e[i][1]]):r[1]<s[1]?n.push([e[i][0],e[i][1]-c]):n.push([e[i][0],e[i][1]+c]),n.push(e[i]),d?a[0]<s[0]?n.push([e[i][0]-c,e[i][1]]):n.push([e[i][0]+c,e[i][1]]):a[1]<s[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(" ")},ti=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return $s(e);case"arrow":case"line":{let n=at.generateElementShape(e,null)[0],[,,,,o,i]=Q(e,t);return Ri(e)?Qs(e,n,me(e.x,e.y),e.angle,me(o,i)):qs(n,me(e.x,e.y),e.angle,me(o,i))}case"ellipse":return Zs(e);case"freedraw":{let[,,,,n,o]=Q(e,t);return Ks(e,me(n,o),Ri(e))}}},Jd=(e,t)=>{let n=[...e.points];if(t){if(!El(e.points))return null;let i=n[0],r=n[n.length-1];Math.hypot(i[0]-r[0],i[1]-r[1])>Vm||n.length<4?n.push(me(i[0],i[1])):n[n.length-1]=me(i[0],i[1])}return{polygon:t,points:n}},$m=e=>Km(Zm(e)),Zm=e=>{let t=e.simulatePressure?e.points:e.points.length?e.points.map(([n,o],i)=>[n,o,e.pressures[i]]):[[0,0,.5]];return rl(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:n=>Math.sin(n*Math.PI/2),last:!0})},dc=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],qm=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,Km=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,o,i,r)=>(i===t?n.push(o,dc(o,r[0]),"L",r[0],"Z"):n.push(o,dc(o,r[i+1])),n),["M",e[0],"Q"]).join(" ").replace(qm,"$1")};var $a=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&&!Ee(t))return i.bounds;if(o&&t.angle!==0){let a=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:a}),a}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,a,s,l,d]=Q(t,n);if(Pe(t)){let[c,u,h,m]=Za(t.points.map(([f,g])=>ce(G(f,g),G(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,h+t.x,m+t.y]}else if(ne(t))o=l0(t,l,d,n);else if(t.type==="diamond"){let[c,u]=ce(G(l,r),G(l,d),t.angle),[h,m]=ce(G(l,s),G(l,d),t.angle),[f,g]=ce(G(i,d),G(l,d),t.angle),[E,x]=ce(G(a,d),G(l,d),t.angle),y=Math.min(c,h,f,E),w=Math.min(u,m,g,x),M=Math.max(c,h,f,E),b=Math.max(u,m,g,x);o=[y,w,M,b]}else if(t.type==="ellipse"){let c=(a-i)/2,u=(s-r)/2,h=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(c*h,u*m),g=Math.hypot(u*h,c*m);o=[l-f,d-g,l+f,d+g]}else{let[c,u]=ce(G(i,r),G(l,d),t.angle),[h,m]=ce(G(i,s),G(l,d),t.angle),[f,g]=ce(G(a,s),G(l,d),t.angle),[E,x]=ce(G(a,r),G(l,d),t.angle),y=Math.min(c,h,f,E),w=Math.min(u,m,g,x),M=Math.max(c,h,f,E),b=Math.max(u,m,g,x);o=[y,w,M,b]}return o}},Q=(e,t,n=!1)=>{if(Pe(e))return n0(e);if(ne(e))return R.getElementAbsoluteCoords(e,t,n);if(te(e)){let o=t?De(e,t):null;if(j(o)){let{x:i,y:r}=R.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]},Ga=(e,t)=>{let n=ti(e,t),[o,i,r,a,s,l]=Q(e,t),d=G(s,l);if(n.type==="polycurve"){let x=n.data.map(w=>_t(w,10)),y=[];if(Ut(e)&&!e.polygon||j(e))for(let w of x){let M=0;for(;M<w.length-1;)y.push(Se(G(w[M][0],w[M][1]),G(w[M+1][0],w[M+1][1]))),M++}else{let w=x.flat(),M=0;for(;M<w.length-1;)y.push(Se(G(w[M][0],w[M][1]),G(w[M+1][0],w[M+1][1]))),M++}return y}else{if(n.type==="polyline")return n.data;if(e0(e)){let[E,x]=hn(e),y=x.map(M=>mc(M,d,e.angle)).flat();return[...hc(E,d,e.angle),...y]}else if(e.type==="diamond"){let[E,x]=mn(e),y=x.map(M=>mc(M,d,e.angle)).flat();return[...hc(E,d,e.angle),...y]}else if(n.type==="polygon"){if(te(e)){let y=De(e,t);if(y&&ne(y))return[Se(G(o,i),G(r,i)),Se(G(r,i),G(r,a)),Se(G(r,a),G(o,a)),Se(G(o,a),G(o,i))]}let E=n.data,x=[];for(let y=0;y<E.length-1;y++)x.push(Se(E[y],E[y+1]));return x}else if(n.type==="ellipse")return t0(e)}let[c,u,h,m,,,f,g]=[[o,i],[r,i],[o,a],[r,a],[s,i],[s,a],[o,l],[r,l]].map(E=>ce(E,d,e.angle));return[Se(c,u),Se(h,m),Se(c,h),Se(u,m),Se(c,g),Se(h,g),Se(u,f),Se(m,f)]},e0=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),hc=(e,t,n)=>e.map(o=>Se(ce(o[0],t,n),ce(o[1],t,n))),mc=(e,t,n)=>{let o=_t(e,10),i=0,r=[];for(;i<o.length-1;)r.push(Se(ce(G(o[i][0],o[i][1]),t,n),ce(G(o[i+1][0],o[i+1][1]),t,n))),i++;return r},t0=e=>{let t=G(e.x+e.width/2,e.y+e.height/2),n=e.width/2,o=e.height/2,i=[],r=[],a=90,s=Math.PI*2/a;for(let l=0;l<a;l++){let d=l*s,c=t[0]+n*Math.cos(d),u=t[1]+o*Math.sin(d);r.push(ce(G(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)i.push(Se(r[l],r[l+1]));return i.push(Se(r[r.length-1],r[0])),i},jb=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],no=e=>{let t=Math.floor(e.width/2)+1,n=0,o=e.width,i=Math.floor(e.height/2)+1,r=t,a=e.height;return[t,n,o,i,r,a,0,i]},fc=(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},gc=(e,t,n,o)=>{let i=t-e,r=n-t,a=o-n,s=3*i-6*r+3*a,l=6*r-6*i,d=3*i,c=l*l-4*s*d;if(!(c>=0))return!1;let h=null,m=null,f=1/0,g=1/0;return s===0?f=g=-d/l:(f=(-l+Math.sqrt(c))/(2*s),g=(-l-Math.sqrt(c))/(2*s)),f>=0&&f<=1&&(h=fc(f,e,t,n,o)),g>=0&&g<=1&&(m=fc(g,e,t,n,o)),[h,m]},Ni=(e,t,n,o)=>{let i=gc(e[0],t[0],n[0],o[0]),r=gc(e[1],t[1],n[1],o[1]),a=Math.min(e[0],o[0]),s=Math.max(e[0],o[0]);if(i){let c=i.filter(u=>u!==null);a=Math.min(a,...c),s=Math.max(s,...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[a,l,s,d]},Zo=(e,t)=>{let n=G(0,0),{minX:o,minY:i,maxX:r,maxY:a}=e.reduce((s,{op:l,data:d})=>{if(l==="move"){let c=xc(d);Xa(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=G(d[0],d[1]),u=G(d[2],d[3]),h=G(d[4],d[5]),m=t?t(c):c,f=t?t(u):u,g=t?t(h):h,E=t?t(n):n;n=h;let[x,y,w,M]=Ni(E,m,f,g);s.minX=Math.min(s.minX,x),s.minY=Math.min(s.minY,y),s.maxX=Math.max(s.maxX,w),s.maxY=Math.max(s.maxY,M)}return s},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[o,i,r,a]},Za=(e,t=0)=>{let n=1/0,o=1/0,i=-1/0,r=-1/0;for(let[a,s]of e)n=Math.min(n,a),o=Math.min(o,s),i=Math.max(i,a),r=Math.max(r,s);return[n-t,o-t,i+t,r+t]},n0=e=>{let[t,n,o,i]=Za(e.points),r=t+e.x,a=n+e.y,s=o+e.x,l=i+e.y;return[r,a,s,l,(r+s)/2,(a+l)/2]},o0=20,i0=15,r0=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"cardinality_many":case"cardinality_one_or_many":case"cardinality_zero_or_many":return i0;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return o0;default:return 15}},a0=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},je=(e,t,n,o,i=0)=>{if(o===null||t.length<1)return null;let r=jt(t[0]);if(r.length<1)return null;let a=n==="start"?1:r.length-1,s=r[a].data;Xa(s.length===6,"Op data length is not 6");let l=G(s[4],s[5]),d=G(s[2],s[3]),c=G(s[0],s[1]),u=r[a-1],h=G(0,0);if(u.op==="move"){let A=xc(u.data);Xa(A!=null,"Op data is not a point"),h=A}else u.op==="bcurveTo"&&(h=G(u.data[4],u.data[5]));let m=(A,_)=>Math.pow(1-A,3)*l[_]+3*A*Math.pow(1-A,2)*d[_]+3*Math.pow(A,2)*(1-A)*c[_]+h[_]*Math.pow(A,3),[f,g]=n==="start"?h:l,[E,x]=[m(.3,0),m(.3,1)],y=Math.hypot(f-E,g-x),w=(f-E)/y,M=(g-x)/y,b=r0(o),S=0;{let[A,_]=n==="end"?e.points[e.points.length-1]:e.points[0],[X,ve]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];S=Math.hypot(A-X,_-ve)}let L=Math.min(b,S*(o==="diamond"||o==="diamond_outline"?.25:.5)),T=f-w*L*i,D=g-M*L*i,B=T-w*L,F=D-M*L;if(o==="circle"||o==="circle_outline"){let A=Math.hypot(F-D,B-T)+e.strokeWidth-2;return[T,D,A]}let O=a0(o);if(o==="cardinality_many"||o==="cardinality_one_or_many"){let[A,_]=ce(G(T,D),G(B,F),Ya(-O)),[X,ve]=ce(G(T,D),G(B,F),Ya(O));return[B,F,A,_,X,ve]}let[K,Y]=ce(G(B,F),G(T,D),-O*Math.PI/180),[se,H]=ce(G(B,F),G(T,D),Ya(O));if(o==="diamond"||o==="diamond_outline"){let A,_;if(n==="start"){let[X,ve]=e.points.length>1?e.points[1]:[0,0];[A,_]=ce(G(T+L*2,D),G(T,D),Math.atan2(ve-D,X-T))}else{let[X,ve]=e.points.length>1?e.points[e.points.length-2]:[0,0];[A,_]=ce(G(T-L*2,D),G(T,D),Math.atan2(D-ve,T-X))}return[T,D,K,Y,A,_,se,H]}return[T,D,K,Y,se,H]},s0=e=>{let t=Hn.generator(),n=Qe(e),o=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[o](e.points,n)},l0=(e,t,n,o)=>{let i=Z(e,o);if(e.points.length<2){let[u,h]=e.points[0],[m,f]=ce(G(e.x+u,e.y+h),G(t,n),e.angle),g=[m,f,m,f];if(i){let E=R.getMinMaxXYWithBoundText(e,o,[m,f,m,f],i);g=[E[0],E[1],E[2],E[3]]}return g}let a=at.get(e,null)?.[0]??s0(e),s=jt(a),d=Zo(s,([u,h])=>ce(G(e.x+u,e.y+h),G(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(i){let u=R.getMinMaxXYWithBoundText(e,o,c,i);c=[u[0],u[1],u[2],u[3]]}return c},ue=(e,t,n=!1)=>$a.getBounds(e,t,n),We=(e,t)=>{if(!Qm(e))return[0,0,0,0];let n=1/0,o=-1/0,i=1/0,r=-1/0,a=t||Ec(e);return e.forEach(s=>{let[l,d,c,u]=ue(s,a);n=Math.min(n,l),i=Math.min(i,d),o=Math.max(o,c),r=Math.max(r,u)}),[n,i,o,r]},Vb=(e,t)=>{let[n,o,i,r]=We(e);return[n+t.x,o+t.y,i+t.x,r+t.y]},pn=(e,t,n,o)=>{if(!(ne(e)||Pe(e)))return[e.x,e.y,e.x+t,e.y+n];let i=pc(0,t,pc(1,n,e.points,o),o),r;if(Pe(e))r=Za(i);else{let c=Hn.generator(),u=e.roundness?c.curve(i,Qe(e)):c.linearPath(i,Qe(e)),h=jt(u);r=Zo(h)}let[a,s,l,d]=r;return[a+e.x,s+e.y,l+e.x,d+e.y]},za=(e,t)=>{let n=Hn.generator(),o=e.roundness==null?n.linearPath(t,Qe(e)):n.curve(t,Qe(e)),i=jt(o),[r,a,s,l]=Zo(i);return[r+e.x,a+e.y,s+e.x,l+e.y]},Ub=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,o=e[0],i=Ec(e);return e.forEach(r=>{let[a,s,l,d]=ue(r,i),c=Jm(G((a+l)/2,(s+d)/2),G(t.x,t.y));c<n&&(n=c,o=r)}),ue(o,i)},Fe=e=>{let[t,n,o,i]=We(e);return{minX:t,minY:n,maxX:o,maxY:i,width:o-t,height:i-n,midX:(t+o)/2,midY:(n+i)/2}},Yb=({scrollX:e,scrollY:t,width:n,height:o,zoom:i})=>[-e,-t,-e+n/i.value,-t+o/i.value],xn=e=>G(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),pt=(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=le(e,t),[r,a]=ce(G(o.minX,o.minY),i,e.angle),[s,l]=ce(G(o.maxX,o.minY),i,e.angle),[d,c]=ce(G(o.maxX,o.maxY),i,e.angle),[u,h]=ce(G(o.minX,o.maxY),i,e.angle),m=[Math.min(r,s,d,u),Math.min(a,l,c,h),Math.max(r,s,d,u),Math.max(a,l,c,h)];if(n){let[f,g,E,x]=n;return[m[0]-x,m[1]-f,m[2]+g,m[3]+E]}return m},wt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],d0=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],Ot=(e,t)=>{if(e==null||t==null)return!1;let[n,o,i,r]=e,[a,s,l,d]=t;return n<l&&i>a&&o<d&&r>s},tr=(e,t)=>[G(t[0],t[1]),G(t[0],t[3]),G(t[2],t[1]),G(t[2],t[3])].every(n=>d0(n,e)),le=(e,t,n=0,o=0)=>{if(ne(e)||Pe(e)){let[a,s,l,d]=Q(e,t),[c,u]=G((a+l)/2,(s+d)/2);return G(c+n,u+o)}let[i,r]=xn(ue(e,t));return G(i+n,r+o)};var h0=.1,wc=e=>ne(e)||Pe(e)?e.points.length<2||e.points.length===2&&j(e)&&p0(e.points[0],e.points[e.points.length-1],h0):e.width===0&&e.height===0,Gd=(e,t,n,o,i)=>{let[r,a,s,l]=ue(e,i),d=ur({clientX:o.offsetLeft,clientY:o.offsetTop},o),c=ur({clientX:o.offsetLeft+t,clientY:o.offsetTop+n},o);return d.x<=s&&d.y<=l&&c.x>=r&&c.y>=a},e6=(e,t,n,o,i,r)=>{let[a,s,l,d]=We(e,i),c=ur({clientX:o.offsetLeft+(r?.left||0),clientY:o.offsetTop+(r?.top||0)},o),u=ur({clientX:o.offsetLeft+t-(r?.right||0),clientY:o.offsetTop+n-(r?.bottom||0)},o);return a>=c.x&&s>=c.y&&l<=u.x&&d<=u.y},qa=(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)/rn)*rn;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}},ec=(e,t,n,o,i)=>{let r=n-e,a=o-t,s=Math.atan2(a,r),l=Math.round(s/rn)*rn;if(i){let d=Math.floor(i/rn)*rn;c0(s,d,d+rn)&&(u0(s,i)<rn/6?l=i:yc(s)>yc(i)?l=d+rn:l=d)}if(l===0)a=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,h=-1/d,m=-1,f=o-h*n,g=(c*f-m*u)/(d*m-h*c),E=(u*h-f*d)/(d*m-h*c);r=g-e,a=E-t}return{width:r,height:a}},t6=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t};I();var s6=(e,t,n,o)=>{let i=ir(e,n.getNonDeletedElementsMap(),o),r=Fe(e);return i.flatMap(a=>{let s=m0(a,r,t);return a.map(l=>{let d=n.mutateElement(l,{x:l.x+s.x,y:l.y+s.y});return Re(l,n,{simultaneouslyUpdated:a}),d})})},m0=(e,t,{axis:n,position:o})=>{let i=Fe(e),[r,a]=n==="x"?["minX","maxX"]:["minY","maxY"],s={x:0,y:0};return o==="start"?{...s,[n]:t[r]-i[r]}:o==="end"?{...s,[n]:t[a]-i[a]}:{...s,[n]:(t[r]+t[a])/2-(i[r]+i[a])/2}};I();I();var pr=class{root;gap;constructor(t=0){this.root=null,this.gap=t}fit(t){let n=t.length,o=n>0?t[0].w:0,i=n>0?t[0].h:0;this.root={x:0,y:0,w:o,h:i};for(let r=0;r<n;r++){let a=t[r],s=this.findNode(this.root,a.w,a.h);s?a.fit=this.splitNode(s,a.w,a.h):a.fit=this.growNode(a.w,a.h)}}findNode(t,n,o){return t?t.used?this.findNode(t.right||null,n,o)||this.findNode(t.down||null,n,o):n<=t.w&&o<=t.h?t:null:null}splitNode(t,n,o){return t.used=!0,t.down={x:t.x,y:t.y+o+this.gap,w:t.w,h:t.h-o-this.gap},t.right={x:t.x+n+this.gap,y:t.y,w:t.w-n-this.gap,h:o},t}growNode(t,n){if(!this.root)return null;let o=t<=this.root.w,i=n<=this.root.h,r=i&&this.root.h>=this.root.w+t+this.gap,a=o&&this.root.w>=this.root.h+n+this.gap;return r?this.growRight(t,n):a?this.growDown(t,n):i?this.growRight(t,n):o?this.growDown(t,n):null}growRight(t,n){if(!this.root)return null;this.root={used:!0,x:0,y:0,w:this.root.w+t+this.gap,h:this.root.h,down:this.root,right:{x:this.root.w+this.gap,y:0,w:t,h:this.root.h}};let o=this.findNode(this.root,t,n);return o?this.splitNode(o,t,n):null}growDown(t,n){if(!this.root)return null;this.root={used:!0,x:0,y:0,w:this.root.w,h:this.root.h+n+this.gap,down:{x:0,y:this.root.h+this.gap,w:this.root.w,h:n},right:this.root};let o=this.findNode(this.root,t,n);return o?this.splitNode(o,t,n):null}};I();var f0=[1,1.08,1.18,1.32,1.5,1.75,2.1,2.6,3.25],g0=[1,4/3,3/4,3/2,2/3,2,1/2],E0=(e,t)=>{let n=Math.max(e.length,t.length);for(let o=0;o<n;o++){let i=(e[o]??0)-(t[o]??0);if(i!==0)return i}return 0},x0=(e,t)=>t.packedW*t.packedH-e.packedW*e.packedH||Math.max(t.packedW,t.packedH)-Math.max(e.packedW,e.packedH)||t.packedH-e.packedH||t.packedW-e.packedW,bc=(e,t,n)=>Math.min(Math.max(e,t),n),y0=(e,t)=>e.x<t.x+t.w&&e.x+e.w>t.x&&e.y<t.y+t.h&&e.y+e.h>t.y,w0=(e,t)=>t.x>=e.x&&t.y>=e.y&&t.x+t.w<=e.x+e.w&&t.y+t.h<=e.y+e.h,Mc=e=>{let t=e.filter(n=>n.fit);return t.length===0?null:t.reduce((n,o)=>({minX:Math.min(n.minX,o.fit.x),minY:Math.min(n.minY,o.fit.y),maxX:Math.max(n.maxX,o.fit.x+o.actualW),maxY:Math.max(n.maxY,o.fit.y+o.actualH)}),{minX:t[0].fit.x,minY:t[0].fit.y,maxX:t[0].fit.x+t[0].actualW,maxY:t[0].fit.y+t[0].actualH})},b0=(e,t)=>{let n=(t.minX+t.maxX)/2,o=(t.minY+t.maxY)/2;return e.reduce((i,r)=>{if(!r.fit)return i;let a=r.fit.x+r.actualW/2,s=r.fit.y+r.actualH/2;return i+Math.abs(a-n)+Math.abs(s-o)},0)},M0=e=>{let t=[];e:for(let n=0;n<e.length;n++){let o=e[n];if(!(o.w<=0||o.h<=0)){for(let i=0;i<e.length;i++)if(n!==i&&w0(e[i],o))continue e;t.some(i=>i.x===o.x&&i.y===o.y&&i.w===o.w&&i.h===o.h)||t.push(o)}}return t},P0=(e,t)=>{let n=[];for(let o of e){if(!y0(o,t)){n.push(o);continue}t.x>o.x&&n.push({x:o.x,y:o.y,w:t.x-o.x,h:o.h}),t.x+t.w<o.x+o.w&&n.push({x:t.x+t.w,y:o.y,w:o.x+o.w-(t.x+t.w),h:o.h}),t.y>o.y&&n.push({x:o.x,y:o.y,w:o.w,h:t.y-o.y}),t.y+t.h<o.y+o.h&&n.push({x:o.x,y:t.y+t.h,w:o.w,h:o.y+o.h-(t.y+t.h)})}return M0(n)},I0=(e,t,n,o)=>{let i=e.x+e.w-t.packedW,r=e.y+e.h-t.packedH,a=[{x:e.x,y:e.y},{x:i,y:e.y},{x:e.x,y:r},{x:i,y:r}];return n==="center-distance"&&a.push({x:bc(o.x-t.actualW/2,e.x,i),y:bc(o.y-t.actualH/2,e.y,r)}),a.filter((s,l,d)=>d.findIndex(c=>c.x===s.x&&c.y===s.y)===l)},S0=(e,t,n,o,i,r,a)=>{let s=e.w*e.h-t.packedW*t.packedH,l=e.w-t.packedW,d=e.h-t.packedH,c=Math.min(l,d),u=Math.max(l,d);if(o==="best-area-fit")return[s,c,u,n.y,n.x];let h=i?{x:(i.minX+i.maxX)/2,y:(i.minY+i.maxY)/2}:{x:r/2,y:a/2},m=n.x+t.actualW/2,f=n.y+t.actualH/2,g=Math.abs(m-h.x)+Math.abs(f-h.y),E=i?{minX:Math.min(i.minX,n.x),minY:Math.min(i.minY,n.y),maxX:Math.max(i.maxX,n.x+t.actualW),maxY:Math.max(i.maxY,n.y+t.actualH)}:{minX:n.x,minY:n.y,maxX:n.x+t.actualW,maxY:n.y+t.actualH},x=E.maxX-E.minX,y=E.maxY-E.minY,w=x*y;return[g,w,s,c,u]},v0=(e,t,n,o)=>{let i=[{x:0,y:0,w:t,h:n}];for(let l of e){let d=Mc(e),c=null;for(let u of i){if(l.packedW>u.w||l.packedH>u.h)continue;let h=d?{x:(d.minX+d.maxX)/2,y:(d.minY+d.maxY)/2}:{x:t/2,y:n/2},m=I0(u,l,o,h);for(let f of m){let g=S0(u,l,f,o,d,t,n);(!c||E0(g,c.score)<0)&&(c={x:f.x,y:f.y,score:g})}}if(!c)return null;l.fit={x:c.x,y:c.y},i=P0(i,{x:c.x,y:c.y,w:l.packedW,h:l.packedH})}let r=Mc(e);if(!r)return{width:0,height:0,spread:0};let a=r.minX,s=r.minY;return e.forEach(l=>{l.fit&&(l.fit={x:l.fit.x-a,y:l.fit.y-s})}),{width:r.maxX-r.minX,height:r.maxY-r.minY,spread:b0(e,{minX:0,minY:0,maxX:r.maxX-r.minX,maxY:r.maxY-r.minY})}},Pc=(e,t={})=>{let n=Math.max(t.gap??0,0),o=t.heuristic??"best-area-fit";if(e.forEach(d=>{d.fit=null}),e.length===0)return{width:0,height:0};let i=e.map(d=>({source:d,actualW:d.w,actualH:d.h,packedW:d.w+n,packedH:d.h+n,fit:null})).sort(x0),r=i.reduce((d,c)=>d+c.packedW*c.packedH,0),a=Math.max(...i.map(d=>d.packedW)),s=Math.max(...i.map(d=>d.packedH)),l=null;for(let d of f0){let c=r*d;for(let u of g0){let h=Math.max(a,Math.ceil(Math.sqrt(c*u))),m=Math.max(s,Math.ceil(c/h)),f=i.map(M=>({...M,fit:null})),g=v0(f,h,m,o);if(!g)continue;let E={width:g.width,height:g.height,spread:g.spread,blocks:f};if(!l){l=E;continue}let x=E.width*E.height-l.width*l.height,y=Math.abs(E.width-E.height),w=Math.abs(l.width-l.height);(x<0||x===0&&(y<w||y===w&&(E.spread<l.spread||E.spread===l.spread&&E.width+E.height<l.width+l.height)))&&(l=E)}if(l)break}return l?(l.blocks.forEach(d=>{d.source.fit=d.fit}),{width:l.width,height:l.height}):null};var A0=(e,t,n)=>{let o=Fe(t),i=n.x-o.minX,r=n.y-o.minY;t.forEach(a=>{e.mutateElement(a,{x:a.x+i,y:a.y+r})})},Ic=e=>e.map(t=>({w:t.boundingBox.width,h:t.boundingBox.height,group:t.group})).sort((t,n)=>n.w*n.h-t.w*t.h||Math.max(n.w,n.h)-Math.max(t.w,t.h)||n.h-t.h||n.w-t.w),Sc=(e,t,n)=>{let o=t.filter(i=>i.fit);return o.forEach(i=>{A0(e,i.group,{x:n.x+(i.fit?.x??0),y:n.y+(i.fit?.y??0)})}),o.flatMap(i=>i.group)},vc=(e,t,n)=>{let o=t.flatMap(l=>l.group),i=Fe(o),r={x:i.minX,y:i.minY},a=Ic(t);return new pr(n).fit(a),Sc(e,a,r)},Ka=(e,t,n,o)=>{let i=t.flatMap(d=>d.group),r=Fe(i),a={x:r.minX,y:r.minY},s=Ic(t);return Pc(s,{gap:n,heuristic:o})?Sc(e,s,a):(console.warn(`Packing heuristic [${o}] failed - using binary tree packer`),vc(e,t,n))},x6=(e,t,n,o,i)=>{let a=or(t,n).map(s=>({group:s,boundingBox:Fe(s)}));switch(o){case"bin-packing":case"bin-packing-center":return Ka(e,a,i,"center-distance");case"bin-packing-max-rects":return Ka(e,a,i,"best-area-fit");case"bin-packing-binary-tree":return vc(e,a,i);default:return console.warn(`Unimplemented algorithm [${o}] - using bin-packing`),Ka(e,a,i,"center-distance")}};I();import{arrayToMap as bf,arrayToObject as an,assertNever as Yc,isDevEnv as Dn,isShallowEqual as Xc,isTestEnv as Gn,randomInteger as Uc}from"@excalidraw/common";I();import{assertNever as N0,COLOR_PALETTE as H0,isDevEnv as z0,isTestEnv as W0,randomId as _0,Emitter as Tc,toIterable as ho}from"@excalidraw/common";I();import{ORIG_ID as C0,randomId as kc,randomInteger as B0,arrayToMap as D0,castArray as Qa,findLastIndex as po,getUpdatedTimestamp as G0,isTestEnv as O0}from"@excalidraw/common";I();import{arrayToMap as k0}from"@excalidraw/common";var T0=e=>{let t=(i,r)=>i.groupIds[i.groupIds.length-r-1],n=(i,r)=>{let a=new Map,s=[];for(let l of i){let d=t(l,r);if(d===void 0){s.push(l);continue}let c=a.get(d);c||(c=[],a.set(d,c),s.push(d)),c.push(l)}return s.flatMap(l=>typeof l=="string"?n(a.get(l),r+1):[l])},o=n(e,0);return o.length!==e.length?(console.error("defragmentGroups: lost some elements... bailing!"),e):o},L0=e=>{let t=k0(e),n=new Set;for(let o of e)if(!n.has(o)){if(o.boundElements?.length){n.add(o);for(let i of o.boundElements){let r=t.get(i.id);r&&i.type==="text"&&n.add(r)}continue}o.type==="text"&&o.containerId&&t.get(o.containerId)?.boundElements?.some(i=>i.id===o.id)||n.add(o)}return n.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...n]},Ac=e=>L0(T0(e));var R0=(e,t,n,o)=>{let i=es(n);return O0()&&F0(i,n.id),i.id=kc(),i.updated=G0(),o&&(i.seed=B0(),ad(i)),i.groupIds=Nd(i.groupIds,e,r=>(t.has(r)||t.set(r,kc()),t.get(r))),i},B6=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},o=new Map,i=new Map,r=[],a=[],s=new Map,l=new Map,d=new Map,c=D0(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(x=>[x.id,x])),h=e.type==="everything"&&e.preserveFrameChildrenOrder;if(e.type==="in-place")for(let x of Object.keys(e.appState.selectedGroupIds))t.filter(y=>y.groupIds?.includes(x)).forEach(y=>u.set(y.id,y));t=Ac(t);let m=t.slice(),f=x=>{let w=Qa(x).reduce((M,b)=>{if(o.has(b.id))return M;o.set(b.id,!0);let S=R0(n.editingGroupId,i,b,e.randomizeSeed);return o.set(S.id,!0),d.set(S.id,S),s.set(b.id,S.id),l.set(S.id,b),a.push(b),r.push(S),M.push(S),M},[]);return Array.isArray(x)?w:w[0]||null},g=(x,y)=>{if(y){if(x>m.length-1){m.push(...Qa(y));return}m.splice(x+1,0,...Qa(y))}},E=new Set(t.filter(x=>u.has(x.id)&&ee(x)).map(x=>x.id));for(let x of t){if(o.has(x.id)||!u.has(x.id))continue;let y=Fa(n,x);if(y){let w=ze(t,y).flatMap(b=>ee(b)&&!h?[...kn(t,b.id),b]:[b]),M=po(m,b=>b.groupIds?.includes(y));g(M,f(w));continue}if(!(!h&&x.frameId&&E.has(x.frameId))){if(ee(x)){let w=x.id;if(h){g(po(m,S=>S.id===w),f(x));continue}let M=kn(t,w),b=po(m,S=>S.frameId===w||S.id===w);g(b,f([...M,x]));continue}if(Ct(x)){let w=Z(x,c),M=po(m,b=>b.id===x.id||"containerId"in b&&b.containerId===x.id);w?g(M,f([x,w])):g(M,f(x));continue}if(Ee(x)){let w=De(x,c),M=po(m,b=>b.id===x.id||b.id===w?.id);w?g(M,f([w,x])):g(M,f(x));continue}g(po(m,w=>w.id===x.id),f(x))}}if(fd(r,s,d),Ad(m,a,s),e.overrides)for(let x of r){let y=l.get(x.id);y&&Object.assign(x,e.overrides({duplicateElement:x,origElement:y,origIdToDuplicateId:s}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:m,origIdToDuplicateId:s}},Ja=(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]=Ja(e[i],t+1)}return o}if(Array.isArray(e)){let o=e.length,i=new Array(o);for(;o--;)i[o]=Ja(e[o],t+1);return i}return C.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},es=e=>Ja(e),F0=(e,t)=>{Object.defineProperty(e,C0,{value:t,writable:!1,enumerable:!1})};var Je={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},Lc=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Tc;onStoreIncrementEmitter=new Tc;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Bn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Je.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,o;if("change"in t)o=t.change;else{let r=Bn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),a=r.maybeClone(n,t.elements?Sd(t.elements):void 0,t.appState);o=ni.create(r,a)}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=Bn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,o=void 0){let i=this.snapshot,r,a;if(n?r=n:r=ni.create(i,t),o?a=o:a=os.calculate(i,t),!a.isEmpty()){let s=new ts(r,a);this.onDurableIncrementEmitter.trigger(s),this.onStoreIncrementEmitter.trigger(s)}}emitEphemeralIncrement(t,n=void 0){let o;if(n)o=n;else{let r=this.snapshot;o=ni.create(r,t)}let i=new ns(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===Je.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 Je.IMMEDIATELY:this.emitDurableIncrement(o,i,r);break;case Je.NEVER:case Je.EVENTUALLY:this.emitEphemeralIncrement(o,i);break;default:N0(n,"Unknown store action")}}finally{switch(n){case Je.IMMEDIATELY:case Je.NEVER:this.snapshot=o;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Je.IMMEDIATELY)?t=Je.IMMEDIATELY:this.scheduledMacroActions.has(Je.NEVER)?t=Je.NEVER:t=Je.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Je).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()),W0()||z0())throw new Error(t)}}},ni=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)}},hr=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},ts=class extends hr{constructor(n,o){super("durable",n);this.change=n;this.delta=o}},ns=class extends hr{constructor(n){super("ephemeral",n);this.change=n}},os=class e{constructor(t,n,o){this.id=t;this.elements=n;this.appState=o}static create(t,n,o={id:_0()}){return new this(o.id,t,n)}static calculate(t,n){let o=n.metadata.didElementsChange?Cn.calculate(t.elements,n.elements):Cn.empty(),i=n.metadata.didAppStateChange?Ln.calculate(t.appState,n.appState):Ln.empty();return this.create(o,i)}static restore(t){let{id:n,elements:o,appState:i}=t;return new this(n,Cn.restore(o),Ln.restore(i))}static load({id:t,elements:{added:n,removed:o,updated:i},appState:{delta:r}}){let a=Cn.create(n,o,i),s=Ln.create(r);return new this(t,a,s)}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,a]=t.elements.applyTo(n,Bn.empty().elements,i),[s,l]=t.appState.applyTo(o,r);return[r,s,a||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(Cn.empty(),Ln.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Bn=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,Cc(n)?n:mo(n),o)}static empty(){return new e(new Map,j0(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let o of ho(t.elements))this.elements.get(o.id)||(n[o.id]=He(o,{isDeleted:!0}));for(let o of ho(this.elements))t.elements.get(o.id)!==o&&(n[o.id]=o);return n}getChangedAppState(t){return $.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=mo({...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===Je.EVENTUALLY&&(i.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,i),a=this.maybeCreateAppStateSnapshot(o,i),s=!1,l=!1;return this.elements!==r&&(s=!0),this.appState!==a&&(l=!0),!s&&!l?this:new e(r,a,{didElementsChange:s,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let o=Cc(t)?t:mo(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=$.isRightDifferent(this.appState,t);if(!o)return;let i=Gc(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 ho(this.elements))t.get(r.id)||o.set(r.id,He(r,{isDeleted:!0}));for(let r of ho(t)){let a=this.elements.get(r.id);if(!a||a.version<r.version){if(Ae(r)&&!zn(r))continue;o.set(r.id,r)}}if(!o.size)return;let i=Dc(o);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===i))return this._lastChangedElementsHash=i,o}createElementsSnapshot(t){let n=new Map;for(let o of ho(this.elements))n.set(o.id,o);for(let o of ho(t))n.set(o.id,es(o));return n}},Bc="__observedAppState",j0=()=>({name:null,editingGroupId:null,viewBackgroundColor:H0.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),mo=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,Bc,{value:!0,enumerable:!1}),t},Cc=e=>!!Reflect.get(e,Bc);I();var Vc=si(Hc(),1);import{randomInteger as lf,arrayToMap as df,toBrandedType as zc,isDevEnv as Wc,isTestEnv as _c,toArray as cf}from"@excalidraw/common";import{isNonDeletedElement as uf}from"@excalidraw/element";import{isFrameLikeElement as pf}from"@excalidraw/element";import{getElementsInGroup as hf}from"@excalidraw/element";import{syncInvalidIndices as mf,syncMovedIndices as ff,validateFractionalIndices as gf}from"@excalidraw/element";import{getSelectedElements as Ef}from"@excalidraw/element";import{mutateElement as xf}from"@excalidraw/element";var jc=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}},yf=(0,Vc.default)(e=>{(Wc()||_c()||window?.DEBUG_FRACTIONAL_INDICES)&&gf(e,{shouldThrow:Wc()||_c(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),wf=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let o of t)n+=`${o}:${e[o]?"1":"0"}`;return n},fo=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=zc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=zc(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=wf(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=Ef(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&&uf(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=cf(t),i=[];n?.skipValidation||yf(o),this.elements=mf(o),this.elementsMap.clear(),this.elements.forEach(a=>{pf(a)&&i.push(a),this.elementsMap.set(a.id,a)});let r=jc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=i,this.nonDeletedFramesLikes=jc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=lf();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementsAtIndex(t,n){if(!t.length)return;if(n===null&&(n=this.elements.length),!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let o=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];ff(o,df(t)),this.replaceAllElements(o)}insertElement=t=>{this.insertElementsAtIndex([t],null)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),o=n.get(t);return o?[o]:hf(n,t)};mutateElement(t,n,o={informMutation:!0,isDragging:!1}){let i=this.getNonDeletedElementsMap(),{version:r}=t,{version:a}=xf(t,i,n,o);return this.elementsMap.has(t.id)&&r!==a&&o.informMutation&&this.triggerUpdate(),t}};var $=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,a=o&&i!=="deleted"?o(n,"inserted"):n;return new e(r,a)}static calculate(t,n,o,i){if(t===n)return e.empty();let r={},a={};for(let d of this.getDifferences(t,n))r[d]=t[d],a[d]=n[d];let[s,l]=i?i(r,a):[r,a];return e.create(s,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(an(t??[],i),an(n??[],i),an(o??[],i)))}static diffObjects(t,n,o,i){if(!t[o]&&!n[o])return;let r=t[o]!==null&&typeof t[o]=="object",a=n[o]!==null&&typeof n[o]=="object";if(r||a){let s=t[o]??{},l=n[o]??{},d=e.getLeftDifferences(s,l).reduce((u,h)=>(u[h]=i(s[h]),u),{}),c=e.getRightDifferences(s,l).reduce((u,h)=>(u[h]=i(l[h]),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]:[],a=Array.isArray(n[o])?n[o]:[],s=an(e.getLeftDifferences(an(r,i),an(a,i)),d=>d),l=an(e.getRightDifferences(an(r,i),an(a,i)),d=>d);if(Object.keys(s).length||Object.keys(l).length){let d=r.filter(u=>s[i?i(u):String(u)]),c=a.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(a=>a in o):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(o)])):Yc(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let a of r){let s=n[a],l=o[a];if(s!==l){if(!i&&typeof s=="object"&&typeof l=="object"&&s!==null&&l!==null&&Xc(s,l))continue;yield a}}}},Ln=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let o=$.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($.create({},{}))}inverse(){let t=$.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=$.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),o=$.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),i=$.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=$.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),a=$.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),s=$.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(a).length||Object.keys(s).length)&&(d.lockedMultiSelections=a,l.lockedMultiSelections=s),this.delta=$.merge(this.delta,t.delta,$.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:o={},selectedGroupIds:i={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:a={},selectedGroupIds:s={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=$.mergeObjects(t.selectedElementIds,a,o),h=$.mergeObjects(t.selectedGroupIds,s,i),m=$.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new R(n.get(d.elementId),n,d.isEditing):null,g={...t,...c,selectedElementIds:u,selectedGroupIds:h,lockedMultiSelections:m,selectedLinearElement:typeof d<"u"?f:t.selectedLinearElement},E=this.filterInvisibleChanges(t,g,n);return[g,E]}catch(o){if(console.error("Couldn't apply appstate change",o),Gn()||Dn())throw o;return[t,!1]}}isEmpty(){return $.isEmpty(this.delta)}filterInvisibleChanges(t,n,o){let i=mo(t),r=mo(n),a=$.isRightDifferent(e.stripElementsProps(i),e.stripElementsProps(r)),s=$.isRightDifferent(e.stripStandaloneProps(i),e.stripStandaloneProps(r));if(!a&&!s)return!1;let l={value:a};if(s){let d=$.getRightDifferences(e.stripStandaloneProps(i),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=Od(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 y=n[u];if(!y)l.value=!0;else{let w=o.get(y);w&&!w.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let h=n[u];h?c.has(h)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let y=o.get(m.elementId);y&&!y.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},g=n[u]||{};Xc(f,g)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,x=n[u]||null;E!==x&&(l.value=!0);break;default:Yc(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 a of i){let s=n.get(a);s&&!s.isDeleted?o.value=!0:delete r[a]}return r}static filterSelectedGroups(t,n,o){if(!Object.keys(t).length)return o.value=!0,t;let r={...t};for(let a of Object.keys(r))n.has(a)?o.value=!0:delete r[a];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:o,selectedElementIds:i,selectedLinearElement:r,croppingElementId:a,lockedMultiSelections:s,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:o,...i}=t;return i}static postProcess(t,n){try{$.diffObjects(t,n,"selectedElementIds",o=>!0),$.diffObjects(t,n,"selectedGroupIds",o=>o??!1),$.diffObjects(t,n,"lockedMultiSelections",o=>o??{})}catch(o){if(console.error("Couldn't postprocess appstate change deltas."),Gn()||Dn())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}},Cn=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 a={},s={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(o)];for(let[c,u]of d)this.satisfiesAddition(u)?a[c]=u:this.satisfiesRemoval(u)?s[c]=u:l[c]=u;r=new e(a,s,l)}else r=new e(t,n,o);return(Gn()||Dn())&&(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 a of t.values())if(!n.get(a.id)){let l={...a},d={isDeleted:!0,version:a.version+1,versionNonce:Uc()},c=$.create(l,d,e.stripIrrelevantProps);a.isDeleted?r[a.id]=c:i[a.id]=c}for(let a of n.values()){let s=t.get(a.id);if(!s){let l={isDeleted:!0,version:a.version-1,versionNonce:Uc()},d={...a},c=$.create(l,d,e.stripIrrelevantProps);a.isDeleted?r[a.id]=c:o[a.id]=c;continue}if(s.versionNonce!==a.versionNonce){let l=$.calculate(s,a,e.stripIrrelevantProps,e.postProcess);if(typeof s.isDeleted=="boolean"&&typeof a.isDeleted=="boolean"&&s.isDeleted!==a.isDeleted){s.isDeleted&&!a.isDeleted?o[a.id]=l:i[a.id]=l;continue}r[a.id]=l}}return e.create(o,i,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let a={};for(let[s,{inserted:l,deleted:d}]of Object.entries(r))a[s]=$.create({...l},{...d});return a},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,h)=>{let m;switch(h){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 g of Object.keys(u))switch(g){case"boundElements":f[g]=u[g];break;default:f[g]=m[g]}return f},r=d=>{let c={};for(let[u,h]of Object.entries(d)){let m=t.get(u),f=n.get(u),g=null;m||f?g=$.create(h.deleted,h.inserted,i(m,f),o):g=h,$.isInnerDifferent(g.deleted,g.inserted)&&(c[u]=g)}return c},a=r(this.added),s=r(this.removed),l=r(this.updated);return e.create(a,s,l,{shouldRedistribute:!0})}applyTo(t,n=Bn.empty().elements,o){let i=new Map(t),r,a={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let s=e.createApplier(t,i,n,a,o),l=s(this.added),d=s(this.removed),c=s(this.updated),u=this.resolveConflicts(t,i,a.applyDirection);r=new Map([...l,...d,...c,...u])}catch(s){if(console.error("Couldn't apply elements delta",s),Gn()||Dn())throw s;return[t,!0]}try{i=e.reorderElements(i,r,a),e.redrawElements(i,r)}catch(s){if(console.error("Couldn't mutate elements after applying elements change",s),Gn()||Dn())throw s}finally{return[i,a.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:o,updated:i}=t,r=(a,s)=>{let l=$.mergeArrays(a.deleted.boundElements??[],s.deleted.boundElements??[],void 0,c=>c.id)??[],d=$.mergeArrays(a.inserted.boundElements??[],s.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return $.create({boundElements:l},{boundElements:d})};for(let[a,s]of Object.entries(n)){let l=this.added[a]??this.removed[a]??this.updated[a];if(!l)this.added[a]=s;else{let d=r(l,s);delete this.removed[a],delete this.updated[a],this.added[a]=$.merge(l,s,d)}}for(let[a,s]of Object.entries(o)){let l=this.added[a]??this.removed[a]??this.updated[a];if(!l)this.removed[a]=s;else{let d=r(l,s);delete this.added[a],delete this.updated[a],this.removed[a]=$.merge(l,s,d)}}for(let[a,s]of Object.entries(i)){let l=this.added[a]??this.removed[a]??this.updated[a];if(!l)this.updated[a]=s;else{let d=r(l,s),c=$.merge(l,s,d);l===this.added[a]?this.added[a]=c:l===this.removed[a]?this.removed[a]=c:this.updated[a]=c}}return(Gn()||Dn())&&(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)=>a=>{let s=e.createGetter(n,o,i);return Object.entries(a).reduce((l,[d,c])=>{let u=s(d,c.inserted);if(u){let h=e.applyDelta(u,c,i,r);if(n.set(h.id,h),l.set(h.id,h),!i.applyDirection){let m=t.get(d);m&&(i.applyDirection=m.version>h.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,o)=>(i,r)=>{let a=t.get(i);return a||(a=n.get(i),a?(o.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!a.isDeleted)&&(o.containsVisibleDifference=!0)):a=He({id:i,version:1},{...r})),a};static applyDelta(t,n,o,i){let r={};for(let a of Object.keys(n.inserted)){if(a==="boundElements"||i?.excludedProperties?.has(a))continue;let s=n.inserted[a];Reflect.set(r,a,s)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let a=$.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,s=>s.id);Object.assign(r,{boundElements:a})}if(!o.containsVisibleDifference){let{index:a,...s}=r,l=e.checkForVisibleDifference(t,s);o.containsVisibleDifference=l}return o.containsZindexDifference||(o.containsZindexDifference=n.deleted.index!==n.inserted.index),He(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:$.isRightDifferent(t,n)}resolveConflicts(t,n,o="forward"){let i=new Map,r=(s,l)=>{let d=n.get(s.id);if(!d)return;let c=t.get(s.id),u=o==="forward"?d.version+1:d.version-1,h=l,m;c===d?m=He(d,{...h,version:u},!0):m=Te(d,n,{...h,version:c?.version!==d.version?d.version:u}),i.set(m.id,m),n.set(m.id,m)};for(let s of Object.keys(this.removed))e.unbindAffected(t,n,s,r);for(let s of Object.keys(this.added))e.rebindAffected(t,n,s,r);for(let[s]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>gd.has(c)))){let l=n.get(s);!l||l.isDeleted||e.rebindAffected(t,n,s,r)}let a=new Map(Array.from(t).filter(([s])=>i.has(s)));return this.squash(e.calculate(a,i)),i}static unbindAffected(t,n,o,i){let r=()=>t.get(o),a=()=>n.get(o);Pn.unbindAffected(n,r(),i),Pn.unbindAffected(n,a(),i),In.unbindAffected(n,r(),i),In.unbindAffected(n,a(),i)}static rebindAffected(t,n,o,i){let r=()=>t.get(o),a=()=>n.get(o);Pn.unbindAffected(n,r(),i),Pn.rebindAffected(n,a(),i),In.unbindAffected(n,r(),(s,l)=>{te(s)&&i(s,l)}),In.rebindAffected(n,a(),i)}static redrawElements(t,n){try{let o=new fo(t,{skipValidation:!0});e.redrawTextBoundingBoxes(o,n),e.redrawBoundArrows(o,n)}catch(o){if(console.error("Couldn't redraw elements",o),Gn()||Dn())throw o}finally{return t}}static redrawTextBoundingBoxes(t,n){let o=t.getNonDeletedElementsMap(),i=new Map;for(let r of n.values()){if(Ee(r)){let{containerId:a}=r,s=a?o.get(a):void 0;s&&i.set(s.id,{container:s,boundText:r})}if(Ct(r)){let a=Qt(r),s=a?o.get(a):void 0;s&&i.set(r.id,{container:r,boundText:s})}}for(let{container:r,boundText:a}of i.values())r.isDeleted||a.isDeleted||Oi(a,r,t)}static redrawBoundArrows(t,n){for(let o of n.values())!o.isDeleted&&ge(o)&&Re(o,t,{changedElements:n})}static reorderElements(t,n,o){if(!o.containsZindexDifference)return t;let i=Array.from(t.values()),r=Id([...i]),a=$.getRightDifferences(i,r,!0).reduce((s,l)=>{let d=i[Number(l)];return d&&n.has(d.id)&&s.set(d.id,d),s},new Map);return!o.containsVisibleDifference&&a.size&&(o.containsVisibleDifference=!0),bf(Yn(r,a))}static postProcess(t,n){try{$.diffArrays(t,n,"boundElements",r=>r.id);let o=t.points??[],i=n.points??[];$.isDifferent(o,i)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(o){if(console.error("Couldn't postprocess elements delta."),Gn()||Dn())throw o}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:o,...i}=t;return i}};I();var f4=(e,t,n,o,i)=>{let[r,a,s,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=Fe(e),c=ir(e,t,o).map(f=>[f,Fe(f)]).sort((f,g)=>f[1][a]-g[1][a]),u=0;for(let f of c)u+=f[1][l];let h=(d[l]-u)/(c.length-1);if(h<0){let f=c.findIndex(y=>y[1][r]===d[r]),g=c.findIndex(y=>y[1][s]===d[s]),E=(c[g][1][a]-c[f][1][a])/(c.length-1),x=c[f][1][a];return c.flatMap(([y,w],M)=>{let b={x:0,y:0};return M!==f&&M!==g&&(x+=E,b[n.axis]=x-w[a]),y.map(S=>{let v=i.mutateElement(S,{x:S.x+b.x,y:S.y+b.y});return Re(S,i,{simultaneouslyUpdated:y}),v})})}let m=d[r];return c.flatMap(([f,g])=>{let E={x:0,y:0};return E[n.axis]=m-g[r],m+=h,m+=g[l],f.map(x=>{let y=i.mutateElement(x,{x:x.x+E.x,y:x.y+E.y});return Re(x,i,{simultaneouslyUpdated:f}),y})})};I();import{TEXT_AUTOWRAP_THRESHOLD as Mf,getGridPoint as Pf,getFontString as If,DRAGGING_THRESHOLD as Sf}from"@excalidraw/common";var S4=(e,t,n,o,i,r)=>{if(t.length===1&&U(t[0])&&(t[0].startBinding||t[0].endBinding))return;let a=t.filter(h=>{if(U(h)&&h.startBinding&&h.endBinding){let m=t.find(g=>g.id===h.startBinding?.elementId),f=t.find(g=>g.id===h.endBinding?.elementId);return m&&f}return!0}),s=new Set(a),l=a.filter(h=>ee(h)).map(h=>h.id);if(l.length>0)for(let h of o.getNonDeletedElements())h.frameId!==null&&l.includes(h.frameId)&&s.add(h);let d=[];for(let h of s){let m=e.originalElements.get(h.id);if(!m)return;d.push(m)}let c=vf(We(d),n,i,r),u=new Set(Array.from(s,h=>h.id));s.forEach(h=>{let m=!j(h),f=m||(h.startBinding?u.has(h.startBinding.elementId):!1),g=m||(h.endBinding?u.has(h.endBinding.elementId):!1);if(j(h)){if(s.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>Sf||!h.startBinding&&!h.endBinding){rs(e,h,o,c);let E=h.startBinding&&!f,x=h.endBinding&&!g;(E||x)&&(E&&Oe(h,"start",o),x&&Oe(h,"end",o))}}else{rs(e,h,o,c);let E=Z(h,o.getNonDeletedElementsMap());E&&rs(e,E,o,c),Re(h,o,{simultaneouslyUpdated:Array.from(s)})}})},vf=(e,t,n,o)=>{let[i,r]=e,a=i+t.x+n.x,s=r+t.y+n.y;if(n.x===0||n.y===0){let[l,d]=Pf(i+t.x,r+t.y,o);n.x===0&&(a=l),n.y===0&&(s=d)}return{x:a-i,y:s-r}},rs=(e,t,n,o)=>{let i=e.originalElements.get(t.id)??t,r=i.x+o.x,a=i.y+o.y;n.mutateElement(t,{x:r,y:a})},v4=(e,t,n)=>{let[o,i]=We(e);return[t-o,n-i]},A4=({newElement:e,elementType:t,originX:n,originY:o,x:i,y:r,width:a,height:s,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:h=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(h?s=a/h:(Math.abs(r-o)>Math.abs(i-n)?{width:a,height:s}=qa(t,s,i<n?-a:a):{width:a,height:s}=qa(t,a,r<o?-s:s),s<0&&(s=-s)));let g=i<n?n-a:n,E=r<o?o-s:o;d&&(a+=a,s+=s,g=n-a/2,E=o-s/2);let x=null;if(te(e)){s=e.height;let y=Ci(If({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);a=Math.max(a,y),Math.abs(i-n)>Mf/c&&(x={autoResize:!1}),E=o,d&&(g=n-a/2)}if(a!==0&&s!==0){let y=null;Ae(e)&&(y={initialWidth:a,initialHeight:s}),u.mutateElement(e,{x:g+(m?.x??0),y:E+(m?.y??0),width:a,height:s,...x,...y},{informMutation:f,isDragging:!1})}};I();import{ELEMENT_LINK_KEY as fr,normalizeLink as $c}from"@excalidraw/common";var B4=(e,t)=>{let n=window.location.href;try{let o=new URL(n);return o.searchParams.set(fr,e),$c(o.toString())}catch(o){console.error(o)}return $c(n)},D4=(e,t)=>{if(e.length>0&&Af(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},Af=e=>!!(e.length===1||e.length>1&&Rd(e)),G4=e=>{try{let t=new URL(e);return t.searchParams.has(fr)&&t.host===window.location.host}catch{return!1}},O4=e=>{try{let{searchParams:t}=new URL(e);if(t.has(fr))return t.get(fr)}catch{}return null};I();import{FONT_FAMILY as Hf,VERTICAL_ALIGN as zf,escapeDoubleQuotes as as,getFontString as Wf}from"@excalidraw/common";I();import{DEFAULT_ELEMENT_PROPS as On,DEFAULT_FONT_FAMILY as kf,DEFAULT_FONT_SIZE as Tf,DEFAULT_TEXT_ALIGN as Lf,DEFAULT_VERTICAL_ALIGN as Cf,VERTICAL_ALIGN as Bf,randomInteger as Df,randomId as Gf,getFontString as gr,getUpdatedTimestamp as Of,getLineHeight as Rf}from"@excalidraw/common";var St=(e,{x:t,y:n,strokeColor:o=On.strokeColor,backgroundColor:i=On.backgroundColor,fillStyle:r=On.fillStyle,strokeWidth:a=On.strokeWidth,strokeStyle:s=On.strokeStyle,roughness:l=On.roughness,opacity:d=On.opacity,width:c=0,height:u=0,angle:h=0,groupIds:m=[],frameId:f=null,index:g=null,roundness:E=null,boundElements:x=null,link:y=null,locked:w=On.locked,...M})=>((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:M.points}),{id:M.id||Gf(),type:e,x:t,y:n,width:c,height:u,angle:h,strokeColor:o,backgroundColor:i,fillStyle:r,strokeWidth:a,strokeStyle:s,roughness:l,opacity:d,groupIds:m,frameId:f,index:g,roundness:E,seed:M.seed??Df(),version:M.version||1,versionNonce:M.versionNonce??0,isDeleted:!1,boundElements:x,updated:Of(),link:y,locked:w,customData:M.customData}),qn=e=>St(e.type,e),U4=e=>St("embeddable",e),Y4=e=>({...St("iframe",e)}),Zc=e=>He({...St("frame",e),type:"frame",name:e?.name||null},{}),qc=e=>He({...St("magicframe",e),type:"magicframe",name:e?.name||null},{}),Kc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Kn=e=>{let t=e.fontFamily||kf,n=e.fontSize||Tf,o=e.lineHeight||Rf(t),i=Ro(e.text),r=ot(i,gr({fontFamily:t,fontSize:n}),o),a=e.textAlign||Lf,s=e.verticalAlign||Cf,l=Kc({textAlign:a,verticalAlign:s},r),d={...St("text",e),text:i,fontSize:n,fontFamily:t,textAlign:a,verticalAlign:s,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 He(d,{})},Ff=(e,t,n)=>{let{width:o,height:i}=ot(n,gr(e),e.lineHeight);e.autoResize||(o=e.width);let{textAlign:r,verticalAlign:a}=e,s,l;if(r==="center"&&a===Bf.MIDDLE&&!e.containerId&&e.autoResize){let d=ot(e.text,gr(e),e.lineHeight),c=Kc(e,{width:o-d.width,height:i-d.height});s=e.x-c.x,l=e.y-c.y}else{let[d,c,u,h]=Q(e,t),[m,f,g,E]=pn(e,o,i,!1),x=(d-m)/2,y=(c-f)/2,w=(u-g)/2,M=(h-E)/2;[s,l]=Nf({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,x,y,w,M)}return{width:o,height:i,x:Number.isFinite(s)?s:e.x,y:Number.isFinite(l)?l:e.y}},Nf=(e,t,n,o,i,r,a,s)=>{let l=Math.cos(o),d=Math.sin(o);return e.e&&e.w?t+=i+a:e.e?(t+=i*(1+l),n+=i*d,t+=a*(1-l),n+=a*-d):e.w&&(t+=i*(1-l),n+=i*-d,t+=a*(1+l),n+=a*d),e.n&&e.s?n+=r+s:e.n?(t+=r*d,n+=r*(1-l),t+=s*-d,n+=s*(1+l)):e.s&&(t+=r*-d,n+=r*(1+l),t+=s*d,n+=s*(1-l)),[t,n]},X4=(e,t,n,o=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(o=Kt(o,gr(e),t?yt(t,e):e.width));let i=Ff(e,n,o);return{text:o,...i}},$4=e=>({...St(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure}),Qc=e=>{let t={...St(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Ut(t)?{...t,polygon:e.polygon??!1}:t},Er=e=>e.elbowed?{...St(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...St(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},Jc=e=>({...St("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,scale:e.scale??[1,1],crop:e.crop??null});var vt=new Map,_f=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,jf=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Vf=/^https:\/\/(?:www\.)?figma\.com/,eu=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Uf=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Yf=/^(?:https?:\/\/)?forms\.microsoft\.com\//,tu=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,Xf=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,$f=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Zf=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,nu=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,ou=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,qf=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,ru=e=>{let t;try{let a=new URL(e.startsWith("http")?e:`https://${e}`);t=a.searchParams.get("t")||a.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)},Kf=e=>{try{let t=new URL(e.startsWith("http")?e:`https://${e}`);if(t.hostname.replace(/^www\./,"")!=="drive.google.com")return null;let o=null,i=t.pathname.match(/^\/file\/d\/([^/]+)(?:\/|$)/);if(i?.[1]?o=i[1]:(t.pathname==="/open"||t.pathname==="/uc")&&(o=t.searchParams.get("id")),!o||!/^[a-zA-Z0-9_-]+$/.test(o))return null;let r=t.searchParams.get("resourcekey"),a=ru(t.toString());return{fileId:o,resourceKey:r&&/^[a-zA-Z0-9_-]+$/.test(r)?r:void 0,timestamp:a>0?a:void 0}}catch{return null}},ls=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),iu=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),ss=e=>`<html><body>${e}</body></html>`,t5=e=>{if(!e)return null;if(vt.has(e))return vt.get(e);let t=e,n=iu.has(ds(e,iu)||""),o="generic",i={w:560,h:840},r=e.match(_f);if(r?.[2]){let c=ru(t),u=c>0?`&start=${c}`:"",h=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${u}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${u}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break}return i=h?{w:315,h:560}:{w:560,h:315},vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}}let a=e.match(jf);if(a?.[1]){let c=a?.[1],u=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return o="video",e=`https://player.vimeo.com/video/${c}?api=1`,i={w:560,h:315},vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,error:u,sandbox:{allowSameOrigin:n}}}let s=Kf(e);if(s){o="video";let c=new URLSearchParams;s.resourceKey&&c.set("resourcekey",s.resourceKey),s.timestamp&&c.set("t",`${s.timestamp}`);let u=c.toString();return e=`https://drive.google.com/file/d/${s.fileId}/preview${u?`?${u}`:""}`,i={w:560,h:315},vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}}if(e.match(Vf))return o="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,i={w:550,h:550},vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}};let d=e.match($f);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}};if(Yf.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),tu.test(e)){let c=e.match(tu)[1],u=as(`https://twitter.com/x/status/${c}`),h={type:"document",srcdoc:m=>ss(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${m}"><a href="${u}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return vt.set(t,h),h}if(ou.test(e)){let[,c,u,h]=e.match(ou),m=as(`https://reddit.com/r/${c}/comments/${u}/${h}`),f={type:"document",srcdoc:g=>ss(`<blockquote class="reddit-embed-bq" data-embed-theme="${g}"><a href="${m}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return vt.set(t,f),f}if(eu.test(e)){let[,c,u]=e.match(eu),h=as(`https://gist.github.com/${c}/${u}`),m={type:"document",srcdoc:()=>ss(`
|
|
21
|
+
C ${l} ${d}, ${l} ${d}, ${l+E} ${d+x}`,Qe(e,!0,a))}else s=t.polygon([[l,d],[c,u],[h,m],[f,g]],Qe(e,!1,a));return s}case"ellipse":return t.ellipse(e.width/2,e.height/2,e.width,e.height,Qe(e,!1,a));case"line":case"arrow":{let s,l=Qe(e,!1,a),d=e.points.length?e.points:[me(0,0)];if(U(e)?d.every(c=>Math.abs(c[0])<=1e6&&Math.abs(c[1])<=1e6)?s=[t.path(uc(d,16),Qe(e,!0,a))]:(console.error("Elbow arrow with extreme point positions detected. Arrow not rendered.",e.id,JSON.stringify(d)),s=[]):e.roundness?s=[t.curve(d,l)]:l.fill?s=[t.polygon(d,l)]:s=[t.linearPath(d,l)],e.type==="arrow"){let{startArrowhead:c=null,endArrowhead:u="arrow"}=e;if(c!==null){let h=lc(e,s,"start",c,t,l,o,a);s.push(...h)}if(u!==null){let h=lc(e,s,"end",u,t,l,o,a);s.push(...h)}}return s}case"freedraw":{let s=[];if($t(e.points)){let l=Ao(e.points,.75);s.push(t.curve(l,{...Qe(e,!1,a),stroke:"none"}))}return s.push($m(e)),s}case"frame":case"magicframe":case"text":case"image":return null;default:return _m(e,`generateElementShape(): Unimplemented type ${e?.type}`),null}},uc=(e,t)=>{let n=[];for(let i=1;i<e.length-1;i+=1){let r=e[i-1],a=e[i+1],s=e[i],l=bt(s,r),d=bt(a,s),c=Math.min(t,ac(e[i],a)/2,ac(e[i],r)/2);l?r[0]<s[0]?n.push([e[i][0]-c,e[i][1]]):n.push([e[i][0]+c,e[i][1]]):r[1]<s[1]?n.push([e[i][0],e[i][1]-c]):n.push([e[i][0],e[i][1]+c]),n.push(e[i]),d?a[0]<s[0]?n.push([e[i][0]-c,e[i][1]]):n.push([e[i][0]+c,e[i][1]]):a[1]<s[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(" ")},ti=(e,t)=>{switch(e.type){case"rectangle":case"diamond":case"frame":case"magicframe":case"embeddable":case"image":case"iframe":case"text":case"selection":return $s(e);case"arrow":case"line":{let n=at.generateElementShape(e,null)[0],[,,,,o,i]=Q(e,t);return Ri(e)?Qs(e,n,me(e.x,e.y),e.angle,me(o,i)):qs(n,me(e.x,e.y),e.angle,me(o,i))}case"ellipse":return Zs(e);case"freedraw":{let[,,,,n,o]=Q(e,t);return Ks(e,me(n,o),Ri(e))}}},Jd=(e,t)=>{let n=[...e.points];if(t){if(!El(e.points))return null;let i=n[0],r=n[n.length-1];Math.hypot(i[0]-r[0],i[1]-r[1])>Vm||n.length<4?n.push(me(i[0],i[1])):n[n.length-1]=me(i[0],i[1])}return{polygon:t,points:n}},$m=e=>Km(Zm(e)),Zm=e=>{let t=e.simulatePressure?e.points:e.points.length?e.points.map(([n,o],i)=>[n,o,e.pressures[i]]):[[0,0,.5]];return rl(t,{simulatePressure:e.simulatePressure,size:e.strokeWidth*4.25,thinning:.6,smoothing:.5,streamline:.5,easing:n=>Math.sin(n*Math.PI/2),last:!0})},dc=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],qm=/(\s?[A-Z]?,?-?[0-9]*\.[0-9]{0,2})(([0-9]|e|-)*)/g,Km=e=>{if(!e.length)return"";let t=e.length-1;return e.reduce((n,o,i,r)=>(i===t?n.push(o,dc(o,r[0]),"L",r[0],"Z"):n.push(o,dc(o,r[i+1])),n),["M",e[0],"Q"]).join(" ").replace(qm,"$1")};var $a=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&&!Ee(t))return i.bounds;if(o&&t.angle!==0){let a=e.calculateBounds({...t,angle:0},n);return e.nonRotatedBoundsCache.set(t,{version:t.version,bounds:a}),a}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,a,s,l,d]=Q(t,n);if(Pe(t)){let[c,u,h,m]=Za(t.points.map(([f,g])=>ce(G(f,g),G(l-t.x,d-t.y),t.angle)));return[c+t.x,u+t.y,h+t.x,m+t.y]}else if(ne(t))o=l0(t,l,d,n);else if(t.type==="diamond"){let[c,u]=ce(G(l,r),G(l,d),t.angle),[h,m]=ce(G(l,s),G(l,d),t.angle),[f,g]=ce(G(i,d),G(l,d),t.angle),[E,x]=ce(G(a,d),G(l,d),t.angle),y=Math.min(c,h,f,E),w=Math.min(u,m,g,x),M=Math.max(c,h,f,E),b=Math.max(u,m,g,x);o=[y,w,M,b]}else if(t.type==="ellipse"){let c=(a-i)/2,u=(s-r)/2,h=Math.cos(t.angle),m=Math.sin(t.angle),f=Math.hypot(c*h,u*m),g=Math.hypot(u*h,c*m);o=[l-f,d-g,l+f,d+g]}else{let[c,u]=ce(G(i,r),G(l,d),t.angle),[h,m]=ce(G(i,s),G(l,d),t.angle),[f,g]=ce(G(a,s),G(l,d),t.angle),[E,x]=ce(G(a,r),G(l,d),t.angle),y=Math.min(c,h,f,E),w=Math.min(u,m,g,x),M=Math.max(c,h,f,E),b=Math.max(u,m,g,x);o=[y,w,M,b]}return o}},Q=(e,t,n=!1)=>{if(Pe(e))return n0(e);if(ne(e))return R.getElementAbsoluteCoords(e,t,n);if(te(e)){let o=t?De(e,t):null;if(j(o)){let{x:i,y:r}=R.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]},Ga=(e,t)=>{let n=ti(e,t),[o,i,r,a,s,l]=Q(e,t),d=G(s,l);if(n.type==="polycurve"){let x=n.data.map(w=>_t(w,10)),y=[];if(Ut(e)&&!e.polygon||j(e))for(let w of x){let M=0;for(;M<w.length-1;)y.push(Se(G(w[M][0],w[M][1]),G(w[M+1][0],w[M+1][1]))),M++}else{let w=x.flat(),M=0;for(;M<w.length-1;)y.push(Se(G(w[M][0],w[M][1]),G(w[M+1][0],w[M+1][1]))),M++}return y}else{if(n.type==="polyline")return n.data;if(e0(e)){let[E,x]=hn(e),y=x.map(M=>mc(M,d,e.angle)).flat();return[...hc(E,d,e.angle),...y]}else if(e.type==="diamond"){let[E,x]=mn(e),y=x.map(M=>mc(M,d,e.angle)).flat();return[...hc(E,d,e.angle),...y]}else if(n.type==="polygon"){if(te(e)){let y=De(e,t);if(y&&ne(y))return[Se(G(o,i),G(r,i)),Se(G(r,i),G(r,a)),Se(G(r,a),G(o,a)),Se(G(o,a),G(o,i))]}let E=n.data,x=[];for(let y=0;y<E.length-1;y++)x.push(Se(E[y],E[y+1]));return x}else if(n.type==="ellipse")return t0(e)}let[c,u,h,m,,,f,g]=[[o,i],[r,i],[o,a],[r,a],[s,i],[s,a],[o,l],[r,l]].map(E=>ce(E,d,e.angle));return[Se(c,u),Se(h,m),Se(c,h),Se(u,m),Se(c,g),Se(h,g),Se(u,f),Se(m,f)]},e0=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),hc=(e,t,n)=>e.map(o=>Se(ce(o[0],t,n),ce(o[1],t,n))),mc=(e,t,n)=>{let o=_t(e,10),i=0,r=[];for(;i<o.length-1;)r.push(Se(ce(G(o[i][0],o[i][1]),t,n),ce(G(o[i+1][0],o[i+1][1]),t,n))),i++;return r},t0=e=>{let t=G(e.x+e.width/2,e.y+e.height/2),n=e.width/2,o=e.height/2,i=[],r=[],a=90,s=Math.PI*2/a;for(let l=0;l<a;l++){let d=l*s,c=t[0]+n*Math.cos(d),u=t[1]+o*Math.sin(d);r.push(ce(G(c,u),t,e.angle))}for(let l=0;l<r.length-1;l++)i.push(Se(r[l],r[l+1]));return i.push(Se(r[r.length-1],r[0])),i},jb=e=>[e.x,e.y,e.x+e.width,e.y+e.height,e.x+e.width/2,e.y+e.height/2],no=e=>{let t=Math.floor(e.width/2)+1,n=0,o=e.width,i=Math.floor(e.height/2)+1,r=t,a=e.height;return[t,n,o,i,r,a,0,i]},fc=(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},gc=(e,t,n,o)=>{let i=t-e,r=n-t,a=o-n,s=3*i-6*r+3*a,l=6*r-6*i,d=3*i,c=l*l-4*s*d;if(!(c>=0))return!1;let h=null,m=null,f=1/0,g=1/0;return s===0?f=g=-d/l:(f=(-l+Math.sqrt(c))/(2*s),g=(-l-Math.sqrt(c))/(2*s)),f>=0&&f<=1&&(h=fc(f,e,t,n,o)),g>=0&&g<=1&&(m=fc(g,e,t,n,o)),[h,m]},Ni=(e,t,n,o)=>{let i=gc(e[0],t[0],n[0],o[0]),r=gc(e[1],t[1],n[1],o[1]),a=Math.min(e[0],o[0]),s=Math.max(e[0],o[0]);if(i){let c=i.filter(u=>u!==null);a=Math.min(a,...c),s=Math.max(s,...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[a,l,s,d]},Zo=(e,t)=>{let n=G(0,0),{minX:o,minY:i,maxX:r,maxY:a}=e.reduce((s,{op:l,data:d})=>{if(l==="move"){let c=xc(d);Xa(c!=null,"Op data is not a point"),n=c}else if(l==="bcurveTo"){let c=G(d[0],d[1]),u=G(d[2],d[3]),h=G(d[4],d[5]),m=t?t(c):c,f=t?t(u):u,g=t?t(h):h,E=t?t(n):n;n=h;let[x,y,w,M]=Ni(E,m,f,g);s.minX=Math.min(s.minX,x),s.minY=Math.min(s.minY,y),s.maxX=Math.max(s.maxX,w),s.maxY=Math.max(s.maxY,M)}return s},{minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0});return[o,i,r,a]},Za=(e,t=0)=>{let n=1/0,o=1/0,i=-1/0,r=-1/0;for(let[a,s]of e)n=Math.min(n,a),o=Math.min(o,s),i=Math.max(i,a),r=Math.max(r,s);return[n-t,o-t,i+t,r+t]},n0=e=>{let[t,n,o,i]=Za(e.points),r=t+e.x,a=n+e.y,s=o+e.x,l=i+e.y;return[r,a,s,l,(r+s)/2,(a+l)/2]},o0=20,i0=15,r0=e=>{switch(e){case"arrow":return 25;case"diamond":case"diamond_outline":return 12;case"cardinality_many":case"cardinality_one_or_many":case"cardinality_zero_or_many":return i0;case"cardinality_one":case"cardinality_exactly_one":case"cardinality_zero_or_one":return o0;default:return 15}},a0=e=>{switch(e){case"bar":return 90;case"arrow":return 20;default:return 25}},je=(e,t,n,o,i=0)=>{if(o===null||t.length<1)return null;let r=jt(t[0]);if(r.length<1)return null;let a=n==="start"?1:r.length-1,s=r[a].data;Xa(s.length===6,"Op data length is not 6");let l=G(s[4],s[5]),d=G(s[2],s[3]),c=G(s[0],s[1]),u=r[a-1],h=G(0,0);if(u.op==="move"){let A=xc(u.data);Xa(A!=null,"Op data is not a point"),h=A}else u.op==="bcurveTo"&&(h=G(u.data[4],u.data[5]));let m=(A,_)=>Math.pow(1-A,3)*l[_]+3*A*Math.pow(1-A,2)*d[_]+3*Math.pow(A,2)*(1-A)*c[_]+h[_]*Math.pow(A,3),[f,g]=n==="start"?h:l,[E,x]=[m(.3,0),m(.3,1)],y=Math.hypot(f-E,g-x),w=(f-E)/y,M=(g-x)/y,b=r0(o),S=0;{let[A,_]=n==="end"?e.points[e.points.length-1]:e.points[0],[X,ve]=e.points.length>1?n==="end"?e.points[e.points.length-2]:e.points[1]:[0,0];S=Math.hypot(A-X,_-ve)}let L=Math.min(b,S*(o==="diamond"||o==="diamond_outline"?.25:.5)),T=f-w*L*i,D=g-M*L*i,B=T-w*L,F=D-M*L;if(o==="circle"||o==="circle_outline"){let A=Math.hypot(F-D,B-T)+e.strokeWidth-2;return[T,D,A]}let O=a0(o);if(o==="cardinality_many"||o==="cardinality_one_or_many"){let[A,_]=ce(G(T,D),G(B,F),Ya(-O)),[X,ve]=ce(G(T,D),G(B,F),Ya(O));return[B,F,A,_,X,ve]}let[K,Y]=ce(G(B,F),G(T,D),-O*Math.PI/180),[se,H]=ce(G(B,F),G(T,D),Ya(O));if(o==="diamond"||o==="diamond_outline"){let A,_;if(n==="start"){let[X,ve]=e.points.length>1?e.points[1]:[0,0];[A,_]=ce(G(T+L*2,D),G(T,D),Math.atan2(ve-D,X-T))}else{let[X,ve]=e.points.length>1?e.points[e.points.length-2]:[0,0];[A,_]=ce(G(T-L*2,D),G(T,D),Math.atan2(D-ve,T-X))}return[T,D,K,Y,A,_,se,H]}return[T,D,K,Y,se,H]},s0=e=>{let t=Hn.generator(),n=Qe(e),o=e.roundness?"curve":n.fill?"polygon":"linearPath";return t[o](e.points,n)},l0=(e,t,n,o)=>{let i=Z(e,o);if(e.points.length<2){let[u,h]=e.points[0],[m,f]=ce(G(e.x+u,e.y+h),G(t,n),e.angle),g=[m,f,m,f];if(i){let E=R.getMinMaxXYWithBoundText(e,o,[m,f,m,f],i);g=[E[0],E[1],E[2],E[3]]}return g}let a=at.get(e,null)?.[0]??s0(e),s=jt(a),d=Zo(s,([u,h])=>ce(G(e.x+u,e.y+h),G(t,n),e.angle)),c=[d[0],d[1],d[2],d[3]];if(i){let u=R.getMinMaxXYWithBoundText(e,o,c,i);c=[u[0],u[1],u[2],u[3]]}return c},ue=(e,t,n=!1)=>$a.getBounds(e,t,n),We=(e,t)=>{if(!Qm(e))return[0,0,0,0];let n=1/0,o=-1/0,i=1/0,r=-1/0,a=t||Ec(e);return e.forEach(s=>{let[l,d,c,u]=ue(s,a);n=Math.min(n,l),i=Math.min(i,d),o=Math.max(o,c),r=Math.max(r,u)}),[n,i,o,r]},Vb=(e,t)=>{let[n,o,i,r]=We(e);return[n+t.x,o+t.y,i+t.x,r+t.y]},pn=(e,t,n,o)=>{if(!(ne(e)||Pe(e)))return[e.x,e.y,e.x+t,e.y+n];let i=pc(0,t,pc(1,n,e.points,o),o),r;if(Pe(e))r=Za(i);else{let c=Hn.generator(),u=e.roundness?c.curve(i,Qe(e)):c.linearPath(i,Qe(e)),h=jt(u);r=Zo(h)}let[a,s,l,d]=r;return[a+e.x,s+e.y,l+e.x,d+e.y]},za=(e,t)=>{let n=Hn.generator(),o=e.roundness==null?n.linearPath(t,Qe(e)):n.curve(t,Qe(e)),i=jt(o),[r,a,s,l]=Zo(i);return[r+e.x,a+e.y,s+e.x,l+e.y]},Ub=(e,t)=>{if(!e.length)return[0,0,0,0];let n=1/0,o=e[0],i=Ec(e);return e.forEach(r=>{let[a,s,l,d]=ue(r,i),c=Jm(G((a+l)/2,(s+d)/2),G(t.x,t.y));c<n&&(n=c,o=r)}),ue(o,i)},Fe=e=>{let[t,n,o,i]=We(e);return{minX:t,minY:n,maxX:o,maxY:i,width:o-t,height:i-n,midX:(t+o)/2,midY:(n+i)/2}},Yb=({scrollX:e,scrollY:t,width:n,height:o,zoom:i})=>[-e,-t,-e+n/i.value,-t+o/i.value],xn=e=>G(e[0]+(e[2]-e[0])/2,e[1]+(e[3]-e[1])/2),pt=(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=le(e,t),[r,a]=ce(G(o.minX,o.minY),i,e.angle),[s,l]=ce(G(o.maxX,o.minY),i,e.angle),[d,c]=ce(G(o.maxX,o.maxY),i,e.angle),[u,h]=ce(G(o.minX,o.maxY),i,e.angle),m=[Math.min(r,s,d,u),Math.min(a,l,c,h),Math.max(r,s,d,u),Math.max(a,l,c,h)];if(n){let[f,g,E,x]=n;return[m[0]-x,m[1]-f,m[2]+g,m[3]+E]}return m},wt=(e,t)=>e[0]>t[0]&&e[0]<t[2]&&e[1]>t[1]&&e[1]<t[3],d0=(e,t)=>e[0]>=t[0]&&e[0]<=t[2]&&e[1]>=t[1]&&e[1]<=t[3],Ot=(e,t)=>{if(e==null||t==null)return!1;let[n,o,i,r]=e,[a,s,l,d]=t;return n<l&&i>a&&o<d&&r>s},tr=(e,t)=>[G(t[0],t[1]),G(t[0],t[3]),G(t[2],t[1]),G(t[2],t[3])].every(n=>d0(n,e)),le=(e,t,n=0,o=0)=>{if(ne(e)||Pe(e)){let[a,s,l,d]=Q(e,t),[c,u]=G((a+l)/2,(s+d)/2);return G(c+n,u+o)}let[i,r]=xn(ue(e,t));return G(i+n,r+o)};var h0=.1,wc=e=>ne(e)||Pe(e)?e.points.length<2||e.points.length===2&&j(e)&&p0(e.points[0],e.points[e.points.length-1],h0):e.width===0&&e.height===0,Gd=(e,t,n,o,i)=>{let[r,a,s,l]=ue(e,i),d=ur({clientX:o.offsetLeft,clientY:o.offsetTop},o),c=ur({clientX:o.offsetLeft+t,clientY:o.offsetTop+n},o);return d.x<=s&&d.y<=l&&c.x>=r&&c.y>=a},e6=(e,t,n,o,i,r)=>{let[a,s,l,d]=We(e,i),c=ur({clientX:o.offsetLeft+(r?.left||0),clientY:o.offsetTop+(r?.top||0)},o),u=ur({clientX:o.offsetLeft+t-(r?.right||0),clientY:o.offsetTop+n-(r?.bottom||0)},o);return a>=c.x&&s>=c.y&&l<=u.x&&d<=u.y},qa=(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)/rn)*rn;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}},ec=(e,t,n,o,i)=>{let r=n-e,a=o-t,s=Math.atan2(a,r),l=Math.round(s/rn)*rn;if(i){let d=Math.floor(i/rn)*rn;c0(s,d,d+rn)&&(u0(s,i)<rn/6?l=i:yc(s)>yc(i)?l=d+rn:l=d)}if(l===0)a=0;else if(l===Math.PI/2)r=0;else{let d=Math.tan(l),c=-1,u=t-d*e,h=-1/d,m=-1,f=o-h*n,g=(c*f-m*u)/(d*m-h*c),E=(u*h-f*d)/(d*m-h*c);r=g-e,a=E-t}return{width:r,height:a}},t6=e=>{let t={width:e.width,height:e.height,x:e.x,y:e.y};if(e.width<0){let n=Math.abs(e.width);t.width=n,t.x=e.x-n}if(e.height<0){let n=Math.abs(e.height);t.height=n,t.y=e.y-n}return t};I();var s6=(e,t,n,o)=>{let i=ir(e,n.getNonDeletedElementsMap(),o),r=Fe(e);return i.flatMap(a=>{let s=m0(a,r,t);return a.map(l=>{let d=n.mutateElement(l,{x:l.x+s.x,y:l.y+s.y});return Re(l,n,{simultaneouslyUpdated:a}),d})})},m0=(e,t,{axis:n,position:o})=>{let i=Fe(e),[r,a]=n==="x"?["minX","maxX"]:["minY","maxY"],s={x:0,y:0};return o==="start"?{...s,[n]:t[r]-i[r]}:o==="end"?{...s,[n]:t[a]-i[a]}:{...s,[n]:(t[r]+t[a])/2-(i[r]+i[a])/2}};I();I();var pr=class{root;gap;constructor(t=0){this.root=null,this.gap=t}fit(t){let n=t.length,o=n>0?t[0].w:0,i=n>0?t[0].h:0;this.root={x:0,y:0,w:o,h:i};for(let r=0;r<n;r++){let a=t[r],s=this.findNode(this.root,a.w,a.h);s?a.fit=this.splitNode(s,a.w,a.h):a.fit=this.growNode(a.w,a.h)}}findNode(t,n,o){return t?t.used?this.findNode(t.right||null,n,o)||this.findNode(t.down||null,n,o):n<=t.w&&o<=t.h?t:null:null}splitNode(t,n,o){return t.used=!0,t.down={x:t.x,y:t.y+o+this.gap,w:t.w,h:t.h-o-this.gap},t.right={x:t.x+n+this.gap,y:t.y,w:t.w-n-this.gap,h:o},t}growNode(t,n){if(!this.root)return null;let o=t<=this.root.w,i=n<=this.root.h,r=i&&this.root.h>=this.root.w+t+this.gap,a=o&&this.root.w>=this.root.h+n+this.gap;return r?this.growRight(t,n):a?this.growDown(t,n):i?this.growRight(t,n):o?this.growDown(t,n):null}growRight(t,n){if(!this.root)return null;this.root={used:!0,x:0,y:0,w:this.root.w+t+this.gap,h:this.root.h,down:this.root,right:{x:this.root.w+this.gap,y:0,w:t,h:this.root.h}};let o=this.findNode(this.root,t,n);return o?this.splitNode(o,t,n):null}growDown(t,n){if(!this.root)return null;this.root={used:!0,x:0,y:0,w:this.root.w,h:this.root.h+n+this.gap,down:{x:0,y:this.root.h+this.gap,w:this.root.w,h:n},right:this.root};let o=this.findNode(this.root,t,n);return o?this.splitNode(o,t,n):null}};I();var f0=[1,1.08,1.18,1.32,1.5,1.75,2.1,2.6,3.25],g0=[1,4/3,3/4,3/2,2/3,2,1/2],E0=(e,t)=>{let n=Math.max(e.length,t.length);for(let o=0;o<n;o++){let i=(e[o]??0)-(t[o]??0);if(i!==0)return i}return 0},x0=(e,t)=>t.packedW*t.packedH-e.packedW*e.packedH||Math.max(t.packedW,t.packedH)-Math.max(e.packedW,e.packedH)||t.packedH-e.packedH||t.packedW-e.packedW,bc=(e,t,n)=>Math.min(Math.max(e,t),n),y0=(e,t)=>e.x<t.x+t.w&&e.x+e.w>t.x&&e.y<t.y+t.h&&e.y+e.h>t.y,w0=(e,t)=>t.x>=e.x&&t.y>=e.y&&t.x+t.w<=e.x+e.w&&t.y+t.h<=e.y+e.h,Mc=e=>{let t=e.filter(n=>n.fit);return t.length===0?null:t.reduce((n,o)=>({minX:Math.min(n.minX,o.fit.x),minY:Math.min(n.minY,o.fit.y),maxX:Math.max(n.maxX,o.fit.x+o.actualW),maxY:Math.max(n.maxY,o.fit.y+o.actualH)}),{minX:t[0].fit.x,minY:t[0].fit.y,maxX:t[0].fit.x+t[0].actualW,maxY:t[0].fit.y+t[0].actualH})},b0=(e,t)=>{let n=(t.minX+t.maxX)/2,o=(t.minY+t.maxY)/2;return e.reduce((i,r)=>{if(!r.fit)return i;let a=r.fit.x+r.actualW/2,s=r.fit.y+r.actualH/2;return i+Math.abs(a-n)+Math.abs(s-o)},0)},M0=e=>{let t=[];e:for(let n=0;n<e.length;n++){let o=e[n];if(!(o.w<=0||o.h<=0)){for(let i=0;i<e.length;i++)if(n!==i&&w0(e[i],o))continue e;t.some(i=>i.x===o.x&&i.y===o.y&&i.w===o.w&&i.h===o.h)||t.push(o)}}return t},P0=(e,t)=>{let n=[];for(let o of e){if(!y0(o,t)){n.push(o);continue}t.x>o.x&&n.push({x:o.x,y:o.y,w:t.x-o.x,h:o.h}),t.x+t.w<o.x+o.w&&n.push({x:t.x+t.w,y:o.y,w:o.x+o.w-(t.x+t.w),h:o.h}),t.y>o.y&&n.push({x:o.x,y:o.y,w:o.w,h:t.y-o.y}),t.y+t.h<o.y+o.h&&n.push({x:o.x,y:t.y+t.h,w:o.w,h:o.y+o.h-(t.y+t.h)})}return M0(n)},I0=(e,t,n,o)=>{let i=e.x+e.w-t.packedW,r=e.y+e.h-t.packedH,a=[{x:e.x,y:e.y},{x:i,y:e.y},{x:e.x,y:r},{x:i,y:r}];return n==="center-distance"&&a.push({x:bc(o.x-t.actualW/2,e.x,i),y:bc(o.y-t.actualH/2,e.y,r)}),a.filter((s,l,d)=>d.findIndex(c=>c.x===s.x&&c.y===s.y)===l)},S0=(e,t,n,o,i,r,a)=>{let s=e.w*e.h-t.packedW*t.packedH,l=e.w-t.packedW,d=e.h-t.packedH,c=Math.min(l,d),u=Math.max(l,d);if(o==="best-area-fit")return[s,c,u,n.y,n.x];let h=i?{x:(i.minX+i.maxX)/2,y:(i.minY+i.maxY)/2}:{x:r/2,y:a/2},m=n.x+t.actualW/2,f=n.y+t.actualH/2,g=Math.abs(m-h.x)+Math.abs(f-h.y),E=i?{minX:Math.min(i.minX,n.x),minY:Math.min(i.minY,n.y),maxX:Math.max(i.maxX,n.x+t.actualW),maxY:Math.max(i.maxY,n.y+t.actualH)}:{minX:n.x,minY:n.y,maxX:n.x+t.actualW,maxY:n.y+t.actualH},x=E.maxX-E.minX,y=E.maxY-E.minY,w=x*y;return[g,w,s,c,u]},v0=(e,t,n,o)=>{let i=[{x:0,y:0,w:t,h:n}];for(let l of e){let d=Mc(e),c=null;for(let u of i){if(l.packedW>u.w||l.packedH>u.h)continue;let h=d?{x:(d.minX+d.maxX)/2,y:(d.minY+d.maxY)/2}:{x:t/2,y:n/2},m=I0(u,l,o,h);for(let f of m){let g=S0(u,l,f,o,d,t,n);(!c||E0(g,c.score)<0)&&(c={x:f.x,y:f.y,score:g})}}if(!c)return null;l.fit={x:c.x,y:c.y},i=P0(i,{x:c.x,y:c.y,w:l.packedW,h:l.packedH})}let r=Mc(e);if(!r)return{width:0,height:0,spread:0};let a=r.minX,s=r.minY;return e.forEach(l=>{l.fit&&(l.fit={x:l.fit.x-a,y:l.fit.y-s})}),{width:r.maxX-r.minX,height:r.maxY-r.minY,spread:b0(e,{minX:0,minY:0,maxX:r.maxX-r.minX,maxY:r.maxY-r.minY})}},Pc=(e,t={})=>{let n=Math.max(t.gap??0,0),o=t.heuristic??"best-area-fit";if(e.forEach(d=>{d.fit=null}),e.length===0)return{width:0,height:0};let i=e.map(d=>({source:d,actualW:d.w,actualH:d.h,packedW:d.w+n,packedH:d.h+n,fit:null})).sort(x0),r=i.reduce((d,c)=>d+c.packedW*c.packedH,0),a=Math.max(...i.map(d=>d.packedW)),s=Math.max(...i.map(d=>d.packedH)),l=null;for(let d of f0){let c=r*d;for(let u of g0){let h=Math.max(a,Math.ceil(Math.sqrt(c*u))),m=Math.max(s,Math.ceil(c/h)),f=i.map(M=>({...M,fit:null})),g=v0(f,h,m,o);if(!g)continue;let E={width:g.width,height:g.height,spread:g.spread,blocks:f};if(!l){l=E;continue}let x=E.width*E.height-l.width*l.height,y=Math.abs(E.width-E.height),w=Math.abs(l.width-l.height);(x<0||x===0&&(y<w||y===w&&(E.spread<l.spread||E.spread===l.spread&&E.width+E.height<l.width+l.height)))&&(l=E)}if(l)break}return l?(l.blocks.forEach(d=>{d.source.fit=d.fit}),{width:l.width,height:l.height}):null};var A0=(e,t,n)=>{let o=Fe(t),i=n.x-o.minX,r=n.y-o.minY;t.forEach(a=>{e.mutateElement(a,{x:a.x+i,y:a.y+r})})},Ic=e=>e.map(t=>({w:t.boundingBox.width,h:t.boundingBox.height,group:t.group})).sort((t,n)=>n.w*n.h-t.w*t.h||Math.max(n.w,n.h)-Math.max(t.w,t.h)||n.h-t.h||n.w-t.w),Sc=(e,t,n)=>{let o=t.filter(i=>i.fit);return o.forEach(i=>{A0(e,i.group,{x:n.x+(i.fit?.x??0),y:n.y+(i.fit?.y??0)})}),o.flatMap(i=>i.group)},vc=(e,t,n)=>{let o=t.flatMap(l=>l.group),i=Fe(o),r={x:i.minX,y:i.minY},a=Ic(t);return new pr(n).fit(a),Sc(e,a,r)},Ka=(e,t,n,o)=>{let i=t.flatMap(d=>d.group),r=Fe(i),a={x:r.minX,y:r.minY},s=Ic(t);return Pc(s,{gap:n,heuristic:o})?Sc(e,s,a):(console.warn(`Packing heuristic [${o}] failed - using binary tree packer`),vc(e,t,n))},x6=(e,t,n,o,i)=>{let a=or(t,n).map(s=>({group:s,boundingBox:Fe(s)}));switch(o){case"bin-packing":case"bin-packing-center":return Ka(e,a,i,"center-distance");case"bin-packing-max-rects":return Ka(e,a,i,"best-area-fit");case"bin-packing-binary-tree":return vc(e,a,i);default:return console.warn(`Unimplemented algorithm [${o}] - using bin-packing`),Ka(e,a,i,"center-distance")}};I();import{arrayToMap as bf,arrayToObject as an,assertNever as Yc,isDevEnv as Dn,isShallowEqual as Xc,isTestEnv as Gn,randomInteger as Uc}from"@excalidraw/common";I();import{assertNever as N0,COLOR_PALETTE as H0,isDevEnv as z0,isTestEnv as W0,randomId as _0,Emitter as Tc,toIterable as ho}from"@excalidraw/common";I();import{ORIG_ID as C0,randomId as kc,randomInteger as B0,arrayToMap as D0,castArray as Qa,findLastIndex as po,getUpdatedTimestamp as G0,isTestEnv as O0}from"@excalidraw/common";I();import{arrayToMap as k0}from"@excalidraw/common";var T0=e=>{let t=(i,r)=>i.groupIds[i.groupIds.length-r-1],n=(i,r)=>{let a=new Map,s=[];for(let l of i){let d=t(l,r);if(d===void 0){s.push(l);continue}let c=a.get(d);c||(c=[],a.set(d,c),s.push(d)),c.push(l)}return s.flatMap(l=>typeof l=="string"?n(a.get(l),r+1):[l])},o=n(e,0);return o.length!==e.length?(console.error("defragmentGroups: lost some elements... bailing!"),e):o},L0=e=>{let t=k0(e),n=new Set;for(let o of e)if(!n.has(o)){if(o.boundElements?.length){n.add(o);for(let i of o.boundElements){let r=t.get(i.id);r&&i.type==="text"&&n.add(r)}continue}o.type==="text"&&o.containerId&&t.get(o.containerId)?.boundElements?.some(i=>i.id===o.id)||n.add(o)}return n.size!==e.length?(console.error("normalizeBoundElementsOrder: lost some elements... bailing!"),e):[...n]},Ac=e=>L0(T0(e));var R0=(e,t,n,o)=>{let i=es(n);return O0()&&F0(i,n.id),i.id=kc(),i.updated=G0(),o&&(i.seed=B0(),ad(i)),i.groupIds=Nd(i.groupIds,e,r=>(t.has(r)||t.set(r,kc()),t.get(r))),i},B6=e=>{let{elements:t}=e,n="appState"in e?e.appState:{editingGroupId:null,selectedGroupIds:{}},o=new Map,i=new Map,r=[],a=[],s=new Map,l=new Map,d=new Map,c=D0(t),u=e.type==="in-place"?e.idsOfElementsToDuplicate:new Map(t.map(x=>[x.id,x])),h=e.type==="everything"&&e.preserveFrameChildrenOrder;if(e.type==="in-place")for(let x of Object.keys(e.appState.selectedGroupIds))t.filter(y=>y.groupIds?.includes(x)).forEach(y=>u.set(y.id,y));t=Ac(t);let m=t.slice(),f=x=>{let w=Qa(x).reduce((M,b)=>{if(o.has(b.id))return M;o.set(b.id,!0);let S=R0(n.editingGroupId,i,b,e.randomizeSeed);return o.set(S.id,!0),d.set(S.id,S),s.set(b.id,S.id),l.set(S.id,b),a.push(b),r.push(S),M.push(S),M},[]);return Array.isArray(x)?w:w[0]||null},g=(x,y)=>{if(y){if(x>m.length-1){m.push(...Qa(y));return}m.splice(x+1,0,...Qa(y))}},E=new Set(t.filter(x=>u.has(x.id)&&ee(x)).map(x=>x.id));for(let x of t){if(o.has(x.id)||!u.has(x.id))continue;let y=Fa(n,x);if(y){let w=ze(t,y).flatMap(b=>ee(b)&&!h?[...kn(t,b.id),b]:[b]),M=po(m,b=>b.groupIds?.includes(y));g(M,f(w));continue}if(!(!h&&x.frameId&&E.has(x.frameId))){if(ee(x)){let w=x.id;if(h){g(po(m,S=>S.id===w),f(x));continue}let M=kn(t,w),b=po(m,S=>S.frameId===w||S.id===w);g(b,f([...M,x]));continue}if(Ct(x)){let w=Z(x,c),M=po(m,b=>b.id===x.id||"containerId"in b&&b.containerId===x.id);w?g(M,f([x,w])):g(M,f(x));continue}if(Ee(x)){let w=De(x,c),M=po(m,b=>b.id===x.id||b.id===w?.id);w?g(M,f([w,x])):g(M,f(x));continue}g(po(m,w=>w.id===x.id),f(x))}}if(fd(r,s,d),Ad(m,a,s),e.overrides)for(let x of r){let y=l.get(x.id);y&&Object.assign(x,e.overrides({duplicateElement:x,origElement:y,origIdToDuplicateId:s}))}return{duplicatedElements:r,duplicateElementsMap:d,elementsWithDuplicates:m,origIdToDuplicateId:s}},Ja=(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]=Ja(e[i],t+1)}return o}if(Array.isArray(e)){let o=e.length,i=new Array(o);for(;o--;)i[o]=Ja(e[o],t+1);return i}return C.DEV&&n!=="[object Object]"&&n!=="[object Array]"&&n.startsWith("[object ")&&console.warn(`_deepCloneElement: unexpected object type ${n}. This value will not be cloned!`),e},es=e=>Ja(e),F0=(e,t)=>{Object.defineProperty(e,C0,{value:t,writable:!1,enumerable:!1})};var Je={IMMEDIATELY:"IMMEDIATELY",NEVER:"NEVER",EVENTUALLY:"EVENTUALLY"},Lc=class{constructor(t){this.app=t}onDurableIncrementEmitter=new Tc;onStoreIncrementEmitter=new Tc;scheduledMacroActions=new Set;scheduledMicroActions=[];_snapshot=Bn.empty();get snapshot(){return this._snapshot}set snapshot(t){this._snapshot=t}scheduleAction(t){this.scheduledMacroActions.add(t),this.satisfiesScheduledActionsInvariant()}scheduleCapture(){this.scheduleAction(Je.IMMEDIATELY)}scheduleMicroAction(t){let{action:n}=t,o;if("change"in t)o=t.change;else{let r=Bn.create(this.app.scene.getElementsMapIncludingDeleted(),this.app.state),a=r.maybeClone(n,t.elements?Sd(t.elements):void 0,t.appState);o=ni.create(r,a)}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=Bn.empty(),this.scheduledMacroActions=new Set}emitDurableIncrement(t,n=void 0,o=void 0){let i=this.snapshot,r,a;if(n?r=n:r=ni.create(i,t),o?a=o:a=os.calculate(i,t),!a.isEmpty()){let s=new ts(r,a);this.onDurableIncrementEmitter.trigger(s),this.onStoreIncrementEmitter.trigger(s)}}emitEphemeralIncrement(t,n=void 0){let o;if(n)o=n;else{let r=this.snapshot;o=ni.create(r,t)}let i=new ns(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===Je.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 Je.IMMEDIATELY:this.emitDurableIncrement(o,i,r);break;case Je.NEVER:case Je.EVENTUALLY:this.emitEphemeralIncrement(o,i);break;default:N0(n,"Unknown store action")}}finally{switch(n){case Je.IMMEDIATELY:case Je.NEVER:this.snapshot=o;break}}}getScheduledMacroAction(){let t;return this.scheduledMacroActions.has(Je.IMMEDIATELY)?t=Je.IMMEDIATELY:this.scheduledMacroActions.has(Je.NEVER)?t=Je.NEVER:t=Je.EVENTUALLY,t}satisfiesScheduledActionsInvariant(){if(!(this.scheduledMacroActions.size>=0&&this.scheduledMacroActions.size<=Object.keys(Je).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()),W0()||z0())throw new Error(t)}}},ni=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)}},hr=class{constructor(t,n){this.type=t;this.change=n}static isDurable(t){return t.type==="durable"}static isEphemeral(t){return t.type==="ephemeral"}},ts=class extends hr{constructor(n,o){super("durable",n);this.change=n;this.delta=o}},ns=class extends hr{constructor(n){super("ephemeral",n);this.change=n}},os=class e{constructor(t,n,o){this.id=t;this.elements=n;this.appState=o}static create(t,n,o={id:_0()}){return new this(o.id,t,n)}static calculate(t,n){let o=n.metadata.didElementsChange?Cn.calculate(t.elements,n.elements):Cn.empty(),i=n.metadata.didAppStateChange?Ln.calculate(t.appState,n.appState):Ln.empty();return this.create(o,i)}static restore(t){let{id:n,elements:o,appState:i}=t;return new this(n,Cn.restore(o),Ln.restore(i))}static load({id:t,elements:{added:n,removed:o,updated:i},appState:{delta:r}}){let a=Cn.create(n,o,i),s=Ln.create(r);return new this(t,a,s)}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,a]=t.elements.applyTo(n,Bn.empty().elements,i),[s,l]=t.appState.applyTo(o,r);return[r,s,a||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(Cn.empty(),Ln.empty())}isEmpty(){return this.elements.isEmpty()&&this.appState.isEmpty()}},Bn=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,Cc(n)?n:mo(n),o)}static empty(){return new e(new Map,j0(),{didElementsChange:!1,didAppStateChange:!1,isEmpty:!0})}getChangedElements(t){let n={};for(let o of ho(t.elements))this.elements.get(o.id)||(n[o.id]=He(o,{isDeleted:!0}));for(let o of ho(this.elements))t.elements.get(o.id)!==o&&(n[o.id]=o);return n}getChangedAppState(t){return $.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=mo({...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===Je.EVENTUALLY&&(i.shouldCompareHashes=!0);let r=this.maybeCreateElementsSnapshot(n,i),a=this.maybeCreateAppStateSnapshot(o,i),s=!1,l=!1;return this.elements!==r&&(s=!0),this.appState!==a&&(l=!0),!s&&!l?this:new e(r,a,{didElementsChange:s,didAppStateChange:l})}maybeCreateAppStateSnapshot(t,n={shouldCompareHashes:!1}){if(!t)return this.appState;let o=Cc(t)?t:mo(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=$.isRightDifferent(this.appState,t);if(!o)return;let i=Gc(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 ho(this.elements))t.get(r.id)||o.set(r.id,He(r,{isDeleted:!0}));for(let r of ho(t)){let a=this.elements.get(r.id);if(!a||a.version<r.version){if(Ae(r)&&!zn(r))continue;o.set(r.id,r)}}if(!o.size)return;let i=Dc(o);if(!(n.shouldCompareHashes&&this._lastChangedElementsHash===i))return this._lastChangedElementsHash=i,o}createElementsSnapshot(t){let n=new Map;for(let o of ho(this.elements))n.set(o.id,o);for(let o of ho(t))n.set(o.id,es(o));return n}},Bc="__observedAppState",j0=()=>({name:null,editingGroupId:null,viewBackgroundColor:H0.white,selectedElementIds:{},selectedGroupIds:{},selectedLinearElement:null,croppingElementId:null,activeLockedId:null,lockedMultiSelections:{}}),mo=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,Bc,{value:!0,enumerable:!1}),t},Cc=e=>!!Reflect.get(e,Bc);I();var Vc=si(Hc(),1);import{randomInteger as lf,arrayToMap as df,toBrandedType as zc,isDevEnv as Wc,isTestEnv as _c,toArray as cf}from"@excalidraw/common";import{isNonDeletedElement as uf}from"@excalidraw/element";import{isFrameLikeElement as pf}from"@excalidraw/element";import{getElementsInGroup as hf}from"@excalidraw/element";import{syncInvalidIndices as mf,syncMovedIndices as ff,validateFractionalIndices as gf}from"@excalidraw/element";import{getSelectedElements as Ef}from"@excalidraw/element";import{mutateElement as xf}from"@excalidraw/element";var jc=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}},yf=(0,Vc.default)(e=>{(Wc()||_c()||window?.DEBUG_FRACTIONAL_INDICES)&&gf(e,{shouldThrow:Wc()||_c(),includeBoundTextValidation:!0})},1e3*60,{leading:!0,trailing:!1}),wf=e=>{let t=["includeBoundTextElement","includeElementsInFrames"],n="";for(let o of t)n+=`${o}:${e[o]?"1":"0"}`;return n},fo=class{callbacks=new Set;nonDeletedElements=[];nonDeletedElementsMap=zc(new Map);elements=[];nonDeletedFramesLikes=[];frames=[];elementsMap=zc(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=wf(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=Ef(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&&uf(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=cf(t),i=[];n?.skipValidation||yf(o),this.elements=mf(o),this.elementsMap.clear(),this.elements.forEach(a=>{pf(a)&&i.push(a),this.elementsMap.set(a.id,a)});let r=jc(this.elements);this.nonDeletedElements=r.elements,this.nonDeletedElementsMap=r.elementsMap,this.frames=i,this.nonDeletedFramesLikes=jc(this.frames).elements,this.triggerUpdate()}triggerUpdate(){this.sceneNonce=lf();for(let t of Array.from(this.callbacks))t()}onUpdate(t){if(this.callbacks.has(t))throw new Error;return this.callbacks.add(t),()=>{if(!this.callbacks.has(t))throw new Error;this.callbacks.delete(t)}}destroy(){this.elements=[],this.nonDeletedElements=[],this.nonDeletedFramesLikes=[],this.frames=[],this.elementsMap.clear(),this.selectedElementsCache.selectedElementIds=null,this.selectedElementsCache.elements=null,this.selectedElementsCache.cache.clear(),this.callbacks.clear()}insertElementsAtIndex(t,n){if(!t.length)return;if(n===null&&(n=this.elements.length),!Number.isFinite(n)||n<0)throw new Error("insertElementAtIndex can only be called with index >= 0");let o=[...this.elements.slice(0,n),...t,...this.elements.slice(n)];ff(o,df(t)),this.replaceAllElements(o)}insertElement=t=>{this.insertElementsAtIndex([t],null)};getElementIndex(t){return this.elements.findIndex(n=>n.id===t)}getContainerElement=t=>t&&t.containerId&&this.getElement(t.containerId)||null;getElementsFromId=t=>{let n=this.getNonDeletedElementsMap(),o=n.get(t);return o?[o]:hf(n,t)};mutateElement(t,n,o={informMutation:!0,isDragging:!1}){let i=this.getNonDeletedElementsMap(),{version:r}=t,{version:a}=xf(t,i,n,o);return this.elementsMap.has(t.id)&&r!==a&&o.informMutation&&this.triggerUpdate(),t}};var $=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,a=o&&i!=="deleted"?o(n,"inserted"):n;return new e(r,a)}static calculate(t,n,o,i){if(t===n)return e.empty();let r={},a={};for(let d of this.getDifferences(t,n))r[d]=t[d],a[d]=n[d];let[s,l]=i?i(r,a):[r,a];return e.create(s,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(an(t??[],i),an(n??[],i),an(o??[],i)))}static diffObjects(t,n,o,i){if(!t[o]&&!n[o])return;let r=t[o]!==null&&typeof t[o]=="object",a=n[o]!==null&&typeof n[o]=="object";if(r||a){let s=t[o]??{},l=n[o]??{},d=e.getLeftDifferences(s,l).reduce((u,h)=>(u[h]=i(s[h]),u),{}),c=e.getRightDifferences(s,l).reduce((u,h)=>(u[h]=i(l[h]),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]:[],a=Array.isArray(n[o])?n[o]:[],s=an(e.getLeftDifferences(an(r,i),an(a,i)),d=>d),l=an(e.getRightDifferences(an(r,i),an(a,i)),d=>d);if(Object.keys(s).length||Object.keys(l).length){let d=r.filter(u=>s[i?i(u):String(u)]),c=a.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(a=>a in o):t==="full"?r=Array.from(new Set([...Object.keys(n),...Object.keys(o)])):Yc(t,`Unknown distinctKeysIterator's join param "${t}"`,!0);for(let a of r){let s=n[a],l=o[a];if(s!==l){if(!i&&typeof s=="object"&&typeof l=="object"&&s!==null&&l!==null&&Xc(s,l))continue;yield a}}}},Ln=class e{constructor(t){this.delta=t}static create(t){return new e(t)}static calculate(t,n){let o=$.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($.create({},{}))}inverse(){let t=$.create(this.delta.inserted,this.delta.deleted);return new e(t)}squash(t){if(t.isEmpty())return this;let n=$.mergeObjects(this.delta.deleted.selectedElementIds??{},t.delta.deleted.selectedElementIds??{}),o=$.mergeObjects(this.delta.inserted.selectedElementIds??{},t.delta.inserted.selectedElementIds??{}),i=$.mergeObjects(this.delta.deleted.selectedGroupIds??{},t.delta.deleted.selectedGroupIds??{}),r=$.mergeObjects(this.delta.inserted.selectedGroupIds??{},t.delta.inserted.selectedGroupIds??{}),a=$.mergeObjects(this.delta.deleted.lockedMultiSelections??{},t.delta.deleted.lockedMultiSelections??{}),s=$.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(a).length||Object.keys(s).length)&&(d.lockedMultiSelections=a,l.lockedMultiSelections=s),this.delta=$.merge(this.delta,t.delta,$.create(d,l)),this}applyTo(t,n){try{let{selectedElementIds:o={},selectedGroupIds:i={},lockedMultiSelections:r={}}=this.delta.deleted,{selectedElementIds:a={},selectedGroupIds:s={},lockedMultiSelections:l={},selectedLinearElement:d,...c}=this.delta.inserted,u=$.mergeObjects(t.selectedElementIds,a,o),h=$.mergeObjects(t.selectedGroupIds,s,i),m=$.mergeObjects(t.lockedMultiSelections,l,r),f=d&&n.has(d.elementId)?new R(n.get(d.elementId),n,d.isEditing):null,g={...t,...c,selectedElementIds:u,selectedGroupIds:h,lockedMultiSelections:m,selectedLinearElement:typeof d<"u"?f:t.selectedLinearElement},E=this.filterInvisibleChanges(t,g,n);return[g,E]}catch(o){if(console.error("Couldn't apply appstate change",o),Gn()||Dn())throw o;return[t,!1]}}isEmpty(){return $.isEmpty(this.delta)}filterInvisibleChanges(t,n,o){let i=mo(t),r=mo(n),a=$.isRightDifferent(e.stripElementsProps(i),e.stripElementsProps(r)),s=$.isRightDifferent(e.stripStandaloneProps(i),e.stripStandaloneProps(r));if(!a&&!s)return!1;let l={value:a};if(s){let d=$.getRightDifferences(e.stripStandaloneProps(i),e.stripStandaloneProps(r)),c=new Set;(d.includes("editingGroupId")||d.includes("selectedGroupIds"))&&(c=Od(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 y=n[u];if(!y)l.value=!0;else{let w=o.get(y);w&&!w.isDeleted?l.value=!0:n[u]=null}break}case"editingGroupId":let h=n[u];h?c.has(h)?l.value=!0:n[u]=null:l.value=!0;break;case"selectedLinearElement":let m=n[u];if(!m)l.value=!0;else{let y=o.get(m.elementId);y&&!y.isDeleted?l.value=!0:n[u]=null}break;case"lockedMultiSelections":let f=t[u]||{},g=n[u]||{};Xc(f,g)||(l.value=!0);break;case"activeLockedId":let E=t[u]||null,x=n[u]||null;E!==x&&(l.value=!0);break;default:Yc(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 a of i){let s=n.get(a);s&&!s.isDeleted?o.value=!0:delete r[a]}return r}static filterSelectedGroups(t,n,o){if(!Object.keys(t).length)return o.value=!0,t;let r={...t};for(let a of Object.keys(r))n.has(a)?o.value=!0:delete r[a];return r}static stripElementsProps(t){let{editingGroupId:n,selectedGroupIds:o,selectedElementIds:i,selectedLinearElement:r,croppingElementId:a,lockedMultiSelections:s,activeLockedId:l,...d}=t;return d}static stripStandaloneProps(t){let{name:n,viewBackgroundColor:o,...i}=t;return i}static postProcess(t,n){try{$.diffObjects(t,n,"selectedElementIds",o=>!0),$.diffObjects(t,n,"selectedGroupIds",o=>o??!1),$.diffObjects(t,n,"lockedMultiSelections",o=>o??{})}catch(o){if(console.error("Couldn't postprocess appstate change deltas."),Gn()||Dn())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}},Cn=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 a={},s={},l={},d=[...Object.entries(t),...Object.entries(n),...Object.entries(o)];for(let[c,u]of d)this.satisfiesAddition(u)?a[c]=u:this.satisfiesRemoval(u)?s[c]=u:l[c]=u;r=new e(a,s,l)}else r=new e(t,n,o);return(Gn()||Dn())&&(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 a of t.values())if(!n.get(a.id)){let l={...a},d={isDeleted:!0,version:a.version+1,versionNonce:Uc()},c=$.create(l,d,e.stripIrrelevantProps);a.isDeleted?r[a.id]=c:i[a.id]=c}for(let a of n.values()){let s=t.get(a.id);if(!s){let l={isDeleted:!0,version:a.version-1,versionNonce:Uc()},d={...a},c=$.create(l,d,e.stripIrrelevantProps);a.isDeleted?r[a.id]=c:o[a.id]=c;continue}if(s.versionNonce!==a.versionNonce){let l=$.calculate(s,a,e.stripIrrelevantProps,e.postProcess);if(typeof s.isDeleted=="boolean"&&typeof a.isDeleted=="boolean"&&s.isDeleted!==a.isDeleted){s.isDeleted&&!a.isDeleted?o[a.id]=l:i[a.id]=l;continue}r[a.id]=l}}return e.create(o,i,r)}static empty(){return e.create({},{},{})}inverse(){let t=r=>{let a={};for(let[s,{inserted:l,deleted:d}]of Object.entries(r))a[s]=$.create({...l},{...d});return a},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,h)=>{let m;switch(h){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 g of Object.keys(u))switch(g){case"boundElements":f[g]=u[g];break;default:f[g]=m[g]}return f},r=d=>{let c={};for(let[u,h]of Object.entries(d)){let m=t.get(u),f=n.get(u),g=null;m||f?g=$.create(h.deleted,h.inserted,i(m,f),o):g=h,$.isInnerDifferent(g.deleted,g.inserted)&&(c[u]=g)}return c},a=r(this.added),s=r(this.removed),l=r(this.updated);return e.create(a,s,l,{shouldRedistribute:!0})}applyTo(t,n=Bn.empty().elements,o){let i=new Map(t),r,a={containsVisibleDifference:!1,containsZindexDifference:!1,applyDirection:void 0};try{let s=e.createApplier(t,i,n,a,o),l=s(this.added),d=s(this.removed),c=s(this.updated),u=this.resolveConflicts(t,i,a.applyDirection);r=new Map([...l,...d,...c,...u])}catch(s){if(console.error("Couldn't apply elements delta",s),Gn()||Dn())throw s;return[t,!0]}try{i=e.reorderElements(i,r,a),e.redrawElements(i,r)}catch(s){if(console.error("Couldn't mutate elements after applying elements change",s),Gn()||Dn())throw s}finally{return[i,a.containsVisibleDifference]}}squash(t){if(t.isEmpty())return this;let{added:n,removed:o,updated:i}=t,r=(a,s)=>{let l=$.mergeArrays(a.deleted.boundElements??[],s.deleted.boundElements??[],void 0,c=>c.id)??[],d=$.mergeArrays(a.inserted.boundElements??[],s.inserted.boundElements??[],void 0,c=>c.id)??[];if(!(!l.length&&!d.length))return $.create({boundElements:l},{boundElements:d})};for(let[a,s]of Object.entries(n)){let l=this.added[a]??this.removed[a]??this.updated[a];if(!l)this.added[a]=s;else{let d=r(l,s);delete this.removed[a],delete this.updated[a],this.added[a]=$.merge(l,s,d)}}for(let[a,s]of Object.entries(o)){let l=this.added[a]??this.removed[a]??this.updated[a];if(!l)this.removed[a]=s;else{let d=r(l,s);delete this.added[a],delete this.updated[a],this.removed[a]=$.merge(l,s,d)}}for(let[a,s]of Object.entries(i)){let l=this.added[a]??this.removed[a]??this.updated[a];if(!l)this.updated[a]=s;else{let d=r(l,s),c=$.merge(l,s,d);l===this.added[a]?this.added[a]=c:l===this.removed[a]?this.removed[a]=c:this.updated[a]=c}}return(Gn()||Dn())&&(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)=>a=>{let s=e.createGetter(n,o,i);return Object.entries(a).reduce((l,[d,c])=>{let u=s(d,c.inserted);if(u){let h=e.applyDelta(u,c,i,r);if(n.set(h.id,h),l.set(h.id,h),!i.applyDirection){let m=t.get(d);m&&(i.applyDirection=m.version>h.version?"backward":"forward")}}return l},new Map)};static createGetter=(t,n,o)=>(i,r)=>{let a=t.get(i);return a||(a=n.get(i),a?(o.containsZindexDifference=!0,(!r.isDeleted||r.isDeleted&&!a.isDeleted)&&(o.containsVisibleDifference=!0)):a=He({id:i,version:1},{...r})),a};static applyDelta(t,n,o,i){let r={};for(let a of Object.keys(n.inserted)){if(a==="boundElements"||i?.excludedProperties?.has(a))continue;let s=n.inserted[a];Reflect.set(r,a,s)}if(n.deleted.boundElements?.length||n.inserted.boundElements?.length){let a=$.mergeArrays(t.boundElements,n.inserted.boundElements,n.deleted.boundElements,s=>s.id);Object.assign(r,{boundElements:a})}if(!o.containsVisibleDifference){let{index:a,...s}=r,l=e.checkForVisibleDifference(t,s);o.containsVisibleDifference=l}return o.containsZindexDifference||(o.containsZindexDifference=n.deleted.index!==n.inserted.index),He(t,r,!0)}static checkForVisibleDifference(t,n){return t.isDeleted&&n.isDeleted!==!1?!1:t.isDeleted&&n.isDeleted===!1||t.isDeleted===!1&&n.isDeleted?!0:$.isRightDifferent(t,n)}resolveConflicts(t,n,o="forward"){let i=new Map,r=(s,l)=>{let d=n.get(s.id);if(!d)return;let c=t.get(s.id),u=o==="forward"?d.version+1:d.version-1,h=l,m;c===d?m=He(d,{...h,version:u},!0):m=Te(d,n,{...h,version:c?.version!==d.version?d.version:u}),i.set(m.id,m),n.set(m.id,m)};for(let s of Object.keys(this.removed))e.unbindAffected(t,n,s,r);for(let s of Object.keys(this.added))e.rebindAffected(t,n,s,r);for(let[s]of Array.from(Object.entries(this.updated)).filter(([l,d])=>Object.keys({...d.deleted,...d.inserted}).find(c=>gd.has(c)))){let l=n.get(s);!l||l.isDeleted||e.rebindAffected(t,n,s,r)}let a=new Map(Array.from(t).filter(([s])=>i.has(s)));return this.squash(e.calculate(a,i)),i}static unbindAffected(t,n,o,i){let r=()=>t.get(o),a=()=>n.get(o);Pn.unbindAffected(n,r(),i),Pn.unbindAffected(n,a(),i),In.unbindAffected(n,r(),i),In.unbindAffected(n,a(),i)}static rebindAffected(t,n,o,i){let r=()=>t.get(o),a=()=>n.get(o);Pn.unbindAffected(n,r(),i),Pn.rebindAffected(n,a(),i),In.unbindAffected(n,r(),(s,l)=>{te(s)&&i(s,l)}),In.rebindAffected(n,a(),i)}static redrawElements(t,n){try{let o=new fo(t,{skipValidation:!0});e.redrawTextBoundingBoxes(o,n),e.redrawBoundArrows(o,n)}catch(o){if(console.error("Couldn't redraw elements",o),Gn()||Dn())throw o}finally{return t}}static redrawTextBoundingBoxes(t,n){let o=t.getNonDeletedElementsMap(),i=new Map;for(let r of n.values()){if(Ee(r)){let{containerId:a}=r,s=a?o.get(a):void 0;s&&i.set(s.id,{container:s,boundText:r})}if(Ct(r)){let a=Qt(r),s=a?o.get(a):void 0;s&&i.set(r.id,{container:r,boundText:s})}}for(let{container:r,boundText:a}of i.values())r.isDeleted||a.isDeleted||Oi(a,r,t)}static redrawBoundArrows(t,n){for(let o of n.values())!o.isDeleted&&ge(o)&&Re(o,t,{changedElements:n})}static reorderElements(t,n,o){if(!o.containsZindexDifference)return t;let i=Array.from(t.values()),r=Id([...i]),a=$.getRightDifferences(i,r,!0).reduce((s,l)=>{let d=i[Number(l)];return d&&n.has(d.id)&&s.set(d.id,d),s},new Map);return!o.containsVisibleDifference&&a.size&&(o.containsVisibleDifference=!0),bf(Yn(r,a))}static postProcess(t,n){try{$.diffArrays(t,n,"boundElements",r=>r.id);let o=t.points??[],i=n.points??[];$.isDifferent(o,i)||(Reflect.deleteProperty(t,"points"),Reflect.deleteProperty(n,"points"))}catch(o){if(console.error("Couldn't postprocess elements delta."),Gn()||Dn())throw o}finally{return[t,n]}}static stripIrrelevantProps(t){let{id:n,updated:o,...i}=t;return i}};I();var f4=(e,t,n,o,i)=>{let[r,a,s,l]=n.axis==="x"?["minX","midX","maxX","width"]:["minY","midY","maxY","height"],d=Fe(e),c=ir(e,t,o).map(f=>[f,Fe(f)]).sort((f,g)=>f[1][a]-g[1][a]),u=0;for(let f of c)u+=f[1][l];let h=(d[l]-u)/(c.length-1);if(h<0){let f=c.findIndex(y=>y[1][r]===d[r]),g=c.findIndex(y=>y[1][s]===d[s]),E=(c[g][1][a]-c[f][1][a])/(c.length-1),x=c[f][1][a];return c.flatMap(([y,w],M)=>{let b={x:0,y:0};return M!==f&&M!==g&&(x+=E,b[n.axis]=x-w[a]),y.map(S=>{let v=i.mutateElement(S,{x:S.x+b.x,y:S.y+b.y});return Re(S,i,{simultaneouslyUpdated:y}),v})})}let m=d[r];return c.flatMap(([f,g])=>{let E={x:0,y:0};return E[n.axis]=m-g[r],m+=h,m+=g[l],f.map(x=>{let y=i.mutateElement(x,{x:x.x+E.x,y:x.y+E.y});return Re(x,i,{simultaneouslyUpdated:f}),y})})};I();import{TEXT_AUTOWRAP_THRESHOLD as Mf,getGridPoint as Pf,getFontString as If,DRAGGING_THRESHOLD as Sf}from"@excalidraw/common";var S4=(e,t,n,o,i,r)=>{if(t.length===1&&U(t[0])&&(t[0].startBinding||t[0].endBinding))return;let a=t.filter(h=>{if(U(h)&&h.startBinding&&h.endBinding){let m=t.find(g=>g.id===h.startBinding?.elementId),f=t.find(g=>g.id===h.endBinding?.elementId);return m&&f}return!0}),s=new Set(a),l=a.filter(h=>ee(h)).map(h=>h.id);if(l.length>0)for(let h of o.getNonDeletedElements())h.frameId!==null&&l.includes(h.frameId)&&s.add(h);let d=[];for(let h of s){let m=e.originalElements.get(h.id);if(!m)return;d.push(m)}let c=vf(We(d),n,i,r),u=new Set(Array.from(s,h=>h.id));s.forEach(h=>{let m=!j(h),f=m||(h.startBinding?u.has(h.startBinding.elementId):!1),g=m||(h.endBinding?u.has(h.endBinding.elementId):!1);if(j(h)){if(s.size>1||Math.max(Math.abs(c.x),Math.abs(c.y))>Sf||!h.startBinding&&!h.endBinding){rs(e,h,o,c);let E=h.startBinding&&!f,x=h.endBinding&&!g;(E||x)&&(E&&Oe(h,"start",o),x&&Oe(h,"end",o))}}else{rs(e,h,o,c);let E=Z(h,o.getNonDeletedElementsMap());E&&rs(e,E,o,c),Re(h,o,{simultaneouslyUpdated:Array.from(s)})}})},vf=(e,t,n,o)=>{let[i,r]=e,a=i+t.x+n.x,s=r+t.y+n.y;if(n.x===0||n.y===0){let[l,d]=Pf(i+t.x,r+t.y,o);n.x===0&&(a=l),n.y===0&&(s=d)}return{x:a-i,y:s-r}},rs=(e,t,n,o)=>{let i=e.originalElements.get(t.id)??t,r=i.x+o.x,a=i.y+o.y;n.mutateElement(t,{x:r,y:a})},v4=(e,t,n)=>{let[o,i]=We(e);return[t-o,n-i]},A4=({newElement:e,elementType:t,originX:n,originY:o,x:i,y:r,width:a,height:s,shouldMaintainAspectRatio:l,shouldResizeFromCenter:d,zoom:c,scene:u,widthAspectRatio:h=null,originOffset:m=null,informMutation:f=!0})=>{l&&e.type!=="selection"&&(h?s=a/h:(Math.abs(r-o)>Math.abs(i-n)?{width:a,height:s}=qa(t,s,i<n?-a:a):{width:a,height:s}=qa(t,a,r<o?-s:s),s<0&&(s=-s)));let g=i<n?n-a:n,E=r<o?o-s:o;d&&(a+=a,s+=s,g=n-a/2,E=o-s/2);let x=null;if(te(e)){s=e.height;let y=Ci(If({fontSize:e.fontSize,fontFamily:e.fontFamily}),e.lineHeight);a=Math.max(a,y),Math.abs(i-n)>Mf/c&&(x={autoResize:!1}),E=o,d&&(g=n-a/2)}if(a!==0&&s!==0){let y=null;Ae(e)&&(y={initialWidth:a,initialHeight:s}),u.mutateElement(e,{x:g+(m?.x??0),y:E+(m?.y??0),width:a,height:s,...x,...y},{informMutation:f,isDragging:!1})}};I();import{ELEMENT_LINK_KEY as fr,normalizeLink as $c}from"@excalidraw/common";var B4=(e,t)=>{let n=window.location.href;try{let o=new URL(n);return o.searchParams.set(fr,e),$c(o.toString())}catch(o){console.error(o)}return $c(n)},D4=(e,t)=>{if(e.length>0&&Af(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},Af=e=>!!(e.length===1||e.length>1&&Rd(e)),G4=e=>{try{let t=new URL(e);return t.searchParams.has(fr)&&t.host===window.location.host}catch{return!1}},O4=e=>{try{let{searchParams:t}=new URL(e);if(t.has(fr))return t.get(fr)}catch{}return null};I();import{FONT_FAMILY as Hf,VERTICAL_ALIGN as zf,escapeDoubleQuotes as as,getFontString as Wf}from"@excalidraw/common";I();import{DEFAULT_ELEMENT_PROPS as On,DEFAULT_FONT_FAMILY as kf,DEFAULT_FONT_SIZE as Tf,DEFAULT_TEXT_ALIGN as Lf,DEFAULT_VERTICAL_ALIGN as Cf,VERTICAL_ALIGN as Bf,randomInteger as Df,randomId as Gf,getFontString as gr,getUpdatedTimestamp as Of,getLineHeight as Rf}from"@excalidraw/common";var St=(e,{x:t,y:n,strokeColor:o=On.strokeColor,backgroundColor:i=On.backgroundColor,fillStyle:r=On.fillStyle,strokeWidth:a=On.strokeWidth,strokeStyle:s=On.strokeStyle,roughness:l=On.roughness,opacity:d=On.opacity,width:c=0,height:u=0,angle:h=0,groupIds:m=[],frameId:f=null,index:g=null,roundness:E=null,boundElements:x=null,link:y=null,locked:w=On.locked,...M})=>((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:M.points}),{id:M.id||Gf(),type:e,x:t,y:n,width:c,height:u,angle:h,strokeColor:o,backgroundColor:i,fillStyle:r,strokeWidth:a,strokeStyle:s,roughness:l,opacity:d,groupIds:m,frameId:f,index:g,roundness:E,seed:M.seed??Df(),version:M.version||1,versionNonce:M.versionNonce??0,isDeleted:!1,boundElements:x,updated:Of(),link:y,locked:w,customData:M.customData}),qn=e=>St(e.type,e),U4=e=>St("embeddable",e),Y4=e=>({...St("iframe",e)}),Zc=e=>He({...St("frame",e),type:"frame",name:e?.name||null},{}),qc=e=>He({...St("magicframe",e),type:"magicframe",name:e?.name||null},{}),Kc=(e,t)=>({x:e.textAlign==="center"?t.width/2:e.textAlign==="right"?t.width:0,y:e.verticalAlign==="middle"?t.height/2:0}),Kn=e=>{let t=e.fontFamily||kf,n=e.fontSize||Tf,o=e.lineHeight||Rf(t),i=Ro(e.text),r=ot(i,gr({fontFamily:t,fontSize:n}),o),a=e.textAlign||Lf,s=e.verticalAlign||Cf,l=Kc({textAlign:a,verticalAlign:s},r),d={...St("text",e),text:i,fontSize:n,fontFamily:t,textAlign:a,verticalAlign:s,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 He(d,{})},Ff=(e,t,n)=>{let{width:o,height:i}=ot(n,gr(e),e.lineHeight);e.autoResize||(o=e.width);let{textAlign:r,verticalAlign:a}=e,s,l;if(r==="center"&&a===Bf.MIDDLE&&!e.containerId&&e.autoResize){let d=ot(e.text,gr(e),e.lineHeight),c=Kc(e,{width:o-d.width,height:i-d.height});s=e.x-c.x,l=e.y-c.y}else{let[d,c,u,h]=Q(e,t),[m,f,g,E]=pn(e,o,i,!1),x=(d-m)/2,y=(c-f)/2,w=(u-g)/2,M=(h-E)/2;[s,l]=Nf({s:!0,e:r==="center"||r==="left",w:r==="center"||r==="right"},e.x,e.y,e.angle,x,y,w,M)}return{width:o,height:i,x:Number.isFinite(s)?s:e.x,y:Number.isFinite(l)?l:e.y}},Nf=(e,t,n,o,i,r,a,s)=>{let l=Math.cos(o),d=Math.sin(o);return e.e&&e.w?t+=i+a:e.e?(t+=i*(1+l),n+=i*d,t+=a*(1-l),n+=a*-d):e.w&&(t+=i*(1-l),n+=i*-d,t+=a*(1+l),n+=a*d),e.n&&e.s?n+=r+s:e.n?(t+=r*d,n+=r*(1-l),t+=s*-d,n+=s*(1+l)):e.s&&(t+=r*-d,n+=r*(1+l),t+=s*d,n+=s*(1-l)),[t,n]},X4=(e,t,n,o=e.text)=>{if(e.isDeleted)return;(t||!e.autoResize)&&(o=Kt(o,gr(e),t?yt(t,e):e.width));let i=Ff(e,n,o);return{text:o,...i}},$4=e=>({...St(e.type,e),points:e.points||[],pressures:e.pressures||[],simulatePressure:e.simulatePressure}),Qc=e=>{let t={...St(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:null,endArrowhead:null};return Ut(t)?{...t,polygon:e.polygon??!1}:t},Er=e=>e.elbowed?{...St(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!0,fixedSegments:e.fixedSegments||[],startIsSpecial:!1,endIsSpecial:!1}:{...St(e.type,e),points:e.points||[],startBinding:null,endBinding:null,startArrowhead:e.startArrowhead||null,endArrowhead:e.endArrowhead||null,elbowed:!1},Jc=e=>({...St("image",e),strokeColor:"transparent",status:e.status??"pending",fileId:e.fileId??null,fileName:e.fileName??null,scale:e.scale??[1,1],crop:e.crop??null});var vt=new Map,_f=/^(?:http(?:s)?:\/\/)?(?:www\.)?youtu(?:be\.com|\.be)\/(embed\/|watch\?v=|shorts\/|playlist\?list=|embed\/videoseries\?list=)?([a-zA-Z0-9_-]+)/,jf=/^(?:http(?:s)?:\/\/)?(?:(?:w){3}\.)?(?:player\.)?vimeo\.com\/(?:video\/)?([^?\s]+)(?:\?.*)?$/,Vf=/^https:\/\/(?:www\.)?figma\.com/,eu=/^https:\/\/gist\.github\.com\/([\w_-]+)\/([\w_-]+)/,Uf=/^<script[\s\S]*?\ssrc=["'](https:\/\/gist\.github\.com\/.*?)\.js["']/i,Yf=/^(?:https?:\/\/)?forms\.microsoft\.com\//,tu=/(?:https?:\/\/)?(?:(?:w){3}\.)?(?:twitter|x)\.com\/[^/]+\/status\/(\d+)/,Xf=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:twitter|x)\.com\/[^"']*)/i,$f=/^https:\/\/(?:www\.)?val\.town\/(v|embed)\/[a-zA-Z_$][0-9a-zA-Z_$]+\.[a-zA-Z_$][0-9a-zA-Z_$]+/,Zf=/^<(?:iframe|blockquote)[\s\S]*?\s(?:src|href)=["']([^"']*)["'][\s\S]*?>$/i,nu=/giphy.com\/(?:clips|embed|gifs)\/[a-zA-Z0-9]*?-?([a-zA-Z0-9]+)(?:[^a-zA-Z0-9]|$)/,ou=/^(?:http(?:s)?:\/\/)?(?:www\.)?reddit\.com\/r\/([a-zA-Z0-9_]+)\/comments\/([a-zA-Z0-9_]+)\/([a-zA-Z0-9_]+)\/?(?:\?[^#\s]*)?(?:#[^\s]*)?$/,qf=/^<blockquote[\s\S]*?\shref=["'](https?:\/\/(?:www\.)?reddit\.com\/[^"']*)/i,ru=e=>{let t;try{let a=new URL(e.startsWith("http")?e:`https://${e}`);t=a.searchParams.get("t")||a.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)},Kf=e=>{try{let t=new URL(e.startsWith("http")?e:`https://${e}`);if(t.hostname.replace(/^www\./,"")!=="drive.google.com")return null;let o=null,i=t.pathname.match(/^\/file\/d\/([^/]+)(?:\/|$)/);if(i?.[1]?o=i[1]:(t.pathname==="/open"||t.pathname==="/uc")&&(o=t.searchParams.get("id")),!o||!/^[a-zA-Z0-9_-]+$/.test(o))return null;let r=t.searchParams.get("resourcekey"),a=ru(t.toString());return{fileId:o,resourceKey:r&&/^[a-zA-Z0-9_-]+$/.test(r)?r:void 0,timestamp:a>0?a:void 0}}catch{return null}},ls=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","link.excalidraw.com","gist.github.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","val.town","giphy.com","reddit.com","forms.microsoft.com"]),iu=new Set(["youtube.com","youtu.be","vimeo.com","player.vimeo.com","drive.google.com","figma.com","twitter.com","x.com","*.simplepdf.eu","stackblitz.com","reddit.com","forms.microsoft.com"]),ss=e=>`<html><body>${e}</body></html>`,t5=e=>{if(!e)return null;if(vt.has(e))return vt.get(e);let t=e,n=iu.has(ds(e,iu)||""),o="generic",i={w:560,h:840},r=e.match(_f);if(r?.[2]){let c=ru(t),u=c>0?`&start=${c}`:"",h=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${u}`;break;case"playlist?list=":case"embed/videoseries?list=":e=`https://www.youtube.com/embed/videoseries?list=${r[2]}&enablejsapi=1${u}`;break;default:e=`https://www.youtube.com/embed/${r[2]}?enablejsapi=1${u}`;break}return i=h?{w:315,h:560}:{w:560,h:315},vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}}let a=e.match(jf);if(a?.[1]){let c=a?.[1],u=/^\d+$/.test(c)?void 0:new URIError("Invalid embed link format");return o="video",e=`https://player.vimeo.com/video/${c}?api=1`,i={w:560,h:315},vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,error:u,sandbox:{allowSameOrigin:n}}}let s=Kf(e);if(s){o="video";let c=new URLSearchParams;s.resourceKey&&c.set("resourcekey",s.resourceKey),s.timestamp&&c.set("t",`${s.timestamp}`);let u=c.toString();return e=`https://drive.google.com/file/d/${s.fileId}/preview${u?`?${u}`:""}`,i={w:560,h:315},vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}}if(e.match(Vf))return o="generic",e=`https://www.figma.com/embed?embed_host=share&url=${encodeURIComponent(e)}`,i={w:550,h:550},vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}};let d=e.match($f);if(d)return e=d[1]==="embed"?d[0]:d[0].replace("/v","/embed"),vt.set(t,{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}}),{link:e,intrinsicSize:i,type:o,sandbox:{allowSameOrigin:n}};if(Yf.test(e)&&!e.includes("embed=true")&&(e+=e.includes("?")?"&embed=true":"?embed=true"),tu.test(e)){let c=e.match(tu)[1],u=as(`https://twitter.com/x/status/${c}`),h={type:"document",srcdoc:m=>ss(`<blockquote class="twitter-tweet" data-dnt="true" data-theme="${m}"><a href="${u}"></a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return vt.set(t,h),h}if(ou.test(e)){let[,c,u,h]=e.match(ou),m=as(`https://reddit.com/r/${c}/comments/${u}/${h}`),f={type:"document",srcdoc:g=>ss(`<blockquote class="reddit-embed-bq" data-embed-theme="${g}"><a href="${m}"></a><br></blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"><\/script>`),intrinsicSize:{w:480,h:480},sandbox:{allowSameOrigin:n}};return vt.set(t,f),f}if(eu.test(e)){let[,c,u]=e.match(eu),h=as(`https://gist.github.com/${c}/${u}`),m={type:"document",srcdoc:()=>ss(`
|
|
22
22
|
<script src="${h}.js"><\/script>
|
|
23
23
|
<style type="text/css">
|
|
24
24
|
* { margin: 0px; }
|
|
@@ -57,6 +57,7 @@ export declare const newImageElement: (opts: {
|
|
|
57
57
|
type: ExcalidrawImageElement["type"];
|
|
58
58
|
status?: ExcalidrawImageElement["status"];
|
|
59
59
|
fileId?: ExcalidrawImageElement["fileId"];
|
|
60
|
+
fileName?: ExcalidrawImageElement["fileName"];
|
|
60
61
|
scale?: ExcalidrawImageElement["scale"];
|
|
61
62
|
crop?: ExcalidrawImageElement["crop"];
|
|
62
63
|
} & ElementConstructorOpts) => NonDeleted<ExcalidrawImageElement>;
|
|
@@ -129,6 +129,7 @@ export type ImageCrop = {
|
|
|
129
129
|
export type ExcalidrawImageElement = _ExcalidrawElementBase & Readonly<{
|
|
130
130
|
type: "image";
|
|
131
131
|
fileId: FileId | null;
|
|
132
|
+
fileName: string | null;
|
|
132
133
|
/** whether respective file is persisted */
|
|
133
134
|
status: "pending" | "saved" | "error";
|
|
134
135
|
/** X and Y scale factors <-1, 1>, used for image axis flipping */
|
|
@@ -1008,6 +1008,7 @@ export declare const actionWrapSelectionInFrame: {
|
|
|
1008
1008
|
}> & Readonly<{
|
|
1009
1009
|
type: "image";
|
|
1010
1010
|
fileId: import("@excalidraw/element/types").FileId | null;
|
|
1011
|
+
fileName: string | null;
|
|
1011
1012
|
status: "pending" | "saved" | "error";
|
|
1012
1013
|
scale: [number, number];
|
|
1013
1014
|
crop: import("@excalidraw/element/types").ImageCrop | null;
|
|
@@ -499,6 +499,7 @@ export declare const actionTogglePolygon: {
|
|
|
499
499
|
}> & Readonly<{
|
|
500
500
|
type: "image";
|
|
501
501
|
fileId: import("@excalidraw/element/types").FileId | null;
|
|
502
|
+
fileName: string | null;
|
|
502
503
|
status: "pending" | "saved" | "error";
|
|
503
504
|
scale: [number, number];
|
|
504
505
|
crop: import("@excalidraw/element/types").ImageCrop | null;
|
|
@@ -271,6 +271,7 @@ export declare class Renderer {
|
|
|
271
271
|
}> & Readonly<{
|
|
272
272
|
type: "image";
|
|
273
273
|
fileId: import("@excalidraw/element/types").FileId | null;
|
|
274
|
+
fileName: string | null;
|
|
274
275
|
status: "pending" | "saved" | "error";
|
|
275
276
|
scale: [number, number];
|
|
276
277
|
crop: import("@excalidraw/element/types").ImageCrop | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myoc/element",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.516",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/types/element/src/index.d.ts",
|
|
6
6
|
"main": "./dist/prod/index.js",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@excalidraw/common": "npm:@myoc/common@0.19.
|
|
68
|
-
"@excalidraw/fractional-indexing": "npm:@myoc/fractional-indexing@0.19.
|
|
69
|
-
"@excalidraw/math": "npm:@myoc/math@0.19.
|
|
67
|
+
"@excalidraw/common": "npm:@myoc/common@0.19.516",
|
|
68
|
+
"@excalidraw/fractional-indexing": "npm:@myoc/fractional-indexing@0.19.516",
|
|
69
|
+
"@excalidraw/math": "npm:@myoc/math@0.19.516"
|
|
70
70
|
}
|
|
71
71
|
}
|